@okam/directus-flexible-content 1.3.2 → 1.3.8
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/CHANGELOG.md +39 -4
- package/README.md +3 -9
- package/index.js +1 -1
- package/index.mjs +159 -176
- package/lib/components/FlexibleEditorContent/extensions.d.ts +1 -1
- package/lib/components/FlexibleEditorContent/index.d.ts +4 -5
- package/lib/components/RenderNodes/index.d.ts +3 -4
- package/lib/components/attributes/remapAttributes.d.ts +2 -2
- package/lib/components/index.d.ts +1 -1
- package/lib/components/nodes/index.d.ts +0 -1
- package/lib/components/nodes/types.d.ts +3 -4
- package/lib/functions/index.d.ts +1 -1
- package/lib/functions/injectDataIntoContent.d.ts +1 -2
- package/lib/functions/mergeSerializers.d.ts +2 -3
- package/lib/functions/renderView.d.ts +2 -3
- package/lib/functions/types.d.ts +19 -10
- package/lib/types.d.ts +3 -4
- package/package.json +24 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
## 1.3.8 (2026-01-21)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated stack-ui to 1.44.4
|
|
6
|
+
- Updated directus-block to 1.7.8
|
|
7
|
+
|
|
8
|
+
## 1.3.6 (2026-01-19)
|
|
9
|
+
|
|
10
|
+
### 🧱 Updated Dependencies
|
|
11
|
+
|
|
12
|
+
- Updated stack-ui to 1.44.2
|
|
13
|
+
- Updated directus-block to 1.7.5
|
|
14
|
+
|
|
15
|
+
## 1.3.4 (2026-01-19)
|
|
16
|
+
|
|
17
|
+
### 🩹 Fixes
|
|
18
|
+
|
|
19
|
+
- cross-lib type imports are always absolute ([#392](https://github.com/OKAMca/stack/pull/392))
|
|
20
|
+
|
|
21
|
+
### ❤️ Thank You
|
|
22
|
+
|
|
23
|
+
- Pierre-Olivier Clerson @poclerson
|
|
24
|
+
|
|
25
|
+
## 1.3.3 (2026-01-19)
|
|
26
|
+
|
|
27
|
+
### 🩹 Fixes
|
|
28
|
+
|
|
29
|
+
- cross-lib type imports are always absolute ([#392](https://github.com/OKAMca/stack/pull/392))
|
|
30
|
+
|
|
31
|
+
### 🧱 Updated Dependencies
|
|
32
|
+
|
|
33
|
+
- Updated directus-block to 1.7.3
|
|
34
|
+
|
|
35
|
+
### ❤️ Thank You
|
|
36
|
+
|
|
37
|
+
- Pierre-Olivier Clerson @poclerson
|
|
38
|
+
|
|
1
39
|
## 1.3.2 (2026-01-16)
|
|
2
40
|
|
|
3
41
|
### 🧱 Updated Dependencies
|
|
@@ -11,6 +49,7 @@
|
|
|
11
49
|
|
|
12
50
|
- ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
|
|
13
51
|
- bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
|
|
52
|
+
- Consumers must now have react and react-dom in their own
|
|
14
53
|
|
|
15
54
|
### 🩹 Fixes
|
|
16
55
|
|
|
@@ -23,10 +62,6 @@
|
|
|
23
62
|
- search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
|
|
24
63
|
- select controlled ([#280](https://github.com/OKAMca/stack/pull/280))
|
|
25
64
|
|
|
26
|
-
### ⚠️ Breaking Changes
|
|
27
|
-
|
|
28
|
-
- Consumers must now have react and react-dom in their own
|
|
29
|
-
|
|
30
65
|
### ❤️ Thank You
|
|
31
66
|
|
|
32
67
|
- Marie-Maxime Tanguay @marie-maxime
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
| nodes | TRenderingNodes \| undefined | This takes in a config object for remapping default HTML semantic tags to React Components. |
|
|
18
18
|
| remappedAttributes | Record<string, string> \| undefined | This allows to remap HTML attributes to fix warnings or errors made by tiptap. |
|
|
19
19
|
|
|
20
|
-
### Configuring the flexible editor inside directus :
|
|
20
|
+
### Configuring the flexible editor inside directus :
|
|
21
21
|
|
|
22
22
|
- [Basic usage](https://github.com/formfcw/directus-extension-flexible-editor?tab=readme-ov-file#basic-usage)
|
|
23
23
|
- [With relation nodes](https://github.com/formfcw/directus-extension-flexible-editor?tab=readme-ov-file#usage-with-relation-nodes)
|
|
@@ -25,20 +25,16 @@
|
|
|
25
25
|
|
|
26
26
|
Adding blocks to the flexible editor options : the related blocks are handled in the Editor Nodes field beside the flexible editor field. You can add more collections by going in the relationship menu of the editor nodes and selecting additional collections in the associated collections section.
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
https://github.com/user-attachments/assets/576bdb52-f9bc-4835-ab2a-4c59995ae77f
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
30
|
Most of the time, if you want to insert blocks inside the flexible editor, you will need to follow the `With relation nodes and exisiting items` tutorial. Note that it is important to prefix related blocks for selection with `related_` so that a related block would look like `related_{block-collection}` so if you have a `block_faqs` your related collection key should be `related_block_faqs`.
|
|
34
31
|
|
|
35
32
|
IMPORTANT: when configuring the many to many relation inside your `related_{block-collection}` collection. The key of the field should always be `blocks`.
|
|
36
33
|

|
|
37
34
|
|
|
35
|
+
### Querying
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Here is an example of what querying should look like :
|
|
37
|
+
Here is an example of what querying should look like :
|
|
42
38
|
|
|
43
39
|
```graphql
|
|
44
40
|
flexible_editor
|
|
@@ -76,5 +72,3 @@ editor_nodes {
|
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
74
|
```
|
|
79
|
-
|
|
80
|
-
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),q=require("@okam/directus-block/server"),b=require("@tiptap/core"),B=require("@okam/stack-ui"),L=require("@tiptap/extension-subscript"),R=require("@tiptap/extension-superscript"),w=require("@tiptap/extension-table"),E=require("@tiptap/extension-table-cell"),I=require("@tiptap/extension-table-header"),J=require("@tiptap/extension-table-row"),j=require("@tiptap/extension-text-align"),D=require("@tiptap/starter-kit");function K(e,n,r="id",i="item"){const o=t=>{if(t==null)return null;if(e==null)return t;if(t.type==="relation-mark"&&t.attrs?.id||t.type==="relation-block"&&t.attrs?.id||t.type==="relation-inline-block"&&t.attrs?.id){const s=e.find(a=>a?.[r]===t.attrs?.id)?.[i];t.attrs.data=s}return t.content?.map(o),t.marks?.map(o),t};return o(n)}function _(e,n){const r=n.map(t=>(t.type==="mark"?b.Mark:b.Node).create({name:t.name,renderHTML({HTMLAttributes:a}){return t.render!=null?[...t.render(a),0]:[t.component??(t.type==="mark"?"span":"div"),a,0]}})),i=r.map(({name:t})=>t);return[...e.filter(t=>!i.includes(t.name)),...r]}function M(e,n,r){const i=r.find(o=>o.type===n&&o.name===e);if(i)return{...i.config,options:i.options}}function F(e,n){const r=n.addAttributes?.();return!r||!e?e:Object.fromEntries(Object.entries(e).filter(([i])=>r[i]?.rendered!==!1))}function y(e,n,r="node"){const i=M(e.type,r,n);if(!i?.renderHTML)return[];const o=F(e.attrs,i);return i.render?i.render(e):i.renderHTML({node:e,HTMLAttributes:o})}function O(e,n,r){if(e?.content&&(e.content=e.content.map(async s=>O(s,n,r))),e.type==="text"){if(e.marks){let s;return e.marks.reverse().forEach(a=>{const l=y({...a,attrs:{...a.attrs,data:{...a?.attrs?.data,markText:e.text}}},n,"mark");if(Array.isArray(l)){const[f="span",m=a.attrs]=l,u={...m,data:void 0};s=r(f,u,s??e.text)}else s=[{...l,text:e.text}]}),s}return e.text??""}if(M(e.type,"node",n)?.render)return y(e,n);const[o="div",t=e.attrs]=y(e,n);return r(o,t,e.content)}function P(e,n,r){return O(e,n,r)}const U={colspan:"colSpan",rowspan:"rowSpan",textAlign:"textalign"};function V(e,n){return{...Object.fromEntries(Object.entries(n).map(([r,i])=>[e?.[r]??U?.[r]??r,i]))}}const W={};function v(e){const{content:n,serializers:r=[],componentSerializers:i=[],renderingNodes:o,remappedAttributes:t,themeName:s,tokens:a,customTheme:l}=e,f=JSON.parse(JSON.stringify(n)),m=_(r,i);return P(f,m,(u,k,d)=>{const T={...k,style:void 0},g=V(t,T),S=u,c=o?.[S]??W?.[S];return c!=null?c({children:d,attrs:g,themeName:s,tokens:a,customTheme:l}):N.jsx(B.Box,{as:u,...g,themeName:s,tokens:a,customTheme:l,children:d},JSON.stringify(d))})}const $=[D.configure({dropcursor:!1,gapcursor:!1,undoRedo:!1,underline:!1}),w.Table,I.TableHeader,J.TableRow,E.TableCell,j,L,R];function G(e){const{jsonContent:n,editorNodes:r,serializers:i,nodes:o,config:t,relationMarksConfig:s,themeName:a,tokens:l,customTheme:f,remappedAttributes:m}=e,u=K(r,n),k=i??[...$],d=(c,z)=>{const{attrs:p}=c,H=`${p?.collection?.replace("related_","")}_id`;if(p?.data!=null){if(p.data.blocks==null){const x={collection:p.collection,item:{...p?.data}};return N.jsx(q.BlockDispatcher,{block:x,config:z},JSON.stringify(x))}const A=p?.data?.blocks,h=A?.map(x=>({item:x?.[H],collection:p?.collection}));return N.jsx(q.BlockDispatcher,{blocks:h,config:z},JSON.stringify(A))}return null},T=b.Node.create({name:"relation-block",renderHTML:()=>["relation-block"],render:c=>d(c,t)}),g=b.Node.create({name:"relation-inline-block",renderHTML:()=>["relation-inline-block"],render:c=>d(c,t)}),S=b.Mark.create({name:"relation-mark",renderHTML:()=>["relation-mark"],render:c=>d(c,s)});return k.push(T,g,S),u==null?null:N.jsx(v,{content:u,serializers:k,renderingNodes:o,themeName:a,tokens:l,customTheme:f,remappedAttributes:m})}exports.FlexibleEditorContent=G;exports.RenderNodes=v;
|
package/index.mjs
CHANGED
|
@@ -1,219 +1,202 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { BlockDispatcher as
|
|
3
|
-
import { Mark as
|
|
4
|
-
import { Box as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { Table as rr } from "@tiptap/extension-table";
|
|
23
|
-
import { TableCell as tr } from "@tiptap/extension-table-cell";
|
|
24
|
-
import { TableHeader as er } from "@tiptap/extension-table-header";
|
|
25
|
-
import { TableRow as or } from "@tiptap/extension-table-row";
|
|
26
|
-
import nr from "@tiptap/extension-text";
|
|
27
|
-
import ir from "@tiptap/extension-text-align";
|
|
28
|
-
const cr = (r, o, n = "id", e = "item") => {
|
|
29
|
-
const i = (t) => {
|
|
30
|
-
var s, a, m, u, d, p;
|
|
31
|
-
if (!r && t) return t;
|
|
32
|
-
if (!t || !r) return null;
|
|
33
|
-
if (t.type === "relation-mark" && ((s = t.attrs) != null && s.id) || t.type === "relation-block" && ((a = t.attrs) != null && a.id) || t.type === "relation-inline-block" && ((m = t.attrs) != null && m.id)) {
|
|
34
|
-
const k = (u = r.find((l) => {
|
|
35
|
-
var b;
|
|
36
|
-
return (l == null ? void 0 : l[n]) === ((b = t.attrs) == null ? void 0 : b.id);
|
|
37
|
-
})) == null ? void 0 : u[e];
|
|
38
|
-
t.attrs.data = k;
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { BlockDispatcher as M } from "@okam/directus-block/server";
|
|
3
|
+
import { Mark as O, Node as T } from "@tiptap/core";
|
|
4
|
+
import { Box as B } from "@okam/stack-ui";
|
|
5
|
+
import I from "@tiptap/extension-subscript";
|
|
6
|
+
import J from "@tiptap/extension-superscript";
|
|
7
|
+
import { Table as w } from "@tiptap/extension-table";
|
|
8
|
+
import { TableCell as E } from "@tiptap/extension-table-cell";
|
|
9
|
+
import { TableHeader as R } from "@tiptap/extension-table-header";
|
|
10
|
+
import { TableRow as K } from "@tiptap/extension-table-row";
|
|
11
|
+
import _ from "@tiptap/extension-text-align";
|
|
12
|
+
import D from "@tiptap/starter-kit";
|
|
13
|
+
function F(e, n, r = "id", i = "item") {
|
|
14
|
+
const o = (t) => {
|
|
15
|
+
if (t == null)
|
|
16
|
+
return null;
|
|
17
|
+
if (e == null)
|
|
18
|
+
return t;
|
|
19
|
+
if (t.type === "relation-mark" && t.attrs?.id || t.type === "relation-block" && t.attrs?.id || t.type === "relation-inline-block" && t.attrs?.id) {
|
|
20
|
+
const a = e.find((s) => s?.[r] === t.attrs?.id)?.[i];
|
|
21
|
+
t.attrs.data = a;
|
|
39
22
|
}
|
|
40
|
-
return
|
|
23
|
+
return t.content?.map(o), t.marks?.map(o), t;
|
|
41
24
|
};
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
25
|
+
return o(n);
|
|
26
|
+
}
|
|
27
|
+
function V(e, n) {
|
|
28
|
+
const r = n.map((t) => (t.type === "mark" ? O : T).create({
|
|
45
29
|
name: t.name,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return t.render ? [...t.render(a), 0] : [t.component ?? (t.type === "mark" ? "span" : "div"), a, 0];
|
|
30
|
+
renderHTML({ HTMLAttributes: s }) {
|
|
31
|
+
return t.render != null ? [...t.render(s), 0] : [t.component ?? (t.type === "mark" ? "span" : "div"), s, 0];
|
|
49
32
|
}
|
|
50
|
-
})),
|
|
51
|
-
return [...
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
})), i = r.map(({ name: t }) => t);
|
|
34
|
+
return [...e.filter((t) => !i.includes(t.name)), ...r];
|
|
35
|
+
}
|
|
36
|
+
function H(e, n, r) {
|
|
37
|
+
const i = r.find((o) => o.type === n && o.name === e);
|
|
38
|
+
if (i)
|
|
55
39
|
return {
|
|
56
|
-
...
|
|
57
|
-
options:
|
|
40
|
+
...i.config,
|
|
41
|
+
options: i.options
|
|
58
42
|
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
return !
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
HTMLAttributes: i
|
|
43
|
+
}
|
|
44
|
+
function W(e, n) {
|
|
45
|
+
const r = n.addAttributes?.();
|
|
46
|
+
return !r || !e ? e : Object.fromEntries(Object.entries(e).filter(([i]) => r[i]?.rendered !== !1));
|
|
47
|
+
}
|
|
48
|
+
function z(e, n, r = "node") {
|
|
49
|
+
const i = H(e.type, r, n);
|
|
50
|
+
if (!i?.renderHTML)
|
|
51
|
+
return [];
|
|
52
|
+
const o = W(e.attrs, i);
|
|
53
|
+
return i.render ? i.render(e) : i.renderHTML({
|
|
54
|
+
node: e,
|
|
55
|
+
HTMLAttributes: o
|
|
73
56
|
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
{ ...
|
|
82
|
-
|
|
57
|
+
}
|
|
58
|
+
function v(e, n, r) {
|
|
59
|
+
if (e?.content && (e.content = e.content.map(async (a) => v(a, n, r))), e.type === "text") {
|
|
60
|
+
if (e.marks) {
|
|
61
|
+
let a;
|
|
62
|
+
return e.marks.reverse().forEach((s) => {
|
|
63
|
+
const l = z(
|
|
64
|
+
{ ...s, attrs: { ...s.attrs, data: { ...s?.attrs?.data, markText: e.text } } },
|
|
65
|
+
n,
|
|
83
66
|
"mark"
|
|
84
67
|
);
|
|
85
|
-
if (Array.isArray(
|
|
86
|
-
const [d = "span",
|
|
87
|
-
|
|
68
|
+
if (Array.isArray(l)) {
|
|
69
|
+
const [d = "span", f = s.attrs] = l, u = { ...f, data: void 0 };
|
|
70
|
+
a = r(d, u, a ?? e.text);
|
|
88
71
|
} else
|
|
89
|
-
|
|
90
|
-
}),
|
|
72
|
+
a = [{ ...l, text: e.text }];
|
|
73
|
+
}), a;
|
|
91
74
|
}
|
|
92
|
-
return
|
|
75
|
+
return e.text ?? "";
|
|
93
76
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
77
|
+
if (H(e.type, "node", n)?.render)
|
|
78
|
+
return z(e, n);
|
|
79
|
+
const [o = "div", t = e.attrs] = z(e, n);
|
|
80
|
+
return r(o, t, e.content);
|
|
81
|
+
}
|
|
82
|
+
function $(e, n, r) {
|
|
83
|
+
return v(e, n, r);
|
|
84
|
+
}
|
|
85
|
+
const q = {
|
|
100
86
|
colspan: "colSpan",
|
|
101
87
|
rowspan: "rowSpan",
|
|
102
88
|
textAlign: "textalign"
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
89
|
+
};
|
|
90
|
+
function G(e, n) {
|
|
91
|
+
return {
|
|
92
|
+
...Object.fromEntries(
|
|
93
|
+
Object.entries(n).map(([r, i]) => [e?.[r] ?? q?.[r] ?? r, i])
|
|
94
|
+
)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const P = {};
|
|
98
|
+
function Q(e) {
|
|
108
99
|
const {
|
|
109
|
-
content:
|
|
110
|
-
serializers:
|
|
111
|
-
componentSerializers:
|
|
112
|
-
renderingNodes:
|
|
100
|
+
content: n,
|
|
101
|
+
serializers: r = [],
|
|
102
|
+
componentSerializers: i = [],
|
|
103
|
+
renderingNodes: o,
|
|
113
104
|
remappedAttributes: t,
|
|
114
|
-
themeName:
|
|
115
|
-
tokens:
|
|
116
|
-
customTheme:
|
|
117
|
-
} =
|
|
118
|
-
return
|
|
119
|
-
u,
|
|
105
|
+
themeName: a,
|
|
106
|
+
tokens: s,
|
|
107
|
+
customTheme: l
|
|
108
|
+
} = e, d = JSON.parse(JSON.stringify(n)), f = V(r, i);
|
|
109
|
+
return $(
|
|
120
110
|
d,
|
|
111
|
+
f,
|
|
121
112
|
// @ts-expect-error Expects ReactNode
|
|
122
|
-
(
|
|
123
|
-
const
|
|
124
|
-
...
|
|
113
|
+
(u, b, m) => {
|
|
114
|
+
const N = {
|
|
115
|
+
...b,
|
|
125
116
|
style: void 0
|
|
126
|
-
},
|
|
127
|
-
return
|
|
128
|
-
|
|
117
|
+
}, k = G(t, N), g = u, c = o?.[g] ?? P?.[g];
|
|
118
|
+
return c != null ? c({ children: m, attrs: k, themeName: a, tokens: s, customTheme: l }) : /* @__PURE__ */ y(
|
|
119
|
+
B,
|
|
129
120
|
{
|
|
130
|
-
as:
|
|
131
|
-
...
|
|
132
|
-
themeName:
|
|
133
|
-
tokens:
|
|
134
|
-
customTheme:
|
|
135
|
-
children:
|
|
121
|
+
as: u,
|
|
122
|
+
...k,
|
|
123
|
+
themeName: a,
|
|
124
|
+
tokens: s,
|
|
125
|
+
customTheme: l,
|
|
126
|
+
children: m
|
|
136
127
|
},
|
|
137
|
-
JSON.stringify(
|
|
128
|
+
JSON.stringify(m)
|
|
138
129
|
);
|
|
139
130
|
}
|
|
140
131
|
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
132
|
+
}
|
|
133
|
+
const U = [
|
|
134
|
+
D.configure({
|
|
135
|
+
// Disable extensions we don't need for read-only rendering
|
|
136
|
+
dropcursor: !1,
|
|
137
|
+
gapcursor: !1,
|
|
138
|
+
undoRedo: !1,
|
|
139
|
+
underline: !1
|
|
140
|
+
}),
|
|
141
|
+
// Extensions not included in StarterKit
|
|
142
|
+
w,
|
|
143
|
+
R,
|
|
148
144
|
K,
|
|
149
|
-
|
|
150
|
-
U,
|
|
151
|
-
D,
|
|
152
|
-
$,
|
|
153
|
-
Q,
|
|
145
|
+
E,
|
|
154
146
|
_,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
er,
|
|
160
|
-
or,
|
|
161
|
-
tr,
|
|
162
|
-
ir,
|
|
163
|
-
j,
|
|
164
|
-
C
|
|
165
|
-
], Fr = (r) => {
|
|
147
|
+
I,
|
|
148
|
+
J
|
|
149
|
+
];
|
|
150
|
+
function ce(e) {
|
|
166
151
|
const {
|
|
167
|
-
jsonContent:
|
|
168
|
-
editorNodes:
|
|
169
|
-
serializers:
|
|
170
|
-
nodes:
|
|
152
|
+
jsonContent: n,
|
|
153
|
+
editorNodes: r,
|
|
154
|
+
serializers: i,
|
|
155
|
+
nodes: o,
|
|
171
156
|
config: t,
|
|
172
|
-
relationMarksConfig:
|
|
173
|
-
themeName:
|
|
174
|
-
tokens:
|
|
175
|
-
customTheme:
|
|
176
|
-
remappedAttributes:
|
|
177
|
-
} =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return /* @__PURE__ */ x(h, { block: S, config: O }, JSON.stringify(S));
|
|
157
|
+
relationMarksConfig: a,
|
|
158
|
+
themeName: s,
|
|
159
|
+
tokens: l,
|
|
160
|
+
customTheme: d,
|
|
161
|
+
remappedAttributes: f
|
|
162
|
+
} = e, u = F(r, n), b = i ?? [...U], m = (c, x) => {
|
|
163
|
+
const { attrs: p } = c, L = `${p?.collection?.replace("related_", "")}_id`;
|
|
164
|
+
if (p?.data != null) {
|
|
165
|
+
if (p.data.blocks == null) {
|
|
166
|
+
const S = { collection: p.collection, item: { ...p?.data } };
|
|
167
|
+
return /* @__PURE__ */ y(M, { block: S, config: x }, JSON.stringify(S));
|
|
184
168
|
}
|
|
185
|
-
const
|
|
186
|
-
return /* @__PURE__ */
|
|
169
|
+
const A = p?.data?.blocks, h = A?.map((S) => ({ item: S?.[L], collection: p?.collection }));
|
|
170
|
+
return /* @__PURE__ */ y(M, { blocks: h, config: x }, JSON.stringify(A));
|
|
187
171
|
}
|
|
188
172
|
return null;
|
|
189
|
-
},
|
|
173
|
+
}, N = T.create({
|
|
190
174
|
name: "relation-block",
|
|
191
175
|
renderHTML: () => ["relation-block"],
|
|
192
|
-
render: (
|
|
193
|
-
}),
|
|
176
|
+
render: (c) => m(c, t)
|
|
177
|
+
}), k = T.create({
|
|
194
178
|
name: "relation-inline-block",
|
|
195
179
|
renderHTML: () => ["relation-inline-block"],
|
|
196
|
-
render: (
|
|
197
|
-
}),
|
|
180
|
+
render: (c) => m(c, t)
|
|
181
|
+
}), g = O.create({
|
|
198
182
|
name: "relation-mark",
|
|
199
|
-
type: "relation-mark",
|
|
200
183
|
renderHTML: () => ["relation-mark"],
|
|
201
|
-
render: (
|
|
184
|
+
render: (c) => m(c, a)
|
|
202
185
|
});
|
|
203
|
-
return
|
|
204
|
-
|
|
186
|
+
return b.push(N, k, g), u == null ? null : /* @__PURE__ */ y(
|
|
187
|
+
Q,
|
|
205
188
|
{
|
|
206
|
-
content:
|
|
207
|
-
serializers:
|
|
208
|
-
renderingNodes:
|
|
209
|
-
themeName:
|
|
210
|
-
tokens:
|
|
211
|
-
customTheme:
|
|
212
|
-
remappedAttributes:
|
|
189
|
+
content: u,
|
|
190
|
+
serializers: b,
|
|
191
|
+
renderingNodes: o,
|
|
192
|
+
themeName: s,
|
|
193
|
+
tokens: l,
|
|
194
|
+
customTheme: d,
|
|
195
|
+
remappedAttributes: f
|
|
213
196
|
}
|
|
214
|
-
)
|
|
215
|
-
}
|
|
197
|
+
);
|
|
198
|
+
}
|
|
216
199
|
export {
|
|
217
|
-
|
|
218
|
-
|
|
200
|
+
ce as FlexibleEditorContent,
|
|
201
|
+
Q as RenderNodes
|
|
219
202
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (import('@tiptap/core').Node<
|
|
1
|
+
declare const _default: (import('@tiptap/core').Extension<import('@tiptap/starter-kit').StarterKitOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-table').TableOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-table').TableHeaderOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-align').TextAlignOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-subscript').SubscriptExtensionOptions, any>)[];
|
|
2
2
|
export default _default;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { TBlockSerializerConfig } from '
|
|
2
|
-
import { TDefaultComponent } from '
|
|
3
|
-
import {
|
|
1
|
+
import { TBlockSerializerConfig } from '@okam/directus-block';
|
|
2
|
+
import { TDefaultComponent } from '@okam/stack-ui';
|
|
3
|
+
import { EditorNodes, Extensions, JSONContent } from '../../functions/types';
|
|
4
4
|
import { TRenderingNodes } from '../nodes/types';
|
|
5
|
-
|
|
6
5
|
interface FlexibleEditorContentProps extends TDefaultComponent {
|
|
7
6
|
jsonContent: JSONContent;
|
|
8
7
|
editorNodes?: EditorNodes[] | undefined | null;
|
|
@@ -12,5 +11,5 @@ interface FlexibleEditorContentProps extends TDefaultComponent {
|
|
|
12
11
|
nodes?: TRenderingNodes;
|
|
13
12
|
remappedAttributes?: Record<string, string>;
|
|
14
13
|
}
|
|
15
|
-
declare
|
|
14
|
+
declare function FlexibleEditorContent(props: FlexibleEditorContentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
16
15
|
export default FlexibleEditorContent;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { TDefaultComponent } from '
|
|
1
|
+
import { TDefaultComponent } from '@okam/stack-ui';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { Extensions, JSONContent, ReactComponentSerializers } from '../../functions/types';
|
|
4
4
|
import { TRenderingNodes } from '../nodes/types';
|
|
5
|
-
|
|
6
5
|
interface RenderNodesProps extends TDefaultComponent {
|
|
7
6
|
content: JSONContent;
|
|
8
7
|
serializers?: Extensions;
|
|
@@ -10,5 +9,5 @@ interface RenderNodesProps extends TDefaultComponent {
|
|
|
10
9
|
renderingNodes?: TRenderingNodes;
|
|
11
10
|
remappedAttributes?: Record<string, string>;
|
|
12
11
|
}
|
|
13
|
-
declare
|
|
12
|
+
declare function RenderNodes(props: RenderNodesProps): ReactNode;
|
|
14
13
|
export default RenderNodes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare
|
|
2
|
-
[
|
|
1
|
+
declare function remapAttributes(mappedAttributes: Record<string, string> | undefined, attrs: Record<string, number | string | undefined>): {
|
|
2
|
+
[k: string]: string | number | undefined;
|
|
3
3
|
};
|
|
4
4
|
export default remapAttributes;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { TDefaultComponent } from '
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { TDefaultComponent } from '@okam/stack-ui';
|
|
2
|
+
import type * as React from 'react';
|
|
4
3
|
export interface TBaseRenderingNode extends TDefaultComponent {
|
|
5
4
|
children: React.ReactNode;
|
|
6
5
|
attrs?: Record<string, number | string | boolean | undefined>;
|
|
7
6
|
}
|
|
8
7
|
export type TRenderingNodes = {
|
|
9
|
-
[
|
|
8
|
+
[_key in keyof React.JSX.IntrinsicElements]?: (_props: TBaseRenderingNode) => React.JSX.Element;
|
|
10
9
|
};
|
package/lib/functions/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JSONContent } from '@tiptap/core';
|
|
2
2
|
import { EditorNodes } from './types';
|
|
3
|
-
|
|
4
|
-
declare const injectDataIntoContent: (data: EditorNodes[] | undefined | null, content: JSONContent, primaryKeyField?: string, itemField?: string) => JSONContent | null;
|
|
3
|
+
declare function injectDataIntoContent(data: EditorNodes[] | undefined | null, content: JSONContent, primaryKeyField?: string, itemField?: string): JSONContent | null;
|
|
5
4
|
export default injectDataIntoContent;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const mergeSerializers: <T>(serializers: Extensions, componentSerializers: ComponentSerializers<T>) => Extensions;
|
|
1
|
+
import { ComponentSerializers, Extensions } from './types';
|
|
2
|
+
declare function mergeSerializers<T>(serializers: Extensions, componentSerializers: ComponentSerializers<T>): Extensions;
|
|
4
3
|
export default mergeSerializers;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { JSONContent,
|
|
3
|
-
|
|
4
|
-
declare const renderView: <T>(node: JSONContent, serializers: Extensions, renderCallback: RenderCallback<ReactNode | JSONContent[]>) => RenderedNode<T>;
|
|
2
|
+
import { Extensions, JSONContent, RenderCallback, RenderedNode } from './types';
|
|
3
|
+
declare function renderView<T>(node: JSONContent, serializers: Extensions, renderCallback: RenderCallback<ReactNode | JSONContent[]>): RenderedNode<T>;
|
|
5
4
|
export default renderView;
|
package/lib/functions/types.d.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import { TBlock } from '
|
|
2
|
-
import {
|
|
1
|
+
import { TBlock } from '@okam/directus-block';
|
|
2
|
+
import { AnyExtension, Extensions, JSONContent } from '@tiptap/core';
|
|
3
3
|
import { ElementType, FunctionComponent, ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
export type { JSONContent, Extensions };
|
|
4
|
+
export type { Extensions, JSONContent };
|
|
6
5
|
export type RenderedNode<T> = T | string | (T | string)[];
|
|
7
6
|
export type Tag = ElementType;
|
|
8
7
|
export type Attrs = JSONContent['attrs'];
|
|
9
8
|
export type NodeType = 'mark' | 'node';
|
|
10
|
-
export type RenderCallback<T> = (
|
|
9
|
+
export type RenderCallback<T> = (_tag: Tag, _attrs: Attrs, _content?: T) => RenderedNode<T>;
|
|
11
10
|
export type SerializedNode = [tag?: Tag, attrs?: Attrs];
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Custom serializer config type that includes the custom `render` property
|
|
13
|
+
* added via module augmentation in tiptap.d.ts
|
|
14
|
+
*/
|
|
15
|
+
export interface SerializerConfig {
|
|
13
16
|
options?: unknown;
|
|
14
|
-
renderHTML?: (
|
|
15
|
-
render?: (
|
|
16
|
-
addAttributes
|
|
17
|
+
renderHTML?: (_attributes: Record<string, unknown>) => SerializedNode;
|
|
18
|
+
render?: (_props: TBlock['item']) => ReactNode;
|
|
19
|
+
addAttributes?: () => Record<string, {
|
|
20
|
+
rendered?: boolean;
|
|
21
|
+
default?: unknown;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export type Serializer = AnyExtension & {
|
|
25
|
+
config: SerializerConfig;
|
|
17
26
|
};
|
|
18
27
|
export type ComponentSerializers<T> = {
|
|
19
28
|
name: string;
|
|
20
29
|
component?: T;
|
|
21
|
-
render?: (
|
|
30
|
+
render?: (_attrs: Attrs) => [Tag | T, Attrs];
|
|
22
31
|
type?: NodeType;
|
|
23
32
|
}[];
|
|
24
33
|
export type RelationBlockSerializers<T> = {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TCommonBlockFragment } from '
|
|
2
|
-
|
|
1
|
+
import { TCommonBlockFragment } from '@okam/directus-block';
|
|
3
2
|
export type RelationBlockSerializers<T> = {
|
|
4
3
|
collection: string;
|
|
5
4
|
component: T;
|
|
@@ -12,8 +11,8 @@ export type RelationBlockProps = RelationBlockAttrs & {
|
|
|
12
11
|
};
|
|
13
12
|
};
|
|
14
13
|
};
|
|
15
|
-
export
|
|
14
|
+
export interface RelationBlockAttrs {
|
|
16
15
|
id: string | null;
|
|
17
16
|
junction: string | null;
|
|
18
17
|
collection: string | null;
|
|
19
|
-
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-flexible-content",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "1.3.8",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "https://github.com/OKAMca/stack.git"
|
|
6
|
+
},
|
|
7
|
+
"sideEffects": false,
|
|
6
8
|
"exports": {
|
|
7
9
|
".": {
|
|
8
10
|
"import": {
|
|
@@ -15,46 +17,33 @@
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
},
|
|
20
|
+
"main": "./index.js",
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20.19.0"
|
|
24
|
+
},
|
|
18
25
|
"publishConfig": {
|
|
19
26
|
"access": "public"
|
|
20
27
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
23
30
|
},
|
|
24
31
|
"dependencies": {
|
|
25
32
|
"@nx/vite": "20.2.2",
|
|
26
|
-
"@okam/directus-block": "1.7.
|
|
27
|
-
"@okam/stack-ui": "1.44.
|
|
33
|
+
"@okam/directus-block": "1.7.8",
|
|
34
|
+
"@okam/stack-ui": "1.44.4",
|
|
35
|
+
"@tiptap/core": "^3.15.3",
|
|
36
|
+
"@tiptap/extension-subscript": "^3.15.3",
|
|
37
|
+
"@tiptap/extension-superscript": "^3.15.3",
|
|
38
|
+
"@tiptap/extension-table": "^3.15.3",
|
|
39
|
+
"@tiptap/extension-table-cell": "^3.15.3",
|
|
40
|
+
"@tiptap/extension-table-header": "^3.15.3",
|
|
41
|
+
"@tiptap/extension-table-row": "^3.15.3",
|
|
42
|
+
"@tiptap/extension-text-align": "^3.15.3",
|
|
43
|
+
"@tiptap/starter-kit": "^3.15.3",
|
|
28
44
|
"@vitejs/plugin-react": "4.3.4",
|
|
29
45
|
"vite": "^5.0.13",
|
|
30
|
-
"vite-plugin-dts": "~2.3.0"
|
|
31
|
-
"@tiptap/extension-blockquote": "^2.10.3",
|
|
32
|
-
"@tiptap/extension-bold": "^2.10.3",
|
|
33
|
-
"@tiptap/extension-bullet-list": "^2.10.3",
|
|
34
|
-
"@tiptap/extension-code": "^2.10.3",
|
|
35
|
-
"@tiptap/extension-code-block": "^2.10.3",
|
|
36
|
-
"@tiptap/extension-document": "^2.10.3",
|
|
37
|
-
"@tiptap/extension-hard-break": "^2.10.3",
|
|
38
|
-
"@tiptap/extension-heading": "^2.10.3",
|
|
39
|
-
"@tiptap/extension-horizontal-rule": "^2.10.3",
|
|
40
|
-
"@tiptap/extension-italic": "^2.10.3",
|
|
41
|
-
"@tiptap/extension-link": "^2.10.3",
|
|
42
|
-
"@tiptap/extension-list-item": "^2.10.3",
|
|
43
|
-
"@tiptap/extension-ordered-list": "^2.10.3",
|
|
44
|
-
"@tiptap/extension-paragraph": "^2.10.3",
|
|
45
|
-
"@tiptap/extension-strike": "^2.10.3",
|
|
46
|
-
"@tiptap/extension-subscript": "^2.10.3",
|
|
47
|
-
"@tiptap/extension-superscript": "^2.10.3",
|
|
48
|
-
"@tiptap/extension-table": "^2.10.3",
|
|
49
|
-
"@tiptap/extension-table-cell": "^2.10.3",
|
|
50
|
-
"@tiptap/extension-table-header": "^2.10.3",
|
|
51
|
-
"@tiptap/extension-table-row": "^2.10.3",
|
|
52
|
-
"@tiptap/extension-text": "^2.10.3",
|
|
53
|
-
"@tiptap/extension-text-align": "^2.10.3",
|
|
54
|
-
"@tiptap/core": "^2.10.3"
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
46
|
+
"vite-plugin-dts": "~2.3.0"
|
|
58
47
|
},
|
|
59
48
|
"devDependencies": {
|
|
60
49
|
"react": "^19.0.0"
|