@clevertask/scribe 0.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/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/SlashCommandList-DYKFukY8.js +3734 -0
- package/dist/components/Menu/BarMenu.d.ts +7 -0
- package/dist/components/Menu/BarMenu.js +119 -0
- package/dist/components/Menu/BubbleMenu.d.ts +7 -0
- package/dist/components/Menu/BubbleMenu.js +176 -0
- package/dist/components/Scribe/extension/extension-link.d.ts +2 -0
- package/dist/components/Scribe/extension/extension-link.js +934 -0
- package/dist/components/Scribe/extension/extension-selectedText.d.ts +12 -0
- package/dist/components/Scribe/extension/extension-selectedText.js +13 -0
- package/dist/components/Scribe/extension/index.d.ts +2 -0
- package/dist/components/Scribe/extension/index.js +1647 -0
- package/dist/components/Scribe/extension/slashCommand/SlashCommandList.d.ts +5 -0
- package/dist/components/Scribe/extension/slashCommand/SlashCommandList.js +10 -0
- package/dist/components/Scribe/extension/slashCommand/index.d.ts +4 -0
- package/dist/components/Scribe/extension/slashCommand/index.js +154 -0
- package/dist/components/Scribe/extension/slashCommand/items.d.ts +23 -0
- package/dist/components/Scribe/extension/slashCommand/items.js +159 -0
- package/dist/components/Scribe/extension/slashCommand/renderItems.d.ts +8 -0
- package/dist/components/Scribe/extension/slashCommand/renderItems.js +38 -0
- package/dist/components/Scribe/index.d.ts +28 -0
- package/dist/components/Scribe/index.js +92 -0
- package/dist/index-Cu10LNOZ.js +2505 -0
- package/dist/index-CzwFCNeI.js +12114 -0
- package/dist/main.css +1134 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +10 -0
- package/dist/marked.esm-DIt7dqAB.js +1574 -0
- package/dist/purify.es-Bzg5nW_L.js +524 -0
- package/dist/turndown.browser.es-DwgPoVx0.js +646 -0
- package/dist/utils/html-to-markdown.d.ts +1 -0
- package/dist/utils/html-to-markdown.js +11 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/is-in-viewport.d.ts +1 -0
- package/dist/utils/is-in-viewport.js +7 -0
- package/dist/utils/markdown-to-html.d.ts +1 -0
- package/dist/utils/markdown-to-html.js +6 -0
- package/dist/vite-env.d.js +1 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CleverTask
|
|
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,167 @@
|
|
|
1
|
+
# @clevertask/scribe
|
|
2
|
+
|
|
3
|
+
A versatile, block-based rich text editor for diverse applications, built with Tiptap and inspired by Notion's intuitive interface. `@clevertask/scribe` allows you to seamlessly view, create, and edit rich text content, with added support for Markdown parsing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Block-based Editing:** Enjoy a familiar and intuitive Notion-style editing experience.
|
|
8
|
+
- **Markdown Support:** Parse and render Markdown content effortlessly.
|
|
9
|
+
- **Versatile Integration:** Easily integrate `@clevertask/scribe` into any project requiring rich text editing.
|
|
10
|
+
- **View and Edit:** Seamlessly switch between viewing and editing modes.
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [@clevertask/scribe](#clevertaskscribe)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Props](#props)
|
|
18
|
+
- [Helper Functions](#helper-functions)
|
|
19
|
+
- [md2html](#md2html)
|
|
20
|
+
- [html2md](#html2md)
|
|
21
|
+
- [Roadmap](#roadmap)
|
|
22
|
+
- [Release Process](#release-process)
|
|
23
|
+
- [License](#license)
|
|
24
|
+
- [Credits](#credits)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @clevertask/scribe
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Basic usage
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import "@clevertask/scribe/dist/main.css";
|
|
38
|
+
import { Scribe, ScribeOnChangeContents } from "@clevertask/scribe";
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
const onContentChange = useCallback(({ markdownContent, htmlContent, jsonContent }: ScribeOnChangeContents) => {
|
|
42
|
+
console.log(markdownContent, htmlContent, jsonContent);
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
return <Scribe onContentChange={onContentChange} />;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With ref
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import "@clevertask/scribe/dist/main.css";
|
|
53
|
+
import { Scribe, ScribeOnChangeContents } from "@clevertask/scribe";
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
const editor = useRef<ScribeRef>(null);
|
|
57
|
+
|
|
58
|
+
const resetContent = useCallback(() => {
|
|
59
|
+
editor.current.resetContent();
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<Scribe ref={editor} />
|
|
65
|
+
<button onClick={resetContent}>Reset content</button>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Props
|
|
72
|
+
|
|
73
|
+
| Prop | Type | Default | Description |
|
|
74
|
+
| ------------------------ | -------------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
75
|
+
| `content` | `string` | `undefined` | The initial content of the editor. This prop can also be used to control the editor's content. When `content` is updated, the editor's content will be updated accordingly. |
|
|
76
|
+
| `onContentChange` | `(content: ScribeOnChangeContents) => void;` | `undefined` | A callback function triggered whenever the editor's content changes. It receives an object containing the current content in various formats (`jsonContent`, `htmlContent`, `markdownContent`). |
|
|
77
|
+
| `editable` | `boolean` | `true` | Controls whether the editor is editable. |
|
|
78
|
+
| `autoFocus` | `boolean` | `false` | Controls whether the editor should automatically focus when mounted. |
|
|
79
|
+
| `extensions` | `Extension[]` | `undefined` | You can set your own extensions for the text editor. For more information, [check the tip tap extensions docs](https://tiptap.dev/docs/editor/core-concepts/extensions) |
|
|
80
|
+
| `editorProps` | `EditorProps` | `undefined` | A tiptap-based prop to handle advanced use cases, you can read about it on their [documentation](https://tiptap.dev/docs/editor/api/editor#editorprops) |
|
|
81
|
+
| `showBarMenu` | `boolean` | `true` | Determines whether to show the text editor top menu bar or not. This menu bar shows options to format the text |
|
|
82
|
+
| `placeholderText` | `string` | `Type "/" for commands...` | Change the initial placeholder for your text editor |
|
|
83
|
+
| `editorContentStyle` | `React.CSSProperties` | `undefined` | You can send a CSS object to add styles to the editor content container. Useful if you want to limit the editor's height. |
|
|
84
|
+
| `editorContentClassName` | `string` | `undefined` | The same idea of `editorContentStyle` but with classes. |
|
|
85
|
+
| `mainContainerStyle` | `React.CSSProperties` | `undefined` | You can send a CSS object to style the main editor container |
|
|
86
|
+
| `mainContainerClassName` | `string` | `undefined` | The same idea of `mainContainerStyle` but with classes. |
|
|
87
|
+
| `onKeyDown` | `KeyboardEventHandler` | `undefined` | A callback function that is triggered when a key is pressed within the editor. This allows you to handle custom keyboard shortcuts. For example, you can use this prop to implement a "send message" functionality when `Ctrl + Enter` is pressed. |
|
|
88
|
+
|
|
89
|
+
## Helper Functions
|
|
90
|
+
|
|
91
|
+
### `md2html`
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
export declare function md2html(md: string): string;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Convert markdown to html. Useful if you're rendering an AI-based response, or if you were storing content on markdown in your database and want to show it on the text editor. This function sanitizes the content to prevent XSS attacks.
|
|
98
|
+
|
|
99
|
+
**Usage Example**:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { md2html, Scribe } from "@clevertask/scribe";
|
|
103
|
+
import { Flex, Heading } from "@radix-ui/themes";
|
|
104
|
+
import { Message, useChat } from "@ai-sdk/react";
|
|
105
|
+
|
|
106
|
+
const ChatMessages = () => {
|
|
107
|
+
const { messages } = useChat({
|
|
108
|
+
/* For more info, see https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-chat */
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return messages.map((message) => (
|
|
112
|
+
<Flex key={message.id} direction="column" mb="4">
|
|
113
|
+
<Heading size="4">{`${message.role}: `}</Heading>
|
|
114
|
+
<Scribe editable={false} showBarMenu={false} content={md2html(message.content)} />
|
|
115
|
+
</Flex>
|
|
116
|
+
));
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### `html2md`
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
export declare function html2md(html: string): string;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Convert html to markdown. Useful if you want to send a text to an AI model by keeping the text format with markdown. This function sanitizes the content to prevent XSS attacks.
|
|
129
|
+
|
|
130
|
+
**Usage Example**:
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { html2md, Scribe } from "@clevertask/scribe";
|
|
134
|
+
|
|
135
|
+
const md = html2md("<h1>Hello world</h1>"); // Output: # Hello world
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
> **Note**: The Scribe component already exposes a property called `markdownContent` when the `onContentChange` is used. In fact, the `markdownContent` is the output of the usage of the `html2md` function.
|
|
139
|
+
|
|
140
|
+
## Roadmap
|
|
141
|
+
|
|
142
|
+
We're constantly working to improve @clevertask/scribe. Here are some features we're planning to implement:
|
|
143
|
+
|
|
144
|
+
- **New default blocks/extensions:** Such as image, video, callout, and table blocks
|
|
145
|
+
- **E2E tests**: It will ensure this component's working as expected.
|
|
146
|
+
|
|
147
|
+
We're excited about these upcoming features and welcome any feedback or contributions from the community. If you have any suggestions or would like to contribute to any of these features, please open an issue or submit a pull request on our GitHub repository.
|
|
148
|
+
|
|
149
|
+
## Release Process
|
|
150
|
+
|
|
151
|
+
This package is automatically published to npm when a new release is created on GitHub. To create a new release:
|
|
152
|
+
|
|
153
|
+
1. Update the version in `package.json` according to semantic versioning rules.
|
|
154
|
+
2. Commit the version change: `git commit -am "Bump version to x.x.x"`
|
|
155
|
+
3. Create a new tag: `git tag x.x.x`
|
|
156
|
+
4. Push the changes and the tag: `git push && git push --tags`
|
|
157
|
+
5. Go to the GitHub repository and create a new release, selecting the tag you just created.
|
|
158
|
+
|
|
159
|
+
The GitHub Action will automatically build, test, and publish the new version to npm.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT
|
|
164
|
+
|
|
165
|
+
## Credits
|
|
166
|
+
|
|
167
|
+
This project is built on top of the excellent [BlockEditor](https://github.com/Sachin-chaurasiya/BlockEditor) repository by Sachin Chaurasiya. We extend our sincere gratitude for their work. <3
|