@plasmicapp/loader-react 1.0.229 → 1.0.231

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.
@@ -1742,6 +1742,7 @@ function parseFetchComponentDataArgs() {
1742
1742
  }
1743
1743
 
1744
1744
  var SUBSTITUTED_COMPONENTS = {};
1745
+ var REGISTERED_CODE_COMPONENT_HELPERS = {};
1745
1746
  var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
1746
1747
  var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1747
1748
  function InternalPlasmicComponentLoader(opts) {
@@ -1783,7 +1784,8 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1783
1784
  '@plasmicapp/host': PlasmicHost,
1784
1785
  '@plasmicapp/loader-runtime-registry': {
1785
1786
  components: SUBSTITUTED_COMPONENTS,
1786
- globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS
1787
+ globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
1788
+ codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS
1787
1789
  }
1788
1790
  });
1789
1791
  }
@@ -1813,25 +1815,51 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1813
1815
  }
1814
1816
  };
1815
1817
  _proto.substituteComponent = function substituteComponent(component, name) {
1818
+ this.internalSubstituteComponent(component, name, undefined);
1819
+ };
1820
+ _proto.internalSubstituteComponent = function internalSubstituteComponent(component, name, codeComponentHelpers) {
1816
1821
  if (!this.registry.isEmpty()) {
1817
1822
  console.warn('Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over.');
1818
1823
  this.registry.clear();
1819
1824
  }
1820
1825
  this.subs.push({
1821
1826
  lookup: name,
1822
- component: component
1827
+ component: component,
1828
+ codeComponentHelpers: codeComponentHelpers
1823
1829
  });
1824
1830
  };
1825
1831
  _proto.registerComponent = function registerComponent(component, meta) {
1826
- var _meta$importPath;
1827
- this.substituteComponent(component, {
1832
+ var _meta$states, _meta$importPath;
1833
+ // making the component meta consistent between codegen and loader
1834
+ var stateHelpers = Object.fromEntries(Object.entries((_meta$states = meta.states) != null ? _meta$states : {}).filter(function (_ref) {
1835
+ var stateSpec = _ref[1];
1836
+ return 'initFunc' in stateSpec || 'onChangeArgsToValue' in stateSpec;
1837
+ }).map(function (_ref2) {
1838
+ var stateName = _ref2[0],
1839
+ stateSpec = _ref2[1];
1840
+ return [stateName, _extends({}, 'initFunc' in stateSpec ? {
1841
+ initFunc: stateSpec.initFunc
1842
+ } : {}, 'onChangeArgsToValue' in stateSpec ? {
1843
+ onChangeArgsToValue: stateSpec.onChangeArgsToValue
1844
+ } : {})];
1845
+ }));
1846
+ var helpers = {
1847
+ states: stateHelpers
1848
+ };
1849
+ this.internalSubstituteComponent(component, {
1828
1850
  name: meta.name,
1829
1851
  isCode: true
1830
- });
1831
- // Import path is not used as we will use component substitution
1852
+ }, Object.keys(stateHelpers).length > 0 ? helpers : undefined);
1832
1853
  PlasmicHost.registerComponent(component, _extends({}, meta, {
1854
+ // Import path is not used as we will use component substitution
1833
1855
  importPath: (_meta$importPath = meta.importPath) != null ? _meta$importPath : ''
1834
- }));
1856
+ }, Object.keys(stateHelpers).length > 0 ? {
1857
+ componentHelpers: {
1858
+ helpers: helpers,
1859
+ importPath: '',
1860
+ importName: ''
1861
+ }
1862
+ } : {}));
1835
1863
  };
1836
1864
  _proto.registerGlobalContext = function registerGlobalContext(context, meta) {
1837
1865
  var _meta$importPath2;
@@ -1952,6 +1980,9 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1952
1980
  var metas = getCompMetas(_this3.getBundle().components, sub.lookup);
1953
1981
  metas.forEach(function (meta) {
1954
1982
  SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
1983
+ if (sub.codeComponentHelpers) {
1984
+ REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
1985
+ }
1955
1986
  });
1956
1987
  };
1957
1988
  // Once we have received data, we register components to