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,5 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type ToolbarTool } from '../toolbar-tools.js';
|
|
1
3
|
interface Props {
|
|
2
4
|
formatState?: Record<string, boolean>;
|
|
3
5
|
blockType?: string;
|
|
@@ -36,6 +38,17 @@ interface Props {
|
|
|
36
38
|
/** The Copy format brush is in hand: the button shows as pressed. */
|
|
37
39
|
copyingFormat?: boolean;
|
|
38
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;
|
|
39
52
|
}
|
|
40
53
|
declare const Toolbar: import("svelte").Component<Props, {}, "">;
|
|
41
54
|
type Toolbar = ReturnType<typeof Toolbar>;
|
|
@@ -8,15 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
active?: boolean;
|
|
10
10
|
title?: string;
|
|
11
|
+
/** The control's name (see toolbar-tools.ts), as `data-tool`. */
|
|
12
|
+
tool?: string;
|
|
11
13
|
onclick?: () => void;
|
|
12
14
|
children: Snippet;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
let { active, title = '', onclick, children }: Props = $props();
|
|
17
|
+
let { active, title = '', tool, onclick, children }: Props = $props();
|
|
16
18
|
</script>
|
|
17
19
|
|
|
18
20
|
<button
|
|
19
21
|
class="tb"
|
|
22
|
+
data-tool={tool}
|
|
20
23
|
class:active={active === true}
|
|
21
24
|
{title}
|
|
22
25
|
aria-label={title || undefined}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as RtfViewer } from './RtfViewer.svelte';
|
|
2
2
|
export { default as InkEditor } from './components/InkEditor.svelte';
|
|
3
|
+
export { TOOLBAR_TOOLS, type ToolbarTool } from './toolbar-tools.js';
|
|
3
4
|
export { rtfToHtml, readRtfFile, DEFAULT_MAX_RTF_BYTES } from './rtf-parser.js';
|
|
4
5
|
export { htmlToRtf, estimateRtfBytes, isSafeLinkUrl, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from './rtf-writer.js';
|
|
5
6
|
export type { RtfWriteOptions } from './rtf-writer.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Svelte components
|
|
2
2
|
export { default as RtfViewer } from './RtfViewer.svelte';
|
|
3
3
|
export { default as InkEditor } from './components/InkEditor.svelte';
|
|
4
|
+
export { TOOLBAR_TOOLS } from './toolbar-tools.js';
|
|
4
5
|
// RTF utilities
|
|
5
6
|
export { rtfToHtml, readRtfFile, DEFAULT_MAX_RTF_BYTES } from './rtf-parser.js';
|
|
6
7
|
export { htmlToRtf, estimateRtfBytes, isSafeLinkUrl, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from './rtf-writer.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The toolbar's controls, by names that are part of the public API: an application chooses
|
|
3
|
+
* which the toolbar has (`tools`) and which wait behind its More button (`moreTools`) by these,
|
|
4
|
+
* and each control carries its name as `data-tool`. A name does not change when a control's
|
|
5
|
+
* tooltip does. A control added in a later version gets a name of its own, and the release
|
|
6
|
+
* notes say so.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The toolbar's layout: sections, set apart by dividers, of groups, of controls. A row of the
|
|
10
|
+
* toolbar shows each section that has a control in it, and a divider only between two of them.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TOOLBAR_SECTIONS: readonly [readonly [readonly ["block"], readonly ["font"], readonly ["fontSize"]], readonly [readonly ["bold", "italic", "underline", "strikethrough"]], readonly [readonly ["textColor", "clearFormatting"]], readonly [readonly ["bulletList", "numberedList"]], readonly [readonly ["alignLeft", "alignCenter", "alignRight"]], readonly [readonly ["outdent", "indent", "hangingOutdent", "hangingIndent", "hangAtCaret", "rightOutdent", "rightIndent"]], readonly [readonly ["spacing"]], readonly [readonly ["copyFormat"]], readonly [readonly ["link", "image", "table", "horizontalRule"]], readonly [readonly ["undo", "redo"]]];
|
|
13
|
+
/** The name of one of the toolbar's controls. */
|
|
14
|
+
export type ToolbarTool = (typeof TOOLBAR_SECTIONS)[number][number][number];
|
|
15
|
+
/** Every control of the toolbar, by name, in the toolbar's own order. */
|
|
16
|
+
export declare const TOOLBAR_TOOLS: readonly ToolbarTool[];
|
|
17
|
+
/**
|
|
18
|
+
* The known controls of a list an application gave, in the toolbar's own order. A name that
|
|
19
|
+
* is no control is left out, with a warning in the console (once for each name).
|
|
20
|
+
*/
|
|
21
|
+
export declare function knownTools(given: readonly string[] | null | undefined, prop: string): Set<ToolbarTool>;
|
|
22
|
+
/**
|
|
23
|
+
* The sections of one row of the toolbar: those of its layout that keep a control, with the
|
|
24
|
+
* groups that keep one, with the controls `shown` has.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toolbarRow(shown: (tool: ToolbarTool) => boolean): ToolbarTool[][][];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The toolbar's controls, by names that are part of the public API: an application chooses
|
|
3
|
+
* which the toolbar has (`tools`) and which wait behind its More button (`moreTools`) by these,
|
|
4
|
+
* and each control carries its name as `data-tool`. A name does not change when a control's
|
|
5
|
+
* tooltip does. A control added in a later version gets a name of its own, and the release
|
|
6
|
+
* notes say so.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The toolbar's layout: sections, set apart by dividers, of groups, of controls. A row of the
|
|
10
|
+
* toolbar shows each section that has a control in it, and a divider only between two of them.
|
|
11
|
+
*/
|
|
12
|
+
export const TOOLBAR_SECTIONS = [
|
|
13
|
+
[['block'], ['font'], ['fontSize']],
|
|
14
|
+
[['bold', 'italic', 'underline', 'strikethrough']],
|
|
15
|
+
[['textColor', 'clearFormatting']],
|
|
16
|
+
[['bulletList', 'numberedList']],
|
|
17
|
+
[['alignLeft', 'alignCenter', 'alignRight']],
|
|
18
|
+
[['outdent', 'indent', 'hangingOutdent', 'hangingIndent', 'hangAtCaret', 'rightOutdent', 'rightIndent']],
|
|
19
|
+
[['spacing']],
|
|
20
|
+
[['copyFormat']],
|
|
21
|
+
[['link', 'image', 'table', 'horizontalRule']],
|
|
22
|
+
[['undo', 'redo']]
|
|
23
|
+
];
|
|
24
|
+
/** Every control of the toolbar, by name, in the toolbar's own order. */
|
|
25
|
+
export const TOOLBAR_TOOLS = Object.freeze(TOOLBAR_SECTIONS.flat(2));
|
|
26
|
+
const KNOWN = new Set(TOOLBAR_TOOLS);
|
|
27
|
+
const warned = new Set();
|
|
28
|
+
/**
|
|
29
|
+
* The known controls of a list an application gave, in the toolbar's own order. A name that
|
|
30
|
+
* is no control is left out, with a warning in the console (once for each name).
|
|
31
|
+
*/
|
|
32
|
+
export function knownTools(given, prop) {
|
|
33
|
+
const tools = new Set();
|
|
34
|
+
for (const name of Array.isArray(given) ? given : []) {
|
|
35
|
+
if (KNOWN.has(name))
|
|
36
|
+
tools.add(name);
|
|
37
|
+
else if (!warned.has(`${prop}:${name}`)) {
|
|
38
|
+
warned.add(`${prop}:${name}`);
|
|
39
|
+
console.warn(`svelte-rtf-editor: \`${prop}\` names "${name}", which is no toolbar control. Known: ${TOOLBAR_TOOLS.join(', ')}.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return tools;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The sections of one row of the toolbar: those of its layout that keep a control, with the
|
|
46
|
+
* groups that keep one, with the controls `shown` has.
|
|
47
|
+
*/
|
|
48
|
+
export function toolbarRow(shown) {
|
|
49
|
+
return TOOLBAR_SECTIONS.map((section) => section.map((group) => group.filter(shown)).filter((group) => group.length > 0)).filter((section) => section.length > 0);
|
|
50
|
+
}
|
package/package.json
CHANGED