Tracking de l'application VApp (IHM du jeu)

This commit is contained in:
2025-05-11 18:04:12 +02:00
commit 89e9db9b62
17763 changed files with 3718499 additions and 0 deletions

View File

@ -0,0 +1,51 @@
// Composables
import { useProxiedModel } from "../../../composables/proxiedModel.mjs"; // Utilities
import { inject, provide, toRef } from 'vue';
import { propsFactory } from "../../../util/index.mjs"; // Types
export const makeDataTableExpandProps = propsFactory({
expandOnClick: Boolean,
showExpand: Boolean,
expanded: {
type: Array,
default: () => []
}
}, 'DataTable-expand');
export const VDataTableExpandedKey = Symbol.for('vuetify:datatable:expanded');
export function provideExpanded(props) {
const expandOnClick = toRef(props, 'expandOnClick');
const expanded = useProxiedModel(props, 'expanded', props.expanded, v => {
return new Set(v);
}, v => {
return [...v.values()];
});
function expand(item, value) {
const newExpanded = new Set(expanded.value);
if (!value) {
newExpanded.delete(item.value);
} else {
newExpanded.add(item.value);
}
expanded.value = newExpanded;
}
function isExpanded(item) {
return expanded.value.has(item.value);
}
function toggleExpand(item) {
expand(item, !isExpanded(item));
}
const data = {
expand,
expanded,
expandOnClick,
isExpanded,
toggleExpand
};
provide(VDataTableExpandedKey, data);
return data;
}
export function useExpanded() {
const data = inject(VDataTableExpandedKey);
if (!data) throw new Error('foo');
return data;
}
//# sourceMappingURL=expand.mjs.map

View File

@ -0,0 +1 @@
{"version":3,"file":"expand.mjs","names":["useProxiedModel","inject","provide","toRef","propsFactory","makeDataTableExpandProps","expandOnClick","Boolean","showExpand","expanded","type","Array","default","VDataTableExpandedKey","Symbol","for","provideExpanded","props","v","Set","values","expand","item","value","newExpanded","delete","add","isExpanded","has","toggleExpand","data","useExpanded","Error"],"sources":["../../../../src/components/VDataTable/composables/expand.ts"],"sourcesContent":["// Composables\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Utilities\nimport { inject, provide, toRef } from 'vue'\nimport { propsFactory } from '@/util'\n\n// Types\nimport type { InjectionKey, PropType, Ref } from 'vue'\nimport type { DataTableItem } from '../types'\n\nexport const makeDataTableExpandProps = propsFactory({\n expandOnClick: Boolean,\n showExpand: Boolean,\n expanded: {\n type: Array as PropType<readonly string[]>,\n default: () => ([]),\n },\n}, 'DataTable-expand')\n\nexport const VDataTableExpandedKey: InjectionKey<{\n expand: (item: DataTableItem, value: boolean) => void\n expanded: Ref<Set<string>>\n expandOnClick: Ref<boolean | undefined>\n isExpanded: (item: DataTableItem) => boolean\n toggleExpand: (item: DataTableItem) => void\n}> = Symbol.for('vuetify:datatable:expanded')\n\ntype ExpandProps = {\n expandOnClick: boolean\n expanded: readonly string[]\n 'onUpdate:expanded': ((value: any[]) => void) | undefined\n}\n\nexport function provideExpanded (props: ExpandProps) {\n const expandOnClick = toRef(props, 'expandOnClick')\n const expanded = useProxiedModel(props, 'expanded', props.expanded, v => {\n return new Set(v)\n }, v => {\n return [...v.values()]\n })\n\n function expand (item: DataTableItem, value: boolean) {\n const newExpanded = new Set(expanded.value)\n\n if (!value) {\n newExpanded.delete(item.value)\n } else {\n newExpanded.add(item.value)\n }\n\n expanded.value = newExpanded\n }\n\n function isExpanded (item: DataTableItem) {\n return expanded.value.has(item.value)\n }\n\n function toggleExpand (item: DataTableItem) {\n expand(item, !isExpanded(item))\n }\n\n const data = { expand, expanded, expandOnClick, isExpanded, toggleExpand }\n\n provide(VDataTableExpandedKey, data)\n\n return data\n}\n\nexport function useExpanded () {\n const data = inject(VDataTableExpandedKey)\n\n if (!data) throw new Error('foo')\n\n return data\n}\n"],"mappings":"AAAA;AAAA,SACSA,eAAe,iDAExB;AACA,SAASC,MAAM,EAAEC,OAAO,EAAEC,KAAK,QAAQ,KAAK;AAAA,SACnCC,YAAY,mCAErB;AAIA,OAAO,MAAMC,wBAAwB,GAAGD,YAAY,CAAC;EACnDE,aAAa,EAAEC,OAAO;EACtBC,UAAU,EAAED,OAAO;EACnBE,QAAQ,EAAE;IACRC,IAAI,EAAEC,KAAoC;IAC1CC,OAAO,EAAEA,CAAA,KAAO;EAClB;AACF,CAAC,EAAE,kBAAkB,CAAC;AAEtB,OAAO,MAAMC,qBAMX,GAAGC,MAAM,CAACC,GAAG,CAAC,4BAA4B,CAAC;AAQ7C,OAAO,SAASC,eAAeA,CAAEC,KAAkB,EAAE;EACnD,MAAMX,aAAa,GAAGH,KAAK,CAACc,KAAK,EAAE,eAAe,CAAC;EACnD,MAAMR,QAAQ,GAAGT,eAAe,CAACiB,KAAK,EAAE,UAAU,EAAEA,KAAK,CAACR,QAAQ,EAAES,CAAC,IAAI;IACvE,OAAO,IAAIC,GAAG,CAACD,CAAC,CAAC;EACnB,CAAC,EAAEA,CAAC,IAAI;IACN,OAAO,CAAC,GAAGA,CAAC,CAACE,MAAM,CAAC,CAAC,CAAC;EACxB,CAAC,CAAC;EAEF,SAASC,MAAMA,CAAEC,IAAmB,EAAEC,KAAc,EAAE;IACpD,MAAMC,WAAW,GAAG,IAAIL,GAAG,CAACV,QAAQ,CAACc,KAAK,CAAC;IAE3C,IAAI,CAACA,KAAK,EAAE;MACVC,WAAW,CAACC,MAAM,CAACH,IAAI,CAACC,KAAK,CAAC;IAChC,CAAC,MAAM;MACLC,WAAW,CAACE,GAAG,CAACJ,IAAI,CAACC,KAAK,CAAC;IAC7B;IAEAd,QAAQ,CAACc,KAAK,GAAGC,WAAW;EAC9B;EAEA,SAASG,UAAUA,CAAEL,IAAmB,EAAE;IACxC,OAAOb,QAAQ,CAACc,KAAK,CAACK,GAAG,CAACN,IAAI,CAACC,KAAK,CAAC;EACvC;EAEA,SAASM,YAAYA,CAAEP,IAAmB,EAAE;IAC1CD,MAAM,CAACC,IAAI,EAAE,CAACK,UAAU,CAACL,IAAI,CAAC,CAAC;EACjC;EAEA,MAAMQ,IAAI,GAAG;IAAET,MAAM;IAAEZ,QAAQ;IAAEH,aAAa;IAAEqB,UAAU;IAAEE;EAAa,CAAC;EAE1E3B,OAAO,CAACW,qBAAqB,EAAEiB,IAAI,CAAC;EAEpC,OAAOA,IAAI;AACb;AAEA,OAAO,SAASC,WAAWA,CAAA,EAAI;EAC7B,MAAMD,IAAI,GAAG7B,MAAM,CAACY,qBAAqB,CAAC;EAE1C,IAAI,CAACiB,IAAI,EAAE,MAAM,IAAIE,KAAK,CAAC,KAAK,CAAC;EAEjC,OAAOF,IAAI;AACb"}

