@plasmicapp/host 1.0.128 → 1.0.130

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/dist/host.esm.js CHANGED
@@ -1,562 +1,485 @@
1
- 'use client';import * as PlasmicQuery from '@plasmicapp/query';
1
+ 'use client';
2
+ import * as PlasmicQuery from '@plasmicapp/query';
2
3
  import * as React from 'react';
3
- import React__default, { useState, useCallback, createContext, useContext, useEffect, createElement, Fragment, useLayoutEffect, Component, isValidElement, cloneElement } from 'react';
4
+ import React__default, { useState, useCallback, createContext, useContext, isValidElement, cloneElement } from 'react';
4
5
  import * as ReactDOM from 'react-dom';
5
- import { createPortal } from 'react-dom';
6
6
 
7
- function _extends() {
8
- _extends = Object.assign ? Object.assign.bind() : function (target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
- for (var key in source) {
12
- if (Object.prototype.hasOwnProperty.call(source, key)) {
13
- target[key] = source[key];
14
- }
15
- }
16
- }
17
- return target;
18
- };
19
- return _extends.apply(this, arguments);
20
- }
21
- function _inheritsLoose(subClass, superClass) {
22
- subClass.prototype = Object.create(superClass.prototype);
23
- subClass.prototype.constructor = subClass;
24
- _setPrototypeOf(subClass, superClass);
25
- }
26
- function _setPrototypeOf(o, p) {
27
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
28
- o.__proto__ = p;
29
- return o;
30
- };
31
- return _setPrototypeOf(o, p);
32
- }
33
- function _unsupportedIterableToArray(o, minLen) {
34
- if (!o) return;
35
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
36
- var n = Object.prototype.toString.call(o).slice(8, -1);
37
- if (n === "Object" && o.constructor) n = o.constructor.name;
38
- if (n === "Map" || n === "Set") return Array.from(o);
39
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
40
- }
41
- function _arrayLikeToArray(arr, len) {
42
- if (len == null || len > arr.length) len = arr.length;
43
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
44
- return arr2;
45
- }
46
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
47
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
48
- if (it) return (it = it.call(o)).next.bind(it);
49
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
50
- if (it) o = it;
51
- var i = 0;
52
- return function () {
53
- if (i >= o.length) return {
54
- done: true
55
- };
56
- return {
57
- done: false,
58
- value: o[i++]
59
- };
60
- };
61
- }
62
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
63
- }
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise */
22
+
23
+ var extendStatics = function(d, b) {
24
+ extendStatics = Object.setPrototypeOf ||
25
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
27
+ return extendStatics(d, b);
28
+ };
29
+
30
+ function __extends(d, b) {
31
+ if (typeof b !== "function" && b !== null)
32
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
+ extendStatics(d, b);
34
+ function __() { this.constructor = d; }
35
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
+ }
37
+
38
+ var __assign = function() {
39
+ __assign = Object.assign || function __assign(t) {
40
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
41
+ s = arguments[i];
42
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
43
+ }
44
+ return t;
45
+ };
46
+ return __assign.apply(this, arguments);
47
+ };
64
48
 
65
- function isString(x) {
66
- return typeof x === "string";
67
- }
68
- function ensure(x, msg) {
69
- if (msg === void 0) {
70
- msg = "";
71
- }
72
- if (x === null || x === undefined) {
73
- debugger;
74
- msg = (isString(msg) ? msg : msg()) || "";
75
- throw new Error("Value must not be undefined or null" + (msg ? "- " + msg : ""));
76
- } else {
77
- return x;
78
- }
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
+ }
79
62
  }
80
63
 
81
- function useForceUpdate() {
82
- var _useState = useState(0),
83
- setTick = _useState[1];
84
- var update = useCallback(function () {
85
- setTick(function (tick) {
86
- return tick + 1;
87
- });
88
- }, []);
89
- 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;
90
70
  }
91
71
 
