@nice-code/state 0.7.0 → 0.9.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/build/Store-B65MojT2.d.ts +201 -0
- package/build/Store-CI9N0P6I.js +366 -0
- package/build/Store-CI9N0P6I.js.map +1 -0
- package/build/Store-PjfFkZ2I.js +349 -0
- package/build/Store-PjfFkZ2I.js.map +1 -0
- package/build/devtools/browser/index.d.ts +120 -0
- package/build/devtools/browser/index.js +2750 -2357
- package/build/devtools/browser/index.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -244
- package/build/react/index.d.ts +58 -0
- package/build/react/index.js +59 -308
- package/build/react/index.js.map +1 -0
- package/package.json +29 -26
- package/build/types/core/Store.d.ts +0 -136
- package/build/types/core/index.d.ts +0 -1
- package/build/types/devtools/browser/NiceStateDevtools.d.ts +0 -10
- package/build/types/devtools/browser/components/ChangeDetailPanel.d.ts +0 -12
- package/build/types/devtools/browser/components/ChangeList.d.ts +0 -9
- package/build/types/devtools/browser/components/DiffView.d.ts +0 -13
- package/build/types/devtools/browser/components/JsonDiffView.d.ts +0 -24
- package/build/types/devtools/browser/components/JsonView.d.ts +0 -7
- package/build/types/devtools/browser/components/PanelChrome.d.ts +0 -54
- package/build/types/devtools/browser/components/SectionLabel.d.ts +0 -4
- package/build/types/devtools/browser/components/StateInspector.d.ts +0 -16
- package/build/types/devtools/browser/components/StoreTabs.d.ts +0 -12
- package/build/types/devtools/browser/components/utils.d.ts +0 -98
- package/build/types/devtools/browser/devtools_dock.d.ts +0 -54
- package/build/types/devtools/browser/index.d.ts +0 -3
- package/build/types/devtools/core/StateDevtools.types.d.ts +0 -43
- package/build/types/devtools/core/StateDevtoolsCore.d.ts +0 -56
- package/build/types/devtools/core/devtools_colors.d.ts +0 -26
- package/build/types/index.d.ts +0 -1
- package/build/types/react/InjectStoreState.d.ts +0 -18
- package/build/types/react/index.d.ts +0 -3
- package/build/types/react/useLocalStore.d.ts +0 -8
- package/build/types/react/useStoreState.d.ts +0 -23
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { Store } from "../../core/Store";
|
|
2
|
-
import type { IDevtoolsStateChange, IStateDevtoolsSnapshot, TStateDevtoolsListener } from "./StateDevtools.types";
|
|
3
|
-
export interface IStateDevtoolsCoreOptions {
|
|
4
|
-
/** Cap on retained changes across all stores (oldest dropped first). */
|
|
5
|
-
maxChanges?: number;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Framework-agnostic collector for nice-state stores.
|
|
9
|
-
*
|
|
10
|
-
* Register any {@link Store} and the core hooks its patch + update streams,
|
|
11
|
-
* pairing the two so each committed mutation becomes a single
|
|
12
|
-
* {@link IDevtoolsStateChange} with patches and full before/after snapshots.
|
|
13
|
-
* The browser panel ({@link NiceStateDevtools}) renders whatever this exposes.
|
|
14
|
-
*
|
|
15
|
-
* Registering a store attaches a patch listener, which makes Immer compute
|
|
16
|
-
* patches for that store's updates — a negligible dev-time cost. Keep this out
|
|
17
|
-
* of production bundles (the panel is dev-gated, but the core is not).
|
|
18
|
-
*/
|
|
19
|
-
export declare class StateDevtoolsCore {
|
|
20
|
-
private readonly _stores;
|
|
21
|
-
private _changes;
|
|
22
|
-
private readonly _listeners;
|
|
23
|
-
private readonly _maxChanges;
|
|
24
|
-
private _paused;
|
|
25
|
-
private _cuidCounter;
|
|
26
|
-
private _sourceOverride;
|
|
27
|
-
constructor(options?: IStateDevtoolsCoreOptions);
|
|
28
|
-
/**
|
|
29
|
-
* Start observing a store under a human-readable label. Returns an
|
|
30
|
-
* unregister function. If the label collides with an existing store, a numeric
|
|
31
|
-
* suffix is appended to keep ids unique.
|
|
32
|
-
*/
|
|
33
|
-
registerStore(label: string, store: Store<any>): () => void;
|
|
34
|
-
unregisterStore(id: string): void;
|
|
35
|
-
/**
|
|
36
|
-
* Replace a registered store's state wholesale — the primary "edit directly
|
|
37
|
-
* for testing" entry point. The resulting change is tagged `devtools-edit`.
|
|
38
|
-
*/
|
|
39
|
-
applyEdit(storeId: string, newState: unknown): void;
|
|
40
|
-
/**
|
|
41
|
-
* Undo a change by applying its inverse patches. Cleanest for the most recent
|
|
42
|
-
* change of a store; older reverts may not apply if later changes touched the
|
|
43
|
-
* same paths. The resulting change is tagged `devtools-revert`.
|
|
44
|
-
*/
|
|
45
|
-
revertChange(change: IDevtoolsStateChange): void;
|
|
46
|
-
setPaused(paused: boolean): void;
|
|
47
|
-
togglePaused(): void;
|
|
48
|
-
/** Drop the recorded timeline; registered stores and their state remain. */
|
|
49
|
-
clear(): void;
|
|
50
|
-
getSnapshot(): IStateDevtoolsSnapshot;
|
|
51
|
-
subscribe(listener: TStateDevtoolsListener): () => void;
|
|
52
|
-
private _recordChange;
|
|
53
|
-
private _uniqueId;
|
|
54
|
-
private _buildSnapshot;
|
|
55
|
-
private _notify;
|
|
56
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const DEVTOOL_COLOR_SEMANTIC_ERROR = "#FF5C5C";
|
|
2
|
-
export declare const DEVTOOL_COLOR_SEMANTIC_SUCCESS = "#A3E635";
|
|
3
|
-
export declare const DEVTOOL_COLOR_SEMANTIC_SYSTEM = "#38BDF8";
|
|
4
|
-
export declare const DEVTOOL_COLOR_SEMANTIC_WARNING = "#FB923C";
|
|
5
|
-
export declare const DEVTOOL_COLOR_SEMANTIC_METADATA = "#A1A1AA";
|
|
6
|
-
export declare const DEVTOOL_COLOR_TEXT_EMPHASIS = "#f1f5f9";
|
|
7
|
-
export declare const DEVTOOL_COLOR_TEXT_SECONDARY = "#cbd5e1";
|
|
8
|
-
export declare const DEVTOOL_COLOR_TEXT_MUTED = "#64748b";
|
|
9
|
-
export declare const DEVTOOL_COLOR_TEXT_FAINT = "#334155";
|
|
10
|
-
export declare const DEVTOOL_LIST_BASE_BACKGROUND = "#0f172a";
|
|
11
|
-
export declare const DEVTOOL_LIST_SELECTED_BACKGROUND = "#1d2942";
|
|
12
|
-
export declare const DEVTOOL_DETAIL_BASE_BACKGROUND = "#0d1729";
|
|
13
|
-
export declare const DEVTOOL_DETAIL_HEADER_BACKGROUND = "#131f35";
|
|
14
|
-
export declare const DEVTOOL_SECTION_BACKGROUND = "#1e293b";
|
|
15
|
-
export declare const DEVTOOL_SECTION_STRING_BACKGROUND = "#0d131f";
|
|
16
|
-
export declare const DEVTOOL_PANEL_BORDER = "#1e293b";
|
|
17
|
-
export declare const DEVTOOL_PANEL_DIVIDER_BORDER = "#1d3352";
|
|
18
|
-
export declare const DEVTOOL_EDITOR_BACKGROUND = "#08101f";
|
|
19
|
-
export declare const DEVTOOL_ERROR_BACKGROUND = "#1e0a0a";
|
|
20
|
-
export declare const DEVTOOL_JSON_KEY = "#a5b4fc";
|
|
21
|
-
export declare const DEVTOOL_JSON_STRING = "#fbbf24";
|
|
22
|
-
export declare const DEVTOOL_JSON_NUMBER = "#34d399";
|
|
23
|
-
export declare const DEVTOOL_JSON_KEYWORD = "#a78bfa";
|
|
24
|
-
export declare const DEVTOOL_JSON_PUNCTUATION = "#475569";
|
|
25
|
-
export declare const MONO_FONT = "ui-monospace, 'Cascadia Code', 'Source Code Pro', monospace";
|
|
26
|
-
export declare const SANS_FONT = "ui-sans-serif, system-ui, sans-serif";
|
package/build/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./core";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ReactElement } from "react";
|
|
2
|
-
import type { Store } from "../core/Store";
|
|
3
|
-
import { type TEqualityFn } from "./useStoreState";
|
|
4
|
-
export interface IPropsInjectStoreState<S extends object, SS> {
|
|
5
|
-
store: Store<S>;
|
|
6
|
-
on?: (state: S) => SS;
|
|
7
|
-
/**
|
|
8
|
-
* Optional equality function for the selected slice. Defaults to a strict
|
|
9
|
-
* reference check; pass `deepEqual` from `fast-equals` for inline objects.
|
|
10
|
-
*/
|
|
11
|
-
equalityFn?: TEqualityFn<SS>;
|
|
12
|
-
children: (output: SS) => ReactElement;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Render-prop binding: subscribes to `store` (optionally narrowed by `on`) and
|
|
16
|
-
* renders `children` with the selected slice.
|
|
17
|
-
*/
|
|
18
|
-
export declare function InjectStoreState<S extends object, SS = S>({ store, on, equalityFn, children, }: IPropsInjectStoreState<S, SS>): ReactElement;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Store } from "../core/Store";
|
|
2
|
-
/**
|
|
3
|
-
* Create a component-local {@link Store} that persists across renders. Passing a
|
|
4
|
-
* `deps` array re-creates the store (with a fresh initial state) whenever the
|
|
5
|
-
* dependencies change by shallow comparison.
|
|
6
|
-
*/
|
|
7
|
-
declare function useLocalStore<S extends object>(initialState: (() => S) | S, deps?: ReadonlyArray<unknown>): Store<S>;
|
|
8
|
-
export { useLocalStore };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Store } from "../core/Store";
|
|
2
|
-
/**
|
|
3
|
-
* Compares the previously selected value against the next one. Returning `true`
|
|
4
|
-
* tells the hook the value is unchanged, so React is handed the *same*
|
|
5
|
-
* reference and no re-render is scheduled.
|
|
6
|
-
*/
|
|
7
|
-
export type TEqualityFn<SS> = (a: SS, b: SS) => boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Subscribe a React component to a store, optionally narrowing to a derived
|
|
10
|
-
* slice.
|
|
11
|
-
*
|
|
12
|
-
* Built on `useSyncExternalStore`, so it is tear-free under React 18+
|
|
13
|
-
* concurrent rendering with no manual `useState`/`useEffect` subscription loop.
|
|
14
|
-
*
|
|
15
|
-
* A `useRef` cache holds the last selected value. On every store emission the
|
|
16
|
-
* selector is re-evaluated and the result is run through a strict-reference
|
|
17
|
-
* fast-path first; only if the reference differs is `equalityFn` consulted. A
|
|
18
|
-
* new reference is handed back to React exclusively when a genuine change is
|
|
19
|
-
* detected, so equal-but-new selector results never trigger a render.
|
|
20
|
-
*/
|
|
21
|
-
declare function useStoreState<S extends object>(store: Store<S>): S;
|
|
22
|
-
declare function useStoreState<S extends object, SS>(store: Store<S>, getSubState: (state: S) => SS, equalityFn?: TEqualityFn<SS>): SS;
|
|
23
|
-
export { useStoreState };
|