@fibrae/semi-ui-svelte 0.6.0 → 0.8.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.
Files changed (124) hide show
  1. package/dist/components/auto-complete/auto-complete.svelte +12 -21
  2. package/dist/components/auto-complete/interface.d.ts +3 -2
  3. package/dist/components/badge/badge.svelte +4 -4
  4. package/dist/components/badge/interface.d.ts +4 -3
  5. package/dist/components/button/button.svelte +3 -2
  6. package/dist/components/button/interface.d.ts +4 -2
  7. package/dist/components/card/card.svelte +9 -10
  8. package/dist/components/card/interface.d.ts +4 -4
  9. package/dist/components/cascader/cascader.svelte +11 -18
  10. package/dist/components/cascader/interface.d.ts +3 -2
  11. package/dist/components/cascader/item.svelte +1 -1
  12. package/dist/components/color-picker/color-picker.svelte +16 -1
  13. package/dist/components/cropper/cropper.svelte +4 -4
  14. package/dist/components/cropper/interface.d.ts +4 -3
  15. package/dist/components/date-picker/date-input.svelte +3 -1
  16. package/dist/components/date-picker/date-picker.svelte +9 -10
  17. package/dist/components/date-picker/interface.d.ts +5 -4
  18. package/dist/components/date-picker/internal.d.ts +2 -0
  19. package/dist/components/descriptions/descriptions.svelte +2 -2
  20. package/dist/components/descriptions/interface.d.ts +4 -2
  21. package/dist/components/dropdown/dropdown-popup.svelte +2 -1
  22. package/dist/components/dropdown/dropdown-popup.svelte.d.ts +2 -1
  23. package/dist/components/dropdown/dropdown.svelte +4 -5
  24. package/dist/components/dropdown/interface.d.ts +6 -4
  25. package/dist/components/empty/empty.svelte +2 -2
  26. package/dist/components/empty/interface.d.ts +4 -3
  27. package/dist/components/feedback/feedback.svelte +6 -0
  28. package/dist/components/feedback/interface.d.ts +5 -0
  29. package/dist/components/form/form.svelte +3 -1
  30. package/dist/components/form/index.d.ts +4 -2
  31. package/dist/components/form/index.js +3 -1
  32. package/dist/components/form/interface.d.ts +57 -10
  33. package/dist/components/form/label.svelte +37 -13
  34. package/dist/components/form/schema-form/schema-field.svelte +4 -6
  35. package/dist/components/form/schema-form/schema-form.svelte +2 -2
  36. package/dist/components/form/schema-form/schema-node.svelte +73 -91
  37. package/dist/components/form/schema-form/schema-node.svelte.d.ts +2 -3
  38. package/dist/components/form/schema-form/semi-array.svelte +47 -0
  39. package/dist/components/form/schema-form/semi-array.svelte.d.ts +7 -0
  40. package/dist/components/form/schema-form/semi-field.svelte +42 -0
  41. package/dist/components/form/schema-form/semi-field.svelte.d.ts +8 -0
  42. package/dist/components/form/schema-form/semi-renderers.svelte +24 -0
  43. package/dist/components/form/schema-form/semi-renderers.svelte.d.ts +24 -0
  44. package/dist/components/form/schema-form/semi-section.svelte +22 -0
  45. package/dist/components/form/schema-form/semi-section.svelte.d.ts +10 -0
  46. package/dist/components/form/section.svelte +8 -2
  47. package/dist/components/highlight/highlight.svelte +6 -7
  48. package/dist/components/highlight/interface.d.ts +4 -3
  49. package/dist/components/icon-button/icon-button.svelte +4 -3
  50. package/dist/components/image/image.svelte +4 -4
  51. package/dist/components/image/interface.d.ts +6 -5
  52. package/dist/components/image/preview/preview-image.svelte +1 -1
  53. package/dist/components/image/preview/preview-inner.svelte +10 -18
  54. package/dist/components/image/preview/preview.svelte +4 -4
  55. package/dist/components/input/input.svelte +4 -2
  56. package/dist/components/input/interface.d.ts +6 -5
  57. package/dist/components/input/textarea.svelte +6 -6
  58. package/dist/components/input-number/input-number.svelte +4 -2
  59. package/dist/components/input-number/interface.d.ts +5 -1
  60. package/dist/components/modal/interface.d.ts +5 -3
  61. package/dist/components/modal/modal-content.svelte +26 -32
  62. package/dist/components/modal/modal-content.svelte.d.ts +5 -4
  63. package/dist/components/modal/modal.svelte +4 -4
  64. package/dist/components/navigation/interface.d.ts +8 -4
  65. package/dist/components/navigation/nav-items.svelte +1 -1
  66. package/dist/components/navigation/nav.svelte +3 -2
  67. package/dist/components/navigation/sub-nav.svelte +5 -4
  68. package/dist/components/overflow-list/interface.d.ts +4 -3
  69. package/dist/components/overflow-list/overflow-list.svelte +3 -3
  70. package/dist/components/pagination/interface.d.ts +1 -1
  71. package/dist/components/pagination/pagination.svelte +63 -61
  72. package/dist/components/popconfirm/interface.d.ts +3 -0
  73. package/dist/components/popconfirm/popconfirm.svelte +4 -4
  74. package/dist/components/popover/arrow.svelte +2 -2
  75. package/dist/components/popover/interface.d.ts +8 -3
  76. package/dist/components/popover/popover.svelte +4 -4
  77. package/dist/components/radio/interface.d.ts +6 -5
  78. package/dist/components/radio/radio-group.svelte +2 -2
  79. package/dist/components/radio/radio.svelte +4 -4
  80. package/dist/components/select/interface.d.ts +3 -2
  81. package/dist/components/select/option.svelte +1 -1
  82. package/dist/components/select/select.svelte +9 -14
  83. package/dist/components/side-sheet/interface.d.ts +6 -5
  84. package/dist/components/side-sheet/side-sheet.svelte +31 -29
  85. package/dist/components/slider/interface.d.ts +4 -2
  86. package/dist/components/slider/slider.svelte +3 -2
  87. package/dist/components/spin/icon.svelte +1 -1
  88. package/dist/components/spin/interface.d.ts +4 -3
  89. package/dist/components/spin/spin.svelte +2 -3
  90. package/dist/components/switch/switch.svelte +1 -1
  91. package/dist/components/table/body/body.svelte +21 -8
  92. package/dist/components/table/context.d.ts +2 -1
  93. package/dist/components/table/interface.d.ts +4 -3
  94. package/dist/components/table/table-header/table-header-row.svelte +15 -3
  95. package/dist/components/table/table.svelte +38 -8
  96. package/dist/components/tabs/interface.d.ts +8 -7
  97. package/dist/components/tabs/tab-bar.svelte +12 -2
  98. package/dist/components/tabs/tabs.svelte +7 -8
  99. package/dist/components/time-picker/interface.d.ts +4 -4
  100. package/dist/components/time-picker/time-input.svelte +2 -2
  101. package/dist/components/time-picker/time-picker.svelte +10 -11
  102. package/dist/components/tooltip/interface.d.ts +5 -2
  103. package/dist/components/tooltip/tooltip.svelte +13 -38
  104. package/dist/components/tree/interface.d.ts +4 -3
  105. package/dist/components/tree/node-arrow.svelte +1 -1
  106. package/dist/components/tree/tree-node.svelte +1 -1
  107. package/dist/components/tree/tree.svelte +23 -74
  108. package/dist/components/tree-select/interface.d.ts +4 -5
  109. package/dist/components/tree-select/tree-select.svelte +28 -67
  110. package/dist/components/typography/base.svelte +1 -1
  111. package/dist/components/upload/file-card.svelte +1 -1
  112. package/dist/components/upload/interface.d.ts +5 -3
  113. package/dist/components/upload/upload.svelte +6 -4
  114. package/dist/components/user-guide/user-guide.svelte +15 -1
  115. package/dist/hooks/index.d.ts +1 -0
  116. package/dist/hooks/index.js +1 -0
  117. package/dist/hooks/use-overlay-resources.svelte.d.ts +13 -0
  118. package/dist/hooks/use-overlay-resources.svelte.js +20 -0
  119. package/dist/internal/virtual-list.svelte +11 -1
  120. package/dist/internal/virtual-list.svelte.d.ts +7 -0
  121. package/dist/styles.css +1 -1
  122. package/package.json +3 -3
  123. package/dist/components/tree/use-tree-keyboard.svelte.d.ts +0 -29
  124. package/dist/components/tree/use-tree-keyboard.svelte.js +0 -61
