@doist/typist 2.2.1 → 2.3.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,15 @@
1
+ ## [2.3.1](https://github.com/Doist/typist/compare/v2.3.0...v2.3.1) (2024-01-17)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **commands:** Restore built-in `toggleBulletList` and `toggleOrderedList` ([#613](https://github.com/Doist/typist/issues/613)) ([4c4a0dc](https://github.com/Doist/typist/commit/4c4a0dc98e5c7351d6a0d2e8b16661c1e8f54fdd))
6
+
7
+ ## [2.3.0](https://github.com/Doist/typist/compare/v2.2.1...v2.3.0) (2024-01-17)
8
+
9
+ ### Features
10
+
11
+ - **commands:** Add `smartToggleBulletList` and `smartToggleOrderedList` ([#612](https://github.com/Doist/typist/issues/612)) ([e5dcc8b](https://github.com/Doist/typist/commit/e5dcc8b523d7596e168f919fd53d9119f7c40ac7))
12
+
1
13
  ## [2.2.1](https://github.com/Doist/typist/compare/v2.2.0...v2.2.1) (2024-01-11)
2
14
 
3
15
  ### Bug Fixes
@@ -0,0 +1,27 @@
1
+ import type { BulletListOptions } from '@tiptap/extension-bullet-list';
2
+ /**
3
+ * Augment the official `@tiptap/core` module with extra commands, relevant for this extension, so
4
+ * that the compiler knows about them.
5
+ */
6
+ declare module '@tiptap/core' {
7
+ interface Commands<ReturnType> {
8
+ richTextBulletList: {
9
+ /**
10
+ * Smartly toggles the selection into a bullet list, converting any hard breaks into
11
+ * paragraphs before doing so.
12
+ *
13
+ * @see https://discuss.prosemirror.net/t/how-to-convert-a-selection-of-text-lines-into-paragraphs/6099
14
+ */
15
+ smartToggleBulletList: () => ReturnType;
16
+ };
17
+ }
18
+ }
19
+ /**
20
+ * Custom extension that extends the built-in `BulletList` extension to add a smart toggle command
21
+ * with support for hard breaks, which are automatically converted into paragraphs before toggling
22
+ * the selection into a bullet list.
23
+ */
24
+ declare const RichTextBulletList: import("@tiptap/core").Node<BulletListOptions, any>;
25
+ export { RichTextBulletList };
26
+ export type { BulletListOptions as RichTextBulletListOptions };
27
+ //# sourceMappingURL=rich-text-bullet-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text-bullet-list.d.ts","sourceRoot":"","sources":["../../../src/extensions/rich-text/rich-text-bullet-list.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAEtE;;;GAGG;AACH,OAAO,QAAQ,cAAc,CAAC;IAC1B,UAAU,QAAQ,CAAC,UAAU;QACzB,kBAAkB,EAAE;YAChB;;;;;eAKG;YACH,qBAAqB,EAAE,MAAM,UAAU,CAAA;SAC1C,CAAA;KACJ;CACJ;AAED;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,qDAqDtB,CAAA;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,YAAY,EAAE,iBAAiB,IAAI,yBAAyB,EAAE,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { BulletList } from '@tiptap/extension-bullet-list';
2
+ import { ListItem } from '@tiptap/extension-list-item';
3
+ import { TextStyle } from '@tiptap/extension-text-style';
4
+ import { Fragment, Slice } from '@tiptap/pm/model';
5
+ /**
6
+ * Custom extension that extends the built-in `BulletList` extension to add a smart toggle command
7
+ * with support for hard breaks, which are automatically converted into paragraphs before toggling
8
+ * the selection into a bullet list.
9
+ */
10
+ const RichTextBulletList = BulletList.extend({
11
+ addCommands() {
12
+ const { editor, name, options } = this;
13
+ return {
14
+ ...this.parent?.(),
15
+ smartToggleBulletList() {
16
+ return ({ commands, state, tr, chain }) => {
17
+ const { schema } = state;
18
+ const { selection } = tr;
19
+ const { $from, $to } = selection;
20
+ const hardBreakPositions = [];
21
+ // Find and store the positions of all hard breaks in the selection
22
+ tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
23
+ if (node.type.name === 'hardBreak') {
24
+ hardBreakPositions.push(pos);
25
+ }
26
+ });
27
+ // Replace each hard break with a slice that closes and re-opens a paragraph,
28
+ // effectively inserting a "paragraph break" in place of a "hard break"
29
+ // (this is performed in reverse order to compensate for content shifting that
30
+ // occurs with each replacement, ensuring accurate insertion points)
31
+ hardBreakPositions.reverse().forEach((pos) => {
32
+ tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
33
+ schema.nodes.paragraph.create(),
34
+ schema.nodes.paragraph.create(),
35
+ ])));
36
+ });
37
+ // Toggle the selection into a bullet list, optionally keeping attributes
38
+ // (this is a verbatim copy of the built-in`toggleBulletList` command)
39
+ if (options.keepAttributes) {
40
+ return chain()
41
+ .toggleList(name, options.itemTypeName, options.keepMarks)
42
+ .updateAttributes(ListItem.name, editor.getAttributes(TextStyle.name))
43
+ .run();
44
+ }
45
+ return commands.toggleList(name, options.itemTypeName, options.keepMarks);
46
+ };
47
+ },
48
+ };
49
+ },
50
+ });
51
+ export { RichTextBulletList };
@@ -1,8 +1,6 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import { RichTextStrikethroughOptions } from './rich-text-strikethrough';
3
2
  import type { BlockquoteOptions } from '@tiptap/extension-blockquote';
