@okam/directus-flexible-content 1.2.24 → 1.3.1

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 CHANGED
@@ -1,3 +1,88 @@
1
+ ## 1.3.0 (2026-01-16)
2
+
3
+ ### 🚀 Features
4
+
5
+ - ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
6
+ - bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
7
+
8
+ ### 🩹 Fixes
9
+
10
+ - **directus-flexible-content:** remove breaking changes tag ([37954b3](https://github.com/OKAMca/stack/commit/37954b3))
11
+ - **directus-flexible-content:** stop bundling okam libs ([cc8cfed](https://github.com/OKAMca/stack/commit/cc8cfed))
12
+ - **directus-flexible-content:** core-lib in external deps ([e44cb2b](https://github.com/OKAMca/stack/commit/e44cb2b))
13
+ - update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
14
+ - package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
15
+ - search field type export ([5ab6070](https://github.com/OKAMca/stack/commit/5ab6070))
16
+ - search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
17
+ - select controlled ([#280](https://github.com/OKAMca/stack/pull/280))
18
+
19
+ ### ⚠️ Breaking Changes
20
+
21
+ - Consumers must now have react and react-dom in their own
22
+
23
+ ### ❤️ Thank You
24
+
25
+ - Marie-Maxime Tanguay @marie-maxime
26
+ - Pierre-Olivier Clerson @poclerson
27
+ - poclerson
28
+
29
+ ## 1.2.26 (2026-01-16)
30
+
31
+ ### 🚀 Features
32
+
33
+ - ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
34
+ - bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
35
+ - Consumers must now have react and react-dom in their own
36
+
37
+ ### 🩹 Fixes
38
+
39
+ - **directus-flexible-content:** remove breaking changes tag ([37954b3](https://github.com/OKAMca/stack/commit/37954b3))
40
+ - **directus-flexible-content:** stop bundling okam libs ([cc8cfed](https://github.com/OKAMca/stack/commit/cc8cfed))
41
+ - **directus-flexible-content:** core-lib in external deps ([e44cb2b](https://github.com/OKAMca/stack/commit/e44cb2b))
42
+ - update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
43
+ - package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
44
+ - search field type export ([5ab6070](https://github.com/OKAMca/stack/commit/5ab6070))
45
+ - search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
46
+ - select controlled ([#280](https://github.com/OKAMca/stack/pull/280))
47
+
48
+ ### 🧱 Updated Dependencies
49
+
50
+ - Updated directus-block to 1.7.0
51
+
52
+ ### ❤️ Thank You
53
+
54
+ - Marie-Maxime Tanguay @marie-maxime
55
+ - Pierre-Olivier Clerson @poclerson
56
+ - poclerson
57
+
58
+ ## 1.2.25 (2026-01-14)
59
+
60
+ ### 🚀 Features
61
+
62
+ - ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
63
+ - Consumers must now have react and react-dom in their own
64
+ - bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
65
+
66
+ ### 🩹 Fixes
67
+
68
+ - **directus-flexible-content:** core-lib in external deps ([e44cb2b](https://github.com/OKAMca/stack/commit/e44cb2b))
69
+ - update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
70
+ - package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
71
+ - search field type export ([5ab6070](https://github.com/OKAMca/stack/commit/5ab6070))
72
+ - search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
73
+ - select controlled ([#280](https://github.com/OKAMca/stack/pull/280))
74
+
75
+ ### 🧱 Updated Dependencies
76
+
77
+ - Updated stack-ui to 1.44.0
78
+ - Updated directus-block to 1.6.3
79
+
80
+ ### ❤️ Thank You
81
+
82
+ - Marie-Maxime Tanguay @marie-maxime
83
+ - Pierre-Olivier Clerson @poclerson
84
+ - poclerson
85
+
1
86
  ## 1.2.24 (2026-01-13)
2
87
 
3
88
  ### 🚀 Features
@@ -621,4 +706,4 @@
621
706
 
622
707
  # 1.0.0 (2024-07-08)
623
708
 
624
- This was a version bump only for directus-flexible-content to align it with other projects, there were no code changes.
709
+ This was a version bump only for directus-flexible-content to align it with other projects, there were no code changes.
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),O=require("@tanstack/react-query"),_=require("radashi"),C=require("graphql-request"),E=require("@okam/stack-ui"),G=require("react"),B=require("@tiptap/core"),K=require("@tiptap/extension-blockquote"),V=require("@tiptap/extension-bold"),X=require("@tiptap/extension-bullet-list"),J=require("@tiptap/extension-code"),W=require("@tiptap/extension-code-block"),$=require("@tiptap/extension-document"),Y=require("@tiptap/extension-hard-break"),Z=require("@tiptap/extension-heading"),ee=require("@tiptap/extension-horizontal-rule"),te=require("@tiptap/extension-italic"),ne=require("@tiptap/extension-link"),re=require("@tiptap/extension-list-item"),oe=require("@tiptap/extension-ordered-list"),ie=require("@tiptap/extension-paragraph"),se=require("@tiptap/extension-strike"),ce=require("@tiptap/extension-subscript"),ae=require("@tiptap/extension-superscript"),le=require("@tiptap/extension-table"),ue=require("@tiptap/extension-table-cell"),de=require("@tiptap/extension-table-header"),me=require("@tiptap/extension-table-row"),fe=require("@tiptap/extension-text"),ge=require("@tiptap/extension-text-align");function H(e,n){return n}class q{constructor(n,r,t){this.nameSpace="[STACK]",this.suppressConsole=!1,this.env=process.env.NODE_ENV,this.nameSpace=n??this.nameSpace,this.suppressConsole=t??this.suppressConsole,this.logger=r??this.internalLogger}internalLogger(n,r,t){this.env!=="production"&&console[r||"log"](`${this.nameSpace} ${n}`.trimStart(),t??"")}setLogger(n){this.logger=(r,t,i)=>{this.suppressConsole&&this.internalLogger(r,t,i),n(r,t,i)}}static getInstance(){return q.instance||(q.instance=new q),q.instance}log(n,r,t){this.logger(n,r,t)}}q.getInstance();const pe=(e,n,r=!1)=>{const t=new q(e,n,r);return t.log("Logger initialized","info"),t},ke=pe("[DirectusQuery]"),ye=process.env.NEXT_PUBLIC_GRAPHQL_URL,be=process.env.NEXT_SERVER_GRAPHQL_URL,Ne=process.env.NEXT_GRAPHQL_URL_ADMIN,qe=process.env.NEXT_PUBLIC_API_TOKEN??"",Te=process.env.NEXT_PUBLIC_API_TOKEN,he=new C.GraphQLClient(be||ye,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${qe}`}});new C.GraphQLClient(Ne,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${Te}`}});new O.QueryClient({queryCache:new O.QueryCache({onError:e=>{ke.log("QueryClient Error","error",{error:e})}}),defaultOptions:{queries:{staleTime:5*1e3}}});function M(e,n,r=he){return r.request(e,{...n})}process.env.NEXT_PUBLIC_GRAPHQL_URL;process.env.NEXT_PUBLIC_API_TOKEN;function A(e){return!!e}function Be(e){const{id:n,settings:r,...t}=e??{};return _.isEmpty(t)}async function Se(e){const{document:n,blockKey:r,variables:t}=e;if(!n||!A(t))return null;const i=await M(n,t);return!i||typeof i!="object"||!r?null:i[r]}async function _e(e){const{document:n,item:r,blockKey:t,variables:i}=e;if(r){if(!Be(r))return r;const s={id:r.id,...i};return A(s)?Se({...e,variables:s}):null}if(!n||!A(i))return null;const o=await M(n,i);return!o||typeof o!="object"||!t?null:o[t]}function ve(e,...n){return n.reduce((t,i)=>i?{components:{...t.components,...i.components}}:t,e)}const z={kind:"Document",definitions:[{kind:"FragmentDefinition",name:{kind:"Name",value:"BlockSettings"},typeCondition:{kind:"NamedType",name:{kind:"Name",value:"block_settings"}},selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"tokens"}},{kind:"Field",name:{kind:"Name",value:"variant"}}]}}]},Le=e=>{var N,m,h;const{item:n,collection:r,config:t,variables:i,defaultVariant:o,...c}=e;if(!r||!t)return null;const s=(N=t==null?void 0:t.components)==null?void 0:N[r];if(!s)return null;const{settings:l}=n??{},u=(n==null?void 0:n.id)??(i==null?void 0:i.id);if(!u)return null;const{variant:g}=H(z,l)??{},f=((m=s.getVariant)==null?void 0:m.call(s,e))??g??o,{default:k,document:d}=s,b=((h=s.variants)==null?void 0:h[f??""])??k;return b?p.jsx(b,{document:d,config:t,collection:r,item:n,...u?{variables:{...i,id:u}}:{variables:i},...c},u):null};async function xe(e,n,r){const t=_.get(e,"item"),i=_.get(e,"document"),o=_.get(e,"variables"),c=await _e({item:t,blockKey:n,document:i,variables:o}),{tokens:s}=H(z,c==null?void 0:c.settings)??{};return{...c,cmsTokens:s}}const Ee=async e=>{const n="block_wysiwyg_by_id",{themeName:r="wysiwyg",tokens:t}=e,{content:i,title:o,level:c,cmsTokens:s}=await xe(e,n);return!i&&!(o&&c)?null:p.jsxs(p.Fragment,{children:[o&&c&&p.jsx(E.Box,{as:"span",themeName:r,tokens:{...t,...s},children:G.createElement(c,{},o)}),i&&p.jsx(E.WysiwygBlock,{themeName:r,tokens:{...t,...s},content:i})]})},Ae={block_wysiwyg:{default:e=>p.jsx(Ee,{...e})}},Ie={components:{...Ae}},P=e=>{const{children:n,config:r,...t}=e,i=ve(Ie,r),o=s=>n?n({...t,...s,config:i}):p.jsx(Le,{...t,...s,config:i});if("blocks"in e){const{blocks:s}=e;return s.map(o)}const{block:c}=e;return o(c)},Re=(e,n,r="id",t="item")=>{const i=o=>{var c,s,l,u,g,f;if(!e&&o)return o;if(!o||!e)return null;if(o.type==="relation-mark"&&((c=o.attrs)!=null&&c.id)||o.type==="relation-block"&&((s=o.attrs)!=null&&s.id)||o.type==="relation-inline-block"&&((l=o.attrs)!=null&&l.id)){const k=(u=e.find(d=>{var y;return(d==null?void 0:d[r])===((y=o.attrs)==null?void 0:y.id)}))==null?void 0:u[t];o.attrs.data=k}return(g=o.content)==null||g.map(i),(f=o.marks)==null||f.map(i),o};return i(n)},we=(e,n)=>{const r=n.map(o=>(o.type==="mark"?B.Mark:B.Node).create({name:o.name,renderHTML({HTMLAttributes:s}){return o.render?[...o.render(s),0]:[o.component??(o.type==="mark"?"span":"div"),s,0]}})),t=r.map(({name:o})=>o);return[...e.filter(o=>t.indexOf(o.name)<0),...r]},D=(e,n,r)=>{const t=r.find(i=>i.type===n&&i.name===e);if(t)return{...t.config,options:t.options}},Oe=(e,n)=>{var t;const r=(t=n.addAttributes)==null?void 0:t.call(n);return!r||!e?e:Object.fromEntries(Object.entries(e).filter(([i])=>{var o;return((o=r[i])==null?void 0:o.rendered)!==!1}))},v=(e,n,r="node")=>{const t=D(e.type,r,n);if(!(t!=null&&t.renderHTML))return[];const i=Oe(e.attrs,t);return t.render?t.render(e):t.renderHTML({node:e,HTMLAttributes:i})},F=(e,n,r)=>{if(e!=null&&e.content&&(e.content=e.content.map(c=>F(c,n,r))),e.type==="text"){if(e.marks){let c;return e.marks.reverse().forEach(s=>{var u;const l=v({...s,attrs:{...s.attrs,data:{...(u=s==null?void 0:s.attrs)==null?void 0:u.data,markText:e.text}}},n,"mark");if(Array.isArray(l)){const[g="span",f=s.attrs]=l,k={...f,data:void 0};c=r(g,k,c||e.text)}else c={...l,text:e.text}}),c}return e.text??""}const t=D(e.type,"node",n);if(t!=null&&t.render)return v(e,n);const[i="div",o=e.attrs]=v(e,n);return r(i,o,e.content)},Pe=(e,n,r)=>F(e,n,r),L={colspan:"colSpan",rowspan:"rowSpan",textAlign:"textalign"},Ce=(e,n)=>({...Object.fromEntries(Object.entries(n).map(([r,t])=>[(e==null?void 0:e[r])??(L==null?void 0:L[r])??r,t]))}),x={},Q=e=>{const{content:n,serializers:r=[],componentSerializers:t=[],renderingNodes:i,remappedAttributes:o,themeName:c,tokens:s,customTheme:l}=e,u=JSON.parse(JSON.stringify(n)),g=we(r,t);return Pe(u,g,(f,k,d)=>{const y={...k,style:void 0},b=Ce(o,y),N=f,m=(i==null?void 0:i[N])??(x==null?void 0:x[N]);return m?m({children:d,attrs:b,themeName:c,tokens:s,customTheme:l}):p.jsx(E.Box,{as:f,...b,themeName:c,tokens:s,customTheme:l,children:d},JSON.stringify(d))})},He=[$,fe,ie,Y,Z,W,X,oe,re,K,ee,ne,V,te,se,J,le.Table,de.TableHeader,me.TableRow,ue.TableCell,ge,ce,ae],Me=e=>{const{jsonContent:n,editorNodes:r,serializers:t,nodes:i,config:o,relationMarksConfig:c,themeName:s,tokens:l,customTheme:u,remappedAttributes:g}=e,f=Re(r,n),k=t??[...He]??[],d=(m,h)=>{var I,R,w;const{attrs:a}=m,U=`${(I=a==null?void 0:a.collection)==null?void 0:I.replace("related_","")}_id`;if(a!=null&&a.data){if(!((R=a==null?void 0:a.data)!=null&&R.blocks)){const T={collection:a.collection,item:{...a==null?void 0:a.data}};return p.jsx(P,{block:T,config:h},JSON.stringify(T))}const S=(w=a==null?void 0:a.data)==null?void 0:w.blocks,j=S==null?void 0:S.map(T=>({item:T==null?void 0:T[U],collection:a==null?void 0:a.collection}));return p.jsx(P,{blocks:j,config:h},JSON.stringify(S))}return null},y=B.Node.create({name:"relation-block",renderHTML:()=>["relation-block"],render:m=>d(m,o)}),b=B.Node.create({name:"relation-inline-block",renderHTML:()=>["relation-inline-block"],render:m=>d(m,o)}),N=B.Mark.create({name:"relation-mark",type:"relation-mark",renderHTML:()=>["relation-mark"],render:m=>d(m,c)});return k.push(y,b,N),f?p.jsx(Q,{content:f,serializers:k,renderingNodes:i,themeName:s,tokens:l,customTheme:u,remappedAttributes:g}):null};exports.FlexibleEditorContent=Me;exports.RenderNodes=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),A=require("@okam/directus-block/server"),x=require("@tiptap/core"),E=require("@okam/stack-ui"),J=require("@tiptap/extension-blockquote"),D=require("@tiptap/extension-bold"),_=require("@tiptap/extension-bullet-list"),j=require("@tiptap/extension-code"),F=require("@tiptap/extension-code-block"),K=require("@tiptap/extension-document"),P=require("@tiptap/extension-hard-break"),U=require("@tiptap/extension-heading"),V=require("@tiptap/extension-horizontal-rule"),W=require("@tiptap/extension-italic"),$=require("@tiptap/extension-link"),G=require("@tiptap/extension-list-item"),Q=require("@tiptap/extension-ordered-list"),X=require("@tiptap/extension-paragraph"),Y=require("@tiptap/extension-strike"),Z=require("@tiptap/extension-subscript"),C=require("@tiptap/extension-superscript"),ee=require("@tiptap/extension-table"),re=require("@tiptap/extension-table-cell"),te=require("@tiptap/extension-table-header"),ne=require("@tiptap/extension-table-row"),oe=require("@tiptap/extension-text"),ie=require("@tiptap/extension-text-align"),ce=(e,n,o="id",t="item")=>{const i=r=>{var a,s,l,f,m,d;if(!e&&r)return r;if(!r||!e)return null;if(r.type==="relation-mark"&&((a=r.attrs)!=null&&a.id)||r.type==="relation-block"&&((s=r.attrs)!=null&&s.id)||r.type==="relation-inline-block"&&((l=r.attrs)!=null&&l.id)){const b=(f=e.find(u=>{var k;return(u==null?void 0:u[o])===((k=r.attrs)==null?void 0:k.id)}))==null?void 0:f[t];r.attrs.data=b}return(m=r.content)==null||m.map(i),(d=r.marks)==null||d.map(i),r};return i(n)},se=(e,n)=>{const o=n.map(r=>(r.type==="mark"?x.Mark:x.Node).create({name:r.name,renderHTML({HTMLAttributes:s}){return r.render?[...r.render(s),0]:[r.component??(r.type==="mark"?"span":"div"),s,0]}})),t=o.map(({name:r})=>r);return[...e.filter(r=>t.indexOf(r.name)<0),...o]},v=(e,n,o)=>{const t=o.find(i=>i.type===n&&i.name===e);if(t)return{...t.config,options:t.options}},ae=(e,n)=>{var t;const o=(t=n.addAttributes)==null?void 0:t.call(n);return!o||!e?e:Object.fromEntries(Object.entries(e).filter(([i])=>{var r;return((r=o[i])==null?void 0:r.rendered)!==!1}))},N=(e,n,o="node")=>{const t=v(e.type,o,n);if(!(t!=null&&t.renderHTML))return[];const i=ae(e.attrs,t);return t.render?t.render(e):t.renderHTML({node:e,HTMLAttributes:i})},h=(e,n,o)=>{if(e!=null&&e.content&&(e.content=e.content.map(a=>h(a,n,o))),e.type==="text"){if(e.marks){let a;return e.marks.reverse().forEach(s=>{var f;const l=N({...s,attrs:{...s.attrs,data:{...(f=s==null?void 0:s.attrs)==null?void 0:f.data,markText:e.text}}},n,"mark");if(Array.isArray(l)){const[m="span",d=s.attrs]=l,b={...d,data:void 0};a=o(m,b,a||e.text)}else a={...l,text:e.text}}),a}return e.text??""}const t=v(e.type,"node",n);if(t!=null&&t.render)return N(e,n);const[i="div",r=e.attrs]=N(e,n);return o(i,r,e.content)},le=(e,n,o)=>h(e,n,o),B={colspan:"colSpan",rowspan:"rowSpan",textAlign:"textalign"},ue=(e,n)=>({...Object.fromEntries(Object.entries(n).map(([o,t])=>[(e==null?void 0:e[o])??(B==null?void 0:B[o])??o,t]))}),H={},I=e=>{const{content:n,serializers:o=[],componentSerializers:t=[],renderingNodes:i,remappedAttributes:r,themeName:a,tokens:s,customTheme:l}=e,f=JSON.parse(JSON.stringify(n)),m=se(o,t);return le(f,m,(d,b,u)=>{const k={...b,style:void 0},S=ue(r,k),T=d,p=(i==null?void 0:i[T])??(H==null?void 0:H[T]);return p?p({children:u,attrs:S,themeName:a,tokens:s,customTheme:l}):y.jsx(E.Box,{as:d,...S,themeName:a,tokens:s,customTheme:l,children:u},JSON.stringify(u))})},de=[K,oe,X,P,U,F,_,Q,G,J,V,$,D,W,Y,j,ee.Table,te.TableHeader,ne.TableRow,re.TableCell,ie,Z,C],pe=e=>{const{jsonContent:n,editorNodes:o,serializers:t,nodes:i,config:r,relationMarksConfig:a,themeName:s,tokens:l,customTheme:f,remappedAttributes:m}=e,d=ce(o,n),b=t??[...de]??[],u=(p,M)=>{var O,L,z;const{attrs:c}=p,R=`${(O=c==null?void 0:c.collection)==null?void 0:O.replace("related_","")}_id`;if(c!=null&&c.data){if(!((L=c==null?void 0:c.data)!=null&&L.blocks)){const q={collection:c.collection,item:{...c==null?void 0:c.data}};return y.jsx(A.BlockDispatcher,{block:q,config:M},JSON.stringify(q))}const g=(z=c==null?void 0:c.data)==null?void 0:z.blocks,w=g==null?void 0:g.map(q=>({item:q==null?void 0:q[R],collection:c==null?void 0:c.collection}));return y.jsx(A.BlockDispatcher,{blocks:w,config:M},JSON.stringify(g))}return null},k=x.Node.create({name:"relation-block",renderHTML:()=>["relation-block"],render:p=>u(p,r)}),S=x.Node.create({name:"relation-inline-block",renderHTML:()=>["relation-inline-block"],render:p=>u(p,r)}),T=x.Mark.create({name:"relation-mark",type:"relation-mark",renderHTML:()=>["relation-mark"],render:p=>u(p,a)});return b.push(k,S,T),d?y.jsx(I,{content:d,serializers:b,renderingNodes:i,themeName:s,tokens:l,customTheme:f,remappedAttributes:m}):null};exports.FlexibleEditorContent=pe;exports.RenderNodes=I;
package/index.mjs CHANGED
@@ -1,367 +1,219 @@
1
- import { jsx as k, jsxs as K, Fragment as G } from "react/jsx-runtime";
2
- import { QueryClient as V, QueryCache as X } from "@tanstack/react-query";
3
- import { isEmpty as J, get as _ } from "radashi";
4
- import { GraphQLClient as H } from "graphql-request";
5
- import { Box as C, WysiwygBlock as W } from "@okam/stack-ui";
6
- import $ from "react";
7
- import { Mark as x, Node as A } from "@tiptap/core";
8
- import j from "@tiptap/extension-blockquote";
9
- import Y from "@tiptap/extension-bold";
10
- import Z from "@tiptap/extension-bullet-list";
11
- import ee from "@tiptap/extension-code";
12
- import te from "@tiptap/extension-code-block";
13
- import re from "@tiptap/extension-document";
14
- import ne from "@tiptap/extension-hard-break";
15
- import oe from "@tiptap/extension-heading";
16
- import ie from "@tiptap/extension-horizontal-rule";
17
- import se from "@tiptap/extension-italic";
18
- import ce from "@tiptap/extension-link";
19
- import ae from "@tiptap/extension-list-item";
20
- import le from "@tiptap/extension-ordered-list";
21
- import me from "@tiptap/extension-paragraph";
22
- import ue from "@tiptap/extension-strike";
23
- import fe from "@tiptap/extension-subscript";
24
- import de from "@tiptap/extension-superscript";
25
- import { Table as pe } from "@tiptap/extension-table";
26
- import { TableCell as ge } from "@tiptap/extension-table-cell";
27
- import { TableHeader as ke } from "@tiptap/extension-table-header";
28
- import { TableRow as ye } from "@tiptap/extension-table-row";
29
- import Ne from "@tiptap/extension-text";
30
- import be from "@tiptap/extension-text-align";
31
- function q(e, r) {
32
- return r;
33
- }
34
- class T {
35
- constructor(r, n, t) {
36
- this.nameSpace = "[STACK]", this.suppressConsole = !1, this.env = process.env.NODE_ENV, this.nameSpace = r ?? this.nameSpace, this.suppressConsole = t ?? this.suppressConsole, this.logger = n ?? this.internalLogger;
37
- }
38
- internalLogger(r, n, t) {
39
- this.env !== "production" && console[n || "log"](`${this.nameSpace} ${r}`.trimStart(), t ?? "");
40
- }
41
- setLogger(r) {
42
- this.logger = (n, t, i) => {
43
- this.suppressConsole && this.internalLogger(n, t, i), r(n, t, i);
44
- };
45
- }
46
- static getInstance() {
47
- return T.instance || (T.instance = new T()), T.instance;
48
- }
49
- log(r, n, t) {
50
- this.logger(r, n, t);
51
- }
52
- }
53
- T.getInstance();
54
- const Te = (e, r, n = !1) => {
55
- const t = new T(e, r, n);
56
- return t.log("Logger initialized", "info"), t;
57
- }, he = Te("[DirectusQuery]"), Be = process.env.NEXT_PUBLIC_GRAPHQL_URL, Se = process.env.NEXT_SERVER_GRAPHQL_URL, _e = process.env.NEXT_GRAPHQL_URL_ADMIN, ve = process.env.NEXT_PUBLIC_API_TOKEN ?? "", Le = process.env.NEXT_PUBLIC_API_TOKEN, Ee = new H(Se || Be, {
58
- credentials: "include",
59
- mode: "cors",
60
- fetch,
61
- headers: {
62
- Authorization: `Bearer ${ve}`
63
- }
64
- });
65
- new H(_e, {
66
- credentials: "include",
67
- mode: "cors",
68
- fetch,
69
- headers: {
70
- Authorization: `Bearer ${Le}`
71
- }
72
- });
73
- new V({
74
- queryCache: new X({
75
- onError: (e) => {
76
- he.log("QueryClient Error", "error", { error: e });
77
- }
78
- }),
79
- defaultOptions: {
80
- queries: {
81
- staleTime: 5 * 1e3
1
+ import { jsx as x } from "react/jsx-runtime";
2
+ import { BlockDispatcher as h } from "@okam/directus-block/server";
3
+ import { Mark as v, Node as L } from "@tiptap/core";
4
+ import { Box as R } from "@okam/stack-ui";
5
+ import D from "@tiptap/extension-blockquote";
6
+ import _ from "@tiptap/extension-bold";
7
+ import K from "@tiptap/extension-bullet-list";
8
+ import q from "@tiptap/extension-code";
9
+ import F from "@tiptap/extension-code-block";
10
+ import P from "@tiptap/extension-document";
11
+ import V from "@tiptap/extension-hard-break";
12
+ import W from "@tiptap/extension-heading";
13
+ import $ from "@tiptap/extension-horizontal-rule";
14
+ import G from "@tiptap/extension-italic";
15
+ import Q from "@tiptap/extension-link";
16
+ import U from "@tiptap/extension-list-item";
17
+ import X from "@tiptap/extension-ordered-list";
18
+ import Y from "@tiptap/extension-paragraph";
19
+ import Z from "@tiptap/extension-strike";
20
+ import j from "@tiptap/extension-subscript";
21
+ import C from "@tiptap/extension-superscript";
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;
82
39
  }
83
- }
84
- });
85
- function z(e, r, n = Ee) {
86
- return n.request(e, {
87
- ...r
88
- });
89
- }
90
- process.env.NEXT_PUBLIC_GRAPHQL_URL;
91
- process.env.NEXT_PUBLIC_API_TOKEN;
92
- function I(e) {
93
- return !!e;
94
- }
95
- function Ae(e) {
96
- const { id: r, settings: n, ...t } = e ?? {};
97
- return J(t);
98
- }
99
- async function Ie(e) {
100
- const { document: r, blockKey: n, variables: t } = e;
101
- if (!r || !I(t)) return null;
102
- const i = await z(r, t);
103
- return !i || typeof i != "object" || !n ? null : i[n];
104
- }
105
- async function we(e) {
106
- const { document: r, item: n, blockKey: t, variables: i } = e;
107
- if (n) {
108
- if (!Ae(n))
109
- return n;
110
- const s = { id: n.id, ...i };
111
- return I(s) ? Ie({
112
- ...e,
113
- variables: s
114
- }) : null;
115
- }
116
- if (!r || !I(i)) return null;
117
- const o = await z(r, i);
118
- return !o || typeof o != "object" || !t ? null : o[t];
119
- }
120
- function Oe(e, ...r) {
121
- return r.reduce((t, i) => i ? { components: { ...t.components, ...i.components } } : t, e);
122
- }
123
- const D = { kind: "Document", definitions: [{ kind: "FragmentDefinition", name: { kind: "Name", value: "BlockSettings" }, typeCondition: { kind: "NamedType", name: { kind: "Name", value: "block_settings" } }, selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "tokens" } }, { kind: "Field", name: { kind: "Name", value: "variant" } }] } }] }, Pe = (e) => {
124
- var b, f, B;
125
- const { item: r, collection: n, config: t, variables: i, defaultVariant: o, ...c } = e;
126
- if (!n || !t) return null;
127
- const s = (b = t == null ? void 0 : t.components) == null ? void 0 : b[n];
128
- if (!s) return null;
129
- const { settings: l } = r ?? {}, m = (r == null ? void 0 : r.id) ?? (i == null ? void 0 : i.id);
130
- if (!m) return null;
131
- const { variant: p } = q(D, l) ?? {}, d = ((f = s.getVariant) == null ? void 0 : f.call(s, e)) ?? p ?? o, { default: g, document: u } = s, N = ((B = s.variants) == null ? void 0 : B[d ?? ""]) ?? g;
132
- return N ? /* @__PURE__ */ k(
133
- N,
134
- {
135
- document: u,
136
- config: t,
137
- collection: n,
138
- item: r,
139
- ...m ? { variables: { ...i, id: m } } : { variables: i },
140
- ...c
141
- },
142
- m
143
- ) : null;
144
- };
145
- async function Re(e, r, n) {
146
- const t = _(e, "item"), i = _(e, "document"), o = _(e, "variables"), c = await we({
147
- item: t,
148
- blockKey: r,
149
- document: i,
150
- variables: o
151
- }), { tokens: s } = q(D, c == null ? void 0 : c.settings) ?? {};
152
- return { ...c, cmsTokens: s };
153
- }
154
- const He = async (e) => {
155
- const r = "block_wysiwyg_by_id", { themeName: n = "wysiwyg", tokens: t } = e, { content: i, title: o, level: c, cmsTokens: s } = await Re(e, r);
156
- return !i && !(o && c) ? null : /* @__PURE__ */ K(G, { children: [
157
- o && c && /* @__PURE__ */ k(C, { as: "span", themeName: n, tokens: { ...t, ...s }, children: $.createElement(c, {}, o) }),
158
- i && /* @__PURE__ */ k(W, { themeName: n, tokens: { ...t, ...s }, content: i })
159
- ] });
160
- }, Ce = {
161
- block_wysiwyg: {
162
- default: (e) => /* @__PURE__ */ k(He, { ...e })
163
- }
164
- }, xe = {
165
- components: {
166
- ...Ce
167
- }
168
- }, R = (e) => {
169
- const { children: r, config: n, ...t } = e, i = Oe(xe, n), o = (s) => r ? r({ ...t, ...s, config: i }) : /* @__PURE__ */ k(Pe, { ...t, ...s, config: i });
170
- if ("blocks" in e) {
171
- const { blocks: s } = e;
172
- return s.map(o);
173
- }
174
- const { block: c } = e;
175
- return o(c);
176
- }, qe = (e, r, n = "id", t = "item") => {
177
- const i = (o) => {
178
- var c, s, l, m, p, d;
179
- if (!e && o) return o;
180
- if (!o || !e) return null;
181
- if (o.type === "relation-mark" && ((c = o.attrs) != null && c.id) || o.type === "relation-block" && ((s = o.attrs) != null && s.id) || o.type === "relation-inline-block" && ((l = o.attrs) != null && l.id)) {
182
- const g = (m = e.find((u) => {
183
- var y;
184
- return (u == null ? void 0 : u[n]) === ((y = o.attrs) == null ? void 0 : y.id);
185
- })) == null ? void 0 : m[t];
186
- o.attrs.data = g;
187
- }
188
- return (p = o.content) == null || p.map(i), (d = o.marks) == null || d.map(i), o;
40
+ return (d = t.content) == null || d.map(i), (p = t.marks) == null || p.map(i), t;
189
41
  };
190
- return i(r);
191
- }, ze = (e, r) => {
192
- const n = r.map((o) => (o.type === "mark" ? x : A).create({
193
- name: o.name,
42
+ return i(o);
43
+ }, ar = (r, o) => {
44
+ const n = o.map((t) => (t.type === "mark" ? v : L).create({
45
+ name: t.name,
194
46
  // eslint-disable-next-line
195
- renderHTML({ HTMLAttributes: s }) {
196
- return o.render ? [...o.render(s), 0] : [o.component ?? (o.type === "mark" ? "span" : "div"), s, 0];
47
+ renderHTML({ HTMLAttributes: a }) {
48
+ return t.render ? [...t.render(a), 0] : [t.component ?? (t.type === "mark" ? "span" : "div"), a, 0];
197
49
  }
198
- })), t = n.map(({ name: o }) => o);
199
- return [...e.filter((o) => t.indexOf(o.name) < 0), ...n];
200
- }, F = (e, r, n) => {
201
- const t = n.find((i) => i.type === r && i.name === e);
202
- if (t)
50
+ })), e = n.map(({ name: t }) => t);
51
+ return [...r.filter((t) => e.indexOf(t.name) < 0), ...n];
52
+ }, I = (r, o, n) => {
53
+ const e = n.find((i) => i.type === o && i.name === r);
54
+ if (e)
203
55
  return {
204
- ...t.config,
205
- options: t.options
56
+ ...e.config,
57
+ options: e.options
206
58
  };
207
- }, De = (e, r) => {
208
- var t;
209
- const n = (t = r.addAttributes) == null ? void 0 : t.call(r);
210
- return !n || !e ? e : Object.fromEntries(Object.entries(e).filter(([i]) => {
211
- var o;
212
- return ((o = n[i]) == null ? void 0 : o.rendered) !== !1;
59
+ }, sr = (r, o) => {
60
+ var e;
61
+ const n = (e = o.addAttributes) == null ? void 0 : e.call(o);
62
+ return !n || !r ? r : Object.fromEntries(Object.entries(r).filter(([i]) => {
63
+ var t;
64
+ return ((t = n[i]) == null ? void 0 : t.rendered) !== !1;
213
65
  }));
214
- }, v = (e, r, n = "node") => {
215
- const t = F(e.type, n, r);
216
- if (!(t != null && t.renderHTML)) return [];
217
- const i = De(e.attrs, t);
218
- return t.render ? t.render(e) : t.renderHTML({
219
- node: e,
66
+ }, N = (r, o, n = "node") => {
67
+ const e = I(r.type, n, o);
68
+ if (!(e != null && e.renderHTML)) return [];
69
+ const i = sr(r.attrs, e);
70
+ return e.render ? e.render(r) : e.renderHTML({
71
+ node: r,
220
72
  HTMLAttributes: i
221
73
  });
222
- }, M = (e, r, n) => {
223
- if (e != null && e.content && (e.content = e.content.map((c) => M(c, r, n))), e.type === "text") {
224
- if (e.marks) {
225
- let c;
226
- return e.marks.reverse().forEach((s) => {
227
- var m;
228
- const l = v(
229
- { ...s, attrs: { ...s.attrs, data: { ...(m = s == null ? void 0 : s.attrs) == null ? void 0 : m.data, markText: e.text } } },
230
- r,
74
+ }, J = (r, o, n) => {
75
+ if (r != null && r.content && (r.content = r.content.map((s) => J(s, o, n))), r.type === "text") {
76
+ if (r.marks) {
77
+ let s;
78
+ return r.marks.reverse().forEach((a) => {
79
+ var u;
80
+ const m = N(
81
+ { ...a, attrs: { ...a.attrs, data: { ...(u = a == null ? void 0 : a.attrs) == null ? void 0 : u.data, markText: r.text } } },
82
+ o,
231
83
  "mark"
232
84
  );
233
- if (Array.isArray(l)) {
234
- const [p = "span", d = s.attrs] = l, g = { ...d, data: void 0 };
235
- c = n(p, g, c || e.text);
85
+ if (Array.isArray(m)) {
86
+ const [d = "span", p = a.attrs] = m, k = { ...p, data: void 0 };
87
+ s = n(d, k, s || r.text);
236
88
  } else
237
- c = { ...l, text: e.text };
238
- }), c;
89
+ s = { ...m, text: r.text };
90
+ }), s;
239
91
  }
240
- return e.text ?? "";
92
+ return r.text ?? "";
241
93
  }
242
- const t = F(e.type, "node", r);
243
- if (t != null && t.render)
244
- return v(e, r);
245
- const [i = "div", o = e.attrs] = v(e, r);
246
- return n(i, o, e.content);
247
- }, Fe = (e, r, n) => M(e, r, n), L = {
94
+ const e = I(r.type, "node", o);
95
+ if (e != null && e.render)
96
+ return N(r, o);
97
+ const [i = "div", t = r.attrs] = N(r, o);
98
+ return n(i, t, r.content);
99
+ }, mr = (r, o, n) => J(r, o, n), B = {
248
100
  colspan: "colSpan",
249
101
  rowspan: "rowSpan",
250
102
  textAlign: "textalign"
251
- }, Me = (e, r) => ({
103
+ }, lr = (r, o) => ({
252
104
  ...Object.fromEntries(
253
- Object.entries(r).map(([n, t]) => [(e == null ? void 0 : e[n]) ?? (L == null ? void 0 : L[n]) ?? n, t])
105
+ Object.entries(o).map(([n, e]) => [(r == null ? void 0 : r[n]) ?? (B == null ? void 0 : B[n]) ?? n, e])
254
106
  )
255
- }), E = {}, Qe = (e) => {
107
+ }), H = {}, pr = (r) => {
256
108
  const {
257
- content: r,
109
+ content: o,
258
110
  serializers: n = [],
259
- componentSerializers: t = [],
111
+ componentSerializers: e = [],
260
112
  renderingNodes: i,
261
- remappedAttributes: o,
262
- themeName: c,
263
- tokens: s,
264
- customTheme: l
265
- } = e, m = JSON.parse(JSON.stringify(r)), p = ze(n, t);
266
- return Fe(
267
- m,
268
- p,
113
+ remappedAttributes: t,
114
+ themeName: s,
115
+ tokens: a,
116
+ customTheme: m
117
+ } = r, u = JSON.parse(JSON.stringify(o)), d = ar(n, e);
118
+ return mr(
119
+ u,
120
+ d,
269
121
  // @ts-expect-error Expects ReactNode
270
- (d, g, u) => {
271
- const y = {
272
- ...g,
122
+ (p, k, l) => {
123
+ const b = {
124
+ ...k,
273
125
  style: void 0
274
- }, N = Me(o, y), b = d, f = (i == null ? void 0 : i[b]) ?? (E == null ? void 0 : E[b]);
275
- return f ? f({ children: u, attrs: N, themeName: c, tokens: s, customTheme: l }) : /* @__PURE__ */ k(
276
- C,
126
+ }, g = lr(t, b), y = p, f = (i == null ? void 0 : i[y]) ?? (H == null ? void 0 : H[y]);
127
+ return f ? f({ children: l, attrs: g, themeName: s, tokens: a, customTheme: m }) : /* @__PURE__ */ x(
128
+ R,
277
129
  {
278
- as: d,
279
- ...N,
280
- themeName: c,
281
- tokens: s,
282
- customTheme: l,
283
- children: u
130
+ as: p,
131
+ ...g,
132
+ themeName: s,
133
+ tokens: a,
134
+ customTheme: m,
135
+ children: l
284
136
  },
285
- JSON.stringify(u)
137
+ JSON.stringify(l)
286
138
  );
287
139
  }
288
140
  );
289
- }, Ue = [
290
- re,
291
- Ne,
292
- me,
293
- ne,
294
- oe,
295
- te,
141
+ }, fr = [
142
+ P,
143
+ nr,
144
+ Y,
145
+ V,
146
+ W,
147
+ F,
148
+ K,
149
+ X,
150
+ U,
151
+ D,
152
+ $,
153
+ Q,
154
+ _,
155
+ G,
296
156
  Z,
297
- le,
298
- ae,
157
+ q,
158
+ rr,
159
+ er,
160
+ or,
161
+ tr,
162
+ ir,
299
163
  j,
300
- ie,
301
- ce,
302
- Y,
303
- se,
304
- ue,
305
- ee,
306
- pe,
307
- ke,
308
- ye,
309
- ge,
310
- be,
311
- fe,
312
- de
313
- ], ht = (e) => {
164
+ C
165
+ ], Fr = (r) => {
314
166
  const {
315
- jsonContent: r,
167
+ jsonContent: o,
316
168
  editorNodes: n,
317
- serializers: t,
169
+ serializers: e,
318
170
  nodes: i,
319
- config: o,
320
- relationMarksConfig: c,
321
- themeName: s,
322
- tokens: l,
323
- customTheme: m,
324
- remappedAttributes: p
325
- } = e, d = qe(n, r), g = t ?? [...Ue] ?? [], u = (f, B) => {
326
- var w, O, P;
327
- const { attrs: a } = f, Q = `${(w = a == null ? void 0 : a.collection) == null ? void 0 : w.replace("related_", "")}_id`;
328
- if (a != null && a.data) {
329
- if (!((O = a == null ? void 0 : a.data) != null && O.blocks)) {
330
- const h = { collection: a.collection, item: { ...a == null ? void 0 : a.data } };
331
- return /* @__PURE__ */ k(R, { block: h, config: B }, JSON.stringify(h));
171
+ config: t,
172
+ relationMarksConfig: s,
173
+ themeName: a,
174
+ tokens: m,
175
+ customTheme: u,
176
+ remappedAttributes: d
177
+ } = r, p = cr(n, o), k = e ?? [...fr] ?? [], l = (f, O) => {
178
+ var z, A, M;
179
+ const { attrs: c } = f, w = `${(z = c == null ? void 0 : c.collection) == null ? void 0 : z.replace("related_", "")}_id`;
180
+ if (c != null && c.data) {
181
+ if (!((A = c == null ? void 0 : c.data) != null && A.blocks)) {
182
+ const S = { collection: c.collection, item: { ...c == null ? void 0 : c.data } };
183
+ return /* @__PURE__ */ x(h, { block: S, config: O }, JSON.stringify(S));
332
184
  }
333
- const S = (P = a == null ? void 0 : a.data) == null ? void 0 : P.blocks, U = S == null ? void 0 : S.map((h) => ({ item: h == null ? void 0 : h[Q], collection: a == null ? void 0 : a.collection }));
334
- return /* @__PURE__ */ k(R, { blocks: U, config: B }, JSON.stringify(S));
185
+ const T = (M = c == null ? void 0 : c.data) == null ? void 0 : M.blocks, E = T == null ? void 0 : T.map((S) => ({ item: S == null ? void 0 : S[w], collection: c == null ? void 0 : c.collection }));
186
+ return /* @__PURE__ */ x(h, { blocks: E, config: O }, JSON.stringify(T));
335
187
  }
336
188
  return null;
337
- }, y = A.create({
189
+ }, b = L.create({
338
190
  name: "relation-block",
339
191
  renderHTML: () => ["relation-block"],
340
- render: (f) => u(f, o)
341
- }), N = A.create({
192
+ render: (f) => l(f, t)
193
+ }), g = L.create({
342
194
  name: "relation-inline-block",
343
195
  renderHTML: () => ["relation-inline-block"],
344
- render: (f) => u(f, o)
345
- }), b = x.create({
196
+ render: (f) => l(f, t)
197
+ }), y = v.create({
346
198
  name: "relation-mark",
347
199
  type: "relation-mark",
348
200
  renderHTML: () => ["relation-mark"],
349
- render: (f) => u(f, c)
201
+ render: (f) => l(f, s)
350
202
  });
351
- return g.push(y, N, b), d ? /* @__PURE__ */ k(
352
- Qe,
203
+ return k.push(b, g, y), p ? /* @__PURE__ */ x(
204
+ pr,
353
205
  {
354
- content: d,
355
- serializers: g,
206
+ content: p,
207
+ serializers: k,
356
208
  renderingNodes: i,
357
- themeName: s,
358
- tokens: l,
359
- customTheme: m,
360
- remappedAttributes: p
209
+ themeName: a,
210
+ tokens: m,
211
+ customTheme: u,
212
+ remappedAttributes: d
361
213
  }
362
214
  ) : null;
363
215
  };
364
216
  export {
365
- ht as FlexibleEditorContent,
366
- Qe as RenderNodes
217
+ Fr as FlexibleEditorContent,
218
+ pr as RenderNodes
367
219
  };
@@ -1,2 +1,2 @@
1
- declare const _default: (import('@tiptap/core').Node<any, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-align').TextAlignOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-subscript').SubscriptExtensionOptions, any>)[];
1
+ declare const _default: (import('@tiptap/core').Node<any, any> | import('@tiptap/core').Mark<import('@tiptap/extension-bold').BoldOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-align').TextAlignOptions, any>)[];
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/directus-flexible-content",
3
- "version": "1.2.24",
3
+ "version": "1.3.1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@nx/vite": "20.2.2",
26
- "@okam/directus-block": "1.6.2",
27
- "@okam/stack-ui": "1.43.0",
26
+ "@okam/directus-block": "1.7.1",
27
+ "@okam/stack-ui": "1.44.0",
28
28
  "@vitejs/plugin-react": "4.3.4",
29
29
  "vite": "^5.0.13",
30
30
  "vite-plugin-dts": "~2.3.0",