@juo/orion-core 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/{ExtensionRoot-BuoY5H2A.js → ExtensionRoot-BFk-vt2J.js} +44 -16
  2. package/dist/block.d.ts +15 -3
  3. package/dist/bridge-fHXg0b-e.js +421 -0
  4. package/dist/core.js +270 -9
  5. package/dist/editor/bridge.d.ts +17 -0
  6. package/dist/editor/bridge.test.d.ts +1 -0
  7. package/dist/editor/components.d.ts +6 -0
  8. package/dist/editor/handler.d.ts +2 -3
  9. package/dist/editor/main.d.ts +7 -4
  10. package/dist/editor/messages.d.ts +86 -6
  11. package/dist/editor.js +299 -59
  12. package/dist/flows/MockWorkflowApiAdapter.d.ts +12 -0
  13. package/dist/flows/WorkflowService.d.ts +156 -0
  14. package/dist/flows/__tests__/WorkflowService.test.d.ts +1 -0
  15. package/dist/flows/__tests__/defaults.test.d.ts +1 -0
  16. package/dist/flows/__tests__/juo-workflow.test.d.ts +1 -0
  17. package/dist/flows/__tests__/overlay-behavior.test.d.ts +1 -0
  18. package/dist/flows/__tests__/theme-state-surfaces.test.d.ts +1 -0
  19. package/dist/flows/defaults.d.ts +14 -0
  20. package/dist/flows/index.d.ts +3 -0
  21. package/dist/flows/juo-workflow.d.ts +47 -0
  22. package/dist/juo-workflow-CoWvwYTn.js +545 -0
  23. package/dist/main.d.ts +5 -3
  24. package/dist/preact.js +1 -1
  25. package/dist/react.js +1 -1
  26. package/dist/{block-CFJIpH_9.js → theme-state-TW-9hD7e.js} +209 -7
  27. package/dist/theme-state.d.ts +84 -0
  28. package/dist/theme-state.locales.test.d.ts +1 -0
  29. package/dist/translation.d.ts +13 -0
  30. package/dist/translation.test.d.ts +1 -0
  31. package/dist/vue/context.d.ts +2 -0
  32. package/dist/vue.js +8 -1
  33. package/dist/web-components/ExtensionRoot.d.ts +12 -1
  34. package/dist/web-components/editor/InlineText.d.ts +4 -0
  35. package/dist/web-components/runtime/InlineText.d.ts +2 -1
  36. package/dist/web-components-editor.js +70 -21
  37. package/dist/web-components-runtime.js +39 -3
  38. package/package.json +1 -1
  39. package/dist/bridge-BPfBHSPI.js +0 -245
  40. package/dist/page-DFFhF7j8.js +0 -12
  41. package/dist/page.d.ts +0 -9