4
3
  import type { BoldOptions } from '@tiptap/extension-bold';
5
- import type { BulletListOptions } from '@tiptap/extension-bullet-list';
6
4
  import type { CodeOptions } from '@tiptap/extension-code';
7
5
  import type { CodeBlockOptions } from '@tiptap/extension-code-block';
8
6
  import type { DropcursorOptions } from '@tiptap/extension-dropcursor';
@@ -13,11 +11,13 @@ import type { HorizontalRuleOptions } from '@tiptap/extension-horizontal-rule';
13
11
  import type { ItalicOptions } from '@tiptap/extension-italic';
14
12
  import type { ListItemOptions } from '@tiptap/extension-list-item';
15
13
  import type { ListKeymapOptions } from '@tiptap/extension-list-keymap';
16
- import type { OrderedListOptions } from '@tiptap/extension-ordered-list';
17
14
  import type { ParagraphOptions } from '@tiptap/extension-paragraph';
15
+ import type { RichTextBulletListOptions } from './rich-text-bullet-list';
18
16
  import type { RichTextDocumentOptions } from './rich-text-document';
19
17
  import type { RichTextImageOptions } from './rich-text-image';
20
18
  import type { RichTextLinkOptions } from './rich-text-link';
19
+ import type { RichTextOrderedListOptions } from './rich-text-ordered-list';
20
+ import type { RichTextStrikethroughOptions } from './rich-text-strikethrough';
21
21
  /**
22
22
  * The options available to customize the `RichTextKit` extension.
23
23
  */
