@pie-lib/graphing 4.0.5-next.32 → 4.0.5-next.33
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/mark-label.js +89 -68
- package/package.json +1 -1
package/dist/mark-label.js
CHANGED
|
@@ -4,72 +4,74 @@ import n from "./label-svg-icon.js";
|
|
|
4
4
|
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
5
5
|
import s from "prop-types";
|
|
6
6
|
import { types as c } from "@pie-lib/plot";
|
|
7
|
-
import { styled as l, useTheme as
|
|
8
|
-
import { Fragment as
|
|
9
|
-
import { color as
|
|
7
|
+
import { styled as l, useTheme as ee } from "@mui/material/styles";
|
|
8
|
+
import { Fragment as te, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
+
import { color as f } from "@pie-lib/render-ui";
|
|
10
10
|
//#region src/mark-label.tsx
|
|
11
|
-
var
|
|
11
|
+
var ne = 500, p = 500, m = [
|
|
12
12
|
0,
|
|
13
13
|
50,
|
|
14
14
|
120,
|
|
15
15
|
250,
|
|
16
|
-
400
|
|
17
|
-
|
|
16
|
+
400,
|
|
17
|
+
700,
|
|
18
|
+
1e3
|
|
19
|
+
], h = 3, g = 30, _ = l("div")(({ theme: e }) => ({
|
|
18
20
|
float: "right",
|
|
19
21
|
padding: e.spacing(.5),
|
|
20
22
|
borderRadius: "4px",
|
|
21
23
|
fontSize: "10px",
|
|
22
|
-
backgroundColor:
|
|
23
|
-
color:
|
|
24
|
-
border: `solid 1px ${
|
|
24
|
+
backgroundColor: f.defaults.WHITE,
|
|
25
|
+
color: f.defaults.CORRECT_WITH_ICON,
|
|
26
|
+
border: `solid 1px ${f.defaults.CORRECT_WITH_ICON}`
|
|
25
27
|
})), v = l("div")(({ theme: e }) => ({
|
|
26
28
|
float: "right",
|
|
27
29
|
padding: e.spacing(.5),
|
|
28
30
|
borderRadius: "4px",
|
|
29
31
|
fontSize: "10px",
|
|
30
|
-
backgroundColor:
|
|
31
|
-
color:
|
|
32
|
-
border: `solid 1px ${
|
|
32
|
+
backgroundColor: f.defaults.WHITE,
|
|
33
|
+
color: f.defaults.INCORRECT_WITH_ICON,
|
|
34
|
+
border: `solid 1px ${f.defaults.INCORRECT_WITH_ICON}`
|
|
33
35
|
})), y = l("div")(({ theme: e }) => ({
|
|
34
36
|
float: "right",
|
|
35
37
|
padding: e.spacing(.5),
|
|
36
38
|
borderRadius: "4px",
|
|
37
39
|
fontSize: "10px",
|
|
38
|
-
backgroundColor:
|
|
39
|
-
color:
|
|
40
|
-
border: `solid 1px ${
|
|
40
|
+
backgroundColor: f.defaults.WHITE,
|
|
41
|
+
color: f.defaults.MISSING_WITH_ICON,
|
|
42
|
+
border: `solid 1px ${f.defaults.MISSING_WITH_ICON}`,
|
|
41
43
|
fontWeight: "bold"
|
|
42
44
|
})), b = l("div")(() => ({
|
|
43
45
|
float: "right",
|
|
44
46
|
padding: 0,
|
|
45
47
|
borderRadius: "4px",
|
|
46
48
|
fontSize: "10px",
|
|
47
|
-
backgroundColor:
|
|
48
|
-
color:
|
|
49
|
+
backgroundColor: f.defaults.WHITE,
|
|
50
|
+
color: f.defaults.INCORRECT_WITH_ICON,
|
|
49
51
|
fontWeight: "bold"
|
|
50
52
|
})), x = (e, t, n) => ({
|
|
51
53
|
float: "right",
|
|
52
54
|
padding: e.spacing(.5),
|
|
53
55
|
fontFamily: e.typography.fontFamily,
|
|
54
56
|
fontSize: "10px",
|
|
55
|
-
border: t ? `solid 1px ${
|
|
57
|
+
border: t ? `solid 1px ${f.defaults.PRIMARY_DARK}` : n ? `solid 1px ${f.disabled()}` : `solid 1px ${f.defaults.SECONDARY}`,
|
|
56
58
|
borderRadius: "3px",
|
|
57
|
-
color: n ?
|
|
58
|
-
backgroundColor:
|
|
59
|
+
color: n ? f.disabled() : f.defaults.PRIMARY_DARK,
|
|
60
|
+
backgroundColor: f.defaults.WHITE,
|
|
59
61
|
WebkitOpacity: t ? "1" : void 0,
|
|
60
|
-
WebkitTextFillColor: n ?
|
|
61
|
-
}),
|
|
62
|
+
WebkitTextFillColor: n ? f.disabled() : void 0
|
|
63
|
+
}), re = () => ({
|
|
62
64
|
padding: "0",
|
|
63
65
|
border: "none",
|
|
64
66
|
color: "inherit",
|
|
65
67
|
fontWeight: "bold"
|
|
66
|
-
}),
|
|
68
|
+
}), S = (e, t, n = {
|
|
67
69
|
width: 0,
|
|
68
70
|
height: 0
|
|
69
71
|
}) => {
|
|
70
72
|
let { scale: r, domain: i, range: a } = e, o = r.x(t.x) + n.width + 5, s = r.y(t.y) + n.height + 5, c = o >= r.x(i.max) ? "left" : "right";
|
|
71
73
|
return `${s >= r.y(a.min) ? "top" : "bottom"}-${c}`;
|
|
72
|
-
},
|
|
74
|
+
}, C = (e, t, n = {
|
|
73
75
|
width: 0,
|
|
74
76
|
height: 0
|
|
75
77
|
}, r) => {
|
|
@@ -93,15 +95,22 @@ var m = 500, h = 500, g = [
|
|
|
93
95
|
};
|
|
94
96
|
default: return {};
|
|
95
97
|
}
|
|
96
|
-
},
|
|
98
|
+
}, w = (e) => {
|
|
99
|
+
if (typeof document > "u" || !document.getSelection) return !0;
|
|
100
|
+
let t = document.getSelection();
|
|
101
|
+
if (!t || !t.rangeCount || !t.anchorNode) return !1;
|
|
102
|
+
let n = t.anchorNode;
|
|
103
|
+
return n === e || n === e.parentNode || e.contains(n);
|
|
104
|
+
}, T = ({ _ref: t, externalInputRef: n, label: r, disabled: i, inputStyle: a, minWidth: o, onChange: s, onBlur: c }) => /* @__PURE__ */ u(e, {
|
|
97
105
|
inputRef: (e) => {
|
|
98
106
|
t(e), n(e);
|
|
99
107
|
},
|
|
100
108
|
disabled: i,
|
|
101
109
|
inputStyle: a,
|
|
110
|
+
minWidth: o,
|
|
102
111
|
value: r,
|
|
103
|
-
onChange:
|
|
104
|
-
onBlur:
|
|
112
|
+
onChange: s,
|
|
113
|
+
onBlur: c
|
|
105
114
|
});
|
|
106
115
|
T.propTypes = {
|
|
107
116
|
_ref: s.func,
|
|
@@ -109,82 +118,94 @@ T.propTypes = {
|
|
|
109
118
|
label: s.string,
|
|
110
119
|
disabled: s.bool,
|
|
111
120
|
inputStyle: s.object,
|
|
121
|
+
minWidth: s.number,
|
|
112
122
|
onChange: s.func,
|
|
113
123
|
onBlur: s.func
|
|
114
124
|
};
|
|
115
125
|
var E = (e) => {
|
|
116
|
-
let s = a(null), [c, l] = o(null),
|
|
126
|
+
let s = a(null), [c, l] = o(null), f = r((e) => {
|
|
117
127
|
s.current = e, l(e);
|
|
118
|
-
}, []), E =
|
|
128
|
+
}, []), E = ee(), { mark: D, graphProps: O, disabled: k, autoFocus: A, inputRef: j } = e, [M, N] = o(D.label), { correctness: P, correctnesslabel: F, correctlabel: I } = D, L = () => !!s.current && typeof document < "u" && document.activeElement === s.current, R = a(D.label === "" && !k && !D.disabled), z = a(0), B = a(D.label), V = () => Date.now() < z.current && !(s.current && s.current.value), H = a(!1), U = a(!1), W = a(0), ie = (e) => N(e.target.value), G = (t) => {
|
|
119
129
|
t !== B.current && (B.current = t, e.onChange(t));
|
|
120
|
-
},
|
|
121
|
-
V() || (R.current = !1, M === "" ? e.onChange("") : M !== D.label &&
|
|
130
|
+
}, ae = r(() => {
|
|
131
|
+
V() || H.current || U.current || (R.current = !1, M === "" ? e.onChange("") : M !== D.label && G(M), e.onBlur && e.onBlur());
|
|
122
132
|
}, [
|
|
123
133
|
M,
|
|
124
134
|
D.label,
|
|
125
135
|
e.onChange,
|
|
126
136
|
e.onBlur
|
|
127
|
-
]),
|
|
137
|
+
]), K = t(M, ne);
|
|
128
138
|
i(() => {
|
|
129
139
|
L() || N(D.label);
|
|
130
140
|
}, [D.label]), i(() => {
|
|
131
|
-
typeof
|
|
132
|
-
}, [
|
|
133
|
-
let
|
|
141
|
+
typeof K == "string" && K !== D.label && G(K);
|
|
142
|
+
}, [K]);
|
|
143
|
+
let q = () => {
|
|
134
144
|
let e = s.current;
|
|
135
|
-
if (!A && !R.current && !V() || !e || e.disabled
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
e.
|
|
145
|
+
if (!A && !R.current && !V() || !e || e.disabled) return;
|
|
146
|
+
let t = L();
|
|
147
|
+
if (t || (e.focus(), L() && (R.current = !1)), !e.setSelectionRange) return;
|
|
148
|
+
let n = t && e.value, r = n ? e.selectionStart : (e.value || "").length, i = n ? e.selectionEnd : r;
|
|
149
|
+
w(e) || e.setSelectionRange(r, i), !(w(e) || W.current >= h) && (W.current += 1, U.current = !0, e.blur(), e.focus(), e.setSelectionRange(r, i), U.current = !1);
|
|
139
150
|
};
|
|
140
|
-
i(() =>
|
|
151
|
+
i(() => q()), i(() => {
|
|
141
152
|
if (!A && !R.current) return;
|
|
142
|
-
z.current ||= Date.now() +
|
|
143
|
-
let e =
|
|
153
|
+
z.current ||= Date.now() + p;
|
|
154
|
+
let e = m.map((e) => setTimeout(q, e));
|
|
144
155
|
return () => e.forEach((e) => clearTimeout(e));
|
|
156
|
+
}, [A]), i(() => {
|
|
157
|
+
let e = () => {
|
|
158
|
+
H.current = !0;
|
|
159
|
+
}, t = () => {
|
|
160
|
+
H.current && (H.current = !1, q());
|
|
161
|
+
};
|
|
162
|
+
return window.addEventListener("blur", e), window.addEventListener("focus", t), () => {
|
|
163
|
+
window.removeEventListener("blur", e), window.removeEventListener("focus", t);
|
|
164
|
+
};
|
|
145
165
|
}, [A]);
|
|
146
|
-
let
|
|
166
|
+
let J = c ? c.getBoundingClientRect() : {
|
|
147
167
|
width: 0,
|
|
148
168
|
height: 0
|
|
149
|
-
},
|
|
169
|
+
}, Y = C(O, D, J, S(O, D, J)), X = {
|
|
150
170
|
position: "fixed",
|
|
151
171
|
pointerEvents: "auto",
|
|
152
172
|
display: "flex",
|
|
153
173
|
alignItems: "center",
|
|
154
174
|
gap: "3px",
|
|
155
|
-
...
|
|
156
|
-
},
|
|
157
|
-
...
|
|
158
|
-
top:
|
|
159
|
-
}, Z = k || D.disabled, Q = (e, t) => /* @__PURE__ */
|
|
160
|
-
_ref:
|
|
175
|
+
...Y
|
|
176
|
+
}, oe = {
|
|
177
|
+
...X,
|
|
178
|
+
top: Y.top + 25
|
|
179
|
+
}, Z = k || D.disabled, Q = (e, t) => /* @__PURE__ */ u(T, {
|
|
180
|
+
_ref: f,
|
|
161
181
|
externalInputRef: j,
|
|
162
182
|
label: t,
|
|
163
183
|
disabled: Z,
|
|
164
184
|
inputStyle: e,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
185
|
+
minWidth: Z ? 1 : g,
|
|
186
|
+
onChange: ie,
|
|
187
|
+
onBlur: ae
|
|
188
|
+
}), $ = re();
|
|
189
|
+
return P === "correct" && F === "correct" && I ? /* @__PURE__ */ d(_, {
|
|
190
|
+
style: X,
|
|
191
|
+
children: [/* @__PURE__ */ u(n, { type: "correct" }), Q($, I)]
|
|
192
|
+
}) : P === "correct" && F === "correct" && !I ? null : P === "correct" && F === "incorrect" ? /* @__PURE__ */ d(te, { children: [/* @__PURE__ */ d(v, {
|
|
193
|
+
style: X,
|
|
194
|
+
children: [/* @__PURE__ */ u(n, { type: "incorrect" }), M === "" ? /* @__PURE__ */ u(n, {
|
|
174
195
|
type: "empty",
|
|
175
196
|
style: { marginLeft: "3px" }
|
|
176
197
|
}) : Q($, M)]
|
|
177
|
-
}), /* @__PURE__ */
|
|
178
|
-
style:
|
|
198
|
+
}), /* @__PURE__ */ u(y, {
|
|
199
|
+
style: oe,
|
|
179
200
|
children: Q($, I)
|
|
180
|
-
})] }) : P === "missing" ? /* @__PURE__ */
|
|
181
|
-
style:
|
|
201
|
+
})] }) : P === "missing" ? /* @__PURE__ */ u(y, {
|
|
202
|
+
style: X,
|
|
182
203
|
children: Q($, M)
|
|
183
|
-
}) : P === "incorrect" ? /* @__PURE__ */
|
|
184
|
-
style:
|
|
204
|
+
}) : P === "incorrect" ? /* @__PURE__ */ u(b, {
|
|
205
|
+
style: X,
|
|
185
206
|
children: Q($, M)
|
|
186
|
-
}) : Z && !M ? null : /* @__PURE__ */
|
|
187
|
-
style:
|
|
207
|
+
}) : Z && !M ? null : /* @__PURE__ */ u("div", {
|
|
208
|
+
style: X,
|
|
188
209
|
children: Q(x(E, k, D.disabled), M)
|
|
189
210
|
});
|
|
190
211
|
};
|
|
@@ -198,4 +219,4 @@ E.propTypes = {
|
|
|
198
219
|
mark: s.object
|
|
199
220
|
};
|
|
200
221
|
//#endregion
|
|
201
|
-
export { E as MarkLabel, E as default,
|
|
222
|
+
export { E as MarkLabel, E as default, C as coordinates, S as position };
|