@arkitektbedriftene/fe-lib 0.3.9 → 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.
- package/dist/lib/rich-text/Editor.d.ts +5 -2
- package/dist/rich-text.es.js +97 -126
- package/package.json +1 -1
- package/src/lib/rich-text/Editor.tsx +10 -39
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
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, }: {
|
|
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;
|
|
7
7
|
nodes: InitialConfigType["nodes"];
|
|
8
8
|
plugins?: ReactNode;
|
|
9
9
|
toolbar?: ReactNode;
|
|
10
|
+
content: ReactElement;
|
|
11
|
+
hideBorder?: boolean | undefined;
|
|
12
|
+
onBlur?: (() => void) | undefined;
|
|
10
13
|
}) => JSX.Element;
|
package/dist/rich-text.es.js
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
import { createHeadlessEditor as
|
|
2
|
-
import { $generateHtmlFromNodes as
|
|
3
|
-
import { $getRoot as p, ParagraphNode as
|
|
4
|
-
import { trimTextContentFromAnchor as
|
|
5
|
-
import { AutoLinkNode as
|
|
6
|
-
import { ListNode as w, ListItemNode as
|
|
7
|
-
import { HeadingNode as
|
|
8
|
-
import { TableNode as
|
|
9
|
-
import { j as
|
|
10
|
-
import { createContext as
|
|
11
|
-
import { c as
|
|
12
|
-
import { LexicalComposer as
|
|
13
|
-
import { RichTextPlugin as
|
|
14
|
-
import
|
|
15
|
-
import V from "@lexical/react/LexicalErrorBoundary";
|
|
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
|
+
import { j as c } from "./jsx-runtime-d0aa4c5b.js";
|
|
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";
|
|
16
15
|
import "react-dom";
|
|
17
|
-
const
|
|
16
|
+
const O = ({
|
|
18
17
|
text: e,
|
|
19
|
-
maxChars:
|
|
20
|
-
maxLines:
|
|
18
|
+
maxChars: i,
|
|
19
|
+
maxLines: s
|
|
21
20
|
}) => {
|
|
22
21
|
if (e.length === 0)
|
|
23
22
|
return 0;
|
|
24
|
-
const r = typeof
|
|
23
|
+
const r = typeof s == "number", o = typeof i == "number";
|
|
25
24
|
if (!r && !o)
|
|
26
25
|
return e.length;
|
|
27
|
-
let
|
|
28
|
-
for (; t < e.length && (!r ||
|
|
26
|
+
let n = 0, t = 0;
|
|
27
|
+
for (; t < e.length && (!r || n < s) && (!o || t < i); )
|
|
29
28
|
e[t] === `
|
|
30
|
-
` &&
|
|
29
|
+
` && n++, t++;
|
|
31
30
|
return e.slice(0, t).length;
|
|
32
|
-
},
|
|
31
|
+
}, Q = ({
|
|
33
32
|
editor: e,
|
|
34
|
-
maxChars:
|
|
35
|
-
maxLines:
|
|
33
|
+
maxChars: i,
|
|
34
|
+
maxLines: s
|
|
36
35
|
}) => {
|
|
37
|
-
const r = p(), o = r.getTextContent(),
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
return
|
|
41
|
-
},
|
|
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) => {
|
|
42
41
|
let r = 0;
|
|
43
|
-
const o =
|
|
44
|
-
nodes:
|
|
42
|
+
const o = T({
|
|
43
|
+
nodes: i,
|
|
45
44
|
editable: !1
|
|
46
45
|
});
|
|
47
46
|
if (e)
|
|
48
47
|
try {
|
|
49
|
-
if (typeof e == "string" && !
|
|
48
|
+
if (typeof e == "string" && !G(e))
|
|
50
49
|
o.update(() => {
|
|
51
|
-
const t = p(),
|
|
52
|
-
|
|
50
|
+
const t = p(), l = E();
|
|
51
|
+
l.append($(e.trim())), t.append(l);
|
|
53
52
|
});
|
|
54
53
|
else {
|
|
55
54
|
const t = o.parseEditorState(e, () => {
|
|
56
|
-
r =
|
|
55
|
+
r = Q({
|
|
57
56
|
editor: o,
|
|
58
|
-
maxLines:
|
|
57
|
+
maxLines: s == null ? void 0 : s.maxLines
|
|
59
58
|
});
|
|
60
59
|
});
|
|
61
60
|
t.isEmpty() || o.setEditorState(t);
|
|
@@ -63,62 +62,62 @@ const W = ({
|
|
|
63
62
|
} catch (t) {
|
|
64
63
|
console.error(t);
|
|
65
64
|
}
|
|
66
|
-
let
|
|
65
|
+
let n = "";
|
|
67
66
|
return o.update(() => {
|
|
68
|
-
|
|
69
|
-
}), { html:
|
|
67
|
+
n = y(o);
|
|
68
|
+
}), { html: n, trimCount: r };
|
|
70
69
|
}, Ce = [
|
|
71
|
-
F,
|
|
72
|
-
L,
|
|
73
|
-
w,
|
|
74
|
-
j,
|
|
75
|
-
E,
|
|
76
|
-
v,
|
|
77
70
|
R,
|
|
78
71
|
H,
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
w,
|
|
73
|
+
v,
|
|
74
|
+
L,
|
|
75
|
+
j,
|
|
76
|
+
k,
|
|
77
|
+
P,
|
|
78
|
+
I
|
|
79
|
+
], K = d({
|
|
81
80
|
fontWeight: "bold"
|
|
82
|
-
}),
|
|
81
|
+
}), U = d({
|
|
83
82
|
fontStyle: "italic"
|
|
84
|
-
}),
|
|
83
|
+
}), X = d({
|
|
85
84
|
textDecoration: "underline"
|
|
86
|
-
}),
|
|
85
|
+
}), Y = d({
|
|
87
86
|
listStyleType: "none"
|
|
88
|
-
}),
|
|
87
|
+
}), Z = d({
|
|
89
88
|
borderLeft: "4px solid #ccc",
|
|
90
89
|
color: "#666",
|
|
91
90
|
fontStyle: "italic",
|
|
92
91
|
margin: "1.5em 10px",
|
|
93
92
|
padding: "0.5em 10px"
|
|
94
|
-
}),
|
|
95
|
-
quote:
|
|
93
|
+
}), _ = {
|
|
94
|
+
quote: Z().className,
|
|
96
95
|
text: {
|
|
97
|
-
bold:
|
|
98
|
-
italic:
|
|
99
|
-
underline:
|
|
96
|
+
bold: K().className,
|
|
97
|
+
italic: U().className,
|
|
98
|
+
underline: X().className
|
|
100
99
|
},
|
|
101
100
|
list: {
|
|
102
101
|
nested: {
|
|
103
|
-
listitem:
|
|
102
|
+
listitem: Y().className
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
}, b =
|
|
107
|
-
const [
|
|
108
|
-
|
|
109
|
-
}, []),
|
|
105
|
+
}, b = M({ hasFocus: !1, editorRef: { current: null } }), ee = ({ onBlur: e }) => {
|
|
106
|
+
const [i, s] = B(!1), r = f(null), o = h(() => {
|
|
107
|
+
s(!0), r.current && window.clearTimeout(r.current);
|
|
108
|
+
}, []), n = h(() => {
|
|
110
109
|
r.current = window.setTimeout(() => {
|
|
111
|
-
|
|
110
|
+
s(!1), e == null || e();
|
|
112
111
|
}, 0);
|
|
113
112
|
}, [e]);
|
|
114
113
|
return {
|
|
115
|
-
hasFocus:
|
|
114
|
+
hasFocus: i,
|
|
116
115
|
attributes: {
|
|
117
116
|
onFocus: o,
|
|
118
|
-
onBlur:
|
|
117
|
+
onBlur: n
|
|
119
118
|
}
|
|
120
119
|
};
|
|
121
|
-
}, Ne = () =>
|
|
120
|
+
}, Ne = () => q(b), te = A("div", {
|
|
122
121
|
border: "1px solid $borderDarker",
|
|
123
122
|
borderRadius: "$md",
|
|
124
123
|
position: "relative",
|
|
@@ -148,33 +147,9 @@ const W = ({
|
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
]
|
|
151
|
-
}),
|
|
152
|
-
padding: "0 $4",
|
|
153
|
-
overflowY: "auto",
|
|
154
|
-
maxHeight: "30rem",
|
|
155
|
-
// backgroundColor: "white",
|
|
156
|
-
"&:focus-visible": {
|
|
157
|
-
outline: "none"
|
|
158
|
-
},
|
|
159
|
-
".main-content": {
|
|
160
|
-
padding: 12,
|
|
161
|
-
border: "1px solid $gray100",
|
|
162
|
-
borderRadius: "$md",
|
|
163
|
-
position: "relative",
|
|
164
|
-
"&::before": {
|
|
165
|
-
content: "Hovedinnhold",
|
|
166
|
-
position: "absolute",
|
|
167
|
-
top: -10,
|
|
168
|
-
left: 16,
|
|
169
|
-
backgroundColor: "white",
|
|
170
|
-
padding: "0 $1",
|
|
171
|
-
fontSize: 12,
|
|
172
|
-
color: "$gray500"
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}), te = ({
|
|
150
|
+
}), oe = ({
|
|
176
151
|
isLoading: e
|
|
177
|
-
}) => /* @__PURE__ */
|
|
152
|
+
}) => /* @__PURE__ */ c.jsx(
|
|
178
153
|
x,
|
|
179
154
|
{
|
|
180
155
|
css: {
|
|
@@ -184,50 +159,46 @@ const W = ({
|
|
|
184
159
|
right: "1rem",
|
|
185
160
|
display: "flex"
|
|
186
161
|
},
|
|
187
|
-
children: /* @__PURE__ */
|
|
162
|
+
children: /* @__PURE__ */ c.jsx(D, {})
|
|
188
163
|
}
|
|
189
164
|
), Te = ({
|
|
190
165
|
isLoading: e,
|
|
191
|
-
children:
|
|
192
|
-
placeholderText:
|
|
166
|
+
children: i,
|
|
167
|
+
placeholderText: s,
|
|
193
168
|
nodes: r,
|
|
194
169
|
plugins: o,
|
|
195
|
-
toolbar:
|
|
170
|
+
toolbar: n,
|
|
171
|
+
content: t,
|
|
172
|
+
hideBorder: l,
|
|
173
|
+
onBlur: m
|
|
196
174
|
}) => {
|
|
197
|
-
const { hasFocus:
|
|
198
|
-
return /* @__PURE__ */
|
|
199
|
-
|
|
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,
|
|
200
178
|
{
|
|
201
179
|
initialConfig: {
|
|
202
180
|
namespace: "CommentEditor",
|
|
203
|
-
onError: (
|
|
204
|
-
console.error(
|
|
181
|
+
onError: (N) => {
|
|
182
|
+
console.error(N);
|
|
205
183
|
},
|
|
206
|
-
theme:
|
|
184
|
+
theme: _,
|
|
207
185
|
nodes: r,
|
|
208
186
|
editable: !0
|
|
209
187
|
},
|
|
210
188
|
children: [
|
|
211
|
-
/* @__PURE__ */
|
|
212
|
-
|
|
189
|
+
/* @__PURE__ */ c.jsxs(
|
|
190
|
+
te,
|
|
213
191
|
{
|
|
214
|
-
ref:
|
|
215
|
-
hasFocus:
|
|
216
|
-
|
|
192
|
+
ref: u,
|
|
193
|
+
hasFocus: a,
|
|
194
|
+
hideBorder: l,
|
|
195
|
+
...g,
|
|
217
196
|
children: [
|
|
218
|
-
/* @__PURE__ */
|
|
219
|
-
|
|
197
|
+
/* @__PURE__ */ c.jsx(
|
|
198
|
+
W,
|
|
220
199
|
{
|
|
221
|
-
contentEditable:
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
css: {
|
|
225
|
-
paddingTop: 16,
|
|
226
|
-
paddingBottom: 16
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
),
|
|
230
|
-
placeholder: n ? /* @__PURE__ */ i.jsx(
|
|
200
|
+
contentEditable: t,
|
|
201
|
+
placeholder: s ? /* @__PURE__ */ c.jsx(
|
|
231
202
|
x,
|
|
232
203
|
{
|
|
233
204
|
css: {
|
|
@@ -238,19 +209,19 @@ const W = ({
|
|
|
238
209
|
pointerEvents: "none",
|
|
239
210
|
fontSize: "$sm"
|
|
240
211
|
},
|
|
241
|
-
children:
|
|
212
|
+
children: s
|
|
242
213
|
}
|
|
243
214
|
) : null,
|
|
244
|
-
ErrorBoundary:
|
|
215
|
+
ErrorBoundary: J
|
|
245
216
|
}
|
|
246
217
|
),
|
|
247
218
|
o,
|
|
248
|
-
/* @__PURE__ */
|
|
249
|
-
|
|
219
|
+
/* @__PURE__ */ c.jsx(oe, { isLoading: e }),
|
|
220
|
+
n
|
|
250
221
|
]
|
|
251
222
|
}
|
|
252
223
|
),
|
|
253
|
-
/* @__PURE__ */
|
|
224
|
+
/* @__PURE__ */ c.jsx(c.Fragment, { children: i })
|
|
254
225
|
]
|
|
255
226
|
}
|
|
256
227
|
) });
|
|
@@ -258,9 +229,9 @@ const W = ({
|
|
|
258
229
|
export {
|
|
259
230
|
Te as RichTextEditor,
|
|
260
231
|
Ce as defaultNodes,
|
|
261
|
-
|
|
232
|
+
G as isJSON,
|
|
262
233
|
b as richTextContext,
|
|
263
234
|
ge as stateToHTML,
|
|
264
|
-
|
|
235
|
+
ee as useHasFocusWithin,
|
|
265
236
|
Ne as useRichTextContext
|
|
266
237
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useRef, type ReactNode, useMemo } from "react";
|
|
1
|
+
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";
|
|
@@ -42,34 +41,6 @@ const Container = styled("div", {
|
|
|
42
41
|
],
|
|
43
42
|
});
|
|
44
43
|
|
|
45
|
-
const NewText = styled(ContentEditable, {}, {
|
|
46
|
-
padding: "0 $4",
|
|
47
|
-
overflowY: "auto",
|
|
48
|
-
maxHeight: "30rem",
|
|
49
|
-
// backgroundColor: "white",
|
|
50
|
-
"&:focus-visible": {
|
|
51
|
-
outline: "none",
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
".main-content": {
|
|
55
|
-
padding: 12,
|
|
56
|
-
border: "1px solid $gray100",
|
|
57
|
-
borderRadius: "$md",
|
|
58
|
-
position: "relative",
|
|
59
|
-
|
|
60
|
-
"&::before": {
|
|
61
|
-
content: "Hovedinnhold",
|
|
62
|
-
position: "absolute",
|
|
63
|
-
top: -10,
|
|
64
|
-
left: 16,
|
|
65
|
-
backgroundColor: "white",
|
|
66
|
-
padding: "0 $1",
|
|
67
|
-
fontSize: 12,
|
|
68
|
-
color: "$gray500",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
44
|
const EditorSpinner = ({
|
|
74
45
|
isLoading,
|
|
75
46
|
}: {
|
|
@@ -97,6 +68,9 @@ export const RichTextEditor = ({
|
|
|
97
68
|
nodes,
|
|
98
69
|
plugins,
|
|
99
70
|
toolbar,
|
|
71
|
+
content,
|
|
72
|
+
hideBorder,
|
|
73
|
+
onBlur,
|
|
100
74
|
}: {
|
|
101
75
|
isLoading: boolean;
|
|
102
76
|
children: ReactNode;
|
|
@@ -104,8 +78,11 @@ export const RichTextEditor = ({
|
|
|
104
78
|
nodes: InitialConfigType["nodes"];
|
|
105
79
|
plugins?: ReactNode;
|
|
106
80
|
toolbar?: ReactNode;
|
|
81
|
+
content: ReactElement;
|
|
82
|
+
hideBorder?: boolean;
|
|
83
|
+
onBlur?: () => void;
|
|
107
84
|
}) => {
|
|
108
|
-
const { hasFocus, attributes } = useHasFocusWithin({});
|
|
85
|
+
const { hasFocus, attributes } = useHasFocusWithin({ onBlur });
|
|
109
86
|
const editorRef = useRef<HTMLDivElement>(null);
|
|
110
87
|
const contextValue = useMemo(() => ({ hasFocus, editorRef }), [hasFocus]);
|
|
111
88
|
|
|
@@ -125,17 +102,11 @@ export const RichTextEditor = ({
|
|
|
125
102
|
<Container
|
|
126
103
|
ref={editorRef}
|
|
127
104
|
hasFocus={hasFocus}
|
|
105
|
+
hideBorder={hideBorder}
|
|
128
106
|
{...attributes}
|
|
129
107
|
>
|
|
130
108
|
<RichTextPlugin
|
|
131
|
-
contentEditable={
|
|
132
|
-
<NewText
|
|
133
|
-
css={{
|
|
134
|
-
paddingTop: 16,
|
|
135
|
-
paddingBottom: 16,
|
|
136
|
-
}}
|
|
137
|
-
/>
|
|
138
|
-
}
|
|
109
|
+
contentEditable={content}
|
|
139
110
|
placeholder={
|
|
140
111
|
placeholderText ? (
|
|
141
112
|
<Box
|