@sveltia/ui 0.89.2 → 0.90.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/dist/components/checkbox/checkbox.svelte +5 -8
- package/dist/components/dialog/dialog.svelte +149 -9
- package/dist/components/emoji/emoji-suggestions.svelte +7 -7
- package/dist/components/grid/grid-col-header.svelte +4 -0
- package/dist/components/grid/grid-head.svelte +1 -1
- package/dist/components/grid/grid-head.svelte.d.ts +1 -1
- package/dist/components/radio/radio.svelte +9 -9
- package/dist/components/resizable-pane/resizable-pane-group.svelte +5 -20
- package/dist/components/resizable-pane/sizing.d.ts +6 -0
- package/dist/components/resizable-pane/sizing.js +31 -0
- package/dist/components/text-editor/code-editor.svelte +22 -39
- package/dist/components/text-editor/constants.js +3 -3
- package/dist/components/text-editor/conversion/editor-components.d.ts +5 -0
- package/dist/components/text-editor/conversion/editor-components.js +228 -0
- package/dist/components/text-editor/{html.d.ts → conversion/html.d.ts} +1 -1
- package/dist/components/text-editor/{html.js → conversion/html.js} +158 -20
- package/dist/components/text-editor/conversion/import.d.ts +12 -0
- package/dist/components/text-editor/conversion/import.js +327 -0
- package/dist/components/text-editor/conversion/paste.d.ts +4 -0
- package/dist/components/text-editor/conversion/paste.js +166 -0
- package/dist/components/text-editor/{transformers → conversion/transformers}/raw-syntax.js +4 -4
- package/dist/components/text-editor/conversion/transformers/table.js +342 -0
- package/dist/components/text-editor/conversion/update.d.ts +6 -0
- package/dist/components/text-editor/conversion/update.js +125 -0
- package/dist/components/text-editor/core.d.ts +50 -26
- package/dist/components/text-editor/core.js +133 -1694
- package/dist/components/text-editor/editing/caret.d.ts +4 -0
- package/dist/components/text-editor/editing/caret.js +248 -0
- package/dist/components/text-editor/editing/commands.d.ts +5 -0
- package/dist/components/text-editor/editing/commands.js +205 -0
- package/dist/components/text-editor/editing/link.d.ts +19 -0
- package/dist/components/text-editor/editing/link.js +222 -0
- package/dist/components/text-editor/{raw-markdown.d.ts → editing/raw-markdown.d.ts} +3 -3
- package/dist/components/text-editor/{raw-markdown.js → editing/raw-markdown.js} +2 -2
- package/dist/components/text-editor/editing/selection.d.ts +5 -0
- package/dist/components/text-editor/editing/selection.js +122 -0
- package/dist/components/text-editor/editing/single-line.d.ts +8 -0
- package/dist/components/text-editor/editing/single-line.js +190 -0
- package/dist/components/text-editor/{table.js → editing/table.js} +1 -1
- package/dist/components/text-editor/lexical-root.svelte +61 -10
- package/dist/components/text-editor/shiki/preload.d.ts +1 -0
- package/dist/components/text-editor/shiki/preload.js +30 -0
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/text-editor/store.svelte.d.ts +5 -0
- package/dist/components/text-editor/store.svelte.js +55 -1
- package/dist/components/text-editor/text-editor.svelte +29 -41
- package/dist/components/text-editor/toolbar/align-menu-button.svelte +1 -1
- package/dist/components/text-editor/toolbar/code-language-switcher.svelte +2 -1
- package/dist/components/text-editor/toolbar/format-text-button.svelte +6 -2
- package/dist/components/text-editor/toolbar/insert-component.js +1 -1
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +4 -4
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +3 -2
- package/dist/components/text-editor/toolbar/insert-table-button.svelte +7 -3
- package/dist/components/text-editor/toolbar/table-action-menu.svelte +3 -3
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +1 -1
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +2 -2
- package/dist/components/text-editor/utils.d.ts +1 -0
- package/dist/components/text-editor/utils.js +17 -0
- package/dist/components/text-editor/{emoji-autocomplete.svelte → widgets/emoji-autocomplete.svelte} +3 -3
- package/dist/components/text-editor/{floating-link-editor.svelte → widgets/floating-link-editor.svelte} +36 -79
- package/dist/components/text-editor/{table-cell-menu-button.svelte → widgets/table-cell-menu-button.svelte} +15 -5
- package/dist/components/text-field/date-time-input.svelte +8 -8
- package/dist/components/text-field/text-area.svelte +10 -10
- package/dist/components/text-field/text-input.svelte +7 -7
- package/dist/components/util/modal.svelte +41 -12
- package/dist/components/util/popup.svelte +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/locales/es-ES.yaml +174 -0
- package/dist/services/label.d.ts +8 -0
- package/dist/services/label.js +15 -0
- package/dist/services/popup-position.d.ts +9 -0
- package/dist/services/popup-position.js +52 -55
- package/dist/styles/mixins.scss +69 -0
- package/dist/typedefs.d.ts +28 -1
- package/dist/typedefs.js +16 -1
- package/package.json +13 -11
- package/dist/components/text-editor/transformers/table.js +0 -296
- /package/dist/components/text-editor/{markdown.d.ts → conversion/markdown.d.ts} +0 -0
- /package/dist/components/text-editor/{markdown.js → conversion/markdown.js} +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/block-escape.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/block-escape.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/code.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/code.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/formatted-code.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/formatted-code.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/hr.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/hr.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/inline-code.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/inline-code.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/link.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/link.js +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/raw-syntax.d.ts +0 -0
- /package/dist/components/text-editor/{transformers → conversion/transformers}/table.d.ts +0 -0
- /package/dist/components/text-editor/{alignment.d.ts → editing/alignment.d.ts} +0 -0
- /package/dist/components/text-editor/{alignment.js → editing/alignment.js} +0 -0
- /package/dist/components/text-editor/{block.d.ts → editing/block.d.ts} +0 -0
- /package/dist/components/text-editor/{block.js → editing/block.js} +0 -0
- /package/dist/components/text-editor/{table.d.ts → editing/table.d.ts} +0 -0
- /package/dist/components/text-editor/{emoji-autocomplete.svelte.d.ts → widgets/emoji-autocomplete.svelte.d.ts} +0 -0
- /package/dist/components/text-editor/{floating-link-editor.svelte.d.ts → widgets/floating-link-editor.svelte.d.ts} +0 -0
- /package/dist/components/text-editor/{table-cell-menu-button.svelte.d.ts → widgets/table-cell-menu-button.svelte.d.ts} +0 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
@see https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/
|
|
7
7
|
-->
|
|
8
8
|
<script>
|
|
9
|
+
import { getToggleLabelAttrs } from '../../services/label.js';
|
|
9
10
|
import Button from '../button/button.svelte';
|
|
10
11
|
import Icon from '../icon/icon.svelte';
|
|
11
12
|
|
|
@@ -63,13 +64,10 @@
|
|
|
63
64
|
*/
|
|
64
65
|
let buttonElement = $state();
|
|
65
66
|
|
|
66
|
-
/**
|
|
67
|
-
* Accessible name given as a prop or as a plain `aria-label` attribute. It takes the place of the
|
|
68
|
-
* visible label, which the button otherwise points at — but only when there is one to point at.
|
|
69
|
-
* @type {string | undefined}
|
|
70
|
-
*/
|
|
71
|
-
const accessibleLabel = $derived(ariaLabel ?? restProps['aria-label']);
|
|
72
67
|
const hasVisibleLabel = $derived(!!(children || label));
|
|
68
|
+
const labelAttrs = $derived(
|
|
69
|
+
getToggleLabelAttrs({ id, ariaLabel: ariaLabel ?? restProps['aria-label'], hasVisibleLabel }),
|
|
70
|
+
);
|
|
73
71
|
const indeterminate = $derived(checked === 'mixed');
|
|
74
72
|
|
|
75
73
|
// Sync `checked` with `group` and `value`
|
|
@@ -119,8 +117,7 @@
|
|
|
119
117
|
aria-required={required}
|
|
120
118
|
aria-invalid={invalid}
|
|
121
119
|
aria-checked={checked}
|
|
122
|
-
|
|
123
|
-
aria-labelledby={!accessibleLabel && hasVisibleLabel ? `${id}-label` : undefined}
|
|
120
|
+
{...labelAttrs}
|
|
124
121
|
onclick={(event) => {
|
|
125
122
|
event.preventDefault();
|
|
126
123
|
event.stopPropagation();
|
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
@see https://w3c.github.io/aria/#dialog
|
|
5
5
|
@see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
|
|
6
6
|
-->
|
|
7
|
+
<script module>
|
|
8
|
+
/**
|
|
9
|
+
* Keep the distance a dialog is dragged within the room it has on either side.
|
|
10
|
+
* @param {number} distance Distance moved.
|
|
11
|
+
* @param {number} before Room on the left or top.
|
|
12
|
+
* @param {number} after Room on the right or bottom.
|
|
13
|
+
* @returns {number} Clamped distance.
|
|
14
|
+
*/
|
|
15
|
+
const clamp = (distance, before, after) =>
|
|
16
|
+
Math.min(Math.max(distance, -before), Math.max(after, 0));
|
|
17
|
+
</script>
|
|
18
|
+
|
|
7
19
|
<script>
|
|
8
20
|
import { _ } from '@sveltia/i18n';
|
|
9
21
|
import { sleep } from '@sveltia/utils/misc';
|
|
@@ -27,6 +39,9 @@
|
|
|
27
39
|
ariaLabelledby = undefined,
|
|
28
40
|
role = 'dialog',
|
|
29
41
|
size = 'medium',
|
|
42
|
+
modal = true,
|
|
43
|
+
showBackdrop = undefined,
|
|
44
|
+
movable = false,
|
|
30
45
|
class: className,
|
|
31
46
|
showClose = false,
|
|
32
47
|
showOk = true,
|
|
@@ -66,12 +81,128 @@
|
|
|
66
81
|
* A reference to the modal component.
|
|
67
82
|
* @type {Modal | undefined}
|
|
68
83
|
*/
|
|
69
|
-
let
|
|
84
|
+
let modalComponent = $state();
|
|
70
85
|
/**
|
|
71
86
|
* @type {HTMLElement | undefined}
|
|
72
87
|
*/
|
|
73
88
|
let content = $state();
|
|
74
89
|
|
|
90
|
+
/**
|
|
91
|
+
* How far the user has moved the dialog from the center of the viewport by dragging its header.
|
|
92
|
+
* @type {{ x: number, y: number }}
|
|
93
|
+
*/
|
|
94
|
+
let offset = $state({ x: 0, y: 0 });
|
|
95
|
+
/**
|
|
96
|
+
* Where the current drag started, if the user is dragging the header.
|
|
97
|
+
* @type {{ pointerId: number, x: number, y: number, offset: { x: number, y: number }, rect:
|
|
98
|
+
* DOMRect } | undefined}
|
|
99
|
+
*/
|
|
100
|
+
let dragStart;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Move the dialog back to the center of the viewport, ending a drag if any.
|
|
104
|
+
*/
|
|
105
|
+
const recenter = () => {
|
|
106
|
+
offset = { x: 0, y: 0 };
|
|
107
|
+
dragStart = undefined;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
$effect(() => {
|
|
111
|
+
if (!open) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Start from the center whenever the dialog is opened again
|
|
116
|
+
recenter();
|
|
117
|
+
|
|
118
|
+
if (!movable) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// A moved dialog could end up outside a smaller viewport, so bring it back to the center
|
|
123
|
+
window.addEventListener('resize', recenter);
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
window.removeEventListener('resize', recenter);
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Start moving the dialog when the header is pressed, unless a button or another control in the
|
|
132
|
+
* header is. Only bound when the dialog is {@link movable}.
|
|
133
|
+
* @param {PointerEvent} event `pointerdown` event.
|
|
134
|
+
*/
|
|
135
|
+
const onHeaderPointerDown = (event) => {
|
|
136
|
+
const { button, pointerId, clientX, clientY, currentTarget, target } = event;
|
|
137
|
+
const headerElement = /** @type {HTMLElement} */ (currentTarget);
|
|
138
|
+
|
|
139
|
+
// Look for the control within the header only: the `<dialog>` around it has `tabindex` as well
|
|
140
|
+
const control = /** @type {HTMLElement} */ (target).closest(
|
|
141
|
+
'button, input, select, textarea, a, [tabindex]',
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (button !== 0 || (control && headerElement.contains(control))) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
headerElement.setPointerCapture(pointerId);
|
|
150
|
+
dragStart = {
|
|
151
|
+
pointerId,
|
|
152
|
+
x: clientX,
|
|
153
|
+
y: clientY,
|
|
154
|
+
offset: { ...offset },
|
|
155
|
+
// The header is rendered within the content
|
|
156
|
+
rect: /** @type {HTMLElement} */ (content).getBoundingClientRect(),
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Move the dialog along with the pointer, keeping it within the viewport.
|
|
162
|
+
* @param {PointerEvent} event `pointermove` event.
|
|
163
|
+
*/
|
|
164
|
+
const onHeaderPointerMove = ({ pointerId, buttons, clientX, clientY }) => {
|
|
165
|
+
if (!dragStart || dragStart.pointerId !== pointerId) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The drag can end without a `pointerup` reaching the header, e.g. when the dialog is closed
|
|
170
|
+
// halfway, so a move without the primary button pressed ends it. The primary button is the
|
|
171
|
+
// lowest bit of `buttons`
|
|
172
|
+
if (buttons % 2 === 0) {
|
|
173
|
+
dragStart = undefined;
|
|
174
|
+
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const { x, y, offset: startOffset, rect } = dragStart;
|
|
179
|
+
|
|
180
|
+
offset = {
|
|
181
|
+
x: startOffset.x + clamp(clientX - x, rect.left, window.innerWidth - rect.right),
|
|
182
|
+
y: startOffset.y + clamp(clientY - y, rect.top, window.innerHeight - rect.bottom),
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Stop moving the dialog.
|
|
188
|
+
* @param {PointerEvent} event `pointerup` or `pointercancel` event.
|
|
189
|
+
*/
|
|
190
|
+
const onHeaderPointerUp = ({ pointerId }) => {
|
|
191
|
+
if (dragStart?.pointerId === pointerId) {
|
|
192
|
+
dragStart = undefined;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Event handlers that let the user move the dialog by dragging its header.
|
|
198
|
+
*/
|
|
199
|
+
const dragHandlers = {
|
|
200
|
+
onpointerdown: onHeaderPointerDown,
|
|
201
|
+
onpointermove: onHeaderPointerMove,
|
|
202
|
+
onpointerup: onHeaderPointerUp,
|
|
203
|
+
onpointercancel: onHeaderPointerUp,
|
|
204
|
+
};
|
|
205
|
+
|
|
75
206
|
$effect(() => {
|
|
76
207
|
if (open && content) {
|
|
77
208
|
let cancelled = false;
|
|
@@ -102,7 +233,7 @@
|
|
|
102
233
|
} else {
|
|
103
234
|
// Fall back to the `<dialog>` element itself, so the focus is never left outside the
|
|
104
235
|
// modal, e.g. when the dialog has no input field or primary button
|
|
105
|
-
|
|
236
|
+
modalComponent?.focus();
|
|
106
237
|
}
|
|
107
238
|
})();
|
|
108
239
|
|
|
@@ -116,7 +247,7 @@
|
|
|
116
247
|
</script>
|
|
117
248
|
|
|
118
249
|
<Modal
|
|
119
|
-
bind:this={
|
|
250
|
+
bind:this={modalComponent}
|
|
120
251
|
{...restProps}
|
|
121
252
|
{role}
|
|
122
253
|
{id}
|
|
@@ -125,11 +256,17 @@
|
|
|
125
256
|
aria-labelledby={labelledby}
|
|
126
257
|
aria-describedby="{id}-body"
|
|
127
258
|
bind:open
|
|
128
|
-
|
|
259
|
+
{modal}
|
|
260
|
+
showBackdrop={showBackdrop ?? modal}
|
|
129
261
|
>
|
|
130
|
-
<div
|
|
262
|
+
<div
|
|
263
|
+
bind:this={content}
|
|
264
|
+
role="none"
|
|
265
|
+
class={['content', className, size]}
|
|
266
|
+
style:translate={movable ? `${offset.x}px ${offset.y}px` : undefined}
|
|
267
|
+
>
|
|
131
268
|
{#if title || showClose || header || headerExtra}
|
|
132
|
-
<div role="none" class="header">
|
|
269
|
+
<div role="none" class="header" class:movable {...movable ? dragHandlers : {}}>
|
|
133
270
|
{#if header}
|
|
134
271
|
{@render header()}
|
|
135
272
|
{:else}
|
|
@@ -143,7 +280,7 @@
|
|
|
143
280
|
controls={id}
|
|
144
281
|
{closeIcon}
|
|
145
282
|
onClose={() => {
|
|
146
|
-
|
|
283
|
+
modalComponent?.close('close');
|
|
147
284
|
}}
|
|
148
285
|
/>
|
|
149
286
|
{/if}
|
|
@@ -167,7 +304,7 @@
|
|
|
167
304
|
keyShortcuts={okShortcuts}
|
|
168
305
|
disabled={okDisabled}
|
|
169
306
|
onclick={() => {
|
|
170
|
-
|
|
307
|
+
modalComponent?.close('ok');
|
|
171
308
|
}}
|
|
172
309
|
/>
|
|
173
310
|
{/if}
|
|
@@ -178,7 +315,7 @@
|
|
|
178
315
|
keyShortcuts={cancelShortcuts}
|
|
179
316
|
disabled={cancelDisabled}
|
|
180
317
|
onclick={() => {
|
|
181
|
-
|
|
318
|
+
modalComponent?.close('cancel');
|
|
182
319
|
}}
|
|
183
320
|
/>
|
|
184
321
|
{/if}
|
|
@@ -273,6 +410,9 @@
|
|
|
273
410
|
padding: var(--sui-dialog-header-padding, 16px 8px);
|
|
274
411
|
height: var(--sui-dialog-header-height, 32px);
|
|
275
412
|
}
|
|
413
|
+
.header.movable {
|
|
414
|
+
cursor: move;
|
|
415
|
+
}
|
|
276
416
|
.header .title {
|
|
277
417
|
font-size: var(--sui-font-size-large);
|
|
278
418
|
font-weight: var(--sui-font-weight-bold);
|
|
@@ -410,22 +410,22 @@
|
|
|
410
410
|
flex-direction: column;
|
|
411
411
|
overflow-y: auto;
|
|
412
412
|
margin: 0;
|
|
413
|
+
padding: var(--sui-listbox-padding, 4px);
|
|
414
|
+
width: 280px;
|
|
415
|
+
font-family: var(--sui-control-font-family);
|
|
416
|
+
font-size: var(--sui-control-font-size);
|
|
417
|
+
line-height: var(--sui-control-line-height);
|
|
418
|
+
-webkit-user-select: none;
|
|
419
|
+
user-select: none;
|
|
413
420
|
border-width: var(--sui-listbox-border-width, 1px);
|
|
414
421
|
border-style: var(--sui-listbox-border-style, solid);
|
|
415
422
|
border-color: var(--sui-listbox-border-color, var(--sui-secondary-border-color));
|
|
416
423
|
border-radius: var(--sui-listbox-border-radius, 4px);
|
|
417
|
-
padding: var(--sui-listbox-padding, 4px);
|
|
418
|
-
width: 280px;
|
|
419
424
|
color: var(--sui-primary-foreground-color);
|
|
420
425
|
background-color: var(--sui-secondary-background-color-translucent);
|
|
421
426
|
box-shadow: 0 8px 16px var(--sui-popup-shadow-color);
|
|
422
427
|
-webkit-backdrop-filter: blur(16px);
|
|
423
428
|
backdrop-filter: blur(16px);
|
|
424
|
-
font-family: var(--sui-control-font-family);
|
|
425
|
-
font-size: var(--sui-control-font-size);
|
|
426
|
-
line-height: var(--sui-control-line-height);
|
|
427
|
-
-webkit-user-select: none;
|
|
428
|
-
user-select: none;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
.option {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
/**
|
|
48
48
|
* Keep the sort button’s clicks and activation keys from the `<Grid>`, which would otherwise
|
|
49
49
|
* select or focus the header row, or prevent the key’s default action, and call `onSort` instead.
|
|
50
|
+
* A click also focuses the button, as it does in browsers other than Safari.
|
|
50
51
|
* Native listeners are used because the grid listens on its own element, which a delegated Svelte
|
|
51
52
|
* event handler would only reach after the grid has handled the event. The arrow keys are left
|
|
52
53
|
* alone, so they still move from the header row to the data rows.
|
|
@@ -59,6 +60,9 @@
|
|
|
59
60
|
*/
|
|
60
61
|
const onClick = (event) => {
|
|
61
62
|
event.stopPropagation();
|
|
63
|
+
// Safari doesn’t focus a button on click, but moves the focus to the closest focusable
|
|
64
|
+
// ancestor instead, which is the header row
|
|
65
|
+
/** @type {HTMLElement} */ (element).focus();
|
|
62
66
|
onSort?.(
|
|
63
67
|
new CustomEvent('Sort', {
|
|
64
68
|
detail: { sortOrder: sortOrder === 'ascending' ? 'descending' : 'ascending' },
|
|
@@ -4,7 +4,7 @@ type GridHead = {
|
|
|
4
4
|
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
|
-
* The interactive version of `<
|
|
7
|
+
* The interactive version of `<TableHead>`.
|
|
8
8
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead
|
|
9
9
|
* @see https://w3c.github.io/aria/#rowgroup
|
|
10
10
|
*/
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
@see https://www.w3.org/WAI/ARIA/apg/patterns/radio/
|
|
7
7
|
-->
|
|
8
8
|
<script>
|
|
9
|
+
import { getToggleLabelAttrs } from '../../services/label.js';
|
|
9
10
|
import Button from '../button/button.svelte';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -66,13 +67,13 @@
|
|
|
66
67
|
*/
|
|
67
68
|
let buttonElement = $state();
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const labelAttrs = $derived(
|
|
71
|
+
getToggleLabelAttrs({
|
|
72
|
+
id,
|
|
73
|
+
ariaLabel: ariaLabel ?? restProps['aria-label'],
|
|
74
|
+
hasVisibleLabel: !!(children || label),
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Check if the radio button belongs to a read-only `<RadioGroup>`.
|
|
@@ -121,8 +122,7 @@
|
|
|
121
122
|
{value}
|
|
122
123
|
{valueType}
|
|
123
124
|
aria-checked={checked}
|
|
124
|
-
|
|
125
|
-
aria-labelledby={!accessibleLabel && hasVisibleLabel ? `${id}-label` : undefined}
|
|
125
|
+
{...labelAttrs}
|
|
126
126
|
onclick={(event) => {
|
|
127
127
|
event.preventDefault();
|
|
128
128
|
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
getInitialSizes,
|
|
12
12
|
resolvePaneConstraints,
|
|
13
13
|
resolveToPercent,
|
|
14
|
+
shareSpaceAmongPanes,
|
|
14
15
|
} from './sizing.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -216,31 +217,15 @@
|
|
|
216
217
|
};
|
|
217
218
|
|
|
218
219
|
/**
|
|
219
|
-
* Give the given space to the given panes,
|
|
220
|
-
*
|
|
221
|
-
* sizes allow.
|
|
220
|
+
* Give the given space to the given panes, then to the others, or take it from them with a
|
|
221
|
+
* negative amount; see {@link shareSpaceAmongPanes}.
|
|
222
222
|
* @param {number[]} neighbors Indexes of the panes to give the space to first.
|
|
223
223
|
* @param {number} amount Space in percentage points.
|
|
224
224
|
* @param {number} [exclude] Index of a pane to leave alone.
|
|
225
225
|
* @returns {number} Space that couldn’t be given or taken.
|
|
226
226
|
*/
|
|
227
|
-
const shareSpace = (neighbors, amount, exclude) =>
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
[...neighbors, ...sizes.map((_size, index) => index)].forEach((neighbor) => {
|
|
231
|
-
if (Math.abs(rest) < 0.001 || neighbor === exclude || sizes[neighbor] === undefined) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const { minSize, maxSize } = getPaneConstraints(neighbor);
|
|
236
|
-
const size = Math.min(Math.max(sizes[neighbor] + rest, minSize), maxSize);
|
|
237
|
-
|
|
238
|
-
rest -= size - sizes[neighbor];
|
|
239
|
-
sizes[neighbor] = size;
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
return rest;
|
|
243
|
-
};
|
|
227
|
+
const shareSpace = (neighbors, amount, exclude) =>
|
|
228
|
+
shareSpaceAmongPanes(sizes, { neighbors, amount, exclude, getConstraints: getPaneConstraints });
|
|
244
229
|
|
|
245
230
|
/**
|
|
246
231
|
* Put the panes and handles in the order they are in the group, and size a pane shown after the
|
|
@@ -10,6 +10,12 @@ export function clampResizeDelta(deltaPercent: number, { sizeBefore, sizeAfter,
|
|
|
10
10
|
constraintsBefore: PaneConstraints;
|
|
11
11
|
constraintsAfter: PaneConstraints;
|
|
12
12
|
}): number;
|
|
13
|
+
export function shareSpaceAmongPanes(sizes: number[], { neighbors, amount, exclude, getConstraints }: {
|
|
14
|
+
neighbors: number[];
|
|
15
|
+
amount: number;
|
|
16
|
+
exclude?: number | undefined;
|
|
17
|
+
getConstraints: (index: number) => PaneConstraints;
|
|
18
|
+
}): number;
|
|
13
19
|
export function getHandleKeyAction({ key, shiftKey, isHorizontal, rtl }: {
|
|
14
20
|
key: string;
|
|
15
21
|
shiftKey: boolean;
|
|
@@ -207,6 +207,37 @@ export const clampResizeDelta = (
|
|
|
207
207
|
return deltaPercent > 0 ? Math.min(deltaPercent, canGrow) : -Math.min(-deltaPercent, canShrink);
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Give the given space to the given panes, the first one first, then to the others, as far as
|
|
212
|
+
* their maximum sizes allow, or take it from them with a negative amount, as far as their minimum
|
|
213
|
+
* sizes allow. The sizes are updated in place.
|
|
214
|
+
* @param {number[]} sizes Pane sizes in percentages.
|
|
215
|
+
* @param {object} args Arguments.
|
|
216
|
+
* @param {number[]} args.neighbors Indexes of the panes to give the space to first.
|
|
217
|
+
* @param {number} args.amount Space in percentage points.
|
|
218
|
+
* @param {number} [args.exclude] Index of a pane to leave alone.
|
|
219
|
+
* @param {(index: number) => PaneConstraints} args.getConstraints Function to get the constraints
|
|
220
|
+
* of a pane.
|
|
221
|
+
* @returns {number} Space that couldn’t be given or taken.
|
|
222
|
+
*/
|
|
223
|
+
export const shareSpaceAmongPanes = (sizes, { neighbors, amount, exclude, getConstraints }) => {
|
|
224
|
+
let rest = amount;
|
|
225
|
+
|
|
226
|
+
[...neighbors, ...sizes.map((_size, index) => index)].forEach((neighbor) => {
|
|
227
|
+
if (Math.abs(rest) < 0.001 || neighbor === exclude || sizes[neighbor] === undefined) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const { minSize, maxSize } = getConstraints(neighbor);
|
|
232
|
+
const size = Math.min(Math.max(sizes[neighbor] + rest, minSize), maxSize);
|
|
233
|
+
|
|
234
|
+
rest -= size - sizes[neighbor];
|
|
235
|
+
sizes[neighbor] = size;
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
return rest;
|
|
239
|
+
};
|
|
240
|
+
|
|
210
241
|
/**
|
|
211
242
|
* Interpret a key pressed on a resize handle. Arrow keys move the handle by 1%, or 10% with Shift.
|
|
212
243
|
* Enter collapses or restores the pane before the handle. Home and End move it to its minimum and
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
-->
|
|
5
5
|
<script>
|
|
6
6
|
import { _ } from '@sveltia/i18n';
|
|
7
|
-
import { setContext
|
|
7
|
+
import { setContext } from 'svelte';
|
|
8
8
|
import Alert from '../alert/alert.svelte';
|
|
9
9
|
import Toast from '../toast/toast.svelte';
|
|
10
10
|
import { parseCodeBlock, toCodeBlock } from './code-editor.js';
|
|
11
11
|
import LexicalRoot from './lexical-root.svelte';
|
|
12
|
-
import { createEditorStore } from './store.svelte.js';
|
|
12
|
+
import { createEditorStore, syncEditorProps } from './store.svelte.js';
|
|
13
13
|
import CodeEditorToolbar from './toolbar/code-editor-toolbar.svelte';
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -90,42 +90,18 @@
|
|
|
90
90
|
|
|
91
91
|
setContext('editorStore', editorStore);
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/* v8 ignore next */
|
|
106
|
-
if (!editorStore.initialized) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
void code;
|
|
111
|
-
void lang;
|
|
112
|
-
|
|
113
|
-
untrack(() => {
|
|
114
|
-
editorStore.inputValue = toCodeBlock(lang, code);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
$effect(() => {
|
|
119
|
-
// The root initializes the editor before these effects first run, and stays initialized
|
|
120
|
-
/* v8 ignore next */
|
|
121
|
-
if (!editorStore.initialized) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
void editorStore.inputValue;
|
|
126
|
-
|
|
127
|
-
untrack(() => {
|
|
128
|
-
const { lang: _lang, code: _code } = parseCodeBlock(editorStore.inputValue);
|
|
93
|
+
syncEditorProps(editorStore, {
|
|
94
|
+
/**
|
|
95
|
+
* Wrap the code in a fenced code block for the editor.
|
|
96
|
+
* @returns {string} Code block.
|
|
97
|
+
*/
|
|
98
|
+
getInputValue: () => toCodeBlock(lang, code),
|
|
99
|
+
/**
|
|
100
|
+
* Take the editor’s code block apart into the language and the code.
|
|
101
|
+
* @param {string} inputValue Code block.
|
|
102
|
+
*/
|
|
103
|
+
setValue: (inputValue) => {
|
|
104
|
+
const { lang: _lang, code: _code } = parseCodeBlock(inputValue);
|
|
129
105
|
|
|
130
106
|
if (lang !== _lang) {
|
|
131
107
|
lang = _lang;
|
|
@@ -134,7 +110,14 @@
|
|
|
134
110
|
if (code !== _code) {
|
|
135
111
|
code = _code;
|
|
136
112
|
}
|
|
137
|
-
}
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Update the `pending` prop.
|
|
116
|
+
* @param {boolean} newValue New value.
|
|
117
|
+
*/
|
|
118
|
+
setPending: (newValue) => {
|
|
119
|
+
pending = newValue;
|
|
120
|
+
},
|
|
138
121
|
});
|
|
139
122
|
</script>
|
|
140
123
|
|
|
@@ -18,9 +18,9 @@ import {
|
|
|
18
18
|
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
19
19
|
import { createCommand } from 'lexical';
|
|
20
20
|
|
|
21
|
-
import { CODE } from './transformers/code.js';
|
|
22
|
-
import { LEADING_INLINE_CODE } from './transformers/inline-code.js';
|
|
23
|
-
import { LINK } from './transformers/link.js';
|
|
21
|
+
import { CODE } from './conversion/transformers/code.js';
|
|
22
|
+
import { LEADING_INLINE_CODE } from './conversion/transformers/inline-code.js';
|
|
23
|
+
import { LINK } from './conversion/transformers/link.js';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @import { EditorThemeClasses, LexicalCommand } from 'lexical';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function getComponentMarkdown({ node, createNode, transformer, createMarkdown }: TextEditorComponent): string;
|
|
2
|
+
export function isInlineComponent({ transformer }: TextEditorComponent): boolean;
|
|
3
|
+
export function removePlaceholdersFromMatch(transformer: Transformer): Transformer;
|
|
4
|
+
import type { TextEditorComponent } from '../../../typedefs.js';
|
|
5
|
+
import type { Transformer } from '@lexical/markdown';
|