@plasmicapp/loader-react 1.0.328 → 1.0.330
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.d.ts +7 -4
- package/dist/index.esm.js +24 -47
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +24 -47
- package/dist/index.js.map +3 -3
- package/dist/react-server.d.ts +3 -2
- package/dist/react-server.esm.js +19 -18
- package/dist/react-server.esm.js.map +2 -2
- package/dist/react-server.js +19 -18
- package/dist/react-server.js.map +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ declare class ComponentLookup {
|
|
|
70
70
|
getRemoteFonts(): FontMeta[];
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
declare type ComponentLookupSpec = string | {
|
|
73
|
+
export declare type ComponentLookupSpec = string | {
|
|
74
74
|
name: string;
|
|
75
75
|
projectId?: string;
|
|
76
76
|
isCode?: boolean;
|
|
@@ -111,7 +111,7 @@ export declare function extractPlasmicQueryDataFromElement(loader: PlasmicCompon
|
|
|
111
111
|
prefetchedQueryData?: Record<string, any>;
|
|
112
112
|
}): Promise<Record<string, any>>;
|
|
113
113
|
|
|
114
|
-
declare interface FetchComponentDataOpts {
|
|
114
|
+
export declare interface FetchComponentDataOpts {
|
|
115
115
|
/**
|
|
116
116
|
* Will fetch either code targeting SSR or browser hydration in the
|
|
117
117
|
* returned bundle.
|
|
@@ -262,11 +262,12 @@ export declare class InternalPlasmicComponentLoader {
|
|
|
262
262
|
* "world"}}`
|
|
263
263
|
* - `matchesPagePath("/hello/[name]", "/")` -> `false`
|
|
264
264
|
* - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
|
|
265
|
+
* - `matchesPagePath("/hello/[[...catchall]]", "/hello/")` -> `{params: {catchall: []}}`
|
|
265
266
|
* - `matchesPagePath("/", "")` -> `{params: {}}`
|
|
266
267
|
*/
|
|
267
|
-
export declare function matchesPagePath(
|
|
268
|
+
export declare function matchesPagePath(pattern: string, path: string): false | {
|
|
268
269
|
params: Record<string, string | string[]>;
|
|
269
|
-
}
|
|
270
|
+
};
|
|
270
271
|
|
|
271
272
|
export { PageMeta }
|
|
272
273
|
|
|
@@ -353,12 +354,14 @@ export declare class PlasmicComponentLoader {
|
|
|
353
354
|
* the Plasmic project.
|
|
354
355
|
*/
|
|
355
356
|
fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
|
|
357
|
+
fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
|
|
356
358
|
/**
|
|
357
359
|
* Like fetchComponentData(), but returns null instead of throwing an Error
|
|
358
360
|
* when a component is not found. Useful when you are implementing a catch-all
|
|
359
361
|
* page and want to check if a specific path had been defined for Plasmic.
|
|
360
362
|
*/
|
|
361
363
|
maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
|
|
364
|
+
maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
|
|
362
365
|
/**
|
|
363
366
|
* Returns all the page component metadata for these projects.
|
|
364
367
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -149,26 +149,27 @@ function useIsMounted() {
|
|
|
149
149
|
}, []);
|
|
150
150
|
return isMounted;
|
|
151
151
|
}
|
|
152
|
-
function matchesPagePath(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
const pagePathRegExp = new RegExp(
|
|
160
|
-
"^/?" + pagePath.replace(/\[\.\.\.[^\]]*\]/g, "(.+)").replace(/\[[^\]]*\]/g, "([^/]+)") + "$"
|
|
161
|
-
);
|
|
162
|
-
const maybeVals = (_a = lookup.replace(/[?].*/, "").match(pagePathRegExp)) == null ? void 0 : _a.slice(1);
|
|
163
|
-
if (!maybeVals) {
|
|
152
|
+
function matchesPagePath(pattern, path) {
|
|
153
|
+
const normalizedPattern = "/" + pattern.replace(/^\/|\/$/g, "");
|
|
154
|
+
const normalizedPath = "/" + path.replace(/^\/|\/$/g, "");
|
|
155
|
+
const regexString = normalizedPattern.replace(/\/\[\[\.\.\.(\w+)]]/g, "(?:/([^]*))?").replace(/\/\[\.\.\.(\w+)]/g, "/([^]*)").replace(/\[(\w+)]/g, "([^/]+)").replace(/\//g, "\\/");
|
|
156
|
+
const regex = new RegExp(`^/?${regexString}$`);
|
|
157
|
+
const match = normalizedPath.match(regex);
|
|
158
|
+
if (!match)
|
|
164
159
|
return false;
|
|
165
|
-
|
|
160
|
+
const slugNames = [...pattern.matchAll(/\[\.?\.?\.?(\w+)]/g)].map(
|
|
161
|
+
(m) => m[1]
|
|
162
|
+
);
|
|
166
163
|
const params = {};
|
|
167
|
-
for (let i = 0; i <
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
params[
|
|
164
|
+
for (let i = 0; i < slugNames.length; i++) {
|
|
165
|
+
const slugName = slugNames[i];
|
|
166
|
+
const value = match[i + 1];
|
|
167
|
+
if (pattern.includes(`[[...${slugName}]]`)) {
|
|
168
|
+
params[slugName] = value ? value.split("/").filter(Boolean) : [];
|
|
169
|
+
} else if (pattern.includes(`[...${slugName}]`)) {
|
|
170
|
+
params[slugName] = value.split("/").filter(Boolean);
|
|
171
|
+
} else if (value !== void 0) {
|
|
172
|
+
params[slugName] = value;
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
return { params };
|
|
@@ -1102,34 +1103,12 @@ var PlasmicComponentLoader = class {
|
|
|
1102
1103
|
registerToken(token) {
|
|
1103
1104
|
this.__internal.registerToken(token);
|
|
1104
1105
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
* these components. Should be passed into PlasmicRootProvider as
|
|
1108
|
-
* the prefetchedData prop.
|
|
1109
|
-
*
|
|
1110
|
-
* You can look up a component either by:
|
|
1111
|
-
* - the name of the component
|
|
1112
|
-
* - the path for a page component
|
|
1113
|
-
* - an array of strings that make up parts of the path
|
|
1114
|
-
* - object { name: "name_or_path", projectId: ...}, to specify which project
|
|
1115
|
-
* to use, if multiple projects have the same component name
|
|
1116
|
-
*
|
|
1117
|
-
* Throws an Error if a specified component to fetch does not exist in
|
|
1118
|
-
* the Plasmic project.
|
|
1119
|
-
*/
|
|
1120
|
-
fetchComponentData(...specs) {
|
|
1121
|
-
return __async(this, null, function* () {
|
|
1122
|
-
return this.__internal.fetchComponentData(...specs);
|
|
1123
|
-
});
|
|
1106
|
+
fetchComponentData(...args) {
|
|
1107
|
+
return this.__internal.fetchComponentData(...args);
|
|
1124
1108
|
}
|
|
1125
|
-
|
|
1126
|
-
* Like fetchComponentData(), but returns null instead of throwing an Error
|
|
1127
|
-
* when a component is not found. Useful when you are implementing a catch-all
|
|
1128
|
-
* page and want to check if a specific path had been defined for Plasmic.
|
|
1129
|
-
*/
|
|
1130
|
-
maybeFetchComponentData(...specs) {
|
|
1109
|
+
maybeFetchComponentData(...args) {
|
|
1131
1110
|
return __async(this, null, function* () {
|
|
1132
|
-
return this.__internal.maybeFetchComponentData(...
|
|
1111
|
+
return this.__internal.maybeFetchComponentData(...args);
|
|
1133
1112
|
});
|
|
1134
1113
|
}
|
|
1135
1114
|
/**
|
|
@@ -1203,6 +1182,7 @@ import {
|
|
|
1203
1182
|
useSelector,
|
|
1204
1183
|
useSelectors
|
|
1205
1184
|
} from "@plasmicapp/host";
|
|
1185
|
+
import { extractPlasmicQueryData as extractPlasmicQueryData2, plasmicPrepass } from "@plasmicapp/prepass";
|
|
1206
1186
|
import { usePlasmicQueryData } from "@plasmicapp/query";
|
|
1207
1187
|
|
|
1208
1188
|
// src/PlasmicComponent.tsx
|
|
@@ -1339,9 +1319,6 @@ function MaybeWrap(props) {
|
|
|
1339
1319
|
return props.cond ? props.wrapper(props.children) : props.children;
|
|
1340
1320
|
}
|
|
1341
1321
|
|
|
1342
|
-
// src/index.ts
|
|
1343
|
-
import { extractPlasmicQueryData as extractPlasmicQueryData2, plasmicPrepass } from "@plasmicapp/prepass";
|
|
1344
|
-
|
|
1345
1322
|
// src/render.tsx
|
|
1346
1323
|
import React6 from "react";
|
|
1347
1324
|
import ReactDOM2 from "react-dom";
|