@plasmicapp/loader-react 1.0.317 → 1.0.318

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 CHANGED
@@ -1,15 +1,523 @@
1
- import { CodeComponentMeta, InternalPlasmicComponentLoader, PlasmicComponentLoader } from "./loader";
2
- import type { InitOptions } from "./loader-react-server";
3
- export type { PropType, TokenRegistration } from "@plasmicapp/host";
4
- export { DataCtxReader, DataProvider, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, repeatedElement, useDataEnv, usePlasmicCanvasContext, useSelector, useSelectors, } from "@plasmicapp/host";
5
- export { usePlasmicQueryData } from "@plasmicapp/query";
6
- export * from "./shared-exports";
7
- export { PlasmicComponent } from "./PlasmicComponent";
8
- export type { GlobalVariantSpec, PlasmicTranslator, } from "./PlasmicRootProvider";
9
- export { PlasmicRootProvider } from "./PlasmicRootProvider";
10
- export { extractPlasmicQueryData, plasmicPrepass } from "@plasmicapp/prepass";
11
- export { extractPlasmicQueryDataFromElement, hydrateFromElement, renderToElement, renderToString, } from "./render";
12
- export { usePlasmicComponent } from "./usePlasmicComponent";
13
- export type { CodeComponentMeta };
14
- export { InternalPlasmicComponentLoader, PlasmicComponentLoader };
1
+ import { AssetModule } from '@plasmicapp/loader-core';
2
+ import { CodeComponentMeta as CodeComponentMeta_2 } from '@plasmicapp/host';
3
+ import { ComponentMeta } from '@plasmicapp/loader-core';
4
+ import { CustomFunctionMeta as CustomFunctionMeta_2 } from '@plasmicapp/host';
5
+ import { DataCtxReader } from '@plasmicapp/host';
6
+ import { DataProvider } from '@plasmicapp/host';
7
+ import { extractPlasmicQueryData } from '@plasmicapp/prepass';
8
+ import { FontMeta } from '@plasmicapp/loader-core';
9
+ import { getExternalIds } from '@plasmicapp/loader-splits';
10
+ import { GlobalContextMeta as GlobalContextMeta_2 } from '@plasmicapp/host';
11
+ import { GlobalGroupMeta } from '@plasmicapp/loader-core';
12
+ import { LoaderBundleCache } from '@plasmicapp/loader-core';
13
+ import { LoaderBundleOutput } from '@plasmicapp/loader-core';
14
+ import { PageMeta } from '@plasmicapp/loader-core';
15
+ import { PageMeta as PageMeta_2 } from '@plasmicapp/loader-fetcher';
16
+ import { PageMetadata } from '@plasmicapp/loader-core';
17
+ import { PageParamsProvider } from '@plasmicapp/host';
18
+ import { PlasmicCanvasContext } from '@plasmicapp/host';
19
+ import { PlasmicCanvasHost } from '@plasmicapp/host';
20
+ import { PlasmicDataSourceContextValue } from '@plasmicapp/data-sources-context';
21
+ import { plasmicPrepass } from '@plasmicapp/prepass';
22
+ import { PropType } from '@plasmicapp/host';
23
+ import { default as React_2 } from 'react';
24
+ import * as React_3 from 'react';
25
+ import { Registry } from '@plasmicapp/loader-core';
26
+ import { repeatedElement } from '@plasmicapp/host';
27
+ import { Split } from '@plasmicapp/loader-fetcher';
28
+ import { StateHelpers } from '@plasmicapp/host';
29
+ import { StateSpec } from '@plasmicapp/host';
30
+ import { TokenRegistration } from '@plasmicapp/host';
31
+ import { TrackRenderOptions } from '@plasmicapp/loader-core';
32
+ import { TraitMeta } from '@plasmicapp/host';
33
+ import { useDataEnv } from '@plasmicapp/host';
34
+ import { usePlasmicCanvasContext } from '@plasmicapp/host';
35
+ import { usePlasmicQueryData } from '@plasmicapp/query';
36
+ import { useSelector } from '@plasmicapp/host';
37
+ import { useSelectors } from '@plasmicapp/host';
38
+
39
+ export declare type CodeComponentMeta<P> = Omit<CodeComponentMeta_2<P>, "importPath" | "componentHelpers" | "states"> & {
40
+ /**
41
+ * The path to be used when importing the component in the generated code.
42
+ * It can be the name of the package that contains the component, or the path
43
+ * to the file in the project (relative to the root directory).
44
+ * Optional: not used by Plasmic headless API, only by codegen.
45
+ */
46
+ importPath?: string;
47
+ /**
48
+ * The states helpers are registered together with the states for the Plasmic headless API
49
+ */
50
+ states?: Record<string, StateSpec<P> & StateHelpers<P, any>>;
51
+ };
52
+
53
+ declare class ComponentLookup {
54
+ private bundle;
55
+ private registry;
56
+ constructor(bundle: LoaderBundleOutput, registry: Registry);
57
+ getComponentMeta(spec: ComponentLookupSpec): ComponentMeta | undefined;
58
+ getComponent<P extends React_3.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
59
+ forceOriginal?: boolean;
60
+ }): any;
61
+ hasComponent(spec: ComponentLookupSpec): boolean;
62
+ getGlobalContexts(): {
63
+ meta: GlobalGroupMeta;
64
+ context: any;
65
+ }[];
66
+ getGlobalContextsProvider(spec: ComponentLookupSpec): any;
67
+ getRootProvider(): any;
68
+ getCss(): AssetModule[];
69
+ getRemoteFonts(): FontMeta[];
70
+ }
71
+
72
+ declare type ComponentLookupSpec = string | {
73
+ name: string;
74
+ projectId?: string;
75
+ isCode?: boolean;
76
+ };
77
+
78
+ export { ComponentMeta }
79
+
80
+ export declare interface ComponentRenderData {
81
+ entryCompMetas: (ComponentMeta & {
82
+ params?: Record<string, string>;
83
+ })[];
84
+ bundle: LoaderBundleOutput;
85
+ remoteFontUrls: string[];
86
+ }
87
+
88
+ export declare const convertBundlesToComponentRenderData: (bundles: LoaderBundleOutput[], compMetas: ComponentMeta[]) => ComponentRenderData | null;
89
+
90
+ declare type CustomFunctionMeta<F extends (...args: any[]) => any> = Omit<CustomFunctionMeta_2<F>, "importPath"> & {
91
+ /**
92
+ * The path to be used when importing the function in the generated code.
93
+ * It can be the name of the package that contains the function, or the path
94
+ * to the file in the project (relative to the root directory).
95
+ * Optional: not used by Plasmic headless API, only by codegen.
96
+ */
97
+ importPath?: string;
98
+ };
99
+
100
+ export { DataCtxReader }
101
+
102
+ export { DataProvider }
103
+
104
+ export { extractPlasmicQueryData }
105
+
106
+ export declare function extractPlasmicQueryDataFromElement(loader: PlasmicComponentLoader, lookup: ComponentLookupSpec, opts?: {
107
+ prefetchedData?: ComponentRenderData;
108
+ componentProps?: any;
109
+ globalVariants?: GlobalVariantSpec[];
110
+ prefetchedQueryData?: Record<string, any>;
111
+ }): Promise<Record<string, any>>;
112
+
113
+ declare interface FetchComponentDataOpts {
114
+ /**
115
+ * Will fetch either code targeting SSR or browser hydration in the
116
+ * returned bundle.
117
+ *
118
+ * By default, the target is browser. That's okay, because even when
119
+ * doing SSR, as long as you are using the same instance of PlasmicLoader
120
+ * that was used to fetch component data, it will still know how to get at
121
+ * the server code.
122
+ *
123
+ * But, if you are building your own SSR solution, where fetching and rendering
124
+ * are using different instances of PlasmicLoader, then you'll want to make
125
+ * sure that when you fetch, you are fetching the right one to be used in the
126
+ * right environment for either SSR or browser hydration.
127
+ */
128
+ target?: "server" | "browser";
129
+ }
130
+
131
+ declare type FetchPagesOpts = {
132
+ /**
133
+ * Whether to include dynamic pages in fetchPages() output. A page is
134
+ * considered dynamic if its path contains some param between brackets,
135
+ * e.g. "[slug]".
136
+ */
137
+ includeDynamicPages?: boolean;
138
+ };
139
+
140
+ declare type GlobalContextMeta<P> = Omit<GlobalContextMeta_2<P>, "importPath"> & {
141
+ /**
142
+ * The path to be used when importing the component in the generated code.
143
+ * It can be the name of the package that contains the component, or the path
144
+ * to the file in the project (relative to the root directory).
145
+ * Optional: not used by Plasmic headless API, only by codegen.
146
+ */
147
+ importPath?: string;
148
+ };
149
+
150
+ export declare interface GlobalVariantSpec {
151
+ name: string;
152
+ projectId?: string;
153
+ value: any;
154
+ }
155
+
156
+ export declare function hydrateFromElement(loader: PlasmicComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
157
+ prefetchedData?: ComponentRenderData;
158
+ componentProps?: any;
159
+ globalVariants?: GlobalVariantSpec[];
160
+ prefetchedQueryData?: Record<string, any>;
161
+ }): Promise<void>;
162
+
163
+ export declare interface InitOptions {
164
+ projects: {
165
+ id: string;
166
+ token: string;
167
+ version?: string;
168
+ }[];
169
+ cache?: LoaderBundleCache;
170
+ platform?: "react" | "nextjs" | "gatsby";
171
+ platformOptions?: {
172
+ nextjs?: {
173
+ appDir: boolean;
174
+ };
175
+ };
176
+ preview?: boolean;
177
+ host?: string;
178
+ onClientSideFetch?: "warn" | "error";
179
+ i18n?: {
180
+ keyScheme: "content" | "hash" | "path";
181
+ tagPrefix?: string;
182
+ };
183
+ /**
184
+ * @deprecated use i18n.keyScheme instead
185
+ */
186
+ i18nKeyScheme?: "content" | "hash";
187
+ /**
188
+ * By default, fetchComponentData() and fetchPages() calls cached in memory
189
+ * with the PlasmicComponentLoader instance. If alwaysFresh is true, then
190
+ * data is always freshly fetched over the network.
191
+ */
192
+ alwaysFresh?: boolean;
193
+ /**
194
+ * If true, generated code from the server won't include page metadata tags
195
+ */
196
+ skipHead?: boolean;
197
+ /**
198
+ * If true, uses browser / node's native fetch
199
+ */
200
+ nativeFetch?: boolean;
201
+ }
202
+
15
203
  export declare function initPlasmicLoader(opts: InitOptions): PlasmicComponentLoader;
