orion-design 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { PropType, ExtractPropTypes, CSSProperties } from 'vue';
1
+ import { PropType, ExtractPropTypes, CSSProperties, ComponentPublicInstance, ComputedRef } from 'vue';
2
2
  type rowClassNameFn = (data: {
3
3
  rowData: any;
4
4
  rowIndex: number;
@@ -46,6 +46,15 @@ export declare const edittableProps: () => {
46
46
  cellStyle: PropType<CSSProperties | cellStyleFn>;
47
47
  };
48
48
  export type EdittableProps = Partial<ExtractPropTypes<ReturnType<typeof edittableProps>>>;
49
+ export interface EdittableExpose {
50
+ clearSelection: () => void;
51
+ toggleRowSelection: (row: any, selected?: boolean) => void;
52
+ toggleAllSelection: () => void;
53
+ getSelectionRows: () => any[];
54
+ setCurrentRow: (row: any) => void;
55
+ columns: ComputedRef<any[]>;
56
+ }
57
+ export type EdittableInstance = ComponentPublicInstance<EdittableProps, EdittableExpose>;
49
58
  declare const _default: import('vue').DefineComponent<ExtractPropTypes<{
50
59
  data: ArrayConstructor;
51
60
  showRowNumber: {
@@ -0,0 +1,30 @@
1
+ import { ShallowRef } from 'vue';
2
+ import { EdittableInstance } from '../../../index.ts';
3
+ interface UseEdittableOptions<Row> {
4
+ tableRef?: Readonly<ShallowRef<EdittableInstance | null>>;
5
+ defaultData?: Row[];
6
+ newRowSchema?: Record<string, any> | (() => Record<string, any>);
7
+ afterSelectionChange?: (newSelection: Row[]) => void;
8
+ afterCurrentRowChange?: (currentRow: Row, oldCurrentRow: Row) => void;
9
+ }
10
+ declare const useEdittable: <Row = any>(options: UseEdittableOptions<Row>) => {
11
+ data: Row[];
12
+ selection: Row[];
13
+ currentRow: Row | undefined;
14
+ onSelectionChange: (newSelection: Row[]) => void;
15
+ onCurrentRowChange: (newCurrentRow: Row, oldCurrentRow: Row) => void;
16
+ clearSelection: () => void;
17
+ toggleRowSelection: (row: Row, selected?: boolean) => void;
18
+ toggleAllSelection: () => void;
19
+ getSelectionRows: () => Row[];
20
+ setCurrentRow: (row: Row) => void;
21
+ appendRow: (rowData: any) => void;
22
+ insertRow: (rowData: any, index: number) => void;
23
+ deleteRow: (index: number) => void;
24
+ updateRow: (rowData: any, index: number) => void;
25
+ moveUp: (index: number) => void;
26
+ moveDown: (index: number) => void;
27
+ moveTo: (from: number, to: number) => void;
28
+ selectionGroup: () => void;
29
+ };
30
+ export default useEdittable;
@@ -0,0 +1,91 @@
1
+ import { ref as w, reactive as N } from "vue";
2
+ import r from "../../../error/OrionError.js";
3
+ import { isEqual as W, isFunction as Y, extend as q } from "lodash-es";
4
+ import "dayjs";
5
+ import "../../../utils/md5.js";
6
+ import "decimal.js";
7
+ import T from "../../../utils/uuid.js";
8
+ const h = "ORION_ROW_KEY", L = (m) => {
9
+ const { tableRef: o, defaultData: R, newRowSchema: c, afterSelectionChange: g, afterCurrentRowChange: v } = m, l = w(R || []), a = w([]), p = w(), S = (e) => {
10
+ a.value = e, g && g(e);
11
+ }, d = (e, t) => {
12
+ p.value = e, v && v(e, t);
13
+ }, C = () => {
14
+ if (!o)
15
+ throw new r("调用clearSelection失败,tableRef为空");
16
+ o.value.clearSelection();
17
+ }, E = (e, t) => {
18
+ if (!o)
19
+ throw new r("调用toggleRowSelection失败,tableRef为空");
20
+ o.value.toggleRowSelection(e, t);
21
+ }, b = () => {
22
+ if (!o)
23
+ throw new r("调用toggleAllSelection失败,tableRef为空");
24
+ o.value.toggleAllSelection();
25
+ }, O = () => {
26
+ if (!o)
27
+ throw new r("调用getSelectionRows失败,tableRef为空");
28
+ return o.value.getSelectionRows();
29
+ }, I = (e) => {
30
+ if (!o)
31
+ throw new r("调用setCurrentRow失败,tableRef为空");
32
+ o.value.setCurrentRow(e);
33
+ }, u = (e) => {
34
+ const t = {};
35
+ e[h] || (t[h] = T());
36
+ let n = {};
37
+ return c && (Y(c) ? n = c() : n = c), q(t, n, e);
38
+ }, _ = (e) => {
39
+ l.value.push(u(e));
40
+ }, A = (e, t) => {
41
+ l.value.splice(t, 0, u(e));
42
+ }, D = (e) => {
43
+ l.value.splice(e, 1);
44
+ }, x = (e, t) => {
45
+ l.value[t] = u(e);
46
+ }, F = (e) => {
47
+ s(e, e - 1);
48
+ }, G = (e) => {
49
+ s(e, e + 1);
50
+ }, s = (e, t) => {
51
+ const n = l.value.splice(e, 1);
52
+ l.value.splice(t, 0, n[0]);
53
+ };
54
+ return N({
55
+ data: l,
56
+ selection: a,
57
+ currentRow: p,
58
+ onSelectionChange: S,
59
+ onCurrentRowChange: d,
60
+ clearSelection: C,
61
+ toggleRowSelection: E,
62
+ toggleAllSelection: b,
63
+ getSelectionRows: O,
64
+ setCurrentRow: I,
65
+ appendRow: _,
66
+ insertRow: A,
67
+ deleteRow: D,
68
+ updateRow: x,
69
+ moveUp: F,
70
+ moveDown: G,
71
+ moveTo: s,
72
+ selectionGroup: () => {
73
+ if (a.value.length < 2)
74
+ return;
75
+ let e = 0, t = !0;
76
+ const n = [];
77
+ l.value.forEach((f, i) => {
78
+ a.value.forEach((K) => {
79
+ if (W(f, K))
80
+ return t ? (e = i, t = !1) : n.push(i), !1;
81
+ });
82
+ }), n.forEach((f, i) => {
83
+ s(f, e + i + 1);
84
+ });
85
+ }
86
+ });
87
+ };
88
+ export {
89
+ L as default
90
+ };
91
+ //# sourceMappingURL=useEdittable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEdittable.js","sources":["../../../../src/components/Edittable/hooks/useEdittable.ts"],"sourcesContent":["import { reactive, ref } from 'vue'\r\nimport type { Ref, ShallowRef } from 'vue'\r\nimport OrionError from '../../../error/OrionError'\r\nimport type { EdittableInstance } from 'orion-design'\r\nimport { uuid } from '../../../utils'\r\nimport { isEqual, extend, isFunction } from 'lodash-es'\r\n\r\nconst ORION_ROW_KEY = 'ORION_ROW_KEY'\r\n\r\ninterface UseEdittableOptions<Row> {\r\n tableRef?: Readonly<ShallowRef<EdittableInstance | null>>\r\n defaultData?: Row[]\r\n newRowSchema?: Record<string, any> | (() => Record<string, any>)\r\n afterSelectionChange?: (newSelection: Row[]) => void\r\n afterCurrentRowChange?: (currentRow: Row, oldCurrentRow: Row) => void\r\n}\r\n\r\nconst useEdittable = <Row = any>(options: UseEdittableOptions<Row>) => {\r\n const { tableRef, defaultData, newRowSchema, afterSelectionChange, afterCurrentRowChange } = options\r\n\r\n const data = ref<Row[]>(defaultData ? defaultData : []) as Ref<Row[]>\r\n const selection = ref<Row[]>([]) as Ref<Row[]>\r\n const currentRow = ref<Row>()\r\n\r\n const onSelectionChange = (newSelection: Row[]) => {\r\n selection.value = newSelection\r\n afterSelectionChange && afterSelectionChange(newSelection)\r\n }\r\n const onCurrentRowChange = (newCurrentRow: Row, oldCurrentRow: Row) => {\r\n currentRow.value = newCurrentRow\r\n afterCurrentRowChange && afterCurrentRowChange(newCurrentRow, oldCurrentRow)\r\n }\r\n\r\n const clearSelection = () => {\r\n if (!tableRef) {\r\n throw new OrionError(`调用clearSelection失败,tableRef为空`)\r\n }\r\n tableRef.value!.clearSelection()\r\n }\r\n const toggleRowSelection = (row: Row, selected?: boolean) => {\r\n if (!tableRef) {\r\n throw new OrionError(`调用toggleRowSelection失败,tableRef为空`)\r\n }\r\n tableRef.value!.toggleRowSelection(row, selected)\r\n }\r\n const toggleAllSelection = () => {\r\n if (!tableRef) {\r\n throw new OrionError(`调用toggleAllSelection失败,tableRef为空`)\r\n }\r\n tableRef.value!.toggleAllSelection()\r\n }\r\n const getSelectionRows = () => {\r\n if (!tableRef) {\r\n throw new OrionError(`调用getSelectionRows失败,tableRef为空`)\r\n }\r\n return tableRef.value!.getSelectionRows() as Row[]\r\n }\r\n const setCurrentRow = (row: Row) => {\r\n if (!tableRef) {\r\n throw new OrionError(`调用setCurrentRow失败,tableRef为空`)\r\n }\r\n tableRef.value!.setCurrentRow(row)\r\n }\r\n\r\n const createRowData = (source: any) => {\r\n const target: any = {}\r\n if (!source[ORION_ROW_KEY]) {\r\n target[ORION_ROW_KEY] = uuid()\r\n }\r\n\r\n let schema: any = {}\r\n if (newRowSchema) {\r\n if (isFunction(newRowSchema)) {\r\n schema = newRowSchema()\r\n } else {\r\n schema = newRowSchema\r\n }\r\n }\r\n\r\n return extend(target, schema, source)\r\n }\r\n const appendRow = (rowData: any) => {\r\n data.value.push(createRowData(rowData))\r\n }\r\n const insertRow = (rowData: any, index: number) => {\r\n data.value.splice(index, 0, createRowData(rowData))\r\n }\r\n const deleteRow = (index: number) => {\r\n data.value.splice(index, 1)\r\n }\r\n const updateRow = (rowData: any, index: number) => {\r\n data.value[index] = createRowData(rowData)\r\n }\r\n const moveUp = (index: number) => {\r\n moveTo(index, index - 1)\r\n }\r\n const moveDown = (index: number) => {\r\n moveTo(index, index + 1)\r\n }\r\n const moveTo = (from: number, to: number) => {\r\n const item = data.value.splice(from, 1)\r\n data.value.splice(to, 0, item[0])\r\n }\r\n const selectionGroup = () => {\r\n if (selection.value.length < 2) {\r\n return\r\n }\r\n\r\n let firstRowIndex: number = 0\r\n let firstRowFlag: boolean = true\r\n const leftRowIndexs: number[] = []\r\n\r\n data.value.forEach((e, i) => {\r\n selection.value.forEach((item) => {\r\n if (isEqual(e, item)) {\r\n if (firstRowFlag) {\r\n firstRowIndex = i\r\n firstRowFlag = false\r\n } else {\r\n leftRowIndexs.push(i)\r\n }\r\n return false\r\n }\r\n })\r\n })\r\n\r\n leftRowIndexs.forEach((e, i) => {\r\n moveTo(e, firstRowIndex + i + 1)\r\n })\r\n }\r\n\r\n return reactive({\r\n data,\r\n selection,\r\n currentRow,\r\n onSelectionChange,\r\n onCurrentRowChange,\r\n clearSelection,\r\n toggleRowSelection,\r\n toggleAllSelection,\r\n getSelectionRows,\r\n setCurrentRow,\r\n appendRow,\r\n insertRow,\r\n deleteRow,\r\n updateRow,\r\n moveUp,\r\n moveDown,\r\n moveTo,\r\n selectionGroup,\r\n })\r\n}\r\n\r\nexport default useEdittable\r\n"],"names":["ORION_ROW_KEY","useEdittable","options","tableRef","defaultData","newRowSchema","afterSelectionChange","afterCurrentRowChange","data","ref","selection","currentRow","onSelectionChange","newSelection","onCurrentRowChange","newCurrentRow","oldCurrentRow","clearSelection","OrionError","toggleRowSelection","row","selected","toggleAllSelection","getSelectionRows","setCurrentRow","createRowData","source","target","uuid","schema","isFunction","extend","appendRow","rowData","insertRow","index","deleteRow","updateRow","moveUp","moveTo","moveDown","from","to","item","reactive","firstRowIndex","firstRowFlag","leftRowIndexs","e","isEqual"],"mappings":";;;;;;;AAOA,MAAMA,IAAgB,iBAUhBC,IAAe,CAAYC,MAAsC;AACrE,QAAM,EAAE,UAAAC,GAAU,aAAAC,GAAa,cAAAC,GAAc,sBAAAC,GAAsB,uBAAAC,EAA0B,IAAAL,GAEvFM,IAAOC,EAAWL,KAA4B,CAAE,CAAA,GAChDM,IAAYD,EAAW,CAAA,CAAE,GACzBE,IAAaF,KAEbG,IAAoB,CAACC,MAAwB;AACjD,IAAAH,EAAU,QAAQG,GAClBP,KAAwBA,EAAqBO,CAAY;AAAA,EAAA,GAErDC,IAAqB,CAACC,GAAoBC,MAAuB;AACrE,IAAAL,EAAW,QAAQI,GACMR,KAAAA,EAAsBQ,GAAeC,CAAa;AAAA,EAAA,GAGvEC,IAAiB,MAAM;AAC3B,QAAI,CAACd;AACG,YAAA,IAAIe,EAAW,+BAA+B;AAEtD,IAAAf,EAAS,MAAO;EAAe,GAE3BgB,IAAqB,CAACC,GAAUC,MAAuB;AAC3D,QAAI,CAAClB;AACG,YAAA,IAAIe,EAAW,mCAAmC;AAEjD,IAAAf,EAAA,MAAO,mBAAmBiB,GAAKC,CAAQ;AAAA,EAAA,GAE5CC,IAAqB,MAAM;AAC/B,QAAI,CAACnB;AACG,YAAA,IAAIe,EAAW,mCAAmC;AAE1D,IAAAf,EAAS,MAAO;EAAmB,GAE/BoB,IAAmB,MAAM;AAC7B,QAAI,CAACpB;AACG,YAAA,IAAIe,EAAW,iCAAiC;AAEjD,WAAAf,EAAS,MAAO;EAAiB,GAEpCqB,IAAgB,CAACJ,MAAa;AAClC,QAAI,CA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AAE;AAAA,IACA,oBAAAG;AAAA,IACA,kBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,WAAAQ;AAAA,IACA,WAAAE;AAAA,IACA,WAAAE;AAAA,IACA,WAAAC;AAAA,IACA,QAAAC;AAAA,IACA,UAAAE;AAAA,IACA,QAAAD;AAAA,IACA,gBA9CqB,MAAM;AACvB,UAAA7B,EAAU,MAAM,SAAS;AAC3B;AAGF,UAAImC,IAAwB,GACxBC,IAAwB;AAC5B,YAAMC,IAA0B,CAAA;AAEhC,MAAAvC,EAAK,MAAM,QAAQ,CAACwC,GAAG,MAAM;AACjB,QAAAtC,EAAA,MAAM,QAAQ,CAACiC,MAAS;AAC5B,cAAAM,EAAQD,GAAGL,CAAI;AACjB,mBAAIG,KACcD,IAAA,GACDC,IAAA,MAEfC,EAAc,KAAK,CAAC,GAEf;AAAA,QACT,CACD;AAAA,MAAA,CACF,GAEaA,EAAA,QAAQ,CAACC,GAAG,MAAM;AACvB,QAAAT,EAAAS,GAAGH,IAAgB,IAAI,CAAC;AAAA,MAAA,CAChC;AAAA,IAAA;AAAA,EAqBD,CACD;AACH;"}
@@ -10,7 +10,6 @@ import { default as EdittableColumnButtongroup } from './columns/EdittableColumn
10
10
  import { default as EdittableCellButton } from './columns/EdittableCellButton';
11
11
  import { default as EdittableColumngroup } from './columns/EdittableColumngroup';
12
12
  import { default as EdittableColumnDiy } from './columns/EdittableColumnDiy';
13
- export type { EdittableProps } from './Edittable';
14
13
  declare const _default: import('../_util').SFCWithInstall<import('vue').DefineComponent<import('vue').ExtractPropTypes<{
15
14
  data: ArrayConstructor;
16
15
  showRowNumber: {
@@ -119,3 +118,5 @@ declare const _default: import('../_util').SFCWithInstall<import('vue').DefineCo
119
118
  EdittableColumnDiy: typeof EdittableColumnDiy;
120
119
  };
121
120
  export default _default;
121
+ export * from './Edittable';
122
+ export { default as useEdittable } from './hooks/useEdittable';