@open-commune/editor 0.1.2
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 +155 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.mjs +1 -0
- package/package.json +54 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as _tiptap_extension_typography from '@tiptap/extension-typography';
|
|
2
|
+
import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
|
|
3
|
+
import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
|
|
4
|
+
import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
|
|
5
|
+
import * as _tiptap_extension_file_handler from '@tiptap/extension-file-handler';
|
|
6
|
+
import * as _tiptap_extension_unique_id from '@tiptap/extension-unique-id';
|
|
7
|
+
import * as _tiptap_extension_details from '@tiptap/extension-details';
|
|
8
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
9
|
+
import { Node } from '@tiptap/core';
|
|
10
|
+
import * as _tiptap_extension_list from '@tiptap/extension-list';
|
|
11
|
+
import * as _tiptap_extension_link from '@tiptap/extension-link';
|
|
12
|
+
|
|
13
|
+
interface UploadPlaceholderOptions {
|
|
14
|
+
upload: ((file: File) => Promise<{
|
|
15
|
+
id: string;
|
|
16
|
+
src: string;
|
|
17
|
+
title: string;
|
|
18
|
+
}>) | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Transient upload slot inserted by the slash menu: shows a file picker in
|
|
22
|
+
* place, then replaces itself with the real image/file node. It must never
|
|
23
|
+
* reach saved content — input-editor strips it on emit.
|
|
24
|
+
*/
|
|
25
|
+
declare const UploadPlaceholder: Node<UploadPlaceholderOptions, any>;
|
|
26
|
+
|
|
27
|
+
/** Markdown-style `` input rule, kept from the previous editor. */
|
|
28
|
+
declare const fileInputRegex: RegExp;
|
|
29
|
+
interface FileNodeOptions {
|
|
30
|
+
/** Uploads a browser File, resolves to { id, src, title }. */
|
|
31
|
+
upload: ((file: File) => Promise<{
|
|
32
|
+
id: string;
|
|
33
|
+
src: string;
|
|
34
|
+
title: string;
|
|
35
|
+
}>) | null;
|
|
36
|
+
/** Resolves a media by id to { src, title } (shared cache, bounded concurrency). */
|
|
37
|
+
fetch: ((attrs: {
|
|
38
|
+
id: string;
|
|
39
|
+
}) => Promise<{
|
|
40
|
+
src?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
}>) | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Attached-file block (attrs src/id/alt/title). The residual legacy `data`
|
|
46
|
+
* attr is intentionally NOT declared: the schema drops it on save, as the
|
|
47
|
+
* previous editor already did — a documented harness exception.
|
|
48
|
+
*/
|
|
49
|
+
declare const FileNode: Node<FileNodeOptions, any>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* View-less extension assembly, importable outside the browser (conservation
|
|
53
|
+
* harness, tests). Node views attach in index.ts, the only browser entry.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* StarterKit options for UEditor. Marks absent from stored content are
|
|
57
|
+
* disabled so saves cannot produce nodes the public themes do not render.
|
|
58
|
+
* `trailingNode` appends a paragraph to documents ending on a block node —
|
|
59
|
+
* a silent mutation the conservation harness forbids. `link` and
|
|
60
|
+
* `orderedList` are replaced below to keep the stored attribute sets.
|
|
61
|
+
*/
|
|
62
|
+
declare const communStarterKit: {
|
|
63
|
+
readonly code: false;
|
|
64
|
+
readonly codeBlock: false;
|
|
65
|
+
readonly strike: false;
|
|
66
|
+
readonly underline: false;
|
|
67
|
+
readonly trailingNode: false;
|
|
68
|
+
readonly link: false;
|
|
69
|
+
readonly orderedList: false;
|
|
70
|
+
};
|
|
71
|
+
/** Link without v3's `title` attr: declaring it would add a null key to every stored link on save. */
|
|
72
|
+
declare const CommunLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
|
|
73
|
+
/** OrderedList without v3's `type` attr (same rationale as CommunLink). */
|
|
74
|
+
declare const CommunOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
|
|
75
|
+
interface CommunEditorMedia {
|
|
76
|
+
upload: FileNodeOptions['upload'];
|
|
77
|
+
fetch: FileNodeOptions['fetch'];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The parity extension set. UEditor must ALSO receive `:image="false"` and
|
|
81
|
+
* `:mention="false"`: its defaults collide with our node names.
|
|
82
|
+
*/
|
|
83
|
+
declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any> | _tiptap_core.Node<any, any> | _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<FileNodeOptions, any>)[];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stable block ids matching stored content: attribute `uid`, UUID v4.
|
|
87
|
+
* Existing ids are never regenerated; missing ones are filled on open.
|
|
88
|
+
* The type list is CLOSED — adding a type would rewrite every document on
|
|
89
|
+
* save, since none of the other nodes carry a uid.
|
|
90
|
+
*/
|
|
91
|
+
declare const UID_TYPES: readonly ["paragraph", "heading", "listItem", "bulletList", "orderedList", "blockquote", "callout", "file", "image"];
|
|
92
|
+
declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Info callout block. Content is bare text (no paragraphs) and `icon` holds
|
|
96
|
+
* a full Iconify name — both fixed by stored client content.
|
|
97
|
+
*/
|
|
98
|
+
declare const Callout: Node<any, any>;
|
|
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
|
+
/**
|
|
117
|
+
* External-service iframe. Attrs mirror stored content exactly: embeds carry
|
|
118
|
+
* no uid and `frameborder` is a string.
|
|
119
|
+
*/
|
|
120
|
+
declare const Embed: Node<any, any>;
|
|
121
|
+
/**
|
|
122
|
+
* Embed services. Stored content only uses `video`; new services extend this
|
|
123
|
+
* table without touching the node contract (same attrs for every service).
|
|
124
|
+
*/
|
|
125
|
+
interface EmbedService {
|
|
126
|
+
label: string;
|
|
127
|
+
icon: string;
|
|
128
|
+
placeholder: string;
|
|
129
|
+
title: string;
|
|
130
|
+
height: number;
|
|
131
|
+
toSrc: (url: string) => string;
|
|
132
|
+
}
|
|
133
|
+
declare const EMBED_SERVICES: Record<string, EmbedService>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Accordion trio on the official Details extensions. `toggle` REPLACES the
|
|
137
|
+
* stock `open` attribute: stored documents only carry `toggle`. Node views
|
|
138
|
+
* attach in index.ts; open state is editing state, never written to content.
|
|
139
|
+
*/
|
|
140
|
+
declare const Details: _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any>;
|
|
141
|
+
declare const DetailsSummary: _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any>;
|
|
142
|
+
declare const DetailsContent: _tiptap_core.Node<_tiptap_extension_details.DetailsContentOptions, any>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Drops text nodes without text — invalid ProseMirror inherited from the
|
|
146
|
+
* migration; every editor rejects them and themes render them as nothing.
|
|
147
|
+
* Returns the same reference when nothing needs repair.
|
|
148
|
+
*/
|
|
149
|
+
declare function sanitizeDoc<T extends {
|
|
150
|
+
type?: string;
|
|
151
|
+
content?: any[];
|
|
152
|
+
}>(doc: T): T;
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as _tiptap_extension_typography from '@tiptap/extension-typography';
|
|
2
|
+
import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
|
|
3
|
+
import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
|
|
4
|
+
import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
|
|
5
|
+
import * as _tiptap_extension_file_handler from '@tiptap/extension-file-handler';
|
|
6
|
+
import * as _tiptap_extension_unique_id from '@tiptap/extension-unique-id';
|
|
7
|
+
import * as _tiptap_extension_details from '@tiptap/extension-details';
|
|
8
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
9
|
+
import { Node } from '@tiptap/core';
|
|
10
|
+
import * as _tiptap_extension_list from '@tiptap/extension-list';
|
|
11
|
+
import * as _tiptap_extension_link from '@tiptap/extension-link';
|
|
12
|
+
|
|
13
|
+
interface UploadPlaceholderOptions {
|
|
14
|
+
upload: ((file: File) => Promise<{
|
|
15
|
+
id: string;
|
|
16
|
+
src: string;
|
|
17
|
+
title: string;
|
|
18
|
+
}>) | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Transient upload slot inserted by the slash menu: shows a file picker in
|
|
22
|
+
* place, then replaces itself with the real image/file node. It must never
|
|
23
|
+
* reach saved content — input-editor strips it on emit.
|
|
24
|
+
*/
|
|
25
|
+
declare const UploadPlaceholder: Node<UploadPlaceholderOptions, any>;
|
|
26
|
+
|
|
27
|
+
/** Markdown-style `` input rule, kept from the previous editor. */
|
|
28
|
+
declare const fileInputRegex: RegExp;
|
|
29
|
+
interface FileNodeOptions {
|
|
30
|
+
/** Uploads a browser File, resolves to { id, src, title }. */
|
|
31
|
+
upload: ((file: File) => Promise<{
|
|
32
|
+
id: string;
|
|
33
|
+
src: string;
|
|
34
|
+
title: string;
|
|
35
|
+
}>) | null;
|
|
36
|
+
/** Resolves a media by id to { src, title } (shared cache, bounded concurrency). */
|
|
37
|
+
fetch: ((attrs: {
|
|
38
|
+
id: string;
|
|
39
|
+
}) => Promise<{
|
|
40
|
+
src?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
}>) | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Attached-file block (attrs src/id/alt/title). The residual legacy `data`
|
|
46
|
+
* attr is intentionally NOT declared: the schema drops it on save, as the
|
|
47
|
+
* previous editor already did — a documented harness exception.
|
|
48
|
+
*/
|
|
49
|
+
declare const FileNode: Node<FileNodeOptions, any>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* View-less extension assembly, importable outside the browser (conservation
|
|
53
|
+
* harness, tests). Node views attach in index.ts, the only browser entry.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* StarterKit options for UEditor. Marks absent from stored content are
|
|
57
|
+
* disabled so saves cannot produce nodes the public themes do not render.
|
|
58
|
+
* `trailingNode` appends a paragraph to documents ending on a block node —
|
|
59
|
+
* a silent mutation the conservation harness forbids. `link` and
|
|
60
|
+
* `orderedList` are replaced below to keep the stored attribute sets.
|
|
61
|
+
*/
|
|
62
|
+
declare const communStarterKit: {
|
|
63
|
+
readonly code: false;
|
|
64
|
+
readonly codeBlock: false;
|
|
65
|
+
readonly strike: false;
|
|
66
|
+
readonly underline: false;
|
|
67
|
+
readonly trailingNode: false;
|
|
68
|
+
readonly link: false;
|
|
69
|
+
readonly orderedList: false;
|
|
70
|
+
};
|
|
71
|
+
/** Link without v3's `title` attr: declaring it would add a null key to every stored link on save. */
|
|
72
|
+
declare const CommunLink: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
|
|
73
|
+
/** OrderedList without v3's `type` attr (same rationale as CommunLink). */
|
|
74
|
+
declare const CommunOrderedList: _tiptap_core.Node<_tiptap_extension_list.OrderedListOptions, any>;
|
|
75
|
+
interface CommunEditorMedia {
|
|
76
|
+
upload: FileNodeOptions['upload'];
|
|
77
|
+
fetch: FileNodeOptions['fetch'];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The parity extension set. UEditor must ALSO receive `:image="false"` and
|
|
81
|
+
* `:mention="false"`: its defaults collide with our node names.
|
|
82
|
+
*/
|
|
83
|
+
declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.Node<UploadPlaceholderOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any> | _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any> | _tiptap_core.Node<any, any> | _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<FileNodeOptions, any>)[];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stable block ids matching stored content: attribute `uid`, UUID v4.
|
|
87
|
+
* Existing ids are never regenerated; missing ones are filled on open.
|
|
88
|
+
* The type list is CLOSED — adding a type would rewrite every document on
|
|
89
|
+
* save, since none of the other nodes carry a uid.
|
|
90
|
+
*/
|
|
91
|
+
declare const UID_TYPES: readonly ["paragraph", "heading", "listItem", "bulletList", "orderedList", "blockquote", "callout", "file", "image"];
|
|
92
|
+
declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOptions, any>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Info callout block. Content is bare text (no paragraphs) and `icon` holds
|
|
96
|
+
* a full Iconify name — both fixed by stored client content.
|
|
97
|
+
*/
|
|
98
|
+
declare const Callout: Node<any, any>;
|
|
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
|
+
/**
|
|
117
|
+
* External-service iframe. Attrs mirror stored content exactly: embeds carry
|
|
118
|
+
* no uid and `frameborder` is a string.
|
|
119
|
+
*/
|
|
120
|
+
declare const Embed: Node<any, any>;
|
|
121
|
+
/**
|
|
122
|
+
* Embed services. Stored content only uses `video`; new services extend this
|
|
123
|
+
* table without touching the node contract (same attrs for every service).
|
|
124
|
+
*/
|
|
125
|
+
interface EmbedService {
|
|
126
|
+
label: string;
|
|
127
|
+
icon: string;
|
|
128
|
+
placeholder: string;
|
|
129
|
+
title: string;
|
|
130
|
+
height: number;
|
|
131
|
+
toSrc: (url: string) => string;
|
|
132
|
+
}
|
|
133
|
+
declare const EMBED_SERVICES: Record<string, EmbedService>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Accordion trio on the official Details extensions. `toggle` REPLACES the
|
|
137
|
+
* stock `open` attribute: stored documents only carry `toggle`. Node views
|
|
138
|
+
* attach in index.ts; open state is editing state, never written to content.
|
|
139
|
+
*/
|
|
140
|
+
declare const Details: _tiptap_core.Node<_tiptap_extension_details.DetailsOptions, any>;
|
|
141
|
+
declare const DetailsSummary: _tiptap_core.Node<_tiptap_extension_details.DetailsSummaryOptions, any>;
|
|
142
|
+
declare const DetailsContent: _tiptap_core.Node<_tiptap_extension_details.DetailsContentOptions, any>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Drops text nodes without text — invalid ProseMirror inherited from the
|
|
146
|
+
* migration; every editor rejects them and themes render them as nothing.
|
|
147
|
+
* Returns the same reference when nothing needs repair.
|
|
148
|
+
*/
|
|
149
|
+
declare function sanitizeDoc<T extends {
|
|
150
|
+
type?: string;
|
|
151
|
+
content?: any[];
|
|
152
|
+
}>(doc: T): T;
|
|
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 };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +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};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@open-commune/editor",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"import": "./dist/index.mjs"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "bun test",
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"build": "unbuild"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@tiptap/core": "^3.27.3",
|
|
17
|
+
"@tiptap/extension-code": "^3.27.3",
|
|
18
|
+
"@tiptap/extension-details": "^3.27.3",
|
|
19
|
+
"@tiptap/extension-file-handler": "^3.27.3",
|
|
20
|
+
"@tiptap/extension-highlight": "^3.27.3",
|
|
21
|
+
"@tiptap/extension-horizontal-rule": "^3.27.3",
|
|
22
|
+
"@tiptap/extension-image": "^3.27.3",
|
|
23
|
+
"@tiptap/extension-link": "^3.27.3",
|
|
24
|
+
"@tiptap/extension-list": "^3.27.3",
|
|
25
|
+
"@tiptap/extension-text-align": "^3.27.3",
|
|
26
|
+
"@tiptap/extension-text-style": "^3.27.3",
|
|
27
|
+
"@tiptap/extension-typography": "^3.27.3",
|
|
28
|
+
"@tiptap/extension-unique-id": "^3.27.3",
|
|
29
|
+
"@tiptap/pm": "^3.27.3",
|
|
30
|
+
"@tiptap/starter-kit": "^3.27.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@happy-dom/global-registrator": "^20",
|
|
34
|
+
"typescript": "^5",
|
|
35
|
+
"@types/bun": "^1"
|
|
36
|
+
},
|
|
37
|
+
"description": "The rich-text editor: document schema, extensions and their sanitisation.",
|
|
38
|
+
"license": "AGPL-3.0-or-later",
|
|
39
|
+
"version": "0.1.2",
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"main": "./dist/index.mjs",
|
|
45
|
+
"types": "./dist/index.d.mts",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/open-commune/open-commune.git",
|
|
52
|
+
"directory": "packages/editor"
|
|
53
|
+
}
|
|
54
|
+
}
|