@arkitektbedriftene/fe-lib 0.3.10 → 0.3.11
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,6 +1,6 @@
|
|
|
1
1
|
import { type ReactNode, type ReactElement } from "react";
|
|
2
2
|
import { type InitialConfigType } from "@lexical/react/LexicalComposer";
|
|
3
|
-
export declare const RichTextEditor: ({ isLoading, children, placeholderText, nodes, plugins, toolbar, content, }: {
|
|
3
|
+
export declare const RichTextEditor: ({ isLoading, children, placeholderText, nodes, plugins, toolbar, content, hideBorder, onBlur, }: {
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
placeholderText?: string | undefined;
|
|
@@ -8,4 +8,6 @@ export declare const RichTextEditor: ({ isLoading, children, placeholderText, no
|
|
|
8
8
|
plugins?: ReactNode;
|
|
9
9
|
toolbar?: ReactNode;
|
|
10
10
|
content: ReactElement;
|
|
11
|
+
hideBorder?: boolean | undefined;
|
|
12
|
+
onBlur?: (() => void) | undefined;
|
|
11
13
|
}) => JSX.Element;
|
package/dist/rich-text.es.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { createHeadlessEditor as
|
|
2
|
-
import { $generateHtmlFromNodes as
|
|
3
|
-
import { $getRoot as
|
|
4
|
-
import { trimTextContentFromAnchor as
|
|
5
|
-
import { AutoLinkNode as
|
|
6
|
-
import { ListNode as
|
|
7
|
-
import { HeadingNode as
|
|
8
|
-
import { TableNode as
|
|
1
|
+
import { createHeadlessEditor as T } from "@lexical/headless";
|
|
2
|
+
import { $generateHtmlFromNodes as y } from "@lexical/html";
|
|
3
|
+
import { $getRoot as p, ParagraphNode as S, $createParagraphNode as E, $createTextNode as $ } from "lexical";
|
|
4
|
+
import { trimTextContentFromAnchor as F } from "@lexical/selection";
|
|
5
|
+
import { AutoLinkNode as L, LinkNode as j } from "@lexical/link";
|
|
6
|
+
import { ListNode as w, ListItemNode as v } from "@lexical/list";
|
|
7
|
+
import { HeadingNode as R, QuoteNode as H } from "@lexical/rich-text";
|
|
8
|
+
import { TableNode as k, TableRowNode as P, TableCellNode as I } from "@lexical/table";
|
|
9
9
|
import { j as c } from "./jsx-runtime-d0aa4c5b.js";
|
|
10
|
-
import { createContext as
|
|
11
|
-
import { c as d, s as
|
|
12
|
-
import { LexicalComposer as
|
|
13
|
-
import { RichTextPlugin as
|
|
14
|
-
import
|
|
10
|
+
import { createContext as M, useState as B, useRef as f, useCallback as h, useContext as q, useMemo as z } from "react";
|
|
11
|
+
import { c as d, s as A, B as x, S as D } from "./Popover-2318823a.js";
|
|
12
|
+
import { LexicalComposer as V } from "@lexical/react/LexicalComposer";
|
|
13
|
+
import { RichTextPlugin as W } from "@lexical/react/LexicalRichTextPlugin";
|
|
14
|
+
import J from "@lexical/react/LexicalErrorBoundary";
|
|
15
15
|
import "react-dom";
|
|
16
|
-
const
|
|
16
|
+
const O = ({
|
|
17
17
|
text: e,
|
|
18
18
|
maxChars: i,
|
|
19
19
|
maxLines: s
|
|
@@ -28,31 +28,31 @@ const W = ({
|
|
|
28
28
|
e[t] === `
|
|
29
29
|
` && n++, t++;
|
|
30
30
|
return e.slice(0, t).length;
|
|
31
|
-
},
|
|
31
|
+
}, Q = ({
|
|
32
32
|
editor: e,
|
|
33
33
|
maxChars: i,
|
|
34
34
|
maxLines: s
|
|
35
35
|
}) => {
|
|
36
|
-
const r =
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
-
},
|
|
36
|
+
const r = p(), o = r.getTextContent(), n = O({ text: o, maxChars: i, maxLines: s }), t = o.length - n, m = r.select().anchor;
|
|
37
|
+
F(e, m, t);
|
|
38
|
+
const a = r.getLastChild();
|
|
39
|
+
return a instanceof S && a.getChildrenSize() === 0 && a.remove(), t;
|
|
40
|
+
}, G = (e) => e[0] === "{", ge = (e, i, s) => {
|
|
41
41
|
let r = 0;
|
|
42
|
-
const o =
|
|
42
|
+
const o = T({
|
|
43
43
|
nodes: i,
|
|
44
44
|
editable: !1
|
|
45
45
|
});
|
|
46
46
|
if (e)
|
|
47
47
|
try {
|
|
48
|
-
if (typeof e == "string" && !
|
|
48
|
+
if (typeof e == "string" && !G(e))
|
|
49
49
|
o.update(() => {
|
|
50
|
-
const t =
|
|
51
|
-
|
|
50
|
+
const t = p(), l = E();
|
|
51
|
+
l.append($(e.trim())), t.append(l);
|
|
52
52
|
});
|
|
53
53
|
else {
|
|
54
54
|
const t = o.parseEditorState(e, () => {
|
|
55
|
-
r =
|
|
55
|
+
r = Q({
|
|
56
56
|
editor: o,
|
|
57
57
|
maxLines: s == null ? void 0 : s.maxLines
|
|
58
58
|
});
|
|
@@ -64,48 +64,48 @@ const W = ({
|
|
|
64
64
|
}
|
|
65
65
|
let n = "";
|
|
66
66
|
return o.update(() => {
|
|
67
|
-
n =
|
|
67
|
+
n = y(o);
|
|
68
68
|
}), { html: n, trimCount: r };
|
|
69
|
-
},
|
|
69
|
+
}, Ce = [
|
|
70
|
+
R,
|
|
71
|
+
H,
|
|
70
72
|
w,
|
|
71
73
|
v,
|
|
72
74
|
L,
|
|
73
75
|
j,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
k
|
|
79
|
-
], Q = d({
|
|
76
|
+
k,
|
|
77
|
+
P,
|
|
78
|
+
I
|
|
79
|
+
], K = d({
|
|
80
80
|
fontWeight: "bold"
|
|
81
|
-
}),
|
|
81
|
+
}), U = d({
|
|
82
82
|
fontStyle: "italic"
|
|
83
|
-
}),
|
|
83
|
+
}), X = d({
|
|
84
84
|
textDecoration: "underline"
|
|
85
|
-
}),
|
|
85
|
+
}), Y = d({
|
|
86
86
|
listStyleType: "none"
|
|
87
|
-
}),
|
|
87
|
+
}), Z = d({
|
|
88
88
|
borderLeft: "4px solid #ccc",
|
|
89
89
|
color: "#666",
|
|
90
90
|
fontStyle: "italic",
|
|
91
91
|
margin: "1.5em 10px",
|
|
92
92
|
padding: "0.5em 10px"
|
|
93
|
-
}),
|
|
94
|
-
quote:
|
|
93
|
+
}), _ = {
|
|
94
|
+
quote: Z().className,
|
|
95
95
|
text: {
|
|
96
|
-
bold:
|
|
97
|
-
italic:
|
|
98
|
-
underline:
|
|
96
|
+
bold: K().className,
|
|
97
|
+
italic: U().className,
|
|
98
|
+
underline: X().className
|
|
99
99
|
},
|
|
100
100
|
list: {
|
|
101
101
|
nested: {
|
|
102
|
-
listitem:
|
|
102
|
+
listitem: Y().className
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
},
|
|
106
|
-
const [i, s] =
|
|
105
|
+
}, b = M({ hasFocus: !1, editorRef: { current: null } }), ee = ({ onBlur: e }) => {
|
|
106
|
+
const [i, s] = B(!1), r = f(null), o = h(() => {
|
|
107
107
|
s(!0), r.current && window.clearTimeout(r.current);
|
|
108
|
-
}, []), n =
|
|
108
|
+
}, []), n = h(() => {
|
|
109
109
|
r.current = window.setTimeout(() => {
|
|
110
110
|
s(!1), e == null || e();
|
|
111
111
|
}, 0);
|
|
@@ -117,7 +117,7 @@ const W = ({
|
|
|
117
117
|
onBlur: n
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
|
-
},
|
|
120
|
+
}, Ne = () => q(b), te = A("div", {
|
|
121
121
|
border: "1px solid $borderDarker",
|
|
122
122
|
borderRadius: "$md",
|
|
123
123
|
position: "relative",
|
|
@@ -147,10 +147,10 @@ const W = ({
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
]
|
|
150
|
-
}),
|
|
150
|
+
}), oe = ({
|
|
151
151
|
isLoading: e
|
|
152
152
|
}) => /* @__PURE__ */ c.jsx(
|
|
153
|
-
|
|
153
|
+
x,
|
|
154
154
|
{
|
|
155
155
|
css: {
|
|
156
156
|
visibility: e ? "visible" : "hidden",
|
|
@@ -159,44 +159,47 @@ const W = ({
|
|
|
159
159
|
right: "1rem",
|
|
160
160
|
display: "flex"
|
|
161
161
|
},
|
|
162
|
-
children: /* @__PURE__ */ c.jsx(
|
|
162
|
+
children: /* @__PURE__ */ c.jsx(D, {})
|
|
163
163
|
}
|
|
164
|
-
),
|
|
164
|
+
), Te = ({
|
|
165
165
|
isLoading: e,
|
|
166
166
|
children: i,
|
|
167
167
|
placeholderText: s,
|
|
168
168
|
nodes: r,
|
|
169
169
|
plugins: o,
|
|
170
170
|
toolbar: n,
|
|
171
|
-
content: t
|
|
171
|
+
content: t,
|
|
172
|
+
hideBorder: l,
|
|
173
|
+
onBlur: m
|
|
172
174
|
}) => {
|
|
173
|
-
const { hasFocus: a, attributes:
|
|
174
|
-
return /* @__PURE__ */ c.jsx(
|
|
175
|
-
|
|
175
|
+
const { hasFocus: a, attributes: g } = ee({ onBlur: m }), u = f(null), C = z(() => ({ hasFocus: a, editorRef: u }), [a]);
|
|
176
|
+
return /* @__PURE__ */ c.jsx(b.Provider, { value: C, children: /* @__PURE__ */ c.jsxs(
|
|
177
|
+
V,
|
|
176
178
|
{
|
|
177
179
|
initialConfig: {
|
|
178
180
|
namespace: "CommentEditor",
|
|
179
|
-
onError: (
|
|
180
|
-
console.error(
|
|
181
|
+
onError: (N) => {
|
|
182
|
+
console.error(N);
|
|
181
183
|
},
|
|
182
|
-
theme:
|
|
184
|
+
theme: _,
|
|
183
185
|
nodes: r,
|
|
184
186
|
editable: !0
|
|
185
187
|
},
|
|
186
188
|
children: [
|
|
187
189
|
/* @__PURE__ */ c.jsxs(
|
|
188
|
-
|
|
190
|
+
te,
|
|
189
191
|
{
|
|
190
|
-
ref:
|
|
192
|
+
ref: u,
|
|
191
193
|
hasFocus: a,
|
|
192
|
-
|
|
194
|
+
hideBorder: l,
|
|
195
|
+
...g,
|
|
193
196
|
children: [
|
|
194
197
|
/* @__PURE__ */ c.jsx(
|
|
195
|
-
|
|
198
|
+
W,
|
|
196
199
|
{
|
|
197
200
|
contentEditable: t,
|
|
198
201
|
placeholder: s ? /* @__PURE__ */ c.jsx(
|
|
199
|
-
|
|
202
|
+
x,
|
|
200
203
|
{
|
|
201
204
|
css: {
|
|
202
205
|
position: "absolute",
|
|
@@ -209,11 +212,11 @@ const W = ({
|
|
|
209
212
|
children: s
|
|
210
213
|
}
|
|
211
214
|
) : null,
|
|
212
|
-
ErrorBoundary:
|
|
215
|
+
ErrorBoundary: J
|
|
213
216
|
}
|
|
214
217
|
),
|
|
215
218
|
o,
|
|
216
|
-
/* @__PURE__ */ c.jsx(
|
|
219
|
+
/* @__PURE__ */ c.jsx(oe, { isLoading: e }),
|
|
217
220
|
n
|
|
218
221
|
]
|
|
219
222
|
}
|
|
@@ -224,11 +227,11 @@ const W = ({
|
|
|
224
227
|
) });
|
|
225
228
|
};
|
|
226
229
|
export {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
Te as RichTextEditor,
|
|
231
|
+
Ce as defaultNodes,
|
|
232
|
+
G as isJSON,
|
|
233
|
+
b as richTextContext,
|
|
234
|
+
ge as stateToHTML,
|
|
235
|
+
ee as useHasFocusWithin,
|
|
236
|
+
Ne as useRichTextContext
|
|
234
237
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,6 @@ import { useRef, type ReactNode, useMemo, type ReactElement } from "react";
|
|
|
2
2
|
import { Box, Spinner, styled } from "../ui/ui";
|
|
3
3
|
import { type InitialConfigType, LexicalComposer } from "@lexical/react/LexicalComposer";
|
|
4
4
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
|
-
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
6
5
|
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
7
6
|
import { lexicalTheme } from "./theme";
|
|
8
7
|
import { useHasFocusWithin, richTextContext } from "./editorContext";
|
|
@@ -70,6 +69,8 @@ export const RichTextEditor = ({
|
|
|
70
69
|
plugins,
|
|
71
70
|
toolbar,
|
|
72
71
|
content,
|
|
72
|
+
hideBorder,
|
|
73
|
+
onBlur,
|
|
73
74
|
}: {
|
|
74
75
|
isLoading: boolean;
|
|
75
76
|
children: ReactNode;
|
|
@@ -78,8 +79,10 @@ export const RichTextEditor = ({
|
|
|
78
79
|
plugins?: ReactNode;
|
|
79
80
|
toolbar?: ReactNode;
|
|
80
81
|
content: ReactElement;
|
|
82
|
+
hideBorder?: boolean;
|
|
83
|
+
onBlur?: () => void;
|
|
81
84
|
}) => {
|
|
82
|
-
const { hasFocus, attributes } = useHasFocusWithin({});
|
|
85
|
+
const { hasFocus, attributes } = useHasFocusWithin({ onBlur });
|
|
83
86
|
const editorRef = useRef<HTMLDivElement>(null);
|
|
84
87
|
const contextValue = useMemo(() => ({ hasFocus, editorRef }), [hasFocus]);
|
|
85
88
|
|
|
@@ -99,6 +102,7 @@ export const RichTextEditor = ({
|
|
|
99
102
|
<Container
|
|
100
103
|
ref={editorRef}
|
|
101
104
|
hasFocus={hasFocus}
|
|
105
|
+
hideBorder={hideBorder}
|
|
102
106
|
{...attributes}
|
|
103
107
|
>
|
|
104
108
|
<RichTextPlugin
|