82805bb14ead983add7979eb946f6de78b88833023d06cbddbae456345f786fbc3505720341dc9554f1d0f15ef00261014d804a3f11c0c970890c8351e8707 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var util = require('../util.js');
  6. function useCurrent(watcherData) {
  7. const instance = vue.getCurrentInstance();
  8. const _currentRowKey = vue.ref(null);
  9. const currentRow = vue.ref(null);
  10. const setCurrentRowKey = (key) => {
  11. instance.store.assertRowKey();
  12. _currentRowKey.value = key;
  13. setCurrentRowByKey(key);
  14. };
  15. const restoreCurrentRowKey = () => {
  16. _currentRowKey.value = null;
  17. };
  18. const setCurrentRowByKey = (key) => {
  19. var _a;
  20. const { data, rowKey } = watcherData;
  21. let _currentRow = null;
  22. if (rowKey.value) {
  23. _currentRow = (_a = (vue.unref(data) || []).find((item) => util.getRowIdentity(item, rowKey.value) === key)) != null ? _a : null;
  24. }
  25. currentRow.value = _currentRow != null ? _currentRow : null;
  26. instance.emit("current-change", currentRow.value, null);
  27. };
  28. const updateCurrentRow = (_currentRow) => {
  29. const oldCurrentRow = currentRow.value;
  30. if (_currentRow && _currentRow !== oldCurrentRow) {
  31. currentRow.value = _currentRow;
  32. instance.emit("current-change", currentRow.value, oldCurrentRow);
  33. return;
  34. }
  35. if (!_currentRow && oldCurrentRow) {
  36. currentRow.value = null;
  37. instance.emit("current-change", null, oldCurrentRow);
  38. }
  39. };
  40. const updateCurrentRowData = () => {
  41. const rowKey = watcherData.rowKey.value;
  42. const data = watcherData.data.value || [];
  43. const oldCurrentRow = currentRow.value;
  44. if (oldCurrentRow && !data.includes(oldCurrentRow)) {
  45. if (rowKey) {
  46. const currentRowKey = util.getRowIdentity(oldCurrentRow, rowKey);
  47. setCurrentRowByKey(currentRowKey);
  48. } else {
  49. currentRow.value = null;
  50. }
  51. if (lodashUnified.isNull(currentRow.value)) {
  52. instance.emit("current-change", null, oldCurrentRow);
  53. }
  54. } else if (_currentRowKey.value) {
  55. setCurrentRowByKey(_currentRowKey.value);
  56. restoreCurrentRowKey();
  57. }
  58. };
  59. return {
  60. setCurrentRowKey,
  61. restoreCurrentRowKey,
  62. setCurrentRowByKey,
  63. updateCurrentRow,
  64. updateCurrentRowData,
  65. states: {
  66. _currentRowKey,
  67. currentRow
  68. }
  69. };
  70. }
  71. exports["default"] = useCurrent;
  72. //# sourceMappingURL=current.js.map