@tooee/overlays 0.2.3 → 0.3.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/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/overlay-context.d.ts +35 -16
- package/dist/overlay-context.d.ts.map +1 -1
- package/dist/overlay-context.js +30 -18
- package/dist/overlay-context.js.map +1 -1
- package/dist/overlay-store.d.ts +44 -23
- package/dist/overlay-store.d.ts.map +1 -1
- package/dist/overlay-store.js +52 -44
- package/dist/overlay-store.js.map +1 -1
- package/dist/overlay-store.typecheck.d.ts +23 -1
- package/dist/overlay-store.typecheck.d.ts.map +1 -1
- package/dist/overlay-store.typecheck.js +16 -10
- package/dist/overlay-store.typecheck.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +12 -4
- package/src/overlay-context.tsx +95 -65
- package/src/overlay-store.ts +134 -77
- package/src/overlay-store.typecheck.ts +80 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { OverlayContext, OverlayControllerContext, OverlayStateContext, useOverlay, useOverlayState, useCurrentOverlay, useHasOverlay, useHasModalOverlay, } from "./overlay-context.js";
|
|
2
|
-
export type { OverlayContextValue, OverlayId, OverlayCloseReason, OverlayOpenOptions, OverlayRole, OverlayRenderArgs, OverlayRenderer, OverlayHandle, OverlayController, OverlayState, } from "./overlay-context.js";
|
|
1
|
+
export { OverlayContext, OverlayControllerContext, OverlayStateContext, overlayUpdater, overlayValue, useOverlay, useOverlayState, useCurrentOverlay, useHasOverlay, useHasModalOverlay, } from "./overlay-context.js";
|
|
2
|
+
export type { OverlayContextValue, OverlayId, OverlayCloseReason, OverlayOpenOptions, OverlayRole, OverlayRenderArgs, OverlayRenderer, OverlayHandle, OverlayController, OverlayState, OverlayUpdate, } from "./overlay-context.js";
|
|
3
3
|
export { createOverlayStore, selectHasOverlay, selectIsOpen, selectStack, selectStackIds, selectTop, } from "./overlay-store.js";
|
|
4
|
-
export type { OverlayClosedEmit, OverlayRecord, OverlayStore, OverlayStoreContext, } from "./overlay-store.js";
|
|
4
|
+
export type { OverlayClosedEmit, OverlayClosedEvent, OverlayClosedTopEvent, OverlayOpenedEvent, OverlayRecord, OverlayStore, OverlayStoreContext, OverlayStoreEvents, OverlayUpdatedEvent, } from "./overlay-store.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,mBAAmB,EACnB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,SAAS,GACV,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { OverlayContext, OverlayControllerContext, OverlayStateContext, useOverlay, useOverlayState, useCurrentOverlay, useHasOverlay, useHasModalOverlay, } from "./overlay-context.js";
|
|
1
|
+
export { OverlayContext, OverlayControllerContext, OverlayStateContext, overlayUpdater, overlayValue, useOverlay, useOverlayState, useCurrentOverlay, useHasOverlay, useHasModalOverlay, } from "./overlay-context.js";
|
|
2
2
|
export { createOverlayStore, selectHasOverlay, selectIsOpen, selectStack, selectStackIds, selectTop, } from "./overlay-store.js";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAc9B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,SAAS,GACV,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { CommandSurfaceRole, Mode } from "@tooee/commands";
|
|
2
3
|
export type OverlayId = string;
|
|
3
4
|
export type OverlayCloseReason = "close" | "escape" | "replaced" | "unmounted";
|
|
4
|
-
export type OverlayRole =
|
|
5
|
+
export type OverlayRole = CommandSurfaceRole;
|
|
5
6
|
export interface OverlayOpenOptions {
|
|
6
7
|
/** Mode to set while overlay is active (default: "insert"). null = don't change mode. */
|
|
7
|
-
mode?:
|
|
8
|
+
mode?: Mode | null;
|
|
8
9
|
/** Restore previous mode on close (default: true) */
|
|
9
10
|
restoreMode?: boolean;
|
|
10
11
|
/** Allow Escape to close this overlay (default: true) */
|
|
@@ -23,30 +24,48 @@ export interface OverlayOpenOptions {
|
|
|
23
24
|
*/
|
|
24
25
|
role?: OverlayRole;
|
|
25
26
|
/** Initial local mode for an owned command surface (default "cursor"). */
|
|
26
|
-
surfaceMode?:
|
|
27
|
+
surfaceMode?: Mode;
|
|
27
28
|
/** Lifecycle callback */
|
|
28
29
|
onClose?: (reason: OverlayCloseReason) => void;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* An overlay payload change. The two cases are explicit because an overlay
|
|
33
|
+
* payload may itself be a function: `{ kind: "value" }` always replaces the
|
|
34
|
+
* payload, `{ kind: "updater" }` always derives it from the previous one. A
|
|
35
|
+
* `typeof next === "function"` check cannot tell those apart, so the caller
|
|
36
|
+
* chooses. Use the `overlayValue` / `overlayUpdater` helpers.
|
|
37
|
+
*/
|
|
38
|
+
export type OverlayUpdate<TPayload = unknown> = {
|
|
39
|
+
kind: "value";
|
|
40
|
+
value: TPayload;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "updater";
|
|
43
|
+
update: (previous: TPayload) => TPayload;
|
|
44
|
+
};
|
|
45
|
+
/** Replace an overlay payload outright (safe even when the payload is a function). */
|
|
46
|
+
export declare const overlayValue: <TPayload>(value: TPayload) => OverlayUpdate<TPayload>;
|
|
47
|
+
/** Derive the next overlay payload from the previous one. */
|
|
48
|
+
export declare const overlayUpdater: <TPayload>(update: (previous: TPayload) => TPayload) => OverlayUpdate<TPayload>;
|
|
30
49
|
export interface OverlayRenderArgs<TPayload> {
|
|
31
50
|
id: OverlayId;
|
|
32
51
|
payload: TPayload;
|
|
33
52
|
isTop: boolean;
|
|
34
53
|
close: (reason?: OverlayCloseReason) => void;
|
|
35
|
-
update: (next: TPayload
|
|
54
|
+
update: (next: OverlayUpdate<TPayload>) => void;
|
|
36
55
|
}
|
|
37
56
|
export type OverlayRenderer<TPayload> = (args: OverlayRenderArgs<TPayload>) => ReactNode;
|
|
38
57
|
export interface OverlayHandle<TPayload> {
|
|
39
58
|
id: OverlayId;
|
|
40
59
|
close: (reason?: OverlayCloseReason) => void;
|
|
41
|
-
update: (next: TPayload
|
|
60
|
+
update: (next: OverlayUpdate<TPayload>) => void;
|
|
42
61
|
}
|
|
43
62
|
export interface OverlayController {
|
|
44
|
-
open<TPayload>(id: OverlayId, render: OverlayRenderer<TPayload>, payload: TPayload, options?: OverlayOpenOptions)
|
|
45
|
-
update<TPayload>(id: OverlayId, next: TPayload
|
|
46
|
-
show(id: OverlayId, content: ReactNode, options?: OverlayOpenOptions)
|
|
47
|
-
hide(id: OverlayId)
|
|
48
|
-
closeTop(reason?: OverlayCloseReason)
|
|
49
|
-
isOpen(id: OverlayId)
|
|
63
|
+
open: <TPayload>(id: OverlayId, render: OverlayRenderer<TPayload>, payload: TPayload, options?: OverlayOpenOptions) => OverlayHandle<TPayload>;
|
|
64
|
+
update: <TPayload>(id: OverlayId, next: OverlayUpdate<TPayload>) => void;
|
|
65
|
+
show: (id: OverlayId, content: ReactNode, options?: OverlayOpenOptions) => void;
|
|
66
|
+
hide: (id: OverlayId) => void;
|
|
67
|
+
closeTop: (reason?: OverlayCloseReason) => void;
|
|
68
|
+
isOpen: (id: OverlayId) => boolean;
|
|
50
69
|
topId: OverlayId | null;
|
|
51
70
|
}
|
|
52
71
|
export interface OverlayState {
|
|
@@ -70,9 +89,9 @@ export interface OverlayContextValue {
|
|
|
70
89
|
export declare const OverlayControllerContext: import("react").Context<OverlayController>;
|
|
71
90
|
export declare const OverlayStateContext: import("react").Context<OverlayState>;
|
|
72
91
|
export declare const OverlayContext: import("react").Context<OverlayContextValue>;
|
|
73
|
-
export declare
|
|
74
|
-
export declare
|
|
75
|
-
export declare
|
|
76
|
-
export declare
|
|
77
|
-
export declare
|
|
92
|
+
export declare const useOverlay: () => OverlayController;
|
|
93
|
+
export declare const useOverlayState: () => OverlayState;
|
|
94
|
+
export declare const useHasOverlay: () => boolean;
|
|
95
|
+
export declare const useHasModalOverlay: () => boolean;
|
|
96
|
+
export declare const useCurrentOverlay: () => ReactNode | null;
|
|
78
97
|
//# sourceMappingURL=overlay-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-context.d.ts","sourceRoot":"","sources":["../src/overlay-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"overlay-context.d.ts","sourceRoot":"","sources":["../src/overlay-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIhE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;AAE/E,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,yFAAyF;IACzF,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yDAAyD;IACzD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,I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AAEF,eAAO,MAAM,eAAe,QAA+B,YAE1D,CAAC;AAEF,eAAO,MAAM,aAAa,QAA6B,OAEtD,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAkC,OAEhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAiC,SAAS,GAAG,IAE1E,CAAC"}
|
package/dist/overlay-context.js
CHANGED
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
+
/** Replace an overlay payload outright (safe even when the payload is a function). */
|
|
3
|
+
export const overlayValue = function overlayValue(value) {
|
|
4
|
+
return { kind: "value", value };
|
|
5
|
+
};
|
|
6
|
+
/** Derive the next overlay payload from the previous one. */
|
|
7
|
+
export const overlayUpdater = function overlayUpdater(update) {
|
|
8
|
+
return { kind: "updater", update };
|
|
9
|
+
};
|
|
2
10
|
// Contexts
|
|
3
11
|
const defaultController = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
show: () => { },
|
|
7
|
-
hide: () => { },
|
|
8
|
-
closeTop: () => { },
|
|
12
|
+
closeTop: () => void 0,
|
|
13
|
+
hide: () => void 0,
|
|
9
14
|
isOpen: () => false,
|
|
15
|
+
open: (id) => ({
|
|
16
|
+
close: () => void 0,
|
|
17
|
+
id,
|
|
18
|
+
update: () => void 0,
|
|
19
|
+
}),
|
|
20
|
+
show: () => void 0,
|
|
10
21
|
topId: null,
|
|
22
|
+
update: () => void 0,
|
|
11
23
|
};
|
|
12
24
|
const defaultState = {
|
|
13
25
|
current: null,
|
|
14
|
-
hasOverlay: false,
|
|
15
26
|
hasModalOverlay: false,
|
|
27
|
+
hasOverlay: false,
|
|
16
28
|
stack: [],
|
|
17
29
|
};
|
|
18
30
|
export const OverlayControllerContext = createContext(defaultController);
|
|
19
31
|
export const OverlayStateContext = createContext(defaultState);
|
|
20
32
|
// Back-compat: OverlayContext that combines both (for existing provider consumers)
|
|
21
33
|
export const OverlayContext = createContext({
|
|
22
|
-
show: () => { },
|
|
23
|
-
hide: () => { },
|
|
24
34
|
current: null,
|
|
25
35
|
hasOverlay: false,
|
|
36
|
+
hide: () => void 0,
|
|
37
|
+
show: () => void 0,
|
|
26
38
|
});
|
|
27
39
|
// Hooks
|
|
28
|
-
export function useOverlay() {
|
|
40
|
+
export const useOverlay = function useOverlay() {
|
|
29
41
|
return useContext(OverlayControllerContext);
|
|
30
|
-
}
|
|
31
|
-
export function useOverlayState() {
|
|
42
|
+
};
|
|
43
|
+
export const useOverlayState = function useOverlayState() {
|
|
32
44
|
return useContext(OverlayStateContext);
|
|
33
|
-
}
|
|
34
|
-
export function useHasOverlay() {
|
|
45
|
+
};
|
|
46
|
+
export const useHasOverlay = function useHasOverlay() {
|
|
35
47
|
return useContext(OverlayStateContext).hasOverlay;
|
|
36
|
-
}
|
|
37
|
-
export function useHasModalOverlay() {
|
|
48
|
+
};
|
|
49
|
+
export const useHasModalOverlay = function useHasModalOverlay() {
|
|
38
50
|
return useContext(OverlayStateContext).hasModalOverlay;
|
|
39
|
-
}
|
|
40
|
-
export function useCurrentOverlay() {
|
|
51
|
+
};
|
|
52
|
+
export const useCurrentOverlay = function useCurrentOverlay() {
|
|
41
53
|
return useContext(OverlayStateContext).current;
|
|
42
|
-
}
|
|
54
|
+
};
|
|
43
55
|
//# sourceMappingURL=overlay-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-context.js","sourceRoot":"","sources":["../src/overlay-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"overlay-context.js","sourceRoot":"","sources":["../src/overlay-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAiDlD,sFAAsF;AACtF,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,YAAY,CAC/C,KAAe;IAEf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAA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,OAAO,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,eAAe;IACrD,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,aAAa;IACjD,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,kBAAkB;IAC3D,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC,eAAe,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,iBAAiB;IACzD,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC;AACjD,CAAC,CAAC"}
|
package/dist/overlay-store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { OverlayCloseReason, OverlayId, OverlayOpenOptions, OverlayRenderer } from "./overlay-context.js";
|
|
1
|
+
import type { OverlayCloseReason, OverlayId, OverlayOpenOptions, OverlayRenderer, OverlayUpdate } from "./overlay-context.js";
|
|
2
|
+
import type { Mode } from "@tooee/commands";
|
|
2
3
|
/**
|
|
3
4
|
* An overlay stack entry as tracked by the store. `prevMode` is the host mode
|
|
4
5
|
* captured at open time (mode itself stays outside this package — see the
|
|
@@ -9,7 +10,7 @@ export interface OverlayRecord<TPayload = unknown> {
|
|
|
9
10
|
render: OverlayRenderer<TPayload>;
|
|
10
11
|
payload: TPayload;
|
|
11
12
|
options: OverlayOpenOptions;
|
|
12
|
-
prevMode:
|
|
13
|
+
prevMode: Mode;
|
|
13
14
|
}
|
|
14
15
|
export interface OverlayStoreContext {
|
|
15
16
|
stack: readonly OverlayRecord[];
|
|
@@ -31,7 +32,7 @@ export interface OverlayClosedEmit {
|
|
|
31
32
|
* above it — R-04); otherwise null. Same-id replacement displacement never
|
|
32
33
|
* restores (the successor takes over).
|
|
33
34
|
*/
|
|
34
|
-
restoreModeTo:
|
|
35
|
+
restoreModeTo: Mode | null;
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Event payload map, passed explicitly as a `createStore` generic
|
|
@@ -43,30 +44,50 @@ export interface OverlayClosedEmit {
|
|
|
43
44
|
* evaluated and rejected: it gives the same strictness while adding runtime
|
|
44
45
|
* schema objects this store does not need.
|
|
45
46
|
*/
|
|
47
|
+
export interface OverlayOpenedEvent {
|
|
48
|
+
record: OverlayRecord;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `next` is a discriminated `OverlayUpdate`, not `unknown | ((prev) => unknown)`:
|
|
52
|
+
* the old union collapsed to `unknown`, so the transition had to guess with
|
|
53
|
+
* `typeof next === "function"` and could not store a function-valued payload.
|
|
54
|
+
* The caller now states which it means.
|
|
55
|
+
*/
|
|
56
|
+
export interface OverlayUpdatedEvent {
|
|
57
|
+
id: OverlayId;
|
|
58
|
+
next: OverlayUpdate;
|
|
59
|
+
}
|
|
60
|
+
export interface OverlayClosedEvent {
|
|
61
|
+
id: OverlayId;
|
|
62
|
+
reason: OverlayCloseReason;
|
|
63
|
+
}
|
|
64
|
+
export interface OverlayClosedTopEvent {
|
|
65
|
+
reason: OverlayCloseReason;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The two payload MAPS below must stay type aliases. XState v4 constrains them
|
|
69
|
+
* with `EventPayloadMap = Record<string, {} | null | undefined>`, and only an
|
|
70
|
+
* object-literal type alias gets TypeScript's implicit index signature — an
|
|
71
|
+
* `interface` is rejected by that constraint. The only way to make an interface
|
|
72
|
+
* satisfy it is to add an index signature, which would OPEN the map and destroy
|
|
73
|
+
* the closed-event-name guarantee pinned by `overlay-store.typecheck.ts`. The
|
|
74
|
+
* payload types themselves are interfaces (above), which is where the rule's
|
|
75
|
+
* intent actually applies.
|
|
76
|
+
*/
|
|
46
77
|
export type OverlayStoreEvents = {
|
|
47
|
-
opened:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
id: OverlayId;
|
|
52
|
-
next: unknown | ((prev: unknown) => unknown);
|
|
53
|
-
};
|
|
54
|
-
closed: {
|
|
55
|
-
id: OverlayId;
|
|
56
|
-
reason: OverlayCloseReason;
|
|
57
|
-
};
|
|
58
|
-
closedTop: {
|
|
59
|
-
reason: OverlayCloseReason;
|
|
60
|
-
};
|
|
78
|
+
opened: OverlayOpenedEvent;
|
|
79
|
+
updated: OverlayUpdatedEvent;
|
|
80
|
+
closed: OverlayClosedEvent;
|
|
81
|
+
closedTop: OverlayClosedTopEvent;
|
|
61
82
|
};
|
|
62
|
-
export declare
|
|
83
|
+
export declare const createOverlayStore: () => import("@xstate/store").Store<OverlayStoreContext, OverlayStoreEvents, OverlayClosedEmit & {
|
|
63
84
|
type: "closed";
|
|
64
85
|
}>;
|
|
65
86
|
export type OverlayStore = ReturnType<typeof createOverlayStore>;
|
|
66
|
-
export declare
|
|
67
|
-
export declare
|
|
68
|
-
export declare
|
|
69
|
-
export declare
|
|
87
|
+
export declare const selectStack: (ctx: OverlayStoreContext) => readonly OverlayRecord[];
|
|
88
|
+
export declare const selectTop: (ctx: OverlayStoreContext) => OverlayRecord | null;
|
|
89
|
+
export declare const selectHasOverlay: (ctx: OverlayStoreContext) => boolean;
|
|
90
|
+
export declare const selectIsOpen: (ctx: OverlayStoreContext, id: OverlayId) => boolean;
|
|
70
91
|
/** Fresh array; prefer selectStack identity + memo in render paths. */
|
|
71
|
-
export declare
|
|
92
|
+
export declare const selectStackIds: (ctx: OverlayStoreContext) => readonly OverlayId[];
|
|
72
93
|
//# sourceMappingURL=overlay-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-store.d.ts","sourceRoot":"","sources":["../src/overlay-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,kBAAkB,EAClB,e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kB,CAAC;IAC3B,SAAS,EAAE,qBAAqB,CAAC;CAClC,CAAC;AAQF,eAAO,MAAM,kBAAkB;;EA6D9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIjE,eAAO,MAAM,WAAW,GACtB,KAAK,mBAAmB,KACvB,SAAS,aAAa,EAExB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAsB,KAAK,mBAAmB,KAAG,aAAa,GAAG,IAEtF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAA6B,KAAK,mBAAmB,KAAG,OAEpF,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,KAAK,mBAAmB,EACxB,IAAI,SAAS,KACZ,OAEF,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,cAAc,GACzB,KAAK,mBAAmB,KACvB,SAAS,SAAS,EAEpB,CAAC"}
|
package/dist/overlay-store.js
CHANGED
|
@@ -4,23 +4,51 @@ import { createStore } from "@xstate/store";
|
|
|
4
4
|
* mutated on open, so there is nothing to restore. For legacy entries, only
|
|
5
5
|
* the topmost non-ownCommands overlay owns the host mode.
|
|
6
6
|
*/
|
|
7
|
-
function restoreModeDecision(stack, record) {
|
|
8
|
-
if (record.options.ownCommands || record.options.restoreMode === false)
|
|
7
|
+
const restoreModeDecision = function restoreModeDecision(stack, record) {
|
|
8
|
+
if (record.options.ownCommands === true || record.options.restoreMode === false) {
|
|
9
9
|
return null;
|
|
10
|
-
|
|
10
|
+
}
|
|
11
|
+
const topLegacy = stack.findLast((entry) => entry.options.ownCommands !== true);
|
|
11
12
|
return topLegacy === record ? record.prevMode : null;
|
|
12
|
-
}
|
|
13
|
-
export function createOverlayStore() {
|
|
13
|
+
};
|
|
14
|
+
export const createOverlayStore = function createOverlayStore() {
|
|
14
15
|
return createStore({
|
|
15
16
|
context: { stack: [] },
|
|
16
17
|
on: {
|
|
18
|
+
closed: (ctx, event, enqueue) => {
|
|
19
|
+
const record = ctx.stack.find((entry) => entry.id === event.id);
|
|
20
|
+
if (!record) {
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
23
|
+
enqueue.emit.closed({
|
|
24
|
+
reason: event.reason,
|
|
25
|
+
record,
|
|
26
|
+
restoreModeTo: restoreModeDecision(ctx.stack, record),
|
|
27
|
+
});
|
|
28
|
+
return { stack: ctx.stack.filter((entry) => entry !== record) };
|
|
29
|
+
},
|
|
30
|
+
closedTop: (ctx, event, enqueue) => {
|
|
31
|
+
if (ctx.stack.length === 0) {
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
const record = ctx.stack.at(-1);
|
|
35
|
+
if (record === undefined) {
|
|
36
|
+
return ctx;
|
|
37
|
+
}
|
|
38
|
+
enqueue.emit.closed({
|
|
39
|
+
reason: event.reason,
|
|
40
|
+
record,
|
|
41
|
+
restoreModeTo: restoreModeDecision(ctx.stack, record),
|
|
42
|
+
});
|
|
43
|
+
return { stack: ctx.stack.slice(0, -1) };
|
|
44
|
+
},
|
|
17
45
|
opened: (ctx, event, enqueue) => {
|
|
18
46
|
// Replacing an existing same-id entry closes it: consumers release
|
|
19
47
|
// open-state (e.g. a picker's isOpen) via the contract's "replaced"
|
|
20
48
|
// reason instead of the entry being silently filtered away.
|
|
21
49
|
const displaced = ctx.stack.find((entry) => entry.id === event.record.id);
|
|
22
50
|
if (displaced) {
|
|
23
|
-
enqueue.emit.closed({
|
|
51
|
+
enqueue.emit.closed({ reason: "replaced", record: displaced, restoreModeTo: null });
|
|
24
52
|
}
|
|
25
53
|
const filtered = displaced
|
|
26
54
|
? ctx.stack.filter((entry) => entry.id !== event.record.id)
|
|
@@ -29,56 +57,36 @@ export function createOverlayStore() {
|
|
|
29
57
|
},
|
|
30
58
|
updated: (ctx, event) => {
|
|
31
59
|
const idx = ctx.stack.findIndex((entry) => entry.id === event.id);
|
|
32
|
-
if (idx === -1)
|
|
60
|
+
if (idx === -1) {
|
|
33
61
|
return ctx;
|
|
62
|
+
}
|
|
34
63
|
const record = ctx.stack[idx];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
64
|
+
if (record === undefined) {
|
|
65
|
+
return ctx;
|
|
66
|
+
}
|
|
67
|
+
const payload = event.next.kind === "updater" ? event.next.update(record.payload) : event.next.value;
|
|
38
68
|
const stack = [...ctx.stack];
|
|
39
69
|
stack[idx] = { ...record, payload };
|
|
40
70
|
return { stack };
|
|
41
71
|
},
|
|
42
|
-
closed: (ctx, event, enqueue) => {
|
|
43
|
-
const record = ctx.stack.find((entry) => entry.id === event.id);
|
|
44
|
-
if (!record)
|
|
45
|
-
return ctx;
|
|
46
|
-
enqueue.emit.closed({
|
|
47
|
-
record,
|
|
48
|
-
reason: event.reason,
|
|
49
|
-
restoreModeTo: restoreModeDecision(ctx.stack, record),
|
|
50
|
-
});
|
|
51
|
-
return { stack: ctx.stack.filter((entry) => entry !== record) };
|
|
52
|
-
},
|
|
53
|
-
closedTop: (ctx, event, enqueue) => {
|
|
54
|
-
if (ctx.stack.length === 0)
|
|
55
|
-
return ctx;
|
|
56
|
-
const record = ctx.stack[ctx.stack.length - 1];
|
|
57
|
-
enqueue.emit.closed({
|
|
58
|
-
record,
|
|
59
|
-
reason: event.reason,
|
|
60
|
-
restoreModeTo: restoreModeDecision(ctx.stack, record),
|
|
61
|
-
});
|
|
62
|
-
return { stack: ctx.stack.slice(0, -1) };
|
|
63
|
-
},
|
|
64
72
|
},
|
|
65
73
|
});
|
|
66
|
-
}
|
|
74
|
+
};
|
|
67
75
|
// --- Selectors ---------------------------------------------------------------
|
|
68
|
-
export function selectStack(ctx) {
|
|
76
|
+
export const selectStack = function selectStack(ctx) {
|
|
69
77
|
return ctx.stack;
|
|
70
|
-
}
|
|
71
|
-
export function selectTop(ctx) {
|
|
72
|
-
return ctx.stack.
|
|
73
|
-
}
|
|
74
|
-
export function selectHasOverlay(ctx) {
|
|
78
|
+
};
|
|
79
|
+
export const selectTop = function selectTop(ctx) {
|
|
80
|
+
return ctx.stack.at(-1) ?? null;
|
|
81
|
+
};
|
|
82
|
+
export const selectHasOverlay = function selectHasOverlay(ctx) {
|
|
75
83
|
return ctx.stack.length > 0;
|
|
76
|
-
}
|
|
77
|
-
export function selectIsOpen(ctx, id) {
|
|
84
|
+
};
|
|
85
|
+
export const selectIsOpen = function selectIsOpen(ctx, id) {
|
|
78
86
|
return ctx.stack.some((entry) => entry.id === id);
|
|
79
|
-
}
|
|
87
|
+
};
|
|
80
88
|
/** Fresh array; prefer selectStack identity + memo in render paths. */
|
|
81
|
-
export function selectStackIds(ctx) {
|
|
89
|
+
export const selectStackIds = function selectStackIds(ctx) {
|
|
82
90
|
return ctx.stack.map((entry) => entry.id);
|
|
83
|
-
}
|
|
91
|
+
};
|
|
84
92
|
//# sourceMappingURL=overlay-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-store.js","sourceRoot":"","sources":["../src/overlay-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"overlay-store.js","sourceRoot":"","sources":["../src/overlay-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA+C5C;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,SAAS,mBAAmB,CACtD,KAA+B,EAC/B,MAAqB;IAErB,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,KAAK,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QAChF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC;IAChF,OAAO,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC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C;AAEF,uEAAuE;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,cAAc,CACnD,GAAwB;IAExB,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import type { OverlayStore } from "./overlay-store.js";
|
|
2
|
+
type Assert<T extends true> = T;
|
|
3
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
4
|
+
type Has<TKeys, TName> = [Extract<TKeys, TName>] extends [never] ? false : true;
|
|
5
|
+
type TriggerNames = keyof OverlayStore["trigger"];
|
|
6
|
+
type SendNames = Parameters<OverlayStore["send"]>[0]["type"];
|
|
7
|
+
type EmittedNames = Parameters<OverlayStore["on"]>[0];
|
|
8
|
+
type KnownTriggers = Assert<Has<TriggerNames, "opened" | "updated" | "closed" | "closedTop">>;
|
|
9
|
+
type KnownSends = Assert<Has<SendNames, "opened" | "updated" | "closed" | "closedTop">>;
|
|
10
|
+
type KnownEmits = Assert<Has<EmittedNames, "closed">>;
|
|
11
|
+
type UnknownTriggerRejected = Assert<IsNever<Extract<TriggerNames, "bogusEvent">>>;
|
|
12
|
+
type UnknownSendRejected = Assert<IsNever<Extract<SendNames, "bogusEvent">>>;
|
|
13
|
+
type UnknownEmitRejected = Assert<IsNever<Extract<EmittedNames, "bogusEmit">>>;
|
|
14
|
+
export type OverlayStoreEventNameChecks = [
|
|
15
|
+
KnownTriggers,
|
|
16
|
+
KnownSends,
|
|
17
|
+
KnownEmits,
|
|
18
|
+
UnknownTriggerRejected,
|
|
19
|
+
UnknownSendRejected,
|
|
20
|
+
UnknownEmitRejected
|
|
21
|
+
];
|
|
22
|
+
export declare const overlayStoreTypeChecks: () => void;
|
|
23
|
+
export {};
|
|
2
24
|
//# sourceMappingURL=overlay-store.typecheck.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-store.typecheck.d.ts","sourceRoot":"","sources":["../src/overlay-store.typecheck.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"overlay-store.typecheck.d.ts","sourceRoot":"","sources":["../src/overlay-store.typecheck.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOtE,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;AAChC,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AACrD,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;AAEhF,KAAK,YAAY,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAC;AAClD,KAAK,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,KAAK,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAItD,KAAK,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC;AAC9F,KAAK,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC;AACxF,KAAK,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;AAItD,KAAK,sBAAsB,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;AACnF,KAAK,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;AAC7E,KAAK,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa;IACb,UAAU;IACV,UAAU;IACV,sBAAsB;IACtB,mBAAmB;IACnB,mBAAmB;CACpB,CAAC;AAGF,eAAO,MAAM,sBAAsB,QAAsC,IAyCxE,CAAC"}
|
|
@@ -1,29 +1,35 @@
|
|
|
1
|
+
import { overlayValue } from "./overlay-context.js";
|
|
1
2
|
import { createOverlayStore } from "./overlay-store.js";
|
|
2
3
|
// Never called; exists only to be typechecked.
|
|
3
|
-
export function overlayStoreTypeChecks() {
|
|
4
|
+
export const overlayStoreTypeChecks = function overlayStoreTypeChecks() {
|
|
4
5
|
const store = createOverlayStore();
|
|
5
6
|
// --- Valid usage must compile -------------------------------------------
|
|
6
7
|
store.trigger.opened({ record });
|
|
7
|
-
store
|
|
8
|
+
// The store's payloads are erased to `unknown`, and `OverlayUpdate<T>` is
|
|
9
|
+
// invariant in T (the updater arm consumes T), so direct store callers erase
|
|
10
|
+
// explicitly. Typed callers go through the shell adapter.
|
|
11
|
+
store.trigger.updated({ id: "x", next: overlayValue(null) });
|
|
8
12
|
store.trigger.closed({ id: "x", reason });
|
|
9
13
|
store.trigger.closedTop({ reason });
|
|
10
|
-
store.send({ type: "closedTop"
|
|
14
|
+
store.send({ reason, type: "closedTop" });
|
|
11
15
|
store.on("closed", (emitted) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const { reason: closeReason, restoreModeTo, record: closedRecord, } = emitted;
|
|
17
|
+
void closeReason;
|
|
18
|
+
void restoreModeTo;
|
|
19
|
+
void closedRecord;
|
|
15
20
|
});
|
|
16
21
|
// --- Unknown event names must NOT compile --------------------------------
|
|
17
|
-
//
|
|
18
|
-
store.trigger.bogusEvent({});
|
|
22
|
+
// (trigger names are covered by the type-level assertions above)
|
|
19
23
|
// @ts-expect-error unknown send event type
|
|
20
24
|
store.send({ type: "bogusEvent" });
|
|
21
25
|
// @ts-expect-error unknown emitted event name
|
|
22
|
-
store.on("bogusEmit", () =>
|
|
26
|
+
store.on("bogusEmit", () => void 0);
|
|
23
27
|
// --- Wrong payloads must NOT compile --------------------------------------
|
|
24
28
|
// @ts-expect-error reason must be an OverlayCloseReason
|
|
25
29
|
store.trigger.closedTop({ reason: 42 });
|
|
26
30
|
// @ts-expect-error record is required
|
|
27
31
|
store.trigger.opened({});
|
|
28
|
-
|
|
32
|
+
// @ts-expect-error a bare value is not an OverlayUpdate (value/updater must be explicit)
|
|
33
|
+
store.trigger.updated({ id: "x", next: "raw-payload" });
|
|
34
|
+
};
|
|
29
35
|
//# sourceMappingURL=overlay-store.typecheck.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-store.typecheck.js","sourceRoot":"","sources":["../src/overlay-store.typecheck.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"overlay-store.typecheck.js","sourceRoot":"","sources":["../src/overlay-store.typecheck.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAqCxD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,sBAAsB;IACnE,MAAM,KAAK,GAAG,kBAAkB,EAAE,CAAC;IAEnC,2EAA2E;IAC3E,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC,0EAA0E;IAC1E,6EAA6E;IAC7E,0DAA0D;IAC1D,KAAK,CAAC,OAAO,CAAC,OAAO,CA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/overlays",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Overlay stack management for Tooee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@tooee/commands": "0.3.0",
|
|
37
38
|
"@xstate/store": "^4"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|