dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
182 lines (181 loc) • 4.43 kB
JavaScript
import b from "react";
const H = (t) => {
let r;
const e = /* @__PURE__ */ new Set(), o = (l, c) => {
const m = typeof l == "function" ? l(r) : l;
if (!Object.is(m, r)) {
const I = r;
r = c ?? (typeof m != "object" || m === null) ? m : Object.assign({}, r, m), e.forEach((h) => h(r, I));
}
}, a = () => r, u = { setState: o, getState: a, getInitialState: () => f, subscribe: (l) => (e.add(l), () => e.delete(l)) }, f = r = t(o, a, u);
return u;
}, k = ((t) => t ? H(t) : H), E = (t) => t;
function R(t, r = E) {
const e = b.useSyncExternalStore(
t.subscribe,
b.useCallback(() => r(t.getState()), [t, r]),
b.useCallback(() => r(t.getInitialState()), [t, r])
);
return b.useDebugValue(e), e;
}
const O = (t) => {
const r = k(t), e = (o) => R(r, o);
return Object.assign(e, r), e;
}, x = ((t) => t ? O(t) : O);
function F(t, r) {
let e;
try {
e = t();
} catch {
return;
}
return {
getItem: (a) => {
var s;
const S = (f) => f === null ? null : JSON.parse(f, void 0), u = (s = e.getItem(a)) != null ? s : null;
return u instanceof Promise ? u.then(S) : S(u);
},
setItem: (a, s) => e.setItem(a, JSON.stringify(s, void 0)),
removeItem: (a) => e.removeItem(a)
};
}
const w = (t) => (r) => {
try {
const e = t(r);
return e instanceof Promise ? e : {
then(o) {
return w(o)(e);
},
catch(o) {
return this;
}
};
} catch (e) {
return {
then(o) {
return this;
},
catch(o) {
return w(o)(e);
}
};
}
}, J = (t, r) => (e, o, a) => {
let s = {
storage: F(() => window.localStorage),
partialize: (n) => n,
version: 0,
merge: (n, g) => ({
...g,
...n
}),
...r
}, S = !1, u = 0;
const f = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
let c = s.storage;
if (!c)
return t(
(...n) => {
console.warn(
`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`
), e(...n);
},
o,
a
);
const m = () => {
const n = s.partialize({ ...o() });
return c.setItem(s.name, {
state: n,
version: s.version
});
}, I = a.setState;
a.setState = (n, g) => (I(n, g), m());
const h = t(
(...n) => (e(...n), m()),
o,
a
);
a.getInitialState = () => h;
let v;
const C = () => {
var n, g;
if (!c) return;
const p = ++u;
S = !1, f.forEach((i) => {
var d;
return i((d = o()) != null ? d : h);
});
const y = ((g = s.onRehydrateStorage) == null ? void 0 : g.call(s, (n = o()) != null ? n : h)) || void 0;
return w(c.getItem.bind(c))(s.name).then((i) => {
if (i)
if (typeof i.version == "number" && i.version !== s.version) {
if (s.migrate) {
const d = s.migrate(
i.state,
i.version
);
return d instanceof Promise ? d.then((_) => [!0, _]) : [!0, d];
}
console.error(
"State loaded from storage couldn't be migrated since no migrate function was provided"
);
} else
return [!1, i.state];
return [!1, void 0];
}).then((i) => {
var d;
if (p !== u)
return;
const [_, j] = i;
if (v = s.merge(
j,
(d = o()) != null ? d : h
), e(v, !0), _)
return m();
}).then(() => {
p === u && (y == null || y(v, void 0), v = o(), S = !0, l.forEach((i) => i(v)));
}).catch((i) => {
p === u && (y == null || y(void 0, i));
});
};
return a.persist = {
setOptions: (n) => {
s = {
...s,
...n
}, n.storage && (c = n.storage);
},
clearStorage: () => {
c == null || c.removeItem(s.name);
},
getOptions: () => s,
rehydrate: () => C(),
hasHydrated: () => S,
onHydrate: (n) => (f.add(n), () => {
f.delete(n);
}),
onFinishHydration: (n) => (l.add(n), () => {
l.delete(n);
})
}, s.skipHydration || C(), v || h;
}, N = J, L = x()(
N(
(t) => ({
setColumns: (r) => {
t({ storedColumns: r });
},
storedColumns: {}
}),
{
name: "columnsStore"
}
)
);
export {
F as a,
x as c,
N as p,
L as u
};
//# sourceMappingURL=useColumnsStore-ByK5r4ZY.es.js.map