@rathkit/rte-svelte 0.0.0 → 0.1.0-alpha.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.
- package/README.md +27 -4
- package/dist/action.d.ts +15 -0
- package/dist/action.js +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/stores.d.ts +6 -0
- package/dist/stores.js +7 -0
- package/package.json +61 -3
package/README.md
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
# @rathkit/rte-svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Alpha** (0.1.0-alpha.0). Not for production: the APIs will change between releases. Published to the `next` tag only.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The editor for Svelte: stores and an action over the headless layer. Svelte's store contract is a plain shape, so this package needs nothing from Svelte itself.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
|
-
npm install @rathkit/rte-svelte@next
|
|
10
|
+
npm install @rathkit/rte-svelte@next @rathkit/rte-core@next @rathkit/rte-headless@next
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
This package has no dependencies of its own. It works with `@rathkit/rte-core`, `@rathkit/rte-headless` (peer dependencies, all optional so that npm installs nothing you did not ask for), so install the ones you use alongside it.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```svelte
|
|
18
|
+
<script>
|
|
19
|
+
import { rteEditor, command } from "@rathkit/rte-svelte";
|
|
20
|
+
let editor;
|
|
21
|
+
$: bold = editor && command(editor, "format.bold");
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<button aria-pressed={$bold?.active} on:click={() => editor.commands.run("format.bold")}>Bold</button>
|
|
25
|
+
<div aria-label="Body" use:rteEditor={{ html: "<p>Hello</p>", onReady: (e) => (editor = e), onChange: (html) => console.log(html) }}></div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## More
|
|
29
|
+
|
|
30
|
+
Documentation: <https://rathkit.com>. Source and issues: <https://github.com/rathkit/rte>. What is checked: [SUPPORT.md](https://github.com/rathkit/rte/blob/main/docs/SUPPORT.md). Changes: [CHANGELOG.md](https://github.com/rathkit/rte/blob/main/CHANGELOG.md). How a release is verified: [VERIFY.md](https://github.com/rathkit/rte/blob/main/docs/VERIFY.md).
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
[Apache-2.0](LICENSE)
|
package/dist/action.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Editor } from "@rathkit/rte-core/dom";
|
|
2
|
+
import { type StandardOptions } from "@rathkit/rte-core/standard";
|
|
3
|
+
export interface RteActionOptions extends Omit<StandardOptions, "element" | "html" | "readOnly"> {
|
|
4
|
+
/** The starting HTML. */
|
|
5
|
+
html?: string;
|
|
6
|
+
readOnly?: boolean;
|
|
7
|
+
/** Called with the HTML after each change that alters it. */
|
|
8
|
+
onChange?: (html: string) => void;
|
|
9
|
+
/** Called once the editor exists. */
|
|
10
|
+
onReady?: (editor: Editor) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function rteEditor(element: HTMLElement, options?: RteActionOptions): {
|
|
13
|
+
update(next: RteActionOptions): void;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
};
|
package/dist/action.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createEditor } from "@rathkit/rte-core/standard";
|
|
2
|
+
export function rteEditor(element, options = {}) {
|
|
3
|
+
const { html, readOnly, onChange: _c, onReady: _r, ...rest } = options;
|
|
4
|
+
const editor = createEditor({ ...rest, element, html: html ?? "", readOnly: readOnly ?? false });
|
|
5
|
+
let latest = options;
|
|
6
|
+
let last = editor.getHtml();
|
|
7
|
+
const stop = editor.subscribe(() => {
|
|
8
|
+
const now = editor.getHtml();
|
|
9
|
+
if (now === last)
|
|
10
|
+
return;
|
|
11
|
+
last = now;
|
|
12
|
+
latest.onChange?.(now);
|
|
13
|
+
});
|
|
14
|
+
options.onReady?.(editor);
|
|
15
|
+
return {
|
|
16
|
+
update(next) {
|
|
17
|
+
latest = next;
|
|
18
|
+
editor.setReadOnly(next.readOnly ?? false);
|
|
19
|
+
},
|
|
20
|
+
destroy() {
|
|
21
|
+
stop();
|
|
22
|
+
editor.destroy();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/stores.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HeadlessEditor, type Readable } from "@rathkit/rte-headless";
|
|
2
|
+
import type { CommandState, EditorSnapshot } from "@rathkit/rte-core";
|
|
3
|
+
/** One command's state: whether it can run, whether it is on, its value. */
|
|
4
|
+
export declare function command(editor: HeadlessEditor, name: string): Readable<CommandState>;
|
|
5
|
+
/** One value worked out from the editor state. Subscribers hear about it only when that value changes. */
|
|
6
|
+
export declare function selector<T>(editor: HeadlessEditor, select: (snapshot: EditorSnapshot) => T, equals?: (a: T, b: T) => boolean): Readable<T>;
|
package/dist/stores.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { commandStore, selectStore, toReadable } from "@rathkit/rte-headless";
|
|
2
|
+
export function command(editor, name) {
|
|
3
|
+
return toReadable(commandStore(editor, name));
|
|
4
|
+
}
|
|
5
|
+
export function selector(editor, select, equals) {
|
|
6
|
+
return toReadable(selectStore(editor, select, equals));
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathkit/rte-svelte",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
|
+
"description": "The editor for Svelte: stores and an action over the headless layer, with no editor or accessibility logic of its own.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rich-text",
|
|
7
|
+
"editor",
|
|
8
|
+
"wysiwyg",
|
|
9
|
+
"contenteditable",
|
|
10
|
+
"zero-dependencies",
|
|
11
|
+
"typescript",
|
|
12
|
+
"svelte",
|
|
13
|
+
"stores"
|
|
14
|
+
],
|
|
5
15
|
"license": "Apache-2.0",
|
|
6
16
|
"homepage": "https://rathkit.com",
|
|
7
17
|
"repository": {
|
|
@@ -12,7 +22,55 @@
|
|
|
12
22
|
"bugs": {
|
|
13
23
|
"url": "https://github.com/rathkit/rte/issues"
|
|
14
24
|
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.14.0"
|
|
29
|
+
},
|
|
15
30
|
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true,
|
|
33
|
+
"tag": "next"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"NOTICE",
|
|
38
|
+
"!dist/**/*.map"
|
|
39
|
+
],
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@rathkit/rte-core": ">=0.1.0-alpha.3 <0.2.0",
|
|
48
|
+
"@rathkit/rte-headless": ">=0.1.0-alpha.3 <0.2.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@rathkit/rte-core": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@rathkit/rte-headless": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@rathkit/rte-core": "workspace:*",
|
|
60
|
+
"@rathkit/rte-headless": "workspace:*"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && tsc -p tsconfig.build.js.json",
|
|
64
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
65
|
+
"test": "node --test \"src/**/*.test.ts\""
|
|
66
|
+
},
|
|
67
|
+
"rathkit": {
|
|
68
|
+
"budgets": [
|
|
69
|
+
{
|
|
70
|
+
"name": "svelte",
|
|
71
|
+
"entry": "dist/index.js",
|
|
72
|
+
"gzipKB": 2
|
|
73
|
+
}
|
|
74
|
+
]
|
|
17
75
|
}
|
|
18
76
|
}
|