@doist/typist 1.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.
Files changed (147) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/CODE_OF_CONDUCT.md +83 -0
  3. package/CONTRIBUTING.md +123 -0
  4. package/LICENSE +21 -0
  5. package/README.md +74 -0
  6. package/dist/components/typist-editor.d.ts +173 -0
  7. package/dist/components/typist-editor.d.ts.map +1 -0
  8. package/dist/components/typist-editor.helper.d.ts +22 -0
  9. package/dist/components/typist-editor.helper.d.ts.map +1 -0
  10. package/dist/components/typist-editor.helper.js +26 -0
  11. package/dist/components/typist-editor.js +160 -0
  12. package/dist/constants/common.d.ts +10 -0
  13. package/dist/constants/common.d.ts.map +1 -0
  14. package/dist/constants/common.js +9 -0
  15. package/dist/constants/extension-priorities.d.ts +26 -0
  16. package/dist/constants/extension-priorities.d.ts.map +1 -0
  17. package/dist/constants/extension-priorities.js +25 -0
  18. package/dist/constants/regular-expressions.d.ts +6 -0
  19. package/dist/constants/regular-expressions.d.ts.map +1 -0
  20. package/dist/constants/regular-expressions.js +5 -0
  21. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts +24 -0
  22. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts.map +1 -0
  23. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js +32 -0
  24. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts +28 -0
  25. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map +1 -0
  26. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js +25 -0
  27. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts +9 -0
  28. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts.map +1 -0
  29. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js +18 -0
  30. package/dist/extensions/core/view-event-handlers.d.ts +33 -0
  31. package/dist/extensions/core/view-event-handlers.d.ts.map +1 -0
  32. package/dist/extensions/core/view-event-handlers.js +35 -0
  33. package/dist/extensions/plain-text/paste-multiline-text.d.ts +10 -0
  34. package/dist/extensions/plain-text/paste-multiline-text.d.ts.map +1 -0
  35. package/dist/extensions/plain-text/paste-multiline-text.js +66 -0
  36. package/dist/extensions/plain-text/plain-text-document.d.ts +17 -0
  37. package/dist/extensions/plain-text/plain-text-document.d.ts.map +1 -0
  38. package/dist/extensions/plain-text/plain-text-document.js +17 -0
  39. package/dist/extensions/plain-text/plain-text-kit.d.ts +42 -0
  40. package/dist/extensions/plain-text/plain-text-kit.d.ts.map +1 -0
  41. package/dist/extensions/plain-text/plain-text-kit.js +47 -0
  42. package/dist/extensions/plain-text/plain-text-paragraph.d.ts +9 -0
  43. package/dist/extensions/plain-text/plain-text-paragraph.d.ts.map +1 -0
  44. package/dist/extensions/plain-text/plain-text-paragraph.js +13 -0
  45. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts +9 -0
  46. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts.map +1 -0
  47. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js +89 -0
  48. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts +9 -0
  49. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts.map +1 -0
  50. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js +49 -0
  51. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts +9 -0
  52. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts.map +1 -0
  53. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js +43 -0
  54. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts +8 -0
  55. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts.map +1 -0
  56. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js +17 -0
  57. package/dist/extensions/rich-text/bold-and-italics.d.ts +8 -0
  58. package/dist/extensions/rich-text/bold-and-italics.d.ts.map +1 -0
  59. package/dist/extensions/rich-text/bold-and-italics.js +40 -0
  60. package/dist/extensions/rich-text/curvenote-codemark.d.ts +11 -0
  61. package/dist/extensions/rich-text/curvenote-codemark.d.ts.map +1 -0
  62. package/dist/extensions/rich-text/curvenote-codemark.js +18 -0
  63. package/dist/extensions/rich-text/paste-emojis.d.ts +9 -0
  64. package/dist/extensions/rich-text/paste-emojis.d.ts.map +1 -0
  65. package/dist/extensions/rich-text/paste-emojis.js +28 -0
  66. package/dist/extensions/rich-text/paste-markdown.d.ts +11 -0
  67. package/dist/extensions/rich-text/paste-markdown.d.ts.map +1 -0
  68. package/dist/extensions/rich-text/paste-markdown.js +68 -0
  69. package/dist/extensions/rich-text/rich-text-document.d.ts +17 -0
  70. package/dist/extensions/rich-text/rich-text-document.d.ts.map +1 -0
  71. package/dist/extensions/rich-text/rich-text-document.js +17 -0
  72. package/dist/extensions/rich-text/rich-text-image.d.ts +80 -0
  73. package/dist/extensions/rich-text/rich-text-image.d.ts.map +1 -0
  74. package/dist/extensions/rich-text/rich-text-image.js +109 -0
  75. package/dist/extensions/rich-text/rich-text-kit.d.ts +129 -0
  76. package/dist/extensions/rich-text/rich-text-kit.d.ts.map +1 -0
  77. package/dist/extensions/rich-text/rich-text-kit.js +130 -0
  78. package/dist/extensions/rich-text/rich-text-link.d.ts +10 -0
  79. package/dist/extensions/rich-text/rich-text-link.d.ts.map +1 -0
  80. package/dist/extensions/rich-text/rich-text-link.js +102 -0
  81. package/dist/extensions/shared/copy-markdown-source.d.ts +20 -0
  82. package/dist/extensions/shared/copy-markdown-source.d.ts.map +1 -0
  83. package/dist/extensions/shared/copy-markdown-source.js +35 -0
  84. package/dist/extensions/shared/paste-singleline-text.d.ts +10 -0
  85. package/dist/extensions/shared/paste-singleline-text.d.ts.map +1 -0
  86. package/dist/extensions/shared/paste-singleline-text.js +43 -0
  87. package/dist/factories/create-suggestion-extension.d.ts +121 -0
  88. package/dist/factories/create-suggestion-extension.d.ts.map +1 -0
  89. package/dist/factories/create-suggestion-extension.js +149 -0
  90. package/dist/helpers/dom.d.ts +8 -0
  91. package/dist/helpers/dom.d.ts.map +1 -0
  92. package/dist/helpers/dom.js +9 -0
  93. package/dist/helpers/schema.d.ts +19 -0
  94. package/dist/helpers/schema.d.ts.map +1 -0
  95. package/dist/helpers/schema.js +21 -0
  96. package/dist/helpers/serializer.d.ts +11 -0
  97. package/dist/helpers/serializer.d.ts.map +1 -0
  98. package/dist/helpers/serializer.js +16 -0
  99. package/dist/hooks/use-editor.d.ts +19 -0
  100. package/dist/hooks/use-editor.d.ts.map +1 -0
  101. package/dist/hooks/use-editor.js +46 -0
  102. package/dist/index.d.ts +26 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +17 -0
  105. package/dist/serializers/html/extensions/checkbox.d.ts +8 -0
  106. package/dist/serializers/html/extensions/checkbox.d.ts.map +1 -0
  107. package/dist/serializers/html/extensions/checkbox.js +12 -0
  108. package/dist/serializers/html/extensions/code.d.ts +9 -0
  109. package/dist/serializers/html/extensions/code.d.ts.map +1 -0
  110. package/dist/serializers/html/extensions/code.js +20 -0
  111. package/dist/serializers/html/extensions/html.d.ts +10 -0
  112. package/dist/serializers/html/extensions/html.d.ts.map +1 -0
  113. package/dist/serializers/html/extensions/html.js +15 -0
  114. package/dist/serializers/html/extensions/link.d.ts +11 -0
  115. package/dist/serializers/html/extensions/link.d.ts.map +1 -0
  116. package/dist/serializers/html/extensions/link.js +28 -0
  117. package/dist/serializers/html/extensions/paragraph.d.ts +12 -0
  118. package/dist/serializers/html/extensions/paragraph.d.ts.map +1 -0
  119. package/dist/serializers/html/extensions/paragraph.js +51 -0
  120. package/dist/serializers/html/extensions/task-list.d.ts +9 -0
  121. package/dist/serializers/html/extensions/task-list.d.ts.map +1 -0
  122. package/dist/serializers/html/extensions/task-list.js +31 -0
  123. package/dist/serializers/html/html.d.ts +27 -0
  124. package/dist/serializers/html/html.d.ts.map +1 -0
  125. package/dist/serializers/html/html.js +129 -0
  126. package/dist/serializers/markdown/markdown.d.ts +40 -0
  127. package/dist/serializers/markdown/markdown.d.ts.map +1 -0
  128. package/dist/serializers/markdown/markdown.js +126 -0
  129. package/dist/serializers/markdown/plugins/image.d.ts +12 -0
  130. package/dist/serializers/markdown/plugins/image.d.ts.map +1 -0
  131. package/dist/serializers/markdown/plugins/image.js +31 -0
  132. package/dist/serializers/markdown/plugins/list-item.d.ts +14 -0
  133. package/dist/serializers/markdown/plugins/list-item.d.ts.map +1 -0
  134. package/dist/serializers/markdown/plugins/list-item.js +41 -0
  135. package/dist/serializers/markdown/plugins/paragraph.d.ts +12 -0
  136. package/dist/serializers/markdown/plugins/paragraph.d.ts.map +1 -0
  137. package/dist/serializers/markdown/plugins/paragraph.js +18 -0
  138. package/dist/serializers/markdown/plugins/strikethrough.d.ts +13 -0
  139. package/dist/serializers/markdown/plugins/strikethrough.d.ts.map +1 -0
  140. package/dist/serializers/markdown/plugins/strikethrough.js +23 -0
  141. package/dist/serializers/markdown/plugins/suggestion.d.ts +11 -0
  142. package/dist/serializers/markdown/plugins/suggestion.d.ts.map +1 -0
  143. package/dist/serializers/markdown/plugins/suggestion.js +21 -0
  144. package/dist/serializers/markdown/plugins/task-item.d.ts +14 -0
  145. package/dist/serializers/markdown/plugins/task-item.d.ts.map +1 -0
  146. package/dist/serializers/markdown/plugins/task-item.js +39 -0
  147. package/package.json +146 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 1.0.0 (2022-11-04)
