@fibery/prosemirror-schema 4.6.0 → 4.8.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 +4 -4
- package/lib/src/create-schema.js +6 -9
- package/lib/src/marks/linked-highlight.d.ts +1 -1
- package/lib/src/marks/linked-highlight.js +6 -9
- package/lib/src/marks/text-background-color.d.ts +2 -0
- package/lib/src/marks/{highlight.js → text-background-color.js} +5 -5
- 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/paragraph.js +4 -1
- package/package.json +4 -4
- package/lib/src/marks/highlight.d.ts +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
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
|
@@ -4,7 +4,6 @@ exports.createSchema = void 0;
|
|
|
4
4
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
9
8
|
const table_nodes_1 = require("./nodes/table-nodes");
|
|
10
9
|
const paragraph_1 = require("./nodes/paragraph");
|
|
@@ -28,7 +27,7 @@ const column_1 = require("./nodes/column");
|
|
|
28
27
|
const strike_1 = require("./marks/strike");
|
|
29
28
|
const underline_1 = require("./marks/underline");
|
|
30
29
|
const hint_query_1 = require("./marks/hint-query");
|
|
31
|
-
const
|
|
30
|
+
const text_background_color_1 = require("./marks/text-background-color");
|
|
32
31
|
const linked_highlight_1 = require("./marks/linked-highlight");
|
|
33
32
|
const link_1 = require("./marks/link");
|
|
34
33
|
const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, emojiOptions, } = {}) => {
|
|
@@ -36,6 +35,8 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
36
35
|
prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
|
|
37
36
|
prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
|
|
38
37
|
prosemirror_schema_basic_1.marks.link = (0, link_1.makeLink)(prosemirror_schema_basic_1.marks.link);
|
|
38
|
+
prosemirror_schema_basic_1.marks.linkedhighlight = (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator });
|
|
39
|
+
prosemirror_schema_basic_1.marks.linkedhighlightentity = (0, linked_highlight_1.makeLinkedHighlightEntity)({ sharedColorGenerator });
|
|
39
40
|
const base = new prosemirror_model_1.Schema({ nodes: prosemirror_schema_basic_1.nodes, marks: prosemirror_schema_basic_1.marks });
|
|
40
41
|
const customNodes = {
|
|
41
42
|
note: note_1.note,
|
|
@@ -69,17 +70,13 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
69
70
|
});
|
|
70
71
|
return new prosemirror_model_1.Schema({
|
|
71
72
|
nodes: actualNodes,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
-
// @ts-ignore
|
|
74
73
|
marks: base.spec.marks
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
-
// @ts-ignore
|
|
77
74
|
.addToEnd("strike", strike_1.strike)
|
|
78
75
|
.addToEnd("underline", underline_1.underline)
|
|
79
76
|
.addToEnd("hintQuery", hint_query_1.hintQuery)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.addToEnd("
|
|
77
|
+
// We leave mark key as "highlight" only because we don't want to do migration.
|
|
78
|
+
// "TextBackgroundColor" term is used everywhere through codebase.
|
|
79
|
+
.addToEnd("highlight", text_background_color_1.textBackgroundColor),
|
|
83
80
|
});
|
|
84
81
|
};
|
|
85
82
|
exports.createSchema = createSchema;
|
|
@@ -5,7 +5,7 @@ type Generator = {
|
|
|
5
5
|
export declare const makeLinkedHighlight: ({ sharedColorGenerator }: {
|
|
6
6
|
sharedColorGenerator?: Generator | undefined;
|
|
7
7
|
}) => MarkSpec;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const makeLinkedHighlightEntity: ({ sharedColorGenerator }: {
|
|
9
9
|
sharedColorGenerator?: Generator | undefined;
|
|
10
10
|
}) => MarkSpec;
|
|
11
11
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeLinkedHighlightEntity = exports.makeLinkedHighlight = void 0;
|
|
4
4
|
const hyphenatePascal = (str) => str
|
|
5
5
|
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
6
6
|
.replace(/([A-Z]{2})[a-z]/, "$1-")
|
|
@@ -30,14 +30,11 @@ const createMark = (markType, sharedColorGenerator) => {
|
|
|
30
30
|
],
|
|
31
31
|
toDOM: ({ attrs }) => {
|
|
32
32
|
const { id, meta } = attrs;
|
|
33
|
-
const
|
|
34
|
-
const { typeId } = meta.links && meta.links.length > 0 ? meta.links[0] : {};
|
|
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)
|
|
@@ -56,8 +53,8 @@ const makeLinkedHighlight = ({ sharedColorGenerator }) => {
|
|
|
56
53
|
return createMark("linkedhighlight", sharedColorGenerator);
|
|
57
54
|
};
|
|
58
55
|
exports.makeLinkedHighlight = makeLinkedHighlight;
|
|
59
|
-
const
|
|
56
|
+
const makeLinkedHighlightEntity = ({ sharedColorGenerator }) => {
|
|
60
57
|
// @ts-expect-error todo: fix this
|
|
61
|
-
return createMark("
|
|
58
|
+
return createMark("linkedhighlightentity", sharedColorGenerator);
|
|
62
59
|
};
|
|
63
|
-
exports.
|
|
60
|
+
exports.makeLinkedHighlightEntity = makeLinkedHighlightEntity;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.textBackgroundColor = void 0;
|
|
4
4
|
const COLORS_NAMES = ["YELLOW", "GREEN", "AQUAMARINE", "AQUA", "BLUE", "PURPLE", "PINK", "RED", "GREY"];
|
|
5
5
|
const DEFAULT_COLOR = "YELLOW";
|
|
6
6
|
const isColorName = (color) => {
|
|
@@ -33,16 +33,16 @@ const getColorName = (color) => {
|
|
|
33
33
|
return getMigratedColorName(color);
|
|
34
34
|
};
|
|
35
35
|
const getClassName = (colorName) => {
|
|
36
|
-
return `
|
|
36
|
+
return `text-background-color ${colorName.toLowerCase()}`;
|
|
37
37
|
};
|
|
38
|
-
exports.
|
|
38
|
+
exports.textBackgroundColor = {
|
|
39
39
|
attrs: {
|
|
40
40
|
guid: { default: "" },
|
|
41
41
|
color: { default: "YELLOW" },
|
|
42
42
|
},
|
|
43
43
|
parseDOM: [
|
|
44
44
|
{
|
|
45
|
-
tag: "span[data-
|
|
45
|
+
tag: "span[data-text-background-color]",
|
|
46
46
|
getAttrs: (domNode) => {
|
|
47
47
|
const dom = domNode;
|
|
48
48
|
return {
|
|
@@ -58,7 +58,7 @@ exports.highlight = {
|
|
|
58
58
|
return [
|
|
59
59
|
"span",
|
|
60
60
|
{
|
|
61
|
-
"data-
|
|
61
|
+
"data-text-background-color": "true",
|
|
62
62
|
"data-guid": node.attrs.guid,
|
|
63
63
|
"data-color": node.attrs.color,
|
|
64
64
|
class: className,
|
|
@@ -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) {
|
|
@@ -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.8.0",
|
|
4
4
|
"description": "Fibery prosemirror schema",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"prosemirror-schema-list": "1.2.2",
|
|
41
41
|
"prosemirror-tables": "1.3.2",
|
|
42
42
|
"typescript": "5.1.6",
|
|
43
|
-
"@fibery/
|
|
44
|
-
"@fibery/
|
|
43
|
+
"@fibery/eslint-config": "8.5.1",
|
|
44
|
+
"@fibery/babel-preset": "7.4.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
|
}
|