x-group-list 0.2.7 → 0.2.8

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.
package/dist/index.js CHANGED
@@ -1,77 +1,77 @@
1
- function d(s, p) {
1
+ function d(s, l) {
2
2
  const o = [];
3
- let i = [];
4
- s.forEach((l) => {
5
- l.type === 0 ? o.push(l) : l.type === 1 ? i.push(l) : console.assert(!1);
6
- }), o.sort((l, e) => l.position - e.position), i.sort((l, e) => l.position - e.position);
7
- const f = [];
8
- i.forEach((l) => {
9
- o.find((e) => e.id === l.group) || f.push(l.id);
10
- }), i = i.filter((l) => !f.find((e) => e === l.id));
3
+ let f = [];
4
+ s.forEach((i) => {
5
+ i.type === 0 ? o.push(i) : i.type === 1 ? f.push(i) : console.assert(!1);
6
+ }), o.sort((i, e) => i.position - e.position), f.sort((i, e) => i.position - e.position);
11
7
  const a = [];
12
- return o.forEach((l) => {
8
+ f.forEach((i) => {
9
+ o.find((e) => e.id === i.group) || a.push(i.id);
10
+ }), f = f.filter((i) => !a.find((e) => e === i.id));
11
+ const u = [];
12
+ return o.forEach((i) => {
13
13
  const e = [];
14
- i.forEach((t) => {
15
- t.group === l.id && (t.show = !l.collapse, e.push(t));
16
- }), l.count = e.length, l.count > 0 ? (a.push(l), a.push(...e)) : p || a.push(l);
17
- }), a;
14
+ f.forEach((t) => {
15
+ t.group === i.id && (t.show = !i.collapse, e.push(t));
16
+ }), i.count = e.length, i.count > 0 ? (u.push(i), u.push(...e)) : l || u.push(i);
17
+ }), u;
18
18
  }
19
- function r(s, p) {
20
- return s.value.find((o) => o.id === p);
19
+ function r(s, l) {
20
+ return s.value.find((o) => o.id === l);
21
21
  }
22
- function v(s, p, o) {
23
- for (let i = 0; i < s.value.length; i++) {
24
- let f = s.value[i];
25
- if (f.id === p) {
26
- if (f.type !== 0) {
22
+ function v(s, l, o) {
23
+ for (let f = 0; f < s.value.length; f++) {
24
+ let a = s.value[f];
25
+ if (a.id === l) {
26
+ if (a.type !== 0) {
27
27
  console.assert(!1, "type must be 0");
28
28
  break;
29
29
  }
30
- for (f.collapse = o, i++; i < s.value.length && (f = s.value[i], f.type !== 0); i++)
31
- f.show = !o;
30
+ for (a.collapse = o, f++; f < s.value.length && (a = s.value[f], a.type !== 0); f++)
31
+ a.show = !o;
32
32
  break;
33
33
  }
34
34
  }
35
35
  }
36
36
  function g(s) {
37
- return !!s.value.find((p) => p.type === 0 && p.detail);
37
+ return !!s.value.find((l) => l.type === 0 && l.detail);
38
38
  }
39
- function E(s, p) {
39
+ function E(s, l) {
40
40
  s.value.forEach((o) => {
41
- o.type === 0 && (o.detail = o.id === p);
41
+ o.type === 0 && (o.detail = o.id === l);
42
42
  });
43
43
  }
44
- function b(s, p) {
44
+ function b(s, l) {
45
45
  s.value.forEach((o) => {
46
- o.type !== 0 && (o.select = o.id === p);
46
+ o.type !== 0 && (o.select = o.id === l);
47
47
  });
48
48
  }
49
- function k(s, p, o, i) {
50
- if (p === 1) {
51
- if (i === 0) {
52
- const t = s.value.splice(i, 1)[0];
49
+ function k(s, l, o, f) {
50
+ if (l === 1) {
51
+ if (f === 0) {
52
+ const t = s.value.splice(f, 1)[0];
53
53
  s.value.splice(o, 0, t);
54
54
  return;
55
55
  }
56
56
  let e;
57
57
  for (let t = 0; t < s.value.length; t++) {
58
- const u = s.value[t];
59
- if (u.type === 0)
60
- e = u;
61
- else if (u.type === 1) {
58
+ const n = s.value[t];
59
+ if (n.type === 0)
60
+ e = n;
61
+ else if (n.type === 1) {
62
62
  if (!e) {
63
63
  console.assert(!1);
64
64
  return;
65
65
  }
66
- if (u.group !== e.id) {
67
- if (u.group = e.id, e.collapse) {
68
- let c = t;
66
+ if (n.group !== e.id) {
67
+ if (n.group = e.id, e.collapse) {
68
+ let p = t;
69
69
  for (t++; t < s.value.length; t++) {
70
- const n = s.value[t];
71
- if (n.type === 0 || n.show)
70
+ const c = s.value[t];
71
+ if (c.type === 0 || c.show)
72
72
  break;
73
- const h = s.value[c];
74
- s.value[c] = n, s.value[t] = h, c = t;
73
+ const h = s.value[p];
74
+ s.value[p] = c, s.value[t] = h, p = t;
75
75
  }
76
76
  }
77
77
  break;
@@ -80,60 +80,49 @@ function k(s, p, o, i) {
80
80
  console.assert(!1);
81
81
  }
82
82
  }
83
- const f = [], a = [];
83
+ const a = [], u = [];
84
84
  s.value.forEach((e) => {
85
- e.type === 0 ? f.push(e) : e.type === 1 ? a.push(e) : console.assert(!1);
85
+ e.type === 0 ? a.push(e) : e.type === 1 ? u.push(e) : console.assert(!1);
86
86
  });
87
- const l = [];
88
- f.forEach((e, t) => {
87
+ const i = [];
88
+ a.forEach((e, t) => {
89
89
  e.position = t;
90
- const u = [];
91
- a.forEach((c) => {
92
- c.group === e.id && (c.position = u.length, u.push(c));
93
- }), e.count = u.length, l.push(e), l.push(...u);
94
- }), s.value = l;
90
+ const n = [];
91
+ u.forEach((p) => {
92
+ p.group === e.id && (p.position = n.length, n.push(p));
93
+ }), e.count = n.length, i.push(e), i.push(...n);
94
+ }), s.value = i;
95
95
  }
96
- function D(s) {
97
- const p = {};
96
+ function I(s) {
97
+ const l = {};
98
98
  return s.value.forEach((o) => {
99
- o.type === 0 ? p[o.id] = {
99
+ o.type === 0 ? l[o.id] = {
100
+ id: o.id,
101
+ group: "",
100
102
  position: o.position
101
- } : o.type === 1 ? p[o.id] = {
103
+ } : o.type === 1 ? l[o.id] = {
104
+ id: o.id,
102
105
  group: o.group,
103
106
  position: o.position
104
107
  } : console.assert(!1);
105
- }), p;
108
+ }), l;
106
109
  }
107
- function I(s, p) {
108
- const o = {};
109
- return s.value.forEach((i) => {
110
- if (i.type === 0) {
111
- const f = p[i.id];
112
- if (i.position === (f == null ? void 0 : f.position))
113
- return;
114
- o[i.id] = {
115
- position: i.position
116
- };
117
- } else if (i.type === 1) {
118
- const f = p[i.id];
119
- if (i.group === (f == null ? void 0 : f.group) && i.position === (f == null ? void 0 : f.position))
120
- return;
121
- o[i.id] = {
122
- group: i.group,
123
- position: i.position
124
- };
125
- } else
126
- console.assert(!1);
127
- }), o;
110
+ function D(s, l) {
111
+ const o = [];
112
+ for (let f in l) {
113
+ const a = l[f], u = s[f];
114
+ (!u || a.group !== u.group || a.position !== u.position) && o.push({ ...a });
115
+ }
116
+ return o;
128
117
  }
129
118
  export {
130
- D as backupPosInfos,
131
- I as diffPosInfos,
119
+ D as diffPosInfos,
132
120
  r as getListEntry,
133
121
  g as hasDetail,
134
122
  k as onDragEnd,
135
123
  b as selectItem,
136
124
  v as setCollapse,
137
125
  d as tidyList,
126
+ I as toPosInfos,
138
127
  E as toggleDetail
139
128
  };
@@ -25,11 +25,13 @@ export declare function hasDetail(entryList: Ref<ListEntry[]>): boolean;
25
25
  export declare function toggleDetail(entryList: Ref<ListEntry[]>, id: string): void;
26
26
  export declare function selectItem(entryList: Ref<ListEntry[]>, id: string): void;
27
27
  export declare function onDragEnd(entryList: Ref<ListEntry[]>, draggingType: 0 | 1, oldIndex: number, newIndex: number): void;
28
+ export interface PosInfo {
29
+ id: string;
30
+ group: string;
31
+ position: number;
32
+ }
28
33
  export type PosInfos = {
29
- [key: string]: {
30
- group?: string;
31
- position: number;
32
- };
34
+ [key: string]: PosInfo;
33
35
  };
34
- export declare function backupPosInfos(entryList: Ref<ListEntry[]>): PosInfos;
35
- export declare function diffPosInfos(entryList: Ref<ListEntry[]>, backup: PosInfos): PosInfos;
36
+ export declare function toPosInfos(entryList: Ref<ListEntry[]>): PosInfos;
37
+ export declare function diffPosInfos(oldPosInfos: PosInfos, newPosInfos: PosInfos): PosInfo[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "x-group-list",
3
3
  "private": false,
4
- "version": "0.2.7",
4
+ "version": "0.2.8",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",