@arkitektbedriftene/fe-lib 0.3.9 → 0.3.10

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