@@ -33,7 +33,7 @@ type RichTextKitOptions = {
33
33
  /**
34
34
  * Set options for the `BulletList` extension, or `false` to disable.
35
35
  */
36
- bulletList: Partial<BulletListOptions> | false;
36
+ bulletList: Partial<RichTextBulletListOptions> | false;
37
37
  /**
38
38
  * Set options for the `Code` extension, or `false` to disable.
39
39
  */
@@ -93,7 +93,7 @@ type RichTextKitOptions = {
93
93
  /**
94
94
  * Set options for the `OrderedList` extension, or `false` to disable.
95
95
  */
96
- orderedList: Partial<OrderedListOptions> | false;
96
+ orderedList: Partial<RichTextOrderedListOptions> | false;
97
97
  /**
98
98
  * Set options for the `Paragraph` extension, or `false` to disable.
99
99
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rich-text-kit.d.ts","sourceRoot":"","sources":["../../../src/extensions/rich-text/rich-text-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAgCxC,OAAO,EAAyB,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAG/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BA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AAG,KAAK,CAAA;IAE1C;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,KAAK,CAAA;IAE1C;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,KAAK,CAAA;IAE9C;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAAG,KAAK,CAAA;IAExD;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAA;IAE5C;;OAEG;IACH,WAAW,EAAE,KAAK,CAAA;IAElB;;OAEG;IACH,aAAa,EAAE,KAAK,CAAA;IAEpB;;OAEG;IACH,mBAAmB,EAAE,KAAK,CAAA;IAE1B;;OAEG;IACH,sBAAsB,EAAE,KAAK,CAAA;IAE7B;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC,4BAA4B,CAAC,GAAG,KAAK,CAAA;IAErD;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IAEX;;OAEG;IACH,UAAU,EAAE,KAAK,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,WAAW,oCA2If,CAAA;AAEF,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,YAAY,EAAE,kBAAkB,EAAE,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import { Extension } from '@tiptap/core';
2
2
  import { Blockquote } from '@tiptap/extension-blockquote';
3
3
  import { Bold } from '@tiptap/extension-bold';
4
- import { BulletList } from '@tiptap/extension-bullet-list';
5
4
  import { CodeBlock } from '@tiptap/extension-code-block';
6
5
  import { Dropcursor } from '@tiptap/extension-dropcursor';
7
6
  import { Gapcursor } from '@tiptap/extension-gapcursor';
@@ -12,7 +11,6 @@ import { HorizontalRule } from '@tiptap/extension-horizontal-rule';
12
11
  import { Italic } from '@tiptap/extension-italic';
13
12
  import { ListItem } from '@tiptap/extension-list-item';
14
13
  import { ListKeymap } from '@tiptap/extension-list-keymap';
15
- import { OrderedList } from '@tiptap/extension-ordered-list';
16
14
  import { Paragraph } from '@tiptap/extension-paragraph';
17
15
  import { Text } from '@tiptap/extension-text';
18
16
  import { Typography } from '@tiptap/extension-typography';
@@ -24,10 +22,12 @@ import { BoldAndItalics } from './bold-and-italics';
24
22
  import { CurvenoteCodemark } from './curvenote-codemark';
25
23
  import { PasteEmojis } from './paste-emojis';
26
24
  import { PasteMarkdown } from './paste-markdown';
25
+ import { RichTextBulletList } from './rich-text-bullet-list';
27
26
  import { RichTextCode } from './rich-text-code';
28
27
  import { RichTextDocument } from './rich-text-document';
29
28
  import { RichTextImage } from './rich-text-image';
30
29
  import { RichTextLink } from './rich-text-link';
30
+ import { RichTextOrderedList } from './rich-text-ordered-list';
31
31
  import { RichTextStrikethrough } from './rich-text-strikethrough';
32
32
  /**
33
33
  * The `RichTextKit` extension is a collection of the minimal required extensions to have a full
@@ -47,7 +47,7 @@ const RichTextKit = Extension.create({
47
47
  extensions.push(Bold.configure(this.options?.bold));
48
48
  }
49
49
  if (this.options.bulletList !== false) {
50
- extensions.push(BulletList.configure(this.options?.bulletList));
50
+ extensions.push(RichTextBulletList.configure(this.options?.bulletList));
51
51
  }
52
52
  if (this.options.code !== false) {
53
53
  extensions.push(RichTextCode.configure(this.options?.code),
@@ -119,7 +119,7 @@ const RichTextKit = Extension.create({
119
119
  extensions.push(ListKeymap.configure(this.options?.listKeymap));
120
120
  }
121
121
  if (this.options.orderedList !== false) {
122
- extensions.push(OrderedList.configure(this.options?.orderedList));
122
+ extensions.push(RichTextOrderedList.configure(this.options?.orderedList));
123
123
  }
124
124
  if (this.options.paragraph !== false) {
125
125
  extensions.push(Paragraph.configure(this.options?.paragraph));
@@ -0,0 +1,27 @@
1
+ import type { OrderedListOptions } from '@tiptap/extension-ordered-list';
2
+ /**
3
+ * Augment the official `@tiptap/core` module with extra commands, relevant for this extension, so
4
+ * that the compiler knows about them.
5
+ */
6
+ declare module '@tiptap/core' {
7
+ interface Commands<ReturnType> {
8
+ richTextOrderedList: {
9
+ /**
10
+ * Smartly toggles the selection into an oredered list, converting any hard breaks into
11
+ * paragraphs before doing so.
12
+ *
13
+ * @see https://discuss.prosemirror.net/t/how-to-convert-a-selection-of-text-lines-into-paragraphs/6099
14
+ */
15
+ smartToggleOrderedList: () => ReturnType;
16
+ };
17
+ }
18
+ }
19
+ /**
20
+ * Custom extension that extends the built-in `OrderedList` extension to add a smart toggle command
21
+ * with support for hard breaks, which are automatically converted into paragraphs before toggling
22
+ * the selection into an ordered list.
23
+ */
24
+ declare const RichTextOrderedList: import("@tiptap/core").Node<OrderedListOptions, any>;
25
+ export { RichTextOrderedList };
26
+ export type { OrderedListOptions as RichTextOrderedListOptions };
27
+ //# sourceMappingURL=rich-text-ordered-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text-ordered-list.d.ts","sourceRoot":"","sources":["../../../src/extensions/rich-text/rich-text-ordered-list.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAExE;;;GAGG;AACH,OAAO,QAAQ,cAAc,CAAC;IAC1B,UAAU,QAAQ,CAAC,UAAU;QACzB,mBAAmB,EAAE;YACjB;;;;;eAKG;YACH,sBAAsB,EAAE,MAAM,UAAU,CAAA;SAC3C,CAAA;KACJ;CACJ;AAED;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,sDAqDvB,CAAA;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAE9B,YAAY,EAAE,kBAAkB,IAAI,0BAA0B,EAAE,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { ListItem } from '@tiptap/extension-list-item';
2
+ import { OrderedList } from '@tiptap/extension-ordered-list';
3
+ import { TextStyle } from '@tiptap/extension-text-style';
4
+ import { Fragment, Slice } from '@tiptap/pm/model';
5
+ /**
6
+ * Custom extension that extends the built-in `OrderedList` extension to add a smart toggle command
7
+ * with support for hard breaks, which are automatically converted into paragraphs before toggling
8
+ * the selection into an ordered list.
9
+ */
10
+ const RichTextOrderedList = OrderedList.extend({
11
+ addCommands() {
12
+ const { editor, name, options } = this;
13
+ return {
14
+ ...this.parent?.(),
15
+ smartToggleOrderedList() {
16
+ return ({ commands, state, tr, chain }) => {
17
+ const { schema } = state;
18
+ const { selection } = tr;
19
+ const { $from, $to } = selection;
20
+ const hardBreakPositions = [];
21
+ // Find and store the positions of all hard breaks in the selection
22
+ tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
23
+ if (node.type.name === 'hardBreak') {
24
+ hardBreakPositions.push(pos);
25
+ }
26
+ });
27
+ // Replace each hard break with a slice that closes and re-opens a paragraph,
28
+ // effectively inserting a "paragraph break" in place of a "hard break"
29
+ // (this is performed in reverse order to compensate for content shifting that
30
+ // occurs with each replacement, ensuring accurate insertion points)
31
+ hardBreakPositions.reverse().forEach((pos) => {
32
+ tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
33
+ schema.nodes.paragraph.create(),
34
+ schema.nodes.paragraph.create(),
35
+ ])));
36
+ });
37
+ // Toggle the selection into a bullet list, optionally keeping attributes
38
+ // (this is a verbatim copy of the built-in`toggleBulletList` command)
39
+ if (options.keepAttributes) {
40
+ return chain()
41
+ .toggleList(name, options.itemTypeName, options.keepMarks)
42
+ .updateAttributes(ListItem.name, editor.getAttributes(TextStyle.name))
43
+ .run();
44
+ }
45
+ return commands.toggleList(name, options.itemTypeName, options.keepMarks);
46
+ };
47
+ },
48
+ };
49
+ },
50
+ });
51
+ export { RichTextOrderedList };
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.2.1",
4
+ "version": "2.3.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -72,6 +72,7 @@
72
72
  "@tiptap/extension-task-item": "2.1.13",
