@doist/typist 2.2.0 → 2.3.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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## [2.3.0](https://github.com/Doist/typist/compare/v2.2.1...v2.3.0) (2024-01-17)
2
+
3
+ ### Features
4
+
5
+ - **commands:** Add `smartToggleBulletList` and `smartToggleOrderedList` ([#612](https://github.com/Doist/typist/issues/612)) ([e5dcc8b](https://github.com/Doist/typist/commit/e5dcc8b523d7596e168f919fd53d9119f7c40ac7))
6
+
7
+ ## [2.2.1](https://github.com/Doist/typist/compare/v2.2.0...v2.2.1) (2024-01-11)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **deps:** update tiptap packages to v2.1.13 ([#554](https://github.com/Doist/typist/issues/554)) ([e89007b](https://github.com/Doist/typist/commit/e89007b7da928c3be46f2beaef9207586c3279a4))
12
+
1
13
  ## [2.2.0](https://github.com/Doist/typist/compare/v2.1.3...v2.2.0) (2023-11-21)
2
14
 
3
15
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022-2023 Doist Inc.
3
+ Copyright (c) 2022-2024 Doist Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -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,qDAoDtB,CAAA;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,YAAY,EAAE,iBAAiB,IAAI,yBAAyB,EAAE,CAAA"}
@@ -0,0 +1,50 @@
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
+ smartToggleBulletList() {
15
+ return ({ commands, state, tr, chain }) => {
16
+ const { schema } = state;
17
+ const { selection } = tr;
18
+ const { $from, $to } = selection;
19
+ const hardBreakPositions = [];
20
+ // Find and store the positions of all hard breaks in the selection
21
+ tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
22
+ if (node.type.name === 'hardBreak') {
23
+ hardBreakPositions.push(pos);
24
+ }
25
+ });
26
+ // Replace each hard break with a slice that closes and re-opens a paragraph,
27
+ // effectively inserting a "paragraph break" in place of a "hard break"
28
+ // (this is performed in reverse order to compensate for content shifting that
29
+ // occurs with each replacement, ensuring accurate insertion points)
30
+ hardBreakPositions.reverse().forEach((pos) => {
31
+ tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
32
+ schema.nodes.paragraph.create(),
33
+ schema.nodes.paragraph.create(),
34
+ ])));
35
+ });
36
+ // Toggle the selection into a bullet list, optionally keeping attributes
37
+ // (this is a verbatim copy of the built-in`toggleBulletList` command)
38
+ if (options.keepAttributes) {
39
+ return chain()
40
+ .toggleList(name, options.itemTypeName, options.keepMarks)
41
+ .updateAttributes(ListItem.name, editor.getAttributes(TextStyle.name))
42
+ .run();
43
+ }
44
+ return commands.toggleList(name, options.itemTypeName, options.keepMarks);
45
+ };
46
+ },
47
+ };
48
+ },
49
+ });
50
+ 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,E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G,KAAK,CAAA;IAE5C;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,KAAK,CAAA;IAEtC;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,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,sDAoDvB,CAAA;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAE9B,YAAY,EAAE,kBAAkB,IAAI,0BAA0B,EAAE,CAAA"}
@@ -0,0 +1,50 @@
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
+ smartToggleOrderedList() {
15
+ return ({ commands, state, tr, chain }) => {
16
+ const { schema } = state;
17
+ const { selection } = tr;
18
+ const { $from, $to } = selection;
19
+ const hardBreakPositions = [];
20
+ // Find and store the positions of all hard breaks in the selection
21
+ tr.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
22
+ if (node.type.name === 'hardBreak') {
23
+ hardBreakPositions.push(pos);
24
+ }
25
+ });
26
+ // Replace each hard break with a slice that closes and re-opens a paragraph,
27
+ // effectively inserting a "paragraph break" in place of a "hard break"
28
+ // (this is performed in reverse order to compensate for content shifting that
29
+ // occurs with each replacement, ensuring accurate insertion points)
30
+ hardBreakPositions.reverse().forEach((pos) => {
31
+ tr.replace(pos, pos + 1, Slice.maxOpen(Fragment.fromArray([
32
+ schema.nodes.paragraph.create(),
33
+ schema.nodes.paragraph.create(),
34
+ ])));
35
+ });
36
+ // Toggle the selection into a bullet list, optionally keeping attributes
37
+ // (this is a verbatim copy of the built-in`toggleBulletList` command)
38
+ if (options.keepAttributes) {
39
+ return chain()
40
+ .toggleList(name, options.itemTypeName, options.keepMarks)
41
+ .updateAttributes(ListItem.name, editor.getAttributes(TextStyle.name))
42
+ .run();
43
+ }
44
+ return commands.toggleList(name, options.itemTypeName, options.keepMarks);
45
+ };
46
+ },
47
+ };
48
+ },
49
+ });
50
+ 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.0",
4
+ "version": "2.3.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -46,100 +46,104 @@
46
46
  "validate:pre-push": "run-s test"
