@open-commune/editor 0.1.3 → 0.1.5

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/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
+ import * as _tiptap_extension_details from '@tiptap/extension-details';
2
+ import * as _tiptap_core from '@tiptap/core';
3
+ import { Node } from '@tiptap/core';
1
4
  import * as _tiptap_extension_typography from '@tiptap/extension-typography';
2
5
  import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
3
6
  import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
4
7
  import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
5
8
  import * as _tiptap_extension_file_handler from '@tiptap/extension-file-handler';
6
- import * as _tiptap_core from '@tiptap/core';
7
- import { Node } from '@tiptap/core';
8
- import * as _tiptap_extension_details from '@tiptap/extension-details';
9
9
  import * as _tiptap_extension_unique_id from '@tiptap/extension-unique-id';
10
10
  import * as _tiptap_extension_list from '@tiptap/extension-list';
11
11
  import * as _tiptap_extension_link from '@tiptap/extension-link';
@@ -24,22 +24,6 @@ interface UploadPlaceholderOptions {
24
24
  */
25
25
  declare const UploadPlaceholder: Node<UploadPlaceholderOptions, any>;
26
26
 
27
- interface ImageNodeOptions {
28
- upload: ((file: File) => Promise<{
29
- id: string;
30
- src: string;
31
- title: string;
32
- }>) | null;
33
- fetch: ((attrs: {
34
- id: string;
35
- }) => Promise<{
36
- src?: string;
37
- title?: string;
38
- }>) | null;
39
- }
40
- /** Image node: TipTap Image plus the `id` of the backing media. */
41
- declare const ImageNode: _tiptap_core.Node<ImageNodeOptions, any>;
42
-
43
27
  /** Markdown-style `![title](src)` input rule, kept from the previous editor. */
44
28
  declare const fileInputRegex: RegExp;
45
29
  interface FileNodeOptions {
@@ -58,9 +42,9 @@ interface FileNodeOptions {
58
42
  }>) | null;
59
43
  }
60
44
  /**
61
- * Attached-file block (attrs src/id/alt/title). The residual legacy `data`
62
- * attr is intentionally NOT declared: the schema drops it on save, as the
63
- * previous editor already did — a documented harness exception.
45
+ * Attached-file block (attrs src/id/alt/title). A residual `data` attribute
46
+ * some stored documents carry is intentionally NOT declared: the schema drops
47
+ * it on save — a documented harness exception.
64
48
  */
65
49
  declare const FileNode: Node<FileNodeOptions, any>;
66
50
 
@@ -75,7 +59,7 @@ declare const FileNode: Node<FileNodeOptions, any>;
75
59
  * a silent mutation the conservation harness forbids. `link` and
76
60
  * `orderedList` are replaced below to keep the stored attribute sets.
77
61
  */
