You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.2 KiB

1 month ago
  1. {"ast":null,"code":"import { getCurrentInstance, ref, unref } from 'vue';\nimport { isNull } from 'lodash-unified';\nimport { getRowIdentity } from '../util.mjs';\nfunction useCurrent(watcherData) {\n const instance = getCurrentInstance();\n const _currentRowKey = ref(null);\n const currentRow = ref(null);\n const setCurrentRowKey = key => {\n instance.store.assertRowKey();\n _currentRowKey.value = key;\n setCurrentRowByKey(key);\n };\n const restoreCurrentRowKey = () => {\n _currentRowKey.value = null;\n };\n const setCurrentRowByKey = key => {\n const {\n data,\n rowKey\n } = watcherData;\n let _currentRow = null;\n if (rowKey.value) {\n _currentRow = (unref(data) || []).find(item => getRowIdentity(item, rowKey.value) === key);\n }\n currentRow.value = _currentRow;\n instance.emit(\"current-change\", currentRow.value, null);\n };\n const updateCurrentRow = _currentRow => {\n const oldCurrentRow = currentRow.value;\n if (_currentRow && _currentRow !== oldCurrentRow) {\n currentRow.value = _currentRow;\n instance.emit(\"current-change\", currentRow.value, oldCurrentRow);\n return;\n }\n if (!_currentRow && oldCurrentRow) {\n currentRow.value = null;\n instance.emit(\"current-change\", null, oldCurrentRow);\n }\n };\n const updateCurrentRowData = () => {\n const rowKey = watcherData.rowKey.value;\n const data = watcherData.data.value || [];\n const oldCurrentRow = currentRow.value;\n if (!data.includes(oldCurrentRow) && oldCurrentRow) {\n if (rowKey) {\n const currentRowKey = getRowIdentity(oldCurrentRow, rowKey);\n setCurrentRowByKey(currentRowKey);\n } else {\n currentRow.value = null;\n }\n if (isNull(currentRow.value)) {\n instance.emit(\"current-change\", null, oldCurrentRow);\n }\n } else if (_currentRowKey.value) {\n setCurrentRowByKey(_currentRowKey.value);\n restoreCurrentRowKey();\n }\n };\n return {\n setCurrentRowKey,\n restoreCurrentRowKey,\n setCurrentRowByKey,\n updateCurrentRow,\n updateCurrentRowData,\n states: {\n _currentRowKey,\n currentRow\n }\n };\n}\nexport { useCurrent as default };","map":{"version":3,"names":["useCurrent","watcherData","instance","getCurrentInstance","_currentRowKey","ref","currentRow","setCurrentRowKey","key","store","assertRowKey","value","setCurrentRowByKey","restoreCurrentRowKey","data","rowKey","_currentRow","unref","find","item","getRowIdentity","emit","updateCurrentRow","oldCurrentRow","updateCurrentRowData","includes","currentRowKey","isNull","states"],"sources":["../../../../../../../packages/components/table/src/store/current.ts"],"sourcesContent":["// @ts-nocheck\nimport { getCurrentInstance, ref, unref } from 'vue'\nimport { isNull } from 'lodash-unified'\nimport { getRowIdentity } from '../util'\n\nimport type { Ref } from 'vue'\nimport type { Table } from '../table/defaults'\nimport type { WatcherPropsData } from '.'\n\nfunction useCurrent<T>(watcherData: WatcherPropsData<T>) {\n const instance = getCurrentInstance() as Table<T>\n const _currentRowKey = ref<string>(null)\n const currentRow: Ref<T> = ref(null)\n\n const setCurrentRowKey = (key: string) => {\n instance.store.assertRowKey()\n _currentRowKey.value = key\n setCurrentRowByKey(key)\n }\n\n const restoreCurrentRowKey = () => {\n _currentRowKey.value = null\n }\n\n const setCurrentRowByKey = (key: string) => {\n const { data, rowKey } = watcherData\n let _currentRow = null\n if (rowKey.value) {\n _currentRow = (unref(data) || []).find(\n (item) => getRowIdentity(item, rowKey.value) === key\n )\n }\n currentRow.value = _currentRow\n instance.emit('current-change', currentRow.value, null)\n }\n\n const updateCurrentRow = (_currentRow: T) => {\n const oldCurrentRow = currentRow.value\n if (_currentRow && _currentRow !== oldCurrentRow) {\n currentRow.value = _currentRow\n instance.emit('current-change', currentRow.value, oldCurr