silk-compose 0.0.1 → 0.0.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/README.md +27 -17
- package/dist/index.d.ts +12 -8
- package/dist/silk.js +398 -392
- package/package.json +5 -14
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ Silk ships as a single component with styles, sensible defaults, and a curated f
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install silk-compose
|
|
11
|
-
@lexical/code-shiki @lexical/history @lexical/link @lexical/list \
|
|
12
|
-
@lexical/markdown @lexical/selection @lexical/dragon
|
|
10
|
+
npm install silk-compose
|
|
13
11
|
```
|
|
14
12
|
|
|
13
|
+
All Lexical dependencies are included automatically.
|
|
14
|
+
|
|
15
15
|
## Quick start
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
@@ -27,19 +27,30 @@ That's it. You get a fully functional editor with formatting, code blocks, lists
|
|
|
27
27
|
|
|
28
28
|
## Saving and restoring content
|
|
29
29
|
|
|
30
|
-
Silk uses Lexical's native serialization. Pass
|
|
30
|
+
Silk uses Lexical's native serialization. Pass a `ref` to get a handle with a `getState()` method that returns the editor content as a JSON string. Pass that string back as `initialEditorState` to restore it.
|
|
31
31
|
|
|
32
32
|
```tsx
|
|
33
|
+
import { useRef } from "react";
|
|
34
|
+
import { SilkEditor } from "silk-compose";
|
|
35
|
+
import type { SilkEditorHandle } from "silk-compose";
|
|
36
|
+
import "silk-compose/styles";
|
|
37
|
+
|
|
33
38
|
function App() {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
)
|
|
39
|
+
const editorRef = useRef<SilkEditorHandle>(null);
|
|
40
|
+
|
|
41
|
+
const handleSave = () => {
|
|
42
|
+
const json = editorRef.current?.getState();
|
|
43
|
+
if (json) saveToDatabase(json);
|
|
44
|
+
};
|
|
37
45
|
|
|
38
46
|
return (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
<>
|
|
48
|
+
<SilkEditor
|
|
49
|
+
ref={editorRef}
|
|
50
|
+
initialEditorState={loadFromDatabase()}
|
|
51
|
+
/>
|
|
52
|
+
<button onClick={handleSave}>Save</button>
|
|
53
|
+
</>
|
|
43
54
|
);
|
|
44
55
|
}
|
|
45
56
|
```
|
|
@@ -50,11 +61,11 @@ The JSON string is a complete snapshot of the document — text, formatting, ima
|
|
|
50
61
|
|
|
51
62
|
| Prop | Type | Default | Description |
|
|
52
63
|
|---|---|---|---|
|
|
64
|
+
| `ref` | `Ref<SilkEditorHandle>` | — | Exposes `getState()` to read the serialized editor content on demand. |
|
|
53
65
|
| `editable` | `boolean` | `true` | Toggle between edit and read-only mode at runtime. |
|
|
54
|
-
| `
|
|
55
|
-
| `initialEditorState` | `string` | — | JSON string from a previous `onChange` to restore content. |
|
|
66
|
+
| `initialEditorState` | `string` | — | JSON string from a previous `getState()` call to restore content. |
|
|
56
67
|
| `features` | `SilkFeatures` | All enabled | Toggle feature groups on/off. |
|
|
57
|
-
| `namespace` | `string` | `"silk-
|
|
68
|
+
| `namespace` | `string` | `"silk-editor"` | Lexical editor namespace. |
|
|
58
69
|
| `className` | `string` | — | Additional CSS class on the container. |
|
|
59
70
|
| `theme` | `EditorThemeClasses` | — | Lexical theme overrides (deep-merged with defaults). |
|
|
60
71
|
| `onError` | `(error: Error) => void` | `console.error` | Error handler for Lexical. |
|
|
@@ -87,7 +98,7 @@ These are not feature-gated and are always available:
|
|
|
87
98
|
- **Horizontal rules** — section dividers
|
|
88
99
|
- **Slash commands** — type `/` to insert headings, code blocks, lists, notes, links, dividers
|
|
89
100
|
- **Markdown shortcuts** — `*`/`-` for bullet lists, `1.` for numbered lists, common text format triggers
|
|
90
|
-
- **Font controls** — size (10
|
|
101
|
+
- **Font controls** — size (10-36), family (Inter, SF Mono, Space Grotesk), and a curated color palette
|
|
91
102
|
- **Read-only mode** — pass `editable={false}` to disable editing; toolbars hide, links become directly clickable
|
|
92
103
|
|
|
93
104
|
## Styling
|
|
@@ -107,7 +118,7 @@ To customize the Lexical theme (class names applied to nodes), pass the `theme`
|
|
|
107
118
|
```tsx
|
|
108
119
|
// Component
|
|
109
120
|
import { SilkEditor } from "silk-compose";
|
|
110
|
-
import type { SilkEditorProps, SilkFeatures } from "silk-compose";
|
|
121
|
+
import type { SilkEditorProps, SilkEditorHandle, SilkFeatures } from "silk-compose";
|
|
111
122
|
|
|
112
123
|
// Nodes (for advanced Lexical integrations)
|
|
113
124
|
import { NoteNode, $createNoteNode, $isNoteNode } from "silk-compose";
|
|
@@ -117,7 +128,6 @@ import { ImageNode, $createImageNode, $isImageNode } from "silk-compose";
|
|
|
117
128
|
## Requirements
|
|
118
129
|
|
|
119
130
|
- React 18 or 19
|
|
120
|
-
- Lexical 0.41+
|
|
121
131
|
|
|
122
132
|
## License
|
|
123
133
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,13 @@ import { DOMExportOutput } from 'lexical';
|
|
|
4
4
|
import { EditorConfig } from 'lexical';
|
|
5
5
|
import { EditorThemeClasses } from 'lexical';
|
|
6
6
|
import { ElementNode } from 'lexical';
|
|
7
|
-
import {
|
|
8
|
-
import { JSX
|
|
7
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
8
|
+
import { JSX } from 'react';
|
|
9
9
|
import { LexicalEditor } from 'lexical';
|
|
10
10
|
import { LexicalNode } from 'lexical';
|
|
11
11
|
import { NodeKey } from 'lexical';
|
|
12
12
|
import { RangeSelection } from 'lexical';
|
|
13
|
+
import { RefAttributes } from 'react';
|
|
13
14
|
import { SerializedElementNode } from 'lexical';
|
|
14
15
|
import { SerializedLexicalNode } from 'lexical';
|
|
15
16
|
import { Spread } from 'lexical';
|
|
@@ -22,7 +23,7 @@ export declare function $isImageNode(node: LexicalNode | null | undefined): node
|
|
|
22
23
|
|
|
23
24
|
export declare function $isNoteNode(node: LexicalNode | null | undefined): node is NoteNode;
|
|
24
25
|
|
|
25
|
-
export declare class ImageNode extends DecoratorNode<
|
|
26
|
+
export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
26
27
|
__src: string;
|
|
27
28
|
__altText: string;
|
|
28
29
|
__width: number | undefined;
|
|
@@ -38,7 +39,7 @@ export declare class ImageNode extends DecoratorNode<JSX_2.Element> {
|
|
|
38
39
|
exportJSON(): SerializedImageNode;
|
|
39
40
|
exportDOM(): DOMExportOutput;
|
|
40
41
|
static importDOM(): DOMConversionMap | null;
|
|
41
|
-
decorate(_editor: LexicalEditor):
|
|
42
|
+
decorate(_editor: LexicalEditor): JSX.Element;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export declare class NoteNode extends ElementNode {
|
|
@@ -69,10 +70,15 @@ declare type SerializedNoteNode = Spread<{
|
|
|
69
70
|
noteType: NoteType;
|
|
70
71
|
}, SerializedElementNode>;
|
|
71
72
|
|
|
72
|
-
declare
|
|
73
|
+
declare const SilkEditor: ForwardRefExoticComponent<SilkEditorProps & RefAttributes<SilkEditorHandle>>;
|
|
73
74
|
export { SilkEditor }
|
|
74
75
|
export default SilkEditor;
|
|
75
76
|
|
|
77
|
+
export declare interface SilkEditorHandle {
|
|
78
|
+
/** Returns the current editor state as a JSON string. */
|
|
79
|
+
getState: () => string;
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
export declare interface SilkEditorProps {
|
|
77
83
|
features?: SilkFeatures;
|
|
78
84
|
namespace?: string;
|
|
@@ -80,9 +86,7 @@ export declare interface SilkEditorProps {
|
|
|
80
86
|
theme?: EditorThemeClasses;
|
|
81
87
|
editable?: boolean;
|
|
82
88
|
onError?: (error: Error) => void;
|
|
83
|
-
/**
|
|
84
|
-
onChange?: (serializedEditorState: string) => void;
|
|
85
|
-
/** JSON string from a previous `onChange` call to restore editor content. */
|
|
89
|
+
/** JSON string from a previous `getState()` call to restore editor content. */
|
|
86
90
|
initialEditorState?: string;
|
|
87
91
|
}
|
|
88
92
|
|