92
- var root = globalThis;
93
- if (root.__PlasmicHostVersion == null) {
94
- root.__PlasmicHostVersion = "2";
95
- }
96
- var rootChangeListeners = [];
97
- var PlasmicRootNodeWrapper = function PlasmicRootNodeWrapper(value) {
98
- var _this = this;
99
- this.value = value;
100
- this.set = function (val) {
101
- _this.value = val;
102
- rootChangeListeners.forEach(function (f) {
103
- return f();
104
- });
105
- };
106
- this.get = function () {
107
- return _this.value;
108
- };
109
- };
110
- var plasmicRootNode = /*#__PURE__*/new PlasmicRootNodeWrapper(null);
111
- function getHashParams() {
112
- return new URLSearchParams(location.hash.replace(/^#/, "?"));
113
- }
114
- function getPlasmicOrigin() {
115
- var params = getHashParams();
116
- return ensure(params.get("origin"), "Missing information from Plasmic window.");
117
- }
118
- function getStudioHash() {
119
- var hashParams = getHashParams();
120
- if (hashParams.has("studioHash")) {
121
- return hashParams.get("studioHash");
122
- }
123
- var urlParams = new URL(location.href).searchParams;
124
- return urlParams.get("studio-hash");
125
- }
126
- function renderStudioIntoIframe() {
127
- var script = document.createElement("script");
128
- var plasmicOrigin = getPlasmicOrigin();
129
- var hash = getStudioHash();
130
- script.src = plasmicOrigin + "/static/js/studio" + (hash ? "." + hash + ".js" : ".js");
131
- document.body.appendChild(script);
132
- }
133
- var renderCount = 0;
134
- function setPlasmicRootNode(node) {
135
- // Keep track of renderCount, which we use as key to ErrorBoundary, so
136
- // we can reset the error on each render
137
- renderCount++;
138
- plasmicRootNode.set(node);
139
- }
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
+ }
140
115
  /**
141
116
  * React context to detect whether the component is rendered on Plasmic editor.
142
117
  * If not, return false.
143
118
  * If so, return an object with more information about the component
144
- */
145
- var PlasmicCanvasContext = /*#__PURE__*/createContext(false);
146
- var usePlasmicCanvasContext = function usePlasmicCanvasContext() {
147
- return useContext(PlasmicCanvasContext);
148
- };
149
- function _PlasmicCanvasHost() {
150
- var _location$hash, _location$hash2;
151
- // If window.parent is null, then this is a window whose containing iframe
152
- // has been detached from the DOM (for the top window, window.parent === window).
153
- // In that case, we shouldn't do anything. If window.parent is null, by the way,
154
- // location.hash will also be null.
155
- var isFrameAttached = !!window.parent;
156
- var isCanvas = !!((_location$hash = location.hash) != null && _location$hash.match(/\bcanvas=true\b/));
157
- var isLive = !!((_location$hash2 = location.hash) != null && _location$hash2.match(/\blive=true\b/)) || !isFrameAttached;
158
- var shouldRenderStudio = isFrameAttached && !document.querySelector("#plasmic-studio-tag") && !isCanvas && !isLive;
159
- var forceUpdate = useForceUpdate();
160
- useLayoutEffect(function () {
161
- rootChangeListeners.push(forceUpdate);
162
- return function () {
163
- var index = rootChangeListeners.indexOf(forceUpdate);
164
- if (index >= 0) {
165
- rootChangeListeners.splice(index, 1);
166
- }
167
- };
168
- }, [forceUpdate]);
169
- useEffect(function () {
170
- if (shouldRenderStudio && isFrameAttached && window.parent !== window) {
171
- renderStudioIntoIframe();
172
- }
173
- }, [shouldRenderStudio, isFrameAttached]);
174
- useEffect(function () {
175
- if (!shouldRenderStudio && !document.querySelector("#getlibs") && isLive) {
176
- var scriptElt = document.createElement("script");
177
- scriptElt.id = "getlibs";
178
- scriptElt.src = getPlasmicOrigin() + "/static/js/getlibs.js";
179
- scriptElt.async = false;
180
- scriptElt.onload = function () {
181
- window.__GetlibsReadyResolver == null ? void 0 : window.__GetlibsReadyResolver();
182
- };
183
- document.head.append(scriptElt);
184
- }
185
- }, [shouldRenderStudio]);
186
- var _React$useState = useState(function () {
187
- return deriveCanvasContextValue();
188
- }),
189
- canvasContextValue = _React$useState[0],
190
- setCanvasContextValue = _React$useState[1];
191
- useEffect(function () {
192
- if (isCanvas) {
193
- var listener = function listener() {
194
- setCanvasContextValue(deriveCanvasContextValue());
195
- };
196
- window.addEventListener("hashchange", listener);
197
- return function () {
198
- return window.removeEventListener("hashchange", listener);
199
- };
200
- }
201
- return undefined;
202
- }, [isCanvas]);
203
- if (!isFrameAttached) {
204
- return null;
205
- }
206
- if (isCanvas || isLive) {
207
- var appDiv = document.querySelector("#plasmic-app.__wab_user-body");
208
- if (!appDiv) {
209
- appDiv = document.createElement("div");
210
- appDiv.id = "plasmic-app";
211
- appDiv.classList.add("__wab_user-body");
212
- document.body.appendChild(appDiv);
213
- }
214
- return createPortal(createElement(ErrorBoundary, {
215
- key: "" + renderCount
216
- }, createElement(PlasmicCanvasContext.Provider, {
217
- value: canvasContextValue
218
- }, plasmicRootNode.get())), appDiv, "plasmic-app");
219
- }
220
- if (shouldRenderStudio && window.parent === window) {
221
- return createElement("iframe", {
222
- src: "https://docs.plasmic.app/app-content/app-host-ready#appHostUrl=" + encodeURIComponent(location.href),
223
- style: {
224
- width: "100vw",
225
- height: "100vh",
226
- border: "none",
227
- position: "fixed",
228
- top: 0,
229
- left: 0,
230
- zIndex: 99999999
231
- }
232
- });
233
- }
234
- return null;
235
- }
236
- var PlasmicCanvasHost = function PlasmicCanvasHost(props) {
237
- var enableWebpackHmr = props.enableWebpackHmr;
238
- var _React$useState2 = useState(null),
239
- node = _React$useState2[0],
240
- setNode = _React$useState2[1];
241
- useEffect(function () {
242
- setNode(createElement(_PlasmicCanvasHost, null));
243
- }, []);
244
- return createElement(Fragment, null, !enableWebpackHmr && createElement(DisableWebpackHmr, null), node);
245
- };
246
- var renderErrorListeners = [];
247
- function registerRenderErrorListener(listener) {
248
- renderErrorListeners.push(listener);
249
- return function () {
250
- var index = renderErrorListeners.indexOf(listener);
251
- if (index >= 0) {
252
- renderErrorListeners.splice(index, 1);
253
- }
254
- };
255
- }
256
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
257
- _inheritsLoose(ErrorBoundary, _React$Component);
258
- function ErrorBoundary(props) {
259
- var _this2;
260
- _this2 = _React$Component.call(this, props) || this;
261
- _this2.state = {};
262
- return _this2;
263
- }
264
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
265
- return {
266
- error: error
267
- };
268
- };
269
- var _proto = ErrorBoundary.prototype;
270
- _proto.componentDidCatch = function componentDidCatch(error) {
271
- renderErrorListeners.forEach(function (listener) {
272
- return listener(error);
273
- });
274
- };
275
- _proto.render = function render() {
276
- if (this.state.error) {
277
- return createElement("div", null, "Error: ", "" + this.state.error.message);
278
- } else {
279
- return createElement(Fragment, null, this.props.children);
280
- }
281
- };
282
- return ErrorBoundary;
283
- }(Component);
284
- function DisableWebpackHmr() {
285
- if (process.env.NODE_ENV === "production") {
286
- return null;
287
- }
288
- return createElement("script", {
289
- type: "text/javascript",
290
- dangerouslySetInnerHTML: {
291
- __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 "
292
- }
293
- });
294
- }
295
- function deriveCanvasContextValue() {
296
- var hash = window.location.hash;
297
- if (hash && hash.length > 0) {
298
- // create URLsearchParams skipping the initial # character
299
- var params = new URLSearchParams(hash.substring(1));
300
- if (params.get("canvas") === "true") {
301
- var _params$get;
302
- var globalVariants = params.get("globalVariants");
303
- return {
304
- componentName: (_params$get = params.get("componentName")) != null ? _params$get : null,
305
- globalVariants: globalVariants ? JSON.parse(globalVariants) : {},
306
- interactive: params.get("interactive") === "true"
307
- };
308
- }
309
- }
310
- return false;
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;
311
273
  }
