@pie-lib/text-select 3.0.3-next.1 → 3.0.3-next.37
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/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/legend.d.ts +13 -0
- package/dist/legend.js +64 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/text-select.d.ts +34 -0
- package/dist/text-select.js +53 -0
- package/dist/token-select/index.d.ts +44 -0
- package/dist/token-select/index.js +170 -0
- package/dist/token-select/token.d.ts +32 -0
- package/dist/token-select/token.js +134 -0
- package/dist/tokenizer/builder.d.ts +27 -0
- package/dist/tokenizer/builder.js +124 -0
- package/dist/tokenizer/controls.d.ts +23 -0
- package/dist/tokenizer/controls.js +68 -0
- package/dist/tokenizer/index.d.ts +35 -0
- package/dist/tokenizer/index.js +91 -0
- package/dist/tokenizer/selection-utils.d.ts +10 -0
- package/dist/tokenizer/selection-utils.js +18 -0
- package/dist/tokenizer/token-text.d.ts +27 -0
- package/dist/tokenizer/token-text.js +85 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +21 -0
- package/package.json +33 -30
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -946
- package/LICENSE.md +0 -5
- package/lib/index.js +0 -57
- package/lib/index.js.map +0 -1
- package/lib/legend.js +0 -119
- package/lib/legend.js.map +0 -1
- package/lib/text-select.js +0 -105
- package/lib/text-select.js.map +0 -1
- package/lib/token-select/index.js +0 -267
- package/lib/token-select/index.js.map +0 -1
- package/lib/token-select/token.js +0 -236
- package/lib/token-select/token.js.map +0 -1
- package/lib/tokenizer/builder.js +0 -265
- package/lib/tokenizer/builder.js.map +0 -1
- package/lib/tokenizer/controls.js +0 -106
- package/lib/tokenizer/controls.js.map +0 -1
- package/lib/tokenizer/index.js +0 -147
- package/lib/tokenizer/index.js.map +0 -1
- package/lib/tokenizer/selection-utils.js +0 -55
- package/lib/tokenizer/selection-utils.js.map +0 -1
- package/lib/tokenizer/token-text.js +0 -176
- package/lib/tokenizer/token-text.js.map +0 -1
- package/lib/utils.js +0 -51
- package/lib/utils.js.map +0 -1
- package/src/__tests__/legend.test.jsx +0 -211
- package/src/__tests__/text-select.test.jsx +0 -44
- package/src/__tests__/utils.test.jsx +0 -27
- package/src/index.js +0 -8
- package/src/legend.js +0 -102
- package/src/text-select.jsx +0 -79
- package/src/token-select/__tests__/index.test.jsx +0 -623
- package/src/token-select/__tests__/token.test.jsx +0 -236
- package/src/token-select/index.jsx +0 -242
- package/src/token-select/token.jsx +0 -223
- package/src/tokenizer/__tests__/builder.test.js +0 -256
- package/src/tokenizer/__tests__/controls.test.jsx +0 -27
- package/src/tokenizer/__tests__/index.test.jsx +0 -329
- package/src/tokenizer/__tests__/selection-utils.test.js +0 -145
- package/src/tokenizer/__tests__/token-text.test.jsx +0 -318
- package/src/tokenizer/builder.js +0 -258
- package/src/tokenizer/controls.jsx +0 -71
- package/src/tokenizer/index.jsx +0 -144
- package/src/tokenizer/selection-utils.js +0 -49
- package/src/tokenizer/token-text.jsx +0 -135
- package/src/utils.js +0 -56
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/index.js
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import Tokenizer from './tokenizer/index.js';
|
|
10
|
+
import TokenSelect, { TokenTypes } from './token-select/index.js';
|
|
11
|
+
import TextSelect from './text-select.js';
|
|
12
|
+
import { Legend } from './legend.js';
|
|
13
|
+
import Token from './token-select/token.js';
|
|
14
|
+
import { prepareText } from './utils.js';
|
|
15
|
+
export { TextSelect, TokenTypes, Tokenizer, TokenSelect, Token, prepareText, Legend };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import e from "./tokenizer/index.js";
|
|
2
|
+
import t, { TokenTypes as n } from "./token-select/token.js";
|
|
3
|
+
import r from "./token-select/index.js";
|
|
4
|
+
import i from "./text-select.js";
|
|
5
|
+
import { Legend as a } from "./legend.js";
|
|
6
|
+
import { prepareText as o } from "./utils.js";
|
|
7
|
+
export { a as Legend, i as TextSelect, t as Token, r as TokenSelect, n as TokenTypes, e as Tokenizer, o as prepareText };
|
package/dist/legend.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/legend.js
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
export declare const Legend: ({ language, showOnlyCorrect }: {
|
|
11
|
+
language: any;
|
|
12
|
+
showOnlyCorrect: any;
|
|
13
|
+
}) => React.JSX.Element;
|
package/dist/legend.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import { styled as e } from "@mui/material/styles";
|
|
3
|
+
import { color as t } from "@pie-lib/render-ui";
|
|
4
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
|
+
import i from "@mui/icons-material/Check";
|
|
6
|
+
import a from "@mui/icons-material/Close";
|
|
7
|
+
import o from "@pie-lib/translator";
|
|
8
|
+
//#region src/legend.tsx
|
|
9
|
+
var { translator: s } = o, c = e("div")(({ theme: e }) => ({
|
|
10
|
+
display: "flex",
|
|
11
|
+
flexDirection: "row",
|
|
12
|
+
alignItems: "center",
|
|
13
|
+
gap: e.spacing(2),
|
|
14
|
+
borderBottom: "1px solid lightgrey",
|
|
15
|
+
borderTop: "1px solid lightgrey",
|
|
16
|
+
paddingBottom: e.spacing(1),
|
|
17
|
+
paddingTop: e.spacing(1),
|
|
18
|
+
marginBottom: e.spacing(1)
|
|
19
|
+
})), l = e("span")(({ theme: e }) => ({
|
|
20
|
+
fontSize: "14px",
|
|
21
|
+
fontWeight: "bold",
|
|
22
|
+
color: t.black(),
|
|
23
|
+
marginLeft: e.spacing(1)
|
|
24
|
+
})), u = e("div")(() => ({
|
|
25
|
+
position: "relative",
|
|
26
|
+
padding: "4px",
|
|
27
|
+
fontSize: "14px",
|
|
28
|
+
borderRadius: "4px"
|
|
29
|
+
})), d = e(u)(() => ({ border: `${t.correctTertiary()} solid 2px` })), f = e(u)(() => ({ border: `${t.incorrectWithIcon()} solid 2px` })), p = e(u)(() => ({ border: `${t.incorrectWithIcon()} dashed 2px` })), m = {
|
|
30
|
+
color: t.white(),
|
|
31
|
+
position: "absolute",
|
|
32
|
+
top: "-8px",
|
|
33
|
+
left: "-8px",
|
|
34
|
+
borderRadius: "50%",
|
|
35
|
+
fontSize: "12px",
|
|
36
|
+
padding: "2px"
|
|
37
|
+
}, h = e(i)(() => ({
|
|
38
|
+
...m,
|
|
39
|
+
backgroundColor: t.correctTertiary()
|
|
40
|
+
})), g = e(a)(() => ({
|
|
41
|
+
...m,
|
|
42
|
+
backgroundColor: t.incorrectWithIcon()
|
|
43
|
+
})), _ = ({ language: e, showOnlyCorrect: t }) => {
|
|
44
|
+
let i = [
|
|
45
|
+
{
|
|
46
|
+
Icon: h,
|
|
47
|
+
label: s.t("selectText.correctAnswerSelected", { lng: e }),
|
|
48
|
+
Container: d
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
Icon: g,
|
|
52
|
+
label: s.t("selectText.incorrectSelection", { lng: e }),
|
|
53
|
+
Container: f
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
Icon: g,
|
|
57
|
+
label: s.t("selectText.correctAnswerNotSelected", { lng: e }),
|
|
58
|
+
Container: p
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
return t && i.splice(1, 2), /* @__PURE__ */ r(c, { children: [/* @__PURE__ */ n(l, { children: s.t("selectText.key", { lng: e }) }), i.map(({ Icon: e, label: t, Container: i }, a) => /* @__PURE__ */ r(i, { children: [/* @__PURE__ */ n(e, {}), /* @__PURE__ */ n("span", { children: t })] }, a))] });
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { _ as Legend };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region ../../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
2
|
+
function e(t) {
|
|
3
|
+
var n, r, i = "";
|
|
4
|
+
if (typeof t == "string" || typeof t == "number") i += t;
|
|
5
|
+
else if (typeof t == "object") if (Array.isArray(t)) {
|
|
6
|
+
var a = t.length;
|
|
7
|
+
for (n = 0; n < a; n++) t[n] && (r = e(t[n])) && (i && (i += " "), i += r);
|
|
8
|
+
} else for (r in t) t[r] && (i && (i += " "), i += r);
|
|
9
|
+
return i;
|
|
10
|
+
}
|
|
11
|
+
function t() {
|
|
12
|
+
for (var t, n, r = 0, i = "", a = arguments.length; r < a; r++) (t = arguments[r]) && (n = e(t)) && (i && (i += " "), i += n);
|
|
13
|
+
return i;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { t as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/text-select.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
/**
|
|
12
|
+
* Built on TokenSelect uses build.normalize to build the token set.
|
|
13
|
+
*/
|
|
14
|
+
export default class TextSelect extends React.Component {
|
|
15
|
+
static propTypes: {
|
|
16
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
17
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
18
|
+
tokens: PropTypes.Validator<(PropTypes.InferProps<{
|
|
19
|
+
text: PropTypes.Requireable<string>;
|
|
20
|
+
selectable: PropTypes.Requireable<boolean>;
|
|
21
|
+
}> | null | undefined)[]>;
|
|
22
|
+
selectedTokens: PropTypes.Validator<(PropTypes.InferProps<{
|
|
23
|
+
text: PropTypes.Requireable<string>;
|
|
24
|
+
selectable: PropTypes.Requireable<boolean>;
|
|
25
|
+
}> | null | undefined)[]>;
|
|
26
|
+
text: PropTypes.Validator<string>;
|
|
27
|
+
className: PropTypes.Requireable<string>;
|
|
28
|
+
highlightChoices: PropTypes.Requireable<boolean>;
|
|
29
|
+
animationsDisabled: PropTypes.Requireable<boolean>;
|
|
30
|
+
maxNoOfSelections: PropTypes.Requireable<number>;
|
|
31
|
+
};
|
|
32
|
+
change: any;
|
|
33
|
+
render(): React.JSX.Element;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { normalize as e } from "./tokenizer/builder.js";
|
|
2
|
+
import { TokenTypes as t } from "./token-select/token.js";
|
|
3
|
+
import n from "./token-select/index.js";
|
|
4
|
+
import r from "react";
|
|
5
|
+
import i from "prop-types";
|
|
6
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
7
|
+
import o from "debug";
|
|
8
|
+
//#region src/text-select.tsx
|
|
9
|
+
var s = o("@pie-lib:text-select"), c = class extends r.Component {
|
|
10
|
+
static propTypes = {
|
|
11
|
+
onChange: i.func,
|
|
12
|
+
disabled: i.bool,
|
|
13
|
+
tokens: i.arrayOf(i.shape(t)).isRequired,
|
|
14
|
+
selectedTokens: i.arrayOf(i.shape(t)).isRequired,
|
|
15
|
+
text: i.string.isRequired,
|
|
16
|
+
className: i.string,
|
|
17
|
+
highlightChoices: i.bool,
|
|
18
|
+
animationsDisabled: i.bool,
|
|
19
|
+
maxNoOfSelections: i.number
|
|
20
|
+
};
|
|
21
|
+
change = (e) => {
|
|
22
|
+
let { onChange: t } = this.props;
|
|
23
|
+
t && t(e.filter((e) => e.selected).map((e) => ({
|
|
24
|
+
start: e.start,
|
|
25
|
+
end: e.end
|
|
26
|
+
})));
|
|
27
|
+
};
|
|
28
|
+
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) => {
|
|
32
|
+
let t = o.findIndex((t) => t.start === e.start && t.end === e.end) !== -1, n = t ? e.correct : void 0, i = e.isMissing;
|
|
33
|
+
return {
|
|
34
|
+
...e,
|
|
35
|
+
selectable: !r && e.predefined,
|
|
36
|
+
selected: t,
|
|
37
|
+
correct: n,
|
|
38
|
+
isMissing: i
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
return /* @__PURE__ */ a(n, {
|
|
42
|
+
highlightChoices: !r && l,
|
|
43
|
+
className: c,
|
|
44
|
+
tokens: p,
|
|
45
|
+
disabled: r,
|
|
46
|
+
onChange: this.change,
|
|
47
|
+
maxNoOfSelections: u,
|
|
48
|
+
animationsDisabled: d
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { c as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/token-select/index.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
import { TokenTypes } from './token.js';
|
|
12
|
+
export declare class TokenSelect extends React.Component {
|
|
13
|
+
static propTypes: {
|
|
14
|
+
tokens: PropTypes.Validator<(PropTypes.InferProps<{
|
|
15
|
+
text: PropTypes.Requireable<string>;
|
|
16
|
+
selectable: PropTypes.Requireable<boolean>;
|
|
17
|
+
}> | null | undefined)[]>;
|
|
18
|
+
className: PropTypes.Requireable<string>;
|
|
19
|
+
onChange: PropTypes.Validator<(...args: any[]) => any>;
|
|
20
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
21
|
+
highlightChoices: PropTypes.Requireable<boolean>;
|
|
22
|
+
animationsDisabled: PropTypes.Requireable<boolean>;
|
|
23
|
+
maxNoOfSelections: PropTypes.Requireable<number>;
|
|
24
|
+
};
|
|
25
|
+
static defaultProps: {
|
|
26
|
+
highlightChoices: boolean;
|
|
27
|
+
maxNoOfSelections: number;
|
|
28
|
+
tokens: never[];
|
|
29
|
+
};
|
|
30
|
+
selectedCount: () => any;
|
|
31
|
+
canSelectMore: any;
|
|
32
|
+
toggleToken: any;
|
|
33
|
+
/**
|
|
34
|
+
* Build an HTML string so that non-selectable token text (which may contain arbitrary or even
|
|
35
|
+
* *partial* HTML — e.g. just an opening <table><tbody><tr><td> in one token and the matching
|
|
36
|
+
* closing tags in another) is preserved exactly as-is. Selectable Token components are
|
|
37
|
+
* serialised via renderToString; their Emotion class names are stable hashes so they match the
|
|
38
|
+
* CSS that the HiddenCssPrimer forces Emotion to inject into the document.
|
|
39
|
+
*/
|
|
40
|
+
generateTokensInHtml: any;
|
|
41
|
+
render(): React.JSX.Element;
|
|
42
|
+
}
|
|
43
|
+
export default TokenSelect;
|
|
44
|
+
export { TokenTypes };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import e, { TokenTypes as t } from "./token.js";
|
|
2
|
+
import n from "react";
|
|
3
|
+
import r from "prop-types";
|
|
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";
|
|
10
|
+
//#region src/token-select/index.tsx
|
|
11
|
+
var p = d("@pie-lib:text-select:token-select"), m = i("div")(() => ({
|
|
12
|
+
backgroundColor: "none",
|
|
13
|
+
whiteSpace: "pre",
|
|
14
|
+
...u(),
|
|
15
|
+
"& p": { whiteSpace: "break-spaces" }
|
|
16
|
+
})), h = i("div")(() => ({
|
|
17
|
+
display: "none",
|
|
18
|
+
position: "absolute",
|
|
19
|
+
visibility: "hidden",
|
|
20
|
+
pointerEvents: "none"
|
|
21
|
+
})), g = (e = "") => e.replace(/ /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 {
|
|
22
|
+
static propTypes = {
|
|
23
|
+
tokens: r.arrayOf(r.shape(t)).isRequired,
|
|
24
|
+
className: r.string,
|
|
25
|
+
onChange: r.func.isRequired,
|
|
26
|
+
disabled: r.bool,
|
|
27
|
+
highlightChoices: r.bool,
|
|
28
|
+
animationsDisabled: r.bool,
|
|
29
|
+
maxNoOfSelections: r.number
|
|
30
|
+
};
|
|
31
|
+
static defaultProps = {
|
|
32
|
+
highlightChoices: !1,
|
|
33
|
+
maxNoOfSelections: 0,
|
|
34
|
+
tokens: []
|
|
35
|
+
};
|
|
36
|
+
selectedCount = () => this.props.tokens.filter((e) => e.selected).length;
|
|
37
|
+
canSelectMore = (e) => {
|
|
38
|
+
let { maxNoOfSelections: t } = this.props;
|
|
39
|
+
return t === 1 ? !0 : (p("[canSelectMore] maxNoOfSelections: ", t, "selectedCount: ", e), t <= 0 || isFinite(t) && e < t);
|
|
40
|
+
};
|
|
41
|
+
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]) ? {
|
|
47
|
+
...e,
|
|
48
|
+
selected: !1
|
|
49
|
+
} : {
|
|
50
|
+
...e,
|
|
51
|
+
selectable: !0
|
|
52
|
+
}), c = {
|
|
53
|
+
...s,
|
|
54
|
+
selected: n
|
|
55
|
+
};
|
|
56
|
+
i.splice(o, 1, c), e(i);
|
|
57
|
+
} else {
|
|
58
|
+
if (n && t > 0 && this.selectedCount() >= t) {
|
|
59
|
+
p("skip toggle max reached");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let r = {
|
|
63
|
+
...s,
|
|
64
|
+
selected: n
|
|
65
|
+
};
|
|
66
|
+
a.splice(o, 1, r), e(a);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
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>";
|
|
84
|
+
};
|
|
85
|
+
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
|
+
})] });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
//#endregion
|
|
170
|
+
export { v as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/token-select/token.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
export declare const TokenTypes: {
|
|
12
|
+
text: PropTypes.Requireable<string>;
|
|
13
|
+
selectable: PropTypes.Requireable<boolean>;
|
|
14
|
+
};
|
|
15
|
+
export declare class Token extends React.Component {
|
|
16
|
+
static rootClassName: string;
|
|
17
|
+
static propTypes: {
|
|
18
|
+
text: PropTypes.Validator<string>;
|
|
19
|
+
className: PropTypes.Requireable<string>;
|
|
20
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
21
|
+
highlight: PropTypes.Requireable<boolean>;
|
|
22
|
+
correct: PropTypes.Requireable<boolean>;
|
|
23
|
+
selectable: PropTypes.Requireable<boolean>;
|
|
24
|
+
};
|
|
25
|
+
static defaultProps: {
|
|
26
|
+
selectable: boolean;
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
getClassAndIconConfig: any;
|
|
30
|
+
render(): React.JSX.Element;
|
|
31
|
+
}
|
|
32
|
+
export default Token;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import e from "../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js";
|
|
2
|
+
import t from "react";
|
|
3
|
+
import n from "prop-types";
|
|
4
|
+
import { styled as r } from "@mui/material/styles";
|
|
5
|
+
import { color as i } from "@pie-lib/render-ui";
|
|
6
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
+
import s from "@mui/icons-material/Check";
|
|
8
|
+
import c from "@mui/icons-material/Close";
|
|
9
|
+
//#region src/token-select/token.tsx
|
|
10
|
+
var l = 3.2, u = 3.4, d = 2, f = r("span")(({ theme: e }) => ({
|
|
11
|
+
cursor: "pointer",
|
|
12
|
+
textIndent: 0,
|
|
13
|
+
"&.disabled": {
|
|
14
|
+
cursor: "inherit",
|
|
15
|
+
color: i.disabled()
|
|
16
|
+
},
|
|
17
|
+
"&.disabledBlack": {
|
|
18
|
+
cursor: "inherit",
|
|
19
|
+
pointerEvents: "none"
|
|
20
|
+
},
|
|
21
|
+
"&.disabledAndSelected": { backgroundColor: i.blueGrey100() },
|
|
22
|
+
[`@media (min-width: ${e.breakpoints.values.md}px)`]: { "&.selectable:hover": {
|
|
23
|
+
backgroundColor: i.blueGrey300(),
|
|
24
|
+
color: e.palette.common.black,
|
|
25
|
+
"& > *": { backgroundColor: i.blueGrey300() }
|
|
26
|
+
} },
|
|
27
|
+
"&.selected": {
|
|
28
|
+
backgroundColor: i.blueGrey100(),
|
|
29
|
+
color: e.palette.common.black,
|
|
30
|
+
lineHeight: `${parseFloat(e.spacing(1)) * l}px`,
|
|
31
|
+
border: `solid 2px ${i.blueGrey900()}`,
|
|
32
|
+
borderRadius: "4px",
|
|
33
|
+
"& > *": { backgroundColor: i.blueGrey100() }
|
|
34
|
+
},
|
|
35
|
+
"&.highlight": {
|
|
36
|
+
border: `dashed 2px ${i.blueGrey600()}`,
|
|
37
|
+
borderRadius: "4px",
|
|
38
|
+
lineHeight: `${parseFloat(e.spacing(1)) * l}px`
|
|
39
|
+
},
|
|
40
|
+
"&.print": {
|
|
41
|
+
border: `dashed 2px ${i.blueGrey600()}`,
|
|
42
|
+
borderRadius: "4px",
|
|
43
|
+
lineHeight: `${parseFloat(e.spacing(1)) * l}px`,
|
|
44
|
+
color: i.text()
|
|
45
|
+
},
|
|
46
|
+
"&.custom": { display: "initial" }
|
|
47
|
+
})), p = r("span")(({ theme: e }) => ({
|
|
48
|
+
position: "relative",
|
|
49
|
+
borderRadius: "4px",
|
|
50
|
+
color: e.palette.common.black,
|
|
51
|
+
lineHeight: `${parseFloat(e.spacing(1)) * u + d}px`,
|
|
52
|
+
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` })), _ = {
|
|
54
|
+
color: i.white(),
|
|
55
|
+
position: "absolute",
|
|
56
|
+
top: "-8px",
|
|
57
|
+
left: "-8px",
|
|
58
|
+
borderRadius: "50%",
|
|
59
|
+
fontSize: "12px",
|
|
60
|
+
padding: "2px",
|
|
61
|
+
display: "inline-block"
|
|
62
|
+
}, v = r(s)(() => ({
|
|
63
|
+
..._,
|
|
64
|
+
backgroundColor: i.correctTertiary()
|
|
65
|
+
})), y = r(c)(() => ({
|
|
66
|
+
..._,
|
|
67
|
+
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 = {
|
|
70
|
+
useWrapper: n.bool,
|
|
71
|
+
Container: n.elementType,
|
|
72
|
+
Icon: n.elementType,
|
|
73
|
+
children: n.node
|
|
74
|
+
};
|
|
75
|
+
var x = {
|
|
76
|
+
text: n.string,
|
|
77
|
+
selectable: n.bool
|
|
78
|
+
}, S = class r extends t.Component {
|
|
79
|
+
static rootClassName = "tokenRootClass";
|
|
80
|
+
static propTypes = {
|
|
81
|
+
...x,
|
|
82
|
+
text: n.string.isRequired,
|
|
83
|
+
className: n.string,
|
|
84
|
+
disabled: n.bool,
|
|
85
|
+
highlight: n.bool,
|
|
86
|
+
correct: n.bool
|
|
87
|
+
};
|
|
88
|
+
static defaultProps = {
|
|
89
|
+
selectable: !1,
|
|
90
|
+
text: ""
|
|
91
|
+
};
|
|
92
|
+
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;
|
|
94
|
+
if (s === void 0 && n && a) return {
|
|
95
|
+
className: e(d, "selected", "disabledBlack", i),
|
|
96
|
+
Component: f
|
|
97
|
+
};
|
|
98
|
+
if (s !== void 0) {
|
|
99
|
+
let t = s === !0;
|
|
100
|
+
return {
|
|
101
|
+
className: e(d, "custom", i),
|
|
102
|
+
Component: f,
|
|
103
|
+
Container: t ? m : h,
|
|
104
|
+
Icon: t ? v : y
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return l ? {
|
|
108
|
+
className: e(d, "custom", "missing", i),
|
|
109
|
+
Component: f,
|
|
110
|
+
Container: g,
|
|
111
|
+
Icon: y
|
|
112
|
+
} : {
|
|
113
|
+
className: e(d, a && "disabled", t && !a && !u && "selectable", n && !a && "selected", n && a && "disabledAndSelected", o && t && !a && !n && "highlight", c && "print", i),
|
|
114
|
+
Component: f,
|
|
115
|
+
Container: void 0,
|
|
116
|
+
Icon: void 0
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
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, {
|
|
122
|
+
useWrapper: n !== void 0 || r,
|
|
123
|
+
Container: s,
|
|
124
|
+
Icon: c,
|
|
125
|
+
children: /* @__PURE__ */ a(o || f, {
|
|
126
|
+
className: i,
|
|
127
|
+
dangerouslySetInnerHTML: { __html: (e || "").replace(/\n/g, "<br>") },
|
|
128
|
+
"data-indexkey": t
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
export { x as TokenTypes, S as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/text-select/src/tokenizer/builder.js
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
export declare const paragraphs: (text: any) => any;
|
|
10
|
+
export declare const handleSentence: (child: any, acc: any) => any;
|
|
11
|
+
export declare const sentences: (text: any) => any;
|
|
12
|
+
export declare const words: (text: any) => any;
|
|
13
|
+
declare class Intersection {
|
|
14
|
+
constructor(results: any);
|
|
15
|
+
get hasOverlap(): boolean;
|
|
16
|
+
get surroundedTokens(): any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* get intersection info for the selection in relation to tokens.
|
|
20
|
+
* @param {{start: number, end: number}} selection
|
|
21
|
+
* @param {{start: number, end: number}[]} tokens
|
|
22
|
+
* @return {tokens: [], type: 'overlap|no-overlap|contains'}
|
|
23
|
+
*/
|
|
24
|
+
export declare const intersection: (selection: any, tokens: any) => Intersection;
|
|
25
|
+
export declare const sort: (tokens: any) => any;
|
|
26
|
+
export declare const normalize: (textToNormalize: any, tokens: any) => any;
|
|
27
|
+
export {};
|