@kerfjs/ui 5.0.0-beta.126 → 5.0.0-beta.128

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 (51) hide show
  1. package/ai/component-props.json +20 -0
  2. package/ai/public-api-signatures-v1.md +7 -5
  3. package/ai/webawesome-jsx-signatures-v1.md +1 -1
  4. package/dist/browser/editor.js +3 -1
  5. package/dist/{chunk-NR3ZO4LK.js → chunk-7U65KLDL.js} +1 -1
  6. package/dist/chunk-7U65KLDL.js.map +1 -0
  7. package/dist/chunk-BMOZSNDU.js +133 -0
  8. package/dist/chunk-BMOZSNDU.js.map +1 -0
  9. package/dist/chunk-GHV36C6I.js +94 -0
  10. package/dist/chunk-GHV36C6I.js.map +1 -0
  11. package/dist/{chunk-Z3BT2SZE.js → chunk-GQUDCWOD.js} +8 -2
  12. package/dist/chunk-GQUDCWOD.js.map +1 -0
  13. package/dist/{chunk-3SCGTP5O.js → chunk-HD7ZLISK.js} +137 -11
  14. package/dist/chunk-HD7ZLISK.js.map +1 -0
  15. package/dist/column-explorer.d.ts +1 -1
  16. package/dist/column-explorer.js +16 -138
  17. package/dist/column-explorer.js.map +1 -1
  18. package/dist/editor.js +838 -115
  19. package/dist/editor.js.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/list-detail-dialog.js +1 -1
  22. package/dist/styles/components/surfaces/editor-frame/editor-frame.css +8 -1
  23. package/dist/styles/components/surfaces/surface-scaffold/surface-scaffold.css +32 -0
  24. package/dist/styles/editor/editor.css +23 -0
  25. package/dist/styles/editor-frame.css +8 -1
  26. package/dist/styles/surface-scaffold.css +32 -0
  27. package/dist/surface-scaffold.d.ts +3 -1
  28. package/dist/surface-scaffold.js +1 -1
  29. package/dist/tree-list.d.ts +2 -2
  30. package/dist/tree-list.js +2 -2
  31. package/dist/{tree-rows-eHnnGLGM.d.ts → tree-rows-Bms5QJvG.d.ts} +3 -0
  32. package/dist/wire-column-explorer.js +1 -92
  33. package/dist/wire-column-explorer.js.map +1 -1
  34. package/dist/workbench-dialog.js +1 -1
  35. package/docs/view.md +19 -0
  36. package/package.json +4 -2
  37. package/ux-demo/recipes/app-shell.tsx +48 -141
  38. package/ux-demo/recipes/collapsible-sidebar.tsx +43 -169
  39. package/ux-demo/recipes/compact-toolbar.tsx +22 -114
  40. package/ux-demo/recipes/composer-form.tsx +14 -104
  41. package/ux-demo/recipes/list-detail-dialog.tsx +38 -84
  42. package/ux-demo/recipes/list-workspace-states.tsx +29 -152
  43. package/ux-demo/recipes/loading-inspector.tsx +30 -174
  44. package/ux-demo/recipes/media-detail.tsx +29 -146
  45. package/ux-demo/recipes/navigation-sidebar.tsx +24 -113
  46. package/ux-demo/recipes/navigation-stack.tsx +7 -43
  47. package/ux-demo/recipes/workspace-header.tsx +2 -66
  48. package/view/generate.mjs +34 -14
  49. package/dist/chunk-3SCGTP5O.js.map +0 -1
  50. package/dist/chunk-NR3ZO4LK.js.map +0 -1
  51. package/dist/chunk-Z3BT2SZE.js.map +0 -1
package/dist/editor.js CHANGED
@@ -8,7 +8,8 @@ import { wireNavStack } from './chunk-I2K4OQKB.js';
8
8
  import { wireWorkbench } from './chunk-OHT2AXER.js';
9
9
  import { wireColorFields } from './chunk-3K5V3ZSD.js';
10
10
  import { wireColorPickers } from './chunk-YE6KCAIN.js';
11
- import { TreeList } from './chunk-Z3BT2SZE.js';
11
+ import { wireColumnExplorer } from './chunk-GHV36C6I.js';
12
+ import { TreeList } from './chunk-GQUDCWOD.js';
12
13
  import { TagField } from './chunk-73LC3JAL.js';
13
14
  import { wireSummaryRows } from './chunk-CKPI4WIN.js';
