@tiptap/core 2.0.0-beta.179 → 2.0.0-beta.181

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": "2.0.0-beta.179",
4
+ "version": "2.0.0-beta.181",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -24,20 +24,13 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "@types/prosemirror-commands": "^1.0.4",
28
- "@types/prosemirror-keymap": "^1.0.4",
29
- "@types/prosemirror-model": "^1.16.0",
30
- "@types/prosemirror-schema-list": "^1.0.3",
31
- "@types/prosemirror-state": "^1.2.8",
32
- "@types/prosemirror-transform": "^1.1.5",
33
- "@types/prosemirror-view": "^1.23.1",
34
- "prosemirror-commands": "^1.2.1",
35
- "prosemirror-keymap": "^1.1.5",
36
- "prosemirror-model": "^1.16.1",
37
- "prosemirror-schema-list": "^1.1.6",
38
- "prosemirror-state": "^1.3.4",
39
- "prosemirror-transform": "^1.3.3",
40
- "prosemirror-view": "^1.23.6"
27
+ "prosemirror-commands": "1.3.0",
28
+ "prosemirror-keymap": "1.2.0",
29
+ "prosemirror-model": "1.18.1",
30
+ "prosemirror-schema-list": "1.2.0",
31
+ "prosemirror-state": "1.4.1",
32
+ "prosemirror-transform": "1.6.0",
33
+ "prosemirror-view": "1.26.2"
41
34
  },
42
35
  "repository": {
43
36
  "type": "git",
@@ -45,5 +38,5 @@
45
38
  "directory": "packages/core"
46
39
  },
47
40
  "sideEffects": false,
48
- "gitHead": "591c0807a2ab5c34b4b7fe12c12511fe4f493ebd"
41
+ "gitHead": "090c5a44566bcd936096574fa62bf301ab4a1285"
49
42
  }
package/src/Editor.ts CHANGED
@@ -198,7 +198,7 @@ export class Editor extends EventEmitter<EditorEvents> {
198
198
  */
199
199
  public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
200
200
  const plugins = isFunction(handlePlugins)
201
- ? handlePlugins(plugin, this.state.plugins)
201
+ ? handlePlugins(plugin, [...this.state.plugins])
202
202
  : [...this.state.plugins, plugin]
203
203
 
204
204
  const state = this.state.reconfigure({ plugins })
@@ -271,7 +271,7 @@ export class Editor extends EventEmitter<EditorEvents> {
271
271
  dispatchTransaction: this.dispatchTransaction.bind(this),
272
272
  state: EditorState.create({
273
273
  doc,
274
- selection,
274
+ selection: selection || undefined,
275
275
  }),
276
276
  })
277
277
 
package/src/InputRule.ts CHANGED
@@ -188,7 +188,7 @@ export function inputRulesPlugin(props: { editor: Editor, rules: InputRule[] }):
188
188
  return null
189
189
  },
