@jenkin-a/jeditor 1.0.1 → 1.0.4

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.en.md CHANGED
@@ -2,34 +2,281 @@
2
2
 
3
3
  Language: English | [中文](README.md)
4
4
 
5
- Current version: v1.0.1
5
+ Current version: `v1.0.2`
6
6
 
7
- JEditor is a lightweight rich-text editor built on Tiptap. It uses a plugin-driven toolbar architecture and exposes a simple DOM API (`JEditor.create`). In v1.0.1, two key capabilities are added:
7
+ JEditor is a web rich text editor for document writing, static fragment authoring, and Source HTML editing. It started as a Tiptap-based editor, but the current version is already more than a simple “toolbar + Tiptap wrapper”. It is evolving into a hybrid editing architecture that supports:
8
8
 
9
- - native HTML bootstrapping from an existing container
10
- - self-contained UMD / IIFE browser builds for CDN usage
9
+ - visual document editing
10
+ - Source HTML editing
11
+ - HTML preservation and restoration
12
+ - direct CDN usage in the browser
11
13
 
12
- ![Screenshot](Demo/img.png)
14
+ ![JEditor Screenshot](Demo/img.png)
15
+
16
+ ## Goals
17
+
18
+ JEditor is not only trying to replicate a traditional rich text editor. Its core goal is harder:
19
+
20
+ `Let users edit content like a document while preserving raw HTML as much as possible.`
21
+
22
+ That is the main difference between JEditor and conventional editors:
23
+
24
+ - most editors focus on structured content only
25
+ - JEditor cares about both structured editing and HTML survivability
13
26
 
14
27
  ## Current capabilities
15
- - ESM build for Vite / Webpack / npm projects
16
- - self-contained UMD / IIFE builds for direct browser usage
17
- - native HTML bootstrap from existing container markup
18
- - `textarea` bootstrap with automatic HTML sync
19
- - core text formatting:
20
- - bold
21
- - italic
22
- - underline
23
- - strike
28
+
29
+ The current version already includes:
30
+
31
+ - dual-toolbar editing UI
32
+ - native HTML bootstrap from a container
33
+ - `textarea` bootstrap with automatic sync
34
+ - ESM / UMD / IIFE builds
35
+ - direct CDN integration without npm
36
+ - Source toggle button
37
+ - source editor on the left and high-fidelity preview on the right
38
+ - full HTML document preservation
39
+ - fragment HTML preprocess and restore flow
40
+ - Raw HTML Block placeholders
41
+ - core editing features:
24
42
  - undo / redo
43
+ - format painter
25
44
  - clear format
