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