@neovici/cosmoz-omnitable 8.7.2 → 8.8.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.
@@ -97,7 +97,7 @@ const checkbox = css`
97
97
  var(--primary-color)
98
98
  );
99
99
  }
100
- .sort[data-sort='desc'] {
100
+ .sort:not([data-sort='desc']) {
101
101
  transform: scaleY(-1);
102
102
  }
103
103
  :not(:hover) > * > .sort:not([data-sort]) {
@@ -0,0 +1,84 @@
1
+ import { html } from 'haunted';
2
+ import { _ } from '@neovici/cosmoz-i18next';
3
+ import { without } from '@neovici/cosmoz-utils/lib/array';
4
+
5
+ const direction = (descending) =>
6
+ `(${descending ? _('Descending') : _('Ascending')})`,
7
+ values = (columns, groupOn) => {
8
+ const value = columns.find((column) => column.name === groupOn);
9
+ return [
10
+ value,
11
+ columns
12
+ ?.filter?.((c) => c['groupOn'])
13
+ /* eslint-disable-next-line no-bitwise */
14
+ .sort((a, b) => ((b.name === value) >> 0) - ((a.name === value) >> 0)),
15
+ ];
16
+ },
17
+ onSelect = (newVal, { value, onChange, onText, limit }) => {
18
+ onText('');
19
+ onChange([...without(newVal)(value), newVal].slice(-limit));
20
+ },
21
+ onChange = ({ setGroupOn, setGroupOnDescending }) => {
22
+ return (val, close) => {
23
+ const value = (val[0] ?? val)?.name ?? '',
24
+ setter = setGroupOn,
25
+ directionSetter = setGroupOnDescending;
26
+
27
+ setter((oldValue) => {
28
+ if (value) {
29
+ directionSetter((oldDirection) =>
30
+ value === oldValue ? !oldDirection : false
31
+ );
32
+ } else {
33
+ directionSetter(null);
34
+ }
35
+ return value;
36
+ });
37
+
38
+ value && close(); /* eslint-disable-line no-unused-expressions */
39
+ };
40
+ };
41
+
42
+ export default () => html`
43
+ <sort-and-group-consumer
44
+ style="display: contents"
45
+ .render=${({
46
+ columns,
47
+ groupOnDescending,
48
+ groupOn,
49
+ setGroupOn,
50
+ setGroupOnDescending,
51
+ } = {}) => {
52
+ const [groupOnColumn, source] = values(columns, groupOn);
53
+ return html` <div class="group">
54
+ <cosmoz-autocomplete
55
+ .label="${_('Group on')} ${direction(groupOnDescending)}"
56
+ .placeholder=${_('No grouping')}
57
+ .source=${source}
58
+ .value=${groupOnColumn}
59
+ limit="1"
60
+ text-property="title"
61
+ always-float-label
62
+ .itemHeight=${48}
63
+ .itemLimit=${8}
64
+ .onChange=${onChange({ setGroupOn, setGroupOnDescending })}
65
+ .onSelect=${onSelect}
66
+ default-index="-1"
67
+ show-single
68
+ >
69
+ <svg
70
+ slot="suffix"
71
+ viewBox="0 0 24 24"
72
+ preserveAspectRatio="xMidYMid meet"
73
+ focusable="false"
74
+ width="24"
75
+ fill="currentColor"
76
+ >
77
+ <path d="M7 10l5 5 5-5z"></path>
78
+ </svg>
79
+ </cosmoz-autocomplete>
80
+ </div>`;
81
+ }}
82
+ >
83
+ </sort-and-group-consumer>
84
+ `;
@@ -5,6 +5,7 @@ import { nothing } from 'lit-html';
5
5
  import { isEmpty } from '@neovici/cosmoz-utils/lib/template';
6
6
  import { defaultPlacement } from '@neovici/cosmoz-dropdown';
7
7
  import sort from './cosmoz-omnitable-sort';
8
+ import group from './cosmoz-omnitable-group';
8
9
 
9
10
  const placement = ['bottom-right', ...defaultPlacement],
10
11
  settingsStyles = `
@@ -67,7 +68,6 @@ const placement = ['bottom-right', ...defaultPlacement],
67
68
  .buttons {
68
69
  display: flex;
69
70
  gap: 8px;
70
- margin-top: 10px;
71
71
  padding: 12px 14px;
72
72
  box-shadow: inset 0px 1px 0px rgba(0, 0, 0, 0.15);
73
73
  }
@@ -96,6 +96,10 @@ const placement = ['bottom-right', ...defaultPlacement],
96
96
  color: inherit;
97
97
  text-decoration: underline;
98
98
  }
99
+ .group {
100
+ padding: 0px 14px;
101
+ box-shadow: inset 0px 1px 0px rgb(0 0 0 / 15%)
102
+ }
99
103
  `,
100
104
  parseIndex = (str) => {
101
105
  const idx = parseInt(str, 10);
@@ -279,26 +283,23 @@ const placement = ['bottom-right', ...defaultPlacement],
279
283
  useSettings(host);
280
284
  return [
281
285
  html`
282
- <style>
283
- ${settingsStyles}
284
- </style>
286
+ <style>${settingsStyles}</style>
285
287
  <div class="list">${settings?.map(renderItem(thru))}</div>
286
288
  `,
287
- settingsId
288
- ? html`<div class="buttons">
289
- <button
290
- class="button reset"
291
- @click=${onReset}
292
- ?disabled=${!hasChanges}
293
- >
294
- Reset
295
- </button>
296
- <button class="button" @click=${onSave} ?disabled=${!hasChanges}>
297
- Save
298
- </button>
299
- </div>`
300
- : nothing,
301
- ];
289
+ group(),
290
+ settingsId && html`<div class="buttons">
291
+ <button
292
+ class="button reset"
293
+ @click=${onReset}
294
+ ?disabled=${!hasChanges}
295
+ >
296
+ Reset
297
+ </button>
298
+ <button class="button" @click=${onSave} ?disabled=${!hasChanges}>
299
+ Save
300
+ </button>
301
+ </div>`
302
+ ].filter(Boolean);
302
303
  },
303
304
  // eslint-disable-next-line max-lines-per-function
304
305
  Settings = ({
@@ -42,6 +42,8 @@ export const useSortAndGroupOptions = (columns, hashParam, initial) => {
42
42
  setSortOn,
43
43
  descending,
44
44
  setDescending,
45
+
46
+ columns,
45
47
  },
46
48
  sortAndGroup = useMemo(() => sortAndGroup_, Object.values(sortAndGroup_));
47
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-omnitable",
3
- "version": "8.7.2",
3
+ "version": "8.8.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"