@fibery/prosemirror-schema 4.7.0 → 4.9.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/lib/src/create-schema.d.ts +3 -3
- package/lib/src/create-schema.js +10 -11
- package/lib/src/marks/linked-highlight.js +5 -14
- package/lib/src/nodes/code-block.js +3 -2
- package/lib/src/nodes/heading.d.ts +1 -1
- package/lib/src/nodes/heading.js +12 -44
- package/lib/src/nodes/image-block.js +2 -2
- package/lib/src/nodes/paragraph.js +4 -1
- package/package.json +12 -12
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Node, Schema } from "prosemirror-model";
|
|
2
2
|
import { EmojiOptions } from "./nodes/emoji";
|
|
3
|
-
|
|
3
|
+
type Params = {
|
|
4
4
|
isImageBlockEnabled?: boolean;
|
|
5
5
|
fiberyViewEnabled?: boolean;
|
|
6
6
|
sharedColorGenerator?: any;
|
|
7
7
|
headingToDOM?: ((node: Node) => HTMLElement) | null;
|
|
8
8
|
mediaToDom?: ((node: Node) => HTMLElement) | null;
|
|
9
9
|
emojiOptions?: EmojiOptions;
|
|
10
|
-
}
|
|
11
|
-
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions, }?:
|
|
10
|
+
};
|
|
11
|
+
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, emojiOptions, }?: Params) => Schema;
|
|
12
12
|
export {};
|
package/lib/src/create-schema.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSchema = void 0;
|
|
4
4
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
|
-
// @ts-ignore
|
|
6
5
|
const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
|
|
7
|
-
// @ts-ignore
|
|
8
6
|
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
9
7
|
const table_nodes_1 = require("./nodes/table-nodes");
|
|
10
8
|
const paragraph_1 = require("./nodes/paragraph");
|
|
@@ -35,8 +33,15 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
35
33
|
prosemirror_schema_basic_1.nodes.code_block = code_block_1.code_block;
|
|
36
34
|
prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
|
|
37
35
|
prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const base = new prosemirror_model_1.Schema({
|
|
37
|
+
nodes: prosemirror_schema_basic_1.nodes,
|
|
38
|
+
marks: {
|
|
39
|
+
...prosemirror_schema_basic_1.marks,
|
|
40
|
+
link: (0, link_1.makeLink)(prosemirror_schema_basic_1.marks.link),
|
|
41
|
+
linkedhighlight: (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator }),
|
|
42
|
+
linkedhighlightentity: (0, linked_highlight_1.makeLinkedHighlightEntity)({ sharedColorGenerator }),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
40
45
|
const customNodes = {
|
|
41
46
|
note: note_1.note,
|
|
42
47
|
important: important_1.important,
|
|
@@ -69,19 +74,13 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
69
74
|
});
|
|
70
75
|
return new prosemirror_model_1.Schema({
|
|
71
76
|
nodes: actualNodes,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
-
// @ts-ignore
|
|
74
77
|
marks: base.spec.marks
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
-
// @ts-ignore
|
|
77
78
|
.addToEnd("strike", strike_1.strike)
|
|
78
79
|
.addToEnd("underline", underline_1.underline)
|
|
79
80
|
.addToEnd("hintQuery", hint_query_1.hintQuery)
|
|
80
81
|
// We leave mark key as "highlight" only because we don't want to do migration.
|
|
81
82
|
// "TextBackgroundColor" term is used everywhere through codebase.
|
|
82
|
-
.addToEnd("highlight", text_background_color_1.textBackgroundColor)
|
|
83
|
-
.addToEnd("linkedhighlight", (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator }))
|
|
84
|
-
.addToEnd("linkedhighlightentity", (0, linked_highlight_1.makeLinkedHighlightEntity)({ sharedColorGenerator })),
|
|
83
|
+
.addToEnd("highlight", text_background_color_1.textBackgroundColor),
|
|
85
84
|
});
|
|
86
85
|
};
|
|
87
86
|
exports.createSchema = createSchema;
|
|
@@ -5,7 +5,7 @@ const hyphenatePascal = (str) => str
|
|
|
5
5
|
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
6
6
|
.replace(/([A-Z]{2})[a-z]/, "$1-")
|
|
7
7
|
.toLowerCase();
|
|
8
|
-
const createMark = (markType,
|
|
8
|
+
const createMark = (markType, sharedColorGenerator) => {
|
|
9
9
|
const markTag = `span.${markType}`;
|
|
10
10
|
const markClassName = `${markType}`;
|
|
11
11
|
const preserveBool = (attr) => (attr === "true" ? true : attr === "false" ? false : attr);
|
|
@@ -30,14 +30,11 @@ const createMark = (markType, getTypeId, sharedColorGenerator) => {
|
|
|
30
30
|
],
|
|
31
31
|
toDOM: ({ attrs }) => {
|
|
32
32
|
const { id, meta } = attrs;
|
|
33
|
-
const
|
|
34
|
-
const typeId = getTypeId(meta);
|
|
35
|
-
const color = sharedColorGenerator ? sharedColorGenerator.generate(typeId) : "#EEEEEE";
|
|
33
|
+
const color = sharedColorGenerator ? sharedColorGenerator.generate(attrs) : "#EEEEEE";
|
|
36
34
|
return [
|
|
37
35
|
markTag,
|
|
38
36
|
{
|
|
39
|
-
class:
|
|
40
|
-
contenteditable: !hidden,
|
|
37
|
+
class: markClassName,
|
|
41
38
|
style: color ? `background-color:${color}` : ``,
|
|
42
39
|
"data-id": id,
|
|
43
40
|
...Object.keys(meta)
|
|
@@ -53,17 +50,11 @@ const createMark = (markType, getTypeId, sharedColorGenerator) => {
|
|
|
53
50
|
};
|
|
54
51
|
const makeLinkedHighlight = ({ sharedColorGenerator }) => {
|
|
55
52
|
// @ts-expect-error todo: fix this
|
|
56
|
-
return createMark("linkedhighlight",
|
|
57
|
-
const { typeId } = meta.links && meta.links.length > 0 ? meta.links[0] : {};
|
|
58
|
-
return typeId;
|
|
59
|
-
}, sharedColorGenerator);
|
|
53
|
+
return createMark("linkedhighlight", sharedColorGenerator);
|
|
60
54
|
};
|
|
61
55
|
exports.makeLinkedHighlight = makeLinkedHighlight;
|
|
62
56
|
const makeLinkedHighlightEntity = ({ sharedColorGenerator }) => {
|
|
63
57
|
// @ts-expect-error todo: fix this
|
|
64
|
-
return createMark("linkedhighlightentity",
|
|
65
|
-
const { typeId } = meta.highlightEntities && meta.highlightEntities.length > 0 ? meta.highlightEntities[0] : {};
|
|
66
|
-
return typeId;
|
|
67
|
-
}, sharedColorGenerator);
|
|
58
|
+
return createMark("linkedhighlightentity", sharedColorGenerator);
|
|
68
59
|
};
|
|
69
60
|
exports.makeLinkedHighlightEntity = makeLinkedHighlightEntity;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.code_block = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const getLanguageFromEditorStyle = (dom) => {
|
|
5
6
|
return dom.getAttribute("data-language") || undefined;
|
|
6
7
|
};
|
|
@@ -38,7 +39,7 @@ const removeLastNewLine = (dom) => {
|
|
|
38
39
|
};
|
|
39
40
|
exports.code_block = {
|
|
40
41
|
content: "text*",
|
|
41
|
-
marks: "",
|
|
42
|
+
marks: "linkedhighlightentity linkedhighlight",
|
|
42
43
|
group: "block",
|
|
43
44
|
code: true,
|
|
44
45
|
isolating: true,
|
|
@@ -53,7 +54,7 @@ exports.code_block = {
|
|
|
53
54
|
preserveWhitespace: "full",
|
|
54
55
|
getAttrs: (domNode) => {
|
|
55
56
|
const dom = domNode;
|
|
56
|
-
const guid = dom.getAttribute("data-guid") ||
|
|
57
|
+
const guid = dom.getAttribute("data-guid") || (0, uuid_1.v4)();
|
|
57
58
|
const language = getLanguageFromBitbucketStyle(dom.parentElement) ||
|
|
58
59
|
getLanguageFromEditorStyle(dom.parentElement) ||
|
|
59
60
|
getLanguageFromCode(dom) ||
|
package/lib/src/nodes/heading.js
CHANGED
|
@@ -1,58 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeHeading = void 0;
|
|
4
|
-
const
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const parseGuid = (dom) => {
|
|
6
|
+
return dom.getAttribute("guid") || (0, uuid_1.v4)();
|
|
7
|
+
};
|
|
8
|
+
const makeGetAttrs = (level) => (dom) => ({ level, guid: parseGuid(dom) });
|
|
5
9
|
const makeHeading = ({ headingToDOM }) => ({
|
|
6
10
|
content: "inline*",
|
|
7
11
|
group: "block",
|
|
8
12
|
attrs: {
|
|
9
13
|
level: { default: 1 },
|
|
10
|
-
guid: { default:
|
|
14
|
+
guid: { default: "" },
|
|
11
15
|
},
|
|
12
16
|
defining: true,
|
|
13
17
|
parseDOM: [
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
},
|
|
18
|
+
{ tag: "h1", getAttrs: makeGetAttrs(1) },
|
|
19
|
+
{ tag: "h2", getAttrs: makeGetAttrs(2) },
|
|
20
|
+
{ tag: "h3", getAttrs: makeGetAttrs(3) },
|
|
21
|
+
{ tag: "h4", getAttrs: makeGetAttrs(4) },
|
|
22
|
+
{ tag: "h5", getAttrs: makeGetAttrs(5) },
|
|
23
|
+
{ tag: "h6", getAttrs: makeGetAttrs(6) },
|
|
56
24
|
],
|
|
57
25
|
toDOM(node) {
|
|
58
26
|
if (headingToDOM) {
|
|
@@ -10,8 +10,8 @@ exports.imageBlock = {
|
|
|
10
10
|
...(0, resizable_node_attrs_1.createDefaultAttrs)(),
|
|
11
11
|
},
|
|
12
12
|
// ----------------
|
|
13
|
-
inline: false,
|
|
14
|
-
group: "block",
|
|
13
|
+
inline: false, // inline: true,
|
|
14
|
+
group: "block", // group: "inline",
|
|
15
15
|
content: "inline*",
|
|
16
16
|
atom: true,
|
|
17
17
|
// ----------------
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.paragraph = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
exports.paragraph = {
|
|
5
6
|
content: "inline*",
|
|
6
7
|
group: "block",
|
|
@@ -10,7 +11,9 @@ exports.paragraph = {
|
|
|
10
11
|
parseDOM: [
|
|
11
12
|
{
|
|
12
13
|
tag: "p",
|
|
13
|
-
getAttrs: (dom) => ({
|
|
14
|
+
getAttrs: (dom) => ({
|
|
15
|
+
guid: dom.getAttribute("data-guid") || (0, uuid_1.v4)(),
|
|
16
|
+
}),
|
|
14
17
|
},
|
|
15
18
|
],
|
|
16
19
|
toDOM(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/prosemirror-schema",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "Fibery prosemirror schema",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -23,25 +23,25 @@
|
|
|
23
23
|
},
|
|
24
24
|
"private": false,
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"prosemirror-schema-basic": "1.
|
|
26
|
+
"prosemirror-schema-basic": "1.2.2",
|
|
27
27
|
"uuid": "8.3.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"prosemirror-model": "^1.
|
|
31
|
-
"prosemirror-schema-list": "^1.
|
|
32
|
-
"prosemirror-tables": "1.3.
|
|
30
|
+
"prosemirror-model": "^1.19.4",
|
|
31
|
+
"prosemirror-schema-list": "^1.3.0",
|
|
32
|
+
"prosemirror-tables": "1.3.7"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/jest": "27.0.1",
|
|
36
36
|
"@types/uuid": "8.3.3",
|
|
37
37
|
"jest": "27.5.1",
|
|
38
38
|
"jest-junit": "13.0.0",
|
|
39
|
-
"prosemirror-model": "1.
|
|
40
|
-
"prosemirror-schema-list": "1.
|
|
41
|
-
"prosemirror-tables": "1.3.
|
|
42
|
-
"typescript": "5.
|
|
43
|
-
"@fibery/
|
|
44
|
-
"@fibery/
|
|
39
|
+
"prosemirror-model": "1.19.4",
|
|
40
|
+
"prosemirror-schema-list": "1.3.0",
|
|
41
|
+
"prosemirror-tables": "1.3.7",
|
|
42
|
+
"typescript": "5.4.3",
|
|
43
|
+
"@fibery/babel-preset": "7.4.0",
|
|
44
|
+
"@fibery/eslint-config": "8.6.0"
|
|
45
45
|
},
|
|
46
46
|
"jest": {
|
|
47
47
|
"testEnvironment": "jsdom",
|
|
@@ -62,6 +62,6 @@
|
|
|
62
62
|
"test": "jest",
|
|
63
63
|
"test:ci": "jest --reporters=default --reporters=jest-junit",
|
|
64
64
|
"test:coverage": "jest --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/prosemirror-schema --reporters=default --reporters=jest-junit",
|
|
65
|
-
"lint": "eslint "
|
|
65
|
+
"lint": "eslint ."
|
|
66
66
|
}
|
|
67
67
|
}
|