mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 02:48:21 +00:00
move atPath to util, set child component props
This commit is contained in:
parent
f736e53f14
commit
6019025df2
2 changed files with 11 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useKeyModifier } from '@vueuse/core';
|
import { useKeyModifier } from '@vueuse/core';
|
||||||
import type { Component } from 'vue';
|
import type { Component } from 'vue';
|
||||||
import { equals } from '~/util';
|
import { equals, atPath } from '~/util';
|
||||||
|
|
||||||
const shiftState = $(useKeyModifier('Shift'));
|
const shiftState = $(useKeyModifier('Shift'));
|
||||||
const ctrlState = $(useKeyModifier('Control'));
|
const ctrlState = $(useKeyModifier('Control'));
|
||||||
|
@ -19,6 +19,7 @@ const props = withDefaults(defineProps<{
|
||||||
heading: string,
|
heading: string,
|
||||||
path: string,
|
path: string,
|
||||||
component: Component,
|
component: Component,
|
||||||
|
props: any,
|
||||||
}[],
|
}[],
|
||||||
sortSelf?: boolean,
|
sortSelf?: boolean,
|
||||||
draggable?: boolean,
|
draggable?: boolean,
|
||||||
|
@ -94,12 +95,6 @@ function toggleRowSelection(index: number) {
|
||||||
emit('selectionChanged');
|
emit('selectionChanged');
|
||||||
}
|
}
|
||||||
|
|
||||||
function atPath(value: any, path: string): any {
|
|
||||||
for (const segment of path.split('.'))
|
|
||||||
value = (value ?? {} as any)[segment];
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
let draggedRow = $ref(-1);
|
let draggedRow = $ref(-1);
|
||||||
let draggedOverRow = $ref(-1);
|
let draggedOverRow = $ref(-1);
|
||||||
function dragDropRow() {
|
function dragDropRow() {
|
||||||
|
@ -149,9 +144,9 @@ function dragDropRow() {
|
||||||
@dragstart="() => draggedRow = index"
|
@dragstart="() => draggedRow = index"
|
||||||
@dragenter="() => draggedOverRow = index"
|
@dragenter="() => draggedOverRow = index"
|
||||||
@dragend="() => dragDropRow()">
|
@dragend="() => dragDropRow()">
|
||||||
<td v-for="{path, component} of columns" :key="path">
|
<td v-for="col of columns" :key="col.path">
|
||||||
<component :is="component" v-if="component" :data="atPath(row, path)"/>
|
<component :is="col.component" v-if="col.component" :data="atPath(row, col.path)" v-bind="col.props"/>
|
||||||
<template v-else>{{ atPath(row, path) }}</template>
|
<template v-else>{{ atPath(row, col.path) }}</template>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -23,3 +23,9 @@ export function variantOf(enumValue: any) {
|
||||||
|
|
||||||
export type Index = string | number | symbol;
|
export type Index = string | number | symbol;
|
||||||
export type MaybeIndex = Index | null;
|
export type MaybeIndex = Index | null;
|
||||||
|
|
||||||
|
export function atPath(value: any, path: string): any {
|
||||||
|
for (const segment of path.split('.'))
|
||||||
|
value = (value ?? {} as any)[segment];
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue