@schema-engine/forms 0.5.2 → 0.5.3
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 +4 -3
- package/dist/agent-tool/index.js +13 -6
- package/dist/agent-tool/index.js.map +2 -2
- package/dist/builder/types.utils.d.ts +1 -0
- package/dist/chunk-2MKT7OIS.js +40 -0
- package/dist/chunk-2MKT7OIS.js.map +7 -0
- package/dist/{chunk-HPPFSWIV.js → chunk-2U4WRMPB.js} +26 -22
- package/dist/chunk-2U4WRMPB.js.map +7 -0
- package/dist/{chunk-YUUDXRBW.js → chunk-3ABPK4QP.js} +62 -2
- package/dist/chunk-3ABPK4QP.js.map +7 -0
- package/dist/chunk-3BMTC224.js +21 -0
- package/dist/chunk-3BMTC224.js.map +7 -0
- package/dist/chunk-3GZKJSXI.js +49 -0
- package/dist/chunk-3GZKJSXI.js.map +7 -0
- package/dist/{chunk-NJXKMF67.js → chunk-4HSGF4WX.js} +33 -52
- package/dist/chunk-4HSGF4WX.js.map +7 -0
- package/dist/chunk-4SWCTY7K.js +8 -0
- package/dist/chunk-4SWCTY7K.js.map +7 -0
- package/dist/{chunk-KLATKWUA.js → chunk-4YANBG3M.js} +1 -1
- package/dist/chunk-53SXH32V.js +43 -0
- package/dist/chunk-53SXH32V.js.map +7 -0
- package/dist/{chunk-DP7SYLLI.js → chunk-6OJ46PR2.js} +15 -20
- package/dist/chunk-6OJ46PR2.js.map +7 -0
- package/dist/chunk-AAOFZ27F.js +39 -0
- package/dist/chunk-AAOFZ27F.js.map +7 -0
- package/dist/{chunk-NJTLBSTR.js → chunk-AROD3D4R.js} +1 -1
- package/dist/{chunk-Q5LEK7CI.js → chunk-AT2NHSY3.js} +1 -1
- package/dist/chunk-B2PMISHZ.js +43 -0
- package/dist/chunk-B2PMISHZ.js.map +7 -0
- package/dist/chunk-BHCSZ4VO.js +27 -0
- package/dist/chunk-BHCSZ4VO.js.map +7 -0
- package/dist/chunk-BXGE5IXF.js +38 -0
- package/dist/chunk-BXGE5IXF.js.map +7 -0
- package/dist/chunk-CW7UMF3K.js +48 -0
- package/dist/chunk-CW7UMF3K.js.map +7 -0
- package/dist/{chunk-BLFLCSG3.js → chunk-DEWI6E3O.js} +2 -2
- package/dist/chunk-DSPTVDHL.js +45 -0
- package/dist/chunk-DSPTVDHL.js.map +7 -0
- package/dist/chunk-DU26WGQA.js +27 -0
- package/dist/chunk-DU26WGQA.js.map +7 -0
- package/dist/{chunk-GH34XFCC.js → chunk-EO5CW7XD.js} +2 -2
- package/dist/{chunk-A5VLMQAK.js → chunk-ERSCXYVE.js} +2 -2
- package/dist/chunk-EWNYEO6T.js.map +7 -0
- package/dist/{chunk-CRVXBWSY.js → chunk-FGL773EA.js} +1 -1
- package/dist/chunk-FVW5Z2CC.js +36 -0
- package/dist/chunk-FVW5Z2CC.js.map +7 -0
- package/dist/chunk-GDUF2SWI.js +32 -0
- package/dist/chunk-GDUF2SWI.js.map +7 -0
- package/dist/{chunk-GQHMU3AR.js → chunk-HEWLTCU4.js} +4 -4
- package/dist/{chunk-6R2MBQPL.js → chunk-HKLDRUFN.js} +4 -1
- package/dist/{chunk-6R2MBQPL.js.map → chunk-HKLDRUFN.js.map} +2 -2
- package/dist/{chunk-J2FC5K4B.js → chunk-IHXXPIFD.js} +1 -2
- package/dist/chunk-IHXXPIFD.js.map +7 -0
- package/dist/{chunk-GRZU6F7Q.js → chunk-KANWAQNI.js} +33 -38
- package/dist/chunk-KANWAQNI.js.map +7 -0
- package/dist/chunk-KWQJFQII.js +52 -0
- package/dist/chunk-KWQJFQII.js.map +7 -0
- package/dist/{chunk-PH3LWLYN.js → chunk-MFZYG6DN.js} +3 -2
- package/dist/chunk-MFZYG6DN.js.map +7 -0
- package/dist/{chunk-WUTGZYP4.js → chunk-MG7VFU6V.js} +2 -2
- package/dist/chunk-OG3OLZ5R.js +184 -0
- package/dist/chunk-OG3OLZ5R.js.map +7 -0
- package/dist/{chunk-WLDCYUN6.js → chunk-OKJLJ3GI.js} +1 -1
- package/dist/chunk-QDU55RCZ.js.map +7 -0
- package/dist/chunk-QFQB5EBY.js +38 -0
- package/dist/chunk-QFQB5EBY.js.map +7 -0
- package/dist/{chunk-6IZYNHZ3.js → chunk-RDQFBY6S.js} +45 -31
- package/dist/chunk-RDQFBY6S.js.map +7 -0
- package/dist/chunk-RMX7C43O.js.map +7 -0
- package/dist/chunk-T5JAAPFB.js +40 -0
- package/dist/chunk-T5JAAPFB.js.map +7 -0
- package/dist/chunk-TDXFT6Q5.js +57 -0
- package/dist/chunk-TDXFT6Q5.js.map +7 -0
- package/dist/{chunk-JA5ET6MC.js → chunk-TWQU2IGF.js} +6 -6
- package/dist/chunk-V3GYAG33.js +12 -0
- package/dist/chunk-V3GYAG33.js.map +7 -0
- package/dist/{chunk-V5H7L5PJ.js → chunk-WHLID5BN.js} +59 -23
- package/dist/{chunk-V5H7L5PJ.js.map → chunk-WHLID5BN.js.map} +2 -2
- package/dist/chunk-XKINCUXT.js +51 -0
- package/dist/chunk-XKINCUXT.js.map +7 -0
- package/dist/chunk-XLEOTW6H.js +50 -0
- package/dist/chunk-XLEOTW6H.js.map +7 -0
- package/dist/chunk-YHSOS3IH.js +53 -0
- package/dist/chunk-YHSOS3IH.js.map +7 -0
- package/dist/chunk-YKXOBPSU.js +19 -0
- package/dist/chunk-YKXOBPSU.js.map +7 -0
- package/dist/{chunk-ZYP3MIH3.js → chunk-YW2KZUAM.js} +5 -3
- package/dist/chunk-YW2KZUAM.js.map +7 -0
- package/dist/{chunk-E4VONSLO.js.map → chunk-YZFL6JPZ.js.map} +2 -2
- package/dist/{chunk-6EYX257T.js → chunk-Z5KZDT7V.js} +1 -1
- package/dist/chunk-ZZ4KB6GE.js +47 -0
- package/dist/chunk-ZZ4KB6GE.js.map +7 -0
- package/dist/default-elements/array-elements.d.ts +793 -0
- package/dist/default-elements/array-elements.js +34 -0
- package/dist/default-elements/array-elements.js.map +7 -0
- package/dist/default-elements/checkbox-group.d.ts +812 -0
- package/dist/default-elements/checkbox-group.js +40 -0
- package/dist/default-elements/checkbox-group.js.map +7 -0
- package/dist/default-elements/checkbox.d.ts +788 -0
- package/dist/default-elements/checkbox.js +38 -0
- package/dist/default-elements/checkbox.js.map +7 -0
- package/dist/default-elements/combobox.d.ts +806 -0
- package/dist/default-elements/combobox.js +40 -0
- package/dist/default-elements/combobox.js.map +7 -0
- package/dist/default-elements/define-contract.d.ts +25 -0
- package/dist/default-elements/define-contract.js +8 -0
- package/dist/default-elements/define-contract.js.map +7 -0
- package/dist/default-elements/drop-zone.d.ts +789 -0
- package/dist/default-elements/drop-zone.js +40 -0
- package/dist/default-elements/drop-zone.js.map +7 -0
- package/dist/default-elements/fieldset.d.ts +783 -0
- package/dist/default-elements/fieldset.js +34 -0
- package/dist/default-elements/fieldset.js.map +7 -0
- package/dist/default-elements/index.d.ts +75 -0
- package/dist/default-elements/index.js +240 -0
- package/dist/default-elements/index.js.map +7 -0
- package/dist/default-elements/input-otp.d.ts +1298 -0
- package/dist/default-elements/input-otp.js +38 -0
- package/dist/default-elements/input-otp.js.map +7 -0
- package/dist/default-elements/input.d.ts +843 -0
- package/dist/default-elements/input.js +40 -0
- package/dist/default-elements/input.js.map +7 -0
- package/dist/default-elements/masked-input.d.ts +835 -0
- package/dist/default-elements/masked-input.js +40 -0
- package/dist/default-elements/masked-input.js.map +7 -0
- package/dist/default-elements/number.d.ts +821 -0
- package/dist/default-elements/number.js +38 -0
- package/dist/default-elements/number.js.map +7 -0
- package/dist/default-elements/phone-input.d.ts +785 -0
- package/dist/default-elements/phone-input.js +40 -0
- package/dist/default-elements/phone-input.js.map +7 -0
- package/dist/default-elements/radio.d.ts +812 -0
- package/dist/default-elements/radio.js +40 -0
- package/dist/default-elements/radio.js.map +7 -0
- package/dist/default-elements/select.d.ts +809 -0
- package/dist/default-elements/select.js +40 -0
- package/dist/default-elements/select.js.map +7 -0
- package/dist/default-elements/slider.d.ts +800 -0
- package/dist/default-elements/slider.js +38 -0
- package/dist/default-elements/slider.js.map +7 -0
- package/dist/default-elements/submission-alert.d.ts +804 -0
- package/dist/default-elements/submission-alert.js +36 -0
- package/dist/default-elements/submission-alert.js.map +7 -0
- package/dist/default-elements/submit-button.d.ts +771 -0
- package/dist/default-elements/submit-button.js +34 -0
- package/dist/default-elements/submit-button.js.map +7 -0
- package/dist/default-elements/switch.d.ts +794 -0
- package/dist/default-elements/switch.js +38 -0
- package/dist/default-elements/switch.js.map +7 -0
- package/dist/default-elements/textarea.d.ts +815 -0
- package/dist/default-elements/textarea.js +40 -0
- package/dist/default-elements/textarea.js.map +7 -0
- package/dist/engine/build-form-engine.js +22 -18
- package/dist/engine/create-form-engine.js +23 -19
- package/dist/engine/form-engine.js +22 -18
- package/dist/engine/index.js +25 -21
- package/dist/engine/schema-artifacts.js +6 -2
- package/dist/engine/step-machine.d.ts +10 -0
- package/dist/engine/step-machine.js +5 -5
- package/dist/engine/submission-schema.js +8 -6
- package/dist/engine/value-validation.js +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +40 -31
- package/dist/index.js.map +3 -3
- package/dist/lib/export-schema.d.ts +128 -0
- package/dist/lib/export-schema.js +15 -0
- package/dist/lib/export-schema.js.map +7 -0
- package/dist/lib/exported-recipe-view.d.ts +17 -0
- package/dist/lib/exported-recipe-view.js +10 -0
- package/dist/lib/exported-recipe-view.js.map +7 -0
- package/dist/lib/field-scope.js +2 -2
- package/dist/lib/grid-track-items.d.ts +26 -0
- package/dist/lib/grid-track-items.js +10 -0
- package/dist/lib/grid-track-items.js.map +7 -0
- package/dist/lib/is-zod-type.d.ts +5 -0
- package/dist/lib/is-zod-type.js +6 -0
- package/dist/lib/is-zod-type.js.map +7 -0
- package/dist/lib/submission-shape.js +3 -3
- package/dist/lib/validate-form/grid-checks.d.ts +24 -0
- package/dist/lib/validate-form/grid-checks.js +6 -1
- package/dist/lib/validate-form/parse-elements.d.ts +9 -7
- package/dist/lib/validate-form/parse-elements.js +5 -6
- package/dist/lib/validate-form/parse-owner-actions.js +1 -1
- package/dist/lib/validate-form/parse-view.js +1 -1
- package/dist/lib/validate-form/step-checks.js +3 -3
- package/dist/lib/validate-form/validation-error.d.ts +1 -10
- package/dist/lib/validate-form/validation-error.js +3 -5
- package/dist/lib/validate-form.d.ts +1 -1
- package/dist/lib/validate-form.js +14 -15
- package/dist/lib/zod-json-schema.d.ts +0 -4
- package/dist/lib/zod-json-schema.js +7 -5
- package/dist/recipes/built-in-specs.js +2 -2
- package/dist/recipes/built-in.js +2 -2
- package/dist/recipes/define-form-recipe.d.ts +2 -2
- package/dist/recipes/define-form-recipe.js +1 -1
- package/dist/recipes/define-recipe-spec.d.ts +3 -2
- package/dist/recipes/define-recipe-spec.js +1 -1
- package/dist/recipes/index.js +8 -8
- package/dist/recipes/types.d.ts +2 -2
- package/dist/recipes/view-model.d.ts +2 -2
- package/dist/recipes/view-model.js +6 -6
- package/dist/runtime/create-form-runtime.js +14 -13
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +14 -13
- package/dist/runtime/types.d.ts +11 -0
- package/dist/runtime/types.js +1 -1
- package/dist/schemas/base-field.d.ts +14 -6
- package/dist/schemas/base-field.js +5 -5
- package/dist/schemas/form-config-shape.d.ts +33 -21
- package/dist/schemas/form-config-shape.js +5 -5
- package/dist/schemas/form-config.d.ts +55 -35
- package/dist/schemas/form-config.js +5 -5
- package/dist/schemas/index.js +5 -5
- package/dist/schemas/validation/dependencies.js +4 -4
- package/dist/schemas/validation/index.js +5 -5
- package/dist/schemas/validation/utils.js +3 -3
- package/dist/schemas/validation/validation-registry.d.ts +1 -1
- package/dist/schemas/validation/validation-registry.js +4 -4
- package/dist/state-container/create-form-state-container.js +8 -8
- package/dist/state-container/index.js +9 -9
- package/dist/state-container/selectors.js +5 -5
- package/dist/state-container/submission.js +6 -6
- package/dist/testing/form-state-container-conformance.js +7 -7
- package/dist/testing/index.js +7 -7
- package/dist/types/define-element.d.ts +2 -2
- package/dist/types/define-element.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/registration.d.ts +7 -0
- package/package.json +8 -4
- package/skill/SKILL.md +12 -11
- package/skill/reference/forms.md +4 -4
- package/dist/chunk-25PLQDKN.js +0 -45
- package/dist/chunk-25PLQDKN.js.map +0 -7
- package/dist/chunk-2XWISGGM.js.map +0 -7
- package/dist/chunk-6IZYNHZ3.js.map +0 -7
- package/dist/chunk-DP7SYLLI.js.map +0 -7
- package/dist/chunk-GRZU6F7Q.js.map +0 -7
- package/dist/chunk-HPPFSWIV.js.map +0 -7
- package/dist/chunk-J2FC5K4B.js.map +0 -7
- package/dist/chunk-K22S7IZR.js.map +0 -7
- package/dist/chunk-NJXKMF67.js.map +0 -7
- package/dist/chunk-PH3LWLYN.js.map +0 -7
- package/dist/chunk-PHNMDWSK.js.map +0 -7
- package/dist/chunk-PN5EH6DM.js +0 -36
- package/dist/chunk-PN5EH6DM.js.map +0 -7
- package/dist/chunk-YUUDXRBW.js.map +0 -7
- package/dist/chunk-ZYP3MIH3.js.map +0 -7
- package/dist/{chunk-KLATKWUA.js.map → chunk-4YANBG3M.js.map} +0 -0
- package/dist/{chunk-S7I76ISM.js → chunk-7QLR5WM3.js} +3 -3
- /package/dist/{chunk-S7I76ISM.js.map → chunk-7QLR5WM3.js.map} +0 -0
- /package/dist/{chunk-NJTLBSTR.js.map → chunk-AROD3D4R.js.map} +0 -0
- /package/dist/{chunk-Q5LEK7CI.js.map → chunk-AT2NHSY3.js.map} +0 -0
- /package/dist/{chunk-BLFLCSG3.js.map → chunk-DEWI6E3O.js.map} +0 -0
- /package/dist/{chunk-GH34XFCC.js.map → chunk-EO5CW7XD.js.map} +0 -0
- /package/dist/{chunk-A5VLMQAK.js.map → chunk-ERSCXYVE.js.map} +0 -0
- /package/dist/{chunk-K22S7IZR.js → chunk-EWNYEO6T.js} +0 -0
- /package/dist/{chunk-CRVXBWSY.js.map → chunk-FGL773EA.js.map} +0 -0
- /package/dist/{chunk-GQHMU3AR.js.map → chunk-HEWLTCU4.js.map} +0 -0
- /package/dist/{chunk-WUTGZYP4.js.map → chunk-MG7VFU6V.js.map} +0 -0
- /package/dist/{chunk-WLDCYUN6.js.map → chunk-OKJLJ3GI.js.map} +0 -0
- /package/dist/{chunk-2XWISGGM.js → chunk-QDU55RCZ.js} +0 -0
- /package/dist/{chunk-PHNMDWSK.js → chunk-RMX7C43O.js} +0 -0
- /package/dist/{chunk-JA5ET6MC.js.map → chunk-TWQU2IGF.js.map} +0 -0
- /package/dist/{chunk-E4VONSLO.js → chunk-YZFL6JPZ.js} +0 -0
- /package/dist/{chunk-6EYX257T.js.map → chunk-Z5KZDT7V.js.map} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineInputContract
|
|
3
|
+
} from "./chunk-V3GYAG33.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseFieldSchema
|
|
6
|
+
} from "./chunk-237BHPDH.js";
|
|
7
|
+
|
|
8
|
+
// src/default-elements/phone-input.ts
|
|
9
|
+
import * as z from "zod/mini";
|
|
10
|
+
var PhoneInputFieldExtensionSchema = z.object({
|
|
11
|
+
defaultCountry: z.optional(z.string()),
|
|
12
|
+
international: z.optional(z.boolean())
|
|
13
|
+
});
|
|
14
|
+
var PhoneInputFieldSchema = z.extend(BaseFieldSchema, {
|
|
15
|
+
$type: z.literal("phone-input"),
|
|
16
|
+
...PhoneInputFieldExtensionSchema.shape
|
|
17
|
+
});
|
|
18
|
+
var phoneInputFieldExample = {
|
|
19
|
+
$type: "phone-input",
|
|
20
|
+
name: "phoneNumber",
|
|
21
|
+
label: "Phone Number",
|
|
22
|
+
description: "Enter your phone number",
|
|
23
|
+
defaultCountry: "US",
|
|
24
|
+
placeholder: "Enter phone number"
|
|
25
|
+
};
|
|
26
|
+
var phoneInputFieldValue = () => z.string();
|
|
27
|
+
var PhoneInputElementContract = defineInputContract({
|
|
28
|
+
$type: "phone-input",
|
|
29
|
+
appearanceAxes: ["size"],
|
|
30
|
+
schema: PhoneInputFieldSchema,
|
|
31
|
+
value: phoneInputFieldValue,
|
|
32
|
+
metadata: {
|
|
33
|
+
name: "Phone Input",
|
|
34
|
+
description: "International phone number input with country selection",
|
|
35
|
+
category: "input"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
PhoneInputFieldExtensionSchema,
|
|
41
|
+
PhoneInputFieldSchema,
|
|
42
|
+
phoneInputFieldExample,
|
|
43
|
+
phoneInputFieldValue,
|
|
44
|
+
PhoneInputElementContract
|
|
45
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/default-elements/phone-input.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport { defineInputContract } from './define-contract';\n\nexport const PhoneInputFieldExtensionSchema = z.object({\n\tdefaultCountry: z.optional(z.string()),\n\tinternational: z.optional(z.boolean()),\n});\n\nexport const PhoneInputFieldSchema = z.extend(BaseFieldSchema, {\n\t$type: z.literal('phone-input'),\n\t...PhoneInputFieldExtensionSchema.shape,\n});\n\n/** Serializable input accepted by the phone-input registration. */\nexport type PhoneInputFieldConfig = z.input<typeof PhoneInputFieldSchema>;\n\n/** The phone-input configuration after validation, which its render function receives. */\nexport type PhoneInputFieldOutput = z.output<typeof PhoneInputFieldSchema>;\n\nexport const phoneInputFieldExample: PhoneInputFieldConfig = {\n\t$type: 'phone-input',\n\tname: 'phoneNumber',\n\tlabel: 'Phone Number',\n\tdescription: 'Enter your phone number',\n\tdefaultCountry: 'US',\n\tplaceholder: 'Enter phone number',\n};\n\n/** The value a phone field writes: the number as text. */\nexport const phoneInputFieldValue = () => z.string();\n\n/** The contract of the `phone-input` element: what every renderer of it agrees on. */\nexport const PhoneInputElementContract = defineInputContract({\n\t$type: 'phone-input',\n\tappearanceAxes: ['size'],\n\tschema: PhoneInputFieldSchema,\n\tvalue: phoneInputFieldValue,\n\tmetadata: {\n\t\tname: 'Phone Input',\n\t\tdescription: 'International phone number input with country selection',\n\t\tcategory: 'input',\n\t},\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,YAAY,OAAO;AAIZ,IAAM,iCAAmC,SAAO;AAAA,EACtD,gBAAkB,WAAW,SAAO,CAAC;AAAA,EACrC,eAAiB,WAAW,UAAQ,CAAC;AACtC,CAAC;AAEM,IAAM,wBAA0B,SAAO,iBAAiB;AAAA,EAC9D,OAAS,UAAQ,aAAa;AAAA,EAC9B,GAAG,+BAA+B;AACnC,CAAC;AAQM,IAAM,yBAAgD;AAAA,EAC5D,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,aAAa;AACd;AAGO,IAAM,uBAAuB,MAAQ,SAAO;AAG5C,IAAM,4BAA4B,oBAAoB;AAAA,EAC5D,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
childPath
|
|
3
|
+
} from "./chunk-LMWJAD3B.js";
|
|
4
|
+
import {
|
|
5
|
+
getElementChildren
|
|
6
|
+
} from "./chunk-ZUYSGCEH.js";
|
|
7
|
+
|
|
8
|
+
// src/lib/grid-track-items.ts
|
|
9
|
+
import { elementIsSubgrid } from "@schema-engine/layout";
|
|
10
|
+
function placedTrackItems(placed) {
|
|
11
|
+
const items = [];
|
|
12
|
+
const visit = ({ element, path }) => {
|
|
13
|
+
items.push({ element, path });
|
|
14
|
+
if (!elementIsSubgrid(element) || typeof element !== "object" || element === null) return;
|
|
15
|
+
getElementChildren(element)?.forEach((child, index) => visit({ element: child, path: childPath(path, index) }));
|
|
16
|
+
};
|
|
17
|
+
placed.forEach(visit);
|
|
18
|
+
return items;
|
|
19
|
+
}
|
|
20
|
+
function gridTrackItems(elements) {
|
|
21
|
+
return placedTrackItems(elements.map((element) => ({ element, path: [] }))).map(({ element }) => element);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
placedTrackItems,
|
|
26
|
+
gridTrackItems
|
|
27
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/grid-track-items.ts"],
|
|
4
|
+
"sourcesContent": ["import { elementIsSubgrid } from '@schema-engine/layout';\nimport { getElementChildren } from './element-children';\nimport { childPath, type Path } from './validate-form/issues';\n\n/** An element and where it sits in the form, as validation reads it. */\nexport interface PlacedItem {\n\telement: unknown;\n\tpath: Path;\n}\n\n/**\n * The elements whose placement counts the tracks of the grid that lays out `placed`: the elements\n * themselves and, for each subgrid, its children, however deep.\n *\n * @remarks\n * A subgrid places its children on its parent's tracks, so a `width` inside it counts the parent's\n * tracks. A container that is not a subgrid draws tracks of its own and stops the walk. Order is depth\n * first, each subgrid right before its children. A child's path is the parent's with `elements` and the\n * child's index.\n */\nexport function placedTrackItems(placed: readonly PlacedItem[]): PlacedItem[] {\n\tconst items: PlacedItem[] = [];\n\tconst visit = ({ element, path }: PlacedItem): void => {\n\t\titems.push({ element, path });\n\t\tif (!elementIsSubgrid(element) || typeof element !== 'object' || element === null) return;\n\t\tgetElementChildren(element)?.forEach((child, index) => visit({ element: child, path: childPath(path, index) }));\n\t};\n\tplaced.forEach(visit);\n\treturn items;\n}\n\n/**\n * The elements whose placement counts the tracks of the grid that lays out `elements`.\n *\n * @remarks\n * Pass the result as `elements` to `getGridVariables`, so a grid takes twelve tracks when a child of a\n * subgrid sets a `width`. It is the set validation checks (see {@link placedTrackItems}). Both renderers\n * use it for a step's grid and for `ChildGrid`.\n */\nexport function gridTrackItems(elements: readonly unknown[]): unknown[] {\n\treturn placedTrackItems(elements.map((element) => ({ element, path: [] }))).map(({ element }) => element);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,SAAS,wBAAwB;AAoB1B,SAAS,iBAAiB,QAA6C;AAC7E,QAAM,QAAsB,CAAC;AAC7B,QAAM,QAAQ,CAAC,EAAE,SAAS,KAAK,MAAwB;AACtD,UAAM,KAAK,EAAE,SAAS,KAAK,CAAC;AAC5B,QAAI,CAAC,iBAAiB,OAAO,KAAK,OAAO,YAAY,YAAY,YAAY,KAAM;AACnF,uBAAmB,OAAO,GAAG,QAAQ,CAAC,OAAO,UAAU,MAAM,EAAE,SAAS,OAAO,MAAM,UAAU,MAAM,KAAK,EAAE,CAAC,CAAC;AAAA,EAC/G;AACA,SAAO,QAAQ,KAAK;AACpB,SAAO;AACR;AAUO,SAAS,eAAe,UAAyC;AACvE,SAAO,iBAAiB,SAAS,IAAI,CAAC,aAAa,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,QAAQ,MAAM,OAAO;AACzG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getValidationRulesForElement
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4YANBG3M.js";
|
|
4
4
|
import {
|
|
5
5
|
resolveFieldRef
|
|
6
6
|
} from "./chunk-YDGH7DTL.js";
|
|
7
7
|
import {
|
|
8
8
|
walkNamedElements
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7QLR5WM3.js";
|
|
10
10
|
import {
|
|
11
11
|
expandFieldTemplatePaths
|
|
12
12
|
} from "./chunk-QLGM2AZW.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
selectFieldState,
|
|
3
3
|
selectValue
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FGL773EA.js";
|
|
5
5
|
import {
|
|
6
6
|
toFieldArrayValue
|
|
7
7
|
} from "./chunk-KFQEDSYI.js";
|
|
8
8
|
import {
|
|
9
9
|
createDefaultValidationRegistry
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-RDQFBY6S.js";
|
|
11
11
|
import {
|
|
12
12
|
logger
|
|
13
13
|
} from "./chunk-VGGERKV2.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types/define-element.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { ElementMetadata } from './metadata';\nimport type { ContainerKind, InputRegistration, StaticRegistration, ValueDeclaration } from './registration';\nimport type { NormalizedElementConfig } from '@/lib/normalized-form-config';\nimport type { ValidationRegistrationConstraint } from '@/schemas/validation/types';\nimport type { AppearanceAxisList } from '@schema-engine/layout';\n\ntype InferOutput<TSchema> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : never;\n\n/**\n * Rewrite container `elements` to the normalized children the renderer receives.\n * Parent schemas only require `$type`; the engine supplies frozen, validated children.\n */\nexport type WithNormalizedChildren<T> = T extends { elements: unknown[] }\n\t? Omit<T, 'elements'> & { readonly elements: ReadonlyArray<NormalizedElementConfig> }\n\t: T;\n\nexport type ElementRenderProps<TSchema extends StandardSchemaV1, THandlers = unknown> = WithNormalizedChildren<\n\tInferOutput<TSchema>\n> & {\n\t/** Stable array-item identity overlaid at render time. Not part of authoring. */\n\tinstanceId?: string;\n} & THandlers;\n\nexport type DefineElementRegistration<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTKind extends ContainerKind | undefined = ContainerKind | undefined,\n> = {\n\t$type: TType;\n\tschema: TSchema;\n\tmetadata: ElementMetadata;\n\tcontainerKind?: TKind;\n\tappearanceAxes?: AppearanceAxisList;\n\trender: (props: TProps) => unknown;\n};\n\n/**\n * What an input declares about its value, by one rule: `value` is required exactly when its schema output has no `elements`.\n *\n * @remarks\n * A schema that declares `elements` makes the element a container, whose value the engine composes from its children,\n * so it declares no `value` and may set `containerKind` (`'object'` when it does not). Any other input must declare\n * `value`, which is how a registration whose control writes a value the engine cannot check is a type error. A schema\n * that merely allows any key (an index signature) does not declare `elements`.\n */\nexport type InputValueDeclaration<TSchema extends StandardSchemaV1, TValue extends StandardSchemaV1> =\n\tDeclaresChildren<InferOutput<TSchema>> extends true\n\t\t? { containerKind?: ContainerKind; value?: never }\n\t\t: { containerKind?: undefined; value: ValueDeclaration<WithNormalizedChildren<InferOutput<TSchema>>, TValue> };\n\n/** Whether a schema output declares `elements`: a key of its own, or an array typed beside an index signature. */\ntype DeclaresChildren<TOutput> = 'elements' extends keyof TOutput\n\t? string extends keyof TOutput\n\t\t? TOutput extends { elements?: readonly unknown[] }\n\t\t\t? true\n\t\t\t: false\n\t\t: true\n\t: false;\n\ntype DefineInputRegistration<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTValue extends StandardSchemaV1,\n\tTKind extends ContainerKind | undefined,\n> = DefineElementRegistration<TType, TSchema, TProps, TKind> & {\n\tvalidations?: readonly ValidationRegistrationConstraint[];\n} & InputValueDeclaration<TSchema, TValue>;\n\ntype DefineElementArg<TType extends string, TSchema extends StandardSchemaV1, TProps> =\n\tWithNormalizedChildren<InferOutput<TSchema>> extends TProps\n\t\t? DefineElementRegistration<TType, TSchema, TProps>\n\t\t: never;\n\ntype DefineInputArg<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTValue extends StandardSchemaV1,\n\tTKind extends ContainerKind | undefined,\n> =\n\tWithNormalizedChildren<InferOutput<TSchema>> extends TProps\n\t\t? DefineInputRegistration<TType, TSchema, TProps, TValue, TKind>\n\t\t: never;\n\n/**\n * Register an input element while preserving schema input/output inference.\n *\n * Form authors supply schema input (defaults stay optional). The render function\n * must accept schema output, with container `elements` already normalized.\n * `validations` are registered when the element is added to a form engine.\n *\n * `value` declares the value the control writes, as a function of the configured element\n * (see {@link ValueDeclaration}); it is required unless the schema has `elements`.\n *\n * It sets the registration's `kind` to `'input'`, which is what the engine reads to require `value`, not the metadata category.\n */\nexport function defineInput<\n\tconst TType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps = WithNormalizedChildren<InferOutput<TSchema>>,\n\tTValue extends StandardSchemaV1 = never,\n\tconst TKind extends ContainerKind | undefined = undefined,\n>(\n\tregistration: DefineInputArg<TType, TSchema, TProps, TValue, TKind>,\n): InputRegistration<TType, TSchema, TProps, TValue, TKind> {\n\treturn { ...registration, kind: 'input' } as unknown as InputRegistration<TType, TSchema, TProps, TValue, TKind>;\n}\n\n/**\n * Register a display-only element while preserving schema input/output inference.\n *\n * It sets the registration's `kind` to `'static'`, so the engine asks it for no `value`, whatever its metadata category.\n */\nexport function defineStatic<\n\tconst TType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps = WithNormalizedChildren<InferOutput<TSchema>>,\n>(registration: DefineElementArg<TType, TSchema, TProps>): StaticRegistration<TType, TSchema, TProps> {\n\treturn { ...registration, kind: 'static' } as StaticRegistration<TType, TSchema, TProps>;\n}\n"],
|
|
5
|
+
"mappings": ";AAmGO,SAAS,YAOf,cAC2D;AAC3D,SAAO,EAAE,GAAG,cAAc,MAAM,QAAQ;AACzC;AAOO,SAAS,aAId,cAAoG;AACrG,SAAO,EAAE,GAAG,cAAc,MAAM,SAAS;AAC1C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineInputContract
|
|
3
|
+
} from "./chunk-V3GYAG33.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseFieldSchema
|
|
6
|
+
} from "./chunk-237BHPDH.js";
|
|
7
|
+
|
|
8
|
+
// src/default-elements/switch.ts
|
|
9
|
+
import * as z from "zod/mini";
|
|
10
|
+
var SwitchFieldExtensionSchema = z.object({
|
|
11
|
+
autoFocus: z.optional(z.boolean()),
|
|
12
|
+
size: z.optional(z.enum(["sm", "md", "lg"]))
|
|
13
|
+
});
|
|
14
|
+
var SwitchFieldConfigSchema = z.extend(BaseFieldSchema, {
|
|
15
|
+
$type: z.literal("switch"),
|
|
16
|
+
...SwitchFieldExtensionSchema.shape
|
|
17
|
+
});
|
|
18
|
+
var switchFieldValue = () => z.boolean();
|
|
19
|
+
var SwitchElementContract = defineInputContract({
|
|
20
|
+
$type: "switch",
|
|
21
|
+
appearanceAxes: ["size"],
|
|
22
|
+
schema: SwitchFieldConfigSchema,
|
|
23
|
+
value: switchFieldValue,
|
|
24
|
+
metadata: {
|
|
25
|
+
name: "Switch Field",
|
|
26
|
+
description: "Toggle switch field for boolean values",
|
|
27
|
+
category: "input"
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
SwitchFieldExtensionSchema,
|
|
33
|
+
SwitchFieldConfigSchema,
|
|
34
|
+
switchFieldValue,
|
|
35
|
+
SwitchElementContract
|
|
36
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/default-elements/switch.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport { defineInputContract } from './define-contract';\n\nexport const SwitchFieldExtensionSchema = z.object({\n\tautoFocus: z.optional(z.boolean()),\n\tsize: z.optional(z.enum(['sm', 'md', 'lg'])),\n});\n\nexport const SwitchFieldConfigSchema = z.extend(BaseFieldSchema, {\n\t$type: z.literal('switch'),\n\t...SwitchFieldExtensionSchema.shape,\n});\n\nexport type SwitchFieldExtension = z.infer<typeof SwitchFieldExtensionSchema>;\nexport type SwitchFieldConfig = z.infer<typeof SwitchFieldConfigSchema>;\n\n/** The value a switch writes: whether it is on. */\nexport const switchFieldValue = () => z.boolean();\n\n/** The contract of the `switch` element: what every renderer of it agrees on. */\nexport const SwitchElementContract = defineInputContract({\n\t$type: 'switch',\n\tappearanceAxes: ['size'],\n\tschema: SwitchFieldConfigSchema,\n\tvalue: switchFieldValue,\n\tmetadata: {\n\t\tname: 'Switch Field',\n\t\tdescription: 'Toggle switch field for boolean values',\n\t\tcategory: 'input',\n\t},\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,YAAY,OAAO;AAIZ,IAAM,6BAA+B,SAAO;AAAA,EAClD,WAAa,WAAW,UAAQ,CAAC;AAAA,EACjC,MAAQ,WAAW,OAAK,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC;AAC5C,CAAC;AAEM,IAAM,0BAA4B,SAAO,iBAAiB;AAAA,EAChE,OAAS,UAAQ,QAAQ;AAAA,EACzB,GAAG,2BAA2B;AAC/B,CAAC;AAMM,IAAM,mBAAmB,MAAQ,UAAQ;AAGzC,IAAM,wBAAwB,oBAAoB;AAAA,EACxD,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineInputContract
|
|
3
|
+
} from "./chunk-V3GYAG33.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseFieldSchema
|
|
6
|
+
} from "./chunk-237BHPDH.js";
|
|
7
|
+
import {
|
|
8
|
+
elementChildrenSchema
|
|
9
|
+
} from "./chunk-ZUYSGCEH.js";
|
|
10
|
+
|
|
11
|
+
// src/default-elements/fieldset.ts
|
|
12
|
+
import * as z from "zod/mini";
|
|
13
|
+
var FieldSetConfigSchema = z.extend(BaseFieldSchema, {
|
|
14
|
+
$type: z.literal("fieldSet"),
|
|
15
|
+
legend: z.optional(z.string()).check(z.describe("Legend text displayed at the top of the fieldset")),
|
|
16
|
+
elements: elementChildrenSchema.check(z.minLength(1)).check(z.describe("Field definitions for the nested object"))
|
|
17
|
+
});
|
|
18
|
+
var FieldSetContract = defineInputContract({
|
|
19
|
+
$type: "fieldSet",
|
|
20
|
+
appearanceAxes: ["size"],
|
|
21
|
+
schema: FieldSetConfigSchema,
|
|
22
|
+
metadata: {
|
|
23
|
+
name: "FieldSet",
|
|
24
|
+
description: "Groups related form fields into a nested object structure",
|
|
25
|
+
category: "input"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
FieldSetConfigSchema,
|
|
31
|
+
FieldSetContract
|
|
32
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/default-elements/fieldset.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Fieldset field type \u2014 groups related fields into a nested object.\n */\n\nimport * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport { elementChildrenSchema } from '@/lib/element-children';\nimport { defineInputContract } from './define-contract';\n\nexport const FieldSetConfigSchema = z.extend(BaseFieldSchema, {\n\t$type: z.literal('fieldSet'),\n\tlegend: z.optional(z.string()).check(z.describe('Legend text displayed at the top of the fieldset')),\n\telements: elementChildrenSchema.check(z.minLength(1)).check(z.describe('Field definitions for the nested object')),\n});\n\nexport type FieldSetConfig = z.output<typeof FieldSetConfigSchema>;\nexport type FieldSetInput = z.input<typeof FieldSetConfigSchema>;\n\n/** The contract of the `fieldset` element: what every renderer of it agrees on. */\nexport const FieldSetContract = defineInputContract({\n\t$type: 'fieldSet',\n\tappearanceAxes: ['size'],\n\tschema: FieldSetConfigSchema,\n\tmetadata: {\n\t\tname: 'FieldSet',\n\t\tdescription: 'Groups related form fields into a nested object structure',\n\t\tcategory: 'input',\n\t},\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAIA,YAAY,OAAO;AAKZ,IAAM,uBAAyB,SAAO,iBAAiB;AAAA,EAC7D,OAAS,UAAQ,UAAU;AAAA,EAC3B,QAAU,WAAW,SAAO,CAAC,EAAE,MAAQ,WAAS,kDAAkD,CAAC;AAAA,EACnG,UAAU,sBAAsB,MAAQ,YAAU,CAAC,CAAC,EAAE,MAAQ,WAAS,yCAAyC,CAAC;AAClH,CAAC;AAMM,IAAM,mBAAmB,oBAAoB;AAAA,EACnD,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildDependencyIndex,
|
|
3
3
|
shouldSurfaceDependentError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EO5CW7XD.js";
|
|
5
5
|
import {
|
|
6
6
|
anchorOf,
|
|
7
7
|
flatIds,
|
|
@@ -32,10 +32,10 @@ import {
|
|
|
32
32
|
submittedTree,
|
|
33
33
|
submittedValues,
|
|
34
34
|
toFormPath
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-DEWI6E3O.js";
|
|
36
36
|
import {
|
|
37
37
|
buildSubmissionShape
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-AROD3D4R.js";
|
|
39
39
|
import {
|
|
40
40
|
logger
|
|
41
41
|
} from "./chunk-VGGERKV2.js";
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
planFormValidation,
|
|
47
47
|
resolveParticipation,
|
|
48
48
|
runValidationPlan
|
|
49
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-MG7VFU6V.js";
|
|
50
50
|
import {
|
|
51
51
|
frozenCopy
|
|
52
52
|
} from "./chunk-3B7CJOF6.js";
|
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
import { parseActions } from "@schema-engine/actions";
|
|
10
10
|
function parseOwnerActions(items, options, ownerPath) {
|
|
11
11
|
if (!items) return { issues: [] };
|
|
12
|
-
const result = parseActions(options, items, {
|
|
12
|
+
const result = parseActions(options, items, {
|
|
13
|
+
triggers: FormActionTriggerSchema.options,
|
|
14
|
+
hint: "Register it with createFormEngine({ actions: [...] })."
|
|
15
|
+
});
|
|
13
16
|
if (!result.success) return { issues: fromSchemaIssues(result.issues, [...ownerPath, "actions"]) };
|
|
14
17
|
return { issues: [], items: result.data };
|
|
15
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lib/validate-form/parse-owner-actions.ts"],
|
|
4
|
-
"sourcesContent": ["import { parseActions, type ParsedActionSequence } from '@schema-engine/actions';\nimport { FormActionTriggerSchema } from '@/actions/triggers';\nimport type { FormTaggedConfig } from '@/schemas/form-config';\nimport type { FormValidationIssue, Path } from './issues';\nimport type { ValidateFormOptions } from './options';\nimport { fromSchemaIssues } from './schema-issues';\n\n/**\n * Parses the `actions` of the form or of a step with {@link parseActions}, and lays the issues under `actions` at the owner.\n *\n * @remarks\n * A nested array is a group of actions that run together; its members sit one level deeper in the path.\n */\nexport function parseOwnerActions(\n\titems: Array<FormTaggedConfig | FormTaggedConfig[]> | undefined,\n\toptions: Pick<ValidateFormOptions, 'getAction'>,\n\townerPath: Path,\n): { issues: FormValidationIssue[]; items?: ParsedActionSequence } {\n\tif (!items) return { issues: [] };\n\tconst result = parseActions(options, items, {
|
|
5
|
-
"mappings": ";;;;;;;;AAAA,SAAS,oBAA+C;AAajD,SAAS,kBACf,OACA,SACA,WACkE;AAClE,MAAI,CAAC,MAAO,QAAO,EAAE,QAAQ,CAAC,EAAE;AAChC,QAAM,SAAS,aAAa,SAAS,OAAO,
|
|
4
|
+
"sourcesContent": ["import { parseActions, type ParsedActionSequence } from '@schema-engine/actions';\nimport { FormActionTriggerSchema } from '@/actions/triggers';\nimport type { FormTaggedConfig } from '@/schemas/form-config';\nimport type { FormValidationIssue, Path } from './issues';\nimport type { ValidateFormOptions } from './options';\nimport { fromSchemaIssues } from './schema-issues';\n\n/**\n * Parses the `actions` of the form or of a step with {@link parseActions}, and lays the issues under `actions` at the owner.\n *\n * @remarks\n * A nested array is a group of actions that run together; its members sit one level deeper in the path.\n */\nexport function parseOwnerActions(\n\titems: Array<FormTaggedConfig | FormTaggedConfig[]> | undefined,\n\toptions: Pick<ValidateFormOptions, 'getAction'>,\n\townerPath: Path,\n): { issues: FormValidationIssue[]; items?: ParsedActionSequence } {\n\tif (!items) return { issues: [] };\n\tconst result = parseActions(options, items, {\n\t\ttriggers: FormActionTriggerSchema.options,\n\t\thint: 'Register it with createFormEngine({ actions: [...] }).',\n\t});\n\tif (!result.success) return { issues: fromSchemaIssues(result.issues, [...ownerPath, 'actions']) };\n\treturn { issues: [], items: result.data };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,SAAS,oBAA+C;AAajD,SAAS,kBACf,OACA,SACA,WACkE;AAClE,MAAI,CAAC,MAAO,QAAO,EAAE,QAAQ,CAAC,EAAE;AAChC,QAAM,SAAS,aAAa,SAAS,OAAO;AAAA,IAC3C,UAAU,wBAAwB;AAAA,IAClC,MAAM;AAAA,EACP,CAAC;AACD,MAAI,CAAC,OAAO,QAAS,QAAO,EAAE,QAAQ,iBAAiB,OAAO,QAAQ,CAAC,GAAG,WAAW,SAAS,CAAC,EAAE;AACjG,SAAO,EAAE,QAAQ,CAAC,GAAG,OAAO,OAAO,KAAK;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
stepAfter,
|
|
3
3
|
stepBefore
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-MFZYG6DN.js";
|
|
5
5
|
|
|
6
6
|
// src/recipes/view-model.ts
|
|
7
|
-
import "zod/mini";
|
|
8
7
|
import { readSlotConfig } from "@schema-engine/layout";
|
|
9
8
|
function getSlotConfig(viewConfig, slot, schema) {
|
|
10
9
|
return readSlotConfig(viewConfig, slot, schema);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/recipes/view-model.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { FormConfigView } from '@/lib/normalized-form-config';\nimport { stepAfter, stepBefore, type FormStepState } from '@/engine/step-machine';\nimport type { AnyRecipeRegistration } from '@/types/registration';\nimport { readSlotConfig, type RecipeViewModel } from '@schema-engine/layout';\nimport type { RecipeKind, RecipeSlot } from './types';\n\n/**\n * The commands a stepper or an actions block calls, and whether each is available.\n *\n * @remarks `goToStep` takes a step id, which stays right when steps are skipped; indexes do not.\n */\nexport interface ViewNavigation {\n\tcanGoNext: boolean;\n\tcanGoPrevious: boolean;\n\tisFirstStep: boolean;\n\tisLastStep: boolean;\n\t/** Whether `goToStep(stepId)` can move there, as the runtime's step state says. */\n\tcanGoToStep: (stepId: string) => boolean;\n\tgoToStep: (stepId: string) => void;\n\tgoToNextStep: () => void;\n\tgoToPreviousStep: () => void;\n}\n\n/**\n * One step that is not skipped, as a recipe block reads it.\n *\n * @remarks `index` is the position among the steps that are not skipped and `total` how many there are, so progress reads \"step 2 of 3\" however many are skipped.\n */\nexport interface ViewStep {\n\tid: string;\n\ttitle?: string;\n\tdescription?: string;\n\tindex: number;\n\ttotal: number;\n\tisActive: boolean;\n\tisCompleted: boolean;\n\tisInvalid: boolean;\n\tisVisited: boolean;\n}\n\nexport interface ViewModel extends RecipeViewModel<RecipeKind> {\n\tform: {\n\t\tid: string;\n\t\ttitle?: string;\n\t\tdescription?: string;\n\t\tisSubmitting: boolean;\n\t};\n\t/** The steps that are not skipped, in order: what progress and a stepper count. */\n\tsteps: ViewStep[];\n\tactiveStep: ViewStep;\n\t/** The position of the current step among `steps`. */\n\tcurrentStepIndex: number;\n\tnavigation: ViewNavigation;\n}\n\n/**\n * Reads one slot's complete config from a normalized view; see the layout `readSlotConfig`, which this\n * types by the forms slot names.\n */\nexport function getSlotConfig<TSchema extends StandardSchemaV1>(\n\tviewConfig: Record<string, unknown>,\n\tslot: RecipeSlot,\n\tschema: TSchema,\n): StandardSchemaV1.InferOutput<TSchema> {\n\treturn readSlotConfig(viewConfig, slot, schema);\n}\n\n/**\n * Resolves the recipe a normalized form's `view` selects, or `undefined` when the form has no view.\n *\n * @remarks\n * Throws when `view.$type` is not registered on the engine, so a config normalized elsewhere fails\n * loudly instead of rendering without chrome.\n */\nexport function getViewRecipe(\n\tengine: { getRecipe(id: string): AnyRecipeRegistration | undefined },\n\tconfig: { id: string; view?: { $type: string } },\n): AnyRecipeRegistration | undefined {\n\tif (!config.view) return undefined;\n\tconst recipe = engine.getRecipe(config.view.$type);\n\tif (!recipe) {\n\t\tthrow new Error(`Form '${config.id}' uses view '${config.view.$type}' but the engine has no such recipe.`);\n\t}\n\treturn recipe;\n}\n\n/** Projects the steps that are not skipped, with their live state, onto the {@link ViewStep} list. */\nexport function projectViewSteps(\n\tsteps: ReadonlyArray<{ id: string; title?: string; description?: string }>,\n\tstates: readonly FormStepState[],\n\tcurrent: string,\n): ViewStep[] {\n\tconst active = steps.flatMap((step) => {\n\t\tconst state = states.find(({ id }) => id === step.id);\n\t\treturn state?.skipped ? [] : [{ step, state }];\n\t});\n\treturn active.map(({ step, state }, index) => ({\n\t\tid: step.id,\n\t\ttitle: step.title,\n\t\tdescription: step.description,\n\t\tindex,\n\t\ttotal: active.length,\n\t\tisActive: step.id === current,\n\t\tisCompleted: state?.complete ?? false,\n\t\tisInvalid: state?.invalid ?? false,\n\t\tisVisited: state?.visited ?? false,\n\t}));\n}\n\n/** The navigation a recipe block reads, from the step states and the commands of a runtime. */\nexport function createViewNavigation(\n\tstates: readonly FormStepState[],\n\tcurrent: string,\n\tcommands: { next: () => unknown; back: () => unknown; goTo: (id: string) => unknown },\n): ViewNavigation {\n\tconst canGoNext = stepAfter(states, current) !== undefined;\n\tconst canGoPrevious = stepBefore(states, current) !== undefined;\n\treturn {\n\t\tcanGoNext,\n\t\tcanGoPrevious,\n\t\tisFirstStep: !canGoPrevious,\n\t\tisLastStep: !canGoNext,\n\t\tcanGoToStep: (stepId) => states.find(({ id }) => id === stepId)?.reachable ?? false,\n\t\tgoToStep: (stepId) => void commands.goTo(stepId),\n\t\tgoToNextStep: () => void commands.next(),\n\t\tgoToPreviousStep: () => void commands.back(),\n\t};\n}\n\nexport function buildViewModel({\n\tconfig,\n\tkind,\n\tstates,\n\tcurrent,\n\tnavigation,\n\tisSubmitting,\n\tviewConfig,\n}: {\n\tconfig: FormConfigView;\n\tkind: RecipeKind;\n\tstates: readonly FormStepState[];\n\tcurrent: string;\n\tnavigation: ViewNavigation;\n\tisSubmitting?: boolean;\n\tviewConfig: Record<string, unknown>;\n}): ViewModel {\n\tconst steps = projectViewSteps(config.steps, states, current);\n\tconst activeStep = steps.find(({ isActive }) => isActive) ?? steps[0];\n\tif (!activeStep) {\n\t\tthrow new Error(`Form '${config.id}' has no steps.`);\n\t}\n\n\treturn {\n\t\tkind,\n\t\tform: {\n\t\t\tid: config.id,\n\t\t\ttitle: config.title,\n\t\t\tdescription: config.description,\n\t\t\tisSubmitting: isSubmitting ?? false,\n\t\t},\n\t\tsteps,\n\t\tactiveStep,\n\t\tcurrentStepIndex: activeStep.index,\n\t\tnavigation,\n\t\tviewConfig,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,SAAS,sBAA4C;AAwD9C,SAAS,cACf,YACA,MACA,QACwC;AACxC,SAAO,eAAe,YAAY,MAAM,MAAM;AAC/C;AASO,SAAS,cACf,QACA,QACoC;AACpC,MAAI,CAAC,OAAO,KAAM,QAAO;AACzB,QAAM,SAAS,OAAO,UAAU,OAAO,KAAK,KAAK;AACjD,MAAI,CAAC,QAAQ;AACZ,UAAM,IAAI,MAAM,SAAS,OAAO,EAAE,gBAAgB,OAAO,KAAK,KAAK,sCAAsC;AAAA,EAC1G;AACA,SAAO;AACR;AAGO,SAAS,iBACf,OACA,QACA,SACa;AACb,QAAM,SAAS,MAAM,QAAQ,CAAC,SAAS;AACtC,UAAM,QAAQ,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,KAAK,EAAE;AACpD,WAAO,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,EAC9C,CAAC;AACD,SAAO,OAAO,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,WAAW;AAAA,IAC9C,IAAI,KAAK;AAAA,IACT,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,IAClB;AAAA,IACA,OAAO,OAAO;AAAA,IACd,UAAU,KAAK,OAAO;AAAA,IACtB,aAAa,OAAO,YAAY;AAAA,IAChC,WAAW,OAAO,WAAW;AAAA,IAC7B,WAAW,OAAO,WAAW;AAAA,EAC9B,EAAE;AACH;AAGO,SAAS,qBACf,QACA,SACA,UACiB;AACjB,QAAM,YAAY,UAAU,QAAQ,OAAO,MAAM;AACjD,QAAM,gBAAgB,WAAW,QAAQ,OAAO,MAAM;AACtD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,aAAa,CAAC,WAAW,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,MAAM,GAAG,aAAa;AAAA,IAC9E,UAAU,CAAC,WAAW,KAAK,SAAS,KAAK,MAAM;AAAA,IAC/C,cAAc,MAAM,KAAK,SAAS,KAAK;AAAA,IACvC,kBAAkB,MAAM,KAAK,SAAS,KAAK;AAAA,EAC5C;AACD;AAEO,SAAS,eAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAQc;AACb,QAAM,QAAQ,iBAAiB,OAAO,OAAO,QAAQ,OAAO;AAC5D,QAAM,aAAa,MAAM,KAAK,CAAC,EAAE,SAAS,MAAM,QAAQ,KAAK,MAAM,CAAC;AACpE,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI,MAAM,SAAS,OAAO,EAAE,iBAAiB;AAAA,EACpD;AAEA,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AAAA,MACL,IAAI,OAAO;AAAA,MACX,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,MACpB,cAAc,gBAAgB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA,kBAAkB,WAAW;AAAA,IAC7B;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -14,7 +14,37 @@ import {
|
|
|
14
14
|
|
|
15
15
|
// src/lib/validate-form/parse-view.ts
|
|
16
16
|
import { resolveRecipeView } from "@schema-engine/layout";
|
|
17
|
+
import { safeParseNode, standardSchema } from "@schema-engine/registry";
|
|
17
18
|
var warnedMissingWizardRecipe = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
function recipeLookup(getRecipe, stepCount, appearance) {
|
|
20
|
+
return {
|
|
21
|
+
get(type) {
|
|
22
|
+
const recipe = getRecipe(type);
|
|
23
|
+
return recipe && { schema: viewSchema(recipe, stepCount, appearance) };
|
|
24
|
+
},
|
|
25
|
+
hint: "Register it with createFormEngine({ recipes: [...] })."
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function viewSchema(recipe, stepCount, appearance) {
|
|
29
|
+
return standardSchema((value) => {
|
|
30
|
+
const issues = [];
|
|
31
|
+
if (recipe.kind === "single-step" && stepCount !== 1) {
|
|
32
|
+
issues.push({
|
|
33
|
+
path: ["$type"],
|
|
34
|
+
message: `Recipe '${recipe.$type}' is single-step only (kind: 'single-step') but the form has ${stepCount} steps.`
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (recipe.kind === "wizard" && stepCount < 2) {
|
|
38
|
+
issues.push({
|
|
39
|
+
path: ["$type"],
|
|
40
|
+
message: `Recipe '${recipe.$type}' requires at least 2 steps (kind: 'wizard') but the form has ${stepCount} step(s).`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const resolved = resolveRecipeView(recipe, value, appearance);
|
|
44
|
+
issues.push(...resolved.issues, ...resolved.schemaIssues ?? []);
|
|
45
|
+
return issues.length > 0 ? { issues } : { value: resolved.view };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
18
48
|
function parseView(authored, form, options, appearance) {
|
|
19
49
|
const { getRecipe } = options;
|
|
20
50
|
const stepCount = form.stepCount;
|
|
@@ -35,44 +65,9 @@ function parseView(authored, form, options, appearance) {
|
|
|
35
65
|
}
|
|
36
66
|
view = { $type: defaultRecipe };
|
|
37
67
|
}
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const recipe = getRecipe(recipeType);
|
|
43
|
-
if (!recipe) {
|
|
44
|
-
return {
|
|
45
|
-
issues: [
|
|
46
|
-
issueAt(
|
|
47
|
-
["view", "$type"],
|
|
48
|
-
`Unknown view recipe '${recipeType}'. Register it with createFormEngine({ recipes: [...] }).`
|
|
49
|
-
)
|
|
50
|
-
]
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const issues = [];
|
|
54
|
-
if (recipe.kind === "single-step" && stepCount !== 1) {
|
|
55
|
-
issues.push(
|
|
56
|
-
issueAt(
|
|
57
|
-
["view", "$type"],
|
|
58
|
-
`Recipe '${recipeType}' is single-step only (kind: 'single-step') but the form has ${stepCount} steps.`
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (recipe.kind === "wizard" && stepCount < 2) {
|
|
63
|
-
issues.push(
|
|
64
|
-
issueAt(
|
|
65
|
-
["view", "$type"],
|
|
66
|
-
`Recipe '${recipeType}' requires at least 2 steps (kind: 'wizard') but the form has ${stepCount} step(s).`
|
|
67
|
-
)
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
const resolved = resolveRecipeView(recipe, view, appearance);
|
|
71
|
-
issues.push(...resolved.issues.map((issue) => issueAt(["view", ...issue.path], issue.message)));
|
|
72
|
-
if (resolved.schemaIssues) {
|
|
73
|
-
issues.push(...fromSchemaIssues(resolved.schemaIssues, ["view"]));
|
|
74
|
-
}
|
|
75
|
-
return { issues, view: isTaggedConfig(resolved.view) ? resolved.view : view };
|
|
68
|
+
const parsed = safeParseNode(recipeLookup(getRecipe, form.stepCount, appearance), view, ["view"]);
|
|
69
|
+
if (!parsed.success) return { issues: fromSchemaIssues(parsed.issues, []) };
|
|
70
|
+
return { issues: [], view: isTaggedConfig(parsed.data) ? parsed.data : view };
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
export {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/validate-form/parse-view.ts"],
|
|
4
|
+
"sourcesContent": ["import type { FormTaggedConfig } from '@/schemas/form-config';\nimport { DEFAULT_WIZARD_RECIPE } from '@/lib/form-view';\nimport { resolveRecipeView, type RecipeViewInput } from '@schema-engine/layout';\nimport { safeParseNode, standardSchema, type NodeLookup, type StandardSchemaIssue } from '@schema-engine/registry';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { AnyRecipeRegistration } from '@/types/registration';\nimport { logger } from '@/lib/logger';\nimport type { AppearanceScope } from '@/lib/resolve-appearance';\nimport { issueAt, isTaggedConfig, type FormValidationIssue } from './issues';\nimport type { ValidateFormOptions } from './options';\nimport { fromSchemaIssues } from './schema-issues';\n\n/**\n * Form ids already warned about, per owner.\n *\n * @remarks\n * A renderer re-validates an inline raw config on every render, so the missing-recipe warning\n * would otherwise repeat for the same form.\n */\nconst warnedMissingWizardRecipe = new WeakMap<object, Set<string>>();\n\n/**\n * Finds a recipe by the `$type` of the view, with what holds a view of that recipe ({@link viewSchema}).\n *\n * @remarks\n * `safeParseNode` runs the schema only once it has found the recipe, so the view is an object with a registered\n * `$type`. Its issues are relative to the view.\n */\nfunction recipeLookup(\n\tgetRecipe: ValidateFormOptions['getRecipe'],\n\tstepCount: number,\n\tappearance: AppearanceScope,\n): NodeLookup<{ schema: StandardSchemaV1 }> {\n\treturn {\n\t\tget(type) {\n\t\t\tconst recipe = getRecipe(type);\n\t\t\treturn recipe && { schema: viewSchema(recipe, stepCount, appearance) };\n\t\t},\n\t\thint: 'Register it with createFormEngine({ recipes: [...] }).',\n\t};\n}\n\n/**\n * The schema of a view: the recipe's kind against the number of steps, then the view as `resolveRecipeView` resolves it.\n *\n * @remarks\n * The `value as RecipeViewInput` cast relies on the lookup contract: {@link recipeLookup} hands this schema only to\n * `safeParseNode`, which runs it after it has checked that the view is an object with a string `$type`.\n */\nfunction viewSchema(recipe: AnyRecipeRegistration, stepCount: number, appearance: AppearanceScope): StandardSchemaV1 {\n\treturn standardSchema((value) => {\n\t\tconst issues: StandardSchemaIssue[] = [];\n\t\tif (recipe.kind === 'single-step' && stepCount !== 1) {\n\t\t\tissues.push({\n\t\t\t\tpath: ['$type'],\n\t\t\t\tmessage: `Recipe '${recipe.$type}' is single-step only (kind: 'single-step') but the form has ${stepCount} steps.`,\n\t\t\t});\n\t\t}\n\t\tif (recipe.kind === 'wizard' && stepCount < 2) {\n\t\t\tissues.push({\n\t\t\t\tpath: ['$type'],\n\t\t\t\tmessage: `Recipe '${recipe.$type}' requires at least 2 steps (kind: 'wizard') but the form has ${stepCount} step(s).`,\n\t\t\t});\n\t\t}\n\t\tconst resolved = resolveRecipeView(recipe, value as RecipeViewInput, appearance);\n\t\tissues.push(...resolved.issues, ...(resolved.schemaIssues ?? []));\n\t\treturn issues.length > 0 ? { issues } : { value: resolved.view };\n\t});\n}\n\nexport function parseView(\n\tauthored: FormTaggedConfig | undefined,\n\tform: { id: string; stepCount: number },\n\toptions: Pick<ValidateFormOptions, 'getRecipe' | 'defaultWizardRecipe' | 'owner'>,\n\tappearance: AppearanceScope,\n): { issues: FormValidationIssue[]; view?: FormTaggedConfig } {\n\tconst { getRecipe } = options;\n\tconst stepCount = form.stepCount;\n\tlet view = authored;\n\tif (!view) {\n\t\tif (stepCount === 0) return { issues: [issueAt(['steps'], 'Form must have at least one step.')] };\n\t\tif (stepCount < 2) return { issues: [] };\n\t\tconst defaultRecipe = options.defaultWizardRecipe ?? DEFAULT_WIZARD_RECIPE;\n\t\tif (!getRecipe(defaultRecipe)) {\n\t\t\tconst warned = warnedMissingWizardRecipe.get(options.owner) ?? new Set<string>();\n\t\t\twarnedMissingWizardRecipe.set(options.owner, warned);\n\t\t\tif (warned.has(form.id)) return { issues: [] };\n\t\t\twarned.add(form.id);\n\t\t\tlogger.warn(\n\t\t\t\t`Form '${form.id}' has ${stepCount} steps but no '${defaultRecipe}' recipe is registered. The form renders every step on a single page without a view layout. Register a wizard recipe with createFormEngine({ recipes: [...] }) or set an explicit view.$type.`,\n\t\t\t);\n\t\t\treturn { issues: [] };\n\t\t}\n\t\tview = { $type: defaultRecipe };\n\t}\n\n\tconst parsed = safeParseNode(recipeLookup(getRecipe, form.stepCount, appearance), view, ['view']);\n\tif (!parsed.success) return { issues: fromSchemaIssues(parsed.issues, []) };\n\treturn { issues: [], view: isTaggedConfig(parsed.data) ? parsed.data : view };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAEA,SAAS,yBAA+C;AACxD,SAAS,eAAe,sBAAiE;AAgBzF,IAAM,4BAA4B,oBAAI,QAA6B;AASnE,SAAS,aACR,WACA,WACA,YAC2C;AAC3C,SAAO;AAAA,IACN,IAAI,MAAM;AACT,YAAM,SAAS,UAAU,IAAI;AAC7B,aAAO,UAAU,EAAE,QAAQ,WAAW,QAAQ,WAAW,UAAU,EAAE;AAAA,IACtE;AAAA,IACA,MAAM;AAAA,EACP;AACD;AASA,SAAS,WAAW,QAA+B,WAAmB,YAA+C;AACpH,SAAO,eAAe,CAAC,UAAU;AAChC,UAAM,SAAgC,CAAC;AACvC,QAAI,OAAO,SAAS,iBAAiB,cAAc,GAAG;AACrD,aAAO,KAAK;AAAA,QACX,MAAM,CAAC,OAAO;AAAA,QACd,SAAS,WAAW,OAAO,KAAK,gEAAgE,SAAS;AAAA,MAC1G,CAAC;AAAA,IACF;AACA,QAAI,OAAO,SAAS,YAAY,YAAY,GAAG;AAC9C,aAAO,KAAK;AAAA,QACX,MAAM,CAAC,OAAO;AAAA,QACd,SAAS,WAAW,OAAO,KAAK,iEAAiE,SAAS;AAAA,MAC3G,CAAC;AAAA,IACF;AACA,UAAM,WAAW,kBAAkB,QAAQ,OAA0B,UAAU;AAC/E,WAAO,KAAK,GAAG,SAAS,QAAQ,GAAI,SAAS,gBAAgB,CAAC,CAAE;AAChE,WAAO,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,EAAE,OAAO,SAAS,KAAK;AAAA,EAChE,CAAC;AACF;AAEO,SAAS,UACf,UACA,MACA,SACA,YAC6D;AAC7D,QAAM,EAAE,UAAU,IAAI;AACtB,QAAM,YAAY,KAAK;AACvB,MAAI,OAAO;AACX,MAAI,CAAC,MAAM;AACV,QAAI,cAAc,EAAG,QAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,GAAG,mCAAmC,CAAC,EAAE;AAChG,QAAI,YAAY,EAAG,QAAO,EAAE,QAAQ,CAAC,EAAE;AACvC,UAAM,gBAAgB,QAAQ,uBAAuB;AACrD,QAAI,CAAC,UAAU,aAAa,GAAG;AAC9B,YAAM,SAAS,0BAA0B,IAAI,QAAQ,KAAK,KAAK,oBAAI,IAAY;AAC/E,gCAA0B,IAAI,QAAQ,OAAO,MAAM;AACnD,UAAI,OAAO,IAAI,KAAK,EAAE,EAAG,QAAO,EAAE,QAAQ,CAAC,EAAE;AAC7C,aAAO,IAAI,KAAK,EAAE;AAClB,aAAO;AAAA,QACN,SAAS,KAAK,EAAE,SAAS,SAAS,kBAAkB,aAAa;AAAA,MAClE;AACA,aAAO,EAAE,QAAQ,CAAC,EAAE;AAAA,IACrB;AACA,WAAO,EAAE,OAAO,cAAc;AAAA,EAC/B;AAEA,QAAM,SAAS,cAAc,aAAa,WAAW,KAAK,WAAW,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;AAChG,MAAI,CAAC,OAAO,QAAS,QAAO,EAAE,QAAQ,iBAAiB,OAAO,QAAQ,CAAC,CAAC,EAAE;AAC1E,SAAO,EAAE,QAAQ,CAAC,GAAG,MAAM,eAAe,OAAO,IAAI,IAAI,OAAO,OAAO,KAAK;AAC7E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineInputContract
|
|
3
|
+
} from "./chunk-V3GYAG33.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseFieldSchema
|
|
6
|
+
} from "./chunk-237BHPDH.js";
|
|
7
|
+
|
|
8
|
+
// src/default-elements/input-otp.ts
|
|
9
|
+
import * as z from "zod/mini";
|
|
10
|
+
var InputOTPFieldExtensionSchema = z.object({
|
|
11
|
+
length: z.optional(z._default(z.number().check(z.positive()), 6)),
|
|
12
|
+
autoFocus: z.optional(z.boolean()),
|
|
13
|
+
pattern: z.optional(z._default(z.enum(["numeric", "alphanumeric"]), "numeric")),
|
|
14
|
+
disabled: z.optional(z.boolean()),
|
|
15
|
+
incompleteMessage: z.optional(z.string())
|
|
16
|
+
});
|
|
17
|
+
function withCompleteCodeRule(config) {
|
|
18
|
+
const length = config.length ?? 6;
|
|
19
|
+
if (config.rules?.some((rule) => ["minLength", "maxLength", "pattern"].includes(rule.$type))) return config;
|
|
20
|
+
const complete = {
|
|
21
|
+
$type: "pattern",
|
|
22
|
+
value: `^.{${length}}$`,
|
|
23
|
+
message: config.incompleteMessage ?? `Enter all ${length} characters`
|
|
24
|
+
};
|
|
25
|
+
return { ...config, rules: [...config.rules ?? [], complete] };
|
|
26
|
+
}
|
|
27
|
+
var InputOTPFieldConfigSchema = z.pipe(
|
|
28
|
+
z.extend(BaseFieldSchema, {
|
|
29
|
+
$type: z.literal("input-otp"),
|
|
30
|
+
...InputOTPFieldExtensionSchema.shape
|
|
31
|
+
}),
|
|
32
|
+
z.transform(withCompleteCodeRule)
|
|
33
|
+
);
|
|
34
|
+
var inputOTPFieldValue = () => z.string();
|
|
35
|
+
var InputOTPElementContract = defineInputContract({
|
|
36
|
+
$type: "input-otp",
|
|
37
|
+
appearanceAxes: ["size"],
|
|
38
|
+
schema: InputOTPFieldConfigSchema,
|
|
39
|
+
value: inputOTPFieldValue,
|
|
40
|
+
metadata: {
|
|
41
|
+
name: "OTP Input",
|
|
42
|
+
description: "One-time password input field with multiple slots",
|
|
43
|
+
category: "input"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
InputOTPFieldExtensionSchema,
|
|
49
|
+
InputOTPFieldConfigSchema,
|
|
50
|
+
inputOTPFieldValue,
|
|
51
|
+
InputOTPElementContract
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/default-elements/input-otp.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport type { BaseValidationRule } from '@/schemas/validation/types';\nimport { defineInputContract } from './define-contract';\n\nexport const InputOTPFieldExtensionSchema = z.object({\n\tlength: z.optional(z._default(z.number().check(z.positive()), 6)),\n\tautoFocus: z.optional(z.boolean()),\n\tpattern: z.optional(z._default(z.enum(['numeric', 'alphanumeric']), 'numeric')),\n\tdisabled: z.optional(z.boolean()),\n\tincompleteMessage: z.optional(z.string()),\n});\n\n/**\n * Adds an exact-length rule when the author wrote no length or pattern rule.\n *\n * @remarks\n * The code is the filled slots joined, so one with a gap is a shorter string and would\n * otherwise pass as complete. A `pattern` rather than `minLength` because it also holds the\n * code to exactly `length` characters. Format rules skip an empty value, so an empty optional\n * code stays valid and `required` still rejects it. `incompleteMessage` replaces the default text.\n */\nfunction withCompleteCodeRule<T extends { length?: number; incompleteMessage?: string; rules?: BaseValidationRule[] }>(\n\tconfig: T,\n): T {\n\tconst length = config.length ?? 6;\n\tif (config.rules?.some((rule) => ['minLength', 'maxLength', 'pattern'].includes(rule.$type))) return config;\n\tconst complete = {\n\t\t$type: 'pattern',\n\t\tvalue: `^.{${length}}$`,\n\t\tmessage: config.incompleteMessage ?? `Enter all ${length} characters`,\n\t} as const;\n\treturn { ...config, rules: [...(config.rules ?? []), complete] };\n}\n\nexport const InputOTPFieldConfigSchema = z.pipe(\n\tz.extend(BaseFieldSchema, {\n\t\t$type: z.literal('input-otp'),\n\t\t...InputOTPFieldExtensionSchema.shape,\n\t}),\n\tz.transform(withCompleteCodeRule),\n);\n\nexport type InputOTPFieldExtension = z.infer<typeof InputOTPFieldExtensionSchema>;\nexport type InputOTPFieldConfig = z.infer<typeof InputOTPFieldConfigSchema>;\n\n/** The value an OTP field writes: the code typed so far. */\nexport const inputOTPFieldValue = () => z.string();\n\n/** The contract of the `input-otp` element: what every renderer of it agrees on. */\nexport const InputOTPElementContract = defineInputContract({\n\t$type: 'input-otp',\n\tappearanceAxes: ['size'],\n\tschema: InputOTPFieldConfigSchema,\n\tvalue: inputOTPFieldValue,\n\tmetadata: {\n\t\tname: 'OTP Input',\n\t\tdescription: 'One-time password input field with multiple slots',\n\t\tcategory: 'input',\n\t},\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,YAAY,OAAO;AAKZ,IAAM,+BAAiC,SAAO;AAAA,EACpD,QAAU,WAAW,WAAW,SAAO,EAAE,MAAQ,WAAS,CAAC,GAAG,CAAC,CAAC;AAAA,EAChE,WAAa,WAAW,UAAQ,CAAC;AAAA,EACjC,SAAW,WAAW,WAAW,OAAK,CAAC,WAAW,cAAc,CAAC,GAAG,SAAS,CAAC;AAAA,EAC9E,UAAY,WAAW,UAAQ,CAAC;AAAA,EAChC,mBAAqB,WAAW,SAAO,CAAC;AACzC,CAAC;AAWD,SAAS,qBACR,QACI;AACJ,QAAM,SAAS,OAAO,UAAU;AAChC,MAAI,OAAO,OAAO,KAAK,CAAC,SAAS,CAAC,aAAa,aAAa,SAAS,EAAE,SAAS,KAAK,KAAK,CAAC,EAAG,QAAO;AACrG,QAAM,WAAW;AAAA,IAChB,OAAO;AAAA,IACP,OAAO,MAAM,MAAM;AAAA,IACnB,SAAS,OAAO,qBAAqB,aAAa,MAAM;AAAA,EACzD;AACA,SAAO,EAAE,GAAG,QAAQ,OAAO,CAAC,GAAI,OAAO,SAAS,CAAC,GAAI,QAAQ,EAAE;AAChE;AAEO,IAAM,4BAA8B;AAAA,EACxC,SAAO,iBAAiB;AAAA,IACzB,OAAS,UAAQ,WAAW;AAAA,IAC5B,GAAG,6BAA6B;AAAA,EACjC,CAAC;AAAA,EACC,YAAU,oBAAoB;AACjC;AAMO,IAAM,qBAAqB,MAAQ,SAAO;AAG1C,IAAM,0BAA0B,oBAAoB;AAAA,EAC1D,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectStepFieldPaths
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MG7VFU6V.js";
|
|
4
4
|
|
|
5
5
|
// src/engine/step-machine.ts
|
|
6
6
|
var startProgress = (first) => ({ current: first, visited: [first], complete: [] });
|
|
@@ -12,11 +12,12 @@ function moveProgress(progress, to, completed = []) {
|
|
|
12
12
|
}
|
|
13
13
|
function deriveStepStates(steps, progress, derived, mode) {
|
|
14
14
|
const at = steps.findIndex(({ id }) => id === progress.current);
|
|
15
|
-
return steps.map(({ id }, index) => {
|
|
15
|
+
return steps.map(({ id, title }, index) => {
|
|
16
16
|
const skipped = derived.skipped.includes(id);
|
|
17
17
|
const visited = progress.visited.includes(id);
|
|
18
18
|
return {
|
|
19
19
|
id,
|
|
20
|
+
title,
|
|
20
21
|
skipped,
|
|
21
22
|
visited,
|
|
22
23
|
complete: progress.complete.includes(id),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/engine/step-machine.ts"],
|
|
4
|
+
"sourcesContent": ["import { collectStepFieldPaths, type ValidationStep } from './value-validation';\n\n/**\n * How freely a wizard moves forward.\n *\n * @remarks\n * `'linear'` reaches only steps already visited and validates every step on the way; `'free'` reaches any\n * active step without validating. Going back is always allowed and `next()` validates in both.\n */\nexport type StepNavigationMode = 'linear' | 'free';\n\n/**\n * One step of a form as a renderer reads it.\n *\n * @remarks\n * Only `visited` and `complete` are stored, by step id. `skipped` is derived from the values (the step's\n * constraints hide it) and `invalid` from the errors recorded at its fields, so neither can go stale.\n * `title` is the step config's, so a stepper reused across forms reads it here instead of looking it up by `id`.\n */\nexport interface FormStepState {\n\treadonly id: string;\n\t/**\n\t * The step config's `title`, as authored: the engine does not translate it.\n\t *\n\t * @remarks\n\t * `undefined` when the runtime was given a step with no title. A form config requires one, so every step of a\n\t * validated config has it; only a hand-built runtime config can leave it out, and a stepper may fall back to `id`.\n\t */\n\treadonly title?: string;\n\t/** Its constraints hide it: it is passed over and its fields take no part. */\n\treadonly skipped: boolean;\n\treadonly visited: boolean;\n\t/** `next()` validated it and moved on. */\n\treadonly complete: boolean;\n\t/** An error is recorded at one of its fields. */\n\treadonly invalid: boolean;\n\t/** `goTo` can move there: an active step other than the current one that is before it, or after it when the form's `navigation` is `'free'` or the step was visited. */\n\treadonly reachable: boolean;\n}\n\n/** What the runtime stores of the steps: where the user is, and which steps were visited and completed, by id. */\nexport interface StepProgress {\n\treadonly current: string;\n\treadonly visited: readonly string[];\n\treadonly complete: readonly string[];\n}\n\n/** Progress at the start: the first step is current and visited. */\nexport const startProgress = (first: string): StepProgress => ({ current: first, visited: [first], complete: [] });\n\nconst including = (ids: readonly string[], added: readonly string[]): readonly string[] =>\n\tadded.every((id) => ids.includes(id)) ? ids : [...ids, ...added.filter((id) => !ids.includes(id))];\n\n/** Progress after moving to `to`, which becomes visited, with `completed` marked complete. */\nexport function moveProgress(progress: StepProgress, to: string, completed: readonly string[] = []): StepProgress {\n\tconst visited = including(progress.visited, [to]);\n\tconst complete = including(progress.complete, completed);\n\treturn progress.current === to && visited === progress.visited && complete === progress.complete\n\t\t? progress\n\t\t: { current: to, visited, complete };\n}\n\n/** The steps as renderers read them, from the stored progress and what the values and errors say. */\nexport function deriveStepStates(\n\tsteps: readonly { readonly id: string; readonly title?: string }[],\n\tprogress: StepProgress,\n\tderived: { readonly skipped: readonly string[]; readonly invalid: readonly string[] },\n\tmode: StepNavigationMode,\n): FormStepState[] {\n\tconst at = steps.findIndex(({ id }) => id === progress.current);\n\treturn steps.map(({ id, title }, index) => {\n\t\tconst skipped = derived.skipped.includes(id);\n\t\tconst visited = progress.visited.includes(id);\n\t\treturn {\n\t\t\tid,\n\t\t\ttitle,\n\t\t\tskipped,\n\t\t\tvisited,\n\t\t\tcomplete: progress.complete.includes(id),\n\t\t\tinvalid: derived.invalid.includes(id),\n\t\t\treachable: !skipped && id !== progress.current && (index < at || mode === 'free' || visited),\n\t\t};\n\t});\n}\n\n/** The ids of the steps that are not skipped, in order. */\nexport const activeStepIds = (states: readonly FormStepState[]): string[] =>\n\tstates.filter(({ skipped }) => !skipped).map(({ id }) => id);\n\n/** The nearest active step after `id`, which may itself be skipped, or `undefined` on the last one. */\nexport function stepAfter(states: readonly FormStepState[], id: string): string | undefined {\n\tconst at = states.findIndex((state) => state.id === id);\n\treturn states.slice(at + 1).find(({ skipped }) => !skipped)?.id;\n}\n\n/** The nearest active step before `id`, which may itself be skipped, or `undefined` on the first one. */\nexport function stepBefore(states: readonly FormStepState[], id: string): string | undefined {\n\tconst at = states.findIndex((state) => state.id === id);\n\treturn states.slice(0, Math.max(at, 0)).findLast(({ skipped }) => !skipped)?.id;\n}\n\n/**\n * The ids of the steps that have an error recorded at one of their fields.\n *\n * @remarks Fields are read as `collectStepFieldPaths` expands them over the live rows.\n */\nexport function stepsWithErrors(\n\tsteps: readonly (ValidationStep & { readonly id: string })[],\n\tvalues: Record<string, unknown>,\n\terrors: Readonly<Record<string, unknown>>,\n): string[] {\n\treturn steps\n\t\t.filter((step) => collectStepFieldPaths(step, values).some((path) => Object.hasOwn(errors, path)))\n\t\t.map(({ id }) => id);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAgDO,IAAM,gBAAgB,CAAC,WAAiC,EAAE,SAAS,OAAO,SAAS,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE;AAEhH,IAAM,YAAY,CAAC,KAAwB,UAC1C,MAAM,MAAM,CAAC,OAAO,IAAI,SAAS,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;AAG3F,SAAS,aAAa,UAAwB,IAAY,YAA+B,CAAC,GAAiB;AACjH,QAAM,UAAU,UAAU,SAAS,SAAS,CAAC,EAAE,CAAC;AAChD,QAAM,WAAW,UAAU,SAAS,UAAU,SAAS;AACvD,SAAO,SAAS,YAAY,MAAM,YAAY,SAAS,WAAW,aAAa,SAAS,WACrF,WACA,EAAE,SAAS,IAAI,SAAS,SAAS;AACrC;AAGO,SAAS,iBACf,OACA,UACA,SACA,MACkB;AAClB,QAAM,KAAK,MAAM,UAAU,CAAC,EAAE,GAAG,MAAM,OAAO,SAAS,OAAO;AAC9D,SAAO,MAAM,IAAI,CAAC,EAAE,IAAI,MAAM,GAAG,UAAU;AAC1C,UAAM,UAAU,QAAQ,QAAQ,SAAS,EAAE;AAC3C,UAAM,UAAU,SAAS,QAAQ,SAAS,EAAE;AAC5C,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU,SAAS,SAAS,SAAS,EAAE;AAAA,MACvC,SAAS,QAAQ,QAAQ,SAAS,EAAE;AAAA,MACpC,WAAW,CAAC,WAAW,OAAO,SAAS,YAAY,QAAQ,MAAM,SAAS,UAAU;AAAA,IACrF;AAAA,EACD,CAAC;AACF;AAGO,IAAM,gBAAgB,CAAC,WAC7B,OAAO,OAAO,CAAC,EAAE,QAAQ,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE;AAGrD,SAAS,UAAU,QAAkC,IAAgC;AAC3F,QAAM,KAAK,OAAO,UAAU,CAAC,UAAU,MAAM,OAAO,EAAE;AACtD,SAAO,OAAO,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,MAAM,CAAC,OAAO,GAAG;AAC9D;AAGO,SAAS,WAAW,QAAkC,IAAgC;AAC5F,QAAM,KAAK,OAAO,UAAU,CAAC,UAAU,MAAM,OAAO,EAAE;AACtD,SAAO,OAAO,MAAM,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,QAAQ,MAAM,CAAC,OAAO,GAAG;AAC9E;AAOO,SAAS,gBACf,OACA,QACA,QACW;AACX,SAAO,MACL,OAAO,CAAC,SAAS,sBAAsB,MAAM,MAAM,EAAE,KAAK,CAAC,SAAS,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,EAChG,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE;AACrB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
createZodSchemaFromRules,
|
|
10
10
|
getValidationRulesForElement,
|
|
11
11
|
isFieldRequired
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4YANBG3M.js";
|
|
13
13
|
import {
|
|
14
14
|
getElementName,
|
|
15
15
|
walkNamedElements
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-7QLR5WM3.js";
|
|
17
17
|
import {
|
|
18
18
|
expandContainerParentPaths,
|
|
19
19
|
expandFieldTemplatePaths,
|