@webstudio-is/react-sdk 0.189.0 → 0.191.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 +211 -4
- package/lib/runtime.js +8 -12
- package/lib/types/components/component-meta.d.ts +627 -444
- package/lib/types/components/components-utils.d.ts +2 -1
- package/lib/types/core-components.d.ts +298 -1
- package/lib/types/embed-template.d.ts +241 -212
- package/lib/types/hook.d.ts +9 -23
- package/package.json +10 -12
package/lib/index.js
CHANGED
|
@@ -82,9 +82,11 @@ import {
|
|
|
82
82
|
|
|
83
83
|
// src/core-components.ts
|
|
84
84
|
import {
|
|
85
|
+
EditIcon,
|
|
85
86
|
ListViewIcon,
|
|
86
87
|
PaintBrushIcon,
|
|
87
|
-
SettingsIcon
|
|
88
|
+
SettingsIcon,
|
|
89
|
+
AddTemplateInstanceIcon
|
|
88
90
|
} from "@webstudio-is/icons/svg";
|
|
89
91
|
import { html } from "@webstudio-is/sdk/normalize.css";
|
|
90
92
|
var rootComponent = "ws:root";
|
|
@@ -192,17 +194,183 @@ var descendantPropsMeta = {
|
|
|
192
194
|
},
|
|
193
195
|
initialProps: ["selector"]
|
|
194
196
|
};
|
|
197
|
+
var blockTemplateComponent = "ws:block-template";
|
|
198
|
+
var blockTemplateMeta = {
|
|
199
|
+
category: "hidden",
|
|
200
|
+
detachable: false,
|
|
201
|
+
type: "container",
|
|
202
|
+
icon: AddTemplateInstanceIcon,
|
|
203
|
+
stylable: false
|
|
204
|
+
};
|
|
205
|
+
var blockTemplatePropsMeta = {
|
|
206
|
+
props: {},
|
|
207
|
+
initialProps: []
|
|
208
|
+
};
|
|
209
|
+
var blockComponent = "ws:block";
|
|
210
|
+
var blockMeta = {
|
|
211
|
+
category: "data",
|
|
212
|
+
order: 2,
|
|
213
|
+
type: "container",
|
|
214
|
+
label: "Content Block",
|
|
215
|
+
icon: EditIcon,
|
|
216
|
+
constraints: {
|
|
217
|
+
relation: "ancestor",
|
|
218
|
+
component: { $neq: collectionComponent }
|
|
219
|
+
},
|
|
220
|
+
stylable: false,
|
|
221
|
+
template: [
|
|
222
|
+
{
|
|
223
|
+
type: "instance",
|
|
224
|
+
component: blockComponent,
|
|
225
|
+
props: [],
|
|
226
|
+
children: [
|
|
227
|
+
{
|
|
228
|
+
type: "instance",
|
|
229
|
+
label: "Templates",
|
|
230
|
+
component: blockTemplateComponent,
|
|
231
|
+
children: [
|
|
232
|
+
{
|
|
233
|
+
type: "instance",
|
|
234
|
+
component: "Paragraph",
|
|
235
|
+
children: [
|
|
236
|
+
{
|
|
237
|
+
type: "text",
|
|
238
|
+
value: "Paragraph text you can edit",
|
|
239
|
+
placeholder: true
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
type: "instance",
|
|
245
|
+
component: "List",
|
|
246
|
+
children: [
|
|
247
|
+
{
|
|
248
|
+
type: "instance",
|
|
249
|
+
component: "ListItem",
|
|
250
|
+
children: [
|
|
251
|
+
{
|
|
252
|
+
type: "text",
|
|
253
|
+
value: "List Item text you can edit",
|
|
254
|
+
placeholder: true
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: "instance",
|
|
260
|
+
component: "ListItem",
|
|
261
|
+
children: [
|
|
262
|
+
{
|
|
263
|
+
type: "text",
|
|
264
|
+
value: "List Item text you can edit",
|
|
265
|
+
placeholder: true
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
type: "instance",
|
|
271
|
+
component: "ListItem",
|
|
272
|
+
children: [
|
|
273
|
+
{
|
|
274
|
+
type: "text",
|
|
275
|
+
value: "List Item text you can edit",
|
|
276
|
+
placeholder: true
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: "instance",
|
|
286
|
+
component: "Paragraph",
|
|
287
|
+
children: [
|
|
288
|
+
{
|
|
289
|
+
type: "text",
|
|
290
|
+
value: "The Content Block component designates regions on the page where pre-styled instances can be inserted in "
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "instance",
|
|
294
|
+
component: "RichTextLink",
|
|
295
|
+
children: [
|
|
296
|
+
{
|
|
297
|
+
type: "text",
|
|
298
|
+
value: "Content mode"
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
props: [
|
|
302
|
+
{
|
|
303
|
+
type: "string",
|
|
304
|
+
name: "href",
|
|
305
|
+
value: "https://wstd.us/content-block"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: "text",
|
|
311
|
+
value: "."
|
|
312
|
+
}
|
|
313
|
+
]
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
type: "instance",
|
|
317
|
+
component: "List",
|
|
318
|
+
children: [
|
|
319
|
+
{
|
|
320
|
+
type: "instance",
|
|
321
|
+
component: "ListItem",
|
|
322
|
+
children: [
|
|
323
|
+
{
|
|
324
|
+
type: "text",
|
|
325
|
+
value: "In Content mode, you can edit any direct child instances that were pre-added to the Content Block, as well as add new instances predefined in Templates."
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
type: "instance",
|
|
331
|
+
component: "ListItem",
|
|
332
|
+
children: [
|
|
333
|
+
{
|
|
334
|
+
type: "text",
|
|
335
|
+
value: "To predefine instances for insertion in Content mode, switch to Design mode and add them to the Templates container."
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
type: "instance",
|
|
341
|
+
component: "ListItem",
|
|
342
|
+
children: [
|
|
343
|
+
{
|
|
344
|
+
type: "text",
|
|
345
|
+
value: "To insert predefined instances in Content mode, click the + button while hovering over the Content Block on the canvas and choose an instance from the list."
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
};
|
|
355
|
+
var blockPropsMeta = {
|
|
356
|
+
props: {},
|
|
357
|
+
initialProps: []
|
|
358
|
+
};
|
|
195
359
|
var coreMetas = {
|
|
196
360
|
[rootComponent]: rootMeta,
|
|
197
361
|
[collectionComponent]: collectionMeta,
|
|
198
|
-
[descendantComponent]: descendantMeta
|
|
362
|
+
[descendantComponent]: descendantMeta,
|
|
363
|
+
[blockComponent]: blockMeta,
|
|
364
|
+
[blockTemplateComponent]: blockTemplateMeta
|
|
199
365
|
};
|
|
200
366
|
var corePropsMetas = {
|
|
201
367
|
[rootComponent]: rootPropsMeta,
|
|
202
368
|
[collectionComponent]: collectionPropsMeta,
|
|
203
|
-
[descendantComponent]: descendantPropsMeta
|
|
369
|
+
[descendantComponent]: descendantPropsMeta,
|
|
370
|
+
[blockComponent]: blockPropsMeta,
|
|
371
|
+
[blockTemplateComponent]: blockTemplatePropsMeta
|
|
204
372
|
};
|
|
205
|
-
var isCoreComponent = (component) => component === rootComponent || component === collectionComponent || component === descendantComponent;
|
|
373
|
+
var isCoreComponent = (component) => component === rootComponent || component === collectionComponent || component === descendantComponent || component === blockComponent || component === blockTemplateComponent;
|
|
206
374
|
|
|
207
375
|
// src/css/css.ts
|
|
208
376
|
import { kebabCase } from "change-case";
|
|
@@ -632,6 +800,7 @@ var PropMeta = z.union([
|
|
|
632
800
|
|
|
633
801
|
// src/components/component-meta.ts
|
|
634
802
|
import { z as z3 } from "zod";
|
|
803
|
+
import { Matchers } from "@webstudio-is/sdk";
|
|
635
804
|
|
|
636
805
|
// src/embed-template.ts
|
|
637
806
|
import { z as z2 } from "zod";
|
|
@@ -985,6 +1154,26 @@ var namespaceEmbedTemplateComponents = (template, namespace, components) => {
|
|
|
985
1154
|
throw Error("Impossible case");
|
|
986
1155
|
});
|
|
987
1156
|
};
|
|
1157
|
+
var namespaceMatcher = (namespace, matcher) => {
|
|
1158
|
+
const newMatcher = structuredClone(matcher);
|
|
1159
|
+
if (newMatcher.component?.$eq) {
|
|
1160
|
+
newMatcher.component.$eq = `${namespace}:${newMatcher.component.$eq}`;
|
|
1161
|
+
}
|
|
1162
|
+
if (newMatcher.component?.$neq) {
|
|
1163
|
+
newMatcher.component.$neq = `${namespace}:${newMatcher.component.$neq}`;
|
|
1164
|
+
}
|
|
1165
|
+
if (newMatcher.component?.$in) {
|
|
1166
|
+
newMatcher.component.$in = newMatcher.component.$in.map(
|
|
1167
|
+
(component) => `${namespace}:${component}`
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
if (newMatcher.component?.$nin) {
|
|
1171
|
+
newMatcher.component.$nin = newMatcher.component.$nin.map(
|
|
1172
|
+
(component) => `${namespace}:${component}`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
return newMatcher;
|
|
1176
|
+
};
|
|
988
1177
|
var namespaceMeta = (meta, namespace, components) => {
|
|
989
1178
|
const newMeta = { ...meta };
|
|
990
1179
|
if (newMeta.requiredAncestors) {
|
|
@@ -997,6 +1186,15 @@ var namespaceMeta = (meta, namespace, components) => {
|
|
|
997
1186
|
(component) => components.has(component) ? `${namespace}:${component}` : component
|
|
998
1187
|
);
|
|
999
1188
|
}
|
|
1189
|
+
if (newMeta.constraints) {
|
|
1190
|
+
if (Array.isArray(newMeta.constraints)) {
|
|
1191
|
+
newMeta.constraints = newMeta.constraints.map(
|
|
1192
|
+
(matcher) => namespaceMatcher(namespace, matcher)
|
|
1193
|
+
);
|
|
1194
|
+
} else {
|
|
1195
|
+
newMeta.constraints = namespaceMatcher(namespace, newMeta.constraints);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1000
1198
|
if (newMeta.indexWithinAncestor) {
|
|
1001
1199
|
newMeta.indexWithinAncestor = components.has(newMeta.indexWithinAncestor) ? `${namespace}:${newMeta.indexWithinAncestor}` : newMeta.indexWithinAncestor;
|
|
1002
1200
|
}
|
|
@@ -1053,6 +1251,7 @@ var WsComponentMeta = z3.object({
|
|
|
1053
1251
|
type: z3.enum(["container", "control", "embed", "rich-text-child"]),
|
|
1054
1252
|
requiredAncestors: z3.optional(z3.array(z3.string())),
|
|
1055
1253
|
invalidAncestors: z3.optional(z3.array(z3.string())),
|
|
1254
|
+
constraints: Matchers.optional(),
|
|
1056
1255
|
// when this field is specified component receives
|
|
1057
1256
|
// prop with index of same components withiin specified ancestor
|
|
1058
1257
|
// important to automatically enumerate collections without
|
|
@@ -1286,6 +1485,9 @@ ${prop.name}={${propValue}}`;
|
|
|
1286
1485
|
className={${classes.join(` + " " + `)}}`;
|
|
1287
1486
|
}
|
|
1288
1487
|
let generatedElement = "";
|
|
1488
|
+
if (instance.component === blockTemplateComponent) {
|
|
1489
|
+
return "";
|
|
1490
|
+
}
|
|
1289
1491
|
if (instance.component === collectionComponent) {
|
|
1290
1492
|
if (collectionDataValue === void 0 || collectionItemValue === void 0) {
|
|
1291
1493
|
return "";
|
|
@@ -1300,6 +1502,8 @@ className={${classes.join(` + " " + `)}}`;
|
|
|
1300
1502
|
`;
|
|
1301
1503
|
generatedElement += `)}
|
|
1302
1504
|
`;
|
|
1505
|
+
} else if (instance.component === blockComponent) {
|
|
1506
|
+
generatedElement += children;
|
|
1303
1507
|
} else {
|
|
1304
1508
|
const [_namespace, shortName] = parseComponentName2(instance.component);
|
|
1305
1509
|
const componentVariable = scope.getName(instance.component, shortName);
|
|
@@ -1496,6 +1700,9 @@ export {
|
|
|
1496
1700
|
WsComponentMeta,
|
|
1497
1701
|
WsEmbedTemplate,
|
|
1498
1702
|
addGlobalRules,
|
|
1703
|
+
blockComponent,
|
|
1704
|
+
blockTemplateComponent,
|
|
1705
|
+
blockTemplateMeta,
|
|
1499
1706
|
collapsedAttribute,
|
|
1500
1707
|
collectionComponent,
|
|
1501
1708
|
componentAttribute,
|
package/lib/runtime.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// src/context.tsx
|
|
2
2
|
import { createContext, useContext, useMemo } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createJsonStringifyProxy,
|
|
5
|
+
isPlainObject
|
|
6
|
+
} from "@webstudio-is/sdk/runtime";
|
|
4
7
|
var ReactSdkContext = createContext({
|
|
5
8
|
assetBaseUrl: "/",
|
|
6
9
|
imageBaseUrl: "/",
|
|
@@ -29,19 +32,13 @@ var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
};
|
|
32
|
-
var getInstanceSelectorById = (instanceSelector, instanceId) => {
|
|
33
|
-
const index = instanceSelector.findIndex(
|
|
34
|
-
(selector) => selector === instanceId
|
|
35
|
-
);
|
|
36
|
-
if (index === -1) {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
return instanceSelector.slice(index);
|
|
40
|
-
};
|
|
41
35
|
|
|
42
36
|
// src/variable-state.tsx
|
|
43
|
-
import { createJsonStringifyProxy as createJsonStringifyProxy2, isPlainObject as isPlainObject2 } from "@webstudio-is/sdk";
|
|
44
37
|
import { useState, useMemo as useMemo2 } from "react";
|
|
38
|
+
import {
|
|
39
|
+
createJsonStringifyProxy as createJsonStringifyProxy2,
|
|
40
|
+
isPlainObject as isPlainObject2
|
|
41
|
+
} from "@webstudio-is/sdk/runtime";
|
|
45
42
|
var useVariableState = (initialState) => {
|
|
46
43
|
const [state, setState] = useState(initialState);
|
|
47
44
|
const value = useMemo2(
|
|
@@ -59,7 +56,6 @@ export {
|
|
|
59
56
|
ReactSdkContext,
|
|
60
57
|
getClosestInstance,
|
|
61
58
|
getIndexWithinAncestorFromComponentProps,
|
|
62
|
-
getInstanceSelectorById,
|
|
63
59
|
useResource,
|
|
64
60
|
useVariableState
|
|
65
61
|
};
|