@webstudio-is/react-sdk 0.216.0 → 0.218.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -179,233 +179,12 @@ var isAttributeNameSafe = (attributeName) => {
|
|
|
179
179
|
return false;
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
// src/embed-template.ts
|
|
183
|
-
import { nanoid } from "nanoid";
|
|
184
|
-
import {
|
|
185
|
-
encodeDataSourceVariable,
|
|
186
|
-
transpileExpression
|
|
187
|
-
} from "@webstudio-is/sdk";
|
|
188
|
-
var getVariablValue = (value) => {
|
|
189
|
-
if (typeof value === "string") {
|
|
190
|
-
return { type: "string", value };
|
|
191
|
-
}
|
|
192
|
-
if (typeof value === "number") {
|
|
193
|
-
return { type: "number", value };
|
|
194
|
-
}
|
|
195
|
-
if (typeof value === "boolean") {
|
|
196
|
-
return { type: "boolean", value };
|
|
197
|
-
}
|
|
198
|
-
if (Array.isArray(value)) {
|
|
199
|
-
return { type: "string[]", value };
|
|
200
|
-
}
|
|
201
|
-
return { type: "json", value };
|
|
202
|
-
};
|
|
203
|
-
var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByRef, styleSourceSelections, styleSources, styles, metas, defaultBreakpointId, generateId) => {
|
|
204
|
-
const parentChildren = [];
|
|
205
|
-
for (const item of treeTemplate) {
|
|
206
|
-
if (item.type === "instance") {
|
|
207
|
-
const instanceId = generateId();
|
|
208
|
-
if (item.variables) {
|
|
209
|
-
for (const [name, variable] of Object.entries(item.variables)) {
|
|
210
|
-
if (dataSourceByRef.has(name)) {
|
|
211
|
-
throw Error(`${name} data source already defined`);
|
|
212
|
-
}
|
|
213
|
-
dataSourceByRef.set(name, {
|
|
214
|
-
type: "variable",
|
|
215
|
-
id: generateId(),
|
|
216
|
-
scopeInstanceId: instanceId,
|
|
217
|
-
name: variable.alias ?? name,
|
|
218
|
-
value: getVariablValue(variable.initialValue)
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (item.props) {
|
|
223
|
-
for (const prop of item.props) {
|
|
224
|
-
const propId = generateId();
|
|
225
|
-
if (prop.type === "expression") {
|
|
226
|
-
props.push({
|
|
227
|
-
id: propId,
|
|
228
|
-
instanceId,
|
|
229
|
-
name: prop.name,
|
|
230
|
-
type: "expression",
|
|
231
|
-
// replace all references with variable names
|
|
232
|
-
value: transpileExpression({
|
|
233
|
-
expression: prop.code,
|
|
234
|
-
replaceVariable: (ref) => {
|
|
235
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
236
|
-
return encodeDataSourceVariable(id);
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
});
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (prop.type === "action") {
|
|
243
|
-
props.push({
|
|
244
|
-
id: propId,
|
|
245
|
-
instanceId,
|
|
246
|
-
type: "action",
|
|
247
|
-
name: prop.name,
|
|
248
|
-
value: prop.value.map((value) => {
|
|
249
|
-
const args = value.args ?? [];
|
|
250
|
-
return {
|
|
251
|
-
type: "execute",
|
|
252
|
-
args,
|
|
253
|
-
// replace all references with variable names
|
|
254
|
-
code: transpileExpression({
|
|
255
|
-
expression: value.code,
|
|
256
|
-
replaceVariable: (ref) => {
|
|
257
|
-
if (args.includes(ref)) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
261
|
-
return encodeDataSourceVariable(id);
|
|
262
|
-
}
|
|
263
|
-
})
|
|
264
|
-
};
|
|
265
|
-
})
|
|
266
|
-
});
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (prop.type === "parameter") {
|
|
270
|
-
const dataSourceId = generateId();
|
|
271
|
-
dataSourceByRef.set(prop.variableName, {
|
|
272
|
-
type: "parameter",
|
|
273
|
-
id: dataSourceId,
|
|
274
|
-
scopeInstanceId: instanceId,
|
|
275
|
-
name: prop.variableAlias ?? prop.variableName
|
|
276
|
-
});
|
|
277
|
-
props.push({
|
|
278
|
-
id: propId,
|
|
279
|
-
instanceId,
|
|
280
|
-
name: prop.name,
|
|
281
|
-
type: "parameter",
|
|
282
|
-
// replace variable reference with variable id
|
|
283
|
-
value: dataSourceId
|
|
284
|
-
});
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
props.push({ id: propId, instanceId, ...prop });
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
const styleSourceIds = [];
|
|
291
|
-
if (item.styles) {
|
|
292
|
-
const styleSourceId = generateId();
|
|
293
|
-
styleSources.push({
|
|
294
|
-
type: "local",
|
|
295
|
-
id: styleSourceId
|
|
296
|
-
});
|
|
297
|
-
styleSourceIds.push(styleSourceId);
|
|
298
|
-
for (const styleDecl of item.styles) {
|
|
299
|
-
styles.push({
|
|
300
|
-
breakpointId: defaultBreakpointId,
|
|
301
|
-
styleSourceId,
|
|
302
|
-
state: styleDecl.state,
|
|
303
|
-
property: styleDecl.property,
|
|
304
|
-
value: styleDecl.value
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (styleSourceIds.length > 0) {
|
|
309
|
-
styleSourceSelections.push({
|
|
310
|
-
instanceId,
|
|
311
|
-
values: styleSourceIds
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
const instance = {
|
|
315
|
-
type: "instance",
|
|
316
|
-
id: instanceId,
|
|
317
|
-
label: item.label,
|
|
318
|
-
component: item.component,
|
|
319
|
-
children: []
|
|
320
|
-
};
|
|
321
|
-
instances.push(instance);
|
|
322
|
-
instance.children = createInstancesFromTemplate(
|
|
323
|
-
item.children,
|
|
324
|
-
instances,
|
|
325
|
-
props,
|
|
326
|
-
dataSourceByRef,
|
|
327
|
-
styleSourceSelections,
|
|
328
|
-
styleSources,
|
|
329
|
-
styles,
|
|
330
|
-
metas,
|
|
331
|
-
defaultBreakpointId,
|
|
332
|
-
generateId
|
|
333
|
-
);
|
|
334
|
-
parentChildren.push({
|
|
335
|
-
type: "id",
|
|
336
|
-
value: instanceId
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
if (item.type === "text") {
|
|
340
|
-
parentChildren.push({
|
|
341
|
-
type: "text",
|
|
342
|
-
value: item.value,
|
|
343
|
-
placeholder: item.placeholder
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
if (item.type === "expression") {
|
|
347
|
-
parentChildren.push({
|
|
348
|
-
type: "expression",
|
|
349
|
-
// replace all references with variable names
|
|
350
|
-
value: transpileExpression({
|
|
351
|
-
expression: item.value,
|
|
352
|
-
replaceVariable: (ref) => {
|
|
353
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
354
|
-
return encodeDataSourceVariable(id);
|
|
355
|
-
}
|
|
356
|
-
})
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return parentChildren;
|
|
361
|
-
};
|
|
362
|
-
var generateDataFromEmbedTemplate = (treeTemplate, metas, generateId = nanoid) => {
|
|
363
|
-
const instances = [];
|
|
364
|
-
const props = [];
|
|
365
|
-
const dataSourceByRef = /* @__PURE__ */ new Map();
|
|
366
|
-
const styleSourceSelections = [];
|
|
367
|
-
const styleSources = [];
|
|
368
|
-
const styles = [];
|
|
369
|
-
const baseBreakpointId = generateId();
|
|
370
|
-
const children = createInstancesFromTemplate(
|
|
371
|
-
treeTemplate,
|
|
372
|
-
instances,
|
|
373
|
-
props,
|
|
374
|
-
dataSourceByRef,
|
|
375
|
-
styleSourceSelections,
|
|
376
|
-
styleSources,
|
|
377
|
-
styles,
|
|
378
|
-
metas,
|
|
379
|
-
baseBreakpointId,
|
|
380
|
-
generateId
|
|
381
|
-
);
|
|
382
|
-
const breakpoints = [];
|
|
383
|
-
if (styles.length > 0) {
|
|
384
|
-
breakpoints.push({
|
|
385
|
-
id: baseBreakpointId,
|
|
386
|
-
label: ""
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
return {
|
|
390
|
-
children,
|
|
391
|
-
instances,
|
|
392
|
-
props,
|
|
393
|
-
dataSources: Array.from(dataSourceByRef.values()),
|
|
394
|
-
styleSourceSelections,
|
|
395
|
-
styleSources,
|
|
396
|
-
styles,
|
|
397
|
-
breakpoints,
|
|
398
|
-
assets: [],
|
|
399
|
-
resources: []
|
|
400
|
-
};
|
|
401
|
-
};
|
|
402
|
-
|
|
403
182
|
// src/component-generator.ts
|
|
404
183
|
import {
|
|
405
184
|
parseComponentName,
|
|
406
185
|
generateExpression,
|
|
407
186
|
decodeDataSourceVariable,
|
|
408
|
-
transpileExpression
|
|
187
|
+
transpileExpression,
|
|
409
188
|
blockComponent,
|
|
410
189
|
blockTemplateComponent,
|
|
411
190
|
collectionComponent,
|
|
@@ -910,7 +689,9 @@ var standardAttributesToReactProps = {
|
|
|
910
689
|
y: "y",
|
|
911
690
|
ychannelselector: "yChannelSelector",
|
|
912
691
|
z: "z",
|
|
913
|
-
zoomandpan: "zoomAndPan"
|
|
692
|
+
zoomandpan: "zoomAndPan",
|
|
693
|
+
// added by us
|
|
694
|
+
dirname: "dirName"
|
|
914
695
|
};
|
|
915
696
|
|
|
916
697
|
// src/component-generator.ts
|
|
@@ -925,7 +706,7 @@ var generateAction = ({
|
|
|
925
706
|
let assignersCode = "";
|
|
926
707
|
for (const value of prop.value) {
|
|
927
708
|
args = value.args;
|
|
928
|
-
assignersCode +=
|
|
709
|
+
assignersCode += transpileExpression({
|
|
929
710
|
expression: value.code,
|
|
930
711
|
executable: true,
|
|
931
712
|
replaceVariable: (identifier, assignee) => {
|
|
@@ -1319,7 +1100,6 @@ export {
|
|
|
1319
1100
|
animationCanPlayOnCanvasAttribute,
|
|
1320
1101
|
collapsedAttribute,
|
|
1321
1102
|
componentAttribute,
|
|
1322
|
-
generateDataFromEmbedTemplate,
|
|
1323
1103
|
generateJsxChildren,
|
|
1324
1104
|
generateJsxElement,
|
|
1325
1105
|
generateRemixParams,
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.218.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type-fest": "^4.37.0",
|
|
15
15
|
"vitest": "^3.0.8",
|
|
16
16
|
"zod": "^3.24.2",
|
|
17
|
-
"@webstudio-is/template": "0.
|
|
17
|
+
"@webstudio-is/template": "0.218.0",
|
|
18
18
|
"@webstudio-is/tsconfig": "1.0.7"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"change-case": "^5.4.4",
|
|
27
27
|
"html-tags": "^4.0.0",
|
|
28
|
-
"nanoid": "^5.
|
|
29
|
-
"@webstudio-is/
|
|
30
|
-
"@webstudio-is/
|
|
31
|
-
"@webstudio-is/
|
|
32
|
-
"@webstudio-is/sdk": "0.
|
|
33
|
-
"@webstudio-is/image": "0.
|
|
28
|
+
"nanoid": "^5.1.5",
|
|
29
|
+
"@webstudio-is/fonts": "0.218.0",
|
|
30
|
+
"@webstudio-is/icons": "^0.218.0",
|
|
31
|
+
"@webstudio-is/css-engine": "0.218.0",
|
|
32
|
+
"@webstudio-is/sdk": "0.218.0",
|
|
33
|
+
"@webstudio-is/image": "0.218.0"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { Instance, WebstudioFragment, WsEmbedTemplate, WsComponentMeta } from "@webstudio-is/sdk";
|
|
2
|
-
export declare const generateDataFromEmbedTemplate: (treeTemplate: WsEmbedTemplate, metas: Map<Instance["component"], WsComponentMeta>, generateId?: () => string) => WebstudioFragment;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|