View File

@ -0,0 +1,142 @@
// Composables
import { useProxiedModel } from "../../../composables/proxiedModel.mjs"; // Utilities
import { computed, inject, provide, ref } from 'vue';
import { getObjectValueByPath, propsFactory } from "../../../util/index.mjs"; // Types
export const makeDataTableGroupProps = propsFactory({
groupBy: {
type: Array,
default: () => []
}
}, 'DataTable-group');
const VDataTableGroupSymbol = Symbol.for('vuetify:data-table-group');
export function createGroupBy(props) {
const groupBy = useProxiedModel(props, 'groupBy');
return {
groupBy
};
}
export function provideGroupBy(options) {
const {
groupBy,
sortBy
} = options;
const opened = ref(new Set());
const sortByWithGroups = computed(() => {
return groupBy.value.map(val => ({
...val,
order: val.order ?? false
})).concat(sortBy.value);
});
function isGroupOpen(group) {
return opened.value.has(group.id);
}
function toggleGroup(group) {
const newOpened = new Set(opened.value);
if (!isGroupOpen(group)) newOpened.add(group.id);else newOpened.delete(group.id);
opened.value = newOpened;
}
function extractRows(items) {
function dive(group) {
const arr = [];
for (const item of group.items) {
if ('type' in item && item.type === 'group') {
arr.push(...dive(item));
} else {
arr.push(item);
}
}
return arr;
}
return dive({
type: 'group',
items,
id: 'dummy',
key: 'dummy',
value: 'dummy',
depth: 0
});
}
// onBeforeMount(() => {
// for (const key of groupedItems.value.keys()) {
// opened.value.add(key)
// }
// })
const data = {
sortByWithGroups,
toggleGroup,
opened,
groupBy,
extractRows,
isGroupOpen
};
provide(VDataTableGroupSymbol, data);
return data;
}
export function useGroupBy() {
const data = inject(VDataTableGroupSymbol);
if (!data) throw new Error('Missing group!');
return data;
}
function groupItemsByProperty(items, groupBy) {
if (!items.length) return [];
const groups = new Map();
for (const item of items) {
const value = getObjectValueByPath(item.raw, groupBy);
if (!groups.has(value)) {
groups.set(value, []);
}
groups.get(value).push(item);
}
return groups;
}
function groupItems(items, groupBy) {
let depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
let prefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'root';
if (!groupBy.length) return [];
const groupedItems = groupItemsByProperty(items, groupBy[0]);
const groups = [];
const rest = groupBy.slice(1);
groupedItems.forEach((items, value) => {
const key = groupBy[0];
const id = `${prefix}_${key}_${value}`;
groups.push({
depth,
id,
key,
value,
items: rest.length ? groupItems(items, rest, depth + 1, id) : items,
type: 'group'
});
});
return groups;
}
function flattenItems(items, opened) {
const flatItems = [];
for (const item of items) {
// TODO: make this better
if ('type' in item && item.type === 'group') {
if (item.value != null) {
flatItems.push(item);
}
if (opened.has(item.id) || item.value == null) {
flatItems.push(...flattenItems(item.items, opened));
}
} else {
flatItems.push(item);
}
}
return flatItems;
}
export function useGroupedItems(items, groupBy, opened) {
const flatItems = computed(() => {
if (!groupBy.value.length) return items.value;
const groupedItems = groupItems(items.value, groupBy.value.map(item => item.key));
return flattenItems(groupedItems, opened.value);
});
return {
flatItems
};
}
//# sourceMappingURL=group.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,265 @@
// Utilities
import { capitalize, inject, provide, ref, watchEffect } from 'vue';
import { consoleError, propsFactory } from "../../../util/index.mjs"; // Types
export const makeDataTableHeaderProps = propsFactory({
headers: Array
}, 'DataTable-header');
export const VDataTableHeadersSymbol = Symbol.for('vuetify:data-table-headers');
const defaultHeader = {
title: '',
sortable: false
};
const defaultActionHeader = {
...defaultHeader,
width: 48
};
function priorityQueue() {
let arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
const queue = arr.map(element => ({
element,
priority: 0
}));
return {
enqueue: (element, priority) => {
let added = false;
for (let i = 0; i < queue.length; i++) {
const item = queue[i];
if (item.priority > priority) {
queue.splice(i, 0, {
element,
priority
});
added = true;
break;
}
}
if (!added) queue.push({
element,
priority
});
},
size: () => queue.length,
count: () => {
let count = 0;
if (!queue.length) return 0;
const whole = Math.floor(queue[0].priority);
for (let i = 0; i < queue.length; i++) {
if (Math.floor(queue[i].priority) === whole) count += 1;
}
return count;
},
dequeue: () => {
return queue.shift();
}
};
}
function extractLeaves(item) {
let columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (!item.children) {
columns.push(item);
} else {
for (const child of item.children) {
extractLeaves(child, columns);
}
}
return columns;
}
function extractKeys(headers) {
let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
for (const item of headers) {
if (item.key) keys.add(item.key);
if (item.children) {
extractKeys(item.children, keys);
}
}
return keys;
}
function getDefaultItem(item) {
if (!item.key) return undefined;
if (item.key === 'data-table-group') return defaultHeader;
if (['data-table-expand', 'data-table-select'].includes(item.key)) return defaultActionHeader;
return undefined;
}
function getDepth(item) {
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (!item.children) return depth;
return Math.max(depth, ...item.children.map(child => getDepth(child, depth + 1)));
}
function parseFixedColumns(items) {
let seenFixed = false;
function setFixed(item) {
let parentFixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (!item) return;
if (parentFixed) {
item.fixed = true;
}
if (item.fixed) {
if (item.children) {
for (let i = item.children.length - 1; i >= 0; i--) {
setFixed(item.children[i], true);
}
} else {
if (!seenFixed) {
item.lastFixed = true;
} else if (isNaN(+item.width)) {
consoleError(`Multiple fixed columns should have a static width (key: ${item.key})`);
}
seenFixed = true;
}
} else {
if (item.children) {
for (let i = item.children.length - 1; i >= 0; i--) {
setFixed(item.children[i]);
}
} else {
seenFixed = false;
}
}
}
for (let i = items.length - 1; i >= 0; i--) {
setFixed(items[i]);
}
function setFixedOffset(item) {
let fixedOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (!item) return fixedOffset;
if (item.children) {
item.fixedOffset = fixedOffset;
for (const child of item.children) {
fixedOffset = setFixedOffset(child, fixedOffset);
}
} else if (item.fixed) {
item.fixedOffset = fixedOffset;
fixedOffset += parseFloat(item.width || '0') || 0;
}
return fixedOffset;
}
let fixedOffset = 0;
for (const item of items) {
fixedOffset = setFixedOffset(item, fixedOffset);
}
}
function parse(items, maxDepth) {
const headers = [];
let currentDepth = 0;
const queue = priorityQueue(items);
while (queue.size() > 0) {
let rowSize = queue.count();
const row = [];
let fraction = 1;
while (rowSize > 0) {
const {
element: item,
priority
} = queue.dequeue();
const diff = maxDepth - currentDepth - getDepth(item);
row.push({
...item,
rowspan: diff ?? 1,
colspan: item.children ? extractLeaves(item).length : 1
});
if (item.children) {
for (const child of item.children) {
// This internally sorts items that are on the same priority "row"
const sort = priority % 1 + fraction / Math.pow(10, currentDepth + 2);
queue.enqueue(child, currentDepth + diff + sort);
}
}
fraction += 1;
rowSize -= 1;
}
currentDepth += 1;
headers.push(row);
}
const columns = items.map(item => extractLeaves(item)).flat();
return {
columns,
headers
};
}
function convertToInternalHeaders(items) {
const internalHeaders = [];
for (const item of items) {
const defaultItem = {
...getDefaultItem(item),
...item
};
const key = defaultItem.key ?? (typeof defaultItem.value === 'string' ? defaultItem.value : null);
const value = defaultItem.value ?? key ?? null;
const internalItem = {
...defaultItem,
key,
value,
sortable: defaultItem.sortable ?? (defaultItem.key != null || !!defaultItem.sort),
children: defaultItem.children ? convertToInternalHeaders(defaultItem.children) : undefined
};
internalHeaders.push(internalItem);
}
return internalHeaders;
}
export function createHeaders(props, options) {
const headers = ref([]);
const columns = ref([]);
const sortFunctions = ref({});
const sortRawFunctions = ref({});
const filterFunctions = ref({});
watchEffect(() => {
const _headers = props.headers || Object.keys(props.items[0] ?? {}).map(key => ({
key,
title: capitalize(key)
}));
const items = _headers.slice();
const keys = extractKeys(items);
if (options?.groupBy?.value.length && !keys.has('data-table-group')) {
items.unshift({
key: 'data-table-group',
title: 'Group'
});
}
if (options?.showSelect?.value && !keys.has('data-table-select')) {
items.unshift({
key: 'data-table-select'
});
}
if (options?.showExpand?.value && !keys.has('data-table-expand')) {
items.push({
key: 'data-table-expand'
});
}
const internalHeaders = convertToInternalHeaders(items);
parseFixedColumns(internalHeaders);
const maxDepth = Math.max(...internalHeaders.map(item => getDepth(item))) + 1;
const parsed = parse(internalHeaders, maxDepth);
headers.value = parsed.headers;
columns.value = parsed.columns;
const flatHeaders = parsed.headers.flat(1);
for (const header of flatHeaders) {
if (!header.key) continue;
if (header.sortable) {
if (header.sort) {
sortFunctions.value[header.key] = header.sort;
}
if (header.sortRaw) {
sortRawFunctions.value[header.key] = header.sortRaw;
}
}
if (header.filter) {
filterFunctions.value[header.key] = header.filter;
}
}
});
const data = {
headers,
columns,
sortFunctions,
sortRawFunctions,
filterFunctions
};
provide(VDataTableHeadersSymbol, data);
return data;
}
export function useHeaders() {
const data = inject(VDataTableHeadersSymbol);
if (!data) throw new Error('Missing headers!');
return data;
}
//# sourceMappingURL=headers.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,48 @@
// Utilities
import { computed } from 'vue';
import { getPropertyFromItem, propsFactory } from "../../../util/index.mjs"; // Types
// Composables
export const makeDataTableItemsProps = propsFactory({
items: {
type: Array,
default: () => []
},
itemValue: {
type: [String, Array, Function],
default: 'id'
},
itemSelectable: {
type: [String, Array, Function],
default: null
},
rowProps: [Object, Function],
cellProps: [Object, Function],
returnObject: Boolean
}, 'DataTable-items');
export function transformItem(props, item, index, columns) {
const value = props.returnObject ? item : getPropertyFromItem(item, props.itemValue);
const selectable = getPropertyFromItem(item, props.itemSelectable, true);
const itemColumns = columns.reduce((obj, column) => {
if (column.key != null) obj[column.key] = getPropertyFromItem(item, column.value);
return obj;
}, {});
return {
type: 'item',
key: props.returnObject ? getPropertyFromItem(item, props.itemValue) : value,
index,
value,
selectable,
columns: itemColumns,
raw: item
};
}
export function transformItems(props, items, columns) {
return items.map((item, index) => transformItem(props, item, index, columns));
}
export function useDataTableItems(props, columns) {
const items = computed(() => transformItems(props, props.items, columns.value));
return {
items
};
}
//# sourceMappingURL=items.mjs.map

