@hairy/react-lib 1.25.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +28 -49
- package/dist/index.d.ts +1 -7
- package/dist/index.global.js +51 -163
- package/dist/index.js +5 -25
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,6 @@ __export(index_exports, {
|
|
|
37
37
|
Injector: () => Injector,
|
|
38
38
|
Switch: () => Switch,
|
|
39
39
|
Then: () => Then,
|
|
40
|
-
Trans: () => Trans,
|
|
41
40
|
Trigger: () => Trigger,
|
|
42
41
|
Unless: () => Unless,
|
|
43
42
|
cls: () => cls,
|
|
@@ -231,27 +230,8 @@ function repack(c) {
|
|
|
231
230
|
return c.component ? c : { component: c };
|
|
232
231
|
}
|
|
233
232
|
|
|
234
|
-
// src/components/utils/Trans.ts
|
|
235
|
-
var import_html_parse_stringify = __toESM(require("html-parse-stringify"), 1);
|
|
236
|
-
var import_react6 = require("react");
|
|
237
|
-
var import_react_i18next = require("react-i18next");
|
|
238
|
-
function Trans({ i18nKey, ...additionalProps }) {
|
|
239
|
-
const translation = (0, import_react_i18next.useTranslation)().t(i18nKey, additionalProps);
|
|
240
|
-
return renderNodes(import_html_parse_stringify.default.parse(translation), additionalProps);
|
|
241
|
-
}
|
|
242
|
-
function renderNodes(tokens, values) {
|
|
243
|
-
let index = 0;
|
|
244
|
-
return tokens.map((token) => {
|
|
245
|
-
if (token.type === "text")
|
|
246
|
-
return token.content;
|
|
247
|
-
index++;
|
|
248
|
-
const props = { ...token.attrs, key: index };
|
|
249
|
-
return token.voidElement ? values[token.name] ? (0, import_react6.createElement)("span", { key: index }, values[token.name]) : (0, import_react6.createElement)(token.name, props) : (0, import_react6.createElement)(token.name, props, renderNodes(token.children, {}));
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
233
|
// src/components/utils/Trigger.ts
|
|
254
|
-
var
|
|
234
|
+
var import_react6 = require("react");
|
|
255
235
|
var import_valtio2 = require("valtio");
|
|
256
236
|
var import_utils8 = require("valtio/utils");
|
|
257
237
|
var pendingTasks = (0, import_utils8.proxyMap)();
|
|
@@ -268,7 +248,7 @@ function createTracker(exposer) {
|
|
|
268
248
|
return Component;
|
|
269
249
|
}
|
|
270
250
|
function renderTracker(Tracker) {
|
|
271
|
-
return (0,
|
|
251
|
+
return (0, import_react6.createElement)(Tracker, { key: Tracker.key });
|
|
272
252
|
}
|
|
273
253
|
function Trigger() {
|
|
274
254
|
const values = [...(0, import_valtio2.useSnapshot)(pendingTasks).values()];
|
|
@@ -278,7 +258,7 @@ Trigger.id = 0;
|
|
|
278
258
|
Trigger.tasks = pendingTasks;
|
|
279
259
|
|
|
280
260
|
// src/hooks/ref.ts
|
|
281
|
-
var
|
|
261
|
+
var import_react7 = require("react");
|
|
282
262
|
function ref2(value) {
|
|
283
263
|
function define(value2) {
|
|
284
264
|
if (typeof value2 === "function")
|
|
@@ -289,14 +269,14 @@ function ref2(value) {
|
|
|
289
269
|
enumerable: true
|
|
290
270
|
});
|
|
291
271
|
}
|
|
292
|
-
const [ref3, set] = (0,
|
|
272
|
+
const [ref3, set] = (0, import_react7.useState)(define(value));
|
|
293
273
|
return ref3;
|
|
294
274
|
}
|
|
295
275
|
|
|
296
276
|
// src/hooks/useAsyncCallback.ts
|
|
297
|
-
var
|
|
277
|
+
var import_react8 = require("react");
|
|
298
278
|
function useAsyncCallback(fun) {
|
|
299
|
-
const [state, set] = (0,
|
|
279
|
+
const [state, set] = (0, import_react8.useState)({ loading: false });
|
|
300
280
|
async function execute(...args) {
|
|
301
281
|
set({ loading: true });
|
|
302
282
|
return fun(...args).then((value) => {
|
|
@@ -311,11 +291,11 @@ function useAsyncCallback(fun) {
|
|
|
311
291
|
}
|
|
312
292
|
|
|
313
293
|
// src/hooks/useAsyncState.ts
|
|
314
|
-
var
|
|
294
|
+
var import_react9 = require("react");
|
|
315
295
|
function useAsyncState(fun, deps = [], options) {
|
|
316
|
-
const [value, set] = (0,
|
|
296
|
+
const [value, set] = (0, import_react9.useState)(options?.initial);
|
|
317
297
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
318
|
-
(0,
|
|
298
|
+
(0, import_react9.useEffect)(
|
|
319
299
|
() => {
|
|
320
300
|
execute();
|
|
321
301
|
},
|
|
@@ -325,10 +305,10 @@ function useAsyncState(fun, deps = [], options) {
|
|
|
325
305
|
}
|
|
326
306
|
|
|
327
307
|
// src/hooks/useDebounce.ts
|
|
328
|
-
var
|
|
308
|
+
var import_react10 = require("react");
|
|
329
309
|
function useDebounce(value, delay) {
|
|
330
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
331
|
-
(0,
|
|
310
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react10.useState)(value);
|
|
311
|
+
(0, import_react10.useEffect)(() => {
|
|
332
312
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
333
313
|
return () => clearTimeout(handler);
|
|
334
314
|
}, [value, delay]);
|
|
@@ -337,14 +317,14 @@ function useDebounce(value, delay) {
|
|
|
337
317
|
|
|
338
318
|
// src/hooks/useEventBus.ts
|
|
339
319
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
340
|
-
var
|
|
320
|
+
var import_react11 = require("react");
|
|
341
321
|
var emitter = (0, import_mitt.default)();
|
|
342
322
|
function useEventBus(key) {
|
|
343
|
-
const onRef = (0,
|
|
323
|
+
const onRef = (0, import_react11.useRef)();
|
|
344
324
|
function on(listener) {
|
|
345
325
|
emitter.on(key, listener);
|
|
346
326
|
onRef.current = listener;
|
|
347
|
-
(0,
|
|
327
|
+
(0, import_react11.useEffect)(() => {
|
|
348
328
|
if (!onRef.current)
|
|
349
329
|
return;
|
|
350
330
|
emitter.off(key, onRef.current);
|
|
@@ -367,9 +347,9 @@ function useEventBus(key) {
|
|
|
367
347
|
}
|
|
368
348
|
|
|
369
349
|
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
370
|
-
var
|
|
350
|
+
var import_react12 = require("react");
|
|
371
351
|
var useEffectOnce = function(effect) {
|
|
372
|
-
(0,
|
|
352
|
+
(0, import_react12.useEffect)(effect, []);
|
|
373
353
|
};
|
|
374
354
|
var useEffectOnce_default = useEffectOnce;
|
|
375
355
|
|
|
@@ -405,23 +385,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
405
385
|
}
|
|
406
386
|
|
|
407
387
|
// src/hooks/useMounted.ts
|
|
408
|
-
var
|
|
388
|
+
var import_react13 = require("react");
|
|
409
389
|
function useMounted() {
|
|
410
|
-
const [mounted, setMounted] = (0,
|
|
411
|
-
(0,
|
|
390
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
391
|
+
(0, import_react13.useEffect)(() => setMounted(true), []);
|
|
412
392
|
return mounted;
|
|
413
393
|
}
|
|
414
394
|
|
|
415
395
|
// src/hooks/useWatch.ts
|
|
416
|
-
var
|
|
396
|
+
var import_react14 = require("react");
|
|
417
397
|
function useWatch(source, callback, options = {}) {
|
|
418
|
-
const firstUpdate = (0,
|
|
419
|
-
const then = (0,
|
|
420
|
-
const deps = (0,
|
|
398
|
+
const firstUpdate = (0, import_react14.useRef)(false);
|
|
399
|
+
const then = (0, import_react14.useRef)();
|
|
400
|
+
const deps = (0, import_react14.useMemo)(
|
|
421
401
|
() => Array.isArray(source) ? source : [source],
|
|
422
402
|
[source]
|
|
423
403
|
);
|
|
424
|
-
(0,
|
|
404
|
+
(0, import_react14.useEffect)(() => {
|
|
425
405
|
if (!firstUpdate.current)
|
|
426
406
|
recordFirst();
|
|
427
407
|
else
|
|
@@ -446,7 +426,7 @@ function useWhenever(source, cb, options) {
|
|
|
446
426
|
var import_utils10 = require("valtio/utils");
|
|
447
427
|
|
|
448
428
|
// src/storage/defineStore.ts
|
|
449
|
-
var
|
|
429
|
+
var import_react15 = require("react");
|
|
450
430
|
var import_valtio4 = require("valtio");
|
|
451
431
|
|
|
452
432
|
// src/storage/persistant.ts
|
|
@@ -500,10 +480,10 @@ function defineStore(store, options = {}) {
|
|
|
500
480
|
Object.assign($state, patch);
|
|
501
481
|
}
|
|
502
482
|
function $signal(fn) {
|
|
503
|
-
return (0,
|
|
483
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio4.useSnapshot)($state)));
|
|
504
484
|
}
|
|
505
485
|
$signal.status = function(fn) {
|
|
506
|
-
return (0,
|
|
486
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio4.useSnapshot)($status)));
|
|
507
487
|
};
|
|
508
488
|
return {
|
|
509
489
|
$subscribe,
|
|
@@ -624,7 +604,6 @@ function useStore(store) {
|
|
|
624
604
|
Injector,
|
|
625
605
|
Switch,
|
|
626
606
|
Then,
|
|
627
|
-
Trans,
|
|
628
607
|
Trigger,
|
|
629
608
|
Unless,
|
|
630
609
|
cls,
|
package/dist/index.d.ts
CHANGED
|
@@ -85,12 +85,6 @@ interface InjectorProps {
|
|
|
85
85
|
}
|
|
86
86
|
declare function Injector(props: InjectorProps): ReactNode;
|
|
87
87
|
|
|
88
|
-
interface TransProps {
|
|
89
|
-
i18nKey: string;
|
|
90
|
-
[key: string]: ReactNode;
|
|
91
|
-
}
|
|
92
|
-
declare function Trans({ i18nKey, ...additionalProps }: TransProps): ReactNode[];
|
|
93
|
-
|
|
94
88
|
interface Exposer {
|
|
95
89
|
deferred: Deferred<any>;
|
|
96
90
|
args: any[];
|
|
@@ -304,4 +298,4 @@ declare function useStore<S extends object, A extends Actions<S>, G extends Gett
|
|
|
304
298
|
|
|
305
299
|
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
306
300
|
|
|
307
|
-
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type Exposer, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray, type Ref, Switch, type SwitchProps, Then, type ThenProps,
|
|
301
|
+
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type Exposer, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray, type Ref, Switch, type SwitchProps, Then, type ThenProps, Trigger, Unless, type UnlessProps, type UseAsyncStateOptions, type Value, type WatchCallback, type WatchOptions, type WrapperProps, type WrapperTag, cls, defineAsyncStore, defineStore, proxyWithPersistant, ref, track, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStatus, useStore, useWatch, useWhenever, wrapper };
|
package/dist/index.global.js
CHANGED
|
@@ -39,37 +39,6 @@ var LibReact = (() => {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
// ../../node_modules/.pnpm/void-elements@3.1.0/node_modules/void-elements/index.js
|
|
43
|
-
var require_void_elements = __commonJS({
|
|
44
|
-
"../../node_modules/.pnpm/void-elements@3.1.0/node_modules/void-elements/index.js"(exports, module) {
|
|
45
|
-
"use strict";
|
|
46
|
-
module.exports = {
|
|
47
|
-
"area": true,
|
|
48
|
-
"base": true,
|
|
49
|
-
"br": true,
|
|
50
|
-
"col": true,
|
|
51
|
-
"embed": true,
|
|
52
|
-
"hr": true,
|
|
53
|
-
"img": true,
|
|
54
|
-
"input": true,
|
|
55
|
-
"link": true,
|
|
56
|
-
"meta": true,
|
|
57
|
-
"param": true,
|
|
58
|
-
"source": true,
|
|
59
|
-
"track": true,
|
|
60
|
-
"wbr": true
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// globals:react-i18next
|
|
66
|
-
var require_react_i18next = __commonJS({
|
|
67
|
-
"globals:react-i18next"(exports, module) {
|
|
68
|
-
"use strict";
|
|
69
|
-
module.exports = reactI18next;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
42
|
// src/index.ts
|
|
74
43
|
var index_exports = {};
|
|
75
44
|
__export(index_exports, {
|
|
@@ -80,7 +49,6 @@ var LibReact = (() => {
|
|
|
80
49
|
Injector: () => Injector,
|
|
81
50
|
Switch: () => Switch,
|
|
82
51
|
Then: () => Then,
|
|
83
|
-
Trans: () => Trans,
|
|
84
52
|
Trigger: () => Trigger,
|
|
85
53
|
Unless: () => Unless,
|
|
86
54
|
cls: () => cls,
|
|
@@ -107,8 +75,8 @@ var LibReact = (() => {
|
|
|
107
75
|
var hasOwn = {}.hasOwnProperty;
|
|
108
76
|
function cls(...args) {
|
|
109
77
|
let classes = "";
|
|
110
|
-
for (let
|
|
111
|
-
const arg = args[
|
|
78
|
+
for (let i = 0; i < args.length; i++) {
|
|
79
|
+
const arg = args[i];
|
|
112
80
|
if (arg)
|
|
113
81
|
classes = cls.append(classes, cls.parse(arg));
|
|
114
82
|
}
|
|
@@ -292,7 +260,7 @@ var LibReact = (() => {
|
|
|
292
260
|
var isAllOwnKeysChanged = (prevObj, nextObj) => {
|
|
293
261
|
const prevKeys = Reflect.ownKeys(prevObj);
|
|
294
262
|
const nextKeys = Reflect.ownKeys(nextObj);
|
|
295
|
-
return prevKeys.length !== nextKeys.length || prevKeys.some((k,
|
|
263
|
+
return prevKeys.length !== nextKeys.length || prevKeys.some((k, i) => k !== nextKeys[i]);
|
|
296
264
|
};
|
|
297
265
|
var isChanged = (prevObj, nextObj, affected, cache, isEqual = Object.is) => {
|
|
298
266
|
if (isEqual(prevObj, nextObj)) {
|
|
@@ -660,7 +628,7 @@ var LibReact = (() => {
|
|
|
660
628
|
)) {
|
|
661
629
|
return lastSnapshot.current;
|
|
662
630
|
}
|
|
663
|
-
} catch (
|
|
631
|
+
} catch (e) {
|
|
664
632
|
}
|
|
665
633
|
return nextSnapshot;
|
|
666
634
|
},
|
|
@@ -717,8 +685,8 @@ var LibReact = (() => {
|
|
|
717
685
|
function If(props) {
|
|
718
686
|
const { then, cond, else: _else, children = props.then, tag, ...attrs } = props;
|
|
719
687
|
const elements = import_react3.Children.toArray(children);
|
|
720
|
-
const thenChild = elements.find((
|
|
721
|
-
const elseChild = elements.find((
|
|
688
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
689
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
722
690
|
const child = thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else;
|
|
723
691
|
return wrapper(tag, attrs, child);
|
|
724
692
|
}
|
|
@@ -756,8 +724,8 @@ var LibReact = (() => {
|
|
|
756
724
|
function Unless(props) {
|
|
757
725
|
const { cond, then, else: _else, tag, children = props.then, ...attrs } = props;
|
|
758
726
|
const elements = import_react5.Children.toArray(children);
|
|
759
|
-
const thenChild = elements.find((
|
|
760
|
-
const elseChild = elements.find((
|
|
727
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
728
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
761
729
|
const child = thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else;
|
|
762
730
|
return wrapper(tag, attrs, child);
|
|
763
731
|
}
|
|
@@ -774,92 +742,12 @@ var LibReact = (() => {
|
|
|
774
742
|
props.children
|
|
775
743
|
);
|
|
776
744
|
}
|
|
777
|
-
function repack(
|
|
778
|
-
return
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// ../../node_modules/.pnpm/html-parse-stringify@3.0.1/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js
|
|
782
|
-
var import_void_elements = __toESM(require_void_elements());
|
|
783
|
-
var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
784
|
-
function n(n2) {
|
|
785
|
-
var r2 = { type: "tag", name: "", voidElement: false, attrs: {}, children: [] }, i2 = n2.match(/<\/?([^\s]+?)[/\s>]/);
|
|
786
|
-
if (i2 && (r2.name = i2[1], (import_void_elements.default[i2[1]] || "/" === n2.charAt(n2.length - 2)) && (r2.voidElement = true), r2.name.startsWith("!--"))) {
|
|
787
|
-
var s2 = n2.indexOf("-->");
|
|
788
|
-
return { type: "comment", comment: -1 !== s2 ? n2.slice(4, s2) : "" };
|
|
789
|
-
}
|
|
790
|
-
for (var a2 = new RegExp(t), c2 = null; null !== (c2 = a2.exec(n2)); ) if (c2[0].trim()) if (c2[1]) {
|
|
791
|
-
var o = c2[1].trim(), l = [o, ""];
|
|
792
|
-
o.indexOf("=") > -1 && (l = o.split("=")), r2.attrs[l[0]] = l[1], a2.lastIndex--;
|
|
793
|
-
} else c2[2] && (r2.attrs[c2[2]] = c2[3].trim().substring(1, c2[3].length - 1));
|
|
794
|
-
return r2;
|
|
795
|
-
}
|
|
796
|
-
var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g;
|
|
797
|
-
var i = /^\s*$/;
|
|
798
|
-
var s = /* @__PURE__ */ Object.create(null);
|
|
799
|
-
function a(e2, t2) {
|
|
800
|
-
switch (t2.type) {
|
|
801
|
-
case "text":
|
|
802
|
-
return e2 + t2.content;
|
|
803
|
-
case "tag":
|
|
804
|
-
return e2 += "<" + t2.name + (t2.attrs ? function(e3) {
|
|
805
|
-
var t3 = [];
|
|
806
|
-
for (var n2 in e3) t3.push(n2 + '="' + e3[n2] + '"');
|
|
807
|
-
return t3.length ? " " + t3.join(" ") : "";
|
|
808
|
-
}(t2.attrs) : "") + (t2.voidElement ? "/>" : ">"), t2.voidElement ? e2 : e2 + t2.children.reduce(a, "") + "</" + t2.name + ">";
|
|
809
|
-
case "comment":
|
|
810
|
-
return e2 + "<!--" + t2.comment + "-->";
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
var c = { parse: function(e2, t2) {
|
|
814
|
-
t2 || (t2 = {}), t2.components || (t2.components = s);
|
|
815
|
-
var a2, c2 = [], o = [], l = -1, m = false;
|
|
816
|
-
if (0 !== e2.indexOf("<")) {
|
|
817
|
-
var u = e2.indexOf("<");
|
|
818
|
-
c2.push({ type: "text", content: -1 === u ? e2 : e2.substring(0, u) });
|
|
819
|
-
}
|
|
820
|
-
return e2.replace(r, function(r2, s2) {
|
|
821
|
-
if (m) {
|
|
822
|
-
if (r2 !== "</" + a2.name + ">") return;
|
|
823
|
-
m = false;
|
|
824
|
-
}
|
|
825
|
-
var u2, f = "/" !== r2.charAt(1), h = r2.startsWith("<!--"), p = s2 + r2.length, d = e2.charAt(p);
|
|
826
|
-
if (h) {
|
|
827
|
-
var v = n(r2);
|
|
828
|
-
return l < 0 ? (c2.push(v), c2) : ((u2 = o[l]).children.push(v), c2);
|
|
829
|
-
}
|
|
830
|
-
if (f && (l++, "tag" === (a2 = n(r2)).type && t2.components[a2.name] && (a2.type = "component", m = true), a2.voidElement || m || !d || "<" === d || a2.children.push({ type: "text", content: e2.slice(p, e2.indexOf("<", p)) }), 0 === l && c2.push(a2), (u2 = o[l - 1]) && u2.children.push(a2), o[l] = a2), (!f || a2.voidElement) && (l > -1 && (a2.voidElement || a2.name === r2.slice(2, -1)) && (l--, a2 = -1 === l ? c2 : o[l]), !m && "<" !== d && d)) {
|
|
831
|
-
u2 = -1 === l ? c2 : o[l].children;
|
|
832
|
-
var x = e2.indexOf("<", p), g = e2.slice(p, -1 === x ? void 0 : x);
|
|
833
|
-
i.test(g) && (g = " "), (x > -1 && l + u2.length >= 0 || " " !== g) && u2.push({ type: "text", content: g });
|
|
834
|
-
}
|
|
835
|
-
}), c2;
|
|
836
|
-
}, stringify: function(e2) {
|
|
837
|
-
return e2.reduce(function(e3, t2) {
|
|
838
|
-
return e3 + a("", t2);
|
|
839
|
-
}, "");
|
|
840
|
-
} };
|
|
841
|
-
var html_parse_stringify_module_default = c;
|
|
842
|
-
|
|
843
|
-
// src/components/utils/Trans.ts
|
|
844
|
-
var import_react7 = __toESM(require_react(), 1);
|
|
845
|
-
var import_react_i18next = __toESM(require_react_i18next(), 1);
|
|
846
|
-
function Trans({ i18nKey, ...additionalProps }) {
|
|
847
|
-
const translation = (0, import_react_i18next.useTranslation)().t(i18nKey, additionalProps);
|
|
848
|
-
return renderNodes(html_parse_stringify_module_default.parse(translation), additionalProps);
|
|
849
|
-
}
|
|
850
|
-
function renderNodes(tokens, values) {
|
|
851
|
-
let index = 0;
|
|
852
|
-
return tokens.map((token) => {
|
|
853
|
-
if (token.type === "text")
|
|
854
|
-
return token.content;
|
|
855
|
-
index++;
|
|
856
|
-
const props = { ...token.attrs, key: index };
|
|
857
|
-
return token.voidElement ? values[token.name] ? (0, import_react7.createElement)("span", { key: index }, values[token.name]) : (0, import_react7.createElement)(token.name, props) : (0, import_react7.createElement)(token.name, props, renderNodes(token.children, {}));
|
|
858
|
-
});
|
|
745
|
+
function repack(c) {
|
|
746
|
+
return c.component ? c : { component: c };
|
|
859
747
|
}
|
|
860
748
|
|
|
861
749
|
// src/components/utils/Trigger.ts
|
|
862
|
-
var
|
|
750
|
+
var import_react7 = __toESM(require_react(), 1);
|
|
863
751
|
|
|
864
752
|
// ../../node_modules/.pnpm/valtio@2.1.4_@types+react@18.3.18_react@18.3.1/node_modules/valtio/esm/vanilla/utils.mjs
|
|
865
753
|
var currentCleanups;
|
|
@@ -1073,7 +961,7 @@ var LibReact = (() => {
|
|
|
1073
961
|
return Component;
|
|
1074
962
|
}
|
|
1075
963
|
function renderTracker(Tracker) {
|
|
1076
|
-
return (0,
|
|
964
|
+
return (0, import_react7.createElement)(Tracker, { key: Tracker.key });
|
|
1077
965
|
}
|
|
1078
966
|
function Trigger() {
|
|
1079
967
|
const values = [...useSnapshot(pendingTasks).values()];
|
|
@@ -1083,7 +971,7 @@ var LibReact = (() => {
|
|
|
1083
971
|
Trigger.tasks = pendingTasks;
|
|
1084
972
|
|
|
1085
973
|
// src/hooks/ref.ts
|
|
1086
|
-
var
|
|
974
|
+
var import_react8 = __toESM(require_react(), 1);
|
|
1087
975
|
function ref2(value) {
|
|
1088
976
|
function define(value2) {
|
|
1089
977
|
if (typeof value2 === "function")
|
|
@@ -1094,14 +982,14 @@ var LibReact = (() => {
|
|
|
1094
982
|
enumerable: true
|
|
1095
983
|
});
|
|
1096
984
|
}
|
|
1097
|
-
const [ref3, set] = (0,
|
|
985
|
+
const [ref3, set] = (0, import_react8.useState)(define(value));
|
|
1098
986
|
return ref3;
|
|
1099
987
|
}
|
|
1100
988
|
|
|
1101
989
|
// src/hooks/useAsyncCallback.ts
|
|
1102
|
-
var
|
|
990
|
+
var import_react9 = __toESM(require_react(), 1);
|
|
1103
991
|
function useAsyncCallback(fun) {
|
|
1104
|
-
const [state, set] = (0,
|
|
992
|
+
const [state, set] = (0, import_react9.useState)({ loading: false });
|
|
1105
993
|
async function execute(...args) {
|
|
1106
994
|
set({ loading: true });
|
|
1107
995
|
return fun(...args).then((value) => {
|
|
@@ -1116,11 +1004,11 @@ var LibReact = (() => {
|
|
|
1116
1004
|
}
|
|
1117
1005
|
|
|
1118
1006
|
// src/hooks/useAsyncState.ts
|
|
1119
|
-
var
|
|
1007
|
+
var import_react10 = __toESM(require_react(), 1);
|
|
1120
1008
|
function useAsyncState(fun, deps = [], options) {
|
|
1121
|
-
const [value, set] = (0,
|
|
1009
|
+
const [value, set] = (0, import_react10.useState)(options?.initial);
|
|
1122
1010
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
1123
|
-
(0,
|
|
1011
|
+
(0, import_react10.useEffect)(
|
|
1124
1012
|
() => {
|
|
1125
1013
|
execute();
|
|
1126
1014
|
},
|
|
@@ -1130,10 +1018,10 @@ var LibReact = (() => {
|
|
|
1130
1018
|
}
|
|
1131
1019
|
|
|
1132
1020
|
// src/hooks/useDebounce.ts
|
|
1133
|
-
var
|
|
1021
|
+
var import_react11 = __toESM(require_react(), 1);
|
|
1134
1022
|
function useDebounce(value, delay) {
|
|
1135
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
1136
|
-
(0,
|
|
1023
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react11.useState)(value);
|
|
1024
|
+
(0, import_react11.useEffect)(() => {
|
|
1137
1025
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
1138
1026
|
return () => clearTimeout(handler);
|
|
1139
1027
|
}, [value, delay]);
|
|
@@ -1141,32 +1029,32 @@ var LibReact = (() => {
|
|
|
1141
1029
|
}
|
|
1142
1030
|
|
|
1143
1031
|
// ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
1144
|
-
function mitt_default(
|
|
1145
|
-
return { all:
|
|
1146
|
-
var
|
|
1147
|
-
|
|
1148
|
-
}, off: function(
|
|
1149
|
-
var
|
|
1150
|
-
|
|
1151
|
-
}, emit: function(
|
|
1152
|
-
var
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
}), (
|
|
1156
|
-
|
|
1032
|
+
function mitt_default(n) {
|
|
1033
|
+
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
1034
|
+
var i = n.get(t);
|
|
1035
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
1036
|
+
}, off: function(t, e) {
|
|
1037
|
+
var i = n.get(t);
|
|
1038
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
1039
|
+
}, emit: function(t, e) {
|
|
1040
|
+
var i = n.get(t);
|
|
1041
|
+
i && i.slice().map(function(n2) {
|
|
1042
|
+
n2(e);
|
|
1043
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
1044
|
+
n2(t, e);
|
|
1157
1045
|
});
|
|
1158
1046
|
} };
|
|
1159
1047
|
}
|
|
1160
1048
|
|
|
1161
1049
|
// src/hooks/useEventBus.ts
|
|
1162
|
-
var
|
|
1050
|
+
var import_react12 = __toESM(require_react(), 1);
|
|
1163
1051
|
var emitter = mitt_default();
|
|
1164
1052
|
function useEventBus(key) {
|
|
1165
|
-
const onRef = (0,
|
|
1053
|
+
const onRef = (0, import_react12.useRef)();
|
|
1166
1054
|
function on(listener) {
|
|
1167
1055
|
emitter.on(key, listener);
|
|
1168
1056
|
onRef.current = listener;
|
|
1169
|
-
(0,
|
|
1057
|
+
(0, import_react12.useEffect)(() => {
|
|
1170
1058
|
if (!onRef.current)
|
|
1171
1059
|
return;
|
|
1172
1060
|
emitter.off(key, onRef.current);
|
|
@@ -1189,9 +1077,9 @@ var LibReact = (() => {
|
|
|
1189
1077
|
}
|
|
1190
1078
|
|
|
1191
1079
|
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
1192
|
-
var
|
|
1080
|
+
var import_react13 = __toESM(require_react());
|
|
1193
1081
|
var useEffectOnce = function(effect) {
|
|
1194
|
-
(0,
|
|
1082
|
+
(0, import_react13.useEffect)(effect, []);
|
|
1195
1083
|
};
|
|
1196
1084
|
var useEffectOnce_default = useEffectOnce;
|
|
1197
1085
|
|
|
@@ -1227,23 +1115,23 @@ var LibReact = (() => {
|
|
|
1227
1115
|
}
|
|
1228
1116
|
|
|
1229
1117
|
// src/hooks/useMounted.ts
|
|
1230
|
-
var
|
|
1118
|
+
var import_react14 = __toESM(require_react(), 1);
|
|
1231
1119
|
function useMounted() {
|
|
1232
|
-
const [mounted, setMounted] = (0,
|
|
1233
|
-
(0,
|
|
1120
|
+
const [mounted, setMounted] = (0, import_react14.useState)(false);
|
|
1121
|
+
(0, import_react14.useEffect)(() => setMounted(true), []);
|
|
1234
1122
|
return mounted;
|
|
1235
1123
|
}
|
|
1236
1124
|
|
|
1237
1125
|
// src/hooks/useWatch.ts
|
|
1238
|
-
var
|
|
1126
|
+
var import_react15 = __toESM(require_react(), 1);
|
|
1239
1127
|
function useWatch(source, callback, options = {}) {
|
|
1240
|
-
const firstUpdate = (0,
|
|
1241
|
-
const then = (0,
|
|
1242
|
-
const deps = (0,
|
|
1128
|
+
const firstUpdate = (0, import_react15.useRef)(false);
|
|
1129
|
+
const then = (0, import_react15.useRef)();
|
|
1130
|
+
const deps = (0, import_react15.useMemo)(
|
|
1243
1131
|
() => Array.isArray(source) ? source : [source],
|
|
1244
1132
|
[source]
|
|
1245
1133
|
);
|
|
1246
|
-
(0,
|
|
1134
|
+
(0, import_react15.useEffect)(() => {
|
|
1247
1135
|
if (!firstUpdate.current)
|
|
1248
1136
|
recordFirst();
|
|
1249
1137
|
else
|
|
@@ -1265,7 +1153,7 @@ var LibReact = (() => {
|
|
|
1265
1153
|
}
|
|
1266
1154
|
|
|
1267
1155
|
// src/storage/defineStore.ts
|
|
1268
|
-
var
|
|
1156
|
+
var import_react16 = __toESM(require_react(), 1);
|
|
1269
1157
|
|
|
1270
1158
|
// src/storage/persistant.ts
|
|
1271
1159
|
function proxyWithPersistant(keyOrOptions, initialObject) {
|
|
@@ -1317,10 +1205,10 @@ var LibReact = (() => {
|
|
|
1317
1205
|
Object.assign($state, patch);
|
|
1318
1206
|
}
|
|
1319
1207
|
function $signal(fn) {
|
|
1320
|
-
return (0,
|
|
1208
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($state)));
|
|
1321
1209
|
}
|
|
1322
1210
|
$signal.status = function(fn) {
|
|
1323
|
-
return (0,
|
|
1211
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($status)));
|
|
1324
1212
|
};
|
|
1325
1213
|
return {
|
|
1326
1214
|
$subscribe,
|
package/dist/index.js
CHANGED
|
@@ -168,27 +168,8 @@ function repack(c) {
|
|
|
168
168
|
return c.component ? c : { component: c };
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
// src/components/utils/Trans.ts
|
|
172
|
-
import HTML from "html-parse-stringify";
|
|
173
|
-
import { createElement as createElement3 } from "react";
|
|
174
|
-
import { useTranslation } from "react-i18next";
|
|
175
|
-
function Trans({ i18nKey, ...additionalProps }) {
|
|
176
|
-
const translation = useTranslation().t(i18nKey, additionalProps);
|
|
177
|
-
return renderNodes(HTML.parse(translation), additionalProps);
|
|
178
|
-
}
|
|
179
|
-
function renderNodes(tokens, values) {
|
|
180
|
-
let index = 0;
|
|
181
|
-
return tokens.map((token) => {
|
|
182
|
-
if (token.type === "text")
|
|
183
|
-
return token.content;
|
|
184
|
-
index++;
|
|
185
|
-
const props = { ...token.attrs, key: index };
|
|
186
|
-
return token.voidElement ? values[token.name] ? createElement3("span", { key: index }, values[token.name]) : createElement3(token.name, props) : createElement3(token.name, props, renderNodes(token.children, {}));
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
171
|
// src/components/utils/Trigger.ts
|
|
191
|
-
import { createElement as
|
|
172
|
+
import { createElement as createElement3 } from "react";
|
|
192
173
|
import { useSnapshot } from "valtio";
|
|
193
174
|
import { proxyMap } from "valtio/utils";
|
|
194
175
|
var pendingTasks = proxyMap();
|
|
@@ -205,7 +186,7 @@ function createTracker(exposer) {
|
|
|
205
186
|
return Component;
|
|
206
187
|
}
|
|
207
188
|
function renderTracker(Tracker) {
|
|
208
|
-
return
|
|
189
|
+
return createElement3(Tracker, { key: Tracker.key });
|
|
209
190
|
}
|
|
210
191
|
function Trigger() {
|
|
211
192
|
const values = [...useSnapshot(pendingTasks).values()];
|
|
@@ -383,7 +364,7 @@ function useWhenever(source, cb, options) {
|
|
|
383
364
|
import { watch } from "valtio/utils";
|
|
384
365
|
|
|
385
366
|
// src/storage/defineStore.ts
|
|
386
|
-
import { createElement as
|
|
367
|
+
import { createElement as createElement4 } from "react";
|
|
387
368
|
import { proxy as proxy2, subscribe as subscribe2, useSnapshot as useSnapshot2 } from "valtio";
|
|
388
369
|
|
|
389
370
|
// src/storage/persistant.ts
|
|
@@ -437,10 +418,10 @@ function defineStore(store, options = {}) {
|
|
|
437
418
|
Object.assign($state, patch);
|
|
438
419
|
}
|
|
439
420
|
function $signal(fn) {
|
|
440
|
-
return
|
|
421
|
+
return createElement4(() => fn(useSnapshot2($state)));
|
|
441
422
|
}
|
|
442
423
|
$signal.status = function(fn) {
|
|
443
|
-
return
|
|
424
|
+
return createElement4(() => fn(useSnapshot2($status)));
|
|
444
425
|
};
|
|
445
426
|
return {
|
|
446
427
|
$subscribe,
|
|
@@ -560,7 +541,6 @@ export {
|
|
|
560
541
|
Injector,
|
|
561
542
|
Switch,
|
|
562
543
|
Then,
|
|
563
|
-
Trans,
|
|
564
544
|
Trigger,
|
|
565
545
|
Unless,
|
|
566
546
|
cls,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/react-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.26.0",
|
|
5
5
|
"description": "Library for react",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.2.0",
|
|
39
39
|
"react-i18next": "^14.1.2",
|
|
40
40
|
"react-use": "^17.6.0",
|
|
41
|
-
"@hairy/utils": "1.
|
|
41
|
+
"@hairy/utils": "1.26.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|