@marianmeres/stuic 1.30.0 → 1.32.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.
@@ -4,11 +4,11 @@ import {
4
4
  Button,
5
5
  FieldSelect,
6
6
  createAlertConfirmPromptStore,
7
- focusTrap
7
+ focusTrap,
8
+ Field,
9
+ Thc
8
10
  } from "../../index.js";
9
- import Thc from "../Thc/Thc.svelte";
10
11
  import { twMerge } from "tailwind-merge";
11
- import { Field } from "../../index.js";
12
12
  import { acpDefaultIcons } from "./acp-icons.js";
13
13
  import { createClog } from "@marianmeres/clog";
14
14
  export class AlertConfirmPromptConfig {
@@ -78,7 +78,7 @@ export class AlertConfirmPromptConfig {
78
78
  static classInputBox = "";
79
79
  static classInputField = "";
80
80
  static classMenu = "";
81
- static classMenuLi = "";
81
+ // static classMenuLi = '';
82
82
  static classButton = "";
83
83
  static classSpinnerBox = "";
84
84
  // 'info' | 'success' | 'warn' | 'error'
@@ -93,7 +93,7 @@ export class AlertConfirmPromptConfig {
93
93
  inputBox: "",
94
94
  inputField: "",
95
95
  menu: "",
96
- menuLi: "",
96
+ // menuLi: '',
97
97
  button: "",
98
98
  spinnerBox: ""
99
99
  },
@@ -106,7 +106,7 @@ export class AlertConfirmPromptConfig {
106
106
  inputBox: "",
107
107
  inputField: "",
108
108
  menu: "",
109
- menuLi: "",
109
+ // menuLi: '',
110
110
  button: "",
111
111
  spinnerBox: ""
112
112
  },
@@ -119,7 +119,7 @@ export class AlertConfirmPromptConfig {
119
119
  inputBox: "",
120
120
  inputField: "",
121
121
  menu: "",
122
- menuLi: "",
122
+ // menuLi: '',
123
123
  button: "",
124
124
  spinnerBox: ""
125
125
  },
@@ -132,7 +132,7 @@ export class AlertConfirmPromptConfig {
132
132
  inputBox: "",
133
133
  inputField: "",
134
134
  menu: "",
135
- menuLi: "",
135
+ // menuLi: '',
136
136
  button: "",
137
137
  spinnerBox: ""
138
138
  }
@@ -144,6 +144,8 @@ export class AlertConfirmPromptConfig {
144
144
  error: void 0,
145
145
  spinner: void 0
146
146
  };
147
+ // conveniently hoisted THC option, since all content is rendered via THC
148
+ static forceAsHtml = void 0;
147
149
  }
148
150
  const _isFn = (v) => typeof v === "function";
149
151
  </script>
@@ -153,7 +155,15 @@ const clog = createClog("AlertConfirmPrompt");
153
155
  export let acp;
154
156
  $:
155
157
  dialog = $acp[0];
158
+ let forceAsHtml = void 0;
159
+ $:
160
+ if (dialog) {
161
+ forceAsHtml = dialog.forceAsHtml ?? AlertConfirmPromptConfig.forceAsHtml;
162
+ } else {
163
+ forceAsHtml = void 0;
164
+ }
156
165
  let _dialogEl;
166
+ let _formEl;
157
167
  let value = null;
158
168
  let isPending = false;
159
169
  $:
@@ -179,12 +189,11 @@ const onKeyDown = (e) => {
179
189
  }
180
190
  };
