dirk-cfx-react 1.1.92 → 1.1.94

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.
Files changed (65) hide show
  1. package/dist/chunk-3T2CCW5E.cjs +150 -0
  2. package/dist/chunk-3T2CCW5E.cjs.map +1 -0
  3. package/dist/chunk-4DE2IREA.cjs +9 -0
  4. package/dist/chunk-4DE2IREA.cjs.map +1 -0
  5. package/dist/chunk-E2SFEBBB.cjs +449 -0
  6. package/dist/chunk-E2SFEBBB.cjs.map +1 -0
  7. package/dist/chunk-GKSP5RIA.js +3 -0
  8. package/dist/chunk-GKSP5RIA.js.map +1 -0
  9. package/dist/chunk-HAB6H274.js +6646 -0
  10. package/dist/chunk-HAB6H274.js.map +1 -0
  11. package/dist/chunk-K3GDU6EY.cjs +6717 -0
  12. package/dist/chunk-K3GDU6EY.cjs.map +1 -0
  13. package/dist/chunk-KGLO3ZAS.js +431 -0
  14. package/dist/chunk-KGLO3ZAS.js.map +1 -0
  15. package/dist/chunk-LRGCBNZ7.cjs +4 -0
  16. package/dist/chunk-LRGCBNZ7.cjs.map +1 -0
  17. package/dist/chunk-MYNNCLMA.js +1375 -0
  18. package/dist/chunk-MYNNCLMA.js.map +1 -0
  19. package/dist/chunk-NVMOGS7Y.js +437 -0
  20. package/dist/chunk-NVMOGS7Y.js.map +1 -0
  21. package/dist/chunk-QOQQ3ERZ.cjs +445 -0
  22. package/dist/chunk-QOQQ3ERZ.cjs.map +1 -0
  23. package/dist/chunk-V6TY7KAL.js +7 -0
  24. package/dist/chunk-V6TY7KAL.js.map +1 -0
  25. package/dist/chunk-VKYONY7E.cjs +112 -0
  26. package/dist/chunk-VKYONY7E.cjs.map +1 -0
  27. package/dist/chunk-YA2PXBP6.cjs +1430 -0
  28. package/dist/chunk-YA2PXBP6.cjs.map +1 -0
  29. package/dist/chunk-Z7N5AQJW.js +146 -0
  30. package/dist/chunk-Z7N5AQJW.js.map +1 -0
  31. package/dist/chunk-ZPFW7C2A.js +108 -0
  32. package/dist/chunk-ZPFW7C2A.js.map +1 -0
  33. package/dist/components/index.cjs +282 -7760
  34. package/dist/components/index.cjs.map +1 -1
  35. package/dist/components/index.d.cts +39 -1
  36. package/dist/components/index.d.ts +39 -1
  37. package/dist/components/index.js +6 -7699
  38. package/dist/components/index.js.map +1 -1
  39. package/dist/hooks/index.cjs +75 -718
  40. package/dist/hooks/index.cjs.map +1 -1
  41. package/dist/hooks/index.d.cts +11 -1
  42. package/dist/hooks/index.d.ts +11 -1
  43. package/dist/hooks/index.js +5 -701
  44. package/dist/hooks/index.js.map +1 -1
  45. package/dist/index.cjs +572 -9066
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +3 -3
  48. package/dist/index.d.ts +3 -3
  49. package/dist/index.js +9 -8928
  50. package/dist/index.js.map +1 -1
  51. package/dist/modelNames-QIAIYORH.cjs +53910 -0
  52. package/dist/modelNames-QIAIYORH.cjs.map +1 -0
  53. package/dist/modelNames-WAUYJLL3.js +53908 -0
  54. package/dist/modelNames-WAUYJLL3.js.map +1 -0
  55. package/dist/providers/index.cjs +11 -596
  56. package/dist/providers/index.cjs.map +1 -1
  57. package/dist/providers/index.js +5 -596
  58. package/dist/providers/index.js.map +1 -1
  59. package/dist/utils/index.cjs +186 -1361
  60. package/dist/utils/index.cjs.map +1 -1
  61. package/dist/utils/index.d.cts +41 -1
  62. package/dist/utils/index.d.ts +41 -1
  63. package/dist/utils/index.js +2 -1324
  64. package/dist/utils/index.js.map +1 -1
  65. package/package.json +1 -1