312
274
 
313
- var tuple = function tuple() {
314
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
315
- args[_key] = arguments[_key];
316
- }
317
- return args;
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;
318
281
  };
319
282
 
320
- var DataContext = /*#__PURE__*/createContext(undefined);
321
- function mkMetaName(name) {
322
- return "__plasmic_meta_" + name;
323
- }
324
- function mkMetaValue(meta) {
325
- return meta;
326
- }
327
- function applySelector(rawData, selector) {
328
- if (!selector) {
329
- return undefined;
330
- }
331
- var curData = rawData;
332
- for (var _iterator = _createForOfIteratorHelperLoose(selector.split(".")), _step; !(_step = _iterator()).done;) {
333
- var _curData;
334
- var key = _step.value;
335
- curData = (_curData = curData) == null ? void 0 : _curData[key];
336
- }
337
- return curData;
338
- }
339
- function useSelector(selector) {
340
- var rawData = useDataEnv();
341
- return applySelector(rawData, selector);
342
- }
343
- function useSelectors(selectors) {
344
- if (selectors === void 0) {
345
- selectors = {};
346
- }
347
- var rawData = useDataEnv();
348
- return Object.fromEntries(Object.entries(selectors).filter(function (_ref) {
349
- var key = _ref[0],
350
- selector = _ref[1];
351
- return !!key && !!selector;
352
- }).map(function (_ref2) {
353
- var key = _ref2[0],
354
- selector = _ref2[1];
355
- return tuple(key, applySelector(rawData, selector));
356
- }));
357
- }
358
- function useDataEnv() {
359
- return useContext(DataContext);
360
- }
361
- function DataProvider(_ref3) {
362
- var _useDataEnv;
363
- var name = _ref3.name,
364
- data = _ref3.data,
365
- hidden = _ref3.hidden,
366
- label = _ref3.label,
367
- children = _ref3.children;
368
- var existingEnv = (_useDataEnv = useDataEnv()) != null ? _useDataEnv : {};
369
- if (!name) {
370
- return React__default.createElement(React__default.Fragment, null, children);
371
- } else {
372
- var _extends2;
373
- return React__default.createElement(DataContext.Provider, {
374
- value: _extends({}, existingEnv, (_extends2 = {}, _extends2[name] = data, _extends2[mkMetaName(name)] = mkMetaValue({
375
- hidden: hidden,
376
- label: label
377
- }), _extends2))
378
- }, children);
379
- }
380
- }
381
- function PageParamsProvider(_ref4) {
382
- var children = _ref4.children,
383
- _ref4$params = _ref4.params,
384
- params = _ref4$params === void 0 ? {} : _ref4$params,
385
- _ref4$query = _ref4.query,
386
- query = _ref4$query === void 0 ? {} : _ref4$query;
387
- var $ctx = useDataEnv() || {};
388
- return React__default.createElement(DataProvider, {
389
- name: "params",
390
- data: _extends({}, $ctx.params, params),
391
- label: "Page URL path params"
392
- }, React__default.createElement(DataProvider, {
393
- name: "query",
394
- data: _extends({}, $ctx.query, query),
395
- label: "Page URL query params"
396
- }, children));
397
- }
398
- function DataCtxReader(_ref5) {
399
- var children = _ref5.children;
400
- var $ctx = useDataEnv();
401
- return children($ctx);
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);
402
343
  }