View File

@ -0,0 +1 @@
{"version":3,"file":"items.mjs","names":["computed","getPropertyFromItem","propsFactory","makeDataTableItemsProps","items","type","Array","default","itemValue","String","Function","itemSelectable","rowProps","Object","cellProps","returnObject","Boolean","transformItem","props","item","index","columns","value","selectable","itemColumns","reduce","obj","column","key","raw","transformItems","map","useDataTableItems"],"sources":["../../../../src/components/VDataTable/composables/items.ts"],"sourcesContent":["// Utilities\nimport { computed } from 'vue'\nimport { getPropertyFromItem, propsFactory } from '@/util'\n\n// Types\nimport type { PropType, Ref } from 'vue'\nimport type { CellProps, DataTableItem, InternalDataTableHeader, RowProps } from '../types'\nimport type { SelectItemKey } from '@/util'\n\nexport interface DataTableItemProps {\n items: any[]\n itemValue: SelectItemKey\n itemSelectable: SelectItemKey\n returnObject: boolean\n}\n\n// Composables\nexport const makeDataTableItemsProps = propsFactory({\n items: {\n type: Array as PropType<DataTableItemProps['items']>,\n default: () => ([]),\n },\n itemValue: {\n type: [String, Array, Function] as PropType<SelectItemKey>,\n default: 'id',\n },\n itemSelectable: {\n type: [String, Array, Function] as PropType<SelectItemKey>,\n default: null,\n },\n rowProps: [Object, Function] as PropType<RowProps<any>>,\n cellProps: [Object, Function] as PropType<CellProps<any>>,\n returnObject: Boolean,\n}, 'DataTable-items')\n\nexport function transformItem (\n props: Omit<DataTableItemProps, 'items'>,\n item: any,\n index: number,\n columns: InternalDataTableHeader[]\n): DataTableItem {\n const value = props.returnObject ? item : getPropertyFromItem(item, props.itemValue)\n const selectable = getPropertyFromItem(item, props.itemSelectable, true)\n const itemColumns = columns.reduce((obj, column) => {\n if (column.key != null) obj[column.key] = getPropertyFromItem(item, column.value!)\n return obj\n }, {} as Record<string, unknown>)\n\n return {\n type: 'item',\n key: props.returnObject ? getPropertyFromItem(item, props.itemValue) : value,\n index,\n value,\n selectable,\n columns: itemColumns,\n raw: item,\n }\n}\n\nexport function transformItems (\n props: Omit<DataTableItemProps, 'items'>,\n items: DataTableItemProps['items'],\n columns: InternalDataTableHeader[]\n): DataTableItem[] {\n return items.map((item, index) => transformItem(props, item, index, columns))\n}\n\nexport function useDataTableItems (props: DataTableItemProps, columns: Ref<InternalDataTableHeader[]>) {\n const items = computed(() => transformItems(props, props.items, columns.value))\n\n return { items }\n}\n"],"mappings":"AAAA;AACA,SAASA,QAAQ,QAAQ,KAAK;AAAA,SACrBC,mBAAmB,EAAEC,YAAY,mCAE1C;AAYA;AACA,OAAO,MAAMC,uBAAuB,GAAGD,YAAY,CAAC;EAClDE,KAAK,EAAE;IACLC,IAAI,EAAEC,KAA8C;IACpDC,OAAO,EAAEA,CAAA,KAAO;EAClB,CAAC;EACDC,SAAS,EAAE;IACTH,IAAI,EAAE,CAACI,MAAM,EAAEH,KAAK,EAAEI,QAAQ,CAA4B;IAC1DH,OAAO,EAAE;EACX,CAAC;EACDI,cAAc,EAAE;IACdN,IAAI,EAAE,CAACI,MAAM,EAAEH,KAAK,EAAEI,QAAQ,CAA4B;IAC1DH,OAAO,EAAE;EACX,CAAC;EACDK,QAAQ,EAAE,CAACC,MAAM,EAAEH,QAAQ,CAA4B;EACvDI,SAAS,EAAE,CAACD,MAAM,EAAEH,QAAQ,CAA6B;EACzDK,YAAY,EAAEC;AAChB,CAAC,EAAE,iBAAiB,CAAC;AAErB,OAAO,SAASC,aAAaA,CAC3BC,KAAwC,EACxCC,IAAS,EACTC,KAAa,EACbC,OAAkC,EACnB;EACf,MAAMC,KAAK,GAAGJ,KAAK,CAACH,YAAY,GAAGI,IAAI,GAAGlB,mBAAmB,CAACkB,IAAI,EAAED,KAAK,CAACV,SAAS,CAAC;EACpF,MAAMe,UAAU,GAAGtB,mBAAmB,CAACkB,IAAI,EAAED,KAAK,CAACP,cAAc,EAAE,IAAI,CAAC;EACxE,MAAMa,WAAW,GAAGH,OAAO,CAACI,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,KAAK;IAClD,IAAIA,MAAM,CAACC,GAAG,IAAI,IAAI,EAAEF,GAAG,CAACC,MAAM,CAACC,GAAG,CAAC,GAAG3B,mBAAmB,CAACkB,IAAI,EAAEQ,MAAM,CAACL,KAAM,CAAC;IAClF,OAAOI,GAAG;EACZ,CAAC,EAAE,CAAC,CAA4B,CAAC;EAEjC,OAAO;IACLrB,IAAI,EAAE,MAAM;IACZuB,GAAG,EAAEV,KAAK,CAACH,YAAY,GAAGd,mBAAmB,CAACkB,IAAI,EAAED,KAAK,CAACV,SAAS,CAAC,GAAGc,KAAK;IAC5EF,KAAK;IACLE,KAAK;IACLC,UAAU;IACVF,OAAO,EAAEG,WAAW;IACpBK,GAAG,EAAEV;EACP,CAAC;AACH;AAEA,OAAO,SAASW,cAAcA,CAC5BZ,KAAwC,EACxCd,KAAkC,EAClCiB,OAAkC,EACjB;EACjB,OAAOjB,KAAK,CAAC2B,GAAG,CAAC,CAACZ,IAAI,EAAEC,KAAK,KAAKH,aAAa,CAACC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,OAAO,CAAC,CAAC;AAC/E;AAEA,OAAO,SAASW,iBAAiBA,CAAEd,KAAyB,EAAEG,OAAuC,EAAE;EACrG,MAAMjB,KAAK,GAAGJ,QAAQ,CAAC,MAAM8B,cAAc,CAACZ,KAAK,EAAEA,KAAK,CAACd,KAAK,EAAEiB,OAAO,CAACC,KAAK,CAAC,CAAC;EAE/E,OAAO;IAAElB;EAAM,CAAC;AAClB"}