181
191
  onMount(() => {
182
- _dialogEl.addEventListener("close", async () => {
183
- if (_dialogEl.returnValue === "") {
184
- acp.escape();
185
- }
192
+ _dialogEl.addEventListener("close", async (e) => {
193
+ });
194
+ _dialogEl.addEventListener("cancel", (e) => {
195
+ e.preventDefault();
186
196
  });
187
- _dialogEl.addEventListener("cancel", (event) => event.preventDefault());
188
197
  document.addEventListener("keydown", onKeyDown, true);
189
198
  return () => document.removeEventListener("keydown", onKeyDown, true);
190
199
  });
@@ -247,9 +256,6 @@ $:
247
256
  $:
248
257
  _menuLiClass = twMerge(`
249
258
  ${AlertConfirmPromptConfig.preset.menuLi}
250
- ${AlertConfirmPromptConfig.classMenuLi}
251
- ${dialog?.class?.menuLi || ""}
252
- ${AlertConfirmPromptConfig.variant?.[dialog?.variant]?.menuLi || ""}
253
259
  `);
254
260
  $:
255
261
  _buttonClass = twMerge(`
@@ -287,15 +293,31 @@ $:
287
293
  tabindex="-1"
288
294
  >
289
295
  {#if dialog}
290
- <!--since we're not using the native form submit, the <form> is not necessary-->
296
+ <!-- svelte-ignore a11y-autofocus -->
291
297
  <form
292
298
  method="dialog"
293
299
  use:focusTrap={{ autoFocusFirst: false }}
294
300
  tabindex="-1"
301
+ autofocus={dialog.type !== PROMPT}
295
302
  data-acp-type={dialog?.type}
296
303
  data-acp-variant={dialog?.variant}
297
304
  data-acp-is-pending={isPending}
298
305
  class={_dialogClass}
306
+ bind:this={_formEl}
307
+ on:submit|preventDefault={async () => {
308
+ // clog('on:submit', value);
309
+ isPending = true;
310
+ await Promise.resolve(dialog.onOk(dialog.type === PROMPT ? value : true));
311
+ isPending = false;
312
+ value = null;
313
+ }}
314
+ on:reset|preventDefault={async () => {
315
+ // clog('on:reset', value);
316
+ isPending = true;
317
+ await Promise.resolve(dialog.onCancel(false));
318
+ isPending = false;
319
+ value = null;
320
+ }}
299
321
  >
300
322
  <!-- this sm:flex is not configurable -->
301
323
  <div class="sm:flex sm:items-start">
@@ -316,7 +338,7 @@ $:
316
338
  data-acp-variant={dialog?.variant}
317
339
  data-acp-is-pending={isPending}
318
340
  >
319
- <Thc thc={dialog.title} />
341
+ <Thc thc={dialog.title} {forceAsHtml} />
320
342
  </h1>
321
343
  {#if dialog.content}
322
344
  <div
@@ -325,7 +347,7 @@ $:
325
347
  data-acp-variant={dialog?.variant}
326
348
  data-acp-is-pending={isPending}
327
349
  >
328
- <Thc thc={dialog.content} />
350
+ <Thc thc={dialog.content} {forceAsHtml} />
329
351
  </div>
330
352
  {/if}
331
353
  {#if dialog.type === PROMPT}
@@ -342,8 +364,9 @@ $:
342
364
  data-acp-type={dialog?.type}
343
365
  data-acp-variant={dialog?.variant}
344
366
  data-acp-is-pending={isPending}
345
- on:input_mounted={({ detail }) => detail.focus()}
367
+ autofocus
346
368
  size="sm"
369
+ validate
347
370
  {...dialog.promptFieldProps}
348
371
  />
349
372
  {:else}
@@ -353,8 +376,9 @@ $:
353
376
  data-acp-type={dialog?.type}
354
377
  data-acp-variant={dialog?.variant}
355
378
  data-acp-is-pending={isPending}
356
- on:input_mounted={({ detail }) => detail.focus()}
379
+ autofocus
357
380
  size="sm"
381
+ validate
358
382
  {...dialog?.promptFieldProps || {}}
359
383
  />
360
384
  {/if}
@@ -377,13 +401,6 @@ $:
377
401
  >
378
402
  <Button
379
403
  class={_buttonClass}
380
- on:click={async (e) => {
381
- e.preventDefault();
382
- isPending = true;
383
- await Promise.resolve(dialog.onCancel(false));
384
- isPending = false;
385
- value = null;
386
- }}
387
404
  type="reset"
388
405
  data-acp-button-type="cancel"
389
406
  data-acp-dialog-type={dialog?.type}
@@ -391,7 +408,7 @@ $:
391
408
  data-acp-is-pending={isPending}
392
409
  disabled={isPending}
393
410
  >
394
- <Thc thc={dialog.labelCancel} />
411
+ <Thc thc={dialog.labelCancel} {forceAsHtml} />
395
412
  </Button>
396
413
  </li>
397
414
  {/if}
@@ -418,7 +435,7 @@ $:
418
435
  data-acp-is-pending={isPending}
419
436
  disabled={isPending}
420
437
  >
421
- <Thc thc={dialog.labelCustom} />
438
+ <Thc thc={dialog.labelCustom} {forceAsHtml} />
422
439
  </Button>
423
440
  </li>
424
441
  {/if}
@@ -436,17 +453,10 @@ $:
436
453
  data-acp-dialog-type={dialog?.type}
437
454
  data-acp-variant={dialog?.variant}
438
455
  data-acp-is-pending={isPending}
439
- on:click={async (e) => {
440
- e.preventDefault();
441
- isPending = true;
442
- await Promise.resolve(dialog.onOk(dialog.type === PROMPT ? value : true));
443
- isPending = false;
444
- value = null;
445
- }}
446
456
  disabled={isPending}
447
457
  variant="primary"
448
458
  >
449
- <Thc thc={dialog.labelOk} />
459
+ <Thc thc={dialog.labelOk} {forceAsHtml} />
450
460
  </Button>
451
461
  </li>
452
462
  </menu>
@@ -22,7 +22,6 @@ export declare class AlertConfirmPromptConfig {
22
22
  static classInputBox: string;
23
23
  static classInputField: string;
24
24
  static classMenu: string;
25
- static classMenuLi: string;
26
25
  static classButton: string;
27
26
  static classSpinnerBox: string;
28
27
  static variant: {
@@ -35,7 +34,6 @@ export declare class AlertConfirmPromptConfig {
35
34
  inputBox: string;
36
35
  inputField: string;
37
36
  menu: string;
38
- menuLi: string;
39
37
  button: string;
40
38
  spinnerBox: string;
41
39
  };
@@ -48,7 +46,6 @@ export declare class AlertConfirmPromptConfig {
48
46
  inputBox: string;
49
47
  inputField: string;
50
48
  menu: string;
51
- menuLi: string;
52
49
  button: string;
53
50
  spinnerBox: string;
54
51
  };
@@ -61,7 +58,6 @@ export declare class AlertConfirmPromptConfig {
61
58
  inputBox: string;
62
59
  inputField: string;
63
60
  menu: string;
64
- menuLi: string;
65
61
  button: string;
66
62
  spinnerBox: string;
67
63
  };
@@ -74,7 +70,6 @@ export declare class AlertConfirmPromptConfig {
74
70
  inputBox: string;
75
71
  inputField: string;
76
72
  menu: string;
77
- menuLi: string;
78
73
  button: string;
79
74
  spinnerBox: string;
80
75
  };
@@ -86,6 +81,7 @@ export declare class AlertConfirmPromptConfig {
86
81
  error: undefined;
87
82
  spinner: undefined;
88
83
  };
84
+ static forceAsHtml: undefined;
89
85
  }
90
86
  declare const __propDef: {
91
87
  props: {
@@ -37,6 +37,7 @@ export interface AlertConfirmPromptOptions extends Record<string, any> {
37
37
  button: string;
38
38
  spinnerBox: string;
39
39
  }>;
40
+ forceAsHtml?: boolean;
40
41
  }
41
42
  export declare const createAlertConfirmPromptStore: () => {
42
43
  subscribe: (cb: import("@marianmeres/store").Subscribe<AlertConfirmPromptOptions[]>) => import("@marianmeres/store").Unsubscribe;
@@ -28,7 +28,7 @@ export const createAlertConfirmPromptStore = () => {
28
28
  if (!isFn(o.onCancel))
29
29
  o.onCancel = shift;
30
30
  if (!isFn(o.onEscape))
31
- o.onEscape = () => undefined;
31
+ o.onEscape = shift;
32
32
  if (o.labelOk === undefined)
33
33
  o.labelOk = labelOk;
34
34
  if (o.labelCancel === undefined)
@@ -34,6 +34,7 @@ export let name = "";
34
34
  export let tabindex = 0;
35
35
  export let description = "";
36
36
  export let descriptionClass = "";
37
+ export let autofocus = void 0;
37
38
  export let disabled = false;
38
39
  export let readonly = false;
39
40
  export let required = false;
@@ -116,6 +117,7 @@ $:
116
117
  {disabled}
117
118
  {readonly}
118
119
  {required}
120
+ {autofocus}
119
121
  {tabindex}
120
122
  use:trim={useTrim}
121
123
  use:validateAction={validate
@@ -137,6 +139,7 @@ $:
137
139
  {disabled}
138
140
  {readonly}
139
141
  {required}
142
+ {autofocus}
140
143
  {autocomplete}
141
144
  {tabindex}
142
145
  {minlength}
@@ -17,6 +17,7 @@ declare const __propDef: {
17
17
  tabindex?: number | undefined;
18
18
  description?: string | undefined;
19
19
  descriptionClass?: string | undefined;
20
+ autofocus?: true | undefined;
20
21
  disabled?: boolean | undefined;
21
22
  readonly?: boolean | undefined;
22
23
  required?: boolean | undefined;
@@ -31,6 +31,7 @@ export let description = "";
31
31
  export let descriptionClass = "";
32
32
  export let disabled = false;
33
33
  export let required = false;
34
+ export let autofocus = void 0;
34
35
  export let validationMessageClass = "";
35
36
  export let validate = void 0;
36
37
  let validation;
@@ -97,6 +98,7 @@ $:
97
98
  {disabled}
98
99
  {required}
99
100
  {tabindex}
101
+ {autofocus}
100
102
  {name}
101
103
  use:validateAction={validate
102
104
  ? { ...(validate === true ? {} : validate), setValidationResult }
@@ -19,6 +19,7 @@ declare const __propDef: {
19
19
  descriptionClass?: string | undefined;
20
20
  disabled?: boolean | undefined;
21
21
  required?: boolean | undefined;
22
+ autofocus?: true | undefined;
22
23
  validationMessageClass?: string | undefined;
23
24
  validate?: ValidateOptions | true | undefined;
24
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",