draftify-react 0.1.3 → 0.1.5
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 +137 -47
- package/dist/draftify-react.es.js +6592 -33803
- package/dist/draftify-react.umd.js +17 -238
- package/index.d.ts +192 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
`draftify-react` is a **fully styled, production-ready React editor** powered by the `draftify` core engine. It provides an out-of-the-box editing experience while preserving the structured, schema-driven philosophy of Draftify.
|
|
6
6
|
|
|
7
7
|
This package focuses purely on **UI and interaction**.
|
|
8
|
-
All document logic
|
|
8
|
+
All document logic, schemas, validation, and export utilities live in `draftify`.
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -13,14 +13,15 @@ All document logic lives in `draftify`.
|
|
|
13
13
|
|
|
14
14
|
`draftify-react` **does not work on its own**.
|
|
15
15
|
|
|
16
|
-
It requires the core engine:
|
|
16
|
+
It requires the Draftify core engine:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
19
|
npm install draftify
|
|
20
20
|
npm install draftify-react
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Both packages must be installed.
|
|
24
|
+
`draftify-react` renders and manipulates **Draftify documents**, but it does not define the document model itself.
|
|
24
25
|
|
|
25
26
|
---
|
|
26
27
|
|
|
@@ -34,6 +35,7 @@ npm install draftify-react
|
|
|
34
35
|
- ✅ Document metadata handling
|
|
35
36
|
- ✅ Preview & editor modes
|
|
36
37
|
- ✅ Clipboard, export & formatting support
|
|
38
|
+
- ✅ Reader component for rendering documents
|
|
37
39
|
- ✅ Zero configuration required to start
|
|
38
40
|
|
|
39
41
|
---
|
|
@@ -46,22 +48,77 @@ npm install draftify draftify-react
|
|
|
46
48
|
|
|
47
49
|
---
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## ❗ Controlled Editor (Very Important)
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
`draftify-react` is a **controlled editor**.
|
|
54
|
+
|
|
55
|
+
This means:
|
|
56
|
+
|
|
57
|
+
- **You own the document state**
|
|
58
|
+
- The editor **does not store blocks internally**
|
|
59
|
+
- You must declare and manage the blocks array yourself
|
|
60
|
+
|
|
61
|
+
This design is intentional. It allows:
|
|
62
|
+
|
|
63
|
+
- Full control over persistence (database, localStorage, APIs)
|
|
64
|
+
- Multiple views of the same document (editor + reader)
|
|
65
|
+
- Easy integration with frameworks and state managers
|
|
66
|
+
- Predictable, debuggable data flow
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Minimal Usage (Required Pattern)
|
|
71
|
+
|
|
72
|
+
This is the **correct and complete** way to use `draftify-react`.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useState } from "react";
|
|
76
|
+
import type { DraftifyBlock } from "draftify";
|
|
77
|
+
import DraftifyReact, { Reader } from "draftify-react";
|
|
53
78
|
import "draftify-react/styles.css";
|
|
54
79
|
|
|
55
80
|
export default function App() {
|
|
81
|
+
const [blocksData, modifyBlocks] = useState<DraftifyBlock[]>([]);
|
|
82
|
+
|
|
56
83
|
return (
|
|
57
|
-
|
|
58
|
-
<DraftifyReact />
|
|
59
|
-
|
|
84
|
+
<>
|
|
85
|
+
<DraftifyReact blocksData={blocksData} modifyBlocks={modifyBlocks} />
|
|
86
|
+
|
|
87
|
+
{/* Render the same document anywhere */}
|
|
88
|
+
<Reader blocksData={blocksData} />
|
|
89
|
+
</>
|
|
60
90
|
);
|
|
61
91
|
}
|
|
62
92
|
```
|
|
63
93
|
|
|
64
|
-
|
|
94
|
+
### What’s happening here
|
|
95
|
+
|
|
96
|
+
- `blocksData` holds the Draftify document
|
|
97
|
+
- `modifyBlocks` is passed to the editor
|
|
98
|
+
- The editor updates state via `modifyBlocks`
|
|
99
|
+
- `Reader` consumes the **same data** to render content
|
|
100
|
+
|
|
101
|
+
There is **one source of truth** for your document.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## TypeScript Users (Recommended)
|
|
106
|
+
|
|
107
|
+
Draftify exposes its schema types via the core package.
|
|
108
|
+
|
|
109
|
+
You should always type your state explicitly:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import type { DraftifyBlock } from "draftify";
|
|
113
|
+
|
|
114
|
+
const [blocksData, modifyBlocks] = useState<DraftifyBlock[]>([]);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This ensures:
|
|
118
|
+
|
|
119
|
+
- Full IntelliSense
|
|
120
|
+
- Compile-time validation
|
|
121
|
+
- Safer integration with APIs and storage layers
|
|
65
122
|
|
|
66
123
|
---
|
|
67
124
|
|
|
@@ -75,29 +132,41 @@ You must import it **once** in your app:
|
|
|
75
132
|
@import "draftify-react/styles.css";
|
|
76
133
|
```
|
|
77
134
|
|
|
135
|
+
or in JavaScript:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import "draftify-react/styles.css";
|
|
139
|
+
```
|
|
140
|
+
|
|
78
141
|
### Tailwind v4 Users
|
|
79
142
|
|
|
80
|
-
|
|
143
|
+
No configuration required.
|
|
81
144
|
All Draftify styles are already compiled and scoped.
|
|
82
145
|
|
|
83
146
|
---
|
|
84
147
|
|
|
85
|
-
##
|
|
148
|
+
## Reader Component
|
|
149
|
+
|
|
150
|
+
`draftify-react` exports a `Reader` component for rendering documents without editing.
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { Reader } from "draftify-react";
|
|
154
|
+
|
|
155
|
+
<Reader blocksData={blocksData} />;
|
|
156
|
+
```
|
|
86
157
|
|
|
87
|
-
|
|
158
|
+
Use cases:
|
|
88
159
|
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
- Copy / export helpers
|
|
94
|
-
- Metadata prompts (title, description, author)
|
|
160
|
+
- Read-only previews
|
|
161
|
+
- Blog posts
|
|
162
|
+
- Exported documents
|
|
163
|
+
- Public-facing content
|
|
95
164
|
|
|
96
|
-
|
|
165
|
+
The `Reader` component **never mutates data**.
|
|
97
166
|
|
|
98
167
|
---
|
|
99
168
|
|
|
100
|
-
## Hooks API
|
|
169
|
+
## Hooks API (Advanced)
|
|
101
170
|
|
|
102
171
|
### `useDraftifyReact`
|
|
103
172
|
|
|
@@ -107,13 +176,47 @@ import { useDraftifyReact } from "draftify-react";
|
|
|
107
176
|
|
|
108
177
|
This hook powers the editor internally and exposes:
|
|
109
178
|
|
|
110
|
-
- Document state
|
|
111
|
-
- Block
|
|
112
|
-
- Block creation & modification helpers
|
|
179
|
+
- Document state helpers
|
|
180
|
+
- Block creation & modification functions
|
|
113
181
|
- Drag & drop handlers
|
|
114
|
-
-
|
|
182
|
+
- View and animation state
|
|
115
183
|
|
|
116
|
-
|
|
184
|
+
This is intended for:
|
|
185
|
+
|
|
186
|
+
- Custom editors
|
|
187
|
+
- Headless integrations
|
|
188
|
+
- Advanced UI wrappers
|
|
189
|
+
|
|
190
|
+
Most users **do not need this hook**.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Collaboration Between Packages
|
|
195
|
+
|
|
196
|
+
Draftify is intentionally split into two layers:
|
|
197
|
+
|
|
198
|
+
### `draftify`
|
|
199
|
+
|
|
200
|
+
- Schema definitions
|
|
201
|
+
- Block types
|
|
202
|
+
- Validation
|
|
203
|
+
- Normalization
|
|
204
|
+
- Clipboard & export helpers
|
|
205
|
+
- Framework-agnostic logic
|
|
206
|
+
|
|
207
|
+
### `draftify-react`
|
|
208
|
+
|
|
209
|
+
- React components
|
|
210
|
+
- UI interactions
|
|
211
|
+
- Animations
|
|
212
|
+
- Styling
|
|
213
|
+
- Editor and Reader views
|
|
214
|
+
|
|
215
|
+
Because of this separation:
|
|
216
|
+
|
|
217
|
+
- `draftify` can be used in **any framework**
|
|
218
|
+
- `draftify-react` can evolve independently
|
|
219
|
+
- You can build alternative UIs without rewriting logic
|
|
117
220
|
|
|
118
221
|
---
|
|
119
222
|
|
|
@@ -131,7 +234,7 @@ draftify-react/
|
|
|
131
234
|
└─ README.md
|
|
132
235
|
```
|
|
133
236
|
|
|
134
|
-
|
|
237
|
+
Only runtime-required files are shipped.
|
|
135
238
|
|
|
136
239
|
---
|
|
137
240
|
|
|
@@ -139,7 +242,7 @@ The distributed package contains only what is required at runtime.
|
|
|
139
242
|
|
|
140
243
|
```ts
|
|
141
244
|
import DraftifyReact from "draftify-react";
|
|
142
|
-
import { useDraftifyReact } from "draftify-react";
|
|
245
|
+
import { Reader, useDraftifyReact } from "draftify-react";
|
|
143
246
|
```
|
|
144
247
|
|
|
145
248
|
Styles:
|
|
@@ -150,36 +253,23 @@ Styles:
|
|
|
150
253
|
|
|
151
254
|
---
|
|
152
255
|
|
|
153
|
-
## Why This Package Exists
|
|
154
|
-
|
|
155
|
-
Draftify was designed with separation of concerns in mind.
|
|
156
|
-
|
|
157
|
-
- `draftify` → **logic, schema, validation, export**
|
|
158
|
-
- `draftify-react` → **UI, interactions, visuals**
|
|
159
|
-
|
|
160
|
-
This allows:
|
|
161
|
-
|
|
162
|
-
- Custom editors without UI constraints
|
|
163
|
-
- Backend usage of Draftify
|
|
164
|
-
- Independent evolution of UI and logic
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
256
|
## When to Use `draftify-react`
|
|
169
257
|
|
|
170
258
|
Use this package if you want:
|
|
171
259
|
|
|
172
|
-
- A complete editor
|
|
173
|
-
- Fast
|
|
174
|
-
-
|
|
260
|
+
- A complete editor UI
|
|
261
|
+
- Fast React integration
|
|
262
|
+
- Full control over document state
|
|
263
|
+
- A clean abstraction over Draftify internals
|
|
175
264
|
|
|
176
|
-
If you want to build your own editor UI, use `draftify` directly.
|
|
265
|
+
If you want to build your own editor UI or use Draftify outside React, use `draftify` directly.
|
|
177
266
|
|
|
178
267
|
---
|
|
179
268
|
|
|
180
269
|
## Compatibility
|
|
181
270
|
|
|
182
271
|
- React ≥ 18
|
|
272
|
+
- TypeScript supported
|
|
183
273
|
- Tailwind v4 supported
|
|
184
274
|
- ESM & UMD builds included
|
|
185
275
|
|