@doist/typist 2.3.1 → 3.0.0
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 +19 -0
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts +13 -20
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-bullet-list.js +34 -25
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts +13 -20
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-ordered-list.js +34 -25
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [3.0.0](https://github.com/Doist/typist/compare/v2.3.1...v3.0.0) (2024-01-18)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
- **extensions:** The `smartToggleBulletList` and
|
|
6
|
+
`smartToggleOrderedList` commands were renamed to have the same name as
|
|
7
|
+
the built-in toggle functions so that they can easily be used by the
|
|
8
|
+
default keyboard shortcuts without having to change the
|
|
9
|
+
`addKeyboardShortcuts` function.
|
|
10
|
+
|
|
11
|
+
The `BulletList` and `OrderedList` extensions now take an additional
|
|
12
|
+
option, `smartToggle` (default: `false`), that indicates whether hard
|
|
13
|
+
breaks should be replaced by paragraphs before toggling the
|
|
14
|
+
selection into a bullet/ordered list, or not.
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- **extensions:** Overwrite built-in List/Ordered toggle functions with a `smartToggle` option ([#620](https://github.com/Doist/typist/issues/620)) ([059da61](https://github.com/Doist/typist/commit/059da61605370f8a3534d3c7669acbc952ea40d3))
|
|
19
|
+
|
|
1
20
|
## [2.3.1](https://github.com/Doist/typist/compare/v2.3.0...v2.3.1) (2024-01-17)
|
|
2
21
|
|
|
3
22
|
### Bug Fixes
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import type { BulletListOptions } from '@tiptap/extension-bullet-list';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* that the compiler knows about them.
|
|
3
|
+
* The options available to customize the `RichTextBulletList` extension.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
5
|
+
type RichTextBulletListOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Replace hard breaks in the selection with paragraphs before toggling the selection into a
|
|
8
|
+
* bullet list. By default, hard breaks are not replaced.
|
|
9
|
+
*/
|
|
10
|
+
smartToggle: boolean;
|
|
11
|
+
} & BulletListOptions;
|
|
19
12
|
/**
|
|
20
|
-
* Custom extension that extends the built-in `BulletList` extension to add
|
|
21
|
-
*
|
|
22
|
-
* the selection into a bullet list.
|
|
13
|
+
* Custom extension that extends the built-in `BulletList` extension to add an option for smart
|
|
14
|
+
* toggling, which takes into account hard breaks in the selection, and converts them into
|
|
15
|
+
* paragraphs before toggling the selection into a bullet list.
|
|
23
16
|
*/
|
|
24
|
-
declare const RichTextBulletList: import("@tiptap/core").Node<
|
|
17
|
+
declare const RichTextBulletList: import("@tiptap/core").Node<RichTextBulletListOptions, any>;
|
|
25
18
|
export { RichTextBulletList };
|
|
26
|
-
export type {
|
|
19
|
+
export type { RichTextBulletListOptions };
|
|
27
20
|
//# sourceMappingURL=rich-text-bullet-list.d.ts.map
|
|
@@ -1 +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
|
|
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;;GAEG;AACH,KAAK,yBAAyB,GAAG;IAC7B;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAA;CACvB,GAAG,iBAAiB,CAAA;AAErB;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,6DA+DtB,CAAA;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,YAAY,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -3,39 +3,48 @@ import { ListItem } from '@tiptap/extension-list-item';
|
|
|
3
3
|
import { TextStyle } from '@tiptap/extension-text-style';
|
|
4
4
|
import { Fragment, Slice } from '@tiptap/pm/model';
|
|
5
5
|
/**
|
|
6
|
-
* Custom extension that extends the built-in `BulletList` extension to add
|
|
7
|
-
*
|
|
8
|
-
* the selection into a bullet list.
|
|
6
|
+
* Custom extension that extends the built-in `BulletList` extension to add an option for smart
|
|
7
|
+
* toggling, which takes into account hard breaks in the selection, and converts them into
|
|
8
|
+
* paragraphs before toggling the selection into a bullet list.
|
|
9
9
|
*/
|
|
10
10
|
const RichTextBulletList = BulletList.extend({
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
...this.parent?.(),
|
|
14
|
+
smartToggle: false,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
11
17
|
addCommands() {
|
|
12
18
|
const { editor, name, options } = this;
|
|
13
19
|
return {
|
|
14
20
|
...this.parent?.(),
|
|
15
|
-
|
|
21
|
+
toggleBulletList() {
|
|
16
22
|
return ({ commands, state, tr, chain }) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
// Replace hard breaks in the selection with paragraphs before toggling?
|
|
24
|
+
if (options.smartToggle) {
|
|
25
|
+
const { schema } = state;
|
|
26
|
+
const { selection } = tr;
|
|
27
|
+
const { $from, $to } = selection;
|
|
28
|
+
const hardBreakPositions = [];
|
|
29
|
+
// Find and store the positions of all hard breaks in the selection
|
|
30
|
+
tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
31
|
+
if (node.type.name === 'hardBreak') {
|
|
32
|
+
hardBreakPositions.push(pos);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// Replace each hard break with a slice that closes and re-opens a paragraph,
|
|
36
|
+
// effectively inserting a "paragraph break" in place of a "hard break"
|
|
37
|
+
// (this is performed in reverse order to compensate for content shifting that
|
|
38
|
+
// occurs with each replacement, ensuring accurate insertion points)
|
|
39
|
+
hardBreakPositions.reverse().forEach((pos) => {
|
|
40
|
+
tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
|
|
41
|
+
schema.nodes.paragraph.create(),
|
|
42
|
+
schema.nodes.paragraph.create(),
|
|
43
|
+
])));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
37
46
|
// Toggle the selection into a bullet list, optionally keeping attributes
|
|
38
|
-
// (this is a verbatim copy of the built-in`toggleBulletList` command)
|
|
47
|
+
// (this is a verbatim copy of the built-in `toggleBulletList` command)
|
|
39
48
|
if (options.keepAttributes) {
|
|
40
49
|
return chain()
|
|
41
50
|
.toggleList(name, options.itemTypeName, options.keepMarks)
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import type { OrderedListOptions } from '@tiptap/extension-ordered-list';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* that the compiler knows about them.
|
|
3
|
+
* The options available to customize the `RichTextOrderedList` extension.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
5
|
+
type RichTextOrderedListOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Replace hard breaks in the selection with paragraphs before toggling the selection into a
|
|
8
|
+
* bullet list. By default, hard breaks are not replaced.
|
|
9
|
+
*/
|
|
10
|
+
smartToggle: boolean;
|
|
11
|
+
} & OrderedListOptions;
|
|
19
12
|
/**
|
|
20
|
-
* Custom extension that extends the built-in `OrderedList` extension to add
|
|
21
|
-
*
|
|
22
|
-
* the selection into
|
|
13
|
+
* Custom extension that extends the built-in `OrderedList` extension to add an option for smart
|
|
14
|
+
* toggling, which takes into account hard breaks in the selection, and converts them into
|
|
15
|
+
* paragraphs before toggling the selection into a bullet list.
|
|
23
16
|
*/
|
|
24
|
-
declare const RichTextOrderedList: import("@tiptap/core").Node<
|
|
17
|
+
declare const RichTextOrderedList: import("@tiptap/core").Node<RichTextOrderedListOptions, any>;
|
|
25
18
|
export { RichTextOrderedList };
|
|
26
|
-
export type {
|
|
19
|
+
export type { RichTextOrderedListOptions };
|
|
27
20
|
//# sourceMappingURL=rich-text-ordered-list.d.ts.map
|
|
@@ -1 +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
|
|
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;;GAEG;AACH,KAAK,0BAA0B,GAAG;IAC9B;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAA;CACvB,GAAG,kBAAkB,CAAA;AAEtB;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,8DA+DvB,CAAA;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAE9B,YAAY,EAAE,0BAA0B,EAAE,CAAA"}
|
|
@@ -3,39 +3,48 @@ import { OrderedList } from '@tiptap/extension-ordered-list';
|
|
|
3
3
|
import { TextStyle } from '@tiptap/extension-text-style';
|
|
4
4
|
import { Fragment, Slice } from '@tiptap/pm/model';
|
|
5
5
|
/**
|
|
6
|
-
* Custom extension that extends the built-in `OrderedList` extension to add
|
|
7
|
-
*
|
|
8
|
-
* the selection into
|
|
6
|
+
* Custom extension that extends the built-in `OrderedList` extension to add an option for smart
|
|
7
|
+
* toggling, which takes into account hard breaks in the selection, and converts them into
|
|
8
|
+
* paragraphs before toggling the selection into a bullet list.
|
|
9
9
|
*/
|
|
10
10
|
const RichTextOrderedList = OrderedList.extend({
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
...this.parent?.(),
|
|
14
|
+
smartToggle: false,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
11
17
|
addCommands() {
|
|
12
18
|
const { editor, name, options } = this;
|
|
13
19
|
return {
|
|
14
20
|
...this.parent?.(),
|
|
15
|
-
|
|
21
|
+
toggleOrderedList() {
|
|
16
22
|
return ({ commands, state, tr, chain }) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
// Replace hard breaks in the selection with paragraphs before toggling?
|
|
24
|
+
if (options.smartToggle) {
|
|
25
|
+
const { schema } = state;
|
|
26
|
+
const { selection } = tr;
|
|
27
|
+
const { $from, $to } = selection;
|
|
28
|
+
const hardBreakPositions = [];
|
|
29
|
+
// Find and store the positions of all hard breaks in the selection
|
|
30
|
+
tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
31
|
+
if (node.type.name === 'hardBreak') {
|
|
32
|
+
hardBreakPositions.push(pos);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// Replace each hard break with a slice that closes and re-opens a paragraph,
|
|
36
|
+
// effectively inserting a "paragraph break" in place of a "hard break"
|
|
37
|
+
// (this is performed in reverse order to compensate for content shifting that
|
|
38
|
+
// occurs with each replacement, ensuring accurate insertion points)
|
|
39
|
+
hardBreakPositions.reverse().forEach((pos) => {
|
|
40
|
+
tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
|
|
41
|
+
schema.nodes.paragraph.create(),
|
|
42
|
+
schema.nodes.paragraph.create(),
|
|
43
|
+
])));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
37
46
|
// Toggle the selection into a bullet list, optionally keeping attributes
|
|
38
|
-
// (this is a verbatim copy of the built-in`toggleBulletList` command)
|
|
47
|
+
// (this is a verbatim copy of the built-in `toggleBulletList` command)
|
|
39
48
|
if (options.keepAttributes) {
|
|
40
49
|
return chain()
|
|
41
50
|
.toggleList(name, options.itemTypeName, options.keepMarks)
|
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": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://typist.doist.dev/",
|
|
7
7
|
"repository": "https://github.com/Doist/typist",
|
|
@@ -88,18 +88,18 @@
|
|
|
88
88
|
"@semantic-release/changelog": "6.0.3",
|
|
89
89
|
"@semantic-release/exec": "6.0.3",
|
|
90
90
|
"@semantic-release/git": "10.0.1",
|
|
91
|
-
"@storybook/addon-a11y": "7.6.
|
|
92
|
-
"@storybook/addon-essentials": "7.6.
|
|
93
|
-
"@storybook/addons": "7.6.
|
|
91
|
+
"@storybook/addon-a11y": "7.6.9",
|
|
92
|
+
"@storybook/addon-essentials": "7.6.9",
|
|
93
|
+
"@storybook/addons": "7.6.9",
|
|
94
94
|
"@storybook/csf": "0.1.2",
|
|
95
95
|
"@storybook/mdx2-csf": "1.1.0",
|
|
96
|
-
"@storybook/react": "7.6.
|
|
97
|
-
"@storybook/react-vite": "7.6.
|
|
96
|
+
"@storybook/react": "7.6.9",
|
|
97
|
+
"@storybook/react-vite": "7.6.9",
|
|
98
98
|
"@testing-library/dom": "9.3.4",
|
|
99
99
|
"@testing-library/jest-dom": "6.2.0",
|
|
100
100
|
"@testing-library/react": "14.1.2",
|
|
101
101
|
"@types/lodash-es": "4.17.12",
|
|
102
|
-
"@types/react": "18.2.
|
|
102
|
+
"@types/react": "18.2.48",
|
|
103
103
|
"@types/react-dom": "18.2.18",
|
|
104
104
|
"@types/react-syntax-highlighter": "15.5.11",
|
|
105
105
|
"@types/turndown": "5.0.4",
|
|
@@ -123,21 +123,21 @@
|
|
|
123
123
|
"jsdom": "23.2.0",
|
|
124
124
|
"lint-staged": "15.2.0",
|
|
125
125
|
"npm-run-all": "4.1.5",
|
|
126
|
-
"prettier": "3.2.
|
|
126
|
+
"prettier": "3.2.4",
|
|
127
127
|
"react": "18.2.0",
|
|
128
128
|
"react-dom": "18.2.0",
|
|
129
129
|
"react-icons": "5.0.1",
|
|
130
130
|
"react-markdown": "8.0.7",
|
|
131
131
|
"react-syntax-highlighter": "15.5.0",
|
|
132
132
|
"rimraf": "5.0.5",
|
|
133
|
-
"semantic-release": "
|
|
133
|
+
"semantic-release": "23.0.0",
|
|
134
134
|
"tippy.js": "6.3.7",
|
|
135
|
-
"storybook": "7.6.
|
|
135
|
+
"storybook": "7.6.9",
|
|
136
136
|
"storybook-css-modules": "1.0.8",
|
|
137
137
|
"type-fest": "4.9.0",
|
|
138
138
|
"typescript": "5.3.3",
|
|
139
139
|
"typescript-plugin-css-modules": "5.0.2",
|
|
140
|
-
"vitest": "1.2.
|
|
140
|
+
"vitest": "1.2.1"
|
|
141
141
|
},
|
|
142
142
|
"peerDependencies": {
|
|
143
143
|
"@react-hookz/web": "^14.2.3 || >=15.x",
|