@rippling/pebble-sdui-web 0.2.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 (58) hide show
  1. package/dist/catalogs/custom-apps/action-params.d.ts +33 -0
  2. package/dist/catalogs/custom-apps/actions.d.ts +9 -0
  3. package/dist/catalogs/custom-apps/catalog.d.ts +25 -0
  4. package/dist/catalogs/custom-apps/component-events.d.ts +173 -0
  5. package/dist/catalogs/custom-apps/component-props.d.ts +3479 -0
  6. package/dist/catalogs/custom-apps/components.d.ts +174 -0
  7. package/dist/catalogs/custom-apps/index.cjs +12 -0
  8. package/dist/catalogs/custom-apps/index.cjs.map +1 -0
  9. package/dist/catalogs/custom-apps/index.d.ts +13 -0
  10. package/dist/catalogs/custom-apps/index.js +25236 -0
  11. package/dist/catalogs/custom-apps/index.js.map +1 -0
  12. package/dist/catalogs/custom-apps/render.d.ts +20 -0
  13. package/dist/core/action-utils.cjs +2 -0
  14. package/dist/core/action-utils.cjs.map +1 -0
  15. package/dist/core/action-utils.d.ts +48 -0
  16. package/dist/core/action-utils.js +8 -0
  17. package/dist/core/action-utils.js.map +1 -0
  18. package/dist/core/component-utils.cjs +2 -0
  19. package/dist/core/component-utils.cjs.map +1 -0
  20. package/dist/core/component-utils.d.ts +77 -0
  21. package/dist/core/component-utils.js +11 -0
  22. package/dist/core/component-utils.js.map +1 -0
  23. package/dist/core/conditions.cjs +2 -0
  24. package/dist/core/conditions.cjs.map +1 -0
  25. package/dist/core/conditions.d.ts +70 -0
  26. package/dist/core/conditions.js +69 -0
  27. package/dist/core/conditions.js.map +1 -0
  28. package/dist/core/elements.cjs +2 -0
  29. package/dist/core/elements.cjs.map +1 -0
  30. package/dist/core/elements.d.ts +24 -0
  31. package/dist/core/elements.js +2 -0
  32. package/dist/core/elements.js.map +1 -0
  33. package/dist/core/expressions.cjs +2 -0
  34. package/dist/core/expressions.cjs.map +1 -0
  35. package/dist/core/expressions.d.ts +81 -0
  36. package/dist/core/expressions.js +2 -0
  37. package/dist/core/expressions.js.map +1 -0
  38. package/dist/core/index.cjs +2 -0
  39. package/dist/core/index.cjs.map +1 -0
  40. package/dist/core/index.d.ts +14 -0
  41. package/dist/core/index.js +25 -0
  42. package/dist/core/index.js.map +1 -0
  43. package/dist/core/paths.cjs +2 -0
  44. package/dist/core/paths.cjs.map +1 -0
  45. package/dist/core/paths.d.ts +27 -0
  46. package/dist/core/paths.js +2 -0
  47. package/dist/core/paths.js.map +1 -0
  48. package/dist/core/spec.cjs +2 -0
  49. package/dist/core/spec.cjs.map +1 -0
  50. package/dist/core/spec.d.ts +56 -0
  51. package/dist/core/spec.js +105 -0
  52. package/dist/core/spec.js.map +1 -0
  53. package/dist/index.cjs +2 -0
  54. package/dist/index.cjs.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.js +24 -0
  57. package/dist/index.js.map +1 -0
  58. package/package.json +51 -0
