@oix1987/yjd 1.0.3 → 2.0.0
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/LICENSE +15 -0
- package/README.md +146 -142
- package/core.js +77 -0
- package/dist/core.esm.js +2 -0
- package/dist/core.esm.js.map +1 -0
- package/dist/rich-editor.esm.js +1 -1
- package/dist/rich-editor.esm.js.map +1 -1
- package/dist/rich-editor.min.js +1 -1
- package/dist/rich-editor.min.js.map +1 -1
- package/index.d.ts +134 -103
- package/index.js +227 -0
- package/lib/core/editor.js +1806 -0
- package/lib/core/format.js +540 -0
- package/lib/core/module.js +81 -0
- package/lib/core/registry.js +158 -0
- package/lib/formats/background.js +213 -0
- package/lib/formats/bold.js +49 -0
- package/lib/formats/capitalization.js +579 -0
- package/lib/formats/color.js +183 -0
- package/lib/formats/emoji.js +282 -0
- package/lib/formats/font-family.js +548 -0
- package/lib/formats/heading.js +502 -0
- package/lib/formats/image.js +347 -0
- package/lib/formats/import.js +385 -0
- package/lib/formats/indent.js +297 -0
- package/lib/formats/italic.js +27 -0
- package/lib/formats/line-height.js +562 -0
- package/lib/formats/link.js +251 -0
- package/lib/formats/list.js +635 -0
- package/lib/formats/strike.js +31 -0
- package/lib/formats/subscript.js +40 -0
- package/lib/formats/superscript.js +39 -0
- package/lib/formats/table.js +293 -0
- package/lib/formats/tag.js +304 -0
- package/lib/formats/text-align.js +422 -0
- package/lib/formats/text-size.js +498 -0
- package/lib/formats/underline.js +30 -0
- package/lib/formats/video.js +381 -0
- package/lib/modules/block-toolbar.js +639 -0
- package/lib/modules/code-view.js +447 -0
- package/lib/modules/find-replace.js +273 -0
- package/lib/modules/history.js +425 -0
- package/lib/modules/resize-handles.js +701 -0
- package/lib/modules/slash-menu.js +183 -0
- package/lib/modules/table-toolbar.js +635 -0
- package/lib/modules/toolbar.js +607 -0
- package/lib/styles-loader.js +142 -0
- package/{dist → lib}/styles.css +1285 -35
- package/lib/styles.css.js +2 -0
- package/lib/styles.min.css +1 -0
- package/lib/ui/color-picker.js +296 -0
- package/lib/ui/customselect.js +351 -0
- package/lib/ui/emoji-picker.js +196 -0
- package/lib/ui/icons.js +145 -0
- package/lib/ui/image-popup.js +435 -0
- package/lib/ui/import-popup.js +288 -0
- package/lib/ui/link-popup.js +139 -0
- package/lib/ui/list-picker.js +307 -0
- package/lib/ui/select-button.js +68 -0
- package/lib/ui/table-popup.js +171 -0
- package/lib/ui/tag-popup.js +249 -0
- package/lib/ui/text-align-picker.js +278 -0
- package/lib/ui/video-popup.js +413 -0
- package/lib/utils/exec-command.js +72 -0
- package/lib/utils/history-helper.js +50 -0
- package/lib/utils/popup-helper.js +219 -0
- package/lib/utils/popup-positioning.js +234 -0
- package/lib/utils/sanitize.js +164 -0
- package/package.json +51 -32
- package/umd-entry.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Oix1987
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,142 +1,146 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<script
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
# yjd
|
|
2
|
+
|
|
3
|
+
**Rich text, without the weight.** A dependency-free, tree-shakeable rich text editor for the web. Compose it from a `/core` entry and ship **16 KB**, not the whole library.
|
|
4
|
+
|
|
5
|
+
🔗 **[yjd.io](https://yjd.io)** · [Live playground](https://yjd.io/demos/) · [Docs](https://yjd.io/site/docs.html)
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import RichEditor from '@oix1987/yjd';
|
|
9
|
+
new RichEditor('#editor', { placeholder: 'Start writing…' });
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Why yjd
|
|
15
|
+
|
|
16
|
+
- **Tree-shakeable core** — register only the formats/modules you use; the rest is dropped.
|
|
17
|
+
- **Zero runtime dependencies** — plain DOM, ESM + UMD builds.
|
|
18
|
+
- **Framework-agnostic** — drop it into React, Vue, Svelte, or a static page.
|
|
19
|
+
- **Responsive** — toolbar fills the width on desktop, a single swipe-row on mobile.
|
|
20
|
+
- **XSS-safe paste** — sanitises pasted HTML (scripts/handlers/unsafe URLs stripped; only trusted embeds survive).
|
|
21
|
+
- **Accessible** — keyboard navigable, WCAG-AA contrast (Lighthouse a11y 100).
|
|
22
|
+
|
|
23
|
+
## Bundle size (gzipped JS)
|
|
24
|
+
|
|
25
|
+
Every preset is built from the same `/core` entry — pick a profile, tree-shake the rest.
|
|
26
|
+
|
|
27
|
+
| Preset | Includes | Size |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| Minimal | bold · italic · underline · link | **~16 KB** |
|
|
30
|
+
| Bubble | floating bar, no toolbar + slash menu | **~21 KB** |
|
|
31
|
+
| Basic | + strike · headings · lists · align | **~25 KB** |
|
|
32
|
+
| Standard | + colour · image · table · find · code view | **~38 KB** |
|
|
33
|
+
| Full | everything (CSS inlined) | **~54 KB** |
|
|
34
|
+
|
|
35
|
+
> For comparison, Quill 2 is ~60 KB. The stylesheet (~8 KB gzip) ships once and is cached, kept out of the JS.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm i @oix1987/yjd
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or via CDN (all-in-one UMD):
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@oix1987/yjd/lib/styles.min.css">
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/npm/@oix1987/yjd"></script>
|
|
48
|
+
<script> new RichEditor('#editor'); </script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick start (all-in-one)
|
|
52
|
+
|
|
53
|
+
The default build registers everything and injects its CSS:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import RichEditor from '@oix1987/yjd';
|
|
57
|
+
|
|
58
|
+
const editor = new RichEditor('#editor', {
|
|
59
|
+
placeholder: 'Start writing…',
|
|
60
|
+
onChange: (html) => console.log(html),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Tree-shakeable core
|
|
65
|
+
|
|
66
|
+
For the smallest bundle, import from `@oix1987/yjd/core` (side-effect-free) and register only what you need. Link the stylesheet once.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import { Editor, registry, Bold, Italic, Underline, Link, Toolbar, History }
|
|
70
|
+
from '@oix1987/yjd/core';
|
|
71
|
+
|
|
72
|
+
registry.register('formats/bold', Bold);
|
|
73
|
+
registry.register('formats/italic', Italic);
|
|
74
|
+
registry.register('formats/underline', Underline);
|
|
75
|
+
registry.register('formats/link', Link);
|
|
76
|
+
registry.register('modules/toolbar', Toolbar);
|
|
77
|
+
registry.register('modules/history', History);
|
|
78
|
+
|
|
79
|
+
new Editor('#editor', {
|
|
80
|
+
formats: ['bold', 'italic', 'underline', 'link'],
|
|
81
|
+
modules: ['toolbar', 'history'],
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<link rel="stylesheet" href="@oix1987/yjd/lib/styles.min.css">
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Options
|
|
90
|
+
|
|
91
|
+
| Option | Type | Description |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `placeholder` | string | Empty-state text. |
|
|
94
|
+
| `content` | string | Initial HTML. |
|
|
95
|
+
| `width` / `maxWidth` | number|string | Number = px; string (e.g. `'100%'`) = responsive. |
|
|
96
|
+
| `height` / `maxHeight` | number | Editor body height in px. |
|
|
97
|
+
| `onChange` | fn(html) | Called on every content change. |
|
|
98
|
+
| `toolbar1` / `toolbar2` | array | Toolbar groups: `{ group, items: [] }`. |
|
|
99
|
+
| `formats` / `modules` | string[] | Which registered features to activate. |
|
|
100
|
+
| `features` | object | `{ wordCount, breadcrumb, … }` — toggle the status bar. |
|
|
101
|
+
| `maxLength` | number | Hard character limit. |
|
|
102
|
+
|
|
103
|
+
## Formats & modules
|
|
104
|
+
|
|
105
|
+
**Formats** — `bold` · `italic` · `underline` · `strike` · `subscript` · `superscript` · `color` · `background` · `link` · `heading` · `font-family` · `text-size` · `line-height` · `capitalization` · `text-align` · `list` · `indent-increase` · `indent-decrease` · `image` · `video` · `table` · `emoji` · `tag`
|
|
106
|
+
|
|
107
|
+
**Modules** — `toolbar` · `history` · `slash-menu` · `block-toolbar` (bubble bar) · `table-toolbar` · `find-replace` · `code-view` · `resize-handles`
|
|
108
|
+
|
|
109
|
+
## Methods
|
|
110
|
+
|
|
111
|
+
`getHTML()` · `getText()` · `insertHTML(html)` · `insertText(t)` · `clear()` · `isEmpty()` · `focus()` · `setReadOnly(bool)` · `undo()` · `redo()`
|
|
112
|
+
|
|
113
|
+
## Styling
|
|
114
|
+
|
|
115
|
+
Theme via CSS custom properties:
|
|
116
|
+
|
|
117
|
+
```css
|
|
118
|
+
.yjd-rich-editor {
|
|
119
|
+
--rte-accent: #6d5efc; /* primary */
|
|
120
|
+
--rte-ink: #20242f; /* text */
|
|
121
|
+
--rte-radius: 14px;
|
|
122
|
+
--rte-border: #e9e9f1;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install
|
|
130
|
+
npm run build # dist/ (UMD + ESM) + bundled /core; regenerates CSS
|
|
131
|
+
npm test # unit tests (sanitize, exec-command)
|
|
132
|
+
npm run build:demos # preset demo bundles
|
|
133
|
+
|
|
134
|
+
# Static site (landing + docs + playground) for Cloudflare Pages
|
|
135
|
+
npm run build:pages # build + assemble ./public
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Deploy to Cloudflare Pages (yjd.io)
|
|
139
|
+
|
|
140
|
+
- **Build command:** `npm run build:pages`
|
|
141
|
+
- **Output directory:** `public`
|
|
142
|
+
- Add `yjd.io` as a custom domain in the Pages project.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
ISC
|
package/core.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-shakeable entry point.
|
|
3
|
+
*
|
|
4
|
+
* Unlike the default entry (./index.js) — which registers every format/module
|
|
5
|
+
* and injects the stylesheet on import (convenient, but pulls the whole editor)
|
|
6
|
+
* — this entry only RE-EXPORTS classes with no side effects. A bundler can drop
|
|
7
|
+
* anything you don't import.
|
|
8
|
+
*
|
|
9
|
+
* Usage (only what you need ends up in your bundle):
|
|
10
|
+
*
|
|
11
|
+
* import { Editor, registry, StylesLoader, Bold, Italic, Toolbar, History }
|
|
12
|
+
* from '@oix1987/yjd/core';
|
|
13
|
+
* StylesLoader.loadStyles();
|
|
14
|
+
* registry.register('formats/bold', Bold);
|
|
15
|
+
* registry.register('formats/italic', Italic);
|
|
16
|
+
* registry.register('modules/toolbar', Toolbar);
|
|
17
|
+
* registry.register('modules/history', History);
|
|
18
|
+
* const editor = new Editor('#app', {
|
|
19
|
+
* formats: ['bold', 'italic'],
|
|
20
|
+
* modules: ['toolbar', 'history'],
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Core
|
|
25
|
+
export { default as Editor } from './lib/core/editor.js';
|
|
26
|
+
export { default as Module } from './lib/core/module.js';
|
|
27
|
+
export { Format, InlineFormat, BlockFormat } from './lib/core/format.js';
|
|
28
|
+
export { default as registry } from './lib/core/registry.js';
|
|
29
|
+
export { default as StylesLoader } from './lib/styles-loader.js';
|
|
30
|
+
|
|
31
|
+
// Formats
|
|
32
|
+
export { default as Bold } from './lib/formats/bold.js';
|
|
33
|
+
export { default as Italic } from './lib/formats/italic.js';
|
|
34
|
+
export { default as Underline } from './lib/formats/underline.js';
|
|
35
|
+
export { default as Strike } from './lib/formats/strike.js';
|
|
36
|
+
export { default as Subscript } from './lib/formats/subscript.js';
|
|
37
|
+
export { default as Superscript } from './lib/formats/superscript.js';
|
|
38
|
+
export { default as Color } from './lib/formats/color.js';
|
|
39
|
+
export { default as Background } from './lib/formats/background.js';
|
|
40
|
+
export { default as Link } from './lib/formats/link.js';
|
|
41
|
+
export { default as Table } from './lib/formats/table.js';
|
|
42
|
+
export { default as Heading } from './lib/formats/heading.js';
|
|
43
|
+
export { default as FontFamily } from './lib/formats/font-family.js';
|
|
44
|
+
export { default as LineHeight } from './lib/formats/line-height.js';
|
|
45
|
+
export { default as Capitalization } from './lib/formats/capitalization.js';
|
|
46
|
+
export { default as TextAlign } from './lib/formats/text-align.js';
|
|
47
|
+
export { default as List } from './lib/formats/list.js';
|
|
48
|
+
export { default as Indent, IndentIncrease, IndentDecrease } from './lib/formats/indent.js';
|
|
49
|
+
export { default as Emoji } from './lib/formats/emoji.js';
|
|
50
|
+
export { default as Image } from './lib/formats/image.js';
|
|
51
|
+
export { default as Video } from './lib/formats/video.js';
|
|
52
|
+
export { default as Tag } from './lib/formats/tag.js';
|
|
53
|
+
export { default as TextSize } from './lib/formats/text-size.js';
|
|
54
|
+
export { default as Import } from './lib/formats/import.js';
|
|
55
|
+
|
|
56
|
+
// Modules
|
|
57
|
+
export { default as Toolbar } from './lib/modules/toolbar.js';
|
|
58
|
+
export { default as History } from './lib/modules/history.js';
|
|
59
|
+
export { default as BlockToolbar } from './lib/modules/block-toolbar.js';
|
|
60
|
+
export { default as TableToolbar } from './lib/modules/table-toolbar.js';
|
|
61
|
+
export { default as CodeView } from './lib/modules/code-view.js';
|
|
62
|
+
export { default as FindReplace } from './lib/modules/find-replace.js';
|
|
63
|
+
export { default as SlashMenu } from './lib/modules/slash-menu.js';
|
|
64
|
+
export { default as ResizeHandles } from './lib/modules/resize-handles.js';
|
|
65
|
+
|
|
66
|
+
// UI
|
|
67
|
+
export { default as IconUtils } from './lib/ui/icons.js';
|
|
68
|
+
export { default as ColorPicker } from './lib/ui/color-picker.js';
|
|
69
|
+
export { default as LinkPopup } from './lib/ui/link-popup.js';
|
|
70
|
+
export { default as TablePopup } from './lib/ui/table-popup.js';
|
|
71
|
+
export { default as TextAlignPicker } from './lib/ui/text-align-picker.js';
|
|
72
|
+
export { default as ListPicker } from './lib/ui/list-picker.js';
|
|
73
|
+
export { default as EmojiPicker } from './lib/ui/emoji-picker.js';
|
|
74
|
+
export { default as ImagePopup } from './lib/ui/image-popup.js';
|
|
75
|
+
export { default as VideoPopup } from './lib/ui/video-popup.js';
|
|
76
|
+
export { default as TagPopup } from './lib/ui/tag-popup.js';
|
|
77
|
+
export { default as createCustomButton } from './lib/ui/select-button.js';
|