@alulore/kumiko 0.16.0 → 0.17.1

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.
Files changed (64) hide show
  1. package/dist/media-viewer/video-controls.js +11 -1
  2. package/dist/shortcuts/bindings.d.ts +50 -0
  3. package/dist/shortcuts/bindings.js +71 -0
  4. package/dist/shortcuts/capture.d.ts +7 -0
  5. package/dist/shortcuts/capture.js +92 -0
  6. package/dist/shortcuts/guard.d.ts +9 -0
  7. package/dist/shortcuts/guard.js +48 -0
  8. package/dist/shortcuts/help.d.ts +29 -0
  9. package/dist/shortcuts/help.js +26 -0
  10. package/dist/shortcuts/hints.d.ts +19 -0
  11. package/dist/shortcuts/hints.js +33 -0
  12. package/dist/shortcuts/index.d.ts +12 -0
  13. package/dist/shortcuts/index.js +12 -0
  14. package/dist/shortcuts/judge.d.ts +42 -0
  15. package/dist/shortcuts/judge.js +34 -0
  16. package/dist/shortcuts/keys.d.ts +11 -0
  17. package/dist/shortcuts/keys.js +89 -0
  18. package/dist/shortcuts/list.d.ts +16 -0
  19. package/dist/shortcuts/list.js +48 -0
  20. package/dist/shortcuts/notes.d.ts +28 -0
  21. package/dist/shortcuts/notes.js +27 -0
  22. package/dist/shortcuts/over-dialogs.d.ts +18 -0
  23. package/dist/shortcuts/over-dialogs.js +38 -0
  24. package/dist/shortcuts/provider.d.ts +98 -0
  25. package/dist/shortcuts/provider.js +116 -0
  26. package/dist/shortcuts/rebinder.d.ts +23 -0
  27. package/dist/shortcuts/rebinder.js +84 -0
  28. package/dist/shortcuts/registration.d.ts +19 -0
  29. package/dist/shortcuts/registration.js +89 -0
  30. package/dist/shortcuts/shortcuts.css +171 -0
  31. package/dist/stored/index.d.ts +4 -0
  32. package/dist/stored/index.js +4 -0
  33. package/dist/stored/storage.d.ts +22 -0
  34. package/dist/stored/storage.js +10 -0
  35. package/dist/stored/stored.d.ts +93 -0
  36. package/dist/stored/stored.js +209 -0
  37. package/dist/stored/use-stored.d.ts +6 -0
  38. package/dist/stored/use-stored.js +12 -0
  39. package/dist/stored/validators.d.ts +6 -0
  40. package/dist/stored/validators.js +13 -0
  41. package/dist/undo/history.d.ts +62 -0
  42. package/dist/undo/history.js +151 -0
  43. package/dist/undo/index.d.ts +10 -0
  44. package/dist/undo/index.js +10 -0
  45. package/dist/undo/undo-adapter.d.ts +35 -0
  46. package/dist/undo/undo-adapter.js +35 -0
  47. package/dist/undo/undo-feedback.d.ts +28 -0
  48. package/dist/undo/undo-feedback.js +69 -0
  49. package/dist/undo/undo-keys.d.ts +32 -0
  50. package/dist/undo/undo-keys.js +76 -0
  51. package/dist/undo/undo-options.d.ts +51 -0
  52. package/dist/undo/undo-options.js +6 -0
  53. package/dist/undo/undo-panel.d.ts +23 -0
  54. package/dist/undo/undo-panel.js +56 -0
  55. package/dist/undo/undo-provider.d.ts +92 -0
  56. package/dist/undo/undo-provider.js +104 -0
  57. package/dist/undo/undo-reveal.d.ts +9 -0
  58. package/dist/undo/undo-reveal.js +45 -0
  59. package/dist/undo/undo-store.d.ts +89 -0
  60. package/dist/undo/undo-store.js +243 -0
  61. package/dist/undo/undo.css +135 -0
  62. package/dist/undo/use-undo-value.d.ts +43 -0
  63. package/dist/undo/use-undo-value.js +85 -0
  64. package/package.json +24 -1
