@sveltia/ui 0.15.13 → 0.15.15
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/package/components/button/button.svelte +1 -1
- package/package/components/button/button.svelte.d.ts +4 -4
- package/package/components/button/split-button.svelte +1 -1
- package/package/components/button/split-button.svelte.d.ts +2 -2
- package/package/components/menu/menu-button.svelte +1 -1
- package/package/components/menu/menu-button.svelte.d.ts +2 -2
- package/package/components/select/combobox.svelte +1 -1
- package/package/components/select/combobox.svelte.d.ts +2 -2
- package/package/components/text-editor/core.js +2 -2
- package/package/components/text-editor/index.d.ts +6 -6
- package/package/components/text-editor/index.js +3 -3
- package/package/components/text-editor/lexical-root.svelte +10 -7
- package/package/components/text-editor/text-editor.svelte +27 -12
- package/package/components/text-editor/text-editor.svelte.d.ts +4 -4
- package/package/components/text-editor/toolbar/editor-toolbar.svelte +11 -16
- package/package/components/text-editor/toolbar/format-text-button.svelte +2 -2
- package/package/components/text-editor/toolbar/format-text-button.svelte.d.ts +2 -2
- package/package/components/text-editor/toolbar/insert-link-button.svelte +13 -5
- package/package/components/text-editor/toolbar/toggle-block-menu-item.svelte +2 -2
- package/package/components/text-editor/toolbar/toggle-block-menu-item.svelte.d.ts +2 -2
- package/package/components/toast/toast.svelte +1 -1
- package/package/components/toast/toast.svelte.d.ts +2 -2
- package/package/components/util/popup.svelte +1 -1
- package/package/components/util/popup.svelte.d.ts +4 -4
- package/package/index.d.ts +1 -0
- package/package/index.js +3 -0
- package/package/services/events.js +22 -9
- package/package/services/popup.d.ts +3 -3
- package/package/services/popup.js +7 -3
- package/package/{typedef.d.ts → typedefs.d.ts} +7 -7
- package/package/{typedef.js → typedefs.js} +2 -0
- package/package.json +28 -607
|
@@ -25,7 +25,7 @@ export default class Button extends SvelteComponent<{
|
|
|
25
25
|
iconic?: boolean | undefined;
|
|
26
26
|
pill?: boolean | undefined;
|
|
27
27
|
flex?: boolean | undefined;
|
|
28
|
-
popupPosition?: PopupPosition | undefined;
|
|
28
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
29
29
|
showPopupBackdrop?: boolean | undefined;
|
|
30
30
|
}, {
|
|
31
31
|
mouseenter: MouseEvent;
|
|
@@ -104,8 +104,8 @@ export default class Button extends SvelteComponent<{
|
|
|
104
104
|
set flex(_: boolean | undefined);
|
|
105
105
|
get flex(): boolean | undefined;
|
|
106
106
|
/**accessor*/
|
|
107
|
-
set popupPosition(_: PopupPosition | undefined);
|
|
108
|
-
get popupPosition(): PopupPosition | undefined;
|
|
107
|
+
set popupPosition(_: import("../../typedefs").PopupPosition | undefined);
|
|
108
|
+
get popupPosition(): import("../../typedefs").PopupPosition | undefined;
|
|
109
109
|
/**accessor*/
|
|
110
110
|
set showPopupBackdrop(_: boolean | undefined);
|
|
111
111
|
get showPopupBackdrop(): boolean | undefined;
|
|
@@ -134,7 +134,7 @@ declare const __propDef: {
|
|
|
134
134
|
iconic?: boolean | undefined;
|
|
135
135
|
pill?: boolean | undefined;
|
|
136
136
|
flex?: boolean | undefined;
|
|
137
|
-
popupPosition?: PopupPosition | undefined;
|
|
137
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
138
138
|
showPopupBackdrop?: boolean | undefined;
|
|
139
139
|
};
|
|
140
140
|
events: {
|
|
@@ -15,7 +15,7 @@ export default class SplitButton extends SvelteComponent<{
|
|
|
15
15
|
size?: "small" | "medium" | "large" | undefined;
|
|
16
16
|
hidden?: boolean | undefined;
|
|
17
17
|
variant?: "primary" | "secondary" | "tertiary" | "ghost" | undefined;
|
|
18
|
-
popupPosition?: PopupPosition | undefined;
|
|
18
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
19
19
|
showPopupBackdrop?: boolean | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
click: MouseEvent;
|
|
@@ -46,7 +46,7 @@ declare const __propDef: {
|
|
|
46
46
|
size?: "small" | "medium" | "large" | undefined;
|
|
47
47
|
hidden?: boolean | undefined;
|
|
48
48
|
variant?: "primary" | "secondary" | "tertiary" | "ghost" | undefined;
|
|
49
|
-
popupPosition?: PopupPosition | undefined;
|
|
49
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
50
50
|
showPopupBackdrop?: boolean | undefined;
|
|
51
51
|
};
|
|
52
52
|
events: {
|
|
@@ -15,7 +15,7 @@ export default class MenuButton extends SvelteComponent<{
|
|
|
15
15
|
hidden?: boolean | undefined;
|
|
16
16
|
variant?: "primary" | "secondary" | "tertiary" | "ghost" | "link" | undefined;
|
|
17
17
|
iconic?: boolean | undefined;
|
|
18
|
-
popupPosition?: PopupPosition | undefined;
|
|
18
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
19
19
|
showPopupBackdrop?: boolean | undefined;
|
|
20
20
|
popupPositionBaseElement?: HTMLElement | undefined;
|
|
21
21
|
}, {
|
|
@@ -47,7 +47,7 @@ declare const __propDef: {
|
|
|
47
47
|
hidden?: boolean | undefined;
|
|
48
48
|
variant?: "primary" | "secondary" | "tertiary" | "ghost" | "link" | undefined;
|
|
49
49
|
iconic?: boolean | undefined;
|
|
50
|
-
popupPosition?: PopupPosition | undefined;
|
|
50
|
+
popupPosition?: import("../../typedefs").PopupPosition | undefined;
|
|
51
51
|
showPopupBackdrop?: boolean | undefined;
|
|
52
52
|
popupPositionBaseElement?: HTMLElement | undefined;
|
|
53
53
|
};
|
|
@@ -14,7 +14,7 @@ export default class Combobox extends SvelteComponent<{
|
|
|
14
14
|
invalid?: boolean | undefined;
|
|
15
15
|
required?: boolean | undefined;
|
|
16
16
|
value?: (string | number | undefined);
|
|
17
|
-
position?: PopupPosition | undefined;
|
|
17
|
+
position?: import("../../typedefs").PopupPosition | undefined;
|
|
18
18
|
hidden?: boolean | undefined;
|
|
19
19
|
readonly?: boolean | undefined;
|
|
20
20
|
editable?: boolean | undefined;
|
|
@@ -41,7 +41,7 @@ declare const __propDef: {
|
|
|
41
41
|
invalid?: boolean | undefined;
|
|
42
42
|
required?: boolean | undefined;
|
|
43
43
|
value?: (string | number | undefined);
|
|
44
|
-
position?: PopupPosition | undefined;
|
|
44
|
+
position?: import("../../typedefs").PopupPosition | undefined;
|
|
45
45
|
hidden?: boolean | undefined;
|
|
46
46
|
readonly?: boolean | undefined;
|
|
47
47
|
editable?: boolean | undefined;
|
|
@@ -91,7 +91,7 @@ const onEditorUpdate = (editor) => {
|
|
|
91
91
|
const anchor = selection.anchor.getNode();
|
|
92
92
|
/** @type {ElementNode | null} */
|
|
93
93
|
let parent = null;
|
|
94
|
-
/** @type {TextEditorInlineType[]} */
|
|
94
|
+
/** @type {import('../../typedefs').TextEditorInlineType[]} */
|
|
95
95
|
const selectionInlineTypes = textFormatButtonTypes.filter((type) => selection.hasFormat(type));
|
|
96
96
|
|
|
97
97
|
if (anchor.getType() !== 'root') {
|
|
@@ -107,7 +107,7 @@ const onEditorUpdate = (editor) => {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const selectionBlockType = /** @type {TextEditorBlockType} */ (
|
|
110
|
+
const selectionBlockType = /** @type {import('../../typedefs').TextEditorBlockType} */ (
|
|
111
111
|
(() => {
|
|
112
112
|
if (!parent) {
|
|
113
113
|
return 'paragraph';
|
|
@@ -10,14 +10,14 @@ export const availableButtons: {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* @type {TextEditorFormatType[]}
|
|
13
|
+
* @type {import('../../typedefs').TextEditorFormatType[]}
|
|
14
14
|
*/
|
|
15
|
-
export const textFormatButtonTypes: TextEditorFormatType[];
|
|
15
|
+
export const textFormatButtonTypes: import("../../typedefs").TextEditorFormatType[];
|
|
16
16
|
/**
|
|
17
|
-
* @type {TextEditorInlineType[]}
|
|
17
|
+
* @type {import('../../typedefs').TextEditorInlineType[]}
|
|
18
18
|
*/
|
|
19
|
-
export const inlineButtonTypes: TextEditorInlineType[];
|
|
19
|
+
export const inlineButtonTypes: import("../../typedefs").TextEditorInlineType[];
|
|
20
20
|
/**
|
|
21
|
-
* @type {TextEditorBlockType[]}
|
|
21
|
+
* @type {import('../../typedefs').TextEditorBlockType[]}
|
|
22
22
|
*/
|
|
23
|
-
export const blockButtonTypes: TextEditorBlockType[];
|
|
23
|
+
export const blockButtonTypes: import("../../typedefs").TextEditorBlockType[];
|
|
@@ -75,15 +75,15 @@ export const availableButtons = {
|
|
|
75
75
|
},
|
|
76
76
|
};
|
|
77
77
|
/**
|
|
78
|
-
* @type {TextEditorFormatType[]}
|
|
78
|
+
* @type {import('../../typedefs').TextEditorFormatType[]}
|
|
79
79
|
*/
|
|
80
80
|
export const textFormatButtonTypes = ['bold', 'italic', 'code'];
|
|
81
81
|
/**
|
|
82
|
-
* @type {TextEditorInlineType[]}
|
|
82
|
+
* @type {import('../../typedefs').TextEditorInlineType[]}
|
|
83
83
|
*/
|
|
84
84
|
export const inlineButtonTypes = [...textFormatButtonTypes, 'link'];
|
|
85
85
|
/**
|
|
86
|
-
* @type {TextEditorBlockType[]}
|
|
86
|
+
* @type {import('../../typedefs').TextEditorBlockType[]}
|
|
87
87
|
*/
|
|
88
88
|
export const blockButtonTypes = [
|
|
89
89
|
'paragraph',
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Text editor state.
|
|
37
|
-
* @type {TextEditorState}
|
|
37
|
+
* @type {import('../../typedefs').TextEditorState}
|
|
38
38
|
*/
|
|
39
39
|
const { editor, editorId, selectionBlockType, selectionInlineTypes, hasConverterError } =
|
|
40
40
|
getContext('state');
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
let lexicalRoot = undefined;
|
|
47
47
|
|
|
48
48
|
$: editable = !(disabled || readonly);
|
|
49
|
-
$: $editor
|
|
49
|
+
$: $editor?.setEditable(editable);
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Update {@link value} and other state variables whenever the editor content is updated.
|
|
@@ -79,17 +79,20 @@
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
onMount(() => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
lexicalRoot.addEventListener('Update', onUpdate);
|
|
85
|
-
lexicalRoot.addEventListener('click', onClick);
|
|
86
|
-
}
|
|
82
|
+
lexicalRoot?.addEventListener('Update', onUpdate);
|
|
83
|
+
lexicalRoot?.addEventListener('click', onClick);
|
|
87
84
|
|
|
88
85
|
return () => {
|
|
89
86
|
lexicalRoot?.removeEventListener('Update', onUpdate);
|
|
90
87
|
lexicalRoot?.removeEventListener('click', onClick);
|
|
91
88
|
};
|
|
92
89
|
});
|
|
90
|
+
|
|
91
|
+
$: {
|
|
92
|
+
if ($editor && lexicalRoot) {
|
|
93
|
+
$editor.setRootElement(lexicalRoot);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
93
96
|
</script>
|
|
94
97
|
|
|
95
98
|
<div
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
-->
|
|
5
5
|
<script>
|
|
6
6
|
import { generateElementId } from '@sveltia/utils/element';
|
|
7
|
-
import { setContext } from 'svelte';
|
|
7
|
+
import { onMount, setContext } from 'svelte';
|
|
8
8
|
import { _ } from 'svelte-i18n';
|
|
9
9
|
import { writable } from 'svelte/store';
|
|
10
|
-
import Alert from '../alert/alert.svelte';
|
|
11
10
|
import { blockButtonTypes, inlineButtonTypes } from '.';
|
|
11
|
+
import Alert from '../alert/alert.svelte';
|
|
12
|
+
import TextArea from '../text-field/text-area.svelte';
|
|
13
|
+
import Toast from '../toast/toast.svelte';
|
|
12
14
|
import { convertMarkdown as convertMarkdownToLexical, initEditor } from './core';
|
|
13
15
|
import LexicalRoot from './lexical-root.svelte';
|
|
14
16
|
import EditorToolbar from './toolbar/editor-toolbar.svelte';
|
|
15
|
-
import TextArea from '../text-field/text-area.svelte';
|
|
16
|
-
import Toast from '../toast/toast.svelte';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Make the text input container flexible.
|
|
@@ -52,16 +52,18 @@
|
|
|
52
52
|
export let value = undefined;
|
|
53
53
|
/**
|
|
54
54
|
* Enabled modes.
|
|
55
|
-
* @type {TextEditorMode[]}
|
|
55
|
+
* @type {import('../../typedefs').TextEditorMode[]}
|
|
56
56
|
*/
|
|
57
57
|
export let modes = ['rich-text', 'plain-text'];
|
|
58
58
|
/**
|
|
59
59
|
* Enabled buttons.
|
|
60
|
-
* @type {(TextEditorBlockType |
|
|
60
|
+
* @type {(import('../../typedefs').TextEditorBlockType |
|
|
61
|
+
* import('../../typedefs').TextEditorInlineType)[]}
|
|
61
62
|
*/
|
|
62
63
|
export let buttons = [...inlineButtonTypes, ...blockButtonTypes];
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
/** @type {import('svelte/store').Writable<import('lexical').LexicalEditor | undefined>} */
|
|
66
|
+
const editor = writable();
|
|
65
67
|
const selectionBlockType = writable('paragraph');
|
|
66
68
|
const selectionInlineTypes = writable([]);
|
|
67
69
|
const editorId = writable(generateElementId('editor'));
|
|
@@ -75,6 +77,10 @@
|
|
|
75
77
|
* restore the original value when there is an error while conversion.
|
|
76
78
|
*/
|
|
77
79
|
const convertMarkdown = async () => {
|
|
80
|
+
if (!$editor) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
78
84
|
const originalValue = inputValue;
|
|
79
85
|
|
|
80
86
|
try {
|
|
@@ -117,13 +123,17 @@
|
|
|
117
123
|
};
|
|
118
124
|
|
|
119
125
|
$: {
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
if ($editor) {
|
|
127
|
+
void value;
|
|
128
|
+
setInputValue();
|
|
129
|
+
}
|
|
122
130
|
}
|
|
123
131
|
|
|
124
132
|
$: {
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
if ($editor) {
|
|
134
|
+
void inputValue;
|
|
135
|
+
setCurrentValue();
|
|
136
|
+
}
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
$: {
|
|
@@ -133,9 +143,14 @@
|
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
|
|
146
|
+
// The editor has to be initialized in the browser
|
|
147
|
+
onMount(() => {
|
|
148
|
+
$editor = initEditor();
|
|
149
|
+
});
|
|
150
|
+
|
|
136
151
|
setContext(
|
|
137
152
|
'state',
|
|
138
|
-
/** @type {TextEditorState} */ ({
|
|
153
|
+
/** @type {import('../../typedefs').TextEditorState} */ ({
|
|
139
154
|
editor,
|
|
140
155
|
editorId,
|
|
141
156
|
selectionBlockType,
|
|
@@ -11,8 +11,8 @@ export default class TextEditor extends SvelteComponent<{
|
|
|
11
11
|
hidden?: boolean | undefined;
|
|
12
12
|
readonly?: boolean | undefined;
|
|
13
13
|
flex?: boolean | undefined;
|
|
14
|
-
modes?: TextEditorMode[] | undefined;
|
|
15
|
-
buttons?: (
|
|
14
|
+
modes?: import("../../typedefs").TextEditorMode[] | undefined;
|
|
15
|
+
buttons?: (import("../../typedefs").TextEditorBlockType | import("../../typedefs").TextEditorInlineType)[] | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
[evt: string]: CustomEvent<any>;
|
|
18
18
|
}, {}> {
|
|
@@ -31,8 +31,8 @@ declare const __propDef: {
|
|
|
31
31
|
hidden?: boolean | undefined;
|
|
32
32
|
readonly?: boolean | undefined;
|
|
33
33
|
flex?: boolean | undefined;
|
|
34
|
-
modes?: TextEditorMode[] | undefined;
|
|
35
|
-
buttons?: (
|
|
34
|
+
modes?: import("../../typedefs").TextEditorMode[] | undefined;
|
|
35
|
+
buttons?: (import("../../typedefs").TextEditorBlockType | import("../../typedefs").TextEditorInlineType)[] | undefined;
|
|
36
36
|
};
|
|
37
37
|
events: {
|
|
38
38
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { unique } from '@sveltia/utils/array';
|
|
2
3
|
import { getContext } from 'svelte';
|
|
3
4
|
import { _ } from 'svelte-i18n';
|
|
4
5
|
import { availableButtons, blockButtonTypes, inlineButtonTypes } from '..';
|
|
@@ -9,10 +10,10 @@
|
|
|
9
10
|
import Icon from '../../icon/icon.svelte';
|
|
10
11
|
import MenuButton from '../../menu/menu-button.svelte';
|
|
11
12
|
import Menu from '../../menu/menu.svelte';
|
|
13
|
+
import Toolbar from '../../toolbar/toolbar.svelte';
|
|
12
14
|
import FormatTextButton from './format-text-button.svelte';
|
|
13
15
|
import InsertLinkButton from './insert-link-button.svelte';
|
|
14
16
|
import ToggleBlockMenuItem from './toggle-block-menu-item.svelte';
|
|
15
|
-
import Toolbar from '../../toolbar/toolbar.svelte';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Whether to disable the widget. An alias of the `aria-disabled` attribute.
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Text editor state.
|
|
30
|
-
* @type {TextEditorState}
|
|
31
|
+
* @type {import('../../../typedefs').TextEditorState}
|
|
31
32
|
*/
|
|
32
33
|
const {
|
|
33
34
|
editorId,
|
|
@@ -41,25 +42,19 @@
|
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Enabled block level buttons.
|
|
45
|
+
* @type {import('../../../typedefs').TextEditorBlockType[]}
|
|
44
46
|
*/
|
|
45
|
-
$: blockLevelButtons =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
...enabledButtons.filter((type) => blockButtonTypes.includes(/** @type {any} */ (type))),
|
|
50
|
-
]),
|
|
51
|
-
),
|
|
52
|
-
);
|
|
47
|
+
$: blockLevelButtons = unique([
|
|
48
|
+
'paragraph', // Always needed
|
|
49
|
+
...enabledButtons.filter((type) => blockButtonTypes.includes(/** @type {any} */ (type))),
|
|
50
|
+
]);
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Enabled inline level buttons.
|
|
54
|
+
* @type {import('../../../typedefs').TextEditorInlineType[]}
|
|
56
55
|
*/
|
|
57
|
-
$: inlineLevelButtons =
|
|
58
|
-
|
|
59
|
-
/** @type {TextEditorInlineType[]} */ ([
|
|
60
|
-
...enabledButtons.filter((type) => inlineButtonTypes.includes(/** @type {any} */ (type))),
|
|
61
|
-
]),
|
|
62
|
-
),
|
|
56
|
+
$: inlineLevelButtons = unique(
|
|
57
|
+
enabledButtons.filter((type) => inlineButtonTypes.includes(/** @type {any} */ (type))),
|
|
63
58
|
);
|
|
64
59
|
</script>
|
|
65
60
|
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Button type.
|
|
11
|
-
* @type {TextEditorFormatType}
|
|
11
|
+
* @type {import('../../../typedefs').TextEditorFormatType}
|
|
12
12
|
*/
|
|
13
13
|
export let type;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Text editor state.
|
|
17
|
-
* @type {TextEditorState}
|
|
17
|
+
* @type {import('../../../typedefs').TextEditorState}
|
|
18
18
|
*/
|
|
19
19
|
const { editor, editorId, selectionInlineTypes, useRichText } = getContext('state');
|
|
20
20
|
</script>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} FormatTextButtonEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} FormatTextButtonSlots */
|
|
4
4
|
export default class FormatTextButton extends SvelteComponent<{
|
|
5
|
-
type: TextEditorFormatType;
|
|
5
|
+
type: import("../../../typedefs").TextEditorFormatType;
|
|
6
6
|
}, {
|
|
7
7
|
[evt: string]: CustomEvent<any>;
|
|
8
8
|
}, {}> {
|
|
@@ -13,7 +13,7 @@ export type FormatTextButtonSlots = typeof __propDef.slots;
|
|
|
13
13
|
import { SvelteComponent } from "svelte";
|
|
14
14
|
declare const __propDef: {
|
|
15
15
|
props: {
|
|
16
|
-
type: TextEditorFormatType;
|
|
16
|
+
type: import("../../../typedefs").TextEditorFormatType;
|
|
17
17
|
};
|
|
18
18
|
events: {
|
|
19
19
|
[evt: string]: CustomEvent<any>;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
$getTextContent as getTextContent,
|
|
12
12
|
$isRangeSelection as isRangeSelection,
|
|
13
13
|
} from 'lexical';
|
|
14
|
-
import { getContext
|
|
14
|
+
import { getContext } from 'svelte';
|
|
15
15
|
import { _ } from 'svelte-i18n';
|
|
16
16
|
import { availableButtons } from '..';
|
|
17
17
|
import { isMac, matchShortcuts } from '../../../services/events';
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Text editor state.
|
|
32
|
-
* @type {TextEditorState}
|
|
32
|
+
* @type {import('../../../typedefs').TextEditorState}
|
|
33
33
|
*/
|
|
34
34
|
const { editor, editorId, selectionInlineTypes, useRichText } = getContext('state');
|
|
35
35
|
|
|
@@ -145,8 +145,10 @@
|
|
|
145
145
|
anchorText = '';
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Open the dialog with a keyboard shortcut: Accel+K.
|
|
150
|
+
*/
|
|
151
|
+
const _registerCommand = () => {
|
|
150
152
|
$editor.registerCommand(
|
|
151
153
|
KEY_DOWN_COMMAND,
|
|
152
154
|
(event) => {
|
|
@@ -159,7 +161,13 @@
|
|
|
159
161
|
},
|
|
160
162
|
COMMAND_PRIORITY_NORMAL,
|
|
161
163
|
);
|
|
162
|
-
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
$: {
|
|
167
|
+
if ($editor) {
|
|
168
|
+
_registerCommand();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
163
171
|
</script>
|
|
164
172
|
|
|
165
173
|
<Button
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Button type.
|
|
19
|
-
* @type {TextEditorBlockType}
|
|
19
|
+
* @type {import('../../../typedefs').TextEditorBlockType}
|
|
20
20
|
*/
|
|
21
21
|
export let type;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Text editor state.
|
|
25
|
-
* @type {TextEditorState}
|
|
25
|
+
* @type {import('../../../typedefs').TextEditorState}
|
|
26
26
|
*/
|
|
27
27
|
const { editor, selectionBlockType } = getContext('state');
|
|
28
28
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} ToggleBlockMenuItemEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} ToggleBlockMenuItemSlots */
|
|
4
4
|
export default class ToggleBlockMenuItem extends SvelteComponent<{
|
|
5
|
-
type: TextEditorBlockType;
|
|
5
|
+
type: import("../../../typedefs").TextEditorBlockType;
|
|
6
6
|
}, {
|
|
7
7
|
[evt: string]: CustomEvent<any>;
|
|
8
8
|
}, {}> {
|
|
@@ -13,7 +13,7 @@ export type ToggleBlockMenuItemSlots = typeof __propDef.slots;
|
|
|
13
13
|
import { SvelteComponent } from "svelte";
|
|
14
14
|
declare const __propDef: {
|
|
15
15
|
props: {
|
|
16
|
-
type: TextEditorBlockType;
|
|
16
|
+
type: import("../../../typedefs").TextEditorBlockType;
|
|
17
17
|
};
|
|
18
18
|
events: {
|
|
19
19
|
[evt: string]: CustomEvent<any>;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export default class Toast extends SvelteComponent<{
|
|
10
10
|
[x: string]: any;
|
|
11
11
|
id?: number | undefined;
|
|
12
|
-
position?: ToastPosition | undefined;
|
|
12
|
+
position?: import("../../typedefs").ToastPosition | undefined;
|
|
13
13
|
show?: boolean | undefined;
|
|
14
14
|
duration?: number | undefined;
|
|
15
15
|
}, {
|
|
@@ -26,7 +26,7 @@ declare const __propDef: {
|
|
|
26
26
|
props: {
|
|
27
27
|
[x: string]: any;
|
|
28
28
|
id?: number | undefined;
|
|
29
|
-
position?: ToastPosition | undefined;
|
|
29
|
+
position?: import("../../typedefs").ToastPosition | undefined;
|
|
30
30
|
show?: boolean | undefined;
|
|
31
31
|
duration?: number | undefined;
|
|
32
32
|
};
|
|
@@ -6,7 +6,7 @@ export default class Popup extends SvelteComponent<{
|
|
|
6
6
|
[x: string]: any;
|
|
7
7
|
anchor: HTMLElement | undefined;
|
|
8
8
|
class?: string | undefined;
|
|
9
|
-
position?: PopupPosition | undefined;
|
|
9
|
+
position?: import("../../typedefs").PopupPosition | undefined;
|
|
10
10
|
open?: import("svelte/store").Writable<boolean> | undefined;
|
|
11
11
|
showBackdrop?: boolean | undefined;
|
|
12
12
|
content?: HTMLElement | undefined;
|
|
@@ -43,8 +43,8 @@ export default class Popup extends SvelteComponent<{
|
|
|
43
43
|
set content(_: HTMLElement | undefined);
|
|
44
44
|
get content(): HTMLElement | undefined;
|
|
45
45
|
/**accessor*/
|
|
46
|
-
set position(_: PopupPosition | undefined);
|
|
47
|
-
get position(): PopupPosition | undefined;
|
|
46
|
+
set position(_: import("../../typedefs").PopupPosition | undefined);
|
|
47
|
+
get position(): import("../../typedefs").PopupPosition | undefined;
|
|
48
48
|
/**accessor*/
|
|
49
49
|
set positionBaseElement(_: HTMLElement | undefined);
|
|
50
50
|
get positionBaseElement(): HTMLElement | undefined;
|
|
@@ -61,7 +61,7 @@ declare const __propDef: {
|
|
|
61
61
|
[x: string]: any;
|
|
62
62
|
anchor: HTMLElement | undefined;
|
|
63
63
|
class?: string | undefined;
|
|
64
|
-
position?: PopupPosition | undefined;
|
|
64
|
+
position?: import("../../typedefs").PopupPosition | undefined;
|
|
65
65
|
open?: import("svelte/store").Writable<boolean> | undefined;
|
|
66
66
|
showBackdrop?: boolean | undefined;
|
|
67
67
|
content?: HTMLElement | undefined;
|
package/package/index.d.ts
CHANGED
|
@@ -68,3 +68,4 @@ export { default as Toolbar } from "./components/toolbar/toolbar.svelte";
|
|
|
68
68
|
export { default as AppShell } from "./components/util/app-shell.svelte";
|
|
69
69
|
export { default as Group } from "./components/util/group.svelte";
|
|
70
70
|
export { default as Modal } from "./components/util/modal.svelte";
|
|
71
|
+
export * from "./typedefs";
|
package/package/index.js
CHANGED
|
@@ -93,3 +93,6 @@ export { default as Toolbar } from './components/toolbar/toolbar.svelte';
|
|
|
93
93
|
export { default as AppShell } from './components/util/app-shell.svelte';
|
|
94
94
|
export { default as Group } from './components/util/group.svelte';
|
|
95
95
|
export { default as Modal } from './components/util/modal.svelte';
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line import/export
|
|
98
|
+
export * from './typedefs';
|
|
@@ -66,16 +66,29 @@ export const activateKeyShortcuts = (element, shortcuts = '') => {
|
|
|
66
66
|
const { disabled, offsetParent } = element;
|
|
67
67
|
const { top, left } = element.getBoundingClientRect();
|
|
68
68
|
|
|
69
|
-
// Check if the element is
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
// Check if the element is visible
|
|
70
|
+
if (!matchShortcuts(event, /** @type {string} */ (platformKeyShortcuts)) || !offsetParent) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (disabled) {
|
|
75
|
+
// Make sure `elementsFromPoint()` works as expected
|
|
76
|
+
element.style.setProperty('pointer-events', 'auto');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Check if the element is clickable (not behind a modal dialog)
|
|
80
|
+
if (document.elementsFromPoint(left + 4, top + 4).includes(element)) {
|
|
76
81
|
event.preventDefault();
|
|
77
|
-
|
|
78
|
-
element
|
|
82
|
+
|
|
83
|
+
// Trigger click only when the element is enabled
|
|
84
|
+
if (!disabled) {
|
|
85
|
+
element.focus();
|
|
86
|
+
element.click();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (disabled) {
|
|
91
|
+
element.style.removeProperty('pointer-events');
|
|
79
92
|
}
|
|
80
93
|
};
|
|
81
94
|
|