@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,11 @@
|
|
|
1
|
+
import { Schema, Node } from "prosemirror-model";
|
|
2
|
+
interface SchemaProps {
|
|
3
|
+
isImageBlockEnabled?: boolean;
|
|
4
|
+
fiberyViewEnabled?: boolean;
|
|
5
|
+
fiberySectionEnabled?: boolean;
|
|
6
|
+
sharedColorGenerator?: any;
|
|
7
|
+
headingToDOM?: ((node: Node) => HTMLElement) | null;
|
|
8
|
+
mediaToDom?: ((node: Node) => HTMLElement) | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, fiberySectionEnabled, }?: SchemaProps) => Schema;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchema = void 0;
|
|
4
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
9
|
+
const table_nodes_1 = require("./nodes/table-nodes");
|
|
10
|
+
const paragraph_1 = require("./nodes/paragraph");
|
|
11
|
+
const heading_1 = require("./nodes/heading");
|
|
12
|
+
const media_1 = require("./nodes/media");
|
|
13
|
+
const note_1 = require("./nodes/note");
|
|
14
|
+
const important_1 = require("./nodes/important");
|
|
15
|
+
const image_block_1 = require("./nodes/image-block");
|
|
16
|
+
const entity_1 = require("./nodes/entity");
|
|
17
|
+
const mention_1 = require("./nodes/mention");
|
|
18
|
+
const fibery_view_1 = require("./nodes/fibery-view");
|
|
19
|
+
const check_list_1 = require("./nodes/check-list");
|
|
20
|
+
const check_item_1 = require("./nodes/check-item");
|
|
21
|
+
const code_block_1 = require("./nodes/code-block");
|
|
22
|
+
const video_1 = require("./nodes/video");
|
|
23
|
+
const strike_1 = require("./marks/strike");
|
|
24
|
+
const underline_1 = require("./marks/underline");
|
|
25
|
+
const hint_query_1 = require("./marks/hint-query");
|
|
26
|
+
const highlight_1 = require("./marks/highlight");
|
|
27
|
+
const linked_highlight_1 = require("./marks/linked-highlight");
|
|
28
|
+
const link_1 = require("./marks/link");
|
|
29
|
+
const fibery_section_1 = require("./nodes/fibery-section");
|
|
30
|
+
const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, fiberySectionEnabled = false, } = {}) => {
|
|
31
|
+
prosemirror_schema_basic_1.nodes.code_block = code_block_1.code_block;
|
|
32
|
+
prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
|
|
33
|
+
prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
|
|
34
|
+
prosemirror_schema_basic_1.marks.link = (0, link_1.makeLink)(prosemirror_schema_basic_1.marks.link);
|
|
35
|
+
const base = new prosemirror_model_1.Schema({ nodes: prosemirror_schema_basic_1.nodes, marks: prosemirror_schema_basic_1.marks });
|
|
36
|
+
const customNodes = {
|
|
37
|
+
note: note_1.note,
|
|
38
|
+
important: important_1.important,
|
|
39
|
+
entity: entity_1.entity,
|
|
40
|
+
mention: mention_1.mention,
|
|
41
|
+
media: (0, media_1.makeMedia)({ mediaToDom }),
|
|
42
|
+
check_item: check_item_1.check_item,
|
|
43
|
+
check_list: check_list_1.check_list,
|
|
44
|
+
video: video_1.video,
|
|
45
|
+
};
|
|
46
|
+
let actualNodes = (0, prosemirror_schema_list_1.addListNodes)(base.spec.nodes, "paragraph block*", "block")
|
|
47
|
+
.append({ ...table_nodes_1.tableNodes })
|
|
48
|
+
.append(customNodes);
|
|
49
|
+
if (fiberyViewEnabled) {
|
|
50
|
+
actualNodes = actualNodes.append({ fiberyView: fibery_view_1.fiberyView });
|
|
51
|
+
}
|
|
52
|
+
if (isImageBlockEnabled) {
|
|
53
|
+
actualNodes = actualNodes.addToStart("imageBlock", image_block_1.imageBlock);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
actualNodes = actualNodes.addToEnd("imageBlock", image_block_1.imageBlock);
|
|
57
|
+
}
|
|
58
|
+
if (fiberySectionEnabled) {
|
|
59
|
+
actualNodes = actualNodes
|
|
60
|
+
.update("doc", {
|
|
61
|
+
content: `${fibery_section_1.blockFiberySectionName}+`,
|
|
62
|
+
})
|
|
63
|
+
.append({
|
|
64
|
+
[fibery_section_1.blockFiberySectionName]: fibery_section_1.fiberySection,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return new prosemirror_model_1.Schema({
|
|
68
|
+
nodes: actualNodes,
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
marks: base.spec.marks
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
.addToEnd("strike", strike_1.strike)
|
|
75
|
+
.addToEnd("underline", underline_1.underline)
|
|
76
|
+
.addToEnd("hintQuery", hint_query_1.hintQuery)
|
|
77
|
+
.addToEnd("highlight", highlight_1.highlight)
|
|
78
|
+
.addToEnd("linkedhighlight", (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator })),
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
exports.createSchema = createSchema;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.highlight = void 0;
|
|
4
|
+
const COLORS_NAMES = ["YELLOW", "GREEN", "AQUAMARINE", "AQUA", "BLUE", "PURPLE", "PINK", "RED", "GREY"];
|
|
5
|
+
const DEFAULT_COLOR = "YELLOW";
|
|
6
|
+
const isColorName = (color) => {
|
|
7
|
+
return COLORS_NAMES.includes(color);
|
|
8
|
+
};
|
|
9
|
+
// Long time ago we used to persist raw colors values, now we've moved to persist colors enum values
|
|
10
|
+
// Until the migration is applied(raw colors -> colors names) we need to map raw colors values to color names on client side
|
|
11
|
+
const getMigratedColorName = (color) => {
|
|
12
|
+
const LEGACY_RAW_COLORS_BY_COLORS_NAMES = {
|
|
13
|
+
YELLOW: "#f6f1a2",
|
|
14
|
+
GREEN: "#d2faad",
|
|
15
|
+
AQUAMARINE: "#befccc",
|
|
16
|
+
AQUA: "#bbf9f8",
|
|
17
|
+
BLUE: "#e0f0fe",
|
|
18
|
+
PURPLE: "#f1ebfe",
|
|
19
|
+
PINK: "#fce7fb",
|
|
20
|
+
RED: "#fce9e9",
|
|
21
|
+
GREY: "#e7e9eb",
|
|
22
|
+
};
|
|
23
|
+
if (Object.values(LEGACY_RAW_COLORS_BY_COLORS_NAMES).includes(color)) {
|
|
24
|
+
const entry = Object.entries(LEGACY_RAW_COLORS_BY_COLORS_NAMES).find(([, value]) => value === color);
|
|
25
|
+
return entry[0];
|
|
26
|
+
}
|
|
27
|
+
return DEFAULT_COLOR;
|
|
28
|
+
};
|
|
29
|
+
const getColorName = (color) => {
|
|
30
|
+
if (isColorName(color)) {
|
|
31
|
+
return color;
|
|
32
|
+
}
|
|
33
|
+
return getMigratedColorName(color);
|
|
34
|
+
};
|
|
35
|
+
const getClassName = (colorName) => {
|
|
36
|
+
return `highlight ${colorName.toLowerCase()}`;
|
|
37
|
+
};
|
|
38
|
+
exports.highlight = {
|
|
39
|
+
attrs: {
|
|
40
|
+
guid: { default: "" },
|
|
41
|
+
color: { default: "YELLOW" },
|
|
42
|
+
},
|
|
43
|
+
parseDOM: [
|
|
44
|
+
{
|
|
45
|
+
tag: "span[data-highlight]",
|
|
46
|
+
getAttrs: (domNode) => {
|
|
47
|
+
const dom = domNode;
|
|
48
|
+
return {
|
|
49
|
+
color: dom.getAttribute("data-color") || DEFAULT_COLOR,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
toDOM(node) {
|
|
55
|
+
const color = node.attrs.color;
|
|
56
|
+
const colorName = getColorName(color);
|
|
57
|
+
const className = getClassName(colorName);
|
|
58
|
+
return [
|
|
59
|
+
"span",
|
|
60
|
+
{
|
|
61
|
+
"data-highlight": "true",
|
|
62
|
+
"data-guid": node.attrs.guid,
|
|
63
|
+
"data-color": node.attrs.color,
|
|
64
|
+
class: className,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hintQuery = void 0;
|
|
4
|
+
exports.hintQuery = {
|
|
5
|
+
excludes: "searchQuery",
|
|
6
|
+
inclusive: true,
|
|
7
|
+
group: "searchQuery",
|
|
8
|
+
attrs: {
|
|
9
|
+
trigger: { default: "" },
|
|
10
|
+
guid: { default: "" },
|
|
11
|
+
},
|
|
12
|
+
parseDOM: [{ tag: "span[data-hint-query]" }],
|
|
13
|
+
toDOM(node) {
|
|
14
|
+
return [
|
|
15
|
+
"span",
|
|
16
|
+
{
|
|
17
|
+
"data-hint-query": "true",
|
|
18
|
+
"data-trigger": node.attrs.trigger,
|
|
19
|
+
"data-guid": node.attrs.guid,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeLink = void 0;
|
|
4
|
+
const makeLink = (baseLink) => {
|
|
5
|
+
return {
|
|
6
|
+
...baseLink,
|
|
7
|
+
toDOM(node) {
|
|
8
|
+
const { href, title } = node.attrs;
|
|
9
|
+
return ["a", { href, title, target: "_blank", class: "prosemirror-link" }, 0];
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.makeLink = makeLink;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeLinkedHighlight = void 0;
|
|
4
|
+
const hyphenatePascal = (str) => str
|
|
5
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
6
|
+
.replace(/([A-Z]{2})[a-z]/, "$1-")
|
|
7
|
+
.toLowerCase();
|
|
8
|
+
const createMark = (markType, sharedColorGenerator) => {
|
|
9
|
+
const markTag = `span.${markType}`;
|
|
10
|
+
const markClassName = `${markType}`;
|
|
11
|
+
const preserveBool = (attr) => (attr === "true" ? true : attr === "false" ? false : attr);
|
|
12
|
+
return {
|
|
13
|
+
attrs: {
|
|
14
|
+
id: {},
|
|
15
|
+
meta: { default: {} },
|
|
16
|
+
},
|
|
17
|
+
inclusive: false,
|
|
18
|
+
parseDOM: [
|
|
19
|
+
{
|
|
20
|
+
tag: markTag,
|
|
21
|
+
getAttrs: ({ dataset }) => {
|
|
22
|
+
return {
|
|
23
|
+
id: dataset.id || false,
|
|
24
|
+
meta: Object.keys(dataset)
|
|
25
|
+
.filter((key) => key !== "id" && dataset[key] !== "false")
|
|
26
|
+
.reduce((out, key) => ({ ...out, [key]: preserveBool(JSON.parse(dataset[key])) }), { type: markType }),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
toDOM: ({ attrs }) => {
|
|
32
|
+
const { id, meta } = attrs;
|
|
33
|
+
const { hidden = false } = meta;
|
|
34
|
+
const { typeId } = meta.links && meta.links.length > 0 ? meta.links[0] : {};
|
|
35
|
+
const color = sharedColorGenerator ? sharedColorGenerator.generate(typeId) : "#eeeeee";
|
|
36
|
+
return [
|
|
37
|
+
markTag,
|
|
38
|
+
{
|
|
39
|
+
class: [markClassName, hidden ? `${markClassName}--collapsed` : ``].join(" "),
|
|
40
|
+
contenteditable: !hidden,
|
|
41
|
+
style: color ? `background-color:${color}` : ``,
|
|
42
|
+
"data-id": id,
|
|
43
|
+
...Object.keys(meta)
|
|
44
|
+
.filter((key) => meta[key] !== false) // remove specials
|
|
45
|
+
.reduce((out, key) => ({
|
|
46
|
+
...out,
|
|
47
|
+
[`data-${hyphenatePascal(key)}`]: JSON.stringify(meta[key]),
|
|
48
|
+
}), {}),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const makeLinkedHighlight = ({ sharedColorGenerator }) => {
|
|
55
|
+
// @ts-expect-error todo: fix this
|
|
56
|
+
return createMark("linkedhighlight", sharedColorGenerator);
|
|
57
|
+
};
|
|
58
|
+
exports.makeLinkedHighlight = makeLinkedHighlight;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeSpec } from "prosemirror-model";
|
|
2
|
+
import { Inline } from "./types/inline-content";
|
|
3
|
+
export interface CheckItemDefinition {
|
|
4
|
+
type: "check_item";
|
|
5
|
+
content?: Array<Inline>;
|
|
6
|
+
attrs: {
|
|
7
|
+
id: string;
|
|
8
|
+
state: "TODO" | "DONE";
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const check_item: NodeSpec;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.check_item = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
exports.check_item = {
|
|
6
|
+
content: "inline*",
|
|
7
|
+
defining: true,
|
|
8
|
+
selectable: false,
|
|
9
|
+
marks: "_",
|
|
10
|
+
attrs: {
|
|
11
|
+
id: { default: "" },
|
|
12
|
+
state: { default: "TODO" },
|
|
13
|
+
},
|
|
14
|
+
parseDOM: [
|
|
15
|
+
{
|
|
16
|
+
tag: `div[data-check-item-id]`,
|
|
17
|
+
// Default priority is 50. We normally don't change this but since this node type is
|
|
18
|
+
// also used by list-item we need to make sure that we run this parser first.
|
|
19
|
+
priority: 100,
|
|
20
|
+
getAttrs: (dom) => ({
|
|
21
|
+
id: (0, uuid_1.v4)(),
|
|
22
|
+
state: dom.getAttribute("data-check-item-state"),
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
toDOM(node) {
|
|
27
|
+
const { id, state } = node.attrs;
|
|
28
|
+
const attrs = {
|
|
29
|
+
"data-check-item-id": id,
|
|
30
|
+
"data-check-item-state": state,
|
|
31
|
+
};
|
|
32
|
+
return ["div", attrs, 0];
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NodeSpec } from "prosemirror-model";
|
|
2
|
+
import { CheckItemDefinition } from "./check-item";
|
|
3
|
+
export interface CheckListContent extends Array<CheckItemDefinition | CheckListDefinition> {
|
|
4
|
+
0: CheckItemDefinition;
|
|
5
|
+
}
|
|
6
|
+
export interface CheckListDefinition {
|
|
7
|
+
type: "check_list";
|
|
8
|
+
content: CheckListContent;
|
|
9
|
+
attrs: {
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const check_list: NodeSpec;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.check_list = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
exports.check_list = {
|
|
6
|
+
group: "block",
|
|
7
|
+
defining: true,
|
|
8
|
+
selectable: false,
|
|
9
|
+
content: `(check_item)+ (check_item|check_list)*`,
|
|
10
|
+
attrs: {
|
|
11
|
+
id: { default: "" },
|
|
12
|
+
},
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: `div[data-check-list-id]`,
|
|
16
|
+
// Default priority is 50. We normaly don't change this but since this node type is
|
|
17
|
+
// also used by ordered-list we need to make sure that we run this parser first.
|
|
18
|
+
priority: 100,
|
|
19
|
+
getAttrs: () => ({
|
|
20
|
+
id: (0, uuid_1.v4)(),
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
toDOM(node) {
|
|
25
|
+
const { id } = node.attrs;
|
|
26
|
+
const attrs = {
|
|
27
|
+
"data-check-list-id": id,
|
|
28
|
+
};
|
|
29
|
+
return ["div", attrs, 0];
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.code_block = void 0;
|
|
4
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
|
+
const getLanguageFromEditorStyle = (dom) => {
|
|
6
|
+
return dom.getAttribute("data-language") || undefined;
|
|
7
|
+
};
|
|
8
|
+
// example of BB style:
|
|
9
|
+
// <div class="codehilite language-javascript"><pre><span>hello world</span><span>\n</span></pre></div>
|
|
10
|
+
const getLanguageFromBitbucketStyle = (dom) => {
|
|
11
|
+
if (dom && dom.classList.contains("codehilite")) {
|
|
12
|
+
// code block html from Bitbucket always contains an extra new line
|
|
13
|
+
return extractLanguageFromClass(dom.className);
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
};
|
|
17
|
+
// If there is a child code element, check that for data-language
|
|
18
|
+
const getLanguageFromCode = (dom) => {
|
|
19
|
+
const firstChild = dom.firstElementChild;
|
|
20
|
+
if (firstChild && firstChild.nodeName === "CODE") {
|
|
21
|
+
return firstChild.getAttribute("data-language") || undefined;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
const extractLanguageFromClass = (className) => {
|
|
26
|
+
const languageRegex = /(?:^|\s)language-([^\s]+)/;
|
|
27
|
+
const result = languageRegex.exec(className);
|
|
28
|
+
if (result && result[1]) {
|
|
29
|
+
return result[1];
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
const removeLastNewLine = (dom) => {
|
|
34
|
+
const parent = dom && dom.parentElement;
|
|
35
|
+
if (parent && parent.classList.contains("codehilite")) {
|
|
36
|
+
dom.textContent = dom.textContent.replace(/\n$/, "");
|
|
37
|
+
}
|
|
38
|
+
return dom;
|
|
39
|
+
};
|
|
40
|
+
exports.code_block = {
|
|
41
|
+
content: "text*",
|
|
42
|
+
marks: "",
|
|
43
|
+
group: "block",
|
|
44
|
+
code: true,
|
|
45
|
+
defining: true,
|
|
46
|
+
attrs: {
|
|
47
|
+
language: { default: null },
|
|
48
|
+
},
|
|
49
|
+
parseDOM: [
|
|
50
|
+
{
|
|
51
|
+
tag: "pre",
|
|
52
|
+
preserveWhitespace: "full",
|
|
53
|
+
getAttrs: (domNode) => {
|
|
54
|
+
const dom = domNode;
|
|
55
|
+
const language = getLanguageFromBitbucketStyle(dom.parentElement) ||
|
|
56
|
+
getLanguageFromEditorStyle(dom.parentElement) ||
|
|
57
|
+
getLanguageFromCode(dom) ||
|
|
58
|
+
dom.getAttribute("data-language");
|
|
59
|
+
removeLastNewLine(dom);
|
|
60
|
+
return { language };
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
// Handle VSCode paste
|
|
64
|
+
{
|
|
65
|
+
tag: "div[style]",
|
|
66
|
+
preserveWhitespace: "full",
|
|
67
|
+
getAttrs: (domNode) => {
|
|
68
|
+
const dom = domNode;
|
|
69
|
+
if (dom.style.whiteSpace === "pre" ||
|
|
70
|
+
(dom.style.fontFamily && dom.style.fontFamily.toLowerCase().indexOf("monospace") > -1)) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
getContent: (domNode, schema) => {
|
|
76
|
+
const dom = domNode;
|
|
77
|
+
const code = Array.from(dom.children)
|
|
78
|
+
.map((child) => child.textContent)
|
|
79
|
+
.filter((x) => x !== undefined)
|
|
80
|
+
.join("\n");
|
|
81
|
+
return code ? prosemirror_model_1.Fragment.from(schema.text(code)) : prosemirror_model_1.Fragment.empty;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
// Handle GitHub/Gist paste
|
|
85
|
+
{
|
|
86
|
+
tag: "table[style]",
|
|
87
|
+
preserveWhitespace: "full",
|
|
88
|
+
getAttrs: (dom) => {
|
|
89
|
+
if (dom.querySelector('td[class*="blob-code"]')) {
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
toDOM(node) {
|
|
97
|
+
return ["pre", ["code", { "data-language": node.attrs.language }, 0]];
|
|
98
|
+
},
|
|
99
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeSpec } from "prosemirror-model";
|
|
2
|
+
export interface EntityAttributes {
|
|
3
|
+
id: string;
|
|
4
|
+
typeId: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface EntityDefinition {
|
|
8
|
+
type: "entity";
|
|
9
|
+
attrs: EntityAttributes;
|
|
10
|
+
}
|
|
11
|
+
export declare const entity: NodeSpec;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entity = void 0;
|
|
4
|
+
exports.entity = {
|
|
5
|
+
inline: true,
|
|
6
|
+
group: "inline",
|
|
7
|
+
selectable: false,
|
|
8
|
+
attrs: {
|
|
9
|
+
id: { default: "" },
|
|
10
|
+
text: { default: "" },
|
|
11
|
+
typeId: { default: "" },
|
|
12
|
+
},
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: "span[data-entity-id]",
|
|
16
|
+
getAttrs: (domNode) => {
|
|
17
|
+
const dom = domNode;
|
|
18
|
+
return {
|
|
19
|
+
id: dom.getAttribute("data-entity-id"),
|
|
20
|
+
text: dom.textContent,
|
|
21
|
+
typeId: dom.getAttribute("data-entity-type-id"),
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
toDOM(node) {
|
|
27
|
+
const { id, typeId, text } = node.attrs;
|
|
28
|
+
const attrs = {
|
|
29
|
+
"data-entity-id": id,
|
|
30
|
+
"data-entity-type-id": typeId,
|
|
31
|
+
contenteditable: "false",
|
|
32
|
+
};
|
|
33
|
+
return ["span", attrs, text];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fiberySection = exports.blockFiberySectionName = void 0;
|
|
4
|
+
const sectionIdAttrName = "data-section-id";
|
|
5
|
+
const tagName = "fibery-section";
|
|
6
|
+
exports.blockFiberySectionName = "fiberySection";
|
|
7
|
+
exports.fiberySection = {
|
|
8
|
+
content: "block+",
|
|
9
|
+
attrs: {
|
|
10
|
+
id: { default: "" },
|
|
11
|
+
},
|
|
12
|
+
parseDOM: [
|
|
13
|
+
{
|
|
14
|
+
tag: `${tagName}[${sectionIdAttrName}]`,
|
|
15
|
+
getAttrs: (domNode) => {
|
|
16
|
+
const dom = domNode;
|
|
17
|
+
return {
|
|
18
|
+
id: dom.getAttribute(sectionIdAttrName),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
toDOM(node) {
|
|
24
|
+
const { id } = node.attrs;
|
|
25
|
+
const attrs = {
|
|
26
|
+
[sectionIdAttrName]: id,
|
|
27
|
+
};
|
|
28
|
+
return [tagName, attrs, ""];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fiberyView = void 0;
|
|
4
|
+
exports.fiberyView = {
|
|
5
|
+
inline: false,
|
|
6
|
+
group: "block",
|
|
7
|
+
selectable: true,
|
|
8
|
+
atom: true,
|
|
9
|
+
draggable: false,
|
|
10
|
+
attrs: {
|
|
11
|
+
id: { default: "" },
|
|
12
|
+
},
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: "div[data-view-id]",
|
|
16
|
+
getAttrs: (domNode) => {
|
|
17
|
+
const dom = domNode;
|
|
18
|
+
return {
|
|
19
|
+
id: dom.getAttribute("data-view-id"),
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
toDOM(node) {
|
|
25
|
+
const { id } = node.attrs;
|
|
26
|
+
const attrs = {
|
|
27
|
+
"data-view-id": id,
|
|
28
|
+
contenteditable: "false",
|
|
29
|
+
};
|
|
30
|
+
return ["div", attrs, ""];
|
|
31
|
+
},
|
|
32
|
+
};
|