14
15
  import { wireTabBars, reorderTabs } from './chunk-3ZWYGGEC.js';
@@ -38,7 +39,7 @@ import { isApplePlatform } from './chunk-GXSX6Q6O.js';
38
39
  import { Grid } from './chunk-FR5G77K5.js';
39
40
 
40
41
  import { ListActionRow } from './chunk-RHMY45DK.js';
41
- import { DialogSurface, wirePinnablePopover, PinnablePopoverSurface, isPopoverPinned } from './chunk-3SCGTP5O.js';
42
+ import { DialogSurface, wirePinnablePopover, PinnablePopoverSurface, isPopoverPinned } from './chunk-HD7ZLISK.js';
42
43
  import { openDialog, closeDialog } from './chunk-UQ4FRQ6M.js';
43
44
 
44
45
  import { EmptyState } from './chunk-FNJA4S6J.js';
@@ -48,6 +49,8 @@ import { deviceClass } from './chunk-WCMGPAY2.js';
48
49
 
49
50
 
50
51
 
52
+ import { ColumnExplorer } from './chunk-BMOZSNDU.js';
53
+ import { treeListPath } from './chunk-7U65KLDL.js';
51
54
 
52
55
  import { openAnchoredSurface } from './chunk-COMEWURO.js';
53
56
  import { realmOf } from './chunk-IFDTSVE6.js';
@@ -99,7 +102,7 @@ import { px } from './chunk-IQSRHXZR.js';
99
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';
100
103
  import { signal, computed, effect, delegate, mount, batch, raw } from 'kerfjs';
101
104
  import { delegateActions } from 'kerfjs/actions';
102
- 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, Activity, BadgeCheck, LoaderCircle, FaceSlightlySmiling, Component, FileText, Ban } from 'lucide';
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';
103
106
  import { jsx, jsxs, Fragment } from 'kerfjs/jsx-runtime';
104
107
 
105
108
  var EDITOR_FILE_API = "/__kerf-ui-editor/api/file";
