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

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.
package/dist/ui.js CHANGED
@@ -1,989 +1,1632 @@
1
- import { useState, useId, useRef, Fragment, useEffect } from 'react';
2
- import { k as dayjs, l as createReactComponent, m as useComponentEvent, n as useCommand, o as IconRowInsertBottom, p as IconTrash } from './initial-insertion-button-DMGBvuDE.js';
3
- export { e as BlockCatalog, h as BlockMenu, q as BlockMenuButton, f as BlockOptions, D as DraftSwitcher, d as EditorDialog, i as InitialInsertionButton, g as ItemEditorHost, r as reactMount, j as registerEngineCommands, u as useUIState } from './initial-insertion-button-DMGBvuDE.js';
4
- import { jsx, jsxs } from 'react/jsx-runtime';
5
-
1
+ import { _ as IconRowInsertBottom, a as BlockMenuButton, b as formatByteSize, c as DraftSwitcher, d as useUIState, f as ItemEditorHost, g as IconTrash, h as BlockCatalog, i as BlockMenuView, l as registerEngineCommands, m as BlockOptions, n as InitialInsertionButton, o as useCommand, p as EditorDialog, r as BlockMenu, s as reactMount, t as EditableAreaView, u as useComponentEvent, v as createReactComponent, x as formatDate } from "./editable-area-view-C00DSDVk.js";
2
+ import { Fragment, useEffect, useId, useRef, useState } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { createRoot } from "react-dom/client";
6
5
  /**
7
- * 数値をバイトサイズ単位にフォーマットする
8
- * @param byteSize 対象の数値
9
- * @param digits 小数点の桁数
10
- * @param autoFormat SI接頭辞をつけるかどうか
11
- * @returns フォーマットされた文字列
12
- */
13
- function formatByteSize(byteSize, digits = 2, autoFormat = true) {
14
- let compute = byteSize;
15
- let counter = 0;
16
- const unit = ['byte', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB'];
17
- if (autoFormat) {
18
- while (compute > 1024) {
19
- compute /= 1024;
20
- counter += 1;
21
- }
22
- if (counter === 0) {
23
- digits = 0;
24
- }
25
- return compute.toFixed(digits) + unit[counter];
26
- }
27
- else {
28
- return byteSize + unit[0];
29
- }
30
- }
6
+ * @license @tabler/icons-react v3.46.0 - MIT
7
+ *
8
+ * This source code is licensed under the MIT license.
9
+ * See the LICENSE file in the root directory of this source tree.
10
+ */
11
+ var IconArrowsTransferDown = createReactComponent("outline", "arrows-transfer-down", "ArrowsTransferDown", [
12
+ ["path", {
13
+ "d": "M17 3v6",
14
+ "key": "svg-0"
15
+ }],
16
+ ["path", {
17
+ "d": "M10 18l-3 3l-3 -3",
18
+ "key": "svg-1"
19
+ }],
20
+ ["path", {
21
+ "d": "M7 21v-18",
22
+ "key": "svg-2"
23
+ }],
24
+ ["path", {
25
+ "d": "M20 6l-3 -3l-3 3",
26
+ "key": "svg-3"
27
+ }],
28
+ ["path", {
29
+ "d": "M17 21v-2",
30
+ "key": "svg-4"
31
+ }],
32
+ ["path", {
33
+ "d": "M17 15v-2",
34
+ "key": "svg-5"
35
+ }]
36
+ ]);
31
37
  /**
32
- * Unixタイムスタンプを日付文字列に変換する
33
- * @param timestamp Unixタイムスタンプ
34
- * @param format フォーマット
35
- */
36
- function formatDate(timestamp, format) {
37
- return dayjs.unix(timestamp).format(format);
38
- }
39
-
38
+ * @license @tabler/icons-react v3.46.0 - MIT
39
+ *
40
+ * This source code is licensed under the MIT license.
41
+ * See the LICENSE file in the root directory of this source tree.
42
+ */
43
+ var IconFileTypeDoc = createReactComponent("outline", "file-type-doc", "FileTypeDoc", [
44
+ ["path", {
45
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
46
+ "key": "svg-0"
47
+ }],
48
+ ["path", {
49
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
50
+ "key": "svg-1"
51
+ }],
52
+ ["path", {
53
+ "d": "M5 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1",
54
+ "key": "svg-2"
55
+ }],
56
+ ["path", {
57
+ "d": "M20 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0",
58
+ "key": "svg-3"
59
+ }],
60
+ ["path", {
61
+ "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",
62
+ "key": "svg-4"
63
+ }]
64
+ ]);
40
65
  /**
41
- * @license @tabler/icons-react v3.45.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
-
47
-
48
- const __iconNode$7 = [["path", { "d": "M17 3v6", "key": "svg-0" }], ["path", { "d": "M10 18l-3 3l-3 -3", "key": "svg-1" }], ["path", { "d": "M7 21v-18", "key": "svg-2" }], ["path", { "d": "M20 6l-3 -3l-3 3", "key": "svg-3" }], ["path", { "d": "M17 21v-2", "key": "svg-4" }], ["path", { "d": "M17 15v-2", "key": "svg-5" }]];
49
- const IconArrowsTransferDown = createReactComponent("outline", "arrows-transfer-down", "ArrowsTransferDown", __iconNode$7);
50
-
66
+ * @license @tabler/icons-react v3.46.0 - MIT
67
+ *
68
+ * This source code is licensed under the MIT license.
69
+ * See the LICENSE file in the root directory of this source tree.
70
+ */
71
+ var IconFileTypePdf = createReactComponent("outline", "file-type-pdf", "FileTypePdf", [
72
+ ["path", {
73
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
74
+ "key": "svg-0"
75
+ }],
76
+ ["path", {
77
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
78
+ "key": "svg-1"
79
+ }],
80
+ ["path", {
81
+ "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
82
+ "key": "svg-2"
83
+ }],
84
+ ["path", {
85
+ "d": "M17 18h2",
86
+ "key": "svg-3"
87
+ }],
88
+ ["path", {
89
+ "d": "M20 15h-3v6",
90
+ "key": "svg-4"
91
+ }],
92
+ ["path", {
93
+ "d": "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1",
94
+ "key": "svg-5"
95
+ }]
96
+ ]);
51
97
  /**
52
- * @license @tabler/icons-react v3.45.0 - MIT
53
- *
54
- * This source code is licensed under the MIT license.
55
- * See the LICENSE file in the root directory of this source tree.
56
- */
57
-
58
-
59
- const __iconNode$6 = [["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-0" }], ["path", { "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "key": "svg-1" }], ["path", { "d": "M5 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1", "key": "svg-2" }], ["path", { "d": "M20 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0", "key": "svg-3" }], ["path", { "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", "key": "svg-4" }]];
60
- const IconFileTypeDoc = createReactComponent("outline", "file-type-doc", "FileTypeDoc", __iconNode$6);
61
-
98
+ * @license @tabler/icons-react v3.46.0 - MIT
99
+ *
100
+ * This source code is licensed under the MIT license.
101
+ * See the LICENSE file in the root directory of this source tree.
102
+ */
103
+ var IconFileTypePpt = createReactComponent("outline", "file-type-ppt", "FileTypePpt", [
104
+ ["path", {
105
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
106
+ "key": "svg-0"
107
+ }],
108
+ ["path", {
109
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
110
+ "key": "svg-1"
111
+ }],
112
+ ["path", {
113
+ "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
114
+ "key": "svg-2"
115
+ }],
116
+ ["path", {
117
+ "d": "M11 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6",
118
+ "key": "svg-3"
119
+ }],
120
+ ["path", {
121
+ "d": "M16.5 15h3",
122
+ "key": "svg-4"
123
+ }],
124
+ ["path", {
125
+ "d": "M18 15v6",
126
+ "key": "svg-5"
127
+ }],
128
+ ["path", {
129
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
130
+ "key": "svg-6"
131
+ }]
132
+ ]);
62
133
  /**
63
- * @license @tabler/icons-react v3.45.0 - MIT
64
- *
65
- * This source code is licensed under the MIT license.
66
- * See the LICENSE file in the root directory of this source tree.
67
- */
68
-
69
-
70
- const __iconNode$5 = [["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-0" }], ["path", { "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "key": "svg-1" }], ["path", { "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6", "key": "svg-2" }], ["path", { "d": "M17 18h2", "key": "svg-3" }], ["path", { "d": "M20 15h-3v6", "key": "svg-4" }], ["path", { "d": "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1", "key": "svg-5" }]];
71
- const IconFileTypePdf = createReactComponent("outline", "file-type-pdf", "FileTypePdf", __iconNode$5);
72
-
73
- /**
74
- * @license @tabler/icons-react v3.45.0 - MIT
75
- *
76
- * This source code is licensed under the MIT license.
77
- * See the LICENSE file in the root directory of this source tree.
78
- */
79
-
80
-
81
- const __iconNode$4 = [["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-0" }], ["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-1" }], ["path", { "d": "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6", "key": "svg-2" }], ["path", { "d": "M11 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6", "key": "svg-3" }], ["path", { "d": "M16.5 15h3", "key": "svg-4" }], ["path", { "d": "M18 15v6", "key": "svg-5" }], ["path", { "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "key": "svg-6" }]];
82
- const IconFileTypePpt = createReactComponent("outline", "file-type-ppt", "FileTypePpt", __iconNode$4);
83
-
134
+ * @license @tabler/icons-react v3.46.0 - MIT
135
+ *
136
+ * This source code is licensed under the MIT license.
137
+ * See the LICENSE file in the root directory of this source tree.
138
+ */
139
+ var IconFileTypeXls = createReactComponent("outline", "file-type-xls", "FileTypeXls", [
140
+ ["path", {
141
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
142
+ "key": "svg-0"
143
+ }],
144
+ ["path", {
145
+ "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4",
146
+ "key": "svg-1"
147
+ }],
148
+ ["path", {
149
+ "d": "M4 15l4 6",
150
+ "key": "svg-2"
151
+ }],
152
+ ["path", {
153
+ "d": "M4 21l4 -6",
154
+ "key": "svg-3"
155
+ }],
156
+ ["path", {
157
+ "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",
158
+ "key": "svg-4"
159
+ }],
160
+ ["path", {
161
+ "d": "M11 15v6h3",
162
+ "key": "svg-5"
163
+ }]
164
+ ]);
84
165
  /**
85
- * @license @tabler/icons-react v3.45.0 - MIT
86
- *
87
- * This source code is licensed under the MIT license.
88
- * See the LICENSE file in the root directory of this source tree.
89
- */
90
-
91
-
92
- const __iconNode$3 = [["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-0" }], ["path", { "d": "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "key": "svg-1" }], ["path", { "d": "M4 15l4 6", "key": "svg-2" }], ["path", { "d": "M4 21l4 -6", "key": "svg-3" }], ["path", { "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", "key": "svg-4" }], ["path", { "d": "M11 15v6h3", "key": "svg-5" }]];
93
- const IconFileTypeXls = createReactComponent("outline", "file-type-xls", "FileTypeXls", __iconNode$3);
94
-
95
- /**
96
- * @license @tabler/icons-react v3.45.0 - MIT
97
- *
98
- * This source code is licensed under the MIT license.
99
- * See the LICENSE file in the root directory of this source tree.
100
- */
101
-
102
-
103
- const __iconNode$2 = [["path", { "d": "M14 3v4a1 1 0 0 0 1 1h4", "key": "svg-0" }], ["path", { "d": "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2", "key": "svg-1" }]];
104
- const IconFile = createReactComponent("outline", "file", "File", __iconNode$2);
105
-
166
+ * @license @tabler/icons-react v3.46.0 - MIT
167
+ *
168
+ * This source code is licensed under the MIT license.
169
+ * See the LICENSE file in the root directory of this source tree.
170
+ */
171
+ var IconFile = createReactComponent("outline", "file", "File", [["path", {
172
+ "d": "M14 3v4a1 1 0 0 0 1 1h4",
173
+ "key": "svg-0"
174
+ }], ["path", {
175
+ "d": "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2",
176
+ "key": "svg-1"
177
+ }]]);
106
178
  /**
107
- * @license @tabler/icons-react v3.45.0 - MIT
108
- *
109
- * This source code is licensed under the MIT license.
110
- * See the LICENSE file in the root directory of this source tree.
111
- */
112
-
113
-
114
- const __iconNode$1 = [["path", { "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", "key": "svg-0" }], ["path", { "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", "key": "svg-1" }], ["path", { "d": "M4 15v-3a8 8 0 0 1 16 0v3", "key": "svg-2" }]];
115
- const IconHeadphones = createReactComponent("outline", "headphones", "Headphones", __iconNode$1);
116
-
179
+ * @license @tabler/icons-react v3.46.0 - MIT
180
+ *
181
+ * This source code is licensed under the MIT license.
182
+ * See the LICENSE file in the root directory of this source tree.
183
+ */
184
+ var IconHeadphones = createReactComponent("outline", "headphones", "Headphones", [
185
+ ["path", {
186
+ "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",
187
+ "key": "svg-0"
188
+ }],
189
+ ["path", {
190
+ "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",
191
+ "key": "svg-1"
192
+ }],
193
+ ["path", {
194
+ "d": "M4 15v-3a8 8 0 0 1 16 0v3",
195
+ "key": "svg-2"
196
+ }]
197
+ ]);
117
198
  /**
118
- * @license @tabler/icons-react v3.45.0 - MIT
119
- *
120
- * This source code is licensed under the MIT license.
121
- * See the LICENSE file in the root directory of this source tree.
122
- */
123
-
124
-
125
- const __iconNode = [["path", { "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", "key": "svg-0" }], ["path", { "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", "key": "svg-1" }]];
126
- const IconVideo = createReactComponent("outline", "video", "Video", __iconNode);
127
-
128
- const ctrl = "_ctrl_1vnsv_1";
129
- const pagination = "_pagination_1vnsv_7";
130
- const page = "_page_1vnsv_19";
131
- const list = "_list_1vnsv_25";
132
- const file = "_file_1vnsv_44";
133
- const thumbnail$1 = "_thumbnail_1vnsv_58";
134
- const attr = "_attr_1vnsv_65";
135
- const styles$5 = {
136
- ctrl: ctrl,
137
- pagination: pagination,
138
- page: page,
139
- list: list,
199
+ * @license @tabler/icons-react v3.46.0 - MIT
200
+ *
201
+ * This source code is licensed under the MIT license.
202
+ * See the LICENSE file in the root directory of this source tree.
203
+ */
204
+ var IconVideo = createReactComponent("outline", "video", "Video", [["path", {
205
+ "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",
206
+ "key": "svg-0"
207
+ }], ["path", {
208
+ "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",
209
+ "key": "svg-1"
210
+ }]]);
211
+ var file_list_module_default = {
212
+ ctrl: "_ctrl_1vnsv_1",
213
+ pagination: "_pagination_1vnsv_7",
214
+ page: "_page_1vnsv_19",
215
+ list: "_list_1vnsv_25",
140
216
  "delete": "_delete_1vnsv_39",
141
- file: file,
142
- thumbnail: thumbnail$1,
143
- attr: attr
217
+ file: "_file_1vnsv_44",
218
+ thumbnail: "_thumbnail_1vnsv_58",
219
+ attr: "_attr_1vnsv_65"
144
220
  };
145
-
221
+ //#endregion
222
+ //#region src/get-ext.ts
223
+ /**
224
+ *
225
+ * @param src
226
+ */
146
227
  function getExt(src) {
147
- const ext = src.split(".").pop()?.toLowerCase() ?? "";
148
- const isImage = ["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(ext);
149
- const isVideo = ["mp4", "webm", "mov", "avi"].includes(ext);
150
- const isAudio = ["mp3", "wav", "m4a", "ogg", "flac"].includes(ext);
151
- const isDoc = ["doc", "docx"].includes(ext);
152
- const isPpt = ["ppt", "pptx"].includes(ext);
153
- const isXls = ["xls", "xlsx"].includes(ext);
154
- const isPdf = ["pdf"].includes(ext);
155
- return {
156
- ext,
157
- isImage,
158
- isVideo,
159
- isAudio,
160
- isDoc,
161
- isPpt,
162
- isXls,
163
- isPdf
164
- };
228
+ const ext = src.split(".").pop()?.toLowerCase() ?? "";
229
+ return {
230
+ ext,
231
+ isImage: [
232
+ "jpg",
233
+ "jpeg",
234
+ "png",
235
+ "gif",
236
+ "webp",
237
+ "svg"
238
+ ].includes(ext),
239
+ isVideo: [
240
+ "mp4",
241
+ "webm",
242
+ "mov",
243
+ "avi"
244
+ ].includes(ext),
245
+ isAudio: [
246
+ "mp3",
247
+ "wav",
248
+ "m4a",
249
+ "ogg",
250
+ "flac"
251
+ ].includes(ext),
252
+ isDoc: ["doc", "docx"].includes(ext),
253
+ isPpt: ["ppt", "pptx"].includes(ext),
254
+ isXls: ["xls", "xlsx"].includes(ext),
255
+ isPdf: ["pdf"].includes(ext)
256
+ };
165
257
  }
166
-
167
- const thumbnail = "_thumbnail_bi2ve_1";
168
- const styles$4 = {
169
- thumbnail: thumbnail
170
- };
171
-
258
+ var thumbnail_module_default = { thumbnail: "_thumbnail_bi2ve_1" };
259
+ //#endregion
260
+ //#region src/components/thumbnail.tsx
261
+ /**
262
+ * File thumbnail. Renders an image/video preview or a file-type icon.
263
+ *
264
+ * The file type is inferred from the URL's extension (`getExt`) — the
265
+ * URL is the only information available here, so the extension decides
266
+ * whether the file can be previewed inline or needs a type icon.
267
+ * @param root0
268
+ * @param root0.src
269
+ * @example
270
+ * ```tsx
271
+ * <Thumbnail src={file.url} />
272
+ * ```
273
+ */
172
274
  function Thumbnail({ src }) {
173
- const [isLoaded, setIsLoaded] = useState(false);
174
- const file = getExt(src);
175
- return /* @__PURE__ */ jsx(
176
- "span",
177
- {
178
- className: styles$4["thumbnail"],
179
- "data-bge-editor-ui-component": "thumbnail",
180
- "data-loaded": isLoaded,
181
- children: file.isImage ? /* @__PURE__ */ jsx(
182
- "img",
183
- {
184
- src,
185
- alt: "画像のプレビュー",
186
- loading: "lazy",
187
- onLoad: () => setIsLoaded(true)
188
- }
189
- ) : file.isVideo ? /* @__PURE__ */ jsxs("video", { controls: false, playsInline: true, children: [
190
- /* @__PURE__ */ jsx("source", { src, type: `video/${file.ext}` }),
191
- /* @__PURE__ */ jsx("track", { kind: "captions", src: "" }),
192
- /* @__PURE__ */ jsx(IconVideo, {})
193
- ] }) : 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, {})
194
- }
195
- );
275
+ const [isLoaded, setIsLoaded] = useState(false);
276
+ const file = getExt(src);
277
+ return /* @__PURE__ */ jsx("span", {
278
+ className: thumbnail_module_default["thumbnail"],
279
+ "data-bge-editor-ui-component": "thumbnail",
280
+ "data-loaded": isLoaded,
281
+ children: file.isImage ? /* @__PURE__ */ jsx("img", {
282
+ src,
283
+ alt: "画像のプレビュー",
284
+ loading: "lazy",
285
+ onLoad: () => setIsLoaded(true)
286
+ }) : file.isVideo ? /* @__PURE__ */ jsxs("video", {
287
+ controls: false,
288
+ playsInline: true,
289
+ children: [
290
+ /* @__PURE__ */ jsx("source", {
291
+ src,
292
+ type: `video/${file.ext}`
293
+ }),
294
+ /* @__PURE__ */ jsx("track", {
295
+ kind: "captions",
296
+ src: ""
297
+ }),
298
+ /* @__PURE__ */ jsx(IconVideo, {})
299
+ ]
300
+ }) : 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, {})
301
+ });
196
302
  }
197
-
198
- function FileList({
199
- engine,
200
- fileType
201
- }) {
202
- const rootId = useId();
203
- const getFileList = engine.serverAPI.getFileList;
204
- const deleteFile = engine.serverAPI.deleteFile;
205
- const [fileList, setFileList] = useState([]);
206
- const [selectedPath, setSelectedPath] = useState("");
207
- const [searchWord, setSearchWord] = useState("");
208
- const [currentPage, setCurrentPage] = useState(0);
209
- const [totalPage, setTotalPage] = useState(1);
210
- const [progress, setProgress] = useState({ uploaded: 0, total: 100 });
211
- const requestDebounce = useRef(-1);
212
- useComponentEvent(engine, "file-select", async ({ path, isMounted }) => {
213
- setSelectedPath(path);
214
- if (!isMounted && // On initial mount
215
- getFileList) {
216
- const result = await getFileList(fileType, {
217
- filter: "",
218
- page: 0,
219
- selected: path
220
- });
221
- setFileList(result.data);
222
- setCurrentPage(result.pagination.current);
223
- setTotalPage(result.pagination.total);
224
- }
225
- if (path.startsWith("blob:")) {
226
- setFileList((prev) => [
227
- {
228
- fileId: "",
229
- name: "",
230
- size: 0,
231
- timestamp: Date.now(),
232
- url: path,
233
- sizes: {}
234
- },
235
- ...prev.filter((file) => !file.url.startsWith("blob:"))
236
- ]);
237
- }
238
- });
239
- useComponentEvent(engine, "file-upload-progress", (p) => {
240
- if (p.blob === selectedPath) {
241
- setProgress({ uploaded: p.uploaded, total: p.total });
242
- }
243
- });
244
- useComponentEvent(engine, "file-listup", ({ data }) => {
245
- setFileList(data);
246
- });
247
- const paginate = (page) => {
248
- page = Number.isNaN(page) ? 0 : Math.min(Math.max(0, page), totalPage - 1);
249
- if (currentPage === page) {
250
- return;
251
- }
252
- setCurrentPage(page);
253
- window.clearTimeout(requestDebounce.current);
254
- requestDebounce.current = window.setTimeout(async () => {
255
- const result = await getFileList?.(fileType, { page });
256
- if (result) {
257
- setFileList(result.data);
258
- setCurrentPage(result.pagination.current);
259
- setTotalPage(result.pagination.total);
260
- }
261
- }, 100);
262
- };
263
- const search = (value) => {
264
- if (searchWord === value) {
265
- return;
266
- }
267
- setSearchWord(value);
268
- window.clearTimeout(requestDebounce.current);
269
- requestDebounce.current = window.setTimeout(async () => {
270
- const result = await getFileList?.(fileType, { filter: value });
271
- if (result) {
272
- setFileList(result.data);
273
- setCurrentPage(result.pagination.current);
274
- setTotalPage(result.pagination.total);
275
- }
276
- }, 300);
277
- };
278
- const rootRef = useCommand({
279
- "--paginate": (e) => {
280
- const direction = e.source?.value;
281
- paginate(direction === "prev" ? currentPage - 1 : currentPage + 1);
282
- },
283
- "--select-file": (e) => {
284
- const source = e.source;
285
- if (!source) {
286
- return;
287
- }
288
- engine.componentObserver.notify("file-select", {
289
- path: source.value,
290
- fileSize: Number(source.dataset["size"] ?? "0"),
291
- isEmpty: false,
292
- isMounted: true
293
- });
294
- },
295
- "--delete-file": (e) => {
296
- const url = e.source?.value;
297
- if (!url) {
298
- return;
299
- }
300
- void (async () => {
301
- const res = await deleteFile?.(fileType, url);
302
- if (!res || res.error) {
303
- throw new Error(`Failed to delete file: ${url}`);
304
- }
305
- const result = await getFileList?.(fileType, {
306
- page: currentPage,
307
- filter: searchWord
308
- });
309
- if (result) {
310
- setFileList(result.data);
311
- setCurrentPage(result.pagination.current);
312
- setTotalPage(result.pagination.total);
313
- }
314
- })().catch(() => {
315
- alert("ファイルの削除に失敗しました。");
316
- });
317
- }
318
- });
319
- const marked = (text) => {
320
- if (!searchWord) {
321
- return text;
322
- }
323
- const chars = text.split(searchWord);
324
- return chars.map((char, i) => /* @__PURE__ */ jsxs(Fragment, { children: [
325
- i === 0 ? null : /* @__PURE__ */ jsx("mark", { children: searchWord }),
326
- char
327
- ] }, char + i));
328
- };
329
- return /* @__PURE__ */ jsxs("div", { ref: rootRef, id: rootId, children: [
330
- /* @__PURE__ */ jsxs("div", { className: styles$5["ctrl"], children: [
331
- /* @__PURE__ */ jsxs("div", { className: styles$5["pagination"], children: [
332
- /* @__PURE__ */ jsx(
333
- "button",
334
- {
335
- type: "button",
336
- disabled: currentPage === 0,
337
- command: "--paginate",
338
- commandfor: rootId,
339
- value: "prev",
340
- children: "前へ"
341
- }
342
- ),
343
- /* @__PURE__ */ jsxs("div", { className: styles$5["page"], children: [
344
- /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
345
- "input",
346
- {
347
- type: "number",
348
- value: currentPage + 1,
349
- min: "1",
350
- max: totalPage,
351
- onChange: (e) => paginate(e.currentTarget.valueAsNumber - 1),
352
- "aria-label": "ページ番号"
353
- }
354
- ) }),
355
- /* @__PURE__ */ jsx("span", { children: "/" }),
356
- /* @__PURE__ */ jsx("span", { children: totalPage })
357
- ] }),
358
- /* @__PURE__ */ jsx(
359
- "button",
360
- {
361
- type: "button",
362
- disabled: currentPage === totalPage - 1,
363
- command: "--paginate",
364
- commandfor: rootId,
365
- value: "next",
366
- children: "次へ"
367
- }
368
- )
369
- ] }),
370
- /* @__PURE__ */ jsx(
371
- "input",
372
- {
373
- type: "search",
374
- placeholder: "検索",
375
- value: searchWord,
376
- onChange: (e) => search(e.currentTarget.value)
377
- }
378
- )
379
- ] }),
380
- /* @__PURE__ */ jsx("ul", { className: styles$5["list"], children: fileList.map((file) => /* @__PURE__ */ jsxs("li", { children: [
381
- /* @__PURE__ */ jsxs(
382
- "button",
383
- {
384
- ref: file.url === selectedPath ? scrollToSelected : void 0,
385
- className: styles$5["file"],
386
- type: "button",
387
- "aria-pressed": file.url === selectedPath,
388
- command: "--select-file",
389
- commandfor: rootId,
390
- value: file.url,
391
- "data-size": file.size,
392
- children: [
393
- /* @__PURE__ */ jsx("span", { className: styles$5["thumbnail"], children: /* @__PURE__ */ jsx(Thumbnail, { src: file.url }) }),
394
- file.url.startsWith("blob:") ? /* @__PURE__ */ jsxs("span", { children: [
395
- "アップロード中...",
396
- " ",
397
- /* @__PURE__ */ jsxs("span", { children: [
398
- Math.floor(progress.uploaded / progress.total * 100),
399
- "%"
400
- ] })
401
- ] }) : /* @__PURE__ */ jsxs("span", { className: styles$5["attr"], children: [
402
- /* @__PURE__ */ jsx("span", { children: "ID" }),
403
- /* @__PURE__ */ jsx("span", { children: marked(file.fileId) }),
404
- /* @__PURE__ */ jsx("span", { children: "名称" }),
405
- /* @__PURE__ */ jsx("span", { children: marked(file.name) }),
406
- /* @__PURE__ */ jsx("span", { children: "更新" }),
407
- /* @__PURE__ */ jsx("span", { children: formatDate(file.timestamp / 1e3, "YYYY-MM-DD HH:mm") }),
408
- /* @__PURE__ */ jsx("span", { children: "サイズ" }),
409
- /* @__PURE__ */ jsx("span", { children: formatByteSize(file.size) })
410
- ] })
411
- ]
412
- }
413
- ),
414
- !file.url.startsWith("blob:") && deleteFile ? /* @__PURE__ */ jsx(
415
- "button",
416
- {
417
- className: styles$5["delete"],
418
- type: "button",
419
- command: "--delete-file",
420
- commandfor: rootId,
421
- value: file.url,
422
- children: "削除"
423
- }
424
- ) : null
425
- ] }, file.url)) })
426
- ] });
303
+ //#endregion
304
+ //#region src/components/file-list.tsx
305
+ /**
306
+ * Paginated, searchable file list. Selection is broadcast on the
307
+ * engine-level component observer (`file-select`); buttons declare local
308
+ * commands instead of click handlers.
309
+ * @param root0
310
+ * @param root0.engine
311
+ * @param root0.fileType
312
+ * @example
313
+ * ```tsx
314
+ * <FileUploader engine={engine} fileType="image" />
315
+ * <FileList engine={engine} fileType="image" />
316
+ * ```
317
+ */
318
+ function FileList({ engine, fileType }) {
319
+ const rootId = useId();
320
+ const getFileList = engine.serverAPI.getFileList;
321
+ const deleteFile = engine.serverAPI.deleteFile;
322
+ const [fileList, setFileList] = useState([]);
323
+ const [selectedPath, setSelectedPath] = useState("");
324
+ const [searchWord, setSearchWord] = useState("");
325
+ const [currentPage, setCurrentPage] = useState(0);
326
+ const [totalPage, setTotalPage] = useState(1);
327
+ const [progress, setProgress] = useState({
328
+ uploaded: 0,
329
+ total: 100
330
+ });
331
+ const requestDebounce = useRef(-1);
332
+ useComponentEvent(engine, "file-select", async ({ path, isMounted }) => {
333
+ setSelectedPath(path);
334
+ if (!isMounted && getFileList) {
335
+ const result = await getFileList(fileType, {
336
+ filter: "",
337
+ page: 0,
338
+ selected: path
339
+ });
340
+ setFileList(result.data);
341
+ setCurrentPage(result.pagination.current);
342
+ setTotalPage(result.pagination.total);
343
+ }
344
+ if (path.startsWith("blob:")) setFileList((prev) => [{
345
+ fileId: "",
346
+ name: "",
347
+ size: 0,
348
+ timestamp: Date.now(),
349
+ url: path,
350
+ sizes: {}
351
+ }, ...prev.filter((file) => !file.url.startsWith("blob:"))]);
352
+ });
353
+ useComponentEvent(engine, "file-upload-progress", (p) => {
354
+ if (p.blob === selectedPath) setProgress({
355
+ uploaded: p.uploaded,
356
+ total: p.total
357
+ });
358
+ });
359
+ useComponentEvent(engine, "file-listup", ({ data }) => {
360
+ setFileList(data);
361
+ });
362
+ const paginate = (page) => {
363
+ page = Number.isNaN(page) ? 0 : Math.min(Math.max(0, page), totalPage - 1);
364
+ if (currentPage === page) return;
365
+ setCurrentPage(page);
366
+ window.clearTimeout(requestDebounce.current);
367
+ requestDebounce.current = window.setTimeout(async () => {
368
+ const result = await getFileList?.(fileType, { page });
369
+ if (result) {
370
+ setFileList(result.data);
371
+ setCurrentPage(result.pagination.current);
372
+ setTotalPage(result.pagination.total);
373
+ }
374
+ }, 100);
375
+ };
376
+ const search = (value) => {
377
+ if (searchWord === value) return;
378
+ setSearchWord(value);
379
+ window.clearTimeout(requestDebounce.current);
380
+ requestDebounce.current = window.setTimeout(async () => {
381
+ const result = await getFileList?.(fileType, { filter: value });
382
+ if (result) {
383
+ setFileList(result.data);
384
+ setCurrentPage(result.pagination.current);
385
+ setTotalPage(result.pagination.total);
386
+ }
387
+ }, 300);
388
+ };
389
+ const rootRef = useCommand({
390
+ "--paginate": (e) => {
391
+ const direction = e.source?.value;
392
+ paginate(direction === "prev" ? currentPage - 1 : currentPage + 1);
393
+ },
394
+ "--select-file": (e) => {
395
+ const source = e.source;
396
+ if (!source) return;
397
+ engine.componentObserver.notify("file-select", {
398
+ path: source.value,
399
+ fileSize: Number(source.dataset["size"] ?? "0"),
400
+ isEmpty: false,
401
+ isMounted: true
402
+ });
403
+ },
404
+ "--delete-file": (e) => {
405
+ const url = e.source?.value;
406
+ if (!url) return;
407
+ (async () => {
408
+ const res = await deleteFile?.(fileType, url);
409
+ if (!res || res.error) throw new Error(`Failed to delete file: ${url}`);
410
+ const result = await getFileList?.(fileType, {
411
+ page: currentPage,
412
+ filter: searchWord
413
+ });
414
+ if (result) {
415
+ setFileList(result.data);
416
+ setCurrentPage(result.pagination.current);
417
+ setTotalPage(result.pagination.total);
418
+ }
419
+ })().catch(() => {
420
+ alert("ファイルの削除に失敗しました。");
421
+ });
422
+ }
423
+ });
424
+ const marked = (text) => {
425
+ if (!searchWord) return text;
426
+ return text.split(searchWord).map((char, i) => /* @__PURE__ */ jsxs(Fragment, { children: [i === 0 ? null : /* @__PURE__ */ jsx("mark", { children: searchWord }), char] }, char + i));
427
+ };
428
+ return /* @__PURE__ */ jsxs("div", {
429
+ ref: rootRef,
430
+ id: rootId,
431
+ children: [/* @__PURE__ */ jsxs("div", {
432
+ className: file_list_module_default["ctrl"],
433
+ children: [/* @__PURE__ */ jsxs("div", {
434
+ className: file_list_module_default["pagination"],
435
+ children: [
436
+ /* @__PURE__ */ jsx("button", {
437
+ type: "button",
438
+ disabled: currentPage === 0,
439
+ command: "--paginate",
440
+ commandfor: rootId,
441
+ value: "prev",
442
+ children: "前へ"
443
+ }),
444
+ /* @__PURE__ */ jsxs("div", {
445
+ className: file_list_module_default["page"],
446
+ children: [
447
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("input", {
448
+ type: "number",
449
+ value: currentPage + 1,
450
+ min: "1",
451
+ max: totalPage,
452
+ onChange: (e) => paginate(e.currentTarget.valueAsNumber - 1),
453
+ "aria-label": "ページ番号"
454
+ }) }),
455
+ /* @__PURE__ */ jsx("span", { children: "/" }),
456
+ /* @__PURE__ */ jsx("span", { children: totalPage })
457
+ ]
458
+ }),
459
+ /* @__PURE__ */ jsx("button", {
460
+ type: "button",
461
+ disabled: currentPage === totalPage - 1,
462
+ command: "--paginate",
463
+ commandfor: rootId,
464
+ value: "next",
465
+ children: "次へ"
466
+ })
467
+ ]
468
+ }), /* @__PURE__ */ jsx("input", {
469
+ type: "search",
470
+ placeholder: "検索",
471
+ value: searchWord,
472
+ onChange: (e) => search(e.currentTarget.value)
473
+ })]
474
+ }), /* @__PURE__ */ jsx("ul", {
475
+ className: file_list_module_default["list"],
476
+ children: fileList.map((file) => /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs("button", {
477
+ ref: file.url === selectedPath ? scrollToSelected : void 0,
478
+ className: file_list_module_default["file"],
479
+ type: "button",
480
+ "aria-pressed": file.url === selectedPath,
481
+ command: "--select-file",
482
+ commandfor: rootId,
483
+ value: file.url,
484
+ "data-size": file.size,
485
+ children: [/* @__PURE__ */ jsx("span", {
486
+ className: file_list_module_default["thumbnail"],
487
+ children: /* @__PURE__ */ jsx(Thumbnail, { src: file.url })
488
+ }), file.url.startsWith("blob:") ? /* @__PURE__ */ jsxs("span", { children: [
489
+ "アップロード中...",
490
+ " ",
491
+ /* @__PURE__ */ jsxs("span", { children: [Math.floor(progress.uploaded / progress.total * 100), "%"] })
492
+ ] }) : /* @__PURE__ */ jsxs("span", {
493
+ className: file_list_module_default["attr"],
494
+ children: [
495
+ /* @__PURE__ */ jsx("span", { children: "ID" }),
496
+ /* @__PURE__ */ jsx("span", { children: marked(file.fileId) }),
497
+ /* @__PURE__ */ jsx("span", { children: "名称" }),
498
+ /* @__PURE__ */ jsx("span", { children: marked(file.name) }),
499
+ /* @__PURE__ */ jsx("span", { children: "更新" }),
500
+ /* @__PURE__ */ jsx("span", { children: formatDate(file.timestamp / 1e3, "YYYY-MM-DD HH:mm") }),
501
+ /* @__PURE__ */ jsx("span", { children: "サイズ" }),
502
+ /* @__PURE__ */ jsx("span", { children: formatByteSize(file.size) })
503
+ ]
504
+ })]
505
+ }), !file.url.startsWith("blob:") && deleteFile ? /* @__PURE__ */ jsx("button", {
506
+ className: file_list_module_default["delete"],
507
+ type: "button",
508
+ command: "--delete-file",
509
+ commandfor: rootId,
510
+ value: file.url,
511
+ children: "削除"
512
+ }) : null] }, file.url))
513
+ })]
514
+ });
427
515
  }
516
+ /**
517
+ * Callback ref attached only to the currently selected file button, so the
518
+ * list scrolls to it when the selection mounts or changes. Kept at module
519
+ * scope for a stable identity — an inline arrow would re-attach (and
520
+ * re-scroll) on every unrelated re-render such as upload progress updates.
521
+ * @param el - The selected button, or null on detach
522
+ */
428
523
  function scrollToSelected(el) {
429
- el?.scrollIntoView({
430
- behavior: "smooth",
431
- block: "nearest"
432
- });
524
+ el?.scrollIntoView({
525
+ behavior: "smooth",
526
+ block: "nearest"
527
+ });
433
528
  }
434
-
435
- const uploader = "_uploader_obiwu_1";
436
- const styles$3 = {
437
- uploader: uploader
438
- };
439
-
440
- function FileUploader({
441
- engine,
442
- fileType
443
- }) {
444
- const rootId = useId();
445
- const inputRef = useRef(null);
446
- const accept = fileType === "image" ? "image/*" : "*";
447
- const rootRef = useCommand({
448
- "--open-file-picker": () => {
449
- inputRef.current?.showPicker();
450
- }
451
- });
452
- const stageFile = async () => {
453
- const inputFile = inputRef.current;
454
- const file = inputFile?.files?.[0];
455
- if (!file) {
456
- return;
457
- }
458
- const path = URL.createObjectURL(file);
459
- engine.componentObserver.notify("file-select", {
460
- path,
461
- fileSize: file.size,
462
- isEmpty: false
463
- });
464
- try {
465
- const res = await engine.serverAPI.postFile?.(fileType, file, (uploaded, total) => {
466
- engine.componentObserver.notify("file-upload-progress", {
467
- blob: path,
468
- uploaded,
469
- total
470
- });
471
- });
472
- if (!res || res.error) {
473
- throw new Error(`Failed to upload file: ${file.name}`);
474
- }
475
- engine.componentObserver.notify("file-listup", {
476
- fileType,
477
- data: [res.uploaded]
478
- });
479
- engine.componentObserver.notify("file-select", {
480
- path: res.uploaded.url,
481
- fileSize: res.uploaded.size,
482
- isEmpty: false
483
- });
484
- } catch {
485
- alert(`ファイルのアップロードに失敗しました: ${file.name}`);
486
- }
487
- };
488
- return /* @__PURE__ */ jsxs("div", { ref: rootRef, id: rootId, className: styles$3["uploader"], children: [
489
- /* @__PURE__ */ jsx(
490
- "input",
491
- {
492
- type: "file",
493
- ref: inputRef,
494
- onChange: () => void stageFile(),
495
- accept
496
- }
497
- ),
498
- /* @__PURE__ */ jsx("button", { type: "button", command: "--open-file-picker", commandfor: rootId, children: "ファイルを追加アップロードする" })
499
- ] });
529
+ var file_uploader_module_default = { uploader: "_uploader_obiwu_1" };
530
+ //#endregion
531
+ //#region src/components/file-uploader.tsx
532
+ /**
533
+ * File upload control. The trigger button declares a local command and
534
+ * the handler opens the picker via `showPicker()` — no click handlers,
535
+ * no programmatic `click()`.
536
+ * @param root0
537
+ * @param root0.engine
538
+ * @param root0.fileType
539
+ * @example
540
+ * ```tsx
541
+ * <FileUploader engine={engine} fileType="image" />
542
+ * ```
543
+ */
544
+ function FileUploader({ engine, fileType }) {
545
+ const rootId = useId();
546
+ const inputRef = useRef(null);
547
+ const accept = fileType === "image" ? "image/*" : "*";
548
+ const rootRef = useCommand({ "--open-file-picker": () => {
549
+ inputRef.current?.showPicker();
550
+ } });
551
+ const stageFile = async () => {
552
+ const file = inputRef.current?.files?.[0];
553
+ if (!file) return;
554
+ const path = URL.createObjectURL(file);
555
+ engine.componentObserver.notify("file-select", {
556
+ path,
557
+ fileSize: file.size,
558
+ isEmpty: false
559
+ });
560
+ try {
561
+ const res = await engine.serverAPI.postFile?.(fileType, file, (uploaded, total) => {
562
+ engine.componentObserver.notify("file-upload-progress", {
563
+ blob: path,
564
+ uploaded,
565
+ total
566
+ });
567
+ });
568
+ if (!res || res.error) throw new Error(`Failed to upload file: ${file.name}`);
569
+ engine.componentObserver.notify("file-listup", {
570
+ fileType,
571
+ data: [res.uploaded]
572
+ });
573
+ engine.componentObserver.notify("file-select", {
574
+ path: res.uploaded.url,
575
+ fileSize: res.uploaded.size,
576
+ isEmpty: false
577
+ });
578
+ } catch {
579
+ alert(`ファイルのアップロードに失敗しました: ${file.name}`);
580
+ }
581
+ };
582
+ return /* @__PURE__ */ jsxs("div", {
583
+ ref: rootRef,
584
+ id: rootId,
585
+ className: file_uploader_module_default["uploader"],
586
+ children: [/* @__PURE__ */ jsx("input", {
587
+ type: "file",
588
+ ref: inputRef,
589
+ onChange: () => void stageFile(),
590
+ accept
591
+ }), /* @__PURE__ */ jsx("button", {
592
+ type: "button",
593
+ command: "--open-file-picker",
594
+ commandfor: rootId,
595
+ children: "ファイルを追加アップロードする"
596
+ })]
597
+ });
500
598
  }
501
-
502
- const img = "_img_18j28_1";
503
- const uploading = "_uploading_18j28_26";
504
- const progress = "_progress_18j28_30";
505
- const meta = "_meta_18j28_40";
506
- const path = "_path_18j28_60";
507
- const upload = "_upload_18j28_26";
508
- const dimension = "_dimension_18j28_72";
509
- const styles$2 = {
510
- img: img,
511
- uploading: uploading,
512
- progress: progress,
513
- meta: meta,
514
- path: path,
515
- upload: upload,
516
- dimension: dimension
517
- };
518
-
519
- function Preview({
520
- engine,
521
- path
522
- }) {
523
- const [dimension, setDimension] = useState(null);
524
- const [progress, setProgress] = useState({ uploaded: 0, total: 100 });
525
- const [prevPath, setPrevPath] = useState(path);
526
- if (prevPath !== path) {
527
- setPrevPath(path);
528
- setDimension(null);
529
- }
530
- const file = path ? getExt(path) : null;
531
- const isUploadingMode = path.startsWith("blob:");
532
- useComponentEvent(engine, "file-upload-progress", (p) => {
533
- if (p.blob === path) {
534
- setProgress({ uploaded: p.uploaded, total: p.total });
535
- }
536
- });
537
- useEffect(() => {
538
- const file2 = path ? getExt(path) : null;
539
- let aborted = false;
540
- if (file2?.isImage) {
541
- const image = new Image();
542
- image.src = path;
543
- image.addEventListener(
544
- "load",
545
- () => {
546
- if (!aborted) {
547
- setDimension({ width: image.naturalWidth, height: image.naturalHeight });
548
- }
549
- },
550
- { once: true }
551
- );
552
- } else if (file2?.isVideo) {
553
- const video = document.createElement("video");
554
- video.src = path;
555
- video.addEventListener(
556
- "loadedmetadata",
557
- () => {
558
- if (!aborted) {
559
- setDimension({ width: video.videoWidth, height: video.videoHeight });
560
- }
561
- },
562
- { once: true }
563
- );
564
- }
565
- return () => {
566
- aborted = true;
567
- };
568
- }, [path]);
569
- return /* @__PURE__ */ jsxs("div", { children: [
570
- /* @__PURE__ */ jsxs(
571
- "div",
572
- {
573
- className: `${styles$2["img"]} ${isUploadingMode ? styles$2["uploading"] : ""}`.trim(),
574
- children: [
575
- file?.isImage ? /* @__PURE__ */ jsx("img", { src: path, alt: "画像プレビュー" }) : file?.isVideo ? /* @__PURE__ */ jsxs("video", { controls: true, playsInline: true, children: [
576
- /* @__PURE__ */ jsx("source", { src: path, type: `video/${file.ext}` }),
577
- /* @__PURE__ */ jsx("track", { kind: "captions", src: "" })
578
- ] }) : file?.isAudio ? /* @__PURE__ */ jsxs("audio", { controls: true, children: [
579
- /* @__PURE__ */ jsx("source", { src: path, type: `audio/${file.ext}` }),
580
- /* @__PURE__ */ jsx("track", { kind: "metadata", src: "" })
581
- ] }) : file?.isDoc || file?.isPpt || file?.isXls || file?.isPdf ? /* @__PURE__ */ jsx(
582
- "object",
583
- {
584
- data: path,
585
- type: `application/${file.ext}`,
586
- title: `${file.ext}ファイルのプレビュー`,
587
- children: /* @__PURE__ */ jsx("p", { children: "プレビューできません" })
588
- }
589
- ) : /* @__PURE__ */ jsx("p", { children: "プレビューできません" }),
590
- isUploadingMode ? /* @__PURE__ */ jsx(
591
- "div",
592
- {
593
- className: styles$2["progress"],
594
- style: { translate: `${progress.uploaded / progress.total * 100}%` }
595
- }
596
- ) : null
597
- ]
598
- }
599
- ),
600
- /* @__PURE__ */ jsxs("ul", { className: styles$2["meta"], children: [
601
- isUploadingMode ? /* @__PURE__ */ jsxs("li", { className: styles$2["upload"], children: [
602
- /* @__PURE__ */ jsx("span", { children: "アップロード..." }),
603
- /* @__PURE__ */ jsxs("span", { className: styles$2["progress"], children: [
604
- Math.round(progress.uploaded / progress.total * 100),
605
- "% (",
606
- progress.uploaded,
607
- "/",
608
- progress.total,
609
- ")"
610
- ] })
611
- ] }) : /* @__PURE__ */ jsx("li", { className: styles$2["path"], children: /* @__PURE__ */ jsx("a", { href: path, target: "_blank", children: path }) }),
612
- dimension ? /* @__PURE__ */ jsxs("li", { className: styles$2["dimension"], children: [
613
- dimension.width,
614
- "x",
615
- dimension.height
616
- ] }) : null
617
- ] })
618
- ] });
599
+ //#endregion
600
+ //#region src/components/front-matter-editor.tsx
601
+ /**
602
+ * Mount the Front Matter editor (a React component) into the given
603
+ * container.
604
+ *
605
+ * The field list is rendered declaratively from React state, so
606
+ * toggling the panel or editing other fields never rebuilds the inputs
607
+ * — focus, caret position and IME composition survive re-renders.
608
+ * @param options - Mount target and initial data
609
+ * @returns A handle exposing the latest data and an unmount function
610
+ * @example
611
+ * ```ts
612
+ * const editor = createFrontMatterEditor({
613
+ * container: document.querySelector('.front-matter-editor')!,
614
+ * initialData: { title: 'ページ' },
615
+ * hasFrontMatter: true,
616
+ * onUpdated: (data) => debouncedSave(data),
617
+ * });
618
+ * editor.getData(); // => { title: 'ページ' }
619
+ * ```
620
+ */
621
+ function createFrontMatterEditor(options) {
622
+ let latest = { ...options.initialData };
623
+ const originalFrontMatter = options.hasFrontMatter ? JSON.stringify(options.initialData) : void 0;
624
+ const root = createRoot(options.container);
625
+ root.render(/* @__PURE__ */ jsx(FrontMatterEditorView, {
626
+ initialData: options.initialData,
627
+ onDataChange: (data) => {
628
+ latest = data;
629
+ options.onUpdated?.(data);
630
+ }
631
+ }));
632
+ const teardown = () => {
633
+ root.unmount();
634
+ };
635
+ return {
636
+ getData: () => latest,
637
+ getOriginalFrontMatter: () => originalFrontMatter,
638
+ unmount: teardown,
639
+ [Symbol.dispose]: teardown
640
+ };
619
641
  }
620
-
621
- const table = "_table_1qb61_1";
622
- const row = "_row_1qb61_7";
623
- const btn = "_btn_1qb61_19";
624
- const styles$1 = {
625
- table: table,
626
- row: row,
627
- btn: btn
642
+ /**
643
+ * Front Matterの動的フォーム本体。フィールド一覧・折りたたみ・追加
644
+ * ダイアログをReact stateとして持ち、操作は Invoker Commands
645
+ * (`--fm-toggle` / `--fm-add-field` / `--fm-delete-field`)で受ける
646
+ * @param root0
647
+ * @param root0.initialData
648
+ * @param root0.onDataChange
649
+ * @example
650
+ * ```tsx
651
+ * <FrontMatterEditorView
652
+ * initialData={{ title: 'ページ' }}
653
+ * onDataChange={(data) => console.log(data)}
654
+ * />
655
+ * ```
656
+ */
657
+ function FrontMatterEditorView({ initialData, onDataChange }) {
658
+ const rootId = useId();
659
+ const dialogId = useId();
660
+ const [fields, setFields] = useState(() => parseInitialData(initialData));
661
+ const [isCollapsed, setIsCollapsed] = useState(false);
662
+ const [addDialogOpen, setAddDialogOpen] = useState(false);
663
+ const [jsonDrafts, setJsonDrafts] = useState({});
664
+ const applyFields = (next) => {
665
+ setFields(next);
666
+ onDataChange(toData(next));
667
+ };
668
+ const updateFieldValue = (key, value) => {
669
+ applyFields(fields.map((f) => f.key === key ? {
670
+ ...f,
671
+ value
672
+ } : f));
673
+ };
674
+ const rootRef = useCommand({
675
+ "--fm-toggle": () => {
676
+ setIsCollapsed((prev) => !prev);
677
+ },
678
+ "--fm-add-field": () => {
679
+ setAddDialogOpen(true);
680
+ },
681
+ "--fm-delete-field": (e) => {
682
+ const key = e.source?.value;
683
+ if (key == null) return;
684
+ applyFields(fields.filter((f) => f.key !== key));
685
+ setJsonDrafts((prev) => {
686
+ const { [key]: _removed, ...rest } = prev;
687
+ return rest;
688
+ });
689
+ }
690
+ });
691
+ const onAddSubmit = (e) => {
692
+ e.preventDefault();
693
+ const formData = new FormData(e.currentTarget);
694
+ const key = String(formData.get("key") ?? "");
695
+ const type = formData.get("type");
696
+ if (key && !fields.some((f) => f.key === key)) applyFields([...fields, {
697
+ key,
698
+ type,
699
+ value: getDefaultValue(type)
700
+ }]);
701
+ setAddDialogOpen(false);
702
+ };
703
+ return /* @__PURE__ */ jsxs("div", {
704
+ ref: rootRef,
705
+ id: rootId,
706
+ className: "fm-editor",
707
+ children: [
708
+ /* @__PURE__ */ jsxs("div", {
709
+ className: "fm-editor-header",
710
+ children: [/* @__PURE__ */ jsxs("button", {
711
+ type: "button",
712
+ className: "fm-editor-toggle",
713
+ "aria-expanded": !isCollapsed,
714
+ command: "--fm-toggle",
715
+ commandfor: rootId,
716
+ children: [/* @__PURE__ */ jsx("span", {
717
+ className: "fm-editor-toggle-icon",
718
+ children: isCollapsed ? "▶" : "▼"
719
+ }), /* @__PURE__ */ jsx("span", { children: "Front Matter" })]
720
+ }), /* @__PURE__ */ jsx("button", {
721
+ type: "button",
722
+ className: "fm-editor-add",
723
+ title: "フィールドを追加",
724
+ command: "--fm-add-field",
725
+ commandfor: rootId,
726
+ children: "+ 追加"
727
+ })]
728
+ }),
729
+ isCollapsed ? null : /* @__PURE__ */ jsx("div", {
730
+ className: "fm-editor-fields",
731
+ children: fields.length === 0 ? /* @__PURE__ */ jsx("div", {
732
+ className: "fm-editor-empty",
733
+ children: "フィールドがありません。「+ 追加」ボタンでフィールドを追加してください。"
734
+ }) : fields.map((field) => /* @__PURE__ */ jsxs("div", {
735
+ className: "fm-editor-field",
736
+ "data-type": field.type,
737
+ children: [
738
+ /* @__PURE__ */ jsx("label", {
739
+ className: "fm-editor-field-label",
740
+ htmlFor: `${rootId}-field-${field.key}`,
741
+ children: field.key
742
+ }),
743
+ /* @__PURE__ */ jsx("div", {
744
+ className: "fm-editor-field-input",
745
+ children: /* @__PURE__ */ jsx(FieldInput, {
746
+ field,
747
+ inputId: `${rootId}-field-${field.key}`,
748
+ jsonDraft: jsonDrafts[field.key],
749
+ onValueChange: (value) => updateFieldValue(field.key, value),
750
+ onJsonDraftChange: (text) => {
751
+ setJsonDrafts((prev) => ({
752
+ ...prev,
753
+ [field.key]: text
754
+ }));
755
+ }
756
+ })
757
+ }),
758
+ /* @__PURE__ */ jsx("button", {
759
+ type: "button",
760
+ className: "fm-editor-field-delete",
761
+ title: "フィールドを削除",
762
+ command: "--fm-delete-field",
763
+ commandfor: rootId,
764
+ value: field.key,
765
+ children: "×"
766
+ })
767
+ ]
768
+ }, field.key))
769
+ }),
770
+ addDialogOpen ? /* @__PURE__ */ jsx(AddFieldDialog, {
771
+ dialogId,
772
+ onSubmit: onAddSubmit,
773
+ onClose: () => setAddDialogOpen(false)
774
+ }) : null
775
+ ]
776
+ });
777
+ }
778
+ /**
779
+ * 型別のcontrolled input
780
+ * @param root0
781
+ * @param root0.field
782
+ * @param root0.inputId
783
+ * @param root0.jsonDraft
784
+ * @param root0.onValueChange
785
+ * @param root0.onJsonDraftChange
786
+ */
787
+ function FieldInput({ field, inputId, jsonDraft, onValueChange, onJsonDraftChange }) {
788
+ switch (field.type) {
789
+ case "boolean": return /* @__PURE__ */ jsx("input", {
790
+ id: inputId,
791
+ type: "checkbox",
792
+ checked: Boolean(field.value),
793
+ onChange: (e) => onValueChange(e.currentTarget.checked)
794
+ });
795
+ case "number": return /* @__PURE__ */ jsx("input", {
796
+ id: inputId,
797
+ type: "number",
798
+ value: field.value == null ? "" : String(field.value),
799
+ onChange: (e) => {
800
+ onValueChange(e.currentTarget.value === "" ? null : Number(e.currentTarget.value));
801
+ }
802
+ });
803
+ case "date": return /* @__PURE__ */ jsx("input", {
804
+ id: inputId,
805
+ type: "date",
806
+ value: toDateInputValue(field.value),
807
+ onChange: (e) => onValueChange(e.currentTarget.value)
808
+ });
809
+ case "json": {
810
+ const text = jsonDraft ?? stringifyJson(field.value);
811
+ return /* @__PURE__ */ jsx("textarea", {
812
+ id: inputId,
813
+ rows: 3,
814
+ className: isValidJson(text) ? void 0 : "fm-editor-error",
815
+ value: text,
816
+ onChange: (e) => {
817
+ const nextText = e.currentTarget.value;
818
+ onJsonDraftChange(nextText);
819
+ try {
820
+ onValueChange(JSON.parse(nextText));
821
+ } catch {}
822
+ }
823
+ });
824
+ }
825
+ default: return /* @__PURE__ */ jsx("input", {
826
+ id: inputId,
827
+ type: "text",
828
+ value: String(field.value ?? ""),
829
+ onChange: (e) => onValueChange(e.currentTarget.value)
830
+ });
831
+ }
832
+ }
833
+ /**
834
+ * フィールド追加ダイアログ。マウント時にshowModalし、close(キャンセル
835
+ * ボタンの組み込みcloseコマンド / Escキー)でアンマウントされる
836
+ * @param root0
837
+ * @param root0.dialogId
838
+ * @param root0.onSubmit
839
+ * @param root0.onClose
840
+ */
841
+ function AddFieldDialog({ dialogId, onSubmit, onClose }) {
842
+ const dialogRef = useRef(null);
843
+ useEffect(() => {
844
+ const dialog = dialogRef.current;
845
+ if (dialog && !dialog.open) dialog.showModal();
846
+ }, []);
847
+ return /* @__PURE__ */ jsx("dialog", {
848
+ ref: dialogRef,
849
+ className: "fm-editor-dialog",
850
+ id: dialogId,
851
+ onClose,
852
+ children: /* @__PURE__ */ jsxs("form", {
853
+ onSubmit,
854
+ children: [
855
+ /* @__PURE__ */ jsx("h3", { children: "フィールドを追加" }),
856
+ /* @__PURE__ */ jsxs("div", {
857
+ className: "fm-editor-dialog-field",
858
+ children: [/* @__PURE__ */ jsx("label", {
859
+ htmlFor: `${dialogId}-key`,
860
+ children: "キー名"
861
+ }), /* @__PURE__ */ jsx("input", {
862
+ type: "text",
863
+ id: `${dialogId}-key`,
864
+ name: "key",
865
+ required: true,
866
+ placeholder: "例: title, author, date"
867
+ })]
868
+ }),
869
+ /* @__PURE__ */ jsxs("div", {
870
+ className: "fm-editor-dialog-field",
871
+ children: [/* @__PURE__ */ jsx("label", {
872
+ htmlFor: `${dialogId}-type`,
873
+ children: "型"
874
+ }), /* @__PURE__ */ jsxs("select", {
875
+ id: `${dialogId}-type`,
876
+ name: "type",
877
+ children: [
878
+ /* @__PURE__ */ jsx("option", {
879
+ value: "text",
880
+ children: "テキスト"
881
+ }),
882
+ /* @__PURE__ */ jsx("option", {
883
+ value: "number",
884
+ children: "数値"
885
+ }),
886
+ /* @__PURE__ */ jsx("option", {
887
+ value: "boolean",
888
+ children: "真偽値"
889
+ }),
890
+ /* @__PURE__ */ jsx("option", {
891
+ value: "date",
892
+ children: "日付"
893
+ }),
894
+ /* @__PURE__ */ jsx("option", {
895
+ value: "json",
896
+ children: "JSON(配列/オブジェクト)"
897
+ })
898
+ ]
899
+ })]
900
+ }),
901
+ /* @__PURE__ */ jsxs("div", {
902
+ className: "fm-editor-dialog-actions",
903
+ children: [/* @__PURE__ */ jsx("button", {
904
+ type: "button",
905
+ className: "fm-editor-dialog-cancel",
906
+ command: "close",
907
+ commandfor: dialogId,
908
+ children: "キャンセル"
909
+ }), /* @__PURE__ */ jsx("button", {
910
+ type: "submit",
911
+ className: "fm-editor-dialog-submit",
912
+ children: "追加"
913
+ })]
914
+ })
915
+ ]
916
+ })
917
+ });
918
+ }
919
+ /**
920
+ * Parse initial data and detect field types
921
+ * @param data
922
+ */
923
+ function parseInitialData(data) {
924
+ return Object.entries(data).map(([key, value]) => ({
925
+ key,
926
+ type: detectType(value),
927
+ value
928
+ }));
929
+ }
930
+ /**
931
+ * フィールド一覧をFront Matterデータへ畳み込む
932
+ * @param fields
933
+ */
934
+ function toData(fields) {
935
+ const data = {};
936
+ for (const field of fields) data[field.key] = field.value;
937
+ return data;
938
+ }
939
+ /**
940
+ * Detect the type of a value
941
+ * @param value
942
+ */
943
+ function detectType(value) {
944
+ if (typeof value === "boolean") return "boolean";
945
+ if (typeof value === "number") return "number";
946
+ if (typeof value === "string") {
947
+ if (/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2})?/.test(value)) {
948
+ const parsed = Date.parse(value);
949
+ if (!Number.isNaN(parsed)) return "date";
950
+ }
951
+ return "text";
952
+ }
953
+ if (value instanceof Date) return "date";
954
+ if (typeof value === "object" && value !== null) return "json";
955
+ return "text";
956
+ }
957
+ /**
958
+ * Get default value for a type
959
+ * @param type
960
+ */
961
+ function getDefaultValue(type) {
962
+ switch (type) {
963
+ case "boolean": return false;
964
+ case "number": return 0;
965
+ case "date": return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
966
+ case "json": return [];
967
+ default: return "";
968
+ }
969
+ }
970
+ /**
971
+ * `<input type="date">` に渡せる `yyyy-mm-dd` へ正規化する。
972
+ * 不正な日付は空文字(未入力)にする
973
+ * @param value
974
+ */
975
+ function toDateInputValue(value) {
976
+ if (!value) return "";
977
+ const dateValue = value instanceof Date ? value : new Date(String(value));
978
+ if (Number.isNaN(dateValue.getTime())) return "";
979
+ return dateValue.toISOString().split("T")[0] ?? "";
980
+ }
981
+ /**
982
+ * @param value
983
+ */
984
+ function stringifyJson(value) {
985
+ try {
986
+ return JSON.stringify(value, null, 2);
987
+ } catch {
988
+ return String(value);
989
+ }
990
+ }
991
+ /**
992
+ * @param text
993
+ */
994
+ function isValidJson(text) {
995
+ try {
996
+ JSON.parse(text);
997
+ return true;
998
+ } catch {
999
+ return false;
1000
+ }
1001
+ }
1002
+ var preview_module_default = {
1003
+ img: "_img_18j28_1",
1004
+ uploading: "_uploading_18j28_26",
1005
+ progress: "_progress_18j28_30",
1006
+ meta: "_meta_18j28_40",
1007
+ path: "_path_18j28_60",
1008
+ upload: "_upload_18j28_26",
1009
+ dimension: "_dimension_18j28_72"
628
1010
  };
629
-
630
- function TableEditor({
631
- value,
632
- onChange
633
- }) {
634
- const rootId = useId();
635
- const rows = value.th.map((th, i) => [
636
- th,
637
- value.td[i] ?? ""
638
- ]);
639
- const commit = (next) => {
640
- onChange({
641
- th: next.map(([th]) => th),
642
- td: next.map(([, td]) => td)
643
- });
644
- };
645
- const rootRef = useCommand({
646
- "--add-row": (e) => {
647
- const index = Number(e.source?.value);
648
- commit(rows.toSpliced(index + 1, 0, ["", ""]));
649
- },
650
- "--remove-row": (e) => {
651
- const index = Number(e.source?.value);
652
- commit(rows.toSpliced(index, 1));
653
- },
654
- "--move-row-down": (e) => {
655
- const from = Number(e.source?.value);
656
- const to = from + 1;
657
- const fromRow = rows[from];
658
- const toRow = rows[to];
659
- if (!fromRow || !toRow) {
660
- return;
661
- }
662
- commit(rows.toSpliced(from, 1, toRow).toSpliced(to, 1, fromRow));
663
- }
664
- });
665
- return /* @__PURE__ */ jsx("div", { className: styles$1["table"], ref: rootRef, id: rootId, children: rows.map(([th, td], i) => /* @__PURE__ */ jsxs("div", { className: styles$1["row"], children: [
666
- /* @__PURE__ */ jsx("div", { className: styles$1["th"], children: /* @__PURE__ */ jsx(
667
- "textarea",
668
- {
669
- "aria-label": `${i}行目の見出しセル`,
670
- name: `bge-th-${i}`,
671
- value: th,
672
- onChange: (e) => {
673
- commit(rows.with(i, [e.currentTarget.value, td]));
674
- }
675
- }
676
- ) }),
677
- /* @__PURE__ */ jsx("div", { className: styles$1["td"], children: /* @__PURE__ */ jsx(
678
- "textarea",
679
- {
680
- "aria-label": `${i}行目の内容セル`,
681
- name: `bge-td-${i}`,
682
- value: td,
683
- onChange: (e) => {
684
- commit(rows.with(i, [th, e.currentTarget.value]));
685
- }
686
- }
687
- ) }),
688
- /* @__PURE__ */ jsx("div", { className: styles$1["btn"], children: /* @__PURE__ */ jsxs("ul", { children: [
689
- /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
690
- "button",
691
- {
692
- type: "button",
693
- title: "下に追加",
694
- command: "--add-row",
695
- commandfor: rootId,
696
- value: i,
697
- children: /* @__PURE__ */ jsx(IconRowInsertBottom, {})
698
- }
699
- ) }),
700
- /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
701
- "button",
702
- {
703
- type: "button",
704
- title: "削除",
705
- disabled: rows.length === 1,
706
- command: "--remove-row",
707
- commandfor: rootId,
708
- value: i,
709
- children: /* @__PURE__ */ jsx(IconTrash, {})
710
- }
711
- ) }),
712
- /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
713
- "button",
714
- {
715
- type: "button",
716
- title: "下に移動",
717
- disabled: i === rows.length - 1,
718
- command: "--move-row-down",
719
- commandfor: rootId,
720
- value: i,
721
- children: /* @__PURE__ */ jsx(IconArrowsTransferDown, { className: "icon" })
722
- }
723
- ) })
724
- ] }) })
725
- ] }, i)) });
1011
+ //#endregion
1012
+ //#region src/components/preview.tsx
1013
+ /**
1014
+ * File preview pane. The previewed path comes from the parent (lifted
1015
+ * from the old `file-select` observer event); upload progress stays on
1016
+ * the engine-level component observer.
1017
+ * @param root0
1018
+ * @param root0.engine
1019
+ * @param root0.path
1020
+ * @example
1021
+ * ```tsx
1022
+ * <Preview engine={engine} path={state.path ?? ''} />
1023
+ * ```
1024
+ */
1025
+ function Preview({ engine, path }) {
1026
+ const [dimension, setDimension] = useState(null);
1027
+ const [progress, setProgress] = useState({
1028
+ uploaded: 0,
1029
+ total: 100
1030
+ });
1031
+ const [prevPath, setPrevPath] = useState(path);
1032
+ if (prevPath !== path) {
1033
+ setPrevPath(path);
1034
+ setDimension(null);
1035
+ }
1036
+ const file = path ? getExt(path) : null;
1037
+ const isUploadingMode = path.startsWith("blob:");
1038
+ useComponentEvent(engine, "file-upload-progress", (p) => {
1039
+ if (p.blob === path) setProgress({
1040
+ uploaded: p.uploaded,
1041
+ total: p.total
1042
+ });
1043
+ });
1044
+ useEffect(() => {
1045
+ const file = path ? getExt(path) : null;
1046
+ let aborted = false;
1047
+ if (file?.isImage) {
1048
+ const image = new Image();
1049
+ image.src = path;
1050
+ image.addEventListener("load", () => {
1051
+ if (!aborted) setDimension({
1052
+ width: image.naturalWidth,
1053
+ height: image.naturalHeight
1054
+ });
1055
+ }, { once: true });
1056
+ } else if (file?.isVideo) {
1057
+ const video = document.createElement("video");
1058
+ video.src = path;
1059
+ video.addEventListener("loadedmetadata", () => {
1060
+ if (!aborted) setDimension({
1061
+ width: video.videoWidth,
1062
+ height: video.videoHeight
1063
+ });
1064
+ }, { once: true });
1065
+ }
1066
+ return () => {
1067
+ aborted = true;
1068
+ };
1069
+ }, [path]);
1070
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
1071
+ className: `${preview_module_default["img"]} ${isUploadingMode ? preview_module_default["uploading"] : ""}`.trim(),
1072
+ children: [file?.isImage ? /* @__PURE__ */ jsx("img", {
1073
+ src: path,
1074
+ alt: "画像プレビュー"
1075
+ }) : file?.isVideo ? /* @__PURE__ */ jsxs("video", {
1076
+ controls: true,
1077
+ playsInline: true,
1078
+ children: [/* @__PURE__ */ jsx("source", {
1079
+ src: path,
1080
+ type: `video/${file.ext}`
1081
+ }), /* @__PURE__ */ jsx("track", {
1082
+ kind: "captions",
1083
+ src: ""
1084
+ })]
1085
+ }) : file?.isAudio ? /* @__PURE__ */ jsxs("audio", {
1086
+ controls: true,
1087
+ children: [/* @__PURE__ */ jsx("source", {
1088
+ src: path,
1089
+ type: `audio/${file.ext}`
1090
+ }), /* @__PURE__ */ jsx("track", {
1091
+ kind: "metadata",
1092
+ src: ""
1093
+ })]
1094
+ }) : file?.isDoc || file?.isPpt || file?.isXls || file?.isPdf ? /* @__PURE__ */ jsx("object", {
1095
+ data: path,
1096
+ type: `application/${file.ext}`,
1097
+ title: `${file.ext}ファイルのプレビュー`,
1098
+ children: /* @__PURE__ */ jsx("p", { children: "プレビューできません" })
1099
+ }) : /* @__PURE__ */ jsx("p", { children: "プレビューできません" }), isUploadingMode ? /* @__PURE__ */ jsx("div", {
1100
+ className: preview_module_default["progress"],
1101
+ style: { translate: `${progress.uploaded / progress.total * 100}%` }
1102
+ }) : null]
1103
+ }), /* @__PURE__ */ jsxs("ul", {
1104
+ className: preview_module_default["meta"],
1105
+ children: [isUploadingMode ? /* @__PURE__ */ jsxs("li", {
1106
+ className: preview_module_default["upload"],
1107
+ children: [/* @__PURE__ */ jsx("span", { children: "アップロード..." }), /* @__PURE__ */ jsxs("span", {
1108
+ className: preview_module_default["progress"],
1109
+ children: [
1110
+ Math.round(progress.uploaded / progress.total * 100),
1111
+ "% (",
1112
+ progress.uploaded,
1113
+ "/",
1114
+ progress.total,
1115
+ ")"
1116
+ ]
1117
+ })]
1118
+ }) : /* @__PURE__ */ jsx("li", {
1119
+ className: preview_module_default["path"],
1120
+ children: /* @__PURE__ */ jsx("a", {
1121
+ href: path,
1122
+ target: "_blank",
1123
+ children: path
1124
+ })
1125
+ }), dimension ? /* @__PURE__ */ jsxs("li", {
1126
+ className: preview_module_default["dimension"],
1127
+ children: [
1128
+ dimension.width,
1129
+ "x",
1130
+ dimension.height
1131
+ ]
1132
+ }) : null]
1133
+ })] });
726
1134
  }
