@streamscloud/kit 1.0.0 → 1.0.2
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 +1 -2
- package/dist/ui/dialog/cmp.dialog-frame.svelte +2 -2
- package/dist/ui/dialog/cmp.dialog.svelte +1 -0
- package/dist/ui/html-block/cmp.html-block.svelte +9 -0
- package/dist/ui/html-block/cmp.html-block.svelte.d.ts +1 -0
- package/dist/ui/rich-text-input/cmp.rich-text-input.svelte +7 -4
- package/dist/ui/rich-text-input/cmp.rich-text-input.svelte.d.ts +3 -3
- package/dist/ui/rich-text-input/index.d.ts +1 -1
- package/dist/ui/rich-text-input/rich-text-input-localization.d.ts +0 -3
- package/dist/ui/rich-text-input/rich-text-input-localization.js +0 -12
- package/dist/ui/rich-text-input/types.d.ts +6 -0
- package/dist/ui/rich-text-input/validated-link-button.d.ts +2 -1
- package/dist/ui/rich-text-input/validated-link-button.js +93 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,8 +24,7 @@ npm run lint:fix # eslint --fix + prettier --write
|
|
|
24
24
|
|
|
25
25
|
## Release
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
`npm publish`. The full workflow is in `.claude/CLAUDE.md`.
|
|
27
|
+
Through the `/sc:ship` skill.
|
|
29
28
|
|
|
30
29
|
## Context
|
|
31
30
|
|
|
@@ -136,9 +136,9 @@ It stacks with `Dialogs.open()` dialogs: only the topmost one reacts to Esc and
|
|
|
136
136
|
border: none;
|
|
137
137
|
background: transparent;
|
|
138
138
|
max-width: 100vw;
|
|
139
|
-
max-height:
|
|
139
|
+
max-height: 100dvh;
|
|
140
140
|
width: 100vw;
|
|
141
|
-
height:
|
|
141
|
+
height: 100dvh;
|
|
142
142
|
overflow-x: hidden;
|
|
143
143
|
overflow-y: auto;
|
|
144
144
|
display: flex;
|
|
@@ -19,12 +19,17 @@ not scrolled horizontally.
|
|
|
19
19
|
| `--sc-kit--html-block--font-size` | Base font size | `0.875em` |
|
|
20
20
|
| `--sc-kit--html-block--text-color` | Body text color | `--sc-kit--color--text--primary` |
|
|
21
21
|
| `--sc-kit--html-block--link-color` | Anchor color | `--sc-kit--color--accent` |
|
|
22
|
+
| `--sc-kit--html-block--link-color--disabled` | Color of an anchor with `aria-disabled="true"` | `--sc-kit--html-block--link-color` |
|
|
22
23
|
| `--sc-kit--html-block--code-font` | Monospace font for `pre` and `code` | `--sc-kit--font--mono` |
|
|
23
24
|
-->
|
|
24
25
|
|
|
25
26
|
<style>.html-block {
|
|
26
27
|
--_html-block--text: var(--sc-kit--html-block--text-color, var(--sc-kit--color--text--primary));
|
|
27
28
|
--_html-block--link: var(--sc-kit--html-block--link-color, var(--sc-kit--color--accent));
|
|
29
|
+
--_html-block--link-disabled: var(
|
|
30
|
+
--sc-kit--html-block--link-color--disabled,
|
|
31
|
+
var(--_html-block--link)
|
|
32
|
+
);
|
|
28
33
|
--_html-block--code-font: var(--sc-kit--html-block--code-font, var(--sc-kit--font--mono));
|
|
29
34
|
--_html-block--font-size: var(--sc-kit--html-block--font-size, 0.875em);
|
|
30
35
|
display: block;
|
|
@@ -101,6 +106,10 @@ not scrolled horizontally.
|
|
|
101
106
|
.html-block :global(a) {
|
|
102
107
|
color: var(--_html-block--link);
|
|
103
108
|
}
|
|
109
|
+
.html-block :global(a[aria-disabled='true']) {
|
|
110
|
+
color: var(--_html-block--link-disabled);
|
|
111
|
+
cursor: default;
|
|
112
|
+
}
|
|
104
113
|
.html-block :global(ul),
|
|
105
114
|
.html-block :global(ol) {
|
|
106
115
|
padding-left: 1.5em;
|
|
@@ -14,6 +14,7 @@ type Props = {
|
|
|
14
14
|
* | `--sc-kit--html-block--font-size` | Base font size | `0.875em` |
|
|
15
15
|
* | `--sc-kit--html-block--text-color` | Body text color | `--sc-kit--color--text--primary` |
|
|
16
16
|
* | `--sc-kit--html-block--link-color` | Anchor color | `--sc-kit--color--accent` |
|
|
17
|
+
* | `--sc-kit--html-block--link-color--disabled` | Color of an anchor with `aria-disabled="true"` | `--sc-kit--html-block--link-color` |
|
|
17
18
|
* | `--sc-kit--html-block--code-font` | Monospace font for `pre` and `code` | `--sc-kit--font--mono` |
|
|
18
19
|
*/
|
|
19
20
|
declare const Cmp: import("svelte").Component<Props, {}, "">;
|
|
@@ -4,7 +4,7 @@ import { getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-fiel
|
|
|
4
4
|
import { InputEmojiPicker } from '../_internal/input-emoji-picker';
|
|
5
5
|
import { HtmlBlock } from '../html-block';
|
|
6
6
|
import { RichTextInputLocalization } from './rich-text-input-localization';
|
|
7
|
-
import {
|
|
7
|
+
import { LINK_TARGET, registerValidatedLink } from './validated-link-button';
|
|
8
8
|
import { onDestroy, onMount } from 'svelte';
|
|
9
9
|
const { value, size = 'md', disabled = false, readonly = false, inert = false, error = false, borderless = false, emoji = false, autofocus = false, rows = 0, placeholder = '', options, conf, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'aria-required': ariaRequired, on } = $props();
|
|
10
10
|
const id = $props.id();
|
|
@@ -82,7 +82,8 @@ onMount(async () => {
|
|
|
82
82
|
auto_focus: autofocus ? id : undefined,
|
|
83
83
|
placeholder,
|
|
84
84
|
readonly: disabled || readonly || inert,
|
|
85
|
-
toolbar: 'undo redo | blocks | fontfamily fontsize | bold italic underline | forecolor backcolor | alignleft aligncenter alignright | bullist numlist outdent indent | lineheight | table |
|
|
85
|
+
toolbar: 'undo redo | blocks | fontfamily fontsize | bold italic underline | forecolor backcolor | alignleft aligncenter alignright | bullist numlist outdent indent | lineheight | table | ' +
|
|
86
|
+
['validatedlink', ...(options?.extraToolbarButtons ?? [])].join(' '),
|
|
86
87
|
toolbar_persist: options?.persistToolbar,
|
|
87
88
|
plugins: ['advlist', 'link', 'lists', 'table'],
|
|
88
89
|
advlist_bullet_styles: 'default,circle,square,disc',
|
|
@@ -91,7 +92,9 @@ onMount(async () => {
|
|
|
91
92
|
font_family_formats: 'Arial=arial,helvetica,sans-serif; Comic Sans MS=comic sans ms,cursive; Courier New=courier new,courier,monospace; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,charcoal,sans-serif; Lucida Console=lucida console,monaco,monospace; Palatino Linotype=palatino linotype,book antiqua,palatino,serif; Tahoma=tahoma,geneva,sans-serif; Times New Roman=times new roman,times,serif; Trebuchet MS=trebuchet ms,sans-serif; Verdana=verdana,geneva,sans-serif',
|
|
92
93
|
font_size_formats: '8px 10px 12px 14px 16px 18px 24px 36px 48px',
|
|
93
94
|
block_formats: 'Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6',
|
|
94
|
-
contextmenu: '
|
|
95
|
+
contextmenu: ['validatedlink', ...(options?.extraContextMenu ?? [])].join(' '),
|
|
96
|
+
link_default_target: LINK_TARGET,
|
|
97
|
+
link_target_list: false,
|
|
95
98
|
paste_data_images: false,
|
|
96
99
|
paste_preprocess: (_, args) => {
|
|
97
100
|
if (args.internal) {
|
|
@@ -126,7 +129,7 @@ onMount(async () => {
|
|
|
126
129
|
everFocused = true;
|
|
127
130
|
on?.focus?.();
|
|
128
131
|
});
|
|
129
|
-
|
|
132
|
+
registerValidatedLink(editor, loc);
|
|
130
133
|
on?.mounted?.({ editor, insertEmoji });
|
|
131
134
|
if (typeof conf?.setup === 'function') {
|
|
132
135
|
conf.setup(editor);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RichTextInputOptions } from './types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { RichTextEditor, RichTextInputOptions } from './types';
|
|
2
|
+
import type { RawEditorOptions } from 'hugerte';
|
|
3
3
|
type Props = {
|
|
4
4
|
/** HTML content. */
|
|
5
5
|
value: string | null | undefined;
|
|
@@ -30,7 +30,7 @@ type Props = {
|
|
|
30
30
|
focus?: () => void;
|
|
31
31
|
blur?: () => void;
|
|
32
32
|
mounted?: (data: {
|
|
33
|
-
editor:
|
|
33
|
+
editor: RichTextEditor;
|
|
34
34
|
insertEmoji: (emoji: string) => void;
|
|
35
35
|
}) => void;
|
|
36
36
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as RichTextInput } from './cmp.rich-text-input.svelte';
|
|
2
|
-
export type { RichTextInputOptions } from './types';
|
|
2
|
+
export type { RichTextEditor, RichTextInputOptions } from './types';
|
|
@@ -3,9 +3,6 @@ export declare class RichTextInputLocalization {
|
|
|
3
3
|
get linkDialogTitle(): string;
|
|
4
4
|
get linkUrlLabel(): string;
|
|
5
5
|
get linkTextLabel(): string;
|
|
6
|
-
get linkTargetLabel(): string;
|
|
7
|
-
get linkTargetSelf(): string;
|
|
8
|
-
get linkTargetBlank(): string;
|
|
9
6
|
get linkCancelButton(): string;
|
|
10
7
|
get linkSaveButton(): string;
|
|
11
8
|
get linkUrlInvalid(): string;
|
|
@@ -4,9 +4,6 @@ const loc = {
|
|
|
4
4
|
linkDialogTitle: { en: 'Insert/Edit Link', no: 'Sett inn/rediger lenke' },
|
|
5
5
|
linkUrlLabel: { en: 'URL', no: 'URL' },
|
|
6
6
|
linkTextLabel: { en: 'Text to display', no: 'Tekst a vise' },
|
|
7
|
-
linkTargetLabel: { en: 'Open link in...', no: 'Apne lenke i...' },
|
|
8
|
-
linkTargetSelf: { en: 'Current window', no: 'Gjeldende vindu' },
|
|
9
|
-
linkTargetBlank: { en: 'New window', no: 'Nytt vindu' },
|
|
10
7
|
linkCancelButton: { en: 'Cancel', no: 'Avbryt' },
|
|
11
8
|
linkSaveButton: { en: 'Save', no: 'Lagre' },
|
|
12
9
|
linkUrlInvalid: {
|
|
@@ -27,15 +24,6 @@ export class RichTextInputLocalization {
|
|
|
27
24
|
get linkTextLabel() {
|
|
28
25
|
return loc.linkTextLabel[AppLocale.current];
|
|
29
26
|
}
|
|
30
|
-
get linkTargetLabel() {
|
|
31
|
-
return loc.linkTargetLabel[AppLocale.current];
|
|
32
|
-
}
|
|
33
|
-
get linkTargetSelf() {
|
|
34
|
-
return loc.linkTargetSelf[AppLocale.current];
|
|
35
|
-
}
|
|
36
|
-
get linkTargetBlank() {
|
|
37
|
-
return loc.linkTargetBlank[AppLocale.current];
|
|
38
|
-
}
|
|
39
27
|
get linkCancelButton() {
|
|
40
28
|
return loc.linkCancelButton[AppLocale.current];
|
|
41
29
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import type { Editor } from 'hugerte';
|
|
2
|
+
export type RichTextEditor = Editor;
|
|
1
3
|
export type RichTextInputOptions = {
|
|
2
4
|
persistToolbar?: boolean;
|
|
3
5
|
fixedToolbarId?: string;
|
|
6
|
+
/** HugeRTE button names appended after the link button. The host registers them in `conf.setup`. */
|
|
7
|
+
extraToolbarButtons?: string[];
|
|
8
|
+
/** HugeRTE context menu names appended after the link menu. The host registers them in `conf.setup`. */
|
|
9
|
+
extraContextMenu?: string[];
|
|
4
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { RichTextInputLocalization } from './rich-text-input-localization';
|
|
2
2
|
import type { Editor } from 'hugerte';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const LINK_TARGET = "_blank";
|
|
4
|
+
export declare const registerValidatedLink: (editor: Editor, loc: RichTextInputLocalization) => void;
|
|
@@ -1,78 +1,101 @@
|
|
|
1
1
|
import { validateHref } from '../../core/utils';
|
|
2
|
-
const
|
|
3
|
-
export const
|
|
2
|
+
export const LINK_TARGET = '_blank';
|
|
3
|
+
export const registerValidatedLink = (editor, loc) => {
|
|
4
|
+
const isInHostAnchor = (node) => {
|
|
5
|
+
const anchor = editor.dom.getParent(node, 'a');
|
|
6
|
+
return anchor !== null && !anchor.hasAttribute('href');
|
|
7
|
+
};
|
|
8
|
+
const selectionTouchesHostAnchor = () => {
|
|
9
|
+
const range = editor.selection.getRng();
|
|
10
|
+
return (isInHostAnchor(editor.selection.getNode()) ||
|
|
11
|
+
(!range.collapsed && range.cloneContents().querySelector('a:not([href])') !== null));
|
|
12
|
+
};
|
|
13
|
+
const disableInHostAnchor = (api) => {
|
|
14
|
+
const update = () => api.setEnabled(!editor.mode.isReadOnly() && !selectionTouchesHostAnchor());
|
|
15
|
+
update();
|
|
16
|
+
// SelectionChange: touch handle drags fire no NodeChange; SwitchMode: the theme re-enables every button when leaving readonly.
|
|
17
|
+
editor.on('NodeChange SelectionChange SwitchMode', update);
|
|
18
|
+
return () => editor.off('NodeChange SelectionChange SwitchMode', update);
|
|
19
|
+
};
|
|
20
|
+
const openLinkDialog = () => {
|
|
21
|
+
const linkNode = editor.dom.getParent(editor.selection.getNode(), 'a[href]');
|
|
22
|
+
let initialUrl = '';
|
|
23
|
+
let initialText = '';
|
|
24
|
+
if (linkNode) {
|
|
25
|
+
initialUrl = linkNode.getAttribute('href') ?? '';
|
|
26
|
+
initialText = linkNode.textContent ?? '';
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
initialText = editor.selection.getContent({ format: 'text' }) ?? '';
|
|
30
|
+
}
|
|
31
|
+
let userChangedText = false;
|
|
32
|
+
editor.windowManager.open({
|
|
33
|
+
title: loc.linkDialogTitle,
|
|
34
|
+
body: {
|
|
35
|
+
type: 'panel',
|
|
36
|
+
items: [
|
|
37
|
+
{ type: 'input', name: 'url', label: loc.linkUrlLabel },
|
|
38
|
+
{ type: 'input', name: 'text', label: loc.linkTextLabel }
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
initialData: {
|
|
42
|
+
url: initialUrl,
|
|
43
|
+
text: initialText
|
|
44
|
+
},
|
|
45
|
+
buttons: [
|
|
46
|
+
{ type: 'cancel', text: loc.linkCancelButton },
|
|
47
|
+
{ type: 'submit', text: loc.linkSaveButton, primary: true }
|
|
48
|
+
],
|
|
49
|
+
onChange: (api, details) => {
|
|
50
|
+
if (details.name === 'text' && !userChangedText) {
|
|
51
|
+
userChangedText = true;
|
|
52
|
+
}
|
|
53
|
+
if (details.name === 'url') {
|
|
54
|
+
const data = api.getData();
|
|
55
|
+
if (!userChangedText && !initialText) {
|
|
56
|
+
api.setData({ text: data.url });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
onSubmit: (api) => {
|
|
61
|
+
const data = api.getData();
|
|
62
|
+
if (!validateHref(data.url, { allowRelative: 'prefixed' }).valid) {
|
|
63
|
+
editor.windowManager.alert(loc.linkUrlInvalid);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (linkNode) {
|
|
67
|
+
editor.dom.setAttrib(linkNode, 'href', data.url);
|
|
68
|
+
editor.dom.setAttrib(linkNode, 'target', LINK_TARGET);
|
|
69
|
+
linkNode.textContent = data.text ?? data.url;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
editor.insertContent(`<a href="${data.url}" target="${LINK_TARGET}">${data.text ?? data.url}</a>`);
|
|
73
|
+
}
|
|
74
|
+
api.close();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
4
78
|
editor.ui.registry.addButton('validatedlink', {
|
|
5
79
|
icon: 'link',
|
|
6
80
|
tooltip: loc.linkButton,
|
|
7
|
-
onAction:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
81
|
+
onAction: openLinkDialog,
|
|
82
|
+
onSetup: disableInHostAnchor
|
|
83
|
+
});
|
|
84
|
+
editor.ui.registry.addMenuItem('validatedlink', {
|
|
85
|
+
icon: 'link',
|
|
86
|
+
text: loc.linkButton,
|
|
87
|
+
onAction: openLinkDialog
|
|
88
|
+
});
|
|
89
|
+
editor.ui.registry.addContextMenu('validatedlink', {
|
|
90
|
+
update: (element) => {
|
|
91
|
+
if (!editor.dom.isEditable(element) ||
|
|
92
|
+
isInHostAnchor(element) ||
|
|
93
|
+
selectionTouchesHostAnchor()) {
|
|
94
|
+
return '';
|
|
19
95
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
body: {
|
|
24
|
-
type: 'panel',
|
|
25
|
-
items: [
|
|
26
|
-
{ type: 'input', name: 'url', label: loc.linkUrlLabel },
|
|
27
|
-
{ type: 'input', name: 'text', label: loc.linkTextLabel },
|
|
28
|
-
{
|
|
29
|
-
type: 'listbox',
|
|
30
|
-
name: 'openIn',
|
|
31
|
-
label: loc.linkTargetLabel,
|
|
32
|
-
items: [
|
|
33
|
-
{ text: loc.linkTargetSelf, value: '_self' },
|
|
34
|
-
{ text: loc.linkTargetBlank, value: '_blank' }
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
initialData: {
|
|
40
|
-
url: initialUrl,
|
|
41
|
-
text: initialText,
|
|
42
|
-
openIn: initialTarget
|
|
43
|
-
},
|
|
44
|
-
buttons: [
|
|
45
|
-
{ type: 'cancel', text: loc.linkCancelButton },
|
|
46
|
-
{ type: 'submit', text: loc.linkSaveButton, primary: true }
|
|
47
|
-
],
|
|
48
|
-
onChange: (api, details) => {
|
|
49
|
-
if (details.name === 'text' && !userChangedText) {
|
|
50
|
-
userChangedText = true;
|
|
51
|
-
}
|
|
52
|
-
if (details.name === 'url') {
|
|
53
|
-
const data = api.getData();
|
|
54
|
-
if (!userChangedText && !initialText) {
|
|
55
|
-
api.setData({ text: data.url });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
onSubmit: (api) => {
|
|
60
|
-
const data = api.getData();
|
|
61
|
-
if (!validateHref(data.url, { allowRelative: 'prefixed' }).valid) {
|
|
62
|
-
editor.windowManager.alert(loc.linkUrlInvalid);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (linkNode) {
|
|
66
|
-
editor.dom.setAttrib(linkNode, 'href', data.url);
|
|
67
|
-
editor.dom.setAttrib(linkNode, 'target', data.openIn);
|
|
68
|
-
linkNode.textContent = data.text ?? data.url;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
editor.insertContent(`<a href="${data.url}" target="${data.openIn}">${data.text ?? data.url}</a>`);
|
|
72
|
-
}
|
|
73
|
-
api.close();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
96
|
+
return editor.dom.getParent(element, 'a[href]')
|
|
97
|
+
? 'validatedlink unlink openlink'
|
|
98
|
+
: 'validatedlink';
|
|
76
99
|
}
|
|
77
100
|
});
|
|
78
101
|
};
|