@neovici/cosmoz-omnitable 14.27.0 → 14.27.1

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.
@@ -10,6 +10,6 @@ export function renderCosmozGroupedList({ renderRow, flatData }: {
10
10
  }): any;
11
11
  export function useCosmozGroupedList(host: any): {
12
12
  renderRow: (item: any, index: any) => any;
13
- flatData: any;
13
+ flatData: (object | import("./utils").GroupItem<object>)[] | undefined;
14
14
  };
15
15
  //# sourceMappingURL=use-cosmoz-grouped-list.d.ts.map
@@ -1,11 +1,22 @@
1
- export namespace symbols {
2
- let group: symbol;
1
+ import { Item } from '../lib/types';
2
+ export interface ItemState {
3
+ expanded?: boolean;
4
+ folded?: boolean;
3
5
  }
4
- export function prepareData(data: any, displayEmptyGroups: any, itemsState: any): any;
5
- export function getItemState(item: any, itemsState: any): any;
6
- export function isExpanded(item: any, itemsState: any): boolean;
7
- export function isFolded(group: any, itemsState: any): boolean;
8
- export function isGroup(item: any): boolean;
9
- export function callFn(fn: any, ...args: any[]): any;
10
- export function byReference(a: any, b: any): boolean;
6
+ export interface GroupItem<T = unknown> {
7
+ items?: T[];
8
+ [key: string]: unknown;
9
+ }
10
+ export type ItemsState = WeakMap<Item, ItemState>;
11
+ declare const symbols: {
12
+ group: symbol;
13
+ };
14
+ declare const getItemState: (item: Item, itemsState: ItemsState) => ItemState;
15
+ declare const isExpanded: (item: Item, itemsState: ItemsState) => boolean;
16
+ declare const isFolded: (group: Item, itemsState: ItemsState) => boolean;
17
+ declare const isGroup: (item: unknown) => item is GroupItem;
18
+ declare const prepareData: <T extends Item>(data: T[] | GroupItem<T>[], displayEmptyGroups: boolean, itemsState: ItemsState) => (T | GroupItem<T>)[] | undefined;
19
+ declare const callFn: <T, A extends unknown[]>(fn: ((...args: A) => T) | T, ...args: A) => T;
20
+ declare const byReference: <T>(a: T, b: T) => boolean;
21
+ export { symbols, prepareData, getItemState, isExpanded, isFolded, isGroup, callFn, byReference, };
11
22
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/grouped-list/utils.js"],"names":[],"mappings":";;;AAAA,sFA6EgC;AA7EhC,8DA6EgC;AA7EhC,gEA6EgC;AA7EhC,+DA6EgC;AA7EhC,4CA6EgC;AA7EhC,qDA6EgC;AA7EhC,qDA6EgC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/grouped-list/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACrC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAElD,QAAA,MAAM,OAAO;;CAEZ,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,MAAM,IAAI,EAAE,YAAY,UAAU,KAAG,SAM1D,CAAC;AAEF,QAAA,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,YAAY,UAAU,KAAG,OACR,CAAC;AAElD,QAAA,MAAM,QAAQ,GAAI,OAAO,IAAI,EAAE,YAAY,UAAU,KAAG,OACR,CAAC;AAEjD,QAAA,MAAM,OAAO,GAAI,MAAM,OAAO,KAAG,IAAI,IAAI,SACiB,CAAC;AAkB3D,QAAA,MAAM,WAAW,GAAI,CAAC,SAAS,IAAI,EAClC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,EAC1B,oBAAoB,OAAO,EAC3B,YAAY,UAAU,KACpB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,SAyCzB,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACrC,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAC3B,GAAG,MAAM,CAAC,KACR,CAMF,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,OAAkB,CAAC;AAExD,OAAO,EACN,OAAO,EACP,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,OAAO,EACP,MAAM,EACN,WAAW,GACX,CAAC"}
@@ -1,49 +1,42 @@
1
1
  const symbols = {
2
2
  group: Symbol('group'),
3
- }, getItemState = (item, itemsState) => {
3
+ };
4
+ const getItemState = (item, itemsState) => {
4
5
  if (!itemsState.has(item)) {
5
6
  itemsState.set(item, {});
6
7
  }
7
8
  return itemsState.get(item);
8
- }, isExpanded = (item, itemsState) => Boolean(getItemState(item, itemsState).expanded), isFolded = (group, itemsState) => Boolean(getItemState(group, itemsState).folded), isGroup = (item) => (item ? item.items instanceof Array : false),
9
- /**
10
- * Asserts that data is either all items or all groups, never mixed.
11
- * @param {Array} data the data
12
- * @return {void}
13
- */
14
- _assertDataIsHomogeneous = (data) => {
9
+ };
10
+ const isExpanded = (item, itemsState) => Boolean(getItemState(item, itemsState).expanded);
11
+ const isFolded = (group, itemsState) => Boolean(getItemState(group, itemsState).folded);
12
+ const isGroup = (item) => item ? item.items instanceof Array : false;
13
+ const _assertDataIsHomogeneous = (data) => {
15
14
  if (!Array.isArray(data) || data.length === 0) {
16
15
  return;
17
16
  }
18
- const firstItemIsAGroup = Array.isArray(data[0].items), isHomogeneous = data.every((group) => Array.isArray(group.items) === firstItemIsAGroup);
17
+ const firstItemIsAGroup = Array.isArray(data[0]?.items), isHomogeneous = data.every((group) => Array.isArray(group.items) === firstItemIsAGroup);
19
18
  if (!isHomogeneous) {
20
19
  throw new Error('Data must be homogeneous.');
21
20
  }
22
- },
23
- /**
24
- * Prepare data.
25
- * @param {array} data Data.
26
- * @param {boolean} displayEmptyGroups Flag.
27
- * @param {WeakMap} itemsState State.
28
- * @returns {void|array} Prepared data.
29
- */
30
- prepareData = (data, displayEmptyGroups, itemsState) => {
21
+ };
22
+ const prepareData = (data, displayEmptyGroups, itemsState) => {
31
23
  if (!Array.isArray(data)) {
32
24
  return;
33
25
  }
34
26
  // data should be either all items or all grouped items, never mixed
35
27
  _assertDataIsHomogeneous(data);
36
28
  const flatData = data.reduce((acc, item) => {
29
+ const groupItem = item;
37
30
  // simple items
38
- if (!item.items) {
31
+ if (!groupItem.items) {
39
32
  return acc.concat(item);
40
33
  }
41
34
  // groups with items
42
- if (item.items.length) {
35
+ if (groupItem.items.length) {
43
36
  if (getItemState(item, itemsState).folded) {
44
37
  return acc.concat(item);
45
38
  }
46
- return acc.concat(item, item.items.map((i) => Object.assign(i, { [symbols.group]: item })));
39
+ return acc.concat(item, groupItem.items.map((i) => Object.assign(i, { [symbols.group]: item })));
47
40
  }
48
41
  // groups without items
49
42
  if (displayEmptyGroups) {
@@ -52,6 +45,13 @@ prepareData = (data, displayEmptyGroups, itemsState) => {
52
45
  return acc;
53
46
  }, []);
54
47
  return flatData;
55
- }, callFn = (fn, ...args) => (typeof fn === 'function' ? fn(...args) : fn), byReference = (a, b) => a === b;
48
+ };
49
+ const callFn = (fn, ...args) => {
50
+ if (typeof fn === 'function') {
51
+ return fn(...args);
52
+ }
53
+ return fn;
54
+ };
55
+ const byReference = (a, b) => a === b;
56
56
  export { symbols, prepareData, getItemState, isExpanded, isFolded, isGroup, callFn, byReference, };
57
57
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-omnitable",
3
- "version": "14.27.0",
3
+ "version": "14.27.1",
4
4
  "description": "[![Build Status](https://travis-ci.org/Neovici/cosmoz-omnitable.svg?branch=master)](https://travis-ci.org/Neovici/cosmoz-omnitable)",
5
5
  "keywords": [
6
6
  "web-components"