mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
feat(plugin): extract disclosure utils to src/utils/disclosure.ts
This commit is contained in:
parent
e8dac801b1
commit
be858c310e
1 changed files with 21 additions and 0 deletions
21
paperforge/plugin/src/utils/disclosure.ts
Normal file
21
paperforge/plugin/src/utils/disclosure.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export function getDisclosureState(
|
||||
store: Record<string, unknown> | null | undefined,
|
||||
key: string,
|
||||
defaultCollapsed: boolean,
|
||||
): boolean {
|
||||
if (!store || typeof store !== "object") return !!defaultCollapsed;
|
||||
if (!Object.prototype.hasOwnProperty.call(store, key)) return !!defaultCollapsed;
|
||||
return !!store[key];
|
||||
}
|
||||
|
||||
export function toggleDisclosureState(
|
||||
store: Record<string, unknown> | null | undefined,
|
||||
key: string,
|
||||
defaultCollapsed: boolean,
|
||||
): boolean {
|
||||
const next = !getDisclosureState(store, key, defaultCollapsed);
|
||||
if (store && typeof store === "object") {
|
||||
store[key] = next;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
Loading…
Reference in a new issue