@lvl99dotcom/edaha-editor 0.3.0 → 0.4.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/README.md +8 -1
- package/dist/client/assets/index--k7n6Qb8.css +1 -0
- package/dist/client/assets/{index-BwcJ6yrI.js → index-owkKXGfS.js} +140 -126
- package/dist/client/index.html +2 -2
- package/dist/client-lib/index.js +4037 -0
- package/dist/client-lib/style.css +1569 -0
- package/dist/editor/index.d.ts +24 -1
- package/dist/editor/index.js +15 -1
- package/dist/server/store/index.d.ts +2 -1
- package/dist/server/store/index.js +4 -3
- package/dist/types/client/components/define/index.d.ts +7 -0
- package/dist/types/client/components/edaha-article/index.d.ts +380 -0
- package/dist/types/client/components/edaha-article-browser/index.d.ts +162 -0
- package/dist/types/client/components/edaha-article-data-field/index.d.ts +121 -0
- package/dist/types/client/components/edaha-article-data-group/index.d.ts +40 -0
- package/dist/types/client/components/edaha-editor/index.d.ts +289 -0
- package/dist/types/client/components/edaha-embed-dialog/index.d.ts +84 -0
- package/dist/types/client/components/edaha-file-browser/index.d.ts +203 -0
- package/dist/types/client/components/edaha-markdown/index.d.ts +70 -0
- package/dist/types/client/components/edaha-metadata-field/index.d.ts +100 -0
- package/dist/types/client/components/edaha-richtext/index.d.ts +88 -0
- package/dist/types/client/components/edaha-toasts/index.d.ts +47 -0
- package/dist/types/client/dates/index.d.ts +14 -0
- package/dist/types/client/editorApi/index.d.ts +129 -0
- package/dist/types/client/embeds/index.d.ts +74 -0
- package/dist/types/client/icons/index.d.ts +60 -0
- package/dist/types/client/index.d.ts +3 -0
- package/dist/types/client/markdown/index.d.ts +163 -0
- package/dist/types/client/metadataForm/index.d.ts +77 -0
- package/dist/types/client/narrow/index.d.ts +21 -0
- package/dist/types/client/richtext/editor/index.d.ts +34 -0
- package/dist/types/client/richtext/extensions/index.d.ts +90 -0
- package/dist/types/client/sortTable/index.d.ts +24 -0
- package/dist/types/client/theme/index.d.ts +48 -0
- package/dist/types/server/types/index.d.ts +251 -0
- package/package.json +15 -10
- package/dist/client/assets/index-D2Y17Fm-.css +0 -1
package/dist/editor/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const EDITOR_BASE = "/_editor/";
|
|
|
15
15
|
export declare const CLIENT_DIR: string;
|
|
16
16
|
/** Options for the article editor's server */
|
|
17
17
|
export interface EditorServerOptions extends SiteConfigOptions {
|
|
18
|
-
/** The
|
|
18
|
+
/** The theme folder that the site's templates and static files override. Default: the config's `theme`, else THEME_DIR */
|
|
19
19
|
themeDir?: string;
|
|
20
20
|
/** The port to listen on. Default: EDITOR_PORT */
|
|
21
21
|
port?: number;
|
|
@@ -25,11 +25,27 @@ export interface EditorServerOptions extends SiteConfigOptions {
|
|
|
25
25
|
fetch?: typeof fetch;
|
|
26
26
|
/** Embed plugins added after the config file's `plugins` (a key in both uses the config file's). Default: none */
|
|
27
27
|
plugins?: readonly EmbedPlugin[];
|
|
28
|
+
/**
|
|
29
|
+
* Hide the "edaha.md" title, e.g. in an app that shows the editor in its own window (Home still goes back to the
|
|
30
|
+
* welcome prompt). Default: false
|
|
31
|
+
*/
|
|
32
|
+
hideTitle?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Hide the light/dark theme switcher, showing the device's light or dark theme instead, e.g. in an app that sets it.
|
|
35
|
+
* Default: false
|
|
36
|
+
*/
|
|
37
|
+
hideThemeSwitcher?: boolean;
|
|
28
38
|
}
|
|
29
39
|
/** A running editor server */
|
|
30
40
|
export interface EditorServer {
|
|
31
41
|
/** The editor's address, e.g. "http://127.0.0.1:5180" */
|
|
32
42
|
url: string;
|
|
43
|
+
/**
|
|
44
|
+
* Answer a request to the editor's server without the network, e.g. for an app that shows `<edaha-editor>` and
|
|
45
|
+
* passes its requests on (see EditorApi's `fetch`). Requests other than GET need an `Origin` header of the editor's
|
|
46
|
+
* address, as from the editor's page.
|
|
47
|
+
*/
|
|
48
|
+
fetch: (request: Request) => Promise<Response>;
|
|
33
49
|
/** Stop the server */
|
|
34
50
|
close: () => Promise<void>;
|
|
35
51
|
}
|
|
@@ -47,6 +63,13 @@ export declare const editorUrl: (port: number) => string;
|
|
|
47
63
|
* editorPort({}); // 5180
|
|
48
64
|
*/
|
|
49
65
|
export declare const editorPort: (options: EditorServerOptions) => number;
|
|
66
|
+
/**
|
|
67
|
+
* The editor page's HTML with the options that change how it looks set as attributes of its `<edaha-editor>` element.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* editorPage("<edaha-editor></edaha-editor>", { hideTitle: true }); // "<edaha-editor hide-title></edaha-editor>"
|
|
71
|
+
*/
|
|
72
|
+
export declare const editorPage: (html: string, options: Pick<EditorServerOptions, "hideTitle" | "hideThemeSwitcher">) => string;
|
|
50
73
|
/**
|
|
51
74
|
* Create the article editor's web app: the editor page at `/`, its files under `EDITOR_BASE`, and the editor API,
|
|
52
75
|
* previews and the site's static files (see createEditorApp) everywhere else. Throws if the site's config file can't be
|
package/dist/editor/index.js
CHANGED
|
@@ -33,6 +33,19 @@ export const editorUrl = (port) => `http://${EDITOR_HOST}:${port}`;
|
|
|
33
33
|
* editorPort({}); // 5180
|
|
34
34
|
*/
|
|
35
35
|
export const editorPort = (options) => options.port ?? EDITOR_PORT;
|
|
36
|
+
/**
|
|
37
|
+
* The editor page's HTML with the options that change how it looks set as attributes of its `<edaha-editor>` element.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* editorPage("<edaha-editor></edaha-editor>", { hideTitle: true }); // "<edaha-editor hide-title></edaha-editor>"
|
|
41
|
+
*/
|
|
42
|
+
export const editorPage = (html, options) => {
|
|
43
|
+
const attributes = [
|
|
44
|
+
options.hideTitle ? " hide-title" : "",
|
|
45
|
+
options.hideThemeSwitcher ? " hide-theme-switcher" : "",
|
|
46
|
+
].join("");
|
|
47
|
+
return html.replace("<edaha-editor>", `<edaha-editor${attributes}>`);
|
|
48
|
+
};
|
|
36
49
|
/**
|
|
37
50
|
* Read one of the editor page's built files, or undefined if there is no such file or the path leaves the folder.
|
|
38
51
|
*/
|
|
@@ -83,7 +96,7 @@ const editorServerParts = async (options) => {
|
|
|
83
96
|
const html = await clientFile(clientDir, "index.html");
|
|
84
97
|
if (!html)
|
|
85
98
|
return c.text("The editor page is missing; build it with `pnpm build`", 500);
|
|
86
|
-
return c.body(html, 200, {
|
|
99
|
+
return c.body(editorPage(new TextDecoder().decode(html), options), 200, {
|
|
87
100
|
"Content-Type": "text/html; charset=utf-8",
|
|
88
101
|
"Cache-Control": "no-store",
|
|
89
102
|
});
|
|
@@ -115,6 +128,7 @@ export const startEditor = async (options) => {
|
|
|
115
128
|
return new Promise((resolve, reject) => {
|
|
116
129
|
const server = serve({ fetch: app.fetch, hostname: EDITOR_HOST, port }, () => resolve({
|
|
117
130
|
url: editorUrl(port),
|
|
131
|
+
fetch: async (request) => app.fetch(request),
|
|
118
132
|
close: () => {
|
|
119
133
|
store.close();
|
|
120
134
|
return new Promise((done, fail) => server.close((error) => (error ? fail(error) : done())));
|
|
@@ -96,7 +96,8 @@ export declare class ArticleStore {
|
|
|
96
96
|
/**
|
|
97
97
|
* @param site - the site's config file, folder (which holds the articles, templates and static files folders) and
|
|
98
98
|
* settings
|
|
99
|
-
* @param themeDir - the
|
|
99
|
+
* @param themeDir - the theme folder that the site's templates and static files override, instead of the config's
|
|
100
|
+
* `theme` (default: the config's `theme`, else THEME_DIR)
|
|
100
101
|
* @param options - how the article index watches for changes
|
|
101
102
|
*/
|
|
102
103
|
constructor(site: SiteConfig, themeDir?: string, options?: ArticleStoreOptions);
|
|
@@ -143,14 +143,15 @@ export class ArticleStore {
|
|
|
143
143
|
/**
|
|
144
144
|
* @param site - the site's config file, folder (which holds the articles, templates and static files folders) and
|
|
145
145
|
* settings
|
|
146
|
-
* @param themeDir - the
|
|
146
|
+
* @param themeDir - the theme folder that the site's templates and static files override, instead of the config's
|
|
147
|
+
* `theme` (default: the config's `theme`, else THEME_DIR)
|
|
147
148
|
* @param options - how the article index watches for changes
|
|
148
149
|
*/
|
|
149
|
-
constructor(site, themeDir
|
|
150
|
+
constructor(site, themeDir, options = {}) {
|
|
150
151
|
this.indexOptions = options;
|
|
151
152
|
this.configFile = site.configFile;
|
|
152
153
|
this.siteDir = site.siteDir;
|
|
153
|
-
this.themeDir = themeDir;
|
|
154
|
+
this.themeDir = themeDir ?? site.themeDir ?? THEME_DIR;
|
|
154
155
|
this.articlesDir = join(site.siteDir, site.config.articlesDir);
|
|
155
156
|
this.templatesDir = site.config.templatesDir;
|
|
156
157
|
this.staticDir = site.config.staticDir;
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { LitElement, type PropertyValues } from "lit";
|
|
2
|
+
import type { MetadataInfo, EditorArticle, EditorAuthor, SiteInfo, EditorArticleData, FileKind, FileSummary } from "../../../server/types/index.ts";
|
|
3
|
+
import { type ArticleLocation, type EditorApi } from "../../editorApi/index.ts";
|
|
4
|
+
import "../edaha-article-data-field/index.ts";
|
|
5
|
+
import "../edaha-article-data-group/index.ts";
|
|
6
|
+
import type { FieldOption } from "../edaha-article-data-field/index.ts";
|
|
7
|
+
import "../edaha-embed-dialog/index.ts";
|
|
8
|
+
import type { EmbedTools } from "../../embeds/index.ts";
|
|
9
|
+
import "../edaha-metadata-field/index.ts";
|
|
10
|
+
import { type MetadataProblem } from "@lvl99dotcom/edaha.md/generator/metadata";
|
|
11
|
+
/** How the body is shown: the rich text editor, its Markdown in a text box, or rendered as the website would */
|
|
12
|
+
export type BodyMode = "wysiwyg" | "markdown" | "preview";
|
|
13
|
+
/** The body modes' tabs */
|
|
14
|
+
export declare const BODY_MODES: readonly {
|
|
15
|
+
mode: BodyMode;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
/** The widths the preview can be shown at: the panel's full width, or a narrower page centred in it */
|
|
19
|
+
export declare const PREVIEW_WIDTHS: readonly [{
|
|
20
|
+
readonly value: "full";
|
|
21
|
+
readonly label: "Full";
|
|
22
|
+
readonly width: "100%";
|
|
23
|
+
}, {
|
|
24
|
+
readonly value: "900";
|
|
25
|
+
readonly label: "900px";
|
|
26
|
+
readonly width: "900px";
|
|
27
|
+
}, {
|
|
28
|
+
readonly value: "600";
|
|
29
|
+
readonly label: "600px";
|
|
30
|
+
readonly width: "600px";
|
|
31
|
+
}, {
|
|
32
|
+
readonly value: "320";
|
|
33
|
+
readonly label: "320px";
|
|
34
|
+
readonly width: "320px";
|
|
35
|
+
}];
|
|
36
|
+
/** A width the preview can be shown at */
|
|
37
|
+
export type PreviewWidth = (typeof PREVIEW_WIDTHS)[number]["value"];
|
|
38
|
+
/**
|
|
39
|
+
* The index of the tab a key moves focus to among `count` tabs, from the tab at `current`: the arrow keys move to the
|
|
40
|
+
* previous or next tab (wrapping around), Home and End to the first or last. Undefined for other keys.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* nextTabIndex("ArrowRight", 2, 3); // 0
|
|
44
|
+
*/
|
|
45
|
+
export declare const nextTabIndex: (key: string, current: number, count: number) => number | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Data for a new, empty article (a draft dated now).
|
|
48
|
+
*/
|
|
49
|
+
export declare const newArticleData: (now?: Date) => EditorArticleData;
|
|
50
|
+
/**
|
|
51
|
+
* Apply a field change to article data. Field names follow the form, e.g. "title", "author[name]", "tags[0]",
|
|
52
|
+
* "attachments[1][url]".
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* applyFieldChange(data, "author[email]", "matt@lvl99.com");
|
|
56
|
+
*/
|
|
57
|
+
export declare const applyFieldChange: (data: EditorArticleData, name: string, value: string) => EditorArticleData;
|
|
58
|
+
/**
|
|
59
|
+
* Remove empty tags and attachments without a URL, and fill in the slug from the title if it is empty.
|
|
60
|
+
*/
|
|
61
|
+
export declare const cleanArticleData: (data: EditorArticleData) => EditorArticleData;
|
|
62
|
+
/**
|
|
63
|
+
* The fields (and groups: "author", "tags" and "attachments") whose values differ between an article's data and its
|
|
64
|
+
* saved data. The body isn't compared, as its HTML is reformatted by the editor (see `EdahaArticle.bodyChanged`).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* changedFields({ ...saved, title: "New" }, saved); // Set { "title" }
|
|
68
|
+
*/
|
|
69
|
+
export declare const changedFields: (data: EditorArticleData, saved: EditorArticleData) => Set<string>;
|
|
70
|
+
/** Said when custom metadata values aren't valid */
|
|
71
|
+
export declare const METADATA_ERRORS = "Some values aren't valid. Fix the fields marked \u26A0\uFE0F in the settings.";
|
|
72
|
+
/** Asked before putting back the last saved version */
|
|
73
|
+
export declare const RESET_QUESTION = "Reset this article to how it was last saved? Your changes will be lost.";
|
|
74
|
+
/**
|
|
75
|
+
* The article form: title and body, with its configuration (type, status, slug, date, author, excerpt, thumbnail, tags
|
|
76
|
+
* and attachments) beside it. The body can be edited as rich text ("WYSIWYG") or Markdown, or previewed as the website
|
|
77
|
+
* would show the article with its type's "single" template. Saving a changed type or slug moves the article's folder.
|
|
78
|
+
* Fields changed since the last save are marked with an asterisk, and "Reset…" puts back the last saved version.
|
|
79
|
+
*
|
|
80
|
+
* Fires `article-saved` (detail: the article's location), `article-deleted`, `edaha-toast` for success and error
|
|
81
|
+
* messages (see `showToast`), and `focus-mode-change` (detail: whether focus mode should be on) from the focus mode
|
|
82
|
+
* button at the top right of the title and body. In the compact layout (`compact`, see `edaha-editor`) the settings
|
|
83
|
+
* open full screen from a bar at the bottom of the screen.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* html`<edaha-article .api=${api} .article=${article} .typeOptions=${[{ value: "article", label: "Article" }]}></edaha-article>`
|
|
87
|
+
*/
|
|
88
|
+
export declare class EdahaArticle extends LitElement {
|
|
89
|
+
static properties: {
|
|
90
|
+
api: {
|
|
91
|
+
attribute: boolean;
|
|
92
|
+
};
|
|
93
|
+
article: {
|
|
94
|
+
attribute: boolean;
|
|
95
|
+
};
|
|
96
|
+
typeOptions: {
|
|
97
|
+
attribute: boolean;
|
|
98
|
+
};
|
|
99
|
+
data: {
|
|
100
|
+
state: boolean;
|
|
101
|
+
};
|
|
102
|
+
files: {
|
|
103
|
+
state: boolean;
|
|
104
|
+
};
|
|
105
|
+
location: {
|
|
106
|
+
state: boolean;
|
|
107
|
+
};
|
|
108
|
+
busy: {
|
|
109
|
+
state: boolean;
|
|
110
|
+
};
|
|
111
|
+
message: {
|
|
112
|
+
state: boolean;
|
|
113
|
+
};
|
|
114
|
+
error: {
|
|
115
|
+
state: boolean;
|
|
116
|
+
};
|
|
117
|
+
templates: {
|
|
118
|
+
state: boolean;
|
|
119
|
+
};
|
|
120
|
+
mode: {
|
|
121
|
+
state: boolean;
|
|
122
|
+
};
|
|
123
|
+
bodyMarkdown: {
|
|
124
|
+
state: boolean;
|
|
125
|
+
};
|
|
126
|
+
previewUrl: {
|
|
127
|
+
state: boolean;
|
|
128
|
+
};
|
|
129
|
+
previewWidth: {
|
|
130
|
+
state: boolean;
|
|
131
|
+
};
|
|
132
|
+
metadataOpen: {
|
|
133
|
+
state: boolean;
|
|
134
|
+
};
|
|
135
|
+
savedData: {
|
|
136
|
+
state: boolean;
|
|
137
|
+
};
|
|
138
|
+
bodyChanged: {
|
|
139
|
+
state: boolean;
|
|
140
|
+
};
|
|
141
|
+
metadata: {
|
|
142
|
+
attribute: boolean;
|
|
143
|
+
};
|
|
144
|
+
site: {
|
|
145
|
+
attribute: boolean;
|
|
146
|
+
};
|
|
147
|
+
metaProblems: {
|
|
148
|
+
state: boolean;
|
|
149
|
+
};
|
|
150
|
+
openGroups: {
|
|
151
|
+
state: boolean;
|
|
152
|
+
};
|
|
153
|
+
compact: {
|
|
154
|
+
attribute: boolean;
|
|
155
|
+
};
|
|
156
|
+
focusMode: {
|
|
157
|
+
attribute: boolean;
|
|
158
|
+
};
|
|
159
|
+
pickFile: {
|
|
160
|
+
attribute: boolean;
|
|
161
|
+
};
|
|
162
|
+
embedTools: {
|
|
163
|
+
state: boolean;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
api: EditorApi;
|
|
167
|
+
/** The loaded article, or undefined for a new one */
|
|
168
|
+
article?: EditorArticle | undefined;
|
|
169
|
+
/** Article types to choose from */
|
|
170
|
+
typeOptions: FieldOption[];
|
|
171
|
+
data: EditorArticleData;
|
|
172
|
+
/** Files in the article's folder */
|
|
173
|
+
files: string[];
|
|
174
|
+
/** Where the article is saved (undefined until a new article is first saved) */
|
|
175
|
+
location?: ArticleLocation | undefined;
|
|
176
|
+
busy: boolean;
|
|
177
|
+
message: string;
|
|
178
|
+
error: string;
|
|
179
|
+
/** Template names for the article's type */
|
|
180
|
+
templates: string[];
|
|
181
|
+
/** How the body is shown */
|
|
182
|
+
mode: BodyMode;
|
|
183
|
+
/** The body's Markdown, while edited in Markdown mode */
|
|
184
|
+
bodyMarkdown: string;
|
|
185
|
+
/** The URL of the article as the website would show it (a temporary page), in Preview mode */
|
|
186
|
+
previewUrl: string;
|
|
187
|
+
/** The width the preview is shown at */
|
|
188
|
+
previewWidth: PreviewWidth;
|
|
189
|
+
/** Whether the article's settings are open full screen (in the compact layout) */
|
|
190
|
+
metadataOpen: boolean;
|
|
191
|
+
/** The data as last saved (or loaded; empty for a new article), which changes are found against */
|
|
192
|
+
savedData: EditorArticleData;
|
|
193
|
+
/** Whether the body differs from the saved one, compared as Markdown */
|
|
194
|
+
bodyChanged: boolean;
|
|
195
|
+
/** The website's default authors: its own, and its types' (the website's name is assumed until it's known) */
|
|
196
|
+
site?: SiteInfo | undefined;
|
|
197
|
+
/** The custom metadata fields, and which each type uses (none without it) */
|
|
198
|
+
metadata?: MetadataInfo | undefined;
|
|
199
|
+
/** Errors in the custom metadata values, from checking them or from the last save */
|
|
200
|
+
metaProblems: MetadataProblem[];
|
|
201
|
+
/** The keys of the settings groups that are open */
|
|
202
|
+
openGroups: Set<string>;
|
|
203
|
+
/** Whether the editor's layout is compact (on narrow screens, or in focus mode) */
|
|
204
|
+
compact: boolean;
|
|
205
|
+
/** Whether focus mode is on */
|
|
206
|
+
focusMode: boolean;
|
|
207
|
+
/** Lets the user choose an existing file (e.g. in the file browser); without it, existing files can't be chosen */
|
|
208
|
+
pickFile?: ((kind?: FileKind) => Promise<FileSummary | undefined>) | undefined;
|
|
209
|
+
/** The site's embeds, the embed dialog and embed blocks' frames, once the embeds are loaded */
|
|
210
|
+
embedTools?: EmbedTools | undefined;
|
|
211
|
+
/** Whether the groups' open state has been set from the config file's groups */
|
|
212
|
+
private groupsOpened;
|
|
213
|
+
/** The errors the article was loaded or last saved with, which resetting shows again */
|
|
214
|
+
private savedProblems;
|
|
215
|
+
/** Validates custom metadata values, for the definitions it was made for */
|
|
216
|
+
private validatorFor?;
|
|
217
|
+
/** How long to wait after a body edit before checking whether it changed, in ms (replaceable for tests) */
|
|
218
|
+
bodyCheckDelay: number;
|
|
219
|
+
/** The saved body as Markdown (undefined until known; a new article's is empty) */
|
|
220
|
+
private savedBodyMarkdown?;
|
|
221
|
+
/** Counts body checks and saved-body updates, so only the latest one is used */
|
|
222
|
+
private bodyChecks;
|
|
223
|
+
private savedBodies;
|
|
224
|
+
/** The waiting body check, if any */
|
|
225
|
+
private bodyTimer?;
|
|
226
|
+
/** The type whose templates were last loaded */
|
|
227
|
+
private templatesType;
|
|
228
|
+
/** Asks to confirm deleting or resetting (replaceable for tests) */
|
|
229
|
+
confirm: (message: string) => boolean;
|
|
230
|
+
constructor();
|
|
231
|
+
protected createRenderRoot(): this;
|
|
232
|
+
/** Ask the editor to turn focus mode on or off */
|
|
233
|
+
private toggleFocusMode;
|
|
234
|
+
connectedCallback(): void;
|
|
235
|
+
/** A new article starts with focus in its title, ready to type */
|
|
236
|
+
protected firstUpdated(): Promise<void>;
|
|
237
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
238
|
+
/**
|
|
239
|
+
* The URL a file in the saved article folder is served at. Addresses and paths on the website (e.g. another
|
|
240
|
+
* article's file) are served as they are.
|
|
241
|
+
*/
|
|
242
|
+
private fileUrl;
|
|
243
|
+
/**
|
|
244
|
+
* The address a file is shown from: fileUrl's, on the editor's server (which may not be the page's, see
|
|
245
|
+
* EditorApi's `baseUrl`). Saved content keeps fileUrl's paths.
|
|
246
|
+
*/
|
|
247
|
+
private readonly fileAddress;
|
|
248
|
+
/** The address images in the rich text body are shown from: their `src`, on the editor's server */
|
|
249
|
+
private readonly bodyFileAddress;
|
|
250
|
+
/** Run an API call, showing errors and a busy state */
|
|
251
|
+
private run;
|
|
252
|
+
/**
|
|
253
|
+
* Upload a file into the article's folder. Returns the saved file name.
|
|
254
|
+
*/
|
|
255
|
+
private upload;
|
|
256
|
+
/** Images inserted into the body are uploaded and shown from the article folder */
|
|
257
|
+
private readonly uploadImage;
|
|
258
|
+
/** Images inserted into the body's Markdown are uploaded and referred to by their file name in the article folder */
|
|
259
|
+
private readonly uploadMarkdownImage;
|
|
260
|
+
/**
|
|
261
|
+
* Let the user choose an existing file, referred to by its name when it's in the article's own folder, or else by
|
|
262
|
+
* its path on the website.
|
|
263
|
+
*/
|
|
264
|
+
private readonly chooseFile;
|
|
265
|
+
/** Files chosen for the rich text body are shown from the URL the editor serves them at */
|
|
266
|
+
private readonly chooseBodyFile;
|
|
267
|
+
/** The file choosers, while existing files can be chosen */
|
|
268
|
+
private choosers;
|
|
269
|
+
/**
|
|
270
|
+
* Load the site's embeds, for the body's embed blocks and the embed dialog. Without them (e.g. the API is
|
|
271
|
+
* unreachable), embed blocks show as they are written and can't be added.
|
|
272
|
+
*/
|
|
273
|
+
private loadEmbeds;
|
|
274
|
+
/** Apply a field change */
|
|
275
|
+
private onFieldChange;
|
|
276
|
+
/** The body as Markdown now: as typed in Markdown mode, otherwise converted from the rich text by the server */
|
|
277
|
+
private currentBodyMarkdown;
|
|
278
|
+
/** Check whether the body changed once editing pauses */
|
|
279
|
+
private scheduleBodyCheck;
|
|
280
|
+
/**
|
|
281
|
+
* Check now whether the body differs from the saved one. Leaves `bodyChanged` as it is if the body can't be converted
|
|
282
|
+
* or the saved body isn't known yet.
|
|
283
|
+
*/
|
|
284
|
+
private checkBody;
|
|
285
|
+
/**
|
|
286
|
+
* Remember a body as the saved one, as Markdown (converted from its HTML unless given), then check the current body
|
|
287
|
+
* against it.
|
|
288
|
+
*/
|
|
289
|
+
private rememberBody;
|
|
290
|
+
/** Whether any field or the body differs from the saved article (as last checked) */
|
|
291
|
+
get dirty(): boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Whether the article has changes that aren't saved, checking the body first (as its last check may be waiting).
|
|
294
|
+
*/
|
|
295
|
+
hasChanges(): Promise<boolean>;
|
|
296
|
+
/** Upload a file chosen in a file field and set the field to its name */
|
|
297
|
+
private onFieldFile;
|
|
298
|
+
/**
|
|
299
|
+
* Bring the body's HTML up to date with its Markdown, when it is edited in Markdown mode. Returns whether it is up to
|
|
300
|
+
* date (false if converting failed, which shows the error).
|
|
301
|
+
*/
|
|
302
|
+
private syncBody;
|
|
303
|
+
/**
|
|
304
|
+
* Show the body another way: as rich text, as Markdown (converted from the rich text), or rendered as the website
|
|
305
|
+
* would show the unsaved article. Stays in the current mode if converting or rendering fails, showing the error.
|
|
306
|
+
*/
|
|
307
|
+
setMode(mode: BodyMode): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Save the article (creating or moving it as needed). Returns whether it was saved.
|
|
310
|
+
*/
|
|
311
|
+
save(): Promise<boolean>;
|
|
312
|
+
/**
|
|
313
|
+
* Put back the last saved version of the article (or an empty one for a new article) after confirming. The body is
|
|
314
|
+
* shown as rich text.
|
|
315
|
+
*/
|
|
316
|
+
reset(): void;
|
|
317
|
+
/**
|
|
318
|
+
* Delete the article after confirming.
|
|
319
|
+
*/
|
|
320
|
+
deleteArticle(): Promise<void>;
|
|
321
|
+
/** The validator for the custom metadata definitions, made once for them */
|
|
322
|
+
private validator;
|
|
323
|
+
/** The custom metadata fields the article's type uses */
|
|
324
|
+
metadataKeys(): string[];
|
|
325
|
+
/**
|
|
326
|
+
* The custom metadata values of the fields the article's type uses, with their defaults and without hidden ones, and
|
|
327
|
+
* which fields are hidden (see resolveFields). Hidden values stay in the article's data until it is saved, so a
|
|
328
|
+
* field shown again gets its value back.
|
|
329
|
+
*/
|
|
330
|
+
private resolvedMeta;
|
|
331
|
+
/** The errors in a custom metadata field's value (none when it has no value, or is hidden) */
|
|
332
|
+
private checkMetadata;
|
|
333
|
+
/** Change a custom metadata value (or a value inside one) */
|
|
334
|
+
private onMetadataChange;
|
|
335
|
+
/** Check a custom metadata field once focus leaves it, saying so when errors are found */
|
|
336
|
+
private onMetadataBlur;
|
|
337
|
+
/** Remove one of the article's other settings (it's gone once the article is saved) */
|
|
338
|
+
removeSetting(key: string): void;
|
|
339
|
+
/** Warnings about the article's other settings: values of fields its type doesn't use, and unknown settings */
|
|
340
|
+
private metadataWarnings;
|
|
341
|
+
/** Whether a field or group differs from the saved article */
|
|
342
|
+
private isChanged;
|
|
343
|
+
/** Render the author fields */
|
|
344
|
+
/**
|
|
345
|
+
* The author the article has when it doesn't name one: its type's default, or the website's (undefined for none).
|
|
346
|
+
*/
|
|
347
|
+
defaultAuthor(): EditorAuthor | undefined;
|
|
348
|
+
/** Render the author fields, with a choice of no author at all */
|
|
349
|
+
private renderAuthor;
|
|
350
|
+
/** Render the tag fields */
|
|
351
|
+
private renderTags;
|
|
352
|
+
/** Render the attachment fields */
|
|
353
|
+
private renderAttachments;
|
|
354
|
+
/** Render the body in its mode, in a tab panel under the tabs that switch modes */
|
|
355
|
+
private renderBody;
|
|
356
|
+
/**
|
|
357
|
+
* Move between the body's tabs with the arrow keys, Home and End. Enter or Space then shows the focused tab, as
|
|
358
|
+
* showing one can take a moment (converting or rendering the body).
|
|
359
|
+
*/
|
|
360
|
+
private onTabKey;
|
|
361
|
+
/** The groups settings are shown in, in order (the built-in ones until the config file's are known) */
|
|
362
|
+
private groups;
|
|
363
|
+
/** The groups holding a custom field with errors */
|
|
364
|
+
private groupsWithErrors;
|
|
365
|
+
/** Whether a setting differs from the saved article (custom ones by their own value) */
|
|
366
|
+
private settingChanged;
|
|
367
|
+
/** Render a core setting's field (or the files in the article's folder, "uploaded") */
|
|
368
|
+
private renderSetting;
|
|
369
|
+
/** Render the files in the article's folder, or that uploads need the article saved first */
|
|
370
|
+
private renderUploaded;
|
|
371
|
+
/** Render a custom field the article's type uses, unless its conditions hide it */
|
|
372
|
+
private renderCustomField;
|
|
373
|
+
/**
|
|
374
|
+
* Render the settings in their groups, as sections that open and close: each with its title (marked when a setting
|
|
375
|
+
* in it changed, or a custom field in it has errors), its description, and its fields. Custom fields show for the
|
|
376
|
+
* article's type only, and warnings about other settings show in the Custom group. Empty groups aren't shown.
|
|
377
|
+
*/
|
|
378
|
+
private renderGroups;
|
|
379
|
+
render(): import("lit").TemplateResult<1>;
|
|
380
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import type { MetadataProblem, ProblemFilter, ArticleFilters, ArticleOrder, ArticlePage, ArticleSort, ArticleStatus, ArticleTypeLabels } from "../../../server/types/index.ts";
|
|
3
|
+
import type { EditorApi } from "../../editorApi/index.ts";
|
|
4
|
+
/** What the article browser starts with when it opens */
|
|
5
|
+
export interface ArticleBrowserOptions {
|
|
6
|
+
/** Text the titles contain */
|
|
7
|
+
search?: string | undefined;
|
|
8
|
+
type?: string | undefined;
|
|
9
|
+
/** Only articles with metadata problems of this kind */
|
|
10
|
+
problems?: ProblemFilter | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The kinds of metadata problems to filter by */
|
|
13
|
+
export declare const PROBLEM_FILTERS: readonly {
|
|
14
|
+
value: ProblemFilter;
|
|
15
|
+
label: string;
|
|
16
|
+
}[];
|
|
17
|
+
/**
|
|
18
|
+
* Count an article's metadata problems, e.g. "1 error, 2 warnings" ("" without any).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* countProblems([{ level: "error", ... }, { level: "warning", ... }]); // "1 error, 1 warning"
|
|
22
|
+
*/
|
|
23
|
+
export declare const countProblems: (problems?: MetadataProblem[]) => string;
|
|
24
|
+
/** The statuses to filter by */
|
|
25
|
+
export declare const STATUS_FILTERS: readonly {
|
|
26
|
+
value: ArticleStatus;
|
|
27
|
+
label: string;
|
|
28
|
+
}[];
|
|
29
|
+
/** The results' columns, each sorting by its own value when its header is pressed */
|
|
30
|
+
export declare const COLUMNS: readonly {
|
|
31
|
+
sort: ArticleSort;
|
|
32
|
+
label: string;
|
|
33
|
+
}[];
|
|
34
|
+
/** The event fired when an article is chosen (detail: its location) */
|
|
35
|
+
export declare const ARTICLE_CHOOSE_EVENT = "article-choose";
|
|
36
|
+
/**
|
|
37
|
+
* A type's singular label, or its name if it isn't configured.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* typeLabel({ news: { labelSingle: "News item", labelPlural: "News" } }, "news"); // "News item"
|
|
41
|
+
*/
|
|
42
|
+
export declare const typeLabel: (types: Record<string, ArticleTypeLabels>, type: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* The article browser: a dialog that finds articles by title, filters them by type, author, tag and status, and shows
|
|
45
|
+
* them 50 at a time in a table whose column headings sort it (see `nextSort`). Choosing one closes it and fires
|
|
46
|
+
* `article-choose` (detail: the article's location). Rendered in the light DOM.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* html`<edaha-article-browser .api=${api} .types=${types} @article-choose=${open}></edaha-article-browser>`
|
|
50
|
+
* browser.show({ type: "news" });
|
|
51
|
+
*/
|
|
52
|
+
export declare class EdahaArticleBrowser extends LitElement {
|
|
53
|
+
static properties: {
|
|
54
|
+
api: {
|
|
55
|
+
attribute: boolean;
|
|
56
|
+
};
|
|
57
|
+
types: {
|
|
58
|
+
attribute: boolean;
|
|
59
|
+
};
|
|
60
|
+
search: {
|
|
61
|
+
state: boolean;
|
|
62
|
+
};
|
|
63
|
+
type: {
|
|
64
|
+
state: boolean;
|
|
65
|
+
};
|
|
66
|
+
author: {
|
|
67
|
+
state: boolean;
|
|
68
|
+
};
|
|
69
|
+
tag: {
|
|
70
|
+
state: boolean;
|
|
71
|
+
};
|
|
72
|
+
status: {
|
|
73
|
+
state: boolean;
|
|
74
|
+
};
|
|
75
|
+
problems: {
|
|
76
|
+
state: boolean;
|
|
77
|
+
};
|
|
78
|
+
sort: {
|
|
79
|
+
state: boolean;
|
|
80
|
+
};
|
|
81
|
+
order: {
|
|
82
|
+
state: boolean;
|
|
83
|
+
};
|
|
84
|
+
page: {
|
|
85
|
+
state: boolean;
|
|
86
|
+
};
|
|
87
|
+
result: {
|
|
88
|
+
state: boolean;
|
|
89
|
+
};
|
|
90
|
+
filters: {
|
|
91
|
+
state: boolean;
|
|
92
|
+
};
|
|
93
|
+
loading: {
|
|
94
|
+
state: boolean;
|
|
95
|
+
};
|
|
96
|
+
error: {
|
|
97
|
+
state: boolean;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
api: EditorApi;
|
|
101
|
+
/** The configured article types' labels */
|
|
102
|
+
types: Record<string, ArticleTypeLabels>;
|
|
103
|
+
search: string;
|
|
104
|
+
type: string;
|
|
105
|
+
author: string;
|
|
106
|
+
tag: string;
|
|
107
|
+
status: string;
|
|
108
|
+
/** The kind of metadata problems articles must have ("" for any article) */
|
|
109
|
+
problems: string;
|
|
110
|
+
/** The column the results are sorted by (undefined: the default order, newest published first) */
|
|
111
|
+
sort?: ArticleSort | undefined;
|
|
112
|
+
order?: ArticleOrder | undefined;
|
|
113
|
+
page: number;
|
|
114
|
+
/** The articles found, once loaded */
|
|
115
|
+
result?: ArticlePage | undefined;
|
|
116
|
+
/** The filters' choices */
|
|
117
|
+
filters: ArticleFilters;
|
|
118
|
+
loading: boolean;
|
|
119
|
+
error: string;
|
|
120
|
+
/** How long to wait after typing in the search before searching, in ms (replaceable for tests) */
|
|
121
|
+
searchDelay: number;
|
|
122
|
+
/** The waiting search, if any */
|
|
123
|
+
private searchTimer?;
|
|
124
|
+
/** Counts searches, so only the latest one's result is shown */
|
|
125
|
+
private searches;
|
|
126
|
+
constructor();
|
|
127
|
+
protected createRenderRoot(): this;
|
|
128
|
+
/** The dialog, once rendered */
|
|
129
|
+
private get dialog();
|
|
130
|
+
/** Whether the browser is open */
|
|
131
|
+
get open(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Open the browser with a search and type (other filters are cleared), on the first page, with focus in the search
|
|
134
|
+
* field.
|
|
135
|
+
*/
|
|
136
|
+
show(options?: ArticleBrowserOptions): Promise<void>;
|
|
137
|
+
/** Close the browser */
|
|
138
|
+
close(): void;
|
|
139
|
+
/** Load the filters' choices (keeping the last ones if it fails) */
|
|
140
|
+
private loadFilters;
|
|
141
|
+
/** Find the articles for the current search, filters, sort and page */
|
|
142
|
+
load(): Promise<void>;
|
|
143
|
+
/** Change a filter or the sort, going back to the first page */
|
|
144
|
+
private choose;
|
|
145
|
+
/** Search once typing pauses, from the first page */
|
|
146
|
+
private onSearch;
|
|
147
|
+
/** Sort by a column (see `nextSort`), going back to the first page */
|
|
148
|
+
private sortBy;
|
|
149
|
+
/** Show another page, from its top */
|
|
150
|
+
private goTo;
|
|
151
|
+
/** Choose an article: close the browser and tell the editor */
|
|
152
|
+
private chooseArticle;
|
|
153
|
+
/** Render a select filter with an "any" choice first */
|
|
154
|
+
private renderSelect;
|
|
155
|
+
/** Render the found articles as a table */
|
|
156
|
+
private renderResults;
|
|
157
|
+
/** Render the page buttons, when there is more than one page */
|
|
158
|
+
private renderPages;
|
|
159
|
+
/** What the status line says: loading, an error, or how many articles were found */
|
|
160
|
+
private statusText;
|
|
161
|
+
render(): import("lit").TemplateResult<1>;
|
|
162
|
+
}
|