47
47
  },
48
48
  "dependencies": {
49
- "@tiptap/core": "2.1.12",
50
- "@tiptap/extension-blockquote": "2.1.12",
51
- "@tiptap/extension-bold": "2.1.12",
52
- "@tiptap/extension-bullet-list": "2.1.12",
53
- "@tiptap/extension-character-count": "2.1.12",
54
- "@tiptap/extension-code": "2.1.12",
55
- "@tiptap/extension-code-block": "2.1.12",
56
- "@tiptap/extension-document": "2.1.12",
57
- "@tiptap/extension-dropcursor": "2.1.12",
58
- "@tiptap/extension-gapcursor": "2.1.12",
59
- "@tiptap/extension-hard-break": "2.1.12",
60
- "@tiptap/extension-heading": "2.1.12",
61
- "@tiptap/extension-history": "2.1.12",
62
- "@tiptap/extension-horizontal-rule": "2.1.12",
63
- "@tiptap/extension-image": "2.1.12",
64
- "@tiptap/extension-italic": "2.1.12",
65
- "@tiptap/extension-link": "2.1.12",
66
- "@tiptap/extension-list-item": "2.1.12",
67
- "@tiptap/extension-list-keymap": "2.1.12",
68
- "@tiptap/extension-ordered-list": "2.1.12",
69
- "@tiptap/extension-paragraph": "2.1.12",
70
- "@tiptap/extension-placeholder": "2.1.12",
71
- "@tiptap/extension-strike": "2.1.12",
72
- "@tiptap/extension-task-item": "2.1.12",
73
- "@tiptap/extension-task-list": "2.1.12",
74
- "@tiptap/extension-text": "2.1.12",
75
- "@tiptap/extension-typography": "2.1.12",
76
- "@tiptap/pm": "2.1.12",
77
- "@tiptap/react": "2.1.12",
78
- "@tiptap/suggestion": "2.1.12",
49
+ "@tiptap/core": "2.1.13",
50
+ "@tiptap/extension-blockquote": "2.1.13",
51
+ "@tiptap/extension-bold": "2.1.13",
52
+ "@tiptap/extension-bullet-list": "2.1.13",
53
+ "@tiptap/extension-character-count": "2.1.13",
54
+ "@tiptap/extension-code": "2.1.13",
55
+ "@tiptap/extension-code-block": "2.1.13",
56
+ "@tiptap/extension-document": "2.1.13",
57
+ "@tiptap/extension-dropcursor": "2.1.13",
58
+ "@tiptap/extension-gapcursor": "2.1.13",
59
+ "@tiptap/extension-hard-break": "2.1.13",
60
+ "@tiptap/extension-heading": "2.1.13",
61
+ "@tiptap/extension-history": "2.1.13",
62
+ "@tiptap/extension-horizontal-rule": "2.1.13",
63
+ "@tiptap/extension-image": "2.1.13",
64
+ "@tiptap/extension-italic": "2.1.13",
65
+ "@tiptap/extension-link": "2.1.13",
66
+ "@tiptap/extension-list-item": "2.1.13",
67
+ "@tiptap/extension-list-keymap": "2.1.13",
68
+ "@tiptap/extension-ordered-list": "2.1.13",
69
+ "@tiptap/extension-paragraph": "2.1.13",
70
+ "@tiptap/extension-placeholder": "2.1.13",
71
+ "@tiptap/extension-strike": "2.1.13",
72
+ "@tiptap/extension-task-item": "2.1.13",
73
+ "@tiptap/extension-task-list": "2.1.13",
74
+ "@tiptap/extension-text": "2.1.13",
75
+ "@tiptap/extension-text-style": "2.1.13",
76
+ "@tiptap/extension-typography": "2.1.13",
77
+ "@tiptap/pm": "2.1.13",
78
+ "@tiptap/react": "2.1.13",
79
+ "@tiptap/suggestion": "2.1.13",
79
80
  "prosemirror-codemark": "0.4.2"
80
81
  },