26
- - image plugin:
27
- - paste images
28
- - base64 insertion
29
- - drag-to-resize
30
- - reserved `uploadUrl` hook
45
+ - heading / paragraph
46
+ - font family / font size
47
+ - bold / italic / underline / strike
48
+ - color
49
+ - blockquote
50
+ - inline code
51
+ - code block
52
+ - lists
53
+ - link
54
+ - table
55
+ - image
56
+ - callout
57
+ - fullscreen
58
+
59
+ ## Architecture overview
60
+
61
+ JEditor now follows a hybrid architecture centered around “Source HTML as the single source of truth”:
62
+
63
+ ```text
64
+ Source HTML
65
+
66
+ Parser / Preprocess
67
+
68
+ Projection
69
+
70
+ Visual Editor (Tiptap)
71
+
72
+ restoreRawHTML()
73
+
74
+ Output HTML
75
+ ```
76
+
77
+ You can think of it as three layers:
78
+
79
+ 1. Source Layer
80
+ - stores the original HTML
81
+ - keeps full documents source-authoritative
82
+ - powers the high-fidelity preview
83
+
84
+ 2. Projection Layer
85
+ - preprocesses HTML before `setContent`
86
+ - sends supported nodes into the schema
87
+ - wraps unknown nodes as `RawHtmlIsland`
88
+
89
+ 3. Visual Layer
90
+ - uses Tiptap for structured editing
91
+ - all toolbar, plugin, command, and selection logic lives here
92
+
93
+ ## Three editing states
94
+
95
+ ### 1. Visual Mode
96
+
97
+ This is the default mode. It is used for structured editing such as writing paragraphs, formatting text, inserting tables, callouts, images, and code blocks.
98
+
99
+ This layer mainly depends on Tiptap for:
100
+
101
+ - selection handling
102
+ - command chains
103
+ - schema
104
+ - history
105
+ - node and mark extensions
106
+
107
+ ### 2. Source Mode
108
+
109
+ Enter it by clicking the `Source` button on the right side of the second toolbar row.
110
+
111
+ The current implementation is:
112
+
113
+ - left: source editor `textarea`
114
+ - right: high-fidelity iframe preview
115
+
116
+ When the content is a full HTML document, JEditor does not force it back through the visual editor. This avoids losing or normalizing:
117
+
118
+ - `<!DOCTYPE html>`
119
+ - `<head>`
120
+ - `<style>`
121
+ - `<script>`
122
+ - the original document structure
123
+
124
+ ### 3. Hybrid / Preservation Flow
125
+
126
+ This is currently the most important layer in JEditor.
127
+
128
+ For fragment HTML, JEditor preprocesses content before `setContent()`:
129
+
130
+ - supported nodes are parsed normally
131
+ - unsupported nodes are wrapped as `raw-html` placeholders
132
+
133
+ When exporting, `restoreRawHTML()` turns them back into their original HTML.
134
+
135
+ The goal is simple:
136
+
137
+ `Unknown HTML may not be editable, but it must not be deleted.`
138
+
139
+ ## Project structure
140
+
141
+ Core source lives under `src`:
142
+
143
+ - `src/jeditor.js`
144
+ - main editor entry
145
+ - controls mode switching, Source flow, HTML sync, and initialization
146
+
147
+ - `src/editor/index.js`
148
+ - creates the Tiptap editor instance
149
+
150
+ - `src/core/plugin-manager.js`
151
+ - central plugin registry and lifecycle manager
152
+
153
+ - `src/core/config.js`
154
+ - default config and user config merging
155
+
156
+ - `src/core/html-preservation.js`
157
+ - `preprocessHTML`
158
+ - `restoreRawHTML`
159
+ - HTML preservation pipeline
160
+
161
+ - `src/toolbar/ui.js`
162
+ - toolbar DOM, popovers, state sync
163
+
164
+ - `src/plugins`
165
+ - all toolbar behaviors and commands
166
+
167
+ - `src/extensions`
168
+ - custom schema / mark / node extensions
169
+
170
+ - `src/styles/editor.css`
171
+ - built-in editor styles
172
+
173
+ ## HTML preservation
174
+
175
+ This is the most important architectural capability in the current version.
176
+
177
+ ### 1. preprocessHTML
178
+
179
+ Runs before `setContent()`.
180
+
181
+ Responsibilities:
182
+
183
+ - walk through input HTML
184
+ - decide whether a node is supported by the current schema
185
+ - convert unsupported nodes into placeholders
186
+
187
+ For example:
188
+
189
+ ```html
190
+ <section style="display:flex">
191
+ <article>...</article>
192
+ </section>
193
+ ```
194
+
195
+ If the current schema cannot fully represent it, JEditor does not drop it. Instead, it converts it into:
196
+
197
+ ```html
198
+ <raw-html data-raw-html="...encoded html..."></raw-html>
199
+ ```
200
+
201
+ ### 2. RawHtmlIsland
202
+
203
+ `RawHtmlIsland` is an indivisible block node.
204
+
205
+ Its job is not to edit arbitrary HTML. Its job is to preserve it.
206
+
207
+ Visually, it is rendered as a visible block instead of an empty node, for example:
208
+
209
+ - Raw HTML Block
210
+ - HTML preserved
211
+
212
+ It currently supports:
213
+
214
+ - double click to jump back to Source
215
+ - copy raw HTML
216
+ - delete block
217
+
218
+ Implementation:
219
+
220
+ - `src/extensions/raw-html-island.js`
221
+
222
+ ### 3. restoreRawHTML
223
+
224
+ Runs during `getHTML()`.
225
+
226
+ Responsibilities:
227
+
228
+ - scan editor output
229
+ - find `raw-html[data-raw-html]`
230
+ - restore the original saved `outerHTML`
231
+
232
+ That means even if some nodes cannot be edited visually, they can still be exported back as their original HTML.
233
+
234
+ ## Schema extension direction
235
+
236
+ The first stage of schema extension has already begun:
237
+
238
+ - `GenericDiv`
239
+ - `GlobalStyle`
240
+ - `RawHtmlIsland`
241
+
242
+ The goal is to gradually support more permissive HTML instead of letting it be removed by a strict schema too early.
243
+
244
+ Next steps will include:
245
+
246
+ - `GenericSpan`
247
+ - finer inline fallback
248
+ - broader unknown-tag preservation
249
+
250
+ ## Plugin system
251
+
252
+ JEditor uses a plugin-driven toolbar and command architecture.
253
+
254
+ A plugin usually contains:
255
+
256
+ - `name`
257
+ - `toolbar`
258
+ - `tiptapExtension`
259
+ - `command`
260
+ - `isActive`
261
+ - `renderPopover`
262
+ - `init / destroy`
263
+
264
+ This gives JEditor a few advantages:
265
+
266
+ - UI and commands stay decoupled
267
+ - toolbar items can be composed by configuration
268
+ - new tools can be added without rewriting the core editor
269
+
270
+ Built-in plugin entry:
271
+
272
+ - `src/plugins/index.js`
273
+
274
+ Plugin manager:
275
+
276
+ - `src/core/plugin-manager.js`
277
+
278
+ ## Install and development
31
279
 
