wds-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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WebDevSnippets
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/README.md CHANGED
@@ -1,3 +1,184 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # WDS Editor
2
+
3
+ A free, open source (MIT) WYSIWYG HTML editor by [WebDevSnippets](https://webdevsnippets.com/wds-editor).
4
+ Built on [ProseMirror](https://prosemirror.net): clean HTML output, safe paste from Word and Google Docs,
5
+ tables (merge / split cells, header row), images with captions and a resize handle, light and dark themes,
6
+ English and Turkish UI, and a **free built-in file manager** that works from a simple JSON list.
7
+
8
+ Docs and live demo: https://webdevsnippets.com/wds-editor
9
+
10
+ ## Quick start (CDN / script tag)
11
+
12
+ ```html
13
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/wds-editor@1/dist/wds-editor.min.css">
14
+ <script src="https://cdn.jsdelivr.net/npm/wds-editor@1/dist/wds-editor.min.js"></script>
15
+
16
+ <form method="post">
17
+ <textarea id="content" name="content"><p>Hello world</p></textarea>
18
+ <button>Save</button>
19
+ </form>
20
+
21
+ <script>
22
+ const editor = WDSEditor.init({ selector: '#content' });
23
+ </script>
24
+ ```
25
+
26
+ When the target is a `<textarea>`, the editor keeps it in sync, so normal form posts keep working.
27
+
28
+ ## npm
29
+
30
+ ```bash
31
+ npm install wds-editor
32
+ ```
33
+
34
+ ```js
35
+ import { WDSEditor } from 'wds-editor';
36
+ import 'wds-editor/style.css';
37
+
38
+ const editor = WDSEditor.init({ selector: '#content', language: 'en' });
39
+ ```
40
+
41
+ ## Options
42
+
43
+ | Option | Default | Description |
44
+ | --- | --- | --- |
45
+ | `selector` | – | CSS selector or element. A `<textarea>` is recommended. |
46
+ | `height` / `minHeight` | auto / `240` | Fixed height, or minimum height of an auto-growing editor. |
47
+ | `content` | textarea value | Initial HTML. |
48
+ | `placeholder` | – | Text shown while the editor is empty. |
49
+ | `language` | browser language | `"en"`, `"tr"`, a language added with `WDSEditor.addLanguage`, or a messages object. |
50
+ | `theme` | `"light"` | `"light"`, `"dark"` or `"auto"`. |
51
+ | `toolbar` | `"default"` | `"bold italic \| link"`, an array of item names, or `false`. |
52
+ | `branding` | `true` | Shows the "Powered by WDS Editor" link. |
53
+ | `wordCount` | `true` | Shows the word and character counter. |
54
+ | `readOnly` | `false` | Starts in read-only mode. |
55
+ | `fileManager` | – | Enables the file manager, see below. |
56
+ | `colors` | built-in palettes | `{ text: ['#dc2626', ...], highlight: ['#fef08a', ...] }`, hex colors only. |
57
+ | `onChange` | – | `(html, editor) => void` |
58
+
59
+ Toolbar items: `undo redo blocks bold italic underline strike code textColor highlight link image file table blockquote bulletList orderedList outdent indent alignLeft alignCenter alignRight alignJustify hr clear pasteText source fullscreen`.
60
+
61
+ ## Tables, images and paste
62
+
63
+ - **Tables:** the table button shows a size picker; inside a table it opens the row / column menu
64
+ (insert, delete, header row / column, merge and split cells, delete table). Drag across cells to select them.
65
+ `Tab` moves to the next cell and adds a row in the last one.
66
+ - **Images:** click to select, drag the corner handle to resize, double-click for alt text, width, alignment and
67
+ **caption** (`<figure>` + `<figcaption>`). Alignment is written as inline styles, so it works on any site.
68
+ - **Colors:** text color and highlight use a small palette (10 text colors, 6 highlights) so content stays
69
+ consistent. Output: `<span style="color: #2563eb">` and `<mark style="background-color: #fef08a">`.
70
+ Pasted colors are kept only when they are real colors (black text and white backgrounds are dropped).
71
+ - **Paste:** Word and Google Docs noise is removed automatically. The paste-as-text button (or `Ctrl+Shift+V`)
72
+ inserts plain paragraphs only.
73
+
74
+ ## File manager
75
+
76
+ Point the editor at an endpoint that returns your files as JSON. Upload and delete are optional.
77
+
78
+ ```js
79
+ WDSEditor.init({
80
+ selector: '#content',
81
+ fileManager: {
82
+ listUrl: '/files/list', // required (a static /files.json works too)
83
+ uploadUrl: '/files/upload', // optional: shows the Upload button, enables paste / drop uploads
84
+ deleteUrl: '/files/delete', // optional: shows the Delete button
85
+ headers: { 'X-CSRF-TOKEN': token },
86
+ withCredentials: false,
87
+ accept: 'image/*' // what the image button lists (default image/*)
88
+ }
89
+ });
90
+ ```
91
+
92
+ The image button opens the file manager (or a URL dialog without one). The file button lists every file
93
+ and inserts a link. Double-click an image in the content to edit its alt text, width and alignment.
94
+
95
+ ### JSON contract (v1)
96
+
97
+ `GET {listUrl}?path=/&q=&page=1`
98
+
99
+ ```json
100
+ {
101
+ "path": "/",
102
+ "folders": [{ "name": "blog", "path": "/blog" }],
103
+ "files": [
104
+ { "url": "/uploads/cover.jpg", "name": "cover.jpg", "size": 184320, "type": "image/jpeg",
105
+ "width": 1200, "height": 800, "thumb": "/uploads/thumbs/cover.jpg", "modified": "2026-12-01T10:20:00Z" }
106
+ ],
107
+ "hasMore": false
108
+ }
109
+ ```
110
+
111
+ - Only `files[].url` and `files[].name` are required. A plain array of files works too.
112
+ - Echo `"q"` when your server searches; otherwise the editor filters the loaded list by name.
113
+ - `hasMore: true` shows a "Load more" button that requests the next `page`.
114
+
115
+ `POST {uploadUrl}` (multipart: `file`, `path`) returns `{ "file": { ...file object } }`.
116
+ `POST {deleteUrl}` (JSON: `{ "url": "..." }`) returns `{ "ok": true }`.
117
+ Errors: any 4xx/5xx status, optionally with `{ "error": "Message" }`, which is shown to the user.
118
+
119
+ ### Server examples
120
+
121
+ Ready to copy, in [`examples/`](examples):
122
+
123
+ - [`node`](examples/node): no dependencies, works with `node:http`, Express and Connect (covered by the test suite)
124
+ - [`aspnetcore`](examples/aspnetcore): minimal API
125
+ - [`php`](examples/php): one file, no framework
126
+ - [`static`](examples/static): a hand-written `files.json`
127
+
128
+ Each keeps paths inside the upload folder, allows only listed extensions (no SVG), limits the size, cleans file
129
+ names and never overwrites files. **Add your own authentication before going live.**
130
+
131
+ ## API
132
+
133
+ ```js
134
+ editor.getHTML(); // clean HTML ("" when empty)
135
+ editor.setHTML('<p>Hi</p>');
136
+ editor.insertHTML('<strong>at cursor</strong>');
137
+ editor.insertImage({ src: '/img/a.jpg', alt: 'A', width: 400, align: 'center' });
138
+ editor.insertImage({ src: '/img/b.jpg', alt: 'B', caption: true }); // <figure>
139
+ editor.openFileManager('image'); // or 'file'
140
+ editor.togglePlainPaste(true);
141
+ editor.getText();
142
+ editor.isEmpty();
143
+ editor.focus();
144
+ editor.setReadOnly(true);
145
+ editor.toggleSource();
146
+ editor.toggleFullscreen();
147
+ editor.on('change', (e) => console.log(e.getHTML()));
148
+ editor.on('upload', (e, file) => console.log('uploaded', file.url));
149
+ editor.on('fileSelect', (e, file) => console.log('inserted', file.url));
150
+ editor.destroy();
151
+
152
+ WDSEditor.initAll('.wds'); // every matching element
153
+ WDSEditor.get(element); // existing instance
154
+ WDSEditor.version;
155
+ ```
156
+
157
+ ## Keyboard and markdown shortcuts
158
+
159
+ `Ctrl+B / I / U`, `Ctrl+K` (link), `Ctrl+Z / Y`, `Tab / Shift+Tab` in lists.
160
+ Typing `# ` … `#### ` makes a heading, `> ` a quote, `- ` or `1. ` a list, three backticks a code block and `---` a rule.
161
+
162
+ ## Security
163
+
164
+ Pasted and loaded HTML is parsed into a strict schema: scripts, event handlers, styles and unknown tags are dropped,
165
+ and `javascript:` style URLs are rejected. Always sanitize HTML on the server as well.
166
+
167
+ **Content Security Policy:** the editor needs no `unsafe-eval` and no inline scripts. Colors, image alignment and
168
+ image width are written as `style` attributes, so a strict CSP needs `style-src 'self' 'unsafe-inline'`
169
+ (or at least `style-src-attr 'unsafe-inline'`) on the page with the editor.
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ npm install
175
+ npm run dev # demo with a working file manager (files go to .dev-uploads/)
176
+ npm test # unit tests (Vitest + jsdom)
177
+ npm run e2e # browser tests in the installed Microsoft Edge, desktop + phone size
178
+ npm run e2e:all # also Chromium, Firefox, WebKit (run "npx playwright install" once first)
179
+ npm run build # dist/: ESM, UMD, IIFE (wds-editor.min.js), CSS, types
180
+ ```
181
+
182
+ ## License
183
+
184
+ MIT © WebDevSnippets
@@ -0,0 +1,13 @@
1
+ /** Color helpers for the text color / highlight marks. Everything is stored as lower-case "#rrggbb". */
2
+ /** "#F00", "rgb(255, 0, 0)", "rgb(255 0 0)", "red" -> "#ff0000". Transparent or unknown values -> null. */
3
+ export declare function normalizeColor(value: string | null | undefined): string | null;
4
+ /** Pasted text colors that are just "the default" are dropped (Word and Google Docs put black on everything). */
5
+ export declare function textColorFromCss(value: string | null | undefined): string | null;
6
+ export declare function highlightFromCss(value: string | null | undefined): string | null;
7
+ export interface Swatch {
8
+ color: string;
9
+ /** i18n key or plain name used as the accessible label. */
10
+ name: string;
11
+ }
12
+ export declare const DEFAULT_TEXT_COLORS: Swatch[];
13
+ export declare const DEFAULT_HIGHLIGHT_COLORS: Swatch[];
@@ -0,0 +1,55 @@
1
+ import type { MarkType, NodeType } from 'prosemirror-model';
2
+ import { type Command, type EditorState, type Transaction } from 'prosemirror-state';
3
+ import { type Node as PMNode } from 'prosemirror-model';
4
+ import { type Align } from './schema';
5
+ export type BlockKind = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'codeBlock';
6
+ export declare function markActive(state: EditorState, type: MarkType): boolean;
7
+ /** The block style of the textblock that holds the cursor, used by the style dropdown. */
8
+ export declare function currentBlock(state: EditorState): BlockKind | null;
9
+ export declare function setBlock(kind: BlockKind): Command;
10
+ export declare const toggle: (name: "strong" | "em" | "underline" | "strike" | "code") => Command;
11
+ /** Inside a node of this type somewhere up the tree? */
12
+ export declare function inside(state: EditorState, type: NodeType): boolean;
13
+ /** Type of the closest list around the cursor (bullet_list / ordered_list) or null. */
14
+ export declare function nearestList(state: EditorState): NodeType | null;
15
+ /** Lists toggle: clicking the active list type unwraps it, another list type converts it. */
16
+ export declare function toggleList(type: NodeType): Command;
17
+ export declare const indent: Command;
18
+ export declare const outdent: Command;
19
+ export declare function toggleBlockquote(): Command;
20
+ /** Alignment applies to every paragraph and heading touched by the selection. */
21
+ export declare function setAlign(align: Align): Command;
22
+ export declare function currentAlign(state: EditorState): Align;
23
+ export declare const insertHorizontalRule: Command;
24
+ /** Removes inline marks (keeps links) and turns headings / code blocks back into paragraphs. */
25
+ export declare const clearFormatting: Command;
26
+ /** Range of the link mark around the cursor (or the selection), used to edit or remove a link. */
27
+ export declare function linkRange(state: EditorState): {
28
+ from: number;
29
+ to: number;
30
+ href: string;
31
+ title: string | null;
32
+ target: string | null;
33
+ } | null;
34
+ /** The selected image or figure (click on an image selects it). */
35
+ export declare function selectedImage(state: EditorState): {
36
+ pos: number;
37
+ attrs: Record<string, unknown>;
38
+ figure: boolean;
39
+ node: PMNode;
40
+ } | null;
41
+ /** Inline image -> figure with an (empty) caption. The cursor moves into the caption. */
42
+ export declare function imageToFigure(tr: Transaction, pos: number, attrs: Record<string, unknown>): Transaction;
43
+ /** Figure -> paragraph with the inline image; a non-empty caption becomes the next paragraph. */
44
+ export declare function figureToImage(tr: Transaction, pos: number, figure: PMNode, attrs: Record<string, unknown>): Transaction;
45
+ /** A rows x cols table, the first row as header cells. */
46
+ export declare function createTable(rows: number, cols: number, header?: boolean): PMNode;
47
+ /** Inserts a table at the cursor and puts the cursor in its first cell. A paragraph follows a table at the end. */
48
+ export declare function insertTable(rows: number, cols: number): Command;
49
+ /** Tab in the last cell adds a row, like word processors do. */
50
+ export declare const nextCellOrAddRow: Command;
51
+ export declare const previousCell: Command;
52
+ /** Color of the text color / highlight mark at the cursor or across the selection (null when mixed or none). */
53
+ export declare function markColor(state: EditorState, name: 'textColor' | 'highlight'): string | null;
54
+ /** Applies (or with null removes) a text color / highlight; with an empty selection it applies to what is typed next. */
55
+ export declare function setMarkColor(name: 'textColor' | 'highlight', color: string | null): Command;
@@ -0,0 +1,152 @@
1
+ import { type Command } from 'prosemirror-state';
2
+ import { EditorView } from 'prosemirror-view';
3
+ import { Slice } from 'prosemirror-model';
4
+ import { type ImageAlign } from './schema';
5
+ import { type Swatch } from './color';
6
+ import { addLanguage, type Messages } from './i18n';
7
+ import { type FileItem, type FileManagerOptions } from './filemanager/api';
8
+ export type { FileManagerOptions, FileItem };
9
+ export type Theme = 'light' | 'dark' | 'auto';
10
+ export interface WDSEditorOptions {
11
+ /** CSS selector or element: a <textarea> (recommended, keeps forms working) or any container element. */
12
+ selector?: string | HTMLElement;
13
+ /** Fixed height of the editing area (px number or CSS value). Without it the editor grows with its content. */
14
+ height?: number | string;
15
+ /** Minimum height of the editing area when no fixed height is set. Default 240. */
16
+ minHeight?: number | string;
17
+ /** Initial HTML. Defaults to the textarea value / container content. */
18
+ content?: string;
19
+ placeholder?: string;
20
+ /** "en", "tr", any language added with WDSEditor.addLanguage, or a messages object. Defaults to the browser language. */
21
+ language?: string | Partial<Messages>;
22
+ theme?: Theme;
23
+ /** "default", a space separated string ("bold italic | link") or an array of item names. "|" groups items. */
24
+ toolbar?: 'default' | string | string[] | false;
25
+ /** Show the "Powered by WDS Editor" link in the status bar. Default true. */
26
+ branding?: boolean;
27
+ /** Show the word / character counter. Default true. */
28
+ wordCount?: boolean;
29
+ readOnly?: boolean;
30
+ /** Color palettes: hex colors or {color, name}. Defaults: 10 text colors, 6 highlight colors. */
31
+ colors?: {
32
+ text?: Array<string | Swatch>;
33
+ highlight?: Array<string | Swatch>;
34
+ };
35
+ /** Enables the file manager (image / file buttons, paste and drop uploads). See README "File manager". */
36
+ fileManager?: FileManagerOptions;
37
+ onChange?: (html: string, editor: WDSEditor) => void;
38
+ }
39
+ export type EditorEvent = 'change' | 'focus' | 'blur' | 'init' | 'destroy' | 'upload' | 'fileSelect';
40
+ /** "upload" and "fileSelect" pass the file object ({url, name, ...}) as the second argument. */
41
+ type Listener = (editor: WDSEditor, detail?: unknown) => void;
42
+ export interface ImageAttrs {
43
+ src: string;
44
+ alt?: string;
45
+ title?: string | null;
46
+ width?: number | null;
47
+ height?: number | null;
48
+ align?: ImageAlign | null;
49
+ }
50
+ export declare class WDSEditor {
51
+ static readonly version: string;
52
+ /** Adds or extends a UI language: WDSEditor.addLanguage('de', { bold: 'Fett' }). */
53
+ static readonly addLanguage: typeof addLanguage;
54
+ /** Creates (or returns the existing) editor for the first element matching options.selector. */
55
+ static init(options: WDSEditorOptions): WDSEditor;
56
+ /** Creates editors for every element matching options.selector. */
57
+ static initAll(options: WDSEditorOptions & {
58
+ selector: string;
59
+ }): WDSEditor[];
60
+ /** Returns the editor attached to an element (or selector), if any. */
61
+ static get(target: string | HTMLElement): WDSEditor | undefined;
62
+ readonly root: HTMLElement;
63
+ readonly view: EditorView;
64
+ readonly t: Messages;
65
+ private readonly target;
66
+ private readonly textarea;
67
+ private readonly options;
68
+ private readonly contentWrap;
69
+ private readonly sourceArea;
70
+ private readonly counter;
71
+ private readonly toolbar;
72
+ private readonly listeners;
73
+ private readonly originalContent;
74
+ private readonly fileManager;
75
+ private notice;
76
+ private noticeTimer;
77
+ private readonly onFormSubmit;
78
+ private readonly onKeydown;
79
+ private sourceMode;
80
+ private plainPaste;
81
+ private fullscreen;
82
+ private readOnly;
83
+ private destroyed;
84
+ private lastHtml;
85
+ constructor(target: HTMLElement, options?: WDSEditorOptions);
86
+ getHTML(): string;
87
+ /** Replaces the whole content. The change can be undone. */
88
+ setHTML(html: string): void;
89
+ /** Inserts HTML at the cursor (replacing the selection). */
90
+ insertHTML(html: string): void;
91
+ getText(): string;
92
+ isEmpty(): boolean;
93
+ focus(): void;
94
+ setReadOnly(value: boolean): void;
95
+ isReadOnly(): boolean;
96
+ /** Runs a ProseMirror command against the editor. Returns whether it applied. */
97
+ exec(command: Command): boolean;
98
+ undo(): void;
99
+ redo(): void;
100
+ isSourceMode(): boolean;
101
+ toggleSource(): void;
102
+ isFullscreen(): boolean;
103
+ toggleFullscreen(): void;
104
+ openLinkDialog(): void;
105
+ removeLink(): void;
106
+ /** True when a file manager (listUrl) is configured. */
107
+ hasFileManager(): boolean;
108
+ /** Inserts an image at the cursor (replacing the selection). caption: true wraps it in <figure>. Unsafe sources are ignored. */
109
+ insertImage(attrs: ImageAttrs & {
110
+ caption?: boolean;
111
+ }): boolean;
112
+ /**
113
+ * Image button: edits the selected image, otherwise opens the file manager (when configured)
114
+ * or the "image by URL" dialog.
115
+ */
116
+ openImageDialog(): void;
117
+ /** Opens the file manager. "image" lists images (accept option, default image/*), "file" lists every file. */
118
+ openFileManager(mode?: 'image' | 'file'): void;
119
+ /** Dialog for an image by URL, or for editing the selected image (alt text, width, alignment). */
120
+ private openImageUrlDialog;
121
+ /** Table button: a size picker outside tables, the row / column menu inside one. */
122
+ openTableMenu(anchor: HTMLElement): void;
123
+ /** Opens the text color or highlight palette under the given toolbar button. */
124
+ openColorPicker(kind: 'textColor' | 'highlight', anchor: HTMLElement): void;
125
+ /** When on, pasted content is inserted as plain text (paragraphs and line breaks only). */
126
+ togglePlainPaste(value?: boolean): void;
127
+ isPlainPaste(): boolean;
128
+ /** Inserts a link to a file: links the selected text, or inserts the text (default: file name). */
129
+ insertFileLink(file: {
130
+ url: string;
131
+ name: string;
132
+ }, text?: string): void;
133
+ private canUploadInline;
134
+ /**
135
+ * Uploads files to the current file manager folder and inserts them at pos (default: the cursor).
136
+ * Images become <img>, other files become links. A placeholder shows where each file will land.
137
+ */
138
+ uploadFiles(files: File[], pos?: number): void;
139
+ /** Short message over the bottom of the editing area (upload errors). */
140
+ private showNotice;
141
+ on(event: EditorEvent, listener: Listener): this;
142
+ off(event: EditorEvent, listener: Listener): this;
143
+ /** Removes the editor and restores the original element (the textarea keeps the latest HTML). */
144
+ destroy(): void;
145
+ private dispatch;
146
+ private applySource;
147
+ private syncTarget;
148
+ private refresh;
149
+ private emit;
150
+ }
151
+ /** Plain text -> paragraphs (blank lines) with hard breaks (single new lines). */
152
+ export declare function plainTextSlice(text: string): Slice;
@@ -0,0 +1,69 @@
1
+ export interface FileItem {
2
+ url: string;
3
+ name: string;
4
+ size?: number;
5
+ type?: string;
6
+ width?: number;
7
+ height?: number;
8
+ thumb?: string;
9
+ modified?: string;
10
+ }
11
+ export interface FolderItem {
12
+ name: string;
13
+ path: string;
14
+ }
15
+ export interface FileListResult {
16
+ path: string;
17
+ folders: FolderItem[];
18
+ files: FileItem[];
19
+ hasMore: boolean;
20
+ /** The server applied the search itself (it echoed "q"). Otherwise the editor filters by name. */
21
+ serverSearch: boolean;
22
+ }
23
+ export interface FileManagerOptions {
24
+ /** GET endpoint (or static .json file) returning the file list. Required to enable the file manager. */
25
+ listUrl: string;
26
+ /** Optional multipart POST endpoint for uploads. */
27
+ uploadUrl?: string;
28
+ /** Optional JSON POST endpoint for deleting a file. */
29
+ deleteUrl?: string;
30
+ /** Extra request headers, e.g. a CSRF token. */
31
+ headers?: Record<string, string>;
32
+ /** Send cookies with cross-origin requests. */
33
+ withCredentials?: boolean;
34
+ /** Which files the image button shows. Default "image/*". */
35
+ accept?: string;
36
+ }
37
+ export declare function normalizeFile(raw: unknown): FileItem | null;
38
+ /** Accepts the full object form or a plain array and drops entries that break the contract. */
39
+ export declare function normalizeList(data: unknown, requestedPath?: string): FileListResult;
40
+ /** "/a//b/" -> "/a/b"; never returns ".." segments. */
41
+ export declare function normalizePath(path: string): string;
42
+ export declare function fileType(file: {
43
+ name: string;
44
+ type?: string;
45
+ }): string;
46
+ export declare function isImage(file: {
47
+ name: string;
48
+ type?: string;
49
+ url?: string;
50
+ }): boolean;
51
+ /** Same rules as <input accept>: "image/*", "application/pdf", ".pdf", comma separated. Empty accepts everything. */
52
+ export declare function matchesAccept(file: {
53
+ name: string;
54
+ type?: string;
55
+ }, accept: string | undefined): boolean;
56
+ export declare function formatSize(bytes: number | undefined): string;
57
+ export declare class FileApiError extends Error {
58
+ }
59
+ export declare class FileApi {
60
+ private readonly options;
61
+ constructor(options: FileManagerOptions);
62
+ get canUpload(): boolean;
63
+ get canDelete(): boolean;
64
+ private init;
65
+ list(path: string, q: string, page: number, signal?: AbortSignal): Promise<FileListResult>;
66
+ /** Multipart upload with progress (XMLHttpRequest, because fetch has no upload progress). */
67
+ upload(file: File, path: string, onProgress?: (fraction: number) => void): Promise<FileItem>;
68
+ remove(url: string): Promise<void>;
69
+ }
@@ -0,0 +1,40 @@
1
+ import { FileApi, type FileItem } from './api';
2
+ import { type Messages } from '../i18n';
3
+ import type { ImageAlign } from '../schema';
4
+ export interface PickResult {
5
+ file: FileItem;
6
+ /** Images: alternative text. */
7
+ alt: string;
8
+ /** Images: display width in px, null keeps the natural size. */
9
+ width: number | null;
10
+ align: ImageAlign | null;
11
+ /** Other files: link text. */
12
+ text: string;
13
+ /** Images: wrap in <figure> with a caption. */
14
+ caption: boolean;
15
+ }
16
+ export interface FileManagerOpenOptions {
17
+ /** Which files are listed and can be uploaded ("image/*", ".pdf", ...). Empty = all. */
18
+ accept?: string;
19
+ /** "image" shows image options (alt, width, align), "file" shows the link text. */
20
+ mode: 'image' | 'file';
21
+ onPick: (result: PickResult) => void;
22
+ /** Shows an "Insert from URL" button. */
23
+ onFromUrl?: () => void;
24
+ onUpload?: (file: FileItem) => void;
25
+ onClose?: () => void;
26
+ }
27
+ /**
28
+ * Modal file browser over the JSON contract. One instance per editor: the current folder,
29
+ * view mode and sort order are remembered between openings.
30
+ */
31
+ export declare class FileManager {
32
+ private readonly host;
33
+ readonly api: FileApi;
34
+ private readonly t;
35
+ path: string;
36
+ private view;
37
+ private sort;
38
+ constructor(host: HTMLElement, api: FileApi, t: Messages);
39
+ open(options: FileManagerOpenOptions): () => void;
40
+ }
@@ -0,0 +1,16 @@
1
+ import { type Node as PMNode } from 'prosemirror-model';
2
+ /**
3
+ * Parses an HTML string into a document. The string is parsed in an inert document
4
+ * (scripts never run, images never load) and then filtered by the schema.
5
+ */
6
+ export declare function parseHtml(html: string): PMNode;
7
+ export declare function serializeHtml(doc: PMNode): string;
8
+ /** "color: rgb(37, 99, 235); margin: 0px 0px 1em;" -> "color: #2563eb; margin: 0 0 1em" */
9
+ export declare function tidyStyle(style: string): string;
10
+ export declare function isEmptyDoc(doc: PMNode): boolean;
11
+ /**
12
+ * Pretty-printing for the source view: one block per line, lists, quotes and tables indented,
13
+ * and list items or table cells with a single paragraph kept on one line. Text inside blocks is not touched,
14
+ * so the HTML parses back to the same document.
15
+ */
16
+ export declare function formatHtml(html: string): string;