@plasmicapp/host 1.0.91 → 1.0.93

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
@@ -5,39 +5,31 @@ import * as ReactDOM from 'react-dom';
5
5
  import { createPortal } from 'react-dom';
6
6
 
7
7
  function _extends() {
8
- _extends = Object.assign || function (target) {
8
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
9
9
  for (var i = 1; i < arguments.length; i++) {
10
10
  var source = arguments[i];
11
-
12
11
  for (var key in source) {
13
12
  if (Object.prototype.hasOwnProperty.call(source, key)) {
14
13
  target[key] = source[key];
15
14
  }
16
15
  }
17
16
  }
18
-
19
17
  return target;
20
18
  };
21
-
22
19
  return _extends.apply(this, arguments);
23
20
  }
24
-
25
21
  function _inheritsLoose(subClass, superClass) {
26
22
  subClass.prototype = Object.create(superClass.prototype);
27
23
  subClass.prototype.constructor = subClass;
28
-
29
24
  _setPrototypeOf(subClass, superClass);
30
25
  }
31
-
32
26
  function _setPrototypeOf(o, p) {
33
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
27
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
34
28
  o.__proto__ = p;
35
29
  return o;
36
30
  };
37
-
38
31
  return _setPrototypeOf(o, p);
39
32
  }
40
-
41
33
  function _unsupportedIterableToArray(o, minLen) {
42
34
  if (!o) return;
43
35
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -46,19 +38,14 @@ function _unsupportedIterableToArray(o, minLen) {
46
38
  if (n === "Map" || n === "Set") return Array.from(o);
47
39
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
48
40
  }
49
-
50
41
  function _arrayLikeToArray(arr, len) {
51
42
  if (len == null || len > arr.length) len = arr.length;
52
-
53
43
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
54
-
55
44
  return arr2;
56
45
  }
57
-
58
46
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
59
47
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
60
48
  if (it) return (it = it.call(o)).next.bind(it);
61
-
62
49
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
63
50
  if (it) o = it;
64
51
  var i = 0;
@@ -72,19 +59,16 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
72
59
  };
73
60
  };
74
61
  }
75
-
76
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.");
77
63
  }
78
64
 
79
65
  function isString(x) {
80
66
  return typeof x === "string";
81
67
  }
