wds-editor 1.0.1 → 1.2.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/README.md +92 -3
- package/dist/lang/ar.d.mts +3 -0
- package/dist/lang/ar.js +6 -0
- package/dist/lang/ar.mjs +2 -0
- package/dist/lang/de.d.mts +3 -0
- package/dist/lang/de.js +6 -0
- package/dist/lang/de.mjs +2 -0
- package/dist/lang/es.d.mts +3 -0
- package/dist/lang/es.js +6 -0
- package/dist/lang/es.mjs +2 -0
- package/dist/lang/fr.d.mts +3 -0
- package/dist/lang/fr.js +6 -0
- package/dist/lang/fr.mjs +2 -0
- package/dist/lang/it.d.mts +3 -0
- package/dist/lang/it.js +6 -0
- package/dist/lang/it.mjs +2 -0
- package/dist/lang/ja.d.mts +3 -0
- package/dist/lang/ja.js +6 -0
- package/dist/lang/ja.mjs +2 -0
- package/dist/lang/pt.d.mts +3 -0
- package/dist/lang/pt.js +6 -0
- package/dist/lang/pt.mjs +2 -0
- package/dist/lang/ru.d.mts +3 -0
- package/dist/lang/ru.js +6 -0
- package/dist/lang/ru.mjs +2 -0
- package/dist/lang/zh.d.mts +3 -0
- package/dist/lang/zh.js +6 -0
- package/dist/lang/zh.mjs +2 -0
- package/dist/types/autosave.d.ts +37 -0
- package/dist/types/commands.d.ts +8 -2
- package/dist/types/contentcss.d.ts +24 -0
- package/dist/types/editor.d.ts +40 -2
- package/dist/types/filemanager/api.d.ts +3 -0
- package/dist/types/find.d.ts +38 -0
- package/dist/types/i18n.d.ts +27 -1
- package/dist/types/ui/menu.d.ts +2 -0
- package/dist/types/video.d.ts +20 -0
- package/dist/wds-editor.js +1480 -944
- package/dist/wds-editor.js.map +1 -1
- package/dist/wds-editor.min.css +1 -1
- package/dist/wds-editor.min.js +13 -12
- package/dist/wds-editor.min.js.map +1 -1
- package/dist/wds-editor.umd.cjs +6 -5
- package/dist/wds-editor.umd.cjs.map +1 -1
- package/package.json +84 -72
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Messages } from './i18n';
|
|
2
|
+
export interface AutosaveOptions {
|
|
3
|
+
/** Storage key; use one per document (e.g. "post-42"). Default: page path + element id or name. */
|
|
4
|
+
key?: string;
|
|
5
|
+
/** Milliseconds to wait after the last change before saving. Default 1000. */
|
|
6
|
+
delay?: number;
|
|
7
|
+
/** Drafts older than this many days are ignored and removed. Default 7. */
|
|
8
|
+
expires?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Keeps a draft of the content in localStorage. When the page is opened again with a different content,
|
|
12
|
+
* a bar offers to restore or discard the draft. Submitting the form removes it.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Autosave {
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly before;
|
|
17
|
+
private readonly t;
|
|
18
|
+
private readonly restore;
|
|
19
|
+
readonly key: string;
|
|
20
|
+
private readonly delay;
|
|
21
|
+
private readonly expires;
|
|
22
|
+
private timer;
|
|
23
|
+
private pending;
|
|
24
|
+
private bar;
|
|
25
|
+
private readonly onPageHide;
|
|
26
|
+
constructor(options: AutosaveOptions, fallbackKey: string, host: HTMLElement, before: HTMLElement, t: Messages, restore: (html: string) => void);
|
|
27
|
+
/** Shows the restore bar when a saved draft differs from the content the editor started with. */
|
|
28
|
+
check(currentHtml: string): void;
|
|
29
|
+
/** Called on every content change. While the restore bar is open the old draft is kept. */
|
|
30
|
+
schedule(html: string): void;
|
|
31
|
+
flush(): void;
|
|
32
|
+
/** Removes the draft (after the content was saved on the server). */
|
|
33
|
+
clear(): void;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
private hideBar;
|
|
36
|
+
private read;
|
|
37
|
+
}
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -18,8 +18,9 @@ export declare const indent: Command;
|
|
|
18
18
|
export declare const outdent: Command;
|
|
19
19
|
export declare function toggleBlockquote(): Command;
|
|
20
20
|
/** Alignment applies to every paragraph and heading touched by the selection. */
|
|
21
|
-
|
|
22
|
-
export declare function
|
|
21
|
+
/** `start` is the side text starts on (right in right-to-left editors); that alignment is stored as no attribute. */
|
|
22
|
+
export declare function setAlign(align: Align, start?: 'left' | 'right'): Command;
|
|
23
|
+
export declare function currentAlign(state: EditorState, start?: 'left' | 'right'): Align;
|
|
23
24
|
export declare const insertHorizontalRule: Command;
|
|
24
25
|
/** Removes inline marks (keeps links) and turns headings / code blocks back into paragraphs. */
|
|
25
26
|
export declare const clearFormatting: Command;
|
|
@@ -32,6 +33,11 @@ export declare function linkRange(state: EditorState): {
|
|
|
32
33
|
target: string | null;
|
|
33
34
|
} | null;
|
|
34
35
|
/** The selected image or figure (click on an image selects it). */
|
|
36
|
+
/** The selected video node, if any. */
|
|
37
|
+
export declare function selectedVideo(state: EditorState): {
|
|
38
|
+
pos: number;
|
|
39
|
+
node: PMNode;
|
|
40
|
+
} | null;
|
|
35
41
|
export declare function selectedImage(state: EditorState): {
|
|
36
42
|
pos: number;
|
|
37
43
|
attrs: Record<string, unknown>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface SiteStyleOptions {
|
|
2
|
+
/** Stylesheet URLs. They are fetched with CORS (same origin or a CDN such as jsDelivr). @import rules are skipped. */
|
|
3
|
+
css?: string | string[];
|
|
4
|
+
/** CSS text, scoped the same way. */
|
|
5
|
+
style?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Entry {
|
|
8
|
+
className: string;
|
|
9
|
+
ready: Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/** Splits a selector list at top-level commas: "a, :is(b, c)" -> ["a", ":is(b, c)"]. */
|
|
12
|
+
export declare function splitSelectors(list: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Scopes a selector list to the element around the editor content. The document roots (:root, html, body, :host)
|
|
15
|
+
* become that element: "body" -> scope, "html body > p" -> "scope > p", "h2, .h2" -> "scope h2, scope .h2".
|
|
16
|
+
*/
|
|
17
|
+
export declare function scopeSelector(selectorList: string, scope: string): string;
|
|
18
|
+
export declare const supportsSiteStyles: () => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Loads (once per set of stylesheets) and returns the class to put on the element around the content.
|
|
21
|
+
* Editors with the same contentCss and contentStyle share the scoped sheets.
|
|
22
|
+
*/
|
|
23
|
+
export declare function siteStyles(options: SiteStyleOptions): Entry | null;
|
|
24
|
+
export {};
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { type ImageAlign } from './schema';
|
|
|
5
5
|
import { type Swatch } from './color';
|
|
6
6
|
import { addLanguage, type Messages } from './i18n';
|
|
7
7
|
import { type FileItem, type FileManagerOptions } from './filemanager/api';
|
|
8
|
-
|
|
8
|
+
import { type AutosaveOptions } from './autosave';
|
|
9
|
+
export type { FileManagerOptions, FileItem, AutosaveOptions };
|
|
9
10
|
export type Theme = 'light' | 'dark' | 'auto';
|
|
10
11
|
export interface WDSEditorOptions {
|
|
11
12
|
/** CSS selector or element: a <textarea> (recommended, keeps forms working) or any container element. */
|
|
@@ -17,8 +18,13 @@ export interface WDSEditorOptions {
|
|
|
17
18
|
/** Initial HTML. Defaults to the textarea value / container content. */
|
|
18
19
|
content?: string;
|
|
19
20
|
placeholder?: string;
|
|
20
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* "en", "tr", a language file loaded from dist/lang (de, fr, es, pt, it, ru, zh, ja, ar),
|
|
23
|
+
* any language added with WDSEditor.addLanguage, or a messages object. Defaults to the browser language.
|
|
24
|
+
*/
|
|
21
25
|
language?: string | Partial<Messages>;
|
|
26
|
+
/** Text direction of the editor. "auto" (default): right-to-left for Arabic and other RTL languages, otherwise inherited from the page. */
|
|
27
|
+
dir?: 'ltr' | 'rtl' | 'auto';
|
|
22
28
|
theme?: Theme;
|
|
23
29
|
/** "default", a space separated string ("bold italic | link") or an array of item names. "|" groups items. */
|
|
24
30
|
toolbar?: 'default' | string | string[] | false;
|
|
@@ -32,8 +38,22 @@ export interface WDSEditorOptions {
|
|
|
32
38
|
text?: Array<string | Swatch>;
|
|
33
39
|
highlight?: Array<string | Swatch>;
|
|
34
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Stylesheet URLs of the site where the HTML is published (your site CSS, Bootstrap from a CDN, a compiled Tailwind file).
|
|
43
|
+
* The content area is shown with them and the rest of the page is not affected. See README "Site styles".
|
|
44
|
+
*/
|
|
45
|
+
contentCss?: string | string[];
|
|
46
|
+
/** CSS text for the content area, scoped like contentCss. */
|
|
47
|
+
contentStyle?: string;
|
|
48
|
+
/** Classes for the content element: "prose" for Tailwind Typography, or the class your site puts around articles. */
|
|
49
|
+
contentClass?: string;
|
|
35
50
|
/** Enables the file manager (image / file buttons, paste and drop uploads). See README "File manager". */
|
|
36
51
|
fileManager?: FileManagerOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Keeps a draft in localStorage and offers to restore it when the page is opened again.
|
|
54
|
+
* true, or { key, delay, expires }. Submitting the form removes the draft. See README "Autosave".
|
|
55
|
+
*/
|
|
56
|
+
autosave?: boolean | AutosaveOptions;
|
|
37
57
|
onChange?: (html: string, editor: WDSEditor) => void;
|
|
38
58
|
}
|
|
39
59
|
export type EditorEvent = 'change' | 'focus' | 'blur' | 'init' | 'destroy' | 'upload' | 'fileSelect';
|
|
@@ -72,6 +92,8 @@ export declare class WDSEditor {
|
|
|
72
92
|
private readonly listeners;
|
|
73
93
|
private readonly originalContent;
|
|
74
94
|
private readonly fileManager;
|
|
95
|
+
private readonly findPanel;
|
|
96
|
+
private readonly autosave;
|
|
75
97
|
private notice;
|
|
76
98
|
private noticeTimer;
|
|
77
99
|
private readonly onFormSubmit;
|
|
@@ -99,10 +121,26 @@ export declare class WDSEditor {
|
|
|
99
121
|
redo(): void;
|
|
100
122
|
isSourceMode(): boolean;
|
|
101
123
|
toggleSource(): void;
|
|
124
|
+
/** Removes the autosave draft, e.g. after saving with fetch instead of a form submit. */
|
|
125
|
+
clearDraft(): void;
|
|
126
|
+
/** Opens the find and replace bar (Ctrl+F / Cmd+F inside the editor). */
|
|
127
|
+
openFind(): void;
|
|
128
|
+
closeFind(): void;
|
|
129
|
+
isFindOpen(): boolean;
|
|
102
130
|
isFullscreen(): boolean;
|
|
103
131
|
toggleFullscreen(): void;
|
|
104
132
|
openLinkDialog(): void;
|
|
105
133
|
removeLink(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Inserts a YouTube or Vimeo video (watch page, short link or embed URL) at the cursor.
|
|
136
|
+
* Returns false for other addresses.
|
|
137
|
+
*/
|
|
138
|
+
insertVideo(url: string, options?: {
|
|
139
|
+
title?: string;
|
|
140
|
+
width?: number | null;
|
|
141
|
+
}): boolean;
|
|
142
|
+
/** Video button: edits the selected video or asks for a YouTube / Vimeo address. */
|
|
143
|
+
openVideoDialog(): void;
|
|
106
144
|
/** True when a file manager (listUrl) is configured. */
|
|
107
145
|
hasFileManager(): boolean;
|
|
108
146
|
/** Inserts an image at the cursor (replacing the selection). caption: true wraps it in <figure>. Unsafe sources are ignored. */
|
|
@@ -54,7 +54,10 @@ export declare function matchesAccept(file: {
|
|
|
54
54
|
type?: string;
|
|
55
55
|
}, accept: string | undefined): boolean;
|
|
56
56
|
export declare function formatSize(bytes: number | undefined): string;
|
|
57
|
+
/** code "network" and "response" are shown with translated texts; other errors carry the server's own message. */
|
|
57
58
|
export declare class FileApiError extends Error {
|
|
59
|
+
readonly code?: "network" | "response" | undefined;
|
|
60
|
+
constructor(message: string, code?: "network" | "response" | undefined);
|
|
58
61
|
}
|
|
59
62
|
export declare class FileApi {
|
|
60
63
|
private readonly options;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Plugin, PluginKey, type EditorState } from 'prosemirror-state';
|
|
2
|
+
import { type EditorView } from 'prosemirror-view';
|
|
3
|
+
import type { Node as PMNode } from 'prosemirror-model';
|
|
4
|
+
import type { Messages } from './i18n';
|
|
5
|
+
export interface Match {
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
}
|
|
9
|
+
interface FindState {
|
|
10
|
+
query: string;
|
|
11
|
+
caseSensitive: boolean;
|
|
12
|
+
matches: Match[];
|
|
13
|
+
/** Index of the current match, -1 when there is none. */
|
|
14
|
+
current: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const findKey: PluginKey<FindState>;
|
|
17
|
+
/** Finds the text in every textblock. Matches never cross blocks; inline nodes (images, breaks) split the text. */
|
|
18
|
+
export declare function findMatches(doc: PMNode, query: string, caseSensitive: boolean): Match[];
|
|
19
|
+
export declare function findPlugin(): Plugin<FindState>;
|
|
20
|
+
/** Find and replace bar shown between the toolbar and the content. */
|
|
21
|
+
export declare class FindPanel {
|
|
22
|
+
private readonly view;
|
|
23
|
+
private readonly t;
|
|
24
|
+
private readonly onClose;
|
|
25
|
+
readonly element: HTMLElement;
|
|
26
|
+
private readonly findInput;
|
|
27
|
+
private readonly replaceInput;
|
|
28
|
+
private readonly caseInput;
|
|
29
|
+
private readonly count;
|
|
30
|
+
private readonly buttons;
|
|
31
|
+
constructor(view: EditorView, t: Messages, onClose: () => void);
|
|
32
|
+
get isOpen(): boolean;
|
|
33
|
+
open(): void;
|
|
34
|
+
close(): void;
|
|
35
|
+
/** Updates the "3 of 10" counter and the button states after every transaction. */
|
|
36
|
+
update(state: EditorState, editable: boolean): void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
package/dist/types/i18n.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ export declare const en: {
|
|
|
84
84
|
fmListFailed: string;
|
|
85
85
|
fmDeleteFailed: string;
|
|
86
86
|
fmUploading: string;
|
|
87
|
+
fmNetworkError: string;
|
|
88
|
+
fmInvalidResponse: string;
|
|
87
89
|
table: string;
|
|
88
90
|
tableInsert: string;
|
|
89
91
|
tableSize: string;
|
|
@@ -117,12 +119,36 @@ export declare const en: {
|
|
|
117
119
|
colorPink: string;
|
|
118
120
|
colorSlate: string;
|
|
119
121
|
colorGray: string;
|
|
122
|
+
video: string;
|
|
123
|
+
videoEdit: string;
|
|
124
|
+
videoUrl: string;
|
|
125
|
+
videoHint: string;
|
|
126
|
+
videoTitle: string;
|
|
127
|
+
videoInvalid: string;
|
|
128
|
+
findReplace: string;
|
|
129
|
+
find: string;
|
|
130
|
+
replaceWith: string;
|
|
131
|
+
findNext: string;
|
|
132
|
+
findPrevious: string;
|
|
133
|
+
replace: string;
|
|
134
|
+
replaceAll: string;
|
|
135
|
+
matchCase: string;
|
|
136
|
+
matchCount: string;
|
|
137
|
+
noMatches: string;
|
|
138
|
+
replacedCount: string;
|
|
139
|
+
draftFound: string;
|
|
140
|
+
draftRestore: string;
|
|
141
|
+
draftDiscard: string;
|
|
120
142
|
};
|
|
121
143
|
export type Messages = typeof en;
|
|
122
144
|
export type MessageKey = keyof Messages;
|
|
123
145
|
export declare const tr: Messages;
|
|
124
146
|
/** Registers or extends a language, e.g. WDSEditor.addLanguage('de', { bold: 'Fett', ... }). Missing keys fall back to English. */
|
|
125
147
|
export declare function addLanguage(code: string, messages: Partial<Messages>): void;
|
|
148
|
+
/** The language code the editor will use for an option value ("de-AT" falls back to "de", unknown codes to "en"). */
|
|
149
|
+
export declare function resolveLanguage(language: string | undefined): string;
|
|
126
150
|
export declare function resolveMessages(language: string | Partial<Messages> | undefined): Messages;
|
|
151
|
+
/** True for right-to-left languages such as Arabic, Hebrew and Persian. */
|
|
152
|
+
export declare function isRtl(code: string): boolean;
|
|
127
153
|
/** Fills {placeholders} in a message. */
|
|
128
|
-
export declare function format(message: string, values: Record<string, string>): string;
|
|
154
|
+
export declare function format(message: string, values: Record<string, string | number>): string;
|
package/dist/types/ui/menu.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** True when the element is laid out right to left (dir="rtl" on the editor or the page). */
|
|
2
|
+
export declare const isRtlElement: (el: Element) => boolean;
|
|
1
3
|
/**
|
|
2
4
|
* Small dropdown anchored to a toolbar button. It lives inside the editor root (theme variables
|
|
3
5
|
* apply), closes on Escape / outside click / item choice and gives focus back to the button's editor.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NodeSpec, Node as PMNode } from 'prosemirror-model';
|
|
2
|
+
import type { EditorView, NodeView } from 'prosemirror-view';
|
|
3
|
+
/**
|
|
4
|
+
* Turns a YouTube or Vimeo address (watch page, short link, Shorts, embed URL or a pasted <iframe> code)
|
|
5
|
+
* into the player URL, or returns null.
|
|
6
|
+
*/
|
|
7
|
+
export declare function videoEmbedUrl(input: string | null | undefined): string | null;
|
|
8
|
+
export declare function videoDomAttrs(attrs: Record<string, unknown>): Record<string, string>;
|
|
9
|
+
export declare const videoNode: NodeSpec;
|
|
10
|
+
/** In the editor the player is shown but not clickable, so a click selects the video (drag, delete, edit). */
|
|
11
|
+
export declare class VideoView implements NodeView {
|
|
12
|
+
private onEdit;
|
|
13
|
+
dom: HTMLElement;
|
|
14
|
+
private iframe;
|
|
15
|
+
constructor(node: PMNode, onEdit: () => void, _view?: EditorView);
|
|
16
|
+
private render;
|
|
17
|
+
update(node: PMNode): boolean;
|
|
18
|
+
stopEvent(): boolean;
|
|
19
|
+
ignoreMutation(): boolean;
|
|
20
|
+
}
|