@pathscale/ui 2.11.3 → 2.11.4
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
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
|
-
import { omit, onSettled } from "solid-js";
|
|
4
|
+
import { createTrackedEffect, omit, onSettled } from "solid-js";
|
|
5
5
|
import { twMerge } from "../../lib/twMerge.js";
|
|
6
|
-
import { createInlineEditInteractions } from "./InlineEdit.interactions.js";
|
|
6
|
+
import { bindInlineEditDismissals, createInlineEditInteractions } from "./InlineEdit.interactions.js";
|
|
7
7
|
import { CLASSES, componentRecipe } from "./InlineEdit.recipe.js";
|
|
8
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>");
|
|
9
9
|
const __solidLayoutInlineEdit = (_stable, p)=>{
|
|
@@ -19,15 +19,11 @@ const __solidLayoutInlineEdit = (_stable, p)=>{
|
|
|
19
19
|
onCommit: (value)=>p.onCommit?.(value)
|
|
20
20
|
});
|
|
21
21
|
const rootClasses = ()=>twMerge(CLASSES.base, interactions.isOpen() && CLASSES.flag.editing, p.fullWidth && CLASSES.flag.fullWidth, p.disabled && CLASSES.flag.disabled, p.class);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
document.addEventListener("pointerdown", pointerDown, true);
|
|
27
|
-
return ()=>{
|
|
28
|
-
document.removeEventListener("pointerdown", pointerDown, true);
|
|
29
|
-
};
|
|
22
|
+
createTrackedEffect(()=>{
|
|
23
|
+
p.value;
|
|
24
|
+
interactions.syncValue();
|
|
30
25
|
});
|
|
26
|
+
onSettled(()=>bindInlineEditDismissals(document, window, interactions.outside, interactions.windowBlur));
|
|
31
27
|
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;
|
|
32
28
|
ref(()=>(element)=>{
|
|
33
29
|
root = element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type InlineEditField = Pick<HTMLInputElement, "focus" | "select" | "value">;
|
|
2
|
+
export declare function bindInlineEditDismissals(documentSource: Pick<Document, "addEventListener" | "removeEventListener">, windowSource: Pick<Window, "addEventListener" | "removeEventListener">, outside: (target: EventTarget | null) => void, windowBlur: () => void): () => void;
|
|
2
3
|
export type InlineEditInteractionOptions = {
|
|
3
4
|
value: () => string;
|
|
4
5
|
disabled: () => boolean;
|
|
@@ -22,6 +23,8 @@ export declare function createInlineEditInteractions(options: InlineEditInteract
|
|
|
22
23
|
input: (value: string) => void;
|
|
23
24
|
focus: () => void;
|
|
24
25
|
blur: () => void;
|
|
25
|
-
|
|
26
|
+
outside: (target: EventTarget | null) => void;
|
|
27
|
+
windowBlur: () => void;
|
|
28
|
+
syncValue: () => void;
|
|
26
29
|
keyDown: (key: string, preventDefault: () => void) => void;
|
|
27
30
|
};
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
function bindInlineEditDismissals(documentSource, windowSource, outside, windowBlur) {
|
|
2
|
+
const pointerDown = (event)=>{
|
|
3
|
+
outside(event.target);
|
|
4
|
+
};
|
|
5
|
+
const focusIn = (event)=>{
|
|
6
|
+
outside(event.target);
|
|
7
|
+
};
|
|
8
|
+
documentSource.addEventListener("pointerdown", pointerDown);
|
|
9
|
+
documentSource.addEventListener("focusin", focusIn);
|
|
10
|
+
windowSource.addEventListener("blur", windowBlur);
|
|
11
|
+
return ()=>{
|
|
12
|
+
documentSource.removeEventListener("pointerdown", pointerDown);
|
|
13
|
+
documentSource.removeEventListener("focusin", focusIn);
|
|
14
|
+
windowSource.removeEventListener("blur", windowBlur);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
1
17
|
function createInlineEditInteractions(options) {
|
|
2
18
|
let open = false;
|
|
3
19
|
let focused = false;
|
|
4
20
|
let draft = "";
|
|
21
|
+
let sourceValue = options.value();
|
|
5
22
|
const apply = (next)=>{
|
|
6
23
|
open = next;
|
|
7
24
|
options.root()?.classList.toggle(options.editingClass, next);
|
|
@@ -13,6 +30,7 @@ function createInlineEditInteractions(options) {
|
|
|
13
30
|
};
|
|
14
31
|
const start = ()=>{
|
|
15
32
|
if (options.disabled()) return;
|
|
33
|
+
sourceValue = options.value();
|
|
16
34
|
resetDraft();
|
|
17
35
|
apply(true);
|
|
18
36
|
queueMicrotask(()=>{
|
|
@@ -46,10 +64,16 @@ function createInlineEditInteractions(options) {
|
|
|
46
64
|
blur: ()=>{
|
|
47
65
|
if (focused && open) commit();
|
|
48
66
|
},
|
|
49
|
-
|
|
67
|
+
outside: (target)=>{
|
|
50
68
|
const root = options.root();
|
|
51
69
|
if (open && root && !root.contains(target)) commit();
|
|
52
70
|
},
|
|
71
|
+
windowBlur: ()=>{
|
|
72
|
+
if (open) commit();
|
|
73
|
+
},
|
|
74
|
+
syncValue: ()=>{
|
|
75
|
+
if (open && options.value() !== sourceValue) cancel();
|
|
76
|
+
},
|
|
53
77
|
keyDown: (key, preventDefault)=>{
|
|
54
78
|
if ("Enter" === key) {
|
|
55
79
|
preventDefault();
|
|
@@ -61,4 +85,4 @@ function createInlineEditInteractions(options) {
|
|
|
61
85
|
}
|
|
62
86
|
};
|
|
63
87
|
}
|
|
64
|
-
export { createInlineEditInteractions };
|
|
88
|
+
export { bindInlineEditDismissals, createInlineEditInteractions };
|