@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
package/dist/editor.js ADDED
@@ -0,0 +1,711 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { getDefinedBlocks, onRegisterBlock } from "@juo/blocks";
5
+ import { a as createEditorBridge, f as createRemoveBlockMessage, g as createRegisterBlocksMessage, h as createRegisterRoutesMessage } from "./bridge-DQsM97cH.js";
6
+ import { p, b, q, v, w, k, n, c, y, u, l, m, x, e, r, t, s, o, d, z, i, j } from "./bridge-DQsM97cH.js";
7
+ import { e as createBlockInstanceFromObject, m as indexOverrides } from "./theme-state-BZplRS92.js";
8
+ function createEditorHandler(options) {
9
+ const { themeState, onBlockSelection } = options;
10
+ const blockSurfaceIndex = /* @__PURE__ */ new Map();
11
+ function getBlocks(surface) {
12
+ return surface === "overlay" ? themeState.overlay.blocks : themeState.page.blocks;
13
+ }
14
+ function indexSurface(surface, blocks) {
15
+ for (const [id, value] of blockSurfaceIndex) {
16
+ if (value === surface) {
17
+ blockSurfaceIndex.delete(id);
18
+ }
19
+ }
20
+ const visit = (block) => {
21
+ if (!(block == null ? void 0 : block.id)) return;
22
+ blockSurfaceIndex.set(block.id, surface);
23
+ for (const slotBlocks of Object.values(block.slots || {})) {
24
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
25
+ for (const child of slotArray) {
26
+ if (typeof child !== "string") {
27
+ visit(child);
28
+ }
29
+ }
30
+ }
31
+ };
32
+ for (const block of blocks) {
33
+ visit(block);
34
+ }
35
+ }
36
+ function resolveSurfaceForMessage(message) {
37
+ const lookup = (id) => id ? blockSurfaceIndex.get(id) : void 0;
38
+ if (message.type === "UPDATE_BLOCK_PROPS") {
39
+ return lookup(message.payload.blockId) ?? "page";
40
+ }
41
+ if (message.type === "REMOVE_BLOCK") {
42
+ return lookup(message.payload.blockId) ?? lookup(message.payload.location.parentId) ?? "page";
43
+ }
44
+ if (message.type === "MOVE_BLOCK") {
45
+ return lookup(message.payload.blockId) ?? lookup(message.payload.location.parentId) ?? "page";
46
+ }
47
+ if (message.type === "ADD_BLOCK") {
48
+ const location = message.payload.location;
49
+ if (location.type === "append") {
50
+ return lookup(location.parentId) ?? "page";
51
+ }
52
+ return lookup(location.targetId) ?? "page";
53
+ }
54
+ return "page";
55
+ }
56
+ function handleMessage(message) {
57
+ var _a, _b;
58
+ if (message.type === "SET_GLOBAL_STYLES") {
59
+ themeState.setGlobalStyles(message.payload.styles);
60
+ return;
61
+ }
62
+ if (message.type === "PROVIDE_THEME_STATE") {
63
+ const surface = message.payload.surface ?? "page";
64
+ const blocks = ((_a = message.payload.blocks) == null ? void 0 : _a.map(
65
+ (block) => createBlockInstanceFromObject(block)
66
+ )) || [];
67
+ const target = getBlocks(surface);
68
+ target.value = blocks;
69
+ indexSurface(surface, target.value);
70
+ } else if (message.type === "SELECT_BLOCK") {
71
+ const blockId = message.payload.blockId;
72
+ if (onBlockSelection) {
73
+ onBlockSelection(blockId);
74
+ }
75
+ } else if (message.type === "PROVIDE_TRANSLATION_OVERRIDES" && message.payload.requestId == null) {
76
+ const catalogs = themeState.locales.catalogs;
77
+ const current = catalogs.value;
78
+ if (current == null) return;
79
+ const indexed = indexOverrides(message.payload.overrides);
80
+ catalogs.value = {
81
+ ...current,
82
+ theme: {
83
+ ...current.theme,
84
+ overrides: indexed.theme
85
+ },
86
+ blocks: {
87
+ ...current.blocks,
88
+ overrides: indexed.blocks
89
+ }
90
+ };
91
+ } else if (message.type === "SET_LOCALE") {
92
+ void themeState.locales.setLocale(message.payload.locale);
93
+ } else if (message.type === "UPDATE_BLOCK_PROPS") {
94
+ let findAndUpdateBlock = function(blocks, blockId, props) {
95
+ for (const block of blocks) {
96
+ if (block.id === blockId) {
97
+ block.props = { ...block.props, ...props };
98
+ return true;
99
+ }
100
+ for (const slotBlocks of Object.values(block.slots || {})) {
101
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
102
+ for (const child of slotArray) {
103
+ if (typeof child !== "string" && (child == null ? void 0 : child.id)) {
104
+ if (findAndUpdateBlock([child], blockId, props)) {
105
+ return true;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return false;
112
+ };
113
+ const surface = resolveSurfaceForMessage(message);
114
+ const target = getBlocks(surface);
115
+ findAndUpdateBlock(
116
+ target.value,
117
+ message.payload.blockId,
118
+ message.payload.props
119
+ );
120
+ target.value = [...target.value];
121
+ indexSurface(surface, target.value);
122
+ } else if (message.type === "ADD_BLOCK") {
123
+ const surface = resolveSurfaceForMessage(message);
124
+ const target = getBlocks(surface);
125
+ const { block: blockData, location } = message.payload;
126
+ const newBlock = createBlockInstanceFromObject(blockData);
127
+ if (location.type === "before" || location.type === "after") {
128
+ let findAndInsertBlock = function(blocks, targetId, newBlock2, position) {
129
+ var _a2;
130
+ for (let i2 = 0; i2 < blocks.length; i2++) {
131
+ if (blocks[i2].id === targetId) {
132
+ if (position === "before") {
133
+ blocks.splice(i2, 0, newBlock2);
134
+ } else {
135
+ blocks.splice(i2 + 1, 0, newBlock2);
136
+ }
137
+ return true;
138
+ }
139
+ for (const slotKey of Object.keys(blocks[i2].slots || {})) {
140
+ const slotBlocks = blocks[i2].slots[slotKey];
141
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
142
+ for (let j2 = 0; j2 < slotArray.length; j2++) {
143
+ if (typeof slotArray[j2] !== "string" && ((_a2 = slotArray[j2]) == null ? void 0 : _a2.id) === targetId) {
144
+ if (position === "before") {
145
+ slotArray.splice(j2, 0, newBlock2);
146
+ } else {
147
+ slotArray.splice(j2 + 1, 0, newBlock2);
148
+ }
149
+ blocks[i2].slots[slotKey] = slotArray;
150
+ return true;
151
+ }
152
+ }
153
+ }
154
+ }
155
+ return false;
156
+ };
157
+ findAndInsertBlock(
158
+ target.value,
159
+ location.targetId,
160
+ newBlock,
161
+ location.type
162
+ );
163
+ } else if (location.type === "append") {
164
+ let findAndAppendBlock = function(blocks, parentId, slot, newBlock2) {
165
+ for (const block of blocks) {
166
+ if (block.id === parentId) {
167
+ if (!block.slots[slot]) {
168
+ block.slots[slot] = [];
169
+ }
170
+ if (Array.isArray(block.slots[slot])) {
171
+ block.slots[slot].push(newBlock2);
172
+ } else {
173
+ block.slots[slot] = [block.slots[slot], newBlock2];
174
+ }
175
+ return true;
176
+ }
177
+ for (const slotKey of Object.keys(block.slots || {})) {
178
+ const slotBlocks = block.slots[slotKey];
179
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
180
+ for (const child of slotArray) {
181
+ if (typeof child !== "string" && (child == null ? void 0 : child.id)) {
182
+ if (findAndAppendBlock([child], parentId, slot, newBlock2)) {
183
+ return true;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ return false;
190
+ };
191
+ findAndAppendBlock(
192
+ target.value,
193
+ location.parentId,
194
+ location.slot,
195
+ newBlock
196
+ );
197
+ }
198
+ target.value = [...target.value];
199
+ indexSurface(surface, target.value);
200
+ } else if (message.type === "REMOVE_BLOCK") {
201
+ let findAndRemoveBlock = function(blocks, blockId, slot, parentId) {
202
+ var _a2;
203
+ for (let i2 = 0; i2 < blocks.length; i2++) {
204
+ if (blocks[i2].id === parentId && ((_a2 = blocks[i2].slots) == null ? void 0 : _a2[slot])) {
205
+ const slotBlocks = blocks[i2].slots[slot];
206
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
207
+ const index = slotArray.findIndex(
208
+ (b2) => typeof b2 !== "string" && (b2 == null ? void 0 : b2.id) === blockId
209
+ );
210
+ if (index !== -1) {
211
+ slotArray.splice(index, 1);
212
+ blocks[i2].slots[slot] = slotArray;
213
+ return true;
214
+ }
215
+ }
216
+ for (const slotKey of Object.keys(blocks[i2].slots || {})) {
217
+ const slotBlocks = blocks[i2].slots[slotKey];
218
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
219
+ for (const child of slotArray) {
220
+ if (typeof child !== "string" && (child == null ? void 0 : child.id)) {
221
+ if (findAndRemoveBlock([child], blockId, slot, parentId)) {
222
+ return true;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ return false;
229
+ };
230
+ const surface = resolveSurfaceForMessage(message);
231
+ const target = getBlocks(surface);
232
+ let resolvedParentId = message.payload.location.parentId;
233
+ if (resolvedParentId === "root") {
234
+ resolvedParentId = ((_b = target.value[0]) == null ? void 0 : _b.id) ?? "root";
235
+ }
236
+ findAndRemoveBlock(
237
+ target.value,
238
+ message.payload.blockId,
239
+ message.payload.location.slot,
240
+ resolvedParentId
241
+ );
242
+ target.value = [...target.value];
243
+ indexSurface(surface, target.value);
244
+ } else if (message.type === "MOVE_BLOCK") {
245
+ let findAndMoveBlock = function(blocks, blockId, slot, parentId, newIndex) {
246
+ var _a2;
247
+ for (const block of blocks) {
248
+ if (block.id === parentId && ((_a2 = block.slots) == null ? void 0 : _a2[slot])) {
249
+ const slotBlocks = block.slots[slot];
250
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
251
+ const oldIndex = slotArray.findIndex(
252
+ (b2) => typeof b2 !== "string" && (b2 == null ? void 0 : b2.id) === blockId
253
+ );
254
+ if (oldIndex !== -1) {
255
+ const [moved] = slotArray.splice(oldIndex, 1);
256
+ slotArray.splice(newIndex, 0, moved);
257
+ block.slots[slot] = slotArray;
258
+ return true;
259
+ }
260
+ }
261
+ for (const slotKey of Object.keys(block.slots || {})) {
262
+ const slotBlocks = block.slots[slotKey];
263
+ const slotArray = Array.isArray(slotBlocks) ? slotBlocks : [slotBlocks];
264
+ for (const child of slotArray) {
265
+ if (typeof child !== "string" && (child == null ? void 0 : child.id)) {
266
+ if (findAndMoveBlock([child], blockId, slot, parentId, newIndex)) {
267
+ return true;
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ return false;
274
+ };
275
+ const surface = resolveSurfaceForMessage(message);
276
+ const target = getBlocks(surface);
277
+ findAndMoveBlock(
278
+ target.value,
279
+ message.payload.blockId,
280
+ message.payload.location.slot,
281
+ message.payload.location.parentId,
282
+ message.payload.location.index
283
+ );
284
+ target.value = [...target.value];
285
+ indexSurface(surface, target.value);
286
+ }
287
+ }
288
+ indexSurface("page", themeState.page.blocks.value);
289
+ indexSurface("overlay", themeState.overlay.blocks.value);
290
+ return {
291
+ handleMessage
292
+ };
293
+ }
294
+ const styles = `
295
+ <style>
296
+ .block-wrapper {
297
+ position: relative;
298
+ padding: 12px;
299
+ background-color: white;
300
+ border: 1px solid #B5B5B5;
301
+ border-radius: 8px;
302
+ justify-self: center;
303
+ max-width: 100%;
304
+ box-sizing: border-box;
305
+ }
306
+
307
+ .block-wrapper:hover,
308
+ .block-wrapper.active {
309
+ border-color: #000000;
310
+ }
311
+
312
+ .block-wrapper__name {
313
+ position: relative;
314
+ display: flex;
315
+ justify-content: space-between;
316
+ align-items: center;
317
+ gap: 6.82px;
318
+ margin-bottom: 12px;
319
+ font-size: 12px;
320
+ font-weight: 500;
321
+ color: #8A8A8A;
322
+ line-height: 100%;
323
+ height: 15px
324
+ }
325
+
326
+ .block-wrapper__actions {
327
+ display: flex;
328
+ align-items: center;
329
+ justify-content: flex-end;
330
+ height: 100%;
331
+ flex-grow: 1;
332
+ }
333
+
334
+ .block-wrapper__actions button {
335
+ height: 100%;
336
+ display: flex;
337
+ align-items: center;
338
+ color: #C4C4C4;
339
+ justify-content: center;
340
+ appearance: none;
341
+ border: none;
342
+ text-inherit: inherit;
343
+ padding: 0;
344
+ background: none;
345
+ cursor: pointer;
346
+ }
347
+
348
+ .block-wrapper__actions button:hover {
349
+ color: #8A8A8A;
350
+ }
351
+
352
+
353
+ .block-wrapper__menu {
354
+ display: none;
355
+ position: absolute;
356
+ top: calc(100% + 4px);
357
+ right: 0;
358
+ z-index: 1000;
359
+ background: white;
360
+ border: 1px solid #e9e9e9;
361
+ border-radius: 6px;
362
+ box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.04);
363
+ padding: 4px 0;
364
+ min-width: 148px;
365
+ flex-direction: column;
366
+ gap: 4px;
367
+ }
368
+
369
+ .block-wrapper__menu.open {
370
+ display: flex;
371
+ }
372
+
373
+ .block-wrapper__menu-section {
374
+ padding: 0 4px;
375
+ }
376
+
377
+ .block-wrapper__menu-item {
378
+ display: flex;
379
+ align-items: center;
380
+ gap: 6px;
381
+ height: 24px;
382
+ padding: 0 8px;
383
+ cursor: pointer;
384
+ font-size: 12px;
385
+ font-weight: 500;
386
+ font-family: inherit;
387
+ border-radius: 4px;
388
+ border: none;
389
+ background: none;
390
+ width: 100%;
391
+ text-align: left;
392
+ color: #111;
393
+ box-sizing: border-box;
394
+ }
395
+
396
+ .block-wrapper__menu-item:hover {
397
+ background: #f5f5f5;
398
+ }
399
+
400
+ .block-wrapper__menu-item--danger {
401
+ color: #f12323;
402
+ }
403
+
404
+ .block-wrapper__menu-divider {
405
+ height: 1px;
406
+ background: #e9e9e9;
407
+ flex-shrink: 0;
408
+ }
409
+ </style>
410
+ `;
411
+ const blockIconSvg = `
412
+ <svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
413
+ <path d="M4.36328 6.5459C4.96626 6.5459 5.4541 7.03374 5.4541 7.63672V10.9092C5.45405 11.5121 4.96623 12 4.36328 12H1.09082C0.96088 12 0.834934 11.9772 0.717773 11.9346C0.626296 11.9016 0.540642 11.8561 0.461914 11.8008C0.182984 11.6037 3.23667e-05 11.2776 0 10.9092V7.63672C0 7.03377 0.487878 6.54595 1.09082 6.5459H4.36328ZM10.9092 6.5459C11.5122 6.5459 12 7.03374 12 7.63672V10.9092C11.9999 11.5121 11.5121 12 10.9092 12H7.63672C7.50675 12 7.38086 11.9772 7.26367 11.9346C7.17215 11.9016 7.08658 11.8561 7.00781 11.8008C6.72883 11.6037 6.54593 11.2777 6.5459 10.9092V7.63672C6.5459 7.03374 7.03374 6.5459 7.63672 6.5459H10.9092ZM1.09082 7.63672V10.9092H4.36328V7.63672H1.09082ZM7.63672 10.9092H10.9092V7.63672H7.63672V10.9092ZM4.36328 0C4.96623 0 5.45405 0.487878 5.4541 1.09082V4.36328C5.4541 4.96626 4.96626 5.4541 4.36328 5.4541H1.09082C0.96088 5.45409 0.834934 5.43225 0.717773 5.38965C0.626233 5.35663 0.54069 5.31024 0.461914 5.25488C0.183079 5.05776 0 4.73167 0 4.36328V1.09082C4.77994e-05 0.487908 0.487908 4.79046e-05 1.09082 0H4.36328ZM10.9092 0C11.5121 0 12 0.487878 12 1.09082V4.36328C12 4.96626 11.5122 5.4541 10.9092 5.4541H7.63672C7.50675 5.4541 7.38086 5.43226 7.26367 5.38965C7.17208 5.35663 7.08662 5.31026 7.00781 5.25488C6.72893 5.05777 6.5459 4.73171 6.5459 4.36328V1.09082C6.54595 0.487878 7.03377 0 7.63672 0H10.9092ZM1.09082 4.36328H4.36328V1.09082H1.09082V4.36328ZM7.63672 4.36328H10.9092V1.09082H7.63672V4.36328Z" fill="currentColor"/>
414
+ </svg>
415
+
416
+ `;
417
+ const moreIconSvg = `
418
+ <svg width="13" height="3" viewBox="0 0 13 3" fill="none" xmlns="http://www.w3.org/2000/svg">
419
+ <path d="M1.5 0C2.32843 2.0934e-07 3 0.671573 3 1.5C3 2.32843 2.32843 3 1.5 3C0.671573 3 3.62117e-08 2.32843 0 1.5C6.04266e-08 0.671573 0.671573 3.62117e-08 1.5 0ZM6.5 0C7.32843 2.0934e-07 8 0.671573 8 1.5C8 2.32843 7.32843 3 6.5 3C5.67157 3 5 2.32843 5 1.5C5 0.671573 5.67157 3.62117e-08 6.5 0ZM11.5 0C12.3284 2.0934e-07 13 0.671573 13 1.5C13 2.32843 12.3284 3 11.5 3C10.6716 3 10 2.32843 10 1.5C10 0.671573 10.6716 3.62117e-08 11.5 0Z" fill="currentColor"/>
420
+ </svg>
421
+ `;
422
+ const trashIconSvg = `
423
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
424
+ <path d="M2 4H12" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
425
+ <path d="M5 4V2.5C5 2.22386 5.22386 2 5.5 2H8.5C8.77614 2 9 2.22386 9 2.5V4" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
426
+ <path d="M10.5 4L10 11.5C10 11.7761 9.77614 12 9.5 12H4.5C4.22386 12 4 11.7761 4 11.5L3.5 4" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
427
+ <line x1="7" y1="6.5" x2="7" y2="9.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
428
+ <line x1="5.5" y1="6.5" x2="5.5" y2="9.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
429
+ <line x1="8.5" y1="6.5" x2="8.5" y2="9.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
430
+ </svg>
431
+ `;
432
+ class BlockWrapper extends HTMLElement {
433
+ constructor() {
434
+ super();
435
+ __publicField(this, "block", null);
436
+ __publicField(this, "editorBridge", createEditorBridge());
437
+ __publicField(this, "nameElement", null);
438
+ __publicField(this, "menuElement", null);
439
+ __publicField(this, "isMenuOpen", false);
440
+ __publicField(this, "closeMenuOnOutsideClick", null);
441
+ this.attachShadow({ mode: "open" });
442
+ this.setupStyles();
443
+ this.setupTemplate();
444
+ }
445
+ static get observedAttributes() {
446
+ return ["data-block-id"];
447
+ }
448
+ setupStyles() {
449
+ const styleElement = document.createElement("style");
450
+ styleElement.textContent = styles.replace(/<style>|<\/style>/g, "").trim();
451
+ this.shadowRoot.appendChild(styleElement);
452
+ }
453
+ setupTemplate() {
454
+ const wrapper = document.createElement("div");
455
+ wrapper.className = "block-wrapper";
456
+ const nameDiv = document.createElement("div");
457
+ nameDiv.className = "block-wrapper__name";
458
+ const iconContainer = document.createElement("div");
459
+ iconContainer.style.display = "flex";
460
+ iconContainer.className = "block-wrapper__icon";
461
+ iconContainer.innerHTML = blockIconSvg;
462
+ const nameSpan = document.createElement("span");
463
+ nameSpan.textContent = "";
464
+ const actionsDiv = document.createElement("div");
465
+ actionsDiv.className = "block-wrapper__actions";
466
+ const moreBtn = document.createElement("button");
467
+ moreBtn.type = "button";
468
+ moreBtn.innerHTML = moreIconSvg;
469
+ moreBtn.addEventListener("click", (e2) => {
470
+ e2.stopPropagation();
471
+ this.toggleMenu();
472
+ });
473
+ const menuEl = document.createElement("div");
474
+ menuEl.className = "block-wrapper__menu";
475
+ menuEl.setAttribute("role", "menu");
476
+ const divider = document.createElement("div");
477
+ divider.className = "block-wrapper__menu-divider";
478
+ divider.setAttribute("role", "separator");
479
+ const deleteSection = document.createElement("div");
480
+ deleteSection.className = "block-wrapper__menu-section";
481
+ const deleteBtn = document.createElement("button");
482
+ deleteBtn.type = "button";
483
+ deleteBtn.className = "block-wrapper__menu-item block-wrapper__menu-item--danger";
484
+ deleteBtn.setAttribute("role", "menuitem");
485
+ deleteBtn.innerHTML = `${trashIconSvg}<span>Delete</span>`;
486
+ deleteBtn.addEventListener("click", (e2) => {
487
+ e2.stopPropagation();
488
+ this.closeMenu();
489
+ this.handleRemoveBlock();
490
+ });
491
+ deleteSection.appendChild(deleteBtn);
492
+ menuEl.appendChild(deleteSection);
493
+ actionsDiv.appendChild(moreBtn);
494
+ nameDiv.appendChild(iconContainer);
495
+ nameDiv.appendChild(nameSpan);
496
+ nameDiv.appendChild(actionsDiv);
497
+ nameDiv.appendChild(menuEl);
498
+ wrapper.appendChild(nameDiv);
499
+ const slot = document.createElement("slot");
500
+ wrapper.appendChild(slot);
501
+ this.shadowRoot.appendChild(wrapper);
502
+ this.nameElement = nameSpan;
503
+ this.menuElement = menuEl;
504
+ this.editorBridge.onMessage((message) => {
505
+ var _a;
506
+ if (message.type === "SELECT_BLOCK") {
507
+ this.updateActiveState(message.payload.blockId === ((_a = this.block) == null ? void 0 : _a.id));
508
+ }
509
+ });
510
+ }
511
+ connectedCallback() {
512
+ const isInOverlay = this.closest('juo-extension-root[surface="overlay"]') !== null;
513
+ if (isInOverlay) {
514
+ const actions = this.shadowRoot.querySelector(
515
+ ".block-wrapper__actions"
516
+ );
517
+ if (actions) actions.style.visibility = "hidden";
518
+ }
519
+ }
520
+ disconnectedCallback() {
521
+ this.closeMenu();
522
+ }
523
+ toggleMenu() {
524
+ if (this.isMenuOpen) {
525
+ this.closeMenu();
526
+ } else {
527
+ this.openMenu();
528
+ }
529
+ }
530
+ openMenu() {
531
+ if (!this.menuElement) return;
532
+ this.menuElement.classList.add("open");
533
+ this.isMenuOpen = true;
534
+ this.closeMenuOnOutsideClick = (e2) => {
535
+ if (!this.shadowRoot.contains(e2.composedPath()[0])) {
536
+ this.closeMenu();
537
+ }
538
+ };
539
+ document.addEventListener("click", this.closeMenuOnOutsideClick);
540
+ }
541
+ closeMenu() {
542
+ if (!this.menuElement) return;
543
+ this.menuElement.classList.remove("open");
544
+ this.isMenuOpen = false;
545
+ if (this.closeMenuOnOutsideClick) {
546
+ document.removeEventListener("click", this.closeMenuOnOutsideClick);
547
+ this.closeMenuOnOutsideClick = null;
548
+ }
549
+ }
550
+ setBlock(block) {
551
+ this.block = block;
552
+ this.setAttribute("data-block-id", block.id);
553
+ if (this.nameElement) {
554
+ this.nameElement.textContent = block.definition.name;
555
+ }
556
+ }
557
+ updateActiveState(isActive) {
558
+ const wrapper = this.shadowRoot.querySelector(
559
+ ".block-wrapper"
560
+ );
561
+ if (!wrapper) return;
562
+ if (isActive) {
563
+ wrapper.classList.add("active");
564
+ } else {
565
+ wrapper.classList.remove("active");
566
+ }
567
+ }
568
+ /**
569
+ * Traverses up the DOM tree to find the parent element, crossing shadow root boundaries
570
+ */
571
+ getParentElement(element) {
572
+ const root = element.getRootNode();
573
+ if (root instanceof ShadowRoot) {
574
+ return root.host;
575
+ }
576
+ return element.parentElement;
577
+ }
578
+ handleRemoveBlock() {
579
+ if (!this.block) return;
580
+ const extensionRoot = this.closest("juo-extension-root");
581
+ const slotName = (extensionRoot == null ? void 0 : extensionRoot.getAttribute("name")) || "default";
582
+ let parentId = "root";
583
+ let current = this;
584
+ while (current) {
585
+ const parent = this.getParentElement(current);
586
+ if (!parent) {
587
+ break;
588
+ }
589
+ if (parent !== this && parent.tagName === "JUO-EDITOR-BLOCK-WRAPPER") {
590
+ const parentBlockId = parent.getAttribute("data-block-id");
591
+ if (parentBlockId) {
592
+ parentId = parentBlockId;
593
+ break;
594
+ }
595
+ }
596
+ current = parent;
597
+ }
598
+ const location = {
599
+ slot: slotName,
600
+ parentId
601
+ };
602
+ const message = createRemoveBlockMessage(
603
+ {
604
+ blockId: this.block.id,
605
+ location
606
+ },
607
+ this.block.id
608
+ );
609
+ this.editorBridge.sendMessage(message);
610
+ }
611
+ }
612
+ if (customElements.get("juo-editor-block-wrapper") == null) {
613
+ customElements.define("juo-editor-block-wrapper", BlockWrapper);
614
+ }
615
+ async function serializeBlock(block) {
616
+ let initialValue = block.initialValue;
617
+ if (typeof initialValue === "function") {
618
+ try {
619
+ initialValue = initialValue();
620
+ } catch {
621
+ initialValue = void 0;
622
+ }
623
+ }
624
+ let locales;
625
+ if (block.locales) {
626
+ const supported = block.locales.supported ?? ["en"];
627
+ const entries = await Promise.all(
628
+ supported.map(async (code) => {
629
+ try {
630
+ const localeFile = await block.locales.load(code);
631
+ const topLevel = Object.fromEntries(
632
+ Object.entries(localeFile).filter(
633
+ ([key, value]) => key !== "overrides" && typeof value === "string"
634
+ )
635
+ );
636
+ return [code, { ...topLevel, ...localeFile.overrides ?? {} }];
637
+ } catch {
638
+ return null;
639
+ }
640
+ })
641
+ );
642
+ const loaded = entries.filter((e2) => e2 !== null);
643
+ if (loaded.length > 0) {
644
+ locales = Object.fromEntries(loaded);
645
+ }
646
+ }
647
+ return {
648
+ name: block.name,
649
+ group: block.group,
650
+ schema: block.schema,
651
+ initialValue,
652
+ presets: block.presets,
653
+ locales
654
+ };
655
+ }
656
+ async function setupEditorMode(routes, themeState) {
657
+ const editor = createEditorBridge();
658
+ const handler = createEditorHandler({
659
+ themeState
660
+ });
661
+ const { unsubscribe } = editor.onMessage((message) => {
662
+ handler.handleMessage(message);
663
+ });
664
+ const blocks = await Promise.all(getDefinedBlocks().map(serializeBlock));
665
+ editor.sendMessage(createRegisterBlocksMessage({ blocks }));
666
+ editor.sendMessage(createRegisterRoutesMessage({ routes }));
667
+ onRegisterBlock((_, block) => {
668
+ void serializeBlock(block).then(
669
+ (serialized) => editor.sendMessage(
670
+ createRegisterBlocksMessage({
671
+ blocks: [serialized]
672
+ })
673
+ )
674
+ );
675
+ });
676
+ return () => {
677
+ unsubscribe();
678
+ editor.destroy();
679
+ };
680
+ }
681
+ export {
682
+ BlockWrapper,
683
+ p as createAddBlockMessage,
684
+ createEditorBridge,
685
+ createEditorHandler,
686
+ b as createFocusInlineTextMessage,
687
+ q as createMoveBlockMessage,
688
+ v as createProvideGlobalStylesMessage,
689
+ w as createProvideInitialGlobalStylesMessage,
690
+ k as createProvideThemeStateMessage,
691
+ n as createProvideTranslationOverridesMessage,
692
+ c as createRegisterBlockTranslationKeysMessage,
693
+ createRegisterBlocksMessage,
694
+ createRegisterRoutesMessage,
695
+ createRemoveBlockMessage,
696
+ y as createReportContentHeightMessage,
697
+ u as createRequestGlobalStylesMessage,
698
+ l as createRequestThemeStateMessage,
699
+ m as createRequestTranslationOverridesMessage,
700
+ x as createScrollSyncMessage,
701
+ e as createSelectBlockMessage,
702
+ r as createSetBlockPresetMessage,
703
+ t as createSetGlobalStylesMessage,
704
+ s as createSetLocaleMessage,
705
+ o as createUpdateBlockPropsMessage,
706
+ d as createUpdateBlockTranslationMessage,
707
+ z as getEditorBridge,
708
+ i as isEditorMessage,
709
+ j as isIframeMessage,
710
+ setupEditorMode
711
+ };