@xleddyl/443-components-vue 0.16.93 → 0.16.95
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.
- package/CATALOG.md +176 -166
- package/README.md +78 -14
- package/dist/components/core/Button.vue.d.ts +3 -3
- package/dist/components/data/SortableList.vue +120 -0
- package/dist/components/data/SortableList.vue.d.ts +48 -0
- package/dist/components/data/Table.vue +43 -3
- package/dist/components/data/Table.vue.d.ts +8 -2
- package/dist/components/data/Thumbnail.vue +157 -0
- package/dist/components/data/Thumbnail.vue.d.ts +439 -0
- package/dist/components/data/TileGrid.vue +274 -0
- package/dist/components/data/TileGrid.vue.d.ts +51 -0
- package/dist/components/data/index.d.ts +3 -0
- package/dist/components/data/index.mjs +3 -0
- package/dist/components/data/types.d.ts +39 -0
- package/dist/components/forms/FocalPointInput.vue +251 -0
- package/dist/components/forms/FocalPointInput.vue.d.ts +426 -0
- package/dist/components/forms/PaletteSelect.vue.d.ts +2 -2
- package/dist/components/forms/index.d.ts +1 -0
- package/dist/components/forms/index.mjs +1 -0
- package/dist/components/layout/ThemeSwitch.vue.d.ts +2 -2
- package/dist/components/layout/types.d.ts +1 -1
- package/dist/components/templates/FormPage.vue.d.ts +2 -2
- package/dist/composables/useSortable.d.ts +1 -0
- package/dist/composables/useSortable.mjs +40 -11
- package/dist/grid/cells/ButtonCell.vue.d.ts +2 -2
- package/dist/icons/builtin.d.ts +3 -0
- package/dist/icons/builtin.mjs +7 -0
- package/dist/internal/data/sortable.d.ts +4 -1
- package/dist/internal/data/sortable.mjs +49 -0
- package/dist/locale/de.mjs +23 -0
- package/dist/locale/en.mjs +23 -0
- package/dist/locale/it.mjs +23 -0
- package/dist/locale/types.d.ts +23 -0
- package/dist/styles/data/sortable-list.css +185 -0
- package/dist/styles/data/table.css +12 -0
- package/dist/styles/data/thumbnail.css +209 -0
- package/dist/styles/data/tile-grid.css +144 -0
- package/dist/styles/data.css +3 -0
- package/dist/styles/forced-colors.css +42 -0
- package/dist/styles/forms/focal-point-input.css +154 -0
- package/dist/styles/forms.css +1 -0
- package/dist/styles/layout/card.css +84 -0
- package/dist/styles/shared.css +2 -1
- package/dist/styles/tailwind.css +2 -0
- package/dist/styles/tokens.css +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -468,18 +468,18 @@ async function switchView() {
|
|
|
468
468
|
|
|
469
469
|
## Components
|
|
470
470
|
|
|
471
|
-
| Group | Components
|
|
472
|
-
| --------- |
|
|
473
|
-
| core | Root, Icon, Button, Spinner, Input, Textarea, FormField, FieldMessage, FieldBoundary, Form, FormAlerts, Kbd, VisuallyHidden
|
|
474
|
-
| forms | Calendar, Checkbox, CheckboxGroup, ColorInput, Combobox, DateInput, DatePicker, FileInput, InputAddon, InputGroup, NumberInput, PaletteSelect, PasswordInput, PinInput, Radio, RadioGroup, SegmentedControl, Select, Slider, Switch, TimeInput, TreeSelect
|
|
475
|
-
| overlays | CommandButton, CommandList, CommandPalette, ConfirmDialog, ConfirmHost, ContextMenu, Drawer, DropdownMenu, HoverCard, Modal, OverlayHost, Popover, Toaster, Tooltip
|
|
476
|
-
| data | Avatar, AvatarGroup, Badge, DescriptionList, FilterPill, FilterPills, Pagination, RecordList, SelectionBar, Stat, Table, Tag, TagList, Timeline, Tree
|
|
477
|
-
| layout | Accordion, AppShell, Breadcrumbs, Card, CopyButton, Grid, NavLink, PageHeader, Separator, Sidebar, SidebarNav, SidebarSection, Stack, Stepper, Tabs, ThemeSwitch, Toolbar
|
|
478
|
-
| templates | DashboardLayout, AuthLayout, AuthLogin, AuthLogout, DashboardPage, ListPage, DetailPage, FormPage, SettingsPage, SettingsSection, SettingsModal, SettingsGroup, AppearanceSettings, SaveBar, ErrorPage, NotFoundPage, EmptyPage, Brand, AccountMenu, FormDrawer
|
|
479
|
-
| feedback | Alert, EmptyState, LoadingOverlay, Meter, Progress, ProgressRing, Skeleton, SkeletonForm, SkeletonList
|
|
480
|
-
| grid | DataGrid, GridToolbar, cell renderers (BadgeCell, BooleanCell, ButtonCell, DateCell, EmptyCell, ImageCell, LinkCell)
|
|
481
|
-
| editor | RichTextEditor, TemplateEditor, TemplateText
|
|
482
|
-
| chart | ChartPanel, ChartLegend, LineChart, BarChart, DoughnutChart
|
|
471
|
+
| Group | Components |
|
|
472
|
+
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
473
|
+
| core | Root, Icon, Button, Spinner, Input, Textarea, FormField, FieldMessage, FieldBoundary, Form, FormAlerts, Kbd, VisuallyHidden |
|
|
474
|
+
| forms | Calendar, Checkbox, CheckboxGroup, ColorInput, Combobox, DateInput, DatePicker, FileInput, FocalPointInput, InputAddon, InputGroup, NumberInput, PaletteSelect, PasswordInput, PinInput, Radio, RadioGroup, SegmentedControl, Select, Slider, Switch, TimeInput, TreeSelect |
|
|
475
|
+
| overlays | CommandButton, CommandList, CommandPalette, ConfirmDialog, ConfirmHost, ContextMenu, Drawer, DropdownMenu, HoverCard, Modal, OverlayHost, Popover, Toaster, Tooltip |
|
|
476
|
+
| data | Avatar, AvatarGroup, Badge, DescriptionList, FilterPill, FilterPills, Pagination, RecordList, SelectionBar, SortableList, Stat, Table, Tag, TagList, Thumbnail, TileGrid, Timeline, Tree |
|
|
477
|
+
| layout | Accordion, AppShell, Breadcrumbs, Card, CopyButton, Grid, NavLink, PageHeader, Separator, Sidebar, SidebarNav, SidebarSection, Stack, Stepper, Tabs, ThemeSwitch, Toolbar |
|
|
478
|
+
| templates | DashboardLayout, AuthLayout, AuthLogin, AuthLogout, DashboardPage, ListPage, DetailPage, FormPage, SettingsPage, SettingsSection, SettingsModal, SettingsGroup, AppearanceSettings, SaveBar, ErrorPage, NotFoundPage, EmptyPage, Brand, AccountMenu, FormDrawer |
|
|
479
|
+
| feedback | Alert, EmptyState, LoadingOverlay, Meter, Progress, ProgressRing, Skeleton, SkeletonForm, SkeletonList |
|
|
480
|
+
| grid | DataGrid, GridToolbar, cell renderers (BadgeCell, BooleanCell, ButtonCell, DateCell, EmptyCell, ImageCell, LinkCell) |
|
|
481
|
+
| editor | RichTextEditor, TemplateEditor, TemplateText |
|
|
482
|
+
| chart | ChartPanel, ChartLegend, LineChart, BarChart, DoughnutChart |
|
|
483
483
|
|
|
484
484
|
Composables: `useTheme`, `usePreset`, `useForm`, `useField`, `useFieldControl`, `useToast` (and `toast`), `useConfirm`, `useAlert`, `usePrompt`, `useModal`, `useDrawer`, `useOverlay`, `useModalContext`, `useLoading` (and `withLoading`), `useLoadingState`, `useHotkey`, `useCopy`, `useFileDrop` (with `readDroppedFiles`), `useSortable`, `usePasswordStrength`, `useTableSort`, `useAppShell`, `useRouteState`, `useRouteRecord`, `usePageCommands`, `usePreference` (with `usePreferences`, `createPreferences`, `providePreferences`), `useScrollLock`, `useLeaveGuard` (with `useLeaveScope`, `provideLeaveScope`), `useDirtyGuard`, `useIcons` helpers and `useLinkComponent`, `provideFieldBoundary`, `provideAuxiliaryControls`, `provideForm`, `provideGridConfig` (with `createGridConfig`, `useGridConfig`), `useLocale`. With the Nuxt module also `useDashboard()` (runtime account, breadcrumbs and badges for the `k-dashboard` layout) and `useNavigationPending()` (`true` while a navigation to another path renders the new page), auto-imported or imported from `@xleddyl/443-components-vue/nuxt/composables`.
|
|
485
485
|
|
|
@@ -536,6 +536,7 @@ On your own elements, `paletteClass(color)` gives the class of a palette name an
|
|
|
536
536
|
```
|
|
537
537
|
|
|
538
538
|
- `Tabs` items take `dot: true` for a small indicator without a number (`dotTone`, default `danger`; `dotLabel` is the hidden text, default "Needs attention"). `color` (a palette name or a hex, `ColorValue`) draws a small color dot before the label, separate from the status dot. `title` shows a tooltip on hover and keyboard focus (the native `title` only until mount) and becomes the tab description; a disabled tab keeps it (it uses `aria-disabled`, cannot be selected and is skipped by Tab and the arrow keys), so it can say why it is disabled. The same items work in the `tabs` of `Modal`, `Drawer`, `FormDrawer` and `DetailPage`.
|
|
539
|
+
- `Card` takes `variant="dashed"` (`CardVariant`) for a placeholder tile: a dashed `--k-line-strong` border on `--k-subtle`, with the icon, title and description centered in a column (the icon in a raised box, the title at 0.8125rem). As a button (`as="button"`) or a link (`to`, `href`) it gets the hover and focus of the `FileInput` dropzone (`--k-fill` and a `--k-text-dimmed` border on hover, a solid `--k-ring` border and the focus ring on focus); `disabled` dims it, and `selected` tints it with the accent, for a drop target while something is dragged over it. Use it for an "Add" tile at the end of a grid of items and for an empty area: `<KCard variant="dashed" as="button" icon="plus" title="Add block" @click="add" />`.
|
|
539
540
|
- `DropdownMenu` takes `matchTriggerWidth` (the menu is at least as wide as its trigger) and `minWidth` (a CSS length).
|
|
540
541
|
- `PageHeader` takes `align` (`'end'` by default, `'start'` or `'center'`) for the title block and the actions, and `truncate` to keep the title on one line with an ellipsis (the full title is in its `title` attribute). `trail` (`BreadcrumbItem[]`, the earlier levels as links) turns the title into a breadcrumb trail that ends with `title`, at the page title size: a `nav` (named by `trailLabel`, default "Breadcrumb") around an ordered list whose last item is the heading (`h<level>`, `aria-current="page"`, only the title, `#title` fills it). With `truncate` the trail stays on one line and the title gets the ellipsis. Use it for a record or a nested page instead of `Breadcrumbs` in `#title` (a `nav` inside a heading). `breadcrumbs` stays the small trail above the title.
|
|
541
542
|
- `RichTextEditor` accepts `'underline'` in `toolbar` (not in the default toolbar).
|
|
@@ -545,6 +546,15 @@ On your own elements, `paletteClass(color)` gives the class of a palette name an
|
|
|
545
546
|
- `FilterPills` is generic: the value type comes from the options, `multiple` makes the model an array and `required` drops `null` from it (like `SegmentedControl`). Options take `menu` items (a dropdown trigger showing `valueLabel`) or `panel: true`, which opens a popover with the `#panel-<value>` slot (`{ option, active, toggle, close }`, `panelLabel` names it). The `#pill` slot renders any trigger and its scope has `defaultPill`, a component that renders the built-in pill for that option, so one custom pill does not mean rewriting the others: `<component :is="defaultPill" v-else />`. `FilterPill` is exported so custom triggers match the other pills.
|
|
546
547
|
- `SegmentedControl` with `required` narrows `v-model` to a non null value. Options take `title` (tooltip and description) and `muted`, and the `#option` slot replaces the content of each option.
|
|
547
548
|
- `FileInput` takes `directory` (folder picker; dropped folders are walked, every file keeps its relative path) or `directory="drop"` (the click opens a file picker, dropped folders are still walked), `directoryAction` (an "Upload a folder" button under the dropzone, `directoryActionLabel` renames it) or the `#actions` slot (`{ browse, browseDirectory, disabled }`), `skipHidden` (ignores dot files and dot folders), `list: false` (no file list: picks and drops only emit `add`), `fill` (the dropzone fills the height of its flex column parent, with the icon and the text centered: an import screen), `loading` and the `#hint` slot. `add` receives `(files, { entries: [{ file, path }], directories, source, event, dataTransfer })`; `directories` lists every folder path of a folder pick or drop, empty folders included, and `add` also fires for a drop of empty folders. `invalid` fires per file and `reject` once with every rejected file (`(events, detail)`). `acceptMode="hint"` only passes `accept` to the picker and leaves filtering to the host. The component exposes `browse()`, `browseDirectory()`, `addFiles()` and `focus()`.
|
|
549
|
+
- `FocalPointInput` edits the point of an image that must stay visible when it is cropped: `v-model` is a `FocalPoint` (`{ x, y }`, each from 0 to 1, rounded to 0.001) or `null` (not set). Click or drag on the `src` image to place the crosshair; the arrow keys move it by `step` (default 0.01, ten times with Shift; from the center when it is not set), Home, End, Page Up and Page Down move along one axis. It is a group (named by `label` or the FormField label, with a development warning when unnamed) of two visually hidden range inputs, "Horizontal position" and "Vertical position" (`horizontalLabel`, `verticalLabel`), with one tab stop: their value text is the percentage, or "Not set" (`emptyText`), and a hidden hint describes the pointer and keys. The current value shows under the image ("X 30%, Y 40%"). `clearable` adds a Reset button (`clearLabel`, focus moves to the point before it disappears) and lets Delete and Backspace clear the value. `disabled` follows `Form`, `Fieldset` and `FormField` (an explicit `:disabled="false"` opts out), `readonly` keeps the point visible and focusable without changes, `invalid` comes from the field. `--k-focal-point-input-height` (20rem) caps the image height. Pass the value to `Thumbnail` `focal` to preview the crops.
|
|
550
|
+
|
|
551
|
+
```vue
|
|
552
|
+
<KFormField label="Focal point">
|
|
553
|
+
<KFocalPointInput v-model="focal" :src="url" :alt="alt" clearable />
|
|
554
|
+
</KFormField>
|
|
555
|
+
<KThumbnail :src="url" aspect="16/9" :focal="focal" />
|
|
556
|
+
```
|
|
557
|
+
|
|
548
558
|
- `TagList` renders `v-model` (`TagListItem[]`: `value`, `label`, `tone`, `icon`, `removable`, `disabled`) as `Tag` chips in a labelled list (`label`, default "Items"). `removable` (or `removable` per item) adds the remove button; the chip is dropped from the model, `remove(item, index)` fires, focus moves to the neighbor and "Label removed" is announced. `sortable` reorders by pointer drag (the list updates live while dragging, Escape cancels), and the chips become one tab stop: the arrow keys, Home and End move between chips, Alt with an arrow key (or Alt with Home and End) moves the focused chip, Delete removes it, and every move is announced ("Name moved to position 2 of 4", `sortable.moved`). `moveButtons` adds "Move earlier" and "Move later" buttons to every chip, a single pointer alternative to dragging. A disabled item cannot move or be removed. `move({ item, from, to })` fires after each move. `accept` (a MIME type, a list of them, or `(event) => boolean`) makes the list a drop target for native drags from outside: an insertion marker follows the pointer and `itemDrop({ index, dataTransfer, event })` (`@item-drop`, named apart from the native `drop` event) gives the insertion index, so the host inserts the item (`dropEffect`, default `copy`, must match the `effectAllowed` of the source). The `#item` slot (`{ item, index }`) replaces the chip label.
|
|
549
559
|
|
|
550
560
|
```vue
|
|
@@ -560,7 +570,61 @@ On your own elements, `paletteClass(color)` gives the class of a palette name an
|
|
|
560
570
|
/>
|
|
561
571
|
```
|
|
562
572
|
|
|
563
|
-
- `
|
|
573
|
+
- `SortableList` is a vertical list of rows to reorder: `v-model` (`SortableListItem[]`: `value`, `label`, `description`, `icon`, `disabled`) in a labelled list (`label`, default "Items"). Each row has a drag handle, the icon, the label with the description under it (both on one line with an ellipsis) and the `#trailing` slot (`{ item, index }`) for switches or actions. A drag starts from the handle or the label (not from the trailing controls), the row follows the pointer and its slot stays as a dashed placeholder, Escape cancels. The handle is a button ("Move Title", `handleLabel` is a `'Move {label}'` template): the up and down arrow keys, Home and End move the row, Alt with an arrow key works from anywhere in the row, and every move is announced. A disabled item cannot be picked up or moved by its handle (the handle is disabled), `disabled` locks the whole list (the trailing controls stay usable). `move({ item, from, to })` fires after each move. `size` is `'md'` (default) or `'sm'` (`SortableListSize`); `#item` replaces the icon, label and description; `emptyText` or `#empty` shows when the list is empty.
|
|
574
|
+
|
|
575
|
+
```vue
|
|
576
|
+
<KSortableList v-model="columns" label="Visible columns">
|
|
577
|
+
<template #trailing="{ item }">
|
|
578
|
+
<KSwitch :model-value="true" :aria-label="`Hide ${item.label}`" @update:model-value="hide(item)" />
|
|
579
|
+
</template>
|
|
580
|
+
</KSortableList>
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
- `useSortable(container, options)` is the reorder logic of `TagList` for any list. Options: `items` (a ref or getter), `onMove(items, move)` (`SortableMove`: `{ item, from, to, items, source }`, write `items` back to your state), `orientation` (`'vertical'` by default, `'horizontal'` for wrapping rows, `'grid'` for a CSS grid of cells: the item lands in the cell nearest to the pointer across wrapped rows, Alt with Left and Right moves it by one and Alt with Up and Down to the nearest cell of the row above or below), `disabled`, `handle` (a selector: only a pointer down on it starts a drag; without it any pointer down outside buttons, links and inputs does), `preview` (a selector inside the item: only that part follows the pointer and the item stays in its slot, so style the dragged item as the drop indicator, a dashed placeholder), `canMove(item, index)`, `label(item)` and `movedText(move)` for the announcement. Bind `itemProps(index)` on each item element (the attribute marks it, plus pointer and Alt with arrow key handlers) and render `announcement` in a polite live region. `move(from, to, { announce })` moves from your own buttons, `dragging` is the index being dragged (for a lifted style), `canMove(index)` reports locked items. Pointer drags reorder live and follow the pointer, Escape or a cancelled pointer puts the item back, and the click after a drag is swallowed.
|
|
584
|
+
|
|
585
|
+
- `Thumbnail` previews an image, a video or a file: `kind` (`ThumbnailKind`, `'image' | 'video' | 'file' | 'icon'`, default `'image'`), `src`, `alt` and `icon` (the fallback icon, by default `photo`, `video-camera` or `document`). A video shows its first frame (`preload="metadata"`, muted, no controls) under a play glyph. Without `size` it is fluid (the width of its parent, the height from `aspect`, a ratio string like `'4/3'` or a number, default 1); `size` (`ThumbnailSize`, `'xs' | 'sm' | 'md' | 'lg'`) gives a fixed inline box for tables and lists. `fit` is `'cover'` (default) or `'contain'`, `rounded` (`ThumbnailRounded`, `'none' | 'sm' | 'md' | 'lg' | 'full'`) overrides the radius of the size, and `focal` (`FocalPoint`, `{ x, y }` from 0 to 1, what `FocalPointInput` edits) or `objectPosition` (any CSS value, it wins) choose the part of the image that stays in view. While the media loads the box pulses; `missing`, or an image or video that fails to load, shows a hatched box with the icon and a hidden "File not available" (`thumbnail.missing`, `missingText` overrides it). The `top-start` and `top-end` slots put badges and actions in the corners, `caption` (or the `#caption` slot) sits at the bottom on a readable scrim, and `reveal` (`ThumbnailOverlay[]`, default `['caption']`) lists the overlays that only show on hover and focus, also when a link or button around the thumbnail is hovered or focused (always on touch screens). The default slot replaces the media with your own content (a text preview). Text and icons over media use the `--k-media-scrim` and `--k-media-text` tokens, the same in both themes; use them for your own overlays too.
|
|
586
|
+
|
|
587
|
+
```vue
|
|
588
|
+
<KThumbnail :src="url" kind="video" aspect="4/3" :caption="name" :reveal="['caption', 'top-end']">
|
|
589
|
+
<template #top-end>
|
|
590
|
+
<KButton icon="trash" size="xs" variant="solid" tone="neutral" square aria-label="Remove" />
|
|
591
|
+
</template>
|
|
592
|
+
</KThumbnail>
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
- `TileGrid` lays out `items` as a responsive grid of tiles: `minItemWidth` (default `10rem`, the narrowest tile), `columns` (the most columns, unset fills the row) and `gap` (`LayoutGap`, default `md`). The `#tile` slot (`{ item, index, selected, dragging }`) renders each tile (a `Card`, a `Thumbnail`) and stretches it to the cell; `#add` is a last cell after the tiles (a `Card variant="dashed" as="button"`). `itemKey` (a field name, default `id`, or `(item, index) => key`) keys the tiles and the selection, `itemLabel(item)` names each tile and its announcements, `label` names the grid (default "Items"). The tiles are one tab stop: the arrow keys move between them across wrapped rows (Up and Down go to the nearest tile of the row above or below), Home and End go to the ends, and the controls inside a tile keep their own tab stops. `selectable` with `v-model:selected` (the keys) makes it a multi select `listbox` (otherwise a `list`): a round check shows on hover, focus and on every tile while something is selected (always on touch screens), a click on it toggles the tile, Shift adds the range from the last toggled tile, Space and Shift with Space do the same from the keyboard and Ctrl or Cmd with A selects all. A click on the tile itself toggles it while something is selected or with Shift, Ctrl or Cmd held, and calls `@activate(item, index, event)` otherwise (Enter too; without an `activate` listener it toggles). `sortable` reorders by pointer drag (the tile follows the pointer and its cell stays as a dashed placeholder, Escape cancels; `handle`, a selector, limits where a drag starts and keeps touch scrolling on the rest of the tile) and by Alt with an arrow key on a focused tile, with an announcement; bind `v-model:items` (or write `items` back from `move({ item, from, to, items })`). `dragData(item, items)` makes tiles native drag sources for drop targets outside the grid (folders): it returns `{ [mimeType]: string }` for the `DataTransfer` (or `null` to refuse the drag), `items` is the whole selection when the dragged tile is selected, `dragEffect` sets `effectAllowed` (default `move`), the dragged tiles fade and `itemDragStart` and `itemDragEnd` (`{ item, items, event }`) fire. `dragData` is ignored when `sortable` is set. `--k-tile-grid-radius` (default `--k-radius-lg`) is the radius of the tiles, the selected ring and the placeholder.
|
|
596
|
+
|
|
597
|
+
```vue
|
|
598
|
+
<KTileGrid
|
|
599
|
+
v-model:selected="selected"
|
|
600
|
+
:items="files"
|
|
601
|
+
:item-label="(file) => file.name"
|
|
602
|
+
label="Files"
|
|
603
|
+
min-item-width="9rem"
|
|
604
|
+
selectable
|
|
605
|
+
:drag-data="(file, files) => ({ 'application/x-media': files.map((f) => f.id).join(',') })"
|
|
606
|
+
@activate="open"
|
|
607
|
+
>
|
|
608
|
+
<template #tile="{ item }">
|
|
609
|
+
<KThumbnail :src="item.url" aspect="1/1" :caption="item.name" />
|
|
610
|
+
</template>
|
|
611
|
+
</KTileGrid>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
- `Table` takes `rowAttrs(row, index)` (`TableRowAttrs`): attributes and listeners bound on each `<tr>` (`data-*`, `title`, `onDragover` to make rows drop targets); classes and listeners merge with the table's own. `rowDraggable` (`true` or `(row, index) => boolean`) with `dragData(row, rows)` makes rows native drag sources for drop targets outside the table (folders): `dragData` returns `{ [mimeType]: string }` for the `DataTransfer` (or `null` to refuse the drag), `rows` is the whole selection when the dragged row is selected, `dragEffect` sets `effectAllowed` (default `move`), the dragged rows fade and `rowDragStart` and `rowDragEnd` (`{ row, rows, event }`) fire. Selection, `rowClick`, row links and the keyboard keep working; links in draggable rows are not dragged on their own.
|
|
615
|
+
|
|
616
|
+
```vue
|
|
617
|
+
<KTable
|
|
618
|
+
v-model:selected="selected"
|
|
619
|
+
:rows="files"
|
|
620
|
+
:columns="columns"
|
|
621
|
+
row-key="name"
|
|
622
|
+
selectable
|
|
623
|
+
row-draggable
|
|
624
|
+
:drag-data="(file, rows) => ({ 'application/x-media': rows.map((r) => r.name).join(',') })"
|
|
625
|
+
@row-click="open"
|
|
626
|
+
/>
|
|
627
|
+
```
|
|
564
628
|
|
|
565
629
|
- `useFileDrop` returns `{ over, reset }` and takes `ignore(event)`. A drop handled by a nested drop zone is skipped by the outer ones, and the state resets after any drop, even when a child stops propagation. `readDroppedFiles(dataTransfer)` walks dropped folders (call it synchronously in the drop handler) and resolves to `[{ file, path }]`; `readDroppedFiles(dataTransfer, { directories: true })` resolves to `{ files, directories }` with every folder path, empty ones included, and `skipHidden: true` leaves out dot entries.
|
|
566
630
|
- `Tabs` items take `badgeTone` and `badgeLabel` (the accessible name of the badge); the `#panel="{ item }"` slot renders a single panel for the active tab. `stretch` makes the tabs fill the remaining height of a flex column and the active panel grow with it (`flex: 1; min-height: 0`), and `inset` spaces the tab list from the container edges with the panel flush below it, for inspectors and side panes. `Breadcrumbs` items take `attrs` and `onClick` (an item without a link renders a button, handy for drop targets), `#item` customizes the content, and `ancestors` links every item and ends with a separator (`breadcrumbsAncestors` on `PageHeader`). `heading` (a heading level) renders the current item as that heading, for a trail that is the title of the page. `Accordion` takes `variant` `card` (default), `outline` (the same card without a shadow), `separated` or `plain`; items take `description`, and `contentVariant="neutral"` drops the content padding and text styling.
|
|
@@ -991,7 +1055,7 @@ The components target WCAG 2.2 AA in every preset and both themes.
|
|
|
991
1055
|
|
|
992
1056
|
Accessibility related props and defaults:
|
|
993
1057
|
|
|
994
|
-
- Accessible names: `label` on `RadioGroup` and `CheckboxGroup` (alias of `legend`), `SegmentedControl`, `Slider`, `PinInput`, `InputGroup`, `Tabs`, `Toolbar`, `Modal`, `Drawer` and `useModal`/`useDrawer` options (when there is no `title`), `Card` (stretched link without a title), `ChartLegend`. `AppShell` takes `closeLabel` for the close button of the mobile navigation, which opens as a named modal dialog. `Sidebar`'s collapse button keeps one label (`collapseLabel`) and exposes the state with `aria-expanded`.
|
|
1058
|
+
- Accessible names: `label` on `RadioGroup` and `CheckboxGroup` (alias of `legend`), `SegmentedControl`, `Slider`, `FocalPointInput`, `PinInput`, `InputGroup`, `Tabs`, `Toolbar`, `Modal`, `Drawer` and `useModal`/`useDrawer` options (when there is no `title`), `Card` (stretched link without a title), `ChartLegend`. `AppShell` takes `closeLabel` for the close button of the mobile navigation, which opens as a named modal dialog. `Sidebar`'s collapse button keeps one label (`collapseLabel`) and exposes the state with `aria-expanded`.
|
|
995
1059
|
- Heading levels: `level` on `Calendar`, `DatePicker`, `ChartPanel`, `ErrorPage` and `NotFoundPage`; page templates pass `level + 1` to their sections and empty states.
|
|
996
1060
|
- Live roles are opt in on `Alert`: pass `role="alert"` or `role="status"` for messages that appear at runtime; static banners get none. Without a title the tone is spoken from a hidden prefix.
|
|
997
1061
|
- `Toolbar` uses roving focus by default (`:roving="false"` renders a plain named group).
|
|
@@ -10,7 +10,7 @@ type __VLS_Slots = {} & {
|
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_base: import("vue").DefineComponent<{
|
|
12
12
|
label?: string;
|
|
13
|
-
type?: "
|
|
13
|
+
type?: "reset" | "submit" | "button" | undefined;
|
|
14
14
|
size?: ButtonSize;
|
|
15
15
|
tone?: Tone;
|
|
16
16
|
variant?: ButtonVariant;
|
|
@@ -237,7 +237,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
237
237
|
popovertargetaction?: import("../../index.ts").PopoverTargetAction | undefined;
|
|
238
238
|
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
|
|
239
239
|
label?: string;
|
|
240
|
-
type?: "
|
|
240
|
+
type?: "reset" | "submit" | "button" | undefined;
|
|
241
241
|
size?: ButtonSize;
|
|
242
242
|
tone?: Tone;
|
|
243
243
|
variant?: ButtonVariant;
|
|
@@ -466,7 +466,7 @@ declare const __VLS_base: import("vue").DefineComponent<{
|
|
|
466
466
|
size: ButtonSize;
|
|
467
467
|
tone: Tone;
|
|
468
468
|
tooltip: string | false;
|
|
469
|
-
type: "
|
|
469
|
+
type: "reset" | "submit" | "button";
|
|
470
470
|
variant: ButtonVariant;
|
|
471
471
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
472
472
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="k-sortable-list"
|
|
4
|
+
:class="[
|
|
5
|
+
`k-sortable-list-${size}`,
|
|
6
|
+
{
|
|
7
|
+
'is-sortable': canSort,
|
|
8
|
+
'is-dragging': sorter.dragging.value !== null,
|
|
9
|
+
'is-disabled': disabled
|
|
10
|
+
}
|
|
11
|
+
]"
|
|
12
|
+
>
|
|
13
|
+
<ul
|
|
14
|
+
v-if="items.length"
|
|
15
|
+
ref="list"
|
|
16
|
+
class="k-sortable-list-items"
|
|
17
|
+
:aria-label="labelText"
|
|
18
|
+
:aria-describedby="hintId"
|
|
19
|
+
>
|
|
20
|
+
<li
|
|
21
|
+
v-for="(item, index) in items"
|
|
22
|
+
:key="item.value"
|
|
23
|
+
class="k-sortable-list-item"
|
|
24
|
+
:class="{
|
|
25
|
+
'is-moving': sorter.dragging.value === index,
|
|
26
|
+
'is-locked': !sorter.canMove(index)
|
|
27
|
+
}"
|
|
28
|
+
v-bind="sorter.itemProps(index)"
|
|
29
|
+
>
|
|
30
|
+
<div class="k-sortable-list-row">
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
class="k-sortable-list-handle"
|
|
34
|
+
:aria-label="handleText(item)"
|
|
35
|
+
:aria-describedby="hintId"
|
|
36
|
+
:disabled="!sorter.canMove(index)"
|
|
37
|
+
@keydown="onHandleKeydown($event, index)"
|
|
38
|
+
>
|
|
39
|
+
<Icon name="bars-2" />
|
|
40
|
+
</button>
|
|
41
|
+
<span class="k-sortable-list-content">
|
|
42
|
+
<slot name="item" :item="item" :index="index">
|
|
43
|
+
<Icon v-if="item.icon" :name="item.icon" class="k-sortable-list-icon" />
|
|
44
|
+
<span class="k-sortable-list-text">
|
|
45
|
+
<span class="k-sortable-list-label">{{ item.label }}</span>
|
|
46
|
+
<span v-if="item.description" class="k-sortable-list-description">{{
|
|
47
|
+
item.description
|
|
48
|
+
}}</span>
|
|
49
|
+
</span>
|
|
50
|
+
</slot>
|
|
51
|
+
</span>
|
|
52
|
+
<span v-if="$slots.trailing" class="k-sortable-list-trailing">
|
|
53
|
+
<slot name="trailing" :item="item" :index="index" />
|
|
54
|
+
</span>
|
|
55
|
+
</div>
|
|
56
|
+
</li>
|
|
57
|
+
</ul>
|
|
58
|
+
<p v-else class="k-sortable-list-empty">
|
|
59
|
+
<slot name="empty">{{ emptyLabel }}</slot>
|
|
60
|
+
</p>
|
|
61
|
+
<span :id="hintId" class="k-visually-hidden">{{ t("sortableList.hint") }}</span>
|
|
62
|
+
<LiveRegion :message="sorter.announcement.value" />
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<script setup>
|
|
67
|
+
import { computed, useId, useTemplateRef } from "vue";
|
|
68
|
+
import { useLocale } from "../../composables/useLocale";
|
|
69
|
+
import { useSortable } from "../../composables/useSortable";
|
|
70
|
+
import LiveRegion from "../../internal/core/LiveRegion.vue";
|
|
71
|
+
import { translateOr } from "../../locale";
|
|
72
|
+
import Icon from "../core/Icon.vue";
|
|
73
|
+
const props = defineProps({
|
|
74
|
+
label: { type: String, required: false },
|
|
75
|
+
size: { type: String, required: false, default: "md" },
|
|
76
|
+
disabled: { type: Boolean, required: false },
|
|
77
|
+
emptyText: { type: String, required: false },
|
|
78
|
+
handleLabel: { type: String, required: false }
|
|
79
|
+
});
|
|
80
|
+
const model = defineModel({ type: Array, ...{ default: () => [] } });
|
|
81
|
+
const emit = defineEmits(["move"]);
|
|
82
|
+
defineSlots();
|
|
83
|
+
const { t, locale } = useLocale();
|
|
84
|
+
const hintId = `${useId()}-hint`;
|
|
85
|
+
const list = useTemplateRef("list");
|
|
86
|
+
const items = computed(() => model.value);
|
|
87
|
+
const canSort = computed(() => !props.disabled && items.value.length > 1);
|
|
88
|
+
const labelText = computed(() => props.label ?? t("sortableList.label"));
|
|
89
|
+
const emptyLabel = computed(() => props.emptyText ?? t("sortableList.empty"));
|
|
90
|
+
function handleText(item) {
|
|
91
|
+
return translateOr(locale.value, props.handleLabel, "sortableList.handle", { label: item.label });
|
|
92
|
+
}
|
|
93
|
+
const sorter = useSortable(list, {
|
|
94
|
+
items,
|
|
95
|
+
orientation: "vertical",
|
|
96
|
+
handle: ".k-sortable-list-handle, .k-sortable-list-content",
|
|
97
|
+
preview: ".k-sortable-list-row",
|
|
98
|
+
disabled: () => props.disabled,
|
|
99
|
+
canMove: (item) => !item.disabled,
|
|
100
|
+
label: (item) => item.label,
|
|
101
|
+
onMove: (next, move) => {
|
|
102
|
+
model.value = next;
|
|
103
|
+
emit("move", { item: move.item, from: move.from, to: move.to });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const HANDLE_KEYS = {
|
|
107
|
+
ArrowUp: (index) => index - 1,
|
|
108
|
+
ArrowDown: (index) => index + 1,
|
|
109
|
+
Home: () => 0,
|
|
110
|
+
End: (_, count) => count - 1
|
|
111
|
+
};
|
|
112
|
+
function onHandleKeydown(event, index) {
|
|
113
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
114
|
+
const target = HANDLE_KEYS[event.key];
|
|
115
|
+
if (!target) return;
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
sorter.move(index, target(index, items.value.length), { announce: true, source: "keyboard" });
|
|
119
|
+
}
|
|
120
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SortableListItem, SortableListSize } from './types';
|
|
2
|
+
declare const __VLS_export: <T extends SortableListItem>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<({
|
|
4
|
+
label?: string;
|
|
5
|
+
size?: SortableListSize;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
emptyText?: string;
|
|
8
|
+
handleLabel?: string;
|
|
9
|
+
} & {
|
|
10
|
+
modelValue?: T[];
|
|
11
|
+
}) & {
|
|
12
|
+
onMove?: ((move: {
|
|
13
|
+
item: T;
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
}) => any) | undefined;
|
|
17
|
+
"onUpdate:modelValue"?: ((value: T[]) => any) | undefined;
|
|
18
|
+
} & Partial<import("vue").HTMLAttributes & import("vue").ReservedProps>> & (typeof globalThis extends {
|
|
19
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
20
|
+
} ? P : {});
|
|
21
|
+
expose: (exposed: {}) => void;
|
|
22
|
+
attrs: any;
|
|
23
|
+
slots: {
|
|
24
|
+
item?: (props: {
|
|
25
|
+
item: T;
|
|
26
|
+
index: number;
|
|
27
|
+
}) => unknown;
|
|
28
|
+
trailing?: (props: {
|
|
29
|
+
item: T;
|
|
30
|
+
index: number;
|
|
31
|
+
}) => unknown;
|
|
32
|
+
empty?: () => unknown;
|
|
33
|
+
};
|
|
34
|
+
emit: ((evt: "move", move: {
|
|
35
|
+
item: T;
|
|
36
|
+
from: number;
|
|
37
|
+
to: number;
|
|
38
|
+
}) => void) & ((event: "update:modelValue", value: T[]) => void);
|
|
39
|
+
}>) => import("vue").VNode & {
|
|
40
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
41
|
+
};
|
|
42
|
+
declare const _default: typeof __VLS_export;
|
|
43
|
+
export default _default;
|
|
44
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
45
|
+
[K in keyof T]: T[K];
|
|
46
|
+
} : {
|
|
47
|
+
[K in keyof T as K]: T[K];
|
|
48
|
+
}) & {};
|
|
@@ -111,10 +111,17 @@
|
|
|
111
111
|
<tr
|
|
112
112
|
v-for="(row, index) in rows"
|
|
113
113
|
:key="keyOf(row, index)"
|
|
114
|
+
:draggable="isDraggable(row, index) ? 'true' : void 0"
|
|
115
|
+
v-bind="rowAttrs?.(row, index)"
|
|
114
116
|
class="k-table-row"
|
|
115
|
-
:class="{
|
|
117
|
+
:class="{
|
|
118
|
+
'is-selected': isSelected(row, index),
|
|
119
|
+
'is-dragging': draggedKeys.has(keyOf(row, index))
|
|
120
|
+
}"
|
|
116
121
|
:style="{ '--k-row-delay': rowDelay(index, stagger ? void 0 : 0) }"
|
|
117
122
|
@click="onRowClick(row, index, $event)"
|
|
123
|
+
@dragstart="onRowDragStart(row, index, $event)"
|
|
124
|
+
@dragend="onRowDragEnd(row, $event)"
|
|
118
125
|
>
|
|
119
126
|
<td v-if="selectable" class="k-table-check-cell" @click.stop>
|
|
120
127
|
<label class="k-table-check-hit">
|
|
@@ -148,6 +155,7 @@
|
|
|
148
155
|
v-else-if="column.key === linkColumnKey && rowLinks.has(row)"
|
|
149
156
|
v-bind="rowLinks.get(row).attrs"
|
|
150
157
|
class="k-table-link"
|
|
158
|
+
:draggable="isDraggable(row, index) ? 'false' : void 0"
|
|
151
159
|
@click.stop
|
|
152
160
|
>
|
|
153
161
|
<slot
|
|
@@ -216,9 +224,13 @@ const props = defineProps({
|
|
|
216
224
|
stickyHeader: { type: Boolean, required: false, default: true },
|
|
217
225
|
maxHeight: { type: String, required: false },
|
|
218
226
|
bordered: { type: Boolean, required: false, default: true },
|
|
219
|
-
stagger: { type: Boolean, required: false, default: true }
|
|
227
|
+
stagger: { type: Boolean, required: false, default: true },
|
|
228
|
+
rowAttrs: { type: Function, required: false },
|
|
229
|
+
rowDraggable: { type: [Boolean, Function], required: false },
|
|
230
|
+
dragData: { type: Function, required: false },
|
|
231
|
+
dragEffect: { type: null, required: false, default: "move" }
|
|
220
232
|
});
|
|
221
|
-
const emit = defineEmits(["rowClick"]);
|
|
233
|
+
const emit = defineEmits(["rowClick", "rowDragStart", "rowDragEnd"]);
|
|
222
234
|
defineSlots();
|
|
223
235
|
const sort = defineModel("sort", { type: [Object, null], ...{ default: null } });
|
|
224
236
|
const selected = defineModel("selected", { type: Array, ...{ default: () => [] } });
|
|
@@ -372,6 +384,34 @@ function onRowClick(row, index, event) {
|
|
|
372
384
|
})
|
|
373
385
|
);
|
|
374
386
|
}
|
|
387
|
+
function isDraggable(row, index) {
|
|
388
|
+
const draggable = props.rowDraggable;
|
|
389
|
+
if (!draggable || !props.dragData) return false;
|
|
390
|
+
return draggable === true || draggable(row, index);
|
|
391
|
+
}
|
|
392
|
+
const draggedKeys = ref(/* @__PURE__ */ new Set());
|
|
393
|
+
let draggedRows = [];
|
|
394
|
+
function onRowDragStart(row, index, event) {
|
|
395
|
+
if (!isDraggable(row, index) || !event.dataTransfer || !props.dragData) return;
|
|
396
|
+
const rows = props.selectable && isSelected(row, index) ? props.rows.filter((entry, position) => isSelected(entry, position)) : [row];
|
|
397
|
+
const data = props.dragData(row, rows);
|
|
398
|
+
if (!data) {
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
for (const [type, value] of Object.entries(data)) event.dataTransfer.setData(type, value);
|
|
403
|
+
event.dataTransfer.effectAllowed = props.dragEffect;
|
|
404
|
+
draggedRows = rows;
|
|
405
|
+
draggedKeys.value = new Set(rows.map((entry) => keyOf(entry, props.rows.indexOf(entry))));
|
|
406
|
+
emit("rowDragStart", { row, rows, event });
|
|
407
|
+
}
|
|
408
|
+
function onRowDragEnd(row, event) {
|
|
409
|
+
if (!draggedKeys.value.size) return;
|
|
410
|
+
const rows = draggedRows;
|
|
411
|
+
draggedRows = [];
|
|
412
|
+
draggedKeys.value = /* @__PURE__ */ new Set();
|
|
413
|
+
emit("rowDragEnd", { row, rows, event });
|
|
414
|
+
}
|
|
375
415
|
const skeletonWidths = [72, 48, 60, 36, 54, 66, 42];
|
|
376
416
|
function skeletonWidth(rowIndex, columnIndex) {
|
|
377
417
|
return `${skeletonWidths[(rowIndex + columnIndex * 3) % skeletonWidths.length]}%`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LinkTarget } from '../core/types';
|
|
2
|
-
import type { RowKey, TableColumn, TableDensity, TableSort } from './types';
|
|
2
|
+
import type { RowKey, TableColumn, TableDensity, TableDragData, TableRowAttrs, TableRowDrag, TableSort } from './types';
|
|
3
3
|
declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
4
|
props: import("vue").PublicProps & __VLS_PrettifyLocal<({
|
|
5
5
|
rows: T[];
|
|
@@ -22,11 +22,17 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
|
|
|
22
22
|
maxHeight?: string;
|
|
23
23
|
bordered?: boolean;
|
|
24
24
|
stagger?: boolean;
|
|
25
|
+
rowAttrs?: (row: T, index: number) => TableRowAttrs;
|
|
26
|
+
rowDraggable?: boolean | ((row: T, index: number) => boolean);
|
|
27
|
+
dragData?: (row: T, rows: T[]) => TableDragData | null | undefined;
|
|
28
|
+
dragEffect?: DataTransfer["effectAllowed"];
|
|
25
29
|
} & {
|
|
26
30
|
sort?: TableSort | null;
|
|
27
31
|
selected?: RowKey[];
|
|
28
32
|
}) & {
|
|
29
33
|
onRowClick?: ((row: T, index: number, event: MouseEvent) => any) | undefined;
|
|
34
|
+
onRowDragStart?: ((drag: TableRowDrag<T>) => any) | undefined;
|
|
35
|
+
onRowDragEnd?: ((drag: TableRowDrag<T>) => any) | undefined;
|
|
30
36
|
"onUpdate:sort"?: ((value: TableSort | null) => any) | undefined;
|
|
31
37
|
"onUpdate:selected"?: ((value: RowKey[]) => any) | undefined;
|
|
32
38
|
} & Partial<import("vue").HTMLAttributes & import("vue").ReservedProps>> & (typeof globalThis extends {
|
|
@@ -48,7 +54,7 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
|
|
|
48
54
|
} & {
|
|
49
55
|
empty?: () => unknown;
|
|
50
56
|
};
|
|
51
|
-
emit: ((evt: "rowClick", row: T, index: number, event: MouseEvent) => void) & (((event: "update:sort", value: TableSort | null) => void) & ((event: "update:selected", value: RowKey[]) => void));
|
|
57
|
+
emit: (((evt: "rowClick", row: T, index: number, event: MouseEvent) => void) & ((evt: "rowDragStart", drag: TableRowDrag<T>) => void) & ((evt: "rowDragEnd", drag: TableRowDrag<T>) => void)) & (((event: "update:sort", value: TableSort | null) => void) & ((event: "update:selected", value: RowKey[]) => void));
|
|
52
58
|
}>) => import("vue").VNode & {
|
|
53
59
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
54
60
|
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span
|
|
3
|
+
class="k-thumbnail"
|
|
4
|
+
:class="[
|
|
5
|
+
size ? `k-thumbnail-${size}` : 'k-thumbnail-fluid',
|
|
6
|
+
`k-thumbnail-${fit}`,
|
|
7
|
+
`k-thumbnail-rounded-${radius}`,
|
|
8
|
+
{
|
|
9
|
+
'has-media': hasMedia,
|
|
10
|
+
'is-loading': loading,
|
|
11
|
+
'is-missing': isMissing
|
|
12
|
+
}
|
|
13
|
+
]"
|
|
14
|
+
:style="{ '--k-thumbnail-aspect': aspectRatio }"
|
|
15
|
+
>
|
|
16
|
+
<span v-if="$slots.default" class="k-thumbnail-content"><slot /></span>
|
|
17
|
+
<template v-else>
|
|
18
|
+
<img
|
|
19
|
+
v-if="showImage"
|
|
20
|
+
ref="image"
|
|
21
|
+
class="k-thumbnail-media"
|
|
22
|
+
:class="{ 'is-loaded': loaded }"
|
|
23
|
+
:src="src"
|
|
24
|
+
:alt="alt ?? ''"
|
|
25
|
+
:style="mediaStyle"
|
|
26
|
+
:loading="lazy ? 'lazy' : void 0"
|
|
27
|
+
decoding="async"
|
|
28
|
+
draggable="false"
|
|
29
|
+
@load="loaded = true"
|
|
30
|
+
@error="failed = true"
|
|
31
|
+
/>
|
|
32
|
+
<span
|
|
33
|
+
v-else
|
|
34
|
+
class="k-thumbnail-frame"
|
|
35
|
+
:role="alt ? 'img' : void 0"
|
|
36
|
+
:aria-label="alt || void 0"
|
|
37
|
+
:aria-hidden="alt ? void 0 : 'true'"
|
|
38
|
+
>
|
|
39
|
+
<video
|
|
40
|
+
v-if="showVideo"
|
|
41
|
+
ref="video"
|
|
42
|
+
class="k-thumbnail-media"
|
|
43
|
+
:class="{ 'is-loaded': loaded }"
|
|
44
|
+
:src="videoSrc"
|
|
45
|
+
:style="mediaStyle"
|
|
46
|
+
preload="metadata"
|
|
47
|
+
muted
|
|
48
|
+
playsinline
|
|
49
|
+
tabindex="-1"
|
|
50
|
+
@loadeddata="loaded = true"
|
|
51
|
+
@error="failed = true"
|
|
52
|
+
/>
|
|
53
|
+
<span v-if="showVideo" class="k-thumbnail-play"><Icon name="play" /></span>
|
|
54
|
+
<Icon v-else class="k-thumbnail-icon" :name="iconName" />
|
|
55
|
+
</span>
|
|
56
|
+
</template>
|
|
57
|
+
<span v-if="isMissing" class="k-visually-hidden">{{ missingCopy }}</span>
|
|
58
|
+
<span
|
|
59
|
+
v-if="$slots['top-start']"
|
|
60
|
+
class="k-thumbnail-overlay k-thumbnail-top-start"
|
|
61
|
+
:class="{ 'is-reveal': reveal.includes('top-start') }"
|
|
62
|
+
>
|
|
63
|
+
<slot name="top-start" />
|
|
64
|
+
</span>
|
|
65
|
+
<span
|
|
66
|
+
v-if="$slots['top-end']"
|
|
67
|
+
class="k-thumbnail-overlay k-thumbnail-top-end"
|
|
68
|
+
:class="{ 'is-reveal': reveal.includes('top-end') }"
|
|
69
|
+
>
|
|
70
|
+
<slot name="top-end" />
|
|
71
|
+
</span>
|
|
72
|
+
<span
|
|
73
|
+
v-if="caption || $slots.caption"
|
|
74
|
+
class="k-thumbnail-overlay k-thumbnail-caption"
|
|
75
|
+
:class="{ 'is-reveal': reveal.includes('caption') }"
|
|
76
|
+
>
|
|
77
|
+
<slot name="caption">
|
|
78
|
+
<span class="k-thumbnail-caption-text" :title="caption">{{ caption }}</span>
|
|
79
|
+
</slot>
|
|
80
|
+
</span>
|
|
81
|
+
</span>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script setup>
|
|
85
|
+
import { computed, onMounted, ref, useTemplateRef, watch } from "vue";
|
|
86
|
+
import { useLocale } from "../../composables/useLocale";
|
|
87
|
+
import Icon from "../core/Icon.vue";
|
|
88
|
+
const props = defineProps({
|
|
89
|
+
src: { type: String, required: false },
|
|
90
|
+
alt: { type: String, required: false },
|
|
91
|
+
kind: { type: String, required: false, default: "image" },
|
|
92
|
+
icon: { type: null, required: false },
|
|
93
|
+
fit: { type: String, required: false, default: "cover" },
|
|
94
|
+
aspect: { type: [String, Number], required: false, default: 1 },
|
|
95
|
+
size: { type: String, required: false },
|
|
96
|
+
rounded: { type: String, required: false },
|
|
97
|
+
missing: { type: Boolean, required: false },
|
|
98
|
+
missingText: { type: String, required: false },
|
|
99
|
+
focal: { type: [Object, null], required: false },
|
|
100
|
+
objectPosition: { type: String, required: false },
|
|
101
|
+
caption: { type: String, required: false },
|
|
102
|
+
reveal: { type: Array, required: false, default: () => ["caption"] },
|
|
103
|
+
lazy: { type: Boolean, required: false, default: true }
|
|
104
|
+
});
|
|
105
|
+
defineSlots();
|
|
106
|
+
const KIND_ICONS = {
|
|
107
|
+
image: "photo",
|
|
108
|
+
video: "video-camera",
|
|
109
|
+
file: "document",
|
|
110
|
+
icon: "photo"
|
|
111
|
+
};
|
|
112
|
+
const { t } = useLocale();
|
|
113
|
+
const image = useTemplateRef("image");
|
|
114
|
+
const video = useTemplateRef("video");
|
|
115
|
+
const failed = ref(false);
|
|
116
|
+
const loaded = ref(false);
|
|
117
|
+
const isMissing = computed(() => props.missing || failed.value);
|
|
118
|
+
const playable = computed(() => Boolean(props.src) && !isMissing.value);
|
|
119
|
+
const showImage = computed(() => props.kind === "image" && playable.value);
|
|
120
|
+
const showVideo = computed(() => props.kind === "video" && playable.value);
|
|
121
|
+
const hasMedia = computed(() => showImage.value || showVideo.value);
|
|
122
|
+
const loading = computed(() => hasMedia.value && !loaded.value);
|
|
123
|
+
const iconName = computed(() => props.icon ?? KIND_ICONS[props.kind]);
|
|
124
|
+
const missingCopy = computed(() => props.missingText ?? t("thumbnail.missing"));
|
|
125
|
+
const radius = computed(() => {
|
|
126
|
+
if (props.rounded) return props.rounded;
|
|
127
|
+
return props.size === "xs" || props.size === "sm" ? "sm" : "md";
|
|
128
|
+
});
|
|
129
|
+
const aspectRatio = computed(() => String(props.aspect));
|
|
130
|
+
const videoSrc = computed(
|
|
131
|
+
() => props.src && !props.src.includes("#") ? `${props.src}#t=0.001` : props.src
|
|
132
|
+
);
|
|
133
|
+
const position = computed(() => {
|
|
134
|
+
if (props.objectPosition) return props.objectPosition;
|
|
135
|
+
if (!props.focal) return void 0;
|
|
136
|
+
const x = Math.min(1, Math.max(0, props.focal.x)) * 100;
|
|
137
|
+
const y = Math.min(1, Math.max(0, props.focal.y)) * 100;
|
|
138
|
+
return `${x}% ${y}%`;
|
|
139
|
+
});
|
|
140
|
+
const mediaStyle = computed(() => position.value ? { objectPosition: position.value } : void 0);
|
|
141
|
+
watch(
|
|
142
|
+
() => [props.src, props.kind],
|
|
143
|
+
() => {
|
|
144
|
+
failed.value = false;
|
|
145
|
+
loaded.value = false;
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
onMounted(() => {
|
|
149
|
+
const element = image.value;
|
|
150
|
+
if (element?.complete) {
|
|
151
|
+
if (element.naturalWidth === 0) failed.value = true;
|
|
152
|
+
else loaded.value = true;
|
|
153
|
+
}
|
|
154
|
+
if (video.value?.error) failed.value = true;
|
|
155
|
+
else if (video.value && video.value.readyState >= 2) loaded.value = true;
|
|
156
|
+
});
|
|
157
|
+
</script>
|