@kerfjs/ui 5.0.0-beta.125 → 5.0.0-beta.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/ai/application-ui-diagnostic-ids-v1.json +1 -0
- package/ai/component-catalog.json +77 -6
- package/ai/component-catalog.schema.json +14 -1
- package/ai/component-composition.json +27 -6
- package/ai/component-props.json +265 -40
- package/ai/components/combobox.md +1 -1
- package/ai/components/surface-scaffold.md +19 -5
- package/ai/components/tab-bar.md +2 -0
- package/ai/components/toolbar.md +1 -0
- package/ai/public-api-signatures-v1.md +251 -298
- package/ai/skill.md +10 -4
- package/ai/view-document.schema.json +55 -2
- package/ai/webawesome-jsx-signatures-v1.md +1 -1
- package/analyzer/cli.mjs +60 -24
- package/analyzer/index.mjs +331 -58
- package/catalog-projection-cli.mjs +86 -50
- package/dist/anchored-surface.js +2 -1
- package/dist/browser/editor.js +12 -7
- package/dist/catalog-resources.d.ts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.js +6 -6
- package/dist/{chunk-VX3YF2UD.js → chunk-3K5V3ZSD.js} +3 -3
- package/dist/{chunk-VX3YF2UD.js.map → chunk-3K5V3ZSD.js.map} +1 -1
- package/dist/{chunk-NHQOX7T4.js → chunk-3ZKUXWAV.js} +4 -4
- package/dist/chunk-3ZKUXWAV.js.map +1 -0
- package/dist/{chunk-ADMWT7FX.js → chunk-3ZWYGGEC.js} +136 -8
- package/dist/chunk-3ZWYGGEC.js.map +1 -0
- package/dist/{chunk-KLR3DCHH.js → chunk-4L5ZIKDZ.js} +1 -1
- package/dist/chunk-4L5ZIKDZ.js.map +1 -0
- package/dist/{chunk-2E7S5C4D.js → chunk-4UWLHKNU.js} +5 -5
- package/dist/chunk-4UWLHKNU.js.map +1 -0
- package/dist/{chunk-EXGDKG7B.js → chunk-5A2DN3LR.js} +5 -5
- package/dist/chunk-5A2DN3LR.js.map +1 -0
- package/dist/{chunk-DJ65XFVN.js → chunk-63TJH2RF.js} +4 -4
- package/dist/chunk-63TJH2RF.js.map +1 -0
- package/dist/{chunk-Q2CLQ3IJ.js → chunk-6PHG2DMG.js} +1 -1
- package/dist/chunk-6PHG2DMG.js.map +1 -0
- package/dist/{chunk-SPI6VMIY.js → chunk-6T7AX365.js} +4 -4
- package/dist/chunk-6T7AX365.js.map +1 -0
- package/dist/{chunk-GVII4JSD.js → chunk-6V6UHPJD.js} +4 -4
- package/dist/chunk-6V6UHPJD.js.map +1 -0
- package/dist/{chunk-NR3ZO4LK.js → chunk-7U65KLDL.js} +1 -1
- package/dist/chunk-7U65KLDL.js.map +1 -0
- package/dist/chunk-BMOZSNDU.js +133 -0
- package/dist/chunk-BMOZSNDU.js.map +1 -0
- package/dist/{chunk-2LM3PYHA.js → chunk-C2TY5DJC.js} +11 -8
- package/dist/chunk-C2TY5DJC.js.map +1 -0
- package/dist/{chunk-3WYREXW4.js → chunk-COMEWURO.js} +8 -6
- package/dist/chunk-COMEWURO.js.map +1 -0
- package/dist/{chunk-VPDSPD76.js → chunk-DB64I3DB.js} +4 -3
- package/dist/chunk-DB64I3DB.js.map +1 -0
- package/dist/{chunk-SBCXWGNP.js → chunk-DBCDYBZP.js} +2 -2
- package/dist/{chunk-SBCXWGNP.js.map → chunk-DBCDYBZP.js.map} +1 -1
- package/dist/{chunk-CNM6ZWP2.js → chunk-DJWBXEF4.js} +4 -2
- package/dist/chunk-DJWBXEF4.js.map +1 -0
- package/dist/{chunk-SVUJIVMR.js → chunk-E2MTHHLS.js} +3 -3
- package/dist/{chunk-SVUJIVMR.js.map → chunk-E2MTHHLS.js.map} +1 -1
- package/dist/{chunk-JG4ONAOI.js → chunk-EI55KWHP.js} +2 -2
- package/dist/chunk-EI55KWHP.js.map +1 -0
- package/dist/{chunk-MVKHSAKE.js → chunk-GE2BQXB3.js} +41 -4
- package/dist/chunk-GE2BQXB3.js.map +1 -0
- package/dist/chunk-GHV36C6I.js +94 -0
- package/dist/chunk-GHV36C6I.js.map +1 -0
- package/dist/{chunk-BCO673YW.js → chunk-GQUDCWOD.js} +10 -4
- package/dist/chunk-GQUDCWOD.js.map +1 -0
- package/dist/chunk-HD7ZLISK.js +808 -0
- package/dist/chunk-HD7ZLISK.js.map +1 -0
- package/dist/{chunk-KELWWCMX.js → chunk-I2K4OQKB.js} +4 -4
- package/dist/chunk-I2K4OQKB.js.map +1 -0
- package/dist/chunk-IFDTSVE6.js +9 -0
- package/dist/chunk-IFDTSVE6.js.map +1 -0
- package/dist/{chunk-TPLVC5BE.js → chunk-IR32NI2O.js} +336 -247
- package/dist/chunk-IR32NI2O.js.map +1 -0
- package/dist/{chunk-ZKKO4MHC.js → chunk-JYKP7TBZ.js} +4 -2
- package/dist/chunk-JYKP7TBZ.js.map +1 -0
- package/dist/{chunk-6OT7FOSA.js → chunk-K3C35KGR.js} +4 -4
- package/dist/chunk-K3C35KGR.js.map +1 -0
- package/dist/{chunk-4RECPEHI.js → chunk-KBS3GP6S.js} +4 -3
- package/dist/chunk-KBS3GP6S.js.map +1 -0
- package/dist/{chunk-YHRJNKD5.js → chunk-KS7EXW4P.js} +6 -4
- package/dist/chunk-KS7EXW4P.js.map +1 -0
- package/dist/{chunk-V6N3YLTM.js → chunk-LTOTL5AS.js} +3 -3
- package/dist/chunk-LTOTL5AS.js.map +1 -0
- package/dist/chunk-M64TAGZY.js +590 -0
- package/dist/chunk-M64TAGZY.js.map +1 -0
- package/dist/{chunk-JZZVWTUB.js → chunk-MMOQR426.js} +2 -2
- package/dist/chunk-MMOQR426.js.map +1 -0
- package/dist/{chunk-SJBMKA4X.js → chunk-OHT2AXER.js} +11 -10
- package/dist/chunk-OHT2AXER.js.map +1 -0
- package/dist/{chunk-TTFW6E6C.js → chunk-OZKBIPXU.js} +2 -2
- package/dist/chunk-OZKBIPXU.js.map +1 -0
- package/dist/{chunk-Q2SLOMN6.js → chunk-RHMY45DK.js} +4 -4
- package/dist/chunk-RHMY45DK.js.map +1 -0
- package/dist/{chunk-BZXA5SSA.js → chunk-S7QB5KMM.js} +2 -2
- package/dist/{chunk-BZXA5SSA.js.map → chunk-S7QB5KMM.js.map} +1 -1
- package/dist/{chunk-HDXUHLTQ.js → chunk-SHECA2N4.js} +8 -2
- package/dist/chunk-SHECA2N4.js.map +1 -0
- package/dist/{chunk-R6FIXYAE.js → chunk-SJEPM5ZU.js} +2 -2
- package/dist/{chunk-R6FIXYAE.js.map → chunk-SJEPM5ZU.js.map} +1 -1
- package/dist/{chunk-FJMABKKV.js → chunk-UQ4FRQ6M.js} +35 -17
- package/dist/chunk-UQ4FRQ6M.js.map +1 -0
- package/dist/{chunk-S4ZGTDSG.js → chunk-UU37OR3D.js} +2 -2
- package/dist/chunk-UU37OR3D.js.map +1 -0
- package/dist/{chunk-SWXWLSUD.js → chunk-WEQNPYVA.js} +1 -1
- package/dist/{chunk-SWXWLSUD.js.map → chunk-WEQNPYVA.js.map} +1 -1
- package/dist/{chunk-5SFHBYEY.js → chunk-WUVHP3UC.js} +97 -24
- package/dist/chunk-WUVHP3UC.js.map +1 -0
- package/dist/{chunk-3S3WXAZ5.js → chunk-X43QQWVC.js} +3 -2
- package/dist/chunk-X43QQWVC.js.map +1 -0
- package/dist/{chunk-Z3T24FX3.js → chunk-YE6KCAIN.js} +3 -2
- package/dist/chunk-YE6KCAIN.js.map +1 -0
- package/dist/{chunk-KQZIC5CA.js → chunk-ZC4KSRAF.js} +7 -7
- package/dist/chunk-ZC4KSRAF.js.map +1 -0
- package/dist/collapsible-panel.d.ts +2 -2
- package/dist/collapsible-panel.js +2 -2
- package/dist/collapsible-panel.js.map +1 -1
- package/dist/column-explorer.d.ts +3 -3
- package/dist/column-explorer.js +16 -138
- package/dist/column-explorer.js.map +1 -1
- package/dist/dialog-surface-controller-BeKZ3e8Z.d.ts +251 -0
- package/dist/editor-frame.d.ts +1 -1
- package/dist/editor-frame.js +1 -1
- package/dist/editor.d.ts +38 -20
- package/dist/editor.js +11651 -7052
- package/dist/editor.js.map +1 -1
- package/dist/file-picker.js +1 -1
- package/dist/help-tags-register.js +2 -1
- package/dist/help-tags-register.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +24 -23
- package/dist/list-action-row.d.ts +1 -1
- package/dist/list-action-row.js +1 -1
- package/dist/list-detail-dialog.d.ts +7 -7
- package/dist/list-detail-dialog.js +6 -5
- package/dist/list-detail-dialog.js.map +1 -1
- package/dist/list-header.d.ts +1 -1
- package/dist/list-header.js +1 -1
- package/dist/list-item.d.ts +1 -1
- package/dist/list-item.js +1 -1
- package/dist/message-composer.js +1 -1
- package/dist/nav-stack.d.ts +6 -6
- package/dist/nav-stack.js +1 -1
- package/dist/popup-menu-register.js +1 -7
- package/dist/popup-menu-register.js.map +1 -1
- package/dist/popup-menu.d.ts +2 -2
- package/dist/popup-menu.js +1 -1
- package/dist/resizable-region.js +1 -1
- package/dist/segmented-control.d.ts +1 -1
- package/dist/segmented-control.js +1 -1
- package/dist/select-register.js +17 -23
- package/dist/select-register.js.map +1 -1
- package/dist/split-view.d.ts +6 -6
- package/dist/split-view.js +1 -1
- package/dist/styles/collapsible-panel.css +34 -25
- package/dist/styles/components/actions/popup-menu/popup-menu.css +4 -4
- package/dist/styles/components/actions/toolbar/toolbar.css +34 -1
- package/dist/styles/components/actions/toolbar-control-group/toolbar-control-group.css +1 -1
- package/dist/styles/components/forms/segmented-control/segmented-control.css +1 -1
- package/dist/styles/components/layout/collapsible-panel/collapsible-panel.css +34 -25
- package/dist/styles/components/layout/split-view/split-view.css +19 -33
- package/dist/styles/components/navigation/nav-stack/nav-stack.css +15 -19
- package/dist/styles/components/navigation/tab-navigator/tab-navigator.css +30 -29
- package/dist/styles/components/surfaces/editor-frame/editor-frame.css +10 -3
- package/dist/styles/components/surfaces/surface-scaffold/surface-scaffold.css +291 -4
- package/dist/styles/editor/editor.css +78 -0
- package/dist/styles/editor-frame.css +10 -3
- package/dist/styles/nav-stack.css +15 -19
- package/dist/styles/popup-menu.css +4 -4
- package/dist/styles/segmented-control.css +1 -1
- package/dist/styles/split-view.css +19 -33
- package/dist/styles/surface-scaffold.css +291 -4
- package/dist/styles/tab-navigator.css +30 -29
- package/dist/styles/toolbar-control-group.css +1 -1
- package/dist/styles/toolbar.css +34 -1
- package/dist/styles/webawesome.css +4 -5
- package/dist/surface-scaffold-register.js +2 -1
- package/dist/surface-scaffold-register.js.map +1 -1
- package/dist/surface-scaffold.d.ts +155 -246
- package/dist/surface-scaffold.js +3 -2
- package/dist/toolbar-control-group.d.ts +2 -2
- package/dist/toolbar-control-group.js +1 -1
- package/dist/toolbar.d.ts +6 -1
- package/dist/toolbar.js +1 -1
- package/dist/tree-list.d.ts +4 -4
- package/dist/tree-list.js +2 -2
- package/dist/{tree-rows-eHnnGLGM.d.ts → tree-rows-Bms5QJvG.d.ts} +3 -0
- package/dist/wire-catalog.d.ts +1 -1
- package/dist/wire-catalog.js +3 -2
- package/dist/wire-catalog.js.map +1 -1
- package/dist/wire-checkboxes.js +2 -1
- package/dist/wire-choice-chips.js +2 -1
- package/dist/wire-color-fields.js +2 -1
- package/dist/wire-color-pickers.js +2 -1
- package/dist/wire-column-explorer.js +1 -92
- package/dist/wire-column-explorer.js.map +1 -1
- package/dist/wire-comboboxes.d.ts +2 -0
- package/dist/wire-comboboxes.js +2 -1
- package/dist/wire-content-items.js +2 -1
- package/dist/wire-corner-status.js +2 -1
- package/dist/wire-nav-stack.js +2 -1
- package/dist/wire-overlay-sheets.js +2 -1
- package/dist/wire-paged-views.js +2 -2
- package/dist/wire-paged-views.js.map +1 -1
- package/dist/wire-resizable-regions.js +2 -1
- package/dist/wire-scroll-dividers.js +1 -1
- package/dist/wire-search-fields.js +2 -1
- package/dist/wire-sidebar.js +2 -1
- package/dist/wire-tab-bars.d.ts +41 -2
- package/dist/wire-tab-bars.js +1 -1
- package/dist/wire-tab-navigator.js +2 -1
- package/dist/wire-tag-fields.js +2 -1
- package/dist/wire-workbench.js +2 -1
- package/dist/workbench-dialog.d.ts +7 -7
- package/dist/workbench-dialog.js +5 -4
- package/dist/workbench-dialog.js.map +1 -1
- package/dist/workbench.d.ts +1 -1
- package/dist/workbench.js +1 -1
- package/docs/accessibility.md +3 -6
- package/docs/component-contract.md +47 -7
- package/docs/component-selection.md +90 -80
- package/docs/design/templates.md +5 -4
- package/docs/editor-frame.md +1 -1
- package/docs/editor-host.md +15 -2
- package/docs/overlay-tooltip.md +1 -1
- package/docs/recipes.md +1 -1
- package/docs/surface-scaffold.md +63 -2
- package/docs/ui-analyzer.md +42 -0
- package/docs/ui-doctor.md +45 -1
- package/docs/ui-evaluator.md +35 -0
- package/docs/ux-demo.md +1 -1
- package/docs/view.md +314 -0
- package/docs/webawesome-theme.md +16 -0
- package/doctor/cli.mjs +36 -31
- package/doctor/index.mjs +349 -162
- package/evaluator/cli.mjs +36 -30
- package/llms.txt +17 -4
- package/package.json +6 -2
- package/props/cli.mjs +47 -21
- package/scripts/lib/cli-args.mjs +98 -0
- package/ux-demo/recipes/app-shell.tsx +48 -141
- package/ux-demo/recipes/collapsible-sidebar.tsx +43 -169
- package/ux-demo/recipes/compact-toolbar.tsx +22 -114
- package/ux-demo/recipes/composer-form.tsx +14 -104
- package/ux-demo/recipes/list-detail-dialog.tsx +38 -84
- package/ux-demo/recipes/list-workspace-states.tsx +29 -152
- package/ux-demo/recipes/loading-inspector.tsx +30 -174
- package/ux-demo/recipes/media-detail.tsx +29 -146
- package/ux-demo/recipes/navigation-sidebar.tsx +24 -113
- package/ux-demo/recipes/navigation-stack.tsx +7 -43
- package/ux-demo/recipes/workspace-header.tsx +2 -66
- package/view/catalog.mjs +229 -0
- package/view/child-kind.mjs +22 -0
- package/view/cli.mjs +142 -119
- package/view/contract.mjs +84 -11
- package/view/css-grammar.mjs +93 -0
- package/view/generate.d.mts +16 -0
- package/view/generate.mjs +155 -56
- package/view/index.d.mts +80 -14
- package/view/index.mjs +5 -9
- package/view/interpret.mjs +104 -36
- package/view/types.mjs +161 -0
- package/view/validate-move.mjs +66 -30
- package/view/validate.mjs +420 -654
- package/vite-editor.d.mts +16 -1
- package/vite-editor.mjs +74 -4
- package/dist/chunk-2E7S5C4D.js.map +0 -1
- package/dist/chunk-2LM3PYHA.js.map +0 -1
- package/dist/chunk-3S3WXAZ5.js.map +0 -1
- package/dist/chunk-3WYREXW4.js.map +0 -1
- package/dist/chunk-4RECPEHI.js.map +0 -1
- package/dist/chunk-5SFHBYEY.js.map +0 -1
- package/dist/chunk-6OT7FOSA.js.map +0 -1
- package/dist/chunk-ADMWT7FX.js.map +0 -1
- package/dist/chunk-BCO673YW.js.map +0 -1
- package/dist/chunk-CNM6ZWP2.js.map +0 -1
- package/dist/chunk-DJ65XFVN.js.map +0 -1
- package/dist/chunk-EXGDKG7B.js.map +0 -1
- package/dist/chunk-FJMABKKV.js.map +0 -1
- package/dist/chunk-GVII4JSD.js.map +0 -1
- package/dist/chunk-HDXUHLTQ.js.map +0 -1
- package/dist/chunk-JG4ONAOI.js.map +0 -1
- package/dist/chunk-JZZVWTUB.js.map +0 -1
- package/dist/chunk-KELWWCMX.js.map +0 -1
- package/dist/chunk-KLR3DCHH.js.map +0 -1
- package/dist/chunk-KQZIC5CA.js.map +0 -1
- package/dist/chunk-LD6A6PYB.js +0 -268
- package/dist/chunk-LD6A6PYB.js.map +0 -1
- package/dist/chunk-MVKHSAKE.js.map +0 -1
- package/dist/chunk-NHQOX7T4.js.map +0 -1
- package/dist/chunk-NR3ZO4LK.js.map +0 -1
- package/dist/chunk-Q2CLQ3IJ.js.map +0 -1
- package/dist/chunk-Q2SLOMN6.js.map +0 -1
- package/dist/chunk-S4ZGTDSG.js.map +0 -1
- package/dist/chunk-SJBMKA4X.js.map +0 -1
- package/dist/chunk-SPI6VMIY.js.map +0 -1
- package/dist/chunk-TPLVC5BE.js.map +0 -1
- package/dist/chunk-TTFW6E6C.js.map +0 -1
- package/dist/chunk-V6N3YLTM.js.map +0 -1
- package/dist/chunk-VNT4MXR5.js +0 -548
- package/dist/chunk-VNT4MXR5.js.map +0 -1
- package/dist/chunk-VPDSPD76.js.map +0 -1
- package/dist/chunk-YHRJNKD5.js.map +0 -1
- package/dist/chunk-Z3T24FX3.js.map +0 -1
- package/dist/chunk-ZKKO4MHC.js.map +0 -1
- package/dist/{nav-stack-DwxpXxqJ.d.ts → nav-stack-vQ3ieerq.d.ts} +3 -3
package/view/contract.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// application code compiles against — inputs, actions, slots, refs — with its
|
|
3
3
|
// layout-independent `kui1:` digest and a breaking/non-breaking diff. Shared
|
|
4
4
|
// by the generator and the runtime interpreter so both compute the same digest.
|
|
5
|
-
import {
|
|
5
|
+
import { childKind } from './child-kind.mjs';
|
|
6
|
+
import { eachTemplates, validateView } from './validate.mjs';
|
|
6
7
|
|
|
7
8
|
const MASK_64 = 0xffffffffffffffffn;
|
|
8
9
|
const FNV_OFFSET = 0xcbf29ce484222325n;
|
|
@@ -108,11 +109,19 @@ function elementOf(catalog, node) {
|
|
|
108
109
|
export function walkView(document, visit) {
|
|
109
110
|
const child = (item, row) => {
|
|
110
111
|
if (!isObject(item)) return;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
switch (childKind(item)) {
|
|
113
|
+
case 'each':
|
|
114
|
+
for (const template of eachTemplates(item)) child(template, true);
|
|
115
|
+
break;
|
|
116
|
+
case 'if':
|
|
117
|
+
child(item.then, row);
|
|
118
|
+
if ('else' in item) child(item.else, row);
|
|
119
|
+
break;
|
|
120
|
+
case 'slot':
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
node(item, row);
|
|
124
|
+
}
|
|
116
125
|
};
|
|
117
126
|
const node = (item, row) => {
|
|
118
127
|
if (!isObject(item)) return;
|
|
@@ -135,11 +144,17 @@ export function walkView(document, visit) {
|
|
|
135
144
|
const slots = (item, found) => {
|
|
136
145
|
if (!isObject(item)) return;
|
|
137
146
|
valueSlots(item.props, found);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
switch (childKind(item)) {
|
|
148
|
+
case 'slot':
|
|
149
|
+
found.add(item.$slot);
|
|
150
|
+
break;
|
|
151
|
+
case 'each':
|
|
152
|
+
for (const template of eachTemplates(item)) slots(template, found);
|
|
153
|
+
break;
|
|
154
|
+
case 'if':
|
|
155
|
+
slots(item.then, found);
|
|
156
|
+
slots(item.else, found);
|
|
157
|
+
break;
|
|
143
158
|
}
|
|
144
159
|
for (const children of Object.values(
|
|
145
160
|
isObject(item.zones) ? item.zones : {},
|
|
@@ -154,6 +169,45 @@ export function walkView(document, visit) {
|
|
|
154
169
|
return found;
|
|
155
170
|
}
|
|
156
171
|
|
|
172
|
+
/**
|
|
173
|
+
* KF-YX6HMT: the kinds each `templates` repeat names, by its item name
|
|
174
|
+
* (`as`), sorted. Repeats that share an item name share one list.
|
|
175
|
+
*/
|
|
176
|
+
function rowKinds(document) {
|
|
177
|
+
const found = {};
|
|
178
|
+
const child = (item) => {
|
|
179
|
+
if (!isObject(item)) return;
|
|
180
|
+
switch (childKind(item)) {
|
|
181
|
+
case 'each':
|
|
182
|
+
if (isObject(item.templates)) {
|
|
183
|
+
found[item.as] ??= new Set();
|
|
184
|
+
for (const kind of Object.keys(item.templates))
|
|
185
|
+
found[item.as].add(kind);
|
|
186
|
+
}
|
|
187
|
+
eachTemplates(item).forEach(child);
|
|
188
|
+
break;
|
|
189
|
+
case 'if':
|
|
190
|
+
child(item.then);
|
|
191
|
+
child(item.else);
|
|
192
|
+
break;
|
|
193
|
+
case 'slot':
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
node(item);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const node = (item) => {
|
|
200
|
+
for (const list of Object.values(isObject(item.zones) ? item.zones : {}))
|
|
201
|
+
if (Array.isArray(list)) list.forEach(child);
|
|
202
|
+
};
|
|
203
|
+
node(document.root);
|
|
204
|
+
return Object.fromEntries(
|
|
205
|
+
Object.entries(found)
|
|
206
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
207
|
+
.map(([as, kinds]) => [as, [...kinds].sort()]),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
157
211
|
/**
|
|
158
212
|
* The contract of a valid view document:
|
|
159
213
|
* `{ inputs, actions, slots, refs }`, each keyed by name.
|
|
@@ -175,6 +229,7 @@ export function contractOf(document, catalog, options = {}) {
|
|
|
175
229
|
// A prop-typed input is optional exactly when that prop is.
|
|
176
230
|
optional:
|
|
177
231
|
'default' in param ||
|
|
232
|
+
param.optional === true ||
|
|
178
233
|
(param.type.kind === 'prop' &&
|
|
179
234
|
!catalog.components
|
|
180
235
|
.get(param.type.component)
|
|
@@ -198,6 +253,7 @@ export function contractOf(document, catalog, options = {}) {
|
|
|
198
253
|
const input = document.slots?.[name]?.input;
|
|
199
254
|
slots[name] = input ? typeText(input) : null;
|
|
200
255
|
}
|
|
256
|
+
const kinds = rowKinds(document);
|
|
201
257
|
return {
|
|
202
258
|
inputs,
|
|
203
259
|
actions: Object.fromEntries(
|
|
@@ -205,6 +261,9 @@ export function contractOf(document, catalog, options = {}) {
|
|
|
205
261
|
),
|
|
206
262
|
slots,
|
|
207
263
|
refs,
|
|
264
|
+
// Only a document with a `templates` repeat has kinds, so every other
|
|
265
|
+
// document keeps its digest.
|
|
266
|
+
...(Object.keys(kinds).length ? { kinds } : {}),
|
|
208
267
|
};
|
|
209
268
|
}
|
|
210
269
|
|
|
@@ -225,6 +284,7 @@ function digestForm(contract) {
|
|
|
225
284
|
{ element: ref.element, keyed: ref.keyed },
|
|
226
285
|
]),
|
|
227
286
|
),
|
|
287
|
+
...(contract.kinds ? { kinds: contract.kinds } : {}),
|
|
228
288
|
};
|
|
229
289
|
}
|
|
230
290
|
|
|
@@ -338,5 +398,18 @@ export function diffContracts(before, after) {
|
|
|
338
398
|
);
|
|
339
399
|
}
|
|
340
400
|
}
|
|
401
|
+
// KF-YX6HMT: a new kind is optional (other items keep `default`); code
|
|
402
|
+
// that names a removed one through the generated type no longer compiles.
|
|
403
|
+
const oldKinds = before.kinds ?? {};
|
|
404
|
+
const newKinds = after.kinds ?? {};
|
|
405
|
+
for (const as of names(oldKinds, newKinds)) {
|
|
406
|
+
const old = new Set(oldKinds[as] ?? []);
|
|
407
|
+
const next = new Set(newKinds[as] ?? []);
|
|
408
|
+
for (const kind of [...new Set([...old, ...next])].sort()) {
|
|
409
|
+
if (!old.has(kind)) add('kind', `${as}.${kind}`, 'added', false, kind);
|
|
410
|
+
else if (!next.has(kind))
|
|
411
|
+
add('kind', `${as}.${kind}`, 'removed', true, kind);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
341
414
|
return changes;
|
|
342
415
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// The `$css` value grammar of @kerfjs/ui/view: a builder call from
|
|
2
|
+
// `@kerfjs/ui/css-values` with literal arguments only, parsed to a tree the
|
|
3
|
+
// interpreter evaluates and the generator emits verbatim.
|
|
4
|
+
|
|
5
|
+
// Every builder `@kerfjs/ui/css-values` exports; a css-value prop without a
|
|
6
|
+
// catalog `cssValue` restriction accepts any of them.
|
|
7
|
+
export const CSS_HELPERS = [
|
|
8
|
+
'calc',
|
|
9
|
+
'colorVar',
|
|
10
|
+
'em',
|
|
11
|
+
'fillColor',
|
|
12
|
+
'flex',
|
|
13
|
+
'foregroundColor',
|
|
14
|
+
'foregroundColorVar',
|
|
15
|
+
'lengthVar',
|
|
16
|
+
'pct',
|
|
17
|
+
'plus',
|
|
18
|
+
'px',
|
|
19
|
+
'rem',
|
|
20
|
+
'remify',
|
|
21
|
+
'space',
|
|
22
|
+
'uiColor',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parses a `$css` builder call with literal arguments only: numbers, quoted
|
|
27
|
+
* strings without quotes or backslashes inside, and nested builder calls.
|
|
28
|
+
* Generated code emits the call verbatim and the interpreter evaluates the
|
|
29
|
+
* tree, so anything else (an identifier, an operator, a template) is rejected
|
|
30
|
+
* rather than trusted. Returns `{ name, args }` (each argument a number,
|
|
31
|
+
* string, or nested call), or undefined when it does not parse.
|
|
32
|
+
*/
|
|
33
|
+
export function parseCssTree(source) {
|
|
34
|
+
if (typeof source !== 'string') return undefined;
|
|
35
|
+
const text = source.trim();
|
|
36
|
+
let index = 0;
|
|
37
|
+
const space = () => {
|
|
38
|
+
while (text[index] === ' ') index += 1;
|
|
39
|
+
};
|
|
40
|
+
const call = () => {
|
|
41
|
+
const name = /^[A-Za-z]+/.exec(text.slice(index))?.[0];
|
|
42
|
+
if (!name || text[index + name.length] !== '(') return undefined;
|
|
43
|
+
const node = { name, args: [] };
|
|
44
|
+
index += name.length + 1;
|
|
45
|
+
space();
|
|
46
|
+
if (text[index] === ')') {
|
|
47
|
+
index += 1;
|
|
48
|
+
return node;
|
|
49
|
+
}
|
|
50
|
+
for (;;) {
|
|
51
|
+
space();
|
|
52
|
+
const value = argument();
|
|
53
|
+
if (value === undefined) return undefined;
|
|
54
|
+
node.args.push(value);
|
|
55
|
+
space();
|
|
56
|
+
if (text[index] === ',') index += 1;
|
|
57
|
+
else if (text[index] === ')') {
|
|
58
|
+
index += 1;
|
|
59
|
+
return node;
|
|
60
|
+
} else return undefined;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const argument = () => {
|
|
64
|
+
const rest = text.slice(index);
|
|
65
|
+
const number = /^-?\d+(?:\.\d+)?/.exec(rest)?.[0];
|
|
66
|
+
if (number) {
|
|
67
|
+
index += number.length;
|
|
68
|
+
return Number(number);
|
|
69
|
+
}
|
|
70
|
+
const quoted =
|
|
71
|
+
/^'[^'\\\n]*'/.exec(rest)?.[0] ?? /^"[^"\\\n]*"/.exec(rest)?.[0];
|
|
72
|
+
if (quoted) {
|
|
73
|
+
index += quoted.length;
|
|
74
|
+
return quoted.slice(1, -1);
|
|
75
|
+
}
|
|
76
|
+
return call();
|
|
77
|
+
};
|
|
78
|
+
const tree = call();
|
|
79
|
+
return tree && index === text.length ? tree : undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The helper names a `$css` call uses, outermost first, or undefined. */
|
|
83
|
+
export function parseCssCall(source) {
|
|
84
|
+
const tree = parseCssTree(source);
|
|
85
|
+
if (!tree) return undefined;
|
|
86
|
+
const names = [];
|
|
87
|
+
const visit = (node) => {
|
|
88
|
+
names.push(node.name);
|
|
89
|
+
for (const arg of node.args) if (typeof arg === 'object') visit(arg);
|
|
90
|
+
};
|
|
91
|
+
visit(tree);
|
|
92
|
+
return names;
|
|
93
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Types for the generator module itself (KF-V5DPD1). `@kerfjs/ui/view`
|
|
2
|
+
// re-exports its supported names; the two helpers declared here are
|
|
3
|
+
// generator internals that only the package's own tests import directly.
|
|
4
|
+
export {
|
|
5
|
+
GENERATOR_VERSION,
|
|
6
|
+
generateView,
|
|
7
|
+
lucideExportName,
|
|
8
|
+
readViewHeader,
|
|
9
|
+
viewModulePath,
|
|
10
|
+
} from './index.mjs';
|
|
11
|
+
|
|
12
|
+
/** Layout printer for generated expressions. */
|
|
13
|
+
export function printDoc(doc: unknown, indent?: number): string;
|
|
14
|
+
|
|
15
|
+
/** A component import as the generated module writes it, relative to `importFrom` when absolute. */
|
|
16
|
+
export function moduleSpecifier(specifier: string, importFrom?: string): string;
|
package/view/generate.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// generateView: turns a valid view document into its read-only view module
|
|
2
2
|
// (docs/26-ui-editor.md §4). Output is plain TypeScript (or JavaScript plus a
|
|
3
|
-
// .d.ts) that
|
|
4
|
-
// consumer's build. Same document and catalogs in,
|
|
3
|
+
// .d.ts) that invokes component functions through a small typed call boundary
|
|
4
|
+
// — no JSX compiler in the consumer's build. Same document and catalogs in,
|
|
5
|
+
// byte-identical code out.
|
|
5
6
|
import {
|
|
6
7
|
canonicalJson,
|
|
7
8
|
contractDigest,
|
|
@@ -13,11 +14,13 @@ import {
|
|
|
13
14
|
import {
|
|
14
15
|
channelOf,
|
|
15
16
|
fieldZoneOf,
|
|
16
|
-
parseCssCall,
|
|
17
17
|
withFieldZones,
|
|
18
18
|
ZoneFill,
|
|
19
19
|
zonePropOf,
|
|
20
|
-
} from './
|
|
20
|
+
} from './catalog.mjs';
|
|
21
|
+
import { childKind } from './child-kind.mjs';
|
|
22
|
+
import { parseCssCall } from './css-grammar.mjs';
|
|
23
|
+
import { composedViewPath, eachNodes } from './validate.mjs';
|
|
21
24
|
|
|
22
25
|
export const GENERATOR_VERSION = 1;
|
|
23
26
|
const HEADER_LINES = 3;
|
|
@@ -206,6 +209,7 @@ function createImports() {
|
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
function createEmitter(document, catalog, imports, importFrom) {
|
|
212
|
+
let usesKerfComponent = false;
|
|
209
213
|
const value = (input, scope) => {
|
|
210
214
|
// A field zone's children, in the content field it fills (KF-PD6QC5).
|
|
211
215
|
if (input instanceof ZoneFill) return children(input.children, scope);
|
|
@@ -256,6 +260,16 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
256
260
|
return raw(literal(input));
|
|
257
261
|
};
|
|
258
262
|
|
|
263
|
+
// KF-EP2152: the document root's key is the render function's optional
|
|
264
|
+
// `rowKey` argument, given when a composing document renders this one as a
|
|
265
|
+
// row; every other row root's key is an expression over its item.
|
|
266
|
+
const ROOT_KEY = Symbol('root key');
|
|
267
|
+
const keyEntries = (rowKey) => {
|
|
268
|
+
if (rowKey === ROOT_KEY)
|
|
269
|
+
return [["...(rowKey === undefined ? {} : { 'data-key': rowKey })"]];
|
|
270
|
+
return rowKey ? [["'data-key'", raw(`String(${rowKey})`)]] : [];
|
|
271
|
+
};
|
|
272
|
+
|
|
259
273
|
/** Marker (and row key) attributes merged into a node's data-* channel. */
|
|
260
274
|
const markers = (node, rowKey, base, scope) => {
|
|
261
275
|
const entries = [];
|
|
@@ -266,7 +280,7 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
266
280
|
entries.push([`...${flat(value(base, scope))}`]);
|
|
267
281
|
}
|
|
268
282
|
entries.push(["'data-kerf-node'", raw(literal(node.id))]);
|
|
269
|
-
|
|
283
|
+
entries.push(...keyEntries(rowKey));
|
|
270
284
|
return obj(entries);
|
|
271
285
|
};
|
|
272
286
|
|
|
@@ -278,41 +292,77 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
278
292
|
};
|
|
279
293
|
|
|
280
294
|
const childExpr = (child, scope, slot) => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
template,
|
|
295
|
+
switch (childKind(child)) {
|
|
296
|
+
case 'each':
|
|
297
|
+
return eachExpr(child, scope, slot);
|
|
298
|
+
case 'if': {
|
|
299
|
+
const otherwise =
|
|
300
|
+
'else' in child ? childExpr(child.else, scope, slot) : raw('null');
|
|
301
|
+
return cond(
|
|
302
|
+
flat(value(child.$if, scope)),
|
|
303
|
+
childExpr(child.then, scope, slot),
|
|
304
|
+
otherwise,
|
|
292
305
|
);
|
|
293
306
|
}
|
|
294
|
-
|
|
307
|
+
case 'slot':
|
|
308
|
+
return isObject(child.input)
|
|
309
|
+
? call(`slots.${child.$slot}(`, value(child.input, scope))
|
|
310
|
+
: raw(`slots.${child.$slot}()`);
|
|
311
|
+
default:
|
|
312
|
+
return nodeExpr(child, scope, undefined, slot);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const eachExpr = (child, scope, slot) => {
|
|
317
|
+
const inner = new Map(scope).set(child.as, true);
|
|
318
|
+
const template =
|
|
319
|
+
'templates' in child
|
|
320
|
+
? kindExpr(child, inner, child.key, slot)
|
|
321
|
+
: rowExpr(child.template, inner, child.key, slot);
|
|
322
|
+
// Scope holds only `$each` items, so a non-empty scope is a row
|
|
323
|
+
// template. kerf never reconciles a list inside a row (a keyed each()
|
|
324
|
+
// there throws), so an inner repeat is a plain map that re-renders with
|
|
325
|
+
// its row (KF-CFA1S1).
|
|
326
|
+
if (scope.size > 0) {
|
|
295
327
|
return call(
|
|
296
|
-
|
|
328
|
+
`${flat(value(child.$each, scope))}.map((${child.as}) => `,
|
|
297
329
|
template,
|
|
298
|
-
`, { key: ${literal(child.template.id)} })`,
|
|
299
330
|
);
|
|
300
331
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
332
|
+
imports.value('kerfjs', 'each');
|
|
333
|
+
return call(
|
|
334
|
+
`each(${flat(value(child.$each, scope))}, (${child.as}) => `,
|
|
335
|
+
template,
|
|
336
|
+
`, { key: ${literal(eachNodes(child)[0].id)} })`,
|
|
337
|
+
);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// A row: the template node, or the branch its `$if` chain picks per item
|
|
341
|
+
// (KF-8J8E5V). Every branch is a keyed node, and `else` is required.
|
|
342
|
+
const rowExpr = (template, scope, rowKey, slot) =>
|
|
343
|
+
'$if' in template
|
|
344
|
+
? cond(
|
|
345
|
+
flat(value(template.$if, scope)),
|
|
346
|
+
rowExpr(template.then, scope, rowKey, slot),
|
|
347
|
+
rowExpr(template.else, scope, rowKey, slot),
|
|
348
|
+
)
|
|
349
|
+
: nodeExpr(template, scope, rowKey, slot);
|
|
350
|
+
|
|
351
|
+
// KF-YX6HMT: the template an item's `kind` picks from `templates`, one
|
|
352
|
+
// comparison per kind in document order, with `default` for the rest.
|
|
353
|
+
const kindExpr = (child, scope, rowKey, slot) => {
|
|
354
|
+
const kind = flat(value(child.kind, scope));
|
|
355
|
+
return Object.entries(child.templates)
|
|
356
|
+
.filter(([name]) => name !== 'default')
|
|
357
|
+
.reduceRight(
|
|
358
|
+
(otherwise, [name, node]) =>
|
|
359
|
+
cond(
|
|
360
|
+
`${kind} === ${literal(name)}`,
|
|
361
|
+
nodeExpr(node, scope, rowKey, slot),
|
|
362
|
+
otherwise,
|
|
363
|
+
),
|
|
364
|
+
nodeExpr(child.templates.default, scope, rowKey, slot),
|
|
308
365
|
);
|
|
309
|
-
}
|
|
310
|
-
if ('$slot' in child) {
|
|
311
|
-
return isObject(child.input)
|
|
312
|
-
? call(`slots.${child.$slot}(`, value(child.input, scope))
|
|
313
|
-
: raw(`slots.${child.$slot}()`);
|
|
314
|
-
}
|
|
315
|
-
return nodeExpr(child, scope, undefined, slot);
|
|
316
366
|
};
|
|
317
367
|
|
|
318
368
|
const nodeExpr = (node, scope, rowKey, slot) => {
|
|
@@ -332,6 +382,20 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
332
382
|
const child = document.views[node.src];
|
|
333
383
|
const names = namesOf(child.name);
|
|
334
384
|
imports.value(viewImport(node.src), names.render);
|
|
385
|
+
// A composed row's root carries the row's key (KF-EP2152); a composed
|
|
386
|
+
// document has no slots, so the second argument is always empty.
|
|
387
|
+
if (rowKey === ROOT_KEY)
|
|
388
|
+
return call(
|
|
389
|
+
`${names.render}(`,
|
|
390
|
+
value(node.props ?? {}, scope),
|
|
391
|
+
', {}, rowKey)',
|
|
392
|
+
);
|
|
393
|
+
if (rowKey)
|
|
394
|
+
return call(
|
|
395
|
+
`${names.render}(`,
|
|
396
|
+
value(node.props ?? {}, scope),
|
|
397
|
+
`, {}, String(${rowKey}))`,
|
|
398
|
+
);
|
|
335
399
|
return call(`${names.render}(`, value(node.props ?? {}, scope));
|
|
336
400
|
}
|
|
337
401
|
const { component: definition, definitions } = catalog.components.get(
|
|
@@ -351,7 +415,7 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
351
415
|
}
|
|
352
416
|
if (definition.source === 'webawesome') {
|
|
353
417
|
entries.push(["'data-kerf-node'", raw(literal(node.id))]);
|
|
354
|
-
|
|
418
|
+
entries.push(...keyEntries(rowKey));
|
|
355
419
|
if (slot) entries.push(['slot', raw(literal(slot))]);
|
|
356
420
|
const parts = Object.keys(zones)
|
|
357
421
|
.sort()
|
|
@@ -386,16 +450,23 @@ function createEmitter(document, catalog, imports, importFrom) {
|
|
|
386
450
|
} else if (channel === 'native') {
|
|
387
451
|
// The component passes data-* props straight through to its root.
|
|
388
452
|
entries.push(["'data-kerf-node'", raw(literal(node.id))]);
|
|
389
|
-
|
|
453
|
+
entries.push(...keyEntries(rowKey));
|
|
390
454
|
}
|
|
391
455
|
imports.value(
|
|
392
456
|
moduleSpecifier(definition.import, importFrom),
|
|
393
457
|
definition.export,
|
|
394
458
|
);
|
|
395
|
-
|
|
459
|
+
// Rollup's effect analysis recursively walks direct component calls in
|
|
460
|
+
// large generated trees. A curried typed boundary preserves the exact
|
|
461
|
+
// call while keeping that analysis linear for the catalog bundle.
|
|
462
|
+
usesKerfComponent = true;
|
|
463
|
+
return call(`kuiComponent(${definition.export})(`, obj(entries));
|
|
396
464
|
};
|
|
397
465
|
|
|
398
|
-
return {
|
|
466
|
+
return {
|
|
467
|
+
root: (node) => nodeExpr(node, new Map(), ROOT_KEY, undefined),
|
|
468
|
+
usesKerfComponent: () => usesKerfComponent,
|
|
469
|
+
};
|
|
399
470
|
}
|
|
400
471
|
|
|
401
472
|
function typesBlock(name, contract, inputType = (input) => input.type) {
|
|
@@ -456,6 +527,11 @@ function typesBlock(name, contract, inputType = (input) => input.type) {
|
|
|
456
527
|
.join('\n')}\n}`
|
|
457
528
|
: `export type ${name}Refs = Readonly<Record<string, never>>;`,
|
|
458
529
|
);
|
|
530
|
+
// KF-YX6HMT: the kinds a `templates` repeat renders, by its item name.
|
|
531
|
+
for (const [as, kinds] of Object.entries(contract.kinds ?? {}))
|
|
532
|
+
lines.push(
|
|
533
|
+
`/** The \`kind\` values with a row design of their own; any other takes \`default\`. */\nexport type ${name}${as[0].toUpperCase()}${as.slice(1)}Kind = ${kinds.map(literal).join(' | ')};`,
|
|
534
|
+
);
|
|
459
535
|
return lines.join('\n\n');
|
|
460
536
|
}
|
|
461
537
|
|
|
@@ -480,7 +556,7 @@ function functionsBlock(name, contract, rootExpr, ts) {
|
|
|
480
556
|
const slotsDefault =
|
|
481
557
|
Object.keys(contract.slots).length === 0 ? ' = {}' : '';
|
|
482
558
|
blocks.push(
|
|
483
|
-
`export function render${name}(inputs${t(`: ${name}Inputs`)}${inputsDefault}, slots${t(`: ${name}Slots`)}${slotsDefault})${t(': SafeHtml')} {\n${unused(rootExpr, 'inputs', 'slots')} return ${rootExpr};\n}`,
|
|
559
|
+
`export function render${name}(inputs${t(`: ${name}Inputs`)}${inputsDefault}, slots${t(`: ${name}Slots`)}${slotsDefault}, rowKey${t('?: string')})${t(': SafeHtml')} {\n${unused(rootExpr, 'inputs', 'slots', 'rowKey')} return ${rootExpr};\n}`,
|
|
484
560
|
);
|
|
485
561
|
}
|
|
486
562
|
const handlerLines = actions.map(([key, scope]) => {
|
|
@@ -530,7 +606,7 @@ function declarationsBlock(name, contract, includeRender) {
|
|
|
530
606
|
: '';
|
|
531
607
|
const slotsDefault = Object.keys(contract.slots).length === 0 ? '?' : '';
|
|
532
608
|
lines.push(
|
|
533
|
-
`export declare function render${name}(inputs${inputsDefault}: ${name}Inputs, slots${slotsDefault}: ${name}Slots): SafeHtml;`,
|
|
609
|
+
`export declare function render${name}(inputs${inputsDefault}: ${name}Inputs, slots${slotsDefault}: ${name}Slots, rowKey?: string): SafeHtml;`,
|
|
534
610
|
);
|
|
535
611
|
}
|
|
536
612
|
lines.push(
|
|
@@ -544,7 +620,7 @@ function declarationsBlock(name, contract, includeRender) {
|
|
|
544
620
|
|
|
545
621
|
/**
|
|
546
622
|
* Generates a view module. `options.source` names the document file in the
|
|
547
|
-
* header; `options.resolveView(src)` loads composed documents (required when
|
|
623
|
+
* header; `options.resolveView(src, path)` loads composed documents (required when
|
|
548
624
|
* the document has `#view` nodes); `options.target` is `ts` (default) or `js`;
|
|
549
625
|
* `options.declarationsOnly` omits `render<Name>` for documents an app loads
|
|
550
626
|
* at runtime through `interpretView`.
|
|
@@ -567,30 +643,42 @@ export function generateView(document, catalog, options = {}) {
|
|
|
567
643
|
const views = {};
|
|
568
644
|
const collectViews = (node) => {
|
|
569
645
|
if (!isObject(node)) return;
|
|
570
|
-
if (node.type === '#view')
|
|
646
|
+
if (node.type === '#view')
|
|
647
|
+
views[node.src] = options.resolveView(
|
|
648
|
+
node.src,
|
|
649
|
+
composedViewPath(undefined, node.src),
|
|
650
|
+
);
|
|
571
651
|
for (const list of Object.values(isObject(node.zones) ? node.zones : {})) {
|
|
572
652
|
for (const child of list) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
653
|
+
switch (childKind(child)) {
|
|
654
|
+
case 'each':
|
|
655
|
+
eachNodes(child).forEach(collectViews);
|
|
656
|
+
break;
|
|
657
|
+
case 'if':
|
|
658
|
+
collectViews(child.then);
|
|
659
|
+
collectViews(child.else);
|
|
660
|
+
break;
|
|
661
|
+
case 'slot':
|
|
662
|
+
break;
|
|
663
|
+
default:
|
|
664
|
+
collectViews(child);
|
|
665
|
+
}
|
|
578
666
|
}
|
|
579
667
|
}
|
|
580
668
|
};
|
|
581
669
|
collectViews(document.root);
|
|
582
670
|
|
|
583
671
|
let rootExpr;
|
|
672
|
+
let usesKerfComponent = false;
|
|
584
673
|
if (!options.declarationsOnly) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
options.importFrom,
|
|
591
|
-
).root(document.root),
|
|
592
|
-
2,
|
|
674
|
+
const emitter = createEmitter(
|
|
675
|
+
{ ...document, views },
|
|
676
|
+
catalog,
|
|
677
|
+
imports,
|
|
678
|
+
options.importFrom,
|
|
593
679
|
);
|
|
680
|
+
rootExpr = printDoc(emitter.root(document.root), 2);
|
|
681
|
+
usesKerfComponent = emitter.usesKerfComponent();
|
|
594
682
|
}
|
|
595
683
|
const digest = contractDigest(contract);
|
|
596
684
|
const sourceDigest = viewDigest(canonicalJson(document));
|
|
@@ -607,6 +695,11 @@ export function generateView(document, catalog, options = {}) {
|
|
|
607
695
|
return `Parameters<typeof ${owner.export}>[0][${literal(input.shape.prop)}]`;
|
|
608
696
|
});
|
|
609
697
|
const contractLine = `export const ${camel}Contract = ${literal(digest)};`;
|
|
698
|
+
const componentHelper = usesKerfComponent
|
|
699
|
+
? target === 'ts'
|
|
700
|
+
? 'function kuiComponent<P>(component: (props: P) => SafeHtml): (props: P) => SafeHtml {\n return (props) => component(props);\n}'
|
|
701
|
+
: 'function kuiComponent(component) {\n return (props) => component(props);\n}'
|
|
702
|
+
: undefined;
|
|
610
703
|
|
|
611
704
|
const assemble = (body) =>
|
|
612
705
|
`${header(sourceName, contract, sourceDigest, body)}\n${body}`;
|
|
@@ -615,15 +708,21 @@ export function generateView(document, catalog, options = {}) {
|
|
|
615
708
|
imports.render(true),
|
|
616
709
|
types,
|
|
617
710
|
contractLine,
|
|
711
|
+
componentHelper,
|
|
618
712
|
functionsBlock(name, contract, rootExpr, true),
|
|
619
|
-
]
|
|
713
|
+
]
|
|
714
|
+
.filter(Boolean)
|
|
715
|
+
.join('\n\n');
|
|
620
716
|
return { code: assemble(`${body}\n`), contract, digest };
|
|
621
717
|
}
|
|
622
718
|
const code = [
|
|
623
719
|
imports.render(false),
|
|
624
720
|
contractLine,
|
|
721
|
+
componentHelper,
|
|
625
722
|
functionsBlock(name, contract, rootExpr, false),
|
|
626
|
-
]
|
|
723
|
+
]
|
|
724
|
+
.filter(Boolean)
|
|
725
|
+
.join('\n\n');
|
|
627
726
|
const dts = [
|
|
628
727
|
`import type { SafeHtml } from 'kerfjs';`,
|
|
629
728
|
types,
|