@pie-element/extended-text-entry 15.1.2-next.18 → 15.1.2-next.19

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,713 @@
1
+ import { o as e, t } from "./browser-jJGxjKdp.js";
2
+ import { B as n, F as r, S as i, Y as a, _ as o, a as s, g as c, l, n as u, t as d, u as f, x as p, y as m } from "./dist-Ce62Biyq.js";
3
+ import h from "react";
4
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
5
+ //#region src/delivery/annotation/annotation-utils.ts
6
+ var v = /* @__PURE__ */ e(a(), 1), y = /* @__PURE__ */ e(t(), 1), b = (e, t, n) => {
7
+ let r = n || [], i = r.reduce((e, t) => e + t.textContent.length, 0), a = !0;
8
+ if (i > t) return !1;
9
+ for (e &&= (e.nodeType === 3 && e.parentNode && !e.parentNode.hasAttribute("data-ann-id") && r.push(e), e.firstChild); e && a;) a = b(e, t, r), e = e.nextSibling;
10
+ return r;
11
+ }, x = (e, t, n) => {
12
+ let r = b(n, t), i = [], a = 0;
13
+ return r.forEach((n) => {
14
+ let r = a + n.textContent.length;
15
+ [e, t].forEach((e) => {
16
+ a <= e && e < r && i.push({
17
+ node: n,
18
+ offset: e - a
19
+ });
20
+ }), a = r;
21
+ }), i;
22
+ }, S = (e) => {
23
+ let { commonAncestorContainer: t, startContainer: n, endContainer: r, startOffset: i, endOffset: a } = e, o = [], s = !1, c = !1, l = "", u = (e) => {
24
+ let { nodeValue: t, childNodes: d } = e;
25
+ e === n && e === r ? (t && (l += t.substring(i, a)), s = c = !0) : e === n ? (t && (l += t.substring(i)), s = !0) : e === r ? (t && (l += t.substring(0, a)), c = !0) : e && e.nodeType === 3 && e.parentNode && !e.parentNode.hasAttribute("data-ann-id") && t && s && !c && (l += t, o.push(e)), d.forEach((e) => {
26
+ if (!c) u(e);
27
+ else return;
28
+ });
29
+ };
30
+ return u(t), [o, l];
31
+ }, C = (e) => {
32
+ let t = document.createElement("SPAN");
33
+ return e.surroundContents(t), t;
34
+ }, w = (e) => {
35
+ if (e.startContainer === e.endContainer) return [C(e)];
36
+ let [t] = S(e), n = document.createRange();
37
+ n.selectNodeContents(e.startContainer), n.setStart(e.startContainer, e.startOffset);
38
+ let r = C(n), i = document.createRange();
39
+ i.selectNode(e.endContainer), i.setEnd(e.endContainer, e.endOffset);
40
+ let a = C(i);
41
+ return [
42
+ r,
43
+ ...t.map((e) => {
44
+ let t = document.createElement("SPAN");
45
+ return e.parentNode.insertBefore(t, e), t.appendChild(e), t;
46
+ }),
47
+ a
48
+ ];
49
+ }, T = (e, t) => {
50
+ let n = document.createRange();
51
+ n.setStart(t, 0), n.setEnd(e.startContainer, e.startOffset);
52
+ let [, r] = S(n), [, i] = S(e), a = r.length;
53
+ return {
54
+ quote: i,
55
+ start: a,
56
+ end: a + i.length
57
+ };
58
+ }, E = (e, t) => {
59
+ (e || []).forEach((e) => {
60
+ let t = e.parentNode, n = e.childNodes, r = n.length;
61
+ if (r > 0) for (let i = 0; i < r; i++) t.insertBefore(n[0], e);
62
+ else t.insertBefore(document.createTextNode(e.textContent), e);
63
+ t.removeChild(e);
64
+ }), t.normalize();
65
+ }, D = () => {
66
+ 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();
67
+ }, O = (e) => e.length >= 20 || e.search(/\n|\r|\r\n/) !== -1, k = (e) => Array.from(document.querySelectorAll(`[data-id='${e}']`)), A = (e) => document.querySelector(`[data-ann-id='${e}']`), j = n(m)(({ annotationType: e }) => ({ "& .MuiPaper-root": {
68
+ overflowX: "unset",
69
+ overflowY: "unset",
70
+ marginLeft: "16px",
71
+ "&::before": {
72
+ position: "absolute",
73
+ right: "100%",
74
+ top: "13px",
75
+ border: "solid transparent",
76
+ content: "\"\"",
77
+ height: 0,
78
+ width: 0,
79
+ pointerEvents: "none",
80
+ borderWidth: "7px",
81
+ borderRightColor: i.border()
82
+ },
83
+ ...e === "negative" && { "&::before": { borderRightColor: "rgb(255, 204, 238) !important" } },
84
+ ...e === "positive" && { "&::before": { borderRightColor: "rgb(153, 255, 153) !important" } }
85
+ } })), M = n("div")(({ annotationType: e }) => ({
86
+ width: "200px",
87
+ overflow: "hidden",
88
+ borderRadius: "4px",
89
+ backgroundColor: i.white(),
90
+ border: `4px solid ${i.border()}`,
91
+ ...e === "negative" && { borderColor: "rgb(255, 204, 238) !important" },
92
+ ...e === "positive" && { borderColor: "rgb(153, 255, 153) !important" }
93
+ })), ee = n("div")(() => ({
94
+ display: "flex",
95
+ flexWrap: "wrap",
96
+ borderTop: `2px solid ${i.border()}`
97
+ })), N = n("div")(({ variant: e, annotationType: t }) => ({
98
+ flexGrow: 1,
99
+ width: "28%",
100
+ textAlign: "center",
101
+ padding: "4px",
102
+ cursor: "pointer",
103
+ "&:not(:nth-child(3n))": { borderRight: `1px solid ${i.border()}` },
104
+ "&:hover": { backgroundColor: i.backgroundDark() },
105
+ ...e === "positive" && {
106
+ backgroundColor: "rgb(153, 255, 153) !important",
107
+ "&:hover": { filter: "brightness(85%)" }
108
+ },
109
+ ...e === "negative" && {
110
+ backgroundColor: "rgb(255, 204, 238) !important",
111
+ "&:hover": { filter: "brightness(85%)" }
112
+ },
113
+ ...e === "typeChange" && t === "negative" && { "&:hover": { backgroundColor: "rgb(153, 255, 153) !important" } },
114
+ ...e === "typeChange" && t === "positive" && { "&:hover": { backgroundColor: "rgb(255, 204, 238) !important" } }
115
+ })), P = class extends h.Component {
116
+ static propTypes = {
117
+ anchorEl: v.default.object,
118
+ open: v.default.bool,
119
+ offset: v.default.number,
120
+ value: v.default.string,
121
+ type: v.default.string,
122
+ onClose: v.default.func,
123
+ onDelete: v.default.func,
124
+ onSave: v.default.func,
125
+ onTypeChange: v.default.func
126
+ };
127
+ constructor(e) {
128
+ super(e), this.state = { value: e.value };
129
+ }
130
+ UNSAFE_componentWillReceiveProps(e) {
131
+ let { value: t } = e, { value: n } = this.props;
132
+ t !== n && this.setState({ value: t });
133
+ }
134
+ onValueChange = (e) => this.setState({ value: e.target.value });
135
+ handleSave = () => {
136
+ let { value: e, onSave: t, onClose: n, onDelete: r } = this.props, { value: i } = this.state;
137
+ i === "" && r(), e !== i && t(e, i), this.setState({ value: "" }), n();
138
+ };
139
+ handleTypeChange = () => {
140
+ let { onTypeChange: e, onDelete: t } = this.props, { value: n } = this.state;
141
+ n === "" ? t() : e(n), this.setState({ value: "" });
142
+ };
143
+ render() {
144
+ let { anchorEl: e, offset: t, onDelete: n, open: r, type: i } = this.props, { value: a } = this.state;
145
+ return /* @__PURE__ */ g(j, {
146
+ anchorEl: e,
147
+ elevation: 2,
148
+ open: r,
149
+ onClose: this.handleSave,
150
+ annotationType: i,
151
+ style: {
152
+ marginTop: `${t}px`,
153
+ transition: "margin-top 2s ease-out"
154
+ },
155
+ transitionDuration: {
156
+ enter: 225,
157
+ exit: 195
158
+ },
159
+ anchorOrigin: {
160
+ vertical: "top",
161
+ horizontal: "right"
162
+ },
163
+ transformOrigin: {
164
+ vertical: "top",
165
+ horizontal: "left"
166
+ },
167
+ children: /* @__PURE__ */ _(M, {
168
+ annotationType: i,
169
+ children: [/* @__PURE__ */ g(s, {
170
+ id: "annotation-editor",
171
+ style: {
172
+ padding: "2px 5px",
173
+ width: "95%"
174
+ },
175
+ autoFocus: !0,
176
+ multiline: !0,
177
+ rows: 1,
178
+ maxRows: 4,
179
+ value: a,
180
+ onChange: this.onValueChange,
181
+ InputProps: { disableUnderline: !0 }
182
+ }), /* @__PURE__ */ _(ee, { children: [
183
+ /* @__PURE__ */ g(N, {
184
+ onClick: n,
185
+ children: "Delete"
186
+ }),
187
+ /* @__PURE__ */ g(N, {
188
+ variant: "typeChange",
189
+ annotationType: i,
190
+ onClick: this.handleTypeChange,
191
+ children: i === "negative" ? "Green" : "Pink"
192
+ }),
193
+ /* @__PURE__ */ g(N, {
194
+ onClick: this.handleSave,
195
+ children: "Save"
196
+ })
197
+ ] })]
198
+ })
199
+ });
200
+ }
201
+ }, F = n(m)({ "& .MuiPaper-root": {
202
+ overflowX: "unset",
203
+ overflowY: "unset",
204
+ marginTop: "-16px",
205
+ "&::after": {
206
+ position: "absolute",
207
+ left: "calc(50% - 7px)",
208
+ border: "solid transparent",
209
+ content: "\"\"",
210
+ height: 0,
211
+ width: 0,
212
+ pointerEvents: "none",
213
+ borderWidth: "7px",
214
+ borderTopColor: i.border()
215
+ }
216
+ } }), I = n("div")(() => ({
217
+ width: "300px",
218
+ overflow: "hidden",
219
+ borderRadius: "4px",
220
+ backgroundColor: i.white(),
221
+ border: `2px solid ${i.border()}`
222
+ })), te = n("div")({
223
+ display: "flex",
224
+ flexWrap: "wrap"
225
+ }), ne = n("div")(() => ({
226
+ display: "flex",
227
+ flexWrap: "wrap",
228
+ borderTop: `2px solid ${i.border()}`
229
+ })), L = n("div")(({ variant: e }) => ({
230
+ width: "22%",
231
+ textAlign: "center",
232
+ padding: "4px",
233
+ cursor: "pointer",
234
+ borderBottom: `1px solid ${i.border()}`,
235
+ "&:not(:nth-child(4n))": { borderRight: `1px solid ${i.border()}` },
236
+ "&:nth-child(4n)": { flexGrow: 1 },
237
+ "&:hover": { backgroundColor: i.backgroundDark() },
238
+ ...e === "positive" && {
239
+ backgroundColor: "rgb(153, 255, 153) !important",
240
+ "&:hover": { filter: "brightness(85%)" }
241
+ },
242
+ ...e === "negative" && {
243
+ backgroundColor: "rgb(255, 204, 238) !important",
244
+ "&:hover": { filter: "brightness(85%)" }
245
+ }
246
+ })), re = class extends h.Component {
247
+ static propTypes = {
248
+ anchorEl: v.default.object,
249
+ open: v.default.bool,
250
+ annotations: v.default.array,
251
+ isNewAnnotation: v.default.bool,
252
+ onClose: v.default.func,
253
+ onDelete: v.default.func,
254
+ onEdit: v.default.func,
255
+ onWrite: v.default.func,
256
+ onAnnotate: v.default.func
257
+ };
258
+ render() {
259
+ let { anchorEl: e, annotations: t, isNewAnnotation: n, onAnnotate: r, onClose: i, onEdit: a, onDelete: o, onWrite: s, open: c } = this.props;
260
+ return /* @__PURE__ */ g(F, {
261
+ anchorEl: e,
262
+ open: c,
263
+ onClose: i,
264
+ elevation: 5,
265
+ transitionDuration: {
266
+ enter: 225,
267
+ exit: 195
268
+ },
269
+ anchorOrigin: {
270
+ vertical: "top",
271
+ horizontal: "center"
272
+ },
273
+ transformOrigin: {
274
+ vertical: "bottom",
275
+ horizontal: "center"
276
+ },
277
+ children: /* @__PURE__ */ _(I, { children: [/* @__PURE__ */ g(te, { children: t.map((e, t) => /* @__PURE__ */ g(L, {
278
+ variant: e.type,
279
+ onClick: () => r(e),
280
+ children: e.label
281
+ }, `annotation-${t}`)) }), /* @__PURE__ */ _(ne, { children: [
282
+ /* @__PURE__ */ g(L, {
283
+ onClick: i,
284
+ children: "Cancel"
285
+ }),
286
+ /* @__PURE__ */ g(L, { style: { pointerEvents: "none" } }),
287
+ n ? /* @__PURE__ */ _(h.Fragment, { children: [/* @__PURE__ */ g(L, {
288
+ variant: "positive",
289
+ onClick: () => s("positive"),
290
+ children: "Write"
291
+ }), /* @__PURE__ */ g(L, {
292
+ variant: "negative",
293
+ onClick: () => s("negative"),
294
+ children: "Write"
295
+ })] }) : /* @__PURE__ */ _(h.Fragment, { children: [/* @__PURE__ */ g(L, {
296
+ onClick: o,
297
+ children: "Delete"
298
+ }), /* @__PURE__ */ g(L, {
299
+ onClick: a,
300
+ children: "Edit"
301
+ })] })
302
+ ] })] })
303
+ });
304
+ }
305
+ }, R = n("div")({
306
+ padding: "10px 120px 10px 16px",
307
+ backgroundColor: "rgba(0, 0, 0, 0.06)",
308
+ border: "1px solid #ccc",
309
+ borderRadius: "4px",
310
+ overflowY: "scroll",
311
+ lineHeight: "36px",
312
+ whiteSpace: "pre-wrap",
313
+ overflowWrap: "break-word",
314
+ "& p": { margin: 0 },
315
+ "& span[data-latex]": {
316
+ userSelect: "none",
317
+ "-webkit-user-select": "none",
318
+ "-moz-user-select": "none",
319
+ "-ms-user-select": "none"
320
+ }
321
+ }), z = n("div")({ width: "230px" }), B = n("div")({
322
+ position: "relative",
323
+ overflowX: "hidden",
324
+ display: "flex"
325
+ }), V = n(d)(({ theme: e }) => ({
326
+ paddingTop: e.spacing(2),
327
+ marginBottom: e.spacing(2),
328
+ marginTop: e.spacing(2),
329
+ width: "100%"
330
+ })), H = "\n .sideAnnotation:before {\n position: absolute;\n right: var(--before-right, 100%);\n top: var(--before-top, 5px);\n border: solid transparent;\n content: \"\";\n height: 0;\n width: 0;\n pointer-events: none;\n border-width: var(--before-border-width, 7px);\n border-right-color: var(--before-border-color, rgb(153, 255, 153));\n }\n";
331
+ if (!document.getElementById("annotation-editor-styles")) {
332
+ let e = document.createElement("style");
333
+ e.id = "annotation-editor-styles", e.textContent = H, document.head.appendChild(e);
334
+ }
335
+ var U = class extends h.Component {
336
+ static propTypes = {
337
+ text: v.default.string,
338
+ comment: v.default.string,
339
+ annotations: v.default.array,
340
+ predefinedAnnotations: v.default.array,
341
+ onChange: v.default.func.isRequired,
342
+ onCommentChange: v.default.func.isRequired,
343
+ width: v.default.number,
344
+ height: v.default.number,
345
+ maxHeight: v.default.string,
346
+ disabled: v.default.bool,
347
+ disabledMath: v.default.bool,
348
+ customKeys: v.default.array,
349
+ keypadMode: v.default.string
350
+ };
351
+ constructor(e) {
352
+ super(e), this.state = {
353
+ anchorEl: null,
354
+ openedMenu: !1,
355
+ openedEditor: !1,
356
+ selectedElems: [],
357
+ labelElem: null,
358
+ selectionDetails: null,
359
+ annotation: null,
360
+ annotationIndex: null
361
+ };
362
+ }
363
+ componentDidMount() {
364
+ let { annotations: e, text: t } = this.props;
365
+ t && e.forEach((e) => {
366
+ let [t, n] = x(e.start, e.end, this.textRef);
367
+ if (t && n) {
368
+ let r = document.createRange();
369
+ r.setStart(t.node, t.offset), r.setEnd(n.node, n.offset);
370
+ let i = w(r);
371
+ this.createDOMAnnotation(i, e);
372
+ }
373
+ }), this.textRef && (this.adjustAnnotationsPosition(), this.textRef.addEventListener("scroll", this.adjustAnnotationsPosition));
374
+ }
375
+ adjustAnnotationsPosition = () => {
376
+ if (this.textRef && this.labelsRef) {
377
+ let e = this.textRef.offsetLeft + this.textRef.offsetWidth + 8;
378
+ Array.from(this.labelsRef.children).forEach((t) => {
379
+ let n = k(t.dataset.annId), r = (n[0].offsetTop ? n[0].offsetTop : n[0].offsetParent.offsetTop) - this.textRef.scrollTop - 6;
380
+ t.style.top = `${r}px`, t.style.left = `${e}px`;
381
+ });
382
+ }
383
+ };
384
+ handleClick = (e) => {
385
+ let { annotations: t } = this.props, { selectionDetails: n } = this.state;
386
+ if (n) return;
387
+ let { id: r, annId: i } = e.target.dataset, a = r || i, o = k(a), s = A(a), c = t.findIndex((e) => e.id === a), l = s.hasAttribute("data-freeform");
388
+ l && (s.style.zIndex = "10"), this.setState({
389
+ anchorEl: o[0],
390
+ openedMenu: !!r || !!i && !l,
391
+ openedEditor: !!i && l,
392
+ selectedElems: o,
393
+ labelElem: s,
394
+ annotationIndex: c,
395
+ annotation: t[c],
396
+ selectionDetails: null
397
+ });
398
+ };
399
+ handleHover = (e) => {
400
+ let { id: t, annId: n } = e.target.dataset, r = t || n, i = k(r), a = A(r), o = a.hasAttribute("data-freeform");
401
+ i.forEach((e) => {
402
+ e.style.zIndex = "20", e.classList.contains("positive") ? e.style.backgroundColor = "rgb(51, 255, 51, 0.7)" : e.classList.contains("negative") && (e.style.backgroundColor = "rgba(255, 102, 204, 0.55)");
403
+ }), o ? (a.style.zIndex = "20", a.classList.contains("positive") ? (a.style.backgroundColor = "rgb(128, 255, 128)", a.style.setProperty("--before-border-color", "rgb(153, 255, 153)")) : a.classList.contains("negative") && (a.style.backgroundColor = "rgb(255, 179, 230)", a.style.setProperty("--before-border-color", "rgb(255, 179, 230)"))) : (a.style.zIndex = "20", a.classList.contains("positive") ? a.style.color = "rgb(0, 77, 0)" : a.classList.contains("negative") && (a.style.color = "rgb(153, 0, 102)"));
404
+ };
405
+ handleCancelHover = (e) => {
406
+ let { id: t, annId: n } = e.target.dataset, r = t || n, i = k(r), a = A(r), o = a.hasAttribute("data-freeform");
407
+ i.forEach((e) => {
408
+ e.style.zIndex = "", e.classList.contains("positive") ? e.style.backgroundColor = "rgb(51, 255, 51, 0.5)" : e.classList.contains("negative") && (e.style.backgroundColor = "rgba(255, 102, 204, 0.4)");
409
+ }), o ? (a.style.zIndex = "", a.classList.contains("positive") ? (a.style.backgroundColor = "rgb(153, 255, 153)", a.style.removeProperty("--before-border-color")) : a.classList.contains("negative") && (a.style.backgroundColor = "rgb(255, 204, 238)", a.style.removeProperty("--before-border-color"))) : (a.style.zIndex = "", a.classList.contains("positive") ? a.style.color = "rgb(0, 128, 0)" : a.classList.contains("negative") && (a.style.color = "rgb(204, 0, 136)"));
410
+ };
411
+ handleClose = (e) => {
412
+ let { selectedElems: t, labelElem: n } = this.state;
413
+ t.length && !t[0].hasAttribute("data-id") && E(t, this.textRef), n && (n.style.zIndex = ""), this.setState({
414
+ anchorEl: null,
415
+ openedMenu: !1,
416
+ openedEditor: !1,
417
+ selectedElems: [],
418
+ labelElem: null,
419
+ selectionDetails: null,
420
+ annotationIndex: null,
421
+ annotation: null
422
+ }), D();
423
+ };
424
+ handleSelection = (e) => {
425
+ let t = window.getSelection();
426
+ if (e.detail > 2) {
427
+ D();
428
+ return;
429
+ }
430
+ if (t && t.rangeCount > 0) {
431
+ let e = t.getRangeAt(0), n = e.toString(), r = this.textRef.contains(e.commonAncestorContainer);
432
+ if (!t.isCollapsed && n !== "" && r) {
433
+ let t = T(e, this.textRef), n = w(e);
434
+ this.setState({
435
+ anchorEl: n[0],
436
+ openedMenu: !0,
437
+ selectedElems: n,
438
+ selectionDetails: t
439
+ });
440
+ }
441
+ }
442
+ };
443
+ deleteAnnotation = () => {
444
+ let { annotations: e, onChange: t } = this.props, { selectedElems: n, labelElem: r, annotationIndex: i, annotation: a } = this.state;
445
+ (O(a.label) ? this.labelsRef : n[0]).removeChild(r), E(n, this.textRef), e.splice(i, 1), t(e), this.handleClose();
446
+ };
447
+ createDOMAnnotation = (e, t) => {
448
+ let { disabled: n } = this.props, { id: r, label: i, type: a } = t;
449
+ (e || []).forEach((e) => {
450
+ e.dataset.id = r, e.className = `annotation ${a}`, e.style.position = "relative", e.style.cursor = "pointer", a === "positive" ? e.style.backgroundColor = "rgb(51, 255, 51, 0.5)" : a === "negative" && (e.style.backgroundColor = "rgba(255, 102, 204, 0.4)"), e.onclick = !n && this.handleClick, e.onmouseover = this.handleHover, e.onmouseout = this.handleCancelHover;
451
+ });
452
+ let o = e && e[0] || {}, s = document.createElement("SPAN");
453
+ if (s.dataset.annId = r, s.innerHTML = i, s.onclick = !n && this.handleClick, s.onmouseover = this.handleHover, s.onmouseout = this.handleCancelHover, O(i)) {
454
+ let e = (o.offsetTop ? o.offsetTop : o.offsetParent.offsetTop) - this.textRef.scrollTop, t = this.textRef.offsetLeft + this.textRef.offsetWidth + 8;
455
+ s.dataset.freeform = !0, s.className = `sideAnnotation ${a}`, s.style.position = "absolute", s.style.padding = "4px", s.style.borderRadius = "4px", s.style.marginLeft = "8px", s.style.width = "180px", s.style.whiteSpace = "pre-wrap", s.style.wordBreak = "break-word", s.style.border = "2px solid #ffffff", s.style.fontSize = "14px", s.style.fontStyle = "normal", s.style.fontWeight = "normal", s.style.top = `${e}px`, s.style.left = `${t}px`, a === "negative" ? s.style.backgroundColor = "rgb(255, 204, 238)" : a === "positive" && (s.style.backgroundColor = "rgb(153, 255, 153)"), s.style.setProperty("--before-border-width", "7px"), s.style.setProperty("--before-top", "5px"), s.style.setProperty("--before-right", "100%"), a === "negative" ? s.style.setProperty("--before-border-color", "rgb(255, 204, 238)") : a === "positive" && s.style.setProperty("--before-border-color", "rgb(153, 255, 153)"), this.labelsRef.appendChild(s);
456
+ } else s.className = `annotationLabel ${a}`, s.style.backgroundColor = "rgb(242, 242, 242)", s.style.padding = "2px", s.style.position = "absolute", s.style.userSelect = "none", s.style.whiteSpace = "nowrap", s.style.top = "-10px", s.style.left = "-2px", s.style.fontSize = "12px", s.style.fontStyle = "normal", s.style.fontWeight = "normal", s.style.lineHeight = "6px", s.style.webkitUserSelect = "none", s.style.mozUserSelect = "none", s.style.msUserSelect = "none", a === "positive" ? s.style.color = "rgb(0, 128, 0)" : a === "negative" && (s.style.color = "rgb(204, 0, 136)"), o.appendChild(s);
457
+ };
458
+ createNewAnnotation = (e, t) => {
459
+ let { selectedElems: n, selectionDetails: r } = this.state, i = {
460
+ id: [
461
+ r.start,
462
+ r.end,
463
+ (/* @__PURE__ */ new Date()).getTime()
464
+ ].join("-"),
465
+ label: e,
466
+ type: t,
467
+ ...r
468
+ };
469
+ return this.createDOMAnnotation(n, i), i;
470
+ };
471
+ handleMenuClick = (e) => {
472
+ let { annotations: t, onChange: n } = this.props, { annotation: r, annotationIndex: i } = this.state, { type: a, text: o } = e;
473
+ if (r) {
474
+ let e = {
475
+ ...r,
476
+ label: o,
477
+ type: a
478
+ }, { type: n, label: s } = r;
479
+ this.updateLabel(s, e, a !== n && n), t.splice(i, 1, e);
480
+ } else {
481
+ let e = this.createNewAnnotation(o, a);
482
+ t.push(e);
483
+ }
484
+ n(t), this.handleClose();
485
+ };
486
+ editAnnotation = () => {
487
+ this.setState({
488
+ openedMenu: !1,
489
+ openedEditor: !0
490
+ });
491
+ };
492
+ addAnnotation = (e) => {
493
+ let { annotations: t, onChange: n } = this.props, r = this.createNewAnnotation("", e), i = A(r.id);
494
+ t.push(r), this.setState({
495
+ openedMenu: !1,
496
+ openedEditor: !0,
497
+ annotationIndex: t.length - 1,
498
+ annotation: r,
499
+ labelElem: i
500
+ }), n(t);
501
+ };
502
+ updateLabel = (e, t, n) => {
503
+ let { selectedElems: r, labelElem: i } = this.state, { label: a, type: o } = t;
504
+ O(a) && O(e) || !O(a) && !O(e) ? (i.innerHTML = a, n && (i.classList.remove(n), i.classList.add(o), r.forEach((e) => {
505
+ e.classList.remove(n), e.classList.add(o);
506
+ }))) : O(a) && !O(e) ? (r[0].removeChild(i), this.createDOMAnnotation(r, t)) : !O(a) && O(e) && (this.labelsRef.removeChild(i), this.createDOMAnnotation(r, t));
507
+ };
508
+ changeAnnotationType = (e) => {
509
+ let { annotations: t, onChange: n } = this.props, { annotationIndex: r, selectedElems: i } = this.state, { type: a, label: o } = t[r], s = a === "positive" ? "negative" : "positive", c = {
510
+ ...t[r],
511
+ type: s,
512
+ label: e
513
+ };
514
+ i.forEach((e) => {
515
+ e.classList.remove(a), e.classList.add(s);
516
+ }), this.updateLabel(o, c, a), t.splice(r, 1, c), n(t), this.handleClose();
517
+ };
518
+ updateAnnotation = (e, t) => {
519
+ let { annotations: n, onChange: r } = this.props, { annotationIndex: i } = this.state, a = {
520
+ ...n[i],
521
+ label: t
522
+ };
523
+ this.updateLabel(e, a), n.splice(i, 1, a), r(n);
524
+ };
525
+ componentWillUnmount() {
526
+ this.textRef.removeEventListener("scroll", this.adjustAnnotationsPosition);
527
+ }
528
+ render() {
529
+ let { comment: e, customKeys: t, disabled: n, disabledMath: r, keypadMode: i, height: a, width: o, maxHeight: s, onCommentChange: c, predefinedAnnotations: l, text: d } = this.props, { anchorEl: f, annotation: p, openedMenu: m, openedEditor: h, selectionDetails: v } = this.state, y = f && (f.offsetTop ? f.offsetTop : f.offsetParent.offsetTop), b = this.textRef && y ? y - this.textRef.scrollTop - 8 : 0;
530
+ return /* @__PURE__ */ _("div", { children: [
531
+ /* @__PURE__ */ _(B, { children: [/* @__PURE__ */ g(R, {
532
+ style: {
533
+ width: o - 34,
534
+ minHeight: a,
535
+ maxHeight: s
536
+ },
537
+ ref: (e) => this.textRef = e,
538
+ onMouseDown: n ? () => {} : D,
539
+ onMouseUp: n ? () => {} : this.handleSelection,
540
+ dangerouslySetInnerHTML: { __html: d }
541
+ }), /* @__PURE__ */ g(z, { ref: (e) => this.labelsRef = e })] }),
542
+ /* @__PURE__ */ g(V, {
543
+ label: "Comment",
544
+ children: /* @__PURE__ */ g(u, {
545
+ className: "prompt",
546
+ markup: e || "",
547
+ onChange: c,
548
+ width: o && (o + 104).toString(),
549
+ disabled: n,
550
+ pluginProps: {
551
+ math: {
552
+ disabled: r,
553
+ customKeys: t,
554
+ keypadMode: i,
555
+ controlledKeypadMode: !1
556
+ },
557
+ video: { disabled: !0 },
558
+ audio: { disabled: !0 },
559
+ textAlign: { disabled: !0 },
560
+ h3: { disabled: !0 }
561
+ }
562
+ })
563
+ }),
564
+ /* @__PURE__ */ g(re, {
565
+ anchorEl: f,
566
+ open: m && !n,
567
+ annotations: l,
568
+ isNewAnnotation: !!v,
569
+ onClose: this.handleClose,
570
+ onDelete: this.deleteAnnotation,
571
+ onEdit: this.editAnnotation,
572
+ onWrite: this.addAnnotation,
573
+ onAnnotate: this.handleMenuClick
574
+ }),
575
+ /* @__PURE__ */ g(P, {
576
+ anchorEl: this.textRef,
577
+ open: h && !n,
578
+ offset: b,
579
+ value: p && p.label || "",
580
+ type: p && p.type,
581
+ onClose: this.handleClose,
582
+ onDelete: this.deleteAnnotation,
583
+ onSave: this.updateAnnotation,
584
+ onTypeChange: this.changeAnnotationType
585
+ })
586
+ ] });
587
+ }
588
+ };
589
+ //#endregion
590
+ //#region src/delivery/main.tsx
591
+ function W(e) {
592
+ return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
593
+ }
594
+ function G(e, t) {
595
+ return !e || W(e) ? e : W(e.default) ? e.default : t && W(e[t]) ? e[t] : t && W(e[t]?.default) ? e[t].default : e;
596
+ }
597
+ var K = G(c, "UiLayout") || G(Q.UiLayout, "UiLayout"), q = G(f, "PreviewPrompt") || G(Q.PreviewPrompt, "PreviewPrompt"), J = G(o, "Collapsible") || G(Q.Collapsible, "Collapsible"), Y = G(p, "Feedback") || G(Q.Feedback, "Feedback"), X = l, Z = X.default, Q = Z && typeof Z == "object" ? Z : X, ie = (0, y.default)("@pie-ui:extended-text-entry"), ae = n(K)({
598
+ backgroundColor: i.background(),
599
+ color: i.text()
600
+ }), oe = n(r)(({ theme: e }) => ({
601
+ width: "100%",
602
+ color: i.text(),
603
+ marginBottom: e.spacing(2),
604
+ fontSize: "inherit",
605
+ display: "block"
606
+ })), se = n("div")(({ theme: e }) => ({ marginBottom: e.spacing(2) })), ce = n(u)(({ theme: e }) => ({
607
+ marginBottom: e.spacing(2),
608
+ borderRadius: "4px"
609
+ })), le = n("h2")({
610
+ position: "absolute",
611
+ left: "-10000px",
612
+ top: "auto",
613
+ width: "1px",
614
+ height: "1px",
615
+ overflow: "hidden"
616
+ }), $ = class extends h.Component {
617
+ static propTypes = {
618
+ onValueChange: v.default.func.isRequired,
619
+ onAnnotationsChange: v.default.func.isRequired,
620
+ onCommentChange: v.default.func.isRequired,
621
+ model: v.default.object,
622
+ session: v.default.shape({
623
+ value: v.default.string,
624
+ annotations: v.default.array,
625
+ comment: v.default.string
626
+ }).isRequired
627
+ };
628
+ render() {
629
+ let { model: e, session: t, onAnnotationsChange: n, onCommentChange: r, onValueChange: i } = this.props, { animationsDisabled: a, annotatorMode: o, customKeys: s, dimensions: c, disabled: l, disabledAnnotator: u, equationEditor: d, extraCSSRules: f, feedback: p, mathInput: m, playersToolbarPosition: h, predefinedAnnotations: v, prompt: y, spanishInput: b, specialInput: x, spellCheckEnabled: S, teacherInstructions: C } = e, { annotations: w, comment: T, value: E } = t, { width: D, height: O } = c || {}, k = "40vh", A = { position: h === "top" ? "top" : "bottom" };
630
+ ie("[render] disabled? ", l);
631
+ let j = /* @__PURE__ */ g(q, {
632
+ defaultClassName: "teacher-instructions",
633
+ prompt: C
634
+ }), M = [];
635
+ return b && M.push({ language: "spanish" }), x && M.push({ language: "special" }), /* @__PURE__ */ _(ae, {
636
+ extraCSSRules: f,
637
+ ref: (e) => {
638
+ this.containerRef = e;
639
+ },
640
+ children: [
641
+ /* @__PURE__ */ g(le, { children: "Constructed Response Question" }),
642
+ C && /* @__PURE__ */ g(se, { children: a ? j : /* @__PURE__ */ g(J, {
643
+ labels: {
644
+ hidden: "Show Teacher Instructions",
645
+ visible: "Hide Teacher Instructions"
646
+ },
647
+ children: j
648
+ }) }),
649
+ y && /* @__PURE__ */ g(oe, {
650
+ component: "span",
651
+ children: /* @__PURE__ */ g(q, {
652
+ defaultClassName: "prompt",
653
+ prompt: e.prompt
654
+ })
655
+ }),
656
+ o ? /* @__PURE__ */ g(U, {
657
+ text: E || "",
658
+ annotations: w || [],
659
+ comment: T || "",
660
+ predefinedAnnotations: v || [],
661
+ onChange: n,
662
+ onCommentChange: r,
663
+ width: D,
664
+ height: O,
665
+ maxHeight: k,
666
+ disabled: u,
667
+ disabledMath: !m,
668
+ customKeys: s,
669
+ keypadMode: d
670
+ }) : /* @__PURE__ */ g(ce, {
671
+ className: "response-area-editor",
672
+ onChange: i,
673
+ markup: E || "",
674
+ maxWidth: D && D.toString(),
675
+ minWidth: "100px",
676
+ minHeight: O && O.toString(),
677
+ maxHeight: k,
678
+ disabled: l,
679
+ highlightShape: !0,
680
+ toolbarOpts: A,
681
+ spellCheck: S,
682
+ charactersLimit: 5e4,
683
+ autoWidthToolbar: !0,
684
+ pluginProps: {
685
+ math: {
686
+ disabled: !m,
687
+ customKeys: this.props.model.customKeys,
688
+ keypadMode: this.props.model.equationEditor,
689
+ controlledKeypadMode: !1
690
+ },
691
+ video: { disabled: !0 },
692
+ audio: { disabled: !0 },
693
+ table: { disabled: !0 },
694
+ textAlign: { disabled: !0 },
695
+ h3: { disabled: !0 },
696
+ separateParagraphs: { disabled: !1 },
697
+ ul_list: { disabled: !0 },
698
+ ol_list: { disabled: !0 }
699
+ },
700
+ languageCharactersProps: M
701
+ }),
702
+ p && /* @__PURE__ */ g(Y, {
703
+ correctness: "correct",
704
+ feedback: p
705
+ })
706
+ ]
707
+ });
708
+ }
709
+ };
710
+ //#endregion
711
+ export { $ as t };
712
+
713
+ //# sourceMappingURL=main-CkQz1rdq.js.map