@fibery/prosemirror-schema 1.6.1 → 3.0.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/index.d.ts +1 -0
- package/lib/index.js +17 -848
- package/lib/src/create-schema.d.ts +10 -0
- package/lib/src/create-schema.js +69 -0
- package/lib/src/marks/highlight.d.ts +2 -0
- package/lib/src/marks/highlight.js +68 -0
- package/lib/src/marks/highlight.test.d.ts +1 -0
- package/lib/src/marks/highlight.test.js +23 -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 +30 -0
- package/lib/src/marks/linked-highlight.js +57 -0
- package/lib/src/marks/linked-highlight.test.d.ts +1 -0
- package/lib/src/marks/linked-highlight.test.js +37 -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/code-block.test.d.ts +1 -0
- package/lib/src/nodes/code-block.test.js +147 -0
- package/lib/src/nodes/entity.d.ts +11 -0
- package/lib/src/nodes/entity.js +35 -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 +22 -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/src/nodes/video.test.d.ts +1 -0
- package/lib/src/nodes/video.test.js +42 -0
- package/lib/test-helpers/index.d.ts +4 -0
- package/lib/test-helpers/index.js +21 -0
- package/package.json +5 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema, Node } from "prosemirror-model";
|
|
2
|
+
interface SchemaProps {
|
|
3
|
+
isImageBlockEnabled?: boolean;
|
|
4
|
+
fiberyViewEnabled?: boolean;
|
|
5
|
+
sharedColorGenerator?: any;
|
|
6
|
+
headingToDOM?: ((node: Node) => HTMLElement) | null;
|
|
7
|
+
mediaToDom?: ((node: Node) => HTMLElement) | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const createSchema: ({ sharedColorGenerator, headingToDOM, mediaToDom, isImageBlockEnabled, fiberyViewEnabled, }?: SchemaProps) => Schema;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
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 createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaToDom = null, isImageBlockEnabled = false, fiberyViewEnabled = false, } = {}) => {
|
|
30
|
+
prosemirror_schema_basic_1.nodes.code_block = code_block_1.code_block;
|
|
31
|
+
prosemirror_schema_basic_1.nodes.paragraph = paragraph_1.paragraph;
|
|
32
|
+
prosemirror_schema_basic_1.nodes.heading = (0, heading_1.makeHeading)({ headingToDOM });
|
|
33
|
+
prosemirror_schema_basic_1.marks.link = (0, link_1.makeLink)(prosemirror_schema_basic_1.marks.link);
|
|
34
|
+
const base = new prosemirror_model_1.Schema({ nodes: prosemirror_schema_basic_1.nodes, marks: prosemirror_schema_basic_1.marks });
|
|
35
|
+
const customNodes = {
|
|
36
|
+
note: note_1.note,
|
|
37
|
+
important: important_1.important,
|
|
38
|
+
entity: entity_1.entity,
|
|
39
|
+
mention: mention_1.mention,
|
|
40
|
+
media: (0, media_1.makeMedia)({ mediaToDom }),
|
|
41
|
+
check_item: check_item_1.check_item,
|
|
42
|
+
check_list: check_list_1.check_list,
|
|
43
|
+
video: video_1.video,
|
|
44
|
+
};
|
|
45
|
+
let actualNodes = (0, prosemirror_schema_list_1.addListNodes)(base.spec.nodes, "paragraph block*", "block").append(table_nodes_1.tableNodes).append(customNodes);
|
|
46
|
+
if (fiberyViewEnabled) {
|
|
47
|
+
actualNodes = actualNodes.append({ fiberyView: fibery_view_1.fiberyView });
|
|
48
|
+
}
|
|
49
|
+
if (isImageBlockEnabled) {
|
|
50
|
+
actualNodes = actualNodes.addToStart("imageBlock", image_block_1.imageBlock);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
actualNodes = actualNodes.addToEnd("imageBlock", image_block_1.imageBlock);
|
|
54
|
+
}
|
|
55
|
+
return new prosemirror_model_1.Schema({
|
|
56
|
+
nodes: actualNodes,
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
marks: base.spec.marks
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
.addToEnd("strike", strike_1.strike)
|
|
63
|
+
.addToEnd("underline", underline_1.underline)
|
|
64
|
+
.addToEnd("hintQuery", hint_query_1.hintQuery)
|
|
65
|
+
.addToEnd("highlight", highlight_1.highlight)
|
|
66
|
+
.addToEnd("linkedhighlight", (0, linked_highlight_1.makeLinkedHighlight)({ sharedColorGenerator })),
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const create_schema_1 = require("../create-schema");
|
|
4
|
+
const test_helpers_1 = require("../../test-helpers");
|
|
5
|
+
describe("highlight", () => {
|
|
6
|
+
const schema = (0, create_schema_1.createSchema)();
|
|
7
|
+
const highlight = schema.marks.highlight;
|
|
8
|
+
it("serializes color name to class name", () => {
|
|
9
|
+
const node = schema.text("foo", [highlight.create({ color: "YELLOW" })]);
|
|
10
|
+
const html = (0, test_helpers_1.toHTML)(node, schema);
|
|
11
|
+
expect(html).toContain('class="highlight yellow"');
|
|
12
|
+
});
|
|
13
|
+
it("serializes known legacy raw color to class name", () => {
|
|
14
|
+
const node = schema.text("foo", [highlight.create({ color: "#d2faad" })]);
|
|
15
|
+
const html = (0, test_helpers_1.toHTML)(node, schema);
|
|
16
|
+
expect(html).toContain('class="highlight green"');
|
|
17
|
+
});
|
|
18
|
+
it("serializes unknown legacy raw color to default class name", () => {
|
|
19
|
+
const node = schema.text("foo", [highlight.create({ color: "#ffffff" })]);
|
|
20
|
+
const html = (0, test_helpers_1.toHTML)(node, schema);
|
|
21
|
+
expect(html).toContain('class="highlight yellow"');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -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" }, 0];
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.makeLink = makeLink;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function makeLinkedHighlight({ sharedColorGenerator }: {
|
|
2
|
+
sharedColorGenerator: any;
|
|
3
|
+
}): {
|
|
4
|
+
attrs: {
|
|
5
|
+
id: {};
|
|
6
|
+
meta: {
|
|
7
|
+
default: {};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
inclusive: boolean;
|
|
11
|
+
parseDOM: {
|
|
12
|
+
tag: string;
|
|
13
|
+
getAttrs: ({ dataset }: {
|
|
14
|
+
dataset: any;
|
|
15
|
+
}) => {
|
|
16
|
+
id: any;
|
|
17
|
+
meta: {
|
|
18
|
+
type: any;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}[];
|
|
22
|
+
toDOM: ({ attrs }: {
|
|
23
|
+
attrs: any;
|
|
24
|
+
}) => (string | {
|
|
25
|
+
class: string;
|
|
26
|
+
contenteditable: boolean;
|
|
27
|
+
style: string;
|
|
28
|
+
"data-id": any;
|
|
29
|
+
})[];
|
|
30
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
return createMark("linkedhighlight", sharedColorGenerator);
|
|
56
|
+
};
|
|
57
|
+
exports.makeLinkedHighlight = makeLinkedHighlight;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const create_schema_1 = require("../create-schema");
|
|
4
|
+
const test_helpers_1 = require("../../test-helpers");
|
|
5
|
+
describe("schema linked highlight mark", () => {
|
|
6
|
+
it("serializes to the correct HTML", () => {
|
|
7
|
+
const schema = (0, create_schema_1.createSchema)();
|
|
8
|
+
const node = schema.text("foo", [
|
|
9
|
+
schema.marks.linkedhighlight.create({
|
|
10
|
+
id: "id",
|
|
11
|
+
meta: {
|
|
12
|
+
links: [{ typeId: "type-id" }],
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
]);
|
|
16
|
+
const html = (0, test_helpers_1.toHTML)(node, schema);
|
|
17
|
+
expect(html).toContain('data-id="id"');
|
|
18
|
+
expect(html).toContain('style="background-color:#eeeeee"');
|
|
19
|
+
});
|
|
20
|
+
it("serializes to the correct HTML with color generator provided", () => {
|
|
21
|
+
const sharedColorGenerator = {
|
|
22
|
+
generate: () => "#FFFFFF",
|
|
23
|
+
};
|
|
24
|
+
const schema = (0, create_schema_1.createSchema)({ sharedColorGenerator });
|
|
25
|
+
const node = schema.text("foo", [
|
|
26
|
+
schema.marks.linkedhighlight.create({
|
|
27
|
+
id: "id",
|
|
28
|
+
meta: {
|
|
29
|
+
links: [{ typeId: "type-id" }],
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
]);
|
|
33
|
+
const html = (0, test_helpers_1.toHTML)(node, schema);
|
|
34
|
+
expect(html).toContain('data-id="id"');
|
|
35
|
+
expect(html).toContain('style="background-color:#FFFFFF"');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|