Skip to content

Commit 6f591ea

Browse files
feat: enablePortalModal option
1 parent 43b4c30 commit 6f591ea

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

packages/demo/src/components/FieldPluginDemo.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type PluginComponent = FunctionComponent<{
1919
export const FieldPluginDemo: FunctionComponent = () => {
2020
const { type, data, actions } = useFieldPlugin({
2121
validateContent,
22+
targetOrigin: 'http://localhost:7070',
23+
enablePortalModal: true,
2224
})
2325

2426
if (type === 'loading') {

packages/field-plugin/src/createFieldPlugin/createFieldPlugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type CreateFieldPluginOptions<Content> = {
1212
onUpdateState: (state: FieldPluginResponse<Content>) => void
1313
validateContent?: ValidateContent<Content>
1414
targetOrigin?: string
15+
enablePortalModal?: boolean
1516
}
1617

1718
export type CreateFieldPlugin = <Content = unknown>(
@@ -25,6 +26,7 @@ export const createFieldPlugin: CreateFieldPlugin = ({
2526
onUpdateState,
2627
validateContent,
2728
targetOrigin,
29+
enablePortalModal,
2830
}) => {
2931
const isEmbedded = window.parent !== window
3032

@@ -107,6 +109,7 @@ export const createFieldPlugin: CreateFieldPlugin = ({
107109
validateContent:
108110
validateContent ||
109111
((content) => ({ content: content as InferredContent })),
112+
enablePortalModal,
110113
})
111114

112115
const cleanupHeightChangeListener = createHeightChangeListener(onHeightChange)

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type CreatePluginActions = <Content>(options: {
2828
postToContainer: (message: unknown) => void
2929
onUpdateState: (state: FieldPluginData<Content>) => void
3030
validateContent: ValidateContent<Content>
31+
enablePortalModal: boolean | undefined
3132
}) => {
3233
// These functions are to be called by the field plugin when the user performs actions in the UI
3334
actions: FieldPluginActions<Content>
@@ -46,6 +47,7 @@ export const createPluginActions: CreatePluginActions = ({
4647
postToContainer,
4748
onUpdateState,
4849
validateContent,
50+
enablePortalModal,
4951
}) => {
5052
const { pushCallback, popCallback } = callbackQueue()
5153

@@ -143,7 +145,9 @@ export const createPluginActions: CreatePluginActions = ({
143145
resolve(pluginStateFromStateChangeMessage(message, validateContent)),
144146
)
145147
// Request the initial state from the Visual Editor.
146-
postToContainer(pluginLoadedMessage({ uid, callbackId }))
148+
postToContainer(
149+
pluginLoadedMessage({ uid, callbackId, enablePortalModal }),
150+
)
147151
})
148152
},
149153
}

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PluginLoadedMessage.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ describe('PluginLoadedMessage', () => {
9898
subscribeState: false,
9999
}),
100100
).toEqual(true)
101-
const { subscribeState: _subscribeState, ...subWithoutSubscribeState } = stub
101+
const { subscribeState: _subscribeState, ...subWithoutSubscribeState } =
102+
stub
102103
expect(isPluginLoadedMessage(subWithoutSubscribeState)).toEqual(true)
103104
expect(
104105
isPluginLoadedMessage({
@@ -142,7 +143,8 @@ describe('PluginLoadedMessage', () => {
142143
subscribeState: false,
143144
}),
144145
).toEqual(true)
145-
const { subscribeState: _subscribeState, ...subWithoutSubscribeState } = stub
146+
const { subscribeState: _subscribeState, ...subWithoutSubscribeState } =
147+
stub
146148
expect(isPluginLoadedMessage(subWithoutSubscribeState)).toEqual(true)
147149
expect(
148150
isPluginLoadedMessage({
@@ -184,11 +186,21 @@ describe('PluginLoadedMessage', () => {
184186
true,
185187
)
186188
})
187-
it('sets enablePortalModal to true', () => {
188-
expect(pluginLoadedMessage({ uid, callbackId })).toHaveProperty(
189+
it('does not define enablePortalModal by default', () => {
190+
expect(pluginLoadedMessage({ uid, callbackId })).not.toHaveProperty(
189191
'enablePortalModal',
190-
true,
191192
)
192193
})
194+
it('lets you define enablePortalModal', () => {
195+
expect(
196+
pluginLoadedMessage({ uid, callbackId, enablePortalModal: true }),
197+
).toHaveProperty('enablePortalModal', true)
198+
expect(
199+
pluginLoadedMessage({ uid, callbackId, enablePortalModal: false }),
200+
).toHaveProperty('enablePortalModal', false)
201+
expect(
202+
pluginLoadedMessage({ uid, callbackId, enablePortalModal: undefined }),
203+
).toHaveProperty('enablePortalModal', undefined)
204+
})
193205
})
194206
})

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PluginLoadedMessage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export const isPluginLoadedMessage = (
2323
typeof obj.enablePortalModal === 'boolean')
2424

2525
export const pluginLoadedMessage = (
26-
options: Pick<PluginLoadedMessage, 'uid' | 'callbackId'>,
26+
options: Pick<
27+
PluginLoadedMessage,
28+
'uid' | 'callbackId' | 'enablePortalModal'
29+
>,
2730
): PluginLoadedMessage => ({
2831
action: 'plugin-changed',
2932
event: 'loaded',
3033
fullHeight: true,
3134
subscribeState: true,
32-
enablePortalModal: true,
3335
...options,
3436
})

0 commit comments

Comments
 (0)