svelte-rtf-editor 1.15.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/dist/components/ColorPicker.svelte +4 -2
- package/dist/components/ColorPicker.svelte.d.ts +2 -0
- package/dist/components/FontMenu.svelte +187 -0
- package/dist/components/FontMenu.svelte.d.ts +20 -0
- package/dist/components/InkEditor.svelte +129 -2
- package/dist/components/InkEditor.svelte.d.ts +120 -1
- package/dist/components/Toolbar.svelte +265 -131
- package/dist/components/Toolbar.svelte.d.ts +13 -0
- package/dist/components/ToolbarButton.svelte +4 -1
- package/dist/components/ToolbarButton.svelte.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/toolbar-tools.d.ts +26 -0
- package/dist/toolbar-tools.js +50 -0
- package/package.json +1 -1
|
@@ -1,3 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InkEditor — A reusable Svelte 5 Rich Text Editor component.
|
|
3
|
+
*
|
|
4
|
+
* Props:
|
|
5
|
+
* content — Initial HTML content (string). Default: an empty paragraph. It is made
|
|
6
|
+
* safe before it is shown (see sanitize.ts): scripts, event handlers and
|
|
7
|
+
* the like are taken out.
|
|
8
|
+
* placeholder — Placeholder text shown when editor is empty.
|
|
9
|
+
* autosave — Keep a draft in localStorage and restore it on mount, in place of
|
|
10
|
+
* `content`. Default: false. Give each document its own storageKey.
|
|
11
|
+
* storageKey — localStorage key for auto-save. Default: 'ink-editor-content'.
|
|
12
|
+
* showToolbar — Show the formatting toolbar. Default: true.
|
|
13
|
+
* stickyToolbar — Keep the toolbar in sight while a long document is scrolled: it
|
|
14
|
+
* stays at the top of the window, or of the scrolling element the
|
|
15
|
+
* editor is in. Default: true. Under a header of your own that stays
|
|
16
|
+
* too, set the CSS variable --ink-toolbar-top to its height.
|
|
17
|
+
* showStatusBar — Show the word/char count status bar. Default: true.
|
|
18
|
+
* minHeight — CSS min-height of the editing area. Default: '40vh'.
|
|
19
|
+
* readonly — If true, editor is not editable. Default: false.
|
|
20
|
+
* ariaLabel — The name of the editing area for a screen reader. Default: 'Document'.
|
|
21
|
+
* maxImageEdge — Longest edge (px) an inserted image is scaled down to.
|
|
22
|
+
* 0 keeps the original dimensions. Default: 1600.
|
|
23
|
+
* maxImageDisplayWidth
|
|
24
|
+
* — Width (px) a newly inserted image is displayed at, unless
|
|
25
|
+
* the editor column is narrower. Defaults to 624 — 6.5in of
|
|
26
|
+
* page at 96 dpi — so pictures arrive sized to the page
|
|
27
|
+
* rather than to the browser window. 0 fills the column.
|
|
28
|
+
* maxImageBytes — Encoded byte ceiling per inserted image. Pictures over it
|
|
29
|
+
* are re-encoded (and shrunk if needed) until they fit,
|
|
30
|
+
* which is what bounds the RTF payload — it costs two hex
|
|
31
|
+
* characters per byte. 0 disables. Default: 524288 (512 KB,
|
|
32
|
+
* about 1 MB of document per image).
|
|
33
|
+
* maxRtfBytes — The largest RTF file Import reads. Default: 52428800 (50 MB);
|
|
34
|
+
* 0 reads any size.
|
|
35
|
+
* fontFamily — Font for the document, both on screen and in the RTF.
|
|
36
|
+
* Given a CSS list ('Segoe UI, Selawik, sans-serif'), the first
|
|
37
|
+
* family is the font, and the rest is what a screen without it
|
|
38
|
+
* shows. Default: DEFAULT_FONT_FAMILY (rtf-writer.ts).
|
|
39
|
+
* fontSize — Body text size in points, both on screen and in the RTF.
|
|
40
|
+
* Headings scale from it. Default: 12.
|
|
41
|
+
* fontSizes — The sizes, in points, the toolbar's size list offers for the
|
|
42
|
+
* selected text. The body size is always among them. An empty
|
|
43
|
+
* list takes the size list off the toolbar.
|
|
44
|
+
* Default: 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 36.
|
|
45
|
+
* fonts — The fonts the toolbar's font list offers for the selected text,
|
|
46
|
+
* beside the document's own: names ('Calibri'), or CSS lists whose
|
|
47
|
+
* first family is the name ('Calibri, Carlito, sans-serif'). Text
|
|
48
|
+
* in one of them is written in it to the RTF and read back in it;
|
|
49
|
+
* any other font is taken off HTML as it comes in, set or pasted.
|
|
50
|
+
* Default: none: there is no font list, and no font but the
|
|
51
|
+
* document's is let in.
|
|
52
|
+
* fontMenu — If true, a right-click on the text opens the editor's own menu of
|
|
53
|
+
* `fonts` in place of the browser's, to set the font of the selected
|
|
54
|
+
* text. Shift with the right-click still opens the browser's menu (its
|
|
55
|
+
* spelling suggestions, Copy and Paste), and so does a right-click on a
|
|
56
|
+
* link or a picture. The menu key and Shift+F10 open it at the caret.
|
|
57
|
+
* Nothing changes without `fonts`, or when readonly. Default: false.
|
|
58
|
+
* tools — The toolbar's controls, by name (TOOLBAR_TOOLS, toolbar-tools.ts). A
|
|
59
|
+
* control not named is not rendered; its keyboard shortcut still works.
|
|
60
|
+
* The order is the editor's own, and an empty group or a divider with
|
|
61
|
+
* nothing beside it is left out. An unknown name is ignored with a console
|
|
62
|
+
* warning. Default: all of them.
|
|
63
|
+
* moreTools — Those of `tools` that wait behind a More button at the end of the first
|
|
64
|
+
* row, in a second row under it when opened. Default: none, and no button.
|
|
65
|
+
* moreOpen — Bindable: whether that second row is open. The editor keeps it nowhere
|
|
66
|
+
* itself. Default: false.
|
|
67
|
+
* moreLabel, lessLabel — The button's words, closed and open. Default: 'More', 'Less'.
|
|
68
|
+
* toolbarEnd — A snippet of the application's own controls, at the end of the first
|
|
69
|
+
* row (before the More button).
|
|
70
|
+
* keepAttributes — `data-` attributes the application's documents carry, which
|
|
71
|
+
* the editor leaves on their elements: a mark on a paragraph that
|
|
72
|
+
* the application reads back (`data-section="2"`). Every other
|
|
73
|
+
* attribute the editor does not know is taken off HTML as it comes
|
|
74
|
+
* in, set or pasted. Names that do not start with `data-` are not
|
|
75
|
+
* kept. Default: none.
|
|
76
|
+
* keepClasses — Class names of the application's own that stay in an element's
|
|
77
|
+
* class list the same way (`<pre class="summary">`). Every other
|
|
78
|
+
* class is taken off. Default: none.
|
|
79
|
+
*
|
|
80
|
+
* Events (callback props):
|
|
81
|
+
* onchange — Fires on content change with
|
|
82
|
+
* { html, text, wordCount, charCount, estimatedRtfBytes }.
|
|
83
|
+
* onsave — Fires on auto-save or Ctrl+S with { html }.
|
|
84
|
+
* onimport — Fires after a successful RTF import with { html }.
|
|
85
|
+
* onmoretoggle — Fires with the new state when the More button opens or closes its row.
|
|
86
|
+
*
|
|
87
|
+
* Bindable methods (via bind:this):
|
|
88
|
+
* getHTML() — Returns the current editor HTML string.
|
|
89
|
+
* getText() — Returns plain text content.
|
|
90
|
+
* setHTML(html) — Replaces editor content with the given HTML.
|
|
91
|
+
* getMarkdown() — Returns Markdown conversion of current content.
|
|
92
|
+
* getRTF() — Returns RTF conversion of current content.
|
|
93
|
+
* getRtfSize() — Returns the exact byte size of that RTF.
|
|
94
|
+
* clear() — Clears the editor (no confirm dialog).
|
|
95
|
+
* focus() — Focuses the editor.
|
|
96
|
+
* exportFile(format) — Downloads as 'html', 'md', or 'rtf'.
|
|
97
|
+
* importRtf() — Opens the file picker to import an RTF file.
|
|
98
|
+
* setFontSize(points) — Sets the size of the selected text, or of what is typed next.
|
|
99
|
+
* setFont(name) — Sets the font of the selected text, or of what is typed next, to
|
|
100
|
+
* one of `fonts`; '' or the document font's name sets it back.
|
|
101
|
+
* clearFormatting() — Takes bold, italic, underline, strike, color, size and font off
|
|
102
|
+
* the selected text. Headings, lists, links, alignment, indents and
|
|
103
|
+
* the application's own marks stay.
|
|
104
|
+
*/
|
|
105
|
+
import { type Snippet } from 'svelte';
|
|
106
|
+
import { type ToolbarTool } from '../toolbar-tools.js';
|
|
1
107
|
interface ChangePayload {
|
|
2
108
|
/**
|
|
3
109
|
* `html`, `text` and `estimatedRtfBytes` are worked out when the handler reads them, and
|
|
@@ -36,6 +142,19 @@ interface Props {
|
|
|
36
142
|
fontSizes?: number[];
|
|
37
143
|
/** The fonts offered for text, beside the document's own; none unless given. */
|
|
38
144
|
fonts?: string[];
|
|
145
|
+
/** A right-click on the text opens a menu of `fonts`; the browser's menu is Shift + right-click. */
|
|
146
|
+
fontMenu?: boolean;
|
|
147
|
+
/** The toolbar's controls, by name; all of them unless given. */
|
|
148
|
+
tools?: readonly ToolbarTool[];
|
|
149
|
+
/** Those of `tools` behind a More button, in a second row; none unless given. */
|
|
150
|
+
moreTools?: readonly ToolbarTool[];
|
|
151
|
+
/** Whether the second row is open (bindable). */
|
|
152
|
+
moreOpen?: boolean;
|
|
153
|
+
moreLabel?: string;
|
|
154
|
+
lessLabel?: string;
|
|
155
|
+
/** The application's own controls, at the end of the toolbar's first row. */
|
|
156
|
+
toolbarEnd?: Snippet;
|
|
157
|
+
onmoretoggle?: (open: boolean) => void;
|
|
39
158
|
/** `data-` attributes of the application's own, kept on HTML that is set or pasted. */
|
|
40
159
|
keepAttributes?: string[];
|
|
41
160
|
/** Class names of the application's own, kept the same way. */
|
|
@@ -74,6 +193,6 @@ declare const InkEditor: import("svelte").Component<Props, {
|
|
|
74
193
|
borders?: boolean;
|
|
75
194
|
header?: boolean;
|
|
76
195
|
}) => void;
|
|
77
|
-
}, "">;
|
|
196
|
+
}, "moreOpen">;
|
|
78
197
|
type InkEditor = ReturnType<typeof InkEditor>;
|
|
79
198
|
export default InkEditor;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/** Each toolbar's second row has an id of its own, for its More button to name. */
|
|
3
|
+
let rows = 0;
|
|
4
|
+
</script>
|
|
5
|
+
|
|
1
6
|
<script lang="ts">
|
|
7
|
+
import type { Snippet } from 'svelte';
|
|
8
|
+
import { toolbarRow, TOOLBAR_TOOLS, type ToolbarTool } from '../toolbar-tools.js';
|
|
2
9
|
import ToolbarButton from './ToolbarButton.svelte';
|
|
3
10
|
import ColorPicker from './ColorPicker.svelte';
|
|
4
11
|
|
|
@@ -31,6 +38,17 @@
|
|
|
31
38
|
/** The Copy format brush is in hand: the button shows as pressed. */
|
|
32
39
|
copyingFormat?: boolean;
|
|
33
40
|
oncopyformat?: () => void;
|
|
41
|
+
/** The controls the toolbar has. All of them unless given. */
|
|
42
|
+
tools?: ReadonlySet<ToolbarTool>;
|
|
43
|
+
/** Those of `tools` that wait behind the More button, in a second row. None, and there is no button. */
|
|
44
|
+
moreTools?: ReadonlySet<ToolbarTool>;
|
|
45
|
+
/** Whether the second row is open. */
|
|
46
|
+
moreOpen?: boolean;
|
|
47
|
+
onmoretoggle?: (open: boolean) => void;
|
|
48
|
+
moreLabel?: string;
|
|
49
|
+
lessLabel?: string;
|
|
50
|
+
/** The application's own controls, at the end of the first row (before the More button). */
|
|
51
|
+
end?: Snippet;
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
let {
|
|
@@ -50,9 +68,23 @@
|
|
|
50
68
|
onfont,
|
|
51
69
|
spacing = { line: null, before: 0, after: 0 },
|
|
52
70
|
copyingFormat = false,
|
|
53
|
-
oncopyformat
|
|
71
|
+
oncopyformat,
|
|
72
|
+
tools = new Set(TOOLBAR_TOOLS),
|
|
73
|
+
moreTools = new Set(),
|
|
74
|
+
moreOpen = false,
|
|
75
|
+
onmoretoggle,
|
|
76
|
+
moreLabel = 'More',
|
|
77
|
+
lessLabel = 'Less',
|
|
78
|
+
end
|
|
54
79
|
}: Props = $props();
|
|
55
80
|
|
|
81
|
+
const moreId = `ink-toolbar-more-${++rows}`;
|
|
82
|
+
|
|
83
|
+
/** A control that has something to offer: a font list needs fonts, a size list sizes. */
|
|
84
|
+
const offers = (tool: ToolbarTool) => (tool === 'font' ? fonts.length > 0 : tool === 'fontSize' ? fontSizes.length > 0 : true);
|
|
85
|
+
const firstRow = $derived(toolbarRow((tool) => tools.has(tool) && !moreTools.has(tool) && offers(tool)));
|
|
86
|
+
const moreRow = $derived(toolbarRow((tool) => tools.has(tool) && moreTools.has(tool) && offers(tool)));
|
|
87
|
+
|
|
56
88
|
// The size at the caret is shown even when it is not one of the sizes offered (13.5 pt in a
|
|
57
89
|
// document from elsewhere), so the list never shows a size the text does not have.
|
|
58
90
|
const sizeChoices = $derived(
|
|
@@ -82,10 +114,11 @@
|
|
|
82
114
|
}
|
|
83
115
|
</script>
|
|
84
116
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
117
|
+
<!-- One control of the toolbar, by its name. -->
|
|
118
|
+
{#snippet control(tool: ToolbarTool)}
|
|
119
|
+
{#if tool === 'block'}
|
|
88
120
|
<select
|
|
121
|
+
data-tool="block"
|
|
89
122
|
class="tb-select"
|
|
90
123
|
title="Paragraph style"
|
|
91
124
|
aria-label="Paragraph style"
|
|
@@ -99,142 +132,117 @@
|
|
|
99
132
|
<option value="blockquote">Quote</option>
|
|
100
133
|
<option value="pre">Code Block</option>
|
|
101
134
|
</select>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
value=
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
{/if}
|
|
144
|
-
{#each sizeChoices as size (size)}
|
|
145
|
-
<option value={String(size)}>{size}</option>
|
|
146
|
-
{/each}
|
|
147
|
-
</select>
|
|
148
|
-
</div>
|
|
149
|
-
{/if}
|
|
150
|
-
|
|
151
|
-
<div class="toolbar-divider"></div>
|
|
152
|
-
|
|
153
|
-
<!-- Inline formatting -->
|
|
154
|
-
<div class="toolbar-group">
|
|
155
|
-
<ToolbarButton active={formatState.bold} title="Bold (Ctrl+B)" onclick={() => exec('bold')}>
|
|
135
|
+
{:else if tool === 'font'}
|
|
136
|
+
<select
|
|
137
|
+
data-tool="font"
|
|
138
|
+
class="tb-select tb-font"
|
|
139
|
+
title="Font"
|
|
140
|
+
aria-label="Font"
|
|
141
|
+
value={font === null ? ' ' : font}
|
|
142
|
+
onchange={(e) => {
|
|
143
|
+
const key = (e.target as HTMLSelectElement).value;
|
|
144
|
+
if (key !== ' ') onfont?.(key);
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{#if font === null}
|
|
148
|
+
<option value=" "></option>
|
|
149
|
+
{/if}
|
|
150
|
+
<option value="">{documentFont}</option>
|
|
151
|
+
{#each fonts as choice (choice.key)}
|
|
152
|
+
<option value={choice.key} style:font-family={choice.css}>{choice.name}</option>
|
|
153
|
+
{/each}
|
|
154
|
+
</select>
|
|
155
|
+
{:else if tool === 'fontSize'}
|
|
156
|
+
<select
|
|
157
|
+
data-tool="fontSize"
|
|
158
|
+
class="tb-select tb-size"
|
|
159
|
+
title="Font size"
|
|
160
|
+
aria-label="Font size"
|
|
161
|
+
value={fontSize === null ? '' : String(fontSize)}
|
|
162
|
+
onchange={(e) => {
|
|
163
|
+
const points = Number((e.target as HTMLSelectElement).value);
|
|
164
|
+
if (points > 0) onfontsize?.(points);
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{#if fontSize === null}
|
|
168
|
+
<option value=""></option>
|
|
169
|
+
{/if}
|
|
170
|
+
{#each sizeChoices as size (size)}
|
|
171
|
+
<option value={String(size)}>{size}</option>
|
|
172
|
+
{/each}
|
|
173
|
+
</select>
|
|
174
|
+
{:else if tool === 'bold'}
|
|
175
|
+
<ToolbarButton tool="bold" active={formatState.bold} title="Bold (Ctrl+B)" onclick={() => exec('bold')}>
|
|
156
176
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>
|
|
157
177
|
</ToolbarButton>
|
|
158
|
-
|
|
178
|
+
{:else if tool === 'italic'}
|
|
179
|
+
<ToolbarButton tool="italic" active={formatState.italic} title="Italic (Ctrl+I)" onclick={() => exec('italic')}>
|
|
159
180
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>
|
|
160
181
|
</ToolbarButton>
|
|
161
|
-
|
|
182
|
+
{:else if tool === 'underline'}
|
|
183
|
+
<ToolbarButton tool="underline" active={formatState.underline} title="Underline (Ctrl+U)" onclick={() => exec('underline')}>
|
|
162
184
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>
|
|
163
185
|
</ToolbarButton>
|
|
164
|
-
|
|
186
|
+
{:else if tool === 'strikethrough'}
|
|
187
|
+
<ToolbarButton tool="strikethrough" active={formatState.strikeThrough} title="Strikethrough" onclick={() => exec('strikeThrough')}>
|
|
165
188
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M16 4c-.5-1.5-2.5-3-5-3-3 0-5 2-5 4.5 0 2 1 3.5 5 5"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M8 20c.5 1.5 2.5 3 5 3 3 0 5-2 5-4.5 0-1.5-.5-2.5-2-3.5"/></svg>
|
|
166
189
|
</ToolbarButton>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
<!-- Color, and all of the above taken off again -->
|
|
172
|
-
<div class="toolbar-group">
|
|
173
|
-
<ColorPicker value="#2C2520" title="Text color" onchange={(c) => exec('foreColor', c)} />
|
|
174
|
-
<ToolbarButton title="Clear formatting" onclick={() => exec('removeFormat')}>
|
|
190
|
+
{:else if tool === 'textColor'}
|
|
191
|
+
<ColorPicker tool="textColor" value="#2C2520" title="Text color" onchange={(c) => exec('foreColor', c)} />
|
|
192
|
+
{:else if tool === 'clearFormatting'}
|
|
193
|
+
<ToolbarButton tool="clearFormatting" title="Clear formatting" onclick={() => exec('removeFormat')}>
|
|
175
194
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/><line x1="18" y1="4" x2="4" y2="20" stroke="var(--accent)" stroke-width="2"/></svg>
|
|
176
195
|
</ToolbarButton>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
<div class="toolbar-divider"></div>
|
|
180
|
-
|
|
181
|
-
<!-- Lists -->
|
|
182
|
-
<div class="toolbar-group">
|
|
183
|
-
<ToolbarButton active={formatState.bulletList} title="Bullet list" onclick={() => exec('insertUnorderedList')}>
|
|
196
|
+
{:else if tool === 'bulletList'}
|
|
197
|
+
<ToolbarButton tool="bulletList" active={formatState.bulletList} title="Bullet list" onclick={() => exec('insertUnorderedList')}>
|
|
184
198
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="5" cy="6" r="1.5" fill="currentColor"/><circle cx="5" cy="12" r="1.5" fill="currentColor"/><circle cx="5" cy="18" r="1.5" fill="currentColor"/></svg>
|
|
185
199
|
</ToolbarButton>
|
|
186
|
-
|
|
200
|
+
{:else if tool === 'numberedList'}
|
|
201
|
+
<ToolbarButton tool="numberedList" active={formatState.numberedList} title="Numbered list" onclick={() => exec('insertOrderedList')}>
|
|
187
202
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="10" y1="6" x2="20" y2="6"/><line x1="10" y1="12" x2="20" y2="12"/><line x1="10" y1="18" x2="20" y2="18"/><text x="3" y="8" font-size="8" fill="currentColor" stroke="none" font-family="sans-serif">1</text><text x="3" y="14" font-size="8" fill="currentColor" stroke="none" font-family="sans-serif">2</text><text x="3" y="20" font-size="8" fill="currentColor" stroke="none" font-family="sans-serif">3</text></svg>
|
|
188
203
|
</ToolbarButton>
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
<div class="toolbar-divider"></div>
|
|
192
|
-
|
|
193
|
-
<!-- Alignment -->
|
|
194
|
-
<div class="toolbar-group">
|
|
195
|
-
<ToolbarButton title="Align left" onclick={() => exec('justifyLeft')}>
|
|
204
|
+
{:else if tool === 'alignLeft'}
|
|
205
|
+
<ToolbarButton tool="alignLeft" title="Align left" onclick={() => exec('justifyLeft')}>
|
|
196
206
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>
|
|
197
207
|
</ToolbarButton>
|
|
198
|
-
|
|
208
|
+
{:else if tool === 'alignCenter'}
|
|
209
|
+
<ToolbarButton tool="alignCenter" title="Align center" onclick={() => exec('justifyCenter')}>
|
|
199
210
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
|
|
200
211
|
</ToolbarButton>
|
|
201
|
-
|
|
212
|
+
{:else if tool === 'alignRight'}
|
|
213
|
+
<ToolbarButton tool="alignRight" title="Align right" onclick={() => exec('justifyRight')}>
|
|
202
214
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>
|
|
203
215
|
</ToolbarButton>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
<div class="toolbar-divider"></div>
|
|
207
|
-
|
|
208
|
-
<!-- Indent -->
|
|
209
|
-
<div class="toolbar-group">
|
|
210
|
-
<ToolbarButton title="Decrease indent (Ctrl+[)" onclick={() => exec('outdent')}>
|
|
216
|
+
{:else if tool === 'outdent'}
|
|
217
|
+
<ToolbarButton tool="outdent" title="Decrease indent (Ctrl+[)" onclick={() => exec('outdent')}>
|
|
211
218
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="11" y1="10" x2="21" y2="10"/><line x1="11" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/><polyline points="7 9 4 12 7 15"/></svg>
|
|
212
219
|
</ToolbarButton>
|
|
213
|
-
|
|
220
|
+
{:else if tool === 'indent'}
|
|
221
|
+
<ToolbarButton tool="indent" title="Increase indent (Ctrl+])" onclick={() => exec('indent')}>
|
|
214
222
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="11" y1="10" x2="21" y2="10"/><line x1="11" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/><polyline points="4 9 7 12 4 15"/></svg>
|
|
215
223
|
</ToolbarButton>
|
|
216
|
-
|
|
224
|
+
{:else if tool === 'hangingOutdent'}
|
|
225
|
+
<ToolbarButton tool="hangingOutdent" title="Decrease hanging indent" onclick={() => exec('hangingOutdent')}>
|
|
217
226
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="11" y1="10" x2="21" y2="10"/><line x1="11" y1="14" x2="21" y2="14"/><line x1="11" y1="19" x2="21" y2="19"/><polyline points="7 11.5 4 14.5 7 17.5"/></svg>
|
|
218
227
|
</ToolbarButton>
|
|
219
|
-
|
|
228
|
+
{:else if tool === 'hangingIndent'}
|
|
229
|
+
<ToolbarButton tool="hangingIndent" title="Increase hanging indent" onclick={() => exec('hangingIndent')}>
|
|
220
230
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="11" y1="10" x2="21" y2="10"/><line x1="11" y1="14" x2="21" y2="14"/><line x1="11" y1="19" x2="21" y2="19"/><polyline points="4 11.5 7 14.5 4 17.5"/></svg>
|
|
221
231
|
</ToolbarButton>
|
|
222
|
-
|
|
232
|
+
{:else if tool === 'hangAtCaret'}
|
|
233
|
+
<ToolbarButton tool="hangAtCaret" title="Hang at caret" onclick={() => exec('hangAtCaret')}>
|
|
223
234
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="7" y2="5"/><line x1="14" y1="5" x2="21" y2="5"/><line x1="10.5" y1="2" x2="10.5" y2="8" stroke="var(--accent, currentColor)"/><line x1="10.5" y1="11" x2="21" y2="11"/><line x1="10.5" y1="15" x2="21" y2="15"/><line x1="10.5" y1="19" x2="21" y2="19"/></svg>
|
|
224
235
|
</ToolbarButton>
|
|
225
|
-
|
|
236
|
+
{:else if tool === 'rightOutdent'}
|
|
237
|
+
<ToolbarButton tool="rightOutdent" title="Decrease right indent" onclick={() => exec('rightOutdent')}>
|
|
226
238
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="13" y2="10"/><line x1="3" y1="14" x2="13" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/><polyline points="17 9 20 12 17 15"/></svg>
|
|
227
239
|
</ToolbarButton>
|
|
228
|
-
|
|
240
|
+
{:else if tool === 'rightIndent'}
|
|
241
|
+
<ToolbarButton tool="rightIndent" title="Increase right indent" onclick={() => exec('rightIndent')}>
|
|
229
242
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="13" y2="10"/><line x1="3" y1="14" x2="13" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/><polyline points="20 9 17 12 20 15"/></svg>
|
|
230
243
|
</ToolbarButton>
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
<div class="toolbar-divider"></div>
|
|
234
|
-
|
|
235
|
-
<!-- Spacing -->
|
|
236
|
-
<div class="toolbar-group">
|
|
237
|
-
<select class="tb-select tb-spacing" title="Line and paragraph spacing" aria-label="Line and paragraph spacing" value="" onchange={chooseSpacing}>
|
|
244
|
+
{:else if tool === 'spacing'}
|
|
245
|
+
<select class="tb-select tb-spacing" data-tool="spacing" title="Line and paragraph spacing" aria-label="Line and paragraph spacing" value="" onchange={chooseSpacing}>
|
|
238
246
|
<option value="" hidden>Spacing</option>
|
|
239
247
|
<optgroup label="Line spacing">
|
|
240
248
|
{#each lineChoices as lines (lines)}
|
|
@@ -261,46 +269,98 @@
|
|
|
261
269
|
</optgroup>
|
|
262
270
|
{/if}
|
|
263
271
|
</select>
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
<div class="toolbar-divider"></div>
|
|
267
|
-
|
|
268
|
-
<!-- Copy format -->
|
|
269
|
-
<div class="toolbar-group">
|
|
270
|
-
<ToolbarButton active={copyingFormat} title="Copy format" onclick={oncopyformat}>
|
|
272
|
+
{:else if tool === 'copyFormat'}
|
|
273
|
+
<ToolbarButton tool="copyFormat" active={copyingFormat} title="Copy format" onclick={oncopyformat}>
|
|
271
274
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="14" height="6" rx="1.5"/><path d="M17 6h3v5h-9v3"/><rect x="9.5" y="14" width="3" height="7" rx="1"/></svg>
|
|
272
275
|
</ToolbarButton>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
<div class="toolbar-divider"></div>
|
|
276
|
-
|
|
277
|
-
<!-- Insert -->
|
|
278
|
-
<div class="toolbar-group">
|
|
279
|
-
<ToolbarButton title="Insert link (Ctrl+K)" onclick={oninsertlink}>
|
|
276
|
+
{:else if tool === 'link'}
|
|
277
|
+
<ToolbarButton tool="link" title="Insert link (Ctrl+K)" onclick={oninsertlink}>
|
|
280
278
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
|
281
279
|
</ToolbarButton>
|
|
282
|
-
|
|
280
|
+
{:else if tool === 'image'}
|
|
281
|
+
<ToolbarButton tool="image" title="Insert image" onclick={oninsertimage}>
|
|
283
282
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>
|
|
284
283
|
</ToolbarButton>
|
|
285
|
-
|
|
284
|
+
{:else if tool === 'table'}
|
|
285
|
+
<ToolbarButton tool="table" title="Insert table" onclick={oninserttable}>
|
|
286
286
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="4" x2="9" y2="20"/><line x1="15" y1="4" x2="15" y2="20"/></svg>
|
|
287
287
|
</ToolbarButton>
|
|
288
|
-
|
|
288
|
+
{:else if tool === 'horizontalRule'}
|
|
289
|
+
<ToolbarButton tool="horizontalRule" title="Horizontal rule" onclick={() => exec('insertHorizontalRule')}>
|
|
289
290
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="12" x2="21" y2="12"/></svg>
|
|
290
291
|
</ToolbarButton>
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
<div class="toolbar-divider"></div>
|
|
294
|
-
|
|
295
|
-
<!-- History -->
|
|
296
|
-
<div class="toolbar-group">
|
|
297
|
-
<ToolbarButton title="Undo (Ctrl+Z)" onclick={() => exec('undo')}>
|
|
292
|
+
{:else if tool === 'undo'}
|
|
293
|
+
<ToolbarButton tool="undo" title="Undo (Ctrl+Z)" onclick={() => exec('undo')}>
|
|
298
294
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M3 7v6h6"/><path d="M3 13c0 0 2.03-7 9-7a9 9 0 0 1 9 9 9 9 0 0 1-9 9c-3.5 0-6-1.5-7.5-4"/></svg>
|
|
299
295
|
</ToolbarButton>
|
|
300
|
-
|
|
296
|
+
{:else if tool === 'redo'}
|
|
297
|
+
<ToolbarButton tool="redo" title="Redo" onclick={() => exec('redo')}>
|
|
301
298
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M21 7v6h-6"/><path d="M21 13c0 0-2.03-7-9-7a9 9 0 0 0-9 9 9 9 0 0 0 9 9c3.5 0 6-1.5 7.5-4"/></svg>
|
|
302
299
|
</ToolbarButton>
|
|
300
|
+
{/if}
|
|
301
|
+
{/snippet}
|
|
302
|
+
|
|
303
|
+
<!-- A row of the toolbar: its sections, a divider between two of them. `tail` goes after its
|
|
304
|
+
last group, held to it: a row that wraps has it at the end of its last line, not alone. -->
|
|
305
|
+
{#snippet row(sections: ToolbarTool[][][], tail?: Snippet)}
|
|
306
|
+
{#each sections as section, i}
|
|
307
|
+
{#if i > 0}
|
|
308
|
+
<div class="toolbar-divider"></div>
|
|
309
|
+
{/if}
|
|
310
|
+
{#each section as group, j}
|
|
311
|
+
{#if tail && i === sections.length - 1 && j === section.length - 1}
|
|
312
|
+
<div class="toolbar-tail">
|
|
313
|
+
{@render toolGroup(group)}
|
|
314
|
+
{@render tail()}
|
|
315
|
+
</div>
|
|
316
|
+
{:else}
|
|
317
|
+
{@render toolGroup(group)}
|
|
318
|
+
{/if}
|
|
319
|
+
{/each}
|
|
320
|
+
{/each}
|
|
321
|
+
{#if tail && sections.length === 0}
|
|
322
|
+
{@render tail()}
|
|
323
|
+
{/if}
|
|
324
|
+
{/snippet}
|
|
325
|
+
|
|
326
|
+
{#snippet toolGroup(group: ToolbarTool[])}
|
|
327
|
+
<div class="toolbar-group">
|
|
328
|
+
{#each group as tool (tool)}
|
|
329
|
+
{@render control(tool)}
|
|
330
|
+
{/each}
|
|
303
331
|
</div>
|
|
332
|
+
{/snippet}
|
|
333
|
+
|
|
334
|
+
<!-- The end of the first row where there is a second: the application's own controls, then More. -->
|
|
335
|
+
{#snippet firstRowEnd()}
|
|
336
|
+
{@render end?.()}
|
|
337
|
+
<!-- (One width for both words: what is before it, and the row under it, stay where they are.) -->
|
|
338
|
+
<button
|
|
339
|
+
type="button"
|
|
340
|
+
class="tb-more"
|
|
341
|
+
data-tool-more
|
|
342
|
+
aria-expanded={moreOpen}
|
|
343
|
+
aria-controls={moreId}
|
|
344
|
+
onmousedown={(e) => e.preventDefault()}
|
|
345
|
+
onclick={() => onmoretoggle?.(!moreOpen)}
|
|
346
|
+
>
|
|
347
|
+
<span class:shown={!moreOpen}>{moreLabel}</span>
|
|
348
|
+
<span class:shown={moreOpen}>{lessLabel}</span>
|
|
349
|
+
</button>
|
|
350
|
+
{/snippet}
|
|
351
|
+
|
|
352
|
+
<div class="toolbar" class:two-rows={moreRow.length > 0} role="toolbar" aria-label="Formatting">
|
|
353
|
+
{#if moreRow.length > 0}
|
|
354
|
+
<div class="toolbar-row">
|
|
355
|
+
{@render row(firstRow, firstRowEnd)}
|
|
356
|
+
</div>
|
|
357
|
+
<div class="toolbar-row toolbar-more" id={moreId} hidden={!moreOpen}>
|
|
358
|
+
{@render row(moreRow)}
|
|
359
|
+
</div>
|
|
360
|
+
{:else}
|
|
361
|
+
{@render row(firstRow)}
|
|
362
|
+
{@render end?.()}
|
|
363
|
+
{/if}
|
|
304
364
|
</div>
|
|
305
365
|
|
|
306
366
|
<style>
|
|
@@ -318,6 +378,80 @@
|
|
|
318
378
|
box-shadow: var(--shadow-sm);
|
|
319
379
|
}
|
|
320
380
|
|
|
381
|
+
/* With a More button the toolbar is two rows, one under the other: the second does not
|
|
382
|
+
move the first, and the first wraps on a narrow page with the button at its end. */
|
|
383
|
+
.toolbar.two-rows {
|
|
384
|
+
flex-direction: column;
|
|
385
|
+
align-items: stretch;
|
|
386
|
+
gap: 4px;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.toolbar-row {
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 2px;
|
|
393
|
+
flex-wrap: wrap;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.toolbar-row[hidden] {
|
|
397
|
+
display: none;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.toolbar-more {
|
|
401
|
+
padding-top: 4px;
|
|
402
|
+
border-top: 1px solid var(--border, #e5e2dc);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/* A word, not an icon; one width for both words (the two are laid over one another). */
|
|
406
|
+
.toolbar-tail {
|
|
407
|
+
display: flex;
|
|
408
|
+
align-items: center;
|
|
409
|
+
gap: 2px;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.tb-more {
|
|
413
|
+
display: inline-grid;
|
|
414
|
+
align-items: center;
|
|
415
|
+
justify-items: center;
|
|
416
|
+
height: 32px;
|
|
417
|
+
margin-left: 4px;
|
|
418
|
+
padding: 0 12px;
|
|
419
|
+
border: 1px solid var(--border, #d9d4cc);
|
|
420
|
+
border-radius: 8px;
|
|
421
|
+
background: transparent;
|
|
422
|
+
font-family: 'DM Sans', sans-serif;
|
|
423
|
+
font-size: 13px;
|
|
424
|
+
font-weight: 500;
|
|
425
|
+
color: var(--text-muted);
|
|
426
|
+
cursor: pointer;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
.tb-more > span {
|
|
430
|
+
grid-area: 1 / 1;
|
|
431
|
+
visibility: hidden;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.tb-more > span.shown {
|
|
435
|
+
visibility: visible;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.tb-more:hover {
|
|
439
|
+
background: var(--surface, #f6f4f0);
|
|
440
|
+
border-color: var(--border-active, #b8ab98);
|
|
441
|
+
color: var(--text);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.tb-more[aria-expanded='true'] {
|
|
445
|
+
background: var(--accent-soft, #ede9fe);
|
|
446
|
+
color: var(--text);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.tb-more:focus-visible {
|
|
450
|
+
outline: none;
|
|
451
|
+
border-color: var(--accent, #6e56cf);
|
|
452
|
+
box-shadow: 0 0 0 3px var(--accent-soft, #ede9fe);
|
|
453
|
+
}
|
|
454
|
+
|
|
321
455
|
.toolbar-group {
|
|
322
456
|
display: flex;
|
|
323
457
|
align-items: center;
|