727
-
728
- const tablist = "_tablist_1hyld_1";
729
- const styles = {
730
- tablist: tablist
1135
+ var table_editor_module_default = {
1136
+ table: "_table_1qb61_1",
1137
+ row: "_row_1qb61_7",
1138
+ btn: "_btn_1qb61_19"
731
1139
  };
732
-
733
- function Tabs({
734
- current,
735
- onChange,
736
- contentId,
737
- length = 2,
738
- createLabel = (index) => `画像${index + 1}`
739
- }) {
740
- const listId = useId();
741
- const refs = useRef([]);
742
- const update = (index) => {
743
- refs.current[index]?.focus();
744
- onChange(index);
745
- };
746
- const rootRef = useCommand({
747
- "--select-tab": (e) => {
748
- const value = e.source?.value;
749
- update(Number(value));
750
- }
751
- });
752
- const onKeyDown = (event) => {
753
- if (event.key === "ArrowLeft") {
754
- update(Math.max(0, current - 1));
755
- } else if (event.key === "ArrowRight") {
756
- update(Math.min(length - 1, current + 1));
757
- }
758
- };
759
- return /* @__PURE__ */ jsx("div", { role: "tablist", ref: rootRef, id: listId, className: styles["tablist"], children: Array.from({ length }, (_, index) => /* @__PURE__ */ jsx(
760
- "button",
761
- {
762
- ref: (el) => {
763
- refs.current[index] = el;
764
- },
765
- type: "button",
766
- role: "tab",
767
- "aria-controls": contentId,
768
- "aria-selected": current === index,
769
- tabIndex: current === index ? 0 : -1,
770
- command: "--select-tab",
771
- commandfor: listId,
772
- value: index,
773
- onKeyDown,
774
- children: createLabel(index)
775
- },
776
- index
777
- )) });
1140
+ //#endregion
1141
+ //#region src/components/table-editor.tsx
1142
+ /**
1143
+ * Table row editor as a fully controlled component. The table item's
1144
+ * editor owns the state; row operations are declared as local commands.
1145
+ * @param root0
1146
+ * @param root0.value
1147
+ * @param root0.onChange
1148
+ * @example
1149
+ * ```tsx
1150
+ * <TableEditor
1151
+ * value={{ th: state.th ?? [], td: state.td ?? [] }}
1152
+ * onChange={({ th, td }) => setState({ ...state, th: [...th], td: [...td] })}
1153
+ * />
1154
+ * ```
1155
+ */
1156
+ function TableEditor({ value, onChange }) {
1157
+ const rootId = useId();
1158
+ const rows = value.th.map((th, i) => [th, value.td[i] ?? ""]);
1159
+ const commit = (next) => {
1160
+ onChange({
1161
+ th: next.map(([th]) => th),
1162
+ td: next.map(([, td]) => td)
1163
+ });
1164
+ };
1165
+ const rootRef = useCommand({
1166
+ "--add-row": (e) => {
1167
+ const index = Number(e.source?.value);
1168
+ commit(rows.toSpliced(index + 1, 0, ["", ""]));
1169
+ },
1170
+ "--remove-row": (e) => {
1171
+ const index = Number(e.source?.value);
1172
+ commit(rows.toSpliced(index, 1));
1173
+ },
1174
+ "--move-row-down": (e) => {
1175
+ const from = Number(e.source?.value);
1176
+ const to = from + 1;
1177
+ const fromRow = rows[from];
1178
+ const toRow = rows[to];
1179
+ if (!fromRow || !toRow) return;
1180
+ commit(rows.toSpliced(from, 1, toRow).toSpliced(to, 1, fromRow));
1181
+ }
1182
+ });
1183
+ return /* @__PURE__ */ jsx("div", {
1184
+ className: table_editor_module_default["table"],
1185
+ ref: rootRef,
1186
+ id: rootId,
1187
+ children: rows.map(([th, td], i) => /* @__PURE__ */ jsxs("div", {
1188
+ className: table_editor_module_default["row"],
1189
+ children: [
1190
+ /* @__PURE__ */ jsx("div", {
1191
+ className: table_editor_module_default["th"],
1192
+ children: /* @__PURE__ */ jsx("textarea", {
1193
+ "aria-label": `${i}行目の見出しセル`,
1194
+ name: `bge-th-${i}`,
1195
+ value: th,
1196
+ onChange: (e) => {
1197
+ commit(rows.with(i, [e.currentTarget.value, td]));
1198
+ }
1199
+ })
1200
+ }),
1201
+ /* @__PURE__ */ jsx("div", {
1202
+ className: table_editor_module_default["td"],
1203
+ children: /* @__PURE__ */ jsx("textarea", {
1204
+ "aria-label": `${i}行目の内容セル`,
1205
+ name: `bge-td-${i}`,
1206
+ value: td,
1207
+ onChange: (e) => {
1208
+ commit(rows.with(i, [th, e.currentTarget.value]));
1209
+ }
1210
+ })
1211
+ }),
1212
+ /* @__PURE__ */ jsx("div", {
1213
+ className: table_editor_module_default["btn"],
1214
+ children: /* @__PURE__ */ jsxs("ul", { children: [
1215
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1216
+ type: "button",
1217
+ title: "下に追加",
1218
+ command: "--add-row",
1219
+ commandfor: rootId,
1220
+ value: i,
1221
+ children: /* @__PURE__ */ jsx(IconRowInsertBottom, {})
1222
+ }) }),
1223
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1224
+ type: "button",
1225
+ title: "削除",
1226
+ disabled: rows.length === 1,
1227
+ command: "--remove-row",
1228
+ commandfor: rootId,
1229
+ value: i,
1230
+ children: /* @__PURE__ */ jsx(IconTrash, {})
1231
+ }) }),
1232
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
1233
+ type: "button",
1234
+ title: "下に移動",
1235
+ disabled: i === rows.length - 1,
1236
+ command: "--move-row-down",
1237
+ commandfor: rootId,
1238
+ value: i,
1239
+ children: /* @__PURE__ */ jsx(IconArrowsTransferDown, { className: "icon" })
1240
+ }) })
1241
+ ] })
1242
+ })
1243
+ ]
1244
+ }, i))
1245
+ });
778
1246
  }
