@webstudio-is/react-sdk 0.124.0 → 0.125.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 +39 -13
- package/lib/types/component-generator.d.ts +8 -2
- package/lib/types/components/component-meta.d.ts +35 -0
- package/lib/types/core-components.d.ts +7 -0
- package/lib/types/embed-template.d.ts +7 -1
- package/lib/types/hook.d.ts +4 -1
- package/lib/types/instance-utils.d.ts +4 -1
- package/lib/types/prop-meta.d.ts +21 -0
- package/lib/types/props.d.ts +1 -0
- package/lib/types/tree/create-elements-tree.d.ts +8 -2
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -136,6 +136,7 @@ var componentAttribute = "data-ws-component";
|
|
|
136
136
|
var showAttribute = "data-ws-show";
|
|
137
137
|
var indexAttribute = "data-ws-index";
|
|
138
138
|
var collapsedAttribute = "data-ws-collapsed";
|
|
139
|
+
var textContentAttribute = "data-ws-text-content";
|
|
139
140
|
var getInstanceIdFromComponentProps = (props) => {
|
|
140
141
|
return props[idAttribute];
|
|
141
142
|
};
|
|
@@ -350,18 +351,25 @@ var createInstanceChildrenElements = ({
|
|
|
350
351
|
elements.push(renderText(child.value));
|
|
351
352
|
continue;
|
|
352
353
|
}
|
|
353
|
-
|
|
354
|
-
if (childInstance === void 0) {
|
|
354
|
+
if (child.type === "expression") {
|
|
355
355
|
continue;
|
|
356
356
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
357
|
+
if (child.type === "id") {
|
|
358
|
+
const childInstance = instances.get(child.value);
|
|
359
|
+
if (childInstance === void 0) {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const childInstanceSelector = [child.value, ...instanceSelector];
|
|
363
|
+
const element = createInstanceElement({
|
|
364
|
+
instance: childInstance,
|
|
365
|
+
instanceSelector: childInstanceSelector,
|
|
366
|
+
Component,
|
|
367
|
+
components
|
|
368
|
+
});
|
|
369
|
+
elements.push(element);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
child;
|
|
365
373
|
}
|
|
366
374
|
if (elements.length === 0) {
|
|
367
375
|
return;
|
|
@@ -403,7 +411,7 @@ var Root = ({
|
|
|
403
411
|
};
|
|
404
412
|
|
|
405
413
|
// src/core-components.ts
|
|
406
|
-
import {
|
|
414
|
+
import { ListViewIcon } from "@webstudio-is/icons/svg";
|
|
407
415
|
var portalComponent = "Slot";
|
|
408
416
|
var collectionComponent = "ws:collection";
|
|
409
417
|
var collectionMeta = {
|
|
@@ -411,7 +419,7 @@ var collectionMeta = {
|
|
|
411
419
|
order: 7,
|
|
412
420
|
type: "container",
|
|
413
421
|
label: "Collection",
|
|
414
|
-
icon:
|
|
422
|
+
icon: ListViewIcon,
|
|
415
423
|
stylable: false,
|
|
416
424
|
template: [
|
|
417
425
|
{
|
|
@@ -590,6 +598,12 @@ var Action = z.object({
|
|
|
590
598
|
type: z.literal("action"),
|
|
591
599
|
defaultValue: z.undefined().optional()
|
|
592
600
|
});
|
|
601
|
+
var TextContent = z.object({
|
|
602
|
+
...common,
|
|
603
|
+
control: z.literal("textContent"),
|
|
604
|
+
type: z.literal("string"),
|
|
605
|
+
defaultValue: z.string().optional()
|
|
606
|
+
});
|
|
593
607
|
var PropMeta = z.union([
|
|
594
608
|
Number,
|
|
595
609
|
Range,
|
|
@@ -607,7 +621,8 @@ var PropMeta = z.union([
|
|
|
607
621
|
Url,
|
|
608
622
|
Json,
|
|
609
623
|
Date,
|
|
610
|
-
Action
|
|
624
|
+
Action,
|
|
625
|
+
TextContent
|
|
611
626
|
]);
|
|
612
627
|
|
|
613
628
|
// src/components/component-meta.ts
|
|
@@ -1497,6 +1512,16 @@ var generateJsxChildren = ({
|
|
|
1497
1512
|
`);
|
|
1498
1513
|
continue;
|
|
1499
1514
|
}
|
|
1515
|
+
if (child.type === "expression") {
|
|
1516
|
+
const expression = generateExpression({
|
|
1517
|
+
expression: child.value,
|
|
1518
|
+
dataSources,
|
|
1519
|
+
scope
|
|
1520
|
+
});
|
|
1521
|
+
generatedChildren = `{${expression}}
|
|
1522
|
+
`;
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1500
1525
|
if (child.type === "id") {
|
|
1501
1526
|
const instanceId = child.value;
|
|
1502
1527
|
const instance = instances.get(instanceId);
|
|
@@ -1758,5 +1783,6 @@ export {
|
|
|
1758
1783
|
selectorIdAttribute,
|
|
1759
1784
|
showAttribute,
|
|
1760
1785
|
stateCategories,
|
|
1786
|
+
textContentAttribute,
|
|
1761
1787
|
validateExpression
|
|
1762
1788
|
};
|
|
@@ -127,14 +127,17 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
|
|
|
127
127
|
instances: Map<string, {
|
|
128
128
|
type: "instance";
|
|
129
129
|
id: string;
|
|
130
|
-
component: string;
|
|
131
130
|
children: ({
|
|
132
131
|
value: string;
|
|
133
132
|
type: "text";
|
|
134
133
|
} | {
|
|
135
134
|
value: string;
|
|
136
135
|
type: "id";
|
|
136
|
+
} | {
|
|
137
|
+
value: string;
|
|
138
|
+
type: "expression";
|
|
137
139
|
})[];
|
|
140
|
+
component: string;
|
|
138
141
|
label?: string | undefined;
|
|
139
142
|
}>;
|
|
140
143
|
props: Map<string, {
|
|
@@ -260,14 +263,17 @@ export declare const generatePageComponent: ({ scope, page, instances, props, da
|
|
|
260
263
|
instances: Map<string, {
|
|
261
264
|
type: "instance";
|
|
262
265
|
id: string;
|
|
263
|
-
component: string;
|
|
264
266
|
children: ({
|
|
265
267
|
value: string;
|
|
266
268
|
type: "text";
|
|
267
269
|
} | {
|
|
268
270
|
value: string;
|
|
269
271
|
type: "id";
|
|
272
|
+
} | {
|
|
273
|
+
value: string;
|
|
274
|
+
type: "expression";
|
|
270
275
|
})[];
|
|
276
|
+
component: string;
|
|
271
277
|
label?: string | undefined;
|
|
272
278
|
}>;
|
|
273
279
|
props: Map<string, {
|
|
@@ -387,6 +387,27 @@ declare const WsComponentPropsMeta: z.ZodObject<{
|
|
|
387
387
|
defaultValue?: undefined;
|
|
388
388
|
label?: string | undefined;
|
|
389
389
|
description?: string | undefined;
|
|
390
|
+
}>, z.ZodObject<{
|
|
391
|
+
control: z.ZodLiteral<"textContent">;
|
|
392
|
+
type: z.ZodLiteral<"string">;
|
|
393
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
394
|
+
label: z.ZodOptional<z.ZodString>;
|
|
395
|
+
description: z.ZodOptional<z.ZodString>;
|
|
396
|
+
required: z.ZodBoolean;
|
|
397
|
+
}, "strip", z.ZodTypeAny, {
|
|
398
|
+
type: "string";
|
|
399
|
+
required: boolean;
|
|
400
|
+
control: "textContent";
|
|
401
|
+
defaultValue?: string | undefined;
|
|
402
|
+
label?: string | undefined;
|
|
403
|
+
description?: string | undefined;
|
|
404
|
+
}, {
|
|
405
|
+
type: "string";
|
|
406
|
+
required: boolean;
|
|
407
|
+
control: "textContent";
|
|
408
|
+
defaultValue?: string | undefined;
|
|
409
|
+
label?: string | undefined;
|
|
410
|
+
description?: string | undefined;
|
|
390
411
|
}>]>>;
|
|
391
412
|
initialProps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
392
413
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -518,6 +539,13 @@ declare const WsComponentPropsMeta: z.ZodObject<{
|
|
|
518
539
|
defaultValue?: undefined;
|
|
519
540
|
label?: string | undefined;
|
|
520
541
|
description?: string | undefined;
|
|
542
|
+
} | {
|
|
543
|
+
type: "string";
|
|
544
|
+
required: boolean;
|
|
545
|
+
control: "textContent";
|
|
546
|
+
defaultValue?: string | undefined;
|
|
547
|
+
label?: string | undefined;
|
|
548
|
+
description?: string | undefined;
|
|
521
549
|
}>;
|
|
522
550
|
initialProps?: string[] | undefined;
|
|
523
551
|
}, {
|
|
@@ -649,6 +677,13 @@ declare const WsComponentPropsMeta: z.ZodObject<{
|
|
|
649
677
|
defaultValue?: undefined;
|
|
650
678
|
label?: string | undefined;
|
|
651
679
|
description?: string | undefined;
|
|
680
|
+
} | {
|
|
681
|
+
type: "string";
|
|
682
|
+
required: boolean;
|
|
683
|
+
control: "textContent";
|
|
684
|
+
defaultValue?: string | undefined;
|
|
685
|
+
label?: string | undefined;
|
|
686
|
+
description?: string | undefined;
|
|
652
687
|
}>;
|
|
653
688
|
initialProps?: string[] | undefined;
|
|
654
689
|
}>;
|
|
@@ -134,6 +134,13 @@ export declare const corePropsMetas: {
|
|
|
134
134
|
defaultValue?: undefined;
|
|
135
135
|
label?: string | undefined;
|
|
136
136
|
description?: string | undefined;
|
|
137
|
+
} | {
|
|
138
|
+
type: "string";
|
|
139
|
+
required: boolean;
|
|
140
|
+
control: "textContent";
|
|
141
|
+
defaultValue?: string | undefined;
|
|
142
|
+
label?: string | undefined;
|
|
143
|
+
description?: string | undefined;
|
|
137
144
|
}>;
|
|
138
145
|
initialProps?: string[] | undefined;
|
|
139
146
|
};
|
|
@@ -2215,18 +2215,24 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
|
|
|
2215
2215
|
} | {
|
|
2216
2216
|
value: string;
|
|
2217
2217
|
type: "id";
|
|
2218
|
+
} | {
|
|
2219
|
+
value: string;
|
|
2220
|
+
type: "expression";
|
|
2218
2221
|
})[];
|
|
2219
2222
|
instances: {
|
|
2220
2223
|
type: "instance";
|
|
2221
2224
|
id: string;
|
|
2222
|
-
component: string;
|
|
2223
2225
|
children: ({
|
|
2224
2226
|
value: string;
|
|
2225
2227
|
type: "text";
|
|
2226
2228
|
} | {
|
|
2227
2229
|
value: string;
|
|
2228
2230
|
type: "id";
|
|
2231
|
+
} | {
|
|
2232
|
+
value: string;
|
|
2233
|
+
type: "expression";
|
|
2229
2234
|
})[];
|
|
2235
|
+
component: string;
|
|
2230
2236
|
label?: string | undefined;
|
|
2231
2237
|
}[];
|
|
2232
2238
|
props: ({
|
package/lib/types/hook.d.ts
CHANGED
|
@@ -28,14 +28,17 @@ export type Hook = {
|
|
|
28
28
|
export declare const getClosestInstance: (instancePath: InstancePath, currentInstance: Instance, closestComponent: Instance["component"]) => {
|
|
29
29
|
type: "instance";
|
|
30
30
|
id: string;
|
|
31
|
-
component: string;
|
|
32
31
|
children: ({
|
|
33
32
|
value: string;
|
|
34
33
|
type: "text";
|
|
35
34
|
} | {
|
|
36
35
|
value: string;
|
|
37
36
|
type: "id";
|
|
37
|
+
} | {
|
|
38
|
+
value: string;
|
|
39
|
+
type: "expression";
|
|
38
40
|
})[];
|
|
41
|
+
component: string;
|
|
39
42
|
label?: string | undefined;
|
|
40
43
|
} | undefined;
|
|
41
44
|
export {};
|
|
@@ -4,13 +4,16 @@ export type IndexesWithinAncestors = Map<Instance["id"], number>;
|
|
|
4
4
|
export declare const getIndexesWithinAncestors: (metas: Map<Instance["component"], WsComponentMeta>, instances: Map<string, {
|
|
5
5
|
type: "instance";
|
|
6
6
|
id: string;
|
|
7
|
-
component: string;
|
|
8
7
|
children: ({
|
|
9
8
|
value: string;
|
|
10
9
|
type: "text";
|
|
11
10
|
} | {
|
|
12
11
|
value: string;
|
|
13
12
|
type: "id";
|
|
13
|
+
} | {
|
|
14
|
+
value: string;
|
|
15
|
+
type: "expression";
|
|
14
16
|
})[];
|
|
17
|
+
component: string;
|
|
15
18
|
label?: string | undefined;
|
|
16
19
|
}>, rootIds: Instance["id"][]) => IndexesWithinAncestors;
|
package/lib/types/prop-meta.d.ts
CHANGED
|
@@ -392,5 +392,26 @@ export declare const PropMeta: z.ZodUnion<[z.ZodObject<{
|
|
|
392
392
|
defaultValue?: undefined;
|
|
393
393
|
label?: string | undefined;
|
|
394
394
|
description?: string | undefined;
|
|
395
|
+
}>, z.ZodObject<{
|
|
396
|
+
control: z.ZodLiteral<"textContent">;
|
|
397
|
+
type: z.ZodLiteral<"string">;
|
|
398
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
399
|
+
label: z.ZodOptional<z.ZodString>;
|
|
400
|
+
description: z.ZodOptional<z.ZodString>;
|
|
401
|
+
required: z.ZodBoolean;
|
|
402
|
+
}, "strip", z.ZodTypeAny, {
|
|
403
|
+
type: "string";
|
|
404
|
+
required: boolean;
|
|
405
|
+
control: "textContent";
|
|
406
|
+
defaultValue?: string | undefined;
|
|
407
|
+
label?: string | undefined;
|
|
408
|
+
description?: string | undefined;
|
|
409
|
+
}, {
|
|
410
|
+
type: "string";
|
|
411
|
+
required: boolean;
|
|
412
|
+
control: "textContent";
|
|
413
|
+
defaultValue?: string | undefined;
|
|
414
|
+
label?: string | undefined;
|
|
415
|
+
description?: string | undefined;
|
|
395
416
|
}>]>;
|
|
396
417
|
export type PropMeta = z.infer<typeof PropMeta>;
|
package/lib/types/props.d.ts
CHANGED
|
@@ -139,5 +139,6 @@ export declare const componentAttribute: "data-ws-component";
|
|
|
139
139
|
export declare const showAttribute: "data-ws-show";
|
|
140
140
|
export declare const indexAttribute: "data-ws-index";
|
|
141
141
|
export declare const collapsedAttribute: "data-ws-collapsed";
|
|
142
|
+
export declare const textContentAttribute: "data-ws-text-content";
|
|
142
143
|
export declare const getInstanceIdFromComponentProps: (props: Record<string, unknown>) => string;
|
|
143
144
|
export declare const getIndexWithinAncestorFromComponentProps: (props: Record<string, unknown>) => string | undefined;
|
|
@@ -13,14 +13,17 @@ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl
|
|
|
13
13
|
instances: Map<string, {
|
|
14
14
|
type: "instance";
|
|
15
15
|
id: string;
|
|
16
|
-
component: string;
|
|
17
16
|
children: ({
|
|
18
17
|
value: string;
|
|
19
18
|
type: "text";
|
|
20
19
|
} | {
|
|
21
20
|
value: string;
|
|
22
21
|
type: "id";
|
|
22
|
+
} | {
|
|
23
|
+
value: string;
|
|
24
|
+
type: "expression";
|
|
23
25
|
})[];
|
|
26
|
+
component: string;
|
|
24
27
|
label?: string | undefined;
|
|
25
28
|
}>;
|
|
26
29
|
imageLoader: ImageLoader;
|
|
@@ -32,14 +35,17 @@ export declare const createInstanceChildrenElements: ({ instances, instanceSelec
|
|
|
32
35
|
instances: Map<string, {
|
|
33
36
|
type: "instance";
|
|
34
37
|
id: string;
|
|
35
|
-
component: string;
|
|
36
38
|
children: ({
|
|
37
39
|
value: string;
|
|
38
40
|
type: "text";
|
|
39
41
|
} | {
|
|
40
42
|
value: string;
|
|
41
43
|
type: "id";
|
|
44
|
+
} | {
|
|
45
|
+
value: string;
|
|
46
|
+
type: "expression";
|
|
42
47
|
})[];
|
|
48
|
+
component: string;
|
|
43
49
|
label?: string | undefined;
|
|
44
50
|
}>;
|
|
45
51
|
instanceSelector: InstanceSelector;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"jsep": "^1.3.8",
|
|
34
34
|
"nanoid": "^5.0.1",
|
|
35
35
|
"title-case": "^4.1.0",
|
|
36
|
-
"@webstudio-is/fonts": "0.
|
|
37
|
-
"@webstudio-is/
|
|
38
|
-
"@webstudio-is/image": "0.
|
|
39
|
-
"@webstudio-is/
|
|
40
|
-
"@webstudio-is/
|
|
36
|
+
"@webstudio-is/fonts": "0.125.0",
|
|
37
|
+
"@webstudio-is/icons": "^0.125.0",
|
|
38
|
+
"@webstudio-is/image": "0.125.0",
|
|
39
|
+
"@webstudio-is/sdk": "0.125.0",
|
|
40
|
+
"@webstudio-is/css-engine": "0.125.0"
|
|
41
41
|
},
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|