@tiptap/core 3.0.0-beta.5 → 3.0.0-beta.7

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.d.cts CHANGED
@@ -1155,6 +1155,15 @@ interface EditorOptions {
1155
1155
  * @default false
1156
1156
  */
1157
1157
  enableContentCheck: boolean;
1158
+ /**
1159
+ * If `true`, the editor will emit the `contentError` event if invalid content is
1160
+ * encountered but `enableContentCheck` is `false`. This lets you preserve the
1161
+ * invalid editor content while still showing a warning or error message to
1162
+ * the user.
1163
+ *
1164
+ * @default false
1165
+ */
1166
+ emitContentError: boolean;
1158
1167
  /**
1159
1168
  * Called before the editor is constructed.
1160
1169
  */
package/dist/index.d.ts CHANGED
@@ -1155,6 +1155,15 @@ interface EditorOptions {
1155
1155
  * @default false
1156
1156
  */
1157
1157
  enableContentCheck: boolean;
1158
+ /**
1159
+ * If `true`, the editor will emit the `contentError` event if invalid content is
1160
+ * encountered but `enableContentCheck` is `false`. This lets you preserve the
1161
+ * invalid editor content while still showing a warning or error message to
1162
+ * the user.
1163
+ *
1164
+ * @default false
1165
+ */
1166
+ emitContentError: boolean;
1158
1167
  /**
1159
1168
  * Called before the editor is constructed.
1160
1169
  */
package/dist/index.js CHANGED
@@ -2716,18 +2716,10 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2716
2716
  };
2717
2717
  let content;
2718
2718
  const { selection } = editor.state;
2719
- try {
2720
- content = createNodeFromContent(value, editor.schema, {
2721
- parseOptions: {
2722
- preserveWhitespace: "full",
2723
- ...options.parseOptions
2724
- },
2725
- errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
2726
- });
2727
- } catch (e) {
2719
+ const emitContentError = (error) => {
2728
2720
  editor.emit("contentError", {
2729
2721
  editor,
2730
- error: e,
2722
+ error,
2731
2723
  disableCollaboration: () => {
2732
2724
  if ("collaboration" in editor.storage && typeof editor.storage.collaboration === "object" && editor.storage.collaboration) {
2733
2725
  ;
@@ -2735,6 +2727,28 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2735
2727
  }
2736
2728
  }
2737
2729
  });
2730
+ };
2731
+ const parseOptions = {
2732
+ preserveWhitespace: "full",
2733
+ ...options.parseOptions
2734
+ };
2735
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
2736
+ try {
2737
+ createNodeFromContent(value, editor.schema, {
2738
+ parseOptions,
2739
+ errorOnInvalidContent: true
2740
+ });
2741
+ } catch (e) {
2742
+ emitContentError(e);
2743
+ }
2744
+ }
2745
+ try {
2746
+ content = createNodeFromContent(value, editor.schema, {
2747
+ parseOptions,
2748
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
2749
+ });
2750
+ } catch (e) {
2751
+ emitContentError(e);
2738
2752
  return false;
2739
2753
  }
2740
2754
  let { from, to } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
@@ -4269,6 +4283,7 @@ var Editor = class extends EventEmitter {
4269
4283
  enablePasteRules: true,
4270
4284
  enableCoreExtensions: true,
4271
4285
  enableContentCheck: false,
4286
+ emitContentError: false,
4272
4287
  onBeforeCreate: () => null,
4273
4288
  onCreate: () => null,
4274
4289
  onUpdate: () => null,