2
+
3
+ ### Features
4
+
5
+ - Initial Typist implementation ([19451ab](https://github.com/Doist/typist/commit/19451ab9eb66de1399585d9a2e06141096d690c4))
6
+
7
+ ### Bug Fixes
8
+
9
+ - **deps:** update tiptap packages to v2.0.0-beta.200 ([#3](https://github.com/Doist/typist/issues/3)) ([6e977a9](https://github.com/Doist/typist/commit/6e977a9ee5f687700d2868a834b8d20068c15e3e))
@@ -0,0 +1,83 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or advances of any kind
22
+ - Trolling, insulting or derogatory comments, and personal or political attacks
23
+ - Public or private harassment
24
+ - Publishing others' private information, such as a physical or email address, without their explicit permission
25
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
26
+
27
+ ## Enforcement Responsibilities
28
+
29
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32
+
33
+ ## Scope
34
+
35
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36
+
37
+ ## Enforcement
38
+
39
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at frontend+opensource@doist.com. All complaints will be reviewed and investigated promptly and fairly.
40
+
41
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42
+
43
+ ## Enforcement Guidelines
44
+
45
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46
+
47
+ ### 1. Correction
48
+
49
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50
+
51
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52
+
53
+ ### 2. Warning
54
+
55
+ **Community Impact**: A violation through a single incident or series of actions.
56
+
57
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58
+
59
+ ### 3. Temporary Ban
60
+
61
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62
+
63
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64
+
65
+ ### 4. Permanent Ban
66
+
67
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68
+
69
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
70
+
71
+ ## Attribution
72
+
73
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
74
+
75
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][mozilla coc].
76
+
77
+ For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][faq]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
78
+
79
+ [homepage]: https://www.contributor-covenant.org
80
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
81
+ [mozilla coc]: https://github.com/mozilla/diversity
82
+ [faq]: https://www.contributor-covenant.org/faq
83
+ [translations]: https://www.contributor-covenant.org/translations
@@ -0,0 +1,123 @@
1
+ # Contributing to Typist
2
+
3
+ The following is a set of guidelines for contributing to Typist. Please spend several minutes reading these guidelines before you create an issue, pull request or discussion.
4
+
5
+ ## Code of Conduct
6
+
7
+ Doist has adopted the [Contributor Covenant](https://www.contributor-covenant.org/) as its Code of Conduct, and we expect contributors to Typist to adhere to it. Please read [the full text](https://github.com/doist/typist/blob/main/CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated.
8
+
9
+ ## Open Development
10
+
11
+ All work on Typist happens directly on [GitHub](https://github.com/Doist/typist). Both core team members and external contributors send pull requests that go through the same review process.
12
+
13
+ ## Semantic Versioning
14
+
15
+ Typist follows [semantic versioning](https://semver.org/). We release patch versions for critical bugfixes, minor versions for new features or non-essential changes, and major versions for any breaking changes.
16
+
17
+ Every significant change is documented in the [CHANGELOG.md](CHANGELOG.md) file.
18
+
19
+ ## Branch Organization
20
+
21
+ Submit all changes directly to the [main](https://github.com/doist/typist/tree/main) branch. We don't use separate branches for development or for upcoming releases. We do our best to keep `main` in good shape, with all tests passing.
22
+
23
+ ## Proposing a Change
24
+
25
+ If you intend to change the public API, or make any non-trivial changes to the implementation, we recommend opening a [GitHub Discussion](https://github.com/doist/typist/discussions) with the core team first. Although we welcome all contributions, this lets us reach an agreement on your proposal before you put significant effort into something that might not fit Doist product requirements.
26
+
27
+ ## Your First Pull Request
28
+
29
+ Working on your first Pull Request? You can learn how from this free video series:
30
+
31
+ - [How to Contribute to an Open Source Project on GitHub](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)
32
+
33
+ If you decide to fix an issue, please be sure to check the comment thread in case somebody is already working on a fix. If nobody is working on it at the moment, please leave a comment stating that you intend to work on it so other people don't accidentally duplicate your effort.
34
+
35
+ ## Project Setup
36
+
37
+ Before you can contribute to the codebase, you will need to fork the Typist repository, and the following steps will help you hit the ground running:
38
+
39
+ 1. Fork the repository (click the <kbd>Fork</kbd> button at the top right of [this page](https://github.com/doist/typist));
40
+
41
+ 2. Clone your fork locally;
42
+
43
+ ```sh
44
+ git clone https://github.com/<your_github_username>/typist.git
45
+ cd typist
46
+ ```
47
+
48
+ 3. Install all dependencies by running `npm install`;
49
+
50
+ > **Note**
51
+ >
52
+ > If you're not using **npm 7+**, install peer dependencies with `npx npm-install-peers`.
53
+
54
+ ## Development Workflow
55
+
56
+ After cloning Typist and installing all dependencies, several commands are at your disposal:
57
+
58
+ - `npm run build`: Builds the `@doist/typist` package for publishing to [npm](https://www.npmjs.com/) and [GitHub Packages](https://github.com/orgs/Doist/packages?repo_name=typist);
59
+ - `npm run check`: Validates code quality with ESLint, styling with Prettier, and types with TypeScript;
60
+ - `npm run clean`: Removes temporary directories used for multiple caches;
61
+ - `npm run storybook:build`: Builds Storybook as a static Web application;
62
+ - `npm run storybook:start`: Starts Storybook Web application (available at http://localhost:6006/);
63
+ - `npm run test`: Runs all unit test with Jest and end-to-end tests with Storybook.
64
+
65
+ ### Release Process (core team only)
66
+
67
+ The release process for Typist is almost fully automated with [`semantic-release`](https://github.com/semantic-release/semantic-release), only requiring a core team member to trigger [this workflow](https://github.com/Doist/typist/actions/workflows/publish-typist-package-release.yml) manually whenever a new release needs to be published.
68
+
69
+ ### Visual Studio Code
70
+
71
+ #### CSS Modules for Storybook
72
+
73
+ Typist Storybook makes use of [`typescript-plugin-css-modules`](https://github.com/mrmckeb/typescript-plugin-css-modules), a [TypeScript language service plugin](https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin) for [CSS Modules](https://github.com/css-modules/css-modules), which provides type information to IDEs and any other tools that work with TypeScript language service plugins.
74
+
75
+ To use this plugin with Visual Studio Code, you should set your workspace's version of TypeScript, which will load plugins from your tsconfig.json file. For instructions, please see: [Using the workspace version of TypeScript](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript).
76
+
77
+ ## Sending a Pull Request
78
+
79
+ Pull requests are actively monitored, and only need the approval of one or more core team members. We will review your pull request and either merge it, request changes to it, or close it with an explanation.
80
+
81
+ Before submitting a pull request, please take the following into consideration:
82
+
83
+ - Fork [the repository](https://github.com/doist/typist) and create your branch from `main`;
84
+ - Follow the [Commit Message Guidelines](#commit-message-guidelines) below;
85
+ - Add tests for code that should be tested (like bug fixes);
86
+ - Ensure the test suite passes with flying colours;
87
+ - Do not override built-in validation and formatting checks.
88
+
89
+ ### Commit Message Guidelines
90
+
91
+ #### Atomic Commits
92
+
93
+ If possible, make [atomic commits](https://en.wikipedia.org/wiki/Atomic_commit), which means:
94
+
95
+ - A commit should not mix whitespace and/or code style changes with functional code changes;
96
+ - A commit should contain exactly one self-contained functional change;
97
+ - A commit should not create an inconsistent state (e.g., test errors, linting errors, partial fix, etc.).
98
+
99
+ #### Commit Message Format
100
+
101
+ This repository expects all commit messages to follow the [Conventional Commits Specification](https://www.conventionalcommits.org/) to automate semantic versioning and `CHANGELOG.md` generation.
102
+
103
+ As a quick summary, each commit message consists of a **header**, an **optional body**, and an **optional footer**. The header has a special format that includes a **type**, an **optional scope**, and a **description**:
104
+
105
+ ```
106
+ <type>[optional scope]: <description>
107
+
108
+ [optional body]
109
+
110
+ [optional footer(s)]
111
+ ```
112
+
113
+ Commit types, such as `feat:` or `fix:`, are the only ones that will affect versioning and `CHANGELOG.md` generation, whereas commit types such as `build:`, `chore:`, `ci:`, `docs:`, `perf:`, `refactor:`, `revert:`, `style:` and `test:` will not. They are still valid, and it would be great if you could use them when appropriate.
114
+
115
+ A commit that has the text `BREAKING CHANGE:` at the beginning of its optional body or footer section, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A breaking change can be part of commits of any _type_.
116
+
117
+ ## License
118
+
119
+ By contributing to Typist, you agree that your contributions will be licensed under its [MIT license](LICENSE).
120
+
121
+ ## Attribution
122
+
123
+ This document is based on [reactjs.org contributing guidelines](https://reactjs.org/docs/how-to-contribute.html).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Doist Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ <div align="center">
2
+ <h1>
3
+ <img src="https://github.com/Doist/typist/blob/main/.github/assets/logo-light.png?raw=true#gh-light-mode-only" />
4
+ <img src="https://github.com/Doist/typist/blob/main/.github/assets/logo-dark.png?raw=true#gh-dark-mode-only" />
5
+ </h1>
6
+ </div>
7
+
8
+ Typist is the mighty [Tiptap](https://tiptap.dev/)-based rich-text editor that powers Doist products, which can also be used for displaying content in a read-only fashion. Typist also supports a plain-text mode, and comes with HTML/Markdown serializers.
9
+
10
+ > **Note**
11
+ >
12
+ > This project is not attempting to be an all-purpose rich-text editor. Whilst everyone is welcome to fork or use this package in their own products, development decisions are centered around Doist product requirements.
13
+
14
+ <div align="center">
15
+
16
+ ![GitHub: CI Validation](https://github.com/Doist/typist/actions/workflows/check-ci-validation.yml/badge.svg?branch=main)
17
+ ![npm Version](https://img.shields.io/npm/v/@doist/typist)
18
+ ![npm Bundle Size (minified)](https://img.shields.io/bundlephobia/min/@doist/typist)
19
+ ![npm Downloads (monthly)](https://img.shields.io/npm/dm/@doist/typist?color=blue)
20
+
21
+ [![semantic-release: Conventional Commits](https://img.shields.io/badge/semantic--release-Conventional%20Commits-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
22
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
23
+ [![License: MIT](https://img.shields.io/github/license/doist/typist)](LICENSE.md)
24
+
25
+ </div>
26
+
27
+ ## Installation
28
+
29
+ ```sh
30
+ npm install --save @doist/typist
31
+ ```
32
+
33
+ ### Peer Dependencies
34
+
35
+ If you are using **npm 7+** and the `legacy-peer-deps` options is not enabled, peer dependencies should have been automatically installed for you with the command above. Otherwise, you can install them with:
36
+
37
+ ```sh
38
+ npm info @doist/typist peerDependencies --json \
39
+ | command sed 's/[\{\},]//g ; s/: /@/g' \
40
+ | xargs npm install --save
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```tsx
46
+ import { TypistEditor, RichTextKit } from '@doist/typist'
47
+
48
+ function TypistEditorContainer({ content }) {
49
+ return (
50
+ <TypistEditor
51
+ placeholder="A full rich-text editor, be creative…"
52
+ content={content}
53
+ extensions={[RichTextKit]}
54
+ />
55
+ )
56
+ }
57
+ ```
58
+
59
+ If you're looking for additional documentation, in-depth examples, or a live demo, please check out our [Storybook](https://typist.doist.dev/).
60
+
61
+ ## Resources
62
+
63
+ A curated list of open-source rich-text editors powered by Tiptap that we can draw inspiration from:
64
+
65
+ - GitLab's content editor:\
66
+ https://gitlab.com/gitlab-org/gitlab/-/tree/master/app/assets/javascripts/content_editor
67
+
68
+ ## Contributing
69
+
70
+ If you're interested in contributing code and/or documentation, please read our [contributing guide](CONTRIBUTING.md).
71
+
72
+ ## License
73
+
74
+ The use of this source code is governed by an MIT-style license that can be found in the [LICENSE](LICENSE) file.
@@ -0,0 +1,173 @@
1
+ /// <reference types="react" />
2
+ import { ViewEventHandlersOptions } from '../extensions/core/view-event-handlers';
3
+ import { getAllNodesAttributesByType } from './typist-editor.helper';
4
+ import type { Editor as CoreEditor, EditorEvents, Extensions } from '@tiptap/core';
5
+ import type { Selection } from 'prosemirror-state';
6
+ /**
7
+ * The forwarded ref that describes the helper methods that the `TypistEditor` parent component
8
+ * will have access to.
9
+ */
10
+ declare type TypistEditorRef = {
11
+ /**
12
+ * Returns the `Editor` instance associated to the `TypistEditor` component.
13
+ */
14
+ getEditor: () => CoreEditor;
15
+ /**
16
+ * Returns the current editor document output as Markdown.
17
+ */
18
+ getMarkdown: () => string;
19
+ /**
20
+ * Returns the attributes of a given node type for all the nodes in the editor document.
21
+ */
22
+ getAllNodesAttributesByType: (nodeType: string) => ReturnType<typeof getAllNodesAttributesByType>;
23
+ };
24
+ /**
25
+ * The properties that describe the `beforeCreate` editor event.
26
+ */
27
+ declare type BeforeCreateProps = EditorEvents['beforeCreate'];
28
+ /**
29
+ * The properties that describe the `create` editor event.
30
+ */
31
+ declare type CreateProps = EditorEvents['create'];
32
+ /**
33
+ * The properties that describe the `update` editor event.
34
+ */
35
+ declare type UpdateProps = EditorEvents['update'] & Pick<TypistEditorRef, 'getMarkdown'>;
36
+ /**
37
+ * The properties that describe the `selectionUpdate` editor event.
38
+ */
39
+ declare type SelectionUpdateProps = EditorEvents['selectionUpdate'];
40
+ /**
41
+ * The properties that describe the `transaction` editor event.
42
+ */
43
+ declare type TransacationProps = EditorEvents['transaction'];
44
+ /**
45
+ * The properties that describe the `focus` editor event.
46
+ */
47
+ declare type FocusProps = EditorEvents['focus'];
48
+ /**
49
+ * The properties that describe the `blur` editor event.
50
+ */
51
+ declare type BlurProps = EditorEvents['blur'];
52
+ /**
53
+ * The properties that describe the `destroy` editor event.
54
+ */
55
+ declare type DestroyProps = EditorEvents['destroy'];
56
+ /**
57
+ * The properties available to represent an instance of the `TypistEditor` component, including
58
+ * the supported WAI-ARIA 1.1 attributes.
59
+ */
60
+ declare type TypistEditorProps = {
61
+ /**
62
+ * Auto focus the editor to the end of the document on initialization.
63
+ */
64
+ autoFocus?: boolean;
65
+ /**
66
+ * The CSS class for the container surrounding the editor DOM element.
67
+ */
68
+ className?: string;
69
+ /**
70
+ * The initial Markdown content for the editor.
71
+ */
72
+ content?: string;
73
+ /**
74
+ * The initial content selection (only applied if `autoFocus` is `true`).
75
+ */
76
+ contentSelection?: Selection;
77
+ /**
78
+ * Determines if users can write into the editor.
79
+ */
80
+ editable?: boolean;
81
+ /**
82
+ * The list of required extensions to initialize the editor.
83
+ *
84
+ * You may consider wrapping this prop with `useMemo` to prevent unnecessary re-renders.
85
+ */
86
+ extensions: Extensions;
87
+ /**
88
+ * A short hint that gives users an idea what can be entered in the editor.
89
+ */
90
+ placeholder?: string;
91
+ /**
92
+ * The event handler that is fired before the editor view is created.
93
+ *
94
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
95
+ */
96
+ onBeforeCreate?: (props: BeforeCreateProps) => void;
97
+ /**
98
+ * The event handler that is fired when the editor view is ready.
99
+ *
100
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
101
+ */
102
+ onCreate?: (props: CreateProps) => void;
103
+ /**
104
+ * The event handler that is fired when the editor content has changed.
105
+ *
106
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
107
+ */
108
+ onUpdate?: (props: UpdateProps) => void;
109
+ /**
110
+ * The event handler that is fired when the editor selection has changed.
111
+ *
112
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
113
+ */
114
+ onSelectionUpdate?: (props: SelectionUpdateProps) => void;
115
+ /**
116
+ * The event handler that is fired when the editor state has changed.
117
+ *
118
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
119
+ */
120
+ onTransaction?: (props: TransacationProps) => void;
121
+ /**
122
+ * The event handler that is fired when the editor view gains focus.
123
+ *
124
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
125
+ */
126
+ onFocus?: (props: FocusProps) => void;
127
+ /**
128
+ * The event handler that is fired when the editor view loses focus.
129
+ *
130
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
131
+ */
132
+ onBlur?: (props: BlurProps) => void;
133
+ /**
134
+ * The event handler that is fired when the editor view is being destroyed.
135
+ *
136
+ * You may consider wrapping this prop with `useCallback` to prevent unnecessary re-renders.
137
+ */
138
+ onDestroy?: (props: DestroyProps) => void;
139
+ /**
140
+ * Identifies the element (or elements) that describes the object.
141
+ *
142
+ * @see aria-labelledby
143
+ */
144
+ 'aria-describedby'?: React.AriaAttributes['aria-describedby'];
145
+ /**
146
+ * Defines a string value that labels the current element.
147
+ *
148
+ * @see aria-labelledby.
149
+ */
150
+ 'aria-label'?: React.AriaAttributes['aria-label'];
151
+ /**
152
+ * Identifies the element (or elements) that labels the current element.
153
+ *
154
+ * @see aria-describedby.
155
+ */
156
+ 'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
157
+ /**
158
+ * The event handler that processes `click` events in the editor.
159
+ */
160
+ onClick?: ViewEventHandlersOptions['onClick'];
161
+ /**
162
+ * The event handler that processes `keydown` events in the editor.
163
+ */
164
+ onKeyDown?: ViewEventHandlersOptions['onKeyDown'];
165
+ };
166
+ /**
167
+ * The `TypistEditor` component represents a plain-text or a rich-text editing control, built on
168
+ * top of the amazing [Tiptap](https://tiptap.dev/) library.
169
+ */
170
+ declare const TypistEditor: import("react").ForwardRefExoticComponent<TypistEditorProps & import("react").RefAttributes<TypistEditorRef>>;
171
+ export { TypistEditor };
172
+ export type { BeforeCreateProps, BlurProps, CreateProps, DestroyProps, FocusProps, SelectionUpdateProps, TransacationProps, TypistEditorProps, TypistEditorRef, UpdateProps, };
173
+ //# sourceMappingURL=typist-editor.d.ts.map
@@ -0,0 +1 @@
1
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AAC,CAAA;IAE3D;;OAEG;IACH,OAAO,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAA;IAE7C;;OAEG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC,WAAW,CAAC,CAAA;CACpD,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,YAAY,+GA8MhB,CAAA;AAEF,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,YAAY,EACR,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACd,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { Selection } from 'prosemirror-state';
2
+ import type { Node as ProseMirrorNode } from 'prosemirror-model';
3
+ /**
4
+ * Given a ProseMirror document, and a selection, resolves that selection within the bounds of the
5
+ * document size. This works similarly to the official `autoFocus` implementation.
6
+ */
7
+ declare function resolveContentSelection(doc: ProseMirrorNode, selection: Selection): Selection;
8
+ /**
9
+ * The return type for the node attributes, an object mapping attribute names to values.
10
+ */
11
+ declare type NodeAttributes = {
12
+ [key: string]: unknown;
13
+ };
14
+ /**
15
+ * Given a ProseMirror document and a node type, returns the attributes of the given node type for
16
+ * all the nodes in the document. This is based on the official implementation for the
17
+ * `findChildren` helper function.
18
+ */
19
+ declare function getAllNodesAttributesByType(doc: ProseMirrorNode, nodeType: string): Array<NodeAttributes>;
20
+ export { getAllNodesAttributesByType, resolveContentSelection };
21
+ export type { NodeAttributes };
22
+ //# sourceMappingURL=typist-editor.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typist-editor.helper.d.ts","sourceRoot":"","sources":["../../src/components/typist-editor.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiB,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEhE;;;GAGG;AACH,iBAAS,uBAAuB,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAStF;AAED;;GAEG;AACH,aAAK,cAAc,GAAG;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACzB,CAAA;AAED;;;;GAIG;AACH,iBAAS,2BAA2B,CAChC,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,MAAM,GACjB,KAAK,CAAC,cAAc,CAAC,CAUvB;AAED,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,CAAA;AAE/D,YAAY,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { clamp } from 'lodash-es';
2
+ import { Selection, TextSelection } from 'prosemirror-state';
3
+ /**
4
+ * Given a ProseMirror document, and a selection, resolves that selection within the bounds of the
5
+ * document size. This works similarly to the official `autoFocus` implementation.
6
+ */
7
+ function resolveContentSelection(doc, selection) {
8
+ const minPos = Selection.atStart(doc).from;
9
+ const maxPos = Selection.atEnd(doc).to;
10
+ return TextSelection.create(doc, clamp(selection.anchor, minPos, maxPos), clamp(selection.head, minPos, maxPos));
11
+ }
12
+ /**
13
+ * Given a ProseMirror document and a node type, returns the attributes of the given node type for
14
+ * all the nodes in the document. This is based on the official implementation for the
15
+ * `findChildren` helper function.
16
+ */
17
+ function getAllNodesAttributesByType(doc, nodeType) {
18
+ const result = [];
19
+ doc.descendants((node) => {
20
+ if (node.type.name === nodeType) {
21
+ result.push(node.attrs);
22
+ }
23
+ });
24
+ return result;
25
+ }
26
+ export { getAllNodesAttributesByType, resolveContentSelection };