@@ -1677,6 +1680,8 @@ function renameParam(document2, from, to) {
1677
1680
  if (value === null || typeof value !== "object") return value;
1678
1681
  const record = value;
1679
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)}` };
1680
1685
  return Object.fromEntries(
1681
1686
  Object.entries(record).map(([key, item]) => [key, follow(item)])
1682
1687
  );
@@ -3875,13 +3880,322 @@ function slotEditor(document2, catalog, address) {
3875
3880
  ] }) : void 0
3876
3881
  ] });
3877
3882
  }
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
+ }
3878
4193
 
3879
4194
  // src/editor/shell-names.ts
3880
4195
  var OUTLINE_ACTION = "editor-select-node";
3881
4196
  var OUTLINE_TOGGLE_ACTION = "editor-toggle-node";
3882
4197
  var PALETTE_ACTION = "editor-show-component";
3883
4198
  var PALETTE_CLEAR_ACTION = "editor-clear-palette-filter";
3884
- var PALETTE_DOCUMENT_ACTION = "editor-insert-library-document";
3885
4199
  var PROBLEM_ACTION = "editor-select-problem";
3886
4200
  var NEW_ACTION = "editor-new";
3887
4201
  var PLAY_ACTION = "editor-play";
@@ -4193,7 +4507,7 @@ function extractProblem(document2, id) {
4193
4507
  var readKey = (read) => read.kind === "param" ? `param ${read.name}` : `item ${read.as}${read.field === void 0 ? "" : `.${read.field}`}`;
4194
4508
  var fieldOf = (type, name) => type?.kind === "object" ? type.props?.find((prop) => prop.name === name)?.type : void 0;
4195
4509
  var optionalField = (type, name) => type.props.find((prop) => prop.name === name).required !== true;
4196
- var CAMEL3 = /^[a-z][A-Za-z0-9]*$/;
4510
+ var CAMEL4 = /^[a-z][A-Za-z0-9]*$/;
4197
4511
  var RESERVED = /* @__PURE__ */ new Set(["inputs", "slots", "each", "handlers"]);
4198
4512
  function mapValue(value, local, reference) {
4199
4513
  if (Array.isArray(value))
@@ -4379,11 +4693,11 @@ function extractToDocument(document2, id, options) {
4379
4693
  continue;
4380
4694
  }
4381
4695
  const base = read.field ?? read.as;
4382
- const camel2 = CAMEL3.test(base) ? base : base.replace(
4696
+ const camel2 = CAMEL4.test(base) ? base : base.replace(
4383
4697
  /[^A-Za-z0-9]+(.)?/g,
4384
4698
  (_, next2 = "") => String(next2).toUpperCase()
4385
4699
  );
4386
- const own = CAMEL3.test(camel2) ? camel2 : `${read.as}Value`;
4700
+ const own = CAMEL4.test(camel2) ? camel2 : `${read.as}Value`;
4387
4701
  let name = taken.has(own) ? `${read.as}${own[0].toUpperCase()}${own.slice(1)}` : own;
4388
4702
  for (let count = 2; taken.has(name); count += 1) name = `${own}${count}`;
4389
4703
  const itemType = items.get(read.as);
@@ -5998,9 +6312,6 @@ function libraryDocuments(paths, query) {
5998
6312
  function documentName(path) {
5999
6313
  return path.slice(path.lastIndexOf("/") + 1);
6000
6314
  }
6001
- function documentFolder(path) {
6002
- return path.slice(0, path.lastIndexOf("/") + 1) || "./";
6003
- }
6004
6315
  function insertDocumentDialog({
6005
6316
  listed,
6006
6317
  files: filesSignal,
@@ -7210,6 +7521,12 @@ function createLibraryDrag(ctx, deps) {
7210
7521
  };
7211
7522
  }
7212
7523
  var PALETTE_VIEW_ACTION = "editor-palette-view";
7524
+ var LIBRARY_MODE_ACTION = "editor-library-mode";
7525
+ var DOCUMENT_VIEW_ACTION = "editor-document-view";
7526
+ var DOCUMENT_ROW_ACTION = "editor-document-row";
7527
+ var DOCUMENT_TOGGLE_ACTION = "editor-document-toggle";
7528
+ var DOCUMENT_BACK_ACTION = "editor-document-back";
7529
+ var DOCUMENT_VIEW_KEY = "kerf-ui-editor:document-view";
7213
7530
  var PALETTE_VIEW_KEY = "kerf-ui-editor:palette-view";
7214
7531
  var PALETTE_ICONS = {
7215
7532
  "@kerfjs/ui:lucide-icon": FaceSlightlySmiling,
@@ -7230,6 +7547,19 @@ function rememberPaletteView(view) {
7230
7547
  } catch {
7231
7548
  }
7232
7549
  }
7550
+ function rememberedDocumentView() {
7551
+ try {
7552
+ return globalThis.localStorage?.getItem(DOCUMENT_VIEW_KEY) === "columns" ? "columns" : "tree";
7553
+ } catch {
7554
+ return "tree";
7555
+ }
7556
+ }
7557
+ function rememberDocumentView(view) {
7558
+ try {
7559
+ globalThis.localStorage?.setItem(DOCUMENT_VIEW_KEY, view);
7560
+ } catch {
7561
+ }
7562
+ }
7233
7563
  var LIBRARY_ID = "editor-library";
7234
7564
  var LIBRARY_KEY = "kerf-ui-editor:library";
7235
7565
  function rememberedLibrary() {
@@ -7255,6 +7585,45 @@ function rememberLibrary({ pinned, placement }) {
7255
7585
  }
7256
7586
  }
7257
7587
 
7588
+ // src/editor/model/library-document-tree.ts
7589
+ var documentFolderId = (path) => `folder:${path}`;
7590
+ var isDocumentFolderId = (id) => id.startsWith("folder:") && id.endsWith("/");
7591
+ function libraryDocumentTree(paths) {
7592
+ const root = { path: "", folders: /* @__PURE__ */ new Map(), files: [] };
7593
+ for (const path of paths) {
7594
+ const parts = path.split("/");
7595
+ let folder = root;
7596
+ for (const name of parts.slice(0, -1)) {
7597
+ if (!name) continue;
7598
+ let child = folder.folders.get(name);
7599
+ if (!child) {
7600
+ child = {
7601
+ name,
7602
+ path: `${folder.path}${name}/`,
7603
+ folders: /* @__PURE__ */ new Map(),
7604
+ files: []
7605
+ };
7606
+ folder.folders.set(name, child);
7607
+ }
7608
+ folder = child;
7609
+ }
7610
+ folder.files.push(path);
7611
+ }
7612
+ const rows = (folder) => [
7613
+ ...[...folder.folders.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => ({
7614
+ id: documentFolderId(child.path),
7615
+ label: child.name,
7616
+ children: rows(child)
7617
+ })),
7618
+ ...folder.files.sort((a, b) => documentName(a).localeCompare(documentName(b))).map((path) => ({
7619
+ id: path,
7620
+ label: documentName(path),
7621
+ rootAttributes: { "data-editor-palette-document": path }
7622
+ }))
7623
+ ];
7624
+ return rows(root);
7625
+ }
7626
+
7258
7627
  // src/editor/palette-schematics.ts
7259
7628
  var WIDTH = 96;
7260
7629
  var HEIGHT = 72;
@@ -7493,6 +7862,10 @@ function createLibraryPopover(ctx, state) {
7493
7862
  paletteFilter,
7494
7863
  paletteFilterRevision,
7495
7864
  paletteView,
7865
+ libraryMode,
7866
+ documentView,
7867
+ documentPath,
7868
+ collapsedDocumentFolders,
7496
7869
  libraryFiles,
7497
7870
  libraryError
7498
7871
  } = state;
@@ -7505,93 +7878,107 @@ function createLibraryPopover(ctx, state) {
7505
7878
  })).filter((group) => group.items.length);
7506
7879
  };
7507
7880
  const paletteSelected = (key) => selection.value?.kind === "component" && selection.value.key === key;
7508
- const palette = (groups, documents) => /* @__PURE__ */ jsxs(List, { gap: "m", children: [
7509
- groups.map((group) => /* @__PURE__ */ jsxs(List, { children: [
7510
- /* @__PURE__ */ jsx(ListHeader, { label: group.category }),
7511
- paletteView.value === "grid" ? /* @__PURE__ */ jsx(Grid, { minColumnWidth: px(96), autoFill: true, gap: "xs", children: group.items.map((item) => /* @__PURE__ */ jsxs(
7512
- ContentItem,
7513
- {
7514
- interactive: true,
7515
- action: PALETTE_ACTION,
7516
- itemId: item.key,
7517
- selectionMode: "single",
7518
- selected: paletteSelected(item.key),
7519
- ariaLabel: item.name,
7520
- title: item.name,
7521
- frame: "framed",
7522
- rootAttributes: {
7523
- [HOOK.palette]: item.key,
7524
- "data-key": item.key
7525
- },
7526
- children: [
7527
- 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(
7528
- LucideIcon,
7529
- {
7530
- icon: PALETTE_ICONS[item.key],
7531
- name: "component"
7532
- }
7533
- ) : raw(paletteSketch(item.key)) }) : /* @__PURE__ */ jsx(
7534
- "div",
7535
- {
7536
- class: "kui-editor__palette-thumb",
7537
- ...{ [HOOK.paletteThumb]: item.key },
7538
- "data-morph-skip": true,
7539
- "aria-hidden": "true",
7540
- inert: true,
7541
- children: /* @__PURE__ */ jsx(LucideIcon, { icon: Component, name: "component" })
7542
- }
7543
- ),
7544
- /* @__PURE__ */ jsx(Text, { variant: "span", size: "compact", maxLines: 1, children: item.name })
7545
- ]
7546
- }
7547
- )) }) : group.items.map((item) => /* @__PURE__ */ jsx(
7548
- ListItem,
7549
- {
7550
- action: PALETTE_ACTION,
7551
- itemId: item.key,
7552
- label: item.name,
7553
- rootAttributes: { [HOOK.palette]: item.key },
7554
- selected: paletteSelected(item.key)
7555
- }
7556
- ))
7557
- ] })),
7558
- documents.length ? libraryDocumentGroup(documents) : void 0
7559
- ] });
7560
- const libraryDocumentGroup = (documents) => /* @__PURE__ */ jsxs(List, { children: [
7561
- /* @__PURE__ */ jsx(ListHeader, { label: LIBRARY_DOCUMENTS }),
7562
- paletteView.value === "grid" ? /* @__PURE__ */ jsx(Grid, { minColumnWidth: px(96), autoFill: true, gap: "xs", children: documents.map((path) => /* @__PURE__ */ jsxs(
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(
7563
7884
  ContentItem,
7564
7885
  {
7565
7886
  interactive: true,
7566
- action: PALETTE_DOCUMENT_ACTION,
7567
- itemId: path,
7568
- ariaLabel: path,
7569
- title: path,
7887
+ action: PALETTE_ACTION,
7888
+ itemId: item.key,
7889
+ selectionMode: "single",
7890
+ selected: paletteSelected(item.key),
7891
+ ariaLabel: item.name,
7892
+ title: item.name,
7570
7893
  frame: "framed",
7571
7894
  rootAttributes: {
7572
- [HOOK.paletteDocument]: path,
7573
- "data-key": `document:${path}`
7895
+ [HOOK.palette]: item.key,
7896
+ "data-key": item.key
7574
7897
  },
7575
7898
  children: [
7576
- /* @__PURE__ */ jsx("div", { class: "kui-editor__palette-thumb", "aria-hidden": "true", children: /* @__PURE__ */ jsx(LucideIcon, { icon: FileText, name: "file-text" }) }),
7577
- /* @__PURE__ */ jsx(Text, { variant: "span", size: "compact", maxLines: 1, children: documentName(path) })
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 })
7578
7917
  ]
7579
7918
  }
7580
- )) }) : documents.map((path) => /* @__PURE__ */ jsx(
7919
+ )) }) : group.items.map((item) => /* @__PURE__ */ jsx(
7581
7920
  ListItem,
7582
7921
  {
7583
- action: PALETTE_DOCUMENT_ACTION,
7584
- label: documentName(path),
7585
- description: documentFolder(path),
7586
- accessibleLabel: path,
7587
- title: path,
7588
- rootAttributes: { [HOOK.paletteDocument]: path }
7922
+ action: PALETTE_ACTION,
7923
+ itemId: item.key,
7924
+ label: item.name,
7925
+ rootAttributes: { [HOOK.palette]: item.key },
7926
+ selected: paletteSelected(item.key)
7589
7927
  }
7590
7928
  ))
7591
- ] });
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"
7955
+ }
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
+ };
7592
7978
  const libraryPopover = () => {
7593
- const groups = paletteMatches();
7594
- const documents = libraryDocuments(libraryFiles.value, paletteFilter.value);
7979
+ const componentsMode = libraryMode.value === "components";
7980
+ const groups = componentsMode ? paletteMatches() : [];
7981
+ const documents = componentsMode ? [] : libraryDocuments(libraryFiles.value, paletteFilter.value);
7595
7982
  return /* @__PURE__ */ jsxs(
7596
7983
  PinnablePopoverSurface,
7597
7984
  {
@@ -7600,7 +7987,8 @@ function createLibraryPopover(ctx, state) {
7600
7987
  size: "small",
7601
7988
  height: px(560),
7602
7989
  bodyLayout: "fill-last",
7603
- headerActions: (
7990
+ resizeFromBottom: true,
7991
+ headerActions: componentsMode ? (
7604
7992
  // KF-JC7WTW: a list of names, or a grid of thumbnails.
7605
7993
  /* @__PURE__ */ jsx(
7606
7994
  SegmentedControl,
@@ -7625,15 +8013,51 @@ function createLibraryPopover(ctx, state) {
7625
8013
  ]
7626
8014
  }
7627
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
+ ]
8037
+ }
7628
8038
  ),
7629
8039
  rootAttributes: { [HOOK.library]: "" },
7630
8040
  children: [
7631
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
+ ),
7632
8056
  /* @__PURE__ */ jsx(
7633
8057
  SearchField,
7634
8058
  {
7635
8059
  id: "editor-palette-filter",
7636
- label: "Filter Components",
8060
+ label: componentsMode ? "Filter Components" : "Filter Documents",
7637
8061
  placeholder: "Filter",
7638
8062
  query: paletteFilter.value,
7639
8063
  revision: paletteFilterRevision.value,
@@ -7652,13 +8076,27 @@ function createLibraryPopover(ctx, state) {
7652
8076
  }
7653
8077
  ) : void 0
7654
8078
  ] }),
7655
- /* @__PURE__ */ jsx(List, { scrollable: true, flex: true, children: groups.length || documents.length ? palette(groups, documents) : /* @__PURE__ */ jsx(
7656
- EmptyState,
8079
+ /* @__PURE__ */ jsx(
8080
+ List,
7657
8081
  {
7658
- title: "No matching components",
7659
- detail: "No component name or category holds that text."
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
+ )
7660
8098
  }
7661
- ) })
8099
+ )
7662
8100
  ]
7663
8101
  }
7664
8102
  );
@@ -7748,24 +8186,24 @@ function newDataAttributeName(attributes, protectedNames = /* @__PURE__ */ new S
7748
8186
  for (let count = 2; taken(name); count += 1) name = `data-name-${count}`;
7749
8187
  return name;
7750
8188
  }
7751
- function editDataAttributes(attributes, edit) {
8189
+ function editDataAttributes(attributes, edit2) {
7752
8190
  let next;
7753
- switch (edit.kind) {
8191
+ switch (edit2.kind) {
7754
8192
  case "name":
7755
8193
  next = attributes.map(
7756
- (item, at) => at === edit.index ? [edit.name, item[1]] : item
8194
+ (item, at) => at === edit2.index ? [edit2.name, item[1]] : item
7757
8195
  );
7758
8196
  break;
7759
8197
  case "value":
7760
8198
  next = attributes.map(
7761
- (item, at) => at === edit.index ? [item[0], edit.value] : item
8199
+ (item, at) => at === edit2.index ? [item[0], edit2.value] : item
7762
8200
  );
7763
8201
  break;
7764
8202
  case "add":
7765
- next = [...attributes, [edit.name, ""]];
8203
+ next = [...attributes, [edit2.name, ""]];
7766
8204
  break;
7767
8205
  case "remove":
7768
- next = attributes.filter((_item, at) => at !== edit.index);
8206
+ next = attributes.filter((_item, at) => at !== edit2.index);
7769
8207
  break;
7770
8208
  }
7771
8209
  return next.length ? Object.fromEntries(next) : void 0;
@@ -10889,6 +11327,8 @@ function createEditor(options) {
10889
11327
  let wired;
10890
11328
  const autosave = options.storage && createAutosave(options.storage, 400, () => realmOf(wired ?? document));
10891
11329
  const documentArea = signal("outline");
11330
+ const newParamName = signal("");
11331
+ const newParamKind = signal("string");
10892
11332
  const inspectorArea = signal("properties");
10893
11333
  const saveAsError = signal("");
10894
11334
  const extractPath = signal("");
@@ -10918,6 +11358,10 @@ function createEditor(options) {
10918
11358
  const paletteFilter = signal("");
10919
11359
  const paletteFilterRevision = signal(0);
10920
11360
  const paletteView = signal(rememberedPaletteView());
11361
+ const libraryMode = signal("components");
11362
+ const documentView = signal(rememberedDocumentView());
11363
+ const documentLibraryPath = signal([]);
11364
+ const collapsedDocumentFolders = signal(/* @__PURE__ */ new Set());
10921
11365
  const libraryFiles = signal([]);
10922
11366
  const libraryError = signal("");
10923
11367
  const commit = (next) => {
@@ -10927,6 +11371,193 @@ function createEditor(options) {
10927
11371
  editNotice.value = null;
10928
11372
  historyVersion.value += 1;
10929
11373
  };
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
+ };
10930
11561
  const lastExport = signal(void 0);
10931
11562
  const documentSize = signal(280);
10932
11563
  const inspectorSize = signal(300);
@@ -11498,37 +12129,37 @@ function createEditor(options) {
11498
12129
  ] })
11499
12130
  ] });
11500
12131
  };
11501
- const editDataAttribute = (edit) => {
12132
+ const editDataAttribute = (edit2) => {
11502
12133
  const id = selectedNodeId();
11503
12134
  const node = findNode(doc.value, id).node;
11504
12135
  const attributes = dataAttributes(
11505
12136
  node.props?.[DATA_ATTRIBUTES_PROP]
11506
12137
  );
11507
- if (edit.kind === "name") {
12138
+ if (edit2.kind === "name") {
11508
12139
  const prop = propsByKey.get(node.type).props.find((item) => item.name === DATA_ATTRIBUTES_PROP);
11509
12140
  const error = dataAttributeNameError(
11510
- edit.name,
12141
+ edit2.name,
11511
12142
  attributes,
11512
- edit.index,
12143
+ edit2.index,
11513
12144
  protectedDataAttributes(prop.type, definitionsOf(node.type))
11514
12145
  );
11515
- const key = `#data-attribute-${edit.index}`;
12146
+ const key = `#data-attribute-${edit2.index}`;
11516
12147
  if (error) {
11517
12148
  fieldErrors.value = { ...fieldErrors.value, [key]: error };
11518
12149
  return;
11519
12150
  }
