@coveo/headless-react 2.5.11-pre.b2d577dca0 → 2.5.11-pre.b407bdfc38
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/ssr/search-engine.js +0 -1
- package/dist/ssr/search-engine.js.map +1 -1
- package/dist/ssr-commerce/commerce-engine.js +0 -1
- package/dist/ssr-commerce/commerce-engine.js.map +1 -1
- package/dist/ssr-commerce-next/index.d.ts +5 -5
- package/dist/ssr-commerce-next/index.js +3 -3
- package/dist/ssr-commerce-next/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/ssr-commerce-next/commerce-engine.d.ts +0 -23
- package/dist/ssr-commerce-next/commerce-engine.js +0 -48
- package/dist/ssr-commerce-next/commerce-engine.js.map +0 -1
- package/dist/ssr-commerce-next/common.d.ts +0 -10
- package/dist/ssr-commerce-next/common.js +0 -60
- package/dist/ssr-commerce-next/common.js.map +0 -1
- package/dist/ssr-commerce-next/providers.d.ts +0 -20
- package/dist/ssr-commerce-next/providers.js +0 -31
- package/dist/ssr-commerce-next/providers.js.map +0 -1
- package/dist/ssr-commerce-next/types.d.ts +0 -25
- package/dist/ssr-commerce-next/types.js +0 -2
- package/dist/ssr-commerce-next/types.js.map +0 -1
|
@@ -3,7 +3,6 @@ import { defineSearchEngine as defineBaseSearchEngine, } from '@coveo/headless/s
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { singleton } from '../utils.js';
|
|
5
5
|
import { buildControllerHooks, buildEngineHook, buildHydratedStateProvider, buildStateProvider, buildStaticStateProvider, } from './common.js';
|
|
6
|
-
// TODO: remove hack: KIT-5009
|
|
7
6
|
// Wrapper to workaround the limitation that `createContext()` cannot be called directly during SSR in next.js
|
|
8
7
|
function createSingletonContext() {
|
|
9
8
|
return singleton(() => React.createContext(null));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-engine.js","sourceRoot":"","sources":["../../src/ssr/search-engine.tsx"],"names":[],"mappings":"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B,CAAC;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,6 @@ import { defineCommerceEngine as defineBaseCommerceEngine, SolutionType, } from
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { singleton } from '../utils.js';
|
|
5
5
|
import { buildControllerHooks, buildEngineHook, buildHydratedStateProvider, buildStateProvider, buildStaticStateProvider, } from './common.js';
|
|
6
|
-
// TODO: remove hack: KIT-5009
|
|
7
6
|
// Wrapper to workaround the limitation that `createContext()` cannot be called directly during SSR in next.js
|
|
8
7
|
function createSingletonContext() {
|
|
9
8
|
return singleton(() => React.createContext(null));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commerce-engine.js","sourceRoot":"","sources":["../../src/ssr-commerce/commerce-engine.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,IAAI,wBAAwB,EAChD,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,wEAAwE;AACxE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAuB,SAAS,EAAC,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAiBrB,
|
|
1
|
+
{"version":3,"file":"commerce-engine.js","sourceRoot":"","sources":["../../src/ssr-commerce/commerce-engine.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,IAAI,wBAAwB,EAChD,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,wEAAwE;AACxE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAuB,SAAS,EAAC,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAiBrB,8GAA8G;AAC9G,SAAS,sBAAsB;IAI7B,OAAO,SAAS,CAAC,GA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U,CACxB;SACF;QACD,8BAA8B,EAAE;YAC9B,GAAG,8BAA8B;YACjC,mBAAmB,EAAE,wBAAwB,CAC3C,gBAAyC,EACzC,YAAY,CAAC,cAAc,CAC5B;YACD,qBAAqB,EAAE,0BAA0B,CAC/C,gBAAyC,EACzC,YAAY,CAAC,cAAc,CAC5B;YACD,aAAa,EAAE,kBAAkB,CAC/B,gBAAyC,EACzC,YAAY,CAAC,cAAc,CAC5B;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from '@coveo/headless/ssr-commerce
|
|
1
|
+
export * from '@coveo/headless/ssr-commerce';
|
|
2
2
|
export { MissingEngineProviderError } from '../errors.js';
|
|
3
|
-
export type { ReactCommerceEngineDefinition } from '
|
|
4
|
-
export { defineCommerceEngine } from '
|
|
5
|
-
export { buildProviderWithDefinition } from '
|
|
6
|
-
export { ReactEngineDefinition } from '
|
|
3
|
+
export type { ReactCommerceEngineDefinition } from '../ssr-commerce/commerce-engine.js';
|
|
4
|
+
export { defineCommerceEngine } from '../ssr-commerce/commerce-engine.js';
|
|
5
|
+
export { buildProviderWithDefinition } from '../ssr-commerce/providers.js';
|
|
6
|
+
export { ReactEngineDefinition } from '../ssr-commerce/types.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from '@coveo/headless/ssr-commerce
|
|
1
|
+
export * from '@coveo/headless/ssr-commerce';
|
|
2
2
|
export { MissingEngineProviderError } from '../errors.js';
|
|
3
|
-
export { defineCommerceEngine } from '
|
|
4
|
-
export { buildProviderWithDefinition } from '
|
|
3
|
+
export { defineCommerceEngine } from '../ssr-commerce/commerce-engine.js';
|
|
4
|
+
export { buildProviderWithDefinition } from '../ssr-commerce/providers.js';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAC,0BAA0B,EAAC,MAAM,cAAc,CAAC;AAExD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,2BAA2B,EAAC,MAAM,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coveo/headless-react",
|
|
3
|
-
"version": "2.5.11-pre.
|
|
3
|
+
"version": "2.5.11-pre.b407bdfc38",
|
|
4
4
|
"description": "React utilities for SSR (Server Side Rendering) with headless",
|
|
5
5
|
"homepage": "https://docs.coveo.com/en/headless/latest/",
|
|
6
6
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"serve:typedoc": "live-server ./docs"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@coveo/headless": "3.30.3-pre.
|
|
44
|
+
"@coveo/headless": "3.30.3-pre.b407bdfc38"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@testing-library/react": "16.3.0",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type AugmentedControllerDefinition, type CommerceEngine, type CommerceEngineDefinitionOptions, type Controller, type ControllerDefinitionsMap, SolutionType } from '@coveo/headless/ssr-commerce-next';
|
|
2
|
-
import type { InferControllerHooksMapFromDefinition, ReactEngineDefinition } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* A React engine definition that includes context providers for static and hydrated states.
|
|
5
|
-
*
|
|
6
|
-
* @group Engine
|
|
7
|
-
* */
|
|
8
|
-
export type ReactCommerceEngineDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = ReactEngineDefinition<TControllers, TSolutionType>;
|
|
9
|
-
/**
|
|
10
|
-
* Returns engine and controller hooks, and context providers.
|
|
11
|
-
*
|
|
12
|
-
* See [Define the commerce engine and controllers](https://docs.coveo.com/en/obif0156#define-the-commerce-engine-and-controllers).
|
|
13
|
-
*
|
|
14
|
-
* @group Engine
|
|
15
|
-
*/
|
|
16
|
-
export declare function defineCommerceEngine<TControllers extends ControllerDefinitionsMap<Controller>>(options: CommerceEngineDefinitionOptions<TControllers>): {
|
|
17
|
-
useEngine: () => CommerceEngine | undefined;
|
|
18
|
-
controllers: InferControllerHooksMapFromDefinition<AugmentedControllerDefinition<TControllers>>;
|
|
19
|
-
listingEngineDefinition: ReactCommerceEngineDefinition<TControllers, SolutionType.listing>;
|
|
20
|
-
searchEngineDefinition: ReactCommerceEngineDefinition<TControllers, SolutionType.search>;
|
|
21
|
-
standaloneEngineDefinition: ReactCommerceEngineDefinition<TControllers, SolutionType.standalone>;
|
|
22
|
-
recommendationEngineDefinition: ReactCommerceEngineDefinition<TControllers, SolutionType.recommendation>;
|
|
23
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { defineCommerceEngine as defineBaseCommerceEngine, defineCart, defineContext, defineParameterManager, SolutionType, } from '@coveo/headless/ssr-commerce-next';
|
|
2
|
-
// Workaround to prevent Next.js erroring about importing CSR only hooks
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { singleton } from '../utils.js';
|
|
5
|
-
import { buildControllerHooks, buildEngineHook, buildStateProvider, } from './common.js';
|
|
6
|
-
// TODO: remove hack: KIT-5009
|
|
7
|
-
// Wrapper to workaround the limitation that `createContext()` cannot be called directly during SSR in next.js
|
|
8
|
-
function createSingletonContext() {
|
|
9
|
-
return singleton(() => React.createContext(null));
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns engine and controller hooks, and context providers.
|
|
13
|
-
*
|
|
14
|
-
* See [Define the commerce engine and controllers](https://docs.coveo.com/en/obif0156#define-the-commerce-engine-and-controllers).
|
|
15
|
-
*
|
|
16
|
-
* @group Engine
|
|
17
|
-
*/
|
|
18
|
-
export function defineCommerceEngine(options) {
|
|
19
|
-
const singletonContext = createSingletonContext();
|
|
20
|
-
const { listingEngineDefinition, searchEngineDefinition, standaloneEngineDefinition, recommendationEngineDefinition, } = defineBaseCommerceEngine({ ...options });
|
|
21
|
-
const augmentedControllerDefinition = {
|
|
22
|
-
...options.controllers,
|
|
23
|
-
parameterManager: defineParameterManager(),
|
|
24
|
-
context: defineContext(),
|
|
25
|
-
cart: defineCart(),
|
|
26
|
-
};
|
|
27
|
-
return {
|
|
28
|
-
useEngine: buildEngineHook(singletonContext),
|
|
29
|
-
controllers: buildControllerHooks(singletonContext, augmentedControllerDefinition),
|
|
30
|
-
listingEngineDefinition: {
|
|
31
|
-
...listingEngineDefinition,
|
|
32
|
-
StateProvider: buildStateProvider(singletonContext, SolutionType.listing),
|
|
33
|
-
},
|
|
34
|
-
searchEngineDefinition: {
|
|
35
|
-
...searchEngineDefinition,
|
|
36
|
-
StateProvider: buildStateProvider(singletonContext, SolutionType.search),
|
|
37
|
-
},
|
|
38
|
-
standaloneEngineDefinition: {
|
|
39
|
-
...standaloneEngineDefinition,
|
|
40
|
-
StateProvider: buildStateProvider(singletonContext, SolutionType.standalone),
|
|
41
|
-
},
|
|
42
|
-
recommendationEngineDefinition: {
|
|
43
|
-
...recommendationEngineDefinition,
|
|
44
|
-
StateProvider: buildStateProvider(singletonContext, SolutionType.recommendation),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=commerce-engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commerce-engine.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/commerce-engine.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,IAAI,wBAAwB,EAChD,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,YAAY,GACb,MAAM,mCAAmC,CAAC;AAC3C,wEAAwE;AACxE,OAAO,KAAK,MAAM,OAAO,CAAC;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BAAkB,CAC/B,gBAAyC,EACzC,YAAY,CAAC,cAAc,CAC5B;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Controller, type ControllerDefinitionsMap, type InferControllerStaticStateMapFromDefinitionsWithSolutionType, type InferControllersMapFromDefinition, SolutionType, type CommerceEngine as SSRCommerceEngine } from '@coveo/headless/ssr-commerce-next';
|
|
2
|
-
import { type Context, type PropsWithChildren } from 'react';
|
|
3
|
-
import { type SingletonGetter } from '../utils.js';
|
|
4
|
-
import type { ContextState, InferControllerHooksMapFromDefinition } from './types.js';
|
|
5
|
-
export declare function buildControllerHooks<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>(singletonContext: SingletonGetter<Context<ContextState<TControllers, TSolutionType> | null>>, controllersMap?: TControllers): InferControllerHooksMapFromDefinition<TControllers>;
|
|
6
|
-
export declare function buildEngineHook<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>(singletonContext: SingletonGetter<Context<ContextState<TControllers, TSolutionType> | null>>): () => SSRCommerceEngine | undefined;
|
|
7
|
-
export declare function buildStateProvider<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>(singletonContext: SingletonGetter<Context<ContextState<TControllers, TSolutionType> | null>>, solutionType: TSolutionType): ({ engine, controllers, children, }: PropsWithChildren<{
|
|
8
|
-
engine?: SSRCommerceEngine;
|
|
9
|
-
controllers: InferControllersMapFromDefinition<TControllers, TSolutionType> | InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>;
|
|
10
|
-
}>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { SolutionType, } from '@coveo/headless/ssr-commerce-next';
|
|
3
|
-
import { useCallback, useContext, useMemo, } from 'react';
|
|
4
|
-
import { useSyncMemoizedStore } from '../client-utils.js';
|
|
5
|
-
import { MissingEngineProviderError, UndefinedControllerError, } from '../errors.js';
|
|
6
|
-
import { capitalize, mapObject } from '../utils.js';
|
|
7
|
-
function isHydratedStateContext(ctx) {
|
|
8
|
-
return 'engine' in ctx && !!ctx.engine;
|
|
9
|
-
}
|
|
10
|
-
function buildControllerHook(singletonContext, key, controllerDefinition) {
|
|
11
|
-
return () => {
|
|
12
|
-
const ctx = useContext(singletonContext.get());
|
|
13
|
-
if (ctx === null) {
|
|
14
|
-
throw new MissingEngineProviderError();
|
|
15
|
-
}
|
|
16
|
-
const allSolutionTypes = Object.values(SolutionType);
|
|
17
|
-
const supportedSolutionTypes = allSolutionTypes.filter((solutionType) => controllerDefinition[solutionType] === true);
|
|
18
|
-
if (ctx.controllers[key] === undefined) {
|
|
19
|
-
throw new UndefinedControllerError(key.toString(), supportedSolutionTypes);
|
|
20
|
-
}
|
|
21
|
-
const subscribe = useCallback((listener) => isHydratedStateContext(ctx)
|
|
22
|
-
? ctx.controllers[key].subscribe(listener)
|
|
23
|
-
: () => { }, [ctx, key]);
|
|
24
|
-
const getStaticState = useCallback(() => ctx.controllers[key].state, [ctx, key]);
|
|
25
|
-
const state = useSyncMemoizedStore(subscribe, getStaticState);
|
|
26
|
-
const methods = useMemo(() => {
|
|
27
|
-
if (!isHydratedStateContext(ctx)) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const controller = ctx.controllers[key];
|
|
31
|
-
const { state: _, subscribe: __, ...remainder } = controller;
|
|
32
|
-
return mapObject(remainder, (member) => typeof member === 'function' ? member.bind(controller) : member);
|
|
33
|
-
}, [ctx, key]);
|
|
34
|
-
return { state, methods };
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function buildControllerHooks(singletonContext, controllersMap) {
|
|
38
|
-
return (controllersMap
|
|
39
|
-
? Object.fromEntries(Object.entries(controllersMap).map(([key, controllerDefinition]) => [
|
|
40
|
-
`use${capitalize(key)}`,
|
|
41
|
-
buildControllerHook(singletonContext, key, controllerDefinition),
|
|
42
|
-
]))
|
|
43
|
-
: {});
|
|
44
|
-
}
|
|
45
|
-
export function buildEngineHook(singletonContext) {
|
|
46
|
-
return () => {
|
|
47
|
-
const ctx = useContext(singletonContext.get());
|
|
48
|
-
if (ctx === null) {
|
|
49
|
-
throw new MissingEngineProviderError();
|
|
50
|
-
}
|
|
51
|
-
return isHydratedStateContext(ctx) ? ctx.engine : undefined;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export function buildStateProvider(singletonContext, solutionType) {
|
|
55
|
-
return ({ engine, controllers, children, }) => {
|
|
56
|
-
const { Provider } = singletonContext.get();
|
|
57
|
-
return (_jsx(Provider, { value: { engine, controllers, solutionType }, children: children }));
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=common.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/common.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,YAAY,GAEb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAGL,WAAW,EACX,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,UAAU,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAC;AAQxE,SAAS,sBAAsB,CAI7B,GAA8C;IAE9C,OAAO,QAAQ,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;AACzC,CAAC;AAED,SAAS,mBAAmB,CAK1B,gBAEC,EACD,GAAS,EACT,oBAAsD;IAEtD,OAAO,GAAG,EAAE;QACV,MAAM,GAAG,GAAG,UAAU,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/C,IAAI,GAAG,KAAK,IAAI,EAAE,CAA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AgB,CAAC,GAAG,EAAE,CAAC;QAC1C,OAAO,CACL,KAAC,QAAQ,IAAC,KAAK,EAAE,EAAC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAC,YACjD,QAAQ,GACA,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Controller, ControllerDefinitionsMap, EngineStaticState, InferControllerStaticStateMapFromDefinitionsWithSolutionType, NavigatorContext, SolutionType } from '@coveo/headless/ssr-commerce-next';
|
|
2
|
-
import { type PropsWithChildren } from 'react';
|
|
3
|
-
import type { ReactCommerceEngineDefinition } from './commerce-engine.js';
|
|
4
|
-
type UnknownAction = {
|
|
5
|
-
type: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Providers take care of displaying your page with the static
|
|
9
|
-
* state, and then hydrating the state and displaying the page
|
|
10
|
-
* with the hydrated state. They are required for your controller hooks to function.
|
|
11
|
-
*
|
|
12
|
-
* See [Create providers](https://docs.coveo.com/en/obif0156/#create-providers).
|
|
13
|
-
*
|
|
14
|
-
* @group Providers
|
|
15
|
-
*/
|
|
16
|
-
export declare function buildProviderWithDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>(definition: ReactCommerceEngineDefinition<TControllers, TSolutionType>): ({ staticState, navigatorContext, children, }: PropsWithChildren<{
|
|
17
|
-
staticState: EngineStaticState<UnknownAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>>;
|
|
18
|
-
navigatorContext: NavigatorContext;
|
|
19
|
-
}>) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* Providers take care of displaying your page with the static
|
|
6
|
-
* state, and then hydrating the state and displaying the page
|
|
7
|
-
* with the hydrated state. They are required for your controller hooks to function.
|
|
8
|
-
*
|
|
9
|
-
* See [Create providers](https://docs.coveo.com/en/obif0156/#create-providers).
|
|
10
|
-
*
|
|
11
|
-
* @group Providers
|
|
12
|
-
*/
|
|
13
|
-
export function buildProviderWithDefinition(definition) {
|
|
14
|
-
return function WrappedProvider({ staticState, navigatorContext, children, }) {
|
|
15
|
-
const [hydratedState, setHydratedState] = useState(undefined);
|
|
16
|
-
definition.setNavigatorContextProvider(() => navigatorContext);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
definition
|
|
19
|
-
// @ts-expect-error: TODO: KIT-4754: get rid of the OptionTuple type
|
|
20
|
-
.hydrateStaticState(staticState)
|
|
21
|
-
.then(({ engine, controllers }) => {
|
|
22
|
-
setHydratedState({
|
|
23
|
-
engine,
|
|
24
|
-
controllers,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}, [staticState, definition]);
|
|
28
|
-
return (_jsx(definition.StateProvider, { engine: hydratedState?.engine, controllers: hydratedState?.controllers || staticState.controllers, children: children }));
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=providers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/providers.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAWb,OAAO,EAAyB,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAKlE;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CAGzC,UAAsE;IACtE,OAAO,SAAS,eAAe,CAAC,EAC9B,WAAW,EACX,gBAAgB,EAChB,QAAQ,GAWR;QACA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAEhD,SAAS,CAAC,CAAC;QACb,UAAU,CAAC,2BAA2B,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,CAAC;QAE/D,SAAS,CAAC,GAAG,EAAE;YACb,UAAU;gBACR,oEAAoE;iBACnE,kBAAkB,CAAC,WAAW,CAAC;iBAC/B,IAAI,CAAC,CAAC,EAAC,MAAM,EAAE,WAAW,EAAC,EAAE,EAAE;gBAC9B,gBAAgB,CAAC;oBACf,MAAM;oBACN,WAAW;iBACZ,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAE9B,OAAO,CACL,KAAC,UAAU,CAAC,aAAa,IACvB,MAAM,EAAE,aAAa,EAAE,MAAM,EAC7B,WAAW,EAAE,aAAa,EAAE,WAAW,IAAI,WAAW,CAAC,WAAW,YAEjE,QAAQ,GACgB,CAC5B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { CommerceEngineDefinition, Controller, ControllerDefinitionsMap, InferControllerFromDefinition, InferControllerStaticStateMapFromDefinitionsWithSolutionType, InferControllersMapFromDefinition, SolutionType, CommerceEngine as SSRCommerceEngine } from '@coveo/headless/ssr-commerce-next';
|
|
2
|
-
import type { FunctionComponent, PropsWithChildren } from 'react';
|
|
3
|
-
export type ContextHydratedState<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
4
|
-
engine: SSRCommerceEngine;
|
|
5
|
-
controllers: InferControllersMapFromDefinition<TControllers, TSolutionType>;
|
|
6
|
-
solutionType: TSolutionType;
|
|
7
|
-
};
|
|
8
|
-
export type ContextState<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
9
|
-
engine?: SSRCommerceEngine;
|
|
10
|
-
controllers: InferControllersMapFromDefinition<TControllers, TSolutionType> | InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>;
|
|
11
|
-
solutionType: TSolutionType;
|
|
12
|
-
};
|
|
13
|
-
export type ControllerHook<TController extends Controller> = () => {
|
|
14
|
-
state: TController['state'];
|
|
15
|
-
methods?: Omit<TController, 'state' | 'subscribe'>;
|
|
16
|
-
};
|
|
17
|
-
export type InferControllerHooksMapFromDefinition<TControllers extends ControllerDefinitionsMap<Controller>> = {
|
|
18
|
-
[K in keyof TControllers as `use${Capitalize<K extends string ? K : never>}`]: ControllerHook<InferControllerFromDefinition<TControllers[K]>>;
|
|
19
|
-
};
|
|
20
|
-
export type ReactEngineDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = CommerceEngineDefinition<TControllers, TSolutionType> & {
|
|
21
|
-
StateProvider: FunctionComponent<PropsWithChildren<{
|
|
22
|
-
engine?: SSRCommerceEngine;
|
|
23
|
-
controllers: InferControllersMapFromDefinition<TControllers, TSolutionType> | InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>;
|
|
24
|
-
}>>;
|
|
25
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ssr-commerce-next/types.ts"],"names":[],"mappings":""}
|