@doist/typist 1.0.7 → 1.0.9

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
+ ## [1.0.9](https://github.com/Doist/typist/compare/v1.0.8...v1.0.9) (2022-12-19)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **rich-text-link:** More lenient regex for input/paste rule ([#72](https://github.com/Doist/typist/issues/72)) ([98e363f](https://github.com/Doist/typist/commit/98e363f27e6e403a775ca8fe729ce17dbdf721df))
6
+
7
+ ## [1.0.8](https://github.com/Doist/typist/compare/v1.0.7...v1.0.8) (2022-12-19)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **factories:** Allow alphanumeric IDs for suggestion nodes in `createSuggestionExtension` ([#66](https://github.com/Doist/typist/issues/66)) ([a1726a6](https://github.com/Doist/typist/commit/a1726a6be089e3e1452def641dfcfc622ac3e942))
12
+
1
13
  ## [1.0.7](https://github.com/Doist/typist/compare/v1.0.6...v1.0.7) (2022-12-14)
2
14
 
3
15
  ### Bug Fixes
@@ -1 +1 @@
1
- {"version":3,"file":"rich-text-link.d.ts","sourceRoot":"","sources":["../../../src/extensions/rich-text/rich-text-link.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AA2DzD;;;;GAIG;AACH,QAAA,MAAM,YAAY,+CA8ChB,CAAA;AAEF,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,YAAY,EAAE,WAAW,IAAI,mBAAmB,EAAE,CAAA"}
1
+ {"version":3,"file":"rich-text-link.d.ts","sourceRoot":"","sources":["../../../src/extensions/rich-text/rich-text-link.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAuDzD;;;;GAIG;AACH,QAAA,MAAM,YAAY,+CA8ChB,CAAA;AAEF,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,YAAY,EAAE,WAAW,IAAI,mBAAmB,EAAE,CAAA"}
@@ -3,17 +3,13 @@ import { Link } from '@tiptap/extension-link';
3
3
  /**
4
4
  * The input regex for Markdown links with title support, and multiple quotation marks (required
5
5
  * in case the `Typography` extension is being included).
6
- *
7
- * @see https://stephenweiss.dev/regex-markdown-link
8
6
  */
9
- const inputRegex = /(?:^|\s)\[([^\]]*)?\]\(([A-Za-z0-9:/.-?]+)(?: ["“](.+)["”])?\)$/;
7
+ const inputRegex = /(?:^|\s)\[([^\]]*)?\]\((\S+)(?: ["“](.+)["”])?\)$/i;
10
8
  /**
11
9
  * The paste regex for Markdown links with title support, and multiple quotation marks (required
12
10
  * in case the `Typography` extension is being included).
13
- *
14
- * @see https://stephenweiss.dev/regex-markdown-link
15
11
  */
16
- const pasteRegex = /(?:^|\s)\[([^\]]*)?\]\(([A-Za-z0-9:/.-?]+)(?: ["“](.+)["”])?\)/g;
12
+ const pasteRegex = /(?:^|\s)\[([^\]]*)?\]\((\S+)(?: ["“](.+)["”])?\)/gi;
17
13
  /**
18
14
  * Input rule built specifically for the `Link` extension, which ignores the auto-linked URL in
19
15
  * parentheses (e.g., `(https://doist.dev)`).
@@ -24,7 +20,7 @@ function linkInputRule(config) {
24
20
  const defaultMarkInputRule = markInputRule(config);
25
21
  return new InputRule({
26
22
  find: config.find,
27
- handler: (props) => {
23
+ handler(props) {
28
24
  const { tr } = props.state;
29
25
  defaultMarkInputRule.handler(props);
30
26
  tr.setMeta('preventAutolink', true);
@@ -42,7 +38,7 @@ function linkPasteRule(config) {
42
38
  const defaultMarkInputRule = markPasteRule(config);
43
39
  return new PasteRule({
44
40
  find: config.find,
45
- handler: (props) => {
41
+ handler(props) {
46
42
  const { tr } = props.state;
47
43
  defaultMarkInputRule.handler(props);
48
44
  tr.setMeta('preventAutolink', true);
@@ -8,7 +8,7 @@ type SuggestionAttributes = {
8
8
  /**
9
9
  * The suggestion node unique identifier to be rendered by the editor as a `data-id` attribute.
10
10
  */
