@shival99/z-ui-svelte 0.1.19 → 0.1.21

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.
@@ -46,8 +46,6 @@
46
46
  zOkDestructive?: boolean;
47
47
  zOkDisabled?: boolean;
48
48
  zLoading?: boolean;
49
- /** Cancel, the close button, Escape and the backdrop keep working while `zLoading` is true. */
50
- zCancelWhileLoading?: boolean;
51
49
  zOverlay?: ZDrawerOverlayType;
52
50
  zShadow?: boolean;
53
51
  zShape?: ZDrawerShape;
@@ -96,7 +94,6 @@
96
94
  zOkDestructive = false,
97
95
  zOkDisabled = false,
98
96
  zLoading = false,
99
- zCancelWhileLoading = false,
100
97
  zOverlay = zDefaultOverlayType(),
101
98
  zShadow = false,
102
99
  zShape = 'rounded',
@@ -129,7 +126,7 @@
129
126
  snap = index;
130
127
  onSnapChange?.(index);
131
128
  },
132
- canDismiss: () => zMaskClosable && (!zLoading || zCancelWhileLoading),
129
+ canDismiss: () => zMaskClosable && !zLoading,
133
130
  dismiss: () => cancel(),
134
131
  });
135
132
  const resize = new ZDrawerResizeController(
@@ -160,7 +157,7 @@
160
157
  };
161
158
 
162
159
  const cancel = (): void => {
163
- if (zLoading && !zCancelWhileLoading) {
160
+ if (zLoading) {
164
161
  return;
165
162
  }
166
163
  onCancel?.();
@@ -33,8 +33,6 @@ interface Props {
33
33
  zOkDestructive?: boolean;
34
34
  zOkDisabled?: boolean;
35
35
  zLoading?: boolean;
36
- /** Cancel, the close button, Escape and the backdrop keep working while `zLoading` is true. */
37
- zCancelWhileLoading?: boolean;
38
36
  zOverlay?: ZDrawerOverlayType;
39
37
  zShadow?: boolean;
40
38
  zShape?: ZDrawerShape;
@@ -52,7 +52,7 @@
52
52
  ref.snap = index;
53
53
  options.onSnapChange?.(index);
54
54
  },
55
- canDismiss: () => (options.zMaskClosable ?? true) && (!ref.busy || !!options.zCancelWhileLoading),
55
+ canDismiss: () => (options.zMaskClosable ?? true) && !ref.busy,
56
56
  dismiss: () => void ref._trigger('cancel'),
57
57
  })
58
58
  : null;
@@ -49,8 +49,6 @@ export interface ZDrawerOptions<R = unknown, U = unknown, T = unknown> {
49
49
  zOkDestructive?: boolean;
50
50
  zOkDisabled?: ZMaybeGetter<boolean>;
51
51
  zLoading?: ZMaybeGetter<boolean>;
52
- /** Keep Cancel, the close button, Escape and the backdrop working while an action is loading (default: they are ignored). */
53
- zCancelWhileLoading?: boolean;
54
52
  zContentLoading?: ZMaybeGetter<boolean>;
55
53
  /** Defaults to 6 for left/right, 3 for top/bottom. */
56
54
  zSkeletonRows?: number;
@@ -10,7 +10,6 @@ export class ZDrawerRef extends ZDialogRef {
10
10
  onOk: options.onOk,
11
11
  onCancel: options.onCancel,
12
12
  zLoading: options.zLoading,
13
- zCancelWhileLoading: options.zCancelWhileLoading,
14
13
  });
15
14
  this.options = options;
16
15
  this.snap = options.zSnap ?? 0;
@@ -180,12 +180,15 @@
180
180
  {/if}
181
181
  </div>
182
182
  {:else if category === 'video' && mediaUrl}