403
344
 
404
- var root$1 = globalThis;
405
- root$1.__PlasmicFetcherRegistry = [];
406
- function registerFetcher(fetcher, meta) {
407
- root$1.__PlasmicFetcherRegistry.push({
408
- fetcher: fetcher,
409
- meta: meta
410
- });
345
+ var root$6 = globalThis;
346
+ root$6.__PlasmicFetcherRegistry = [];
347
+ function registerFetcher(fetcher, meta) {
348
+ root$6.__PlasmicFetcherRegistry.push({ fetcher: fetcher, meta: meta });
411
349
  }
412
350
 
413
- var GlobalActionsContext = /*#__PURE__*/React__default.createContext(undefined);
414
- function GlobalActionsProvider(props) {
415
- var contextName = props.contextName,
416
- children = props.children,
417
- actions = props.actions;
418
- var namespacedActions = React__default.useMemo(function () {
419
- return Object.fromEntries(Object.entries(actions).map(function (_ref) {
420
- var key = _ref[0],
421
- val = _ref[1];
422
- return [contextName + "." + key, val];
423
- }));
424
- }, [contextName, actions]);
425
- return React__default.createElement(GlobalActionsContext.Provider, {
426
- value: namespacedActions
427
- }, children);
428
- }
429
- function useGlobalActions() {
430
- var _React$useContext;
431
- return (_React$useContext = React__default.useContext(GlobalActionsContext)) != null ? _React$useContext : {};
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 : {};
432
368
  }
433
369
 
434
- var root$2 = globalThis;
435
- if (root$2.__PlasmicComponentRegistry == null) {
436
- root$2.__PlasmicComponentRegistry = [];
437
- }
438
- function registerComponent(component, meta) {
439
- // Check for duplicates
440
- if (root$2.__PlasmicComponentRegistry.some(function (r) {
441
- return r.component === component && r.meta.name === meta.name;
442
- })) {
443
- return;
444
- }
445
- root$2.__PlasmicComponentRegistry.push({
446
- component: component,
447
- meta: meta
448
- });
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 });
449
382
  }