11
- id: number;
11
+ id: number | string;
12
12
  /**
13
13
  * The suggestion node label to be rendered by the editor as a `data-label` attribute and the
14
14
  * display text itself.
@@ -84,7 +84,7 @@ type SuggestionStorage<SuggestionItemType> = Readonly<{
84
84
  * A collection of suggestion items indexed by the item id.
85
85
  */
86
86
  itemsById: {
87
- readonly [id: number]: SuggestionItemType | undefined;
87
+ readonly [id: SuggestionAttributes['id']]: SuggestionItemType | undefined;
88
88
  };
89
89
  }>;
90
90
  /**
@@ -109,11 +109,11 @@ type SuggestionExtensionResult<SuggestionItemType> = Node<SuggestionOptions<Sugg
109
109
  * @returns A new suggestion extension tailored to a specific use case.
110
110
  */
111
111
  declare function createSuggestionExtension<SuggestionItemType extends {
112
- [id: string]: unknown;
112
+ [id: SuggestionAttributes['id']]: unknown;
113
113
  } = SuggestionAttributes>(type: string, items?: SuggestionItemType[], ...attributesMapping: SuggestionItemType extends SuggestionAttributes ? [] : [
114
114
  RequireAtLeastOne<{
115
- id: ConditionalKeys<SuggestionItemType, number>;
116
- label: ConditionalKeys<SuggestionItemType, string>;
115
+ id: ConditionalKeys<SuggestionItemType, SuggestionAttributes['id']>;
116
+ label: ConditionalKeys<SuggestionItemType, SuggestionAttributes['label']>;
117
117
  }>
118
118
  ]): SuggestionExtensionResult<SuggestionItemType>;
119
119
  export { createSuggestionExtension };
