frosty 0.0.155 → 0.0.156
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/_native.js +3 -3
- package/dist/dom.js +3 -3
- package/dist/i18n.d.mts +38 -0
- package/dist/i18n.d.mts.map +1 -0
- package/dist/i18n.d.ts +38 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +79 -0
- package/dist/i18n.js.map +1 -0
- package/dist/i18n.mjs +72 -0
- package/dist/i18n.mjs.map +1 -0
- package/dist/index.js +47 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internals/callback-DEKCuARB.mjs +170 -0
- package/dist/internals/callback-DEKCuARB.mjs.map +1 -0
- package/dist/internals/callback-DVD1MTA9.js +180 -0
- package/dist/internals/callback-DVD1MTA9.js.map +1 -0
- package/dist/internals/{events-BgboMOG9.js → events-CcBnpWOF.js} +7 -3
- package/dist/internals/{events-BgboMOG9.js.map → events-CcBnpWOF.js.map} +1 -1
- package/dist/internals/{form-BGe5OdHZ.js → form-CC8A5nkh.js} +40 -205
- package/dist/internals/form-CC8A5nkh.js.map +1 -0
- package/dist/internals/{form-RKmiM_eK.mjs → form-Cee86QUZ.mjs} +4 -168
- package/dist/internals/form-Cee86QUZ.mjs.map +1 -0
- package/dist/internals/{index-CHID44Lo.js → index-Bvwj3lIq.js} +39 -35
- package/dist/internals/{index-CHID44Lo.js.map → index-Bvwj3lIq.js.map} +1 -1
- package/dist/internals/{renderer-CFxFx-Ik.js → renderer-C5NIsxDg.js} +67 -61
- package/dist/internals/{renderer-CFxFx-Ik.js.map → renderer-C5NIsxDg.js.map} +1 -1
- package/dist/internals/{renderer-ijDmCUMe.js → renderer-DR_CVQzd.js} +16 -11
- package/dist/internals/{renderer-ijDmCUMe.js.map → renderer-DR_CVQzd.js.map} +1 -1
- package/dist/server-dom.js +3 -3
- package/dist/web.js +31 -26
- package/dist/web.js.map +1 -1
- package/dist/web.mjs +2 -1
- package/dist/web.mjs.map +1 -1
- package/package.json +2 -1
- package/packages/frosty-cli/webpack.mjs +2 -2
- package/packages/frosty-cli/yarn.lock +3 -3
- package/dist/internals/form-BGe5OdHZ.js.map +0 -1
- package/dist/internals/form-RKmiM_eK.mjs.map +0 -1
package/dist/_native.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var runtime = require('./internals/runtime-CeVOFcK_.js');
|
|
4
|
-
var renderer = require('./internals/renderer-
|
|
5
|
-
var index = require('./internals/index-
|
|
6
|
-
var events = require('./internals/events-
|
|
4
|
+
var renderer = require('./internals/renderer-DR_CVQzd.js');
|
|
5
|
+
var index = require('./internals/index-Bvwj3lIq.js');
|
|
6
|
+
var events = require('./internals/events-CcBnpWOF.js');
|
|
7
7
|
require('lodash');
|
|
8
8
|
require('nextick');
|
|
9
9
|
require('myers.js');
|
package/dist/dom.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var renderer = require('./internals/renderer-
|
|
3
|
+
var renderer = require('./internals/renderer-C5NIsxDg.js');
|
|
4
4
|
require('lodash');
|
|
5
5
|
require('myers.js');
|
|
6
|
-
require('./internals/renderer-
|
|
7
|
-
require('./internals/index-
|
|
6
|
+
require('./internals/renderer-DR_CVQzd.js');
|
|
7
|
+
require('./internals/index-Bvwj3lIq.js');
|
|
8
8
|
require('./internals/runtime-CeVOFcK_.js');
|
|
9
9
|
require('nextick');
|
|
10
10
|
require('postcss');
|
package/dist/i18n.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { Opts } from '@formatjs/intl-localematcher';
|
|
3
|
+
|
|
4
|
+
type I18nStateOPts = Partial<Opts> & {
|
|
5
|
+
locales: string[];
|
|
6
|
+
availableLocales: string[];
|
|
7
|
+
preferredLocale?: string;
|
|
8
|
+
fallback: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A hook that provides the current i18n state based on the provided options.
|
|
12
|
+
*
|
|
13
|
+
* @param opts - An object containing the following properties:
|
|
14
|
+
* - `locales`: An array of preferred locales.
|
|
15
|
+
* - `availableLocales`: An array of available locales.
|
|
16
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
17
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
18
|
+
* - Additional options for locale matching can be provided as well.
|
|
19
|
+
*
|
|
20
|
+
* @returns The matched locale string based on the provided options.
|
|
21
|
+
*/
|
|
22
|
+
declare const useI18nState: (opts: I18nStateOPts) => string;
|
|
23
|
+
/**
|
|
24
|
+
* A hook that provides a localization function based on the current i18n state.
|
|
25
|
+
*
|
|
26
|
+
* @param opts - An object containing the following properties:
|
|
27
|
+
* - `locales`: An array of preferred locales.
|
|
28
|
+
* - `availableLocales`: An array of available locales.
|
|
29
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
30
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
31
|
+
* - Additional options for locale matching can be provided as well.
|
|
32
|
+
*
|
|
33
|
+
* @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.
|
|
34
|
+
*/
|
|
35
|
+
declare const useLocalize: (opts: I18nStateOPts) => <TObject extends unknown>(strings: Record<string, TObject>, selector?: _.PropertyPath) => any;
|
|
36
|
+
|
|
37
|
+
export { useI18nState, useLocalize };
|
|
38
|
+
//# sourceMappingURL=i18n.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.mts","sources":["../src/i18n/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { match, Opts } from '@formatjs/intl-localematcher';\nimport { useMemo } from '../core/hooks/memo';\nimport { useCallback } from '../core/hooks/callback';\n\ntype I18nStateOPts = Partial<Opts> & {\n locales: string[];\n availableLocales: string[];\n preferredLocale?: string;\n fallback: string;\n};\n\n/**\n * A hook that provides the current i18n state based on the provided options.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n *\n * @returns The matched locale string based on the provided options.\n */\nexport const useI18nState = (opts: I18nStateOPts) => useMemo(() => {\n const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;\n if (preferredLocale && _.includes(availableLocales, preferredLocale)) {\n return preferredLocale;\n }\n return match(locales, availableLocales, defaultLocale, {\n algorithm: 'best fit',\n ...options,\n });\n}, [opts]);\n\n/**\n * A hook that provides a localization function based on the current i18n state.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n * \n * @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.\n */\nexport const useLocalize = (opts: I18nStateOPts) => {\n const i18nState = useI18nState(opts);\n return useCallback(<TObject extends unknown>(\n strings: Record<string, TObject>,\n selector?: _.PropertyPath,\n ) => selector ? _.get(strings[i18nState], selector) : strings[i18nState]);\n};"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;;"}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { Opts } from '@formatjs/intl-localematcher';
|
|
3
|
+
|
|
4
|
+
type I18nStateOPts = Partial<Opts> & {
|
|
5
|
+
locales: string[];
|
|
6
|
+
availableLocales: string[];
|
|
7
|
+
preferredLocale?: string;
|
|
8
|
+
fallback: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A hook that provides the current i18n state based on the provided options.
|
|
12
|
+
*
|
|
13
|
+
* @param opts - An object containing the following properties:
|
|
14
|
+
* - `locales`: An array of preferred locales.
|
|
15
|
+
* - `availableLocales`: An array of available locales.
|
|
16
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
17
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
18
|
+
* - Additional options for locale matching can be provided as well.
|
|
19
|
+
*
|
|
20
|
+
* @returns The matched locale string based on the provided options.
|
|
21
|
+
*/
|
|
22
|
+
declare const useI18nState: (opts: I18nStateOPts) => string;
|
|
23
|
+
/**
|
|
24
|
+
* A hook that provides a localization function based on the current i18n state.
|
|
25
|
+
*
|
|
26
|
+
* @param opts - An object containing the following properties:
|
|
27
|
+
* - `locales`: An array of preferred locales.
|
|
28
|
+
* - `availableLocales`: An array of available locales.
|
|
29
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
30
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
31
|
+
* - Additional options for locale matching can be provided as well.
|
|
32
|
+
*
|
|
33
|
+
* @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.
|
|
34
|
+
*/
|
|
35
|
+
declare const useLocalize: (opts: I18nStateOPts) => <TObject extends unknown>(strings: Record<string, TObject>, selector?: _.PropertyPath) => any;
|
|
36
|
+
|
|
37
|
+
export { useI18nState, useLocalize };
|
|
38
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sources":["../src/i18n/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { match, Opts } from '@formatjs/intl-localematcher';\nimport { useMemo } from '../core/hooks/memo';\nimport { useCallback } from '../core/hooks/callback';\n\ntype I18nStateOPts = Partial<Opts> & {\n locales: string[];\n availableLocales: string[];\n preferredLocale?: string;\n fallback: string;\n};\n\n/**\n * A hook that provides the current i18n state based on the provided options.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n *\n * @returns The matched locale string based on the provided options.\n */\nexport const useI18nState = (opts: I18nStateOPts) => useMemo(() => {\n const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;\n if (preferredLocale && _.includes(availableLocales, preferredLocale)) {\n return preferredLocale;\n }\n return match(locales, availableLocales, defaultLocale, {\n algorithm: 'best fit',\n ...options,\n });\n}, [opts]);\n\n/**\n * A hook that provides a localization function based on the current i18n state.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n * \n * @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.\n */\nexport const useLocalize = (opts: I18nStateOPts) => {\n const i18nState = useI18nState(opts);\n return useCallback(<TObject extends unknown>(\n strings: Record<string, TObject>,\n selector?: _.PropertyPath,\n ) => selector ? _.get(strings[i18nState], selector) : strings[i18nState]);\n};"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;;"}
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var intlLocalematcher = require('@formatjs/intl-localematcher');
|
|
5
|
+
var callback = require('./internals/callback-DVD1MTA9.js');
|
|
6
|
+
require('./internals/index-Bvwj3lIq.js');
|
|
7
|
+
require('./internals/runtime-CeVOFcK_.js');
|
|
8
|
+
require('myers.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
13
|
+
|
|
14
|
+
//
|
|
15
|
+
// index.ts
|
|
16
|
+
//
|
|
17
|
+
// The MIT License
|
|
18
|
+
// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
22
|
+
// in the Software without restriction, including without limitation the rights
|
|
23
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
25
|
+
// furnished to do so, subject to the following conditions:
|
|
26
|
+
//
|
|
27
|
+
// The above copyright notice and this permission notice shall be included in
|
|
28
|
+
// all copies or substantial portions of the Software.
|
|
29
|
+
//
|
|
30
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
36
|
+
// THE SOFTWARE.
|
|
37
|
+
//
|
|
38
|
+
/**
|
|
39
|
+
* A hook that provides the current i18n state based on the provided options.
|
|
40
|
+
*
|
|
41
|
+
* @param opts - An object containing the following properties:
|
|
42
|
+
* - `locales`: An array of preferred locales.
|
|
43
|
+
* - `availableLocales`: An array of available locales.
|
|
44
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
45
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
46
|
+
* - Additional options for locale matching can be provided as well.
|
|
47
|
+
*
|
|
48
|
+
* @returns The matched locale string based on the provided options.
|
|
49
|
+
*/
|
|
50
|
+
const useI18nState = (opts) => callback.useMemo(() => {
|
|
51
|
+
const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;
|
|
52
|
+
if (preferredLocale && ___default.default.includes(availableLocales, preferredLocale)) {
|
|
53
|
+
return preferredLocale;
|
|
54
|
+
}
|
|
55
|
+
return intlLocalematcher.match(locales, availableLocales, defaultLocale, {
|
|
56
|
+
algorithm: 'best fit',
|
|
57
|
+
...options,
|
|
58
|
+
});
|
|
59
|
+
}, [opts]);
|
|
60
|
+
/**
|
|
61
|
+
* A hook that provides a localization function based on the current i18n state.
|
|
62
|
+
*
|
|
63
|
+
* @param opts - An object containing the following properties:
|
|
64
|
+
* - `locales`: An array of preferred locales.
|
|
65
|
+
* - `availableLocales`: An array of available locales.
|
|
66
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
67
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
68
|
+
* - Additional options for locale matching can be provided as well.
|
|
69
|
+
*
|
|
70
|
+
* @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.
|
|
71
|
+
*/
|
|
72
|
+
const useLocalize = (opts) => {
|
|
73
|
+
const i18nState = useI18nState(opts);
|
|
74
|
+
return callback.useCallback((strings, selector) => selector ? ___default.default.get(strings[i18nState], selector) : strings[i18nState]);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.useI18nState = useI18nState;
|
|
78
|
+
exports.useLocalize = useLocalize;
|
|
79
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sources":["../../src/i18n/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { match, Opts } from '@formatjs/intl-localematcher';\nimport { useMemo } from '../core/hooks/memo';\nimport { useCallback } from '../core/hooks/callback';\n\ntype I18nStateOPts = Partial<Opts> & {\n locales: string[];\n availableLocales: string[];\n preferredLocale?: string;\n fallback: string;\n};\n\n/**\n * A hook that provides the current i18n state based on the provided options.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n *\n * @returns The matched locale string based on the provided options.\n */\nexport const useI18nState = (opts: I18nStateOPts) => useMemo(() => {\n const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;\n if (preferredLocale && _.includes(availableLocales, preferredLocale)) {\n return preferredLocale;\n }\n return match(locales, availableLocales, defaultLocale, {\n algorithm: 'best fit',\n ...options,\n });\n}, [opts]);\n\n/**\n * A hook that provides a localization function based on the current i18n state.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n * \n * @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.\n */\nexport const useLocalize = (opts: I18nStateOPts) => {\n const i18nState = useI18nState(opts);\n return useCallback(<TObject extends unknown>(\n strings: Record<string, TObject>,\n selector?: _.PropertyPath,\n ) => selector ? _.get(strings[i18nState], selector) : strings[i18nState]);\n};"],"names":["useMemo","_","match","useCallback"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcA;;;;;;;;;;;AAWG;AACI,MAAM,YAAY,GAAG,CAAC,IAAmB,KAAKA,gBAAO,CAAC,MAAK;AAChE,IAAA,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI;IAChG,IAAI,eAAe,IAAIC,kBAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC,EAAE;AACpE,QAAA,OAAO,eAAe;IACxB;AACA,IAAA,OAAOC,uBAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE;AACrD,QAAA,SAAS,EAAE,UAAU;AACrB,QAAA,GAAG,OAAO;AACX,KAAA,CAAC;AACJ,CAAC,EAAE,CAAC,IAAI,CAAC;AAET;;;;;;;;;;;AAWG;AACI,MAAM,WAAW,GAAG,CAAC,IAAmB,KAAI;AACjD,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC;AACpC,IAAA,OAAOC,oBAAW,CAAC,CACjB,OAAgC,EAChC,QAAyB,KACtB,QAAQ,GAAGF,kBAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAC3E;;;;;"}
|
package/dist/i18n.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { match } from '@formatjs/intl-localematcher';
|
|
3
|
+
import { c as useMemo, u as useCallback } from './internals/callback-DEKCuARB.mjs';
|
|
4
|
+
import './internals/index-CODWK-gF.mjs';
|
|
5
|
+
import './internals/runtime-Bpq-U9sI.mjs';
|
|
6
|
+
import 'myers.js';
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
// index.ts
|
|
10
|
+
//
|
|
11
|
+
// The MIT License
|
|
12
|
+
// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.
|
|
13
|
+
//
|
|
14
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
// in the Software without restriction, including without limitation the rights
|
|
17
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
// furnished to do so, subject to the following conditions:
|
|
20
|
+
//
|
|
21
|
+
// The above copyright notice and this permission notice shall be included in
|
|
22
|
+
// all copies or substantial portions of the Software.
|
|
23
|
+
//
|
|
24
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
30
|
+
// THE SOFTWARE.
|
|
31
|
+
//
|
|
32
|
+
/**
|
|
33
|
+
* A hook that provides the current i18n state based on the provided options.
|
|
34
|
+
*
|
|
35
|
+
* @param opts - An object containing the following properties:
|
|
36
|
+
* - `locales`: An array of preferred locales.
|
|
37
|
+
* - `availableLocales`: An array of available locales.
|
|
38
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
39
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
40
|
+
* - Additional options for locale matching can be provided as well.
|
|
41
|
+
*
|
|
42
|
+
* @returns The matched locale string based on the provided options.
|
|
43
|
+
*/
|
|
44
|
+
const useI18nState = (opts) => useMemo(() => {
|
|
45
|
+
const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;
|
|
46
|
+
if (preferredLocale && _.includes(availableLocales, preferredLocale)) {
|
|
47
|
+
return preferredLocale;
|
|
48
|
+
}
|
|
49
|
+
return match(locales, availableLocales, defaultLocale, {
|
|
50
|
+
algorithm: 'best fit',
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
}, [opts]);
|
|
54
|
+
/**
|
|
55
|
+
* A hook that provides a localization function based on the current i18n state.
|
|
56
|
+
*
|
|
57
|
+
* @param opts - An object containing the following properties:
|
|
58
|
+
* - `locales`: An array of preferred locales.
|
|
59
|
+
* - `availableLocales`: An array of available locales.
|
|
60
|
+
* - `preferredLocale`: An optional preferred locale to use if available.
|
|
61
|
+
* - `fallback`: A fallback locale to use if no match is found.
|
|
62
|
+
* - Additional options for locale matching can be provided as well.
|
|
63
|
+
*
|
|
64
|
+
* @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.
|
|
65
|
+
*/
|
|
66
|
+
const useLocalize = (opts) => {
|
|
67
|
+
const i18nState = useI18nState(opts);
|
|
68
|
+
return useCallback((strings, selector) => selector ? _.get(strings[i18nState], selector) : strings[i18nState]);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { useI18nState, useLocalize };
|
|
72
|
+
//# sourceMappingURL=i18n.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.mjs","sources":["../../src/i18n/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2026 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { match, Opts } from '@formatjs/intl-localematcher';\nimport { useMemo } from '../core/hooks/memo';\nimport { useCallback } from '../core/hooks/callback';\n\ntype I18nStateOPts = Partial<Opts> & {\n locales: string[];\n availableLocales: string[];\n preferredLocale?: string;\n fallback: string;\n};\n\n/**\n * A hook that provides the current i18n state based on the provided options.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n *\n * @returns The matched locale string based on the provided options.\n */\nexport const useI18nState = (opts: I18nStateOPts) => useMemo(() => {\n const { locales, availableLocales, preferredLocale, fallback: defaultLocale, ...options } = opts;\n if (preferredLocale && _.includes(availableLocales, preferredLocale)) {\n return preferredLocale;\n }\n return match(locales, availableLocales, defaultLocale, {\n algorithm: 'best fit',\n ...options,\n });\n}, [opts]);\n\n/**\n * A hook that provides a localization function based on the current i18n state.\n *\n * @param opts - An object containing the following properties:\n * - `locales`: An array of preferred locales.\n * - `availableLocales`: An array of available locales.\n * - `preferredLocale`: An optional preferred locale to use if available.\n * - `fallback`: A fallback locale to use if no match is found.\n * - Additional options for locale matching can be provided as well.\n * \n * @returns A function that takes a record of localized strings and an optional selector, returning the localized string based on the current i18n state.\n */\nexport const useLocalize = (opts: I18nStateOPts) => {\n const i18nState = useI18nState(opts);\n return useCallback(<TObject extends unknown>(\n strings: Record<string, TObject>,\n selector?: _.PropertyPath,\n ) => selector ? _.get(strings[i18nState], selector) : strings[i18nState]);\n};"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcA;;;;;;;;;;;AAWG;AACI,MAAM,YAAY,GAAG,CAAC,IAAmB,KAAK,OAAO,CAAC,MAAK;AAChE,IAAA,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI;IAChG,IAAI,eAAe,IAAI,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC,EAAE;AACpE,QAAA,OAAO,eAAe;IACxB;AACA,IAAA,OAAO,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE;AACrD,QAAA,SAAS,EAAE,UAAU;AACrB,QAAA,GAAG,OAAO;AACX,KAAA,CAAC;AACJ,CAAC,EAAE,CAAC,IAAI,CAAC;AAET;;;;;;;;;;;AAWG;AACI,MAAM,WAAW,GAAG,CAAC,IAAmB,KAAI;AACjD,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC;AACpC,IAAA,OAAO,WAAW,CAAC,CACjB,OAAgC,EAChC,QAAyB,KACtB,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAC3E;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var runtime = require('./internals/runtime-CeVOFcK_.js');
|
|
4
|
-
var index = require('./internals/index-
|
|
5
|
-
var form = require('./internals/form-
|
|
4
|
+
var index = require('./internals/index-Bvwj3lIq.js');
|
|
5
|
+
var form = require('./internals/form-CC8A5nkh.js');
|
|
6
6
|
var _ = require('lodash');
|
|
7
|
+
var callback = require('./internals/callback-DVD1MTA9.js');
|
|
7
8
|
require('myers.js');
|
|
8
9
|
require('./jsx-runtime.js');
|
|
9
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
14
|
+
|
|
10
15
|
//
|
|
11
16
|
// debounce.ts
|
|
12
17
|
//
|
|
@@ -33,7 +38,7 @@ require('./jsx-runtime.js');
|
|
|
33
38
|
//
|
|
34
39
|
const debounce = (callback, settings) => {
|
|
35
40
|
const { wait, ...options } = settings;
|
|
36
|
-
return
|
|
41
|
+
return ___default.default.debounce(callback, wait, {
|
|
37
42
|
...options,
|
|
38
43
|
leading: 'leading' in options ? !!options.leading : true,
|
|
39
44
|
trailing: 'trailing' in options ? !!options.trailing : true,
|
|
@@ -43,12 +48,12 @@ const asyncDebounce = (func, settings) => {
|
|
|
43
48
|
let preflight;
|
|
44
49
|
const debounced = debounce(async function (resolve, ...args) {
|
|
45
50
|
const result = func.call(this, ...args);
|
|
46
|
-
if (
|
|
51
|
+
if (___default.default.isFunction(resolve))
|
|
47
52
|
resolve(result);
|
|
48
53
|
return result;
|
|
49
54
|
}, settings);
|
|
50
55
|
return function (...args) {
|
|
51
|
-
if (
|
|
56
|
+
if (___default.default.isNil(preflight)) {
|
|
52
57
|
preflight = new Promise(r => debounced.call(this, r, ...args));
|
|
53
58
|
return preflight;
|
|
54
59
|
}
|
|
@@ -70,17 +75,17 @@ const asyncDebounce = (func, settings) => {
|
|
|
70
75
|
* - Other lodash debounce options such as `leading` and `trailing`.
|
|
71
76
|
* @returns A debounced version of the callback function.
|
|
72
77
|
*/
|
|
73
|
-
const useDebounce = (callback, settings) => {
|
|
74
|
-
const store =
|
|
78
|
+
const useDebounce = (callback$1, settings) => {
|
|
79
|
+
const store = callback._useMemo('useDebounce', () => {
|
|
75
80
|
const store = {
|
|
76
|
-
current: callback,
|
|
81
|
+
current: callback$1,
|
|
77
82
|
stable: debounce((function (...args) {
|
|
78
83
|
return store.current.call(this, ...args);
|
|
79
84
|
}), settings),
|
|
80
85
|
};
|
|
81
86
|
return store;
|
|
82
87
|
}, null);
|
|
83
|
-
store.current = callback;
|
|
88
|
+
store.current = callback$1;
|
|
84
89
|
return store.stable;
|
|
85
90
|
};
|
|
86
91
|
/**
|
|
@@ -98,17 +103,17 @@ const useDebounce = (callback, settings) => {
|
|
|
98
103
|
* - Other lodash debounce options such as `leading` and `trailing`.
|
|
99
104
|
* @returns A debounced version of the asynchronous callback function.
|
|
100
105
|
*/
|
|
101
|
-
const useAsyncDebounce = (callback, settings) => {
|
|
102
|
-
const store =
|
|
106
|
+
const useAsyncDebounce = (callback$1, settings) => {
|
|
107
|
+
const store = callback._useMemo('useAsyncDebounce', () => {
|
|
103
108
|
const store = {
|
|
104
|
-
current: callback,
|
|
109
|
+
current: callback$1,
|
|
105
110
|
stable: asyncDebounce((function (...args) {
|
|
106
111
|
return store.current.call(this, ...args);
|
|
107
112
|
}), settings),
|
|
108
113
|
};
|
|
109
114
|
return store;
|
|
110
115
|
}, null);
|
|
111
|
-
store.current = callback;
|
|
116
|
+
store.current = callback$1;
|
|
112
117
|
return store.stable;
|
|
113
118
|
};
|
|
114
119
|
|
|
@@ -157,11 +162,11 @@ const useAsyncDebounce = (callback, settings) => {
|
|
|
157
162
|
* - `setResource`: A function to manually update the resource state.
|
|
158
163
|
*/
|
|
159
164
|
const useResource = (config, deps) => {
|
|
160
|
-
const fetch =
|
|
161
|
-
const debounce =
|
|
165
|
+
const fetch = ___default.default.isFunction(config) ? config : config.fetch;
|
|
166
|
+
const debounce = ___default.default.isFunction(config) ? {} : config.debounce;
|
|
162
167
|
const [state, setState] = form.useState({});
|
|
163
168
|
const _dispatch = (token, next) => setState(state => state.token === token ? ({
|
|
164
|
-
...(
|
|
169
|
+
...(___default.default.isFunction(next) ? next(state.flag ? state : ___default.default.omit(state, 'resource', 'error')) : next),
|
|
165
170
|
count: state.flag ? state.count : (state.count ?? 0) + 1,
|
|
166
171
|
flag: true,
|
|
167
172
|
}) : state);
|
|
@@ -176,7 +181,7 @@ const useResource = (config, deps) => {
|
|
|
176
181
|
dispatch: (next) => {
|
|
177
182
|
_dispatch(token, state => ({
|
|
178
183
|
...state,
|
|
179
|
-
resource:
|
|
184
|
+
resource: ___default.default.isFunction(next) ? next(state.resource) : next,
|
|
180
185
|
}));
|
|
181
186
|
},
|
|
182
187
|
});
|
|
@@ -194,12 +199,12 @@ const useResource = (config, deps) => {
|
|
|
194
199
|
void _fetch('refresh', controller, true);
|
|
195
200
|
return () => controller.abort();
|
|
196
201
|
}, deps ?? []);
|
|
197
|
-
const _cancelRef =
|
|
198
|
-
const _refreshRef =
|
|
199
|
-
const _nextRef =
|
|
200
|
-
const _setResRef =
|
|
201
|
-
...
|
|
202
|
-
resource:
|
|
202
|
+
const _cancelRef = callback.useCallback((reason) => { state.abort?.abort(reason); });
|
|
203
|
+
const _refreshRef = callback.useCallback((param) => _fetch('refresh', new AbortController(), true, param));
|
|
204
|
+
const _nextRef = callback.useCallback((param) => _fetch('next', new AbortController(), false, param, state.resource));
|
|
205
|
+
const _setResRef = callback.useCallback((resource) => setState(state => ({
|
|
206
|
+
...___default.default.omit(state, 'resource', 'error'),
|
|
207
|
+
resource: ___default.default.isFunction(resource) ? resource(state.resource) : resource,
|
|
203
208
|
})));
|
|
204
209
|
const { setErrors } = form.useErrorContext();
|
|
205
210
|
form.useEffect(() => {
|
|
@@ -210,15 +215,15 @@ const useResource = (config, deps) => {
|
|
|
210
215
|
token,
|
|
211
216
|
error,
|
|
212
217
|
refresh: _refreshRef,
|
|
213
|
-
refreshing: !
|
|
214
|
-
loading: !
|
|
218
|
+
refreshing: !___default.default.isNil(abort) && type === 'refresh',
|
|
219
|
+
loading: !___default.default.isNil(abort),
|
|
215
220
|
}]);
|
|
216
|
-
return () => setErrors(v =>
|
|
221
|
+
return () => setErrors(v => ___default.default.filter(v, x => x.token !== token));
|
|
217
222
|
}, [state]);
|
|
218
223
|
return {
|
|
219
224
|
count: state.count ?? 0,
|
|
220
|
-
refreshing: !
|
|
221
|
-
loading: !
|
|
225
|
+
refreshing: !___default.default.isNil(state.abort) && state.type === 'refresh',
|
|
226
|
+
loading: !___default.default.isNil(state.abort),
|
|
222
227
|
resource: state.resource,
|
|
223
228
|
error: state.error,
|
|
224
229
|
cancel: _cancelRef,
|
|
@@ -239,8 +244,8 @@ const useResource = (config, deps) => {
|
|
|
239
244
|
* @returns An object containing the same properties as `useResource`, but optimized for iterable resources.
|
|
240
245
|
*/
|
|
241
246
|
const useIterableResource = (config, deps) => {
|
|
242
|
-
const fetch =
|
|
243
|
-
const debounce =
|
|
247
|
+
const fetch = ___default.default.isFunction(config) ? config : config.fetch;
|
|
248
|
+
const debounce = ___default.default.isFunction(config) ? {} : config.debounce;
|
|
244
249
|
const { next, ...result } = useResource({
|
|
245
250
|
fetch: async ({ dispatch, abortSignal, param }) => {
|
|
246
251
|
const resource = await fetch({ abortSignal, param });
|
|
@@ -290,7 +295,7 @@ const useIterableResource = (config, deps) => {
|
|
|
290
295
|
* }, 1000);
|
|
291
296
|
*/
|
|
292
297
|
const useInterval = (callback, ms) => form.useEffect(() => {
|
|
293
|
-
if (
|
|
298
|
+
if (___default.default.isNil(ms))
|
|
294
299
|
return;
|
|
295
300
|
const interval = setInterval(() => {
|
|
296
301
|
callback();
|
|
@@ -357,7 +362,7 @@ class Store {
|
|
|
357
362
|
*/
|
|
358
363
|
setValue(dispatch) {
|
|
359
364
|
const oldVal = this.#value;
|
|
360
|
-
this.#value =
|
|
365
|
+
this.#value = ___default.default.isFunction(dispatch) ? dispatch(this.#value) : dispatch;
|
|
361
366
|
this.#listeners.forEach(listener => void listener(oldVal, this.#value));
|
|
362
367
|
}
|
|
363
368
|
/**
|
|
@@ -397,7 +402,7 @@ const createStore = (initialValue) => new Store(initialValue);
|
|
|
397
402
|
* // Using a selector
|
|
398
403
|
* const userName = useStore(userStore, user => user.name);
|
|
399
404
|
*/
|
|
400
|
-
const useStore = (store, selector = v => v, equal =
|
|
405
|
+
const useStore = (store, selector = v => v, equal = ___default.default.isEqual) => form.useSyncExternalStore((onStoreChange) => store.subscribe((oldVal, newVal) => {
|
|
401
406
|
if (!equal(selector(oldVal), selector(newVal)))
|
|
402
407
|
onStoreChange();
|
|
403
408
|
}), () => selector(store.value));
|
|
@@ -460,7 +465,7 @@ const useAwaited = (factory, deps) => {
|
|
|
460
465
|
const state = index.reconciler.currentHookState;
|
|
461
466
|
if (!state)
|
|
462
467
|
throw Error('useAwaited must be used within a render function.');
|
|
463
|
-
const promise =
|
|
468
|
+
const promise = callback._useMemo('useAwaited', () => factory(), deps ?? null);
|
|
464
469
|
if (resolved.has(promise)) {
|
|
465
470
|
const { result, error } = resolved.get(promise) ?? {};
|
|
466
471
|
if (error)
|
|
@@ -503,7 +508,7 @@ const useAwaited = (factory, deps) => {
|
|
|
503
508
|
// THE SOFTWARE.
|
|
504
509
|
//
|
|
505
510
|
function useRef(initialValue) {
|
|
506
|
-
return
|
|
511
|
+
return callback._useMemo('useRef', () => ({ current: initialValue }), null);
|
|
507
512
|
}
|
|
508
513
|
/**
|
|
509
514
|
* Associates a reference with a value created by an initializer function.
|
|
@@ -514,7 +519,7 @@ function useRef(initialValue) {
|
|
|
514
519
|
* @param init A function that initializes and returns the value to associate with the reference.
|
|
515
520
|
* @param deps An optional dependency array. The initializer function is re-executed when the dependencies change.
|
|
516
521
|
*/
|
|
517
|
-
const useRefHandle = (ref, init, deps) =>
|
|
522
|
+
const useRefHandle = (ref, init, deps) => callback._useEffect('useRefHandle', () => {
|
|
518
523
|
try {
|
|
519
524
|
if (ref) {
|
|
520
525
|
const _ref = init();
|
|
@@ -569,7 +574,7 @@ const useStack = () => {
|
|
|
569
574
|
const state = index.reconciler.currentHookState;
|
|
570
575
|
if (!state)
|
|
571
576
|
throw Error('useStack must be used within a render function.');
|
|
572
|
-
return
|
|
577
|
+
return ___default.default.map(state.stack, x => x.component);
|
|
573
578
|
};
|
|
574
579
|
|
|
575
580
|
//
|
|
@@ -597,9 +602,9 @@ const useStack = () => {
|
|
|
597
602
|
// THE SOFTWARE.
|
|
598
603
|
//
|
|
599
604
|
function useReducer(reducer, initialState) {
|
|
600
|
-
const { value, dispatch } =
|
|
605
|
+
const { value, dispatch } = callback._useMemo('useReducer', (_state) => {
|
|
601
606
|
const state = {
|
|
602
|
-
value:
|
|
607
|
+
value: ___default.default.isFunction(initialState) ? initialState() : initialState,
|
|
603
608
|
dispatch: (action) => {
|
|
604
609
|
const oldValue = state.value;
|
|
605
610
|
const newValue = reducer(state.value, action);
|
|
@@ -625,17 +630,17 @@ exports.mergeRefs = index.mergeRefs;
|
|
|
625
630
|
exports.useContext = index.useContext;
|
|
626
631
|
exports.FormActivity = form.FormActivity;
|
|
627
632
|
exports.ResourceErrors = form.ResourceErrors;
|
|
628
|
-
exports._useCallbacks = form._useCallbacks;
|
|
629
633
|
exports.createActivity = form.createActivity;
|
|
630
634
|
exports.useActivity = form.useActivity;
|
|
631
|
-
exports.useCallback = form.useCallback;
|
|
632
635
|
exports.useEffect = form.useEffect;
|
|
633
636
|
exports.useFormState = form.useFormState;
|
|
634
|
-
exports.useMemo = form.useMemo;
|
|
635
637
|
exports.useRendererStorage = form.useRendererStorage;
|
|
636
638
|
exports.useResourceErrors = form.useResourceErrors;
|
|
637
639
|
exports.useState = form.useState;
|
|
638
640
|
exports.useSyncExternalStore = form.useSyncExternalStore;
|
|
641
|
+
exports._useCallbacks = callback._useCallbacks;
|
|
642
|
+
exports.useCallback = callback.useCallback;
|
|
643
|
+
exports.useMemo = callback.useMemo;
|
|
639
644
|
exports.createStore = createStore;
|
|
640
645
|
exports.useAsyncDebounce = useAsyncDebounce;
|
|
641
646
|
exports.useAwaited = useAwaited;
|