@plasmicapp/react-web 0.2.183 → 0.2.185

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.
@@ -8,9 +8,9 @@ export { default as get } from 'dlv';
8
8
  import ReactDOM__default, { createPortal } from 'react-dom';
9
9
  import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
10
10
  import { useFocusRing, useFocusable, FocusScope } from '@react-aria/focus';
11
+ import { proxy, ref, useSnapshot, getVersion, subscribe } from 'valtio';
11
12
  import clone from 'clone';
12
13
  import deepEqual from 'fast-deep-equal';
13
- import { proxy, ref, useSnapshot } from 'valtio';
14
14
  import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
15
15
  import { VisuallyHidden } from '@react-aria/visually-hidden';
16
16
  import { useToggleState } from '@react-stately/toggle';
@@ -2549,6 +2549,7 @@ function canProxy(value) {
2549
2549
  return typeof value === "object" && value != null;
2550
2550
  }
2551
2551
  var proxyObjToStateCell = /*#__PURE__*/new WeakMap();
2552
+ var valtioSubscriptions = /*#__PURE__*/new WeakMap();
2552
2553
  function ensureStateCell(target, property, path, node) {
2553
2554
  if (!proxyObjToStateCell.has(target)) {
2554
2555
  proxyObjToStateCell.set(target, {});
@@ -2582,6 +2583,30 @@ function tryGetStateCellFrom$StateRoot($state, path) {
2582
2583
  function getStateCellFrom$StateRoot($state, path) {
2583
2584
  return ensure(tryGetStateCellFrom$StateRoot($state, path));
2584
2585
  }
2586
+ function unsubscribeToValtio($$state, statePath) {
2587
+ var oldValue = _get($$state.stateValues, statePath);
2588
+ if (getVersion(oldValue)) {
2589
+ var _valtioSubscriptions$;
2590
+ (_valtioSubscriptions$ = valtioSubscriptions.get(oldValue)) == null ? void 0 : _valtioSubscriptions$.forEach(function (f) {
2591
+ return f();
2592
+ });
2593
+ valtioSubscriptions["delete"](oldValue);
2594
+ }
2595
+ }
2596
+ function subscribeToValtio($$state, statePath, node) {
2597
+ var spec = node.getSpec();
2598
+ var maybeValtioProxy = spec.valueProp ? $$state.env.$props[spec.valueProp] : _get($$state.stateValues, statePath);
2599
+ if (getVersion(maybeValtioProxy) && spec.onChangeProp) {
2600
+ var unsub = subscribe(maybeValtioProxy, function () {
2601
+ var _$$state$env$$props$s, _$$state$env$$props;
2602
+ (_$$state$env$$props$s = (_$$state$env$$props = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s.call(_$$state$env$$props, spec.valueProp ? $$state.env.$props[spec.valueProp] : _get($$state.stateValues, statePath));
2603
+ });
2604
+ if (!valtioSubscriptions.has(maybeValtioProxy)) {
2605
+ valtioSubscriptions.set(maybeValtioProxy, []);
2606
+ }
2607
+ ensure(valtioSubscriptions.get(maybeValtioProxy)).push(unsub);
2608
+ }
2609
+ }
2585
2610
  function initializeStateValue($$state, initialStateCell, proxyRoot) {
2586
2611
  var _initialStateCell$ove2;
2587
2612
  var initialStateName = initialStateCell.node.getSpec().path;
@@ -2642,8 +2667,8 @@ function initializeStateValue($$state, initialStateCell, proxyRoot) {
2642
2667
  set(proxyRoot, initialStateCell.path, value);
2643
2668
  //immediately fire onChange
2644
2669
  if (initialSpec.onChangeProp) {
2645
- var _$$state$env$$props$i, _$$state$env$$props;
2646
- (_$$state$env$$props$i = (_$$state$env$$props = $$state.env.$props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$i.call(_$$state$env$$props, initialValue);
2670
+ var _$$state$env$$props$i, _$$state$env$$props2;
2671
+ (_$$state$env$$props$i = (_$$state$env$$props2 = $$state.env.$props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$i.call(_$$state$env$$props2, initialValue);
2647
2672
  }
2648
2673
  $$state.stateInitializationEnv.visited["delete"](initialStateName);
2649
2674
  $$state.stateInitializationEnv.stack.pop();
@@ -2651,23 +2676,23 @@ function initializeStateValue($$state, initialStateCell, proxyRoot) {
2651
2676
  }
2652
2677
  function create$StateProxy($$state, leafHandlers) {
2653
2678
  var proxyRoot;
2654
- var rec = function rec(currPath, currNode, isOutside, initialObject) {
2679
+ var rec = function rec(currPath, currNode) {
2655
2680
  var getNextPath = function getNextPath(property) {
2656
2681
  return [].concat(currPath, [isNum(property) ? +property : property]);
2657
2682
  };
2658
2683
  var spec = currNode.getSpec();
2659
2684
  var handlers = {
2660
2685
  deleteProperty: function deleteProperty(target, property) {
2661
- if (!isOutside && !currNode.isLeaf() && !currNode.hasArrayTransition() && !isNum(property)) {
2686
+ if (!currNode.isLeaf() && !currNode.hasArrayTransition() && !isNum(property)) {
2662
2687
  throw new InvalidOperation("Can't delete a property in the middle of the state spec");
2663
2688
  }
2664
2689
  delete _get($$state.stateValues, currPath)[property];
2665
2690
  if (spec.onChangeProp) {
2666
- var _$$state$env$$props$s, _$$state$env$$props2;
2691
+ var _$$state$env$$props$s2, _$$state$env$$props3;
2667
2692
  //we are always in a leaf, since we only have two cases:
2668
2693
  // 1 - delete properties outside the state tree
2669
2694
  // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
2670
- (_$$state$env$$props$s = (_$$state$env$$props2 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s.call(_$$state$env$$props2, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
2695
+ (_$$state$env$$props$s2 = (_$$state$env$$props3 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s2.call(_$$state$env$$props3, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
2671
2696
  }
2672
2697
  return Reflect.deleteProperty(target, property);
2673
2698
  },
@@ -2675,27 +2700,23 @@ function create$StateProxy($$state, leafHandlers) {
2675
2700
  if (property === PLASMIC_STATE_PROXY_SYMBOL) {
2676
2701
  return {
2677
2702
  node: currNode,
2678
- path: currPath,
2679
- isOutside: isOutside
2703
+ path: currPath
2680
2704
  };
2681
2705
  }
2682
2706
  var nextPath = getNextPath(property);
2683
- if (isOutside || currNode.isLeaf()) {
2684
- return Reflect.get(target, property, receiver);
2685
- }
2686
2707
  var nextNode = currNode.makeTransition(property);
2687
2708
  if (nextNode != null && nextNode.isLeaf()) {
2688
2709
  var _leafHandlers$get, _leafHandlers;
2689
2710
  return (_leafHandlers$get = (_leafHandlers = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).get) == null ? void 0 : _leafHandlers$get.call(_leafHandlers, target, property, receiver);
2690
2711
  } else if (nextNode && !(property in target)) {
2691
- target[property] = rec(nextPath, nextNode, false, undefined);
2712
+ target[property] = rec(nextPath, nextNode);
2692
2713
  }
2693
2714
  return Reflect.get(target, property, receiver);
2694
2715
  },
2695
2716
  set: function set$1(target, property, value, receiver) {
2696
- var _nextNode, _nextNode2;
2697
2717
  var nextPath = getNextPath(property);
2698
2718
  var nextNode = currNode.makeTransition(property);
2719
+ var nextSpec = nextNode == null ? void 0 : nextNode.getSpec();
2699
2720
  if (property === "registerInitFunc" && currPath.length === 0) {
2700
2721
  return Reflect.set(target, property, value, receiver);
2701
2722
  }
@@ -2704,62 +2725,42 @@ function create$StateProxy($$state, leafHandlers) {
2704
2725
  //array can set his own properties such as length, map, ...
2705
2726
  return Reflect.set(target, property, value, receiver);
2706
2727
  }
2707
- if ((_nextNode = nextNode) != null && _nextNode.isLeaf()) {
2728
+ if (nextNode != null && nextNode.isLeaf()) {
2708
2729
  var _leafHandlers$set, _leafHandlers2;
2709
2730
  (_leafHandlers$set = (_leafHandlers2 = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) == null ? void 0 : _leafHandlers$set.call(_leafHandlers2, target, property, value, receiver);
2731
+ Reflect.set(target, property, value, receiver);
2732
+ if (nextSpec != null && nextSpec.onChangeProp) {
2733
+ var _$$state$env$$props$n, _$$state$env$$props4;
2734
+ (_$$state$env$$props$n = (_$$state$env$$props4 = $$state.env.$props)[nextSpec.onChangeProp]) == null ? void 0 : _$$state$env$$props$n.call(_$$state$env$$props4, value);
2735
+ }
2710
2736
  }
2711
- if (!isOutside && !currNode.isLeaf() && !nextNode) {
2737
+ if (!nextNode) {
2712
2738
  // can't set an unknown field in $state
2713
2739
  return false;
2714
2740
  }
2715
- // we keep pointing to the leaf
2716
- if (!nextNode) {
2717
- assert(isOutside || currNode.isLeaf, "unexpected update in nextNode");
2718
- nextNode = currNode;
2719
- }
2720
- if (canProxy(value)) {
2721
- target[property] = rec(nextPath, nextNode, isOutside || currNode.isLeaf(), value);
2722
- } else if (!isOutside && !currNode.isLeaf() && !((_nextNode2 = nextNode) != null && _nextNode2.isLeaf())) {
2723
- throw new InvalidOperation("inserting a primitive value into a non-leaf");
2724
- } else {
2725
- Reflect.set(target, property, value, receiver);
2726
- }
2727
- if (currNode.isLeaf()) {
2728
- if (spec.onChangeProp) {
2729
- var _$$state$env$$props$s2, _$$state$env$$props3;
2730
- (_$$state$env$$props$s2 = (_$$state$env$$props3 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s2.call(_$$state$env$$props3, target);
2731
- }
2732
- } else {
2733
- nextNode.getAllSpecs().forEach(function (spec) {
2734
- if (spec.onChangeProp) {
2735
- var _$$state$env$$props$s3, _$$state$env$$props4;
2736
- (_$$state$env$$props$s3 = (_$$state$env$$props4 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props4, value);
2737
- }
2741
+ if (canProxy(value) && !nextNode.isLeaf()) {
2742
+ target[property] = rec(nextPath, nextNode);
2743
+ Reflect.ownKeys(value).forEach(function (key) {
2744
+ target[property][key] = value[key];
2738
2745
  });
2746
+ } else if (!nextNode.isLeaf()) {
2747
+ throw new InvalidOperation("inserting a primitive value into a non-leaf");
2739
2748
  }
2740
- var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
2749
+ var newValue = nextNode.isLeaf() && nextSpec != null && nextSpec.isImmutable ? mkUntrackedValue(value) : value;
2750
+ unsubscribeToValtio($$state, nextPath);
2741
2751
  set($$state.stateValues, nextPath, newValue);
2752
+ subscribeToValtio($$state, nextPath, nextNode);
2742
2753
  return true;
2743
2754
  }
2744
2755
  };
2745
- var baseObject = !isOutside && !currNode.isLeaf() ? currNode.hasArrayTransition() ? [] : {} : Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject != null ? initialObject : {}));
2756
+ var baseObject = currNode.hasArrayTransition() ? [] : {};
2746
2757
  var proxyObj = new Proxy(baseObject, handlers);
2747
2758
  if (currPath.length === 0) {
2748
2759
  proxyRoot = proxyObj;
2749
2760
  }
2750
- if (initialObject) {
2751
- Reflect.ownKeys(initialObject).forEach(function (key) {
2752
- var desc = Object.getOwnPropertyDescriptor(initialObject, key);
2753
- if (desc.get || desc.set) {
2754
- Object.defineProperty(baseObject, key, desc);
2755
- } else {
2756
- proxyObj[key] = initialObject[key];
2757
- }
2758
- });
2759
- }
2760
2761
  return proxyObj;
2761
2762
  };
2762
- return rec([], $$state.rootSpecTree, false, undefined);
2763
+ return rec([], $$state.rootSpecTree);
2763
2764
  }
2764
2765
  var mkUntrackedValue = function mkUntrackedValue(o) {
2765
2766
  return o != null && typeof o === "object" ? ref(o) : o;
@@ -2845,12 +2846,14 @@ function useDollarState(specs) {
2845
2846
  set($state, stateCell.path, spec.initVal);
2846
2847
  }
2847
2848
  return {
2848
- get: function get(target, property, receiver) {
2849
+ get: function get() {
2849
2850
  var spec = stateCell.node.getSpec();
2850
2851
  if (spec.valueProp) {
2851
- return $$state.env.$props[spec.valueProp];
2852
+ var valueProp = $$state.env.$props[spec.valueProp];
2853
+ subscribeToValtio($$state, stateCell.path, stateCell.node);
2854
+ return valueProp;
2852
2855
  } else {
2853
- return Reflect.get(target, property, receiver);
2856
+ return _get($$state.stateValues, stateCell.path);
2854
2857
  }
2855
2858
  }
2856
2859
  };
@@ -2899,7 +2902,7 @@ function useDollarState(specs) {
2899
2902
  }
2900
2903
  // we need to eager initialize all states in canvas to populate the data picker
2901
2904
  $$state.specTreeLeaves.forEach(function (node) {
2902
- var _newSpec$initFuncHash;
2905
+ var _newSpec$initFuncHash, _newSpec$initFuncHash2;
2903
2906
  var spec = node.getSpec();
2904
2907
  if (spec.isRepeated) {
2905
2908
  return;
@@ -2908,11 +2911,11 @@ function useDollarState(specs) {
2908
2911
  var newSpec = specs.find(function (sp) {
2909
2912
  return sp.path === spec.path;
2910
2913
  });
2911
- if (!newSpec || stateCell.initFuncHash === (newSpec == null ? void 0 : newSpec.initFuncHash) || stateCell.initialValue !== UNINITIALIZED) {
2914
+ if (!newSpec || stateCell.initFuncHash === ((_newSpec$initFuncHash = newSpec == null ? void 0 : newSpec.initFuncHash) != null ? _newSpec$initFuncHash : "") && stateCell.initialValue !== UNINITIALIZED) {
2912
2915
  return;
2913
2916
  }
2914
2917
  stateCell.initFunc = newSpec.initFunc;
2915
- stateCell.initFuncHash = (_newSpec$initFuncHash = newSpec.initFuncHash) != null ? _newSpec$initFuncHash : "";
2918
+ stateCell.initFuncHash = (_newSpec$initFuncHash2 = newSpec.initFuncHash) != null ? _newSpec$initFuncHash2 : "";
2916
2919
  var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, stateCell, $state) : spec.initVal;
2917
2920
  set($state, spec.pathObj, init);
2918
2921
  });
@@ -2937,8 +2940,8 @@ function useDollarState(specs) {
2937
2940
  var newInit = initializeStateValue($$state, stateCell, $state);
2938
2941
  var spec = stateCell.node.getSpec();
2939
2942
  if (spec.onChangeProp) {
2940
- var _$$state$env$$props$s4, _$$state$env$$props5;
2941
- (_$$state$env$$props$s4 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s4.call(_$$state$env$$props5, newInit);
2943
+ var _$$state$env$$props$s3, _$$state$env$$props5;
2944
+ (_$$state$env$$props$s3 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s3.call(_$$state$env$$props5, newInit);
2942
2945
  }
2943
2946
  };
2944
2947
  useIsomorphicLayoutEffect$1(function () {
@@ -3033,6 +3036,9 @@ var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffec
3033
3036
  function isPlasmicStateProxy(obj) {
3034
3037
  return obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL];
3035
3038
  }
3039
+ function is$StateProxy(obj) {
3040
+ return obj != null && typeof obj === "object" && (!!obj[PLASMIC_STATE_PROXY_SYMBOL] || getVersion(obj));
3041
+ }
3036
3042
  function getStateCells($state, root) {
3037
3043
  if ($state == null || typeof $state !== "object") {
3038
3044
  return [];
@@ -3082,11 +3088,9 @@ function getStateSpecInPlasmicProxy(obj, path) {
3082
3088
  if (!isPlasmicStateProxy(obj)) {
3083
3089
  return undefined;
3084
3090
  }
3085
- var _obj$PLASMIC_STATE_PR2 = obj[PLASMIC_STATE_PROXY_SYMBOL],
3086
- node = _obj$PLASMIC_STATE_PR2.node,
3087
- isOutside = _obj$PLASMIC_STATE_PR2.isOutside;
3091
+ var node = obj[PLASMIC_STATE_PROXY_SYMBOL].node;
3088
3092
  var nextNode = node.makeTransition(path[path.length - 1]);
3089
- if (isOutside || node.isLeaf() || !nextNode) {
3093
+ if (node.isLeaf() || !nextNode) {
3090
3094
  return undefined;
3091
3095
  }
3092
3096
  return {
@@ -3129,18 +3133,6 @@ function arrayEq(xs, ys) {
3129
3133
  function isNum$1(value) {
3130
3134
  return typeof value === "symbol" ? false : !isNaN(+value);
3131
3135
  }
3132
- function assert(cond, msg) {
3133
- if (msg === void 0) {
3134
- msg = "Assertion failed";
3135
- }
3136
- if (!cond) {
3137
- // We always generate an non empty message so that it doesn't get swallowed
3138
- // by the async library.
3139
- msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
3140
- debugger;
3141
- throw new Error(msg);
3142
- }
3143
- }
3144
3136
  /**
3145
3137
  * Forked from https://github.com/lukeed/dset
3146
3138
  * Changes: fixed setting a deep value to a proxy object
@@ -4662,5 +4654,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
4662
4654
  };
4663
4655
  }
4664
4656
 
4665
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, resetToInitialValue, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
4657
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, resetToInitialValue, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
4666
4658
  //# sourceMappingURL=react-web.esm.js.map