@juo/blocks 1.0.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 (153) hide show
  1. package/dist/ExtensionRoot-CZyBNJZY.js +159 -0
  2. package/dist/block-VhmfGB3N.js +51 -0
  3. package/dist/block.d.ts +96 -0
  4. package/dist/block.d.ts.map +1 -0
  5. package/dist/bridge-DQsM97cH.js +490 -0
  6. package/dist/context.d.ts +76 -0
  7. package/dist/context.d.ts.map +1 -0
  8. package/dist/context.test.d.ts +2 -0
  9. package/dist/context.test.d.ts.map +1 -0
  10. package/dist/core.js +1163 -0
  11. package/dist/editor/bridge.d.ts +75 -0
  12. package/dist/editor/bridge.d.ts.map +1 -0
  13. package/dist/editor/bridge.test.d.ts +2 -0
  14. package/dist/editor/bridge.test.d.ts.map +1 -0
  15. package/dist/editor/components.d.ts +31 -0
  16. package/dist/editor/components.d.ts.map +1 -0
  17. package/dist/editor/handler.d.ts +10 -0
  18. package/dist/editor/handler.d.ts.map +1 -0
  19. package/dist/editor/main.d.ts +17 -0
  20. package/dist/editor/main.d.ts.map +1 -0
  21. package/dist/editor/messages.d.ts +233 -0
  22. package/dist/editor/messages.d.ts.map +1 -0
  23. package/dist/editor.js +711 -0
  24. package/dist/flows/MockWorkflowApiAdapter.d.ts +13 -0
  25. package/dist/flows/MockWorkflowApiAdapter.d.ts.map +1 -0
  26. package/dist/flows/WorkflowService.d.ts +175 -0
  27. package/dist/flows/WorkflowService.d.ts.map +1 -0
  28. package/dist/flows/__tests__/WorkflowService.test.d.ts +2 -0
  29. package/dist/flows/__tests__/WorkflowService.test.d.ts.map +1 -0
  30. package/dist/flows/__tests__/defaults.test.d.ts +2 -0
  31. package/dist/flows/__tests__/defaults.test.d.ts.map +1 -0
  32. package/dist/flows/__tests__/juo-workflow.test.d.ts +2 -0
  33. package/dist/flows/__tests__/juo-workflow.test.d.ts.map +1 -0
  34. package/dist/flows/__tests__/overlay-behavior.test.d.ts +2 -0
  35. package/dist/flows/__tests__/overlay-behavior.test.d.ts.map +1 -0
  36. package/dist/flows/__tests__/theme-state-surfaces.test.d.ts +2 -0
  37. package/dist/flows/__tests__/theme-state-surfaces.test.d.ts.map +1 -0
  38. package/dist/flows/defaults.d.ts +15 -0
  39. package/dist/flows/defaults.d.ts.map +1 -0
  40. package/dist/flows/index.d.ts +4 -0
  41. package/dist/flows/index.d.ts.map +1 -0
  42. package/dist/flows/juo-workflow.d.ts +48 -0
  43. package/dist/flows/juo-workflow.d.ts.map +1 -0
  44. package/dist/juo-workflow-RSrOuKUH.js +591 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/preact/block.d.ts +21 -0
  48. package/dist/preact/block.d.ts.map +1 -0
  49. package/dist/preact/block.test.d.ts +2 -0
  50. package/dist/preact/block.test.d.ts.map +1 -0
  51. package/dist/preact/bridge.d.ts +11 -0
  52. package/dist/preact/bridge.d.ts.map +1 -0
  53. package/dist/preact/context.d.ts +31 -0
  54. package/dist/preact/context.d.ts.map +1 -0
  55. package/dist/preact/main.d.ts +11 -0
  56. package/dist/preact/main.d.ts.map +1 -0
  57. package/dist/preact/signals.d.ts +23 -0
  58. package/dist/preact/signals.d.ts.map +1 -0
  59. package/dist/preact.js +230 -0
  60. package/dist/react/block.d.ts +21 -0
  61. package/dist/react/block.d.ts.map +1 -0
  62. package/dist/react/block.test.d.ts +2 -0
  63. package/dist/react/block.test.d.ts.map +1 -0
  64. package/dist/react/bridge.d.ts +11 -0
  65. package/dist/react/bridge.d.ts.map +1 -0
  66. package/dist/react/context.d.ts +28 -0
  67. package/dist/react/context.d.ts.map +1 -0
  68. package/dist/react/main.d.ts +11 -0
  69. package/dist/react/main.d.ts.map +1 -0
  70. package/dist/react/signals.d.ts +23 -0
  71. package/dist/react/signals.d.ts.map +1 -0
  72. package/dist/react.js +205 -0
  73. package/dist/services/index.d.ts +4 -0
  74. package/dist/services/index.d.ts.map +1 -0
  75. package/dist/services/login/index.d.ts +23 -0
  76. package/dist/services/login/index.d.ts.map +1 -0
  77. package/dist/services/login/loginService.d.ts +82 -0
  78. package/dist/services/login/loginService.d.ts.map +1 -0
  79. package/dist/services/product/adapter.d.ts +20 -0
  80. package/dist/services/product/adapter.d.ts.map +1 -0
  81. package/dist/services/product/index.d.ts +5 -0
  82. package/dist/services/product/index.d.ts.map +1 -0
  83. package/dist/services/product/productService.d.ts +12 -0
  84. package/dist/services/product/productService.d.ts.map +1 -0
  85. package/dist/services/product/types.d.ts +32 -0
  86. package/dist/services/product/types.d.ts.map +1 -0
  87. package/dist/services/subscription/adapter.d.ts +49 -0
  88. package/dist/services/subscription/adapter.d.ts.map +1 -0
  89. package/dist/services/subscription/index.d.ts +5 -0
  90. package/dist/services/subscription/index.d.ts.map +1 -0
  91. package/dist/services/subscription/list.d.ts +22 -0
  92. package/dist/services/subscription/list.d.ts.map +1 -0
  93. package/dist/services/subscription/store.d.ts +30 -0
  94. package/dist/services/subscription/store.d.ts.map +1 -0
  95. package/dist/services/subscription/subscriptionService.d.ts +12 -0
  96. package/dist/services/subscription/subscriptionService.d.ts.map +1 -0
  97. package/dist/services/subscription/types.d.ts +76 -0
  98. package/dist/services/subscription/types.d.ts.map +1 -0
  99. package/dist/shared/block.d.ts +17 -0
  100. package/dist/shared/block.d.ts.map +1 -0
  101. package/dist/shared/context.d.ts +16 -0
  102. package/dist/shared/context.d.ts.map +1 -0
  103. package/dist/shared/signals.d.ts +17 -0
  104. package/dist/shared/signals.d.ts.map +1 -0
  105. package/dist/state.d.ts +81 -0
  106. package/dist/state.d.ts.map +1 -0
  107. package/dist/theme-state-BZplRS92.js +886 -0
  108. package/dist/theme-state.d.ts +85 -0
  109. package/dist/theme-state.d.ts.map +1 -0
  110. package/dist/theme-state.locales.test.d.ts +2 -0
  111. package/dist/theme-state.locales.test.d.ts.map +1 -0
  112. package/dist/translation.d.ts +14 -0
  113. package/dist/translation.d.ts.map +1 -0
  114. package/dist/translation.test.d.ts +2 -0
  115. package/dist/translation.test.d.ts.map +1 -0
  116. package/dist/utils/index.d.ts +32 -0
  117. package/dist/utils/index.d.ts.map +1 -0
  118. package/dist/utils/login.d.ts +11 -0
  119. package/dist/utils/login.d.ts.map +1 -0
  120. package/dist/utils/uuid.d.ts +2 -0
  121. package/dist/utils/uuid.d.ts.map +1 -0
  122. package/dist/vue/block.d.ts +7 -0
  123. package/dist/vue/block.d.ts.map +1 -0
  124. package/dist/vue/bridge.d.ts +11 -0
  125. package/dist/vue/bridge.d.ts.map +1 -0
  126. package/dist/vue/context.d.ts +24 -0
  127. package/dist/vue/context.d.ts.map +1 -0
  128. package/dist/vue/main.d.ts +6 -0
  129. package/dist/vue/main.d.ts.map +1 -0
  130. package/dist/vue/signals.d.ts +5 -0
  131. package/dist/vue/signals.d.ts.map +1 -0
  132. package/dist/vue/target.d.ts +2 -0
  133. package/dist/vue/target.d.ts.map +1 -0
  134. package/dist/vue/transform.d.ts +2 -0
  135. package/dist/vue/transform.d.ts.map +1 -0
  136. package/dist/vue.js +254 -0
  137. package/dist/web-components/Block.d.ts +17 -0
  138. package/dist/web-components/Block.d.ts.map +1 -0
  139. package/dist/web-components/Block.test.d.ts +2 -0
  140. package/dist/web-components/Block.test.d.ts.map +1 -0
  141. package/dist/web-components/ExtensionRoot.d.ts +29 -0
  142. package/dist/web-components/ExtensionRoot.d.ts.map +1 -0
  143. package/dist/web-components/editor/InlineText.d.ts +29 -0
  144. package/dist/web-components/editor/InlineText.d.ts.map +1 -0
  145. package/dist/web-components/editor/main.d.ts +2 -0
  146. package/dist/web-components/editor/main.d.ts.map +1 -0
  147. package/dist/web-components/runtime/InlineText.d.ts +6 -0
  148. package/dist/web-components/runtime/InlineText.d.ts.map +1 -0
  149. package/dist/web-components/runtime/main.d.ts +2 -0
  150. package/dist/web-components/runtime/main.d.ts.map +1 -0
  151. package/dist/web-components-editor.js +183 -0
  152. package/dist/web-components-runtime.js +55 -0
  153. package/package.json +62 -0
