@neovici/cosmoz-omnitable 14.1.1 → 14.2.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 +0 -2
- package/lib/use-fast-layout.js +22 -9
- package/lib/use-tween-array.js +51 -45
- package/package.json +2 -2
package/cosmoz-omnitable.js
CHANGED
|
@@ -77,8 +77,6 @@ customElements.define(
|
|
|
77
77
|
|
|
78
78
|
const tmplt = `
|
|
79
79
|
<slot name="actions" slot="actions"></slot>
|
|
80
|
-
<slot name="bottom-bar-toolbar" slot="bottom-bar-toolbar"></slot>
|
|
81
|
-
<slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
|
|
82
80
|
`;
|
|
83
81
|
|
|
84
82
|
export const actionSlots = html(Object.assign([tmplt], { raw: [tmplt] })),
|
package/lib/use-fast-layout.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { useMemo } from '@pionjs/pion';
|
|
1
|
+
import { useEffect, useMemo } from '@pionjs/pion';
|
|
2
2
|
import { toCss } from './compute-layout';
|
|
3
3
|
import { useResizableColumns } from './use-resizable-columns';
|
|
4
4
|
import { useCanvasWidth } from './use-canvas-width';
|
|
5
5
|
import { useTweenArray } from './use-tween-array';
|
|
6
6
|
import { useLayout } from './use-layout';
|
|
7
|
-
import { useStyleSheet } from '@neovici/cosmoz-utils/hooks/use-stylesheet';
|
|
8
7
|
import { useMini } from './use-mini';
|
|
8
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
9
|
+
|
|
10
|
+
const useAdoptedStyleSheet = (host) => {
|
|
11
|
+
const styleSheet = useMemo(() => new CSSStyleSheet(), []);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
host.shadowRoot.adoptedStyleSheets = [
|
|
15
|
+
...host.shadowRoot.adoptedStyleSheets,
|
|
16
|
+
styleSheet,
|
|
17
|
+
];
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return styleSheet;
|
|
21
|
+
};
|
|
9
22
|
|
|
10
23
|
export const useFastLayout = ({
|
|
11
24
|
host,
|
|
@@ -28,11 +41,7 @@ export const useFastLayout = ({
|
|
|
28
41
|
miniColumn,
|
|
29
42
|
config: settings.columns,
|
|
30
43
|
}),
|
|
31
|
-
|
|
32
|
-
layoutCss = useMemo(
|
|
33
|
-
() => toCss(tweenedlayout, settings.columns),
|
|
34
|
-
[tweenedlayout, settings.columns],
|
|
35
|
-
),
|
|
44
|
+
styleSheet = useAdoptedStyleSheet(host),
|
|
36
45
|
collapsedColumns = useMemo(
|
|
37
46
|
() =>
|
|
38
47
|
settings.columns.reduce(
|
|
@@ -47,6 +56,12 @@ export const useFastLayout = ({
|
|
|
47
56
|
[columns, settings, layout],
|
|
48
57
|
);
|
|
49
58
|
|
|
59
|
+
const meta = useMeta({ columns: settings.columns });
|
|
60
|
+
useTweenArray(layout, resizeSpeedFactor, (tweenedlayout) => {
|
|
61
|
+
const layoutCss = toCss(tweenedlayout, meta.columns);
|
|
62
|
+
styleSheet.replace(layoutCss);
|
|
63
|
+
});
|
|
64
|
+
|
|
50
65
|
useResizableColumns({
|
|
51
66
|
host,
|
|
52
67
|
canvasWidth,
|
|
@@ -54,7 +69,5 @@ export const useFastLayout = ({
|
|
|
54
69
|
setSettings: (update) => setSettings(update(settings)),
|
|
55
70
|
});
|
|
56
71
|
|
|
57
|
-
useStyleSheet(layoutCss);
|
|
58
|
-
|
|
59
72
|
return { isMini, collapsedColumns, miniColumns };
|
|
60
73
|
};
|
package/lib/use-tween-array.js
CHANGED
|
@@ -1,55 +1,61 @@
|
|
|
1
|
-
import { useCallback, useEffect,
|
|
1
|
+
import { useCallback, useEffect, useMemo } from '@pionjs/pion';
|
|
2
|
+
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
|
+
import { noop } from '@neovici/cosmoz-utils/function';
|
|
4
|
+
|
|
5
|
+
const useAnimationLoop = (animate, trigger) => {
|
|
6
|
+
const animationLoop = useMemo(() => {
|
|
7
|
+
let running = false,
|
|
8
|
+
af;
|
|
9
|
+
|
|
10
|
+
const animationLoop = () => {
|
|
11
|
+
if (!running) return;
|
|
12
|
+
af = requestAnimationFrame(animationLoop);
|
|
13
|
+
const stop = animate();
|
|
14
|
+
if (stop) running = false;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
start: () => {
|
|
19
|
+
running = true;
|
|
20
|
+
cancelAnimationFrame(af);
|
|
21
|
+
af = requestAnimationFrame(animationLoop);
|
|
22
|
+
},
|
|
23
|
+
stop: () => {
|
|
24
|
+
running = false;
|
|
25
|
+
cancelAnimationFrame(af);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
animationLoop.start();
|
|
32
|
+
}, trigger);
|
|
33
|
+
|
|
34
|
+
useEffect(() => () => animationLoop.stop(), []);
|
|
35
|
+
};
|
|
2
36
|
|
|
3
37
|
export const isCloseEnough = (a = 0, b = 0) => Math.abs(a - b) < 0.1,
|
|
4
38
|
// eslint-disable-next-line max-lines-per-function
|
|
5
|
-
useTweenArray = (target, speedFactor = 1.9) => {
|
|
6
|
-
const state =
|
|
7
|
-
|
|
8
|
-
target,
|
|
9
|
-
running: false,
|
|
10
|
-
}),
|
|
11
|
-
[tween, setTween] = useState(target),
|
|
39
|
+
useTweenArray = (target, speedFactor = 1.9, callback = noop) => {
|
|
40
|
+
const state = useMeta({ target }),
|
|
41
|
+
// [tween, setTween] = useState(target),
|
|
12
42
|
animate = useCallback(() => {
|
|
13
|
-
if (!state.
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
state.current.request = requestAnimationFrame(animate);
|
|
43
|
+
if (!state.tween) state.tween = state.target;
|
|
18
44
|
|
|
19
|
-
|
|
20
|
-
|
|
45
|
+
if (state.target.every((t, idx) => state.tween[idx] === t)) {
|
|
46
|
+
callback(state.tween);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
21
49
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
state.tween = state.target.map((t, idx) =>
|
|
51
|
+
isCloseEnough(state.tween[idx], t)
|
|
52
|
+
? t
|
|
53
|
+
: (state.tween[idx] ?? 0) +
|
|
54
|
+
((t ?? 0) - (state.tween[idx] ?? 0)) / speedFactor || 0,
|
|
55
|
+
);
|
|
26
56
|
|
|
27
|
-
|
|
28
|
-
isCloseEnough(tween[idx], t)
|
|
29
|
-
? t
|
|
30
|
-
: (tween[idx] ?? 0) +
|
|
31
|
-
((t ?? 0) - (tween[idx] ?? 0)) / speedFactor || 0,
|
|
32
|
-
);
|
|
33
|
-
});
|
|
57
|
+
callback(state.tween);
|
|
34
58
|
}, []);
|
|
35
59
|
|
|
36
|
-
|
|
37
|
-
state.current.request = requestAnimationFrame(animate);
|
|
38
|
-
return () => cancelAnimationFrame(state.current.request);
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (state.current.target.length === 0 && target.length > 0) {
|
|
43
|
-
setTween(target);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
state.current.target = target;
|
|
47
|
-
|
|
48
|
-
if (state.current.running) return;
|
|
49
|
-
|
|
50
|
-
state.current.running = true;
|
|
51
|
-
state.current.request = requestAnimationFrame(animate);
|
|
52
|
-
}, [target]);
|
|
53
|
-
|
|
54
|
-
return tween;
|
|
60
|
+
useAnimationLoop(animate, [target]);
|
|
55
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.2.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@neovici/cosmoz-autocomplete": "^10.0.0",
|
|
63
|
-
"@neovici/cosmoz-bottom-bar": "^
|
|
63
|
+
"@neovici/cosmoz-bottom-bar": "^9.0.3",
|
|
64
64
|
"@neovici/cosmoz-collapse": "^1.1.0",
|
|
65
65
|
"@neovici/cosmoz-datetime-input": "^4.0.1",
|
|
66
66
|
"@neovici/cosmoz-dropdown": "^5.0.0",
|