@cn-ui/reactive
Advanced tools
Comparing version 2.3.0 to 3.0.0
export {}; |
export {}; |
export {}; |
export {}; |
export {}; |
export {}; |
export {}; |
@@ -1,32 +0,5 @@ | ||
import { SignalOptions } from 'solid-js'; | ||
import type { SignalOptions } from 'solid-js'; | ||
import { Atom } from './atom'; | ||
import type { InferArray } from '../typeUtils'; | ||
export interface BaseArrayAtomHandle<T> { | ||
push(...items: T[]): this; | ||
pop(): this; | ||
shift(): this; | ||
unshift(...items: T[]): this; | ||
join(separator?: string): Atom<string>; | ||
indexOf(searchElement: T, fromIndex?: number): Atom<number>; | ||
lastIndexOf(searchElement: T, fromIndex?: number): Atom<number>; | ||
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; | ||
every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is ArrayAtomType<S[]>; | ||
every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): Atom<boolean>; | ||
some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): Atom<boolean>; | ||
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): Atom<T>; | ||
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): Atom<T>; | ||
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): Atom<U>; | ||
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): Atom<T>; | ||
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): Atom<T>; | ||
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): Atom<U>; | ||
reverse(): ArrayAtomType<T[]>; | ||
slice(start?: number, end?: number): ArrayAtomType<T[]>; | ||
sort(compareFn?: (a: T, b: T) => number): ArrayAtomType<T[]>; | ||
splice(start: number, deleteCount?: number): ArrayAtomType<T[]>; | ||
splice(start: number, deleteCount: number, ...items: T[]): ArrayAtomType<T[]>; | ||
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): ArrayAtomType<U[]>; | ||
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): ArrayAtomType<S[]>; | ||
filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): ArrayAtomType<T[]>; | ||
} | ||
export interface ArrayAtomExtends<T> extends BaseArrayAtomHandle<T> { | ||
export interface ArrayAtomExtends<T> { | ||
replace(oldItem: T, newItem: T): this; | ||
@@ -39,3 +12,2 @@ replaceAll(oldItem: T, newItem: T): this; | ||
switch(thisItem: T, nearByItem: T): this; | ||
toggle(thisItem: T): this; | ||
} | ||
@@ -42,0 +14,0 @@ export interface ArrayAtomType<Arr extends any[]> extends Atom<Arr>, ArrayAtomExtends<InferArray<Arr>> { |
@@ -0,0 +0,0 @@ import { Accessor } from 'solid-js'; |
@@ -1,5 +0,5 @@ | ||
import { throttle } from 'lodash-es'; | ||
import { debounce, throttle } from 'lodash-es'; | ||
import { Atom } from './atom'; | ||
/** 呈现 debounceTime 内数据的最新情况 */ | ||
export declare function DebounceAtom<T>(a: Atom<T>, debounceTime?: number): Atom<T>; | ||
export declare function ThrottleAtom<T>(a: Atom<T>, debounceTime?: number, options?: Parameters<typeof throttle>[2]): Atom<T>; | ||
export { throttle, debounce }; |
@@ -0,0 +0,0 @@ export * from './atom'; |
@@ -9,2 +9,14 @@ import type { SignalOptions } from 'solid-js'; | ||
* | ||
* @example | ||
* const form = ObjectAtom({ | ||
* username: '江夏尧', | ||
* password: '124567890', | ||
* }) | ||
* | ||
* form.username() | ||
* form.password() | ||
* | ||
* const submit = ()=>{ | ||
* const result = form() | ||
* } | ||
*/ | ||
@@ -11,0 +23,0 @@ declare function ObjectAtom<T extends Record<string, unknown>>(obj: Atom<T>): ObjectAtomType<T>; |
@@ -26,5 +26,6 @@ export interface ReflectOptions<T> { | ||
* | ||
* @design refect 是为了衍生 Atom,同时具有读写权限。但是不能复用 atom ,atom 中传入函数是把函数当做初始值。 Memo 是只读的,这是它们的区别。 | ||
* @design reflect 是为了衍生 Atom,同时具有读写权限。但是不能复用 atom ,atom 中传入函数是把函数当做初始值。 Memo 是只读的,这是它们的区别。 | ||
*/ | ||
export declare const reflect: <T>(memoFunc: (lastValue: T) => T, { immediately, initValue, }?: ReflectOptions<T>) => import("./atom").Atom<T>; | ||
export declare const computed: <T>(memoFunc: (lastValue: T) => T, { immediately, initValue, }?: ReflectOptions<T>) => import("./atom").Atom<T>; | ||
/** | ||
@@ -31,0 +32,0 @@ * @zh Memo 形式的映射,注意,其为只读特性 |
import { Accessor } from 'solid-js'; | ||
import { Atom } from './atom'; | ||
export interface ResourceBase<T> { | ||
export interface ResourceBase<T, Params> { | ||
loading: Accessor<boolean>; | ||
@@ -8,3 +8,3 @@ error: Accessor<Error>; | ||
/** 重新进行异步行为 */ | ||
refetch: (option?: RefetchOption) => Promise<boolean>; | ||
refetch: (params?: Params, option?: RefetchOption) => Promise<boolean>; | ||
/** 同步突变数据 */ | ||
@@ -15,3 +15,3 @@ mutate: (data: T) => void; | ||
} | ||
export interface ResourceAtom<T> extends ResourceBase<T>, Atom<T> { | ||
export interface ResourceAtom<T, Params = unknown> extends ResourceBase<T, Params>, Atom<T> { | ||
} | ||
@@ -24,5 +24,6 @@ export interface ResourceOptions<T> { | ||
refetch?: RefetchOption; | ||
tap?: (data: T) => void; | ||
/** 忽略报错提示 */ | ||
ignoreError?: boolean; | ||
/** 当成功时,发送副作用 */ | ||
onSuccess?: (data: T) => void; | ||
/** 当发生错误时,发送副作用 */ | ||
onError?: (data: T) => void; | ||
} | ||
@@ -37,4 +38,4 @@ export interface RefetchOption { | ||
* @zh 安全获取异步数据并返回状态 | ||
* @description 使用 resource 创建一个异步绑定的 Atom | ||
* @description 使用 resource 创建一个异步绑定的 Atom,默认直接调用 | ||
*/ | ||
export declare const resource: <T>(fetcher: () => Promise<T>, { initValue, immediately, deps, refetch: defaultRefetch, tap: tapFn, ignoreError, }?: ResourceOptions<T>) => ResourceAtom<T>; | ||
export declare const resource: <T, Params>(fetcher: (val?: Params | undefined) => Promise<T>, { initValue, immediately, deps, refetch: defaultRefetch, onSuccess, onError, }?: ResourceOptions<T>) => ResourceAtom<T, Params>; |
import { Accessor } from 'solid-js'; | ||
import type { EffectFunction } from 'solid-js/types/reactive/signal'; | ||
import type { EffectFunction } from 'solid-js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * @zh 忽略首次执行的 Effect, 但是你需要手动声明依赖 |
export {}; |
export {}; |
export {}; |
export {}; |
@@ -0,0 +0,0 @@ /** |
@@ -15,1 +15,22 @@ /** | ||
}; | ||
/** | ||
* @zh Context 和 useContext 一体化 | ||
* @example | ||
* const ctx = createCtx<{ | ||
* username: '江夏尧', | ||
* password: '123456' | ||
* }>(); | ||
* | ||
* // parent | ||
* ()=> <ctx.Provider value={ctx.defaultValue}></ctx.Provider> | ||
* | ||
* // child | ||
* const info = ctx.use() | ||
* | ||
* */ | ||
export declare const createCtx: <T>(data?: T | undefined) => { | ||
use(): T | undefined; | ||
id: symbol; | ||
Provider: import("solid-js").ContextProviderComponent<T | undefined>; | ||
defaultValue: T | undefined; | ||
}; |
@@ -0,0 +0,0 @@ export * from './blackboard'; |
@@ -7,3 +7,3 @@ import { type Atom, ResourceOptions } from '../atom/index'; | ||
/** | ||
* @zh 逐页查询组件, 内部采用了时间过滤 | ||
* @zh 逐页查询组件, 页码跳转内部采用了时间过滤 | ||
* */ | ||
@@ -24,5 +24,5 @@ export declare const usePagination: <T>(getData: (pageNumber: number, maxPage: Atom<number>) => Promise<T>, init?: PaginationOptions<T>) => { | ||
/** 重新异步获取 */ | ||
refetch: import("lodash-es").DebouncedFunc<() => Promise<boolean>>; | ||
refetch: import("lodash").DebouncedFunc<() => Promise<boolean>>; | ||
goto: (index: number) => false | Promise<boolean> | undefined; | ||
currentData: import("../atom/resource").ResourceAtom<T>; | ||
currentData: import("../atom/resource").ResourceAtom<T, unknown>; | ||
}; | ||
@@ -51,5 +51,5 @@ /** | ||
/** 重新异步获取 */ | ||
refetch: import("lodash-es").DebouncedFunc<() => Promise<boolean>>; | ||
refetch: import("lodash").DebouncedFunc<() => Promise<boolean>>; | ||
goto: (index: number) => false | Promise<boolean> | undefined; | ||
currentData: import("../atom/resource").ResourceAtom<T>; | ||
currentData: import("../atom/resource").ResourceAtom<T, unknown>; | ||
}; |
@@ -0,0 +0,0 @@ import { Atom } from '../atom/index'; |
@@ -0,0 +0,0 @@ export * from './atom'; |
@@ -1,388 +0,374 @@ | ||
var M = Object.defineProperty, R = Object.defineProperties; | ||
var B = Object.getOwnPropertyDescriptors; | ||
var T = Object.getOwnPropertySymbols; | ||
var J = Object.prototype.hasOwnProperty, q = Object.prototype.propertyIsEnumerable; | ||
var P = (t, r, e) => r in t ? M(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e, d = (t, r) => { | ||
for (var e in r || (r = {})) | ||
J.call(r, e) && P(t, e, r[e]); | ||
if (T) | ||
for (var e of T(r)) | ||
q.call(r, e) && P(t, e, r[e]); | ||
return t; | ||
}, v = (t, r) => R(t, B(r)); | ||
var S = (t, r, e) => new Promise((n, s) => { | ||
var o = (c) => { | ||
var B = Object.defineProperty, C = Object.defineProperties; | ||
var F = Object.getOwnPropertyDescriptors; | ||
var k = Object.getOwnPropertySymbols; | ||
var q = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable; | ||
var O = (e, r, t) => r in e ? B(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, w = (e, r) => { | ||
for (var t in r || (r = {})) | ||
q.call(r, t) && O(e, t, r[t]); | ||
if (k) | ||
for (var t of k(r)) | ||
H.call(r, t) && O(e, t, r[t]); | ||
return e; | ||
}, y = (e, r) => C(e, F(r)); | ||
var g = (e, r, t) => new Promise((n, s) => { | ||
var c = (o) => { | ||
try { | ||
a(e.next(c)); | ||
} catch (i) { | ||
s(i); | ||
a(t.next(o)); | ||
} catch (l) { | ||
s(l); | ||
} | ||
}, u = (c) => { | ||
}, u = (o) => { | ||
try { | ||
a(e.throw(c)); | ||
} catch (i) { | ||
s(i); | ||
a(t.throw(o)); | ||
} catch (l) { | ||
s(l); | ||
} | ||
}, a = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(o, u); | ||
a((e = e.apply(t, r)).next()); | ||
}, a = (o) => o.done ? n(o.value) : Promise.resolve(o.value).then(c, u); | ||
a((t = t.apply(e, r)).next()); | ||
}); | ||
import { createEffect as p, on as H, createSignal as _, untrack as $, createMemo as L, batch as k, onCleanup as z } from "solid-js"; | ||
import { debounce as N, throttle as C } from "lodash-es"; | ||
const A = (t, r, e = null) => { | ||
import { createEffect as P, on as $, createSignal as J, untrack as N, createMemo as M, batch as E, createContext as _, useContext as z, onCleanup as K } from "solid-js"; | ||
import { debounce as D, throttle as U } from "lodash-es"; | ||
import { debounce as be, throttle as ve } from "lodash-es"; | ||
const A = (e, r, t = null) => { | ||
let n = !0; | ||
return G( | ||
(s) => n ? (n = !1, null) : t(s), | ||
return W( | ||
(s) => n ? (n = !1, null) : e(s), | ||
r, | ||
e | ||
t | ||
); | ||
}, ne = A, G = (t, r, e = null) => { | ||
let n = e; | ||
return p( | ||
H(r, () => (n = t(n), n)) | ||
}, ne = A, W = (e, r, t = null) => { | ||
let n = t; | ||
return P( | ||
$(r, () => (n = e(n), n)) | ||
); | ||
}, m = Symbol("AtomTypeSymbol"), se = (t) => t[m], f = (t, r) => { | ||
const [e, n] = _(t, r); | ||
}, d = Symbol("AtomTypeSymbol"), oe = (e) => e[d], f = (e, r) => { | ||
const [t, n] = J(e, r); | ||
return Object.assign( | ||
(...s) => s.length === 0 ? e() : n(...s), | ||
{ reflux: K, [m]: "atom" } | ||
(...s) => s.length === 0 ? t() : n(...s), | ||
{ reflux: G, [d]: "atom" } | ||
); | ||
}, K = function(t, r, e) { | ||
const n = this, s = f(t, e); | ||
}, G = function(e, r, t) { | ||
const n = this, s = f(e, t); | ||
return A(() => { | ||
n(() => r(s())); | ||
}, [s]), s[m] = "reflux", s; | ||
}, y = (t, { | ||
}, [s]), s[d] = "reflux", s; | ||
}, S = (e, { | ||
/** 是否立刻求值 (是否忽略第一次求值) */ | ||
immediately: r = !0, | ||
initValue: e = null | ||
/** 如果不进行求值,那么将会之用初始值进行替代 */ | ||
/** @ts-ignore */ | ||
initValue: t = null | ||
} = {}) => { | ||
const n = f(r ? $(() => t(e)) : e); | ||
return p((s) => { | ||
n(() => t(s)); | ||
}, e), n[m] = "reflect", n; | ||
}, U = (t, { | ||
const n = f(r ? N(() => e(t)) : t); | ||
return P((s) => n(() => e(s)), t), n[d] = "reflect", n; | ||
}, se = S, Q = (e, { | ||
/** 是否立刻求值 (是否忽略第一次求值) */ | ||
immediately: r = !0, | ||
initValue: e = null | ||
} = {}) => L((n) => { | ||
const s = t(n); | ||
return r ? s : (r = !0, e); | ||
}, e), V = (t, { | ||
/** 如果不进行求值,那么将会之用初始值进行替代 */ | ||
/** @ts-ignore */ | ||
initValue: t = null | ||
} = {}) => M((n) => { | ||
const s = e(n); | ||
return r ? s : (r = !0, t); | ||
}, t), X = (e, { | ||
/** @ts-ignore */ | ||
initValue: r = null, | ||
immediately: e = !0, | ||
immediately: t = !0, | ||
deps: n, | ||
refetch: s = {}, | ||
tap: o = (a) => { | ||
onSuccess: c = () => { | ||
}, | ||
ignoreError: u = !1 | ||
onError: u = () => { | ||
} | ||
} = {}) => { | ||
const a = f(r), c = f(!1), i = f(!1), l = L(() => !c() && !i()); | ||
const a = f(r), o = f(!1), l = f(!1), i = M(() => !o() && !l()); | ||
let h = Promise.resolve(!1); | ||
const E = (...be) => S(void 0, [...be], function* ({ warn: x = !0, cancelCallback: I } = s) { | ||
l() || (I ? I(h) : x && console.warn( | ||
"Resource Atom: some fetch has been covered; Recommend to add a cancelCallback to some Hook" | ||
)), c(!0); | ||
const O = t().then((g) => (k(() => { | ||
a(() => g), c(!1), i(!1); | ||
}), O === h && o(g), !0)).catch((g) => (k(() => { | ||
i(g), c(!1); | ||
}), u || console.error(g), g)); | ||
return h = O, O; | ||
const b = (Ee, ...Pe) => g(void 0, [Ee, ...Pe], function* (v, { warn: j = !0, cancelCallback: T } = s) { | ||
i() || (T ? T(h) : j && console.warn("Resource Atom: some fetch has been covered; Recommend to add a cancelCallback to some Hook")), o(!0); | ||
const x = e(v).then((m) => (E(() => { | ||
a(() => m), o(!1), l(!1); | ||
}), x === h && c(m), !0)).catch((m) => (E(() => { | ||
l(m), o(!1); | ||
}), u(m), m)); | ||
return h = x, x; | ||
}); | ||
return e && E(), n && n.length && A(() => E(s), n), Object.assign(a, { | ||
error: i, | ||
loading: c, | ||
mutate(x) { | ||
a(() => x); | ||
return t && b(), n && n.length && A(() => b(void 0, s), n), Object.assign(a, { | ||
error: l, | ||
loading: o, | ||
mutate(v) { | ||
a(() => v); | ||
}, | ||
isReady: l, | ||
refetch: E, | ||
isReady: i, | ||
refetch: b, | ||
promise: () => h, | ||
[m]: "resource" | ||
[d]: "resource" | ||
}); | ||
}; | ||
let D = () => { | ||
let L = () => { | ||
}; | ||
const oe = (t) => { | ||
t && (D = t); | ||
}, W = function(t, r = D) { | ||
let e = !1; | ||
const ce = (e) => { | ||
e && (L = e); | ||
}, Y = function(e, r = L) { | ||
let t = !1; | ||
return function(...n) { | ||
return e ? (r && r(), e) : (e = Promise.resolve(t.apply(this, n)).then((s) => (e = !1, s)), e); | ||
return t ? (r && r(), t) : (t = Promise.resolve(e.apply(this, n)).then((s) => (t = !1, s)), t); | ||
}; | ||
}, ce = W; | ||
function j(t) { | ||
return typeof t == "function" ? w(t) ? t : y(t()) : f(t); | ||
}, ue = Y; | ||
function I(e) { | ||
return typeof e == "function" ? p(e) ? e : S(e()) : f(e); | ||
} | ||
function w(t) { | ||
return typeof t[m] == "string"; | ||
function p(e) { | ||
return typeof e[d] == "string"; | ||
} | ||
const ue = (t) => t().map((r, e) => y(() => t()[e])), Q = (t, r) => new Promise((e) => setTimeout(() => e(r), t)), ae = (t, { valueName: r = "value" }) => ({ | ||
value: t(), | ||
"on:input": (e) => t(() => e.target.value) | ||
}), ie = (t, r, e) => { | ||
var o, u, a; | ||
const n = (o = e == null ? void 0 : e.parse) != null ? o : (c) => JSON.parse(c), s = (u = e == null ? void 0 : e.stringify) != null ? u : (c) => JSON.stringify(c); | ||
if ((a = e == null ? void 0 : e.immediately) == null || a) { | ||
const c = localStorage.getItem(r); | ||
c && t(n(c)); | ||
} | ||
return A(() => { | ||
localStorage.setItem(r, s(t())); | ||
}, [t]), t; | ||
}, le = (t) => [...Array(t).keys()], X = (t, r) => Object.fromEntries(r.map((e) => [e, function(...n) { | ||
return t((s) => { | ||
const o = [...s]; | ||
return o[e](...n), o; | ||
}), this; | ||
}])), Y = (t, r) => Object.fromEntries(r.map((e) => [e, function(...n) { | ||
return y(() => t()[e](...n)); | ||
}])), F = (t, r, e = !1) => Object.fromEntries(r.map((n) => [n, function(...s) { | ||
return b(y(e ? () => [...t()][n](...s) : () => t()[n](...s))); | ||
}])); | ||
function b(t, r) { | ||
const e = w(t) ? t : f(t, r), n = (o, u, a) => { | ||
const c = o.findIndex((i) => i === u); | ||
if (c >= 0) { | ||
const i = [...o]; | ||
return a(i, c), i; | ||
const ae = (e) => e().map((r, t) => S(() => e()[t])), Z = (e, r) => new Promise((t) => setTimeout(() => t(r), e)), le = (e) => [...Array(e).keys()]; | ||
function R(e, r) { | ||
const t = p(e) ? e : f(e, r), n = (c, u, a) => { | ||
const o = c.findIndex((l) => l === u); | ||
if (o >= 0) { | ||
const l = [...c]; | ||
return a(l, o), l; | ||
} else | ||
return console.warn("Can't find array atom Item: ", u), o; | ||
}, s = d(d(d(d({ | ||
replace(o, u) { | ||
return e((a) => n(a, o, (c, i) => { | ||
c[i] = u; | ||
return console.warn("Can't find array atom Item: ", u), c; | ||
}; | ||
return Object.assign(t, y(w({}, { | ||
/** 替换一个数组位置 */ | ||
replace(c, u) { | ||
return t((a) => n(a, c, (o, l) => { | ||
o[l] = u; | ||
})), this; | ||
}, | ||
replaceAll(o, u) { | ||
return e((a) => { | ||
const c = []; | ||
a.forEach((l, h) => l === o && c.push(h)); | ||
const i = [...a]; | ||
return c.forEach((l) => i[l] = u), i; | ||
/** 替换所有的数组位置 */ | ||
replaceAll(c, u) { | ||
return t((a) => { | ||
const o = []; | ||
a.forEach((i, h) => i === c && o.push(h)); | ||
const l = [...a]; | ||
return o.forEach((i) => l[i] = u), l; | ||
}), this; | ||
}, | ||
remove(o) { | ||
return e((u) => n(u, o, (a, c) => { | ||
a.splice(c, 1); | ||
/** 根据该元素删除数组中的所有这个元素 */ | ||
remove(c) { | ||
return t((u) => n(u, c, (a, o) => { | ||
a.splice(o, 1); | ||
})), this; | ||
}, | ||
removeAll(o) { | ||
return e((u) => u.filter((a) => a !== o)), this; | ||
removeAll(c) { | ||
return t((u) => u.filter((a) => a !== c)), this; | ||
}, | ||
insert(o, u, a = "before") { | ||
return e((c) => n(c, u, (i, l) => { | ||
i.splice(a === "before" ? l : l + 1, 0, o); | ||
insert(c, u, a = "before") { | ||
return t((o) => n(o, u, (l, i) => { | ||
l.splice(a === "before" ? i : i + 1, 0, c); | ||
})), this; | ||
}, | ||
move(o, u, a) { | ||
return this.remove(o), this.insert(o, u, a), this; | ||
move(c, u, a) { | ||
return this.remove(c), this.insert(c, u, a), this; | ||
}, | ||
switch(o, u) { | ||
return e((a) => { | ||
const c = [...a], i = e().findIndex((h) => h === o), l = e().findIndex((h) => h === u); | ||
if (i === -1 || l === -1) | ||
switch(c, u) { | ||
return t((a) => { | ||
const o = [...a], l = t().findIndex((h) => h === c), i = t().findIndex((h) => h === u); | ||
if (l === -1 || i === -1) | ||
throw new Error("ArrayAtom: Please check the Items you want to switch "); | ||
return c[i] = u, c[l] = o, c; | ||
return o[l] = u, o[i] = c, o; | ||
}), this; | ||
} | ||
}), { [d]: "array" })); | ||
} | ||
function ie(e) { | ||
const r = p(e) ? e : f(e, { equals: !1 }), t = p(e) ? e() : e; | ||
r[d] = "object"; | ||
const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set([d, ...Object.keys(t)]); | ||
return new Proxy(r, { | ||
get(c, u) { | ||
if (!s.has(u)) | ||
throw new Error(`key: ${u} can't be found in formObject!`); | ||
if (n.has(u)) | ||
return n.get(u); | ||
{ | ||
const a = c.reflux(c()[u], (o) => (c()[u] = o, c())); | ||
return n.set(u, a), a; | ||
} | ||
}, | ||
toggle(o) { | ||
return e((u) => { | ||
const a = u.indexOf(o); | ||
return a === -1 ? [...u, o] : [...u.splice(a, 1)]; | ||
}), this; | ||
}, | ||
forEach(o, u) { | ||
p(() => e().forEach(o)); | ||
apply(c, u, a) { | ||
return Reflect.apply(c, u, a); | ||
} | ||
}, X(e, ["push", "pop", "shift", "unshift"])), Y( | ||
e, | ||
[ | ||
"join", | ||
"indexOf", | ||
"lastIndexOf", | ||
"every", | ||
"some", | ||
"reduce", | ||
"reduceRight" | ||
] | ||
)), F( | ||
e, | ||
[ | ||
"slice", | ||
"map", | ||
"filter" | ||
] | ||
)), F( | ||
e, | ||
[ | ||
"reverse", | ||
"sort", | ||
"splice" | ||
], | ||
!0 | ||
)); | ||
return Object.assign(e, v(d({}, s), { [m]: "array" })); | ||
}); | ||
} | ||
function fe(t, r) { | ||
const e = w(t) ? t : f(t, { equals: !1 }), n = w(t) ? t() : t; | ||
return e[m] = "object", Object.assign( | ||
e, | ||
Object.fromEntries( | ||
Object.keys(n).reduce((s, o) => { | ||
const u = e.reflux(e()[o], (a) => v(d({}, e()), { [o]: a })); | ||
return s.push([o, u]), s; | ||
}, []) | ||
) | ||
); | ||
} | ||
function he(t, r = 150) { | ||
let e = t(); | ||
const n = f(e); | ||
function fe(e, r = 150) { | ||
let t = e(); | ||
const n = f(t); | ||
return A( | ||
N(() => { | ||
const s = t(); | ||
D(() => { | ||
const s = e(); | ||
s !== void 0 && n(() => s); | ||
}, r), | ||
[t] | ||
[e] | ||
), n; | ||
} | ||
function de(t, r = 150, e) { | ||
let n = t(); | ||
function he(e, r = 150, t) { | ||
let n = e(); | ||
const s = f(n); | ||
return A( | ||
C( | ||
U( | ||
() => { | ||
const o = t(); | ||
o !== void 0 && s(() => o); | ||
const c = e(); | ||
c !== void 0 && s(() => c); | ||
}, | ||
r, | ||
e | ||
t | ||
), | ||
[t] | ||
[e] | ||
), s; | ||
} | ||
const me = () => { | ||
const t = /* @__PURE__ */ new Map(); | ||
const de = () => { | ||
const e = /* @__PURE__ */ new Map(); | ||
return { | ||
register(r, e) { | ||
if (t.has(r)) | ||
/** 应该在组件声明时进行注册 App,保证在 onMount 时能够获取到数据 */ | ||
register(r, t) { | ||
if (e.has(r)) | ||
throw new Error("Blackboard has a same app named " + r.toString()); | ||
return t.set(r, e); | ||
return e.set(r, t); | ||
}, | ||
/** 在 onMount 阶段可以获取到所有声明的 App */ | ||
getApp(r) { | ||
if (!t.has(r)) | ||
if (!e.has(r)) | ||
throw new Error(`Blackboard app ${r.toString()} isn't init yet`); | ||
return t.get(r); | ||
return e.get(r); | ||
}, | ||
delete(r) { | ||
if (!t.has(r)) | ||
if (!e.has(r)) | ||
throw new Error(`Blackboard app ${r.toString()} isn't init yet`); | ||
t.delete(r); | ||
e.delete(r); | ||
}, | ||
/** 检查APP是否注册*/ | ||
check(r) { | ||
return t.has(r); | ||
return e.has(r); | ||
}, | ||
destroy() { | ||
t.clear(); | ||
e.clear(); | ||
} | ||
}; | ||
}, Z = (t, r = {}) => { | ||
var a, c; | ||
}, me = (e) => { | ||
const r = _(e); | ||
return y(w({}, r), { | ||
use() { | ||
return z(r); | ||
} | ||
}); | ||
}, V = (e, r = {}) => { | ||
var a, o; | ||
r.debounceTime = (a = r.debounceTime) != null ? a : 100; | ||
const e = f((c = r.initIndex) != null ? c : 0), n = f(10), s = V(() => t(e(), n), r), o = N(() => s.refetch(), r.debounceTime), u = (l) => { | ||
if (l < 0 || l >= n()) | ||
const t = f((o = r.initIndex) != null ? o : 0), n = f(10), s = X(() => e(t(), n), r), c = D(() => s.refetch(), r.debounceTime), u = (i) => { | ||
if (i < 0 || i >= n()) | ||
return !1; | ||
{ | ||
e(l); | ||
t(i); | ||
//! 页码改变如果迅速的话,那应该不进行请求,而是直接忽略 | ||
return o(); | ||
return c(); | ||
} | ||
}; | ||
return { | ||
currentIndex: e, | ||
currentPage: U(() => e() + 1), | ||
/** index 数值,从 0 开始 */ | ||
currentIndex: t, | ||
/** 页数 数值,从 1 开始 */ | ||
currentPage: Q(() => t() + 1), | ||
/** 类似于数组的 length ,表示页数 */ | ||
maxPage: n, | ||
prev() { | ||
return u(e() - 1); | ||
return u(t() - 1); | ||
}, | ||
next() { | ||
return u(e() + 1); | ||
return u(t() + 1); | ||
}, | ||
/** | ||
* @zh 保证在下一次请求完成后,promise 结束,如果结束了,那么就稍等 debounceTime 再返回,测试用途较多 | ||
*/ | ||
waitForDone() { | ||
return S(this, null, function* () { | ||
return Q(r.debounceTime + 10).then(s.promise); | ||
return g(this, null, function* () { | ||
return Z(r.debounceTime + 10).then(s.promise); | ||
}); | ||
}, | ||
refetch: o, | ||
/** 重新异步获取 */ | ||
refetch: c, | ||
goto: u, | ||
currentData: s | ||
}; | ||
}, ge = (t, r) => { | ||
const e = f([], { equals: !1 }), n = Z((...s) => S(void 0, null, function* () { | ||
const o = yield t(...s); | ||
return e((u) => (u[s[0]] = o, u)), o; | ||
}, Ae = (e, r) => { | ||
const t = f([], { equals: !1 }), n = V((...s) => g(void 0, null, function* () { | ||
const c = yield e(...s); | ||
return t((u) => (u[s[0]] = c, u)), c; | ||
}), r); | ||
return v(d({}, n), { | ||
return y(w({}, n), { | ||
/** 重置加载 */ | ||
resetStack(s = !0) { | ||
k(() => { | ||
e([]), n.currentIndex(0), s && n.currentData.refetch(); | ||
E(() => { | ||
t([]), n.currentIndex(0), s && n.currentData.refetch(); | ||
}); | ||
}, | ||
dataSlices: e | ||
/** 这个才是需要渲染的最终数据 */ | ||
dataSlices: t | ||
}); | ||
}, ye = function(t = {}) { | ||
}, we = function(e = {}) { | ||
var u, a; | ||
const r = b(j((u = t.activeIds) != null ? u : [])), e = j((a = t.multi) != null ? a : !0), n = f(new Set(r())); | ||
p(() => { | ||
!e() && r((c) => c.slice(0, 1)), n(() => new Set(r())); | ||
const r = R(I((u = e.activeIds) != null ? u : [])), t = I((a = e.multi) != null ? a : !0), n = f(new Set(r())); | ||
P(() => { | ||
!t() && r((o) => o.slice(0, 1)), n(() => new Set(r())); | ||
}); | ||
const s = f(/* @__PURE__ */ new Set(), { equals: !1 }), o = (c, i) => { | ||
i === void 0 && (i = !n().has(c)), i === !0 && !n().has(c) ? r((l) => e() ? [...l, c] : [c]) : i === !1 && r.removeAll(c); | ||
const s = f(/* @__PURE__ */ new Set(), { equals: !1 }), c = (o, l) => { | ||
l === void 0 && (l = !n().has(o)), l === !0 && !n().has(o) ? r((i) => t() ? [...i, o] : [o]) : l === !1 && r.removeAll(o); | ||
}; | ||
return { | ||
changeSelected: o, | ||
register(c, i = !1) { | ||
s((l) => (l.add(c), l)), o(c, i); | ||
/** 更改状态 */ | ||
changeSelected: c, | ||
/** 注册键,可以在任何时候进行注册 */ | ||
register(o, l = !1) { | ||
s((i) => (i.add(o), i)), c(o, l); | ||
}, | ||
deregister(c) { | ||
r.removeAll(c), s((i) => (i.delete(c), i)); | ||
/** 取消整个键的采用 */ | ||
deregister(o) { | ||
r.removeAll(o), s((l) => (l.delete(o), l)); | ||
}, | ||
/** 所有注册过的键 */ | ||
allRegistered: s, | ||
/** 被选中的键的 Set Atom */ | ||
activeIds: n, | ||
isSelected: (c) => n().has(c) | ||
/** 检查一个键是否被选中 */ | ||
isSelected: (o) => n().has(o) | ||
}; | ||
}, Ae = (t, r, e, { | ||
on: n = (o) => o.addEventListener, | ||
off: s = (o) => o.removeEventListener | ||
}, ye = (e, r, t, { | ||
/** @ts-ignore */ | ||
on: n = (c) => c.addEventListener, | ||
/** @ts-ignore */ | ||
off: s = (c) => c.removeEventListener | ||
} = {}) => { | ||
n(t).call(t, r, e), z(() => { | ||
s(t).call(t, r, e); | ||
n(e).call(e, r, t), K(() => { | ||
s(e).call(e, r, t); | ||
}); | ||
}, ve = (t) => { | ||
const r = (e, n, s) => { | ||
const o = s != null ? s : new n(); | ||
return Object.entries(e()).forEach(([u, a]) => { | ||
o.set(u, a.toString()); | ||
}), o; | ||
}, ge = (e) => { | ||
const r = (t, n, s) => { | ||
const c = s != null ? s : new n(); | ||
return Object.entries(t()).forEach(([u, a]) => { | ||
c.set(u, a.toString()); | ||
}), c; | ||
}; | ||
return { | ||
toKeysAtom() { | ||
return y(() => b(Object.keys(t))); | ||
return S(() => R(Object.keys(e))); | ||
}, | ||
toEntries() { | ||
return Object.entries(t()); | ||
return Object.entries(e()); | ||
}, | ||
toFromData(e) { | ||
return r(t, FormData, e); | ||
toFromData(t) { | ||
return r(e, FormData, t); | ||
}, | ||
toSearchParams(e) { | ||
return r(t, URLSearchParams, e); | ||
toSearchParams(t) { | ||
return r(e, URLSearchParams, t); | ||
}, | ||
toHeaders(e) { | ||
return r(t, Headers, e); | ||
toHeaders(t) { | ||
return r(e, Headers, t); | ||
}, | ||
toMap(e) { | ||
return r(t, Map, e); | ||
toMap(t) { | ||
return r(e, Map, t); | ||
}, | ||
toJSON() { | ||
return JSON.stringify(t()); | ||
return JSON.stringify(e()); | ||
} | ||
@@ -392,32 +378,34 @@ }; | ||
export { | ||
b as ArrayAtom, | ||
ue as AtomToArray, | ||
m as AtomTypeSymbol, | ||
he as DebounceAtom, | ||
ve as EntriesTransform, | ||
fe as ObjectAtom, | ||
de as ThrottleAtom, | ||
ae as VModel, | ||
Ae as addListener, | ||
W as asyncLock, | ||
R as ArrayAtom, | ||
ae as AtomToArray, | ||
d as AtomTypeSymbol, | ||
fe as DebounceAtom, | ||
ge as EntriesTransform, | ||
ie as ObjectAtom, | ||
he as ThrottleAtom, | ||
ye as addListener, | ||
Y as asyncLock, | ||
f as atom, | ||
j as atomization, | ||
me as createBlackBoard, | ||
I as atomization, | ||
se as computed, | ||
de as createBlackBoard, | ||
me as createCtx, | ||
ne as createIgnoreFirst, | ||
be as debounce, | ||
le as genArray, | ||
se as getAtomType, | ||
w as isAtom, | ||
ie as localSync, | ||
y as reflect, | ||
U as reflectMemo, | ||
V as resource, | ||
oe as setAsyncLockDefaultRefuse, | ||
Q as sleep, | ||
G as useEffect, | ||
oe as getAtomType, | ||
p as isAtom, | ||
S as reflect, | ||
Q as reflectMemo, | ||
X as resource, | ||
ce as setAsyncLockDefaultRefuse, | ||
Z as sleep, | ||
ve as throttle, | ||
W as useEffect, | ||
A as useEffectWithoutFirst, | ||
Z as usePagination, | ||
ge as usePaginationStack, | ||
ye as useSelect, | ||
ce as useSingleAsync | ||
V as usePagination, | ||
Ae as usePaginationStack, | ||
we as useSelect, | ||
ue as useSingleAsync | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -10,3 +10,3 @@ import type { Atom } from '../atom/atom'; | ||
/** | ||
* @zh ObjectAtom 的转换器,主要是服务于 FormData 等一系列的特殊属性 | ||
* @zh ObjectAtom 的转换器,主要是服务于 对象转换成 FormData 等一系列的特殊属性 | ||
* @example EntriesTransform(atomA).toFromData() | ||
@@ -13,0 +13,0 @@ */ |
export * from './EntriesTransform'; |
export type InferArray<T> = T extends (infer U)[] ? U : never; |
export {}; |
@@ -0,0 +0,0 @@ /** 设置全局的拒绝事件 */ |
@@ -0,0 +0,0 @@ import type { Accessor } from 'solid-js'; |
@@ -5,3 +5,1 @@ export * from './asyncLock'; | ||
export declare const genArray: (num: number) => number[]; | ||
export * from './VModel'; | ||
export * from './localSync'; |
export declare const sleep: <T>(ms: number, data?: T | undefined) => Promise<T>; |
{ | ||
"name": "@cn-ui/reactive", | ||
"version": "2.3.0", | ||
"description": "", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@astrojs/solid-js": "^2.0.2", | ||
"@astrojs/tailwind": "^3.0.1", | ||
"@icon-park/svg": "^1.4.2", | ||
"@tailwindcss/typography": "^0.5.9", | ||
"fs-extra": "^10.1.0", | ||
"tailwindcss": "^3.0.24", | ||
"typescript": "^4.9.4", | ||
"undici": "^5.15.1", | ||
"vite": "^3.2.5", | ||
"vite-plugin-solid": "^2.3.9" | ||
}, | ||
"keywords": [ | ||
"pridepack", | ||
"solid-js", | ||
"use", | ||
"hooks", | ||
"component", | ||
"utils" | ||
], | ||
"dependencies": { | ||
"lodash-es": "^4.17.21", | ||
"mitt": "^3.0.0", | ||
"solid-js": "^1.7.11" | ||
}, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"build-doc": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro", | ||
"build": "vite build && tsc", | ||
"test": "vitest run", | ||
"test-watch": "vitest", | ||
"test-ui": "vitest --ui", | ||
"coverage": "vitest run --coverage", | ||
"prepublish": "pnpm build" | ||
} | ||
} | ||
"name": "@cn-ui/reactive", | ||
"version": "3.0.0", | ||
"description": "", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "vite build && tsc", | ||
"test": "vitest run", | ||
"test-watch": "vitest", | ||
"test-ui": "vitest --ui", | ||
"coverage": "vitest run --coverage", | ||
"prepublish": "pnpm build", | ||
"release": "release-it" | ||
}, | ||
"type": "module", | ||
"license": "MIT", | ||
"keywords": [ | ||
"pridepack", | ||
"solid-js", | ||
"use", | ||
"hooks", | ||
"component", | ||
"utils" | ||
], | ||
"peerDependencies": { | ||
"solid-js": "^1.7.8" | ||
}, | ||
"dependencies": { | ||
"@types/testing-library__jest-dom": "5.14.9", | ||
"lodash-es": "^4.17.21", | ||
"mitt": "^3.0.0", | ||
"solidjs-use": "^2.3.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
70100
5
41
812
1
+ Addedsolidjs-use@^2.3.0
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@jest/expect-utils@29.7.0(transitive)
+ Added@jest/schemas@29.6.3(transitive)
+ Added@jest/types@29.6.3(transitive)
+ Added@sinclair/typebox@0.27.8(transitive)
+ Added@solidjs-use/shared@2.3.0(transitive)
+ Added@solidjs-use/solid-to-vue@2.3.0(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/istanbul-lib-report@3.0.3(transitive)
+ Added@types/istanbul-reports@3.0.4(transitive)
+ Added@types/jest@29.5.14(transitive)
+ Added@types/node@22.10.7(transitive)
+ Added@types/stack-utils@2.0.3(transitive)
+ Added@types/testing-library__jest-dom@5.14.9(transitive)
+ Added@types/web-bluetooth@0.0.16(transitive)
+ Added@types/yargs@17.0.33(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedansi-styles@4.3.05.2.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddiff-sequences@29.6.3(transitive)
+ Addedescape-string-regexp@2.0.0(transitive)
+ Addedexpect@29.7.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjest-diff@29.7.0(transitive)
+ Addedjest-get-type@29.6.3(transitive)
+ Addedjest-matcher-utils@29.7.0(transitive)
+ Addedjest-message-util@29.7.0(transitive)
+ Addedjest-util@29.7.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpretty-format@29.7.0(transitive)
+ Addedreact-is@18.3.1(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsolidjs-use@2.3.0(transitive)
+ Addedstack-utils@2.0.6(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedundici-types@6.20.0(transitive)
- Removedsolid-js@^1.7.11