@neovici/cosmoz-omnitable 10.1.0 → 11.1.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.
- package/cosmoz-omnitable.js +2 -2
- package/lib/cosmoz-omnitable-date-input-mixin.js +1 -1
- package/lib/settings/cosmoz-omnitable-settings.js +1 -1
- package/lib/settings/drivers/context.js +13 -0
- package/lib/settings/drivers/index.js +3 -0
- package/lib/settings/drivers/local.js +29 -0
- package/lib/settings/drivers/remote.js +22 -0
- package/lib/settings/normalize.js +1 -1
- package/lib/settings/use-saved-settings.js +20 -38
- package/lib/settings/use-settings-ui.js +2 -1
- package/lib/use-hash-state.js +1 -1
- package/lib/use-omnitable.js +1 -1
- package/lib/utils-date.js +1 -1
- package/lib/utils-datetime.js +1 -1
- package/lib/utils-time.js +1 -1
- package/package.json +5 -5
package/cosmoz-omnitable.js
CHANGED
|
@@ -21,12 +21,12 @@ import { html as litHtml } from 'lit-html';
|
|
|
21
21
|
|
|
22
22
|
import { translatable } from '@neovici/cosmoz-i18next';
|
|
23
23
|
import { mixin, hauntedPolymer } from '@neovici/cosmoz-utils';
|
|
24
|
-
import { isEmpty } from '@neovici/cosmoz-utils/
|
|
24
|
+
import { isEmpty } from '@neovici/cosmoz-utils/template';
|
|
25
25
|
import { useOmnitable } from './lib/use-omnitable';
|
|
26
26
|
import { saveAsCsvAction } from './lib/save-as-csv-action';
|
|
27
27
|
import { saveAsXlsxAction } from './lib/save-as-xlsx-action';
|
|
28
28
|
import { defaultPlacement } from '@neovici/cosmoz-dropdown';
|
|
29
|
-
import { without } from '@neovici/cosmoz-utils/
|
|
29
|
+
import { without } from '@neovici/cosmoz-utils/array';
|
|
30
30
|
import { indexSymbol } from './lib/utils';
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html, component } from 'haunted';
|
|
2
2
|
import { nothing } from 'lit-html';
|
|
3
3
|
import { _ } from '@neovici/cosmoz-i18next';
|
|
4
|
-
import { isEmpty } from '@neovici/cosmoz-utils/
|
|
4
|
+
import { isEmpty } from '@neovici/cosmoz-utils/template';
|
|
5
5
|
import { defaultPlacement } from '@neovici/cosmoz-dropdown';
|
|
6
6
|
import '@neovici/cosmoz-collapse';
|
|
7
7
|
import sort from './cosmoz-omnitable-sort';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo } from 'haunted';
|
|
2
|
+
import local from './local';
|
|
3
|
+
|
|
4
|
+
export const DriverContext = createContext(local),
|
|
5
|
+
useDriver = () => {
|
|
6
|
+
const driver = useContext(DriverContext);
|
|
7
|
+
return useMemo(() => driver(), [driver]);
|
|
8
|
+
},
|
|
9
|
+
registerProvider = () =>
|
|
10
|
+
customElements.define(
|
|
11
|
+
'omnitable-settings-driver-provider',
|
|
12
|
+
DriverContext.Provider
|
|
13
|
+
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default ({ prefix = 'omnitable-' } = {}) => {
|
|
2
|
+
const read = async (settingsId) => {
|
|
3
|
+
if (!settingsId) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(localStorage.getItem(prefix + settingsId));
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.error(e);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
write: async (settingsId, settings) => {
|
|
15
|
+
const key = prefix + settingsId;
|
|
16
|
+
try {
|
|
17
|
+
if (settings) {
|
|
18
|
+
localStorage.setItem(key, JSON.stringify(settings));
|
|
19
|
+
} else {
|
|
20
|
+
localStorage.removeItem(key);
|
|
21
|
+
}
|
|
22
|
+
} catch (e) {
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
read,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default ({ prefix = '', get$, post$ } = {}) => {
|
|
2
|
+
const read = async (settingsId) => {
|
|
3
|
+
try {
|
|
4
|
+
return await get$(prefix + settingsId);
|
|
5
|
+
} catch (e) {
|
|
6
|
+
// eslint-disable-next-line no-console
|
|
7
|
+
console.error(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
write: async (settingsId, settings) => {
|
|
12
|
+
const key = prefix + settingsId;
|
|
13
|
+
try {
|
|
14
|
+
await post$(key, settings);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.error(e);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
read,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,62 +1,44 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useEffect, useState } from 'haunted';
|
|
2
2
|
import { normalizeStore } from './normalize';
|
|
3
|
+
import { useDriver } from './drivers';
|
|
3
4
|
|
|
4
|
-
const storagePrefix = 'omnitable-',
|
|
5
|
-
read = (settingsId) => {
|
|
6
|
-
if (!settingsId) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(localStorage.getItem(storagePrefix + settingsId)) ?? [];
|
|
11
|
-
} catch (e) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
5
|
// eslint-disable-next-line max-lines-per-function
|
|
16
6
|
export default (settingsId, settings, setSettings, onReset) => {
|
|
17
|
-
const [
|
|
18
|
-
|
|
7
|
+
const [savedSettings, setSavedSettings] = useState(),
|
|
8
|
+
{ read, write } = useDriver();
|
|
9
|
+
|
|
10
|
+
useEffect(async () => {
|
|
11
|
+
if (!settingsId) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
setSavedSettings(await read(settingsId));
|
|
15
|
+
}, [settingsId, read]);
|
|
19
16
|
|
|
20
17
|
return {
|
|
21
18
|
settingsId,
|
|
22
19
|
savedSettings,
|
|
23
20
|
|
|
24
|
-
onSave: useCallback(() => {
|
|
21
|
+
onSave: useCallback(async () => {
|
|
25
22
|
if (!settingsId) {
|
|
26
23
|
return;
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
JSON.stringify(normalizeStore(settings, current))
|
|
34
|
-
);
|
|
35
|
-
setSettings();
|
|
36
|
-
setCounter((counter) => counter + 1);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.error(e);
|
|
40
|
-
}
|
|
41
|
-
}, [settings]),
|
|
25
|
+
const newSettings = normalizeStore(settings, savedSettings);
|
|
26
|
+
await write(settingsId, newSettings);
|
|
27
|
+
setSettings();
|
|
28
|
+
setSavedSettings(newSettings);
|
|
29
|
+
}, [settings, savedSettings]),
|
|
42
30
|
|
|
43
31
|
onReset: useCallback(
|
|
44
|
-
(e) => {
|
|
32
|
+
async (e) => {
|
|
45
33
|
setSettings();
|
|
46
|
-
|
|
47
34
|
if (e.shiftKey) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setCounter((counter) => counter + 1);
|
|
51
|
-
} catch (err) {
|
|
52
|
-
// ignore error
|
|
53
|
-
}
|
|
35
|
+
await write(settingsId);
|
|
36
|
+
setSavedSettings();
|
|
54
37
|
}
|
|
55
38
|
onReset?.();
|
|
56
39
|
},
|
|
57
40
|
[onReset]
|
|
58
41
|
),
|
|
59
|
-
|
|
60
42
|
hasChanges: settings != null,
|
|
61
43
|
};
|
|
62
44
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback } from 'haunted';
|
|
2
|
-
import { useMeta } from '@neovici/cosmoz-utils/
|
|
2
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
3
|
|
|
4
4
|
const parseIndex = (str) => {
|
|
5
5
|
const idx = parseInt(str, 10);
|
|
@@ -47,6 +47,7 @@ export default (host) => {
|
|
|
47
47
|
meta.handle = null;
|
|
48
48
|
e.dataTransfer.effectAllowed = 'move';
|
|
49
49
|
e.dataTransfer.setData('omnitable/sort-index', index);
|
|
50
|
+
e.dataTransfer.setData('text/plain', index);
|
|
50
51
|
setTimeout(() => target.classList.add('drag'), 0);
|
|
51
52
|
target.addEventListener(
|
|
52
53
|
'dragend',
|
package/lib/use-hash-state.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useState } from 'haunted';
|
|
2
2
|
import { navigate } from '@neovici/cosmoz-router';
|
|
3
|
-
import { identity } from '@neovici/cosmoz-utils/
|
|
3
|
+
import { identity } from '@neovici/cosmoz-utils/function';
|
|
4
4
|
import { invoke } from './invoke';
|
|
5
5
|
|
|
6
6
|
const
|
package/lib/use-omnitable.js
CHANGED
|
@@ -5,7 +5,7 @@ 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/
|
|
8
|
+
import { useNotifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property';
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line max-lines-per-function
|
|
11
11
|
export const useOmnitable = (host) => {
|
package/lib/utils-date.js
CHANGED
package/lib/utils-datetime.js
CHANGED
package/lib/utils-time.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toLocalISOString } from '@neovici/cosmoz-utils/
|
|
1
|
+
import { toLocalISOString } from '@neovici/cosmoz-utils/date';
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
3
|
import { getAbsoluteISOString, renderValue, toDate as superToDate } from './utils-date';
|
|
4
4
|
import { toNumber } from './utils-number';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@neovici/cosmoz-autocomplete": "^
|
|
62
|
+
"@neovici/cosmoz-autocomplete": "^5.0.0",
|
|
63
63
|
"@neovici/cosmoz-bottom-bar": "^6.0.0",
|
|
64
64
|
"@neovici/cosmoz-collapse": "^1.1.0",
|
|
65
65
|
"@neovici/cosmoz-datetime-input": "^3.0.3",
|
|
66
|
-
"@neovici/cosmoz-dropdown": "^
|
|
67
|
-
"@neovici/cosmoz-grouped-list": "^
|
|
66
|
+
"@neovici/cosmoz-dropdown": "^3.0.0",
|
|
67
|
+
"@neovici/cosmoz-grouped-list": "^6.0.0",
|
|
68
68
|
"@neovici/cosmoz-i18next": "^3.1.1",
|
|
69
69
|
"@neovici/cosmoz-router": "^10.0.0",
|
|
70
|
-
"@neovici/cosmoz-utils": "^
|
|
70
|
+
"@neovici/cosmoz-utils": "^5.0.0",
|
|
71
71
|
"@neovici/nullxlsx": "^3.0.0",
|
|
72
72
|
"@polymer/iron-icon": "^3.0.0",
|
|
73
73
|
"@polymer/iron-icons": "^3.0.0",
|