@burger-editor/client 4.0.0-alpha.72 → 4.0.0-alpha.73

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 (85) hide show
  1. package/README.md +22 -9
  2. package/dist/__tests__/setup.d.ts +2 -0
  3. package/dist/__tests__/setup.d.ts.map +1 -0
  4. package/dist/burger-editor-root.d.ts +3 -7
  5. package/dist/burger-editor-root.d.ts.map +1 -1
  6. package/dist/client.js +323 -133
  7. package/dist/client.js.map +1 -1
  8. package/dist/commands/register-engine-commands.d.ts +2 -1
  9. package/dist/commands/register-engine-commands.d.ts.map +1 -1
  10. package/dist/components/block-catalog.d.ts +3 -5
  11. package/dist/components/block-catalog.d.ts.map +1 -1
  12. package/dist/components/block-menu-button.d.ts +1 -1
  13. package/dist/components/block-menu-view.d.ts +7 -3
  14. package/dist/components/block-menu-view.d.ts.map +1 -1
  15. package/dist/components/block-menu.d.ts +2 -5
  16. package/dist/components/block-menu.d.ts.map +1 -1
  17. package/dist/components/block-options.d.ts +4 -6
  18. package/dist/components/block-options.d.ts.map +1 -1
  19. package/dist/components/draft-switcher.d.ts +11 -10
  20. package/dist/components/draft-switcher.d.ts.map +1 -1
  21. package/dist/components/editable-area-view.d.ts +11 -14
  22. package/dist/components/editable-area-view.d.ts.map +1 -1
  23. package/dist/components/file-list.d.ts +9 -9
  24. package/dist/components/file-list.d.ts.map +1 -1
  25. package/dist/components/file-uploader.d.ts +6 -6
  26. package/dist/components/file-uploader.d.ts.map +1 -1
  27. package/dist/components/front-matter-editor.d.ts +43 -11
  28. package/dist/components/front-matter-editor.d.ts.map +1 -1
  29. package/dist/components/index.d.ts +2 -2
  30. package/dist/components/index.d.ts.map +1 -1
  31. package/dist/components/initial-insertion-button.d.ts +7 -2
  32. package/dist/components/initial-insertion-button.d.ts.map +1 -1
  33. package/dist/components/item-editor-host.d.ts +7 -6
  34. package/dist/components/item-editor-host.d.ts.map +1 -1
  35. package/dist/components/preview.d.ts +4 -7
  36. package/dist/components/preview.d.ts.map +1 -1
  37. package/dist/components/table-editor.d.ts.map +1 -1
  38. package/dist/components/wysiwyg-field.d.ts +11 -1
  39. package/dist/components/wysiwyg-field.d.ts.map +1 -1
  40. package/dist/editable-area-view-DssYcTqQ.js +2941 -0
  41. package/dist/editable-area-view-DssYcTqQ.js.map +1 -0
  42. package/dist/editor-dialog.d.ts +16 -7
  43. package/dist/editor-dialog.d.ts.map +1 -1
  44. package/dist/{editable-area-view-C00DSDVk.js → engine-context-gX6mWHke.js} +199 -1951
  45. package/dist/engine-context-gX6mWHke.js.map +1 -0
  46. package/dist/engine-context.d.ts +40 -0
  47. package/dist/engine-context.d.ts.map +1 -0
  48. package/dist/file-browser/store.d.ts +127 -0
  49. package/dist/file-browser/store.d.ts.map +1 -0
  50. package/dist/file-browser/use-external-file-selection.d.ts +39 -0
  51. package/dist/file-browser/use-external-file-selection.d.ts.map +1 -0
  52. package/dist/file-browser/use-file-browser.d.ts +17 -0
  53. package/dist/file-browser/use-file-browser.d.ts.map +1 -0
  54. package/dist/form/text-field.d.ts +3 -1
  55. package/dist/form/text-field.d.ts.map +1 -1
  56. package/dist/index.d.ts +4 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/mount.d.ts +6 -1
  59. package/dist/mount.d.ts.map +1 -1
  60. package/dist/root-error-boundary.d.ts +34 -0
  61. package/dist/root-error-boundary.d.ts.map +1 -0
  62. package/dist/testing/create-mock-engine.d.ts +30 -0
  63. package/dist/testing/create-mock-engine.d.ts.map +1 -0
  64. package/dist/testing/index.d.ts +4 -0
  65. package/dist/testing/index.d.ts.map +1 -0
  66. package/dist/testing/render-with-engine.d.ts +20 -0
  67. package/dist/testing/render-with-engine.d.ts.map +1 -0
  68. package/dist/testing/suppress-console-error.d.ts +24 -0
  69. package/dist/testing/suppress-console-error.d.ts.map +1 -0
  70. package/dist/testing.js +119 -0
  71. package/dist/testing.js.map +1 -0
  72. package/dist/ui.d.ts +7 -1
  73. package/dist/ui.d.ts.map +1 -1
  74. package/dist/ui.js +1618 -537
  75. package/dist/ui.js.map +1 -1
  76. package/dist/use-command.d.ts +13 -4
  77. package/dist/use-command.d.ts.map +1 -1
  78. package/dist/use-engine.d.ts +16 -32
  79. package/dist/use-engine.d.ts.map +1 -1
  80. package/dist/use-mount-effect.d.ts +20 -0
  81. package/dist/use-mount-effect.d.ts.map +1 -0
  82. package/dist/view/create-react-view.d.ts +33 -9
  83. package/dist/view/create-react-view.d.ts.map +1 -1
  84. package/package.json +44 -17
  85. package/dist/editable-area-view-C00DSDVk.js.map +0 -1