@@ -0,0 +1,171 @@
1
+ @import "../motion/motion.css";
2
+
3
+ @layer kumiko {
4
+ :where(:root) {
5
+ --kumiko-shortcuts-gap: 0.6rem;
6
+ --kumiko-shortcuts-heading-fg: color-mix(in oklab, CanvasText 60%, Canvas);
7
+ --kumiko-shortcuts-row-border: color-mix(in oklab, CanvasText 12%, transparent);
8
+ --kumiko-shortcuts-accent: Highlight;
9
+ --kumiko-shortcuts-danger: #b42318;
10
+ --kumiko-shortcuts-panel-width: 24rem;
11
+ }
12
+
13
+ .kumiko-shortcuts-sheet {
14
+ display: flex;
15
+ flex-direction: column;
16
+ gap: var(--kumiko-shortcuts-gap);
17
+ font-size: 0.875rem;
18
+ }
19
+
20
+ .kumiko-shortcuts-sheet input[type="search"] {
21
+ padding: 0.4rem 0.6rem;
22
+ }
23
+
24
+ .kumiko-shortcuts-list section + section {
25
+ margin-block-start: var(--kumiko-shortcuts-gap);
26
+ }
27
+
28
+ .kumiko-shortcuts-list h3 {
29
+ margin: 0 0 0.25rem;
30
+ color: var(--kumiko-shortcuts-heading-fg);
31
+ font-size: 0.75rem;
32
+ font-weight: 600;
33
+ letter-spacing: 0.04em;
34
+ text-transform: uppercase;
35
+ }
36
+
37
+ .kumiko-shortcuts-list ul {
38
+ margin: 0;
39
+ padding: 0;
40
+ list-style: none;
41
+ }
42
+
43
+ .kumiko-shortcuts-list li {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: 0.35rem 0.75rem;
47
+ align-items: center;
48
+ justify-content: space-between;
49
+ padding: 0.4rem 0;
50
+ border-block-end: 1px solid var(--kumiko-shortcuts-row-border);
51
+ }
52
+
53
+ .kumiko-shortcuts-list li[data-unavailable] .kumiko-shortcuts-name {
54
+ opacity: 0.55;
55
+ }
56
+
57
+ .kumiko-shortcuts-keys,
58
+ .kumiko-shortcuts-editor {
59
+ display: flex;
60
+ flex-wrap: wrap;
61
+ gap: 0.35rem 0.5rem;
62
+ align-items: center;
63
+ }
64
+
65
+ .kumiko-shortcuts-key {
66
+ display: inline-flex;
67
+ gap: 0.25rem;
68
+ align-items: center;
69
+ padding: 0.15rem;
70
+ border-radius: 0.5rem;
71
+ }
72
+
73
+ .kumiko-shortcuts-key[data-changing] {
74
+ outline: 2px solid var(--kumiko-shortcuts-accent);
75
+ }
76
+
77
+ .kumiko-shortcuts-sheet button {
78
+ padding: 0.2rem 0.55rem;
79
+ border: 1px solid var(--kumiko-shortcuts-row-border);
80
+ border-radius: 0.5rem;
81
+ background: transparent;
82
+ color: inherit;
83
+ font: inherit;
84
+ font-size: 0.8125rem;
85
+ cursor: var(--kumiko-press-cursor, pointer);
86
+ }
87
+
88
+ @media (pointer: coarse) {
89
+ .kumiko-shortcuts-sheet button,
90
+ .kumiko-shortcuts-sheet input,
91
+ .kumiko-shortcuts-sheet select {
92
+ min-block-size: var(--kumiko-touch-target, 2.75rem);
93
+ }
94
+ }
95
+
96
+ .kumiko-shortcuts-capture-wrap {
97
+ flex-basis: 100%;
98
+ }
99
+
100
+ .kumiko-shortcuts-capture {
101
+ display: flex;
102
+ flex-wrap: wrap;
103
+ gap: 0.4rem 0.6rem;
104
+ align-items: center;
105
+ margin: 0;
106
+ padding: 0.5rem 0.6rem;
107
+ border: 1px dashed var(--kumiko-shortcuts-accent);
108
+ border-radius: 0.6rem;
109
+ }
110
+
111
+ .kumiko-shortcuts-capture p {
112
+ flex-basis: 100%;
113
+ margin: 0;
114
+ }
115
+
116
+ .kumiko-shortcuts-message {
117
+ margin: 0.3rem 0 0;
118
+ color: var(--kumiko-shortcuts-danger);
119
+ }
120
+
121
+ .kumiko-shortcuts-empty,
122
+ .kumiko-shortcuts-foot,
123
+ .kumiko-shortcuts-none {
124
+ margin: 0;
125
+ color: var(--kumiko-shortcuts-heading-fg);
126
+ }
127
+
128
+ :where([data-slot$="popover-content"].kumiko-shortcuts-popover) {
129
+ inline-size: min(26rem, 100dvw - 2rem);
130
+ max-block-size: 70dvh;
131
+ }
132
+
133
+ /* The panel sits against the inline-end edge and takes the page's full height. */
134
+ [data-slot$="dialog-content"].kumiko-shortcuts-dialog[data-kumiko-shortcuts="panel"]:not(
135
+ [data-presentation="sheet"]
136
+ ) {
137
+ inset-block: 0;
138
+ inset-inline: auto 0;
139
+ margin: 0;
140
+ inline-size: min(var(--kumiko-shortcuts-panel-width), 100dvw);
141
+ block-size: 100dvh;
142
+ max-block-size: 100dvh;
143
+ border-start-end-radius: 0;
144
+ border-end-end-radius: 0;
145
+ }
146
+
147
+ /* A key badge sits on the corner of its control and shows while the mod key is held. */
148
+ .kumiko-shortcuts-target {
149
+ position: relative;
150
+ display: inline-flex;
151
+ }
152
+
153
+ .kumiko-shortcuts-badge {
154
+ position: absolute;
155
+ inset-block-start: -0.7rem;
156
+ inset-inline-end: -0.4rem;
157
+ opacity: 0;
158
+ pointer-events: none;
159
+ transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
160
+ }
161
+
162
+ .kumiko-shortcuts-badge[data-shown] {
163
+ opacity: 1;
164
+ }
165
+
166
+ @media (forced-colors: active) {
167
+ .kumiko-shortcuts-key[data-changing] {
168
+ outline-color: Highlight;
169
+ }
170
+ }
171
+ }
@@ -0,0 +1,4 @@
1
+ export { backendFor, type StoredBackend, type StoredBackendFactory, type StoredStorage } from "./storage";
2
+ export { defineStored, type Stored, type StoredDefinition, type StoredFormat, type StoredInvalid, type StoredOptions, type StoredStatus, type StoredUpdate, type StoredWrites } from "./stored";
3
+ export { useStored } from "./use-stored";
4
+ export { isStringList, numberBetween, oneOf } from "./validators";
@@ -0,0 +1,4 @@
1
+ export { backendFor } from "./storage";
2
+ export { defineStored } from "./stored";
3
+ export { useStored } from "./use-stored";
4
+ export { isStringList, numberBetween, oneOf } from "./validators";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The narrow seam between a stored value and wherever it is kept. ui-sdk's
3
+ * `createLocalStorage(id)` and `createSessionStorage(id)` already fit it, and
4
+ * so does anything an app writes with the same four methods.
5
+ */
6
+ export interface StoredBackend {
7
+ /** The saved text, or null when nothing is saved or reading fails. */
8
+ get: () => string | null;
9
+ /** Saves text. Returns false when the write fails. */
10
+ set: (value: string) => boolean;
11
+ /** Removes the text. Returns false when the removal fails. */
12
+ remove: () => boolean;
13
+ /** Hears the saved text change elsewhere (another tab, another instance). */
14
+ subscribe: (listener: (value: string | null) => void) => () => void;
15
+ /** Whether saving appears possible. Optional; a missing method means yes. */
16
+ available?: () => boolean;
17
+ }
18
+ /** Makes the backend for one key. */
19
+ export type StoredBackendFactory = (id: string) => StoredBackend;
20
+ /** Where a value lives: localStorage, sessionStorage, or an app's own backend. */
21
+ export type StoredStorage = "local" | "session" | StoredBackendFactory;
22
+ export declare function backendFor(storage: StoredStorage, key: string): StoredBackend;
@@ -0,0 +1,10 @@
1
+ import { createLocalStorage, createSessionStorage } from "@ui-sdk/core";
2
+ export function backendFor(storage, key) {
3
+ if (storage === "local") {
4
+ return createLocalStorage(key);
5
+ }
6
+ if (storage === "session") {
7
+ return createSessionStorage(key);
8
+ }
9
+ return storage(key);
10
+ }
@@ -0,0 +1,93 @@
1
+ import { type StoredStorage } from "./storage";
2
+ /** What a saved value that fails `validate` does: stay in storage, or go. */
3
+ export type StoredInvalid = "keep" | "remove";
4
+ /** When a change is written: at once, or once changes stop for `delay` ms. */
5
+ export type StoredWrites = "immediate" | "debounced";
6
+ /** How a value is written to storage: as JSON, or as the plain text it is. */
7
+ export type StoredFormat = "json" | "text";
8
+ export interface StoredOptions<T> {
9
+ /** The storage key. A scope is added after it, like `rows.folded:board-2`. */
10
+ key: string;
11
+ /** The value used when nothing valid is saved, and on the server. */
12
+ fallback: T;
13
+ /**
14
+ * How the value is written. "text" keeps a string as it is, with no JSON
15
+ * quotes, for values an app already saved as bare text. Only string values
16
+ * can use it.
17
+ * @defaultValue "json"
18
+ */
19
+ format?: StoredFormat;
20
+ /** Whether a parsed saved value is allowed. Anything else counts as invalid. */
21
+ validate: (value: unknown) => value is T;
22
+ /**
23
+ * Where it lives.
24
+ * @defaultValue "local"
25
+ */
26
+ storage?: StoredStorage;
27
+ /**
28
+ * Whether changes made in other windows show up live. False keeps the
29
+ * value read at first use until the page reloads.
30
+ * @defaultValue true
31
+ */
32
+ follow?: boolean;
33
+ /**
34
+ * A saved value that fails validation always shows the fallback. "keep"
35
+ * leaves the bad text in storage, "remove" deletes it.
36
+ * @defaultValue "keep"
37
+ */
38
+ invalid?: StoredInvalid;
39
+ /**
40
+ * "debounced" writes after `delay` ms without a change, and also when
41
+ * the page is hidden.
42
+ * @defaultValue "immediate"
43
+ */
44
+ writes?: StoredWrites;
45
+ /**
46
+ * The quiet time for debounced writes, in milliseconds.
47
+ * @defaultValue 300
48
+ */
49
+ delay?: number;
50
+ }
51
+ export interface StoredStatus {
52
+ /** Whether the storage appears to accept writes. */
53
+ available: boolean;
54
+ /** Whether the last write or removal failed (blocked or full). */
55
+ writeFailed: boolean;
56
+ /** Whether the saved text was invalid the last time it was read. */
57
+ invalid: boolean;
58
+ /** Whether a debounced write is still waiting. */
59
+ pending: boolean;
60
+ }
61
+ export type StoredUpdate<T> = T | ((current: T) => T);
62
+ export interface Stored<T> {
63
+ key: string;
64
+ /** The current value. The same reference until it changes. */
65
+ get: () => T;
66
+ set: (next: StoredUpdate<T>) => void;
67
+ /** Goes back to the fallback and removes the saved text. */
68
+ reset: () => void;
69
+ /** Hears any change to the value or the status. Returns the stop function. */
70
+ subscribe: (listener: () => void) => () => void;
71
+ /** The status. The same object until it changes. */
72
+ status: () => StoredStatus;
73
+ /** Writes a waiting debounced change now. */
74
+ flush: () => void;
75
+ }
76
+ export interface StoredDefinition<T> {
77
+ options: StoredOptions<T>;
78
+ /** The stored value for a scope, such as a board id. The same one each time. */
79
+ open: (scope?: string) => Stored<T>;
80
+ /** Flushes every waiting write of this definition. */
81
+ flush: () => void;
82
+ }
83
+ export declare const serverStatus: StoredStatus;
84
+ /**
85
+ * Describes one saved value. Open it for a scope (or none) to read and
86
+ * change it, or give it to `useStored`.
87
+ */
88
+ export declare function defineStored<T extends string>(options: StoredOptions<T> & {
89
+ format: "text";
90
+ }): StoredDefinition<T>;
91
+ export declare function defineStored<T>(options: StoredOptions<T> & {
92
+ format?: "json";
93
+ }): StoredDefinition<T>;
@@ -0,0 +1,209 @@
1
+ import { backendFor } from "./storage";
2
+ export const serverStatus = {
3
+ available: true,
4
+ writeFailed: false,
5
+ invalid: false,
6
+ pending: false
7
+ };
8
+ const waiting = new Set();
9
+ let hooked = false;
10
+ const runWaiting = () => {
11
+ for (const flush of waiting) {
12
+ flush();
13
+ }
14
+ };
15
+ /* Waiting writes must not be lost when the tab is closed or hidden. */
16
+ function hookPageHide() {
17
+ if (hooked || typeof window === "undefined") {
18
+ return;
19
+ }
20
+ hooked = true;
21
+ window.addEventListener("pagehide", runWaiting);
22
+ document.addEventListener("visibilitychange", () => {
23
+ if (document.visibilityState === "hidden") {
24
+ runWaiting();
25
+ }
26
+ });
27
+ }
28
+ function isUpdater(next) {
29
+ return typeof next === "function";
30
+ }
31
+ function parse(text, validate, format) {
32
+ try {
33
+ const parsed = format === "text" ? text : JSON.parse(text);
34
+ return validate(parsed) ? parsed : undefined;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ }
40
+ class StoredCell {
41
+ key;
42
+ options;
43
+ listeners = new Set();
44
+ backend;
45
+ stopFollowing;
46
+ loaded = false;
47
+ value;
48
+ /* The text storage held when we last looked or wrote. */
49
+ raw = null;
50
+ current = serverStatus;
51
+ timer;
52
+ constructor(options, key) {
53
+ this.options = options;
54
+ this.key = key;
55
+ this.value = options.fallback;
56
+ }
57
+ notify() {
58
+ for (const listener of this.listeners) {
59
+ listener();
60
+ }
61
+ }
62
+ patch(change) {
63
+ this.current = { ...this.current, ...change };
64
+ }
65
+ availableNow() {
66
+ return this.backend?.available?.() ?? true;
67
+ }
68
+ load() {
69
+ this.loaded = true;
70
+ const storage = this.options.storage ?? "local";
71
+ /* The browser's own storages do not exist on the server. An app's own backend works anywhere. */
72
+ if (typeof storage === "string" && typeof window === "undefined") {
73
+ return;
74
+ }
75
+ this.backend = backendFor(storage, this.key);
76
+ this.patch({ available: this.availableNow() });
77
+ this.apply(this.backend.get());
78
+ }
79
+ /* Turns saved text into the value, handling an invalid one per the option. */
80
+ apply(text) {
81
+ this.raw = text;
82
+ const parsed = text === null ? undefined : parse(text, this.options.validate, this.options.format);
83
+ if (text === null || parsed !== undefined) {
84
+ this.value = parsed ?? this.options.fallback;
85
+ this.patch({ invalid: false });
86
+ return;
87
+ }
88
+ this.value = this.options.fallback;
89
+ this.patch({ invalid: true });
90
+ if (this.options.invalid === "remove" && this.backend) {
91
+ const removed = this.backend.remove();
92
+ this.patch({ writeFailed: !removed });
93
+ this.raw = removed ? null : text;
94
+ }
95
+ }
96
+ persist() {
97
+ waiting.delete(this.flush);
98
+ this.timer = undefined;
99
+ if (!this.backend) {
100
+ return;
101
+ }
102
+ const text = this.options.format === "text" ? String(this.value) : JSON.stringify(this.value);
103
+ /* Set first: the backend may announce the write before it returns. */
104
+ this.raw = text;
105
+ const written = this.backend.set(text);
106
+ this.patch({ writeFailed: !written, available: this.availableNow(), pending: false });
107
+ this.notify();
108
+ }
109
+ heard = (text) => {
110
+ /* Our own writes echo back; a waiting local change wins over a remote one. */
111
+ if (text === this.raw || this.timer !== undefined) {
112
+ return;
113
+ }
114
+ this.apply(text);
115
+ this.notify();
116
+ };
117
+ get = () => {
118
+ if (!this.loaded) {
119
+ this.load();
120
+ }
121
+ return this.value;
122
+ };
123
+ status = () => {
124
+ this.get();
125
+ return this.current;
126
+ };
127
+ set = (next) => {
128
+ const current = this.get();
129
+ const resolved = isUpdater(next) ? next(current) : next;
130
+ if (Object.is(resolved, this.value)) {
131
+ return;
132
+ }
133
+ this.value = resolved;
134
+ if (this.options.writes !== "debounced") {
135
+ this.persist();
136
+ return;
137
+ }
138
+ clearTimeout(this.timer);
139
+ this.timer = setTimeout(() => this.persist(), this.options.delay ?? 300);
140
+ waiting.add(this.flush);
141
+ hookPageHide();
142
+ this.patch({ pending: true });
143
+ this.notify();
144
+ };
145
+ reset = () => {
146
+ this.get();
147
+ clearTimeout(this.timer);
148
+ this.timer = undefined;
149
+ waiting.delete(this.flush);
150
+ this.value = this.options.fallback;
151
+ const removed = this.backend?.remove() ?? true;
152
+ if (removed) {
153
+ this.raw = null;
154
+ }
155
+ this.patch({
156
+ writeFailed: !removed,
157
+ available: this.availableNow(),
158
+ pending: false,
159
+ invalid: false
160
+ });
161
+ this.notify();
162
+ };
163
+ flush = () => {
164
+ if (this.timer !== undefined) {
165
+ clearTimeout(this.timer);
166
+ this.persist();
167
+ }
168
+ };
169
+ subscribe = (listener) => {
170
+ this.get();
171
+ this.listeners.add(listener);
172
+ if ((this.options.follow ?? true) && this.backend && this.listeners.size === 1) {
173
+ /* Catch up on anything missed while nobody was listening. */
174
+ const latest = this.backend.get();
175
+ if (latest !== this.raw && this.timer === undefined) {
176
+ this.apply(latest);
177
+ }
178
+ this.stopFollowing = this.backend.subscribe(this.heard);
179
+ }
180
+ return () => {
181
+ this.listeners.delete(listener);
182
+ if (this.listeners.size === 0) {
183
+ this.stopFollowing?.();
184
+ this.stopFollowing = undefined;
185
+ }
186
+ };
187
+ };
188
+ }
189
+ export function defineStored(options) {
190
+ const opened = new Map();
191
+ return {
192
+ options,
193
+ open: (scope) => {
194
+ const key = scope === undefined ? options.key : `${options.key}:${scope}`;
195
+ const existing = opened.get(key);
196
+ if (existing) {
197
+ return existing;
198
+ }
199
+ const created = new StoredCell(options, key);
200
+ opened.set(key, created);
201
+ return created;
202
+ },
203
+ flush: () => {
204
+ for (const stored of opened.values()) {
205
+ stored.flush();
206
+ }
207
+ }
208
+ };
209
+ }
@@ -0,0 +1,6 @@
1
+ import { type StoredDefinition, type StoredStatus, type StoredUpdate } from "./stored";
2
+ /**
3
+ * Reads and changes a stored value: `[value, set, status, reset]`. The server
4
+ * and the first hydration render use the fallback, then the saved value shows.
5
+ */
6
+ export declare function useStored<T>(definition: StoredDefinition<T>, scope?: string): [T, (next: StoredUpdate<T>) => void, StoredStatus, () => void];
@@ -0,0 +1,12 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { serverStatus } from "./stored";
3
+ /**
4
+ * Reads and changes a stored value: `[value, set, status, reset]`. The server
5
+ * and the first hydration render use the fallback, then the saved value shows.
6
+ */
7
+ export function useStored(definition, scope) {
8
+ const stored = definition.open(scope);
9
+ const value = useSyncExternalStore(stored.subscribe, stored.get, () => definition.options.fallback);
10
+ const status = useSyncExternalStore(stored.subscribe, stored.status, () => serverStatus);
11
+ return [value, stored.set, status, stored.reset];
12
+ }
@@ -0,0 +1,6 @@
1
+ /** A value from a fixed list, like a density or a view mode. */
2
+ export declare function oneOf<T extends string | number>(choices: readonly T[]): (value: unknown) => value is T;
3
+ /** A finite number inside a range, ends included. */
4
+ export declare function numberBetween(min: number, max: number): (value: unknown) => value is number;
5
+ /** A list of strings, like the ids of folded rows. */
6
+ export declare function isStringList(value: unknown): value is string[];
@@ -0,0 +1,13 @@
1
+ /* Ready-made `validate` functions for the usual shapes of saved values. */
2
+ /** A value from a fixed list, like a density or a view mode. */
3
+ export function oneOf(choices) {
4
+ return (value) => choices.some((choice) => choice === value);
5
+ }
6
+ /** A finite number inside a range, ends included. */
7
+ export function numberBetween(min, max) {
8
+ return (value) => typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
9
+ }
10
+ /** A list of strings, like the ids of folded rows. */
11
+ export function isStringList(value) {
12
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string");
13
+ }
@@ -0,0 +1,62 @@
1
+ /** A step an app remembered, as the app describes it. */
2
+ export interface NewUndoEntry {
3
+ /** What the step did, in words a person reads: "Move card", "Delete card". */
4
+ label: string;
5
+ /** Takes the step back. May be async. A throw keeps the step in the history and reports an error. */
6
+ undo: () => unknown;
7
+ /** Does the step again. May be async. */
8
+ redo: () => unknown;
9
+ /** Where the step happened (a board, a document). Apps decide what a place is. */
10
+ place?: string;
11
+ /** Steps with the same key, close together in time, join one step. */
12
+ mergeKey?: string;
13
+ /** Names the thing the step changed, so focus or a flash can find it afterwards. */
14
+ target?: string;
15
+ /**
16
+ * Steps that share this key only work in order: one can't be undone while a newer one with the
17
+ * same key is still done (a typed value, an editor with its own stack). Newest first.
18
+ */
19
+ orderKey?: string;
20
+ }
21
+ /** A remembered step, as the history keeps it. */
22
+ export interface UndoEntry extends NewUndoEntry {
23
+ /** Stays the same when later steps merge into this one. */
24
+ id: string;
25
+ /** When the latest merged step was remembered, in milliseconds. */
26
+ at: number;
27
+ }
28
+ export interface History {
29
+ past: readonly UndoEntry[];
30
+ future: readonly UndoEntry[];
31
+ sealed: boolean;
32
+ }
33
+ export interface RememberOptions {
34
+ limit: number;
35
+ windowMs: number;
36
+ now: number;
37
+ id: string;
38
+ ownFuture: boolean;
39
+ }
40
+ export declare const DEFAULT_LIMIT = 100;
41
+ export declare const DEFAULT_MERGE_WINDOW = 1200;
42
+ export declare const EMPTY_HISTORY: History;
43
+ export declare const NEWER_FIRST = "Newer steps depend on this one. Undo them first.";
44
+ export declare const OLDER_FIRST = "Older steps come first. Redo them first.";
45
+ export declare function reversed<Item>(items: readonly Item[]): Item[];
46
+ export declare function inPlace(entries: readonly UndoEntry[], place: string | undefined): UndoEntry[];
47
+ export declare function remember(history: History, entry: NewUndoEntry, options: RememberOptions): {
48
+ history: History;
49
+ entry: UndoEntry;
50
+ };
51
+ export declare function seal(history: History): History;
52
+ export declare function nextUndo(history: History, place?: string): UndoEntry | null;
53
+ export declare function nextRedo(history: History, place?: string): UndoEntry | null;
54
+ export declare function markUndone(history: History, id: string): History;
55
+ export declare function markRedone(history: History, id: string): History;
56
+ export declare function forget(history: History, id: string): History;
57
+ export declare function reinstate(history: History, entry: UndoEntry): History;
58
+ export declare function isOnTop(history: History, id: string, place?: string): boolean;
59
+ export declare function blockedUndo(history: History, id: string): string | null;
60
+ export declare function blockedRedo(history: History, id: string): string | null;
61
+ export declare function stepsBack(history: History, id: string | null, include: boolean, place?: string): UndoEntry[];
62
+ export declare function stepsForward(history: History, id: string, place?: string): UndoEntry[];