@samhammer/tiptob 2.3.0 → 2.3.1

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/README.md CHANGED
@@ -1,199 +1,193 @@
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
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';
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🧩 Components
57
+
58
+
59
+ TipToB provides the following web components:
60
+
61
+ | Web Component | Required TipTap Extension(s) and Import |
62
+ |-----------------------------|---------------------------------------------|
63
+ | `<tiptob-bold-button>` | `@tiptap/extension-bold (Bold)` |
64
+ | `<tiptob-italic-button>` | `@tiptap/extension-italic (Italic)` |
65
+ | `<tiptob-underline-button>` | `@tiptap/extension-underline (Underline)` |
66
+ | `<tiptob-strike-button>` | `@tiptap/extension-strike (Strike)` |
67
+ | `<tiptob-bullet-list-button>`| `@tiptap/extension-list (ListKit)` |
68
+ | `<tiptob-ordered-list-button>`| `@tiptap/extension-list (ListKit)`|
69
+ | `<tiptob-font-color-button>`| `@tiptap/extension-color (Color)`, `@tiptap/extension-text-style (TextStyleKit)` |
70
+ | `<tiptob-font-highlight-button>`| `HighlightExtension` (from TipToB), `@tiptap/extension-text-style (TextStyleKit)` |
71
+ | `<tiptob-image-button>` | `ImageExtension` (from TipToB) |
72
+ | `<tiptob-redo-button>` | `@tiptap/extensions (UndoRedo)` |
73
+ | `<tiptob-undo-button>` | `@tiptap/extensions (UndoRedo)` |
74
+ | `<tiptob-remove-format-button>`||
75
+ | `<tiptob-hyperlink-button>` | `@tiptap/extension-link (Link)` |
76
+ | `<tiptob-table-button>` | `@tiptap/extension-table (Table, TableCell, TableHeader, TableRow)`|
77
+ | `<tiptob-table-bubble-menu>`| `TableBubbleMenuExtension` (from TipToB), `@tiptap/extension-table (Table, TableCell, TableHeader, TableRow)` |
78
+ | `<tiptob-text-align-button>`| `@tiptap/extension-text-align (TextAlign)` |
79
+
80
+ ---
81
+
82
+ ## 🧩 Extensions
83
+
84
+ - **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:
85
+ ```js
86
+ uploadInlineImage(file: File): Promise<string>;
87
+ ```
88
+ - **TableBubbleMenuExtension**: Bubble Menu for table editing support.
89
+
90
+ ---
91
+
92
+ ## ⚡ Simple TipTap Editor Example
93
+
94
+ Below is a minimal example of initializing a TipTap editor. For more advanced usage and configuration, see the [TipTap documentation](https://tiptap.dev/):
95
+
96
+ ```js
97
+ import { Editor } from '@tiptap/core';
98
+ import StarterKit from '@tiptap/starter-kit';
99
+
100
+
101
+ const editor = new Editor({
102
+ element: document.querySelector('.editor'),
103
+ extensions: [
104
+ StarterKit,
105
+ ],
106
+ content: '<p>Hello World!</p>',
107
+ });
108
+ ```
109
+
110
+ ```html
111
+ <div class="editor"></div>
112
+ ```
113
+
114
+ For more details and advanced configuration, visit the [TipTap documentation](https://tiptap.dev/).
115
+
116
+ ---
117
+
118
+ ## 🔗 Binding the Editor Instance to Web Components (Plain JavaScript)
119
+
120
+ 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):
121
+
122
+ ```js
123
+ import { Editor } from '@tiptap/core';
124
+ import StarterKit from '@tiptap/starter-kit';
125
+ import Bold from '@tiptap/extension-bold';
126
+ import Italic from '@tiptap/extension-italic';
127
+ import { ImageExtension } from '@samhammer/tiptob/extensions.js';
128
+
129
+ // Example image upload function (should return a Promise<string> with the image URL)
130
+ function uploadInlineImage(file) {
131
+ // Replace this with your actual upload logic
132
+ return new Promise((resolve) => {
133
+ setTimeout(() => {
134
+ // Simulate upload and return a dummy URL
135
+ resolve('https://your.cdn.com/' + file.name);
136
+ }, 1000);
137
+ });
138
+ }
139
+
140
+ const editor = new Editor({
141
+ element: document.querySelector('#editor'),
142
+ extensions: [
143
+ StarterKit,
144
+ Bold,
145
+ Italic,
146
+ ImageExtension(uploadInlineImage)
147
+ ],
148
+ content: '<p>Hello World!</p>',
149
+ });
150
+
151
+ // Assign the editor instance to each TipToB custom element
152
+ const boldButton = document.querySelector('tiptob-bold-button');
153
+ boldButton.editor = editor;
154
+
155
+ const italicButton = document.querySelector('tiptob-italic-button');
156
+ italicButton.editor = editor;
157
+
158
+ const imageButton = document.querySelector('tiptob-image-button');
159
+ imageButton.editor = editor;
160
+ imageButton.imageUpload = uploadInlineImage;
161
+ ```
162
+
163
+ ```html
164
+ <script type="module" src="@samhammer/tiptob/web-components.js"></script>
165
+
166
+ <div id="editor"></div>
167
+ <tiptob-bold-button></tiptob-bold-button>
168
+ <tiptob-italic-button></tiptob-italic-button>
169
+ <tiptob-image-button></tiptob-image-button>
170
+ ```
171
+
172
+ > **Note:** For components like `<tiptob-image-button>`, you must provide an `imageUpload` function that returns a Promise resolving to the image URL.
173
+
174
+ ---
175
+
176
+ ## 🎨 Styling
177
+
178
+ TipToB components use CSS custom properties for easy theming. The following variables can be overwritten:
179
+
180
+ ```css
181
+ :root {
182
+ --tiptob-bg-button: white;
183
+ --tiptob-bg-button-hover: #e2e2e2;
184
+ --tiptob-bg-button-highlighted: #a6ccf7;
185
+ --tiptob-bg-icon: rgba(37, 39, 45, 0.37);
186
+ }
187
+ ```
188
+
189
+ ---
190
+
191
+ ## 📄 License
192
+
193
+ MIT © Samhammer AG