779
-
780
- function WysiwygField({
781
- value,
782
- onChange,
783
- itemName,
784
- commands,
785
- label
786
- }) {
787
- const ref = useRef(null);
788
- const initialValue = useRef(value);
789
- const onChangeRef = useRef(onChange);
790
- useEffect(() => {
791
- onChangeRef.current = onChange;
792
- });
793
- useEffect(() => {
794
- const el = ref.current;
795
- if (!el) {
796
- return;
797
- }
798
- el.innerHTML = initialValue.current;
799
- const inner = el.querySelector("bge-wysiwyg");
800
- const onTransaction = () => {
801
- onChangeRef.current(el.value);
802
- };
803
- inner?.addEventListener("transaction", onTransaction);
804
- return () => {
805
- inner?.removeEventListener("transaction", onTransaction);
806
- };
807
- }, []);
808
- return /* @__PURE__ */ jsx(
809
- "bge-wysiwyg-editor",
810
- {
811
- ref: (el) => {
812
- ref.current = el;
813
- },
814
- "item-name": itemName,
815
- commands,
816
- label
817
- }
818
- );
1247
+ var tabs_module_default = { tablist: "_tablist_1hyld_1" };
1248
+ //#endregion
1249
+ //#region src/components/tabs.tsx
1250
+ /**
1251
+ * Controlled tab list. Selection is lifted to the parent via
1252
+ * `current`/`onChange`; tab buttons declare a local command instead of a
1253
+ * click handler. Arrow keys move the selection. The tab panel itself is
1254
+ * rendered by the parent, which also owns its `aria-label`.
1255
+ * @param root0
1256
+ * @param root0.current
1257
+ * @param root0.onChange
1258
+ * @param root0.contentId
1259
+ * @param root0.length
1260
+ * @param root0.createLabel
1261
+ * @example
1262
+ * ```tsx
1263
+ * <Tabs current={currentIndex} onChange={setCurrentIndex} contentId="tab-content" />
1264
+ * <div id="tab-content" role="tabpanel" aria-label={`画像${currentIndex + 1}`}>
1265
+ * {currentIndex === 0 ? <PcForm /> : <SpForm />}
1266
+ * </div>
1267
+ * ```
1268
+ */
1269
+ function Tabs({ current, onChange, contentId, length = 2, createLabel = (index) => `画像${index + 1}` }) {
1270
+ const listId = useId();
1271
+ const refs = useRef([]);
1272
+ const update = (index) => {
1273
+ refs.current[index]?.focus();
1274
+ onChange(index);
1275
+ };
1276
+ const rootRef = useCommand({ "--select-tab": (e) => {
1277
+ const value = e.source?.value;
1278
+ update(Number(value));
1279
+ } });
1280
+ const onKeyDown = (event) => {
1281
+ if (event.key === "ArrowLeft") update(Math.max(0, current - 1));
1282
+ else if (event.key === "ArrowRight") update(Math.min(length - 1, current + 1));
1283
+ };
1284
+ return /* @__PURE__ */ jsx("div", {
1285
+ role: "tablist",
1286
+ ref: rootRef,
1287
+ id: listId,
1288
+ className: tabs_module_default["tablist"],
1289
+ children: Array.from({ length }, (_, index) => /* @__PURE__ */ jsx("button", {
1290
+ ref: (el) => {
1291
+ refs.current[index] = el;
1292
+ },
1293
+ type: "button",
1294
+ role: "tab",
1295
+ "aria-controls": contentId,
1296
+ "aria-selected": current === index,
1297
+ tabIndex: current === index ? 0 : -1,
1298
+ command: "--select-tab",
1299
+ commandfor: listId,
1300
+ value: index,
1301
+ onKeyDown,
1302
+ children: createLabel(index)
1303
+ }, index))
1304
+ });
819
1305
  }
820
-
821
- function Checkbox({
822
- label,
823
- checked,
824
- onChange,
825
- name,
826
- disabled,
827
- describedBy
828
- }) {
829
- return /* @__PURE__ */ jsxs("label", { children: [
830
- /* @__PURE__ */ jsx(
831
- "input",
832
- {
833
- type: "checkbox",
834
- name,
835
- checked,
836
- disabled,
837
- "aria-describedby": describedBy,
838
- onChange: (e) => onChange(e.currentTarget.checked)
839
- }
840
- ),
841
- label
842
- ] });
1306
+ //#endregion
1307
+ //#region src/components/wysiwyg-field.tsx
1308
+ /**
1309
+ * Rich text field backed by the `<bge-wysiwyg-editor>` custom element
1310
+ * (TipTap). The element manages its own DOM; this wrapper feeds the
1311
+ * initial value and lifts edits into the editor state via the
1312
+ * `transaction` event.
1313
+ * @param root0
1314
+ * @param root0.value
1315
+ * @param root0.onChange
1316
+ * @param root0.itemName
1317
+ * @param root0.commands
1318
+ * @param root0.label
1319
+ * @example
1320
+ * ```tsx
1321
+ * <WysiwygField
1322
+ * itemName="wysiwyg"
1323
+ * value={state.wysiwyg ?? ''}
1324
+ * onChange={(wysiwyg) => setState({ ...state, wysiwyg })}
1325
+ * />
1326
+ * ```
1327
+ */
1328
+ function WysiwygField({ value, onChange, itemName, commands, label }) {
1329
+ const ref = useRef(null);
1330
+ const initialValue = useRef(value);
1331
+ const onChangeRef = useRef(onChange);
1332
+ useEffect(() => {
1333
+ onChangeRef.current = onChange;
1334
+ });
1335
+ useEffect(() => {
1336
+ const el = ref.current;
1337
+ if (!el) return;
1338
+ el.innerHTML = initialValue.current;
1339
+ const inner = el.querySelector("bge-wysiwyg");
1340
+ const onTransaction = () => {
1341
+ onChangeRef.current(el.value);
1342
+ };
1343
+ inner?.addEventListener("transaction", onTransaction);
1344
+ return () => {
1345
+ inner?.removeEventListener("transaction", onTransaction);
1346
+ };
1347
+ }, []);
1348
+ return /* @__PURE__ */ jsx("bge-wysiwyg-editor", {
1349
+ ref: (el) => {
1350
+ ref.current = el;
1351
+ },
1352
+ "item-name": itemName,
1353
+ commands,
1354
+ label
1355
+ });
843
1356
  }
844
-
845
- function Fieldset({
846
- legend,
847
- id,
848
- disabled,
849
- children
850
- }) {
851
- return /* @__PURE__ */ jsxs("fieldset", { id, disabled, children: [
852
- /* @__PURE__ */ jsx("legend", { children: legend }),
853
- children
854
- ] });
1357
+ //#endregion
1358
+ //#region src/form/checkbox.tsx
1359
+ /**
1360
+ * Controlled checkbox following the editor form markup convention
1361
+ * (`label > input + text`).
1362
+ *
1363
+ * The structure is a styling contract: `ui.css` turns
1364
+ * `label:not([for]):has(input[type='checkbox'])` into a flex row, so it
1365
+ * must be preserved.
1366
+ * @param root0
1367
+ * @param root0.label
1368
+ * @param root0.checked
1369
+ * @param root0.onChange
1370
+ * @param root0.name
1371
+ * @param root0.disabled
1372
+ * @param root0.describedBy
1373
+ * @example
1374
+ * ```tsx
1375
+ * <Checkbox
1376
+ * label={<span>横スクロール可能</span>}
1377
+ * name="bge-scrollable"
1378
+ * checked={state.scrollable ?? false}
1379
+ * onChange={(scrollable) => setState({ ...state, scrollable })}
1380
+ * />
1381
+ * ```
1382
+ */
1383
+ function Checkbox({ label, checked, onChange, name, disabled, describedBy }) {
1384
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
1385
+ type: "checkbox",
1386
+ name,
1387
+ checked,
1388
+ disabled,
1389
+ "aria-describedby": describedBy,
1390
+ onChange: (e) => onChange(e.currentTarget.checked)
1391
+ }), label] });
855
1392
  }
