@pathscale/ui 2.11.0 → 2.11.2
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/components/_shared/overlayPosition.js +1 -1
- package/dist/components/inline-edit/InlineEdit.generated.js +22 -58
- package/dist/components/inline-edit/InlineEdit.interactions.d.ts +26 -0
- package/dist/components/inline-edit/InlineEdit.interactions.js +60 -0
- package/dist/layouts.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -97,7 +97,7 @@ const createOverlayPosition = (options)=>{
|
|
|
97
97
|
cancelAnimationFrame(frame);
|
|
98
98
|
frame = requestAnimationFrame(update);
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
update();
|
|
101
101
|
window.addEventListener("resize", schedule);
|
|
102
102
|
window.addEventListener("scroll", schedule, true);
|
|
103
103
|
const resizeObserver = "u" > typeof ResizeObserver ? new ResizeObserver(schedule) : void 0;
|
|
@@ -1,81 +1,45 @@
|
|
|
1
|
-
import { className, delegateEvents, effect, insert, mergeProps, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
1
|
+
import { addEvent, className, delegateEvents, effect, insert, mergeProps, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
2
2
|
import { defineComponent } from "solid-layouts/solid-2/application-boundary";
|
|
3
3
|
import "./InlineEdit.css";
|
|
4
4
|
import { omit } from "solid-js";
|
|
5
5
|
import { twMerge } from "../../lib/twMerge.js";
|
|
6
|
+
import { createInlineEditInteractions } from "./InlineEdit.interactions.js";
|
|
6
7
|
import { CLASSES, componentRecipe } from "./InlineEdit.recipe.js";
|
|
7
8
|
var _tmpl$ = /*#__PURE__*/ template("<span><span data-slot=inline-edit-read><span data-slot=inline-edit-value></span><button type=button data-slot=inline-edit-trigger></button></span><span data-slot=inline-edit-edit><input type=text data-slot=inline-edit-field>");
|
|
8
9
|
const __solidLayoutInlineEdit = (_stable, p)=>{
|
|
9
|
-
const others = omit(p, "class", "value", "onCommit", "label", "trigger", "children", "fullWidth", "disabled", "fieldClass");
|
|
10
|
-
let
|
|
11
|
-
let editRow;
|
|
10
|
+
const others = omit(p, "class", "value", "onCommit", "label", "trigger", "children", "fullWidth", "disabled", "fieldClass", "ref");
|
|
11
|
+
let root;
|
|
12
12
|
let field;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
const
|
|
22
|
-
if (p.disabled) return;
|
|
23
|
-
draft = p.value;
|
|
24
|
-
if (field) field.value = draft;
|
|
25
|
-
apply(true);
|
|
26
|
-
queueMicrotask(()=>{
|
|
27
|
-
field?.focus();
|
|
28
|
-
field?.select();
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
const cancel = ()=>{
|
|
32
|
-
draft = p.value;
|
|
33
|
-
if (field) field.value = draft;
|
|
34
|
-
focused = false;
|
|
35
|
-
apply(false);
|
|
36
|
-
};
|
|
37
|
-
const commit = ()=>{
|
|
38
|
-
const next = draft.trim();
|
|
39
|
-
focused = false;
|
|
40
|
-
apply(false);
|
|
41
|
-
if (!next || next === p.value) return;
|
|
42
|
-
p.onCommit?.(next);
|
|
43
|
-
};
|
|
44
|
-
const rootClasses = ()=>twMerge(CLASSES.base, p.fullWidth && CLASSES.flag.fullWidth, p.disabled && CLASSES.flag.disabled, p.class);
|
|
13
|
+
const interactions = createInlineEditInteractions({
|
|
14
|
+
value: ()=>p.value,
|
|
15
|
+
disabled: ()=>Boolean(p.disabled),
|
|
16
|
+
root: ()=>root,
|
|
17
|
+
field: ()=>field,
|
|
18
|
+
editingClass: CLASSES.flag.editing,
|
|
19
|
+
onCommit: (value)=>p.onCommit?.(value)
|
|
20
|
+
});
|
|
21
|
+
const rootClasses = ()=>twMerge(CLASSES.base, interactions.isOpen() && CLASSES.flag.editing, p.fullWidth && CLASSES.flag.fullWidth, p.disabled && CLASSES.flag.disabled, p.class);
|
|
45
22
|
var _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$3.nextSibling, _el$5 = _el$2.nextSibling, _el$6 = _el$5.firstChild;
|
|
23
|
+
ref(()=>(element)=>{
|
|
24
|
+
root = element;
|
|
25
|
+
if ("function" == typeof p.ref) p.ref(element);
|
|
26
|
+
}, _el$);
|
|
46
27
|
spread(_el$, mergeProps(others, {
|
|
47
28
|
get ["class"] () {
|
|
48
29
|
return rootClasses();
|
|
49
30
|
},
|
|
50
31
|
"data-slot": "root"
|
|
51
32
|
}), true);
|
|
52
|
-
ref(()=>(element)=>{
|
|
53
|
-
readRow = element;
|
|
54
|
-
}, _el$2);
|
|
55
33
|
insert(_el$3, ()=>p.children ?? p.value);
|
|
56
|
-
_el$4
|
|
34
|
+
addEvent(_el$4, "click", interactions.start, true);
|
|
57
35
|
insert(_el$4, ()=>p.trigger);
|
|
58
|
-
ref(()=>(element)=>{
|
|
59
|
-
editRow = element;
|
|
60
|
-
}, _el$5);
|
|
61
36
|
_el$6.$$keydown = (event)=>{
|
|
62
|
-
|
|
63
|
-
event.preventDefault();
|
|
64
|
-
commit();
|
|
65
|
-
} else if ("Escape" === event.key) {
|
|
66
|
-
event.preventDefault();
|
|
67
|
-
cancel();
|
|
68
|
-
}
|
|
37
|
+
interactions.keyDown(event.key, ()=>event.preventDefault());
|
|
69
38
|
};
|
|
70
|
-
_el$6
|
|
71
|
-
|
|
72
|
-
if (open) commit();
|
|
73
|
-
});
|
|
74
|
-
_el$6.addEventListener("focus", ()=>{
|
|
75
|
-
focused = true;
|
|
76
|
-
});
|
|
39
|
+
addEvent(_el$6, "blur", interactions.blur);
|
|
40
|
+
addEvent(_el$6, "focus", interactions.focus);
|
|
77
41
|
_el$6.$$input = (event)=>{
|
|
78
|
-
|
|
42
|
+
interactions.input(event.currentTarget.value);
|
|
79
43
|
};
|
|
80
44
|
ref(()=>(element)=>{
|
|
81
45
|
field = element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type InlineEditField = Pick<HTMLInputElement, "focus" | "select" | "value">;
|
|
2
|
+
export type InlineEditInteractionOptions = {
|
|
3
|
+
value: () => string;
|
|
4
|
+
disabled: () => boolean;
|
|
5
|
+
root: () => Pick<HTMLElement, "classList"> | undefined;
|
|
6
|
+
field: () => InlineEditField | undefined;
|
|
7
|
+
editingClass: string;
|
|
8
|
+
onCommit?: (value: string) => void | Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Own the complete open, cancel and commit interaction for InlineEdit.
|
|
12
|
+
*
|
|
13
|
+
* The root class is the only rendered state. Keeping the swap here makes a
|
|
14
|
+
* pencil press independently testable and keeps CSS as the single authority
|
|
15
|
+
* for which row is visible.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createInlineEditInteractions(options: InlineEditInteractionOptions): {
|
|
18
|
+
start: () => void;
|
|
19
|
+
cancel: () => void;
|
|
20
|
+
commit: () => void;
|
|
21
|
+
isOpen: () => boolean;
|
|
22
|
+
input: (value: string) => void;
|
|
23
|
+
focus: () => void;
|
|
24
|
+
blur: () => void;
|
|
25
|
+
keyDown: (key: string, preventDefault: () => void) => void;
|
|
26
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function createInlineEditInteractions(options) {
|
|
2
|
+
let open = false;
|
|
3
|
+
let focused = false;
|
|
4
|
+
let draft = "";
|
|
5
|
+
const apply = (next)=>{
|
|
6
|
+
open = next;
|
|
7
|
+
options.root()?.classList.toggle(options.editingClass, next);
|
|
8
|
+
};
|
|
9
|
+
const resetDraft = ()=>{
|
|
10
|
+
draft = options.value();
|
|
11
|
+
const field = options.field();
|
|
12
|
+
if (field) field.value = draft;
|
|
13
|
+
};
|
|
14
|
+
const start = ()=>{
|
|
15
|
+
if (options.disabled()) return;
|
|
16
|
+
resetDraft();
|
|
17
|
+
apply(true);
|
|
18
|
+
queueMicrotask(()=>{
|
|
19
|
+
options.field()?.focus();
|
|
20
|
+
options.field()?.select();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const cancel = ()=>{
|
|
24
|
+
resetDraft();
|
|
25
|
+
focused = false;
|
|
26
|
+
apply(false);
|
|
27
|
+
};
|
|
28
|
+
const commit = ()=>{
|
|
29
|
+
const next = draft.trim();
|
|
30
|
+
focused = false;
|
|
31
|
+
apply(false);
|
|
32
|
+
if (!next || next === options.value()) return;
|
|
33
|
+
options.onCommit?.(next);
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
start,
|
|
37
|
+
cancel,
|
|
38
|
+
commit,
|
|
39
|
+
isOpen: ()=>open,
|
|
40
|
+
input: (value)=>{
|
|
41
|
+
draft = value;
|
|
42
|
+
},
|
|
43
|
+
focus: ()=>{
|
|
44
|
+
focused = true;
|
|
45
|
+
},
|
|
46
|
+
blur: ()=>{
|
|
47
|
+
if (focused && open) commit();
|
|
48
|
+
},
|
|
49
|
+
keyDown: (key, preventDefault)=>{
|
|
50
|
+
if ("Enter" === key) {
|
|
51
|
+
preventDefault();
|
|
52
|
+
commit();
|
|
53
|
+
} else if ("Escape" === key) {
|
|
54
|
+
preventDefault();
|
|
55
|
+
cancel();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { createInlineEditInteractions };
|