@tschk/crepus-moonshine 0.3.3 → 0.3.5

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 (2) hide show
  1. package/package.json +4 -4
  2. package/src/render.ts +30 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tschk/crepus-moonshine",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Bridge: .crepus (parsed by the Rust parser via WASM) to moonshine React elements",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -24,9 +24,9 @@
24
24
  "lint": "bunx oxlint ."
25
25
  },
26
26
  "dependencies": {
27
- "@tschk/crepuscularity-wasm": "^0.1.0",
28
- "@tschk/moonshine": "^0.3.3",
29
- "@tschk/moonshine-framework": "^0.3.3"
27
+ "@tschk/crepuscularity-wasm": "^0.1.3",
28
+ "@tschk/moonshine": "^0.3.5",
29
+ "@tschk/moonshine-framework": "^0.3.5"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": ">=18",
package/src/render.ts CHANGED
@@ -13,6 +13,11 @@ export interface RenderCrepusOptions {
13
13
  * styles the output. The lowered `style` hints exist for native targets and are
14
14
  * deliberately not converted to inline CSS here.
15
15
  */
16
+ function idOf(node: ViewNode): string | undefined {
17
+ const id = (node as { style?: { id?: string } }).style?.id;
18
+ return id && id.length > 0 ? id : undefined;
19
+ }
20
+
16
21
  function classNameOf(node: ViewNode): string | undefined {
17
22
  const classes = (node as { style?: { classes?: string[] } }).style?.classes;
18
23
  if (!classes || classes.length === 0) return undefined;
@@ -28,16 +33,18 @@ function renderChildren(children: ViewNode[], keyPrefix: string): ReactNode[] {
28
33
 
29
34
  export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
30
35
  const className = classNameOf(node);
36
+ const id = idOf(node);
31
37
 
32
38
  switch (node.kind) {
33
39
  case "text":
34
- return createElement("span", { key, className }, node.content);
40
+ return createElement("span", { key, id, className }, node.content);
35
41
 
36
42
  case "link":
37
43
  return createElement(
38
44
  "a",
39
45
  {
40
46
  key,
47
+ id,
41
48
  className,
42
49
  href: node.href,
43
50
  target: node.target,
@@ -50,67 +57,69 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
50
57
  case "scroll":
51
58
  return createElement(
52
59
  "div",
53
- { key, className },
60
+ { key, id, className },
54
61
  ...renderChildren(node.children, key),
55
62
  );
56
63
 
57
64
  case "dropzone":
58
65
  return createElement(
59
66
  "div",
60
- { key, className, "aria-label": node.label },
67
+ { key, id, className, "aria-label": node.label },
61
68
  ...renderChildren(node.children, key),
62
69
  );
63
70
 
64
71
  case "list":
65
72
  return createElement(
66
73
  node.ordered ? "ol" : "ul",
67
- { key, className },
74
+ { key, id, className },
68
75
  ...renderChildren(node.children, key),
69
76
  );
70
77
 
71
78
  case "listItem":
72
79
  return createElement(
73
80
  "li",
74
- { key, className },
81
+ { key, id, className },
75
82
  ...renderChildren(node.children, key),
76
83
  );
77
84
 
78
85
  case "button":
79
86
  return createElement(
80
87
  "button",
81
- { key, className, type: "button" },
88
+ { key, id, className, type: "button" },
82
89
  node.label,
83
90
  );
84
91
 
85
92
  case "badge":
86
93
  return createElement(
87
94
  "span",
88
- { key, className, "data-tone": node.tone },
95
+ { key, id, className, "data-tone": node.tone },
89
96
  node.label,
90
97
  );
91
98
 
92
99
  case "divider":
93
- return createElement("hr", { key, className });
100
+ return createElement("hr", { key, id, className });
94
101
 
95
102
  case "spacer":
96
- return createElement("div", { key, className, "aria-hidden": true });
103
+ return createElement("div", { key, id, className, "aria-hidden": true });
97
104
 
98
105
  case "image":
99
106
  return createElement("img", {
100
107
  key,
108
+ id,
101
109
  className,
102
110
  src: node.src,
103
111
  alt: node.alt ?? "",
104
112
  });
105
113
 
106
114
  case "webView":
107
- return createElement("iframe", { key, className, src: node.src });
115
+ return createElement("iframe", { key, id, className, src: node.src });
108
116
 
109
117
  case "toggle":
110
118
  return createElement(
111
119
  "button",
112
120
  {
113
121
  key,
122
+ id,
114
123
  className,
115
124
  type: "button",
116
125
  role: "switch",
@@ -122,7 +131,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
122
131
  case "checkbox":
123
132
  return createElement(
124
133
  "label",
125
- { key, className },
134
+ { key, id, className },
126
135
  createElement("input", {
127
136
  key: `${key}.input`,
128
137
  type: "checkbox",
@@ -135,6 +144,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
135
144
  case "slider":
136
145
  return createElement("input", {
137
146
  key,
147
+ id,
138
148
  className,
139
149
  type: "range",
140
150
  defaultValue: node.value,
@@ -147,6 +157,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
147
157
  case "progress":
148
158
  return createElement("progress", {
149
159
  key,
160
+ id,
150
161
  className,
151
162
  value: node.value,
152
163
  max: node.max,
@@ -155,6 +166,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
155
166
  case "meter":
156
167
  return createElement("meter", {
157
168
  key,
169
+ id,
158
170
  className,
159
171
  value: node.value,
160
172
  min: node.min,
@@ -164,6 +176,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
164
176
  case "input":
165
177
  return createElement(node.multiline ? "textarea" : "input", {
166
178
  key,
179
+ id,
167
180
  className,
168
181
  type: node.multiline ? undefined : node.secure ? "password" : "text",
169
182
  placeholder: node.placeholder,
@@ -173,7 +186,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
173
186
  case "picker":
174
187
  return createElement(
175
188
  "select",
176
- { key, className, name: node.bind },
189
+ { key, id, className, name: node.bind },
177
190
  ...node.options.map((option, i) =>
178
191
  createElement(
179
192
  "option",
@@ -186,7 +199,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
186
199
  case "filePicker":
187
200
  return createElement(
188
201
  "label",
189
- { key, className },
202
+ { key, id, className },
190
203
  createElement("input", {
191
204
  key: `${key}.input`,
192
205
  type: "file",
@@ -201,6 +214,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
201
214
  "span",
202
215
  {
203
216
  key,
217
+ id,
204
218
  className,
205
219
  "data-crepus-slot-rotate": node.phrases.join("|"),
206
220
  "data-interval-ms": node.intervalMs,
@@ -211,7 +225,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
211
225
  case "tabs":
212
226
  return createElement(
213
227
  "div",
214
- { key, className },
228
+ { key, id, className },
215
229
  createElement(
216
230
  "div",
217
231
  { key: `${key}.tablist`, role: "tablist" },
@@ -237,7 +251,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
237
251
  case "if":
238
252
  return createElement(
239
253
  "div",
240
- { key, className, "data-crepus-if": node.condition },
254
+ { key, id, className, "data-crepus-if": node.condition },
241
255
  ...renderChildren(node.thenChildren, key),
242
256
  );
243
257
 
@@ -246,6 +260,7 @@ export function renderCrepusNode(node: ViewNode, key: string): ReactNode {
246
260
  "div",
247
261
  {
248
262
  key,
263
+ id,
249
264
  className,
250
265
  "data-crepus-for-each": node.bind,
251
266
  "data-crepus-item": node.itemName,