@pie-lib/text-select 3.0.3-next.36 → 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.
Files changed (70) hide show
  1. package/dist/index.d.ts +15 -0
  2. package/dist/index.js +7 -0
  3. package/dist/legend.d.ts +13 -0
  4. package/dist/legend.js +64 -0
  5. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  6. package/dist/text-select.d.ts +34 -0
  7. package/dist/text-select.js +53 -0
  8. package/dist/token-select/index.d.ts +44 -0
  9. package/dist/token-select/index.js +170 -0
  10. package/dist/token-select/token.d.ts +32 -0
  11. package/dist/token-select/token.js +134 -0
  12. package/dist/tokenizer/builder.d.ts +27 -0
  13. package/dist/tokenizer/builder.js +124 -0
  14. package/dist/tokenizer/controls.d.ts +23 -0
  15. package/dist/tokenizer/controls.js +68 -0
  16. package/dist/tokenizer/index.d.ts +35 -0
  17. package/dist/tokenizer/index.js +91 -0
  18. package/dist/tokenizer/selection-utils.d.ts +10 -0
  19. package/dist/tokenizer/selection-utils.js +18 -0
  20. package/dist/tokenizer/token-text.d.ts +27 -0
  21. package/dist/tokenizer/token-text.js +85 -0
  22. package/dist/utils.d.ts +12 -0
  23. package/dist/utils.js +21 -0
  24. package/package.json +33 -30
  25. package/CHANGELOG.json +0 -1
  26. package/CHANGELOG.md +0 -946
  27. package/LICENSE.md +0 -5
  28. package/lib/index.js +0 -57
  29. package/lib/index.js.map +0 -1
  30. package/lib/legend.js +0 -119
  31. package/lib/legend.js.map +0 -1
  32. package/lib/text-select.js +0 -105
  33. package/lib/text-select.js.map +0 -1
  34. package/lib/token-select/index.js +0 -267
  35. package/lib/token-select/index.js.map +0 -1
  36. package/lib/token-select/token.js +0 -236
  37. package/lib/token-select/token.js.map +0 -1
  38. package/lib/tokenizer/builder.js +0 -265
  39. package/lib/tokenizer/builder.js.map +0 -1
  40. package/lib/tokenizer/controls.js +0 -106
  41. package/lib/tokenizer/controls.js.map +0 -1
  42. package/lib/tokenizer/index.js +0 -147
  43. package/lib/tokenizer/index.js.map +0 -1
  44. package/lib/tokenizer/selection-utils.js +0 -55
  45. package/lib/tokenizer/selection-utils.js.map +0 -1
  46. package/lib/tokenizer/token-text.js +0 -176
  47. package/lib/tokenizer/token-text.js.map +0 -1
  48. package/lib/utils.js +0 -51
  49. package/lib/utils.js.map +0 -1
  50. package/src/__tests__/legend.test.jsx +0 -211
  51. package/src/__tests__/text-select.test.jsx +0 -44
  52. package/src/__tests__/utils.test.jsx +0 -27
  53. package/src/index.js +0 -8
  54. package/src/legend.js +0 -102
  55. package/src/text-select.jsx +0 -79
  56. package/src/token-select/__tests__/index.test.jsx +0 -623
  57. package/src/token-select/__tests__/token.test.jsx +0 -236
  58. package/src/token-select/index.jsx +0 -242
  59. package/src/token-select/token.jsx +0 -223
  60. package/src/tokenizer/__tests__/builder.test.js +0 -256
  61. package/src/tokenizer/__tests__/controls.test.jsx +0 -27
  62. package/src/tokenizer/__tests__/index.test.jsx +0 -329
  63. package/src/tokenizer/__tests__/selection-utils.test.js +0 -145
  64. package/src/tokenizer/__tests__/token-text.test.jsx +0 -318
  65. package/src/tokenizer/builder.js +0 -258
  66. package/src/tokenizer/controls.jsx +0 -71
  67. package/src/tokenizer/index.jsx +0 -144
  68. package/src/tokenizer/selection-utils.js +0 -49
  69. package/src/tokenizer/token-text.jsx +0 -135
  70. package/src/utils.js +0 -56
