@neovici/cosmoz-omnitable 8.7.1 → 8.8.0
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.
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { component } from 'haunted';
|
|
2
2
|
import { nothing } from 'lit-html';
|
|
3
3
|
|
|
4
|
-
const GroupRow = ({ column, item, selected, folded }) => {
|
|
4
|
+
const GroupRow = ({ column, item, selected, folded, group }) => {
|
|
5
5
|
if (!column) {
|
|
6
6
|
return nothing;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
return (column.renderGroup ?? column.renderCell)(column, { item, selected, folded });
|
|
9
|
+
return (column.renderGroup ?? column.renderCell)(column, { item, selected, folded, group });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
customElements.define('cosmoz-omnitable-group-row', component(GroupRow, { useShadowDOM: false }));
|
package/cosmoz-omnitable.js
CHANGED
|
@@ -121,8 +121,9 @@ class Omnitable extends hauntedPolymer(useOmnitable)(mixin({ isEmpty }, translat
|
|
|
121
121
|
<input class="checkbox" type="checkbox" checked="[[ selected ]]" on-input="_onCheckboxChange" disabled$="[[ !_dataIsValid ]]" />
|
|
122
122
|
<h3 class="groupRow-label">
|
|
123
123
|
<div><span>[[ groupOnColumn.title ]]</span>: </div>
|
|
124
|
-
<cosmoz-omnitable-group-row column="[[ groupOnColumn ]]" item="[[ item.items.0 ]]" selected="[[ selected ]]" folded="[[ folded ]]"
|
|
125
|
-
|
|
124
|
+
<cosmoz-omnitable-group-row column="[[ groupOnColumn ]]" item="[[ item.items.0 ]]" selected="[[ selected ]]" folded="[[ folded ]]"
|
|
125
|
+
group="[[ item ]]"
|
|
126
|
+
></cosmoz-omnitable-group-row>
|
|
126
127
|
</h3>
|
|
127
128
|
<div class="groupRow-badge">[[ item.items.length ]]</div>
|
|
128
129
|
<paper-icon-button class="fold" icon="[[ _getFoldIcon(folded) ]]" on-tap="_toggleGroup"></paper-icon-button>
|
|
@@ -0,0 +1,79 @@
|
|
|
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, type, value) => {
|
|
8
|
+
return (
|
|
9
|
+
columns
|
|
10
|
+
?.filter?.((c) => c[type])
|
|
11
|
+
/* eslint-disable-next-line no-bitwise */
|
|
12
|
+
.sort((a, b) => ((b === value) >> 0) - ((a === value) >> 0))
|
|
13
|
+
);
|
|
14
|
+
},
|
|
15
|
+
onSelect = (newVal, { value, onChange, onText, limit }) => {
|
|
16
|
+
onText('');
|
|
17
|
+
onChange([...without(newVal)(value), newVal].slice(-limit));
|
|
18
|
+
},
|
|
19
|
+
onChange = ({ setGroupOn, setGroupOnDescending }) => {
|
|
20
|
+
return (val, close) => {
|
|
21
|
+
const value = (val[0] ?? val)?.name ?? '',
|
|
22
|
+
setter = setGroupOn,
|
|
23
|
+
directionSetter = setGroupOnDescending;
|
|
24
|
+
|
|
25
|
+
setter((oldValue) => {
|
|
26
|
+
if (value) {
|
|
27
|
+
directionSetter((oldDirection) =>
|
|
28
|
+
value === oldValue ? !oldDirection : false
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
directionSetter(null);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
value && close(); /* eslint-disable-line no-unused-expressions */
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default () => html`
|
|
41
|
+
<sort-and-group-consumer
|
|
42
|
+
style="display: contents"
|
|
43
|
+
.render=${({
|
|
44
|
+
columns,
|
|
45
|
+
groupOnDescending,
|
|
46
|
+
groupOnColumn,
|
|
47
|
+
setGroupOn,
|
|
48
|
+
setGroupOnDescending,
|
|
49
|
+
} = {}) => html` <div class="group">
|
|
50
|
+
<cosmoz-autocomplete
|
|
51
|
+
.label="${_('Group on')} ${direction(groupOnDescending)}"
|
|
52
|
+
.placeholder=${_('No grouping')}
|
|
53
|
+
.source=${values(columns, 'groupOn', groupOnColumn)}
|
|
54
|
+
.value=${groupOnColumn}
|
|
55
|
+
limit="1"
|
|
56
|
+
text-property="title"
|
|
57
|
+
always-float-label
|
|
58
|
+
.itemHeight=${48}
|
|
59
|
+
.itemLimit=${8}
|
|
60
|
+
.onChange=${onChange({ setGroupOn, setGroupOnDescending })}
|
|
61
|
+
.onSelect=${onSelect}
|
|
62
|
+
default-index="-1"
|
|
63
|
+
show-single
|
|
64
|
+
>
|
|
65
|
+
<svg
|
|
66
|
+
slot="suffix"
|
|
67
|
+
viewBox="0 0 24 24"
|
|
68
|
+
preserveAspectRatio="xMidYMid meet"
|
|
69
|
+
focusable="false"
|
|
70
|
+
width="24"
|
|
71
|
+
fill="currentColor"
|
|
72
|
+
>
|
|
73
|
+
<path d="M7 10l5 5 5-5z"></path>
|
|
74
|
+
</svg>
|
|
75
|
+
</cosmoz-autocomplete>
|
|
76
|
+
</div>`}
|
|
77
|
+
>
|
|
78
|
+
</sort-and-group-consumer>
|
|
79
|
+
`;
|
|
@@ -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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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 = ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|