@para-ui/core 5.0.3-beta.10 → 5.0.3-beta.11
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/es/ExpressionInput/index.js +122 -114
- package/lib/ExpressionInput/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
import { j as
|
|
1
|
+
import { j as d } from "../_virtual/jsx-runtime.js";
|
|
2
2
|
import './index.css';/* empty css */
|
|
3
3
|
import * as r from "react";
|
|
4
|
-
import * as
|
|
5
|
-
import { UUID as
|
|
6
|
-
import { TextField as
|
|
7
|
-
import { Tooltip as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { $prefixCls as
|
|
11
|
-
import { useExpressionInput as
|
|
12
|
-
import { Popup as
|
|
13
|
-
import { isExpressionValue as
|
|
14
|
-
import { highlightSegments as
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
const
|
|
4
|
+
import * as I from "react-dom";
|
|
5
|
+
import { UUID as ee } from "@snack-kit/lib";
|
|
6
|
+
import { TextField as te } from "../TextField/index.js";
|
|
7
|
+
import { Tooltip as re } from "../Tooltip/index.js";
|
|
8
|
+
import ne from "../GlobalContext/usePopupContainer.js";
|
|
9
|
+
import oe from "../GlobalContext/useFormatMessage.js";
|
|
10
|
+
import { $prefixCls as W } from "../GlobalContext/constant.js";
|
|
11
|
+
import { useExpressionInput as se } from "./useExpressionInput.js";
|
|
12
|
+
import { Popup as ie } from "./Popup.js";
|
|
13
|
+
import { isExpressionValue as le } from "./isExpressionValue.js";
|
|
14
|
+
import { highlightSegments as ae } from "./highlightSegments.js";
|
|
15
|
+
import ce from "./HighlightOverlay.js";
|
|
16
|
+
import ue from "./lang/index.js";
|
|
17
|
+
const de = 50, pe = "$", fe = (p, s) => {
|
|
18
|
+
const f = Object.keys(s);
|
|
19
|
+
return f.length === Object.keys(p).length && f.every((g) => p[g] === s[g]);
|
|
20
|
+
}, Fe = (p) => {
|
|
18
21
|
const {
|
|
19
|
-
value:
|
|
20
|
-
onChange:
|
|
21
|
-
resolveCandidates:
|
|
22
|
-
triggerMode:
|
|
23
|
-
triggerPrefix:
|
|
24
|
-
virtualizeThreshold:
|
|
25
|
-
renderPopupHeader:
|
|
26
|
-
expressionTooltip:
|
|
27
|
-
disabled:
|
|
28
|
-
readOnly:
|
|
29
|
-
className:
|
|
30
|
-
...
|
|
31
|
-
} =
|
|
32
|
-
open:
|
|
33
|
-
ctx:
|
|
34
|
-
candidates:
|
|
35
|
-
highlight:
|
|
36
|
-
setHighlight:
|
|
37
|
-
handleValueChange:
|
|
38
|
-
handleKeyDown:
|
|
39
|
-
handleSelect:
|
|
40
|
-
close:
|
|
41
|
-
pendingCursorRef:
|
|
42
|
-
} =
|
|
43
|
-
value:
|
|
44
|
-
onChange:
|
|
45
|
-
resolveCandidates:
|
|
46
|
-
triggerMode:
|
|
47
|
-
triggerPrefix:
|
|
48
|
-
disabled:
|
|
49
|
-
readOnly:
|
|
50
|
-
}),
|
|
22
|
+
value: s,
|
|
23
|
+
onChange: f,
|
|
24
|
+
resolveCandidates: g,
|
|
25
|
+
triggerMode: w = "braces",
|
|
26
|
+
triggerPrefix: h = pe,
|
|
27
|
+
virtualizeThreshold: $ = de,
|
|
28
|
+
renderPopupHeader: R,
|
|
29
|
+
expressionTooltip: v,
|
|
30
|
+
disabled: b,
|
|
31
|
+
readOnly: H,
|
|
32
|
+
className: L,
|
|
33
|
+
...E
|
|
34
|
+
} = p, P = oe("ExpressionInput", ue), [y] = r.useState(() => `${W}-expression-input-${ee()}`), n = r.useRef(null), T = r.useRef(null), M = r.useRef({ getRootDomNode: () => n.current }), k = ne(M), [q, A] = r.useState({ top: 0, left: 0, width: 0 }), i = r.useRef(null), [C, B] = r.useState(null), [U, N] = r.useState({}), u = String(s ?? ""), V = r.useMemo(() => ae(u), [u]), {
|
|
35
|
+
open: l,
|
|
36
|
+
ctx: m,
|
|
37
|
+
candidates: x,
|
|
38
|
+
highlight: _,
|
|
39
|
+
setHighlight: K,
|
|
40
|
+
handleValueChange: G,
|
|
41
|
+
handleKeyDown: X,
|
|
42
|
+
handleSelect: J,
|
|
43
|
+
close: F,
|
|
44
|
+
pendingCursorRef: S
|
|
45
|
+
} = se({
|
|
46
|
+
value: u,
|
|
47
|
+
onChange: f,
|
|
48
|
+
resolveCandidates: g,
|
|
49
|
+
triggerMode: w,
|
|
50
|
+
triggerPrefix: h,
|
|
51
|
+
disabled: b,
|
|
52
|
+
readOnly: H
|
|
53
|
+
}), a = r.useCallback(() => {
|
|
51
54
|
const e = n.current?.querySelector("input, textarea");
|
|
52
55
|
if (!e)
|
|
53
56
|
return;
|
|
54
57
|
const t = e.getBoundingClientRect();
|
|
55
|
-
|
|
56
|
-
}, []),
|
|
58
|
+
A({ top: t.bottom + 4, left: t.left, width: Math.max(t.width, 280) });
|
|
59
|
+
}, []), o = r.useCallback(() => {
|
|
57
60
|
const e = n.current?.querySelector("input, textarea");
|
|
58
61
|
if (!e)
|
|
59
62
|
return;
|
|
60
|
-
|
|
61
|
-
const t = window.getComputedStyle(e), c = e.tagName === "TEXTAREA"
|
|
62
|
-
|
|
63
|
+
B(e.parentElement);
|
|
64
|
+
const t = window.getComputedStyle(e), c = e.tagName === "TEXTAREA", O = c ? Math.max(
|
|
65
|
+
0,
|
|
66
|
+
e.offsetWidth - e.clientWidth - (parseFloat(t.borderLeftWidth) || 0) - (parseFloat(t.borderRightWidth) || 0)
|
|
67
|
+
) : 0, j = {
|
|
63
68
|
paddingTop: t.paddingTop,
|
|
64
|
-
paddingRight: t.paddingRight,
|
|
69
|
+
paddingRight: O ? `${parseFloat(t.paddingRight) + O}px` : t.paddingRight,
|
|
65
70
|
paddingBottom: t.paddingBottom,
|
|
66
71
|
paddingLeft: t.paddingLeft,
|
|
67
72
|
fontFamily: t.fontFamily,
|
|
@@ -75,116 +80,119 @@ const ae = 50, ce = "$", Le = (F) => {
|
|
|
75
80
|
borderColor: "transparent",
|
|
76
81
|
whiteSpace: c ? t.whiteSpace : "pre",
|
|
77
82
|
wordBreak: c ? t.wordBreak : "normal"
|
|
78
|
-
}
|
|
83
|
+
};
|
|
84
|
+
N((D) => fe(D, j) ? D : j);
|
|
79
85
|
}, []);
|
|
80
86
|
r.useLayoutEffect(() => {
|
|
81
|
-
|
|
87
|
+
o(), window.addEventListener("resize", o);
|
|
82
88
|
const e = n.current;
|
|
83
89
|
let t;
|
|
84
|
-
return e && typeof ResizeObserver < "u" && (t = new ResizeObserver(
|
|
85
|
-
window.removeEventListener("resize",
|
|
90
|
+
return e && typeof ResizeObserver < "u" && (t = new ResizeObserver(o), t.observe(e)), () => {
|
|
91
|
+
window.removeEventListener("resize", o), t?.disconnect();
|
|
86
92
|
};
|
|
87
|
-
}, [
|
|
93
|
+
}, [o]), r.useEffect(() => {
|
|
88
94
|
const e = n.current?.querySelector("input, textarea");
|
|
89
95
|
if (!e)
|
|
90
96
|
return;
|
|
91
97
|
const t = () => {
|
|
92
|
-
|
|
98
|
+
i.current && (i.current.scrollLeft = e.scrollLeft, i.current.scrollTop = e.scrollTop);
|
|
93
99
|
};
|
|
94
100
|
return e.addEventListener("scroll", t), () => e.removeEventListener("scroll", t);
|
|
95
|
-
}, []), r.
|
|
101
|
+
}, []), r.useLayoutEffect(() => {
|
|
102
|
+
o();
|
|
103
|
+
}, [s, o]), r.useEffect(() => {
|
|
96
104
|
const e = n.current?.querySelector("input, textarea");
|
|
97
|
-
e &&
|
|
98
|
-
}, [
|
|
99
|
-
const e =
|
|
105
|
+
e && i.current && (i.current.scrollLeft = e.scrollLeft, i.current.scrollTop = e.scrollTop);
|
|
106
|
+
}, [s]), r.useEffect(() => {
|
|
107
|
+
const e = S.current;
|
|
100
108
|
if (e === null)
|
|
101
109
|
return;
|
|
102
110
|
const t = n.current?.querySelector("input, textarea");
|
|
103
|
-
t && (t.focus(), t.setSelectionRange(e, e)),
|
|
104
|
-
}, [
|
|
105
|
-
if (
|
|
106
|
-
return
|
|
107
|
-
window.removeEventListener("scroll",
|
|
111
|
+
t && (t.focus(), t.setSelectionRange(e, e)), S.current = null;
|
|
112
|
+
}, [s, S]), r.useEffect(() => {
|
|
113
|
+
if (l)
|
|
114
|
+
return a(), window.addEventListener("scroll", a, !0), window.addEventListener("resize", a), () => {
|
|
115
|
+
window.removeEventListener("scroll", a, !0), window.removeEventListener("resize", a);
|
|
108
116
|
};
|
|
109
|
-
}, [
|
|
110
|
-
if (!
|
|
117
|
+
}, [l, a]), r.useEffect(() => {
|
|
118
|
+
if (!l)
|
|
111
119
|
return;
|
|
112
120
|
const e = (t) => {
|
|
113
121
|
const c = t.target;
|
|
114
|
-
n.current?.contains(c) ||
|
|
122
|
+
n.current?.contains(c) || T.current?.contains(c) || F();
|
|
115
123
|
};
|
|
116
124
|
return document.addEventListener("mousedown", e, !0), () => document.removeEventListener("mousedown", e, !0);
|
|
117
|
-
}, [
|
|
118
|
-
const
|
|
125
|
+
}, [l, F, y]);
|
|
126
|
+
const Z = (e) => {
|
|
119
127
|
const t = e.target.selectionStart ?? e.target.value.length;
|
|
120
|
-
|
|
121
|
-
},
|
|
128
|
+
G(e.target.value, t);
|
|
129
|
+
}, Q = m ? R ? R(m, x.length) : P(
|
|
122
130
|
{ id: "header" },
|
|
123
|
-
{ path:
|
|
124
|
-
) : null,
|
|
125
|
-
|
|
131
|
+
{ path: m.parts.length ? m.parts.join(".") : h, count: x.length }
|
|
132
|
+
) : null, Y = !!v && le(u, h, w), z = /* @__PURE__ */ d.jsx(
|
|
133
|
+
te,
|
|
126
134
|
{
|
|
127
|
-
...
|
|
128
|
-
value:
|
|
129
|
-
disabled:
|
|
130
|
-
onChange:
|
|
135
|
+
...E,
|
|
136
|
+
value: u,
|
|
137
|
+
disabled: b,
|
|
138
|
+
onChange: Z,
|
|
131
139
|
onFocus: (e) => {
|
|
132
|
-
|
|
140
|
+
o(), E.onFocus?.(e);
|
|
133
141
|
},
|
|
134
142
|
onKeydown: (e) => {
|
|
135
|
-
|
|
143
|
+
X(e), E.onKeydown?.(e);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
);
|
|
139
|
-
return /* @__PURE__ */
|
|
147
|
+
return /* @__PURE__ */ d.jsxs(
|
|
140
148
|
"div",
|
|
141
149
|
{
|
|
142
150
|
ref: n,
|
|
143
|
-
className: `${
|
|
151
|
+
className: `${W}-expression-input ${y}${L ? ` ${L}` : ""}`,
|
|
144
152
|
children: [
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
v ? /* @__PURE__ */ d.jsx(
|
|
154
|
+
re,
|
|
147
155
|
{
|
|
148
|
-
title:
|
|
156
|
+
title: v,
|
|
149
157
|
trigger: ["hover", "focus"],
|
|
150
|
-
...
|
|
151
|
-
children:
|
|
158
|
+
...Y ? {} : { visible: !1 },
|
|
159
|
+
children: z
|
|
152
160
|
}
|
|
153
|
-
) :
|
|
154
|
-
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
|
|
161
|
+
) : z,
|
|
162
|
+
C && I.createPortal(
|
|
163
|
+
/* @__PURE__ */ d.jsx(
|
|
164
|
+
ce,
|
|
157
165
|
{
|
|
158
|
-
ref:
|
|
159
|
-
segments:
|
|
160
|
-
style:
|
|
166
|
+
ref: i,
|
|
167
|
+
segments: V,
|
|
168
|
+
style: U
|
|
161
169
|
}
|
|
162
170
|
),
|
|
163
|
-
|
|
171
|
+
C
|
|
164
172
|
),
|
|
165
|
-
|
|
166
|
-
/* @__PURE__ */
|
|
167
|
-
|
|
173
|
+
l && n.current && I.createPortal(
|
|
174
|
+
/* @__PURE__ */ d.jsx(
|
|
175
|
+
ie,
|
|
168
176
|
{
|
|
169
|
-
ref:
|
|
170
|
-
instanceClass:
|
|
171
|
-
visible:
|
|
172
|
-
rect:
|
|
173
|
-
header:
|
|
174
|
-
candidates:
|
|
175
|
-
highlight:
|
|
176
|
-
virtualizeThreshold:
|
|
177
|
-
onSelect:
|
|
178
|
-
onHighlightChange:
|
|
177
|
+
ref: T,
|
|
178
|
+
instanceClass: y,
|
|
179
|
+
visible: l,
|
|
180
|
+
rect: q,
|
|
181
|
+
header: Q,
|
|
182
|
+
candidates: x,
|
|
183
|
+
highlight: _,
|
|
184
|
+
virtualizeThreshold: $,
|
|
185
|
+
onSelect: J,
|
|
186
|
+
onHighlightChange: K
|
|
179
187
|
}
|
|
180
188
|
),
|
|
181
|
-
|
|
189
|
+
k(n.current)
|
|
182
190
|
)
|
|
183
191
|
]
|
|
184
192
|
}
|
|
185
193
|
);
|
|
186
194
|
};
|
|
187
195
|
export {
|
|
188
|
-
|
|
196
|
+
Fe as default
|
|
189
197
|
};
|
|
190
198
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require('./index.css');const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require('./index.css');const g=require("../_virtual/jsx-runtime.js");;/* empty css */const te=require("react"),ne=require("react-dom"),re=require("@snack-kit/lib"),oe=require("../TextField/index.js"),se=require("../Tooltip/index.js"),ie=require("../GlobalContext/usePopupContainer.js"),ce=require("../GlobalContext/useFormatMessage.js"),_=require("../GlobalContext/constant.js"),le=require("./useExpressionInput.js"),ue=require("./Popup.js"),ae=require("./isExpressionValue.js"),de=require("./highlightSegments.js"),pe=require("./HighlightOverlay.js"),fe=require("./lang/index.js");function P(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const i in s)if(i!=="default"){const l=Object.getOwnPropertyDescriptor(s,i);Object.defineProperty(r,i,l.get?l:{enumerable:!0,get:()=>s[i]})}}return r.default=s,Object.freeze(r)}const n=P(te),D=P(ne),ge=50,he="$",xe=(s,r)=>{const i=Object.keys(r);return i.length===Object.keys(s).length&&i.every(l=>s[l]===r[l])},me=s=>{const{value:r,onChange:i,resolveCandidates:l,triggerMode:R="braces",triggerPrefix:x=he,virtualizeThreshold:M=ge,renderPopupHeader:b,expressionTooltip:m,disabled:w,readOnly:I,className:T,...v}=s,$=ce.default("ExpressionInput",fe.default),[E]=n.useState(()=>`${_.$prefixCls}-expression-input-${re.UUID()}`),o=n.useRef(null),L=n.useRef(null),W=n.useRef({getRootDomNode:()=>o.current}),H=ie.default(W),[k,A]=n.useState({top:0,left:0,width:0}),u=n.useRef(null),[q,B]=n.useState(null),[N,U]=n.useState({}),f=String(r??""),V=n.useMemo(()=>de.highlightSegments(f),[f]),{open:a,ctx:h,candidates:y,highlight:K,setHighlight:G,handleValueChange:X,handleKeyDown:Z,handleSelect:J,close:j,pendingCursorRef:S}=le.useExpressionInput({value:f,onChange:i,resolveCandidates:l,triggerMode:R,triggerPrefix:x,disabled:w,readOnly:I}),d=n.useCallback(()=>{const e=o.current?.querySelector("input, textarea");if(!e)return;const t=e.getBoundingClientRect();A({top:t.bottom+4,left:t.left,width:Math.max(t.width,280)})},[]),c=n.useCallback(()=>{const e=o.current?.querySelector("input, textarea");if(!e)return;B(e.parentElement);const t=window.getComputedStyle(e),p=e.tagName==="TEXTAREA",O=p?Math.max(0,e.offsetWidth-e.clientWidth-(parseFloat(t.borderLeftWidth)||0)-(parseFloat(t.borderRightWidth)||0)):0,F={paddingTop:t.paddingTop,paddingRight:O?`${parseFloat(t.paddingRight)+O}px`:t.paddingRight,paddingBottom:t.paddingBottom,paddingLeft:t.paddingLeft,fontFamily:t.fontFamily,fontSize:t.fontSize,fontWeight:t.fontWeight,lineHeight:t.lineHeight,letterSpacing:t.letterSpacing,boxSizing:t.boxSizing,borderWidth:t.borderWidth,borderStyle:t.borderStyle,borderColor:"transparent",whiteSpace:p?t.whiteSpace:"pre",wordBreak:p?t.wordBreak:"normal"};U(z=>xe(z,F)?z:F)},[]);n.useLayoutEffect(()=>{c(),window.addEventListener("resize",c);const e=o.current;let t;return e&&typeof ResizeObserver<"u"&&(t=new ResizeObserver(c),t.observe(e)),()=>{window.removeEventListener("resize",c),t?.disconnect()}},[c]),n.useEffect(()=>{const e=o.current?.querySelector("input, textarea");if(!e)return;const t=()=>{u.current&&(u.current.scrollLeft=e.scrollLeft,u.current.scrollTop=e.scrollTop)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),n.useLayoutEffect(()=>{c()},[r,c]),n.useEffect(()=>{const e=o.current?.querySelector("input, textarea");e&&u.current&&(u.current.scrollLeft=e.scrollLeft,u.current.scrollTop=e.scrollTop)},[r]),n.useEffect(()=>{const e=S.current;if(e===null)return;const t=o.current?.querySelector("input, textarea");t&&(t.focus(),t.setSelectionRange(e,e)),S.current=null},[r,S]),n.useEffect(()=>{if(a)return d(),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[a,d]),n.useEffect(()=>{if(!a)return;const e=t=>{const p=t.target;o.current?.contains(p)||L.current?.contains(p)||j()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[a,j,E]);const Q=e=>{const t=e.target.selectionStart??e.target.value.length;X(e.target.value,t)},Y=h?b?b(h,y.length):$({id:"header"},{path:h.parts.length?h.parts.join("."):x,count:y.length}):null,ee=!!m&&ae.isExpressionValue(f,x,R),C=g.jsxRuntimeExports.jsx(oe.TextField,{...v,value:f,disabled:w,onChange:Q,onFocus:e=>{c(),v.onFocus?.(e)},onKeydown:e=>{Z(e),v.onKeydown?.(e)}});return g.jsxRuntimeExports.jsxs("div",{ref:o,className:`${_.$prefixCls}-expression-input ${E}${T?` ${T}`:""}`,children:[m?g.jsxRuntimeExports.jsx(se.Tooltip,{title:m,trigger:["hover","focus"],...ee?{}:{visible:!1},children:C}):C,q&&D.createPortal(g.jsxRuntimeExports.jsx(pe.default,{ref:u,segments:V,style:N}),q),a&&o.current&&D.createPortal(g.jsxRuntimeExports.jsx(ue.Popup,{ref:L,instanceClass:E,visible:a,rect:k,header:Y,candidates:y,highlight:K,virtualizeThreshold:M,onSelect:J,onHighlightChange:G}),H(o.current))]})};exports.default=me;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|