@tiptap/core 3.0.0-beta.25 → 3.0.0-beta.27

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "3.0.0-beta.25",
4
+ "version": "3.0.0-beta.27",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -52,11 +52,10 @@
52
52
  "jsx-dev-runtime"
53
53
  ],
54
54
  "devDependencies": {
55
- "prosemirror-dev-toolkit": "^1.1.8",
56
- "@tiptap/pm": "3.0.0-beta.25"
55
+ "@tiptap/pm": "3.0.0-beta.27"
57
56
  },
58
57
  "peerDependencies": {
59
- "@tiptap/pm": "3.0.0-beta.25"
58
+ "@tiptap/pm": "3.0.0-beta.27"
60
59
  },
61
60
  "repository": {
62
61
  "type": "git",
package/src/Editor.ts CHANGED
@@ -92,7 +92,6 @@ export class Editor extends EventEmitter<EditorEvents> {
92
92
  enablePasteRules: true,
93
93
  enableCoreExtensions: true,
94
94
  enableContentCheck: false,
95
- enableDevTools: false,
96
95
  emitContentError: false,
97
96
  onBeforeCreate: () => null,
98
97
  onCreate: () => null,
@@ -187,43 +186,6 @@ export class Editor extends EventEmitter<EditorEvents> {
187
186
  this.css = null
188
187
  }
189
188
 
190
- /**
191
- *
192
- * @returns
193
- */
194
- /**
195
- * Applies ProseMirror dev tools to the editor instance if enabled and running in a browser environment.
196
- *
197
- * This method dynamically imports the `prosemirror-dev-toolkit` package and applies it to the current
198
- * editor view. If the dev tools are not installed, a warning is logged to the console.
199
- *
200
- * @private
201
- * @remarks
202
- * - Dev tools are only applied if `this.options.enableDevTools` is `true` and the code is running in a browser.
203
- * - If the editor view is not available, the dev tools are not applied.
204
- * - If the `prosemirror-dev-toolkit` package is missing, a warning is shown in the console.
205
- *
206
- * @returns {void}
207
- */
208
- private applyDevTools(): void {
209
- if (typeof window === 'undefined' || !this.options.enableDevTools) {
210
- return
211
- }
212
-
213
- import('prosemirror-dev-toolkit')
214
- .then(({ applyDevTools }) => {
215
- if (!this.editorView) {
216
- return
217
- }
218
-
219
- applyDevTools(this.editorView)
220
- })
221
- .catch(() => {
222
- console.warn('[Tiptap warning]: Devtools are enabled but `prosemirror-dev-toolkit` is not installed.')
223
- console.warn("Install 'prosemirror-dev-toolkit' as a dev dependency to use the dev tools.")
224
- })
225
- }
226
-
227
189
  /**
228
190
  * Returns the editor storage.
229
191
  */
@@ -527,11 +489,6 @@ export class Editor extends EventEmitter<EditorEvents> {
527
489
  state: this.editorState,
528
490
  })
529
491
 
530
- // Apply dev tools if enabled
531
- if (this.options.enableDevTools) {
532
- this.applyDevTools()
533
- }
534
-
535
492
  // `editor.view` is not yet available at this time.
536
493
  // Therefore we will add all plugins and node views directly afterwards.
537
494
  const newState = this.state.reconfigure({
@@ -17,7 +17,7 @@ import {
17
17
  sortExtensions,
18
18
  splitExtensions,
19
19
  } from './helpers/index.js'
20
- import { type MarkConfig, type NodeConfig, type Storage, getMarkType } from './index.js'
20
+ import { type MarkConfig, type NodeConfig, type Storage, getMarkType, updateMarkViewAttributes } from './index.js'
21
21
  import type { InputRule } from './InputRule.js'
22
22
  import { inputRulesPlugin } from './InputRule.js'
23
23
  import { Mark } from './Mark.js'
@@ -262,6 +262,9 @@ export class ExtensionManager {
262
262
  editor,
263
263
  extension,
264
264
  HTMLAttributes,
265
+ updateAttributes: (attrs: Record<string, any>) => {
266
+ updateMarkViewAttributes(mark, editor, attrs)
267
+ },
265
268
  })
266
269
  }
267
270
 
package/src/MarkView.ts CHANGED
@@ -1,9 +1,57 @@
1
+ import type { Mark } from '@tiptap/pm/model'
1
2
  import type { ViewMutationRecord } from '@tiptap/pm/view'
2
3
 
3
4
  import type { Editor } from './Editor.js'
4
5
  import type { MarkViewProps, MarkViewRendererOptions } from './types.js'
5
6
  import { isAndroid, isiOS } from './utilities/index.js'
6
7
 
8
+ export function updateMarkViewAttributes(checkMark: Mark, editor: Editor, attrs: Record<string, any> = {}): void {
9
+ const { state } = editor
10
+ const { doc, tr } = state
11
+ const thisMark = checkMark
12
+
13
+ doc.descendants((node, pos) => {
14
+ const from = tr.mapping.map(pos)
15
+ const to = tr.mapping.map(pos) + node.nodeSize
16
+ let foundMark: Mark | null = null
17
+
18
+ // find the mark on the current node
19
+ node.marks.forEach(mark => {
20
+ if (mark !== thisMark) {
21
+ return false
22
+ }
23
+
24
+ foundMark = mark
25
+ })
26
+
27
+ if (!foundMark) {
28
+ return
29
+ }
30
+
31
+ // check if we need to update given the attributes
32
+ let needsUpdate = false
33
+ Object.keys(attrs).forEach(k => {
34
+ if (attrs[k] !== foundMark!.attrs[k]) {
35
+ needsUpdate = true
36
+ }
37
+ })
38
+
39
+ if (needsUpdate) {
40
+ const updatedMark = checkMark.type.create({
41
+ ...checkMark.attrs,
42
+ ...attrs,
43
+ })
44
+
45
+ tr.removeMark(from, to, checkMark.type)
46
+ tr.addMark(from, to, updatedMark)
47
+ }
48
+ })
49
+
50
+ if (tr.docChanged) {
51
+ editor.view.dispatch(tr)
52
+ }
53
+ }
54
+
7
55
  export class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {
8
56
  component: Component
9
57
  editor: Editor
@@ -27,6 +75,14 @@ export class MarkView<Component, Options extends MarkViewRendererOptions = MarkV
27
75
  return null
28
76
  }
29
77
 
78
+ /**
79
+ * Update the attributes of the mark in the document.
80
+ * @param attrs The attributes to update.
81
+ */
82
+ updateAttributes(attrs: Record<string, any>, checkMark?: Mark): void {
83
+ updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs)
84
+ }
85
+
30
86
  ignoreMutation(mutation: ViewMutationRecord): boolean {
31
87
  if (!this.dom || !this.contentDOM) {
32
88
  return true
package/src/types.ts CHANGED
@@ -363,18 +363,6 @@ export interface EditorOptions {
363
363
  * @default false
364
364
  */
365
365
  emitContentError: boolean
366
- /**
367
- * Enable a lazy-loaded Prosemirror DevTools integration.
368
- *
369
- * Requires having the `prosemirror-dev-toolkit` npm package installed.
370
- * @type boolean
371
- * @default false
372
- * @example
373
- * ```js
374
- * enableDevTools: true
375
- * ```
376
- */
377
- enableDevTools: boolean
378
366
  /**
379
367
  * Called before the editor is constructed.
380
368
  */
@@ -674,9 +662,11 @@ export interface MarkViewRendererProps {
674
662
  * The HTML attributes that should be added to the mark's DOM element.
675
663
  */
676
664
  HTMLAttributes: Record<string, any>
665
+
666
+ updateAttributes: (attrs: Record<string, any>) => void
677
667
  }
678
668
 
679
- export type MarkViewRenderer = (props: MarkViewRendererProps) => MarkView
669
+ export type MarkViewRenderer<Props = MarkViewRendererProps> = (props: Props) => MarkView
680
670
 
681
671
  export interface MarkViewRendererOptions {
682
672
  ignoreMutation: ((props: { mutation: ViewMutationRecord }) => boolean) | null
@@ -1,36 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
-
31
- export {
32
- __commonJS,
33
- __export,
34
- __toESM
35
- };
36
- //# sourceMappingURL=chunk-G3PMV62Z.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}