@webstudio-is/react-sdk 0.0.0-588fe22 → 0.0.0-73cd6ea
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 +304 -554
- package/lib/runtime.js +15 -7
- package/lib/types/__generated__/standard-attributes.d.ts +2 -0
- package/lib/types/component-generator.d.ts +16 -6
- package/lib/types/context.d.ts +8 -1
- package/lib/types/hook.d.ts +2 -2
- package/lib/types/index.d.ts +1 -3
- package/lib/types/page-settings-meta.d.ts +2 -1
- package/lib/types/props.d.ts +1337 -8
- package/lib/types/runtime.d.ts +0 -1
- package/package.json +11 -11
- package/placeholder.d.ts +16 -12
- package/lib/types/css/css.d.ts +0 -20
- package/lib/types/css/css.test.d.ts +0 -1
- package/lib/types/css/global-rules.d.ts +0 -6
- package/lib/types/css/index.d.ts +0 -2
- package/lib/types/embed-template.d.ts +0 -54
- package/lib/types/embed-template.test.d.ts +0 -1
- package/lib/types/instance-utils.d.ts +0 -3
- package/lib/types/instance-utils.test.d.ts +0 -1
package/lib/index.js
CHANGED
|
@@ -54,178 +54,6 @@ var generateRemixParams = (pathname) => {
|
|
|
54
54
|
return generated;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
// src/css/global-rules.ts
|
|
58
|
-
import { getFontFaces } from "@webstudio-is/fonts";
|
|
59
|
-
var addGlobalRules = (sheet, { assets, assetBaseUrl }) => {
|
|
60
|
-
const fontAssets = [];
|
|
61
|
-
for (const asset of assets.values()) {
|
|
62
|
-
if (asset.type === "font") {
|
|
63
|
-
fontAssets.push(asset);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
|
|
67
|
-
for (const fontFace of fontFaces) {
|
|
68
|
-
sheet.addFontFaceRule(fontFace);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// src/css/css.ts
|
|
73
|
-
import {
|
|
74
|
-
createRegularStyleSheet,
|
|
75
|
-
generateAtomic
|
|
76
|
-
} from "@webstudio-is/css-engine";
|
|
77
|
-
import {
|
|
78
|
-
ROOT_INSTANCE_ID,
|
|
79
|
-
createScope,
|
|
80
|
-
parseComponentName,
|
|
81
|
-
descendantComponent,
|
|
82
|
-
rootComponent
|
|
83
|
-
} from "@webstudio-is/sdk";
|
|
84
|
-
import { kebabCase } from "change-case";
|
|
85
|
-
var createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
|
|
86
|
-
if (styleValue.type === "image" && styleValue.value.type === "asset") {
|
|
87
|
-
const asset = assets.get(styleValue.value.value);
|
|
88
|
-
if (asset === void 0) {
|
|
89
|
-
return { type: "keyword", value: "none" };
|
|
90
|
-
}
|
|
91
|
-
const url = `${assetBaseUrl}${asset.name}`;
|
|
92
|
-
return {
|
|
93
|
-
type: "image",
|
|
94
|
-
value: {
|
|
95
|
-
type: "url",
|
|
96
|
-
url
|
|
97
|
-
},
|
|
98
|
-
hidden: styleValue.hidden
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var normalizeClassName = (name) => kebabCase(name);
|
|
103
|
-
var generateCss = ({
|
|
104
|
-
assets,
|
|
105
|
-
instances,
|
|
106
|
-
props,
|
|
107
|
-
breakpoints,
|
|
108
|
-
styles,
|
|
109
|
-
styleSourceSelections,
|
|
110
|
-
componentMetas,
|
|
111
|
-
assetBaseUrl,
|
|
112
|
-
atomic
|
|
113
|
-
}) => {
|
|
114
|
-
const globalSheet = createRegularStyleSheet({ name: "ssr" });
|
|
115
|
-
const sheet = createRegularStyleSheet({ name: "ssr" });
|
|
116
|
-
addGlobalRules(globalSheet, { assets, assetBaseUrl });
|
|
117
|
-
globalSheet.addMediaRule("presets");
|
|
118
|
-
const presetClasses = /* @__PURE__ */ new Map();
|
|
119
|
-
const scope = createScope([], normalizeClassName, "-");
|
|
120
|
-
for (const [component, meta] of componentMetas) {
|
|
121
|
-
const [_namespace, componentName] = parseComponentName(component);
|
|
122
|
-
const className = `w-${scope.getName(component, meta.label ?? componentName)}`;
|
|
123
|
-
const presetStyle = Object.entries(meta.presetStyle ?? {});
|
|
124
|
-
if (presetStyle.length > 0) {
|
|
125
|
-
presetClasses.set(component, className);
|
|
126
|
-
}
|
|
127
|
-
for (const [tag, styles2] of presetStyle) {
|
|
128
|
-
const selector = component === rootComponent ? ":root" : `:where(${tag}.${className})`;
|
|
129
|
-
const rule = globalSheet.addNestingRule(selector);
|
|
130
|
-
for (const declaration of styles2) {
|
|
131
|
-
rule.setDeclaration({
|
|
132
|
-
breakpoint: "presets",
|
|
133
|
-
selector: declaration.state ?? "",
|
|
134
|
-
property: declaration.property,
|
|
135
|
-
value: declaration.value
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
for (const breakpoint of breakpoints.values()) {
|
|
141
|
-
sheet.addMediaRule(breakpoint.id, breakpoint);
|
|
142
|
-
}
|
|
143
|
-
const imageValueTransformer = createImageValueTransformer(assets, {
|
|
144
|
-
assetBaseUrl
|
|
145
|
-
});
|
|
146
|
-
sheet.setTransformer(imageValueTransformer);
|
|
147
|
-
for (const styleDecl of styles.values()) {
|
|
148
|
-
const rule = sheet.addMixinRule(styleDecl.styleSourceId);
|
|
149
|
-
rule.setDeclaration({
|
|
150
|
-
breakpoint: styleDecl.breakpointId,
|
|
151
|
-
selector: styleDecl.state ?? "",
|
|
152
|
-
property: styleDecl.property,
|
|
153
|
-
value: styleDecl.value
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
const classes = /* @__PURE__ */ new Map();
|
|
157
|
-
const parentIdByInstanceId = /* @__PURE__ */ new Map();
|
|
158
|
-
for (const instance of instances.values()) {
|
|
159
|
-
const presetClass = presetClasses.get(instance.component);
|
|
160
|
-
if (presetClass) {
|
|
161
|
-
classes.set(instance.id, [presetClass]);
|
|
162
|
-
}
|
|
163
|
-
for (const child of instance.children) {
|
|
164
|
-
if (child.type === "id") {
|
|
165
|
-
parentIdByInstanceId.set(child.value, instance.id);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
|
|
170
|
-
for (const prop of props.values()) {
|
|
171
|
-
if (prop.name === "selector" && prop.type === "string") {
|
|
172
|
-
descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const instanceByRule = /* @__PURE__ */ new Map();
|
|
176
|
-
for (const selection of styleSourceSelections.values()) {
|
|
177
|
-
let { instanceId } = selection;
|
|
178
|
-
const { values } = selection;
|
|
179
|
-
if (instanceId === ROOT_INSTANCE_ID) {
|
|
180
|
-
const rule2 = sheet.addNestingRule(`:root`);
|
|
181
|
-
rule2.applyMixins(values);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
let descendantSuffix = "";
|
|
185
|
-
const instance = instances.get(instanceId);
|
|
186
|
-
if (instance === void 0) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (instance.component === descendantComponent) {
|
|
190
|
-
const parentId = parentIdByInstanceId.get(instanceId);
|
|
191
|
-
const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
|
|
192
|
-
if (parentId && descendantSelector) {
|
|
193
|
-
descendantSuffix = descendantSelector;
|
|
194
|
-
instanceId = parentId;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const meta = componentMetas.get(instance.component);
|
|
198
|
-
const [_namespace, shortName] = parseComponentName(instance.component);
|
|
199
|
-
const baseName = instance.label ?? meta?.label ?? shortName;
|
|
200
|
-
const className = `w-${scope.getName(instanceId, baseName)}`;
|
|
201
|
-
if (atomic === false) {
|
|
202
|
-
let classList = classes.get(instanceId);
|
|
203
|
-
if (classList === void 0) {
|
|
204
|
-
classList = [];
|
|
205
|
-
classes.set(instanceId, classList);
|
|
206
|
-
}
|
|
207
|
-
classList.push(className);
|
|
208
|
-
}
|
|
209
|
-
const rule = sheet.addNestingRule(`.${className}`, descendantSuffix);
|
|
210
|
-
rule.applyMixins(values);
|
|
211
|
-
instanceByRule.set(rule, instanceId);
|
|
212
|
-
}
|
|
213
|
-
if (atomic) {
|
|
214
|
-
const { cssText } = generateAtomic(sheet, {
|
|
215
|
-
getKey: (rule) => instanceByRule.get(rule),
|
|
216
|
-
transformValue: imageValueTransformer,
|
|
217
|
-
classes
|
|
218
|
-
});
|
|
219
|
-
return { cssText: `${globalSheet.cssText}
|
|
220
|
-
${cssText}`, classes };
|
|
221
|
-
}
|
|
222
|
-
return {
|
|
223
|
-
cssText: `${globalSheet.cssText}
|
|
224
|
-
${sheet.cssText}`,
|
|
225
|
-
classes
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
|
|
229
57
|
// src/props.ts
|
|
230
58
|
import {
|
|
231
59
|
getPagePath,
|
|
@@ -325,11 +153,8 @@ var idAttribute = "data-ws-id";
|
|
|
325
153
|
var selectorIdAttribute = "data-ws-selector";
|
|
326
154
|
var componentAttribute = "data-ws-component";
|
|
327
155
|
var showAttribute = "data-ws-show";
|
|
328
|
-
var indexAttribute = "data-ws-index";
|
|
329
156
|
var collapsedAttribute = "data-ws-collapsed";
|
|
330
157
|
var textContentAttribute = "data-ws-text-content";
|
|
331
|
-
var editablePlaceholderVariable = "--data-ws-editable-placeholder";
|
|
332
|
-
var editingPlaceholderVariable = "--data-ws-editing-placeholder";
|
|
333
158
|
var attributeNameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
|
334
159
|
var attributeNameChar = attributeNameStartChar + ":\\-0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
|
335
160
|
var validAttributeNameRegex = new RegExp(
|
|
@@ -353,349 +178,240 @@ var isAttributeNameSafe = (attributeName) => {
|
|
|
353
178
|
return false;
|
|
354
179
|
};
|
|
355
180
|
|
|
356
|
-
// src/embed-template.ts
|
|
357
|
-
import { nanoid } from "nanoid";
|
|
358
|
-
import {
|
|
359
|
-
encodeDataSourceVariable,
|
|
360
|
-
transpileExpression
|
|
361
|
-
} from "@webstudio-is/sdk";
|
|
362
|
-
var getVariablValue = (value) => {
|
|
363
|
-
if (typeof value === "string") {
|
|
364
|
-
return { type: "string", value };
|
|
365
|
-
}
|
|
366
|
-
if (typeof value === "number") {
|
|
367
|
-
return { type: "number", value };
|
|
368
|
-
}
|
|
369
|
-
if (typeof value === "boolean") {
|
|
370
|
-
return { type: "boolean", value };
|
|
371
|
-
}
|
|
372
|
-
if (Array.isArray(value)) {
|
|
373
|
-
return { type: "string[]", value };
|
|
374
|
-
}
|
|
375
|
-
return { type: "json", value };
|
|
376
|
-
};
|
|
377
|
-
var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByRef, styleSourceSelections, styleSources, styles, metas, defaultBreakpointId, generateId) => {
|
|
378
|
-
const parentChildren = [];
|
|
379
|
-
for (const item of treeTemplate) {
|
|
380
|
-
if (item.type === "instance") {
|
|
381
|
-
const instanceId = generateId();
|
|
382
|
-
if (item.variables) {
|
|
383
|
-
for (const [name, variable] of Object.entries(item.variables)) {
|
|
384
|
-
if (dataSourceByRef.has(name)) {
|
|
385
|
-
throw Error(`${name} data source already defined`);
|
|
386
|
-
}
|
|
387
|
-
dataSourceByRef.set(name, {
|
|
388
|
-
type: "variable",
|
|
389
|
-
id: generateId(),
|
|
390
|
-
scopeInstanceId: instanceId,
|
|
391
|
-
name: variable.alias ?? name,
|
|
392
|
-
value: getVariablValue(variable.initialValue)
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (item.props) {
|
|
397
|
-
for (const prop of item.props) {
|
|
398
|
-
const propId = generateId();
|
|
399
|
-
if (prop.type === "expression") {
|
|
400
|
-
props.push({
|
|
401
|
-
id: propId,
|
|
402
|
-
instanceId,
|
|
403
|
-
name: prop.name,
|
|
404
|
-
type: "expression",
|
|
405
|
-
// replace all references with variable names
|
|
406
|
-
value: transpileExpression({
|
|
407
|
-
expression: prop.code,
|
|
408
|
-
replaceVariable: (ref) => {
|
|
409
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
410
|
-
return encodeDataSourceVariable(id);
|
|
411
|
-
}
|
|
412
|
-
})
|
|
413
|
-
});
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
if (prop.type === "action") {
|
|
417
|
-
props.push({
|
|
418
|
-
id: propId,
|
|
419
|
-
instanceId,
|
|
420
|
-
type: "action",
|
|
421
|
-
name: prop.name,
|
|
422
|
-
value: prop.value.map((value) => {
|
|
423
|
-
const args = value.args ?? [];
|
|
424
|
-
return {
|
|
425
|
-
type: "execute",
|
|
426
|
-
args,
|
|
427
|
-
// replace all references with variable names
|
|
428
|
-
code: transpileExpression({
|
|
429
|
-
expression: value.code,
|
|
430
|
-
replaceVariable: (ref) => {
|
|
431
|
-
if (args.includes(ref)) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
435
|
-
return encodeDataSourceVariable(id);
|
|
436
|
-
}
|
|
437
|
-
})
|
|
438
|
-
};
|
|
439
|
-
})
|
|
440
|
-
});
|
|
441
|
-
continue;
|
|
442
|
-
}
|
|
443
|
-
if (prop.type === "parameter") {
|
|
444
|
-
const dataSourceId = generateId();
|
|
445
|
-
dataSourceByRef.set(prop.variableName, {
|
|
446
|
-
type: "parameter",
|
|
447
|
-
id: dataSourceId,
|
|
448
|
-
scopeInstanceId: instanceId,
|
|
449
|
-
name: prop.variableAlias ?? prop.variableName
|
|
450
|
-
});
|
|
451
|
-
props.push({
|
|
452
|
-
id: propId,
|
|
453
|
-
instanceId,
|
|
454
|
-
name: prop.name,
|
|
455
|
-
type: "parameter",
|
|
456
|
-
// replace variable reference with variable id
|
|
457
|
-
value: dataSourceId
|
|
458
|
-
});
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
props.push({ id: propId, instanceId, ...prop });
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
const styleSourceIds = [];
|
|
465
|
-
if (item.styles) {
|
|
466
|
-
const styleSourceId = generateId();
|
|
467
|
-
styleSources.push({
|
|
468
|
-
type: "local",
|
|
469
|
-
id: styleSourceId
|
|
470
|
-
});
|
|
471
|
-
styleSourceIds.push(styleSourceId);
|
|
472
|
-
for (const styleDecl of item.styles) {
|
|
473
|
-
styles.push({
|
|
474
|
-
breakpointId: defaultBreakpointId,
|
|
475
|
-
styleSourceId,
|
|
476
|
-
state: styleDecl.state,
|
|
477
|
-
property: styleDecl.property,
|
|
478
|
-
value: styleDecl.value
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (styleSourceIds.length > 0) {
|
|
483
|
-
styleSourceSelections.push({
|
|
484
|
-
instanceId,
|
|
485
|
-
values: styleSourceIds
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
const instance = {
|
|
489
|
-
type: "instance",
|
|
490
|
-
id: instanceId,
|
|
491
|
-
label: item.label,
|
|
492
|
-
component: item.component,
|
|
493
|
-
children: []
|
|
494
|
-
};
|
|
495
|
-
instances.push(instance);
|
|
496
|
-
instance.children = createInstancesFromTemplate(
|
|
497
|
-
item.children,
|
|
498
|
-
instances,
|
|
499
|
-
props,
|
|
500
|
-
dataSourceByRef,
|
|
501
|
-
styleSourceSelections,
|
|
502
|
-
styleSources,
|
|
503
|
-
styles,
|
|
504
|
-
metas,
|
|
505
|
-
defaultBreakpointId,
|
|
506
|
-
generateId
|
|
507
|
-
);
|
|
508
|
-
parentChildren.push({
|
|
509
|
-
type: "id",
|
|
510
|
-
value: instanceId
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
if (item.type === "text") {
|
|
514
|
-
parentChildren.push({
|
|
515
|
-
type: "text",
|
|
516
|
-
value: item.value,
|
|
517
|
-
placeholder: item.placeholder
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
if (item.type === "expression") {
|
|
521
|
-
parentChildren.push({
|
|
522
|
-
type: "expression",
|
|
523
|
-
// replace all references with variable names
|
|
524
|
-
value: transpileExpression({
|
|
525
|
-
expression: item.value,
|
|
526
|
-
replaceVariable: (ref) => {
|
|
527
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
528
|
-
return encodeDataSourceVariable(id);
|
|
529
|
-
}
|
|
530
|
-
})
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
return parentChildren;
|
|
535
|
-
};
|
|
536
|
-
var generateDataFromEmbedTemplate = (treeTemplate, metas, generateId = nanoid) => {
|
|
537
|
-
const instances = [];
|
|
538
|
-
const props = [];
|
|
539
|
-
const dataSourceByRef = /* @__PURE__ */ new Map();
|
|
540
|
-
const styleSourceSelections = [];
|
|
541
|
-
const styleSources = [];
|
|
542
|
-
const styles = [];
|
|
543
|
-
const baseBreakpointId = generateId();
|
|
544
|
-
const children = createInstancesFromTemplate(
|
|
545
|
-
treeTemplate,
|
|
546
|
-
instances,
|
|
547
|
-
props,
|
|
548
|
-
dataSourceByRef,
|
|
549
|
-
styleSourceSelections,
|
|
550
|
-
styleSources,
|
|
551
|
-
styles,
|
|
552
|
-
metas,
|
|
553
|
-
baseBreakpointId,
|
|
554
|
-
generateId
|
|
555
|
-
);
|
|
556
|
-
const breakpoints = [];
|
|
557
|
-
if (styles.length > 0) {
|
|
558
|
-
breakpoints.push({
|
|
559
|
-
id: baseBreakpointId,
|
|
560
|
-
label: ""
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
return {
|
|
564
|
-
children,
|
|
565
|
-
instances,
|
|
566
|
-
props,
|
|
567
|
-
dataSources: Array.from(dataSourceByRef.values()),
|
|
568
|
-
styleSourceSelections,
|
|
569
|
-
styleSources,
|
|
570
|
-
styles,
|
|
571
|
-
breakpoints,
|
|
572
|
-
assets: [],
|
|
573
|
-
resources: []
|
|
574
|
-
};
|
|
575
|
-
};
|
|
576
|
-
var namespaceEmbedTemplateComponents = (template, namespace, components) => {
|
|
577
|
-
return template.map((item) => {
|
|
578
|
-
if (item.type === "text") {
|
|
579
|
-
return item;
|
|
580
|
-
}
|
|
581
|
-
if (item.type === "expression") {
|
|
582
|
-
return item;
|
|
583
|
-
}
|
|
584
|
-
if (item.type === "instance") {
|
|
585
|
-
const prefix = components.has(item.component) ? `${namespace}:` : "";
|
|
586
|
-
return {
|
|
587
|
-
...item,
|
|
588
|
-
component: `${prefix}${item.component}`,
|
|
589
|
-
children: namespaceEmbedTemplateComponents(
|
|
590
|
-
item.children,
|
|
591
|
-
namespace,
|
|
592
|
-
components
|
|
593
|
-
)
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
item;
|
|
597
|
-
throw Error("Impossible case");
|
|
598
|
-
});
|
|
599
|
-
};
|
|
600
|
-
var namespaceMatcher = (namespace, matcher) => {
|
|
601
|
-
const newMatcher = structuredClone(matcher);
|
|
602
|
-
if (newMatcher.component?.$eq) {
|
|
603
|
-
newMatcher.component.$eq = `${namespace}:${newMatcher.component.$eq}`;
|
|
604
|
-
}
|
|
605
|
-
if (newMatcher.component?.$neq) {
|
|
606
|
-
newMatcher.component.$neq = `${namespace}:${newMatcher.component.$neq}`;
|
|
607
|
-
}
|
|
608
|
-
if (newMatcher.component?.$in) {
|
|
609
|
-
newMatcher.component.$in = newMatcher.component.$in.map(
|
|
610
|
-
(component) => `${namespace}:${component}`
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
if (newMatcher.component?.$nin) {
|
|
614
|
-
newMatcher.component.$nin = newMatcher.component.$nin.map(
|
|
615
|
-
(component) => `${namespace}:${component}`
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
return newMatcher;
|
|
619
|
-
};
|
|
620
|
-
var namespaceMeta = (meta, namespace, components) => {
|
|
621
|
-
const newMeta = { ...meta };
|
|
622
|
-
if (newMeta.constraints) {
|
|
623
|
-
if (Array.isArray(newMeta.constraints)) {
|
|
624
|
-
newMeta.constraints = newMeta.constraints.map(
|
|
625
|
-
(matcher) => namespaceMatcher(namespace, matcher)
|
|
626
|
-
);
|
|
627
|
-
} else {
|
|
628
|
-
newMeta.constraints = namespaceMatcher(namespace, newMeta.constraints);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
if (newMeta.indexWithinAncestor) {
|
|
632
|
-
newMeta.indexWithinAncestor = components.has(newMeta.indexWithinAncestor) ? `${namespace}:${newMeta.indexWithinAncestor}` : newMeta.indexWithinAncestor;
|
|
633
|
-
}
|
|
634
|
-
if (newMeta.template) {
|
|
635
|
-
newMeta.template = namespaceEmbedTemplateComponents(
|
|
636
|
-
newMeta.template,
|
|
637
|
-
namespace,
|
|
638
|
-
components
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
return newMeta;
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
// src/instance-utils.ts
|
|
645
|
-
var getIndexesWithinAncestors = (metas, instances, rootIds) => {
|
|
646
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
647
|
-
for (const meta of metas.values()) {
|
|
648
|
-
if (meta.indexWithinAncestor !== void 0) {
|
|
649
|
-
ancestors.add(meta.indexWithinAncestor);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
const indexes = /* @__PURE__ */ new Map();
|
|
653
|
-
const traverseInstances = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
|
|
654
|
-
const instance = instances2.get(instanceId);
|
|
655
|
-
if (instance === void 0) {
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
const meta = metas.get(instance.component);
|
|
659
|
-
if (meta === void 0) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
if (ancestors.has(instance.component)) {
|
|
663
|
-
latestIndexes2 = new Map(latestIndexes2);
|
|
664
|
-
latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
|
|
665
|
-
}
|
|
666
|
-
if (meta.indexWithinAncestor !== void 0) {
|
|
667
|
-
const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
|
|
668
|
-
if (ancestorIndexes !== void 0) {
|
|
669
|
-
let index = ancestorIndexes.get(instance.component) ?? -1;
|
|
670
|
-
index += 1;
|
|
671
|
-
ancestorIndexes.set(instance.component, index);
|
|
672
|
-
indexes.set(instance.id, index);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
for (const child of instance.children) {
|
|
676
|
-
if (child.type === "id") {
|
|
677
|
-
traverseInstances(instances2, child.value, latestIndexes2);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
const latestIndexes = /* @__PURE__ */ new Map();
|
|
682
|
-
for (const instanceId of rootIds) {
|
|
683
|
-
traverseInstances(instances, instanceId, latestIndexes);
|
|
684
|
-
}
|
|
685
|
-
return indexes;
|
|
686
|
-
};
|
|
687
|
-
|
|
688
181
|
// src/component-generator.ts
|
|
689
182
|
import {
|
|
690
|
-
parseComponentName
|
|
183
|
+
parseComponentName,
|
|
691
184
|
generateExpression,
|
|
692
185
|
decodeDataSourceVariable,
|
|
693
|
-
transpileExpression
|
|
186
|
+
transpileExpression,
|
|
694
187
|
blockComponent,
|
|
695
188
|
blockTemplateComponent,
|
|
696
189
|
collectionComponent,
|
|
697
|
-
descendantComponent
|
|
190
|
+
descendantComponent,
|
|
191
|
+
getIndexesWithinAncestors,
|
|
192
|
+
elementComponent
|
|
698
193
|
} from "@webstudio-is/sdk";
|
|
194
|
+
import { indexProperty, tagProperty } from "@webstudio-is/sdk/runtime";
|
|
195
|
+
|
|
196
|
+
// src/__generated__/standard-attributes.ts
|
|
197
|
+
var standardAttributesToReactProps = {
|
|
198
|
+
"accept-charset": "acceptCharset",
|
|
199
|
+
accesskey: "accessKey",
|
|
200
|
+
allowfullscreen: "allowFullScreen",
|
|
201
|
+
autocapitalize: "autoCapitalize",
|
|
202
|
+
autocomplete: "autoComplete",
|
|
203
|
+
autocorrect: "autoCorrect",
|
|
204
|
+
autofocus: "autoFocus",
|
|
205
|
+
autoplay: "autoPlay",
|
|
206
|
+
charset: "charSet",
|
|
207
|
+
class: "className",
|
|
208
|
+
colspan: "colSpan",
|
|
209
|
+
contenteditable: "contentEditable",
|
|
210
|
+
crossorigin: "crossOrigin",
|
|
211
|
+
datetime: "dateTime",
|
|
212
|
+
enctype: "encType",
|
|
213
|
+
enterkeyhint: "enterKeyHint",
|
|
214
|
+
fetchpriority: "fetchPriority",
|
|
215
|
+
for: "htmlFor",
|
|
216
|
+
formmethod: "formMethod",
|
|
217
|
+
formaction: "formAction",
|
|
218
|
+
formenctype: "formEncType",
|
|
219
|
+
formnovalidate: "formNoValidate",
|
|
220
|
+
formtarget: "formTarget",
|
|
221
|
+
hreflang: "hrefLang",
|
|
222
|
+
"http-equiv": "httpEquiv",
|
|
223
|
+
imagesizes: "imageSizes",
|
|
224
|
+
imagesrcset: "imageSrcSet",
|
|
225
|
+
inputmode: "inputMode",
|
|
226
|
+
itemid: "itemID",
|
|
227
|
+
itemprop: "itemProp",
|
|
228
|
+
itemref: "itemRef",
|
|
229
|
+
itemscope: "itemScope",
|
|
230
|
+
itemtype: "itemType",
|
|
231
|
+
maxlength: "maxLength",
|
|
232
|
+
minlength: "minLength",
|
|
233
|
+
nomodule: "noModule",
|
|
234
|
+
novalidate: "noValidate",
|
|
235
|
+
playsinline: "playsInline",
|
|
236
|
+
readonly: "readOnly",
|
|
237
|
+
referrerpolicy: "referrerPolicy",
|
|
238
|
+
rowspan: "rowSpan",
|
|
239
|
+
spellcheck: "spellCheck",
|
|
240
|
+
srcdoc: "srcDoc",
|
|
241
|
+
srclang: "srcLang",
|
|
242
|
+
srcset: "srcSet",
|
|
243
|
+
tabindex: "tabIndex",
|
|
244
|
+
usemap: "useMap",
|
|
245
|
+
"alignment-baseline": "alignmentBaseline",
|
|
246
|
+
"baseline-shift": "baselineShift",
|
|
247
|
+
"clip-path": "clipPath",
|
|
248
|
+
"clip-rule": "clipRule",
|
|
249
|
+
"color-interpolation": "colorInterpolation",
|
|
250
|
+
"color-interpolation-filters": "colorInterpolationFilters",
|
|
251
|
+
"color-profile": "colorProfile",
|
|
252
|
+
"color-rendering": "colorRendering",
|
|
253
|
+
"dominant-baseline": "dominantBaseline",
|
|
254
|
+
"enable-background": "enableBackground",
|
|
255
|
+
"fill-opacity": "fillOpacity",
|
|
256
|
+
"fill-rule": "fillRule",
|
|
257
|
+
"flood-opacity": "floodOpacity",
|
|
258
|
+
"flood-color": "floodColor",
|
|
259
|
+
"font-family": "fontFamily",
|
|
260
|
+
"font-size": "fontSize",
|
|
261
|
+
"font-size-adjust": "fontSizeAdjust",
|
|
262
|
+
"font-stretch": "fontStretch",
|
|
263
|
+
"font-style": "fontStyle",
|
|
264
|
+
"font-variant": "fontVariant",
|
|
265
|
+
"font-weight": "fontWeight",
|
|
266
|
+
"glyph-orientation-horizontal": "glyphOrientationHorizontal",
|
|
267
|
+
"glyph-orientation-vertical": "glyphOrientationVertical",
|
|
268
|
+
"image-rendering": "imageRendering",
|
|
269
|
+
"letter-spacing": "letterSpacing",
|
|
270
|
+
"lighting-color": "lightingColor",
|
|
271
|
+
"marker-end": "markerEnd",
|
|
272
|
+
"marker-mid": "markerMid",
|
|
273
|
+
"marker-start": "markerStart",
|
|
274
|
+
"pointer-events": "pointerEvents",
|
|
275
|
+
popovertarget: "popoverTarget",
|
|
276
|
+
popovertargetaction: "popoverTargetAction",
|
|
277
|
+
"shape-rendering": "shapeRendering",
|
|
278
|
+
"stop-color": "stopColor",
|
|
279
|
+
"stop-opacity": "stopOpacity",
|
|
280
|
+
"stroke-dasharray": "strokeDasharray",
|
|
281
|
+
"stroke-dashoffset": "strokeDashoffset",
|
|
282
|
+
"stroke-linecap": "strokeLinecap",
|
|
283
|
+
"stroke-linejoin": "strokeLinejoin",
|
|
284
|
+
"stroke-miterlimit": "strokeMiterlimit",
|
|
285
|
+
"stroke-width": "strokeWidth",
|
|
286
|
+
"stroke-opacity": "strokeOpacity",
|
|
287
|
+
"text-anchor": "textAnchor",
|
|
288
|
+
"text-decoration": "textDecoration",
|
|
289
|
+
"text-rendering": "textRendering",
|
|
290
|
+
"unicode-bidi": "unicodeBidi",
|
|
291
|
+
"word-spacing": "wordSpacing",
|
|
292
|
+
"writing-mode": "writingMode",
|
|
293
|
+
"xlink:actuate": "xlinkActuate",
|
|
294
|
+
"xlink:arcrole": "xlinkArcrole",
|
|
295
|
+
"xlink:href": "xlinkHref",
|
|
296
|
+
"xlink:role": "xlinkRole",
|
|
297
|
+
"xlink:show": "xlinkShow",
|
|
298
|
+
"xlink:title": "xlinkTitle",
|
|
299
|
+
"xlink:type": "xlinkType",
|
|
300
|
+
"xml:base": "xmlBase",
|
|
301
|
+
"xml:lang": "xmlLang",
|
|
302
|
+
"xml:space": "xmlSpace",
|
|
303
|
+
dirname: "dirName"
|
|
304
|
+
};
|
|
305
|
+
var reactPropsToStandardAttributes = {
|
|
306
|
+
acceptCharset: "accept-charset",
|
|
307
|
+
accessKey: "accesskey",
|
|
308
|
+
allowFullScreen: "allowfullscreen",
|
|
309
|
+
autoCapitalize: "autocapitalize",
|
|
310
|
+
autoComplete: "autocomplete",
|
|
311
|
+
autoCorrect: "autocorrect",
|
|
312
|
+
autoFocus: "autofocus",
|
|
313
|
+
autoPlay: "autoplay",
|
|
314
|
+
charSet: "charset",
|
|
315
|
+
className: "class",
|
|
316
|
+
colSpan: "colspan",
|
|
317
|
+
contentEditable: "contenteditable",
|
|
318
|
+
crossOrigin: "crossorigin",
|
|
319
|
+
dateTime: "datetime",
|
|
320
|
+
encType: "enctype",
|
|
321
|
+
enterKeyHint: "enterkeyhint",
|
|
322
|
+
fetchPriority: "fetchpriority",
|
|
323
|
+
htmlFor: "for",
|
|
324
|
+
formMethod: "formmethod",
|
|
325
|
+
formAction: "formaction",
|
|
326
|
+
formEncType: "formenctype",
|
|
327
|
+
formNoValidate: "formnovalidate",
|
|
328
|
+
formTarget: "formtarget",
|
|
329
|
+
hrefLang: "hreflang",
|
|
330
|
+
httpEquiv: "http-equiv",
|
|
331
|
+
imageSizes: "imagesizes",
|
|
332
|
+
imageSrcSet: "imagesrcset",
|
|
333
|
+
inputMode: "inputmode",
|
|
334
|
+
itemID: "itemid",
|
|
335
|
+
itemProp: "itemprop",
|
|
336
|
+
itemRef: "itemref",
|
|
337
|
+
itemScope: "itemscope",
|
|
338
|
+
itemType: "itemtype",
|
|
339
|
+
maxLength: "maxlength",
|
|
340
|
+
minLength: "minlength",
|
|
341
|
+
noModule: "nomodule",
|
|
342
|
+
noValidate: "novalidate",
|
|
343
|
+
playsInline: "playsinline",
|
|
344
|
+
readOnly: "readonly",
|
|
345
|
+
referrerPolicy: "referrerpolicy",
|
|
346
|
+
rowSpan: "rowspan",
|
|
347
|
+
spellCheck: "spellcheck",
|
|
348
|
+
srcDoc: "srcdoc",
|
|
349
|
+
srcLang: "srclang",
|
|
350
|
+
srcSet: "srcset",
|
|
351
|
+
tabIndex: "tabindex",
|
|
352
|
+
useMap: "usemap",
|
|
353
|
+
alignmentBaseline: "alignment-baseline",
|
|
354
|
+
baselineShift: "baseline-shift",
|
|
355
|
+
clipPath: "clip-path",
|
|
356
|
+
clipRule: "clip-rule",
|
|
357
|
+
colorInterpolation: "color-interpolation",
|
|
358
|
+
colorInterpolationFilters: "color-interpolation-filters",
|
|
359
|
+
colorProfile: "color-profile",
|
|
360
|
+
colorRendering: "color-rendering",
|
|
361
|
+
dominantBaseline: "dominant-baseline",
|
|
362
|
+
enableBackground: "enable-background",
|
|
363
|
+
fillOpacity: "fill-opacity",
|
|
364
|
+
fillRule: "fill-rule",
|
|
365
|
+
floodOpacity: "flood-opacity",
|
|
366
|
+
floodColor: "flood-color",
|
|
367
|
+
fontFamily: "font-family",
|
|
368
|
+
fontSize: "font-size",
|
|
369
|
+
fontSizeAdjust: "font-size-adjust",
|
|
370
|
+
fontStretch: "font-stretch",
|
|
371
|
+
fontStyle: "font-style",
|
|
372
|
+
fontVariant: "font-variant",
|
|
373
|
+
fontWeight: "font-weight",
|
|
374
|
+
glyphOrientationHorizontal: "glyph-orientation-horizontal",
|
|
375
|
+
glyphOrientationVertical: "glyph-orientation-vertical",
|
|
376
|
+
imageRendering: "image-rendering",
|
|
377
|
+
letterSpacing: "letter-spacing",
|
|
378
|
+
lightingColor: "lighting-color",
|
|
379
|
+
markerEnd: "marker-end",
|
|
380
|
+
markerMid: "marker-mid",
|
|
381
|
+
markerStart: "marker-start",
|
|
382
|
+
pointerEvents: "pointer-events",
|
|
383
|
+
popoverTarget: "popovertarget",
|
|
384
|
+
popoverTargetAction: "popovertargetaction",
|
|
385
|
+
shapeRendering: "shape-rendering",
|
|
386
|
+
stopColor: "stop-color",
|
|
387
|
+
stopOpacity: "stop-opacity",
|
|
388
|
+
strokeDasharray: "stroke-dasharray",
|
|
389
|
+
strokeDashoffset: "stroke-dashoffset",
|
|
390
|
+
strokeLinecap: "stroke-linecap",
|
|
391
|
+
strokeLinejoin: "stroke-linejoin",
|
|
392
|
+
strokeMiterlimit: "stroke-miterlimit",
|
|
393
|
+
strokeWidth: "stroke-width",
|
|
394
|
+
strokeOpacity: "stroke-opacity",
|
|
395
|
+
textAnchor: "text-anchor",
|
|
396
|
+
textDecoration: "text-decoration",
|
|
397
|
+
textRendering: "text-rendering",
|
|
398
|
+
unicodeBidi: "unicode-bidi",
|
|
399
|
+
wordSpacing: "word-spacing",
|
|
400
|
+
writingMode: "writing-mode",
|
|
401
|
+
xlinkActuate: "xlink:actuate",
|
|
402
|
+
xlinkArcrole: "xlink:arcrole",
|
|
403
|
+
xlinkHref: "xlink:href",
|
|
404
|
+
xlinkRole: "xlink:role",
|
|
405
|
+
xlinkShow: "xlink:show",
|
|
406
|
+
xlinkTitle: "xlink:title",
|
|
407
|
+
xlinkType: "xlink:type",
|
|
408
|
+
xmlBase: "xml:base",
|
|
409
|
+
xmlLang: "xml:lang",
|
|
410
|
+
xmlSpace: "xml:space",
|
|
411
|
+
dirName: "dirname"
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// src/component-generator.ts
|
|
699
415
|
var generateAction = ({
|
|
700
416
|
scope,
|
|
701
417
|
prop,
|
|
@@ -707,7 +423,7 @@ var generateAction = ({
|
|
|
707
423
|
let assignersCode = "";
|
|
708
424
|
for (const value of prop.value) {
|
|
709
425
|
args = value.args;
|
|
710
|
-
assignersCode +=
|
|
426
|
+
assignersCode += transpileExpression({
|
|
711
427
|
expression: value.code,
|
|
712
428
|
executable: true,
|
|
713
429
|
replaceVariable: (identifier, assignee) => {
|
|
@@ -758,7 +474,7 @@ var generatePropValue = ({
|
|
|
758
474
|
if (prop.type === "asset" || prop.type === "page") {
|
|
759
475
|
return;
|
|
760
476
|
}
|
|
761
|
-
if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
|
|
477
|
+
if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json" || prop.type === "animationAction") {
|
|
762
478
|
return JSON.stringify(prop.value);
|
|
763
479
|
}
|
|
764
480
|
if (prop.type === "parameter") {
|
|
@@ -788,6 +504,8 @@ var generatePropValue = ({
|
|
|
788
504
|
var generateJsxElement = ({
|
|
789
505
|
context = "jsx",
|
|
790
506
|
scope,
|
|
507
|
+
metas,
|
|
508
|
+
tagsOverrides,
|
|
791
509
|
instance,
|
|
792
510
|
props,
|
|
793
511
|
dataSources,
|
|
@@ -796,14 +514,20 @@ var generateJsxElement = ({
|
|
|
796
514
|
children,
|
|
797
515
|
classesMap
|
|
798
516
|
}) => {
|
|
799
|
-
if (instance.component ===
|
|
517
|
+
if (instance.component === descendantComponent) {
|
|
800
518
|
return "";
|
|
801
519
|
}
|
|
520
|
+
const meta = metas.get(instance.component);
|
|
521
|
+
const hasTags = Object.keys(meta?.presetStyle ?? {}).length > 0;
|
|
802
522
|
let generatedProps = "";
|
|
803
523
|
const index = indexesWithinAncestors.get(instance.id);
|
|
804
524
|
if (index !== void 0) {
|
|
805
525
|
generatedProps += `
|
|
806
|
-
${
|
|
526
|
+
${indexProperty}="${index}"`;
|
|
527
|
+
}
|
|
528
|
+
if (instance.tag !== void 0 && instance.component !== elementComponent) {
|
|
529
|
+
generatedProps += `
|
|
530
|
+
${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
807
531
|
}
|
|
808
532
|
let conditionValue;
|
|
809
533
|
let collectionDataValue;
|
|
@@ -822,6 +546,10 @@ ${indexAttribute}="${index}"`;
|
|
|
822
546
|
if (isAttributeNameSafe(prop.name) === false) {
|
|
823
547
|
continue;
|
|
824
548
|
}
|
|
549
|
+
let name = prop.name;
|
|
550
|
+
if (hasTags && !meta?.props?.[prop.name]) {
|
|
551
|
+
name = standardAttributesToReactProps[prop.name] ?? prop.name;
|
|
552
|
+
}
|
|
825
553
|
if (prop.name === showAttribute) {
|
|
826
554
|
if (propValue === "true") {
|
|
827
555
|
continue;
|
|
@@ -841,13 +569,13 @@ ${indexAttribute}="${index}"`;
|
|
|
841
569
|
}
|
|
842
570
|
continue;
|
|
843
571
|
}
|
|
844
|
-
if (
|
|
572
|
+
if (name === "className" && propValue !== void 0) {
|
|
845
573
|
classNameValue = propValue;
|
|
846
574
|
continue;
|
|
847
575
|
}
|
|
848
576
|
if (propValue !== void 0) {
|
|
849
577
|
generatedProps += `
|
|
850
|
-
${
|
|
578
|
+
${name}={${propValue}}`;
|
|
851
579
|
}
|
|
852
580
|
}
|
|
853
581
|
const classMapArray = classesMap?.get(instance.id);
|
|
@@ -870,7 +598,7 @@ ${prop.name}={${propValue}}`;
|
|
|
870
598
|
return "";
|
|
871
599
|
}
|
|
872
600
|
const indexVariable = scope.getName(`${instance.id}-index`, "index");
|
|
873
|
-
generatedElement += `{${collectionDataValue}?.map((${collectionItemValue}: any, ${indexVariable}: number) =>
|
|
601
|
+
generatedElement += `{${collectionDataValue}?.map?.((${collectionItemValue}: any, ${indexVariable}: number) =>
|
|
874
602
|
`;
|
|
875
603
|
generatedElement += `<Fragment key={${indexVariable}}>
|
|
876
604
|
`;
|
|
@@ -882,8 +610,18 @@ ${prop.name}={${propValue}}`;
|
|
|
882
610
|
} else if (instance.component === blockComponent) {
|
|
883
611
|
generatedElement += children;
|
|
884
612
|
} else {
|
|
885
|
-
|
|
886
|
-
|
|
613
|
+
let componentVariable;
|
|
614
|
+
if (instance.component === elementComponent) {
|
|
615
|
+
componentVariable = instance.tag ?? "div";
|
|
616
|
+
const componentDescriptor = tagsOverrides?.[componentVariable];
|
|
617
|
+
if (componentDescriptor !== void 0) {
|
|
618
|
+
const [_importSource, importSpecifier] = componentDescriptor.split(":");
|
|
619
|
+
componentVariable = scope.getName(componentDescriptor, importSpecifier);
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
const [_namespace, shortName] = parseComponentName(instance.component);
|
|
623
|
+
componentVariable = scope.getName(instance.component, shortName);
|
|
624
|
+
}
|
|
887
625
|
if (instance.children.length === 0) {
|
|
888
626
|
generatedElement += `<${componentVariable}${generatedProps} />
|
|
889
627
|
`;
|
|
@@ -920,6 +658,8 @@ ${prop.name}={${propValue}}`;
|
|
|
920
658
|
};
|
|
921
659
|
var generateJsxChildren = ({
|
|
922
660
|
scope,
|
|
661
|
+
metas,
|
|
662
|
+
tagsOverrides,
|
|
923
663
|
children,
|
|
924
664
|
instances,
|
|
925
665
|
props,
|
|
@@ -960,6 +700,8 @@ var generateJsxChildren = ({
|
|
|
960
700
|
generatedChildren += generateJsxElement({
|
|
961
701
|
context: "jsx",
|
|
962
702
|
scope,
|
|
703
|
+
metas,
|
|
704
|
+
tagsOverrides,
|
|
963
705
|
instance,
|
|
964
706
|
props,
|
|
965
707
|
dataSources,
|
|
@@ -969,6 +711,8 @@ var generateJsxChildren = ({
|
|
|
969
711
|
children: generateJsxChildren({
|
|
970
712
|
classesMap,
|
|
971
713
|
scope,
|
|
714
|
+
metas,
|
|
715
|
+
tagsOverrides,
|
|
972
716
|
children: instance.children,
|
|
973
717
|
instances,
|
|
974
718
|
props,
|
|
@@ -992,49 +736,61 @@ var generateWebstudioComponent = ({
|
|
|
992
736
|
instances,
|
|
993
737
|
props,
|
|
994
738
|
dataSources,
|
|
995
|
-
|
|
739
|
+
metas,
|
|
740
|
+
tagsOverrides,
|
|
996
741
|
classesMap
|
|
997
742
|
}) => {
|
|
998
743
|
const instance = instances.get(rootInstanceId);
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
744
|
+
const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
|
|
745
|
+
rootInstanceId
|
|
746
|
+
]);
|
|
1002
747
|
const usedDataSources = /* @__PURE__ */ new Map();
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
props,
|
|
1008
|
-
dataSources,
|
|
1009
|
-
usedDataSources,
|
|
1010
|
-
indexesWithinAncestors,
|
|
1011
|
-
classesMap,
|
|
1012
|
-
children: generateJsxChildren({
|
|
748
|
+
let generatedJsx = "<></>\n";
|
|
749
|
+
if (instance) {
|
|
750
|
+
generatedJsx = generateJsxElement({
|
|
751
|
+
context: "expression",
|
|
1013
752
|
scope,
|
|
1014
|
-
|
|
1015
|
-
|
|
753
|
+
metas,
|
|
754
|
+
tagsOverrides,
|
|
755
|
+
instance,
|
|
1016
756
|
props,
|
|
1017
757
|
dataSources,
|
|
1018
758
|
usedDataSources,
|
|
1019
759
|
indexesWithinAncestors,
|
|
1020
|
-
classesMap
|
|
1021
|
-
|
|
1022
|
-
|
|
760
|
+
classesMap,
|
|
761
|
+
children: generateJsxChildren({
|
|
762
|
+
scope,
|
|
763
|
+
metas,
|
|
764
|
+
tagsOverrides,
|
|
765
|
+
children: instance.children,
|
|
766
|
+
instances,
|
|
767
|
+
props,
|
|
768
|
+
dataSources,
|
|
769
|
+
usedDataSources,
|
|
770
|
+
indexesWithinAncestors,
|
|
771
|
+
classesMap
|
|
772
|
+
})
|
|
773
|
+
});
|
|
774
|
+
}
|
|
1023
775
|
let generatedProps = "";
|
|
776
|
+
let generatedParameters = "";
|
|
777
|
+
const uniqueParameters = new Set(
|
|
778
|
+
parameters.map((parameter) => parameter.name)
|
|
779
|
+
);
|
|
1024
780
|
if (parameters.length > 0) {
|
|
1025
|
-
let
|
|
1026
|
-
|
|
781
|
+
let generatedPropsType = "";
|
|
782
|
+
for (const parameterName of uniqueParameters) {
|
|
783
|
+
generatedPropsType += `${parameterName}: any; `;
|
|
784
|
+
}
|
|
785
|
+
generatedProps = `_props: { ${generatedPropsType}}`;
|
|
1027
786
|
for (const parameter of parameters) {
|
|
1028
787
|
const dataSource = usedDataSources.get(parameter.value);
|
|
1029
788
|
if (dataSource) {
|
|
1030
789
|
const valueName = scope.getName(dataSource.id, dataSource.name);
|
|
1031
|
-
|
|
790
|
+
generatedParameters += `const ${valueName} = _props.${parameter.name};
|
|
791
|
+
`;
|
|
1032
792
|
}
|
|
1033
|
-
generatedPropsType += `${parameter.name}: any; `;
|
|
1034
793
|
}
|
|
1035
|
-
generatedPropsValue += `}`;
|
|
1036
|
-
generatedPropsType += `}`;
|
|
1037
|
-
generatedProps = `${generatedPropsValue}: ${generatedPropsType}`;
|
|
1038
794
|
}
|
|
1039
795
|
let generatedDataSources = "";
|
|
1040
796
|
for (const dataSource of usedDataSources.values()) {
|
|
@@ -1063,6 +819,7 @@ var generateWebstudioComponent = ({
|
|
|
1063
819
|
let generatedComponent = "";
|
|
1064
820
|
generatedComponent += `const ${name} = (${generatedProps}) => {
|
|
1065
821
|
`;
|
|
822
|
+
generatedComponent += `${generatedParameters}`;
|
|
1066
823
|
generatedComponent += `${generatedDataSources}`;
|
|
1067
824
|
generatedComponent += `return ${generatedJsx}`;
|
|
1068
825
|
generatedComponent += `}
|
|
@@ -1070,26 +827,19 @@ var generateWebstudioComponent = ({
|
|
|
1070
827
|
return generatedComponent;
|
|
1071
828
|
};
|
|
1072
829
|
export {
|
|
1073
|
-
addGlobalRules,
|
|
1074
830
|
collapsedAttribute,
|
|
1075
831
|
componentAttribute,
|
|
1076
|
-
createImageValueTransformer,
|
|
1077
|
-
editablePlaceholderVariable,
|
|
1078
|
-
editingPlaceholderVariable,
|
|
1079
|
-
generateCss,
|
|
1080
|
-
generateDataFromEmbedTemplate,
|
|
1081
832
|
generateJsxChildren,
|
|
1082
833
|
generateJsxElement,
|
|
1083
834
|
generateRemixParams,
|
|
1084
835
|
generateRemixRoute,
|
|
1085
836
|
generateWebstudioComponent,
|
|
1086
|
-
getIndexesWithinAncestors,
|
|
1087
837
|
idAttribute,
|
|
1088
|
-
indexAttribute,
|
|
1089
838
|
isAttributeNameSafe,
|
|
1090
|
-
namespaceMeta,
|
|
1091
839
|
normalizeProps,
|
|
840
|
+
reactPropsToStandardAttributes,
|
|
1092
841
|
selectorIdAttribute,
|
|
1093
842
|
showAttribute,
|
|
843
|
+
standardAttributesToReactProps,
|
|
1094
844
|
textContentAttribute
|
|
1095
845
|
};
|