@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.
@@ -0,0 +1 @@
1
+ export {};
@@ -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;
@@ -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, f = e(t, i);
30
- s("normalized: ", f);
31
- let p = f.map((e) => {
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: p,
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 { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
6
- import { clone as c, isEqual as l } from "@pie-element/shared-lodash";
7
- import { noSelect as u } from "@pie-lib/style-utils";
8
- import d from "debug";
9
- import { renderToString as f } from "react-dom/server";
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 p = d("@pie-lib:text-select:token-select"), m = i("div")(() => ({
13
+ var { translator: h } = m, g = f("@pie-lib:text-select:token-select"), _ = i("div")(() => ({
12
14
  backgroundColor: "none",
13
15
  whiteSpace: "pre",
14
- ...u(),
16
+ ...d(),
15
17
  "& p": { whiteSpace: "break-spaces" }
16
- })), h = i("div")(() => ({
18
+ })), v = i("div")(() => ({
17
19
  display: "none",
18
20
  position: "absolute",
19
21
  visibility: "hidden",
20
22
  pointerEvents: "none"
21
- })), g = (e = "") => e.replace(/&nbsp;/gi, "\xA0"), _ = (e = "") => g(e).replace(/<\/p>\s*<p[^>]*>/gi, "\n\n").replace(/<br\s*\/?>/gi, "\n").replace(/<\/?(table|tbody|tr|td|p)[^>]*>/gi, ""), v = class extends n.Component {
23
+ })), y = (e = "") => e.replace(/&nbsp;/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 : (p("[canSelectMore] maxNoOfSelections: ", t, "selectedCount: ", e), t <= 0 || isFinite(t) && e < t);
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 { target: n } = t, { tokens: r, animationsDisabled: i } = this.props, a = c(r), o = (n.closest?.(`.${e.rootClassName}`))?.dataset?.indexkey, s = o === void 0 ? void 0 : a[o];
43
- if (s && s.correct === void 0 && !i && !s.isMissing) {
44
- let { onChange: e, maxNoOfSelections: t } = this.props, n = !s.selected;
45
- if (t === 1 && this.selectedCount() === 1) {
46
- let t = (r || []).filter((e) => e.selected), i = a.map((e) => l(e, t[0]) ? {
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
- ...s,
54
- selected: n
69
+ ...i,
70
+ selected: o
55
71
  };
56
- i.splice(o, 1, c), e(i);
72
+ s.splice(e, 1, c), n(s);
57
73
  } else {
58
- if (n && t > 0 && this.selectedCount() >= t) {
59
- p("skip toggle max reached");
74
+ if (o && a > 0 && this.selectedCount() >= a) {
75
+ g("skip toggle max reached");
60
76
  return;
61
77
  }
62
- let r = {
63
- ...s,
64
- selected: n
78
+ let t = {
79
+ ...i,
80
+ selected: o
65
81
  };
66
- a.splice(o, 1, r), e(a);
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, a = this.selectedCount();
72
- return (t || []).reduce((t, s, c) => {
73
- let l = s.selected || s.selectable && this.canSelectMore(a), u = s.correct !== void 0 && (s.selectable || s.selected);
74
- return s.text === "\n\n" ? `${t}</p><p>` : s.text === "\n" ? `${t}<br>` : l && !n || u || s.selected || s.isMissing || i && s.predefined ? t + f(/* @__PURE__ */ o(e, {
75
- disabled: n,
76
- index: c,
77
- ...s,
78
- text: _(s.text),
79
- selectable: l,
80
- highlight: r,
81
- animationsDisabled: i
82
- }, c)) : t + g(s.text);
83
- }, "<p>") + "</p>";
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__ */ s(a, { children: [/* @__PURE__ */ s(h, {
88
- "aria-hidden": "true",
89
- children: [
90
- /* @__PURE__ */ o(e, {
91
- text: " ",
92
- index: -1,
93
- selectable: !0,
94
- disabled: !1,
95
- highlight: !1,
96
- animationsDisabled: !1
97
- }),
98
- /* @__PURE__ */ o(e, {
99
- text: " ",
100
- index: -1,
101
- selectable: !0,
102
- disabled: !1,
103
- highlight: !0,
104
- animationsDisabled: !1
105
- }),
106
- /* @__PURE__ */ o(e, {
107
- text: " ",
108
- index: -1,
109
- selectable: !0,
110
- selected: !0,
111
- disabled: !1,
112
- highlight: !1,
113
- animationsDisabled: !1
114
- }),
115
- /* @__PURE__ */ o(e, {
116
- text: " ",
117
- index: -1,
118
- selectable: !0,
119
- selected: !0,
120
- disabled: !0,
121
- highlight: !1,
122
- animationsDisabled: !1
123
- }),
124
- /* @__PURE__ */ o(e, {
125
- text: " ",
126
- index: -1,
127
- selectable: !0,
128
- disabled: !1,
129
- highlight: !1,
130
- animationsDisabled: !0,
131
- predefined: !0
132
- }),
133
- /* @__PURE__ */ o(e, {
134
- text: " ",
135
- index: -1,
136
- selectable: !0,
137
- selected: !0,
138
- correct: !0,
139
- disabled: !1,
140
- highlight: !1,
141
- animationsDisabled: !1
142
- }),
143
- /* @__PURE__ */ o(e, {
144
- text: " ",
145
- index: -1,
146
- selectable: !0,
147
- selected: !0,
148
- correct: !1,
149
- disabled: !1,
150
- highlight: !1,
151
- animationsDisabled: !1
152
- }),
153
- /* @__PURE__ */ o(e, {
154
- text: " ",
155
- index: -1,
156
- isMissing: !0,
157
- disabled: !1,
158
- highlight: !1,
159
- animationsDisabled: !1
160
- })
161
- ]
162
- }), /* @__PURE__ */ o(m, {
163
- className: t,
164
- onClick: this.toggleToken,
165
- dangerouslySetInnerHTML: { __html: n }
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 { v as TokenSelect, v as default, t as TokenTypes };
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
- })), p = r("span")(({ theme: e }) => ({
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
- })), m = r(p)(() => ({ border: `${i.correctTertiary()} solid 2px` })), h = r(p)(() => ({ border: `${i.incorrectWithIcon()} solid 2px` })), g = r(p)(() => ({ border: `${i.incorrectWithIcon()} dashed 2px` })), _ = {
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
- }, v = r(s)(() => ({
63
- ..._,
69
+ }, y = r(s)(() => ({
70
+ ...v,
64
71
  backgroundColor: i.correctTertiary()
65
- })), y = r(c)(() => ({
66
- ..._,
72
+ })), b = r(c)(() => ({
73
+ ...v,
67
74
  backgroundColor: i.incorrectWithIcon()
68
- })), b = ({ useWrapper: e, children: t, Container: n, Icon: r }) => e ? /* @__PURE__ */ o(n, { children: [t, r ? /* @__PURE__ */ a(r, {}) : null] }) : t;
69
- b.propTypes = {
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 x = {
82
+ var S = {
76
83
  text: n.string,
77
84
  selectable: n.bool
78
- }, S = class r extends t.Component {
85
+ }, C = class r extends t.Component {
79
86
  static rootClassName = "tokenRootClass";
80
87
  static propTypes = {
81
- ...x,
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, u = "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0, d = r.rootClassName;
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(d, "selectedToken", "disabledBlack", i),
96
- Component: f
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(d, "custom", i),
102
- Component: f,
103
- Container: t ? m : h,
104
- Icon: t ? v : y
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(d, "custom", "missing", i),
109
- Component: f,
110
- Container: g,
111
- Icon: y
118
+ className: e(f, "custom", "missing", i),
119
+ Component: p,
120
+ Container: _,
121
+ Icon: b
112
122
  } : {
113
- className: e(d, a && "disabled", t && !a && !u && "selectableToken", n && !a && "selectedToken", n && a && "disabledAndSelected", o && t && !a && !n && "highlight", c && "print", i),
114
- Component: f,
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: i, Component: o, Container: s, Icon: c } = this.getClassAndIconConfig();
121
- return /* @__PURE__ */ a(b, {
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: s,
124
- Icon: c,
125
- children: /* @__PURE__ */ a(o || f, {
126
- className: i,
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 { S as Token, S as default, x as TokenTypes };
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.20261005000911",
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.20261005000911",
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.20261005000911",
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",