856
-
857
- function NumberField({
858
- label,
859
- value,
860
- onChange,
861
- name,
862
- min,
863
- max,
864
- step,
865
- disabled
866
- }) {
867
- return /* @__PURE__ */ jsxs("label", { children: [
868
- /* @__PURE__ */ jsx("span", { children: label }),
869
- /* @__PURE__ */ jsx(
870
- "input",
871
- {
872
- type: "number",
873
- name,
874
- value: Number.isFinite(value) ? value : "",
875
- min,
876
- max,
877
- step,
878
- disabled,
879
- onChange: (e) => onChange(e.currentTarget.valueAsNumber)
880
- }
881
- )
882
- ] });
1393
+ //#endregion
1394
+ //#region src/form/fieldset.tsx
1395
+ /**
1396
+ * Grouping fieldset following the editor form markup convention
1397
+ * (`fieldset > legend`).
1398
+ *
1399
+ * The structure is a styling contract: `ui.css` draws the group border
1400
+ * and spacing on the `fieldset` element itself, so it must be preserved.
1401
+ * @param root0
1402
+ * @param root0.legend
1403
+ * @param root0.id
1404
+ * @param root0.disabled
1405
+ * @param root0.children
1406
+ * @example
1407
+ * ```tsx
1408
+ * <Fieldset legend="リンク設定" disabled={!state.useLink}>
1409
+ * <TextField
1410
+ * label="URL"
1411
+ * name="bge-href"
1412
+ * value={state.href ?? ''}
1413
+ * onChange={(href) => setState({ ...state, href })}
1414
+ * />
1415
+ * </Fieldset>
1416
+ * ```
1417
+ */
1418
+ function Fieldset({ legend, id, disabled, children }) {
1419
+ return /* @__PURE__ */ jsxs("fieldset", {
1420
+ id,
1421
+ disabled,
1422
+ children: [/* @__PURE__ */ jsx("legend", { children: legend }), children]
1423
+ });
883
1424
  }
884
-
885
- function RadioGroup({
886
- label,
887
- value,
888
- onChange,
889
- options,
890
- name,
891
- disabled
892
- }) {
893
- const labelId = useId();
894
- return /* @__PURE__ */ jsxs("div", { role: "radiogroup", "aria-labelledby": labelId, children: [
895
- /* @__PURE__ */ jsx("div", { id: labelId, children: label }),
896
- options.map((option) => /* @__PURE__ */ jsxs("label", { children: [
897
- /* @__PURE__ */ jsx(
898
- "input",
899
- {
900
- type: "radio",
901
- name,
902
- value: option.value,
903
- checked: value === option.value,
904
- disabled,
905
- onChange: (e) => {
906
- if (e.currentTarget.checked) {
907
- onChange(option.value);
908
- }
909
- }
910
- }
911
- ),
912
- option.label
913
- ] }, option.value))
914
- ] });
1425
+ //#endregion
1426
+ //#region src/form/number-field.tsx
1427
+ /**
1428
+ * Controlled numeric input following the editor form markup convention.
1429
+ *
1430
+ * The `label > span + input` structure is a styling contract: `ui.css`
1431
+ * lays out fields with structural selectors
1432
+ * (`label:not([for]) > span:has(+ input)`), so it must be preserved.
1433
+ * @param root0
1434
+ * @param root0.label
1435
+ * @param root0.value
1436
+ * @param root0.onChange
1437
+ * @param root0.name
1438
+ * @param root0.min
1439
+ * @param root0.max
1440
+ * @param root0.step
1441
+ * @param root0.disabled
1442
+ * @example
1443
+ * ```tsx
1444
+ * <NumberField
1445
+ * label="表示件数"
1446
+ * name="bge-count"
1447
+ * value={state.count ?? 1}
1448
+ * min={1}
1449
+ * onChange={(count) => setState({ ...state, count })}
1450
+ * />
1451
+ * ```
1452
+ */
1453
+ function NumberField({ label, value, onChange, name, min, max, step, disabled }) {
1454
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsx("input", {
1455
+ type: "number",
1456
+ name,
1457
+ value: Number.isFinite(value) ? value : "",
1458
+ min,
1459
+ max,
1460
+ step,
1461
+ disabled,
1462
+ onChange: (e) => onChange(e.currentTarget.valueAsNumber)
1463
+ })] });
915
1464
  }
