@fibery/prosemirror-schema 4.18.0 → 4.19.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Basic = exports.createSchema = void 0;
4
+ const prosemirror_suggest_changes_1 = require("@handlewithcare/prosemirror-suggest-changes");
4
5
  const prosemirror_model_1 = require("prosemirror-model");
5
6
  const prosemirror_schema_basic_1 = require("prosemirror-schema-basic");
6
7
  const prosemirror_schema_list_1 = require("prosemirror-schema-list");
@@ -80,6 +81,15 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
80
81
  }
81
82
  actualNodes = actualNodes.update("doc", {
82
83
  content: `(block | columns)+`,
84
+ marks: "insertion modification deletion",
85
+ });
86
+ // prosemirror-schema-list@1.5.0+ added validate:"number" to the order attr,
87
+ // which rejects legacy documents where order was stored as null. Drop the
88
+ // validator so those documents can still be parsed.
89
+ const orderedListSpec = actualNodes.get("ordered_list");
90
+ actualNodes = actualNodes.update("ordered_list", {
91
+ ...orderedListSpec,
92
+ attrs: { order: { default: 1 } },
83
93
  });
84
94
  const listItemSpec = actualNodes.get("list_item");
85
95
  actualNodes = actualNodes.update("list_item", {
@@ -95,12 +105,70 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
95
105
  getAttrs: (dom) => {
96
106
  const el = dom;
97
107
  const state = el.getAttribute("data-check-item-state");
108
+ // Strip the "[] "/"[x] " text prefix added by the clipboard serializer so
109
+ // it doesn't appear as document content when pasting back into Fibery.
110
+ // getAttrs runs before ProseMirror walks the children, so mutation is safe.
111
+ const firstBlock = el.firstChild;
112
+ if (firstBlock !== null && firstBlock.nodeType === 1 /* ELEMENT_NODE */) {
113
+ const firstText = firstBlock.firstChild;
114
+ if (firstText !== null && firstText.nodeType === 3 /* TEXT_NODE */) {
115
+ const text = firstText.textContent ?? "";
116
+ if (text.startsWith("[ ] ") || text.startsWith("[x] ")) {
117
+ const rest = text.slice(4);
118
+ if (rest) {
119
+ firstText.textContent = rest;
120
+ }
121
+ else {
122
+ firstBlock.removeChild(firstText);
123
+ }
124
+ }
125
+ }
126
+ }
98
127
  return {
99
128
  state: state === "TODO" || state === "DONE" ? state : null,
100
129
  id: el.getAttribute("data-list-item-id") ?? null,
101
130
  };
102
131
  },
103
132
  },
133
+ {
134
+ tag: "li",
135
+ getAttrs: (dom) => {
136
+ const el = dom;
137
+ const firstChild = el.firstChild;
138
+ if (firstChild === null) {
139
+ return false;
140
+ }
141
+ // Support pasting from external editors that output [ ] / [x] as text
142
+ // without data-check-item-state. Check text directly in <li> or inside
143
+ // the first block element (e.g. <p>).
144
+ let textNode = null;
145
+ let textParent = null;
146
+ if (firstChild.nodeType === 3 /* TEXT_NODE */) {
147
+ textNode = firstChild;
148
+ textParent = el;
149
+ }
150
+ else if (firstChild.nodeType === 1 /* ELEMENT_NODE */ && firstChild.firstChild?.nodeType === 3) {
151
+ textNode = firstChild.firstChild;
152
+ textParent = firstChild;
153
+ }
154
+ if (textNode === null) {
155
+ return false;
156
+ }
157
+ const text = textNode.textContent ?? "";
158
+ const state = text.startsWith("[ ] ") ? "TODO" : text.startsWith("[x] ") ? "DONE" : null;
159
+ if (state === null) {
160
+ return false;
161
+ }
162
+ const rest = text.slice(4);
163
+ if (rest) {
164
+ textNode.textContent = rest;
165
+ }
166
+ else {
167
+ textParent.removeChild(textNode);
168
+ }
169
+ return { state, id: null };
170
+ },
171
+ },
104
172
  { tag: "li" },
105
173
  ],
106
174
  toDOM(node) {
@@ -123,7 +191,10 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
123
191
  .addToEnd("hintQuery", hint_query_1.hintQuery)
124
192
  // We leave mark key as "highlight" only because we don't want to do migration.
125
193
  // "TextBackgroundColor" term is used everywhere through codebase.
126
- .addToEnd("highlight", text_background_color_1.textBackgroundColor),
194
+ .addToEnd("highlight", text_background_color_1.textBackgroundColor)
195
+ .addToEnd("insertion", prosemirror_suggest_changes_1.insertion)
196
+ .addToEnd("deletion", prosemirror_suggest_changes_1.deletion)
197
+ .addToEnd("modification", prosemirror_suggest_changes_1.modification),
127
198
  });
128
199
  };
129
200
  exports.createSchema = createSchema;
@@ -21,7 +21,7 @@ export declare const callout: {
21
21
  icon: string | null;
22
22
  };
23
23
  }[];
24
- toDOM(node: import("prosemirror-model").Node): [string, {
24
+ toDOM(node: import("../..").Node): [string, {
25
25
  "data-callout-node": string;
26
26
  "data-color": any;
27
27
  "data-icon-type": any;
@@ -16,14 +16,14 @@ export declare const makeEmoji: ({ getEmoji }?: EmojiOptions) => {
16
16
  group: string;
17
17
  selectable: false;
18
18
  draggable: false;
19
- leafText: (node: import("prosemirror-model").Node) => any;
19
+ leafText: (node: import("../..").Node) => any;
20
20
  parseDOM: {
21
21
  tag: string;
22
22
  getAttrs(domNode: HTMLElement): {
23
23
  code: string;
24
24
  };
25
25
  }[];
26
- toDOM(node: import("prosemirror-model").Node): [string, {
26
+ toDOM(node: import("../..").Node): [string, {
27
27
  "data-emoji-node": string;
28
28
  "data-emoji-code": any;
29
29
  }, any];
@@ -18,7 +18,7 @@ export declare const file: {
18
18
  group: string;
19
19
  selectable: false;
20
20
  draggable: false;
21
- leafText: (node: import("prosemirror-model").Node) => any;
21
+ leafText: (node: import("../..").Node) => any;
22
22
  parseDOM: {
23
23
  tag: string;
24
24
  getAttrs(domNode: HTMLElement): {
@@ -28,7 +28,7 @@ export declare const file: {
28
28
  type: string | null;
29
29
  };
30
30
  }[];
31
- toDOM(node: import("prosemirror-model").Node): [string, {
31
+ toDOM(node: import("../..").Node): [string, {
32
32
  "data-file-href": any;
33
33
  "data-size": any;
34
34
  "data-type": any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/prosemirror-schema",
3
- "version": "4.18.0",
3
+ "version": "4.19.0-next.0",
4
4
  "private": false,
5
5
  "description": "Fibery prosemirror schema",
6
6
  "files": [
@@ -22,6 +22,7 @@
22
22
  "./lib/src/nodes/fibery-section.d.ts": "./lib/src/nodes/fibery-section.d.ts"
23
23
  },
24
24
  "dependencies": {
25
+ "@handlewithcare/prosemirror-suggest-changes": "^0.1.8",
25
26
  "prosemirror-model": "1.25.4",
26
27
  "prosemirror-schema-basic": "1.2.2",
27
28
  "prosemirror-schema-list": "1.5.1",