@@ -1,703 +1,7 @@
1
- import { create, createStore, useStore } from 'zustand';
2
- import clickSoundUrl from '../click_sound-PNCRRTM4.mp3';
3
- import hoverSoundUrl from '../hover_sound-NBUA222C.mp3';
4
- import { createContext, useRef, useEffect, useContext, useMemo, useState } from 'react';
5
- import { jsx, jsxs } from 'react/jsx-runtime';
6
- import { z } from 'zod';
7
- import { useQuery, keepPreviousData } from '@tanstack/react-query';
8
-
9
- // src/hooks/useAudio/store.ts
10
- var useAudio = create(() => {
11
- const audioRefs = {};
12
- const sounds = {
13
- click: clickSoundUrl,
14
- hover: hoverSoundUrl
15
- };
16
- for (const [key, src] of Object.entries(sounds)) {
17
- audioRefs[key] = new Audio(src);
18
- }
19
- return {
20
- play: (sound) => {
21
- const audio = audioRefs[sound];
22
- if (!audio) return console.warn(`Sound '${sound}' not found.`);
23
- audio.currentTime = 0;
24
- audio.volume = 0.1;
25
- audio.play();
26
- },
27
- stop: (sound) => {
28
- const audio = audioRefs[sound];
29
- if (!audio) return console.warn(`Sound '${sound}' not found.`);
30
- audio.pause();
31
- audio.currentTime = 0;
32
- }
33
- };
34
- });
35
-
36
- // src/utils/misc.ts
37
- var isEnvBrowser = () => !window.invokeNative;
38
- var noop = () => {
39
- };
40
-
41
- // src/hooks/useNuiEvent.ts
42
- var useNuiEvent = (action, handler) => {
43
- const savedHandler = useRef(noop);
44
- useEffect(() => {
45
- savedHandler.current = handler;
46
- }, [handler]);
47
- useEffect(() => {
48
- const eventListener = (event) => {
49
- const { action: eventAction, data } = event.data;
50
- if (savedHandler.current) {
51
- if (eventAction === action) {
52
- savedHandler.current(data);
53
- }
54
- }
55
- };
56
- window.addEventListener("message", eventListener);
57
- return () => window.removeEventListener("message", eventListener);
58
- }, [action]);
59
- };
60
- function getNested(obj, path) {
61
- return path.split(".").reduce((acc, key) => acc ? acc[key] : void 0, obj);
62
- }
63
- function setNested(obj, path, value) {
64
- const keys = path.split(".");
65
- const root = Array.isArray(obj) ? [...obj] : { ...obj };
66
- let current = root;
67
- for (let i = 0; i < keys.length - 1; i++) {
68
- const key = keys[i];
69
- const nextKey = keys[i + 1];
70
- const isIndex = !isNaN(Number(nextKey));
71
- const existing = current[key];
72
- current[key] = existing != null ? Array.isArray(existing) ? [...existing] : { ...existing } : isIndex ? [] : {};
73
- current = current[key];
74
- }
75
- current[keys[keys.length - 1]] = value;
76
- return root;
77
- }
78
- function deleteNested(obj, path) {
79
- const keys = path.split(".");
80
- const newObj = { ...obj };
81
- let current = newObj;
82
- for (let i = 0; i < keys.length - 1; i++) {
83
- const key = keys[i];
84
- if (!current[key]) return obj;
85
- current[key] = { ...current[key] };
86
- current = current[key];
87
- }
88
- delete current[keys[keys.length - 1]];
89
- return newObj;
90
- }
91
- function isPlainObject(value) {
92
- return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
93
- }
94
- function collectChangedPaths(values, initial, prefix = "") {
95
- if (Object.is(values, initial)) return [];
96
- const valuesIsObj = isPlainObject(values);
97
- const initialIsObj = isPlainObject(initial);
98
- const valuesIsArr = Array.isArray(values);
99
- const initialIsArr = Array.isArray(initial);
100
- if (valuesIsArr || initialIsArr) {
101
- const maxLen = Math.max(values?.length ?? 0, initial?.length ?? 0);
102
- const fields = [];
103
- for (let i = 0; i < maxLen; i++) {
104
- const nextPrefix = prefix ? `${prefix}.${i}` : `${i}`;
105
- fields.push(...collectChangedPaths(values?.[i], initial?.[i], nextPrefix));
106
- }
107
- return fields;
108
- }
109
- if (valuesIsObj || initialIsObj) {
110
- const keys = /* @__PURE__ */ new Set([
111
- ...Object.keys(values ?? {}),
112
- ...Object.keys(initial ?? {})
113
- ]);
114
- const fields = [];
115
- for (const key of keys) {
116
- const nextPrefix = prefix ? `${prefix}.${key}` : key;
117
- fields.push(...collectChangedPaths(values?.[key], initial?.[key], nextPrefix));
118
- }
119
- return fields;
120
- }
121
- return prefix ? [prefix] : [];
122
- }
123
- function computeChangedState(values, initialVals) {
124
- const fields = collectChangedPaths(values, initialVals);
125
- let partial = {};
126
- for (const path of fields) {
127
- partial = setNested(partial, path, getNested(values, path));
128
- }
129
- return { fields, partial };
130
- }
131
- function flattenRules(rules, prefix = "") {
132
- const result = {};
133
- for (const key in rules) {
134
- const fullPath = prefix ? `${prefix}.${key}` : key;
135
- const val = rules[key];
136
- if (typeof val === "function") result[fullPath] = val;
137
- else if (typeof val === "object")
138
- Object.assign(result, flattenRules(val, fullPath));
139
- }
140
- return result;
141
- }
142
- async function runRule(rule, value, values) {
143
- const result = rule(value, values);
144
- return result instanceof Promise ? await result : result;
145
- }
146
- function createFormStore(initialValues, validationRules, onSubmit) {
147
- const flatRules = validationRules ? flattenRules(validationRules) : {};
148
- const history = [];
149
- const future = [];
150
- const changed = /* @__PURE__ */ new Set();
151
- return createStore((set, get) => ({
152
- initialValues,
153
- values: initialValues,
154
- errors: {},
155
- partialChanged: {},
156
- canBack: false,
157
- canForward: false,
158
- changedFields: [],
159
- changedCount: 0,
160
- onSubmit,
161
- submit: async () => {
162
- const state = get();
163
- const isValid = await state.validate();
164
- if (isValid && state.onSubmit) {
165
- state.onSubmit(get());
166
- }
167
- },
168
- getInputProps: (path) => {
169
- return {
170
- value: getNested(get().values, path) ?? "",
171
- error: get().errors[path],
172
- onChange: (e) => {
173
- get().setValue(path, e.target.value, { validate: true });
174
- }
175
- };
176
- },
177
- resetChangeCount: () => {
178
- changed.clear();
179
- set({ changedFields: [], changedCount: 0, partialChanged: {} });
180
- },
181
- setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
182
- setValue: (path, value, options) => {
183
- const state = get();
184
- const currentValues = state.values;
185
- const newValues = setNested(currentValues, path, value);
186
- const oldValue = getNested(state.initialValues, path);
187
- const hasChanged = value !== oldValue;
188
- history.push(currentValues);
189
- future.length = 0;
190
- let newPartial = state.partialChanged;
191
- if (hasChanged) {
192
- changed.add(path);
193
- newPartial = setNested(newPartial, path, value);
194
- } else {
195
- changed.delete(path);
196
- newPartial = deleteNested(newPartial, path);
197
- }
198
- set({
199
- values: newValues,
200
- partialChanged: newPartial,
201
- canBack: history.length > 0,
202
- canForward: false,
203
- changedFields: Array.from(changed),
204
- changedCount: changed.size
205
- });
206
- if (!options?.validate) return;
207
- const rule = flatRules[path];
208
- if (!rule) return;
209
- Promise.resolve(runRule(rule, value, newValues)).then((error) => {
210
- if (error)
211
- set((s) => ({ errors: setNested(s.errors, path, error) }));
212
- else
213
- set((s) => ({ errors: deleteNested(s.errors, path) }));
214
- });
215
- },
216
- setError: (path, message) => set((s) => ({ errors: setNested(s.errors, path, message) })),
217
- clearError: (path) => set((s) => ({ errors: deleteNested(s.errors, path) })),
218
- validateField: async (path) => {
219
- const state = get();
220
- const rule = flatRules[path];
221
- if (!rule) return true;
222
- const value = getNested(state.values, path);
223
- const error = await runRule(rule, value, state.values);
224
- if (error) {
225
- set((s) => ({ errors: setNested(s.errors, path, error) }));
226
- return false;
227
- }
228
- set((s) => ({ errors: deleteNested(s.errors, path) }));
229
- return true;
230
- },
231
- validate: async () => {
232
- const state = get();
233
- let isValid = true;
234
- let newErrors = {};
235
- for (const path in flatRules) {
236
- const rule = flatRules[path];
237
- const value = getNested(state.values, path);
238
- const error = await runRule(rule, value, state.values);
239
- if (error) {
240
- isValid = false;
241
- newErrors = setNested(newErrors, path, error);
242
- }
243
- }
244
- set({ errors: newErrors });
245
- return isValid;
246
- },
247
- reset: () => {
248
- history.length = 0;
249
- future.length = 0;
250
- changed.clear();
251
- set({
252
- values: get().initialValues,
253
- errors: {},
254
- partialChanged: {},
255
- canBack: false,
256
- canForward: false,
257
- changedFields: [],
258
- changedCount: 0
259
- });
260
- },
261
- reinitialize: (newValues) => {
262
- history.length = 0;
263
- future.length = 0;
264
- changed.clear();
265
- set({
266
- values: newValues,
267
- initialValues: newValues,
268
- errors: {},
269
- partialChanged: {},
270
- canBack: false,
271
- canForward: false,
272
- changedFields: [],
273
- changedCount: 0
274
- });
275
- },
276
- back: () => {
277
- if (!history.length) return;
278
- const prev = history.pop();
279
- future.push(get().values);
280
- const { fields, partial } = computeChangedState(prev, get().initialValues);
281
- set({
282
- values: prev,
283
- partialChanged: partial,
284
- canBack: history.length > 0,
285
- canForward: true,
286
- changedFields: fields,
287
- changedCount: fields.length
288
- });
289
- },
290
- forward: () => {
291
- if (!future.length) return;
292
- const next = future.pop();
293
- history.push(get().values);
294
- const { fields, partial } = computeChangedState(next, get().initialValues);
295
- set({
296
- values: next,
297
- partialChanged: partial,
298
- canBack: true,
299
- canForward: future.length > 0,
300
- changedFields: fields,
301
- changedCount: fields.length
302
- });
303
- }
304
- }));
305
- }
306
- var FormContext = createContext(null);
307
- function FormProvider({
308
- initialValues,
309
- validate,
310
- onSubmit,
311
- children
312
- }) {
313
- const storeRef = useRef(
314
- createFormStore(initialValues, validate, onSubmit)
315
- );
316
- return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children });
317
- }
318
- function useForm() {
319
- const store2 = useContext(FormContext);
320
- if (!store2) {
321
- throw new Error("useForm must be used inside <FormProvider>");
322
- }
323
- const state = useStore(store2);
324
- const changedFields = useMemo(() => {
325
- return collectChangedPaths(state.values, state.initialValues);
326
- }, [state.values, state.initialValues]);
327
- return { ...state, changedFields, changedCount: changedFields.length };
328
- }
329
- function useFormField(path) {
330
- const store2 = useContext(FormContext);
331
- if (!store2) {
332
- throw new Error("useFormField must be used inside <FormProvider>");
333
- }
334
- return useStore(store2, (s) => getNested(s.values, path));
335
- }
336
- function useFormFields(...paths) {
337
- const store2 = useContext(FormContext);
338
- if (!store2) {
339
- throw new Error("useFormFields must be used inside <FormProvider>");
340
- }
341
- return useStore(store2, (s) => {
342
- const result = {};
343
- for (const path of paths) {
344
- result[path] = getNested(s.values, path);
345
- }
346
- return result;
347
- });
348
- }
349
- function useFormError(path) {
350
- const store2 = useContext(FormContext);
351
- if (!store2) {
352
- throw new Error("useFormError must be used inside <FormProvider>");
353
- }
354
- return useStore(store2, (s) => s.errors[path]);
355
- }
356
- function useFormErrors(...paths) {
357
- const store2 = useContext(FormContext);
358
- if (!store2) {
359
- throw new Error("useFormErrors must be used inside <FormProvider>");
360
- }
361
- return useStore(store2, (s) => {
362
- const result = {};
363
- for (const path of paths) {
364
- result[path] = s.errors[path];
365
- }
366
- return result;
367
- });
368
- }
369
- function useFormActions() {
370
- const store2 = useContext(FormContext);
371
- if (!store2) {
372
- throw new Error("useFormActions must be used inside <FormProvider>");
373
- }
374
- return store2.getState();
375
- }
376
- var DEFAULT_PALETTE = [
377
- "#f0f4ff",
378
- "#d9e3ff",
379
- "#bfcfff",
380
- "#a6bbff",
381
- "#8ca7ff",
382
- "#7393ff",
383
- "#5a7fff",
384
- "#406bff",
385
- "#2547ff",
386
- "#0b33ff"
387
- ];
388
- z.object({
389
- useOverride: z.boolean(),
390
- primaryColor: z.string(),
391
- primaryShade: z.number(),
392
- customTheme: z.array(z.string())
393
- });
394
-
395
- // src/utils/useSettings.ts
396
- var useSettings = create(() => ({
397
- currency: "$",
398
- game: "fivem",
399
- primaryColor: "dirk",
400
- primaryShade: 9,
401
- itemImgPath: "",
402
- resourceVersion: "dev",
403
- customTheme: DEFAULT_PALETTE
404
- }));
405
- function useTornEdges() {
406
- const game = useSettings((state) => state.game);
407
- return game === "rdr3" ? "torn-edge-wrapper" : "";
408
- }
409
- function TornEdgeSVGFilter() {
410
- return /* @__PURE__ */ jsx(
411
- "svg",
412
- {
413
- style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
414
- "aria-hidden": "true",
415
- children: /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
416
- /* @__PURE__ */ jsx(
417
- "feTurbulence",
418
- {
419
- type: "fractalNoise",
420
- baseFrequency: "0.018 0.022",
421
- numOctaves: "5",
422
- seed: "9",
423
- result: "noise1"
424
- }
425
- ),
426
- /* @__PURE__ */ jsx(
427
- "feTurbulence",
428
- {
429
- type: "fractalNoise",
430
- baseFrequency: "0.08 0.12",
431
- numOctaves: "2",
432
- seed: "3",
433
- result: "noise2"
434
- }
435
- ),
436
- /* @__PURE__ */ jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
437
- /* @__PURE__ */ jsx(
438
- "feDisplacementMap",
439
- {
440
- in: "SourceGraphic",
441
- in2: "combinedNoise",
442
- scale: "52",
443
- xChannelSelector: "R",
444
- yChannelSelector: "G",
445
- result: "displaced"
446
- }
447
- ),
448
- /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
449
- /* @__PURE__ */ jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
450
- /* @__PURE__ */ jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
451
- /* @__PURE__ */ jsx("feMerge", { children: /* @__PURE__ */ jsx("feMergeNode", { in: "eroded" }) })
452
- ] }) })
453
- }
454
- );
455
- }
456
- async function fetchNui(eventName, data, mockData) {
457
- const options = {
458
- method: "post",
459
- headers: {
460
- "Content-Type": "application/json; charset=UTF-8"
461
- },
462
- body: JSON.stringify(data)
463
- };
464
- if (isEnvBrowser() && mockData !== void 0) return mockData;
465
- if (isEnvBrowser() && mockData === void 0) {
466
- console.warn(
467
- `[fetchNui] Called fetchNui for event "${eventName}" in browser environment without mockData. Returning empty object.`
468
- );
469
- return {};
470
- }
471
- const overrideResourceName = useSettings.getState().overideResourceName;
472
- const hasResourceContext = typeof window.GetParentResourceName === "function" || !!overrideResourceName;
473
- if (!hasResourceContext) {
474
- return mockData ?? {};
475
- }
476
- const resourceName = window.GetParentResourceName ? window.GetParentResourceName() : overrideResourceName;
477
- try {
478
- const resp = await fetch(`https://${resourceName}/${eventName}`, options);
479
- return await resp.json();
480
- } catch {
481
- return mockData ?? {};
482
- }
483
- }
484
- function changedTopLevelSections(changedFields) {
485
- if (!changedFields || changedFields.length === 0) return [];
486
- const sections = /* @__PURE__ */ new Set();
487
- for (const path of changedFields) {
488
- if (typeof path !== "string" || path.length === 0) continue;
489
- const dot = path.indexOf(".");
490
- sections.add(dot === -1 ? path : path.slice(0, dot));
491
- }
492
- return Array.from(sections);
493
- }
494
- var _instance = null;
495
- function getScriptConfigInstance() {
496
- if (!_instance) throw new Error("[dirk-cfx-react] createScriptConfig must be called before using ConfigPanel");
497
- return _instance;
498
- }
499
- function createScriptConfig(defaultValue) {
500
- const store2 = create(() => defaultValue);
501
- let clientVersion = 0;
502
- const useScriptConfigHooks = () => {
503
- useNuiEvent(
504
- "UPDATE_SCRIPT_CONFIG",
505
- (data) => {
506
- if (!data) return;
507
- if (typeof data.clientVersion === "number") {
508
- clientVersion = data.clientVersion;
509
- }
510
- if (data.config && typeof data.config === "object") {
511
- store2.setState((prev) => ({ ...prev, ...data.config }));
512
- }
513
- }
514
- );
515
- };
516
- const fetchScriptConfig = async () => {
517
- try {
518
- const response = await fetchNui("GET_FULL_SCRIPT_CONFIG");
519
- if (response?.success && response.data?.config) {
520
- store2.setState(() => response.data.config);
521
- if (typeof response.data.clientVersion === "number") {
522
- clientVersion = response.data.clientVersion;
523
- }
524
- return response.data.config;
525
- }
526
- } catch {
527
- }
528
- return null;
529
- };
530
- const updateScriptConfig = async (newConfig, changedFields) => {
531
- store2.setState((prev) => ({ ...prev, ...newConfig }));
532
- const sections = changedTopLevelSections(changedFields);
533
- let payload;
534
- if (sections.length > 0) {
535
- const current = store2.getState();
536
- const delta = {};
537
- for (const key of sections) delta[key] = current[key];
538
- payload = { data: delta, expectedVersion: clientVersion, sectionReplace: true };
539
- } else {
540
- payload = { data: newConfig, expectedVersion: clientVersion };
541
- }
542
- const response = await fetchNui("UPDATE_SCRIPT_CONFIG", payload);
543
- if (response?.meta?.client_version != null) {
544
- clientVersion = response.meta.client_version;
545
- }
546
- if (response?.success === false && response?.meta?.latestData) {
547
- store2.setState((prev) => ({ ...prev, ...response.meta.latestData }));
548
- }
549
- return response;
550
- };
551
- const getScriptConfigHistory = async (params = {}) => {
552
- return fetchNui("GET_SCRIPT_CONFIG_HISTORY", params);
553
- };
554
- const resetConfig = async () => {
555
- const response = await fetchNui("RESET_SCRIPT_CONFIG");
556
- if (response?.success) {
557
- const fresh = await fetchScriptConfig();
558
- if (fresh) {
559
- store2.setState(() => fresh);
560
- }
561
- }
562
- return response;
563
- };
564
- _instance = {
565
- store: store2,
566
- updateConfig: updateScriptConfig,
567
- resetConfig,
568
- getHistory: getScriptConfigHistory,
569
- fetchConfig: fetchScriptConfig
570
- };
571
- return { store: store2, updateScriptConfig, resetConfig, getScriptConfigHistory, useScriptConfigHooks, fetchScriptConfig };
572
- }
573
- var moduleCache = /* @__PURE__ */ new Map();
574
- function useValidModels(names) {
575
- const cacheKey = useMemo(() => {
576
- const unique = Array.from(new Set(names.filter((n) => typeof n === "string" && n.length > 0)));
577
- unique.sort();
578
- return unique.join("|");
579
- }, [names]);
580
- const [version, setVersion] = useState(0);
581
- const inflight = useRef(/* @__PURE__ */ new Set());
582
- useEffect(() => {
583
- if (!cacheKey) return;
584
- const all = cacheKey.split("|").filter(Boolean);
585
- const missing = all.filter((n) => !moduleCache.has(n) && !inflight.current.has(n));
586
- if (missing.length === 0) return;
587
- missing.forEach((n) => inflight.current.add(n));
588
- let cancelled = false;
589
- fetchNui(
590
- "ADMIN_TOOL_QUERY",
591
- { id: "validateModels", value: missing },
592
- // Fallback when running outside FiveM (browser dev) — assume valid so the
593
- // dev shell doesn't grey out every row.
594
- Object.fromEntries(missing.map((n) => [n, true]))
595
- ).then((result) => {
596
- if (cancelled) return;
597
- const map = result && typeof result === "object" ? result : {};
598
- missing.forEach((n) => {
599
- moduleCache.set(n, !!map[n]);
600
- inflight.current.delete(n);
601
- });
602
- setVersion((v) => v + 1);
603
- }).catch(() => {
604
- if (cancelled) return;
605
- missing.forEach((n) => {
606
- inflight.current.delete(n);
607
- });
608
- });
609
- return () => {
610
- cancelled = true;
611
- };
612
- }, [cacheKey]);
613
- return useMemo(() => {
614
- const out = /* @__PURE__ */ new Set();
615
- if (!cacheKey) return out;
616
- for (const n of cacheKey.split("|")) {
617
- if (n && moduleCache.get(n) === true) out.add(n);
618
- }
619
- return out;
620
- }, [cacheKey, version]);
621
- }
622
- var store = /* @__PURE__ */ new Map();
623
- var listeners = /* @__PURE__ */ new Map();
624
- function notify(key) {
625
- const ls = listeners.get(key);
626
- if (!ls) return;
627
- ls.forEach((fn) => fn());
628
- }
629
- function useAdminState(key, initial) {
630
- const [, setTick] = useState(0);
631
- useEffect(() => {
632
- const set = listeners.get(key) ?? /* @__PURE__ */ new Set();
633
- listeners.set(key, set);
634
- const handler = () => setTick((t) => t + 1);
635
- set.add(handler);
636
- return () => {
637
- set.delete(handler);
638
- if (set.size === 0) listeners.delete(key);
639
- };
640
- }, [key]);
641
- const value = store.has(key) ? store.get(key) : initial;
642
- const setValue = (v) => {
643
- const next = typeof v === "function" ? v(value) : v;
644
- store.set(key, next);
645
- notify(key);
646
- };
647
- return [value, setValue];
648
- }
649
- function clearAdminState(key) {
650
- if (key) {
651
- store.delete(key);
652
- notify(key);
653
- } else {
654
- const keys = Array.from(store.keys());
655
- store.clear();
656
- keys.forEach(notify);
657
- }
658
- }
659
- function usePlayers(opts = {}) {
660
- const {
661
- includeOffline = false,
662
- search = "",
663
- limit = 50,
664
- staleTimeMs,
665
- refetchIntervalMs
666
- } = opts;
667
- const query = useQuery({
668
- queryKey: includeOffline ? ["dirk:players", "search", search.trim().toLowerCase(), limit] : ["dirk:players", "online"],
669
- queryFn: async () => {
670
- const toolId = includeOffline ? "searchPlayers" : "getOnlinePlayers";
671
- const payload = includeOffline ? { id: toolId, value: { search: search.trim(), limit } } : { id: toolId };
672
- const result = await fetchNui(
673
- "ADMIN_TOOL_QUERY",
674
- payload,
675
- // Browser-dev fallback. Returns a couple of mock players so the
676
- // dev shell isn't blank.
677
- includeOffline ? [
678
- { id: 1, citizenId: "ABC12345", name: "Dev User", charName: "John Doe", online: true },
679
- { id: null, citizenId: "DEF67890", name: "", charName: "Jane Offline", online: false }
680
- ] : [
681
- { id: 1, citizenId: "ABC12345", name: "Dev User", charName: "John Doe", online: true }
682
- ]
683
- );
684
- return Array.isArray(result) ? result : [];
685
- },
686
- staleTime: staleTimeMs ?? (includeOffline ? 3e4 : 5e3),
687
- gcTime: 5 * 6e4,
688
- refetchInterval: refetchIntervalMs ?? false,
689
- refetchOnWindowFocus: false,
690
- placeholderData: includeOffline ? keepPreviousData : void 0
691
- });
692
- return {
693
- players: query.data ?? [],
694
- isLoading: query.isLoading,
695
- isFetching: query.isFetching,
696
- error: query.error ?? null,
697
- refresh: () => query.refetch()
698
- };
699
- }
700
-
701
- export { FormProvider, TornEdgeSVGFilter, clearAdminState, createFormStore, createScriptConfig, getScriptConfigInstance, useAdminState, useAudio, useForm, useFormActions, useFormError, useFormErrors, useFormField, useFormFields, useNuiEvent, usePlayers, useTornEdges, useValidModels };
1
+ export { TornEdgeSVGFilter, useTornEdges, useValidModels } from '../chunk-ZPFW7C2A.js';
2
+ export { FormProvider, clearAdminState, createFormStore, useAdminState, useAudio, useForm, useFormActions, useFormError, useFormErrors, useFormField, useFormFields, usePlayers } from '../chunk-KGLO3ZAS.js';
3
+ export { createScriptConfig, getScriptConfigInstance, useNuiEvent } from '../chunk-Z7N5AQJW.js';
4
+ import '../chunk-MYNNCLMA.js';
5
+ import '../chunk-V6TY7KAL.js';
702
6
  //# sourceMappingURL=index.js.map
703
7
  //# sourceMappingURL=index.js.map