@aigentyc/chat-sdk 0.1.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/LICENSE +21 -0
- package/README.md +156 -0
- package/dist/JsonRenderResult-Ftw4AKwb.d.cts +18 -0
- package/dist/JsonRenderResult-Ftw4AKwb.d.ts +18 -0
- package/dist/JsonRenderResult-GQOYPLVH.cjs +15 -0
- package/dist/JsonRenderResult-GQOYPLVH.cjs.map +1 -0
- package/dist/JsonRenderResult-ZFJ6VWMS.js +6 -0
- package/dist/JsonRenderResult-ZFJ6VWMS.js.map +1 -0
- package/dist/SlotsContext-CBtt36al.d.ts +148 -0
- package/dist/SlotsContext-CHvISDJT.d.cts +148 -0
- package/dist/VisualizationRenderer-FNFYNN66.js +5 -0
- package/dist/VisualizationRenderer-FNFYNN66.js.map +1 -0
- package/dist/VisualizationRenderer-VKMZXRUX.cjs +20 -0
- package/dist/VisualizationRenderer-VKMZXRUX.cjs.map +1 -0
- package/dist/ai-elements.cjs +4608 -0
- package/dist/ai-elements.cjs.map +1 -0
- package/dist/ai-elements.d.cts +897 -0
- package/dist/ai-elements.d.ts +897 -0
- package/dist/ai-elements.js +4363 -0
- package/dist/ai-elements.js.map +1 -0
- package/dist/chunk-3MP2EGEJ.cjs +270 -0
- package/dist/chunk-3MP2EGEJ.cjs.map +1 -0
- package/dist/chunk-3RW7O444.js +26 -0
- package/dist/chunk-3RW7O444.js.map +1 -0
- package/dist/chunk-42ARGQXE.js +51 -0
- package/dist/chunk-42ARGQXE.js.map +1 -0
- package/dist/chunk-4FBVV64J.js +257 -0
- package/dist/chunk-4FBVV64J.js.map +1 -0
- package/dist/chunk-4QT25AXI.js +21 -0
- package/dist/chunk-4QT25AXI.js.map +1 -0
- package/dist/chunk-525KS5HM.cjs +30 -0
- package/dist/chunk-525KS5HM.cjs.map +1 -0
- package/dist/chunk-5F3O3ZJH.js +299 -0
- package/dist/chunk-5F3O3ZJH.js.map +1 -0
- package/dist/chunk-5QSXB6UL.cjs +259 -0
- package/dist/chunk-5QSXB6UL.cjs.map +1 -0
- package/dist/chunk-5T4FJ2SR.js +664 -0
- package/dist/chunk-5T4FJ2SR.js.map +1 -0
- package/dist/chunk-7BNYTOTE.cjs +67 -0
- package/dist/chunk-7BNYTOTE.cjs.map +1 -0
- package/dist/chunk-AWAJOSFP.cjs +96 -0
- package/dist/chunk-AWAJOSFP.cjs.map +1 -0
- package/dist/chunk-BKDV2H6Z.js +224 -0
- package/dist/chunk-BKDV2H6Z.js.map +1 -0
- package/dist/chunk-FQN6OBGN.cjs +171 -0
- package/dist/chunk-FQN6OBGN.cjs.map +1 -0
- package/dist/chunk-FYPJSHCL.js +190 -0
- package/dist/chunk-FYPJSHCL.js.map +1 -0
- package/dist/chunk-J2H6MLQF.cjs +680 -0
- package/dist/chunk-J2H6MLQF.cjs.map +1 -0
- package/dist/chunk-J2K7EJYP.cjs +198 -0
- package/dist/chunk-J2K7EJYP.cjs.map +1 -0
- package/dist/chunk-JI5KCSOI.cjs +23 -0
- package/dist/chunk-JI5KCSOI.cjs.map +1 -0
- package/dist/chunk-JOO6C3XT.cjs +44 -0
- package/dist/chunk-JOO6C3XT.cjs.map +1 -0
- package/dist/chunk-KBGPBUTI.cjs +78 -0
- package/dist/chunk-KBGPBUTI.cjs.map +1 -0
- package/dist/chunk-MT2AMINB.js +75 -0
- package/dist/chunk-MT2AMINB.js.map +1 -0
- package/dist/chunk-MZQKGNWF.js +4 -0
- package/dist/chunk-MZQKGNWF.js.map +1 -0
- package/dist/chunk-NG7OTWXQ.cjs +226 -0
- package/dist/chunk-NG7OTWXQ.cjs.map +1 -0
- package/dist/chunk-NPJKLYLV.js +68 -0
- package/dist/chunk-NPJKLYLV.js.map +1 -0
- package/dist/chunk-NW2ESHRV.js +685 -0
- package/dist/chunk-NW2ESHRV.js.map +1 -0
- package/dist/chunk-NWF735F5.js +1631 -0
- package/dist/chunk-NWF735F5.js.map +1 -0
- package/dist/chunk-NYQSM3EB.cjs +305 -0
- package/dist/chunk-NYQSM3EB.cjs.map +1 -0
- package/dist/chunk-OU7OROOE.cjs +1643 -0
- package/dist/chunk-OU7OROOE.cjs.map +1 -0
- package/dist/chunk-PS3U7T37.js +42 -0
- package/dist/chunk-PS3U7T37.js.map +1 -0
- package/dist/chunk-Q7T3VAJV.cjs +687 -0
- package/dist/chunk-Q7T3VAJV.cjs.map +1 -0
- package/dist/chunk-QYCEHFAB.js +265 -0
- package/dist/chunk-QYCEHFAB.js.map +1 -0
- package/dist/chunk-RPDJXB3U.js +676 -0
- package/dist/chunk-RPDJXB3U.js.map +1 -0
- package/dist/chunk-UKEL7FWS.js +64 -0
- package/dist/chunk-UKEL7FWS.js.map +1 -0
- package/dist/chunk-VS3NZ7FX.js +164 -0
- package/dist/chunk-VS3NZ7FX.js.map +1 -0
- package/dist/chunk-WZLWAVSS.cjs +73 -0
- package/dist/chunk-WZLWAVSS.cjs.map +1 -0
- package/dist/chunk-X5YEOOPK.cjs +758 -0
- package/dist/chunk-X5YEOOPK.cjs.map +1 -0
- package/dist/chunk-X7R334SB.cjs +5 -0
- package/dist/chunk-X7R334SB.cjs.map +1 -0
- package/dist/chunk-XXNDL5SJ.cjs +432 -0
- package/dist/chunk-XXNDL5SJ.cjs.map +1 -0
- package/dist/chunk-YQELMJW5.js +429 -0
- package/dist/chunk-YQELMJW5.js.map +1 -0
- package/dist/components.cjs +551 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +181 -0
- package/dist/components.d.ts +181 -0
- package/dist/components.js +483 -0
- package/dist/components.js.map +1 -0
- package/dist/core.cjs +283 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +455 -0
- package/dist/core.d.ts +455 -0
- package/dist/core.js +241 -0
- package/dist/core.js.map +1 -0
- package/dist/hooks.cjs +324 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.cts +163 -0
- package/dist/hooks.d.ts +163 -0
- package/dist/hooks.js +277 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.cjs +26 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.d.cts +50 -0
- package/dist/i18n.d.ts +50 -0
- package/dist/i18n.js +5 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.cjs +466 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +438 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction-tracker-D9P1Oq4j.d.cts +83 -0
- package/dist/interaction-tracker-D9P1Oq4j.d.ts +83 -0
- package/dist/json-render.cjs +23 -0
- package/dist/json-render.cjs.map +1 -0
- package/dist/json-render.d.cts +857 -0
- package/dist/json-render.d.ts +857 -0
- package/dist/json-render.js +6 -0
- package/dist/json-render.js.map +1 -0
- package/dist/live-chat-transport-4XLOIPOE.js +4 -0
- package/dist/live-chat-transport-4XLOIPOE.js.map +1 -0
- package/dist/live-chat-transport-ALVRGWX7.cjs +13 -0
- package/dist/live-chat-transport-ALVRGWX7.cjs.map +1 -0
- package/dist/select-B4l9yoyn.d.cts +99 -0
- package/dist/select-B4l9yoyn.d.ts +99 -0
- package/dist/styles.css +2 -0
- package/dist/theme.cjs +18 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +55 -0
- package/dist/theme.d.ts +55 -0
- package/dist/theme.js +5 -0
- package/dist/theme.js.map +1 -0
- package/dist/tools.cjs +32 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.d.cts +117 -0
- package/dist/tools.d.ts +117 -0
- package/dist/tools.js +11 -0
- package/dist/tools.js.map +1 -0
- package/dist/types-DKJ_-nbG.d.cts +349 -0
- package/dist/types-DKJ_-nbG.d.ts +349 -0
- package/dist/ui.cjs +667 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +95 -0
- package/dist/ui.d.ts +95 -0
- package/dist/ui.js +414 -0
- package/dist/ui.js.map +1 -0
- package/package.json +255 -0
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export { L as LiveChatReturn, U as UseAigentycChatOptions, a as UseAigentycChatReturn, u as useAigentycChat, b as useChatContext, c as useLiveChat, d as useSlot, e as useSlots } from './SlotsContext-CBtt36al.js';
|
|
2
|
+
export { useTheme } from './theme.js';
|
|
3
|
+
export { useI18n } from './i18n.js';
|
|
4
|
+
import { RefObject } from 'react';
|
|
5
|
+
export { u as useInteractionTracker } from './interaction-tracker-D9P1Oq4j.js';
|
|
6
|
+
import './types-DKJ_-nbG.js';
|
|
7
|
+
import 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
/** Information about a preview to display in an embedded panel. */
|
|
10
|
+
interface PreviewInfo {
|
|
11
|
+
/** URL to preview. */
|
|
12
|
+
url: string;
|
|
13
|
+
/** Optional title for the preview. */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Optional description for the preview. */
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
interface PreviewEmbedContextValue {
|
|
19
|
+
/** Current preview info, or null if no preview is active. */
|
|
20
|
+
preview: PreviewInfo | null;
|
|
21
|
+
/** Open a preview panel with the given info. */
|
|
22
|
+
openPreview: (info: PreviewInfo) => void;
|
|
23
|
+
/** Close the active preview panel. */
|
|
24
|
+
closePreview: () => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the preview embed context.
|
|
28
|
+
* Returns null if used outside a PreviewEmbedProvider (non-throwing for optional usage).
|
|
29
|
+
*/
|
|
30
|
+
declare function usePreviewEmbed(): PreviewEmbedContextValue | null;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Detects whether the viewport is mobile-sized.
|
|
34
|
+
* Ignores height-only changes (e.g. virtual keyboard) and only reacts
|
|
35
|
+
* when width actually crosses the breakpoint.
|
|
36
|
+
*
|
|
37
|
+
* SSR-safe: returns false during server rendering.
|
|
38
|
+
*/
|
|
39
|
+
declare function useIsMobile(): boolean;
|
|
40
|
+
|
|
41
|
+
interface UseImageLoaderReturn {
|
|
42
|
+
/** Whether the image has finished loading. */
|
|
43
|
+
loaded: boolean;
|
|
44
|
+
/** Callback to set loaded state to true. Pass as `onLoad` to an `<img>`. */
|
|
45
|
+
onLoad: () => void;
|
|
46
|
+
/** Reset loaded state to false. */
|
|
47
|
+
reset: () => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Tracks load state for a single image element.
|
|
51
|
+
*/
|
|
52
|
+
declare function useImageLoader(): UseImageLoaderReturn;
|
|
53
|
+
interface UseMultiImageLoaderReturn {
|
|
54
|
+
/** Check if a specific image has loaded. */
|
|
55
|
+
isLoaded: (key: string) => boolean;
|
|
56
|
+
/** Returns a callback for the given key to mark it as loaded. */
|
|
57
|
+
onLoad: (key: string) => () => void;
|
|
58
|
+
/** Reset a specific image's loaded state. */
|
|
59
|
+
reset: (key: string) => void;
|
|
60
|
+
/** Reset all images' loaded states. */
|
|
61
|
+
resetAll: () => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Tracks load state for multiple images by key.
|
|
65
|
+
*/
|
|
66
|
+
declare function useMultiImageLoader(): UseMultiImageLoaderReturn;
|
|
67
|
+
|
|
68
|
+
interface UsePaginationOptions<T> {
|
|
69
|
+
/** The full list of items to paginate. */
|
|
70
|
+
items: T[];
|
|
71
|
+
/** Number of items per page. */
|
|
72
|
+
itemsPerPage: number;
|
|
73
|
+
/** Optional callback when the page changes. */
|
|
74
|
+
onPageChange?: (direction: "next" | "prev", newPage: number, totalPages: number) => void;
|
|
75
|
+
}
|
|
76
|
+
interface UsePaginationReturn<T> {
|
|
77
|
+
/** Current page index (0-based). */
|
|
78
|
+
page: number;
|
|
79
|
+
/** Total number of pages. */
|
|
80
|
+
totalPages: number;
|
|
81
|
+
/** Items for the current page. */
|
|
82
|
+
currentItems: T[];
|
|
83
|
+
/** Go to the next page. */
|
|
84
|
+
goNext: () => void;
|
|
85
|
+
/** Go to the previous page. */
|
|
86
|
+
goPrev: () => void;
|
|
87
|
+
/** Go to a specific page (0-based). */
|
|
88
|
+
goToPage: (page: number) => void;
|
|
89
|
+
/** Whether the current page is the first page. */
|
|
90
|
+
isFirstPage: boolean;
|
|
91
|
+
/** Whether the current page is the last page. */
|
|
92
|
+
isLastPage: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generic pagination hook for any list of items.
|
|
96
|
+
*/
|
|
97
|
+
declare function usePagination<T>({ items, itemsPerPage, onPageChange, }: UsePaginationOptions<T>): UsePaginationReturn<T>;
|
|
98
|
+
|
|
99
|
+
interface UseSliderDragOptions {
|
|
100
|
+
/** Ref to the container element. */
|
|
101
|
+
containerRef: RefObject<HTMLDivElement | null>;
|
|
102
|
+
/** Initial slider position as a percentage (0-100). Defaults to 50. */
|
|
103
|
+
initialPosition?: number;
|
|
104
|
+
/** Minimum allowed position. Defaults to 0. */
|
|
105
|
+
minPosition?: number;
|
|
106
|
+
/** Maximum allowed position. Defaults to 100. */
|
|
107
|
+
maxPosition?: number;
|
|
108
|
+
}
|
|
109
|
+
interface UseSliderDragReturn {
|
|
110
|
+
/** Current slider position as a percentage (0-100). */
|
|
111
|
+
sliderPosition: number;
|
|
112
|
+
/** Whether the user is currently dragging. */
|
|
113
|
+
isDragging: boolean;
|
|
114
|
+
/** Call this on mousedown/touchstart to begin dragging. */
|
|
115
|
+
handleMouseDown: () => void;
|
|
116
|
+
/** Programmatically set the slider position. */
|
|
117
|
+
setSliderPosition: (position: number) => void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Handles mouse and touch drag interactions for a horizontal slider.
|
|
121
|
+
* SSR-safe: event listeners are only attached in the browser.
|
|
122
|
+
*/
|
|
123
|
+
declare function useSliderDrag({ containerRef, initialPosition, minPosition, maxPosition, }: UseSliderDragOptions): UseSliderDragReturn;
|
|
124
|
+
|
|
125
|
+
type OrderStatus = "idle" | "pending" | "added" | "error";
|
|
126
|
+
interface UseOrderTrackingOptions {
|
|
127
|
+
/** Product ID to track. */
|
|
128
|
+
productId?: string;
|
|
129
|
+
}
|
|
130
|
+
interface UseOrderTrackingReturn {
|
|
131
|
+
/** Current order status. */
|
|
132
|
+
orderStatus: OrderStatus;
|
|
133
|
+
/** Error message if status is "error". */
|
|
134
|
+
orderError: string | null;
|
|
135
|
+
/** Mark the order as pending. */
|
|
136
|
+
startOrder: () => void;
|
|
137
|
+
/** Reset to idle state. */
|
|
138
|
+
reset: () => void;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tracks a single product order status via the `caesarstone:order-sample-complete` custom event.
|
|
142
|
+
* SSR-safe: event listeners are only attached in the browser.
|
|
143
|
+
*/
|
|
144
|
+
declare function useOrderTracking({ productId, }: UseOrderTrackingOptions): UseOrderTrackingReturn;
|
|
145
|
+
interface UseMultiOrderTrackingReturn {
|
|
146
|
+
/** Get status for a specific product. */
|
|
147
|
+
getStatus: (productId: string) => OrderStatus;
|
|
148
|
+
/** Get error message for a specific product. */
|
|
149
|
+
getError: (productId: string) => string | undefined;
|
|
150
|
+
/** Mark a product order as pending. */
|
|
151
|
+
startOrder: (productId: string) => void;
|
|
152
|
+
/** Reset a specific product's order status. */
|
|
153
|
+
reset: (productId: string) => void;
|
|
154
|
+
/** Reset all tracked products. */
|
|
155
|
+
resetAll: () => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Tracks multiple product order statuses via the `caesarstone:order-sample-complete` custom event.
|
|
159
|
+
* SSR-safe: event listeners are only attached in the browser.
|
|
160
|
+
*/
|
|
161
|
+
declare function useMultiOrderTracking(): UseMultiOrderTrackingReturn;
|
|
162
|
+
|
|
163
|
+
export { useImageLoader, useIsMobile, useMultiImageLoader, useMultiOrderTracking, useOrderTracking, usePagination, usePreviewEmbed, useSliderDrag };
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { useAigentycChat } from './chunk-4FBVV64J.js';
|
|
3
|
+
export { useInteractionTracker } from './chunk-MT2AMINB.js';
|
|
4
|
+
import './chunk-BKDV2H6Z.js';
|
|
5
|
+
export { useIsMobile, useLiveChat, usePreviewEmbed } from './chunk-5F3O3ZJH.js';
|
|
6
|
+
export { useTheme } from './chunk-UKEL7FWS.js';
|
|
7
|
+
import './chunk-MZQKGNWF.js';
|
|
8
|
+
export { useI18n } from './chunk-QYCEHFAB.js';
|
|
9
|
+
export { useChatContext, useSlot, useSlots } from './chunk-FYPJSHCL.js';
|
|
10
|
+
import { useState, useCallback, useMemo, useEffect } from 'react';
|
|
11
|
+
|
|
12
|
+
function useImageLoader() {
|
|
13
|
+
const [loaded, setLoaded] = useState(false);
|
|
14
|
+
const onLoad = useCallback(() => {
|
|
15
|
+
setLoaded(true);
|
|
16
|
+
}, []);
|
|
17
|
+
const reset = useCallback(() => {
|
|
18
|
+
setLoaded(false);
|
|
19
|
+
}, []);
|
|
20
|
+
return { loaded, onLoad, reset };
|
|
21
|
+
}
|
|
22
|
+
function useMultiImageLoader() {
|
|
23
|
+
const [loadedMap, setLoadedMap] = useState(/* @__PURE__ */ new Set());
|
|
24
|
+
const isLoaded = useCallback(
|
|
25
|
+
(key) => loadedMap.has(key),
|
|
26
|
+
[loadedMap]
|
|
27
|
+
);
|
|
28
|
+
const onLoad = useCallback(
|
|
29
|
+
(key) => () => {
|
|
30
|
+
setLoadedMap((prev) => new Set(prev).add(key));
|
|
31
|
+
},
|
|
32
|
+
[]
|
|
33
|
+
);
|
|
34
|
+
const reset = useCallback((key) => {
|
|
35
|
+
setLoadedMap((prev) => {
|
|
36
|
+
const next = new Set(prev);
|
|
37
|
+
next.delete(key);
|
|
38
|
+
return next;
|
|
39
|
+
});
|
|
40
|
+
}, []);
|
|
41
|
+
const resetAll = useCallback(() => {
|
|
42
|
+
setLoadedMap(/* @__PURE__ */ new Set());
|
|
43
|
+
}, []);
|
|
44
|
+
return { isLoaded, onLoad, reset, resetAll };
|
|
45
|
+
}
|
|
46
|
+
function usePagination({
|
|
47
|
+
items,
|
|
48
|
+
itemsPerPage,
|
|
49
|
+
onPageChange
|
|
50
|
+
}) {
|
|
51
|
+
const [page, setPage] = useState(0);
|
|
52
|
+
const totalPages = useMemo(
|
|
53
|
+
() => Math.ceil(items.length / itemsPerPage),
|
|
54
|
+
[items.length, itemsPerPage]
|
|
55
|
+
);
|
|
56
|
+
const currentItems = useMemo(
|
|
57
|
+
() => items.slice(page * itemsPerPage, (page + 1) * itemsPerPage),
|
|
58
|
+
[items, page, itemsPerPage]
|
|
59
|
+
);
|
|
60
|
+
const goNext = useCallback(() => {
|
|
61
|
+
if (page < totalPages - 1) {
|
|
62
|
+
const newPage = page + 1;
|
|
63
|
+
setPage(newPage);
|
|
64
|
+
onPageChange?.("next", newPage, totalPages);
|
|
65
|
+
}
|
|
66
|
+
}, [page, totalPages, onPageChange]);
|
|
67
|
+
const goPrev = useCallback(() => {
|
|
68
|
+
if (page > 0) {
|
|
69
|
+
const newPage = page - 1;
|
|
70
|
+
setPage(newPage);
|
|
71
|
+
onPageChange?.("prev", newPage, totalPages);
|
|
72
|
+
}
|
|
73
|
+
}, [page, totalPages, onPageChange]);
|
|
74
|
+
const goToPage = useCallback(
|
|
75
|
+
(newPage) => {
|
|
76
|
+
if (newPage >= 0 && newPage < totalPages) {
|
|
77
|
+
const direction = newPage > page ? "next" : "prev";
|
|
78
|
+
setPage(newPage);
|
|
79
|
+
onPageChange?.(direction, newPage, totalPages);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[page, totalPages, onPageChange]
|
|
83
|
+
);
|
|
84
|
+
const isFirstPage = page === 0;
|
|
85
|
+
const isLastPage = page >= totalPages - 1;
|
|
86
|
+
return {
|
|
87
|
+
page,
|
|
88
|
+
totalPages,
|
|
89
|
+
currentItems,
|
|
90
|
+
goNext,
|
|
91
|
+
goPrev,
|
|
92
|
+
goToPage,
|
|
93
|
+
isFirstPage,
|
|
94
|
+
isLastPage
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function useSliderDrag({
|
|
98
|
+
containerRef,
|
|
99
|
+
initialPosition = 50,
|
|
100
|
+
minPosition = 0,
|
|
101
|
+
maxPosition = 100
|
|
102
|
+
}) {
|
|
103
|
+
const [sliderPosition, setSliderPosition] = useState(initialPosition);
|
|
104
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
105
|
+
const handleSliderMove = useCallback(
|
|
106
|
+
(clientX) => {
|
|
107
|
+
if (!containerRef.current) return;
|
|
108
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
109
|
+
const x = clientX - rect.left;
|
|
110
|
+
const percentage = Math.max(
|
|
111
|
+
minPosition,
|
|
112
|
+
Math.min(maxPosition, x / rect.width * 100)
|
|
113
|
+
);
|
|
114
|
+
setSliderPosition(percentage);
|
|
115
|
+
},
|
|
116
|
+
[containerRef, minPosition, maxPosition]
|
|
117
|
+
);
|
|
118
|
+
const handleMouseDown = useCallback(() => {
|
|
119
|
+
setIsDragging(true);
|
|
120
|
+
}, []);
|
|
121
|
+
const handleMouseUp = useCallback(() => {
|
|
122
|
+
setIsDragging(false);
|
|
123
|
+
}, []);
|
|
124
|
+
const handleMouseMove = useCallback(
|
|
125
|
+
(e) => {
|
|
126
|
+
if (isDragging) {
|
|
127
|
+
handleSliderMove(e.clientX);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
[isDragging, handleSliderMove]
|
|
131
|
+
);
|
|
132
|
+
const handleTouchMove = useCallback(
|
|
133
|
+
(e) => {
|
|
134
|
+
if (isDragging && e.touches[0]) {
|
|
135
|
+
handleSliderMove(e.touches[0].clientX);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[isDragging, handleSliderMove]
|
|
139
|
+
);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (typeof window === "undefined") return;
|
|
142
|
+
if (isDragging) {
|
|
143
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
144
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
145
|
+
window.addEventListener("touchmove", handleTouchMove);
|
|
146
|
+
window.addEventListener("touchend", handleMouseUp);
|
|
147
|
+
}
|
|
148
|
+
return () => {
|
|
149
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
150
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
151
|
+
window.removeEventListener("touchmove", handleTouchMove);
|
|
152
|
+
window.removeEventListener("touchend", handleMouseUp);
|
|
153
|
+
};
|
|
154
|
+
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove]);
|
|
155
|
+
return {
|
|
156
|
+
sliderPosition,
|
|
157
|
+
isDragging,
|
|
158
|
+
handleMouseDown,
|
|
159
|
+
setSliderPosition
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function useOrderTracking({
|
|
163
|
+
productId
|
|
164
|
+
}) {
|
|
165
|
+
const [orderStatus, setOrderStatus] = useState("idle");
|
|
166
|
+
const [orderError, setOrderError] = useState(null);
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (typeof window === "undefined" || !productId) return;
|
|
169
|
+
const handleOrderComplete = (e) => {
|
|
170
|
+
const customEvent = e;
|
|
171
|
+
const { success, product_id, error } = customEvent.detail || {};
|
|
172
|
+
if (product_id === productId) {
|
|
173
|
+
if (success) {
|
|
174
|
+
setOrderStatus("added");
|
|
175
|
+
setOrderError(null);
|
|
176
|
+
} else {
|
|
177
|
+
setOrderStatus("error");
|
|
178
|
+
setOrderError(error || "Failed to add to cart");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
window.addEventListener(
|
|
183
|
+
"caesarstone:order-sample-complete",
|
|
184
|
+
handleOrderComplete
|
|
185
|
+
);
|
|
186
|
+
return () => {
|
|
187
|
+
window.removeEventListener(
|
|
188
|
+
"caesarstone:order-sample-complete",
|
|
189
|
+
handleOrderComplete
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
}, [productId]);
|
|
193
|
+
const startOrder = useCallback(() => {
|
|
194
|
+
setOrderStatus("pending");
|
|
195
|
+
setOrderError(null);
|
|
196
|
+
}, []);
|
|
197
|
+
const reset = useCallback(() => {
|
|
198
|
+
setOrderStatus("idle");
|
|
199
|
+
setOrderError(null);
|
|
200
|
+
}, []);
|
|
201
|
+
return { orderStatus, orderError, startOrder, reset };
|
|
202
|
+
}
|
|
203
|
+
function useMultiOrderTracking() {
|
|
204
|
+
const [statusMap, setStatusMap] = useState(
|
|
205
|
+
/* @__PURE__ */ new Map()
|
|
206
|
+
);
|
|
207
|
+
const [errorMap, setErrorMap] = useState(/* @__PURE__ */ new Map());
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (typeof window === "undefined") return;
|
|
210
|
+
const handleOrderComplete = (e) => {
|
|
211
|
+
const customEvent = e;
|
|
212
|
+
const { success, product_id, error } = customEvent.detail || {};
|
|
213
|
+
if (product_id) {
|
|
214
|
+
if (success) {
|
|
215
|
+
setStatusMap((prev) => new Map(prev).set(product_id, "added"));
|
|
216
|
+
setErrorMap((prev) => {
|
|
217
|
+
const next = new Map(prev);
|
|
218
|
+
next.delete(product_id);
|
|
219
|
+
return next;
|
|
220
|
+
});
|
|
221
|
+
} else {
|
|
222
|
+
setStatusMap((prev) => new Map(prev).set(product_id, "error"));
|
|
223
|
+
setErrorMap(
|
|
224
|
+
(prev) => new Map(prev).set(product_id, error || "Failed to add to cart")
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
window.addEventListener(
|
|
230
|
+
"caesarstone:order-sample-complete",
|
|
231
|
+
handleOrderComplete
|
|
232
|
+
);
|
|
233
|
+
return () => {
|
|
234
|
+
window.removeEventListener(
|
|
235
|
+
"caesarstone:order-sample-complete",
|
|
236
|
+
handleOrderComplete
|
|
237
|
+
);
|
|
238
|
+
};
|
|
239
|
+
}, []);
|
|
240
|
+
const getStatus = useCallback(
|
|
241
|
+
(productId) => statusMap.get(productId) || "idle",
|
|
242
|
+
[statusMap]
|
|
243
|
+
);
|
|
244
|
+
const getError = useCallback(
|
|
245
|
+
(productId) => errorMap.get(productId),
|
|
246
|
+
[errorMap]
|
|
247
|
+
);
|
|
248
|
+
const startOrder = useCallback((productId) => {
|
|
249
|
+
setStatusMap((prev) => new Map(prev).set(productId, "pending"));
|
|
250
|
+
setErrorMap((prev) => {
|
|
251
|
+
const next = new Map(prev);
|
|
252
|
+
next.delete(productId);
|
|
253
|
+
return next;
|
|
254
|
+
});
|
|
255
|
+
}, []);
|
|
256
|
+
const reset = useCallback((productId) => {
|
|
257
|
+
setStatusMap((prev) => {
|
|
258
|
+
const next = new Map(prev);
|
|
259
|
+
next.delete(productId);
|
|
260
|
+
return next;
|
|
261
|
+
});
|
|
262
|
+
setErrorMap((prev) => {
|
|
263
|
+
const next = new Map(prev);
|
|
264
|
+
next.delete(productId);
|
|
265
|
+
return next;
|
|
266
|
+
});
|
|
267
|
+
}, []);
|
|
268
|
+
const resetAll = useCallback(() => {
|
|
269
|
+
setStatusMap(/* @__PURE__ */ new Map());
|
|
270
|
+
setErrorMap(/* @__PURE__ */ new Map());
|
|
271
|
+
}, []);
|
|
272
|
+
return { getStatus, getError, startOrder, reset, resetAll };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export { useImageLoader, useMultiImageLoader, useMultiOrderTracking, useOrderTracking, usePagination, useSliderDrag };
|
|
276
|
+
//# sourceMappingURL=hooks.js.map
|
|
277
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-image-loader.ts","../src/hooks/use-pagination.ts","../src/hooks/use-slider-drag.ts","../src/hooks/use-order-tracking.ts"],"names":["useState","useCallback","useEffect"],"mappings":";;;;;;;;;;AAgBO,SAAS,cAAA,GAAuC;AACrD,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAS,KAAK,CAAA;AAE1C,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM;AAC/B,IAAA,SAAA,CAAU,IA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MAAA,OAAO,IAAA;AAAA,IACT,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,KAAA,GAAQA,WAAAA,CAAY,CAAC,SAAA,KAAsB;AAC/C,IAAA,YAAA,CAAa,CAAC,IAAA,KAAS;AACrB,MAAA,MAAM,IAAA,GAAO,IAAI,GAAA,CAAI,IAAI,CAAA;AACzB,MAAA,IAAA,CAAK,OAAO,SAAS,CAAA;AACrB,MAAA,OAAO,IAAA;AAAA,IACT,CAAC,CAAA;AACD,IAAA,WAAA,CAAY,CAAC,IAAA,KAAS;AACpB,MAAA,MAAM,IAAA,GAAO,IAAI,GAAA,CAAI,IAAI,CAAA;AACzB,MAAA,IAAA,CAAK,OAAO,SAAS,CAAA;AACrB,MAAA,OAAO,IAAA;AAAA,IACT,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,QAAA,GAAWA,YAAY,MAAM;AACjC,IAAA,YAAA,iBAAa,IAAI,KAAK,CAAA;AACtB,IAAA,WAAA,iBAAY,IAAI,KAAK,CAAA;AAAA,EACvB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO,EAAE,SAAA,EAAW,QAAA,EAAU,UAAA,EAAY,OAAO,QAAA,EAAS;AAC5D","file":"hooks.js","sourcesContent":["\"use client\";\n\nimport { useState, useCallback } from \"react\";\n\ninterface UseImageLoaderReturn {\n /** Whether the image has finished loading. */\n loaded: boolean;\n /** Callback to set loaded state to true. Pass as `onLoad` to an `<img>`. */\n onLoad: () => void;\n /** Reset loaded state to false. */\n reset: () => void;\n}\n\n/**\n * Tracks load state for a single image element.\n */\nexport function useImageLoader(): UseImageLoaderReturn {\n const [loaded, setLoaded] = useState(false);\n\n const onLoad = useCallback(() => {\n setLoaded(true);\n }, []);\n\n const reset = useCallback(() => {\n setLoaded(false);\n }, []);\n\n return { loaded, onLoad, reset };\n}\n\ninterface UseMultiImageLoaderReturn {\n /** Check if a specific image has loaded. */\n isLoaded: (key: string) => boolean;\n /** Returns a callback for the given key to mark it as loaded. */\n onLoad: (key: string) => () => void;\n /** Reset a specific image's loaded state. */\n reset: (key: string) => void;\n /** Reset all images' loaded states. */\n resetAll: () => void;\n}\n\n/**\n * Tracks load state for multiple images by key.\n */\nexport function useMultiImageLoader(): UseMultiImageLoaderReturn {\n const [loadedMap, setLoadedMap] = useState<Set<string>>(new Set());\n\n const isLoaded = useCallback(\n (key: string) => loadedMap.has(key),\n [loadedMap]\n );\n\n const onLoad = useCallback(\n (key: string) => () => {\n setLoadedMap((prev) => new Set(prev).add(key));\n },\n []\n );\n\n const reset = useCallback((key: string) => {\n setLoadedMap((prev) => {\n const next = new Set(prev);\n next.delete(key);\n return next;\n });\n }, []);\n\n const resetAll = useCallback(() => {\n setLoadedMap(new Set());\n }, []);\n\n return { isLoaded, onLoad, reset, resetAll };\n}\n","\"use client\";\n\nimport { useState, useMemo, useCallback } from \"react\";\n\ninterface UsePaginationOptions<T> {\n /** The full list of items to paginate. */\n items: T[];\n /** Number of items per page. */\n itemsPerPage: number;\n /** Optional callback when the page changes. */\n onPageChange?: (\n direction: \"next\" | \"prev\",\n newPage: number,\n totalPages: number\n ) => void;\n}\n\ninterface UsePaginationReturn<T> {\n /** Current page index (0-based). */\n page: number;\n /** Total number of pages. */\n totalPages: number;\n /** Items for the current page. */\n currentItems: T[];\n /** Go to the next page. */\n goNext: () => void;\n /** Go to the previous page. */\n goPrev: () => void;\n /** Go to a specific page (0-based). */\n goToPage: (page: number) => void;\n /** Whether the current page is the first page. */\n isFirstPage: boolean;\n /** Whether the current page is the last page. */\n isLastPage: boolean;\n}\n\n/**\n * Generic pagination hook for any list of items.\n */\nexport function usePagination<T>({\n items,\n itemsPerPage,\n onPageChange,\n}: UsePaginationOptions<T>): UsePaginationReturn<T> {\n const [page, setPage] = useState(0);\n\n const totalPages = useMemo(\n () => Math.ceil(items.length / itemsPerPage),\n [items.length, itemsPerPage]\n );\n\n const currentItems = useMemo(\n () => items.slice(page * itemsPerPage, (page + 1) * itemsPerPage),\n [items, page, itemsPerPage]\n );\n\n const goNext = useCallback(() => {\n if (page < totalPages - 1) {\n const newPage = page + 1;\n setPage(newPage);\n onPageChange?.(\"next\", newPage, totalPages);\n }\n }, [page, totalPages, onPageChange]);\n\n const goPrev = useCallback(() => {\n if (page > 0) {\n const newPage = page - 1;\n setPage(newPage);\n onPageChange?.(\"prev\", newPage, totalPages);\n }\n }, [page, totalPages, onPageChange]);\n\n const goToPage = useCallback(\n (newPage: number) => {\n if (newPage >= 0 && newPage < totalPages) {\n const direction = newPage > page ? \"next\" : \"prev\";\n setPage(newPage);\n onPageChange?.(direction, newPage, totalPages);\n }\n },\n [page, totalPages, onPageChange]\n );\n\n const isFirstPage = page === 0;\n const isLastPage = page >= totalPages - 1;\n\n return {\n page,\n totalPages,\n currentItems,\n goNext,\n goPrev,\n goToPage,\n isFirstPage,\n isLastPage,\n };\n}\n","\"use client\";\n\nimport { useState, useEffect, useCallback, type RefObject } from \"react\";\n\ninterface UseSliderDragOptions {\n /** Ref to the container element. */\n containerRef: RefObject<HTMLDivElement | null>;\n /** Initial slider position as a percentage (0-100). Defaults to 50. */\n initialPosition?: number;\n /** Minimum allowed position. Defaults to 0. */\n minPosition?: number;\n /** Maximum allowed position. Defaults to 100. */\n maxPosition?: number;\n}\n\ninterface UseSliderDragReturn {\n /** Current slider position as a percentage (0-100). */\n sliderPosition: number;\n /** Whether the user is currently dragging. */\n isDragging: boolean;\n /** Call this on mousedown/touchstart to begin dragging. */\n handleMouseDown: () => void;\n /** Programmatically set the slider position. */\n setSliderPosition: (position: number) => void;\n}\n\n/**\n * Handles mouse and touch drag interactions for a horizontal slider.\n * SSR-safe: event listeners are only attached in the browser.\n */\nexport function useSliderDrag({\n containerRef,\n initialPosition = 50,\n minPosition = 0,\n maxPosition = 100,\n}: UseSliderDragOptions): UseSliderDragReturn {\n const [sliderPosition, setSliderPosition] = useState(initialPosition);\n const [isDragging, setIsDragging] = useState(false);\n\n const handleSliderMove = useCallback(\n (clientX: number) => {\n if (!containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n const x = clientX - rect.left;\n const percentage = Math.max(\n minPosition,\n Math.min(maxPosition, (x / rect.width) * 100)\n );\n setSliderPosition(percentage);\n },\n [containerRef, minPosition, maxPosition]\n );\n\n const handleMouseDown = useCallback(() => {\n setIsDragging(true);\n }, []);\n\n const handleMouseUp = useCallback(() => {\n setIsDragging(false);\n }, []);\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (isDragging) {\n handleSliderMove(e.clientX);\n }\n },\n [isDragging, handleSliderMove]\n );\n\n const handleTouchMove = useCallback(\n (e: TouchEvent) => {\n if (isDragging && e.touches[0]) {\n handleSliderMove(e.touches[0].clientX);\n }\n },\n [isDragging, handleSliderMove]\n );\n\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n\n if (isDragging) {\n window.addEventListener(\"mousemove\", handleMouseMove);\n window.addEventListener(\"mouseup\", handleMouseUp);\n window.addEventListener(\"touchmove\", handleTouchMove);\n window.addEventListener(\"touchend\", handleMouseUp);\n }\n return () => {\n window.removeEventListener(\"mousemove\", handleMouseMove);\n window.removeEventListener(\"mouseup\", handleMouseUp);\n window.removeEventListener(\"touchmove\", handleTouchMove);\n window.removeEventListener(\"touchend\", handleMouseUp);\n };\n }, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove]);\n\n return {\n sliderPosition,\n isDragging,\n handleMouseDown,\n setSliderPosition,\n };\n}\n","\"use client\";\n\nimport { useState, useEffect, useCallback } from \"react\";\n\ntype OrderStatus = \"idle\" | \"pending\" | \"added\" | \"error\";\n\ninterface UseOrderTrackingOptions {\n /** Product ID to track. */\n productId?: string;\n}\n\ninterface UseOrderTrackingReturn {\n /** Current order status. */\n orderStatus: OrderStatus;\n /** Error message if status is \"error\". */\n orderError: string | null;\n /** Mark the order as pending. */\n startOrder: () => void;\n /** Reset to idle state. */\n reset: () => void;\n}\n\n/**\n * Tracks a single product order status via the `caesarstone:order-sample-complete` custom event.\n * SSR-safe: event listeners are only attached in the browser.\n */\nexport function useOrderTracking({\n productId,\n}: UseOrderTrackingOptions): UseOrderTrackingReturn {\n const [orderStatus, setOrderStatus] = useState<OrderStatus>(\"idle\");\n const [orderError, setOrderError] = useState<string | null>(null);\n\n useEffect(() => {\n if (typeof window === \"undefined\" || !productId) return;\n\n const handleOrderComplete = (e: Event) => {\n const customEvent = e as CustomEvent<{\n success: boolean;\n product_id: string;\n error?: string;\n }>;\n const { success, product_id, error } = customEvent.detail || {};\n\n if (product_id === productId) {\n if (success) {\n setOrderStatus(\"added\");\n setOrderError(null);\n } else {\n setOrderStatus(\"error\");\n setOrderError(error || \"Failed to add to cart\");\n }\n }\n };\n\n window.addEventListener(\n \"caesarstone:order-sample-complete\",\n handleOrderComplete\n );\n return () => {\n window.removeEventListener(\n \"caesarstone:order-sample-complete\",\n handleOrderComplete\n );\n };\n }, [productId]);\n\n const startOrder = useCallback(() => {\n setOrderStatus(\"pending\");\n setOrderError(null);\n }, []);\n\n const reset = useCallback(() => {\n setOrderStatus(\"idle\");\n setOrderError(null);\n }, []);\n\n return { orderStatus, orderError, startOrder, reset };\n}\n\ninterface UseMultiOrderTrackingReturn {\n /** Get status for a specific product. */\n getStatus: (productId: string) => OrderStatus;\n /** Get error message for a specific product. */\n getError: (productId: string) => string | undefined;\n /** Mark a product order as pending. */\n startOrder: (productId: string) => void;\n /** Reset a specific product's order status. */\n reset: (productId: string) => void;\n /** Reset all tracked products. */\n resetAll: () => void;\n}\n\n/**\n * Tracks multiple product order statuses via the `caesarstone:order-sample-complete` custom event.\n * SSR-safe: event listeners are only attached in the browser.\n */\nexport function useMultiOrderTracking(): UseMultiOrderTrackingReturn {\n const [statusMap, setStatusMap] = useState<Map<string, OrderStatus>>(\n new Map()\n );\n const [errorMap, setErrorMap] = useState<Map<string, string>>(new Map());\n\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n\n const handleOrderComplete = (e: Event) => {\n const customEvent = e as CustomEvent<{\n success: boolean;\n product_id: string;\n error?: string;\n }>;\n const { success, product_id, error } = customEvent.detail || {};\n\n if (product_id) {\n if (success) {\n setStatusMap((prev) => new Map(prev).set(product_id, \"added\"));\n setErrorMap((prev) => {\n const next = new Map(prev);\n next.delete(product_id);\n return next;\n });\n } else {\n setStatusMap((prev) => new Map(prev).set(product_id, \"error\"));\n setErrorMap((prev) =>\n new Map(prev).set(product_id, error || \"Failed to add to cart\")\n );\n }\n }\n };\n\n window.addEventListener(\n \"caesarstone:order-sample-complete\",\n handleOrderComplete\n );\n return () => {\n window.removeEventListener(\n \"caesarstone:order-sample-complete\",\n handleOrderComplete\n );\n };\n }, []);\n\n const getStatus = useCallback(\n (productId: string) => statusMap.get(productId) || \"idle\",\n [statusMap]\n );\n\n const getError = useCallback(\n (productId: string) => errorMap.get(productId),\n [errorMap]\n );\n\n const startOrder = useCallback((productId: string) => {\n setStatusMap((prev) => new Map(prev).set(productId, \"pending\"));\n setErrorMap((prev) => {\n const next = new Map(prev);\n next.delete(productId);\n return next;\n });\n }, []);\n\n const reset = useCallback((productId: string) => {\n setStatusMap((prev) => {\n const next = new Map(prev);\n next.delete(productId);\n return next;\n });\n setErrorMap((prev) => {\n const next = new Map(prev);\n next.delete(productId);\n return next;\n });\n }, []);\n\n const resetAll = useCallback(() => {\n setStatusMap(new Map());\n setErrorMap(new Map());\n }, []);\n\n return { getStatus, getError, startOrder, reset, resetAll };\n}\n"]}
|
package/dist/i18n.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
require('./chunk-X7R334SB.cjs');
|
|
5
|
+
var chunk3MP2EGEJ_cjs = require('./chunk-3MP2EGEJ.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "I18nProvider", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunk3MP2EGEJ_cjs.I18nProvider; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "addLanguage", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunk3MP2EGEJ_cjs.addLanguage; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "isRTL", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunk3MP2EGEJ_cjs.isRTL; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "useI18n", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunk3MP2EGEJ_cjs.useI18n; }
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=i18n.cjs.map
|
|
26
|
+
//# sourceMappingURL=i18n.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"i18n.cjs"}
|
package/dist/i18n.d.cts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export { L as Language } from './types-DKJ_-nbG.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* All supported translation keys.
|
|
7
|
+
*/
|
|
8
|
+
type TranslationKeys = "welcomeTitle" | "welcomeSubtitle" | "searchKnowledgeBase" | "searchingFor" | "processing" | "thinking" | "newConversation" | "backToStart" | "closeChat" | "alwaysVerify" | "poweredBy" | "startNewConversation" | "somethingWentWrong" | "conversationTooLong" | "conversationTooLongDesc" | "somethingWentWrongDesc" | "typeMessage" | "send" | "aboutUs" | "aboutUsDesc" | "support" | "supportDesc" | "features" | "featuresDesc" | "search" | "searchDesc" | "greeting" | "guest" | "guestDesc" | "customer" | "customerDesc" | "partner" | "partnerDesc" | "aboutUsQuery" | "supportQuery" | "featuresQuery" | "searchQuery" | "whatWentWrong" | "wrongAnswer" | "partialAnswer" | "hallucination" | "inappropriateTone" | "addDetails" | "submitting" | "submitFeedback" | "helpful" | "notHelpful" | "copyResponse" | "searchingProducts" | "searchingProductsFor" | "sendingVerification" | "verifyingOrders" | "generatingLogin" | "noProductsFound" | "noOrdersFound" | "inStock" | "outOfStock" | "backorder" | "sale" | "addToCart" | "addedToCart" | "addToCartError" | "loginToStore" | "enterEmail" | "sendCode" | "otpSentTo" | "verifyCode" | "verifiedSuccess" | "resendCode" | "invalidCode" | "selectVariation" | "orderStatus_completed" | "orderStatus_processing" | "orderStatus_on-hold" | "orderStatus_pending" | "orderStatus_cancelled" | "orderStatus_failed" | "orderStatus_refunded" | "cart" | "yourCart" | "cartItems" | "cartEmpty" | "checkout" | "cartTotal" | "removeItem" | "liveChatConnecting" | "liveChatPosition" | "liveChatCancel" | "liveChatChattingWith" | "liveChatEndChat" | "liveChatRateTitle" | "liveChatRateThank" | "liveChatBackToAI" | "liveChatSubmit" | "liveChatSkip" | "liveChatFeedbackPlaceholder" | "liveChatTalkToHuman" | "liveChatIdentityTitle" | "liveChatIdentityName" | "liveChatIdentityEmail" | "liveChatIdentityConnect" | "liveChatIdentityContinue" | "liveChatRateExperience" | "liveChatEnded";
|
|
9
|
+
/** A complete set of translations for a language. */
|
|
10
|
+
type TranslationMap = Record<TranslationKeys, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Register a new language at runtime. Merges with any existing translations.
|
|
13
|
+
*
|
|
14
|
+
* @param code - Language code (e.g. "fr", "es")
|
|
15
|
+
* @param translations - Full or partial translation map
|
|
16
|
+
*/
|
|
17
|
+
declare function addLanguage(code: string, translations: Partial<TranslationMap>): void;
|
|
18
|
+
/** Returns true if the given language code is RTL. */
|
|
19
|
+
declare function isRTL(language: string): boolean;
|
|
20
|
+
interface I18nContextValue {
|
|
21
|
+
/** Translate a key, with optional interpolation params. */
|
|
22
|
+
t: (key: TranslationKeys, params?: Record<string, string>) => string;
|
|
23
|
+
/** Current language code. */
|
|
24
|
+
language: string;
|
|
25
|
+
/** Change the active language at runtime. */
|
|
26
|
+
setLanguage: (lang: string) => void;
|
|
27
|
+
/** Current text direction. */
|
|
28
|
+
direction: "ltr" | "rtl";
|
|
29
|
+
}
|
|
30
|
+
/** Props for the I18nProvider component. */
|
|
31
|
+
interface I18nProviderProps {
|
|
32
|
+
/** Active language code. Defaults to "en". */
|
|
33
|
+
language?: string;
|
|
34
|
+
/** Per-key translation overrides applied on top of built-in strings. */
|
|
35
|
+
translations?: Partial<TranslationMap>;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Provides i18n context to descendant components.
|
|
40
|
+
* Supports built-in "en" and "he", dynamic languages via `addLanguage()`,
|
|
41
|
+
* and per-instance overrides via the `translations` prop.
|
|
42
|
+
*/
|
|
43
|
+
declare function I18nProvider({ language: initialLanguage, translations: overrides, children, }: I18nProviderProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the i18n context: `t()` translation function, current language, and `setLanguage`.
|
|
46
|
+
* Must be used within an `I18nProvider`.
|
|
47
|
+
*/
|
|
48
|
+
declare function useI18n(): I18nContextValue;
|
|
49
|
+
|
|
50
|
+
export { I18nProvider, type I18nProviderProps, type TranslationKeys, type TranslationMap, addLanguage, isRTL, useI18n };
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export { L as Language } from './types-DKJ_-nbG.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* All supported translation keys.
|
|
7
|
+
*/
|
|
8
|
+
type TranslationKeys = "welcomeTitle" | "welcomeSubtitle" | "searchKnowledgeBase" | "searchingFor" | "processing" | "thinking" | "newConversation" | "backToStart" | "closeChat" | "alwaysVerify" | "poweredBy" | "startNewConversation" | "somethingWentWrong" | "conversationTooLong" | "conversationTooLongDesc" | "somethingWentWrongDesc" | "typeMessage" | "send" | "aboutUs" | "aboutUsDesc" | "support" | "supportDesc" | "features" | "featuresDesc" | "search" | "searchDesc" | "greeting" | "guest" | "guestDesc" | "customer" | "customerDesc" | "partner" | "partnerDesc" | "aboutUsQuery" | "supportQuery" | "featuresQuery" | "searchQuery" | "whatWentWrong" | "wrongAnswer" | "partialAnswer" | "hallucination" | "inappropriateTone" | "addDetails" | "submitting" | "submitFeedback" | "helpful" | "notHelpful" | "copyResponse" | "searchingProducts" | "searchingProductsFor" | "sendingVerification" | "verifyingOrders" | "generatingLogin" | "noProductsFound" | "noOrdersFound" | "inStock" | "outOfStock" | "backorder" | "sale" | "addToCart" | "addedToCart" | "addToCartError" | "loginToStore" | "enterEmail" | "sendCode" | "otpSentTo" | "verifyCode" | "verifiedSuccess" | "resendCode" | "invalidCode" | "selectVariation" | "orderStatus_completed" | "orderStatus_processing" | "orderStatus_on-hold" | "orderStatus_pending" | "orderStatus_cancelled" | "orderStatus_failed" | "orderStatus_refunded" | "cart" | "yourCart" | "cartItems" | "cartEmpty" | "checkout" | "cartTotal" | "removeItem" | "liveChatConnecting" | "liveChatPosition" | "liveChatCancel" | "liveChatChattingWith" | "liveChatEndChat" | "liveChatRateTitle" | "liveChatRateThank" | "liveChatBackToAI" | "liveChatSubmit" | "liveChatSkip" | "liveChatFeedbackPlaceholder" | "liveChatTalkToHuman" | "liveChatIdentityTitle" | "liveChatIdentityName" | "liveChatIdentityEmail" | "liveChatIdentityConnect" | "liveChatIdentityContinue" | "liveChatRateExperience" | "liveChatEnded";
|
|
9
|
+
/** A complete set of translations for a language. */
|
|
10
|
+
type TranslationMap = Record<TranslationKeys, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Register a new language at runtime. Merges with any existing translations.
|
|
13
|
+
*
|
|
14
|
+
* @param code - Language code (e.g. "fr", "es")
|
|
15
|
+
* @param translations - Full or partial translation map
|
|
16
|
+
*/
|
|
17
|
+
declare function addLanguage(code: string, translations: Partial<TranslationMap>): void;
|
|
18
|
+
/** Returns true if the given language code is RTL. */
|
|
19
|
+
declare function isRTL(language: string): boolean;
|
|
20
|
+
interface I18nContextValue {
|
|
21
|
+
/** Translate a key, with optional interpolation params. */
|
|
22
|
+
t: (key: TranslationKeys, params?: Record<string, string>) => string;
|
|
23
|
+
/** Current language code. */
|
|
24
|
+
language: string;
|
|
25
|
+
/** Change the active language at runtime. */
|
|
26
|
+
setLanguage: (lang: string) => void;
|
|
27
|
+
/** Current text direction. */
|
|
28
|
+
direction: "ltr" | "rtl";
|
|
29
|
+
}
|
|
30
|
+
/** Props for the I18nProvider component. */
|
|
31
|
+
interface I18nProviderProps {
|
|
32
|
+
/** Active language code. Defaults to "en". */
|
|
33
|
+
language?: string;
|
|
34
|
+
/** Per-key translation overrides applied on top of built-in strings. */
|
|
35
|
+
translations?: Partial<TranslationMap>;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Provides i18n context to descendant components.
|
|
40
|
+
* Supports built-in "en" and "he", dynamic languages via `addLanguage()`,
|
|
41
|
+
* and per-instance overrides via the `translations` prop.
|
|
42
|
+
*/
|
|
43
|
+
declare function I18nProvider({ language: initialLanguage, translations: overrides, children, }: I18nProviderProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the i18n context: `t()` translation function, current language, and `setLanguage`.
|
|
46
|
+
* Must be used within an `I18nProvider`.
|
|
47
|
+
*/
|
|
48
|
+
declare function useI18n(): I18nContextValue;
|
|
49
|
+
|
|
50
|
+
export { I18nProvider, type I18nProviderProps, type TranslationKeys, type TranslationMap, addLanguage, isRTL, useI18n };
|
package/dist/i18n.js
ADDED
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"i18n.js"}
|