@open-commune/editor 0.1.2 → 0.1.3
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/README.md +32 -0
- package/dist/index.d.mts +19 -19
- package/dist/index.d.ts +19 -19
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @open-commune/editor
|
|
2
|
+
|
|
3
|
+
The rich-text editor of [Open Commune](https://github.com/open-commune/open-commune): document schema, TipTap extensions, and the sanitisation that guards them.
|
|
4
|
+
|
|
5
|
+
Split out from the application so that the same document schema is shared by the editor writing the content and the server storing it — a document accepted by one is valid for the other.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @open-commune/editor
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Callout, Details, Embed, FileNode, ImageNode, Uid, sanitizeDoc } from '@open-commune/editor';
|
|
17
|
+
|
|
18
|
+
// client — add the shared nodes to a TipTap editor
|
|
19
|
+
const editor = new Editor({
|
|
20
|
+
extensions: [StarterKit, Uid, Callout, ImageNode, FileNode, Embed, Details],
|
|
21
|
+
content: doc,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// server — never trust a document that came over the wire
|
|
25
|
+
const safe = sanitizeDoc(incoming);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`sanitizeDoc` returns a document conforming to the schema, dropping anything the schema does not allow. It is what stands between stored content and injected markup, so run it on every write path.
|
|
29
|
+
|
|
30
|
+
## Licence
|
|
31
|
+
|
|
32
|
+
AGPL-3.0-or-later.
|
package/dist/index.d.mts
CHANGED
|
@@ -3,10 +3,10 @@ import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
|
|
|
3
3
|
import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
|
|
4
4
|
import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
|
|
5
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
6
|
import * as _tiptap_core from '@tiptap/core';
|
|
9
7
|
import { Node } from '@tiptap/core';
|
|
8
|
+
import * as _tiptap_extension_details from '@tiptap/extension-details';
|
|
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';
|
|
12
12
|
|
|
@@ -24,6 +24,22 @@ 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
|
+
|
|
27
43
|
/** Markdown-style `` input rule, kept from the previous editor. */
|
|
28
44
|
declare const fileInputRegex: RegExp;
|
|
29
45
|
interface FileNodeOptions {
|
|
@@ -80,7 +96,7 @@ interface CommunEditorMedia {
|
|
|
80
96
|
* The parity extension set. UEditor must ALSO receive `:image="false"` and
|
|
81
97
|
* `:mention="false"`: its defaults collide with our node names.
|
|
82
98
|
*/
|
|
83
|
-
declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.
|
|
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>)[];
|
|
84
100
|
|
|
85
101
|
/**
|
|
86
102
|
* Stable block ids matching stored content: attribute `uid`, UUID v4.
|
|
@@ -97,22 +113,6 @@ declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOp
|
|
|
97
113
|
*/
|
|
98
114
|
declare const Callout: Node<any, any>;
|
|
99
115
|
|
|
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.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import * as _tiptap_extension_highlight from '@tiptap/extension-highlight';
|
|
|
3
3
|
import * as _tiptap_extension_text_style from '@tiptap/extension-text-style';
|
|
4
4
|
import * as _tiptap_extension_text_align from '@tiptap/extension-text-align';
|
|
5
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
6
|
import * as _tiptap_core from '@tiptap/core';
|
|
9
7
|
import { Node } from '@tiptap/core';
|
|
8
|
+
import * as _tiptap_extension_details from '@tiptap/extension-details';
|
|
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';
|
|
12
12
|
|
|
@@ -24,6 +24,22 @@ 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
|
+
|
|
27
43
|
/** Markdown-style `` input rule, kept from the previous editor. */
|
|
28
44
|
declare const fileInputRegex: RegExp;
|
|
29
45
|
interface FileNodeOptions {
|
|
@@ -80,7 +96,7 @@ interface CommunEditorMedia {
|
|
|
80
96
|
* The parity extension set. UEditor must ALSO receive `:image="false"` and
|
|
81
97
|
* `:mention="false"`: its defaults collide with our node names.
|
|
82
98
|
*/
|
|
83
|
-
declare function communSchemaExtensions(media?: Partial<CommunEditorMedia>): (_tiptap_core.
|
|
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>)[];
|
|
84
100
|
|
|
85
101
|
/**
|
|
86
102
|
* Stable block ids matching stored content: attribute `uid`, UUID v4.
|
|
@@ -97,22 +113,6 @@ declare const Uid: _tiptap_core.Extension<_tiptap_extension_unique_id.UniqueIDOp
|
|
|
97
113
|
*/
|
|
98
114
|
declare const Callout: Node<any, any>;
|
|
99
115
|
|
|
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.
|