@plasmicapp/loader-react 1.0.415 → 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.esm.js +51 -48
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +46 -43
- package/dist/index.js.map +4 -4
- package/dist/react-server.esm.js +51 -28
- package/dist/react-server.esm.js.map +4 -4
- package/dist/react-server.js +29 -6
- package/dist/react-server.js.map +4 -4
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
} from "@plasmicapp/host";
|
|
65
65
|
import { PlasmicModulesFetcher as PlasmicModulesFetcher2 } from "@plasmicapp/loader-core";
|
|
66
66
|
import * as PlasmicQuery from "@plasmicapp/query";
|
|
67
|
-
import
|
|
67
|
+
import React4 from "react";
|
|
68
68
|
import ReactDOM from "react-dom";
|
|
69
69
|
import * as jsxDevRuntime from "react/jsx-dev-runtime";
|
|
70
70
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
@@ -72,15 +72,19 @@ import * as jsxRuntime from "react/jsx-runtime";
|
|
|
72
72
|
// src/PlasmicRootProvider.tsx
|
|
73
73
|
import { PageParamsProvider } from "@plasmicapp/host";
|
|
74
74
|
import { PlasmicQueryDataProvider } from "@plasmicapp/query";
|
|
75
|
-
import * as
|
|
75
|
+
import * as React3 from "react";
|
|
76
|
+
|
|
77
|
+
// src/react-utils.ts
|
|
78
|
+
import * as React from "react";
|
|
79
|
+
var REACT_MAJOR_VERSION = +React.version.split(".")[0];
|
|
76
80
|
|
|
77
81
|
// src/utils.tsx
|
|
78
82
|
import pascalcase from "pascalcase";
|
|
79
|
-
import * as
|
|
83
|
+
import * as React2 from "react";
|
|
80
84
|
var isBrowser = typeof window !== "undefined";
|
|
81
85
|
function useForceUpdate() {
|
|
82
|
-
const [, setTick] =
|
|
83
|
-
const update =
|
|
86
|
+
const [, setTick] = React2.useState(0);
|
|
87
|
+
const update = React2.useCallback(() => {
|
|
84
88
|
setTick((tick) => tick + 1);
|
|
85
89
|
}, []);
|
|
86
90
|
return update;
|
|
@@ -89,8 +93,8 @@ function useStableLookupSpec(spec) {
|
|
|
89
93
|
return useStableLookupSpecs(spec)[0];
|
|
90
94
|
}
|
|
91
95
|
function useStableLookupSpecs(...specs) {
|
|
92
|
-
const [stableSpecs, setStableSpecs] =
|
|
93
|
-
|
|
96
|
+
const [stableSpecs, setStableSpecs] = React2.useState(specs);
|
|
97
|
+
React2.useEffect(() => {
|
|
94
98
|
if (specs.length !== stableSpecs.length || specs.some((s, i) => !areLookupSpecsEqual(s, stableSpecs[i]))) {
|
|
95
99
|
setStableSpecs(specs);
|
|
96
100
|
}
|
|
@@ -136,9 +140,9 @@ function normalizeName(name) {
|
|
|
136
140
|
return pascalcase(name).trim();
|
|
137
141
|
}
|
|
138
142
|
function useIsMounted() {
|
|
139
|
-
const ref =
|
|
140
|
-
const isMounted =
|
|
141
|
-
|
|
143
|
+
const ref = React2.useRef(false);
|
|
144
|
+
const isMounted = React2.useCallback(() => ref.current, []);
|
|
145
|
+
React2.useEffect(() => {
|
|
142
146
|
ref.current = true;
|
|
143
147
|
return () => {
|
|
144
148
|
ref.current = false;
|
|
@@ -275,7 +279,7 @@ var mergeGlobalVariantsSpec = (target, from) => {
|
|
|
275
279
|
};
|
|
276
280
|
|
|
277
281
|
// src/PlasmicRootProvider.tsx
|
|
278
|
-
var PlasmicRootContext =
|
|
282
|
+
var PlasmicRootContext = React3.createContext(void 0);
|
|
279
283
|
function PlasmicRootProvider(props) {
|
|
280
284
|
const {
|
|
281
285
|
globalVariants,
|
|
@@ -302,9 +306,9 @@ function PlasmicRootProvider(props) {
|
|
|
302
306
|
if (prefetchedData) {
|
|
303
307
|
loader.registerPrefetchedBundle(prefetchedData.bundle);
|
|
304
308
|
}
|
|
305
|
-
const [splits, setSplits] =
|
|
309
|
+
const [splits, setSplits] = React3.useState(loader.getActiveSplits());
|
|
306
310
|
const forceUpdate = useForceUpdate();
|
|
307
|
-
const watcher =
|
|
311
|
+
const watcher = React3.useMemo(
|
|
308
312
|
() => ({
|
|
309
313
|
onDataFetched: () => {
|
|
310
314
|
setSplits(loader.getActiveSplits());
|
|
@@ -313,13 +317,13 @@ function PlasmicRootProvider(props) {
|
|
|
313
317
|
}),
|
|
314
318
|
[loader, forceUpdate]
|
|
315
319
|
);
|
|
316
|
-
|
|
320
|
+
React3.useEffect(() => {
|
|
317
321
|
loader.subscribePlasmicRoot(watcher);
|
|
318
322
|
return () => loader.unsubscribePlasmicRoot(watcher);
|
|
319
323
|
}, [watcher, loader]);
|
|
320
|
-
const currentContextValue =
|
|
324
|
+
const currentContextValue = React3.useContext(PlasmicRootContext);
|
|
321
325
|
const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
|
|
322
|
-
const value =
|
|
326
|
+
const value = React3.useMemo(() => {
|
|
323
327
|
var _a, _b, _c;
|
|
324
328
|
const withCurrentContextValueFallback = (v, key) => {
|
|
325
329
|
return v !== void 0 ? v : currentContextValue == null ? void 0 : currentContextValue[key];
|
|
@@ -379,7 +383,7 @@ function PlasmicRootProvider(props) {
|
|
|
379
383
|
styleTokenOverridesProjectId,
|
|
380
384
|
currentContextValue
|
|
381
385
|
]);
|
|
382
|
-
|
|
386
|
+
React3.useEffect(() => {
|
|
383
387
|
loader.trackRender({
|
|
384
388
|
renderCtx: {
|
|
385
389
|
// We track the provider as a single entity
|
|
@@ -390,48 +394,47 @@ function PlasmicRootProvider(props) {
|
|
|
390
394
|
variation: value.variation
|
|
391
395
|
});
|
|
392
396
|
}, [loader, value]);
|
|
393
|
-
const reactMajorVersion = +React2.version.split(".")[0];
|
|
394
397
|
const shouldDisableRootLoadingBoundary = disableRootLoadingBoundary != null ? disableRootLoadingBoundary : loader.getBundle().disableRootLoadingBoundaryByDefault;
|
|
395
|
-
return /* @__PURE__ */
|
|
398
|
+
return /* @__PURE__ */ React3.createElement(
|
|
396
399
|
PlasmicQueryDataProvider,
|
|
397
400
|
{
|
|
398
401
|
prefetchedCache: prefetchedQueryData,
|
|
399
402
|
suspense: suspenseForQueryData
|
|
400
403
|
},
|
|
401
|
-
/* @__PURE__ */
|
|
404
|
+
/* @__PURE__ */ React3.createElement(PlasmicRootContext.Provider, { value }, !skipCss && /* @__PURE__ */ React3.createElement(
|
|
402
405
|
PlasmicCss,
|
|
403
406
|
{
|
|
404
407
|
loader,
|
|
405
408
|
prefetchedData,
|
|
406
409
|
skipFonts
|
|
407
410
|
}
|
|
408
|
-
), /* @__PURE__ */
|
|
411
|
+
), /* @__PURE__ */ React3.createElement(
|
|
409
412
|
PageParamsProvider,
|
|
410
413
|
{
|
|
411
414
|
route: pageRoute,
|
|
412
415
|
params: pageParams,
|
|
413
416
|
query: pageQuery
|
|
414
417
|
},
|
|
415
|
-
/* @__PURE__ */
|
|
418
|
+
/* @__PURE__ */ React3.createElement(
|
|
416
419
|
MaybeWrap,
|
|
417
420
|
{
|
|
418
|
-
cond: !shouldDisableRootLoadingBoundary &&
|
|
419
|
-
wrapper: (contents) => /* @__PURE__ */
|
|
421
|
+
cond: !shouldDisableRootLoadingBoundary && REACT_MAJOR_VERSION >= 18,
|
|
422
|
+
wrapper: (contents) => /* @__PURE__ */ React3.createElement(React3.Suspense, { fallback: suspenseFallback != null ? suspenseFallback : "Loading..." }, contents)
|
|
420
423
|
},
|
|
421
424
|
children
|
|
422
425
|
)
|
|
423
426
|
))
|
|
424
427
|
);
|
|
425
428
|
}
|
|
426
|
-
var PlasmicCss =
|
|
429
|
+
var PlasmicCss = React3.memo(function PlasmicCss2(props) {
|
|
427
430
|
const { loader, prefetchedData, skipFonts } = props;
|
|
428
|
-
const [useScopedCss, setUseScopedCss] =
|
|
431
|
+
const [useScopedCss, setUseScopedCss] = React3.useState(!!prefetchedData);
|
|
429
432
|
const builtCss = buildCss(loader, {
|
|
430
433
|
scopedCompMetas: useScopedCss && prefetchedData ? prefetchedData.bundle.components : void 0,
|
|
431
434
|
skipFonts
|
|
432
435
|
});
|
|
433
436
|
const forceUpdate = useForceUpdate();
|
|
434
|
-
const watcher =
|
|
437
|
+
const watcher = React3.useMemo(
|
|
435
438
|
() => ({
|
|
436
439
|
onDataFetched: () => {
|
|
437
440
|
setUseScopedCss(false);
|
|
@@ -440,11 +443,11 @@ var PlasmicCss = React2.memo(function PlasmicCss2(props) {
|
|
|
440
443
|
}),
|
|
441
444
|
[loader, forceUpdate]
|
|
442
445
|
);
|
|
443
|
-
|
|
446
|
+
React3.useEffect(() => {
|
|
444
447
|
loader.subscribePlasmicRoot(watcher);
|
|
445
448
|
return () => loader.unsubscribePlasmicRoot(watcher);
|
|
446
449
|
}, [watcher, loader]);
|
|
447
|
-
return /* @__PURE__ */
|
|
450
|
+
return /* @__PURE__ */ React3.createElement("style", { dangerouslySetInnerHTML: { __html: builtCss } });
|
|
448
451
|
});
|
|
449
452
|
function buildCss(loader, opts) {
|
|
450
453
|
const { scopedCompMetas, skipFonts } = opts;
|
|
@@ -463,7 +466,7 @@ function buildCss(loader, opts) {
|
|
|
463
466
|
`;
|
|
464
467
|
}
|
|
465
468
|
function usePlasmicRootContext() {
|
|
466
|
-
return
|
|
469
|
+
return React3.useContext(PlasmicRootContext);
|
|
467
470
|
}
|
|
468
471
|
|
|
469
472
|
// src/global-variants.ts
|
|
@@ -1212,7 +1215,7 @@ var InternalPlasmicComponentLoader = class extends BaseInternalPlasmicComponentL
|
|
|
1212
1215
|
});
|
|
1213
1216
|
},
|
|
1214
1217
|
builtinModules: {
|
|
1215
|
-
react:
|
|
1218
|
+
react: React4,
|
|
1216
1219
|
"react-dom": ReactDOM,
|
|
1217
1220
|
"react/jsx-runtime": jsxRuntime,
|
|
1218
1221
|
"react/jsx-dev-runtime": jsxDevRuntime,
|
|
@@ -1319,10 +1322,10 @@ import {
|
|
|
1319
1322
|
import { usePlasmicQueryData } from "@plasmicapp/query";
|
|
1320
1323
|
|
|
1321
1324
|
// src/PlasmicComponent.tsx
|
|
1322
|
-
import * as
|
|
1325
|
+
import * as React6 from "react";
|
|
1323
1326
|
|
|
1324
1327
|
// src/usePlasmicComponent.tsx
|
|
1325
|
-
import * as
|
|
1328
|
+
import * as React5 from "react";
|
|
1326
1329
|
function usePlasmicComponent(spec, opts = {}) {
|
|
1327
1330
|
const rootContext = usePlasmicRootContext();
|
|
1328
1331
|
if (!rootContext) {
|
|
@@ -1336,7 +1339,7 @@ function usePlasmicComponent(spec, opts = {}) {
|
|
|
1336
1339
|
const stableSpec = useStableLookupSpec(spec);
|
|
1337
1340
|
const isMounted = useIsMounted();
|
|
1338
1341
|
const forceUpdate = useForceUpdate();
|
|
1339
|
-
|
|
1342
|
+
React5.useEffect(() => {
|
|
1340
1343
|
if (!component) {
|
|
1341
1344
|
(() => __async(this, null, function* () {
|
|
1342
1345
|
yield loader.fetchComponentData(stableSpec);
|
|
@@ -1350,11 +1353,11 @@ function usePlasmicComponent(spec, opts = {}) {
|
|
|
1350
1353
|
}
|
|
1351
1354
|
|
|
1352
1355
|
// src/PlasmicComponent.tsx
|
|
1353
|
-
var PlasmicComponentContext =
|
|
1356
|
+
var PlasmicComponentContext = React6.createContext(false);
|
|
1354
1357
|
function PlasmicComponent(props) {
|
|
1355
1358
|
const { component, projectId, componentProps, forceOriginal } = props;
|
|
1356
1359
|
const rootContext = usePlasmicRootContext();
|
|
1357
|
-
const isRootLoader = !
|
|
1360
|
+
const isRootLoader = !React6.useContext(PlasmicComponentContext);
|
|
1358
1361
|
if (!rootContext) {
|
|
1359
1362
|
throw new Error(
|
|
1360
1363
|
`You must use <PlasmicRootProvider/> at the root of your app`
|
|
@@ -1381,7 +1384,7 @@ function PlasmicComponent(props) {
|
|
|
1381
1384
|
{ name: component, projectId, isCode: false },
|
|
1382
1385
|
{ forceOriginal }
|
|
1383
1386
|
);
|
|
1384
|
-
|
|
1387
|
+
React6.useEffect(() => {
|
|
1385
1388
|
if (isRootLoader) {
|
|
1386
1389
|
const meta = loader.getLookup().getComponentMeta({ name: component, projectId });
|
|
1387
1390
|
if (meta) {
|
|
@@ -1398,12 +1401,12 @@ function PlasmicComponent(props) {
|
|
|
1398
1401
|
}
|
|
1399
1402
|
}
|
|
1400
1403
|
}, [component, projectId, loader, variation]);
|
|
1401
|
-
const element =
|
|
1404
|
+
const element = React6.useMemo(() => {
|
|
1402
1405
|
var _a2;
|
|
1403
1406
|
if (!Component) {
|
|
1404
1407
|
return null;
|
|
1405
1408
|
}
|
|
1406
|
-
let elt = /* @__PURE__ */
|
|
1409
|
+
let elt = /* @__PURE__ */ React6.createElement(Component, __spreadValues({}, componentProps));
|
|
1407
1410
|
if (isRootLoader) {
|
|
1408
1411
|
const lookup = loader.getLookup();
|
|
1409
1412
|
const ReactWebRootProvider = lookup.getRootProvider();
|
|
@@ -1418,7 +1421,7 @@ function PlasmicComponent(props) {
|
|
|
1418
1421
|
name: component,
|
|
1419
1422
|
projectId
|
|
1420
1423
|
});
|
|
1421
|
-
elt = /* @__PURE__ */
|
|
1424
|
+
elt = /* @__PURE__ */ React6.createElement(
|
|
1422
1425
|
ReactWebRootProvider,
|
|
1423
1426
|
__spreadProps(__spreadValues({}, rest), {
|
|
1424
1427
|
userAuthToken,
|
|
@@ -1429,19 +1432,19 @@ function PlasmicComponent(props) {
|
|
|
1429
1432
|
tagPrefix: (_a2 = loader.opts.i18n) == null ? void 0 : _a2.tagPrefix
|
|
1430
1433
|
}
|
|
1431
1434
|
}),
|
|
1432
|
-
/* @__PURE__ */
|
|
1435
|
+
/* @__PURE__ */ React6.createElement(
|
|
1433
1436
|
MaybeWrap,
|
|
1434
1437
|
{
|
|
1435
1438
|
cond: !!GlobalContextsProvider,
|
|
1436
|
-
wrapper: (children) => /* @__PURE__ */
|
|
1439
|
+
wrapper: (children) => /* @__PURE__ */ React6.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), children)
|
|
1437
1440
|
},
|
|
1438
|
-
/* @__PURE__ */
|
|
1441
|
+
/* @__PURE__ */ React6.createElement(
|
|
1439
1442
|
MaybeWrap,
|
|
1440
1443
|
{
|
|
1441
1444
|
cond: !!StyleTokensProvider,
|
|
1442
|
-
wrapper: (children) => /* @__PURE__ */
|
|
1445
|
+
wrapper: (children) => /* @__PURE__ */ React6.createElement(StyleTokensProvider, null, children)
|
|
1443
1446
|
},
|
|
1444
|
-
/* @__PURE__ */
|
|
1447
|
+
/* @__PURE__ */ React6.createElement(PlasmicComponentContext.Provider, { value: true }, elt)
|
|
1445
1448
|
)
|
|
1446
1449
|
)
|
|
1447
1450
|
);
|
|
@@ -1477,7 +1480,7 @@ function plasmicPrepass(element) {
|
|
|
1477
1480
|
|
|
1478
1481
|
// src/render.tsx
|
|
1479
1482
|
import { extractPlasmicQueryData as extractPlasmicQueryData2 } from "@plasmicapp/prepass";
|
|
1480
|
-
import
|
|
1483
|
+
import React7 from "react";
|
|
1481
1484
|
import ReactDOM2 from "react-dom";
|
|
1482
1485
|
import { renderToString as reactRenderToString } from "react-dom/server";
|
|
1483
1486
|
function renderToElement(_0, _1, _2) {
|
|
@@ -1507,7 +1510,7 @@ function hydrateFromElement(_0, _1, _2) {
|
|
|
1507
1510
|
});
|
|
1508
1511
|
}
|
|
1509
1512
|
function makeElement(loader, lookup, opts = {}) {
|
|
1510
|
-
return /* @__PURE__ */
|
|
1513
|
+
return /* @__PURE__ */ React7.createElement(
|
|
1511
1514
|
PlasmicRootProvider,
|
|
1512
1515
|
{
|
|
1513
1516
|
loader,
|
|
@@ -1517,7 +1520,7 @@ function makeElement(loader, lookup, opts = {}) {
|
|
|
1517
1520
|
pageParams: opts.pageParams,
|
|
1518
1521
|
pageQuery: opts.pageQuery
|
|
1519
1522
|
},
|
|
1520
|
-
/* @__PURE__ */
|
|
1523
|
+
/* @__PURE__ */ React7.createElement(
|
|
1521
1524
|
PlasmicComponent,
|
|
1522
1525
|
{
|
|
1523
1526
|
component: typeof lookup === "string" ? lookup : lookup.name,
|