190
190
  apply(tr, prev) {
191
- const stored = tr.getMeta(this)
191
+ const stored = tr.getMeta(plugin)
192
192
 
193
193
  if (stored) {
194
194
  return stored
package/src/NodeView.ts CHANGED
@@ -49,11 +49,11 @@ export class NodeView<
49
49
  return
50
50
  }
51
51
 
52
- get dom(): Element | null {
53
- return null
52
+ get dom(): HTMLElement {
53
+ return this.editor.view.dom as HTMLElement
54
54
  }
55
55
 
56
- get contentDOM(): Element | null {
56
+ get contentDOM(): HTMLElement | null {
57
57
  return null
58
58
  }
59
59
 
package/src/PasteRule.ts CHANGED
@@ -190,8 +190,8 @@ export function pasteRulesPlugin(props: { editor: Editor, rules: PasteRule[] }):
190
190
  return false
191
191
  },
192
192
 
193
- paste: (view, event) => {
194
- const html = event.clipboardData?.getData('text/html')
193
+ paste: (view, event: Event) => {
194
+ const html = (event as ClipboardEvent).clipboardData?.getData('text/html')
195
195
 
196
196
  isPastedFromProseMirror = !!html?.includes('data-pm-slice')
197
197
 
@@ -60,7 +60,9 @@ export const focus: RawCommands['focus'] = (position = null, options = {}) => ({
60
60
  return true
61
61
  }
62
62
 
63
- const selection = resolveFocusPosition(editor.state.doc, position) || editor.state.selection
63
+ // pass through tr.doc instead of editor.state.doc
64
+ // since transactions could change the editors state before this command has been run
65
+ const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection
64
66
  const isSameSelection = editor.state.selection.eq(selection)
65
67
 
66
68
  if (dispatch) {
@@ -13,7 +13,7 @@ export const FocusEvents = Extension.create({
13
13
  key: new PluginKey('focusEvents'),
14
14
  props: {
15
15
  handleDOMEvents: {
16
- focus: (view, event) => {
16
+ focus: (view, event: Event) => {
17
17
  editor.isFocused = true
18
18
 
19
19
  const transaction = editor.state.tr
@@ -24,7 +24,7 @@ export const FocusEvents = Extension.create({
24
24
 
25
25
  return false
26
26
  },
27
- blur: (view, event) => {
27
+ blur: (view, event: Event) => {
28
28
  editor.isFocused = false
29
29
 
30
30
  const transaction = editor.state.tr
@@ -10,13 +10,7 @@ export const Tabindex = Extension.create({
10
10
  new Plugin({
11
11
  key: new PluginKey('tabindex'),
12
12
  props: {
13
- attributes: () => {
14
- if (this.editor.isEditable) {
15
- return {
16
- tabindex: '0',
17
- }
18
- }
19
- },
13
+ attributes: this.editor.isEditable ? { tabindex: '0' } : {},
20
14
  },
21
15
  }),
22
16
  ]
@@ -11,10 +11,11 @@ export function createChainableState(config: {
11
11
 
12
12
  return {
13
13
  ...state,
14
- schema: state.schema,
15
- plugins: state.plugins,
16
14
  apply: state.apply.bind(state),
17
15
  applyTransaction: state.applyTransaction.bind(state),
16
+ filterTransaction: state.filterTransaction,
17
+ plugins: state.plugins,
18
+ schema: state.schema,
18
19
  reconfigure: state.reconfigure.bind(state),
19
20
  toJSON: state.toJSON.bind(state),
20
21
  get storedMarks() {
@@ -40,7 +40,7 @@ export function getMarkRange(
40
40
  return
41
41
  }
42
42
 
43
- const mark = findMarkInSet(start.node.marks, type, attributes)
43
+ const mark = findMarkInSet([...start.node.marks], type, attributes)
44
44
 
45
45
  if (!mark) {
46
46
  return
@@ -51,7 +51,7 @@ export function getMarkRange(
51
51
  let endIndex = startIndex + 1
52
52
  let endPos = startPos + start.node.nodeSize
53
53
 
54
- findMarkInSet(start.node.marks, type, attributes)
54
+ findMarkInSet([...start.node.marks], type, attributes)
55
55
 
56
56
  while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
57
57
  startIndex -= 1
@@ -60,7 +60,7 @@ export function getMarkRange(
60
60
 
61
61
  while (
62
62
  endIndex < $pos.parent.childCount
63
- && isMarkInSet($pos.parent.child(endIndex).marks, type, attributes)
63
+ && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)
64
64
  ) {
65
65
  endPos += $pos.parent.child(endIndex).nodeSize
66
66
  endIndex += 1
@@ -27,13 +27,15 @@ export function getTextBetween(
27
27
  separated = true
28
28
  }
29
29
 
30
- text += textSerializer({
31
- node,
32
- pos,
33
- parent,
34
- index,
35
- range,
36
- })
30
+ if (parent) {
31
+ text += textSerializer({
32
+ node,
33
+ pos,
34
+ parent,
35
+ index,
36
+ range,
37
+ })
38
+ }
37
39
  } else if (node.isText) {
38
40
  text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line
39
41
  separated = false
@@ -1,6 +1,6 @@
1
1
  import { ResolvedPos } from 'prosemirror-model'
2
2
 
3
- export const getTextContentFromNodes = ($from: ResolvedPos<any>, maxMatch = 500) => {
3
+ export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
4
4
  let textBefore = ''
5
5
 
6
6
  $from.parent.nodesBetween(
@@ -1,2 +1,3 @@
1
1
  export * from './markPasteRule'
2
+ export * from './nodePasteRule'
2
3
  export * from './textPasteRule'
@@ -0,0 +1,39 @@
1
+ import { NodeType } from 'prosemirror-model'
2
+
3
+ import { PasteRule } from '../PasteRule'
4
+ import { ExtendedRegExpMatchArray } from '../types'
5
+ import { callOrReturn } from '../utilities'
6
+
7
+ /**
8
+ * Build an paste rule that adds a node when the
9
+ * matched text is pasted into it.
10
+ */
11
+ export function nodePasteRule(config: {
12
+ find: RegExp,
13
+ type: NodeType,
14
+ getAttributes?:
15
+ | Record<string, any>
16
+ | ((match: ExtendedRegExpMatchArray) => Record<string, any>)
17
+ | false
18
+ | null,
19
+ }) {
20
+ return new PasteRule({
21
+ find: config.find,
22
+ handler({ match, chain, range }) {
23
+ const attributes = callOrReturn(config.getAttributes, undefined, match)
24
+
25
+ if (attributes === false || attributes === null) {
26
+ return null
27
+ }
28
+
29
+ if (match.input) {
30
+ chain()
31
+ .deleteRange(range)
32
+ .insertContent({
33
+ type: config.type.name,
34
+ attrs: attributes,
35
+ })
36
+ }
37
+ },
38
+ })
39
+ }