@doist/typist 2.0.0 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [2.0.1](https://github.com/Doist/typist/compare/v2.0.0...v2.0.1) (2023-09-14)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **commands:** Buggy `insertMarkdownContentAt` implementation ([#442](https://github.com/Doist/typist/issues/442)) ([b9667f9](https://github.com/Doist/typist/commit/b9667f94d726285438244db1c58662b7c04ed8be))
6
+
1
7
  ## [2.0.0](https://github.com/Doist/typist/compare/v1.5.0...v2.0.0) (2023-09-13)
2
8
 
3
9
  ### ⚠ BREAKING CHANGES
@@ -1,6 +1,6 @@
1
1
  import { RawCommands } from '@tiptap/core';
2
2
  import type { Range } from '@tiptap/core';
3
- import type { ParseOptions } from 'prosemirror-model';
3
+ import type { ParseOptions } from '@tiptap/pm/model';
4
4
  /**
5
5
  * Augment the official `@tiptap/core` module with extra commands so that the compiler knows about
6
6
  * them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.
@@ -1 +1 @@
1
- {"version":3,"file":"insert-markdown-content-at.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2B,MAAM,cAAc,CAAA;AAMnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD;;;GAGG;AACH,OAAO,QAAQ,cAAc,CAAC;IAC1B,UAAU,QAAQ,CAAC,UAAU;QACzB,uBAAuB,EAAE;YACrB;;;;;;;;eAQG;YACH,uBAAuB,EAAE,CACrB,QAAQ,EAAE,MAAM,GAAG,KAAK,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;gBACN,YAAY,CAAC,EAAE,YAAY,CAAA;gBAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;aAC5B,KACA,UAAU,CAAA;SAClB,CAAA;KACJ;CACJ;AAED;;;;;GAKG;AACH,iBAAS,uBAAuB,CAC5B,QAAQ,EAAE,MAAM,GAAG,KAAK,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACN,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC5B,GACF,UAAU,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC,CAgDpD;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
1
+ {"version":3,"file":"insert-markdown-content-at.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2B,MAAM,cAAc,CAAA;AAMnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;GAGG;AACH,OAAO,QAAQ,cAAc,CAAC;IAC1B,UAAU,QAAQ,CAAC,UAAU;QACzB,uBAAuB,EAAE;YACrB;;;;;;;;eAQG;YACH,uBAAuB,EAAE,CACrB,QAAQ,EAAE,MAAM,GAAG,KAAK,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;gBACN,YAAY,CAAC,EAAE,YAAY,CAAA;gBAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;aAC5B,KACA,UAAU,CAAA;SAClB,CAAA;KACJ;CACJ;AAED;;;;;GAKG;AACH,iBAAS,uBAAuB,CAC5B,QAAQ,EAAE,MAAM,GAAG,KAAK,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACN,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC5B,GACF,UAAU,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC,CAqCpD;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { selectionToInsertionEnd } from '@tiptap/core';
2
- import { DOMParser } from 'prosemirror-model';
2
+ import { DOMParser } from '@tiptap/pm/model';
3
3
  import { parseHtmlToElement } from '../../../../helpers/dom';
4
4
  import { getHTMLSerializerInstance } from '../../../../serializers/html/html';
5
5
  /**
@@ -21,23 +21,14 @@ function insertMarkdownContentAt(position, markdown, options) {
21
21
  ...options,
22
22
  };
23
23
  // Get the start and end positions from the provided position
24
- let { from, to } = typeof position === 'number'
24
+ const { from, to } = typeof position === 'number'
25
25
  ? { from: position, to: position }
26
26
  : { from: position.from, to: position.to };
27
- // If the selection is empty, and we're in an empty textblock, expand the start and end
28
- // positions to include the whole textblock (not leaving empty paragraphs behind)
29
- if (from === to) {
30
- const { parent } = tr.doc.resolve(from);
31
- if (parent.isTextblock && parent.childCount === 0) {
32
- from -= 1;
33
- to += 1;
34
- }
35
- }
36
27
  // Parse the Markdown to HTML and then then into ProseMirror nodes
37
28
  const htmlContent = getHTMLSerializerInstance(editor.schema).serialize(markdown);
38
- const content = DOMParser.fromSchema(editor.schema).parse(parseHtmlToElement(htmlContent), options.parseOptions);
29
+ const content = DOMParser.fromSchema(editor.schema).parseSlice(parseHtmlToElement(htmlContent), options.parseOptions);
39
30
  // Inserts the content into the editor while preserving the current selection
40
- tr.replaceWith(from, to, content);
31
+ tr.replaceRange(from, to, content);
41
32
  // Set the text cursor to the end of the inserted content
42
33
  if (options.updateSelection) {
43
34
  selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@doist/typist",
3
3
  "description": "The mighty Tiptap-based rich-text editor React component that powers Doist products.",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -106,7 +106,7 @@
106
106
  "classnames": "2.3.2",
107
107
  "conventional-changelog-conventionalcommits": "6.1.0",
108
108
  "emoji-regex": "10.2.1",
109
- "eslint": "8.48.0",
109
+ "eslint": "8.49.0",
110
110
  "eslint-formatter-codeframe": "7.32.1",
111
111
  "eslint-import-resolver-typescript": "3.6.0",
112
112
  "eslint-plugin-simple-import-sort": "10.0.0",
@@ -134,7 +134,7 @@
134
134
  "type-fest": "4.3.1",
135
135
  "typescript": "5.2.2",
136
136
  "typescript-plugin-css-modules": "5.0.1",
137
- "vitest": "0.34.3"
137
+ "vitest": "0.34.4"
138
138
  },
139
139
  "peerDependencies": {
140
140
  "@react-hookz/web": "^14.2.3 || >=15.x",