@fibery/prosemirror-schema 1.6.1 → 3.0.0-next.0
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/LICENSE +214 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +17 -848
- package/lib/src/create-schema.d.ts +11 -0
- package/lib/src/create-schema.js +81 -0
- package/lib/src/marks/highlight.d.ts +2 -0
- package/lib/src/marks/highlight.js +68 -0
- package/lib/src/marks/hint-query.d.ts +2 -0
- package/lib/src/marks/hint-query.js +23 -0
- package/lib/src/marks/link.d.ts +2 -0
- package/lib/src/marks/link.js +13 -0
- package/lib/src/marks/linked-highlight.d.ts +8 -0
- package/lib/src/marks/linked-highlight.js +58 -0
- package/lib/src/marks/strike.d.ts +2 -0
- package/lib/src/marks/strike.js +7 -0
- package/lib/src/marks/types/mark.d.ts +3 -0
- package/lib/src/marks/types/mark.js +2 -0
- package/lib/src/marks/underline.d.ts +2 -0
- package/lib/src/marks/underline.js +7 -0
- package/lib/src/nodes/check-item.d.ts +11 -0
- package/lib/src/nodes/check-item.js +34 -0
- package/lib/src/nodes/check-list.d.ts +13 -0
- package/lib/src/nodes/check-list.js +31 -0
- package/lib/src/nodes/code-block.d.ts +2 -0
- package/lib/src/nodes/code-block.js +99 -0
- package/lib/src/nodes/entity.d.ts +11 -0
- package/lib/src/nodes/entity.js +35 -0
- package/lib/src/nodes/fibery-section.d.ts +3 -0
- package/lib/src/nodes/fibery-section.js +30 -0
- package/lib/src/nodes/fibery-view.d.ts +2 -0
- package/lib/src/nodes/fibery-view.js +32 -0
- package/lib/src/nodes/heading.d.ts +4 -0
- package/lib/src/nodes/heading.js +65 -0
- package/lib/src/nodes/image-block.d.ts +2 -0
- package/lib/src/nodes/image-block.js +35 -0
- package/lib/src/nodes/important.d.ts +2 -0
- package/lib/src/nodes/important.js +11 -0
- package/lib/src/nodes/media.d.ts +4 -0
- package/lib/src/nodes/media.js +33 -0
- package/lib/src/nodes/mention.d.ts +11 -0
- package/lib/src/nodes/mention.js +35 -0
- package/lib/src/nodes/note.d.ts +2 -0
- package/lib/src/nodes/note.js +11 -0
- package/lib/src/nodes/paragraph.d.ts +2 -0
- package/lib/src/nodes/paragraph.js +20 -0
- package/lib/src/nodes/table-nodes.d.ts +1 -0
- package/lib/src/nodes/table-nodes.js +21 -0
- package/lib/src/nodes/types/inline-content.d.ts +7 -0
- package/lib/src/nodes/types/inline-content.js +2 -0
- package/lib/src/nodes/types/text.d.ts +5 -0
- package/lib/src/nodes/types/text.js +2 -0
- package/lib/src/nodes/video.d.ts +2 -0
- package/lib/src/nodes/video.js +49 -0
- package/lib/test-helpers/index.d.ts +4 -0
- package/lib/test-helpers/index.js +21 -0
- package/package.json +19 -18
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeHeading = void 0;
|
|
4
|
+
const DEFAULT_GUID = "";
|
|
5
|
+
const makeHeading = ({ headingToDOM }) => ({
|
|
6
|
+
content: "inline*",
|
|
7
|
+
group: "block",
|
|
8
|
+
attrs: {
|
|
9
|
+
level: { default: 1 },
|
|
10
|
+
guid: { default: DEFAULT_GUID },
|
|
11
|
+
},
|
|
12
|
+
defining: true,
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: "h1",
|
|
16
|
+
getAttrs: (dom) => ({
|
|
17
|
+
level: 1,
|
|
18
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
tag: "h2",
|
|
23
|
+
getAttrs: (dom) => ({
|
|
24
|
+
level: 2,
|
|
25
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
tag: "h3",
|
|
30
|
+
getAttrs: (dom) => ({
|
|
31
|
+
level: 3,
|
|
32
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
tag: "h4",
|
|
37
|
+
getAttrs: (dom) => ({
|
|
38
|
+
level: 4,
|
|
39
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
tag: "h5",
|
|
44
|
+
getAttrs: (dom) => ({
|
|
45
|
+
level: 5,
|
|
46
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
tag: "h6",
|
|
51
|
+
getAttrs: (dom) => ({
|
|
52
|
+
level: 6,
|
|
53
|
+
guid: dom.getAttribute("guid") || DEFAULT_GUID,
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
toDOM(node) {
|
|
58
|
+
if (headingToDOM) {
|
|
59
|
+
return headingToDOM(node);
|
|
60
|
+
}
|
|
61
|
+
const { guid } = node.attrs;
|
|
62
|
+
return ["h" + node.attrs.level, { guid }, 0];
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
exports.makeHeading = makeHeading;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageBlock = void 0;
|
|
4
|
+
exports.imageBlock = {
|
|
5
|
+
attrs: {
|
|
6
|
+
src: {},
|
|
7
|
+
alt: { default: null },
|
|
8
|
+
title: { default: null },
|
|
9
|
+
},
|
|
10
|
+
// ----------------
|
|
11
|
+
inline: false,
|
|
12
|
+
group: "block",
|
|
13
|
+
content: "inline*",
|
|
14
|
+
atom: true,
|
|
15
|
+
// ----------------
|
|
16
|
+
draggable: true,
|
|
17
|
+
parseDOM: [
|
|
18
|
+
{
|
|
19
|
+
tag: "img[src]",
|
|
20
|
+
getAttrs(domNode) {
|
|
21
|
+
const dom = domNode;
|
|
22
|
+
return {
|
|
23
|
+
src: dom.getAttribute("src"),
|
|
24
|
+
title: dom.getAttribute("title"),
|
|
25
|
+
alt: dom.getAttribute("alt"),
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
toDOM(node) {
|
|
31
|
+
const { src, alt, title } = node.attrs;
|
|
32
|
+
// return ["img", {src, alt, title}];
|
|
33
|
+
return ["div", {}, ["img", { src, alt, title }]];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.important = void 0;
|
|
4
|
+
exports.important = {
|
|
5
|
+
content: "inline*",
|
|
6
|
+
group: "block",
|
|
7
|
+
parseDOM: [{ tag: "div.fibery-important" }],
|
|
8
|
+
toDOM() {
|
|
9
|
+
return ["div", { class: "fibery-important" }, ["p", 0]];
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMedia = void 0;
|
|
4
|
+
const makeMedia = ({ mediaToDom }) => ({
|
|
5
|
+
inline: false,
|
|
6
|
+
attrs: {
|
|
7
|
+
url: {},
|
|
8
|
+
},
|
|
9
|
+
group: "block",
|
|
10
|
+
draggable: true,
|
|
11
|
+
parseDOM: [
|
|
12
|
+
{
|
|
13
|
+
tag: "div[data-url]",
|
|
14
|
+
getAttrs(dom) {
|
|
15
|
+
return {
|
|
16
|
+
url: dom.getAttribute("data-url"),
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
toDOM(node) {
|
|
22
|
+
if (mediaToDom) {
|
|
23
|
+
return mediaToDom(node);
|
|
24
|
+
}
|
|
25
|
+
const { url } = node.attrs;
|
|
26
|
+
const attrs = {
|
|
27
|
+
"data-url": url,
|
|
28
|
+
contenteditable: "false",
|
|
29
|
+
};
|
|
30
|
+
return ["div", attrs, url];
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
exports.makeMedia = makeMedia;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeSpec } from "prosemirror-model";
|
|
2
|
+
export interface MentionAttributes {
|
|
3
|
+
id: string;
|
|
4
|
+
typeId: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface MentionDefinition {
|
|
8
|
+
type: "mention";
|
|
9
|
+
attrs: MentionAttributes;
|
|
10
|
+
}
|
|
11
|
+
export declare const mention: NodeSpec;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mention = void 0;
|
|
4
|
+
exports.mention = {
|
|
5
|
+
inline: true,
|
|
6
|
+
group: "inline",
|
|
7
|
+
selectable: false,
|
|
8
|
+
attrs: {
|
|
9
|
+
id: { default: "" },
|
|
10
|
+
name: { default: "" },
|
|
11
|
+
typeId: { default: "" },
|
|
12
|
+
},
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: "span[data-mention-id]",
|
|
16
|
+
getAttrs: (domNode) => {
|
|
17
|
+
const dom = domNode;
|
|
18
|
+
return {
|
|
19
|
+
id: dom.getAttribute("data-mention-id"),
|
|
20
|
+
name: dom.textContent,
|
|
21
|
+
typeId: dom.getAttribute("data-mention-type-id"),
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
toDOM(node) {
|
|
27
|
+
const { id, typeId, name } = node.attrs;
|
|
28
|
+
const attrs = {
|
|
29
|
+
"data-mention-id": id,
|
|
30
|
+
"data-mention-type-id": typeId,
|
|
31
|
+
contenteditable: "false",
|
|
32
|
+
};
|
|
33
|
+
return ["span", attrs, name];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.note = void 0;
|
|
4
|
+
exports.note = {
|
|
5
|
+
content: "inline*",
|
|
6
|
+
group: "block",
|
|
7
|
+
toDOM() {
|
|
8
|
+
return ["div", { class: "fibery-note" }, ["p", 0]];
|
|
9
|
+
},
|
|
10
|
+
parseDOM: [{ tag: "div.fibery-note" }],
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paragraph = void 0;
|
|
4
|
+
exports.paragraph = {
|
|
5
|
+
content: "inline*",
|
|
6
|
+
group: "block",
|
|
7
|
+
attrs: {
|
|
8
|
+
guid: { default: "" },
|
|
9
|
+
},
|
|
10
|
+
parseDOM: [
|
|
11
|
+
{
|
|
12
|
+
tag: "p",
|
|
13
|
+
getAttrs: (dom) => ({ guid: dom.getAttribute("data-guid") }),
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
toDOM(node) {
|
|
17
|
+
const { guid } = node.attrs;
|
|
18
|
+
return ["p", { "data-guid": guid }, 0];
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const tableNodes: import("prosemirror-tables").TableNodes;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableNodes = void 0;
|
|
4
|
+
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
5
|
+
exports.tableNodes = (0, prosemirror_tables_1.tableNodes)({
|
|
6
|
+
tableGroup: "block",
|
|
7
|
+
cellContent: "block+",
|
|
8
|
+
cellAttributes: {
|
|
9
|
+
background: {
|
|
10
|
+
default: null,
|
|
11
|
+
getFromDOM(dom) {
|
|
12
|
+
return dom.style.backgroundColor || null;
|
|
13
|
+
},
|
|
14
|
+
setDOMAttr(value, attrs) {
|
|
15
|
+
if (value) {
|
|
16
|
+
attrs.style = (attrs.style || "") + `background-color: ${value};`;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MentionDefinition as Mention } from "../mention";
|
|
2
|
+
import { EntityDefinition as Entity } from "../entity";
|
|
3
|
+
import { TextDefinition as Text } from "./text";
|
|
4
|
+
import { MarksObject } from "../../marks/types/mark";
|
|
5
|
+
export type InlineFormattedText = Text & MarksObject<unknown>;
|
|
6
|
+
export type InlineAtomic = Mention | Entity | unknown;
|
|
7
|
+
export type Inline = InlineFormattedText | InlineAtomic;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.video = void 0;
|
|
4
|
+
const DEFAULT_VIDEO_WIDTH = 400;
|
|
5
|
+
const DEFAULT_VIDEO_HEIGHT = 200;
|
|
6
|
+
exports.video = {
|
|
7
|
+
inline: false,
|
|
8
|
+
attrs: {
|
|
9
|
+
src: {},
|
|
10
|
+
type: {},
|
|
11
|
+
width: { default: DEFAULT_VIDEO_WIDTH },
|
|
12
|
+
height: { default: DEFAULT_VIDEO_HEIGHT },
|
|
13
|
+
title: { default: "" },
|
|
14
|
+
alignment: { default: ":alignment/block-center" },
|
|
15
|
+
},
|
|
16
|
+
group: "block",
|
|
17
|
+
draggable: true,
|
|
18
|
+
parseDOM: [
|
|
19
|
+
{
|
|
20
|
+
tag: "video",
|
|
21
|
+
getAttrs(domNode) {
|
|
22
|
+
const dom = domNode;
|
|
23
|
+
return {
|
|
24
|
+
src: dom.getAttribute("src"),
|
|
25
|
+
type: dom.getAttribute("type"),
|
|
26
|
+
width: Number(dom.getAttribute("width")) || DEFAULT_VIDEO_WIDTH,
|
|
27
|
+
height: Number(dom.getAttribute("height")) || DEFAULT_VIDEO_HEIGHT,
|
|
28
|
+
title: dom.getAttribute("title"),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
toDOM(node) {
|
|
34
|
+
const { src, type, width = DEFAULT_VIDEO_WIDTH, height = DEFAULT_VIDEO_HEIGHT, title } = node.attrs;
|
|
35
|
+
return [
|
|
36
|
+
"video",
|
|
37
|
+
{
|
|
38
|
+
src,
|
|
39
|
+
type,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
title,
|
|
43
|
+
playsinline: "",
|
|
44
|
+
controls: "",
|
|
45
|
+
preload: "metadata",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Schema, Node as PMNode, ParseOptions } from "prosemirror-model";
|
|
2
|
+
export declare const fromHTML: (html: string, schema: Schema, options?: ParseOptions) => PMNode;
|
|
3
|
+
export declare const toDOM: (node: PMNode, schema: Schema) => Node;
|
|
4
|
+
export declare const toHTML: (node: PMNode, schema: Schema) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toHTML = exports.toDOM = exports.fromHTML = void 0;
|
|
4
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
|
+
const fromHTML = (html, schema, options) => {
|
|
6
|
+
const el = document.createElement("div");
|
|
7
|
+
el.innerHTML = html;
|
|
8
|
+
return prosemirror_model_1.DOMParser.fromSchema(schema).parse(el, options);
|
|
9
|
+
};
|
|
10
|
+
exports.fromHTML = fromHTML;
|
|
11
|
+
const toDOM = (node, schema) => {
|
|
12
|
+
const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema);
|
|
13
|
+
return serializer.serializeFragment(prosemirror_model_1.Fragment.from(node));
|
|
14
|
+
};
|
|
15
|
+
exports.toDOM = toDOM;
|
|
16
|
+
const toHTML = (node, schema) => {
|
|
17
|
+
const el = document.createElement("div");
|
|
18
|
+
el.appendChild((0, exports.toDOM)(node, schema));
|
|
19
|
+
return el.innerHTML;
|
|
20
|
+
};
|
|
21
|
+
exports.toHTML = toHTML;
|
package/package.json
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/prosemirror-schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "Fibery prosemirror schema",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"/lib"
|
|
8
8
|
],
|
|
9
9
|
"private": false,
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "BABEL_ENV=production webpack",
|
|
12
|
-
"test": "jest",
|
|
13
|
-
"test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit",
|
|
14
|
-
"lint": "eslint ",
|
|
15
|
-
"prepublishOnly": "npm run build"
|
|
16
|
-
},
|
|
17
10
|
"dependencies": {
|
|
18
11
|
"prosemirror-schema-basic": "1.0.0",
|
|
19
12
|
"uuid": "8.3.2"
|
|
20
13
|
},
|
|
21
14
|
"peerDependencies": {
|
|
22
|
-
"prosemirror-model": "^1.
|
|
23
|
-
"prosemirror-schema-list": "^1.
|
|
24
|
-
"prosemirror-tables": "^
|
|
15
|
+
"prosemirror-model": "^1.18.2",
|
|
16
|
+
"prosemirror-schema-list": "^1.2.2",
|
|
17
|
+
"prosemirror-tables": "^1.2.5"
|
|
25
18
|
},
|
|
26
19
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"eslint-config-fibery": "7.1.0",
|
|
20
|
+
"@fibery/babel-preset": "7.2.0",
|
|
21
|
+
"@fibery/eslint-config": "8.3.0",
|
|
22
|
+
"@types/uuid": "8.3.3",
|
|
31
23
|
"jest": "27.5.1",
|
|
32
24
|
"jest-junit": "13.0.0",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
25
|
+
"prosemirror-model": "1.18.2",
|
|
26
|
+
"prosemirror-schema-list": "1.2.2",
|
|
27
|
+
"prosemirror-tables": "1.2.5",
|
|
28
|
+
"typescript": "5.0.3"
|
|
35
29
|
},
|
|
36
30
|
"jest": {
|
|
37
31
|
"testEnvironment": "jsdom",
|
|
@@ -46,5 +40,12 @@
|
|
|
46
40
|
"text",
|
|
47
41
|
"cobertura"
|
|
48
42
|
]
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rm -rf lib && tsc --declaration --noEmit false",
|
|
46
|
+
"test": "jest",
|
|
47
|
+
"test:ci": "yarn test --reporters=default --reporters=jest-junit",
|
|
48
|
+
"test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/prosemirror-schema --reporters=default --reporters=jest-junit",
|
|
49
|
+
"lint": "eslint "
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
}
|