204
+
205
+ export declare class InternalPlasmicComponentLoader {
206
+ opts: InitOptions;
207
+ private readonly reactServerLoader;
208
+ private readonly registry;
209
+ private subs;
210
+ private roots;
211
+ private globalVariants;
212
+ private tracker;
213
+ constructor(opts: InitOptions);
214
+ getBundle(): LoaderBundleOutput;
215
+ setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
216
+ getGlobalVariants(): GlobalVariantSpec[];
217
+ registerModules(modules: Record<string, any>): void;
218
+ substituteComponent<P>(component: React_2.ComponentType<P>, name: ComponentLookupSpec): void;
219
+ private internalSubstituteComponent;
220
+ registerComponent<T extends React_2.ComponentType<any>>(component: T, meta: CodeComponentMeta<React_2.ComponentProps<T>>): void;
221
+ unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
222
+ registerGlobalContext<T extends React_2.ComponentType<any>>(context: T, meta: GlobalContextMeta<React_2.ComponentProps<T>>): void;
223
+ registerTrait(trait: string, meta: TraitMeta): void;
224
+ registerToken(token: TokenRegistration): void;
225
+ registerPrefetchedBundle(bundle: LoaderBundleOutput): void;
226
+ subscribePlasmicRoot(watcher: PlasmicRootWatcher): void;
227
+ unsubscribePlasmicRoot(watcher: PlasmicRootWatcher): void;
228
+ clearCache(): void;
229
+ getLookup(): ComponentLookup;
230
+ maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
231
+ maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
232
+ fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
233
+ fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
234
+ fetchPages(opts?: FetchPagesOpts): Promise<PageMeta_2[]>;
235
+ fetchComponents(): Promise<ComponentMeta[]>;
236
+ getActiveSplits(): Split[];
237
+ trackConversion(value?: number): void;
238
+ getActiveVariation(opts: {
239
+ traits: Record<string, string | number | boolean>;
240
+ getKnownValue: (key: string) => string | undefined;
241
+ updateKnownValue: (key: string, value: string) => void;
242
+ }): Promise<Record<string, string>>;
243
+ getTeamIds(): string[];
244
+ getProjectIds(): string[];
245
+ trackRender(opts?: TrackRenderOptions): void;
246
+ private refreshRegistry;
247
+ }
248
+
249
+ /**
250
+ * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
251
+ * containing path params; otherwise, return false.
252
+ *
253
+ * For example,
254
+ * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
255
+ * "world"}}`
256
+ * - `matchesPagePath("/hello/[name]", "/")` -> `false`
257
+ * - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
258
+ * - `matchesPagePath("/", "")` -> `{params: {}}`
259
+ */
260
+ export declare function matchesPagePath(pagePath: string, lookup: string): {
261
+ params: Record<string, string | string[]>;
262
+ } | false;
263
+
264
+ export { PageMeta }
265
+
266
+ export { PageMetadata }
267
+
268
+ export { PageParamsProvider }
269
+
270
+ export { PlasmicCanvasContext }
271
+
272
+ export { PlasmicCanvasHost }
273
+
274
+ export declare function PlasmicComponent(props: {
275
+ /**
276
+ * Name of the component to render, or the path of the page component
277
+ */
278
+ component: string;
279
+ /**
280
+ * Optionally specify a projectId if there are multiple components
281
+ * of the same name from different projects
282
+ */
283
+ projectId?: string;
284
+ /**
285
+ * If you used registerComponent(), then if the name matches a registered
286
+ * component, that component is used. If you want the Plasmic-generated
287
+ * component instead, specify forceOriginal.
288
+ */
289
+ forceOriginal?: boolean;
290
+ componentProps?: any;
291
+ }): React_3.ReactElement | null;
292
+
293
+ /**
294
+ * Library for fetching component data, and registering
295
+ * custom components.
296
+ */
297
+ export declare class PlasmicComponentLoader {
298
+ private __internal;
299
+ constructor(internal: InternalPlasmicComponentLoader);
300
+ /**
301
+ * Sets global variants to be used for all components. Note that
302
+ * this is not reactive, and will not re-render all components
303
+ * already mounted; instead, it should be used to activate global
304
+ * variants that should always be activated for the lifetime of this
305
+ * app. If you'd like to reactively change the global variants,
306
+ * you should specify them via <PlasmicRootProvider />
307
+ */
308
+ setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
309
+ registerModules(modules: Record<string, any>): void;
310
+ /**
311
+ * Register custom components that should be swapped in for
312
+ * components defined in your project. You can use this to
313
+ * swap in / substitute a Plasmic component with a "real" component.
314
+ */
315
+ substituteComponent<P>(component: React_2.ComponentType<P>, name: ComponentLookupSpec): void;
316
+ /**
317
+ * Register code components to be used on Plasmic Editor.
318
+ */
319
+ registerComponent<T extends React_2.ComponentType<any>>(component: T, meta: CodeComponentMeta<React_2.ComponentProps<T>>): void;
320
+ /**
321
+ * [[deprecated]] Please use `substituteComponent` instead for component
322
+ * substitution, or the other `registerComponent` overload to register
323
+ * code components to be used on Plasmic Editor.
324
+ *
325
+ * @see `substituteComponent`
326
+ */
327
+ registerComponent<T extends React_2.ComponentType<any>>(component: T, name: ComponentLookupSpec): void;
328
+ private warnedRegisterComponent;
329
+ unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
330
+ registerGlobalContext<T extends React_2.ComponentType<any>>(context: T, meta: GlobalContextMeta<React_2.ComponentProps<T>>): void;
331
+ registerTrait(trait: string, meta: TraitMeta): void;
332
+ registerToken(token: TokenRegistration): void;
333
+ /**
334
+ * Pre-fetches component data needed to for PlasmicLoader to render
335
+ * these components. Should be passed into PlasmicRootProvider as
336
+ * the prefetchedData prop.
337
+ *
338
+ * You can look up a component either by:
339
+ * - the name of the component
340
+ * - the path for a page component
341
+ * - an array of strings that make up parts of the path
342
+ * - object { name: "name_or_path", projectId: ...}, to specify which project
343
+ * to use, if multiple projects have the same component name
344
+ *
345
+ * Throws an Error if a specified component to fetch does not exist in
346
+ * the Plasmic project.
347
+ */
348
+ fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
349
+ /**
350
+ * Like fetchComponentData(), but returns null instead of throwing an Error
351
+ * when a component is not found. Useful when you are implementing a catch-all
352
+ * page and want to check if a specific path had been defined for Plasmic.
353
+ */
354
+ maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
355
+ /**
356
+ * Returns all the page component metadata for these projects.
357
+ */
358
+ fetchPages(opts?: FetchPagesOpts): Promise<PageMeta_2[]>;
359
+ /**
360
+ * Returns all components metadata for these projects.
361
+ */
362
+ fetchComponents(): Promise<ComponentMeta[]>;
363
+ protected _getActiveVariation(opts: {
364
+ traits: Record<string, string | number | boolean>;
365
+ getKnownValue: (key: string) => string | undefined;
366
+ updateKnownValue: (key: string, value: string) => void;
367
+ }): Promise<Record<string, string>>;
368
+ getActiveVariation(opts: {
369
+ known?: Record<string, string>;
370
+ traits: Record<string, string | number | boolean>;
371
+ }): Promise<Record<string, string>>;
372
+ getExternalVariation(variation: Record<string, string>, filters?: Parameters<typeof getExternalIds>[2]): Record<string, string>;
373
+ getActiveSplits(): Split[];
374
+ trackConversion(value?: number): void;
375
+ clearCache(): void;
376
+ }
377
+
378
+ export { plasmicPrepass }
379
+
380
+ /**
381
+ * PlasmicRootProvider should be used at the root of your page
382
+ * or application.
383
+ */
384
+ export declare function PlasmicRootProvider(props: {
385
+ /**
386
+ * The global PlasmicComponentLoader instance you created via
387
+ * initPlasmicLoader().
388
+ */
389
+ loader: PlasmicComponentLoader;
390
+ /**
391
+ * Global variants to activate for Plasmic components
392
+ */
393
+ globalVariants?: GlobalVariantSpec[];
394
+ children?: React_3.ReactNode;
395
+ /**
396
+ * If true, will skip rendering css
397
+ */
398
+ skipCss?: boolean;
399
+ /**
400
+ * If true, will skip installing fonts
401
+ */
402
+ skipFonts?: boolean;
403
+ /**
404
+ * If you have pre-fetched component data via PlasmicComponentLoader,
405
+ * you can pass them in here; PlasmicComponent will avoid fetching
406
+ * component data that have already been pre-fetched.
407
+ */
408
+ prefetchedData?: ComponentRenderData;
409
+ /**
410
+ * If you have pre-fetched data that are needed by usePlasmicQueryData(),
411
+ * then pass in the pre-fetched cache here, mapping query key to fetched data.
412
+ */
413
+ prefetchedQueryData?: Record<string, any>;
414
+ /**
415
+ * Specifies whether usePlasmicQueryData() should be operating in suspense mode
416
+ * (throwing promises).
417
+ */
418
+ suspenseForQueryData?: boolean;
419
+ /**
420
+ * Override your Global Contexts Provider props. This is a map from
421
+ * globalContextComponentNameProps to object of props to use for that
422
+ * component.
423
+ */
424
+ globalContextsProps?: Record<string, any>;
425
+ /**
426
+ * Specifies a mapping of split id to slice id that should be activated
427
+ */
428
+ variation?: Record<string, string>;
429
+ /**
430
+ * Translator function to be used for text blocks
431
+ */
432
+ translator?: PlasmicTranslator;
433
+ /**
434
+ * Head component to use in PlasmicHead component (e.g. Head from next/head
435
+ * or Helmet from react-helmet).
436
+ */
437
+ Head?: React_3.ComponentType<any>;
438
+ /**
439
+ * Link component to use. Can be any component that takes in props passed
440
+ * to an <a/> tag.
441
+ */
442
+ Link?: React_3.ComponentType<any>;
443
+ /**
444
+ * Page route without params substitution (e.g. /products/[slug]).
445
+ */
446
+ pageRoute?: string;
447
+ /**
448
+ * Page path parameters (e.g. {slug: "foo"} if page path is
449
+ * /products/[slug] and URI is /products/foo).
450
+ */
451
+ pageParams?: Record<string, string | string[] | undefined>;
452
+ /**
453
+ * Page query parameters (e.g. {q: "foo"} if page path is
454
+ * /some/path?q=foo).
455
+ */
456
+ pageQuery?: Record<string, string | string[] | undefined>;
457
+ /**
458
+ * Whether the React.Suspense boundaries should be removed
459
+ */
460
+ disableLoadingBoundary?: boolean;
461
+ /**
462
+ * Fallback value for the root-level React.Suspense
463
+ */
464
+ suspenseFallback?: React_3.ReactNode;
465
+ } & PlasmicDataSourceContextValue): React_3.JSX.Element;
466
+
467
+ declare interface PlasmicRootWatcher {
468
+ onDataFetched?: () => void;
469
+ }
470
+
471
+ export declare type PlasmicTranslator = (str: string, opts?: {
472
+ components?: {
473
+ [key: string]: React_3.ReactElement | React_3.ReactFragment;
474
+ };
475
+ }) => React_3.ReactNode;
476
+
477
+ export { PropType }
478
+
479
+ export declare function renderToElement(loader: PlasmicComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
480
+ prefetchedData?: ComponentRenderData;
481
+ componentProps?: any;
482
+ globalVariants?: GlobalVariantSpec[];
483
+ prefetchedQueryData?: Record<string, any>;
484
+ pageParams?: Record<string, any>;
485
+ pageQuery?: Record<string, any>;
486
+ }): Promise<void>;
487
+
488
+ export declare function renderToString(loader: PlasmicComponentLoader, lookup: ComponentLookupSpec, opts?: {
489
+ prefetchedData?: ComponentRenderData;
490
+ componentProps?: any;
491
+ globalVariants?: GlobalVariantSpec[];
492
+ prefetchedQueryData?: Record<string, any>;
493
+ }): string;
494
+
495
+ export { repeatedElement }
496
+
497
+ export { TokenRegistration }
498
+
499
+ export { useDataEnv }
500
+
501
+ export { usePlasmicCanvasContext }
502
+
503
+ /**
504
+ * Hook that fetches and returns a React component for rendering the argument
505
+ * Plasmic component. Returns undefined if the component data is still
506
+ * being fetched.
507
+ *
508
+ * @param opts.forceOriginal if you used PlasmicComponentLoader.registerComponent,
509
+ * then normally usePlasmicComponent will return the registered component.
510
+ * You can set forceOriginal to true if you want to return the Plasmic-generated
511
+ * component instead.
512
+ */
513
+ export declare function usePlasmicComponent<P extends React_3.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
514
+ forceOriginal?: boolean;
515
+ }): P;
516
+
517
+ export { usePlasmicQueryData }
518
+
519
+ export { useSelector }
520
+
521
+ export { useSelectors }
522
+
523
+ export { }
@@ -1,5 +1,151 @@
1
- import "server-only";
2
- import { InitOptions, ReactServerPlasmicComponentLoader } from "./loader-react-server";
3
- export * from "./shared-exports";
4
- export { ReactServerPlasmicComponentLoader };
1
+ import { ComponentMeta } from '@plasmicapp/loader-core';
2
+ import { ComponentMeta as ComponentMeta_2 } from '@plasmicapp/loader-fetcher';
3
+ import { LoaderBundleCache } from '@plasmicapp/loader-core';
4
+ import { LoaderBundleOutput } from '@plasmicapp/loader-core';
5
+ import { LoaderBundleOutput as LoaderBundleOutput_2 } from '@plasmicapp/loader-fetcher';
6
+ import { PageMeta } from '@plasmicapp/loader-core';
7
+ import { PageMetadata } from '@plasmicapp/loader-core';
8
+ import { PlasmicModulesFetcher } from '@plasmicapp/loader-core';
9
+ import { PlasmicTracker } from '@plasmicapp/loader-core';
10
+ import { Split } from '@plasmicapp/loader-fetcher';
11
+
12
+ declare type ComponentLookupSpec = string | {
13
+ name: string;
14
+ projectId?: string;
15
+ isCode?: boolean;
16
+ };
17
+
18
+ export { ComponentMeta }
19
+
20
+ export declare interface ComponentRenderData {
21
+ entryCompMetas: (ComponentMeta & {
22
+ params?: Record<string, string>;
23
+ })[];
24
+ bundle: LoaderBundleOutput;
25
+ remoteFontUrls: string[];
26
+ }
27
+
28
+ export declare const convertBundlesToComponentRenderData: (bundles: LoaderBundleOutput[], compMetas: ComponentMeta[]) => ComponentRenderData | null;
29
+
30
+ declare interface FetchComponentDataOpts {
31
+ /**
32
+ * Will fetch either code targeting SSR or browser hydration in the
33
+ * returned bundle.
34
+ *
35
+ * By default, the target is browser. That's okay, because even when
36
+ * doing SSR, as long as you are using the same instance of PlasmicLoader
37
+ * that was used to fetch component data, it will still know how to get at
38
+ * the server code.
39
+ *
40
+ * But, if you are building your own SSR solution, where fetching and rendering
41
+ * are using different instances of PlasmicLoader, then you'll want to make
42
+ * sure that when you fetch, you are fetching the right one to be used in the
43
+ * right environment for either SSR or browser hydration.
44
+ */
45
+ target?: "server" | "browser";
46
+ }
47
+
48
+ declare type FetchPagesOpts = {
49
+ /**
50
+ * Whether to include dynamic pages in fetchPages() output. A page is
51
+ * considered dynamic if its path contains some param between brackets,
52
+ * e.g. "[slug]".
53
+ */
54
+ includeDynamicPages?: boolean;
55
+ };
56
+
57
+ export declare interface InitOptions {
58
+ projects: {
59
+ id: string;
60
+ token: string;
61
+ version?: string;
62
+ }[];
63
+ cache?: LoaderBundleCache;
64
+ platform?: "react" | "nextjs" | "gatsby";
65
+ platformOptions?: {
66
+ nextjs?: {
67
+ appDir: boolean;
68
+ };
69
+ };
70
+ preview?: boolean;
71
+ host?: string;
72
+ onClientSideFetch?: "warn" | "error";
73
+ i18n?: {
74
+ keyScheme: "content" | "hash" | "path";
75
+ tagPrefix?: string;
76
+ };
77
+ /**
78
+ * @deprecated use i18n.keyScheme instead
79
+ */
80
+ i18nKeyScheme?: "content" | "hash";
81
+ /**
82
+ * By default, fetchComponentData() and fetchPages() calls cached in memory
83
+ * with the PlasmicComponentLoader instance. If alwaysFresh is true, then
84
+ * data is always freshly fetched over the network.
85
+ */
86
+ alwaysFresh?: boolean;
87
+ /**
88
+ * If true, generated code from the server won't include page metadata tags
89
+ */
90
+ skipHead?: boolean;
91
+ /**
92
+ * If true, uses browser / node's native fetch
93
+ */
94
+ nativeFetch?: boolean;
95
+ }
96
+
5
97
  export declare function initPlasmicLoader(opts: InitOptions): ReactServerPlasmicComponentLoader;
