@samhammer/tiptob 2.2.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 +199 -0
- package/dist/extensions.d.ts +11 -0
- package/dist/extensions.js +9728 -0
- package/dist/extensions.js.map +1 -0
- package/dist/plugins/FontHighlight/HighlightExtension.d.ts +1 -0
- package/dist/plugins/Image/ImageExtension.d.ts +2 -0
- package/dist/plugins/KnowledgeMark/KnowledgeMarkExtension.d.ts +25 -0
- package/dist/plugins/Selection/SelectionPlugin.d.ts +2 -0
- package/dist/plugins/Table/TableExtension.d.ts +2 -0
- package/dist/utils/click-outside.d.ts +4 -0
- package/dist/web-components.js +4108 -0
- package/dist/web-components.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Samhammer AG
|
|
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,199 @@
|
|
|
1
|
+
# @samhammer/TipToB
|
|
2
|
+
|
|
3
|
+
TipTap ToolBox (TipToB)
|
|
4
|
+
================================
|
|
5
|
+
|
|
6
|
+
TipToB is a customizable, web component-based toolbox for [TipTap](https://tiptap.dev/). It provides a set of ready-to-use Svelte web components and extensions for building modern, flexible, and framework-agnostic rich text editing experiences.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- **Web Components**: Use editor buttons and menus as custom elements in any framework or plain HTML.
|
|
13
|
+
- **TipTap Extensions**: Includes a set of TipTap extensions for advanced editing features.
|
|
14
|
+
- **Svelte-based**: All UI components are written in Svelte for performance and reactivity.
|
|
15
|
+
- **Customizable**: Easily style and extend the toolbox to fit your needs.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🚀 Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install @samhammer/tiptob
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🛠️ Usage
|
|
28
|
+
|
|
29
|
+
### Using Web Components
|
|
30
|
+
|
|
31
|
+
Import the web components bundle in your application:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import '@samhammer/tiptob/web-components.js';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can now use the provided custom elements in your HTML:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<tiptob-bold-button></tiptob-bold-button>
|
|
41
|
+
<tiptob-italic-button></tiptob-italic-button>
|
|
42
|
+
<tiptob-underline-button></tiptob-underline-button>
|
|
43
|
+
<!-- ...and more -->
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using Extensions
|
|
47
|
+
|
|
48
|
+
Import the extensions bundle to use with your TipTap editor instance:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { ImageExtension, KnowledgeExtension, SelectionDecoration, TableBubbleMenuExtension } from '@samhammer/tiptob/extensions.js';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🧩 Components
|
|
57
|
+
|
|
58
|
+
TipToB provides the following web components:
|
|
59
|
+
|
|
60
|
+
- `<tiptob-bold-button>`
|
|
61
|
+
- `<tiptob-italic-button>`
|
|
62
|
+
- `<tiptob-underline-button>`
|
|
63
|
+
- `<tiptob-bullet-list-button>`
|
|
64
|
+
- `<tiptob-ordered-list-button>`
|
|
65
|
+
- `<tiptob-font-color-button>`
|
|
66
|
+
- `<tiptob-font-highlight-button>`
|
|
67
|
+
- `<tiptob-image-button>`
|
|
68
|
+
- `<tiptob-knowledge-button>`
|
|
69
|
+
- `<tiptob-redo-button>`
|
|
70
|
+
- `<tiptob-undo-button>`
|
|
71
|
+
- `<tiptob-remove-format-button>`
|
|
72
|
+
- `<tiptob-strike-button>`
|
|
73
|
+
- `<tiptob-hyperlink-button>`
|
|
74
|
+
- `<tiptob-table-button>`
|
|
75
|
+
- `<tiptob-table-bubble-menu>`
|
|
76
|
+
- `<tiptob-text-align-button>`
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🧩 Extensions
|
|
81
|
+
|
|
82
|
+
- **ImageExtension**: Add image support to your editor. You need to bind a function that uploads the File to your choosen FileProvider, the function receives a `File` and returns a `Promise<string>`. Example:
|
|
83
|
+
```js
|
|
84
|
+
uploadInlineImage(file: File): Promise<string>;
|
|
85
|
+
```
|
|
86
|
+
- **SelectionDecoration**: Visual selection highlighting.
|
|
87
|
+
- **TableBubbleMenuExtension**: Bubble Menu for table editing support.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## ⚡ Simple TipTap Editor Example
|
|
92
|
+
|
|
93
|
+
Below is a minimal example of initializing a TipTap editor. For more advanced usage and configuration, see the [TipTap documentation](https://tiptap.dev/):
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
import { Editor } from '@tiptap/core';
|
|
97
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
98
|
+
import {
|
|
99
|
+
ImageExtension,
|
|
100
|
+
SelectionDecoration,
|
|
101
|
+
TableBubbleMenuExtension
|
|
102
|
+
} from '@samhammer/tiptob/extensions.js';
|
|
103
|
+
|
|
104
|
+
const editor = new Editor({
|
|
105
|
+
element: document.querySelector('#editor'),
|
|
106
|
+
extensions: [
|
|
107
|
+
StarterKit,
|
|
108
|
+
ImageExtension,
|
|
109
|
+
SelectionDecoration,
|
|
110
|
+
TableBubbleMenuExtension
|
|
111
|
+
],
|
|
112
|
+
content: '<p>Hello World!</p>',
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<div id="editor"></div>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For more details and advanced configuration, visit the [TipTap documentation](https://tiptap.dev/).
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🔗 Binding the Editor Instance to Web Components (Plain JavaScript)
|
|
125
|
+
|
|
126
|
+
TipToB web components require a TipTap editor instance to function. Some components, like the image upload button, also require a callback function for uploading images that returns a string (the image URL). Here is how you can do this in plain JavaScript (example for bold, italic, and image upload buttons):
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import { Editor } from '@tiptap/core';
|
|
130
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
131
|
+
import Bold from '@tiptap/extension-bold';
|
|
132
|
+
import Italic from '@tiptap/extension-italic';
|
|
133
|
+
import { ImageExtension } from '@samhammer/tiptob/extensions.js';
|
|
134
|
+
|
|
135
|
+
// Example image upload function (should return a Promise<string> with the image URL)
|
|
136
|
+
function uploadInlineImage(file) {
|
|
137
|
+
// Replace this with your actual upload logic
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
// Simulate upload and return a dummy URL
|
|
141
|
+
resolve('https://your.cdn.com/' + file.name);
|
|
142
|
+
}, 1000);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const editor = new Editor({
|
|
147
|
+
element: document.querySelector('#editor'),
|
|
148
|
+
extensions: [
|
|
149
|
+
StarterKit,
|
|
150
|
+
Bold,
|
|
151
|
+
Italic,
|
|
152
|
+
ImageExtension(uploadInlineImage)
|
|
153
|
+
],
|
|
154
|
+
content: '<p>Hello World!</p>',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Assign the editor instance to each TipToB custom element
|
|
158
|
+
const boldButton = document.querySelector('tiptob-bold-button');
|
|
159
|
+
boldButton.editor = editor;
|
|
160
|
+
|
|
161
|
+
const italicButton = document.querySelector('tiptob-italic-button');
|
|
162
|
+
italicButton.editor = editor;
|
|
163
|
+
|
|
164
|
+
const imageButton = document.querySelector('tiptob-image-button');
|
|
165
|
+
imageButton.editor = editor;
|
|
166
|
+
imageButton.imageUpload = uploadInlineImage;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```html
|
|
170
|
+
<script type="module" src="@samhammer/tiptob/web-components.js"></script>
|
|
171
|
+
|
|
172
|
+
<div id="editor"></div>
|
|
173
|
+
<tiptob-bold-button></tiptob-bold-button>
|
|
174
|
+
<tiptob-italic-button></tiptob-italic-button>
|
|
175
|
+
<tiptob-image-button></tiptob-image-button>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
> **Note:** For components like `<tiptob-image-button>`, you must provide an `imageUpload` function that returns a Promise resolving to the image URL.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 🎨 Styling
|
|
183
|
+
|
|
184
|
+
TipToB components use CSS custom properties for easy theming. The following variables can be overwritten:
|
|
185
|
+
|
|
186
|
+
```css
|
|
187
|
+
:root {
|
|
188
|
+
--tiptob-bg-button: white;
|
|
189
|
+
--tiptob-bg-button-hover: #e2e2e2;
|
|
190
|
+
--tiptob-bg-button-highlighted: #a6ccf7;
|
|
191
|
+
--tiptob-bg-icon: rgba(37, 39, 45, 0.37);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 📄 License
|
|
198
|
+
|
|
199
|
+
MIT © Samhammer AG
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ImageExtension from "./plugins/Image/ImageExtension";
|
|
2
|
+
import KnowledgeExtension from "./plugins/KnowledgeMark/KnowledgeMarkExtension";
|
|
3
|
+
import { getBubbleMenuExtension as TableBubbleMenuExtension } from "./plugins/Table/TableExtension";
|
|
4
|
+
import { SelectionDecoration } from "./plugins/Selection/SelectionPlugin";
|
|
5
|
+
import type { Editor } from "@tiptap/core";
|
|
6
|
+
import { ExtendedHighlight } from "./plugins/FontHighlight/HighlightExtension";
|
|
7
|
+
interface CustomHTMLElement extends HTMLElement {
|
|
8
|
+
editor: Editor;
|
|
9
|
+
imageUpload: (file: File) => Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
export { ImageExtension, KnowledgeExtension, SelectionDecoration, TableBubbleMenuExtension, ExtendedHighlight, type CustomHTMLElement };
|