@webstudio-is/react-sdk 0.90.0 → 0.92.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/app/index.js +1 -0
- package/lib/app/root.js +2 -4
- package/lib/component-renderer.js +3 -5
- package/lib/components/component-meta.js +6 -11
- package/lib/components/components-utils.js +1 -0
- package/lib/context.js +2 -4
- package/lib/css/css.js +4 -9
- package/lib/css/global-rules.js +3 -5
- package/lib/css/index.js +1 -0
- package/lib/css/normalize-type-check.js +1 -0
- package/lib/css/normalize.js +48 -96
- package/lib/css/presets.js +3 -6
- package/lib/css/style-rules.js +3 -6
- package/{src/css/style-rules.test.ts → lib/css/style-rules.test.js} +23 -28
- package/lib/embed-template.js +7 -22
- package/{src/embed-template.test.ts → lib/embed-template.test.js} +165 -176
- package/lib/expression.js +11 -22
- package/{src/expression.test.ts → lib/expression.test.js} +55 -83
- package/lib/generator.js +2 -4
- package/{src/generator.test.ts → lib/generator.test.js} +28 -31
- package/lib/hook.js +2 -4
- package/{src/hook.test.ts → lib/hook.test.js} +4 -4
- package/lib/index.js +9 -31
- package/lib/instance-utils.js +2 -4
- package/{src/instance-utils.test.ts → lib/instance-utils.test.js} +19 -43
- package/lib/prop-meta.js +150 -0
- package/lib/props.js +8 -16
- package/{src/props.test.ts → lib/props.test.js} +39 -68
- package/lib/pubsub/create.js +2 -4
- package/lib/pubsub/index.js +1 -0
- package/lib/pubsub/raf-queue.js +2 -4
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/tree/index.js +1 -0
- package/lib/tree/root.js +2 -5
- package/lib/tree/webstudio-component.js +10 -20
- package/lib/types/component-renderer.d.ts +1 -1
- package/lib/types/components/component-meta.d.ts +526 -526
- package/lib/types/context.d.ts +1 -2
- package/lib/types/css/css.d.ts +22 -23
- package/lib/types/css/global-rules.d.ts +19 -19
- package/lib/types/css/normalize.d.ts +2444 -2444
- package/lib/types/css/style-rules.d.ts +2 -2
- package/lib/types/embed-template.d.ts +648 -648
- package/lib/types/generator.d.ts +1 -1
- package/lib/types/hook.d.ts +3 -3
- package/lib/types/index.d.ts +1 -0
- package/lib/types/instance-utils.d.ts +3 -3
- package/lib/types/prop-meta.d.ts +396 -0
- package/lib/types/props.d.ts +52 -53
- package/lib/types/tree/create-elements-tree.d.ts +3 -4
- package/lib/types/tree/root.d.ts +8 -8
- package/lib/types/tree/webstudio-component.d.ts +1 -1
- package/package.json +14 -22
- package/lib/cjs/app/index.js +0 -18
- package/lib/cjs/app/root.js +0 -40
- package/lib/cjs/component-renderer.js +0 -143
- package/lib/cjs/components/component-meta.js +0 -87
- package/lib/cjs/components/components-utils.js +0 -17
- package/lib/cjs/context.js +0 -43
- package/lib/cjs/css/css.js +0 -84
- package/lib/cjs/css/global-rules.js +0 -37
- package/lib/cjs/css/index.js +0 -20
- package/lib/cjs/css/normalize-type-check.js +0 -26
- package/lib/cjs/css/normalize.js +0 -349
- package/lib/cjs/css/presets.js +0 -48
- package/lib/cjs/css/style-rules.js +0 -86
- package/lib/cjs/embed-template.js +0 -368
- package/lib/cjs/expression.js +0 -371
- package/lib/cjs/generator.js +0 -128
- package/lib/cjs/hook.js +0 -34
- package/lib/cjs/index.js +0 -59
- package/lib/cjs/instance-utils.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/props.js +0 -204
- package/lib/cjs/pubsub/create.js +0 -78
- package/lib/cjs/pubsub/index.js +0 -18
- package/lib/cjs/pubsub/raf-queue.js +0 -42
- package/lib/cjs/tree/create-elements-tree.js +0 -152
- package/lib/cjs/tree/index.js +0 -20
- package/lib/cjs/tree/root.js +0 -100
- package/lib/cjs/tree/webstudio-component.js +0 -91
- package/src/app/index.ts +0 -1
- package/src/app/root.tsx +0 -25
- package/src/component-renderer.tsx +0 -146
- package/src/components/component-meta.ts +0 -86
- package/src/components/components-utils.ts +0 -13
- package/src/context.tsx +0 -73
- package/src/css/css.ts +0 -88
- package/src/css/global-rules.ts +0 -26
- package/src/css/index.ts +0 -3
- package/src/css/normalize-type-check.ts +0 -13
- package/src/css/normalize.ts +0 -507
- package/src/css/presets.ts +0 -27
- package/src/css/style-rules.ts +0 -101
- package/src/embed-template.ts +0 -438
- package/src/expression.ts +0 -401
- package/src/generator.ts +0 -147
- package/src/hook.ts +0 -52
- package/src/index.ts +0 -39
- package/src/instance-utils.ts +0 -65
- package/src/props.ts +0 -231
- package/src/pubsub/create.ts +0 -77
- package/src/pubsub/index.ts +0 -1
- package/src/pubsub/raf-queue.ts +0 -25
- package/src/tree/create-elements-tree.tsx +0 -186
- package/src/tree/index.ts +0 -3
- package/src/tree/root.ts +0 -131
- package/src/tree/webstudio-component.tsx +0 -97
package/lib/cjs/props.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var props_exports = {};
|
|
20
|
-
__export(props_exports, {
|
|
21
|
-
getIndexWithinAncestorFromComponentProps: () => getIndexWithinAncestorFromComponentProps,
|
|
22
|
-
getInstanceIdFromComponentProps: () => getInstanceIdFromComponentProps,
|
|
23
|
-
getPropsByInstanceId: () => getPropsByInstanceId,
|
|
24
|
-
resolveUrlProp: () => resolveUrlProp,
|
|
25
|
-
useInstanceProps: () => useInstanceProps,
|
|
26
|
-
usePropAsset: () => usePropAsset,
|
|
27
|
-
usePropUrl: () => usePropUrl
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(props_exports);
|
|
30
|
-
var import_react = require("react");
|
|
31
|
-
var import_nanostores = require("nanostores");
|
|
32
|
-
var import_react2 = require("@nanostores/react");
|
|
33
|
-
var import_context = require("./context");
|
|
34
|
-
var import_webstudio_component = require("./tree/webstudio-component");
|
|
35
|
-
const getPropsByInstanceId = (props) => {
|
|
36
|
-
const propsByInstanceId = /* @__PURE__ */ new Map();
|
|
37
|
-
for (const prop of props.values()) {
|
|
38
|
-
let instanceProps = propsByInstanceId.get(prop.instanceId);
|
|
39
|
-
if (instanceProps === void 0) {
|
|
40
|
-
instanceProps = [];
|
|
41
|
-
propsByInstanceId.set(prop.instanceId, instanceProps);
|
|
42
|
-
}
|
|
43
|
-
instanceProps.push(prop);
|
|
44
|
-
}
|
|
45
|
-
return propsByInstanceId;
|
|
46
|
-
};
|
|
47
|
-
const useInstanceProps = (instanceId) => {
|
|
48
|
-
const {
|
|
49
|
-
propsByInstanceIdStore,
|
|
50
|
-
dataSourceValuesStore,
|
|
51
|
-
executeEffectfulExpression,
|
|
52
|
-
setDataSourceValues,
|
|
53
|
-
indexesWithinAncestors
|
|
54
|
-
} = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
55
|
-
const index = indexesWithinAncestors.get(instanceId);
|
|
56
|
-
const instancePropsObjectStore = (0, import_react.useMemo)(() => {
|
|
57
|
-
return (0, import_nanostores.computed)(
|
|
58
|
-
[propsByInstanceIdStore, dataSourceValuesStore],
|
|
59
|
-
(propsByInstanceId, dataSourceValues) => {
|
|
60
|
-
const instancePropsObject2 = {};
|
|
61
|
-
if (index !== void 0) {
|
|
62
|
-
instancePropsObject2[import_webstudio_component.indexAttribute] = index.toString();
|
|
63
|
-
}
|
|
64
|
-
const instanceProps = propsByInstanceId.get(instanceId);
|
|
65
|
-
if (instanceProps === void 0) {
|
|
66
|
-
return instancePropsObject2;
|
|
67
|
-
}
|
|
68
|
-
for (const prop of instanceProps) {
|
|
69
|
-
if (prop.type === "asset" || prop.type === "page") {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (prop.type === "dataSource") {
|
|
73
|
-
const dataSourceId = prop.value;
|
|
74
|
-
const value = dataSourceValues.get(dataSourceId);
|
|
75
|
-
if (value !== void 0) {
|
|
76
|
-
instancePropsObject2[prop.name] = value;
|
|
77
|
-
}
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (prop.type === "action") {
|
|
81
|
-
instancePropsObject2[prop.name] = (...args) => {
|
|
82
|
-
for (const value of prop.value) {
|
|
83
|
-
if (value.type === "execute") {
|
|
84
|
-
const argsMap = /* @__PURE__ */ new Map();
|
|
85
|
-
for (const [i, name] of value.args.entries()) {
|
|
86
|
-
argsMap.set(name, args[i]);
|
|
87
|
-
}
|
|
88
|
-
const newValues = executeEffectfulExpression(
|
|
89
|
-
value.code,
|
|
90
|
-
argsMap,
|
|
91
|
-
dataSourceValues
|
|
92
|
-
);
|
|
93
|
-
setDataSourceValues(newValues);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
instancePropsObject2[prop.name] = prop.value;
|
|
100
|
-
}
|
|
101
|
-
return instancePropsObject2;
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
}, [
|
|
105
|
-
propsByInstanceIdStore,
|
|
106
|
-
dataSourceValuesStore,
|
|
107
|
-
instanceId,
|
|
108
|
-
executeEffectfulExpression,
|
|
109
|
-
setDataSourceValues,
|
|
110
|
-
index
|
|
111
|
-
]);
|
|
112
|
-
const instancePropsObject = (0, import_react2.useStore)(instancePropsObjectStore);
|
|
113
|
-
return instancePropsObject;
|
|
114
|
-
};
|
|
115
|
-
const usePropAsset = (instanceId, name) => {
|
|
116
|
-
const { propsByInstanceIdStore, assetsStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
117
|
-
const assetStore = (0, import_react.useMemo)(() => {
|
|
118
|
-
return (0, import_nanostores.computed)(
|
|
119
|
-
[propsByInstanceIdStore, assetsStore],
|
|
120
|
-
(propsByInstanceId, assets) => {
|
|
121
|
-
const instanceProps = propsByInstanceId.get(instanceId);
|
|
122
|
-
if (instanceProps === void 0) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
for (const prop of instanceProps) {
|
|
126
|
-
if (prop.type === "asset" && prop.name === name) {
|
|
127
|
-
const assetId = prop.value;
|
|
128
|
-
return assets.get(assetId);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
}, [propsByInstanceIdStore, assetsStore, instanceId, name]);
|
|
134
|
-
const asset = (0, import_react2.useStore)(assetStore);
|
|
135
|
-
return asset;
|
|
136
|
-
};
|
|
137
|
-
const resolveUrlProp = (instanceId, name, {
|
|
138
|
-
props,
|
|
139
|
-
pages,
|
|
140
|
-
assets
|
|
141
|
-
}) => {
|
|
142
|
-
const instanceProps = props.get(instanceId);
|
|
143
|
-
if (instanceProps === void 0) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
let prop = void 0;
|
|
147
|
-
for (const intanceProp of instanceProps) {
|
|
148
|
-
if (intanceProp.name !== name) {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
prop = intanceProp;
|
|
152
|
-
}
|
|
153
|
-
if (prop === void 0) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (prop.type === "page") {
|
|
157
|
-
if (typeof prop.value === "string") {
|
|
158
|
-
const page2 = pages.get(prop.value);
|
|
159
|
-
return page2 && { type: "page", page: page2 };
|
|
160
|
-
}
|
|
161
|
-
const { instanceId: instanceId2, pageId } = prop.value;
|
|
162
|
-
const page = pages.get(pageId);
|
|
163
|
-
if (page === void 0) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const idProp = props.get(instanceId2)?.find((prop2) => prop2.name === "id");
|
|
167
|
-
return {
|
|
168
|
-
type: "page",
|
|
169
|
-
page,
|
|
170
|
-
instanceId: instanceId2,
|
|
171
|
-
hash: idProp === void 0 || idProp.type !== "string" ? void 0 : idProp.value
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
if (prop.type === "string") {
|
|
175
|
-
for (const page of pages.values()) {
|
|
176
|
-
if (page.path === prop.value) {
|
|
177
|
-
return { type: "page", page };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return { type: "string", url: prop.value };
|
|
181
|
-
}
|
|
182
|
-
if (prop.type === "asset") {
|
|
183
|
-
const asset = assets.get(prop.value);
|
|
184
|
-
return asset && { type: "asset", asset };
|
|
185
|
-
}
|
|
186
|
-
return;
|
|
187
|
-
};
|
|
188
|
-
const usePropUrl = (instanceId, name) => {
|
|
189
|
-
const { propsByInstanceIdStore, pagesStore, assetsStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
190
|
-
const store = (0, import_react.useMemo)(
|
|
191
|
-
() => (0, import_nanostores.computed)(
|
|
192
|
-
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
193
|
-
(props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
|
|
194
|
-
),
|
|
195
|
-
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
196
|
-
);
|
|
197
|
-
return (0, import_react2.useStore)(store);
|
|
198
|
-
};
|
|
199
|
-
const getInstanceIdFromComponentProps = (props) => {
|
|
200
|
-
return props[import_webstudio_component.idAttribute];
|
|
201
|
-
};
|
|
202
|
-
const getIndexWithinAncestorFromComponentProps = (props) => {
|
|
203
|
-
return props[import_webstudio_component.indexAttribute];
|
|
204
|
-
};
|
package/lib/cjs/pubsub/create.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var create_exports = {};
|
|
20
|
-
__export(create_exports, {
|
|
21
|
-
createPubsub: () => createPubsub
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(create_exports);
|
|
24
|
-
var import_nanoevents = require("nanoevents");
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_raf_queue = require("./raf-queue");
|
|
27
|
-
const createPubsub = () => {
|
|
28
|
-
const emitter = (0, import_nanoevents.createNanoEvents)();
|
|
29
|
-
if (typeof window === "object") {
|
|
30
|
-
window.addEventListener(
|
|
31
|
-
"message",
|
|
32
|
-
(event) => {
|
|
33
|
-
if (typeof event.data?.type === "string") {
|
|
34
|
-
(0, import_raf_queue.batchUpdate)(() => emitter.emit(event.data.type, event.data.payload));
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
false
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
/**
|
|
42
|
-
* To publish a postMessage event on the current window and parent window from the iframe.
|
|
43
|
-
*/
|
|
44
|
-
publish(action) {
|
|
45
|
-
window.parent.postMessage(action, "*");
|
|
46
|
-
window.postMessage(action, "*");
|
|
47
|
-
},
|
|
48
|
-
/**
|
|
49
|
-
* To publish a postMessage event on the iframe and parent window from the parent window.
|
|
50
|
-
*/
|
|
51
|
-
usePublish() {
|
|
52
|
-
const iframeRef = (0, import_react.useRef)(null);
|
|
53
|
-
const publishCallback = (0, import_react.useCallback)(
|
|
54
|
-
(action) => {
|
|
55
|
-
const element = iframeRef.current;
|
|
56
|
-
if (element?.contentWindow == null) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
element.contentWindow.postMessage(action, "*");
|
|
60
|
-
window.postMessage(action, "*");
|
|
61
|
-
},
|
|
62
|
-
[iframeRef]
|
|
63
|
-
);
|
|
64
|
-
return [publishCallback, iframeRef];
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* To subscribe a message event on the current window.
|
|
68
|
-
*/
|
|
69
|
-
useSubscribe(type, onAction) {
|
|
70
|
-
(0, import_react.useEffect)(() => {
|
|
71
|
-
return emitter.on(type, onAction);
|
|
72
|
-
}, [type, onAction]);
|
|
73
|
-
},
|
|
74
|
-
subscribe(type, onAction) {
|
|
75
|
-
return emitter.on(type, onAction);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
};
|
package/lib/cjs/pubsub/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var pubsub_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(pubsub_exports);
|
|
18
|
-
__reExport(pubsub_exports, require("./create"), module.exports);
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var raf_queue_exports = {};
|
|
20
|
-
__export(raf_queue_exports, {
|
|
21
|
-
batchUpdate: () => batchUpdate
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(raf_queue_exports);
|
|
24
|
-
let handle;
|
|
25
|
-
let updateQueue = [];
|
|
26
|
-
const processUpdates = (updates) => {
|
|
27
|
-
for (const update of updates) {
|
|
28
|
-
update();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const batchUpdate = (update) => {
|
|
32
|
-
updateQueue.push(update);
|
|
33
|
-
if (handle !== void 0) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
handle = requestAnimationFrame(() => {
|
|
37
|
-
const updates = updateQueue;
|
|
38
|
-
updateQueue = [];
|
|
39
|
-
handle = void 0;
|
|
40
|
-
processUpdates(updates);
|
|
41
|
-
});
|
|
42
|
-
};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var create_elements_tree_exports = {};
|
|
20
|
-
__export(create_elements_tree_exports, {
|
|
21
|
-
createElementsTree: () => createElementsTree
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(create_elements_tree_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_context = require("../context");
|
|
27
|
-
const createElementsTree = ({
|
|
28
|
-
renderer,
|
|
29
|
-
imageBaseUrl,
|
|
30
|
-
assetBaseUrl,
|
|
31
|
-
instances,
|
|
32
|
-
rootInstanceId,
|
|
33
|
-
propsByInstanceIdStore,
|
|
34
|
-
assetsStore,
|
|
35
|
-
pagesStore,
|
|
36
|
-
dataSourceValuesStore,
|
|
37
|
-
executeEffectfulExpression,
|
|
38
|
-
onDataSourceUpdate,
|
|
39
|
-
indexesWithinAncestors,
|
|
40
|
-
Component,
|
|
41
|
-
components,
|
|
42
|
-
scripts
|
|
43
|
-
}) => {
|
|
44
|
-
const rootInstance = instances.get(rootInstanceId);
|
|
45
|
-
if (rootInstance === void 0) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const rootInstanceSelector = [rootInstanceId];
|
|
49
|
-
const children = createInstanceChildrenElements({
|
|
50
|
-
instances,
|
|
51
|
-
instanceSelector: rootInstanceSelector,
|
|
52
|
-
Component,
|
|
53
|
-
children: rootInstance.children,
|
|
54
|
-
components
|
|
55
|
-
});
|
|
56
|
-
const root = createInstanceElement({
|
|
57
|
-
Component,
|
|
58
|
-
instance: rootInstance,
|
|
59
|
-
instanceSelector: rootInstanceSelector,
|
|
60
|
-
children: [
|
|
61
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
|
|
62
|
-
children,
|
|
63
|
-
scripts
|
|
64
|
-
] }, "children")
|
|
65
|
-
],
|
|
66
|
-
components
|
|
67
|
-
});
|
|
68
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
-
import_context.ReactSdkContext.Provider,
|
|
70
|
-
{
|
|
71
|
-
value: {
|
|
72
|
-
propsByInstanceIdStore,
|
|
73
|
-
assetsStore,
|
|
74
|
-
pagesStore,
|
|
75
|
-
dataSourceValuesStore,
|
|
76
|
-
renderer,
|
|
77
|
-
imageBaseUrl,
|
|
78
|
-
assetBaseUrl,
|
|
79
|
-
indexesWithinAncestors,
|
|
80
|
-
executeEffectfulExpression,
|
|
81
|
-
setDataSourceValues: onDataSourceUpdate,
|
|
82
|
-
setBoundDataSourceValue: (instanceId, propName, value) => {
|
|
83
|
-
const propsByInstanceId = propsByInstanceIdStore.get();
|
|
84
|
-
const props = propsByInstanceId.get(instanceId);
|
|
85
|
-
const prop = props?.find((prop2) => prop2.name === propName);
|
|
86
|
-
if (prop?.type !== "dataSource") {
|
|
87
|
-
throw Error(`${propName} is not data source`);
|
|
88
|
-
}
|
|
89
|
-
const dataSourceId = prop.value;
|
|
90
|
-
const newValues = /* @__PURE__ */ new Map();
|
|
91
|
-
newValues.set(dataSourceId, value);
|
|
92
|
-
onDataSourceUpdate(newValues);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
children: root
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
const createInstanceChildrenElements = ({
|
|
100
|
-
instances,
|
|
101
|
-
instanceSelector,
|
|
102
|
-
children,
|
|
103
|
-
Component,
|
|
104
|
-
components
|
|
105
|
-
}) => {
|
|
106
|
-
const elements = [];
|
|
107
|
-
for (const child of children) {
|
|
108
|
-
if (child.type === "text") {
|
|
109
|
-
elements.push(child.value);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const childInstance = instances.get(child.value);
|
|
113
|
-
if (childInstance === void 0) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const childInstanceSelector = [child.value, ...instanceSelector];
|
|
117
|
-
const children2 = createInstanceChildrenElements({
|
|
118
|
-
instances,
|
|
119
|
-
instanceSelector: childInstanceSelector,
|
|
120
|
-
children: childInstance.children,
|
|
121
|
-
Component,
|
|
122
|
-
components
|
|
123
|
-
});
|
|
124
|
-
const element = createInstanceElement({
|
|
125
|
-
instance: childInstance,
|
|
126
|
-
instanceSelector: childInstanceSelector,
|
|
127
|
-
Component,
|
|
128
|
-
children: children2,
|
|
129
|
-
components
|
|
130
|
-
});
|
|
131
|
-
elements.push(element);
|
|
132
|
-
}
|
|
133
|
-
return elements;
|
|
134
|
-
};
|
|
135
|
-
const createInstanceElement = ({
|
|
136
|
-
Component,
|
|
137
|
-
instance,
|
|
138
|
-
instanceSelector,
|
|
139
|
-
children = [],
|
|
140
|
-
components
|
|
141
|
-
}) => {
|
|
142
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
-
Component,
|
|
144
|
-
{
|
|
145
|
-
instance,
|
|
146
|
-
instanceSelector,
|
|
147
|
-
components,
|
|
148
|
-
children
|
|
149
|
-
},
|
|
150
|
-
instance.id
|
|
151
|
-
);
|
|
152
|
-
};
|
package/lib/cjs/tree/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var tree_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(tree_exports);
|
|
18
|
-
__reExport(tree_exports, require("./create-elements-tree"), module.exports);
|
|
19
|
-
__reExport(tree_exports, require("./root"), module.exports);
|
|
20
|
-
__reExport(tree_exports, require("./webstudio-component"), module.exports);
|
package/lib/cjs/tree/root.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var root_exports = {};
|
|
20
|
-
__export(root_exports, {
|
|
21
|
-
InstanceRoot: () => InstanceRoot
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(root_exports);
|
|
24
|
-
var import_react = require("react");
|
|
25
|
-
var import_nanostores = require("nanostores");
|
|
26
|
-
var import_project_build = require("@webstudio-is/project-build");
|
|
27
|
-
var import_create_elements_tree = require("./create-elements-tree");
|
|
28
|
-
var import_webstudio_component = require("./webstudio-component");
|
|
29
|
-
var import_props = require("../props");
|
|
30
|
-
const InstanceRoot = ({
|
|
31
|
-
data,
|
|
32
|
-
utils,
|
|
33
|
-
Component,
|
|
34
|
-
components,
|
|
35
|
-
scripts
|
|
36
|
-
}) => {
|
|
37
|
-
const {
|
|
38
|
-
indexesWithinAncestors,
|
|
39
|
-
executeComputingExpressions,
|
|
40
|
-
executeEffectfulExpression
|
|
41
|
-
} = utils;
|
|
42
|
-
const dataSourceVariablesStoreRef = (0, import_react.useRef)(void 0);
|
|
43
|
-
if (dataSourceVariablesStoreRef.current === void 0) {
|
|
44
|
-
dataSourceVariablesStoreRef.current = (0, import_nanostores.atom)(/* @__PURE__ */ new Map());
|
|
45
|
-
}
|
|
46
|
-
const dataSourceVariablesStore = dataSourceVariablesStoreRef.current;
|
|
47
|
-
const dataSourceValuesStoreRef = (0, import_react.useRef)(void 0);
|
|
48
|
-
if (dataSourceValuesStoreRef.current === void 0) {
|
|
49
|
-
dataSourceValuesStoreRef.current = (0, import_nanostores.computed)(
|
|
50
|
-
dataSourceVariablesStore,
|
|
51
|
-
(dataSourceVariables) => {
|
|
52
|
-
const dataSourceValues = /* @__PURE__ */ new Map();
|
|
53
|
-
for (const [dataSourceId, dataSource] of data.build.dataSources) {
|
|
54
|
-
if (dataSource.type === "variable") {
|
|
55
|
-
const value = dataSourceVariables.get(dataSourceId) ?? dataSource.value.value;
|
|
56
|
-
dataSourceValues.set(dataSourceId, value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const result = executeComputingExpressions(dataSourceValues);
|
|
61
|
-
for (const [id, value] of result) {
|
|
62
|
-
dataSourceValues.set(id, value);
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error(error);
|
|
66
|
-
}
|
|
67
|
-
return dataSourceValues;
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
const dataSourceValuesStore = dataSourceValuesStoreRef.current;
|
|
72
|
-
const onDataSourceUpdate = (0, import_react.useCallback)(
|
|
73
|
-
(newValues) => {
|
|
74
|
-
const dataSourceVariables = new Map(dataSourceVariablesStore.get());
|
|
75
|
-
for (const [dataSourceId, value] of newValues) {
|
|
76
|
-
dataSourceVariables.set(dataSourceId, value);
|
|
77
|
-
}
|
|
78
|
-
dataSourceVariablesStore.set(dataSourceVariables);
|
|
79
|
-
},
|
|
80
|
-
[dataSourceVariablesStore]
|
|
81
|
-
);
|
|
82
|
-
return (0, import_create_elements_tree.createElementsTree)({
|
|
83
|
-
imageBaseUrl: data.params?.imageBaseUrl ?? "/",
|
|
84
|
-
assetBaseUrl: data.params?.assetBaseUrl ?? "/",
|
|
85
|
-
instances: new Map(data.build.instances),
|
|
86
|
-
rootInstanceId: data.page.rootInstanceId,
|
|
87
|
-
propsByInstanceIdStore: (0, import_nanostores.atom)(
|
|
88
|
-
(0, import_props.getPropsByInstanceId)(new Map(data.build.props))
|
|
89
|
-
),
|
|
90
|
-
assetsStore: (0, import_nanostores.atom)(new Map(data.assets.map((asset) => [asset.id, asset]))),
|
|
91
|
-
pagesStore: (0, import_nanostores.atom)(new Map(data.pages.map((page) => [page.id, page]))),
|
|
92
|
-
indexesWithinAncestors,
|
|
93
|
-
executeEffectfulExpression,
|
|
94
|
-
dataSourceValuesStore,
|
|
95
|
-
onDataSourceUpdate,
|
|
96
|
-
Component: Component ?? import_webstudio_component.WebstudioComponent,
|
|
97
|
-
components,
|
|
98
|
-
scripts
|
|
99
|
-
});
|
|
100
|
-
};
|