@tiptap/core 2.0.0-beta.180 → 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.180",
4
+ "version": "2.0.0-beta.181",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -24,13 +24,13 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "prosemirror-commands": "^1.3.0",
28
- "prosemirror-keymap": "^1.2.0",
29
- "prosemirror-model": "^1.17.0",
30
- "prosemirror-schema-list": "^1.2.0",
31
- "prosemirror-state": "^1.4.0",
32
- "prosemirror-transform": "^1.6.0",
33
- "prosemirror-view": "^1.25.0"
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"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
@@ -38,5 +38,5 @@
38
38
  "directory": "packages/core"
39
39
  },
40
40
  "sideEffects": false,
41
- "gitHead": "a1e612bf897a14065b4f9ba6d48925c97d136811"
41
+ "gitHead": "090c5a44566bcd936096574fa62bf301ab4a1285"
42
42
  }
package/src/PasteRule.ts CHANGED
@@ -190,7 +190,7 @@ export function pasteRulesPlugin(props: { editor: Editor, rules: PasteRule[] }):
190
190
  return false
191
191
  },
192
192
 
193
- paste: (view, event) => {
193
+ paste: (view, event: Event) => {
194
194
  const html = (event as ClipboardEvent).clipboardData?.getData('text/html')
195
195
 
196
196
  isPastedFromProseMirror = !!html?.includes('data-pm-slice')
@@ -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
@@ -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
+ }