View File

@ -0,0 +1,35 @@
// Utilities
import { computed, watch } from 'vue';
import { deepEqual, getCurrentInstance } from "../../../util/index.mjs"; // Types
export function useOptions(_ref) {
let {
page,
itemsPerPage,
sortBy,
groupBy,
search
} = _ref;
const vm = getCurrentInstance('VDataTable');
const options = computed(() => ({
page: page.value,
itemsPerPage: itemsPerPage.value,
sortBy: sortBy.value,
groupBy: groupBy.value,
search: search.value
}));
let oldOptions = null;
watch(options, () => {
if (deepEqual(oldOptions, options.value)) return;
// Reset page when searching
if (oldOptions?.search !== options.value.search) {
page.value = 1;
}
vm.emit('update:options', options.value);
oldOptions = options.value;
}, {
deep: true,
immediate: true
});
}
//# sourceMappingURL=options.mjs.map

View File

@ -0,0 +1 @@
{"version":3,"file":"options.mjs","names":["computed","watch","deepEqual","getCurrentInstance","useOptions","_ref","page","itemsPerPage","sortBy","groupBy","search","vm","options","value","oldOptions","emit","deep","immediate"],"sources":["../../../../src/components/VDataTable/composables/options.ts"],"sourcesContent":["// Utilities\nimport { computed, watch } from 'vue'\nimport { deepEqual, getCurrentInstance } from '@/util'\n\n// Types\nimport type { Ref } from 'vue'\nimport type { SortItem } from './sort'\n\nexport function useOptions ({\n page,\n itemsPerPage,\n sortBy,\n groupBy,\n search,\n}: {\n page: Ref<number>\n itemsPerPage: Ref<number>\n sortBy: Ref<readonly SortItem[]>\n groupBy: Ref<readonly SortItem[]>\n search: Ref<string | undefined>\n}) {\n const vm = getCurrentInstance('VDataTable')\n\n const options = computed(() => ({\n page: page.value,\n itemsPerPage: itemsPerPage.value,\n sortBy: sortBy.value,\n groupBy: groupBy.value,\n search: search.value,\n }))\n\n let oldOptions: typeof options.value | null = null\n watch(options, () => {\n if (deepEqual(oldOptions, options.value)) return\n\n // Reset page when searching\n if (oldOptions?.search !== options.value.search) {\n page.value = 1\n }\n\n vm.emit('update:options', options.value)\n oldOptions = options.value\n }, { deep: true, immediate: true })\n}\n"],"mappings":"AAAA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,KAAK;AAAA,SAC5BC,SAAS,EAAEC,kBAAkB,mCAEtC;AAIA,OAAO,SAASC,UAAUA,CAAAC,IAAA,EAYvB;EAAA,IAZyB;IAC1BC,IAAI;IACJC,YAAY;IACZC,MAAM;IACNC,OAAO;IACPC;EAOF,CAAC,GAAAL,IAAA;EACC,MAAMM,EAAE,GAAGR,kBAAkB,CAAC,YAAY,CAAC;EAE3C,MAAMS,OAAO,GAAGZ,QAAQ,CAAC,OAAO;IAC9BM,IAAI,EAAEA,IAAI,CAACO,KAAK;IAChBN,YAAY,EAAEA,YAAY,CAACM,KAAK;IAChCL,MAAM,EAAEA,MAAM,CAACK,KAAK;IACpBJ,OAAO,EAAEA,OAAO,CAACI,KAAK;IACtBH,MAAM,EAAEA,MAAM,CAACG;EACjB,CAAC,CAAC,CAAC;EAEH,IAAIC,UAAuC,GAAG,IAAI;EAClDb,KAAK,CAACW,OAAO,EAAE,MAAM;IACnB,IAAIV,SAAS,CAACY,UAAU,EAAEF,OAAO,CAACC,KAAK,CAAC,EAAE;;IAE1C;IACA,IAAIC,UAAU,EAAEJ,MAAM,KAAKE,OAAO,CAACC,KAAK,CAACH,MAAM,EAAE;MAC/CJ,IAAI,CAACO,KAAK,GAAG,CAAC;IAChB;IAEAF,EAAE,CAACI,IAAI,CAAC,gBAAgB,EAAEH,OAAO,CAACC,KAAK,CAAC;IACxCC,UAAU,GAAGF,OAAO,CAACC,KAAK;EAC5B,CAAC,EAAE;IAAEG,IAAI,EAAE,IAAI;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC;AACrC"}

