@floegence/floe-webapp-core 0.86.14 → 0.86.15
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/remote-input.js +99 -91
- package/package.json +1 -1
package/dist/remote-input.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
function
|
|
2
|
-
const { surface:
|
|
3
|
-
if (!
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
let l = null,
|
|
7
|
-
const
|
|
8
|
-
let
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
e.addEventListener(
|
|
1
|
+
function j(n) {
|
|
2
|
+
const { surface: A } = n, x = A.ownerDocument, c = x.defaultView;
|
|
3
|
+
if (!c) throw new Error("Remote input requires an attached document");
|
|
4
|
+
const i = x.createElement("textarea");
|
|
5
|
+
i.className = "floe-remote-input", i.setAttribute("aria-label", n.label), i.setAttribute("autocorrect", "off"), i.autocomplete = "off", i.autocapitalize = "off", i.spellcheck = !1, i.wrap = "off", i.disabled = !0, i.tabIndex = -1, x.body.append(i);
|
|
6
|
+
let l = null, K = 0, f = !1, R = !1, o = null, h = !1, a = null, w = "physical";
|
|
7
|
+
const k = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set();
|
|
8
|
+
let $ = null;
|
|
9
|
+
const V = [];
|
|
10
|
+
function s(e, t, r) {
|
|
11
|
+
const d = r;
|
|
12
|
+
e.addEventListener(t, d), V.push(() => e.removeEventListener(t, d));
|
|
13
13
|
}
|
|
14
|
-
const b = (e) => e.code || e.key,
|
|
14
|
+
const b = (e) => e.code || e.key, M = (e, t) => ({
|
|
15
15
|
key: e.key,
|
|
16
16
|
code: e.code,
|
|
17
|
-
pressed:
|
|
17
|
+
pressed: t,
|
|
18
18
|
repeat: e.repeat,
|
|
19
19
|
location: e.location,
|
|
20
20
|
shiftKey: e.shiftKey,
|
|
@@ -22,139 +22,147 @@ function W(n) {
|
|
|
22
22
|
altKey: e.altKey,
|
|
23
23
|
metaKey: e.metaKey
|
|
24
24
|
});
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
function d() {
|
|
29
|
-
const e = E.getBoundingClientRect(), i = u.visualViewport, r = Math.max(e.left, i?.offsetLeft ?? 0), k = Math.max(e.top, i?.offsetTop ?? 0), B = Math.min(e.right, (i?.offsetLeft ?? 0) + (i?.width ?? u.innerWidth)), P = Math.min(e.bottom, (i?.offsetTop ?? 0) + (i?.height ?? u.innerHeight)), R = Math.max(1, Math.min(320, B - r - 8));
|
|
30
|
-
t.style.maxWidth = `${R}px`;
|
|
31
|
-
const D = t.getBoundingClientRect(), $ = T?.x ?? r + 12, N = T?.y ?? k + 12;
|
|
32
|
-
t.style.left = `${Math.max(r, Math.min($, B - D.width - 4))}px`, t.style.top = `${Math.max(k, Math.min(N, P - D.height - 4))}px`;
|
|
25
|
+
function T(e) {
|
|
26
|
+
R !== e && (R = e, n.onKeyboardVisibilityChange?.(e));
|
|
33
27
|
}
|
|
34
28
|
function p() {
|
|
35
|
-
t.
|
|
29
|
+
const e = A.getBoundingClientRect(), t = c.visualViewport, r = Math.max(e.left, t?.offsetLeft ?? 0), d = Math.max(e.top, t?.offsetTop ?? 0), y = Math.min(e.right, (t?.offsetLeft ?? 0) + (t?.width ?? c.innerWidth)), I = Math.min(e.bottom, (t?.offsetTop ?? 0) + (t?.height ?? c.innerHeight)), P = Math.max(1, Math.min(320, y - r - 8));
|
|
30
|
+
i.style.maxWidth = `${P}px`;
|
|
31
|
+
const B = i.getBoundingClientRect(), N = $?.x ?? r + 12, W = $?.y ?? d + 12;
|
|
32
|
+
i.style.left = `${Math.max(r, Math.min(N, y - B.width - 4))}px`, i.style.top = `${Math.max(d, Math.min(W, I - B.height - 4))}px`;
|
|
33
|
+
}
|
|
34
|
+
function m() {
|
|
35
|
+
i.value = "", delete i.dataset.composing, a = null;
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
const e = l,
|
|
39
|
-
|
|
37
|
+
function E() {
|
|
38
|
+
const e = l, t = u.size > 0;
|
|
39
|
+
u.clear(), k.clear(), C.clear(), e !== null && t && n.release(e);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
41
|
+
function g() {
|
|
42
|
+
K++, o && (o.cancelled = !0), h = !0, m(), E(), o && x.activeElement === i && i.blur();
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
!e || l === null ||
|
|
44
|
+
function S(e) {
|
|
45
|
+
!e || l === null || f || (w === "text" && u.size && (u.clear(), C.clear(), n.release(l)), n.commitText(e, l));
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function z(e) {
|
|
48
48
|
if (l !== null) {
|
|
49
|
-
if (
|
|
50
|
-
for (const [
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (!/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code))
|
|
50
|
+
for (const [t, r] of [
|
|
51
|
+
["Shift", e.shiftKey],
|
|
52
|
+
["Control", e.ctrlKey],
|
|
53
|
+
["Alt", e.altKey],
|
|
54
|
+
["Meta", e.metaKey]
|
|
55
|
+
]) {
|
|
56
|
+
if (!r || [...u].some((y) => y === `${t}Left` || y === `${t}Right`)) continue;
|
|
57
|
+
const d = [...k.values()].find((y) => y.code === `${t}Left` || y.code === `${t}Right`) ?? { ...e, key: t, code: `${t}Left`, pressed: !0, repeat: !1, location: 1 };
|
|
58
|
+
u.add(d.code), k.has(d.code) || C.add(d.code), n.sendKey(d, l);
|
|
59
|
+
}
|
|
60
|
+
u.add(e.code || e.key), n.sendKey(e, l);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
function
|
|
63
|
+
function D(e) {
|
|
56
64
|
if (l === null) return;
|
|
57
|
-
const
|
|
58
|
-
n.sendKey(
|
|
65
|
+
const t = { key: e, code: e, pressed: !0, repeat: !1, shiftKey: !1, ctrlKey: !1, altKey: !1, metaKey: !1, location: 0 }, r = l;
|
|
66
|
+
n.sendKey(t, r), l === r && n.sendKey({ ...t, pressed: !1 }, r);
|
|
59
67
|
}
|
|
60
|
-
function
|
|
61
|
-
if (l === null ||
|
|
62
|
-
|
|
68
|
+
function F(e) {
|
|
69
|
+
if (l === null || f) {
|
|
70
|
+
m();
|
|
63
71
|
return;
|
|
64
72
|
}
|
|
65
|
-
if (o?.cancelled || o && o.epoch !==
|
|
66
|
-
|
|
73
|
+
if (o?.cancelled || o && o.epoch !== K) {
|
|
74
|
+
m();
|
|
67
75
|
return;
|
|
68
76
|
}
|
|
69
77
|
if (e.isComposing) {
|
|
70
|
-
o ??= { epoch:
|
|
78
|
+
o ??= { epoch: K, committed: !1, cancelled: !1 }, i.dataset.composing = "true", p();
|
|
71
79
|
return;
|
|
72
80
|
}
|
|
73
81
|
if (o) {
|
|
74
|
-
!o.committed &&
|
|
82
|
+
!o.committed && i.value && (o.committed = !0, S(i.value)), m();
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
85
|
+
if (h || e.inputType === "insertFromComposition") {
|
|
86
|
+
h = !1, m();
|
|
79
87
|
return;
|
|
80
88
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const r = s;
|
|
84
|
-
f.add(r.code || r.key), n.sendKey(r, l);
|
|
85
|
-
} else V(i);
|
|
86
|
-
p();
|
|
89
|
+
const t = i.value;
|
|
90
|
+
w === "physical" && a && t === a.key && !a.altKey && t.length === 1 ? z(a) : S(t), m();
|
|
87
91
|
}
|
|
88
|
-
return
|
|
89
|
-
if (!(l === null ||
|
|
92
|
+
return s(i, "keydown", (e) => {
|
|
93
|
+
if (!(l === null || f)) {
|
|
90
94
|
if (e.stopPropagation(), o?.cancelled && !e.isComposing && e.key !== "Process" && e.keyCode !== 229 && (o = null), e.isComposing || o || e.key === "Process" || e.keyCode === 229) {
|
|
91
|
-
|
|
95
|
+
L.add(b(e)), a = null;
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
94
|
-
if (
|
|
95
|
-
|
|
98
|
+
if (L.delete(b(e)), h = !1, n.clipboard?.(e, l)) {
|
|
99
|
+
a = null;
|
|
96
100
|
return;
|
|
97
101
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
102
|
+
if (w === "text" && /^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code)) {
|
|
103
|
+
k.set(b(e), M(e, !0));
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
106
|
if (e.key === "Dead" || e.key === "Unidentified") {
|
|
103
|
-
|
|
107
|
+
a = null;
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
110
|
if (Array.from(e.key).length === 1 && !e.metaKey && (!e.ctrlKey || e.getModifierState("AltGraph"))) {
|
|
107
|
-
|
|
111
|
+
a = M(e, !0);
|
|
108
112
|
return;
|
|
109
113
|
}
|
|
110
|
-
e.preventDefault(),
|
|
114
|
+
e.preventDefault(), z(M(e, !0));
|
|
115
|
+
}
|
|
116
|
+
}), s(i, "keyup", (e) => {
|
|
117
|
+
if (e.stopPropagation(), a = null, k.delete(b(e)), !L.delete(b(e)) && (l !== null && u.delete(b(e)) && n.sendKey(M(e, !1), l), l !== null && ![...u].some((t) => !/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(t)))) {
|
|
118
|
+
for (const t of C)
|
|
119
|
+
u.delete(t), n.sendKey({ ...M(e, !1), code: t, key: t.replace(/Left$/, ""), location: 1 }, l);
|
|
120
|
+
C.clear();
|
|
111
121
|
}
|
|
112
|
-
}),
|
|
113
|
-
|
|
114
|
-
}), a(t, "beforeinput", (e) => {
|
|
115
|
-
if (l === null || c) {
|
|
122
|
+
}), s(i, "beforeinput", (e) => {
|
|
123
|
+
if (l === null || f) {
|
|
116
124
|
e.preventDefault();
|
|
117
125
|
return;
|
|
118
126
|
}
|
|
119
127
|
if (e.isComposing || o || e.inputType === "insertCompositionText" || e.inputType === "deleteCompositionText" || e.inputType === "insertFromComposition") return;
|
|
120
|
-
|
|
128
|
+
h = !1;
|
|
121
129
|
const r = { deleteContentBackward: "Backspace", deleteContentForward: "Delete", insertLineBreak: "Enter", insertParagraph: "Enter" }[e.inputType];
|
|
122
|
-
r && (e.preventDefault(),
|
|
123
|
-
}),
|
|
124
|
-
o = { epoch:
|
|
125
|
-
}),
|
|
126
|
-
const
|
|
127
|
-
o = null,
|
|
128
|
-
}),
|
|
129
|
-
|
|
130
|
-
}),
|
|
131
|
-
element:
|
|
130
|
+
r && (e.preventDefault(), m(), D(r));
|
|
131
|
+
}), s(i, "input", F), s(i, "compositionstart", () => {
|
|
132
|
+
o = { epoch: K, committed: !1, cancelled: l === null }, h = !1, a = null, i.dataset.composing = "true", p();
|
|
133
|
+
}), s(i, "compositionend", (e) => {
|
|
134
|
+
const t = o;
|
|
135
|
+
o = null, h = !0, m(), t && !t.cancelled && !t.committed && t.epoch === K && S(e.data);
|
|
136
|
+
}), s(i, "blur", () => {
|
|
137
|
+
g(), T(!1);
|
|
138
|
+
}), s(c, "blur", g), s(c, "pagehide", g), s(c, "resize", p), c.visualViewport && (s(c.visualViewport, "resize", p), s(c.visualViewport, "scroll", p)), p(), {
|
|
139
|
+
element: i,
|
|
132
140
|
bindTarget(e) {
|
|
133
|
-
|
|
141
|
+
f || Object.is(l, e) || (g(), l = e, i.disabled = e === null);
|
|
134
142
|
},
|
|
135
143
|
setTextInputMode(e) {
|
|
136
|
-
|
|
144
|
+
f || e === w || (g(), w = e);
|
|
137
145
|
},
|
|
138
|
-
setAnchor(e,
|
|
139
|
-
!Number.isFinite(e) || !Number.isFinite(
|
|
146
|
+
setAnchor(e, t) {
|
|
147
|
+
!Number.isFinite(e) || !Number.isFinite(t) || ($ = { x: e, y: t }, p());
|
|
140
148
|
},
|
|
141
149
|
focus() {
|
|
142
|
-
l === null ||
|
|
150
|
+
l === null || f || (i.focus({ preventScroll: !0 }), p());
|
|
143
151
|
},
|
|
144
152
|
setKeyboardVisible(e) {
|
|
145
|
-
e && l !== null && !
|
|
153
|
+
e && l !== null && !f ? (i.focus({ preventScroll: !0 }), T(!0), p()) : (i.blur(), T(!1));
|
|
146
154
|
},
|
|
147
|
-
release:
|
|
148
|
-
reset:
|
|
155
|
+
release: E,
|
|
156
|
+
reset: g,
|
|
149
157
|
dispose() {
|
|
150
|
-
if (!
|
|
151
|
-
|
|
152
|
-
for (const e of
|
|
153
|
-
|
|
158
|
+
if (!f) {
|
|
159
|
+
g(), f = !0, l = null;
|
|
160
|
+
for (const e of V) e();
|
|
161
|
+
i.remove(), T(!1);
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
};
|
|
157
165
|
}
|
|
158
166
|
export {
|
|
159
|
-
|
|
167
|
+
j as createRemoteInput
|
|
160
168
|
};
|