@kerfjs/ui 5.0.0-beta.129 → 5.0.0-beta.130

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 (170) hide show
  1. package/ai/component-catalog.json +14 -9
  2. package/ai/component-composition-rules.json +1 -1
  3. package/ai/component-composition.d.ts +17 -0
  4. package/ai/component-composition.json +4 -3
  5. package/ai/component-composition.schema.json +326 -80
  6. package/ai/component-props-overlay.json +8568 -628
  7. package/ai/component-props-overlay.schema.json +15 -1
  8. package/ai/component-props.json +6221 -2069
  9. package/ai/component-props.schema.json +7 -0
  10. package/ai/components/radio-group.md +5 -1
  11. package/ai/components/state-banner.md +1 -1
  12. package/ai/components/surface-scaffold.md +3 -2
  13. package/ai/components/tab-bar.md +1 -1
  14. package/ai/components/toolbar-control-group.md +1 -1
  15. package/ai/public-api-signatures-v1.md +205 -42
  16. package/ai/skill.md +21 -8
  17. package/ai/view-document.schema.json +140 -86
  18. package/ai/webawesome-jsx-signatures-v1.md +1 -1
  19. package/dist/browser/column-explorer.js +5 -1
  20. package/dist/browser/radio-group.js +1 -0
  21. package/dist/catalog-resources.d.ts +2 -2
  22. package/dist/catalog.d.ts +2 -2
  23. package/dist/catalog.js +5 -5
  24. package/dist/{chunk-E2MTHHLS.js → chunk-2FA3SX57.js} +2 -2
  25. package/dist/{chunk-E2MTHHLS.js.map → chunk-2FA3SX57.js.map} +1 -1
  26. package/dist/{chunk-ZC4KSRAF.js → chunk-4CYCJ3NY.js} +6 -4
  27. package/dist/chunk-4CYCJ3NY.js.map +1 -0
  28. package/dist/{chunk-IMXLOMTF.js → chunk-76BLSFEA.js} +30 -12
  29. package/dist/chunk-76BLSFEA.js.map +1 -0
  30. package/dist/{chunk-IR32NI2O.js → chunk-ALBFHXMZ.js} +3 -3
  31. package/dist/chunk-ALBFHXMZ.js.map +1 -0
  32. package/dist/{chunk-3ZWYGGEC.js → chunk-ASU4ODOH.js} +38 -7
  33. package/dist/chunk-ASU4ODOH.js.map +1 -0
  34. package/dist/chunk-BMUYZKXW.js +155 -0
  35. package/dist/chunk-BMUYZKXW.js.map +1 -0
  36. package/dist/{chunk-GQUDCWOD.js → chunk-D2KHQNJ6.js} +49 -23
  37. package/dist/chunk-D2KHQNJ6.js.map +1 -0
  38. package/dist/{chunk-34FWYJX6.js → chunk-ECJHCPBN.js} +8 -2
  39. package/dist/chunk-ECJHCPBN.js.map +1 -0
  40. package/dist/{chunk-DBCDYBZP.js → chunk-HHEBNP6Z.js} +2 -2
  41. package/dist/{chunk-DBCDYBZP.js.map → chunk-HHEBNP6Z.js.map} +1 -1
  42. package/dist/{chunk-3ZKUXWAV.js → chunk-IPYQYLSX.js} +16 -9
  43. package/dist/chunk-IPYQYLSX.js.map +1 -0
  44. package/dist/{chunk-SJEPM5ZU.js → chunk-LETAE6SX.js} +2 -2
  45. package/dist/{chunk-SJEPM5ZU.js.map → chunk-LETAE6SX.js.map} +1 -1
  46. package/dist/chunk-MVWR5WRX.js +99 -0
  47. package/dist/chunk-MVWR5WRX.js.map +1 -0
  48. package/dist/{chunk-6T7AX365.js → chunk-OSL4LQ7T.js} +52 -23
  49. package/dist/chunk-OSL4LQ7T.js.map +1 -0
  50. package/dist/{chunk-OHT2AXER.js → chunk-QSJAIXLM.js} +19 -3
  51. package/dist/chunk-QSJAIXLM.js.map +1 -0
  52. package/dist/{chunk-UQ4FRQ6M.js → chunk-R4JK2C6D.js} +13 -3
  53. package/dist/chunk-R4JK2C6D.js.map +1 -0
  54. package/dist/{chunk-5A2DN3LR.js → chunk-SGYBIKQA.js} +3 -1
  55. package/dist/chunk-SGYBIKQA.js.map +1 -0
  56. package/dist/{chunk-K3C35KGR.js → chunk-XO5IOPM5.js} +2 -2
  57. package/dist/{chunk-K3C35KGR.js.map → chunk-XO5IOPM5.js.map} +1 -1
  58. package/dist/collapsible-panel.d.ts +2 -2
  59. package/dist/collapsible-panel.js +2 -2
  60. package/dist/column-explorer.d.ts +5 -1
  61. package/dist/column-explorer.js +5 -1
  62. package/dist/column-track.d.ts +3 -1
  63. package/dist/column-track.js +1 -1
  64. package/dist/editor.d.ts +87 -2
  65. package/dist/editor.js +2249 -1320
  66. package/dist/editor.js.map +1 -1
  67. package/dist/index.js +12 -12
  68. package/dist/list-detail-dialog.d.ts +2 -2
  69. package/dist/list-detail-dialog.js +4 -4
  70. package/dist/list-header.d.ts +47 -5
  71. package/dist/list-header.js +1 -1
  72. package/dist/message-composer.js +1 -1
  73. package/dist/{nav-stack-vQ3ieerq.d.ts → nav-stack-DKrvqFjA.d.ts} +1 -1
  74. package/dist/nav-stack.d.ts +2 -2
  75. package/dist/nav-stack.js +1 -1
  76. package/dist/{panel-toolbar-vg6Ir5Dy.d.ts → panel-toolbar-CEcHHDkn.d.ts} +8 -0
  77. package/dist/radio-group.d.ts +19 -2
  78. package/dist/radio-group.js +3 -1
  79. package/dist/split-view.d.ts +2 -2
  80. package/dist/split-view.js +1 -1
  81. package/dist/styles/column-track.css +7 -2
  82. package/dist/styles/components/actions/toolbar-control-group/toolbar-control-group.css +11 -4
  83. package/dist/styles/components/collections/list-header/list-header.css +50 -0
  84. package/dist/styles/components/collections/list-item/list-item.css +6 -1
  85. package/dist/styles/components/collections/tree-list/tree-list.css +3 -2
  86. package/dist/styles/components/forms/radio-group/radio-group.css +107 -0
  87. package/dist/styles/components/layout/column-track/column-track.css +7 -2
  88. package/dist/styles/components/surfaces/surface-scaffold/surface-scaffold.css +30 -1
  89. package/dist/styles/editor/editor.css +0 -23
  90. package/dist/styles/list-header.css +50 -0
  91. package/dist/styles/list-item.css +6 -1
  92. package/dist/styles/radio-group.css +107 -0
  93. package/dist/styles/surface-scaffold.css +30 -1
  94. package/dist/styles/toolbar-control-group.css +11 -4
  95. package/dist/styles/tree-list.css +3 -2
  96. package/dist/surface-scaffold-register.js +1 -1
  97. package/dist/surface-scaffold.d.ts +46 -11
  98. package/dist/surface-scaffold.js +2 -2
  99. package/dist/toolbar-control-group.d.ts +10 -1
  100. package/dist/toolbar-control-group.js +1 -1
  101. package/dist/tree-list.d.ts +7 -1
  102. package/dist/tree-list.js +1 -1
  103. package/dist/view-runtime.d.ts +9 -0
  104. package/dist/view-runtime.js +8 -0
  105. package/dist/view-runtime.js.map +1 -0
  106. package/dist/wire-catalog.d.ts +2 -2
  107. package/dist/wire-catalog.js +1 -1
  108. package/dist/wire-search-fields.js +1 -1
  109. package/dist/wire-tab-bars.d.ts +10 -0
  110. package/dist/wire-tab-bars.js +1 -1
  111. package/dist/wire-tag-fields.js +1 -1
  112. package/dist/wire-workbench.d.ts +17 -1
  113. package/dist/wire-workbench.js +1 -1
  114. package/dist/workbench-dialog.d.ts +2 -2
  115. package/dist/workbench-dialog.js +4 -4
  116. package/dist/workbench.d.ts +10 -2
  117. package/dist/workbench.js +1 -1
  118. package/docs/accessibility.md +1 -1
  119. package/docs/column-explorer.md +4 -0
  120. package/docs/component-contract.md +10 -4
  121. package/docs/component-integration.md +7 -3
  122. package/docs/component-selection.md +2 -1
  123. package/docs/design/sketch/Kerf-UI.sketch +0 -0
  124. package/docs/design/sketch/coverage.md +7 -6
  125. package/docs/design/sketch/forms/README.md +5 -4
  126. package/docs/design/sketch/unified/pages/forms.png +0 -0
  127. package/docs/design/templates/radio-group/tiles-dark.svg +1 -0
  128. package/docs/design/templates/radio-group/tiles.svg +1 -0
  129. package/docs/design/templates/radio-group-dark.svg +1 -1
  130. package/docs/design/templates/radio-group.svg +1 -1
  131. package/docs/editor-host.md +90 -5
  132. package/docs/interaction-conventions.md +2 -0
  133. package/docs/layout.md +1 -1
  134. package/docs/surface-scaffold.md +49 -2
  135. package/docs/tree-list.md +10 -0
  136. package/docs/workbench.md +16 -0
  137. package/evaluator/firefox-app-data.d.mts +4 -0
  138. package/evaluator/firefox-app-data.mjs +35 -0
  139. package/evaluator/index.mjs +19 -5
  140. package/llms.txt +20 -4
  141. package/package.json +8 -1
  142. package/props/component-props.d.mts +3 -0
  143. package/view/cli.mjs +36 -5
  144. package/view/contract.mjs +3 -0
  145. package/view/generate.mjs +8 -7
  146. package/view/index.d.mts +14 -0
  147. package/view/project-types-worker.mjs +55 -0
  148. package/view/project-types.d.mts +43 -0
  149. package/view/project-types.mjs +618 -0
  150. package/view/type-expression.d.mts +15 -0
  151. package/view/type-expression.mjs +162 -0
  152. package/view/types.mjs +4 -0
  153. package/view/validate.mjs +20 -1
  154. package/vite-editor.d.mts +31 -3
  155. package/vite-editor.mjs +168 -4
  156. package/dist/chunk-34FWYJX6.js.map +0 -1
  157. package/dist/chunk-3ZKUXWAV.js.map +0 -1
  158. package/dist/chunk-3ZWYGGEC.js.map +0 -1
  159. package/dist/chunk-5A2DN3LR.js.map +0 -1
  160. package/dist/chunk-6T7AX365.js.map +0 -1
  161. package/dist/chunk-BMOZSNDU.js +0 -133
  162. package/dist/chunk-BMOZSNDU.js.map +0 -1
  163. package/dist/chunk-GQUDCWOD.js.map +0 -1
  164. package/dist/chunk-IMXLOMTF.js.map +0 -1
  165. package/dist/chunk-IR32NI2O.js.map +0 -1
  166. package/dist/chunk-MLDO7WLA.js +0 -82
  167. package/dist/chunk-MLDO7WLA.js.map +0 -1
  168. package/dist/chunk-OHT2AXER.js.map +0 -1
  169. package/dist/chunk-UQ4FRQ6M.js.map +0 -1
  170. package/dist/chunk-ZC4KSRAF.js.map +0 -1
package/dist/editor.js CHANGED
@@ -1,21 +1,22 @@
1
+ import { wireSliders } from './chunk-TXBNPEIJ.js';
1
2
  import { wireTabNavigator } from './chunk-6V6UHPJD.js';
2
- import { wireTagFields } from './chunk-DBCDYBZP.js';
3
+ import { wireTagFields } from './chunk-HHEBNP6Z.js';
3
4
  import { wireTreeList, treeListExternalDrop } from './chunk-HPOXLOVC.js';
5
+ import { wireNavStack } from './chunk-I2K4OQKB.js';
4
6
  import { wireSidebar } from './chunk-63TJH2RF.js';
5
- import { wireSliders } from './chunk-TXBNPEIJ.js';
6
7
  import { wireContentItems } from './chunk-X43QQWVC.js';
7
- import { wireNavStack } from './chunk-I2K4OQKB.js';
8
- import { wireWorkbench } from './chunk-OHT2AXER.js';
8
+ import { wireWorkbench } from './chunk-QSJAIXLM.js';
9
9
  import { wireColorFields } from './chunk-3K5V3ZSD.js';
10
10
  import { wireColorPickers } from './chunk-YE6KCAIN.js';
11
11
  import { wireColumnExplorer } from './chunk-GHV36C6I.js';
12
- import { TreeList } from './chunk-GQUDCWOD.js';
12
+ import { TreeList } from './chunk-D2KHQNJ6.js';
13
13
  import { TagField } from './chunk-73LC3JAL.js';
14
14
  import { wireSummaryRows } from './chunk-CKPI4WIN.js';
15
- import { wireTabBars, reorderTabs } from './chunk-3ZWYGGEC.js';
15
+ import { wireTabBars, reorderTabs } from './chunk-ASU4ODOH.js';
16
16
  import { wireTextFields } from './chunk-KC6WUSNS.js';
17
17
  import { wireResizableRegions } from './chunk-MMOQR426.js';
18
- import { wireSearchFields } from './chunk-IR32NI2O.js';
18
+ import { wireSearchFields } from './chunk-ALBFHXMZ.js';
19
+ import { wireComboboxes } from './chunk-GE2BQXB3.js';
19
20
 
20
21
  import { wireFilePickers } from './chunk-KK3S5OTW.js';
21
22
  import { wireForms } from './chunk-44AOBT2F.js';
@@ -24,7 +25,6 @@ import { wireListReorder, reorderListItems } from './chunk-MJ5RU6XT.js';
24
25
  import { wireScrollDividers } from './chunk-M64TAGZY.js';
25
26
  import { wireCheckboxes } from './chunk-DJWBXEF4.js';
26
27
  import { wireChoiceChips, readChoiceChips } from './chunk-DB64I3DB.js';
27
- import { wireComboboxes } from './chunk-GE2BQXB3.js';
28
28
  import { TextField } from './chunk-RGB4DPMN.js';
29
29
  import { ValueTable, ValueTableRow } from './chunk-WSPXSWFG.js';
30
30
  import { TabBarItem } from './chunk-Q7RILH2D.js';
@@ -39,8 +39,8 @@ import { isApplePlatform } from './chunk-GXSX6Q6O.js';
39
39
  import { Grid } from './chunk-FR5G77K5.js';
40
40
 
41
41
  import { ListActionRow } from './chunk-RHMY45DK.js';
42
- import { DialogSurface, wirePinnablePopover, PinnablePopoverSurface, isPopoverPinned } from './chunk-IMXLOMTF.js';
43
- import { openDialog, closeDialog } from './chunk-UQ4FRQ6M.js';
42
+ import { DialogSurface, wirePinnablePopover, PinnablePopoverSurface, isPopoverPinned } from './chunk-76BLSFEA.js';
43
+ import { openDialog, closeDialog } from './chunk-R4JK2C6D.js';
44
44
 
45
45
  import { EmptyState } from './chunk-FNJA4S6J.js';
46
46
  import { FilePickerTrigger } from './chunk-4L5ZIKDZ.js';
@@ -49,7 +49,7 @@ import { deviceClass } from './chunk-WCMGPAY2.js';
49
49
 
50
50
 
51
51
 
52
- import { ColumnExplorer } from './chunk-BMOZSNDU.js';
52
+ import { ColumnExplorer } from './chunk-BMUYZKXW.js';
53
53
  import { treeListPath } from './chunk-7U65KLDL.js';
54
54
 
55
55
  import { openAnchoredSurface } from './chunk-COMEWURO.js';
@@ -57,7 +57,7 @@ import { realmOf } from './chunk-IFDTSVE6.js';
57
57
 
58
58
 
59
59
  import { Button } from './chunk-QXXLDY6I.js';
60
- import { Workbench } from './chunk-ZC4KSRAF.js';
60
+ import { Workbench } from './chunk-4CYCJ3NY.js';
61
61
  import { workbenchRegionId } from './chunk-UU37OR3D.js';
62
62
  import { Switch } from './chunk-C4FBYP2D.js';
63
63
  import { SearchField, readSearchField } from './chunk-UD5KHQOH.js';
@@ -66,16 +66,13 @@ import { ListInsetText } from './chunk-CJAKN2KZ.js';
66
66
  import { PopupMenu, openPopupMenuAt } from './chunk-S7QB5KMM.js';
67
67
 
68
68
 
69
-
69
+ import { NavStack } from './chunk-XO5IOPM5.js';
70
70
 
71
71
  import { ToolbarText } from './chunk-JAC6AVZN.js';
72
- import { ListHeader } from './chunk-6T7AX365.js';
73
- import { Text } from './chunk-F34LHBQI.js';
74
72
 
75
73
 
76
74
 
77
-
78
- import { ToolbarControlGroup, ToolbarButton } from './chunk-5A2DN3LR.js';
75
+ import { ToolbarControlGroup, ToolbarButton } from './chunk-SGYBIKQA.js';
79
76
 
80
77
 
81
78
 
@@ -87,6 +84,9 @@ import { ListItem } from './chunk-4UWLHKNU.js';
87
84
 
88
85
 
89
86
 
87
+ import { ListHeader } from './chunk-OSL4LQ7T.js';
88
+ import { Text } from './chunk-F34LHBQI.js';
89
+
90
90
 
91
91
  import { List } from './chunk-WVQDIOD7.js';
92
92
 
@@ -99,12 +99,33 @@ import { CheckboxGroup } from './chunk-6BXPN5SC.js';
99
99
  import { LucideIcon } from './chunk-CMG4OZPV.js';
100
100
  import { px } from './chunk-IQSRHXZR.js';
101
101
 
102
- import { lucideExportName, createViewCatalog, validateView, contractOf, previewView, interpretView, contractDigest, composedViewPath, readViewHeader, diffContracts, VIEW_DOCUMENT_SCHEMA_ID, classifyChild, parseCssCall, isLiteralOf, channelOf, dataAttributeProblem, typeText, fieldZoneOf, generateView, childKind, createMoveCheck } from '@kerfjs/ui/view';
103
- import { signal, computed, effect, delegate, mount, batch, raw } from 'kerfjs';
102
+ import { lucideExportName, createViewCatalog, validateView, contractOf, previewView, interpretView, contractDigest, composedViewPath, readViewHeader, diffContracts, VIEW_DOCUMENT_SCHEMA_ID, classifyChild, parseCssCall, isLiteralOf, typeText, channelOf, dataAttributeProblem, fieldZoneOf, generateView, childKind, createMoveCheck } from '@kerfjs/ui/view';
103
+ import { raw, signal, computed, effect, delegate, mount, batch, isSafeHtml } from 'kerfjs';
104
104
  import { delegateActions } from 'kerfjs/actions';
105
- import { icons as icons$1, FilePlus, FolderOpen, GitCompare, FileCode, Save, Plus, Undo2, Redo2, Play, ArrowLeft, Group, ArrowUp, ArrowDown, Trash, ChevronRight, CopyPlus, Logs, RotateCwSquare, HousePlus, Frame, List as List$1, LayoutGrid, Columns3, ListTree, Activity, BadgeCheck, LoaderCircle, FaceSlightlySmiling, Component, Ban } from 'lucide';
105
+ import { icons as icons$1, Activity, BadgeCheck, LoaderCircle, FaceSlightlySmiling, FilePlus, FolderOpen, GitCompare, FileCode, Save, Plus, Undo2, Redo2, Play, ArrowLeft, Group, ArrowUp, ArrowDown, Trash, X, ChevronRight, List as List$1, LayoutGrid, Columns3, ListTree, CopyPlus, Logs, RotateCwSquare, HousePlus, Frame, Folder, FileBracesCorner, FileCodeCorner, FileText, FileImage, FileHeadphone, FilePlay, FileArchive, FileSpreadsheet, File, Component, Ban } from 'lucide';
106
106
  import { jsx, jsxs, Fragment } from 'kerfjs/jsx-runtime';
107
107
 
108
+ // src/editor/project-type-service.ts
109
+ var EDITOR_TYPES_API = "/__kerf-ui-editor/api/types";
110
+ var TYPE_SERVICE_REQUIRED = {
111
+ code: "KUI-V018",
112
+ path: "$.params",
113
+ message: "Project TypeScript validation is unavailable. Connect this editor to its project dev server."
114
+ };
115
+ function devServerTypeService(api = EDITOR_TYPES_API) {
116
+ return async (request) => {
117
+ const response = await globalThis.fetch(api, {
118
+ method: "POST",
119
+ headers: { "Content-Type": "application/json", "X-Kerf-UI-Editor": "1" },
120
+ body: JSON.stringify(request)
121
+ });
122
+ if (!response.ok)
123
+ throw new Error(await response.text() || response.statusText);
124
+ return response.json();
125
+ };
126
+ }
127
+
128
+ // src/editor/autosave.ts
108
129
  var EDITOR_FILE_API = "/__kerf-ui-editor/api/file";
109
130
  var EDITOR_LIST_API = "/__kerf-ui-editor/api/files";
110
131
  var DRAFTS_FOLDER = ".kerf-ui-editor/drafts/";