@@ -1,7 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { ClassValue, HTMLInputAttributes } from 'svelte/elements';
3
3
  import type { TimeStamp } from '@fibrae/semi-foundation/components/time-picker/combobox-options';
4
- import type { PanelType } from '@fibrae/semi-foundation/components/time-picker/constants';
4
+ import type { PanelType, TimePickerPart } from '@fibrae/semi-foundation/components/time-picker/constants';
5
5
  import type { DisabledTimeFns } from '@fibrae/semi-foundation/components/time-picker/foundation';
6
6
  import type { InputProps, InputSize, ValidateStatus } from '../input/index.js';
7
7
  import type { ScrollItemProps } from '../scroll-list/index.js';
@@ -49,7 +49,9 @@ export interface TimePickerProps extends Omit<HTMLInputAttributes, NativeInputKe
49
49
  inputReadOnly?: boolean;
50
50
  validateStatus?: ValidateStatus;
51
51
  insetLabelId?: string;
52
- inputStyle?: string;
52
+ /** `dropdown` is the panel card; `input` is the Input's root element */
53
+ classNames?: Partial<Record<TimePickerPart, ClassValue>>;
54
+ styles?: Partial<Record<TimePickerPart, string>>;
53
55
  autofocus?: boolean;
54
56
  /** Focuses and selects the input once mounted */
