@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
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="k-tile-grid"
|
|
4
|
+
:class="{
|
|
5
|
+
'is-selectable': selectable,
|
|
6
|
+
'is-sortable': canSort,
|
|
7
|
+
'has-handle': Boolean(handle),
|
|
8
|
+
'has-selection': selectable && selected.length > 0,
|
|
9
|
+
'is-dragging': sorter.dragging.value !== null || dragKeys.length > 0,
|
|
10
|
+
'is-disabled': disabled
|
|
11
|
+
}"
|
|
12
|
+
>
|
|
13
|
+
<Grid :min-item-width="minItemWidth" :columns="columns ?? MAX_COLUMNS" :gap="gap">
|
|
14
|
+
<div
|
|
15
|
+
v-if="items.length"
|
|
16
|
+
ref="list"
|
|
17
|
+
class="k-tile-grid-list"
|
|
18
|
+
:role="selectable ? 'listbox' : 'list'"
|
|
19
|
+
:aria-label="labelText"
|
|
20
|
+
:aria-multiselectable="selectable ? 'true' : void 0"
|
|
21
|
+
:aria-disabled="selectable && disabled ? 'true' : void 0"
|
|
22
|
+
:aria-describedby="hintText ? hintId : void 0"
|
|
23
|
+
>
|
|
24
|
+
<div
|
|
25
|
+
v-for="(item, index) in items"
|
|
26
|
+
:key="keyOf(item, index)"
|
|
27
|
+
class="k-tile-grid-item"
|
|
28
|
+
:class="{
|
|
29
|
+
'is-moving': sorter.dragging.value === index,
|
|
30
|
+
'is-dragging': isDragged(item, index)
|
|
31
|
+
}"
|
|
32
|
+
:role="selectable ? 'option' : 'listitem'"
|
|
33
|
+
:aria-selected="selectable ? isSelected(item, index) : void 0"
|
|
34
|
+
:aria-label="itemLabel ? itemLabel(item) : void 0"
|
|
35
|
+
:tabindex="index === focusIndex ? 0 : -1"
|
|
36
|
+
:draggable="canDragOut ? 'true' : void 0"
|
|
37
|
+
v-bind="canSort ? sorter.itemProps(index) : void 0"
|
|
38
|
+
@focus="focusIndex = index"
|
|
39
|
+
@click="onTileClick($event, item, index)"
|
|
40
|
+
@keydown="onTileKeydown($event, item, index)"
|
|
41
|
+
@dragstart="onDragStart($event, item, index)"
|
|
42
|
+
@dragend="onDragEnd($event, item)"
|
|
43
|
+
>
|
|
44
|
+
<div class="k-tile-grid-tile">
|
|
45
|
+
<slot
|
|
46
|
+
name="tile"
|
|
47
|
+
:item="item"
|
|
48
|
+
:index="index"
|
|
49
|
+
:selected="isSelected(item, index)"
|
|
50
|
+
:dragging="sorter.dragging.value === index || isDragged(item, index)"
|
|
51
|
+
/>
|
|
52
|
+
<span
|
|
53
|
+
v-if="selectable"
|
|
54
|
+
class="k-tile-grid-check"
|
|
55
|
+
aria-hidden="true"
|
|
56
|
+
@click.stop="onCheckClick($event, item, index)"
|
|
57
|
+
>
|
|
58
|
+
<Icon name="check" />
|
|
59
|
+
</span>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div v-if="$slots.add" class="k-tile-grid-add">
|
|
64
|
+
<slot name="add" />
|
|
65
|
+
</div>
|
|
66
|
+
</Grid>
|
|
67
|
+
<span v-if="hintText" :id="hintId" class="k-visually-hidden">{{ hintText }}</span>
|
|
68
|
+
<LiveRegion :message="sorter.announcement.value" />
|
|
69
|
+
</div>
|
|
70
|
+
</template>
|
|
71
|
+
|
|
72
|
+
<script setup>
|
|
73
|
+
import { computed, ref, useId, useTemplateRef, watch } from "vue";
|
|
74
|
+
import { useLocale } from "../../composables/useLocale";
|
|
75
|
+
import { useSortable } from "../../composables/useSortable";
|
|
76
|
+
import LiveRegion from "../../internal/core/LiveRegion.vue";
|
|
77
|
+
import { gridNeighbor, isRtl, layoutRect } from "../../internal/data/sortable";
|
|
78
|
+
import Icon from "../core/Icon.vue";
|
|
79
|
+
import Grid from "../layout/Grid.vue";
|
|
80
|
+
const props = defineProps({
|
|
81
|
+
itemKey: { type: [String, Function], required: false, default: "id" },
|
|
82
|
+
itemLabel: { type: Function, required: false },
|
|
83
|
+
label: { type: String, required: false },
|
|
84
|
+
minItemWidth: { type: String, required: false, default: "10rem" },
|
|
85
|
+
columns: { type: Number, required: false },
|
|
86
|
+
gap: { type: String, required: false, default: "md" },
|
|
87
|
+
selectable: { type: Boolean, required: false },
|
|
88
|
+
sortable: { type: Boolean, required: false },
|
|
89
|
+
handle: { type: String, required: false },
|
|
90
|
+
dragData: { type: Function, required: false },
|
|
91
|
+
dragEffect: { type: null, required: false, default: "move" },
|
|
92
|
+
disabled: { type: Boolean, required: false },
|
|
93
|
+
onActivate: { type: Function, required: false }
|
|
94
|
+
});
|
|
95
|
+
const items = defineModel("items", { type: Array, ...{ required: true } });
|
|
96
|
+
const selected = defineModel("selected", { type: Array, ...{ default: () => [] } });
|
|
97
|
+
const emit = defineEmits(["move", "itemDragStart", "itemDragEnd"]);
|
|
98
|
+
defineSlots();
|
|
99
|
+
const MAX_COLUMNS = 64;
|
|
100
|
+
const INTERACTIVE = 'a, button, input, select, textarea, label, summary, [role="button"]';
|
|
101
|
+
const { t } = useLocale();
|
|
102
|
+
const hintId = `${useId()}-hint`;
|
|
103
|
+
const list = useTemplateRef("list");
|
|
104
|
+
const focusIndex = ref(0);
|
|
105
|
+
const anchor = ref(null);
|
|
106
|
+
const dragKeys = ref([]);
|
|
107
|
+
const canSort = computed(() => props.sortable && !props.disabled);
|
|
108
|
+
const canDragOut = computed(() => Boolean(props.dragData) && !canSort.value && !props.disabled);
|
|
109
|
+
const canSelect = computed(() => props.selectable && !props.disabled);
|
|
110
|
+
const labelText = computed(() => props.label ?? t("tileGrid.label"));
|
|
111
|
+
const hintText = computed(() => {
|
|
112
|
+
const parts = [t("tileGrid.navigateHint")];
|
|
113
|
+
if (canSelect.value) parts.push(t("tileGrid.selectHint"));
|
|
114
|
+
if (canSort.value) parts.push(t("tileGrid.sortHint"));
|
|
115
|
+
return parts.join(". ");
|
|
116
|
+
});
|
|
117
|
+
function keyOf(item, index) {
|
|
118
|
+
if (typeof props.itemKey === "function") return props.itemKey(item, index);
|
|
119
|
+
const value = item?.[props.itemKey];
|
|
120
|
+
return typeof value === "string" || typeof value === "number" ? value : index;
|
|
121
|
+
}
|
|
122
|
+
function labelOf(item) {
|
|
123
|
+
return props.itemLabel ? props.itemLabel(item) : String(keyOf(item, items.value.indexOf(item)));
|
|
124
|
+
}
|
|
125
|
+
const selectedSet = computed(() => new Set(selected.value));
|
|
126
|
+
function isSelected(item, index) {
|
|
127
|
+
return Boolean(props.selectable) && selectedSet.value.has(keyOf(item, index));
|
|
128
|
+
}
|
|
129
|
+
function isDragged(item, index) {
|
|
130
|
+
return dragKeys.value.includes(keyOf(item, index));
|
|
131
|
+
}
|
|
132
|
+
watch(
|
|
133
|
+
() => items.value.length,
|
|
134
|
+
(length) => {
|
|
135
|
+
if (focusIndex.value >= length) focusIndex.value = Math.max(0, length - 1);
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
const sorter = useSortable(list, {
|
|
139
|
+
items: () => items.value,
|
|
140
|
+
orientation: "grid",
|
|
141
|
+
handle: props.handle ?? ".k-tile-grid-tile",
|
|
142
|
+
preview: ".k-tile-grid-tile",
|
|
143
|
+
disabled: () => !canSort.value,
|
|
144
|
+
label: labelOf,
|
|
145
|
+
onMove: (next, move) => {
|
|
146
|
+
items.value = next;
|
|
147
|
+
focusIndex.value = move.to;
|
|
148
|
+
emit("move", { item: move.item, from: move.from, to: move.to, items: next });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
function toggle(item, index, event) {
|
|
152
|
+
if (!canSelect.value) return;
|
|
153
|
+
const key = keyOf(item, index);
|
|
154
|
+
if (event?.shiftKey && anchor.value !== null) {
|
|
155
|
+
const keys = items.value.map((entry, position) => keyOf(entry, position));
|
|
156
|
+
const from = keys.indexOf(anchor.value);
|
|
157
|
+
if (from !== -1) {
|
|
158
|
+
const range = keys.slice(Math.min(from, index), Math.max(from, index) + 1);
|
|
159
|
+
selected.value = [.../* @__PURE__ */ new Set([...selected.value, ...range])];
|
|
160
|
+
anchor.value = key;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
selected.value = selectedSet.value.has(key) ? selected.value.filter((entry) => entry !== key) : [...selected.value, key];
|
|
165
|
+
anchor.value = key;
|
|
166
|
+
}
|
|
167
|
+
function selectAll() {
|
|
168
|
+
if (!canSelect.value) return;
|
|
169
|
+
const keys = items.value.map((item, index) => keyOf(item, index));
|
|
170
|
+
selected.value = [.../* @__PURE__ */ new Set([...selected.value, ...keys])];
|
|
171
|
+
}
|
|
172
|
+
function activate(item, index, event) {
|
|
173
|
+
if (props.onActivate) props.onActivate(item, index, event);
|
|
174
|
+
else toggle(item, index, event);
|
|
175
|
+
}
|
|
176
|
+
function onCheckClick(event, item, index) {
|
|
177
|
+
focusIndex.value = index;
|
|
178
|
+
toggle(item, index, event);
|
|
179
|
+
}
|
|
180
|
+
function onTileClick(event, item, index) {
|
|
181
|
+
const tile = event.currentTarget;
|
|
182
|
+
const origin = event.target?.closest(INTERACTIVE);
|
|
183
|
+
if (origin && origin !== tile && tile.contains(origin)) return;
|
|
184
|
+
const selecting = selected.value.length > 0 || event.shiftKey || event.metaKey || event.ctrlKey;
|
|
185
|
+
if (canSelect.value && selecting) toggle(item, index, event);
|
|
186
|
+
else activate(item, index, event);
|
|
187
|
+
}
|
|
188
|
+
function tileElements() {
|
|
189
|
+
return Array.from(list.value?.children ?? []);
|
|
190
|
+
}
|
|
191
|
+
function focusTile(index) {
|
|
192
|
+
focusIndex.value = index;
|
|
193
|
+
tileElements()[index]?.focus();
|
|
194
|
+
}
|
|
195
|
+
function navigationTarget(event, index) {
|
|
196
|
+
const count = items.value.length;
|
|
197
|
+
const rtl = isRtl(list.value);
|
|
198
|
+
switch (event.key) {
|
|
199
|
+
case "ArrowLeft":
|
|
200
|
+
return rtl ? index + 1 : index - 1;
|
|
201
|
+
case "ArrowRight":
|
|
202
|
+
return rtl ? index - 1 : index + 1;
|
|
203
|
+
case "ArrowUp":
|
|
204
|
+
case "ArrowDown":
|
|
205
|
+
return gridNeighbor(
|
|
206
|
+
tileElements().map(layoutRect),
|
|
207
|
+
index,
|
|
208
|
+
event.key === "ArrowUp" ? -1 : 1
|
|
209
|
+
);
|
|
210
|
+
case "Home":
|
|
211
|
+
return 0;
|
|
212
|
+
case "End":
|
|
213
|
+
return count - 1;
|
|
214
|
+
default:
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function onTileKeydown(event, item, index) {
|
|
219
|
+
if (event.target !== event.currentTarget || event.altKey) return;
|
|
220
|
+
const modifier = event.ctrlKey || event.metaKey;
|
|
221
|
+
if (event.key === " " && !modifier) {
|
|
222
|
+
if (!canSelect.value) return;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
toggle(item, index, event);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (event.key === "Enter" && !modifier) {
|
|
228
|
+
if (!props.onActivate && !canSelect.value) return;
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
activate(item, index, event);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (modifier && event.key.toLowerCase() === "a") {
|
|
234
|
+
if (!canSelect.value) return;
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
selectAll();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (modifier) return;
|
|
240
|
+
const target = navigationTarget(event, index);
|
|
241
|
+
if (target === null) return;
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
if (target >= 0 && target < items.value.length) focusTile(target);
|
|
244
|
+
}
|
|
245
|
+
function draggedGroup(item) {
|
|
246
|
+
if (!props.selectable || !selectedSet.value.has(keyOf(item, items.value.indexOf(item))))
|
|
247
|
+
return [item];
|
|
248
|
+
return items.value.filter((entry, index) => isSelected(entry, index));
|
|
249
|
+
}
|
|
250
|
+
let dragged = [];
|
|
251
|
+
function onDragStart(event, item, index) {
|
|
252
|
+
if (canSort.value) event.preventDefault();
|
|
253
|
+
if (!canDragOut.value || !event.dataTransfer || !props.dragData) return;
|
|
254
|
+
const group = draggedGroup(item);
|
|
255
|
+
const data = props.dragData(item, group);
|
|
256
|
+
if (!data) {
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
for (const [type, value] of Object.entries(data)) event.dataTransfer.setData(type, value);
|
|
261
|
+
event.dataTransfer.effectAllowed = props.dragEffect;
|
|
262
|
+
focusIndex.value = index;
|
|
263
|
+
dragged = group;
|
|
264
|
+
dragKeys.value = group.map((entry) => keyOf(entry, items.value.indexOf(entry)));
|
|
265
|
+
emit("itemDragStart", { item, items: group, event });
|
|
266
|
+
}
|
|
267
|
+
function onDragEnd(event, item) {
|
|
268
|
+
if (!dragKeys.value.length) return;
|
|
269
|
+
const group = dragged;
|
|
270
|
+
dragged = [];
|
|
271
|
+
dragKeys.value = [];
|
|
272
|
+
emit("itemDragEnd", { item, items: group, event });
|
|
273
|
+
}
|
|
274
|
+
</script>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { LayoutGap } from '../layout/types';
|
|
2
|
+
import type { RowKey, TileGridDrag, TileGridDragData, TileGridMove } from './types';
|
|
3
|
+
declare const __VLS_export: <T>(__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
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<({
|
|
5
|
+
itemKey?: string | ((item: T, index: number) => RowKey);
|
|
6
|
+
itemLabel?: (item: T) => string;
|
|
7
|
+
label?: string;
|
|
8
|
+
minItemWidth?: string;
|
|
9
|
+
columns?: number;
|
|
10
|
+
gap?: LayoutGap;
|
|
11
|
+
selectable?: boolean;
|
|
12
|
+
sortable?: boolean;
|
|
13
|
+
handle?: string;
|
|
14
|
+
dragData?: (item: T, items: T[]) => TileGridDragData | null | undefined;
|
|
15
|
+
dragEffect?: DataTransfer["effectAllowed"];
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
onActivate?: (item: T, index: number, event: MouseEvent | KeyboardEvent) => void;
|
|
18
|
+
} & {
|
|
19
|
+
items: T[];
|
|
20
|
+
selected?: RowKey[];
|
|
21
|
+
}) & {
|
|
22
|
+
onMove?: ((move: TileGridMove<T>) => any) | undefined;
|
|
23
|
+
"onUpdate:selected"?: ((value: RowKey[]) => any) | undefined;
|
|
24
|
+
onItemDragStart?: ((drag: TileGridDrag<T>) => any) | undefined;
|
|
25
|
+
onItemDragEnd?: ((drag: TileGridDrag<T>) => any) | undefined;
|
|
26
|
+
"onUpdate:items"?: ((value: T[]) => any) | undefined;
|
|
27
|
+
} & Partial<import("vue").HTMLAttributes & import("vue").ReservedProps>> & (typeof globalThis extends {
|
|
28
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
29
|
+
} ? P : {});
|
|
30
|
+
expose: (exposed: {}) => void;
|
|
31
|
+
attrs: any;
|
|
32
|
+
slots: {
|
|
33
|
+
tile?: (props: {
|
|
34
|
+
item: T;
|
|
35
|
+
index: number;
|
|
36
|
+
selected: boolean;
|
|
37
|
+
dragging: boolean;
|
|
38
|
+
}) => unknown;
|
|
39
|
+
add?: () => unknown;
|
|
40
|
+
};
|
|
41
|
+
emit: (((evt: "move", move: TileGridMove<T>) => void) & ((evt: "itemDragStart", drag: TileGridDrag<T>) => void) & ((evt: "itemDragEnd", drag: TileGridDrag<T>) => void)) & (((event: "update:selected", value: RowKey[]) => void) & ((event: "update:items", value: T[]) => void));
|
|
42
|
+
}>) => import("vue").VNode & {
|
|
43
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
44
|
+
};
|
|
45
|
+
declare const _default: typeof __VLS_export;
|
|
46
|
+
export default _default;
|
|
47
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
48
|
+
[K in keyof T]: T[K];
|
|
49
|
+
} : {
|
|
50
|
+
[K in keyof T as K]: T[K];
|
|
51
|
+
}) & {};
|
|
@@ -6,11 +6,14 @@ export { default as FilterPill } from './FilterPill.vue';
|
|
|
6
6
|
export { default as FilterPills } from './FilterPills.vue';
|
|
7
7
|
export { default as Pagination } from './Pagination.vue';
|
|
8
8
|
export { default as SelectionBar } from './SelectionBar.vue';
|
|
9
|
+
export { default as SortableList } from './SortableList.vue';
|
|
9
10
|
export { default as Stat } from './Stat.vue';
|
|
10
11
|
export { default as Table } from './Table.vue';
|
|
11
12
|
export { default as Tag } from './Tag.vue';
|
|
12
13
|
export { default as TagList } from './TagList.vue';
|
|
13
14
|
export { default as RecordList } from './RecordList.vue';
|
|
15
|
+
export { default as Thumbnail } from './Thumbnail.vue';
|
|
16
|
+
export { default as TileGrid } from './TileGrid.vue';
|
|
14
17
|
export { default as Timeline } from './Timeline.vue';
|
|
15
18
|
export { default as Tree } from './Tree.vue';
|
|
16
19
|
export type * from './types';
|
|
@@ -6,11 +6,14 @@ export { default as FilterPill } from "./FilterPill.vue";
|
|
|
6
6
|
export { default as FilterPills } from "./FilterPills.vue";
|
|
7
7
|
export { default as Pagination } from "./Pagination.vue";
|
|
8
8
|
export { default as SelectionBar } from "./SelectionBar.vue";
|
|
9
|
+
export { default as SortableList } from "./SortableList.vue";
|
|
9
10
|
export { default as Stat } from "./Stat.vue";
|
|
10
11
|
export { default as Table } from "./Table.vue";
|
|
11
12
|
export { default as Tag } from "./Tag.vue";
|
|
12
13
|
export { default as TagList } from "./TagList.vue";
|
|
13
14
|
export { default as RecordList } from "./RecordList.vue";
|
|
15
|
+
export { default as Thumbnail } from "./Thumbnail.vue";
|
|
16
|
+
export { default as TileGrid } from "./TileGrid.vue";
|
|
14
17
|
export { default as Timeline } from "./Timeline.vue";
|
|
15
18
|
export { default as Tree } from "./Tree.vue";
|
|
16
19
|
export { applyTreeMove } from "../../internal/data/tree.mjs";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
1
2
|
import type { ColorValue, Tone } from '../core/types';
|
|
2
3
|
import type { IconName } from '../../composables/useIcons';
|
|
3
4
|
import type { MenuItems } from '../overlays/types';
|
|
@@ -24,6 +25,15 @@ export interface TableColumn<T = Record<string, unknown>> {
|
|
|
24
25
|
format?: (value: unknown, row: T) => string;
|
|
25
26
|
class?: string;
|
|
26
27
|
}
|
|
28
|
+
export type TableRowAttrs = HTMLAttributes & {
|
|
29
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
export type TableDragData = Record<string, string>;
|
|
32
|
+
export interface TableRowDrag<T> {
|
|
33
|
+
row: T;
|
|
34
|
+
rows: T[];
|
|
35
|
+
event: DragEvent;
|
|
36
|
+
}
|
|
27
37
|
export type PageSize = number | 'all';
|
|
28
38
|
export interface PaginationItem {
|
|
29
39
|
type: 'page' | 'ellipsis';
|
|
@@ -41,6 +51,15 @@ export type StatTrend = 'up' | 'down' | 'flat';
|
|
|
41
51
|
export type StatDeltaTone = 'positive' | 'negative' | 'neutral';
|
|
42
52
|
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
43
53
|
export type AvatarShape = 'circle' | 'square';
|
|
54
|
+
export interface FocalPoint {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
}
|
|
58
|
+
export type ThumbnailKind = 'image' | 'video' | 'file' | 'icon';
|
|
59
|
+
export type ThumbnailFit = 'cover' | 'contain';
|
|
60
|
+
export type ThumbnailSize = 'xs' | 'sm' | 'md' | 'lg';
|
|
61
|
+
export type ThumbnailRounded = 'none' | 'sm' | 'md' | 'lg' | 'full';
|
|
62
|
+
export type ThumbnailOverlay = 'caption' | 'top-start' | 'top-end';
|
|
44
63
|
export interface AvatarItem {
|
|
45
64
|
src?: string;
|
|
46
65
|
name?: string;
|
|
@@ -111,6 +130,26 @@ export interface TagListDrop {
|
|
|
111
130
|
dataTransfer: DataTransfer | null;
|
|
112
131
|
event: DragEvent;
|
|
113
132
|
}
|
|
133
|
+
export interface SortableListItem {
|
|
134
|
+
value: string | number;
|
|
135
|
+
label: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
icon?: IconName;
|
|
138
|
+
disabled?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export type SortableListSize = 'sm' | 'md';
|
|
141
|
+
export type TileGridDragData = Record<string, string>;
|
|
142
|
+
export interface TileGridMove<T> {
|
|
143
|
+
item: T;
|
|
144
|
+
from: number;
|
|
145
|
+
to: number;
|
|
146
|
+
items: T[];
|
|
147
|
+
}
|
|
148
|
+
export interface TileGridDrag<T> {
|
|
149
|
+
item: T;
|
|
150
|
+
items: T[];
|
|
151
|
+
event: DragEvent;
|
|
152
|
+
}
|
|
114
153
|
export type TagListAccept = string | string[] | ((event: DragEvent) => boolean);
|
|
115
154
|
export interface RecordListItem {
|
|
116
155
|
id: string | number;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:id="control.id.value"
|
|
4
|
+
role="group"
|
|
5
|
+
data-k-shake
|
|
6
|
+
class="k-focal-point-input"
|
|
7
|
+
:class="[
|
|
8
|
+
{
|
|
9
|
+
'is-disabled': control.disabled.value,
|
|
10
|
+
'is-readonly': readonly,
|
|
11
|
+
'is-invalid': control.invalid.value,
|
|
12
|
+
'is-dragging': dragging,
|
|
13
|
+
'is-editable': editable
|
|
14
|
+
},
|
|
15
|
+
props.class
|
|
16
|
+
]"
|
|
17
|
+
:style="props.style"
|
|
18
|
+
:aria-label="label"
|
|
19
|
+
:aria-labelledby="label || $attrs['aria-label'] ? void 0 : control.labelledBy.value"
|
|
20
|
+
v-bind="$attrs"
|
|
21
|
+
:aria-disabled="control.disabled.value ? 'true' : void 0"
|
|
22
|
+
>
|
|
23
|
+
<div
|
|
24
|
+
ref="areaRef"
|
|
25
|
+
class="k-focal-point-input-area"
|
|
26
|
+
:class="{ 'is-loaded': loaded, 'is-failed': !showImage }"
|
|
27
|
+
@pointerdown="onPointerDown"
|
|
28
|
+
@pointermove="onPointerMove"
|
|
29
|
+
@pointerup="endDrag"
|
|
30
|
+
@pointercancel="endDrag"
|
|
31
|
+
@lostpointercapture="endDrag"
|
|
32
|
+
>
|
|
33
|
+
<img
|
|
34
|
+
v-if="showImage"
|
|
35
|
+
ref="imageRef"
|
|
36
|
+
class="k-focal-point-input-image"
|
|
37
|
+
:src="src"
|
|
38
|
+
:alt="alt ?? ''"
|
|
39
|
+
draggable="false"
|
|
40
|
+
@load="loaded = true"
|
|
41
|
+
@error="failed = true"
|
|
42
|
+
/>
|
|
43
|
+
<span v-else class="k-focal-point-input-placeholder" aria-hidden="true">
|
|
44
|
+
<Icon name="photo" />
|
|
45
|
+
</span>
|
|
46
|
+
<span
|
|
47
|
+
v-if="point"
|
|
48
|
+
class="k-focal-point-input-marker"
|
|
49
|
+
:style="{ left: `${point.x * 100}%`, top: `${point.y * 100}%` }"
|
|
50
|
+
aria-hidden="true"
|
|
51
|
+
/>
|
|
52
|
+
<input
|
|
53
|
+
v-for="axis in AXES"
|
|
54
|
+
:key="axis"
|
|
55
|
+
:ref="(el) => inputs[axis] = el"
|
|
56
|
+
type="range"
|
|
57
|
+
class="k-focal-point-input-axis k-visually-hidden"
|
|
58
|
+
min="0"
|
|
59
|
+
max="100"
|
|
60
|
+
step="1"
|
|
61
|
+
:value="Math.round((point?.[axis] ?? 0.5) * 100)"
|
|
62
|
+
:aria-label="axis === 'x' ? horizontalCopy : verticalCopy"
|
|
63
|
+
:aria-valuetext="point ? percent(point[axis]) : emptyCopy"
|
|
64
|
+
:aria-describedby="joinIds(hintId, control.describedBy.value)"
|
|
65
|
+
:aria-invalid="control.invalid.value ? 'true' : void 0"
|
|
66
|
+
:aria-readonly="readonly ? 'true' : void 0"
|
|
67
|
+
:disabled="control.disabled.value || void 0"
|
|
68
|
+
:tabindex="axis === activeAxis ? 0 : -1"
|
|
69
|
+
@focus="activeAxis = axis"
|
|
70
|
+
@keydown="onKeydown($event, axis)"
|
|
71
|
+
@input="onInput($event, axis)"
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
<span :id="hintId" class="k-visually-hidden">{{ t("focalPoint.hint") }}</span>
|
|
75
|
+
<div class="k-focal-point-input-bar">
|
|
76
|
+
<span class="k-focal-point-input-value k-tabular" aria-hidden="true">{{ valueCopy }}</span>
|
|
77
|
+
<Button
|
|
78
|
+
v-if="clearable && point && editable"
|
|
79
|
+
size="xs"
|
|
80
|
+
variant="ghost"
|
|
81
|
+
tone="neutral"
|
|
82
|
+
icon="arrow-path"
|
|
83
|
+
:label="clearCopy"
|
|
84
|
+
@click="clear"
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<script setup>
|
|
91
|
+
import { computed, onMounted, ref, useAttrs, useId, useTemplateRef, watch } from "vue";
|
|
92
|
+
import { useFieldControl } from "../../composables/useField";
|
|
93
|
+
import { useLocale } from "../../composables/useLocale";
|
|
94
|
+
import { numberFormat } from "../../internal/core/intl";
|
|
95
|
+
import { joinIds } from "../../internal/forms/control";
|
|
96
|
+
import { hasNameAttrs, warnUnnamed } from "../../internal/forms/name";
|
|
97
|
+
import Button from "../core/Button.vue";
|
|
98
|
+
import Icon from "../core/Icon.vue";
|
|
99
|
+
defineOptions({ inheritAttrs: false });
|
|
100
|
+
const props = defineProps({
|
|
101
|
+
src: { type: String, required: false },
|
|
102
|
+
alt: { type: String, required: false },
|
|
103
|
+
label: { type: String, required: false },
|
|
104
|
+
clearable: { type: Boolean, required: false },
|
|
105
|
+
clearLabel: { type: String, required: false },
|
|
106
|
+
horizontalLabel: { type: String, required: false },
|
|
107
|
+
verticalLabel: { type: String, required: false },
|
|
108
|
+
emptyText: { type: String, required: false },
|
|
109
|
+
step: { type: Number, required: false, default: 0.01 },
|
|
110
|
+
invalid: { type: Boolean, required: false, default: void 0 },
|
|
111
|
+
disabled: { type: Boolean, required: false, default: void 0 },
|
|
112
|
+
readonly: { type: Boolean, required: false },
|
|
113
|
+
class: { type: null, required: false },
|
|
114
|
+
style: { type: null, required: false }
|
|
115
|
+
});
|
|
116
|
+
const model = defineModel({ type: null });
|
|
117
|
+
const AXES = ["x", "y"];
|
|
118
|
+
const KEY_DELTAS = {
|
|
119
|
+
ArrowLeft: [-1, 0],
|
|
120
|
+
ArrowRight: [1, 0],
|
|
121
|
+
ArrowUp: [0, -1],
|
|
122
|
+
ArrowDown: [0, 1]
|
|
123
|
+
};
|
|
124
|
+
const AXIS_KEYS = {
|
|
125
|
+
Home: () => 0,
|
|
126
|
+
End: () => 1,
|
|
127
|
+
PageUp: (value, page) => value - page,
|
|
128
|
+
PageDown: (value, page) => value + page
|
|
129
|
+
};
|
|
130
|
+
const { t, locale } = useLocale();
|
|
131
|
+
const attrs = useAttrs();
|
|
132
|
+
const hintId = useId();
|
|
133
|
+
const areaRef = useTemplateRef("areaRef");
|
|
134
|
+
const imageRef = useTemplateRef("imageRef");
|
|
135
|
+
const inputs = { x: null, y: null };
|
|
136
|
+
const activeAxis = ref("x");
|
|
137
|
+
const dragging = ref(false);
|
|
138
|
+
const loaded = ref(false);
|
|
139
|
+
const failed = ref(false);
|
|
140
|
+
const control = useFieldControl({
|
|
141
|
+
invalid: () => props.invalid,
|
|
142
|
+
disabled: () => props.disabled,
|
|
143
|
+
labelable: false
|
|
144
|
+
});
|
|
145
|
+
warnUnnamed(
|
|
146
|
+
"FocalPointInput",
|
|
147
|
+
() => Boolean(props.label || control.labelledBy.value) || hasNameAttrs(attrs)
|
|
148
|
+
);
|
|
149
|
+
const editable = computed(() => !control.disabled.value && !props.readonly);
|
|
150
|
+
const showImage = computed(() => Boolean(props.src) && !failed.value);
|
|
151
|
+
const point = computed(() => model.value ? normalize(model.value) : null);
|
|
152
|
+
const horizontalCopy = computed(() => props.horizontalLabel ?? t("focalPoint.horizontal"));
|
|
153
|
+
const verticalCopy = computed(() => props.verticalLabel ?? t("focalPoint.vertical"));
|
|
154
|
+
const emptyCopy = computed(() => props.emptyText ?? t("focalPoint.empty"));
|
|
155
|
+
const clearCopy = computed(() => props.clearLabel ?? t("focalPoint.reset"));
|
|
156
|
+
const valueCopy = computed(
|
|
157
|
+
() => point.value ? t("focalPoint.value", { x: percent(point.value.x), y: percent(point.value.y) }) : emptyCopy.value
|
|
158
|
+
);
|
|
159
|
+
function clamp(value) {
|
|
160
|
+
return Math.min(1, Math.max(0, Number.isFinite(value) ? value : 0.5));
|
|
161
|
+
}
|
|
162
|
+
function normalize(value) {
|
|
163
|
+
return { x: clamp(value.x), y: clamp(value.y) };
|
|
164
|
+
}
|
|
165
|
+
function round(value) {
|
|
166
|
+
return Math.round(clamp(value) * 1e3) / 1e3;
|
|
167
|
+
}
|
|
168
|
+
function percent(value) {
|
|
169
|
+
return numberFormat(locale.value.code, { style: "percent", maximumFractionDigits: 0 }).format(
|
|
170
|
+
value
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function set(x, y) {
|
|
174
|
+
const next = { x: round(x), y: round(y) };
|
|
175
|
+
if (point.value && point.value.x === next.x && point.value.y === next.y) return;
|
|
176
|
+
model.value = next;
|
|
177
|
+
}
|
|
178
|
+
function fromPointer(event) {
|
|
179
|
+
const rect = areaRef.value?.getBoundingClientRect();
|
|
180
|
+
if (!rect || !rect.width || !rect.height) return;
|
|
181
|
+
set((event.clientX - rect.left) / rect.width, (event.clientY - rect.top) / rect.height);
|
|
182
|
+
}
|
|
183
|
+
function onPointerDown(event) {
|
|
184
|
+
if (!editable.value || event.button !== 0) return;
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
areaRef.value?.setPointerCapture(event.pointerId);
|
|
187
|
+
dragging.value = true;
|
|
188
|
+
fromPointer(event);
|
|
189
|
+
inputs[activeAxis.value]?.focus({ preventScroll: true });
|
|
190
|
+
}
|
|
191
|
+
function onPointerMove(event) {
|
|
192
|
+
if (dragging.value) fromPointer(event);
|
|
193
|
+
}
|
|
194
|
+
function endDrag() {
|
|
195
|
+
dragging.value = false;
|
|
196
|
+
}
|
|
197
|
+
function onKeydown(event, axis) {
|
|
198
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
199
|
+
const current = point.value ?? { x: 0.5, y: 0.5 };
|
|
200
|
+
const delta = KEY_DELTAS[event.key];
|
|
201
|
+
if (delta) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
if (!editable.value) return;
|
|
204
|
+
const step = props.step * (event.shiftKey ? 10 : 1);
|
|
205
|
+
set(current.x + delta[0] * step, current.y + delta[1] * step);
|
|
206
|
+
const target = delta[0] ? "x" : "y";
|
|
207
|
+
if (target !== axis) inputs[target]?.focus();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const jump = AXIS_KEYS[event.key];
|
|
211
|
+
if (jump) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
if (!editable.value) return;
|
|
214
|
+
const value = jump(current[axis], props.step * 10);
|
|
215
|
+
set(axis === "x" ? value : current.x, axis === "y" ? value : current.y);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if ((event.key === "Delete" || event.key === "Backspace") && props.clearable && editable.value) {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
model.value = null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function onInput(event, axis) {
|
|
224
|
+
const target = event.target;
|
|
225
|
+
if (!editable.value) {
|
|
226
|
+
target.value = String(Math.round((point.value?.[axis] ?? 0.5) * 100));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const value = Number(target.value) / 100;
|
|
230
|
+
const current = point.value ?? { x: 0.5, y: 0.5 };
|
|
231
|
+
set(axis === "x" ? value : current.x, axis === "y" ? value : current.y);
|
|
232
|
+
}
|
|
233
|
+
function clear() {
|
|
234
|
+
inputs[activeAxis.value]?.focus();
|
|
235
|
+
model.value = null;
|
|
236
|
+
}
|
|
237
|
+
watch(
|
|
238
|
+
() => props.src,
|
|
239
|
+
() => {
|
|
240
|
+
failed.value = false;
|
|
241
|
+
loaded.value = false;
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
onMounted(() => {
|
|
245
|
+
const element = imageRef.value;
|
|
246
|
+
if (!element?.complete) return;
|
|
247
|
+
if (element.naturalWidth === 0) failed.value = true;
|
|
248
|
+
else loaded.value = true;
|
|
249
|
+
});
|
|
250
|
+
defineExpose({ focus: () => inputs[activeAxis.value]?.focus() });
|
|
251
|
+
</script>
|