@daouy/loader-react 1.0.409

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.
@@ -0,0 +1,728 @@
1
+ import { AssetModule } from '@daouy/loader-core';
2
+ import type { CodeComponentMeta as CodeComponentMeta_2 } from '@daouy/host';
3
+ import { CodeModule } from '@daouy/loader-fetcher';
4
+ import type { ComponentHelpers } from '@daouy/host';
5
+ import { ComponentMeta } from '@daouy/loader-core';
6
+ import { ComponentMeta as ComponentMeta_2 } from '@daouy/loader-fetcher';
7
+ import type { CustomFunctionMeta as CustomFunctionMeta_2 } from '@daouy/host';
8
+ import { DaouyCanvasContext } from '@daouy/host';
9
+ import { DaouyCanvasHost } from '@daouy/host';
10
+ import { DaouyDataSourceContextValue } from '@daouy/data-sources-context';
11
+ import { daouyDataSourcesContext } from '@daouy/data-sources-context';
12
+ import { daouyHost } from '@daouy/host';
13
+ import { DaouyModulesFetcher } from '@daouy/loader-core';
14
+ import { daouyQuery } from '@daouy/query';
15
+ import { DaouyTranslatorContext } from '@daouy/host';
16
+ import { DataCtxReader } from '@daouy/host';
17
+ import { DataProvider } from '@daouy/host';
18
+ import { FontMeta } from '@daouy/loader-core';
19
+ import { getActiveVariation } from '@daouy/loader-splits';
20
+ import { getExternalIds } from '@daouy/loader-splits';
21
+ import { GlobalActionsContext } from '@daouy/host';
22
+ import { GlobalActionsProvider } from '@daouy/host';
23
+ import type { GlobalContextMeta as GlobalContextMeta_2 } from '@daouy/host';
24
+ import { GlobalGroupMeta } from '@daouy/loader-core';
25
+ import { LoaderBundleCache } from '@daouy/loader-core';
26
+ import { LoaderBundleOutput } from '@daouy/loader-fetcher';
27
+ import { LoaderBundleOutput as LoaderBundleOutput_2 } from '@daouy/loader-core';
28
+ import { PageMeta } from '@daouy/loader-core';
29
+ import { PageMetadata } from '@daouy/loader-core';
30
+ import { PageParamsProvider } from '@daouy/host';
31
+ import { PropType } from '@daouy/host';
32
+ import { react } from 'react';
33
+ import * as React_2 from 'react';
34
+ import { default as React_3 } from 'react';
35
+ import { reactDom } from 'react-dom';
36
+ import { reactJsxDevRuntime } from 'react/jsx-dev-runtime';
37
+ import { reactJsxRuntime } from 'react/jsx-runtime';
38
+ import { Registry } from '@daouy/loader-core';
39
+ import { repeatedElement } from '@daouy/host';
40
+ import { Split } from '@daouy/loader-fetcher';
41
+ import type { StateHelpers } from '@daouy/host';
42
+ import type { StateSpec } from '@daouy/host';
43
+ import { TokenRegistration } from '@daouy/host';
44
+ import { TrackRenderOptions } from '@daouy/loader-core';
45
+ import { TraitMeta } from '@daouy/host';
46
+ import { useDaouyCanvasComponentInfo } from '@daouy/host';
47
+ import { useDaouyCanvasContext } from '@daouy/host';
48
+ import { useDaouyQueryData } from '@daouy/query';
49
+ import { useDataEnv } from '@daouy/host';
50
+ import type { useMutableDaouyQueryData } from '@daouy/query';
51
+ import { useSelector } from '@daouy/host';
52
+ import { useSelectors } from '@daouy/host';
53
+
54
+ /** Subset of loader functionality that works on Client and React Server Components. */
55
+ declare abstract class BaseInternalDaouyComponentLoader {
56
+ readonly opts: InitOptions;
57
+ private readonly registry;
58
+ private readonly fetcher;
59
+ private readonly onBundleMerged?;
60
+ private readonly onBundleFetched?;
61
+ private globalVariants;
62
+ private subs;
63
+ private bundle;
64
+ constructor(args: {
65
+ opts: InitOptions;
66
+ fetcher: DaouyModulesFetcher;
67
+ /** Called after `mergeBundle` (including `fetch` calls). */
68
+ onBundleMerged?: () => void;
69
+ /** Called after any `fetch` calls. */
70
+ onBundleFetched?: () => void;
71
+ builtinModules: BuiltinRegisteredModules;
72
+ });
73
+ private maybeGetCompMetas;
74
+ maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
75
+ maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
76
+ fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
77
+ fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
78
+ fetchPages(opts?: FetchPagesOpts): Promise<PageMeta[]>;
79
+ fetchComponents(): Promise<ComponentMeta_2[]>;
80
+ getActiveSplits(): Split[];
81
+ getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]): string;
82
+ private fetchMissingData;
83
+ private maybeReportClientSideFetch;
84
+ private fetchAllData;
85
+ mergeBundle(newBundle: LoaderBundleOutput): void;
86
+ getBundle(): LoaderBundleOutput;
87
+ clearCache(): void;
88
+ registerModules(modules: Record<string, any>): void;
89
+ substituteComponent<P>(component: React.ComponentType<P>, name: ComponentLookupSpec): void;
90
+ protected internalSubstituteComponent<P>(component: React.ComponentType<P>, name: ComponentLookupSpec, codeComponentHelpers: ComponentHelpers<React.ComponentProps<React.ComponentType<P>>> | undefined): void;
91
+ abstract registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
92
+ abstract registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
93
+ abstract registerGlobalContext<T extends React.ComponentType<any>>(context: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
94
+ abstract registerTrait(trait: string, meta: TraitMeta): void;
95
+ abstract registerToken(token: TokenRegistration): void;
96
+ protected refreshRegistry(): void;
97
+ isRegistryEmpty(): boolean;
98
+ clearRegistry(): void;
99
+ setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
100
+ getGlobalVariants(): GlobalVariantSpec[];
101
+ registerPrefetchedBundle(bundle: LoaderBundleOutput): void;
102
+ getLookup(): ComponentLookup;
103
+ trackConversion(_value?: number): void;
104
+ getActiveVariation(opts: Omit<Parameters<typeof getActiveVariation>[0], "splits">): Promise<Record<string, string>>;
105
+ getTeamIds(): string[];
106
+ getProjectIds(): string[];
107
+ trackRender(_opts?: TrackRenderOptions): void;
108
+ loadServerQueriesModule(fileName: string): any;
109
+ }
110
+
111
+ declare interface BuiltinRegisteredModules {
112
+ react: react;
113
+ "react-dom": reactDom;
114
+ "react/jsx-runtime": reactJsxRuntime;
115
+ "react/jsx-dev-runtime": reactJsxDevRuntime;
116
+ "@daouy/query": daouyQuery;
117
+ "@daouy/data-sources-context": daouyDataSourcesContext;
118
+ "@daouy/host": daouyHost;
119
+ "@daouy/loader-runtime-registry": {
120
+ components: Record<string, React.ComponentType<any>>;
121
+ globalVariantHooks: Record<string, () => any>;
122
+ codeComponentHelpers: Record<string, ComponentHelpers<any>>;
123
+ functions: Record<string, (...args: any[]) => any>;
124
+ };
125
+ }
126
+
127
+ export declare type CodeComponentMeta<P> = Omit<CodeComponentMeta_2<P>, "importPath" | "componentHelpers" | "states"> & {
128
+ /**
129
+ * The path to be used when importing the component in the generated code.
130
+ * It can be the name of the package that contains the component, or the path
131
+ * to the file in the project (relative to the root directory).
132
+ * Optional: not used by Daouy headless API, only by codegen.
133
+ */
134
+ importPath?: string;
135
+ /**
136
+ * The states helpers are registered together with the states for the Daouy headless API
137
+ */
138
+ states?: Record<string, StateSpec<P> & StateHelpers<P, any>>;
139
+ /**
140
+ * Helper function to enable data extraction when running Daouy from
141
+ * Next.js App Router.
142
+ */
143
+ getServerInfo?: (props: P, ops: ReactServerOps) => ServerInfo;
144
+ };
145
+
146
+ declare class ComponentLookup {
147
+ private bundle;
148
+ private registry;
149
+ constructor(bundle: LoaderBundleOutput_2, registry: Registry);
150
+ getComponentMeta(spec: ComponentLookupSpec): ComponentMeta | undefined;
151
+ getComponent<P extends React_2.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
152
+ forceOriginal?: boolean;
153
+ }): any;
154
+ hasComponent(spec: ComponentLookupSpec): boolean;
155
+ getGlobalContexts(): {
156
+ meta: GlobalGroupMeta;
157
+ context: any;
158
+ }[];
159
+ /** Returns StyleTokensProvider if the project has style token overrides. */
160
+ maybeGetStyleTokensProvider(spec: ComponentLookupSpec, styleTokenOverridesProjectId?: string): any;
161
+ getGlobalContextsProvider(spec: ComponentLookupSpec): any;
162
+ getRootProvider(): any;
163
+ getCss(): AssetModule[];
164
+ getRemoteFonts(): FontMeta[];
165
+ }
166
+
167
+ export declare type ComponentLookupSpec = string | {
168
+ name: string;
169
+ projectId?: string;
170
+ isCode?: boolean;
171
+ };
172
+
173
+ export { ComponentMeta }
174
+
175
+ export declare interface ComponentRenderData {
176
+ entryCompMetas: (ComponentMeta_2 & {
177
+ params?: Record<string, string>;
178
+ })[];
179
+ bundle: LoaderBundleOutput;
180
+ remoteFontUrls: string[];
181
+ }
182
+
183
+ export declare const convertBundlesToComponentRenderData: (bundles: LoaderBundleOutput_2[], compMetas: ComponentMeta[]) => ComponentRenderData | null;
184
+
185
+ export declare type CustomFunctionMeta<F extends (...args: any[]) => any> = Omit<CustomFunctionMeta_2<F>, "importPath"> & {
186
+ /**
187
+ * The path to be used when importing the function in the generated code.
188
+ * It can be the name of the package that contains the function, or the path
189
+ * to the file in the project (relative to the root directory).
190
+ * Optional: not used by Daouy headless API, only by codegen.
191
+ */
192
+ importPath?: string;
193
+ };
194
+
195
+ export { DaouyCanvasContext }
196
+
197
+ export { DaouyCanvasHost }
198
+
199
+ export declare function DaouyComponent(props: {
200
+ /**
201
+ * Name of the component to render, or the path of the page component
202
+ */
203
+ component: string;
204
+ /**
205
+ * Optionally specify a projectId if there are multiple components
206
+ * of the same name from different projects
207
+ */
208
+ projectId?: string;
209
+ /**
210
+ * If you used registerComponent(), then if the name matches a registered
211
+ * component, that component is used. If you want the Daouy-generated
212
+ * component instead, specify forceOriginal.
213
+ */
214
+ forceOriginal?: boolean;
215
+ componentProps?: any;
216
+ }): React_2.ReactElement | null;
217
+
218
+ /**
219
+ * Library for fetching component data, and registering
220
+ * custom components.
221
+ */
222
+ export declare class DaouyComponentLoader {
223
+ private __internal;
224
+ constructor(internal: BaseInternalDaouyComponentLoader);
225
+ /**
226
+ * Sets global variants to be used for all components. Note that
227
+ * this is not reactive, and will not re-render all components
228
+ * already mounted; instead, it should be used to activate global
229
+ * variants that should always be activated for the lifetime of this
230
+ * app. If you'd like to reactively change the global variants,
231
+ * you should specify them via <DaouyRootProvider />
232
+ */
233
+ setGlobalVariants(globalVariants: GlobalVariantSpec[]): void;
234
+ registerModules(modules: Record<string, any>): void;
235
+ /**
236
+ * Register custom components that should be swapped in for
237
+ * components defined in your project. You can use this to
238
+ * swap in / substitute a Daouy component with a "real" component.
239
+ */
240
+ substituteComponent<P>(component: React.ComponentType<P>, name: ComponentLookupSpec): void;
241
+ /**
242
+ * Register code components to be used on Daouy Editor.
243
+ */
244
+ registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
245
+ /**
246
+ * [[deprecated]] Please use `substituteComponent` instead for component
247
+ * substitution, or the other `registerComponent` overload to register
248
+ * code components to be used on Daouy Editor.
249
+ *
250
+ * @see `substituteComponent`
251
+ */
252
+ registerComponent<T extends React.ComponentType<any>>(component: T, name: ComponentLookupSpec): void;
253
+ private warnedRegisterComponent;
254
+ registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
255
+ registerGlobalContext<T extends React.ComponentType<any>>(context: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
256
+ registerTrait(trait: string, meta: TraitMeta): void;
257
+ registerToken(token: TokenRegistration): void;
258
+ /**
259
+ * Pre-fetches component data needed to for DaouyLoader to render
260
+ * these components. Should be passed into DaouyRootProvider as
261
+ * the prefetchedData prop.
262
+ *
263
+ * You can look up a component either by:
264
+ * - the name of the component
265
+ * - the path for a page component
266
+ * - an array of strings that make up parts of the path
267
+ * - object { name: "name_or_path", projectId: ...}, to specify which project
268
+ * to use, if multiple projects have the same component name
269
+ *
270
+ * Throws an Error if a specified component to fetch does not exist in
271
+ * the Daouy project.
272
+ */
273
+ fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
274
+ fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
275
+ /**
276
+ * Like fetchComponentData(), but returns null instead of throwing an Error
277
+ * when a component is not found. Useful when you are implementing a catch-all
278
+ * page and want to check if a specific path had been defined for Daouy.
279
+ */
280
+ maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
281
+ maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
282
+ /**
283
+ * Returns all the page component metadata for these projects.
284
+ */
285
+ fetchPages(opts?: FetchPagesOpts): Promise<PageMeta[]>;
286
+ /**
287
+ * Returns all components metadata for these projects.
288
+ */
289
+ fetchComponents(): Promise<ComponentMeta_2[]>;
290
+ protected _getActiveVariation(opts: Parameters<typeof DaouyComponentLoader.__internal.getActiveVariation>[0]): Promise<Record<string, string>>;
291
+ getActiveVariation(opts: {
292
+ known?: Record<string, string>;
293
+ traits: Record<string, string | number | boolean>;
294
+ }): Promise<Record<string, string>>;
295
+ getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]): string;
296
+ getExternalVariation(variation: Record<string, string>, filters?: Parameters<typeof getExternalIds>[2]): Record<string, string>;
297
+ getActiveSplits(): Split[];
298
+ trackConversion(value?: number): void;
299
+ clearCache(): void;
300
+ getExecFuncModule(renderData: ComponentRenderData, fileNameKey: "serverQueriesExecFuncFileName" | "generateMetadataFuncFileName"): any;
301
+ unstable__getServerQueriesData(renderData: ComponentRenderData, $ctx: Record<string, any>): Promise<any>;
302
+ unstable__generateMetadata(renderData: ComponentRenderData, props: {
303
+ params: Promise<ParamsRecord> | ParamsRecord;
304
+ query: Promise<ParamsRecord> | ParamsRecord;
305
+ }): Promise<any>;
306
+ }
307
+
308
+ /**
309
+ * @deprecated Maintained for backwards compatibility
310
+ */
311
+ export declare function daouyPrepass(element: React.ReactElement): Promise<void>;
312
+
313
+ /**
314
+ * DaouyRootProvider should be used at the root of your page
315
+ * or application.
316
+ */
317
+ export declare function DaouyRootProvider(props: {
318
+ /**
319
+ * The global DaouyComponentLoader instance you created via
320
+ * initDaouyLoader().
321
+ */
322
+ loader: DaouyComponentLoader;
323
+ /**
324
+ * Global variants to activate for Daouy components
325
+ */
326
+ globalVariants?: GlobalVariantSpec[];
327
+ children?: React_2.ReactNode;
328
+ /**
329
+ * If true, will skip rendering css
330
+ */
331
+ skipCss?: boolean;
332
+ /**
333
+ * If true, will skip installing fonts
334
+ */
335
+ skipFonts?: boolean;
336
+ /**
337
+ * If you have pre-fetched component data via DaouyComponentLoader,
338
+ * you can pass them in here; DaouyComponent will avoid fetching
339
+ * component data that have already been pre-fetched.
340
+ */
341
+ prefetchedData?: ComponentRenderData;
342
+ /**
343
+ * If you have pre-fetched data that are needed by useDaouyQueryData(),
344
+ * then pass in the pre-fetched cache here, mapping query key to fetched data.
345
+ */
346
+ prefetchedQueryData?: Record<string, any>;
347
+ /**
348
+ * Specifies whether useDaouyQueryData() should be operating in suspense mode
349
+ * (throwing promises).
350
+ */
351
+ suspenseForQueryData?: boolean;
352
+ /**
353
+ * Override your Global Contexts Provider props. This is a map from
354
+ * globalContextComponentNameProps to object of props to use for that
355
+ * component.
356
+ */
357
+ globalContextsProps?: Record<string, any>;
358
+ /**
359
+ * Specifies a mapping of split id to slice id that should be activated
360
+ */
361
+ variation?: Record<string, string>;
362
+ /**
363
+ * Translator function to be used for text blocks
364
+ */
365
+ translator?: DaouyTranslator;
366
+ /**
367
+ * Head component to use in DaouyHead component (e.g. Head from next/head
368
+ * or Helmet from react-helmet).
369
+ */
370
+ Head?: React_2.ComponentType<any>;
371
+ /**
372
+ * Link component to use. Can be any component that takes in props passed
373
+ * to an <a/> tag.
374
+ */
375
+ Link?: React_2.ComponentType<any>;
376
+ /**
377
+ * Page route without params substitution (e.g. /products/[slug]).
378
+ */
379
+ pageRoute?: string;
380
+ /**
381
+ * Page path parameters (e.g. {slug: "foo"} if page path is
382
+ * /products/[slug] and URI is /products/foo).
383
+ */
384
+ pageParams?: Record<string, string | string[] | undefined>;
385
+ /**
386
+ * Page query parameters (e.g. {q: "foo"} if page path is
387
+ * /some/path?q=foo).
388
+ */
389
+ pageQuery?: Record<string, string | string[] | undefined>;
390
+ /**
391
+ * Whether the internal Daouy React.Suspense boundaries should be removed
392
+ */
393
+ disableLoadingBoundary?: boolean;
394
+ /**
395
+ * Whether the root React.Suspense boundary should be removed
396
+ */
397
+ disableRootLoadingBoundary?: boolean;
398
+ /**
399
+ * Fallback value for React.Suspense boundary
400
+ */
401
+ suspenseFallback?: React_2.ReactNode;
402
+ /**
403
+ * When Daouy loads components from multiple projects, we must choose a style token overrides to use that will apply to all components under the root DaouyComponent.
404
+ *
405
+ * If styleTokenOverridesProjectId is set, all DaouyComponents and their subtrees will use the specified project's style token overrides.
406
+ * If styleTokenOverridesProjectId it not set, each DaouyComponent and its subtree will use the style token overrides of the root DaouyComponent's project.
407
+ */
408
+ styleTokenOverridesProjectId?: string;
409
+ } & DaouyDataSourceContextValue): React_2.JSX.Element;
410
+
411
+ declare interface DaouyRootWatcher {
412
+ onDataFetched?: () => void;
413
+ }
414
+
415
+ export declare type DaouyTranslator = (str: string, opts?: {
416
+ components?: {
417
+ [key: string]: React_2.ReactElement | React_2.ReactFragment;
418
+ };
419
+ }) => React_2.ReactNode;
420
+
421
+ export { DaouyTranslatorContext }
422
+
423
+ export { DataCtxReader }
424
+
425
+ export { DataProvider }
426
+
427
+ /**
428
+ * Performs a prepass over Daouy content, kicking off the necessary
429
+ * data fetches, and populating the fetched data into a cache. This
430
+ * cache can be passed as prefetchedQueryData into DaouyRootProvider.
431
+ *
432
+ * To limit rendering errors that can occur when you do this, we recommend
433
+ * that you pass in _only_ the DaouyComponents that you are planning to use
434
+ * as the argument. For example:
435
+ *
436
+ * const cache = await extractDaouyQueryData(
437
+ * <DaouyRootProvider loader={DAOUY} prefetchedData={daouyData}>
438
+ * <DaouyComponent component="Home" componentProps={{
439
+ * // Specify the component prop overrides you are planning to use
440
+ * // to render the page, as they may change what data is fetched.
441
+ * ...
442
+ * }} />
443
+ * <DaouyComponent component="NavBar" componentProps={{
444
+ * ...
445
+ * }} />
446
+ * ...
447
+ * </DaouyRootProvider>
448
+ * );
449
+ *
450
+ * If your DaouyComponent will be wrapping components that require special
451
+ * context set up, you should also wrap the element above with those context
452
+ * providers.
453
+ *
454
+ * You should avoid passing in elements that are not related to Daouy, as any
455
+ * rendering errors from those elements during the prepass may result in data
456
+ * not being populated in the cache.
457
+ *
458
+ * @param element a React element containing instances of DaouyComponent.
459
+ * Will attempt to satisfy all data needs from useDaouyDataQuery()
460
+ * in this element tree.
461
+ * @returns an object mapping query key to fetched data
462
+ */
463
+ export declare function extractDaouyQueryData(element: React.ReactElement): Promise<Record<string, any>>;
464
+
465
+ export declare function extractDaouyQueryDataFromElement(loader: DaouyComponentLoader, lookup: ComponentLookupSpec, opts?: {
466
+ prefetchedData?: ComponentRenderData;
467
+ componentProps?: any;
468
+ globalVariants?: GlobalVariantSpec[];
469
+ prefetchedQueryData?: Record<string, any>;
470
+ }): Promise<Record<string, any>>;
471
+
472
+ export declare interface FetchComponentDataOpts {
473
+ /**
474
+ * Will fetch either code targeting SSR or browser hydration in the
475
+ * returned bundle.
476
+ *
477
+ * By default, the target is browser. That's okay, because even when
478
+ * doing SSR, as long as you are using the same instance of DaouyLoader
479
+ * that was used to fetch component data, it will still know how to get at
480
+ * the server code.
481
+ *
482
+ * But, if you are building your own SSR solution, where fetching and rendering
483
+ * are using different instances of DaouyLoader, then you'll want to make
484
+ * sure that when you fetch, you are fetching the right one to be used in the
485
+ * right environment for either SSR or browser hydration.
486
+ */
487
+ target?: "server" | "browser";
488
+ }
489
+
490
+ declare type FetchPagesOpts = {
491
+ /**
492
+ * Whether to include dynamic pages in fetchPages() output. A page is
493
+ * considered dynamic if its path contains some param between brackets,
494
+ * e.g. "[slug]".
495
+ */
496
+ includeDynamicPages?: boolean;
497
+ };
498
+
499
+ export { GlobalActionsContext }
500
+
501
+ export { GlobalActionsProvider }
502
+
503
+ export declare type GlobalContextMeta<P> = Omit<GlobalContextMeta_2<P>, "importPath"> & {
504
+ /**
505
+ * The path to be used when importing the component in the generated code.
506
+ * It can be the name of the package that contains the component, or the path
507
+ * to the file in the project (relative to the root directory).
508
+ * Optional: not used by Daouy headless API, only by codegen.
509
+ */
510
+ importPath?: string;
511
+ };
512
+
513
+ export declare interface GlobalVariantSpec {
514
+ name: string;
515
+ projectId?: string;
516
+ value: any;
517
+ }
518
+
519
+ export declare function hydrateFromElement(loader: DaouyComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
520
+ prefetchedData?: ComponentRenderData;
521
+ componentProps?: any;
522
+ globalVariants?: GlobalVariantSpec[];
523
+ prefetchedQueryData?: Record<string, any>;
524
+ }): Promise<void>;
525
+
526
+ export declare function initDaouyLoader(opts: InitOptions): DaouyComponentLoader;
527
+
528
+ export declare interface InitOptions {
529
+ projects: {
530
+ id: string;
531
+ token: string;
532
+ version?: string;
533
+ }[];
534
+ cache?: LoaderBundleCache;
535
+ platform?: "react" | "nextjs" | "gatsby";
536
+ platformOptions?: {
537
+ nextjs?: {
538
+ appDir: boolean;
539
+ };
540
+ };
541
+ preview?: boolean;
542
+ host?: string;
543
+ onClientSideFetch?: "warn" | "error";
544
+ i18n?: {
545
+ keyScheme: "content" | "hash" | "path";
546
+ tagPrefix?: string;
547
+ };
548
+ /**
549
+ * @deprecated use i18n.keyScheme instead
550
+ */
551
+ i18nKeyScheme?: "content" | "hash";
552
+ /**
553
+ * By default, fetchComponentData() and fetchPages() calls cached in memory
554
+ * with the DaouyComponentLoader instance. If alwaysFresh is true, then
555
+ * data is always freshly fetched over the network.
556
+ */
557
+ alwaysFresh?: boolean;
558
+ /**
559
+ * If true, generated code from the server won't include page metadata tags
560
+ */
561
+ skipHead?: boolean;
562
+ /**
563
+ * If true, uses browser / node's native fetch
564
+ */
565
+ nativeFetch?: boolean;
566
+ /**
567
+ * If true, will not redirect to the codegen server automatically, and will
568
+ * try to reuse the existing bundle in the cache.
569
+ */
570
+ manualRedirect?: boolean;
571
+ }
572
+
573
+ export declare class InternalDaouyComponentLoader extends BaseInternalDaouyComponentLoader {
574
+ private readonly roots;
575
+ constructor(opts: InitOptions);
576
+ registerComponent<T extends React_3.ComponentType<any>>(component: T, meta: CodeComponentMeta<React_3.ComponentProps<T>>): void;
577
+ registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
578
+ registerGlobalContext<T extends React_3.ComponentType<any>>(context: T, meta: GlobalContextMeta<React_3.ComponentProps<T>>): void;
579
+ registerTrait(trait: string, meta: TraitMeta): void;
580
+ registerToken(token: TokenRegistration): void;
581
+ subscribeDaouyRoot(watcher: DaouyRootWatcher): void;
582
+ unsubscribeDaouyRoot(watcher: DaouyRootWatcher): void;
583
+ refreshRegistry(): void;
584
+ }
585
+
586
+ /**
587
+ * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
588
+ * containing path params; otherwise, return false.
589
+ *
590
+ * For example,
591
+ * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
592
+ * "world"}}`
593
+ * - `matchesPagePath("/hello/[name]", "/")` -> `false`
594
+ * - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
595
+ * - `matchesPagePath("/hello/[[...catchall]]", "/hello/")` -> `{params: {catchall: []}}`
596
+ * - `matchesPagePath("/", "")` -> `{params: {}}`
597
+ */
598
+ export declare function matchesPagePath(pattern: string, path: string): false | {
599
+ params: Record<string, string | string[]>;
600
+ };
601
+
602
+ export { PageMeta }
603
+
604
+ export { PageMetadata }
605
+
606
+ export { PageParamsProvider }
607
+
608
+ declare type ParamsRecord = Record<string, string | string[] | undefined>;
609
+
610
+ export { PropType }
611
+
612
+ /**
613
+ * Helper functions to describe code component behaviors, in order to allow
614
+ * data extraction in RSC / Next.js App routing.
615
+ */
616
+ declare interface ReactServerOps {
617
+ readDataEnv: typeof useDataEnv;
618
+ readDataSelector: typeof useSelector;
619
+ readDataSelectors: typeof useSelectors;
620
+ /**
621
+ * The contexts are passed using a key instead of the context provider
622
+ * Notice it cannot access the default context value if none has been provided,
623
+ * since React server components cannot create contexts.
624
+ */
625
+ readContext: (contextKey: string) => any;
626
+ /**
627
+ * Allows data fetching from the code component and caching the result,
628
+ * which will be stored in the `queryCache` returned by
629
+ * `extractDaouyQueryData`.
630
+ */
631
+ fetchData: typeof useMutableDaouyQueryData;
632
+ }
633
+
634
+ export declare function renderToElement(loader: DaouyComponentLoader, target: HTMLElement, lookup: ComponentLookupSpec, opts?: {
635
+ prefetchedData?: ComponentRenderData;
636
+ componentProps?: any;
637
+ globalVariants?: GlobalVariantSpec[];
638
+ prefetchedQueryData?: Record<string, any>;
639
+ pageParams?: Record<string, any>;
640
+ pageQuery?: Record<string, any>;
641
+ }): Promise<void>;
642
+
643
+ export declare function renderToString(loader: DaouyComponentLoader, lookup: ComponentLookupSpec, opts?: {
644
+ prefetchedData?: ComponentRenderData;
645
+ componentProps?: any;
646
+ globalVariants?: GlobalVariantSpec[];
647
+ prefetchedQueryData?: Record<string, any>;
648
+ }): string;
649
+
650
+ export { repeatedElement }
651
+
652
+ /**
653
+ * Each child of a code component might receive separate `DataProvider` and
654
+ * Context values.
655
+ */
656
+ declare interface ServerChildData {
657
+ providedData?: ServerProvidedData | ServerProvidedData[];
658
+ providedContexts?: ServerProvidedContext | ServerProvidedContext[];
659
+ node: React.ReactNode;
660
+ }
661
+
662
+ declare interface ServerInfo {
663
+ /**
664
+ * Optional: Indicates the React Nodes created by the component and the
665
+ * respective contexts provided to them. If not specified, it will render the
666
+ * children passed to the component as props.
667
+ */
668
+ children?: ServerChildData | ServerChildData[];
669
+ providedData?: ServerProvidedData | ServerProvidedData[];
670
+ providedContexts?: ServerProvidedContext | ServerProvidedContext[];
671
+ }
672
+
673
+ /**
674
+ * Provides a new value for a given context key, similar to Context.Provider.
675
+ * The context itself is not available (RSC doesn't allow calling
676
+ * `createContext`) so each context will need to be represented as a unique
677
+ * "context key". Also it means the default context value is not available
678
+ * in case no value is passed (and reading that context will return `undefined`)
679
+ */
680
+ declare interface ServerProvidedContext {
681
+ /**
682
+ * Identifier to the context, required to read it later via
683
+ * `ReactServerOps.readContext()`.
684
+ */
685
+ contextKey: string;
686
+ /**
687
+ * Context value being provided (similar to `Context.Provider`).
688
+ */
689
+ value: any;
690
+ }
691
+
692
+ /**
693
+ * Represents data provided by a code component via `DataProvider`
694
+ */
695
+ declare interface ServerProvidedData {
696
+ name: string;
697
+ data: any;
698
+ }
699
+
700
+ export { TokenRegistration }
701
+
702
+ export { useDaouyCanvasComponentInfo }
703
+
704
+ export { useDaouyCanvasContext }
705
+
706
+ /**
707
+ * Hook that fetches and returns a React component for rendering the argument
708
+ * Daouy component. Returns undefined if the component data is still
709
+ * being fetched.
710
+ *
711
+ * @param opts.forceOriginal if you used DaouyComponentLoader.registerComponent,
712
+ * then normally useDaouyComponent will return the registered component.
713
+ * You can set forceOriginal to true if you want to return the Daouy-generated
714
+ * component instead.
715
+ */
716
+ export declare function useDaouyComponent<P extends React_2.ComponentType = any>(spec: ComponentLookupSpec, opts?: {
717
+ forceOriginal?: boolean;
718
+ }): P;
719
+
720
+ export { useDaouyQueryData }
721
+
722
+ export { useDataEnv }
723
+
724
+ export { useSelector }
725
+
726
+ export { useSelectors }
727
+
728
+ export { }