98
+
99
+ /**
100
+ * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
101
+ * containing path params; otherwise, return false.
102
+ *
103
+ * For example,
104
+ * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
105
+ * "world"}}`
106
+ * - `matchesPagePath("/hello/[name]", "/")` -> `false`
107
+ * - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
108
+ * - `matchesPagePath("/", "")` -> `{params: {}}`
109
+ */
110
+ export declare function matchesPagePath(pagePath: string, lookup: string): {
111
+ params: Record<string, string | string[]>;
112
+ } | false;
113
+
114
+ export { PageMeta }
115
+
116
+ export { PageMetadata }
117
+
118
+ /** Subset of loader functionality that works on React Server Components. */
119
+ export declare class ReactServerPlasmicComponentLoader {
120
+ private readonly opts;
121
+ private readonly fetcher;
122
+ private readonly tracker;
123
+ private readonly onBundleMerged?;
124
+ private readonly onBundleFetched?;
125
+ private bundle;
126
+ constructor(args: {
127
+ opts: InitOptions;
128
+ fetcher: PlasmicModulesFetcher;
129
+ tracker: PlasmicTracker;
130
+ /** Called after `mergeBundle` (including `fetch` calls). */
131
+ onBundleMerged?: () => void;
132
+ /** Called after any `fetch` calls. */
133
+ onBundleFetched?: () => void;
134
+ });
135
+ private maybeGetCompMetas;
136
+ maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
137
+ maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
138
+ fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
139
+ fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
140
+ fetchPages(opts?: FetchPagesOpts): Promise<PageMeta[]>;
141
+ fetchComponents(): Promise<ComponentMeta_2[]>;
142
+ getActiveSplits(): Split[];
143
+ private fetchMissingData;
144
+ private maybeReportClientSideFetch;
145
+ private fetchAllData;
146
+ mergeBundle(bundle: LoaderBundleOutput_2): void;
147
+ getBundle(): LoaderBundleOutput_2;
148
+ clearCache(): void;
149
+ }
150
+
151
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/loader-react",
3
- "version": "1.0.317",
3
+ "version": "1.0.318",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -42,9 +42,6 @@
42
42
  "build:types": "yarn tsc",
