@rippling/pebble-sdui-mobile 0.16.0 → 0.18.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.
Files changed (35) hide show
  1. package/dist/catalogs/custom-apps/action-params.d.ts +6 -0
  2. package/dist/catalogs/custom-apps/actions.d.ts +3 -1
  3. package/dist/catalogs/custom-apps/catalog.d.ts +3 -1
  4. package/dist/catalogs/custom-apps/component-events.d.ts +1 -0
  5. package/dist/catalogs/custom-apps/component-props.d.ts +66 -7
  6. package/dist/catalogs/custom-apps/components.d.ts +17 -16
  7. package/dist/catalogs/custom-apps/function-params.d.ts +4 -0
  8. package/dist/catalogs/custom-apps/functions.d.ts +9 -1
  9. package/dist/catalogs/custom-apps/index.cjs +5 -5
  10. package/dist/catalogs/custom-apps/index.cjs.map +1 -1
  11. package/dist/catalogs/custom-apps/index.d.ts +8 -8
  12. package/dist/catalogs/custom-apps/index.js +1450 -1141
  13. package/dist/catalogs/custom-apps/index.js.map +1 -1
  14. package/dist/core/component-markdown.cjs +19 -0
  15. package/dist/core/component-markdown.cjs.map +1 -0
  16. package/dist/core/component-markdown.d.ts +8 -0
  17. package/dist/core/component-markdown.js +58 -0
  18. package/dist/core/component-markdown.js.map +1 -0
  19. package/dist/core/component-utils.cjs +1 -1
  20. package/dist/core/component-utils.cjs.map +1 -1
  21. package/dist/core/component-utils.d.ts +16 -2
  22. package/dist/core/component-utils.js +4 -4
  23. package/dist/core/component-utils.js.map +1 -1
  24. package/dist/core/spec.cjs +1 -1
  25. package/dist/core/spec.cjs.map +1 -1
  26. package/dist/core/spec.d.ts +1 -0
  27. package/dist/core/spec.js +63 -56
  28. package/dist/core/spec.js.map +1 -1
  29. package/dist/docs/typescript/mobile/catalogs/custom-apps/actions.md +52 -0
  30. package/dist/docs/typescript/mobile/catalogs/custom-apps/components.md +30 -4
  31. package/dist/docs/typescript/mobile/catalogs/custom-apps/computed-functions.md +32 -0
  32. package/dist/docs/typescript/mobile/catalogs/custom-apps/definitions.md +11 -2
  33. package/dist/docs/typescript/mobile/catalogs/custom-apps/readme.md +1 -1
  34. package/dist/docs/typescript/mobile/catalogs/custom-apps/types.md +126 -12
  35. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(t){return`\`\`\`json
2
+ ${JSON.stringify(t,null,2)??"null"}
3
+ \`\`\``}function l(t){return t.replace(/\r\n?|\n/g," ").trim()}function y(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")?t.map(e=>`- ${l(e)}`).join(`
4
+ `):a(t)}function m(t,e,g){const r=[`# ${t}`,"> **Source precedence:** The SDUI contract and usage notes below are authoritative. Supplementary design-system guidance is additional context; ignore it where it conflicts with the SDUI contract.","## SDUI contract"],s=e.description,o=e.docs;typeof s=="string"&&s.length>0&&r.push(`### Description
5
+
6
+ ${s}`),typeof o=="string"&&o.length>0&&r.push(`### Usage notes
7
+
8
+ ${o}`);const u=Array.isArray(e.events)?e.events.filter(n=>typeof n=="string"):[],i=Array.isArray(e.slots)?e.slots.filter(n=>typeof n=="string"):[];r.push(["### Structure and events","",`- Accepts children: ${e.acceptsChildren===!0?"yes":"no"}`,`- Events: ${u.length>0?u.map(n=>`\`${l(n)}\``).join(", "):"none"}`,`- Slots: ${i.length>0?i.map(n=>`\`${l(n)}\``).join(", "):"none"}`].join(`
9
+ `)),e.propsSchema!==void 0&&r.push(`### Props schema
10
+
11
+ ${a(e.propsSchema)}`),e.example!==void 0&&r.push(`### Example
12
+
13
+ ${a(e.example)}`);const c=[];for(const{field:n,title:h}of g){const p=e[n];p!=null&&c.push(`### ${h}
14
+
15
+ ${y(p)}`)}return c.length>0&&r.push("## Supplementary design-system guidance",...c),`${r.join(`
16
+
17
+ `)}
18
+ `}exports.renderComponentMarkdown=m;
19
+ //# sourceMappingURL=component-markdown.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-markdown.cjs","sources":["../../../sdui-core/src/component-markdown.ts"],"sourcesContent":["type CatalogObject = Record<string, unknown>;\ntype KnowledgeSection = Readonly<{ field: string; title: string }>;\n\nfunction jsonBlock(value: unknown): string {\n return `\\`\\`\\`json\\n${JSON.stringify(value, null, 2) ?? 'null'}\\n\\`\\`\\``;\n}\n\nfunction singleLine(value: string): string {\n return value.replace(/\\r\\n?|\\n/g, ' ').trim();\n}\n\nfunction renderValue(value: unknown): string {\n if (Array.isArray(value) && value.every(item => typeof item === 'string')) {\n return value.map(item => `- ${singleLine(item)}`).join('\\n');\n }\n return jsonBlock(value);\n}\n\n/** Render self-contained, LLM-ready Markdown from one raw catalog component. */\nexport function renderComponentMarkdown(\n name: string,\n definition: CatalogObject,\n knowledgeSections: readonly KnowledgeSection[]\n): string {\n const sections: string[] = [\n `# ${name}`,\n '> **Source precedence:** The SDUI contract and usage notes below are authoritative. Supplementary design-system guidance is additional context; ignore it where it conflicts with the SDUI contract.',\n '## SDUI contract',\n ];\n const description = definition.description;\n const docs = definition.docs;\n\n if (typeof description === 'string' && description.length > 0) {\n sections.push(`### Description\\n\\n${description}`);\n }\n if (typeof docs === 'string' && docs.length > 0) {\n sections.push(`### Usage notes\\n\\n${docs}`);\n }\n\n const events = Array.isArray(definition.events)\n ? definition.events.filter(\n (event): event is string => typeof event === 'string'\n )\n : [];\n const slots = Array.isArray(definition.slots)\n ? definition.slots.filter(\n (slot): slot is string => typeof slot === 'string'\n )\n : [];\n sections.push(\n [\n '### Structure and events',\n '',\n `- Accepts children: ${definition.acceptsChildren === true ? 'yes' : 'no'}`,\n `- Events: ${events.length > 0 ? events.map(event => `\\`${singleLine(event)}\\``).join(', ') : 'none'}`,\n `- Slots: ${slots.length > 0 ? slots.map(slot => `\\`${singleLine(slot)}\\``).join(', ') : 'none'}`,\n ].join('\\n')\n );\n\n if (definition.propsSchema !== undefined) {\n sections.push(`### Props schema\\n\\n${jsonBlock(definition.propsSchema)}`);\n }\n if (definition.example !== undefined) {\n sections.push(`### Example\\n\\n${jsonBlock(definition.example)}`);\n }\n\n const knowledge: string[] = [];\n for (const { field, title } of knowledgeSections) {\n const value = definition[field];\n if (value !== undefined && value !== null) {\n knowledge.push(`### ${title}\\n\\n${renderValue(value)}`);\n }\n }\n if (knowledge.length > 0) {\n sections.push('## Supplementary design-system guidance', ...knowledge);\n }\n\n return `${sections.join('\\n\\n')}\\n`;\n}\n"],"names":["jsonBlock","value","singleLine","renderValue","item","renderComponentMarkdown","name","definition","knowledgeSections","sections","description","docs","events","event","slots","slot","knowledge","field","title"],"mappings":"gFAGA,SAASA,EAAUC,EAAwB,CACzC,MAAO;AAAA,EAAe,KAAK,UAAUA,EAAO,KAAM,CAAC,GAAK,MAAM;AAAA,OAChE,CAEA,SAASC,EAAWD,EAAuB,CACzC,OAAOA,EAAM,QAAQ,YAAa,GAAG,EAAE,KAAA,CACzC,CAEA,SAASE,EAAYF,EAAwB,CAC3C,OAAI,MAAM,QAAQA,CAAK,GAAKA,EAAM,MAAMG,GAAQ,OAAOA,GAAS,QAAQ,EAC/DH,EAAM,IAAIG,GAAQ,KAAKF,EAAWE,CAAI,CAAC,EAAE,EAAE,KAAK;AAAA,CAAI,EAEtDJ,EAAUC,CAAK,CACxB,CAGO,SAASI,EACdC,EACAC,EACAC,EACQ,CACR,MAAMC,EAAqB,CACzB,KAAKH,CAAI,GACT,uMACA,kBAAA,EAEII,EAAcH,EAAW,YACzBI,EAAOJ,EAAW,KAEpB,OAAOG,GAAgB,UAAYA,EAAY,OAAS,GAC1DD,EAAS,KAAK;AAAA;AAAA,EAAsBC,CAAW,EAAE,EAE/C,OAAOC,GAAS,UAAYA,EAAK,OAAS,GAC5CF,EAAS,KAAK;AAAA;AAAA,EAAsBE,CAAI,EAAE,EAG5C,MAAMC,EAAS,MAAM,QAAQL,EAAW,MAAM,EAC1CA,EAAW,OAAO,OACfM,GAA2B,OAAOA,GAAU,QAAA,EAE/C,CAAA,EACEC,EAAQ,MAAM,QAAQP,EAAW,KAAK,EACxCA,EAAW,MAAM,OACdQ,GAAyB,OAAOA,GAAS,QAAA,EAE5C,CAAA,EACJN,EAAS,KACP,CACE,2BACA,GACA,uBAAuBF,EAAW,kBAAoB,GAAO,MAAQ,IAAI,GACzE,aAAaK,EAAO,OAAS,EAAIA,EAAO,IAAIC,GAAS,KAAKX,EAAWW,CAAK,CAAC,IAAI,EAAE,KAAK,IAAI,EAAI,MAAM,GACpG,YAAYC,EAAM,OAAS,EAAIA,EAAM,IAAIC,GAAQ,KAAKb,EAAWa,CAAI,CAAC,IAAI,EAAE,KAAK,IAAI,EAAI,MAAM,EAAA,EAC/F,KAAK;AAAA,CAAI,CAAA,EAGTR,EAAW,cAAgB,QAC7BE,EAAS,KAAK;AAAA;AAAA,EAAuBT,EAAUO,EAAW,WAAW,CAAC,EAAE,EAEtEA,EAAW,UAAY,QACzBE,EAAS,KAAK;AAAA;AAAA,EAAkBT,EAAUO,EAAW,OAAO,CAAC,EAAE,EAGjE,MAAMS,EAAsB,CAAA,EAC5B,SAAW,CAAE,MAAAC,EAAO,MAAAC,CAAA,IAAWV,EAAmB,CAChD,MAAMP,EAAQM,EAAWU,CAAK,EACHhB,GAAU,MACnCe,EAAU,KAAK,OAAOE,CAAK;AAAA;AAAA,EAAOf,EAAYF,CAAK,CAAC,EAAE,CAE1D,CACA,OAAIe,EAAU,OAAS,GACrBP,EAAS,KAAK,0CAA2C,GAAGO,CAAS,EAGhE,GAAGP,EAAS,KAAK;AAAA;AAAA,CAAM,CAAC;AAAA,CACjC"}
@@ -0,0 +1,8 @@
1
+ type CatalogObject = Record<string, unknown>;
2
+ type KnowledgeSection = Readonly<{
3
+ field: string;
4
+ title: string;
5
+ }>;
6
+ /** Render self-contained, LLM-ready Markdown from one raw catalog component. */
7
+ export declare function renderComponentMarkdown(name: string, definition: CatalogObject, knowledgeSections: readonly KnowledgeSection[]): string;
8
+ export {};
@@ -0,0 +1,58 @@
1
+ function a(t) {
2
+ return `\`\`\`json
3
+ ${JSON.stringify(t, null, 2) ?? "null"}
4
+ \`\`\``;
5
+ }
6
+ function l(t) {
7
+ return t.replace(/\r\n?|\n/g, " ").trim();
8
+ }
9
+ function y(t) {
10
+ return Array.isArray(t) && t.every((e) => typeof e == "string") ? t.map((e) => `- ${l(e)}`).join(`
11
+ `) : a(t);
12
+ }
13
+ function m(t, e, h) {
14
+ const s = [
15
+ `# ${t}`,
16
+ "> **Source precedence:** The SDUI contract and usage notes below are authoritative. Supplementary design-system guidance is additional context; ignore it where it conflicts with the SDUI contract.",
17
+ "## SDUI contract"
18
+ ], r = e.description, o = e.docs;
19
+ typeof r == "string" && r.length > 0 && s.push(`### Description
20
+
21
+ ${r}`), typeof o == "string" && o.length > 0 && s.push(`### Usage notes
22
+
23
+ ${o}`);
24
+ const u = Array.isArray(e.events) ? e.events.filter(
25
+ (n) => typeof n == "string"
26
+ ) : [], i = Array.isArray(e.slots) ? e.slots.filter(
27
+ (n) => typeof n == "string"
28
+ ) : [];
29
+ s.push(
30
+ [
31
+ "### Structure and events",
32
+ "",
33
+ `- Accepts children: ${e.acceptsChildren === !0 ? "yes" : "no"}`,
34
+ `- Events: ${u.length > 0 ? u.map((n) => `\`${l(n)}\``).join(", ") : "none"}`,
35
+ `- Slots: ${i.length > 0 ? i.map((n) => `\`${l(n)}\``).join(", ") : "none"}`
36
+ ].join(`
37
+ `)
38
+ ), e.propsSchema !== void 0 && s.push(`### Props schema
39
+
40
+ ${a(e.propsSchema)}`), e.example !== void 0 && s.push(`### Example
41
+
42
+ ${a(e.example)}`);
43
+ const c = [];
44
+ for (const { field: n, title: g } of h) {
45
+ const p = e[n];
46
+ p != null && c.push(`### ${g}
47
+
48
+ ${y(p)}`);
49
+ }
50
+ return c.length > 0 && s.push("## Supplementary design-system guidance", ...c), `${s.join(`
51
+
52
+ `)}
53
+ `;
54
+ }
55
+ export {
56
+ m as renderComponentMarkdown
57
+ };
58
+ //# sourceMappingURL=component-markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-markdown.js","sources":["../../../sdui-core/src/component-markdown.ts"],"sourcesContent":["type CatalogObject = Record<string, unknown>;\ntype KnowledgeSection = Readonly<{ field: string; title: string }>;\n\nfunction jsonBlock(value: unknown): string {\n return `\\`\\`\\`json\\n${JSON.stringify(value, null, 2) ?? 'null'}\\n\\`\\`\\``;\n}\n\nfunction singleLine(value: string): string {\n return value.replace(/\\r\\n?|\\n/g, ' ').trim();\n}\n\nfunction renderValue(value: unknown): string {\n if (Array.isArray(value) && value.every(item => typeof item === 'string')) {\n return value.map(item => `- ${singleLine(item)}`).join('\\n');\n }\n return jsonBlock(value);\n}\n\n/** Render self-contained, LLM-ready Markdown from one raw catalog component. */\nexport function renderComponentMarkdown(\n name: string,\n definition: CatalogObject,\n knowledgeSections: readonly KnowledgeSection[]\n): string {\n const sections: string[] = [\n `# ${name}`,\n '> **Source precedence:** The SDUI contract and usage notes below are authoritative. Supplementary design-system guidance is additional context; ignore it where it conflicts with the SDUI contract.',\n '## SDUI contract',\n ];\n const description = definition.description;\n const docs = definition.docs;\n\n if (typeof description === 'string' && description.length > 0) {\n sections.push(`### Description\\n\\n${description}`);\n }\n if (typeof docs === 'string' && docs.length > 0) {\n sections.push(`### Usage notes\\n\\n${docs}`);\n }\n\n const events = Array.isArray(definition.events)\n ? definition.events.filter(\n (event): event is string => typeof event === 'string'\n )\n : [];\n const slots = Array.isArray(definition.slots)\n ? definition.slots.filter(\n (slot): slot is string => typeof slot === 'string'\n )\n : [];\n sections.push(\n [\n '### Structure and events',\n '',\n `- Accepts children: ${definition.acceptsChildren === true ? 'yes' : 'no'}`,\n `- Events: ${events.length > 0 ? events.map(event => `\\`${singleLine(event)}\\``).join(', ') : 'none'}`,\n `- Slots: ${slots.length > 0 ? slots.map(slot => `\\`${singleLine(slot)}\\``).join(', ') : 'none'}`,\n ].join('\\n')\n );\n\n if (definition.propsSchema !== undefined) {\n sections.push(`### Props schema\\n\\n${jsonBlock(definition.propsSchema)}`);\n }\n if (definition.example !== undefined) {\n sections.push(`### Example\\n\\n${jsonBlock(definition.example)}`);\n }\n\n const knowledge: string[] = [];\n for (const { field, title } of knowledgeSections) {\n const value = definition[field];\n if (value !== undefined && value !== null) {\n knowledge.push(`### ${title}\\n\\n${renderValue(value)}`);\n }\n }\n if (knowledge.length > 0) {\n sections.push('## Supplementary design-system guidance', ...knowledge);\n }\n\n return `${sections.join('\\n\\n')}\\n`;\n}\n"],"names":["jsonBlock","value","singleLine","renderValue","item","renderComponentMarkdown","name","definition","knowledgeSections","sections","description","docs","events","event","slots","slot","knowledge","field","title"],"mappings":"AAGA,SAASA,EAAUC,GAAwB;AACzC,SAAO;AAAA,EAAe,KAAK,UAAUA,GAAO,MAAM,CAAC,KAAK,MAAM;AAAA;AAChE;AAEA,SAASC,EAAWD,GAAuB;AACzC,SAAOA,EAAM,QAAQ,aAAa,GAAG,EAAE,KAAA;AACzC;AAEA,SAASE,EAAYF,GAAwB;AAC3C,SAAI,MAAM,QAAQA,CAAK,KAAKA,EAAM,MAAM,CAAAG,MAAQ,OAAOA,KAAS,QAAQ,IAC/DH,EAAM,IAAI,CAAAG,MAAQ,KAAKF,EAAWE,CAAI,CAAC,EAAE,EAAE,KAAK;AAAA,CAAI,IAEtDJ,EAAUC,CAAK;AACxB;AAGO,SAASI,EACdC,GACAC,GACAC,GACQ;AACR,QAAMC,IAAqB;AAAA,IACzB,KAAKH,CAAI;AAAA,IACT;AAAA,IACA;AAAA,EAAA,GAEII,IAAcH,EAAW,aACzBI,IAAOJ,EAAW;AAExB,EAAI,OAAOG,KAAgB,YAAYA,EAAY,SAAS,KAC1DD,EAAS,KAAK;AAAA;AAAA,EAAsBC,CAAW,EAAE,GAE/C,OAAOC,KAAS,YAAYA,EAAK,SAAS,KAC5CF,EAAS,KAAK;AAAA;AAAA,EAAsBE,CAAI,EAAE;AAG5C,QAAMC,IAAS,MAAM,QAAQL,EAAW,MAAM,IAC1CA,EAAW,OAAO;AAAA,IAChB,CAACM,MAA2B,OAAOA,KAAU;AAAA,EAAA,IAE/C,CAAA,GACEC,IAAQ,MAAM,QAAQP,EAAW,KAAK,IACxCA,EAAW,MAAM;AAAA,IACf,CAACQ,MAAyB,OAAOA,KAAS;AAAA,EAAA,IAE5C,CAAA;AACJ,EAAAN,EAAS;AAAA,IACP;AAAA,MACE;AAAA,MACA;AAAA,MACA,uBAAuBF,EAAW,oBAAoB,KAAO,QAAQ,IAAI;AAAA,MACzE,aAAaK,EAAO,SAAS,IAAIA,EAAO,IAAI,CAAAC,MAAS,KAAKX,EAAWW,CAAK,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,MAAM;AAAA,MACpG,YAAYC,EAAM,SAAS,IAAIA,EAAM,IAAI,CAAAC,MAAQ,KAAKb,EAAWa,CAAI,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,MAAM;AAAA,IAAA,EAC/F,KAAK;AAAA,CAAI;AAAA,EAAA,GAGTR,EAAW,gBAAgB,UAC7BE,EAAS,KAAK;AAAA;AAAA,EAAuBT,EAAUO,EAAW,WAAW,CAAC,EAAE,GAEtEA,EAAW,YAAY,UACzBE,EAAS,KAAK;AAAA;AAAA,EAAkBT,EAAUO,EAAW,OAAO,CAAC,EAAE;AAGjE,QAAMS,IAAsB,CAAA;AAC5B,aAAW,EAAE,OAAAC,GAAO,OAAAC,EAAA,KAAWV,GAAmB;AAChD,UAAMP,IAAQM,EAAWU,CAAK;AAC9B,IAA2BhB,KAAU,QACnCe,EAAU,KAAK,OAAOE,CAAK;AAAA;AAAA,EAAOf,EAAYF,CAAK,CAAC,EAAE;AAAA,EAE1D;AACA,SAAIe,EAAU,SAAS,KACrBP,EAAS,KAAK,2CAA2C,GAAGO,CAAS,GAGhE,GAAGP,EAAS,KAAK;AAAA;AAAA,CAAM,CAAC;AAAA;AACjC;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(d,e){const o={type:d,props:e.props??{}};return e.id!==void 0&&(o.id=e.id),e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.children&&(o.children=e.children),e.repeat&&(o.repeat=e.repeat),o}exports.buildNode=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(d,e){const o={type:d,props:e.props??{}};return e.id!==void 0&&(o.id=e.id),e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.children&&(o.children=e.children),e.slots&&(o.slots=e.slots),e.repeat&&(o.repeat=e.repeat),o}exports.buildNode=i;
2
2
  //# sourceMappingURL=component-utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"component-utils.cjs","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"gFA6EO,SAASA,EAIdC,EACAC,EAQkC,CAClC,MAAMC,EAA4B,CAChC,KAAAF,EACA,MAAQC,EAAM,OAAS,CAAA,CAAC,EAE1B,OAAIA,EAAM,KAAO,SAAWC,EAAK,GAAKD,EAAM,IACxCA,EAAM,UAAY,SAAWC,EAAK,QAAUD,EAAM,SAClDA,EAAM,KAAIC,EAAK,GAAKD,EAAM,IAC1BA,EAAM,WAAUC,EAAK,SAAWD,EAAM,UACtCA,EAAM,SACRC,EAAK,OAASD,EAAM,QAIfC,CACT"}
1
+ {"version":3,"file":"component-utils.cjs","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n slots?: Record<string, ElementNode[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n slots?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.slots) node.slots = input.slots as Record<string, ElementNode[]>;\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"gFAsFO,SAASA,EAIdC,EACAC,EASkC,CAClC,MAAMC,EAA4B,CAChC,KAAAF,EACA,MAAQC,EAAM,OAAS,CAAA,CAAC,EAE1B,OAAIA,EAAM,KAAO,SAAWC,EAAK,GAAKD,EAAM,IACxCA,EAAM,UAAY,SAAWC,EAAK,QAAUD,EAAM,SAClDA,EAAM,KAAIC,EAAK,GAAKD,EAAM,IAC1BA,EAAM,WAAUC,EAAK,SAAWD,EAAM,UACtCA,EAAM,QAAOC,EAAK,MAAQD,EAAM,OAChCA,EAAM,SACRC,EAAK,OAASD,EAAM,QAIfC,CACT"}
@@ -12,6 +12,7 @@ export interface InternalElementNode {
12
12
  type: string;
13
13
  props: Record<string, unknown>;
14
14
  children?: ElementNode[];
15
+ slots?: Record<string, ElementNode[]>;
15
16
  visible?: unknown;
16
17
  on?: Record<string, unknown>;
17
18
  watch?: Record<string, unknown>;
@@ -30,7 +31,7 @@ export interface InternalElementNode {
30
31
  * The conditional types ensure `on` is only available when events exist,
31
32
  * and `children` is only available when HasChildren is true.
32
33
  */
33
- export type ComponentInputs<Props, Events extends string = never, HasChildren extends boolean = false> = {
34
+ export type ComponentInputs<Props, Events extends string = never, HasChildren extends boolean = false, Slots extends string = never> = {
34
35
  id?: string;
35
36
  props: WrapWithPropValue<Props>;
36
37
  visible?: VisibilityBinding | boolean;
@@ -45,11 +46,17 @@ export type ComponentInputs<Props, Events extends string = never, HasChildren ex
45
46
  children?: ElementNode[];
46
47
  } : {
47
48
  children?: never;
49
+ }) & ([Slots] extends [never] ? {
50
+ slots?: never;
51
+ } : {
52
+ slots?: {
53
+ [K in Slots]?: ElementNode[];
54
+ };
48
55
  });
49
56
  /**
50
57
  * Variant where props is optional (for components with all-optional props).
51
58
  */
52
- export type ComponentInputsOptionalProps<Props, Events extends string = never, HasChildren extends boolean = false> = {
59
+ export type ComponentInputsOptionalProps<Props, Events extends string = never, HasChildren extends boolean = false, Slots extends string = never> = {
53
60
  id?: string;
54
61
  props?: WrapWithPropValue<Props>;
55
62
  visible?: VisibilityBinding | boolean;
@@ -64,6 +71,12 @@ export type ComponentInputsOptionalProps<Props, Events extends string = never, H
64
71
  children?: ElementNode[];
65
72
  } : {
66
73
  children?: never;
74
+ }) & ([Slots] extends [never] ? {
75
+ slots?: never;
76
+ } : {
77
+ slots?: {
78
+ [K in Slots]?: ElementNode[];
79
+ };
67
80
  });
68
81
  /**
69
82
  * Creates an ElementNode from builder input. Used by generated component builders.
@@ -74,5 +87,6 @@ export declare function buildNode<TPlatform extends string = string, TCatalog ex
74
87
  visible?: unknown;
75
88
  on?: unknown;
76
89
  children?: unknown;
90
+ slots?: unknown;
77
91
  repeat?: unknown;
78
92
  }): ElementNode<TPlatform, TCatalog>;
@@ -1,11 +1,11 @@
1
- function i(d, e) {
1
+ function d(s, e) {
2
2
  const o = {
3
- type: d,
3
+ type: s,
4
4
  props: e.props ?? {}
5
5
  };
6
- return e.id !== void 0 && (o.id = e.id), e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.children && (o.children = e.children), e.repeat && (o.repeat = e.repeat), o;
6
+ return e.id !== void 0 && (o.id = e.id), e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.children && (o.children = e.children), e.slots && (o.slots = e.slots), e.repeat && (o.repeat = e.repeat), o;
7
7
  }
8
8
  export {
9
- i as buildNode
9
+ d as buildNode
10
10
  };
11
11
  //# sourceMappingURL=component-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component-utils.js","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"AA6EO,SAASA,EAIdC,GACAC,GAQkC;AAClC,QAAMC,IAA4B;AAAA,IAChC,MAAAF;AAAA,IACA,OAAQC,EAAM,SAAS,CAAA;AAAA,EAAC;AAE1B,SAAIA,EAAM,OAAO,WAAWC,EAAK,KAAKD,EAAM,KACxCA,EAAM,YAAY,WAAWC,EAAK,UAAUD,EAAM,UAClDA,EAAM,OAAIC,EAAK,KAAKD,EAAM,KAC1BA,EAAM,aAAUC,EAAK,WAAWD,EAAM,WACtCA,EAAM,WACRC,EAAK,SAASD,EAAM,SAIfC;AACT;"}
1
+ {"version":3,"file":"component-utils.js","sources":["../../../sdui-core/src/component-utils.ts"],"sourcesContent":["/**\n * Component Utilities\n *\n * Generic types and helpers used by generated component builders.\n * Mirrors Python SDK's elements.py Element base class.\n */\n\nimport type { WrapWithPropValue } from './expressions';\nimport type { ActionBinding } from './action-utils';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\n\nexport type EventAction = ActionBinding | ActionBinding[];\n\n/**\n * The actual runtime shape behind the branded ElementNode.\n * Only used internally by buildNode() and render().\n */\nexport interface InternalElementNode {\n id?: string;\n type: string;\n props: Record<string, unknown>;\n children?: ElementNode[];\n slots?: Record<string, ElementNode[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\n/**\n * Standard input shape for a component builder.\n *\n * - `Props`: plain prop types — automatically wrapped with PropValue\n * - `Events`: string union of supported event names (use `never` for none)\n * - `HasChildren`: whether this component accepts children\n *\n * The conditional types ensure `on` is only available when events exist,\n * and `children` is only available when HasChildren is true.\n */\nexport type ComponentInputs<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Variant where props is optional (for components with all-optional props).\n */\nexport type ComponentInputsOptionalProps<\n Props,\n Events extends string = never,\n HasChildren extends boolean = false,\n Slots extends string = never,\n> = {\n id?: string;\n props?: WrapWithPropValue<Props>;\n visible?: VisibilityBinding | boolean;\n repeat?: RepeatBinding;\n} & ([Events] extends [never]\n ? { on?: never }\n : { on?: { [K in Events]?: EventAction } }) &\n (HasChildren extends true\n ? { children?: ElementNode[] }\n : { children?: never }) &\n ([Slots] extends [never]\n ? { slots?: never }\n : { slots?: { [K in Slots]?: ElementNode[] } });\n\n/**\n * Creates an ElementNode from builder input. Used by generated component builders.\n */\nexport function buildNode<\n TPlatform extends string = string,\n TCatalog extends string = string,\n>(\n type: string,\n input: {\n id?: string;\n props?: unknown;\n visible?: unknown;\n on?: unknown;\n children?: unknown;\n slots?: unknown;\n repeat?: unknown;\n }\n): ElementNode<TPlatform, TCatalog> {\n const node: InternalElementNode = {\n type,\n props: (input.props ?? {}) as Record<string, unknown>,\n };\n if (input.id !== undefined) node.id = input.id;\n if (input.visible !== undefined) node.visible = input.visible;\n if (input.on) node.on = input.on as Record<string, unknown>;\n if (input.children) node.children = input.children as ElementNode[];\n if (input.slots) node.slots = input.slots as Record<string, ElementNode[]>;\n if (input.repeat)\n node.repeat = input.repeat as unknown as {\n statePath: string;\n key?: string;\n };\n return node as unknown as ElementNode<TPlatform, TCatalog>;\n}\n"],"names":["buildNode","type","input","node"],"mappings":"AAsFO,SAASA,EAIdC,GACAC,GASkC;AAClC,QAAMC,IAA4B;AAAA,IAChC,MAAAF;AAAA,IACA,OAAQC,EAAM,SAAS,CAAA;AAAA,EAAC;AAE1B,SAAIA,EAAM,OAAO,WAAWC,EAAK,KAAKD,EAAM,KACxCA,EAAM,YAAY,WAAWC,EAAK,UAAUD,EAAM,UAClDA,EAAM,OAAIC,EAAK,KAAKD,EAAM,KAC1BA,EAAM,aAAUC,EAAK,WAAWD,EAAM,WACtCA,EAAM,UAAOC,EAAK,QAAQD,EAAM,QAChCA,EAAM,WACRC,EAAK,SAASD,EAAM,SAIfC;AACT;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(f,S){const $={},p=new Map,m=new WeakMap,h=new WeakSet,u=new Set;let b=0;function t(n,d=new WeakSet){var l;const c=n;if(d.has(c))return;d.add(c);const e=n;if(e.id!==void 0){const o=p.get(e.id);if(o&&o!==c)throw new Error(`Duplicate element id: ${e.id}`);p.set(e.id,c),u.add(e.id)}(l=e.children)==null||l.forEach(o=>t(o,d))}function s(){let n;do n=`element-${b}`,b+=1;while(u.has(n));return u.add(n),n}function r(n){const d=n,c=m.get(d);if(c)return c;const l=n.id??s();return m.set(d,l),l}function a(n){const d=n,c=r(n);if(h.has(d))return c;h.add(d);const e=n,l=e.children?e.children.map(I=>a(I)):[],o={type:e.type,props:e.props,children:l};return e.visible!==void 0&&(o.visible=e.visible),e.on&&(o.on=e.on),e.watch&&(o.watch=e.watch),e.repeat&&(o.repeat=e.repeat),$[c]=o,c}t(f);const i=a(f);return JSON.parse(JSON.stringify({root:i,elements:$,state:S}))}function g(f){const S=f.state;function $(t){return{$state:t}}function p(t){return{$bindState:t}}function m(t,...s){let r=t[0];for(let a=0;a<s.length;a+=1){const i=s[a];!i||typeof i!="object"?r+="":"$state"in i?r+=`\${${i.$state}}`:"$item"in i?r+=`\${$item.${i.$item}}`:"$index"in i&&(r+="${$index}"),r+=t[a+1]}return{$template:r}}function h(t,s,r){return{$cond:t,$then:s,$else:r}}function u(t,s){return[{statePath:t,key:s},{$(i){return{$item:i}},$bind(i){return{$bindItem:i}},$index(){return{$index:!0}}}]}function b(t){return w(t,S)}return{$state:$,$bindState:p,$template:m,$cond:h,repeat:u,render:b}}exports.createSpec=g;exports.renderElementTree=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function I($,w){const p={},m=new Map,h=new WeakMap,b=new WeakSet,f=new Set;let S=0;function t(n,s=new WeakSet){var l;const o=n;if(s.has(o))return;s.add(o);const e=n;if(e.id!==void 0){const r=m.get(e.id);if(r&&r!==o)throw new Error(`Duplicate element id: ${e.id}`);m.set(e.id,o),f.add(e.id)}(l=e.children)==null||l.forEach(r=>t(r,s)),Object.values(e.slots??{}).forEach(r=>r.forEach(u=>t(u,s)))}function a(){let n;do n=`element-${S}`,S+=1;while(f.has(n));return f.add(n),n}function c(n){const s=n,o=h.get(s);if(o)return o;const l=n.id??a();return h.set(s,l),l}function d(n){const s=n,o=c(n);if(b.has(s))return o;b.add(s);const e=n,l=e.children?e.children.map(u=>d(u)):[],r={type:e.type,props:e.props,children:l};return e.slots&&(r.slots=Object.fromEntries(Object.entries(e.slots).map(([u,g])=>[u,g.map(x=>d(x))]))),e.visible!==void 0&&(r.visible=e.visible),e.on&&(r.on=e.on),e.watch&&(r.watch=e.watch),e.repeat&&(r.repeat=e.repeat),p[o]=r,o}t($);const i=d($);return JSON.parse(JSON.stringify({root:i,elements:p,state:w}))}function E($){const w=$.state;function p(t){return{$state:t}}function m(t){return{$bindState:t}}function h(t,...a){let c=t[0];for(let d=0;d<a.length;d+=1){const i=a[d];!i||typeof i!="object"?c+="":"$state"in i?c+=`\${${i.$state}}`:"$item"in i?c+=`\${$item.${i.$item}}`:"$index"in i&&(c+="${$index}"),c+=t[d+1]}return{$template:c}}function b(t,a,c){return{$cond:t,$then:a,$else:c}}function f(t,a){return[{statePath:t,key:a},{$(i){return{$item:i}},$bind(i){return{$bindItem:i}},$index(){return{$index:!0}}}]}function S(t){return I(t,w)}return{$state:p,$bindState:m,$template:h,$cond:b,repeat:f,render:S}}exports.createSpec=E;exports.renderElementTree=I;
2
2
  //# sourceMappingURL=spec.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"spec.cjs","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","nodeObject","n","existing","_a","child","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"gFAiEO,SAASA,EAAkBC,EAAmBC,EAA0B,CAC7E,MAAMC,EAA0C,CAAA,EAC1CC,MAAkB,IAClBC,MAAiB,QACjBC,MAAc,QACdC,MAAc,IACpB,IAAIC,EAAkB,EAEtB,SAASC,EACPC,EACAC,EAAO,IAAI,QACL,OACN,MAAMC,EAAaF,EACnB,GAAIC,EAAK,IAAIC,CAAU,EACrB,OAEFD,EAAK,IAAIC,CAA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,EACA,OAAAI,EACA,OAAAG,CAAA,CAEJ"}
1
+ {"version":3,"file":"spec.cjs","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","nodeObject","n","existing","_a","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"gFAkEO,SAASA,EAAkBC,EAAmBC,EAA0B,CAC7E,MAAMC,EAA0C,CAAA,EAC1CC,MAAkB,IAClBC,MAAiB,QACjBC,MAAc,QACdC,MAAc,IACpB,IAAIC,EAAkB,EAEtB,SAASC,EACPC,EACAC,EAAO,IAAI,QACL,OACN,MAAMC,EAAaF,EACnB,GAAIC,EAAK,IAAIC,CAAU,EACrB,OAEFD,EAAK,IAAIC,CAAU,EAEnB,MAAMC,EAAIH,EACV,GAAIG,EAAE,KAAO,OAAW,CACtB,MAAMC,EAAWV,EAAY,IAAIS,EAAE,EAAE,EACrC,GAAIC,GAAYA,IAAaF,EAC3B,MAAM,IAAI,MAAM,yBAAyBC,EAAE,EAAE,EAAE,EAEjDT,EAAY,IAAIS,EAAE,GAAID,CAAU,EAChCL,EAAQ,IAAIM,EAAE,EAAE,CAClB,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AAAE,EACA,UAAAC,EACA,MAAAM,EACA,OAAAI,EACA,OAAAG,CAAA,CAEJ"}
@@ -15,6 +15,7 @@ export interface FlatUIElement {
15
15
  type: string;
16
16
  props: Record<string, unknown>;
17
17
  children?: string[];
18
+ slots?: Record<string, string[]>;
18
19
  visible?: unknown;
19
20
  on?: Record<string, unknown>;
20
21
  watch?: Record<string, unknown>;
package/dist/core/spec.js CHANGED
@@ -1,78 +1,85 @@
1
- function I(f, w) {
2
- const $ = {}, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakSet(), u = /* @__PURE__ */ new Set();
3
- let b = 0;
4
- function t(n, d = /* @__PURE__ */ new WeakSet()) {
1
+ function E($, x) {
2
+ const p = {}, m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new Set();
3
+ let w = 0;
4
+ function t(n, s = /* @__PURE__ */ new WeakSet()) {
5
5
  var l;
6
- const c = n;
7
- if (d.has(c))
6
+ const o = n;
7
+ if (s.has(o))
8
8
  return;
9
- d.add(c);
9
+ s.add(o);
10
10
  const e = n;
11
11
  if (e.id !== void 0) {
12
- const o = p.get(e.id);
13
- if (o && o !== c)
12
+ const r = m.get(e.id);
13
+ if (r && r !== o)
14
14
  throw new Error(`Duplicate element id: ${e.id}`);
15
- p.set(e.id, c), u.add(e.id);
15
+ m.set(e.id, o), f.add(e.id);
16
16
  }
17
- (l = e.children) == null || l.forEach((o) => t(o, d));
17
+ (l = e.children) == null || l.forEach((r) => t(r, s)), Object.values(e.slots ?? {}).forEach(
18
+ (r) => r.forEach((u) => t(u, s))
19
+ );
18
20
  }
19
- function s() {
21
+ function a() {
20
22
  let n;
21
23
  do
22
- n = `element-${b}`, b += 1;
23
- while (u.has(n));
24
- return u.add(n), n;
24
+ n = `element-${w}`, w += 1;
25
+ while (f.has(n));
26
+ return f.add(n), n;
25
27
  }
26
- function r(n) {
27
- const d = n, c = m.get(d);
28
- if (c)
29
- return c;
30
- const l = n.id ?? s();
31
- return m.set(d, l), l;
28
+ function c(n) {
29
+ const s = n, o = h.get(s);
30
+ if (o)
31
+ return o;
32
+ const l = n.id ?? a();
33
+ return h.set(s, l), l;
32
34
  }
33
- function a(n) {
34
- const d = n, c = r(n);
35
- if (h.has(d))
36
- return c;
37
- h.add(d);
38
- const e = n, l = e.children ? e.children.map((x) => a(x)) : [], o = {
35
+ function d(n) {
36
+ const s = n, o = c(n);
37
+ if (b.has(s))
38
+ return o;
39
+ b.add(s);
40
+ const e = n, l = e.children ? e.children.map((u) => d(u)) : [], r = {
39
41
  type: e.type,
40
42
  props: e.props,
41
43
  children: l
42
44
  };
43
- return e.visible !== void 0 && (o.visible = e.visible), e.on && (o.on = e.on), e.watch && (o.watch = e.watch), e.repeat && (o.repeat = e.repeat), $[c] = o, c;
45
+ return e.slots && (r.slots = Object.fromEntries(
46
+ Object.entries(e.slots).map(([u, I]) => [
47
+ u,
48
+ I.map((S) => d(S))
49
+ ])
50
+ )), e.visible !== void 0 && (r.visible = e.visible), e.on && (r.on = e.on), e.watch && (r.watch = e.watch), e.repeat && (r.repeat = e.repeat), p[o] = r, o;
44
51
  }
45
- t(f);
46
- const i = a(f);
52
+ t($);
53
+ const i = d($);
47
54
  return JSON.parse(
48
55
  JSON.stringify({
49
56
  root: i,
50
- elements: $,
51
- state: w
57
+ elements: p,
58
+ state: x
52
59
  })
53
60
  );
54
61
  }
55
- function S(f) {
56
- const w = f.state;
57
- function $(t) {
62
+ function O($) {
63
+ const x = $.state;
64
+ function p(t) {
58
65
  return { $state: t };
59
66
  }
60
- function p(t) {
67
+ function m(t) {
61
68
  return { $bindState: t };
62
69
  }
63
- function m(t, ...s) {
64
- let r = t[0];
65
- for (let a = 0; a < s.length; a += 1) {
66
- const i = s[a];
67
- !i || typeof i != "object" ? r += "" : "$state" in i ? r += `\${${i.$state}}` : "$item" in i ? r += `\${$item.${i.$item}}` : "$index" in i && (r += "${$index}"), r += t[a + 1];
70
+ function h(t, ...a) {
71
+ let c = t[0];
72
+ for (let d = 0; d < a.length; d += 1) {
73
+ const i = a[d];
74
+ !i || typeof i != "object" ? c += "" : "$state" in i ? c += `\${${i.$state}}` : "$item" in i ? c += `\${$item.${i.$item}}` : "$index" in i && (c += "${$index}"), c += t[d + 1];
68
75
  }
69
- return { $template: r };
76
+ return { $template: c };
70
77
  }
71
- function h(t, s, r) {
72
- return { $cond: t, $then: s, $else: r };
78
+ function b(t, a, c) {
79
+ return { $cond: t, $then: a, $else: c };
73
80
  }
74
- function u(t, s) {
75
- return [{ statePath: t, key: s }, {
81
+ function f(t, a) {
82
+ return [{ statePath: t, key: a }, {
76
83
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
84
  $(i) {
78
85
  return { $item: i };
@@ -87,20 +94,20 @@ function S(f) {
87
94
  }
88
95
  }];
89
96
  }
90
- function b(t) {
91
- return I(t, w);
97
+ function w(t) {
98
+ return E(t, x);
92
99
  }
93
100
  return {
94
- $state: $,
95
- $bindState: p,
96
- $template: m,
97
- $cond: h,
98
- repeat: u,
99
- render: b
101
+ $state: p,
102
+ $bindState: m,
103
+ $template: h,
104
+ $cond: b,
105
+ repeat: f,
106
+ render: w
100
107
  };
101
108
  }
102
109
  export {
103
- S as createSpec,
104
- I as renderElementTree
110
+ O as createSpec,
111
+ E as renderElementTree
105
112
  };
106
113
  //# sourceMappingURL=spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spec.js","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","_a","nodeObject","n","existing","child","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"AAiEO,SAASA,EAAkBC,GAAmBC,GAA0B;AAC7E,QAAMC,IAA0C,CAAA,GAC1CC,wBAAkB,IAAA,GAClBC,wBAAiB,QAAA,GACjBC,wBAAc,QAAA,GACdC,wBAAc,IAAA;AACpB,MAAIC,IAAkB;AAEtB,WAASC,EACPC,GACAC,IAAO,oBAAI,WACL;AAXH,QAAAC;AAYH,UAAMC,IAAaH;AACnB,QAAIC,EAAK,IAAIE,CAAU;AACrB;AAEF,IAAAF,EAAK,IAAIE,CAAU;AAEnB,UAAMC,IAAIJ;AACV,QAAII,EAAE,OAAO,QAAW;AACtB,YAAMC,IAAWX,EAAY,IAAIU,EAAE,EAAE;AACrC,UAAIC,KAAYA,MAAaF;AAC3B,cAAM,IAAI,MAAM,yBAAyBC,EAAE,EAAE,EAAE;AAEjD,MAAAV,EAAY,IAAIU,EAAE,IAAID,CAAU,GAChCN,EAAQ,IAAIO,EAAE,EAAE;AAAA,IAClB;AAEA,KAAAF,IAAAE,EAAE,aAAF,QAAAF,EAAY,QAAQ,CAAAI,MAASP,EAAmBO,GAAOL,CAAI;AAAA,EAC7D;AAEA,WAASM,IAA8B;AACrC,QAAIC;AACJ;AACE,MAAAA,IAAK,WAAWV,CAAe,IAC/BA,KAAmB;AAAA,WACZD,EAAQ,IAAIW,CAAE;AAEvB,WAAAX,EAAQ,IAAIW,CAAE,GACPA;AAAA,EACT;AAEA,WAASC,EAAUT,GAA2B;AAC5C,UAAMG,IAAaH,GACbK,IAAWV,EAAW,IAAIQ,CAAU;AAC1C,QAAIE;AACF,aAAOA;AAIT,UAAMG,IADIR,EACG,MAAMO,EAAA;AACnB,WAAAZ,EAAW,IAAIQ,GAAYK,CAAE,GACtBA;AAAA,EACT;AAEA,WAASE,EAAQV,GAA2B;AAC1C,UAAM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MACtB,YAAYA,MACrBF,KAAU,cAEZA,KAAUF,EAAQG,IAAI,CAAC;AAAA,IACzB;AACA,WAAO,EAAE,WAAWD,EAAA;AAAA,EACtB;AAEA,WAASG,EAAMC,GAAoBC,GAAeC,GAAyB;AACzE,WAAO,EAAE,OAAOF,GAAW,OAAOC,GAAM,OAAOC,EAAA;AAAA,EACjD;AASA,WAASC,EACPC,GACAC,GACkC;AAkBlC,WAAO,CAjBe,EAAE,WAAAD,GAAW,KAAAC,EAAA,GAES;AAAA;AAAA,MAE1C,EAAEd,GAAmB;AACnB,eAAO,EAAE,OAAOA,EAAA;AAAA,MAClB;AAAA;AAAA,MAEA,MAAMA,GAAmB;AACvB,eAAO,EAAE,WAAWA,EAAA;AAAA,MACtB;AAAA;AAAA,MAEA,SAAc;AACZ,eAAO,EAAE,QAAQ,GAAA;AAAA,MACnB;AAAA,IAAA,CAGiC;AAAA,EACrC;AAEA,WAASe,EAAO1C,GAA6B;AAC3C,WAAOD,EAAkBC,GAAMyB,CAAY;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,QAAAC;AAAA,IACA,YAAAE;AAAA,IACA,WAAAC;AAAA,IACA,OAAAM;AAAA,IACA,QAAAI;AAAA,IACA,QAAAG;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"spec.js","sources":["../../../sdui-core/src/spec.ts"],"sourcesContent":["/**\n * createSpec - Factory for state-bound expression helpers + render\n *\n * Mirrors Python SDK's StateHandle + render module.\n */\n\nimport type {\n StatePaths,\n ValueAt,\n ArrayPaths,\n ArrayItemAt,\n ItemPaths,\n ItemValueAt,\n} from './paths';\nimport type {\n StateRef,\n BindStateRef,\n ItemRef,\n BindItemRef,\n IndexRef,\n TemplateRef,\n TemplateInterpolation,\n CondRef,\n PropValue,\n} from './expressions';\nimport type { VisibilityBinding } from './conditions';\nimport type { ElementNode, RepeatBinding } from './elements';\nimport type { InternalElementNode } from './component-utils';\n\n/** Typed accessor for repeat item fields. */\nexport interface ItemAccessor<TItem> {\n /** Read a field from the current repeat item. */\n $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;\n /** Two-way bind to a field on the current repeat item. */\n $bind<P extends ItemPaths<TItem>>(\n path: P\n ): BindItemRef<ItemValueAt<TItem, P>>;\n /** Current repeat index (number). */\n $index(): IndexRef;\n}\n\nexport interface FlatUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: string[];\n slots?: Record<string, string[]>;\n visible?: unknown;\n on?: Record<string, unknown>;\n watch?: Record<string, unknown>;\n repeat?: { statePath: string; key?: string };\n}\n\nexport interface FlatSpec {\n root: string;\n elements: Record<string, FlatUIElement>;\n state?: Record<string, unknown>;\n}\n\nexport type Spec = FlatSpec;\nexport type CoreSpec = FlatSpec;\n\n/**\n * Flatten an element tree into a flat spec format.\n * Uses JSON round-trip to strip Symbol properties and undefined values,\n * ensuring clean serialization.\n */\nexport function renderElementTree(root: ElementNode, state?: object): FlatSpec {\n const elements: Record<string, FlatUIElement> = {};\n const explicitIds = new Map<string, object>();\n const elementIds = new WeakMap<object, string>();\n const emitted = new WeakSet<object>();\n const usedIds = new Set<string>();\n let nextGeneratedId = 0;\n\n function collectExplicitIds(\n node: ElementNode,\n seen = new WeakSet<object>()\n ): void {\n const nodeObject = node as unknown as object;\n if (seen.has(nodeObject)) {\n return;\n }\n seen.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n if (n.id !== undefined) {\n const existing = explicitIds.get(n.id);\n if (existing && existing !== nodeObject) {\n throw new Error(`Duplicate element id: ${n.id}`);\n }\n explicitIds.set(n.id, nodeObject);\n usedIds.add(n.id);\n }\n\n n.children?.forEach(child => collectExplicitIds(child, seen));\n Object.values(n.slots ?? {}).forEach(slotChildren =>\n slotChildren.forEach(child => collectExplicitIds(child, seen))\n );\n }\n\n function allocateGeneratedId(): string {\n let id: string;\n do {\n id = `element-${nextGeneratedId}`;\n nextGeneratedId += 1;\n } while (usedIds.has(id));\n\n usedIds.add(id);\n return id;\n }\n\n function elementId(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const existing = elementIds.get(nodeObject);\n if (existing) {\n return existing;\n }\n\n const n = node as unknown as InternalElementNode;\n const id = n.id ?? allocateGeneratedId();\n elementIds.set(nodeObject, id);\n return id;\n }\n\n function flatten(node: ElementNode): string {\n const nodeObject = node as unknown as object;\n const id = elementId(node);\n if (emitted.has(nodeObject)) {\n return id;\n }\n emitted.add(nodeObject);\n\n const n = node as unknown as InternalElementNode;\n const childIds: string[] = n.children\n ? n.children.map(child => flatten(child))\n : [];\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n children: childIds,\n };\n if (n.slots) {\n flatElement.slots = Object.fromEntries(\n Object.entries(n.slots).map(([name, slotChildren]) => [\n name,\n slotChildren.map(child => flatten(child)),\n ])\n );\n }\n\n if (n.visible !== undefined) {\n flatElement.visible = n.visible;\n }\n if (n.on) {\n flatElement.on = n.on;\n }\n if (n.watch) {\n flatElement.watch = n.watch;\n }\n if (n.repeat) {\n flatElement.repeat = n.repeat;\n }\n\n elements[id] = flatElement;\n return id;\n }\n\n collectExplicitIds(root);\n const rootId = flatten(root);\n\n return JSON.parse(\n JSON.stringify({\n root: rootId,\n elements,\n state,\n })\n ) as FlatSpec;\n}\n\nexport interface SpecContext<TState> {\n /** Read-only reference to a state path. */\n $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;\n\n /** Two-way binding to a state path. */\n $bindState<P extends StatePaths<TState>>(\n path: P\n ): BindStateRef<ValueAt<TState, P>>;\n\n /** String template expression (tagged template literal). */\n $template(\n strings: TemplateStringsArray,\n ...values: TemplateInterpolation[]\n ): TemplateRef;\n\n /** Conditional expression with typed branches. */\n $cond<T>(\n condition: VisibilityBinding | boolean,\n then: PropValue<T>,\n else_: PropValue<T>\n ): CondRef<T>;\n\n /**\n * Create a repeat binding for an array state path.\n * Returns [RepeatBinding, ItemAccessor<T>].\n */\n repeat<P extends ArrayPaths<TState>>(\n statePath: P,\n key?: string\n ): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];\n\n /** Flatten an element tree into the flat spec format. */\n render(root: ElementNode): FlatSpec;\n}\n\nexport function createSpec<TState extends object>(config: {\n state: TState;\n}): SpecContext<TState> {\n const initialState = config.state;\n\n function $state(path: string): unknown {\n return { $state: path };\n }\n\n function $bindState(path: string): unknown {\n return { $bindState: path };\n }\n\n /**\n * Build a template string from a tagged template literal.\n * Converts expression refs ($state, $item, $index) into template variables.\n */\n function $template(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): unknown {\n let result = strings[0];\n for (let i = 0; i < values.length; i += 1) {\n const val = values[i];\n if (!val || typeof val !== 'object') {\n result += '';\n } else if ('$state' in val) {\n result += `\\${${val.$state}}`;\n } else if ('$item' in val) {\n result += `\\${$item.${val.$item}}`;\n } else if ('$index' in val) {\n result += '${$index}';\n }\n result += strings[i + 1];\n }\n return { $template: result };\n }\n\n function $cond(condition: unknown, then: unknown, else_: unknown): unknown {\n return { $cond: condition, $then: then, $else: else_ };\n }\n\n /**\n * Create a repeat binding for array iteration.\n * Returns [RepeatBinding, ItemAccessor] tuple.\n *\n * Type safety is enforced at the createSpec boundary through type parameters.\n * Internal implementations use `any` to work with the opaque branded types.\n */\n function repeat(\n statePath: string,\n key?: string\n ): [unknown, ItemAccessor<unknown>] {\n const repeatBinding = { statePath, key } as unknown as RepeatBinding;\n\n const itemAccessor: ItemAccessor<unknown> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $(path: string): any {\n return { $item: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $bind(path: string): any {\n return { $bindItem: path };\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n $index(): any {\n return { $index: true };\n },\n };\n\n return [repeatBinding, itemAccessor];\n }\n\n function render(root: ElementNode): FlatSpec {\n return renderElementTree(root, initialState);\n }\n\n return {\n $state,\n $bindState,\n $template,\n $cond,\n repeat,\n render,\n } as unknown as SpecContext<TState>;\n}\n"],"names":["renderElementTree","root","state","elements","explicitIds","elementIds","emitted","usedIds","nextGeneratedId","collectExplicitIds","node","seen","_a","nodeObject","n","existing","child","slotChildren","allocateGeneratedId","id","elementId","flatten","childIds","flatElement","name","rootId","createSpec","config","initialState","$state","path","$bindState","$template","strings","values","result","i","val","$cond","condition","then","else_","repeat","statePath","key","render"],"mappings":"AAkEO,SAASA,EAAkBC,GAAmBC,GAA0B;AAC7E,QAAMC,IAA0C,CAAA,GAC1CC,wBAAkB,IAAA,GAClBC,wBAAiB,QAAA,GACjBC,wBAAc,QAAA,GACdC,wBAAc,IAAA;AACpB,MAAIC,IAAkB;AAEtB,WAASC,EACPC,GACAC,IAAO,oBAAI,WACL;AAXH,QAAAC;AAYH,UAAMC,IAAaH;AACnB,QAAIC,EAAK,IAAIE,CAAU;AACrB;AAEF,IAAAF,EAAK,IAAIE,CAAU;AAEnB,UAAMC,IAAIJ;AACV,QAAII,EAAE,OAAO,QAAW;AACtB,YAAMC,IAAWX,EAAY,IAAIU,EAAE,EAAE;AACrC,UAAIC,KAAYA,MAAaF;AAC3B,cAAM,IAAI,MAAM,yBAAyBC,EAAE,EAAE,EAAE;AAEjD,MAAAV,EAAY,IAAIU,EAAE,IAAID,CAAU,GAChCN,EAAQ,IAAIO,EAAE,EAAE;AAAA,IAClB;AAEA,KAAAF,IAAAE,EAAE,aAAF,QAAAF,EAAY,QAAQ,CAAAI,MAASP,EAAmBO,GAAOL,CAAI,IAC3D,OAAO,OAAOG,EAAE,SAAS,CAAA,CAAE,EAAE;AAAA,MAAQ,OACnCG,EAAa,QAAQ,OAASR,EAAmBO,GAAOL,CAAI,CAAC;AAAA,IAAA;AAAA,EAEjE;AAEA,WAASO,IAA8B;AACrC,QAAIC;AACJ;AACE,MAAAA,IAAK,WAAWX,CAAe,IAC/BA,KAAmB;AAAA,WACZD,EAAQ,IAAIY,CAAE;AAEvB,WAAAZ,EAAQ,IAAIY,CAAE,GACPA;AAAA,EACT;AAEA,WAASC,EAAUV,GAA2B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3,32 @@
3
3
 
4
4
  Import action creators from `@rippling/pebble-sdui-mobile/catalogs/custom-apps`. Read [definitions.md](./definitions.md) for enum values linked from param tables.
5
5
 
6
+ ## copyToClipboard
7
+
8
+ Copy text to the device clipboard.
9
+
10
+ `text` (required): the resolved text to place on the device clipboard.
11
+
12
+ Catalog key: `copyToClipboard`
13
+ Creator: `copyToClipboard`
14
+ Params type: `CopyToClipboardParams`
15
+
16
+ ### Params
17
+
18
+ | Name | Required | Type | Description |
19
+ |---|---:|---|---|
20
+ | `text` | yes | string | Text to copy to the device clipboard. |
21
+
22
+ No additional properties.
23
+
24
+ ### Usage Shape
25
+
26
+ ```ts
27
+ on: {
28
+ press: copyToClipboard({ ... })
29
+ }
30
+ ```
31
+
6
32
  ## goBack
7
33
 
8
34
  Mobile-specific action that goes back to the previous screen in the navigation stack.
@@ -27,6 +53,32 @@ on: {
27
53
  }
28
54
  ```
29
55
 
56
+ ## linking_openURL
57
+
58
+ Open a supported URL using the device operating system.
59
+
60
+ `url` (required): the resolved URL to open.
61
+
62
+ Catalog key: `linking_openURL`
63
+ Creator: `linking_openURL`
64
+ Params type: `Linking_openURLParams`
65
+
66
+ ### Params
67
+
68
+ | Name | Required | Type | Description |
69
+ |---|---:|---|---|
70
+ | `url` | yes | string | URL to open using the device operating system. |
71
+
72
+ No additional properties.
73
+
74
+ ### Usage Shape
75
+
76
+ ```ts
77
+ on: {
78
+ press: linking_openURL({ ... })
79
+ }
80
+ ```
81
+
30
82
  ## navigate
31
83
 
32
84
  Navigate to a React Navigation screen by name using the mobile route registered in the navigator.