@cmtlyt/lingshu-toolkit 0.5.0 → 0.7.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/README.md +10 -0
- package/dist/665.js +1 -0
- package/dist/893.js +1 -0
- package/dist/react/index.js +1 -205
- package/dist/react/use-boolean/index.d.ts +2 -1
- package/dist/react/use-boolean/index.js +1 -16
- package/dist/react/use-controllable-value/index.d.ts +3 -3
- package/dist/react/use-controllable-value/index.js +1 -32
- package/dist/react/use-counter/index.d.ts +2 -2
- package/dist/react/use-counter/index.js +1 -49
- package/dist/react/use-force-update/index.d.ts +2 -1
- package/dist/react/use-force-update/index.js +1 -6
- package/dist/react/use-mount/index.d.ts +2 -1
- package/dist/react/use-mount/index.js +1 -16
- package/dist/react/use-ref-state/index.d.ts +3 -2
- package/dist/react/use-ref-state/index.js +1 -33
- package/dist/react/use-storage/index.d.ts +2 -1
- package/dist/react/use-storage/index.js +1 -15
- package/dist/react/use-title/index.d.ts +2 -2
- package/dist/react/use-title/index.js +1 -24
- package/dist/react/use-toggle/index.d.ts +4 -4
- package/dist/react/use-toggle/index.js +1 -26
- package/dist/react/use-valid-data/index.d.ts +5 -4
- package/dist/react/use-valid-data/index.js +1 -14
- package/dist/shared/allx/index.d.ts +2 -1
- package/dist/shared/allx/index.js +1 -44
- package/dist/shared/allx/types.d.ts +6 -0
- package/dist/shared/allx/utils.d.ts +9 -7
- package/dist/shared/allx/utils.js +1 -94
- package/dist/shared/animation/index.d.ts +3 -2
- package/dist/shared/animation/index.js +1 -77
- package/dist/shared/animation/types.d.ts +8 -0
- package/dist/shared/animation/utils.d.ts +3 -10
- package/dist/shared/animation/utils.js +1 -134
- package/dist/shared/api-controller/create-api.js +1 -79
- package/dist/shared/api-controller/index.js +1 -3
- package/dist/shared/api-controller/request.js +1 -66
- package/dist/shared/api-controller/types.d.ts +26 -27
- package/dist/shared/api-controller/utils.d.ts +6 -15
- package/dist/shared/api-controller/utils.js +1 -96
- package/dist/shared/condition-merge/index.d.ts +6 -6
- package/dist/shared/condition-merge/index.js +1 -30
- package/dist/shared/create-storage-handler/index.d.ts +4 -3
- package/dist/shared/create-storage-handler/index.js +1 -68
- package/dist/shared/data-handler/index.d.ts +4 -3
- package/dist/shared/data-handler/index.js +1 -77
- package/dist/shared/data-handler/tools.d.ts +6 -23
- package/dist/shared/data-handler/tools.js +1 -48
- package/dist/shared/data-handler/types.d.ts +20 -2
- package/dist/shared/data-mixed-manager/constants.js +1 -9
- package/dist/shared/data-mixed-manager/index.js +1 -226
- package/dist/shared/data-mixed-manager/types.d.ts +1 -2
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +1 -957
- package/dist/shared/lock-data/__test__/_helpers/memory-adapters.d.ts +95 -0
- package/dist/shared/lock-data/__test__/_helpers/memory-adapters.js +1 -0
- package/dist/shared/lock-data/__test__/playground.js +1 -0
- package/dist/shared/lock-data/adapters/authority.d.ts +40 -0
- package/dist/shared/lock-data/adapters/authority.js +1 -0
- package/dist/shared/lock-data/adapters/channel.d.ts +39 -0
- package/dist/shared/lock-data/adapters/channel.js +1 -0
- package/dist/shared/lock-data/adapters/index.d.ts +58 -0
- package/dist/shared/lock-data/adapters/index.js +1 -0
- package/dist/shared/lock-data/adapters/logger.d.ts +56 -0
- package/dist/shared/lock-data/adapters/logger.js +1 -0
- package/dist/shared/lock-data/adapters/session-store.d.ts +37 -0
- package/dist/shared/lock-data/adapters/session-store.js +1 -0
- package/dist/shared/lock-data/authority/epoch.d.ts +135 -0
- package/dist/shared/lock-data/authority/epoch.js +1 -0
- package/dist/shared/lock-data/authority/extract.d.ts +107 -0
- package/dist/shared/lock-data/authority/extract.js +1 -0
- package/dist/shared/lock-data/authority/index.d.ts +182 -0
- package/dist/shared/lock-data/authority/index.js +1 -0
- package/dist/shared/lock-data/authority/serialize.d.ts +35 -0
- package/dist/shared/lock-data/authority/serialize.js +1 -0
- package/dist/shared/lock-data/constants.d.ts +46 -0
- package/dist/shared/lock-data/constants.js +1 -0
- package/dist/shared/lock-data/core/actions-helpers.d.ts +163 -0
- package/dist/shared/lock-data/core/actions-helpers.js +1 -0
- package/dist/shared/lock-data/core/actions.d.ts +72 -0
- package/dist/shared/lock-data/core/actions.js +1 -0
- package/dist/shared/lock-data/core/draft.d.ts +64 -0
- package/dist/shared/lock-data/core/draft.js +1 -0
- package/dist/shared/lock-data/core/entry.d.ts +133 -0
- package/dist/shared/lock-data/core/entry.js +1 -0
- package/dist/shared/lock-data/core/fanout.d.ts +42 -0
- package/dist/shared/lock-data/core/fanout.js +1 -0
- package/dist/shared/lock-data/core/readonly-view.d.ts +49 -0
- package/dist/shared/lock-data/core/readonly-view.js +1 -0
- package/dist/shared/lock-data/core/registry.d.ts +282 -0
- package/dist/shared/lock-data/core/registry.js +1 -0
- package/dist/shared/lock-data/core/signal.d.ts +33 -0
- package/dist/shared/lock-data/core/signal.js +1 -0
- package/dist/shared/lock-data/drivers/broadcast-protocol.d.ts +71 -0
- package/dist/shared/lock-data/drivers/broadcast-protocol.js +1 -0
- package/dist/shared/lock-data/drivers/broadcast-state.d.ts +125 -0
- package/dist/shared/lock-data/drivers/broadcast-state.js +1 -0
- package/dist/shared/lock-data/drivers/broadcast.d.ts +36 -0
- package/dist/shared/lock-data/drivers/broadcast.js +1 -0
- package/dist/shared/lock-data/drivers/custom.d.ts +27 -0
- package/dist/shared/lock-data/drivers/custom.js +1 -0
- package/dist/shared/lock-data/drivers/index.d.ts +59 -0
- package/dist/shared/lock-data/drivers/index.js +1 -0
- package/dist/shared/lock-data/drivers/local.d.ts +86 -0
- package/dist/shared/lock-data/drivers/local.js +1 -0
- package/dist/shared/lock-data/drivers/storage-protocol.d.ts +67 -0
- package/dist/shared/lock-data/drivers/storage-protocol.js +1 -0
- package/dist/shared/lock-data/drivers/storage-state.d.ts +103 -0
- package/dist/shared/lock-data/drivers/storage-state.js +1 -0
- package/dist/shared/lock-data/drivers/storage.d.ts +71 -0
- package/dist/shared/lock-data/drivers/storage.js +1 -0
- package/dist/shared/lock-data/drivers/types.d.ts +73 -0
- package/dist/shared/lock-data/drivers/types.js +0 -0
- package/dist/shared/lock-data/drivers/web-locks.d.ts +123 -0
- package/dist/shared/lock-data/drivers/web-locks.js +1 -0
- package/dist/shared/lock-data/errors/index.d.ts +12 -0
- package/dist/shared/lock-data/errors/index.js +1 -0
- package/dist/shared/lock-data/errors/invalid-options-error.d.ts +11 -0
- package/dist/shared/lock-data/errors/invalid-options-error.js +1 -0
- package/dist/shared/lock-data/errors/lock-aborted-error.d.ts +10 -0
- package/dist/shared/lock-data/errors/lock-aborted-error.js +1 -0
- package/dist/shared/lock-data/errors/lock-disposed-error.d.ts +14 -0
- package/dist/shared/lock-data/errors/lock-disposed-error.js +1 -0
- package/dist/shared/lock-data/errors/lock-revoked-error.d.ts +10 -0
- package/dist/shared/lock-data/errors/lock-revoked-error.js +1 -0
- package/dist/shared/lock-data/errors/lock-timeout-error.d.ts +9 -0
- package/dist/shared/lock-data/errors/lock-timeout-error.js +1 -0
- package/dist/shared/lock-data/errors/readonly-mutation-error.d.ts +11 -0
- package/dist/shared/lock-data/errors/readonly-mutation-error.js +1 -0
- package/dist/shared/lock-data/index.d.ts +57 -0
- package/dist/shared/lock-data/index.js +1 -0
- package/dist/shared/lock-data/types.d.ts +347 -0
- package/dist/shared/lock-data/types.js +0 -0
- package/dist/shared/lock-data/utils/json-safe.d.ts +69 -0
- package/dist/shared/lock-data/utils/json-safe.js +1 -0
- package/dist/shared/logger/index.d.ts +2 -2
- package/dist/shared/logger/index.js +1 -10
- package/dist/shared/priority-queue/index.d.ts +45 -0
- package/dist/shared/priority-queue/index.js +1 -0
- package/dist/shared/priority-queue/types.d.ts +10 -0
- package/dist/shared/priority-queue/types.js +0 -0
- package/dist/shared/priority-queue/utils.d.ts +7 -0
- package/dist/shared/priority-queue/utils.js +1 -0
- package/dist/shared/throw-error/index.d.ts +11 -3
- package/dist/shared/throw-error/index.js +1 -10
- package/dist/shared/try-call/index.d.ts +3 -3
- package/dist/shared/try-call/index.js +1 -59
- package/dist/shared/types/index.js +1 -2
- package/dist/shared/types/pack.d.ts +2 -2
- package/dist/shared/types/pack.js +1 -1
- package/dist/shared/utils/base.d.ts +1 -1
- package/dist/shared/utils/base.js +1 -6
- package/dist/shared/utils/index.js +1 -2
- package/dist/shared/utils/verify.d.ts +1 -1
- package/dist/shared/utils/verify.js +1 -67
- package/dist/shared/with-resolvers/index.d.ts +5 -3
- package/dist/shared/with-resolvers/index.js +1 -15
- package/dist/vue/index.js +1 -29
- package/dist/vue/use-title/index.d.ts +2 -2
- package/dist/vue/use-title/index.js +1 -29
- package/package.json +27 -27
- package/dist/247.js +0 -66
- package/dist/707.js +0 -142
- package/dist/react/use-force-update/index.test.d.ts +0 -1
- package/dist/react/use-mount/index.test.d.ts +0 -1
- package/dist/react/use-ref-state/index.test.d.ts +0 -1
- package/dist/react/use-storage/index.test.d.ts +0 -1
- package/dist/react/use-title/index.test.d.ts +0 -1
- package/dist/react/use-toggle/index.test.d.ts +0 -1
- package/dist/react/use-valid-data/index.test.d.ts +0 -1
- package/dist/shared/allx/__test__/allsettled.test.d.ts +0 -1
- package/dist/shared/allx/__test__/basic.test.d.ts +0 -1
- package/dist/shared/allx/__test__/circular-dependency.test.d.ts +0 -1
- package/dist/shared/allx/__test__/dependency.test.d.ts +0 -1
- package/dist/shared/allx/__test__/edge-cases.test.d.ts +0 -1
- package/dist/shared/allx/__test__/error-handling.test.d.ts +0 -1
- package/dist/shared/allx/__test__/execution-order.test.d.ts +0 -1
- package/dist/shared/allx/__test__/falsy-values.test.d.ts +0 -1
- package/dist/shared/allx/__test__/performance.test.d.ts +0 -1
- package/dist/shared/allx/__test__/type-checking.test.d.ts +0 -1
- package/dist/shared/allx/__test__/use-cases.test.d.ts +0 -1
- package/dist/shared/animation/__test__/animation-pause-resume.test.d.ts +0 -1
- package/dist/shared/animation/__test__/animation.test.d.ts +0 -1
- package/dist/shared/animation/__test__/step-animation.test.d.ts +0 -1
- package/dist/shared/animation/__test__/utils.test.d.ts +0 -1
- package/dist/shared/api-controller/__test__/index.browser.test.d.ts +0 -1
- package/dist/shared/api-controller/__test__/index.node.test.d.ts +0 -1
- package/dist/shared/condition-merge/index.test-d.js +0 -108
- package/dist/shared/condition-merge/index.test.d.ts +0 -1
- package/dist/shared/create-storage-handler/index.browser.test.d.ts +0 -1
- package/dist/shared/create-storage-handler/index.test.d.ts +0 -1
- package/dist/shared/data-handler/index.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/basic.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/build-options.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/constructor-options.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/data-management.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/edge-cases.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/events.browser.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/events.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/fixed-slots.test.d.ts +0 -1
- package/dist/shared/data-mixed-manager/__test__/insert-mode.test.d.ts +0 -1
- package/dist/shared/throw-error/index.test.d.ts +0 -1
- package/dist/shared/try-call/index.test.d.ts +0 -1
- package/dist/shared/utils/__test__/base.test.d.ts +0 -1
- package/dist/shared/utils/__test__/verify.test.d.ts +0 -1
- package/dist/shared/with-resolvers/index.test.d.ts +0 -1
- package/dist/test/utils.d.ts +0 -13
- package/dist/vue/use-title/index.test.d.ts +0 -1
- /package/dist/{react/use-boolean/index.test.d.ts → shared/lock-data/__test__/index.test-d.d.ts} +0 -0
- /package/dist/{react/use-controllable-value/index.test.d.ts → shared/lock-data/__test__/integration/entry.test-d.d.ts} +0 -0
- /package/dist/{react/use-counter/index.test.d.ts → shared/lock-data/__test__/playground.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -11,3 +11,13 @@
|
|
|
11
11
|
然后 shadcn 可以提供很好的定制化, 而且 npm 包有 bug 的话也可以通过 shadcn 拉取并修改, 修改完成后还能通过 pr 的方式重新提交回 npm 包, 这样就可以获取 npm 包的长期维护能力了
|
|
12
12
|
|
|
13
13
|
shadcn 的安装方式可以通过[官方文档](https://cmtlyt.github.io/lingshu-toolkit/)查看, 文档后续会慢慢完善的
|
|
14
|
+
|
|
15
|
+
## AI 支持
|
|
16
|
+
|
|
17
|
+
AI 用户可以通过在 AGENTS.md 或者 CLAUDE.md 等 AI 文件中添加 [llms.txt](https://cmtlyt.github.io/lingshu-toolkit/llms.txt) 来让 AI 可以自动获取 lingshu-toolkit 的文档
|
|
18
|
+
|
|
19
|
+
```md
|
|
20
|
+
## Docs
|
|
21
|
+
|
|
22
|
+
- @cmtlyt/lingshu-toolkit: https://cmtlyt.github.io/lingshu-toolkit/llms.txt
|
|
23
|
+
```
|
package/dist/665.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(n,t,e=Error,o){let i="function"==typeof e,u=i?e:Error,s=i?o:e,a=`[@cmtlyt/lingshu-toolkit#${n}]: ${t}`;return s&&"cause"in s?new u(a,{cause:s.cause}):new u(a)}function n(t,e,o=Error,i){throw r(t,e,o,i)}function t(r,t,e){n(r,t,TypeError,e)}function e(r){return"symbol"==typeof r}function o(r){return void 0===r}function i(r){return null===r}function u(r){return i(r)||o(r)}function s(r){return Number.isNaN(r)}function a(r){return e(r)&&o(Symbol.keyFor(r))}function l(r){return"object"==typeof r&&!i(r)}function f(r){return l(r)&&!c(r)}function c(r){return Array.isArray(r)}function y(r){return c(r)&&0===r.length}function d(r){return"string"==typeof r}function m(r){return d(r)&&0===r.length}function b(r){return"number"==typeof r}function g(r){return b(r)&&!s(r)}function h(r){return d(r)||b(r)||e(r)}function p(r){return"boolean"==typeof r}function N(r){return!0===r||d(r)&&"true"===r.toLowerCase()}function E(r){return!1===r||d(r)&&"false"===r.toLowerCase()}function w(r){return!!r}function $(r){return!(s(r)||r)}function v(r){return"function"==typeof r}function S(r){return(l(r)||v(r))&&v(r.then)}let T=new Proxy(console,{get(r,n,t){if((globalThis.$$lingshu$$||{}).disableLogger)return()=>void 0;let e=Reflect.get(r,n,t).bind(console);return(r,...n)=>{e(`[@cmtlyt/lingshu-toolkit#${r}]:`,...n)}}}),K=()=>void 0,j=r=>r;function A(r){return Object.prototype.toString.call(r).slice(8,-1).toLowerCase()}function P(r,n){return t=>(e,o)=>{if(n?n(e):A(e)===r)return!0;if(u(t))return!1;let i=t;"function"==typeof t&&(i=t(e)),o.transform(i)}}let L={notNullable:P("notNullable",r=>!u(r)),string:P("string"),validString:P("validString",r=>"string"==typeof r&&r.length>0),number:P("number"),validNumber:P("validNumber",r=>"number"==typeof r&&!Number.isNaN(r)),boolean:P("boolean"),object:P("object"),array:P("array"),function:P("function"),symbol:P("symbol"),enum:(r,n)=>{Array.isArray(r)||t("$t.enum","list must be an array");let e=new Set(r);return P("enum",r=>e.has(r))(n)}};function k(r){let n={},t=Reflect.ownKeys(r);for(let e=0,o=t[e],i=r[o];e<t.length;i=r[o=t[++e]]){if("function"==typeof i){n[o]=i;continue}let r=L[i];if(!r){T.warn("defineTransform",`${i} is not a valid type`);continue}n[o]=r()}return n}function F(r,n,e){let o,i;n||t("dataHandler","handler is required");let{strict:u=!1,errorHandler:s,defaultValue:a,unwrap:l=!1}=e||{},f="function"==typeof n,c=f?n:(r,t,...e)=>n[t](r,...e),d={...a,...r},m=f?Reflect.ownKeys(r):Reflect.ownKeys(n),[b,g,h]=(o={errors:[],transforms:[],handledErrorKeys:new Set},i={addError(r,n=`${String(r)} is not valid`){o.handledErrorKeys.has(r)||(o.handledErrorKeys.add(r),o.errors.push(n))},addTransform(r,n){o.transforms.push([r,n])}},[o,i,r=>({assert:(n,t=`${String(r)} is not valid`)=>(n||i.addError(r,t),n),transform:n=>(o.handledErrorKeys.has(r)||i.addTransform(r,n),n)})]);for(let r=0,n=m[r];r<m.length;n=m[++r])!1===c(d[n],n,h(n),d)&&g.addError(n);p=b.errors,!y(p)&&(s?s(p):u&&t("dataHandler",p.join("\n")));var p,N=b.transforms;if(!y(N))for(let r=0,[n,t]=N[r];r<N.length;[n,t]=N[++r]||[])d[n]=t;return!function(r,n,t={}){n.handledErrorKeys.forEach(n=>{r[n]=t[n]})}(d,b,a),l?d:{result:d,errors:b.errors}}export{L as $t,r as createError,F as dataHandler,k as $dt,A as getType,j as identity,c as isArray,p as isBoolean,y as isEmptyArray,m as isEmptyString,E as isFalse,$ as isFalsy,v as isFunction,i as isNull,u as isNullOrUndef,b as isNumber,l as isObject,g as isPlainNumber,f as isPlainObject,a as isPlainSymbol,S as isPromiseLike,h as isPropertyKey,d as isString,e as isSymbol,N as isTrue,w as isTruthy,o as isUndef,T as logger,K as noop,n as throwError,t as throwType,s as isNaN};
|
package/dist/893.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{dataHandler as e,logger as t,$dt as a,throwError as r,isNullOrUndef as o,$t as l}from"./665.js";let n=a({storageKey:"validString",storageType:l.enum(["local","session","memory"],"local"),autoSaveInterval:l.number(0)}),s={data:{},getItem(e){return this.data[e]},setItem(e,t){this.data[e]=t},removeItem(e){delete this.data[e]}},m=Symbol("cleared");function i(a,l,d={}){let{storageKey:g,storageType:c,autoSaveInterval:S}=e({storageKey:a,...d},n,{unwrap:!0}),u=function(e){try{if("memory"===e)return s;return"local"===e?localStorage:sessionStorage}catch{return t.warn("createStorage","Failed to access localStorage or sessionStorage, using memoryStorage instead."),s}}(c),y=u.getItem(g),I={data:y?JSON.parse(y):l||{},timer:null},f=()=>{null!==I.timer&&(clearTimeout(I.timer),I.timer=null)};return{get:e=>(I.data===m&&r("createStorageHandler","Storage has been cleared."),o(e))?I.data:I.data[e],set(e,t){I.data===m&&r("createStorageHandler","Storage has been cleared."),o(t)?I.data=e:I.data[t]=e,S>0?(f(),I.timer=setTimeout(()=>{u.setItem(g,JSON.stringify(I.data))},S)):u.setItem(g,JSON.stringify(I.data))},clear(){f(),I.data=m,u.removeItem(g)}}}export{i as createStorageHandler};
|
package/dist/react/index.js
CHANGED
|
@@ -1,205 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dataHandler, logger, $dt, $t, throwType } from "../707.js";
|
|
3
|
-
import { createStorageHandler } from "../247.js";
|
|
4
|
-
function useToggle(defualtValue = false, reverseValue) {
|
|
5
|
-
const [state, setState] = useState(defualtValue);
|
|
6
|
-
const toggleRef = useRef([
|
|
7
|
-
defualtValue,
|
|
8
|
-
void 0 === reverseValue ? !defualtValue : reverseValue
|
|
9
|
-
]);
|
|
10
|
-
const actions = useMemo(()=>{
|
|
11
|
-
const [left, right] = toggleRef.current;
|
|
12
|
-
return {
|
|
13
|
-
set: (value)=>{
|
|
14
|
-
if (value !== left && value !== right) throwType('useToggle', 'value is not left or right');
|
|
15
|
-
setState(value);
|
|
16
|
-
},
|
|
17
|
-
setLeft: ()=>setState(left),
|
|
18
|
-
setRight: ()=>setState(right),
|
|
19
|
-
toggle: ()=>setState((prev)=>prev === left ? right : left)
|
|
20
|
-
};
|
|
21
|
-
}, []);
|
|
22
|
-
return [
|
|
23
|
-
state,
|
|
24
|
-
actions
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
function useBoolean(defaultValue = false) {
|
|
28
|
-
const [state, { toggle, set }] = useToggle(!!defaultValue);
|
|
29
|
-
const actions = useMemo(()=>({
|
|
30
|
-
toggle,
|
|
31
|
-
setTrue: ()=>set(true),
|
|
32
|
-
setFalse: ()=>set(false),
|
|
33
|
-
set: (value)=>set(!!value)
|
|
34
|
-
}), []);
|
|
35
|
-
return [
|
|
36
|
-
state,
|
|
37
|
-
actions
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
function useValidData(data, verifyInfo, options) {
|
|
41
|
-
const verifyInfoRef = useRef(verifyInfo);
|
|
42
|
-
const optionsRef = useRef(options);
|
|
43
|
-
return useMemo(()=>dataHandler(data, verifyInfoRef.current, {
|
|
44
|
-
unwrap: true,
|
|
45
|
-
...optionsRef.current
|
|
46
|
-
}), [
|
|
47
|
-
data
|
|
48
|
-
]);
|
|
49
|
-
}
|
|
50
|
-
const validInfo = $dt({
|
|
51
|
-
defaultValuePropName: $t.validString('defaultValue'),
|
|
52
|
-
valuePropName: $t.validString('value'),
|
|
53
|
-
trigger: $t.validString('onChange')
|
|
54
|
-
});
|
|
55
|
-
function useControllableValue(props = {}, options = {}) {
|
|
56
|
-
const { defaultValue: _defaultValue, trigger, valuePropName, defaultValuePropName } = useValidData(options, validInfo);
|
|
57
|
-
const { [valuePropName]: propValue, [defaultValuePropName]: defaultValue = _defaultValue, [trigger]: emitChange } = props;
|
|
58
|
-
const hasValueRef = useRef(Boolean(Reflect.getOwnPropertyDescriptor(props, valuePropName)));
|
|
59
|
-
const isFirstRenderRef = useRef(true);
|
|
60
|
-
const [ctrlValue, setCtrlValue] = useState(hasValueRef.current ? propValue : defaultValue);
|
|
61
|
-
const setValue = useEffectEvent((value, ...args)=>{
|
|
62
|
-
if ('function' == typeof emitChange) emitChange(value, ...args);
|
|
63
|
-
if (!hasValueRef.current) setCtrlValue(value);
|
|
64
|
-
});
|
|
65
|
-
useEffect(()=>{
|
|
66
|
-
if (isFirstRenderRef.current || !hasValueRef.current) {
|
|
67
|
-
isFirstRenderRef.current = false;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
setCtrlValue(propValue);
|
|
71
|
-
}, [
|
|
72
|
-
propValue
|
|
73
|
-
]);
|
|
74
|
-
return [
|
|
75
|
-
ctrlValue,
|
|
76
|
-
setValue
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
function getRealValue(value, options) {
|
|
80
|
-
const { min, max } = options;
|
|
81
|
-
return Math.min(Math.max(value, min), max);
|
|
82
|
-
}
|
|
83
|
-
function nanTransform(_dv) {
|
|
84
|
-
return (_v)=>{
|
|
85
|
-
if (void 0 === _v) return _dv;
|
|
86
|
-
logger.warn('useCounter', 'value is not a number', _v, 'useCounter will use default value');
|
|
87
|
-
const numV = Number(_v);
|
|
88
|
-
if (Number.isNaN(numV)) return _dv;
|
|
89
|
-
return numV;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const use_counter_validInfo = $dt({
|
|
93
|
-
min: $t.validNumber(nanTransform(-1 / 0)),
|
|
94
|
-
max: $t.validNumber(nanTransform(1 / 0)),
|
|
95
|
-
step: $t.validNumber(nanTransform(1))
|
|
96
|
-
});
|
|
97
|
-
function useCounter(initialValue = 0, options = {}) {
|
|
98
|
-
const validOptions = useValidData(options, use_counter_validInfo);
|
|
99
|
-
const { step } = validOptions;
|
|
100
|
-
const initialValueRef = useRef(getRealValue(Number(initialValue), validOptions));
|
|
101
|
-
const [current, setCurrent] = useState(getRealValue(Number(initialValue), validOptions));
|
|
102
|
-
const setValue = useEffectEvent((value)=>{
|
|
103
|
-
setCurrent(()=>getRealValue('function' == typeof value ? value(current) : value, validOptions));
|
|
104
|
-
});
|
|
105
|
-
const actions = useMemo(()=>{
|
|
106
|
-
const _step = Math.abs(step);
|
|
107
|
-
const increment = (delta = _step)=>setValue((prev)=>prev + delta);
|
|
108
|
-
const decrement = (delta = _step)=>setValue((prev)=>prev - delta);
|
|
109
|
-
const reset = ()=>setCurrent(initialValueRef.current);
|
|
110
|
-
return {
|
|
111
|
-
increment,
|
|
112
|
-
decrement,
|
|
113
|
-
reset,
|
|
114
|
-
set: setValue
|
|
115
|
-
};
|
|
116
|
-
}, [
|
|
117
|
-
step
|
|
118
|
-
]);
|
|
119
|
-
return [
|
|
120
|
-
current,
|
|
121
|
-
actions
|
|
122
|
-
];
|
|
123
|
-
}
|
|
124
|
-
function useForceUpdate() {
|
|
125
|
-
const [, forceUpdate] = useReducer((prev)=>(prev + 1) % 10, 0);
|
|
126
|
-
return forceUpdate;
|
|
127
|
-
}
|
|
128
|
-
function useMount(callback) {
|
|
129
|
-
const callbackRef = useRef(callback);
|
|
130
|
-
useEffect(()=>{
|
|
131
|
-
dataHandler({
|
|
132
|
-
fn: callbackRef.current
|
|
133
|
-
}, {
|
|
134
|
-
fn: $t["function"]()
|
|
135
|
-
}, {
|
|
136
|
-
strict: true
|
|
137
|
-
});
|
|
138
|
-
callbackRef.current();
|
|
139
|
-
}, []);
|
|
140
|
-
}
|
|
141
|
-
const clone = structuredClone;
|
|
142
|
-
function useRefState(initialState) {
|
|
143
|
-
const stateRef = useRef(initialState);
|
|
144
|
-
const forceUpdate = useForceUpdate();
|
|
145
|
-
const ctrl = useMemo(()=>{
|
|
146
|
-
const origin = clone(stateRef.current);
|
|
147
|
-
const updateHandler = (update = true)=>void (update && forceUpdate());
|
|
148
|
-
const patchState = (updater, update = true)=>{
|
|
149
|
-
updater(stateRef.current);
|
|
150
|
-
updateHandler(update);
|
|
151
|
-
};
|
|
152
|
-
const setState = (state, update = true)=>{
|
|
153
|
-
stateRef.current = state;
|
|
154
|
-
updateHandler(update);
|
|
155
|
-
};
|
|
156
|
-
return {
|
|
157
|
-
patchState,
|
|
158
|
-
forceUpdate,
|
|
159
|
-
getState: ()=>stateRef.current,
|
|
160
|
-
setState,
|
|
161
|
-
reset: (update = true)=>setState(clone(origin), update)
|
|
162
|
-
};
|
|
163
|
-
}, [
|
|
164
|
-
forceUpdate
|
|
165
|
-
]);
|
|
166
|
-
return [
|
|
167
|
-
stateRef.current,
|
|
168
|
-
ctrl
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
function useStorage(storageKey, options, initialData) {
|
|
172
|
-
const optionsRef = useRef({
|
|
173
|
-
initialData,
|
|
174
|
-
options
|
|
175
|
-
});
|
|
176
|
-
return useMemo(()=>{
|
|
177
|
-
const { initialData: _initialData, options: _options } = optionsRef.current;
|
|
178
|
-
return createStorageHandler(storageKey, _initialData || {}, _options);
|
|
179
|
-
}, [
|
|
180
|
-
storageKey
|
|
181
|
-
]);
|
|
182
|
-
}
|
|
183
|
-
function setTitle(title) {
|
|
184
|
-
if (!title) return;
|
|
185
|
-
document.title = title;
|
|
186
|
-
}
|
|
187
|
-
const use_title_validInfo = $dt({
|
|
188
|
-
restoreOnUnmount: $t.boolean(true)
|
|
189
|
-
});
|
|
190
|
-
function useTitle(title, options = {}) {
|
|
191
|
-
const { restoreOnUnmount } = useValidData(options, use_title_validInfo);
|
|
192
|
-
useEffect(()=>{
|
|
193
|
-
const originalTitle = document.title;
|
|
194
|
-
setTitle(title);
|
|
195
|
-
return ()=>{
|
|
196
|
-
if (restoreOnUnmount) setTitle(originalTitle);
|
|
197
|
-
};
|
|
198
|
-
}, [
|
|
199
|
-
title,
|
|
200
|
-
restoreOnUnmount
|
|
201
|
-
]);
|
|
202
|
-
return setTitle;
|
|
203
|
-
}
|
|
204
|
-
export { $dt, $t, defineTransform } from "../707.js";
|
|
205
|
-
export { useBoolean, useControllableValue, useCounter, useForceUpdate, useMount, useRefState, useStorage, useTitle, useToggle, useValidData };
|
|
1
|
+
import{useEffect as e,useEffectEvent as t,useMemo as r,useReducer as n,useRef as u,useState as l}from"react";import{dataHandler as o,logger as a,$dt as i,$t as c,throwType as s}from"../665.js";import{createStorageHandler as f}from"../893.js";function m(e=!1,t){let[n,o]=l(e),a=u([e,void 0===t?!e:t]);return[n,r(()=>{let[e,t]=a.current;return{set:r=>{r!==e&&r!==t&&s("useToggle","value is not left or right"),o(r)},setLeft:()=>o(e),setRight:()=>o(t),toggle:()=>o(r=>r===e?t:e)}},[])]}function d(e=!1){let[t,{toggle:n,set:u}]=m(!!e);return[t,r(()=>({toggle:n,setTrue:()=>u(!0),setFalse:()=>u(!1),set:e=>u(!!e)}),[])]}function g(e,t,n){let l=u(t),a=u(n);return r(()=>o(e,l.current,{unwrap:!0,...a.current}),[e])}let p=i({defaultValuePropName:c.validString("defaultValue"),valuePropName:c.validString("value"),trigger:c.validString("onChange")});function _(r={},n={}){let{defaultValue:o,trigger:a,valuePropName:i,defaultValuePropName:c}=g(n,p),{[i]:s,[c]:f=o,[a]:m}=r,d=u(!!Reflect.getOwnPropertyDescriptor(r,i)),N=u(!0),[v,S]=l(d.current?s:f),C=t((e,...t)=>{"function"==typeof m&&m(e,...t),d.current||S(e)});return e(()=>{if(N.current||!d.current){N.current=!1;return}S(s)},[s]),[v,C]}function N(e,t){let{min:r,max:n}=t;return Math.min(Math.max(e,r),n)}function v(e){return t=>{if(void 0===t)return e;a.warn("useCounter","value is not a number",t,"useCounter will use default value");let r=Number(t);return Number.isNaN(r)?e:r}}let S=i({min:c.validNumber(v(-1/0)),max:c.validNumber(v(1/0)),step:c.validNumber(v(1))});function C(e=0,n={}){let o=g(n,S),{step:a}=o,i=u(N(Number(e),o)),[c,s]=l(N(Number(e),o)),f=t(e=>{s(()=>N("function"==typeof e?e(c):e,o))});return[c,r(()=>{let e=Math.abs(a);return{increment:(t=e)=>f(e=>e+t),decrement:(t=e)=>f(e=>e-t),reset:()=>s(i.current),set:f}},[a])]}function b(){let[,e]=n(e=>(e+1)%10,0);return e}function h(t){let r=u(t);e(()=>{o({fn:r.current},{fn:c.function()},{strict:!0}),r.current()},[])}let M=structuredClone;function K(e){let t=u(e),n=b(),l=r(()=>{let e=M(t.current),r=(e,r=!0)=>{t.current=e,((e=!0)=>e&&n())(r)};return{patchState:(e,r=!0)=>{e(t.current),((e=!0)=>e&&n())(r)},forceUpdate:n,getState:()=>t.current,setState:r,reset:(t=!0)=>r(M(e),t)}},[n]);return[t.current,l]}function P(e,t,n){let l=u({initialData:n,options:t});return r(()=>{let{initialData:t,options:r}=l.current;return f(e,t||{},r)},[e])}function R(e){e&&(document.title=e)}let T=i({restoreOnUnmount:c.boolean(!0)});function U(t,r={}){let{restoreOnUnmount:n}=g(r,T);return e(()=>{let e=document.title;return R(t),()=>{n&&R(e)}},[t,n]),R}export{$dt,$dt as defineTransform,$t,dataHandler}from"../665.js";export{d as useBoolean,_ as useControllableValue,C as useCounter,b as useForceUpdate,h as useMount,K as useRefState,P as useStorage,U as useTitle,m as useToggle,g as useValidData};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
declare function useBoolean(defaultValue?: boolean): readonly [boolean, {
|
|
2
2
|
toggle: () => void;
|
|
3
3
|
setTrue: () => void;
|
|
4
4
|
setFalse: () => void;
|
|
5
5
|
set: (value: boolean) => void;
|
|
6
6
|
}];
|
|
7
|
+
export { useBoolean };
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useToggle } from "../use-toggle/index.js";
|
|
3
|
-
function useBoolean(defaultValue = false) {
|
|
4
|
-
const [state, { toggle, set }] = useToggle(!!defaultValue);
|
|
5
|
-
const actions = useMemo(()=>({
|
|
6
|
-
toggle,
|
|
7
|
-
setTrue: ()=>set(true),
|
|
8
|
-
setFalse: ()=>set(false),
|
|
9
|
-
set: (value)=>set(!!value)
|
|
10
|
-
}), []);
|
|
11
|
-
return [
|
|
12
|
-
state,
|
|
13
|
-
actions
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
export { useBoolean };
|
|
1
|
+
import{useMemo as e}from"react";import{useToggle as t}from"../use-toggle/index.js";function o(r=!1){let[s,{toggle:n,set:u}]=t(!!r);return[s,e(()=>({toggle:n,setTrue:()=>u(!0),setFalse:()=>u(!1),set:e=>u(!!e)}),[])]}export{o as useBoolean};
|
|
@@ -4,12 +4,12 @@ interface UseControllableValueOptions<Ks extends PropertyKey = PropertyKey, P ex
|
|
|
4
4
|
valuePropName: P;
|
|
5
5
|
trigger: Ks;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
type PublicUseControllableValueOptions<Ks extends PropertyKey = PropertyKey, P extends Ks | (string & {}) = 'value'> = Partial<UseControllableValueOptions<Ks, P>>;
|
|
8
8
|
type ParseDefaultValue<OT extends Record<PropertyKey, any>, O extends PublicUseControllableValueOptions> = O['defaultValuePropName'] extends keyof OT ? OT[O['defaultValuePropName']] : O['defaultValue'];
|
|
9
9
|
type Defaultize<OT extends Record<PropertyKey, any>, P extends keyof OT | (string & {}), O extends PublicUseControllableValueOptions> = P extends keyof OT ? undefined extends OT[P] ? OT[P] & ParseDefaultValue<OT, O> : OT[P] : ParseDefaultValue<OT, O>;
|
|
10
10
|
type ValueType<T extends Record<PropertyKey, any>, O extends PublicUseControllableValueOptions<PropertyKey, any>> = O['valuePropName'] extends keyof T ? Defaultize<T, O['valuePropName'], O> : Defaultize<T, 'value', O>;
|
|
11
11
|
/**
|
|
12
12
|
* 受控组件 value 逻辑切换, 如果传递了 value 则走受控逻辑, 否则走非受控逻辑
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
export {};
|
|
14
|
+
declare function useControllableValue<T extends Record<PropertyKey, any>, P extends keyof T | (string & {}) = PropertyKey, O extends PublicUseControllableValueOptions<keyof T, P> = PublicUseControllableValueOptions<keyof T, P>>(props?: T, options?: O): [ValueType<T, O>, (value: ValueType<T, O>, ...args: any[]) => void];
|
|
15
|
+
export { type PublicUseControllableValueOptions, useControllableValue };
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { $dt, $t, useValidData } from "../use-valid-data/index.js";
|
|
3
|
-
const validInfo = $dt({
|
|
4
|
-
defaultValuePropName: $t.validString('defaultValue'),
|
|
5
|
-
valuePropName: $t.validString('value'),
|
|
6
|
-
trigger: $t.validString('onChange')
|
|
7
|
-
});
|
|
8
|
-
function useControllableValue(props = {}, options = {}) {
|
|
9
|
-
const { defaultValue: _defaultValue, trigger, valuePropName, defaultValuePropName } = useValidData(options, validInfo);
|
|
10
|
-
const { [valuePropName]: propValue, [defaultValuePropName]: defaultValue = _defaultValue, [trigger]: emitChange } = props;
|
|
11
|
-
const hasValueRef = useRef(Boolean(Reflect.getOwnPropertyDescriptor(props, valuePropName)));
|
|
12
|
-
const isFirstRenderRef = useRef(true);
|
|
13
|
-
const [ctrlValue, setCtrlValue] = useState(hasValueRef.current ? propValue : defaultValue);
|
|
14
|
-
const setValue = useEffectEvent((value, ...args)=>{
|
|
15
|
-
if ('function' == typeof emitChange) emitChange(value, ...args);
|
|
16
|
-
if (!hasValueRef.current) setCtrlValue(value);
|
|
17
|
-
});
|
|
18
|
-
useEffect(()=>{
|
|
19
|
-
if (isFirstRenderRef.current || !hasValueRef.current) {
|
|
20
|
-
isFirstRenderRef.current = false;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
setCtrlValue(propValue);
|
|
24
|
-
}, [
|
|
25
|
-
propValue
|
|
26
|
-
]);
|
|
27
|
-
return [
|
|
28
|
-
ctrlValue,
|
|
29
|
-
setValue
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
export { useControllableValue };
|
|
1
|
+
import{useEffect as e,useEffectEvent as r,useRef as t,useState as a}from"react";import{$dt as u,$t as l,useValidData as n}from"../use-valid-data/index.js";let i=u({defaultValuePropName:l.validString("defaultValue"),valuePropName:l.validString("value"),trigger:l.validString("onChange")});function o(u={},l={}){let{defaultValue:c,trigger:f,valuePropName:d,defaultValuePropName:p}=n(l,i),{[d]:g,[p]:m=c,[f]:v}=u,s=t(!!Reflect.getOwnPropertyDescriptor(u,d)),V=t(!0),[P,S]=a(s.current?g:m),x=r((e,...r)=>{"function"==typeof v&&v(e,...r),s.current||S(e)});return e(()=>{if(V.current||!s.current){V.current=!1;return}S(g)},[g]),[P,x]}export{o as useControllableValue};
|
|
@@ -3,10 +3,10 @@ interface UseCounterOptions {
|
|
|
3
3
|
max: number;
|
|
4
4
|
step: number;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
declare function useCounter(initialValue?: number, options?: Partial<UseCounterOptions>): readonly [number, {
|
|
7
7
|
increment: (delta?: number) => void;
|
|
8
8
|
decrement: (delta?: number) => void;
|
|
9
9
|
reset: () => void;
|
|
10
10
|
set: (value: number | ((prev: number) => number)) => void;
|
|
11
11
|
}];
|
|
12
|
-
export {};
|
|
12
|
+
export { useCounter };
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { $dt, $t, useValidData } from "../use-valid-data/index.js";
|
|
3
|
-
import { logger } from "../../shared/logger/index.js";
|
|
4
|
-
function getRealValue(value, options) {
|
|
5
|
-
const { min, max } = options;
|
|
6
|
-
return Math.min(Math.max(value, min), max);
|
|
7
|
-
}
|
|
8
|
-
function nanTransform(_dv) {
|
|
9
|
-
return (_v)=>{
|
|
10
|
-
if (void 0 === _v) return _dv;
|
|
11
|
-
logger.warn('useCounter', 'value is not a number', _v, 'useCounter will use default value');
|
|
12
|
-
const numV = Number(_v);
|
|
13
|
-
if (Number.isNaN(numV)) return _dv;
|
|
14
|
-
return numV;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const validInfo = $dt({
|
|
18
|
-
min: $t.validNumber(nanTransform(-1 / 0)),
|
|
19
|
-
max: $t.validNumber(nanTransform(1 / 0)),
|
|
20
|
-
step: $t.validNumber(nanTransform(1))
|
|
21
|
-
});
|
|
22
|
-
function useCounter(initialValue = 0, options = {}) {
|
|
23
|
-
const validOptions = useValidData(options, validInfo);
|
|
24
|
-
const { step } = validOptions;
|
|
25
|
-
const initialValueRef = useRef(getRealValue(Number(initialValue), validOptions));
|
|
26
|
-
const [current, setCurrent] = useState(getRealValue(Number(initialValue), validOptions));
|
|
27
|
-
const setValue = useEffectEvent((value)=>{
|
|
28
|
-
setCurrent(()=>getRealValue('function' == typeof value ? value(current) : value, validOptions));
|
|
29
|
-
});
|
|
30
|
-
const actions = useMemo(()=>{
|
|
31
|
-
const _step = Math.abs(step);
|
|
32
|
-
const increment = (delta = _step)=>setValue((prev)=>prev + delta);
|
|
33
|
-
const decrement = (delta = _step)=>setValue((prev)=>prev - delta);
|
|
34
|
-
const reset = ()=>setCurrent(initialValueRef.current);
|
|
35
|
-
return {
|
|
36
|
-
increment,
|
|
37
|
-
decrement,
|
|
38
|
-
reset,
|
|
39
|
-
set: setValue
|
|
40
|
-
};
|
|
41
|
-
}, [
|
|
42
|
-
step
|
|
43
|
-
]);
|
|
44
|
-
return [
|
|
45
|
-
current,
|
|
46
|
-
actions
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
export { useCounter };
|
|
1
|
+
import{useEffectEvent as e,useMemo as r,useRef as t,useState as u}from"react";import{$dt as n,$t as i,useValidData as a}from"../use-valid-data/index.js";import{logger as m}from"../../shared/logger/index.js";function o(e,r){let{min:t,max:u}=r;return Math.min(Math.max(e,t),u)}function l(e){return r=>{if(void 0===r)return e;m.warn("useCounter","value is not a number",r,"useCounter will use default value");let t=Number(r);return Number.isNaN(t)?e:t}}let s=n({min:i.validNumber(l(-1/0)),max:i.validNumber(l(1/0)),step:i.validNumber(l(1))});function d(n=0,i={}){let m=a(i,s),{step:l}=m,f=t(o(Number(n),m)),[b,N]=u(o(Number(n),m)),c=e(e=>{N(()=>o("function"==typeof e?e(b):e,m))});return[b,r(()=>{let e=Math.abs(l);return{increment:(r=e)=>c(e=>e+r),decrement:(r=e)=>c(e=>e-r),reset:()=>N(f.current),set:c}},[l])]}export{d as useCounter};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare function useForceUpdate(): import("react").ActionDispatch<[]>;
|
|
2
|
+
export { useForceUpdate };
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useForceUpdate() {
|
|
3
|
-
const [, forceUpdate] = useReducer((prev)=>(prev + 1) % 10, 0);
|
|
4
|
-
return forceUpdate;
|
|
5
|
-
}
|
|
6
|
-
export { useForceUpdate };
|
|
1
|
+
import{useReducer as e}from"react";function r(){let[,r]=e(e=>(e+1)%10,0);return r}export{r as useForceUpdate};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare function useMount(callback: () => any): void;
|
|
2
|
+
export { useMount };
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { $t, dataHandler } from "../../shared/data-handler/index.js";
|
|
3
|
-
function useMount(callback) {
|
|
4
|
-
const callbackRef = useRef(callback);
|
|
5
|
-
useEffect(()=>{
|
|
6
|
-
dataHandler({
|
|
7
|
-
fn: callbackRef.current
|
|
8
|
-
}, {
|
|
9
|
-
fn: $t["function"]()
|
|
10
|
-
}, {
|
|
11
|
-
strict: true
|
|
12
|
-
});
|
|
13
|
-
callbackRef.current();
|
|
14
|
-
}, []);
|
|
15
|
-
}
|
|
16
|
-
export { useMount };
|
|
1
|
+
import{useEffect as r,useRef as t}from"react";import{$t as n,dataHandler as e}from"../../shared/data-handler/index.js";function o(o){let c=t(o);r(()=>{e({fn:c.current},{fn:n.function()},{strict:!0}),c.current()},[])}export{o as useMount};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface UseRefStateCtrl<T> {
|
|
2
2
|
patchState: (updater: (draft: T) => void, update?: boolean) => void;
|
|
3
3
|
forceUpdate: () => void;
|
|
4
4
|
getState: () => T;
|
|
5
5
|
setState: (state: T, update?: boolean) => void;
|
|
6
6
|
reset: (update?: boolean) => void;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
declare function useRefState<T>(initialState: T): readonly [T, UseRefStateCtrl<T>];
|
|
9
|
+
export { type UseRefStateCtrl, useRefState };
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useForceUpdate } from "../use-force-update/index.js";
|
|
3
|
-
const clone = structuredClone;
|
|
4
|
-
function useRefState(initialState) {
|
|
5
|
-
const stateRef = useRef(initialState);
|
|
6
|
-
const forceUpdate = useForceUpdate();
|
|
7
|
-
const ctrl = useMemo(()=>{
|
|
8
|
-
const origin = clone(stateRef.current);
|
|
9
|
-
const updateHandler = (update = true)=>void (update && forceUpdate());
|
|
10
|
-
const patchState = (updater, update = true)=>{
|
|
11
|
-
updater(stateRef.current);
|
|
12
|
-
updateHandler(update);
|
|
13
|
-
};
|
|
14
|
-
const setState = (state, update = true)=>{
|
|
15
|
-
stateRef.current = state;
|
|
16
|
-
updateHandler(update);
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
patchState,
|
|
20
|
-
forceUpdate,
|
|
21
|
-
getState: ()=>stateRef.current,
|
|
22
|
-
setState,
|
|
23
|
-
reset: (update = true)=>setState(clone(origin), update)
|
|
24
|
-
};
|
|
25
|
-
}, [
|
|
26
|
-
forceUpdate
|
|
27
|
-
]);
|
|
28
|
-
return [
|
|
29
|
-
stateRef.current,
|
|
30
|
-
ctrl
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
export { useRefState };
|
|
1
|
+
import{useMemo as t,useRef as e}from"react";import{useForceUpdate as r}from"../use-force-update/index.js";let u=structuredClone;function n(n){let c=e(n),o=r(),a=t(()=>{let t=u(c.current),e=(t,e=!0)=>{c.current=t,((t=!0)=>t&&o())(e)};return{patchState:(t,e=!0)=>{t(c.current),((t=!0)=>t&&o())(e)},forceUpdate:o,getState:()=>c.current,setState:e,reset:(r=!0)=>e(u(t),r)}},[o]);return[c.current,a]}export{n as useRefState};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type CreateStorageOptions } from '../../shared/create-storage-handler';
|
|
2
|
-
|
|
2
|
+
declare function useStorage<T extends Record<string, any>>(storageKey: string, options?: Partial<CreateStorageOptions>, initialData?: T): import("../../shared/create-storage-handler").StorageHandler<T>;
|
|
3
|
+
export { useStorage };
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createStorageHandler } from "../../shared/create-storage-handler/index.js";
|
|
3
|
-
function useStorage(storageKey, options, initialData) {
|
|
4
|
-
const optionsRef = useRef({
|
|
5
|
-
initialData,
|
|
6
|
-
options
|
|
7
|
-
});
|
|
8
|
-
return useMemo(()=>{
|
|
9
|
-
const { initialData: _initialData, options: _options } = optionsRef.current;
|
|
10
|
-
return createStorageHandler(storageKey, _initialData || {}, _options);
|
|
11
|
-
}, [
|
|
12
|
-
storageKey
|
|
13
|
-
]);
|
|
14
|
-
}
|
|
15
|
-
export { useStorage };
|
|
1
|
+
import{useMemo as r,useRef as t}from"react";import{createStorageHandler as e}from"../../shared/create-storage-handler/index.js";function o(o,a,n){let i=t({initialData:n,options:a});return r(()=>{let{initialData:r,options:t}=i.current;return e(o,r||{},t)},[o])}export{o as useStorage};
|
|
@@ -2,5 +2,5 @@ interface UseTitleOptions {
|
|
|
2
2
|
restoreOnUnmount: boolean;
|
|
3
3
|
}
|
|
4
4
|
declare function setTitle(title?: string): void;
|
|
5
|
-
|
|
6
|
-
export {};
|
|
5
|
+
declare function useTitle(title?: string, options?: Partial<UseTitleOptions>): typeof setTitle;
|
|
6
|
+
export { useTitle };
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { $dt, $t, useValidData } from "../use-valid-data/index.js";
|
|
3
|
-
function setTitle(title) {
|
|
4
|
-
if (!title) return;
|
|
5
|
-
document.title = title;
|
|
6
|
-
}
|
|
7
|
-
const validInfo = $dt({
|
|
8
|
-
restoreOnUnmount: $t.boolean(true)
|
|
9
|
-
});
|
|
10
|
-
function useTitle(title, options = {}) {
|
|
11
|
-
const { restoreOnUnmount } = useValidData(options, validInfo);
|
|
12
|
-
useEffect(()=>{
|
|
13
|
-
const originalTitle = document.title;
|
|
14
|
-
setTitle(title);
|
|
15
|
-
return ()=>{
|
|
16
|
-
if (restoreOnUnmount) setTitle(originalTitle);
|
|
17
|
-
};
|
|
18
|
-
}, [
|
|
19
|
-
title,
|
|
20
|
-
restoreOnUnmount
|
|
21
|
-
]);
|
|
22
|
-
return setTitle;
|
|
23
|
-
}
|
|
24
|
-
export { useTitle };
|
|
1
|
+
import{useEffect as t}from"react";import{$dt as e,$t as n,useValidData as o}from"../use-valid-data/index.js";function r(t){t&&(document.title=t)}let i=e({restoreOnUnmount:n.boolean(!0)});function u(e,n={}){let{restoreOnUnmount:l}=o(n,i);return t(()=>{let t=document.title;return r(e),()=>{l&&r(t)}},[e,l]),r}export{u as useTitle};
|
|
@@ -4,7 +4,7 @@ interface Actions<T> {
|
|
|
4
4
|
setRight: () => void;
|
|
5
5
|
toggle: () => void;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export {};
|
|
7
|
+
declare function useToggle(): [boolean, Actions<boolean>];
|
|
8
|
+
declare function useToggle<L>(defaultValue: L): [L, Actions<L>];
|
|
9
|
+
declare function useToggle<L, R>(defaultValue: L, reverseValue: R): [L | R, Actions<L | R>];
|
|
10
|
+
export { useToggle };
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { throwType } from "../../shared/throw-error/index.js";
|
|
3
|
-
function useToggle(defualtValue = false, reverseValue) {
|
|
4
|
-
const [state, setState] = useState(defualtValue);
|
|
5
|
-
const toggleRef = useRef([
|
|
6
|
-
defualtValue,
|
|
7
|
-
void 0 === reverseValue ? !defualtValue : reverseValue
|
|
8
|
-
]);
|
|
9
|
-
const actions = useMemo(()=>{
|
|
10
|
-
const [left, right] = toggleRef.current;
|
|
11
|
-
return {
|
|
12
|
-
set: (value)=>{
|
|
13
|
-
if (value !== left && value !== right) throwType('useToggle', 'value is not left or right');
|
|
14
|
-
setState(value);
|
|
15
|
-
},
|
|
16
|
-
setLeft: ()=>setState(left),
|
|
17
|
-
setRight: ()=>setState(right),
|
|
18
|
-
toggle: ()=>setState((prev)=>prev === left ? right : left)
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
return [
|
|
22
|
-
state,
|
|
23
|
-
actions
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
export { useToggle };
|
|
1
|
+
import{useMemo as e,useRef as t,useState as r}from"react";import{throwType as o}from"../../shared/throw-error/index.js";function g(i=!1,s){let[l,n]=r(i),u=t([i,void 0===s?!i:s]);return[l,e(()=>{let[e,t]=u.current;return{set:r=>{r!==e&&r!==t&&o("useToggle","value is not left or right"),n(r)},setLeft:()=>n(e),setRight:()=>n(t),toggle:()=>n(r=>r===e?t:e)}},[])]}export{g as useToggle};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DataHandlerOptions, Handler } from '../../shared/data-handler/types';
|
|
2
|
-
|
|
3
|
-
export declare function useValidData<T extends Record<PropertyKey, any>, H extends Handler<T> = Handler<T>, O extends DataHandlerOptions<T> = DataHandlerOptions<T> & {
|
|
2
|
+
declare function useValidData<T extends Record<PropertyKey, any>, H extends Handler<T> = Handler<T>, O extends DataHandlerOptions<T> = DataHandlerOptions<T> & {
|
|
4
3
|
unwrap: true;
|
|
5
|
-
}>(data: T, verifyInfo: H, options?: O): O["unwrap"] extends true ? import("../../shared").Printify<import("../../shared/data-handler").Transform2Type<H> extends infer T_1 ? T_1 extends import("../../shared/data-handler").Transform2Type<H> ? T_1 extends (...args: any[]) => any ? T & O["defaultValue"] : T & O["defaultValue"] & { [K in keyof T_1]: import("../../shared").Equal<T_1[K], any> extends true ? Required<T & O["defaultValue"]>[K] : T_1[K]; } : never : never> : {
|
|
6
|
-
result: import("../../shared").Printify<import("../../shared/data-handler").Transform2Type<H> extends infer T_2 ? T_2 extends import("../../shared/data-handler").Transform2Type<H> ? T_2 extends (...args: any[]) => any ? T & O["defaultValue"] : T & O["defaultValue"] & { [K_1 in keyof T_2]: import("../../shared").Equal<T_2[K_1], any> extends true ? Required<T & O["defaultValue"]>[K_1] : T_2[K_1]; } : never : never>;
|
|
4
|
+
}>(data: T, verifyInfo: H, options?: O): O["unwrap"] extends true ? import("../../shared").Printify<import("../../shared/data-handler/tools").Transform2Type<H> extends infer T_1 ? T_1 extends import("../../shared/data-handler/tools").Transform2Type<H> ? T_1 extends (...args: any[]) => any ? T & O["defaultValue"] : T & O["defaultValue"] & { [K in keyof T_1]: import("../../shared").Equal<T_1[K], any> extends true ? Required<T & O["defaultValue"]>[K] : T_1[K]; } : never : never> : {
|
|
5
|
+
result: import("../../shared").Printify<import("../../shared/data-handler/tools").Transform2Type<H> extends infer T_2 ? T_2 extends import("../../shared/data-handler/tools").Transform2Type<H> ? T_2 extends (...args: any[]) => any ? T & O["defaultValue"] : T & O["defaultValue"] & { [K_1 in keyof T_2]: import("../../shared").Equal<T_2[K_1], any> extends true ? Required<T & O["defaultValue"]>[K_1] : T_2[K_1]; } : never : never>;
|
|
7
6
|
errors: string[];
|
|
8
7
|
};
|
|
8
|
+
export * from '@/shared/data-handler';
|
|
9
|
+
export { useValidData };
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dataHandler } from "../../shared/data-handler/index.js";
|
|
3
|
-
export * from "../../shared/data-handler/tools.js";
|
|
4
|
-
function useValidData(data, verifyInfo, options) {
|
|
5
|
-
const verifyInfoRef = useRef(verifyInfo);
|
|
6
|
-
const optionsRef = useRef(options);
|
|
7
|
-
return useMemo(()=>dataHandler(data, verifyInfoRef.current, {
|
|
8
|
-
unwrap: true,
|
|
9
|
-
...optionsRef.current
|
|
10
|
-
}), [
|
|
11
|
-
data
|
|
12
|
-
]);
|
|
13
|
-
}
|
|
14
|
-
export { useValidData };
|
|
1
|
+
import{useMemo as r,useRef as e}from"react";import{dataHandler as a}from"../../shared/data-handler/index.js";export*from"../../shared/data-handler/index.js";function t(t,n,d){let o=e(n),i=e(d);return r(()=>a(t,o.current,{unwrap:!0,...i.current}),[t])}export{t as useValidData};
|
|
@@ -10,4 +10,5 @@ import type { AllxContext, AllxOptions, AllxResult } from './types';
|
|
|
10
10
|
* async c() { return (await this.$.a) + 10 }
|
|
11
11
|
* })
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
declare function allx<M extends Record<PropertyKey, any>, O extends AllxOptions>(tasks: M & ThisType<AllxContext<M>>, options?: O): Promise<AllxResult<M, O>>;
|
|
14
|
+
export { allx };
|