@burger-editor/client 4.0.0-alpha.8 → 4.0.0-alpha.80

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 (137) hide show
  1. package/README.md +169 -2
  2. package/dist/__tests__/setup.d.ts +2 -0
  3. package/dist/__tests__/setup.d.ts.map +1 -0
  4. package/dist/animate-insertion.d.ts +17 -0
  5. package/dist/animate-insertion.d.ts.map +1 -0
  6. package/dist/block-swap-view-transition-css.d.ts +7 -0
  7. package/dist/block-swap-view-transition-css.d.ts.map +1 -0
  8. package/dist/burger-editor-root.d.ts +7 -0
  9. package/dist/burger-editor-root.d.ts.map +1 -0
  10. package/dist/client.css +981 -573
  11. package/dist/client.js +28193 -14074
  12. package/dist/client.js.map +1 -1
  13. package/dist/commands/register-engine-commands.d.ts +18 -0
  14. package/dist/commands/register-engine-commands.d.ts.map +1 -0
  15. package/dist/components/block-catalog.d.ts +18 -0
  16. package/dist/components/block-catalog.d.ts.map +1 -0
  17. package/dist/components/block-menu-anchors.d.ts +25 -0
  18. package/dist/components/block-menu-anchors.d.ts.map +1 -0
  19. package/dist/components/block-menu-button.d.ts +33 -0
  20. package/dist/components/block-menu-button.d.ts.map +1 -0
  21. package/dist/components/block-menu-view.d.ts +88 -0
  22. package/dist/components/block-menu-view.d.ts.map +1 -0
  23. package/dist/components/block-menu.d.ts +25 -0
  24. package/dist/components/block-menu.d.ts.map +1 -0
  25. package/dist/components/block-options.d.ts +23 -0
  26. package/dist/components/block-options.d.ts.map +1 -0
  27. package/dist/components/draft-switcher.d.ts +24 -0
  28. package/dist/components/draft-switcher.d.ts.map +1 -0
  29. package/dist/components/editable-area-view.d.ts +41 -0
  30. package/dist/components/editable-area-view.d.ts.map +1 -0
  31. package/dist/components/file-list.d.ts +19 -0
  32. package/dist/components/file-list.d.ts.map +1 -0
  33. package/dist/components/file-uploader.d.ts +18 -0
  34. package/dist/components/file-uploader.d.ts.map +1 -0
  35. package/dist/components/front-matter-editor.d.ts +115 -0
  36. package/dist/components/front-matter-editor.d.ts.map +1 -0
  37. package/dist/components/index.d.ts +23 -0
  38. package/dist/components/index.d.ts.map +1 -0
  39. package/dist/components/initial-insertion-button.d.ts +15 -0
  40. package/dist/components/initial-insertion-button.d.ts.map +1 -0
  41. package/dist/components/item-editor-host.d.ts +24 -0
  42. package/dist/components/item-editor-host.d.ts.map +1 -0
  43. package/dist/components/preview.d.ts +15 -0
  44. package/dist/components/preview.d.ts.map +1 -0
  45. package/dist/components/table-editor.d.ts +28 -0
  46. package/dist/components/table-editor.d.ts.map +1 -0
  47. package/dist/components/tabs.d.ts +27 -0
  48. package/dist/components/tabs.d.ts.map +1 -0
  49. package/dist/components/thumbnail-button.d.ts +39 -0
  50. package/dist/components/thumbnail-button.d.ts.map +1 -0
  51. package/dist/components/thumbnail.d.ts +17 -0
  52. package/dist/components/thumbnail.d.ts.map +1 -0
  53. package/dist/components/wysiwyg-field.d.ts +50 -0
  54. package/dist/components/wysiwyg-field.d.ts.map +1 -0
  55. package/dist/create-mock-engine-BloCpuEu.js +87 -0
  56. package/dist/create-mock-engine-BloCpuEu.js.map +1 -0
  57. package/dist/dist-DYydjVsL.js +16188 -0
  58. package/dist/dist-DYydjVsL.js.map +1 -0
  59. package/dist/editable-area-view-DhEipEQV.js +2962 -0
  60. package/dist/editable-area-view-DhEipEQV.js.map +1 -0
  61. package/dist/editor-dialog.d.ts +50 -0
  62. package/dist/editor-dialog.d.ts.map +1 -0
  63. package/dist/engine-context-oEEsvNSx.js +49 -0
  64. package/dist/engine-context-oEEsvNSx.js.map +1 -0
  65. package/dist/engine-context.d.ts +43 -0
  66. package/dist/engine-context.d.ts.map +1 -0
  67. package/dist/file-browser/store.d.ts +132 -0
  68. package/dist/file-browser/store.d.ts.map +1 -0
  69. package/dist/file-browser/use-external-file-selection.d.ts +39 -0
  70. package/dist/file-browser/use-external-file-selection.d.ts.map +1 -0
  71. package/dist/file-browser/use-file-browser.d.ts +17 -0
  72. package/dist/file-browser/use-file-browser.d.ts.map +1 -0
  73. package/dist/form/checkbox.d.ts +34 -0
  74. package/dist/form/checkbox.d.ts.map +1 -0
  75. package/dist/form/fieldset.d.ts +31 -0
  76. package/dist/form/fieldset.d.ts.map +1 -0
  77. package/dist/form/index.d.ts +8 -0
  78. package/dist/form/index.d.ts.map +1 -0
  79. package/dist/form/number-field.d.ts +37 -0
  80. package/dist/form/number-field.d.ts.map +1 -0
  81. package/dist/form/radio-group.d.ts +38 -0
  82. package/dist/form/radio-group.d.ts.map +1 -0
  83. package/dist/form/select-field.d.ts +41 -0
  84. package/dist/form/select-field.d.ts.map +1 -0
  85. package/dist/form/text-area.d.ts +33 -0
  86. package/dist/form/text-area.d.ts.map +1 -0
  87. package/dist/form/text-field.d.ts +47 -0
  88. package/dist/form/text-field.d.ts.map +1 -0
  89. package/dist/index.d.ts +42 -6
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/interest-hints.d.ts +21 -0
  92. package/dist/interest-hints.d.ts.map +1 -0
  93. package/dist/invoker-commands.d.ts +24 -0
  94. package/dist/invoker-commands.d.ts.map +1 -0
  95. package/dist/mount.d.ts +24 -0
  96. package/dist/mount.d.ts.map +1 -0
  97. package/dist/replace-element.d.ts +12 -4
  98. package/dist/replace-element.d.ts.map +1 -1
  99. package/dist/root-error-boundary.d.ts +34 -0
  100. package/dist/root-error-boundary.d.ts.map +1 -0
  101. package/dist/testing/create-mock-engine.d.ts +33 -0
  102. package/dist/testing/create-mock-engine.d.ts.map +1 -0
  103. package/dist/testing/index.d.ts +4 -0
  104. package/dist/testing/index.d.ts.map +1 -0
  105. package/dist/testing/render-with-engine.d.ts +20 -0
  106. package/dist/testing/render-with-engine.d.ts.map +1 -0
  107. package/dist/testing/suppress-console-error.d.ts +24 -0
  108. package/dist/testing/suppress-console-error.d.ts.map +1 -0
  109. package/dist/testing-mock-engine.js +1 -0
  110. package/dist/testing.js +68 -0
  111. package/dist/testing.js.map +1 -0
  112. package/dist/ui.d.ts +17 -0
  113. package/dist/ui.d.ts.map +1 -0
  114. package/dist/ui.js +2830 -0
  115. package/dist/ui.js.map +1 -0
  116. package/dist/use-command.d.ts +38 -0
  117. package/dist/use-command.d.ts.map +1 -0
  118. package/dist/use-engine.d.ts +37 -0
  119. package/dist/use-engine.d.ts.map +1 -0
  120. package/dist/use-mount-effect.d.ts +20 -0
  121. package/dist/use-mount-effect.d.ts.map +1 -0
  122. package/dist/view/create-react-view.d.ts +41 -0
  123. package/dist/view/create-react-view.d.ts.map +1 -0
  124. package/package.json +61 -16
  125. package/dist/block-catalog.svelte.d.ts +0 -1
  126. package/dist/block-menu-button.svelte.d.ts +0 -1
  127. package/dist/block-menu.svelte.d.ts +0 -1
  128. package/dist/block-options.svelte.d.ts +0 -1
  129. package/dist/draft-switcher.svelte.d.ts +0 -1
  130. package/dist/file-list.svelte.d.ts +0 -1
  131. package/dist/file-uploader.svelte.d.ts +0 -1
  132. package/dist/preview.svelte.d.ts +0 -1
  133. package/dist/svelte-mount.d.ts +0 -10
  134. package/dist/svelte-mount.d.ts.map +0 -1
  135. package/dist/table-editor.svelte.d.ts +0 -1
  136. package/dist/tabs.svelte.d.ts +0 -1
  137. package/dist/thumbnail.svelte.d.ts +0 -1
