@pie-lib/text-select 4.0.1-next.20261005000911 → 4.0.1-next.20261005003301
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/__tests__/token-select-keyboard.test.d.ts +1 -0
- package/dist/text-select.d.ts +1 -0
- package/dist/text-select.js +8 -6
- package/dist/token-select/index.d.ts +18 -0
- package/dist/token-select/index.js +229 -120
- package/dist/token-select/token.d.ts +3 -0
- package/dist/token-select/token.js +49 -34
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/text-select.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export default class TextSelect extends React.Component {
|
|
|
20
20
|
highlightChoices: PropTypes.Requireable<boolean>;
|
|
21
21
|
animationsDisabled: PropTypes.Requireable<boolean>;
|
|
22
22
|
maxNoOfSelections: PropTypes.Requireable<number>;
|
|
23
|
+
language: PropTypes.Requireable<string>;
|
|
23
24
|
};
|
|
24
25
|
change: any;
|
|
25
26
|
render(): React.JSX.Element;
|
package/dist/text-select.js
CHANGED
|
@@ -16,7 +16,8 @@ var s = o("@pie-lib:text-select"), c = class extends r.Component {
|
|
|
16
16
|
className: i.string,
|
|
17
17
|
highlightChoices: i.bool,
|
|
18
18
|
animationsDisabled: i.bool,
|
|
19
|
-
maxNoOfSelections: i.number
|
|
19
|
+
maxNoOfSelections: i.number,
|
|
20
|
+
language: i.string
|
|
20
21
|
};
|
|
21
22
|
change = (e) => {
|
|
22
23
|
let { onChange: t } = this.props;
|
|
@@ -26,9 +27,9 @@ var s = o("@pie-lib:text-select"), c = class extends r.Component {
|
|
|
26
27
|
})));
|
|
27
28
|
};
|
|
28
29
|
render() {
|
|
29
|
-
let { text: t, disabled: r, tokens: i, selectedTokens: o, className: c, highlightChoices: l, maxNoOfSelections: u, animationsDisabled: d } = this.props,
|
|
30
|
-
s("normalized: ",
|
|
31
|
-
let
|
|
30
|
+
let { text: t, disabled: r, tokens: i, selectedTokens: o, className: c, highlightChoices: l, maxNoOfSelections: u, animationsDisabled: d, language: f } = this.props, p = e(t, i);
|
|
31
|
+
s("normalized: ", p);
|
|
32
|
+
let m = p.map((e) => {
|
|
32
33
|
let t = o.findIndex((t) => t.start === e.start && t.end === e.end) !== -1, n = t ? e.correct : void 0, i = e.isMissing;
|
|
33
34
|
return {
|
|
34
35
|
...e,
|
|
@@ -41,11 +42,12 @@ var s = o("@pie-lib:text-select"), c = class extends r.Component {
|
|
|
41
42
|
return /* @__PURE__ */ a(n, {
|
|
42
43
|
highlightChoices: !r && l,
|
|
43
44
|
className: c,
|
|
44
|
-
tokens:
|
|
45
|
+
tokens: m,
|
|
45
46
|
disabled: r,
|
|
46
47
|
onChange: this.change,
|
|
47
48
|
maxNoOfSelections: u,
|
|
48
|
-
animationsDisabled: d
|
|
49
|
+
animationsDisabled: d,
|
|
50
|
+
language: f
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
};
|
|
@@ -13,21 +13,39 @@ export declare class TokenSelect extends React.Component {
|
|
|
13
13
|
highlightChoices: PropTypes.Requireable<boolean>;
|
|
14
14
|
animationsDisabled: PropTypes.Requireable<boolean>;
|
|
15
15
|
maxNoOfSelections: PropTypes.Requireable<number>;
|
|
16
|
+
language: PropTypes.Requireable<string>;
|
|
16
17
|
};
|
|
17
18
|
static defaultProps: {
|
|
18
19
|
highlightChoices: boolean;
|
|
19
20
|
maxNoOfSelections: number;
|
|
20
21
|
tokens: never[];
|
|
21
22
|
};
|
|
23
|
+
containerRef: React.RefObject<unknown>;
|
|
24
|
+
idPrefix: string;
|
|
25
|
+
activeIndex: undefined;
|
|
26
|
+
keyboardToggle: boolean;
|
|
27
|
+
operable: () => boolean;
|
|
22
28
|
selectedCount: () => any;
|
|
23
29
|
canSelectMore: any;
|
|
24
30
|
toggleToken: any;
|
|
31
|
+
toggleAt: any;
|
|
32
|
+
sequence: () => unknown[];
|
|
33
|
+
focusedToken: () => any;
|
|
34
|
+
syncTabStop: () => unknown;
|
|
35
|
+
onFocus: any;
|
|
36
|
+
onKeyDown: any;
|
|
37
|
+
componentDidMount(): void;
|
|
38
|
+
getSnapshotBeforeUpdate(): number | null | undefined;
|
|
39
|
+
componentDidUpdate(prevProps: any, prevState: any, focusedIndex: any): void;
|
|
40
|
+
groupName: () => string;
|
|
25
41
|
/**
|
|
26
42
|
* Build an HTML string so that non-selectable token text (which may contain arbitrary or even
|
|
27
43
|
* *partial* HTML — e.g. just an opening <table><tbody><tr><td> in one token and the matching
|
|
28
44
|
* closing tags in another) is preserved exactly as-is. Selectable Token components are
|
|
29
45
|
* serialised via renderToString; their Emotion class names are stable hashes so they match the
|
|
30
46
|
* CSS that the HiddenCssPrimer forces Emotion to inject into the document.
|
|
47
|
+
*
|
|
48
|
+
* Returns the descriptions the tokens reference alongside the HTML.
|
|
31
49
|
*/
|
|
32
50
|
generateTokensInHtml: any;
|
|
33
51
|
render(): React.JSX.Element;
|
|
@@ -2,23 +2,29 @@ import { Token as e, TokenTypes as t } from "./token.js";
|
|
|
2
2
|
import n from "react";
|
|
3
3
|
import r from "prop-types";
|
|
4
4
|
import { styled as i } from "@mui/material/styles";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import d from "
|
|
9
|
-
import
|
|
5
|
+
import { createUniqueId as a } from "@pie-lib/render-ui";
|
|
6
|
+
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
7
|
+
import { clone as l, isEqual as u } from "@pie-element/shared-lodash";
|
|
8
|
+
import { noSelect as d } from "@pie-lib/style-utils";
|
|
9
|
+
import f from "debug";
|
|
10
|
+
import { renderToString as p } from "react-dom/server";
|
|
11
|
+
import m from "@pie-lib/translator";
|
|
10
12
|
//#region src/token-select/index.tsx
|
|
11
|
-
var
|
|
13
|
+
var { translator: h } = m, g = f("@pie-lib:text-select:token-select"), _ = i("div")(() => ({
|
|
12
14
|
backgroundColor: "none",
|
|
13
15
|
whiteSpace: "pre",
|
|
14
|
-
...
|
|
16
|
+
...d(),
|
|
15
17
|
"& p": { whiteSpace: "break-spaces" }
|
|
16
|
-
})),
|
|
18
|
+
})), v = i("div")(() => ({
|
|
17
19
|
display: "none",
|
|
18
20
|
position: "absolute",
|
|
19
21
|
visibility: "hidden",
|
|
20
22
|
pointerEvents: "none"
|
|
21
|
-
})),
|
|
23
|
+
})), y = (e = "") => e.replace(/ /gi, "\xA0"), b = (e = "") => y(e).replace(/<\/p>\s*<p[^>]*>/gi, "\n\n").replace(/<br\s*\/?>/gi, "\n").replace(/<\/?(table|tbody|tr|td|p)[^>]*>/gi, ""), x = {
|
|
24
|
+
correct: "selectText.correctAnswerSelected",
|
|
25
|
+
incorrect: "selectText.incorrectSelection",
|
|
26
|
+
missing: "selectText.correctAnswerNotSelected"
|
|
27
|
+
}, S = (e) => e.correct === void 0 ? e.isMissing ? "missing" : void 0 : e.correct ? "correct" : "incorrect", C = (e) => e.text === "\n\n" || e.text === "\n", w = "[data-indexkey][tabindex]", T = (e) => e ? Number(e.dataset.indexkey) : void 0, E = class extends n.Component {
|
|
22
28
|
static propTypes = {
|
|
23
29
|
tokens: r.arrayOf(r.shape(t)).isRequired,
|
|
24
30
|
className: r.string,
|
|
@@ -26,145 +32,248 @@ var p = d("@pie-lib:text-select:token-select"), m = i("div")(() => ({
|
|
|
26
32
|
disabled: r.bool,
|
|
27
33
|
highlightChoices: r.bool,
|
|
28
34
|
animationsDisabled: r.bool,
|
|
29
|
-
maxNoOfSelections: r.number
|
|
35
|
+
maxNoOfSelections: r.number,
|
|
36
|
+
language: r.string
|
|
30
37
|
};
|
|
31
38
|
static defaultProps = {
|
|
32
39
|
highlightChoices: !1,
|
|
33
40
|
maxNoOfSelections: 0,
|
|
34
41
|
tokens: []
|
|
35
42
|
};
|
|
43
|
+
containerRef = n.createRef();
|
|
44
|
+
idPrefix = a("text-select");
|
|
45
|
+
activeIndex = void 0;
|
|
46
|
+
keyboardToggle = !1;
|
|
47
|
+
operable = () => !this.props.disabled && !this.props.animationsDisabled;
|
|
36
48
|
selectedCount = () => this.props.tokens.filter((e) => e.selected).length;
|
|
37
49
|
canSelectMore = (e) => {
|
|
38
50
|
let { maxNoOfSelections: t } = this.props;
|
|
39
|
-
return t === 1 ? !0 : (
|
|
51
|
+
return t === 1 ? !0 : (g("[canSelectMore] maxNoOfSelections: ", t, "selectedCount: ", e), t <= 0 || isFinite(t) && e < t);
|
|
40
52
|
};
|
|
41
53
|
toggleToken = (t) => {
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
let n = (t.target.closest?.(`.${e.rootClassName}`))?.dataset?.indexkey;
|
|
55
|
+
n !== void 0 && (this.keyboardToggle = !1, this.toggleAt(Number(n)));
|
|
56
|
+
};
|
|
57
|
+
toggleAt = (e) => {
|
|
58
|
+
let { tokens: t, animationsDisabled: n } = this.props, r = l(t), i = r[e];
|
|
59
|
+
if (this.operable() && i && i.correct === void 0 && !n && !i.isMissing) {
|
|
60
|
+
let { onChange: n, maxNoOfSelections: a } = this.props, o = !i.selected;
|
|
61
|
+
if (a === 1 && this.selectedCount() === 1) {
|
|
62
|
+
let a = (t || []).filter((e) => e.selected), s = r.map((e) => u(e, a[0]) ? {
|
|
47
63
|
...e,
|
|
48
64
|
selected: !1
|
|
49
65
|
} : {
|
|
50
66
|
...e,
|
|
51
67
|
selectable: !0
|
|
52
68
|
}), c = {
|
|
53
|
-
...
|
|
54
|
-
selected:
|
|
69
|
+
...i,
|
|
70
|
+
selected: o
|
|
55
71
|
};
|
|
56
|
-
|
|
72
|
+
s.splice(e, 1, c), n(s);
|
|
57
73
|
} else {
|
|
58
|
-
if (
|
|
59
|
-
|
|
74
|
+
if (o && a > 0 && this.selectedCount() >= a) {
|
|
75
|
+
g("skip toggle max reached");
|
|
60
76
|
return;
|
|
61
77
|
}
|
|
62
|
-
let
|
|
63
|
-
...
|
|
64
|
-
selected:
|
|
78
|
+
let t = {
|
|
79
|
+
...i,
|
|
80
|
+
selected: o
|
|
65
81
|
};
|
|
66
|
-
|
|
82
|
+
r.splice(e, 1, t), n(r);
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
};
|
|
86
|
+
sequence = () => Array.from(this.containerRef.current?.querySelectorAll(w) || []);
|
|
87
|
+
focusedToken = () => {
|
|
88
|
+
let e = this.containerRef.current, t = e?.getRootNode().activeElement;
|
|
89
|
+
return t && e.contains(t) ? t.closest(w) : null;
|
|
90
|
+
};
|
|
91
|
+
syncTabStop = () => {
|
|
92
|
+
let e = this.sequence(), t = e.find((e) => T(e) === this.activeIndex) || e.find((e) => e.getAttribute("aria-pressed") === "true") || e[0];
|
|
93
|
+
return e.forEach((e) => {
|
|
94
|
+
let n = e === t ? "0" : "-1";
|
|
95
|
+
e.getAttribute("tabindex") !== n && e.setAttribute("tabindex", n);
|
|
96
|
+
}), t;
|
|
97
|
+
};
|
|
98
|
+
onFocus = (e) => {
|
|
99
|
+
let t = e.target.closest?.(w);
|
|
100
|
+
t && (this.activeIndex = T(t), this.syncTabStop());
|
|
101
|
+
};
|
|
102
|
+
onKeyDown = (e) => {
|
|
103
|
+
if (!this.operable() || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
104
|
+
let t = e.target.closest?.(w);
|
|
105
|
+
if (!t) return;
|
|
106
|
+
if (e.key === " " || e.key === "Enter") {
|
|
107
|
+
e.preventDefault(), !e.repeat && t.getAttribute("aria-disabled") !== "true" && (this.keyboardToggle = !0, this.toggleAt(T(t)));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let n = this.sequence(), r = n.indexOf(t), i = n.length - 1, a = {
|
|
111
|
+
ArrowRight: Math.min(r + 1, i),
|
|
112
|
+
ArrowDown: Math.min(r + 1, i),
|
|
113
|
+
ArrowLeft: Math.max(r - 1, 0),
|
|
114
|
+
ArrowUp: Math.max(r - 1, 0),
|
|
115
|
+
Home: 0,
|
|
116
|
+
End: i
|
|
117
|
+
}[e.key];
|
|
118
|
+
a !== void 0 && (e.preventDefault(), n[a].focus());
|
|
119
|
+
};
|
|
120
|
+
componentDidMount() {
|
|
121
|
+
this.syncTabStop();
|
|
122
|
+
}
|
|
123
|
+
getSnapshotBeforeUpdate() {
|
|
124
|
+
let e = this.focusedToken();
|
|
125
|
+
return e ? T(e) : null;
|
|
126
|
+
}
|
|
127
|
+
componentDidUpdate(e, t, n) {
|
|
128
|
+
let r = this.syncTabStop();
|
|
129
|
+
n == null || this.focusedToken() || (this.sequence().find((e) => T(e) === n) || r)?.focus({
|
|
130
|
+
preventScroll: !0,
|
|
131
|
+
focusVisible: this.keyboardToggle
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
groupName = () => {
|
|
135
|
+
let { maxNoOfSelections: e, language: t } = this.props;
|
|
136
|
+
return e > 0 ? h.t("selectText.textGroupWithLimit", {
|
|
137
|
+
lng: t,
|
|
138
|
+
max: e
|
|
139
|
+
}) : h.t("selectText.textGroup", { lng: t });
|
|
140
|
+
};
|
|
70
141
|
generateTokensInHtml = () => {
|
|
71
|
-
let { tokens: t, disabled: n, highlightChoices: r, animationsDisabled: i } = this.props,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
142
|
+
let { tokens: t, disabled: n, highlightChoices: r, animationsDisabled: i, language: a } = this.props, o = this.selectedCount(), c = this.operable(), l = {}, u = (e) => c && !C(e) && (e.selected || e.selectable), d = (t || []).filter(u).length, f = 0, m = (e, t) => {
|
|
143
|
+
let n = `${this.idPrefix}-${e}`;
|
|
144
|
+
return l[n] = t, n;
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
html: (t || []).reduce((t, c, l) => {
|
|
148
|
+
let g = c.selected || c.selectable && this.canSelectMore(o), _ = c.correct !== void 0 && (c.selectable || c.selected);
|
|
149
|
+
if (c.text === "\n\n") return `${t}</p><p>`;
|
|
150
|
+
if (c.text === "\n") return `${t}<br>`;
|
|
151
|
+
if (u(c) || g && !n || _ || c.selected || c.isMissing || i && c.predefined) {
|
|
152
|
+
let o = u(c), _;
|
|
153
|
+
if (o) f += 1, _ = m(`position-${f}`, h.t("selectText.tokenPosition", {
|
|
154
|
+
lng: a,
|
|
155
|
+
index: f,
|
|
156
|
+
total: d
|
|
157
|
+
}));
|
|
158
|
+
else {
|
|
159
|
+
let e = S(c);
|
|
160
|
+
e && (_ = m(e, h.t(x[e], { lng: a })));
|
|
161
|
+
}
|
|
162
|
+
return t + p(/* @__PURE__ */ s(e, {
|
|
163
|
+
disabled: n,
|
|
164
|
+
index: l,
|
|
165
|
+
...c,
|
|
166
|
+
text: b(c.text),
|
|
167
|
+
selectable: g,
|
|
168
|
+
highlight: r,
|
|
169
|
+
animationsDisabled: i,
|
|
170
|
+
operable: o,
|
|
171
|
+
describedBy: _
|
|
172
|
+
}, l));
|
|
173
|
+
}
|
|
174
|
+
return t + y(c.text);
|
|
175
|
+
}, "<p>") + "</p>",
|
|
176
|
+
descriptions: l
|
|
177
|
+
};
|
|
84
178
|
};
|
|
85
179
|
render() {
|
|
86
|
-
let { className: t } = this.props, n = this.generateTokensInHtml();
|
|
87
|
-
return /* @__PURE__ */
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
let { className: t } = this.props, { html: n, descriptions: r } = this.generateTokensInHtml();
|
|
181
|
+
return /* @__PURE__ */ c(o, { children: [
|
|
182
|
+
/* @__PURE__ */ c(v, {
|
|
183
|
+
"aria-hidden": "true",
|
|
184
|
+
children: [
|
|
185
|
+
/* @__PURE__ */ s(e, {
|
|
186
|
+
text: " ",
|
|
187
|
+
index: -1,
|
|
188
|
+
selectable: !0,
|
|
189
|
+
disabled: !1,
|
|
190
|
+
highlight: !1,
|
|
191
|
+
animationsDisabled: !1
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ s(e, {
|
|
194
|
+
text: " ",
|
|
195
|
+
index: -1,
|
|
196
|
+
selectable: !0,
|
|
197
|
+
disabled: !1,
|
|
198
|
+
highlight: !0,
|
|
199
|
+
animationsDisabled: !1
|
|
200
|
+
}),
|
|
201
|
+
/* @__PURE__ */ s(e, {
|
|
202
|
+
text: " ",
|
|
203
|
+
index: -1,
|
|
204
|
+
selectable: !0,
|
|
205
|
+
selected: !0,
|
|
206
|
+
disabled: !1,
|
|
207
|
+
highlight: !1,
|
|
208
|
+
animationsDisabled: !1
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ s(e, {
|
|
211
|
+
text: " ",
|
|
212
|
+
index: -1,
|
|
213
|
+
selectable: !0,
|
|
214
|
+
selected: !0,
|
|
215
|
+
disabled: !0,
|
|
216
|
+
highlight: !1,
|
|
217
|
+
animationsDisabled: !1
|
|
218
|
+
}),
|
|
219
|
+
/* @__PURE__ */ s(e, {
|
|
220
|
+
text: " ",
|
|
221
|
+
index: -1,
|
|
222
|
+
selectable: !0,
|
|
223
|
+
disabled: !1,
|
|
224
|
+
highlight: !1,
|
|
225
|
+
animationsDisabled: !0,
|
|
226
|
+
predefined: !0
|
|
227
|
+
}),
|
|
228
|
+
/* @__PURE__ */ s(e, {
|
|
229
|
+
text: " ",
|
|
230
|
+
index: -1,
|
|
231
|
+
selectable: !0,
|
|
232
|
+
selected: !0,
|
|
233
|
+
correct: !0,
|
|
234
|
+
disabled: !1,
|
|
235
|
+
highlight: !1,
|
|
236
|
+
animationsDisabled: !1
|
|
237
|
+
}),
|
|
238
|
+
/* @__PURE__ */ s(e, {
|
|
239
|
+
text: " ",
|
|
240
|
+
index: -1,
|
|
241
|
+
selectable: !0,
|
|
242
|
+
selected: !0,
|
|
243
|
+
correct: !1,
|
|
244
|
+
disabled: !1,
|
|
245
|
+
highlight: !1,
|
|
246
|
+
animationsDisabled: !1
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ s(e, {
|
|
249
|
+
text: " ",
|
|
250
|
+
index: -1,
|
|
251
|
+
isMissing: !0,
|
|
252
|
+
disabled: !1,
|
|
253
|
+
highlight: !1,
|
|
254
|
+
animationsDisabled: !1
|
|
255
|
+
})
|
|
256
|
+
]
|
|
257
|
+
}),
|
|
258
|
+
/* @__PURE__ */ s(_, {
|
|
259
|
+
ref: this.containerRef,
|
|
260
|
+
className: t,
|
|
261
|
+
role: "group",
|
|
262
|
+
"aria-label": this.groupName(),
|
|
263
|
+
onClick: this.toggleToken,
|
|
264
|
+
onKeyDown: this.onKeyDown,
|
|
265
|
+
onFocus: this.onFocus,
|
|
266
|
+
dangerouslySetInnerHTML: { __html: n }
|
|
267
|
+
}),
|
|
268
|
+
Object.keys(r).length > 0 && /* @__PURE__ */ s("div", {
|
|
269
|
+
hidden: !0,
|
|
270
|
+
children: Object.entries(r).map(([e, t]) => /* @__PURE__ */ s("span", {
|
|
271
|
+
id: e,
|
|
272
|
+
children: t
|
|
273
|
+
}, e))
|
|
274
|
+
})
|
|
275
|
+
] });
|
|
167
276
|
}
|
|
168
277
|
};
|
|
169
278
|
//#endregion
|
|
170
|
-
export {
|
|
279
|
+
export { E as TokenSelect, E as default, t as TokenTypes };
|
|
@@ -12,10 +12,13 @@ export declare class Token extends React.Component {
|
|
|
12
12
|
disabled: PropTypes.Requireable<boolean>;
|
|
13
13
|
highlight: PropTypes.Requireable<boolean>;
|
|
14
14
|
correct: PropTypes.Requireable<boolean>;
|
|
15
|
+
operable: PropTypes.Requireable<boolean>;
|
|
16
|
+
describedBy: PropTypes.Requireable<string>;
|
|
15
17
|
selectable: PropTypes.Requireable<boolean>;
|
|
16
18
|
};
|
|
17
19
|
static defaultProps: {
|
|
18
20
|
selectable: boolean;
|
|
21
|
+
operable: boolean;
|
|
19
22
|
text: string;
|
|
20
23
|
};
|
|
21
24
|
getClassAndIconConfig: any;
|
|
@@ -7,9 +7,16 @@ import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
|
7
7
|
import s from "@mui/icons-material/Check";
|
|
8
8
|
import c from "@mui/icons-material/Close";
|
|
9
9
|
//#region src/token-select/token.tsx
|
|
10
|
-
var l = 3.2, u = 3.4, d = 2, f = r("span")(({ theme: e }) => ({
|
|
10
|
+
var l = 3.2, u = 3.4, d = 2, f = () => i.v("pie")("focus-outline", "button-focus-outline", "focus-checked-border", i.defaults.FOCUS_CHECKED_BORDER), p = r("span")(({ theme: e }) => ({
|
|
11
11
|
cursor: "pointer",
|
|
12
12
|
textIndent: 0,
|
|
13
|
+
"&:focus:not(:focus-visible)": { outline: "none" },
|
|
14
|
+
"&:focus-visible": {
|
|
15
|
+
outline: `3px solid ${f()}`,
|
|
16
|
+
outlineOffset: "2px",
|
|
17
|
+
borderRadius: "4px"
|
|
18
|
+
},
|
|
19
|
+
"&.unavailable": { cursor: "inherit" },
|
|
13
20
|
"&.disabled": {
|
|
14
21
|
cursor: "inherit",
|
|
15
22
|
color: i.disabled()
|
|
@@ -44,13 +51,13 @@ var l = 3.2, u = 3.4, d = 2, f = r("span")(({ theme: e }) => ({
|
|
|
44
51
|
color: i.text()
|
|
45
52
|
},
|
|
46
53
|
"&.custom": { display: "initial" }
|
|
47
|
-
})),
|
|
54
|
+
})), m = r("span")(({ theme: e }) => ({
|
|
48
55
|
position: "relative",
|
|
49
56
|
borderRadius: "4px",
|
|
50
57
|
color: i.text(),
|
|
51
58
|
lineHeight: `${parseFloat(e.spacing(1)) * u + d}px`,
|
|
52
59
|
padding: `${d}px`
|
|
53
|
-
})),
|
|
60
|
+
})), h = r(m)(() => ({ border: `${i.correctTertiary()} solid 2px` })), g = r(m)(() => ({ border: `${i.incorrectWithIcon()} solid 2px` })), _ = r(m)(() => ({ border: `${i.incorrectWithIcon()} dashed 2px` })), v = {
|
|
54
61
|
color: i.white(),
|
|
55
62
|
position: "absolute",
|
|
56
63
|
top: "-8px",
|
|
@@ -59,76 +66,84 @@ var l = 3.2, u = 3.4, d = 2, f = r("span")(({ theme: e }) => ({
|
|
|
59
66
|
fontSize: "12px",
|
|
60
67
|
padding: "2px",
|
|
61
68
|
display: "inline-block"
|
|
62
|
-
},
|
|
63
|
-
...
|
|
69
|
+
}, y = r(s)(() => ({
|
|
70
|
+
...v,
|
|
64
71
|
backgroundColor: i.correctTertiary()
|
|
65
|
-
})),
|
|
66
|
-
...
|
|
72
|
+
})), b = r(c)(() => ({
|
|
73
|
+
...v,
|
|
67
74
|
backgroundColor: i.incorrectWithIcon()
|
|
68
|
-
})),
|
|
69
|
-
|
|
75
|
+
})), x = ({ useWrapper: e, children: t, Container: n, Icon: r }) => e ? /* @__PURE__ */ o(n, { children: [t, r ? /* @__PURE__ */ a(r, {}) : null] }) : t;
|
|
76
|
+
x.propTypes = {
|
|
70
77
|
useWrapper: n.bool,
|
|
71
78
|
Container: n.elementType,
|
|
72
79
|
Icon: n.elementType,
|
|
73
80
|
children: n.node
|
|
74
81
|
};
|
|
75
|
-
var
|
|
82
|
+
var S = {
|
|
76
83
|
text: n.string,
|
|
77
84
|
selectable: n.bool
|
|
78
|
-
},
|
|
85
|
+
}, C = class r extends t.Component {
|
|
79
86
|
static rootClassName = "tokenRootClass";
|
|
80
87
|
static propTypes = {
|
|
81
|
-
...
|
|
88
|
+
...S,
|
|
82
89
|
text: n.string.isRequired,
|
|
83
90
|
className: n.string,
|
|
84
91
|
disabled: n.bool,
|
|
85
92
|
highlight: n.bool,
|
|
86
|
-
correct: n.bool
|
|
93
|
+
correct: n.bool,
|
|
94
|
+
operable: n.bool,
|
|
95
|
+
describedBy: n.string
|
|
87
96
|
};
|
|
88
97
|
static defaultProps = {
|
|
89
98
|
selectable: !1,
|
|
99
|
+
operable: !1,
|
|
90
100
|
text: ""
|
|
91
101
|
};
|
|
92
102
|
getClassAndIconConfig = () => {
|
|
93
|
-
let { selectable: t, selected: n, className: i, disabled: a, highlight: o, correct: s, animationsDisabled: c, isMissing: l } = this.props,
|
|
103
|
+
let { selectable: t, selected: n, className: i, disabled: a, highlight: o, correct: s, animationsDisabled: c, isMissing: l, operable: u } = this.props, d = "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0, f = r.rootClassName;
|
|
94
104
|
if (s === void 0 && n && a) return {
|
|
95
|
-
className: e(
|
|
96
|
-
Component:
|
|
105
|
+
className: e(f, "selectedToken", "disabledBlack", i),
|
|
106
|
+
Component: p
|
|
97
107
|
};
|
|
98
108
|
if (s !== void 0) {
|
|
99
109
|
let t = s === !0;
|
|
100
110
|
return {
|
|
101
|
-
className: e(
|
|
102
|
-
Component:
|
|
103
|
-
Container: t ?
|
|
104
|
-
Icon: t ?
|
|
111
|
+
className: e(f, "custom", i),
|
|
112
|
+
Component: p,
|
|
113
|
+
Container: t ? h : g,
|
|
114
|
+
Icon: t ? y : b
|
|
105
115
|
};
|
|
106
116
|
}
|
|
107
117
|
return l ? {
|
|
108
|
-
className: e(
|
|
109
|
-
Component:
|
|
110
|
-
Container:
|
|
111
|
-
Icon:
|
|
118
|
+
className: e(f, "custom", "missing", i),
|
|
119
|
+
Component: p,
|
|
120
|
+
Container: _,
|
|
121
|
+
Icon: b
|
|
112
122
|
} : {
|
|
113
|
-
className: e(
|
|
114
|
-
Component:
|
|
123
|
+
className: e(f, a && "disabled", t && !a && !d && "selectableToken", n && !a && "selectedToken", n && a && "disabledAndSelected", o && t && !a && !n && "highlight", u && !t && !n && "unavailable", c && "print", i),
|
|
124
|
+
Component: p,
|
|
115
125
|
Container: void 0,
|
|
116
126
|
Icon: void 0
|
|
117
127
|
};
|
|
118
128
|
};
|
|
119
129
|
render() {
|
|
120
|
-
let { text: e, index: t, correct: n, isMissing: r } = this.props, { className:
|
|
121
|
-
return /* @__PURE__ */ a(
|
|
130
|
+
let { text: e, index: t, correct: n, isMissing: r, selected: i, selectable: o, operable: s, describedBy: c } = this.props, { className: l, Component: u, Container: d, Icon: f } = this.getClassAndIconConfig(), m = u || p, h = s && (o || i);
|
|
131
|
+
return /* @__PURE__ */ a(x, {
|
|
122
132
|
useWrapper: n !== void 0 || r,
|
|
123
|
-
Container:
|
|
124
|
-
Icon:
|
|
125
|
-
children: /* @__PURE__ */ a(
|
|
126
|
-
className:
|
|
133
|
+
Container: d,
|
|
134
|
+
Icon: f,
|
|
135
|
+
children: /* @__PURE__ */ a(m, {
|
|
136
|
+
className: l,
|
|
127
137
|
dangerouslySetInnerHTML: { __html: (e || "").replace(/\n/g, "<br>") },
|
|
128
|
-
"data-indexkey": t
|
|
138
|
+
"data-indexkey": t,
|
|
139
|
+
role: "button",
|
|
140
|
+
"aria-pressed": !!i,
|
|
141
|
+
"aria-disabled": !h || void 0,
|
|
142
|
+
"aria-describedby": c || void 0,
|
|
143
|
+
tabIndex: s ? -1 : void 0
|
|
129
144
|
})
|
|
130
145
|
});
|
|
131
146
|
}
|
|
132
147
|
};
|
|
133
148
|
//#endregion
|
|
134
|
-
export {
|
|
149
|
+
export { C as Token, C as default, S as TokenTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/text-select",
|
|
3
|
-
"version": "4.0.1-next.
|
|
3
|
+
"version": "4.0.1-next.20261005003301",
|
|
4
4
|
"description": "Some react components for text selection",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"@mui/icons-material": "^7.3.4",
|
|
14
14
|
"@mui/material": "^7.3.4",
|
|
15
15
|
"@pie-framework/parse-english": "^1.0.0",
|
|
16
|
-
"@pie-lib/render-ui": "8.0.1-next.
|
|
16
|
+
"@pie-lib/render-ui": "8.0.1-next.20261005003301",
|
|
17
17
|
"@pie-lib/style-utils": "3.0.1-next.20261002233132",
|
|
18
|
-
"@pie-lib/translator": "5.0.1-next.
|
|
18
|
+
"@pie-lib/translator": "5.0.1-next.20261005003301",
|
|
19
19
|
"debug": "^4.1.1",
|
|
20
20
|
"prop-types": "^15.6.2",
|
|
21
21
|
"@pie-element/shared-lodash": "0.1.2-next.20261002215153",
|