@@ -114,6 +135,7 @@ function devServerStorage(api = EDITOR_FILE_API, listApi = EDITOR_LIST_API) {
114
135
  const url = (path) => `${api}?path=${encodeURIComponent(path)}`;
115
136
  const failure = async (response) => new Error(await response.text() || response.statusText);
116
137
  return {
138
+ types: devServerTypeService(),
117
139
  async read(path) {
118
140
  const response = await globalThis.fetch(url(path));
119
141
  if (response.status === 404) return void 0;
@@ -278,6 +300,8 @@ var HOOK = {
278
300
  embedSearch: "data-editor-embed-search",
279
301
  extract: "data-editor-extract",
280
302
  field: "data-editor-field",
303
+ /** KF-QWDPM3: a Properties row's group path, `Behavior/Link`. */
304
+ group: "data-editor-prop-group",
281
305
  icon: "data-editor-icon",
282
306
  iconSearch: "data-editor-icon-search",
283
307
  insertDocument: "data-editor-insert-document",
@@ -289,7 +313,7 @@ var HOOK = {
289
313
  paletteDocument: "data-editor-palette-document",
290
314
  paletteFilter: "data-editor-palette-filter",
291
315
  param: "data-editor-param",
292
- promote: "data-editor-promote",
316
+ propertiesSearch: "data-editor-properties-search",
293
317
  prop: "data-editor-prop"
294
318
  };
295
319
  function hook(name, value) {
@@ -707,8 +731,8 @@ function visitNodes(document2) {
707
731
  };
708
732
  const node = (item, ancestors, repeated) => {
709
733
  visits.push({ node: item, ancestors, repeated });
710
- for (const [zone, children] of Object.entries(item.zones ?? {})) {
711
- for (const entry of children)
734
+ for (const [zone, children2] of Object.entries(item.zones ?? {})) {
735
+ for (const entry of children2)
712
736
  child(entry, [...ancestors, { node: item, zone }], repeated);
713
737
  }
714
738
  };
@@ -913,8 +937,10 @@ var SPELLED = {
913
937
  h: "horizontal",
914
938
  v: "vertical"
915
939
  };
940
+ var fieldLabel = (prop) => prop.label ?? propLabel(prop.name);
916
941
  function propLabel(name) {
917
942
  if (name === "className" || name === "class") return "Classes";
943
+ if (name === "rootAttributes") return "Data attributes";
918
944
  const words2 = name.replace(/[-_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/([a-zA-Z])(\d)/g, "$1 $2").trim().split(/\s+/).map((word) => word.toLowerCase()).map((word) => SPELLED[word] ?? word);
919
945
  return words2.map(
920
946
  (word, index) => ACRONYMS.has(word) ? word.toUpperCase() : index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word
@@ -990,11 +1016,11 @@ function withValueAt(value, path, next) {
990
1016
  else list[step] = item;
991
1017
  return list;
992
1018
  }
993
- const object = { ...fieldsOf(value) };
994
- const field = withValueAt(object[step], rest, next);
995
- if (field === void 0) delete object[step];
996
- else object[step] = field;
997
- return Object.keys(object).length ? object : void 0;
1019
+ const object2 = { ...fieldsOf(value) };
1020
+ const field = withValueAt(object2[step], rest, next);
1021
+ if (field === void 0) delete object2[step];
1022
+ else object2[step] = field;
1023
+ return Object.keys(object2).length ? object2 : void 0;
998
1024
  }
999
1025
  function withRequiredBooleans(value, type, definitions, path) {
1000
1026
  if (value === void 0) return value;
@@ -1107,9 +1133,9 @@ function documentInDeclaredOrder(document2, propsOf, definitionsOf) {
1107
1133
  definitionsOf(item.type)
1108
1134
  ) : item.props;
1109
1135
  const zones = item.zones ? Object.fromEntries(
1110
- Object.entries(item.zones).map(([zone, children]) => [
1136
+ Object.entries(item.zones).map(([zone, children2]) => [
1111
1137
  zone,
1112
- children.map(child)
1138
+ children2.map(child)
1113
1139
  ])
1114
1140
  ) : void 0;
1115
1141
  return {
@@ -1322,9 +1348,9 @@ function walk(document2, visit) {
1322
1348
  stopped = true;
1323
1349
  return;
1324
1350
  }
1325
- for (const [key, children] of Object.entries(node.zones ?? {})) {
1326
- children.forEach(
1327
- (child, childIndex) => visitChild(child, children, childIndex, node, key)
1351
+ for (const [key, children2] of Object.entries(node.zones ?? {})) {
1352
+ children2.forEach(
1353
+ (child, childIndex) => visitChild(child, children2, childIndex, node, key)
1328
1354
  );
1329
1355
  }
1330
1356
  };
@@ -1628,11 +1654,11 @@ function ownNode(node, catalog) {
1628
1654
  }
1629
1655
  function ownedFields(node, catalog) {
1630
1656
  const fields = [];
1631
- for (const [key, children] of Object.entries(node.zones ?? {})) {
1657
+ for (const [key, children2] of Object.entries(node.zones ?? {})) {
1632
1658
  const component = catalog.components.get(node.type);
1633
1659
  const field = component && fieldZoneOf(component.component, component.definitions, key);
1634
1660
  const own = node.props?.[field?.prop ?? ""];
1635
- if (!field || !children.length || valueAt(own, field.path) === void 0)
1661
+ if (!field || !children2.length || valueAt(own, field.path) === void 0)
1636
1662
  continue;
1637
1663
  fields.push([field.prop, withValueAt(own, field.path, void 0) ?? {}]);
1638
1664
  }
@@ -1678,12 +1704,12 @@ function renameParam(document2, from, to) {
1678
1704
  const follow = (value) => {
1679
1705
  if (Array.isArray(value)) return value.map(follow);
1680
1706
  if (value === null || typeof value !== "object") return value;
1681
- const record = value;
1682
- if (record.$param === from) return { ...record, $param: to };
1683
- if (typeof record.$bind === "string" && record.$bind.split(".")[0] === from)
1684
- return { ...record, $bind: `${to}${record.$bind.slice(from.length)}` };
1707
+ const record2 = value;
1708
+ if (record2.$param === from) return { ...record2, $param: to };
1709
+ if (typeof record2.$bind === "string" && record2.$bind.split(".")[0] === from)
1710
+ return { ...record2, $bind: `${to}${record2.$bind.slice(from.length)}` };
1685
1711
  return Object.fromEntries(
1686
- Object.entries(record).map(([key, item]) => [key, follow(item)])
1712
+ Object.entries(record2).map(([key, item]) => [key, follow(item)])
1687
1713
  );
1688
1714
  };
1689
1715
  const renamed = Object.fromEntries(
@@ -1797,8 +1823,8 @@ function eachScopes(document2, id) {
1797
1823
  };
1798
1824
  const visit = (node, frames) => {
1799
1825
  if (node.id === id) return frames;
1800
- for (const children of Object.values(node.zones ?? {}))
1801
- for (const item of children) {
1826
+ for (const children2 of Object.values(node.zones ?? {}))
1827
+ for (const item of children2) {
1802
1828
  const found = scopeOf(item, frames);
1803
1829
  if (found) return found;
1804
1830
  }
@@ -1825,7 +1851,7 @@ function bindingOptions(document2, catalog, id, prop, path = [], prepare = (same
1825
1851
  }
1826
1852
  const known = new Set(
1827
1853
  validateView(prepare(document2), catalog, { resolveView }).diagnostics.map(
1828
- (diagnostic) => `${diagnostic.code} ${diagnostic.path}`
1854
+ (diagnostic2) => `${diagnostic2.code} ${diagnostic2.path}`
1829
1855
  )
1830
1856
  );
1831
1857
  return candidates.filter(
@@ -1834,7 +1860,7 @@ function bindingOptions(document2, catalog, id, prop, path = [], prepare = (same
1834
1860
  catalog,
1835
1861
  { resolveView }
1836
1862
  ).diagnostics.every(
1837
- (diagnostic) => known.has(`${diagnostic.code} ${diagnostic.path}`)
1863
+ (diagnostic2) => known.has(`${diagnostic2.code} ${diagnostic2.path}`)
1838
1864
  )
1839
1865
  );
1840
1866
  }
@@ -1853,9 +1879,9 @@ function problemCounts(document2, catalog) {
1853
1879
  }
1854
1880
  function addsProblems(before, next, catalog, ignore = () => false) {
1855
1881
  const counts = new Map(problemCounts(before, catalog));
1856
- return validateView(next, catalog).diagnostics.some((diagnostic) => {
1857
- if (ignore(diagnostic)) return false;
1858
- const { code, message } = diagnostic;
1882
+ return validateView(next, catalog).diagnostics.some((diagnostic2) => {
1883
+ if (ignore(diagnostic2)) return false;
1884
+ const { code, message } = diagnostic2;
1859
1885
  const left = counts.get(`${code} ${message}`) ?? 0;
1860
1886
  counts.set(`${code} ${message}`, left - 1);
1861
1887
  return left <= 0;
@@ -1968,7 +1994,7 @@ function outlineTree(document2, names) {
1968
1994
  placed2.sort(
1969
1995
  (a, b) => placeKey(a.at, props) < placeKey(b.at, props) ? -1 : 1
1970
1996
  );
1971
- const children = [...placed2.flatMap(({ rows }) => rows), ...own];
1997
+ const children2 = [...placed2.flatMap(({ rows }) => rows), ...own];
1972
1998
  return {
1973
1999
  id: node.id,
1974
2000
  label: node.name ?? component,
@@ -1978,7 +2004,7 @@ function outlineTree(document2, names) {
1978
2004
  ...control,
1979
2005
  repeated && !control.some((part) => part.startsWith("for each")) ? "repeated" : void 0
1980
2006
  ].filter(Boolean).join(" \xB7 "),
1981
- ...children.length ? { children } : {}
2007
+ ...children2.length ? { children: children2 } : {}
1982
2008
  };
1983
2009
  };
1984
2010
  const child = (item, parent, zone, index, repeated, control) => {
@@ -2136,9 +2162,9 @@ function markRows(document2, catalog, prefix = []) {
2136
2162
  return {
2137
2163
  ...marked,
2138
2164
  zones: Object.fromEntries(
2139
- Object.entries(item.zones).map(([zone, children]) => [
2165
+ Object.entries(item.zones).map(([zone, children2]) => [
2140
2166
  zone,
2141
- children.map((entry) => child(entry, keys))
2167
+ children2.map((entry) => child(entry, keys))
2142
2168
  ])
2143
2169
  )
2144
2170
  };
@@ -2192,8 +2218,8 @@ function recordValue(document2, rows, id, key, prop, value) {
2192
2218
  }
2193
2219
  function eachOf(document2, id) {
2194
2220
  for (const { node } of visitNodes(document2))
2195
- for (const children of Object.values(node.zones ?? {}))
2196
- for (const child of children)
2221
+ for (const children2 of Object.values(node.zones ?? {}))
2222
+ for (const child of children2)
2197
2223
  if ("$each" in child && rowNodes(child).some((node2) => node2.id === id))
2198
2224
  return child;
2199
2225
  return void 0;
@@ -2271,10 +2297,10 @@ function setRowField(document2, id, keys, field, value, params) {
2271
2297
  const set = (item, [name, ...rest]) => {
2272
2298
  if (typeof item !== "object" || item === null || Array.isArray(item))
2273
2299
  return item;
2274
- const record = item;
2300
+ const record2 = item;
2275
2301
  return {
2276
- ...record,
2277
- [name]: rest.length ? set(record[name], rest) : value
2302
+ ...record2,
2303
+ [name]: rest.length ? set(record2[name], rest) : value
2278
2304
  };
2279
2305
  };
2280
2306
  return changeRow(
@@ -2572,9 +2598,9 @@ function previewSlots(document2, emptyZonesOf = () => []) {
2572
2598
  };
2573
2599
  const node = (item) => {
2574
2600
  const zones = item.zones ? Object.fromEntries(
2575
- Object.entries(item.zones).map(([zone, children]) => [
2601
+ Object.entries(item.zones).map(([zone, children2]) => [
2576
2602
  zone,
2577
- children.map(
2603
+ children2.map(
2578
2604
  (entry, index) => child(entry, { parent: item.id, zone, index })
2579
2605
  )
2580
2606
  ])
@@ -2840,15 +2866,15 @@ function composedDocuments(document2, resolve) {
2840
2866
  }
2841
2867
  var composesViews = (document2) => viewSources(document2).length > 0;
2842
2868
  function explainViewLoads(diagnostics, documentPath, loads) {
2843
- return diagnostics.map((diagnostic) => {
2844
- const found = /^#view "(.*)" was not found$/.exec(diagnostic.message);
2845
- if (diagnostic.code !== "KUI-V012" || !found) return diagnostic;
2869
+ return diagnostics.map((diagnostic2) => {
2870
+ const found = /^#view "(.*)" was not found$/.exec(diagnostic2.message);
2871
+ if (diagnostic2.code !== "KUI-V012" || !found) return diagnostic2;
2846
2872
  const src = found[1];
2847
- const at = [...diagnostic.path.matchAll(/\{([^}]*)\}/g)].reduce((from, [, inside]) => composedViewPath(from, inside), void 0);
2873
+ const at = [...diagnostic2.path.matchAll(/\{([^}]*)\}/g)].reduce((from, [, inside]) => composedViewPath(from, inside), void 0);
2848
2874
  const path = documentPath === void 0 ? void 0 : viewPath(documentPath, composedViewPath(at, src));
2849
2875
  const load = path === void 0 ? void 0 : loads.get(path);
2850
2876
  const why = documentPath === void 0 ? "the editor has no storage to load it from" : path === void 0 ? "it is outside the project" : load?.state === "missing" ? `there is no ${path}` : load?.state === "failed" ? `it could not be read: ${load.error}` : "it is loading";
2851
- return { ...diagnostic, message: `#view "${src}" was not found: ${why}` };
2877
+ return { ...diagnostic2, message: `#view "${src}" was not found: ${why}` };
2852
2878
  });
2853
2879
  }
2854
2880
  var icons = new Proxy({}, {
@@ -3036,8 +3062,8 @@ function ownerOf(document2, id) {
3036
3062
  } : void 0;
3037
3063
  };
3038
3064
  const visit = (node) => {
3039
- for (const children of Object.values(node.zones ?? {})) {
3040
- const list = children;
3065
+ for (const children2 of Object.values(node.zones ?? {})) {
3066
+ const list = children2;
3041
3067
  for (const [index, child] of list.entries()) {
3042
3068
  const found = match(child);
3043
3069
  if (found) return { list, index, ...found };
@@ -3273,8 +3299,8 @@ function insertSlot(document2, parent, zone, name, passItem = false) {
3273
3299
  function findHolder(document2, id) {
3274
3300
  const visit = (node) => {
3275
3301
  if (node.id === id) return node;
3276
- for (const children of Object.values(node.zones ?? {}))
3277
- for (const child of children)
3302
+ for (const children2 of Object.values(node.zones ?? {}))
3303
+ for (const child of children2)
3278
3304
  for (const inner of nodesUnder(child)) {
3279
3305
  const found = visit(inner);
3280
3306
  if (found) return found;
@@ -3303,8 +3329,8 @@ function placedSlots(document2) {
3303
3329
  }
3304
3330
  };
3305
3331
  const node = (item) => {
3306
- for (const children of Object.values(item.zones ?? {}))
3307
- children.forEach(child);
3332
+ for (const children2 of Object.values(item.zones ?? {}))
3333
+ children2.forEach(child);
3308
3334
  };
3309
3335
  node(document2.root);
3310
3336
  return names;
@@ -3880,316 +3906,6 @@ function slotEditor(document2, catalog, address) {
3880
3906
  ] }) : void 0
3881
3907
  ] });
3882
3908
  }
3883
- var CAMEL3 = /^[a-z][A-Za-z0-9]*$/;
3884
- function checkedParamEdit(document2, next, catalog) {
3885
- const before = new Set(
3886
- validateView(document2, catalog).diagnostics.map(
3887
- ({ code, path, message }) => `${code}:${path}:${message}`
3888
- )
3889
- );
3890
- const added = validateView(next, catalog).diagnostics.find(
3891
- ({ code, path, message }) => !before.has(`${code}:${path}:${message}`)
3892
- );
3893
- return added ? { error: added.message } : { document: next };
3894
- }
3895
- function createParam(document2, catalog, name, type) {
3896
- if (!CAMEL3.test(name))
3897
- return { error: "A param name is a camelCase identifier." };
3898
- if (Object.hasOwn(document2.params ?? {}, name))
3899
- return { error: `There is already a param named ${name}.` };
3900
- return checkedParamEdit(
3901
- document2,
3902
- { ...document2, params: { ...document2.params, [name]: { type } } },
3903
- catalog
3904
- );
3905
- }
3906
- function changeParam(document2, catalog, name, param) {
3907
- if (!Object.hasOwn(document2.params ?? {}, name))
3908
- return { error: `No param ${name}.` };
3909
- return checkedParamEdit(
3910
- document2,
3911
- { ...document2, params: { ...document2.params, [name]: param } },
3912
- catalog
3913
- );
3914
- }
3915
- function paramIsReferenced(document2, name) {
3916
- const reads = (value) => {
3917
- if (Array.isArray(value)) return value.some(reads);
3918
- if (value === null || typeof value !== "object") return false;
3919
- const record = value;
3920
- if (record.$param === name) return true;
3921
- if (typeof record.$bind === "string" && record.$bind.split(".")[0] === name)
3922
- return true;
3923
- return Object.values(record).some(reads);
3924
- };
3925
- return reads(document2.root);
3926
- }
3927
- function removeParam(document2, catalog, name) {
3928
- if (!Object.hasOwn(document2.params ?? {}, name))
3929
- return { error: `No param ${name}.` };
3930
- if (paramIsReferenced(document2, name))
3931
- return {
3932
- error: `Param ${name} is used in this view. Remove its bindings first.`
3933
- };
3934
- const params = Object.fromEntries(
3935
- Object.entries(document2.params ?? {}).filter(([key]) => key !== name)
3936
- );
3937
- return checkedParamEdit(
3938
- document2,
3939
- {
3940
- ...document2,
3941
- ...Object.keys(params).length ? { params } : { params: void 0 }
3942
- },
3943
- catalog
3944
- );
3945
- }
3946
- var CREATE_PARAM_ACTION = "editor-create-document-param";
3947
- var REMOVE_PARAM_ACTION = "editor-remove-document-param";
3948
- var ADD_PARAM_FIELD_ACTION = "editor-add-document-param-field";
3949
- var REMOVE_PARAM_FIELD_ACTION = "editor-remove-document-param-field";
3950
- var PARAM_EDIT = "data-editor-document-param-edit";
3951
- var PARAM_NEW = "data-editor-document-param-new";
3952
- var PARAM_REMOVE = "data-editor-document-param-remove";
3953
- var PARAM_FIELD = "data-editor-document-param-field";
3954
- var edit = (at) => ({ [PARAM_EDIT]: JSON.stringify(at) });
3955
- var kindChoices = [
3956
- { value: "string", label: "Text" },
3957
- { value: "number", label: "Number" },
3958
- { value: "boolean", label: "Boolean" },
3959
- { value: "content", label: "Content" },
3960
- { value: "array", label: "List" },
3961
- { value: "object", label: "Object" },
3962
- { value: "enum", label: "Choice" },
3963
- { value: "literal", label: "Literal" }
3964
- ];
3965
- var itemChoices = kindChoices.filter(
3966
- ({ value }) => ["string", "number", "boolean", "object"].includes(value)
3967
- );
3968
- var fieldChoices = kindChoices.filter(
3969
- ({ value }) => ["string", "number", "boolean"].includes(value)
3970
- );
3971
- var choicesFor = (choices, value) => choices.some((choice) => choice.value === value) ? choices : [{ value, label: value }, ...choices];
3972
- function fieldSchema(name, type) {
3973
- const item = type.kind === "array" ? type.items : type;
3974
- if (item?.kind !== "object") return void 0;
3975
- return /* @__PURE__ */ jsxs(List, { gap: true, rootAttributes: { "data-editor-param-schema": name }, children: [
3976
- /* @__PURE__ */ jsx(ListHeader, { label: "Item fields", size: "xs" }),
3977
- (item.props ?? []).map((field, index) => /* @__PURE__ */ jsxs(
3978
- List,
3979
- {
3980
- gap: true,
3981
- controlInsets: "trbl",
3982
- rootAttributes: { "data-editor-param-field-row": `${name}:${index}` },
3983
- children: [
3984
- /* @__PURE__ */ jsx(
3985
- TextField,
3986
- {
3987
- label: `Field ${index + 1} name`,
3988
- value: field.name,
3989
- rootAttributes: edit({ name, part: "fieldName", index })
3990
- }
3991
- ),
3992
- /* @__PURE__ */ jsx(
3993
- Select,
3994
- {
3995
- name: `param-${name}-field-${index}-type`,
3996
- label: "Field type",
3997
- value: field.type.kind,
3998
- choices: choicesFor(fieldChoices, field.type.kind),
3999
- rootAttributes: edit({ name, part: "fieldType", index })
4000
- }
4001
- ),
4002
- /* @__PURE__ */ jsx(
4003
- Switch,
4004
- {
4005
- label: "Required",
4006
- checked: field.required,
4007
- rootAttributes: edit({ name, part: "fieldRequired", index })
4008
- }
4009
- ),
4010
- /* @__PURE__ */ jsx(
4011
- Button,
4012
- {
4013
- emphasis: "secondary",
4014
- size: "compact",
4015
- action: REMOVE_PARAM_FIELD_ACTION,
4016
- rootAttributes: { [PARAM_FIELD]: JSON.stringify({ name, index }) },
4017
- children: "Remove field"
4018
- }
4019
- )
4020
- ]
4021
- }
4022
- )),
4023
- /* @__PURE__ */ jsx(List, { controlInsets: "trbl", children: /* @__PURE__ */ jsx(
4024
- Button,
4025
- {
4026
- emphasis: "secondary",
4027
- size: "compact",
4028
- action: ADD_PARAM_FIELD_ACTION,
4029
- rootAttributes: { [PARAM_FIELD]: JSON.stringify({ name }) },
4030
- children: "Add field"
4031
- }
4032
- ) })
4033
- ] });
4034
- }
4035
- var defaultText = (value, kind) => ["string", "content", "number"].includes(kind) ? String(value) : JSON.stringify(value) ?? "";
4036
- function documentParamsPanel(document2, newName, newKind, errors) {
4037
- const params = Object.entries(document2.params ?? {});
4038
- return /* @__PURE__ */ jsxs(List, { gap: true, rootAttributes: { "data-editor-document-params": "" }, children: [
4039
- /* @__PURE__ */ jsx(
4040
- ListHeader,
4041
- {
4042
- label: "Parameters",
4043
- count: params.length,
4044
- countLabel: "parameters"
4045
- }
4046
- ),
4047
- params.length ? params.map(([name, param]) => {
4048
- const type = param.type;
4049
- const hasDefault = Object.hasOwn(param, "default");
4050
- const referenced = paramIsReferenced(document2, name);
4051
- return /* @__PURE__ */ jsxs(List, { gap: true, rootAttributes: { "data-editor-param-row": name }, children: [
4052
- /* @__PURE__ */ jsx(ListHeader, { label: name, size: "xs" }),
4053
- errors[`#doc-param:${name}`] ? /* @__PURE__ */ jsx(
4054
- StateBanner,
4055
- {
4056
- tone: "warning",
4057
- title: errors[`#doc-param:${name}`]
4058
- }
4059
- ) : void 0,
4060
- /* @__PURE__ */ jsxs(List, { gap: true, controlInsets: "trbl", children: [
4061
- /* @__PURE__ */ jsx(
4062
- TextField,
4063
- {
4064
- label: "Name",
4065
- value: name,
4066
- error: errors[`#doc-param:${name}`],
4067
- rootAttributes: edit({ name, part: "name" })
4068
- }
4069
- ),
4070
- /* @__PURE__ */ jsx(
4071
- Select,
4072
- {
4073
- name: `param-${name}-type`,
4074
- label: "Type",
4075
- value: type.kind,
4076
- choices: choicesFor(kindChoices, type.kind),
4077
- rootAttributes: edit({ name, part: "type" })
4078
- }
4079
- ),
4080
- type.kind === "array" ? /* @__PURE__ */ jsx(
4081
- Select,
4082
- {
4083
- name: `param-${name}-item-type`,
4084
- label: "Item type",
4085
- value: type.items?.kind ?? "string",
4086
- choices: choicesFor(
4087
- itemChoices,
4088
- type.items?.kind ?? "string"
4089
- ),
4090
- rootAttributes: edit({ name, part: "itemType" })
4091
- }
4092
- ) : void 0,
4093
- type.kind === "enum" ? /* @__PURE__ */ jsx(
4094
- TextField,
4095
- {
4096
- label: "Choices (JSON array)",
4097
- value: JSON.stringify(type.values ?? []),
4098
- rootAttributes: edit({ name, part: "enumValues" })
4099
- }
4100
- ) : void 0,
4101
- type.kind === "literal" ? /* @__PURE__ */ jsx(
4102
- TextField,
4103
- {
4104
- label: "Literal (JSON value)",
4105
- value: JSON.stringify(type.value),
4106
- rootAttributes: edit({ name, part: "literalValue" })
4107
- }
4108
- ) : void 0,
4109
- type.kind === "prop" ? /* @__PURE__ */ jsxs(Text, { tone: "quiet", children: [
4110
- "This input uses ",
4111
- type.component,
4112
- ".",
4113
- type.prop,
4114
- " from the component catalog."
4115
- ] }) : void 0,
4116
- fieldSchema(name, type),
4117
- /* @__PURE__ */ jsx(
4118
- Switch,
4119
- {
4120
- label: "Use default",
4121
- checked: hasDefault,
4122
- disabled: !hasDefault && (type.kind === "prop" || type.kind === "content" && !type.acceptsText),
4123
- rootAttributes: edit({ name, part: "defaultEnabled" })
4124
- }
4125
- ),
4126
- type.kind === "content" && !type.acceptsText && !hasDefault ? /* @__PURE__ */ jsx(Text, { tone: "quiet", children: "Content inputs are supplied by the app and cannot have a JSON default." }) : void 0,
4127
- hasDefault ? type.kind === "boolean" ? /* @__PURE__ */ jsx(
4128
- Select,
4129
- {
4130
- name: `param-${name}-default`,
4131
- label: "Default value",
4132
- value: param.default === true ? "true" : "false",
4133
- choices: [
4134
- { value: "false", label: "False" },
4135
- { value: "true", label: "True" }
4136
- ],
4137
- rootAttributes: edit({ name, part: "default" })
4138
- }
4139
- ) : /* @__PURE__ */ jsx(
4140
- TextField,
4141
- {
4142
- label: "Default value",
4143
- value: defaultText(param.default, type.kind),
4144
- hint: ["array", "object", "enum", "literal", "prop"].includes(
4145
- type.kind
4146
- ) ? "Enter a JSON value matching this type." : void 0,
4147
- error: errors[`#doc-param:${name}:default`],
4148
- rootAttributes: edit({ name, part: "default" })
4149
- }
4150
- ) : void 0,
4151
- /* @__PURE__ */ jsx(
4152
- Button,
4153
- {
4154
- emphasis: "secondary",
4155
- size: "compact",
4156
- action: REMOVE_PARAM_ACTION,
4157
- disabled: referenced,
4158
- rootAttributes: { [PARAM_REMOVE]: name },
4159
- children: "Remove parameter"
4160
- }
4161
- ),
4162
- referenced ? /* @__PURE__ */ jsx(Text, { tone: "quiet", children: "Remove this parameter\u2019s bindings before deleting it." }) : void 0
4163
- ] })
4164
- ] });
4165
- }) : /* @__PURE__ */ jsx(ListInsetText, { children: /* @__PURE__ */ jsx(Text, { tone: "quiet", children: "This document has no parameters yet." }) }),
4166
- /* @__PURE__ */ jsx(ListHeader, { label: "Add parameter", size: "xs" }),
4167
- /* @__PURE__ */ jsxs(List, { gap: true, controlInsets: "trbl", children: [
4168
- /* @__PURE__ */ jsx(
4169
- TextField,
4170
- {
4171
- label: "Name",
4172
- value: newName,
4173
- error: errors["#doc-param-new"],
4174
- rootAttributes: { [PARAM_NEW]: "name" }
4175
- }
4176
- ),
4177
- /* @__PURE__ */ jsx(
4178
- Select,
4179
- {
4180
- name: "new-document-param-type",
4181
- label: "Type",
4182
- value: newKind,
4183
- choices: kindChoices.filter(
4184
- ({ value }) => value !== "enum" && value !== "literal"
4185
- ),
4186
- rootAttributes: { [PARAM_NEW]: "type" }
4187
- }
4188
- ),
4189
- /* @__PURE__ */ jsx(Button, { action: CREATE_PARAM_ACTION, children: "Add parameter" })
4190
- ] })
4191
- ] });
4192
- }
4193
3909
 
4194
3910
  // src/editor/shell-names.ts
4195
3911
  var OUTLINE_ACTION = "editor-select-node";
@@ -4204,6 +3920,10 @@ var DOCUMENT_TAB_ACTION = "editor-document-tab";
4204
3920
  var INSPECTOR_TAB_ACTION = "editor-inspector-tab";
4205
3921
  var DOCUMENT_AREAS = "editor-document-areas";
4206
3922
  var SPRING_MS = 500;
3923
+ var INSPECTOR_GROUP_ACTION = "editor-inspector-group";
3924
+ var ALL_PROPERTIES = "All properties";
3925
+ var BIND_STEP = "#bind:";
3926
+ var PROPERTIES_CLEAR_ACTION = "editor-properties-clear";
4207
3927
  var SAVE_ACTION = "editor-save";
4208
3928
  var SAVE_AS_ACTION = "editor-save-as";
4209
3929
  var SAVE_AS_DIALOG = "editor-save-as-dialog";
@@ -4282,7 +4002,6 @@ var EMBED_PROPS = {
4282
4002
  var FIELD_ADD_ITEM_ACTION = "editor-add-item";
4283
4003
  var FIELD_REMOVE_ITEM_ACTION = "editor-remove-item";
4284
4004
  var FIELD_SET_ACTION = "editor-set-field";
4285
- var PROMOTE_ACTION = "editor-promote";
4286
4005
  var PROMOTE_PROP_ACTION = "editor-promote-prop";
4287
4006
  var PROMOTE_FIELD_ACTION = "editor-promote-field";
4288
4007
  var EXPORT_MODULE_ACTION = "editor-export-module";
@@ -4507,7 +4226,7 @@ function extractProblem(document2, id) {
4507
4226
  var readKey = (read) => read.kind === "param" ? `param ${read.name}` : `item ${read.as}${read.field === void 0 ? "" : `.${read.field}`}`;
4508
4227
  var fieldOf = (type, name) => type?.kind === "object" ? type.props?.find((prop) => prop.name === name)?.type : void 0;
4509
4228
  var optionalField = (type, name) => type.props.find((prop) => prop.name === name).required !== true;
4510
- var CAMEL4 = /^[a-z][A-Za-z0-9]*$/;
4229
+ var CAMEL3 = /^[a-z][A-Za-z0-9]*$/;
4511
4230
  var RESERVED = /* @__PURE__ */ new Set(["inputs", "slots", "each", "handlers"]);
4512
4231
  function mapValue(value, local, reference) {
4513
4232
  if (Array.isArray(value))
@@ -4693,11 +4412,11 @@ function extractToDocument(document2, id, options) {
4693
4412
  continue;
4694
4413
  }
4695
4414
  const base = read.field ?? read.as;
4696
- const camel2 = CAMEL4.test(base) ? base : base.replace(
4415
+ const camel2 = CAMEL3.test(base) ? base : base.replace(
4697
4416
  /[^A-Za-z0-9]+(.)?/g,
4698
4417
  (_, next2 = "") => String(next2).toUpperCase()
4699
4418
  );
4700
- const own = CAMEL4.test(camel2) ? camel2 : `${read.as}Value`;
4419
+ const own = CAMEL3.test(camel2) ? camel2 : `${read.as}Value`;
4701
4420
  let name = taken.has(own) ? `${read.as}${own[0].toUpperCase()}${own.slice(1)}` : own;
4702
4421
  for (let count = 2; taken.has(name); count += 1) name = `${own}${count}`;
4703
4422
  const itemType = items.get(read.as);
@@ -4912,10 +4631,10 @@ function choiceOptions(type, definitions = {}) {
4912
4631
  const seen = /* @__PURE__ */ new Set();
4913
4632
  const options = [];
4914
4633
  for (const value of fixed) {
4915
- const json = JSON.stringify(value);
4916
- if (seen.has(json)) continue;
4917
- seen.add(json);
4918
- options.push({ value: json, label: String(value) });
4634
+ const json2 = JSON.stringify(value);
4635
+ if (seen.has(json2)) continue;
4636
+ seen.add(json2);
4637
+ options.push({ value: json2, label: String(value) });
4919
4638
  }
4920
4639
  const objects = open.filter((option) => option.label === OPEN_LABELS.object);
4921
4640
  const names = memberLabels(
@@ -5053,9 +4772,9 @@ function controlFor(prop, value, definitions = {}) {
5053
4772
  if (options && !fixed) {
5054
4773
  if (value === void 0) return { kind: "choice", options, raw: "" };
5055
4774
  if (isBinding(value)) return { kind: "readonly", raw: "" };
5056
- const json = JSON.stringify(value);
5057
- if (options.some((option) => option.value === json))
5058
- return { kind: "choice", options, raw: json };
4775
+ const json2 = JSON.stringify(value);
4776
+ if (options.some((option) => option.value === json2))
4777
+ return { kind: "choice", options, raw: json2 };
5059
4778
  const open = openOptionFor(
5060
4779
  options,
5061
4780
  value,
@@ -5128,10 +4847,10 @@ function controlFor(prop, value, definitions = {}) {
5128
4847
  return { kind: "readonly", raw: "" };
5129
4848
  }
5130
4849
  }
5131
- function valueFromControl(kind, raw4, helpers, type) {
4850
+ function valueFromControl(kind, raw5, helpers, type) {
5132
4851
  switch (kind) {
5133
4852
  case "list": {
5134
- const text = String(raw4).trim();
4853
+ const text = String(raw5).trim();
5135
4854
  if (text === "") return { value: void 0 };
5136
4855
  let value;
5137
4856
  try {
@@ -5147,15 +4866,15 @@ function valueFromControl(kind, raw4, helpers, type) {
5147
4866
  }
5148
4867
  case "tags":
5149
4868
  case "enum-set": {
5150
- const items = JSON.parse(String(raw4));
4869
+ const items = JSON.parse(String(raw5));
5151
4870
  return { value: items.length ? items : void 0 };
5152
4871
  }
5153
4872
  case "choice": {
5154
- if (raw4 === "") return { value: void 0 };
5155
- if (!String(raw4).startsWith("#"))
5156
- return { value: JSON.parse(String(raw4)) };
4873
+ if (raw5 === "") return { value: void 0 };
4874
+ if (!String(raw5).startsWith("#"))
4875
+ return { value: JSON.parse(String(raw5)) };
5157
4876
  const member = choiceOptions(type.type, type.definitions).find(
5158
- (option) => option.value === raw4
4877
+ (option) => option.value === raw5
5159
4878
  ).member;
5160
4879
  const start = exampleValue(
5161
4880
  member,
@@ -5182,10 +4901,10 @@ function valueFromControl(kind, raw4, helpers, type) {
5182
4901
  }
5183
4902
  case "switch":
5184
4903
  return {
5185
- value: raw4 === type?.unset ? void 0 : raw4 === true
4904
+ value: raw5 === type?.unset ? void 0 : raw5 === true
5186
4905
  };
5187
4906
  case "size": {
5188
- if (raw4 === AXES_SIZE) {
4907
+ if (raw5 === AXES_SIZE) {
5189
4908
  if (isAxesValue(type?.current)) return { value: type.current };
5190
4909
  const start = [type?.current, type?.fallback].find(
5191
4910
  (item) => typeof item === "string" && item !== "" || isDynamic(item) && "$css" in item
@@ -5197,16 +4916,16 @@ function valueFromControl(kind, raw4, helpers, type) {
5197
4916
  )
5198
4917
  };
5199
4918
  }
5200
- return raw4 === "true" ? { value: true } : { value: raw4 === "" || raw4 === CUSTOM_SIZE ? void 0 : raw4 };
4919
+ return raw5 === "true" ? { value: true } : { value: raw5 === "" || raw5 === CUSTOM_SIZE ? void 0 : raw5 };
5201
4920
  }
5202
4921
  case "number": {
5203
- const text = String(raw4).trim();
4922
+ const text = String(raw5).trim();
5204
4923
  if (text === "") return { value: void 0 };
5205
4924
  const number = Number(text);
5206
4925
  return Number.isFinite(number) ? { value: number } : { error: "Enter a number." };
5207
4926
  }
5208
4927
  case "css": {
5209
- const text = String(raw4).trim();
4928
+ const text = String(raw5).trim();
5210
4929
  if (text === "") return { value: void 0 };
5211
4930
  const names = parseCssCall(text);
5212
4931
  if (!names)
@@ -5216,7 +4935,7 @@ function valueFromControl(kind, raw4, helpers, type) {
5216
4935
  return !helpers || helpers.includes(names[0]) ? { value: { $css: text } } : { error: `This prop takes ${listOf(helpers)}, not ${names[0]}().` };
5217
4936
  }
5218
4937
  default: {
5219
- const text = String(raw4);
4938
+ const text = String(raw5);
5220
4939
  if (kind === "text") return { value: text };
5221
4940
  if (text === "") return { value: void 0 };
5222
4941
  return {
@@ -5618,7 +5337,7 @@ function createFieldEditorViews(ctx, state) {
5618
5337
  place
5619
5338
  );
5620
5339
  const union = items ?? declared;
5621
- const record = value ?? {};
5340
+ const record2 = value ?? {};
5622
5341
  const switchField = memberSwitchField(union, definitions);
5623
5342
  const switcher = switchField ? memberSwitch(switchField, union, definitions, value, place) : void 0;
5624
5343
  const fields = objectFields(type, definitions).filter(
@@ -5626,7 +5345,7 @@ function createFieldEditorViews(ctx, state) {
5626
5345
  );
5627
5346
  const rows = fields.map((field) => {
5628
5347
  const at = { prop: place.prop, path: [...place.path, field.name] };
5629
- const fieldValue = record[field.name];
5348
+ const fieldValue = record2[field.name];
5630
5349
  const control = controlFor(field, fieldValue, definitions);
5631
5350
  const label = propLabel(field.name);
5632
5351
  if (isParamOrBind(fieldValue))
@@ -5679,7 +5398,7 @@ function createFieldEditorViews(ctx, state) {
5679
5398
  switcher ? [{ kind: "edit", row: switcher }, ...rows] : rows,
5680
5399
  `${stepTitle(place)} fields`
5681
5400
  ),
5682
- fieldBindSection(node, place, fields, definitions, record)
5401
+ fieldBindSection(node, place, fields, definitions, record2)
5683
5402
  ] });
5684
5403
  };
5685
5404
  const isParamOrBind = (value) => value !== null && typeof value === "object" && ("$param" in value || "$bind" in value);
@@ -5687,7 +5406,7 @@ function createFieldEditorViews(ctx, state) {
5687
5406
  const { $param, $bind } = value;
5688
5407
  return $param === void 0 ? String($bind) : `Param ${$param}`;
5689
5408
  };
5690
- const fieldBindSection = (node, place, fields, definitions, record) => {
5409
+ const fieldBindSection = (node, place, fields, definitions, record2) => {
5691
5410
  const bindable = fields.filter(
5692
5411
  (field2) => field2.type.kind !== "content" && paramTypeFor(resolveType(field2.type, definitions)) !== void 0
5693
5412
  );
@@ -5717,7 +5436,7 @@ function createFieldEditorViews(ctx, state) {
5717
5436
  prepare,
5718
5437
  resolveView
5719
5438
  );
5720
- const current = record[field.name];
5439
+ const current = record2[field.name];
5721
5440
  const bound2 = isParamOrBind(current) ? JSON.stringify(current) : "";
5722
5441
  const param = current?.$param;
5723
5442
  const choices = [
@@ -6444,7 +6163,7 @@ function createInspectorControls(ctx, state) {
6444
6163
  return /* @__PURE__ */ jsx(
6445
6164
  CheckboxGroup,
6446
6165
  {
6447
- label: propLabel(prop.name),
6166
+ label: fieldLabel(prop),
6448
6167
  name: `prop-${key}`,
6449
6168
  choices: offered.map((choice) => ({
6450
6169
  value: JSON.stringify(choice.value),
@@ -6465,7 +6184,7 @@ function createInspectorControls(ctx, state) {
6465
6184
  Select,
6466
6185
  {
6467
6186
  name: `prop-${key}`,
6468
- label: propLabel(prop.name),
6187
+ label: fieldLabel(prop),
6469
6188
  value: value === void 0 ? "" : JSON.stringify(value),
6470
6189
  choices: [
6471
6190
  { value: "", label: "Not set" },
@@ -6500,11 +6219,11 @@ function createInspectorControls(ctx, state) {
6500
6219
  "data-key": controlKey(place)
6501
6220
  };
6502
6221
  const grammar = cssGrammar(prop.type, definitionsOf(type));
6503
- const builderField = (raw4) => /* @__PURE__ */ jsx(
6222
+ const builderField = (raw5) => /* @__PURE__ */ jsx(
6504
6223
  TextField,
6505
6224
  {
6506
- label: `${propLabel(prop.name)} value`,
6507
- value: raw4,
6225
+ label: `${fieldLabel(prop)} value`,
6226
+ value: raw5,
6508
6227
  hint: cssHint(prop.cssValue?.helpers, grammar),
6509
6228
  placeholder: cssPlaceholder(prop.cssValue?.helpers, grammar),
6510
6229
  error,
@@ -6531,7 +6250,7 @@ function createInspectorControls(ctx, state) {
6531
6250
  Select,
6532
6251
  {
6533
6252
  name: `prop-${key}`,
6534
- label: propLabel(prop.name),
6253
+ label: fieldLabel(prop),
6535
6254
  value: custom ? CUSTOM_SIZE : String(control.raw),
6536
6255
  choices: control.choices.map((choice) => ({
6537
6256
  value: choice,
@@ -6567,7 +6286,7 @@ function createInspectorControls(ctx, state) {
6567
6286
  Select,
6568
6287
  {
6569
6288
  name: `prop-${key}`,
6570
- label: propLabel(prop.name),
6289
+ label: fieldLabel(prop),
6571
6290
  value: String(control.raw),
6572
6291
  choices: control.choices.map((choice) => ({
6573
6292
  value: choice,
@@ -6581,7 +6300,7 @@ function createInspectorControls(ctx, state) {
6581
6300
  return /* @__PURE__ */ jsx(
6582
6301
  Switch,
6583
6302
  {
6584
- label: propLabel(prop.name),
6303
+ label: fieldLabel(prop),
6585
6304
  checked: control.raw === true,
6586
6305
  rootAttributes: marker("switch")
6587
6306
  }
@@ -6589,12 +6308,12 @@ function createInspectorControls(ctx, state) {
6589
6308
  case "readonly":
6590
6309
  return void 0;
6591
6310
  case "icon":
6592
- return iconRow(propLabel(prop.name), String(control.raw), place);
6311
+ return iconRow(fieldLabel(prop), String(control.raw), place);
6593
6312
  // KF-3CKTKN: a typed value from a Select, and an open member's own
6594
6313
  // control (text, a number, a list) or form (an object) beneath it.
6595
6314
  case "choice": {
6596
6315
  const member = control.member && {
6597
- name: propLabel(prop.name),
6316
+ name: fieldLabel(prop),
6598
6317
  type: control.member,
6599
6318
  required: false
6600
6319
  };
@@ -6603,7 +6322,7 @@ function createInspectorControls(ctx, state) {
6603
6322
  Select,
6604
6323
  {
6605
6324
  name: `prop-${key}`,
6606
- label: `${propLabel(prop.name)} type`,
6325
+ label: `${fieldLabel(prop)} type`,
6607
6326
  value: String(control.raw),
6608
6327
  choices: [
6609
6328
  {
@@ -6618,7 +6337,7 @@ function createInspectorControls(ctx, state) {
6618
6337
  rootAttributes: marker("choice")
6619
6338
  }
6620
6339
  ),
6621
- member ? fieldEditorKind(member.type, definitionsOf(type)) === "object" ? configureRow(propLabel(prop.name), value, place) : propControl(member, value, type, place) : void 0
6340
+ member ? fieldEditorKind(member.type, definitionsOf(type)) === "object" ? configureRow(fieldLabel(prop), value, place) : propControl(member, value, type, place) : void 0
6622
6341
  ] });
6623
6342
  }
6624
6343
  // KF-A9ZHGW: strings edit inline as tags, enum values as checkboxes.
@@ -6627,7 +6346,7 @@ function createInspectorControls(ctx, state) {
6627
6346
  TagField,
6628
6347
  {
6629
6348
  id: `editor-tags-${key}`,
6630
- label: propLabel(prop.name),
6349
+ label: fieldLabel(prop),
6631
6350
  tags: JSON.parse(String(control.raw)),
6632
6351
  error,
6633
6352
  rootAttributes: marker("tags")
@@ -6637,7 +6356,7 @@ function createInspectorControls(ctx, state) {
6637
6356
  return /* @__PURE__ */ jsx(
6638
6357
  CheckboxGroup,
6639
6358
  {
6640
- label: propLabel(prop.name),
6359
+ label: fieldLabel(prop),
6641
6360
  name: `prop-${key}`,
6642
6361
  choices: control.choices.map((choice) => ({
6643
6362
  value: choice,
@@ -6659,7 +6378,7 @@ function createInspectorControls(ctx, state) {
6659
6378
  /* @__PURE__ */ jsx(
6660
6379
  TextField,
6661
6380
  {
6662
- label: propLabel(prop.name),
6381
+ label: fieldLabel(prop),
6663
6382
  value: String(control.raw),
6664
6383
  multiline: true,
6665
6384
  rows: control.raw === "" ? 2 : 4,
@@ -6692,7 +6411,7 @@ function createInspectorControls(ctx, state) {
6692
6411
  return /* @__PURE__ */ jsx(
6693
6412
  TextField,
6694
6413
  {
6695
- label: propLabel(prop.name),
6414
+ label: fieldLabel(prop),
6696
6415
  value: String(control.raw),
6697
6416
  type: control.kind === "number" ? "number" : "text",
6698
6417
  multiline,
@@ -6765,7 +6484,7 @@ function insertPlacement(document2, catalog, node, target, position, zonesOf) {
6765
6484
  document2,
6766
6485
  next,
6767
6486
  catalog,
6768
- (diagnostic) => unfilled(diagnostic, node.type)
6487
+ (diagnostic2) => unfilled(diagnostic2, node.type)
6769
6488
  );
6770
6489
  });
6771
6490
  }
@@ -7034,7 +6753,7 @@ function replaceNode2(document2, catalog, target, by) {
7034
6753
  document2,
7035
6754
  next,
7036
6755
  catalog,
7037
- (diagnostic) => "node" in by && unfilled(diagnostic, by.node.type)
6756
+ (diagnostic2) => "node" in by && unfilled(diagnostic2, by.node.type)
7038
6757
  ) ? void 0 : next;
7039
6758
  }
7040
6759
 
@@ -7066,7 +6785,7 @@ function variantFix(node, variants) {
7066
6785
  const props = node.props ?? {};
7067
6786
  const present = /* @__PURE__ */ new Set([
7068
6787
  ...Object.keys(props),
7069
- ...Object.entries(node.zones ?? {}).filter(([, children]) => children.length).map(([zone]) => zone)
6788
+ ...Object.entries(node.zones ?? {}).filter(([, children2]) => children2.length).map(([zone]) => zone)
7070
6789
  ]);
7071
6790
  const differs = (name, value) => present.has(name) ? !bound(props[name]) && props[name] !== value : value !== false;
7072
6791
  const changes = variants.map((variant) => [
@@ -7088,19 +6807,19 @@ function variantFix(node, variants) {
7088
6807
  }
7089
6808
  var NO_VARIANT = /props match none of its variants$/;
7090
6809
  function problemsOf(document2, diagnostics, variantsOf = () => void 0) {
7091
- return diagnostics.map((diagnostic) => {
7092
- const nodeId = nodeIdForPath(document2, diagnostic.path);
7093
- if (!nodeId) return { diagnostic };
6810
+ return diagnostics.map((diagnostic2) => {
6811
+ const nodeId = nodeIdForPath(document2, diagnostic2.path);
6812
+ if (!nodeId) return { diagnostic: diagnostic2 };
7094
6813
  const node = findNode(document2, nodeId).node;
7095
6814
  const variants = variantsOf(node.type);
7096
- const fix = variants?.length && NO_VARIANT.test(diagnostic.message) ? variantFix(node, variants) : "";
6815
+ const fix = variants?.length && NO_VARIANT.test(diagnostic2.message) ? variantFix(node, variants) : "";
7097
6816
  return fix ? {
7098
6817
  diagnostic: {
7099
- ...diagnostic,
7100
- message: `${diagnostic.message}: ${fix}`
6818
+ ...diagnostic2,
6819
+ message: `${diagnostic2.message}: ${fix}`
7101
6820
  },
7102
6821
  nodeId
7103
- } : { diagnostic, nodeId };
6822
+ } : { diagnostic: diagnostic2, nodeId };
7104
6823
  });
7105
6824
  }
7106
6825
  function problemCounts2(problems) {
@@ -7121,7 +6840,7 @@ function readableMessage(message, names) {
7121
6840
  }
7122
6841
  function placementReason(document2, added, id, names) {
7123
6842
  const reason = added.find(
7124
- (diagnostic) => nodeIdForPath(document2, diagnostic.path) === id
6843
+ (diagnostic2) => nodeIdForPath(document2, diagnostic2.path) === id
7125
6844
  ) ?? added[0];
7126
6845
  return reason && readableMessage(reason.message, names);
7127
6846
  }
@@ -7272,7 +6991,7 @@ function createLibraryDrag(ctx, deps) {
7272
6991
  const zone = empty?.zone ?? slot?.zone ?? zoneKeys(target).find((key) => target.props?.[key] === void 0);
7273
6992
  if (!zone) return `${name} cannot go here`;
7274
6993
  const before = new Set(
7275
- currentProblems.value.map(({ diagnostic }) => diagnostic.message)
6994
+ currentProblems.value.map(({ diagnostic: diagnostic2 }) => diagnostic2.message)
7276
6995
  );
7277
6996
  const inserted = fromLibrary(sourceId) ? node : (
7278
6997
  // A copy, so its names do not clash with the original's.
@@ -7292,7 +7011,7 @@ function createLibraryDrag(ctx, deps) {
7292
7011
  return placementReason(
7293
7012
  placed2,
7294
7013
  validateView(placed2, viewCatalog).diagnostics.filter(
7295
- (diagnostic) => !before.has(diagnostic.message)
7014
+ (diagnostic2) => !before.has(diagnostic2.message)
7296
7015
  ),
7297
7016
  inserted.id,
7298
7017
  componentNames
@@ -7404,8 +7123,8 @@ function createLibraryDrag(ctx, deps) {
7404
7123
  const zoneDrop = (sourceId, parent, zone) => {
7405
7124
  const move = zoneMove(sourceId, parent, zone);
7406
7125
  if (dropFor(move)) return move;
7407
- const children = parent.zones?.[zone];
7408
- const only = children?.length === 1 ? children[0] : void 0;
7126
+ const children2 = parent.zones?.[zone];
7127
+ const only = children2?.length === 1 ? children2[0] : void 0;
7409
7128
  return only && "id" in only && "type" in only ? replaceMove(sourceId, only.id) : void 0;
7410
7129
  };
7411
7130
  const canvasNode = (element) => {
@@ -7520,20 +7239,15 @@ function createLibraryDrag(ctx, deps) {
7520
7239
  zoneKeys
7521
7240
  };
7522
7241
  }
7242
+
7243
+ // src/editor/library-memory.ts
7523
7244
  var PALETTE_VIEW_ACTION = "editor-palette-view";
7524
7245
  var LIBRARY_MODE_ACTION = "editor-library-mode";
7525
7246
  var DOCUMENT_VIEW_ACTION = "editor-document-view";
7526
7247
  var DOCUMENT_ROW_ACTION = "editor-document-row";
7527
7248
  var DOCUMENT_TOGGLE_ACTION = "editor-document-toggle";
7528
- var DOCUMENT_BACK_ACTION = "editor-document-back";
7529
7249
  var DOCUMENT_VIEW_KEY = "kerf-ui-editor:document-view";
7530
7250
  var PALETTE_VIEW_KEY = "kerf-ui-editor:palette-view";
7531
- var PALETTE_ICONS = {
7532
- "@kerfjs/ui:lucide-icon": FaceSlightlySmiling,
7533
- "@kerfjs/ui:loading-spinner": LoaderCircle,
7534
- "@kerfjs/ui:corner-status": BadgeCheck,
7535
- "@kerfjs/ui:edge-activity-indicator": Activity
7536
- };
7537
7251
  function rememberedPaletteView() {
7538
7252
  try {
7539
7253
  return globalThis.localStorage?.getItem(PALETTE_VIEW_KEY) === "grid" ? "grid" : "list";
@@ -7584,6 +7298,28 @@ function rememberLibrary({ pinned, placement }) {
7584
7298
  } catch {
7585
7299
  }
7586
7300
  }
7301
+ var categories = [
7302
+ [/\.json$/i, FileBracesCorner, "file-braces-corner"],
7303
+ [
7304
+ /\.(?:[cm]?[jt]sx?|html?|css|scss|vue|svelte|xml|ya?ml|sh)$/i,
7305
+ FileCodeCorner,
7306
+ "file-code-corner"
7307
+ ],
7308
+ [/\.(?:mdx?|txt|rtf|pdf)$/i, FileText, "file-text"],
7309
+ [/\.(?:png|jpe?g|gif|webp|avif|svg|ico|tiff?)$/i, FileImage, "file-image"],
7310
+ [/\.(?:mp3|wav|ogg|flac|m4a|aac)$/i, FileHeadphone, "file-headphone"],
7311
+ [/\.(?:mp4|webm|mov|avi|mkv)$/i, FilePlay, "file-play"],
7312
+ [/\.(?:zip|tar|gz|bz2|7z|rar)$/i, FileArchive, "file-archive"],
7313
+ [/\.(?:csv|tsv|xlsx?|ods)$/i, FileSpreadsheet, "file-spreadsheet"]
7314
+ ];
7315
+ function libraryDocumentIcon(path) {
7316
+ const [, icon, name] = categories.find(([pattern]) => pattern.test(path)) ?? [
7317
+ null,
7318
+ File,
7319
+ "file"
7320
+ ];
7321
+ return LucideIcon({ icon, name });
7322
+ }
7587
7323
 
7588
7324
  // src/editor/model/library-document-tree.ts
7589
7325
  var documentFolderId = (path) => `folder:${path}`;
@@ -7613,88 +7349,344 @@ function libraryDocumentTree(paths) {
7613
7349
  ...[...folder.folders.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => ({
7614
7350
  id: documentFolderId(child.path),
7615
7351
  label: child.name,
7352
+ icon: LucideIcon({ icon: Folder, name: "folder" }),
7616
7353
  children: rows(child)
7617
7354
  })),
7618
7355
  ...folder.files.sort((a, b) => documentName(a).localeCompare(documentName(b))).map((path) => ({
7619
7356
  id: path,
7620
7357
  label: documentName(path),
7358
+ icon: libraryDocumentIcon(path),
7621
7359
  rootAttributes: { "data-editor-palette-document": path }
7622
7360
  }))
7623
7361
  ];
7624
7362
  return rows(root);
7625
7363
  }
7626
-
7627
- // src/editor/palette-schematics.ts
7628
- var WIDTH = 96;
7629
- var HEIGHT = 72;
7630
- var box = ({ x, y, w, h, fill, line = false, r = 2 }) => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}" fill="currentColor" fill-opacity="${fill ?? 0}"${line ? ' stroke="currentColor" stroke-opacity="0.55"' : ""}/>`;
7631
- var stroke = (d, opacity = 0.55) => `<path d="${d}" fill="none" stroke="currentColor" stroke-opacity="${opacity}" stroke-linecap="round" stroke-linejoin="round"/>`;
7632
- var FRAME = box({ x: 4, y: 4, w: 88, h: 64, line: true, r: 4 });
7633
- var lines = (x, y, w, count, gap = 8) => Array.from(
7634
- { length: count },
7635
- (_, index) => box({
7636
- x,
7637
- y: y + index * gap,
7638
- w: w * (index % 2 ? 0.7 : 1),
7639
- h: 3,
7640
- fill: 0.3,
7641
- r: 1.5
7642
- })
7643
- ).join("");
7644
- var SKETCHES = {
7645
- workbench: [
7646
- FRAME,
7647
- box({ x: 4, y: 4, w: 22, h: 64, fill: 0.12, r: 4 }),
7648
- box({ x: 70, y: 4, w: 22, h: 64, fill: 0.12, r: 4 }),
7649
- box({ x: 26, y: 4, w: 44, h: 10, fill: 0.06, r: 0 }),
7650
- box({ x: 26, y: 52, w: 44, h: 16, fill: 0.09, r: 0 }),
7651
- lines(8, 12, 14, 4),
7652
- lines(74, 12, 14, 4)
7653
- ].join(""),
7654
- "split-view": [
7655
- FRAME,
7656
- box({ x: 4, y: 4, w: 32, h: 64, fill: 0.12, r: 4 }),
7657
- lines(8, 12, 24, 6),
7658
- lines(42, 12, 44, 3, 10)
7659
- ].join(""),
7660
- "nav-stack": [
7661
- FRAME,
7662
- box({ x: 4, y: 4, w: 88, h: 14, fill: 0.08, r: 4 }),
7663
- stroke("M13 8 L9 11 L13 14"),
7664
- box({ x: 36, y: 9.5, w: 24, h: 3, fill: 0.4, r: 1.5 }),
7665
- lines(10, 26, 76, 5)
7666
- ].join(""),
7667
- "tab-navigator": [
7668
- FRAME,
7669
- box({ x: 4, y: 54, w: 88, h: 14, fill: 0.08, r: 4 }),
7670
- ...[22, 48, 74].map(
7671
- (x, index) => box({ x: x - 4, y: 58, w: 8, h: 6, fill: index ? 0.3 : 0.7, r: 2 })
7672
- ),
7673
- lines(10, 12, 76, 4)
7674
- ].join(""),
7675
- pane: [
7676
- FRAME,
7677
- box({ x: 4, y: 4, w: 88, h: 14, fill: 0.08, r: 4 }),
7678
- box({ x: 10, y: 9.5, w: 26, h: 3, fill: 0.4, r: 1.5 }),
7679
- lines(10, 26, 76, 5)
7680
- ].join(""),
7681
- "collapsible-panel": [
7682
- FRAME,
7683
- box({ x: 4, y: 4, w: 30, h: 64, fill: 0.12, r: 4 }),
7684
- stroke("M27 34 L24 37 L27 40"),
7685
- lines(8, 12, 14, 3),
7686
- lines(40, 12, 46, 4)
7687
- ].join(""),
7688
- "surface-scaffold": [
7689
- box({ x: 0, y: 0, w: WIDTH, h: HEIGHT, fill: 0.08, r: 4 }),
7690
- box({ x: 18, y: 12, w: 60, h: 48, fill: 0.02, line: true, r: 4 }),
7691
- box({ x: 24, y: 18, w: 22, h: 3, fill: 0.45, r: 1.5 }),
7692
- lines(24, 28, 48, 2),
7693
- box({ x: 58, y: 48, w: 14, h: 6, fill: 0.5, r: 3 }),
7694
- box({ x: 42, y: 48, w: 14, h: 6, line: true, r: 3 })
7695
- ].join(""),
7696
- "surface-scaffold#PopoverDialogSurface": [
7697
- box({ x: 10, y: 8, w: 20, h: 8, line: true, r: 3 }),
7364
+ function createLibraryPopover(ctx, state) {
7365
+ const { catalog, selection } = ctx;
7366
+ const {
7367
+ paletteFilter,
7368
+ paletteFilterRevision,
7369
+ paletteView,
7370
+ libraryMode,
7371
+ documentView,
7372
+ documentPath,
7373
+ collapsedDocumentFolders,
7374
+ libraryFiles,
7375
+ libraryError
7376
+ } = state;
7377
+ const paletteMatches = () => {
7378
+ const query = paletteFilter.value.trim().toLocaleLowerCase();
7379
+ const holds2 = (text) => text.toLocaleLowerCase().includes(query);
7380
+ return catalog.paletteGroups().map((group) => ({
7381
+ ...group,
7382
+ items: holds2(group.category) ? group.items : group.items.filter((item) => holds2(item.name))
7383
+ })).filter((group) => group.items.length);
7384
+ };
7385
+ const fallbackIcon = (key) => {
7386
+ try {
7387
+ return LucideIcon({
7388
+ icon: catalog.libraryPreviews?.[key]?.icon ?? Component,
7389
+ name: "component"
7390
+ });
7391
+ } catch {
7392
+ return LucideIcon({ icon: Component, name: "component" });
7393
+ }
7394
+ };
7395
+ const paletteSelected = (key) => selection.value?.kind === "component" && selection.value.key === key;
7396
+ const palette = (groups) => /* @__PURE__ */ jsx(List, { gap: "m", children: groups.map((group) => /* @__PURE__ */ jsxs(List, { children: [
7397
+ /* @__PURE__ */ jsx(ListHeader, { label: group.category }),
7398
+ paletteView.value === "grid" ? /* @__PURE__ */ jsx(Grid, { minColumnWidth: px(96), autoFill: true, gap: "xs", children: group.items.map((item) => /* @__PURE__ */ jsxs(
7399
+ ContentItem,
7400
+ {
7401
+ interactive: true,
7402
+ action: PALETTE_ACTION,
7403
+ itemId: item.key,
7404
+ selectionMode: "single",
7405
+ selected: paletteSelected(item.key),
7406
+ ariaLabel: item.name,
7407
+ title: item.name,
7408
+ frame: "framed",
7409
+ rootAttributes: {
7410
+ [HOOK.palette]: item.key,
7411
+ "data-key": item.key
7412
+ },
7413
+ children: [
7414
+ /* @__PURE__ */ jsx(
7415
+ "div",
7416
+ {
7417
+ class: "kui-editor__palette-thumb",
7418
+ ...{ [HOOK.paletteThumb]: item.key },
7419
+ "data-morph-skip": true,
7420
+ "aria-hidden": "true",
7421
+ inert: true,
7422
+ children: fallbackIcon(item.key)
7423
+ }
7424
+ ),
7425
+ /* @__PURE__ */ jsx(Text, { variant: "span", size: "compact", wrap: "truncate", children: item.name })
7426
+ ]
7427
+ }
7428
+ )) }) : group.items.map((item) => /* @__PURE__ */ jsx(
7429
+ ListItem,
7430
+ {
7431
+ action: PALETTE_ACTION,
7432
+ itemId: item.key,
7433
+ label: item.name,
7434
+ rootAttributes: { [HOOK.palette]: item.key },
7435
+ selected: paletteSelected(item.key)
7436
+ }
7437
+ ))
7438
+ ] })) });
7439
+ const filteredDocuments = computed(
7440
+ () => libraryDocuments(libraryFiles.value, paletteFilter.value)
7441
+ );
7442
+ const documentNodes = computed(
7443
+ () => libraryDocumentTree(filteredDocuments.value)
7444
+ );
7445
+ const documentFolders = computed(
7446
+ () => new Set(
7447
+ filteredDocuments.value.flatMap((path) => {
7448
+ const parts = path.split("/").filter(Boolean);
7449
+ return parts.slice(0, -1).map(
7450
+ (_, index) => documentFolderId(`${parts.slice(0, index + 1).join("/")}/`)
7451
+ );
7452
+ })
7453
+ )
7454
+ );
7455
+ const libraryDocumentGroup = () => {
7456
+ const nodes = documentNodes.value;
7457
+ return documentView.value === "columns" ? /* @__PURE__ */ jsx(
7458
+ ColumnExplorer,
7459
+ {
7460
+ id: "editor-library-documents-columns",
7461
+ label: LIBRARY_DOCUMENTS,
7462
+ nodes,
7463
+ path: documentPath.value,
7464
+ action: DOCUMENT_ROW_ACTION,
7465
+ layout: "paged",
7466
+ rootHeading: "Project",
7467
+ inset: "none"
7468
+ }
7469
+ ) : /* @__PURE__ */ jsx(
7470
+ TreeList,
7471
+ {
7472
+ id: "editor-library-documents-tree",
7473
+ keyedRows: true,
7474
+ label: LIBRARY_DOCUMENTS,
7475
+ nodes,
7476
+ expanded: new Set(
7477
+ [...documentFolders.value].filter(
7478
+ (id) => !collapsedDocumentFolders.value.has(id)
7479
+ )
7480
+ ),
7481
+ selected: documentPath.value.at(-1),
7482
+ action: DOCUMENT_ROW_ACTION,
7483
+ toggleAction: DOCUMENT_TOGGLE_ACTION,
7484
+ density: "compact"
7485
+ }
7486
+ );
7487
+ };
7488
+ const libraryPopover = () => {
7489
+ const componentsMode = libraryMode.value === "components";
7490
+ const groups = componentsMode ? paletteMatches() : [];
7491
+ const documents = componentsMode ? [] : filteredDocuments.value;
7492
+ return /* @__PURE__ */ jsxs(
7493
+ PinnablePopoverSurface,
7494
+ {
7495
+ id: LIBRARY_ID,
7496
+ label: "Library",
7497
+ size: "small",
7498
+ height: px(560),
7499
+ minHeight: px(320),
7500
+ bodyLayout: "fill-last",
7501
+ bodyInset: "none",
7502
+ resizeFromBottom: true,
7503
+ headerActions: componentsMode ? (
7504
+ // KF-JC7WTW: a list of names, or a grid of thumbnails.
7505
+ /* @__PURE__ */ jsx(
7506
+ SegmentedControl,
7507
+ {
7508
+ id: "editor-palette-view",
7509
+ label: "Component View",
7510
+ value: paletteView.value,
7511
+ action: PALETTE_VIEW_ACTION,
7512
+ choices: [
7513
+ {
7514
+ value: "list",
7515
+ label: "List",
7516
+ title: "List",
7517
+ content: /* @__PURE__ */ jsx(LucideIcon, { icon: List$1, name: "list" })
7518
+ },
7519
+ {
7520
+ value: "grid",
7521
+ label: "Grid",
7522
+ title: "Grid",
7523
+ content: /* @__PURE__ */ jsx(LucideIcon, { icon: LayoutGrid, name: "layout-grid" })
7524
+ }
7525
+ ]
7526
+ }
7527
+ )
7528
+ ) : /* @__PURE__ */ jsx(
7529
+ SegmentedControl,
7530
+ {
7531
+ id: "editor-document-view",
7532
+ label: "Document View",
7533
+ value: documentView.value,
7534
+ action: DOCUMENT_VIEW_ACTION,
7535
+ choices: [
7536
+ {
7537
+ value: "columns",
7538
+ label: "Columns",
7539
+ title: "Columns",
7540
+ content: /* @__PURE__ */ jsx(LucideIcon, { icon: Columns3, name: "columns" })
7541
+ },
7542
+ {
7543
+ value: "tree",
7544
+ label: "Tree",
7545
+ title: "Tree",
7546
+ content: /* @__PURE__ */ jsx(LucideIcon, { icon: ListTree, name: "list-tree" })
7547
+ }
7548
+ ]
7549
+ }
7550
+ ),
7551
+ rootAttributes: { [HOOK.library]: "" },
7552
+ children: [
7553
+ /* @__PURE__ */ jsxs(List, { controlInsets: "trbl", gap: true, children: [
7554
+ /* @__PURE__ */ jsx(
7555
+ SegmentedControl,
7556
+ {
7557
+ id: "editor-library-mode",
7558
+ label: "Library Content",
7559
+ layout: "equal",
7560
+ value: libraryMode.value,
7561
+ action: LIBRARY_MODE_ACTION,
7562
+ choices: [
7563
+ { value: "components", label: "Components" },
7564
+ { value: "documents", label: "Documents" }
7565
+ ]
7566
+ }
7567
+ ),
7568
+ /* @__PURE__ */ jsx(
7569
+ SearchField,
7570
+ {
7571
+ id: "editor-palette-filter",
7572
+ label: componentsMode ? "Filter Components" : "Filter Documents",
7573
+ placeholder: "Filter",
7574
+ query: paletteFilter.value,
7575
+ revision: paletteFilterRevision.value,
7576
+ clearAction: PALETTE_CLEAR_ACTION,
7577
+ clearLabel: "Clear Filter",
7578
+ editorAttributes: { [HOOK.paletteFilter]: "" }
7579
+ }
7580
+ ),
7581
+ libraryError.value ? /* @__PURE__ */ jsx(
7582
+ StateBanner,
7583
+ {
7584
+ tone: "danger",
7585
+ title: "That document cannot be inserted",
7586
+ detail: libraryError.value,
7587
+ rootAttributes: { "data-editor-library-error": "" }
7588
+ }
7589
+ ) : void 0
7590
+ ] }),
7591
+ /* @__PURE__ */ jsx(
7592
+ List,
7593
+ {
7594
+ scrollable: true,
7595
+ flex: true,
7596
+ rootAttributes: { "data-editor-library-results": "" },
7597
+ children: componentsMode ? groups.length ? palette(groups) : /* @__PURE__ */ jsx(
7598
+ EmptyState,
7599
+ {
7600
+ title: "No matching components",
7601
+ detail: "No component name or category holds that text."
7602
+ }
7603
+ ) : documents.length ? libraryDocumentGroup() : /* @__PURE__ */ jsx(
7604
+ EmptyState,
7605
+ {
7606
+ title: "No matching documents",
7607
+ detail: "No project document name or folder holds that text."
7608
+ }
7609
+ )
7610
+ }
7611
+ )
7612
+ ]
7613
+ }
7614
+ );
7615
+ };
7616
+ return libraryPopover;
7617
+ }
7618
+
7619
+ // src/editor/palette-schematics.ts
7620
+ var WIDTH = 96;
7621
+ var HEIGHT = 72;
7622
+ var box = ({ x, y, w, h, fill, line = false, r = 2 }) => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}" fill="currentColor" fill-opacity="${fill ?? 0}"${line ? ' stroke="currentColor" stroke-opacity="0.55"' : ""}/>`;
7623
+ var stroke = (d, opacity = 0.55) => `<path d="${d}" fill="none" stroke="currentColor" stroke-opacity="${opacity}" stroke-linecap="round" stroke-linejoin="round"/>`;
7624
+ var FRAME = box({ x: 4, y: 4, w: 88, h: 64, line: true, r: 4 });
7625
+ var lines = (x, y, w, count, gap = 8) => Array.from(
7626
+ { length: count },
7627
+ (_, index) => box({
7628
+ x,
7629
+ y: y + index * gap,
7630
+ w: w * (index % 2 ? 0.7 : 1),
7631
+ h: 3,
7632
+ fill: 0.3,
7633
+ r: 1.5
7634
+ })
7635
+ ).join("");
7636
+ var SKETCHES = {
7637
+ workbench: [
7638
+ FRAME,
7639
+ box({ x: 4, y: 4, w: 22, h: 64, fill: 0.12, r: 4 }),
7640
+ box({ x: 70, y: 4, w: 22, h: 64, fill: 0.12, r: 4 }),
7641
+ box({ x: 26, y: 4, w: 44, h: 10, fill: 0.06, r: 0 }),
7642
+ box({ x: 26, y: 52, w: 44, h: 16, fill: 0.09, r: 0 }),
7643
+ lines(8, 12, 14, 4),
7644
+ lines(74, 12, 14, 4)
7645
+ ].join(""),
7646
+ "split-view": [
7647
+ FRAME,
7648
+ box({ x: 4, y: 4, w: 32, h: 64, fill: 0.12, r: 4 }),
7649
+ lines(8, 12, 24, 6),
7650
+ lines(42, 12, 44, 3, 10)
7651
+ ].join(""),
7652
+ "nav-stack": [
7653
+ FRAME,
7654
+ box({ x: 4, y: 4, w: 88, h: 14, fill: 0.08, r: 4 }),
7655
+ stroke("M13 8 L9 11 L13 14"),
7656
+ box({ x: 36, y: 9.5, w: 24, h: 3, fill: 0.4, r: 1.5 }),
7657
+ lines(10, 26, 76, 5)
7658
+ ].join(""),
7659
+ "tab-navigator": [
7660
+ FRAME,
7661
+ box({ x: 4, y: 54, w: 88, h: 14, fill: 0.08, r: 4 }),
7662
+ ...[22, 48, 74].map(
7663
+ (x, index) => box({ x: x - 4, y: 58, w: 8, h: 6, fill: index ? 0.3 : 0.7, r: 2 })
7664
+ ),
7665
+ lines(10, 12, 76, 4)
7666
+ ].join(""),
7667
+ pane: [
7668
+ FRAME,
7669
+ box({ x: 4, y: 4, w: 88, h: 14, fill: 0.08, r: 4 }),
7670
+ box({ x: 10, y: 9.5, w: 26, h: 3, fill: 0.4, r: 1.5 }),
7671
+ lines(10, 26, 76, 5)
7672
+ ].join(""),
7673
+ "collapsible-panel": [
7674
+ FRAME,
7675
+ box({ x: 4, y: 4, w: 30, h: 64, fill: 0.12, r: 4 }),
7676
+ stroke("M27 34 L24 37 L27 40"),
7677
+ lines(8, 12, 14, 3),
7678
+ lines(40, 12, 46, 4)
7679
+ ].join(""),
7680
+ "surface-scaffold": [
7681
+ box({ x: 0, y: 0, w: WIDTH, h: HEIGHT, fill: 0.08, r: 4 }),
7682
+ box({ x: 18, y: 12, w: 60, h: 48, fill: 0.02, line: true, r: 4 }),
7683
+ box({ x: 24, y: 18, w: 22, h: 3, fill: 0.45, r: 1.5 }),
7684
+ lines(24, 28, 48, 2),
7685
+ box({ x: 58, y: 48, w: 14, h: 6, fill: 0.5, r: 3 }),
7686
+ box({ x: 42, y: 48, w: 14, h: 6, line: true, r: 3 })
7687
+ ].join(""),
7688
+ "surface-scaffold#PopoverDialogSurface": [
7689
+ box({ x: 10, y: 8, w: 20, h: 8, line: true, r: 3 }),
7698
7690
  stroke("M20 20 L24 24 L16 24 Z", 0.55),
7699
7691
  box({ x: 10, y: 24, w: 62, h: 40, line: true, r: 4 }),
7700
7692
  lines(16, 32, 50, 3)
@@ -7856,263 +7848,152 @@ function paletteSketch(key) {
7856
7848
  const drawing = SKETCHES[SAME_AS[id] ?? id];
7857
7849
  return drawing === void 0 ? void 0 : `<svg viewBox="0 0 ${WIDTH} ${HEIGHT}" width="100%" height="100%" aria-hidden="true">${drawing}</svg>`;
7858
7850
  }
7859
- function createLibraryPopover(ctx, state) {
7860
- const { catalog, selection } = ctx;
7861
- const {
7862
- paletteFilter,
7863
- paletteFilterRevision,
7864
- paletteView,
7865
- libraryMode,
7866
- documentView,
7867
- documentPath,
7868
- collapsedDocumentFolders,
7869
- libraryFiles,
7870
- libraryError
7871
- } = state;
7872
- const paletteMatches = () => {
7873
- const query = paletteFilter.value.trim().toLocaleLowerCase();
7874
- const holds2 = (text) => text.toLocaleLowerCase().includes(query);
7875
- return catalog.paletteGroups().map((group) => ({
7876
- ...group,
7877
- items: holds2(group.category) ? group.items : group.items.filter((item) => holds2(item.name))
7878
- })).filter((group) => group.items.length);
7879
- };
7880
- const paletteSelected = (key) => selection.value?.kind === "component" && selection.value.key === key;
7881
- const palette = (groups) => /* @__PURE__ */ jsx(List, { gap: "m", children: groups.map((group) => /* @__PURE__ */ jsxs(List, { children: [
7882
- /* @__PURE__ */ jsx(ListHeader, { label: group.category }),
7883
- paletteView.value === "grid" ? /* @__PURE__ */ jsx(Grid, { minColumnWidth: px(96), autoFill: true, gap: "xs", children: group.items.map((item) => /* @__PURE__ */ jsxs(
7884
- ContentItem,
7851
+ function paletteSketches() {
7852
+ return Object.fromEntries(
7853
+ [...Object.keys(SKETCHES), ...Object.keys(SAME_AS)].map((id) => {
7854
+ const key = `@kerfjs/ui:${id}`;
7855
+ return [key, paletteSketch(key)];
7856
+ })
7857
+ );
7858
+ }
7859
+
7860
+ // src/editor/library-preview-defaults.ts
7861
+ var KERF_UI_LIBRARY_PREVIEWS = {
7862
+ ...Object.fromEntries(
7863
+ Object.entries(paletteSketches()).map(([key, drawing]) => [
7864
+ key,
7865
+ { render: () => raw(drawing), fit: "fill" }
7866
+ ])
7867
+ ),
7868
+ ...Object.fromEntries(
7869
+ Object.entries({
7870
+ "@kerfjs/ui:lucide-icon": FaceSlightlySmiling,
7871
+ "@kerfjs/ui:loading-spinner": LoaderCircle,
7872
+ "@kerfjs/ui:corner-status": BadgeCheck,
7873
+ "@kerfjs/ui:edge-activity-indicator": Activity
7874
+ }).map(([key, icon]) => [
7875
+ key,
7885
7876
  {
7886
- interactive: true,
7887
- action: PALETTE_ACTION,
7888
- itemId: item.key,
7889
- selectionMode: "single",
7890
- selected: paletteSelected(item.key),
7891
- ariaLabel: item.name,
7892
- title: item.name,
7893
- frame: "framed",
7894
- rootAttributes: {
7895
- [HOOK.palette]: item.key,
7896
- "data-key": item.key
7897
- },
7898
- children: [
7899
- paletteSketch(item.key) || PALETTE_ICONS[item.key] ? /* @__PURE__ */ jsx("div", { class: "kui-editor__palette-thumb", "aria-hidden": "true", children: PALETTE_ICONS[item.key] ? /* @__PURE__ */ jsx(
7900
- LucideIcon,
7901
- {
7902
- icon: PALETTE_ICONS[item.key],
7903
- name: "component"
7904
- }
7905
- ) : raw(paletteSketch(item.key)) }) : /* @__PURE__ */ jsx(
7906
- "div",
7907
- {
7908
- class: "kui-editor__palette-thumb",
7909
- ...{ [HOOK.paletteThumb]: item.key },
7910
- "data-morph-skip": true,
7911
- "aria-hidden": "true",
7912
- inert: true,
7913
- children: /* @__PURE__ */ jsx(LucideIcon, { icon: Component, name: "component" })
7914
- }
7915
- ),
7916
- /* @__PURE__ */ jsx(Text, { variant: "span", size: "compact", wrap: "truncate", children: item.name })
7917
- ]
7877
+ render: () => LucideIcon({ icon, name: "component" }),
7878
+ icon,
7879
+ fit: "fill"
7918
7880
  }
7919
- )) }) : group.items.map((item) => /* @__PURE__ */ jsx(
7920
- ListItem,
7921
- {
7922
- action: PALETTE_ACTION,
7923
- itemId: item.key,
7924
- label: item.name,
7925
- rootAttributes: { [HOOK.palette]: item.key },
7926
- selected: paletteSelected(item.key)
7881
+ ])
7882
+ )
7883
+ };
7884
+
7885
+ // src/editor/library-previews.ts
7886
+ function defineLibraryPreviews(components, previews) {
7887
+ return previews;
7888
+ }
7889
+ function object(value) {
7890
+ return value !== null && typeof value === "object" && !Array.isArray(value);
7891
+ }
7892
+ function json(value, ancestors = /* @__PURE__ */ new Set()) {
7893
+ if (value === null || typeof value === "string" || typeof value === "boolean")
7894
+ return true;
7895
+ if (typeof value === "number") return Number.isFinite(value);
7896
+ if (typeof value !== "object" || ancestors.has(value)) return false;
7897
+ const prototype = Object.getPrototypeOf(value);
7898
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
7899
+ return false;
7900
+ ancestors.add(value);
7901
+ const valid = Reflect.ownKeys(value).every((key) => typeof key === "string") && Object.values(value).every((item) => json(item, ancestors));
7902
+ ancestors.delete(value);
7903
+ return valid;
7904
+ }
7905
+ function mergeLibraryPreviews(...layers) {
7906
+ const result = {};
7907
+ for (const layer of layers)
7908
+ for (const [key, preview] of Object.entries(layer ?? {})) {
7909
+ if (object(preview)) result[key] = preview;
7910
+ }
7911
+ return result;
7912
+ }
7913
+ function libraryPreviewSamples(catalogs) {
7914
+ const result = {};
7915
+ for (const catalog of catalogs) {
7916
+ if (!object(catalog) || !object(catalog.libraryPreviews)) continue;
7917
+ for (const [key, sample] of Object.entries(catalog.libraryPreviews)) {
7918
+ if (!object(sample) || Object.keys(sample).some((field) => field !== "props"))
7919
+ continue;
7920
+ if (!Object.hasOwn(sample, "props")) {
7921
+ result[key] = {};
7922
+ continue;
7927
7923
  }
7928
- ))
7929
- ] })) });
7930
- const libraryDocumentGroup = (documents) => {
7931
- const nodes = libraryDocumentTree(documents);
7932
- return documentView.value === "columns" ? /* @__PURE__ */ jsxs("div", { class: "kui-editor__document-columns", children: [
7933
- /* @__PURE__ */ jsxs("div", { class: "kui-editor__document-location", children: [
7934
- documentPath.value.length ? /* @__PURE__ */ jsx(
7935
- Button,
7936
- {
7937
- icon: /* @__PURE__ */ jsx(LucideIcon, { icon: ArrowLeft, name: "back" }),
7938
- ariaLabel: "Parent folder",
7939
- action: DOCUMENT_BACK_ACTION,
7940
- size: "compact"
7941
- }
7942
- ) : void 0,
7943
- /* @__PURE__ */ jsx(Text, { variant: "span", size: "compact", wrap: "truncate", children: documentPath.value.length ? `Project / ${documentPath.value.at(-1).slice("folder:".length)}` : "Project" })
7944
- ] }),
7945
- /* @__PURE__ */ jsx(
7946
- ColumnExplorer,
7947
- {
7948
- id: "editor-library-documents-columns",
7949
- label: LIBRARY_DOCUMENTS,
7950
- nodes,
7951
- path: documentPath.value,
7952
- action: DOCUMENT_ROW_ACTION,
7953
- layout: "paged",
7954
- className: "kui-editor__document-explorer"
7924
+ if (!object(sample.props) || !json(sample.props)) continue;
7925
+ const text = JSON.stringify(sample.props);
7926
+ result[key] = {
7927
+ sampleProps: () => JSON.parse(text)
7928
+ };
7929
+ }
7930
+ }
7931
+ return result;
7932
+ }
7933
+ var record = (value) => Object.prototype.toString.call(value) === "[object Object]";
7934
+ function createLibraryThumbnails(catalog, previews, documentOf) {
7935
+ const cache = /* @__PURE__ */ new Map();
7936
+ const htmlOf = (key) => {
7937
+ if (!catalog.propsByKey.has(key)) return void 0;
7938
+ if (!cache.has(key)) {
7939
+ const preview = previews[key];
7940
+ const component = catalog.components[key];
7941
+ const render = (props) => {
7942
+ let sampled = props;
7943
+ try {
7944
+ const values = preview?.sampleProps?.();
7945
+ if (record(values)) sampled = { ...props, ...values };
7946
+ } catch {
7955
7947
  }
7956
- )
7957
- ] }) : /* @__PURE__ */ jsx(
7958
- TreeList,
7959
- {
7960
- id: "editor-library-documents-tree",
7961
- label: LIBRARY_DOCUMENTS,
7962
- nodes,
7963
- expanded: new Set(
7964
- documents.flatMap((path) => {
7965
- const parts = path.split("/").filter(Boolean);
7966
- return parts.slice(0, -1).map(
7967
- (_, index) => documentFolderId(`${parts.slice(0, index + 1).join("/")}/`)
7968
- );
7969
- }).filter((id) => !collapsedDocumentFolders.value.has(id))
7970
- ),
7971
- selected: documentPath.value.at(-1),
7972
- action: DOCUMENT_ROW_ACTION,
7973
- toggleAction: DOCUMENT_TOGGLE_ACTION,
7974
- density: "compact"
7975
- }
7976
- );
7977
- };
7978
- const libraryPopover = () => {
7979
- const componentsMode = libraryMode.value === "components";
7980
- const groups = componentsMode ? paletteMatches() : [];
7981
- const documents = componentsMode ? [] : libraryDocuments(libraryFiles.value, paletteFilter.value);
7982
- return /* @__PURE__ */ jsxs(
7983
- PinnablePopoverSurface,
7984
- {
7985
- id: LIBRARY_ID,
7986
- label: "Library",
7987
- size: "small",
7988
- height: px(560),
7989
- bodyLayout: "fill-last",
7990
- resizeFromBottom: true,
7991
- headerActions: componentsMode ? (
7992
- // KF-JC7WTW: a list of names, or a grid of thumbnails.
7993
- /* @__PURE__ */ jsx(
7994
- SegmentedControl,
7995
- {
7996
- id: "editor-palette-view",
7997
- label: "Component View",
7998
- value: paletteView.value,
7999
- action: PALETTE_VIEW_ACTION,
8000
- choices: [
8001
- {
8002
- value: "list",
8003
- label: "List",
8004
- title: "List",
8005
- content: /* @__PURE__ */ jsx(LucideIcon, { icon: List$1, name: "list" })
8006
- },
8007
- {
8008
- value: "grid",
8009
- label: "Grid",
8010
- title: "Grid",
8011
- content: /* @__PURE__ */ jsx(LucideIcon, { icon: LayoutGrid, name: "layout-grid" })
8012
- }
8013
- ]
8014
- }
8015
- )
8016
- ) : /* @__PURE__ */ jsx(
8017
- SegmentedControl,
8018
- {
8019
- id: "editor-document-view",
8020
- label: "Document View",
8021
- value: documentView.value,
8022
- action: DOCUMENT_VIEW_ACTION,
8023
- choices: [
8024
- {
8025
- value: "columns",
8026
- label: "Columns",
8027
- title: "Columns",
8028
- content: /* @__PURE__ */ jsx(LucideIcon, { icon: Columns3, name: "columns" })
8029
- },
8030
- {
8031
- value: "tree",
8032
- label: "Tree",
8033
- title: "Tree",
8034
- content: /* @__PURE__ */ jsx(LucideIcon, { icon: ListTree, name: "list-tree" })
8035
- }
8036
- ]
7948
+ try {
7949
+ const result = preview?.render?.({
7950
+ key,
7951
+ name: catalog.componentNames.get(key) ?? key,
7952
+ props: sampled
7953
+ });
7954
+ if (isSafeHtml(result) && result.toString().trim()) return result;
7955
+ } catch {
7956
+ }
7957
+ if (component) {
7958
+ try {
7959
+ const result = component(sampled);
7960
+ if (isSafeHtml(result)) return result;
7961
+ } catch {
8037
7962
  }
8038
- ),
8039
- rootAttributes: { [HOOK.library]: "" },
8040
- children: [
8041
- /* @__PURE__ */ jsxs(List, { controlInsets: "trbl", gap: true, children: [
8042
- /* @__PURE__ */ jsx(
8043
- SegmentedControl,
8044
- {
8045
- id: "editor-library-mode",
8046
- label: "Library Content",
8047
- layout: "equal",
8048
- value: libraryMode.value,
8049
- action: LIBRARY_MODE_ACTION,
8050
- choices: [
8051
- { value: "components", label: "Components" },
8052
- { value: "documents", label: "Documents" }
8053
- ]
8054
- }
8055
- ),
8056
- /* @__PURE__ */ jsx(
8057
- SearchField,
8058
- {
8059
- id: "editor-palette-filter",
8060
- label: componentsMode ? "Filter Components" : "Filter Documents",
8061
- placeholder: "Filter",
8062
- query: paletteFilter.value,
8063
- revision: paletteFilterRevision.value,
8064
- clearAction: PALETTE_CLEAR_ACTION,
8065
- clearLabel: "Clear Filter",
8066
- editorAttributes: { [HOOK.paletteFilter]: "" }
8067
- }
8068
- ),
8069
- libraryError.value ? /* @__PURE__ */ jsx(
8070
- StateBanner,
8071
- {
8072
- tone: "danger",
8073
- title: "That document cannot be inserted",
8074
- detail: libraryError.value,
8075
- rootAttributes: { "data-editor-library-error": "" }
8076
- }
8077
- ) : void 0
8078
- ] }),
8079
- /* @__PURE__ */ jsx(
8080
- List,
8081
- {
8082
- scrollable: true,
8083
- flex: true,
8084
- rootAttributes: { "data-editor-library-results": "" },
8085
- children: componentsMode ? groups.length ? palette(groups) : /* @__PURE__ */ jsx(
8086
- EmptyState,
8087
- {
8088
- title: "No matching components",
8089
- detail: "No component name or category holds that text."
8090
- }
8091
- ) : documents.length ? libraryDocumentGroup(documents) : /* @__PURE__ */ jsx(
8092
- EmptyState,
8093
- {
8094
- title: "No matching documents",
8095
- detail: "No project document name or folder holds that text."
8096
- }
8097
- )
7963
+ if (sampled !== props) {
7964
+ try {
7965
+ const result = component(props);
7966
+ if (isSafeHtml(result)) return result;
7967
+ } catch {
8098
7968
  }
8099
- )
8100
- ]
8101
- }
8102
- );
7969
+ }
7970
+ }
7971
+ return raw("");
7972
+ };
7973
+ const renderer = canvasRenderer({
7974
+ ...catalog,
7975
+ components: { ...catalog.components, [key]: render }
7976
+ });
7977
+ cache.set(
7978
+ key,
7979
+ renderer(documentOf(key), [], void 0, void 0, true).toString()
7980
+ );
7981
+ }
7982
+ return cache.get(key);
8103
7983
  };
8104
- return libraryPopover;
7984
+ const fitOf = (key) => previews[key]?.fit === "fill" ? "fill" : "contain";
7985
+ return { htmlOf, fitOf };
8105
7986
  }
8106
7987
 
8107
7988
  // src/editor/model/content.ts
8108
7989
  function contentOf(node, prop) {
8109
- const children = node.zones?.[prop] ?? [];
8110
- if (children.length) {
8111
- const [only] = children;
8112
- const text = children.length === 1 && only && "type" in only && only.type === "#text" && typeof only.value === "string" ? only.value : void 0;
7990
+ const children2 = node.zones?.[prop] ?? [];
7991
+ if (children2.length) {
7992
+ const [only] = children2;
7993
+ const text = children2.length === 1 && only && "type" in only && only.type === "#text" && typeof only.value === "string" ? only.value : void 0;
8113
7994
  return {
8114
7995
  kind: "nodes",
8115
- count: children.length,
7996
+ count: children2.length,
8116
7997
  ...text !== void 0 ? { text } : {}
8117
7998
  };
8118
7999
  }
@@ -8186,24 +8067,24 @@ function newDataAttributeName(attributes, protectedNames = /* @__PURE__ */ new S
8186
8067
  for (let count = 2; taken(name); count += 1) name = `data-name-${count}`;
8187
8068
  return name;
8188
8069
  }
8189
- function editDataAttributes(attributes, edit2) {
8070
+ function editDataAttributes(attributes, edit) {
8190
8071
  let next;
8191
- switch (edit2.kind) {
8072
+ switch (edit.kind) {
8192
8073
  case "name":
8193
8074
  next = attributes.map(
8194
- (item, at) => at === edit2.index ? [edit2.name, item[1]] : item
8075
+ (item, at) => at === edit.index ? [edit.name, item[1]] : item
8195
8076
  );
8196
8077
  break;
8197
8078
  case "value":
8198
8079
  next = attributes.map(
8199
- (item, at) => at === edit2.index ? [item[0], edit2.value] : item
8080
+ (item, at) => at === edit.index ? [item[0], edit.value] : item
8200
8081
  );
8201
8082
  break;
8202
8083
  case "add":
8203
- next = [...attributes, [edit2.name, ""]];
8084
+ next = [...attributes, [edit.name, ""]];
8204
8085
  break;
8205
8086
  case "remove":
8206
- next = attributes.filter((_item, at) => at !== edit2.index);
8087
+ next = attributes.filter((_item, at) => at !== edit.index);
8207
8088
  break;
8208
8089
  }
8209
8090
  return next.length ? Object.fromEntries(next) : void 0;
@@ -8211,11 +8092,12 @@ function editDataAttributes(attributes, edit2) {
8211
8092
  function moduleFileName(document2) {
8212
8093
  return documentFileName(document2).replace(/\.kui\.json$/, ".view.ts");
8213
8094
  }
8214
- function exportModule(document2, catalog, kind, resolveView) {
8095
+ function exportModule(document2, catalog, kind, resolveView, source) {
8215
8096
  const generated = generateView(document2, catalog, {
8216
8097
  source: documentFileName(document2),
8217
8098
  declarationsOnly: kind === "declarations",
8218
- resolveView
8099
+ resolveView,
8100
+ typeSource: source
8219
8101
  });
8220
8102
  return {
8221
8103
  fileName: moduleFileName(document2),
@@ -8302,29 +8184,171 @@ function formatValue(value) {
8302
8184
  }
8303
8185
  return JSON.stringify(value);
8304
8186
  }
8305
- var OTHER = "Other";
8306
- var ADVANCED = "Advanced";
8187
+ var PROP_FAMILIES = [
8188
+ "Content",
8189
+ "Appearance",
8190
+ "Behavior",
8191
+ "Layout",
8192
+ "Accessibility",
8193
+ "Integration"
8194
+ ];
8195
+ var LEGACY_GROUPS = {
8196
+ State: { family: "Behavior", subgroup: "State" },
8197
+ Form: { family: "Behavior", subgroup: "Form" },
8198
+ Input: { family: "Behavior", subgroup: "Input" },
8199
+ Validation: { family: "Behavior", subgroup: "Validation" },
8200
+ Mode: { family: "Behavior", subgroup: "Mode" },
8201
+ Surface: { family: "Appearance", subgroup: "Surface" },
8202
+ Chrome: { family: "Appearance", subgroup: "Chrome" },
8203
+ Wrapping: { family: "Layout", subgroup: "Wrapping" },
8204
+ Responsive: { family: "Layout", subgroup: "Responsive" },
8205
+ Icon: { family: "Content", subgroup: "Icon" },
8206
+ Semantics: { family: "Accessibility", subgroup: "Semantics" }
8207
+ };
8208
+ var isFamily = (name) => PROP_FAMILIES.includes(name);
8209
+ var CONTENT_WORDS = /* @__PURE__ */ new Set([
8210
+ "children",
8211
+ "label",
8212
+ "text",
8213
+ "title",
8214
+ "description",
8215
+ "detail",
8216
+ "placeholder",
8217
+ "hint",
8218
+ "icon",
8219
+ "badge",
8220
+ "items",
8221
+ "choices",
8222
+ "options",
8223
+ "content"
8224
+ ]);
8225
+ var APPEARANCE_WORDS = /* @__PURE__ */ new Set([
8226
+ "tone",
8227
+ "emphasis",
8228
+ "size",
8229
+ "shape",
8230
+ "variant",
8231
+ "appearance",
8232
+ "density",
8233
+ "color",
8234
+ "background",
8235
+ "presentation",
8236
+ "divider",
8237
+ "dividers",
8238
+ "outlined",
8239
+ "surface",
8240
+ "frame",
8241
+ "font",
8242
+ "elevation",
8243
+ "caret",
8244
+ "inline"
8245
+ ]);
8246
+ var LAYOUT_WORDS = /* @__PURE__ */ new Set([
8247
+ "placement",
8248
+ "position",
8249
+ "side",
8250
+ "orientation",
8251
+ "layout",
8252
+ "gap",
8253
+ "align",
8254
+ "width",
8255
+ "height",
8256
+ "wrap",
8257
+ "responsive",
8258
+ "collapsed",
8259
+ "resizable",
8260
+ "scrollable",
8261
+ "sticky",
8262
+ "insets",
8263
+ "columns",
8264
+ // A breakpoint (`iconOnlyAt`, `hideBelow`).
8265
+ "at",
8266
+ "below",
8267
+ "above"
8268
+ ]);
8269
+ var BEHAVIOR_WORDS = /* @__PURE__ */ new Set([
8270
+ "active",
8271
+ "open",
8272
+ "expanded",
8273
+ "selected",
8274
+ "checked",
8275
+ "pressed",
8276
+ "disabled",
8277
+ "busy",
8278
+ "loading"
8279
+ ]);
8280
+ var ACCESSIBILITY_WORDS = /* @__PURE__ */ new Set([
8281
+ "role",
8282
+ "heading",
8283
+ "tab",
8284
+ "live",
8285
+ "element"
8286
+ ]);
8287
+ function inferredFamily(prop) {
8288
+ if (prop.control === "classes" || prop.name === "id") return "Integration";
8289
+ if (prop.type.kind === "content" || prop.slot) return "Content";
8290
+ const words2 = prop.name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(" ");
8291
+ if (words2[0] === "aria") return "Accessibility";
8292
+ if (words2.length > 1 && words2.at(-1) === "label") return "Accessibility";
8293
+ for (const word of [words2.at(-1), words2[0]]) {
8294
+ if (BEHAVIOR_WORDS.has(word)) return "Behavior";
8295
+ if (CONTENT_WORDS.has(word)) return "Content";
8296
+ if (APPEARANCE_WORDS.has(word)) return "Appearance";
8297
+ if (LAYOUT_WORDS.has(word)) return "Layout";
8298
+ if (ACCESSIBILITY_WORDS.has(word)) return "Accessibility";
8299
+ }
8300
+ return "Behavior";
8301
+ }
8302
+ function propPlace(prop, component) {
8303
+ if (prop.control === "classes") return { group: "Integration" };
8304
+ const declared = prop.group && (component.groups ?? []).includes(prop.group) ? prop.group : void 0;
8305
+ if (declared && isFamily(declared))
8306
+ return prop.subgroup ? { group: declared, subgroup: prop.subgroup } : { group: declared };
8307
+ if (declared && LEGACY_GROUPS[declared]) {
8308
+ const { family, subgroup } = LEGACY_GROUPS[declared];
8309
+ return { group: family, subgroup: prop.subgroup ?? subgroup };
8310
+ }
8311
+ if (declared) return { group: declared };
8312
+ return { group: inferredFamily(prop) };
8313
+ }
8314
+ var byOrder = (a, b) => (a.order ?? 999) - (b.order ?? 999) || a.name.localeCompare(b.name);
8307
8315
  function groupedProps(component) {
8308
8316
  const visible = component.props.filter(
8309
8317
  (prop) => prop.control !== "hidden" && !prop.zone && prop.type.kind !== "never"
8310
8318
  );
8311
- const order = [...component.groups ?? []];
8312
8319
  const byGroup = /* @__PURE__ */ new Map();
8313
8320
  for (const prop of visible) {
8314
- const group = prop.control === "classes" ? ADVANCED : prop.group && order.includes(prop.group) ? prop.group : OTHER;
8315
- byGroup.set(group, [...byGroup.get(group) ?? [], prop]);
8321
+ const { group, subgroup } = propPlace(prop, component);
8322
+ const subgroups = byGroup.get(group) ?? /* @__PURE__ */ new Map();
8323
+ subgroups.set(subgroup, [...subgroups.get(subgroup) ?? [], prop]);
8324
+ byGroup.set(group, subgroups);
8316
8325
  }
8317
8326
  const titles = [
8318
- ...order.filter((title) => byGroup.has(title)),
8319
- ...byGroup.has(OTHER) ? [OTHER] : [],
8320
- ...byGroup.has(ADVANCED) ? [ADVANCED] : []
8321
- ];
8322
- return titles.map((title) => ({
8323
- title,
8324
- props: byGroup.get(title).slice().sort(
8325
- (a, b) => (a.order ?? 999) - (b.order ?? 999) || a.name.localeCompare(b.name)
8327
+ ...PROP_FAMILIES.filter((title) => byGroup.has(title)),
8328
+ ...(component.groups ?? []).filter(
8329
+ (title) => !isFamily(title) && !LEGACY_GROUPS[title] && byGroup.has(title)
8326
8330
  )
8327
- }));
8331
+ ];
8332
+ const declaredRank = (title) => {
8333
+ const index = (component.groups ?? []).indexOf(title);
8334
+ return index < 0 ? 999 : index;
8335
+ };
8336
+ return titles.map((title) => {
8337
+ const subgroups = [...byGroup.get(title)].map(([subtitle, props]) => ({
8338
+ title: subtitle,
8339
+ props: props.slice().sort(byOrder)
8340
+ })).sort(
8341
+ (a, b) => Number(a.title !== void 0) - Number(b.title !== void 0) || (a.props[0].order ?? 999) - (b.props[0].order ?? 999) || // Map keys are unique, so a tie here is two titled subgroups.
8342
+ declaredRank(a.title) - declaredRank(b.title) || a.title.localeCompare(b.title)
8343
+ ).map(
8344
+ (subgroup) => subgroup.title === void 0 ? { props: subgroup.props } : subgroup
8345
+ );
8346
+ return {
8347
+ title,
8348
+ props: subgroups.flatMap((subgroup) => subgroup.props),
8349
+ subgroups
8350
+ };
8351
+ });
8328
8352
  }
8329
8353
  function inspectorSections(node, component) {
8330
8354
  const props = node?.props ?? {};
@@ -8346,6 +8370,29 @@ function inspectorSections(node, component) {
8346
8370
  })
8347
8371
  }));
8348
8372
  }
8373
+ function propertiesGroups(component) {
8374
+ const groups = groupedProps(component);
8375
+ return component.props.some((prop) => prop.name === "rootAttributes") && !groups.some((group) => group.title === "Integration") ? [...groups, { title: "Integration", props: [], subgroups: [] }] : groups;
8376
+ }
8377
+ var FOCUSED_FIELD_LIMIT = 10;
8378
+ var splitsIntoPages = (group) => group.props.length > FOCUSED_FIELD_LIMIT && group.subgroups.some((subgroup) => subgroup.title !== void 0);
8379
+ function groupSummary(props, values, problems, label) {
8380
+ const set = props.filter((prop) => prop.name in values);
8381
+ const named = set.map((prop) => {
8382
+ const value = values[prop.name];
8383
+ const bound2 = value !== null && typeof value === "object" && ("$param" in value || "$bind" in value);
8384
+ return bound2 ? `${label(prop)} (bound)` : label(prop);
8385
+ });
8386
+ const description = !named.length ? "Defaults" : named.length > 3 ? `${named.slice(0, 3).join(", ")} + ${named.length - 3} more` : named.join(", ");
8387
+ return {
8388
+ description,
8389
+ problems: props.filter((prop) => problems.has(prop.name)).length
8390
+ };
8391
+ }
8392
+ function matchesQuery(prop, label, place, query) {
8393
+ const haystack = [label, prop.name, ...place].join(" ").toLowerCase();
8394
+ return query.toLowerCase().split(/\s+/).filter(Boolean).every((word) => haystack.includes(word));
8395
+ }
8349
8396
 
8350
8397
  // src/editor/model/play-device.ts
8351
8398
  var NONE = { top: 0, right: 0, bottom: 0, left: 0 };
@@ -8717,17 +8764,13 @@ function nodeContextMenu(ctx, { embedFirstLegal, extractBlocked }) {
8717
8764
  }
8718
8765
  );
8719
8766
  }
8720
- function dataAttributesSection(ctx, node, component) {
8721
- const prop = component.props.find(
8722
- (item) => item.name === DATA_ATTRIBUTES_PROP
8723
- );
8724
- if (!prop) return void 0;
8767
+ function dataAttributesSection(ctx, node) {
8725
8768
  const value = node.props?.[DATA_ATTRIBUTES_PROP];
8726
8769
  const attributes = dataAttributes(value);
8727
8770
  const problems = new Map(
8728
- ctx.currentProblems.value.filter(({ nodeId }) => nodeId === node.id).map(({ diagnostic }) => [
8729
- diagnostic.path.split(`.props.${DATA_ATTRIBUTES_PROP}.`)[1],
8730
- diagnostic.message
8771
+ ctx.currentProblems.value.filter(({ nodeId }) => nodeId === node.id).map(({ diagnostic: diagnostic2 }) => [
8772
+ diagnostic2.path.split(`.props.${DATA_ATTRIBUTES_PROP}.`)[1],
8773
+ diagnostic2.message
8731
8774
  ])
8732
8775
  );
8733
8776
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -8800,6 +8843,63 @@ function dataAttributesSection(ctx, node, component) {
8800
8843
  ] })
8801
8844
  ] });
8802
8845
  }
8846
+ function bindingSummary(value) {
8847
+ if (value === null || typeof value !== "object") return "Not bound";
8848
+ const { $param, $bind } = value;
8849
+ if (typeof $param === "string") return `Param ${$param}`;
8850
+ return typeof $bind === "string" ? `Item field ${$bind}` : "Not bound";
8851
+ }
8852
+ function bindPropPage(ctx, node, prop, promotable) {
8853
+ const { name } = prop;
8854
+ const label = fieldLabel(prop);
8855
+ const options = bindingOptions(
8856
+ ctx.doc.value,
8857
+ ctx.catalog.viewCatalog,
8858
+ node.id,
8859
+ name,
8860
+ [],
8861
+ void 0,
8862
+ ctx.resolveView
8863
+ );
8864
+ const current = node.props?.[name];
8865
+ const bound2 = current !== null && typeof current === "object" && ("$param" in current || "$bind" in current) ? JSON.stringify(current) : "";
8866
+ const choices = [
8867
+ { value: "", label: "Not bound" },
8868
+ ...options.map((option) => ({
8869
+ value: JSON.stringify(option.value),
8870
+ label: option.label
8871
+ }))
8872
+ ];
8873
+ return /* @__PURE__ */ jsxs(List, { rootAttributes: { "data-editor-bind-page": name }, children: [
8874
+ options.length || bound2 ? /* @__PURE__ */ jsx(List, { controlInsets: "trbl", gap: true, children: /* @__PURE__ */ jsx(
8875
+ Select,
8876
+ {
8877
+ name: "bind-source",
8878
+ label: "Source",
8879
+ value: choices.some((choice) => choice.value === bound2) ? bound2 : "",
8880
+ choices,
8881
+ rootAttributes: {
8882
+ [HOOK.bind]: "source",
8883
+ "data-editor-bind-prop": name
8884
+ }
8885
+ }
8886
+ ) }) : /* @__PURE__ */ jsx(ListInsetText, { children: /* @__PURE__ */ jsxs(Text, { tone: "quiet", children: [
8887
+ "No param or item field in scope fits ",
8888
+ label.toLowerCase(),
8889
+ "."
8890
+ ] }) }),
8891
+ promotable ? /* @__PURE__ */ jsx(List, { controlInsets: "trbl", children: /* @__PURE__ */ jsx(Row, { children: /* @__PURE__ */ jsx(
8892
+ Button,
8893
+ {
8894
+ emphasis: "secondary",
8895
+ size: "compact",
8896
+ action: PROMOTE_PROP_ACTION,
8897
+ rootAttributes: { "data-editor-promote-prop": name },
8898
+ children: "Promote to a param"
8899
+ }
8900
+ ) }) }) : void 0
8901
+ ] });
8902
+ }
8803
8903
  function inspectorBindSection(ctx, bindProp, node, component) {
8804
8904
  const bindable = component.props.filter(
8805
8905
  (prop2) => prop2.control !== "hidden" && !prop2.zone
@@ -8857,6 +8957,234 @@ function inspectorBindSection(ctx, bindProp, node, component) {
8857
8957
  ] })
8858
8958
  ] });
8859
8959
  }
8960
+ var problemCount = (count) => count === 0 ? void 0 : `${count} ${count === 1 ? "problem" : "problems"}`;
8961
+ function inTask(props, task) {
8962
+ if (task === void 0) return props;
8963
+ const prefix = `${task.toLowerCase()} `;
8964
+ return props.map((prop) => {
8965
+ const label = fieldLabel(prop);
8966
+ if (!label.toLowerCase().startsWith(prefix)) return prop;
8967
+ const rest = label.slice(prefix.length);
8968
+ return { ...prop, label: rest[0].toUpperCase() + rest.slice(1) };
8969
+ });
8970
+ }
8971
+ function groupRow(state, path, props) {
8972
+ const title = path.at(-1);
8973
+ const { description, problems } = groupSummary(
8974
+ state.extra?.group === path.join("/") ? [...props, ...state.extra.props] : props,
8975
+ state.values,
8976
+ state.problems,
8977
+ fieldLabel
8978
+ );
8979
+ const status = problemCount(problems);
8980
+ return /* @__PURE__ */ jsx(
8981
+ ListItem,
8982
+ {
8983
+ label: title,
8984
+ description,
8985
+ status,
8986
+ action: INSPECTOR_GROUP_ACTION,
8987
+ accessibleLabel: `${title}: ${description}${status ? `, ${status}` : ""}`,
8988
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
8989
+ rootAttributes: {
8990
+ [HOOK.group]: path.join("/"),
8991
+ // The props the page holds, for finding a field's page.
8992
+ "data-editor-group-props": props.map((prop) => prop.name).join(" ")
8993
+ }
8994
+ }
8995
+ );
8996
+ }
8997
+ function bindSection(state, path, props) {
8998
+ if (!props.length) return [];
8999
+ return [
9000
+ /* @__PURE__ */ jsx(ListHeader, { label: "Bindings", size: "xs" }),
9001
+ /* @__PURE__ */ jsx(List, { rootAttributes: { "data-editor-bind-rows": path.join("/") }, children: props.map((prop) => {
9002
+ const label = fieldLabel(prop);
9003
+ const binding = state.bindingOf(prop);
9004
+ return /* @__PURE__ */ jsx(
9005
+ ListItem,
9006
+ {
9007
+ label,
9008
+ description: binding,
9009
+ action: INSPECTOR_GROUP_ACTION,
9010
+ accessibleLabel: `Bind or promote ${label.toLowerCase()}: ${binding}`,
9011
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
9012
+ rootAttributes: {
9013
+ [HOOK.group]: [...path, `${BIND_STEP}${prop.name}`].join("/"),
9014
+ "data-editor-bind-row": prop.name
9015
+ }
9016
+ }
9017
+ );
9018
+ }) })
9019
+ ];
9020
+ }
9021
+ function propertiesDirectory(state) {
9022
+ const every = state.groups.flatMap((group) => group.props);
9023
+ return /* @__PURE__ */ jsxs(List, { rootAttributes: { "data-key": "editor-properties-directory" }, children: [
9024
+ state.groups.map((group) => groupRow(state, [group.title], group.props)),
9025
+ /* @__PURE__ */ jsx(
9026
+ ListItem,
9027
+ {
9028
+ label: ALL_PROPERTIES,
9029
+ description: `Search all ${every.length} by name`,
9030
+ action: INSPECTOR_GROUP_ACTION,
9031
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
9032
+ rootAttributes: { [HOOK.group]: ALL_PROPERTIES }
9033
+ }
9034
+ )
9035
+ ] });
9036
+ }
9037
+ var page = (path, content, title = path.at(-1)) => ({
9038
+ key: `properties-${path.map(
9039
+ (step) => step.replace(/[^A-Za-z0-9]+/g, " ").trim().replace(/ /g, "-")
9040
+ ).join("-")}`,
9041
+ toolbar: { title },
9042
+ pane: INSPECTOR_PANE,
9043
+ content
9044
+ });
9045
+ function groupPage(state, group) {
9046
+ const split = splitsIntoPages(group);
9047
+ return /* @__PURE__ */ jsxs(List, { rootAttributes: { "data-editor-properties-page": group.title }, children: [
9048
+ group.subgroups.map(
9049
+ (subgroup) => subgroup.title === void 0 ? state.fieldsOf(subgroup.props, `${state.title} ${group.title}`) : split ? void 0 : [
9050
+ /* @__PURE__ */ jsx(
9051
+ ListHeader,
9052
+ {
9053
+ label: subgroup.title,
9054
+ size: "xs",
9055
+ rootAttributes: {
9056
+ "data-editor-prop-subgroup": `${group.title}/${subgroup.title}`
9057
+ }
9058
+ }
9059
+ ),
9060
+ ...state.fieldsOf(
9061
+ inTask(subgroup.props, subgroup.title),
9062
+ `${state.title} ${group.title} ${subgroup.title}`
9063
+ )
9064
+ ]
9065
+ ),
9066
+ split ? /* @__PURE__ */ jsx(List, { children: group.subgroups.flatMap(
9067
+ (subgroup) => subgroup.title === void 0 ? [] : [
9068
+ groupRow(
9069
+ state,
9070
+ [group.title, subgroup.title],
9071
+ subgroup.props
9072
+ )
9073
+ ]
9074
+ ) }) : void 0,
9075
+ state.extra?.group === group.title ? state.extra.content : void 0,
9076
+ bindSection(
9077
+ state,
9078
+ [group.title],
9079
+ split ? group.subgroups.flatMap(
9080
+ (subgroup) => subgroup.title === void 0 ? subgroup.props : []
9081
+ ) : group.props
9082
+ )
9083
+ ] });
9084
+ }
9085
+ function allPropertiesPage(state, query, revision) {
9086
+ const matching = state.groups.flatMap((group) => {
9087
+ const subgroups = group.subgroups.flatMap((subgroup) => {
9088
+ const props = subgroup.props.filter(
9089
+ (prop) => matchesQuery(
9090
+ prop,
9091
+ fieldLabel(prop),
9092
+ [group.title, subgroup.title ?? ""],
9093
+ query
9094
+ )
9095
+ );
9096
+ return props.length ? [{ title: subgroup.title, props }] : [];
9097
+ });
9098
+ return subgroups.length ? [{ title: group.title, subgroups }] : [];
9099
+ });
9100
+ return /* @__PURE__ */ jsxs(List, { rootAttributes: { "data-editor-properties-page": ALL_PROPERTIES }, children: [
9101
+ /* @__PURE__ */ jsx(List, { controlInsets: "trbl", children: /* @__PURE__ */ jsx(
9102
+ SearchField,
9103
+ {
9104
+ id: "editor-properties-search",
9105
+ label: "Search Properties",
9106
+ placeholder: "Search properties",
9107
+ query,
9108
+ revision,
9109
+ clearAction: PROPERTIES_CLEAR_ACTION,
9110
+ clearLabel: "Clear Search",
9111
+ editorAttributes: {
9112
+ [HOOK.propertiesSearch]: "",
9113
+ "data-nav-focus": ""
9114
+ }
9115
+ }
9116
+ ) }),
9117
+ matching.length ? matching.map((group) => [
9118
+ // Each field shows under the group and task it belongs to.
9119
+ ...group.subgroups.flatMap((subgroup) => [
9120
+ /* @__PURE__ */ jsx(
9121
+ ListHeader,
9122
+ {
9123
+ label: subgroup.title === void 0 ? group.title : `${group.title} \xB7 ${subgroup.title}`,
9124
+ size: "xs"
9125
+ }
9126
+ ),
9127
+ ...state.fieldsOf(
9128
+ inTask(subgroup.props, subgroup.title),
9129
+ `${state.title} ${group.title} ${subgroup.title ?? ""}`.trim()
9130
+ )
9131
+ ])
9132
+ ]) : /* @__PURE__ */ jsx(ListInsetText, { children: /* @__PURE__ */ jsxs(Text, { tone: "quiet", children: [
9133
+ "No properties match \u201C",
9134
+ query,
9135
+ "\u201D."
9136
+ ] }) })
9137
+ ] });
9138
+ }
9139
+ function propertiesPages(state, path, query, revision) {
9140
+ if (!path.length) return [];
9141
+ const pages = [];
9142
+ let rest = path.slice(1);
9143
+ if (path[0] === ALL_PROPERTIES)
9144
+ pages.push(
9145
+ page([ALL_PROPERTIES], allPropertiesPage(state, query, revision))
9146
+ );
9147
+ else {
9148
+ const group = state.groups.find((item) => item.title === path[0]);
9149
+ if (!group) return [];
9150
+ pages.push(page([group.title], groupPage(state, group)));
9151
+ const subgroup = rest[0] !== void 0 && splitsIntoPages(group) ? group.subgroups.find((item) => item.title === rest[0]) : void 0;
9152
+ if (subgroup) {
9153
+ const at = [group.title, subgroup.title];
9154
+ pages.push(
9155
+ page(
9156
+ at,
9157
+ /* @__PURE__ */ jsxs(
9158
+ List,
9159
+ {
9160
+ rootAttributes: { "data-editor-properties-page": at.join("/") },
9161
+ children: [
9162
+ state.fieldsOf(
9163
+ inTask(subgroup.props, subgroup.title),
9164
+ `${state.title} ${group.title} ${subgroup.title}`
9165
+ ),
9166
+ bindSection(state, at, subgroup.props)
9167
+ ]
9168
+ }
9169
+ )
9170
+ )
9171
+ );
9172
+ rest = rest.slice(1);
9173
+ }
9174
+ }
9175
+ const step = rest[0];
9176
+ const name = step?.startsWith(BIND_STEP) ? step.slice(BIND_STEP.length) : void 0;
9177
+ const prop = state.groups.flatMap((group) => group.props).find((item) => item.name === name);
9178
+ if (prop)
9179
+ pages.push(
9180
+ page(
9181
+ path.slice(0, path.length - rest.length + 1),
9182
+ state.bindPage(prop),
9183
+ `Bind ${fieldLabel(prop)}`
9184
+ )
9185
+ );
9186
+ return pages;
9187
+ }
8860
9188
  function createNodeInspectorViews(ctx, state) {
8861
9189
  const {
8862
9190
  autosave,
@@ -8866,6 +9194,9 @@ function createNodeInspectorViews(ctx, state) {
8866
9194
  doc,
8867
9195
  fieldErrors,
8868
9196
  inspectorArea,
9197
+ inspectorGroup,
9198
+ propertiesQuery,
9199
+ propertiesQueryRevision,
8869
9200
  propsEntryOf,
8870
9201
  resolveView
8871
9202
  } = ctx;
@@ -8890,7 +9221,7 @@ function createNodeInspectorViews(ctx, state) {
8890
9221
  bindProp,
8891
9222
  addZone,
8892
9223
  addComponent,
8893
- promoteProp
9224
+ fieldProblems
8894
9225
  } = state;
8895
9226
  const viewEditor = (node, title) => {
8896
9227
  const src = node.src ?? "";
@@ -8913,7 +9244,7 @@ function createNodeInspectorViews(ctx, state) {
8913
9244
  row: /* @__PURE__ */ jsx(
8914
9245
  TextField,
8915
9246
  {
8916
- label: `${propLabel(prop.name)} param`,
9247
+ label: `${fieldLabel(prop)} param`,
8917
9248
  value: param,
8918
9249
  hint: "Renaming the param updates every prop that uses it.",
8919
9250
  error: fieldErrors.value[`#param:${param}`],
@@ -8926,7 +9257,7 @@ function createNodeInspectorViews(ctx, state) {
8926
9257
  row: /* @__PURE__ */ jsx(
8927
9258
  ValueTableRow,
8928
9259
  {
8929
- label: propLabel(prop.name),
9260
+ label: fieldLabel(prop),
8930
9261
  value: inspectorSections(node, {
8931
9262
  ...entry,
8932
9263
  props: [prop],
@@ -8943,13 +9274,13 @@ function createNodeInspectorViews(ctx, state) {
8943
9274
  controlInsets: "trbl",
8944
9275
  gap: true,
8945
9276
  rootAttributes: { "data-key": "editor-node-problems" },
8946
- children: own.map(({ diagnostic }) => /* @__PURE__ */ jsx(
9277
+ children: own.map(({ diagnostic: diagnostic2 }) => /* @__PURE__ */ jsx(
8947
9278
  StateBanner,
8948
9279
  {
8949
9280
  tone: "warning",
8950
- title: diagnostic.message,
8951
- detail: diagnostic.code,
8952
- rootAttributes: { "data-editor-node-problem": diagnostic.code }
9281
+ title: diagnostic2.message,
9282
+ detail: diagnostic2.code,
9283
+ rootAttributes: { "data-editor-node-problem": diagnostic2.code }
8953
9284
  }
8954
9285
  ))
8955
9286
  }
@@ -9021,14 +9352,116 @@ function createNodeInspectorViews(ctx, state) {
9021
9352
  label: "Existing document\u2026",
9022
9353
  group: "Documents"
9023
9354
  }
9024
- ] : []
9025
- ];
9026
- const parent = findNode(doc.value, node.id)?.ancestors.at(-1);
9027
- const otherwiseChoices = parent ? addableIn(
9028
- zonesOf(parent.node).find((option) => option.key === parent.zone),
9029
- parent.node.type
9030
- ) : [];
9031
- const chosen = addable.find((item) => item.value === addComponent.value) ?? addable[0];
9355
+ ] : []
9356
+ ];
9357
+ const parent = findNode(doc.value, node.id)?.ancestors.at(-1);
9358
+ const otherwiseChoices = parent ? addableIn(
9359
+ zonesOf(parent.node).find((option) => option.key === parent.zone),
9360
+ parent.node.type
9361
+ ) : [];
9362
+ const chosen = addable.find((item) => item.value === addComponent.value) ?? addable[0];
9363
+ const opens = (prop) => !isBinding(props[prop.name]) && (Boolean(customFor(prop.type)) || opensEditor(
9364
+ fieldEditorKind(
9365
+ prop.type,
9366
+ definitionsOf(node.type),
9367
+ prop.iconSource
9368
+ )
9369
+ )) || controlFor(prop, props[prop.name], definitionsOf(node.type)).kind === "icon";
9370
+ const rowsOf2 = (group) => group.flatMap((prop) => {
9371
+ const value = props[prop.name];
9372
+ if (opens(prop))
9373
+ return [
9374
+ {
9375
+ kind: "open",
9376
+ row: controlFor(prop, value, definitionsOf(node.type)).kind === "icon" ? propControl(prop, value, node.type) : configureRow(fieldLabel(prop), value, {
9377
+ prop: prop.name,
9378
+ path: []
9379
+ })
9380
+ }
9381
+ ];
9382
+ if (!isBinding(value) && isAppSupplied(prop.type, definitionsOf(node.type)))
9383
+ return [
9384
+ {
9385
+ kind: "open",
9386
+ row: /* @__PURE__ */ jsx(
9387
+ ListItem,
9388
+ {
9389
+ label: fieldLabel(prop),
9390
+ description: "The app supplies it",
9391
+ status: "Promote to a param",
9392
+ accessibleLabel: `Promote ${fieldLabel(prop).toLowerCase()} to a param`,
9393
+ action: PROMOTE_PROP_ACTION,
9394
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
9395
+ rootAttributes: {
9396
+ "data-editor-promote-prop": prop.name
9397
+ }
9398
+ }
9399
+ )
9400
+ }
9401
+ ];
9402
+ if (prop.slot && prop.name !== "children" && !prop.type.acceptsText)
9403
+ return [{ kind: "open", row: nodeContentRow(node, prop.name) }];
9404
+ const control = contentControl(node, prop) ?? propControl(prop, value, node.type);
9405
+ if (control) return [{ kind: "edit", row: control }];
9406
+ const param = value?.$param;
9407
+ if (typeof param === "string")
9408
+ return [
9409
+ {
9410
+ kind: "edit",
9411
+ row: /* @__PURE__ */ jsx(
9412
+ TextField,
9413
+ {
9414
+ label: `${fieldLabel(prop)} param`,
9415
+ value: param,
9416
+ hint: "Renaming the param updates every prop that uses it.",
9417
+ error: fieldErrors.value[`#param:${param}`],
9418
+ rootAttributes: { [HOOK.param]: param }
9419
+ }
9420
+ )
9421
+ }
9422
+ ];
9423
+ return [
9424
+ {
9425
+ kind: "fixed",
9426
+ row: /* @__PURE__ */ jsx(
9427
+ ValueTableRow,
9428
+ {
9429
+ label: fieldLabel(prop),
9430
+ value: inspectorSections(node, {
9431
+ ...component,
9432
+ props: [prop],
9433
+ groups: []
9434
+ })[0].rows[0].value
9435
+ }
9436
+ )
9437
+ }
9438
+ ];
9439
+ });
9440
+ const dataAttributes2 = component.props.find(
9441
+ (prop) => prop.name === DATA_ATTRIBUTES_PROP
9442
+ );
9443
+ const groups = propertiesGroups(component);
9444
+ const propertiesState = {
9445
+ groups,
9446
+ values: props,
9447
+ problems: fieldProblems.value,
9448
+ fieldsOf: (group, label) => inspectorRuns(rowsOf2(group), label),
9449
+ title,
9450
+ bindingOf: (prop) => bindingSummary(props[prop.name]),
9451
+ bindPage: (prop) => bindPropPage(
9452
+ ctx,
9453
+ node,
9454
+ prop,
9455
+ promotable.some((item) => item.name === prop.name)
9456
+ ),
9457
+ ...dataAttributes2 ? {
9458
+ extra: {
9459
+ group: "Integration",
9460
+ props: [dataAttributes2],
9461
+ content: dataAttributesSection(ctx, node)
9462
+ }
9463
+ } : {}
9464
+ };
9032
9465
  const own = currentProblems.value.filter(
9033
9466
  (problem) => problem.nodeId === node.id
9034
9467
  );
@@ -9039,13 +9472,13 @@ function createNodeInspectorViews(ctx, state) {
9039
9472
  controlInsets: "trbl",
9040
9473
  gap: true,
9041
9474
  rootAttributes: { "data-key": "editor-node-problems" },
9042
- children: own.map(({ diagnostic }) => /* @__PURE__ */ jsx(
9475
+ children: own.map(({ diagnostic: diagnostic2 }) => /* @__PURE__ */ jsx(
9043
9476
  StateBanner,
9044
9477
  {
9045
9478
  tone: "warning",
9046
- title: diagnostic.message,
9047
- detail: diagnostic.code,
9048
- rootAttributes: { "data-editor-node-problem": diagnostic.code }
9479
+ title: diagnostic2.message,
9480
+ detail: diagnostic2.code,
9481
+ rootAttributes: { "data-editor-node-problem": diagnostic2.code }
9049
9482
  }
9050
9483
  ))
9051
9484
  }
@@ -9060,123 +9493,14 @@ function createNodeInspectorViews(ctx, state) {
9060
9493
  {
9061
9494
  label: "Ref name",
9062
9495
  value: node.name ?? "",
9063
- hint: "A name makes the node a typed ref in the generated module.",
9496
+ hint: node.name ? void 0 : "Name it to use it as a typed ref in code.",
9064
9497
  error: fieldErrors.value["#name"],
9065
9498
  rootAttributes: { [HOOK.name]: "true" }
9066
9499
  }
9067
9500
  )
9068
9501
  }
9069
9502
  ),
9070
- groupedProps(component).map((section) => {
9071
- const opens = (prop) => !isBinding(props[prop.name]) && (Boolean(customFor(prop.type)) || opensEditor(
9072
- fieldEditorKind(
9073
- prop.type,
9074
- definitionsOf(node.type),
9075
- prop.iconSource
9076
- )
9077
- )) || controlFor(prop, props[prop.name], definitionsOf(node.type)).kind === "icon";
9078
- const rows = section.props.flatMap((prop) => {
9079
- const value = props[prop.name];
9080
- if (opens(prop))
9081
- return [
9082
- {
9083
- kind: "open",
9084
- row: controlFor(prop, value, definitionsOf(node.type)).kind === "icon" ? propControl(prop, value, node.type) : configureRow(propLabel(prop.name), value, {
9085
- prop: prop.name,
9086
- path: []
9087
- })
9088
- }
9089
- ];
9090
- if (!isBinding(value) && isAppSupplied(prop.type, definitionsOf(node.type)))
9091
- return [
9092
- {
9093
- kind: "open",
9094
- row: /* @__PURE__ */ jsx(
9095
- ListItem,
9096
- {
9097
- label: propLabel(prop.name),
9098
- description: "The app supplies it",
9099
- status: "Promote to a param",
9100
- accessibleLabel: `Promote ${propLabel(prop.name).toLowerCase()} to a param`,
9101
- action: PROMOTE_PROP_ACTION,
9102
- trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
9103
- rootAttributes: { "data-editor-promote-prop": prop.name }
9104
- }
9105
- )
9106
- }
9107
- ];
9108
- if (prop.slot && prop.name !== "children" && !prop.type.acceptsText)
9109
- return [{ kind: "open", row: nodeContentRow(node, prop.name) }];
9110
- const control = contentControl(node, prop) ?? propControl(prop, value, node.type);
9111
- if (control) return [{ kind: "edit", row: control }];
9112
- const param = value?.$param;
9113
- if (typeof param === "string")
9114
- return [
9115
- {
9116
- kind: "edit",
9117
- row: /* @__PURE__ */ jsx(
9118
- TextField,
9119
- {
9120
- label: `${propLabel(prop.name)} param`,
9121
- value: param,
9122
- hint: "Renaming the param updates every prop that uses it.",
9123
- error: fieldErrors.value[`#param:${param}`],
9124
- rootAttributes: { [HOOK.param]: param }
9125
- }
9126
- )
9127
- }
9128
- ];
9129
- return [
9130
- {
9131
- kind: "fixed",
9132
- row: /* @__PURE__ */ jsx(
9133
- ValueTableRow,
9134
- {
9135
- label: propLabel(prop.name),
9136
- value: inspectorSections(node, {
9137
- ...component,
9138
- props: [prop],
9139
- groups: []
9140
- })[0].rows[0].value
9141
- }
9142
- )
9143
- }
9144
- ];
9145
- });
9146
- return [
9147
- /* @__PURE__ */ jsx(ListHeader, { label: section.title, size: "xs" }),
9148
- ...inspectorRuns(rows, `${title} ${section.title}`)
9149
- ];
9150
- }),
9151
- dataAttributesSection(ctx, node, component),
9152
- promotable.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
9153
- /* @__PURE__ */ jsx(ListHeader, { label: "Promote to a param", size: "xs" }),
9154
- /* @__PURE__ */ jsxs(List, { controlInsets: "trbl", gap: true, children: [
9155
- /* @__PURE__ */ jsx(
9156
- Select,
9157
- {
9158
- name: "promote-prop",
9159
- label: "Prop",
9160
- value: promotable.some((prop) => prop.name === promoteProp.value) ? promoteProp.value : promotable[0].name,
9161
- choices: promotable.map((prop) => ({
9162
- value: prop.name,
9163
- label: propLabel(prop.name)
9164
- })),
9165
- rootAttributes: { [HOOK.promote]: "true" }
9166
- }
9167
- ),
9168
- /* @__PURE__ */ jsx(
9169
- Button,
9170
- {
9171
- emphasis: "secondary",
9172
- size: "compact",
9173
- action: PROMOTE_ACTION,
9174
- children: "Promote"
9175
- }
9176
- )
9177
- ] })
9178
- ] }) : void 0,
9179
- inspectorBindSection(ctx, bindProp, node, component)
9503
+ propertiesDirectory(propertiesState)
9180
9504
  ] });
9181
9505
  const flow = /* @__PURE__ */ jsxs(List, { children: [
9182
9506
  controlFlowSection(
@@ -9194,7 +9518,7 @@ function createNodeInspectorViews(ctx, state) {
9194
9518
  extractSection(node, extractBlocked),
9195
9519
  moveSection(node)
9196
9520
  ] });
9197
- const children = /* @__PURE__ */ jsxs(List, { children: [
9521
+ const children2 = /* @__PURE__ */ jsxs(List, { children: [
9198
9522
  /* @__PURE__ */ jsx(ListHeader, { label: "Add a child", size: "xs" }),
9199
9523
  zones.length && zone ? /* @__PURE__ */ jsxs(List, { controlInsets: "trbl", gap: true, children: [
9200
9524
  /* @__PURE__ */ jsx(
@@ -9235,7 +9559,7 @@ function createNodeInspectorViews(ctx, state) {
9235
9559
  [
9236
9560
  { area: "properties", name: "Properties", panel: properties },
9237
9561
  { area: "flow", name: "Flow", panel: flow },
9238
- { area: "children", name: "Children", panel: children }
9562
+ { area: "children", name: "Children", panel: children2 }
9239
9563
  ]
9240
9564
  );
9241
9565
  return {
@@ -9243,9 +9567,7 @@ function createNodeInspectorViews(ctx, state) {
9243
9567
  /* @__PURE__ */ jsx(
9244
9568
  ListHeader,
9245
9569
  {
9246
- label: node.name ? `${node.name} \xB7 ${title}` : title,
9247
- count: component.props.length,
9248
- countLabel: "props",
9570
+ label: title,
9249
9571
  action: DUPLICATE_ACTION,
9250
9572
  actionLabel: "Duplicate",
9251
9573
  actionIcon: /* @__PURE__ */ jsx(LucideIcon, { icon: CopyPlus, name: "copy-plus" }),
@@ -9255,7 +9577,13 @@ function createNodeInspectorViews(ctx, state) {
9255
9577
  ),
9256
9578
  strip
9257
9579
  ] }),
9258
- content: /* @__PURE__ */ jsx(List, { children: panels })
9580
+ content: /* @__PURE__ */ jsx(List, { children: panels }),
9581
+ pages: propertiesPages(
9582
+ propertiesState,
9583
+ inspectorGroup.value,
9584
+ propertiesQuery.value,
9585
+ propertiesQueryRevision.value
9586
+ )
9259
9587
  };
9260
9588
  };
9261
9589
  return { viewEditor, nodeEditor };
@@ -9347,63 +9675,808 @@ function fit(host) {
9347
9675
  const shadow = host.shadowRoot;
9348
9676
  const stage = shadow.querySelector("[data-thumb-stage]");
9349
9677
  const slot = shadow.querySelector("slot");
9350
- const content = stage.firstElementChild ?? stage;
9351
- const width = Math.max(content.offsetWidth, content.scrollWidth);
9352
- const height = Math.max(content.offsetHeight, content.scrollHeight);
9353
- const box2 = { width: host.clientWidth, height: host.clientHeight };
9354
- const empty = content === stage || !width || !height;
9678
+ stage.style.transform = "";
9679
+ const stageRect = stage.getBoundingClientRect();
9680
+ const boxes = Array.from(stage.children).map((element) => {
9681
+ const content = element;
9682
+ const rect = content.getBoundingClientRect();
9683
+ return {
9684
+ x: content.offsetLeft ?? rect.left - stageRect.left,
9685
+ y: content.offsetTop ?? rect.top - stageRect.top,
9686
+ width: Math.max(
9687
+ content.offsetWidth || 0,
9688
+ content.scrollWidth || 0,
9689
+ rect.width
9690
+ ),
9691
+ height: Math.max(
9692
+ content.offsetHeight || 0,
9693
+ content.scrollHeight || 0,
9694
+ rect.height
9695
+ )
9696
+ };
9697
+ });
9698
+ for (const node of stage.childNodes) {
9699
+ if (node.nodeType !== 3 || !node.textContent?.trim()) continue;
9700
+ const range = host.ownerDocument.createRange();
9701
+ range.selectNode(node);
9702
+ if (typeof range.getBoundingClientRect !== "function") continue;
9703
+ const rect = range.getBoundingClientRect();
9704
+ boxes.push({
9705
+ x: rect.left - stageRect.left,
9706
+ y: rect.top - stageRect.top,
9707
+ width: rect.width,
9708
+ height: rect.height
9709
+ });
9710
+ }
9711
+ const visible = boxes.filter((box3) => box3.width > 0 && box3.height > 0);
9712
+ const empty = visible.length === 0;
9355
9713
  host.toggleAttribute("data-thumb-empty", empty);
9356
9714
  slot.hidden = !empty;
9357
9715
  stage.style.visibility = empty ? "hidden" : "";
9358
- if (empty || !box2.width || !box2.height) return;
9716
+ const box2 = { width: host.clientWidth, height: host.clientHeight };
9717
+ if (empty || !box2.width || !box2.height || host.dataset.thumbFit === "fill")
9718
+ return;
9719
+ const left = Math.min(...visible.map((box3) => box3.x));
9720
+ const top = Math.min(...visible.map((box3) => box3.y));
9721
+ const width = Math.max(...visible.map((box3) => box3.x + box3.width)) - left;
9722
+ const height = Math.max(...visible.map((box3) => box3.y + box3.height)) - top;
9359
9723
  const scale = Math.min(
9360
9724
  MAX_SCALE,
9361
9725
  (box2.width - INSET * 2) / width,
9362
9726
  (box2.height - INSET * 2) / height
9363
9727
  );
9364
- const centerX = content.offsetLeft + width / 2;
9365
- const centerY = content.offsetTop + height / 2;
9366
- stage.style.transform = `translate(${box2.width / 2 - centerX * scale}px, ${box2.height / 2 - centerY * scale}px) scale(${scale})`;
9728
+ stage.style.transform = `translate(${box2.width / 2 - (left + width / 2) * scale}px, ${box2.height / 2 - (top + height / 2) * scale}px) scale(${scale})`;
9367
9729
  }
9368
9730
  function wirePaletteThumbnails(root, options) {
9369
9731
  const document2 = root.ownerDocument;
9370
9732
  const View = document2.defaultView;
9733
+ const hosts = /* @__PURE__ */ new Map();
9734
+ const owners = /* @__PURE__ */ new Map();
9735
+ const frames = /* @__PURE__ */ new Map();
9736
+ let disposed = false;
9737
+ const schedule = (host) => {
9738
+ const previous = frames.get(host);
9739
+ if (previous !== void 0) View.cancelAnimationFrame(previous);
9740
+ frames.set(
9741
+ host,
9742
+ View.requestAnimationFrame(() => {
9743
+ frames.delete(host);
9744
+ if (!disposed && root.contains(host)) fit(host);
9745
+ })
9746
+ );
9747
+ };
9371
9748
  const resize = "ResizeObserver" in View ? new View.ResizeObserver((entries) => {
9372
- for (const entry of entries) fit(entry.target);
9749
+ for (const entry of entries) {
9750
+ const host = owners.get(entry.target);
9751
+ if (host) schedule(host);
9752
+ }
9373
9753
  }) : void 0;
9754
+ const release = (host) => {
9755
+ const owned = hosts.get(host);
9756
+ const frame = frames.get(host);
9757
+ if (frame !== void 0) View.cancelAnimationFrame(frame);
9758
+ frames.delete(host);
9759
+ resize?.unobserve(host);
9760
+ owners.delete(host);
9761
+ if (owned.content) {
9762
+ resize?.unobserve(owned.content);
9763
+ owners.delete(owned.content);
9764
+ }
9765
+ host.shadowRoot.removeEventListener("load", owned.load, true);
9766
+ hosts.delete(host);
9767
+ };
9374
9768
  const fill = (host) => {
9375
9769
  const key = host.dataset.editorPaletteThumb;
9376
- if (host.dataset.thumbKey === key) return;
9770
+ if (hosts.get(host)?.key === key) return;
9771
+ if (hosts.has(host)) release(host);
9377
9772
  host.dataset.thumbKey = key;
9773
+ host.dataset.thumbFit = options.fitOf?.(key) ?? "contain";
9378
9774
  const html = options.htmlOf(key);
9379
9775
  const shadow = host.shadowRoot ?? host.attachShadow({ mode: "open" });
9380
9776
  const sheet = sharedSheet(document2);
9381
9777
  if (sheet) shadow.adoptedStyleSheets = [sheet];
9382
- shadow.innerHTML = `<slot></slot><div data-thumb-stage style="${STAGE_STYLE}; visibility: hidden">${html ?? ""}</div>`;
9778
+ const style = host.dataset.thumbFit === "fill" ? `${STAGE_STYLE}; width: 100%; height: 100%` : STAGE_STYLE;
9779
+ shadow.innerHTML = `<slot></slot><div data-thumb-stage style="${style}; visibility: hidden">${html ?? ""}</div>`;
9780
+ const content = shadow.querySelector("[data-thumb-stage]").firstElementChild ?? void 0;
9781
+ const load = () => schedule(host);
9782
+ hosts.set(host, { key, content, load });
9783
+ shadow.addEventListener("load", load, true);
9383
9784
  if (html === void 0) {
9384
9785
  host.toggleAttribute("data-thumb-empty", true);
9385
9786
  return;
9386
9787
  }
9387
- View.requestAnimationFrame(() => fit(host));
9388
- resize?.observe(host);
9788
+ owners.set(host, host);
9789
+ resize?.observe(host);
9790
+ if (content) {
9791
+ owners.set(content, host);
9792
+ resize?.observe(content);
9793
+ }
9794
+ schedule(host);
9795
+ };
9796
+ const scan = () => {
9797
+ const current = new Set(
9798
+ root.querySelectorAll(hook(HOOK.paletteThumb))
9799
+ );
9800
+ for (const host of hosts.keys()) if (!current.has(host)) release(host);
9801
+ for (const host of current) fill(host);
9802
+ };
9803
+ scan();
9804
+ const observer = new View.MutationObserver(scan);
9805
+ observer.observe(root, {
9806
+ childList: true,
9807
+ subtree: true,
9808
+ attributes: true,
9809
+ attributeFilter: [HOOK.paletteThumb]
9810
+ });
9811
+ return () => {
9812
+ if (disposed) return;
9813
+ disposed = true;
9814
+ observer.disconnect();
9815
+ for (const host of hosts.keys()) release(host);
9816
+ resize?.disconnect();
9817
+ };
9818
+ }
9819
+ var CAMEL4 = /^[a-z][A-Za-z0-9]*$/;
9820
+ function checkedParamEdit(document2, next, catalog) {
9821
+ const before = new Set(
9822
+ validateView(document2, catalog).diagnostics.map(
9823
+ ({ code, path, message }) => `${code}:${path}:${message}`
9824
+ )
9825
+ );
9826
+ const added = validateView(next, catalog).diagnostics.find(
9827
+ ({ code, path, message }) => !before.has(`${code}:${path}:${message}`)
9828
+ );
9829
+ return added ? { error: added.message } : { document: next };
9830
+ }
9831
+ function createParam(document2, catalog, name, type) {
9832
+ if (!CAMEL4.test(name))
9833
+ return { error: "A param name is a camelCase identifier." };
9834
+ if (Object.hasOwn(document2.params ?? {}, name))
9835
+ return { error: `There is already a param named ${name}.` };
9836
+ return checkedParamEdit(
9837
+ document2,
9838
+ { ...document2, params: { ...document2.params, [name]: { type } } },
9839
+ catalog
9840
+ );
9841
+ }
9842
+ function paramIsReferenced(document2, name) {
9843
+ const reads = (value) => {
9844
+ if (Array.isArray(value)) return value.some(reads);
9845
+ if (value === null || typeof value !== "object") return false;
9846
+ const record2 = value;
9847
+ if (record2.$param === name) return true;
9848
+ if (typeof record2.$bind === "string" && record2.$bind.split(".")[0] === name)
9849
+ return true;
9850
+ return Object.values(record2).some(reads);
9851
+ };
9852
+ return reads(document2.root);
9853
+ }
9854
+ function removeParam(document2, catalog, name) {
9855
+ if (!Object.hasOwn(document2.params ?? {}, name))
9856
+ return { error: `No param ${name}.` };
9857
+ if (paramIsReferenced(document2, name))
9858
+ return {
9859
+ error: `Param ${name} is used in this view. Remove its bindings first.`
9860
+ };
9861
+ const params = Object.fromEntries(
9862
+ Object.entries(document2.params ?? {}).filter(([key]) => key !== name)
9863
+ );
9864
+ return checkedParamEdit(
9865
+ document2,
9866
+ {
9867
+ ...document2,
9868
+ ...Object.keys(params).length ? { params } : { params: void 0 }
9869
+ },
9870
+ catalog
9871
+ );
9872
+ }
9873
+ var PARAMETER_DIALOG = "editor-parameter-dialog";
9874
+ var STACK = "editor-parameter-stack";
9875
+ var OPEN = "editor-parameter-open";
9876
+ var SAVE = "editor-parameter-save";
9877
+ var REMOVE = "editor-parameter-remove";
9878
+ var NAVIGATE = "editor-parameter-navigate";
9879
+ var COMPLETE = "editor-parameter-complete";
9880
+ var describe = (type) => {
9881
+ if (type.typescript) return type.typescript.text;
9882
+ if (type.text) return type.text;
9883
+ return typeText(type);
9884
+ };
9885
+ var hasProjectTypes = (document2) => Object.values(document2.params ?? {}).some((param) => param.type.typescript);
9886
+ var diagnostic = (item) => ({
9887
+ code: "code" in item ? String(item.code) : "KUI-V018",
9888
+ path: "path" in item ? String(item.path) : "$.params",
9889
+ message: item.message
9890
+ });
9891
+ var children = (type) => type.kind === "array" && type.items ? [{ key: "items", name: "Item", type: type.items }] : type.kind === "object" ? (type.props ?? []).map((item, index) => ({
9892
+ key: `field:${index}`,
9893
+ name: item.name,
9894
+ type: item.type
9895
+ })) : type.kind === "union" ? (type.members ?? []).map((item, index) => ({
9896
+ key: `member:${index}`,
9897
+ name: `Member ${index + 1}`,
9898
+ type: item
9899
+ })) : [];
9900
+ function createParameterEditor(options) {
9901
+ const draft = signal(null);
9902
+ const semanticProblems = signal([]);
9903
+ const checking = signal(false);
9904
+ let root;
9905
+ let draftRevision = 0;
9906
+ let semanticRevision = 0;
9907
+ let timer;
9908
+ let focused = false;
9909
+ const clearTimer = () => {
9910
+ if (timer !== void 0 && root) realmOf(root).clearTimeout(timer);
9911
+ timer = void 0;
9912
+ };
9913
+ const setError = (error) => {
9914
+ draft.value = { ...draft.peek(), error, pending: false };
9915
+ };
9916
+ const analyze = async (format = false, cursor) => {
9917
+ clearTimer();
9918
+ const current = draft.peek();
9919
+ const revision = ++draftRevision;
9920
+ const source = options.source();
9921
+ if (!options.service) {
9922
+ setError(TYPE_SERVICE_REQUIRED.message);
9923
+ return;
9924
+ }
9925
+ draft.value = { ...current, pending: true, error: "" };
9926
+ try {
9927
+ const result = await options.service({
9928
+ action: "analyze",
9929
+ source,
9930
+ text: current.text,
9931
+ cursor,
9932
+ // A formatting pass never shows suggestions (KF-SNM61J).
9933
+ ...format ? { suggest: false } : {},
9934
+ declared: current.type?.typescript ? void 0 : current.type
9935
+ });
9936
+ if (revision !== draftRevision || !draft.peek() || source !== options.source())
9937
+ return;
9938
+ const next = draft.peek();
9939
+ const text = format && result.type?.typescript ? result.type.typescript.text : next.text;
9940
+ draft.value = {
9941
+ ...next,
9942
+ text,
9943
+ type: result.type,
9944
+ pending: false,
9945
+ error: result.diagnostics.map((item) => item.message).join("\n"),
9946
+ suggestions: focused && !format ? (result.suggestions ?? []).slice(0, 8) : []
9947
+ };
9948
+ if (format && text !== next.text && root) {
9949
+ const input2 = root.querySelector(
9950
+ '[data-parameter-draft="type"] textarea'
9951
+ );
9952
+ input2.value = text;
9953
+ }
9954
+ } catch (error) {
9955
+ if (revision === draftRevision && source === options.source())
9956
+ setError(error instanceof Error ? error.message : String(error));
9957
+ }
9958
+ };
9959
+ const schedule = (cursor) => {
9960
+ clearTimer();
9961
+ draftRevision += 1;
9962
+ draft.value = {
9963
+ ...draft.peek(),
9964
+ type: void 0,
9965
+ pending: true,
9966
+ error: ""
9967
+ };
9968
+ timer = realmOf(root).setTimeout(() => {
9969
+ void analyze(false, cursor);
9970
+ }, 120);
9971
+ };
9972
+ const validateNow = async () => {
9973
+ const document2 = options.document.peek();
9974
+ if (!hasProjectTypes(document2)) {
9975
+ semanticProblems.value = [];
9976
+ checking.value = false;
9977
+ return document2;
9978
+ }
9979
+ const revision = ++semanticRevision;
9980
+ const source = options.source();
9981
+ checking.value = true;
9982
+ if (!options.service) {
9983
+ semanticProblems.value = [TYPE_SERVICE_REQUIRED];
9984
+ checking.value = false;
9985
+ return void 0;
9986
+ }
9987
+ try {
9988
+ const result = await options.service({
9989
+ action: "validate",
9990
+ source,
9991
+ document: document2
9992
+ });
9993
+ if (revision !== semanticRevision || document2 !== options.document.peek() || source !== options.source())
9994
+ return void 0;
9995
+ semanticProblems.value = result.diagnostics.map(diagnostic);
9996
+ checking.value = false;
9997
+ if (result.diagnostics.length) return void 0;
9998
+ const next = result.document ?? document2;
9999
+ if (JSON.stringify(next) !== JSON.stringify(document2))
10000
+ options.refresh(next);
10001
+ return next;
10002
+ } catch (error) {
10003
+ if (revision === semanticRevision && document2 === options.document.peek() && source === options.source()) {
10004
+ semanticProblems.value = [
10005
+ {
10006
+ ...TYPE_SERVICE_REQUIRED,
10007
+ message: error instanceof Error ? error.message : String(error)
10008
+ }
10009
+ ];
10010
+ checking.value = false;
10011
+ }
10012
+ return void 0;
10013
+ }
10014
+ };
10015
+ const open = (name) => {
10016
+ const param = name ? options.document.peek().params?.[name] : void 0;
10017
+ draftRevision += 1;
10018
+ draft.value = {
10019
+ original: name,
10020
+ name: name ?? "",
10021
+ text: param ? describe(param.type) : "string",
10022
+ type: param?.type,
10023
+ hasDefault: param ? Object.hasOwn(param, "default") : false,
10024
+ defaultText: JSON.stringify(param?.default ?? ""),
10025
+ error: "",
10026
+ pending: false,
10027
+ suggestions: [],
10028
+ path: []
10029
+ };
10030
+ focused = false;
10031
+ void analyze(true);
10032
+ const dialog2 = root.querySelector(
10033
+ `#${PARAMETER_DIALOG}`
10034
+ );
10035
+ openDialog(dialog2);
10036
+ };
10037
+ const close = () => {
10038
+ const dialog2 = root?.querySelector(
10039
+ `#${PARAMETER_DIALOG}`
10040
+ );
10041
+ if (dialog2?.open) closeDialog(dialog2);
10042
+ clearTimer();
10043
+ draftRevision += 1;
10044
+ draft.value = null;
10045
+ focused = false;
10046
+ };
10047
+ const save = async () => {
10048
+ const current = draft.peek();
10049
+ if (!current || current.pending || !current.type || !options.service)
10050
+ return;
10051
+ const document2 = options.document.peek();
10052
+ const param = current.original ? document2.params?.[current.original] : void 0;
10053
+ const definition = { ...param, type: current.type };
10054
+ delete definition.default;
10055
+ if (current.hasDefault) {
10056
+ try {
10057
+ definition.default = JSON.parse(current.defaultText);
10058
+ delete definition.optional;
10059
+ } catch {
10060
+ setError("Enter a valid JSON default value.");
10061
+ return;
10062
+ }
10063
+ }
10064
+ const name = current.name.trim();
10065
+ let edited;
10066
+ if (!current.original)
10067
+ edited = createParam(document2, options.catalog, name, current.type);
10068
+ else edited = renameParam(document2, current.original, name);
10069
+ if ("error" in edited) {
10070
+ setError(edited.error);
10071
+ return;
10072
+ }
10073
+ const checked2 = checkedParamEdit(
10074
+ document2,
10075
+ {
10076
+ ...edited.document,
10077
+ params: { ...edited.document.params, [name]: definition }
10078
+ },
10079
+ options.catalog
10080
+ );
10081
+ if ("error" in checked2) {
10082
+ setError(checked2.error);
10083
+ return;
10084
+ }
10085
+ const revision = ++draftRevision;
10086
+ const source = options.source();
10087
+ draft.value = { ...current, pending: true, error: "", suggestions: [] };
10088
+ try {
10089
+ const result = await options.service({
10090
+ action: "validate",
10091
+ source,
10092
+ document: checked2.document
10093
+ });
10094
+ if (revision !== draftRevision || !draft.peek()) return;
10095
+ if (document2 !== options.document.peek() || source !== options.source()) {
10096
+ setError("The document changed. Review the parameter and save again.");
10097
+ return;
10098
+ }
10099
+ if (result.diagnostics.length) {
10100
+ setError(result.diagnostics.map((item) => item.message).join("\n"));
10101
+ return;
10102
+ }
10103
+ options.commit(result.document ?? checked2.document);
10104
+ close();
10105
+ } catch (error) {
10106
+ if (revision === draftRevision)
10107
+ setError(error instanceof Error ? error.message : String(error));
10108
+ }
10109
+ };
10110
+ const panel = () => /* @__PURE__ */ jsxs(List, { rootAttributes: { "data-editor-document-params": "" }, children: [
10111
+ /* @__PURE__ */ jsx(ListHeader, { label: "Parameters" }),
10112
+ Object.entries(options.document.value.params ?? {}).map(
10113
+ ([name, param]) => /* @__PURE__ */ jsx(
10114
+ ListItem,
10115
+ {
10116
+ label: name,
10117
+ description: describe(param.type),
10118
+ action: OPEN,
10119
+ itemId: name,
10120
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" }),
10121
+ rootAttributes: { "data-editor-param-row": name }
10122
+ }
10123
+ )
10124
+ ),
10125
+ /* @__PURE__ */ jsx(
10126
+ ListItem,
10127
+ {
10128
+ label: "Add parameter",
10129
+ action: OPEN,
10130
+ rootAttributes: { "data-editor-param-add": "" }
10131
+ }
10132
+ )
10133
+ ] });
10134
+ const input = (part) => ({ "data-parameter-draft": part });
10135
+ const rootFields = (value) => /* @__PURE__ */ jsxs(List, { gap: true, controlInsets: "trbl", children: [
10136
+ /* @__PURE__ */ jsx(
10137
+ TextField,
10138
+ {
10139
+ label: "Name",
10140
+ value: value.name,
10141
+ rootAttributes: input("name")
10142
+ }
10143
+ ),
10144
+ /* @__PURE__ */ jsx(
10145
+ TextField,
10146
+ {
10147
+ label: "Type",
10148
+ value: value.text,
10149
+ multiline: true,
10150
+ rows: 4,
10151
+ maxRows: 10,
10152
+ spellcheck: false,
10153
+ autocapitalize: "off",
10154
+ autocorrect: "off",
10155
+ autocomplete: "off",
10156
+ error: !value.type ? value.error || void 0 : void 0,
10157
+ rootAttributes: input("type")
10158
+ }
10159
+ ),
10160
+ value.type && value.error ? /* @__PURE__ */ jsx(StateBanner, { tone: "warning", title: value.error }) : void 0,
10161
+ value.pending ? /* @__PURE__ */ jsx(Text, { tone: "quiet", children: "Checking type\u2026" }) : void 0,
10162
+ value.suggestions.length ? /* @__PURE__ */ jsx(List, { children: value.suggestions.map((item, index) => /* @__PURE__ */ jsx(
10163
+ ListItem,
10164
+ {
10165
+ label: item.name,
10166
+ description: item.source,
10167
+ action: COMPLETE,
10168
+ itemId: String(index),
10169
+ rootAttributes: { "data-type-suggestion": String(index) }
10170
+ }
10171
+ )) }) : void 0,
10172
+ /* @__PURE__ */ jsx(
10173
+ Switch,
10174
+ {
10175
+ label: "Use default",
10176
+ checked: value.hasDefault,
10177
+ rootAttributes: input("hasDefault")
10178
+ }
10179
+ ),
10180
+ value.hasDefault ? /* @__PURE__ */ jsx(
10181
+ TextField,
10182
+ {
10183
+ label: "Default value (JSON)",
10184
+ value: value.defaultText,
10185
+ multiline: true,
10186
+ rootAttributes: input("default")
10187
+ }
10188
+ ) : void 0
10189
+ ] });
10190
+ const members = (type, path) => /* @__PURE__ */ jsx(List, { children: children(type).map((item) => /* @__PURE__ */ jsx(
10191
+ ListItem,
10192
+ {
10193
+ label: item.name,
10194
+ description: describe(item.type),
10195
+ action: NAVIGATE,
10196
+ itemId: JSON.stringify([...path, item.key]),
10197
+ trailing: /* @__PURE__ */ jsx(LucideIcon, { icon: ChevronRight, name: "chevron-right" })
10198
+ }
10199
+ )) });
10200
+ const dialog = () => {
10201
+ const value = draft.value;
10202
+ const views = value ? [
10203
+ {
10204
+ key: "parameter",
10205
+ toolbar: { title: value.original ?? "Add parameter" },
10206
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
10207
+ rootFields(value),
10208
+ value.type ? members(value.type, []) : void 0
10209
+ ] })
10210
+ }
10211
+ ] : [];
10212
+ let type = value?.type;
10213
+ const path = [];
10214
+ for (const key of value?.path ?? []) {
10215
+ const item = type && children(type).find((child) => child.key === key);
10216
+ if (!item) break;
10217
+ path.push(key);
10218
+ type = item.type;
10219
+ views.push({
10220
+ key: `parameter:${path.join("/")}`,
10221
+ toolbar: { title: item.name },
10222
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
10223
+ /* @__PURE__ */ jsx(List, { controlInsets: "trbl", children: /* @__PURE__ */ jsx(
10224
+ TextField,
10225
+ {
10226
+ label: "Type",
10227
+ value: describe(item.type),
10228
+ multiline: true,
10229
+ readOnly: true
10230
+ }
10231
+ ) }),
10232
+ members(item.type, [...path])
10233
+ ] })
10234
+ });
10235
+ }
10236
+ return /* @__PURE__ */ jsx(
10237
+ DialogSurface,
10238
+ {
10239
+ id: PARAMETER_DIALOG,
10240
+ label: "Parameter",
10241
+ size: "medium",
10242
+ withoutHeader: true,
10243
+ bodyInset: "none",
10244
+ bodyLayout: "fill",
10245
+ height: px(560),
10246
+ rootAttributes: { "data-key": PARAMETER_DIALOG },
10247
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
10248
+ value?.original ? /* @__PURE__ */ jsx(
10249
+ Button,
10250
+ {
10251
+ action: REMOVE,
10252
+ emphasis: "secondary",
10253
+ disabled: paramIsReferenced(
10254
+ options.document.value,
10255
+ value.original
10256
+ ),
10257
+ title: paramIsReferenced(options.document.value, value.original) ? "Remove this parameter\u2019s bindings before deleting it." : void 0,
10258
+ children: "Remove parameter"
10259
+ }
10260
+ ) : void 0,
10261
+ /* @__PURE__ */ jsx(Button, { rootAttributes: { "data-dialog-close": "" }, children: "Cancel" }),
10262
+ /* @__PURE__ */ jsx(
10263
+ Button,
10264
+ {
10265
+ action: SAVE,
10266
+ tone: "brand",
10267
+ disabled: !value?.type || value.pending || !options.service,
10268
+ children: value?.original ? "Save" : "Add parameter"
10269
+ }
10270
+ )
10271
+ ] }),
10272
+ children: /* @__PURE__ */ jsx(
10273
+ NavStack,
10274
+ {
10275
+ id: STACK,
10276
+ label: "Parameter type",
10277
+ views: views.map((view) => ({
10278
+ ...view,
10279
+ toolbar: {
10280
+ ...view.toolbar,
10281
+ trailing: /* @__PURE__ */ jsx(ToolbarControlGroup, { children: /* @__PURE__ */ jsx(
10282
+ Button,
10283
+ {
10284
+ ariaLabel: "Close parameter",
10285
+ icon: /* @__PURE__ */ jsx(LucideIcon, { icon: X, name: "x" }),
10286
+ rootAttributes: { "data-dialog-close": "" }
10287
+ }
10288
+ ) })
10289
+ }
10290
+ }))
10291
+ }
10292
+ )
10293
+ }
10294
+ );
9389
10295
  };
9390
- const scan = () => {
9391
- for (const host of root.querySelectorAll(
9392
- hook(HOOK.paletteThumb)
9393
- ))
9394
- fill(host);
10296
+ const wire = (element) => {
10297
+ root = element;
10298
+ const stops = [
10299
+ delegate(
10300
+ root,
10301
+ "click",
10302
+ `[data-action="${OPEN}"]`,
10303
+ (_event, target) => open(target.dataset.itemId)
10304
+ ),
10305
+ delegate(root, "click", `[data-action="${SAVE}"]`, () => {
10306
+ void save();
10307
+ }),
10308
+ delegate(root, "click", `[data-action="${REMOVE}"]`, () => {
10309
+ const name = draft.peek().original;
10310
+ const result = removeParam(
10311
+ options.document.peek(),
10312
+ options.catalog,
10313
+ name
10314
+ );
10315
+ if ("error" in result) setError(result.error);
10316
+ else {
10317
+ options.commit(result.document);
10318
+ close();
10319
+ }
10320
+ }),
10321
+ delegate(
10322
+ root,
10323
+ "click",
10324
+ `[data-action="${NAVIGATE}"]`,
10325
+ (_event, target) => {
10326
+ draft.value = {
10327
+ ...draft.peek(),
10328
+ path: JSON.parse(target.dataset.itemId)
10329
+ };
10330
+ }
10331
+ ),
10332
+ delegate(
10333
+ root,
10334
+ "click",
10335
+ `[data-action="${COMPLETE}"]`,
10336
+ (_event, target) => {
10337
+ const suggestion = draft.peek()?.suggestions[Number(target.dataset.itemId)];
10338
+ if (!suggestion || !draft.peek()) return;
10339
+ draft.value = {
10340
+ ...draft.peek(),
10341
+ text: suggestion.text,
10342
+ suggestions: [],
10343
+ path: []
10344
+ };
10345
+ const field = root.querySelector(
10346
+ '[data-parameter-draft="type"] textarea'
10347
+ );
10348
+ field.value = suggestion.text;
10349
+ field.focus();
10350
+ field.setSelectionRange(suggestion.cursor, suggestion.cursor);
10351
+ focused = true;
10352
+ schedule(suggestion.cursor);
10353
+ }
10354
+ ),
10355
+ delegate(
10356
+ root,
10357
+ "input",
10358
+ "[data-parameter-draft]",
10359
+ (_event, target) => {
10360
+ const current = draft.peek();
10361
+ const field = target.querySelector("input,textarea");
10362
+ switch (target.dataset.parameterDraft) {
10363
+ case "name":
10364
+ draft.value = { ...current, name: field.value, error: "" };
10365
+ break;
10366
+ case "default":
10367
+ draft.value = { ...current, defaultText: field.value };
10368
+ break;
10369
+ case "type":
10370
+ draft.value = { ...current, text: field.value, path: [] };
10371
+ focused = true;
10372
+ schedule(field.selectionStart);
10373
+ break;
10374
+ }
10375
+ }
10376
+ ),
10377
+ delegate(
10378
+ root,
10379
+ "change",
10380
+ '[data-parameter-draft="hasDefault"]',
10381
+ (_event, target) => {
10382
+ draft.value = {
10383
+ ...draft.peek(),
10384
+ hasDefault: target.querySelector("input").checked
10385
+ };
10386
+ }
10387
+ ),
10388
+ delegate(
10389
+ root,
10390
+ "focusin",
10391
+ '[data-parameter-draft="type"]',
10392
+ () => {
10393
+ focused = true;
10394
+ }
10395
+ ),
10396
+ delegate(
10397
+ root,
10398
+ "focusout",
10399
+ '[data-parameter-draft="type"]',
10400
+ (event) => {
10401
+ if (event.relatedTarget instanceof Element && event.relatedTarget.closest(
10402
+ "[data-type-suggestion]"
10403
+ ))
10404
+ return;
10405
+ focused = false;
10406
+ const value = draft.peek();
10407
+ if (value?.type?.typescript) {
10408
+ draft.value = {
10409
+ ...value,
10410
+ text: value.type.typescript.text,
10411
+ suggestions: []
10412
+ };
10413
+ const field = root.querySelector(
10414
+ '[data-parameter-draft="type"] textarea'
10415
+ );
10416
+ field.value = value.type.typescript.text;
10417
+ } else if (value) void analyze(true);
10418
+ }
10419
+ ),
10420
+ delegate(
10421
+ root,
10422
+ "keydown",
10423
+ '[data-parameter-draft="type"]',
10424
+ (event) => {
10425
+ const key = event;
10426
+ if (key.key === "ArrowDown" && draft.peek()?.suggestions.length) {
10427
+ key.preventDefault();
10428
+ root.querySelector("[data-type-suggestion]")?.focus();
10429
+ }
10430
+ if (key.key === "Escape" && draft.peek()?.suggestions.length) {
10431
+ key.preventDefault();
10432
+ key.stopPropagation();
10433
+ draft.value = { ...draft.peek(), suggestions: [] };
10434
+ }
10435
+ }
10436
+ ),
10437
+ wireNavStack(root.querySelector(`#${STACK}`), {
10438
+ onBack: () => {
10439
+ draft.value = {
10440
+ ...draft.peek(),
10441
+ path: draft.peek().path.slice(0, -1)
10442
+ };
10443
+ }
10444
+ }),
10445
+ effect(() => {
10446
+ void options.document.value;
10447
+ void options.source();
10448
+ void validateNow();
10449
+ })
10450
+ ];
10451
+ const onClose = (event) => {
10452
+ if (event.target.id === PARAMETER_DIALOG) close();
10453
+ };
10454
+ const onFocus = () => {
10455
+ void validateNow();
10456
+ };
10457
+ root.addEventListener("close", onClose, true);
10458
+ realmOf(root).addEventListener("focus", onFocus);
10459
+ let disposed = false;
10460
+ return () => {
10461
+ if (disposed) return;
10462
+ disposed = true;
10463
+ clearTimer();
10464
+ draftRevision += 1;
10465
+ semanticRevision += 1;
10466
+ element.removeEventListener("close", onClose, true);
10467
+ realmOf(element).removeEventListener("focus", onFocus);
10468
+ for (const stop of stops) stop();
10469
+ root = void 0;
10470
+ };
9395
10471
  };
9396
- scan();
9397
- const observer = new View.MutationObserver(scan);
9398
- observer.observe(root, {
9399
- childList: true,
9400
- subtree: true,
9401
- attributes: true,
9402
- attributeFilter: [HOOK.paletteThumb]
9403
- });
9404
- return () => {
9405
- observer.disconnect();
9406
- resize?.disconnect();
10472
+ return {
10473
+ panel,
10474
+ dialog,
10475
+ wire,
10476
+ semanticProblems,
10477
+ checking,
10478
+ validateNow,
10479
+ close
9407
10480
  };
9408
10481
  }
9409
10482
 
@@ -9445,7 +10518,7 @@ function popView(document2, id) {
9445
10518
  }
9446
10519
  function barItems(bar) {
9447
10520
  return Object.values(bar.zones ?? {}).flatMap(
9448
- (children) => children.flatMap((child) => {
10521
+ (children2) => children2.flatMap((child) => {
9449
10522
  const nodes = "$each" in child ? rowNodes(child) : [child];
9450
10523
  return nodes.flatMap(
9451
10524
  (node) => "type" in node && node.type === TAB_BAR_ITEM ? [{ node, repeated: "$each" in child }] : []
@@ -9703,10 +10776,10 @@ function pushView(play, original, id, viewKey) {
9703
10776
  const next = setProp(play, id, "views", [...views, sourceViews[from]]);
9704
10777
  const node = findNode(next, id).node;
9705
10778
  const zones = { ...node.zones };
9706
- for (const [key, children] of Object.entries(source.zones ?? {})) {
10779
+ for (const [key, children2] of Object.entries(source.zones ?? {})) {
9707
10780
  const match = VIEW_ZONE2.exec(key);
9708
10781
  if (match && Number(match[1]) === from)
9709
- zones[`views.${views.length}.${match[2]}`] = children;
10782
+ zones[`views.${views.length}.${match[2]}`] = children2;
9710
10783
  }
9711
10784
  node.zones = zones;
9712
10785
  return next;
@@ -9973,7 +11046,7 @@ function createPlayContext(root, state, { rows, params, setParams, device, views
9973
11046
  rows.value = owner === void 0 ? scoped : rowsOut(rows.peek(), owner, scoped);
9974
11047
  };
9975
11048
  const adapters = /* @__PURE__ */ new Map();
9976
- const record = (id, key, prop, value) => {
11049
+ const record2 = (id, key, prop, value) => {
9977
11050
  if (isComposed(id)) {
9978
11051
  const { levels, id: own } = levelsOf(state.peek(), id, resolve);
9979
11052
  const recorded2 = recordComposedValue(
@@ -10032,7 +11105,7 @@ function createPlayContext(root, state, { rows, params, setParams, device, views
10032
11105
  change.id,
10033
11106
  change.element ?? change.input
10034
11107
  );
10035
- if (at) record(at.id, at.row, prop, change[prop]);
11108
+ if (at) record2(at.id, at.row, prop, change[prop]);
10036
11109
  };
10037
11110
  const onValue = (readers) => (event) => {
10038
11111
  const at = nodeAt(event.target);
@@ -10045,7 +11118,7 @@ function createPlayContext(root, state, { rows, params, setParams, device, views
10045
11118
  found.state.peek(),
10046
11119
  found.id
10047
11120
  );
10048
- if (change) record(at.id, at.row, change.prop, change.value);
11121
+ if (change) record2(at.id, at.row, change.prop, change.value);
10049
11122
  };
10050
11123
  const onChange = onValue(ON_CHANGE);
10051
11124
  const onClick = onValue(ON_CLICK);
@@ -10053,7 +11126,7 @@ function createPlayContext(root, state, { rows, params, setParams, device, views
10053
11126
  const details = event.target;
10054
11127
  const at = nodeAt(details);
10055
11128
  if (at?.element === details && locate2(at.id)?.node.type === "@kerfjs/ui:disclosure")
10056
- record(at.id, at.row, "open", details.open);
11129
+ record2(at.id, at.row, "open", details.open);
10057
11130
  };
10058
11131
  root.addEventListener("change", onChange);
10059
11132
  root.addEventListener("click", onClick);
@@ -11031,13 +12104,13 @@ function createPlayStage({ presets, doneAction }) {
11031
12104
  };
11032
12105
  return { render, start, safeArea, settings, logAction: logAction2, log };
11033
12106
  }
11034
- var problemRows = (problems) => problems.map(({ diagnostic, nodeId }, index) => /* @__PURE__ */ jsx(
12107
+ var problemRows = (problems) => problems.map(({ diagnostic: diagnostic2, nodeId }, index) => /* @__PURE__ */ jsx(
11035
12108
  ListItem,
11036
12109
  {
11037
12110
  action: PROBLEM_ACTION,
11038
12111
  itemId: nodeId ?? `document-${index}`,
11039
- label: diagnostic.message,
11040
- description: `${diagnostic.code} \xB7 ${diagnostic.path}`,
12112
+ label: diagnostic2.message,
12113
+ description: `${diagnostic2.code} \xB7 ${diagnostic2.path}`,
11041
12114
  multiline: true,
11042
12115
  disabled: !nodeId
11043
12116
  }
@@ -11045,16 +12118,16 @@ var problemRows = (problems) => problems.map(({ diagnostic, nodeId }, index) =>
11045
12118
  var hintRows = (hints) => {
11046
12119
  const plain = problemRows(hints);
11047
12120
  return hints.map(
11048
- ({ diagnostic, nodeId }, index) => (
12121
+ ({ diagnostic: diagnostic2, nodeId }, index) => (
11049
12122
  // KUI-H001 is about a Kerf UI layout node, so it has a node id and
11050
12123
  // SizedRegion is cataloged.
11051
- diagnostic.code === "KUI-H001" ? /* @__PURE__ */ jsx(
12124
+ diagnostic2.code === "KUI-H001" ? /* @__PURE__ */ jsx(
11052
12125
  ListActionRow,
11053
12126
  {
11054
12127
  action: PROBLEM_ACTION,
11055
12128
  itemId: nodeId,
11056
- label: diagnostic.message,
11057
- description: `${diagnostic.code} \xB7 ${diagnostic.path}`,
12129
+ label: diagnostic2.message,
12130
+ description: `${diagnostic2.code} \xB7 ${diagnostic2.path}`,
11058
12131
  multiline: true,
11059
12132
  trailingAction: EMBED_ACTION,
11060
12133
  trailingActionLabel: "Embed in SizedRegion",
@@ -11104,6 +12177,11 @@ function createEditorCatalog(inputs) {
11104
12177
  componentNames,
11105
12178
  components: inputs.components,
11106
12179
  placeholders: { ...KERF_UI_PLACEHOLDERS, ...inputs.placeholders },
12180
+ libraryPreviews: mergeLibraryPreviews(
12181
+ KERF_UI_LIBRARY_PREVIEWS,
12182
+ libraryPreviewSamples(inputs.composition),
12183
+ inputs.libraryPreviews
12184
+ ),
11107
12185
  paletteGroups() {
11108
12186
  const groups = /* @__PURE__ */ new Map();
11109
12187
  const add = (category, key) => {
@@ -11208,7 +12286,14 @@ function download(fileName, text) {
11208
12286
  URL.revokeObjectURL(url);
11209
12287
  }
11210
12288
  function createEditor(options) {
11211
- const { catalog } = options;
12289
+ const catalog = {
12290
+ ...options.catalog,
12291
+ libraryPreviews: mergeLibraryPreviews(
12292
+ KERF_UI_LIBRARY_PREVIEWS,
12293
+ options.catalog.libraryPreviews,
12294
+ options.libraryPreviews
12295
+ )
12296
+ };
11212
12297
  const { viewCatalog, propsByKey, componentNames } = catalog;
11213
12298
  const variantsOf = (type) => propsByKey.get(type)?.variants;
11214
12299
  if (isPlayPage(globalThis.location)) {
@@ -11269,7 +12354,10 @@ function createEditor(options) {
11269
12354
  () => problemsOf(
11270
12355
  doc.value,
11271
12356
  explainViewLoads(
11272
- validation.value.diagnostics,
12357
+ [
12358
+ ...validation.value.diagnostics,
12359
+ ...parameterEditor.semanticProblems.value
12360
+ ],
11273
12361
  documentPath(),
11274
12362
  viewLoads.value
11275
12363
  ),
@@ -11277,7 +12365,10 @@ function createEditor(options) {
11277
12365
  )
11278
12366
  );
11279
12367
  const currentHints = computed(
11280
- () => problemsOf(doc.value, validation.value.hints).map((hint) => ({
12368
+ () => problemsOf(
12369
+ doc.value,
12370
+ validation.value.hints.filter((item) => item.code !== "KUI-H002")
12371
+ ).map((hint) => ({
11281
12372
  ...hint,
11282
12373
  diagnostic: {
11283
12374
  ...hint.diagnostic,
@@ -11288,15 +12379,15 @@ function createEditor(options) {
11288
12379
  const fieldProblems = computed(() => {
11289
12380
  const id = selectedNodeId();
11290
12381
  const byProp = /* @__PURE__ */ new Map();
11291
- for (const { diagnostic, nodeId } of currentProblems.value) {
12382
+ for (const { diagnostic: diagnostic2, nodeId } of currentProblems.value) {
11292
12383
  if (nodeId !== id) continue;
11293
- const prop = /^[^{]*\.props\.([A-Za-z]\w*)$/.exec(diagnostic.path)?.[1];
11294
- if (prop) byProp.set(prop, diagnostic.message);
12384
+ const prop = /^[^{]*\.props\.([A-Za-z]\w*)$/.exec(diagnostic2.path)?.[1];
12385
+ if (prop) byProp.set(prop, diagnostic2.message);
11295
12386
  const required = /^#view "[^"]*" requires param "(\w+)"$/.exec(
11296
- diagnostic.message
12387
+ diagnostic2.message
11297
12388
  )?.[1];
11298
- if (required) byProp.set(required, diagnostic.message);
11299
- const fix = diagnostic.message.split("variants: ")[1];
12389
+ if (required) byProp.set(required, diagnostic2.message);
12390
+ const fix = diagnostic2.message.split("variants: ")[1];
11300
12391
  for (const [, name] of fix?.matchAll(/"([^"]+)"/g) ?? [])
11301
12392
  byProp.set(name, `To fix: ${fix}`);
11302
12393
  }
@@ -11327,9 +12418,10 @@ function createEditor(options) {
11327
12418
  let wired;
11328
12419
  const autosave = options.storage && createAutosave(options.storage, 400, () => realmOf(wired ?? document));
11329
12420
  const documentArea = signal("outline");
11330
- const newParamName = signal("");
11331
- const newParamKind = signal("string");
11332
12421
  const inspectorArea = signal("properties");
12422
+ const inspectorGroup = signal([]);
12423
+ const propertiesQuery = signal("");
12424
+ const propertiesQueryRevision = signal(0);
11333
12425
  const saveAsError = signal("");
11334
12426
  const extractPath = signal("");
11335
12427
  const extractError = signal("");
@@ -11337,7 +12429,6 @@ function createEditor(options) {
11337
12429
  const addZone = signal("");
11338
12430
  const addComponent = signal("");
11339
12431
  const rootComponent = signal("");
11340
- const promoteProp = signal("");
11341
12432
  const bindProp = signal("");
11342
12433
  const bindField = signal("");
11343
12434
  const customSize = signal("");
@@ -11371,203 +12462,32 @@ function createEditor(options) {
11371
12462
  editNotice.value = null;
11372
12463
  historyVersion.value += 1;
11373
12464
  };
11374
- const paramError = (name, message) => {
11375
- fieldErrors.value = {
11376
- ...fieldErrors.value,
11377
- [`#doc-param:${name}`]: message
11378
- };
11379
- };
11380
- const paramType = (kind) => {
11381
- switch (kind) {
11382
- case "array":
11383
- return { kind, items: { kind: "object", props: [] } };
11384
- case "object":
11385
- return { kind, props: [] };
11386
- case "enum":
11387
- return { kind, values: ["choice"] };
11388
- case "literal":
11389
- return { kind, value: "" };
11390
- default:
11391
- return { kind };
11392
- }
11393
- };
11394
- const applyParam = (name, param) => {
11395
- const result = changeParam(doc.value, viewCatalog, name, param);
11396
- if ("error" in result) paramError(name, result.error);
11397
- else commit(result.document);
11398
- };
11399
- const editParam = (at, raw4) => {
11400
- const param = doc.value.params?.[at.name];
11401
- if (!param) return;
11402
- if (at.part === "name") {
11403
- const renamed = renameParam(doc.value, at.name, String(raw4).trim());
11404
- const result = "error" in renamed ? renamed : checkedParamEdit(doc.value, renamed.document, viewCatalog);
11405
- if ("error" in result) paramError(at.name, result.error);
11406
- else commit(result.document);
11407
- return;
11408
- }
11409
- let next = param;
11410
- const type = param.type;
11411
- switch (at.part) {
11412
- case "type":
11413
- next = { ...param, type: paramType(String(raw4)) };
11414
- break;
11415
- case "itemType":
11416
- if (type.kind !== "array") return;
11417
- next = { ...param, type: { ...type, items: paramType(String(raw4)) } };
11418
- break;
11419
- case "defaultEnabled":
11420
- if (raw4 === false) {
11421
- next = Object.fromEntries(
11422
- Object.entries(param).filter(([key]) => key !== "default")
11423
- );
11424
- } else {
11425
- const value = sampleValue(type, at.name, (label) => label);
11426
- if (value === void 0) {
11427
- paramError(at.name, "This type has no editable example default.");
11428
- return;
11429
- }
11430
- next = { ...param, default: value };
11431
- }
11432
- break;
11433
- case "default": {
11434
- let value = raw4;
11435
- if (type.kind === "number") {
11436
- value = Number(raw4);
11437
- if (!String(raw4).trim() || !Number.isFinite(value)) {
11438
- paramError(at.name, "Enter a finite number.");
11439
- return;
11440
- }
11441
- } else if (type.kind === "boolean") {
11442
- value = raw4 === "true";
11443
- } else if (!["string", "content"].includes(type.kind)) {
11444
- try {
11445
- value = JSON.parse(String(raw4));
11446
- } catch {
11447
- paramError(at.name, "Enter a valid JSON value.");
11448
- return;
11449
- }
11450
- }
11451
- next = { ...param, default: value };
11452
- break;
11453
- }
11454
- case "enumValues": {
11455
- let values;
11456
- try {
11457
- values = JSON.parse(String(raw4));
11458
- } catch {
11459
- paramError(at.name, "Enter a JSON array of choices.");
11460
- return;
11461
- }
11462
- if (!Array.isArray(values) || values.length === 0 || !values.every(
11463
- (value) => ["string", "number", "boolean"].includes(typeof value)
11464
- )) {
11465
- paramError(at.name, "Enter a non-empty JSON array of choices.");
11466
- return;
11467
- }
11468
- next = { ...param, type: { ...type, values } };
11469
- break;
11470
- }
11471
- case "literalValue": {
11472
- let value;
11473
- try {
11474
- value = JSON.parse(String(raw4));
11475
- } catch {
11476
- paramError(at.name, "Enter a JSON string, number, or boolean.");
11477
- return;
11478
- }
11479
- if (!["string", "number", "boolean"].includes(typeof value)) {
11480
- paramError(at.name, "Enter a JSON string, number, or boolean.");
11481
- return;
11482
- }
11483
- next = {
11484
- ...param,
11485
- type: { ...type, value }
11486
- };
11487
- break;
11488
- }
11489
- case "fieldName":
11490
- case "fieldType":
11491
- case "fieldRequired": {
11492
- const item = type.kind === "array" ? type.items : type;
11493
- if (item?.kind !== "object" || at.index === void 0) return;
11494
- const fields = [...item.props ?? []];
11495
- const field = fields[at.index];
11496
- if (!field) return;
11497
- if (at.part === "fieldName") {
11498
- const name = String(raw4).trim();
11499
- if (!/^[a-z][A-Za-z0-9]*$/.test(name) || fields.some(
11500
- (other, index) => index !== at.index && other.name === name
11501
- )) {
11502
- paramError(
11503
- at.name,
11504
- "Field names must be unique camelCase identifiers."
11505
- );
11506
- return;
11507
- }
11508
- fields[at.index] = { ...field, name };
11509
- } else if (at.part === "fieldType") {
11510
- fields[at.index] = { ...field, type: paramType(String(raw4)) };
11511
- } else {
11512
- fields[at.index] = { ...field, required: raw4 === true };
11513
- }
11514
- const changed = { ...item, props: fields };
11515
- next = {
11516
- ...param,
11517
- type: type.kind === "array" ? { ...type, items: changed } : changed
11518
- };
11519
- break;
11520
- }
11521
- }
11522
- applyParam(at.name, next);
11523
- };
11524
- const addParamField = (name) => {
11525
- const param = doc.value.params?.[name];
11526
- if (!param) return;
11527
- const type = param.type;
11528
- const item = type.kind === "array" ? type.items : type;
11529
- if (item?.kind !== "object") return;
11530
- const fields = item.props ?? [];
11531
- let fieldName = "field";
11532
- for (let index = 2; fields.some((field) => field.name === fieldName); index += 1)
11533
- fieldName = `field${index}`;
11534
- const changed = {
11535
- ...item,
11536
- props: [
11537
- ...fields,
11538
- { name: fieldName, type: { kind: "string" }, required: true }
11539
- ]
11540
- };
11541
- applyParam(name, {
11542
- ...param,
11543
- type: type.kind === "array" ? { ...type, items: changed } : changed
11544
- });
11545
- };
11546
- const removeParamField = (name, index) => {
11547
- const param = doc.value.params?.[name];
11548
- if (!param) return;
11549
- const type = param.type;
11550
- const item = type.kind === "array" ? type.items : type;
11551
- if (item?.kind !== "object" || !item.props?.[index]) return;
11552
- const changed = {
11553
- ...item,
11554
- props: item.props.filter((_, at) => at !== index)
11555
- };
11556
- applyParam(name, {
11557
- ...param,
11558
- type: type.kind === "array" ? { ...type, items: changed } : changed
11559
- });
11560
- };
12465
+ const parameterEditor = createParameterEditor({
12466
+ document: doc,
12467
+ catalog: viewCatalog,
12468
+ commit,
12469
+ refresh: (document2) => {
12470
+ doc.value = document2;
12471
+ },
12472
+ source: () => documentPath() || documentFileName(doc.peek()),
12473
+ service: options.typeService ?? options.storage?.types
12474
+ });
11561
12475
  const lastExport = signal(void 0);
11562
12476
  const documentSize = signal(280);
11563
12477
  const inspectorSize = signal(300);
11564
12478
  const documentCollapsed = signal(false);
11565
12479
  const inspectorCollapsed = signal(false);
12480
+ const inspectorOverlay = signal(false);
11566
12481
  const collapsed = signal(/* @__PURE__ */ new Set());
11567
12482
  const select = (next) => {
12483
+ const previous = selection.peek();
11568
12484
  selection.value = next;
11569
12485
  if (next?.kind !== "node" || next.id !== openField.value?.node)
11570
12486
  openField.value = null;
12487
+ keepPropertiesPage(
12488
+ next,
12489
+ previous?.kind === "node" && next?.kind === "node" && previous.id === next.id
12490
+ );
11571
12491
  if (next?.kind !== "node" && next?.kind !== "slot") return;
11572
12492
  const visit = findNode(
11573
12493
  doc.value,
@@ -11584,6 +12504,23 @@ function createEditor(options) {
11584
12504
  const current = selection.value;
11585
12505
  return current?.kind === "node" && findNode(doc.value, current.id) ? current.id : void 0;
11586
12506
  };
12507
+ function keepPropertiesPage(next, same) {
12508
+ const steps = inspectorGroup.peek();
12509
+ const path = same ? steps : steps.filter((step) => !step.startsWith(BIND_STEP));
12510
+ if (next?.kind !== "node") {
12511
+ inspectorGroup.value = [];
12512
+ return;
12513
+ }
12514
+ if (path.length !== steps.length) inspectorGroup.value = path;
12515
+ if (path[0] === void 0 || path[0] === ALL_PROPERTIES) return;
12516
+ const component = propsByKey.get(findNode(doc.peek(), next.id).node.type);
12517
+ const group = propertiesGroups(component ?? { props: [] }).find(
12518
+ (item) => item.title === path[0]
12519
+ );
12520
+ if (!group) inspectorGroup.value = [];
12521
+ else if (path.length > 1 && !path[1].startsWith(BIND_STEP) && !group.subgroups.some((subgroup) => subgroup.title === path[1]))
12522
+ inspectorGroup.value = [group.title];
12523
+ }
11587
12524
  const ctx = {
11588
12525
  catalog,
11589
12526
  doc,
@@ -11594,6 +12531,9 @@ function createEditor(options) {
11594
12531
  fieldErrors,
11595
12532
  currentProblems,
11596
12533
  inspectorArea,
12534
+ inspectorGroup,
12535
+ propertiesQuery,
12536
+ propertiesQueryRevision,
11597
12537
  definitionsOf,
11598
12538
  propsEntryOf,
11599
12539
  resolveView,
@@ -11745,7 +12685,7 @@ function createEditor(options) {
11745
12685
  };
11746
12686
  const nodeContentRow = (node, prop, label = propLabel(prop), unset = "Not set") => {
11747
12687
  const entries = node.zones?.[prop] ?? [];
11748
- const children = entries.filter(
12688
+ const children2 = entries.filter(
11749
12689
  (child) => "id" in child && "type" in child
11750
12690
  );
11751
12691
  if (!entries.length) {
@@ -11763,7 +12703,7 @@ function createEditor(options) {
11763
12703
  }
11764
12704
  );
11765
12705
  }
11766
- const first = children[0];
12706
+ const first = children2[0];
11767
12707
  const icon = first?.props?.icon?.$icon;
11768
12708
  return /* @__PURE__ */ jsx(
11769
12709
  ListItem,
@@ -11808,7 +12748,7 @@ function createEditor(options) {
11808
12748
  /* @__PURE__ */ jsx(
11809
12749
  TextField,
11810
12750
  {
11811
- label: propLabel(prop.name),
12751
+ label: fieldLabel(prop),
11812
12752
  value: content.text ?? "",
11813
12753
  disabled: true,
11814
12754
  hint: `Holds ${content.count} ${content.count === 1 ? "node" : "nodes"}; select ${content.count === 1 ? "it" : "them"} in the outline.`
@@ -12035,7 +12975,7 @@ function createEditor(options) {
12035
12975
  const asked = wanted && ![...zones, ...fields].some((zone) => zone.key === wanted) && isFieldZoneKey(node, props, definitionsOf(node.type), wanted) ? [{ key: wanted }] : [];
12036
12976
  return [...zones, ...fields, ...asked];
12037
12977
  };
12038
- const categories = new Map(
12978
+ const categories2 = new Map(
12039
12979
  catalog.paletteGroups().flatMap(
12040
12980
  (group) => group.items.map((item) => [item.key, group.category])
12041
12981
  )
@@ -12055,11 +12995,11 @@ function createEditor(options) {
12055
12995
  ...zone?.key ? suggestedComponents(zone.key, keys) : []
12056
12996
  ])
12057
12997
  ];
12058
- const order = [...categories.keys()];
12998
+ const order = [...categories2.keys()];
12059
12999
  const rank = (key) => order.includes(key) ? order.indexOf(key) : order.length;
12060
13000
  const rest = keys.filter((key) => !suggested.includes(key)).sort((a, b) => rank(a) - rank(b));
12061
- const group = (key) => suggested.length || categories.size ? {
12062
- group: suggested.includes(key) ? "Suggested" : categories.get(key) ?? "Other"
13001
+ const group = (key) => suggested.length || categories2.size ? {
13002
+ group: suggested.includes(key) ? "Suggested" : categories2.get(key) ?? "Other"
12063
13003
  } : {};
12064
13004
  return [...suggested, ...rest].map((key) => ({
12065
13005
  value: key,
@@ -12129,37 +13069,37 @@ function createEditor(options) {
12129
13069
  ] })
12130
13070
  ] });
12131
13071
  };
12132
- const editDataAttribute = (edit2) => {
13072
+ const editDataAttribute = (edit) => {
12133
13073
  const id = selectedNodeId();
12134
13074
  const node = findNode(doc.value, id).node;
12135
13075
  const attributes = dataAttributes(
12136
13076
  node.props?.[DATA_ATTRIBUTES_PROP]
12137
13077
  );
12138
- if (edit2.kind === "name") {
13078
+ if (edit.kind === "name") {
12139
13079
  const prop = propsByKey.get(node.type).props.find((item) => item.name === DATA_ATTRIBUTES_PROP);
12140
13080
  const error = dataAttributeNameError(
12141
- edit2.name,
13081
+ edit.name,
12142
13082
  attributes,
12143
- edit2.index,
13083
+ edit.index,
12144
13084
  protectedDataAttributes(prop.type, definitionsOf(node.type))
12145
13085
  );
12146
- const key = `#data-attribute-${edit2.index}`;
13086
+ const key = `#data-attribute-${edit.index}`;
12147
13087
  if (error) {
12148
13088
  fieldErrors.value = { ...fieldErrors.value, [key]: error };
12149
13089
  return;
12150
13090
  }
12151
13091
  if (fieldErrors.value[key]) fieldErrors.value = {};
12152
- if (attributes[edit2.index][0] === edit2.name) return;
13092
+ if (attributes[edit.index][0] === edit.name) return;
12153
13093
  }
12154
- if (edit2.kind === "value" && attributes[edit2.index][1] === edit2.value)
13094
+ if (edit.kind === "value" && attributes[edit.index][1] === edit.value)
12155
13095
  return;
12156
- if (edit2.kind === "remove") fieldErrors.value = {};
13096
+ if (edit.kind === "remove") fieldErrors.value = {};
12157
13097
  commit(
12158
13098
  setProp(
12159
13099
  doc.value,
12160
13100
  id,
12161
13101
  DATA_ATTRIBUTES_PROP,
12162
- editDataAttributes(attributes, edit2)
13102
+ editDataAttributes(attributes, edit)
12163
13103
  )
12164
13104
  );
12165
13105
  };
@@ -12249,8 +13189,7 @@ function createEditor(options) {
12249
13189
  historyVersion.value += 1;
12250
13190
  selection.value = null;
12251
13191
  loadError.value = null;
12252
- newParamName.value = "";
12253
- newParamKind.value = "string";
13192
+ parameterEditor.close();
12254
13193
  viewLoads.value = /* @__PURE__ */ new Map();
12255
13194
  viewTrail.value = [];
12256
13195
  if (!autosave) return;
@@ -12503,12 +13442,7 @@ function createEditor(options) {
12503
13442
  {
12504
13443
  area: "params",
12505
13444
  name: "Params",
12506
- panel: documentArea.value === "params" ? documentParamsPanel(
12507
- document2,
12508
- newParamName.value,
12509
- newParamKind.value,
12510
- fieldErrors.value
12511
- ) : ""
13445
+ panel: documentArea.value === "params" ? parameterEditor.panel() : ""
12512
13446
  },
12513
13447
  {
12514
13448
  area: "problems",
@@ -12607,14 +13541,14 @@ function createEditor(options) {
12607
13541
  {
12608
13542
  label: "View module (.view.ts)",
12609
13543
  action: EXPORT_MODULE_ACTION,
12610
- disabled: problems > 0,
12611
- disabledReason: "Fix the problems first"
13544
+ disabled: problems > 0 || parameterEditor.checking.value,
13545
+ disabledReason: parameterEditor.checking.value ? "Checking types\u2026" : "Fix the problems first"
12612
13546
  },
12613
13547
  {
12614
13548
  label: "Declarations only (for interpretView)",
12615
13549
  action: EXPORT_DECLARATIONS_ACTION,
12616
- disabled: problems > 0,
12617
- disabledReason: "Fix the problems first"
13550
+ disabled: problems > 0 || parameterEditor.checking.value,
13551
+ disabledReason: parameterEditor.checking.value ? "Checking types\u2026" : "Fix the problems first"
12618
13552
  }
12619
13553
  ]
12620
13554
  }
@@ -12635,6 +13569,7 @@ function createEditor(options) {
12635
13569
  ),
12636
13570
  autosave ? saveAsDialog(document2) : void 0,
12637
13571
  autosave ? extractDialog({ path: extractPath, error: extractError }) : void 0,
13572
+ parameterEditor.dialog(),
12638
13573
  fieldDialog(),
12639
13574
  iconDialog(),
12640
13575
  embedDialog({
@@ -12753,27 +13688,22 @@ function createEditor(options) {
12753
13688
  size: inspectorSize.value,
12754
13689
  resizable: { min: 240, max: 480 },
12755
13690
  collapsed: inspectorCollapsed.value,
13691
+ overlaid: inspectorOverlay.value,
12756
13692
  toolbar: {
12757
13693
  label: "Inspector",
12758
- toggle: { action: INSPECTOR_TOGGLE, name: "Inspector" }
13694
+ // KF-9H30XE: as an overlay, the toggle names its return.
13695
+ toggle: {
13696
+ action: INSPECTOR_TOGGLE,
13697
+ name: "Inspector",
13698
+ overlayLabel: "Preview"
13699
+ }
12759
13700
  },
12760
13701
  // KF-Z9S029: an object's form pushes onto the Inspector.
12761
13702
  navStack: {
12762
13703
  id: INSPECTOR_STACK,
12763
13704
  label: "Inspector",
12764
13705
  toolbarConfig: { titleSize: "default" },
12765
- views: [
12766
- {
12767
- key: "inspector",
12768
- toolbar: {
12769
- title: "Inspector",
12770
- trailing: nodeActions(document2)
12771
- },
12772
- pane: INSPECTOR_PANE,
12773
- ...inspector(document2)
12774
- },
12775
- ...fieldViews()
12776
- ]
13706
+ views: inspectorViews(document2)
12777
13707
  }
12778
13708
  }
12779
13709
  }
@@ -12788,6 +13718,19 @@ function createEditor(options) {
12788
13718
  dragChip()
12789
13719
  ] });
12790
13720
  };
13721
+ const inspectorViews = (document2) => {
13722
+ const { pages = [], ...body } = inspector(document2);
13723
+ return [
13724
+ {
13725
+ key: "inspector",
13726
+ toolbar: { title: "Inspector", trailing: nodeActions(document2) },
13727
+ pane: INSPECTOR_PANE,
13728
+ ...body
13729
+ },
13730
+ ...pages,
13731
+ ...fieldViews()
13732
+ ];
13733
+ };
12791
13734
  const placeHighlight = (root) => {
12792
13735
  const canvas2 = root.querySelector(hook(HOOK.canvas));
12793
13736
  const highlight = canvas2?.querySelector(
@@ -12819,14 +13762,29 @@ function createEditor(options) {
12819
13762
  highlight.style.height = `${Math.max(bottom - top, 0)}px`;
12820
13763
  };
12821
13764
  const exportAs = (kind) => {
12822
- const result = exportModule(doc.value, viewCatalog, kind, resolveView);
12823
- lastExport.value = {
12824
- contract: result.contract,
12825
- report: describeExport(result.contract, lastExport.value?.contract)
13765
+ const finish = (document2) => {
13766
+ if (!document2) return;
13767
+ const result = exportModule(
13768
+ document2,
13769
+ viewCatalog,
13770
+ kind,
13771
+ resolveView,
13772
+ documentPath()
13773
+ );
13774
+ lastExport.value = {
13775
+ contract: result.contract,
13776
+ report: describeExport(result.contract, lastExport.value?.contract)
13777
+ };
13778
+ (options.save ?? download)(result.fileName, result.code);
12826
13779
  };
12827
- (options.save ?? download)(result.fileName, result.code);
13780
+ if (Object.values(doc.peek().params ?? {}).some(
13781
+ (param) => param.type.typescript
13782
+ ))
13783
+ return parameterEditor.validateNow().then(finish);
13784
+ return finish(doc.peek());
12828
13785
  };
12829
13786
  const discardInspectorDrafts = () => {
13787
+ parameterEditor.close();
12830
13788
  const stack = wired?.querySelector(`#${INSPECTOR_STACK}`);
12831
13789
  if (stack) discardDrafts(stack);
12832
13790
  const params = wired?.querySelector("[data-editor-document-params]");
@@ -12866,17 +13824,17 @@ function createEditor(options) {
12866
13824
  if (delta < 0 ? movable.up : movable.down)
12867
13825
  commit(moveNode(doc.value, id, delta));
12868
13826
  };
12869
- const editProp = (field, raw4 = controlValue(field)) => {
13827
+ const editProp = (field, raw5 = controlValue(field)) => {
12870
13828
  const id = selectedNodeId();
12871
13829
  const name = field.dataset.editorProp;
12872
13830
  const kind = field.dataset.editorKind;
12873
13831
  if (!id) return;
12874
13832
  if (kind === "size")
12875
- customSize.value = raw4 === CUSTOM_SIZE ? `${id} ${name}` : "";
13833
+ customSize.value = raw5 === CUSTOM_SIZE ? `${id} ${name}` : "";
12876
13834
  const node = findNode(doc.value, id).node;
12877
13835
  const prop = propsEntryOf(node).props.find((item) => item.name === name);
12878
13836
  if (kind === "value-choices") {
12879
- const picked = JSON.parse(String(raw4)).map(
13837
+ const picked = JSON.parse(String(raw5)).map(
12880
13838
  (item) => JSON.parse(item)
12881
13839
  );
12882
13840
  if (JSON.stringify(node.props?.[name]) !== JSON.stringify(picked))
@@ -12884,12 +13842,12 @@ function createEditor(options) {
12884
13842
  return;
12885
13843
  }
12886
13844
  if (kind === "value-choice") {
12887
- const picked = raw4 ? JSON.parse(String(raw4)) : void 0;
13845
+ const picked = raw5 ? JSON.parse(String(raw5)) : void 0;
12888
13846
  if (JSON.stringify(node.props?.[name]) !== JSON.stringify(picked))
12889
13847
  commit(setProp(doc.value, id, name, picked));
12890
13848
  return;
12891
13849
  }
12892
- const result = valueFromControl(kind, raw4, prop.cssValue?.helpers, {
13850
+ const result = valueFromControl(kind, raw5, prop.cssValue?.helpers, {
12893
13851
  type: prop.type,
12894
13852
  definitions: definitionsOf(node.type),
12895
13853
  // A typed choice's new member names its slots and keeps the fields it
@@ -12945,23 +13903,23 @@ function createEditor(options) {
12945
13903
  );
12946
13904
  return true;
12947
13905
  };
12948
- const editField = (field, raw4 = controlValue(field)) => {
13906
+ const editField = (field, raw5 = controlValue(field)) => {
12949
13907
  const id = selectedNodeId();
12950
13908
  const place = JSON.parse(field.dataset.editorField);
12951
13909
  const kind = field.dataset.editorKind;
12952
13910
  const key = placeKey2(place);
12953
13911
  if (kind === "size")
12954
- customSize.value = raw4 === CUSTOM_SIZE ? `${id} ${key}` : "";
12955
- if (kind === "size" && raw4 === CUSTOM_SIZE) return;
13912
+ customSize.value = raw5 === CUSTOM_SIZE ? `${id} ${key}` : "";
13913
+ if (kind === "size" && raw5 === CUSTOM_SIZE) return;
12956
13914
  const { definitions, type, declared, items, value } = fieldContext(
12957
13915
  findNode(doc.value, id).node,
12958
13916
  place
12959
13917
  );
12960
- const result = kind === "choice" ? valueFromControl(kind, raw4, void 0, {
13918
+ const result = kind === "choice" ? valueFromControl(kind, raw5, void 0, {
12961
13919
  type: items ?? declared,
12962
13920
  definitions,
12963
13921
  current: value
12964
- }) : valueFromControl(kind, raw4, void 0, type && { type, definitions });
13922
+ }) : valueFromControl(kind, raw5, void 0, type && { type, definitions });
12965
13923
  if ("error" in result) {
12966
13924
  fieldErrors.value = { ...fieldErrors.value, [key]: result.error };
12967
13925
  return;
@@ -13047,20 +14005,11 @@ function createEditor(options) {
13047
14005
  newNodeId,
13048
14006
  slotNamer(usedSlots(doc.value))
13049
14007
  );
13050
- const thumbnails = /* @__PURE__ */ new Map();
13051
- const thumbnailOf = (key) => {
13052
- if (!thumbnails.has(key)) {
13053
- const document2 = withCatalog(
13054
- { ...emptyDocument(), root: asRoot(seededNode(key)) },
13055
- key
13056
- );
13057
- thumbnails.set(
13058
- key,
13059
- canvasContent(document2, [], void 0, void 0, true).toString()
13060
- );
13061
- }
13062
- return thumbnails.get(key);
13063
- };
14008
+ const thumbnails = createLibraryThumbnails(
14009
+ catalog,
14010
+ catalog.libraryPreviews,
14011
+ (key) => withCatalog({ ...emptyDocument(), root: asRoot(seededNode(key)) }, key)
14012
+ );
13064
14013
  const embedPlace = (seeded) => {
13065
14014
  const options2 = zonesOf(seeded);
13066
14015
  const main = options2.find(
@@ -13129,7 +14078,7 @@ function createEditor(options) {
13129
14078
  bindProp,
13130
14079
  addZone,
13131
14080
  addComponent,
13132
- promoteProp
14081
+ fieldProblems
13133
14082
  });
13134
14083
  const openEmbedDialog = (root) => {
13135
14084
  embedTarget.value = selectedNodeId();
@@ -13237,17 +14186,11 @@ function createEditor(options) {
13237
14186
  () => wired?.querySelector(`${hook(HOOK.name)} input`)?.focus()
13238
14187
  );
13239
14188
  };
13240
- const promote = (chosen) => {
14189
+ const promote = (name) => {
13241
14190
  const id = selectedNodeId();
13242
- if (!id) return;
13243
14191
  const node = findNode(doc.value, id).node;
13244
- const component = propsByKey.get(node.type);
13245
- const picker = document.querySelector(hook(HOOK.promote));
13246
- const name = chosen ?? (picker ? String(controlValue(picker)) : promoteProp.value);
13247
- const prop = component?.props.find((item) => item.name === name);
13248
- const type = prop && (paramTypeFor(prop.type) ?? appParamFor(node.type, prop, definitionsOf(node.type)));
13249
- const current = node.props?.[name];
13250
- if (!prop || !type || isBinding(current)) return;
14192
+ const prop = propsByKey.get(node.type).props.find((item) => item.name === name);
14193
+ const type = paramTypeFor(prop.type) ?? appParamFor(node.type, prop, definitionsOf(node.type));
13251
14194
  const base = `${node.name ?? "node"}${name[0].toUpperCase()}${name.slice(1)}`;
13252
14195
  let param = base;
13253
14196
  for (let index = 2; doc.value.params && param in doc.value.params; index += 1)
@@ -13258,10 +14201,10 @@ function createEditor(options) {
13258
14201
  const promoteField = (at) => {
13259
14202
  const node = findNode(doc.value, selectedNodeId()).node;
13260
14203
  const { type, definitions } = fieldContext(node, at);
13261
- const paramType2 = paramTypeFor(
14204
+ const paramType = paramTypeFor(
13262
14205
  resolveType(type, definitions)
13263
14206
  );
13264
- if (!paramType2 || isBinding(valueAt(node.props?.[at.prop], at.path)))
14207
+ if (!paramType || isBinding(valueAt(node.props?.[at.prop], at.path)))
13265
14208
  return;
13266
14209
  const words2 = [
13267
14210
  at.prop,
@@ -13278,7 +14221,7 @@ function createEditor(options) {
13278
14221
  node.id,
13279
14222
  at.prop,
13280
14223
  param,
13281
- paramType2,
14224
+ paramType,
13282
14225
  at.path
13283
14226
  );
13284
14227
  commit(result.document);
@@ -13601,6 +14544,7 @@ function createEditor(options) {
13601
14544
  root.addEventListener("toggle", answered, true);
13602
14545
  const stops = [
13603
14546
  stopPopover,
14547
+ wireSearchFields(surface, { collapsible: false }),
13604
14548
  on2(doc2, "keydown", (event) => {
13605
14549
  const key = event;
13606
14550
  if (playing.value || key.key.toLowerCase() !== "l" || !key.shiftKey || key.altKey || !(key.metaKey || key.ctrlKey))
@@ -13674,20 +14618,6 @@ function createEditor(options) {
13674
14618
  };
13675
14619
  };
13676
14620
  const wireInspectorChanges = (root) => [
13677
- delegate(root, "change", `[${PARAM_NEW}]`, (_event, field) => {
13678
- const value = String(controlValue(field));
13679
- if (field.getAttribute(PARAM_NEW) === "name") newParamName.value = value;
13680
- else newParamKind.value = value;
13681
- }),
13682
- delegate(
13683
- root,
13684
- "change",
13685
- `[${PARAM_EDIT}]`,
13686
- (_event, field) => {
13687
- const at = JSON.parse(field.getAttribute(PARAM_EDIT));
13688
- editParam(at, controlValue(field));
13689
- }
13690
- ),
13691
14621
  delegate(
13692
14622
  root,
13693
14623
  "change",
@@ -13706,9 +14636,9 @@ function createEditor(options) {
13706
14636
  hook(HOOK.attribute),
13707
14637
  (_event, field) => {
13708
14638
  const index = Number(field.dataset.editorAttribute);
13709
- const raw4 = String(controlValue(field));
14639
+ const raw5 = String(controlValue(field));
13710
14640
  editDataAttribute(
13711
- field.dataset.editorAttributePart === "name" ? { kind: "name", index, name: raw4.trim() } : { kind: "value", index, value: raw4 }
14641
+ field.dataset.editorAttributePart === "name" ? { kind: "name", index, name: raw5.trim() } : { kind: "value", index, value: raw5 }
13712
14642
  );
13713
14643
  }
13714
14644
  ),
@@ -13833,17 +14763,15 @@ function createEditor(options) {
13833
14763
  )
13834
14764
  );
13835
14765
  }
13836
- ),
13837
- delegate(
13838
- root,
13839
- "change",
13840
- hook(HOOK.promote),
13841
- (_event, field) => {
13842
- promoteProp.value = String(controlValue(field));
13843
- }
13844
14766
  )
13845
14767
  ];
13846
14768
  const wireSearch = (root) => [
14769
+ // Picker dialogs own their search mechanics. The Library owns its own
14770
+ // helper, while play-stage and TagField searches have separate wiring.
14771
+ ...[EMBED_DIALOG, INSERT_DOCUMENT_DIALOG, ICON_DIALOG].flatMap((id) => {
14772
+ const dialog = root.querySelector(`#${id}`);
14773
+ return dialog ? [wireSearchFields(dialog, { collapsible: false })] : [];
14774
+ }),
13847
14775
  delegate(
13848
14776
  root,
13849
14777
  "input",
@@ -13868,6 +14796,14 @@ function createEditor(options) {
13868
14796
  iconQuery.value = readSearchField(editor).query;
13869
14797
  }
13870
14798
  ),
14799
+ delegate(
14800
+ root,
14801
+ "input",
14802
+ hook(HOOK.propertiesSearch),
14803
+ (_event, editor) => {
14804
+ propertiesQuery.value = readSearchField(editor).query;
14805
+ }
14806
+ ),
13871
14807
  delegate(
13872
14808
  root,
13873
14809
  "input",
@@ -13901,9 +14837,6 @@ function createEditor(options) {
13901
14837
  if (!isDocumentFolderId(id))
13902
14838
  void insertFromLibrary(root, id, event.altKey);
13903
14839
  },
13904
- [DOCUMENT_BACK_ACTION]: () => {
13905
- documentLibraryPath.value = documentLibraryPath.peek().slice(0, -1);
13906
- },
13907
14840
  [DOCUMENT_TOGGLE_ACTION]: (_event, target) => {
13908
14841
  const id = target.dataset.itemId;
13909
14842
  const next = new Set(collapsedDocumentFolders.peek());
@@ -13975,6 +14908,7 @@ function createEditor(options) {
13975
14908
  addZone.value = zone;
13976
14909
  addComponent.value = "";
13977
14910
  inspectorArea.value = "children";
14911
+ inspectorGroup.value = [];
13978
14912
  }
13979
14913
  },
13980
14914
  [REPLACE_ROOT_ACTION]: () => replaceRootWith(),
@@ -13994,6 +14928,18 @@ function createEditor(options) {
13994
14928
  )
13995
14929
  ),
13996
14930
  [FIELD_BACK_ACTION]: fieldBack,
14931
+ [INSPECTOR_GROUP_ACTION]: (_event, target) => {
14932
+ const path = target.closest(hook(HOOK.group)).dataset.editorPropGroup.split("/");
14933
+ if (path[0] === ALL_PROPERTIES) {
14934
+ propertiesQuery.value = "";
14935
+ propertiesQueryRevision.value += 1;
14936
+ }
14937
+ inspectorGroup.value = path;
14938
+ },
14939
+ [PROPERTIES_CLEAR_ACTION]: () => {
14940
+ propertiesQuery.value = "";
14941
+ propertiesQueryRevision.value += 1;
14942
+ },
13997
14943
  [FIELD_ADD_ITEM_ACTION]: (_event, target) => {
13998
14944
  const place = JSON.parse(target.dataset.editorStep);
13999
14945
  const { definitions, type, value } = fieldContext(
@@ -14207,7 +15153,6 @@ function createEditor(options) {
14207
15153
  // KF-STBQBG: the moved design stays selected.
14208
15154
  [MOVE_ROW_DESIGN_EARLIER_ACTION]: () => commit(moveRowDesign(doc.value, selectedNodeId(), -1)),
14209
15155
  [MOVE_ROW_DESIGN_LATER_ACTION]: () => commit(moveRowDesign(doc.value, selectedNodeId(), 1)),
14210
- [PROMOTE_ACTION]: () => promote(),
14211
15156
  [PROMOTE_PROP_ACTION]: (_event, target) => promote(target.dataset.editorPromoteProp),
14212
15157
  [PROMOTE_FIELD_ACTION]: (_event, target) => promoteField(
14213
15158
  JSON.parse(target.dataset.editorPromoteField)
@@ -14235,37 +15180,6 @@ function createEditor(options) {
14235
15180
  // KF-QSSTMX: a new empty document; with storage it is a new draft,
14236
15181
  // and the previous document stays in its file.
14237
15182
  [NEW_ACTION]: () => load(emptyDocument()),
14238
- [CREATE_PARAM_ACTION]: () => {
14239
- const result = createParam(
14240
- doc.value,
14241
- viewCatalog,
14242
- newParamName.value.trim(),
14243
- paramType(newParamKind.value)
14244
- );
14245
- if ("error" in result)
14246
- fieldErrors.value = { "#doc-param-new": result.error };
14247
- else {
14248
- commit(result.document);
14249
- newParamName.value = "";
14250
- }
14251
- },
14252
- [REMOVE_PARAM_ACTION]: (_event, target) => {
14253
- const name = target.getAttribute(PARAM_REMOVE);
14254
- if (!name) return;
14255
- const result = removeParam(doc.value, viewCatalog, name);
14256
- if ("error" in result) paramError(name, result.error);
14257
- else commit(result.document);
14258
- },
14259
- [ADD_PARAM_FIELD_ACTION]: (_event, target) => {
14260
- const field = target.getAttribute(PARAM_FIELD);
14261
- if (field) addParamField(JSON.parse(field).name);
14262
- },
14263
- [REMOVE_PARAM_FIELD_ACTION]: (_event, target) => {
14264
- const field = target.getAttribute(PARAM_FIELD);
14265
- if (!field) return;
14266
- const { name, index } = JSON.parse(field);
14267
- removeParamField(name, index);
14268
- },
14269
15183
  [DOCUMENT_TAB_ACTION]: (_event, target) => {
14270
15184
  documentArea.value = target.dataset.tabId.slice(
14271
15185
  DOCUMENT_AREAS.length + 1
@@ -14416,7 +15330,14 @@ function createEditor(options) {
14416
15330
  id: WORKBENCH_ID,
14417
15331
  panels: {
14418
15332
  leftRail: { size: documentSize, collapsed: documentCollapsed },
14419
- rightRail: { size: inspectorSize, collapsed: inspectorCollapsed }
15333
+ // KF-EGNN3J: narrowing keeps the Inspector open while it is being
15334
+ // edited, as the focused overlay, rather than taking it away.
15335
+ rightRail: {
15336
+ size: inspectorSize,
15337
+ collapsed: inspectorCollapsed,
15338
+ overlay: inspectorOverlay,
15339
+ keepFocusedOpen: true
15340
+ }
14420
15341
  }
14421
15342
  }),
14422
15343
  ...wireInspectorChanges(root),
@@ -14535,9 +15456,9 @@ function createEditor(options) {
14535
15456
  const host = [
14536
15457
  ...scope.querySelectorAll("[data-tag-field-id]")
14537
15458
  ].find((field) => field.dataset.tagFieldId === id);
14538
- const raw4 = JSON.stringify(tags);
14539
- if (host.dataset.editorField) editField(host, raw4);
14540
- else editProp(host, raw4);
15459
+ const raw5 = JSON.stringify(tags);
15460
+ if (host.dataset.editorField) editField(host, raw5);
15461
+ else editProp(host, raw5);
14541
15462
  }
14542
15463
  })
14543
15464
  ),
@@ -14582,8 +15503,12 @@ function createEditor(options) {
14582
15503
  ),
14583
15504
  // KF-Z9S029: Back pops a field editor's pushed view; closing its
14584
15505
  // dialog closes the editor.
15506
+ // KF-QWDPM3: below the field steps, Back closes a Properties page.
14585
15507
  wireNavStack(root.querySelector(`#${INSPECTOR_STACK}`), {
14586
- onBack: fieldBack
15508
+ onBack: () => {
15509
+ if (activeField()?.container === "subview") fieldBack();
15510
+ else inspectorGroup.value = inspectorGroup.value.slice(0, -1);
15511
+ }
14587
15512
  }),
14588
15513
  (() => {
14589
15514
  const closed = (event) => {
@@ -14615,7 +15540,10 @@ function createEditor(options) {
14615
15540
  wireTabBars(root, { onReorder: () => {
14616
15541
  } }),
14617
15542
  // KF-JC7WTW: the palette grid's tiles show their components as added.
14618
- wirePaletteThumbnails(root, { htmlOf: thumbnailOf }),
15543
+ wirePaletteThumbnails(root, {
15544
+ htmlOf: thumbnails.htmlOf,
15545
+ fitOf: thumbnails.fitOf
15546
+ }),
14619
15547
  // KF-67K2VP: a rail's pinned tab strip shows its divider once its
14620
15548
  // area scrolls under it.
14621
15549
  wireScrollDividers(root),
@@ -14656,6 +15584,7 @@ function createEditor(options) {
14656
15584
  });
14657
15585
  })()
14658
15586
  ];
15587
+ stops.push(parameterEditor.wire(root));
14659
15588
  if (autosave) stops.push(...wireAutosave(root));
14660
15589
  stops.push(wirePlay(root), wireLibrary(root));
14661
15590
  const observer = new (realmOf(root)).ResizeObserver(
@@ -14670,6 +15599,6 @@ function createEditor(options) {
14670
15599
  return { render, wire, document: doc, selection, loadError };
14671
15600
  }
14672
15601
 
14673
- export { EDITOR_FILE_API, EDITOR_LIST_API, SHIPPED_DEVICE_PRESETS, WORKBENCH_ID, componentMap, createEditor, createEditorCatalog, devServerStorage, emptyDocument };
15602
+ export { EDITOR_FILE_API, EDITOR_LIST_API, SHIPPED_DEVICE_PRESETS, WORKBENCH_ID, componentMap, createEditor, createEditorCatalog, defineLibraryPreviews, devServerStorage, devServerTypeService, emptyDocument };
14674
15603
 
14675
15604
  //# sourceMappingURL=editor.js.map