@plasmicapp/loader-react 1.0.344 → 1.0.345
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 +47 -56
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +47 -56
- package/dist/index.js.map +2 -2
- package/dist/react-server.esm.js +147 -154
- package/dist/react-server.esm.js.map +2 -2
- package/dist/react-server.js +147 -154
- package/dist/react-server.js.map +3 -3
- package/package.json +5 -5
package/dist/react-server.esm.js
CHANGED
|
@@ -73,6 +73,109 @@ import { getActiveVariation, getExternalIds } from "@plasmicapp/loader-splits";
|
|
|
73
73
|
import {
|
|
74
74
|
getBundleSubset
|
|
75
75
|
} from "@plasmicapp/loader-core";
|
|
76
|
+
|
|
77
|
+
// src/utils.tsx
|
|
78
|
+
import pascalcase from "pascalcase";
|
|
79
|
+
import * as React from "react";
|
|
80
|
+
var isBrowser = typeof window !== "undefined";
|
|
81
|
+
function isNameSpec(lookup) {
|
|
82
|
+
return "name" in lookup;
|
|
83
|
+
}
|
|
84
|
+
function toFullLookup(lookup) {
|
|
85
|
+
const namePart = typeof lookup === "string" ? lookup : lookup.name;
|
|
86
|
+
const projectId = typeof lookup === "string" ? void 0 : lookup.projectId;
|
|
87
|
+
const codeComponent = typeof lookup === "string" ? void 0 : lookup.isCode;
|
|
88
|
+
if (codeComponent !== true && namePart.startsWith("/")) {
|
|
89
|
+
return { path: normalizePath(namePart), projectId };
|
|
90
|
+
} else {
|
|
91
|
+
return {
|
|
92
|
+
name: codeComponent ? namePart : normalizeName(namePart),
|
|
93
|
+
rawName: namePart.trim(),
|
|
94
|
+
projectId,
|
|
95
|
+
isCode: codeComponent
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function normalizePath(path) {
|
|
100
|
+
return path.trim();
|
|
101
|
+
}
|
|
102
|
+
function normalizeName(name) {
|
|
103
|
+
return pascalcase(name).trim();
|
|
104
|
+
}
|
|
105
|
+
function matchesPagePath(pattern, path) {
|
|
106
|
+
const normalizedPattern = "/" + pattern.replace(/^\/|\/$/g, "");
|
|
107
|
+
const normalizedPath = "/" + path.replace(/^\/|\/$/g, "");
|
|
108
|
+
const regexString = normalizedPattern.replace(/\/\[\[\.\.\.([^\]^]+)]]/g, "(?:/([^]*))?").replace(/\/\[\.\.\.([^\]^]+)]/g, "/([^]*)").replace(/\[([^\]^]+)]/g, "([^/]+)").replace(/\//g, "\\/");
|
|
109
|
+
const regex = new RegExp(`^/?${regexString}$`);
|
|
110
|
+
const match = normalizedPath.match(regex);
|
|
111
|
+
if (!match)
|
|
112
|
+
return false;
|
|
113
|
+
const slugNames = [...pattern.matchAll(/\[\.?\.?\.?([^[\]]+)]/g)].map(
|
|
114
|
+
(m) => m[1]
|
|
115
|
+
);
|
|
116
|
+
const params = {};
|
|
117
|
+
for (let i = 0; i < slugNames.length; i++) {
|
|
118
|
+
const slugName = slugNames[i];
|
|
119
|
+
const value = match[i + 1];
|
|
120
|
+
if (pattern.includes(`[[...${slugName}]]`)) {
|
|
121
|
+
params[slugName] = value ? value.split("/").filter(Boolean) : [];
|
|
122
|
+
} else if (pattern.includes(`[...${slugName}]`)) {
|
|
123
|
+
params[slugName] = value.split("/").filter(Boolean);
|
|
124
|
+
} else if (value !== void 0) {
|
|
125
|
+
params[slugName] = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { params };
|
|
129
|
+
}
|
|
130
|
+
function isDynamicPagePath(path) {
|
|
131
|
+
return !!path.match(/\[[^/]*\]/);
|
|
132
|
+
}
|
|
133
|
+
function matchesCompMeta(lookup, meta) {
|
|
134
|
+
if (lookup.projectId && meta.projectId !== lookup.projectId) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : !!(meta.path && matchesPagePath(meta.path, lookup.path));
|
|
138
|
+
}
|
|
139
|
+
function getCompMetas(metas, lookup) {
|
|
140
|
+
const full = toFullLookup(lookup);
|
|
141
|
+
return metas.filter((meta) => matchesCompMeta(full, meta)).map(
|
|
142
|
+
(meta) => {
|
|
143
|
+
if (isNameSpec(full) || !meta.path) {
|
|
144
|
+
return meta;
|
|
145
|
+
}
|
|
146
|
+
const match = matchesPagePath(meta.path, full.path);
|
|
147
|
+
if (!match) {
|
|
148
|
+
return meta;
|
|
149
|
+
}
|
|
150
|
+
return __spreadProps(__spreadValues({}, meta), { params: match.params });
|
|
151
|
+
}
|
|
152
|
+
).sort(
|
|
153
|
+
(meta1, meta2) => (
|
|
154
|
+
// We sort the matched component metas by the number of path params, so
|
|
155
|
+
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
156
|
+
// the first one will have higher precedence.
|
|
157
|
+
Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function getLookupSpecName(lookup) {
|
|
162
|
+
if (typeof lookup === "string") {
|
|
163
|
+
return lookup;
|
|
164
|
+
} else if (lookup.projectId) {
|
|
165
|
+
return `${lookup.name} (project ${lookup.projectId})`;
|
|
166
|
+
} else {
|
|
167
|
+
return lookup.name;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function uniq(elements) {
|
|
171
|
+
return Array.from(new Set(elements));
|
|
172
|
+
}
|
|
173
|
+
function intersect(a, b) {
|
|
174
|
+
const setB = new Set(b);
|
|
175
|
+
return a.filter((elt) => setB.has(elt));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/bundles.ts
|
|
76
179
|
function getUsedComps(allComponents, entryCompIds) {
|
|
77
180
|
const q = [...entryCompIds];
|
|
78
181
|
const seenIds = new Set(entryCompIds);
|
|
@@ -141,14 +244,7 @@ function prepComponentData(bundle, compMetas, opts) {
|
|
|
141
244
|
};
|
|
142
245
|
}
|
|
143
246
|
function mergeBundles(target, from) {
|
|
144
|
-
var _a2;
|
|
145
|
-
const existingCompIds = new Set(target.components.map((c) => c.id));
|
|
146
|
-
const newCompMetas = from.components.filter(
|
|
147
|
-
(m) => !existingCompIds.has(m.id)
|
|
148
|
-
);
|
|
149
|
-
if (newCompMetas.length > 0) {
|
|
150
|
-
target = __spreadProps(__spreadValues({}, target), { components: [...target.components, ...newCompMetas] });
|
|
151
|
-
}
|
|
247
|
+
var _a2, _b, _c, _d, _e;
|
|
152
248
|
const existingProjects = new Set(target.projects.map((p) => p.id));
|
|
153
249
|
const newProjects = from.projects.filter((p) => !existingProjects.has(p.id));
|
|
154
250
|
if (newProjects.length > 0) {
|
|
@@ -156,6 +252,35 @@ function mergeBundles(target, from) {
|
|
|
156
252
|
projects: [...target.projects, ...newProjects]
|
|
157
253
|
});
|
|
158
254
|
}
|
|
255
|
+
const existingCompIds = new Set(target.components.map((c) => c.id));
|
|
256
|
+
function shouldIncludeComponentInBundle(c) {
|
|
257
|
+
if (existingCompIds.has(c.id)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (!existingProjects.has(c.projectId)) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
if (!target.filteredIds[c.projectId]) {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
return target.filteredIds[c.projectId].includes(c.id);
|
|
267
|
+
}
|
|
268
|
+
const newCompMetas = from.components.filter(
|
|
269
|
+
(m) => shouldIncludeComponentInBundle(m)
|
|
270
|
+
);
|
|
271
|
+
if (newCompMetas.length > 0) {
|
|
272
|
+
target = __spreadProps(__spreadValues({}, target), { components: [...target.components, ...newCompMetas] });
|
|
273
|
+
Object.entries(from.filteredIds).forEach(([projectId, ids]) => {
|
|
274
|
+
if (!target.filteredIds[projectId]) {
|
|
275
|
+
target.filteredIds[projectId] = [...ids];
|
|
276
|
+
} else {
|
|
277
|
+
target.filteredIds[projectId] = intersect(
|
|
278
|
+
target.filteredIds[projectId],
|
|
279
|
+
ids
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
159
284
|
const existingModules = {
|
|
160
285
|
browser: new Set(target.modules.browser.map((m) => m.fileName)),
|
|
161
286
|
server: new Set(target.modules.server.map((m) => m.fileName))
|
|
@@ -186,12 +311,18 @@ function mergeBundles(target, from) {
|
|
|
186
311
|
});
|
|
187
312
|
}
|
|
188
313
|
const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
|
|
189
|
-
const newSplits = (_a2 = from.activeSplits.filter(
|
|
314
|
+
const newSplits = (_a2 = from.activeSplits.filter(
|
|
315
|
+
// Don't include splits belonging to projects already present
|
|
316
|
+
// in the target bundle
|
|
317
|
+
(s) => !existingSplitIds.has(s.id) && !existingProjects.has(s.projectId)
|
|
318
|
+
)) != null ? _a2 : [];
|
|
190
319
|
if (newSplits.length > 0) {
|
|
191
320
|
target = __spreadProps(__spreadValues({}, target), {
|
|
192
321
|
activeSplits: [...target.activeSplits, ...newSplits]
|
|
193
322
|
});
|
|
194
323
|
}
|
|
324
|
+
target.bundleKey = (_c = (_b = target.bundleKey) != null ? _b : from.bundleKey) != null ? _c : null;
|
|
325
|
+
target.deferChunksByDefault = (_e = (_d = target.deferChunksByDefault) != null ? _d : from.deferChunksByDefault) != null ? _e : false;
|
|
195
326
|
return target;
|
|
196
327
|
}
|
|
197
328
|
var convertBundlesToComponentRenderData = (bundles, compMetas) => {
|
|
@@ -202,115 +333,6 @@ var convertBundlesToComponentRenderData = (bundles, compMetas) => {
|
|
|
202
333
|
return prepComponentData(mergedBundles, compMetas);
|
|
203
334
|
};
|
|
204
335
|
|
|
205
|
-
// src/utils.tsx
|
|
206
|
-
import pascalcase from "pascalcase";
|
|
207
|
-
import * as React from "react";
|
|
208
|
-
var isBrowser = typeof window !== "undefined";
|
|
209
|
-
function isNameSpec(lookup) {
|
|
210
|
-
return "name" in lookup;
|
|
211
|
-
}
|
|
212
|
-
function toFullLookup(lookup) {
|
|
213
|
-
const namePart = typeof lookup === "string" ? lookup : lookup.name;
|
|
214
|
-
const projectId = typeof lookup === "string" ? void 0 : lookup.projectId;
|
|
215
|
-
const codeComponent = typeof lookup === "string" ? void 0 : lookup.isCode;
|
|
216
|
-
if (codeComponent !== true && namePart.startsWith("/")) {
|
|
217
|
-
return { path: normalizePath(namePart), projectId };
|
|
218
|
-
} else {
|
|
219
|
-
return {
|
|
220
|
-
name: codeComponent ? namePart : normalizeName(namePart),
|
|
221
|
-
rawName: namePart.trim(),
|
|
222
|
-
projectId,
|
|
223
|
-
isCode: codeComponent
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
function normalizePath(path) {
|
|
228
|
-
return path.trim();
|
|
229
|
-
}
|
|
230
|
-
function normalizeName(name) {
|
|
231
|
-
return pascalcase(name).trim();
|
|
232
|
-
}
|
|
233
|
-
function matchesPagePath(pattern, path) {
|
|
234
|
-
const normalizedPattern = "/" + pattern.replace(/^\/|\/$/g, "");
|
|
235
|
-
const normalizedPath = "/" + path.replace(/^\/|\/$/g, "");
|
|
236
|
-
const regexString = normalizedPattern.replace(/\/\[\[\.\.\.([^\]^]+)]]/g, "(?:/([^]*))?").replace(/\/\[\.\.\.([^\]^]+)]/g, "/([^]*)").replace(/\[([^\]^]+)]/g, "([^/]+)").replace(/\//g, "\\/");
|
|
237
|
-
const regex = new RegExp(`^/?${regexString}$`);
|
|
238
|
-
const match = normalizedPath.match(regex);
|
|
239
|
-
if (!match)
|
|
240
|
-
return false;
|
|
241
|
-
const slugNames = [...pattern.matchAll(/\[\.?\.?\.?([^[\]]+)]/g)].map(
|
|
242
|
-
(m) => m[1]
|
|
243
|
-
);
|
|
244
|
-
const params = {};
|
|
245
|
-
for (let i = 0; i < slugNames.length; i++) {
|
|
246
|
-
const slugName = slugNames[i];
|
|
247
|
-
const value = match[i + 1];
|
|
248
|
-
if (pattern.includes(`[[...${slugName}]]`)) {
|
|
249
|
-
params[slugName] = value ? value.split("/").filter(Boolean) : [];
|
|
250
|
-
} else if (pattern.includes(`[...${slugName}]`)) {
|
|
251
|
-
params[slugName] = value.split("/").filter(Boolean);
|
|
252
|
-
} else if (value !== void 0) {
|
|
253
|
-
params[slugName] = value;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return { params };
|
|
257
|
-
}
|
|
258
|
-
function isDynamicPagePath(path) {
|
|
259
|
-
return !!path.match(/\[[^/]*\]/);
|
|
260
|
-
}
|
|
261
|
-
function matchesCompMeta(lookup, meta) {
|
|
262
|
-
if (lookup.projectId && meta.projectId !== lookup.projectId) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : !!(meta.path && matchesPagePath(meta.path, lookup.path));
|
|
266
|
-
}
|
|
267
|
-
function getCompMetas(metas, lookup) {
|
|
268
|
-
const full = toFullLookup(lookup);
|
|
269
|
-
return metas.filter((meta) => matchesCompMeta(full, meta)).map(
|
|
270
|
-
(meta) => {
|
|
271
|
-
if (isNameSpec(full) || !meta.path) {
|
|
272
|
-
return meta;
|
|
273
|
-
}
|
|
274
|
-
const match = matchesPagePath(meta.path, full.path);
|
|
275
|
-
if (!match) {
|
|
276
|
-
return meta;
|
|
277
|
-
}
|
|
278
|
-
return __spreadProps(__spreadValues({}, meta), { params: match.params });
|
|
279
|
-
}
|
|
280
|
-
).sort(
|
|
281
|
-
(meta1, meta2) => (
|
|
282
|
-
// We sort the matched component metas by the number of path params, so
|
|
283
|
-
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
284
|
-
// the first one will have higher precedence.
|
|
285
|
-
Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
|
|
286
|
-
)
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
function getLookupSpecName(lookup) {
|
|
290
|
-
if (typeof lookup === "string") {
|
|
291
|
-
return lookup;
|
|
292
|
-
} else if (lookup.projectId) {
|
|
293
|
-
return `${lookup.name} (project ${lookup.projectId})`;
|
|
294
|
-
} else {
|
|
295
|
-
return lookup.name;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
function uniq(elements) {
|
|
299
|
-
return Array.from(new Set(elements));
|
|
300
|
-
}
|
|
301
|
-
function uniqBy(elements, iterator) {
|
|
302
|
-
const vis = /* @__PURE__ */ new Set();
|
|
303
|
-
const filtered = [];
|
|
304
|
-
for (const elt of elements) {
|
|
305
|
-
const key = iterator(elt);
|
|
306
|
-
if (!vis.has(key)) {
|
|
307
|
-
vis.add(key);
|
|
308
|
-
filtered.push(elt);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return filtered;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
336
|
// src/component-lookup.ts
|
|
315
337
|
function getFirstCompMeta(metas, lookup) {
|
|
316
338
|
const filtered = getCompMetas(metas, lookup);
|
|
@@ -468,7 +490,8 @@ var BaseInternalPlasmicComponentLoader = class {
|
|
|
468
490
|
projects: [],
|
|
469
491
|
activeSplits: [],
|
|
470
492
|
bundleKey: null,
|
|
471
|
-
deferChunksByDefault: false
|
|
493
|
+
deferChunksByDefault: false,
|
|
494
|
+
filteredIds: {}
|
|
472
495
|
};
|
|
473
496
|
this.opts = args.opts;
|
|
474
497
|
this.fetcher = args.fetcher;
|
|
@@ -579,7 +602,7 @@ var BaseInternalPlasmicComponentLoader = class {
|
|
|
579
602
|
});
|
|
580
603
|
}
|
|
581
604
|
mergeBundle(newBundle) {
|
|
582
|
-
var _a2, _b
|
|
605
|
+
var _a2, _b;
|
|
583
606
|
newBundle.bundleKey = (_a2 = newBundle.bundleKey) != null ? _a2 : null;
|
|
584
607
|
if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
|
|
585
608
|
console.warn(
|
|
@@ -589,39 +612,8 @@ ${newBundle.bundleKey}
|
|
|
589
612
|
${this.bundle.bundleKey}`
|
|
590
613
|
);
|
|
591
614
|
}
|
|
592
|
-
|
|
593
|
-
this.
|
|
594
|
-
activeSplits: uniqBy(
|
|
595
|
-
bundles.flatMap((bundle) => bundle.activeSplits),
|
|
596
|
-
(split) => split.id
|
|
597
|
-
),
|
|
598
|
-
components: uniqBy(
|
|
599
|
-
bundles.flatMap((bundle) => bundle.components),
|
|
600
|
-
(c) => c.id
|
|
601
|
-
),
|
|
602
|
-
globalGroups: uniqBy(
|
|
603
|
-
bundles.flatMap((bundle) => bundle.globalGroups),
|
|
604
|
-
(g) => g.id
|
|
605
|
-
),
|
|
606
|
-
modules: {
|
|
607
|
-
browser: uniqBy(
|
|
608
|
-
bundles.flatMap((bundle) => bundle.modules.browser),
|
|
609
|
-
(m) => m.fileName
|
|
610
|
-
),
|
|
611
|
-
server: uniqBy(
|
|
612
|
-
bundles.flatMap((bundle) => bundle.modules.server),
|
|
613
|
-
(m) => m.fileName
|
|
614
|
-
)
|
|
615
|
-
},
|
|
616
|
-
projects: uniqBy(
|
|
617
|
-
bundles.flatMap((bundle) => bundle.projects),
|
|
618
|
-
(p) => p.id
|
|
619
|
-
),
|
|
620
|
-
// Avoid `undefined` as it cannot be serialized as JSON
|
|
621
|
-
bundleKey: (_c = (_b = newBundle.bundleKey) != null ? _b : this.bundle.bundleKey) != null ? _c : null,
|
|
622
|
-
deferChunksByDefault: (_d = newBundle.deferChunksByDefault) != null ? _d : false
|
|
623
|
-
};
|
|
624
|
-
(_e = this.onBundleMerged) == null ? void 0 : _e.call(this);
|
|
615
|
+
this.bundle = mergeBundles(newBundle, this.bundle);
|
|
616
|
+
(_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
|
|
625
617
|
}
|
|
626
618
|
getBundle() {
|
|
627
619
|
return this.bundle;
|
|
@@ -637,7 +629,8 @@ ${this.bundle.bundleKey}`
|
|
|
637
629
|
projects: [],
|
|
638
630
|
activeSplits: [],
|
|
639
631
|
bundleKey: null,
|
|
640
|
-
deferChunksByDefault: false
|
|
632
|
+
deferChunksByDefault: false,
|
|
633
|
+
filteredIds: {}
|
|
641
634
|
};
|
|
642
635
|
this.registry.clear();
|
|
643
636
|
}
|