@@ -0,0 +1,124 @@
1
+ import { clone as e, compact as t } from "@pie-element/shared-lodash";
2
+ import n from "@pie-framework/parse-english";
3
+ //#region src/tokenizer/builder.ts
4
+ var r = (e, t) => t.children ? t.children.reduce(r, e) : t.value ? e + t.value : e, i = (e) => r("", e), a = (e) => r("", e), o = (e) => r("", e), s = (e) => new n().parse(e).children.reduce((e, t) => {
5
+ if (t.type === "ParagraphNode") {
6
+ let n = {
7
+ text: i(t),
8
+ start: t.position.start.offset,
9
+ end: t.position.end.offset
10
+ };
11
+ return e.concat([n]);
12
+ } else return e;
13
+ }, []), c = (e, t) => {
14
+ let n = [], r = e.children.reduce(function(e, t) {
15
+ if (t.type === "WhiteSpaceNode" && t.value === "\n") {
16
+ if (n.length) {
17
+ let r = n[0], i = {
18
+ text: n.map((e) => a(e)).join(""),
19
+ start: r.position.start.offset,
20
+ end: t.position.start.offset
21
+ };
22
+ return n.splice(0, n.length), e.concat([i]);
23
+ }
24
+ } else n.push(t);
25
+ return e;
26
+ }, t);
27
+ if (n.length) {
28
+ let e = n[0], t = n[n.length - 1], i = {
29
+ text: n.map((e) => a(e)).join(""),
30
+ start: e.position.start.offset,
31
+ end: t.position.end.offset
32
+ };
33
+ r = r.concat([i]), n.splice(0, n.length);
34
+ }
35
+ return r;
36
+ }, l = (e) => new n().parse(e).children.reduce((e, t) => t.type === "ParagraphNode" ? t.children.reduce((e, t) => t.type === "SentenceNode" && c(t, e) || e, e) : e, []), u = (e) => new n().parse(e).children.reduce((e, t) => t.type === "ParagraphNode" ? t.children.reduce((e, t) => t.type === "SentenceNode" ? t.children.reduce((e, t) => {
37
+ if (t.type === "WordNode") {
38
+ let n = {
39
+ text: o(t),
40
+ start: t.position.start.offset,
41
+ end: t.position.end.offset
42
+ };
43
+ return e.concat([n]);
44
+ } else return e;
45
+ }, e) : e, e) : e, []), d = class {
46
+ constructor(e) {
47
+ this.results = e;
48
+ }
49
+ get hasOverlap() {
50
+ return this.results.filter((e) => e.type === "overlap").length > 0;
51
+ }
52
+ get surroundedTokens() {
53
+ return this.results.filter((e) => e.type === "within-selection").map((e) => e.token);
54
+ }
55
+ }, f = (e, n) => {
56
+ let { start: r, end: i } = e, a = (e) => r >= e.start && r < e.end, o = (e) => i > e.start && i <= e.end;
57
+ return new d(t(n.map((e) => {
58
+ if (r === e.start && i === e.end) return {
59
+ token: e,
60
+ type: "exact-fit"
61
+ };
62
+ if (r <= e.start && i >= e.end) return {
63
+ token: e,
64
+ type: "within-selection"
65
+ };
66
+ if (a(e) || o(e)) return {
67
+ token: e,
68
+ type: "overlap"
69
+ };
70
+ })));
71
+ }, p = (t) => {
72
+ if (Array.isArray(t)) {
73
+ let n = e(t);
74
+ return n.sort((e, t) => {
75
+ let n = e.start < t.start ? -1 : +(e.start > t.start), r = e.end < t.end ? -1 : +(e.end > t.end);
76
+ if (n === -1 && r !== -1) throw Error(`sort does not support intersecting tokens. a: ${e.start}-${e.end}, b: ${t.start}-${t.end}`);
77
+ return n;
78
+ }), n;
79
+ } else return t;
80
+ }, m = (e, t) => {
81
+ let n = e || "";
82
+ return !Array.isArray(t) || t.length === 0 ? [{
83
+ text: n,
84
+ start: 0,
85
+ end: n.length
86
+ }] : p(t).reduce((e, t, r, i) => {
87
+ let a = [], o = e.lastIndex;
88
+ if (t.start === o ? a = [{
89
+ text: n.substring(o, t.end),
90
+ start: o,
91
+ end: t.end,
92
+ predefined: !0,
93
+ correct: t.correct,
94
+ isMissing: t.isMissing
95
+ }] : o < t.start && (a = [{
96
+ text: n.substring(o, t.start),
97
+ start: o,
98
+ end: t.start
99
+ }, {
100
+ text: n.substring(t.start, t.end),
101
+ start: t.start,
102
+ end: t.end,
103
+ predefined: !0,
104
+ correct: t.correct,
105
+ isMissing: t.isMissing
106
+ }]), r === i.length - 1 && t.end < n.length) {
107
+ let e = {
108
+ text: n.substring(t.end),
109
+ start: t.end,
110
+ end: n.length
111
+ };
112
+ a.push(e);
113
+ }
114
+ return {
115
+ lastIndex: a.length ? a[a.length - 1].end : o,
116
+ result: e.result.concat(a)
117
+ };
118
+ }, {
119
+ result: [],
120
+ lastIndex: 0
121
+ }).result;
122
+ };
123
+ //#endregion
124
+ export { f as intersection, m as normalize, s as paragraphs, l as sentences, u as words };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/text-select/src/tokenizer/controls.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 class Controls extends React.Component {
12
+ static propTypes: {
13
+ onClear: PropTypes.Validator<(...args: any[]) => any>;
14
+ onWords: PropTypes.Validator<(...args: any[]) => any>;
15
+ onSentences: PropTypes.Validator<(...args: any[]) => any>;
16
+ onParagraphs: PropTypes.Validator<(...args: any[]) => any>;
17
+ setCorrectMode: PropTypes.Validator<boolean>;
18
+ onToggleCorrectMode: PropTypes.Validator<(...args: any[]) => any>;
19
+ };
20
+ static defaultProps: {};
21
+ render(): React.JSX.Element;
22
+ }
23
+ export default Controls;
@@ -0,0 +1,68 @@
1
+ import e from "react";
2
+ import t from "prop-types";
3
+ import n from "@mui/material/Button";
4
+ import { styled as r } from "@mui/material/styles";
5
+ import i from "@mui/material/Switch";
6
+ import a from "@mui/material/FormControlLabel";
7
+ import { color as o } from "@pie-lib/render-ui";
8
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
9
+ //#region src/tokenizer/controls.tsx
10
+ var l = r("div")(() => ({
11
+ display: "flex",
12
+ alignItems: "center",
13
+ justifyContent: "space-between"
14
+ })), u = r(n)(({ theme: e }) => ({ marginRight: e.spacing(1) })), d = r(i)(() => ({
15
+ "& .MuiSwitch-thumb": { "&.Mui-checked": { color: `${o.tertiary()} !important` } },
16
+ "& .MuiSwitch-track": { "&.Mui-checked": { backgroundColor: `${o.tertiaryLight()} !important` } }
17
+ })), f = class extends e.Component {
18
+ static propTypes = {
19
+ onClear: t.func.isRequired,
20
+ onWords: t.func.isRequired,
21
+ onSentences: t.func.isRequired,
22
+ onParagraphs: t.func.isRequired,
23
+ setCorrectMode: t.bool.isRequired,
24
+ onToggleCorrectMode: t.func.isRequired
25
+ };
26
+ static defaultProps = {};
27
+ render() {
28
+ let { onClear: e, onWords: t, onSentences: n, onParagraphs: r, setCorrectMode: i, onToggleCorrectMode: o } = this.props;
29
+ return /* @__PURE__ */ c(l, { children: [/* @__PURE__ */ c("div", { children: [
30
+ /* @__PURE__ */ s(u, {
31
+ onClick: t,
32
+ size: "small",
33
+ color: "primary",
34
+ disabled: i,
35
+ children: "Words"
36
+ }),
37
+ /* @__PURE__ */ s(u, {
38
+ onClick: n,
39
+ size: "small",
40
+ color: "primary",
41
+ disabled: i,
42
+ children: "Sentences"
43
+ }),
44
+ /* @__PURE__ */ s(u, {
45
+ onClick: r,
46
+ size: "small",
47
+ color: "primary",
48
+ disabled: i,
49
+ children: "Paragraphs"
50
+ }),
51
+ /* @__PURE__ */ s(u, {
52
+ size: "small",
53
+ color: "secondary",
54
+ onClick: e,
55
+ disabled: i,
56
+ children: "Clear"
57
+ })
58
+ ] }), /* @__PURE__ */ s(a, {
59
+ control: /* @__PURE__ */ s(d, {
60
+ checked: i,
61
+ onChange: o
62
+ }),
63
+ label: "Set correct answers"
64
+ })] });
65
+ }
66
+ };
67
+ //#endregion
68
+ export { f as default };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/text-select/src/tokenizer/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
+ export declare class Tokenizer extends React.Component {
12
+ static propTypes: {
13
+ text: PropTypes.Validator<string>;
14
+ tokens: PropTypes.Requireable<(PropTypes.InferProps<{
15
+ text: PropTypes.Requireable<string>;
16
+ correct: PropTypes.Requireable<boolean>;
17
+ start: PropTypes.Requireable<number>;
18
+ end: PropTypes.Requireable<number>;
19
+ }> | null | undefined)[]>;
20
+ onChange: PropTypes.Validator<(...args: any[]) => any>;
21
+ };
22
+ static defaultProps: {};
23
+ constructor(props: any);
24
+ onChangeHandler: any;
25
+ toggleCorrectMode: () => void;
26
+ clear: any;
27
+ buildTokens: any;
28
+ selectToken: any;
29
+ tokenClick: any;
30
+ tokenIndex: any;
31
+ setCorrect: any;
32
+ removeToken: any;
33
+ render(): React.JSX.Element;
34
+ }
35
+ export default Tokenizer;
@@ -0,0 +1,91 @@
1
+ import e from "./controls.js";
2
+ import { paragraphs as t, sentences as n, words as r } from "./builder.js";
3
+ import i from "./token-text.js";
4
+ import a from "react";
5
+ import o from "prop-types";
6
+ import { styled as s } from "@mui/material/styles";
7
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
8
+ import { clone as u, differenceWith as d, isEqual as f } from "@pie-element/shared-lodash";
9
+ import { noSelect as p } from "@pie-lib/style-utils";
10
+ //#region src/tokenizer/index.tsx
11
+ var m = s("div")(({ disabled: e }) => ({
12
+ whiteSpace: "pre-wrap",
13
+ ...e && { ...p() }
14
+ })), h = class extends a.Component {
15
+ static propTypes = {
16
+ text: o.string.isRequired,
17
+ tokens: o.arrayOf(o.shape({
18
+ text: o.string,
19
+ correct: o.bool,
20
+ start: o.number,
21
+ end: o.number
22
+ })),
23
+ onChange: o.func.isRequired
24
+ };
25
+ static defaultProps = {};
26
+ constructor(e) {
27
+ super(e), this.state = {
28
+ setCorrectMode: !1,
29
+ mode: ""
30
+ };
31
+ }
32
+ onChangeHandler = (e, t) => {
33
+ this.props.onChange(e, t), this.setState({ mode: t });
34
+ };
35
+ toggleCorrectMode = () => this.setState({ setCorrectMode: !this.state.setCorrectMode });
36
+ clear = () => {
37
+ this.onChangeHandler([], "");
38
+ };
39
+ buildTokens = (e, t) => {
40
+ let { text: n } = this.props, r = t(n);
41
+ this.onChangeHandler(r, e);
42
+ };
43
+ selectToken = (e, t) => {
44
+ let { tokens: n } = this.props, r = d(u(n), t, f);
45
+ r.push(e), this.onChangeHandler(r, this.state.mode);
46
+ };
47
+ tokenClick = (e) => {
48
+ let { setCorrectMode: t } = this.state;
49
+ t ? this.setCorrect(e) : this.removeToken(e);
50
+ };
51
+ tokenIndex = (e) => {
52
+ let { tokens: t } = this.props;
53
+ return t.findIndex((t) => t.text == e.text && t.start == e.start && t.end == e.end);
54
+ };
55
+ setCorrect = (e) => {
56
+ let { tokens: t } = this.props, n = this.tokenIndex(e);
57
+ if (n !== -1) {
58
+ let e = t[n];
59
+ e.correct = !e.correct;
60
+ let r = u(t);
61
+ r.splice(n, 1, e), this.onChangeHandler(r, this.state.mode);
62
+ }
63
+ };
64
+ removeToken = (e) => {
65
+ let { tokens: t } = this.props, n = this.tokenIndex(e);
66
+ if (n !== -1) {
67
+ let e = u(t);
68
+ e.splice(n, 1), this.onChangeHandler(e, this.state.mode);
69
+ }
70
+ };
71
+ render() {
72
+ let { text: a, tokens: o } = this.props, { setCorrectMode: s } = this.state;
73
+ return /* @__PURE__ */ l("div", { children: [/* @__PURE__ */ c(e, {
74
+ onClear: this.clear,
75
+ onWords: () => this.buildTokens("words", r),
76
+ onSentences: () => this.buildTokens("sentence", n),
77
+ onParagraphs: () => this.buildTokens("paragraphs", t),
78
+ setCorrectMode: s,
79
+ onToggleCorrectMode: this.toggleCorrectMode
80
+ }), /* @__PURE__ */ c(m, {
81
+ disabled: s,
82
+ as: i,
83
+ text: a,
84
+ tokens: o,
85
+ onTokenClick: this.tokenClick,
86
+ onSelectToken: this.selectToken
87
+ })] });
88
+ }
89
+ };
90
+ //#endregion
91
+ export { h as default };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/text-select/src/tokenizer/selection-utils.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 clearSelection: () => void;
10
+ export declare const getCaretCharacterOffsetWithin: (element: any) => number;
@@ -0,0 +1,18 @@
1
+ //#region src/tokenizer/selection-utils.ts
2
+ var e = () => {
3
+ document.getSelection ? (document.getSelection().removeAllRanges(), document.getSelection().addRange(document.createRange())) : window.getSelection ? window.getSelection().removeAllRanges ? (window.getSelection().removeAllRanges(), window.getSelection().addRange(document.createRange())) : window.getSelection().empty && window.getSelection().empty() : document.selection && document.selection.empty();
4
+ }, t = (e) => {
5
+ var t = 0, n = e.ownerDocument || e.document, r = n.defaultView || n.parentWindow, i;
6
+ if (r.getSelection !== void 0) {
7
+ if (i = r.getSelection(), i.rangeCount > 0) {
8
+ var a = r.getSelection().getRangeAt(0), o = a.toString().length, s = a.cloneRange();
9
+ s.selectNodeContents(e), s.setEnd(a.endContainer, a.endOffset), t = o ? s.toString().length - o : s.toString().length;
10
+ }
11
+ } else if ((i = n.selection) && i.type !== "Control") {
12
+ var c = i.createRange(), l = n.body.createTextRange();
13
+ l.moveToElementText(e), l.setEndPoint("EndToEnd", c), t = l.text.length;
14
+ }
15
+ return t;
16
+ };
17
+ //#endregion
18
+ export { e as clearSelection, t as getCaretCharacterOffsetWithin };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/text-select/src/tokenizer/token-text.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 Text: ({ text, predefined, onClick, correct }: {
12
+ text: any;
13
+ predefined: any;
14
+ onClick: any;
15
+ correct: any;
16
+ }) => React.JSX.Element;
17
+ export default class TokenText extends React.Component {
18
+ static propTypes: {
19
+ text: PropTypes.Validator<string>;
20
+ tokens: PropTypes.Validator<any[]>;
21
+ onTokenClick: PropTypes.Validator<(...args: any[]) => any>;
22
+ onSelectToken: PropTypes.Validator<(...args: any[]) => any>;
23
+ className: PropTypes.Requireable<string>;
24
+ };
25
+ onClick: any;
26
+ render(): React.JSX.Element;
27
+ }
@@ -0,0 +1,85 @@
1
+ import { intersection as e, normalize as t } from "./builder.js";
2
+ import n from "../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js";
3
+ import { clearSelection as r, getCaretCharacterOffsetWithin as i } from "./selection-utils.js";
4
+ import a from "react";
5
+ import o from "prop-types";
6
+ import { styled as s } from "@mui/material/styles";
7
+ import { jsx as c } from "react/jsx-runtime";
8
+ import l from "debug";
9
+ import { green as u, yellow as d } from "@mui/material/colors";
10
+ //#region src/tokenizer/token-text.tsx
11
+ var f = l("@pie-lib:text-select:token-text"), p = s("span")(() => ({
12
+ "&.predefined": {
13
+ cursor: "pointer",
14
+ backgroundColor: d[100],
15
+ border: `dashed 0px ${d[700]}`,
16
+ "& *": {
17
+ cursor: "pointer",
18
+ backgroundColor: d[100],
19
+ border: `dashed 0px ${d[700]}`
20
+ }
21
+ },
22
+ "&.correct": {
23
+ backgroundColor: u[500],
24
+ "& *": { backgroundColor: u[500] }
25
+ }
26
+ })), m = ({ text: e, predefined: t, onClick: r, correct: i }) => {
27
+ let a = (e || "").replace(/\n/g, "<br>");
28
+ return t ? /* @__PURE__ */ c(p, {
29
+ onClick: r,
30
+ className: n("predefined", i && "correct"),
31
+ dangerouslySetInnerHTML: { __html: a }
32
+ }) : /* @__PURE__ */ c("span", { dangerouslySetInnerHTML: { __html: a } });
33
+ }, h = [
34
+ "\n",
35
+ " ",
36
+ " "
37
+ ], g = class extends a.Component {
38
+ static propTypes = {
39
+ text: o.string.isRequired,
40
+ tokens: o.array.isRequired,
41
+ onTokenClick: o.func.isRequired,
42
+ onSelectToken: o.func.isRequired,
43
+ className: o.string
44
+ };
45
+ onClick = (t) => {
46
+ let { onSelectToken: n, text: a, tokens: o } = this.props;
47
+ if (t.preventDefault(), typeof window > "u") return;
48
+ let s = window.getSelection().toString();
49
+ if (s.length > 0 && h.indexOf(s) < 0 && this.root) {
50
+ let t = i(this.root), c = a.slice(t).indexOf(s);
51
+ if (t += c, t !== void 0) {
52
+ let i = t + s.length;
53
+ if (i <= a.length) {
54
+ let a = e({
55
+ start: t,
56
+ end: i
57
+ }, o);
58
+ if (a.hasOverlap) f("hasOverlap - do nothing"), r();
59
+ else {
60
+ let e = a.surroundedTokens;
61
+ n({
62
+ text: s,
63
+ start: t,
64
+ end: i
65
+ }, e), r();
66
+ }
67
+ }
68
+ }
69
+ }
70
+ };
71
+ render() {
72
+ let { text: e, tokens: n, className: r, onTokenClick: i } = this.props, a = t(e, n);
73
+ return /* @__PURE__ */ c("div", {
74
+ className: r,
75
+ ref: (e) => this.root = e,
76
+ onClick: this.onClick,
77
+ children: a.map((e, t) => /* @__PURE__ */ c(m, {
78
+ ...e,
79
+ onClick: () => i(e)
80
+ }, t))
81
+ });
82
+ }
83
+ };
84
+ //#endregion
85
+ export { g as default };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/text-select/src/utils.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 parseBrs: (dom: any) => void;
10
+ export declare const parseParagraph: (paragraph: any, end: any) => any;
11
+ export declare const parseParagraphs: (dom: any) => string | null;
12
+ export declare const prepareText: (text: any) => any;
package/dist/utils.js ADDED
@@ -0,0 +1,21 @@
1
+ //#region src/utils.tsx
2
+ var e = (e = "") => {
3
+ let t = document.createElement("div");
4
+ return t.innerHTML = e.trim(), t;
5
+ }, t = (e) => {
6
+ e.querySelectorAll("br").forEach((e) => e.replaceWith("\n")), e.innerHTML = e.innerHTML.replace(/\n\n/g, "\n");
7
+ }, n = (e, t) => t ? e.innerHTML : `${e.innerHTML}\n\n`, r = (e) => {
8
+ let t = e.querySelectorAll("p"), r = "";
9
+ return t.forEach((e, i) => {
10
+ r += n(e, i === t.length - 1);
11
+ }), r || null;
12
+ }, i = (n) => {
13
+ let i = e(n), a = Array.from(i.querySelectorAll("*"));
14
+ if (i.querySelectorAll("p").length === 0) {
15
+ let e = document.createElement("div");
16
+ e.innerHTML = `<p>${i.innerHTML}</p>`, i = e;
17
+ }
18
+ return a.length === 0 ? n : (t(i), r(i));
19
+ };
20
+ //#endregion
21
+ export { i as prepareText };
package/package.json CHANGED
@@ -1,45 +1,48 @@
1
1
  {
2
2
  "name": "@pie-lib/text-select",
3
- "publishConfig": {
4
- "access": "public"
5
- },
6
- "version": "3.0.3-next.36+31c58d108",
3
+ "version": "3.0.3-next.37",
7
4
  "description": "Some react components for text selection",
8
- "keywords": [
9
- "react",
10
- "pie",
11
- "text",
12
- "select"
13
- ],
14
- "main": "lib/index.js",
15
- "module": "src/index.js",
16
- "author": "",
17
- "license": "ISC",
18
- "repository": "pie-framework/pie-lib",
19
5
  "dependencies": {
20
6
  "@emotion/react": "^11.14.0",
21
7
  "@emotion/style": "^0.8.0",
22
8
  "@mui/icons-material": "^7.3.4",
23
9
  "@mui/material": "^7.3.4",
24
10
  "@pie-framework/parse-english": "^1.0.0",
25
- "@pie-lib/render-ui": "^6.1.1-next.36+31c58d108",
26
- "@pie-lib/style-utils": "^2.0.2",
27
- "@pie-lib/translator": "^4.0.2",
28
- "classnames": "^2.2.6",
11
+ "@pie-lib/render-ui": "6.1.1-next.37",
12
+ "@pie-lib/style-utils": "2.0.2",
13
+ "@pie-lib/translator": "4.0.3-next.0",
29
14
  "debug": "^4.1.1",
30
- "lodash-es": "^4.17.23",
31
- "prop-types": "^15.6.2"
15
+ "prop-types": "^15.6.2",
16
+ "@pie-element/shared-lodash": "0.1.1-next.0",
17
+ "clsx": "^2.1.1"
18
+ },
19
+ "type": "module",
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "sideEffects": false,
32
+ "scripts": {
33
+ "build": "bun x vite build && bun x tsc --emitDeclarationOnly",
34
+ "dev": "bun x vite",
35
+ "test": "bun x vitest run"
32
36
  },
33
37
  "devDependencies": {
34
- "@pie-framework/parse-english": "^1.0.0",
35
- "@pie-lib/test-utils": "^2.0.2",
36
- "natural": "^0.6.3",
37
- "react": "^18.2.0",
38
- "react-dom": "^18.2.0"
38
+ "vite": "^8.0.1",
39
+ "typescript": "^5.9.3",
40
+ "@vitejs/plugin-react": "^6.0.1",
41
+ "@types/react": "^18.2.0",
42
+ "@types/react-dom": "^18.2.0"
39
43
  },
40
44
  "peerDependencies": {
41
- "react": "^18.2.0"
42
- },
43
- "gitHead": "31c58d108817fb25448ce7b29d4369f667f75625",
44
- "scripts": {}
45
+ "react": "^18.0.0",
46
+ "react-dom": "^18.0.0"
47
+ }
45
48
  }
package/CHANGELOG.json DELETED
@@ -1 +0,0 @@
1
- []