@lvl99dotcom/edaha-editor 0.3.0 → 0.4.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.
Files changed (37) hide show
  1. package/README.md +8 -1
  2. package/dist/client/assets/index--k7n6Qb8.css +1 -0
  3. package/dist/client/assets/{index-BwcJ6yrI.js → index-owkKXGfS.js} +140 -126
  4. package/dist/client/index.html +2 -2
  5. package/dist/client-lib/index.js +4037 -0
  6. package/dist/client-lib/style.css +1569 -0
  7. package/dist/editor/index.d.ts +24 -1
  8. package/dist/editor/index.js +15 -1
  9. package/dist/server/store/index.d.ts +2 -1
  10. package/dist/server/store/index.js +4 -3
  11. package/dist/types/client/components/define/index.d.ts +7 -0
  12. package/dist/types/client/components/edaha-article/index.d.ts +380 -0
  13. package/dist/types/client/components/edaha-article-browser/index.d.ts +162 -0
  14. package/dist/types/client/components/edaha-article-data-field/index.d.ts +121 -0
  15. package/dist/types/client/components/edaha-article-data-group/index.d.ts +40 -0
  16. package/dist/types/client/components/edaha-editor/index.d.ts +289 -0
  17. package/dist/types/client/components/edaha-embed-dialog/index.d.ts +84 -0
  18. package/dist/types/client/components/edaha-file-browser/index.d.ts +203 -0
  19. package/dist/types/client/components/edaha-markdown/index.d.ts +70 -0
  20. package/dist/types/client/components/edaha-metadata-field/index.d.ts +100 -0
  21. package/dist/types/client/components/edaha-richtext/index.d.ts +88 -0
  22. package/dist/types/client/components/edaha-toasts/index.d.ts +47 -0
  23. package/dist/types/client/dates/index.d.ts +14 -0
  24. package/dist/types/client/editorApi/index.d.ts +129 -0
  25. package/dist/types/client/embeds/index.d.ts +74 -0
  26. package/dist/types/client/icons/index.d.ts +60 -0
  27. package/dist/types/client/index.d.ts +2 -0
  28. package/dist/types/client/markdown/index.d.ts +163 -0
  29. package/dist/types/client/metadataForm/index.d.ts +77 -0
  30. package/dist/types/client/narrow/index.d.ts +21 -0
  31. package/dist/types/client/richtext/editor/index.d.ts +34 -0
  32. package/dist/types/client/richtext/extensions/index.d.ts +90 -0
  33. package/dist/types/client/sortTable/index.d.ts +24 -0
  34. package/dist/types/client/theme/index.d.ts +48 -0
  35. package/dist/types/server/types/index.d.ts +251 -0
  36. package/package.json +15 -10
  37. package/dist/client/assets/index-D2Y17Fm-.css +0 -1
