@fibery/prosemirror-schema 4.18.0 → 4.18.1
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.js +66 -0
- package/package.json +1 -1
package/lib/src/create-schema.js
CHANGED
|
@@ -81,6 +81,14 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
81
81
|
actualNodes = actualNodes.update("doc", {
|
|
82
82
|
content: `(block | columns)+`,
|
|
83
83
|
});
|
|
84
|
+
// prosemirror-schema-list@1.5.0+ added validate:"number" to the order attr,
|
|
85
|
+
// which rejects legacy documents where order was stored as null. Drop the
|
|
86
|
+
// validator so those documents can still be parsed.
|
|
87
|
+
const orderedListSpec = actualNodes.get("ordered_list");
|
|
88
|
+
actualNodes = actualNodes.update("ordered_list", {
|
|
89
|
+
...orderedListSpec,
|
|
90
|
+
attrs: { order: { default: 1 } },
|
|
91
|
+
});
|
|
84
92
|
const listItemSpec = actualNodes.get("list_item");
|
|
85
93
|
actualNodes = actualNodes.update("list_item", {
|
|
86
94
|
...listItemSpec,
|
|
@@ -95,12 +103,70 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
|
|
|
95
103
|
getAttrs: (dom) => {
|
|
96
104
|
const el = dom;
|
|
97
105
|
const state = el.getAttribute("data-check-item-state");
|
|
106
|
+
// Strip the "[] "/"[x] " text prefix added by the clipboard serializer so
|
|
107
|
+
// it doesn't appear as document content when pasting back into Fibery.
|
|
108
|
+
// getAttrs runs before ProseMirror walks the children, so mutation is safe.
|
|
109
|
+
const firstBlock = el.firstChild;
|
|
110
|
+
if (firstBlock !== null && firstBlock.nodeType === 1 /* ELEMENT_NODE */) {
|
|
111
|
+
const firstText = firstBlock.firstChild;
|
|
112
|
+
if (firstText !== null && firstText.nodeType === 3 /* TEXT_NODE */) {
|
|
113
|
+
const text = firstText.textContent ?? "";
|
|
114
|
+
if (text.startsWith("[ ] ") || text.startsWith("[x] ")) {
|
|
115
|
+
const rest = text.slice(4);
|
|
116
|
+
if (rest) {
|
|
117
|
+
firstText.textContent = rest;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
firstBlock.removeChild(firstText);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
98
125
|
return {
|
|
99
126
|
state: state === "TODO" || state === "DONE" ? state : null,
|
|
100
127
|
id: el.getAttribute("data-list-item-id") ?? null,
|
|
101
128
|
};
|
|
102
129
|
},
|
|
103
130
|
},
|
|
131
|
+
{
|
|
132
|
+
tag: "li",
|
|
133
|
+
getAttrs: (dom) => {
|
|
134
|
+
const el = dom;
|
|
135
|
+
const firstChild = el.firstChild;
|
|
136
|
+
if (firstChild === null) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
// Support pasting from external editors that output [ ] / [x] as text
|
|
140
|
+
// without data-check-item-state. Check text directly in <li> or inside
|
|
141
|
+
// the first block element (e.g. <p>).
|
|
142
|
+
let textNode = null;
|
|
143
|
+
let textParent = null;
|
|
144
|
+
if (firstChild.nodeType === 3 /* TEXT_NODE */) {
|
|
145
|
+
textNode = firstChild;
|
|
146
|
+
textParent = el;
|
|
147
|
+
}
|
|
148
|
+
else if (firstChild.nodeType === 1 /* ELEMENT_NODE */ && firstChild.firstChild?.nodeType === 3) {
|
|
149
|
+
textNode = firstChild.firstChild;
|
|
150
|
+
textParent = firstChild;
|
|
151
|
+
}
|
|
152
|
+
if (textNode === null) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const text = textNode.textContent ?? "";
|
|
156
|
+
const state = text.startsWith("[ ] ") ? "TODO" : text.startsWith("[x] ") ? "DONE" : null;
|
|
157
|
+
if (state === null) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const rest = text.slice(4);
|
|
161
|
+
if (rest) {
|
|
162
|
+
textNode.textContent = rest;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
textParent.removeChild(textNode);
|
|
166
|
+
}
|
|
167
|
+
return { state, id: null };
|
|
168
|
+
},
|
|
169
|
+
},
|
|
104
170
|
{ tag: "li" },
|
|
105
171
|
],
|
|
106
172
|
toDOM(node) {
|