@visual-platform/contracts 0.0.0-stage → 0.1.0
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/dist/classes.d.ts +11 -0
- package/dist/classes.d.ts.map +1 -0
- package/dist/classes.js +34 -0
- package/dist/classes.js.map +1 -0
- package/dist/component.d.ts +135 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +176 -0
- package/dist/component.js.map +1 -0
- package/dist/data.d.ts +152 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +336 -0
- package/dist/data.js.map +1 -0
- package/dist/design.d.ts +139 -0
- package/dist/design.d.ts.map +1 -0
- package/dist/design.js +226 -0
- package/dist/design.js.map +1 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +46 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/locales.d.ts +37 -0
- package/dist/locales.d.ts.map +1 -0
- package/dist/locales.js +36 -0
- package/dist/locales.js.map +1 -0
- package/dist/page-document.d.ts +202 -0
- package/dist/page-document.d.ts.map +1 -0
- package/dist/page-document.js +71 -0
- package/dist/page-document.js.map +1 -0
- package/dist/published.d.ts +353 -0
- package/dist/published.d.ts.map +1 -0
- package/dist/published.js +66 -0
- package/dist/published.js.map +1 -0
- package/dist/references.d.ts +51 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +35 -0
- package/dist/references.js.map +1 -0
- package/dist/responsive.d.ts +19 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +18 -0
- package/dist/responsive.js.map +1 -0
- package/dist/section.d.ts +33 -0
- package/dist/section.d.ts.map +1 -0
- package/dist/section.js +53 -0
- package/dist/section.js.map +1 -0
- package/dist/seo.d.ts +98 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +71 -0
- package/dist/seo.js.map +1 -0
- package/dist/tables.d.ts +134 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +438 -0
- package/dist/tables.js.map +1 -0
- package/package.json +31 -3
- package/README.md +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ComponentNode } from "./page-document.js";
|
|
3
|
+
export declare const MAX_CLASSES = 60;
|
|
4
|
+
export declare function splitClasses(value: string): string[];
|
|
5
|
+
export declare function invalidClasses(value: string): string[];
|
|
6
|
+
export declare const ClassNameSchema: z.ZodString;
|
|
7
|
+
/** Every class used by these documents (for CSS compilation and `vp classes pull`). */
|
|
8
|
+
export declare function collectClasses(documents: {
|
|
9
|
+
nodes: readonly ComponentNode[];
|
|
10
|
+
}[]): string[];
|
|
11
|
+
//# sourceMappingURL=classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnE,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEtD;AAED,eAAO,MAAM,eAAe,aAI1B,CAAC;AAEH,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,SAAS,EAAE;IAAE,KAAK,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,EAAE,GAAG,MAAM,EAAE,CAIzF"}
|
package/dist/classes.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { walkNodes } from "./page-document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Tailwind utility classes on a block (ADR-029). Only utility syntax: letters, digits and the
|
|
5
|
+
* punctuation used by variants/arbitrary values. No quotes, backslashes, url()/image-set() (no
|
|
6
|
+
* external loads), no @import/expression.
|
|
7
|
+
*/
|
|
8
|
+
const TOKEN = /^[A-Za-z0-9_:\-[\].\/#%(),!@&*+>~=]{1,120}$/;
|
|
9
|
+
const FORBIDDEN = /url\(|image-set\(|expression\(|@import|javascript:/i;
|
|
10
|
+
export const MAX_CLASSES = 60;
|
|
11
|
+
export function splitClasses(value) {
|
|
12
|
+
return value.split(/\s+/).filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
export function invalidClasses(value) {
|
|
15
|
+
return splitClasses(value).filter((t) => !TOKEN.test(t) || FORBIDDEN.test(t));
|
|
16
|
+
}
|
|
17
|
+
export const ClassNameSchema = z.string().max(600).superRefine((v, ctx) => {
|
|
18
|
+
const bad = invalidClasses(v);
|
|
19
|
+
if (bad.length)
|
|
20
|
+
ctx.addIssue({ code: "custom", message: `not allowed: ${bad.slice(0, 3).join(" ")}` });
|
|
21
|
+
if (splitClasses(v).length > MAX_CLASSES)
|
|
22
|
+
ctx.addIssue({ code: "custom", message: `at most ${MAX_CLASSES} classes per block` });
|
|
23
|
+
});
|
|
24
|
+
/** Every class used by these documents (for CSS compilation and `vp classes pull`). */
|
|
25
|
+
export function collectClasses(documents) {
|
|
26
|
+
const out = new Set();
|
|
27
|
+
for (const d of documents)
|
|
28
|
+
for (const n of walkNodes(d.nodes))
|
|
29
|
+
if (n.className)
|
|
30
|
+
for (const c of splitClasses(n.className))
|
|
31
|
+
out.add(c);
|
|
32
|
+
return [...out].sort();
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAsB,MAAM,oBAAoB,CAAC;AA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M,CAAC,IAAI,SAAS;QAAE,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,CAAC,SAAS;gBAAE,KAAK,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;oBAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACtI,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ComponentNode } from "./page-document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Composed component (ADR-028): built in the editor from built-in basic/container blocks, stored at
|
|
5
|
+
* Project scope with draft/versions. `props` expose chosen inner fields to whoever places it; text is
|
|
6
|
+
* translated per locale inside the component (structure is shared by all languages).
|
|
7
|
+
*/
|
|
8
|
+
export declare const COMPONENT_REF_TYPE = "ComponentRef";
|
|
9
|
+
/** Internal wrapper the renderer understands natively: applies a design-system theme to its children. */
|
|
10
|
+
export declare const THEME_SCOPE_TYPE = "VisualThemeScope";
|
|
11
|
+
export declare const COMPONENT_PROP_TYPES: readonly ["text", "textarea", "image", "link", "icon", "number", "boolean", "select"];
|
|
12
|
+
export declare const ComponentPropSchema: z.ZodObject<{
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
label: z.ZodString;
|
|
15
|
+
type: z.ZodEnum<{
|
|
16
|
+
boolean: "boolean";
|
|
17
|
+
icon: "icon";
|
|
18
|
+
image: "image";
|
|
19
|
+
link: "link";
|
|
20
|
+
number: "number";
|
|
21
|
+
select: "select";
|
|
22
|
+
text: "text";
|
|
23
|
+
textarea: "textarea";
|
|
24
|
+
}>;
|
|
25
|
+
binds: z.ZodArray<z.ZodObject<{
|
|
26
|
+
nodeId: z.ZodString;
|
|
27
|
+
prop: z.ZodString;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type ComponentProp = z.infer<typeof ComponentPropSchema>;
|
|
33
|
+
export declare const ComponentDocumentSchema: z.ZodObject<{
|
|
34
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
35
|
+
nodes: z.ZodArray<z.ZodType<ComponentNode, unknown, z.core.$ZodTypeInternals<ComponentNode, unknown>>>;
|
|
36
|
+
props: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
label: z.ZodString;
|
|
39
|
+
type: z.ZodEnum<{
|
|
40
|
+
boolean: "boolean";
|
|
41
|
+
icon: "icon";
|
|
42
|
+
image: "image";
|
|
43
|
+
link: "link";
|
|
44
|
+
number: "number";
|
|
45
|
+
select: "select";
|
|
46
|
+
text: "text";
|
|
47
|
+
textarea: "textarea";
|
|
48
|
+
}>;
|
|
49
|
+
binds: z.ZodArray<z.ZodObject<{
|
|
50
|
+
nodeId: z.ZodString;
|
|
51
|
+
prop: z.ZodString;
|
|
52
|
+
}, z.core.$strict>>;
|
|
53
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
55
|
+
}, z.core.$strict>>>;
|
|
56
|
+
defaultLocale: z.ZodString;
|
|
57
|
+
translations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
58
|
+
theme: z.ZodOptional<z.ZodString>;
|
|
59
|
+
data: z.ZodOptional<z.ZodLazy<z.ZodArray<z.ZodObject<{
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
label: z.ZodOptional<z.ZodString>;
|
|
62
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
63
|
+
app: "app";
|
|
64
|
+
table: "table";
|
|
65
|
+
}>>;
|
|
66
|
+
shape: z.ZodEnum<{
|
|
67
|
+
list: "list";
|
|
68
|
+
object: "object";
|
|
69
|
+
}>;
|
|
70
|
+
fields: z.ZodArray<z.ZodType<import("./data.js").DataField, unknown, z.core.$ZodTypeInternals<import("./data.js").DataField, unknown>>>;
|
|
71
|
+
sample: z.ZodOptional<z.ZodUnknown>;
|
|
72
|
+
query: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
73
|
+
table: z.ZodString;
|
|
74
|
+
where: z.ZodOptional<z.ZodType<import("./tables.js").Filter, unknown, z.core.$ZodTypeInternals<import("./tables.js").Filter, unknown>>>;
|
|
75
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
|
+
field: z.ZodString;
|
|
77
|
+
dir: z.ZodDefault<z.ZodEnum<{
|
|
78
|
+
asc: "asc";
|
|
79
|
+
desc: "desc";
|
|
80
|
+
}>>;
|
|
81
|
+
}, z.core.$strict>>>;
|
|
82
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
83
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
84
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
85
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strict>>>;
|
|
87
|
+
single: z.ZodOptional<z.ZodBoolean>;
|
|
88
|
+
}, z.core.$strict>>>>;
|
|
89
|
+
disabledLocales: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
90
|
+
childrenSlot: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
nodeId: z.ZodString;
|
|
92
|
+
slot: z.ZodString;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
export type ComponentDocument = z.infer<typeof ComponentDocumentSchema>;
|
|
96
|
+
export declare const ComponentRefPropsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
97
|
+
values: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
dataMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
99
|
+
eventMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
100
|
+
mode: z.ZodLiteral<"follow">;
|
|
101
|
+
componentId: z.ZodString;
|
|
102
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
103
|
+
values: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
104
|
+
dataMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
105
|
+
eventMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
106
|
+
mode: z.ZodLiteral<"fixed">;
|
|
107
|
+
componentId: z.ZodString;
|
|
108
|
+
versionId: z.ZodString;
|
|
109
|
+
}, z.core.$loose>], "mode">;
|
|
110
|
+
export type ComponentRefProps = z.infer<typeof ComponentRefPropsSchema>;
|
|
111
|
+
export declare function componentRefs(nodes: readonly ComponentNode[]): {
|
|
112
|
+
nodeId: string;
|
|
113
|
+
props: ComponentRefProps | null;
|
|
114
|
+
}[];
|
|
115
|
+
/**
|
|
116
|
+
* The component's nodes for one locale with prop values applied:
|
|
117
|
+
* base content → translations of `locale` → values passed by the page/app (values win).
|
|
118
|
+
* Bindings to nodes that no longer exist are ignored.
|
|
119
|
+
*/
|
|
120
|
+
export declare function applyComponent(doc: ComponentDocument, opts?: {
|
|
121
|
+
locale?: string | undefined;
|
|
122
|
+
values?: Record<string, unknown> | undefined;
|
|
123
|
+
}): ComponentNode[];
|
|
124
|
+
/** Wrap nodes in a theme scope when the component pins a theme. */
|
|
125
|
+
export declare function withTheme(nodes: ComponentNode[], theme: string | undefined, id: string): ComponentNode[];
|
|
126
|
+
/** Is the component switched on for this locale (exact code or its base language)? */
|
|
127
|
+
export declare function componentEnabledFor(doc: Pick<ComponentDocument, "disabledLocales">, locale: string | undefined): boolean;
|
|
128
|
+
/** Apply a placement's dataMap/eventMap to a component's nodes (ADR-036). */
|
|
129
|
+
export declare function applyPlacement(nodes: readonly ComponentNode[], dataMap?: Record<string, string>, eventMap?: Record<string, string>): ComponentNode[];
|
|
130
|
+
/**
|
|
131
|
+
* Replace ComponentRef nodes with the component's nodes (delivery time), using the page's locale and
|
|
132
|
+
* the values stored on the ref. Ids are namespaced with the ref id (a component may appear twice).
|
|
133
|
+
*/
|
|
134
|
+
export declare function expandComponentRefs(nodes: readonly ComponentNode[], locale: string, resolve: (ref: ComponentRefProps) => ComponentDocument | null, depth?: number, seen?: ReadonlySet<string>): ComponentNode[];
|
|
135
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAgE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKtH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,yGAAyG;AACzG,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAGnD,eAAO,MAAM,oBAAoB,YAAI,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAE1H,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;kBASrB,CAAC;AACZ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAKhE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0BlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAYxE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;2BAGlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,C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,176 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ComponentNodeSchema, PAGE_DOCUMENT_SCHEMA_VERSION, walkNodes } from "./page-document.js";
|
|
3
|
+
import { SECTION_REF_TYPE } from "./section.js";
|
|
4
|
+
import { DataInputsSchema, DataPathSchema, REPEAT_TYPE } from "./data.js";
|
|
5
|
+
import { EventNameSchema } from "./events.js";
|
|
6
|
+
/**
|
|
7
|
+
* Composed component (ADR-028): built in the editor from built-in basic/container blocks, stored at
|
|
8
|
+
* Project scope with draft/versions. `props` expose chosen inner fields to whoever places it; text is
|
|
9
|
+
* translated per locale inside the component (structure is shared by all languages).
|
|
10
|
+
*/
|
|
11
|
+
export const COMPONENT_REF_TYPE = "ComponentRef";
|
|
12
|
+
/** Internal wrapper the renderer understands natively: applies a design-system theme to its children. */
|
|
13
|
+
export const THEME_SCOPE_TYPE = "VisualThemeScope";
|
|
14
|
+
const LOCALE = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
15
|
+
export const COMPONENT_PROP_TYPES = ["text", "textarea", "image", "link", "icon", "number", "boolean", "select"];
|
|
16
|
+
export const ComponentPropSchema = z.object({
|
|
17
|
+
name: z.string().regex(/^[a-z][a-zA-Z0-9]{0,39}$/, "prop names are camelCase, e.g. title or ctaLabel"),
|
|
18
|
+
label: z.string().min(1).max(60),
|
|
19
|
+
type: z.enum(COMPONENT_PROP_TYPES),
|
|
20
|
+
/** Inner fields this prop writes to (one prop may drive several fields). */
|
|
21
|
+
binds: z.array(z.object({ nodeId: z.string().min(1), prop: z.string().min(1).max(60) }).strict()).min(1).max(10),
|
|
22
|
+
required: z.boolean().optional(),
|
|
23
|
+
/** select props: the allowed values (from the bound field). */
|
|
24
|
+
options: z.array(z.string()).max(100).optional(),
|
|
25
|
+
}).strict();
|
|
26
|
+
/** `${nodeId}.${prop}` → translated text, per locale. */
|
|
27
|
+
const TranslationsSchema = z.record(LOCALE, z.record(z.string().regex(/^[A-Za-z0-9_]+\.[A-Za-z0-9_]+$/), z.string().max(5000)));
|
|
28
|
+
export const ComponentDocumentSchema = z.object({
|
|
29
|
+
schemaVersion: z.literal(PAGE_DOCUMENT_SCHEMA_VERSION),
|
|
30
|
+
nodes: z.array(ComponentNodeSchema).min(1, "a component needs at least one block"),
|
|
31
|
+
props: z.array(ComponentPropSchema).max(30).default([]),
|
|
32
|
+
defaultLocale: LOCALE,
|
|
33
|
+
translations: TranslationsSchema.default({}),
|
|
34
|
+
/** Design-system theme for this component (e.g. "dark"); omitted → the page's theme. */
|
|
35
|
+
theme: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).optional(),
|
|
36
|
+
/** Data inputs the component reads (ADR-034); inside a page they come from the page's data by name. */
|
|
37
|
+
data: z.lazy(() => DataInputsSchema).optional(),
|
|
38
|
+
/** Languages this component is switched off for (ADR-038): it is not rendered on pages in them. */
|
|
39
|
+
disabledLocales: z.array(LOCALE).max(50).optional(),
|
|
40
|
+
/** The inner slot that receives the blocks placed inside the component on a page (ADR-043). */
|
|
41
|
+
childrenSlot: z.object({ nodeId: z.string().min(1), slot: z.string().min(1).max(60) }).strict().optional(),
|
|
42
|
+
}).strict().superRefine((doc, ctx) => {
|
|
43
|
+
if (doc.disabledLocales?.includes(doc.defaultLocale))
|
|
44
|
+
ctx.addIssue({ code: "custom", path: ["disabledLocales"], message: "the source language cannot be switched off" });
|
|
45
|
+
for (const n of walkNodes(doc.nodes)) {
|
|
46
|
+
// Components may contain other components (ADR-043; cycles are refused when saving), not shared sections.
|
|
47
|
+
if (n.type === SECTION_REF_TYPE)
|
|
48
|
+
ctx.addIssue({ code: "custom", path: ["nodes"], message: "components cannot contain shared sections" });
|
|
49
|
+
}
|
|
50
|
+
if (doc.childrenSlot && ![...walkNodes(doc.nodes)].some((n) => n.id === doc.childrenSlot.nodeId))
|
|
51
|
+
ctx.addIssue({ code: "custom", path: ["childrenSlot"], message: "children slot block not found" });
|
|
52
|
+
const names = new Set();
|
|
53
|
+
for (const p of doc.props) {
|
|
54
|
+
if (names.has(p.name))
|
|
55
|
+
ctx.addIssue({ code: "custom", path: ["props"], message: `duplicate prop "${p.name}"` });
|
|
56
|
+
names.add(p.name);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Per placement (ADR-036): `dataMap` feeds a component data input from a page data path
|
|
61
|
+
* ({ products: "menu.items" }); `eventMap` renames the component's handlers for this placement
|
|
62
|
+
* ({ onBuy: "onBuyHero" }). Without them a component reads page data and fires events by the same name.
|
|
63
|
+
*/
|
|
64
|
+
const PlacementSchema = {
|
|
65
|
+
values: z.record(z.string(), z.unknown()).optional(),
|
|
66
|
+
dataMap: z.record(z.string().regex(/^[a-z][A-Za-z0-9]{0,39}$/), DataPathSchema).optional(),
|
|
67
|
+
eventMap: z.record(EventNameSchema, EventNameSchema).optional(),
|
|
68
|
+
};
|
|
69
|
+
export const ComponentRefPropsSchema = z.discriminatedUnion("mode", [
|
|
70
|
+
z.object({ mode: z.literal("follow"), componentId: z.string().uuid(), ...PlacementSchema }).passthrough(),
|
|
71
|
+
z.object({ mode: z.literal("fixed"), componentId: z.string().uuid(), versionId: z.string().uuid(), ...PlacementSchema }).passthrough(),
|
|
72
|
+
]);
|
|
73
|
+
export function componentRefs(nodes) {
|
|
74
|
+
return [...walkNodes(nodes)].filter((n) => n.type === COMPONENT_REF_TYPE).map((n) => {
|
|
75
|
+
const r = ComponentRefPropsSchema.safeParse(n.props);
|
|
76
|
+
return { nodeId: n.id, props: r.success ? r.data : null };
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The component's nodes for one locale with prop values applied:
|
|
81
|
+
* base content → translations of `locale` → values passed by the page/app (values win).
|
|
82
|
+
* Bindings to nodes that no longer exist are ignored.
|
|
83
|
+
*/
|
|
84
|
+
export function applyComponent(doc, opts = {}) {
|
|
85
|
+
const tr = opts.locale && opts.locale !== doc.defaultLocale ? (doc.translations[opts.locale] ?? doc.translations[opts.locale.split("-")[0]] ?? {}) : {};
|
|
86
|
+
const writes = new Map();
|
|
87
|
+
const put = (nodeId, prop, v) => { (writes.get(nodeId) ?? writes.set(nodeId, {}).get(nodeId))[prop] = v; };
|
|
88
|
+
for (const [key, text] of Object.entries(tr)) {
|
|
89
|
+
const [nodeId, prop] = key.split(".");
|
|
90
|
+
put(nodeId, prop, text);
|
|
91
|
+
}
|
|
92
|
+
for (const p of doc.props) {
|
|
93
|
+
const v = opts.values?.[p.name];
|
|
94
|
+
if (v === undefined || v === null || v === "")
|
|
95
|
+
continue;
|
|
96
|
+
for (const b of p.binds)
|
|
97
|
+
put(b.nodeId, b.prop, v);
|
|
98
|
+
}
|
|
99
|
+
const walk = (list) => list.map((n) => {
|
|
100
|
+
const w = writes.get(n.id);
|
|
101
|
+
const slots = n.slots ? Object.fromEntries(Object.entries(n.slots).map(([k, v]) => [k, walk(v)])) : undefined;
|
|
102
|
+
return { ...n, props: w ? { ...n.props, ...w } : n.props, ...(slots ? { slots } : {}) };
|
|
103
|
+
});
|
|
104
|
+
return walk(doc.nodes);
|
|
105
|
+
}
|
|
106
|
+
/** Wrap nodes in a theme scope when the component pins a theme. */
|
|
107
|
+
export function withTheme(nodes, theme, id) {
|
|
108
|
+
return theme ? [{ id: `${id}_theme`, type: THEME_SCOPE_TYPE, props: { theme }, slots: { children: nodes } }] : nodes;
|
|
109
|
+
}
|
|
110
|
+
/** Is the component switched on for this locale (exact code or its base language)? */
|
|
111
|
+
export function componentEnabledFor(doc, locale) {
|
|
112
|
+
if (!locale || !doc.disabledLocales?.length)
|
|
113
|
+
return true;
|
|
114
|
+
return !doc.disabledLocales.includes(locale) && !doc.disabledLocales.includes(locale.split("-")[0]);
|
|
115
|
+
}
|
|
116
|
+
/** Rewrite a data path whose first segment is a mapped input (products.0.name → menu.items.0.name). */
|
|
117
|
+
function remap(path, dataMap) {
|
|
118
|
+
const [root, ...rest] = path.split(".");
|
|
119
|
+
const to = dataMap[root];
|
|
120
|
+
return to ? [to, ...rest].join(".") : path;
|
|
121
|
+
}
|
|
122
|
+
/** Apply a placement's dataMap/eventMap to a component's nodes (ADR-036). */
|
|
123
|
+
export function applyPlacement(nodes, dataMap, eventMap) {
|
|
124
|
+
if (!dataMap && !eventMap)
|
|
125
|
+
return [...nodes];
|
|
126
|
+
const walk = (n) => {
|
|
127
|
+
const out = { ...n };
|
|
128
|
+
if (dataMap && n.bind)
|
|
129
|
+
out.bind = Object.fromEntries(Object.entries(n.bind).map(([k, b]) => [k, { ...b, path: remap(b.path, dataMap) }]));
|
|
130
|
+
if (dataMap && n.type === REPEAT_TYPE && typeof n.props.source === "string")
|
|
131
|
+
out.props = { ...n.props, source: remap(n.props.source, dataMap) };
|
|
132
|
+
if (eventMap && n.events)
|
|
133
|
+
out.events = Object.fromEntries(Object.entries(n.events).map(([k, v]) => [k, v && eventMap[v] ? eventMap[v] : v]));
|
|
134
|
+
if (n.slots)
|
|
135
|
+
out.slots = Object.fromEntries(Object.entries(n.slots).map(([k, v]) => [k, v.map(walk)]));
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
return nodes.map(walk);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Replace ComponentRef nodes with the component's nodes (delivery time), using the page's locale and
|
|
142
|
+
* the values stored on the ref. Ids are namespaced with the ref id (a component may appear twice).
|
|
143
|
+
*/
|
|
144
|
+
export function expandComponentRefs(nodes, locale, resolve, depth = 0, seen = new Set()) {
|
|
145
|
+
const prefix = (refId, n) => {
|
|
146
|
+
const slots = n.slots ? Object.fromEntries(Object.entries(n.slots).map(([k, v]) => [k, v.map((c) => prefix(refId, c))])) : undefined;
|
|
147
|
+
return { ...n, id: `${refId}_${n.id.replace(/^n_/, "")}`, ...(slots ? { slots } : {}) };
|
|
148
|
+
};
|
|
149
|
+
const walk = (list) => list.flatMap((n) => {
|
|
150
|
+
if (n.type === COMPONENT_REF_TYPE) {
|
|
151
|
+
const r = ComponentRefPropsSchema.safeParse(n.props);
|
|
152
|
+
// Nested components (ADR-043): at most 5 levels, never the same component inside itself.
|
|
153
|
+
if (!r.success || depth >= 5 || seen.has(r.data.componentId))
|
|
154
|
+
return [];
|
|
155
|
+
const doc = resolve(r.data);
|
|
156
|
+
if (!doc)
|
|
157
|
+
return [];
|
|
158
|
+
if (!componentEnabledFor(doc, locale))
|
|
159
|
+
return []; // switched off for this language (ADR-038)
|
|
160
|
+
let inner = applyPlacement(applyComponent(doc, { locale, values: r.data.values }), r.data.dataMap, r.data.eventMap);
|
|
161
|
+
// Children placed inside the component on the page go into its children slot.
|
|
162
|
+
const children = n.slots?.children;
|
|
163
|
+
if (doc.childrenSlot && children?.length) {
|
|
164
|
+
const put = (list2) => list2.map((x) => x.id === doc.childrenSlot.nodeId
|
|
165
|
+
? { ...x, slots: { ...(x.slots ?? {}), [doc.childrenSlot.slot]: [...(x.slots?.[doc.childrenSlot.slot] ?? []), ...walk(children)] } }
|
|
166
|
+
: x.slots ? { ...x, slots: Object.fromEntries(Object.entries(x.slots).map(([k, v]) => [k, put(v)])) } : x);
|
|
167
|
+
inner = put(inner);
|
|
168
|
+
}
|
|
169
|
+
inner = expandComponentRefs(inner, locale, resolve, depth + 1, new Set([...seen, r.data.componentId]));
|
|
170
|
+
return withTheme(inner.map((c) => prefix(n.id, c)), doc.theme, n.id);
|
|
171
|
+
}
|
|
172
|
+
return n.slots ? [{ ...n, slots: Object.fromEntries(Object.entries(n.slots).map(([k, v]) => [k, walk(v)])) }] : [n];
|
|
173
|
+
});
|
|
174
|
+
return walk(nodes);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,SAAS,EAAsB,MAAM,oBAAoB,CAAC;AACtH,OAAO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M,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/data.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ComponentNode } from "./page-document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data binding (ADR-034). A block prop is either its static value (props) or bound to a field of a
|
|
5
|
+
* data input: node.bind = { title: { path: "item.name" } }. The static value stays as the fallback.
|
|
6
|
+
* Phase A source: "app" — the customer app passes the data when rendering.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REPEAT_TYPE = "Repeat";
|
|
9
|
+
/** "app": passed by the customer app; "table": a project data table query (ADR-041). */
|
|
10
|
+
export declare const DATA_SOURCES: readonly ["app", "table"];
|
|
11
|
+
export declare const DATA_FIELD_TYPES: readonly ["text", "number", "boolean", "image", "link", "date", "list", "object"];
|
|
12
|
+
export type DataFieldType = (typeof DATA_FIELD_TYPES)[number];
|
|
13
|
+
export declare const BIND_FORMATS: readonly ["number", "currency", "date", "datetime", "upper", "lower"];
|
|
14
|
+
export type BindFormat = (typeof BIND_FORMATS)[number];
|
|
15
|
+
/** products · products.0.name · item.price · item.variants — dotted names/indexes only, no expressions. */
|
|
16
|
+
export declare const DataPathSchema: z.ZodString;
|
|
17
|
+
export type DataField = {
|
|
18
|
+
name: string;
|
|
19
|
+
type: DataFieldType;
|
|
20
|
+
label?: string | undefined;
|
|
21
|
+
fields?: DataField[] | undefined;
|
|
22
|
+
localized?: boolean | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare const DataFieldSchema: z.ZodType<DataField>;
|
|
25
|
+
export declare const DataInputSchema: z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
label: z.ZodOptional<z.ZodString>;
|
|
28
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
29
|
+
app: "app";
|
|
30
|
+
table: "table";
|
|
31
|
+
}>>;
|
|
32
|
+
shape: z.ZodEnum<{
|
|
33
|
+
list: "list";
|
|
34
|
+
object: "object";
|
|
35
|
+
}>;
|
|
36
|
+
fields: z.ZodArray<z.ZodType<DataField, unknown, z.core.$ZodTypeInternals<DataField, unknown>>>;
|
|
37
|
+
sample: z.ZodOptional<z.ZodUnknown>;
|
|
38
|
+
query: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
39
|
+
table: z.ZodString;
|
|
40
|
+
where: z.ZodOptional<z.ZodType<import("./tables.js").Filter, unknown, z.core.$ZodTypeInternals<import("./tables.js").Filter, unknown>>>;
|
|
41
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
42
|
+
field: z.ZodString;
|
|
43
|
+
dir: z.ZodDefault<z.ZodEnum<{
|
|
44
|
+
asc: "asc";
|
|
45
|
+
desc: "desc";
|
|
46
|
+
}>>;
|
|
47
|
+
}, z.core.$strict>>>;
|
|
48
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
49
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
50
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
51
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strict>>>;
|
|
53
|
+
single: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
export type DataInput = z.infer<typeof DataInputSchema>;
|
|
56
|
+
export declare const DataInputsSchema: z.ZodArray<z.ZodObject<{
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
label: z.ZodOptional<z.ZodString>;
|
|
59
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
60
|
+
app: "app";
|
|
61
|
+
table: "table";
|
|
62
|
+
}>>;
|
|
63
|
+
shape: z.ZodEnum<{
|
|
64
|
+
list: "list";
|
|
65
|
+
object: "object";
|
|
66
|
+
}>;
|
|
67
|
+
fields: z.ZodArray<z.ZodType<DataField, unknown, z.core.$ZodTypeInternals<DataField, unknown>>>;
|
|
68
|
+
sample: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
query: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
70
|
+
table: z.ZodString;
|
|
71
|
+
where: z.ZodOptional<z.ZodType<import("./tables.js").Filter, unknown, z.core.$ZodTypeInternals<import("./tables.js").Filter, unknown>>>;
|
|
72
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
73
|
+
field: z.ZodString;
|
|
74
|
+
dir: z.ZodDefault<z.ZodEnum<{
|
|
75
|
+
asc: "asc";
|
|
76
|
+
desc: "desc";
|
|
77
|
+
}>>;
|
|
78
|
+
}, z.core.$strict>>>;
|
|
79
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
80
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
81
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, z.core.$strict>>>;
|
|
84
|
+
single: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
}, z.core.$strict>>;
|
|
86
|
+
export declare const BindingSchema: z.ZodObject<{
|
|
87
|
+
path: z.ZodString;
|
|
88
|
+
format: z.ZodOptional<z.ZodEnum<{
|
|
89
|
+
currency: "currency";
|
|
90
|
+
date: "date";
|
|
91
|
+
datetime: "datetime";
|
|
92
|
+
lower: "lower";
|
|
93
|
+
number: "number";
|
|
94
|
+
upper: "upper";
|
|
95
|
+
}>>;
|
|
96
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
97
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
98
|
+
suffix: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$strict>;
|
|
100
|
+
export type Binding = z.infer<typeof BindingSchema>;
|
|
101
|
+
export declare const NodeBindingsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
102
|
+
path: z.ZodString;
|
|
103
|
+
format: z.ZodOptional<z.ZodEnum<{
|
|
104
|
+
currency: "currency";
|
|
105
|
+
date: "date";
|
|
106
|
+
datetime: "datetime";
|
|
107
|
+
lower: "lower";
|
|
108
|
+
number: "number";
|
|
109
|
+
upper: "upper";
|
|
110
|
+
}>>;
|
|
111
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
112
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
113
|
+
suffix: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.core.$strict>>;
|
|
115
|
+
export type NodeBindings = z.infer<typeof NodeBindingsSchema>;
|
|
116
|
+
/** Field types a definition field can receive from data. */
|
|
117
|
+
export declare const BINDABLE_FIELD_TYPES: readonly ["text", "textarea", "number", "boolean", "select", "image", "link"];
|
|
118
|
+
/** { vi: "…", en: "…" } — every key a language code, every value a string. */
|
|
119
|
+
export declare const isLocalizedValue: (v: unknown) => v is Record<string, string>;
|
|
120
|
+
/** Fields of an object (merging keys of several samples, e.g. all items of a list). */
|
|
121
|
+
export declare function inferFields(samples: unknown[], depth?: number): DataField[];
|
|
122
|
+
/** A data input from a pasted sample: a list (array) or an object. */
|
|
123
|
+
export declare function inferDataInput(name: string, sample: unknown): DataInput;
|
|
124
|
+
/** Read a dotted path from a scope ({ products, item, index }). Unknown segments → undefined. */
|
|
125
|
+
export declare function readPath(scope: Record<string, unknown>, path: string, locale?: string): unknown;
|
|
126
|
+
/**
|
|
127
|
+
* Convert a data value to what a definition field expects. Returns undefined when it does not fit
|
|
128
|
+
* (the static value is then kept).
|
|
129
|
+
*/
|
|
130
|
+
export declare function coerceBound(v: unknown, fieldType: string, b: Binding, opts?: {
|
|
131
|
+
locale?: string | undefined;
|
|
132
|
+
options?: readonly string[] | undefined;
|
|
133
|
+
}): unknown;
|
|
134
|
+
/** The list a Repeat iterates (props.source path); non-arrays → []. Honors props.limit. */
|
|
135
|
+
export declare function repeatItems(node: ComponentNode, scope: Record<string, unknown>): unknown[];
|
|
136
|
+
/** Names of data inputs a set of nodes reads (first path segment, excluding item/index). */
|
|
137
|
+
export declare function usedDataInputs(nodes: readonly ComponentNode[]): string[];
|
|
138
|
+
/** Paths a picker can offer for a scope: inputs (and item fields inside a Repeat). */
|
|
139
|
+
export type DataPathOption = {
|
|
140
|
+
path: string;
|
|
141
|
+
type: DataFieldType;
|
|
142
|
+
list: boolean;
|
|
143
|
+
localized?: boolean;
|
|
144
|
+
};
|
|
145
|
+
export declare function dataPaths(inputs: readonly DataInput[], itemFields?: readonly DataField[]): DataPathOption[];
|
|
146
|
+
/** Item fields of a list path (to type `item.*` inside a Repeat over it). */
|
|
147
|
+
export declare function listItemFields(inputs: readonly DataInput[], path: string, outerItem?: readonly DataField[]): DataField[] | undefined;
|
|
148
|
+
/** Can a data field of this type feed a definition field of that type? (pickers) */
|
|
149
|
+
export declare function bindingFits(fieldType: string, data: DataFieldType): boolean;
|
|
150
|
+
/** Example data for a set of fields (editor preview when the user defines fields by hand). */
|
|
151
|
+
export declare function sampleFromFields(fields: readonly DataField[], locales?: readonly string[], depth?: number): Record<string, unknown>;
|
|
152
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnE;;;;GAIG;AACH,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,wFAAwF;AACxF,eAAO,MAAM,YAAY,YAAI,KAAK,EAAE,OAAO,CAAU,CAAC;AACtD,eAAO,MAAM,gBAAgB,YAAI,M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