@kerfjs/ui 5.0.0-beta.125 → 5.0.0-beta.126
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 +245 -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 +246 -295
- 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 +11 -8
- 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-3SCGTP5O.js +682 -0
- package/dist/chunk-3SCGTP5O.js.map +1 -0
- 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-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-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-BCO673YW.js → chunk-Z3BT2SZE.js} +3 -3
- package/dist/chunk-Z3BT2SZE.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 +2 -2
- package/dist/column-explorer.js +2 -2
- 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 +10855 -6979
- 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 +2 -2
- package/dist/styles/components/surfaces/surface-scaffold/surface-scaffold.css +259 -4
- package/dist/styles/editor/editor.css +55 -0
- package/dist/styles/editor-frame.css +2 -2
- 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 +259 -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 +153 -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 +2 -2
- package/dist/tree-list.js +1 -1
- 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-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 +295 -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 +3 -1
- package/props/cli.mjs +47 -21
- package/scripts/lib/cli-args.mjs +98 -0
- package/ux-demo/recipes/compact-toolbar.tsx +1 -1
- package/ux-demo/recipes/loading-inspector.tsx +1 -1
- 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 +122 -43
- 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-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/validate.mjs
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
// validateView: checks a Kerf UI view document (kerf-ui-document/v1, see
|
|
2
2
|
// docs/26-ui-editor.md) against the component-props and composition
|
|
3
3
|
// catalogs. Pure and synchronous, with no Node APIs, so the editor runs it in
|
|
4
|
-
// the browser and the CLI runs it in Node.
|
|
4
|
+
// the browser and the CLI runs it in Node. The catalog index, the type
|
|
5
|
+
// system, and the `$css` grammar it checks against live in catalog.mjs,
|
|
6
|
+
// types.mjs, and css-grammar.mjs.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
channelOf,
|
|
10
|
+
fieldParent,
|
|
11
|
+
fieldZoneOf,
|
|
12
|
+
isBinding,
|
|
13
|
+
isObject,
|
|
14
|
+
keyOf,
|
|
15
|
+
propsOf,
|
|
16
|
+
quoteValue,
|
|
17
|
+
resolveType,
|
|
18
|
+
withFieldZones,
|
|
19
|
+
} from './catalog.mjs';
|
|
20
|
+
import { childKind } from './child-kind.mjs';
|
|
21
|
+
import { CSS_HELPERS, parseCssCall } from './css-grammar.mjs';
|
|
22
|
+
import { ICON_NAME, isAssignable, isLiteralOf, literalOf } from './types.mjs';
|
|
5
23
|
|
|
6
24
|
export const VIEW_DOCUMENT_SCHEMA_ID = 'kerf-ui-document/v1';
|
|
7
25
|
|
|
@@ -10,28 +28,8 @@ const CAMEL = /^[a-z][A-Za-z0-9]*$/;
|
|
|
10
28
|
const PASCAL = /^[A-Z][A-Za-z0-9]*$/;
|
|
11
29
|
const ACTION_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
12
30
|
const ACTION_PROP = /^action$|[a-z]Action$/;
|
|
13
|
-
const ICON_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
14
31
|
// Loop variable names the generated module already uses.
|
|
15
32
|
const RESERVED_NAMES = new Set(['inputs', 'slots', 'each', 'handlers']);
|
|
16
|
-
// Every builder `@kerfjs/ui/css-values` exports; a css-value prop without a
|
|
17
|
-
// catalog `cssValue` restriction accepts any of them.
|
|
18
|
-
const CSS_HELPERS = [
|
|
19
|
-
'calc',
|
|
20
|
-
'colorVar',
|
|
21
|
-
'em',
|
|
22
|
-
'fillColor',
|
|
23
|
-
'flex',
|
|
24
|
-
'foregroundColor',
|
|
25
|
-
'foregroundColorVar',
|
|
26
|
-
'lengthVar',
|
|
27
|
-
'pct',
|
|
28
|
-
'plus',
|
|
29
|
-
'px',
|
|
30
|
-
'rem',
|
|
31
|
-
'remify',
|
|
32
|
-
'space',
|
|
33
|
-
'uiColor',
|
|
34
|
-
];
|
|
35
33
|
const PARAM_KINDS = new Set([
|
|
36
34
|
'string',
|
|
37
35
|
'number',
|
|
@@ -47,432 +45,8 @@ const PARAM_KINDS = new Set([
|
|
|
47
45
|
'prop',
|
|
48
46
|
]);
|
|
49
47
|
|
|
50
|
-
const isObject = (value) =>
|
|
51
|
-
value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
52
48
|
const only = (value, keys) =>
|
|
53
49
|
Object.keys(value).filter((key) => !keys.includes(key));
|
|
54
|
-
const keyOf = (type) => type.split('#')[0];
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Indexes component-props and composition documents for validation. Each
|
|
58
|
-
* component keeps the `definitions` table of the document that declared it,
|
|
59
|
-
* so two packages' same-named types never collide.
|
|
60
|
-
*/
|
|
61
|
-
export function createViewCatalog({ props = [], composition = [] }) {
|
|
62
|
-
const components = new Map();
|
|
63
|
-
for (const document of props) {
|
|
64
|
-
for (const component of document.components ?? []) {
|
|
65
|
-
components.set(component.key, {
|
|
66
|
-
component,
|
|
67
|
-
definitions: document.definitions ?? {},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const entries = new Map();
|
|
72
|
-
// A config type another component renders as an entry (KF-THTR71), keyed
|
|
73
|
-
// `package:TypeName` since type names are only unique within a package.
|
|
74
|
-
const configParents = new Map();
|
|
75
|
-
for (const document of composition) {
|
|
76
|
-
for (const entry of document.entries ?? []) {
|
|
77
|
-
entries.set(entry.key, entry);
|
|
78
|
-
for (const name of entry.configTypes ?? [])
|
|
79
|
-
configParents.set(
|
|
80
|
-
`${keyOf(entry.key).split(':')[0]}:${name}`,
|
|
81
|
-
entry.key,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return { components, entries, configParents };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function resolveType(type, definitions) {
|
|
89
|
-
let current = type;
|
|
90
|
-
for (let hops = 0; current?.kind === 'ref' && hops < 32; hops += 1) {
|
|
91
|
-
current = definitions[current.ref];
|
|
92
|
-
}
|
|
93
|
-
return current ?? { kind: 'unknown' };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const propsOf = (type, definitions) => resolveType(type, definitions).props;
|
|
97
|
-
|
|
98
|
-
/** A type, or each member of a union of it (unions of unions flattened). */
|
|
99
|
-
function membersOf(type, definitions) {
|
|
100
|
-
const resolved = resolveType(type, definitions);
|
|
101
|
-
return resolved.kind === 'union'
|
|
102
|
-
? resolved.members.flatMap((member) => membersOf(member, definitions))
|
|
103
|
-
: [resolved];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const INDEX = /^\d+$/;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A zone key that names a content field inside a prop value (KF-PD6QC5:
|
|
110
|
-
* field zones): the prop, then field names and list indexes, dot-separated
|
|
111
|
-
* (`leftRail.content`, `mainToolbar.title`, `views.0.content`). Walks the
|
|
112
|
-
* prop's type through refs, union members, objects (never a field the type
|
|
113
|
-
* forbids), and lists, and ends at rendered content. Returns the prop, the
|
|
114
|
-
* path inside its value, and whether the field takes text; undefined for any
|
|
115
|
-
* other key.
|
|
116
|
-
*/
|
|
117
|
-
export function fieldZoneOf(component, definitions, key) {
|
|
118
|
-
const walked = walkField(component, definitions, key);
|
|
119
|
-
if (!walked) return undefined;
|
|
120
|
-
const content = walked.types
|
|
121
|
-
.flatMap((type) => membersOf(type, definitions))
|
|
122
|
-
.find((type) => type.kind === 'content');
|
|
123
|
-
return content
|
|
124
|
-
? {
|
|
125
|
-
prop: walked.name,
|
|
126
|
-
path: walked.path.map((step) =>
|
|
127
|
-
INDEX.test(step) ? Number(step) : step,
|
|
128
|
-
),
|
|
129
|
-
text: content.acceptsText === true,
|
|
130
|
-
}
|
|
131
|
-
: undefined;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The types a field zone key reaches in a component's prop value, with the
|
|
136
|
-
* named types (`ref`s) of the value that holds that field: a NavStack view's
|
|
137
|
-
* `views.0.toolbar.leading` is held by a `NavStackViewToolbar`.
|
|
138
|
-
*/
|
|
139
|
-
function walkField(component, definitions, key) {
|
|
140
|
-
if (typeof key !== 'string' || !key.includes('.')) return undefined;
|
|
141
|
-
const [name, ...path] = key.split('.');
|
|
142
|
-
const prop = component.props.find((item) => item.name === name);
|
|
143
|
-
if (!prop || prop.slot || prop.zone) return undefined;
|
|
144
|
-
let types = [prop.type];
|
|
145
|
-
let holders = [];
|
|
146
|
-
for (const step of path) {
|
|
147
|
-
holders = types.flatMap((type) => (type.kind === 'ref' ? [type.ref] : []));
|
|
148
|
-
const next = [];
|
|
149
|
-
for (const type of types.flatMap((item) => membersOf(item, definitions))) {
|
|
150
|
-
if (INDEX.test(step)) {
|
|
151
|
-
if (type.kind === 'array') next.push(type.items);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const field =
|
|
155
|
-
type.kind === 'object'
|
|
156
|
-
? type.props?.find((item) => item.name === step)
|
|
157
|
-
: undefined;
|
|
158
|
-
if (field && resolveType(field.type, definitions).kind !== 'never')
|
|
159
|
-
next.push(field.type);
|
|
160
|
-
}
|
|
161
|
-
if (!next.length) return undefined;
|
|
162
|
-
types = next;
|
|
163
|
-
}
|
|
164
|
-
return { name, path, types, holders };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The component a field zone's children are placed in (KF-THTR71): a
|
|
169
|
-
* content field inside a value another component renders, such as a
|
|
170
|
-
* NavStack view's toolbar config, which renders as a Toolbar. A config type
|
|
171
|
-
* may name one field (`ListDetailDialogList.toolbar`) when only that field
|
|
172
|
-
* renders in the component. Undefined when neither the field nor its holder
|
|
173
|
-
* is cataloged.
|
|
174
|
-
*/
|
|
175
|
-
function fieldParent(ctx, node, component, definitions, key) {
|
|
176
|
-
const pkg = keyOf(node.type).split(':')[0];
|
|
177
|
-
const walked = walkField(component, definitions, key);
|
|
178
|
-
const field = walked?.path.at(-1);
|
|
179
|
-
for (const holder of walked?.holders ?? []) {
|
|
180
|
-
// KF-WBH5P2: one field of a holder that renders only that field in
|
|
181
|
-
// another component (`ListDetailDialogList.toolbar` in a Toolbar)
|
|
182
|
-
// names it alone; the whole holder's mapping is the fallback.
|
|
183
|
-
const parent =
|
|
184
|
-
ctx.catalog.configParents?.get(`${pkg}:${holder}.${field}`) ??
|
|
185
|
-
ctx.catalog.configParents?.get(`${pkg}:${holder}`);
|
|
186
|
-
if (parent) return parent;
|
|
187
|
-
}
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Where a field zone's children go in a prop value while it is checked,
|
|
193
|
-
* interpreted, or generated: a placeholder no document can spell, so it
|
|
194
|
-
* never reads as a literal of the document's own.
|
|
195
|
-
*/
|
|
196
|
-
export class ZoneFill {
|
|
197
|
-
constructor(key, children) {
|
|
198
|
-
this.key = key;
|
|
199
|
-
this.children = children;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* A prop value as a problem quotes it: JSON, with each field zone written as
|
|
205
|
-
* `<zone key>` rather than its nodes (KF-20GMVX), so the message stays short
|
|
206
|
-
* and does not change when something inside the zone does.
|
|
207
|
-
*/
|
|
208
|
-
function quoteValue(value) {
|
|
209
|
-
return JSON.stringify(value, (_key, item) =>
|
|
210
|
-
item instanceof ZoneFill ? `<zone ${item.key}>` : item,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** `value` with `fill` at `path`, copying each object and list on the way. */
|
|
215
|
-
function withAt(value, path, fill) {
|
|
216
|
-
if (!path.length) return fill;
|
|
217
|
-
const [step, ...rest] = path;
|
|
218
|
-
if (typeof step === 'number') {
|
|
219
|
-
const list = Array.isArray(value) ? [...value] : [];
|
|
220
|
-
list[step] = withAt(list[step], rest, fill);
|
|
221
|
-
return list;
|
|
222
|
-
}
|
|
223
|
-
const object = isObject(value) ? { ...value } : {};
|
|
224
|
-
object[step] = withAt(object[step], rest, fill);
|
|
225
|
-
return object;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** Whether a value is a binding (`$param`, `$bind`, …) rather than a literal. */
|
|
229
|
-
const isBinding = (value) =>
|
|
230
|
-
isObject(value) && Object.keys(value).some((key) => key.startsWith('$'));
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* `props` with each filled field zone's placeholder (a `ZoneFill`) at its
|
|
234
|
-
* path, so the zone fills that content field (KF-PD6QC5). A prop held by a
|
|
235
|
-
* binding is left alone; validation reports the clash.
|
|
236
|
-
*/
|
|
237
|
-
export function withFieldZones(props, zones, component, definitions) {
|
|
238
|
-
let merged = props;
|
|
239
|
-
for (const key of Object.keys(zones)) {
|
|
240
|
-
const field = fieldZoneOf(component, definitions, key);
|
|
241
|
-
if (!field || !zones[key].length || isBinding(merged[field.prop])) continue;
|
|
242
|
-
merged = {
|
|
243
|
-
...merged,
|
|
244
|
-
[field.prop]: withAt(
|
|
245
|
-
merged[field.prop],
|
|
246
|
-
field.path,
|
|
247
|
-
new ZoneFill(key, zones[key]),
|
|
248
|
-
),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
return merged;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** Whether a value of type `from` (a param or binding) fits type `to`. */
|
|
255
|
-
export function isAssignable(from, to, definitions = {}) {
|
|
256
|
-
// A component prop's type fits only that same component prop.
|
|
257
|
-
if (from?.kind === 'prop' || to?.kind === 'prop')
|
|
258
|
-
return (
|
|
259
|
-
from?.kind === to?.kind &&
|
|
260
|
-
from.component === to.component &&
|
|
261
|
-
from.prop === to.prop
|
|
262
|
-
);
|
|
263
|
-
const target = resolveType(to, definitions);
|
|
264
|
-
const source = resolveType(from, definitions);
|
|
265
|
-
if (target.kind === 'unknown' || source.kind === 'unknown') return true;
|
|
266
|
-
if (target.kind === 'union') {
|
|
267
|
-
return target.members.some((member) =>
|
|
268
|
-
isAssignable(source, member, definitions),
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
const values =
|
|
272
|
-
source.kind === 'enum'
|
|
273
|
-
? source.values
|
|
274
|
-
: source.kind === 'literal'
|
|
275
|
-
? [source.value]
|
|
276
|
-
: undefined;
|
|
277
|
-
if (values) {
|
|
278
|
-
if (target.kind === 'enum') {
|
|
279
|
-
return values.every((value) => target.values.includes(value));
|
|
280
|
-
}
|
|
281
|
-
if (target.kind === 'literal') {
|
|
282
|
-
return values.length === 1 && values[0] === target.value;
|
|
283
|
-
}
|
|
284
|
-
return values.every((value) => isLiteralOf(value, target, definitions));
|
|
285
|
-
}
|
|
286
|
-
switch (source.kind) {
|
|
287
|
-
case 'string':
|
|
288
|
-
case 'number':
|
|
289
|
-
return (
|
|
290
|
-
target.kind === source.kind ||
|
|
291
|
-
(target.kind === 'content' && target.acceptsText === true)
|
|
292
|
-
);
|
|
293
|
-
case 'boolean':
|
|
294
|
-
case 'content':
|
|
295
|
-
return target.kind === source.kind;
|
|
296
|
-
case 'array':
|
|
297
|
-
return (
|
|
298
|
-
target.kind === 'array' &&
|
|
299
|
-
isAssignable(source.items, target.items, definitions)
|
|
300
|
-
);
|
|
301
|
-
case 'object': {
|
|
302
|
-
if (target.kind === 'record') return true;
|
|
303
|
-
if (target.kind !== 'object') return false;
|
|
304
|
-
const given = new Map(
|
|
305
|
-
(source.props ?? []).map((prop) => [prop.name, prop]),
|
|
306
|
-
);
|
|
307
|
-
return (target.props ?? []).every((prop) => {
|
|
308
|
-
const match = given.get(prop.name);
|
|
309
|
-
if (!match) return !prop.required;
|
|
310
|
-
return (
|
|
311
|
-
(match.required || !prop.required) &&
|
|
312
|
-
isAssignable(match.type, prop.type, definitions)
|
|
313
|
-
);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
default:
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Whether a JSON literal is a valid value of a type descriptor. */
|
|
322
|
-
export function isLiteralOf(value, type, definitions = {}) {
|
|
323
|
-
return literalOf(value, type, definitions);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* `isLiteralOf`, with `hooks` for the forms a prop value may nest:
|
|
328
|
-
* `hooks.slot` decides a `{ $slot }` at a content-typed position (KF-SXDM56:
|
|
329
|
-
* item slots), and `hooks.dynamic` a `{ $param }` / `{ $bind }` at any typed
|
|
330
|
-
* position against that position's type (KF-3QEZFB: nested params). Without
|
|
331
|
-
* them, neither is a literal.
|
|
332
|
-
*/
|
|
333
|
-
function literalOf(value, type, definitions, hooks) {
|
|
334
|
-
if (
|
|
335
|
-
hooks?.dynamic &&
|
|
336
|
-
isObject(value) &&
|
|
337
|
-
('$param' in value || '$bind' in value)
|
|
338
|
-
)
|
|
339
|
-
return hooks.dynamic(value, type);
|
|
340
|
-
const target = resolveType(type, definitions);
|
|
341
|
-
if (value === null) return target.nullable === true;
|
|
342
|
-
switch (target.kind) {
|
|
343
|
-
case 'unknown':
|
|
344
|
-
return true;
|
|
345
|
-
case 'union':
|
|
346
|
-
return target.members.some((member) =>
|
|
347
|
-
literalOf(value, member, definitions, hooks),
|
|
348
|
-
);
|
|
349
|
-
case 'string':
|
|
350
|
-
return typeof value === 'string';
|
|
351
|
-
case 'number':
|
|
352
|
-
return typeof value === 'number' && Number.isFinite(value);
|
|
353
|
-
case 'boolean':
|
|
354
|
-
return typeof value === 'boolean';
|
|
355
|
-
case 'enum':
|
|
356
|
-
return target.values.includes(value);
|
|
357
|
-
case 'literal':
|
|
358
|
-
return value === target.value;
|
|
359
|
-
// A builder call inside a list or object value (KF-3J9GJV).
|
|
360
|
-
case 'css-value':
|
|
361
|
-
return isObject(value) && parseCssCall(value.$css) !== undefined;
|
|
362
|
-
case 'content':
|
|
363
|
-
if (value instanceof ZoneFill) return true;
|
|
364
|
-
if (hooks?.slot && isObject(value) && '$slot' in value)
|
|
365
|
-
return hooks.slot(value);
|
|
366
|
-
return (
|
|
367
|
-
target.acceptsText === true &&
|
|
368
|
-
(typeof value === 'string' || typeof value === 'number')
|
|
369
|
-
);
|
|
370
|
-
case 'array':
|
|
371
|
-
return (
|
|
372
|
-
Array.isArray(value) &&
|
|
373
|
-
value.every((item) => literalOf(item, target.items, definitions, hooks))
|
|
374
|
-
);
|
|
375
|
-
case 'record':
|
|
376
|
-
return (
|
|
377
|
-
isObject(value) &&
|
|
378
|
-
Object.values(value).every((item) => typeof item === 'string')
|
|
379
|
-
);
|
|
380
|
-
case 'object': {
|
|
381
|
-
if (!isObject(value)) return false;
|
|
382
|
-
const known = new Map(
|
|
383
|
-
(target.props ?? []).map((prop) => [prop.name, prop]),
|
|
384
|
-
);
|
|
385
|
-
const { index } = target;
|
|
386
|
-
return (
|
|
387
|
-
Object.entries(value).every(([name, item]) =>
|
|
388
|
-
known.has(name)
|
|
389
|
-
? // An icon-data field names its icon (KF-3J9GJV).
|
|
390
|
-
(known.get(name).iconSource &&
|
|
391
|
-
ICON_NAME.test(item?.$icon ?? '')) ||
|
|
392
|
-
literalOf(item, known.get(name).type, definitions, hooks)
|
|
393
|
-
: index !== undefined &&
|
|
394
|
-
name.startsWith(index.keyPrefix) &&
|
|
395
|
-
literalOf(item, index.value, definitions, hooks),
|
|
396
|
-
) &&
|
|
397
|
-
[...known.values()].every(
|
|
398
|
-
(prop) => !prop.required || prop.name in value,
|
|
399
|
-
)
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
default:
|
|
403
|
-
return false;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Parses a `$css` builder call with literal arguments only: numbers, quoted
|
|
409
|
-
* strings without quotes or backslashes inside, and nested builder calls.
|
|
410
|
-
* Generated code emits the call verbatim and the interpreter evaluates the
|
|
411
|
-
* tree, so anything else (an identifier, an operator, a template) is rejected
|
|
412
|
-
* rather than trusted. Returns `{ name, args }` (each argument a number,
|
|
413
|
-
* string, or nested call), or undefined when it does not parse.
|
|
414
|
-
*/
|
|
415
|
-
export function parseCssTree(source) {
|
|
416
|
-
if (typeof source !== 'string') return undefined;
|
|
417
|
-
const text = source.trim();
|
|
418
|
-
let index = 0;
|
|
419
|
-
const space = () => {
|
|
420
|
-
while (text[index] === ' ') index += 1;
|
|
421
|
-
};
|
|
422
|
-
const call = () => {
|
|
423
|
-
const name = /^[A-Za-z]+/.exec(text.slice(index))?.[0];
|
|
424
|
-
if (!name || text[index + name.length] !== '(') return undefined;
|
|
425
|
-
const node = { name, args: [] };
|
|
426
|
-
index += name.length + 1;
|
|
427
|
-
space();
|
|
428
|
-
if (text[index] === ')') {
|
|
429
|
-
index += 1;
|
|
430
|
-
return node;
|
|
431
|
-
}
|
|
432
|
-
for (;;) {
|
|
433
|
-
space();
|
|
434
|
-
const value = argument();
|
|
435
|
-
if (value === undefined) return undefined;
|
|
436
|
-
node.args.push(value);
|
|
437
|
-
space();
|
|
438
|
-
if (text[index] === ',') index += 1;
|
|
439
|
-
else if (text[index] === ')') {
|
|
440
|
-
index += 1;
|
|
441
|
-
return node;
|
|
442
|
-
} else return undefined;
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
const argument = () => {
|
|
446
|
-
const rest = text.slice(index);
|
|
447
|
-
const number = /^-?\d+(?:\.\d+)?/.exec(rest)?.[0];
|
|
448
|
-
if (number) {
|
|
449
|
-
index += number.length;
|
|
450
|
-
return Number(number);
|
|
451
|
-
}
|
|
452
|
-
const quoted =
|
|
453
|
-
/^'[^'\\\n]*'/.exec(rest)?.[0] ?? /^"[^"\\\n]*"/.exec(rest)?.[0];
|
|
454
|
-
if (quoted) {
|
|
455
|
-
index += quoted.length;
|
|
456
|
-
return quoted.slice(1, -1);
|
|
457
|
-
}
|
|
458
|
-
return call();
|
|
459
|
-
};
|
|
460
|
-
const tree = call();
|
|
461
|
-
return tree && index === text.length ? tree : undefined;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/** The helper names a `$css` call uses, outermost first, or undefined. */
|
|
465
|
-
export function parseCssCall(source) {
|
|
466
|
-
const tree = parseCssTree(source);
|
|
467
|
-
if (!tree) return undefined;
|
|
468
|
-
const names = [];
|
|
469
|
-
const visit = (node) => {
|
|
470
|
-
names.push(node.name);
|
|
471
|
-
for (const arg of node.args) if (typeof arg === 'object') visit(arg);
|
|
472
|
-
};
|
|
473
|
-
visit(tree);
|
|
474
|
-
return names;
|
|
475
|
-
}
|
|
476
50
|
|
|
477
51
|
// Optional props print as `T | undefined`; messages name the type itself.
|
|
478
52
|
function describe(type) {
|
|
@@ -773,28 +347,6 @@ export function dataAttributeProblem(key) {
|
|
|
773
347
|
return `"${key}" is reserved for the generated view and the editor`;
|
|
774
348
|
}
|
|
775
349
|
|
|
776
|
-
/**
|
|
777
|
-
* How a component carries application `data-*` attributes (the node marker
|
|
778
|
-
* and a row key): its `rootAttributes` prop, a Web Awesome element's own
|
|
779
|
-
* attributes, or nothing. A generated `dataChannel` field wins when present.
|
|
780
|
-
*/
|
|
781
|
-
export function channelOf(component) {
|
|
782
|
-
if (component.dataChannel) return component.dataChannel;
|
|
783
|
-
if (component.source === 'webawesome') return 'attributes';
|
|
784
|
-
return component.props.some((prop) => prop.name === 'rootAttributes')
|
|
785
|
-
? 'rootAttributes'
|
|
786
|
-
: 'none';
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
/** The prop a zone key fills: the composition zone's binding or the prop itself. */
|
|
790
|
-
export function zonePropOf(catalog, component, key) {
|
|
791
|
-
const entry = component.key.includes('#')
|
|
792
|
-
? undefined
|
|
793
|
-
: catalog.entries.get(component.key);
|
|
794
|
-
const zone = entry?.zones?.find((item) => item.id === key && item.jsx?.prop);
|
|
795
|
-
return zone ? zone.jsx.prop : key;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
350
|
/** A zone key's binding: the composition zone, or a content (`slot`) prop. */
|
|
799
351
|
function zonesOf(ctx, component) {
|
|
800
352
|
const zones = new Map();
|
|
@@ -1107,194 +659,361 @@ function checkNode(ctx, node, at, scope, rowScoped, parentKey, text = false) {
|
|
|
1107
659
|
checkComposition(ctx, node, at, parentKey, shapes, literals, zones);
|
|
1108
660
|
}
|
|
1109
661
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
else if (list && list.kind !== 'array')
|
|
1137
|
-
ctx.report(
|
|
1138
|
-
'KUI-V008',
|
|
1139
|
-
`${at}.$each`,
|
|
1140
|
-
`\`$each\` needs an array, not ${describe(list)}`,
|
|
1141
|
-
);
|
|
1142
|
-
// kerf's each() keys rows by item identity, so items are objects.
|
|
1143
|
-
else if (
|
|
1144
|
-
list &&
|
|
1145
|
-
!['object', 'unknown', 'record'].includes(
|
|
1146
|
-
resolveType(list.items, {}).kind,
|
|
1147
|
-
)
|
|
1148
|
-
) {
|
|
1149
|
-
ctx.report(
|
|
1150
|
-
'KUI-V008',
|
|
1151
|
-
`${at}.$each`,
|
|
1152
|
-
'`$each` items are objects (each() keys rows by item identity)',
|
|
1153
|
-
);
|
|
1154
|
-
}
|
|
1155
|
-
if (
|
|
1156
|
-
typeof child.as !== 'string' ||
|
|
1157
|
-
!CAMEL.test(child.as) ||
|
|
1158
|
-
RESERVED_NAMES.has(child.as) ||
|
|
1159
|
-
ctx.params.has(child.as) ||
|
|
1160
|
-
scope.has(child.as)
|
|
1161
|
-
) {
|
|
1162
|
-
ctx.report(
|
|
1163
|
-
'KUI-V008',
|
|
1164
|
-
`${at}.as`,
|
|
1165
|
-
'`as` names the item with a camelCase identifier that is not reserved, a param, or an outer item',
|
|
1166
|
-
);
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
const inner = new Map(scope).set(
|
|
1170
|
-
child.as,
|
|
1171
|
-
list?.kind === 'array' ? list.items : { kind: 'unknown' },
|
|
662
|
+
/**
|
|
663
|
+
* An `$each` template: one keyable node, or (KF-8J8E5V: per-item row
|
|
664
|
+
* designs) an `$if` chain whose every branch is one. `else` is required, so
|
|
665
|
+
* each item yields exactly one row and a repeat never filters.
|
|
666
|
+
*/
|
|
667
|
+
function checkTemplate(
|
|
668
|
+
ctx,
|
|
669
|
+
template,
|
|
670
|
+
at,
|
|
671
|
+
scope,
|
|
672
|
+
parentKey,
|
|
673
|
+
text,
|
|
674
|
+
chain = true,
|
|
675
|
+
) {
|
|
676
|
+
// A chain nests only in `else`; `then` is always one node.
|
|
677
|
+
if (chain && isObject(template) && '$if' in template) {
|
|
678
|
+
for (const key of only(template, ['$if', 'then', 'else']))
|
|
679
|
+
ctx.report('KUI-V001', `${at}.${key}`, 'unknown `$if` field');
|
|
680
|
+
checkPropValue(
|
|
681
|
+
ctx,
|
|
682
|
+
{ name: 'condition', type: { kind: 'boolean' } },
|
|
683
|
+
template.$if,
|
|
684
|
+
{},
|
|
685
|
+
scope,
|
|
686
|
+
`${at}.$if`,
|
|
687
|
+
true,
|
|
1172
688
|
);
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
);
|
|
1184
|
-
|
|
1185
|
-
if (!isObject(child.template) || !('type' in child.template)) {
|
|
689
|
+
checkTemplate(
|
|
690
|
+
ctx,
|
|
691
|
+
template.then,
|
|
692
|
+
`${at}.then`,
|
|
693
|
+
scope,
|
|
694
|
+
parentKey,
|
|
695
|
+
text,
|
|
696
|
+
false,
|
|
697
|
+
);
|
|
698
|
+
if ('else' in template)
|
|
699
|
+
checkTemplate(ctx, template.else, `${at}.else`, scope, parentKey, text);
|
|
700
|
+
else
|
|
1186
701
|
ctx.report(
|
|
1187
702
|
'KUI-V008',
|
|
1188
|
-
|
|
1189
|
-
'
|
|
703
|
+
at,
|
|
704
|
+
'a template `$if` needs an `else`, so every item yields exactly one row',
|
|
1190
705
|
);
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (!isObject(template) || !('type' in template)) {
|
|
709
|
+
ctx.report(
|
|
710
|
+
'KUI-V008',
|
|
711
|
+
at,
|
|
712
|
+
'the template is exactly one node, or an `$if` chain of them',
|
|
713
|
+
);
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const entry = ctx.catalog.components.get(template.type);
|
|
717
|
+
if (entry && channelOf(entry.component) === 'none') {
|
|
718
|
+
ctx.report(
|
|
719
|
+
'KUI-V008',
|
|
720
|
+
at,
|
|
721
|
+
`${template.type} has no data-* channel to carry the row key`,
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
checkNode(ctx, template, at, scope, true, parentKey, text);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* An `$each`'s rows: exactly one of `template` (one node or an `$if` chain)
|
|
729
|
+
* and `templates`, a map of one node per item kind picked by `kind`
|
|
730
|
+
* (KF-YX6HMT: keyed row designs). `templates` needs a `default`, which an
|
|
731
|
+
* item of any other kind takes, so every item yields exactly one row.
|
|
732
|
+
*/
|
|
733
|
+
function checkRows(ctx, child, at, scope, parentKey, text) {
|
|
734
|
+
if (!('templates' in child)) {
|
|
735
|
+
if ('kind' in child)
|
|
1195
736
|
ctx.report(
|
|
1196
737
|
'KUI-V008',
|
|
1197
|
-
`${at}.
|
|
1198
|
-
|
|
738
|
+
`${at}.kind`,
|
|
739
|
+
'`kind` picks one of `templates`; this `$each` has none',
|
|
1199
740
|
);
|
|
1200
|
-
|
|
1201
|
-
checkNode(
|
|
741
|
+
checkTemplate(
|
|
1202
742
|
ctx,
|
|
1203
743
|
child.template,
|
|
1204
744
|
`${at}.template`,
|
|
1205
|
-
|
|
1206
|
-
true,
|
|
745
|
+
scope,
|
|
1207
746
|
parentKey,
|
|
1208
747
|
text,
|
|
1209
748
|
);
|
|
1210
749
|
return;
|
|
1211
750
|
}
|
|
1212
|
-
if ('
|
|
1213
|
-
|
|
1214
|
-
|
|
751
|
+
if ('template' in child)
|
|
752
|
+
ctx.report(
|
|
753
|
+
'KUI-V008',
|
|
754
|
+
at,
|
|
755
|
+
'an `$each` has exactly one of `template` and `templates`',
|
|
756
|
+
);
|
|
757
|
+
const templates = isObject(child.templates) ? child.templates : {};
|
|
758
|
+
if (!('default' in templates))
|
|
759
|
+
ctx.report(
|
|
760
|
+
'KUI-V008',
|
|
761
|
+
`${at}.templates`,
|
|
762
|
+
'`templates` needs a `default` row design, which an item of any other kind takes',
|
|
763
|
+
);
|
|
764
|
+
if ('kind' in child)
|
|
1215
765
|
checkPropValue(
|
|
1216
766
|
ctx,
|
|
1217
|
-
{ name: '
|
|
1218
|
-
child
|
|
767
|
+
{ name: 'kind', type: { kind: 'string' } },
|
|
768
|
+
child.kind,
|
|
1219
769
|
{},
|
|
1220
770
|
scope,
|
|
1221
|
-
`${at}
|
|
1222
|
-
|
|
771
|
+
`${at}.kind`,
|
|
772
|
+
true,
|
|
773
|
+
);
|
|
774
|
+
else
|
|
775
|
+
ctx.report(
|
|
776
|
+
'KUI-V008',
|
|
777
|
+
`${at}.kind`,
|
|
778
|
+
'`templates` needs a `kind` that resolves to a string on the item',
|
|
779
|
+
);
|
|
780
|
+
for (const [kind, template] of Object.entries(templates)) {
|
|
781
|
+
const path = `${at}.templates.${kind}`;
|
|
782
|
+
if (!isObject(template) || !('type' in template))
|
|
783
|
+
ctx.report(
|
|
784
|
+
'KUI-V008',
|
|
785
|
+
path,
|
|
786
|
+
'each `templates` entry is exactly one node',
|
|
787
|
+
);
|
|
788
|
+
else checkTemplate(ctx, template, path, scope, parentKey, text, false);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The templates an `$each` can render a row from: its `template`, or every
|
|
794
|
+
* entry of its `templates` map in order (KF-YX6HMT). Each is one node or an
|
|
795
|
+
* `$if` chain of them.
|
|
796
|
+
*/
|
|
797
|
+
export function eachTemplates(each) {
|
|
798
|
+
if (!('templates' in each)) return [each.template];
|
|
799
|
+
// A malformed map is one malformed template, so walkers report it.
|
|
800
|
+
return isObject(each.templates)
|
|
801
|
+
? Object.values(each.templates)
|
|
802
|
+
: [each.templates];
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** Every node an `$each` can render a row from, in order; the first keys it. */
|
|
806
|
+
export function eachNodes(each) {
|
|
807
|
+
return eachTemplates(each).flatMap(templateNodes);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* The nodes an `$each` template can render, in branch order: the template
|
|
812
|
+
* itself, or every leaf of its `$if` chain.
|
|
813
|
+
*/
|
|
814
|
+
export function templateNodes(template) {
|
|
815
|
+
if (isObject(template) && '$if' in template)
|
|
816
|
+
return [
|
|
817
|
+
...templateNodes(template.then),
|
|
818
|
+
...('else' in template ? templateNodes(template.else) : []),
|
|
819
|
+
];
|
|
820
|
+
return isObject(template) ? [template] : [];
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function checkChild(ctx, child, at, scope, rowScoped, parentKey, text = false) {
|
|
824
|
+
if (!isObject(child)) {
|
|
825
|
+
ctx.report('KUI-V001', at, 'a zone child is an object');
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
switch (childKind(child)) {
|
|
829
|
+
case 'each':
|
|
830
|
+
return checkEach(ctx, child, at, scope, rowScoped, parentKey, text);
|
|
831
|
+
case 'if':
|
|
832
|
+
return checkIf(ctx, child, at, scope, rowScoped, parentKey, text);
|
|
833
|
+
case 'slot':
|
|
834
|
+
return checkSlot(ctx, child, at, scope, rowScoped);
|
|
835
|
+
default:
|
|
836
|
+
return checkNode(ctx, child, at, scope, rowScoped, parentKey, text);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** Checks an `$each` child: its fields, source list, key, and rows. */
|
|
841
|
+
function checkEach(ctx, child, at, scope, rowScoped, parentKey, text) {
|
|
842
|
+
for (const key of only(child, [
|
|
843
|
+
'$each',
|
|
844
|
+
'as',
|
|
845
|
+
'key',
|
|
846
|
+
'template',
|
|
847
|
+
'templates',
|
|
848
|
+
'kind',
|
|
849
|
+
]))
|
|
850
|
+
ctx.report('KUI-V001', `${at}.${key}`, 'unknown `$each` field');
|
|
851
|
+
// KF-CFA1S1: an inner `$each` in this document renders as a plain map, but
|
|
852
|
+
// a document composed into another's row cannot know it is in one: its
|
|
853
|
+
// module renders a keyed each(), which kerf refuses inside a row render.
|
|
854
|
+
if (ctx.rowHost && !rowScoped) {
|
|
855
|
+
ctx.report(
|
|
856
|
+
'KUI-V016',
|
|
857
|
+
at,
|
|
858
|
+
'a document composed into an `$each` row cannot repeat; move the `$each` into the composing document',
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
const source = dynamicType(ctx, child.$each, scope, `${at}.$each`);
|
|
862
|
+
const list = source ? resolveType(source, {}) : undefined;
|
|
863
|
+
if (source === null)
|
|
864
|
+
ctx.report(
|
|
865
|
+
'KUI-V008',
|
|
866
|
+
`${at}.$each`,
|
|
867
|
+
'`$each` iterates a `$param` or `$bind`, not a literal',
|
|
868
|
+
);
|
|
869
|
+
else if (list && list.kind !== 'array')
|
|
870
|
+
ctx.report(
|
|
871
|
+
'KUI-V008',
|
|
872
|
+
`${at}.$each`,
|
|
873
|
+
`\`$each\` needs an array, not ${describe(list)}`,
|
|
874
|
+
);
|
|
875
|
+
// kerf's each() keys rows by item identity, so items are objects.
|
|
876
|
+
else if (
|
|
877
|
+
list &&
|
|
878
|
+
!['object', 'unknown', 'record'].includes(resolveType(list.items, {}).kind)
|
|
879
|
+
) {
|
|
880
|
+
ctx.report(
|
|
881
|
+
'KUI-V008',
|
|
882
|
+
`${at}.$each`,
|
|
883
|
+
'`$each` items are objects (each() keys rows by item identity)',
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
if (
|
|
887
|
+
typeof child.as !== 'string' ||
|
|
888
|
+
!CAMEL.test(child.as) ||
|
|
889
|
+
RESERVED_NAMES.has(child.as) ||
|
|
890
|
+
ctx.params.has(child.as) ||
|
|
891
|
+
scope.has(child.as)
|
|
892
|
+
) {
|
|
893
|
+
ctx.report(
|
|
894
|
+
'KUI-V008',
|
|
895
|
+
`${at}.as`,
|
|
896
|
+
'`as` names the item with a camelCase identifier that is not reserved, a param, or an outer item',
|
|
897
|
+
);
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const inner = new Map(scope).set(
|
|
901
|
+
child.as,
|
|
902
|
+
list?.kind === 'array' ? list.items : { kind: 'unknown' },
|
|
903
|
+
);
|
|
904
|
+
const keyType =
|
|
905
|
+
typeof child.key === 'string' && child.key.split('.')[0] === child.as
|
|
906
|
+
? bindingType(ctx, child.key, inner, `${at}.key`)
|
|
907
|
+
: undefined;
|
|
908
|
+
const keyKind = keyType && resolveType(keyType, {}).kind;
|
|
909
|
+
if (!keyType || !['string', 'number', 'unknown'].includes(keyKind)) {
|
|
910
|
+
ctx.report(
|
|
911
|
+
'KUI-V008',
|
|
912
|
+
`${at}.key`,
|
|
913
|
+
'`key` is a path on the item that resolves to a string or number',
|
|
1223
914
|
);
|
|
915
|
+
}
|
|
916
|
+
checkRows(ctx, child, at, inner, parentKey, text);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/** Checks an `$if` child: its condition and both branches. */
|
|
920
|
+
function checkIf(ctx, child, at, scope, rowScoped, parentKey, text) {
|
|
921
|
+
for (const key of only(child, ['$if', 'then', 'else']))
|
|
922
|
+
ctx.report('KUI-V001', `${at}.${key}`, 'unknown `$if` field');
|
|
923
|
+
checkPropValue(
|
|
924
|
+
ctx,
|
|
925
|
+
{ name: 'condition', type: { kind: 'boolean' } },
|
|
926
|
+
child.$if,
|
|
927
|
+
{},
|
|
928
|
+
scope,
|
|
929
|
+
`${at}.$if`,
|
|
930
|
+
rowScoped,
|
|
931
|
+
);
|
|
932
|
+
checkChild(ctx, child.then, `${at}.then`, scope, rowScoped, parentKey, text);
|
|
933
|
+
if ('else' in child)
|
|
1224
934
|
checkChild(
|
|
1225
935
|
ctx,
|
|
1226
|
-
child.
|
|
1227
|
-
`${at}.
|
|
936
|
+
child.else,
|
|
937
|
+
`${at}.else`,
|
|
1228
938
|
scope,
|
|
1229
939
|
rowScoped,
|
|
1230
940
|
parentKey,
|
|
1231
941
|
text,
|
|
1232
942
|
);
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** Checks a `$slot` child: its name and the input it passes. */
|
|
946
|
+
function checkSlot(ctx, child, at, scope, rowScoped) {
|
|
947
|
+
for (const key of only(child, ['$slot', 'input']))
|
|
948
|
+
ctx.report('KUI-V001', `${at}.${key}`, 'unknown `$slot` field');
|
|
949
|
+
if (typeof child.$slot !== 'string' || !CAMEL.test(child.$slot)) {
|
|
950
|
+
ctx.report(
|
|
951
|
+
'KUI-V001',
|
|
952
|
+
`${at}.$slot`,
|
|
953
|
+
'a slot name is a camelCase identifier',
|
|
954
|
+
);
|
|
1243
955
|
return;
|
|
1244
956
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
ctx.report(
|
|
1260
|
-
'KUI-V001',
|
|
1261
|
-
`${at}.input`,
|
|
1262
|
-
`slot "${child.$slot}" declares no input`,
|
|
1263
|
-
);
|
|
1264
|
-
return;
|
|
1265
|
-
}
|
|
1266
|
-
const given = isObject(child.input) ? child.input : {};
|
|
1267
|
-
for (const prop of props) {
|
|
1268
|
-
if (!(prop.name in given)) {
|
|
1269
|
-
if (prop.required)
|
|
1270
|
-
ctx.report(
|
|
1271
|
-
'KUI-V005',
|
|
1272
|
-
`${at}.input`,
|
|
1273
|
-
`slot "${child.$slot}" requires input "${prop.name}"`,
|
|
1274
|
-
);
|
|
1275
|
-
continue;
|
|
1276
|
-
}
|
|
1277
|
-
checkPropValue(
|
|
1278
|
-
ctx,
|
|
1279
|
-
prop,
|
|
1280
|
-
given[prop.name],
|
|
1281
|
-
{},
|
|
1282
|
-
scope,
|
|
1283
|
-
`${at}.input.${prop.name}`,
|
|
1284
|
-
rowScoped,
|
|
1285
|
-
);
|
|
1286
|
-
}
|
|
1287
|
-
for (const name of Object.keys(given)) {
|
|
1288
|
-
if (!props.some((prop) => prop.name === name))
|
|
957
|
+
const declared = ctx.slots.get(child.$slot);
|
|
958
|
+
const props = declared?.input?.props ?? [];
|
|
959
|
+
if (child.input !== undefined && !declared?.input) {
|
|
960
|
+
ctx.report(
|
|
961
|
+
'KUI-V001',
|
|
962
|
+
`${at}.input`,
|
|
963
|
+
`slot "${child.$slot}" declares no input`,
|
|
964
|
+
);
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
const given = isObject(child.input) ? child.input : {};
|
|
968
|
+
for (const prop of props) {
|
|
969
|
+
if (!(prop.name in given)) {
|
|
970
|
+
if (prop.required)
|
|
1289
971
|
ctx.report(
|
|
1290
|
-
'KUI-
|
|
1291
|
-
`${at}.input
|
|
1292
|
-
`slot "${child.$slot}"
|
|
972
|
+
'KUI-V005',
|
|
973
|
+
`${at}.input`,
|
|
974
|
+
`slot "${child.$slot}" requires input "${prop.name}"`,
|
|
1293
975
|
);
|
|
976
|
+
continue;
|
|
1294
977
|
}
|
|
1295
|
-
|
|
978
|
+
checkPropValue(
|
|
979
|
+
ctx,
|
|
980
|
+
prop,
|
|
981
|
+
given[prop.name],
|
|
982
|
+
{},
|
|
983
|
+
scope,
|
|
984
|
+
`${at}.input.${prop.name}`,
|
|
985
|
+
rowScoped,
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
for (const name of Object.keys(given)) {
|
|
989
|
+
if (!props.some((prop) => prop.name === name))
|
|
990
|
+
ctx.report(
|
|
991
|
+
'KUI-V003',
|
|
992
|
+
`${at}.input.${name}`,
|
|
993
|
+
`slot "${child.$slot}" has no input "${name}"`,
|
|
994
|
+
);
|
|
1296
995
|
}
|
|
1297
|
-
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* KF-3X7MFF: where a `#view`'s `src` points, relative to the top document's
|
|
1000
|
+
* folder, from the composing document at `from` (undefined for the top
|
|
1001
|
+
* document): `src` resolves from the folder of the document that contains it,
|
|
1002
|
+
* as each generated module imports its children. A posix path with `.`
|
|
1003
|
+
* segments removed and `..` folded; it may start with `../` (or `/`).
|
|
1004
|
+
*/
|
|
1005
|
+
export function composedViewPath(from, src) {
|
|
1006
|
+
const parts = from === undefined ? [] : from.split('/').slice(0, -1);
|
|
1007
|
+
if (src.startsWith('/')) parts.length = 0;
|
|
1008
|
+
for (const part of src.split('/')) {
|
|
1009
|
+
if (part === '' || part === '.') continue;
|
|
1010
|
+
if (part !== '..') parts.push(part);
|
|
1011
|
+
// `..` folds a folder; above the root (`/`) it stays at the root.
|
|
1012
|
+
else if (parts.length && parts.at(-1) !== '..') {
|
|
1013
|
+
if (parts.at(-1) !== '') parts.pop();
|
|
1014
|
+
} else parts.push(part);
|
|
1015
|
+
}
|
|
1016
|
+
return `${src.startsWith('/') ? '/' : ''}${parts.join('/')}`;
|
|
1298
1017
|
}
|
|
1299
1018
|
|
|
1300
1019
|
function checkView(ctx, node, at, scope, rowScoped) {
|
|
@@ -1307,11 +1026,14 @@ function checkView(ctx, node, at, scope, rowScoped) {
|
|
|
1307
1026
|
return;
|
|
1308
1027
|
}
|
|
1309
1028
|
if (!ctx.resolveView) return;
|
|
1310
|
-
|
|
1029
|
+
// Cycles compare where sources point, not their text: the same `src` in
|
|
1030
|
+
// two folders names two documents.
|
|
1031
|
+
const path = composedViewPath(ctx.viewPath, node.src);
|
|
1032
|
+
if (ctx.viewStack.includes(path)) {
|
|
1311
1033
|
ctx.report('KUI-V012', `${at}.src`, `#view "${node.src}" is cyclic`);
|
|
1312
1034
|
return;
|
|
1313
1035
|
}
|
|
1314
|
-
const child = ctx.resolveView(node.src);
|
|
1036
|
+
const child = ctx.resolveView(node.src, path);
|
|
1315
1037
|
if (!isObject(child)) {
|
|
1316
1038
|
ctx.report('KUI-V012', `${at}.src`, `#view "${node.src}" was not found`);
|
|
1317
1039
|
return;
|
|
@@ -1345,7 +1067,12 @@ function checkView(ctx, node, at, scope, rowScoped) {
|
|
|
1345
1067
|
);
|
|
1346
1068
|
}
|
|
1347
1069
|
for (const [name, param] of Object.entries(params)) {
|
|
1348
|
-
if (
|
|
1070
|
+
if (
|
|
1071
|
+
isObject(param) &&
|
|
1072
|
+
!('default' in param) &&
|
|
1073
|
+
param.optional !== true &&
|
|
1074
|
+
!(name in given)
|
|
1075
|
+
) {
|
|
1349
1076
|
ctx.report(
|
|
1350
1077
|
'KUI-V012',
|
|
1351
1078
|
at,
|
|
@@ -1356,7 +1083,8 @@ function checkView(ctx, node, at, scope, rowScoped) {
|
|
|
1356
1083
|
const nested = validateView(child, ctx.catalog, {
|
|
1357
1084
|
resolveView: ctx.resolveView,
|
|
1358
1085
|
icons: ctx.icons,
|
|
1359
|
-
viewStack: [...ctx.viewStack,
|
|
1086
|
+
viewStack: [...ctx.viewStack, path],
|
|
1087
|
+
viewPath: path,
|
|
1360
1088
|
// A composed document inside a control renders inside it too.
|
|
1361
1089
|
interactiveHost: ctx.interactiveHost,
|
|
1362
1090
|
// ... and one inside a row renders inside that row.
|
|
@@ -1369,8 +1097,13 @@ function checkView(ctx, node, at, scope, rowScoped) {
|
|
|
1369
1097
|
diagnostic.message,
|
|
1370
1098
|
);
|
|
1371
1099
|
}
|
|
1100
|
+
// KF-RDZ7N7: a document composed into a row renders inside that keyed row,
|
|
1101
|
+
// and the generated row passes its key to the composed root, so a delegated
|
|
1102
|
+
// handler reads the row key there. Its actions are row actions of the
|
|
1103
|
+
// composing document; its own contract keeps them view-scoped, since
|
|
1104
|
+
// standalone it has no row.
|
|
1372
1105
|
for (const [name, actionScope] of nested.actions)
|
|
1373
|
-
ctx.noteAction(name, actionScope, at);
|
|
1106
|
+
ctx.noteAction(name, rowScoped ? 'row' : actionScope, at);
|
|
1374
1107
|
}
|
|
1375
1108
|
|
|
1376
1109
|
// Zone shapes, as the ESLint rule computes them over JSX: how many direct
|
|
@@ -1388,25 +1121,30 @@ function combine(shapes) {
|
|
|
1388
1121
|
}
|
|
1389
1122
|
function childShape(child) {
|
|
1390
1123
|
if (!isObject(child)) return shape(0, 0, []);
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1124
|
+
switch (childKind(child)) {
|
|
1125
|
+
case 'each': {
|
|
1126
|
+
const items = eachTemplates(child).flatMap((template) =>
|
|
1127
|
+
isObject(template) ? childShape(template).items : [],
|
|
1128
|
+
);
|
|
1129
|
+
return shape(0, Number.POSITIVE_INFINITY, items);
|
|
1130
|
+
}
|
|
1131
|
+
case 'if': {
|
|
1132
|
+
const then = childShape(child.then);
|
|
1133
|
+
const otherwise =
|
|
1134
|
+
'else' in child ? childShape(child.else) : shape(0, 0, []);
|
|
1135
|
+
return shape(
|
|
1136
|
+
Math.min(then.min, otherwise.min),
|
|
1137
|
+
Math.max(then.max, otherwise.max),
|
|
1138
|
+
[...then.items, ...otherwise.items],
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
case 'slot':
|
|
1142
|
+
case 'view':
|
|
1143
|
+
return shape(1, 1, []);
|
|
1144
|
+
default:
|
|
1145
|
+
if (child.type === '#text') return shape(1, 1, [{ label: 'text' }]);
|
|
1146
|
+
return shape(1, 1, [{ node: child }]);
|
|
1406
1147
|
}
|
|
1407
|
-
if ('$slot' in child || child.type === '#view') return shape(1, 1, []);
|
|
1408
|
-
if (child.type === '#text') return shape(1, 1, [{ label: 'text' }]);
|
|
1409
|
-
return shape(1, 1, [{ node: child }]);
|
|
1410
1148
|
}
|
|
1411
1149
|
|
|
1412
1150
|
// Interactive content (HTML's button, a, input, label, and so on) cannot hold
|
|
@@ -1584,11 +1322,22 @@ function hintUnsizedLayouts(node, at, sized, hints, isRoot = false) {
|
|
|
1584
1322
|
});
|
|
1585
1323
|
const child = (item, path, childSized) => {
|
|
1586
1324
|
if (!isObject(item)) return;
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1325
|
+
switch (childKind(item)) {
|
|
1326
|
+
case 'each':
|
|
1327
|
+
if ('templates' in item)
|
|
1328
|
+
for (const [kind, template] of Object.entries(
|
|
1329
|
+
isObject(item.templates) ? item.templates : {},
|
|
1330
|
+
))
|
|
1331
|
+
child(template, `${path}.templates.${kind}`, childSized);
|
|
1332
|
+
else child(item.template, `${path}.template`, childSized);
|
|
1333
|
+
break;
|
|
1334
|
+
case 'if':
|
|
1335
|
+
child(item.then, `${path}.then`, childSized);
|
|
1336
|
+
if ('else' in item) child(item.else, `${path}.else`, childSized);
|
|
1337
|
+
break;
|
|
1338
|
+
default:
|
|
1339
|
+
hintUnsizedLayouts(item, path, childSized, hints);
|
|
1340
|
+
}
|
|
1592
1341
|
};
|
|
1593
1342
|
for (const [zone, children] of Object.entries(
|
|
1594
1343
|
isObject(node.zones) ? node.zones : {},
|
|
@@ -1607,8 +1356,10 @@ function hintUnsizedLayouts(node, at, sized, hints, isRoot = false) {
|
|
|
1607
1356
|
* or a `KUI-L201`–`L204` composition id) and `actions` maps each action name
|
|
1608
1357
|
* to its `row` or `view` scope. `hints` are non-blocking `KUI-H###` advice
|
|
1609
1358
|
* about a valid document (a nested layout with no height); they never make it
|
|
1610
|
-
* invalid. `options.resolveView(src)` loads a composed document
|
|
1611
|
-
*
|
|
1359
|
+
* invalid. `options.resolveView(src, path)` loads a composed document, where
|
|
1360
|
+
* `path` is where `src` points relative to the top document's folder (each
|
|
1361
|
+
* `src` resolves from the document that contains it); without it, `#view`
|
|
1362
|
+
* nodes are checked for shape only.
|
|
1612
1363
|
*/
|
|
1613
1364
|
export function validateView(document, catalog, options = {}) {
|
|
1614
1365
|
return runView(document, catalog, options);
|
|
@@ -1632,6 +1383,7 @@ function createContext(catalog, options, trace) {
|
|
|
1632
1383
|
resolveView: options.resolveView,
|
|
1633
1384
|
icons: options.icons ? new Set(options.icons) : undefined,
|
|
1634
1385
|
viewStack: options.viewStack ?? [],
|
|
1386
|
+
viewPath: options.viewPath,
|
|
1635
1387
|
params: new Map(),
|
|
1636
1388
|
slots: new Map(),
|
|
1637
1389
|
checkedSlots: new WeakSet(),
|
|
@@ -1741,12 +1493,26 @@ function checkHeader(ctx, document) {
|
|
|
1741
1493
|
ctx.report(
|
|
1742
1494
|
'KUI-V001',
|
|
1743
1495
|
at,
|
|
1744
|
-
'a param is a camelCase name mapped to `{ type, default? }`',
|
|
1496
|
+
'a param is a camelCase name mapped to `{ type, default?, optional? }`',
|
|
1745
1497
|
);
|
|
1746
1498
|
continue;
|
|
1747
1499
|
}
|
|
1748
|
-
for (const key of only(param, [
|
|
1500
|
+
for (const key of only(param, [
|
|
1501
|
+
'type',
|
|
1502
|
+
'default',
|
|
1503
|
+
'optional',
|
|
1504
|
+
'description',
|
|
1505
|
+
]))
|
|
1749
1506
|
ctx.report('KUI-V001', `${at}.${key}`, 'unknown param field');
|
|
1507
|
+
// KF-JE8KHX: `optional: true` makes an input optional with no default,
|
|
1508
|
+
// so an omitted value reads as absent (an optional item field extracted
|
|
1509
|
+
// into a row document).
|
|
1510
|
+
if ('optional' in param && (param.optional !== true || 'default' in param))
|
|
1511
|
+
ctx.report(
|
|
1512
|
+
'KUI-V001',
|
|
1513
|
+
`${at}.optional`,
|
|
1514
|
+
'optional is `true`, on a param with no default (a default already makes it optional)',
|
|
1515
|
+
);
|
|
1750
1516
|
validateDeclaredType(ctx, param.type, `${at}.type`);
|
|
1751
1517
|
// A prop-typed param's default is a literal of that prop (KF-V9V2B6: a
|
|
1752
1518
|
// Select's choices promoted with their current list).
|