73
73
  "@tiptap/extension-task-list": "2.1.13",
74
74
  "@tiptap/extension-text": "2.1.13",
75
+ "@tiptap/extension-text-style": "2.1.13",
75
76
  "@tiptap/extension-typography": "2.1.13",
76
77
  "@tiptap/pm": "2.1.13",
77
78
  "@tiptap/react": "2.1.13",
@@ -83,18 +84,18 @@
83
84
  "@doist/prettier-config": "4.0.0",
84
85
  "@doist/reactist": "22.3.3",
85
86
  "@mdx-js/react": "3.0.0",
86
- "@rollup/rollup-linux-x64-gnu": "4.9.4",
87
+ "@rollup/rollup-linux-x64-gnu": "4.9.5",
87
88
  "@semantic-release/changelog": "6.0.3",
88
89
  "@semantic-release/exec": "6.0.3",
89
90
  "@semantic-release/git": "10.0.1",
90
- "@storybook/addon-a11y": "7.6.7",
91
- "@storybook/addon-essentials": "7.6.7",
92
- "@storybook/addons": "7.6.7",
91
+ "@storybook/addon-a11y": "7.6.8",
92
+ "@storybook/addon-essentials": "7.6.8",
93
+ "@storybook/addons": "7.6.8",
93
94
  "@storybook/csf": "0.1.2",