43
43
  "build:index": "node ../../build.mjs ./src/index.ts --use-client",
44
44
  "build:react-server": "node ../../build.mjs ./src/react-server.ts",
45
- "postbuild": "yarn postbuild:index && yarn postbuild:react-server",
46
- "postbuild:index": "node ../../print-module-api.js ./packages/loader-react/dist/index.js > index-api.txt",
47
- "postbuild:react-server": "node ../../print-module-api.js ./packages/loader-react/dist/react-server.js > index-react-server-api.txt",
48
45
  "yalcp": "yalc publish --push",
49
46
  "test": "yarn --cwd=../.. test",
50
47
  "coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
@@ -54,13 +51,13 @@
54
51
  "analyze": "size-limit --why"
55
52
  },
56
53
  "dependencies": {
57
- "@plasmicapp/data-sources-context": "0.1.18",
58
- "@plasmicapp/host": "1.0.178",
59
- "@plasmicapp/loader-core": "1.0.119",
60
- "@plasmicapp/loader-fetcher": "1.0.41",
61
- "@plasmicapp/loader-splits": "1.0.47",
62
- "@plasmicapp/prepass": "1.0.11",
63
- "@plasmicapp/query": "0.1.75",
54
+ "@plasmicapp/data-sources-context": "0.1.19",
55
+ "@plasmicapp/host": "1.0.179",
56
+ "@plasmicapp/loader-core": "1.0.120",
57
+ "@plasmicapp/loader-fetcher": "1.0.42",
58
+ "@plasmicapp/loader-splits": "1.0.48",
59
+ "@plasmicapp/prepass": "1.0.12",
60
+ "@plasmicapp/query": "0.1.76",
64
61
  "pascalcase": "^1.0.0",
65
62
  "server-only": "0.0.1"
66
63
  },