916
-
917
- function SelectField({
918
- label,
919
- value,
920
- onChange,
921
- options,
922
- name,
923
- disabled
924
- }) {
925
- return /* @__PURE__ */ jsxs("label", { children: [
926
- /* @__PURE__ */ jsx("span", { children: label }),
927
- /* @__PURE__ */ jsx(
928
- "select",
929
- {
930
- name,
931
- value,
932
- disabled,
933
- onChange: (e) => onChange(e.currentTarget.value),
934
- children: options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value))
935
- }
936
- )
937
- ] });
1465
+ //#endregion
1466
+ //#region src/form/radio-group.tsx
1467
+ /**
1468
+ * Controlled radio group following the editor form markup convention
1469
+ * (`div[role=radiogroup] > label > input + text`).
1470
+ *
1471
+ * The structure is a styling contract: `ui.css` lays out the group via
1472
+ * `[role='radiogroup'] > label` (and appends `:` to the group label), so
1473
+ * it must be preserved.
1474
+ * @param root0
1475
+ * @param root0.label
1476
+ * @param root0.value
1477
+ * @param root0.onChange
1478
+ * @param root0.options
1479
+ * @param root0.name
1480
+ * @param root0.disabled
1481
+ * @example
1482
+ * ```tsx
1483
+ * <RadioGroup
1484
+ * label="配置"
1485
+ * name="bge-align"
1486
+ * value={state.align ?? 'start'}
1487
+ * options={[
1488
+ * { value: 'start', label: '左寄せ' },
1489
+ * { value: 'end', label: '右寄せ' },
1490
+ * ]}
1491
+ * onChange={(align) => setState({ ...state, align })}
1492
+ * />
1493
+ * ```
1494
+ */
1495
+ function RadioGroup({ label, value, onChange, options, name, disabled }) {
1496
+ const labelId = useId();
1497
+ return /* @__PURE__ */ jsxs("div", {
1498
+ role: "radiogroup",
1499
+ "aria-labelledby": labelId,
1500
+ children: [/* @__PURE__ */ jsx("div", {
1501
+ id: labelId,
1502
+ children: label
1503
+ }), options.map((option) => /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
1504
+ type: "radio",
1505
+ name,
1506
+ value: option.value,
1507
+ checked: value === option.value,
1508
+ disabled,
1509
+ onChange: (e) => {
1510
+ if (e.currentTarget.checked) onChange(option.value);
1511
+ }
1512
+ }), option.label] }, option.value))]
1513
+ });
938
1514
  }
