@plasmicapp/loader-react 1.0.63 → 1.0.67

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.
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import { ComponentRenderData, InternalPlasmicComponentLoader, PlasmicComponentLoader } from './loader';
3
3
  interface PlasmicRootContextValue {
4
4
  globalVariants?: GlobalVariantSpec[];
5
+ globalContextsProps?: Record<string, any>;
5
6
  loader: InternalPlasmicComponentLoader;
6
7
  }
7
8
  export interface GlobalVariantSpec {
@@ -48,6 +49,12 @@ export declare function PlasmicRootProvider(props: {
48
49
  * (throwing promises).
49
50
  */
50
51
  suspenseForQueryData?: boolean;
52
+ /**
53
+ * Override your Global Contexts Provider props. This is a map from
54
+ * globalContextComponentNameProps to object of props to use for that
55
+ * component.
56
+ */
57
+ globalContextsProps?: Record<string, any>;
51
58
  }): JSX.Element;
52
59
  export declare function usePlasmicRootContext(): PlasmicRootContextValue | undefined;
53
60
  export {};
@@ -13,6 +13,7 @@ export declare class ComponentLookup {
13
13
  meta: GlobalGroupMeta;
14
14
  context: any;
15
15
  }[];
16
+ getGlobalContextsProvider(projectId: string | undefined): any;
16
17
  getRootProvider(): any;
17
18
  getCss(): AssetModule[];
18
19
  getRemoteFonts(): FontMeta[];
@@ -174,7 +174,11 @@ function prepComponentData(bundle) {
174
174
  var compPaths = usedComps.map(function (compMeta) {
175
175
  return compMeta.entry;
176
176
  });
177
- var subBundle = loaderCore.getBundleSubset.apply(void 0, [bundle, 'entrypoint.css'].concat(compPaths, ['root-provider.js'], bundle.globalGroups.map(function (g) {
177
+ var subBundle = loaderCore.getBundleSubset.apply(void 0, [bundle, 'entrypoint.css'].concat(compPaths, ['root-provider.js'], bundle.projects.map(function (x) {
178
+ return x.globalContextsProviderFileName;
179
+ }).filter(function (x) {
180
+ return !!x;
181
+ }), bundle.globalGroups.map(function (g) {
178
182
  return g.contextFile;
179
183
  })));
180
184
  var remoteFontUrls = [];
@@ -1183,6 +1187,21 @@ var ComponentLookup = /*#__PURE__*/function () {
1183
1187
  });
1184
1188
  };
1185
1189
 
1190
+ _proto.getGlobalContextsProvider = function getGlobalContextsProvider(projectId) {
1191
+ var projectMeta = projectId ? this.bundle.projects.find(function (x) {
1192
+ return x.id === projectId;
1193
+ }) : this.bundle.projects.find(function (x) {
1194
+ return !!x.globalContextsProviderFileName;
1195
+ });
1196
+
1197
+ if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
1198
+ return undefined;
1199
+ }
1200
+
1201
+ var entry = this.registry.load(projectMeta.globalContextsProviderFileName);
1202
+ return entry["default"];
1203
+ };
1204
+
1186
1205
  _proto.getRootProvider = function getRootProvider() {
1187
1206
  var entry = this.registry.load('root-provider.js');
1188
1207
  return entry["default"];
@@ -1217,7 +1236,8 @@ function PlasmicRootProvider(props) {
1217
1236
  skipCss = props.skipCss,
1218
1237
  skipFonts = props.skipFonts,
1219
1238
  prefetchedQueryData = props.prefetchedQueryData,
1220
- suspenseForQueryData = props.suspenseForQueryData;
1239
+ suspenseForQueryData = props.suspenseForQueryData,
1240
+ globalContextsProps = props.globalContextsProps;
1221
1241
  var loader = props.loader.__internal;
1222
1242
 
1223
1243
  if (prefetchedData) {
@@ -1227,9 +1247,10 @@ function PlasmicRootProvider(props) {
1227
1247
  var value = React.useMemo(function () {
1228
1248
  return {
1229
1249
  globalVariants: globalVariants,
1250
+ globalContextsProps: globalContextsProps,
1230
1251
  loader: loader
1231
1252
  };
1232
- }, [globalVariants, loader]);
1253
+ }, [globalVariants, globalContextsProps, loader]);
1233
1254
  return React.createElement(PlasmicQuery.PlasmicQueryDataProvider, {
1234
1255
  prefetchedCache: prefetchedQueryData,
1235
1256
  suspense: suspenseForQueryData
@@ -2143,14 +2164,24 @@ function PlasmicComponent(props) {
2143
2164
  // "root-most PlasmicComponent"; we won't risk invalidating the sub-tree
2144
2165
  // here because there were no children before the data came in.
2145
2166
  var ReactWebRootProvider = lookup.getRootProvider();
2146
- element = React.createElement(ReactWebRootProvider, null, React.createElement(PlasmicComponentContext.Provider, {
2167
+ var GlobalContextsProvider = lookup.getGlobalContextsProvider(projectId);
2168
+ element = React.createElement(ReactWebRootProvider, null, React.createElement(MaybeWrap, {
2169
+ cond: !!GlobalContextsProvider,
2170
+ wrapper: function wrapper(children) {
2171
+ return React.createElement(GlobalContextsProvider, Object.assign({}, rootContext.globalContextsProps), children);
2172
+ }
2173
+ }, React.createElement(PlasmicComponentContext.Provider, {
2147
2174
  value: true
2148
- }, element));
2175
+ }, element)));
2149
2176
  }
2150
2177
 
2151
2178
  return element;
2152
2179
  }
2153
2180
 
2181
+ function MaybeWrap(props) {
2182
+ return props.cond ? props.wrapper(props.children) : props.children;
2183
+ }
2184
+
2154
2185
  /**
2155
2186
  * Performs a prepass over Plasmic content, kicking off the necessary
2156
2187
  * data fetches, and populating the fetched data into a cache. This