@@ -0,0 +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\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[] | undefined = n.children\n ? n.children.map(child => flatten(child))\n : undefined;\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n };\n\n if (childIds && childIds.length > 0) {\n flatElement.children = childIds;\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":"gFA8DO,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,OAC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6B,CAC3C,OAAOD,EAAkBC,EAAMyB,CAAY,CAC7C,CAEA,MAAO,CACL,OAAAC,EACA,WAAAE,EACA,UAAAC,EACA,MAAAM,EACA,OAAAI,EACA,OAAAG,CAAA,CAEJ"}
@@ -0,0 +1,56 @@
1
+ import { StatePaths, ValueAt, ArrayPaths, ArrayItemAt, ItemPaths, ItemValueAt } from './paths';
2
+ import { StateRef, BindStateRef, ItemRef, BindItemRef, IndexRef, TemplateRef, TemplateInterpolation, CondRef, PropValue } from './expressions';
3
+ import { VisibilityBinding } from './conditions';
4
+ import { ElementNode, RepeatBinding } from './elements';
5
+ /** Typed accessor for repeat item fields. */
6
+ export interface ItemAccessor<TItem> {
7
+ /** Read a field from the current repeat item. */
8
+ $<P extends ItemPaths<TItem>>(path: P): ItemRef<ItemValueAt<TItem, P>>;
9
+ /** Two-way bind to a field on the current repeat item. */
10
+ $bind<P extends ItemPaths<TItem>>(path: P): BindItemRef<ItemValueAt<TItem, P>>;
11
+ /** Current repeat index (number). */
12
+ $index(): IndexRef;
13
+ }
14
+ export interface FlatUIElement {
15
+ type: string;
16
+ props: Record<string, unknown>;
17
+ children?: string[];
18
+ visible?: unknown;
19
+ on?: Record<string, unknown>;
20
+ watch?: Record<string, unknown>;
21
+ repeat?: {
22
+ statePath: string;
23
+ key?: string;
24
+ };
25
+ }
26
+ export interface FlatSpec {
27
+ root: string;
28
+ elements: Record<string, FlatUIElement>;
29
+ state?: Record<string, unknown>;
30
+ }
31
+ /**
32
+ * Flatten an element tree into a flat spec format.
33
+ * Uses JSON round-trip to strip Symbol properties and undefined values,
34
+ * ensuring clean serialization.
35
+ */
36
+ export declare function renderElementTree(root: ElementNode, state?: object): FlatSpec;
37
+ export interface SpecContext<TState> {
38
+ /** Read-only reference to a state path. */
39
+ $state<P extends StatePaths<TState>>(path: P): StateRef<ValueAt<TState, P>>;
40
+ /** Two-way binding to a state path. */
41
+ $bindState<P extends StatePaths<TState>>(path: P): BindStateRef<ValueAt<TState, P>>;
42
+ /** String template expression (tagged template literal). */
43
+ $template(strings: TemplateStringsArray, ...values: TemplateInterpolation[]): TemplateRef;
44
+ /** Conditional expression with typed branches. */
45
+ $cond<T>(condition: VisibilityBinding | boolean, then: PropValue<T>, else_: PropValue<T>): CondRef<T>;
46
+ /**
47
+ * Create a repeat binding for an array state path.
48
+ * Returns [RepeatBinding, ItemAccessor<T>].
49
+ */
50
+ repeat<P extends ArrayPaths<TState>>(statePath: P, key?: string): [RepeatBinding, ItemAccessor<ArrayItemAt<TState, P>>];
51
+ /** Flatten an element tree into the flat spec format. */
52
+ render(root: ElementNode): FlatSpec;
53
+ }
54
+ export declare function createSpec<TState extends object>(config: {
55
+ state: TState;
56
+ }): SpecContext<TState>;
@@ -0,0 +1,105 @@
1
+ function I(u, w) {
2
+ const $ = {}, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new Set();
3
+ let b = 0;
4
+ function t(n, d = /* @__PURE__ */ new WeakSet()) {
5
+ var s;
6
+ const c = n;
7
+ if (d.has(c))
8
+ return;
9
+ d.add(c);
10
+ const e = n;
11
+ if (e.id !== void 0) {
12
+ const o = p.get(e.id);
13
+ if (o && o !== c)
14
+ throw new Error(`Duplicate element id: ${e.id}`);
15
+ p.set(e.id, c), f.add(e.id);
16
+ }
17
+ (s = e.children) == null || s.forEach((o) => t(o, d));
18
+ }
19
+ function a() {
20
+ let n;
21
+ do
22
+ n = `element-${b}`, b += 1;
23
+ while (f.has(n));
24
+ return f.add(n), n;
25
+ }
26
+ function r(n) {
27
+ const d = n, c = m.get(d);
28
+ if (c)
29
+ return c;
30
+ const s = n.id ?? a();
31
+ return m.set(d, s), s;
32
+ }
33
+ function l(n) {
34
+ const d = n, c = r(n);
35
+ if (h.has(d))
36
+ return c;
37
+ h.add(d);
38
+ const e = n, s = e.children ? e.children.map((x) => l(x)) : void 0, o = {
39
+ type: e.type,
40
+ props: e.props
41
+ };
42
+ return s && s.length > 0 && (o.children = s), 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;
43
+ }
44
+ t(u);
45
+ const i = l(u);
46
+ return JSON.parse(
47
+ JSON.stringify({
48
+ root: i,
49
+ elements: $,
50
+ state: w
51
+ })
52
+ );
53
+ }
54
+ function S(u) {
55
+ const w = u.state;
56
+ function $(t) {
57
+ return { $state: t };
58
+ }
59
+ function p(t) {
60
+ return { $bindState: t };
61
+ }
62
+ function m(t, ...a) {
63
+ let r = t[0];
64
+ for (let l = 0; l < a.length; l += 1) {
65
+ const i = a[l];
66
+ !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[l + 1];
67
+ }
68
+ return { $template: r };
69
+ }
70
+ function h(t, a, r) {
71
+ return { $cond: t, $then: a, $else: r };
72
+ }
73
+ function f(t, a) {
74
+ return [{ statePath: t, key: a }, {
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ $(i) {
77
+ return { $item: i };
78
+ },
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ $bind(i) {
81
+ return { $bindItem: i };
82
+ },
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ $index() {
85
+ return { $index: !0 };
86
+ }
87
+ }];
88
+ }
89
+ function b(t) {
90
+ return I(t, w);
91
+ }
92
+ return {
93
+ $state: $,
94
+ $bindState: p,
95
+ $template: m,
96
+ $cond: h,
97
+ repeat: f,
98
+ render: b
99
+ };
100
+ }
101
+ export {
102
+ S as createSpec,
103
+ I as renderElementTree
104
+ };
105
+ //# sourceMappingURL=spec.js.map
@@ -0,0 +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\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[] | undefined = n.children\n ? n.children.map(child => flatten(child))\n : undefined;\n\n const flatElement: FlatUIElement = {\n type: n.type,\n props: n.props,\n };\n\n if (childIds && childIds.length > 0) {\n flatElement.children = childIds;\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":"AA8DO,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,IAA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,IAAI,GAAGA,IAAIF,EAAO,QAAQE,KAAK,GAAG;AACzC,YAAMC,IAAMH,EAAOE,CAAC;AACpB,MAAI,CAACC,KAAO,OAAOA,KAAQ,WACzBF,KAAU,KACD,YAAYE,IACrBF,KAAU,MAAME,EAAI,MAAM,MACjB,WAAWA,IACpBF,KAAU,YAAYE,EAAI,KAAK,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;"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./core/spec.cjs"),o=require("./core/component-utils.cjs"),r=require("./core/action-utils.cjs"),e=require("./core/conditions.cjs");exports.createSpec=t.createSpec;exports.buildNode=o.buildNode;exports.buildAction=r.buildAction;exports.$and=e.$and;exports.$or=e.$or;exports.$when=e.$when;exports.and_=e.$and;exports.equals=e.equals;exports.falsy=e.falsy;exports.gt=e.gt;exports.gte=e.gte;exports.lt=e.lt;exports.lte=e.lte;exports.neq=e.neq;exports.not_=e.not_;exports.or_=e.$or;exports.truthy=e.truthy;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Web SDK authoring utilities.
3
+ *
4
+ * Catalog-specific code lives under subpath exports like
5
+ * '@rippling/pebble-sdui-web/catalogs/aichat'.
6
+ */
7
+ export { createSpec, buildNode, buildAction, $when, equals, neq, gt, gte, lt, lte, truthy, falsy, not_, $and, $or, and_, or_, } from './core/index';
8
+ export type { SpecContext, FlatSpec, FlatUIElement, ItemAccessor, ComponentInputs, ComponentInputsOptionalProps, InternalElementNode, ActionBinding, ActionConfirm, ActionOptions, ActionOnSuccess, ActionOnError, PropValue, WrapWithPropValue, StateRef, BindStateRef, ItemRef, BindItemRef, IndexRef, TemplateRef, CondRef, TemplateInterpolation, ActionParamValue, WrapWithActionParamValue, VisibilityBinding, ComparisonOps, StatePaths, ValueAt, ArrayPaths, ArrayItemAt, ItemPaths, ItemValueAt, ElementNode, RepeatBinding, } from './core/index';
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { createSpec as r } from "./core/spec.js";
2
+ import { buildNode as a } from "./core/component-utils.js";
3
+ import { buildAction as d } from "./core/action-utils.js";
4
+ import { $and as f, $or as p, $when as $, $and as m, equals as s, falsy as u, gt as x, gte as c, lt as i, lte as _, neq as b, not_ as g, $or as h, truthy as q } from "./core/conditions.js";
5
+ export {
6
+ f as $and,
7
+ p as $or,
8
+ $ as $when,
9
+ m as and_,
10
+ d as buildAction,
11
+ a as buildNode,
12
+ r as createSpec,
13
+ s as equals,
14
+ u as falsy,
15
+ x as gt,
16
+ c as gte,
17
+ i as lt,
18
+ _ as lte,
19
+ b as neq,
20
+ g as not_,
21
+ h as or_,
22
+ q as truthy
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@rippling/pebble-sdui-web",
3
+ "version": "0.2.0",
4
+ "description": "Type-safe TypeScript web SDK for authoring json-render specs",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+ssh://git@github.com/Rippling/pebble-kit.git",
8
+ "directory": "packages/typescript/sdui-web"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.cjs",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ },
20
+ "./catalogs/custom-apps": {
21
+ "types": "./dist/catalogs/custom-apps/index.d.ts",
22
+ "import": "./dist/catalogs/custom-apps/index.js",
23
+ "require": "./dist/catalogs/custom-apps/index.cjs"
24
+ }
25
+ },
26
+ "imports": {
27
+ "#core/*": {
28
+ "types": "./dist/core/*.d.ts",
29
+ "import": "./dist/core/*.js",
30
+ "require": "./dist/core/*.cjs"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "npm run build:self",
35
+ "build:self": "vite build",
36
+ "typecheck": "npm run typecheck:self",
37
+ "typecheck:self": "tsc --noEmit"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.5.0",
41
+ "vite": "^6.0.0",
42
+ "vite-plugin-dts": "^4.0.0",
43
+ "vitest": "^2.0.0"
44
+ },
45
+ "dependencies": {
46
+ "ajv": "^8.17.0"
47
+ },
48
+ "files": [
49
+ "dist"
50
+ ]
51
+ }