@plasmicapp/loader-react 1.0.152 → 1.0.155
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/README.md +9 -1
- package/dist/component-lookup.d.ts +2 -1
- package/dist/loader-react.cjs.development.js +86 -2
- package/dist/loader-react.cjs.development.js.map +1 -1
- package/dist/loader-react.cjs.production.min.js +1 -1
- package/dist/loader-react.cjs.production.min.js.map +1 -1
- package/dist/loader-react.esm.js +87 -3
- package/dist/loader-react.esm.js.map +1 -1
- package/dist/loader.d.ts +6 -1
- package/dist/variation.d.ts +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
# @plasmicapp/loader-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the SDK for using the Plasmic visual builder with React codebases.
|
|
4
|
+
|
|
5
|
+
To get started, see the quickstart for React:
|
|
6
|
+
|
|
7
|
+
https://docs.plasmic.app/learn/react-quickstart
|
|
8
|
+
|
|
9
|
+
If you are using Next.js or Gatsby, please instead use the specific SDKs for those: `@plasmicapp/loader-nextjs` and `@plasmicapp/loader-gatsby`.
|
|
10
|
+
|
|
11
|
+
This library uses `@plasmicapp/loader-core` under the hood.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AssetModule, FontMeta, GlobalGroupMeta, LoaderBundleOutput, Registry } from '@plasmicapp/loader-core';
|
|
1
|
+
import { AssetModule, ComponentMeta, FontMeta, GlobalGroupMeta, LoaderBundleOutput, Registry } from '@plasmicapp/loader-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ComponentLookupSpec } from './utils';
|
|
4
4
|
export declare class ComponentLookup {
|
|
5
5
|
private bundle;
|
|
6
6
|
private registry;
|
|
7
7
|
constructor(bundle: LoaderBundleOutput, registry: Registry);
|
|
8
|
+
getComponentMeta(spec: ComponentLookupSpec): ComponentMeta | undefined;
|
|
8
9
|
getComponent<P extends React.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
|
|
9
10
|
forceOriginal?: boolean;
|
|
10
11
|
}): any;
|
|
@@ -1163,6 +1163,11 @@ var ComponentLookup = /*#__PURE__*/function () {
|
|
|
1163
1163
|
|
|
1164
1164
|
var _proto = ComponentLookup.prototype;
|
|
1165
1165
|
|
|
1166
|
+
_proto.getComponentMeta = function getComponentMeta(spec) {
|
|
1167
|
+
var compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
1168
|
+
return compMeta;
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1166
1171
|
_proto.getComponent = function getComponent(spec, opts) {
|
|
1167
1172
|
if (opts === void 0) {
|
|
1168
1173
|
opts = {};
|
|
@@ -1259,6 +1264,16 @@ function getPlasmicCookieValues() {
|
|
|
1259
1264
|
function updatePlasmicCookieValue(key, value) {
|
|
1260
1265
|
document.cookie = "plasmic:" + key + "=" + value;
|
|
1261
1266
|
}
|
|
1267
|
+
function ensureVariationCookies(variation) {
|
|
1268
|
+
if (variation === void 0) {
|
|
1269
|
+
variation = {};
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
Object.keys(variation).map(function (variationKey) {
|
|
1273
|
+
var sliceId = variation[variationKey];
|
|
1274
|
+
updatePlasmicCookieValue(variationKey, sliceId);
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1262
1277
|
var getGlobalVariantsFromSplits = function getGlobalVariantsFromSplits(splits, variation) {
|
|
1263
1278
|
var globalVariants = [];
|
|
1264
1279
|
Object.keys(variation).map(function (variationKey) {
|
|
@@ -1350,6 +1365,17 @@ function PlasmicRootProvider(props) {
|
|
|
1350
1365
|
return loader.unsubscribePlasmicRoot(watcher);
|
|
1351
1366
|
};
|
|
1352
1367
|
}, [watcher, loader]);
|
|
1368
|
+
React.useEffect(function () {
|
|
1369
|
+
ensureVariationCookies(variation);
|
|
1370
|
+
loader.trackRender({
|
|
1371
|
+
renderCtx: {
|
|
1372
|
+
// We track the provider as a single entity
|
|
1373
|
+
rootComponentId: 'provider',
|
|
1374
|
+
teamIds: loader.getTeamIds()
|
|
1375
|
+
},
|
|
1376
|
+
variation: variation
|
|
1377
|
+
});
|
|
1378
|
+
}, [loader, variation]);
|
|
1353
1379
|
var value = React.useMemo(function () {
|
|
1354
1380
|
return {
|
|
1355
1381
|
globalVariants: mergeGlobalVariantsSpec(globalVariants != null ? globalVariants : [], getGlobalVariantsFromSplits(splits, variation != null ? variation : {})),
|
|
@@ -1499,6 +1525,13 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
|
|
|
1499
1525
|
this.substitutedGlobalVariantHooks = {};
|
|
1500
1526
|
this.registry = loaderCore.Registry.getInstance();
|
|
1501
1527
|
this.fetcher = new loaderCore.PlasmicModulesFetcher(opts);
|
|
1528
|
+
this.tracker = new loaderCore.PlasmicTracker({
|
|
1529
|
+
projectIds: opts.projects.map(function (p) {
|
|
1530
|
+
return p.id;
|
|
1531
|
+
}),
|
|
1532
|
+
platform: opts.platform,
|
|
1533
|
+
preview: opts.preview
|
|
1534
|
+
});
|
|
1502
1535
|
this.registerModules({
|
|
1503
1536
|
react: React__default,
|
|
1504
1537
|
'react-dom': ReactDOM,
|
|
@@ -1843,6 +1876,14 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
|
|
|
1843
1876
|
|
|
1844
1877
|
_proto.getActiveSplits = function getActiveSplits() {
|
|
1845
1878
|
return this.bundle.activeSplits;
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
_proto.trackConversion = function trackConversion(value) {
|
|
1882
|
+
if (value === void 0) {
|
|
1883
|
+
value = 0;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
this.tracker.trackConversion(value);
|
|
1846
1887
|
} // @ts-ignore
|
|
1847
1888
|
;
|
|
1848
1889
|
|
|
@@ -1918,6 +1959,18 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
|
|
|
1918
1959
|
return getActiveVariation;
|
|
1919
1960
|
}();
|
|
1920
1961
|
|
|
1962
|
+
_proto.getTeamIds = function getTeamIds() {
|
|
1963
|
+
return this.bundle.projects.map(function (p) {
|
|
1964
|
+
return p.teamId;
|
|
1965
|
+
}).filter(function (x) {
|
|
1966
|
+
return !!x;
|
|
1967
|
+
});
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
_proto.trackRender = function trackRender(opts) {
|
|
1971
|
+
this.tracker.trackRender(opts);
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1921
1974
|
_proto.fetchAllData = /*#__PURE__*/function () {
|
|
1922
1975
|
var _fetchAllData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
|
|
1923
1976
|
var bundle;
|
|
@@ -1930,13 +1983,14 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
|
|
|
1930
1983
|
|
|
1931
1984
|
case 2:
|
|
1932
1985
|
bundle = _context8.sent;
|
|
1986
|
+
this.tracker.trackFetch();
|
|
1933
1987
|
this.mergeBundle(bundle);
|
|
1934
1988
|
this.roots.forEach(function (watcher) {
|
|
1935
1989
|
return watcher.onDataFetched == null ? void 0 : watcher.onDataFetched();
|
|
1936
1990
|
});
|
|
1937
1991
|
return _context8.abrupt("return", bundle);
|
|
1938
1992
|
|
|
1939
|
-
case
|
|
1993
|
+
case 7:
|
|
1940
1994
|
case "end":
|
|
1941
1995
|
return _context8.stop();
|
|
1942
1996
|
}
|
|
@@ -2294,6 +2348,14 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
|
|
|
2294
2348
|
return this.__internal.getActiveSplits();
|
|
2295
2349
|
};
|
|
2296
2350
|
|
|
2351
|
+
_proto2.trackConversion = function trackConversion(value) {
|
|
2352
|
+
if (value === void 0) {
|
|
2353
|
+
value = 0;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
this.__internal.trackConversion(value);
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2297
2359
|
_proto2.clearCache = function clearCache() {
|
|
2298
2360
|
return this.__internal.clearCache();
|
|
2299
2361
|
};
|
|
@@ -2372,13 +2434,35 @@ function PlasmicComponent(props) {
|
|
|
2372
2434
|
|
|
2373
2435
|
var loader = rootContext.loader,
|
|
2374
2436
|
globalContextsProps = rootContext.globalContextsProps,
|
|
2437
|
+
variation = rootContext.variation,
|
|
2375
2438
|
translator = rootContext.translator;
|
|
2376
2439
|
var Component = usePlasmicComponent({
|
|
2377
2440
|
name: component,
|
|
2378
|
-
projectId: projectId
|
|
2441
|
+
projectId: projectId,
|
|
2442
|
+
isCode: false
|
|
2379
2443
|
}, {
|
|
2380
2444
|
forceOriginal: forceOriginal
|
|
2381
2445
|
});
|
|
2446
|
+
React.useEffect(function () {
|
|
2447
|
+
if (isRootLoader) {
|
|
2448
|
+
var meta = loader.getLookup().getComponentMeta({
|
|
2449
|
+
name: component,
|
|
2450
|
+
projectId: projectId
|
|
2451
|
+
});
|
|
2452
|
+
|
|
2453
|
+
if (meta) {
|
|
2454
|
+
loader.trackRender({
|
|
2455
|
+
renderCtx: {
|
|
2456
|
+
rootProjectId: meta.projectId,
|
|
2457
|
+
rootComponentId: meta.id,
|
|
2458
|
+
rootComponentName: component,
|
|
2459
|
+
teamIds: loader.getTeamIds()
|
|
2460
|
+
},
|
|
2461
|
+
variation: variation
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}, [component, projectId, loader, variation]);
|
|
2382
2466
|
var element = React.useMemo(function () {
|
|
2383
2467
|
if (!Component) {
|
|
2384
2468
|
return null;
|