@flexiui/svelte-rich-text 0.0.1 → 0.0.3

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 (2) hide show
  1. package/README.md +63 -0
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -181,4 +181,67 @@ You can add custom extensions to the editor by passing them as an array to the `
181
181
 
182
182
  In this example, the `SpecialBox` extension is imported from a file called `SpecialBox.ts` in the `editor/custom-extensions` directory.
183
183
 
184
+ In this case, the `SpecialBox` extension is a custom "Mark" that adds a special box inline node to the editor.
185
+
186
+ ```ts
187
+ import { Mark } from "@tiptap/core";
188
+
189
+ declare module '@tiptap/core' {
190
+ interface Commands<ReturnType> {
191
+ specialBox: {
192
+ specialBox: () => ReturnType
193
+ isActive: (options: any) => ReturnType
194
+ }
195
+ }
196
+ }
197
+
198
+ export const SpecialBox = Mark.create({
199
+ name: "specialBox",
200
+ excludes: 'code highlight',
201
+
202
+ parseHTML() {
203
+ return [
204
+ {
205
+ tag: "span[data-special-box]",
206
+ },
207
+ ];
208
+ },
209
+
210
+ renderHTML({ HTMLAttributes }) {
211
+ return [
212
+ "span",
213
+ {
214
+ "class": "special-box",
215
+ "data-special-box": "true",
216
+ style: "line-height: 1.5;",
217
+ },
218
+ 0,
219
+ ];
220
+ },
221
+
222
+ addCommands(): any {
223
+ return {
224
+ specialBox: () => ({ commands }: any) => {
225
+ return commands.toggleMark(this.name);
226
+ },
227
+ isActive: (options: any) => {
228
+ return options.type === this.name;
229
+ },
230
+ };
231
+ },
232
+ });
233
+ ```
234
+
235
+ In this example, the `SpecialBox` extension defines a custom "Mark" that adds a special box inline node to the editor.
236
+
237
+ The `parseHTML` method defines the HTML structure of the special box node. In this case, the node is a `<span>` element with a `data-special-box` attribute.
238
+
239
+ The `renderHTML` method defines the HTML structure of the special box node. In this case, the node is a `<span>` element with a `data-special-box` attribute and a `special-box` class.
240
+
241
+ The `addCommands` method defines the commands for the special box node. In this case, the `specialBox` command toggles the mark on the selected text.
242
+
243
+ The `isActive` method defines the logic for determining whether the special box node is active or not. In this case, the node is active if the selected text has the `specialBox` mark.
244
+
245
+ You can customize the behavior of the special box node by modifying the `SpecialBox` extension as needed.
246
+
184
247
  More information about custom nodes, marks and extensions can be found in the [Tiptap documentation](https://tiptap.dev/docs/editor/extensions/custom-extensions/create-new).
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",
7
7
  "rich text",
8
8
  "editor",
9
9
  "wysiwyg",
10
- "flexiui"
10
+ "flexiui",
11
+ "text editor",
12
+ "tiptap",
13
+ "prosemirror"
11
14
  ],
12
15
  "type": "module",
13
16
  "scripts": {
@@ -38,6 +41,7 @@
38
41
  "dependencies": {
39
42
  "@flexiui/svelte-dropdown": "^0.4.0",
40
43
  "@tiptap/core": "^3.0.9",
44
+ "@tiptap/extension-highlight": "^3.6.6",
41
45
  "@tiptap/extension-text-align": "^3.6.6",
42
46
  "@tiptap/extension-text-style": "^3.0.9",
43
47
  "@tiptap/pm": "^3.0.9",