@@ -86,5 +83,5 @@
86
83
  "@types/react-is": "^17.0.3"
87
84
  },
88
85
  "license": "MIT",
89
- "gitHead": "6f034859cd2316dfed75d01006abbc002149374c"
86
+ "gitHead": "48a2877c3dc093d101508fcdde2fd213055fdab9"
90
87
  }
@@ -1,19 +0,0 @@
1
- import * as React from "react";
2
- export declare function PlasmicComponent(props: {
3
- /**
4
- * Name of the component to render, or the path of the page component
5
- */
6
- component: string;
7
- /**
8
- * Optionally specify a projectId if there are multiple components
9
- * of the same name from different projects
10
- */
11
- projectId?: string;
12
- /**
13
- * If you used registerComponent(), then if the name matches a registered
14
- * component, that component is used. If you want the Plasmic-generated
15
- * component instead, specify forceOriginal.
16
- */
17
- forceOriginal?: boolean;
18
- componentProps?: any;
19
- }): React.ReactElement | null;
@@ -1,112 +0,0 @@
1
- import { PlasmicDataSourceContextValue } from "@plasmicapp/data-sources-context";
2
- import * as React from "react";
3
- import { ComponentRenderData, InternalPlasmicComponentLoader, PlasmicComponentLoader } from "./loader";
4
- interface PlasmicRootContextValue extends PlasmicDataSourceContextValue {
5
- globalVariants?: GlobalVariantSpec[];
6
- globalContextsProps?: Record<string, any>;
7
- loader: InternalPlasmicComponentLoader;
8
- variation?: Record<string, string>;
9
- translator?: PlasmicTranslator;
10
- Head?: React.ComponentType<any>;
11
- Link?: React.ComponentType<any>;
12
- disableLoadingBoundary?: boolean;
13
- suspenseFallback?: React.ReactNode;
14
- }
15
- export interface GlobalVariantSpec {
16
- name: string;
17
- projectId?: string;
18
- value: any;
19
- }
20
- export type PlasmicTranslator = (str: string, opts?: {
21
- components?: {
22
- [key: string]: React.ReactElement | React.ReactFragment;
23
- };
24
- }) => React.ReactNode;
25
- /**
26
- * PlasmicRootProvider should be used at the root of your page
27
- * or application.
28
- */
29
- export declare function PlasmicRootProvider(props: {
30
- /**
31
- * The global PlasmicComponentLoader instance you created via
32
- * initPlasmicLoader().
33
- */
34
- loader: PlasmicComponentLoader;
35
- /**
36
- * Global variants to activate for Plasmic components
37
- */
38
- globalVariants?: GlobalVariantSpec[];
39
- children?: React.ReactNode;
40
- /**
41
- * If true, will skip rendering css
42
- */
43
- skipCss?: boolean;
44
- /**
45
- * If true, will skip installing fonts
46
- */
47
- skipFonts?: boolean;
48
- /**
49
- * If you have pre-fetched component data via PlasmicComponentLoader,
50
- * you can pass them in here; PlasmicComponent will avoid fetching
51
- * component data that have already been pre-fetched.
52
- */
53
- prefetchedData?: ComponentRenderData;
54
- /**
55
- * If you have pre-fetched data that are needed by usePlasmicQueryData(),
56
- * then pass in the pre-fetched cache here, mapping query key to fetched data.
57
- */
58
- prefetchedQueryData?: Record<string, any>;
59
- /**
60
- * Specifies whether usePlasmicQueryData() should be operating in suspense mode
61
- * (throwing promises).
62
- */
63
- suspenseForQueryData?: boolean;
64
- /**
65
- * Override your Global Contexts Provider props. This is a map from
66
- * globalContextComponentNameProps to object of props to use for that
67
- * component.
68
- */
69
- globalContextsProps?: Record<string, any>;
70
- /**
71
- * Specifies a mapping of split id to slice id that should be activated
72
- */
73
- variation?: Record<string, string>;
74
- /**
75
- * Translator function to be used for text blocks
76
- */
77
- translator?: PlasmicTranslator;
78
- /**
79
- * Head component to use in PlasmicHead component (e.g. Head from next/head
80
- * or Helmet from react-helmet).
81
- */
82
- Head?: React.ComponentType<any>;
83
- /**
84
- * Link component to use. Can be any component that takes in props passed
85
- * to an <a/> tag.
86
- */
87
- Link?: React.ComponentType<any>;
88
- /**
89
- * Page route without params substitution (e.g. /products/[slug]).
90
- */
91
- pageRoute?: string;
92
- /**
93
- * Page path parameters (e.g. {slug: "foo"} if page path is
94
- * /products/[slug] and URI is /products/foo).
95
- */
96
- pageParams?: Record<string, string | string[] | undefined>;
97
- /**
98
- * Page query parameters (e.g. {q: "foo"} if page path is
99
- * /some/path?q=foo).
100
- */
101
- pageQuery?: Record<string, string | string[] | undefined>;
102
- /**
103
- * Whether the React.Suspense boundaries should be removed
104
- */
105
- disableLoadingBoundary?: boolean;
106
- /**
107
- * Fallback value for the root-level React.Suspense
108
- */
109
- suspenseFallback?: React.ReactNode;
110
- } & PlasmicDataSourceContextValue): React.JSX.Element;
111
- export declare function usePlasmicRootContext(): PlasmicRootContextValue | undefined;
112
- export {};
package/dist/bundles.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { ComponentMeta, LoaderBundleOutput } from '@plasmicapp/loader-core';
2
- import type { ComponentRenderData } from './loader';
3
- export declare function prepComponentData(bundle: LoaderBundleOutput, compMetas: ComponentMeta[], opts?: {
4
- target?: 'browser' | 'server';
5
- }): ComponentRenderData;
6
- export declare function mergeBundles(target: LoaderBundleOutput, from: LoaderBundleOutput): LoaderBundleOutput;
7
- export declare const convertBundlesToComponentRenderData: (bundles: LoaderBundleOutput[], compMetas: ComponentMeta[]) => ComponentRenderData | null;
@@ -1,21 +0,0 @@
1
- import { AssetModule, ComponentMeta, FontMeta, GlobalGroupMeta, LoaderBundleOutput, Registry } from '@plasmicapp/loader-core';
2
- import * as React from 'react';
3
- import { ComponentLookupSpec } from './utils';
4
- export declare class ComponentLookup {
5
- private bundle;
6
- private registry;
7
- constructor(bundle: LoaderBundleOutput, registry: Registry);
8
- getComponentMeta(spec: ComponentLookupSpec): ComponentMeta | undefined;
9
- getComponent<P extends React.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
10
- forceOriginal?: boolean;
11
- }): any;
12
- hasComponent(spec: ComponentLookupSpec): boolean;
13
- getGlobalContexts(): {
14
- meta: GlobalGroupMeta;
15
- context: any;
16
- }[];
17
- getGlobalContextsProvider(spec: ComponentLookupSpec): any;
18
- getRootProvider(): any;
19
- getCss(): AssetModule[];
20
- getRemoteFonts(): FontMeta[];
21
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * We don't actually make use of the global variant React contexts generated
3
- * in the bundle. That's because we would have to wait until the data is
4
- * loaded before we can set up the context providers, but setting up context
5
- * providers will mutate the React tree and invalidate all the children. That means
6
- * once data comes in, we'll re-render the React tree from the providers down
7
- * in a way that will lose all existing React state. Therefore, instead,
8
- * we always have a single context provided -- the PlasmicRootContext -- and we
9
- * create these fake useGlobalVariant() hooks that just read from that
10
- * PlasmicRootContext. This allows us to have a stable React tree before and
11
- * after the data load.
12
- */
13
- export declare function createUseGlobalVariant(name: string, projectId: string): () => any;
@@ -1,92 +0,0 @@
1
- import { LoaderBundleCache, PageMeta, PlasmicModulesFetcher, PlasmicTracker } from "@plasmicapp/loader-core";
2
- import { ComponentMeta, LoaderBundleOutput } from "@plasmicapp/loader-fetcher";
3
- import { ComponentRenderData, FetchPagesOpts } from "./loader";
4
- import { ComponentLookupSpec } from "./utils";
5
- export interface InitOptions {
6
- projects: {
7
- id: string;
8
- token: string;
9
- version?: string;
10
- }[];
11
- cache?: LoaderBundleCache;
12
- platform?: "react" | "nextjs" | "gatsby";
13
- platformOptions?: {
14
- nextjs?: {
15
- appDir: boolean;
16
- };
17
- };
18
- preview?: boolean;
19
- host?: string;
20
- onClientSideFetch?: "warn" | "error";
21
- i18n?: {
22
- keyScheme: "content" | "hash" | "path";
23
- tagPrefix?: string;
24
- };
25
- /**
26
- * @deprecated use i18n.keyScheme instead
27
- */
28
- i18nKeyScheme?: "content" | "hash";
29
- /**
30
- * By default, fetchComponentData() and fetchPages() calls cached in memory
31
- * with the PlasmicComponentLoader instance. If alwaysFresh is true, then
32
- * data is always freshly fetched over the network.
33
- */
34
- alwaysFresh?: boolean;
35
- /**
36
- * If true, generated code from the server won't include page metadata tags
37
- */
38
- skipHead?: boolean;
39
- /**
40
- * If true, uses browser / node's native fetch
41
- */
42
- nativeFetch?: boolean;
43
- }
44
- /** Subset of loader functionality that works on React Server Components. */
45
- export declare class ReactServerPlasmicComponentLoader {
46
- private readonly opts;
47
- private readonly fetcher;
48
- private readonly tracker;
49
- private readonly onBundleMerged?;
50
- private readonly onBundleFetched?;
51
- private bundle;
52
- constructor(args: {
53
- opts: InitOptions;
54
- fetcher: PlasmicModulesFetcher;
55
- tracker: PlasmicTracker;
56
- /** Called after `mergeBundle` (including `fetch` calls). */
57
- onBundleMerged?: () => void;
58
- /** Called after any `fetch` calls. */
59
- onBundleFetched?: () => void;
60
- });
61
- private maybeGetCompMetas;
62
- maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
63
- maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
64
- fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
65
- fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
66
- fetchPages(opts?: FetchPagesOpts): Promise<PageMeta[]>;
67
- fetchComponents(): Promise<ComponentMeta[]>;
68
- getActiveSplits(): import("@plasmicapp/loader-core").Split[];
69
- private fetchMissingData;
70
- private maybeReportClientSideFetch;
71
- private fetchAllData;
72
- mergeBundle(bundle: LoaderBundleOutput): void;
73
- getBundle(): LoaderBundleOutput;
74
- clearCache(): void;
75
- }
76
- export interface FetchComponentDataOpts {
77
- /**
78
- * Will fetch either code targeting SSR or browser hydration in the
79
- * returned bundle.
80
- *
81
- * By default, the target is browser. That's okay, because even when
82
- * doing SSR, as long as you are using the same instance of PlasmicLoader
83
- * that was used to fetch component data, it will still know how to get at
84
- * the server code.
85
- *
86
- * But, if you are building your own SSR solution, where fetching and rendering
87
- * are using different instances of PlasmicLoader, then you'll want to make
88
- * sure that when you fetch, you are fetching the right one to be used in the
89
- * right environment for either SSR or browser hydration.
90
- */
91
- target?: "server" | "browser";
92
- }
package/dist/loader.d.ts DELETED
@@ -1,185 +0,0 @@
1
- import { CodeComponentMeta as InternalCodeComponentMeta, CustomFunctionMeta as InternalCustomFunctionMeta, GlobalContextMeta as InternalGlobalContextMeta, StateHelpers, StateSpec, TokenRegistration, TraitMeta } from "@plasmicapp/host";
2
- import { ComponentMeta, LoaderBundleOutput, TrackRenderOptions } from "@plasmicapp/loader-core";
3
- import { getExternalIds } from "@plasmicapp/loader-splits";
4
- import React from "react";
5
- import { ComponentLookup } from "./component-lookup";
6
- import { FetchComponentDataOpts, InitOptions } from "./loader-react-server";
7
- import type { GlobalVariantSpec } from "./PlasmicRootProvider";
8
- import { ComponentLookupSpec } from "./utils";
9
- export interface ComponentRenderData {
10
- entryCompMetas: (ComponentMeta & {
11
- params?: Record<string, string>;
12
- })[];
13
- bundle: LoaderBundleOutput;
14
- remoteFontUrls: string[];
15
- }
16
- interface PlasmicRootWatcher {
17
- onDataFetched?: () => void;
18
- }
19
- export type CodeComponentMeta<P> = Omit<InternalCodeComponentMeta<P>, "importPath" | "componentHelpers" | "states"> & {
20
- /**
21
- * The path to be used when importing the component in the generated code.
22
- * It can be the name of the package that contains the component, or the path
23
- * to the file in the project (relative to the root directory).
24
- * Optional: not used by Plasmic headless API, only by codegen.
25
- */
26
- importPath?: string;
27
- /**
28
- * The states helpers are registered together with the states for the Plasmic headless API
29
- */
30
- states?: Record<string, StateSpec<P> & StateHelpers<P, any>>;
31
- };
32
- export type GlobalContextMeta<P> = Omit<InternalGlobalContextMeta<P>, "importPath"> & {
33
- /**
34
- * The path to be used when importing the component in the generated code.
35
- * It can be the name of the package that contains the component, or the path
36
- * to the file in the project (relative to the root directory).
37
- * Optional: not used by Plasmic headless API, only by codegen.
38
- */
39
- importPath?: string;
40
- };
41
- export type CustomFunctionMeta<F extends (...args: any[]) => any> = Omit<InternalCustomFunctionMeta<F>, "importPath"> & {
42
- /**
43
- * The path to be used when importing the function in the generated code.
44
- * It can be the name of the package that contains the function, or the path
45
- * to the file in the project (relative to the root directory).
46
- * Optional: not used by Plasmic headless API, only by codegen.
47
- */
48
- importPath?: string;
49
- };
50
- export type FetchPagesOpts = {
51
- /**
52
- * Whether to include dynamic pages in fetchPages() output. A page is
53
- * considered dynamic if its path contains some param between brackets,
54
- * e.g. "[slug]".
55
- */
56
- includeDynamicPages?: boolean;
57
- };
58
- export declare class InternalPlasmicComponentLoader {
59
- opts: InitOptions;
60
- private readonly reactServerLoader;
61
- private readonly registry;
62
- private subs;
63
- private roots;
64
- private globalVariants;
65
- private tracker;
66
- constructor(opts: InitOptions);
67
- getBundle(): LoaderBundleOutput;
68
- setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
69
- getGlobalVariants(): GlobalVariantSpec[];
70
- registerModules(modules: Record<string, any>): void;
71
- substituteComponent<P>(component: React.ComponentType<P>, name: ComponentLookupSpec): void;
72
- private internalSubstituteComponent;
73
- registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
74
- unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
75
- registerGlobalContext<T extends React.ComponentType<any>>(context: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
76
- registerTrait(trait: string, meta: TraitMeta): void;
77
- registerToken(token: TokenRegistration): void;
78
- registerPrefetchedBundle(bundle: LoaderBundleOutput): void;
79
- subscribePlasmicRoot(watcher: PlasmicRootWatcher): void;
80
- unsubscribePlasmicRoot(watcher: PlasmicRootWatcher): void;
81
- clearCache(): void;
82
- getLookup(): ComponentLookup;
83
- maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
84
- maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
85
- fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
86
- fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
87
- fetchPages(opts?: FetchPagesOpts): Promise<import("@plasmicapp/loader-core").PageMeta[]>;
88
- fetchComponents(): Promise<ComponentMeta[]>;
89
- getActiveSplits(): import("@plasmicapp/loader-core").Split[];
90
- trackConversion(value?: number): void;
91
- getActiveVariation(opts: {
92
- traits: Record<string, string | number | boolean>;
93
- getKnownValue: (key: string) => string | undefined;
94
- updateKnownValue: (key: string, value: string) => void;
95
- }): Promise<Record<string, string>>;
96
- getTeamIds(): string[];
97
- getProjectIds(): string[];
98
- trackRender(opts?: TrackRenderOptions): void;
99
- private refreshRegistry;
100
- }
101
- /**
102
- * Library for fetching component data, and registering
103
- * custom components.
104
- */
105
- export declare class PlasmicComponentLoader {
106
- private __internal;
107
- constructor(internal: InternalPlasmicComponentLoader);
108
- /**
109
- * Sets global variants to be used for all components. Note that
110
- * this is not reactive, and will not re-render all components
111
- * already mounted; instead, it should be used to activate global
112
- * variants that should always be activated for the lifetime of this
113
- * app. If you'd like to reactively change the global variants,
114
- * you should specify them via <PlasmicRootProvider />
115
- */
116
- setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
117
- registerModules(modules: Record<string, any>): void;
118
- /**
119
- * Register custom components that should be swapped in for
120
- * components defined in your project. You can use this to
121
- * swap in / substitute a Plasmic component with a "real" component.
122
- */
123
- substituteComponent<P>(component: React.ComponentType<P>, name: ComponentLookupSpec): void;
124
- /**
125
- * Register code components to be used on Plasmic Editor.
126
- */
127
- registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
128
- /**
129
- * [[deprecated]] Please use `substituteComponent` instead for component
130
- * substitution, or the other `registerComponent` overload to register
131
- * code components to be used on Plasmic Editor.
132
- *
133
- * @see `substituteComponent`
134
- */
135
- registerComponent<T extends React.ComponentType<any>>(component: T, name: ComponentLookupSpec): void;
136
- private warnedRegisterComponent;
137
- unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
138
- registerGlobalContext<T extends React.ComponentType<any>>(context: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
139
- registerTrait(trait: string, meta: TraitMeta): void;
140
- registerToken(token: TokenRegistration): void;
141
- /**
142
- * Pre-fetches component data needed to for PlasmicLoader to render
143
- * these components. Should be passed into PlasmicRootProvider as
144
- * the prefetchedData prop.
145
- *
146
- * You can look up a component either by:
147
- * - the name of the component
148
- * - the path for a page component
149
- * - an array of strings that make up parts of the path
150
- * - object { name: "name_or_path", projectId: ...}, to specify which project
151
- * to use, if multiple projects have the same component name
152
- *
153
- * Throws an Error if a specified component to fetch does not exist in
154
- * the Plasmic project.
155
- */
156
- fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
157
- /**
158
- * Like fetchComponentData(), but returns null instead of throwing an Error
159
- * when a component is not found. Useful when you are implementing a catch-all
160
- * page and want to check if a specific path had been defined for Plasmic.
161
- */
162
- maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
163
- /**
164
- * Returns all the page component metadata for these projects.
165
- */
166
- fetchPages(opts?: FetchPagesOpts): Promise<import("@plasmicapp/loader-core").PageMeta[]>;
167
- /**
168
- * Returns all components metadata for these projects.
169
- */
170
- fetchComponents(): Promise<ComponentMeta[]>;
171
- protected _getActiveVariation(opts: {
172
- traits: Record<string, string | number | boolean>;
173
- getKnownValue: (key: string) => string | undefined;
174
- updateKnownValue: (key: string, value: string) => void;
175
- }): Promise<Record<string, string>>;
176
- getActiveVariation(opts: {
177
- known?: Record<string, string>;
178
- traits: Record<string, string | number | boolean>;
179
- }): Promise<Record<string, string>>;
180
- getExternalVariation(variation: Record<string, string>, filters?: Parameters<typeof getExternalIds>[2]): Record<string, string>;
181
- getActiveSplits(): import("@plasmicapp/loader-core").Split[];
182
- trackConversion(value?: number): void;
183
- clearCache(): void;
184
- }
185
- export {};
package/dist/render.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import { ComponentRenderData, PlasmicComponentLoader } from "./loader";
2
- import { GlobalVariantSpec } from "./PlasmicRootProvider";
3
- import { ComponentLookupSpec } from "./utils";
4
- export declare function renderToElement(loader: PlasmicComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
5
- prefetchedData?: ComponentRenderData;
6
- componentProps?: any;
7
- globalVariants?: GlobalVariantSpec[];
8
- prefetchedQueryData?: Record<string, any>;
9
- pageParams?: Record<string, any>;
10
- pageQuery?: Record<string, any>;
11
- }): Promise<void>;
12
- export declare function renderToString(loader: PlasmicComponentLoader, lookup: ComponentLookupSpec, opts?: {
13
- prefetchedData?: ComponentRenderData;
14
- componentProps?: any;
15
- globalVariants?: GlobalVariantSpec[];
16
- prefetchedQueryData?: Record<string, any>;
17
- }): string;
18
- export declare function extractPlasmicQueryDataFromElement(loader: PlasmicComponentLoader, lookup: ComponentLookupSpec, opts?: {
19
- prefetchedData?: ComponentRenderData;
20
- componentProps?: any;
21
- globalVariants?: GlobalVariantSpec[];
22
- prefetchedQueryData?: Record<string, any>;
23
- }): Promise<Record<string, any>>;
24
- export declare function hydrateFromElement(loader: PlasmicComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
25
- prefetchedData?: ComponentRenderData;
26
- componentProps?: any;
27
- globalVariants?: GlobalVariantSpec[];
28
- prefetchedQueryData?: Record<string, any>;
29
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- /** Shared exports for both "default" and "react-server" exports live here. */
2
- export type { ComponentMeta, PageMeta, PageMetadata, } from "@plasmicapp/loader-core";
3
- export { convertBundlesToComponentRenderData } from "./bundles";
4
- export type { ComponentRenderData } from "./loader";
5
- export type { InitOptions } from "./loader-react-server";
6
- export { matchesPagePath } from "./utils";
@@ -1,15 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentLookupSpec } from './utils';
3
- /**
4
- * Hook that fetches and returns a React component for rendering the argument
5
- * Plasmic component. Returns undefined if the component data is still
6
- * being fetched.
7
- *
8
- * @param opts.forceOriginal if you used PlasmicComponentLoader.registerComponent,
9
- * then normally usePlasmicComponent will return the registered component.
10
- * You can set forceOriginal to true if you want to return the Plasmic-generated
11
- * component instead.
12
- */
13
- export declare function usePlasmicComponent<P extends React.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
14
- forceOriginal?: boolean;
15
- }): P;
package/dist/utils.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { ComponentMeta } from "@plasmicapp/loader-core";
2
- export declare const isBrowser: boolean;
3
- export type ComponentLookupSpec = string | {
4
- name: string;
5
- projectId?: string;
6
- isCode?: boolean;
7
- };
8
- export declare function useForceUpdate(): () => void;
9
- export declare function useStableLookupSpec(spec: ComponentLookupSpec): ComponentLookupSpec;
10
- export declare function useStableLookupSpecs(...specs: ComponentLookupSpec[]): ComponentLookupSpec[];
11
- export declare function useIsMounted(): () => boolean;
12
- /**
13
- * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
14
- * containing path params; otherwise, return false.
15
- *
16
- * For example,
17
- * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
18
- * "world"}}`
19
- * - `matchesPagePath("/hello/[name]", "/")` -> `false`
20
- * - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
21
- * - `matchesPagePath("/", "")` -> `{params: {}}`
22
- */
23
- export declare function matchesPagePath(pagePath: string, lookup: string): {
24
- params: Record<string, string | string[]>;
25
- } | false;
26
- export declare function isDynamicPagePath(path: string): boolean;
27
- export declare function getCompMetas(metas: ComponentMeta[], lookup: ComponentLookupSpec): (ComponentMeta & {
28
- params?: Record<string, string | string[]> | undefined;
29
- })[];
30
- export declare function getLookupSpecName(lookup: ComponentLookupSpec): string;
31
- export declare function uniq<T>(elements: T[]): T[];
@@ -1,9 +0,0 @@
1
- import { Split } from "@plasmicapp/loader-core";
2
- import type { GlobalVariantSpec } from "./PlasmicRootProvider";
3
- export declare function getPlasmicCookieValues(): {
4
- [k: string]: string;
5
- };
6
- export declare function updatePlasmicCookieValue(key: string, value: string): void;
7
- export declare function ensureVariationCookies(variation?: Record<string, string>): void;
8
- export declare const getGlobalVariantsFromSplits: (splits: Split[], variation: Record<string, string>) => GlobalVariantSpec[];
9
- export declare const mergeGlobalVariantsSpec: (target: GlobalVariantSpec[], from: GlobalVariantSpec[]) => GlobalVariantSpec[];