@@ -0,0 +1,490 @@
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" || message.type === "SCROLL_SYNC" || message.type === "REQUEST_CONTENT_HEIGHT";
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 === "REGISTER_BLOCK_TRANSLATION_KEYS" || message.type === "FOCUS_INLINE_TEXT" || message.type === "REQUEST_GLOBAL_STYLES" || message.type === "PROVIDE_INITIAL_GLOBAL_STYLES" || message.type === "REPORT_CONTENT_HEIGHT" || message.type === "SCROLL_SYNC";
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
+ locales: block.locales == null ? block.locales : JSON.parse(JSON.stringify(block.locales))
91
+ }));
92
+ return {
93
+ type: "REGISTER_BLOCKS",
94
+ payload: {
95
+ blocks: serializedBlocks
96
+ },
97
+ timestamp: Date.now()
98
+ };
99
+ }
100
+ function createSetBlockPresetMessage(payload) {
101
+ return {
102
+ type: "SET_BLOCK_PRESET",
103
+ payload,
104
+ timestamp: Date.now()
105
+ };
106
+ }
107
+ function createSetLocaleMessage(payload) {
108
+ return {
109
+ type: "SET_LOCALE",
110
+ payload,
111
+ timestamp: Date.now()
112
+ };
113
+ }
114
+ function createRegisterBlockTranslationKeysMessage(payload) {
115
+ return {
116
+ type: "REGISTER_BLOCK_TRANSLATION_KEYS",
117
+ payload,
118
+ timestamp: Date.now()
119
+ };
120
+ }
121
+ function createFocusInlineTextMessage(payload, blockId) {
122
+ return {
123
+ type: "FOCUS_INLINE_TEXT",
124
+ payload,
125
+ blockId,
126
+ timestamp: Date.now()
127
+ };
128
+ }
129
+ function createRegisterRoutesMessage(payload) {
130
+ return {
131
+ type: "REGISTER_ROUTES",
132
+ payload,
133
+ timestamp: Date.now()
134
+ };
135
+ }
136
+ function createSetGlobalStylesMessage(payload) {
137
+ return {
138
+ type: "SET_GLOBAL_STYLES",
139
+ payload,
140
+ timestamp: Date.now()
141
+ };
142
+ }
143
+ function createRequestGlobalStylesMessage(payload) {
144
+ return {
145
+ type: "REQUEST_GLOBAL_STYLES",
146
+ payload,
147
+ timestamp: Date.now()
148
+ };
149
+ }
150
+ function createProvideGlobalStylesMessage(payload) {
151
+ return {
152
+ type: "PROVIDE_GLOBAL_STYLES",
153
+ payload,
154
+ timestamp: Date.now()
155
+ };
156
+ }
157
+ function createProvideInitialGlobalStylesMessage(payload) {
158
+ return {
159
+ type: "PROVIDE_INITIAL_GLOBAL_STYLES",
160
+ payload,
161
+ timestamp: Date.now()
162
+ };
163
+ }
164
+ function createScrollSyncMessage(payload) {
165
+ return {
166
+ type: "SCROLL_SYNC",
167
+ payload,
168
+ timestamp: Date.now()
169
+ };
170
+ }
171
+ function createReportContentHeightMessage(payload) {
172
+ return {
173
+ type: "REPORT_CONTENT_HEIGHT",
174
+ payload,
175
+ timestamp: Date.now()
176
+ };
177
+ }
178
+ let bridgeInstance = null;
179
+ function getEditorBridge() {
180
+ return bridgeInstance;
181
+ }
182
+ function createEditorBridge() {
183
+ if (bridgeInstance !== null) {
184
+ return bridgeInstance;
185
+ }
186
+ const messageHandlers = [];
187
+ const selectedBlockId = { value: null };
188
+ const pendingRequests = /* @__PURE__ */ new Map();
189
+ const pendingTranslationRequests = /* @__PURE__ */ new Map();
190
+ const pendingGlobalStylesRequests = /* @__PURE__ */ new Map();
191
+ let parentOrigin = "*";
192
+ const frame = window.parent || window;
193
+ if (window.parent !== window) {
194
+ try {
195
+ parentOrigin = window.parent.location.origin;
196
+ } catch {
197
+ parentOrigin = "*";
198
+ }
199
+ }
200
+ function sendMessage(message) {
201
+ frame.postMessage(message, parentOrigin);
202
+ }
203
+ function onMessage(handler) {
204
+ messageHandlers.push(handler);
205
+ return {
206
+ unsubscribe: () => {
207
+ const index = messageHandlers.indexOf(handler);
208
+ if (index !== -1) {
209
+ messageHandlers.splice(index, 1);
210
+ }
211
+ }
212
+ };
213
+ }
214
+ function updateBlockSelection(blockId) {
215
+ selectedBlockId.value = blockId;
216
+ }
217
+ function handleGlobalClick(event) {
218
+ const path = event.composedPath();
219
+ if (!path.some(
220
+ (node) => node instanceof HTMLElement && node.tagName !== "HTML"
221
+ )) {
222
+ return;
223
+ }
224
+ const isOverlay = path.some((node) => {
225
+ if (!(node instanceof HTMLElement)) return false;
226
+ let current = node;
227
+ while (current) {
228
+ const computedStyle = window.getComputedStyle(current);
229
+ const zIndex = parseInt(computedStyle.zIndex, 10);
230
+ if (!isNaN(zIndex) && zIndex >= 50 || ["listbox", "menu", "dialog"].includes(
231
+ current.getAttribute("role") || ""
232
+ )) {
233
+ return true;
234
+ }
235
+ current = current.parentElement;
236
+ }
237
+ return false;
238
+ });
239
+ const isEditorUI = path.some((node) => {
240
+ if (!(node instanceof HTMLElement)) return false;
241
+ let current = node;
242
+ const root = node.getRootNode();
243
+ while (current && current !== root) {
244
+ const classList = current.classList;
245
+ 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")) {
246
+ return true;
247
+ }
248
+ current = current.parentElement;
249
+ }
250
+ return false;
251
+ });
252
+ let blockWrapper = null;
253
+ for (const node of path) {
254
+ if (node instanceof HTMLElement && node.tagName === "JUO-EDITOR-BLOCK-WRAPPER") {
255
+ blockWrapper = node;
256
+ break;
257
+ }
258
+ }
259
+ if (isOverlay && !blockWrapper) {
260
+ return;
261
+ }
262
+ if (!blockWrapper && isEditorUI) {
263
+ return;
264
+ }
265
+ const clickedBlockId = (blockWrapper == null ? void 0 : blockWrapper.getAttribute("data-block-id")) || null;
266
+ if (clickedBlockId && clickedBlockId === selectedBlockId.value) {
267
+ return;
268
+ }
269
+ const newBlockId = clickedBlockId || null;
270
+ if (newBlockId !== selectedBlockId.value) {
271
+ const message = createSelectBlockMessage(
272
+ { blockId: newBlockId },
273
+ newBlockId || void 0
274
+ );
275
+ updateBlockSelection(newBlockId);
276
+ messageHandlers.forEach((handler) => handler(message));
277
+ sendMessage(message);
278
+ }
279
+ }
280
+ document.addEventListener("click", handleGlobalClick, true);
281
+ function requestThemeState(surface, id, defaultBlock) {
282
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
283
+ return new Promise((resolve, reject) => {
284
+ const timer = setTimeout(() => {
285
+ pendingRequests.delete(requestId);
286
+ reject(
287
+ new Error(`REQUEST_THEME_STATE timed out for (${surface}, ${id})`)
288
+ );
289
+ }, 5e3);
290
+ pendingRequests.set(requestId, { resolve, timer });
291
+ sendMessage(
292
+ createRequestThemeStateMessage({
293
+ requestId,
294
+ surface,
295
+ id,
296
+ defaultBlock
297
+ })
298
+ );
299
+ });
300
+ }
301
+ function requestTranslationOverrides(locale) {
302
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
303
+ return new Promise((resolve, reject) => {
304
+ const timer = setTimeout(() => {
305
+ pendingTranslationRequests.delete(requestId);
306
+ reject(
307
+ new Error(
308
+ `REQUEST_TRANSLATION_OVERRIDES timed out for locale ${locale}`
309
+ )
310
+ );
311
+ }, 5e3);
312
+ pendingTranslationRequests.set(requestId, { resolve, timer });
313
+ sendMessage(
314
+ createRequestTranslationOverridesMessage({
315
+ requestId,
316
+ locale
317
+ })
318
+ );
319
+ });
320
+ }
321
+ function requestGlobalStyles() {
322
+ const requestId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2);
323
+ return new Promise((resolve, reject) => {
324
+ const timer = setTimeout(() => {
325
+ pendingGlobalStylesRequests.delete(requestId);
326
+ reject(new Error("REQUEST_GLOBAL_STYLES timed out"));
327
+ }, 5e3);
328
+ pendingGlobalStylesRequests.set(requestId, { resolve, timer });
329
+ sendMessage(createRequestGlobalStylesMessage({ requestId }));
330
+ });
331
+ }
332
+ function handleWindowMessage(event) {
333
+ if (parentOrigin !== "*" && event.origin !== parentOrigin) {
334
+ return;
335
+ }
336
+ const { data } = event;
337
+ if (isEditorMessage(data)) {
338
+ if (data.type === "PROVIDE_THEME_STATE" && data.payload.requestId) {
339
+ const pending = pendingRequests.get(data.payload.requestId);
340
+ if (pending) {
341
+ clearTimeout(pending.timer);
342
+ pendingRequests.delete(data.payload.requestId);
343
+ pending.resolve({ blocks: data.payload.blocks });
344
+ }
345
+ } else if (data.type === "PROVIDE_TRANSLATION_OVERRIDES" && data.payload.requestId) {
346
+ const pending = pendingTranslationRequests.get(data.payload.requestId);
347
+ if (pending) {
348
+ clearTimeout(pending.timer);
349
+ pendingTranslationRequests.delete(data.payload.requestId);
350
+ pending.resolve(data.payload.overrides);
351
+ }
352
+ } else if (data.type === "PROVIDE_GLOBAL_STYLES" && data.payload.requestId) {
353
+ const pending = pendingGlobalStylesRequests.get(data.payload.requestId);
354
+ if (pending) {
355
+ clearTimeout(pending.timer);
356
+ pendingGlobalStylesRequests.delete(data.payload.requestId);
357
+ pending.resolve(data.payload.styles);
358
+ }
359
+ } else if (data.type === "SELECT_BLOCK") {
360
+ updateBlockSelection(data.payload.blockId);
361
+ } else if (data.type === "SCROLL_SYNC") {
362
+ suppressScrollReport = true;
363
+ window.scrollTo(0, data.payload.scrollY);
364
+ return;
365
+ } else if (data.type === "REQUEST_CONTENT_HEIGHT") {
366
+ reportContentHeight();
367
+ return;
368
+ }
369
+ messageHandlers.forEach((handler) => handler(data));
370
+ }
371
+ }
372
+ window.addEventListener("message", handleWindowMessage);
373
+ if (document.readyState === "complete") {
374
+ sendMessage({
375
+ type: "IFRAME_READY",
376
+ payload: {},
377
+ timestamp: Date.now()
378
+ });
379
+ } else {
380
+ window.addEventListener("load", () => {
381
+ sendMessage({
382
+ type: "IFRAME_READY",
383
+ payload: {},
384
+ timestamp: Date.now()
385
+ });
386
+ });
387
+ }
388
+ const isEditorMode = window.parent !== window;
389
+ let ghostScrollStyleEl = null;
390
+ let ghostScrollObserver = null;
391
+ let suppressScrollReport = false;
392
+ function reportContentHeight() {
393
+ var _a;
394
+ if (!isEditorMode) return;
395
+ const height = Math.max(
396
+ document.documentElement.scrollHeight,
397
+ ((_a = document.body) == null ? void 0 : _a.scrollHeight) ?? 0
398
+ );
399
+ sendMessage(createReportContentHeightMessage({ height }));
400
+ }
401
+ function handleScrollEvent() {
402
+ if (suppressScrollReport) {
403
+ suppressScrollReport = false;
404
+ return;
405
+ }
406
+ sendMessage(createScrollSyncMessage({ scrollY: window.scrollY }));
407
+ }
408
+ if (isEditorMode) {
409
+ ghostScrollStyleEl = document.createElement("style");
410
+ ghostScrollStyleEl.textContent = "html { scrollbar-width: none; } html::-webkit-scrollbar { display: none; }";
411
+ document.head.appendChild(ghostScrollStyleEl);
412
+ window.addEventListener("scroll", handleScrollEvent, { passive: true });
413
+ ghostScrollObserver = new ResizeObserver(reportContentHeight);
414
+ ghostScrollObserver.observe(document.documentElement);
415
+ reportContentHeight();
416
+ }
417
+ function onBlockPresetChange(blockId, callback) {
418
+ return onMessage((message) => {
419
+ if (message.type !== "SET_BLOCK_PRESET") return;
420
+ const presetMessage = message;
421
+ if (presetMessage.payload.blockId !== blockId) return;
422
+ const preset = presetMessage.payload.preset;
423
+ callback(
424
+ preset
425
+ );
426
+ });
427
+ }
428
+ function destroy() {
429
+ window.removeEventListener("message", handleWindowMessage);
430
+ document.removeEventListener("click", handleGlobalClick, true);
431
+ window.removeEventListener("scroll", handleScrollEvent);
432
+ ghostScrollObserver == null ? void 0 : ghostScrollObserver.disconnect();
433
+ ghostScrollObserver = null;
434
+ ghostScrollStyleEl == null ? void 0 : ghostScrollStyleEl.remove();
435
+ ghostScrollStyleEl = null;
436
+ for (const [, { timer }] of pendingRequests) {
437
+ clearTimeout(timer);
438
+ }
439
+ pendingRequests.clear();
440
+ for (const [, { timer }] of pendingTranslationRequests) {
441
+ clearTimeout(timer);
442
+ }
443
+ pendingTranslationRequests.clear();
444
+ for (const [, { timer }] of pendingGlobalStylesRequests) {
445
+ clearTimeout(timer);
446
+ }
447
+ pendingGlobalStylesRequests.clear();
448
+ messageHandlers.length = 0;
449
+ bridgeInstance = null;
450
+ }
451
+ bridgeInstance = {
452
+ isEditorMode,
453
+ sendMessage,
454
+ onMessage,
455
+ onBlockPresetChange,
456
+ requestThemeState,
457
+ requestTranslationOverrides,
458
+ requestGlobalStyles,
459
+ destroy
460
+ };
461
+ return bridgeInstance;
462
+ }
463
+ export {
464
+ createEditorBridge as a,
465
+ createFocusInlineTextMessage as b,
466
+ createRegisterBlockTranslationKeysMessage as c,
467
+ createUpdateBlockTranslationMessage as d,
468
+ createSelectBlockMessage as e,
469
+ createRemoveBlockMessage as f,
470
+ createRegisterBlocksMessage as g,
471
+ createRegisterRoutesMessage as h,
472
+ isEditorMessage as i,
473
+ isIframeMessage as j,
474
+ createProvideThemeStateMessage as k,
475
+ createRequestThemeStateMessage as l,
476
+ createRequestTranslationOverridesMessage as m,
477
+ createProvideTranslationOverridesMessage as n,
478
+ createUpdateBlockPropsMessage as o,
479
+ createAddBlockMessage as p,
480
+ createMoveBlockMessage as q,
481
+ createSetBlockPresetMessage as r,
482
+ createSetLocaleMessage as s,
483
+ createSetGlobalStylesMessage as t,
484
+ createRequestGlobalStylesMessage as u,
485
+ createProvideGlobalStylesMessage as v,
486
+ createProvideInitialGlobalStylesMessage as w,
487
+ createScrollSyncMessage as x,
488
+ createReportContentHeightMessage as y,
489
+ getEditorBridge as z
490
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @see https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md#the-context-request-event
3
+ */
4
+ /**
5
+ * A context key.
6
+ *
7
+ * A context key can be any type of object, including strings and symbols. The
8
+ * Context type brands the key type with the `__context__` property that
9
+ * carries the type of the value the context references.
10
+ */
11
+ export type Context<KeyType, ValueType> = KeyType & {
12
+ __context__: ValueType;
13
+ };
14
+ /**
15
+ * An unknown context type
16
+ */
17
+ export type UnknownContext = Context<unknown, unknown>;
18
+ /**
19
+ * A helper type which can extract a Context value type from a Context type
20
+ */
21
+ export type ContextType<T extends UnknownContext> = T extends Context<infer _, infer V> ? V : never;
22
+ /**
23
+ * A function which creates a Context value object
24
+ */
25
+ export declare const createContext: <ValueType>(key: unknown) => Context<typeof key, ValueType>;
26
+ /**
27
+ * A callback which is provided by a context requester and is called with the value satisfying the request.
28
+ * This callback can be called multiple times by context providers as the requested value is changed.
29
+ */
30
+ export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
31
+ /**
32
+ * An event fired by a context requester to signal it desires a named context.
33
+ *
34
+ * A provider should inspect the `context` property of the event to determine if it has a value that can
35
+ * satisfy the request, calling the `callback` with the requested value if so.
36
+ *
37
+ * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback
38
+ * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`
39
+ * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.
40
+ */
41
+ export declare class ContextRequestEvent<T extends UnknownContext> extends Event {
42
+ readonly context: T;
43
+ readonly callback: ContextCallback<ContextType<T>>;
44
+ readonly subscribe?: boolean | undefined;
45
+ constructor(context: T, callback: ContextCallback<ContextType<T>>, subscribe?: boolean | undefined);
46
+ }
47
+ export declare class ContextProvideEvent<T extends UnknownContext> extends Event {
48
+ readonly context: T;
49
+ readonly value: ContextType<T>;
50
+ readonly subscribe?: boolean | undefined;
51
+ constructor(context: T, value: ContextType<T>, subscribe?: boolean | undefined);
52
+ }
53
+ declare global {
54
+ interface HTMLElementEventMap {
55
+ /**
56
+ * A 'context-request' event can be emitted by any element which desires
57
+ * a context value to be injected by an external provider.
58
+ */
59
+ "context-request": ContextRequestEvent<Context<unknown, unknown>>;
60
+ /**
61
+ * A 'context-provide' event can be emitted by any element which desires
62
+ * to provide a context value for 'context-request' events.
63
+ */
64
+ "context-provide": ContextProvideEvent<Context<unknown, unknown>>;
65
+ }
66
+ }
67
+ export declare function provideContext<C extends UnknownContext>(target: HTMLElement, context: C, init: ContextType<C>): void;
68
+ export declare function injectContext<C extends UnknownContext>(target: HTMLElement, context: C): ContextType<C>;
69
+ export type ContextSubscriberCallback<ValueType> = (value: ValueType) => void;
70
+ export declare function subscribeContext<C extends UnknownContext>(target: HTMLElement, context: C, callback: ContextSubscriberCallback<ContextType<C>>): () => void;
71
+ export declare class ContextRoot extends HTMLElement {
72
+ private store;
73
+ private callbacks;
74
+ connectedCallback(): void;
75
+ }
76
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG;IAAE,WAAW,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,SAAS,OAAO,CACnE,MAAM,CAAC,EACP,MAAM,CAAC,CACR,GACG,CAAC,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO,OAAO,KAC5C,OAAO,CAAC,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,SAAS,IAAI,CACvC,KAAK,EAAE,SAAS,EAChB,WAAW,CAAC,EAAE,MAAM,IAAI,KACrB,IAAI,CAAC;AAEV;;;;;;;;;GASG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,KAAK;aAEpD,OAAO,EAAE,CAAC;aACV,QAAQ,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;aACzC,SAAS,CAAC,EAAE,OAAO;gBAFnB,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,SAAS,CAAC,EAAE,OAAO,YAAA;CAItC;AAED,qBAAa,mBAAmB,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,KAAK;aAEpD,OAAO,EAAE,CAAC;aACV,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;aACrB,SAAS,CAAC,EAAE,OAAO;gBAFnB,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,SAAS,CAAC,EAAE,OAAO,YAAA;CAItC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,mBAAmB;QAC3B;;;WAGG;QACH,iBAAiB,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAElE;;;WAGG;QACH,iBAAiB,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;KACnE;CACF;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,cAAc,EACrD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,CAAC,EACV,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,IAAI,CAIN;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EACpD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,CAAC,GACT,WAAW,CAAC,CAAC,CAAC,CAehB;AAED,MAAM,MAAM,yBAAyB,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,cAAc,EACvD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,yBAAyB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAClD,MAAM,IAAI,CAuBZ;AAED,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,SAAS,CAAsD;IAEvE,iBAAiB;CAgElB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.test.d.ts","sourceRoot":"","sources":["../src/context.test.ts"],"names":[],"mappings":""}