@plasmicapp/host 1.0.92 → 1.0.94

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