55
57
  focusOnOpen?: boolean;
@@ -57,8 +59,6 @@ export interface TimePickerProps extends Omit<HTMLInputAttributes, NativeInputKe
57
59
  motion?: boolean;
58
60
  autoAdjustOverflow?: boolean;
59
61
  position?: Position;
60
- popupClassName?: ClassValue;
61
- popupStyle?: string;
62
62
  stopPropagation?: boolean;
63
63
  /** Falls back to ConfigProvider's timeZone */
64
64
  timeZone?: string | number;
@@ -9,7 +9,7 @@
9
9
  type Foundation = TimeInputFoundation<TimeInputProps, FocusEvent>;
10
10
  type Adapter = TimeInputAdapter<TimeInputProps, FocusEvent>;
11
11
 
12
- let { value, inputReadOnly = false, invalid = false, validateStatus, focusOnOpen = false, preventScroll, onChange, onFocus, onBlur, ...rest }: TimeInputProps = $props();
12
+ let { class: className, value, inputReadOnly = false, invalid = false, validateStatus, focusOnOpen = false, preventScroll, onChange, onFocus, onBlur, ...rest }: TimeInputProps = $props();
13
13
 
14
14
  let input = $state<Input>();
15
15
 
@@ -44,7 +44,7 @@
44
44
  bind:this={input}
45
45
  {...rest}
46
46
  bind:value={() => value, (next) => foundation.handleChange(String(next ?? ''))}
47
- class={[`${prefix}-input`, { [`${prefix}-input-invalid`]: invalid, [`${prefix}-input-readonly`]: inputReadOnly }]}
47
+ class={[`${prefix}-input`, { [`${prefix}-input-invalid`]: invalid, [`${prefix}-input-readonly`]: inputReadOnly }, className]}
48
48
  hideSuffix
49
49
  onBlur={foundation.handleBlur}
50
50
  onFocus={foundation.handleFocus}
@@ -52,15 +52,14 @@
52
52
  inputReadOnly = defaults('inputReadOnly', false),
53
53
  validateStatus = defaults('validateStatus'),
54
54
  insetLabelId,
55
- inputStyle = defaults('inputStyle'),
55
+ classNames = defaults('classNames'),
56
+ styles = defaults('styles'),
56
57
  autofocus = defaults('autofocus', false),
57
58
  focusOnOpen = defaults('focusOnOpen', false),
58
59
  preventScroll = defaults('preventScroll'),
59
60
  motion = defaults('motion', true),
60
61
  autoAdjustOverflow = defaults('autoAdjustOverflow', true),
61
62
  position = defaults('position'),
62
- popupClassName = defaults('popupClassName'),
63
- popupStyle = defaults('popupStyle'),
64
63
  stopPropagation = defaults('stopPropagation', true),
65
64
  // read below: ConfigProvider's timeZone comes before the global default
66
65
  timeZone,
@@ -178,7 +177,7 @@
178
177
 
179
178
  // class and style size the root; every other attribute names and identifies the input
180
179
  const attrs = $derived(trigger ? { root: rest as Record<string, unknown>, control: {} } : splitControlAttrs(rest, (key) => key !== 'class' && key !== 'style'));
181
- const panelClass = $derived([...TimePickerFoundation.getPanelClassNames({ prefixCls, format, use12Hours, type }), `${prefixCls}-panel-${size}`, popupClassName]);
180
+ const panelClass = $derived([...TimePickerFoundation.getPanelClassNames({ prefixCls, format, use12Hours, type }), `${prefixCls}-panel-${size}`, classNames?.dropdown]);
182
181
 