32
- ## Install and develop
33
280
  ```bash
34
281
  npm install
35
282
  npm run dev
@@ -38,57 +285,56 @@ npm run preview
38
285
  ```
39
286
 
40
287
  Build outputs:
288
+
41
289
  - `dist/jeditor.es.js`
42
290
  - `dist/jeditor.umd.js`
43
291
  - `dist/jeditor.iife.js`
44
292
  - `dist/jeditor.css`
45
293
 
46
294
  ## ESM usage
295
+
47
296
  ```js
48
- import 'jeditor/dist/jeditor.css'
297
+ import '@jenkin-a/jeditor/dist/jeditor.css'
49
298
  import { JEditor } from '@jenkin-a/jeditor'
50
299
 
51
- const editor = JEditor.create('#j-editor-container', {
52
- placeholder: 'Start creating...',
300
+ const editor = JEditor.create('#editor', {
301
+ placeholder: 'Start writing...',
53
302
  })
54
303
  ```
55
304
 
56
- You can also create an editor from an HTML string:
57
- ```js
58
- const editor = JEditor.fromHTML('#j-editor-container', '<h2>Hello</h2><p>World</p>')
59
- ```
60
-
61
- If the container already contains HTML, JEditor will parse it automatically:
62
- ```html
63
- <div id="editor">
64
- <h2>Existing HTML</h2>
65
- <p>This will be parsed as the initial content.</p>
66
- </div>
67
- ```
305
+ You can also create from an HTML string:
68
306
 
69
307
  ```js
70
- JEditor.create('#editor')
308
+ const editor = JEditor.fromHTML('#editor', '<h2>Hello</h2><p>World</p>')
71
309
  ```
72
310
 