450
383
 
451
- var root$3 = globalThis;
452
- if (root$3.__PlasmicContextRegistry == null) {
453
- root$3.__PlasmicContextRegistry = [];
454
- }
455
- function registerGlobalContext(component, meta) {
456
- // Check for duplicates
457
- if (root$3.__PlasmicContextRegistry.some(function (r) {
458
- return r.component === component && r.meta.name === meta.name;
459
- })) {
460
- return;
461
- }
462
- root$3.__PlasmicContextRegistry.push({
463
- component: component,
464
- meta: meta
465
- });
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 });
466
396
  }
467
397
 
468
- var root$4 = globalThis;
469
- if (root$4.__PlasmicTokenRegistry == null) {
470
- root$4.__PlasmicTokenRegistry = [];
471
- }
472
- function registerToken(token) {
473
- root$4.__PlasmicTokenRegistry.push(token);
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);
474
404
  }
475
405
 
476
- var root$5 = globalThis;
477
- if (root$5.__PlasmicTraitRegistry == null) {
478
- root$5.__PlasmicTraitRegistry = [];
479
- }
480
- function registerTrait(trait, meta) {
481
- root$5.__PlasmicTraitRegistry.push({
482
- trait: trait,
483
- meta: meta
484
- });
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
+ });
485
415
  }
486
416
 
487
- var _root$__Sub$setRepeat, _root$__Sub;
488
- function repeatedElement(index, elt) {
489
- return _repeatedElementFn(index, elt);
490
- }
491
- var _repeatedElementFn = function repeatedElementFn(index, elt) {
492
- if (Array.isArray(elt)) {
493
- return elt.map(function (v) {
494
- return _repeatedElementFn(index, v);
495
- });
496
- }
497
- if (elt && isValidElement(elt) && typeof elt !== "string") {
498
- return cloneElement(elt);
499
- }
500
- return elt;
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;
501
433
  };
