@codeauradev/ngx-wind-editor 1.0.0 → 1.0.1
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/package.json +9 -22
- package/.idea/workspace.xml +0 -120
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -90
- package/dist/package.json +0 -48
- package/ng-package.json +0 -15
- package/scripts/patch-dist.mjs +0 -11
- package/src/catalog.ts +0 -27
- package/src/delta.ts +0 -115
- package/src/html.ts +0 -327
- package/src/public-api.ts +0 -8
- package/src/session.ts +0 -843
- package/src/styles/ngx-wind-editor.css +0 -184
- package/src/surface.ts +0 -499
- package/src/toolbar.ts +0 -53
- package/src/types.ts +0 -69
- package/src/wind-editor.ts +0 -357
- package/src/wind-icon.ts +0 -32
- package/test/editor.test.ts +0 -58
- package/tsconfig.json +0 -27
- /package/{dist/fesm2022 → fesm2022}/codeauradev-ngx-wind-editor.mjs +0 -0
- /package/{dist/fesm2022 → fesm2022}/codeauradev-ngx-wind-editor.mjs.map +0 -0
- /package/{dist/ngx-wind-editor.css → ngx-wind-editor.css} +0 -0
- /package/{dist/types → types}/codeauradev-ngx-wind-editor.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeauradev/ngx-wind-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "WYSIWYG HTML editor for Angular 22, styled with Tailwind CSS v4.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -20,16 +20,17 @@
|
|
|
20
20
|
"styles.css"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"types": "./src/public-api.ts",
|
|
26
|
-
"typings": "./src/public-api.ts",
|
|
23
|
+
"module": "fesm2022/codeauradev-ngx-wind-editor.mjs",
|
|
24
|
+
"typings": "types/codeauradev-ngx-wind-editor.d.ts",
|
|
27
25
|
"exports": {
|
|
28
26
|
".": {
|
|
29
|
-
"types": "./
|
|
30
|
-
"default": "./
|
|
27
|
+
"types": "./types/codeauradev-ngx-wind-editor.d.ts",
|
|
28
|
+
"default": "./fesm2022/codeauradev-ngx-wind-editor.mjs"
|
|
31
29
|
},
|
|
32
|
-
"./styles.css": "./
|
|
30
|
+
"./styles.css": "./ngx-wind-editor.css",
|
|
31
|
+
"./package.json": {
|
|
32
|
+
"default": "./package.json"
|
|
33
|
+
}
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"@angular/core": "^22.0.0",
|
|
@@ -43,19 +44,5 @@
|
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"tslib": "^2.8.1",
|
|
45
46
|
"yjs": "^13.6.27"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@angular/compiler": "22.2.3",
|
|
49
|
-
"@angular/compiler-cli": "22.2.3",
|
|
50
|
-
"@angular/core": "22.2.3",
|
|
51
|
-
"ng-packagr": "22.2.3",
|
|
52
|
-
"rxjs": "7.8.2",
|
|
53
|
-
"tsx": "^4.20.5",
|
|
54
|
-
"typescript": "6.0.3",
|
|
55
|
-
"yjs": "13.6.27"
|
|
56
|
-
},
|
|
57
|
-
"scripts": {
|
|
58
|
-
"build": "ng-packagr -p ng-package.json -c tsconfig.json && node scripts/patch-dist.mjs",
|
|
59
|
-
"test": "tsx --test test/*.test.ts"
|
|
60
47
|
}
|
|
61
48
|
}
|
package/.idea/workspace.xml
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="AutoImportSettings">
|
|
4
|
-
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
-
</component>
|
|
6
|
-
<component name="ChangeListManager">
|
|
7
|
-
<list default="true" id="dddd179b-1b8b-4c78-9e6c-2af59aa46f63" name="Changes" comment="" />
|
|
8
|
-
<option name="SHOW_DIALOG" value="false" />
|
|
9
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
10
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
11
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
12
|
-
</component>
|
|
13
|
-
<component name="EmbeddingIndexingInfo">
|
|
14
|
-
<option name="cachedIndexableFilesCount" value="14" />
|
|
15
|
-
</component>
|
|
16
|
-
<component name="McpProjectServerCommands">
|
|
17
|
-
<commands />
|
|
18
|
-
<urls />
|
|
19
|
-
</component>
|
|
20
|
-
<component name="NextEditCompletionFeaturesState">
|
|
21
|
-
<decayedCancelled>
|
|
22
|
-
<entry key="MS100" value="1.0001115886368703" />
|
|
23
|
-
<entry key="MS500" value="1.1948794499459696" />
|
|
24
|
-
<entry key="S2" value="2.1869433799188776" />
|
|
25
|
-
<entry key="S5" value="2.9825256379321456" />
|
|
26
|
-
<entry key="S10" value="3.41812528727204" />
|
|
27
|
-
<entry key="S30" value="3.786387362660663" />
|
|
28
|
-
<entry key="S60" value="3.8904843964087816" />
|
|
29
|
-
<entry key="M2" value="3.9445442044642562" />
|
|
30
|
-
<entry key="M5" value="3.977647438695401" />
|
|
31
|
-
<entry key="M10" value="3.988795115094321" />
|
|
32
|
-
<entry key="M15" value="3.992523703040572" />
|
|
33
|
-
<entry key="M30" value="3.9962586603670154" />
|
|
34
|
-
<entry key="H1" value="3.998128531586192" />
|
|
35
|
-
<entry key="H2" value="3.999064066042545" />
|
|
36
|
-
<entry key="H4" value="3.9995319830709763" />
|
|
37
|
-
<entry key="D1" value="3.9999219902398804" />
|
|
38
|
-
<entry key="W1" value="3.999988855578615" />
|
|
39
|
-
</decayedCancelled>
|
|
40
|
-
<decayedSelected>
|
|
41
|
-
<entry key="MS100" value="0.0" />
|
|
42
|
-
<entry key="MS500" value="0.0" />
|
|
43
|
-
<entry key="S2" value="0.0" />
|
|
44
|
-
<entry key="S5" value="0.0" />
|
|
45
|
-
<entry key="S10" value="0.0" />
|
|
46
|
-
<entry key="S30" value="0.0" />
|
|
47
|
-
<entry key="S60" value="0.0" />
|
|
48
|
-
<entry key="M2" value="0.0" />
|
|
49
|
-
<entry key="M5" value="0.0" />
|
|
50
|
-
<entry key="M10" value="0.0" />
|
|
51
|
-
<entry key="M15" value="0.0" />
|
|
52
|
-
<entry key="M30" value="0.0" />
|
|
53
|
-
<entry key="H1" value="0.0" />
|
|
54
|
-
<entry key="H2" value="0.0" />
|
|
55
|
-
<entry key="H4" value="0.0" />
|
|
56
|
-
<entry key="D1" value="0.0" />
|
|
57
|
-
<entry key="W1" value="0.0" />
|
|
58
|
-
</decayedSelected>
|
|
59
|
-
<decayedShown>
|
|
60
|
-
<entry key="MS100" value="0.9202903328756359" />
|
|
61
|
-
<entry key="MS500" value="1.1748831837532834" />
|
|
62
|
-
<entry key="S2" value="2.1187503324718144" />
|
|
63
|
-
<entry key="S5" value="2.8806834430249055" />
|
|
64
|
-
<entry key="S10" value="3.3375501941549914" />
|
|
65
|
-
<entry key="S30" value="3.7497962118056876" />
|
|
66
|
-
<entry key="S60" value="3.870711561646617" />
|
|
67
|
-
<entry key="M2" value="3.93426591538041" />
|
|
68
|
-
<entry key="M5" value="3.9734390453964807" />
|
|
69
|
-
<entry key="M10" value="3.9866744803524328" />
|
|
70
|
-
<entry key="M15" value="3.9911062742677355" />
|
|
71
|
-
<entry key="M30" value="3.9955481049777206" />
|
|
72
|
-
<entry key="H1" value="3.9977727927268436" />
|
|
73
|
-
<entry key="H2" value="3.99888608120727" />
|
|
74
|
-
<entry key="H4" value="3.9994429617876244" />
|
|
75
|
-
<entry key="D1" value="3.9999071493489797" />
|
|
76
|
-
<entry key="W1" value="3.999986735353115" />
|
|
77
|
-
</decayedShown>
|
|
78
|
-
</component>
|
|
79
|
-
<component name="ProjectColorInfo"><![CDATA[{
|
|
80
|
-
"customColor": "467ffe29",
|
|
81
|
-
"associatedIndex": 8,
|
|
82
|
-
"fromUser": false
|
|
83
|
-
}]]></component>
|
|
84
|
-
<component name="ProjectId" id="3LkGtLtMlVrCxbh24OvdaS4qmTr" />
|
|
85
|
-
<component name="ProjectViewState">
|
|
86
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
|
87
|
-
<option name="showLibraryContents" value="true" />
|
|
88
|
-
</component>
|
|
89
|
-
<component name="PropertiesComponent"><![CDATA[{
|
|
90
|
-
"keyToString": {
|
|
91
|
-
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
|
92
|
-
"RunOnceActivity.MCP Project settings loaded": "true",
|
|
93
|
-
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
94
|
-
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
|
95
|
-
"codeWithMe.voiceChat.enabledByDefault": "false",
|
|
96
|
-
"node.js.detected.package.eslint": "true",
|
|
97
|
-
"node.js.detected.package.tslint": "true",
|
|
98
|
-
"node.js.selected.package.eslint": "(autodetect)",
|
|
99
|
-
"node.js.selected.package.tslint": "(autodetect)",
|
|
100
|
-
"nodejs_package_manager_path": "npm",
|
|
101
|
-
"settings.editor.selected.configurable": "preferences.lookFeel",
|
|
102
|
-
"ts.external.directory.path": "/Users/caseycolvell/Herd/ngx-wind-editor/node_modules/typescript/lib"
|
|
103
|
-
}
|
|
104
|
-
}]]></component>
|
|
105
|
-
<component name="TaskManager">
|
|
106
|
-
<task active="true" id="Default" summary="Default task">
|
|
107
|
-
<changelist id="dddd179b-1b8b-4c78-9e6c-2af59aa46f63" name="Changes" comment="" />
|
|
108
|
-
<created>1792612006340</created>
|
|
109
|
-
<option name="number" value="Default" />
|
|
110
|
-
<option name="presentableId" value="Default" />
|
|
111
|
-
<updated>1792612006340</updated>
|
|
112
|
-
<workItem from="1792612008984" duration="755000" />
|
|
113
|
-
<workItem from="1793990867474" duration="1465000" />
|
|
114
|
-
</task>
|
|
115
|
-
<servers />
|
|
116
|
-
</component>
|
|
117
|
-
<component name="TypeScriptGeneratedFilesManager">
|
|
118
|
-
<option name="version" value="3" />
|
|
119
|
-
</component>
|
|
120
|
-
</project>
|
package/dist/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 ngx-wind-editor contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/README.md
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# @codeauradev/ngx-wind-editor
|
|
2
|
-
|
|
3
|
-
WYSIWYG HTML editor for Angular 22. The chrome is Tailwind CSS v4, and it follows a `dark` class on an ancestor for dark mode.
|
|
4
|
-
|
|
5
|
-
```html
|
|
6
|
-
<wind-editor [(html)]="html" placeholder="Write something…" />
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import { Component, signal } from '@angular/core';
|
|
11
|
-
import { WindEditor } from '@codeauradev/ngx-wind-editor';
|
|
12
|
-
|
|
13
|
-
@Component({
|
|
14
|
-
selector: 'app-note',
|
|
15
|
-
imports: [WindEditor],
|
|
16
|
-
template: `<wind-editor [(html)]="html" />`,
|
|
17
|
-
})
|
|
18
|
-
export class Note {
|
|
19
|
-
readonly html = signal('<p>Start writing.</p>');
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
`[(html)]` is the serialized document.
|
|
24
|
-
|
|
25
|
-
## Install
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install @codeauradev/ngx-wind-editor
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Peer: `@angular/core` `^22`. Tailwind CSS v4 is optional and styles the toolbar.
|
|
32
|
-
|
|
33
|
-
```css
|
|
34
|
-
@import "tailwindcss";
|
|
35
|
-
@source "../node_modules/@codeauradev/ngx-wind-editor";
|
|
36
|
-
@custom-variant dark (&:where(.dark, .dark *));
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
`@source` lets Tailwind see the utility classes in the component. Document typography and the placeholder ship in the component stylesheet, so the page still reads if you skip Tailwind. Put `class="dark"` on an ancestor to switch the document to dark.
|
|
40
|
-
|
|
41
|
-
## Toolbar
|
|
42
|
-
|
|
43
|
-
`toolbar` picks which buttons appear. A preset name, or a list of ids in the order you want:
|
|
44
|
-
|
|
45
|
-
```html
|
|
46
|
-
<wind-editor [(html)]="html" toolbar="writing" />
|
|
47
|
-
<wind-editor [(html)]="html" [toolbar]="['bold', 'italic', 'link', 'bullet']" />
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
| Preset | Buttons |
|
|
51
|
-
| --- | --- |
|
|
52
|
-
| `full` | Every button. This is the default. |
|
|
53
|
-
| `writing` | Paragraph, headings, bold, italic, link, lists, quote, undo, redo |
|
|
54
|
-
| `basic` | Bold, italic, underline, strike, link, lists, undo, redo |
|
|
55
|
-
| `minimal` | Bold, italic, link |
|
|
56
|
-
|
|
57
|
-
Ids: `paragraph`, `h1`, `h2`, `bold`, `italic`, `underline`, `strike`, `code`, `link`, `bullet`, `ordered`, `quote`, `codeblock`, `rule`, `image`, `clear`, `undo`, `redo`, `source`. Unknown ids are ignored. `[showToolbar]="false"` hides the bar entirely.
|
|
58
|
-
|
|
59
|
-
`/` at the start of an empty block opens the block menu. Arrow keys move, Enter applies, Escape cancels. In a code block, Enter inserts a newline and Ctrl/Cmd+Enter starts a paragraph under it.
|
|
60
|
-
|
|
61
|
-
| Shortcut | Action |
|
|
62
|
-
| --- | --- |
|
|
63
|
-
| Mod+B / I / U / E | Bold, italic, underline, inline code |
|
|
64
|
-
| Mod+Shift+X | Strikethrough |
|
|
65
|
-
| Mod+K | Link |
|
|
66
|
-
| Mod+Z / Mod+Shift+Z | Undo / redo |
|
|
67
|
-
|
|
68
|
-
Mod is Cmd on macOS and Ctrl elsewhere.
|
|
69
|
-
|
|
70
|
-
## HTML
|
|
71
|
-
|
|
72
|
-
The editor reads and writes a fixed subset: `p`, `h1`–`h3`, `blockquote`, `ul`, `ol`, `li`, `pre`, `code`, `strong`, `em`, `u`, `s`, `a`, `br`, `hr`, `img`. `javascript:` URLs are dropped. Lists are flat.
|
|
73
|
-
|
|
74
|
-
Set the model and the editor replaces its document. Edits write back.
|
|
75
|
-
|
|
76
|
-
## Readonly
|
|
77
|
-
|
|
78
|
-
```html
|
|
79
|
-
<wind-editor [html]="published" [readonly]="true" [showToolbar]="false" />
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Build this package
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
npm install
|
|
86
|
-
npm test
|
|
87
|
-
npm run build
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Publish `dist/`. It is an Angular Package Format build (partial compilation).
|
package/dist/package.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@codeauradev/ngx-wind-editor",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "WYSIWYG HTML editor for Angular 22, styled with Tailwind CSS v4.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"angular",
|
|
7
|
-
"angular22",
|
|
8
|
-
"wysiwyg",
|
|
9
|
-
"rich-text",
|
|
10
|
-
"editor",
|
|
11
|
-
"tailwindcss",
|
|
12
|
-
"ngx"
|
|
13
|
-
],
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
17
|
-
},
|
|
18
|
-
"sideEffects": [
|
|
19
|
-
"*.css",
|
|
20
|
-
"styles.css"
|
|
21
|
-
],
|
|
22
|
-
"type": "module",
|
|
23
|
-
"module": "fesm2022/codeauradev-ngx-wind-editor.mjs",
|
|
24
|
-
"typings": "types/codeauradev-ngx-wind-editor.d.ts",
|
|
25
|
-
"exports": {
|
|
26
|
-
".": {
|
|
27
|
-
"types": "./types/codeauradev-ngx-wind-editor.d.ts",
|
|
28
|
-
"default": "./fesm2022/codeauradev-ngx-wind-editor.mjs"
|
|
29
|
-
},
|
|
30
|
-
"./styles.css": "./ngx-wind-editor.css",
|
|
31
|
-
"./package.json": {
|
|
32
|
-
"default": "./package.json"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"@angular/core": "^22.0.0",
|
|
37
|
-
"tailwindcss": "^4.0.0"
|
|
38
|
-
},
|
|
39
|
-
"peerDependenciesMeta": {
|
|
40
|
-
"tailwindcss": {
|
|
41
|
-
"optional": true
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"tslib": "^2.8.1",
|
|
46
|
-
"yjs": "^13.6.27"
|
|
47
|
-
}
|
|
48
|
-
}
|
package/ng-package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
|
|
3
|
-
"dest": "./dist",
|
|
4
|
-
"allowedNonPeerDependencies": ["yjs"],
|
|
5
|
-
"lib": {
|
|
6
|
-
"entryFile": "src/public-api.ts"
|
|
7
|
-
},
|
|
8
|
-
"assets": [
|
|
9
|
-
{
|
|
10
|
-
"input": "src/styles",
|
|
11
|
-
"glob": "**/*.css",
|
|
12
|
-
"output": "."
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|
package/scripts/patch-dist.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
const file = 'dist/package.json';
|
|
4
|
-
const pkg = JSON.parse(readFileSync(file, 'utf8'));
|
|
5
|
-
delete pkg.main;
|
|
6
|
-
delete pkg.types;
|
|
7
|
-
pkg.exports = {
|
|
8
|
-
...pkg.exports,
|
|
9
|
-
'./styles.css': './ngx-wind-editor.css',
|
|
10
|
-
};
|
|
11
|
-
writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
|
package/src/catalog.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { SlashChoice } from './session';
|
|
2
|
-
|
|
3
|
-
export interface SlashItem {
|
|
4
|
-
id: SlashChoice;
|
|
5
|
-
label: string;
|
|
6
|
-
hint: string;
|
|
7
|
-
keys: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const SLASH_ITEMS: readonly SlashItem[] = [
|
|
11
|
-
{ id: 'paragraph', label: 'Text', hint: 'Plain paragraph', keys: 'p text paragraph' },
|
|
12
|
-
{ id: 'h1', label: 'Heading 1', hint: 'Large title', keys: 'h1 heading title' },
|
|
13
|
-
{ id: 'h2', label: 'Heading 2', hint: 'Section', keys: 'h2 heading' },
|
|
14
|
-
{ id: 'h3', label: 'Heading 3', hint: 'Subsection', keys: 'h3 heading' },
|
|
15
|
-
{ id: 'bullet', label: 'Bullet list', hint: 'Unordered', keys: 'ul list bullet' },
|
|
16
|
-
{ id: 'ordered', label: 'Numbered list', hint: 'Ordered', keys: 'ol list number' },
|
|
17
|
-
{ id: 'quote', label: 'Quote', hint: 'Blockquote', keys: 'quote blockquote' },
|
|
18
|
-
{ id: 'code', label: 'Code', hint: 'Monospace block', keys: 'code pre' },
|
|
19
|
-
{ id: 'rule', label: 'Divider', hint: 'Horizontal rule', keys: 'hr rule divider line' },
|
|
20
|
-
{ id: 'image', label: 'Image', hint: 'From a URL', keys: 'img image picture' },
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export function filterSlash(query: string): SlashItem[] {
|
|
24
|
-
const needle = query.trim().toLowerCase();
|
|
25
|
-
if (!needle) return [...SLASH_ITEMS];
|
|
26
|
-
return SLASH_ITEMS.filter((item) => `${item.label} ${item.keys}`.toLowerCase().includes(needle));
|
|
27
|
-
}
|
package/src/delta.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { Delta, DeltaOp, TextAttrs } from './types';
|
|
2
|
-
|
|
3
|
-
const MARK_KEYS = ['bold', 'italic', 'underline', 'strike', 'code', 'href'] as const;
|
|
4
|
-
|
|
5
|
-
export function packAttrs(attrs: TextAttrs | null | undefined): TextAttrs | undefined {
|
|
6
|
-
if (!attrs) return undefined;
|
|
7
|
-
const out: TextAttrs = {};
|
|
8
|
-
if (attrs.bold) out.bold = true;
|
|
9
|
-
if (attrs.italic) out.italic = true;
|
|
10
|
-
if (attrs.underline) out.underline = true;
|
|
11
|
-
if (attrs.strike) out.strike = true;
|
|
12
|
-
if (attrs.code) out.code = true;
|
|
13
|
-
if (typeof attrs.href === 'string' && attrs.href.length > 0) out.href = attrs.href;
|
|
14
|
-
return Object.keys(out).length > 0 ? out : undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function attrsEqual(a: TextAttrs | undefined, b: TextAttrs | undefined): boolean {
|
|
18
|
-
const left = packAttrs(a) ?? {};
|
|
19
|
-
const right = packAttrs(b) ?? {};
|
|
20
|
-
return MARK_KEYS.every((key) => left[key] === right[key]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function mergeDelta(delta: Delta): Delta {
|
|
24
|
-
const out: Delta = [];
|
|
25
|
-
for (const op of delta) {
|
|
26
|
-
if (!op.insert) continue;
|
|
27
|
-
const prev = out[out.length - 1];
|
|
28
|
-
if (prev && attrsEqual(prev.attributes, op.attributes)) prev.insert += op.insert;
|
|
29
|
-
else out.push({ insert: op.insert, attributes: packAttrs(op.attributes) });
|
|
30
|
-
}
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function deltaLength(delta: Delta): number {
|
|
35
|
-
return delta.reduce((sum, op) => sum + op.insert.length, 0);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function deltaToText(delta: Delta): string {
|
|
39
|
-
return delta.map((op) => op.insert).join('');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function sliceDelta(delta: Delta, start: number, end: number): Delta {
|
|
43
|
-
const out: DeltaOp[] = [];
|
|
44
|
-
let pos = 0;
|
|
45
|
-
for (const op of delta) {
|
|
46
|
-
const len = op.insert.length;
|
|
47
|
-
const from = Math.max(start, pos);
|
|
48
|
-
const to = Math.min(end, pos + len);
|
|
49
|
-
if (to > from) {
|
|
50
|
-
out.push({ insert: op.insert.slice(from - pos, to - pos), attributes: packAttrs(op.attributes) });
|
|
51
|
-
}
|
|
52
|
-
pos += len;
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Attributes that apply to a caret sitting at `index` (the character before it). */
|
|
58
|
-
export function attrsAt(delta: Delta, index: number): TextAttrs {
|
|
59
|
-
if (index <= 0 || delta.length === 0) return {};
|
|
60
|
-
let pos = 0;
|
|
61
|
-
for (const op of delta) {
|
|
62
|
-
const len = op.insert.length;
|
|
63
|
-
if (index <= pos + len) return { ...(packAttrs(op.attributes) ?? {}) };
|
|
64
|
-
pos += len;
|
|
65
|
-
}
|
|
66
|
-
return { ...(packAttrs(delta[delta.length - 1]?.attributes) ?? {}) };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function commonEdges(prev: string, next: string): { start: number; prevEnd: number; nextEnd: number } {
|
|
70
|
-
let start = 0;
|
|
71
|
-
const limit = Math.min(prev.length, next.length);
|
|
72
|
-
while (start < limit && prev[start] === next[start]) start += 1;
|
|
73
|
-
let prevEnd = prev.length;
|
|
74
|
-
let nextEnd = next.length;
|
|
75
|
-
while (prevEnd > start && nextEnd > start && prev[prevEnd - 1] === next[nextEnd - 1]) {
|
|
76
|
-
prevEnd -= 1;
|
|
77
|
-
nextEnd -= 1;
|
|
78
|
-
}
|
|
79
|
-
return { start, prevEnd, nextEnd };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
interface GraphemePart {
|
|
83
|
-
index: number;
|
|
84
|
-
segment: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface GraphemeSegmenter {
|
|
88
|
-
segment(input: string): Iterable<GraphemePart>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Local shape so the build does not depend on the ES2022 Intl lib. */
|
|
92
|
-
function graphemeSegmenter(): GraphemeSegmenter | null {
|
|
93
|
-
const intl = Intl as typeof Intl & {
|
|
94
|
-
Segmenter?: new (locales?: string, options?: { granularity?: 'grapheme' }) => GraphemeSegmenter;
|
|
95
|
-
};
|
|
96
|
-
if (typeof intl.Segmenter !== 'function') return null;
|
|
97
|
-
return new intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function graphemeBefore(text: string, offset: number): number {
|
|
101
|
-
if (offset <= 0) return 0;
|
|
102
|
-
const segmenter = graphemeSegmenter();
|
|
103
|
-
if (!segmenter) return offset - 1;
|
|
104
|
-
let last = 0;
|
|
105
|
-
for (const part of segmenter.segment(text.slice(0, offset))) last = part.index;
|
|
106
|
-
return last;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function graphemeAfter(text: string, offset: number): number {
|
|
110
|
-
if (offset >= text.length) return text.length;
|
|
111
|
-
const segmenter = graphemeSegmenter();
|
|
112
|
-
if (!segmenter) return offset + 1;
|
|
113
|
-
const part = segmenter.segment(text.slice(offset))[Symbol.iterator]().next().value;
|
|
114
|
-
return offset + (part?.segment.length ?? 1);
|
|
115
|
-
}
|