@@ -0,0 +1,203 @@
1
+ import { LitElement } from "lit";
2
+ import type { ArticleOrder, ArticleTypeLabels, FileChange, FileFilters, FileKind, FilePage, FileSort, FileSummary } from "../../../server/types/index.ts";
3
+ import type { EditorApi } from "../../editorApi/index.ts";
4
+ /** The kinds of files, as the file browser names them */
5
+ export declare const FILE_KINDS: readonly {
6
+ value: FileKind;
7
+ label: string;
8
+ }[];
9
+ /** The results' sortable columns (Operations isn't sortable) */
10
+ export declare const FILE_COLUMNS: readonly {
11
+ sort: FileSort;
12
+ label: string;
13
+ }[];
14
+ /** The event fired after a file is replaced or deleted (detail: the file and what changed) */
15
+ export declare const FILES_CHANGED_EVENT = "files-changed";
16
+ /** Detail of the `files-changed` event */
17
+ export interface FilesChanged extends FileChange {
18
+ /** The file that was replaced or deleted */
19
+ file: FileSummary;
20
+ }
21
+ /** A file chosen for an article: how the article refers to it, its name, and its kind */
22
+ export interface ChosenFile {
23
+ /** How the article refers to it (or, in the rich text editor, the URL showing it) */
24
+ url: string;
25
+ name: string;
26
+ kind: FileKind;
27
+ }
28
+ /** Lets the user choose an existing file (first showing files of a kind, if given); undefined if none was chosen */
29
+ export type FileChooser = (kind?: FileKind) => Promise<ChosenFile | undefined>;
30
+ /**
31
+ * The kind of files a file input's `accept` takes, when it only takes images.
32
+ *
33
+ * @example
34
+ * acceptedKind("image/png, image/jpeg"); // "image"
35
+ * acceptedKind("image/png, application/pdf"); // undefined
36
+ */
37
+ export declare const acceptedKind: (accept?: string) => FileKind | undefined;
38
+ /**
39
+ * A file size for people: bytes, kilobytes, megabytes or gigabytes (1 KB = 1024 bytes), with one decimal below 10.
40
+ *
41
+ * @example
42
+ * formatFileSize(512); // "512 B"
43
+ * formatFileSize(1536); // "1.5 KB"
44
+ * formatFileSize(5 * 1024 ** 3); // "5 GB"
45
+ */
46
+ export declare const formatFileSize: (bytes: number) => string;
47
+ /**
48
+ * The file browser: a dialog listing the files in the articles' folders, 50 at a time, found by name and filtered by
49
+ * kind and article type, in a table whose column headings sort it. Each file can be opened, its website path copied,
50
+ * replaced with another file, or deleted; replacing and deleting update references to it in every article, and fire
51
+ * `files-changed` (detail: {@link FilesChanged}). Rendered in the light DOM.
52
+ *
53
+ * Opened with `pick`, it also lets the user choose a file (e.g. to insert into an article), and gives the chosen file.
54
+ *
55
+ * @example
56
+ * html`<edaha-file-browser .api=${api} .types=${types}></edaha-file-browser>`
57
+ * browser.show();
58
+ * const file = await browser.pick("image");
59
+ */
60
+ export declare class EdahaFileBrowser extends LitElement {
61
+ static properties: {
62
+ api: {
63
+ attribute: boolean;
64
+ };
65
+ types: {
66
+ attribute: boolean;
67
+ };
68
+ search: {
69
+ state: boolean;
70
+ };
71
+ kind: {
72
+ state: boolean;
73
+ };
74
+ type: {
75
+ state: boolean;
76
+ };
77
+ sort: {
78
+ state: boolean;
79
+ };
80
+ order: {
81
+ state: boolean;
82
+ };
83
+ page: {
84
+ state: boolean;
85
+ };
86
+ result: {
87
+ state: boolean;
88
+ };
89
+ filters: {
90
+ state: boolean;
91
+ };
92
+ loading: {
93
+ state: boolean;
94
+ };
95
+ message: {
96
+ state: boolean;
97
+ };
98
+ error: {
99
+ state: boolean;
100
+ };
101
+ picking: {
102
+ state: boolean;
103
+ };
104
+ };
105
+ api: EditorApi;
106
+ /** The configured article types' labels */
107
+ types: Record<string, ArticleTypeLabels>;
108
+ search: string;
109
+ kind: string;
110
+ type: string;
111
+ /** The column the results are sorted by (undefined: by location, then name) */
112
+ sort?: FileSort | undefined;
113
+ order?: ArticleOrder | undefined;
114
+ page: number;
115
+ /** The files found, once loaded */
116
+ result?: FilePage | undefined;
117
+ filters: FileFilters;
118
+ loading: boolean;
119
+ /** What the last operation did, e.g. "Copied /news/hello/photo.png" */
120
+ message: string;
121
+ error: string;
122
+ /** While choosing a file with `pick`: gives the chosen file (or undefined) */
123
+ picking?: ((file?: FileSummary) => void) | undefined;
124
+ /** How long to wait after typing in the search before searching, in ms (replaceable for tests) */
125
+ searchDelay: number;
126
+ /** Asks to confirm replacing or deleting (replaceable for tests) */
127
+ confirm: (message: string) => boolean;
128
+ /**
129
+ * Copy text to the clipboard: with the Clipboard API, or where it isn't allowed, by selecting the text in a hidden
130
+ * text box inside the dialog (the page behind it can't be focused). Rejects if neither works.
131
+ */
132
+ copy: (text: string) => Promise<void>;
133
+ /** The waiting search, if any */
134
+ private searchTimer?;
135
+ /** Counts searches, so only the latest one's result is shown */
136
+ private searches;
137
+ /** The file being replaced, while its replacement is chosen */
138
+ private replacing?;
139
+ constructor();
140
+ protected createRenderRoot(): this;
141
+ /** The dialog, once rendered */
142
+ private get dialog();
143
+ /** Whether the browser is open */
144
+ get open(): boolean;
145
+ /** Open the browser with its filters cleared, on the first page, with focus in the search field */
146
+ show(): Promise<void>;
147
+ /** Open the browser with its filters cleared but for the kind, on the first page, with focus in the search field */
148
+ private openWith;
149
+ /**
150
+ * Open the browser to choose a file (first showing files of a kind, if given). Resolves with the chosen file, or
151
+ * undefined if the browser is closed without choosing one.
152
+ *
153
+ * @example
154
+ * const image = await browser.pick("image");
155
+ */
156
+ pick(kind?: FileKind | ""): Promise<FileSummary | undefined>;
157
+ /** Stop choosing a file, giving the chosen one (or undefined) */
158
+ private finishPicking;
159
+ /** Choose a file while picking, closing the browser */
160
+ private chooseFile;
161
+ /** Close the browser */
162
+ close(): void;
163
+ /** Load the filters' choices (keeping the last ones if it fails) */
164
+ private loadFilters;
165
+ /** Find the files for the current search, filters, sort and page */
166
+ load(): Promise<void>;
167
+ /** Change a filter, going back to the first page */
168
+ private choose;
169
+ /** Search once typing pauses, from the first page */
170
+ private onSearch;
171
+ /** Sort by a column (see `nextSort`), going back to the first page */
172
+ private sortBy;
173
+ /** Show another page, from its top */
174
+ private goTo;
175
+ /** Show what an operation did, or its error */
176
+ private report;
177
+ /** Copy a file's path on the website */
178
+ copyUrl(file: FileSummary): Promise<void>;
179
+ /** Choose a file to replace another with (it is replaced once chosen) */
180
+ private chooseReplacement;
181
+ /** Tell the editor a file was replaced or deleted, and show the files again */
182
+ private changed;
183
+ /**
184
+ * Replace a file with another, after confirming (saying how many articles refer to it, which then refer to the new
185
+ * file if its name differs).
186
+ */
187
+ replace(file: FileSummary, replacement: File): Promise<void>;
188
+ /**
189
+ * Delete a file after confirming (saying how many articles refer to it, which then don't).
190
+ */
191
+ delete(file: FileSummary): Promise<void>;
192
+ /** Render a select filter with an "any" choice first */
193
+ private renderSelect;
194
+ /** Render an operation's icon button, named for screen readers and as a tooltip */
195
+ private renderOperation;
196
+ /** Render the found files as a table */
197
+ private renderResults;
198
+ /** Render the page buttons, when there is more than one page */
199
+ private renderPages;
200
+ /** What the status line says: an error, what an operation did, loading, or how many files were found */
201
+ private statusText;
202
+ render(): import("lit").TemplateResult<1>;
203
+ }
@@ -0,0 +1,70 @@
1
+ import { LitElement } from "lit";
2
+ import type { ImageUploader } from "../edaha-richtext/index.ts";
3
+ import type { FileChooser } from "../edaha-file-browser/index.ts";
4
+ import { type EmbedTools } from "../../embeds/index.ts";
5
+ import { type TextEdit } from "../../markdown/index.ts";
6
+ /**
7
+ * Markdown editor for an article body: a text box with a toolbar that has the same buttons as the rich text editor's.
8
+ * The buttons write Markdown, or HTML where Markdown has nothing for it (small and big text, details blocks). Rendered
9
+ * in the light DOM, so its text box can be labelled by the field's label (give it `textareaId`). Fires
10
+ * `markdown-change` when the text changes; read it from `value`.
11
+ *
12
+ * @example
13
+ * html`<edaha-markdown .value=${markdown} .textareaId=${"field-body"} @markdown-change=${onChange}></edaha-markdown>`
14
+ */
15
+ export declare class EdahaMarkdown extends LitElement {
16
+ static properties: {
17
+ value: {
18
+ attribute: boolean;
19
+ };
20
+ textareaId: {
21
+ attribute: boolean;
22
+ };
23
+ uploadImage: {
24
+ attribute: boolean;
25
+ };
26
+ chooseFile: {
27
+ attribute: boolean;
28
+ };
29
+ embedTools: {
30
+ attribute: boolean;
31
+ };
32
+ };
33
+ /** The Markdown */
34
+ value: string;
35
+ /** The text box's id, for its label */
36
+ textareaId: string;
37
+ /** Uploads an image file and returns how to refer to it in Markdown; without it, the upload button is disabled */
38
+ uploadImage?: ImageUploader | undefined;
39
+ /** Lets the user choose an existing file, giving how to refer to it; without it, its button is disabled */
40
+ chooseFile?: FileChooser | undefined;
41
+ /** The site's embeds and the embed dialog; without them, the embed button is disabled */
42
+ embedTools?: EmbedTools | undefined;
43
+ /** Asks for a URL (replaceable for tests) */
44
+ prompt: (message: string, value?: string) => string | null;
45
+ constructor();
46
+ protected createRenderRoot(): this;
47
+ /** The toolbar's buttons, in the same order as the rich text editor's */
48
+ private readonly actions;
49
+ /** The text box, once rendered */
50
+ private get textarea();
51
+ /** The text and its selection now */
52
+ private get selection();
53
+ /** Take the text box's text as the value, announcing it if it changed */
54
+ private sync;
55
+ /**
56
+ * Make an edit in the text box: replace only the part that changed, then select what the edit selects. The change is
57
+ * typed in where the browser supports it, so it can be undone like typing.
58
+ */
59
+ apply(edit: TextEdit | undefined): void;
60
+ /** Upload the chosen image and insert it at the cursor */
61
+ private onImageFile;
62
+ /**
63
+ * Ask for an embed's content in the embed dialog (where the selection was when asked): a new embed of a kind,
64
+ * inserted after the selection, or the selected embed block when it is of that kind.
65
+ */
66
+ private editEmbed;
67
+ /** Let the user choose an existing file, and insert it where the selection was when asked */
68
+ private onChooseFile;
69
+ render(): import("lit").TemplateResult<1>;
70
+ }
@@ -0,0 +1,100 @@
1
+ import { LitElement } from "lit";
2
+ import type { MetadataProblem, MetadataSchema } from "@lvl99dotcom/edaha.md/generator/metadata";
3
+ import { type FileChooser } from "../edaha-file-browser/index.ts";
4
+ /** Detail of the `metadata-change` event: the changed value's path (e.g. "credit/name") and its new value */
5
+ export interface MetadataChange {
6
+ path: string;
7
+ value: unknown;
8
+ }
9
+ /** Uploads a file into the article's folder and returns its name */
10
+ export type FileUploader = (file: File) => Promise<string>;
11
+ /**
12
+ * One custom metadata value's field, built from its schema: an input, textarea, select, checkboxes, radio buttons or
13
+ * a file chooser, a group of fields for a map, or a list of fields with Add and Delete buttons. Its label and
14
+ * description come from `$edahaField` (or the schema), and its problems show above it. Rendered in the light DOM.
15
+ *
16
+ * Fires `metadata-change` (detail: {@link MetadataChange}) when the value changes, and `metadata-blur` (detail: the
17
+ * path) when focus leaves the field.
18
+ *
19
+ * @example
20
+ * html`<edaha-metadata-field path="featured" .schema=${schema} .value=${value}></edaha-metadata-field>`
21
+ */
22
+ export declare class EdahaMetadataField extends LitElement {
23
+ static properties: {
24
+ path: {};
25
+ label: {};
26
+ schema: {
27
+ attribute: boolean;
28
+ };
29
+ value: {
30
+ attribute: boolean;
31
+ };
32
+ problems: {
33
+ attribute: boolean;
34
+ };
35
+ hiddenFields: {
36
+ attribute: boolean;
37
+ };
38
+ required: {
39
+ type: BooleanConstructor;
40
+ };
41
+ uploadFile: {
42
+ attribute: boolean;
43
+ };
44
+ chooseFile: {
45
+ attribute: boolean;
46
+ };
47
+ fileUrl: {
48
+ attribute: boolean;
49
+ };
50
+ };
51
+ /** The value's path from the article's settings, e.g. "featured", "credit/name" or "images/2" */
52
+ path: string;
53
+ /** The label, when it isn't the schema's (e.g. "Images 2" for a list's item) */
54
+ label?: string | undefined;
55
+ schema: MetadataSchema;
56
+ value: unknown;
57
+ /** Problems with the article's metadata (those for this value, and inside it, show) */
58
+ problems: MetadataProblem[];
59
+ /** The paths (in dot notation, e.g. "credit.name") of fields hidden by their conditions, which aren't shown */
60
+ hiddenFields: ReadonlySet<string>;
61
+ required: boolean;
62
+ /** Uploads files for file fields; without it they can't be chosen */
63
+ uploadFile?: FileUploader | undefined;
64
+ /** Lets the user choose an existing file for file fields */
65
+ chooseFile?: FileChooser | undefined;
66
+ /** The URL a file name is shown at, for file fields */
67
+ fileUrl?: ((name: string) => string | undefined) | undefined;
68
+ constructor();
69
+ protected createRenderRoot(): this;
70
+ /** Change the value at a path inside this one (or this one), telling the article */
71
+ private change;
72
+ /** The key at the end of the path, e.g. "name" for "credit/name" */
73
+ private get key();
74
+ /** The label shown */
75
+ private get fieldTitle();
76
+ /** Render the description, extra information and problems shown above the input, linked to it by id */
77
+ private renderNotes;
78
+ /** The ids of the notes an input is described by */
79
+ private describedBy;
80
+ /** Render a child field for a map's property or a list's item */
81
+ private renderChild;
82
+ /** Render a map of fields as a group */
83
+ private renderObject;
84
+ /** Render a list of fields, with Delete buttons and an Add button */
85
+ private renderList;
86
+ /** Render a select: a dropdown, a list (`list: true`), and choosing several for a whole list (`multiple: true`) */
87
+ private renderSelect;
88
+ /** Render radio buttons, each with its own description */
89
+ private renderRadio;
90
+ /** Let the user choose an existing file (of the kind the field accepts), and set the value to it */
91
+ private chooseExisting;
92
+ /**
93
+ * Render a file field: the file's name (linked), a chooser that uploads it, a button choosing an existing file, and
94
+ * a button that clears it.
95
+ */
96
+ private renderFile;
97
+ /** Render the input for a single value's field kind (the other kinds are an `<input>` of the same type) */
98
+ private renderInput;
99
+ render(): import("lit").TemplateResult<1>;
100
+ }
@@ -0,0 +1,88 @@
1
+ import type { Editor } from "@tiptap/core";
2
+ import { LitElement, type PropertyValues } from "lit";
3
+ import { type EmbedTools } from "../../embeds/index.ts";
4
+ import { type FileAddress } from "../../richtext/editor/index.ts";
5
+ import type { ChosenFile, FileChooser } from "../edaha-file-browser/index.ts";
6
+ /** Uploads an image and returns the URL to show it at */
7
+ export type ImageUploader = (file: File) => Promise<string>;
8
+ /**
9
+ * Rich text editor for an article body (Tiptap) with a toolbar. Rendered in the light DOM, as ProseMirror needs
10
+ * document selection APIs. Fires `richtext-change` when the content changes (not `input`, which typing in the
11
+ * editable area fires too); read the HTML from `value`.
12
+ *
13
+ * @example
14
+ * html`<edaha-richtext .value=${body} .uploadImage=${upload} @richtext-change=${onChange}></edaha-richtext>`
15
+ */
16
+ export declare class EdahaRichtext extends LitElement {
17
+ static properties: {
18
+ value: {
19
+ attribute: boolean;
20
+ };
21
+ uploadImage: {
22
+ attribute: boolean;
23
+ };
24
+ chooseFile: {
25
+ attribute: boolean;
26
+ };
27
+ embedTools: {
28
+ attribute: boolean;
29
+ };
30
+ fileAddress: {
31
+ attribute: boolean;
32
+ };
33
+ };
34
+ /** The content as HTML */
35
+ value: string;
36
+ /** Uploads an image file; without it, the upload button is disabled */
37
+ uploadImage?: ImageUploader | undefined;
38
+ /** Lets the user choose an existing file, giving the URL to show it at; without it, its button is disabled */
39
+ chooseFile?: FileChooser | undefined;
40
+ /** The site's embeds, the embed dialog, and embed blocks' frames */
41
+ embedTools?: EmbedTools | undefined;
42
+ /** The address images in the body are shown from, for their `src` (e.g. on another page's editor server) */
43
+ fileAddress?: FileAddress | undefined;
44
+ /** The Tiptap editor, once rendered */
45
+ editor?: Editor;
46
+ /**
47
+ * The toolbar that floats above selected text, with its format buttons. The editor shows it and moves it into the
48
+ * editable area's box while text is selected, so it is rendered here rather than in the component's template.
49
+ */
50
+ readonly formatMenu: HTMLElement;
51
+ /** Asks for a URL (replaceable for tests) */
52
+ prompt: (message: string, value?: string) => string | null;
53
+ constructor();
54
+ protected createRenderRoot(): this;
55
+ /** The floating toolbar's buttons, for formatting selected text */
56
+ private readonly formatActions;
57
+ /** The toolbar's buttons */
58
+ private readonly actions;
59
+ /**
60
+ * Add, change or remove (empty URL) the link on the selection.
61
+ */
62
+ private editLink;
63
+ /**
64
+ * Insert an image by URL.
65
+ */
66
+ private insertImageUrl;
67
+ /**
68
+ * Ask for an embed's content in the embed dialog: a new embed of a kind (from its toolbar button), inserted after the
69
+ * selected block, or the selected embed block (from its "Edit" button, or its kind's toolbar button).
70
+ *
71
+ * @param key - the kind of embed to add, from its toolbar button
72
+ */
73
+ private editEmbed;
74
+ /**
75
+ * Upload the chosen image and insert it.
76
+ */
77
+ private onImageFile;
78
+ /**
79
+ * Insert a file: an image as an image, anything else as a link (on the selection, or named after the file).
80
+ */
81
+ insertFile({ url, name, kind }: ChosenFile): void;
82
+ /** Let the user choose an existing file, and insert it */
83
+ private onChooseFile;
84
+ protected firstUpdated(): void;
85
+ protected updated(changed: PropertyValues<this>): void;
86
+ disconnectedCallback(): void;
87
+ render(): import("lit").TemplateResult<1>;
88
+ }
@@ -0,0 +1,47 @@
1
+ import { LitElement } from "lit";
2
+ /** A message shown as a toast */
3
+ export interface ToastMessage {
4
+ kind: "success" | "error";
5
+ message: string;
6
+ }
7
+ /** The event other components fire (bubbling) to show a toast; its detail is a {@link ToastMessage} */
8
+ export declare const TOAST_EVENT = "edaha-toast";
9
+ /** A toast on screen */
10
+ interface Toast extends ToastMessage {
11
+ id: number;
12
+ }
13
+ /**
14
+ * Show a toast from a component, by firing {@link TOAST_EVENT} for the editor to show.
15
+ *
16
+ * @example
17
+ * showToast(this, { kind: "success", message: "Saved" });
18
+ */
19
+ export declare const showToast: (from: EventTarget, toast: ToastMessage) => void;
20
+ /**
21
+ * Toasts in a corner of the editor: successes go away after a few seconds, errors stay until dismissed. Rendered in the
22
+ * light DOM.
23
+ *
24
+ * @example
25
+ * html`<edaha-toasts></edaha-toasts>`; // then toasts.show({ kind: "error", message: "Not found" })
26
+ */
27
+ export declare class EdahaToasts extends LitElement {
28
+ static properties: {
29
+ toasts: {
30
+ state: boolean;
31
+ };
32
+ };
33
+ toasts: Toast[];
34
+ /** How long a success toast is shown, in ms (replaceable for tests) */
35
+ duration: number;
36
+ private nextId;
37
+ constructor();
38
+ protected createRenderRoot(): this;
39
+ /**
40
+ * Show a toast. Success toasts are dismissed after `duration`.
41
+ */
42
+ show(toast: ToastMessage): void;
43
+ /** Remove a toast */
44
+ dismiss(id: number): void;
45
+ render(): import("lit").TemplateResult<1>;
46
+ }
47
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Convert an ISO 8601 date to a `datetime-local` input value in local time.
3
+ *
4
+ * @example
5
+ * toLocalInput("2026-10-19T09:54:00.000Z"); // "2026-10-19T11:54" in Paris (UTC+2)
6
+ */
7
+ export declare const toLocalInput: (iso: string) => string;
8
+ /**
9
+ * Convert a `datetime-local` input value (local time) to an ISO 8601 date. Returns "" for an empty or invalid value.
10
+ *
11
+ * @example
12
+ * fromLocalInput("2026-10-19T11:54"); // "2026-10-19T09:54:00.000Z" in Paris (UTC+2)
13
+ */
14
+ export declare const fromLocalInput: (value: string) => string;
@@ -0,0 +1,129 @@
1
+ import type { ArticleFilters, ArticleLocation, FileChange, FileFilters, FilePage, FileQuery, MetadataInfo, MetadataProblem, SiteInfo, ArticlePage, ArticleQuery, ArticleTypeLabels, EditorArticle, EditorArticleData, EmbedFrame, EmbedInfo, RecentArticles, UploadResult } from "../../server/types/index.ts";
2
+ export type { ArticleLocation } from "../../server/types/index.ts";
3
+ /** How an EditorApi reaches the editor's server */
4
+ export interface EditorApiOptions {
5
+ /**
6
+ * The editor server's address, e.g. "http://127.0.0.1:5180", for a page the server doesn't serve itself (e.g. an
7
+ * app showing `<edaha-editor>`). Requests, articles' files and previews use it. Default: "" (the page's own server)
8
+ */
9
+ baseUrl?: string | undefined;
10
+ /** Sends the requests, e.g. through an app's own channel to the server. Default: the global fetch */
11
+ fetch?: typeof fetch | undefined;
12
+ }
13
+ /** A failed request: the server's message, and the problems with an article's metadata when saving it was refused */
14
+ export declare class ApiError extends Error {
15
+ readonly problems?: MetadataProblem[] | undefined;
16
+ constructor(message: string, problems?: MetadataProblem[]);
17
+ }
18
+ /** A file in an article's folder */
19
+ export interface FileLocation extends ArticleLocation {
20
+ name: string;
21
+ }
22
+ /**
23
+ * A query as URL search parameters, leaving out empty parts, e.g. "?search=hi&page=2" (or "" for none).
24
+ *
25
+ * @example
26
+ * searchParams({ search: "hi", type: "", page: 2 }); // "?search=hi&page=2"
27
+ */
28
+ export declare const searchParams: (query: object) => string;
29
+ /**
30
+ * Talks to the editor's local server (see src/server/app.ts): the page's own, or another at `baseUrl`.
31
+ *
32
+ * @example
33
+ * const api = new EditorApi();
34
+ * const { articles, total } = await api.query({ search: "hello" });
35
+ * const other = new EditorApi({ baseUrl: "http://127.0.0.1:5193" });
36
+ */
37
+ export declare class EditorApi {
38
+ private readonly fetch;
39
+ /** The editor server's address, without a "/" at the end, or "" for the page's own server */
40
+ readonly baseUrl: string;
41
+ /**
42
+ * @param options - the editor server's address and how to send requests to it, or (as before) just the fetch
43
+ */
44
+ constructor(options?: EditorApiOptions | typeof fetch);
45
+ /**
46
+ * The address of a path on the editor's server (e.g. an article's file), for links and images. Other addresses
47
+ * (e.g. "https://...", or a name relative to the page) are kept as they are.
48
+ *
49
+ * @example
50
+ * new EditorApi({ baseUrl: "http://127.0.0.1:5193" }).url("/files/news/hello/a.png");
51
+ * // "http://127.0.0.1:5193/files/news/hello/a.png"
52
+ */
53
+ url(path: string): string;
54
+ /**
55
+ * The address a preview page or embed frame is shown from: the editor server's, at the previews' own origin (see
56
+ * previewAddress).
57
+ *
58
+ * @example
59
+ * new EditorApi({ baseUrl: "http://127.0.0.1:5193" }).previewUrl("/preview/1/");
60
+ * // "http://localhost:5193/preview/1/"
61
+ */
62
+ previewUrl(path: string): string;
63
+ /**
64
+ * Send a request and return its JSON response. Throws an Error with the server's message if it fails.
65
+ */
66
+ private request;
67
+ /** Send JSON with a method */
68
+ private send;
69
+ /**
70
+ * Find articles by title, type, author, tag and status, sorted by title or date, a page at a time.
71
+ *
72
+ * @example
73
+ * await api.query({ search: "hello", sort: "title", page: 2 });
74
+ */
75
+ query(query?: ArticleQuery): Promise<ArticlePage>;
76
+ /**
77
+ * Find files in the articles' folders by name, kind and article type, sorted by name, kind, size or location, a page
78
+ * at a time.
79
+ *
80
+ * @example
81
+ * await api.queryFiles({ kind: "image", sort: "size", order: "desc" });
82
+ */
83
+ queryFiles(query?: FileQuery): Promise<FilePage>;
84
+ /** The kinds of files and the article types they are in, for the file browser's filters */
85
+ fileFilters(): Promise<FileFilters>;
86
+ /** The articles that refer to a file */
87
+ fileReferences(file: FileLocation): Promise<ArticleLocation[]>;
88
+ /** Replace a file with another, updating references to it if the new one's name differs */
89
+ replaceFile(file: FileLocation, replacement: File): Promise<FileChange>;
90
+ /** Delete a file, removing references to it from every article */
91
+ deleteFile(file: FileLocation): Promise<FileChange>;
92
+ /** Each type's most recently changed articles, for the nav */
93
+ recent(): Promise<RecentArticles[]>;
94
+ /** The types, authors and tags articles use, for the article browser's filters */
95
+ filters(): Promise<ArticleFilters>;
96
+ /** The custom metadata fields, and which fields each configured type uses */
97
+ metadata(): Promise<MetadataInfo>;
98
+ /** The website's name, and the author of articles that don't name one */
99
+ site(): Promise<SiteInfo>;
100
+ /** The article types from the config file, with their labels */
101
+ types(): Promise<Record<string, ArticleTypeLabels>>;
102
+ /** The template names an article of a type can use */
103
+ templates(type: string): Promise<string[]>;
104
+ /** Load an article for editing */
105
+ read({ type, slug }: ArticleLocation): Promise<EditorArticle>;
106
+ /** Create a new article */
107
+ create(data: EditorArticleData): Promise<ArticleLocation>;
108
+ /** Save an article, moving it if its type or slug changed */
109
+ save(from: ArticleLocation, data: EditorArticleData): Promise<ArticleLocation>;
110
+ /** Delete an article and its files */
111
+ remove({ type, slug }: ArticleLocation): Promise<void>;
112
+ /** The site's embed plugins */
113
+ embeds(): Promise<EmbedInfo[]>;
114
+ /** Why an embed block's content or options aren't valid for its plugin (none when they are) */
115
+ validateEmbed(key: string, content: string, options?: Record<string, unknown>): Promise<string[]>;
116
+ /** Render an embed block for its frame in the rich text body */
117
+ embedFrame(key: string, content: string, options?: Record<string, unknown>): Promise<EmbedFrame>;
118
+ /** Convert an article body from editor HTML to Markdown (relative URLs are relative to its saved location) */
119
+ toMarkdown(html: string, location?: ArticleLocation): Promise<string>;
120
+ /** Convert an article body from Markdown to editor HTML (relative URLs are relative to its saved location) */
121
+ toHtml(markdown: string, location?: ArticleLocation): Promise<string>;
122
+ /**
123
+ * Render unsaved article data as the website would, with its type's "single" template, as a temporary page on the
124
+ * preview server. Returns the page's URL.
125
+ */
126
+ preview(data: EditorArticleData, location?: ArticleLocation): Promise<string>;
127
+ /** Upload a file into an article's folder */
128
+ upload({ type, slug }: ArticleLocation, file: File): Promise<UploadResult>;
129
+ }