@the-w1zard/the-cloud 1.0.2 → 1.0.4
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/index.js +25850 -8
- package/package.json +12 -4
- package/dist/hooks/callback.d.ts +0 -1
- package/dist/hooks/callback.js +0 -13
- package/dist/hooks/compose-event-handlers.d.ts +0 -10
- package/dist/hooks/compose-event-handlers.js +0 -10
- package/dist/hooks/core/index.d.ts +0 -1
- package/dist/hooks/core/index.js +0 -1
- package/dist/hooks/core/use-id.d.ts +0 -1
- package/dist/hooks/core/use-id.js +0 -4
- package/dist/hooks/core/use-reducer.d.ts +0 -1
- package/dist/hooks/core/use-reducer.js +0 -14
- package/dist/hooks/core/use-ref.d.ts +0 -92
- package/dist/hooks/core/use-ref.js +0 -559
- package/dist/hooks/core/use-state2.d.ts +0 -1
- package/dist/hooks/core/use-state2.js +0 -15
- package/dist/hooks/deferred_value.d.ts +0 -1
- package/dist/hooks/deferred_value.js +0 -12
- package/dist/hooks/effect.d.ts +0 -1
- package/dist/hooks/effect.js +0 -37
- package/dist/hooks/hooks.d.ts +0 -1
- package/dist/hooks/hooks.js +0 -1
- package/dist/hooks/impertaive_handle.d.ts +0 -3
- package/dist/hooks/impertaive_handle.js +0 -24
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -4
- package/dist/hooks/init_hooks.d.ts +0 -285
- package/dist/hooks/init_hooks.js +0 -285
- package/dist/hooks/lazy.d.ts +0 -3
- package/dist/hooks/lazy.js +0 -15
- package/dist/hooks/memo.d.ts +0 -2
- package/dist/hooks/memo.js +0 -44
- package/dist/hooks/rect.d.ts +0 -24
- package/dist/hooks/rect.js +0 -77
- package/dist/hooks/state.d.ts +0 -1
- package/dist/hooks/state.js +0 -34
- package/dist/hooks/suspense.d.ts +0 -4
- package/dist/hooks/suspense.js +0 -10
- package/dist/hooks/types.d.ts +0 -25
- package/dist/hooks/types.js +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/the-cloud.d.ts +0 -406
- package/dist/the-cloud.js +0 -1386
package/dist/hooks/rect.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observes an element's rectangle on screen (getBoundingClientRect)
|
|
3
|
-
* This is useful to track elements on the screen and attach other elements
|
|
4
|
-
* that might be in different layers, etc.
|
|
5
|
-
*/
|
|
6
|
-
export function observeElementRect(
|
|
7
|
-
/** The element whose rect to observe */
|
|
8
|
-
elementToObserve,
|
|
9
|
-
/** The callback which will be called when the rect changes */
|
|
10
|
-
callback) {
|
|
11
|
-
const observedData = observedElements.get(elementToObserve);
|
|
12
|
-
if (observedData === undefined) {
|
|
13
|
-
// add the element to the map of observed elements with its first callback
|
|
14
|
-
// because this is the first time this element is observed
|
|
15
|
-
observedElements.set(elementToObserve, { rect: {}, callbacks: [callback] });
|
|
16
|
-
if (observedElements.size === 1) {
|
|
17
|
-
// start the internal loop once at least 1 element is observed
|
|
18
|
-
rafId = requestAnimationFrame(runLoop);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// only add a callback for this element as it's already observed
|
|
23
|
-
observedData.callbacks.push(callback);
|
|
24
|
-
callback(elementToObserve.getBoundingClientRect());
|
|
25
|
-
}
|
|
26
|
-
return () => {
|
|
27
|
-
const observedData = observedElements.get(elementToObserve);
|
|
28
|
-
if (observedData === undefined)
|
|
29
|
-
return;
|
|
30
|
-
// start by removing the callback
|
|
31
|
-
const index = observedData.callbacks.indexOf(callback);
|
|
32
|
-
if (index > -1) {
|
|
33
|
-
observedData.callbacks.splice(index, 1);
|
|
34
|
-
}
|
|
35
|
-
if (observedData.callbacks.length === 0) {
|
|
36
|
-
// stop observing this element because there are no
|
|
37
|
-
// callbacks registered for it anymore
|
|
38
|
-
observedElements.delete(elementToObserve);
|
|
39
|
-
if (observedElements.size === 0) {
|
|
40
|
-
// stop the internal loop once no elements are observed anymore
|
|
41
|
-
cancelAnimationFrame(rafId);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
let rafId;
|
|
47
|
-
export const observedElements = new Map();
|
|
48
|
-
export function runLoop() {
|
|
49
|
-
const changedRectsData = [];
|
|
50
|
-
// process all DOM reads first (getBoundingClientRect)
|
|
51
|
-
observedElements.forEach((data, element) => {
|
|
52
|
-
const newRect = element.getBoundingClientRect();
|
|
53
|
-
// gather all the data for elements whose rects have changed
|
|
54
|
-
if (!rectEquals(data.rect, newRect)) {
|
|
55
|
-
data.rect = newRect;
|
|
56
|
-
changedRectsData.push(data);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
// group DOM writes here after the DOM reads (getBoundingClientRect)
|
|
60
|
-
// as DOM writes will most likely happen with the callbacks
|
|
61
|
-
changedRectsData.forEach((data) => {
|
|
62
|
-
data.callbacks.forEach((callback) => callback(data.rect));
|
|
63
|
-
});
|
|
64
|
-
rafId = requestAnimationFrame(runLoop);
|
|
65
|
-
}
|
|
66
|
-
// ========================================================================
|
|
67
|
-
/**
|
|
68
|
-
* Returns whether 2 rects are equal in values
|
|
69
|
-
*/
|
|
70
|
-
export function rectEquals(rect1, rect2) {
|
|
71
|
-
return (rect1.width === rect2.width &&
|
|
72
|
-
rect1.height === rect2.height &&
|
|
73
|
-
rect1.top === rect2.top &&
|
|
74
|
-
rect1.right === rect2.right &&
|
|
75
|
-
rect1.bottom === rect2.bottom &&
|
|
76
|
-
rect1.left === rect2.left);
|
|
77
|
-
}
|
package/dist/hooks/state.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useState<T = any, S = T>(initialValue?: T | (() => T), options?: StateOptions<T, S>, __sauron_id__?: string): readonly [S, (v: T | ((prev: T) => T)) => T, any] | readonly [S, (v: T | ((prev: T) => T)) => T];
|
package/dist/hooks/state.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export function useState(initialValue, options = {}, __sauron_id__ = _sid()) {
|
|
2
|
-
return createHook("useState", __sauron_id__, () => ({
|
|
3
|
-
value: {
|
|
4
|
-
current: typeof initialValue === "function" ? initialValue() : initialValue,
|
|
5
|
-
derived: undefined
|
|
6
|
-
}
|
|
7
|
-
}), (state, key, notify) => {
|
|
8
|
-
const s = state.value;
|
|
9
|
-
const equals = options.equals ?? ((a, b) => a === b);
|
|
10
|
-
const selector = options.selector ?? null;
|
|
11
|
-
const derive = options.derive ?? null;
|
|
12
|
-
const getValue = () => selector ? selector(s.current) : s.current;
|
|
13
|
-
const setValue = (v) => {
|
|
14
|
-
const next = typeof v === "function" ? v(s.current) : v;
|
|
15
|
-
const prevSelected = getValue();
|
|
16
|
-
const nextSelected = selector ? selector(next) : next;
|
|
17
|
-
if (!equals(prevSelected, nextSelected)) {
|
|
18
|
-
s.current = next;
|
|
19
|
-
if (derive) {
|
|
20
|
-
s.derived = derive(next);
|
|
21
|
-
}
|
|
22
|
-
notify(key);
|
|
23
|
-
}
|
|
24
|
-
return next;
|
|
25
|
-
};
|
|
26
|
-
if (derive && s.derived === undefined) {
|
|
27
|
-
s.derived = derive(s.current);
|
|
28
|
-
}
|
|
29
|
-
if (derive) {
|
|
30
|
-
return [getValue(), setValue, s.derived];
|
|
31
|
-
}
|
|
32
|
-
return [getValue(), setValue];
|
|
33
|
-
});
|
|
34
|
-
}
|
package/dist/hooks/suspense.d.ts
DELETED
package/dist/hooks/suspense.js
DELETED
package/dist/hooks/types.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface ProviderProps<T> {
|
|
2
|
-
value: T;
|
|
3
|
-
children?: any | undefined;
|
|
4
|
-
}
|
|
5
|
-
export interface ConsumerProps<T> {
|
|
6
|
-
children: (value: T) => any;
|
|
7
|
-
}
|
|
8
|
-
export interface ExoticComponent<P = {}> {
|
|
9
|
-
(props: P): any;
|
|
10
|
-
readonly $$typeof?: symbol;
|
|
11
|
-
}
|
|
12
|
-
export interface ProviderExoticComponent<P> {
|
|
13
|
-
(props: P): any;
|
|
14
|
-
$$typeof?: symbol;
|
|
15
|
-
}
|
|
16
|
-
export type Provider<T> = ProviderExoticComponent<ProviderProps<T>>;
|
|
17
|
-
export type Consumer<T> = ExoticComponent<ConsumerProps<T>>;
|
|
18
|
-
export interface Context<T> {
|
|
19
|
-
Provider: Provider<T>;
|
|
20
|
-
Consumer: Consumer<T>;
|
|
21
|
-
displayName?: string | undefined;
|
|
22
|
-
_sauronKey: symbol;
|
|
23
|
-
defaultValue: T;
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
}
|
package/dist/hooks/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { root, ROOT, _root, getNestedMap, getMetadata, scheduleGlobalNotify, scheduleNotify, state, _devRecord, devRecord, registerDevRecorder, rerender, flushHookKey, _flushHookNotifications, getCurrentComponent, unmountComponent, mountComponent, hmrPreserve, hmrRestore, subscribeToHook, notifyHook, endHookDependencyCapture, beginHookDependencyCapture, registerDOMBinding, setCurrentComponent, registerDOMRef, getDOMRef, registerAdapter, _reactHookCursor, _currentRenderInstanceCheck, _isReactRenderContext, createHook, _broadcastSS, getChain, getReChain, get, getSauron, getAll, getAllSauron, getMany, setChain, set, setSauron, setMany, subChain, sub, subSauron, subAll, subAllSauron, delSauron, deleteSauron, deleteChain, deleteMany, waitFor, waitForSauron } from './the-cloud.js';
|
|
2
|
-
import { useComposedRefs, composeRefs1, composeRefs, createRefForwarder, useDomRef, forwardRef, mergeAnyRefs, useReactRef, toReactRef, mergeForwardRefs, useForwardedRef, createForwardRef, isForwardRefObject, isForwardRefCallback } from './hooks/core/use-ref.js';
|
|
3
|
-
import { useReducer } from './hooks/core/use-reducer.js';
|
|
4
|
-
import { useRef } from './hooks/core/use-ref.js';
|
|
5
|
-
import { useState2 } from './hooks/core/use-state2.js';
|
|
6
|
-
import { useId } from './hooks/core/use-id.js';
|
|
7
|
-
export { useId, useReducer, useRef, useState2, root, ROOT, _root, getNestedMap, getMetadata, scheduleGlobalNotify, scheduleNotify, state, _devRecord, devRecord, registerDevRecorder, rerender, flushHookKey, _flushHookNotifications, getCurrentComponent, unmountComponent, mountComponent, hmrPreserve, hmrRestore, subscribeToHook, notifyHook, endHookDependencyCapture, beginHookDependencyCapture, registerDOMBinding, setCurrentComponent, registerDOMRef, getDOMRef, registerAdapter, _reactHookCursor, _currentRenderInstanceCheck, _isReactRenderContext, createHook, _broadcastSS, getChain, getReChain, get, getSauron, getAll, getAllSauron, getMany, setChain, set, setSauron, setMany, subChain, sub, subSauron, subAll, subAllSauron, delSauron, deleteSauron, deleteChain, deleteMany, waitFor, waitForSauron, useComposedRefs, composeRefs1, composeRefs, createRefForwarder, useDomRef, forwardRef, mergeAnyRefs, useReactRef, toReactRef, mergeForwardRefs, useForwardedRef, createForwardRef, isForwardRefObject, isForwardRefCallback, };
|
|
8
|
-
/**useSlideIn1 , useCounter , useToggle , useSessionStorage , useLocalStorage , useScript , usePagination ,useSwap , useMutationObserver , useLocales , useLucideDrawerAnimation , useExpandable , useExportMarkdownUsage , useExportMarkdown , useColorTheme , useSlideIn , useSliderWithInput ,useOverlayListener , useOverlayScrollListener , useSse , useStorage ,useCache2 , useControllableStateReducer , useControllableState , useSubmit, useEscapeKeydown ,useDeclarativeSchema , */
|
package/dist/the-cloud.d.ts
DELETED
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
export declare function _sidi(): S;
|
|
2
|
-
declare class SAURON {
|
|
3
|
-
root: ROOT;
|
|
4
|
-
constructor(root?: A);
|
|
5
|
-
online: boolean;
|
|
6
|
-
r: A;
|
|
7
|
-
m: A;
|
|
8
|
-
s: A;
|
|
9
|
-
k: A;
|
|
10
|
-
u: undefined;
|
|
11
|
-
uuuu: undefined[];
|
|
12
|
-
UUUU: any[];
|
|
13
|
-
uuu: undefined[];
|
|
14
|
-
UUU: any[];
|
|
15
|
-
uu: undefined[];
|
|
16
|
-
UU: any[];
|
|
17
|
-
_localChange: boolean;
|
|
18
|
-
_channel: BroadcastChannel | null;
|
|
19
|
-
init_hooks_context: boolean;
|
|
20
|
-
batchDepth: number;
|
|
21
|
-
openScopes: Set<symbol>;
|
|
22
|
-
dirty: Set<FlushCallback>;
|
|
23
|
-
_flushScheduled: boolean;
|
|
24
|
-
_adapter: RuntimeAdapter | null;
|
|
25
|
-
_currentHookState: HookState | null;
|
|
26
|
-
_currentComponent: ComponentInstance | null;
|
|
27
|
-
PRIORITY_ORDER: Priority[];
|
|
28
|
-
GLOBAL_SCOPE: symbol;
|
|
29
|
-
scopeCursors: Record<Priority, number>;
|
|
30
|
-
currentScope: symbol | string;
|
|
31
|
-
loopScheduled: boolean;
|
|
32
|
-
_subscribers: Map<string, Set<() => void>>;
|
|
33
|
-
__subscribers: Map<string, Map<string, Map<string, Map<any, Set<(value: A) => void>>>>>;
|
|
34
|
-
_externalSubscribers: Map<string, Map<string, Map<string, Map<any, Set<(value: A) => void>>>>>;
|
|
35
|
-
_components: Map<string, ComponentInstance>;
|
|
36
|
-
_pendingNotifications: Set<string>;
|
|
37
|
-
externalSubscribers: Set<() => void>;
|
|
38
|
-
readonly instanceId: string;
|
|
39
|
-
_root: ComponentInstance;
|
|
40
|
-
FULFIL_THIS_SAURON_DEPOT(r: A): void;
|
|
41
|
-
getNestedMap<K, V>(s?: any, m?: any, r?: any): Map<K, V>;
|
|
42
|
-
getMetadata(s?: any, m?: any, r?: any): any;
|
|
43
|
-
onFlush(cb: FlushCallback): void;
|
|
44
|
-
scheduleDrain(): void;
|
|
45
|
-
drain(): void;
|
|
46
|
-
microtask(fn: FlushCallback): void;
|
|
47
|
-
batch<T>(fn: () => T): T;
|
|
48
|
-
openBatch(): BatchScope;
|
|
49
|
-
closeBatch(scope: BatchScope): void;
|
|
50
|
-
isBatching(): boolean;
|
|
51
|
-
flushSync(): void;
|
|
52
|
-
flush<T>(fn?: () => T): T | void;
|
|
53
|
-
enqueue(task: ScheduledTask): void;
|
|
54
|
-
scheduleLoop(): void;
|
|
55
|
-
pickNext(): ScheduledTask | undefined;
|
|
56
|
-
runOne(task: ScheduledTask): void;
|
|
57
|
-
drainOne(): void;
|
|
58
|
-
schedule(fn: () => void, opts?: {
|
|
59
|
-
priority?: Priority;
|
|
60
|
-
scope?: string;
|
|
61
|
-
signal?: AbortSignal;
|
|
62
|
-
}): Task;
|
|
63
|
-
withRequestScope<T>(requestId: string, fn: () => T): T;
|
|
64
|
-
yieldToScheduler(): Promise<void>;
|
|
65
|
-
scheduleChunked(work: Iterable<() => void> | Iterator<() => void>, opts?: {
|
|
66
|
-
priority?: Priority;
|
|
67
|
-
scope?: string;
|
|
68
|
-
chunkBudgetMs?: number;
|
|
69
|
-
}): Task;
|
|
70
|
-
_globalNotifyCache: WeakMap<any, Map<any, () => void>>;
|
|
71
|
-
_notifyCache: WeakMap<Map<any, Set<(value: A) => void>>, Map<any, () => void>>;
|
|
72
|
-
scheduleGlobalNotify(key: string | symbol, meta: A, opts: ScopeOptions): void;
|
|
73
|
-
scheduleNotify(key: A, _listeners: Map<A, Set<(value: A) => void>>, _state: Map<A, A>): void;
|
|
74
|
-
store: {
|
|
75
|
-
get: <T = any>(key: A, opts?: ScopeOptions) => T | undefined;
|
|
76
|
-
set: <T = any>(key: A, value: T | ((prev: T | undefined) => T), opts?: {
|
|
77
|
-
triggerRender?: boolean;
|
|
78
|
-
cap?: number;
|
|
79
|
-
} & ScopeOptions) => any;
|
|
80
|
-
subscribe: <T = any>(key: A, listener: (value: T) => void, opts?: ScopeOptions) => (() => void);
|
|
81
|
-
delete: (key: A, opts?: ScopeOptions) => boolean;
|
|
82
|
-
entries: <T = any>(opts?: ScopeOptions) => [A, T][];
|
|
83
|
-
persist: (key: A, opts?: ScopeOptions) => void;
|
|
84
|
-
unpersist: (key: A, opts?: ScopeOptions) => void;
|
|
85
|
-
has: (key: A, opts?: ScopeOptions) => boolean;
|
|
86
|
-
clear: (opts?: ScopeOptions) => void;
|
|
87
|
-
clearPersistent: (opts?: ScopeOptions) => void;
|
|
88
|
-
_emit: (key: string | symbol, sl_reg?: any, ms_reg?: any, globalKey?: any) => void;
|
|
89
|
-
};
|
|
90
|
-
state: SauronState;
|
|
91
|
-
/** public store2 = (() => {
|
|
92
|
-
const sa = {
|
|
93
|
-
get: <T = A>(key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },) => {
|
|
94
|
-
const { s, m, r, } = opts;
|
|
95
|
-
const atom = this.root.SIGNALS.create<T>(key, undefined, undefined, s, m, r,) as SIGNAL_CELL;
|
|
96
|
-
return atom ? atom.node : undefined;
|
|
97
|
-
},
|
|
98
|
-
set: <T = A>(key: SignalKey, value: A, opts: { triggerRender?: boolean; cap?: number; source?: string; } & ScopeOptions = { s: this.s, m: this.m, r: this.r, triggerRender: true, cap: 200, },): T | undefined => {
|
|
99
|
-
const { triggerRender = true, cap = 200, source = "state.set", s, m, r, } = opts;
|
|
100
|
-
const atom = this.root.SIGNALS.create(key, typeof value === "function" ? value() : value, opts, s, m, r,);
|
|
101
|
-
atom.historyMax = cap;
|
|
102
|
-
const next = atom.write((previous: A) => typeof value === "function" ? (value as (prev: T | undefined) => T)(previous) : value, { source, triggerRender },);
|
|
103
|
-
const listeners = this.__subscribers.get(r)?.get(m)?.get(s)?.get(key);
|
|
104
|
-
if (listeners) {
|
|
105
|
-
for (const listener of listeners) {
|
|
106
|
-
try { listener(next); }
|
|
107
|
-
catch (error) { console.error(`[Sauron:state.subscribeAll] listener failed for "${String(atom.key)}":`, error,); }
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return MaybePromise(next);
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
subscribe: <T = A>(key: SignalKey, listener: (value: T) => void, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): Unsubscribe => {
|
|
114
|
-
let msMap = this.__subscribers.get(opts.r);
|
|
115
|
-
|
|
116
|
-
if (!msMap) { msMap = new Map(); this.__subscribers.set(opts.r, msMap); }
|
|
117
|
-
let slMap = msMap.get(opts.m);
|
|
118
|
-
if (!slMap) { slMap = new Map(); msMap.set(opts.m, slMap); }
|
|
119
|
-
let keyMap = slMap.get(opts.s);
|
|
120
|
-
if (!keyMap) { keyMap = new Map(); slMap.set(opts.s, keyMap); }
|
|
121
|
-
let listeners = keyMap.get(key);
|
|
122
|
-
if (!listeners) { listeners = new Set(); keyMap.set(key, listeners); }
|
|
123
|
-
|
|
124
|
-
listeners.add(listener);
|
|
125
|
-
|
|
126
|
-
return () => {
|
|
127
|
-
listeners!.delete(listener);
|
|
128
|
-
if (listeners!.size === 0) { keyMap!.delete(key); }
|
|
129
|
-
if (keyMap!.size === 0) { slMap!.delete(opts.s); }
|
|
130
|
-
if (slMap!.size === 0) { msMap!.delete(opts.m); }
|
|
131
|
-
if (msMap!.size === 0) { this.__subscribers.delete(opts.r); }
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
delete: (key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, }): boolean => {
|
|
136
|
-
const { s, m, r } = opts;
|
|
137
|
-
const registry = this.root.SIGNALS.atom_reg(s, m, r);
|
|
138
|
-
const atom = this.root.SIGNALS.get(key, s, m, r);
|
|
139
|
-
if (!atom) return false;
|
|
140
|
-
const previous = atom.peek();
|
|
141
|
-
const resolvedKey = this.root.SIGNALS.resolveKey(key, s, m, r);
|
|
142
|
-
const listeners = this.__subscribers.get(r)?.get(m)?.get(s)?.get(key);
|
|
143
|
-
if (listeners) for (const listener of listeners) {
|
|
144
|
-
try { listener({ key: atom.key, previous, current: undefined, version: atom.version + 1, timestamp: Date.now(), source: "state.delete" }); }
|
|
145
|
-
catch (error) { console.error(`[Sauron:state.delete] listener failed for "${String(key)}":`, error); }
|
|
146
|
-
}
|
|
147
|
-
const subscribers = this._externalSubscribers.get(r)?.get(m)?.get(s)?.get(key);
|
|
148
|
-
if (subscribers) for (const notify of subscribers) {
|
|
149
|
-
try { notify(undefined); }
|
|
150
|
-
catch (error) { console.error(`[Sauron:state.delete] external subscriber failed for "${String(key)}":`, error); }
|
|
151
|
-
}
|
|
152
|
-
registry.delete(resolvedKey);
|
|
153
|
-
return MaybePromise(true);
|
|
154
|
-
},
|
|
155
|
-
entries: <T = A>(opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): [SignalKey, T][] => {
|
|
156
|
-
const { s, m, r, } = opts;
|
|
157
|
-
const registry = this.root.SIGNALS.atom_reg(s, m, r,);
|
|
158
|
-
return MaybePromise([...registry.entries()].map(([key, atom]) => [key, atom.read() as T,]),
|
|
159
|
-
);
|
|
160
|
-
},
|
|
161
|
-
persist: (key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): void => {
|
|
162
|
-
const atom = this.root.SIGNALS.atom_reg(opts.s, opts.m, opts.r,).get(key);
|
|
163
|
-
if (!atom) return;
|
|
164
|
-
atom.persisted = true;
|
|
165
|
-
setSS(String(atom.key), atom.peek(),);
|
|
166
|
-
},
|
|
167
|
-
unpersist: (key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): void => {
|
|
168
|
-
const atom = this.root.SIGNALS.get(key, opts.s, opts.m, opts.r,);
|
|
169
|
-
if (!atom) return;
|
|
170
|
-
atom.persisted = false;
|
|
171
|
-
deleteSS(String(atom.key));
|
|
172
|
-
},
|
|
173
|
-
has: (key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): boolean => {
|
|
174
|
-
const registry = this.root.SIGNALS.atom_reg(opts.s, opts.m, opts.r,);
|
|
175
|
-
const resolvedKey = this.root.SIGNALS.resolveKey(key, opts.s, opts.m, opts.r,);
|
|
176
|
-
return registry.has(resolvedKey);
|
|
177
|
-
},
|
|
178
|
-
clear: (opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): void => {
|
|
179
|
-
const registry = this.root.SIGNALS.atom_reg(opts.s, opts.m, opts.r,);
|
|
180
|
-
for (const atom of registry.values()) {
|
|
181
|
-
for (const notify of atom.externalSubscribers) {
|
|
182
|
-
try {
|
|
183
|
-
notify();
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.error(
|
|
186
|
-
`[Sauron:state.clear] external subscriber failed:`,
|
|
187
|
-
error,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
atom.listeners.clear();
|
|
193
|
-
atom.externalSubscribers.clear();
|
|
194
|
-
atom.waiters.clear();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
registry.clear();
|
|
198
|
-
},
|
|
199
|
-
clearPersistent: (opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): void => {
|
|
200
|
-
const registry = this.root.SIGNALS.atom_reg(opts.s, opts.m, opts.r,);
|
|
201
|
-
|
|
202
|
-
for (const atom of registry.values()) {
|
|
203
|
-
if (!atom.persisted) continue;
|
|
204
|
-
|
|
205
|
-
atom.persisted = false;
|
|
206
|
-
deleteSS(String(atom.key));
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
_emit: (key: SignalKey, s = this.s, m = this.m, r = this.r,): void => {
|
|
210
|
-
const atom = this.root.SIGNALS.atom_reg(s, m, r,).get('_LISTENERS').get(key);
|
|
211
|
-
if (!atom) return;
|
|
212
|
-
const value = atom.peek();
|
|
213
|
-
for (const listener of atom.listeners) {
|
|
214
|
-
listener({ key: atom.key, previous: value, current: value, version: atom.version, timestamp: Date.now(), source: "state.emit", });
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
for (const notify of atom.externalSubscribers) { notify(); }
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
return sa
|
|
221
|
-
})();
|
|
222
|
-
public state2 = (() => {
|
|
223
|
-
const sa = {
|
|
224
|
-
get: <T = A>(key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): T | undefined => {
|
|
225
|
-
return MaybePromise(this.store.get<T>(key, opts) as T);
|
|
226
|
-
},
|
|
227
|
-
set: <T = A>(key: SignalKey, value: T | ((prev: T | undefined) => T), opts: { triggerRender?: boolean; } & ScopeOptions = { s: this.s, m: this.m, r: this.r, },) => {
|
|
228
|
-
this.store.set(key, value, { triggerRender: opts.triggerRender ?? true, s: opts.s, m: opts.m, r: opts.r, source: "state.set", });
|
|
229
|
-
return MaybePromise(value as T);
|
|
230
|
-
},
|
|
231
|
-
delete: (key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): boolean => {
|
|
232
|
-
return this.store.delete(key, opts);
|
|
233
|
-
},
|
|
234
|
-
getByPrefix: <T = A>(prefix: string, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },) => {
|
|
235
|
-
return this.store.entries<T>(opts).filter(([key]) => { return typeof key === "string" && key.startsWith(prefix); }).map(([key, value]) => ({ key: key as string, value, }));
|
|
236
|
-
},
|
|
237
|
-
getAll: <T = A>(opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): Record<string | symbol, T> => {
|
|
238
|
-
const result: Record<string | symbol, T> = {};
|
|
239
|
-
for (const [key, value] of this.store.entries<T>(opts)) { result[key] = value; }
|
|
240
|
-
return result;
|
|
241
|
-
},
|
|
242
|
-
subscribe: <T = A>(key: SignalKey, listener: (value: T) => void, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): Unsubscribe => {
|
|
243
|
-
return this.store.subscribe<T>(key, listener, opts);
|
|
244
|
-
},
|
|
245
|
-
subscribeAll: (listener: (key: SignalKey, value: unknown) => void, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): Unsubscribe => {
|
|
246
|
-
const scope = this.root.SIGNALS.get(opts.s, opts.m, opts.r,);
|
|
247
|
-
return () => { scope.listeners.delete(listener); };
|
|
248
|
-
},
|
|
249
|
-
clear: (opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): void => {
|
|
250
|
-
this.store.clear(opts);
|
|
251
|
-
},
|
|
252
|
-
waitFor: <T = A>(key: SignalKey, opts: ScopeOptions = { s: this.s, m: this.m, r: this.r, },): Promise<T> => {
|
|
253
|
-
const atom = this.root.SIGNALS.get(opts.s, opts.m, opts.r,);
|
|
254
|
-
if (!atom) { return new Promise<T>(() => { }); }
|
|
255
|
-
|
|
256
|
-
if (atom.hasWritten) {
|
|
257
|
-
return Promise.resolve(atom.read());
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return atom.waitForNext();
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
return sa
|
|
264
|
-
})(); */
|
|
265
|
-
_devRecord: ((componentId: string, hookName: string, sauronId: string, key: string, value: A) => void) | null;
|
|
266
|
-
devRecord(componentId: string, hookName: string, sauronId: string, key: string, value: A): void | undefined;
|
|
267
|
-
registerDevRecorder(fn: typeof this._devRecord): void;
|
|
268
|
-
rerender: (key?: string) => void;
|
|
269
|
-
flushHookKey: (key: string) => void;
|
|
270
|
-
_flushHookNotifications: () => void;
|
|
271
|
-
getCurrentComponent: () => ComponentInstance;
|
|
272
|
-
unmountComponent(id: string): void;
|
|
273
|
-
mountComponent(id: string, renderFn?: () => void): ComponentInstance;
|
|
274
|
-
hmrPreserve(): Map<string, Map<string, A>>;
|
|
275
|
-
hmrRestore(snapshot: Map<string, Map<string, A>>): void;
|
|
276
|
-
subscribeToHook(key: string, cb: () => void): () => void;
|
|
277
|
-
notifyHook(key: string): void;
|
|
278
|
-
endHookDependencyCapture(): void;
|
|
279
|
-
beginHookDependencyCapture(hook: HookState): void;
|
|
280
|
-
registerDOMBinding(node: Node, update: (node: Node, value: A) => void): (() => void) | undefined;
|
|
281
|
-
setCurrentComponent(instance: ComponentInstance | null): void;
|
|
282
|
-
registerDOMRef(name: string, node: Node): void;
|
|
283
|
-
getDOMRef(name: string): Node | undefined;
|
|
284
|
-
registerAdapter(adapter: RuntimeAdapter): void;
|
|
285
|
-
_reactHookCursor: number;
|
|
286
|
-
_currentRenderInstanceCheck: A;
|
|
287
|
-
_isReactRenderContext(): boolean;
|
|
288
|
-
createHook<T>(hookName: string, sauronId: string, initializer: () => HookState, updater: (state: HookState, key: string, notify: (key: string) => void) => T, triggerRender?: boolean): T;
|
|
289
|
-
_broadcastSS(key: A, value: A, storageType: S, fn: S, path?: S, domain?: S, options?: A): void;
|
|
290
|
-
getChain<T = A>(key: A, s?: S, m?: S, r?: S, chain?: CHAIN): any;
|
|
291
|
-
getReChain<T = A>(key: A, s?: S, m?: S, r?: S): any;
|
|
292
|
-
get<T = A>(key: A, s?: S, m?: S, r?: S): any;
|
|
293
|
-
getSauron<T = A>(key: A, s?: S, m?: S, r?: S): any;
|
|
294
|
-
getAll<T = A>(opts?: ScopeOptions): Record<S | symbol, T>;
|
|
295
|
-
getAllSauron<T = A>(opts?: ScopeOptions): Record<S | symbol, T>;
|
|
296
|
-
getMany<T = A>(keys: S[], s?: S, m?: S, r?: S): Promise<Record<string, T | undefined>>;
|
|
297
|
-
setChain<T = A>(label: A, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S): any;
|
|
298
|
-
set<T = A>(label: A, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S): any;
|
|
299
|
-
setSauron<T = A>(label: S, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S): any;
|
|
300
|
-
setMany<T = Record<S, A>>(entries: T): Promise<void>;
|
|
301
|
-
subChain<T = A>(label: S, fn: (value: T) => V, s?: S, m?: S, r?: S): any;
|
|
302
|
-
sub<T = A>(label: A, fn: (value: T) => V, s?: S, m?: S, r?: S): () => V;
|
|
303
|
-
/**
|
|
304
|
-
* subSauronInfinity<MyType>('myKey', (value) => {
|
|
305
|
-
console.log(value) // every value
|
|
306
|
-
})
|
|
307
|
-
*/
|
|
308
|
-
subSauron<T = A>(k: A, fn: (value: T) => void, s?: S, m?: S, r?: S): () => void;
|
|
309
|
-
subAll(fn: (key: A, value: A) => void, s?: S, m?: S, r?: S): () => V;
|
|
310
|
-
subAllSauron(fn: (key: S | symbol, value: A) => V, s?: S, m?: S, r?: S): () => V;
|
|
311
|
-
delSauron(label: S, s?: S, m?: S, r?: S): B;
|
|
312
|
-
deleteSauron(label: A, s?: S, m?: S, r?: S): B;
|
|
313
|
-
deleteChain(label: A, s?: S, m?: S, r?: S): any;
|
|
314
|
-
deleteMany(keys: A[], s?: S, m?: S, r?: S): P<B>;
|
|
315
|
-
waitFor<T = A>(label: S, s?: S, m?: S, r?: S): P<T>;
|
|
316
|
-
waitForSauron<T = A>(label: S, s?: S, m?: S, r?: S): P<T>;
|
|
317
|
-
}
|
|
318
|
-
declare class DRSTimeTravel {
|
|
319
|
-
root: ROOT;
|
|
320
|
-
_time_travel_reverting: boolean;
|
|
321
|
-
constructor(root: ROOT);
|
|
322
|
-
private get sauron();
|
|
323
|
-
private defaultChannels;
|
|
324
|
-
private resolveChannels;
|
|
325
|
-
private resolveHistory;
|
|
326
|
-
history: <T = unknown>(key: SignalKey, channels?: HistoryChannels) => readonly HistoryEntry<T>[];
|
|
327
|
-
private replay;
|
|
328
|
-
graft: (drs: A) => any;
|
|
329
|
-
back: <T = unknown>(key: SignalKey, steps?: number, channels?: HistoryChannels) => T | undefined;
|
|
330
|
-
forward: <T = unknown>(key: SignalKey, steps?: number, channels?: HistoryChannels) => T | undefined;
|
|
331
|
-
goto: <T = unknown>(key: SignalKey, sequence: number, channels?: HistoryChannels) => T | undefined;
|
|
332
|
-
}
|
|
333
|
-
export declare class ROOT {
|
|
334
|
-
SAURON: SAURON;
|
|
335
|
-
TIME_TRAVEL: DRSTimeTravel;
|
|
336
|
-
SIGNALS: SIGNALS;
|
|
337
|
-
r: S;
|
|
338
|
-
m: S;
|
|
339
|
-
s: S;
|
|
340
|
-
isReact: boolean;
|
|
341
|
-
IS_THE_WIZARD: boolean;
|
|
342
|
-
constructor();
|
|
343
|
-
}
|
|
344
|
-
export declare const root: ROOT;
|
|
345
|
-
export declare const signals: SIGNALS;
|
|
346
|
-
export declare const _root: ComponentInstance;
|
|
347
|
-
export declare const getNestedMap: <K, V>(s?: any, m?: any, r?: any) => Map<K, V>;
|
|
348
|
-
export declare const getMetadata: (s?: any, m?: any, r?: any) => any;
|
|
349
|
-
export declare const scheduleGlobalNotify: (key: string | symbol, meta: A, opts: ScopeOptions) => void;
|
|
350
|
-
export declare const scheduleNotify: (key: A, _listeners: Map<A, Set<(value: A) => void>>, _state: Map<A, A>) => void;
|
|
351
|
-
export declare const state: SauronState;
|
|
352
|
-
export declare const _devRecord: ((componentId: string, hookName: string, sauronId: string, key: string, value: A) => void) | null;
|
|
353
|
-
export declare const devRecord: (componentId: string, hookName: string, sauronId: string, key: string, value: A) => void | undefined;
|
|
354
|
-
export declare const registerDevRecorder: (fn: typeof this._devRecord) => void;
|
|
355
|
-
export declare const rerender: (key?: string) => void;
|
|
356
|
-
export declare const flushHookKey: (key: string) => void;
|
|
357
|
-
export declare const _flushHookNotifications: () => void;
|
|
358
|
-
export declare const getCurrentComponent: () => ComponentInstance;
|
|
359
|
-
export declare const unmountComponent: (id: string) => void;
|
|
360
|
-
export declare const mountComponent: (id: string, renderFn?: () => void) => ComponentInstance;
|
|
361
|
-
export declare const hmrPreserve: () => Map<string, Map<string, A>>;
|
|
362
|
-
export declare const hmrRestore: (snapshot: Map<string, Map<string, A>>) => void;
|
|
363
|
-
export declare const subscribeToHook: (key: string, cb: () => void) => () => void;
|
|
364
|
-
export declare const notifyHook: (key: string) => void;
|
|
365
|
-
export declare const endHookDependencyCapture: () => void;
|
|
366
|
-
export declare const beginHookDependencyCapture: (hook: HookState) => void;
|
|
367
|
-
export declare const registerDOMBinding: (node: Node, update: (node: Node, value: A) => void) => (() => void) | undefined;
|
|
368
|
-
export declare const setCurrentComponent: (instance: ComponentInstance | null) => void;
|
|
369
|
-
export declare const registerDOMRef: (name: string, node: Node) => void;
|
|
370
|
-
export declare const getDOMRef: (name: string) => Node | undefined;
|
|
371
|
-
export declare const registerAdapter: (adapter: RuntimeAdapter) => void;
|
|
372
|
-
export declare const _reactHookCursor: number;
|
|
373
|
-
export declare const _currentRenderInstanceCheck: any;
|
|
374
|
-
export declare const _isReactRenderContext: () => boolean;
|
|
375
|
-
export declare const createHook: <T>(hookName: string, sauronId: string, initializer: () => HookState, updater: (state: HookState, key: string, notify: (key: string) => void) => T, triggerRender?: boolean) => T;
|
|
376
|
-
export declare const _broadcastSS: (key: A, value: A, storageType: S, fn: S, path?: S, domain?: S, options?: A) => void;
|
|
377
|
-
export declare const getChain: <T = any>(key: A, s?: S, m?: S, r?: S, chain?: CHAIN) => any;
|
|
378
|
-
export declare const getReChain: <T = any>(key: A, s?: S, m?: S, r?: S) => any;
|
|
379
|
-
export declare const get: <T = any>(key: A, s?: S, m?: S, r?: S) => any;
|
|
380
|
-
export declare const getSauron: <T = any>(key: A, s?: S, m?: S, r?: S) => any;
|
|
381
|
-
export declare const getAll: <T = any>(opts?: ScopeOptions) => Record<S | symbol, T>;
|
|
382
|
-
export declare const getAllSauron: <T = any>(opts?: ScopeOptions) => Record<S | symbol, T>;
|
|
383
|
-
export declare const getMany: <T = any>(keys: S[], s?: S, m?: S, r?: S) => Promise<Record<string, T | undefined>>;
|
|
384
|
-
export declare const setChain: <T = any>(label: A, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S) => any;
|
|
385
|
-
export declare const set: <T = any>(label: A, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S) => any;
|
|
386
|
-
export declare const setSauron: <T = any>(label: S, value: T, triggerRender?: boolean, s?: S, m?: S, r?: S) => any;
|
|
387
|
-
export declare const setMany: <T = Record<string, any>>(entries: T) => Promise<void>;
|
|
388
|
-
export declare const subChain: <T = any>(label: S, fn: (value: T) => V, s?: S, m?: S, r?: S) => any;
|
|
389
|
-
export declare const sub: <T = any>(label: A, fn: (value: T) => V, s?: S, m?: S, r?: S) => () => V;
|
|
390
|
-
export declare const subSauron: <T = any>(k: A, fn: (value: T) => void, s?: S, m?: S, r?: S) => () => void;
|
|
391
|
-
export declare const subAll: (fn: (key: A, value: A) => void, s?: S, m?: S, r?: S) => () => V;
|
|
392
|
-
export declare const subAllSauron: (fn: (key: S | symbol, value: A) => V, s?: S, m?: S, r?: S) => () => V;
|
|
393
|
-
export declare const delSauron: (label: S, s?: S, m?: S, r?: S) => B;
|
|
394
|
-
export declare const deleteSauron: (label: A, s?: S, m?: S, r?: S) => B;
|
|
395
|
-
export declare const deleteChain: (label: A, s?: S, m?: S, r?: S) => any;
|
|
396
|
-
export declare const deleteMany: (keys: A[], s?: S, m?: S, r?: S) => P<B>;
|
|
397
|
-
export declare const waitFor: <T = any>(label: S, s?: S, m?: S, r?: S) => P<T>;
|
|
398
|
-
export declare const waitForSauron: <T = any>(label: S, s?: S, m?: S, r?: S) => P<T>;
|
|
399
|
-
interface sidtype {
|
|
400
|
-
(): S;
|
|
401
|
-
}
|
|
402
|
-
declare global {
|
|
403
|
-
var _sid: sidtype;
|
|
404
|
-
var createHook: <T>(hookName: string, sauronId: string, initializer: () => HookState, updater: (state: HookState, key: string, notify: (key: string) => void) => T, triggerRender?: boolean) => T;
|
|
405
|
-
}
|
|
406
|
-
export {};
|