@codeauradev/ngx-wind-editor 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +89 -2
- package/fesm2022/codeauradev-ngx-wind-editor.mjs +2596 -0
- package/fesm2022/codeauradev-ngx-wind-editor.mjs.map +1 -0
- package/ngx-wind-editor.css +184 -0
- package/package.json +46 -4
- package/types/codeauradev-ngx-wind-editor.d.ts +270 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
declare const BLOCK_TYPES: readonly ["paragraph", "heading", "blockquote", "code", "bullet", "ordered", "rule", "image"];
|
|
4
|
+
type BlockType = (typeof BLOCK_TYPES)[number];
|
|
5
|
+
declare const MARKS: readonly ["bold", "italic", "underline", "strike", "code"];
|
|
6
|
+
type MarkName = (typeof MARKS)[number];
|
|
7
|
+
interface TextAttrs {
|
|
8
|
+
bold?: boolean;
|
|
9
|
+
italic?: boolean;
|
|
10
|
+
underline?: boolean;
|
|
11
|
+
strike?: boolean;
|
|
12
|
+
code?: boolean;
|
|
13
|
+
href?: string;
|
|
14
|
+
}
|
|
15
|
+
interface DeltaOp {
|
|
16
|
+
insert: string;
|
|
17
|
+
attributes?: TextAttrs;
|
|
18
|
+
}
|
|
19
|
+
type Delta = DeltaOp[];
|
|
20
|
+
interface BlockData {
|
|
21
|
+
id: string;
|
|
22
|
+
type: BlockType;
|
|
23
|
+
level: number;
|
|
24
|
+
src: string;
|
|
25
|
+
alt: string;
|
|
26
|
+
delta: Delta;
|
|
27
|
+
}
|
|
28
|
+
interface Point {
|
|
29
|
+
blockId: string;
|
|
30
|
+
offset: number;
|
|
31
|
+
}
|
|
32
|
+
interface Selection {
|
|
33
|
+
anchor: Point;
|
|
34
|
+
head: Point;
|
|
35
|
+
}
|
|
36
|
+
interface EditorSnapshot {
|
|
37
|
+
html: string;
|
|
38
|
+
text: string;
|
|
39
|
+
words: number;
|
|
40
|
+
characters: number;
|
|
41
|
+
blockType: BlockType;
|
|
42
|
+
level: number;
|
|
43
|
+
marks: TextAttrs;
|
|
44
|
+
href: string | null;
|
|
45
|
+
canUndo: boolean;
|
|
46
|
+
canRedo: boolean;
|
|
47
|
+
slash: string | null;
|
|
48
|
+
}
|
|
49
|
+
declare function isBlockType(value: unknown): value is BlockType;
|
|
50
|
+
interface LocatedBlock {
|
|
51
|
+
map: Y.Map<unknown>;
|
|
52
|
+
index: number;
|
|
53
|
+
id: string;
|
|
54
|
+
type: BlockType;
|
|
55
|
+
level: number;
|
|
56
|
+
text: Y.Text | null;
|
|
57
|
+
}
|
|
58
|
+
type SlashChoice = 'paragraph' | 'h1' | 'h2' | 'h3' | 'bullet' | 'ordered' | 'quote' | 'code' | 'rule' | 'image';
|
|
59
|
+
declare function blocksOf(doc: Y.Doc): Y.Array<Y.Map<unknown>>;
|
|
60
|
+
declare function makeBlock(type: BlockType, fields?: {
|
|
61
|
+
level?: number;
|
|
62
|
+
src?: string;
|
|
63
|
+
alt?: string;
|
|
64
|
+
delta?: Delta;
|
|
65
|
+
}): Y.Map<unknown>;
|
|
66
|
+
declare function readDelta(text: Y.Text): Delta;
|
|
67
|
+
export declare function readBlocks(doc: Y.Doc): BlockData[];
|
|
68
|
+
interface SessionSnapshot {
|
|
69
|
+
blockType: BlockType;
|
|
70
|
+
level: number;
|
|
71
|
+
marks: TextAttrs;
|
|
72
|
+
href: string | null;
|
|
73
|
+
slash: string | null;
|
|
74
|
+
canUndo: boolean;
|
|
75
|
+
canRedo: boolean;
|
|
76
|
+
}
|
|
77
|
+
export declare class WindSession {
|
|
78
|
+
readonly doc: Y.Doc;
|
|
79
|
+
readonly origin: object;
|
|
80
|
+
selection: Selection;
|
|
81
|
+
private stored;
|
|
82
|
+
private pendingBefore;
|
|
83
|
+
private readonly undoManager;
|
|
84
|
+
private readonly listeners;
|
|
85
|
+
constructor(doc: Y.Doc);
|
|
86
|
+
onChange(listener: (structural: boolean) => void): () => void;
|
|
87
|
+
get html(): string;
|
|
88
|
+
get text(): string;
|
|
89
|
+
get words(): number;
|
|
90
|
+
get canUndo(): boolean;
|
|
91
|
+
get canRedo(): boolean;
|
|
92
|
+
undo(): void;
|
|
93
|
+
redo(): void;
|
|
94
|
+
select(selection: Selection): void;
|
|
95
|
+
focusPoint(blockId: string, offset: number): void;
|
|
96
|
+
insertText(value: string): void;
|
|
97
|
+
deleteBackward(): void;
|
|
98
|
+
deleteForward(): void;
|
|
99
|
+
split(mode: 'enter' | 'hard' | 'exit'): void;
|
|
100
|
+
toggleMark(mark: MarkName): void;
|
|
101
|
+
setLink(href: string | null): void;
|
|
102
|
+
clearMarks(): void;
|
|
103
|
+
setBlockType(type: BlockType, level?: number): void;
|
|
104
|
+
insertDivider(): void;
|
|
105
|
+
insertImage(src: string, alt?: string): void;
|
|
106
|
+
applySlash(choice: SlashChoice): 'image' | 'applied';
|
|
107
|
+
paste(html: string | null, plain: string | null): void;
|
|
108
|
+
replaceHtml(html: string): void;
|
|
109
|
+
reconcileText(blockId: string, next: string): void;
|
|
110
|
+
snapshot(): SessionSnapshot;
|
|
111
|
+
dismissSlash(): void;
|
|
112
|
+
private slashQuery;
|
|
113
|
+
private consumeSlash;
|
|
114
|
+
private typingAttrs;
|
|
115
|
+
private effectiveMarks;
|
|
116
|
+
private toolbarMarks;
|
|
117
|
+
private rangeHas;
|
|
118
|
+
private formatRange;
|
|
119
|
+
private iterRange;
|
|
120
|
+
private deleteRange;
|
|
121
|
+
private insertParsed;
|
|
122
|
+
private selectedBlocks;
|
|
123
|
+
private ensureText;
|
|
124
|
+
private ensureBlock;
|
|
125
|
+
private current;
|
|
126
|
+
private clampSelection;
|
|
127
|
+
private transact;
|
|
128
|
+
private emit;
|
|
129
|
+
}
|
|
130
|
+
export declare function loadHtml(doc: Y.Doc, html: string, origin?: unknown): void;
|
|
131
|
+
interface SlashItem {
|
|
132
|
+
id: SlashChoice;
|
|
133
|
+
label: string;
|
|
134
|
+
hint: string;
|
|
135
|
+
keys: string;
|
|
136
|
+
}
|
|
137
|
+
export declare const SLASH_ITEMS: readonly SlashItem[];
|
|
138
|
+
export declare function filterSlash(query: string): SlashItem[];
|
|
139
|
+
export declare const WIND_TOOLS: readonly ["paragraph", "h1", "h2", "bold", "italic", "underline", "strike", "code", "link", "bullet", "ordered", "quote", "codeblock", "rule", "image", "clear", "undo", "redo", "source"];
|
|
140
|
+
type WindTool = (typeof WIND_TOOLS)[number];
|
|
141
|
+
type WindToolbarPreset = 'full' | 'writing' | 'basic' | 'minimal';
|
|
142
|
+
export declare const WIND_TOOLBAR_PRESETS: Record<WindToolbarPreset, readonly WindTool[]>;
|
|
143
|
+
export declare function isWindTool(value: string): value is WindTool;
|
|
144
|
+
export declare function isToolbarPreset(value: string): value is WindToolbarPreset;
|
|
145
|
+
/** A preset name, or an explicit list. Unknown ids are dropped. List order is the button order. */
|
|
146
|
+
export declare function resolveToolbar(value?: WindToolbarPreset | readonly string[] | null): WindTool[];
|
|
147
|
+
interface SlashPoint {
|
|
148
|
+
top: number;
|
|
149
|
+
left: number;
|
|
150
|
+
}
|
|
151
|
+
interface SurfaceChange extends EditorSnapshot {
|
|
152
|
+
slashRect: SlashPoint | null;
|
|
153
|
+
}
|
|
154
|
+
type WindCommand = {
|
|
155
|
+
type: 'mark';
|
|
156
|
+
mark: MarkName;
|
|
157
|
+
} | {
|
|
158
|
+
type: 'link';
|
|
159
|
+
href: string | null;
|
|
160
|
+
} | {
|
|
161
|
+
type: 'clear';
|
|
162
|
+
} | {
|
|
163
|
+
type: 'block';
|
|
164
|
+
block: BlockType;
|
|
165
|
+
level?: number;
|
|
166
|
+
} | {
|
|
167
|
+
type: 'divider';
|
|
168
|
+
} | {
|
|
169
|
+
type: 'image';
|
|
170
|
+
src: string;
|
|
171
|
+
alt?: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: 'undo';
|
|
174
|
+
} | {
|
|
175
|
+
type: 'redo';
|
|
176
|
+
} | {
|
|
177
|
+
type: 'slash';
|
|
178
|
+
choice: SlashChoice;
|
|
179
|
+
};
|
|
180
|
+
interface WindMount {
|
|
181
|
+
destroy(): void;
|
|
182
|
+
focus(): void;
|
|
183
|
+
exec(command: WindCommand): void;
|
|
184
|
+
setReadonly(readonly: boolean): void;
|
|
185
|
+
setPlaceholder(value: string): void;
|
|
186
|
+
setHtml(html: string): void;
|
|
187
|
+
getHtml(): string;
|
|
188
|
+
session: WindSession;
|
|
189
|
+
}
|
|
190
|
+
interface SurfaceOptions {
|
|
191
|
+
html?: string;
|
|
192
|
+
placeholder?: string;
|
|
193
|
+
readonly?: boolean;
|
|
194
|
+
onChange?: (change: SurfaceChange) => void;
|
|
195
|
+
/** Return true to swallow the key (slash menu, for example). */
|
|
196
|
+
interceptKey?: (event: KeyboardEvent) => boolean;
|
|
197
|
+
onLink?: () => void;
|
|
198
|
+
}
|
|
199
|
+
declare function mountWindSurface(host: HTMLElement, options: SurfaceOptions): WindMount;
|
|
200
|
+
interface Tool {
|
|
201
|
+
id: WindTool;
|
|
202
|
+
label: string;
|
|
203
|
+
icon: string;
|
|
204
|
+
}
|
|
205
|
+
export declare class WindEditor {
|
|
206
|
+
readonly html: import("@angular/core").ModelSignal<string>;
|
|
207
|
+
readonly placeholder: import("@angular/core").InputSignal<string>;
|
|
208
|
+
readonly readOnly: import("@angular/core").InputSignal<boolean>;
|
|
209
|
+
readonly showToolbar: import("@angular/core").InputSignal<boolean>;
|
|
210
|
+
/** Preset name, or the buttons to show, in order. */
|
|
211
|
+
readonly toolbar: import("@angular/core").InputSignal<readonly ("paragraph" | "code" | "bullet" | "ordered" | "rule" | "image" | "bold" | "italic" | "underline" | "strike" | "link" | "source" | "h1" | "h2" | "quote" | "undo" | "redo" | "codeblock" | "clear")[] | WindToolbarPreset>;
|
|
212
|
+
protected readonly tools: import("@angular/core").Signal<Tool[]>;
|
|
213
|
+
protected readonly change: import("@angular/core").WritableSignal<SurfaceChange | null>;
|
|
214
|
+
protected readonly linkOpen: import("@angular/core").WritableSignal<boolean>;
|
|
215
|
+
protected readonly linkDraft: import("@angular/core").WritableSignal<string>;
|
|
216
|
+
protected readonly imageOpen: import("@angular/core").WritableSignal<boolean>;
|
|
217
|
+
protected readonly imageSrc: import("@angular/core").WritableSignal<string>;
|
|
218
|
+
protected readonly imageAlt: import("@angular/core").WritableSignal<string>;
|
|
219
|
+
protected readonly sourceOpen: import("@angular/core").WritableSignal<boolean>;
|
|
220
|
+
protected readonly sourceDraft: import("@angular/core").WritableSignal<string>;
|
|
221
|
+
protected readonly slashIndex: import("@angular/core").WritableSignal<number>;
|
|
222
|
+
protected readonly slashItems: import("@angular/core").Signal<SlashItem[]>;
|
|
223
|
+
private readonly surfaceRef;
|
|
224
|
+
private readonly destroyRef;
|
|
225
|
+
private handle;
|
|
226
|
+
private echo;
|
|
227
|
+
constructor();
|
|
228
|
+
protected pressed(id: string): boolean;
|
|
229
|
+
protected disabled(id: string): boolean;
|
|
230
|
+
protected run(id: string): void;
|
|
231
|
+
protected pickSlash(item: SlashItem): void;
|
|
232
|
+
protected applyLink(event: Event): void;
|
|
233
|
+
protected clearLink(): void;
|
|
234
|
+
protected applyImage(event: Event): void;
|
|
235
|
+
protected applySource(): void;
|
|
236
|
+
protected onDraft(event: Event, field: 'link' | 'src' | 'alt' | 'source'): void;
|
|
237
|
+
private attach;
|
|
238
|
+
private onKey;
|
|
239
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<WindEditor, never>;
|
|
240
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<WindEditor, "wind-editor", never, {
|
|
241
|
+
"html": {
|
|
242
|
+
"alias": "html";
|
|
243
|
+
"required": false;
|
|
244
|
+
"isSignal": true;
|
|
245
|
+
};
|
|
246
|
+
"placeholder": {
|
|
247
|
+
"alias": "placeholder";
|
|
248
|
+
"required": false;
|
|
249
|
+
"isSignal": true;
|
|
250
|
+
};
|
|
251
|
+
"readOnly": {
|
|
252
|
+
"alias": "readonly";
|
|
253
|
+
"required": false;
|
|
254
|
+
"isSignal": true;
|
|
255
|
+
};
|
|
256
|
+
"showToolbar": {
|
|
257
|
+
"alias": "showToolbar";
|
|
258
|
+
"required": false;
|
|
259
|
+
"isSignal": true;
|
|
260
|
+
};
|
|
261
|
+
"toolbar": {
|
|
262
|
+
"alias": "toolbar";
|
|
263
|
+
"required": false;
|
|
264
|
+
"isSignal": true;
|
|
265
|
+
};
|
|
266
|
+
}, {
|
|
267
|
+
"html": "htmlChange";
|
|
268
|
+
}, never, never, true, never>;
|
|
269
|
+
}
|
|
270
|
+
export type { BlockData, BlockType, EditorSnapshot, MarkName, Selection, SlashChoice, SlashItem, TextAttrs, WindTool, WindToolbarPreset };
|