package/dist/ui.js ADDED
@@ -0,0 +1,2830 @@
1
+ import { _ as BlockCatalog, a as BlockMenuButton, b as createReactComponent, c as RootErrorBoundary, d as DraftSwitcher, f as registerEngineCommands, g as BlockOptions, h as EditorDialog, i as BlockMenuView, l as reportRenderError, m as ItemEditorHost, n as InitialInsertionButton, o as BGE_BLOCK_MENU_BLOCK_ANCHOR, p as useUIState, r as BlockMenu, s as useCommand, t as EditableAreaView, u as reactMount, v as IconTrash, y as IconRowInsertBottom } from "./editable-area-view-DhEipEQV.js";
2
+ import { n as useEngine, t as EngineProvider } from "./engine-context-oEEsvNSx.js";
3
+ import { c as formatByteSize, l as formatDate } from "./dist-DYydjVsL.js";
4
+ import { c } from "react/compiler-runtime";
5
+ import { Fragment, use, useDeferredValue, useEffect, useEffectEvent, useId, useRef, useState, useSyncExternalStore, useTransition } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { createRoot } from "react-dom/client";
8
+ /**
9
+ * @license @tabler/icons-react v3.52.0 - MIT
10
+ *
11
+ * This source code is licensed under the MIT license.
12
+ * See the LICENSE file in the root directory of this source tree.
13
+ */
14
+ var IconArrowsTransferDown = /* @__PURE__ */ createReactComponent("outline", "arrows-transfer-down", "ArrowsTransferDown", [
15
+ ["path", {
16
+ "d": "M17 3v6",
17
+ "key": "svg-0"
18
+ }],
19
+ ["path", {
20
+ "d": "M10 18l-3 3l-3 -3",
21
+ "key": "svg-1"
22
+ }],
23
+ ["path", {
24
+ "d": "M7 21v-18",
25
+ "key": "svg-2"
26
+ }],
27
+ ["path", {
28
+ "d": "M20 6l-3 -3l-3 3",
29
+ "key": "svg-3"
30
+ }],
31
+ ["path", {
32
+ "d": "M17 21v-2",
33
+ "key": "svg-4"
34
+ }],
35
+ ["path", {
36
+ "d": "M17 15v-2",
37
+ "key": "svg-5"
38
+ }]
39
+ ]);
40
+ /**
41
+ * @license @tabler/icons-react v3.52.0 - MIT
42
+ *
43
+ * This source code is licensed under the MIT license.
44
+ * See the LICENSE file in the root directory of this source tree.
45
+ */
46
+ var IconFileTypeDoc = /* @__PURE__ */ createReactComponent("outline", "file-type-doc", "FileTypeDoc", [
47
+ ["path", {
48
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
49
+ "key": "svg-0"
50
+ }],
51
+ ["path", {
52
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
53
+ "key": "svg-1"
54
+ }],
55
+ ["path", {
56
+ "d": "M5 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1",
57
+ "key": "svg-2"
58
+ }],
59
+ ["path", {
60
+ "d": "M20 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0",
61
+ "key": "svg-3"
62
+ }],
63
+ ["path", {
64
+ "d": "M12.5 15a1.5 1.5 0 0 1 1.5 1.5v3a1.5 1.5 0 0 1 -3 0v-3a1.5 1.5 0 0 1 1.5 -1.5",
65
+ "key": "svg-4"
66
+ }]
67
+ ]);
68
+ /**
69
+ * @license @tabler/icons-react v3.52.0 - MIT
70
+ *
71
+ * This source code is licensed under the MIT license.
72
+ * See the LICENSE file in the root directory of this source tree.
73
+ */
74
+ var IconFileTypePdf = /* @__PURE__ */ createReactComponent("outline", "file-type-pdf", "FileTypePdf", [
75
+ ["path", {
76
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
77
+ "key": "svg-0"
78
+ }],
79
+ ["path", {
80
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
81
+ "key": "svg-1"
82
+ }],
83
+ ["path", {
84
+ "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
85
+ "key": "svg-2"
86
+ }],
87
+ ["path", {
88
+ "d": "M17 18h2",
89
+ "key": "svg-3"
90
+ }],
91
+ ["path", {
92
+ "d": "M20 15h-3v6",
93
+ "key": "svg-4"
94
+ }],
95
+ ["path", {
96
+ "d": "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1",
97
+ "key": "svg-5"
98
+ }]
99
+ ]);
100
+ /**
101
+ * @license @tabler/icons-react v3.52.0 - MIT
102
+ *
103
+ * This source code is licensed under the MIT license.
104
+ * See the LICENSE file in the root directory of this source tree.
105
+ */
106
+ var IconFileTypePpt = /* @__PURE__ */ createReactComponent("outline", "file-type-ppt", "FileTypePpt", [
107
+ ["path", {
108
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
109
+ "key": "svg-0"
110
+ }],
111
+ ["path", {
112
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
113
+ "key": "svg-1"
114
+ }],
115
+ ["path", {
116
+ "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
117
+ "key": "svg-2"
118
+ }],
119
+ ["path", {
120
+ "d": "M11 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
121
+ "key": "svg-3"
122
+ }],
123
+ ["path", {
124
+ "d": "M16.5 15h3",
125
+ "key": "svg-4"
126
+ }],
127
+ ["path", {
128
+ "d": "M18 15v6",
129
+ "key": "svg-5"
130
+ }],
131
+ ["path", {
132
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
133
+ "key": "svg-6"
134
+ }]
135
+ ]);
136
+ /**
137
+ * @license @tabler/icons-react v3.52.0 - MIT
138
+ *
139
+ * This source code is licensed under the MIT license.
140
+ * See the LICENSE file in the root directory of this source tree.
141
+ */
142
+ var IconFileTypeXls = /* @__PURE__ */ createReactComponent("outline", "file-type-xls", "FileTypeXls", [
143
+ ["path", {
144
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
145
+ "key": "svg-0"
146
+ }],
147
+ ["path", {
148
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
149
+ "key": "svg-1"
150
+ }],
151
+ ["path", {
152
+ "d": "M4 15l4 6",
153
+ "key": "svg-2"
154
+ }],
155
+ ["path", {
156
+ "d": "M4 21l4 -6",
157
+ "key": "svg-3"
158
+ }],
159
+ ["path", {
160
+ "d": "M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75",
161
+ "key": "svg-4"
162
+ }],
163
+ ["path", {
164
+ "d": "M11 15v6h3",
165
+ "key": "svg-5"
166
+ }]
167
+ ]);
168
+ /**
169
+ * @license @tabler/icons-react v3.52.0 - MIT
170
+ *
171
+ * This source code is licensed under the MIT license.
172
+ * See the LICENSE file in the root directory of this source tree.
173
+ */
174
+ var IconFile = /* @__PURE__ */ createReactComponent("outline", "file", "File", [["path", {
175
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
176
+ "key": "svg-0"
177
+ }], ["path", {
178
+ "d": "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2",
179
+ "key": "svg-1"
180
+ }]]);
181
+ /**
182
+ * @license @tabler/icons-react v3.52.0 - MIT
183
+ *
184
+ * This source code is licensed under the MIT license.
185
+ * See the LICENSE file in the root directory of this source tree.
186
+ */
187
+ var IconHeadphones = /* @__PURE__ */ createReactComponent("outline", "headphones", "Headphones", [
188
+ ["path", {
189
+ "d": "M4 15a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-1a2 2 0 0 1 -2 -2l0 -3",
190
+ "key": "svg-0"
191
+ }],
192
+ ["path", {
193
+ "d": "M15 15a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-1a2 2 0 0 1 -2 -2l0 -3",
194
+ "key": "svg-1"
195
+ }],
196
+ ["path", {
197
+ "d": "M4 15v-3a8 8 0 0 1 16 0v3",
198
+ "key": "svg-2"
199
+ }]
200
+ ]);
201
+ /**
202
+ * @license @tabler/icons-react v3.52.0 - MIT
203
+ *
204
+ * This source code is licensed under the MIT license.
205
+ * See the LICENSE file in the root directory of this source tree.
206
+ */
207
+ var IconPhoto = /* @__PURE__ */ createReactComponent("outline", "photo", "Photo", [
208
+ ["path", {
209
+ "d": "M15 8h.01",
210
+ "key": "svg-0"
211
+ }],
212
+ ["path", {
213
+ "d": "M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12",
214
+ "key": "svg-1"
215
+ }],
216
+ ["path", {
217
+ "d": "M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5",
218
+ "key": "svg-2"
219
+ }],
220
+ ["path", {
221
+ "d": "M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3",
222
+ "key": "svg-3"
223
+ }]
224
+ ]);
225
+ /**
226
+ * @license @tabler/icons-react v3.52.0 - MIT
227
+ *
228
+ * This source code is licensed under the MIT license.
229
+ * See the LICENSE file in the root directory of this source tree.
230
+ */
231
+ var IconVideo = /* @__PURE__ */ createReactComponent("outline", "video", "Video", [["path", {
232
+ "d": "M15 10l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -1.447 .894l-4.553 -2.276v-4",
233
+ "key": "svg-0"
234
+ }], ["path", {
235
+ "d": "M3 8a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2l0 -8",
236
+ "key": "svg-1"
237
+ }]]);
238
+ // src/file-browser/store.ts
239
+ /**
240
+ * A file currently selected for a given `FileType` inside a dialog — the
241
+ * path the item editor should apply, plus the byte size the old
242
+ * `file-select` component-observer payload used to carry.
243
+ */
244
+ /**
245
+ * One upload in flight. Kept in the store (not local component state) so
246
+ * `FileList` and `Preview` — siblings under the same item editor — both
247
+ * see the same synthetic "uploading…" row / progress bar without a
248
+ * broadcast bus.
249
+ */
250
+ var EMPTY_RESULT = {
251
+ error: false,
252
+ data: [],
253
+ pagination: {
254
+ current: 0,
255
+ total: 1
256
+ }
257
+ };
258
+ /**
259
+ * Cache key for a file-list query — used both to look up a cached
260
+ * promise and (via its `fileType` prefix) to find every cached page for
261
+ * a given file type on invalidation.
262
+ *
263
+ * `selectedPath` (present only on the very first read for a `fileType`,
264
+ * see {@link FileBrowserStore.read}) is folded into the key so that an
265
+ * initial read's response — which the server may have jumped to a
266
+ * different page than the one requested, to land on the selected file —
267
+ * never collides with a later, unrelated `{fileType, page, filter}`
268
+ * request for the *same nominal page* opened by a different item in the
269
+ * same engine session. Without this, a second item reusing page 0 would
270
+ * transparently receive the first item's page-jumped response instead of
271
+ * a real page 0.
272
+ * @param query - The query to key
273
+ * @param selectedPath - The `selected` path actually sent with this
274
+ * query, if any
275
+ */
276
+ function queryKey(query, selectedPath) {
277
+ return `${query.fileType}:${query.page}:${query.filter}:${selectedPath ?? ""}`;
278
+ }
279
+ /**
280
+ * Per-engine file-browser state: paginated/filtered `getFileList` query
281
+ * results (cached by query, read through `use()`), the file currently
282
+ * selected per `FileType`, and in-flight upload progress.
283
+ *
284
+ * React-independent so it can be constructed once per engine and shared
285
+ * by every component that opens onto the same file browser (`FileList`,
286
+ * `FileUploader`, `Preview`, and the item's own `Editor`) without a
287
+ * window-level broadcast bus — see {@link getFileBrowserStore}.
288
+ * @example
289
+ * ```tsx
290
+ * const store = getFileBrowserStore(engine);
291
+ * const result = use(store.read({ fileType: 'image', page: 0, filter: '' }));
292
+ * const selected = useSyncExternalStore(store.subscribe, store.getSnapshot);
293
+ * ```
294
+ */
295
+ var FileBrowserStore = class {
296
+ getSnapshot = () => this.#state;
297
+ subscribe = (listener) => {
298
+ this.#listeners.add(listener);
299
+ return () => {
300
+ this.#listeners.delete(listener);
301
+ };
302
+ };
303
+ #engine;
304
+ #initialReadDone = /* @__PURE__ */ new Set();
305
+ #listeners = /* @__PURE__ */ new Set();
306
+ #queries = /* @__PURE__ */ new Map();
307
+ #state = {
308
+ selected: {},
309
+ uploads: []
310
+ };
311
+ /** Whether the engine's `serverAPI` supports deleting files. */
312
+ get canDelete() {
313
+ return !!this.#engine.serverAPI.deleteFile;
314
+ }
315
+ constructor(engine) {
316
+ this.#engine = engine;
317
+ }
318
+ /**
319
+ * Delete a file from the server and invalidate `fileType`'s cached
320
+ * pages so the list reflects the deletion on next read.
321
+ * @param fileType - The file type the file belongs to
322
+ * @param url - The file's URL
323
+ * @throws {Error} When the server reports the deletion failed
324
+ */
325
+ async deleteFile(fileType, url) {
326
+ const deleteFile = this.#engine.serverAPI.deleteFile;
327
+ if (!deleteFile) return;
328
+ if ((await deleteFile(fileType, url)).error) throw new Error(`Failed to delete file: ${url}`);
329
+ this.invalidate(fileType);
330
+ }
331
+ /**
332
+ * Drop every cached page for `fileType` and notify subscribers, so the
333
+ * next `read()` for that type issues a fresh request (after an upload
334
+ * or a delete changes the underlying list).
335
+ * @param fileType - The file type whose cached pages should be dropped
336
+ */
337
+ invalidate(fileType) {
338
+ const prefix = `${fileType}:`;
339
+ for (const key of this.#queries.keys()) if (key.startsWith(prefix)) this.#queries.delete(key);
340
+ this.#emit();
341
+ }
342
+ /**
343
+ * Read (and cache) one page of the file list. The returned promise is
344
+ * stable per `{fileType, page, filter}` plus whether this particular
345
+ * read sent `selected` (see below) — safe to pass to `use()` directly
346
+ * from render, repeated calls with the same query return the same
347
+ * promise instead of re-suspending.
348
+ *
349
+ * The very first read for a given `fileType` also sends the currently
350
+ * selected file's path as `selected`, so the server can jump straight
351
+ * to the page that already contains it (e.g. re-opening an image item
352
+ * whose file isn't on page 0) instead of always starting at `page`.
353
+ * Later reads for that `fileType` (explicit pagination, search, or a
354
+ * post-upload/-delete refetch via {@link invalidate}) omit it — always
355
+ * including it would silently override the page the caller asked for.
356
+ *
357
+ * Because that jump means the response's actual page can differ from
358
+ * the requested one, `selected` is folded into the cache key (see
359
+ * {@link queryKey}): a later item opening the same `fileType` and
360
+ * nominal page never transparently receives the first item's
361
+ * page-jumped response — it misses the cache and gets a real page.
362
+ * @param query - The file type, page and filter to query
363
+ * @returns The (possibly still-pending, cached) file list page
364
+ */
365
+ read(query) {
366
+ const selectedPath = !this.#initialReadDone.has(query.fileType) ? this.#state.selected[query.fileType]?.path : void 0;
367
+ const key = queryKey(query, selectedPath);
368
+ const cached = this.#queries.get(key);
369
+ if (cached) return cached;
370
+ this.#initialReadDone.add(query.fileType);
371
+ const getFileList = this.#engine.serverAPI.getFileList;
372
+ const options = {
373
+ page: query.page,
374
+ filter: query.filter,
375
+ selected: selectedPath
376
+ };
377
+ const promise = getFileList ? getFileList(query.fileType, options) : Promise.resolve(EMPTY_RESULT);
378
+ promise.catch(() => {
379
+ this.#queries.delete(key);
380
+ });
381
+ this.#queries.set(key, promise);
382
+ return promise;
383
+ }
384
+ /**
385
+ * Record the file currently selected for `fileType` — a no-op when the
386
+ * path is unchanged, so callers can call this unconditionally (e.g.
387
+ * every render) without causing redundant notifications.
388
+ * @param fileType - The file type being selected for
389
+ * @param path - The selected file's path, or `''` for "nothing selected"
390
+ * @param fileSize - The selected file's byte size, when known
391
+ */
392
+ select(fileType, path, fileSize = 0) {
393
+ if (this.#state.selected[fileType]?.path === path) return;
394
+ this.#patch({ selected: {
395
+ ...this.#state.selected,
396
+ [fileType]: {
397
+ path,
398
+ fileSize
399
+ }
400
+ } });
401
+ }
402
+ /**
403
+ * Upload a file, tracking progress in `uploads` (so `FileList` and
404
+ * `Preview` can both show it) and selecting the resulting URL once the
405
+ * server responds — a blob URL is selected immediately so the UI has
406
+ * something to show while the upload is in flight.
407
+ *
408
+ * The blob URL is revoked once the upload settles. On failure the
409
+ * selection is restored to what it was before the upload (empty path if
410
+ * nothing was selected), so a revoked blob URL is never left selected
411
+ * for the dialog to confirm.
412
+ * @param fileType - The file type to upload into
413
+ * @param file - The file to upload
414
+ * @throws {Error} When no `postFile` API is configured, or the server
415
+ * reports the upload failed
416
+ */
417
+ async upload(fileType, file) {
418
+ const postFile = this.#engine.serverAPI.postFile;
419
+ const blob = URL.createObjectURL(file);
420
+ const previous = this.#state.selected[fileType];
421
+ this.select(fileType, blob, file.size);
422
+ this.#patch({ uploads: [...this.#state.uploads, {
423
+ fileType,
424
+ blob,
425
+ uploaded: 0,
426
+ total: file.size || 1
427
+ }] });
428
+ try {
429
+ if (!postFile) throw new Error("postFile is not configured");
430
+ const res = await postFile(fileType, file, (uploaded, total) => {
431
+ this.#patch({ uploads: this.#state.uploads.map((u) => u.blob === blob ? {
432
+ ...u,
433
+ uploaded,
434
+ total
435
+ } : u) });
436
+ });
437
+ if (res.error) throw new Error(`Failed to upload file: ${file.name}`);
438
+ this.invalidate(fileType);
439
+ this.select(fileType, res.uploaded.url, res.uploaded.size);
440
+ } catch (error) {
441
+ this.select(fileType, previous?.path ?? "", previous?.fileSize);
442
+ throw error;
443
+ } finally {
444
+ this.#patch({ uploads: this.#state.uploads.filter((u) => u.blob !== blob) });
445
+ URL.revokeObjectURL(blob);
446
+ }
447
+ }
448
+ #emit() {
449
+ for (const listener of this.#listeners) listener();
450
+ }
451
+ #patch(patch) {
452
+ this.#state = {
453
+ ...this.#state,
454
+ ...patch
455
+ };
456
+ this.#emit();
457
+ }
458
+ };
459
+ var stores = /* @__PURE__ */ new WeakMap();
460
+ /**
461
+ * Get (creating on first access) the `FileBrowserStore` for `engine`. One
462
+ * store per engine, shared by every component under it — see
463
+ * {@link FileBrowserStore}.
464
+ * @param engine - The engine to get the store for
465
+ * @returns That engine's file-browser store
466
+ */
467
+ function getFileBrowserStore(engine) {
468
+ let store = stores.get(engine);
469
+ if (!store) {
470
+ store = new FileBrowserStore(engine);
471
+ stores.set(engine, store);
472
+ }
473
+ return store;
474
+ }
475
+ // src/file-browser/use-file-browser.ts
476
+ /**
477
+ * Get the current engine's `FileBrowserStore` — file-list query cache,
478
+ * current selection and upload progress shared by `FileList`,
479
+ * `FileUploader`, `Preview` and the item's own `Editor`.
480
+ * @returns The engine's file-browser store
481
+ * @example
482
+ * ```tsx
483
+ * const fileBrowser = useFileBrowser();
484
+ * const selected = useSyncExternalStore(
485
+ * fileBrowser.subscribe,
486
+ * () => fileBrowser.getSnapshot().selected.image,
487
+ * );
488
+ * ```
489
+ */
490
+ function useFileBrowser() {
491
+ const $ = c(2);
492
+ const engine = useEngine();
493
+ let t0;
494
+ if ($[0] !== engine) {
495
+ t0 = getFileBrowserStore(engine);
496
+ $[0] = engine;
497
+ $[1] = t0;
498
+ } else t0 = $[1];
499
+ return t0;
500
+ }
501
+ var file_list_module_default = {
502
+ ctrl: "_ctrl_1vnsv_1",
503
+ pagination: "_pagination_1vnsv_7",
504
+ page: "_page_1vnsv_19",
505
+ list: "_list_1vnsv_25",
506
+ "delete": "_delete_1vnsv_39",
507
+ file: "_file_1vnsv_44",
508
+ thumbnail: "_thumbnail_1vnsv_58",
509
+ attr: "_attr_1vnsv_65"
510
+ };
511
+ // src/get-ext.ts
512
+ /**
513
+ *
514
+ * @param src
515
+ */
516
+ function getExt(src) {
517
+ const ext = src.split(".").pop()?.toLowerCase() ?? "";
518
+ return {
519
+ ext,
520
+ isImage: [
521
+ "jpg",
522
+ "jpeg",
523
+ "png",
524
+ "gif",
525
+ "webp",
526
+ "svg"
527
+ ].includes(ext),
528
+ isVideo: [
529
+ "mp4",
530
+ "webm",
531
+ "mov",
532
+ "avi"
533
+ ].includes(ext),
534
+ isAudio: [
535
+ "mp3",
536
+ "wav",
537
+ "m4a",
538
+ "ogg",
539
+ "flac"
540
+ ].includes(ext),
541
+ isDoc: ["doc", "docx"].includes(ext),
542
+ isPpt: ["ppt", "pptx"].includes(ext),
543
+ isXls: ["xls", "xlsx"].includes(ext),
544
+ isPdf: ["pdf"].includes(ext)
545
+ };
546
+ }
547
+ var thumbnail_module_default = { thumbnail: "_thumbnail_bi2ve_1" };
548
+ // src/components/thumbnail.tsx
549
+ /**
550
+ * File thumbnail. Renders an image/video preview or a file-type icon.
551
+ *
552
+ * The file type is inferred from the URL's extension (`getExt`) — the
553
+ * URL is the only information available here, so the extension decides
554
+ * whether the file can be previewed inline or needs a type icon.
555
+ * @param root0
556
+ * @param root0.src
557
+ * @example
558
+ * ```tsx
559
+ * <Thumbnail src={file.url} />
560
+ * ```
561
+ */
562
+ function Thumbnail(t0) {
563
+ const $ = c(15);
564
+ const { src } = t0;
565
+ const [isLoaded, setIsLoaded] = useState(false);
566
+ let t1;
567
+ if ($[0] !== src) {
568
+ t1 = getExt(src);
569
+ $[0] = src;
570
+ $[1] = t1;
571
+ } else t1 = $[1];
572
+ const file = t1;
573
+ let t2;
574
+ if ($[2] !== file.ext || $[3] !== file.isAudio || $[4] !== file.isDoc || $[5] !== file.isImage || $[6] !== file.isPdf || $[7] !== file.isPpt || $[8] !== file.isVideo || $[9] !== file.isXls || $[10] !== src) {
575
+ t2 = file.isImage ? /* @__PURE__ */ jsx("img", {
576
+ src,
577
+ alt: "画像のプレビュー",
578
+ loading: "lazy",
579
+ onLoad: () => setIsLoaded(true)
580
+ }) : file.isVideo ? /* @__PURE__ */ jsxs("video", {
581
+ controls: false,
582
+ playsInline: true,
583
+ children: [
584
+ /* @__PURE__ */ jsx("source", {
585
+ src,
586
+ type: `video/${file.ext}`
587
+ }),
588
+ /* @__PURE__ */ jsx("track", {
589
+ kind: "captions",
590
+ src: ""
591
+ }),
592
+ /* @__PURE__ */ jsx(IconVideo, {})
593
+ ]
594
+ }) : file.isAudio ? /* @__PURE__ */ jsx(IconHeadphones, {}) : file.isDoc ? /* @__PURE__ */ jsx(IconFileTypeDoc, {}) : file.isPpt ? /* @__PURE__ */ jsx(IconFileTypePpt, {}) : file.isXls ? /* @__PURE__ */ jsx(IconFileTypeXls, {}) : file.isPdf ? /* @__PURE__ */ jsx(IconFileTypePdf, {}) : /* @__PURE__ */ jsx(IconFile, {});
595
+ $[2] = file.ext;
596
+ $[3] = file.isAudio;
597
+ $[4] = file.isDoc;
598
+ $[5] = file.isImage;
599
+ $[6] = file.isPdf;
600
+ $[7] = file.isPpt;
601
+ $[8] = file.isVideo;
602
+ $[9] = file.isXls;
603
+ $[10] = src;
604
+ $[11] = t2;
605
+ } else t2 = $[11];
606
+ let t3;
607
+ if ($[12] !== isLoaded || $[13] !== t2) {
608
+ t3 = /* @__PURE__ */ jsx("span", {
609
+ className: thumbnail_module_default.thumbnail,
610
+ "data-bge-editor-ui-component": "thumbnail",
611
+ "data-loaded": isLoaded,
612
+ children: t2
613
+ });
614
+ $[12] = isLoaded;
615
+ $[13] = t2;
616
+ $[14] = t3;
617
+ } else t3 = $[14];
618
+ return t3;
619
+ }
620
+ // src/components/file-list.tsx
621
+ /**
622
+ * Paginated, searchable file list. Reads its page through `use()` against
623
+ * the engine's `FileBrowserStore` (suspends into the dialog's Suspense
624
+ * boundary while loading); selection and in-flight uploads come from the
625
+ * same store, shared with `FileUploader` and the item's own `Editor`
626
+ * instead of a broadcast bus.
627
+ * @param root0
628
+ * @param root0.fileType
629
+ * @example
630
+ * ```tsx
631
+ * <FileUploader fileType="image" />
632
+ * <FileList fileType="image" />
633
+ * ```
634
+ */
635
+ function FileList({ fileType }) {
636
+ "use no memo";
637
+ const store = useFileBrowser();
638
+ const rootId = useId();
639
+ const [page, setPage] = useState(0);
640
+ const [searchWord, setSearchWord] = useState("");
641
+ const deferredFilter = useDeferredValue(searchWord);
642
+ const [isPending, startTransition] = useTransition();
643
+ const selected = useSyncExternalStore(store.subscribe, () => store.getSnapshot().selected[fileType]);
644
+ const myUploads = useSyncExternalStore(store.subscribe, () => store.getSnapshot().uploads).filter((u) => u.fileType === fileType);
645
+ const result = use(store.read({
646
+ fileType,
647
+ page,
648
+ filter: deferredFilter
649
+ }));
650
+ const totalPage = result.pagination.total;
651
+ const currentPage = result.pagination.current;
652
+ const files = [...myUploads.map((u_0) => ({
653
+ fileId: "",
654
+ name: "",
655
+ size: 0,
656
+ timestamp: 0,
657
+ url: u_0.blob,
658
+ sizes: {}
659
+ })), ...result.data.filter((f) => !myUploads.some((u_1) => u_1.blob === f.url))];
660
+ const paginate = (nextPage) => {
661
+ nextPage = Number.isNaN(nextPage) ? 0 : Math.min(Math.max(0, nextPage), totalPage - 1);
662
+ if (nextPage === currentPage) return;
663
+ startTransition(() => {
664
+ setPage(nextPage);
665
+ });
666
+ };
667
+ const rootRef = useCommand({
668
+ "--paginate": (e) => {
669
+ const direction = e.source?.value;
670
+ paginate(direction === "prev" ? currentPage - 1 : currentPage + 1);
671
+ },
672
+ "--select-file": (e_0) => {
673
+ const source = e_0.source;
674
+ if (!source) return;
675
+ store.select(fileType, source.value, Number(source.dataset["size"] ?? "0"));
676
+ },
677
+ "--delete-file": (e_1) => {
678
+ const url = e_1.source?.value;
679
+ if (!url) return;
680
+ startTransition(async () => {
681
+ try {
682
+ await store.deleteFile(fileType, url);
683
+ } catch {
684
+ alert("ファイルの削除に失敗しました。");
685
+ }
686
+ });
687
+ }
688
+ });
689
+ const marked = (text) => {
690
+ if (!searchWord) return text;
691
+ return text.split(searchWord).map((char, i) => /* @__PURE__ */ jsxs(Fragment, { children: [i === 0 ? null : /* @__PURE__ */ jsx("mark", { children: searchWord }), char] }, char + i));
692
+ };
693
+ return /* @__PURE__ */ jsxs("div", {
694
+ ref: rootRef,
695
+ id: rootId,
696
+ "aria-busy": isPending,
697
+ children: [/* @__PURE__ */ jsxs("div", {
698
+ className: file_list_module_default["ctrl"],
699
+ children: [/* @__PURE__ */ jsxs("div", {
700
+ className: file_list_module_default["pagination"],
701
+ children: [
702
+ /* @__PURE__ */ jsx("button", {
703
+ type: "button",
704
+ disabled: currentPage === 0,
705
+ command: "--paginate",
706
+ commandfor: rootId,
707
+ value: "prev",
708
+ children: "前へ"
709
+ }),
710
+ /* @__PURE__ */ jsxs("div", {
711
+ className: file_list_module_default["page"],
712
+ children: [
713
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("input", {
714
+ type: "number",
715
+ value: currentPage + 1,
716
+ min: "1",
717
+ max: totalPage,
718
+ onChange: (e_2) => paginate(e_2.currentTarget.valueAsNumber - 1),
719
+ "aria-label": "ページ番号"
720
+ }) }),
721
+ /* @__PURE__ */ jsx("span", { children: "/" }),
722
+ /* @__PURE__ */ jsx("span", { children: totalPage })
723
+ ]
724
+ }),
725
+ /* @__PURE__ */ jsx("button", {
726
+ type: "button",
727
+ disabled: currentPage === totalPage - 1,
728
+ command: "--paginate",
729
+ commandfor: rootId,
730
+ value: "next",
731
+ children: "次へ"
732
+ })
733
+ ]
734
+ }), /* @__PURE__ */ jsx("input", {
735
+ type: "search",
736
+ placeholder: "検索",
737
+ value: searchWord,
738
+ onChange: (e_3) => setSearchWord(e_3.currentTarget.value)
739
+ })]
740
+ }), /* @__PURE__ */ jsx("ul", {
741
+ className: file_list_module_default["list"],
742
+ children: files.map((file) => {
743
+ const upload = myUploads.find((u_2) => u_2.blob === file.url);
744
+ return /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs("button", {
745
+ ref: file.url === selected?.path ? scrollToSelected : void 0,
746
+ className: file_list_module_default["file"],
747
+ type: "button",
748
+ "aria-pressed": file.url === selected?.path,
749
+ command: "--select-file",
750
+ commandfor: rootId,
751
+ value: file.url,
752
+ "data-size": file.size,
753
+ children: [/* @__PURE__ */ jsx("span", {
754
+ className: file_list_module_default["thumbnail"],
755
+ children: /* @__PURE__ */ jsx(Thumbnail, { src: file.url })
756
+ }), upload ? /* @__PURE__ */ jsxs("span", { children: [
757
+ "アップロード中...",
758
+ " ",
759
+ /* @__PURE__ */ jsxs("span", { children: [Math.floor(upload.uploaded / upload.total * 100), "%"] })
760
+ ] }) : /* @__PURE__ */ jsxs("span", {
761
+ className: file_list_module_default["attr"],
762
+ children: [
763
+ /* @__PURE__ */ jsx("span", { children: "ID" }),
764
+ /* @__PURE__ */ jsx("span", { children: marked(file.fileId) }),
765
+ /* @__PURE__ */ jsx("span", { children: "名称" }),
766
+ /* @__PURE__ */ jsx("span", { children: marked(file.name) }),
767
+ /* @__PURE__ */ jsx("span", { children: "更新" }),
768
+ /* @__PURE__ */ jsx("span", { children: formatDate(file.timestamp / 1e3, "YYYY-MM-DD HH:mm") }),
769
+ /* @__PURE__ */ jsx("span", { children: "サイズ" }),
770
+ /* @__PURE__ */ jsx("span", { children: formatByteSize(file.size) })
771
+ ]
772
+ })]
773
+ }), !upload && store.canDelete ? /* @__PURE__ */ jsx("button", {
774
+ className: file_list_module_default["delete"],
775
+ type: "button",
776
+ command: "--delete-file",
777
+ commandfor: rootId,
778
+ value: file.url,
779
+ children: "削除"
780
+ }) : null] }, file.url);
781
+ })
782
+ })]
783
+ });
784
+ }
785
+ /**
786
+ * Callback ref attached only to the currently selected file button, so the
787
+ * list scrolls to it when the selection mounts or changes. Kept at module
788
+ * scope for a stable identity — an inline arrow would re-attach (and
789
+ * re-scroll) on every unrelated re-render such as upload progress updates.
790
+ * @param el - The selected button, or null on detach
791
+ */
792
+ function scrollToSelected(el) {
793
+ el?.scrollIntoView({
794
+ behavior: "smooth",
795
+ block: "nearest"
796
+ });
797
+ }
798
+ var file_uploader_module_default = { uploader: "_uploader_obiwu_1" };
799
+ // src/components/file-uploader.tsx
800
+ /**
801
+ * File upload control. The trigger button declares a local command and
802
+ * the handler opens the picker via `showPicker()` — no click handlers,
803
+ * no programmatic `click()`. The upload itself goes through the engine's
804
+ * `FileBrowserStore`, shared with `FileList`/`Preview` so they see the
805
+ * same progress without a broadcast bus.
806
+ * @param root0
807
+ * @param root0.fileType
808
+ * @example
809
+ * ```tsx
810
+ * <FileUploader fileType="image" />
811
+ * ```
812
+ */
813
+ function FileUploader(t0) {
814
+ const $ = c(15);
815
+ const { fileType } = t0;
816
+ const store = useFileBrowser();
817
+ const rootId = useId();
818
+ const inputRef = useRef(null);
819
+ const [, startTransition] = useTransition();
820
+ const accept = fileType === "image" ? "image/*" : "*";
821
+ let t1;
822
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
823
+ t1 = { "--open-file-picker": () => {
824
+ inputRef.current?.showPicker();
825
+ } };
826
+ $[0] = t1;
827
+ } else t1 = $[0];
828
+ const rootRef = useCommand(t1);
829
+ let t2;
830
+ if ($[1] !== fileType || $[2] !== startTransition || $[3] !== store) {
831
+ t2 = () => {
832
+ const file = inputRef.current?.files?.[0];
833
+ if (!file) return;
834
+ startTransition(async () => {
835
+ try {
836
+ await store.upload(fileType, file);
837
+ } catch {
838
+ alert(`ファイルのアップロードに失敗しました: ${file.name}`);
839
+ }
840
+ });
841
+ };
842
+ $[1] = fileType;
843
+ $[2] = startTransition;
844
+ $[3] = store;
845
+ $[4] = t2;
846
+ } else t2 = $[4];
847
+ const stageFile = t2;
848
+ let t3;
849
+ if ($[5] !== accept || $[6] !== stageFile) {
850
+ t3 = /* @__PURE__ */ jsx("input", {
851
+ type: "file",
852
+ ref: inputRef,
853
+ onChange: stageFile,
854
+ accept
855
+ });
856
+ $[5] = accept;
857
+ $[6] = stageFile;
858
+ $[7] = t3;
859
+ } else t3 = $[7];
860
+ let t4;
861
+ if ($[8] !== rootId) {
862
+ t4 = /* @__PURE__ */ jsx("button", {
863
+ type: "button",
864
+ command: "--open-file-picker",
865
+ commandfor: rootId,
866
+ children: "ファイルを追加アップロードする"
867
+ });
868
+ $[8] = rootId;
869
+ $[9] = t4;
870
+ } else t4 = $[9];
871
+ let t5;
872
+ if ($[10] !== rootId || $[11] !== rootRef || $[12] !== t3 || $[13] !== t4) {
873
+ t5 = /* @__PURE__ */ jsxs("div", {
874
+ ref: rootRef,
875
+ id: rootId,
876
+ className: file_uploader_module_default.uploader,
877
+ children: [t3, t4]
878
+ });
879
+ $[10] = rootId;
880
+ $[11] = rootRef;
881
+ $[12] = t3;
882
+ $[13] = t4;
883
+ $[14] = t5;
884
+ } else t5 = $[14];
885
+ return t5;
886
+ }
887
+ // src/components/front-matter-editor.tsx
888
+ /**
889
+ * Supported field types for Front Matter editor
890
+ */
891
+ /**
892
+ * Field definition for Front Matter
893
+ */
894
+ /**
895
+ * Owns the Front Matter field list — the actual data, as opposed to the
896
+ * view's own UI-only state (add-dialog-open, in-progress JSON drafts).
897
+ * Whether the panel is open is not part of this store.
898
+ * `createFrontMatterEditor`'s handle reads `getData()`/
899
+ * `getSnapshot()` directly and subscribes to be notified of changes,
900
+ * instead of a mutable closure variable updated from inside a React
901
+ * callback — the handle has no other way to read React state from
902
+ * outside React.
903
+ * @example
904
+ * ```ts
905
+ * const store = new FrontMatterStore({ title: 'A' });
906
+ * store.subscribe(() => console.log(store.getData()));
907
+ * store.setFields([{ key: 'title', type: 'text', value: 'B' }]);
908
+ * ```
909
+ */
910
+ var FrontMatterStore = class {
911
+ getSnapshot = () => this.#fields;
912
+ subscribe = (listener) => {
913
+ this.#listeners.add(listener);
914
+ return () => {
915
+ this.#listeners.delete(listener);
916
+ };
917
+ };
918
+ #fields;
919
+ #listeners = /* @__PURE__ */ new Set();
920
+ constructor(initialData) {
921
+ this.#fields = parseInitialData(initialData);
922
+ }
923
+ getData() {
924
+ return toData(this.#fields);
925
+ }
926
+ setFields(next) {
927
+ this.#fields = next;
928
+ for (const listener of this.#listeners) listener();
929
+ }
930
+ };
931
+ /**
932
+ * Options for the Front Matter editor
933
+ */
934
+ /**
935
+ * Handle returned by {@link createFrontMatterEditor}.
936
+ */
937
+ /**
938
+ * Mount the Front Matter editor (a React component) into the given
939
+ * container.
940
+ *
941
+ * The field list is rendered declaratively from React state, so
942
+ * toggling the panel or editing other fields never rebuilds the inputs
943
+ * — focus, caret position and IME composition survive re-renders.
944
+ * @param options - Mount target and initial data
945
+ * @returns A handle exposing the latest data and an unmount function
946
+ * @example
947
+ * ```ts
948
+ * const editor = createFrontMatterEditor({
949
+ * container: document.querySelector('.front-matter-editor')!,
950
+ * initialData: { title: 'ページ' },
951
+ * hasFrontMatter: true,
952
+ * onUpdated: (data) => debouncedSave(data),
953
+ * });
954
+ * editor.getData(); // => { title: 'ページ' }
955
+ * ```
956
+ */
957
+ function createFrontMatterEditor(options) {
958
+ const store = new FrontMatterStore(options.initialData);
959
+ const originalFrontMatter = options.hasFrontMatter ? JSON.stringify(options.initialData) : void 0;
960
+ const unsubscribe = store.subscribe(() => {
961
+ options.onUpdated?.(store.getData());
962
+ });
963
+ const root = createRoot(options.container);
964
+ root.render(/* @__PURE__ */ jsx(FrontMatterEditorView, { store }));
965
+ const teardown = () => {
966
+ unsubscribe();
967
+ root.unmount();
968
+ };
969
+ return {
970
+ getData: () => store.getData(),
971
+ getOriginalFrontMatter: () => originalFrontMatter,
972
+ unmount: teardown,
973
+ [Symbol.dispose]: teardown
974
+ };
975
+ }
976
+ /**
977
+ * Front Matterの動的フォーム本体。フィールド一覧は`store`(唯一の
978
+ * データソース)から読み、追加ダイアログとJSON下書きはこの見た目だけの
979
+ * UI状態としてローカルに持つ。フィールドの追加と削除は Invoker Commands
980
+ * (`--fm-add-field` / `--fm-delete-field`)で受ける。
981
+ *
982
+ * 開閉は `<details>` の `open` に任せる。Invoker Command と React の
983
+ * state には戻さない。同じ状態をコマンドのハンドラと DOM の属性の両方に
984
+ * 持つと、再レンダーのたびにどちらかがもう一方を上書きする。
985
+ *
986
+ * 「+ 追加」は `summary` の外に置く。`summary` の内容モデルはフレーズ内容
987
+ * で、ボタンを入れると対話要素の入れ子になり、押すとパネルも開閉する。
988
+ * 閉じた `details` の中に置くと、閉じている間はボタンが押せなくなる。
989
+ * 見た目は見出し行の右端だが、DOM 順ではフィールドの後なので、キーボードの
990
+ * 移動順は見出し、フィールド、追加ボタンになる。
991
+ * @param root0
992
+ * @param root0.store
993
+ * @example
994
+ * ```tsx
995
+ * <FrontMatterEditorView store={new FrontMatterStore({ title: 'ページ' })} />
996
+ * ```
997
+ */
998
+ function FrontMatterEditorView({ store }) {
999
+ const rootId = useId();
1000
+ const dialogId = useId();
1001
+ const fields = useSyncExternalStore(store.subscribe, store.getSnapshot);
1002
+ const [addDialogOpen, setAddDialogOpen] = useState(false);
1003
+ const [jsonDrafts, setJsonDrafts] = useState({});
1004
+ const applyFields = (next) => {
1005
+ store.setFields(next);
1006
+ };
1007
+ const updateFieldValue = (key, value) => {
1008
+ applyFields(fields.map((f) => f.key === key ? {
1009
+ ...f,
1010
+ value
1011
+ } : f));
1012
+ };
1013
+ const rootRef = useCommand({
1014
+ "--fm-add-field": () => {
1015
+ setAddDialogOpen(true);
1016
+ },
1017
+ "--fm-delete-field": (e) => {
1018
+ const key_0 = e.source?.value;
1019
+ if (key_0 == null) return;
1020
+ applyFields(fields.filter((f_0) => f_0.key !== key_0));
1021
+ setJsonDrafts((prev) => {
1022
+ const { [key_0]: _removed, ...rest } = prev;
1023
+ return rest;
1024
+ });
1025
+ }
1026
+ });
1027
+ const onAddSubmit = (e_0) => {
1028
+ e_0.preventDefault();
1029
+ const formData = new FormData(e_0.currentTarget);
1030
+ const key_1 = String(formData.get("key") ?? "");
1031
+ const type = formData.get("type");
1032
+ if (key_1 && !fields.some((f_1) => f_1.key === key_1)) applyFields([...fields, {
1033
+ key: key_1,
1034
+ type,
1035
+ value: getDefaultValue(type)
1036
+ }]);
1037
+ setAddDialogOpen(false);
1038
+ };
1039
+ return /* @__PURE__ */ jsxs("div", {
1040
+ ref: rootRef,
1041
+ id: rootId,
1042
+ className: "fm-editor",
1043
+ children: [
1044
+ /* @__PURE__ */ jsxs("details", {
1045
+ className: "fm-editor-details",
1046
+ open: true,
1047
+ children: [/* @__PURE__ */ jsx("summary", {
1048
+ className: "fm-editor-toggle",
1049
+ children: "Front Matter"
1050
+ }), /* @__PURE__ */ jsx("div", {
1051
+ className: "fm-editor-fields",
1052
+ children: fields.length === 0 ? /* @__PURE__ */ jsx("div", {
1053
+ className: "fm-editor-empty",
1054
+ children: "フィールドがありません。「+ 追加」ボタンでフィールドを追加してください。"
1055
+ }) : fields.map((field) => /* @__PURE__ */ jsxs("div", {
1056
+ className: "fm-editor-field",
1057
+ "data-type": field.type,
1058
+ children: [
1059
+ /* @__PURE__ */ jsx("label", {
1060
+ className: "fm-editor-field-label",
1061
+ htmlFor: `${rootId}-field-${field.key}`,
1062
+ children: field.key
1063
+ }),
1064
+ /* @__PURE__ */ jsx("div", {
1065
+ className: "fm-editor-field-input",
1066
+ children: /* @__PURE__ */ jsx(FieldInput, {
1067
+ field,
1068
+ inputId: `${rootId}-field-${field.key}`,
1069
+ jsonDraft: jsonDrafts[field.key],
1070
+ onValueChange: (value_0) => updateFieldValue(field.key, value_0),
1071
+ onJsonDraftChange: (text) => {
1072
+ setJsonDrafts((prev_0) => ({
1073
+ ...prev_0,
1074
+ [field.key]: text
1075
+ }));
1076
+ }
1077
+ })
1078
+ }),
1079
+ /* @__PURE__ */ jsx("button", {
1080
+ type: "button",
1081
+ className: "fm-editor-field-delete",
1082
+ title: "フィールドを削除",
1083
+ command: "--fm-delete-field",
1084
+ commandfor: rootId,
1085
+ value: field.key,
1086
+ children: "×"
1087
+ })
1088
+ ]
1089
+ }, field.key))
1090
+ })]
1091
+ }),
1092
+ /* @__PURE__ */ jsx("button", {
1093
+ type: "button",
1094
+ className: "fm-editor-add",
1095
+ title: "フィールドを追加",
1096
+ command: "--fm-add-field",
1097
+ commandfor: rootId,
1098
+ children: "+ 追加"
1099
+ }),
1100
+ addDialogOpen ? /* @__PURE__ */ jsx(AddFieldDialog, {
1101
+ dialogId,
1102
+ onSubmit: onAddSubmit,
1103
+ onClose: () => setAddDialogOpen(false)
1104
+ }) : null
1105
+ ]
1106
+ });
1107
+ }
1108
+ /**
1109
+ * 型別のcontrolled input
1110
+ * @param root0
1111
+ * @param root0.field
1112
+ * @param root0.inputId
1113
+ * @param root0.jsonDraft
1114
+ * @param root0.onValueChange
1115
+ * @param root0.onJsonDraftChange
1116
+ */
1117
+ function FieldInput(t0) {
1118
+ const $ = c(37);
1119
+ const { field, inputId, jsonDraft, onValueChange, onJsonDraftChange } = t0;
1120
+ switch (field.type) {
1121
+ case "boolean": {
1122
+ const t1 = Boolean(field.value);
1123
+ let t2;
1124
+ if ($[0] !== onValueChange) {
1125
+ t2 = (e_3) => onValueChange(e_3.currentTarget.checked);
1126
+ $[0] = onValueChange;
1127
+ $[1] = t2;
1128
+ } else t2 = $[1];
1129
+ let t3;
1130
+ if ($[2] !== inputId || $[3] !== t1 || $[4] !== t2) {
1131
+ t3 = /* @__PURE__ */ jsx("input", {
1132
+ id: inputId,
1133
+ type: "checkbox",
1134
+ checked: t1,
1135
+ onChange: t2
1136
+ });
1137
+ $[2] = inputId;
1138
+ $[3] = t1;
1139
+ $[4] = t2;
1140
+ $[5] = t3;
1141
+ } else t3 = $[5];
1142
+ return t3;
1143
+ }
1144
+ case "number": {
1145
+ const t1 = field.value == null ? "" : String(field.value);
1146
+ let t2;
1147
+ if ($[6] !== onValueChange) {
1148
+ t2 = (e_2) => {
1149
+ onValueChange(e_2.currentTarget.value === "" ? null : Number(e_2.currentTarget.value));
1150
+ };
1151
+ $[6] = onValueChange;
1152
+ $[7] = t2;
1153
+ } else t2 = $[7];
1154
+ let t3;
1155
+ if ($[8] !== inputId || $[9] !== t1 || $[10] !== t2) {
1156
+ t3 = /* @__PURE__ */ jsx("input", {
1157
+ id: inputId,
1158
+ type: "number",
1159
+ value: t1,
1160
+ onChange: t2
1161
+ });
1162
+ $[8] = inputId;
1163
+ $[9] = t1;
1164
+ $[10] = t2;
1165
+ $[11] = t3;
1166
+ } else t3 = $[11];
1167
+ return t3;
1168
+ }
1169
+ case "date": {
1170
+ let t1;
1171
+ if ($[12] !== field.value) {
1172
+ t1 = toDateInputValue(field.value);
1173
+ $[12] = field.value;
1174
+ $[13] = t1;
1175
+ } else t1 = $[13];
1176
+ let t2;
1177
+ if ($[14] !== onValueChange) {
1178
+ t2 = (e_1) => onValueChange(e_1.currentTarget.value);
1179
+ $[14] = onValueChange;
1180
+ $[15] = t2;
1181
+ } else t2 = $[15];
1182
+ let t3;
1183
+ if ($[16] !== inputId || $[17] !== t1 || $[18] !== t2) {
1184
+ t3 = /* @__PURE__ */ jsx("input", {
1185
+ id: inputId,
1186
+ type: "date",
1187
+ value: t1,
1188
+ onChange: t2
1189
+ });
1190
+ $[16] = inputId;
1191
+ $[17] = t1;
1192
+ $[18] = t2;
1193
+ $[19] = t3;
1194
+ } else t3 = $[19];
1195
+ return t3;
1196
+ }
1197
+ case "json": {
1198
+ let t1;
1199
+ if ($[20] !== field.value || $[21] !== jsonDraft) {
1200
+ t1 = jsonDraft ?? stringifyJson(field.value);
1201
+ $[20] = field.value;
1202
+ $[21] = jsonDraft;
1203
+ $[22] = t1;
1204
+ } else t1 = $[22];
1205
+ const text = t1;
1206
+ const t2 = isValidJson(text) ? void 0 : "fm-editor-error";
1207
+ let t3;
1208
+ if ($[23] !== onJsonDraftChange || $[24] !== onValueChange) {
1209
+ t3 = (e_0) => {
1210
+ const nextText = e_0.currentTarget.value;
1211
+ onJsonDraftChange(nextText);
1212
+ try {
1213
+ onValueChange(JSON.parse(nextText));
1214
+ } catch {}
1215
+ };
1216
+ $[23] = onJsonDraftChange;
1217
+ $[24] = onValueChange;
1218
+ $[25] = t3;
1219
+ } else t3 = $[25];
1220
+ let t4;
1221
+ if ($[26] !== inputId || $[27] !== t2 || $[28] !== t3 || $[29] !== text) {
1222
+ t4 = /* @__PURE__ */ jsx("textarea", {
1223
+ id: inputId,
1224
+ rows: 3,
1225
+ className: t2,
1226
+ value: text,
1227
+ onChange: t3
1228
+ });
1229
+ $[26] = inputId;
1230
+ $[27] = t2;
1231
+ $[28] = t3;
1232
+ $[29] = text;
1233
+ $[30] = t4;
1234
+ } else t4 = $[30];
1235
+ return t4;
1236
+ }
1237
+ default: {
1238
+ const t1 = String(field.value ?? "");
1239
+ let t2;
1240
+ if ($[31] !== onValueChange) {
1241
+ t2 = (e) => onValueChange(e.currentTarget.value);
1242
+ $[31] = onValueChange;
1243
+ $[32] = t2;
1244
+ } else t2 = $[32];
1245
+ let t3;
1246
+ if ($[33] !== inputId || $[34] !== t1 || $[35] !== t2) {
1247
+ t3 = /* @__PURE__ */ jsx("input", {
1248
+ id: inputId,
1249
+ type: "text",
1250
+ value: t1,
1251
+ onChange: t2
1252
+ });
1253
+ $[33] = inputId;
1254
+ $[34] = t1;
1255
+ $[35] = t2;
1256
+ $[36] = t3;
1257
+ } else t3 = $[36];
1258
+ return t3;
1259
+ }
1260
+ }
1261
+ }
1262
+ /**
1263
+ * フィールド追加ダイアログ。マウント時にshowModalし、close(キャンセル
1264
+ * ボタンの組み込みcloseコマンド / Escキー)でアンマウントされる
1265
+ * @param root0
1266
+ * @param root0.dialogId
1267
+ * @param root0.onSubmit
1268
+ * @param root0.onClose
1269
+ */
1270
+ function AddFieldDialog(t0) {
1271
+ const $ = c(36);
1272
+ const { dialogId, onSubmit, onClose } = t0;
1273
+ const dialogRef = useRef(null);
1274
+ let t1;
1275
+ let t2;
1276
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1277
+ t1 = () => {
1278
+ const dialog = dialogRef.current;
1279
+ if (dialog && !dialog.open) dialog.showModal();
1280
+ };
1281
+ t2 = [];
1282
+ $[0] = t1;
1283
+ $[1] = t2;
1284
+ } else {
1285
+ t1 = $[0];
1286
+ t2 = $[1];
1287
+ }
1288
+ useEffect(t1, t2);
1289
+ let t3;
1290
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
1291
+ t3 = /* @__PURE__ */ jsx("h3", { children: "フィールドを追加" });
1292
+ $[2] = t3;
1293
+ } else t3 = $[2];
1294
+ const t4 = `${dialogId}-key`;
1295
+ let t5;
1296
+ if ($[3] !== t4) {
1297
+ t5 = /* @__PURE__ */ jsx("label", {
1298
+ htmlFor: t4,
1299
+ children: "キー名"
1300
+ });
1301
+ $[3] = t4;
1302
+ $[4] = t5;
1303
+ } else t5 = $[4];
1304
+ const t6 = `${dialogId}-key`;
1305
+ let t7;
1306
+ if ($[5] !== t6) {
1307
+ t7 = /* @__PURE__ */ jsx("input", {
1308
+ type: "text",
1309
+ id: t6,
1310
+ name: "key",
1311
+ required: true,
1312
+ placeholder: "例: title, author, date"
1313
+ });
1314
+ $[5] = t6;
1315
+ $[6] = t7;
1316
+ } else t7 = $[6];
1317
+ let t8;
1318
+ if ($[7] !== t5 || $[8] !== t7) {
1319
+ t8 = /* @__PURE__ */ jsxs("div", {
1320
+ className: "fm-editor-dialog-field",
1321
+ children: [t5, t7]
1322
+ });
1323
+ $[7] = t5;
1324
+ $[8] = t7;
1325
+ $[9] = t8;
1326
+ } else t8 = $[9];
1327
+ const t9 = `${dialogId}-type`;
1328
+ let t10;
1329
+ if ($[10] !== t9) {
1330
+ t10 = /* @__PURE__ */ jsx("label", {
1331
+ htmlFor: t9,
1332
+ children: "型"
1333
+ });
1334
+ $[10] = t9;
1335
+ $[11] = t10;
1336
+ } else t10 = $[11];
1337
+ const t11 = `${dialogId}-type`;
1338
+ let t12;
1339
+ let t13;
1340
+ let t14;
1341
+ let t15;
1342
+ let t16;
1343
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
1344
+ t12 = /* @__PURE__ */ jsx("option", {
1345
+ value: "text",
1346
+ children: "テキスト"
1347
+ });
1348
+ t13 = /* @__PURE__ */ jsx("option", {
1349
+ value: "number",
1350
+ children: "数値"
1351
+ });
1352
+ t14 = /* @__PURE__ */ jsx("option", {
1353
+ value: "boolean",
1354
+ children: "真偽値"
1355
+ });
1356
+ t15 = /* @__PURE__ */ jsx("option", {
1357
+ value: "date",
1358
+ children: "日付"
1359
+ });
1360
+ t16 = /* @__PURE__ */ jsx("option", {
1361
+ value: "json",
1362
+ children: "JSON(配列/オブジェクト)"
1363
+ });
1364
+ $[12] = t12;
1365
+ $[13] = t13;
1366
+ $[14] = t14;
1367
+ $[15] = t15;
1368
+ $[16] = t16;
1369
+ } else {
1370
+ t12 = $[12];
1371
+ t13 = $[13];
1372
+ t14 = $[14];
1373
+ t15 = $[15];
1374
+ t16 = $[16];
1375
+ }
1376
+ let t17;
1377
+ if ($[17] !== t11) {
1378
+ t17 = /* @__PURE__ */ jsxs("select", {
1379
+ id: t11,
1380
+ name: "type",
1381
+ children: [
1382
+ t12,
1383
+ t13,
1384
+ t14,
1385
+ t15,
1386
+ t16
1387
+ ]
1388
+ });
1389
+ $[17] = t11;
1390
+ $[18] = t17;
1391
+ } else t17 = $[18];
1392
+ let t18;
1393
+ if ($[19] !== t10 || $[20] !== t17) {
1394
+ t18 = /* @__PURE__ */ jsxs("div", {
1395
+ className: "fm-editor-dialog-field",
1396
+ children: [t10, t17]
1397
+ });
1398
+ $[19] = t10;
1399
+ $[20] = t17;
1400
+ $[21] = t18;
1401
+ } else t18 = $[21];
1402
+ let t19;
1403
+ if ($[22] !== dialogId) {
1404
+ t19 = /* @__PURE__ */ jsx("button", {
1405
+ type: "button",
1406
+ className: "fm-editor-dialog-cancel",
1407
+ command: "close",
1408
+ commandfor: dialogId,
1409
+ children: "キャンセル"
1410
+ });
1411
+ $[22] = dialogId;
1412
+ $[23] = t19;
1413
+ } else t19 = $[23];
1414
+ let t20;
1415
+ if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
1416
+ t20 = /* @__PURE__ */ jsx("button", {
1417
+ type: "submit",
1418
+ className: "fm-editor-dialog-submit",
1419
+ children: "追加"
1420
+ });
1421
+ $[24] = t20;
1422
+ } else t20 = $[24];
1423
+ let t21;
1424
+ if ($[25] !== t19) {
1425
+ t21 = /* @__PURE__ */ jsxs("div", {
1426
+ className: "fm-editor-dialog-actions",
1427
+ children: [t19, t20]
1428
+ });
1429
+ $[25] = t19;
1430
+ $[26] = t21;
1431
+ } else t21 = $[26];
1432
+ let t22;
1433
+ if ($[27] !== onSubmit || $[28] !== t18 || $[29] !== t21 || $[30] !== t8) {
1434
+ t22 = /* @__PURE__ */ jsxs("form", {
1435
+ onSubmit,
1436
+ children: [
1437
+ t3,
1438
+ t8,
1439
+ t18,
1440
+ t21
1441
+ ]
1442
+ });
1443
+ $[27] = onSubmit;
1444
+ $[28] = t18;
1445
+ $[29] = t21;
1446
+ $[30] = t8;
1447
+ $[31] = t22;
1448
+ } else t22 = $[31];
1449
+ let t23;
1450
+ if ($[32] !== dialogId || $[33] !== onClose || $[34] !== t22) {
1451
+ t23 = /* @__PURE__ */ jsx("dialog", {
1452
+ ref: dialogRef,
1453
+ className: "fm-editor-dialog",
1454
+ id: dialogId,
1455
+ onClose,
1456
+ children: t22
1457
+ });
1458
+ $[32] = dialogId;
1459
+ $[33] = onClose;
1460
+ $[34] = t22;
1461
+ $[35] = t23;
1462
+ } else t23 = $[35];
1463
+ return t23;
1464
+ }
1465
+ /**
1466
+ * Parse initial data and detect field types
1467
+ * @param data
1468
+ */
1469
+ function parseInitialData(data) {
1470
+ return Object.entries(data).map(([key, value]) => ({
1471
+ key,
1472
+ type: detectType(value),
1473
+ value
1474
+ }));
1475
+ }
1476
+ /**
1477
+ * フィールド一覧をFront Matterデータへ畳み込む
1478
+ * @param fields
1479
+ */
1480
+ function toData(fields) {
1481
+ const data = {};
1482
+ for (const field of fields) data[field.key] = field.value;
1483
+ return data;
1484
+ }
1485
+ /**
1486
+ * Detect the type of a value
1487
+ * @param value
1488
+ */
1489
+ function detectType(value) {
1490
+ if (typeof value === "boolean") return "boolean";
1491
+ if (typeof value === "number") return "number";
1492
+ if (typeof value === "string") {
1493
+ if (/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2})?/.test(value)) {
1494
+ const parsed = Date.parse(value);
1495
+ if (!Number.isNaN(parsed)) return "date";
1496
+ }
1497
+ return "text";
1498
+ }
1499
+ if (value instanceof Date) return "date";
1500
+ if (typeof value === "object" && value !== null) return "json";
1501
+ return "text";
1502
+ }
1503
+ /**
1504
+ * Get default value for a type
1505
+ * @param type
1506
+ */
1507
+ function getDefaultValue(type) {
1508
+ switch (type) {
1509
+ case "boolean": return false;
1510
+ case "number": return 0;
1511
+ case "date": return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
1512
+ case "json": return [];
1513
+ default: return "";
1514
+ }
1515
+ }
1516
+ /**
1517
+ * `<input type="date">` に渡せる `yyyy-mm-dd` へ正規化する。
1518
+ * 不正な日付は空文字(未入力)にする
1519
+ * @param value
1520
+ */
1521
+ function toDateInputValue(value) {
1522
+ if (!value) return "";
1523
+ const dateValue = value instanceof Date ? value : new Date(String(value));
1524
+ if (Number.isNaN(dateValue.getTime())) return "";
1525
+ return dateValue.toISOString().split("T")[0] ?? "";
1526
+ }
1527
+ /**
1528
+ * @param value
1529
+ */
1530
+ function stringifyJson(value) {
1531
+ try {
1532
+ return JSON.stringify(value, null, 2);
1533
+ } catch {
1534
+ return String(value);
1535
+ }
1536
+ }
1537
+ /**
1538
+ * @param text
1539
+ */
1540
+ function isValidJson(text) {
1541
+ try {
1542
+ JSON.parse(text);
1543
+ return true;
1544
+ } catch {
1545
+ return false;
1546
+ }
1547
+ }
1548
+ var preview_module_default = {
1549
+ img: "_img_18j28_1",
1550
+ uploading: "_uploading_18j28_26",
1551
+ progress: "_progress_18j28_30",
1552
+ meta: "_meta_18j28_40",
1553
+ path: "_path_18j28_60",
1554
+ upload: "_upload_18j28_26",
1555
+ dimension: "_dimension_18j28_72"
1556
+ };
1557
+ // src/components/preview.tsx
1558
+ /**
1559
+ * File preview pane. The previewed path comes from the parent (lifted
1560
+ * from the item's own state); upload progress is read from the engine's
1561
+ * `FileBrowserStore`, shared with `FileList`/`FileUploader`.
1562
+ * @param root0
1563
+ * @param root0.path
1564
+ * @example
1565
+ * ```tsx
1566
+ * <Preview path={state.path ?? ''} />
1567
+ * ```
1568
+ */
1569
+ function Preview(t0) {
1570
+ const $ = c(36);
1571
+ const { path } = t0;
1572
+ const store = useFileBrowser();
1573
+ const [dimension, setDimension] = useState(null);
1574
+ const [prevPath, setPrevPath] = useState(path);
1575
+ if (prevPath !== path) {
1576
+ setPrevPath(path);
1577
+ setDimension(null);
1578
+ }
1579
+ let t1;
1580
+ if ($[0] !== path) {
1581
+ t1 = path ? getExt(path) : null;
1582
+ $[0] = path;
1583
+ $[1] = t1;
1584
+ } else t1 = $[1];
1585
+ const file = t1;
1586
+ let t2;
1587
+ if ($[2] !== path) {
1588
+ t2 = path.startsWith("blob:");
1589
+ $[2] = path;
1590
+ $[3] = t2;
1591
+ } else t2 = $[3];
1592
+ const isUploadingMode = t2;
1593
+ let t3;
1594
+ if ($[4] !== store) {
1595
+ t3 = () => store.getSnapshot().uploads;
1596
+ $[4] = store;
1597
+ $[5] = t3;
1598
+ } else t3 = $[5];
1599
+ const uploads = useSyncExternalStore(store.subscribe, t3);
1600
+ let t4;
1601
+ if ($[6] !== path || $[7] !== uploads) {
1602
+ t4 = uploads.find((u) => u.blob === path) ?? {
1603
+ uploaded: 0,
1604
+ total: 100
1605
+ };
1606
+ $[6] = path;
1607
+ $[7] = uploads;
1608
+ $[8] = t4;
1609
+ } else t4 = $[8];
1610
+ const progress = t4;
1611
+ let t5;
1612
+ let t6;
1613
+ if ($[9] !== path) {
1614
+ t5 = () => {
1615
+ const file_0 = path ? getExt(path) : null;
1616
+ let aborted = false;
1617
+ if (file_0?.isImage) {
1618
+ const image = new Image();
1619
+ image.src = path;
1620
+ image.addEventListener("load", () => {
1621
+ if (!aborted) setDimension({
1622
+ width: image.naturalWidth,
1623
+ height: image.naturalHeight
1624
+ });
1625
+ }, { once: true });
1626
+ } else if (file_0?.isVideo) {
1627
+ const video = document.createElement("video");
1628
+ video.src = path;
1629
+ video.addEventListener("loadedmetadata", () => {
1630
+ if (!aborted) setDimension({
1631
+ width: video.videoWidth,
1632
+ height: video.videoHeight
1633
+ });
1634
+ }, { once: true });
1635
+ }
1636
+ return () => {
1637
+ aborted = true;
1638
+ };
1639
+ };
1640
+ t6 = [path];
1641
+ $[9] = path;
1642
+ $[10] = t5;
1643
+ $[11] = t6;
1644
+ } else {
1645
+ t5 = $[10];
1646
+ t6 = $[11];
1647
+ }
1648
+ useEffect(t5, t6);
1649
+ const t7 = `${preview_module_default.img} ${isUploadingMode ? preview_module_default.uploading : ""}`;
1650
+ let t8;
1651
+ if ($[12] !== t7) {
1652
+ t8 = t7.trim();
1653
+ $[12] = t7;
1654
+ $[13] = t8;
1655
+ } else t8 = $[13];
1656
+ let t9;
1657
+ if ($[14] !== file || $[15] !== path) {
1658
+ t9 = file?.isImage ? /* @__PURE__ */ jsx("img", {
1659
+ src: path,
1660
+ alt: "画像プレビュー"
1661
+ }) : file?.isVideo ? /* @__PURE__ */ jsxs("video", {
1662
+ controls: true,
1663
+ playsInline: true,
1664
+ children: [/* @__PURE__ */ jsx("source", {
1665
+ src: path,
1666
+ type: `video/${file.ext}`
1667
+ }), /* @__PURE__ */ jsx("track", {
1668
+ kind: "captions",
1669
+ src: ""
1670
+ })]
1671
+ }) : file?.isAudio ? /* @__PURE__ */ jsxs("audio", {
1672
+ controls: true,
1673
+ children: [/* @__PURE__ */ jsx("source", {
1674
+ src: path,
1675
+ type: `audio/${file.ext}`
1676
+ }), /* @__PURE__ */ jsx("track", {
1677
+ kind: "metadata",
1678
+ src: ""
1679
+ })]
1680
+ }) : file?.isDoc || file?.isPpt || file?.isXls || file?.isPdf ? /* @__PURE__ */ jsx("object", {
1681
+ data: path,
1682
+ type: `application/${file.ext}`,
1683
+ title: `${file.ext}ファイルのプレビュー`,
1684
+ children: /* @__PURE__ */ jsx("p", { children: "プレビューできません" })
1685
+ }) : /* @__PURE__ */ jsx("p", { children: "プレビューできません" });
1686
+ $[14] = file;
1687
+ $[15] = path;
1688
+ $[16] = t9;
1689
+ } else t9 = $[16];
1690
+ let t10;
1691
+ if ($[17] !== isUploadingMode || $[18] !== progress) {
1692
+ t10 = isUploadingMode ? /* @__PURE__ */ jsx("div", {
1693
+ className: preview_module_default.progress,
1694
+ style: { translate: `${progress.uploaded / progress.total * 100}%` }
1695
+ }) : null;
1696
+ $[17] = isUploadingMode;
1697
+ $[18] = progress;
1698
+ $[19] = t10;
1699
+ } else t10 = $[19];
1700
+ let t11;
1701
+ if ($[20] !== t10 || $[21] !== t8 || $[22] !== t9) {
1702
+ t11 = /* @__PURE__ */ jsxs("div", {
1703
+ className: t8,
1704
+ children: [t9, t10]
1705
+ });
1706
+ $[20] = t10;
1707
+ $[21] = t8;
1708
+ $[22] = t9;
1709
+ $[23] = t11;
1710
+ } else t11 = $[23];
1711
+ let t12;
1712
+ if ($[24] !== isUploadingMode || $[25] !== path || $[26] !== progress) {
1713
+ t12 = isUploadingMode ? /* @__PURE__ */ jsxs("li", {
1714
+ className: preview_module_default.upload,
1715
+ children: [/* @__PURE__ */ jsx("span", { children: "アップロード..." }), /* @__PURE__ */ jsxs("span", {
1716
+ className: preview_module_default.progress,
1717
+ children: [
1718
+ Math.round(progress.uploaded / progress.total * 100),
1719
+ "% (",
1720
+ progress.uploaded,
1721
+ "/",
1722
+ progress.total,
1723
+ ")"
1724
+ ]
1725
+ })]
1726
+ }) : /* @__PURE__ */ jsx("li", {
1727
+ className: preview_module_default.path,
1728
+ children: /* @__PURE__ */ jsx("a", {
1729
+ href: path,
1730
+ target: "_blank",
1731
+ children: path
1732
+ })
1733
+ });
1734
+ $[24] = isUploadingMode;
1735
+ $[25] = path;
1736
+ $[26] = progress;
1737
+ $[27] = t12;
1738
+ } else t12 = $[27];
1739
+ let t13;
1740
+ if ($[28] !== dimension) {
1741
+ t13 = dimension ? /* @__PURE__ */ jsxs("li", {
1742
+ className: preview_module_default.dimension,
1743
+ children: [
1744
+ dimension.width,
1745
+ "x",
1746
+ dimension.height
1747
+ ]
1748
+ }) : null;
1749
+ $[28] = dimension;
1750
+ $[29] = t13;
1751
+ } else t13 = $[29];
1752
+ let t14;
1753
+ if ($[30] !== t12 || $[31] !== t13) {
1754
+ t14 = /* @__PURE__ */ jsxs("ul", {
1755
+ className: preview_module_default.meta,
1756
+ children: [t12, t13]
1757
+ });
1758
+ $[30] = t12;
1759
+ $[31] = t13;
1760
+ $[32] = t14;
1761
+ } else t14 = $[32];
1762
+ let t15;
1763
+ if ($[33] !== t11 || $[34] !== t14) {
1764
+ t15 = /* @__PURE__ */ jsxs("div", { children: [t11, t14] });
1765
+ $[33] = t11;
1766
+ $[34] = t14;
1767
+ $[35] = t15;
1768
+ } else t15 = $[35];
1769
+ return t15;
1770
+ }
1771
+ var table_editor_module_default = {
1772
+ table: "_table_1qb61_1",
1773
+ row: "_row_1qb61_7",
1774
+ btn: "_btn_1qb61_19"
1775
+ };
1776
+ // src/components/table-editor.tsx
1777
+ /**
1778
+ * Row-aligned table cell text: `th[i]` and `td[i]` form one row. In the
1779
+ * table item the `td` cells hold Markdown while editing (converted
1780
+ * to/from HTML via `toEditorState`/`toItemData`); `th` cells stay plain.
1781
+ */
1782
+ /**
1783
+ * Table row editor as a fully controlled component. The table item's
1784
+ * editor owns the state; row operations are declared as local commands.
1785
+ * @param root0
1786
+ * @param root0.value
1787
+ * @param root0.onChange
1788
+ * @example
1789
+ * ```tsx
1790
+ * <TableEditor
1791
+ * value={{ th: state.th ?? [], td: state.td ?? [] }}
1792
+ * onChange={({ th, td }) => setState({ ...state, th: [...th], td: [...td] })}
1793
+ * />
1794
+ * ```
1795
+ */
1796
+ function TableEditor(t0) {
1797
+ const $ = c(12);
1798
+ const { value, onChange } = t0;
1799
+ const rootId = useId();
1800
+ let t1;
1801
+ if ($[0] !== value.th) {
1802
+ t1 = () => value.th.map(_temp$1);
1803
+ $[0] = value.th;
1804
+ $[1] = t1;
1805
+ } else t1 = $[1];
1806
+ const [rowIds, setRowIds] = useState(t1);
1807
+ let t2;
1808
+ if ($[2] !== rowIds || $[3] !== value.td) {
1809
+ t2 = (th, i) => ({
1810
+ id: rowIds[i] ?? String(i),
1811
+ th,
1812
+ td: value.td[i] ?? ""
1813
+ });
1814
+ $[2] = rowIds;
1815
+ $[3] = value.td;
1816
+ $[4] = t2;
1817
+ } else t2 = $[4];
1818
+ const rows = value.th.map(t2);
1819
+ let t3;
1820
+ if ($[5] !== onChange) {
1821
+ t3 = (next) => {
1822
+ setRowIds(next.map(_temp2));
1823
+ onChange({
1824
+ th: next.map(_temp3),
1825
+ td: next.map(_temp4)
1826
+ });
1827
+ };
1828
+ $[5] = onChange;
1829
+ $[6] = t3;
1830
+ } else t3 = $[6];
1831
+ const commit = t3;
1832
+ const rootRef = useCommand({
1833
+ "--add-row": (e) => {
1834
+ const index = Number(e.source?.value);
1835
+ commit(rows.toSpliced(index + 1, 0, {
1836
+ id: crypto.randomUUID(),
1837
+ th: "",
1838
+ td: ""
1839
+ }));
1840
+ },
1841
+ "--remove-row": (e_0) => {
1842
+ const index_0 = Number(e_0.source?.value);
1843
+ commit(rows.toSpliced(index_0, 1));
1844
+ },
1845
+ "--move-row-down": (e_1) => {
1846
+ const from = Number(e_1.source?.value);
1847
+ const to = from + 1;
1848
+ const fromRow = rows[from];
1849
+ const toRow = rows[to];
1850
+ if (!fromRow || !toRow) return;
1851
+ commit(rows.toSpliced(from, 1, toRow).toSpliced(to, 1, fromRow));
1852
+ }
1853
+ });
1854
+ const t4 = table_editor_module_default;
1855
+ const t6 = rows.map((t5, i_0) => {
1856
+ const { id, th: th_0, td } = t5;
1857
+ return /* @__PURE__ */ jsxs("div", {
1858
+ className: table_editor_module_default.row,
1859
+ children: [
1860
+ /* @__PURE__ */ jsx("div", {
1861
+ className: table_editor_module_default.th,
1862
+ children: /* @__PURE__ */ jsx("textarea", {
1863
+ "aria-label": `${i_0}行目の見出しセル`,
1864
+ name: `bge-th-${i_0}`,
1865
+ value: th_0,
1866
+ onChange: (e_2) => {
1867
+ commit(rows.with(i_0, {
1868
+ id,
1869
+ th: e_2.currentTarget.value,
1870
+ td
1871
+ }));
1872
+ }
1873
+ })
1874
+ }),
1875
+ /* @__PURE__ */ jsx("div", {
1876
+ className: table_editor_module_default.td,
1877
+ children: /* @__PURE__ */ jsx("textarea", {
1878
+ "aria-label": `${i_0}行目の内容セル`,
1879
+ name: `bge-td-${i_0}`,
1880
+ value: td,
1881
+ onChange: (e_3) => {
1882
+ commit(rows.with(i_0, {
1883
+ id,
1884
+ th: th_0,
1885
+ td: e_3.currentTarget.value
1886
+ }));
1887
+ }
1888
+ })
1889
+ }),
1890
+ /* @__PURE__ */ jsx("div", {
1891
+ className: table_editor_module_default.btn,
1892
+ children: /* @__PURE__ */ jsxs("ul", { children: [
1893
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1894
+ type: "button",
1895
+ title: "下に追加",
1896
+ command: "--add-row",
1897
+ commandfor: rootId,
1898
+ value: i_0,
1899
+ children: /* @__PURE__ */ jsx(IconRowInsertBottom, {})
1900
+ }) }),
1901
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1902
+ type: "button",
1903
+ title: "削除",
1904
+ disabled: rows.length === 1,
1905
+ command: "--remove-row",
1906
+ commandfor: rootId,
1907
+ value: i_0,
1908
+ children: /* @__PURE__ */ jsx(IconTrash, {})
1909
+ }) }),
1910
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1911
+ type: "button",
1912
+ title: "下に移動",
1913
+ disabled: i_0 === rows.length - 1,
1914
+ command: "--move-row-down",
1915
+ commandfor: rootId,
1916
+ value: i_0,
1917
+ children: /* @__PURE__ */ jsx(IconArrowsTransferDown, { className: "icon" })
1918
+ }) })
1919
+ ] })
1920
+ })
1921
+ ]
1922
+ }, id);
1923
+ });
1924
+ let t7;
1925
+ if ($[7] !== rootId || $[8] !== rootRef || $[9] !== t4.table || $[10] !== t6) {
1926
+ t7 = /* @__PURE__ */ jsx("div", {
1927
+ className: t4.table,
1928
+ ref: rootRef,
1929
+ id: rootId,
1930
+ children: t6
1931
+ });
1932
+ $[7] = rootId;
1933
+ $[8] = rootRef;
1934
+ $[9] = t4.table;
1935
+ $[10] = t6;
1936
+ $[11] = t7;
1937
+ } else t7 = $[11];
1938
+ return t7;
1939
+ }
1940
+ function _temp4(row_1) {
1941
+ return row_1.td;
1942
+ }
1943
+ function _temp3(row_0) {
1944
+ return row_0.th;
1945
+ }
1946
+ function _temp2(row) {
1947
+ return row.id;
1948
+ }
1949
+ function _temp$1() {
1950
+ return crypto.randomUUID();
1951
+ }
1952
+ var tabs_module_default = { tablist: "_tablist_1hyld_1" };
1953
+ // src/components/tabs.tsx
1954
+ /**
1955
+ * Controlled tab list. Selection is lifted to the parent via
1956
+ * `current`/`onChange`; tab buttons declare a local command instead of a
1957
+ * click handler. Arrow keys move the selection. The tab panel itself is
1958
+ * rendered by the parent, which also owns its `aria-label`.
1959
+ * @param root0
1960
+ * @param root0.current
1961
+ * @param root0.onChange
1962
+ * @param root0.contentId
1963
+ * @param root0.length
1964
+ * @param root0.createLabel
1965
+ * @example
1966
+ * ```tsx
1967
+ * <Tabs current={currentIndex} onChange={setCurrentIndex} contentId="tab-content" />
1968
+ * <div id="tab-content" role="tabpanel" aria-label={`画像${currentIndex + 1}`}>
1969
+ * {currentIndex === 0 ? <PcForm /> : <SpForm />}
1970
+ * </div>
1971
+ * ```
1972
+ */
1973
+ function Tabs({ current, onChange, contentId, length = 2, createLabel = (index) => `画像${index + 1}` }) {
1974
+ const listId = useId();
1975
+ const refs = useRef([]);
1976
+ const update = (index_0) => {
1977
+ refs.current[index_0]?.focus();
1978
+ onChange(index_0);
1979
+ };
1980
+ const rootRef = useCommand({ "--select-tab": (e) => {
1981
+ const value = e.source?.value;
1982
+ update(Number(value));
1983
+ } });
1984
+ const onKeyDown = (event) => {
1985
+ if (event.key === "ArrowLeft") update(Math.max(0, current - 1));
1986
+ else if (event.key === "ArrowRight") update(Math.min(length - 1, current + 1));
1987
+ };
1988
+ return /* @__PURE__ */ jsx("div", {
1989
+ role: "tablist",
1990
+ ref: rootRef,
1991
+ id: listId,
1992
+ className: tabs_module_default["tablist"],
1993
+ children: Array.from({ length }, (_, index_1) => /* @__PURE__ */ jsx("button", {
1994
+ ref: (el) => {
1995
+ refs.current[index_1] = el;
1996
+ },
1997
+ type: "button",
1998
+ role: "tab",
1999
+ "aria-controls": contentId,
2000
+ "aria-selected": current === index_1,
2001
+ tabIndex: current === index_1 ? 0 : -1,
2002
+ command: "--select-tab",
2003
+ commandfor: listId,
2004
+ value: index_1,
2005
+ onKeyDown,
2006
+ children: createLabel(index_1)
2007
+ }, index_1))
2008
+ });
2009
+ }
2010
+ var thumbnail_button_module_default = {
2011
+ button: "_button_fs9jb_4",
2012
+ image: "_image_fs9jb_3",
2013
+ placeholder: "_placeholder_fs9jb_23",
2014
+ "tabler-icon": "_tabler-icon_fs9jb_36",
2015
+ label: "_label_fs9jb_44"
2016
+ };
2017
+ // src/components/thumbnail-button.tsx
2018
+ /**
2019
+ * Thumbnail that is itself a button. Pressing it invokes `command` on the
2020
+ * `commandfor` target (like every other button in the editor UI, no click
2021
+ * handler). The `label` is hidden until the pointer hovers it or it gets
2022
+ * keyboard focus, so the thumbnail stays uncluttered but the action is
2023
+ * discoverable.
2024
+ *
2025
+ * An empty `src` renders a placeholder of the same size, so a row of
2026
+ * thumbnails keeps its layout while some of them have no file yet.
2027
+ *
2028
+ * `aria-label` is the accessible name. It must contain `label` and say what
2029
+ * the button acts on, since several of these buttons sit side by side.
2030
+ * @param root0
2031
+ * @param root0.src - File URL to preview; empty for "no file yet"
2032
+ * @param root0.label - Text shown on hover / focus (e.g. `編集`)
2033
+ * @param root0.command - Command name invoked on the `commandfor` target (a custom `--`-prefixed command or a built-in one)
2034
+ * @param root0.commandfor - The id of the element that receives the command; it must be in the same document as the button
2035
+ * @param root0.value - Passed to the command handler as `source.value`
2036
+ * @example
2037
+ * ```tsx
2038
+ * <ThumbnailButton
2039
+ * src={slide.path}
2040
+ * label="編集"
2041
+ * aria-label={`スライド${index + 1}を編集`}
2042
+ * command="--edit-slide"
2043
+ * commandfor={rootId}
2044
+ * value={String(index)}
2045
+ * />
2046
+ * ```
2047
+ */
2048
+ function ThumbnailButton(t0) {
2049
+ const $ = c(11);
2050
+ const { src, label, "aria-label": ariaLabel, command, commandfor, value } = t0;
2051
+ let t1;
2052
+ if ($[0] !== src) {
2053
+ t1 = /* @__PURE__ */ jsx("span", {
2054
+ className: thumbnail_button_module_default.image,
2055
+ children: src ? /* @__PURE__ */ jsx(Thumbnail, { src }) : /* @__PURE__ */ jsxs("span", {
2056
+ className: thumbnail_button_module_default.placeholder,
2057
+ "data-bge-thumbnail-placeholder": "",
2058
+ children: [/* @__PURE__ */ jsx(IconPhoto, { "aria-hidden": "true" }), /* @__PURE__ */ jsx("span", { children: "画像未選択" })]
2059
+ })
2060
+ });
2061
+ $[0] = src;
2062
+ $[1] = t1;
2063
+ } else t1 = $[1];
2064
+ let t2;
2065
+ if ($[2] !== label) {
2066
+ t2 = /* @__PURE__ */ jsx("span", {
2067
+ className: thumbnail_button_module_default.label,
2068
+ "aria-hidden": "true",
2069
+ children: label
2070
+ });
2071
+ $[2] = label;
2072
+ $[3] = t2;
2073
+ } else t2 = $[3];
2074
+ let t3;
2075
+ if ($[4] !== ariaLabel || $[5] !== command || $[6] !== commandfor || $[7] !== t1 || $[8] !== t2 || $[9] !== value) {
2076
+ t3 = /* @__PURE__ */ jsxs("button", {
2077
+ type: "button",
2078
+ className: thumbnail_button_module_default.button,
2079
+ "aria-label": ariaLabel,
2080
+ command,
2081
+ commandfor,
2082
+ value,
2083
+ children: [t1, t2]
2084
+ });
2085
+ $[4] = ariaLabel;
2086
+ $[5] = command;
2087
+ $[6] = commandfor;
2088
+ $[7] = t1;
2089
+ $[8] = t2;
2090
+ $[9] = value;
2091
+ $[10] = t3;
2092
+ } else t3 = $[10];
2093
+ return t3;
2094
+ }
2095
+ // src/components/wysiwyg-field.tsx
2096
+ /**
2097
+ * Wrap `promise` so a rejection resolves to `fallback` instead, without
2098
+ * breaking the `use()` cache contract (react.dev's `wrapPromise` pattern:
2099
+ * a thenable tagged with `.status`/`.value`/`.reason` lets `use()` read it
2100
+ * synchronously on the first render). `Promise.prototype.catch()` always
2101
+ * returns a fresh, untagged promise, so chaining it directly onto an
2102
+ * already-tagged thenable would silently drop that fast path. A tagged
2103
+ * `'fulfilled'` promise is returned as-is (nothing to fall back from); a
2104
+ * tagged `'rejected'` promise is converted synchronously; only a genuinely
2105
+ * untagged promise falls back to the real async `.catch()`.
2106
+ * @param promise - Source promise, optionally pre-tagged per the `use()`
2107
+ * cache contract
2108
+ * @param fallback - Value to resolve to when `promise` rejects
2109
+ */
2110
+ function withFallback(promise, fallback) {
2111
+ const tagged = promise;
2112
+ if (tagged.status === "fulfilled") return promise;
2113
+ if (tagged.status === "rejected") {
2114
+ const resolved = Promise.resolve(fallback);
2115
+ resolved.status = "fulfilled";
2116
+ resolved.value = fallback;
2117
+ return resolved;
2118
+ }
2119
+ return promise.catch(() => fallback);
2120
+ }
2121
+ /**
2122
+ * Rich text field backed by the `<bge-wysiwyg-editor>` custom element
2123
+ * (TipTap). The element manages its own DOM; this wrapper feeds the
2124
+ * initial value and lifts edits into the editor state via the
2125
+ * `transaction` event — subscribed directly on the host element (the
2126
+ * event is dispatched with `bubbles: true` on the inner `<bge-wysiwyg>`,
2127
+ * so it reaches here without needing to query into it).
2128
+ *
2129
+ * Content CSS (so the WYSIWYG surface matches the published page's
2130
+ * styling) is fetched once per engine via `use()` — only an item whose
2131
+ * `Editor` actually renders `WysiwygField` pays for this fetch/suspend,
2132
+ * unlike hoisting it to the item-editor host for every item — and
2133
+ * passed as the `contentCss` property (React 19 sets it directly on the
2134
+ * element, replacing an imperative `el.setStyle()` call).
2135
+ * @param root0
2136
+ * @param root0.value
2137
+ * @param root0.onChange
2138
+ * @param root0.itemName
2139
+ * @param root0.commands
2140
+ * @param root0.label
2141
+ * @example
2142
+ * ```tsx
2143
+ * <WysiwygField
2144
+ * itemName="wysiwyg"
2145
+ * value={state.wysiwyg ?? ''}
2146
+ * onChange={(wysiwyg) => setState({ ...state, wysiwyg })}
2147
+ * />
2148
+ * ```
2149
+ */
2150
+ function WysiwygField(t0) {
2151
+ const $ = c(13);
2152
+ const { value, onChange, itemName, commands, label } = t0;
2153
+ const engine = useEngine();
2154
+ let t1;
2155
+ if ($[0] !== engine) {
2156
+ t1 = () => withFallback(engine.getContentStylesheet(), "");
2157
+ $[0] = engine;
2158
+ $[1] = t1;
2159
+ } else t1 = $[1];
2160
+ const [contentCssPromise] = useState(t1);
2161
+ const contentCss = use(contentCssPromise);
2162
+ const ref = useRef(null);
2163
+ const initialValue = useRef(value);
2164
+ let t2;
2165
+ if ($[2] !== onChange) {
2166
+ t2 = (el) => {
2167
+ onChange(el.value);
2168
+ };
2169
+ $[2] = onChange;
2170
+ $[3] = t2;
2171
+ } else t2 = $[3];
2172
+ const onTransaction = useEffectEvent(t2);
2173
+ let t3;
2174
+ if ($[4] !== onTransaction) {
2175
+ t3 = () => {
2176
+ const el_0 = ref.current;
2177
+ if (!el_0) return;
2178
+ el_0.innerHTML = initialValue.current;
2179
+ const listener = () => onTransaction(el_0);
2180
+ el_0.addEventListener("transaction", listener);
2181
+ return () => {
2182
+ el_0.removeEventListener("transaction", listener);
2183
+ };
2184
+ };
2185
+ $[4] = onTransaction;
2186
+ $[5] = t3;
2187
+ } else t3 = $[5];
2188
+ let t4;
2189
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
2190
+ t4 = [];
2191
+ $[6] = t4;
2192
+ } else t4 = $[6];
2193
+ useEffect(t3, t4);
2194
+ let t5;
2195
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
2196
+ t5 = (el_1) => {
2197
+ ref.current = el_1;
2198
+ };
2199
+ $[7] = t5;
2200
+ } else t5 = $[7];
2201
+ let t6;
2202
+ if ($[8] !== commands || $[9] !== contentCss || $[10] !== itemName || $[11] !== label) {
2203
+ t6 = /* @__PURE__ */ jsx("bge-wysiwyg-editor", {
2204
+ ref: t5,
2205
+ contentCss,
2206
+ "item-name": itemName,
2207
+ commands,
2208
+ label
2209
+ });
2210
+ $[8] = commands;
2211
+ $[9] = contentCss;
2212
+ $[10] = itemName;
2213
+ $[11] = label;
2214
+ $[12] = t6;
2215
+ } else t6 = $[12];
2216
+ return t6;
2217
+ }
2218
+ // src/use-mount-effect.ts
2219
+ /**
2220
+ * Run `fn` exactly once, when the component mounts, always reading `fn`'s
2221
+ * latest closure (via `useEffectEvent`) rather than the one captured at
2222
+ * mount time.
2223
+ *
2224
+ * Exists so a mount-only effect can honestly declare `useEffect(fn, [])`
2225
+ * without an `eslint-disable-next-line react-hooks/exhaustive-deps` — that
2226
+ * suppression is also a React Compiler bailout condition for the whole
2227
+ * component containing it (see ARCHITECTURE.md's negative-knowledge note
2228
+ * on React Compiler).
2229
+ * @param fn - Called once on mount
2230
+ * @example
2231
+ * ```tsx
2232
+ * useMountEffect(() => {
2233
+ * fileBrowser.select(fileType, state.path ?? '', size);
2234
+ * });
2235
+ * ```
2236
+ */
2237
+ function useMountEffect(fn) {
2238
+ const $ = c(3);
2239
+ const onMount = useEffectEvent(fn);
2240
+ let t0;
2241
+ if ($[0] !== onMount) {
2242
+ t0 = () => {
2243
+ onMount();
2244
+ };
2245
+ $[0] = onMount;
2246
+ $[1] = t0;
2247
+ } else t0 = $[1];
2248
+ let t1;
2249
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
2250
+ t1 = [];
2251
+ $[2] = t1;
2252
+ } else t1 = $[2];
2253
+ useEffect(t0, t1);
2254
+ }
2255
+ // src/file-browser/use-external-file-selection.ts
2256
+ /**
2257
+ * React to a file becoming selected from outside the item's own `Editor`
2258
+ * (i.e. via `FileList`, in the same `FileBrowserStore` the item's own
2259
+ * `fileType` uses) — `onExternalChange` is called with the new selection.
2260
+ *
2261
+ * `selected` is shared per-engine across every item that opens onto the
2262
+ * same `fileType`, so it can still hold a *previous* item's selection at
2263
+ * the moment a new `Editor` instance mounts. This hook's first effect run
2264
+ * is always skipped for that reason — reacting to it would load that
2265
+ * stale, unrelated selection into the freshly-mounted item's own state,
2266
+ * racing the item's own mount-time `fileBrowser.select(fileType, ownPath)`
2267
+ * call (whichever one's async work — if any — finishes last wins,
2268
+ * corrupting the item with a different item's file). Callers still need
2269
+ * their own mount effect to register their own current path with the
2270
+ * store; this hook only covers reacting to *later* external changes.
2271
+ * @param selected - The `fileType`'s current selection (from
2272
+ * `useSyncExternalStore(fileBrowser.subscribe, () =>
2273
+ * fileBrowser.getSnapshot().selected[fileType])`)
2274
+ * @param getCurrentPath - Returns the item's own current path at call
2275
+ * time (a function, not a plain value, so the effect doesn't need it in
2276
+ * its dependency array and can stay `[selected]`-only)
2277
+ * @param onExternalChange - Called when `selected` changes to a path
2278
+ * different from `getCurrentPath()`, after the initial mount is skipped
2279
+ * @example
2280
+ * ```tsx
2281
+ * const selected = useSyncExternalStore(
2282
+ * fileBrowser.subscribe,
2283
+ * () => fileBrowser.getSnapshot().selected.image,
2284
+ * );
2285
+ * useExternalFileSelection(
2286
+ * selected,
2287
+ * () => state.path ?? '',
2288
+ * (next) => setState((prev) => ({ ...prev, path: next.path })),
2289
+ * );
2290
+ * ```
2291
+ */
2292
+ function useExternalFileSelection(selected, getCurrentPath, onExternalChange) {
2293
+ const $ = c(8);
2294
+ const skipNextRun = useRef(true);
2295
+ let t0;
2296
+ if ($[0] !== getCurrentPath || $[1] !== onExternalChange || $[2] !== selected) {
2297
+ t0 = () => {
2298
+ if (skipNextRun.current) {
2299
+ skipNextRun.current = false;
2300
+ return;
2301
+ }
2302
+ if (!selected?.path || selected.path === getCurrentPath()) return;
2303
+ onExternalChange(selected);
2304
+ };
2305
+ $[0] = getCurrentPath;
2306
+ $[1] = onExternalChange;
2307
+ $[2] = selected;
2308
+ $[3] = t0;
2309
+ } else t0 = $[3];
2310
+ const handleSelectedChange = useEffectEvent(t0);
2311
+ let t1;
2312
+ if ($[4] !== handleSelectedChange) {
2313
+ t1 = () => {
2314
+ handleSelectedChange();
2315
+ };
2316
+ $[4] = handleSelectedChange;
2317
+ $[5] = t1;
2318
+ } else t1 = $[5];
2319
+ let t2;
2320
+ if ($[6] !== selected) {
2321
+ t2 = [selected];
2322
+ $[6] = selected;
2323
+ $[7] = t2;
2324
+ } else t2 = $[7];
2325
+ useEffect(t1, t2);
2326
+ }
2327
+ // src/form/checkbox.tsx
2328
+ /**
2329
+ * Controlled checkbox following the editor form markup convention
2330
+ * (`label > input + text`).
2331
+ *
2332
+ * The structure is a styling contract: `ui.css` turns
2333
+ * `label:not([for]):has(input[type='checkbox'])` into a flex row, so it
2334
+ * must be preserved.
2335
+ * @param root0
2336
+ * @param root0.label
2337
+ * @param root0.checked
2338
+ * @param root0.onChange
2339
+ * @param root0.name
2340
+ * @param root0.disabled
2341
+ * @param root0.describedBy
2342
+ * @example
2343
+ * ```tsx
2344
+ * <Checkbox
2345
+ * label={<span>横スクロール可能</span>}
2346
+ * name="bge-scrollable"
2347
+ * checked={state.scrollable ?? false}
2348
+ * onChange={(scrollable) => setState({ ...state, scrollable })}
2349
+ * />
2350
+ * ```
2351
+ */
2352
+ function Checkbox(t0) {
2353
+ const $ = c(11);
2354
+ const { label, checked, onChange, name, disabled, describedBy } = t0;
2355
+ let t1;
2356
+ if ($[0] !== onChange) {
2357
+ t1 = (e) => onChange(e.currentTarget.checked);
2358
+ $[0] = onChange;
2359
+ $[1] = t1;
2360
+ } else t1 = $[1];
2361
+ let t2;
2362
+ if ($[2] !== checked || $[3] !== describedBy || $[4] !== disabled || $[5] !== name || $[6] !== t1) {
2363
+ t2 = /* @__PURE__ */ jsx("input", {
2364
+ type: "checkbox",
2365
+ name,
2366
+ checked,
2367
+ disabled,
2368
+ "aria-describedby": describedBy,
2369
+ onChange: t1
2370
+ });
2371
+ $[2] = checked;
2372
+ $[3] = describedBy;
2373
+ $[4] = disabled;
2374
+ $[5] = name;
2375
+ $[6] = t1;
2376
+ $[7] = t2;
2377
+ } else t2 = $[7];
2378
+ let t3;
2379
+ if ($[8] !== label || $[9] !== t2) {
2380
+ t3 = /* @__PURE__ */ jsxs("label", { children: [t2, label] });
2381
+ $[8] = label;
2382
+ $[9] = t2;
2383
+ $[10] = t3;
2384
+ } else t3 = $[10];
2385
+ return t3;
2386
+ }
2387
+ // src/form/fieldset.tsx
2388
+ /**
2389
+ * Grouping fieldset following the editor form markup convention
2390
+ * (`fieldset > legend`).
2391
+ *
2392
+ * The structure is a styling contract: `ui.css` draws the group border
2393
+ * and spacing on the `fieldset` element itself, so it must be preserved.
2394
+ * @param root0
2395
+ * @param root0.legend
2396
+ * @param root0.id
2397
+ * @param root0.disabled
2398
+ * @param root0.children
2399
+ * @example
2400
+ * ```tsx
2401
+ * <Fieldset legend="リンク設定" disabled={!state.useLink}>
2402
+ * <TextField
2403
+ * label="URL"
2404
+ * name="bge-href"
2405
+ * value={state.href ?? ''}
2406
+ * onChange={(href) => setState({ ...state, href })}
2407
+ * />
2408
+ * </Fieldset>
2409
+ * ```
2410
+ */
2411
+ function Fieldset(t0) {
2412
+ const $ = c(7);
2413
+ const { legend, id, disabled, children } = t0;
2414
+ let t1;
2415
+ if ($[0] !== legend) {
2416
+ t1 = /* @__PURE__ */ jsx("legend", { children: legend });
2417
+ $[0] = legend;
2418
+ $[1] = t1;
2419
+ } else t1 = $[1];
2420
+ let t2;
2421
+ if ($[2] !== children || $[3] !== disabled || $[4] !== id || $[5] !== t1) {
2422
+ t2 = /* @__PURE__ */ jsxs("fieldset", {
2423
+ id,
2424
+ disabled,
2425
+ children: [t1, children]
2426
+ });
2427
+ $[2] = children;
2428
+ $[3] = disabled;
2429
+ $[4] = id;
2430
+ $[5] = t1;
2431
+ $[6] = t2;
2432
+ } else t2 = $[6];
2433
+ return t2;
2434
+ }
2435
+ // src/form/number-field.tsx
2436
+ /**
2437
+ * Controlled numeric input following the editor form markup convention.
2438
+ *
2439
+ * The `label > span + input` structure is a styling contract: `ui.css`
2440
+ * lays out fields with structural selectors
2441
+ * (`label:not([for]) > span:has(+ input)`), so it must be preserved.
2442
+ * @param root0
2443
+ * @param root0.label
2444
+ * @param root0.value
2445
+ * @param root0.onChange
2446
+ * @param root0.name
2447
+ * @param root0.min
2448
+ * @param root0.max
2449
+ * @param root0.step
2450
+ * @param root0.disabled
2451
+ * @example
2452
+ * ```tsx
2453
+ * <NumberField
2454
+ * label="表示件数"
2455
+ * name="bge-count"
2456
+ * value={state.count ?? 1}
2457
+ * min={1}
2458
+ * onChange={(count) => setState({ ...state, count })}
2459
+ * />
2460
+ * ```
2461
+ */
2462
+ function NumberField(t0) {
2463
+ const $ = c(15);
2464
+ const { label, value, onChange, name, min, max, step, disabled } = t0;
2465
+ let t1;
2466
+ if ($[0] !== label) {
2467
+ t1 = /* @__PURE__ */ jsx("span", { children: label });
2468
+ $[0] = label;
2469
+ $[1] = t1;
2470
+ } else t1 = $[1];
2471
+ const t2 = Number.isFinite(value) ? value : "";
2472
+ let t3;
2473
+ if ($[2] !== onChange) {
2474
+ t3 = (e) => onChange(e.currentTarget.valueAsNumber);
2475
+ $[2] = onChange;
2476
+ $[3] = t3;
2477
+ } else t3 = $[3];
2478
+ let t4;
2479
+ if ($[4] !== disabled || $[5] !== max || $[6] !== min || $[7] !== name || $[8] !== step || $[9] !== t2 || $[10] !== t3) {
2480
+ t4 = /* @__PURE__ */ jsx("input", {
2481
+ type: "number",
2482
+ name,
2483
+ value: t2,
2484
+ min,
2485
+ max,
2486
+ step,
2487
+ disabled,
2488
+ onChange: t3
2489
+ });
2490
+ $[4] = disabled;
2491
+ $[5] = max;
2492
+ $[6] = min;
2493
+ $[7] = name;
2494
+ $[8] = step;
2495
+ $[9] = t2;
2496
+ $[10] = t3;
2497
+ $[11] = t4;
2498
+ } else t4 = $[11];
2499
+ let t5;
2500
+ if ($[12] !== t1 || $[13] !== t4) {
2501
+ t5 = /* @__PURE__ */ jsxs("label", { children: [t1, t4] });
2502
+ $[12] = t1;
2503
+ $[13] = t4;
2504
+ $[14] = t5;
2505
+ } else t5 = $[14];
2506
+ return t5;
2507
+ }
2508
+ // src/form/radio-group.tsx
2509
+ /**
2510
+ * Controlled radio group following the editor form markup convention
2511
+ * (`div[role=radiogroup] > label > input + text`).
2512
+ *
2513
+ * The structure is a styling contract: `ui.css` lays out the group via
2514
+ * `[role='radiogroup'] > label` (and appends `:` to the group label), so
2515
+ * it must be preserved.
2516
+ * @param root0
2517
+ * @param root0.label
2518
+ * @param root0.value
2519
+ * @param root0.onChange
2520
+ * @param root0.options
2521
+ * @param root0.name
2522
+ * @param root0.disabled
2523
+ * @example
2524
+ * ```tsx
2525
+ * <RadioGroup
2526
+ * label="配置"
2527
+ * name="bge-align"
2528
+ * value={state.align ?? 'start'}
2529
+ * options={[
2530
+ * { value: 'start', label: '左寄せ' },
2531
+ * { value: 'end', label: '右寄せ' },
2532
+ * ]}
2533
+ * onChange={(align) => setState({ ...state, align })}
2534
+ * />
2535
+ * ```
2536
+ */
2537
+ function RadioGroup(t0) {
2538
+ const $ = c(18);
2539
+ const { label, value, onChange, options, name, disabled } = t0;
2540
+ const labelId = useId();
2541
+ let t1;
2542
+ if ($[0] !== label || $[1] !== labelId) {
2543
+ t1 = /* @__PURE__ */ jsx("div", {
2544
+ id: labelId,
2545
+ children: label
2546
+ });
2547
+ $[0] = label;
2548
+ $[1] = labelId;
2549
+ $[2] = t1;
2550
+ } else t1 = $[2];
2551
+ let t2;
2552
+ if ($[3] !== disabled || $[4] !== name || $[5] !== onChange || $[6] !== options || $[7] !== value) {
2553
+ let t3;
2554
+ if ($[9] !== disabled || $[10] !== name || $[11] !== onChange || $[12] !== value) {
2555
+ t3 = (option) => /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
2556
+ type: "radio",
2557
+ name,
2558
+ value: option.value,
2559
+ checked: value === option.value,
2560
+ disabled,
2561
+ onChange: (e) => {
2562
+ if (e.currentTarget.checked) onChange(option.value);
2563
+ }
2564
+ }), option.label] }, option.value);
2565
+ $[9] = disabled;
2566
+ $[10] = name;
2567
+ $[11] = onChange;
2568
+ $[12] = value;
2569
+ $[13] = t3;
2570
+ } else t3 = $[13];
2571
+ t2 = options.map(t3);
2572
+ $[3] = disabled;
2573
+ $[4] = name;
2574
+ $[5] = onChange;
2575
+ $[6] = options;
2576
+ $[7] = value;
2577
+ $[8] = t2;
2578
+ } else t2 = $[8];
2579
+ let t3;
2580
+ if ($[14] !== labelId || $[15] !== t1 || $[16] !== t2) {
2581
+ t3 = /* @__PURE__ */ jsxs("div", {
2582
+ role: "radiogroup",
2583
+ "aria-labelledby": labelId,
2584
+ children: [t1, t2]
2585
+ });
2586
+ $[14] = labelId;
2587
+ $[15] = t1;
2588
+ $[16] = t2;
2589
+ $[17] = t3;
2590
+ } else t3 = $[17];
2591
+ return t3;
2592
+ }
2593
+ // src/form/select-field.tsx
2594
+ /**
2595
+ * Controlled select following the editor form markup convention
2596
+ * (`label > span + select`).
2597
+ *
2598
+ * The structure is a styling contract: `ui.css` lays out fields with
2599
+ * structural selectors (`label:not([for]) > span:has(+ select)`), so it
2600
+ * must be preserved.
2601
+ * @param root0
2602
+ * @param root0.label
2603
+ * @param root0.value
2604
+ * @param root0.onChange
2605
+ * @param root0.options
2606
+ * @param root0.name
2607
+ * @param root0.disabled
2608
+ * @param root0.describedBy - The ID of the element that describes the select
2609
+ * (for example, why it is disabled), wired through `aria-describedby`.
2610
+ * @example
2611
+ * ```tsx
2612
+ * <SelectField
2613
+ * label="種類"
2614
+ * name="bge-kind"
2615
+ * value={state.kind ?? 'normal'}
2616
+ * options={[
2617
+ * { value: 'normal', label: '通常' },
2618
+ * { value: 'wide', label: 'ワイド' },
2619
+ * ]}
2620
+ * onChange={(kind) => setState({ ...state, kind })}
2621
+ * />
2622
+ * ```
2623
+ */
2624
+ function SelectField(t0) {
2625
+ const $ = c(16);
2626
+ const { label, value, onChange, options, name, disabled, describedBy } = t0;
2627
+ let t1;
2628
+ if ($[0] !== label) {
2629
+ t1 = /* @__PURE__ */ jsx("span", { children: label });
2630
+ $[0] = label;
2631
+ $[1] = t1;
2632
+ } else t1 = $[1];
2633
+ let t2;
2634
+ if ($[2] !== onChange) {
2635
+ t2 = (e) => onChange(e.currentTarget.value);
2636
+ $[2] = onChange;
2637
+ $[3] = t2;
2638
+ } else t2 = $[3];
2639
+ let t3;
2640
+ if ($[4] !== options) {
2641
+ t3 = options.map(_temp);
2642
+ $[4] = options;
2643
+ $[5] = t3;
2644
+ } else t3 = $[5];
2645
+ let t4;
2646
+ if ($[6] !== describedBy || $[7] !== disabled || $[8] !== name || $[9] !== t2 || $[10] !== t3 || $[11] !== value) {
2647
+ t4 = /* @__PURE__ */ jsx("select", {
2648
+ name,
2649
+ value,
2650
+ disabled,
2651
+ "aria-describedby": describedBy,
2652
+ onChange: t2,
2653
+ children: t3
2654
+ });
2655
+ $[6] = describedBy;
2656
+ $[7] = disabled;
2657
+ $[8] = name;
2658
+ $[9] = t2;
2659
+ $[10] = t3;
2660
+ $[11] = value;
2661
+ $[12] = t4;
2662
+ } else t4 = $[12];
2663
+ let t5;
2664
+ if ($[13] !== t1 || $[14] !== t4) {
2665
+ t5 = /* @__PURE__ */ jsxs("label", { children: [t1, t4] });
2666
+ $[13] = t1;
2667
+ $[14] = t4;
2668
+ $[15] = t5;
2669
+ } else t5 = $[15];
2670
+ return t5;
2671
+ }
2672
+ function _temp(option) {
2673
+ return /* @__PURE__ */ jsx("option", {
2674
+ value: option.value,
2675
+ children: option.label
2676
+ }, option.value);
2677
+ }
2678
+ // src/form/text-area.tsx
2679
+ /**
2680
+ * Controlled multi-line text input following the editor form markup
2681
+ * convention.
2682
+ *
2683
+ * The `label > span + textarea` structure is a styling contract: `ui.css`
2684
+ * lays out fields with structural selectors
2685
+ * (`label:not([for]) > span:has(+ textarea)`), so it must be preserved.
2686
+ * @param root0
2687
+ * @param root0.label
2688
+ * @param root0.value
2689
+ * @param root0.onChange
2690
+ * @param root0.name
2691
+ * @param root0.rows
2692
+ * @param root0.disabled
2693
+ * @example
2694
+ * ```tsx
2695
+ * <TextArea
2696
+ * label="説明文"
2697
+ * name="bge-text"
2698
+ * value={state.text ?? ''}
2699
+ * onChange={(text) => setState({ ...state, text })}
2700
+ * />
2701
+ * ```
2702
+ */
2703
+ function TextArea(t0) {
2704
+ const $ = c(13);
2705
+ const { label, value, onChange, name, rows, disabled } = t0;
2706
+ let t1;
2707
+ if ($[0] !== label) {
2708
+ t1 = /* @__PURE__ */ jsx("span", { children: label });
2709
+ $[0] = label;
2710
+ $[1] = t1;
2711
+ } else t1 = $[1];
2712
+ let t2;
2713
+ if ($[2] !== onChange) {
2714
+ t2 = (e) => onChange(e.currentTarget.value);
2715
+ $[2] = onChange;
2716
+ $[3] = t2;
2717
+ } else t2 = $[3];
2718
+ let t3;
2719
+ if ($[4] !== disabled || $[5] !== name || $[6] !== rows || $[7] !== t2 || $[8] !== value) {
2720
+ t3 = /* @__PURE__ */ jsx("textarea", {
2721
+ name,
2722
+ value,
2723
+ rows,
2724
+ disabled,
2725
+ onChange: t2
2726
+ });
2727
+ $[4] = disabled;
2728
+ $[5] = name;
2729
+ $[6] = rows;
2730
+ $[7] = t2;
2731
+ $[8] = value;
2732
+ $[9] = t3;
2733
+ } else t3 = $[9];
2734
+ let t4;
2735
+ if ($[10] !== t1 || $[11] !== t3) {
2736
+ t4 = /* @__PURE__ */ jsxs("label", { children: [t1, t3] });
2737
+ $[10] = t1;
2738
+ $[11] = t3;
2739
+ $[12] = t4;
2740
+ } else t4 = $[12];
2741
+ return t4;
2742
+ }
2743
+ // src/form/text-field.tsx
2744
+ /**
2745
+ * Controlled single-line text input following the editor form markup
2746
+ * convention (`label > span + input`).
2747
+ *
2748
+ * The structure is a styling contract: `ui.css` lays out fields with
2749
+ * structural selectors (`label:not([for]) > span:has(+ input)`) instead
2750
+ * of `for`/`id` wiring, so it must be preserved.
2751
+ * @param root0
2752
+ * @param root0.label
2753
+ * @param root0.value
2754
+ * @param root0.onChange
2755
+ * @param root0.type
2756
+ * @param root0.name
2757
+ * @param root0.disabled
2758
+ * @param root0.placeholder
2759
+ * @param root0.describedBy
2760
+ * @param root0.required - Marks the field as required for assistive
2761
+ * technology via `aria-required`. The native `required` attribute is not
2762
+ * used: `type` is dynamic here, so markup linting cannot tell it is valid.
2763
+ * The dialog form is `noValidate`, so the browser never blocks submission;
2764
+ * the item's `toItemData` is what rejects an empty value.
2765
+ * @param root0.onBlur - Called when focus leaves the input. Use it to
2766
+ * normalize a value (for example, to restore a default when the field was
2767
+ * left empty) once the user has finished typing, not on every keystroke.
2768
+ * @example
2769
+ * ```tsx
2770
+ * <TextField
2771
+ * label="URL"
2772
+ * name="bge-link"
2773
+ * value={state.href ?? ''}
2774
+ * onChange={(href) => setState({ ...state, href })}
2775
+ * />
2776
+ * ```
2777
+ */
2778
+ function TextField(t0) {
2779
+ const $ = c(17);
2780
+ const { label, value, onChange, type: t1, name, disabled, placeholder, describedBy, required, onBlur } = t0;
2781
+ const type = t1 === void 0 ? "text" : t1;
2782
+ let t2;
2783
+ if ($[0] !== label) {
2784
+ t2 = /* @__PURE__ */ jsx("span", { children: label });
2785
+ $[0] = label;
2786
+ $[1] = t2;
2787
+ } else t2 = $[1];
2788
+ const t3 = required || void 0;
2789
+ let t4;
2790
+ if ($[2] !== onChange) {
2791
+ t4 = (e) => onChange(e.currentTarget.value);
2792
+ $[2] = onChange;
2793
+ $[3] = t4;
2794
+ } else t4 = $[3];
2795
+ let t5;
2796
+ if ($[4] !== describedBy || $[5] !== disabled || $[6] !== name || $[7] !== onBlur || $[8] !== placeholder || $[9] !== t3 || $[10] !== t4 || $[11] !== type || $[12] !== value) {
2797
+ t5 = /* @__PURE__ */ jsx("input", {
2798
+ type,
2799
+ name,
2800
+ value,
2801
+ disabled,
2802
+ "aria-required": t3,
2803
+ placeholder,
2804
+ "aria-describedby": describedBy,
2805
+ onChange: t4,
2806
+ onBlur
2807
+ });
2808
+ $[4] = describedBy;
2809
+ $[5] = disabled;
2810
+ $[6] = name;
2811
+ $[7] = onBlur;
2812
+ $[8] = placeholder;
2813
+ $[9] = t3;
2814
+ $[10] = t4;
2815
+ $[11] = type;
2816
+ $[12] = value;
2817
+ $[13] = t5;
2818
+ } else t5 = $[13];
2819
+ let t6;
2820
+ if ($[14] !== t2 || $[15] !== t5) {
2821
+ t6 = /* @__PURE__ */ jsxs("label", { children: [t2, t5] });
2822
+ $[14] = t2;
2823
+ $[15] = t5;
2824
+ $[16] = t6;
2825
+ } else t6 = $[16];
2826
+ return t6;
2827
+ }
2828
+ export { BGE_BLOCK_MENU_BLOCK_ANCHOR, BlockCatalog, BlockMenu, BlockMenuButton, BlockMenuView, BlockOptions, Checkbox, DraftSwitcher, EditableAreaView, EditorDialog, EngineProvider, Fieldset, FileList, FileUploader, FrontMatterEditorView, FrontMatterStore, InitialInsertionButton, ItemEditorHost, NumberField, Preview, RadioGroup, RootErrorBoundary, SelectField, TableEditor, Tabs, TextArea, TextField, Thumbnail, ThumbnailButton, WysiwygField, createFrontMatterEditor, reactMount, registerEngineCommands, reportRenderError, useCommand, useEngine, useExternalFileSelection, useFileBrowser, useMountEffect, useUIState };
2829
+
2830
+ //# sourceMappingURL=ui.js.map