78
- declare const communStarterKit: {
62
+ declare const openCommuneStarterKit: {
79
63
  readonly code: false;
80
64
  readonly codeBlock: false;
81
65
  readonly strike: false;
@@ -85,10 +69,10 @@ declare const communStarterKit: {
85
69
  readonly orderedList: false;
86
70
  };
87
71
  /** Link without v3's `title` attr: declaring it would add a null key to every stored link on save. */
88
- declare const CommunLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
89
- /** OrderedList without v3's `type` attr (same rationale as CommunLink). */
90
- declare const CommunOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
91
- interface CommunEditorMedia {
72
+ declare const OpenCommuneLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
73
+ /** OrderedList without v3's `type` attr (same rationale as OpenCommuneLink). */
74
+ declare const OpenCommuneOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
75
+ interface OpenCommuneEditorMedia {
92
76
  upload: FileNodeOptions['upload'];
93
77
  fetch: FileNodeOptions['fetch'];
94
78
  }
@@ -96,7 +80,7 @@ interface CommunEditorMedia {
96
80
  * The parity extension set. UEditor must ALSO receive `:image="false"` and
97
81
  * `:mention="false"`: its defaults collide with our node names.
98
82
  */
99
- declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any> | _tiptap_core.Node<ImageNodeOptions, any> | _tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any> | _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any> | _tiptap_core.Extension<Omit<_tiptap_extension_file_handler.FileHandlePluginOptions, "key" | "editor">, any> | _tiptap_core.Extension<_tiptap_extension_text_align.TextAlignOptions, any> | _tiptap_core.Mark<_tiptap_extension_text_style.TextStyleOptions, any> | _tiptap_core.Mark<_tiptap_extension_highlight.HighlightOptions, any> | _tiptap_core.Extension<_tiptap_extension_typography.TypographyOptions, any> | _tiptap_core.Node<any, any>)[];
83
+ declare function openCommuneSchemaExtensions(media?: Partial<OpenCommuneEditorMedia>): (_tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any> | _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any> | _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any> | _tiptap_core.Extension<Omit<_tiptap_extension_file_handler.FileHandlePluginOptions, "key" | "editor">, any> | _tiptap_core.Extension<_tiptap_extension_text_align.TextAlignOptions, any> | _tiptap_core.Mark<_tiptap_extension_text_style.TextStyleOptions, any> | _tiptap_core.Mark<_tiptap_extension_highlight.HighlightOptions, any> | _tiptap_core.Extension<_tiptap_extension_typography.TypographyOptions, any> | _tiptap_core.Node<any, any> | _tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Node<FileNodeOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any>)[];
100
84
 
101
85
  /**
102
86
  * Stable block ids matching stored content: attribute `uid`, UUID v4.
@@ -113,6 +97,22 @@ declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOp
113
97
  */
114
98
  declare const Callout: Node<any, any>;
115
99
 
100
+ interface ImageNodeOptions {
101
+ upload: ((file: File) => Promise<{
102
+ id: string;
103
+ src: string;
104
+ title: string;
105
+ }>) | null;
106
+ fetch: ((attrs: {
107
+ id: string;
108
+ }) => Promise<{
109
+ src?: string;
110
+ title?: string;
111
+ }>) | null;
112
+ }
113
+ /** Image node: TipTap Image plus the `id` of the backing media. */
114
+ declare const ImageNode: _tiptap_core.Node<ImageNodeOptions, any>;
115
+
116
116
  /**
117
117
  * External-service iframe. Attrs mirror stored content exactly: embeds carry
118
118
  * no uid and `frameborder` is a string.
@@ -151,5 +151,5 @@ declare function sanitizeDoc<T extends {
151
151
  content?: any[];
152
152
  }>(doc: T): T;
153
153
 
154
- export { Callout, CommunLink, CommunOrderedList, Details, DetailsContent, DetailsSummary, EMBED_SERVICES, Embed, FileNode, ImageNode, UID_TYPES, Uid, UploadPlaceholder, communSchemaExtensions, communStarterKit, fileInputRegex, sanitizeDoc };
155
- export type { CommunEditorMedia, EmbedService, FileNodeOptions };
154
+ export { Callout, Details, DetailsContent, DetailsSummary, EMBED_SERVICES, Embed, FileNode, ImageNode, OpenCommuneLink, OpenCommuneOrderedList, UID_TYPES, Uid, UploadPlaceholder, fileInputRegex, openCommuneSchemaExtensions, openCommuneStarterKit, sanitizeDoc };
155
+ export type { EmbedService, FileNodeOptions, OpenCommuneEditorMedia };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
+ import * as _tiptap_extension_details from '@tiptap/extension-details';
2
+ import * as _tiptap_core from '@tiptap/core';
3
+ import { Node } from '@tiptap/core';
1
4
  import * as _tiptap_extension_typography from '@tiptap/extension-typography';
2
5
  import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
3
6
  import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
4
7
  import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
5
8
  import * as _tiptap_extension_file_handler from '@tiptap/extension-file-handler';
6
- import * as _tiptap_core from '@tiptap/core';
7
- import { Node } from '@tiptap/core';
8
- import * as _tiptap_extension_details from '@tiptap/extension-details';
9
9
  import * as _tiptap_extension_unique_id from '@tiptap/extension-unique-id';
10
10
  import * as _tiptap_extension_list from '@tiptap/extension-list';
11
11
  import * as _tiptap_extension_link from '@tiptap/extension-link';
@@ -24,22 +24,6 @@ interface UploadPlaceholderOptions {
24
24
  */
25
25
  declare const UploadPlaceholder: Node<UploadPlaceholderOptions, any>;
26
26
 
27
- interface ImageNodeOptions {
28
- upload: ((file: File) => Promise<{
29
- id: string;
30
- src: string;
31
- title: string;
32
- }>) | null;
33
- fetch: ((attrs: {
34
- id: string;
35
- }) => Promise<{
36
- src?: string;
37
- title?: string;
38
- }>) | null;
39
- }
40
- /** Image node: TipTap Image plus the `id` of the backing media. */
41
- declare const ImageNode: _tiptap_core.Node<ImageNodeOptions, any>;
42
-
43
27
  /** Markdown-style `![title](src)` input rule, kept from the previous editor. */
44
28
  declare const fileInputRegex: RegExp;
45
29
  interface FileNodeOptions {
@@ -58,9 +42,9 @@ interface FileNodeOptions {
58
42
  }>) | null;
59
43
  }
60
44
  /**
61
- * Attached-file block (attrs src/id/alt/title). The residual legacy `data`
62
- * attr is intentionally NOT declared: the schema drops it on save, as the
63
- * previous editor already did — a documented harness exception.
45
+ * Attached-file block (attrs src/id/alt/title). A residual `data` attribute
46
+ * some stored documents carry is intentionally NOT declared: the schema drops
47
+ * it on save — a documented harness exception.
64
48
  */
65
49
  declare const FileNode: Node<FileNodeOptions, any>;
66
50
 
@@ -75,7 +59,7 @@ declare const FileNode: Node<FileNodeOptions, any>;
75
59
  * a silent mutation the conservation harness forbids. `link` and
76
60
  * `orderedList` are replaced below to keep the stored attribute sets.
77
61
  */
78
- declare const communStarterKit: {
62
+ declare const openCommuneStarterKit: {
79
63
  readonly code: false;
80
64
  readonly codeBlock: false;
81
65
  readonly strike: false;
@@ -85,10 +69,10 @@ declare const communStarterKit: {
85
69
  readonly orderedList: false;
86
70
  };
87
71
  /** Link without v3's `title` attr: declaring it would add a null key to every stored link on save. */
88
- declare const CommunLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
89
- /** OrderedList without v3's `type` attr (same rationale as CommunLink). */
90
- declare const CommunOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
91
- interface CommunEditorMedia {
72
+ declare const OpenCommuneLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
73
+ /** OrderedList without v3's `type` attr (same rationale as OpenCommuneLink). */
74
+ declare const OpenCommuneOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
75
+ interface OpenCommuneEditorMedia {
92
76
  upload: FileNodeOptions['upload'];
93
77
  fetch: FileNodeOptions['fetch'];
94
78
  }
@@ -96,7 +80,7 @@ interface CommunEditorMedia {
96
80
  * The parity extension set. UEditor must ALSO receive `:image="false"` and
97
81
  * `:mention="false"`: its defaults collide with our node names.
98
82
  */
99
- declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any> | _tiptap_core.Node<ImageNodeOptions, any> | _tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any> | _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any> | _tiptap_core.Extension<Omit<_tiptap_extension_file_handler.FileHandlePluginOptions, "key" | "editor">, any> | _tiptap_core.Extension<_tiptap_extension_text_align.TextAlignOptions, any> | _tiptap_core.Mark<_tiptap_extension_text_style.TextStyleOptions, any> | _tiptap_core.Mark<_tiptap_extension_highlight.HighlightOptions, any> | _tiptap_core.Extension<_tiptap_extension_typography.TypographyOptions, any> | _tiptap_core.Node<any, any>)[];
83
+ declare function openCommuneSchemaExtensions(media?: Partial<OpenCommuneEditorMedia>): (_tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any> | _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any> | _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any> | _tiptap_core.Extension<Omit<_tiptap_extension_file_handler.FileHandlePluginOptions, "key" | "editor">, any> | _tiptap_core.Extension<_tiptap_extension_text_align.TextAlignOptions, any> | _tiptap_core.Mark<_tiptap_extension_text_style.TextStyleOptions, any> | _tiptap_core.Mark<_tiptap_extension_highlight.HighlightOptions, any> | _tiptap_core.Extension<_tiptap_extension_typography.TypographyOptions, any> | _tiptap_core.Node<any, any> | _tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Node<FileNodeOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any>)[];
100
84
 
101
85
  /**
102
86
  * Stable block ids matching stored content: attribute `uid`, UUID v4.
@@ -113,6 +97,22 @@ declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOp
113
97
  */
114
98
  declare const Callout: Node<any, any>;
115
99
 
100
+ interface ImageNodeOptions {
101
+ upload: ((file: File) => Promise<{
102
+ id: string;
103
+ src: string;
104
+ title: string;
105
+ }>) | null;
106
+ fetch: ((attrs: {
107
+ id: string;
108
+ }) => Promise<{
109
+ src?: string;
110
+ title?: string;
111
+ }>) | null;
112
+ }
113
+ /** Image node: TipTap Image plus the `id` of the backing media. */
114
+ declare const ImageNode: _tiptap_core.Node<ImageNodeOptions, any>;
115
+
116
116
  /**
117
117
  * External-service iframe. Attrs mirror stored content exactly: embeds carry
118
118
  * no uid and `frameborder` is a string.
@@ -151,5 +151,5 @@ declare function sanitizeDoc<T extends {
151
151
  content?: any[];
152
152
  }>(doc: T): T;
153
153
 
154
- export { Callout, CommunLink, CommunOrderedList, Details, DetailsContent, DetailsSummary, EMBED_SERVICES, Embed, FileNode, ImageNode, UID_TYPES, Uid, UploadPlaceholder, communSchemaExtensions, communStarterKit, fileInputRegex, sanitizeDoc };
155
- export type { CommunEditorMedia, EmbedService, FileNodeOptions };
154
+ export { Callout, Details, DetailsContent, DetailsSummary, EMBED_SERVICES, Embed, FileNode, ImageNode, OpenCommuneLink, OpenCommuneOrderedList, UID_TYPES, Uid, UploadPlaceholder, fileInputRegex, openCommuneSchemaExtensions, openCommuneStarterKit, sanitizeDoc };
155
+ export type { EmbedService, FileNodeOptions, OpenCommuneEditorMedia };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import S from"@tiptap/extension-text-align";import{TextStyle as H}from"@tiptap/extension-text-style";import D from"@tiptap/extension-highlight";import w from"@tiptap/extension-typography";import k from"@tiptap/extension-link";import{OrderedList as E}from"@tiptap/extension-list";import v from"@tiptap/extension-file-handler";import P from"@tiptap/extension-unique-id";import{Node as u,nodeInputRule as I,mergeAttributes as d}from"@tiptap/core";import $ from"@tiptap/extension-image";import{DetailsContent as O,DetailsSummary as z,Details as N}from"@tiptap/extension-details";import{Plugin as R,PluginKey as U,TextSelection as F}from"@tiptap/pm/state";const c=["paragraph","heading","listItem","bulletList","orderedList","blockquote","callout","file","image"],m=P.configure({attributeName:"uid",types:[...c]}),p=u.create({name:"callout",group:"block",content:"text*",draggable:!0,selectable:!0,inline:!1,defining:!1,addAttributes(){return{icon:{default:null,parseHTML:e=>e.getAttribute("data-icon"),renderHTML:e=>({"data-icon":e.icon})}}},parseHTML(){return[{tag:"aside"}]},renderHTML({HTMLAttributes:e}){return["aside",e,0]},addCommands(){return{setCallout:(e={})=>({commands:t})=>t.setNode(this.name,e)}}}),f=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,g=u.create({name:"file",group:"block",draggable:!0,inline:!1,addOptions(){return{upload:null,fetch:null,HTMLAttributes:{type:"file"}}},addAttributes(){return{src:{default:null,parseHTML:e=>{if(e.getAttribute("type")==="file")return e.getAttribute("src")}},id:{default:null},alt:{default:null},title:{default:null}}},parseHTML(){return[{tag:"input",attrs:{type:"file"}}]},renderHTML({HTMLAttributes:e}){return["input",d(this.options.HTMLAttributes,e)]},addCommands(){return{setFile:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[I({find:f,type:this.type,getAttributes:e=>{const[,,t,n,o]=e;return{src:n,alt:t,title:o}}})]}}),h=$.extend({addOptions(){return{...this.parent?.(),upload:null,fetch:null}},addAttributes(){const{width:e,height:t,...n}=this.parent?.()??{};return{...n,src:{default:null},id:{default:null},title:{default:null}}}}),b=u.create({name:"embed",group:"block",atom:!0,draggable:!0,selectable:!0,inline:!1,defining:!1,addAttributes(){return{service:{default:null},icon:{default:null},placeholder:{default:null},src:{default:null},title:{default:null},height:{default:null},frameborder:{default:"0"},allow:{default:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"},allowfullscreen:{default:!0}}},parseHTML(){return[{tag:"iframe[src]"}]},renderHTML({HTMLAttributes:e}){return["div",["iframe",e]]},addCommands(){return{setEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),V={video:{label:"Vid\xE9o",icon:"iconoir:youtube",placeholder:"Collez l'url YouTube ou Vimeo\u2026",title:"Lecteur vid\xE9o",height:315,toSrc:e=>{const t=e.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/);if(t)return`https://www.youtube.com/embed/${t[1]}`;const n=e.match(/vimeo\.com\/(\d+)/);return n?`https://player.vimeo.com/video/${n[1]}`:e}},map:{label:"Carte",icon:"iconoir:map-pin",placeholder:"Collez l'url d'int\xE9gration Google Maps\u2026",title:"Carte",height:400,toSrc:e=>e},form:{label:"Formulaire",icon:"iconoir:list-select",placeholder:"Collez l'url du formulaire (Typeform\u2026)\u2026",title:"Formulaire",height:500,toSrc:e=>e}},B=e=>e.content.childCount===1&&e.content.firstChild!==null&&e.content.firstChild.isTextblock&&e.openStart>0&&e.openEnd>0,y=N.extend({addAttributes(){return{toggle:{default:!0}}},addProseMirrorPlugins(){return[...this.parent?.()??[],new R({key:new U("communDetailsSummaryPaste"),props:{handlePaste:(e,t,n)=>{if(B(n))return!1;const{$head:o}=e.state.selection;for(let r=o.depth;r>0;r--){if(o.node(r).type.name!=="detailsSummary")continue;if(o.node(r-1).type.name!=="details")return!1;const a=o.after(r),l=e.state.tr.replaceRange(a+1,a+1,n),i=Math.min(a+1+n.size,l.doc.content.size);return l.setSelection(F.near(l.doc.resolve(i),-1)),l.setMeta("communDetailsOpenAt",a+1),e.dispatch(l.scrollIntoView()),!0}return!1}}})]}}),C=z,L=O,A=u.create({name:"imageUpload",group:"block",atom:!0,draggable:!0,addOptions(){return{upload:null}},parseHTML(){return[{tag:'div[data-type="image-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",d(e,{"data-type":"image-upload"})]},addCommands(){return{insertUploadPlaceholder:(e={})=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),_={code:!1,codeBlock:!1,strike:!1,underline:!1,trailingNode:!1,link:!1,orderedList:!1},T=k.extend({addAttributes(){const{title:e,...t}=this.parent?.()??{};return t}}).configure({openOnClick:!1,HTMLAttributes:{class:"underline text-primary",target:"_blank"}}),M=E.extend({addAttributes(){const{type:e,...t}=this.parent?.()??{};return t}});function K(e){const t=async(n,o,r)=>{for(const a of o){const{id:l,src:i,title:x}=await e(a),s={type:a.type.startsWith("image/")?"image":"file",attrs:{id:l,src:i,title:x}};r==null?n.chain().focus().insertContent(s).run():n.chain().insertContentAt(r,s).run()}};return v.configure({onDrop:(n,o,r)=>{t(n,o,r)},onPaste:(n,o)=>{t(n,o)}})}function Y(e={}){const t={upload:e.upload??null,fetch:e.fetch??null};return[m,...e.upload?[K(e.upload)]:[],T,M,S.configure({types:["heading","paragraph"]}),H.extend({priority:100}),D.configure({multicolor:!0}),w,p,A.configure({upload:t.upload}),g.configure(t),h.configure(t),b,y,C,L]}function j(e){let t=!1;const n=r=>{if(!r||typeof r!="object")return r;if(r.type==="text"&&!r.text)return t=!0,null;if(Array.isArray(r.content)){const a=r.content.map(n).filter(Boolean);return a.length!==r.content.length?{...r,content:a}:a.some((l,i)=>l!==r.content[i])?{...r,content:a}:r}return r},o=n(e);return t&&typeof console<"u"&&console.warn("[editor] repaired document: empty text node(s) dropped"),o}export{p as Callout,T as CommunLink,M as CommunOrderedList,y as Details,L as DetailsContent,C as DetailsSummary,V as EMBED_SERVICES,b as Embed,g as FileNode,h as ImageNode,c as UID_TYPES,m as Uid,A as UploadPlaceholder,Y as communSchemaExtensions,_ as communStarterKit,f as fileInputRegex,j as sanitizeDoc};
1
+ import S from"@tiptap/extension-text-align";import{TextStyle as H}from"@tiptap/extension-text-style";import D from"@tiptap/extension-highlight";import w from"@tiptap/extension-typography";import k from"@tiptap/extension-link";import{OrderedList as E}from"@tiptap/extension-list";import v from"@tiptap/extension-file-handler";import P from"@tiptap/extension-unique-id";import{Node as u,nodeInputRule as O,mergeAttributes as d}from"@tiptap/core";import I from"@tiptap/extension-image";import{DetailsContent as $,DetailsSummary as z,Details as N}from"@tiptap/extension-details";import{Plugin as R,PluginKey as U,TextSelection as F}from"@tiptap/pm/state";const c=["paragraph","heading","listItem","bulletList","orderedList","blockquote","callout","file","image"],m=P.configure({attributeName:"uid",types:[...c]}),p=u.create({name:"callout",group:"block",content:"text*",draggable:!0,selectable:!0,inline:!1,defining:!1,addAttributes(){return{icon:{default:null,parseHTML:e=>e.getAttribute("data-icon"),renderHTML:e=>({"data-icon":e.icon})}}},parseHTML(){return[{tag:"aside"}]},renderHTML({HTMLAttributes:e}){return["aside",e,0]},addCommands(){return{setCallout:(e={})=>({commands:t})=>t.setNode(this.name,e)}}}),f=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,g=u.create({name:"file",group:"block",draggable:!0,inline:!1,addOptions(){return{upload:null,fetch:null,HTMLAttributes:{type:"file"}}},addAttributes(){return{src:{default:null,parseHTML:e=>{if(e.getAttribute("type")==="file")return e.getAttribute("src")}},id:{default:null},alt:{default:null},title:{default:null}}},parseHTML(){return[{tag:"input",attrs:{type:"file"}}]},renderHTML({HTMLAttributes:e}){return["input",d(this.options.HTMLAttributes,e)]},addCommands(){return{setFile:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[O({find:f,type:this.type,getAttributes:e=>{const[,,t,n,o]=e;return{src:n,alt:t,title:o}}})]}}),h=I.extend({addOptions(){return{...this.parent?.(),upload:null,fetch:null}},addAttributes(){const{width:e,height:t,...n}=this.parent?.()??{};return{...n,src:{default:null},id:{default:null},title:{default:null}}}}),b=u.create({name:"embed",group:"block",atom:!0,draggable:!0,selectable:!0,inline:!1,defining:!1,addAttributes(){return{service:{default:null},icon:{default:null},placeholder:{default:null},src:{default:null},title:{default:null},height:{default:null},frameborder:{default:"0"},allow:{default:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"},allowfullscreen:{default:!0}}},parseHTML(){return[{tag:"iframe[src]"}]},renderHTML({HTMLAttributes:e}){return["div",["iframe",e]]},addCommands(){return{setEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),V={video:{label:"Vid\xE9o",icon:"iconoir:youtube",placeholder:"Collez l'url YouTube ou Vimeo\u2026",title:"Lecteur vid\xE9o",height:315,toSrc:e=>{const t=e.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/);if(t)return`https://www.youtube.com/embed/${t[1]}`;const n=e.match(/vimeo\.com\/(\d+)/);return n?`https://player.vimeo.com/video/${n[1]}`:e}},map:{label:"Carte",icon:"iconoir:map-pin",placeholder:"Collez l'url d'int\xE9gration Google Maps\u2026",title:"Carte",height:400,toSrc:e=>e},form:{label:"Formulaire",icon:"iconoir:list-select",placeholder:"Collez l'url du formulaire (Typeform\u2026)\u2026",title:"Formulaire",height:500,toSrc:e=>e}},B=e=>e.content.childCount===1&&e.content.firstChild!==null&&e.content.firstChild.isTextblock&&e.openStart>0&&e.openEnd>0,y=N.extend({addAttributes(){return{toggle:{default:!0}}},addProseMirrorPlugins(){return[...this.parent?.()??[],new R({key:new U("communDetailsSummaryPaste"),props:{handlePaste:(e,t,n)=>{if(B(n))return!1;const{$head:o}=e.state.selection;for(let r=o.depth;r>0;r--){if(o.node(r).type.name!=="detailsSummary")continue;if(o.node(r-1).type.name!=="details")return!1;const a=o.after(r),l=e.state.tr.replaceRange(a+1,a+1,n),i=Math.min(a+1+n.size,l.doc.content.size);return l.setSelection(F.near(l.doc.resolve(i),-1)),l.setMeta("communDetailsOpenAt",a+1),e.dispatch(l.scrollIntoView()),!0}return!1}}})]}}),C=z,L=$,A=u.create({name:"imageUpload",group:"block",atom:!0,draggable:!0,addOptions(){return{upload:null}},parseHTML(){return[{tag:'div[data-type="image-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",d(e,{"data-type":"image-upload"})]},addCommands(){return{insertUploadPlaceholder:(e={})=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),_={code:!1,codeBlock:!1,strike:!1,underline:!1,trailingNode:!1,link:!1,orderedList:!1},T=k.extend({addAttributes(){const{title:e,...t}=this.parent?.()??{};return t}}).configure({openOnClick:!1,HTMLAttributes:{class:"underline text-primary",target:"_blank"}}),M=E.extend({addAttributes(){const{type:e,...t}=this.parent?.()??{};return t}});function K(e){const t=async(n,o,r)=>{for(const a of o){const{id:l,src:i,title:x}=await e(a),s={type:a.type.startsWith("image/")?"image":"file",attrs:{id:l,src:i,title:x}};r==null?n.chain().focus().insertContent(s).run():n.chain().insertContentAt(r,s).run()}};return v.configure({onDrop:(n,o,r)=>{t(n,o,r)},onPaste:(n,o)=>{t(n,o)}})}function Y(e={}){const t={upload:e.upload??null,fetch:e.fetch??null};return[m,...e.upload?[K(e.upload)]:[],T,M,S.configure({types:["heading","paragraph"]}),H.extend({priority:100}),D.configure({multicolor:!0}),w,p,A.configure({upload:t.upload}),g.configure(t),h.configure(t),b,y,C,L]}function j(e){let t=!1;const n=r=>{if(!r||typeof r!="object")return r;if(r.type==="text"&&!r.text)return t=!0,null;if(Array.isArray(r.content)){const a=r.content.map(n).filter(Boolean);return a.length!==r.content.length?{...r,content:a}:a.some((l,i)=>l!==r.content[i])?{...r,content:a}:r}return r},o=n(e);return t&&typeof console<"u"&&console.warn("[editor] repaired document: empty text node(s) dropped"),o}export{p as Callout,y as Details,L as DetailsContent,C as DetailsSummary,V as EMBED_SERVICES,b as Embed,g as FileNode,h as ImageNode,T as OpenCommuneLink,M as OpenCommuneOrderedList,c as UID_TYPES,m as Uid,A as UploadPlaceholder,f as fileInputRegex,Y as openCommuneSchemaExtensions,_ as openCommuneStarterKit,j as sanitizeDoc};
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "description": "The rich-text editor: document schema, extensions and their sanitisation.",
38
38
  "license": "AGPL-3.0-or-later",
39
- "version": "0.1.3",
39
+ "version": "0.1.5",
40
40
  "sideEffects": false,
41
41
  "files": [
42
42
  "dist"