@bigfootai/bigfoot-types 3.7.8 → 3.7.10
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/editor.js +81 -36
- package/editor.ts +96 -40
- package/package.json +1 -1
package/editor.js
CHANGED
@@ -1,48 +1,93 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.bigfootSchema = void 0;
|
7
4
|
const prosemirror_model_1 = require("prosemirror-model");
|
8
5
|
const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
|
9
6
|
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
10
|
-
const
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
const tag = {
|
8
|
+
attrs: {
|
9
|
+
tagId: { default: null },
|
10
|
+
tagType: { default: null },
|
11
|
+
recommendationId: { default: null },
|
12
|
+
ignore: { default: null },
|
13
|
+
},
|
14
|
+
inclusive: false,
|
15
|
+
parseDOM: [
|
16
|
+
{
|
17
|
+
tag: 'span[data-tag-id][data-tag-type][data-recommendation-id][data-ignore]',
|
18
|
+
getAttrs(dom) {
|
19
|
+
return {
|
20
|
+
tagId: dom.getAttribute('data-tag-id'),
|
21
|
+
tagType: dom.getAttribute('data-tag-type'),
|
22
|
+
recommendationId: dom.getAttribute('data-recommendation-id'),
|
23
|
+
ignore: dom.getAttribute('data-ignore'),
|
24
|
+
};
|
25
|
+
},
|
19
26
|
},
|
20
|
-
|
21
|
-
|
27
|
+
],
|
28
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
29
|
+
toDOM(node) {
|
30
|
+
const { tagId, tagType, recommendationId, ignore } = node.attrs;
|
31
|
+
return [
|
32
|
+
'span',
|
22
33
|
{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
'data-tag-id': tagId,
|
35
|
+
'data-tag-type': tagType,
|
36
|
+
'data-recommendation-id': recommendationId,
|
37
|
+
'data-ignore': ignore,
|
38
|
+
},
|
39
|
+
0,
|
40
|
+
];
|
41
|
+
},
|
42
|
+
};
|
43
|
+
const checklist = {
|
44
|
+
content: 'checklistItem+',
|
45
|
+
group: 'block',
|
46
|
+
toDOM: () => ['ul', 0],
|
47
|
+
parseDOM: [{ tag: 'ul.checklist' }],
|
48
|
+
};
|
49
|
+
const checklistItem = {
|
50
|
+
content: 'text*',
|
51
|
+
attrs: { checked: { default: false } },
|
52
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
53
|
+
toDOM: (node) => [
|
54
|
+
'li',
|
55
|
+
{ 'data-checked': node?.attrs?.checked ? 'true' : 'false' },
|
56
|
+
[
|
57
|
+
'input',
|
58
|
+
{
|
59
|
+
type: 'checkbox',
|
60
|
+
checked: node?.attrs?.checked ? 'checked' : '',
|
32
61
|
},
|
33
62
|
],
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
63
|
+
['span', {}],
|
64
|
+
],
|
65
|
+
parseDOM: [
|
66
|
+
{
|
67
|
+
tag: 'li[data-checked]',
|
68
|
+
getAttrs: (dom) => ({
|
69
|
+
checked: dom.getAttribute('data-checked') === 'true',
|
70
|
+
}),
|
71
|
+
},
|
72
|
+
],
|
73
|
+
};
|
74
|
+
const strong = {
|
75
|
+
parseDOM: [
|
76
|
+
{ tag: 'strong' },
|
77
|
+
{
|
78
|
+
tag: 'b',
|
79
|
+
getAttrs: (node) => node.style.fontWeight != 'normal' && null,
|
46
80
|
},
|
47
|
-
|
81
|
+
],
|
82
|
+
toDOM: () => ['strong', 0],
|
83
|
+
};
|
84
|
+
exports.bigfootSchema = new prosemirror_model_1.Schema({
|
85
|
+
nodes: (0, prosemirror_schema_list_1.addListNodes)(prosemirror_schema_basic_1.schema.spec.nodes, 'paragraph block*', 'block')
|
86
|
+
.addToEnd('checklist', checklist)
|
87
|
+
.addToEnd('checklistItem', checklistItem),
|
88
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
89
|
+
marks: orderedMap
|
90
|
+
.from(prosemirror_schema_basic_1.schema.spec.marks)
|
91
|
+
.addToEnd('tag', tag)
|
92
|
+
.addToEnd('strong', strong),
|
48
93
|
});
|
package/editor.ts
CHANGED
@@ -1,49 +1,105 @@
|
|
1
|
-
import { Schema } from 'prosemirror-model';
|
1
|
+
import { MarkSpec, NodeSpec, Schema } from 'prosemirror-model';
|
2
2
|
import { schema } from 'prosemirror-schema-basic';
|
3
3
|
import { addListNodes } from 'prosemirror-schema-list';
|
4
|
-
import orderedMap from 'orderedmap';
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
const tag: MarkSpec = {
|
6
|
+
attrs: {
|
7
|
+
tagId: { default: null },
|
8
|
+
tagType: { default: null },
|
9
|
+
recommendationId: { default: null },
|
10
|
+
ignore: { default: null },
|
11
|
+
},
|
12
|
+
inclusive: false,
|
13
|
+
parseDOM: [
|
14
|
+
{
|
15
|
+
tag: 'span[data-tag-id][data-tag-type][data-recommendation-id][data-ignore]',
|
16
|
+
getAttrs(dom: string | HTMLElement) {
|
17
|
+
return {
|
18
|
+
tagId: (dom as HTMLElement).getAttribute('data-tag-id'),
|
19
|
+
tagType: (dom as HTMLElement).getAttribute('data-tag-type'),
|
20
|
+
recommendationId: (dom as HTMLElement).getAttribute(
|
21
|
+
'data-recommendation-id'
|
22
|
+
),
|
23
|
+
ignore: (dom as HTMLElement).getAttribute('data-ignore'),
|
24
|
+
};
|
25
|
+
},
|
14
26
|
},
|
15
|
-
|
16
|
-
|
27
|
+
],
|
28
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
29
|
+
toDOM(node: {
|
30
|
+
attrs: {
|
31
|
+
tagId: string;
|
32
|
+
tagType: string;
|
33
|
+
recommendationId: string;
|
34
|
+
ignore: string;
|
35
|
+
};
|
36
|
+
}) {
|
37
|
+
const { tagId, tagType, recommendationId, ignore } = node.attrs;
|
38
|
+
return [
|
39
|
+
'span',
|
40
|
+
{
|
41
|
+
'data-tag-id': tagId,
|
42
|
+
'data-tag-type': tagType,
|
43
|
+
'data-recommendation-id': recommendationId,
|
44
|
+
'data-ignore': ignore,
|
45
|
+
},
|
46
|
+
0,
|
47
|
+
];
|
48
|
+
},
|
49
|
+
};
|
50
|
+
|
51
|
+
const checklist: NodeSpec = {
|
52
|
+
content: 'checklistItem+',
|
53
|
+
group: 'block',
|
54
|
+
toDOM: () => ['ul', 0],
|
55
|
+
parseDOM: [{ tag: 'ul.checklist' }],
|
56
|
+
};
|
57
|
+
|
58
|
+
const checklistItem: NodeSpec = {
|
59
|
+
content: 'text*',
|
60
|
+
attrs: { checked: { default: false } },
|
61
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
62
|
+
toDOM: (node: NodeSpec) => [
|
63
|
+
'li',
|
64
|
+
{ 'data-checked': node?.attrs?.checked ? 'true' : 'false' },
|
65
|
+
[
|
66
|
+
'input',
|
17
67
|
{
|
18
|
-
|
19
|
-
|
20
|
-
return {
|
21
|
-
tagId: (dom as HTMLElement).getAttribute('data-tag-id'),
|
22
|
-
tagType: (dom as HTMLElement).getAttribute(
|
23
|
-
'data-tag-type'
|
24
|
-
),
|
25
|
-
recommendationId: (dom as HTMLElement).getAttribute(
|
26
|
-
'data-recommendation-id'
|
27
|
-
),
|
28
|
-
ignore: (dom as HTMLElement).getAttribute(
|
29
|
-
'data-ignore'
|
30
|
-
),
|
31
|
-
};
|
32
|
-
},
|
68
|
+
type: 'checkbox',
|
69
|
+
checked: node?.attrs?.checked ? 'checked' : '',
|
33
70
|
},
|
34
71
|
],
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
72
|
+
['span', {}],
|
73
|
+
],
|
74
|
+
parseDOM: [
|
75
|
+
{
|
76
|
+
tag: 'li[data-checked]',
|
77
|
+
getAttrs: (dom: HTMLElement) => ({
|
78
|
+
checked: dom.getAttribute('data-checked') === 'true',
|
79
|
+
}),
|
80
|
+
},
|
81
|
+
],
|
82
|
+
};
|
83
|
+
|
84
|
+
const strong: MarkSpec = {
|
85
|
+
parseDOM: [
|
86
|
+
{ tag: 'strong' },
|
87
|
+
{
|
88
|
+
tag: 'b',
|
89
|
+
getAttrs: (node: HTMLElement) =>
|
90
|
+
node.style.fontWeight != 'normal' && null,
|
47
91
|
},
|
48
|
-
|
92
|
+
],
|
93
|
+
toDOM: () => ['strong', 0],
|
94
|
+
};
|
95
|
+
|
96
|
+
export const bigfootSchema = new Schema({
|
97
|
+
nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block')
|
98
|
+
.addToEnd('checklist', checklist)
|
99
|
+
.addToEnd('checklistItem', checklistItem),
|
100
|
+
//@ts-expect-error Not sure why this is throwing an error, but will revisit
|
101
|
+
marks: orderedMap
|
102
|
+
.from(schema.spec.marks)
|
103
|
+
.addToEnd('tag', tag)
|
104
|
+
.addToEnd('strong', strong),
|
49
105
|
});
|