@plasmicapp/loader-react 1.0.416 → 1.0.417

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/index.js CHANGED
@@ -126,15 +126,19 @@ var jsxRuntime = __toESM(require("react/jsx-runtime"));
126
126
  // src/PlasmicRootProvider.tsx
127
127
  var import_host = require("@plasmicapp/host");
128
128
  var import_query = require("@plasmicapp/query");
129
- var React2 = __toESM(require("react"));
129
+ var React3 = __toESM(require("react"));
130
+
131
+ // src/react-utils.ts
132
+ var React = __toESM(require("react"));
133
+ var REACT_MAJOR_VERSION = +React.version.split(".")[0];
130
134
 
131
135
  // src/utils.tsx
132
136
  var import_pascalcase = __toESM(require("pascalcase"));
133
- var React = __toESM(require("react"));
137
+ var React2 = __toESM(require("react"));
134
138
  var isBrowser = typeof window !== "undefined";
135
139
  function useForceUpdate() {
136
- const [, setTick] = React.useState(0);
137
- const update = React.useCallback(() => {
140
+ const [, setTick] = React2.useState(0);
141
+ const update = React2.useCallback(() => {
138
142
  setTick((tick) => tick + 1);
139
143
  }, []);
140
144
  return update;
@@ -143,8 +147,8 @@ function useStableLookupSpec(spec) {
143
147
  return useStableLookupSpecs(spec)[0];
144
148
  }
145
149
  function useStableLookupSpecs(...specs) {
146
- const [stableSpecs, setStableSpecs] = React.useState(specs);
147
- React.useEffect(() => {
150
+ const [stableSpecs, setStableSpecs] = React2.useState(specs);
151
+ React2.useEffect(() => {
148
152
  if (specs.length !== stableSpecs.length || specs.some((s, i) => !areLookupSpecsEqual(s, stableSpecs[i]))) {
149
153
  setStableSpecs(specs);
150
154
  }
@@ -190,9 +194,9 @@ function normalizeName(name) {
190
194
  return (0, import_pascalcase.default)(name).trim();
191
195
  }
192
196
  function useIsMounted() {
193
- const ref = React.useRef(false);
194
- const isMounted = React.useCallback(() => ref.current, []);
195
- React.useEffect(() => {
197
+ const ref = React2.useRef(false);
198
+ const isMounted = React2.useCallback(() => ref.current, []);
199
+ React2.useEffect(() => {
196
200
  ref.current = true;
197
201
  return () => {
198
202
  ref.current = false;
@@ -329,7 +333,7 @@ var mergeGlobalVariantsSpec = (target, from) => {
329
333
  };
330
334
 
331
335
  // src/PlasmicRootProvider.tsx
332
- var PlasmicRootContext = React2.createContext(void 0);
336
+ var PlasmicRootContext = React3.createContext(void 0);
333
337
  function PlasmicRootProvider(props) {
334
338
  const {
335
339
  globalVariants,
@@ -356,9 +360,9 @@ function PlasmicRootProvider(props) {
356
360
  if (prefetchedData) {
357
361
  loader.registerPrefetchedBundle(prefetchedData.bundle);
358
362
  }
359
- const [splits, setSplits] = React2.useState(loader.getActiveSplits());
363
+ const [splits, setSplits] = React3.useState(loader.getActiveSplits());
360
364
  const forceUpdate = useForceUpdate();
361
- const watcher = React2.useMemo(
365
+ const watcher = React3.useMemo(
362
366
  () => ({
363
367
  onDataFetched: () => {
364
368
  setSplits(loader.getActiveSplits());
@@ -367,13 +371,13 @@ function PlasmicRootProvider(props) {
367
371
  }),
368
372
  [loader, forceUpdate]
369
373
  );
370
- React2.useEffect(() => {
374
+ React3.useEffect(() => {
371
375
  loader.subscribePlasmicRoot(watcher);
372
376
  return () => loader.unsubscribePlasmicRoot(watcher);
373
377
  }, [watcher, loader]);
374
- const currentContextValue = React2.useContext(PlasmicRootContext);
378
+ const currentContextValue = React3.useContext(PlasmicRootContext);
375
379
  const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
376
- const value = React2.useMemo(() => {
380
+ const value = React3.useMemo(() => {
377
381
  var _a, _b, _c;
378
382
  const withCurrentContextValueFallback = (v, key) => {
379
383
  return v !== void 0 ? v : currentContextValue == null ? void 0 : currentContextValue[key];
@@ -433,7 +437,7 @@ function PlasmicRootProvider(props) {
433
437
  styleTokenOverridesProjectId,
434
438
  currentContextValue
435
439
  ]);
436
- React2.useEffect(() => {
440
+ React3.useEffect(() => {
437
441
  loader.trackRender({
438
442
  renderCtx: {
439
443
  // We track the provider as a single entity
@@ -444,48 +448,47 @@ function PlasmicRootProvider(props) {
444
448
  variation: value.variation
445
449
  });
446
450
  }, [loader, value]);
447
- const reactMajorVersion = +React2.version.split(".")[0];
448
451
  const shouldDisableRootLoadingBoundary = disableRootLoadingBoundary != null ? disableRootLoadingBoundary : loader.getBundle().disableRootLoadingBoundaryByDefault;
449
- return /* @__PURE__ */ React2.createElement(
452
+ return /* @__PURE__ */ React3.createElement(
450
453
  import_query.PlasmicQueryDataProvider,
451
454
  {
452
455
  prefetchedCache: prefetchedQueryData,
453
456
  suspense: suspenseForQueryData
454
457
  },
455
- /* @__PURE__ */ React2.createElement(PlasmicRootContext.Provider, { value }, !skipCss && /* @__PURE__ */ React2.createElement(
458
+ /* @__PURE__ */ React3.createElement(PlasmicRootContext.Provider, { value }, !skipCss && /* @__PURE__ */ React3.createElement(
456
459
  PlasmicCss,
457
460
  {
458
461
  loader,
459
462
  prefetchedData,
460
463
  skipFonts
461
464
  }
462
- ), /* @__PURE__ */ React2.createElement(
465
+ ), /* @__PURE__ */ React3.createElement(
463
466
  import_host.PageParamsProvider,
464
467
  {
465
468
  route: pageRoute,
466
469
  params: pageParams,
467
470
  query: pageQuery
468
471
  },
469
- /* @__PURE__ */ React2.createElement(
472
+ /* @__PURE__ */ React3.createElement(
470
473
  MaybeWrap,
471
474
  {
472
- cond: !shouldDisableRootLoadingBoundary && reactMajorVersion >= 18,
473
- wrapper: (contents) => /* @__PURE__ */ React2.createElement(React2.Suspense, { fallback: suspenseFallback != null ? suspenseFallback : "Loading..." }, contents)
475
+ cond: !shouldDisableRootLoadingBoundary && REACT_MAJOR_VERSION >= 18,
476
+ wrapper: (contents) => /* @__PURE__ */ React3.createElement(React3.Suspense, { fallback: suspenseFallback != null ? suspenseFallback : "Loading..." }, contents)
474
477
  },
475
478
  children
476
479
  )
477
480
  ))
478
481
  );
479
482
  }
480
- var PlasmicCss = React2.memo(function PlasmicCss2(props) {
483
+ var PlasmicCss = React3.memo(function PlasmicCss2(props) {
481
484
  const { loader, prefetchedData, skipFonts } = props;
482
- const [useScopedCss, setUseScopedCss] = React2.useState(!!prefetchedData);
485
+ const [useScopedCss, setUseScopedCss] = React3.useState(!!prefetchedData);
483
486
  const builtCss = buildCss(loader, {
484
487
  scopedCompMetas: useScopedCss && prefetchedData ? prefetchedData.bundle.components : void 0,
485
488
  skipFonts
486
489
  });
487
490
  const forceUpdate = useForceUpdate();
488
- const watcher = React2.useMemo(
491
+ const watcher = React3.useMemo(
489
492
  () => ({
490
493
  onDataFetched: () => {
491
494
  setUseScopedCss(false);
@@ -494,11 +497,11 @@ var PlasmicCss = React2.memo(function PlasmicCss2(props) {
494
497
  }),
495
498
  [loader, forceUpdate]
496
499
  );
497
- React2.useEffect(() => {
500
+ React3.useEffect(() => {
498
501
  loader.subscribePlasmicRoot(watcher);
499
502
  return () => loader.unsubscribePlasmicRoot(watcher);
500
503
  }, [watcher, loader]);
501
- return /* @__PURE__ */ React2.createElement("style", { dangerouslySetInnerHTML: { __html: builtCss } });
504
+ return /* @__PURE__ */ React3.createElement("style", { dangerouslySetInnerHTML: { __html: builtCss } });
502
505
  });
503
506
  function buildCss(loader, opts) {
504
507
  const { scopedCompMetas, skipFonts } = opts;
@@ -517,7 +520,7 @@ function buildCss(loader, opts) {
517
520
  `;
518
521
  }
519
522
  function usePlasmicRootContext() {
520
- return React2.useContext(PlasmicRootContext);
523
+ return React3.useContext(PlasmicRootContext);
521
524
  }
522
525
 
523
526
  // src/global-variants.ts
@@ -1352,10 +1355,10 @@ var import_host3 = require("@plasmicapp/host");
1352
1355
  var import_query2 = require("@plasmicapp/query");
1353
1356
 
1354
1357
  // src/PlasmicComponent.tsx
1355
- var React5 = __toESM(require("react"));
1358
+ var React6 = __toESM(require("react"));
1356
1359
 
1357
1360
  // src/usePlasmicComponent.tsx
1358
- var React4 = __toESM(require("react"));
1361
+ var React5 = __toESM(require("react"));
1359
1362
  function usePlasmicComponent(spec, opts = {}) {
1360
1363
  const rootContext = usePlasmicRootContext();
1361
1364
  if (!rootContext) {
@@ -1369,7 +1372,7 @@ function usePlasmicComponent(spec, opts = {}) {
1369
1372
  const stableSpec = useStableLookupSpec(spec);
1370
1373
  const isMounted = useIsMounted();
1371
1374
  const forceUpdate = useForceUpdate();
1372
- React4.useEffect(() => {
1375
+ React5.useEffect(() => {
1373
1376
  if (!component) {
1374
1377
  (() => __async(this, null, function* () {
1375
1378
  yield loader.fetchComponentData(stableSpec);
@@ -1383,11 +1386,11 @@ function usePlasmicComponent(spec, opts = {}) {
1383
1386
  }
1384
1387
 
1385
1388
  // src/PlasmicComponent.tsx
1386
- var PlasmicComponentContext = React5.createContext(false);
1389
+ var PlasmicComponentContext = React6.createContext(false);
1387
1390
  function PlasmicComponent(props) {
1388
1391
  const { component, projectId, componentProps, forceOriginal } = props;
1389
1392
  const rootContext = usePlasmicRootContext();
1390
- const isRootLoader = !React5.useContext(PlasmicComponentContext);
1393
+ const isRootLoader = !React6.useContext(PlasmicComponentContext);
1391
1394
  if (!rootContext) {
1392
1395
  throw new Error(
1393
1396
  `You must use <PlasmicRootProvider/> at the root of your app`
@@ -1414,7 +1417,7 @@ function PlasmicComponent(props) {
1414
1417
  { name: component, projectId, isCode: false },
1415
1418
  { forceOriginal }
1416
1419
  );
1417
- React5.useEffect(() => {
1420
+ React6.useEffect(() => {
1418
1421
  if (isRootLoader) {
1419
1422
  const meta = loader.getLookup().getComponentMeta({ name: component, projectId });
1420
1423
  if (meta) {
@@ -1431,12 +1434,12 @@ function PlasmicComponent(props) {
1431
1434
  }
1432
1435
  }
1433
1436
  }, [component, projectId, loader, variation]);
1434
- const element = React5.useMemo(() => {
1437
+ const element = React6.useMemo(() => {
1435
1438
  var _a2;
1436
1439
  if (!Component) {
1437
1440
  return null;
1438
1441
  }
1439
- let elt = /* @__PURE__ */ React5.createElement(Component, __spreadValues({}, componentProps));
1442
+ let elt = /* @__PURE__ */ React6.createElement(Component, __spreadValues({}, componentProps));
1440
1443
  if (isRootLoader) {
1441
1444
  const lookup = loader.getLookup();
1442
1445
  const ReactWebRootProvider = lookup.getRootProvider();
@@ -1451,7 +1454,7 @@ function PlasmicComponent(props) {
1451
1454
  name: component,
1452
1455
  projectId
1453
1456
  });
1454
- elt = /* @__PURE__ */ React5.createElement(
1457
+ elt = /* @__PURE__ */ React6.createElement(
1455
1458
  ReactWebRootProvider,
1456
1459
  __spreadProps(__spreadValues({}, rest), {
1457
1460
  userAuthToken,
@@ -1462,19 +1465,19 @@ function PlasmicComponent(props) {
1462
1465
  tagPrefix: (_a2 = loader.opts.i18n) == null ? void 0 : _a2.tagPrefix
1463
1466
  }
1464
1467
  }),
1465
- /* @__PURE__ */ React5.createElement(
1468
+ /* @__PURE__ */ React6.createElement(
1466
1469
  MaybeWrap,
1467
1470
  {
1468
1471
  cond: !!GlobalContextsProvider,
1469
- wrapper: (children) => /* @__PURE__ */ React5.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), children)
1472
+ wrapper: (children) => /* @__PURE__ */ React6.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), children)
1470
1473
  },
1471
- /* @__PURE__ */ React5.createElement(
1474
+ /* @__PURE__ */ React6.createElement(
1472
1475
  MaybeWrap,
1473
1476
  {
1474
1477
  cond: !!StyleTokensProvider,
1475
- wrapper: (children) => /* @__PURE__ */ React5.createElement(StyleTokensProvider, null, children)
1478
+ wrapper: (children) => /* @__PURE__ */ React6.createElement(StyleTokensProvider, null, children)
1476
1479
  },
1477
- /* @__PURE__ */ React5.createElement(PlasmicComponentContext.Provider, { value: true }, elt)
1480
+ /* @__PURE__ */ React6.createElement(PlasmicComponentContext.Provider, { value: true }, elt)
1478
1481
  )
1479
1482
  )
1480
1483
  );