73
- ## CDN / direct browser usage
311
+ ## CDN / no-npm usage
312
+
74
313
  ```html
75
- <link rel="stylesheet" href="https://unpkg.com/@jenkin-a/jeditor/dist/jeditor.css" />
314
+ <link rel="stylesheet" href="https://unpkg.com/@jenkin-a/jeditor/dist/jeditor.css">
76
315
  <script src="https://unpkg.com/feather-icons"></script>
77
316
  <script src="https://unpkg.com/@jenkin-a/jeditor/dist/jeditor.iife.js"></script>
78
317
 
79
318
  <div id="editor">
80
- <h2>Hello JEditor</h2>
81
- <p>This HTML is parsed on startup.</p>
319
+ <h2>Hello, JEditor</h2>
320
+ <p>The native HTML inside this container will be parsed on startup.</p>
82
321
  </div>
83
322
 
84
323
  <script>
85
- const editor = window.JEditor.create('#editor')
324
+ const editor = window.JEditor.create('#editor', {
325
+ placeholder: 'Start writing...',
326
+ })
86
327
  </script>
87
328
  ```
88
329
 
89
- For a local browser-only example, run `npm run build` and open `Demo/cdn.html`.
330
+ To pin a version:
331
+
332
+ ```html
333
+ <script src="https://unpkg.com/@jenkin-a/jeditor@1.0.2/dist/jeditor.iife.js"></script>
334
+ ```
335
+
336
+ ## API
90
337
 
91
- ## Public API
92
338
  ```js
93
339
  editor.getHTML()
94
340
  editor.getJSON()
@@ -97,25 +343,46 @@ editor.setContent('<p>Hello</p>')
97
343
  editor.importHTML('<p>Hello</p>')
98
344
  editor.focus()
99
345
  editor.destroy()
346
+ editor.toggleSourceMode()
100
347
  ```
101
348
 
102
- ## Dependency notes
103
- The ESM build expects these peer dependencies in your app:
104
- ```bash
105
- npm install @tiptap/core @tiptap/starter-kit @tiptap/extension-underline @tiptap/extension-image @tiptap/pm
106
- ```
349
+ ## Good fit for
350
+
351
+ JEditor is a good fit for:
352
+
353
+ - enterprise knowledge-base editors
354
+ - SOP / notice / documentation workbenches
355
+ - CMS editors that need Source HTML support
356
+ - admin systems that need both visual editing and HTML editing
357
+ - lightweight browser integrations via CDN
107
358
 
108
- The CDN / IIFE build is self-contained and does not require extra Tiptap imports.
359
+ ## Current boundaries
109
360
 
110
- ## Known limitations
111
- - Several toolbar buttons are still placeholders; see `src/plugins/placeholders.js`
112
- - Image upload still defaults to base64; the full `uploadUrl` pipeline is not wired yet
113
- - Source HTML editing mode is planned for the next major feature cycle
361
+ The current version is already strong, but it is still evolving.
114
362
 
115
- ## Roadmap
116
- 1. v1.0.1: native HTML bootstrap + self-contained CDN / IIFE build
117
- 2. v1.1.x: fill core editing features such as headings, lists, alignment, colors, font controls, links, and code blocks
118
- 3. v1.2.x: Source HTML mode with visual HTML switching
363
+ Some current boundaries:
364
+
365
+ - some UI details still need polishing
366
+ - a few toolbar interactions can be refined further
367
+ - complex unknown inline HTML preservation is not final yet
368
+ - Source Mode and Hybrid Mode will continue to evolve
369
+
370
+ ## Next direction
371
+
372
+ The next development direction is clear:
373
+
374
+ 1. expand the schema
375
+ - `GenericSpan`
376
+ - broader style / attr preservation
377
+
378
+ 2. improve Raw HTML preservation
379
+ - finer fallback behavior
380
+ - better import / export restoration
381
+
382
+ 3. strengthen Source / Visual collaboration
383
+ - more stable mode switching
384
+ - deeper Hybrid editing experience
119
385
 
120
386
  ## License
387
+
121
388
  MIT