@sveltia/ui 0.89.3 → 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/dialog/dialog.svelte +149 -9
- package/dist/components/text-editor/conversion/html.js +156 -18
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/util/modal.svelte +41 -12
- package/dist/locales/es-ES.yaml +174 -0
- package/dist/typedefs.d.ts +28 -1
- package/dist/typedefs.js +16 -1
- package/package.json +9 -9
|
@@ -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);
|
|
@@ -147,10 +147,143 @@ const exportElementNode = (editor, node) => {
|
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Elements a paragraph can’t hold: the HTML parser ends an open `<p>` before any of them.
|
|
152
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
|
|
153
|
+
*/
|
|
154
|
+
const PARAGRAPH_ENDING_TAGS = [
|
|
155
|
+
...['address', 'article', 'aside', 'blockquote', 'center', 'dd', 'details', 'dialog', 'dir'],
|
|
156
|
+
...['div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3'],
|
|
157
|
+
...['h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'li', 'listing', 'main', 'menu', 'nav', 'ol'],
|
|
158
|
+
...['p', 'plaintext', 'pre', 'search', 'section', 'summary', 'table', 'ul', 'xmp'],
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Check whether the given node is an element a paragraph can’t hold, like a `<figure>`.
|
|
163
|
+
* @param {Node} node Node.
|
|
164
|
+
* @returns {boolean} Result.
|
|
165
|
+
*/
|
|
166
|
+
const isParagraphEndingElement = (node) =>
|
|
167
|
+
isHTMLElement(node) && PARAGRAPH_ENDING_TAGS.includes(node.localName);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Check if the given node is within a `<pre>` element or an element with preformatted whitespace,
|
|
171
|
+
* whose text is imported by Lexical’s own conversion as is.
|
|
172
|
+
* @param {Node} node Node.
|
|
173
|
+
* @returns {boolean} Result.
|
|
174
|
+
*/
|
|
175
|
+
const isPreformatted = (node) => {
|
|
176
|
+
for (let element = node.parentElement; element; element = element.parentElement) {
|
|
177
|
+
if (element.localName === 'pre' || element.style.whiteSpace.startsWith('pre')) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return false;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Find the first or last text node within the given node, or the node itself if it’s a text node.
|
|
187
|
+
* @param {Node | undefined} node Node.
|
|
188
|
+
* @param {boolean} forward Whether to look for the first text node rather than the last.
|
|
189
|
+
* @returns {Text | undefined} Text node, if any.
|
|
190
|
+
*/
|
|
191
|
+
const findEdgeTextNode = (node, forward) => {
|
|
192
|
+
let current = node ?? null;
|
|
193
|
+
|
|
194
|
+
while (current && !isDOMTextNode(current)) {
|
|
195
|
+
current = forward ? current.firstChild : current.lastChild;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return current ?? undefined;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Names of the elements of the text formats, which hold nothing but text. See
|
|
203
|
+
* {@link TEXT_FORMAT_TAGS}.
|
|
204
|
+
*/
|
|
205
|
+
const TEXT_FORMAT_TAG_NAMES = TEXT_FORMAT_TAGS.map(([, tagName]) => tagName);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Check whether the given node is blank: text with nothing but whitespace, or the element of a text
|
|
209
|
+
* format, like `<strong>`, holding only such text. Any other element, like an image, a line break
|
|
210
|
+
* or a link, is content, even without any text.
|
|
211
|
+
* @param {Node} node Node.
|
|
212
|
+
* @returns {boolean} Result.
|
|
213
|
+
*/
|
|
214
|
+
const isBlank = (node) =>
|
|
215
|
+
isDOMTextNode(node)
|
|
216
|
+
? !node.data.trim()
|
|
217
|
+
: isHTMLElement(node) &&
|
|
218
|
+
TEXT_FORMAT_TAG_NAMES.includes(node.localName) &&
|
|
219
|
+
[...node.childNodes].every(isBlank);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Split the given exported paragraph around the elements it can’t hold, like the `<figure>` an
|
|
223
|
+
* inline editor component exports for an image with a caption: the HTML parser would end the `<p>`
|
|
224
|
+
* before the first one, leaving the content after it in an empty paragraph. The rest of the content
|
|
225
|
+
* stays in copies of the paragraph, which keep its alignment, while the whitespace next to such an
|
|
226
|
+
* element is dropped, as the parser collapses it at the start and end of a paragraph.
|
|
227
|
+
* @param {HTMLElement} paragraph Exported paragraph element.
|
|
228
|
+
* @returns {DocumentFragment | undefined} Paragraphs and elements to replace the paragraph with,
|
|
229
|
+
* or `undefined` if it holds no such element.
|
|
230
|
+
*/
|
|
231
|
+
const splitParagraphAroundBlocks = (paragraph) => {
|
|
232
|
+
const children = [...paragraph.childNodes];
|
|
233
|
+
|
|
234
|
+
if (!children.some(isParagraphEndingElement)) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const fragment = document.createDocumentFragment();
|
|
239
|
+
/** @type {ChildNode[]} */
|
|
240
|
+
let run = [];
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Add the content collected since the last block, if any, to the fragment in a new paragraph.
|
|
244
|
+
*/
|
|
245
|
+
const flush = () => {
|
|
246
|
+
const first = findEdgeTextNode(run[0], true);
|
|
247
|
+
const last = findEdgeTextNode(run.at(-1), false);
|
|
248
|
+
|
|
249
|
+
// Preformatted whitespace is imported as is, so it’s kept as well
|
|
250
|
+
if (first && !isPreformatted(first)) {
|
|
251
|
+
first.data = first.data.trimStart();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (last && !isPreformatted(last)) {
|
|
255
|
+
last.data = last.data.trimEnd();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (!run.every(isBlank)) {
|
|
259
|
+
const newParagraph = /** @type {HTMLElement} */ (paragraph.cloneNode(false));
|
|
260
|
+
|
|
261
|
+
newParagraph.append(...run);
|
|
262
|
+
fragment.append(newParagraph);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
run = [];
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
children.forEach((child) => {
|
|
269
|
+
if (isParagraphEndingElement(child)) {
|
|
270
|
+
flush();
|
|
271
|
+
fragment.append(child);
|
|
272
|
+
} else {
|
|
273
|
+
run.push(child);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
flush();
|
|
278
|
+
|
|
279
|
+
return fragment;
|
|
280
|
+
};
|
|
281
|
+
|
|
150
282
|
/**
|
|
151
283
|
* Export a paragraph node. Empty paragraphs at the end are left out, as they have no content; one
|
|
152
284
|
* may be added just by clicking below a block decorator. A paragraph that is the only child of a
|
|
153
|
-
* table cell is exported without the `<p>` element, unless it’s aligned.
|
|
285
|
+
* table cell is exported without the `<p>` element, unless it’s aligned. A paragraph holding
|
|
286
|
+
* elements it can’t hold, like a `<figure>`, is split around them.
|
|
154
287
|
* @param {LexicalEditor} editor Editor instance.
|
|
155
288
|
* @param {ParagraphNode} node Paragraph node.
|
|
156
289
|
* @returns {DOMExportOutput} Export output.
|
|
@@ -170,7 +303,28 @@ const exportParagraphNode = (editor, node) => {
|
|
|
170
303
|
return { element: null };
|
|
171
304
|
}
|
|
172
305
|
|
|
173
|
-
|
|
306
|
+
const { after, ...output } = exportElementNode(editor, node);
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
...output,
|
|
310
|
+
/**
|
|
311
|
+
* Clean up the paragraph once its children are in place, and split it around the elements it
|
|
312
|
+
* can’t hold, if any.
|
|
313
|
+
* @param {HTMLElement | DocumentFragment | Text | null | undefined} element Exported element.
|
|
314
|
+
* @returns {HTMLElement | DocumentFragment | Text | null | undefined} New element to replace
|
|
315
|
+
* the exported one, if any.
|
|
316
|
+
*/
|
|
317
|
+
after: (element) => {
|
|
318
|
+
const newElement = /** @type {NonNullable<DOMExportOutput['after']>} */ (after).call(
|
|
319
|
+
node,
|
|
320
|
+
element,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const target = newElement ?? element;
|
|
324
|
+
|
|
325
|
+
return (isHTMLElement(target) && splitParagraphAroundBlocks(target)) || newElement;
|
|
326
|
+
},
|
|
327
|
+
};
|
|
174
328
|
};
|
|
175
329
|
|
|
176
330
|
/**
|
|
@@ -505,22 +659,6 @@ const findContentInLine = (text, forward) => {
|
|
|
505
659
|
}
|
|
506
660
|
};
|
|
507
661
|
|
|
508
|
-
/**
|
|
509
|
-
* Check if the given node is within a `<pre>` element or an element with preformatted whitespace,
|
|
510
|
-
* whose text is imported by Lexical’s own conversion as is.
|
|
511
|
-
* @param {Node} node Node.
|
|
512
|
-
* @returns {boolean} Result.
|
|
513
|
-
*/
|
|
514
|
-
const isPreformatted = (node) => {
|
|
515
|
-
for (let element = node.parentElement; element; element = element.parentElement) {
|
|
516
|
-
if (element.localName === 'pre' || element.style.whiteSpace.startsWith('pre')) {
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return false;
|
|
522
|
-
};
|
|
523
|
-
|
|
524
662
|
/**
|
|
525
663
|
* Convert a text node, collapsing whitespace like Lexical’s own conversion does, except that an
|
|
526
664
|
* inline editor component element counts as content. See {@link findContentInLine}.
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
dialog = $bindable(),
|
|
38
38
|
class: className,
|
|
39
39
|
role = 'dialog',
|
|
40
|
+
modal = true,
|
|
40
41
|
showBackdrop = false,
|
|
41
42
|
lightDismiss = false,
|
|
42
43
|
escapeDismiss = true,
|
|
@@ -62,6 +63,19 @@
|
|
|
62
63
|
dialog?.focus();
|
|
63
64
|
};
|
|
64
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Show the `<dialog>` element, as a modal unless {@link modal} is disabled. A non-modal dialog
|
|
68
|
+
* leaves the rest of the page usable: it isn’t put in the top layer and doesn’t make the page
|
|
69
|
+
* `inert`.
|
|
70
|
+
*/
|
|
71
|
+
const showDialog = () => {
|
|
72
|
+
if (modal) {
|
|
73
|
+
dialog?.showModal();
|
|
74
|
+
} else {
|
|
75
|
+
dialog?.show();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
65
79
|
/**
|
|
66
80
|
* Close the modal.
|
|
67
81
|
* @param {string} returnValue Return value to be used for `<dialog>`.
|
|
@@ -268,7 +282,7 @@
|
|
|
268
282
|
|
|
269
283
|
if (gen !== generation || !dialog || dialog.open) return;
|
|
270
284
|
|
|
271
|
-
|
|
285
|
+
showDialog();
|
|
272
286
|
onOpen?.(new CustomEvent('Open'));
|
|
273
287
|
// Force a style recalculation, so the browser has a state to transition from. This is required
|
|
274
288
|
// because the element may have just been added to the DOM tree.
|
|
@@ -410,6 +424,7 @@
|
|
|
410
424
|
{role}
|
|
411
425
|
class="sui modal {className}"
|
|
412
426
|
class:backdrop={showBackdrop}
|
|
427
|
+
class:non-modal={!modal}
|
|
413
428
|
class:open={setOpenClass}
|
|
414
429
|
class:active={setActiveClass}
|
|
415
430
|
onpointerdown={({ target }) => {
|
|
@@ -425,22 +440,30 @@
|
|
|
425
440
|
return;
|
|
426
441
|
}
|
|
427
442
|
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
443
|
+
if (lightDismiss && /** @type {HTMLElement | undefined} */ (target)?.matches('dialog')) {
|
|
444
|
+
close('cancel');
|
|
445
|
+
}
|
|
446
|
+
}}
|
|
447
|
+
onkeydown={(event) => {
|
|
448
|
+
// A non-modal dialog gets no `cancel` event from the browser when Escape is pressed, so the
|
|
449
|
+
// key is handled here instead, as long as the focus is within the dialog. Escape that
|
|
450
|
+
// cancels an IME composition is left to the input method, as the browser does for a modal
|
|
451
|
+
if (modal || event.key !== 'Escape' || event.isComposing || event.defaultPrevented) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
|
|
457
|
+
if (escapeDismiss) {
|
|
458
|
+
close('cancel');
|
|
435
459
|
}
|
|
436
460
|
}}
|
|
437
461
|
oncancel={(event) => {
|
|
438
462
|
event.preventDefault();
|
|
439
463
|
|
|
440
464
|
// Escape key is pressed
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
open = false;
|
|
465
|
+
if (escapeDismiss) {
|
|
466
|
+
close('cancel');
|
|
444
467
|
}
|
|
445
468
|
}}
|
|
446
469
|
onclose={() => {
|
|
@@ -454,7 +477,7 @@
|
|
|
454
477
|
// activation in between. Show the dialog again if it shouldn’t be dismissed with Escape,
|
|
455
478
|
// otherwise bring the state in line, so the usual closing steps run.
|
|
456
479
|
if (!escapeDismiss) {
|
|
457
|
-
|
|
480
|
+
showDialog();
|
|
458
481
|
} else {
|
|
459
482
|
open = false;
|
|
460
483
|
}
|
|
@@ -496,6 +519,12 @@ dialog::backdrop {
|
|
|
496
519
|
dialog.backdrop {
|
|
497
520
|
background-color: var(--sui-popup-backdrop-color);
|
|
498
521
|
}
|
|
522
|
+
dialog.non-modal {
|
|
523
|
+
pointer-events: none;
|
|
524
|
+
}
|
|
525
|
+
dialog.non-modal.active > :global(*) {
|
|
526
|
+
pointer-events: auto;
|
|
527
|
+
}
|
|
499
528
|
dialog.open {
|
|
500
529
|
transition-duration: 50ms;
|
|
501
530
|
opacity: 1;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Dialog action button labels
|
|
2
|
+
ok: OK
|
|
3
|
+
cancel: Cancelar
|
|
4
|
+
close: Cerrar
|
|
5
|
+
|
|
6
|
+
# Button to clear content, e.g. search input or calendar date
|
|
7
|
+
clear: Limpiar
|
|
8
|
+
|
|
9
|
+
# Text editor dialog buttons for link/image insertion
|
|
10
|
+
insert: Insertar
|
|
11
|
+
update: Actualizar
|
|
12
|
+
remove: Quitar
|
|
13
|
+
|
|
14
|
+
# Combobox dropdown toggle button aria-labels
|
|
15
|
+
collapse: Contraer
|
|
16
|
+
expand: Expandir
|
|
17
|
+
|
|
18
|
+
# Infobar/toast dismiss button label
|
|
19
|
+
dismiss: Descartar
|
|
20
|
+
|
|
21
|
+
# Alert & infobar status, read out by screen readers before the message (visually hidden)
|
|
22
|
+
alert:
|
|
23
|
+
error: Error
|
|
24
|
+
warning: Advertencia
|
|
25
|
+
info: Información
|
|
26
|
+
success: Éxito
|
|
27
|
+
|
|
28
|
+
# Role descriptions, read out by screen readers in place of the generic “group” role
|
|
29
|
+
role_descriptions:
|
|
30
|
+
disclosure: sección desplegable
|
|
31
|
+
option_group: grupo de opciones
|
|
32
|
+
menu_item_group: grupo de elementos de menú
|
|
33
|
+
checkbox_group: grupo de casillas de verificación
|
|
34
|
+
table_head: encabezado de tabla
|
|
35
|
+
table_body: cuerpo de tabla
|
|
36
|
+
table_foot: pie de tabla
|
|
37
|
+
grid_head: encabezado de cuadrícula
|
|
38
|
+
grid_body: cuerpo de cuadrícula
|
|
39
|
+
grid_foot: pie de cuadrícula
|
|
40
|
+
|
|
41
|
+
# Emoji suggestion listbox aria-label, shared by the text fields and the text editor
|
|
42
|
+
emoji_suggestions: Sugerencias de emojis
|
|
43
|
+
|
|
44
|
+
# Calendar component
|
|
45
|
+
calendar:
|
|
46
|
+
# View switcher group aria-labels and navigation button aria-labels
|
|
47
|
+
year: Año
|
|
48
|
+
previous_decade: Década anterior
|
|
49
|
+
next_decade: Década siguiente
|
|
50
|
+
month: Mes
|
|
51
|
+
previous_month: Mes anterior
|
|
52
|
+
next_month: Mes siguiente
|
|
53
|
+
# “Today” button label in footer
|
|
54
|
+
today: Hoy
|
|
55
|
+
|
|
56
|
+
# Split button component
|
|
57
|
+
split_button:
|
|
58
|
+
# Wrapper aria-label, e.g. “Save Options” when primary button is “Save”
|
|
59
|
+
x_options: Opciones de {$name}
|
|
60
|
+
# Dropdown toggle aria-label
|
|
61
|
+
more_options: Más opciones
|
|
62
|
+
|
|
63
|
+
# Combobox component
|
|
64
|
+
combobox:
|
|
65
|
+
# Placeholder when no option is selected
|
|
66
|
+
select_an_option: Selecciona una opción…
|
|
67
|
+
# Filter input aria-label
|
|
68
|
+
filter_options: Filtrar opciones
|
|
69
|
+
# Empty state message when filter has no matches
|
|
70
|
+
no_matching_options: No se han encontrado opciones que coincidan
|
|
71
|
+
|
|
72
|
+
# Number input component
|
|
73
|
+
number_input:
|
|
74
|
+
# Spin button aria-labels for incrementing/decrementing the number value
|
|
75
|
+
increase: Aumentar
|
|
76
|
+
decrease: Disminuir
|
|
77
|
+
# Description of the allowed range when the number can’t be stepped, e.g. “From 1 to 10”
|
|
78
|
+
range: De {$min} a {$max}
|
|
79
|
+
# Description of the minimum value when the number can’t be stepped
|
|
80
|
+
min: Mínimo {$min}
|
|
81
|
+
# Description of the maximum value when the number can’t be stepped
|
|
82
|
+
max: Máximo {$max}
|
|
83
|
+
|
|
84
|
+
# Password input component
|
|
85
|
+
password_input:
|
|
86
|
+
# Visibility toggle button aria-labels
|
|
87
|
+
show_password: Mostrar la contraseña
|
|
88
|
+
hide_password: Ocultar la contraseña
|
|
89
|
+
|
|
90
|
+
# Secret input component (API keys, tokens, etc.)
|
|
91
|
+
secret_input:
|
|
92
|
+
# Visibility toggle button aria-labels
|
|
93
|
+
show_secret: Mostrar el secreto
|
|
94
|
+
hide_secret: Ocultar el secreto
|
|
95
|
+
|
|
96
|
+
# Select tags component (multi-select)
|
|
97
|
+
select_tags:
|
|
98
|
+
# Listbox aria-label
|
|
99
|
+
selected_options: Opciones seleccionadas
|
|
100
|
+
# Remove button aria-label, e.g. “Remove Option 1”
|
|
101
|
+
remove_x: Quitar {$name}
|
|
102
|
+
|
|
103
|
+
# Text editor component
|
|
104
|
+
text_editor:
|
|
105
|
+
# Toolbar aria-labels
|
|
106
|
+
text_editor: Editor de texto
|
|
107
|
+
code_editor: Editor de código
|
|
108
|
+
# Block style menu button and menu aria-labels
|
|
109
|
+
text_style_options: Opciones de estilo de texto
|
|
110
|
+
show_text_style_options: Mostrar las opciones de estilo de texto
|
|
111
|
+
# Block style menu items
|
|
112
|
+
paragraph: Párrafo
|
|
113
|
+
heading_1: Encabezado 1
|
|
114
|
+
heading_2: Encabezado 2
|
|
115
|
+
heading_3: Encabezado 3
|
|
116
|
+
heading_4: Encabezado 4
|
|
117
|
+
heading_5: Encabezado 5
|
|
118
|
+
heading_6: Encabezado 6
|
|
119
|
+
bulleted_list: Lista con viñetas
|
|
120
|
+
numbered_list: Lista numerada
|
|
121
|
+
blockquote: Cita
|
|
122
|
+
code_block: Bloque de código
|
|
123
|
+
# Inline style button aria-labels
|
|
124
|
+
bold: Negrita
|
|
125
|
+
italic: Cursiva
|
|
126
|
+
strikethrough: Tachado
|
|
127
|
+
code: Código
|
|
128
|
+
link: Enlace
|
|
129
|
+
# Link dialog title
|
|
130
|
+
insert_link: Insertar enlace
|
|
131
|
+
# Floating link editor button aria-labels
|
|
132
|
+
edit_link: Editar enlace
|
|
133
|
+
remove_link: Quitar enlace
|
|
134
|
+
# Link dialog input field labels
|
|
135
|
+
text: Texto
|
|
136
|
+
url: URL
|
|
137
|
+
# Link dialog checkbox label and floating link editor button aria-label
|
|
138
|
+
open_in_new_tab: Abrir en una pestaña nueva
|
|
139
|
+
# Table dialog title
|
|
140
|
+
insert_table: Insertar tabla
|
|
141
|
+
# Table dialog input field labels
|
|
142
|
+
rows: Filas
|
|
143
|
+
columns: Columnas
|
|
144
|
+
# Table menu button and menu aria-labels
|
|
145
|
+
table_options: Opciones de tabla
|
|
146
|
+
show_table_options: Mostrar las opciones de tabla
|
|
147
|
+
# Table menu items
|
|
148
|
+
insert_row_above: Insertar fila arriba
|
|
149
|
+
insert_row_below: Insertar fila abajo
|
|
150
|
+
insert_column_left: Insertar columna a la izquierda
|
|
151
|
+
insert_column_right: Insertar columna a la derecha
|
|
152
|
+
delete_row: Eliminar fila
|
|
153
|
+
delete_column: Eliminar columna
|
|
154
|
+
delete_table: Eliminar tabla
|
|
155
|
+
# Horizontal rule button aria-label
|
|
156
|
+
insert_horizontal_rule: Insertar línea horizontal
|
|
157
|
+
# Alignment menu button and menu aria-labels
|
|
158
|
+
alignment_options: Opciones de alineación
|
|
159
|
+
show_alignment_options: Mostrar las opciones de alineación
|
|
160
|
+
# Alignment menu items
|
|
161
|
+
align_left: Alinear a la izquierda
|
|
162
|
+
align_center: Centrar
|
|
163
|
+
align_right: Alinear a la derecha
|
|
164
|
+
align_justify: Justificar
|
|
165
|
+
# Markdown mode toggle button aria-label
|
|
166
|
+
edit_in_markdown: Editar en Markdown
|
|
167
|
+
# HTML mode toggle button aria-label
|
|
168
|
+
edit_in_html: Editar en HTML
|
|
169
|
+
# Error message when rich text conversion fails
|
|
170
|
+
converter_error: No se ha podido activar el modo de texto enriquecido. Usa el editor de texto sin formato en su lugar.
|
|
171
|
+
# Language selector aria-label
|
|
172
|
+
language: Idioma
|
|
173
|
+
# Plain text mode option in language selector
|
|
174
|
+
plain_text: Texto sin formato
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -141,7 +141,16 @@ export type ModalProps = {
|
|
|
141
141
|
*/
|
|
142
142
|
open?: boolean | undefined;
|
|
143
143
|
/**
|
|
144
|
-
* Whether to show the
|
|
144
|
+
* Whether to show the `<dialog>` element as a modal, which makes the
|
|
145
|
+
* rest of the page `inert` until it’s closed. Default: `true`. If `false`, the page can still be
|
|
146
|
+
* scrolled and used while the dialog is open, and the Escape key only dismisses the dialog while
|
|
147
|
+
* the focus is within it. `lightDismiss` has no effect then, as clicks outside the content go to
|
|
148
|
+
* the page.
|
|
149
|
+
*/
|
|
150
|
+
modal?: boolean | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Whether to show the backdrop. Default: `false` on a bare
|
|
153
|
+
* modal; components built on it, like `<Dialog>`, may choose another.
|
|
145
154
|
*/
|
|
146
155
|
showBackdrop?: boolean | undefined;
|
|
147
156
|
/**
|
|
@@ -230,6 +239,24 @@ export type DialogProps = {
|
|
|
230
239
|
* Whether to open the dialog.
|
|
231
240
|
*/
|
|
232
241
|
open?: boolean | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Whether to open the dialog as a modal, which makes the rest of the
|
|
244
|
+
* page `inert` and dims it with a backdrop. Default: `true`. If `false`, the page can still be
|
|
245
|
+
* scrolled and used while the dialog is open, so the user can refer to it before answering.
|
|
246
|
+
*/
|
|
247
|
+
modal?: boolean | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Whether to dim the page behind the dialog. Default: the value
|
|
250
|
+
* of `modal`. A non-modal dialog can have one as well to make it stand out, while the page behind
|
|
251
|
+
* it can still be scrolled and used.
|
|
252
|
+
*/
|
|
253
|
+
showBackdrop?: boolean | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Whether the user can move the dialog around by dragging its header,
|
|
256
|
+
* so as to see what’s behind it. The dialog is kept within the viewport, and goes back to the
|
|
257
|
+
* center whenever it’s opened or the viewport is resized. Default: `false`.
|
|
258
|
+
*/
|
|
259
|
+
movable?: boolean | undefined;
|
|
233
260
|
/**
|
|
234
261
|
* Whether to show the Close button on the header.
|
|
235
262
|
*/
|
package/dist/typedefs.js
CHANGED
|
@@ -53,7 +53,13 @@
|
|
|
53
53
|
* @property {'dialog' | 'alertdialog' | 'none'} [role] The `role` attribute on the `<dialog>`
|
|
54
54
|
* element.
|
|
55
55
|
* @property {boolean} [open] Whether to show the modal.
|
|
56
|
-
* @property {boolean} [
|
|
56
|
+
* @property {boolean} [modal] Whether to show the `<dialog>` element as a modal, which makes the
|
|
57
|
+
* rest of the page `inert` until it’s closed. Default: `true`. If `false`, the page can still be
|
|
58
|
+
* scrolled and used while the dialog is open, and the Escape key only dismisses the dialog while
|
|
59
|
+
* the focus is within it. `lightDismiss` has no effect then, as clicks outside the content go to
|
|
60
|
+
* the page.
|
|
61
|
+
* @property {boolean} [showBackdrop] Whether to show the backdrop. Default: `false` on a bare
|
|
62
|
+
* modal; components built on it, like `<Dialog>`, may choose another.
|
|
57
63
|
* @property {boolean} [lightDismiss] Whether to close the modal when the backdrop (outside of the
|
|
58
64
|
* modal) is clicked.
|
|
59
65
|
* @property {boolean} [escapeDismiss] Whether to close the modal when the Escape key is pressed.
|
|
@@ -85,6 +91,15 @@
|
|
|
85
91
|
* @property {'x-small' | 'small' | 'medium' | 'large' | 'x-large'} [size] Width of the dialog.
|
|
86
92
|
* @property {string} [class] The `class` attribute on the `<dialog>` element.
|
|
87
93
|
* @property {boolean} [open] Whether to open the dialog.
|
|
94
|
+
* @property {boolean} [modal] Whether to open the dialog as a modal, which makes the rest of the
|
|
95
|
+
* page `inert` and dims it with a backdrop. Default: `true`. If `false`, the page can still be
|
|
96
|
+
* scrolled and used while the dialog is open, so the user can refer to it before answering.
|
|
97
|
+
* @property {boolean} [showBackdrop] Whether to dim the page behind the dialog. Default: the value
|
|
98
|
+
* of `modal`. A non-modal dialog can have one as well to make it stand out, while the page behind
|
|
99
|
+
* it can still be scrolled and used.
|
|
100
|
+
* @property {boolean} [movable] Whether the user can move the dialog around by dragging its header,
|
|
101
|
+
* so as to see what’s behind it. The dialog is kept within the viewport, and goes back to the
|
|
102
|
+
* center whenever it’s opened or the viewport is resized. Default: `false`.
|
|
88
103
|
* @property {boolean} [showClose] Whether to show the Close button on the header.
|
|
89
104
|
* @property {boolean} [showOk] Whether to show the OK button on the footer.
|
|
90
105
|
* @property {boolean} [showCancel] Whether to show the Cancel button on the footer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"description": "A collection of Svelte components and utilities for building user interfaces.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@fontsource-variable/source-sans-3": "5.3.1",
|
|
71
71
|
"@fontsource/noto-mono": "5.3.0",
|
|
72
72
|
"@rollup/plugin-yaml": "^5.0.1",
|
|
73
|
-
"@sveltejs/adapter-auto": "^8.0.
|
|
74
|
-
"@sveltejs/kit": "^3.
|
|
73
|
+
"@sveltejs/adapter-auto": "^8.0.1",
|
|
74
|
+
"@sveltejs/kit": "^3.2.0",
|
|
75
75
|
"@sveltejs/package": "^3.0.2",
|
|
76
76
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
77
77
|
"@vitest/browser-playwright": "^5.1.0",
|
|
@@ -91,19 +91,19 @@
|
|
|
91
91
|
"playwright": "^1.65.0",
|
|
92
92
|
"postcss": "^8.5.32",
|
|
93
93
|
"postcss-html": "^2.0.0",
|
|
94
|
-
"prettier": "^3.
|
|
94
|
+
"prettier": "^3.10.1",
|
|
95
95
|
"prettier-plugin-svelte": "^4.1.1",
|
|
96
|
-
"rolldown": "^1.3.
|
|
97
|
-
"sass": "^1.108.
|
|
96
|
+
"rolldown": "^1.3.2",
|
|
97
|
+
"sass": "^1.108.2",
|
|
98
98
|
"shiki": "^4.6.0",
|
|
99
99
|
"stylelint": "^18.0.0",
|
|
100
|
-
"stylelint-config-recommended-scss": "^
|
|
101
|
-
"stylelint-scss": "^7.
|
|
100
|
+
"stylelint-config-recommended-scss": "^18.0.0",
|
|
101
|
+
"stylelint-scss": "^7.5.0",
|
|
102
102
|
"svelte": "^5.57.3",
|
|
103
103
|
"svelte-check": "^4.7.8",
|
|
104
104
|
"svelte-preprocess": "^6.0.5",
|
|
105
105
|
"tslib": "^2.9.1",
|
|
106
|
-
"vite": "^8.3.
|
|
106
|
+
"vite": "^8.3.8",
|
|
107
107
|
"vitest": "^5.1.0",
|
|
108
108
|
"vitest-browser-svelte": "^3.1.0"
|
|
109
109
|
},
|