939
-
940
- function TextArea({
941
- label,
942
- value,
943
- onChange,
944
- name,
945
- rows,
946
- disabled
947
- }) {
948
- return /* @__PURE__ */ jsxs("label", { children: [
949
- /* @__PURE__ */ jsx("span", { children: label }),
950
- /* @__PURE__ */ jsx(
951
- "textarea",
952
- {
953
- name,
954
- value,
955
- rows,
956
- disabled,
957
- onChange: (e) => onChange(e.currentTarget.value)
958
- }
959
- )
960
- ] });
1515
+ //#endregion
1516
+ //#region src/form/select-field.tsx
1517
+ /**
1518
+ * Controlled select following the editor form markup convention
1519
+ * (`label > span + select`).
1520
+ *
1521
+ * The structure is a styling contract: `ui.css` lays out fields with
1522
+ * structural selectors (`label:not([for]) > span:has(+ select)`), so it
1523
+ * must be preserved.
1524
+ * @param root0
1525
+ * @param root0.label
1526
+ * @param root0.value
1527
+ * @param root0.onChange
1528
+ * @param root0.options
1529
+ * @param root0.name
1530
+ * @param root0.disabled
1531
+ * @example
1532
+ * ```tsx
1533
+ * <SelectField
1534
+ * label="種類"
1535
+ * name="bge-kind"
1536
+ * value={state.kind ?? 'normal'}
1537
+ * options={[
1538
+ * { value: 'normal', label: '通常' },
1539
+ * { value: 'wide', label: 'ワイド' },
1540
+ * ]}
1541
+ * onChange={(kind) => setState({ ...state, kind })}
1542
+ * />
1543
+ * ```
1544
+ */
1545
+ function SelectField({ label, value, onChange, options, name, disabled }) {
1546
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsx("select", {
1547
+ name,
1548
+ value,
1549
+ disabled,
1550
+ onChange: (e) => onChange(e.currentTarget.value),
1551
+ children: options.map((option) => /* @__PURE__ */ jsx("option", {
1552
+ value: option.value,
1553
+ children: option.label
1554
+ }, option.value))
1555
+ })] });
961
1556
  }