@@ -0,0 +1,2941 @@
1
+ import { f as CSS_LAYER, l as Item, n as useEngine, o as createBgeEvent, r as getBlockAtPosition, s as beginProcessing } from "./engine-context-gX6mWHke.js";
2
+ import { c } from "react/compiler-runtime";
3
+ import { Component, Fragment, Suspense, createContext, createElement, forwardRef, useActionState, useEffect, useEffectEvent, useId, useRef, useState } from "react";
4
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
5
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
6
+ import { createRoot } from "react-dom/client";
7
+ import { createPortal } from "react-dom";
8
+ //#region ../utils/dist/append-stylesheet-to.js
9
+ /**
10
+ * Append a `<link rel="stylesheet">` to a document's `<head>`.
11
+ * @param doc - The target document
12
+ * @param url - The stylesheet URL (often a blob URL)
13
+ * @param id - A cache-busting fragment identifier appended to `url`
14
+ * @example
15
+ * ```ts
16
+ * appendStylesheetTo(iframeDoc, blobUrl, 'block-menu-ui');
17
+ * ```
18
+ */
19
+ function appendStylesheetTo(doc, url, id) {
20
+ const link = doc.createElement("link");
21
+ link.rel = "stylesheet";
22
+ link.crossOrigin = "anonymous";
23
+ link.href = `${url}#${id}`;
24
+ doc.head.append(link);
25
+ }
26
+ //#endregion
27
+ //#region ../core/dist/command/commands.js
28
+ /**
29
+ * The engine's command vocabulary — every custom command accepted by the
30
+ * central command bus. Buttons declare these with
31
+ * `commandfor={engine.commandBus.receiverId}`; the dispatch table is
32
+ * registered by the UI layer at engine setup.
33
+ *
34
+ * Parameters travel on the invoker button (`value` / `data-*` attributes)
35
+ * and are read from `CommandEvent.source`.
36
+ * @example
37
+ * ```tsx
38
+ * <button command={BGE_COMMAND.moveBlock} commandfor={engine.commandBus.receiverId} value="up">
39
+ * 上に移動
40
+ * </button>
41
+ * ```
42
+ */
43
+ var BGE_COMMAND = {
44
+ /** Append a new block from the catalog. `value`: catalog index. */
45
+ addBlock: "--add-block",
46
+ /** Paste the block currently held in the clipboard. */
47
+ pasteBlock: "--paste-block",
48
+ /** Move the current block. `value`: `up` | `down`. */
49
+ moveBlock: "--move-block",
50
+ /** Open the catalog to insert a block. `value`: `before` | `after`. */
51
+ insertBlock: "--insert-block",
52
+ /** Add or remove a grid item in the current block. `value`: `+1` | `-1`. */
53
+ updateGridItems: "--update-grid-items",
54
+ /** Open the options dialog for the current block. */
55
+ openBlockOptions: "--open-block-options",
56
+ /** Copy the current block to the clipboard. */
57
+ copyBlock: "--copy-block",
58
+ /** Remove the current block. */
59
+ removeBlock: "--remove-block",
60
+ /** Insert the first block into an empty editable area. */
61
+ insertInitialBlock: "--insert-initial-block",
62
+ /** Switch the visible content. `value`: `main` | `draft`. */
63
+ switchContent: "--switch-content",
64
+ /** Copy the main content over the draft. */
65
+ copyMainToDraft: "--copy-main-to-draft",
66
+ /** Copy the draft content over the main. */
67
+ copyDraftToMain: "--copy-draft-to-main",
68
+ /** Open the item editor for the item hosting the invoker button. */
69
+ openItemEditor: "--open-item-editor"
70
+ };
71
+ //#endregion
72
+ //#region ../../../node_modules/@tabler/icons-react/dist/esm/defaultAttributes.mjs
73
+ /**
74
+ * @license @tabler/icons-react v3.46.0 - MIT
75
+ *
76
+ * This source code is licensed under the MIT license.
77
+ * See the LICENSE file in the root directory of this source tree.
78
+ */
79
+ var defaultAttributes = {
80
+ outline: {
81
+ xmlns: "http://www.w3.org/2000/svg",
82
+ width: 24,
83
+ height: 24,
84
+ viewBox: "0 0 24 24",
85
+ fill: "none",
86
+ stroke: "currentColor",
87
+ strokeWidth: 2,
88
+ strokeLinecap: "round",
89
+ strokeLinejoin: "round"
90
+ },
91
+ filled: {
92
+ xmlns: "http://www.w3.org/2000/svg",
93
+ width: 24,
94
+ height: 24,
95
+ viewBox: "0 0 24 24",
96
+ fill: "currentColor",
97
+ stroke: "none"
98
+ }
99
+ };
100
+ //#endregion
101
+ //#region ../../../node_modules/@tabler/icons-react/dist/esm/createReactComponent.mjs
102
+ /**
103
+ * @license @tabler/icons-react v3.46.0 - MIT
104
+ *
105
+ * This source code is licensed under the MIT license.
106
+ * See the LICENSE file in the root directory of this source tree.
107
+ */
108
+ var createReactComponent = (type, iconName, iconNamePascal, iconNode) => {
109
+ const Component = forwardRef(({ color = "currentColor", size = 24, stroke = 2, title, className, children, ...rest }, ref) => createElement("svg", {
110
+ ref,
111
+ ...defaultAttributes[type],
112
+ width: size,
113
+ height: size,
114
+ className: [
115
+ `tabler-icon`,
116
+ `tabler-icon-${iconName}`,
117
+ className
118
+ ].join(" "),
119
+ ...type === "filled" ? { fill: color } : {
120
+ strokeWidth: stroke,
121
+ stroke: color
122
+ },
123
+ ...rest
124
+ }, [
125
+ title && createElement("title", { key: "svg-title" }, title),
126
+ ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),
127
+ ...Array.isArray(children) ? children : [children]
128
+ ]));
129
+ Component.displayName = `${iconNamePascal}`;
130
+ return Component;
131
+ };
132
+ /**
133
+ * @license @tabler/icons-react v3.46.0 - MIT
134
+ *
135
+ * This source code is licensed under the MIT license.
136
+ * See the LICENSE file in the root directory of this source tree.
137
+ */
138
+ var IconArrowBigDownLine = createReactComponent("outline", "arrow-big-down-line", "ArrowBigDownLine", [["path", {
139
+ "d": "M15 12h3.586a1 1 0 0 1 .707 1.707l-6.586 6.586a1 1 0 0 1 -1.414 0l-6.586 -6.586a1 1 0 0 1 .707 -1.707h3.586v-6h6v6",
140
+ "key": "svg-0"
141
+ }], ["path", {
142
+ "d": "M15 3h-6",
143
+ "key": "svg-1"
144
+ }]]);
145
+ /**
146
+ * @license @tabler/icons-react v3.46.0 - MIT
147
+ *
148
+ * This source code is licensed under the MIT license.
149
+ * See the LICENSE file in the root directory of this source tree.
150
+ */
151
+ var IconArrowBigUpLine = createReactComponent("outline", "arrow-big-up-line", "ArrowBigUpLine", [["path", {
152
+ "d": "M9 12h-3.586a1 1 0 0 1 -.707 -1.707l6.586 -6.586a1 1 0 0 1 1.414 0l6.586 6.586a1 1 0 0 1 -.707 1.707h-3.586v6h-6v-6",
153
+ "key": "svg-0"
154
+ }], ["path", {
155
+ "d": "M9 21h6",
156
+ "key": "svg-1"
157
+ }]]);
158
+ /**
159
+ * @license @tabler/icons-react v3.46.0 - MIT
160
+ *
161
+ * This source code is licensed under the MIT license.
162
+ * See the LICENSE file in the root directory of this source tree.
163
+ */
164
+ var IconClipboardPlus = createReactComponent("outline", "clipboard-plus", "ClipboardPlus", [
165
+ ["path", {
166
+ "d": "M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2",
167
+ "key": "svg-0"
168
+ }],
169
+ ["path", {
170
+ "d": "M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2",
171
+ "key": "svg-1"
172
+ }],
173
+ ["path", {
174
+ "d": "M10 14h4",
175
+ "key": "svg-2"
176
+ }],
177
+ ["path", {
178
+ "d": "M12 12v4",
179
+ "key": "svg-3"
180
+ }]
181
+ ]);
182
+ /**
183
+ * @license @tabler/icons-react v3.46.0 - MIT
184
+ *
185
+ * This source code is licensed under the MIT license.
186
+ * See the LICENSE file in the root directory of this source tree.
187
+ */
188
+ var IconClipboard = createReactComponent("outline", "clipboard", "Clipboard", [["path", {
189
+ "d": "M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2",
190
+ "key": "svg-0"
191
+ }], ["path", {
192
+ "d": "M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2",
193
+ "key": "svg-1"
194
+ }]]);
195
+ /**
196
+ * @license @tabler/icons-react v3.46.0 - MIT
197
+ *
198
+ * This source code is licensed under the MIT license.
199
+ * See the LICENSE file in the root directory of this source tree.
200
+ */
201
+ var IconLayoutGridAdd = createReactComponent("outline", "layout-grid-add", "LayoutGridAdd", [
202
+ ["path", {
203
+ "d": "M4 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4",
204
+ "key": "svg-0"
205
+ }],
206
+ ["path", {
207
+ "d": "M14 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4",
208
+ "key": "svg-1"
209
+ }],
210
+ ["path", {
211
+ "d": "M4 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4",
212
+ "key": "svg-2"
213
+ }],
214
+ ["path", {
215
+ "d": "M14 17h6m-3 -3v6",
216
+ "key": "svg-3"
217
+ }]
218
+ ]);
219
+ /**
220
+ * @license @tabler/icons-react v3.46.0 - MIT
221
+ *
222
+ * This source code is licensed under the MIT license.
223
+ * See the LICENSE file in the root directory of this source tree.
224
+ */
225
+ var IconLayoutGridRemove = createReactComponent("outline", "layout-grid-remove", "LayoutGridRemove", [
226
+ ["path", {
227
+ "d": "M4 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-4",
228
+ "key": "svg-0"
229
+ }],
230
+ ["path", {
231
+ "d": "M14 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-4",
232
+ "key": "svg-1"
233
+ }],
234
+ ["path", {
235
+ "d": "M4 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-4",
236
+ "key": "svg-2"
237
+ }],
238
+ ["path", {
239
+ "d": "M14 17h6",
240
+ "key": "svg-3"
241
+ }]
242
+ ]);
243
+ /**
244
+ * @license @tabler/icons-react v3.46.0 - MIT
245
+ *
246
+ * This source code is licensed under the MIT license.
247
+ * See the LICENSE file in the root directory of this source tree.
248
+ */
249
+ var IconRowInsertBottom = createReactComponent("outline", "row-insert-bottom", "RowInsertBottom", [
250
+ ["path", {
251
+ "d": "M20 6v4a1 1 0 0 1 -1 1h-14a1 1 0 0 1 -1 -1v-4a1 1 0 0 1 1 -1h14a1 1 0 0 1 1 1",
252
+ "key": "svg-0"
253
+ }],
254
+ ["path", {
255
+ "d": "M12 15l0 4",
256
+ "key": "svg-1"
257
+ }],
258
+ ["path", {
259
+ "d": "M14 17l-4 0",
260
+ "key": "svg-2"
261
+ }]
262
+ ]);
263
+ /**
264
+ * @license @tabler/icons-react v3.46.0 - MIT
265
+ *
266
+ * This source code is licensed under the MIT license.
267
+ * See the LICENSE file in the root directory of this source tree.
268
+ */
269
+ var IconRowInsertTop = createReactComponent("outline", "row-insert-top", "RowInsertTop", [
270
+ ["path", {
271
+ "d": "M4 18v-4a1 1 0 0 1 1 -1h14a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-14a1 1 0 0 1 -1 -1",
272
+ "key": "svg-0"
273
+ }],
274
+ ["path", {
275
+ "d": "M12 9v-4",
276
+ "key": "svg-1"
277
+ }],
278
+ ["path", {
279
+ "d": "M10 7l4 0",
280
+ "key": "svg-2"
281
+ }]
282
+ ]);
283
+ /**
284
+ * @license @tabler/icons-react v3.46.0 - MIT
285
+ *
286
+ * This source code is licensed under the MIT license.
287
+ * See the LICENSE file in the root directory of this source tree.
288
+ */
289
+ var IconSettings = createReactComponent("outline", "settings", "Settings", [["path", {
290
+ "d": "M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065",
291
+ "key": "svg-0"
292
+ }], ["path", {
293
+ "d": "M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",
294
+ "key": "svg-1"
295
+ }]]);
296
+ /**
297
+ * @license @tabler/icons-react v3.46.0 - MIT
298
+ *
299
+ * This source code is licensed under the MIT license.
300
+ * See the LICENSE file in the root directory of this source tree.
301
+ */
302
+ var IconTrash = createReactComponent("outline", "trash", "Trash", [
303
+ ["path", {
304
+ "d": "M4 7l16 0",
305
+ "key": "svg-0"
306
+ }],
307
+ ["path", {
308
+ "d": "M10 11l0 6",
309
+ "key": "svg-1"
310
+ }],
311
+ ["path", {
312
+ "d": "M14 11l0 6",
313
+ "key": "svg-2"
314
+ }],
315
+ ["path", {
316
+ "d": "M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12",
317
+ "key": "svg-3"
318
+ }],
319
+ ["path", {
320
+ "d": "M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3",
321
+ "key": "svg-4"
322
+ }]
323
+ ]);
324
+ var block_catalog_module_default = {
325
+ blockCatalog: "_blockCatalog_96ih6_1",
326
+ figure: "_figure_96ih6_36",
327
+ img: "_img_96ih6_42",
328
+ figcaption: "_figcaption_96ih6_56",
329
+ pasteSection: "_pasteSection_96ih6_66",
330
+ pasteButton: "_pasteButton_96ih6_72"
331
+ };
332
+ //#endregion
333
+ //#region src/components/block-catalog.tsx
334
+ /**
335
+ * Block catalog dialog content. Adding and pasting blocks are declared
336
+ * as engine commands; the catalog entry is identified by
337
+ * `data-category` / `data-index` on the invoker button.
338
+ * @param root0
339
+ * @param root0.catalog
340
+ * @example
341
+ * ```tsx
342
+ * <EditorDialog name="catalog" open={open} onClose={close} buttons={{ close: 'キャンセル' }}>
343
+ * <BlockCatalog catalog={engine.catalog} />
344
+ * </EditorDialog>
345
+ * ```
346
+ */
347
+ function BlockCatalog(t0) {
348
+ const $ = c(11);
349
+ const { catalog } = t0;
350
+ const engine = useEngine();
351
+ let t1;
352
+ if ($[0] !== engine.storageKey.blockClipboard) {
353
+ t1 = sessionStorage.getItem(engine.storageKey.blockClipboard);
354
+ $[0] = engine.storageKey.blockClipboard;
355
+ $[1] = t1;
356
+ } else t1 = $[1];
357
+ const hasCopiedBlock = !!t1;
358
+ let t2;
359
+ if ($[2] !== engine.commandBus || $[3] !== hasCopiedBlock) {
360
+ t2 = hasCopiedBlock ? /* @__PURE__ */ jsx("div", {
361
+ className: block_catalog_module_default.pasteSection,
362
+ children: /* @__PURE__ */ jsxs("button", {
363
+ type: "button",
364
+ className: block_catalog_module_default.pasteButton,
365
+ command: BGE_COMMAND.pasteBlock,
366
+ commandfor: engine.commandBus.receiverId,
367
+ children: [/* @__PURE__ */ jsx(IconClipboard, {}), /* @__PURE__ */ jsx("span", { children: "クリップボードから貼り付け" })]
368
+ })
369
+ }) : null;
370
+ $[2] = engine.commandBus;
371
+ $[3] = hasCopiedBlock;
372
+ $[4] = t2;
373
+ } else t2 = $[4];
374
+ let t3;
375
+ if ($[5] !== catalog || $[6] !== engine.commandBus) {
376
+ t3 = /* @__PURE__ */ jsx("dl", { children: Object.entries(catalog).map((t4) => {
377
+ const [category, blocks] = t4;
378
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: category }), /* @__PURE__ */ jsx("div", { children: blocks.map((blockInfo, index) => /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("button", {
379
+ type: "button",
380
+ command: BGE_COMMAND.addBlock,
381
+ commandfor: engine.commandBus.receiverId,
382
+ "data-category": category,
383
+ "data-index": index,
384
+ children: blockInfo.definition.img || blockInfo.definition.svg ? /* @__PURE__ */ jsxs("span", {
385
+ className: block_catalog_module_default.figure,
386
+ children: [blockInfo.definition.img ? /* @__PURE__ */ jsx("span", {
387
+ className: block_catalog_module_default.img,
388
+ children: /* @__PURE__ */ jsx("img", {
389
+ src: blockInfo.definition.img,
390
+ alt: "",
391
+ loading: "lazy"
392
+ })
393
+ }) : /* @__PURE__ */ jsx("span", {
394
+ className: block_catalog_module_default.img,
395
+ dangerouslySetInnerHTML: { __html: blockInfo.definition.svg ?? "" }
396
+ }), /* @__PURE__ */ jsx("span", {
397
+ className: block_catalog_module_default.figcaption,
398
+ children: blockInfo.label
399
+ })]
400
+ }) : blockInfo.label
401
+ }) }, category + blockInfo.label + blockInfo.definition.name)) })] }, category);
402
+ }) });
403
+ $[5] = catalog;
404
+ $[6] = engine.commandBus;
405
+ $[7] = t3;
406
+ } else t3 = $[7];
407
+ let t4;
408
+ if ($[8] !== t2 || $[9] !== t3) {
409
+ t4 = /* @__PURE__ */ jsxs("div", {
410
+ className: block_catalog_module_default.blockCatalog,
411
+ children: [t2, t3]
412
+ });
413
+ $[8] = t2;
414
+ $[9] = t3;
415
+ $[10] = t4;
416
+ } else t4 = $[10];
417
+ return t4;
418
+ }
419
+ //#endregion
420
+ //#region src/components/block-options.tsx
421
+ var containerTypeLabel = {
422
+ grid: "グリッド",
423
+ inline: "横並び",
424
+ float: "左右折り返し"
425
+ };
426
+ /**
427
+ * Block options dialog content. Values are read out of the dialog form
428
+ * on submit (uncontrolled, `name="bge-options-*"`); only the fields that
429
+ * drive conditional rendering are controlled.
430
+ * @param root0
431
+ * @param root0.block
432
+ * @example
433
+ * ```tsx
434
+ * <EditorDialog
435
+ * name="options"
436
+ * open={block !== null}
437
+ * onClose={close}
438
+ * action={(formData) => applyBlockOptions(block, formData)}
439
+ * buttons={{ close: 'キャンセル', complete: '決定' }}>
440
+ * {block ? <BlockOptions block={block} /> : null}
441
+ * </EditorDialog>
442
+ * ```
443
+ */
444
+ function BlockOptions(t0) {
445
+ const $ = c(72);
446
+ const { block } = t0;
447
+ const engine = useEngine();
448
+ const currentBlock = block;
449
+ const uid = useId();
450
+ let t1;
451
+ if ($[0] !== currentBlock) {
452
+ t1 = () => currentBlock.exportOptions();
453
+ $[0] = currentBlock;
454
+ $[1] = t1;
455
+ } else t1 = $[1];
456
+ const [options] = useState(t1);
457
+ let t2;
458
+ if ($[2] !== engine || $[3] !== options.containerProps.type) {
459
+ t2 = engine.getCustomProperties(options.containerProps.type);
460
+ $[2] = engine;
461
+ $[3] = options.containerProps.type;
462
+ $[4] = t2;
463
+ } else t2 = $[4];
464
+ const cssProps = t2;
465
+ let t3;
466
+ if ($[5] !== engine) {
467
+ t3 = engine.getRepeatMinInlineSizeVariants();
468
+ $[5] = engine;
469
+ $[6] = t3;
470
+ } else t3 = $[6];
471
+ const repeatMinInlineSizeVariants = t3;
472
+ const [currentColumns, setCurrentColumns] = useState(options.containerProps.columns ?? 1);
473
+ const [currentContainerType, setCurrentContainerType] = useState(options.containerProps.type);
474
+ const [currentFrameSemantics, setCurrentFrameSemantics] = useState(options.containerProps.frameSemantics);
475
+ const [currentAutoRepeat, setCurrentAutoRepeat] = useState(options.containerProps.autoRepeat ?? "fixed");
476
+ const itemCount = currentBlock.items.length;
477
+ const effectiveContainerType = options.containerProps.type === "float" ? options.containerProps.type : currentContainerType;
478
+ let t4;
479
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
480
+ t4 = /* @__PURE__ */ jsx("legend", { children: "コンテナ特性" });
481
+ $[7] = t4;
482
+ } else t4 = $[7];
483
+ let t5;
484
+ if ($[8] !== currentContainerType || $[9] !== options.containerProps.immutable || $[10] !== options.containerProps.type) {
485
+ t5 = options.containerProps.immutable || options.containerProps.type === "float" ? /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: "コンテナタイプ" }), /* @__PURE__ */ jsxs("output", { children: [
486
+ containerTypeLabel[options.containerProps.type ?? "inline"],
487
+ " (",
488
+ options.containerProps.type ?? "inline",
489
+ ")"
490
+ ] })] }) : /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: "コンテナタイプ" }), /* @__PURE__ */ jsxs("select", {
491
+ name: "bge-options-container-type",
492
+ value: currentContainerType,
493
+ onChange: (e) => {
494
+ setCurrentContainerType(e.currentTarget.value);
495
+ },
496
+ children: [/* @__PURE__ */ jsx("option", {
497
+ value: "grid",
498
+ children: containerTypeLabel.grid
499
+ }), /* @__PURE__ */ jsx("option", {
500
+ value: "inline",
501
+ children: containerTypeLabel.inline
502
+ })]
503
+ })] });
504
+ $[8] = currentContainerType;
505
+ $[9] = options.containerProps.immutable;
506
+ $[10] = options.containerProps.type;
507
+ $[11] = t5;
508
+ } else t5 = $[11];
509
+ let t6;
510
+ if ($[12] !== currentFrameSemantics || $[13] !== options.containerProps.immutable || $[14] !== options.containerProps.type) {
511
+ t6 = !options.containerProps.immutable && options.containerProps.type !== "float" ? /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: "セマンティック要素" }), /* @__PURE__ */ jsxs("select", {
512
+ name: "bge-options-frame-semantics",
513
+ value: currentFrameSemantics,
514
+ onChange: (e_0) => {
515
+ setCurrentFrameSemantics(e_0.currentTarget.value);
516
+ },
517
+ children: [
518
+ /* @__PURE__ */ jsx("option", {
519
+ value: "div",
520
+ children: "div(汎用)"
521
+ }),
522
+ /* @__PURE__ */ jsx("option", {
523
+ value: "ul",
524
+ children: "ul(順序なしリスト)"
525
+ }),
526
+ /* @__PURE__ */ jsx("option", {
527
+ value: "ol",
528
+ children: "ol(順序ありリスト)"
529
+ })
530
+ ]
531
+ })] }) : null;
532
+ $[12] = currentFrameSemantics;
533
+ $[13] = options.containerProps.immutable;
534
+ $[14] = options.containerProps.type;
535
+ $[15] = t6;
536
+ } else t6 = $[15];
537
+ let t7;
538
+ if ($[16] !== effectiveContainerType || $[17] !== itemCount || $[18] !== options.containerProps.align || $[19] !== options.containerProps.immutable || $[20] !== options.containerProps.justify || $[21] !== uid) {
539
+ t7 = effectiveContainerType === "inline" && !(options.containerProps.immutable && itemCount === 1) ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
540
+ role: "radiogroup",
541
+ "aria-labelledby": `${uid}-justify`,
542
+ children: [/* @__PURE__ */ jsx("div", {
543
+ id: `${uid}-justify`,
544
+ children: "横方向配置"
545
+ }), [
546
+ ["center", "中央寄せ"],
547
+ ["start", "左寄せ"],
548
+ ["end", "右寄せ"],
549
+ ["between", "両端寄せ"],
550
+ ["around", "要素間余白均等"],
551
+ ["evenly", "要素間均等"]
552
+ ].map((t8) => {
553
+ const [value, label] = t8;
554
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
555
+ type: "radio",
556
+ name: "bge-options-justify",
557
+ value,
558
+ defaultChecked: options.containerProps.justify === value
559
+ }), /* @__PURE__ */ jsx("span", { children: label })] }, value);
560
+ })]
561
+ }), /* @__PURE__ */ jsxs("div", {
562
+ role: "radiogroup",
563
+ "aria-labelledby": `${uid}-align`,
564
+ children: [/* @__PURE__ */ jsx("div", {
565
+ id: `${uid}-align`,
566
+ children: "縦向配置"
567
+ }), [
568
+ ["align-center", "垂直中央寄せ"],
569
+ ["align-start", "上寄せ"],
570
+ ["align-end", "下寄せ"],
571
+ ["align-stretch", "伸縮"],
572
+ ["align-baseline", "ベースライン"]
573
+ ].map((t9) => {
574
+ const [value_0, label_0] = t9;
575
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
576
+ type: "radio",
577
+ name: "bge-options-align",
578
+ value: value_0,
579
+ defaultChecked: options.containerProps.align === value_0
580
+ }), /* @__PURE__ */ jsx("span", { children: label_0 })] }, value_0);
581
+ })]
582
+ })] }) : null;
583
+ $[16] = effectiveContainerType;
584
+ $[17] = itemCount;
585
+ $[18] = options.containerProps.align;
586
+ $[19] = options.containerProps.immutable;
587
+ $[20] = options.containerProps.justify;
588
+ $[21] = uid;
589
+ $[22] = t7;
590
+ } else t7 = $[22];
591
+ let t8;
592
+ if ($[23] !== currentAutoRepeat || $[24] !== currentColumns || $[25] !== effectiveContainerType || $[26] !== options.containerProps.immutable || $[27] !== options.containerProps.repeatMinInlineSize || $[28] !== options.containerProps.type || $[29] !== repeatMinInlineSizeVariants) {
593
+ t8 = effectiveContainerType === "grid" ? options.containerProps.immutable || options.containerProps.type === "float" ? /* @__PURE__ */ jsx("p", { children: "このブロックはコンテナタイプを変更できません。" }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
594
+ /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: "列の自動調整" }), /* @__PURE__ */ jsxs("select", {
595
+ name: "bge-options-auto-repeat",
596
+ value: currentAutoRepeat,
597
+ onChange: (e_1) => {
598
+ setCurrentAutoRepeat(e_1.currentTarget.value);
599
+ },
600
+ children: [
601
+ /* @__PURE__ */ jsx("option", {
602
+ value: "fixed",
603
+ children: "固定列数"
604
+ }),
605
+ /* @__PURE__ */ jsx("option", {
606
+ value: "auto-fill",
607
+ children: "auto-fill(空白保持)"
608
+ }),
609
+ /* @__PURE__ */ jsx("option", {
610
+ value: "auto-fit",
611
+ children: "auto-fit(空白最小)"
612
+ })
613
+ ]
614
+ })] }),
615
+ currentAutoRepeat === "fixed" ? /* @__PURE__ */ jsxs("label", { children: [
616
+ /* @__PURE__ */ jsx("span", { children: "基準列数" }),
617
+ /* @__PURE__ */ jsx("output", { children: currentColumns }),
618
+ /* @__PURE__ */ jsx("input", {
619
+ name: "bge-options-columns",
620
+ type: "range",
621
+ value: currentColumns,
622
+ onChange: (e_2) => {
623
+ setCurrentColumns(e_2.currentTarget.valueAsNumber);
624
+ },
625
+ min: "1",
626
+ max: "5"
627
+ })
628
+ ] }) : null,
629
+ currentAutoRepeat !== "fixed" && repeatMinInlineSizeVariants ? /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: "折り返し基準幅" }), /* @__PURE__ */ jsx("select", {
630
+ name: "bge-options-repeat-min-inline-size",
631
+ defaultValue: [...repeatMinInlineSizeVariants.properties].find((t9) => {
632
+ const [variantName, data] = t9;
633
+ return options.containerProps.repeatMinInlineSize == null ? data.isDefault : options.containerProps.repeatMinInlineSize === variantName;
634
+ })?.[0],
635
+ children: [...repeatMinInlineSizeVariants.properties].map(_temp$4)
636
+ })] }) : null
637
+ ] }) : null;
638
+ $[23] = currentAutoRepeat;
639
+ $[24] = currentColumns;
640
+ $[25] = effectiveContainerType;
641
+ $[26] = options.containerProps.immutable;
642
+ $[27] = options.containerProps.repeatMinInlineSize;
643
+ $[28] = options.containerProps.type;
644
+ $[29] = repeatMinInlineSizeVariants;
645
+ $[30] = t8;
646
+ } else t8 = $[30];
647
+ let t9;
648
+ if ($[31] !== effectiveContainerType || $[32] !== options.containerProps.float || $[33] !== uid) {
649
+ t9 = effectiveContainerType === "float" ? /* @__PURE__ */ jsxs("div", {
650
+ role: "radiogroup",
651
+ "aria-labelledby": `${uid}-float`,
652
+ children: [/* @__PURE__ */ jsx("div", {
653
+ id: `${uid}-float`,
654
+ children: "回り込み"
655
+ }), [["start", "左寄せ"], ["end", "右寄せ"]].map((t10) => {
656
+ const [value_1, label_1] = t10;
657
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
658
+ type: "radio",
659
+ name: "bge-options-float",
660
+ value: value_1,
661
+ defaultChecked: options.containerProps.float === value_1
662
+ }), /* @__PURE__ */ jsx("span", { children: label_1 })] }, value_1);
663
+ })]
664
+ }) : null;
665
+ $[31] = effectiveContainerType;
666
+ $[32] = options.containerProps.float;
667
+ $[33] = uid;
668
+ $[34] = t9;
669
+ } else t9 = $[34];
670
+ const t10 = options.containerProps.linkarea ?? false;
671
+ let t11;
672
+ if ($[35] !== t10) {
673
+ t11 = /* @__PURE__ */ jsx("input", {
674
+ type: "checkbox",
675
+ name: "bge-options-linkarea",
676
+ value: "true",
677
+ defaultChecked: t10
678
+ });
679
+ $[35] = t10;
680
+ $[36] = t11;
681
+ } else t11 = $[36];
682
+ let t12;
683
+ if ($[37] === Symbol.for("react.memo_cache_sentinel")) {
684
+ t12 = /* @__PURE__ */ jsx("span", { children: "リンクエリア機能を有効にする" });
685
+ $[37] = t12;
686
+ } else t12 = $[37];
687
+ let t13;
688
+ if ($[38] !== t11) {
689
+ t13 = /* @__PURE__ */ jsxs("label", { children: [t11, t12] });
690
+ $[38] = t11;
691
+ $[39] = t13;
692
+ } else t13 = $[39];
693
+ let t14;
694
+ if ($[40] !== t13 || $[41] !== t5 || $[42] !== t6 || $[43] !== t7 || $[44] !== t8 || $[45] !== t9) {
695
+ t14 = /* @__PURE__ */ jsxs("fieldset", { children: [
696
+ t4,
697
+ t5,
698
+ t6,
699
+ t7,
700
+ t8,
701
+ t9,
702
+ t13
703
+ ] });
704
+ $[40] = t13;
705
+ $[41] = t5;
706
+ $[42] = t6;
707
+ $[43] = t7;
708
+ $[44] = t8;
709
+ $[45] = t9;
710
+ $[46] = t14;
711
+ } else t14 = $[46];
712
+ let t15;
713
+ if ($[47] !== cssProps || $[48] !== options.style) {
714
+ t15 = cssProps.size > 0 ? /* @__PURE__ */ jsxs("fieldset", { children: [/* @__PURE__ */ jsx("legend", { children: "ブロックのスタイル拡張" }), [...cssProps].map((t16) => {
715
+ const [, category] = t16;
716
+ const selected = [...category.properties].find((t17) => {
717
+ const [propName, data_1] = t17;
718
+ return options.style?.[category.id] == null ? data_1.isDefault : options.style[category.id] === propName;
719
+ });
720
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: category.name }), /* @__PURE__ */ jsx("select", {
721
+ name: `bge-options-style-${category.id}`,
722
+ defaultValue: selected ? selected[1].isDefault ? "@@default" : selected[0] : void 0,
723
+ children: [...category.properties].map(_temp2$3)
724
+ })] }, `bge-options-style-${category.id}`);
725
+ })] }) : null;
726
+ $[47] = cssProps;
727
+ $[48] = options.style;
728
+ $[49] = t15;
729
+ } else t15 = $[49];
730
+ let t16;
731
+ if ($[50] === Symbol.for("react.memo_cache_sentinel")) {
732
+ t16 = /* @__PURE__ */ jsx("span", { children: "独自class設定" });
733
+ $[50] = t16;
734
+ } else t16 = $[50];
735
+ let t17;
736
+ if ($[51] !== options.classList) {
737
+ t17 = options.classList?.join(" ") ?? "";
738
+ $[51] = options.classList;
739
+ $[52] = t17;
740
+ } else t17 = $[52];
741
+ const t18 = `${uid}-classes-desc`;
742
+ let t19;
743
+ if ($[53] !== t17 || $[54] !== t18) {
744
+ t19 = /* @__PURE__ */ jsxs("label", { children: [t16, /* @__PURE__ */ jsx("input", {
745
+ type: "text",
746
+ name: "bge-options-classes",
747
+ defaultValue: t17,
748
+ "aria-describedby": t18
749
+ })] });
750
+ $[53] = t17;
751
+ $[54] = t18;
752
+ $[55] = t19;
753
+ } else t19 = $[55];
754
+ const t20 = `${uid}-classes-desc`;
755
+ let t21;
756
+ if ($[56] !== t20) {
757
+ t21 = /* @__PURE__ */ jsx("small", {
758
+ id: t20,
759
+ children: "複数指定する場合はスペース(空白文字)で区切ってください。"
760
+ });
761
+ $[56] = t20;
762
+ $[57] = t21;
763
+ } else t21 = $[57];
764
+ let t22;
765
+ if ($[58] === Symbol.for("react.memo_cache_sentinel")) {
766
+ t22 = /* @__PURE__ */ jsxs("span", { children: ["ID設定: ", /* @__PURE__ */ jsx("code", { children: "bge-" })] });
767
+ $[58] = t22;
768
+ } else t22 = $[58];
769
+ const t23 = options.id ?? "";
770
+ const t24 = `${uid}-id-desc`;
771
+ let t25;
772
+ if ($[59] !== t23 || $[60] !== t24) {
773
+ t25 = /* @__PURE__ */ jsxs("label", { children: [t22, /* @__PURE__ */ jsx("input", {
774
+ name: "bge-options-id",
775
+ type: "text",
776
+ defaultValue: t23,
777
+ "aria-describedby": t24
778
+ })] });
779
+ $[59] = t23;
780
+ $[60] = t24;
781
+ $[61] = t25;
782
+ } else t25 = $[61];
783
+ const t26 = `${uid}-id-desc`;
784
+ let t27;
785
+ if ($[62] === Symbol.for("react.memo_cache_sentinel")) {
786
+ t27 = /* @__PURE__ */ jsx("code", { children: "bge-" });
787
+ $[62] = t27;
788
+ } else t27 = $[62];
789
+ let t28;
790
+ if ($[63] !== t26) {
791
+ t28 = /* @__PURE__ */ jsxs("small", {
792
+ id: t26,
793
+ children: [
794
+ "アンカーリンク用のID属性を設定します。実際のIDは",
795
+ t27,
796
+ "が自動的に先頭に付加されます。"
797
+ ]
798
+ });
799
+ $[63] = t26;
800
+ $[64] = t28;
801
+ } else t28 = $[64];
802
+ let t29;
803
+ if ($[65] !== t14 || $[66] !== t15 || $[67] !== t19 || $[68] !== t21 || $[69] !== t25 || $[70] !== t28) {
804
+ t29 = /* @__PURE__ */ jsxs(Fragment$1, { children: [
805
+ t14,
806
+ t15,
807
+ t19,
808
+ t21,
809
+ t25,
810
+ t28
811
+ ] });
812
+ $[65] = t14;
813
+ $[66] = t15;
814
+ $[67] = t19;
815
+ $[68] = t21;
816
+ $[69] = t25;
817
+ $[70] = t28;
818
+ $[71] = t29;
819
+ } else t29 = $[71];
820
+ return t29;
821
+ }
822
+ function _temp2$3(t0) {
823
+ const [propName_0, data_2] = t0;
824
+ return /* @__PURE__ */ jsx("option", {
825
+ value: data_2.isDefault ? "@@default" : propName_0,
826
+ children: `${propName_0} (${data_2.value})`
827
+ }, propName_0);
828
+ }
829
+ function _temp$4(t0) {
830
+ const [variantName_0, data_0] = t0;
831
+ return /* @__PURE__ */ jsx("option", {
832
+ value: variantName_0,
833
+ children: `${variantName_0} (${data_0.value})`
834
+ }, variantName_0);
835
+ }
836
+ //#endregion
837
+ //#region ../../../node_modules/react-error-boundary/dist/react-error-boundary.js
838
+ var h = createContext(null);
839
+ var c$1 = {
840
+ didCatch: !1,
841
+ error: null
842
+ };
843
+ var m = class extends Component {
844
+ constructor(e) {
845
+ super(e), this.resetErrorBoundary = this.resetErrorBoundary.bind(this), this.state = c$1;
846
+ }
847
+ static getDerivedStateFromError(e) {
848
+ return {
849
+ didCatch: !0,
850
+ error: e
851
+ };
852
+ }
853
+ resetErrorBoundary(...e) {
854
+ const { didCatch: t } = this.state;
855
+ t && (this.props.onReset?.({
856
+ args: e,
857
+ reason: "imperative-api"
858
+ }), this.setState(c$1));
859
+ }
860
+ componentDidCatch(e, t) {
861
+ this.props.onError?.(e, t);
862
+ }
863
+ componentDidUpdate(e, t) {
864
+ const { didCatch: o } = this.state, { resetKeys: s } = this.props;
865
+ o && t.didCatch && C(e.resetKeys, s) && (this.props.onReset?.({
866
+ next: s,
867
+ prev: e.resetKeys,
868
+ reason: "keys"
869
+ }), this.setState(c$1));
870
+ }
871
+ render() {
872
+ const { children: e, fallbackRender: t, FallbackComponent: o, fallback: s } = this.props, { didCatch: n, error: a } = this.state;
873
+ let i = e;
874
+ if (n) {
875
+ const u = {
876
+ error: a,
877
+ resetErrorBoundary: this.resetErrorBoundary
878
+ };
879
+ if (typeof t == "function") i = t(u);
880
+ else if (o) i = createElement(o, u);
881
+ else if (s !== void 0) i = s;
882
+ else throw a;
883
+ }
884
+ return createElement(h.Provider, { value: {
885
+ didCatch: n,
886
+ error: a,
887
+ resetErrorBoundary: this.resetErrorBoundary
888
+ } }, i);
889
+ }
890
+ };
891
+ function C(r = [], e = []) {
892
+ return r.length !== e.length || r.some((t, o) => !Object.is(t, e[o]));
893
+ }
894
+ //#endregion
895
+ //#region src/invoker-commands.ts
896
+ /**
897
+ * Invoker Commands API attributes for buttons. Re-exported (rather than
898
+ * imported for side effects only) so that the module augmentation above
899
+ * survives d.ts bundling and reaches consumers.
900
+ */
901
+ //#endregion
902
+ //#region src/editor-dialog.tsx
903
+ /**
904
+ * Minimal fallback for a dialog body that suspended and then threw.
905
+ * Display-only — the dialog's own close button (outside this boundary,
906
+ * in the footer) is always available as a way out.
907
+ * @param root0
908
+ * @param root0.error
909
+ */
910
+ function DialogErrorFallback(t0) {
911
+ const $ = c(2);
912
+ const { error } = t0;
913
+ const t1 = error instanceof Error ? error.message : String(error);
914
+ let t2;
915
+ if ($[0] !== t1) {
916
+ t2 = /* @__PURE__ */ jsxs("p", {
917
+ role: "alert",
918
+ children: ["エラーが発生しました: ", t1]
919
+ });
920
+ $[0] = t1;
921
+ $[1] = t2;
922
+ } else t2 = $[1];
923
+ return t2;
924
+ }
925
+ /**
926
+ * Suspense fallback shown while a dialog body's `use()` calls are
927
+ * pending (e.g. content stylesheet fetch). Kept intentionally small —
928
+ * the dialog chrome (title, footer buttons) renders immediately.
929
+ */
930
+ function DialogSkeleton() {
931
+ const $ = c(1);
932
+ let t0;
933
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
934
+ t0 = /* @__PURE__ */ jsx("p", {
935
+ "aria-busy": "true",
936
+ children: "読み込み中…"
937
+ });
938
+ $[0] = t0;
939
+ } else t0 = $[0];
940
+ return t0;
941
+ }
942
+ /**
943
+ * Declarative `<dialog>` shell.
944
+ *
945
+ * The markup follows the `dialog.bge-dialog > div > form > div` + `footer`
946
+ * structure that `ui.css` styles. Opening/closing is driven by the `open`
947
+ * prop; the close button uses the built-in `close` command — no click
948
+ * handlers. Submission goes through `<form action>` (`useActionState`):
949
+ * on success the dialog stays under the caller's control (the action is
950
+ * responsible for closing it — typically `engine.uiState.closeDialog()`
951
+ * + `engine.save()`); on a thrown error the dialog stays open and shows
952
+ * the message via `role="alert"`, and the submit button is disabled
953
+ * while pending.
954
+ * @param root0
955
+ * @param root0.name
956
+ * @param root0.open
957
+ * @param root0.onClose
958
+ * @param root0.action
959
+ * @param root0.buttons
960
+ * @param root0.buttons.close
961
+ * @param root0.buttons.complete
962
+ * @param root0.children
963
+ * @example
964
+ * ```tsx
965
+ * <EditorDialog
966
+ * name="options"
967
+ * open={block !== null}
968
+ * onClose={() => { engine.uiState.closeDialog(); engine.save(); }}
969
+ * action={(formData) => {
970
+ * applyBlockOptions(block, formData);
971
+ * engine.uiState.closeDialog();
972
+ * engine.save();
973
+ * }}
974
+ * buttons={{ close: 'キャンセル', complete: '決定' }}>
975
+ * {block ? <BlockOptions block={block} /> : null}
976
+ * </EditorDialog>
977
+ * ```
978
+ */
979
+ function EditorDialog(t0) {
980
+ const $ = c(18);
981
+ const { name, open, onClose, action, buttons, children } = t0;
982
+ const dialogRef = useRef(null);
983
+ const uid = useId();
984
+ const dialogId = `${uid}-dialog`;
985
+ const formId = `${uid}-form`;
986
+ const [prevOpen, setPrevOpen] = useState(open);
987
+ const [generation, setGeneration] = useState(0);
988
+ if (open !== prevOpen) {
989
+ setPrevOpen(open);
990
+ if (open) setGeneration(_temp$3);
991
+ }
992
+ let t1;
993
+ let t2;
994
+ if ($[0] !== open) {
995
+ t1 = () => {
996
+ const dialog = dialogRef.current;
997
+ if (!dialog) return;
998
+ if (open && !dialog.open) dialog.showModal();
999
+ else if (!open && dialog.open) dialog.close();
1000
+ };
1001
+ t2 = [open];
1002
+ $[0] = open;
1003
+ $[1] = t1;
1004
+ $[2] = t2;
1005
+ } else {
1006
+ t1 = $[1];
1007
+ t2 = $[2];
1008
+ }
1009
+ useEffect(t1, t2);
1010
+ let t3;
1011
+ if ($[3] !== onClose) {
1012
+ t3 = (e) => {
1013
+ if (e.target !== e.currentTarget) return;
1014
+ onClose();
1015
+ };
1016
+ $[3] = onClose;
1017
+ $[4] = t3;
1018
+ } else t3 = $[4];
1019
+ let t4;
1020
+ if ($[5] !== action || $[6] !== buttons || $[7] !== children || $[8] !== dialogId || $[9] !== formId || $[10] !== generation || $[11] !== name || $[12] !== open) {
1021
+ t4 = /* @__PURE__ */ jsx(EditorDialogBody, {
1022
+ name,
1023
+ formId,
1024
+ dialogId,
1025
+ open,
1026
+ action,
1027
+ buttons,
1028
+ children
1029
+ }, generation);
1030
+ $[5] = action;
1031
+ $[6] = buttons;
1032
+ $[7] = children;
1033
+ $[8] = dialogId;
1034
+ $[9] = formId;
1035
+ $[10] = generation;
1036
+ $[11] = name;
1037
+ $[12] = open;
1038
+ $[13] = t4;
1039
+ } else t4 = $[13];
1040
+ let t5;
1041
+ if ($[14] !== dialogId || $[15] !== t3 || $[16] !== t4) {
1042
+ t5 = /* @__PURE__ */ jsx("dialog", {
1043
+ ref: dialogRef,
1044
+ id: dialogId,
1045
+ className: "bge-dialog",
1046
+ closedby: "any",
1047
+ onClose: t3,
1048
+ children: t4
1049
+ });
1050
+ $[14] = dialogId;
1051
+ $[15] = t3;
1052
+ $[16] = t4;
1053
+ $[17] = t5;
1054
+ } else t5 = $[17];
1055
+ return t5;
1056
+ }
1057
+ /**
1058
+ * The form + footer, split out from {@link EditorDialog} solely so it can
1059
+ * be remounted (via a `key` the caller bumps on each open) without also
1060
+ * remounting the `<dialog>` element itself — see the comment at the
1061
+ * `key={generation}` call site for why.
1062
+ * @param root0
1063
+ * @param root0.name
1064
+ * @param root0.formId
1065
+ * @param root0.dialogId
1066
+ * @param root0.open
1067
+ * @param root0.action
1068
+ * @param root0.buttons
1069
+ * @param root0.buttons.close
1070
+ * @param root0.buttons.complete
1071
+ * @param root0.children
1072
+ */
1073
+ function _temp$3(g) {
1074
+ return g + 1;
1075
+ }
1076
+ function EditorDialogBody({ name, formId, dialogId, open, action, buttons, children }) {
1077
+ const [error, submitAction, isPending] = useActionState(async (_prevError, formData) => {
1078
+ try {
1079
+ await action?.(formData);
1080
+ return null;
1081
+ } catch (error_) {
1082
+ return error_ instanceof Error ? error_.message : String(error_);
1083
+ }
1084
+ }, null);
1085
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("form", {
1086
+ id: formId,
1087
+ action: submitAction,
1088
+ noValidate: true,
1089
+ autoComplete: "off",
1090
+ autoCapitalize: "off",
1091
+ children: [/* @__PURE__ */ jsx("div", {
1092
+ "data-bge-component": `${name}-dialog`,
1093
+ children: open ? /* @__PURE__ */ jsx(m, {
1094
+ FallbackComponent: DialogErrorFallback,
1095
+ children: /* @__PURE__ */ jsx(Suspense, {
1096
+ fallback: /* @__PURE__ */ jsx(DialogSkeleton, {}),
1097
+ children
1098
+ })
1099
+ }) : null
1100
+ }), error ? /* @__PURE__ */ jsx("p", {
1101
+ role: "alert",
1102
+ children: error
1103
+ }) : null]
1104
+ }) }), /* @__PURE__ */ jsxs("footer", { children: [buttons?.close ? /* @__PURE__ */ jsx("button", {
1105
+ type: "button",
1106
+ command: "close",
1107
+ commandfor: dialogId,
1108
+ children: buttons.close
1109
+ }) : null, buttons?.complete ? /* @__PURE__ */ jsx("button", {
1110
+ type: "submit",
1111
+ form: formId,
1112
+ disabled: isPending,
1113
+ "aria-busy": isPending,
1114
+ children: buttons.complete
1115
+ }) : null] })] });
1116
+ }
1117
+ //#endregion
1118
+ //#region src/components/item-editor-host.tsx
1119
+ /**
1120
+ * Declarative item editor dialog. Renders the item's `Editor` component
1121
+ * with editor state derived via `toEditorState`; on submit the state is
1122
+ * converted back with `toItemData` and imported into the item. Reads the
1123
+ * engine via {@link useEngine}.
1124
+ * @param root0
1125
+ * @param root0.item
1126
+ * @param root0.containerType
1127
+ * @example
1128
+ * ```tsx
1129
+ * <ItemEditorHost
1130
+ * item={open?.type === 'item-editor' ? open.item : null}
1131
+ * containerType={open?.type === 'item-editor' ? open.containerType : undefined}
1132
+ * />
1133
+ * ```
1134
+ */
1135
+ function ItemEditorHost(t0) {
1136
+ const $ = c(13);
1137
+ const { item, containerType } = t0;
1138
+ const engine = useEngine();
1139
+ const submitRef = useRef(null);
1140
+ let t1;
1141
+ if ($[0] !== engine) {
1142
+ t1 = () => {
1143
+ engine.uiState.closeDialog();
1144
+ engine.save();
1145
+ };
1146
+ $[0] = engine;
1147
+ $[1] = t1;
1148
+ } else t1 = $[1];
1149
+ const closeAndSave = t1;
1150
+ const t2 = !!item;
1151
+ let t3;
1152
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
1153
+ t3 = {
1154
+ close: "キャンセル",
1155
+ complete: "決定"
1156
+ };
1157
+ $[2] = t3;
1158
+ } else t3 = $[2];
1159
+ let t4;
1160
+ if ($[3] !== closeAndSave) {
1161
+ t4 = async () => {
1162
+ await submitRef.current?.();
1163
+ closeAndSave();
1164
+ };
1165
+ $[3] = closeAndSave;
1166
+ $[4] = t4;
1167
+ } else t4 = $[4];
1168
+ let t5;
1169
+ if ($[5] !== containerType || $[6] !== item) {
1170
+ t5 = item ? /* @__PURE__ */ jsx(ItemEditorBody, {
1171
+ item,
1172
+ containerType,
1173
+ submitRef
1174
+ }) : null;
1175
+ $[5] = containerType;
1176
+ $[6] = item;
1177
+ $[7] = t5;
1178
+ } else t5 = $[7];
1179
+ let t6;
1180
+ if ($[8] !== closeAndSave || $[9] !== t2 || $[10] !== t4 || $[11] !== t5) {
1181
+ t6 = /* @__PURE__ */ jsx(EditorDialog, {
1182
+ name: "item-editor",
1183
+ open: t2,
1184
+ buttons: t3,
1185
+ onClose: closeAndSave,
1186
+ action: t4,
1187
+ children: t5
1188
+ });
1189
+ $[8] = closeAndSave;
1190
+ $[9] = t2;
1191
+ $[10] = t4;
1192
+ $[11] = t5;
1193
+ $[12] = t6;
1194
+ } else t6 = $[12];
1195
+ return t6;
1196
+ }
1197
+ /**
1198
+ * The editor form body. Owns the editor state for the currently edited
1199
+ * item.
1200
+ * @param root0
1201
+ * @param root0.item
1202
+ * @param root0.containerType
1203
+ * @param root0.submitRef
1204
+ */
1205
+ function ItemEditorBody(t0) {
1206
+ const $ = c(24);
1207
+ const { item, containerType, submitRef } = t0;
1208
+ const engine = useEngine();
1209
+ const seed = item.seed;
1210
+ let t1;
1211
+ if ($[0] !== engine || $[1] !== item || $[2] !== seed) {
1212
+ t1 = () => {
1213
+ const data = item.export();
1214
+ return seed.toEditorState ? seed.toEditorState(data, engine.config) : data;
1215
+ };
1216
+ $[0] = engine;
1217
+ $[1] = item;
1218
+ $[2] = seed;
1219
+ $[3] = t1;
1220
+ } else t1 = $[3];
1221
+ const [state, setState] = useState(t1);
1222
+ let t2;
1223
+ if ($[4] !== engine || $[5] !== seed || $[6] !== state) {
1224
+ t2 = async () => seed.toItemData ? await seed.toItemData(state, engine.config) : state;
1225
+ $[4] = engine;
1226
+ $[5] = seed;
1227
+ $[6] = state;
1228
+ $[7] = t2;
1229
+ } else t2 = $[7];
1230
+ const resolveSubmitData = useEffectEvent(t2);
1231
+ let t3;
1232
+ if ($[8] !== item || $[9] !== resolveSubmitData || $[10] !== submitRef) {
1233
+ t3 = () => {
1234
+ submitRef.current = async () => {
1235
+ const data_0 = await resolveSubmitData();
1236
+ await item.import(data_0);
1237
+ };
1238
+ return () => {
1239
+ submitRef.current = null;
1240
+ };
1241
+ };
1242
+ $[8] = item;
1243
+ $[9] = resolveSubmitData;
1244
+ $[10] = submitRef;
1245
+ $[11] = t3;
1246
+ } else t3 = $[11];
1247
+ let t4;
1248
+ if ($[12] !== item || $[13] !== submitRef) {
1249
+ t4 = [item, submitRef];
1250
+ $[12] = item;
1251
+ $[13] = submitRef;
1252
+ $[14] = t4;
1253
+ } else t4 = $[14];
1254
+ useEffect(t3, t4);
1255
+ const Editor = seed.Editor;
1256
+ if (!Editor) {
1257
+ let t5;
1258
+ if ($[15] !== item.name) {
1259
+ t5 = /* @__PURE__ */ jsxs("p", { children: [
1260
+ "編集できないコンテンツです (Error: Editor not found: \"",
1261
+ item.name,
1262
+ "\")"
1263
+ ] });
1264
+ $[15] = item.name;
1265
+ $[16] = t5;
1266
+ } else t5 = $[16];
1267
+ return t5;
1268
+ }
1269
+ let t5;
1270
+ if ($[17] !== Editor || $[18] !== item || $[19] !== state) {
1271
+ t5 = /* @__PURE__ */ jsx(Editor, {
1272
+ state,
1273
+ setState,
1274
+ item
1275
+ });
1276
+ $[17] = Editor;
1277
+ $[18] = item;
1278
+ $[19] = state;
1279
+ $[20] = t5;
1280
+ } else t5 = $[20];
1281
+ let t6;
1282
+ if ($[21] !== containerType || $[22] !== t5) {
1283
+ t6 = /* @__PURE__ */ jsx("div", {
1284
+ "data-bge-container": containerType,
1285
+ children: t5
1286
+ });
1287
+ $[21] = containerType;
1288
+ $[22] = t5;
1289
+ $[23] = t6;
1290
+ } else t6 = $[23];
1291
+ return t6;
1292
+ }
1293
+ //#endregion
1294
+ //#region src/use-engine.ts
1295
+ var identity = (state) => state;
1296
+ /**
1297
+ * Subscribe to the engine's UI state store.
1298
+ *
1299
+ * Wraps `useSyncExternalStoreWithSelector` so call sites don't repeat the
1300
+ * subscribe/getSnapshot/selector wiring. `engine.uiState.subscribe` and
1301
+ * `.getSnapshot` are stable per-instance methods (see `UIStateStore`), so
1302
+ * passing them directly — instead of a new inline closure each render —
1303
+ * means React doesn't unsubscribe and resubscribe on every render. The
1304
+ * engine is read from the nearest `EngineProvider`.
1305
+ * @returns The current UI state snapshot
1306
+ * @example
1307
+ * ```tsx
1308
+ * const { openDialog } = useUIState();
1309
+ * return <ItemEditorHost item={openDialog?.type === 'item-editor' ? openDialog.item : null} />;
1310
+ * ```
1311
+ */
1312
+ /**
1313
+ * Subscribe to a projection of the engine's UI state store.
1314
+ *
1315
+ * 選択的な状態(`processing` や `sourceMode[type]` など)だけを読む
1316
+ * コンポーネントは、`selector` でそのフィールドだけを取り出すと無関係な
1317
+ * 状態変化(例: ダイアログの開閉)での再レンダーを避けられる —
1318
+ * `useSyncExternalStoreWithSelector` が選択後の値を `Object.is` で比較し、
1319
+ * 変化がなければ再レンダーをスキップする(selector 自体は毎レンダー
1320
+ * 新しい関数でよい。比較されるのは戻り値であって関数の同一性ではない)。
1321
+ * @param selector - Projection of the snapshot
1322
+ * @returns The selected value
1323
+ * @example
1324
+ * ```tsx
1325
+ * // 無関係な状態変化での再レンダーを避ける
1326
+ * const processing = useUIState((s) => s.processing);
1327
+ * ```
1328
+ */
1329
+ function useUIState(selector) {
1330
+ const engine = useEngine();
1331
+ return useSyncExternalStoreWithSelector(engine.uiState.subscribe, engine.uiState.getSnapshot, engine.uiState.getSnapshot, selector ?? identity);
1332
+ }
1333
+ //#endregion
1334
+ //#region src/replace-element.ts
1335
+ /**
1336
+ *
1337
+ * @param elA
1338
+ * @param elB
1339
+ * @param duration
1340
+ */
1341
+ async function replaceElement(elA, elB, duration = 600) {
1342
+ if (elA.parentElement !== elB.parentElement) throw new Error("The parent element of the two elements is different.");
1343
+ const lockCSS = {
1344
+ visibility: "hidden",
1345
+ pointerEvents: "none"
1346
+ };
1347
+ const beforeStyleA = elA.style.cssText.trim();
1348
+ const beforeStyleB = elB.style.cssText.trim();
1349
+ const boxA = elA.getBoundingClientRect();
1350
+ const boxB = elB.getBoundingClientRect();
1351
+ const tmpContainer = elA.ownerDocument.createElement("div");
1352
+ tmpContainer.style.position = "absolute";
1353
+ tmpContainer.style.top = `0px`;
1354
+ tmpContainer.style.left = `0px`;
1355
+ tmpContainer.style.zIndex = "2147483647";
1356
+ const tmpA = elA.cloneNode(true);
1357
+ tmpA.style.position = "absolute";
1358
+ tmpA.style.top = `${boxA.top}px`;
1359
+ tmpA.style.left = `${boxA.left}px`;
1360
+ tmpA.style.width = `${boxA.width}px`;
1361
+ tmpA.style.height = `${boxA.height}px`;
1362
+ tmpA.style.zIndex = "20";
1363
+ const tmpB = elB.cloneNode(true);
1364
+ tmpB.style.position = "absolute";
1365
+ tmpB.style.top = `${boxB.top}px`;
1366
+ tmpB.style.left = `${boxB.left}px`;
1367
+ tmpB.style.width = `${boxB.width}px`;
1368
+ tmpB.style.height = `${boxB.height}px`;
1369
+ tmpB.style.zIndex = "10";
1370
+ tmpContainer.append(tmpA, tmpB);
1371
+ tmpContainer.ownerDocument.body.append(tmpContainer);
1372
+ elB.remove();
1373
+ elA.before(elB);
1374
+ elA.style.visibility = lockCSS.visibility;
1375
+ elA.style.pointerEvents = lockCSS.pointerEvents;
1376
+ elB.style.visibility = lockCSS.visibility;
1377
+ elB.style.pointerEvents = lockCSS.pointerEvents;
1378
+ const animateA = tmpA.animate([{
1379
+ top: tmpA.style.top,
1380
+ left: tmpA.style.left
1381
+ }, {
1382
+ top: `${boxA.top + boxB.height}px`,
1383
+ left: tmpB.style.left
1384
+ }], { duration });
1385
+ const animateB = tmpB.animate([{
1386
+ top: tmpB.style.top,
1387
+ left: tmpB.style.left
1388
+ }, {
1389
+ top: tmpA.style.top,
1390
+ left: tmpA.style.left
1391
+ }], { duration });
1392
+ await Promise.all([animateA.finished, animateB.finished]);
1393
+ tmpContainer.remove();
1394
+ elA.removeAttribute("style");
1395
+ elB.removeAttribute("style");
1396
+ if (beforeStyleA) elA.style.cssText = beforeStyleA;
1397
+ if (beforeStyleB) elB.style.cssText = beforeStyleB;
1398
+ }
1399
+ //#endregion
1400
+ //#region src/commands/register-engine-commands.ts
1401
+ /**
1402
+ * Register the engine's central command dispatch table.
1403
+ *
1404
+ * This is the single place where engine-mutating UI commands are
1405
+ * implemented; buttons anywhere (main document or EditableArea iframes)
1406
+ * declare them with `commandfor={engine.commandBus.receiverId}`. Call once
1407
+ * per engine.
1408
+ * @param engine - The engine instance
1409
+ * @param catalog - The block catalog used by `--add-block`
1410
+ * @example
1411
+ * ```ts
1412
+ * const engine = await BurgerEditorEngine.new(options);
1413
+ * registerEngineCommands(engine, options.catalog);
1414
+ * ```
1415
+ */
1416
+ function registerEngineCommands(engine, catalog) {
1417
+ const bus = engine.commandBus;
1418
+ bus.define(BGE_COMMAND.moveBlock, async (e) => {
1419
+ const currentBlock = engine.getCurrentBlock();
1420
+ if (engine.isProcessed || !currentBlock) return;
1421
+ const toTop = e.source?.value === "up";
1422
+ let fromEl;
1423
+ let toEl;
1424
+ if (toTop) {
1425
+ fromEl = currentBlock.el.previousElementSibling;
1426
+ toEl = currentBlock.el;
1427
+ } else {
1428
+ fromEl = currentBlock.el;
1429
+ toEl = currentBlock.el.nextElementSibling;
1430
+ }
1431
+ if (!fromEl || !toEl) return;
1432
+ {
1433
+ using _processing = beginProcessing(engine);
1434
+ await replaceElement(fromEl, toEl);
1435
+ }
1436
+ engine.save();
1437
+ });
1438
+ bus.define(BGE_COMMAND.insertBlock, (e) => {
1439
+ const currentBlock = engine.getCurrentBlock();
1440
+ if (engine.isProcessed || !currentBlock) return;
1441
+ const toTop = e.source?.value === "before";
1442
+ engine.content.insertionPoint.set(currentBlock, toTop);
1443
+ engine.uiState.openBlockCatalog();
1444
+ });
1445
+ bus.define(BGE_COMMAND.updateGridItems, (e) => {
1446
+ const currentBlock = engine.getCurrentBlock();
1447
+ if (engine.isProcessed || !currentBlock) return;
1448
+ const addOrRemove = e.source?.value === "-1" ? -1 : 1;
1449
+ if (addOrRemove === -1 && !confirm("ブロック内の最後の要素を削除します。\n削除した要素はもとに戻すことはできません。\n削除してもよろしいですか?")) return;
1450
+ currentBlock.updateGridItems(addOrRemove, engine);
1451
+ engine.save();
1452
+ });
1453
+ bus.define(BGE_COMMAND.openBlockOptions, () => {
1454
+ const currentBlock = engine.getCurrentBlock();
1455
+ if (engine.isProcessed || !currentBlock) return;
1456
+ engine.uiState.openBlockOptions(currentBlock);
1457
+ });
1458
+ bus.define(BGE_COMMAND.copyBlock, () => {
1459
+ const currentBlock = engine.getCurrentBlock();
1460
+ if (engine.isProcessed || !currentBlock) return;
1461
+ const json = currentBlock.toJSONStringify();
1462
+ sessionStorage.setItem(engine.storageKey.blockClipboard, json);
1463
+ alert("ブロックをコピーしました。\nブロックの追加ボタンからペースト(貼り付け)することができます。");
1464
+ });
1465
+ bus.define(BGE_COMMAND.removeBlock, async () => {
1466
+ const currentBlock = engine.getCurrentBlock();
1467
+ if (engine.isProcessed || !currentBlock) return;
1468
+ if (!confirm("ブロックを削除します。\n削除したブロックはもとに戻すことはできません。\n削除してもよろしいですか?")) return;
1469
+ {
1470
+ using _processing = beginProcessing(engine);
1471
+ await Promise.resolve();
1472
+ currentBlock.remove();
1473
+ engine.clearCurrentBlock();
1474
+ }
1475
+ engine.save();
1476
+ });
1477
+ bus.define(BGE_COMMAND.insertInitialBlock, () => {
1478
+ if (engine.isProcessed) return;
1479
+ engine.content.insertionPoint.set(null, false);
1480
+ engine.uiState.openBlockCatalog();
1481
+ });
1482
+ bus.define(BGE_COMMAND.addBlock, async (e) => {
1483
+ const source = e.source;
1484
+ const category = source?.dataset["category"];
1485
+ const index = Number(source?.dataset["index"]);
1486
+ const definition = category ? catalog[category]?.[index]?.definition : void 0;
1487
+ if (!definition) return;
1488
+ engine.uiState.closeDialog();
1489
+ await engine.addBlock(definition);
1490
+ });
1491
+ bus.define(BGE_COMMAND.switchContent, (e) => {
1492
+ if (e.source?.value === "main") engine.showMain();
1493
+ else engine.showDraft();
1494
+ });
1495
+ bus.define(BGE_COMMAND.copyMainToDraft, async () => {
1496
+ if (await engine.mainToDraft(() => confirm("本稿内容を下書きへ上書きしてもよろしいですか?"))) engine.showDraft();
1497
+ });
1498
+ bus.define(BGE_COMMAND.copyDraftToMain, async () => {
1499
+ if (await engine.draftToMain(() => confirm("下書き内容を本稿へ上書きしてもよろしいですか?"))) engine.showMain();
1500
+ });
1501
+ bus.define(BGE_COMMAND.pasteBlock, async () => {
1502
+ const jsonString = sessionStorage.getItem(engine.storageKey.blockClipboard);
1503
+ if (!jsonString) {
1504
+ alert("クリップボードにブロックデータがありません。");
1505
+ return;
1506
+ }
1507
+ let blockData;
1508
+ try {
1509
+ blockData = JSON.parse(jsonString);
1510
+ } catch (error) {
1511
+ console.error("Invalid JSON in clipboard:", error);
1512
+ alert("ブロックの貼り付けに失敗しました。\nクリップボードのデータが破損している可能性があります。\nもう一度ブロックをコピーしてください。");
1513
+ return;
1514
+ }
1515
+ engine.uiState.closeDialog();
1516
+ await engine.addBlock(blockData);
1517
+ sessionStorage.removeItem(engine.storageKey.blockClipboard);
1518
+ });
1519
+ }
1520
+ var draft_switcher_module_default = {
1521
+ draftBtn: "_draftBtn_14xtl_1",
1522
+ draftTabBtn: "_draftTabBtn_14xtl_16",
1523
+ draftCopyBtn: "_draftCopyBtn_14xtl_47"
1524
+ };
1525
+ //#endregion
1526
+ //#region src/components/draft-switcher.tsx
1527
+ /**
1528
+ * Main/draft content switcher. Switching and copying are declared as
1529
+ * engine commands; the pressed state follows `engine.uiState.activeArea`
1530
+ * and the source-view indicator follows `engine.uiState.sourceMode` — no
1531
+ * state is duplicated locally. Reads the engine via {@link useEngine} —
1532
+ * the caller wraps this in an `EngineProvider`.
1533
+ *
1534
+ * The alt+double-click source-view toggle is kept as a DOM event —
1535
+ * double-click has no Invoker Commands equivalent (the no-click rule
1536
+ * targets single-click activation).
1537
+ * @example
1538
+ * ```tsx
1539
+ * const container = document.createElement('div');
1540
+ * engine.viewArea.insertAdjacentElement('beforebegin', container);
1541
+ * reactMount(
1542
+ * <EngineProvider engine={engine}>
1543
+ * <DraftSwitcher />
1544
+ * </EngineProvider>,
1545
+ * container,
1546
+ * );
1547
+ * ```
1548
+ */
1549
+ function DraftSwitcher() {
1550
+ const $ = c(36);
1551
+ const engine = useEngine();
1552
+ const sourceMode = useUIState(_temp$2);
1553
+ const isMain = useUIState(_temp2$2);
1554
+ const isVisualMode = !sourceMode[isMain ? "main" : "draft"];
1555
+ let t0;
1556
+ if ($[0] !== engine.content.type || $[1] !== engine.uiState) {
1557
+ t0 = () => {
1558
+ engine.uiState.toggleSourceMode(engine.content.type);
1559
+ };
1560
+ $[0] = engine.content.type;
1561
+ $[1] = engine.uiState;
1562
+ $[2] = t0;
1563
+ } else t0 = $[2];
1564
+ const toggleDisplayMode = t0;
1565
+ let t1;
1566
+ if ($[3] !== engine || $[4] !== isMain || $[5] !== toggleDisplayMode) {
1567
+ t1 = (e) => {
1568
+ if (!e.altKey || !isMain) return;
1569
+ engine.showMain();
1570
+ toggleDisplayMode();
1571
+ };
1572
+ $[3] = engine;
1573
+ $[4] = isMain;
1574
+ $[5] = toggleDisplayMode;
1575
+ $[6] = t1;
1576
+ } else t1 = $[6];
1577
+ const onDblClickMain = t1;
1578
+ let t2;
1579
+ if ($[7] !== engine || $[8] !== isMain || $[9] !== toggleDisplayMode) {
1580
+ t2 = (e_0) => {
1581
+ if (!e_0.altKey || isMain) return;
1582
+ engine.showDraft();
1583
+ toggleDisplayMode();
1584
+ };
1585
+ $[7] = engine;
1586
+ $[8] = isMain;
1587
+ $[9] = toggleDisplayMode;
1588
+ $[10] = t2;
1589
+ } else t2 = $[10];
1590
+ const onDblClickDraft = t2;
1591
+ let t3;
1592
+ if ($[11] !== isMain || $[12] !== isVisualMode) {
1593
+ t3 = isMain && !isVisualMode ? /* @__PURE__ */ jsx("span", { children: "ソース表示" }) : null;
1594
+ $[11] = isMain;
1595
+ $[12] = isVisualMode;
1596
+ $[13] = t3;
1597
+ } else t3 = $[13];
1598
+ let t4;
1599
+ if ($[14] !== engine.commandBus.receiverId || $[15] !== isMain || $[16] !== onDblClickMain || $[17] !== t3) {
1600
+ t4 = /* @__PURE__ */ jsxs("button", {
1601
+ type: "button",
1602
+ "aria-pressed": isMain,
1603
+ command: BGE_COMMAND.switchContent,
1604
+ commandfor: engine.commandBus.receiverId,
1605
+ value: "main",
1606
+ onDoubleClick: onDblClickMain,
1607
+ children: ["本稿モード", t3]
1608
+ });
1609
+ $[14] = engine.commandBus.receiverId;
1610
+ $[15] = isMain;
1611
+ $[16] = onDblClickMain;
1612
+ $[17] = t3;
1613
+ $[18] = t4;
1614
+ } else t4 = $[18];
1615
+ const t5 = !isMain;
1616
+ let t6;
1617
+ if ($[19] !== isMain || $[20] !== isVisualMode) {
1618
+ t6 = !isMain && !isVisualMode ? /* @__PURE__ */ jsx("span", { children: "ソース表示" }) : null;
1619
+ $[19] = isMain;
1620
+ $[20] = isVisualMode;
1621
+ $[21] = t6;
1622
+ } else t6 = $[21];
1623
+ let t7;
1624
+ if ($[22] !== engine.commandBus.receiverId || $[23] !== onDblClickDraft || $[24] !== t5 || $[25] !== t6) {
1625
+ t7 = /* @__PURE__ */ jsxs("button", {
1626
+ type: "button",
1627
+ "aria-pressed": t5,
1628
+ command: BGE_COMMAND.switchContent,
1629
+ commandfor: engine.commandBus.receiverId,
1630
+ value: "draft",
1631
+ onDoubleClick: onDblClickDraft,
1632
+ children: ["下書きモード", t6]
1633
+ });
1634
+ $[22] = engine.commandBus.receiverId;
1635
+ $[23] = onDblClickDraft;
1636
+ $[24] = t5;
1637
+ $[25] = t6;
1638
+ $[26] = t7;
1639
+ } else t7 = $[26];
1640
+ let t8;
1641
+ if ($[27] !== t4 || $[28] !== t7) {
1642
+ t8 = /* @__PURE__ */ jsxs("div", {
1643
+ className: draft_switcher_module_default.draftTabBtn,
1644
+ children: [t4, t7]
1645
+ });
1646
+ $[27] = t4;
1647
+ $[28] = t7;
1648
+ $[29] = t8;
1649
+ } else t8 = $[29];
1650
+ let t9;
1651
+ if ($[30] !== engine.commandBus.receiverId || $[31] !== isMain) {
1652
+ t9 = /* @__PURE__ */ jsx("div", {
1653
+ className: draft_switcher_module_default.draftCopyBtn,
1654
+ children: isMain ? /* @__PURE__ */ jsx("button", {
1655
+ type: "button",
1656
+ command: BGE_COMMAND.copyMainToDraft,
1657
+ commandfor: engine.commandBus.receiverId,
1658
+ children: "本稿を下書きにコピー"
1659
+ }) : /* @__PURE__ */ jsx("button", {
1660
+ type: "button",
1661
+ command: BGE_COMMAND.copyDraftToMain,
1662
+ commandfor: engine.commandBus.receiverId,
1663
+ children: "下書きを本稿にコピー"
1664
+ })
1665
+ });
1666
+ $[30] = engine.commandBus.receiverId;
1667
+ $[31] = isMain;
1668
+ $[32] = t9;
1669
+ } else t9 = $[32];
1670
+ let t10;
1671
+ if ($[33] !== t8 || $[34] !== t9) {
1672
+ t10 = /* @__PURE__ */ jsxs("div", {
1673
+ className: draft_switcher_module_default.draftBtn,
1674
+ children: [t8, t9]
1675
+ });
1676
+ $[33] = t8;
1677
+ $[34] = t9;
1678
+ $[35] = t10;
1679
+ } else t10 = $[35];
1680
+ return t10;
1681
+ }
1682
+ function _temp2$2(s_0) {
1683
+ return s_0.activeArea === "main";
1684
+ }
1685
+ function _temp$2(s) {
1686
+ return s.sourceMode;
1687
+ }
1688
+ //#endregion
1689
+ //#region src/mount.tsx
1690
+ /**
1691
+ * Mount a React node into a DOM container and return a `Disposable`
1692
+ * teardown handle, matching the `UICreator` contract shape used across
1693
+ * the engine.
1694
+ * @param node - The React node to render
1695
+ * @param target - The DOM container
1696
+ * @returns A handle that unmounts the root, via `using` or `cleanUp()`
1697
+ * @example
1698
+ * ```tsx
1699
+ * using mount = reactMount(
1700
+ * <EngineProvider engine={engine}>
1701
+ * <DraftSwitcher />
1702
+ * </EngineProvider>,
1703
+ * container,
1704
+ * );
1705
+ * // Root is unmounted automatically when `mount` goes out of scope.
1706
+ * ```
1707
+ */
1708
+ function reactMount(node, target) {
1709
+ const root = createRoot(target);
1710
+ root.render(node);
1711
+ const teardown = () => {
1712
+ root.unmount();
1713
+ };
1714
+ return {
1715
+ cleanUp: teardown,
1716
+ [Symbol.dispose]: teardown
1717
+ };
1718
+ }
1719
+ //#endregion
1720
+ //#region src/root-error-boundary.tsx
1721
+ /**
1722
+ * Report a render error onto the engine element as `bge:error`. This is
1723
+ * the only way an in-tree failure reaches code outside React — `core`
1724
+ * never reads the event, platform layers (e.g. `local`) may log it.
1725
+ * @param engine - The engine instance to report on
1726
+ * @param error - The thrown value
1727
+ * @param componentStack - The React component stack, when available
1728
+ */
1729
+ function reportRenderError(engine, error, componentStack) {
1730
+ engine.el.dispatchEvent(createBgeEvent("bge:error", {
1731
+ error,
1732
+ componentStack
1733
+ }));
1734
+ }
1735
+ /**
1736
+ * Fallback for {@link RootErrorBoundary}: reports the error and renders
1737
+ * nothing. Only *this boundary's own subtree* is replaced — how big that
1738
+ * subtree is depends entirely on where the boundary is placed. Placed
1739
+ * once around the whole single-root tree (as `createReactView` does for
1740
+ * the top level), it is a last resort: the whole editor blanks. Nested
1741
+ * one level per editable area (as `createReactView` also does) or per
1742
+ * dialog (`EditorDialog`'s own boundary around each dialog's body), it
1743
+ * instead isolates a failure to that one area/dialog and leaves sibling
1744
+ * areas, other dialogs, and the chrome running.
1745
+ * @param root0
1746
+ * @param root0.error
1747
+ */
1748
+ function RootErrorFallback(t0) {
1749
+ const $ = c(4);
1750
+ const { error } = t0;
1751
+ const engine = useEngine();
1752
+ let t1;
1753
+ let t2;
1754
+ if ($[0] !== engine || $[1] !== error) {
1755
+ t1 = () => {
1756
+ reportRenderError(engine, error);
1757
+ };
1758
+ t2 = [engine, error];
1759
+ $[0] = engine;
1760
+ $[1] = error;
1761
+ $[2] = t1;
1762
+ $[3] = t2;
1763
+ } else {
1764
+ t1 = $[2];
1765
+ t2 = $[3];
1766
+ }
1767
+ useEffect(t1, t2);
1768
+ return null;
1769
+ }
1770
+ /**
1771
+ * Reusable error boundary for the client UI tree: reports the caught
1772
+ * error as `bge:error` and blanks only its own subtree. Deliberately not
1773
+ * scoped to any one tree position — `createReactView` places one around
1774
+ * the whole single-root tree as a last resort, and one more per editable
1775
+ * area so a failure in one area (or the `BlockMenu` inside it) does not
1776
+ * blank sibling areas or the dialog chrome. `EditorDialog` places its own
1777
+ * around each dialog's body for the same reason at that granularity.
1778
+ * @param root0
1779
+ * @param root0.children
1780
+ * @example
1781
+ * ```tsx
1782
+ * <EngineProvider engine={engine}>
1783
+ * <RootErrorBoundary>
1784
+ * <BurgerEditorRoot />
1785
+ * </RootErrorBoundary>
1786
+ * </EngineProvider>
1787
+ * ```
1788
+ */
1789
+ function RootErrorBoundary(t0) {
1790
+ const $ = c(2);
1791
+ const { children } = t0;
1792
+ let t1;
1793
+ if ($[0] !== children) {
1794
+ t1 = /* @__PURE__ */ jsx(m, {
1795
+ FallbackComponent: RootErrorFallback,
1796
+ children
1797
+ });
1798
+ $[0] = children;
1799
+ $[1] = t1;
1800
+ } else t1 = $[1];
1801
+ return t1;
1802
+ }
1803
+ //#endregion
1804
+ //#region src/animate-insertion.ts
1805
+ var INSERTION_ANIMATION_DURATION_MS = 400;
1806
+ /**
1807
+ * Expand the block-insertion marker from zero to its natural height.
1808
+ *
1809
+ * Implemented with `Element.animate()` because its `finished` promise
1810
+ * settles regardless of the animation's duration — a CSS transition +
1811
+ * `transitionend` never fires when the duration is 0 (e.g. under
1812
+ * `prefers-reduced-motion: reduce`), which would leave the engine's
1813
+ * processing flag stuck. Cancellation is also treated as completion.
1814
+ * @param markerEl - The marker element wrapping the inserted block
1815
+ * @example
1816
+ * ```ts
1817
+ * await animateInsertion(markerEl);
1818
+ * // The marker is fully expanded (or the animation was skipped).
1819
+ * ```
1820
+ */
1821
+ async function animateInsertion(markerEl) {
1822
+ markerEl.style.height = "auto";
1823
+ const targetHeight = markerEl.getBoundingClientRect().height;
1824
+ markerEl.style.overflow = "hidden";
1825
+ const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
1826
+ await markerEl.animate([{ height: "0px" }, { height: `${targetHeight}px` }], {
1827
+ duration: reducedMotion ? 0 : INSERTION_ANIMATION_DURATION_MS,
1828
+ easing: "ease"
1829
+ }).finished.then(() => {}, () => {});
1830
+ }
1831
+ //#endregion
1832
+ //#region src/use-command.ts
1833
+ /**
1834
+ * Receive Invoker Commands API `command` events on the element the returned
1835
+ * ref callback is attached to. Buttons address the element with
1836
+ * `commandfor={idOfElement}`; `CommandEvent` does not bubble, so the ref
1837
+ * must be on the exact `commandfor` target.
1838
+ *
1839
+ * Returns a ref **callback** (not a `RefObject`) so the listener attaches
1840
+ * as soon as the element mounts, including when the element appears later
1841
+ * from a conditional render — a `useRef` + `useEffect(..., [])` pair only
1842
+ * reads `ref.current` once, at the first commit, and would miss an
1843
+ * element that shows up afterward. `handlers` is read through
1844
+ * `useEffectEvent` so the listener always calls the latest render's
1845
+ * closure without needing `handlers` in the attach effect's deps (and
1846
+ * without re-attaching the DOM listener on every render).
1847
+ * @param handlers - Map of custom command names to handlers
1848
+ * @returns A ref callback to attach to the receiving element
1849
+ * @example
1850
+ * ```tsx
1851
+ * const rootId = useId();
1852
+ * const rootRef = useCommand<HTMLDivElement>({
1853
+ * '--select-tab': (e) => {
1854
+ * setCurrent(Number((e.source as HTMLButtonElement | null)?.value));
1855
+ * },
1856
+ * });
1857
+ * return (
1858
+ * <div ref={rootRef} id={rootId}>
1859
+ * <button command="--select-tab" commandfor={rootId} value="1">タブ1</button>
1860
+ * </div>
1861
+ * );
1862
+ * ```
1863
+ */
1864
+ function useCommand(handlers) {
1865
+ const $ = c(7);
1866
+ const [el, setEl] = useState(null);
1867
+ let t0;
1868
+ if ($[0] !== handlers) {
1869
+ t0 = (event) => {
1870
+ const handler = handlers[event.command];
1871
+ handler?.(event);
1872
+ };
1873
+ $[0] = handlers;
1874
+ $[1] = t0;
1875
+ } else t0 = $[1];
1876
+ const onCommand = useEffectEvent(t0);
1877
+ let t1;
1878
+ if ($[2] !== el || $[3] !== onCommand) {
1879
+ t1 = () => {
1880
+ if (!el) return;
1881
+ const listener = (event_0) => onCommand(event_0);
1882
+ el.addEventListener("command", listener);
1883
+ return () => {
1884
+ el.removeEventListener("command", listener);
1885
+ };
1886
+ };
1887
+ $[2] = el;
1888
+ $[3] = onCommand;
1889
+ $[4] = t1;
1890
+ } else t1 = $[4];
1891
+ let t2;
1892
+ if ($[5] !== el) {
1893
+ t2 = [el];
1894
+ $[5] = el;
1895
+ $[6] = t2;
1896
+ } else t2 = $[6];
1897
+ useEffect(t1, t2);
1898
+ return setEl;
1899
+ }
1900
+ var block_menu_button_module_default = { wrapper: "_wrapper_t7zhr_1" };
1901
+ //#endregion
1902
+ //#region src/components/block-menu-button.tsx
1903
+ /**
1904
+ * Icon button of the block menu with an anchored tooltip. The action is
1905
+ * declared with the Invoker Commands API instead of a click handler.
1906
+ * @param root0
1907
+ * @param root0.label
1908
+ * @param root0.command
1909
+ * @param root0.commandfor
1910
+ * @param root0.value
1911
+ * @param root0.children
1912
+ * @example
1913
+ * ```tsx
1914
+ * <BlockMenuButton
1915
+ * label="ブロックを削除"
1916
+ * command={BGE_COMMAND.removeBlock}
1917
+ * commandfor={engine.commandBus.receiverId}>
1918
+ * <IconTrash />
1919
+ * </BlockMenuButton>
1920
+ * ```
1921
+ */
1922
+ function BlockMenuButton(t0) {
1923
+ const $ = c(17);
1924
+ const { label, command, commandfor, value, children } = t0;
1925
+ const uid = useId();
1926
+ let t1;
1927
+ if ($[0] !== uid) {
1928
+ t1 = CSS.escape(uid);
1929
+ $[0] = uid;
1930
+ $[1] = t1;
1931
+ } else t1 = $[1];
1932
+ const t2 = `--anchor-${t1}`;
1933
+ let t3;
1934
+ if ($[2] !== t2) {
1935
+ t3 = { "--name": t2 };
1936
+ $[2] = t2;
1937
+ $[3] = t3;
1938
+ } else t3 = $[3];
1939
+ const t4 = t3;
1940
+ let t5;
1941
+ if ($[4] !== children || $[5] !== command || $[6] !== commandfor || $[7] !== uid || $[8] !== value) {
1942
+ t5 = /* @__PURE__ */ jsx("button", {
1943
+ type: "button",
1944
+ "aria-labelledby": uid,
1945
+ command,
1946
+ commandfor,
1947
+ value,
1948
+ children
1949
+ });
1950
+ $[4] = children;
1951
+ $[5] = command;
1952
+ $[6] = commandfor;
1953
+ $[7] = uid;
1954
+ $[8] = value;
1955
+ $[9] = t5;
1956
+ } else t5 = $[9];
1957
+ let t6;
1958
+ if ($[10] !== label || $[11] !== uid) {
1959
+ t6 = /* @__PURE__ */ jsx("span", {
1960
+ id: uid,
1961
+ children: label
1962
+ });
1963
+ $[10] = label;
1964
+ $[11] = uid;
1965
+ $[12] = t6;
1966
+ } else t6 = $[12];
1967
+ let t7;
1968
+ if ($[13] !== t4 || $[14] !== t5 || $[15] !== t6) {
1969
+ t7 = /* @__PURE__ */ jsxs("div", {
1970
+ className: block_menu_button_module_default.wrapper,
1971
+ style: t4,
1972
+ children: [t5, t6]
1973
+ });
1974
+ $[13] = t4;
1975
+ $[14] = t5;
1976
+ $[15] = t6;
1977
+ $[16] = t7;
1978
+ } else t7 = $[16];
1979
+ return t7;
1980
+ }
1981
+ var block_menu_module_default = {
1982
+ bgeMenuBase: "_bgeMenuBase_2cydd_1",
1983
+ bgeMenuMargin: "_bgeMenuMargin_2cydd_10",
1984
+ bgeMenu: "_bgeMenu_2cydd_1",
1985
+ bgeItemOverlay: "_bgeItemOverlay_2cydd_68",
1986
+ bgeMoveGroup: "_bgeMoveGroup_2cydd_85",
1987
+ bgeStandardGroup: "_bgeStandardGroup_2cydd_86"
1988
+ };
1989
+ //#endregion
1990
+ //#region src/components/block-menu-view.tsx
1991
+ /**
1992
+ * 選択中ブロックの位置・サイズ・下マージン。座標とサイズはドキュメント
1993
+ * 座標系のpx。`BlockMenu` が `getBlockAtPosition` の戻り値から算出し、
1994
+ * `BlockMenuView` はこれをCSSカスタムプロパティに変換してメニューを
1995
+ * ブロックに追従させる。
1996
+ * @example
1997
+ * ```ts
1998
+ * const geometry: MenuGeometry = {
1999
+ * width: 320,
2000
+ * height: 120,
2001
+ * x: 0,
2002
+ * y: 0,
2003
+ * marginBlockEnd: 16,
2004
+ * marginBlockEndValue: '1em',
2005
+ * };
2006
+ * ```
2007
+ */
2008
+ /**
2009
+ * ブロック内の各アイテム(`[data-bgi]`要素)のオーバーレイ矩形。
2010
+ * 座標はブロック左上を原点とした相対px。クリックするとそのアイテムの
2011
+ * エディタが開く透明ボタンの位置決めに使う。
2012
+ * @example
2013
+ * ```ts
2014
+ * const rect: ItemOverlayRect = { x: 8, y: 8, width: 140, height: 40 };
2015
+ * ```
2016
+ */
2017
+ /**
2018
+ * `BlockMenu` の描画専用の中身。マウス追跡・`BurgerBlock` 解決・
2019
+ * `engine` 接続は一切持たず、位置とアイテム矩形を props で受け取って
2020
+ * 並べるだけの純粋なプレゼンテーションコンポーネント。
2021
+ *
2022
+ * `BurgerBlock` の実インスタンス生成なしに見た目だけ確認したい用途
2023
+ * (Storybook)のために `BlockMenu` から切り出されている。
2024
+ * @param root0
2025
+ * @param root0.rootRef
2026
+ * @param root0.menuId
2027
+ * @param root0.commandBusId
2028
+ * @param root0.visible
2029
+ * @param root0.geometry
2030
+ * @param root0.itemRects
2031
+ * @param root0.isMutable
2032
+ * @example
2033
+ * ```tsx
2034
+ * <BlockMenuView
2035
+ * rootRef={rootRef}
2036
+ * menuId="bge-block-menu"
2037
+ * commandBusId={engine.commandBus.receiverId}
2038
+ * visible
2039
+ * geometry={{ width: 100, height: 40, x: 0, y: 0, marginBlockEnd: 0, marginBlockEndValue: '0px' }}
2040
+ * itemRects={[]}
2041
+ * isMutable
2042
+ * />
2043
+ * ```
2044
+ */
2045
+ function BlockMenuView(t0) {
2046
+ const $ = c(59);
2047
+ const { rootRef, menuId, commandBusId, visible, geometry, itemRects, isMutable } = t0;
2048
+ const t1 = !visible;
2049
+ const t2 = `${geometry.width}px`;
2050
+ const t3 = `${geometry.height}px`;
2051
+ const t4 = `${geometry.x}px`;
2052
+ const t5 = `${geometry.y}px`;
2053
+ const t6 = `${geometry.marginBlockEnd ?? "0"}px`;
2054
+ let t7;
2055
+ if ($[0] !== t2 || $[1] !== t3 || $[2] !== t4 || $[3] !== t5 || $[4] !== t6) {
2056
+ t7 = {
2057
+ "--width": t2,
2058
+ "--height": t3,
2059
+ "--x": t4,
2060
+ "--y": t5,
2061
+ "--margin-block-end": t6
2062
+ };
2063
+ $[0] = t2;
2064
+ $[1] = t3;
2065
+ $[2] = t4;
2066
+ $[3] = t5;
2067
+ $[4] = t6;
2068
+ $[5] = t7;
2069
+ } else t7 = $[5];
2070
+ const t8 = t7;
2071
+ let t9;
2072
+ if ($[6] !== itemRects || $[7] !== menuId) {
2073
+ let t10;
2074
+ if ($[9] !== menuId) {
2075
+ t10 = (rect, index) => /* @__PURE__ */ jsx("button", {
2076
+ type: "button",
2077
+ className: block_menu_module_default.bgeItemOverlay,
2078
+ "aria-label": "コンテンツを編集",
2079
+ command: "--open-item-editor",
2080
+ commandfor: menuId,
2081
+ value: index,
2082
+ style: {
2083
+ insetInlineStart: `${rect.x}px`,
2084
+ insetBlockStart: `${rect.y}px`,
2085
+ inlineSize: `${rect.width}px`,
2086
+ blockSize: `${rect.height}px`
2087
+ }
2088
+ }, index);
2089
+ $[9] = menuId;
2090
+ $[10] = t10;
2091
+ } else t10 = $[10];
2092
+ t9 = itemRects.map(t10);
2093
+ $[6] = itemRects;
2094
+ $[7] = menuId;
2095
+ $[8] = t9;
2096
+ } else t9 = $[8];
2097
+ let t10;
2098
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
2099
+ t10 = /* @__PURE__ */ jsx(IconArrowBigUpLine, {});
2100
+ $[11] = t10;
2101
+ } else t10 = $[11];
2102
+ let t11;
2103
+ if ($[12] !== commandBusId) {
2104
+ t11 = /* @__PURE__ */ jsx(BlockMenuButton, {
2105
+ label: "ひとつ上へ移動",
2106
+ command: BGE_COMMAND.moveBlock,
2107
+ commandfor: commandBusId,
2108
+ value: "up",
2109
+ children: t10
2110
+ });
2111
+ $[12] = commandBusId;
2112
+ $[13] = t11;
2113
+ } else t11 = $[13];
2114
+ let t12;
2115
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
2116
+ t12 = /* @__PURE__ */ jsx(IconArrowBigDownLine, {});
2117
+ $[14] = t12;
2118
+ } else t12 = $[14];
2119
+ let t13;
2120
+ if ($[15] !== commandBusId) {
2121
+ t13 = /* @__PURE__ */ jsx(BlockMenuButton, {
2122
+ label: "ひとつ下へ移動",
2123
+ command: BGE_COMMAND.moveBlock,
2124
+ commandfor: commandBusId,
2125
+ value: "down",
2126
+ children: t12
2127
+ });
2128
+ $[15] = commandBusId;
2129
+ $[16] = t13;
2130
+ } else t13 = $[16];
2131
+ let t14;
2132
+ if ($[17] !== t11 || $[18] !== t13) {
2133
+ t14 = /* @__PURE__ */ jsxs("div", {
2134
+ className: block_menu_module_default.bgeMoveGroup,
2135
+ children: [t11, t13]
2136
+ });
2137
+ $[17] = t11;
2138
+ $[18] = t13;
2139
+ $[19] = t14;
2140
+ } else t14 = $[19];
2141
+ let t15;
2142
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
2143
+ t15 = /* @__PURE__ */ jsx(IconRowInsertTop, {});
2144
+ $[20] = t15;
2145
+ } else t15 = $[20];
2146
+ let t16;
2147
+ if ($[21] !== commandBusId) {
2148
+ t16 = /* @__PURE__ */ jsx(BlockMenuButton, {
2149
+ label: "上にブロックを追加",
2150
+ command: BGE_COMMAND.insertBlock,
2151
+ commandfor: commandBusId,
2152
+ value: "before",
2153
+ children: t15
2154
+ });
2155
+ $[21] = commandBusId;
2156
+ $[22] = t16;
2157
+ } else t16 = $[22];
2158
+ let t17;
2159
+ if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
2160
+ t17 = /* @__PURE__ */ jsx(IconRowInsertBottom, {});
2161
+ $[23] = t17;
2162
+ } else t17 = $[23];
2163
+ let t18;
2164
+ if ($[24] !== commandBusId) {
2165
+ t18 = /* @__PURE__ */ jsx(BlockMenuButton, {
2166
+ label: "下にブロックを追加",
2167
+ command: BGE_COMMAND.insertBlock,
2168
+ commandfor: commandBusId,
2169
+ value: "after",
2170
+ children: t17
2171
+ });
2172
+ $[24] = commandBusId;
2173
+ $[25] = t18;
2174
+ } else t18 = $[25];
2175
+ let t19;
2176
+ if ($[26] !== commandBusId || $[27] !== isMutable) {
2177
+ t19 = isMutable ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(BlockMenuButton, {
2178
+ label: "ブロック内に要素を追加",
2179
+ command: BGE_COMMAND.updateGridItems,
2180
+ commandfor: commandBusId,
2181
+ value: "+1",
2182
+ children: /* @__PURE__ */ jsx(IconLayoutGridAdd, {})
2183
+ }), /* @__PURE__ */ jsx(BlockMenuButton, {
2184
+ label: "ブロック内の要素を削除",
2185
+ command: BGE_COMMAND.updateGridItems,
2186
+ commandfor: commandBusId,
2187
+ value: "-1",
2188
+ children: /* @__PURE__ */ jsx(IconLayoutGridRemove, {})
2189
+ })] }) : null;
2190
+ $[26] = commandBusId;
2191
+ $[27] = isMutable;
2192
+ $[28] = t19;
2193
+ } else t19 = $[28];
2194
+ let t20;
2195
+ if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
2196
+ t20 = /* @__PURE__ */ jsx(IconSettings, {});
2197
+ $[29] = t20;
2198
+ } else t20 = $[29];
2199
+ let t21;
2200
+ if ($[30] !== commandBusId) {
2201
+ t21 = /* @__PURE__ */ jsx(BlockMenuButton, {
2202
+ label: "オプション設定",
2203
+ command: BGE_COMMAND.openBlockOptions,
2204
+ commandfor: commandBusId,
2205
+ children: t20
2206
+ });
2207
+ $[30] = commandBusId;
2208
+ $[31] = t21;
2209
+ } else t21 = $[31];
2210
+ let t22;
2211
+ if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
2212
+ t22 = /* @__PURE__ */ jsx(IconClipboardPlus, {});
2213
+ $[32] = t22;
2214
+ } else t22 = $[32];
2215
+ let t23;
2216
+ if ($[33] !== commandBusId) {
2217
+ t23 = /* @__PURE__ */ jsx(BlockMenuButton, {
2218
+ label: "ブロックをコピー",
2219
+ command: BGE_COMMAND.copyBlock,
2220
+ commandfor: commandBusId,
2221
+ children: t22
2222
+ });
2223
+ $[33] = commandBusId;
2224
+ $[34] = t23;
2225
+ } else t23 = $[34];
2226
+ let t24;
2227
+ if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
2228
+ t24 = /* @__PURE__ */ jsx(IconTrash, {});
2229
+ $[35] = t24;
2230
+ } else t24 = $[35];
2231
+ let t25;
2232
+ if ($[36] !== commandBusId) {
2233
+ t25 = /* @__PURE__ */ jsx(BlockMenuButton, {
2234
+ label: "ブロックを削除",
2235
+ command: BGE_COMMAND.removeBlock,
2236
+ commandfor: commandBusId,
2237
+ children: t24
2238
+ });
2239
+ $[36] = commandBusId;
2240
+ $[37] = t25;
2241
+ } else t25 = $[37];
2242
+ let t26;
2243
+ if ($[38] !== t16 || $[39] !== t18 || $[40] !== t19 || $[41] !== t21 || $[42] !== t23 || $[43] !== t25) {
2244
+ t26 = /* @__PURE__ */ jsxs("div", {
2245
+ className: block_menu_module_default.bgeStandardGroup,
2246
+ children: [
2247
+ t16,
2248
+ t18,
2249
+ t19,
2250
+ t21,
2251
+ t23,
2252
+ t25
2253
+ ]
2254
+ });
2255
+ $[38] = t16;
2256
+ $[39] = t18;
2257
+ $[40] = t19;
2258
+ $[41] = t21;
2259
+ $[42] = t23;
2260
+ $[43] = t25;
2261
+ $[44] = t26;
2262
+ } else t26 = $[44];
2263
+ let t27;
2264
+ if ($[45] !== t14 || $[46] !== t26) {
2265
+ t27 = /* @__PURE__ */ jsxs("div", {
2266
+ className: block_menu_module_default.bgeMenu,
2267
+ children: [t14, t26]
2268
+ });
2269
+ $[45] = t14;
2270
+ $[46] = t26;
2271
+ $[47] = t27;
2272
+ } else t27 = $[47];
2273
+ let t28;
2274
+ if ($[48] !== geometry.marginBlockEnd || $[49] !== geometry.marginBlockEndValue) {
2275
+ t28 = /* @__PURE__ */ jsx("div", {
2276
+ className: block_menu_module_default.bgeMenuMargin,
2277
+ children: /* @__PURE__ */ jsxs("span", { children: [
2278
+ "余白: ",
2279
+ geometry.marginBlockEndValue,
2280
+ " (",
2281
+ geometry.marginBlockEnd,
2282
+ "px)"
2283
+ ] })
2284
+ });
2285
+ $[48] = geometry.marginBlockEnd;
2286
+ $[49] = geometry.marginBlockEndValue;
2287
+ $[50] = t28;
2288
+ } else t28 = $[50];
2289
+ let t29;
2290
+ if ($[51] !== menuId || $[52] !== rootRef || $[53] !== t1 || $[54] !== t27 || $[55] !== t28 || $[56] !== t8 || $[57] !== t9) {
2291
+ t29 = /* @__PURE__ */ jsxs("div", {
2292
+ ref: rootRef,
2293
+ id: menuId,
2294
+ hidden: t1,
2295
+ className: block_menu_module_default.bgeMenuBase,
2296
+ style: t8,
2297
+ children: [
2298
+ t9,
2299
+ t27,
2300
+ t28
2301
+ ]
2302
+ });
2303
+ $[51] = menuId;
2304
+ $[52] = rootRef;
2305
+ $[53] = t1;
2306
+ $[54] = t27;
2307
+ $[55] = t28;
2308
+ $[56] = t8;
2309
+ $[57] = t9;
2310
+ $[58] = t29;
2311
+ } else t29 = $[58];
2312
+ return t29;
2313
+ }
2314
+ //#endregion
2315
+ //#region src/components/block-menu.tsx
2316
+ /**
2317
+ * Hover menu over the selected block inside the editable area iframe.
2318
+ * Block operations are declared as engine commands; positioning and
2319
+ * visibility are React state owned entirely by this component — the
2320
+ * single source of truth. While `engine.uiState.processing` is true the
2321
+ * menu hides itself by subscribing to the store; nothing outside React
2322
+ * ever writes this component's `hidden` attribute (a direct DOM write
2323
+ * would leave React's `visible` state out of sync and a later same-value
2324
+ * `setVisible(true)` would be skipped, leaving the menu stuck hidden).
2325
+ *
2326
+ * マウス追跡・`BurgerBlock` 解決・`engine` 接続を担うコンテナで、
2327
+ * 実際の描画は {@link BlockMenuView} に委譲する。`BlockMenuView` は
2328
+ * `BurgerBlock` の実インスタンスなしに見た目だけ確認できるため、
2329
+ * Storybook 等では `BlockMenuView` を直接使う。
2330
+ * @param root0
2331
+ * @param root0.container
2332
+ * @example
2333
+ * ```tsx
2334
+ * <BlockMenu container={frameBody} />
2335
+ * ```
2336
+ */
2337
+ function BlockMenu(t0) {
2338
+ const $ = c(32);
2339
+ const { container } = t0;
2340
+ const engine = useEngine();
2341
+ const menuId = useId();
2342
+ const currentBlock = useUIState(_temp$1);
2343
+ const [visible, setVisible] = useState(false);
2344
+ let t1;
2345
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2346
+ t1 = [];
2347
+ $[0] = t1;
2348
+ } else t1 = $[0];
2349
+ const [itemRects, setItemRects] = useState(t1);
2350
+ let t2;
2351
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
2352
+ t2 = [];
2353
+ $[1] = t2;
2354
+ } else t2 = $[1];
2355
+ const itemsRef = useRef(t2);
2356
+ let t3;
2357
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
2358
+ t3 = {
2359
+ width: 0,
2360
+ height: 0,
2361
+ x: 0,
2362
+ y: 0,
2363
+ marginBlockEnd: 0,
2364
+ marginBlockEndValue: "0px"
2365
+ };
2366
+ $[2] = t3;
2367
+ } else t3 = $[2];
2368
+ const [geometry, setGeometry] = useState(t3);
2369
+ let t4;
2370
+ if ($[3] !== engine.isProcessed || $[4] !== engine.uiState) {
2371
+ t4 = { "--open-item-editor": (e) => {
2372
+ if (engine.isProcessed) return;
2373
+ const index = Number(e.source?.value);
2374
+ const item = itemsRef.current[index];
2375
+ if (!item) throw new Error(`item overlay index ${index} does not resolve to an Item`);
2376
+ engine.uiState.openItemEditor(item);
2377
+ } };
2378
+ $[3] = engine.isProcessed;
2379
+ $[4] = engine.uiState;
2380
+ $[5] = t4;
2381
+ } else t4 = $[5];
2382
+ const rootRef = useCommand(t4);
2383
+ let t5;
2384
+ if ($[6] !== engine) {
2385
+ t5 = () => {
2386
+ setVisible(false);
2387
+ engine.clearCurrentBlock();
2388
+ };
2389
+ $[6] = engine;
2390
+ $[7] = t5;
2391
+ } else t5 = $[7];
2392
+ const hide = t5;
2393
+ let t6;
2394
+ if ($[8] !== engine.uiState || $[9] !== hide) {
2395
+ t6 = () => engine.uiState.subscribe(() => {
2396
+ if (engine.uiState.getSnapshot().processing) hide();
2397
+ });
2398
+ $[8] = engine.uiState;
2399
+ $[9] = hide;
2400
+ $[10] = t6;
2401
+ } else t6 = $[10];
2402
+ let t7;
2403
+ if ($[11] !== engine || $[12] !== hide) {
2404
+ t7 = [engine, hide];
2405
+ $[11] = engine;
2406
+ $[12] = hide;
2407
+ $[13] = t7;
2408
+ } else t7 = $[13];
2409
+ useEffect(t6, t7);
2410
+ let t8;
2411
+ if ($[14] !== container.ownerDocument || $[15] !== engine || $[16] !== hide) {
2412
+ t8 = () => {
2413
+ const doc = container.ownerDocument;
2414
+ const body = doc.body;
2415
+ const win = doc.defaultView;
2416
+ let mouseX = 0;
2417
+ let mouseY = 0;
2418
+ let raf = 0;
2419
+ const updatePosition = () => {
2420
+ const selected = getBlockAtPosition(doc, mouseX, mouseY);
2421
+ if (!selected) {
2422
+ hide();
2423
+ return;
2424
+ }
2425
+ setVisible(true);
2426
+ const { block, rect, marginBlockEnd } = selected;
2427
+ setGeometry({
2428
+ width: rect.width,
2429
+ height: rect.height,
2430
+ x: rect.left,
2431
+ y: rect.top,
2432
+ marginBlockEnd,
2433
+ marginBlockEndValue: window.getComputedStyle(block.el).getPropertyValue("--bge-block-margin")
2434
+ });
2435
+ const itemEntries = [...block.el.querySelectorAll("[data-bgi]")].map(_temp2$1).filter(_temp3);
2436
+ itemsRef.current = itemEntries.map(_temp4);
2437
+ setItemRects(itemEntries.map((t9) => {
2438
+ const { el: itemEl_0 } = t9;
2439
+ const itemRect = itemEl_0.getBoundingClientRect();
2440
+ return {
2441
+ x: itemRect.left - rect.left,
2442
+ y: itemRect.top - rect.top,
2443
+ width: itemRect.width,
2444
+ height: itemRect.height
2445
+ };
2446
+ }));
2447
+ engine.setCurrentBlock(block);
2448
+ };
2449
+ const scheduleUpdate = () => {
2450
+ cancelAnimationFrame(raf);
2451
+ if (engine.isProcessed) {
2452
+ hide();
2453
+ return;
2454
+ }
2455
+ raf = requestAnimationFrame(() => {
2456
+ updatePosition();
2457
+ });
2458
+ };
2459
+ const onMouseMove = (e_0) => {
2460
+ mouseX = e_0.pageX;
2461
+ mouseY = e_0.pageY;
2462
+ scheduleUpdate();
2463
+ };
2464
+ const onHideEvent = () => hide();
2465
+ body.addEventListener("mousemove", onMouseMove);
2466
+ body.addEventListener("mouseleave", onHideEvent);
2467
+ doc.addEventListener("mouseleave", onHideEvent);
2468
+ win?.addEventListener("mouseleave", onHideEvent);
2469
+ globalThis.addEventListener("resize", onHideEvent);
2470
+ engine.el.addEventListener("bge:saved", scheduleUpdate);
2471
+ const observer = new MutationObserver((mutations) => {
2472
+ for (const mutation of mutations) for (const node of mutation.addedNodes) {
2473
+ if (!(node instanceof HTMLElement)) continue;
2474
+ const images = node.querySelectorAll("img");
2475
+ for (const img of images) {
2476
+ img.addEventListener("load", scheduleUpdate, { once: true });
2477
+ img.addEventListener("error", scheduleUpdate, { once: true });
2478
+ img.addEventListener("abort", scheduleUpdate, { once: true });
2479
+ }
2480
+ }
2481
+ });
2482
+ observer.observe(doc, {
2483
+ childList: true,
2484
+ subtree: true
2485
+ });
2486
+ return () => {
2487
+ body.removeEventListener("mousemove", onMouseMove);
2488
+ body.removeEventListener("mouseleave", onHideEvent);
2489
+ doc.removeEventListener("mouseleave", onHideEvent);
2490
+ win?.removeEventListener("mouseleave", onHideEvent);
2491
+ globalThis.removeEventListener("resize", onHideEvent);
2492
+ engine.el.removeEventListener("bge:saved", scheduleUpdate);
2493
+ observer.disconnect();
2494
+ cancelAnimationFrame(raf);
2495
+ };
2496
+ };
2497
+ $[14] = container.ownerDocument;
2498
+ $[15] = engine;
2499
+ $[16] = hide;
2500
+ $[17] = t8;
2501
+ } else t8 = $[17];
2502
+ let t9;
2503
+ if ($[18] !== container || $[19] !== engine || $[20] !== hide) {
2504
+ t9 = [
2505
+ engine,
2506
+ container,
2507
+ hide
2508
+ ];
2509
+ $[18] = container;
2510
+ $[19] = engine;
2511
+ $[20] = hide;
2512
+ $[21] = t9;
2513
+ } else t9 = $[21];
2514
+ useEffect(t8, t9);
2515
+ let t10;
2516
+ if ($[22] !== currentBlock) {
2517
+ t10 = currentBlock?.isMutable() ?? false;
2518
+ $[22] = currentBlock;
2519
+ $[23] = t10;
2520
+ } else t10 = $[23];
2521
+ const isMutable = t10;
2522
+ let t11;
2523
+ if ($[24] !== engine.commandBus.receiverId || $[25] !== geometry || $[26] !== isMutable || $[27] !== itemRects || $[28] !== menuId || $[29] !== rootRef || $[30] !== visible) {
2524
+ t11 = /* @__PURE__ */ jsx(BlockMenuView, {
2525
+ rootRef,
2526
+ menuId,
2527
+ commandBusId: engine.commandBus.receiverId,
2528
+ visible,
2529
+ geometry,
2530
+ itemRects,
2531
+ isMutable
2532
+ });
2533
+ $[24] = engine.commandBus.receiverId;
2534
+ $[25] = geometry;
2535
+ $[26] = isMutable;
2536
+ $[27] = itemRects;
2537
+ $[28] = menuId;
2538
+ $[29] = rootRef;
2539
+ $[30] = visible;
2540
+ $[31] = t11;
2541
+ } else t11 = $[31];
2542
+ return t11;
2543
+ }
2544
+ function _temp4(entry_0) {
2545
+ return entry_0.item;
2546
+ }
2547
+ function _temp3(entry) {
2548
+ return entry.item != null;
2549
+ }
2550
+ function _temp2$1(itemEl) {
2551
+ return {
2552
+ el: itemEl,
2553
+ item: Item.getInstance(itemEl)
2554
+ };
2555
+ }
2556
+ function _temp$1(s) {
2557
+ return s.currentBlock;
2558
+ }
2559
+ //#endregion
2560
+ //#region src/components/initial-insertion-button.tsx
2561
+ /**
2562
+ * Button shown in an empty editable area to insert the first block.
2563
+ * Declares the engine command instead of taking a callback.
2564
+ * @param root0
2565
+ * @param root0.commandBusId
2566
+ * @example
2567
+ * ```tsx
2568
+ * reactMount(<InitialInsertionButton commandBusId={engine.commandBus.receiverId} />, container);
2569
+ * ```
2570
+ */
2571
+ function InitialInsertionButton(t0) {
2572
+ const $ = c(2);
2573
+ const { commandBusId } = t0;
2574
+ let t1;
2575
+ if ($[0] !== commandBusId) {
2576
+ t1 = /* @__PURE__ */ jsx("button", {
2577
+ className: "insert_after",
2578
+ type: "button",
2579
+ command: BGE_COMMAND.insertInitialBlock,
2580
+ commandfor: commandBusId,
2581
+ children: "下に要素を追加"
2582
+ });
2583
+ $[0] = commandBusId;
2584
+ $[1] = t1;
2585
+ } else t1 = $[1];
2586
+ return t1;
2587
+ }
2588
+ //#endregion
2589
+ //#region src/components/editable-area-view.tsx
2590
+ var CONTAINER_PADDING = 10;
2591
+ var CONTENT_ID = "bge-editable-area";
2592
+ /**
2593
+ * The React shell of one editable area: the iframe hosting the edited
2594
+ * content, the HTML source textarea, and the in-frame UI islands
2595
+ * (block menu, initial insertion button) rendered through a portal.
2596
+ *
2597
+ * All presentation state is React state derived from `engine.uiState`
2598
+ * and engine events — the engine never touches this component's DOM.
2599
+ * The iframe is rendered unconditionally at a fixed position in the
2600
+ * tree (visibility is `hidden` only) because unmounting an iframe
2601
+ * destroys its document, and the engine owns the content inside it.
2602
+ * Reads the engine via {@link useEngine}, wired up by the view that
2603
+ * portals this component in (`createReactView`).
2604
+ * @param root0
2605
+ * @param root0.type
2606
+ * @param root0.initialContent
2607
+ * @param root0.stylesheets
2608
+ * @param root0.classList
2609
+ * @param root0.onReady
2610
+ * @example
2611
+ * ```tsx
2612
+ * <EditableAreaView
2613
+ * type="main"
2614
+ * initialContent={html}
2615
+ * stylesheets={stylesheets}
2616
+ * classList={classList}
2617
+ * onReady={(host) => resolve(host)}
2618
+ * />
2619
+ * ```
2620
+ */
2621
+ function EditableAreaView(t0) {
2622
+ const $ = c(60);
2623
+ const { type, initialContent, stylesheets, classList, onReady } = t0;
2624
+ const engine = useEngine();
2625
+ let t1;
2626
+ if ($[0] !== type) {
2627
+ t1 = (s) => s.sourceMode[type];
2628
+ $[0] = type;
2629
+ $[1] = t1;
2630
+ } else t1 = $[1];
2631
+ const sourceMode = useUIState(t1);
2632
+ const processing = useUIState(_temp);
2633
+ const dialogOpen = useUIState(_temp2);
2634
+ let t2;
2635
+ if ($[2] !== type) {
2636
+ t2 = (s_2) => s_2.activeArea === type;
2637
+ $[2] = type;
2638
+ $[3] = t2;
2639
+ } else t2 = $[3];
2640
+ const active = useUIState(t2);
2641
+ const [sourceText, setSourceText] = useState(initialContent);
2642
+ let t3;
2643
+ if ($[4] !== initialContent) {
2644
+ t3 = initialContent.trim();
2645
+ $[4] = initialContent;
2646
+ $[5] = t3;
2647
+ } else t3 = $[5];
2648
+ const [isEmpty, setIsEmpty] = useState(t3 === "");
2649
+ const [height, setHeight] = useState(0);
2650
+ const [frameBody, setFrameBody] = useState(null);
2651
+ const initializedRef = useRef(false);
2652
+ const resizeObserverRef = useRef(null);
2653
+ let t4;
2654
+ if ($[6] !== classList || $[7] !== engine.commandBus || $[8] !== onReady || $[9] !== stylesheets) {
2655
+ t4 = (iframe) => {
2656
+ if (!iframe || initializedRef.current) return;
2657
+ initializedRef.current = true;
2658
+ const frameWindow = iframe.contentWindow;
2659
+ if (!frameWindow) throw new Error("Impossible error: The contentWindow of created iframe is null.");
2660
+ const frameDoc = frameWindow.document;
2661
+ frameDoc.open();
2662
+ frameDoc.write("<!doctype html><html><head></head><body></body></html>");
2663
+ frameDoc.close();
2664
+ for (const { path, id } of stylesheets) appendStylesheetTo(frameDoc, path, id);
2665
+ const injectedUiStyle = frameDoc.createElement("style");
2666
+ injectedUiStyle.textContent = `@layer ${CSS_LAYER.ui} {
2667
+ [data-bge-component='block-menu'] {
2668
+ position: absolute;
2669
+ inset: 0;
2670
+ z-index: 2147483647;
2671
+ pointer-events: none;
2672
+ }
2673
+
2674
+ /* #0c7e9e はui.cssの--bge-ui-primary-colorと同じ値。iframe文書には
2675
+ その:root変数定義が読み込まれない(このstyleタグがそもそも
2676
+ その代替)ため、ここではvar()参照できずハードコードしている。
2677
+ 将来テーマカラーを変更する際はこの値も揃えて更新すること */
2678
+ @keyframes bge-highlight-blink {
2679
+ 0%, 100% {
2680
+ outline-color: transparent;
2681
+ background-color: transparent;
2682
+ }
2683
+ 50% {
2684
+ outline-color: #0c7e9e;
2685
+ background-color: rgb(12 126 158 / 12%);
2686
+ }
2687
+ }
2688
+
2689
+ [data-bge-highlight] {
2690
+ outline: 3px solid transparent;
2691
+ outline-offset: 2px;
2692
+ animation: bge-highlight-blink 0.5s ease-in-out 2;
2693
+ }
2694
+ }`;
2695
+ frameDoc.head.append(injectedUiStyle);
2696
+ frameDoc.body.setAttribute("style", "margin: 0; border: 0;");
2697
+ engine.commandBus.createReceiver(frameDoc.body);
2698
+ const containerElement = frameDoc.createElement("div");
2699
+ containerElement.id = CONTENT_ID;
2700
+ containerElement.style.setProperty("padding", `${CONTAINER_PADDING}px`, "important");
2701
+ containerElement.style.setProperty("overflow", "hidden", "important");
2702
+ containerElement.style.setProperty("margin", "0", "important");
2703
+ containerElement.style.setProperty("box-sizing", "border-box", "important");
2704
+ containerElement.classList.add(...classList);
2705
+ containerElement.dataset.bgeComponent = "editable-area";
2706
+ frameDoc.body.append(containerElement);
2707
+ if (typeof ResizeObserver !== "undefined") {
2708
+ const observer = new ResizeObserver(() => {
2709
+ requestAnimationFrame(() => {
2710
+ setHeight(containerElement.getBoundingClientRect().height + 20);
2711
+ });
2712
+ });
2713
+ observer.observe(containerElement);
2714
+ resizeObserverRef.current = observer;
2715
+ }
2716
+ setFrameBody(frameDoc.body);
2717
+ onReady({
2718
+ containerElement,
2719
+ animateInsertion
2720
+ });
2721
+ };
2722
+ $[6] = classList;
2723
+ $[7] = engine.commandBus;
2724
+ $[8] = onReady;
2725
+ $[9] = stylesheets;
2726
+ $[10] = t4;
2727
+ } else t4 = $[10];
2728
+ const initFrame = t4;
2729
+ let t5;
2730
+ let t6;
2731
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
2732
+ t5 = () => () => {
2733
+ resizeObserverRef.current?.disconnect();
2734
+ };
2735
+ t6 = [];
2736
+ $[11] = t5;
2737
+ $[12] = t6;
2738
+ } else {
2739
+ t5 = $[11];
2740
+ t6 = $[12];
2741
+ }
2742
+ useEffect(t5, t6);
2743
+ let t7;
2744
+ if ($[13] !== engine.el || $[14] !== type) {
2745
+ t7 = () => {
2746
+ const onSaved = (e) => {
2747
+ const value = type === "main" ? e.detail.main : e.detail.draft ?? "";
2748
+ setSourceText(value);
2749
+ setIsEmpty(value.trim() === "");
2750
+ };
2751
+ engine.el.addEventListener("bge:saved", onSaved);
2752
+ return () => {
2753
+ engine.el.removeEventListener("bge:saved", onSaved);
2754
+ };
2755
+ };
2756
+ $[13] = engine.el;
2757
+ $[14] = type;
2758
+ $[15] = t7;
2759
+ } else t7 = $[15];
2760
+ let t8;
2761
+ if ($[16] !== engine || $[17] !== type) {
2762
+ t8 = [engine, type];
2763
+ $[16] = engine;
2764
+ $[17] = type;
2765
+ $[18] = t8;
2766
+ } else t8 = $[18];
2767
+ useEffect(t7, t8);
2768
+ let t9;
2769
+ if ($[19] !== sourceText) {
2770
+ t9 = () => sourceText;
2771
+ $[19] = sourceText;
2772
+ $[20] = t9;
2773
+ } else t9 = $[20];
2774
+ const getPendingSourceText = useEffectEvent(t9);
2775
+ let t10;
2776
+ if ($[21] !== engine || $[22] !== type) {
2777
+ t10 = (value_0) => {
2778
+ engine.commitSourceEdit(type, value_0).then(() => {
2779
+ const committed = engine.getEditableContent(type)?.getContentsAsString() ?? "";
2780
+ setSourceText(committed);
2781
+ setIsEmpty(committed.trim() === "");
2782
+ });
2783
+ };
2784
+ $[21] = engine;
2785
+ $[22] = type;
2786
+ $[23] = t10;
2787
+ } else t10 = $[23];
2788
+ const commitSource = t10;
2789
+ const [prevSourceMode, setPrevSourceMode] = useState(sourceMode);
2790
+ if (sourceMode !== prevSourceMode) {
2791
+ setPrevSourceMode(sourceMode);
2792
+ if (sourceMode) {
2793
+ const value_1 = engine.getEditableContent(type)?.getContentsAsString() ?? "";
2794
+ setSourceText(value_1);
2795
+ setIsEmpty(value_1.trim() === "");
2796
+ }
2797
+ }
2798
+ const wasSourceModeRef = useRef(sourceMode);
2799
+ let t11;
2800
+ if ($[24] !== engine || $[25] !== getPendingSourceText || $[26] !== sourceMode || $[27] !== type) {
2801
+ t11 = () => {
2802
+ const wasSourceMode = wasSourceModeRef.current;
2803
+ wasSourceModeRef.current = sourceMode;
2804
+ if (!wasSourceMode || sourceMode) return;
2805
+ let cancelled = false;
2806
+ engine.commitSourceEdit(type, getPendingSourceText()).then(() => {
2807
+ if (cancelled) return;
2808
+ const value_2 = engine.getEditableContent(type)?.getContentsAsString() ?? "";
2809
+ setSourceText(value_2);
2810
+ setIsEmpty(value_2.trim() === "");
2811
+ });
2812
+ return () => {
2813
+ cancelled = true;
2814
+ };
2815
+ };
2816
+ $[24] = engine;
2817
+ $[25] = getPendingSourceText;
2818
+ $[26] = sourceMode;
2819
+ $[27] = type;
2820
+ $[28] = t11;
2821
+ } else t11 = $[28];
2822
+ let t12;
2823
+ if ($[29] !== engine || $[30] !== sourceMode || $[31] !== type) {
2824
+ t12 = [
2825
+ engine,
2826
+ type,
2827
+ sourceMode
2828
+ ];
2829
+ $[29] = engine;
2830
+ $[30] = sourceMode;
2831
+ $[31] = type;
2832
+ $[32] = t12;
2833
+ } else t12 = $[32];
2834
+ useEffect(t11, t12);
2835
+ const t13 = `${type}-editable-area`;
2836
+ const t14 = sourceMode ? "source" : "visual";
2837
+ const t15 = !active;
2838
+ const t16 = !sourceMode;
2839
+ const t17 = !sourceMode;
2840
+ let t18;
2841
+ if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
2842
+ t18 = (e_0) => setSourceText(e_0.currentTarget.value);
2843
+ $[33] = t18;
2844
+ } else t18 = $[33];
2845
+ let t19;
2846
+ if ($[34] !== commitSource) {
2847
+ t19 = (e_1) => commitSource(e_1.currentTarget.value);
2848
+ $[34] = commitSource;
2849
+ $[35] = t19;
2850
+ } else t19 = $[35];
2851
+ let t20;
2852
+ if ($[36] !== sourceText || $[37] !== t16 || $[38] !== t17 || $[39] !== t19) {
2853
+ t20 = /* @__PURE__ */ jsx("textarea", {
2854
+ "aria-label": "HTMLソース",
2855
+ spellCheck: false,
2856
+ hidden: t16,
2857
+ disabled: t17,
2858
+ value: sourceText,
2859
+ onChange: t18,
2860
+ onBlur: t19
2861
+ });
2862
+ $[36] = sourceText;
2863
+ $[37] = t16;
2864
+ $[38] = t17;
2865
+ $[39] = t19;
2866
+ $[40] = t20;
2867
+ } else t20 = $[40];
2868
+ const t21 = type === "main" ? "本稿の編集エリア" : "下書きの編集エリア";
2869
+ let t22;
2870
+ if ($[41] === Symbol.for("react.memo_cache_sentinel")) {
2871
+ t22 = {
2872
+ inlineSize: "100%",
2873
+ overflow: "hidden"
2874
+ };
2875
+ $[41] = t22;
2876
+ } else t22 = $[41];
2877
+ let t23;
2878
+ if ($[42] !== height || $[43] !== initFrame || $[44] !== sourceMode || $[45] !== t21) {
2879
+ t23 = /* @__PURE__ */ jsx("iframe", {
2880
+ title: t21,
2881
+ loading: "lazy",
2882
+ style: t22,
2883
+ height,
2884
+ hidden: sourceMode,
2885
+ ref: initFrame
2886
+ });
2887
+ $[42] = height;
2888
+ $[43] = initFrame;
2889
+ $[44] = sourceMode;
2890
+ $[45] = t21;
2891
+ $[46] = t23;
2892
+ } else t23 = $[46];
2893
+ let t24;
2894
+ if ($[47] !== dialogOpen || $[48] !== engine.commandBus || $[49] !== frameBody || $[50] !== isEmpty || $[51] !== processing) {
2895
+ t24 = frameBody ? createPortal(/* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
2896
+ "data-bge-component": "block-menu",
2897
+ children: /* @__PURE__ */ jsx(BlockMenu, { container: frameBody })
2898
+ }), /* @__PURE__ */ jsx("div", {
2899
+ "data-bge-component": "initial-insertion",
2900
+ hidden: !(isEmpty && !processing && !dialogOpen),
2901
+ children: /* @__PURE__ */ jsx(InitialInsertionButton, { commandBusId: engine.commandBus.receiverId })
2902
+ })] }), frameBody) : null;
2903
+ $[47] = dialogOpen;
2904
+ $[48] = engine.commandBus;
2905
+ $[49] = frameBody;
2906
+ $[50] = isEmpty;
2907
+ $[51] = processing;
2908
+ $[52] = t24;
2909
+ } else t24 = $[52];
2910
+ let t25;
2911
+ if ($[53] !== t13 || $[54] !== t14 || $[55] !== t15 || $[56] !== t20 || $[57] !== t23 || $[58] !== t24) {
2912
+ t25 = /* @__PURE__ */ jsxs("div", {
2913
+ "data-bge-component": t13,
2914
+ "data-bge-component-mode": t14,
2915
+ hidden: t15,
2916
+ children: [
2917
+ t20,
2918
+ t23,
2919
+ t24
2920
+ ]
2921
+ });
2922
+ $[53] = t13;
2923
+ $[54] = t14;
2924
+ $[55] = t15;
2925
+ $[56] = t20;
2926
+ $[57] = t23;
2927
+ $[58] = t24;
2928
+ $[59] = t25;
2929
+ } else t25 = $[59];
2930
+ return t25;
2931
+ }
2932
+ function _temp2(s_1) {
2933
+ return s_1.openDialog !== null;
2934
+ }
2935
+ function _temp(s_0) {
2936
+ return s_0.processing;
2937
+ }
2938
+ //#endregion
2939
+ export { IconTrash as _, BlockMenuButton as a, reportRenderError as c, registerEngineCommands as d, useUIState as f, BlockCatalog as g, BlockOptions as h, BlockMenuView as i, reactMount as l, EditorDialog as m, InitialInsertionButton as n, useCommand as o, ItemEditorHost as p, BlockMenu as r, RootErrorBoundary as s, EditableAreaView as t, DraftSwitcher as u, IconRowInsertBottom as v, createReactComponent as y };
2940
+
2941
+ //# sourceMappingURL=editable-area-view-DssYcTqQ.js.map