@marianmeres/stuic 1.30.0 → 1.31.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
  }
@@ -154,6 +154,7 @@ export let acp;
154
154
  $:
155
155
  dialog = $acp[0];
156
156
  let _dialogEl;
157
+ let _formEl;
157
158
  let value = null;
158
159
  let isPending = false;
159
160
  $:
@@ -179,12 +180,11 @@ const onKeyDown = (e) => {
179
180
  }
180
181
  };
181
182
  onMount(() => {
182
- _dialogEl.addEventListener("close", async () => {
183
- if (_dialogEl.returnValue === "") {
184
- acp.escape();
185
- }
183
+ _dialogEl.addEventListener("close", async (e) => {
184
+ });
185
+ _dialogEl.addEventListener("cancel", (e) => {
186
+ e.preventDefault();
186
187
  });
187
- _dialogEl.addEventListener("cancel", (event) => event.preventDefault());
188
188
  document.addEventListener("keydown", onKeyDown, true);
189
189
  return () => document.removeEventListener("keydown", onKeyDown, true);
190
190
  });
@@ -247,9 +247,6 @@ $:
247
247
  $:
248
248
  _menuLiClass = twMerge(`
249
249
  ${AlertConfirmPromptConfig.preset.menuLi}
250
- ${AlertConfirmPromptConfig.classMenuLi}
251
- ${dialog?.class?.menuLi || ""}
252
- ${AlertConfirmPromptConfig.variant?.[dialog?.variant]?.menuLi || ""}
253
250
  `);
254
251
  $:
255
252
  _buttonClass = twMerge(`
@@ -287,15 +284,31 @@ $:
287
284
  tabindex="-1"
288
285
  >
289
286
  {#if dialog}
290
- <!--since we're not using the native form submit, the <form> is not necessary-->
287
+ <!-- svelte-ignore a11y-autofocus -->
291
288
  <form
292
289
  method="dialog"
293
290
  use:focusTrap={{ autoFocusFirst: false }}
294
291
  tabindex="-1"
292
+ autofocus={dialog.type !== PROMPT}
295
293
  data-acp-type={dialog?.type}
296
294
  data-acp-variant={dialog?.variant}
297
295
  data-acp-is-pending={isPending}
298
296
  class={_dialogClass}
297
+ bind:this={_formEl}
298
+ on:submit|preventDefault={async () => {
299
+ // clog('on:submit', value);
300
+ isPending = true;
301
+ await Promise.resolve(dialog.onOk(dialog.type === PROMPT ? value : true));
302
+ isPending = false;
303
+ value = null;
304
+ }}
305
+ on:reset|preventDefault={async () => {
306
+ // clog('on:reset', value);
307
+ isPending = true;
308
+ await Promise.resolve(dialog.onCancel(false));
309
+ isPending = false;
310
+ value = null;
311
+ }}
299
312
  >
300
313
  <!-- this sm:flex is not configurable -->
301
314
  <div class="sm:flex sm:items-start">
@@ -342,8 +355,9 @@ $:
342
355
  data-acp-type={dialog?.type}
343
356
  data-acp-variant={dialog?.variant}
344
357
  data-acp-is-pending={isPending}
345
- on:input_mounted={({ detail }) => detail.focus()}
358
+ autofocus
346
359
  size="sm"
360
+ validate
347
361
  {...dialog.promptFieldProps}
348
362
  />
349
363
  {:else}
@@ -353,8 +367,9 @@ $:
353
367
  data-acp-type={dialog?.type}
354
368
  data-acp-variant={dialog?.variant}
355
369
  data-acp-is-pending={isPending}
356
- on:input_mounted={({ detail }) => detail.focus()}
370
+ autofocus
357
371
  size="sm"
372
+ validate
358
373
  {...dialog?.promptFieldProps || {}}
359
374
  />
360
375
  {/if}
@@ -377,13 +392,6 @@ $:
377
392
  >
378
393
  <Button
379
394
  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
395
  type="reset"
388
396
  data-acp-button-type="cancel"
389
397
  data-acp-dialog-type={dialog?.type}
@@ -436,13 +444,6 @@ $:
436
444
  data-acp-dialog-type={dialog?.type}
437
445
  data-acp-variant={dialog?.variant}
438
446
  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
447
  disabled={isPending}
447
448
  variant="primary"
448
449
  >
@@ -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
  };
@@ -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.31.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",