@fbkworks/adapter-element-plus 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, computed, withDirectives, createVNode, mergeProps } from "vue";
|
|
1
|
+
import { defineComponent, ref, onMounted, watch, computed, withDirectives, createVNode, mergeProps, nextTick } from "vue";
|
|
2
2
|
import { ElTable, ElTableColumn, vLoading } from "element-plus";
|
|
3
3
|
import { renderCell } from "@fbkworks/adapter-core";
|
|
4
4
|
import { getRowKey } from "@fbkworks/shared";
|
|
@@ -50,8 +50,33 @@ const DataGrid = /* @__PURE__ */ defineComponent({
|
|
|
50
50
|
slots
|
|
51
51
|
}) {
|
|
52
52
|
const rowKeyOf = (row, index) => getRowKey(row, index, props.rowKey);
|
|
53
|
+
const tableRef = ref(null);
|
|
54
|
+
let syncing = false;
|
|
55
|
+
const applySelection = () => {
|
|
56
|
+
const table = tableRef.value;
|
|
57
|
+
if (!table || !props.selectionEnabled) return;
|
|
58
|
+
syncing = true;
|
|
59
|
+
table.clearSelection?.();
|
|
60
|
+
props.data.forEach((row, index) => {
|
|
61
|
+
if (props.selectedKeys.includes(rowKeyOf(row, index))) table.toggleRowSelection(row, true);
|
|
62
|
+
});
|
|
63
|
+
void nextTick(() => {
|
|
64
|
+
syncing = false;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
onMounted(applySelection);
|
|
68
|
+
watch(() => props.selectedKeys, applySelection, {
|
|
69
|
+
deep: true
|
|
70
|
+
});
|
|
71
|
+
watch(() => props.data, applySelection);
|
|
72
|
+
watch(() => props.selectionEnabled, applySelection);
|
|
73
|
+
const onSelectionChange = (rows) => {
|
|
74
|
+
if (syncing) return;
|
|
75
|
+
emit("update:selectedKeys", rows.map((row) => rowKeyOf(row, props.data.indexOf(row))));
|
|
76
|
+
};
|
|
53
77
|
const elementSize = computed(() => props.size === "sm" ? "small" : props.size === "lg" ? "large" : "default");
|
|
54
78
|
return () => withDirectives(createVNode(ElTable, mergeProps(attrs, {
|
|
79
|
+
"ref": tableRef,
|
|
55
80
|
"data": props.data,
|
|
56
81
|
"rowKey": props.rowKey,
|
|
57
82
|
"size": elementSize.value,
|
|
@@ -60,7 +85,7 @@ const DataGrid = /* @__PURE__ */ defineComponent({
|
|
|
60
85
|
prop: props.sort.field,
|
|
61
86
|
order: props.sort.order === "asc" ? "ascending" : "descending"
|
|
62
87
|
} : void 0,
|
|
63
|
-
"onSelection-change":
|
|
88
|
+
"onSelection-change": onSelectionChange,
|
|
64
89
|
"onSort-change": ({
|
|
65
90
|
prop,
|
|
66
91
|
order
|
|
@@ -97,7 +122,10 @@ const DataGrid = /* @__PURE__ */ defineComponent({
|
|
|
97
122
|
index: $index,
|
|
98
123
|
value: renderCell(column, row, $index)
|
|
99
124
|
}) ?? renderCell(column, row, $index)
|
|
100
|
-
}))]
|
|
125
|
+
}))],
|
|
126
|
+
...slots.empty ? {
|
|
127
|
+
empty: () => slots.empty()
|
|
128
|
+
} : void 0
|
|
101
129
|
}), [[vLoading, props.loading]]);
|
|
102
130
|
}
|
|
103
131
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.mjs","sources":["../../src/primitives/DataGrid.tsx"],"sourcesContent":["import { computed, defineComponent, withDirectives, type PropType } from 'vue'\nimport { ElTable, ElTableColumn, vLoading } from 'element-plus'\nimport {\n renderCell,\n type DataGridColumn,\n type DataGridProps,\n type SortState,\n} from '@fbkworks/adapter-core'\nimport { getRowKey } from '@fbkworks/shared'\n\nexport const DataGrid = defineComponent({\n name: 'FbkElDataGrid',\n inheritAttrs: false,\n props: {\n columns: { type: Array as PropType<DataGridColumn<any>[]>, default: () => [] },\n data: { type: Array as PropType<any[]>, default: () => [] },\n rowKey: { type: [String, Function] as PropType<DataGridProps['rowKey']>, default: 'id' },\n loading: Boolean,\n presentation: { type: String as PropType<DataGridProps['presentation']>, default: 'auto' },\n selectionEnabled: Boolean,\n selectionWidth: { type: Number, default: 48 },\n selectedKeys: { type: Array as PropType<Array<string | number>>, default: () => [] },\n sort: { type: Object as PropType<SortState | null>, default: null },\n emptyText: String,\n rowClickable: Boolean,\n size: { type: String, default: 'md' },\n },\n emits: ['update:selectedKeys', 'update:sort', 'row-click'],\n setup(props, { attrs, emit, slots }) {\n const rowKeyOf = (row: any, index: number) => getRowKey(row, index, props.rowKey)\n\n const elementSize = computed(() =>\n props.size === 'sm' ? 'small' : props.size === 'lg' ? 'large' : 'default',\n )\n\n /* element-plus 没有独立 Spin,loading 只能靠 v-loading 指令挂遮罩;\n 这里用 withDirectives 直接绑指令对象,不要求业务侧全局注册 v-loading。 */\n return () => withDirectives(\n <ElTable\n {...attrs}\n data={props.data}\n rowKey={props.rowKey as any}\n size={elementSize.value}\n emptyText={props.emptyText ?? '暂无数据'}\n defaultSort={props.sort ? { prop: props.sort.field, order: props.sort.order === 'asc' ? 'ascending' : 'descending' } : undefined}\n onSelection-change={
|
|
1
|
+
{"version":3,"file":"DataGrid.mjs","sources":["../../src/primitives/DataGrid.tsx"],"sourcesContent":["import { computed, defineComponent, nextTick, onMounted, ref, watch, withDirectives, type PropType } from 'vue'\nimport { ElTable, ElTableColumn, vLoading } from 'element-plus'\nimport {\n renderCell,\n type DataGridColumn,\n type DataGridProps,\n type SortState,\n} from '@fbkworks/adapter-core'\nimport { getRowKey } from '@fbkworks/shared'\n\nexport const DataGrid = defineComponent({\n name: 'FbkElDataGrid',\n inheritAttrs: false,\n props: {\n columns: { type: Array as PropType<DataGridColumn<any>[]>, default: () => [] },\n data: { type: Array as PropType<any[]>, default: () => [] },\n rowKey: { type: [String, Function] as PropType<DataGridProps['rowKey']>, default: 'id' },\n loading: Boolean,\n presentation: { type: String as PropType<DataGridProps['presentation']>, default: 'auto' },\n selectionEnabled: Boolean,\n selectionWidth: { type: Number, default: 48 },\n selectedKeys: { type: Array as PropType<Array<string | number>>, default: () => [] },\n sort: { type: Object as PropType<SortState | null>, default: null },\n emptyText: String,\n rowClickable: Boolean,\n size: { type: String, default: 'md' },\n },\n emits: ['update:selectedKeys', 'update:sort', 'row-click'],\n setup(props, { attrs, emit, slots }) {\n const rowKeyOf = (row: any, index: number) => getRowKey(row, index, props.rowKey)\n\n /* ---------- 受控选择 ----------\n `selectedKeys` 是**受控** prop(ProTable 的 clearSelection、父级重置勾选都靠它),\n 而这个适配器以前只声明了它、从不读 —— 于是 naive/vant 能跟着外部状态走,\n element-plus 却只有「用户点了才动」:父级把 selectedKeys 置空后勾选框仍然勾着。\n 一致性套件过去只断言「点击会 emit」,所以这个洞一直没被发现。\n 下面把 props.selectedKeys 真的映射到 ElTable 的选择状态上。 */\n const tableRef = ref<any>(null)\n /* 由我们自己触发的 toggleRowSelection 会同步触发 selection-change。\n 不挡住的话会「外部置空 → 组件回写非空」,形成值抖动。 */\n let syncing = false\n\n const applySelection = () => {\n const table = tableRef.value\n if (!table || !props.selectionEnabled) return\n syncing = true\n table.clearSelection?.()\n props.data.forEach((row, index) => {\n if (props.selectedKeys.includes(rowKeyOf(row, index))) table.toggleRowSelection(row, true)\n })\n /* ElTable 在 toggleRowSelection 里同步派发 selection-change,\n 所以这里放行要等一个 tick,避免把同步流程里的那次 emit 漏挡。 */\n void nextTick(() => {\n syncing = false\n })\n }\n\n onMounted(applySelection)\n watch(() => props.selectedKeys, applySelection, { deep: true })\n watch(() => props.data, applySelection)\n watch(() => props.selectionEnabled, applySelection)\n\n const onSelectionChange = (rows: any[]) => {\n if (syncing) return\n emit(\n 'update:selectedKeys',\n rows.map((row) => rowKeyOf(row, props.data.indexOf(row))),\n )\n }\n\n const elementSize = computed(() =>\n props.size === 'sm' ? 'small' : props.size === 'lg' ? 'large' : 'default',\n )\n\n /* element-plus 没有独立 Spin,loading 只能靠 v-loading 指令挂遮罩;\n 这里用 withDirectives 直接绑指令对象,不要求业务侧全局注册 v-loading。 */\n return () => withDirectives(\n <ElTable\n {...attrs}\n ref={tableRef}\n v-slots={slots.empty ? { empty: () => slots.empty!() } : undefined}\n data={props.data}\n rowKey={props.rowKey as any}\n size={elementSize.value}\n emptyText={props.emptyText ?? '暂无数据'}\n defaultSort={props.sort ? { prop: props.sort.field, order: props.sort.order === 'asc' ? 'ascending' : 'descending' } : undefined}\n onSelection-change={onSelectionChange}\n onSort-change={({ prop, order }: { prop: string | null; order: string | null }) =>\n emit(\n 'update:sort',\n order && prop ? { field: prop, order: order === 'ascending' ? 'asc' : 'desc' } : null,\n )\n }\n onRow-click={(row: any, _column: any, event: Event) => {\n if (!props.rowClickable) return\n emit('row-click', row, props.data.indexOf(row), event)\n }}\n >\n {props.selectionEnabled ? (\n <ElTableColumn type=\"selection\" width={props.selectionWidth} reserveSelection />\n ) : null}\n {props.columns.map((column) => (\n <ElTableColumn\n key={column.key}\n /* prop 同时是 sort-change 回传的字段名:dataIndex 可选,\n 缺省时回退 key,否则点击排序只会发出 null。 */\n prop={(column.dataIndex ?? column.key) as string}\n label={column.title}\n width={column.width}\n minWidth={column.minWidth}\n fixed={column.fixed}\n align={column.align}\n sortable={column.sortable ? 'custom' : false}\n showOverflowTooltip={column.ellipsis}\n /* 数值列加 .fbk-numeric,由适配器样式给等宽数字。\n className 是 el-table-column 的官方 prop(落在 <td> 上),\n 比自己拼 class 稳。 */\n className={column.numeric ? 'fbk-numeric' : undefined}\n v-slots={{\n default: ({ row, $index }: { row: any; $index: number }) =>\n slots[`cell-${column.key}`]?.({ row, index: $index, value: renderCell(column, row, $index) }) ??\n renderCell(column, row, $index),\n }}\n />\n ))}\n </ElTable>,\n [[vLoading, props.loading]],\n )\n },\n})\n"],"names":["DataGrid","defineComponent","name","inheritAttrs","props","columns","type","Array","default","data","rowKey","String","Function","loading","Boolean","presentation","selectionEnabled","selectionWidth","Number","selectedKeys","sort","Object","emptyText","rowClickable","size","emits","setup","attrs","emit","slots","rowKeyOf","row","index","getRowKey","tableRef","ref","syncing","applySelection","table","value","clearSelection","forEach","includes","toggleRowSelection","nextTick","onMounted","watch","deep","onSelectionChange","rows","map","indexOf","elementSize","computed","withDirectives","_createVNode","ElTable","_mergeProps","prop","field","order","undefined","onSort-change","onRow-click","_column","event","ElTableColumn","column","key","dataIndex","title","width","minWidth","fixed","align","sortable","ellipsis","numeric","$index","renderCell","empty","vLoading"],"mappings":";;;;AAUO,MAAMA,WAAWC,gCAAgB;AAAA,EACtCC,MAAM;AAAA,EACNC,cAAc;AAAA,EACdC,OAAO;AAAA,IACLC,SAAS;AAAA,MAAEC,MAAMC;AAAAA,MAA0CC,SAASA,MAAM,CAAA;AAAA;IAC1EC,MAAM;AAAA,MAAEH,MAAMC;AAAAA,MAA0BC,SAASA,MAAM,CAAA;AAAA;IACvDE,QAAQ;AAAA,MAAEJ,MAAM,CAACK,QAAQC,QAAQ;AAAA,MAAwCJ,SAAS;AAAA;IAClFK,SAASC;AAAAA,IACTC,cAAc;AAAA,MAAET,MAAMK;AAAAA,MAAmDH,SAAS;AAAA;IAClFQ,kBAAkBF;AAAAA,IAClBG,gBAAgB;AAAA,MAAEX,MAAMY;AAAAA,MAAQV,SAAS;AAAA;IACzCW,cAAc;AAAA,MAAEb,MAAMC;AAAAA,MAA2CC,SAASA,MAAM,CAAA;AAAA;IAChFY,MAAM;AAAA,MAAEd,MAAMe;AAAAA,MAAsCb,SAAS;AAAA;IAC7Dc,WAAWX;AAAAA,IACXY,cAAcT;AAAAA,IACdU,MAAM;AAAA,MAAElB,MAAMK;AAAAA,MAAQH,SAAS;AAAA,IAAK;AAAA;EAEtCiB,OAAO,CAAC,uBAAuB,eAAe,WAAW;AAAA,EACzDC,MAAMtB,OAAO;AAAA,IAAEuB;AAAAA,IAAOC;AAAAA,IAAMC;AAAAA,EAAM,GAAG;AACnC,UAAMC,WAAWA,CAACC,KAAUC,UAAkBC,UAAUF,KAAKC,OAAO5B,MAAMM,MAAM;AAQhF,UAAMwB,WAAWC,IAAS,IAAI;AAG9B,QAAIC,UAAU;AAEd,UAAMC,iBAAiBA,MAAM;AAC3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AI,IAAInB;AAAAA,KAAS,GA8CpE,CAAC,CAACoB,UAAU7E,MAAMS,OAAO,CAAC,CAC5B;AAAA,EACF;AACF,CAAC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbkworks/adapter-element-plus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@fbkworks/adapter-core": "^0.
|
|
24
|
+
"@fbkworks/adapter-core": "^0.6.0",
|
|
25
25
|
"@fbkworks/shared": "^0.3.0",
|
|
26
26
|
"@fbkworks/tokens": "^0.3.0"
|
|
27
27
|
},
|