11520
12151
  if (fieldErrors.value[key]) fieldErrors.value = {};
11521
- if (attributes[edit.index][0] === edit.name) return;
12152
+ if (attributes[edit2.index][0] === edit2.name) return;
11522
12153
  }
11523
- if (edit.kind === "value" && attributes[edit.index][1] === edit.value)
12154
+ if (edit2.kind === "value" && attributes[edit2.index][1] === edit2.value)
11524
12155
  return;
11525
- if (edit.kind === "remove") fieldErrors.value = {};
12156
+ if (edit2.kind === "remove") fieldErrors.value = {};
11526
12157
  commit(
11527
12158
  setProp(
11528
12159
  doc.value,
11529
12160
  id,
11530
12161
  DATA_ATTRIBUTES_PROP,
11531
- editDataAttributes(attributes, edit)
12162
+ editDataAttributes(attributes, edit2)
11532
12163
  )
11533
12164
  );
11534
12165
  };
@@ -11602,6 +12233,10 @@ function createEditor(options) {
11602
12233
  paletteFilter,
11603
12234
  paletteFilterRevision,
11604
12235
  paletteView,
12236
+ libraryMode,
12237
+ documentView,
12238
+ documentPath: documentLibraryPath,
12239
+ collapsedDocumentFolders,
11605
12240
  libraryFiles,
11606
12241
  libraryError
11607
12242
  });
