@burger-editor/client 4.0.0-alpha.70 → 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/README.md +93 -242
- package/dist/animate-insertion.d.ts +17 -0
- package/dist/animate-insertion.d.ts.map +1 -0
- package/dist/burger-editor-root.d.ts +11 -0
- package/dist/burger-editor-root.d.ts.map +1 -0
- package/dist/client.css +465 -434
- package/dist/client.js +26083 -48423
- package/dist/client.js.map +1 -1
- package/dist/commands/register-engine-commands.d.ts +17 -0
- package/dist/commands/register-engine-commands.d.ts.map +1 -0
- package/dist/components/block-catalog.d.ts +20 -0
- package/dist/components/block-catalog.d.ts.map +1 -0
- package/dist/components/block-menu-button.d.ts +28 -0
- package/dist/components/block-menu-button.d.ts.map +1 -0
- package/dist/components/block-menu-view.d.ts +78 -0
- package/dist/components/block-menu-view.d.ts.map +1 -0
- package/dist/components/block-menu.d.ts +28 -0
- package/dist/components/block-menu.d.ts.map +1 -0
- package/dist/components/block-options.d.ts +25 -0
- package/dist/components/block-options.d.ts.map +1 -0
- package/dist/components/draft-switcher.d.ts +23 -0
- package/dist/components/draft-switcher.d.ts.map +1 -0
- package/dist/components/editable-area-view.d.ts +44 -0
- package/dist/components/editable-area-view.d.ts.map +1 -0
- package/dist/components/file-list.d.ts +19 -0
- package/dist/components/file-list.d.ts.map +1 -0
- package/dist/components/file-uploader.d.ts +18 -0
- package/dist/components/file-uploader.d.ts.map +1 -0
- package/dist/components/front-matter-editor.d.ts +72 -0
- package/dist/components/front-matter-editor.d.ts.map +1 -0
- package/dist/components/index.d.ts +21 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/initial-insertion-button.d.ts +10 -0
- package/dist/components/initial-insertion-button.d.ts.map +1 -0
- package/dist/components/item-editor-host.d.ts +23 -0
- package/dist/components/item-editor-host.d.ts.map +1 -0
- package/dist/components/preview.d.ts +18 -0
- package/dist/components/preview.d.ts.map +1 -0
- package/dist/components/table-editor.d.ts +28 -0
- package/dist/components/table-editor.d.ts.map +1 -0
- package/dist/components/tabs.d.ts +27 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/thumbnail.d.ts +17 -0
- package/dist/components/thumbnail.d.ts.map +1 -0
- package/dist/components/wysiwyg-field.d.ts +40 -0
- package/dist/components/wysiwyg-field.d.ts.map +1 -0
- package/dist/editable-area-view-C00DSDVk.js +17510 -0
- package/dist/editable-area-view-C00DSDVk.js.map +1 -0
- package/dist/editor-dialog.d.ts +41 -0
- package/dist/editor-dialog.d.ts.map +1 -0
- package/dist/form/checkbox.d.ts +34 -0
- package/dist/form/checkbox.d.ts.map +1 -0
- package/dist/form/fieldset.d.ts +31 -0
- package/dist/form/fieldset.d.ts.map +1 -0
- package/dist/form/index.d.ts +8 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/number-field.d.ts +37 -0
- package/dist/form/number-field.d.ts.map +1 -0
- package/dist/form/radio-group.d.ts +38 -0
- package/dist/form/radio-group.d.ts.map +1 -0
- package/dist/form/select-field.d.ts +38 -0
- package/dist/form/select-field.d.ts.map +1 -0
- package/dist/form/text-area.d.ts +33 -0
- package/dist/form/text-area.d.ts.map +1 -0
- package/dist/form/text-field.d.ts +35 -0
- package/dist/form/text-field.d.ts.map +1 -0
- package/dist/index.d.ts +37 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/invoker-commands.d.ts +24 -0
- package/dist/invoker-commands.d.ts.map +1 -0
- package/dist/mount.d.ts +19 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/ui.d.ts +10 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +1632 -0
- package/dist/ui.js.map +1 -0
- package/dist/use-command.d.ts +29 -0
- package/dist/use-command.d.ts.map +1 -0
- package/dist/use-engine.d.ts +53 -0
- package/dist/use-engine.d.ts.map +1 -0
- package/dist/view/create-react-view.d.ts +17 -0
- package/dist/view/create-react-view.d.ts.map +1 -0
- package/package.json +25 -13
- package/dist/block-catalog.svelte.d.ts +0 -1
- package/dist/block-menu-button.svelte.d.ts +0 -1
- package/dist/block-menu.svelte.d.ts +0 -1
- package/dist/block-options.svelte.d.ts +0 -1
- package/dist/draft-switcher.svelte.d.ts +0 -1
- package/dist/engine-state.svelte.d.ts +0 -42
- package/dist/engine-state.svelte.d.ts.map +0 -1
- package/dist/file-list.svelte.d.ts +0 -1
- package/dist/file-uploader.svelte.d.ts +0 -1
- package/dist/initial-insertion-button.svelte.d.ts +0 -1
- package/dist/preview.svelte.d.ts +0 -1
- package/dist/svelte-mount.d.ts +0 -10
- package/dist/svelte-mount.d.ts.map +0 -1
- package/dist/table-editor.svelte.d.ts +0 -1
- package/dist/tabs.svelte.d.ts +0 -1
- package/dist/thumbnail.svelte.d.ts +0 -1
package/dist/ui.js
ADDED
|
@@ -0,0 +1,1632 @@
|
|
|
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";
|
|
5
|
+
/**
|
|
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
|
+
]);
|
|
37
|
+
/**
|
|
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
|
+
]);
|
|
65
|
+
/**
|
|
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
|
+
]);
|
|
97
|
+
/**
|
|
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
|
+
]);
|
|
133
|
+
/**
|
|
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
|
+
]);
|
|
165
|
+
/**
|
|
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
|
+
}]]);
|
|
178
|
+
/**
|
|
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
|
+
]);
|
|
198
|
+
/**
|
|
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",
|
|
216
|
+
"delete": "_delete_1vnsv_39",
|
|
217
|
+
file: "_file_1vnsv_44",
|
|
218
|
+
thumbnail: "_thumbnail_1vnsv_58",
|
|
219
|
+
attr: "_attr_1vnsv_65"
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/get-ext.ts
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
* @param src
|
|
226
|
+
*/
|
|
227
|
+
function getExt(src) {
|
|
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
|
+
};
|
|
257
|
+
}
|
|
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
|
+
*/
|
|
274
|
+
function Thumbnail({ src }) {
|
|
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
|
+
});
|
|
302
|
+
}
|
|
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
|
+
});
|
|
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
|
+
*/
|
|
523
|
+
function scrollToSelected(el) {
|
|
524
|
+
el?.scrollIntoView({
|
|
525
|
+
behavior: "smooth",
|
|
526
|
+
block: "nearest"
|
|
527
|
+
});
|
|
528
|
+
}
|
|
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
|
+
});
|
|
598
|
+
}
|
|
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
|
+
};
|
|
641
|
+
}
|
|
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"
|
|
1010
|
+
};
|
|
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
|
+
})] });
|
|
1134
|
+
}
|
|
1135
|
+
var table_editor_module_default = {
|
|
1136
|
+
table: "_table_1qb61_1",
|
|
1137
|
+
row: "_row_1qb61_7",
|
|
1138
|
+
btn: "_btn_1qb61_19"
|
|
1139
|
+
};
|
|
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
|
+
});
|
|
1246
|
+
}
|
|
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
|
+
});
|
|
1305
|
+
}
|
|
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
|
+
});
|
|
1356
|
+
}
|
|
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] });
|
|
1392
|
+
}
|
|
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
|
+
});
|
|
1424
|
+
}
|
|
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
|
+
})] });
|
|
1464
|
+
}
|
|
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
|
+
});
|
|
1514
|
+
}
|
|
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
|
+
})] });
|
|
1556
|
+
}
|
|
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
|
+
})] });
|
|
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 };
|
|
1631
|
+
|
|
1632
|
+
//# sourceMappingURL=ui.js.map
|