@pelatform/ui 1.6.0 → 2.0.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/css/source.css +20 -0
- package/css/theme.css +1 -2
- package/dist/animation.d.ts +4 -379
- package/dist/animation.js +2 -1752
- package/dist/aria.d.ts +1 -31
- package/dist/aria.js +2 -139
- package/dist/base.d.ts +1 -651
- package/dist/base.js +2 -5556
- package/dist/chunk-UEVIEY7W.js +51 -0
- package/dist/{components.cjs → chunk-VZEE3GOC.js} +81 -2344
- package/dist/components.d.ts +224 -181
- package/dist/components.js +364 -765
- package/dist/default.d.ts +1 -1322
- package/dist/default.js +2 -8931
- package/dist/hooks.d.ts +4 -1083
- package/dist/hooks.js +5 -662
- package/dist/index.d.ts +58 -308
- package/dist/index.js +5 -226
- package/package.json +25 -105
- package/dist/animation.cjs +0 -1752
- package/dist/animation.d.cts +0 -379
- package/dist/aria.cjs +0 -139
- package/dist/aria.d.cts +0 -31
- package/dist/badge-BtI4BMea.d.cts +0 -33
- package/dist/badge-BtI4BMea.d.ts +0 -33
- package/dist/base.cjs +0 -5556
- package/dist/base.d.cts +0 -651
- package/dist/chunk-3N75YA6Q.cjs +0 -60
- package/dist/chunk-7472NIIL.cjs +0 -40
- package/dist/chunk-BXUKTDPN.cjs +0 -576
- package/dist/chunk-CD2BCCQU.js +0 -180
- package/dist/chunk-CJXIPSTG.cjs +0 -10
- package/dist/chunk-CTHRAJQZ.js +0 -1522
- package/dist/chunk-D373YKDA.js +0 -196
- package/dist/chunk-EZW5GNS4.js +0 -6
- package/dist/chunk-HILACSFA.cjs +0 -1522
- package/dist/chunk-HR3R6KKM.js +0 -40
- package/dist/chunk-HW52LCWN.js +0 -22
- package/dist/chunk-I46SELBA.cjs +0 -22
- package/dist/chunk-J4JGE3U5.cjs +0 -180
- package/dist/chunk-RQHJBTEU.js +0 -10
- package/dist/chunk-SK6SSJHC.js +0 -9
- package/dist/chunk-T74DBLYY.js +0 -60
- package/dist/chunk-TB6DU23O.js +0 -576
- package/dist/chunk-UP53DCYH.cjs +0 -6
- package/dist/chunk-ZBO5IAMA.cjs +0 -196
- package/dist/chunk-ZDR3OZ7Z.cjs +0 -9
- package/dist/colors-CUDWvz1g.d.cts +0 -42
- package/dist/colors-CUDWvz1g.d.ts +0 -42
- package/dist/components-CidsRcc3.d.cts +0 -46
- package/dist/components-CidsRcc3.d.ts +0 -46
- package/dist/components.d.cts +0 -2944
- package/dist/default.cjs +0 -8931
- package/dist/default.d.cts +0 -1322
- package/dist/hooks.cjs +0 -666
- package/dist/hooks.d.cts +0 -1172
- package/dist/index.cjs +0 -230
- package/dist/index.d.cts +0 -318
- package/dist/input-AwYIskrX.d.cts +0 -22
- package/dist/input-AwYIskrX.d.ts +0 -22
- package/dist/menu-GmSRfRGB.d.cts +0 -43
- package/dist/menu-GmSRfRGB.d.ts +0 -43
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
- package/dist/re-export/cva.cjs +0 -6
- package/dist/re-export/cva.d.cts +0 -10
- package/dist/re-export/cva.d.ts +0 -10
- package/dist/re-export/cva.js +0 -6
- package/dist/re-export/motion.cjs +0 -2
- package/dist/re-export/motion.d.cts +0 -1
- package/dist/re-export/motion.d.ts +0 -1
- package/dist/re-export/motion.js +0 -2
- package/dist/re-export/next-themes.cjs +0 -2
- package/dist/re-export/next-themes.d.cts +0 -1
- package/dist/re-export/next-themes.d.ts +0 -1
- package/dist/re-export/next-themes.js +0 -2
- package/dist/re-export/react-day-picker.cjs +0 -2
- package/dist/re-export/react-day-picker.d.cts +0 -1
- package/dist/re-export/react-day-picker.d.ts +0 -1
- package/dist/re-export/react-day-picker.js +0 -2
- package/dist/re-export/react-hook-form.cjs +0 -2
- package/dist/re-export/react-hook-form.d.cts +0 -1
- package/dist/re-export/react-hook-form.d.ts +0 -1
- package/dist/re-export/react-hook-form.js +0 -2
- package/dist/re-export/resolver.cjs +0 -2
- package/dist/re-export/resolver.d.cts +0 -1
- package/dist/re-export/resolver.d.ts +0 -1
- package/dist/re-export/resolver.js +0 -2
- package/dist/re-export/sonner.cjs +0 -2
- package/dist/re-export/sonner.d.cts +0 -1
- package/dist/re-export/sonner.d.ts +0 -1
- package/dist/re-export/sonner.js +0 -2
- package/dist/re-export/tanstack-query.cjs +0 -2
- package/dist/re-export/tanstack-query.d.cts +0 -1
- package/dist/re-export/tanstack-query.d.ts +0 -1
- package/dist/re-export/tanstack-query.js +0 -2
- package/dist/re-export/tanstack-table.cjs +0 -2
- package/dist/re-export/tanstack-table.d.cts +0 -1
- package/dist/re-export/tanstack-table.d.ts +0 -1
- package/dist/re-export/tanstack-table.js +0 -2
- package/dist/re-export/zod.cjs +0 -2
- package/dist/re-export/zod.d.cts +0 -1
- package/dist/re-export/zod.d.ts +0 -1
- package/dist/re-export/zod.js +0 -2
package/dist/hooks.js
CHANGED
|
@@ -1,666 +1,9 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./chunk-SK6SSJHC.js";
|
|
6
|
-
import {
|
|
7
|
-
useMetaColor,
|
|
8
|
-
useRecaptchaV2
|
|
9
|
-
} from "./chunk-CD2BCCQU.js";
|
|
10
|
-
import {
|
|
11
|
-
useCopyToClipboard,
|
|
12
|
-
useIsMobile
|
|
13
|
-
} from "./chunk-T74DBLYY.js";
|
|
14
|
-
import "./chunk-HW52LCWN.js";
|
|
15
|
-
|
|
16
|
-
// src/hooks/use-analytics.ts
|
|
17
|
-
import { useCallback } from "react";
|
|
18
|
-
var useAnalytics = () => {
|
|
19
|
-
const trackEvent = useCallback(
|
|
20
|
-
({
|
|
21
|
-
event_name,
|
|
22
|
-
module,
|
|
23
|
-
submodule,
|
|
24
|
-
item_type,
|
|
25
|
-
item_id,
|
|
26
|
-
action,
|
|
27
|
-
delete_type
|
|
28
|
-
}) => {
|
|
29
|
-
if (typeof window !== "undefined" && window.gtag) {
|
|
30
|
-
window.gtag("event", event_name, {
|
|
31
|
-
module,
|
|
32
|
-
submodule,
|
|
33
|
-
module_path: `${module}/${submodule}`,
|
|
34
|
-
item_type,
|
|
35
|
-
item_id,
|
|
36
|
-
action,
|
|
37
|
-
delete_type,
|
|
38
|
-
category: "crud",
|
|
39
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
[]
|
|
44
|
-
);
|
|
45
|
-
const trackCreate = useCallback(
|
|
46
|
-
(module, submodule, itemType, itemId) => {
|
|
47
|
-
trackEvent({
|
|
48
|
-
event_name: "crud_create",
|
|
49
|
-
module,
|
|
50
|
-
submodule,
|
|
51
|
-
item_type: itemType,
|
|
52
|
-
item_id: itemId,
|
|
53
|
-
action: "create"
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
[trackEvent]
|
|
57
|
-
);
|
|
58
|
-
const trackUpdate = useCallback(
|
|
59
|
-
(module, submodule, itemType, itemId) => {
|
|
60
|
-
trackEvent({
|
|
61
|
-
event_name: "crud_update",
|
|
62
|
-
module,
|
|
63
|
-
submodule,
|
|
64
|
-
item_type: itemType,
|
|
65
|
-
item_id: itemId,
|
|
66
|
-
action: "update"
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
[trackEvent]
|
|
70
|
-
);
|
|
71
|
-
const trackDelete = useCallback(
|
|
72
|
-
(module, submodule, itemType, itemId, isHardDelete = false) => {
|
|
73
|
-
trackEvent({
|
|
74
|
-
event_name: "crud_delete",
|
|
75
|
-
module,
|
|
76
|
-
submodule,
|
|
77
|
-
item_type: itemType,
|
|
78
|
-
item_id: itemId,
|
|
79
|
-
action: "delete",
|
|
80
|
-
delete_type: isHardDelete ? "hard" : "soft"
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
[trackEvent]
|
|
84
|
-
);
|
|
85
|
-
return {
|
|
86
|
-
trackCreate,
|
|
87
|
-
trackUpdate,
|
|
88
|
-
trackDelete
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// src/hooks/use-body-class.ts
|
|
93
|
-
import { useEffect } from "react";
|
|
94
|
-
var useBodyClasses = (className) => {
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (!className.trim()) return;
|
|
97
|
-
const classList = className.split(/\s+/).filter(Boolean);
|
|
98
|
-
classList.forEach((cls) => {
|
|
99
|
-
document.body.classList.add(cls);
|
|
100
|
-
});
|
|
101
|
-
return () => {
|
|
102
|
-
classList.forEach((cls) => {
|
|
103
|
-
document.body.classList.remove(cls);
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
}, [className]);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/hooks/use-file-upload.ts
|
|
110
|
-
import {
|
|
111
|
-
useCallback as useCallback2,
|
|
112
|
-
useRef,
|
|
113
|
-
useState
|
|
114
|
-
} from "react";
|
|
115
|
-
var useFileUpload = (options = {}) => {
|
|
116
|
-
const {
|
|
117
|
-
maxFiles = Number.POSITIVE_INFINITY,
|
|
118
|
-
maxSize = Number.POSITIVE_INFINITY,
|
|
119
|
-
accept = "*",
|
|
120
|
-
multiple = false,
|
|
121
|
-
initialFiles = [],
|
|
122
|
-
onFilesChange,
|
|
123
|
-
onFilesAdded,
|
|
124
|
-
onError
|
|
125
|
-
} = options;
|
|
126
|
-
const [state, setState] = useState({
|
|
127
|
-
files: initialFiles.map((file) => ({
|
|
128
|
-
file,
|
|
129
|
-
id: file.id,
|
|
130
|
-
preview: file.url
|
|
131
|
-
})),
|
|
132
|
-
isDragging: false,
|
|
133
|
-
errors: []
|
|
134
|
-
});
|
|
135
|
-
const inputRef = useRef(null);
|
|
136
|
-
const validateFile = useCallback2(
|
|
137
|
-
(file) => {
|
|
138
|
-
if (file instanceof File) {
|
|
139
|
-
if (file.size > maxSize) {
|
|
140
|
-
return `File "${file.name}" exceeds the maximum size of ${formatBytes(maxSize)}.`;
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
if (file.size > maxSize) {
|
|
144
|
-
return `File "${file.name}" exceeds the maximum size of ${formatBytes(maxSize)}.`;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (accept !== "*") {
|
|
148
|
-
const acceptedTypes = accept.split(",").map((type) => type.trim());
|
|
149
|
-
const fileType = file instanceof File ? file.type || "" : file.type;
|
|
150
|
-
const fileExtension = `.${file instanceof File ? file.name.split(".").pop() : file.name.split(".").pop()}`;
|
|
151
|
-
const isAccepted = acceptedTypes.some((type) => {
|
|
152
|
-
if (type.startsWith(".")) {
|
|
153
|
-
return fileExtension.toLowerCase() === type.toLowerCase();
|
|
154
|
-
}
|
|
155
|
-
if (type.endsWith("/*")) {
|
|
156
|
-
const baseType = type.split("/")[0];
|
|
157
|
-
return fileType.startsWith(`${baseType}/`);
|
|
158
|
-
}
|
|
159
|
-
return fileType === type;
|
|
160
|
-
});
|
|
161
|
-
if (!isAccepted) {
|
|
162
|
-
return `File "${file instanceof File ? file.name : file.name}" is not an accepted file type.`;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
},
|
|
167
|
-
[accept, maxSize]
|
|
168
|
-
);
|
|
169
|
-
const createPreview = useCallback2((file) => {
|
|
170
|
-
if (file instanceof File) {
|
|
171
|
-
return URL.createObjectURL(file);
|
|
172
|
-
}
|
|
173
|
-
return file.url;
|
|
174
|
-
}, []);
|
|
175
|
-
const generateUniqueId = useCallback2((file) => {
|
|
176
|
-
if (file instanceof File) {
|
|
177
|
-
return `${file.name}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
178
|
-
}
|
|
179
|
-
return file.id;
|
|
180
|
-
}, []);
|
|
181
|
-
const clearFiles = useCallback2(() => {
|
|
182
|
-
setState((prev) => {
|
|
183
|
-
for (const file of prev.files) {
|
|
184
|
-
if (file.preview && file.file instanceof File && file.file.type.startsWith("image/")) {
|
|
185
|
-
URL.revokeObjectURL(file.preview);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (inputRef.current) {
|
|
189
|
-
inputRef.current.value = "";
|
|
190
|
-
}
|
|
191
|
-
const newState = {
|
|
192
|
-
...prev,
|
|
193
|
-
files: [],
|
|
194
|
-
errors: []
|
|
195
|
-
};
|
|
196
|
-
onFilesChange?.(newState.files);
|
|
197
|
-
return newState;
|
|
198
|
-
});
|
|
199
|
-
}, [onFilesChange]);
|
|
200
|
-
const addFiles = useCallback2(
|
|
201
|
-
(newFiles) => {
|
|
202
|
-
if (!newFiles || newFiles.length === 0) return;
|
|
203
|
-
const newFilesArray = Array.from(newFiles);
|
|
204
|
-
const errors = [];
|
|
205
|
-
setState((prev) => ({ ...prev, errors: [] }));
|
|
206
|
-
if (!multiple) {
|
|
207
|
-
clearFiles();
|
|
208
|
-
}
|
|
209
|
-
if (multiple && maxFiles !== Number.POSITIVE_INFINITY && state.files.length + newFilesArray.length > maxFiles) {
|
|
210
|
-
errors.push(`You can only upload a maximum of ${maxFiles} files.`);
|
|
211
|
-
onError?.(errors);
|
|
212
|
-
setState((prev) => ({ ...prev, errors }));
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const validFiles = [];
|
|
216
|
-
for (const file of newFilesArray) {
|
|
217
|
-
if (multiple) {
|
|
218
|
-
const isDuplicate = state.files.some(
|
|
219
|
-
(existingFile) => existingFile.file.name === file.name && existingFile.file.size === file.size
|
|
220
|
-
);
|
|
221
|
-
if (isDuplicate) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (file.size > maxSize) {
|
|
226
|
-
errors.push(
|
|
227
|
-
multiple ? `Some files exceed the maximum size of ${formatBytes(maxSize)}.` : `File exceeds the maximum size of ${formatBytes(maxSize)}.`
|
|
228
|
-
);
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const error = validateFile(file);
|
|
232
|
-
if (error) {
|
|
233
|
-
errors.push(error);
|
|
234
|
-
} else {
|
|
235
|
-
validFiles.push({
|
|
236
|
-
file,
|
|
237
|
-
id: generateUniqueId(file),
|
|
238
|
-
preview: createPreview(file)
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (validFiles.length > 0) {
|
|
243
|
-
onFilesAdded?.(validFiles);
|
|
244
|
-
setState((prev) => {
|
|
245
|
-
const newFiles2 = !multiple ? validFiles : [...prev.files, ...validFiles];
|
|
246
|
-
onFilesChange?.(newFiles2);
|
|
247
|
-
return {
|
|
248
|
-
...prev,
|
|
249
|
-
files: newFiles2,
|
|
250
|
-
errors
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
} else if (errors.length > 0) {
|
|
254
|
-
onError?.(errors);
|
|
255
|
-
setState((prev) => ({
|
|
256
|
-
...prev,
|
|
257
|
-
errors
|
|
258
|
-
}));
|
|
259
|
-
}
|
|
260
|
-
if (inputRef.current) {
|
|
261
|
-
inputRef.current.value = "";
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
[
|
|
265
|
-
state.files,
|
|
266
|
-
maxFiles,
|
|
267
|
-
multiple,
|
|
268
|
-
maxSize,
|
|
269
|
-
validateFile,
|
|
270
|
-
createPreview,
|
|
271
|
-
generateUniqueId,
|
|
272
|
-
clearFiles,
|
|
273
|
-
onFilesChange,
|
|
274
|
-
onFilesAdded,
|
|
275
|
-
onError
|
|
276
|
-
]
|
|
277
|
-
);
|
|
278
|
-
const removeFile = useCallback2(
|
|
279
|
-
(id) => {
|
|
280
|
-
setState((prev) => {
|
|
281
|
-
const fileToRemove = prev.files.find((file) => file.id === id);
|
|
282
|
-
if (fileToRemove?.preview && fileToRemove.file instanceof File && fileToRemove.file.type.startsWith("image/")) {
|
|
283
|
-
URL.revokeObjectURL(fileToRemove.preview);
|
|
284
|
-
}
|
|
285
|
-
const newFiles = prev.files.filter((file) => file.id !== id);
|
|
286
|
-
onFilesChange?.(newFiles);
|
|
287
|
-
return {
|
|
288
|
-
...prev,
|
|
289
|
-
files: newFiles,
|
|
290
|
-
errors: []
|
|
291
|
-
};
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
[onFilesChange]
|
|
295
|
-
);
|
|
296
|
-
const clearErrors = useCallback2(() => {
|
|
297
|
-
setState((prev) => ({
|
|
298
|
-
...prev,
|
|
299
|
-
errors: []
|
|
300
|
-
}));
|
|
301
|
-
}, []);
|
|
302
|
-
const handleDragEnter = useCallback2((e) => {
|
|
303
|
-
e.preventDefault();
|
|
304
|
-
e.stopPropagation();
|
|
305
|
-
setState((prev) => ({ ...prev, isDragging: true }));
|
|
306
|
-
}, []);
|
|
307
|
-
const handleDragLeave = useCallback2((e) => {
|
|
308
|
-
e.preventDefault();
|
|
309
|
-
e.stopPropagation();
|
|
310
|
-
if (e.currentTarget.contains(e.relatedTarget)) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
setState((prev) => ({ ...prev, isDragging: false }));
|
|
314
|
-
}, []);
|
|
315
|
-
const handleDragOver = useCallback2((e) => {
|
|
316
|
-
e.preventDefault();
|
|
317
|
-
e.stopPropagation();
|
|
318
|
-
}, []);
|
|
319
|
-
const handleDrop = useCallback2(
|
|
320
|
-
(e) => {
|
|
321
|
-
e.preventDefault();
|
|
322
|
-
e.stopPropagation();
|
|
323
|
-
setState((prev) => ({ ...prev, isDragging: false }));
|
|
324
|
-
if (inputRef.current?.disabled) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
328
|
-
if (!multiple) {
|
|
329
|
-
const file = e.dataTransfer.files[0];
|
|
330
|
-
addFiles([file]);
|
|
331
|
-
} else {
|
|
332
|
-
addFiles(e.dataTransfer.files);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
[addFiles, multiple]
|
|
337
|
-
);
|
|
338
|
-
const handleFileChange = useCallback2(
|
|
339
|
-
(e) => {
|
|
340
|
-
if (e.target.files && e.target.files.length > 0) {
|
|
341
|
-
addFiles(e.target.files);
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
[addFiles]
|
|
345
|
-
);
|
|
346
|
-
const openFileDialog = useCallback2(() => {
|
|
347
|
-
if (inputRef.current) {
|
|
348
|
-
inputRef.current.click();
|
|
349
|
-
}
|
|
350
|
-
}, []);
|
|
351
|
-
const getInputProps = useCallback2(
|
|
352
|
-
(props = {}) => {
|
|
353
|
-
return {
|
|
354
|
-
...props,
|
|
355
|
-
type: "file",
|
|
356
|
-
onChange: handleFileChange,
|
|
357
|
-
accept: props.accept || accept,
|
|
358
|
-
multiple: props.multiple !== void 0 ? props.multiple : multiple,
|
|
359
|
-
ref: inputRef
|
|
360
|
-
};
|
|
361
|
-
},
|
|
362
|
-
[accept, multiple, handleFileChange]
|
|
363
|
-
);
|
|
364
|
-
return [
|
|
365
|
-
state,
|
|
366
|
-
{
|
|
367
|
-
addFiles,
|
|
368
|
-
removeFile,
|
|
369
|
-
clearFiles,
|
|
370
|
-
clearErrors,
|
|
371
|
-
handleDragEnter,
|
|
372
|
-
handleDragLeave,
|
|
373
|
-
handleDragOver,
|
|
374
|
-
handleDrop,
|
|
375
|
-
handleFileChange,
|
|
376
|
-
openFileDialog,
|
|
377
|
-
getInputProps
|
|
378
|
-
}
|
|
379
|
-
];
|
|
380
|
-
};
|
|
381
|
-
var formatBytes = (bytes, decimals = 2) => {
|
|
382
|
-
if (bytes === 0) return "0 Bytes";
|
|
383
|
-
const k = 1024;
|
|
384
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
385
|
-
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
386
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
387
|
-
return Number.parseFloat((bytes / k ** i).toFixed(dm)) + sizes[i];
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
// src/hooks/use-media-query.ts
|
|
391
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
392
|
-
var getMatches = (query) => {
|
|
393
|
-
if (typeof window !== "undefined") {
|
|
394
|
-
return window.matchMedia(query).matches;
|
|
395
|
-
}
|
|
396
|
-
return false;
|
|
397
|
-
};
|
|
398
|
-
var useMediaQuery = (query) => {
|
|
399
|
-
const [matches, setMatches] = useState2(getMatches(query));
|
|
400
|
-
useEffect2(() => {
|
|
401
|
-
function handleChange() {
|
|
402
|
-
setMatches(getMatches(query));
|
|
403
|
-
}
|
|
404
|
-
const matchMedia = window.matchMedia(query);
|
|
405
|
-
handleChange();
|
|
406
|
-
matchMedia.addEventListener("change", handleChange);
|
|
407
|
-
return () => {
|
|
408
|
-
matchMedia.removeEventListener("change", handleChange);
|
|
409
|
-
};
|
|
410
|
-
}, [query]);
|
|
411
|
-
return matches;
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
// src/hooks/use-menu.ts
|
|
415
|
-
var useMenu = (pathname) => {
|
|
416
|
-
const isActive = (path) => {
|
|
417
|
-
if (path && path === "/") {
|
|
418
|
-
return path === pathname;
|
|
419
|
-
} else {
|
|
420
|
-
return !!path && pathname.startsWith(path);
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
const hasActiveChild = (children) => {
|
|
424
|
-
if (!children || !Array.isArray(children)) return false;
|
|
425
|
-
return children.some(
|
|
426
|
-
(child) => child.path && isActive(child.path) || child.children && hasActiveChild(child.children)
|
|
427
|
-
);
|
|
428
|
-
};
|
|
429
|
-
const isItemActive = (item) => {
|
|
430
|
-
return (item.path ? isActive(item.path) : false) || (item.children ? hasActiveChild(item.children) : false);
|
|
431
|
-
};
|
|
432
|
-
const getCurrentItem = (items) => {
|
|
433
|
-
for (const item of items) {
|
|
434
|
-
if (item.path && isActive(item.path)) {
|
|
435
|
-
if (item.children && item.children.length > 0) {
|
|
436
|
-
const childMatch = getCurrentItem(item.children);
|
|
437
|
-
return childMatch || item;
|
|
438
|
-
}
|
|
439
|
-
return item;
|
|
440
|
-
}
|
|
441
|
-
if (item.children && item.children.length > 0) {
|
|
442
|
-
const childMatch = getCurrentItem(item.children);
|
|
443
|
-
if (childMatch) {
|
|
444
|
-
return childMatch;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return void 0;
|
|
449
|
-
};
|
|
450
|
-
const getBreadcrumb = (items) => {
|
|
451
|
-
const findBreadcrumb = (nodes, breadcrumb2 = []) => {
|
|
452
|
-
for (const item of nodes) {
|
|
453
|
-
const currentBreadcrumb = [...breadcrumb2, item];
|
|
454
|
-
if (item.path && isActive(item.path)) {
|
|
455
|
-
return currentBreadcrumb;
|
|
456
|
-
}
|
|
457
|
-
if (item.children && item.children.length > 0) {
|
|
458
|
-
const childBreadcrumb = findBreadcrumb(item.children, currentBreadcrumb);
|
|
459
|
-
if (childBreadcrumb.length > currentBreadcrumb.length) {
|
|
460
|
-
return childBreadcrumb;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return breadcrumb2;
|
|
465
|
-
};
|
|
466
|
-
const breadcrumb = findBreadcrumb(items);
|
|
467
|
-
return breadcrumb.length > 0 ? breadcrumb : [];
|
|
468
|
-
};
|
|
469
|
-
const getChildren = (items, level) => {
|
|
470
|
-
const hasActiveChildAtLevel = (items2) => {
|
|
471
|
-
for (const item of items2) {
|
|
472
|
-
if (item.path && (item.path === pathname || item.path !== "/" && item.path !== "" && pathname.startsWith(item.path)) || item.children && hasActiveChildAtLevel(item.children)) {
|
|
473
|
-
return true;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return false;
|
|
477
|
-
};
|
|
478
|
-
const findChildren = (items2, targetLevel, currentLevel = 0) => {
|
|
479
|
-
for (const item of items2) {
|
|
480
|
-
if (item.children) {
|
|
481
|
-
if (targetLevel === currentLevel && hasActiveChildAtLevel(item.children)) {
|
|
482
|
-
return item.children;
|
|
483
|
-
}
|
|
484
|
-
const children = findChildren(item.children, targetLevel, currentLevel + 1);
|
|
485
|
-
if (children) {
|
|
486
|
-
return children;
|
|
487
|
-
}
|
|
488
|
-
} else if (targetLevel === currentLevel && item.path && (item.path === pathname || item.path !== "/" && item.path !== "" && pathname.startsWith(item.path))) {
|
|
489
|
-
return items2;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return null;
|
|
493
|
-
};
|
|
494
|
-
return findChildren(items, level);
|
|
495
|
-
};
|
|
496
|
-
return {
|
|
497
|
-
isActive,
|
|
498
|
-
hasActiveChild,
|
|
499
|
-
isItemActive,
|
|
500
|
-
getCurrentItem,
|
|
501
|
-
getBreadcrumb,
|
|
502
|
-
getChildren
|
|
503
|
-
};
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
// src/hooks/use-mounted.ts
|
|
507
|
-
import * as React from "react";
|
|
508
|
-
function useMounted() {
|
|
509
|
-
const [mounted, setMounted] = React.useState(false);
|
|
510
|
-
React.useEffect(() => {
|
|
511
|
-
setMounted(true);
|
|
512
|
-
}, []);
|
|
513
|
-
return mounted;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// src/hooks/use-mutation-observer.ts
|
|
517
|
-
import * as React2 from "react";
|
|
518
|
-
var DEFAULT_OPTIONS = {
|
|
519
|
-
/** Watch for attribute changes */
|
|
520
|
-
attributes: true,
|
|
521
|
-
/** Watch for text content changes */
|
|
522
|
-
characterData: true,
|
|
523
|
-
/** Watch for child element additions/removals */
|
|
524
|
-
childList: true,
|
|
525
|
-
/** Watch for changes in descendant elements */
|
|
526
|
-
subtree: true
|
|
527
|
-
};
|
|
528
|
-
var useMutationObserver = (ref, callback, options = DEFAULT_OPTIONS) => {
|
|
529
|
-
React2.useEffect(() => {
|
|
530
|
-
if (ref.current) {
|
|
531
|
-
const observer = new MutationObserver(callback);
|
|
532
|
-
observer.observe(ref.current, options);
|
|
533
|
-
return () => {
|
|
534
|
-
observer.disconnect();
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
}, [ref, callback, options]);
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
// src/hooks/use-remove-ga-params.ts
|
|
541
|
-
import { useEffect as useEffect5 } from "react";
|
|
542
|
-
function useRemoveGAParams() {
|
|
543
|
-
useEffect5(() => {
|
|
544
|
-
const url = new URL(window.location.href);
|
|
545
|
-
if (url.searchParams.has("_gl")) {
|
|
546
|
-
const timer = setTimeout(() => {
|
|
547
|
-
url.searchParams.delete("_gl");
|
|
548
|
-
window.history.replaceState({}, "", url.toString());
|
|
549
|
-
}, 2e3);
|
|
550
|
-
return () => clearTimeout(timer);
|
|
551
|
-
}
|
|
552
|
-
}, []);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// src/hooks/use-scroll-position.ts
|
|
556
|
-
import { useEffect as useEffect6, useState as useState4 } from "react";
|
|
557
|
-
var useScrollPosition = ({ targetRef } = {}) => {
|
|
558
|
-
const [scrollPosition, setScrollPosition] = useState4(0);
|
|
559
|
-
useEffect6(() => {
|
|
560
|
-
const target = targetRef?.current || document;
|
|
561
|
-
const scrollable = target === document ? window : target;
|
|
562
|
-
const updatePosition = () => {
|
|
563
|
-
const scrollY = target === document ? window.scrollY || window.pageYOffset : target.scrollTop;
|
|
564
|
-
setScrollPosition(scrollY);
|
|
565
|
-
};
|
|
566
|
-
scrollable.addEventListener("scroll", updatePosition, { passive: true });
|
|
567
|
-
updatePosition();
|
|
568
|
-
return () => {
|
|
569
|
-
scrollable.removeEventListener("scroll", updatePosition);
|
|
570
|
-
};
|
|
571
|
-
}, [targetRef]);
|
|
572
|
-
return scrollPosition;
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
// src/hooks/use-slider-input.ts
|
|
576
|
-
import { useCallback as useCallback3, useState as useState5 } from "react";
|
|
577
|
-
function useSliderInput({ minValue, maxValue, initialValue }) {
|
|
578
|
-
const [sliderValues, setSliderValues] = useState5(initialValue);
|
|
579
|
-
const [inputValues, setInputValues] = useState5(initialValue);
|
|
580
|
-
const handleSliderChange = useCallback3((values) => {
|
|
581
|
-
setSliderValues(values);
|
|
582
|
-
setInputValues(values);
|
|
583
|
-
}, []);
|
|
584
|
-
const handleInputChange = useCallback3(
|
|
585
|
-
(e, index) => {
|
|
586
|
-
const newValue = parseFloat(e.target.value);
|
|
587
|
-
if (!Number.isNaN(newValue)) {
|
|
588
|
-
const updatedInputs = [...inputValues];
|
|
589
|
-
updatedInputs[index] = newValue;
|
|
590
|
-
setInputValues(updatedInputs);
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
[inputValues]
|
|
594
|
-
);
|
|
595
|
-
const validateAndUpdateValue = useCallback3(
|
|
596
|
-
(value, index) => {
|
|
597
|
-
const updatedSlider = [...sliderValues];
|
|
598
|
-
if (index === 0) {
|
|
599
|
-
updatedSlider[0] = Math.max(minValue, Math.min(value, sliderValues[1]));
|
|
600
|
-
} else {
|
|
601
|
-
updatedSlider[1] = Math.min(maxValue, Math.max(value, sliderValues[0]));
|
|
602
|
-
}
|
|
603
|
-
setSliderValues(updatedSlider);
|
|
604
|
-
setInputValues(updatedSlider);
|
|
605
|
-
},
|
|
606
|
-
[sliderValues, minValue, maxValue]
|
|
607
|
-
);
|
|
608
|
-
return {
|
|
609
|
-
/** Function to manually set slider values */
|
|
610
|
-
setSliderValues,
|
|
611
|
-
/** Function to manually set input values */
|
|
612
|
-
setInputValues,
|
|
613
|
-
/** Current slider values [min, max] */
|
|
614
|
-
sliderValues,
|
|
615
|
-
/** Current input values [min, max] */
|
|
616
|
-
inputValues,
|
|
617
|
-
/** Handler for slider value changes */
|
|
618
|
-
handleSliderChange,
|
|
619
|
-
/** Handler for input field changes */
|
|
620
|
-
handleInputChange,
|
|
621
|
-
/** Function to validate and update values from inputs */
|
|
622
|
-
validateAndUpdateValue
|
|
623
|
-
};
|
|
624
|
-
}
|
|
2
|
+
useMetaColor
|
|
3
|
+
} from "./chunk-UEVIEY7W.js";
|
|
625
4
|
|
|
626
|
-
// src/hooks
|
|
627
|
-
|
|
628
|
-
var useViewport = () => {
|
|
629
|
-
const [dimensions, setDimensions] = useState6(() => {
|
|
630
|
-
if (typeof window !== "undefined") {
|
|
631
|
-
return [window.innerHeight, window.innerWidth];
|
|
632
|
-
}
|
|
633
|
-
return [0, 0];
|
|
634
|
-
});
|
|
635
|
-
useEffect7(() => {
|
|
636
|
-
const handleResize = () => {
|
|
637
|
-
setDimensions([window.innerHeight, window.innerWidth]);
|
|
638
|
-
};
|
|
639
|
-
handleResize();
|
|
640
|
-
window.addEventListener("resize", handleResize, { passive: true });
|
|
641
|
-
return () => {
|
|
642
|
-
window.removeEventListener("resize", handleResize);
|
|
643
|
-
};
|
|
644
|
-
}, []);
|
|
645
|
-
return dimensions;
|
|
646
|
-
};
|
|
5
|
+
// src/hooks.ts
|
|
6
|
+
export * from "@pelatform/ui.hook";
|
|
647
7
|
export {
|
|
648
|
-
|
|
649
|
-
toastManager,
|
|
650
|
-
useAnalytics,
|
|
651
|
-
useBodyClasses,
|
|
652
|
-
useCopyToClipboard,
|
|
653
|
-
useFileUpload,
|
|
654
|
-
useIsMobile,
|
|
655
|
-
useMediaQuery,
|
|
656
|
-
useMenu,
|
|
657
|
-
useMetaColor,
|
|
658
|
-
useMounted,
|
|
659
|
-
useMutationObserver,
|
|
660
|
-
useRecaptchaV2,
|
|
661
|
-
useRemoveGAParams,
|
|
662
|
-
useScrollPosition,
|
|
663
|
-
useSliderInput,
|
|
664
|
-
useToast,
|
|
665
|
-
useViewport
|
|
8
|
+
useMetaColor
|
|
666
9
|
};
|