94
95
  "@storybook/mdx2-csf": "1.1.0",
95
- "@storybook/react": "7.6.7",
96
- "@storybook/react-vite": "7.6.7",
97
- "@testing-library/dom": "9.3.3",
96
+ "@storybook/react": "7.6.8",
97
+ "@storybook/react-vite": "7.6.8",
98
+ "@testing-library/dom": "9.3.4",
98
99
  "@testing-library/jest-dom": "6.2.0",
99
100
  "@testing-library/react": "14.1.2",
100
101
  "@types/lodash-es": "4.17.12",
@@ -119,24 +120,24 @@
119
120
  "husky": "8.0.3",
120
121
  "ignore-sync": "7.0.1",
121
122
  "is-ci": "3.0.1",
122
- "jsdom": "23.1.0",
123
+ "jsdom": "23.2.0",
123
124
  "lint-staged": "15.2.0",
124
125
  "npm-run-all": "4.1.5",
125
- "prettier": "3.1.1",
126
+ "prettier": "3.2.1",
126
127
  "react": "18.2.0",
127
128
  "react-dom": "18.2.0",
128
- "react-icons": "4.12.0",
129
+ "react-icons": "5.0.1",
129
130
  "react-markdown": "8.0.7",
130
131
  "react-syntax-highlighter": "15.5.0",
131
132
  "rimraf": "5.0.5",
132
133
  "semantic-release": "22.0.12",
133
134
  "tippy.js": "6.3.7",
134
- "storybook": "7.6.7",
135
+ "storybook": "7.6.8",
135
136
  "storybook-css-modules": "1.0.8",
136
137
  "type-fest": "4.9.0",
137
138
  "typescript": "5.3.3",
138
139
  "typescript-plugin-css-modules": "5.0.2",
139
- "vitest": "1.1.3"
140
+ "vitest": "1.2.0"
140
141
  },
141
142
  "peerDependencies": {
142
143
  "@react-hookz/web": "^14.2.3 || >=15.x",