@lexion-rte/core 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -0
- package/README.md +89 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
# @lexion-rte/core
|
|
2
2
|
|
|
3
|
-
Headless editor runtime for Lexion.
|
|
3
|
+
Headless editor runtime for the Lexion platform.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
`@lexion-rte/core` provides
|
|
7
|
+
`@lexion-rte/core` provides:
|
|
8
|
+
|
|
9
|
+
- editor state and schema management
|
|
10
|
+
- command registration/execution
|
|
11
|
+
- extension lifecycle hooks (`onCreate`, `onDestroy`)
|
|
12
|
+
- JSON document input/output
|
|
13
|
+
|
|
14
|
+
This package does not render UI by itself. Pair it with `@lexion-rte/extensions` and optionally an adapter package.
|
|
8
15
|
|
|
9
16
|
## Install
|
|
10
17
|
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @lexion-rte/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Typical pairing:
|
|
23
|
+
|
|
11
24
|
```bash
|
|
12
25
|
pnpm add @lexion-rte/core @lexion-rte/extensions
|
|
13
26
|
```
|
|
14
27
|
|
|
15
|
-
##
|
|
28
|
+
## Quick Start
|
|
16
29
|
|
|
17
30
|
```ts
|
|
18
31
|
import { LexionEditor } from "@lexion-rte/core";
|
|
@@ -23,7 +36,77 @@ const editor = new LexionEditor({
|
|
|
23
36
|
});
|
|
24
37
|
|
|
25
38
|
editor.execute(starterKitCommandNames.toggleBold);
|
|
26
|
-
|
|
27
|
-
console.log(json.type);
|
|
39
|
+
console.log(editor.getJSON());
|
|
28
40
|
```
|
|
29
41
|
|
|
42
|
+
## Editor Options
|
|
43
|
+
|
|
44
|
+
`LexionEditor` accepts:
|
|
45
|
+
|
|
46
|
+
- `schema?: Schema`
|
|
47
|
+
- `doc?: JSONDocument`
|
|
48
|
+
- `extensions?: LexionExtension[]`
|
|
49
|
+
- `plugins?: LexionPlugin[]` (alias for extensions)
|
|
50
|
+
- `commands?: CommandMap`
|
|
51
|
+
|
|
52
|
+
## Core API
|
|
53
|
+
|
|
54
|
+
Main instance members:
|
|
55
|
+
|
|
56
|
+
- `schema`
|
|
57
|
+
- `state`
|
|
58
|
+
- `doc`
|
|
59
|
+
- `getJSON()`
|
|
60
|
+
- `setJSON(document)`
|
|
61
|
+
- `dispatchTransaction(transaction)`
|
|
62
|
+
- `execute(command, ...args)`
|
|
63
|
+
- `registerCommand(name, handler)`
|
|
64
|
+
- `unregisterCommand(name)`
|
|
65
|
+
- `use(extension)`
|
|
66
|
+
- `removePlugin(key)`
|
|
67
|
+
- `destroy()`
|
|
68
|
+
|
|
69
|
+
## Custom Command Example
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { LexionEditor } from "@lexion-rte/core";
|
|
73
|
+
import { starterKitExtension } from "@lexion-rte/extensions";
|
|
74
|
+
|
|
75
|
+
const editor = new LexionEditor({ extensions: [starterKitExtension] });
|
|
76
|
+
|
|
77
|
+
editor.registerCommand("insertTimestamp", ({ state, dispatch }) => {
|
|
78
|
+
const { from, to } = state.selection;
|
|
79
|
+
dispatch(state.tr.insertText(new Date().toISOString(), from, to));
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
editor.execute("insertTimestamp");
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Extension Lifecycle Example
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import type { LexionExtension } from "@lexion-rte/core";
|
|
90
|
+
|
|
91
|
+
const auditExtension: LexionExtension = {
|
|
92
|
+
key: "audit",
|
|
93
|
+
onCreate: ({ editor }) => {
|
|
94
|
+
console.log("created", editor.getJSON());
|
|
95
|
+
},
|
|
96
|
+
onDestroy: () => {
|
|
97
|
+
console.log("destroyed");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Error Behavior
|
|
103
|
+
|
|
104
|
+
- Executing an unknown command throws `Unknown command: <name>`.
|
|
105
|
+
- Using an editor after `destroy()` throws an error.
|
|
106
|
+
- Registering duplicate command names throws.
|
|
107
|
+
|
|
108
|
+
## Related Packages
|
|
109
|
+
|
|
110
|
+
- `@lexion-rte/extensions` for starter-kit, AI, and collaboration features
|
|
111
|
+
- `@lexion-rte/tools` for HTML/text conversions
|
|
112
|
+
- adapter packages (`web`, `react`, `vue`, etc.) for UI integration
|