@marianmeres/stuic 1.85.0 → 1.86.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.
@@ -84,7 +84,6 @@ export let classesByVariant = {};
84
84
  $:
85
85
  dialog = $acp[0];
86
86
  let _dialogEl;
87
- let _formEl;
88
87
  let value = null;
89
88
  let isPending = false;
90
89
  $:
@@ -158,185 +157,186 @@ $:
158
157
  tabindex="-1"
159
158
  >
160
159
  {#if dialog}
161
- <!-- svelte-ignore a11y-autofocus -->
162
- <form
163
- method="dialog"
164
- use:focusTrap={{ autoFocusFirst: false }}
165
- tabindex="-1"
166
- autofocus={dialog.type !== PROMPT}
167
- data-acp-type={dialog?.type}
168
- data-acp-variant={dialog?.variant}
169
- data-acp-is-pending={isPending}
170
- class={_dialogClass}
171
- bind:this={_formEl}
172
- on:submit|preventDefault={async () => {
173
- // clog('on:submit', value);
174
- isPending = true;
175
- await Promise.resolve(dialog.onOk(dialog.type === PROMPT ? value : true));
176
- isPending = false;
177
- value = null;
178
- }}
179
- on:reset|preventDefault={async () => {
180
- // clog('on:reset', value);
181
- isPending = true;
182
- await Promise.resolve(dialog.onCancel(false));
183
- isPending = false;
184
- value = null;
185
- }}
186
- >
187
- <!-- this sm:flex is not configurable -->
188
- <div class="sm:flex sm:items-start">
189
- {#if _isFn(iconFn)}
190
- <div
191
- class={_iconClass}
192
- data-acp-type={dialog?.type}
193
- data-acp-variant={dialog?.variant}
194
- data-acp-is-pending={isPending}
195
- >
196
- {@html iconFn()}
197
- </div>
198
- {/if}
199
- <div class={_contentBlockClass}>
200
- <h1
201
- class={_titleClass}
202
- data-acp-type={dialog?.type}
203
- data-acp-variant={dialog?.variant}
204
- data-acp-is-pending={isPending}
205
- >
206
- <Thc thc={dialog.title} {forceAsHtml} />
207
- </h1>
208
- {#if dialog.content}
160
+ {#key dialog.id}
161
+ <!-- svelte-ignore a11y-autofocus -->
162
+ <form
163
+ method="dialog"
164
+ use:focusTrap={{ autoFocusFirst: false }}
165
+ tabindex="-1"
166
+ autofocus={dialog.type !== PROMPT}
167
+ data-acp-type={dialog?.type}
168
+ data-acp-variant={dialog?.variant}
169
+ data-acp-is-pending={isPending}
170
+ class={_dialogClass}
171
+ on:submit|preventDefault={async () => {
172
+ // clog('on:submit', value);
173
+ isPending = true;
174
+ await Promise.resolve(dialog.onOk(dialog.type === PROMPT ? value : true));
175
+ isPending = false;
176
+ value = null;
177
+ }}
178
+ on:reset|preventDefault={async () => {
179
+ // clog('on:reset', value);
180
+ isPending = true;
181
+ await Promise.resolve(dialog.onCancel(false));
182
+ isPending = false;
183
+ value = null;
184
+ }}
185
+ >
186
+ <!-- this sm:flex is not configurable -->
187
+ <div class="sm:flex sm:items-start">
188
+ {#if _isFn(iconFn)}
209
189
  <div
210
- class={_contentClass}
190
+ class={_iconClass}
211
191
  data-acp-type={dialog?.type}
212
192
  data-acp-variant={dialog?.variant}
213
193
  data-acp-is-pending={isPending}
214
194
  >
215
- <Thc thc={dialog.content} {forceAsHtml} />
195
+ {@html iconFn()}
216
196
  </div>
217
197
  {/if}
218
- {#if dialog.type === PROMPT}
219
- <div
220
- class={_inputBoxClass}
198
+ <div class={_contentBlockClass}>
199
+ <h1
200
+ class={_titleClass}
221
201
  data-acp-type={dialog?.type}
222
202
  data-acp-variant={dialog?.variant}
223
203
  data-acp-is-pending={isPending}
224
204
  >
225
- {#if dialog?.promptFieldProps?.options?.length}
226
- <FieldSelect
227
- class={_inputFieldClass}
228
- bind:value
229
- data-acp-type={dialog?.type}
230
- data-acp-variant={dialog?.variant}
231
- data-acp-is-pending={isPending}
232
- autofocus
233
- size="sm"
234
- validate
235
- {...dialog.promptFieldProps}
236
- />
237
- {:else}
238
- <Field
239
- class={_inputFieldClass}
240
- bind:value
241
- data-acp-type={dialog?.type}
242
- data-acp-variant={dialog?.variant}
243
- data-acp-is-pending={isPending}
244
- autofocus
245
- size="sm"
246
- validate
247
- {...dialog?.promptFieldProps || {}}
248
- />
249
- {/if}
250
- </div>
251
- {/if}
205
+ <Thc thc={dialog.title} {forceAsHtml} />
206
+ </h1>
207
+ {#if dialog.content}
208
+ <div
209
+ class={_contentClass}
210
+ data-acp-type={dialog?.type}
211
+ data-acp-variant={dialog?.variant}
212
+ data-acp-is-pending={isPending}
213
+ >
214
+ <Thc thc={dialog.content} {forceAsHtml} />
215
+ </div>
216
+ {/if}
217
+ {#if dialog.type === PROMPT}
218
+ <div
219
+ class={_inputBoxClass}
220
+ data-acp-type={dialog?.type}
221
+ data-acp-variant={dialog?.variant}
222
+ data-acp-is-pending={isPending}
223
+ >
224
+ {#if dialog?.promptFieldProps?.options?.length}
225
+ <FieldSelect
226
+ class={_inputFieldClass}
227
+ bind:value
228
+ data-acp-type={dialog?.type}
229
+ data-acp-variant={dialog?.variant}
230
+ data-acp-is-pending={isPending}
231
+ autofocus
232
+ size="sm"
233
+ validate
234
+ {...dialog.promptFieldProps}
235
+ />
236
+ {:else}
237
+ <Field
238
+ class={_inputFieldClass}
239
+ bind:value
240
+ data-acp-type={dialog?.type}
241
+ data-acp-variant={dialog?.variant}
242
+ data-acp-is-pending={isPending}
243
+ autofocus
244
+ size="sm"
245
+ validate
246
+ {...dialog?.promptFieldProps || {}}
247
+ />
248
+ {/if}
249
+ </div>
250
+ {/if}
251
+ </div>
252
252
  </div>
253
- </div>
254
- <menu
255
- class={_menuClass}
256
- data-acp-type={dialog?.type}
257
- data-acp-variant={dialog?.variant}
258
- data-acp-is-pending={isPending}
259
- >
260
- {#if dialog.type !== ALERT}
261
- <li
262
- class={_menuLiClass}
263
- data-acp-dialog-type={dialog?.type}
264
- data-acp-variant={dialog?.variant}
265
- data-acp-is-pending={isPending}
266
- >
267
- <Button
268
- class={_buttonClass}
269
- type="reset"
270
- data-acp-button-type="cancel"
253
+ <menu
254
+ class={_menuClass}
255
+ data-acp-type={dialog?.type}
256
+ data-acp-variant={dialog?.variant}
257
+ data-acp-is-pending={isPending}
258
+ >
259
+ {#if dialog.type !== ALERT}
260
+ <li
261
+ class={_menuLiClass}
271
262
  data-acp-dialog-type={dialog?.type}
272
263
  data-acp-variant={dialog?.variant}
273
264
  data-acp-is-pending={isPending}
274
- disabled={isPending}
275
265
  >
276
- <Thc thc={dialog.labelCancel} {forceAsHtml} />
277
- </Button>
278
- </li>
279
- {/if}
280
- {#if dialog.labelCustom && _isFn(dialog.onCustom)}
266
+ <Button
267
+ class={_buttonClass}
268
+ type="reset"
269
+ data-acp-button-type="cancel"
270
+ data-acp-dialog-type={dialog?.type}
271
+ data-acp-variant={dialog?.variant}
272
+ data-acp-is-pending={isPending}
273
+ disabled={isPending}
274
+ >
275
+ <Thc thc={dialog.labelCancel} {forceAsHtml} />
276
+ </Button>
277
+ </li>
278
+ {/if}
279
+ {#if dialog.labelCustom && _isFn(dialog.onCustom)}
280
+ <li
281
+ class={_menuLiClass}
282
+ data-acp-dialog-type={dialog?.type}
283
+ data-acp-variant={dialog?.variant}
284
+ data-acp-is-pending={isPending}
285
+ >
286
+ <Button
287
+ class={_buttonClass}
288
+ on:click={async (e) => {
289
+ e.preventDefault();
290
+ isPending = true;
291
+ await Promise.resolve(dialog.onCustom(value));
292
+ isPending = false;
293
+ value = null;
294
+ }}
295
+ type="button"
296
+ data-acp-button-type="custom"
297
+ data-acp-dialog-type={dialog?.type}
298
+ data-acp-variant={dialog?.variant}
299
+ data-acp-is-pending={isPending}
300
+ disabled={isPending}
301
+ >
302
+ <Thc thc={dialog.labelCustom} {forceAsHtml} />
303
+ </Button>
304
+ </li>
305
+ {/if}
281
306
  <li
282
307
  class={_menuLiClass}
283
- data-acp-dialog-type={dialog?.type}
308
+ data-acp-type={dialog?.type}
284
309
  data-acp-variant={dialog?.variant}
285
310
  data-acp-is-pending={isPending}
286
311
  >
287
312
  <Button
288
313
  class={_buttonClass}
289
- on:click={async (e) => {
290
- e.preventDefault();
291
- isPending = true;
292
- await Promise.resolve(dialog.onCustom(value));
293
- isPending = false;
294
- value = null;
295
- }}
296
- type="button"
297
- data-acp-button-type="custom"
314
+ type="submit"
315
+ value="OK"
316
+ data-acp-button-type="ok"
298
317
  data-acp-dialog-type={dialog?.type}
299
318
  data-acp-variant={dialog?.variant}
300
319
  data-acp-is-pending={isPending}
301
320
  disabled={isPending}
321
+ variant="primary"
302
322
  >
303
- <Thc thc={dialog.labelCustom} {forceAsHtml} />
323
+ <Thc thc={dialog.labelOk} {forceAsHtml} />
304
324
  </Button>
305
325
  </li>
306
- {/if}
307
- <li
308
- class={_menuLiClass}
309
- data-acp-type={dialog?.type}
310
- data-acp-variant={dialog?.variant}
311
- data-acp-is-pending={isPending}
312
- >
313
- <Button
314
- class={_buttonClass}
315
- type="submit"
316
- value="OK"
317
- data-acp-button-type="ok"
318
- data-acp-dialog-type={dialog?.type}
326
+ </menu>
327
+ {#if isPending}
328
+ <div
329
+ class={_spinnerBoxClass}
330
+ data-acp-type={dialog?.type}
319
331
  data-acp-variant={dialog?.variant}
320
- data-acp-is-pending={isPending}
321
- disabled={isPending}
322
- variant="primary"
323
332
  >
324
- <Thc thc={dialog.labelOk} {forceAsHtml} />
325
- </Button>
326
- </li>
327
- </menu>
328
- {#if isPending}
329
- <div
330
- class={_spinnerBoxClass}
331
- data-acp-type={dialog?.type}
332
- data-acp-variant={dialog?.variant}
333
- >
334
- <div class="rotating-cw">
335
- {@html acpDefaultIcons.spinner()}
333
+ <div class="rotating-cw">
334
+ {@html acpDefaultIcons.spinner()}
335
+ </div>
336
336
  </div>
337
- </div>
338
- {/if}
339
- </form>
337
+ {/if}
338
+ </form>
339
+ {/key}
340
340
  {/if}
341
341
 
342
342
  {#if notifications}
@@ -47,6 +47,7 @@ export declare const createAlertConfirmPromptStore: (defaults?: Partial<AlertCon
47
47
  reset: (stack?: AlertConfirmPromptOptions[]) => void;
48
48
  escape: () => void;
49
49
  close: () => void;
50
+ setHeadValue: (value: string) => void;
50
51
  alert: (o?: Partial<AlertConfirmPromptOptions> | string) => void;
51
52
  confirm: (onOk: FnOnOK, o?: Partial<AlertConfirmPromptOptions>) => void;
52
53
  prompt: (onOk: FnOnOK, o?: Partial<AlertConfirmPromptOptions>) => void;
@@ -39,6 +39,7 @@ export const createAlertConfirmPromptStore = (defaults) => {
39
39
  if (!['info', 'success', 'warn', 'error'].includes(o?.variant)) {
40
40
  o.variant = 'info';
41
41
  }
42
+ o._id = Math.random().toString(36).slice(2);
42
43
  //
43
44
  _stack.update((old) => [...old, o]);
44
45
  };
@@ -52,6 +53,15 @@ export const createAlertConfirmPromptStore = (defaults) => {
52
53
  _stack.get()[0].onEscape();
53
54
  shift();
54
55
  };
56
+ // will update value of the current (at index 0) element. Relevant for prompts, when validation
57
+ // is needed
58
+ const setHeadValue = (value) => {
59
+ const head = _stack.get()[0];
60
+ if (head) {
61
+ head.value = value;
62
+ _stack.update((old) => [head, ...old.slice(1)]);
63
+ }
64
+ };
55
65
  return {
56
66
  subscribe: _stack.subscribe,
57
67
  get: _stack.get,
@@ -61,6 +71,8 @@ export const createAlertConfirmPromptStore = (defaults) => {
61
71
  escape,
62
72
  // human alias
63
73
  close: shift,
74
+ //
75
+ setHeadValue,
64
76
  // sugar below
65
77
  //
66
78
  alert: (o) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.85.0",
3
+ "version": "1.86.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",