@logora/debate 0.4.56 → 0.4.57
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.
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { useLexicalComposerContext as p } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import
|
|
3
|
-
import { $addUpdateTag as
|
|
4
|
-
import { useEffect as
|
|
2
|
+
import m from "@rooks/use-localstorage-state";
|
|
3
|
+
import { $addUpdateTag as i, $getRoot as l, $createParagraphNode as f } from "lexical";
|
|
4
|
+
import { useEffect as d } from "react";
|
|
5
5
|
import { useInput as u } from "../../input_provider/useInput.js";
|
|
6
|
-
const
|
|
7
|
-
const [
|
|
8
|
-
`TextEditor:content_${
|
|
6
|
+
const L = ({ storageUid: s }) => {
|
|
7
|
+
const [n] = p(), { reset: t, setReset: a } = u(), [g, x, c] = m(
|
|
8
|
+
`TextEditor:content_${s}`,
|
|
9
9
|
{}
|
|
10
10
|
);
|
|
11
|
-
return
|
|
12
|
-
t &&
|
|
13
|
-
|
|
14
|
-
const e =
|
|
15
|
-
e.clear(), e.append(
|
|
11
|
+
return d(() => {
|
|
12
|
+
t && n.update(() => {
|
|
13
|
+
i("skip-dom-selection");
|
|
14
|
+
const e = l(), o = f();
|
|
15
|
+
e.clear(), e.append(o);
|
|
16
|
+
const r = o.selectStart();
|
|
17
|
+
r.format = 0, r.style = "", c(), a(!1);
|
|
16
18
|
});
|
|
17
19
|
}, [t]), null;
|
|
18
20
|
};
|
|
19
21
|
export {
|
|
20
|
-
|
|
22
|
+
L as ResetPlugin
|
|
21
23
|
};
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { $isListNode as
|
|
1
|
+
import { jsxs as B, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { $isListNode as $, ListNode as Y, INSERT_ORDERED_LIST_COMMAND as Z, $isListItemNode as q, $createListNode as ee } from "@lexical/list";
|
|
3
3
|
import { useLexicalComposerContext as te } from "@lexical/react/LexicalComposerContext";
|
|
4
|
-
import { $isHeadingNode as oe, $createQuoteNode as
|
|
5
|
-
import { $setBlocksType as
|
|
4
|
+
import { $isHeadingNode as oe, $createQuoteNode as K } from "@lexical/rich-text";
|
|
5
|
+
import { $setBlocksType as F } from "@lexical/selection";
|
|
6
6
|
import { $getNearestNodeOfType as ne, mergeRegister as ie } from "@lexical/utils";
|
|
7
7
|
import l from "classnames";
|
|
8
|
-
import { $getSelection as M, $isRangeSelection as I, SELECTION_CHANGE_COMMAND as le, FORMAT_TEXT_COMMAND as ae, $createParagraphNode as
|
|
9
|
-
import { useRef as
|
|
8
|
+
import { $getSelection as M, $isRangeSelection as I, SELECTION_CHANGE_COMMAND as le, FORMAT_TEXT_COMMAND as ae, $createParagraphNode as U } from "lexical";
|
|
9
|
+
import { useRef as D, useState as N, useCallback as re, useEffect as j } from "react";
|
|
10
10
|
import { useIntl as se } from "react-intl";
|
|
11
11
|
import t from "./ToolbarPlugin.module.scss.js";
|
|
12
12
|
import { Icon as f } from "../../../icons/icon/Icon.js";
|
|
13
13
|
import { Button as ce } from "../../../action/button/Button.js";
|
|
14
14
|
const Ce = (r) => {
|
|
15
|
-
const d = se(),
|
|
15
|
+
const d = se(), H = 1, [a] = te(), Q = D(null), [T, C] = N("paragraph"), [de, E] = N(null), [V, k] = N(!1), [z, w] = N(!1), [G, x] = N(!1), v = r.hideSubmit && r.hideSourceAction && r.disableRichText, _ = re(() => {
|
|
16
16
|
const e = M();
|
|
17
17
|
if (I(e)) {
|
|
18
18
|
const o = e.anchor.getNode(), s = o.getKey() === "root" ? o : o.getTopLevelElementOrThrow(), u = s.getKey();
|
|
19
19
|
if (a.getElementByKey(u) !== null)
|
|
20
|
-
if (
|
|
20
|
+
if (E(u), $(s)) {
|
|
21
21
|
const n = ne(o, Y), p = n ? n.getTag() : s.getTag();
|
|
22
|
-
|
|
22
|
+
C(p);
|
|
23
23
|
} else {
|
|
24
24
|
const n = oe(s) ? s.getTag() : s.getType();
|
|
25
|
-
|
|
25
|
+
C(n);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
k(e.hasFormat("bold")), w(e.hasFormat("italic")), x(e.hasFormat("underline"));
|
|
28
|
+
} else
|
|
29
|
+
E(null), C("paragraph"), k(!1), w(!1), x(!1);
|
|
29
30
|
}, [a]);
|
|
30
|
-
|
|
31
|
+
j(() => ie(
|
|
31
32
|
a.registerUpdateListener(({ editorState: e }) => {
|
|
32
33
|
e.read(() => {
|
|
33
34
|
_();
|
|
@@ -36,11 +37,11 @@ const Ce = (r) => {
|
|
|
36
37
|
a.registerCommand(
|
|
37
38
|
le,
|
|
38
39
|
() => (_(), !1),
|
|
39
|
-
|
|
40
|
+
H
|
|
40
41
|
)
|
|
41
42
|
), [a, _]);
|
|
42
|
-
const y =
|
|
43
|
-
|
|
43
|
+
const y = D(!1), c = D(null);
|
|
44
|
+
j(() => () => {
|
|
44
45
|
c.current && clearTimeout(c.current);
|
|
45
46
|
}, []);
|
|
46
47
|
const g = (e, o) => {
|
|
@@ -53,17 +54,17 @@ const Ce = (r) => {
|
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
e();
|
|
56
|
-
},
|
|
57
|
+
}, S = () => {
|
|
57
58
|
setTimeout(() => {
|
|
58
59
|
a.getEditorState().read(() => {
|
|
59
60
|
_();
|
|
60
61
|
});
|
|
61
62
|
}, 0);
|
|
62
63
|
}, b = (e) => {
|
|
63
|
-
a.dispatchCommand(ae, e), e === "bold" ?
|
|
64
|
+
a.dispatchCommand(ae, e), e === "bold" ? k((o) => !o) : e === "italic" ? w((o) => !o) : e === "underline" && x((o) => !o), a.focus(() => {
|
|
64
65
|
const o = a.getRootElement();
|
|
65
66
|
o && o.focus();
|
|
66
|
-
}),
|
|
67
|
+
}), S();
|
|
67
68
|
}, X = () => {
|
|
68
69
|
a.update(() => {
|
|
69
70
|
const e = M();
|
|
@@ -72,53 +73,53 @@ const Ce = (r) => {
|
|
|
72
73
|
const o = e.getNodes(), s = /* @__PURE__ */ new Set();
|
|
73
74
|
for (const m of o) {
|
|
74
75
|
let n = m;
|
|
75
|
-
for (; n !== null &&
|
|
76
|
+
for (; n !== null && !q(n); )
|
|
76
77
|
n = n.getParent();
|
|
77
|
-
|
|
78
|
+
q(n) && s.add(n);
|
|
78
79
|
}
|
|
79
80
|
const u = Array.from(s).reverse();
|
|
80
81
|
for (const m of u) {
|
|
81
82
|
const n = m.getParent();
|
|
82
|
-
if (
|
|
83
|
+
if (!$(n))
|
|
83
84
|
continue;
|
|
84
|
-
const p =
|
|
85
|
-
for (const
|
|
86
|
-
p.append(
|
|
87
|
-
const
|
|
88
|
-
if (n.insertAfter(p),
|
|
89
|
-
const
|
|
90
|
-
for (const W of
|
|
91
|
-
|
|
92
|
-
p.insertAfter(
|
|
85
|
+
const p = U(), J = m.getChildren();
|
|
86
|
+
for (const A of J)
|
|
87
|
+
p.append(A);
|
|
88
|
+
const L = m.getNextSiblings();
|
|
89
|
+
if (n.insertAfter(p), L.length > 0) {
|
|
90
|
+
const A = L[0].getValue(), R = ee(n.getListType(), A);
|
|
91
|
+
for (const W of L)
|
|
92
|
+
R.append(W);
|
|
93
|
+
p.insertAfter(R);
|
|
93
94
|
}
|
|
94
95
|
m.remove(), n.getChildrenSize() === 0 && n.remove();
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
|
-
}, v = () => {
|
|
98
|
-
T !== "ol" ? a.dispatchCommand(Z) : X(), C();
|
|
99
98
|
}, O = () => {
|
|
99
|
+
T !== "ol" ? a.dispatchCommand(Z) : X(), S();
|
|
100
|
+
}, P = () => {
|
|
100
101
|
T !== "quote" ? a.update(() => {
|
|
101
102
|
const e = M();
|
|
102
103
|
if (I(e))
|
|
103
104
|
if (e.isCollapsed()) {
|
|
104
|
-
const s = e.anchor.getNode().getTopLevelElementOrThrow(), u =
|
|
105
|
+
const s = e.anchor.getNode().getTopLevelElementOrThrow(), u = K();
|
|
105
106
|
s.insertAfter(u), u.selectEnd();
|
|
106
107
|
} else
|
|
107
|
-
|
|
108
|
+
F(e, () => K());
|
|
108
109
|
}) : a.update(() => {
|
|
109
110
|
const e = M();
|
|
110
|
-
I(e) &&
|
|
111
|
-
}),
|
|
111
|
+
I(e) && F(e, () => U());
|
|
112
|
+
}), S();
|
|
112
113
|
};
|
|
113
|
-
return
|
|
114
|
+
return v ? null : /* @__PURE__ */ B(
|
|
114
115
|
"div",
|
|
115
116
|
{
|
|
116
117
|
className: l(t.toolbar, {
|
|
117
|
-
[t.toolbarIsActive]:
|
|
118
|
+
[t.toolbarIsActive]: v ? !1 : r.isActive
|
|
118
119
|
}),
|
|
119
|
-
ref:
|
|
120
|
+
ref: Q,
|
|
120
121
|
children: [
|
|
121
|
-
r.isActive ? !r.disableRichText && /* @__PURE__ */
|
|
122
|
+
r.isActive ? !r.disableRichText && /* @__PURE__ */ B(
|
|
122
123
|
"div",
|
|
123
124
|
{
|
|
124
125
|
className: l(t.iconToolbar, {
|
|
@@ -199,8 +200,8 @@ const Ce = (r) => {
|
|
|
199
200
|
/* @__PURE__ */ i(
|
|
200
201
|
"button",
|
|
201
202
|
{
|
|
202
|
-
onPointerDown: (e) => g(e, () =>
|
|
203
|
-
onClick: () => h(() =>
|
|
203
|
+
onPointerDown: (e) => g(e, () => P()),
|
|
204
|
+
onClick: () => h(() => P()),
|
|
204
205
|
type: "button",
|
|
205
206
|
className: l(t.toolbarItem, {
|
|
206
207
|
[t.active]: T === "quote"
|
|
@@ -223,8 +224,8 @@ const Ce = (r) => {
|
|
|
223
224
|
/* @__PURE__ */ i(
|
|
224
225
|
"button",
|
|
225
226
|
{
|
|
226
|
-
onPointerDown: (e) => g(e, () =>
|
|
227
|
-
onClick: () => h(() =>
|
|
227
|
+
onPointerDown: (e) => g(e, () => O()),
|
|
228
|
+
onClick: () => h(() => O()),
|
|
228
229
|
type: "button",
|
|
229
230
|
className: l(t.toolbarItem, {
|
|
230
231
|
[t.active]: T === "ol"
|