81
82
  "devDependencies": {
82
83
  "@doist/eslint-config": "11.0.0",
83
84
  "@doist/prettier-config": "4.0.0",
84
- "@doist/reactist": "22.3.0",
85
- "@mdx-js/react": "2.3.0",
85
+ "@doist/reactist": "22.3.3",
86
+ "@mdx-js/react": "3.0.0",
87
+ "@rollup/rollup-linux-x64-gnu": "4.9.5",
86
88
  "@semantic-release/changelog": "6.0.3",
87
89
  "@semantic-release/exec": "6.0.3",
88
90
  "@semantic-release/git": "10.0.1",
89
- "@storybook/addon-a11y": "7.5.3",
90
- "@storybook/addon-essentials": "7.5.3",
91
- "@storybook/addons": "7.5.3",
92
- "@storybook/csf": "0.1.1",
91
+ "@storybook/addon-a11y": "7.6.8",
92
+ "@storybook/addon-essentials": "7.6.8",
93
+ "@storybook/addons": "7.6.8",
94
+ "@storybook/csf": "0.1.2",
93
95
  "@storybook/mdx2-csf": "1.1.0",
94
- "@storybook/react": "7.5.3",
95
- "@storybook/react-vite": "7.5.3",
96
- "@testing-library/dom": "9.3.3",
97
- "@testing-library/jest-dom": "6.1.4",
98
- "@testing-library/react": "14.1.0",
99
- "@types/lodash-es": "4.17.11",
100
- "@types/react": "18.2.37",
101
- "@types/react-dom": "18.2.15",
102
- "@types/react-syntax-highlighter": "15.5.10",
96
+ "@storybook/react": "7.6.8",
97
+ "@storybook/react-vite": "7.6.8",
98
+ "@testing-library/dom": "9.3.4",
99
+ "@testing-library/jest-dom": "6.2.0",
100
+ "@testing-library/react": "14.1.2",
101
+ "@types/lodash-es": "4.17.12",
102
+ "@types/react": "18.2.47",
103
+ "@types/react-dom": "18.2.18",
104
+ "@types/react-syntax-highlighter": "15.5.11",
103
105
  "@types/turndown": "5.0.4",
104
- "@vitejs/plugin-react": "4.1.1",
106
+ "@vitejs/plugin-react": "4.2.1",
105
107
  "boring-avatars": "1.10.1",
106
- "classnames": "2.3.2",
108
+ "classnames": "2.5.1",
107
109
  "conventional-changelog-conventionalcommits": "7.0.2",
108
110
  "emoji-regex": "10.3.0",
109
- "eslint": "8.53.0",
111
+ "eslint": "8.56.0",
110
112
  "eslint-formatter-codeframe": "7.32.1",
111
113
  "eslint-import-resolver-typescript": "3.6.1",
112
114
  "eslint-plugin-simple-import-sort": "10.0.0",
113
115
  "eslint-plugin-storybook": "0.6.15",
114
- "eslint-plugin-unicorn": "48.0.1",
115
- "eslint-plugin-vitest": "0.3.9",
116
+ "eslint-plugin-unicorn": "50.0.1",
117
+ "eslint-plugin-vitest": "0.3.20",
116
118
  "eslint-plugin-vitest-globals": "1.4.0",
117
- "github-markdown-css": "5.4.0",
119
+ "github-markdown-css": "5.5.0",
118
120
  "husky": "8.0.3",
119
121
  "ignore-sync": "7.0.1",
120
122
  "is-ci": "3.0.1",
121
- "jsdom": "22.1.0",
122
- "lint-staged": "15.1.0",
123
+ "jsdom": "23.2.0",
124
+ "lint-staged": "15.2.0",
123
125
  "npm-run-all": "4.1.5",
124
- "prettier": "3.1.0",
126
+ "prettier": "3.2.1",
125
127
  "react": "18.2.0",
126
128
  "react-dom": "18.2.0",
127
- "react-icons": "4.12.0",
129
+ "react-icons": "5.0.1",
128
130
  "react-markdown": "8.0.7",
129
131
  "react-syntax-highlighter": "15.5.0",
130
132
  "rimraf": "5.0.5",
131
- "semantic-release": "22.0.7",
132
- "storybook": "7.5.3",
133
+ "semantic-release": "22.0.12",
134
+ "tippy.js": "6.3.7",
135
+ "storybook": "7.6.8",
133
136
  "storybook-css-modules": "1.0.8",
134
- "type-fest": "4.7.1",
135
- "typescript": "5.2.2",
137
+ "type-fest": "4.9.0",
138
+ "typescript": "5.3.3",
136
139
  "typescript-plugin-css-modules": "5.0.2",
137
- "vitest": "0.34.6"
140
+ "vitest": "1.2.0"
138
141
  },
139
142
  "peerDependencies": {
140
143
  "@react-hookz/web": "^14.2.3 || >=15.x",
141
144
  "emoji-regex": "^10.2.1",
142
145
  "hast-util-is-element": "^2.1.0",
146
+ "linkifyjs": "^4.1.1",
143
147
  "lodash-es": "^4.17.21",
144
148
  "mdast-util-gfm-autolink-literal": "^1.0.0",
145
149
  "mdast-util-gfm-strikethrough": "^1.0.0",
@@ -151,7 +155,6 @@
151
155
  "rehype-minify-whitespace": "^5.0.0",
152
156
  "rehype-raw": "^6.1.0",
153
157
  "rehype-stringify": "^9.0.0",
154
- "linkifyjs": "^4.1.1",
155
158
  "remark": "^14.0.0",
156
159
  "remark-breaks": "^3.0.0",
157
160
  "remark-gfm": "^3.0.0",