@@ -4,9 +4,9 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { signal, effect, createBlockInstance, subscribeContext, untracked } from "@juo/orion-core";
8
- import { P as PageContext } from "./page-DFFhF7j8.js";
9
- import { j as withWrapper } from "./block-CFJIpH_9.js";
7
+ import { signal, effect, createBlockInstance } from "@juo/orion-core";
8
+ import { d, j as withWrapper, q as subscribeContext, T as ThemeStateContext, E, t as n } from "./theme-state-TW-9hD7e.js";
9
+ import "./juo-workflow-CoWvwYTn.js";
10
10
  class Block extends HTMLElement {
11
11
  constructor() {
12
12
  super();
@@ -55,36 +55,58 @@ class Block extends HTMLElement {
55
55
  class ExtensionRoot extends HTMLElement {
56
56
  constructor() {
57
57
  super();
58
- __publicField(this, "state", signal(null));
59
- __publicField(this, "unsubscribeContext");
58
+ __publicField(this, "state", d(null));
59
+ __publicField(this, "themeState", null);
60
+ __publicField(this, "unsubscribeThemeContext");
60
61
  __publicField(this, "disposeEffect");
62
+ /**
63
+ * Optional function to wrap each rendered block element.
64
+ * Called with the rendered block HTMLElement, must return an HTMLElement.
65
+ * When set, the wrapper sits between the editor wrapper (outer) and the actual block (inner).
66
+ * Must be set before blocks are first rendered; changing it afterwards has no effect
67
+ * on already-cached block wrappers.
68
+ */
69
+ __publicField(this, "blockWrapper", null);
61
70
  __publicField(this, "wrapperCache", /* @__PURE__ */ new WeakMap());
62
71
  }
63
72
  static get observedAttributes() {
64
- return ["name"];
73
+ return ["name", "surface"];
65
74
  }
66
75
  withWrapper(block) {
67
76
  if (!this.wrapperCache.has(block)) {
68
- const wrapper = withWrapper((block2) => block2.definition.render(block2));
77
+ const blockWrapper = this.blockWrapper;
78
+ const wrapper = withWrapper((block2) => {
79
+ const rendered = block2.definition.render(block2);
80
+ return blockWrapper ? blockWrapper(rendered) : rendered;
81
+ });
69
82
  this.wrapperCache.set(block, wrapper);
70
83
  }
71
84
  return this.wrapperCache.get(block)(block);
72
85
  }
86
+ getSurface() {
87
+ return this.getAttribute("surface") === "overlay" ? "overlay" : "page";
88
+ }
89
+ setStateFromThemeState(themeState) {
90
+ const surface = this.getSurface();
91
+ this.state.value = surface === "overlay" ? themeState.overlay : themeState.page;
92
+ }
73
93
  connectedCallback() {
74
94
  this.state.value = null;
95
+ this.themeState = null;
75
96
  this.style.display = "flex";
76
97
  this.style.flexDirection = "column";
77
98
  this.style.gap = "16px";
78
99
  this.style.width = "fit-content";
79
100
  this.style.justifySelf = "center";
80
- this.unsubscribeContext = subscribeContext(
101
+ this.unsubscribeThemeContext = subscribeContext(
81
102
  this,
82
- PageContext,
103
+ ThemeStateContext,
83
104
  (contextValue) => {
84
- this.state.value = contextValue;
105
+ this.themeState = contextValue;
106
+ this.setStateFromThemeState(contextValue);
85
107
  }
86
108
  );
87
- this.disposeEffect = effect(() => {
109
+ this.disposeEffect = E(() => {
88
110
  const state = this.state.value;
89
111
  if (state == null) {
90
112
  this.replaceChildren();
@@ -97,7 +119,7 @@ class ExtensionRoot extends HTMLElement {
97
119
  return;
98
120
  }
99
121
  const blocks = state.blocks.value;
100
- untracked(() => {
122
+ n(() => {
101
123
  var _a;
102
124
  try {
103
125
  const extensionBlocks = (((_a = blocks.at(0)) == null ? void 0 : _a.slots) ?? {})[name] ?? [];
@@ -113,14 +135,20 @@ class ExtensionRoot extends HTMLElement {
113
135
  });
114
136
  }
115
137
  attributeChangedCallback(name, oldValue, newValue) {
116
- if (name === "name" && oldValue !== newValue && this.state.value) {
138
+ if ((name === "name" || name === "surface") && oldValue !== newValue && this.state.value) {
139
+ if (name === "surface") {
140
+ if (this.themeState) {
141
+ this.setStateFromThemeState(this.themeState);
142
+ return;
143
+ }
144
+ }
117
145
  this.state.value = { ...this.state.value };
118
146
  }
119
147
  }
120
148
  disconnectedCallback() {
121
- if (this.unsubscribeContext) {
122
- this.unsubscribeContext();
123
- this.unsubscribeContext = void 0;
149
+ if (this.unsubscribeThemeContext) {
150
+ this.unsubscribeThemeContext();
151
+ this.unsubscribeThemeContext = void 0;
124
152
  }
125
153
  if (this.disposeEffect) {
126
154
  this.disposeEffect();
package/dist/block.d.ts CHANGED
@@ -11,13 +11,20 @@ export interface BlockPreset<TState = unknown, TContext extends Record<string, u
11
11
  }
12
12
  export type BlockPresets = Record<string, BlockPreset<unknown, Record<string, unknown>>>;
13
13
  export type BlockRenderer = (block: BlockInstance) => HTMLElement;
14
+ export type BlockLocaleFile = {
15
+ overrides?: Record<string, string>;
16
+ [key: string]: string | Record<string, string> | undefined;
17
+ };
14
18
  export type BlockDefinition<T = unknown> = {
15
19
  name: string;
16
- group: "internal" | "juo" | "theme" | "integration" | "page";
20
+ group: "internal" | "juo" | "theme" | "integration" | "page" | "workflow" | "action";
17
21
  schema: Schema;
18
22
  initialValue: T | (() => T);
19
23
  render: BlockRenderer;
20
24
  presets?: BlockPresets;
25
+ locales?: {
26
+ load: (locale: string) => Promise<BlockLocaleFile>;
27
+ };
21
28
  };
22
29
  export type Block = {
23
30
  id: string;
@@ -28,6 +35,7 @@ export type Block = {
28
35
  export type BlockInstance = Block & {
29
36
  readonly definition: BlockDefinition;
30
37
  };
38
+ export declare function serializeBlocks(blocks: (Block | BlockInstance)[]): Block[];
31
39
  export declare function createSelectedBlock(): {
32
40
  selected: import('@preact/signals-core').Signal<BlockInstance | null>;
33
41
  setSelection: (block: BlockInstance) => void;
@@ -57,15 +65,19 @@ declare global {
57
65
  }
58
66
  export declare function withWrapper(fn: (block: BlockInstance) => HTMLElement): (block: BlockInstance) => HTMLElement;
59
67
  export declare function registerBlock<T>(block: BlockDefinition<T>): void;
68
+ export declare function onRegisterBlock(cb: (name: string, block: BlockDefinition) => void): void;
60
69
  export declare function defineBlock<T>(name: string, opts: {
61
- group: "internal" | "juo" | "theme" | "integration" | "page";
70
+ group: "internal" | "juo" | "theme" | "integration" | "page" | "workflow" | "action";
62
71
  schema: JSONSchema;
63
72
  initialValue: T | (() => T);
64
73
  renderer: (block: BlockInstance) => HTMLElement;
65
74
  presets?: BlockPresets;
75
+ locales?: {
76
+ load: (locale: string) => Promise<BlockLocaleFile>;
77
+ };
66
78
  }): BlockDefinition<T>;
67
79
  export declare function defineBlockRuntime<T = never>(name: string, opts: {
68
- group: "internal" | "juo" | "theme" | "integration" | "page";
80
+ group: "internal" | "juo" | "theme" | "integration" | "page" | "workflow" | "action";
69
81
  renderer: (block: BlockInstance) => HTMLElement;
70
82
  }): BlockDefinition<T>;
71
83
  export declare function getDefinedBlocks(): BlockDefinition[];
@@ -0,0 +1,421 @@
1
+ function isEditorMessage(message) {
2
+ return message.type === "PROVIDE_THEME_STATE" || message.type === "PROVIDE_TRANSLATION_OVERRIDES" || message.type === "SELECT_BLOCK" || message.type === "UPDATE_BLOCK_PROPS" || message.type === "ADD_BLOCK" || message.type === "REMOVE_BLOCK" || message.type === "MOVE_BLOCK" || message.type === "SET_BLOCK_PRESET" || message.type === "SET_LOCALE" || message.type === "SET_GLOBAL_STYLES" || message.type === "PROVIDE_GLOBAL_STYLES";
3
+ }
4
+ function isIframeMessage(message) {
5
+ return message.type === "SELECT_BLOCK" || message.type === "IFRAME_READY" || message.type === "REGISTER_BLOCKS" || message.type === "REGISTER_ROUTES" || message.type === "REMOVE_BLOCK" || message.type === "UPDATE_BLOCK_PROPS" || message.type === "REQUEST_THEME_STATE" || message.type === "REQUEST_TRANSLATION_OVERRIDES" || message.type === "UPDATE_BLOCK_TRANSLATION" || message.type === "FOCUS_INLINE_TEXT" || message.type === "REQUEST_GLOBAL_STYLES";
6
+ }
7
+ function createProvideThemeStateMessage(payload) {
8
+ return {
9
+ type: "PROVIDE_THEME_STATE",
10
+ payload,
11
+ timestamp: Date.now()
12
+ };
13
+ }
14
+ function createRequestThemeStateMessage(payload) {
15
+ return {
16
+ type: "REQUEST_THEME_STATE",
17
+ payload,
18
+ timestamp: Date.now()
19
+ };
20
+ }
21
+ function createRequestTranslationOverridesMessage(payload) {
22
+ return {
23
+ type: "REQUEST_TRANSLATION_OVERRIDES",
24
+ payload,
25
+ timestamp: Date.now()
26
+ };
27
+ }
28
+ function createProvideTranslationOverridesMessage(payload) {
29
+ return {
30
+ type: "PROVIDE_TRANSLATION_OVERRIDES",
31
+ payload,
32
+ timestamp: Date.now()
33
+ };
34
+ }
35
+ function createSelectBlockMessage(payload, blockId) {
36
+ return {
37
+ type: "SELECT_BLOCK",
38
+ payload,
39
+ blockId,
40
+ timestamp: Date.now()
41
+ };
42
+ }
43
+ function createUpdateBlockPropsMessage(payload, blockId) {
44
+ return {
45
+ type: "UPDATE_BLOCK_PROPS",
46
+ payload,
47
+ blockId,
48
+ timestamp: Date.now()
49
+ };
50
+ }
51
+ function createUpdateBlockTranslationMessage(payload, blockId) {
52
+ return {
53
+ type: "UPDATE_BLOCK_TRANSLATION",
54
+ payload,
55
+ blockId,
56
+ timestamp: Date.now()
57
+ };
58
+ }
59
+ function createAddBlockMessage(payload, blockId) {
60
+ return {
61
+ type: "ADD_BLOCK",
62
+ payload,
63
+ blockId,
64
+ timestamp: Date.now()
65
+ };
66
+ }
67
+ function createRemoveBlockMessage(payload, blockId) {
68
+ return {
69
+ type: "REMOVE_BLOCK",
70
+ payload,
71
+ blockId,
72
+ timestamp: Date.now()
73
+ };
74
+ }
75
+ function createMoveBlockMessage(payload, blockId) {
76
+ return {
77
+ type: "MOVE_BLOCK",
78
+ payload,
79
+ blockId,
80
+ timestamp: Date.now()
81
+ };
82
+ }
83
+ function createRegisterBlocksMessage(payload) {
84
+ const serializedBlocks = payload.blocks.map((block) => ({
85
+ name: block.name,
86
+ group: block.group,
87
+ schema: block.schema == null ? block.schema : JSON.parse(JSON.stringify(block.schema)),
88
+ initialValue: block.initialValue == null ? block.initialValue : JSON.parse(JSON.stringify(block.initialValue)),
89
+ presets: block.presets == null ? block.presets : JSON.parse(JSON.stringify(block.presets))
90
+ }));
91
+ return {
92
+ type: "REGISTER_BLOCKS",
93
+ payload: {
94
+ blocks: serializedBlocks
95
+ },
96
+ timestamp: Date.now()
97
+ };
98
+ }
99
+ function createSetBlockPresetMessage(payload) {
100
+ return {
101
+ type: "SET_BLOCK_PRESET",
102
+ payload,
103
+ timestamp: Date.now()
104
+ };
105
+ }
106
+ function createSetLocaleMessage(payload) {
107
+ return {
108
+ type: "SET_LOCALE",
109
+ payload,
110
+ timestamp: Date.now()
111
+ };
112
+ }
113
+ function createFocusInlineTextMessage(payload, blockId) {
114
+ return {
115
+ type: "FOCUS_INLINE_TEXT",
116
+ payload,
117
+ blockId,
118
+ timestamp: Date.now()
119
+ };
120
+ }
121
+ function createRegisterRoutesMessage(payload) {
122
+ return {
123
+ type: "REGISTER_ROUTES",
124
+ payload,
125
+ timestamp: Date.now()
126
+ };
127
+ }
128
+ function createSetGlobalStylesMessage(payload) {
129
+ return {
130
+ type: "SET_GLOBAL_STYLES",
131
+ payload,
132
+ timestamp: Date.now()
133
+ };
134
+ }
135
+ function createRequestGlobalStylesMessage(payload) {
136
+ return {
137
+ type: "REQUEST_GLOBAL_STYLES",
138
+ payload,
139
+ timestamp: Date.now()
140
+ };
141
+ }
142
+ function createProvideGlobalStylesMessage(payload) {
143
+ return {
144
+ type: "PROVIDE_GLOBAL_STYLES",
145
+ payload,
146
+ timestamp: Date.now()
147
+ };
148
+ }
149
+ let bridgeInstance = null;
150
+ function getEditorBridge() {
151
+ return bridgeInstance;
152
+ }
153
+ function createEditorBridge() {
154
+ if (bridgeInstance !== null) {
155
+ return bridgeInstance;
156
+ }
157
+ const messageHandlers = [];
158
+ const selectedBlockId = { value: null };
159
+ const pendingRequests = /* @__PURE__ */ new Map();
160
+ const pendingTranslationRequests = /* @__PURE__ */ new Map();
161
+ const pendingGlobalStylesRequests = /* @__PURE__ */ new Map();
162
+ let parentOrigin = "*";
163
+ const frame = window.parent || window;
164
+ if (window.parent !== window) {
165
+ try {
166
+ parentOrigin = window.parent.location.origin;
167
+ } catch {
168
+ parentOrigin = "*";
169
+ }
170
+ }
171
+ function sendMessage(message) {
172
+ frame.postMessage(message, parentOrigin);
173
+ }
174
+ function onMessage(handler) {
175
+ messageHandlers.push(handler);
176
+ return {
177
+ unsubscribe: () => {
178
+ const index = messageHandlers.indexOf(handler);
179
+ if (index !== -1) {
180
+ messageHandlers.splice(index, 1);
181
+ }
182
+ }
183
+ };
184
+ }
185
+ function updateBlockSelection(blockId) {
186
+ selectedBlockId.value = blockId;
187
+ }
188
+ function handleGlobalClick(event) {
189
+ const path = event.composedPath();
190
+ if (!path.some(
191
+ (node) => node instanceof HTMLElement && node.tagName !== "HTML"
192
+ )) {
193
+ return;
194
+ }
195
+ const isOverlay = path.some((node) => {
196
+ if (!(node instanceof HTMLElement))
197
+ return false;
198
+ let current = node;
199
+ while (current) {
200
+ const computedStyle = window.getComputedStyle(current);
201
+ const zIndex = parseInt(computedStyle.zIndex, 10);
202
+ if (!isNaN(zIndex) && zIndex >= 50 || ["listbox", "menu", "dialog"].includes(
203
+ current.getAttribute("role") || ""
204
+ )) {
205
+ return true;
206
+ }
207
+ current = current.parentElement;
208
+ }
209
+ return false;
210
+ });
211
+ const isEditorUI = path.some((node) => {
212
+ if (!(node instanceof HTMLElement))
213
+ return false;
214
+ let current = node;
215
+ const root = node.getRootNode();
216
+ while (current && current !== root) {
217
+ const classList = current.classList;
218
+ if (classList.contains("block-wrapper__name") || classList.contains("block-wrapper__actions") || classList.contains("block-wrapper__icon") || classList.contains("block-wrapper__remove-icon") || current.hasAttribute("data-block-editor")) {
219
+ return true;
220
+ }
221
+ current = current.parentElement;
222
+ }
223
+ return false;
224
+ });
225
+ let blockWrapper = null;
226
+ for (const node of path) {
227
+ if (node instanceof HTMLElement && node.tagName === "JUO-EDITOR-BLOCK-WRAPPER") {
228
+ blockWrapper = node;
229
+ break;
230
+ }
231
+ }
232
+ if (isOverlay && !blockWrapper) {
233
+ return;
234
+ }
235
+ if (!blockWrapper && isEditorUI) {
236
+ return;
237
+ }
238
+ const clickedBlockId = (blockWrapper == null ? void 0 : blockWrapper.getAttribute("data-block-id")) || null;
239
+ if (clickedBlockId && clickedBlockId === selectedBlockId.value) {
240
+ return;
241
+ }
242
+ const newBlockId = clickedBlockId || null;
243
+ if (newBlockId !== selectedBlockId.value) {
244
+ const message = createSelectBlockMessage(
245
+ { blockId: newBlockId },
246
+ newBlockId || void 0
247
+ );
248
+ updateBlockSelection(newBlockId);
249
+ messageHandlers.forEach((handler) => handler(message));
250
+ sendMessage(message);
251
+ }
252
+ }
253
+ document.addEventListener("click", handleGlobalClick, true);
254
+ function requestThemeState(surface, id, defaultBlock) {
255
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
256
+ return new Promise((resolve, reject) => {
257
+ const timer = setTimeout(() => {
258
+ pendingRequests.delete(requestId);
259
+ reject(
260
+ new Error(`REQUEST_THEME_STATE timed out for (${surface}, ${id})`)
261
+ );
262
+ }, 5e3);
263
+ pendingRequests.set(requestId, { resolve, timer });
264
+ sendMessage(
265
+ createRequestThemeStateMessage({
266
+ requestId,
267
+ surface,
268
+ id,
269
+ defaultBlock
270
+ })
271
+ );
272
+ });
273
+ }
274
+ function requestTranslationOverrides(locale) {
275
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
276
+ return new Promise((resolve, reject) => {
277
+ const timer = setTimeout(() => {
278
+ pendingTranslationRequests.delete(requestId);
279
+ reject(
280
+ new Error(
281
+ `REQUEST_TRANSLATION_OVERRIDES timed out for locale ${locale}`
282
+ )
283
+ );
284
+ }, 5e3);
285
+ pendingTranslationRequests.set(requestId, { resolve, timer });
286
+ sendMessage(
287
+ createRequestTranslationOverridesMessage({
288
+ requestId,
289
+ locale
290
+ })
291
+ );
292
+ });
293
+ }
294
+ function requestGlobalStyles() {
295
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
296
+ return new Promise((resolve, reject) => {
297
+ const timer = setTimeout(() => {
298
+ pendingGlobalStylesRequests.delete(requestId);
299
+ reject(new Error("REQUEST_GLOBAL_STYLES timed out"));
300
+ }, 5e3);
301
+ pendingGlobalStylesRequests.set(requestId, { resolve, timer });
302
+ sendMessage(createRequestGlobalStylesMessage({ requestId }));
303
+ });
304
+ }
305
+ function handleWindowMessage(event) {
306
+ if (parentOrigin !== "*" && event.origin !== parentOrigin) {
307
+ return;
308
+ }
309
+ const { data } = event;
310
+ if (isEditorMessage(data)) {
311
+ if (data.type === "PROVIDE_THEME_STATE" && data.payload.requestId) {
312
+ const pending = pendingRequests.get(data.payload.requestId);
313
+ if (pending) {
314
+ clearTimeout(pending.timer);
315
+ pendingRequests.delete(data.payload.requestId);
316
+ pending.resolve({ blocks: data.payload.blocks });
317
+ }
318
+ } else if (data.type === "PROVIDE_TRANSLATION_OVERRIDES" && data.payload.requestId) {
319
+ const pending = pendingTranslationRequests.get(data.payload.requestId);
320
+ if (pending) {
321
+ clearTimeout(pending.timer);
322
+ pendingTranslationRequests.delete(data.payload.requestId);
323
+ pending.resolve(data.payload.overrides);
324
+ }
325
+ } else if (data.type === "PROVIDE_GLOBAL_STYLES" && data.payload.requestId) {
326
+ const pending = pendingGlobalStylesRequests.get(data.payload.requestId);
327
+ if (pending) {
328
+ clearTimeout(pending.timer);
329
+ pendingGlobalStylesRequests.delete(data.payload.requestId);
330
+ pending.resolve(data.payload.styles);
331
+ }
332
+ } else if (data.type === "SELECT_BLOCK") {
333
+ updateBlockSelection(data.payload.blockId);
334
+ }
335
+ messageHandlers.forEach((handler) => handler(data));
336
+ }
337
+ }
338
+ window.addEventListener("message", handleWindowMessage);
339
+ if (document.readyState === "complete") {
340
+ sendMessage({
341
+ type: "IFRAME_READY",
342
+ payload: {},
343
+ timestamp: Date.now()
344
+ });
345
+ } else {
346
+ window.addEventListener("load", () => {
347
+ sendMessage({
348
+ type: "IFRAME_READY",
349
+ payload: {},
350
+ timestamp: Date.now()
351
+ });
352
+ });
353
+ }
354
+ const isEditorMode = window.parent !== window;
355
+ function onBlockPresetChange(blockId, callback) {
356
+ return onMessage((message) => {
357
+ if (message.type !== "SET_BLOCK_PRESET")
358
+ return;
359
+ const presetMessage = message;
360
+ if (presetMessage.payload.blockId !== blockId)
361
+ return;
362
+ const preset = presetMessage.payload.preset;
363
+ callback(
364
+ preset
365
+ );
366
+ });
367
+ }
368
+ function destroy() {
369
+ window.removeEventListener("message", handleWindowMessage);
370
+ document.removeEventListener("click", handleGlobalClick, true);
371
+ for (const [, { timer }] of pendingRequests) {
372
+ clearTimeout(timer);
373
+ }
374
+ pendingRequests.clear();
375
+ for (const [, { timer }] of pendingTranslationRequests) {
376
+ clearTimeout(timer);
377
+ }
378
+ pendingTranslationRequests.clear();
379
+ for (const [, { timer }] of pendingGlobalStylesRequests) {
380
+ clearTimeout(timer);
381
+ }
382
+ pendingGlobalStylesRequests.clear();
383
+ messageHandlers.length = 0;
384
+ bridgeInstance = null;
385
+ }
386
+ bridgeInstance = {
387
+ isEditorMode,
388
+ sendMessage,
389
+ onMessage,
390
+ onBlockPresetChange,
391
+ requestThemeState,
392
+ requestTranslationOverrides,
393
+ requestGlobalStyles,
394
+ destroy
395
+ };
396
+ return bridgeInstance;
397
+ }
398
+ export {
399
+ createFocusInlineTextMessage as a,
400
+ createUpdateBlockTranslationMessage as b,
401
+ createEditorBridge as c,
402
+ createRemoveBlockMessage as d,
403
+ createRegisterBlocksMessage as e,
404
+ createRegisterRoutesMessage as f,
405
+ isIframeMessage as g,
406
+ createProvideThemeStateMessage as h,
407
+ isEditorMessage as i,
408
+ createRequestThemeStateMessage as j,
409
+ createRequestTranslationOverridesMessage as k,
410
+ createProvideTranslationOverridesMessage as l,
411
+ createSelectBlockMessage as m,
412
+ createUpdateBlockPropsMessage as n,
413
+ createAddBlockMessage as o,
414
+ createMoveBlockMessage as p,
415
+ createSetBlockPresetMessage as q,
416
+ createSetLocaleMessage as r,
417
+ createSetGlobalStylesMessage as s,
418
+ createRequestGlobalStylesMessage as t,
419
+ createProvideGlobalStylesMessage as u,
420
+ getEditorBridge as v
421
+ };