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

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