@wovvmap/sdk-react-core 0.0.0-stage → 1.2.0
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/MallRequestManager.d.ts +34 -0
- package/dist/MallRequestManager.d.ts.map +1 -0
- package/dist/MallRequestManager.js +75 -0
- package/dist/WovvMapContext.d.ts +15 -0
- package/dist/WovvMapContext.d.ts.map +1 -0
- package/dist/WovvMapContext.js +34 -0
- package/dist/hooks.d.ts +8 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/useCatalogSearch.d.ts +123 -0
- package/dist/useCatalogSearch.d.ts.map +1 -0
- package/dist/useCatalogSearch.js +144 -0
- package/dist/useMallRequest.d.ts +14 -0
- package/dist/useMallRequest.d.ts.map +1 -0
- package/dist/useMallRequest.js +27 -0
- package/dist/viewerLink.d.ts +16 -0
- package/dist/viewerLink.d.ts.map +1 -0
- package/dist/viewerLink.js +39 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MallApiRequestOptions, MallController, MallApiVersion } from '@wovvmap/map-data';
|
|
2
|
+
export interface MallRequestConfig {
|
|
3
|
+
controller: MallController;
|
|
4
|
+
apiVersion?: MallApiVersion;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
environment?: string;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
autoFetch?: boolean;
|
|
9
|
+
mallId?: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface MallRequestState<T> {
|
|
12
|
+
data: T;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** Owns request cancellation and stale-result protection; no map-domain state is stored here.
|
|
17
|
+
* Hinglish: Sirf API request ka lifecycle hai; viewer/floor ka doosra store nahi banta. */
|
|
18
|
+
export declare class MallRequestManager<T> {
|
|
19
|
+
private readonly empty;
|
|
20
|
+
private readonly fetch;
|
|
21
|
+
private readonly canFetch;
|
|
22
|
+
private state;
|
|
23
|
+
private config;
|
|
24
|
+
private abort?;
|
|
25
|
+
private listeners;
|
|
26
|
+
constructor(config: MallRequestConfig, empty: T, fetch: (config: MallRequestConfig, options: MallApiRequestOptions) => Promise<T>, canFetch: (config: MallRequestConfig) => boolean);
|
|
27
|
+
getSnapshot: () => MallRequestState<T>;
|
|
28
|
+
subscribe: (listener: () => void) => (() => void);
|
|
29
|
+
private update;
|
|
30
|
+
configure(config: MallRequestConfig): void;
|
|
31
|
+
refresh: () => Promise<void>;
|
|
32
|
+
stop: () => void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=MallRequestManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MallRequestManager.d.ts","sourceRoot":"","sources":["../src/MallRequestManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE9F,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,cAAc,CAAA;IAC1B,UAAU,CAAC,EAAE,cAAc,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AACD,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAED;2FAC2F;AAC3F,qBAAa,kBAAkB,CAAC,CAAC;IAO7B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAItB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAX3B,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,KAAK,CAAC,CAAiB;IAC/B,OAAO,CAAC,SAAS,CAAwB;gBAEvC,MAAM,EAAE,iBAAiB,EACR,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,CACtB,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,CAAC,CAAC,EACE,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO;IASnE,WAAW,QAAO,gBAAgB,CAAC,CAAC,CAAC,CAAc;IACnD,SAAS,GAAI,UAAU,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CAG/C;IACD,OAAO,CAAC,MAAM;IAUd,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAM1C,OAAO,QAAa,OAAO,CAAC,IAAI,CAAC,CA0BhC;IACD,IAAI,QAAO,IAAI,CAEd;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Owns request cancellation and stale-result protection; no map-domain state is stored here.
|
|
2
|
+
* Hinglish: Sirf API request ka lifecycle hai; viewer/floor ka doosra store nahi banta. */
|
|
3
|
+
export class MallRequestManager {
|
|
4
|
+
empty;
|
|
5
|
+
fetch;
|
|
6
|
+
canFetch;
|
|
7
|
+
state;
|
|
8
|
+
config;
|
|
9
|
+
abort;
|
|
10
|
+
listeners = new Set();
|
|
11
|
+
constructor(config, empty, fetch, canFetch) {
|
|
12
|
+
this.empty = empty;
|
|
13
|
+
this.fetch = fetch;
|
|
14
|
+
this.canFetch = canFetch;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.state = {
|
|
17
|
+
data: empty,
|
|
18
|
+
loading: canFetch(config) && config.autoFetch !== false,
|
|
19
|
+
error: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getSnapshot = () => this.state;
|
|
23
|
+
subscribe = (listener) => {
|
|
24
|
+
this.listeners.add(listener);
|
|
25
|
+
return () => this.listeners.delete(listener);
|
|
26
|
+
};
|
|
27
|
+
update(patch) {
|
|
28
|
+
if (Object.entries(patch).every(([key, value]) => Object.is(this.state[key], value)))
|
|
29
|
+
return;
|
|
30
|
+
this.state = { ...this.state, ...patch };
|
|
31
|
+
for (const listener of this.listeners)
|
|
32
|
+
listener();
|
|
33
|
+
}
|
|
34
|
+
configure(config) {
|
|
35
|
+
this.config = config;
|
|
36
|
+
if (!this.canFetch(config))
|
|
37
|
+
this.update({ data: this.empty, loading: false, error: null });
|
|
38
|
+
else if (config.autoFetch !== false)
|
|
39
|
+
void this.refresh();
|
|
40
|
+
else
|
|
41
|
+
this.update({ loading: false });
|
|
42
|
+
}
|
|
43
|
+
refresh = async () => {
|
|
44
|
+
this.stop();
|
|
45
|
+
const config = this.config;
|
|
46
|
+
if (!this.canFetch(config)) {
|
|
47
|
+
this.update({ data: this.empty, loading: false, error: null });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const abort = new AbortController();
|
|
51
|
+
this.abort = abort;
|
|
52
|
+
this.update({ loading: true, error: null });
|
|
53
|
+
try {
|
|
54
|
+
const data = await this.fetch(config, {
|
|
55
|
+
version: config.apiVersion,
|
|
56
|
+
baseUrl: config.baseUrl,
|
|
57
|
+
endpoint: config.endpoint,
|
|
58
|
+
environment: config.environment,
|
|
59
|
+
signal: abort.signal,
|
|
60
|
+
});
|
|
61
|
+
if (!abort.signal.aborted)
|
|
62
|
+
this.update({ data, loading: false });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!abort.signal.aborted)
|
|
66
|
+
this.update({
|
|
67
|
+
error: error instanceof Error ? error.message : String(error),
|
|
68
|
+
loading: false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
stop = () => {
|
|
73
|
+
this.abort?.abort();
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode, type JSX } from 'react';
|
|
2
|
+
import { MallController, type MallControllerInit } from '@wovvmap/map-data';
|
|
3
|
+
/** Shared data provider; contains no DOM, Three.js or WebView dependency.
|
|
4
|
+
* Hinglish: Web aur Native ke data hooks ek hi provider use karte hain. */
|
|
5
|
+
export interface WovvMapContextValue {
|
|
6
|
+
controller: MallController | null;
|
|
7
|
+
}
|
|
8
|
+
export interface WovvMapProviderProps {
|
|
9
|
+
controller?: MallController;
|
|
10
|
+
options?: MallControllerInit;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function WovvMapProvider({ controller, options, children, }: WovvMapProviderProps): JSX.Element;
|
|
14
|
+
export declare function useWovvMapContext(): WovvMapContextValue;
|
|
15
|
+
//# sourceMappingURL=WovvMapContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WovvMapContext.d.ts","sourceRoot":"","sources":["../src/WovvMapContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AACnF,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3E;2EAC2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAA;CAClC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,cAAc,CAAA;IAC3B,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,QAAQ,EAAE,SAAS,CAAA;CACpB;AA4BD,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAQpC;AACD,wBAAgB,iBAAiB,IAAI,mBAAmB,CAEvD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useRef } from 'react';
|
|
3
|
+
import { MallController } from '@wovvmap/map-data';
|
|
4
|
+
const Context = createContext({ controller: null });
|
|
5
|
+
/** Stabilize equivalent option objects without serializing custom adapters/cache instances.
|
|
6
|
+
* Hinglish: Same config ke naye object se controller ya requests dobara nahi bante. */
|
|
7
|
+
class ProviderController {
|
|
8
|
+
options;
|
|
9
|
+
explicit;
|
|
10
|
+
value = { controller: null };
|
|
11
|
+
resolve(controller, options) {
|
|
12
|
+
const sameOptions = options === this.options ||
|
|
13
|
+
(options &&
|
|
14
|
+
this.options &&
|
|
15
|
+
Object.getPrototypeOf(options) === Object.prototype &&
|
|
16
|
+
Object.getPrototypeOf(this.options) === Object.prototype &&
|
|
17
|
+
Object.keys(options).length === Object.keys(this.options).length &&
|
|
18
|
+
Object.entries(options).every(([key, value]) => Object.is(value, this.options[key])));
|
|
19
|
+
if (this.explicit !== controller || (!controller && !sameOptions)) {
|
|
20
|
+
this.explicit = controller;
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.value = { controller: controller ?? (options ? new MallController(options) : null) };
|
|
23
|
+
}
|
|
24
|
+
return this.value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function WovvMapProvider({ controller, options, children, }) {
|
|
28
|
+
const resolver = useRef(null);
|
|
29
|
+
resolver.current ??= new ProviderController();
|
|
30
|
+
return (_jsx(Context.Provider, { value: resolver.current.resolve(controller, options), children: children }));
|
|
31
|
+
}
|
|
32
|
+
export function useWovvMapContext() {
|
|
33
|
+
return useContext(Context);
|
|
34
|
+
}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UseMallDataOptions, UseMallDataResult, UseMallListOptions, UseMallListResult } from './types.js';
|
|
2
|
+
/** Same data hook on Web and Native; API parsing/cache stay in map-data.
|
|
3
|
+
* Hinglish: Dono SDK ka hook same hai; parsing/cache map-data ki zimmedari hai. */
|
|
4
|
+
export declare function useMallData(mallId: string | null | undefined, options?: UseMallDataOptions): UseMallDataResult;
|
|
5
|
+
/** Shared catalog hook; consumes the same provider and request lifecycle.
|
|
6
|
+
* Hinglish: Catalog bhi wahi provider aur request lifecycle use karta hai. */
|
|
7
|
+
export declare function useMallList(options?: UseMallListOptions): UseMallListResult;
|
|
8
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAMhB;mFACmF;AACnF,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,OAAO,GAAE,kBAAuB,GAC/B,iBAAiB,CASnB;AACD;8EAC8E;AAC9E,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,iBAAiB,CAS/E"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMallRequest } from './useMallRequest.js';
|
|
2
|
+
const hasMall = (config) => Boolean(config.mallId);
|
|
3
|
+
const always = () => true;
|
|
4
|
+
const emptyList = [];
|
|
5
|
+
/** Same data hook on Web and Native; API parsing/cache stay in map-data.
|
|
6
|
+
* Hinglish: Dono SDK ka hook same hai; parsing/cache map-data ki zimmedari hai. */
|
|
7
|
+
export function useMallData(mallId, options = {}) {
|
|
8
|
+
const { data, ...state } = useMallRequest(options, mallId, null, (config, request) => config.controller.getMallMapData(config.mallId, request), hasMall);
|
|
9
|
+
return { ...state, mapData: data };
|
|
10
|
+
}
|
|
11
|
+
/** Shared catalog hook; consumes the same provider and request lifecycle.
|
|
12
|
+
* Hinglish: Catalog bhi wahi provider aur request lifecycle use karta hai. */
|
|
13
|
+
export function useMallList(options = {}) {
|
|
14
|
+
const { data, ...state } = useMallRequest(options, undefined, emptyList, async (config, request) => (await config.controller.getActiveMalls(request)).data, always);
|
|
15
|
+
return { ...state, mallsList: data };
|
|
16
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { useMallData, useMallList } from './hooks.js';
|
|
2
|
+
export { createUseCatalogSearchHook, type CatalogDiscoveryChannel, type DiscoveryChannelPort, type DiscoveryChannelSnapshot, type DiscoveryQueryParams, type DiscoveryQueryStatus, type UseCatalogSearchOptions, type UseCatalogSearchResult, type ViewerDiscoveryPort, type ViewerDiscoveryStoreSlice, } from './useCatalogSearch.js';
|
|
3
|
+
export type { UseMallDataOptions, UseMallDataResult, UseMallListOptions, UseMallListResult, } from './types.js';
|
|
4
|
+
export { WovvMapProvider, useWovvMapContext } from './WovvMapContext.js';
|
|
5
|
+
export type { WovvMapProviderProps, WovvMapContextValue } from './WovvMapContext.js';
|
|
6
|
+
export { createMallController, MallController, DEFAULT_BASE_URL, DEFAULT_MALL_ENVIRONMENT, } from '@wovvmap/map-data';
|
|
7
|
+
export type { CatalogTarget, MallApiRequestOptions, MallApiVersion, MallControllerInit, MallDataInfo, MallEnvironment, MallListResponse, MallMapData, MallMetadataResponse, } from '@wovvmap/map-data';
|
|
8
|
+
export { parseViewerLink } from './viewerLink.js';
|
|
9
|
+
export type { ViewerLinkRequest, ViewerLinkOptions } from './viewerLink.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EACL,0BAA0B,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,GAC/B,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACrE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACjF,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,oBAAoB,GACrB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useMallData, useMallList } from './hooks.js';
|
|
2
|
+
export { createUseCatalogSearchHook, } from './useCatalogSearch.js';
|
|
3
|
+
export { WovvMapProvider, useWovvMapContext } from './WovvMapContext.js';
|
|
4
|
+
export { createMallController, MallController, DEFAULT_BASE_URL, DEFAULT_MALL_ENVIRONMENT, } from '@wovvmap/map-data';
|
|
5
|
+
export { parseViewerLink } from './viewerLink.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MallApiVersion, MallController, MallDataInfo, MallEnvironment, MallMapData } from '@wovvmap/map-data';
|
|
2
|
+
/**
|
|
3
|
+
* Options for useMallList hook.
|
|
4
|
+
* Hinglish: useMallList hook ke options.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseMallListOptions {
|
|
7
|
+
/** Optional custom MallController instance / Custom MallController instance */
|
|
8
|
+
controller?: MallController;
|
|
9
|
+
/** Override base URL for request / Base URL override */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** Override API version ('v1' | 'v2') / API version override */
|
|
12
|
+
apiVersion?: MallApiVersion;
|
|
13
|
+
/** Override target environment ('sit' | 'prod') / Environment override */
|
|
14
|
+
environment?: MallEnvironment | string;
|
|
15
|
+
/** Override endpoint path / Endpoint override */
|
|
16
|
+
endpoint?: string;
|
|
17
|
+
/** Whether to automatically fetch malls on mount (default: true) / Mount par auto fetch karein ya nahi */
|
|
18
|
+
autoFetch?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return state from useMallList hook.
|
|
22
|
+
* Hinglish: useMallList hook se return hone wala state.
|
|
23
|
+
*/
|
|
24
|
+
export interface UseMallListResult {
|
|
25
|
+
/** Array of active malls returned by Strapi / Strapi se prapt active malls ki list */
|
|
26
|
+
mallsList: MallDataInfo[];
|
|
27
|
+
/** Currently active API version ('v1' | 'v2') / Currently configured API version */
|
|
28
|
+
apiVersion: MallApiVersion;
|
|
29
|
+
/** Currently active backend environment ('sit' | 'prod') / Currently configured environment */
|
|
30
|
+
environment: MallEnvironment | string;
|
|
31
|
+
/** Loading indicator / Data fetch hone tak true rehta hai */
|
|
32
|
+
loading: boolean;
|
|
33
|
+
/** Error message if request failed, or null / Request fail hone par error message */
|
|
34
|
+
error: string | null;
|
|
35
|
+
/** Function to manually re-fetch the mall list / Mall list dobara fetch karne ka function */
|
|
36
|
+
refresh: () => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for useMallData hook.
|
|
40
|
+
* Hinglish: useMallData hook ke options.
|
|
41
|
+
*/
|
|
42
|
+
export type UseMallDataOptions = UseMallListOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Return state from useMallData hook.
|
|
45
|
+
* Hinglish: useMallData hook se return hone wala state.
|
|
46
|
+
*/
|
|
47
|
+
export interface UseMallDataResult extends Omit<UseMallListResult, 'mallsList'> {
|
|
48
|
+
/** Complete mall map data or null if not yet loaded / Complete mall map data */
|
|
49
|
+
mapData: MallMapData | null;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAE1B;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,cAAc,CAAA;IAC3B,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gEAAgE;IAChE,UAAU,CAAC,EAAE,cAAc,CAAA;IAC3B,0EAA0E;IAC1E,WAAW,CAAC,EAAE,eAAe,GAAG,MAAM,CAAA;IACtC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,SAAS,EAAE,YAAY,EAAE,CAAA;IACzB,oFAAoF;IACpF,UAAU,EAAE,cAAc,CAAA;IAC1B,+FAA+F;IAC/F,WAAW,EAAE,eAAe,GAAG,MAAM,CAAA;IACrC,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAA;IAChB,qFAAqF;IACrF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,6FAA6F;IAC7F,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,CAAA;AAEnD;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC;IAC7E,gFAAgF;IAChF,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;CAC5B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useCatalogSearch.ts
|
|
3
|
+
* @description Shared React hook factory for catalog browse and search across `@wovvmap/sdk-react`
|
|
4
|
+
* and `@wovvmap/sdk-react-native`. Subscribes ONLY to the target per-viewer discovery channel
|
|
5
|
+
* (`general`, `origin`, `destination`) and `parsedMap.mallId` so camera motion, floor switches,
|
|
6
|
+
* and activity on sibling search channels never cause unnecessary React re-renders.
|
|
7
|
+
*
|
|
8
|
+
* Hinglish: `@wovvmap/sdk-react` aur `@wovvmap/sdk-react-native` dono ke liye shared `useCatalogSearch`
|
|
9
|
+
* hook factory. Ye sirf specific channel (`general`, `origin`, `destination`) aur `parsedMap.mallId`
|
|
10
|
+
* ko subscribe karta hai taaki camera movement ya doosre channel me typing se extra re-render na ho.
|
|
11
|
+
*/
|
|
12
|
+
import type { CatalogDiscoveryChannel, CatalogFilterInput, CatalogFloorSecondarySortMode, CatalogGroupMembersPage, CatalogGroupMembersRequest, CatalogPage, CatalogPaginationInput, CatalogSortMode, CatalogTarget, DiscoveryChannelSnapshot, DiscoveryQueryParams } from '@wovvmap/map-data';
|
|
13
|
+
export type { CatalogDiscoveryChannel, CatalogFloorSecondarySortMode, CatalogItemForTarget, DiscoveryChannelSnapshot, DiscoveryQueryParams, DiscoveryQueryStatus, } from '@wovvmap/map-data';
|
|
14
|
+
/**
|
|
15
|
+
* Structural port for a per-channel discovery controller (`DiscoveryChannelController` from `@wovvmap/runtime-core`).
|
|
16
|
+
*
|
|
17
|
+
* Hinglish: `@wovvmap/runtime-core` ke `DiscoveryChannelController` ka structural contract.
|
|
18
|
+
*/
|
|
19
|
+
export interface DiscoveryChannelPort<TTarget extends CatalogTarget = CatalogTarget> {
|
|
20
|
+
getSnapshot(target?: TTarget): Readonly<DiscoveryChannelSnapshot<TTarget>>;
|
|
21
|
+
subscribe(listener: () => void): () => void;
|
|
22
|
+
execute(params: DiscoveryQueryParams<TTarget>, options?: {
|
|
23
|
+
immediate?: boolean;
|
|
24
|
+
}): Promise<CatalogPage<TTarget> | null>;
|
|
25
|
+
setQuery(query: string, options?: {
|
|
26
|
+
immediate?: boolean;
|
|
27
|
+
debounceMs?: number;
|
|
28
|
+
activeFloorIndex?: number;
|
|
29
|
+
}): Promise<CatalogPage<TTarget> | null>;
|
|
30
|
+
setFilter(filter: CatalogFilterInput | undefined, options?: {
|
|
31
|
+
immediate?: boolean;
|
|
32
|
+
activeFloorIndex?: number;
|
|
33
|
+
}): Promise<CatalogPage<TTarget> | null>;
|
|
34
|
+
setSortBy(sortBy: CatalogSortMode | undefined, floorSecondarySortBy?: CatalogFloorSecondarySortMode, options?: {
|
|
35
|
+
immediate?: boolean;
|
|
36
|
+
activeFloorIndex?: number;
|
|
37
|
+
}): Promise<CatalogPage<TTarget> | null>;
|
|
38
|
+
getGroupMembers?(groupIdOrRequest: string | CatalogGroupMembersRequest, pagination?: CatalogPaginationInput): Promise<CatalogGroupMembersPage | null>;
|
|
39
|
+
loadMore(): Promise<CatalogPage<TTarget> | null>;
|
|
40
|
+
retry(options?: {
|
|
41
|
+
activeFloorIndex?: number;
|
|
42
|
+
}): Promise<CatalogPage<TTarget> | null>;
|
|
43
|
+
cancel(): void;
|
|
44
|
+
reset(target?: TTarget): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Structural port for a per-viewer discovery coordinator (`ViewerDiscoveryCoordinator` from `@wovvmap/runtime-core`).
|
|
48
|
+
*
|
|
49
|
+
* Hinglish: `@wovvmap/runtime-core` ke `ViewerDiscoveryCoordinator` ka structural contract.
|
|
50
|
+
*/
|
|
51
|
+
export interface ViewerDiscoveryPort {
|
|
52
|
+
getChannel<TTarget extends CatalogTarget = 'stores'>(channel?: CatalogDiscoveryChannel, initialTarget?: TTarget): DiscoveryChannelPort<TTarget>;
|
|
53
|
+
getGroupMembers(request: CatalogGroupMembersRequest, channel?: CatalogDiscoveryChannel): Promise<CatalogGroupMembersPage | null>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Minimal viewer store slice required by `createUseCatalogSearchHook`.
|
|
57
|
+
*
|
|
58
|
+
* Hinglish: `createUseCatalogSearchHook` ke liye zaroori viewer store slice.
|
|
59
|
+
*/
|
|
60
|
+
export interface ViewerDiscoveryStoreSlice {
|
|
61
|
+
readonly discovery: ViewerDiscoveryPort;
|
|
62
|
+
readonly parsedMap: {
|
|
63
|
+
readonly mallId: string;
|
|
64
|
+
} | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for `useCatalogSearch`.
|
|
68
|
+
*
|
|
69
|
+
* Hinglish: `useCatalogSearch` hook ke options.
|
|
70
|
+
*/
|
|
71
|
+
export interface UseCatalogSearchOptions<TTarget extends CatalogTarget = 'stores'> {
|
|
72
|
+
readonly channel?: CatalogDiscoveryChannel;
|
|
73
|
+
readonly target?: TTarget;
|
|
74
|
+
readonly mode?: 'catalog' | 'search';
|
|
75
|
+
readonly query?: string;
|
|
76
|
+
readonly filter?: CatalogFilterInput;
|
|
77
|
+
readonly sortBy?: CatalogSortMode;
|
|
78
|
+
readonly floorSecondarySortBy?: CatalogFloorSecondarySortMode;
|
|
79
|
+
readonly activeFloorIndex?: number;
|
|
80
|
+
readonly groupMultiLocation?: boolean;
|
|
81
|
+
readonly pageSize?: number;
|
|
82
|
+
readonly debounceMs?: number;
|
|
83
|
+
readonly enabled?: boolean;
|
|
84
|
+
readonly immediate?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Return value of `useCatalogSearch<TTarget>`.
|
|
88
|
+
*
|
|
89
|
+
* Hinglish: `useCatalogSearch<TTarget>` hook ka return value aur actions.
|
|
90
|
+
*/
|
|
91
|
+
export interface UseCatalogSearchResult<TTarget extends CatalogTarget = 'stores'> extends DiscoveryChannelSnapshot<TTarget> {
|
|
92
|
+
readonly execute: (params: DiscoveryQueryParams<TTarget>, options?: {
|
|
93
|
+
immediate?: boolean;
|
|
94
|
+
}) => Promise<CatalogPage<TTarget> | null>;
|
|
95
|
+
readonly setQuery: (query: string, options?: {
|
|
96
|
+
immediate?: boolean;
|
|
97
|
+
debounceMs?: number;
|
|
98
|
+
activeFloorIndex?: number;
|
|
99
|
+
}) => Promise<CatalogPage<TTarget> | null>;
|
|
100
|
+
readonly setFilter: (filter: CatalogFilterInput | undefined, options?: {
|
|
101
|
+
immediate?: boolean;
|
|
102
|
+
activeFloorIndex?: number;
|
|
103
|
+
}) => Promise<CatalogPage<TTarget> | null>;
|
|
104
|
+
readonly setSortBy: (sortBy: CatalogSortMode | undefined, floorSecondarySortBy?: CatalogFloorSecondarySortMode, options?: {
|
|
105
|
+
immediate?: boolean;
|
|
106
|
+
activeFloorIndex?: number;
|
|
107
|
+
}) => Promise<CatalogPage<TTarget> | null>;
|
|
108
|
+
readonly loadMore: () => Promise<CatalogPage<TTarget> | null>;
|
|
109
|
+
readonly retry: (options?: {
|
|
110
|
+
activeFloorIndex?: number;
|
|
111
|
+
}) => Promise<CatalogPage<TTarget> | null>;
|
|
112
|
+
readonly cancel: () => void;
|
|
113
|
+
readonly reset: (target?: TTarget) => void;
|
|
114
|
+
readonly getGroupMembers: (request: CatalogGroupMembersRequest) => Promise<CatalogGroupMembersPage | null>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Creates the shared `useCatalogSearch` hook bound to a platform's `useMapViewerStore` hook
|
|
118
|
+
* (`@wovvmap/sdk-react` on Web or `@wovvmap/sdk-react-native` on Native).
|
|
119
|
+
*
|
|
120
|
+
* Hinglish: Platform ke `useMapViewerStore` hook ke upar shared `useCatalogSearch` hook banata hai.
|
|
121
|
+
*/
|
|
122
|
+
export declare function createUseCatalogSearchHook<TStoreState extends ViewerDiscoveryStoreSlice>(useStore: <TSelected>(selector: (state: TStoreState) => TSelected) => TSelected): <TTarget extends CatalogTarget = "stores">(options?: UseCatalogSearchOptions<TTarget>) => UseCatalogSearchResult<TTarget>;
|
|
123
|
+
//# sourceMappingURL=useCatalogSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCatalogSearch.d.ts","sourceRoot":"","sources":["../src/useCatalogSearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,uBAAuB,EACvB,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EACV,uBAAuB,EACvB,6BAA6B,EAC7B,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,mBAAmB,CAAA;AAE1B;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,aAAa,GAAG,aAAa;IACjF,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1E,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3C,OAAO,CACL,MAAM,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACrC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAChC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;IACvC,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;Q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AC,GAAG,IAAI,CAAC,CAAA;IACjG,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1C,QAAQ,CAAC,eAAe,EAAE,CACxB,OAAO,EAAE,0BAA0B,KAChC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAA;CAC7C;AAMD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,SAAS,yBAAyB,EACtF,QAAQ,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,SAAS,KAAK,SAAS,IAE9C,OAAO,SAAS,aAAa,GAAG,QAAQ,EACvE,UAAU,uBAAuB,CAAC,OAAO,CAAC,KACzC,sBAAsB,CAAC,OAAO,CAAC,CAoLnC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useCatalogSearch.ts
|
|
3
|
+
* @description Shared React hook factory for catalog browse and search across `@wovvmap/sdk-react`
|
|
4
|
+
* and `@wovvmap/sdk-react-native`. Subscribes ONLY to the target per-viewer discovery channel
|
|
5
|
+
* (`general`, `origin`, `destination`) and `parsedMap.mallId` so camera motion, floor switches,
|
|
6
|
+
* and activity on sibling search channels never cause unnecessary React re-renders.
|
|
7
|
+
*
|
|
8
|
+
* Hinglish: `@wovvmap/sdk-react` aur `@wovvmap/sdk-react-native` dono ke liye shared `useCatalogSearch`
|
|
9
|
+
* hook factory. Ye sirf specific channel (`general`, `origin`, `destination`) aur `parsedMap.mallId`
|
|
10
|
+
* ko subscribe karta hai taaki camera movement ya doosre channel me typing se extra re-render na ho.
|
|
11
|
+
*/
|
|
12
|
+
import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react';
|
|
13
|
+
const selectDiscovery = (state) => state.discovery;
|
|
14
|
+
const selectLoadedMap = (state) => state.parsedMap;
|
|
15
|
+
/**
|
|
16
|
+
* Creates the shared `useCatalogSearch` hook bound to a platform's `useMapViewerStore` hook
|
|
17
|
+
* (`@wovvmap/sdk-react` on Web or `@wovvmap/sdk-react-native` on Native).
|
|
18
|
+
*
|
|
19
|
+
* Hinglish: Platform ke `useMapViewerStore` hook ke upar shared `useCatalogSearch` hook banata hai.
|
|
20
|
+
*/
|
|
21
|
+
export function createUseCatalogSearchHook(useStore) {
|
|
22
|
+
return function useCatalogSearch(options) {
|
|
23
|
+
const channel = options?.channel ?? 'general';
|
|
24
|
+
const target = (options?.target ?? 'stores');
|
|
25
|
+
const discovery = useStore(selectDiscovery);
|
|
26
|
+
const loadedMap = useStore(selectLoadedMap);
|
|
27
|
+
const channelController = discovery.getChannel(channel, target);
|
|
28
|
+
const getSnapshot = useCallback(() => channelController.getSnapshot(target), [channelController, target]);
|
|
29
|
+
const snapshot = useSyncExternalStore(channelController.subscribe, getSnapshot, getSnapshot);
|
|
30
|
+
// Bind imperative actions to this hook's target without changing shared state during render.
|
|
31
|
+
// Hinglish: Sirf explicit action target badalta hai; render/disabled hook query nahi chalata.
|
|
32
|
+
const getActionController = useCallback(() => {
|
|
33
|
+
if (channelController.getSnapshot().target !== target)
|
|
34
|
+
channelController.reset(target);
|
|
35
|
+
return channelController;
|
|
36
|
+
}, [channelController, target]);
|
|
37
|
+
const filterKey = JSON.stringify([
|
|
38
|
+
options?.filter?.categoryCode ?? null,
|
|
39
|
+
options?.filter?.subCategoryCode ?? null,
|
|
40
|
+
options?.filter?.amenityId ?? null,
|
|
41
|
+
options?.filter?.floorIndex ?? null,
|
|
42
|
+
options?.filter?.offersOnly ?? false,
|
|
43
|
+
]);
|
|
44
|
+
const latestOptionsRef = useRef(options);
|
|
45
|
+
latestOptionsRef.current = options;
|
|
46
|
+
const enabled = options?.enabled ?? false;
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!enabled || !loadedMap?.mallId) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const currentOpts = latestOptionsRef.current;
|
|
52
|
+
void channelController.execute({
|
|
53
|
+
target,
|
|
54
|
+
mode: currentOpts?.mode,
|
|
55
|
+
query: currentOpts?.query,
|
|
56
|
+
filter: currentOpts?.filter,
|
|
57
|
+
sortBy: currentOpts?.sortBy,
|
|
58
|
+
floorSecondarySortBy: currentOpts?.floorSecondarySortBy,
|
|
59
|
+
activeFloorIndex: currentOpts?.activeFloorIndex,
|
|
60
|
+
groupMultiLocation: currentOpts?.groupMultiLocation,
|
|
61
|
+
pageSize: currentOpts?.pageSize,
|
|
62
|
+
debounceMs: currentOpts?.debounceMs,
|
|
63
|
+
}, { immediate: currentOpts?.immediate });
|
|
64
|
+
// Intentionally omit `options?.activeFloorIndex` from automatic effect dependencies so floor
|
|
65
|
+
// changes on the map never trigger automatic catalog/search reloads; explicit actions (`setSortBy`,
|
|
66
|
+
// `setQuery`, `setFilter`, `retry`, `execute`) forward `latestOptionsRef.current?.activeFloorIndex`.
|
|
67
|
+
}, [
|
|
68
|
+
enabled,
|
|
69
|
+
loadedMap,
|
|
70
|
+
channelController,
|
|
71
|
+
target,
|
|
72
|
+
options?.mode,
|
|
73
|
+
options?.query,
|
|
74
|
+
filterKey,
|
|
75
|
+
options?.sortBy,
|
|
76
|
+
options?.floorSecondarySortBy,
|
|
77
|
+
options?.groupMultiLocation,
|
|
78
|
+
options?.pageSize,
|
|
79
|
+
options?.debounceMs,
|
|
80
|
+
options?.immediate,
|
|
81
|
+
]);
|
|
82
|
+
const execute = useCallback((params, execOptions) => {
|
|
83
|
+
const fallbackFloor = latestOptionsRef.current?.activeFloorIndex;
|
|
84
|
+
return channelController.execute(params.activeFloorIndex === undefined && fallbackFloor !== undefined
|
|
85
|
+
? { ...params, activeFloorIndex: fallbackFloor }
|
|
86
|
+
: params, execOptions);
|
|
87
|
+
}, [channelController]);
|
|
88
|
+
const setQuery = useCallback((query, queryOptions) => {
|
|
89
|
+
const activeFloorIndex = queryOptions?.activeFloorIndex ?? latestOptionsRef.current?.activeFloorIndex;
|
|
90
|
+
return getActionController().setQuery(query, {
|
|
91
|
+
...queryOptions,
|
|
92
|
+
...(activeFloorIndex !== undefined ? { activeFloorIndex } : {}),
|
|
93
|
+
});
|
|
94
|
+
}, [getActionController]);
|
|
95
|
+
const setFilter = useCallback((filter, filterOptions) => {
|
|
96
|
+
const activeFloorIndex = filterOptions?.activeFloorIndex ?? latestOptionsRef.current?.activeFloorIndex;
|
|
97
|
+
return getActionController().setFilter(filter, {
|
|
98
|
+
...filterOptions,
|
|
99
|
+
...(activeFloorIndex !== undefined ? { activeFloorIndex } : {}),
|
|
100
|
+
});
|
|
101
|
+
}, [getActionController]);
|
|
102
|
+
const setSortBy = useCallback((sortBy, floorSecondarySortBy, sortOptions) => {
|
|
103
|
+
const activeFloorIndex = sortOptions?.activeFloorIndex ?? latestOptionsRef.current?.activeFloorIndex;
|
|
104
|
+
return getActionController().setSortBy(sortBy, floorSecondarySortBy, {
|
|
105
|
+
...sortOptions,
|
|
106
|
+
...(activeFloorIndex !== undefined ? { activeFloorIndex } : {}),
|
|
107
|
+
});
|
|
108
|
+
}, [getActionController]);
|
|
109
|
+
const loadMore = useCallback(() => channelController.getSnapshot().target === target
|
|
110
|
+
? channelController.loadMore()
|
|
111
|
+
: Promise.resolve(null), [channelController, target]);
|
|
112
|
+
const retry = useCallback((retryOptions) => {
|
|
113
|
+
const activeFloorIndex = retryOptions?.activeFloorIndex ?? latestOptionsRef.current?.activeFloorIndex;
|
|
114
|
+
return getActionController().retry(activeFloorIndex !== undefined ? { activeFloorIndex } : retryOptions);
|
|
115
|
+
}, [getActionController]);
|
|
116
|
+
const cancel = useCallback(() => {
|
|
117
|
+
if (channelController.getSnapshot().target === target)
|
|
118
|
+
channelController.cancel();
|
|
119
|
+
}, [channelController, target]);
|
|
120
|
+
const reset = useCallback((nextTarget) => channelController.reset(nextTarget ?? target), [channelController, target]);
|
|
121
|
+
const getGroupMembers = useCallback((request) => {
|
|
122
|
+
const fallbackFloor = latestOptionsRef.current?.activeFloorIndex;
|
|
123
|
+
const effectiveRequest = request.activeFloorIndex === undefined && fallbackFloor !== undefined
|
|
124
|
+
? { ...request, activeFloorIndex: fallbackFloor }
|
|
125
|
+
: request;
|
|
126
|
+
if (typeof channelController.getGroupMembers === 'function') {
|
|
127
|
+
return channelController.getGroupMembers(effectiveRequest);
|
|
128
|
+
}
|
|
129
|
+
return discovery.getGroupMembers(effectiveRequest, channel);
|
|
130
|
+
}, [channelController, discovery, channel]);
|
|
131
|
+
return {
|
|
132
|
+
...snapshot,
|
|
133
|
+
execute,
|
|
134
|
+
setQuery,
|
|
135
|
+
setFilter,
|
|
136
|
+
setSortBy,
|
|
137
|
+
loadMore,
|
|
138
|
+
retry,
|
|
139
|
+
cancel,
|
|
140
|
+
reset,
|
|
141
|
+
getGroupMembers,
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MallApiRequestOptions } from '@wovvmap/map-data';
|
|
2
|
+
import { type MallRequestConfig } from './MallRequestManager.js';
|
|
3
|
+
import type { UseMallListOptions } from './types.js';
|
|
4
|
+
/** One React lifecycle binding; the manager owns fetch, cancellation and notifications.
|
|
5
|
+
* Hinglish: Effect sirf inputs attach/detach karta hai; request ka logic class me hai. */
|
|
6
|
+
export declare function useMallRequest<T>(options: UseMallListOptions, mallId: string | null | undefined, empty: T, fetch: (config: MallRequestConfig, request: MallApiRequestOptions) => Promise<T>, canFetch: (config: MallRequestConfig) => boolean): {
|
|
7
|
+
refresh: () => Promise<void>;
|
|
8
|
+
apiVersion: import("@wovvmap/map-data").MallApiVersion;
|
|
9
|
+
environment: string;
|
|
10
|
+
data: T;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: string | null;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useMallRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMallRequest.d.ts","sourceRoot":"","sources":["../src/useMallRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAEjF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIjD;0FAC0F;AAC1F,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC,CAAC,EAChF,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO;;;;;;;EAoBjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
2
|
+
import { MallController } from '@wovvmap/map-data';
|
|
3
|
+
import { MallRequestManager } from './MallRequestManager.js';
|
|
4
|
+
import { useWovvMapContext } from './WovvMapContext.js';
|
|
5
|
+
let fallback;
|
|
6
|
+
/** One React lifecycle binding; the manager owns fetch, cancellation and notifications.
|
|
7
|
+
* Hinglish: Effect sirf inputs attach/detach karta hai; request ka logic class me hai. */
|
|
8
|
+
export function useMallRequest(options, mallId, empty, fetch, canFetch) {
|
|
9
|
+
const context = useWovvMapContext();
|
|
10
|
+
const controller = options.controller ?? context.controller ?? (fallback ??= new MallController());
|
|
11
|
+
const { apiVersion, environment, baseUrl, endpoint, autoFetch } = options;
|
|
12
|
+
const config = { controller, apiVersion, environment, baseUrl, endpoint, autoFetch, mallId };
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
ref.current ??= new MallRequestManager(config, empty, fetch, canFetch);
|
|
15
|
+
const manager = ref.current;
|
|
16
|
+
const state = useSyncExternalStore(manager.subscribe, manager.getSnapshot, manager.getSnapshot);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
manager.configure({ controller, apiVersion, environment, baseUrl, endpoint, autoFetch, mallId });
|
|
19
|
+
return manager.stop;
|
|
20
|
+
}, [manager, controller, apiVersion, environment, baseUrl, endpoint, autoFetch, mallId]);
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
refresh: manager.refresh,
|
|
24
|
+
apiVersion: apiVersion ?? controller.version,
|
|
25
|
+
environment: environment ?? controller.environment,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MallApiVersion, MallEnvironment } from '@wovvmap/map-data';
|
|
2
|
+
export interface ViewerLinkRequest {
|
|
3
|
+
readonly mallId: string;
|
|
4
|
+
readonly apiVersion: MallApiVersion;
|
|
5
|
+
readonly environment: MallEnvironment;
|
|
6
|
+
readonly initialFloor?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ViewerLinkOptions {
|
|
9
|
+
readonly allowedOrigins: readonly string[];
|
|
10
|
+
readonly apiVersion: MallApiVersion;
|
|
11
|
+
readonly environment: MallEnvironment;
|
|
12
|
+
}
|
|
13
|
+
/** Parse only map identity, never delivery URLs, executable content, tokens or route commands.
|
|
14
|
+
* Hinglish: Web/Native ke same link fields; RN ke incomplete URL implementation par dependency nahi. */
|
|
15
|
+
export declare function parseViewerLink(raw: string, options: ViewerLinkOptions): ViewerLinkRequest | null;
|
|
16
|
+
//# sourceMappingURL=viewerLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewerLink.d.ts","sourceRoot":"","sources":["../src/viewerLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAA;IACnC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAA;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AACD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAA;IACnC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAA;CACtC;AACD;wGACwG;AACxG,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,GAAG,IAAI,CAgCjG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Parse only map identity, never delivery URLs, executable content, tokens or route commands.
|
|
2
|
+
* Hinglish: Web/Native ke same link fields; RN ke incomplete URL implementation par dependency nahi. */
|
|
3
|
+
export function parseViewerLink(raw, options) {
|
|
4
|
+
if (typeof raw !== 'string' || raw.length > 4096)
|
|
5
|
+
return null;
|
|
6
|
+
const match = /^([a-z][a-z0-9+.-]*:\/\/[^/?#]+)\/viewer\/([a-zA-Z0-9_-]+)\/?(?:\?([^#]*))?(?:#.*)?$/i.exec(raw);
|
|
7
|
+
if (!match || !options.allowedOrigins.includes(match[1]))
|
|
8
|
+
return null;
|
|
9
|
+
const query = Object.create(null);
|
|
10
|
+
try {
|
|
11
|
+
for (const entry of (match[3] ?? '').split('&')) {
|
|
12
|
+
if (!entry)
|
|
13
|
+
continue;
|
|
14
|
+
const split = entry.indexOf('=');
|
|
15
|
+
const key = decodeURIComponent(split < 0 ? entry : entry.slice(0, split));
|
|
16
|
+
if (!['v', 'env', 'floor'].includes(key))
|
|
17
|
+
continue;
|
|
18
|
+
if (Object.hasOwn(query, key))
|
|
19
|
+
return null;
|
|
20
|
+
query[key] = decodeURIComponent(split < 0 ? '' : entry.slice(split + 1));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const apiVersion = query.v ?? options.apiVersion;
|
|
27
|
+
const environment = query.env ?? options.environment;
|
|
28
|
+
if (!['v1', 'v2'].includes(apiVersion) || !['sit', 'prod'].includes(environment))
|
|
29
|
+
return null;
|
|
30
|
+
const floor = query.floor;
|
|
31
|
+
if (floor !== undefined && (!/^\d+$/.test(floor) || !Number.isSafeInteger(Number(floor))))
|
|
32
|
+
return null;
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
mallId: match[2],
|
|
35
|
+
apiVersion: apiVersion,
|
|
36
|
+
environment: environment,
|
|
37
|
+
...(floor === undefined ? {} : { initialFloor: Number(floor) }),
|
|
38
|
+
});
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wovvmap/sdk-react-core",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Shared React data bindings for WovVMap Web and Native adapters.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@wovvmap/map-data": "1.2.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^19.1.0 || ^19.2.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "19.2.18",
|
|
33
|
+
"@types/react-test-renderer": "^19.3.0",
|
|
34
|
+
"react": "19.2.8",
|
|
35
|
+
"react-test-renderer": "19.2.8"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"test": "vitest run src --passWithNoTests",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit"
|
|
42
|
+
}
|
|
6
43
|
}
|
package/README.md
DELETED