@@ -1 +1 @@
1
- {"version":3,"file":"create-suggestion-extension.d.ts","sourceRoot":"","sources":["../../src/factories/create-suggestion-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,cAAc,CAAA;AAOpD,OAAO,KAAK,EACR,sBAAsB,IAAI,0BAA0B,EACpD,iBAAiB,IAAI,qBAAqB,EAC7C,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEnE;;GAEG;AACH,KAAK,oBAAoB,GAAG;IACxB;;OAEG;IACH,EAAE,EAAE,MAAM,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AAA;IAE3B;;OAEG;IACH,SAAS,EAAE;QAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAAA;KAAE,CAAA;CACvE,CAAC,CAAA;AAEF;;GAEG;AACH,KAAK,yBAAyB,CAAC,kBAAkB,IAAI,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAEhG;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,yBAAyB,CAC9B,kBAAkB,SAAS;IAAE,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GAAG,oBAAoB,EAE3E,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,kBAAkB,EAAO,EAKhC,GAAG,iBAAiB,EAAE,kBAAkB,SAAS,oBAAoB,GAC/D,EAAE,GACF;IACI,iBAAiB,CAAC;QACd,EAAE,EAAE,eAAe,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;QAC/C,KAAK,EAAE,eAAe,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;KACrD,CAAC;CACL,GACR,yBAAyB,CAAC,kBAAkB,CAAC,CAuJ/C;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA;AAEpC,YAAY,EACR,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GACpB,CAAA"}
1
+ {"version":3,"file":"create-suggestion-extension.d.ts","sourceRoot":"","sources":["../../src/factories/create-suggestion-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,cAAc,CAAA;AAOpD,OAAO,KAAK,EACR,sBAAsB,IAAI,0BAA0B,EACpD,iBAAiB,IAAI,qBAAqB,EAC7C,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEnE;;GAEG;AACH,KAAK,oBAAoB,GAAG;IACxB;;OAEG;IACH,EAAE,EAAE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AAE,kBAAkB,EAAE,CAAA;IAE3B;;OAEG;IACH,SAAS,EAAE;QAAE,QAAQ,EAAE,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAAG,kBAAkB,GAAG,SAAS,CAAA;KAAE,CAAA;CAC3F,CAAC,CAAA;AAEF;;GAEG;AACH,KAAK,yBAAyB,CAAC,kBAAkB,IAAI,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAEhG;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,yBAAyB,CAC9B,kBAAkB,SAAS;IAAE,CAAC,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAA;CAAE,GAAG,oBAAoB,EAE/F,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,kBAAkB,EAAO,EAKhC,GAAG,iBAAiB,EAAE,kBAAkB,SAAS,oBAAoB,GAC/D,EAAE,GACF;IACI,iBAAiB,CAAC;QACd,EAAE,EAAE,eAAe,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAA;QACnE,KAAK,EAAE,eAAe,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAA;KAC5E,CAAC;CACL,GACR,yBAAyB,CAAC,kBAAkB,CAAC,CAuJ/C;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA;AAEpC,YAAY,EACR,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GACpB,CAAA"}
@@ -63,13 +63,13 @@ function createSuggestionExtension(type, items = [],
63
63
  default: null,
64
64
  parseHTML: (element) => element.getAttribute('data-id'),
65
65
  renderHTML: (attributes) => ({
66
- 'data-id': Number(attributes[idAttribute]),
66
+ 'data-id': String(attributes[idAttribute]),
67
67
  }),
68
68
  },
69
69
  [labelAttribute]: {
70
70
  default: null,
71
71
  parseHTML: (element) => {
72
- const id = Number(element.getAttribute('data-id'));
72
+ const id = String(element.getAttribute('data-id'));
73
73
  const item = this.storage.itemsById[id];
74
74
  // Read the latest item label from the storage, if available, otherwise
75
75
  // fallback to the item label in the `data-label` attribute
@@ -90,7 +90,7 @@ function createSuggestionExtension(type, items = [],
90
90
  mergeAttributes({
91
91
  [`data-${attributeType}`]: '',
92
92
  'aria-label': this.options.renderAriaLabel?.({
93
- id: Number(node.attrs[idAttribute]),
93
+ id: String(node.attrs[idAttribute]),
94
94
  label: String(node.attrs[labelAttribute]),
95
95
  }),
96
96
  }, HTMLAttributes),
@@ -15,7 +15,7 @@ function link(suggestionNodes) {
15
15
  renderer: {
16
16
  link(href, title, text) {
17
17
  if (href && linkSchemaRegex.test(href)) {
18
- const [, schema, id] = /^([a-z-]+):\/\/(\d+)$/i.exec(href) || [];
18
+ const [, schema, id] = /^([a-z-]+):\/\/(\S+)$/i.exec(href) || [];
19
19
  if (schema && id && text) {
20
20
  return `<span data-${schema} data-id="${id}" data-label="${text}"></span>`;
21
21
  }
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": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -82,15 +82,15 @@
82
82
  "devDependencies": {
83
83
  "@doist/eslint-config": "8.1.3",
84
84
  "@doist/prettier-config": "3.0.5",
85
- "@doist/reactist": "17.4.0",
86
- "@mdx-js/react": "2.1.5",
85
+ "@doist/reactist": "17.5.0",
86
+ "@mdx-js/react": "2.2.1",
87
87
  "@semantic-release/changelog": "6.0.2",
88
88
  "@semantic-release/exec": "6.0.3",
89
89
  "@semantic-release/git": "10.0.1",
90
90
  "@storybook/addon-a11y": "6.5.14",
91
91
  "@storybook/addon-essentials": "6.5.14",
92
92
  "@storybook/addons": "6.5.14",
93
- "@storybook/builder-vite": "0.2.5",
93
+ "@storybook/builder-vite": "0.2.6",
94
94
  "@storybook/mdx2-csf": "0.0.3",
95
95
  "@storybook/react": "6.5.14",
96
96
  "@testing-library/dom": "8.19.0",
@@ -112,7 +112,7 @@
112
112
  "eslint-import-resolver-typescript": "3.5.2",
113
113
  "eslint-plugin-jest": "27.1.6",
114
114
  "eslint-plugin-simple-import-sort": "8.0.0",
115
- "eslint-plugin-unicorn": "45.0.1",
115
+ "eslint-plugin-unicorn": "45.0.2",
116
116
  "github-markdown-css": "5.1.0",
117
117
  "husky": "8.0.2",
118
118
  "ignore-sync": "6.0.2",
@@ -132,7 +132,7 @@
132
132
  "storybook-css-modules": "1.0.8",
133
133
  "ts-jest": "29.0.3",
134
134
  "ts-node": "10.9.1",
135
- "type-fest": "3.3.0",
135
+ "type-fest": "3.4.0",
136
136
  "typescript": "4.9.4",
137
137
  "typescript-plugin-css-modules": "4.1.1"
138
138
  },