@plasmicapp/host 1.0.130 → 1.0.132

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.
Files changed (36) hide show
  1. package/dist/canvas-host.d.ts +41 -41
  2. package/dist/common.d.ts +1 -1
  3. package/dist/data.d.ts +43 -43
  4. package/dist/element-types.d.ts +115 -115
  5. package/dist/exports.d.ts +10 -10
  6. package/dist/fetcher.d.ts +40 -40
  7. package/dist/global-actions.d.ts +9 -9
  8. package/dist/host.esm.js +380 -383
  9. package/dist/host.esm.js.map +1 -1
  10. package/dist/index.cjs.js +380 -383
  11. package/dist/index.cjs.js.map +1 -1
  12. package/dist/index.d.ts +1 -1
  13. package/dist/lang-utils.d.ts +3 -3
  14. package/dist/registerComponent.d.ts +590 -589
  15. package/dist/registerGlobalContext.d.ts +75 -75
  16. package/dist/registerToken.d.ts +13 -13
  17. package/dist/registerTrait.d.ts +20 -20
  18. package/dist/repeatedElement.d.ts +15 -15
  19. package/dist/useForceUpdate.d.ts +1 -1
  20. package/dist/version.d.ts +1 -1
  21. package/package.json +5 -6
  22. package/registerComponent/dist/element-types.d.ts +115 -115
  23. package/registerComponent/dist/index.cjs.js +12 -12
  24. package/registerComponent/dist/index.esm.js +12 -12
  25. package/registerComponent/dist/registerComponent.d.ts +590 -589
  26. package/registerGlobalContext/dist/element-types.d.ts +115 -115
  27. package/registerGlobalContext/dist/index.cjs.js +12 -12
  28. package/registerGlobalContext/dist/index.esm.js +12 -12
  29. package/registerGlobalContext/dist/registerComponent.d.ts +590 -589
  30. package/registerGlobalContext/dist/registerGlobalContext.d.ts +75 -75
  31. package/registerToken/dist/index.cjs.js +6 -6
  32. package/registerToken/dist/index.esm.js +6 -6
  33. package/registerToken/dist/registerToken.d.ts +13 -13
  34. package/registerTrait/dist/index.cjs.js +9 -9
  35. package/registerTrait/dist/index.esm.js +9 -9
  36. package/registerTrait/dist/registerTrait.d.ts +20 -20
package/dist/host.esm.js CHANGED
@@ -46,390 +46,393 @@ var __assign = function() {
46
46
  return __assign.apply(this, arguments);
47
47
  };
48
48
 
