@fibrae/semi-ui-svelte 0.7.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 (26) hide show
  1. package/dist/components/form/form.svelte +3 -1
  2. package/dist/components/form/index.d.ts +4 -2
  3. package/dist/components/form/index.js +3 -1
  4. package/dist/components/form/interface.d.ts +57 -10
  5. package/dist/components/form/label.svelte +37 -13
  6. package/dist/components/form/schema-form/schema-field.svelte +4 -6
  7. package/dist/components/form/schema-form/schema-form.svelte +2 -2
  8. package/dist/components/form/schema-form/schema-node.svelte +73 -91
  9. package/dist/components/form/schema-form/schema-node.svelte.d.ts +2 -3
  10. package/dist/components/form/schema-form/semi-array.svelte +47 -0
  11. package/dist/components/form/schema-form/semi-array.svelte.d.ts +7 -0
  12. package/dist/components/form/schema-form/semi-field.svelte +42 -0
  13. package/dist/components/form/schema-form/semi-field.svelte.d.ts +8 -0
  14. package/dist/components/form/schema-form/semi-renderers.svelte +24 -0
  15. package/dist/components/form/schema-form/semi-renderers.svelte.d.ts +24 -0
  16. package/dist/components/form/schema-form/semi-section.svelte +22 -0
  17. package/dist/components/form/schema-form/semi-section.svelte.d.ts +10 -0
  18. package/dist/components/form/section.svelte +8 -2
  19. package/dist/components/spin/icon.svelte +1 -1
  20. package/dist/components/table/body/body.svelte +21 -8
  21. package/dist/components/table/table-header/table-header-row.svelte +13 -2
  22. package/dist/components/table/table.svelte +31 -5
  23. package/dist/internal/virtual-list.svelte +11 -1
  24. package/dist/internal/virtual-list.svelte.d.ts +7 -0
  25. package/dist/styles.css +1 -1
  26. package/package.json +3 -3