183
182
  const triggerProps: TimePickerTriggerRenderProps = $derived({
184
183
  value: states().value,
@@ -208,15 +207,12 @@
208
207
  inputReadOnly,
209
208
  validateStatus,
210
209
  insetLabelId,
211
- inputStyle,
212
210
  autofocus,
213
211
  focusOnOpen,
214
212
  preventScroll,
215
213
  motion,
216
214
  autoAdjustOverflow,
217
215
  position,
218
- popupClassName,
219
- popupStyle,
220
216
  stopPropagation,
221
217
  timeZone,
222
218
  scrollItemProps,
@@ -264,6 +260,8 @@
264
260
  }
265
261
  </script>
266
262
 
263
+ <svelte:document onfocusin={(event) => foundation.handleDocumentFocusIn(event, root)} />
264
+
267
265
  {#snippet content()}
268
266
  <div bind:this={panelElement} class={{ [cssClasses.RANGE_PANEL_LISTS]: isRange }} id={panelId}>
269
267
  {#each isRange ? [0, 1] : [0] as index (index)}
@@ -292,14 +290,14 @@
292
290
  {/snippet}
293
291
 
294
292
  <div bind:this={root} {...attrs.root} class={[prefixCls, rest.class]} role={trigger && (rest['aria-label'] || rest['aria-labelledby']) ? 'group' : undefined} onclick={handleRootClick}>
295
- <Popover aria-label={locale().locale.panel[type]} {autoAdjustOverflow} {content} contentClassName={panelClass} {motion} onEscKeyDown={foundation.handleEscKeyDown} position={popupPosition} {stopPropagation} style={popupStyle} trigger="custom" visible={shown}>
293
+ <Popover aria-label={locale().locale.panel[type]} {autoAdjustOverflow} classNames={{ content: panelClass }} {content} {motion} onEscKeyDown={foundation.handleEscKeyDown} position={popupPosition} {stopPropagation} styles={{ content: styles?.dropdown }} trigger="custom" visible={shown}>
296
294
  {#snippet child({ props })}
297
295
  {#if trigger}
298
296
  <!-- the wrapper is the Tab stop and the button only while the trigger has no focus target of its own -->
299
297
  <div
300
298
  bind:this={triggerWrapper}
301
299
  {...props}
302
- aria-controls={isTriggerButton ? panelId : undefined}
300
+ aria-controls={isTriggerButton && shown ? panelId : undefined}
303
301
  aria-disabled={isTriggerButton ? disabled : undefined}
304
302
  aria-expanded={isTriggerButton ? shown : undefined}
305
303
  aria-haspopup={isTriggerButton ? 'dialog' : undefined}
@@ -314,11 +312,12 @@
314
312
  <span {...props} class={`${prefixCls}-header`} tabindex="-1">
315
313
  <TimeInput
316
314
  {...attrs.control}
317
- aria-controls={panelId}
315
+ aria-controls={shown ? panelId : undefined}
318
316
  aria-expanded={shown}
319
317
  aria-haspopup="dialog"
320
318
  {autofocus}
321
319
  {borderless}
320
+ class={classNames?.input}
322
321
  {clearIcon}
323
322
  {disabled}
324
323
  {focusOnOpen}
@@ -335,7 +334,7 @@
335
334
  role="combobox"
336
335
  showClear={disabled ? false : showClear}
337
336
  {size}
338
- style={inputStyle}
337
+ style={styles?.input}
339
338
  {validateStatus}
340
339
  value={states().inputValue}
341
340
  />
@@ -1,6 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { Attachment } from 'svelte/attachments';
3
- import type { strings } from '@fibrae/semi-foundation/components/tooltip/constants';
3
+ import type { ClassValue } from 'svelte/elements';
4
+ import type { strings, TooltipPart } from '@fibrae/semi-foundation/components/tooltip/constants';
4
5
  import type { Position, TooltipBaseProps } from '@fibrae/semi-foundation/components/tooltip/foundation';
5
6
  import type { POPUP_ID_ATTRIBUTE } from '@fibrae/semi-foundation/utils';
6
7
  export type { Position } from '@fibrae/semi-foundation/components/tooltip/foundation';
@@ -52,7 +53,9 @@ export interface TooltipProps extends TooltipBaseProps {
52
53
  'aria-describedby'?: string;
53
54
  arrowPointAtCenter?: boolean;
54
55
  stopPropagation?: boolean;
55
- wrapperClassName?: string;
56
+ /** `wrapper` exists only when the trigger is wrapped: text, several nodes, or a disabled or loading trigger */
57
+ classNames?: Partial<Record<TooltipPart, ClassValue>>;
58
+ styles?: Partial<Record<TooltipPart, string>>;
56
59
  wrapperId?: string;
57
60
  /**
58
61
  * Whether a disabled or loading Semi Button, Switch or Checkbox that fills the default span gets its pointer events
@@ -52,7 +52,8 @@
52
52
  preventScroll = defaults('preventScroll'),
53
53
  // an id shared by every Tooltip would break the popup's references, so the global default is not read
54
54
  wrapperId,
55
- wrapperClassName = defaults('wrapperClassName'),
55
+ classNames = defaults('classNames'),
56
+ styles = defaults('styles'),
56
57
  wrapWhenSpecial = defaults('wrapWhenSpecial', true),
57
58
  'aria-label': ariaLabel = defaults('aria-label'),
58
59
  'aria-labelledby': ariaLabelledby = defaults('aria-labelledby'),
@@ -80,7 +81,6 @@
80
81
  let focusableInside = $state(false);
81
82
  let textOnly = $state(false);
82
83
  let initialFocus: FocusTarget | undefined;
83
- let clickOutside: AbortController | undefined;
84
84
  let warnedFocusable = false;
85
85
 
86
86
  // The value this Tooltip last wrote to an uncontrolled `visible`: the foundation still sees it as uncontrolled, so
@@ -177,20 +177,6 @@
177
177
  removePortal: () => {
178
178
  contentShown = false;
179
179
  },
180
- showPopover: () => {
181
- if (!container?.matches(':popover-open')) {
182
- container?.showPopover();
183
- }
184
- },
185
- hidePopover: () => container?.hidePopover(),
186
- // shortcut: a leave set by a prop reaction (handlePropsChange runs in a host effect created before the
187
- // phase effect) reaches syncPopup before the template drops the show class, so the animations are read
188
- // after tick(). Read them at once again when the host runs prop reactions after the component's effects.
189
- waitAnimations: () =>
190
- tick().then(() => {
191
- const animations = container?.getAnimations() ?? [];
192
- return animations.length ? Promise.allSettled(animations.map((animation) => animation.finished)) : undefined;
193
- }),
194
180
  notifyAfterOpen: () => afterOpen?.(),
195
181
  notifyAfterClose: () => afterClose?.(),
196
182
  notifyVisibleChange: (next) => {
@@ -203,17 +189,9 @@
203
189
  selfWritten = uncontrolled && visible === next ? next : undefined;
204
190
  onVisibleChange?.(next);
205
191
  },
206
- registerClickOutsideHandler: (handler) => {
207
- clickOutside?.abort();
208
- clickOutside = new AbortController();
209
- window.addEventListener('mousedown', handler, { signal: clickOutside.signal });
210
- },
211
- unregisterClickOutsideHandler: () => {
212
- clickOutside?.abort();
213
- clickOutside = undefined;
214
- },
215
192
  isEventInTrigger: (event) => isEventInside(event, triggerElement),
216
- isEventInPopup: (event) => isEventInside(event, container, ...nestedPopups()),
193
+ getNestedPopups: () => nestedPopups(),
194
+ batch: (fn) => fn(),
217
195
  notifyClickOutSide: (event) => onClickOutSide?.(event),
218
196
  getPortalContainer: () => container,
219
197
  getTriggerNode: () => triggerElement,
@@ -274,6 +252,9 @@
274
252
  // A loading Button keeps the description itself, as do components that route aria-describedby to their own control
275
253
  const describes = $derived(status === strings.STATUS_LOADING || Boolean(triggerState?.describes));
276
254
  const blockTrigger = $derived(Boolean(triggerState?.block || (inner && isBlockDisplay(inner.style.display))));
255
+
256
+ // one string rather than style: directives, which would beat the caller's styles.wrapper
257
+ const wrapperStyle = $derived([status === strings.STATUS_DISABLED && wrapsSpecial && 'cursor: not-allowed', !textOnly && 'display: inline-block', blockTrigger && 'width: 100%', styles?.wrapper].filter(Boolean).join('; ') || undefined);
277
258
  const spanTabindex = $derived(focusableInside || status === strings.STATUS_LOADING ? -1 : 0);
278
259
 
279
260
  // Popover and Dropdown hand their class prefix to this Tooltip only, not to Tooltips rendered in its trigger or content
@@ -434,8 +415,11 @@
434
415
  $effect(() => {
435
416
  void phase;
436
417
  void container;
437
- // only the phase and the popup element drive it; what the sync reads (layout, props) must not
438
- untrack(foundation.syncPopup);
418
+ // only the phase and the popup element drive it; what the sync reads (layout, props) must not.
419
+ // shortcut: a leave set by a prop reaction (handlePropsChange runs in a host effect created before this one)
420
+ // reaches the sync before the template drops the show class, so the animations are read after tick(). Read
421
+ // them at once again when the host runs prop reactions after the component's effects.
422
+ untrack(() => foundation.syncPopup(tick()));
439
423
  });
440
424
 
441
425
  // showPopover() ran its autofocus step before the content mounted; syncPopup measured the popup without its
@@ -504,16 +488,7 @@
504
488
  {#if child}
505
489
  {@render child({ props: triggerProps })}
506
490
  {:else}
507
- <span
508
- {@attach attachTrigger}
509
- {...{ [POPUP_ID_ATTRIBUTE]: popupId }}
510
- aria-describedby={describes ? undefined : describedBy}
511
- class={[`${cssClasses.PREFIX}-trigger-wrapper`, wrapperClassName]}
512
- style:cursor={status === strings.STATUS_DISABLED && wrapsSpecial ? 'not-allowed' : undefined}
513
- style:display={textOnly ? undefined : 'inline-block'}
514
- style:width={blockTrigger ? '100%' : undefined}
515
- tabindex={spanTabindex}
516
- >
491
+ <span {@attach attachTrigger} {...{ [POPUP_ID_ATTRIBUTE]: popupId }} aria-describedby={describes ? undefined : describedBy} class={[`${cssClasses.PREFIX}-trigger-wrapper`, classNames?.wrapper]} style={wrapperStyle} tabindex={spanTabindex}>
517
492
  {@render children?.()}
518
493
  </span>
519
494
  {/if}{#if portalTarget}
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { TreePart } from '@fibrae/semi-foundation/components/tree/constants';
3
4
  import type { BasicExpandedOtherProps, BasicFlattenNode, BasicOnDragProps, BasicTreeNodeData, BasicTreeNodeProps, CheckRelation, ExpandAction, KeyMapProps, ScrollAlign, TreeDataSimpleJson, TreeMotionType, Virtualize } from '@fibrae/semi-foundation/components/tree/foundation';
4
5
  export type { TreeDataSimpleJson } from '@fibrae/semi-foundation/components/tree/foundation';
5
6
  export type TreeKeyMapProps = KeyMapProps;
@@ -129,9 +130,9 @@ export interface TreeProps extends Omit<HTMLAttributes<HTMLDivElement>, NativeKe
129
130
  /** On by default for a virtualized tree */
130
131
  labelEllipsis?: boolean;
131
132
  virtualize?: TreeVirtualize;
132
- searchClassName?: string;
133
+ classNames?: Partial<Record<TreePart, ClassValue>>;
134
+ styles?: Partial<Record<TreePart, string>>;
133
135
  searchPlaceholder?: string;
134
- searchStyle?: string;
135
136
  filterTreeNode?: boolean | ((inputValue: string, treeNodeString: string, data?: TreeNodeData) => boolean);
136
137
  /** Loads a node's children; a node without `isLeaf` shows the expand arrow while it is set */
137
138
  loadData?: (treeNode?: TreeNodeData) => Promise<void>;
@@ -25,7 +25,7 @@
25
25
 
26
26
  <!-- the row carries aria-busy; the spinner's own name would join the row's name -->
27
27
  {#if row.loading}
28
- <Spin aria-hidden="true" wrapperClassName="{prefix}-spin-icon" />
28
+ <Spin aria-hidden="true" class="{prefix}-spin-icon" />
29
29
  {:else if !isLeaf}
30
30
  {#if expandIcon}
31
31
  {@render expandIcon({ onClick: onExpand, class: iconClass, expanded: Boolean(row.expanded) })}
@@ -206,7 +206,7 @@
206
206
  {#if label}
207
207
  {@render label({ item: row.data, label: row.label, searchWord: row.keyword })}
208
208
  {:else if highlighted}
209
- <Highlight component="span" highlightClassName="{prefix}-highlight" searchWords={[row.keyword]} sourceString={String(row.label)} />
209
+ <Highlight classNames={{ highlight: `${prefix}-highlight` }} component="span" searchWords={[row.keyword]} sourceString={String(row.label)} />
210
210
  {:else}
211
211
  {row.label}
212
212
  {/if}
@@ -3,7 +3,7 @@
3
3
  import { isEqual } from 'es-toolkit';
4
4
  import { cssClasses } from '@fibrae/semi-foundation/components/tree/constants';
5
5
  import TreeFoundation, { type BasicTreeInnerData, type BasicTreeNodeData, type BasicTreeProps, type TreeAdapter } from '@fibrae/semi-foundation/components/tree/foundation';
6
- import { buildRowProps, getClearedSelection, nodeId } from '@fibrae/semi-foundation/components/tree/shared';
6
+ import { buildRowProps, getClearedSelection, handleTreeFocusIn, nodeId } from '@fibrae/semi-foundation/components/tree/shared';
7
7
  import '@fibrae/semi-foundation/components/tree/tree.css';
8
8
  import { IconSearch } from '@fibrae/semi-icons-svelte';
9
9
  import { useDefaultProps, useFoundation } from '../../base/index.js';
@@ -17,7 +17,6 @@
17
17
  import type { FlattenNode, TreeExpandedOtherProps, TreeNodeData, TreeProps, TreeRowProps, TreeScrollData, TreeValue } from './interface.js';
18
18
  import NodeList from './node-list.svelte';
19
19
  import TreeNode from './tree-node.svelte';
20
- import useTreeKeyboard from './use-tree-keyboard.svelte.js';
21
20
 
22
21
  type Foundation = TreeFoundation<MouseEvent>;
23
22
  type Adapter = TreeAdapter<MouseEvent>;
@@ -56,9 +55,9 @@
56
55
  treeNodeFilterProp = defaults('treeNodeFilterProp', 'label'),
57
56
  labelEllipsis = defaults('labelEllipsis'),
58
57
  virtualize = defaults('virtualize'),
59
- searchClassName = defaults('searchClassName'),
58
+ classNames = defaults('classNames'),
60
59
  searchPlaceholder = defaults('searchPlaceholder'),
61
- searchStyle = defaults('searchStyle'),
60
+ styles = defaults('styles'),
62
61
  filterTreeNode = defaults('filterTreeNode', false),
63
62
  loadData = defaults('loadData'),
64
63
  onChange,
@@ -232,33 +231,22 @@
232
231
  nodeList?.scrollToItem(index, align);
233
232
  }
234
233
  }),
235
- })
234
+ revealRow: (index, key) => {
235
+ if (!nodeList?.scrollToItem(index)) {
236
+ // inside the tree, not the document: a tree in a ShadowRoot is out of document.getElementById's reach
237
+ treeRoot?.querySelector(`#${CSS.escape(nodeId(treeId, key))}`)?.scrollIntoView({ block: 'nearest' });
238
+ }
239
+ },
240
+ }),
241
+ { context: () => ({ direction: config.direction }) }
236
242
  );
237
243
 
238
- const keyboard = useTreeKeyboard({
239
- rows: () => view.flattenNodes as FlattenNode[],
240
- defaultIndex: () =>
241
- Math.max(
242
- view.flattenNodes.findIndex((node) => view.selectedKeys.includes(node.key!)),
243
- 0
244
- ),
245
- rowProps: (node) => rowProps(node),
246
- hasLoadData: () => Boolean(loadData),
247
- rtl: () => config.direction === 'rtl',
248
- select: foundation.handleNodeSelect,
249
- expand: foundation.handleNodeExpand,
250
- reveal: (index, key) => {
251
- if (!nodeList?.scrollToItem(index)) {
252
- // inside the tree, not the document: a tree in a ShadowRoot is out of document.getElementById's reach
253
- treeRoot?.querySelector(`#${CSS.escape(nodeId(treeId, key))}`)?.scrollIntoView({ block: 'nearest' });
254
- }
255
- },
256
- });
257
-
258
244
  // State implied by new props renders with them; the pre-effect writes it back for the handlers before render
259
245
  // not named `derived`: a local of that name turns the `$derived` rune into a store subscription
260
246
  const implied = $derived(TreeFoundation.deriveState(foundationProps, states()));
261
247
  const view = $derived<BasicTreeInnerData>(implied ? { ...states(), ...implied } : states());
248
+ const activeIndex = $derived(TreeFoundation.getActiveIndex(view));
249
+ const activeKey = $derived(view.flattenNodes[activeIndex]?.key);
262
250
 
263
251
  const noData = $derived.by(() => {
264
252
  const { keyEntities, inputValue, filteredKeys } = view;
@@ -294,26 +282,11 @@
294
282
  get dropPosition() {
295
283
  return view.dropPosition;
296
284
  },
297
- onNodeExpand: (event, row) => {
298
- keyboard.activate(row.key);
299
- foundation.handleNodeExpand(event, row);
300
- },
301
- onNodeSelect: (event, row) => {
302
- keyboard.activate(row.key);
303
- foundation.handleNodeSelect(event, row);
304
- },
305
- onNodeCheck: (event, row) => {
306
- keyboard.activate(row.key);
307
- foundation.handleNodeSelect(event, row);
308
- },
309
- onNodeRightClick: (event, row) => {
310
- keyboard.activate(row.key);
311
- foundation.handleNodeRightClick(event, row);
312
- },
313
- onNodeDoubleClick: (event, row) => {
314
- keyboard.activate(row.key);
315
- foundation.handleNodeDoubleClick(event, row);
316
- },
285
+ onNodeExpand: foundation.handleNodeExpand,
286
+ onNodeSelect: foundation.handleNodeSelect,
287
+ onNodeCheck: foundation.handleNodeSelect,
288
+ onNodeRightClick: foundation.handleNodeRightClick,
289
+ onNodeDoubleClick: foundation.handleNodeDoubleClick,
317
290
  onNodeDragStart: foundation.handleNodeDragStart,
318
291
  onNodeDragEnter: foundation.handleNodeDragEnter,
319
292
  onNodeDragOver: foundation.handleNodeDragOver,
@@ -338,31 +311,7 @@
338
311
 
339
312
  const handleSearch = (input: string) => foundation.handleInputChange(input);
340
313
 
341
- const handleTreeKeyDown = (event: KeyboardEvent) => {
342
- // a tabbable control inside a row handles its own keys
343
- if (event.target !== event.currentTarget && event.target instanceof HTMLElement && event.target.tabIndex >= 0) {
344
- return;
345
- }
346
- keyboard.handleKeyDown(event);
347
- };
348
-
349
- const handleTreeFocus = (event: FocusEvent & { currentTarget: HTMLElement }) => {
350
- const tree = event.currentTarget;
351
- const target = event.target;
352
- if (target !== tree) {
353
- // A click focuses the tabindex=-1 element it lands on (the virtual scroller, a row's checkbox); the tree takes
354
- // focus back, so aria-activedescendant and the row's focus ring keep working.
355
- if (target instanceof HTMLElement && target.tabIndex < 0) {
356
- tree.focus({ preventScroll: true });
357
- }
358
- return;
359
- }
360
- // A virtual list may not have rendered the active descendant yet. Pointer focus is skipped: mousedown focuses the
361
- // tree before click, and scrolling back to the stale active row would unmount the clicked row.
362
- if (tree.matches(':focus-visible')) {
363
- nodeList?.scrollToItem(keyboard.activeIndex);
364
- }
365
- };
314
+ const handleTreeFocus = (event: FocusEvent & { currentTarget: HTMLElement }) => handleTreeFocusIn(event, () => nodeList?.scrollToItem(activeIndex));
366
315
 
367
316
  $effect.pre(() => {
368
317
  if (implied) {
@@ -399,7 +348,7 @@
399
348
 
400
349
  <div {...attrs.root} class={[`${prefixCls}-wrapper`, rest.class]}>
401
350
  {#if filterTreeNode && searchBox !== false}
402
- <div class={[`${prefixCls}-search-wrapper`, searchClassName]} style={searchStyle}>
351
+ <div class={[`${prefixCls}-search-wrapper`, classNames?.search]} style={styles?.search}>
403
352
  {#if searchBox}
404
353
  {@render searchBox({ class: `${prefixCls}-input`, value: view.inputValue, placeholder, showClear, onChange: handleSearch })}
405
354
  {:else}
@@ -427,19 +376,19 @@
427
376
  <ul
428
377
  bind:this={treeRoot}
429
378
  {...attrs.control}
430
- aria-activedescendant={keyboard.activeKey === undefined ? undefined : nodeId(treeId, keyboard.activeKey)}
379
+ aria-activedescendant={activeKey === undefined ? undefined : nodeId(treeId, activeKey)}
431
380
  aria-multiselectable={multiple}
432
381
  class={listClass}
433
382
  role="tree"
434
383
  tabindex={(attrs.control.tabindex as number | undefined) ?? 0}
435
384
  onfocusin={handleTreeFocus}
436
- onkeydown={handleTreeKeyDown}
385
+ onkeydown={foundation.handleKeyDown}
437
386
  >
438
387
  <NodeList bind:this={nodeList} flattenList={view.cachedFlattenNodes} flattenNodes={view.flattenNodes} {motion} motionKeys={view.motionKeys} motionType={view.motionType} {virtualize}>
439
388
  {#snippet children({ node, style })}
440
389
  {@const row = rowProps(node)}
441
390
  {#if row}
442
- <TreeNode {expandIcon} focused={row.key === keyboard.activeKey} {fullLabel} {icon} id={nodeId(treeId, row.key)} {label} {row} rowStyle={style} {showLine} />
391
+ <TreeNode {expandIcon} focused={row.key === activeKey} {fullLabel} {icon} id={nodeId(treeId, row.key)} {label} {row} rowStyle={style} {showLine} />
443
392
  {/if}
444
393
  {/snippet}
445
394
  </NodeList>
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { TreeSelectPart } from '@fibrae/semi-foundation/components/tree-select/constants';
3
4
  import type { CheckRelation, ExpandAction } from '@fibrae/semi-foundation/components/tree/foundation';
4
5
  import type { Size } from '@fibrae/semi-foundation/utils';
5
6
  import type { ValidateStatus } from '../input/index.js';
@@ -122,11 +123,9 @@ export interface TreeSelectProps extends Omit<HTMLAttributes<HTMLDivElement>, Na
122
123
  autoAdjustOverflow?: boolean;
123
124
  position?: Position;
124
125
  stopPropagation?: boolean | string;
125
- dropdownClassName?: string;
126
- dropdownStyle?: string;
126
+ classNames?: Partial<Record<TreeSelectPart, ClassValue>>;
127
+ styles?: Partial<Record<TreeSelectPart, string>>;
127
128
  dropdownMatchSelectWidth?: boolean;
128
- /** Goes on the `role="tree"` element */
129
- optionListStyle?: string;
130
129
  preventScroll?: boolean;
131
130
  triggerTagWrap?: boolean;
132
131
  /** With `onChangeWithObject` the value and the node are both the node */