View File

@ -0,0 +1,99 @@
// Composables
import { useProxiedModel } from "../../../composables/proxiedModel.mjs"; // Utilities
import { computed, inject, provide, watch, watchEffect } from 'vue';
import { clamp, getCurrentInstance, propsFactory } from "../../../util/index.mjs"; // Types
export const makeDataTablePaginateProps = propsFactory({
page: {
type: [Number, String],
default: 1
},
itemsPerPage: {
type: [Number, String],
default: 10
}
}, 'DataTable-paginate');
const VDataTablePaginationSymbol = Symbol.for('vuetify:data-table-pagination');
export function createPagination(props) {
const page = useProxiedModel(props, 'page', undefined, value => +(value ?? 1));
const itemsPerPage = useProxiedModel(props, 'itemsPerPage', undefined, value => +(value ?? 10));
return {
page,
itemsPerPage
};
}
export function providePagination(options) {
const {
page,
itemsPerPage,
itemsLength
} = options;
const startIndex = computed(() => {
if (itemsPerPage.value === -1) return 0;
return itemsPerPage.value * (page.value - 1);
});
const stopIndex = computed(() => {
if (itemsPerPage.value === -1) return itemsLength.value;
return Math.min(itemsLength.value, startIndex.value + itemsPerPage.value);
});
const pageCount = computed(() => {
if (itemsPerPage.value === -1 || itemsLength.value === 0) return 1;
return Math.ceil(itemsLength.value / itemsPerPage.value);
});
watchEffect(() => {
if (page.value > pageCount.value) {
page.value = pageCount.value;
}
});
function setItemsPerPage(value) {
itemsPerPage.value = value;
page.value = 1;
}
function nextPage() {
page.value = clamp(page.value + 1, 1, pageCount.value);
}
function prevPage() {
page.value = clamp(page.value - 1, 1, pageCount.value);
}
function setPage(value) {
page.value = clamp(value, 1, pageCount.value);
}
const data = {
page,
itemsPerPage,
startIndex,
stopIndex,
pageCount,
itemsLength,
nextPage,
prevPage,
setPage,
setItemsPerPage
};
provide(VDataTablePaginationSymbol, data);
return data;
}
export function usePagination() {
const data = inject(VDataTablePaginationSymbol);
if (!data) throw new Error('Missing pagination!');
return data;
}
export function usePaginatedItems(options) {
const vm = getCurrentInstance('usePaginatedItems');
const {
items,
startIndex,
stopIndex,
itemsPerPage
} = options;
const paginatedItems = computed(() => {
if (itemsPerPage.value <= 0) return items.value;
return items.value.slice(startIndex.value, stopIndex.value);
});
watch(paginatedItems, val => {
vm.emit('update:currentItems', val);
});
return {
paginatedItems
};
}
//# sourceMappingURL=paginate.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,180 @@
// Composables
import { useProxiedModel } from "../../../composables/proxiedModel.mjs"; // Utilities
import { computed, inject, provide } from 'vue';
import { deepEqual, propsFactory, wrapInArray } from "../../../util/index.mjs"; // Types
const singleSelectStrategy = {
showSelectAll: false,
allSelected: () => [],
select: _ref => {
let {
items,
value
} = _ref;
return new Set(value ? [items[0]?.value] : []);
},
selectAll: _ref2 => {
let {
selected
} = _ref2;
return selected;
}
};
const pageSelectStrategy = {
showSelectAll: true,
allSelected: _ref3 => {
let {
currentPage
} = _ref3;
return currentPage;
},
select: _ref4 => {
let {
items,
value,
selected
} = _ref4;
for (const item of items) {
if (value) selected.add(item.value);else selected.delete(item.value);
}
return selected;
},
selectAll: _ref5 => {
let {
value,
currentPage,
selected
} = _ref5;
return pageSelectStrategy.select({
items: currentPage,
value,
selected
});
}
};
const allSelectStrategy = {
showSelectAll: true,
allSelected: _ref6 => {
let {
allItems
} = _ref6;
return allItems;
},
select: _ref7 => {
let {
items,
value,
selected
} = _ref7;
for (const item of items) {
if (value) selected.add(item.value);else selected.delete(item.value);
}
return selected;
},
selectAll: _ref8 => {
let {
value,
allItems,
selected
} = _ref8;
return allSelectStrategy.select({
items: allItems,
value,
selected
});
}
};
export const makeDataTableSelectProps = propsFactory({
showSelect: Boolean,
selectStrategy: {
type: [String, Object],
default: 'page'
},
modelValue: {
type: Array,
default: () => []
},
valueComparator: {
type: Function,
default: deepEqual
}
}, 'DataTable-select');
export const VDataTableSelectionSymbol = Symbol.for('vuetify:data-table-selection');
export function provideSelection(props, _ref9) {
let {
allItems,
currentPage
} = _ref9;
const selected = useProxiedModel(props, 'modelValue', props.modelValue, v => {
return new Set(wrapInArray(v).map(v => {
return allItems.value.find(item => props.valueComparator(v, item.value))?.value ?? v;
}));
}, v => {
return [...v.values()];
});
const allSelectable = computed(() => allItems.value.filter(item => item.selectable));
const currentPageSelectable = computed(() => currentPage.value.filter(item => item.selectable));
const selectStrategy = computed(() => {
if (typeof props.selectStrategy === 'object') return props.selectStrategy;
switch (props.selectStrategy) {
case 'single':
return singleSelectStrategy;
case 'all':
return allSelectStrategy;
case 'page':
default:
return pageSelectStrategy;
}
});
function isSelected(items) {
return wrapInArray(items).every(item => selected.value.has(item.value));
}
function isSomeSelected(items) {
return wrapInArray(items).some(item => selected.value.has(item.value));
}
function select(items, value) {
const newSelected = selectStrategy.value.select({
items,
value,
selected: new Set(selected.value)
});
selected.value = newSelected;
}
function toggleSelect(item) {
select([item], !isSelected([item]));
}
function selectAll(value) {
const newSelected = selectStrategy.value.selectAll({
value,
allItems: allSelectable.value,
currentPage: currentPageSelectable.value,
selected: new Set(selected.value)
});
selected.value = newSelected;
}
const someSelected = computed(() => selected.value.size > 0);
const allSelected = computed(() => {
const items = selectStrategy.value.allSelected({
allItems: allSelectable.value,
currentPage: currentPageSelectable.value
});
return !!items.length && isSelected(items);
});
const data = {
toggleSelect,
select,
selectAll,
isSelected,
isSomeSelected,
someSelected,
allSelected,
showSelectAll: selectStrategy.value.showSelectAll
};
provide(VDataTableSelectionSymbol, data);
return data;
}
export function useSelection() {
const data = inject(VDataTableSelectionSymbol);
if (!data) throw new Error('Missing selection!');
return data;
}
//# sourceMappingURL=select.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,135 @@
// Composables
import { useLocale } from "../../../composables/index.mjs";
import { useProxiedModel } from "../../../composables/proxiedModel.mjs"; // Utilities
import { computed, inject, provide, toRef } from 'vue';
import { getObjectValueByPath, isEmpty, propsFactory } from "../../../util/index.mjs"; // Types
export const makeDataTableSortProps = propsFactory({
sortBy: {
type: Array,
default: () => []
},
customKeySort: Object,
multiSort: Boolean,
mustSort: Boolean
}, 'DataTable-sort');
const VDataTableSortSymbol = Symbol.for('vuetify:data-table-sort');
export function createSort(props) {
const sortBy = useProxiedModel(props, 'sortBy');
const mustSort = toRef(props, 'mustSort');
const multiSort = toRef(props, 'multiSort');
return {
sortBy,
mustSort,
multiSort
};
}
export function provideSort(options) {
const {
sortBy,
mustSort,
multiSort,
page
} = options;
const toggleSort = column => {
if (column.key == null) return;
let newSortBy = sortBy.value.map(x => ({
...x
})) ?? [];
const item = newSortBy.find(x => x.key === column.key);
if (!item) {
if (multiSort.value) newSortBy = [...newSortBy, {
key: column.key,
order: 'asc'
}];else newSortBy = [{
key: column.key,
order: 'asc'
}];
} else if (item.order === 'desc') {
if (mustSort.value) {
item.order = 'asc';
} else {
newSortBy = newSortBy.filter(x => x.key !== column.key);
}
} else {
item.order = 'desc';
}
sortBy.value = newSortBy;
if (page) page.value = 1;
};
function isSorted(column) {
return !!sortBy.value.find(item => item.key === column.key);
}
const data = {
sortBy,
toggleSort,
isSorted
};
provide(VDataTableSortSymbol, data);
return data;
}
export function useSort() {
const data = inject(VDataTableSortSymbol);
if (!data) throw new Error('Missing sort!');
return data;
}
// TODO: abstract into project composable
export function useSortedItems(props, items, sortBy, sortFunctions, sortRawFunctions) {
const locale = useLocale();
const sortedItems = computed(() => {
if (!sortBy.value.length) return items.value;
return sortItems(items.value, sortBy.value, locale.current.value, {
...props.customKeySort,
...sortFunctions?.value
}, sortRawFunctions?.value);
});
return {
sortedItems
};
}
export function sortItems(items, sortByItems, locale, customSorters, customRawSorters) {
const stringCollator = new Intl.Collator(locale, {
sensitivity: 'accent',
usage: 'sort'
});
return [...items].sort((a, b) => {
for (let i = 0; i < sortByItems.length; i++) {
const sortKey = sortByItems[i].key;
const sortOrder = sortByItems[i].order ?? 'asc';
if (sortOrder === false) continue;
let sortA = getObjectValueByPath(a.raw, sortKey);
let sortB = getObjectValueByPath(b.raw, sortKey);
let sortARaw = a.raw;
let sortBRaw = b.raw;
if (sortOrder === 'desc') {
[sortA, sortB] = [sortB, sortA];
[sortARaw, sortBRaw] = [sortBRaw, sortARaw];
}
if (customRawSorters?.[sortKey]) {
const customResult = customRawSorters[sortKey](sortARaw, sortBRaw);
if (!customResult) continue;
return customResult;
}
if (customSorters?.[sortKey]) {
const customResult = customSorters[sortKey](sortA, sortB);
if (!customResult) continue;
return customResult;
}
// Dates should be compared numerically
if (sortA instanceof Date && sortB instanceof Date) {
return sortA.getTime() - sortB.getTime();
}
[sortA, sortB] = [sortA, sortB].map(s => s != null ? s.toString().toLocaleLowerCase() : s);
if (sortA !== sortB) {
if (isEmpty(sortA) && isEmpty(sortB)) return 0;
if (isEmpty(sortA)) return -1;
if (isEmpty(sortB)) return 1;
if (!isNaN(sortA) && !isNaN(sortB)) return Number(sortA) - Number(sortB);
return stringCollator.compare(sortA, sortB);
}
}
return 0;
});
}
//# sourceMappingURL=sort.mjs.map

File diff suppressed because one or more lines are too long