@neovici/cosmoz-omnitable 9.0.1 → 9.1.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.
@@ -44,7 +44,7 @@ class Omnitable extends hauntedPolymer(useOmnitable)(
44
44
  /* eslint-disable-next-line max-lines-per-function */
45
45
  static get template() {
46
46
  const template = html`
47
- ${html([styles])}
47
+ ${html(Object.assign([styles], { raw: [styles] }))}
48
48
  <div id="layoutStyle"></div>
49
49
 
50
50
  <div class="mainContainer">
@@ -230,18 +230,14 @@ class Omnitable extends hauntedPolymer(useOmnitable)(
230
230
  }
231
231
 
232
232
  renderItem(collapsedColumns) {
233
- return (
234
- item,
235
- index,
236
- { selected, expanded, toggleCollapse }
237
- ) => {
233
+ return (item, index, { selected, expanded, toggleCollapse }) => {
238
234
  return litHtml`
239
235
  <div class="item-row-wrapper">
240
236
  <div ?selected=${selected}
241
237
  part="itemRow itemRow-${item[indexSymbol]}"
242
238
  .dataIndex=${item[indexSymbol]}
243
239
  .dataItem=${item}
244
- class="itemRow"
240
+ class="itemRow"
245
241
  @click=${this.onItemClick}
246
242
  >
247
243
  <input class="checkbox"
@@ -268,7 +264,7 @@ class Omnitable extends hauntedPolymer(useOmnitable)(
268
264
  </div>
269
265
  <cosmoz-omnitable-item-expand .columns=${collapsedColumns}
270
266
  .item=${item}
271
- .index=${index}
267
+ .index=${index}
272
268
  ?selected=${selected}
273
269
  ?expanded=${expanded}
274
270
  .groupOnColumn=${this.groupOnColumn}
@@ -280,7 +276,7 @@ class Omnitable extends hauntedPolymer(useOmnitable)(
280
276
 
281
277
  renderGroup(item, index, { selected, folded, toggleFold }) {
282
278
  return litHtml`
283
- <div class="${this._getGroupRowClasses(folded)}"
279
+ <div class="${this._getGroupRowClasses(folded)}"
284
280
  part="groupRow groupRow-${item[indexSymbol]}">
285
281
  <input class="checkbox"
286
282
  type="checkbox"
@@ -688,5 +684,5 @@ const tmplt = `
688
684
  <slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
689
685
  `;
690
686
 
691
- export const actionSlots = litHtml([tmplt]),
692
- actionSlotsPolymer = html([tmplt]);
687
+ export const actionSlots = litHtml(Object.assign([tmplt], { raw: [tmplt] })),
688
+ actionSlotsPolymer = html(Object.assign([tmplt], { raw: [tmplt] }));
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable import/group-exports */
2
2
  import { props } from '@neovici/cosmoz-utils/lib/object';
3
3
 
4
- export const sgProps = ['sortOn', 'descending', 'groupOn', 'groupOn'];
4
+ export const sgProps = ['sortOn', 'descending', 'groupOn', 'groupOnDescending'];
5
5
 
6
6
  const byName = (name) => (item) => item.name === name;
7
7
 
@@ -13,7 +13,7 @@ const storagePrefix = 'omnitable-',
13
13
  }
14
14
  };
15
15
  // eslint-disable-next-line max-lines-per-function
16
- export default (settingsId, settings, setSettings) => {
16
+ export default (settingsId, settings, setSettings, onReset) => {
17
17
  const [counter, setCounter] = useState(0),
18
18
  savedSettings = useMemo(() => read(settingsId), [settingsId, counter]);
19
19
 
@@ -40,18 +40,22 @@ export default (settingsId, settings, setSettings) => {
40
40
  }
41
41
  }, [settings]),
42
42
 
43
- onReset: (e) => {
44
- setSettings();
43
+ onReset: useCallback(
44
+ (e) => {
45
+ setSettings();
45
46
 
46
- if (e.shiftKey) {
47
- try {
48
- localStorage.removeItem(storagePrefix + settingsId);
49
- setCounter((counter) => counter + 1);
50
- } catch (err) {
51
- // ignore error
47
+ if (e.shiftKey) {
48
+ try {
49
+ localStorage.removeItem(storagePrefix + settingsId);
50
+ setCounter((counter) => counter + 1);
51
+ } catch (err) {
52
+ // ignore error
53
+ }
52
54
  }
53
- }
54
- },
55
+ onReset?.();
56
+ },
57
+ [onReset]
58
+ ),
55
59
 
56
60
  hasChanges: settings != null,
57
61
  };
@@ -1,15 +1,24 @@
1
- import { useMemo, useState } from 'haunted';
1
+ import { useMemo, useState, useRef, useCallback } from 'haunted';
2
2
 
3
3
  import useSavedSettings from './use-saved-settings';
4
- import normalize from './normalize';
4
+ import normalize, { sgProps } from './normalize';
5
5
 
6
- export default ({ settingsId, ...thru }) => {
7
- const [settings, setSettings] = useState(),
6
+ export default ({ settingsId, initial: ini, ...thru }) => {
7
+ const initial = useMemo(
8
+ () => Object.fromEntries(sgProps.map((k) => [k, ini[k]])),
9
+ []
10
+ ),
11
+ resetRef = useRef(),
12
+ onReset = useCallback(() => {
13
+ resetRef.current?.(initial);
14
+ }, [initial]),
15
+ [settings, setSettings] = useState(),
8
16
  [opened, setOpened] = useState({ columns: true, sort: true }),
9
17
  { savedSettings, ...rest } = useSavedSettings(
10
18
  settingsId,
11
19
  settings,
12
- setSettings
20
+ setSettings,
21
+ onReset
13
22
  ),
14
23
  { columns } = thru,
15
24
  normalizedSettings = useMemo(
@@ -17,6 +26,7 @@ export default ({ settingsId, ...thru }) => {
17
26
  normalize({
18
27
  settings,
19
28
  savedSettings,
29
+ initial,
20
30
  ...thru,
21
31
  }),
22
32
  [settings, savedSettings, ...Object.values(thru)]
@@ -36,5 +46,6 @@ export default ({ settingsId, ...thru }) => {
36
46
  settings: normalizedSettings,
37
47
  columns: normalizedColumns,
38
48
  setSettings,
49
+ resetRef,
39
50
  };
40
51
  };
@@ -5,15 +5,21 @@ import { useSettings } from './settings';
5
5
  import { useDOMColumns } from './use-dom-columns';
6
6
  import { useSortAndGroupOptions } from './use-sort-and-group-options';
7
7
  import { onItemChange } from './utils-data';
8
- import { useNotifyProperty } from '@neovici/cosmoz-utils/lib/hooks/use-notify-property'
8
+ import { useNotifyProperty } from '@neovici/cosmoz-utils/lib/hooks/use-notify-property';
9
9
 
10
10
  // eslint-disable-next-line max-lines-per-function
11
11
  export const useOmnitable = (host) => {
12
12
  const { enabledColumns, hashParam, settingsId } = host,
13
13
  _columns = useDOMColumns(host, { enabledColumns }),
14
14
  settingS = useSettings({ columns: _columns, settingsId, initial: host }),
15
- { settings, setSettings, columns } = settingS,
16
- sortAndGroupOptions = useSortAndGroupOptions(columns, hashParam, settings, setSettings),
15
+ { settings, setSettings, columns, resetRef } = settingS,
16
+ sortAndGroupOptions = useSortAndGroupOptions(
17
+ columns,
18
+ hashParam,
19
+ settings,
20
+ setSettings,
21
+ resetRef
22
+ ),
17
23
  { groupOnColumn, groupOnDescending, sortOnColumn, descending } =
18
24
  sortAndGroupOptions,
19
25
  { data, resizeSpeedFactor } = host,
@@ -4,6 +4,7 @@ import {
4
4
  component,
5
5
  useContext,
6
6
  useCallback,
7
+ useEffect,
7
8
  } from 'haunted';
8
9
  import { useHashState } from './use-hash-state';
9
10
 
@@ -23,7 +24,8 @@ export const useSortAndGroupOptions = (
23
24
  columns,
24
25
  hashParam,
25
26
  settings,
26
- setSettings
27
+ setSettings,
28
+ resetRef
27
29
  ) => {
28
30
  const [sortOn, setSortOn] = useHashState(settings.sortOn, hashParam, {
29
31
  suffix: '-sortOn',
@@ -73,7 +75,16 @@ export const useSortAndGroupOptions = (
73
75
 
74
76
  columns,
75
77
  },
76
- sortAndGroup = useMemo(() => sortAndGroup_, Object.values(sortAndGroup_));
78
+ sortAndGroup = useMemo(() => sortAndGroup_, Object.values(sortAndGroup_)),
79
+ setSG = useCallback((c) => {
80
+ setSortOn(c.sortOn);
81
+ setGroupOn(c.groupOn);
82
+ setDescending(c.descending);
83
+ setGroupOnDescending(c.groupOnDescending);
84
+ }, []);
85
+
86
+ // eslint-disable-next-line no-void
87
+ useEffect(() => void (resetRef.current = setSG), []);
77
88
 
78
89
  return {
79
90
  ...sortAndGroup,
@@ -84,7 +95,6 @@ export const useSortAndGroupOptions = (
84
95
  },
85
96
  SortAndGroupContext = createContext();
86
97
 
87
-
88
98
  customElements.define('sort-and-group-provider', SortAndGroupContext.Provider);
89
99
  customElements.define(
90
100
  'sort-and-group-consumer',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-omnitable",
3
- "version": "9.0.1",
3
+ "version": "9.1.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"
@@ -70,7 +70,7 @@
70
70
  "@polymer/paper-spinner": "^3.0.0",
71
71
  "@polymer/polymer": "^3.3.0",
72
72
  "@webcomponents/shadycss": "^1.10.0",
73
- "file-saver-es": "^2.0.5",
73
+ "file-saver-es": "^2.0.0",
74
74
  "haunted": "^4.8.0",
75
75
  "lit-html": "^1.3.0"
76
76
  },
@@ -78,20 +78,19 @@
78
78
  "@commitlint/cli": "^17.0.0",
79
79
  "@commitlint/config-conventional": "^17.0.0",
80
80
  "@neovici/cfg": "^1.13.0",
81
- "@neovici/cosmoz-viewinfo": "^3.1.3",
82
- "@neovici/eslint-config": "^1.3.3",
81
+ "@neovici/cosmoz-viewinfo": "^3.1.0",
83
82
  "@open-wc/testing": "^2.5.28",
84
83
  "@polymer/iron-test-helpers": "^3.0.0",
85
- "@polymer/paper-button": "^3.0.1",
86
- "@polymer/paper-item": "^3.0.1",
87
- "@polymer/paper-listbox": "^3.0.1",
84
+ "@polymer/paper-button": "^3.0.0",
85
+ "@polymer/paper-item": "^3.0.0",
86
+ "@polymer/paper-listbox": "^3.0.0",
88
87
  "@polymer/paper-toggle-button": "^3.0.0",
89
88
  "@semantic-release/changelog": "^6.0.0",
90
89
  "@semantic-release/git": "^10.0.0",
91
90
  "@web/dev-server": "^0.1.10",
92
91
  "husky": "^8.0.0",
93
92
  "semantic-release": "^19.0.0",
94
- "sinon": "^13.0.0",
95
- "web-animations-js": "^2.3.2"
93
+ "sinon": "^14.0.0",
94
+ "web-animations-js": "^2.3.0"
96
95
  }
97
96
  }