@@ -0,0 +1,24 @@
1
+ import type { SchemaFieldRenderers } from '../interface.js';
2
+ /**
3
+ * Renders SchemaField with Semi Form controls: objects and arrays as Sections, array rows with move and remove buttons,
4
+ * single-value rows without a label. Spread it to replace one kind: `{ ...semiRenderers, array: myArray }`.
5
+ */
6
+ export declare const semiRenderers: Required<SchemaFieldRenderers>;
7
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
8
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
9
+ $$bindings?: Bindings;
10
+ } & Exports;
11
+ (internal: unknown, props: {
12
+ $$events?: Events;
13
+ $$slots?: Slots;
14
+ }): Exports & {
15
+ $set?: any;
16
+ $on?: any;
17
+ };
18
+ z_$$bindings?: Bindings;
19
+ }
20
+ declare const SemiRenderers: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
21
+ [evt: string]: CustomEvent<any>;
22
+ }, {}, {}, string>;
23
+ type SemiRenderers = InstanceType<typeof SemiRenderers>;
24
+ export default SemiRenderers;
@@ -0,0 +1,22 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { SchemaFieldNode } from '@fibrae/semi-foundation/components/form/json-schema';
4
+ import { formatLocale } from '@fibrae/semi-foundation/locale';
5
+ import useLocale from '../../locale/use-locale.svelte.js';
6
+ import FormSection from '../section.svelte';
7
+
8
+ let { node, children, ...rest }: { node: SchemaFieldNode; children: Snippet; 'x-field-id'?: string } = $props();
9
+
10
+ const locale = useLocale('Form');
11
+ </script>
12
+
13
+ {#snippet text()}{node.title ?? formatLocale(locale().locale.item, { index: (node.item?.index ?? 0) + 1 })}{/snippet}
14
+
15
+ {#snippet extraText()}{node.description}{/snippet}
16
+
17
+ <!-- The root renders no Section: the Form already is its group -->
18
+ {#if node.field === ''}
19
+ {@render children()}
20
+ {:else}
21
+ <FormSection {...rest} extraText={node.description ? extraText : undefined} {text}>{@render children()}</FormSection>
22
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { SchemaFieldNode } from '@fibrae/semi-foundation/components/form/json-schema';
3
+ type $$ComponentProps = {
4
+ node: SchemaFieldNode;
5
+ children: Snippet;
6
+ 'x-field-id'?: string;
7
+ };
8
+ declare const SemiSection: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type SemiSection = ReturnType<typeof SemiSection>;
10
+ export default SemiSection;
@@ -1,15 +1,21 @@
1
1
  <script lang="ts">
2
2
  import { cssClasses } from '@fibrae/semi-foundation/components/form/constants';
3
+ import { joinIds } from '@fibrae/semi-foundation/utils';
3
4
  import '@fibrae/semi-foundation/components/form/form.css';
4
5
  import type { SectionProps } from './interface.js';
5
6
 
6
- let { text, children, ...rest }: SectionProps = $props();
7
+ let { text, extraText, children, ...rest }: SectionProps = $props();
8
+
9
+ const extraId = $props.id();
7
10
  </script>
8
11
 
9
- <fieldset {...rest} class={[`${cssClasses.PREFIX}-section`, rest.class]}>
12
+ <fieldset {...rest} aria-describedby={joinIds(rest['aria-describedby'], extraText && extraId)} class={[`${cssClasses.PREFIX}-section`, rest.class]}>
10
13
  <!-- an empty legend would still draw its divider -->
11
14
  {#if text}
12
15
  <legend class={`${cssClasses.PREFIX}-section-text`}>{@render text()}</legend>
13
16
  {/if}
17
+ {#if extraText}
18
+ <div class={`${cssClasses.PREFIX}-section-extra`} id={extraId}>{@render extraText()}</div>
19
+ {/if}
14
20
  {@render children?.()}
15
21
  </fieldset>
@@ -4,7 +4,7 @@
4
4
  const gradientId = `linearGradient-${uid}`;
5
5
  </script>
6
6
 
7
- <svg aria-hidden="true" data-icon="spin" height="48" version="1.1" viewBox="0 0 36 36" width="48" xmlns="http://www.w3.org/2000/svg">
7
+ <svg aria-hidden="true" data-icon="spin" height="48" viewBox="0 0 36 36" width="48" xmlns="http://www.w3.org/2000/svg">
8
8
  <defs>
9
9
  <linearGradient id={gradientId} x1="0%" x2="100%" y1="100%" y2="100%">
10
10
  <stop offset="0%" stop-color="currentColor" stop-opacity="0" />
@@ -54,6 +54,8 @@
54
54
  let bodyElement = $state<HTMLDivElement>();
55
55
  let listElement = $state<HTMLElement>();
56
56
  let list = $state<ReturnType<typeof VirtualList>>();
57
+ let listHeader = $state<HTMLDivElement>();
58
+ let listHeaderHeight = $state(0);
57
59
  let hoveredRowKey = $state<BaseRowKeyType | null>(null);
58
60
 
59
61
  // whether the body overflows, so it takes keyboard focus to scroll; known after mount
@@ -98,13 +100,12 @@
98
100
  if (!table.virtualized) {
99
101
  return null;
100
102
  }
103
+ // the header measures the widths, so it renders before the rows have any
101
104
  const cellWidths = table.getCellWidths(columns);
102
- if (!cellWidths.length) {
103
- return null;
104
- }
105
+ const hasWidths = cellWidths.length > 0;
105
106
  const y = typeof table.scroll?.y === 'number' ? table.scroll.y : numbers.DEFAULT_VIRTUALIZED_BODY_HEIGHT;
106
- const rowWidth = arrayAdd(cellWidths, 0, columns.length);
107
- return { rowWidth, height: virtualizedData.length ? y : 0 };
107
+ const rowWidth = hasWidths ? arrayAdd(cellWidths, 0, columns.length) : 0;
108
+ return { rowWidth, itemCount: hasWidths ? virtualizedData.length : 0, height: virtualizedData.length ? y : 0 };
108
109
  });
109
110
 
110
111
  // a scrolling body must be keyboard reachable even without a focusable cell
@@ -185,10 +186,10 @@
185
186
  untrack(() => list?.measure());
186
187
  });
187
188
 
188
- // with scroll.y the header is a separate table that reserves the width of a vertical scrollbar the body shows
189
+ // a separate (sticky) header reserves the width of a vertical scrollbar the body shows (#1219)
189
190
  $effect(() => {
190
191
  const node = scrollElement();
191
- if (!table.scroll?.y || !node) {
192
+ if (!table.scroll?.y || includeHeader || !node) {
192
193
  return;
193
194
  }
194
195
  const observer = new ResizeObserver(() => {
@@ -232,15 +233,27 @@
232
233
  class="{table.prefixCls}-body"
233
234
  height={virtualBody.height}
234
235
  innerAttrs={{ class: `${table.prefixCls}-tbody`, role: 'rowgroup' }}
235
- itemCount={virtualizedData.length}
236
+ itemCount={virtualBody.itemCount}
236
237
  itemKey={virtualKey}
237
238
  {itemSize}
238
239
  overscan={table.virtualizedProps?.overscanCount}
240
+ scrollMargin={includeHeader ? listHeaderHeight : 0}
239
241
  style="direction: {table.direction}{virtualizedData.length ? '' : '; height: auto'}"
240
242
  tabindex={0}
241
243
  wrapperAttrs={{ class: [table.prefixCls, `${table.prefixCls}-fixed`], role: 'none', style: rowStyle }}
242
244
  onscroll={handleListScroll}
243
245
  >
246
+ {#snippet before()}
247
+ {#if includeHeader}
248
+ <!-- a hidden header stays for its column widths; inert keeps its controls out of the Tab order and the a11y tree; rendered in the list's scroller above the rows, so the browser moves it with them in the same frame -->
249
+ <div {@attach observeResize(() => (listHeaderHeight = listHeader?.offsetHeight ?? 0))} bind:this={listHeader} class="{table.prefixCls}-list-header" inert={!table.showHeader}>
250
+ <svelte:element this={table.components.header.outer} class={[table.prefixCls, `${table.prefixCls}-fixed`]} role="none" style={joinStyles(table.scroll?.x != null && `width: ${toCssLength(table.scroll.x)}`, minWidth !== undefined && `min-width: ${toCssLength(minWidth)}`)}>
251
+ <ColGroup {columns} prefixCls={table.prefixCls} />
252
+ <TableHeader {columns} hidden={!table.showHeader} />
253
+ </svelte:element>
254
+ </div>
255
+ {/if}
256
+ {/snippet}
244
257
  {#snippet children({ index, style })}
245
258
  {@const item = virtualItem(index)}
246
259
  {#if item.sectionRow}
@@ -124,8 +124,9 @@
124
124
  return { ...custom, class: [customClass, `${table.prefixCls}-row`] };
125
125
  });
126
126
 
127
- // The measured widths give the sticky offsets of fixed columns; measured when the columns change, not on every
128
- // render, since reading layout after a DOM update forces a reflow
127
+ // The measured widths give the sticky offsets of fixed columns; measured when the columns change or the row resizes
128
+ // (a column without a number width follows the table's width), not on every render, since reading layout after a
129
+ // DOM update forces a reflow
129
130
  const measure = (node: HTMLElement) => {
130
131
  const levelColumns = getColumnsByLevel(columns, index) as ColumnProps[];
131
132
  const heads = node.querySelectorAll(`.${table.prefixCls}-row-head`);
@@ -172,6 +173,16 @@
172
173
  untrack(() => measure(row));
173
174
  }
174
175
  });
176
+
177
+ $effect(() => {
178
+ const row = rowElement;
179
+ if (!row) {
180
+ return;
181
+ }
182
+ const observer = new ResizeObserver(() => measure(row));
183
+ observer.observe(row);
184
+ return () => observer.disconnect();
185
+ });
175
186
  </script>
176
187
 
177
188
  <svelte:element this={table.components.header.row} bind:this={rowElement} {...rowAttrs} role="row">
@@ -166,7 +166,13 @@
166
166
  const showExpandIcon = $derived(expandIcon !== false);
167
167
  const fixedHeader = $derived(Boolean(scroll?.y) || Boolean(sticky));
168
168
  const isVirtualized = $derived(Boolean(virtualized));
169
- const splitTable = $derived(fixedHeader || isVirtualized);
169
+
170
+ /**
171
+ * Elsewhere the header sits in the body's scroller, so the compositor moves both in the same frame. A header stuck
172
+ * to the page would be trapped by the body's overflow, so it renders as a separate table above the body
173
+ */
174
+ const headerApart = $derived(Boolean(sticky));
175
+ const splitTable = $derived(headerApart || isVirtualized);
170
176
  const mergedComponents = $derived(mergeComponents(components, isVirtualized));
171
177
  const paginationPosition = $derived(paginationOptions?.position ?? 'bottom');
172
178
  const formatPageText = $derived(paginationOptions?.formatPageText);
@@ -343,8 +349,13 @@
343
349
  return;
344
350
  }
345
351
  const scroller = body?.element();
346
- if (target.scrollLeft !== lastScrollLeft) {
347
- if (target === scroller && head) {
352
+ if (target === head && scroller && foundation.headerFollowsInCss()) {
353
+ // focus scrolled the clipped header to reveal a cell; the body takes the distance, and the header's
354
+ // animation follows it
355
+ scroller.scrollLeft += target.scrollLeft;
356
+ target.scrollLeft = 0;
357
+ } else if (target.scrollLeft !== lastScrollLeft) {
358
+ if (target === scroller && head && !foundation.headerFollowsInCss()) {
348
359
  head.scrollLeft = target.scrollLeft;
349
360
  } else if (target === head && scroller) {
350
361
  scroller.scrollLeft = target.scrollLeft;
@@ -591,6 +602,21 @@
591
602
  return () => observer.disconnect();
592
603
  });
593
604
 
605
+ // the content-box size changes with the body's scrollbar too; columns or rows that widen the table without
606
+ // resizing the body are caught after the update
607
+ $effect(() => {
608
+ void tableColumns;
609
+ void view.dataSource;
610
+ const node = body?.element();
611
+ if (!headerApart || !node) {
612
+ return;
613
+ }
614
+ untrack(foundation.syncHeaderScrollRange);
615
+ const observer = new ResizeObserver(foundation.syncHeaderScrollRange);
616
+ observer.observe(node);
617
+ return () => observer.disconnect();
618
+ });
619
+
594
620
  export function getCurrentPageData(): ReturnType<TableHandle['getCurrentPageData']> {
595
621
  return cloneDeep(foundation.getCurrentPageData());
596
622
  }
@@ -627,7 +653,7 @@
627
653
  </div>
628
654
  {/if}
629
655
  <div {...splitTable ? nameAttrs : {}} aria-rowcount={isVirtualized ? headerRowCount + virtualizedData.length : undefined} class="{prefixCls}-container" role={splitTable ? 'table' : undefined}>
630
- {#if fixedHeader}
656
+ {#if headerApart}
631
657
  <HeadTable bind:element={head} columns={tableColumns} />
632
658
  {/if}
633
659
  <Body
@@ -636,7 +662,7 @@
636
662
  dataSource={view.dataSource ?? []}
637
663
  expandedRowKeys={view.expandedRowKeys ?? []}
638
664
  groups={view.groups}
639
- includeHeader={!fixedHeader}
665
+ includeHeader={!headerApart}
640
666
  {onScroll}
641
667
  pageDisabledRowKeysSet={view.pageDisabledRowKeysSet ?? EMPTY_KEYS}
642
668
  tableAttrs={splitTable ? undefined : nameAttrs}
@@ -18,12 +18,19 @@
18
18
  /** Key of a row; the index when absent */
19
19
  itemKey?: (index: number) => PropertyKey;
20
20
  overscan?: number;
21
+ /**
22
+ * Height of content rendered in `before`, such as a sticky header: rows start this far down, and a row scrolled
23
+ * to the start lands below it
24
+ */
25
+ scrollMargin?: number;
21
26
  /** Attributes of the element that holds the rows */
22
27
  innerAttrs?: HTMLAttributes<HTMLElement>;
23
28
  /** Tag of the element that holds the rows; `ul` when the rows are `li` */
24
29
  innerTag?: 'div' | 'ul';
25
30
  /** Attributes of a div between the scroll container and the row holder, for styles that select the row holder as its direct child */
26
31
  wrapperAttrs?: HTMLAttributes<HTMLDivElement>;
32
+ /** Rendered inside the scroll container before the rows */
33
+ before?: Snippet;
27
34
  /** Rendered inside the scroll container after the rows, such as an empty placeholder */
28
35
  after?: Snippet;
29
36
  /** Renders one row; `style` positions it and goes on the row's element */
@@ -34,7 +41,7 @@
34
41
  * Attributes land on the scroll container; lists whose rows take no focus pass `tabindex={-1}` so Chrome does not
35
42
  * make the container a second tab stop.
36
43
  */
37
- let { height, width = '100%', itemCount, itemSize, itemKey, overscan = 2, innerAttrs, innerTag = 'div', wrapperAttrs, after, children, ...rest }: VirtualListProps = $props();
44
+ let { height, width = '100%', itemCount, itemSize, itemKey, overscan = 2, scrollMargin = 0, innerAttrs, innerTag = 'div', wrapperAttrs, before, after, children, ...rest }: VirtualListProps = $props();
38
45
 
39
46
  let scroller = $state<HTMLDivElement>();
40
47
  let reportRect: ((rect: Rect) => void) | null = null;
@@ -44,6 +51,8 @@
44
51
  getScrollElement: () => scroller ?? null,
45
52
  estimateSize: (index: number) => (typeof itemSize === 'number' ? itemSize : itemSize(index)),
46
53
  overscan,
54
+ scrollMargin,
55
+ scrollPaddingStart: scrollMargin,
47
56
  // The viewport size is the height prop: measuring would read 0 in jsdom and needs a ResizeObserver to follow a
48
57
  // prop change
49
58
  initialRect: { width: 0, height },
@@ -97,6 +106,7 @@
97
106
  </script>
98
107
 
99
108
  <div bind:this={scroller} {...rest} style="position: relative; height: {toCssLength(height)}; width: {toCssLength(width)}; overflow: auto;{rest.style ?? ''}">
109
+ {@render before?.()}
100
110
  {#snippet rows()}
101
111
  <svelte:element this={innerTag} {...innerAttrs} style="height: {$virtualizer.getTotalSize()}px; width: 100%">
102
112
  {#each $virtualizer.getVirtualItems() as item (itemKey ? itemKey(item.index) : item.index)}
@@ -11,12 +11,19 @@ interface VirtualListProps extends Omit<HTMLAttributes<HTMLDivElement>, 'childre
11
11
  /** Key of a row; the index when absent */
12
12
  itemKey?: (index: number) => PropertyKey;
13
13
  overscan?: number;
14
+ /**
15
+ * Height of content rendered in `before`, such as a sticky header: rows start this far down, and a row scrolled
16
+ * to the start lands below it
17
+ */
18
+ scrollMargin?: number;
14
19
  /** Attributes of the element that holds the rows */
15
20
  innerAttrs?: HTMLAttributes<HTMLElement>;
16
21
  /** Tag of the element that holds the rows; `ul` when the rows are `li` */
17
22
  innerTag?: 'div' | 'ul';
18
23
  /** Attributes of a div between the scroll container and the row holder, for styles that select the row holder as its direct child */
19
24
  wrapperAttrs?: HTMLAttributes<HTMLDivElement>;
25
+ /** Rendered inside the scroll container before the rows */
26
+ before?: Snippet;
20
27
  /** Rendered inside the scroll container after the rows, such as an empty placeholder */
21
28
  after?: Snippet;
22
29
  /** Renders one row; `style` positions it and goes on the row's element */