@coyalabs/bts-style 1.3.14 → 1.3.17
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 +58 -8
- package/dist/Base/BaseText.svelte +6 -5
- package/dist/Components/ContextMenu.svelte +175 -29
- package/dist/Components/InputBox.svelte +241 -18
- package/dist/Components/InputBox.svelte.d.ts +23 -1
- package/dist/Components/Popup/AlertPopup.svelte +8 -0
- package/dist/Components/Popup/AlertPopup.svelte.d.ts +11 -1
- package/dist/Components/Popup/ConfirmPopup.svelte +8 -0
- package/dist/Components/Popup/ConfirmPopup.svelte.d.ts +11 -1
- package/dist/Components/Popup/Popup.svelte +90 -3
- package/dist/Components/Popup/PromptPopup.svelte +16 -1
- package/dist/Components/Popup/PromptPopup.svelte.d.ts +15 -1
- package/dist/Components/Popup/popupStore.d.ts +12 -0
- package/dist/Components/Popup/popupStore.js +57 -29
- package/dist/Components/ScrollContainer.svelte +88 -3
- package/dist/Components/ScrollContainer.svelte.d.ts +2 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.js +2 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { onMount, tick } from 'svelte';
|
|
2
3
|
import BaseContainer from '../Base/BaseContainer.svelte';
|
|
3
4
|
import BaseIcon from '../Base/BaseIcon.svelte';
|
|
4
5
|
import { icons } from '../icons.js';
|
|
@@ -28,6 +29,35 @@
|
|
|
28
29
|
*/
|
|
29
30
|
export let type = 'text';
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @type {boolean}
|
|
34
|
+
*/
|
|
35
|
+
export let multiline = false;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @type {number}
|
|
39
|
+
*/
|
|
40
|
+
export let rows = 4;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Keep multiline inputs visually compact (1 row) until the value contains a newline.
|
|
44
|
+
* @type {boolean}
|
|
45
|
+
*/
|
|
46
|
+
export let expandOnNewline = false;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* When enabled for multiline inputs, plain Enter submits the nearest form
|
|
50
|
+
* or falls through to parent handlers, while Ctrl+Enter and Shift+Enter
|
|
51
|
+
* insert a newline.
|
|
52
|
+
* @type {boolean}
|
|
53
|
+
*/
|
|
54
|
+
export let newlineOnCtrlEnter = false;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @type {'none' | 'both' | 'horizontal' | 'vertical'}
|
|
58
|
+
*/
|
|
59
|
+
export let resize = 'vertical';
|
|
60
|
+
|
|
31
61
|
/**
|
|
32
62
|
* @type {string | null}
|
|
33
63
|
*/
|
|
@@ -62,27 +92,148 @@
|
|
|
62
92
|
* @type {boolean}
|
|
63
93
|
*/
|
|
64
94
|
export let autofocus = false;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type {boolean}
|
|
98
|
+
*/
|
|
99
|
+
export let disabled = false;
|
|
100
|
+
|
|
101
|
+
/** @type {HTMLInputElement | HTMLTextAreaElement | null} */
|
|
102
|
+
let inputRef = null;
|
|
103
|
+
|
|
104
|
+
let mounted = false;
|
|
105
|
+
|
|
106
|
+
let hasExplicitNewline = false;
|
|
107
|
+
|
|
108
|
+
/** @type {number | null} */
|
|
109
|
+
let focusFrame = null;
|
|
110
|
+
|
|
111
|
+
function clearScheduledFocus() {
|
|
112
|
+
if (focusFrame !== null) {
|
|
113
|
+
cancelAnimationFrame(focusFrame);
|
|
114
|
+
focusFrame = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function scheduleFocus() {
|
|
119
|
+
if (!autofocus || disabled || !inputRef) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
clearScheduledFocus();
|
|
124
|
+
void tick().then(() => {
|
|
125
|
+
focusFrame = requestAnimationFrame(() => {
|
|
126
|
+
focusFrame = null;
|
|
127
|
+
inputRef?.focus({ preventScroll: true });
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onMount(() => {
|
|
133
|
+
mounted = true;
|
|
134
|
+
scheduleFocus();
|
|
135
|
+
|
|
136
|
+
return () => {
|
|
137
|
+
clearScheduledFocus();
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
$: hasExplicitNewline = typeof value === 'string' && value.includes('\n');
|
|
142
|
+
$: effectiveRows = expandOnNewline && !hasExplicitNewline ? 1 : rows;
|
|
143
|
+
|
|
144
|
+
$: if (mounted && autofocus && inputRef) {
|
|
145
|
+
scheduleFocus();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function focus() {
|
|
149
|
+
if (disabled) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
inputRef?.focus({ preventScroll: true });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function blur() {
|
|
157
|
+
inputRef?.blur();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {HTMLTextAreaElement} node
|
|
162
|
+
* @param {boolean} enabled
|
|
163
|
+
*/
|
|
164
|
+
function ctrlEnterNewline(node, enabled) {
|
|
165
|
+
let isEnabled = enabled;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @param {KeyboardEvent} event
|
|
169
|
+
*/
|
|
170
|
+
function handleKeydown(event) {
|
|
171
|
+
if (!isEnabled || event.key !== 'Enter' || event.isComposing || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
node.form?.requestSubmit();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
node.addEventListener('keydown', handleKeydown);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
update(/** @type {boolean} */ nextEnabled) {
|
|
183
|
+
isEnabled = nextEnabled;
|
|
184
|
+
},
|
|
185
|
+
destroy() {
|
|
186
|
+
node.removeEventListener('keydown', handleKeydown);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
65
190
|
</script>
|
|
66
191
|
|
|
67
|
-
<div class="input-wrapper">
|
|
192
|
+
<div class="input-wrapper" class:disabled>
|
|
68
193
|
<BaseContainer {theme} {borderRadiusTopLeft} {borderRadiusTopRight} {borderRadiusBottomLeft} {borderRadiusBottomRight}>
|
|
69
|
-
<div class="input-content">
|
|
194
|
+
<div class="input-content" class:multiline class:multiline-expanded={multiline && effectiveRows > 1}>
|
|
70
195
|
{#if icon}
|
|
71
|
-
<
|
|
196
|
+
<div class="icon-wrapper">
|
|
197
|
+
<BaseIcon variant="toned" svg={icon} size={iconSize} />
|
|
198
|
+
</div>
|
|
72
199
|
{/if}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
200
|
+
{#if multiline}
|
|
201
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
202
|
+
<textarea
|
|
203
|
+
bind:this={inputRef}
|
|
204
|
+
use:ctrlEnterNewline={newlineOnCtrlEnter}
|
|
205
|
+
data-newline-on-ctrl-enter={newlineOnCtrlEnter ? 'true' : undefined}
|
|
206
|
+
{placeholder}
|
|
207
|
+
bind:value
|
|
208
|
+
rows={effectiveRows}
|
|
209
|
+
autofocus={autofocus}
|
|
210
|
+
{disabled}
|
|
211
|
+
style={`resize: ${resize};`}
|
|
212
|
+
on:input
|
|
213
|
+
on:change
|
|
214
|
+
on:focus
|
|
215
|
+
on:blur
|
|
216
|
+
on:keydown
|
|
217
|
+
></textarea>
|
|
218
|
+
{:else}
|
|
219
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
220
|
+
<input
|
|
221
|
+
bind:this={inputRef}
|
|
222
|
+
{type}
|
|
223
|
+
{placeholder}
|
|
224
|
+
bind:value
|
|
225
|
+
autofocus={autofocus}
|
|
226
|
+
{disabled}
|
|
227
|
+
on:input
|
|
228
|
+
on:change
|
|
229
|
+
on:focus
|
|
230
|
+
on:blur
|
|
231
|
+
on:keydown
|
|
232
|
+
/>
|
|
233
|
+
{/if}
|
|
234
|
+
<div class="icon-wrapper">
|
|
235
|
+
<BaseIcon variant="toned" svg={icons.pen} size="15px" />
|
|
236
|
+
</div>
|
|
86
237
|
</div>
|
|
87
238
|
</BaseContainer>
|
|
88
239
|
</div>
|
|
@@ -92,16 +243,36 @@
|
|
|
92
243
|
width: 100%;
|
|
93
244
|
}
|
|
94
245
|
|
|
246
|
+
.input-wrapper.disabled {
|
|
247
|
+
opacity: 0.7;
|
|
248
|
+
pointer-events: none;
|
|
249
|
+
filter: saturate(0%);
|
|
250
|
+
}
|
|
251
|
+
|
|
95
252
|
.input-content {
|
|
96
253
|
display: flex;
|
|
97
254
|
align-items: center;
|
|
98
255
|
gap: 8px;
|
|
99
|
-
height: 25px;
|
|
256
|
+
min-height: 25px;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.input-content.multiline-expanded {
|
|
260
|
+
align-items: flex-start;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.icon-wrapper {
|
|
264
|
+
flex-shrink: 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.input-content.multiline-expanded .icon-wrapper {
|
|
268
|
+
margin-top: 0.2rem;
|
|
100
269
|
}
|
|
101
270
|
|
|
102
271
|
input {
|
|
103
272
|
all: unset;
|
|
273
|
+
display: block;
|
|
104
274
|
flex: 1;
|
|
275
|
+
min-width: 0;
|
|
105
276
|
font-family: 'Noto Serif KR', serif;
|
|
106
277
|
font-weight: 900;
|
|
107
278
|
font-size: 17px;
|
|
@@ -109,7 +280,59 @@
|
|
|
109
280
|
width: 100%;
|
|
110
281
|
}
|
|
111
282
|
|
|
112
|
-
|
|
283
|
+
textarea {
|
|
284
|
+
/* Don't use `all: unset` — Firefox drops intrinsic sizing so `rows` stops working. */
|
|
285
|
+
display: block;
|
|
286
|
+
flex: 1;
|
|
287
|
+
min-width: 0;
|
|
288
|
+
font-family: 'Noto Serif KR', serif;
|
|
289
|
+
font-weight: 900;
|
|
290
|
+
font-size: 17px;
|
|
291
|
+
color: #E3D8D8;
|
|
292
|
+
width: 100%;
|
|
293
|
+
line-height: 1.45;
|
|
294
|
+
min-height: 1.45em;
|
|
295
|
+
white-space: pre-wrap;
|
|
296
|
+
overflow-wrap: break-word;
|
|
297
|
+
margin: 0;
|
|
298
|
+
padding: 0;
|
|
299
|
+
border: none;
|
|
300
|
+
background: transparent;
|
|
301
|
+
outline: none;
|
|
302
|
+
box-shadow: none;
|
|
303
|
+
appearance: none;
|
|
304
|
+
field-sizing: content;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
textarea::-webkit-resizer {
|
|
308
|
+
background: transparent;
|
|
309
|
+
border: none;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
textarea::-webkit-scrollbar-corner {
|
|
313
|
+
background: transparent;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
textarea::-webkit-scrollbar {
|
|
317
|
+
width: 8px;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
textarea::-webkit-scrollbar-track {
|
|
321
|
+
background: rgba(227, 216, 216, 0.05);
|
|
322
|
+
border-radius: 4px;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
textarea::-webkit-scrollbar-thumb {
|
|
326
|
+
background: rgba(227, 216, 216, 0.2);
|
|
327
|
+
border-radius: 4px;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
textarea::-webkit-scrollbar-thumb:hover {
|
|
331
|
+
background: rgba(227, 216, 216, 0.3);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
input::placeholder,
|
|
335
|
+
textarea::placeholder {
|
|
113
336
|
color: rgba(227, 216, 216, 0.4);
|
|
114
337
|
}
|
|
115
338
|
</style>
|
|
@@ -6,10 +6,18 @@ type InputBox = SvelteComponent<{
|
|
|
6
6
|
borderRadiusBottomLeft?: string | undefined;
|
|
7
7
|
borderRadiusBottomRight?: string | undefined;
|
|
8
8
|
icon?: string | null | undefined;
|
|
9
|
+
blur?: (() => void) | undefined;
|
|
10
|
+
focus?: (() => void) | undefined;
|
|
11
|
+
resize?: "none" | "both" | "horizontal" | "vertical" | undefined;
|
|
9
12
|
iconSize?: string | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
10
14
|
value?: string | undefined;
|
|
11
15
|
placeholder?: string | undefined;
|
|
12
16
|
type?: string | undefined;
|
|
17
|
+
multiline?: boolean | undefined;
|
|
18
|
+
rows?: number | undefined;
|
|
19
|
+
expandOnNewline?: boolean | undefined;
|
|
20
|
+
newlineOnCtrlEnter?: boolean | undefined;
|
|
13
21
|
autofocus?: boolean | undefined;
|
|
14
22
|
}, {
|
|
15
23
|
input: Event;
|
|
@@ -21,6 +29,9 @@ type InputBox = SvelteComponent<{
|
|
|
21
29
|
[evt: string]: CustomEvent<any>;
|
|
22
30
|
}, {}> & {
|
|
23
31
|
$$bindings?: string | undefined;
|
|
32
|
+
} & {
|
|
33
|
+
focus: () => void;
|
|
34
|
+
blur: () => void;
|
|
24
35
|
};
|
|
25
36
|
declare const InputBox: $$__sveltets_2_IsomorphicComponent<{
|
|
26
37
|
theme?: import("../Base/variantTypes.js").BaseContainerVariant | undefined;
|
|
@@ -29,10 +40,18 @@ declare const InputBox: $$__sveltets_2_IsomorphicComponent<{
|
|
|
29
40
|
borderRadiusBottomLeft?: string | undefined;
|
|
30
41
|
borderRadiusBottomRight?: string | undefined;
|
|
31
42
|
icon?: string | null | undefined;
|
|
43
|
+
blur?: (() => void) | undefined;
|
|
44
|
+
focus?: (() => void) | undefined;
|
|
45
|
+
resize?: "none" | "both" | "horizontal" | "vertical" | undefined;
|
|
32
46
|
iconSize?: string | undefined;
|
|
47
|
+
disabled?: boolean | undefined;
|
|
33
48
|
value?: string | undefined;
|
|
34
49
|
placeholder?: string | undefined;
|
|
35
50
|
type?: string | undefined;
|
|
51
|
+
multiline?: boolean | undefined;
|
|
52
|
+
rows?: number | undefined;
|
|
53
|
+
expandOnNewline?: boolean | undefined;
|
|
54
|
+
newlineOnCtrlEnter?: boolean | undefined;
|
|
36
55
|
autofocus?: boolean | undefined;
|
|
37
56
|
}, {
|
|
38
57
|
input: Event;
|
|
@@ -42,7 +61,10 @@ declare const InputBox: $$__sveltets_2_IsomorphicComponent<{
|
|
|
42
61
|
keydown: KeyboardEvent;
|
|
43
62
|
} & {
|
|
44
63
|
[evt: string]: CustomEvent<any>;
|
|
45
|
-
}, {}, {
|
|
64
|
+
}, {}, {
|
|
65
|
+
focus: () => void;
|
|
66
|
+
blur: () => void;
|
|
67
|
+
}, string>;
|
|
46
68
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
47
69
|
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
48
70
|
$$bindings?: Bindings;
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
export default AlertPopup;
|
|
2
2
|
type AlertPopup = SvelteComponent<{
|
|
3
|
+
cancel?: (() => void) | undefined;
|
|
4
|
+
confirm?: (() => void) | undefined;
|
|
3
5
|
onOk?: (() => void) | undefined;
|
|
4
6
|
okText?: string | undefined;
|
|
5
7
|
}, {
|
|
6
8
|
[evt: string]: CustomEvent<any>;
|
|
7
9
|
}, {}> & {
|
|
8
10
|
$$bindings?: string | undefined;
|
|
11
|
+
} & {
|
|
12
|
+
confirm: () => void;
|
|
13
|
+
cancel: () => void;
|
|
9
14
|
};
|
|
10
15
|
declare const AlertPopup: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
cancel?: (() => void) | undefined;
|
|
17
|
+
confirm?: (() => void) | undefined;
|
|
11
18
|
onOk?: (() => void) | undefined;
|
|
12
19
|
okText?: string | undefined;
|
|
13
20
|
}, {
|
|
14
21
|
[evt: string]: CustomEvent<any>;
|
|
15
|
-
}, {}, {
|
|
22
|
+
}, {}, {
|
|
23
|
+
confirm: () => void;
|
|
24
|
+
cancel: () => void;
|
|
25
|
+
}, string>;
|
|
16
26
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
17
27
|
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
18
28
|
$$bindings?: Bindings;
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
export default ConfirmPopup;
|
|
2
2
|
type ConfirmPopup = SvelteComponent<{
|
|
3
|
+
cancel?: (() => void) | undefined;
|
|
3
4
|
onConfirm?: (() => void) | undefined;
|
|
4
5
|
onCancel?: (() => void) | undefined;
|
|
5
6
|
confirmText?: string | undefined;
|
|
6
7
|
cancelText?: string | undefined;
|
|
8
|
+
confirm?: (() => void) | undefined;
|
|
7
9
|
}, {
|
|
8
10
|
[evt: string]: CustomEvent<any>;
|
|
9
11
|
}, {}> & {
|
|
10
12
|
$$bindings?: string | undefined;
|
|
13
|
+
} & {
|
|
14
|
+
confirm: () => void;
|
|
15
|
+
cancel: () => void;
|
|
11
16
|
};
|
|
12
17
|
declare const ConfirmPopup: $$__sveltets_2_IsomorphicComponent<{
|
|
18
|
+
cancel?: (() => void) | undefined;
|
|
13
19
|
onConfirm?: (() => void) | undefined;
|
|
14
20
|
onCancel?: (() => void) | undefined;
|
|
15
21
|
confirmText?: string | undefined;
|
|
16
22
|
cancelText?: string | undefined;
|
|
23
|
+
confirm?: (() => void) | undefined;
|
|
17
24
|
}, {
|
|
18
25
|
[evt: string]: CustomEvent<any>;
|
|
19
|
-
}, {}, {
|
|
26
|
+
}, {}, {
|
|
27
|
+
confirm: () => void;
|
|
28
|
+
cancel: () => void;
|
|
29
|
+
}, string>;
|
|
20
30
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
21
31
|
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
22
32
|
$$bindings?: Bindings;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { tick } from 'svelte';
|
|
2
3
|
import { fade, fly } from 'svelte/transition';
|
|
3
4
|
import { backOut } from 'svelte/easing';
|
|
4
5
|
import { popupStore } from './popupStore.js';
|
|
@@ -9,11 +10,85 @@
|
|
|
9
10
|
import { VARIANT_FILLED } from '../../Base/variantTypes.js';
|
|
10
11
|
|
|
11
12
|
// Subscribe to the actual stack
|
|
12
|
-
/** @type {Array<{id: string, title: string, subtitle?: string, component: any, props: any}>} */
|
|
13
|
+
/** @type {Array<{id: string, title: string, subtitle?: string, component: any, props: any, widthRatio: number}>} */
|
|
13
14
|
let popupStack = [];
|
|
14
15
|
popupStore.stack.subscribe((s) => {
|
|
15
16
|
popupStack = s;
|
|
16
17
|
});
|
|
18
|
+
|
|
19
|
+
/** @type {{submit?: () => void, confirm?: () => void, cancel?: () => void, focusInput?: () => void} | null} */
|
|
20
|
+
let activePopupInstance = null;
|
|
21
|
+
|
|
22
|
+
/** @type {HTMLDivElement | null} */
|
|
23
|
+
let activeDialogRef = null;
|
|
24
|
+
|
|
25
|
+
function focusActivePopup() {
|
|
26
|
+
void tick().then(() => {
|
|
27
|
+
if (popupStack.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (activePopupInstance?.focusInput) {
|
|
32
|
+
activePopupInstance.focusInput();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
activeDialogRef?.focus({ preventScroll: true });
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {KeyboardEvent} event
|
|
42
|
+
*/
|
|
43
|
+
function handlePopupKeydown(event) {
|
|
44
|
+
const textareaAllowsEnterEvents = event.target instanceof HTMLTextAreaElement
|
|
45
|
+
&& event.target.dataset.newlineOnCtrlEnter === 'true';
|
|
46
|
+
|
|
47
|
+
if (event.defaultPrevented || event.isComposing || event.altKey || event.ctrlKey || event.metaKey) {
|
|
48
|
+
if (!(textareaAllowsEnterEvents && event.defaultPrevented && !event.ctrlKey && !event.metaKey && !event.altKey && !event.isComposing)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (event.key === 'Escape') {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
if (activePopupInstance?.cancel) {
|
|
56
|
+
activePopupInstance.cancel();
|
|
57
|
+
} else {
|
|
58
|
+
popupStore.close();
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (event.key !== 'Enter') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (event.shiftKey) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (event.target instanceof HTMLTextAreaElement && !textareaAllowsEnterEvents) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (event.target instanceof Element && event.target.closest('button, a, [role="button"]')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
|
|
81
|
+
if (activePopupInstance?.submit) {
|
|
82
|
+
activePopupInstance.submit();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
activePopupInstance?.confirm?.();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$: if (popupStack.length > 0) {
|
|
90
|
+
focusActivePopup();
|
|
91
|
+
}
|
|
17
92
|
</script>
|
|
18
93
|
|
|
19
94
|
{#if popupStack.length > 0}
|
|
@@ -24,15 +99,18 @@
|
|
|
24
99
|
<div
|
|
25
100
|
class="dialog"
|
|
26
101
|
class:background={!isTop}
|
|
102
|
+
bind:this={activeDialogRef}
|
|
27
103
|
style="
|
|
28
104
|
--scale: {isTop ? 1 : Math.max(0.85, 1 - depth * 0.08)};
|
|
29
105
|
--brightness: {isTop ? 1 : Math.max(0.4, 1 - depth * 0.3)};
|
|
30
106
|
--y-offset: {isTop ? 0 : -depth * 20}px;
|
|
107
|
+
--popup-width-ratio: {popup.widthRatio || 1};
|
|
31
108
|
z-index: {index};
|
|
32
109
|
"
|
|
33
110
|
in:fly|global={{ y: 40, duration: 350, easing: backOut }}
|
|
34
111
|
out:fly|global={{ y: 20, duration: 200 }}
|
|
35
112
|
on:click|stopPropagation
|
|
113
|
+
on:keydown={handlePopupKeydown}
|
|
36
114
|
on:keydown|stopPropagation
|
|
37
115
|
role="dialog"
|
|
38
116
|
tabindex="-1"
|
|
@@ -45,7 +123,7 @@
|
|
|
45
123
|
</div>
|
|
46
124
|
</header>
|
|
47
125
|
<main>
|
|
48
|
-
<svelte:component this={popup.component} {...popup.props} />
|
|
126
|
+
<svelte:component bind:this={activePopupInstance} this={popup.component} {...popup.props} />
|
|
49
127
|
</main>
|
|
50
128
|
</BaseContainer>
|
|
51
129
|
</div>
|
|
@@ -66,7 +144,11 @@
|
|
|
66
144
|
|
|
67
145
|
.dialog {
|
|
68
146
|
position: absolute;
|
|
69
|
-
width: min(
|
|
147
|
+
width: min(
|
|
148
|
+
calc(100vw - 2rem),
|
|
149
|
+
calc(90vw * var(--popup-width-ratio)),
|
|
150
|
+
calc(600px * var(--popup-width-ratio))
|
|
151
|
+
);
|
|
70
152
|
max-height: 80vh;
|
|
71
153
|
zoom: 0.92;
|
|
72
154
|
display: flex;
|
|
@@ -76,6 +158,11 @@
|
|
|
76
158
|
transition: transform 0.3s ease, filter 0.3s ease;
|
|
77
159
|
}
|
|
78
160
|
|
|
161
|
+
.dialog:focus,
|
|
162
|
+
.dialog:focus-visible {
|
|
163
|
+
outline: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
79
166
|
.dialog.background {
|
|
80
167
|
pointer-events: none;
|
|
81
168
|
}
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
|
|
27
27
|
let value = '';
|
|
28
28
|
|
|
29
|
+
/** @type {import('../InputBox.svelte').default | null} */
|
|
30
|
+
let inputRef = null;
|
|
31
|
+
|
|
29
32
|
function handleSubmit() {
|
|
30
33
|
onSubmit(value);
|
|
31
34
|
popupStore.close();
|
|
@@ -35,13 +38,25 @@
|
|
|
35
38
|
onCancel();
|
|
36
39
|
popupStore.close();
|
|
37
40
|
}
|
|
41
|
+
|
|
42
|
+
export function submit() {
|
|
43
|
+
handleSubmit();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function cancel() {
|
|
47
|
+
handleCancel();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function focusInput() {
|
|
51
|
+
inputRef?.focus();
|
|
52
|
+
}
|
|
38
53
|
</script>
|
|
39
54
|
|
|
40
55
|
<div class="prompt">
|
|
41
56
|
{#if label}
|
|
42
57
|
<BaseText variant="content">{label}</BaseText>
|
|
43
58
|
{/if}
|
|
44
|
-
<InputBox bind:value {placeholder} autofocus={true} />
|
|
59
|
+
<InputBox bind:this={inputRef} bind:value {placeholder} autofocus={true} />
|
|
45
60
|
<div class="buttons">
|
|
46
61
|
<Button theme={VARIANT_PRIMARY} actionIcon={icons.check} on:click={handleSubmit}>{submitText}</Button>
|
|
47
62
|
<Button theme={VARIANT_SECONDARY} actionIcon={icons.crossb} on:click={handleCancel}>{cancelText}</Button>
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
export default PromptPopup;
|
|
2
2
|
type PromptPopup = SvelteComponent<{
|
|
3
3
|
label?: string | undefined;
|
|
4
|
+
cancel?: (() => void) | undefined;
|
|
5
|
+
submit?: (() => void) | undefined;
|
|
4
6
|
placeholder?: string | undefined;
|
|
5
7
|
onCancel?: (() => void) | undefined;
|
|
6
8
|
cancelText?: string | undefined;
|
|
7
9
|
onSubmit?: ((value: string) => void) | undefined;
|
|
8
10
|
submitText?: string | undefined;
|
|
11
|
+
focusInput?: (() => void) | undefined;
|
|
9
12
|
}, {
|
|
10
13
|
[evt: string]: CustomEvent<any>;
|
|
11
14
|
}, {}> & {
|
|
12
15
|
$$bindings?: string | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
submit: () => void;
|
|
18
|
+
cancel: () => void;
|
|
19
|
+
focusInput: () => void;
|
|
13
20
|
};
|
|
14
21
|
declare const PromptPopup: $$__sveltets_2_IsomorphicComponent<{
|
|
15
22
|
label?: string | undefined;
|
|
23
|
+
cancel?: (() => void) | undefined;
|
|
24
|
+
submit?: (() => void) | undefined;
|
|
16
25
|
placeholder?: string | undefined;
|
|
17
26
|
onCancel?: (() => void) | undefined;
|
|
18
27
|
cancelText?: string | undefined;
|
|
19
28
|
onSubmit?: ((value: string) => void) | undefined;
|
|
20
29
|
submitText?: string | undefined;
|
|
30
|
+
focusInput?: (() => void) | undefined;
|
|
21
31
|
}, {
|
|
22
32
|
[evt: string]: CustomEvent<any>;
|
|
23
|
-
}, {}, {
|
|
33
|
+
}, {}, {
|
|
34
|
+
submit: () => void;
|
|
35
|
+
cancel: () => void;
|
|
36
|
+
focusInput: () => void;
|
|
37
|
+
}, string>;
|
|
24
38
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
25
39
|
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
26
40
|
$$bindings?: Bindings;
|