962
-
963
- function TextField({
964
- label,
965
- value,
966
- onChange,
967
- type = "text",
968
- name,
969
- disabled,
970
- placeholder
971
- }) {
972
- return /* @__PURE__ */ jsxs("label", { children: [
973
- /* @__PURE__ */ jsx("span", { children: label }),
974
- /* @__PURE__ */ jsx(
975
- "input",
976
- {
977
- type,
978
- name,
979
- value,
980
- disabled,
981
- placeholder,
982
- onChange: (e) => onChange(e.currentTarget.value)
983
- }
984
- )
985
- ] });
1557
+ //#endregion
1558
+ //#region src/form/text-area.tsx
1559
+ /**
1560
+ * Controlled multi-line text input following the editor form markup
1561
+ * convention.
1562
+ *
1563
+ * The `label > span + textarea` structure is a styling contract: `ui.css`
1564
+ * lays out fields with structural selectors
1565
+ * (`label:not([for]) > span:has(+ textarea)`), so it must be preserved.
1566
+ * @param root0
1567
+ * @param root0.label
1568
+ * @param root0.value
1569
+ * @param root0.onChange
1570
+ * @param root0.name
1571
+ * @param root0.rows
1572
+ * @param root0.disabled
1573
+ * @example
1574
+ * ```tsx
1575
+ * <TextArea
1576
+ * label="説明文"
1577
+ * name="bge-text"
1578
+ * value={state.text ?? ''}
1579
+ * onChange={(text) => setState({ ...state, text })}
1580
+ * />
1581
+ * ```
1582
+ */
1583
+ function TextArea({ label, value, onChange, name, rows, disabled }) {
1584
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsx("textarea", {
1585
+ name,
1586
+ value,
1587
+ rows,
1588
+ disabled,
1589
+ onChange: (e) => onChange(e.currentTarget.value)
1590
+ })] });
1591
+ }
1592
+ //#endregion
1593
+ //#region src/form/text-field.tsx
1594
+ /**
1595
+ * Controlled single-line text input following the editor form markup
1596
+ * convention (`label > span + input`).
1597
+ *
1598
+ * The structure is a styling contract: `ui.css` lays out fields with
1599
+ * structural selectors (`label:not([for]) > span:has(+ input)`) instead
1600
+ * of `for`/`id` wiring, so it must be preserved.
1601
+ * @param root0
1602
+ * @param root0.label
1603
+ * @param root0.value
1604
+ * @param root0.onChange
1605
+ * @param root0.type
1606
+ * @param root0.name
1607
+ * @param root0.disabled
1608
+ * @param root0.placeholder
1609
+ * @example
1610
+ * ```tsx
1611
+ * <TextField
1612
+ * label="URL"
1613
+ * name="bge-link"
1614
+ * value={state.href ?? ''}
1615
+ * onChange={(href) => setState({ ...state, href })}
1616
+ * />
1617
+ * ```
1618
+ */
1619
+ function TextField({ label, value, onChange, type = "text", name, disabled, placeholder }) {
1620
+ return /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsx("input", {
1621
+ type,
1622
+ name,
1623
+ value,
1624
+ disabled,
1625
+ placeholder,
1626
+ onChange: (e) => onChange(e.currentTarget.value)
1627
+ })] });
986
1628
  }
1629
+ //#endregion
1630
+ export { BlockCatalog, BlockMenu, BlockMenuButton, BlockMenuView, BlockOptions, Checkbox, DraftSwitcher, EditableAreaView, EditorDialog, Fieldset, FileList, FileUploader, FrontMatterEditorView, InitialInsertionButton, ItemEditorHost, NumberField, Preview, RadioGroup, SelectField, TableEditor, Tabs, TextArea, TextField, Thumbnail, WysiwygField, createFrontMatterEditor, reactMount, registerEngineCommands, useCommand, useComponentEvent, useUIState };
987
1631
 
988
- export { Checkbox, Fieldset, FileList, FileUploader, NumberField, Preview, RadioGroup, SelectField, TableEditor, Tabs, TextArea, TextField, Thumbnail, WysiwygField, useCommand, useComponentEvent };
989
- //# sourceMappingURL=ui.js.map
1632
+ //# sourceMappingURL=ui.js.map