49
- function isString(x) {
50
- return typeof x === "string";
51
- }
52
- function ensure(x, msg) {
53
- if (msg === void 0) { msg = ""; }
54
- if (x === null || x === undefined) {
55
- debugger;
56
- msg = (isString(msg) ? msg : msg()) || "";
57
- throw new Error("Value must not be undefined or null" + (msg ? "- " + msg : ""));
58
- }
59
- else {
60
- return x;
61
- }
49
+ function isString(x) {
50
+ return typeof x === "string";
51
+ }
52
+ function ensure(x, msg) {
53
+ if (msg === void 0) { msg = ""; }
54
+ if (x === null || x === undefined) {
55
+ debugger;
56
+ msg = (isString(msg) ? msg : msg()) || "";
57
+ throw new Error("Value must not be undefined or null".concat(msg ? "- ".concat(msg) : ""));
58
+ }
59
+ else {
60
+ return x;
61
+ }
62
62
  }
63
63
 
64
- function useForceUpdate() {
65
- var _a = useState(0), setTick = _a[1];
66
- var update = useCallback(function () {
67
- setTick(function (tick) { return tick + 1; });
68
- }, []);
69
- return update;
64
+ function useForceUpdate() {
65
+ var _a = useState(0), setTick = _a[1];
66
+ var update = useCallback(function () {
67
+ setTick(function (tick) { return tick + 1; });
68
+ }, []);
69
+ return update;
70
70
  }
71
71
 
72
- var rootChangeListeners = [];
73
- var PlasmicRootNodeWrapper = /** @class */ (function () {
74
- function PlasmicRootNodeWrapper(value) {
75
- var _this = this;
76
- this.value = value;
77
- this.set = function (val) {
78
- _this.value = val;
79
- rootChangeListeners.forEach(function (f) { return f(); });
80
- };
81
- this.get = function () { return _this.value; };
82
- }
83
- return PlasmicRootNodeWrapper;
84
- }());
85
- var plasmicRootNode = new PlasmicRootNodeWrapper(null);
86
- function getHashParams() {
87
- return new URLSearchParams(location.hash.replace(/^#/, "?"));
88
- }
89
- function getPlasmicOrigin() {
90
- var params = getHashParams();
91
- return ensure(params.get("origin"), "Missing information from Plasmic window.");
92
- }
93
- function getStudioHash() {
94
- var hashParams = getHashParams();
95
- if (hashParams.has("studioHash")) {
96
- return hashParams.get("studioHash");
97
- }
98
- var urlParams = new URL(location.href).searchParams;
99
- return urlParams.get("studio-hash");
100
- }
101
- function renderStudioIntoIframe() {
102
- var script = document.createElement("script");
103
- var plasmicOrigin = getPlasmicOrigin();
104
- var hash = getStudioHash();
105
- script.src = plasmicOrigin + "/static/js/studio" + (hash ? "." + hash + ".js" : ".js");
106
- document.body.appendChild(script);
107
- }
108
- var renderCount = 0;
109
- function setPlasmicRootNode(node) {
110
- // Keep track of renderCount, which we use as key to ErrorBoundary, so
111
- // we can reset the error on each render
112
- renderCount++;
113
- plasmicRootNode.set(node);
114
- }
115
- /**
116
- * React context to detect whether the component is rendered on Plasmic editor.
117
- * If not, return false.
118
- * If so, return an object with more information about the component
119
- */
120
- var PlasmicCanvasContext = React.createContext(false);
121
- var usePlasmicCanvasContext = function () {
122
- return React.useContext(PlasmicCanvasContext);
123
- };
124
- function _PlasmicCanvasHost() {
125
- var _a, _b;
126
- // If window.parent is null, then this is a window whose containing iframe
127
- // has been detached from the DOM (for the top window, window.parent === window).
128
- // In that case, we shouldn't do anything. If window.parent is null, by the way,
129
- // location.hash will also be null.
130
- var isFrameAttached = !!window.parent;
131
- var isCanvas = !!((_a = location.hash) === null || _a === void 0 ? void 0 : _a.match(/\bcanvas=true\b/));
132
- var isLive = !!((_b = location.hash) === null || _b === void 0 ? void 0 : _b.match(/\blive=true\b/)) || !isFrameAttached;
133
- var shouldRenderStudio = isFrameAttached &&
134
- !document.querySelector("#plasmic-studio-tag") &&
135
- !isCanvas &&
136
- !isLive;
137
- var forceUpdate = useForceUpdate();
138
- React.useLayoutEffect(function () {
139
- rootChangeListeners.push(forceUpdate);
140
- return function () {
141
- var index = rootChangeListeners.indexOf(forceUpdate);
142
- if (index >= 0) {
143
- rootChangeListeners.splice(index, 1);
144
- }
145
- };
146
- }, [forceUpdate]);
147
- React.useEffect(function () {
148
- if (shouldRenderStudio && isFrameAttached && window.parent !== window) {
149
- renderStudioIntoIframe();
150
- }
151
- }, [shouldRenderStudio, isFrameAttached]);
152
- React.useEffect(function () {
153
- if (!shouldRenderStudio && !document.querySelector("#getlibs") && isLive) {
154
- var scriptElt = document.createElement("script");
155
- scriptElt.id = "getlibs";
156
- scriptElt.src = getPlasmicOrigin() + "/static/js/getlibs.js";
157
- scriptElt.async = false;
158
- scriptElt.onload = function () {
159
- var _a, _b;
160
- (_b = (_a = window).__GetlibsReadyResolver) === null || _b === void 0 ? void 0 : _b.call(_a);
161
- };
162
- document.head.append(scriptElt);
163
- }
164
- }, [shouldRenderStudio]);
165
- var _c = React.useState(function () {
166
- return deriveCanvasContextValue();
167
- }), canvasContextValue = _c[0], setCanvasContextValue = _c[1];
168
- React.useEffect(function () {
169
- if (isCanvas) {
170
- var listener_1 = function () {
171
- setCanvasContextValue(deriveCanvasContextValue());
172
- };
173
- window.addEventListener("hashchange", listener_1);
174
- return function () { return window.removeEventListener("hashchange", listener_1); };
175
- }
176
- return undefined;
177
- }, [isCanvas]);
178
- if (!isFrameAttached) {
179
- return null;
180
- }
181
- if (isCanvas || isLive) {
182
- var appDiv = document.querySelector("#plasmic-app.__wab_user-body");
183
- if (!appDiv) {
184
- appDiv = document.createElement("div");
185
- appDiv.id = "plasmic-app";
186
- appDiv.classList.add("__wab_user-body");
187
- document.body.appendChild(appDiv);
188
- }
189
- return ReactDOM.createPortal(React.createElement(ErrorBoundary, { key: "" + renderCount },
190
- React.createElement(PlasmicCanvasContext.Provider, { value: canvasContextValue }, plasmicRootNode.get())), appDiv, "plasmic-app");
191
- }
192
- if (shouldRenderStudio && window.parent === window) {
193
- return (React.createElement("iframe", { src: "https://docs.plasmic.app/app-content/app-host-ready#appHostUrl=" + encodeURIComponent(location.href), style: {
194
- width: "100vw",
195
- height: "100vh",
196
- border: "none",
197
- position: "fixed",
198
- top: 0,
199
- left: 0,
200
- zIndex: 99999999,
201
- } }));
202
- }
203
- return null;
204
- }
205
- var PlasmicCanvasHost = function (props) {
206
- var enableWebpackHmr = props.enableWebpackHmr;
207
- var _a = React.useState(null), node = _a[0], setNode = _a[1];
208
- React.useEffect(function () {
209
- setNode(React.createElement(_PlasmicCanvasHost, null));
210
- }, []);
211
- return (React.createElement(React.Fragment, null,
212
- !enableWebpackHmr && React.createElement(DisableWebpackHmr, null),
213
- node));
214
- };
215
- var renderErrorListeners = [];
216
- function registerRenderErrorListener(listener) {
217
- renderErrorListeners.push(listener);
218
- return function () {
219
- var index = renderErrorListeners.indexOf(listener);
220
- if (index >= 0) {
221
- renderErrorListeners.splice(index, 1);
222
- }
223
- };
224
- }
225
- var ErrorBoundary = /** @class */ (function (_super) {
226
- __extends(ErrorBoundary, _super);
227
- function ErrorBoundary(props) {
228
- var _this = _super.call(this, props) || this;
229
- _this.state = {};
230
- return _this;
231
- }
232
- ErrorBoundary.getDerivedStateFromError = function (error) {
233
- return { error: error };
234
- };
235
- ErrorBoundary.prototype.componentDidCatch = function (error) {
236
- renderErrorListeners.forEach(function (listener) { return listener(error); });
237
- };
238
- ErrorBoundary.prototype.render = function () {
239
- if (this.state.error) {
240
- return React.createElement("div", null,
241
- "Error: ", "" + this.state.error.message);
242
- }
243
- else {
244
- return React.createElement(React.Fragment, null, this.props.children);
245
- }
246
- };
247
- return ErrorBoundary;
248
- }(React.Component));
249
- function DisableWebpackHmr() {
250
- if (process.env.NODE_ENV === "production") {
251
- return null;
252
- }
253
- return (React.createElement("script", { type: "text/javascript", dangerouslySetInnerHTML: {
254
- __html: "\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n ",
255
- } }));
256
- }
257
- function deriveCanvasContextValue() {
258
- var _a;
259
- var hash = window.location.hash;
260
- if (hash && hash.length > 0) {
261
- // create URLsearchParams skipping the initial # character
262
- var params = new URLSearchParams(hash.substring(1));
263
- if (params.get("canvas") === "true") {
264
- var globalVariants = params.get("globalVariants");
265
- return {
266
- componentName: (_a = params.get("componentName")) !== null && _a !== void 0 ? _a : null,
267
- globalVariants: globalVariants ? JSON.parse(globalVariants) : {},
268
- interactive: params.get("interactive") === "true",
269
- };
270
- }
271
- }
272
- return false;
72
+ if (globalThis.__PlasmicHostVersion == null) {
73
+ globalThis.__PlasmicHostVersion = "2";
74
+ }
75
+ var rootChangeListeners = [];
76
+ var PlasmicRootNodeWrapper = /** @class */ (function () {
77
+ function PlasmicRootNodeWrapper(value) {
78
+ var _this = this;
79
+ this.value = value;
80
+ this.set = function (val) {
81
+ _this.value = val;
82
+ rootChangeListeners.forEach(function (f) { return f(); });
83
+ };
84
+ this.get = function () { return _this.value; };
85
+ }
86
+ return PlasmicRootNodeWrapper;
87
+ }());
88
+ var plasmicRootNode = new PlasmicRootNodeWrapper(null);
89
+ function getHashParams() {
90
+ return new URLSearchParams(location.hash.replace(/^#/, "?"));
91
+ }
92
+ function getPlasmicOrigin() {
93
+ var params = getHashParams();
94
+ return ensure(params.get("origin"), "Missing information from Plasmic window.");
95
+ }
96
+ function getStudioHash() {
97
+ var hashParams = getHashParams();
98
+ if (hashParams.has("studioHash")) {
99
+ return hashParams.get("studioHash");
100
+ }
101
+ var urlParams = new URL(location.href).searchParams;
102
+ return urlParams.get("studio-hash");
103
+ }
104
+ function renderStudioIntoIframe() {
105
+ var script = document.createElement("script");
106
+ var plasmicOrigin = getPlasmicOrigin();
107
+ var hash = getStudioHash();
108
+ script.src = "".concat(plasmicOrigin, "/static/js/studio").concat(hash ? ".".concat(hash, ".js") : ".js");
109
+ document.body.appendChild(script);
110
+ }
111
+ var renderCount = 0;
112
+ function setPlasmicRootNode(node) {
113
+ // Keep track of renderCount, which we use as key to ErrorBoundary, so
114
+ // we can reset the error on each render
115
+ renderCount++;
116
+ plasmicRootNode.set(node);
117
+ }
118
+ /**
119
+ * React context to detect whether the component is rendered on Plasmic editor.
120
+ * If not, return false.
121
+ * If so, return an object with more information about the component
122
+ */
123
+ var PlasmicCanvasContext = React.createContext(false);
124
+ var usePlasmicCanvasContext = function () {
125
+ return React.useContext(PlasmicCanvasContext);
126
+ };
127
+ function _PlasmicCanvasHost() {
128
+ var _a, _b;
129
+ // If window.parent is null, then this is a window whose containing iframe
130
+ // has been detached from the DOM (for the top window, window.parent === window).
131
+ // In that case, we shouldn't do anything. If window.parent is null, by the way,
132
+ // location.hash will also be null.
133
+ var isFrameAttached = !!window.parent;
134
+ var isCanvas = !!((_a = location.hash) === null || _a === void 0 ? void 0 : _a.match(/\bcanvas=true\b/));
135
+ var isLive = !!((_b = location.hash) === null || _b === void 0 ? void 0 : _b.match(/\blive=true\b/)) || !isFrameAttached;
136
+ var shouldRenderStudio = isFrameAttached &&
137
+ !document.querySelector("#plasmic-studio-tag") &&
138
+ !isCanvas &&
139
+ !isLive;
140
+ var forceUpdate = useForceUpdate();
141
+ React.useLayoutEffect(function () {
142
+ rootChangeListeners.push(forceUpdate);
143
+ return function () {
144
+ var index = rootChangeListeners.indexOf(forceUpdate);
145
+ if (index >= 0) {
146
+ rootChangeListeners.splice(index, 1);
147
+ }
148
+ };
149
+ }, [forceUpdate]);
150
+ React.useEffect(function () {
151
+ if (shouldRenderStudio && isFrameAttached && window.parent !== window) {
152
+ renderStudioIntoIframe();
153
+ }
154
+ }, [shouldRenderStudio, isFrameAttached]);
155
+ React.useEffect(function () {
156
+ if (!shouldRenderStudio && !document.querySelector("#getlibs") && isLive) {
157
+ var scriptElt = document.createElement("script");
158
+ scriptElt.id = "getlibs";
159
+ scriptElt.src = getPlasmicOrigin() + "/static/js/getlibs.js";
160
+ scriptElt.async = false;
161
+ scriptElt.onload = function () {
162
+ var _a, _b;
163
+ (_b = (_a = window).__GetlibsReadyResolver) === null || _b === void 0 ? void 0 : _b.call(_a);
164
+ };
165
+ document.head.append(scriptElt);
166
+ }
167
+ }, [shouldRenderStudio]);
168
+ var _c = React.useState(function () {
169
+ return deriveCanvasContextValue();
170
+ }), canvasContextValue = _c[0], setCanvasContextValue = _c[1];
171
+ React.useEffect(function () {
172
+ if (isCanvas) {
173
+ var listener_1 = function () {
174
+ setCanvasContextValue(deriveCanvasContextValue());
175
+ };
176
+ window.addEventListener("hashchange", listener_1);
177
+ return function () { return window.removeEventListener("hashchange", listener_1); };
178
+ }
179
+ return undefined;
180
+ }, [isCanvas]);
181
+ if (!isFrameAttached) {
182
+ return null;
183
+ }
184
+ if (isCanvas || isLive) {
185
+ var appDiv = document.querySelector("#plasmic-app.__wab_user-body");
186
+ if (!appDiv) {
187
+ appDiv = document.createElement("div");
188
+ appDiv.id = "plasmic-app";
189
+ appDiv.classList.add("__wab_user-body");
190
+ document.body.appendChild(appDiv);
191
+ }
192
+ return ReactDOM.createPortal(React.createElement(ErrorBoundary, { key: "".concat(renderCount) },
193
+ React.createElement(PlasmicCanvasContext.Provider, { value: canvasContextValue }, plasmicRootNode.get())), appDiv, "plasmic-app");
194
+ }
195
+ if (shouldRenderStudio && window.parent === window) {
196
+ return (React.createElement("iframe", { src: "https://docs.plasmic.app/app-content/app-host-ready#appHostUrl=".concat(encodeURIComponent(location.href)), style: {
197
+ width: "100vw",
198
+ height: "100vh",
199
+ border: "none",
200
+ position: "fixed",
201
+ top: 0,
202
+ left: 0,
203
+ zIndex: 99999999,
204
+ } }));
205
+ }
206
+ return null;
207
+ }
208
+ var PlasmicCanvasHost = function (props) {
209
+ var enableWebpackHmr = props.enableWebpackHmr;
210
+ var _a = React.useState(null), node = _a[0], setNode = _a[1];
211
+ React.useEffect(function () {
212
+ setNode(React.createElement(_PlasmicCanvasHost, null));
213
+ }, []);
214
+ return (React.createElement(React.Fragment, null,
215
+ !enableWebpackHmr && React.createElement(DisableWebpackHmr, null),
216
+ node));
217
+ };
218
+ var renderErrorListeners = [];
219
+ function registerRenderErrorListener(listener) {
220
+ renderErrorListeners.push(listener);
221
+ return function () {
222
+ var index = renderErrorListeners.indexOf(listener);
223
+ if (index >= 0) {
224
+ renderErrorListeners.splice(index, 1);
225
+ }
226
+ };
227
+ }
228
+ var ErrorBoundary = /** @class */ (function (_super) {
229
+ __extends(ErrorBoundary, _super);
230
+ function ErrorBoundary(props) {
231
+ var _this = _super.call(this, props) || this;
232
+ _this.state = {};
233
+ return _this;
234
+ }
235
+ ErrorBoundary.getDerivedStateFromError = function (error) {
236
+ return { error: error };
237
+ };
238
+ ErrorBoundary.prototype.componentDidCatch = function (error) {
239
+ renderErrorListeners.forEach(function (listener) { return listener(error); });
240
+ };
241
+ ErrorBoundary.prototype.render = function () {
242
+ if (this.state.error) {
243
+ return React.createElement("div", null,
244
+ "Error: ", "".concat(this.state.error.message));
245
+ }
246
+ else {
247
+ return React.createElement(React.Fragment, null, this.props.children);
248
+ }
249
+ };
250
+ return ErrorBoundary;
251
+ }(React.Component));
252
+ function DisableWebpackHmr() {
253
+ if (process.env.NODE_ENV === "production") {
254
+ return null;
255
+ }
256
+ return (React.createElement("script", { type: "text/javascript", dangerouslySetInnerHTML: {
257
+ __html: "\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n ",
258
+ } }));
259
+ }
260
+ function deriveCanvasContextValue() {
261
+ var _a;
262
+ var hash = window.location.hash;
263
+ if (hash && hash.length > 0) {
264
+ // create URLsearchParams skipping the initial # character
265
+ var params = new URLSearchParams(hash.substring(1));
266
+ if (params.get("canvas") === "true") {
267
+ var globalVariants = params.get("globalVariants");
268
+ return {
269
+ componentName: (_a = params.get("componentName")) !== null && _a !== void 0 ? _a : null,
270
+ globalVariants: globalVariants ? JSON.parse(globalVariants) : {},
271
+ interactive: params.get("interactive") === "true",
272
+ };
273
+ }
274
+ }
275
+ return false;
273
276
  }
274
277
 
275
- var tuple = function () {
276
- var args = [];
277
- for (var _i = 0; _i < arguments.length; _i++) {
278
- args[_i] = arguments[_i];
279
- }
280
- return args;
278
+ var tuple = function () {
279
+ var args = [];
280
+ for (var _i = 0; _i < arguments.length; _i++) {
281
+ args[_i] = arguments[_i];
282
+ }
283
+ return args;
281
284
  };
282
285
 
283
- var DataContext = createContext(undefined);
284
- function mkMetaName(name) {
285
- return "__plasmic_meta_" + name;
286
- }
287
- function mkMetaValue(meta) {
288
- return meta;
289
- }
290
- function applySelector(rawData, selector) {
291
- if (!selector) {
292
- return undefined;
293
- }
294
- var curData = rawData;
295
- for (var _i = 0, _a = selector.split("."); _i < _a.length; _i++) {
296
- var key = _a[_i];
297
- curData = curData === null || curData === void 0 ? void 0 : curData[key];
298
- }
299
- return curData;
300
- }
301
- function useSelector(selector) {
302
- var rawData = useDataEnv();
303
- return applySelector(rawData, selector);
304
- }
305
- function useSelectors(selectors) {
306
- if (selectors === void 0) { selectors = {}; }
307
- var rawData = useDataEnv();
308
- return Object.fromEntries(Object.entries(selectors)
309
- .filter(function (_a) {
310
- var key = _a[0], selector = _a[1];
311
- return !!key && !!selector;
312
- })
313
- .map(function (_a) {
314
- var key = _a[0], selector = _a[1];
315
- return tuple(key, applySelector(rawData, selector));
316
- }));
317
- }
318
- function useDataEnv() {
319
- return useContext(DataContext);
320
- }
321
- function DataProvider(_a) {
322
- var _b;
323
- var _c;
324
- var name = _a.name, data = _a.data, hidden = _a.hidden, label = _a.label, children = _a.children;
325
- var existingEnv = (_c = useDataEnv()) !== null && _c !== void 0 ? _c : {};
326
- if (!name) {
327
- return React__default.createElement(React__default.Fragment, null, children);
328
- }
329
- else {
330
- return (React__default.createElement(DataContext.Provider, { value: __assign(__assign({}, existingEnv), (_b = {}, _b[name] = data, _b[mkMetaName(name)] = mkMetaValue({ hidden: hidden, label: label }), _b)) }, children));
331
- }
332
- }
333
- function PageParamsProvider(_a) {
334
- var children = _a.children, _b = _a.params, params = _b === void 0 ? {} : _b, _c = _a.query, query = _c === void 0 ? {} : _c;
335
- var $ctx = useDataEnv() || {};
336
- return (React__default.createElement(DataProvider, { name: "params", data: __assign(__assign({}, $ctx.params), params), label: "Page URL path params" },
337
- React__default.createElement(DataProvider, { name: "query", data: __assign(__assign({}, $ctx.query), query), label: "Page URL query params" }, children)));
338
- }
339
- function DataCtxReader(_a) {
340
- var children = _a.children;
341
- var $ctx = useDataEnv();
342
- return children($ctx);
286
+ var DataContext = createContext(undefined);
287
+ function mkMetaName(name) {
288
+ return "__plasmic_meta_".concat(name);
289
+ }
290
+ function mkMetaValue(meta) {
291
+ return meta;
292
+ }
293
+ function applySelector(rawData, selector) {
294
+ if (!selector) {
295
+ return undefined;
296
+ }
297
+ var curData = rawData;
298
+ for (var _i = 0, _a = selector.split("."); _i < _a.length; _i++) {
299
+ var key = _a[_i];
300
+ curData = curData === null || curData === void 0 ? void 0 : curData[key];
301
+ }
302
+ return curData;
303
+ }
304
+ function useSelector(selector) {
305
+ var rawData = useDataEnv();
306
+ return applySelector(rawData, selector);
307
+ }
308
+ function useSelectors(selectors) {
309
+ if (selectors === void 0) { selectors = {}; }
310
+ var rawData = useDataEnv();
311
+ return Object.fromEntries(Object.entries(selectors)
312
+ .filter(function (_a) {
313
+ var key = _a[0], selector = _a[1];
314
+ return !!key && !!selector;
315
+ })
316
+ .map(function (_a) {
317
+ var key = _a[0], selector = _a[1];
318
+ return tuple(key, applySelector(rawData, selector));
319
+ }));
320
+ }
321
+ function useDataEnv() {
322
+ return useContext(DataContext);
323
+ }
324
+ function DataProvider(_a) {
325
+ var _b;
326
+ var _c;
327
+ var name = _a.name, data = _a.data, hidden = _a.hidden, label = _a.label, children = _a.children;
328
+ var existingEnv = (_c = useDataEnv()) !== null && _c !== void 0 ? _c : {};
329
+ if (!name) {
330
+ return React__default.createElement(React__default.Fragment, null, children);
331
+ }
332
+ else {
333
+ return (React__default.createElement(DataContext.Provider, { value: __assign(__assign({}, existingEnv), (_b = {}, _b[name] = data, _b[mkMetaName(name)] = mkMetaValue({ hidden: hidden, label: label }), _b)) }, children));
334
+ }
335
+ }
336
+ function PageParamsProvider(_a) {
337
+ var children = _a.children, _b = _a.params, params = _b === void 0 ? {} : _b, _c = _a.query, query = _c === void 0 ? {} : _c;
338
+ var $ctx = useDataEnv() || {};
339
+ return (React__default.createElement(DataProvider, { name: "params", data: __assign(__assign({}, $ctx.params), params), label: "Page URL path params" },
340
+ React__default.createElement(DataProvider, { name: "query", data: __assign(__assign({}, $ctx.query), query), label: "Page URL query params" }, children)));
341
+ }
342
+ function DataCtxReader(_a) {
343
+ var children = _a.children;
344
+ var $ctx = useDataEnv();
345
+ return children($ctx);
343
346
  }
344
347
 
345
- var root$6 = globalThis;
346
- root$6.__PlasmicFetcherRegistry = [];
347
- function registerFetcher(fetcher, meta) {
348
- root$6.__PlasmicFetcherRegistry.push({ fetcher: fetcher, meta: meta });
348
+ var root$6 = globalThis;
349
+ root$6.__PlasmicFetcherRegistry = [];
350
+ function registerFetcher(fetcher, meta) {
351
+ root$6.__PlasmicFetcherRegistry.push({ fetcher: fetcher, meta: meta });
349
352
  }
350
353
 
351
- var GlobalActionsContext = React__default.createContext(undefined);
352
- function GlobalActionsProvider(props) {
353
- var contextName = props.contextName, children = props.children, actions = props.actions;
354
- var namespacedActions = React__default.useMemo(function () {
355
- return Object.fromEntries(Object.entries(actions).map(function (_a) {
356
- var key = _a[0], val = _a[1];
357
- return [
358
- contextName + "." + key,
359
- val,
360
- ];
361
- }));
362
- }, [contextName, actions]);
363
- return (React__default.createElement(GlobalActionsContext.Provider, { value: namespacedActions }, children));
364
- }
365
- function useGlobalActions() {
366
- var _a;
367
- return (_a = React__default.useContext(GlobalActionsContext)) !== null && _a !== void 0 ? _a : {};
354
+ var GlobalActionsContext = React__default.createContext(undefined);
355
+ function GlobalActionsProvider(props) {
356
+ var contextName = props.contextName, children = props.children, actions = props.actions;
357
+ var namespacedActions = React__default.useMemo(function () {
358
+ return Object.fromEntries(Object.entries(actions).map(function (_a) {
359
+ var key = _a[0], val = _a[1];
360
+ return [
361
+ "".concat(contextName, ".").concat(key),
362
+ val,
363
+ ];
364
+ }));
365
+ }, [contextName, actions]);
366
+ return (React__default.createElement(GlobalActionsContext.Provider, { value: namespacedActions }, children));
367
+ }
368
+ function useGlobalActions() {
369
+ var _a;
370
+ return (_a = React__default.useContext(GlobalActionsContext)) !== null && _a !== void 0 ? _a : {};
368
371
  }
369
372
 
370
- var root$5 = globalThis;
371
- if (root$5.__PlasmicComponentRegistry == null) {
372
- root$5.__PlasmicComponentRegistry = [];
373
- }
374
- function registerComponent(component, meta) {
375
- // Check for duplicates
376
- if (root$5.__PlasmicComponentRegistry.some(function (r) {
377
- return r.component === component && r.meta.name === meta.name;
378
- })) {
379
- return;
380
- }
381
- root$5.__PlasmicComponentRegistry.push({ component: component, meta: meta });
373
+ var root$5 = globalThis;
374
+ if (root$5.__PlasmicComponentRegistry == null) {
375
+ root$5.__PlasmicComponentRegistry = [];
376
+ }
377
+ function registerComponent(component, meta) {
378
+ // Check for duplicates
379
+ if (root$5.__PlasmicComponentRegistry.some(function (r) {
380
+ return r.component === component && r.meta.name === meta.name;
381
+ })) {
382
+ return;
383
+ }
384
+ root$5.__PlasmicComponentRegistry.push({ component: component, meta: meta });
382
385
  }
383
386
 
384
- var root$4 = globalThis;
385
- if (root$4.__PlasmicContextRegistry == null) {
386
- root$4.__PlasmicContextRegistry = [];
387
- }
388
- function registerGlobalContext(component, meta) {
389
- // Check for duplicates
390
- if (root$4.__PlasmicContextRegistry.some(function (r) {
391
- return r.component === component && r.meta.name === meta.name;
392
- })) {
393
- return;
394
- }
395
- root$4.__PlasmicContextRegistry.push({ component: component, meta: meta });
387
+ var root$4 = globalThis;
388
+ if (root$4.__PlasmicContextRegistry == null) {
389
+ root$4.__PlasmicContextRegistry = [];
390
+ }
391
+ function registerGlobalContext(component, meta) {
392
+ // Check for duplicates
393
+ if (root$4.__PlasmicContextRegistry.some(function (r) {
394
+ return r.component === component && r.meta.name === meta.name;
395
+ })) {
396
+ return;
397
+ }
398
+ root$4.__PlasmicContextRegistry.push({ component: component, meta: meta });
396
399
  }
397
400
 
398
- var root$3 = globalThis;
399
- if (root$3.__PlasmicTokenRegistry == null) {
400
- root$3.__PlasmicTokenRegistry = [];
401
- }
402
- function registerToken(token) {
403
- root$3.__PlasmicTokenRegistry.push(token);
401
+ var root$3 = globalThis;
402
+ if (root$3.__PlasmicTokenRegistry == null) {
403
+ root$3.__PlasmicTokenRegistry = [];
404
+ }
405
+ function registerToken(token) {
406
+ root$3.__PlasmicTokenRegistry.push(token);
404
407
  }
405
408
 
406
- var root$2 = globalThis;
407
- if (root$2.__PlasmicTraitRegistry == null) {
408
- root$2.__PlasmicTraitRegistry = [];
409
- }
410
- function registerTrait(trait, meta) {
411
- root$2.__PlasmicTraitRegistry.push({
412
- trait: trait,
413
- meta: meta,
414
- });
409
+ var root$2 = globalThis;
410
+ if (root$2.__PlasmicTraitRegistry == null) {
411
+ root$2.__PlasmicTraitRegistry = [];
412
+ }
413
+ function registerTrait(trait, meta) {
414
+ root$2.__PlasmicTraitRegistry.push({
415
+ trait: trait,
416
+ meta: meta,
417
+ });
415
418
  }
416
419
 
417
- var _a, _b;
418
- function repeatedElement(index, elt) {
419
- return repeatedElementFn(index, elt);
420
- }
421
- var repeatedElementFn = function (index, elt) {
422
- if (Array.isArray(elt)) {
423
- return elt.map(function (v) { return repeatedElementFn(index, v); });
424
- }
425
- if (elt && isValidElement(elt) && typeof elt !== "string") {
426
- return cloneElement(elt);
427
- }
428
- return elt;
429
- };
430
- var root$1 = globalThis;
431
- var setRepeatedElementFn = (_b = (_a = root$1 === null || root$1 === void 0 ? void 0 : root$1.__Sub) === null || _a === void 0 ? void 0 : _a.setRepeatedElementFn) !== null && _b !== void 0 ? _b : function (fn) {
432
- repeatedElementFn = fn;
420
+ var _a, _b;
421
+ function repeatedElement(index, elt) {
422
+ return repeatedElementFn(index, elt);
423
+ }
424
+ var repeatedElementFn = function (index, elt) {
425
+ if (Array.isArray(elt)) {
426
+ return elt.map(function (v) { return repeatedElementFn(index, v); });
427
+ }
428
+ if (elt && isValidElement(elt) && typeof elt !== "string") {
429
+ return cloneElement(elt);
430
+ }
431
+ return elt;
432
+ };
433
+ var root$1 = globalThis;
434
+ var setRepeatedElementFn = (_b = (_a = root$1 === null || root$1 === void 0 ? void 0 : root$1.__Sub) === null || _a === void 0 ? void 0 : _a.setRepeatedElementFn) !== null && _b !== void 0 ? _b : function (fn) {
435
+ repeatedElementFn = fn;
433
436
  };
434
437
 
435
438
  var hostModule = /*#__PURE__*/Object.freeze({
@@ -458,28 +461,22 @@ var hostModule = /*#__PURE__*/Object.freeze({
458
461
  useGlobalActions: useGlobalActions
459
462
  });
460
463
 
461
- var hostVersion = "1.0.130";
464
+ var hostVersion = "1.0.132";
462
465
 
463
- var root = globalThis;
464
- if (root.__Sub == null) {
465
- // Creating a side effect here by logging, so that vite won't
466
- // ignore this block for whatever reason. Hiding this for now
467
- // as users are complaining; will have to check if this has
468
- // been fixed with vite.
469
- // console.log("Plasmic: Setting up app host dependencies");
470
- root.__Sub = __assign({ React: React,
471
- ReactDOM: ReactDOM,
472
- PlasmicQuery: PlasmicQuery,
473
- hostModule: hostModule,
474
- hostVersion: hostVersion, hostUtils: {
475
- setPlasmicRootNode: setPlasmicRootNode,
476
- registerRenderErrorListener: registerRenderErrorListener,
477
- setRepeatedElementFn: setRepeatedElementFn,
478
- },
479
- // For backwards compatibility:
480
- setPlasmicRootNode: setPlasmicRootNode,
481
- registerRenderErrorListener: registerRenderErrorListener,
482
- setRepeatedElementFn: setRepeatedElementFn }, hostModule);
466
+ var root = globalThis;
467
+ if (root.__Sub == null) {
468
+ // Creating a side effect here by logging, so that vite won't
469
+ // ignore this block for whatever reason. Hiding this for now
470
+ // as users are complaining; will have to check if this has
471
+ // been fixed with vite.
472
+ // console.log("Plasmic: Setting up app host dependencies");
473
+ root.__Sub = __assign({ React: React, ReactDOM: ReactDOM, PlasmicQuery: PlasmicQuery, hostModule: hostModule, hostVersion: hostVersion, hostUtils: {
474
+ setPlasmicRootNode: setPlasmicRootNode,
475
+ registerRenderErrorListener: registerRenderErrorListener,
476
+ setRepeatedElementFn: setRepeatedElementFn,
477
+ },
478
+ // For backwards compatibility:
479
+ setPlasmicRootNode: setPlasmicRootNode, registerRenderErrorListener: registerRenderErrorListener, setRepeatedElementFn: setRepeatedElementFn }, hostModule);
483
480
  }
484
481
 
485
482
  export { DataContext, DataCtxReader, DataProvider, GlobalActionsContext, GlobalActionsProvider, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, applySelector, mkMetaName, mkMetaValue, registerComponent, registerGlobalContext, registerToken, registerTrait, repeatedElement, registerFetcher as unstable_registerFetcher, useDataEnv, useGlobalActions, usePlasmicCanvasContext, useSelector, useSelectors };