x-group-list 0.1.3 → 0.1.5

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.d.ts CHANGED
@@ -1,35 +1 @@
1
- import { Ref } from 'vue'
2
-
3
- type Type = 0 | 1
4
-
5
- interface ListEntry {
6
- id: string
7
- type: Type
8
- name: string
9
- position: number
10
- // group
11
- count?: number
12
- collapse?: boolean
13
- detail?: boolean
14
- // item
15
- group?: string
16
- select?: boolean
17
- show?: boolean
18
- }
19
-
20
- export declare function tidyList(
21
- entryList: ListEntry[],
22
- clean: boolean
23
- ): ListEntry[]
24
- export declare function getListEntry(
25
- entryList: Ref<ListEntry[]>,
26
- id: string
27
- ): ListEntry | undefined
28
- export declare function setCollapse(
29
- entryList: Ref<ListEntry[]>,
30
- id: string,
31
- collapse: boolean
32
- )
33
- export declare function hasDetail(entryList: Ref<ListEntry[]>): boolean
34
- export declare function toggleDetail(entryList: Ref<ListEntry[]>, id: string)
35
- export declare function selectItem(entryList: Ref<ListEntry[]>, id: string)
1
+ export * from './utils/groupList';
package/dist/index.js CHANGED
@@ -1,61 +1,56 @@
1
- function u(s, t) {
2
- return s.position < t.position ? -1 : s.position > t.position ? 1 : 0;
3
- }
4
- function c(s, t) {
1
+ function n(o, t) {
5
2
  const i = [];
6
- let o = [];
7
- s.forEach((e) => {
8
- e.type === 0 ? i.findIndex((l) => l.id === e.id) === -1 ? i.push(e) : console.assert(!1, "duplicate group", e) : e.type === 1 ? o.findIndex((l) => l.id === e.id) === -1 ? o.push(e) : console.assert(!1, "duplicate item", e) : console.assert(!1, "invalid type", e);
9
- }), i.sort(u), o.sort(u);
10
- const f = [];
3
+ let s = [];
11
4
  o.forEach((e) => {
12
- i.findIndex((l) => l.id === e.group) === -1 && f.push(e.id);
13
- }), o = o.filter(
14
- (e) => f.findIndex((l) => l === e.id) === -1
15
- );
16
- const n = [];
5
+ e.type === 0 ? i.find((l) => l.id === e.id) ? console.assert(!1, "duplicate group", e) : i.push(e) : e.type === 1 ? s.find((l) => l.id === e.id) ? console.assert(!1, "duplicate item", e) : s.push(e) : console.assert(!1, "invalid type", e);
6
+ }), i.sort((e, l) => e.position - l.position), s.sort((e, l) => e.position - l.position);
7
+ const f = [];
8
+ s.forEach((e) => {
9
+ i.find((l) => l.id === e.group) || f.push(e.id);
10
+ }), s = s.filter((e) => !f.find((l) => l === e.id));
11
+ const a = [];
17
12
  return i.forEach((e) => {
18
13
  const l = [];
19
- o.forEach((a) => {
20
- a.group === e.id && (a.show = !e.collapse, l.push(a));
21
- }), e.count = l.length, e.count > 0 ? (n.push(e), n.push(...l)) : t || n.push(e);
22
- }), n;
14
+ s.forEach((c) => {
15
+ c.group === e.id && (c.show = !e.collapse, l.push(c));
16
+ }), e.count = l.length, e.count > 0 ? (a.push(e), a.push(...l)) : t || a.push(e);
17
+ }), a;
23
18
  }
24
- function d(s, t) {
25
- return s.value.find((i) => i.id === t);
19
+ function u(o, t) {
20
+ return o.value.find((i) => i.id === t);
26
21
  }
27
- function p(s, t, i) {
28
- for (let o = 0; o < s.value.length; o++) {
29
- let f = s.value[o];
22
+ function p(o, t, i) {
23
+ for (let s = 0; s < o.value.length; s++) {
24
+ let f = o.value[s];
30
25
  if (f.id === t) {
31
26
  if (f.type !== 0) {
32
27
  console.assert(!1, "type must be 0");
33
28
  break;
34
29
  }
35
- for (f.collapse = i, o++; o < s.value.length && (f = s.value[o], f.type !== 0); o++)
30
+ for (f.collapse = i, s++; s < o.value.length && (f = o.value[s], f.type !== 0); s++)
36
31
  f.show = !i;
37
32
  break;
38
33
  }
39
34
  }
40
35
  }
41
- function h(s) {
42
- return s.value.findIndex((t) => t.type === 0 && t.detail) !== -1;
36
+ function d(o) {
37
+ return !!o.value.find((t) => t.type === 0 && t.detail);
43
38
  }
44
- function r(s, t) {
45
- s.value.forEach((i) => {
39
+ function h(o, t) {
40
+ o.value.forEach((i) => {
46
41
  i.type === 0 && (i.detail = i.id === t);
47
42
  });
48
43
  }
49
- function v(s, t) {
50
- s.value.forEach((i) => {
44
+ function r(o, t) {
45
+ o.value.forEach((i) => {
51
46
  i.type !== 0 && (i.select = i.id === t);
52
47
  });
53
48
  }
54
49
  export {
55
- d as getListEntry,
56
- h as hasDetail,
57
- v as selectItem,
50
+ u as getListEntry,
51
+ d as hasDetail,
52
+ r as selectItem,
58
53
  p as setCollapse,
59
- c as tidyList,
60
- r as toggleDetail
54
+ n as tidyList,
55
+ h as toggleDetail
61
56
  };
@@ -0,0 +1,27 @@
1
+ import { Ref } from 'vue';
2
+ export interface ListGroup {
3
+ id: string;
4
+ type: 0;
5
+ name: string;
6
+ position: number;
7
+ collapse: boolean;
8
+ count: number;
9
+ detail?: boolean;
10
+ }
11
+ export interface ListItem {
12
+ id: string;
13
+ type: 1;
14
+ name: string;
15
+ position: number;
16
+ group: string;
17
+ select: boolean;
18
+ show?: boolean;
19
+ }
20
+ type ListEntry = ListGroup | ListItem;
21
+ export declare function tidyList(entryList: ListEntry[], clean: boolean): ListEntry[];
22
+ export declare function getListEntry(entryList: Ref<ListEntry[]>, id: string): ListEntry | undefined;
23
+ export declare function setCollapse(entryList: Ref<ListEntry[]>, id: string, collapse: boolean): void;
24
+ export declare function hasDetail(entryList: Ref<ListEntry[]>): boolean;
25
+ export declare function toggleDetail(entryList: Ref<ListEntry[]>, id: string): void;
26
+ export declare function selectItem(entryList: Ref<ListEntry[]>, id: string): void;
27
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "x-group-list",
3
3
  "private": false,
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",