502
- var root$6 = globalThis;
503
- var setRepeatedElementFn = (_root$__Sub$setRepeat = root$6 == null ? void 0 : (_root$__Sub = root$6.__Sub) == null ? void 0 : _root$__Sub.setRepeatedElementFn) != null ? _root$__Sub$setRepeat : function (fn) {
504
- _repeatedElementFn = fn;
505
- };
506
-
507
434
 
435
+ var hostModule = /*#__PURE__*/Object.freeze({
436
+ __proto__: null,
437
+ PlasmicCanvasContext: PlasmicCanvasContext,
438
+ PlasmicCanvasHost: PlasmicCanvasHost,
439
+ usePlasmicCanvasContext: usePlasmicCanvasContext,
440
+ unstable_registerFetcher: registerFetcher,
441
+ registerComponent: registerComponent,
442
+ registerGlobalContext: registerGlobalContext,
443
+ registerToken: registerToken,
444
+ registerTrait: registerTrait,
445
+ repeatedElement: repeatedElement,
446
+ DataContext: DataContext,
447
+ mkMetaName: mkMetaName,
448
+ mkMetaValue: mkMetaValue,
449
+ applySelector: applySelector,
450
+ useSelector: useSelector,
451
+ useSelectors: useSelectors,
452
+ useDataEnv: useDataEnv,
453
+ DataProvider: DataProvider,
454
+ PageParamsProvider: PageParamsProvider,
455
+ DataCtxReader: DataCtxReader,
456
+ GlobalActionsContext: GlobalActionsContext,
457
+ GlobalActionsProvider: GlobalActionsProvider,
458
+ useGlobalActions: useGlobalActions
459
+ });
508
460
 
509
- var hostModule = {
510
- __proto__: null,
511
- PlasmicCanvasContext: PlasmicCanvasContext,
512
- PlasmicCanvasHost: PlasmicCanvasHost,
513
- usePlasmicCanvasContext: usePlasmicCanvasContext,
514
- unstable_registerFetcher: registerFetcher,
515
- registerComponent: registerComponent,
516
- registerGlobalContext: registerGlobalContext,
517
- registerToken: registerToken,
518
- registerTrait: registerTrait,
519
- repeatedElement: repeatedElement,
520
- DataContext: DataContext,
521
- mkMetaName: mkMetaName,
522
- mkMetaValue: mkMetaValue,
523
- applySelector: applySelector,
524
- useSelector: useSelector,
525
- useSelectors: useSelectors,
526
- useDataEnv: useDataEnv,
527
- DataProvider: DataProvider,
528
- PageParamsProvider: PageParamsProvider,
529
- DataCtxReader: DataCtxReader,
530
- GlobalActionsContext: GlobalActionsContext,
531
- GlobalActionsProvider: GlobalActionsProvider,
532
- useGlobalActions: useGlobalActions
533
- };
534
-
535
- var hostVersion = "1.0.128";
461
+ var hostVersion = "1.0.130";
536
462
 
537
- var root$7 = globalThis;
538
- if (root$7.__Sub == null) {
539
- // Creating a side effect here by logging, so that vite won't
540
- // ignore this block for whatever reason. Hiding this for now
541
- // as users are complaining; will have to check if this has
542
- // been fixed with vite.
543
- // console.log("Plasmic: Setting up app host dependencies");
544
- root$7.__Sub = /*#__PURE__*/_extends({
545
- React: React,
546
- ReactDOM: ReactDOM,
547
- PlasmicQuery: PlasmicQuery,
548
- hostModule: hostModule,
549
- hostVersion: hostVersion,
550
- hostUtils: {
551
- setPlasmicRootNode: setPlasmicRootNode,
552
- registerRenderErrorListener: registerRenderErrorListener,
553
- setRepeatedElementFn: setRepeatedElementFn
554
- },
555
- // For backwards compatibility:
556
- setPlasmicRootNode: setPlasmicRootNode,
557
- registerRenderErrorListener: registerRenderErrorListener,
558
- setRepeatedElementFn: setRepeatedElementFn
559
- }, hostModule);
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);
560
483
  }
561
484
 
562
485
  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 };