183
- <div class="relative flex max-h-[min(75vh,calc(100dvh-9.5rem))] w-[min(90vw,70rem)] items-center justify-center">
183
+ <!-- The box is only as large as the frame's own space: outside the video, a click passes through to the stage and dismisses it. -->
184
+ <div
185
+ class="pointer-events-none relative flex max-h-[min(75vh,calc(100dvh-9.5rem))] w-[min(90vw,70rem)] items-center justify-center"
186
+ >
184
187
  {#if loading && !failed}
185
188
  {@render loadingState()}
186
189
  {/if}
187
190
  {#if failed}
188
- {@render errorState(zTranslate('i18n_z_ui_gallery_preview_load_error'))}
191
+ <div class="pointer-events-auto">{@render errorState(zTranslate('i18n_z_ui_gallery_preview_load_error'))}</div>
189
192
  {:else}
190
193
  <!-- svelte-ignore a11y_media_has_caption (arbitrary user files have no caption tracks) -->
191
194
  <video
@@ -194,7 +197,7 @@
194
197
  controls
195
198
  playsinline
196
199
  class={[
197
- 'max-h-[min(75vh,calc(100dvh-9.5rem))] max-w-full rounded-lg bg-black shadow-2xl transition-opacity duration-300',
200
+ 'pointer-events-auto max-h-[min(75vh,calc(100dvh-9.5rem))] max-w-full rounded-lg bg-black shadow-2xl transition-opacity duration-300',
198
201
  loading ? 'opacity-0' : 'opacity-100',
199
202
  ]}
200
203
  onloadeddata={done}
@@ -33,8 +33,6 @@
33
33
  zOkDestructive?: boolean;
34
34
  zOkDisabled?: boolean;
35
35
  zLoading?: boolean;
36
- /** Cancel, the close button, Escape and the backdrop keep working while `zLoading` is true. */
37
- zCancelWhileLoading?: boolean;
38
36
  zContentLoading?: boolean;
39
37
  zSkeletonRows?: number;
40
38
  zOverlay?: ZModalOverlayType;
@@ -68,7 +66,6 @@
68
66
  zOkDestructive = false,
69
67
  zOkDisabled = false,
70
68
  zLoading = false,
71
- zCancelWhileLoading = false,
72
69
  zContentLoading = false,
73
70
  zSkeletonRows = 3,
74
71
  zOverlay = zDefaultOverlayType(),
@@ -105,7 +102,7 @@
105
102
  };
106
103
 
107
104
  const cancel = (): void => {
108
- if (zLoading && !zCancelWhileLoading) {
105
+ if (zLoading) {
109
106
  return;
110
107
  }
111
108
  onCancel?.();
@@ -22,8 +22,6 @@ interface Props {
22
22
  zOkDestructive?: boolean;
23
23
  zOkDisabled?: boolean;
24
24
  zLoading?: boolean;
25
- /** Cancel, the close button, Escape and the backdrop keep working while `zLoading` is true. */
26
- zCancelWhileLoading?: boolean;
27
25
  zContentLoading?: boolean;
28
26
  zSkeletonRows?: number;
29
27
  zOverlay?: ZModalOverlayType;
@@ -41,8 +41,6 @@ export interface ZModalOptions<R = unknown, U = unknown, T = unknown> {
41
41
  zOkDisabled?: ZMaybeGetter<boolean>;
42
42
  /** OK button loading state, e.g. `() => saving`. `ref.loading` works too. */
43
43
  zLoading?: ZMaybeGetter<boolean>;
44
- /** Keep Cancel, the close button, Escape and the backdrop working while an action is loading (default: they are ignored). */
45
- zCancelWhileLoading?: boolean;
46
44
  /** Shows a skeleton while true, e.g. `() => loading`. */
47
45
  zContentLoading?: ZMaybeGetter<boolean>;
48
46
  zSkeletonRows?: number;
@@ -11,7 +11,6 @@ export class ZModalRef extends ZDialogRef {
11
11
  onOk: options.onOk,
12
12
  onCancel: options.onCancel,
13
13
  zLoading: options.zLoading,
14
- zCancelWhileLoading: options.zCancelWhileLoading,
15
14
  });
16
15
  this.options = options;
17
16
  }
@@ -44,7 +44,6 @@ export class ZModalService {
44
44
  zConfirmIcon: options.zIcon ?? (options.zConfirmStyle === 'dialog' ? preset.dialogIcon : preset.icon),
45
45
  zConfirmStyle: options.zConfirmStyle,
46
46
  zMaskClosable: options.zMaskClosable ?? true,
47
- zCancelWhileLoading: options.zCancelWhileLoading,
48
47
  zWidth: options.zWidth ?? '500px',
49
48
  zConfirmType: type,
50
49
  zData: options.zData,
@@ -21,8 +21,6 @@ export interface ZModalConfirmOptions<U = unknown> {
21
21
  /** `null` hides the cancel button */
22
22
  zCancelText?: string | null;
23
23
  zMaskClosable?: boolean;
24
- /** Keep Cancel, Escape and the backdrop working while `onOk` is pending. */
25
- zCancelWhileLoading?: boolean;
26
24
  zConfirmStyle?: ZModalConfirmStyle;
27
25
  zWidth?: string;
28
26
  zData?: U;
@@ -71,6 +71,29 @@
71
71
  const ratio = window.devicePixelRatio || 1;
72
72
  const snap = (value: number): number => Math.round(value * ratio) / ratio;
73
73
 
74
+ // The panel stays hidden until its first resolved position (see `style="opacity:0"`), then slides in once from the
75
+ // side it really sits on, like ZPopover. Animating from the unpositioned spot made the tooltip jump on entry.
76
+ let entered = false;
77
+ const enter = (resolved: string): void => {
78
+ if (entered) {
79
+ return;
80
+ }
81
+ entered = true;
82
+ node.style.opacity = '';
83
+ if (zPrefersReducedMotion() || zTooltipTakeover.active || typeof node.animate !== 'function') {
84
+ return;
85
+ }
86
+ const resolvedSide = (REVERSE[resolved] ?? tooltip.position).split('-')[0] as 'top' | 'bottom' | 'left' | 'right';
87
+ const [dx, dy] = zSideOffset(resolvedSide, Z_TOOLTIP_SLIDE_DISTANCE);
88
+ node.animate(
89
+ [
90
+ { opacity: 0, transform: `translate(${dx}px, ${dy}px)` },
91
+ { opacity: 1, transform: 'none' },
92
+ ],
93
+ { duration: 150, easing: 'cubic-bezier(0.32, 0.72, 0, 1)' }
94
+ );
95
+ };
96
+
74
97
  const update = (): void => {
75
98
  const { position, offset: gap } = tooltip;
76
99
  void computePosition(anchor, node, {
@@ -98,6 +121,7 @@
98
121
  node.style.top = `${snap(y)}px`;
99
122
  placement = REVERSE[resolved] ?? tooltip.position;
100
123
  arrowOffset = zTooltipArrowOffset(anchor.getBoundingClientRect(), node.getBoundingClientRect(), placement);
124
+ enter(resolved);
101
125
  });
102
126
  };
103
127
 
@@ -109,14 +133,12 @@
109
133
  };
110
134
  }
111
135
 
112
- /** 4px slide from the anchor plus a fade — the core-ui z-tooltip motion (same curve), as a real transition. */
113
- function motion(_node: Element) {
136
+ /** Exit: 4px slide back toward the anchor plus a fade, 150ms, the core-ui z-animate-out curve. */
137
+ function exit(_node: Element) {
114
138
  const [dx, dy] = zSideOffset(side, Z_TOOLTIP_SLIDE_DISTANCE);
115
139
  return {
116
- // core-ui timing: 150ms both ways (z-duration-150 in, z-animate-out's 150ms out).
117
140
  // An early dismiss (another tooltip taking over, or a press on the trigger) has no outro.
118
141
  duration: zPrefersReducedMotion() || zTooltipTakeover.active ? 0 : 150,
119
- // core-ui's z-animate-in/out curve: most of the change lands in the first frames, then it settles.
120
142
  easing: Z_EASE_DRAWER,
121
143
  css: (t: number) => `opacity:${t};transform:translate(${dx * (1 - t)}px, ${dy * (1 - t)}px)`,
122
144
  };
@@ -129,8 +151,9 @@
129
151
  popover="manual"
130
152
  class={['z-popover-host z-tooltip-host', classes]}
131
153
  data-position={placement}
154
+ style="opacity:0"
132
155
  {@attach float}
133
- transition:motion|global
156
+ out:exit
134
157
  onpointerenter={tooltip.onPointerEnter}
135
158
  onpointerleave={tooltip.onPointerLeave}
136
159
  >
@@ -50,8 +50,10 @@
50
50
  zDefaultExpandAll?: boolean;
51
51
  /** Expand the ancestors of the initial `selected` on mount. */
52
52
  zExpandToSelected?: boolean;
53
- /** Clicking a row also toggles it (file-explorer behaviour). */
53
+ /** A click on a folder's label also expands or collapses it (the arrow always does). Off: the label only selects. */
54
54
  zExpandOnClick?: boolean;
55
+ /** Gap in px between the rows' hover and selected backgrounds (the library default is about 1px). */
56
+ zRowGap?: number;
55
57
  zBordered?: boolean;
56
58
  /** Scroll area max height; the tree is as tall as its rows until then. */
57
59
  zMaxHeight?: number | string;
@@ -92,7 +94,8 @@
92
94
  zMultiple = false,
93
95
  zDefaultExpandAll = false,
94
96
  zExpandToSelected = true,
95
- zExpandOnClick = false,
97
+ zExpandOnClick = true,
98
+ zRowGap,
96
99
  zBordered = false,
97
100
  zMaxHeight = 360,
98
101
  zLabel = '',
@@ -142,6 +145,8 @@
142
145
  let loadingIds = $state.raw<ReadonlySet<string>>(new Set());
143
146
 
144
147
  const rowHeight = $derived(Z_TREE_ROW_HEIGHT[zSize]);
148
+ // Space between neighbouring highlights: 2px, 1.5px in the small size (zRowGap overrides it).
149
+ const rowGap = $derived(zRowGap ?? (zSize === 'sm' ? 1.5 : 2));
145
150
  const expandedSet = $derived(new Set(expanded));
146
151
  const selectedSet = $derived(new Set(selected));
147
152
  const checkedSet = $derived(new Set(checked));
@@ -559,8 +564,13 @@
559
564
  return state === 'checked';
560
565
  }
561
566
 
567
+ // A folder is a branch that can open, or one whose children are known to be none (an empty folder): it keeps the folder
568
+ // icon without an arrow. A leaf or a node without children is a file.
569
+ const isFolder = (row: ZTreeRow<T>): boolean =>
570
+ !row.node.isLeaf && (row.expandable || childrenOf(row.node) !== undefined);
571
+
562
572
  function defaultIcon(row: ZTreeRow<T>): ZIconName {
563
- if (!row.expandable) {
573
+ if (!isFolder(row)) {
564
574
  return 'lucideFile';
565
575
  }
566
576
  return row.expanded ? 'lucideFolderOpen' : 'lucideFolder';
@@ -600,8 +610,10 @@
600
610
  tabindex={tabStopRendered || rows.length === 0 ? -1 : 0}
601
611
  class={zMergeClasses(zTreeVariants({ zBordered }), moving && 'z-tree-moving', className)}
602
612
  style:max-height={typeof zMaxHeight === 'number' ? `${zMaxHeight}px` : zMaxHeight}
613
+ style:--z-tree-row-gap={`${rowGap}px`}
603
614
  {@attach zHoverGlide({
604
- class: 'bg-muted/70 [clip-path:inset(0_4px_var(--z-tree-row-gap,1.3px)_4px_round_var(--radius-lg))]',
615
+ class:
616
+ 'bg-muted/70 [clip-path:inset(calc(var(--z-tree-row-gap,2px)/2)_4px_calc(var(--z-tree-row-gap,2px)/2)_4px_round_var(--radius-lg))]',
605
617
  })}
606
618
  onkeydown={handleKeydown}
607
619
  onwheel={cancelMotion}
@@ -716,7 +728,7 @@
716
728
  })}
717
729
  {:else}
718
730
  {#if zShowIcon || row.node.icon}
719
- {#if !row.node.icon && row.expandable}
731
+ {#if !row.node.icon && isFolder(row)}
720
732
  <!-- beUI-style swap: both folders stay mounted and trade places (scale + tilt + fade). -->
721
733
  <span
722
734
  class={[iconClass, 'z-tree-folder relative']}
@@ -746,10 +758,11 @@
746
758
  </div>
747
759
 
748
760
  <style>
749
- /* Motion values follow beUI's file tree (MIT, see THIRD_PARTY_NOTICES.md): EASE_OUT [0.16, 1, 0.3, 1],
750
- rows rise 6px over 220ms with a 25ms stagger capped at 100ms, branch lines draw in over 300ms. */
761
+ /* Opening unrolls the revealed rows top to bottom (a clip from 0% to 100% of the row, with a 25ms stagger), and the
762
+ rows below glide down into place: the same look as a grid row going 0fr -> 1fr, without a grid, so the rows keep
763
+ their virtualized absolute offsets. Motion values follow beUI's file tree (MIT, see THIRD_PARTY_NOTICES.md). */
751
764
  :global(.z-tree-enter) {
752
- animation: z-tree-enter 220ms cubic-bezier(0.16, 1, 0.3, 1) var(--z-tree-delay, 0ms) backwards;
765
+ animation: z-tree-enter 300ms cubic-bezier(0.16, 1, 0.3, 1) var(--z-tree-delay, 0ms) backwards;
753
766
  }
754
767
 
755
768
  :global(.z-tree-enter .z-tree-guides) {
@@ -757,9 +770,9 @@
757
770
  animation: z-tree-guide 300ms cubic-bezier(0.16, 1, 0.3, 1) var(--z-tree-delay, 0ms) backwards;
758
771
  }
759
772
 
760
- /* `translate` is its own property, so it never fights the virtualizer's inline `transform`. */
773
+ /* Closing rolls the removed rows up into the parent's line; the rows below glide up (see z-tree-moving). */
761
774
  :global(.z-tree-exit) {
762
- animation: z-tree-exit 140ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
775
+ animation: z-tree-exit 240ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
763
776
  pointer-events: none;
764
777
  }
765
778
 
@@ -803,8 +816,8 @@
803
816
 
804
817
  @keyframes z-tree-exit {
805
818
  to {
819
+ clip-path: inset(0 0 100% 0);
806
820
  opacity: 0;
807
- translate: 0 -6px;
808
821
  }
809
822
  }
810
823
 
@@ -817,8 +830,8 @@
817
830
 
818
831
  @keyframes z-tree-enter {
819
832
  from {
833
+ clip-path: inset(0 0 100% 0);
820
834
  opacity: 0;
821
- translate: 0 -6px;
822
835
  }
823
836
  }
824
837
 
@@ -22,8 +22,10 @@ declare function $$render<T = unknown>(): {
22
22
  zDefaultExpandAll?: boolean;
23
23
  /** Expand the ancestors of the initial `selected` on mount. */
24
24
  zExpandToSelected?: boolean;
25
- /** Clicking a row also toggles it (file-explorer behaviour). */
25
+ /** A click on a folder's label also expands or collapses it (the arrow always does). Off: the label only selects. */
26
26
  zExpandOnClick?: boolean;
27
+ /** Gap in px between the rows' hover and selected backgrounds (the library default is about 1px). */
28
+ zRowGap?: number;
27
29
  zBordered?: boolean;
28
30
  /** Scroll area max height; the tree is as tall as its rows until then. */
29
31
  zMaxHeight?: number | string;
@@ -1,5 +1,5 @@
1
1
  import { cva } from 'class-variance-authority';
2
- export const zTreeVariants = cva('z-tree relative block w-full overflow-x-hidden overflow-y-auto overscroll-y-contain text-sm outline-none [--z-tree-row-gap:1.3px] [--z-tree-guide:color-mix(in_oklab,var(--color-foreground)_14%,var(--color-background))]', {
2
+ export const zTreeVariants = cva('z-tree relative block w-full overflow-x-hidden overflow-y-auto overscroll-y-contain text-sm outline-none [--z-tree-row-gap:2px] [--z-tree-guide:color-mix(in_oklab,var(--color-foreground)_14%,var(--color-background))]', {
3
3
  variants: {
4
4
  zBordered: {
5
5
  // An inset ring, not a border: the hover glide positions its pill relative to the padding box.
@@ -13,7 +13,7 @@ export const zTreeRowVariants = cva([
13
13
  'z-tree-row group/tree-row absolute right-0 left-0 flex min-w-0 cursor-pointer items-center gap-1.5 rounded-(--radius-lg) pr-2 select-none',
14
14
  'outline-none transition-colors duration-200 motion-reduce:transition-none',
15
15
  // One shape for the selected background, the focus ring and the hover pill (see ZTree's zHoverGlide class).
16
- 'before:pointer-events-none before:absolute before:inset-x-1 before:top-0 before:bottom-(--z-tree-row-gap) before:-z-10 before:rounded-(--radius-lg) before:content-[""]',
16
+ 'before:pointer-events-none before:absolute before:inset-x-1 before:inset-y-[calc(var(--z-tree-row-gap)/2)] before:-z-10 before:rounded-(--radius-lg) before:content-[""]',
17
17
  'focus-visible:before:ring-ring/60 focus-visible:before:ring-2 focus-visible:before:ring-inset',
18
18
  'text-muted-foreground hover:text-foreground data-[selected=true]:before:bg-muted data-[selected=true]:font-medium data-[selected=true]:text-foreground',
19
19
  'data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50',
@@ -7,8 +7,6 @@ interface ZDialogRefInit<Ref, R, U> {
7
7
  onOk?: ZDialogHandler<Ref, R>;
8
8
  onCancel?: ZDialogHandler<Ref, R>;
9
9
  zLoading?: ZMaybeGetter<boolean>;
10
- /** Cancel stays available while an action is loading. */
11
- zCancelWhileLoading?: boolean;
12
10
  }
13
11
  /**
14
12
  * Shared handle behind `ZModalRef` / `ZDrawerRef`. Plain reactive class fields instead of
@@ -51,7 +51,7 @@ export class ZDialogRef {
51
51
  }
52
52
  /** @internal */
53
53
  async _trigger(action) {
54
- if (this.#closing || (this.busy && !(action === 'cancel' && this.#init.zCancelWhileLoading))) {
54
+ if (this.busy || this.#closing) {
55
55
  return;
56
56
  }
57
57
  const handler = action === 'ok' ? this.#init.onOk : this.#init.onCancel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shival99/z-ui-svelte",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Z-UI component library for Svelte 5 (runes, no CDK).",
5
5
  "license": "MIT",
6
6
  "type": "module",