@para-ui/core 5.0.1 → 5.0.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.
|
@@ -1,59 +1,62 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { detectChainAtCursor as
|
|
3
|
-
import { filterCandidatesByPartial as
|
|
4
|
-
function
|
|
5
|
-
const { value:
|
|
1
|
+
import * as r from "react";
|
|
2
|
+
import { detectChainAtCursor as $ } from "./detectChainAtCursor.js";
|
|
3
|
+
import { filterCandidatesByPartial as B } from "./filterCandidatesByPartial.js";
|
|
4
|
+
function H(M) {
|
|
5
|
+
const { value: h, onChange: i, resolveCandidates: a, triggerMode: u, triggerPrefix: l, disabled: p, readOnly: d } = M, [t, c] = r.useState(null), [g, o] = r.useState(0), y = r.useRef(/* @__PURE__ */ new Map()), x = r.useRef(a), C = r.useRef(null), b = r.useMemo(() => {
|
|
6
6
|
if (!t)
|
|
7
7
|
return [];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
x.current !== a && (y.current.clear(), x.current = a);
|
|
9
|
+
const e = t.parts.join("."), n = y.current;
|
|
10
|
+
return n.has(e) || n.set(e, a(t.parts)), n.get(e);
|
|
11
|
+
}, [t, a]), s = r.useMemo(
|
|
12
|
+
() => t ? B(b, t.partial) : [],
|
|
13
|
+
[b, t]
|
|
14
|
+
), k = !p && !d && !!t && s.length > 0, S = r.useCallback(
|
|
14
15
|
(e, n) => {
|
|
15
|
-
if (
|
|
16
|
-
|
|
16
|
+
if (p || d) {
|
|
17
|
+
c(null);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
C.current = n, i?.(e);
|
|
21
|
+
const m = $(e, n, { triggerPrefix: l, triggerMode: u });
|
|
22
|
+
c(m), o(0);
|
|
22
23
|
},
|
|
23
|
-
[
|
|
24
|
-
),
|
|
24
|
+
[i, p, d, l, u]
|
|
25
|
+
), A = r.useCallback(() => c(null), []), f = r.useCallback(
|
|
25
26
|
(e) => {
|
|
26
27
|
if (!t)
|
|
27
28
|
return;
|
|
28
|
-
const n =
|
|
29
|
-
|
|
29
|
+
const n = h.slice(0, t.startIdx), m = h.slice(t.endIdx), j = [...t.parts, e.value].join("."), R = `${l}.${j}${e.chain ? "." : ""}`, w = `${n}${R}${m}`, D = n.length + R.length;
|
|
30
|
+
C.current = D, i?.(w), c(
|
|
31
|
+
e.chain ? $(w, D, { triggerPrefix: l, triggerMode: u }) : null
|
|
32
|
+
), o(0);
|
|
30
33
|
},
|
|
31
|
-
[t,
|
|
32
|
-
),
|
|
34
|
+
[t, h, i, l, u]
|
|
35
|
+
), E = r.useCallback(
|
|
33
36
|
(e) => {
|
|
34
|
-
|
|
37
|
+
k && (e.key === "ArrowDown" ? (e.preventDefault(), o((n) => (n + 1) % s.length)) : e.key === "ArrowUp" ? (e.preventDefault(), o((n) => (n - 1 + s.length) % s.length)) : e.key === "Enter" || e.key === "Tab" ? (e.preventDefault(), f(s[g])) : e.key === "Escape" && (e.preventDefault(), c(null)));
|
|
35
38
|
},
|
|
36
|
-
[
|
|
37
|
-
),
|
|
39
|
+
[k, s, g, f]
|
|
40
|
+
), I = r.useCallback(
|
|
38
41
|
(e) => {
|
|
39
|
-
|
|
42
|
+
f(e);
|
|
40
43
|
},
|
|
41
|
-
[
|
|
44
|
+
[f]
|
|
42
45
|
);
|
|
43
46
|
return {
|
|
44
|
-
open:
|
|
47
|
+
open: k,
|
|
45
48
|
ctx: t ? { parts: t.parts, partial: t.partial } : null,
|
|
46
|
-
candidates:
|
|
47
|
-
highlight:
|
|
48
|
-
setHighlight:
|
|
49
|
-
pendingCursorRef:
|
|
50
|
-
handleValueChange:
|
|
51
|
-
handleKeyDown:
|
|
52
|
-
handleSelect:
|
|
53
|
-
close:
|
|
49
|
+
candidates: s,
|
|
50
|
+
highlight: g,
|
|
51
|
+
setHighlight: o,
|
|
52
|
+
pendingCursorRef: C,
|
|
53
|
+
handleValueChange: S,
|
|
54
|
+
handleKeyDown: E,
|
|
55
|
+
handleSelect: I,
|
|
56
|
+
close: A
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
export {
|
|
57
|
-
|
|
60
|
+
H as useExpressionInput
|
|
58
61
|
};
|
|
59
62
|
//# sourceMappingURL=useExpressionInput.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react"),w=require("./detectChainAtCursor.js"),I=require("./filterCandidatesByPartial.js");function T(l){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const s in l)if(s!=="default"){const a=Object.getOwnPropertyDescriptor(l,s);Object.defineProperty(c,s,a.get?a:{enumerable:!0,get:()=>l[s]})}}return c.default=l,Object.freeze(c)}const r=T(E);function q(l){const{value:c,onChange:s,resolveCandidates:a,triggerMode:d,triggerPrefix:u,disabled:h,readOnly:g}=l,[t,i]=r.useState(null),[C,f]=r.useState(0),m=r.useRef(new Map),x=r.useRef(a),b=r.useRef(null),D=r.useMemo(()=>{if(!t)return[];x.current!==a&&(m.current.clear(),x.current=a);const e=t.parts.join("."),n=m.current;return n.has(e)||n.set(e,a(t.parts)),n.get(e)},[t,a]),o=r.useMemo(()=>t?I.filterCandidatesByPartial(D,t.partial):[],[D,t]),y=!h&&!g&&!!t&&o.length>0,O=r.useCallback((e,n)=>{if(h||g){i(null);return}b.current=n,s?.(e);const k=w.detectChainAtCursor(e,n,{triggerPrefix:u,triggerMode:d});i(k),f(0)},[s,h,g,u,d]),M=r.useCallback(()=>i(null),[]),p=r.useCallback(e=>{if(!t)return;const n=c.slice(0,t.startIdx),k=c.slice(t.endIdx),A=[...t.parts,e.value].join("."),R=`${u}.${A}${e.chain?".":""}`,S=`${n}${R}${k}`,j=n.length+R.length;b.current=j,s?.(S),i(e.chain?w.detectChainAtCursor(S,j,{triggerPrefix:u,triggerMode:d}):null),f(0)},[t,c,s,u,d]),P=r.useCallback(e=>{y&&(e.key==="ArrowDown"?(e.preventDefault(),f(n=>(n+1)%o.length)):e.key==="ArrowUp"?(e.preventDefault(),f(n=>(n-1+o.length)%o.length)):e.key==="Enter"||e.key==="Tab"?(e.preventDefault(),p(o[C])):e.key==="Escape"&&(e.preventDefault(),i(null)))},[y,o,C,p]),$=r.useCallback(e=>{p(e)},[p]);return{open:y,ctx:t?{parts:t.parts,partial:t.partial}:null,candidates:o,highlight:C,setHighlight:f,pendingCursorRef:b,handleValueChange:O,handleKeyDown:P,handleSelect:$,close:M}}exports.useExpressionInput=q;
|
|
2
2
|
//# sourceMappingURL=useExpressionInput.js.map
|