@domternal/core 0.10.0 → 0.11.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/dist/index.cjs CHANGED
@@ -201,6 +201,7 @@ function inputRulesPlugin({ rules }) {
201
201
  handleDOMEvents: {
202
202
  compositionend: (view) => {
203
203
  setTimeout(() => {
204
+ if (view.isDestroyed) return;
204
205
  const { $cursor } = view.state.selection;
205
206
  if ($cursor) {
206
207
  run(view, $cursor.pos, $cursor.pos, "", rules, plugin);
@@ -1421,26 +1422,31 @@ var insertContent = (content) => ({ state, tr, dispatch }) => {
1421
1422
  const { schema } = state;
1422
1423
  const { from, to } = tr.selection;
1423
1424
  let fragment;
1424
- if (typeof content === "string") {
1425
- if (typeof window === "undefined") {
1426
- return false;
1427
- }
1428
- const parser = model.DOMParser.fromSchema(schema);
1429
- const wrapper = document.createElement("div");
1430
- wrapper.innerHTML = content;
1431
- const parsed = parser.parse(wrapper);
1432
- fragment = parsed.content;
1433
- } else if (content && typeof content === "object") {
1434
- if (Array.isArray(content)) {
1435
- const nodes = content.map((item) => schema.nodeFromJSON(item));
1436
- fragment = model.Fragment.from(nodes);
1437
- } else if ("type" in content) {
1438
- const node = schema.nodeFromJSON(content);
1439
- fragment = node.type.name === "doc" ? node.content : model.Fragment.from(node);
1425
+ try {
1426
+ if (typeof content === "string") {
1427
+ if (typeof window === "undefined") {
1428
+ return false;
1429
+ }
1430
+ const parser = model.DOMParser.fromSchema(schema);
1431
+ const wrapper = document.createElement("div");
1432
+ wrapper.innerHTML = content;
1433
+ const parsed = parser.parse(wrapper);
1434
+ fragment = parsed.content;
1435
+ } else if (content && typeof content === "object") {
1436
+ if (Array.isArray(content)) {
1437
+ if (content.length === 0) return false;
1438
+ const nodes = content.map((item) => schema.nodeFromJSON(item));
1439
+ fragment = model.Fragment.from(nodes);
1440
+ } else if ("type" in content) {
1441
+ const node = schema.nodeFromJSON(content);
1442
+ fragment = node.type.name === "doc" ? node.content : model.Fragment.from(node);
1443
+ } else {
1444
+ return false;
1445
+ }
1440
1446
  } else {
1441
1447
  return false;
1442
1448
  }
1443
- } else {
1449
+ } catch {
1444
1450
  return false;
1445
1451
  }
1446
1452
  if (!dispatch) {
@@ -5545,7 +5551,7 @@ var Heading = Node2.create({
5545
5551
  },
5546
5552
  renderHTML({ node, HTMLAttributes }) {
5547
5553
  const level = node.attrs["level"];
5548
- const validLevel = this.options.levels.includes(level) ? level : this.options.levels[0];
5554
+ const validLevel = this.options.levels.includes(level) ? level : this.options.levels[0] ?? 1;
5549
5555
  return [`h${String(validLevel)}`, { ...this.options.HTMLAttributes, ...HTMLAttributes }, 0];
5550
5556
  },
5551
5557
  addCommands() {
@@ -9429,7 +9435,7 @@ var TextColor = Extension.create({
9429
9435
  return commands.setMark("textStyle", { color, colorToken: null });
9430
9436
  },
9431
9437
  unsetTextColor: () => ({ commands }) => {
9432
- if (!commands.setMark("textStyle", { color: null })) return false;
9438
+ if (!commands.setMark("textStyle", { color: null, colorToken: null })) return false;
9433
9439
  commands.removeEmptyTextStyle();
9434
9440
  return true;
9435
9441
  },
@@ -9574,7 +9580,7 @@ var Highlight = Extension.create({
9574
9580
  return commands.setMark("textStyle", { backgroundColor: color, backgroundColorToken: null });
9575
9581
  },
9576
9582
  unsetHighlight: () => ({ commands }) => {
9577
- if (!commands.setMark("textStyle", { backgroundColor: null })) return false;
9583
+ if (!commands.setMark("textStyle", { backgroundColor: null, backgroundColorToken: null })) return false;
9578
9584
  commands.removeEmptyTextStyle();
9579
9585
  return true;
9580
9586
  },