@alulore/kumiko 0.15.1 → 0.17.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/media-viewer/icons.d.ts +4 -0
- package/dist/media-viewer/icons.js +18 -0
- package/dist/media-viewer/index.d.ts +4 -0
- package/dist/media-viewer/index.js +3 -0
- package/dist/media-viewer/media-slide.d.ts +14 -0
- package/dist/media-viewer/media-slide.js +67 -0
- package/dist/media-viewer/media-viewer.css +611 -0
- package/dist/media-viewer/media-viewer.d.ts +17 -0
- package/dist/media-viewer/media-viewer.js +241 -0
- package/dist/media-viewer/pager-drag.d.ts +10 -0
- package/dist/media-viewer/pager-drag.js +53 -0
- package/dist/media-viewer/types.d.ts +58 -0
- package/dist/media-viewer/types.js +17 -0
- package/dist/media-viewer/video-controls.d.ts +3 -0
- package/dist/media-viewer/video-controls.js +62 -0
- package/dist/media-viewer/view-gesture.d.ts +74 -0
- package/dist/media-viewer/view-gesture.js +465 -0
- package/dist/media-viewer/viewer-chrome.d.ts +13 -0
- package/dist/media-viewer/viewer-chrome.js +35 -0
- package/dist/media-viewer/viewer-motion.d.ts +9 -0
- package/dist/media-viewer/viewer-motion.js +126 -0
- package/dist/media-viewer/zoom-pan.d.ts +35 -0
- package/dist/media-viewer/zoom-pan.js +102 -0
- package/dist/shortcuts/bindings.d.ts +44 -0
- package/dist/shortcuts/bindings.js +71 -0
- package/dist/shortcuts/capture.d.ts +7 -0
- package/dist/shortcuts/capture.js +92 -0
- package/dist/shortcuts/guard.d.ts +9 -0
- package/dist/shortcuts/guard.js +48 -0
- package/dist/shortcuts/help.d.ts +25 -0
- package/dist/shortcuts/help.js +26 -0
- package/dist/shortcuts/hints.d.ts +19 -0
- package/dist/shortcuts/hints.js +33 -0
- package/dist/shortcuts/index.d.ts +11 -0
- package/dist/shortcuts/index.js +11 -0
- package/dist/shortcuts/judge.d.ts +42 -0
- package/dist/shortcuts/judge.js +34 -0
- package/dist/shortcuts/keys.d.ts +11 -0
- package/dist/shortcuts/keys.js +89 -0
- package/dist/shortcuts/list.d.ts +16 -0
- package/dist/shortcuts/list.js +43 -0
- package/dist/shortcuts/notes.d.ts +28 -0
- package/dist/shortcuts/notes.js +27 -0
- package/dist/shortcuts/provider.d.ts +98 -0
- package/dist/shortcuts/provider.js +116 -0
- package/dist/shortcuts/rebinder.d.ts +23 -0
- package/dist/shortcuts/rebinder.js +84 -0
- package/dist/shortcuts/registration.d.ts +19 -0
- package/dist/shortcuts/registration.js +84 -0
- package/dist/shortcuts/shortcuts.css +171 -0
- package/dist/stored/index.d.ts +4 -0
- package/dist/stored/index.js +4 -0
- package/dist/stored/storage.d.ts +22 -0
- package/dist/stored/storage.js +10 -0
- package/dist/stored/stored.d.ts +93 -0
- package/dist/stored/stored.js +209 -0
- package/dist/stored/use-stored.d.ts +6 -0
- package/dist/stored/use-stored.js +12 -0
- package/dist/stored/validators.d.ts +6 -0
- package/dist/stored/validators.js +13 -0
- package/dist/titlebar/index.d.ts +2 -0
- package/dist/titlebar/index.js +2 -0
- package/dist/titlebar/titlebar-looks.d.ts +53 -0
- package/dist/titlebar/titlebar-looks.js +26 -0
- package/dist/titlebar/titlebar.css +561 -0
- package/dist/titlebar/titlebar.d.ts +54 -0
- package/dist/titlebar/titlebar.js +68 -0
- package/dist/undo/history.d.ts +62 -0
- package/dist/undo/history.js +151 -0
- package/dist/undo/index.d.ts +10 -0
- package/dist/undo/index.js +10 -0
- package/dist/undo/undo-adapter.d.ts +35 -0
- package/dist/undo/undo-adapter.js +35 -0
- package/dist/undo/undo-feedback.d.ts +28 -0
- package/dist/undo/undo-feedback.js +69 -0
- package/dist/undo/undo-keys.d.ts +32 -0
- package/dist/undo/undo-keys.js +76 -0
- package/dist/undo/undo-options.d.ts +51 -0
- package/dist/undo/undo-options.js +6 -0
- package/dist/undo/undo-panel.d.ts +23 -0
- package/dist/undo/undo-panel.js +56 -0
- package/dist/undo/undo-provider.d.ts +88 -0
- package/dist/undo/undo-provider.js +104 -0
- package/dist/undo/undo-reveal.d.ts +9 -0
- package/dist/undo/undo-reveal.js +45 -0
- package/dist/undo/undo-store.d.ts +89 -0
- package/dist/undo/undo-store.js +243 -0
- package/dist/undo/undo.css +135 -0
- package/dist/undo/use-undo-value.d.ts +43 -0
- package/dist/undo/use-undo-value.js +85 -0
- package/package.json +42 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
@import "../motion/motion.css";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Styles the history panel and the flash that shows what an undo changed. The flash is a colour
|
|
5
|
+
* fade, so it uses the fade tokens and stays under reduced motion.
|
|
6
|
+
*/
|
|
7
|
+
@layer kumiko {
|
|
8
|
+
:where(:root) {
|
|
9
|
+
--kumiko-undo-flash-color: Highlight;
|
|
10
|
+
--kumiko-undo-flash-width: 3px;
|
|
11
|
+
--kumiko-undo-flash-length: 5;
|
|
12
|
+
--kumiko-undo-panel-gap: 0.25rem;
|
|
13
|
+
--kumiko-undo-step-radius: 0.5rem;
|
|
14
|
+
--kumiko-undo-undone-opacity: 0.55;
|
|
15
|
+
--kumiko-undo-latest-color: Highlight;
|
|
16
|
+
--kumiko-undo-spinner-size: 1rem;
|
|
17
|
+
--kumiko-undo-spinner-width: 2px;
|
|
18
|
+
--kumiko-undo-spinner-color: currentColor;
|
|
19
|
+
--kumiko-undo-spinner-delay: 300ms;
|
|
20
|
+
--kumiko-undo-locked-opacity: 0.5;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* A step is running: the controls ignore taps but keep focus, so they look off, not gone. The
|
|
25
|
+
* spinner fades in after the delay, so a quick step never shows one.
|
|
26
|
+
*/
|
|
27
|
+
[data-kumiko-undo] button[aria-disabled="true"] {
|
|
28
|
+
cursor: not-allowed;
|
|
29
|
+
opacity: var(--kumiko-undo-locked-opacity);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[data-kumiko-undo="spinner"] {
|
|
33
|
+
display: inline-block;
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
inline-size: var(--kumiko-undo-spinner-size);
|
|
36
|
+
block-size: var(--kumiko-undo-spinner-size);
|
|
37
|
+
border: var(--kumiko-undo-spinner-width) solid var(--kumiko-undo-spinner-color);
|
|
38
|
+
border-block-start-color: transparent;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
opacity: 1;
|
|
41
|
+
transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease)
|
|
42
|
+
var(--kumiko-undo-spinner-delay);
|
|
43
|
+
animation: kumiko-undo-spin var(--kumiko-spin-duration) var(--kumiko-spin-ease) infinite;
|
|
44
|
+
|
|
45
|
+
@starting-style {
|
|
46
|
+
opacity: 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@keyframes kumiko-undo-spin {
|
|
51
|
+
to {
|
|
52
|
+
rotate: 1turn;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[data-kumiko-undo-flash] {
|
|
57
|
+
animation: kumiko-undo-flash
|
|
58
|
+
calc(var(--kumiko-fade-duration) * var(--kumiko-undo-flash-length))
|
|
59
|
+
var(--kumiko-fade-ease);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes kumiko-undo-flash {
|
|
63
|
+
from {
|
|
64
|
+
outline: var(--kumiko-undo-flash-width) solid var(--kumiko-undo-flash-color);
|
|
65
|
+
outline-offset: 2px;
|
|
66
|
+
background-color: color-mix(in oklab, var(--kumiko-undo-flash-color) 30%, transparent);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
to {
|
|
70
|
+
outline: var(--kumiko-undo-flash-width) solid transparent;
|
|
71
|
+
outline-offset: 2px;
|
|
72
|
+
background-color: transparent;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
[data-kumiko-undo="panel"] h3 {
|
|
77
|
+
margin: 0 0 0.5rem;
|
|
78
|
+
font-size: 0.9rem;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[data-kumiko-undo="panel"] ol {
|
|
82
|
+
display: grid;
|
|
83
|
+
gap: var(--kumiko-undo-panel-gap);
|
|
84
|
+
margin: 0;
|
|
85
|
+
padding: 0;
|
|
86
|
+
list-style: none;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[data-kumiko-undo="panel"] li {
|
|
90
|
+
display: flex;
|
|
91
|
+
gap: 0.5rem;
|
|
92
|
+
align-items: center;
|
|
93
|
+
justify-content: space-between;
|
|
94
|
+
min-block-size: 2rem;
|
|
95
|
+
border-radius: var(--kumiko-undo-step-radius);
|
|
96
|
+
transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
[data-kumiko-undo="panel"] li[data-kumiko-undo-step="undone"] {
|
|
100
|
+
opacity: var(--kumiko-undo-undone-opacity);
|
|
101
|
+
font-style: italic;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
[data-kumiko-undo="panel"] li[data-kumiko-undo-step="latest"] {
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
box-shadow: inset 3px 0 0 var(--kumiko-undo-latest-color);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
[data-kumiko-undo="panel"] li > button:only-child {
|
|
110
|
+
flex: 1;
|
|
111
|
+
text-align: start;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
[data-kumiko-undo="panel"] button {
|
|
115
|
+
cursor: var(--kumiko-press-cursor, pointer);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[data-kumiko-undo="buttons"] {
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
gap: 0.5rem;
|
|
121
|
+
align-items: center;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@media (pointer: coarse) {
|
|
125
|
+
[data-kumiko-undo] button {
|
|
126
|
+
min-block-size: var(--kumiko-touch-target, 2.75rem);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@media (forced-colors: active) {
|
|
131
|
+
[data-kumiko-undo-flash] {
|
|
132
|
+
outline-color: Highlight;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { NewUndoEntry } from "./history";
|
|
2
|
+
export interface UndoHistory {
|
|
3
|
+
remember: (entry: NewUndoEntry) => unknown;
|
|
4
|
+
undo: () => unknown;
|
|
5
|
+
redo: () => unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface UndoValueOptions {
|
|
8
|
+
/**
|
|
9
|
+
* When given (pass `useUndo()`), the value joins that history: each run of edits is one entry
|
|
10
|
+
* in it, and the page's undo reaches it. Such entries only work in order, so a newer one is
|
|
11
|
+
* undone first.
|
|
12
|
+
* @defaultValue undefined, so the value keeps only its own undo
|
|
13
|
+
*/
|
|
14
|
+
history?: UndoHistory;
|
|
15
|
+
/**
|
|
16
|
+
* The entry's label.
|
|
17
|
+
* @defaultValue "Typing"
|
|
18
|
+
*/
|
|
19
|
+
label?: string;
|
|
20
|
+
place?: string;
|
|
21
|
+
target?: string;
|
|
22
|
+
/**
|
|
23
|
+
* How long a pause closes one step, in milliseconds. Infinity closes only on blur or `seal`.
|
|
24
|
+
* @defaultValue 1200
|
|
25
|
+
*/
|
|
26
|
+
pause?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface UndoValue<Value> {
|
|
29
|
+
value: Value;
|
|
30
|
+
set: (value: Value) => void;
|
|
31
|
+
undo: () => void;
|
|
32
|
+
redo: () => void;
|
|
33
|
+
canUndo: boolean;
|
|
34
|
+
canRedo: boolean;
|
|
35
|
+
seal: () => void;
|
|
36
|
+
onKeyDown: (event: React.KeyboardEvent) => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One value with its own undo, on ui-sdk's `createUndoStack`. With a `store`, every run of edits
|
|
40
|
+
* also becomes one entry in the page's history, so the page's undo reaches it. Steps in the
|
|
41
|
+
* stack and entries in the history stay in step as long as they are undone in order.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useUndoValue<Value>(initial: Value, options?: UndoValueOptions): UndoValue<Value>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createUndoStack } from "@ui-sdk/core";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { undoFieldKeys } from "./undo-keys";
|
|
4
|
+
/* The stack never splits steps on its own clock: this hook closes them. */
|
|
5
|
+
const NEVER = Number.MAX_SAFE_INTEGER;
|
|
6
|
+
const DEFAULT_PAUSE = 1200;
|
|
7
|
+
/* The open step: whether one is running, and the timer that closes it after a pause. */
|
|
8
|
+
function useOpenStep(close) {
|
|
9
|
+
const open = useRef(false);
|
|
10
|
+
const timer = useRef(undefined);
|
|
11
|
+
const closeRef = useRef(close);
|
|
12
|
+
closeRef.current = close;
|
|
13
|
+
const stop = () => {
|
|
14
|
+
clearTimeout(timer.current);
|
|
15
|
+
open.current = false;
|
|
16
|
+
};
|
|
17
|
+
const restart = (pause) => {
|
|
18
|
+
clearTimeout(timer.current);
|
|
19
|
+
if (Number.isFinite(pause)) {
|
|
20
|
+
timer.current = setTimeout(() => closeRef.current(), pause);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
24
|
+
return { open, restart, stop };
|
|
25
|
+
}
|
|
26
|
+
/* Adds the entry for a run of edits to the history, when the value has one. */
|
|
27
|
+
function rememberStep(options, orderKey, move) {
|
|
28
|
+
options.history?.remember({
|
|
29
|
+
orderKey,
|
|
30
|
+
label: options.label ?? "Typing",
|
|
31
|
+
place: options.place,
|
|
32
|
+
target: options.target,
|
|
33
|
+
undo: () => move("undo"),
|
|
34
|
+
redo: () => move("redo")
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One value with its own undo, on ui-sdk's `createUndoStack`. With a `store`, every run of edits
|
|
39
|
+
* also becomes one entry in the page's history, so the page's undo reaches it. Steps in the
|
|
40
|
+
* stack and entries in the history stay in step as long as they are undone in order.
|
|
41
|
+
*/
|
|
42
|
+
export function useUndoValue(initial, options = {}) {
|
|
43
|
+
const [value, setValue] = useState(initial);
|
|
44
|
+
const [, refresh] = useState(0);
|
|
45
|
+
const stack = useRef(createUndoStack(initial, { groupDelay: NEVER }));
|
|
46
|
+
const orderKey = `value-${useId()}`;
|
|
47
|
+
const latest = useRef(options);
|
|
48
|
+
latest.current = options;
|
|
49
|
+
const step = useOpenStep(() => seal());
|
|
50
|
+
function seal() {
|
|
51
|
+
stack.current.seal();
|
|
52
|
+
step.stop();
|
|
53
|
+
}
|
|
54
|
+
function move(direction) {
|
|
55
|
+
seal();
|
|
56
|
+
const next = direction === "undo" ? stack.current.undo() : stack.current.redo();
|
|
57
|
+
if (next !== undefined) {
|
|
58
|
+
setValue(next);
|
|
59
|
+
}
|
|
60
|
+
refresh((count) => count + 1);
|
|
61
|
+
}
|
|
62
|
+
function set(next) {
|
|
63
|
+
setValue(next);
|
|
64
|
+
stack.current.record(next, { group: "typing" });
|
|
65
|
+
if (!step.open.current) {
|
|
66
|
+
step.open.current = true;
|
|
67
|
+
rememberStep(latest.current, orderKey, move);
|
|
68
|
+
}
|
|
69
|
+
step.restart(latest.current.pause ?? DEFAULT_PAUSE);
|
|
70
|
+
refresh((count) => count + 1);
|
|
71
|
+
}
|
|
72
|
+
const history = options.history;
|
|
73
|
+
const undo = () => (history ? void history.undo() : move("undo"));
|
|
74
|
+
const redo = () => (history ? void history.redo() : move("redo"));
|
|
75
|
+
return {
|
|
76
|
+
value,
|
|
77
|
+
set,
|
|
78
|
+
undo,
|
|
79
|
+
redo,
|
|
80
|
+
canUndo: stack.current.canUndo(),
|
|
81
|
+
canRedo: stack.current.canRedo(),
|
|
82
|
+
seal,
|
|
83
|
+
onKeyDown: (event) => undoFieldKeys(event, undo, redo)
|
|
84
|
+
};
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alulore/kumiko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Polished, cozy React components with gentle motion, built on ui-sdk. Every look and behaviour can be switched with props and CSS tokens.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -70,6 +70,15 @@
|
|
|
70
70
|
"source": "./src/label/label.css",
|
|
71
71
|
"default": "./dist/label/label.css"
|
|
72
72
|
},
|
|
73
|
+
"./media-viewer": {
|
|
74
|
+
"source": "./src/media-viewer/index.ts",
|
|
75
|
+
"types": "./dist/media-viewer/index.d.ts",
|
|
76
|
+
"default": "./dist/media-viewer/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./media-viewer.css": {
|
|
79
|
+
"source": "./src/media-viewer/media-viewer.css",
|
|
80
|
+
"default": "./dist/media-viewer/media-viewer.css"
|
|
81
|
+
},
|
|
73
82
|
"./menu": {
|
|
74
83
|
"source": "./src/menu/index.ts",
|
|
75
84
|
"types": "./dist/menu/index.d.ts",
|
|
@@ -106,6 +115,15 @@
|
|
|
106
115
|
"source": "./src/progress/progress.css",
|
|
107
116
|
"default": "./dist/progress/progress.css"
|
|
108
117
|
},
|
|
118
|
+
"./titlebar": {
|
|
119
|
+
"source": "./src/titlebar/index.ts",
|
|
120
|
+
"types": "./dist/titlebar/index.d.ts",
|
|
121
|
+
"default": "./dist/titlebar/index.js"
|
|
122
|
+
},
|
|
123
|
+
"./titlebar.css": {
|
|
124
|
+
"source": "./src/titlebar/titlebar.css",
|
|
125
|
+
"default": "./dist/titlebar/titlebar.css"
|
|
126
|
+
},
|
|
109
127
|
"./select": {
|
|
110
128
|
"source": "./src/select/index.ts",
|
|
111
129
|
"types": "./dist/select/index.d.ts",
|
|
@@ -133,6 +151,11 @@
|
|
|
133
151
|
"source": "./src/slider/slider.css",
|
|
134
152
|
"default": "./dist/slider/slider.css"
|
|
135
153
|
},
|
|
154
|
+
"./stored": {
|
|
155
|
+
"source": "./src/stored/index.ts",
|
|
156
|
+
"types": "./dist/stored/index.d.ts",
|
|
157
|
+
"default": "./dist/stored/index.js"
|
|
158
|
+
},
|
|
136
159
|
"./switch": {
|
|
137
160
|
"source": "./src/switch/index.ts",
|
|
138
161
|
"types": "./dist/switch/index.d.ts",
|
|
@@ -151,6 +174,15 @@
|
|
|
151
174
|
"source": "./src/toast/toast.css",
|
|
152
175
|
"default": "./dist/toast/toast.css"
|
|
153
176
|
},
|
|
177
|
+
"./shortcuts": {
|
|
178
|
+
"source": "./src/shortcuts/index.ts",
|
|
179
|
+
"types": "./dist/shortcuts/index.d.ts",
|
|
180
|
+
"default": "./dist/shortcuts/index.js"
|
|
181
|
+
},
|
|
182
|
+
"./shortcuts.css": {
|
|
183
|
+
"source": "./src/shortcuts/shortcuts.css",
|
|
184
|
+
"default": "./dist/shortcuts/shortcuts.css"
|
|
185
|
+
},
|
|
154
186
|
"./tooltip": {
|
|
155
187
|
"source": "./src/tooltip/index.ts",
|
|
156
188
|
"types": "./dist/tooltip/index.d.ts",
|
|
@@ -160,6 +192,15 @@
|
|
|
160
192
|
"source": "./src/tooltip/tooltip.css",
|
|
161
193
|
"default": "./dist/tooltip/tooltip.css"
|
|
162
194
|
},
|
|
195
|
+
"./undo": {
|
|
196
|
+
"source": "./src/undo/index.ts",
|
|
197
|
+
"types": "./dist/undo/index.d.ts",
|
|
198
|
+
"default": "./dist/undo/index.js"
|
|
199
|
+
},
|
|
200
|
+
"./undo.css": {
|
|
201
|
+
"source": "./src/undo/undo.css",
|
|
202
|
+
"default": "./dist/undo/undo.css"
|
|
203
|
+
},
|
|
163
204
|
"./badge": {
|
|
164
205
|
"source": "./src/badge/index.ts",
|
|
165
206
|
"types": "./dist/badge/index.d.ts",
|