82
-
83
68
  function ensure(x, msg) {
84
69
  if (msg === void 0) {
85
70
  msg = "";
86
71
  }
87
-
88
72
  if (x === null || x === undefined) {
89
73
  debugger;
90
74
  msg = (isString(msg) ? msg : msg()) || "";
@@ -96,8 +80,7 @@ function ensure(x, msg) {
96
80
 
97
81
  function useForceUpdate() {
98
82
  var _useState = useState(0),
99
- setTick = _useState[1];
100
-
83
+ setTick = _useState[1];
101
84
  var update = useCallback(function () {
102
85
  setTick(function (tick) {
103
86
  return tick + 1;
@@ -107,52 +90,39 @@ function useForceUpdate() {
107
90
  }
108
91
 
109
92
  var root = globalThis;
110
-
111
93
  if (root.__PlasmicHostVersion == null) {
112
94
  root.__PlasmicHostVersion = "2";
113
95
  }
114
-
115
96
  var rootChangeListeners = [];
116
-
117
97
  var PlasmicRootNodeWrapper = function PlasmicRootNodeWrapper(value) {
118
98
  var _this = this;
119
-
120
99
  this.value = value;
121
-
122
100
  this.set = function (val) {
123
101
  _this.value = val;
124
102
  rootChangeListeners.forEach(function (f) {
125
103
  return f();
126
104
  });
127
105
  };
128
-
129
106
  this.get = function () {
130
107
  return _this.value;
131
108
  };
132
109
  };
133
-
134
110
  var plasmicRootNode = /*#__PURE__*/new PlasmicRootNodeWrapper(null);
135
-
136
111
  function getHashParams() {
137
112
  return new URLSearchParams(location.hash.replace(/^#/, "?"));
138
113
  }
139
-
140
114
  function getPlasmicOrigin() {
141
115
  var params = getHashParams();
142
116
  return ensure(params.get("origin"), "Missing information from Plasmic window.");
143
117
  }
144
-
145
118
  function getStudioHash() {
146
119
  var hashParams = getHashParams();
147
-
148
120
  if (hashParams.has("studioHash")) {
149
121
  return hashParams.get("studioHash");
150
122
  }
151
-
152
123
  var urlParams = new URL(location.href).searchParams;
153
124
  return urlParams.get("studio-hash");
154
125
  }
155
-
156
126
  function renderStudioIntoIframe() {
157
127
  var script = document.createElement("script");
158
128
  var plasmicOrigin = getPlasmicOrigin();
@@ -160,7 +130,6 @@ function renderStudioIntoIframe() {
160
130
  script.src = plasmicOrigin + "/static/js/studio" + (hash ? "." + hash + ".js" : ".js");
161
131
  document.body.appendChild(script);
162
132
  }
163
-
164
133
  var renderCount = 0;
165
134
  function setPlasmicRootNode(node) {
166
135
  // Keep track of renderCount, which we use as key to ErrorBoundary, so
@@ -173,15 +142,12 @@ function setPlasmicRootNode(node) {
173
142
  * If not, return false.
174
143
  * If so, return an object with more information about the component
175
144
  */
176
-
177
145
  var PlasmicCanvasContext = /*#__PURE__*/createContext(false);
178
146
  var usePlasmicCanvasContext = function usePlasmicCanvasContext() {
179
147
  return useContext(PlasmicCanvasContext);
180
148
  };
181
-
182
149
  function _PlasmicCanvasHost() {
183
150
  var _location$hash, _location$hash2;
184
-
185
151
  // If window.parent is null, then this is a window whose containing iframe
186
152
  // has been detached from the DOM (for the top window, window.parent === window).
187
153
  // In that case, we shouldn't do anything. If window.parent is null, by the way,
@@ -191,21 +157,17 @@ function _PlasmicCanvasHost() {
191
157
  var isLive = !!((_location$hash2 = location.hash) != null && _location$hash2.match(/\blive=true\b/)) || !isFrameAttached;
192
158
  var shouldRenderStudio = isFrameAttached && !document.querySelector("#plasmic-studio-tag") && !isCanvas && !isLive;
193
159
  var locationHash = new URLSearchParams(location.hash);
194
-
195
160
  var _React$useState = useState(function () {
196
- var _locationHash$get;
197
-
198
- return JSON.parse((_locationHash$get = locationHash.get("globalVariants")) != null ? _locationHash$get : "{}");
199
- }),
200
- activeGlobalVariants = _React$useState[0],
201
- setActiveGlobalVariants = _React$useState[1];
202
-
161
+ var _locationHash$get;
162
+ return JSON.parse((_locationHash$get = locationHash.get("globalVariants")) != null ? _locationHash$get : "{}");
163
+ }),
164
+ activeGlobalVariants = _React$useState[0],
165
+ setActiveGlobalVariants = _React$useState[1];
203
166
  var forceUpdate = useForceUpdate();
204
167
  useLayoutEffect(function () {
205
168
  rootChangeListeners.push(forceUpdate);
206
169
  return function () {
207
170
  var index = rootChangeListeners.indexOf(forceUpdate);
208
-
209
171
  if (index >= 0) {
210
172
  rootChangeListeners.splice(index, 1);
211
173
  }
@@ -222,11 +184,9 @@ function _PlasmicCanvasHost() {
222
184
  scriptElt.id = "getlibs";
223
185
  scriptElt.src = getPlasmicOrigin() + "/static/js/getlibs.js";
224
186
  scriptElt.async = false;
225
-
226
187
  scriptElt.onload = function () {
227
188
  window.__GetlibsReadyResolver == null ? void 0 : window.__GetlibsReadyResolver();
228
189
  };
229
-
230
190
  document.head.append(scriptElt);
231
191
  }
232
192
  }, [shouldRenderStudio]);
@@ -234,33 +194,27 @@ function _PlasmicCanvasHost() {
234
194
  var listener = function listener(event) {
235
195
  try {
236
196
  var data = JSON.parse(event.data);
237
-
238
197
  if (data.source === "canvas-frame") {
239
198
  setActiveGlobalVariants(data.activeGlobalVariants);
240
199
  }
241
200
  } catch (_unused) {}
242
201
  };
243
-
244
202
  window.addEventListener("message", listener);
245
203
  return function () {
246
204
  return window.removeEventListener("message", listener);
247
205
  };
248
206
  }, []);
249
-
250
207
  if (!isFrameAttached) {
251
208
  return null;
252
209
  }
253
-
254
210
  if (isCanvas || isLive) {
255
211
  var appDiv = document.querySelector("#plasmic-app.__wab_user-body");
256
-
257
212
  if (!appDiv) {
258
213
  appDiv = document.createElement("div");
259
214
  appDiv.id = "plasmic-app";
260
215
  appDiv.classList.add("__wab_user-body");
261
216
  document.body.appendChild(appDiv);
262
217
  }
263
-
264
218
  var plasmicContextValue = isCanvas ? {
265
219
  componentName: locationHash.get("componentName"),
266
220
  globalVariants: activeGlobalVariants
@@ -271,7 +225,6 @@ function _PlasmicCanvasHost() {
271
225
  value: plasmicContextValue
272
226
  }, plasmicRootNode.get())), appDiv, "plasmic-app");
273
227
  }
274
-
275
228
  if (shouldRenderStudio && window.parent === window) {
276
229
  return createElement("iframe", {
277
230
  src: "https://docs.plasmic.app/app-content/app-host-ready#appHostUrl=" + encodeURIComponent(location.href),
@@ -286,17 +239,13 @@ function _PlasmicCanvasHost() {
286
239
  }
287
240
  });
288
241
  }
289
-
290
242
  return null;
291
243
  }
292
-
293
244
  var PlasmicCanvasHost = function PlasmicCanvasHost(props) {
294
245
  var enableWebpackHmr = props.enableWebpackHmr;
295
-
296
246
  var _React$useState2 = useState(null),
297
- node = _React$useState2[0],
298
- setNode = _React$useState2[1];
299
-
247
+ node = _React$useState2[0],
248
+ setNode = _React$useState2[1];
300
249
  useEffect(function () {
301
250
  setNode(createElement(_PlasmicCanvasHost, null));
302
251
  }, []);
@@ -307,38 +256,30 @@ function registerRenderErrorListener(listener) {
307
256
  renderErrorListeners.push(listener);
308
257
  return function () {
309
258
  var index = renderErrorListeners.indexOf(listener);
310
-
311
259
  if (index >= 0) {
312
260
  renderErrorListeners.splice(index, 1);
313
261
  }
314
262
  };
315
263
  }
316
-
317
264
  var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
318
265
  _inheritsLoose(ErrorBoundary, _React$Component);
319
-
320
266
  function ErrorBoundary(props) {
321
267
  var _this2;
322
-
323
268
  _this2 = _React$Component.call(this, props) || this;
324
269
  _this2.state = {};
325
270
  return _this2;
326
271
  }
327
-
328
272
  ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
329
273
  return {
330
274
  error: error
331
275
  };
332
276
  };
333
-
334
277
  var _proto = ErrorBoundary.prototype;
335
-
336
278
  _proto.componentDidCatch = function componentDidCatch(error) {
337
279
  renderErrorListeners.forEach(function (listener) {
338
280
  return listener(error);
339
281
  });
340
282
  };
341
-
342
283
  _proto.render = function render() {
343
284
  if (this.state.error) {
344
285
  return createElement("div", null, "Error: ", "" + this.state.error.message);
@@ -346,15 +287,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
346
287
  return createElement(Fragment, null, this.props.children);
347
288
  }
348
289
  };
349
-
350
290
  return ErrorBoundary;
351
291
  }(Component);
352
-
353
292
  function DisableWebpackHmr() {
354
293
  if (process.env.NODE_ENV === "production") {
355
294
  return null;
356
295
  }
357
-
358
296
  return createElement("script", {
359
297
  type: "text/javascript",
360
298
  dangerouslySetInnerHTML: {
@@ -367,7 +305,6 @@ var tuple = function tuple() {
367
305
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
368
306
  args[_key] = arguments[_key];
369
307
  }
370
-
371
308
  return args;
372
309
  };
373
310
 
@@ -382,16 +319,12 @@ function applySelector(rawData, selector) {
382
319
  if (!selector) {
383
320
  return undefined;
384
321
  }
385
-
386
322
  var curData = rawData;
387
-
388
323
  for (var _iterator = _createForOfIteratorHelperLoose(selector.split(".")), _step; !(_step = _iterator()).done;) {
389
324
  var _curData;
390
-
391
325
  var key = _step.value;
392
326
  curData = (_curData = curData) == null ? void 0 : _curData[key];
393
327
  }
394
-
395
328
  return curData;
396
329
  }
397
330
  function useSelector(selector) {
@@ -402,15 +335,14 @@ function useSelectors(selectors) {
402
335
  if (selectors === void 0) {
403
336
  selectors = {};
404
337
  }
405
-
406
338
  var rawData = useDataEnv();
407
339
  return Object.fromEntries(Object.entries(selectors).filter(function (_ref) {
408
340
  var key = _ref[0],
409
- selector = _ref[1];
341
+ selector = _ref[1];
410
342
  return !!key && !!selector;
411
343
  }).map(function (_ref2) {
412
344
  var key = _ref2[0],
413
- selector = _ref2[1];
345
+ selector = _ref2[1];
414
346
  return tuple(key, applySelector(rawData, selector));
415
347
  }));
416
348
  }
@@ -419,19 +351,16 @@ function useDataEnv() {
419
351
  }
420
352
  function DataProvider(_ref3) {
421
353
  var _useDataEnv;
422
-
423
354
  var name = _ref3.name,
424
- data = _ref3.data,
425
- hidden = _ref3.hidden,
426
- label = _ref3.label,
427
- children = _ref3.children;
355
+ data = _ref3.data,
356
+ hidden = _ref3.hidden,
357
+ label = _ref3.label,
358
+ children = _ref3.children;
428
359
  var existingEnv = (_useDataEnv = useDataEnv()) != null ? _useDataEnv : {};
429
-
430
360
  if (!name) {
431
361
  return React__default.createElement(React__default.Fragment, null, children);
432
362
  } else {
433
363
  var _extends2;
434
-
435
364
  return React__default.createElement(DataContext.Provider, {
436
365
  value: _extends({}, existingEnv, (_extends2 = {}, _extends2[name] = data, _extends2[mkMetaName(name)] = mkMetaValue({
437
366
  hidden: hidden,
@@ -442,10 +371,10 @@ function DataProvider(_ref3) {
442
371
  }
443
372
  function PageParamsProvider(_ref4) {
444
373
  var children = _ref4.children,
445
- _ref4$params = _ref4.params,
446
- params = _ref4$params === void 0 ? {} : _ref4$params,
447
- _ref4$query = _ref4.query,
448
- query = _ref4$query === void 0 ? {} : _ref4$query;
374
+ _ref4$params = _ref4.params,
375
+ params = _ref4$params === void 0 ? {} : _ref4$params,
376
+ _ref4$query = _ref4.query,
377
+ query = _ref4$query === void 0 ? {} : _ref4$query;
449
378
  var $ctx = useDataEnv() || {};
450
379
  return React__default.createElement(DataProvider, {
451
380
  name: "params",
@@ -473,11 +402,9 @@ function registerFetcher(fetcher, meta) {
473
402
  }
474
403
 
475
404
  var root$2 = globalThis;
476
-
477
405
  if (root$2.__PlasmicComponentRegistry == null) {
478
406
  root$2.__PlasmicComponentRegistry = [];
479
407
  }
480
-
481
408
  function registerComponent(component, meta) {
482
409
  root$2.__PlasmicComponentRegistry.push({
483
410
  component: component,
@@ -486,11 +413,9 @@ function registerComponent(component, meta) {
486
413
  }
487
414
 
488
415
  var root$3 = globalThis;
489
-
490
416
  if (root$3.__PlasmicContextRegistry == null) {
491
417
  root$3.__PlasmicContextRegistry = [];
492
418
  }
493
-
494
419
  function registerGlobalContext(component, meta) {
495
420
  root$3.__PlasmicContextRegistry.push({
496
421
  component: component,
@@ -499,11 +424,9 @@ function registerGlobalContext(component, meta) {
499
424
  }
500
425
 
501
426
  var root$4 = globalThis;
502
-
503
427
  if (root$4.__PlasmicTraitRegistry == null) {
504
428
  root$4.__PlasmicTraitRegistry = [];
505
429
  }
506
-
507
430
  function registerTrait(trait, meta) {
508
431
  root$4.__PlasmicTraitRegistry.push({
509
432
  trait: trait,
@@ -515,21 +438,17 @@ var _root$__Sub$setRepeat, _root$__Sub;
515
438
  function repeatedElement(index, elt) {
516
439
  return _repeatedElementFn(index, elt);
517
440
  }
518
-
519
441
  var _repeatedElementFn = function repeatedElementFn(index, elt) {
520
442
  if (Array.isArray(elt)) {
521
443
  return elt.map(function (v) {
522
444
  return _repeatedElementFn(index, v);
523
445
  });
524
446
  }
525
-
526
447
  if (elt && isValidElement(elt) && typeof elt !== "string") {
527
448
  return cloneElement(elt);
528
449
  }
529
-
530
450
  return elt;
531
451
  };
532
-
533
452
  var root$5 = globalThis;
534
453
  var setRepeatedElementFn = (_root$__Sub$setRepeat = root$5 == null ? void 0 : (_root$__Sub = root$5.__Sub) == null ? void 0 : _root$__Sub.setRepeatedElementFn) != null ? _root$__Sub$setRepeat : function (fn) {
535
454
  _repeatedElementFn = fn;
@@ -559,10 +478,9 @@ var hostModule = {
559
478
  DataCtxReader: DataCtxReader
560
479
  };
561
480
 
562
- var hostVersion = "1.0.91";
481
+ var hostVersion = "1.0.93";
563
482
 
564
483
  var root$6 = globalThis;
565
-
566
484
  if (root$6.__Sub == null) {
567
485
  // Creating a side effect here by logging, so that vite won't
568
486
  // ignore this block for whatever reason. Hiding this for now