@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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type TemplateResult } from "lit";
|
|
2
|
+
import type { EmbedOptionValues } from "@lvl99dotcom/edaha.md/embeds/blocks";
|
|
3
|
+
import type { EmbedFrame, EmbedInfo } from "../../server/types/index.ts";
|
|
4
|
+
/** An embed block's kind (its plugin's key), content and options */
|
|
5
|
+
export interface EmbedValue {
|
|
6
|
+
/** The embed plugin's key, e.g. "youtube" (empty for an old block without one) */
|
|
7
|
+
key: string;
|
|
8
|
+
/** The block's content, e.g. a URL or a diagram's code */
|
|
9
|
+
content: string;
|
|
10
|
+
/** The block's options, as set in the embed dialog (see EmbedPlugin.options) */
|
|
11
|
+
options: EmbedOptionValues;
|
|
12
|
+
}
|
|
13
|
+
/** Gives why an embed's content or options aren't valid for its kind (none when they are) */
|
|
14
|
+
export type EmbedValidator = (value: EmbedValue) => Promise<string[]>;
|
|
15
|
+
/** What the rich text and Markdown editors need for embed blocks */
|
|
16
|
+
export interface EmbedTools {
|
|
17
|
+
/** The site's embed plugins */
|
|
18
|
+
embeds: readonly EmbedInfo[];
|
|
19
|
+
/**
|
|
20
|
+
* Ask for an embed's content and options in the embed dialog, checking they are valid: for a new embed of a kind
|
|
21
|
+
* (`adding`, with empty content and no options), or a block to change. Its kind stays the same. Undefined if cancelled, or if the site has no
|
|
22
|
+
* plugin for its kind.
|
|
23
|
+
*/
|
|
24
|
+
edit(value: EmbedValue, adding: boolean): Promise<EmbedValue | undefined>;
|
|
25
|
+
/** Render an embed block for its frame in the rich text body */
|
|
26
|
+
loadFrame(value: EmbedValue): Promise<EmbedFrame>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An embed plugin's name, or a label for a key without a plugin.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* embedName(embeds, "youtube"); // "YouTube video"
|
|
33
|
+
* embedName(embeds, ""); // "Embed without a kind"
|
|
34
|
+
*/
|
|
35
|
+
export declare const embedName: (embeds: readonly EmbedInfo[], key: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Render an embed plugin's icon, hidden from screen readers (its name is shown beside it), or nothing without one.
|
|
38
|
+
* Icons come from the site's own plugins, so their markup is trusted.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* html`${embedIcon(youtubeInfo)} YouTube video`
|
|
42
|
+
*/
|
|
43
|
+
export declare const embedIcon: (embed: EmbedInfo | undefined) => TemplateResult | string;
|
|
44
|
+
/** What an embed's toolbar button does */
|
|
45
|
+
export interface EmbedButtonOptions {
|
|
46
|
+
/** Whether a block of its kind is selected */
|
|
47
|
+
pressed: boolean;
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
/** Add an embed of its kind, or change the selected one */
|
|
50
|
+
onClick: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A toolbar button for adding an embed of a kind: its icon (or a general one), named by the embed's name for screen
|
|
54
|
+
* readers and tooltips.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* html`${embeds.map((embed) => embedButton(embed, { pressed: false, disabled: false, onClick: () => add(embed.key) }))}`
|
|
58
|
+
*/
|
|
59
|
+
export declare const embedButton: (embed: EmbedInfo, { pressed, disabled, onClick }: EmbedButtonOptions) => TemplateResult;
|
|
60
|
+
/**
|
|
61
|
+
* The address of a preview page or embed frame: on the editor's server, at the previews' own origin (`localhost`
|
|
62
|
+
* rather than `127.0.0.1`), which can't reach the editor's API. The path is on the page's own server, or the editor
|
|
63
|
+
* server's address given in full (e.g. when another app shows the editor). Elsewhere (e.g. tests), and for an empty
|
|
64
|
+
* path, the path is kept as it is.
|
|
65
|
+
*
|
|
66
|
+
* @param base - the address the path is relative to: the page's own, by default
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* previewAddress("/preview/1/"); // "http://localhost:5180/preview/1/" on http://127.0.0.1:5180
|
|
70
|
+
* previewAddress("http://127.0.0.1:5180/preview/1/"); // "http://localhost:5180/preview/1/" anywhere
|
|
71
|
+
*/
|
|
72
|
+
export declare const previewAddress: (path: string, base?: {
|
|
73
|
+
href: string;
|
|
74
|
+
}) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor's icons: Material Symbols (outlined, weight 400), bundled as SVG so only these are included.
|
|
3
|
+
*/
|
|
4
|
+
export declare const ICONS: {
|
|
5
|
+
readonly add_column_right: string;
|
|
6
|
+
readonly add_photo_alternate: string;
|
|
7
|
+
readonly add_row_below: string;
|
|
8
|
+
readonly close: string;
|
|
9
|
+
readonly content_copy: string;
|
|
10
|
+
readonly delete: string;
|
|
11
|
+
readonly find_replace: string;
|
|
12
|
+
readonly folder_open: string;
|
|
13
|
+
readonly code_blocks: string;
|
|
14
|
+
readonly delete_sweep: string;
|
|
15
|
+
readonly expand_circle_down: string;
|
|
16
|
+
readonly format_bold: string;
|
|
17
|
+
readonly format_h1: string;
|
|
18
|
+
readonly format_h2: string;
|
|
19
|
+
readonly format_h3: string;
|
|
20
|
+
readonly format_italic: string;
|
|
21
|
+
readonly format_list_bulleted: string;
|
|
22
|
+
readonly format_list_numbered: string;
|
|
23
|
+
readonly format_quote: string;
|
|
24
|
+
readonly format_underlined: string;
|
|
25
|
+
readonly fullscreen: string;
|
|
26
|
+
readonly fullscreen_exit: string;
|
|
27
|
+
readonly image: string;
|
|
28
|
+
readonly link: string;
|
|
29
|
+
readonly manage_search: string;
|
|
30
|
+
readonly menu: string;
|
|
31
|
+
readonly playlist_remove: string;
|
|
32
|
+
readonly raw_on: string;
|
|
33
|
+
readonly read_more: string;
|
|
34
|
+
readonly smart_display: string;
|
|
35
|
+
readonly strikethrough_s: string;
|
|
36
|
+
readonly table: string;
|
|
37
|
+
readonly text_decrease: string;
|
|
38
|
+
readonly text_increase: string;
|
|
39
|
+
};
|
|
40
|
+
/** The name of one of the editor's icons */
|
|
41
|
+
export type IconName = keyof typeof ICONS;
|
|
42
|
+
/**
|
|
43
|
+
* The formatting toolbars' icons, by button label. Both the rich text and the Markdown toolbars use them, so the same
|
|
44
|
+
* button looks the same in both.
|
|
45
|
+
*/
|
|
46
|
+
export declare const TOOLBAR_ICONS: Record<string, IconName>;
|
|
47
|
+
/**
|
|
48
|
+
* Render an icon, hidden from screen readers (its button or link names what it does).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* html`<button type="button">${icon("menu")}<span class="visually-hidden">Articles</span></button>`
|
|
52
|
+
*/
|
|
53
|
+
export declare const icon: (name: IconName) => import("lit").TemplateResult<1>;
|
|
54
|
+
/**
|
|
55
|
+
* Render a toolbar button's content: its icon and its label, which is read by screen readers and shown as a tooltip.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* html`<button type="button" title="Bold">${toolbarButtonContent("Bold")}</button>`
|
|
59
|
+
*/
|
|
60
|
+
export declare const toolbarButtonContent: (label: string) => string | import("lit").TemplateResult<1>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { EdahaEditor } from "./components/edaha-editor/index.ts";
|
|
2
|
+
export { EdahaMetadataField, type MetadataChange, } from "./components/edaha-metadata-field/index.ts";
|
|
3
|
+
export { ApiError, EditorApi, type ArticleLocation, type EditorApiOptions, } from "./editorApi/index.ts";
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { EmbedValue } from "../embeds/index.ts";
|
|
2
|
+
/** Text and its selection (`start` to `end`; equal when nothing is selected) */
|
|
3
|
+
export interface TextEdit {
|
|
4
|
+
value: string;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
}
|
|
8
|
+
/** The part of a text that changed: replacing `start` to `end` of the old text with `text` gives the new text */
|
|
9
|
+
export interface TextChange {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
/** The read more break */
|
|
15
|
+
export declare const READMORE = "<!-- readmore -->";
|
|
16
|
+
/**
|
|
17
|
+
* The part of a text that changed between two versions, found by comparing their starts and ends. Used to replace only
|
|
18
|
+
* that part, which keeps the browser's undo history.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* textChange("Hello world", "Hello **world**"); // { start: 6, end: 11, text: "**world**" }
|
|
22
|
+
*/
|
|
23
|
+
export declare const textChange: (from: string, to: string) => TextChange;
|
|
24
|
+
/**
|
|
25
|
+
* Wrap the selection in `before` and `after`, e.g. "**" for bold, or unwrap it if it is already wrapped (inside or
|
|
26
|
+
* around the selection). With nothing selected, the placeholder is inserted and selected.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* wrapInline({ value: "Hi there", start: 3, end: 8 }, "**", "**"); // { value: "Hi **there**", start: 5, end: 10 }
|
|
30
|
+
*/
|
|
31
|
+
export declare const wrapInline: (edit: TextEdit, before: string, after: string, placeholder?: string) => TextEdit;
|
|
32
|
+
/**
|
|
33
|
+
* Add a marker to the start of each line the selection is on (blank lines are left alone), or remove it if every line
|
|
34
|
+
* already has it. `isOn` matches the marker; `strip` matches other markers replaced by it (e.g. other heading levels).
|
|
35
|
+
* The marker can depend on the line's number, for numbered lists.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* toggleLines({ value: "Title", start: 0, end: 0 }, /^## /, () => "## ", /^#{1,6} /); // { value: "## Title", ... }
|
|
39
|
+
*/
|
|
40
|
+
export declare const toggleLines: (edit: TextEdit, isOn: RegExp, marker: (line: number) => string, strip?: RegExp) => TextEdit;
|
|
41
|
+
/**
|
|
42
|
+
* Wrap the lines the selection is on in an opening and closing line, e.g. a code fence, or unwrap them if they already
|
|
43
|
+
* start and end with them.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* wrapLines({ value: "code", start: 0, end: 0 }, "```", "```"); // { value: "```\ncode\n```", start: 4, end: 8 }
|
|
47
|
+
*/
|
|
48
|
+
export declare const wrapLines: (edit: TextEdit, open: string, close: string) => TextEdit;
|
|
49
|
+
/**
|
|
50
|
+
* Replace the selection with a block (e.g. a table) on its own, with blank lines around it. The block is selected, or
|
|
51
|
+
* the part of it from `selectFrom` to `selectTo`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* insertBlock({ value: "Intro", start: 5, end: 5 }, READMORE); // { value: "Intro\n\n<!-- readmore -->", ... }
|
|
55
|
+
*/
|
|
56
|
+
export declare const insertBlock: ({ value, start, end }: TextEdit, block: string, selectFrom?: number, selectTo?: number) => TextEdit;
|
|
57
|
+
/**
|
|
58
|
+
* Replace the selection with text, then put the cursor after it.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* insertText({ value: "a b", start: 2, end: 2 }, ""); // { value: "a  b", start: 14, end: 14 }
|
|
62
|
+
*/
|
|
63
|
+
export declare const insertText: ({ value, start, end }: TextEdit, text: string) => TextEdit;
|
|
64
|
+
/** The URL of the selected link, if a whole link is selected */
|
|
65
|
+
export declare const selectedLinkUrl: ({ value, start, end }: TextEdit) => string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Link the selection to a URL, change the selected link's URL, or remove the selected link (an empty URL). Without a
|
|
68
|
+
* selection, the URL is also the link's text.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* setLink({ value: "Read this", start: 5, end: 9 }, "https://example.com"); // "Read [this](https://example.com)"
|
|
72
|
+
*/
|
|
73
|
+
export declare const setLink: (edit: TextEdit, url: string) => TextEdit | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Insert a file at the selection: an image as an image, anything else as a link (on the selected text, or named after
|
|
76
|
+
* the file).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* insertFile({ value: "", start: 0, end: 0 }, "cat.png", "cat.png", true); // ""
|
|
80
|
+
* insertFile({ value: "", start: 0, end: 0 }, "/news/a/notes.pdf", "notes.pdf", false); // "[notes.pdf](/news/a/notes.pdf)"
|
|
81
|
+
* insertFile({ value: "Read", start: 0, end: 4 }, "notes.pdf", "notes.pdf", false); // "[Read](notes.pdf)"
|
|
82
|
+
*/
|
|
83
|
+
export declare const insertFile: (edit: TextEdit, url: string, name: string, image: boolean) => TextEdit;
|
|
84
|
+
/**
|
|
85
|
+
* The selected embed block's kind, content and options, if a whole embed block is selected (an old block without a
|
|
86
|
+
* key has an empty kind).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* selectedEmbed(edit); // { key: "youtube", content: "https://youtu.be/abc", options: {} }
|
|
90
|
+
*/
|
|
91
|
+
export declare const selectedEmbed: ({ value, start, end, }: TextEdit) => EmbedValue | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Insert an embed block (on its own line), or replace the selected one.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* setEmbed({ value: "", start: 0, end: 0 }, { key: "youtube", content: "https://youtu.be/abc", options: {} }); // "<!-- embed:youtube -->https://youtu.be/abc<!-- /embed:youtube -->"
|
|
97
|
+
*/
|
|
98
|
+
export declare const setEmbed: (edit: TextEdit, embed: EmbedValue) => TextEdit;
|
|
99
|
+
/**
|
|
100
|
+
* Insert an embed block on its own line after the selection (keeping what is selected, e.g. another embed block).
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* insertEmbed({ value: "Intro", start: 0, end: 5 }, { key: "youtube", content: "https://youtu.be/abc", options: {} }); // "Intro\n\n<!-- embed:youtube -->..."
|
|
104
|
+
*/
|
|
105
|
+
export declare const insertEmbed: (edit: TextEdit, embed: EmbedValue) => TextEdit;
|
|
106
|
+
/**
|
|
107
|
+
* Remove the selected read more break, or insert one on its own line.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* toggleReadmore({ value: "Intro", start: 5, end: 5 }); // { value: "Intro\n\n<!-- readmore -->", ... }
|
|
111
|
+
*/
|
|
112
|
+
export declare const toggleReadmore: (edit: TextEdit) => TextEdit;
|
|
113
|
+
/** A Markdown table around the cursor */
|
|
114
|
+
interface Table {
|
|
115
|
+
/** Where its lines start and end in the text */
|
|
116
|
+
from: number;
|
|
117
|
+
to: number;
|
|
118
|
+
/** Its rows' cells; row 1 is the delimiter row */
|
|
119
|
+
rows: string[][];
|
|
120
|
+
/** The row and column the cursor is in */
|
|
121
|
+
row: number;
|
|
122
|
+
column: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The Markdown table the cursor is in: lines starting with "|" around it, the second being the delimiter row.
|
|
126
|
+
*/
|
|
127
|
+
export declare const tableAt: ({ value, start }: TextEdit) => Table | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Insert a 3 by 3 table with a header row, putting the cursor in its first header cell.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* insertTable({ value: "", start: 0, end: 0 }).value; // "| Header | Header | Header |\n| --- | --- | --- |\n..."
|
|
133
|
+
*/
|
|
134
|
+
export declare const insertTable: (edit: TextEdit) => TextEdit;
|
|
135
|
+
/**
|
|
136
|
+
* Add an empty row after the cursor's row (after the delimiter row, when in the header).
|
|
137
|
+
*/
|
|
138
|
+
export declare const addTableRow: (edit: TextEdit) => TextEdit | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Add an empty column after the cursor's column.
|
|
141
|
+
*/
|
|
142
|
+
export declare const addTableColumn: (edit: TextEdit) => TextEdit | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Remove the cursor's row. The header and delimiter rows can't be removed.
|
|
145
|
+
*/
|
|
146
|
+
export declare const removeTableRow: (edit: TextEdit) => TextEdit | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Remove the cursor's column, or the whole table if it is the last one.
|
|
149
|
+
*/
|
|
150
|
+
export declare const removeTableColumn: (edit: TextEdit) => TextEdit | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Remove the table the cursor is in.
|
|
153
|
+
*/
|
|
154
|
+
export declare const removeTable: (edit: TextEdit) => TextEdit | undefined;
|
|
155
|
+
/** Toggle a heading of the given level on the selected lines */
|
|
156
|
+
export declare const toggleHeading: (edit: TextEdit, level: number) => TextEdit;
|
|
157
|
+
/** Toggle a bullet list on the selected lines */
|
|
158
|
+
export declare const toggleBulletList: (edit: TextEdit) => TextEdit;
|
|
159
|
+
/** Toggle a numbered list on the selected lines */
|
|
160
|
+
export declare const toggleNumberedList: (edit: TextEdit) => TextEdit;
|
|
161
|
+
/** Toggle a quote on the selected lines */
|
|
162
|
+
export declare const toggleQuote: (edit: TextEdit) => TextEdit;
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type FieldChoice, type FieldKind, type MetadataProblem, type MetadataSchema } from "@lvl99dotcom/edaha.md/generator/metadata";
|
|
2
|
+
/**
|
|
3
|
+
* A metadata value's label: its field's title, its schema's title, or its key.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* fieldLabel("featured", { title: "Featured Image", $edahaField: { file: true } }); // "Featured Image"
|
|
7
|
+
*/
|
|
8
|
+
export declare const fieldLabel: (key: string, schema: MetadataSchema) => string;
|
|
9
|
+
/** A metadata value's description: its field's, or its schema's */
|
|
10
|
+
export declare const fieldDescription: (schema: MetadataSchema) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* How a value is edited: the kind of its field, "object" for a map of fields, "list" for a list edited item by item.
|
|
13
|
+
*/
|
|
14
|
+
export declare const editorKind: (schema: MetadataSchema) => FieldKind | "object" | "list";
|
|
15
|
+
/**
|
|
16
|
+
* The choices of a select or radio field: its own `options`, or its schema's `enum` (its items' for a whole list).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* fieldChoices({ enum: ["a", "b"], $edahaField: { select: true } }); // [{ value: "a" }, { value: "b" }]
|
|
20
|
+
*/
|
|
21
|
+
export declare const fieldChoices: (schema: MetadataSchema) => FieldChoice[];
|
|
22
|
+
/**
|
|
23
|
+
* A field's HTML attributes: from its schema's keywords (e.g. `minimum` becomes `min`), then its own options (e.g.
|
|
24
|
+
* `accept`, `step`, `rows`), which win.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* inputAttributes({ type: "number", maximum: 10, $edahaField: { number: { step: 1 } } }); // { max: "10", step: "1" }
|
|
28
|
+
*/
|
|
29
|
+
export declare const inputAttributes: (schema: MetadataSchema) => Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Set a value inside another at a path of keys and list positions, without changing the original. Setting undefined
|
|
32
|
+
* leaves out a map's key.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* setAt({ a: [1, 2] }, ["a", "1"], 5); // { a: [1, 5] }
|
|
36
|
+
* setAt({ a: 1, b: 2 }, ["b"], undefined); // { a: 1 }
|
|
37
|
+
*/
|
|
38
|
+
export declare const setAt: (root: unknown, path: string[], value: unknown) => unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Read an input's value for a field kind: numbers as numbers, checkboxes as true or false, and other text as text
|
|
41
|
+
* (undefined when empty, so the value is left out).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* inputValue("number", "3.5"); // 3.5
|
|
45
|
+
* inputValue("text", ""); // undefined
|
|
46
|
+
*/
|
|
47
|
+
export declare const inputValue: (kind: FieldKind, input: string | boolean) => unknown;
|
|
48
|
+
/**
|
|
49
|
+
* The values a checkbox saves: its `value` option when checked and nothing when not (e.g. `{ checkbox: { value:
|
|
50
|
+
* "none" } }`), or true and false.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* checkboxValues({ $edahaField: { checkbox: { value: "none" } } }); // { checked: "none", unchecked: undefined }
|
|
54
|
+
* checkboxValues({ $edahaField: { checkbox: true } }); // { checked: true, unchecked: false }
|
|
55
|
+
*/
|
|
56
|
+
export declare const checkboxValues: (schema: MetadataSchema) => {
|
|
57
|
+
checked: unknown;
|
|
58
|
+
unchecked: unknown;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A colour field's value as its input shows it: with a "#" (e.g. "0687f5" as "#0687f5"), or empty when it isn't a
|
|
62
|
+
* colour.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* colourInputValue("0687F5"); // "#0687f5"
|
|
66
|
+
*/
|
|
67
|
+
export declare const colourInputValue: (value: unknown) => string;
|
|
68
|
+
/**
|
|
69
|
+
* A colour chosen in a colour field, written like the field's value (or default) was: without a "#" if it had none.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* colourValue("#051c2c", "ffffff"); // "051c2c"
|
|
73
|
+
* colourValue("#051c2c", undefined); // "#051c2c"
|
|
74
|
+
*/
|
|
75
|
+
export declare const colourValue: (input: string, current: unknown) => string;
|
|
76
|
+
/** The problems with exactly the value at a path */
|
|
77
|
+
export declare const problemsAt: (problems: MetadataProblem[], path: string) => MetadataProblem[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow screens (phones and small tablets), where the editor always has its compact layout: the article list opens
|
|
3
|
+
* from a menu button and the article's settings open full screen from a bar at the bottom. Keep in step with the
|
|
4
|
+
* `@media (max-width: 899.98px)` rules in style.css.
|
|
5
|
+
*/
|
|
6
|
+
export declare const NARROW_QUERY = "(max-width: 899.98px)";
|
|
7
|
+
/**
|
|
8
|
+
* Whether the screen is narrow now (false where the browser can't tell).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* isNarrow(); // true on a phone
|
|
12
|
+
*/
|
|
13
|
+
export declare const isNarrow: () => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Call a function when the screen becomes narrow or wide, e.g. when a window is resized or a tablet turned. Returns a
|
|
16
|
+
* function that stops it.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const stop = onNarrowChange(() => (element.open = false));
|
|
20
|
+
*/
|
|
21
|
+
export declare const onNarrowChange: (listener: () => void) => (() => void);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import type { EmbedTools } from "../../embeds/index.ts";
|
|
3
|
+
/** Gives the address an image is shown from, for its `src` in the body (e.g. on the editor's server) */
|
|
4
|
+
export type FileAddress = (src: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Images, shown from the address `address` gives for their `src`, which the body's HTML keeps as it is.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* AddressedImage.configure({ address: (src) => `http://127.0.0.1:5193${src}` });
|
|
10
|
+
*/
|
|
11
|
+
export declare const AddressedImage: import("@tiptap/core").Node<{
|
|
12
|
+
address: FileAddress;
|
|
13
|
+
}, any>;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the floating format toolbar shows: while text is selected in the editor (or focus is in the toolbar), and
|
|
16
|
+
* not in code or raw text, which can't be formatted.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* showFormatMenu(editor, menu); // true while "Hello" is selected in a paragraph
|
|
20
|
+
*/
|
|
21
|
+
export declare const showFormatMenu: (editor: Editor, menu: HTMLElement) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Create a Tiptap editor for an article body, with images, links, tables, collapsible details blocks, small and big
|
|
24
|
+
* text, heading IDs shown after headings, the readmore break and embed blocks.
|
|
25
|
+
*
|
|
26
|
+
* @param onUpdate - called with the new HTML whenever the content changes
|
|
27
|
+
* @param embedTools - the embed tools, for embed blocks' names and frames (read when a block is shown)
|
|
28
|
+
* @param formatMenu - a toolbar to float above selected text (see showFormatMenu), if any
|
|
29
|
+
* @param fileAddress - the address images are shown from, for their `src` (default: their `src`)
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const editor = createRichtextEditor(element, "<p>Hello</p>", (html) => console.log(html));
|
|
33
|
+
*/
|
|
34
|
+
export declare const createRichtextEditor: (element: HTMLElement, content: string, onUpdate: (html: string) => void, embedTools?: () => EmbedTools | undefined, formatMenu?: HTMLElement, fileAddress?: FileAddress) => Editor;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Extension, Mark, Node, type NodeViewRendererProps } from "@tiptap/core";
|
|
2
|
+
import { type NodeView } from "@tiptap/pm/view";
|
|
3
|
+
import { type EmbedTools, type EmbedValue } from "../../embeds/index.ts";
|
|
4
|
+
declare module "@tiptap/core" {
|
|
5
|
+
interface Commands<ReturnType> {
|
|
6
|
+
readmore: {
|
|
7
|
+
/** Insert the readmore break at the cursor, removing any other one (an article has at most one) */
|
|
8
|
+
setReadmore: () => ReturnType;
|
|
9
|
+
};
|
|
10
|
+
embed: {
|
|
11
|
+
/** Insert an embed block, or change the selected embed block's kind and content */
|
|
12
|
+
setEmbed: (value: EmbedValue) => ReturnType;
|
|
13
|
+
/** Insert an embed block, after the selected block if one is selected (rather than in its place) */
|
|
14
|
+
insertEmbed: (value: EmbedValue) => ReturnType;
|
|
15
|
+
};
|
|
16
|
+
raw: {
|
|
17
|
+
/** Turn the current block into a raw block, or a raw block back into a paragraph */
|
|
18
|
+
toggleRaw: () => ReturnType;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** A button in a block's header */
|
|
23
|
+
interface BlockButton {
|
|
24
|
+
text: string;
|
|
25
|
+
/** Called with the block's position and element */
|
|
26
|
+
onClick: (pos: number, dom: HTMLElement) => void;
|
|
27
|
+
}
|
|
28
|
+
/** Event fired (bubbling) by an embed block's "Edit" button, after selecting the block */
|
|
29
|
+
export declare const EMBED_EDIT_EVENT = "embed-edit";
|
|
30
|
+
/** Event that makes an embed block show itself again, e.g. once the embed tools are known (fired at `.embed-block`) */
|
|
31
|
+
export declare const EMBED_REFRESH_EVENT = "embed-refresh";
|
|
32
|
+
/**
|
|
33
|
+
* Create the editor's view of a block: a labelled box with a "Remove" button, that can also be clicked to select it
|
|
34
|
+
* (then deleted with Backspace or Delete, or changed from the toolbar). The saved HTML still comes from the node's
|
|
35
|
+
* renderHTML. Returns the view and its parts, so blocks can add their own content.
|
|
36
|
+
*
|
|
37
|
+
* @param buttons - extra buttons shown before "Remove"
|
|
38
|
+
*/
|
|
39
|
+
export declare const blockView: (className: string, label: string, { editor, getPos }: Pick<NodeViewRendererProps, "editor" | "getPos">, buttons?: BlockButton[]) => {
|
|
40
|
+
view: NodeView;
|
|
41
|
+
dom: HTMLDivElement;
|
|
42
|
+
title: HTMLSpanElement;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The `<!-- readmore -->` break, saved as `<hr class="readmore">` and shown in the editor as a "Read more" box with a
|
|
46
|
+
* "Remove" button.
|
|
47
|
+
*/
|
|
48
|
+
export declare const Readmore: Node<any, any>;
|
|
49
|
+
/**
|
|
50
|
+
* A raw block (`<!-- raw -->...<!-- /raw -->` on its own lines): plain text that the website shows exactly as it is
|
|
51
|
+
* written, with no Markdown, embeds or shortcodes. Saved as `<pre class="raw">`, and edited like a code block (Enter
|
|
52
|
+
* adds a line break, Mod-Enter leaves it).
|
|
53
|
+
*/
|
|
54
|
+
export declare const Raw: Node<any, any>;
|
|
55
|
+
/**
|
|
56
|
+
* Raw text within a line (`text <!-- raw -->...<!-- /raw --> text`), shown exactly as it is written. Saved as
|
|
57
|
+
* `<span class="raw">`; it can't have other formatting.
|
|
58
|
+
*/
|
|
59
|
+
export declare const RawInline: Mark<any, any>;
|
|
60
|
+
/**
|
|
61
|
+
* Smaller text, saved as `<small>`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const Small: Mark<any, any>;
|
|
64
|
+
/**
|
|
65
|
+
* Bigger text, saved as `<big>` (which browsers still show bigger, although HTML no longer recommends it).
|
|
66
|
+
*/
|
|
67
|
+
export declare const Big: Mark<any, any>;
|
|
68
|
+
/** Options of the embed block */
|
|
69
|
+
export interface EmbedOptions {
|
|
70
|
+
/** The embed tools (read when a block is shown, so they can be set after the editor is created) */
|
|
71
|
+
tools: () => EmbedTools | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* An embed block (`<!-- embed:<key> -->content<!-- /embed:<key> -->`), saved as
|
|
75
|
+
* `<div class="embed" data-embed="key" data-content="...">` and shown in the editor as a box with its kind, the embed
|
|
76
|
+
* in a sandboxed frame (as the editor shows it, see the embed plugins' `editor` renderers), and "Edit" and "Remove"
|
|
77
|
+
* buttons. "Edit" selects the block and fires EMBED_EDIT_EVENT, so the toolbar can ask for its new kind and content.
|
|
78
|
+
*/
|
|
79
|
+
export declare const Embed: Node<EmbedOptions, any>;
|
|
80
|
+
/**
|
|
81
|
+
* Show each heading's ID after it (e.g. `#this-is-an-example`), as the website gives it from the heading's text, so it
|
|
82
|
+
* can be copied for links. The IDs aren't saved: they come from the text whenever the article is built.
|
|
83
|
+
*/
|
|
84
|
+
export declare const HeadingIds: Extension<any, any>;
|
|
85
|
+
/**
|
|
86
|
+
* Select a whole details block when its box is clicked (its border, padding or "Details" label, rather than its
|
|
87
|
+
* summary or content), so it can be cut, copied, pasted, deleted or moved like the other blocks.
|
|
88
|
+
*/
|
|
89
|
+
export declare const SelectDetails: Extension<any, any>;
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ArticleOrder } from "../../server/types/index.ts";
|
|
2
|
+
/** How a table is sorted: by a column, ascending or descending, or neither (its default order) */
|
|
3
|
+
export interface TableSort<S extends string> {
|
|
4
|
+
sort?: S | undefined;
|
|
5
|
+
order?: ArticleOrder | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* How a table is sorted after pressing a column's heading: another column sorts ascending, the sorted column changes
|
|
9
|
+
* to descending, and a column sorted descending goes back to the table's default order.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* nextSort({}, "title"); // { sort: "title", order: "asc" }
|
|
13
|
+
* nextSort({ sort: "title", order: "asc" }, "title"); // { sort: "title", order: "desc" }
|
|
14
|
+
* nextSort({ sort: "title", order: "desc" }, "title"); // {}
|
|
15
|
+
*/
|
|
16
|
+
export declare const nextSort: <S extends string>(current: TableSort<S>, column: S) => TableSort<S>;
|
|
17
|
+
/**
|
|
18
|
+
* Render a column's heading: a button that sorts by it (see `nextSort`), with an arrow showing which way it is sorted,
|
|
19
|
+
* a tooltip saying what pressing it does, and `aria-sort` for screen readers.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* html`<tr>${sortHeading("title", "Title", { sort, order }, (column) => sortBy(column))}</tr>`
|
|
23
|
+
*/
|
|
24
|
+
export declare const sortHeading: <S extends string>(column: S, label: string, current: TableSort<S>, onSort: (column: S) => void) => import("lit").TemplateResult<1>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** A colour theme */
|
|
2
|
+
export type Theme = "light" | "dark";
|
|
3
|
+
/** Where the editor remembers the chosen theme in this browser */
|
|
4
|
+
export declare const THEME_STORAGE_KEY = "edaha-editor-theme";
|
|
5
|
+
/**
|
|
6
|
+
* The theme chosen with the theme switcher and remembered in this browser, or undefined if none was chosen (or the
|
|
7
|
+
* browser blocks storage).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* storedTheme(); // "dark"
|
|
11
|
+
*/
|
|
12
|
+
export declare const storedTheme: () => Theme | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The theme being shown: the chosen one (`data-theme` on <html>), or else the device's (light if it can't tell).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* currentTheme(); // "light"
|
|
18
|
+
*/
|
|
19
|
+
export declare const currentTheme: () => Theme;
|
|
20
|
+
/**
|
|
21
|
+
* Show a theme (as `data-theme` on <html>, which the stylesheet uses) and remember it where the browser allows it.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* chooseTheme("dark");
|
|
25
|
+
*/
|
|
26
|
+
export declare const chooseTheme: (theme: Theme) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Switch to the other theme from the one being shown. Returns the new theme.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* toggleTheme(); // "dark" when the light theme was shown
|
|
32
|
+
*/
|
|
33
|
+
export declare const toggleTheme: () => Theme;
|
|
34
|
+
/**
|
|
35
|
+
* The theme switcher's label: what pressing it does.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* themeSwitcherLabel(); // "Switch to the dark theme" when the light theme is shown
|
|
39
|
+
*/
|
|
40
|
+
export declare const themeSwitcherLabel: () => string;
|
|
41
|
+
/**
|
|
42
|
+
* Call a function when the device's light or dark setting changes (which changes the theme shown while none is
|
|
43
|
+
* chosen). Returns a function that stops it.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const stop = onDeviceThemeChange(() => element.requestUpdate());
|
|
47
|
+
*/
|
|
48
|
+
export declare const onDeviceThemeChange: (listener: () => void) => (() => void);
|