@@ -11614,6 +12249,8 @@ function createEditor(options) {
11614
12249
  historyVersion.value += 1;
11615
12250
  selection.value = null;
11616
12251
  loadError.value = null;
12252
+ newParamName.value = "";
12253
+ newParamKind.value = "string";
11617
12254
  viewLoads.value = /* @__PURE__ */ new Map();
11618
12255
  viewTrail.value = [];
11619
12256
  if (!autosave) return;
@@ -11863,6 +12500,16 @@ function createEditor(options) {
11863
12500
  problemCounts2(problemList)
11864
12501
  ) })
11865
12502
  },
12503
+ {
12504
+ area: "params",
12505
+ name: "Params",
12506
+ panel: documentArea.value === "params" ? documentParamsPanel(
12507
+ document2,
12508
+ newParamName.value,
12509
+ newParamKind.value,
12510
+ fieldErrors.value
12511
+ ) : ""
12512
+ },
11866
12513
  {
11867
12514
  area: "problems",
11868
12515
  name: "Problems",
@@ -12182,6 +12829,8 @@ function createEditor(options) {
12182
12829
  const discardInspectorDrafts = () => {
12183
12830
  const stack = wired?.querySelector(`#${INSPECTOR_STACK}`);
12184
12831
  if (stack) discardDrafts(stack);
12832
+ const params = wired?.querySelector("[data-editor-document-params]");
12833
+ if (params) discardDrafts(params);
12185
12834
  };
12186
12835
  const undo = () => {
12187
12836
  if (!history.canUndo) return;
@@ -12609,10 +13258,10 @@ function createEditor(options) {
12609
13258
  const promoteField = (at) => {
12610
13259
  const node = findNode(doc.value, selectedNodeId()).node;
12611
13260
  const { type, definitions } = fieldContext(node, at);
12612
- const paramType = paramTypeFor(
13261
+ const paramType2 = paramTypeFor(
12613
13262
  resolveType(type, definitions)
12614
13263
  );
12615
- if (!paramType || isBinding(valueAt(node.props?.[at.prop], at.path)))
13264
+ if (!paramType2 || isBinding(valueAt(node.props?.[at.prop], at.path)))
12616
13265
  return;
12617
13266
  const words2 = [
12618
13267
  at.prop,
@@ -12629,7 +13278,7 @@ function createEditor(options) {
12629
13278
  node.id,
12630
13279
  at.prop,
12631
13280
  param,
12632
- paramType,
13281
+ paramType2,
12633
13282
  at.path
12634
13283
  );
12635
13284
  commit(result.document);
@@ -13025,6 +13674,20 @@ function createEditor(options) {
13025
13674
  };
13026
13675
  };
13027
13676
  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
+ ),
13028
13691
  delegate(
13029
13692
  root,
13030
13693
  "change",
@@ -13211,10 +13874,42 @@ function createEditor(options) {
13211
13874
  hook(HOOK.paletteFilter),
13212
13875
  (_event, editor) => {
13213
13876
  paletteFilter.value = readSearchField(editor).query;
13877
+ documentLibraryPath.value = [];
13214
13878
  }
13215
13879
  )
13216
13880
  ];
13217
13881
  const paletteAndShellActions = (root) => ({
13882
+ [LIBRARY_MODE_ACTION]: (_event, target) => {
13883
+ libraryMode.value = target.dataset.segmentValue === "documents" ? "documents" : "components";
13884
+ paletteFilter.value = "";
13885
+ paletteFilterRevision.value += 1;
13886
+ },
13887
+ [DOCUMENT_VIEW_ACTION]: (_event, target) => {
13888
+ const view = target.dataset.segmentValue === "tree" ? "tree" : "columns";
13889
+ documentView.value = view;
13890
+ rememberDocumentView(view);
13891
+ },
13892
+ [DOCUMENT_ROW_ACTION]: (event, target) => {
13893
+ const id = target.dataset.itemId;
13894
+ const path = treeListPath(
13895
+ libraryDocumentTree(
13896
+ libraryDocuments(libraryFiles.peek(), paletteFilter.peek())
13897
+ ),
13898
+ id
13899
+ );
13900
+ documentLibraryPath.value = isDocumentFolderId(id) ? path : path.slice(0, -1);
13901
+ if (!isDocumentFolderId(id))
13902
+ void insertFromLibrary(root, id, event.altKey);
13903
+ },
13904
+ [DOCUMENT_BACK_ACTION]: () => {
13905
+ documentLibraryPath.value = documentLibraryPath.peek().slice(0, -1);
13906
+ },
13907
+ [DOCUMENT_TOGGLE_ACTION]: (_event, target) => {
13908
+ const id = target.dataset.itemId;
13909
+ const next = new Set(collapsedDocumentFolders.peek());
13910
+ if (!next.delete(id)) next.add(id);
13911
+ collapsedDocumentFolders.value = next;
13912
+ },
13218
13913
  [PALETTE_VIEW_ACTION]: (_event, target) => {
13219
13914
  const view = target.dataset.segmentValue === "grid" ? "grid" : "list";
13220
13915
  paletteView.value = view;
@@ -13222,6 +13917,7 @@ function createEditor(options) {
13222
13917
  },
13223
13918
  [PALETTE_CLEAR_ACTION]: () => {
13224
13919
  paletteFilter.value = "";
13920
+ documentLibraryPath.value = [];
13225
13921
  paletteFilterRevision.value += 1;
13226
13922
  root.querySelector(hook(HOOK.paletteFilter))?.focus();
13227
13923
  },
@@ -13517,7 +14213,7 @@ function createEditor(options) {
13517
14213
  JSON.parse(target.dataset.editorPromoteField)
13518
14214
  )
13519
14215
  });
13520
- const outlineAndDocumentActions = (root) => ({
14216
+ const outlineAndDocumentActions = () => ({
13521
14217
  [OUTLINE_ACTION]: (_event, target) => {
13522
14218
  leaveFieldEditor(target);
13523
14219
  const id = target.dataset.itemId;
@@ -13534,16 +14230,42 @@ function createEditor(options) {
13534
14230
  },
13535
14231
  [PROBLEM_ACTION]: (_event, target) => select({ kind: "node", id: target.dataset.itemId }),
13536
14232
  [PALETTE_ACTION]: (_event, target) => select({ kind: "component", key: target.dataset.itemId }),
13537
- [PALETTE_DOCUMENT_ACTION]: (event, target) => void insertFromLibrary(
13538
- root,
13539
- target.dataset.editorPaletteDocument,
13540
- event.altKey
13541
- ),
13542
14233
  [EXPORT_MODULE_ACTION]: () => exportAs("module"),
13543
14234
  [EXPORT_DECLARATIONS_ACTION]: () => exportAs("declarations"),
13544
14235
  // KF-QSSTMX: a new empty document; with storage it is a new draft,
13545
14236
  // and the previous document stays in its file.
13546
14237
  [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
+ },
13547
14269
  [DOCUMENT_TAB_ACTION]: (_event, target) => {
13548
14270
  documentArea.value = target.dataset.tabId.slice(
13549
14271
  DOCUMENT_AREAS.length + 1
@@ -13608,7 +14330,7 @@ function createEditor(options) {
13608
14330
  ...inspectorFieldActions(),
13609
14331
  ...dialogActions(root),
13610
14332
  ...inspectorFlowActions(),
13611
- ...outlineAndDocumentActions(root),
14333
+ ...outlineAndDocumentActions(),
13612
14334
  ...documentDialogActions(root)
13613
14335
  });
13614
14336
  const wireCanvasDragHandlers = (root) => wireCanvasDrag(root, {
@@ -13878,6 +14600,7 @@ function createEditor(options) {
13878
14600
  // KF-WKABP2: an inside drop with several places asks where.
13879
14601
  onMove: (move) => moveOrAsk(root, move)
13880
14602
  }),
14603
+ wireColumnExplorer(root),
13881
14604
  // KF-WKABP2: a replacing drop of authored content asks first.
13882
14605
  effect(() => {
13883
14606
  if (!pendingReplace.value) return;