@neovici/cosmoz-omnitable 14.1.0 → 14.1.2

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.
@@ -22,32 +22,33 @@ const /* eslint-disable-next-line max-lines-per-function */
22
22
  repeat(
23
23
  columns,
24
24
  (column) => column.name,
25
- (column) =>
25
+ (column) => [
26
26
  html`<div
27
- class="cell ${column.headerCellClass} header-cell"
28
- part="cell header-cell cell-${column.name} header-cell-${column.name}"
29
- ?hidden="${column === groupOnColumn}"
30
- title="${column.title}"
31
- name="${column.name}"
32
- >
33
- ${column.renderHeader(
34
- column,
35
- filters[column.name] ?? {},
36
- (state) => setFilterState(column.name, state),
37
- column.source(column, data),
38
- )}
39
- ${render({
40
- on,
41
- setOn,
42
- descending,
43
- setDescending,
44
- column,
45
- })}
46
- </div>
47
- <cosmoz-omnitable-resize-nub
48
- .column="${column}"
49
- name="${column.name}"
50
- ></cosmoz-omnitable-resize-nub>`,
27
+ class="cell ${column.headerCellClass} header-cell"
28
+ part="cell header-cell cell-${column.name} header-cell-${column.name}"
29
+ ?hidden="${column === groupOnColumn}"
30
+ title="${column.title}"
31
+ name="${column.name}"
32
+ >
33
+ ${column.renderHeader(
34
+ column,
35
+ filters[column.name] ?? {},
36
+ (state) => setFilterState(column.name, state),
37
+ column.source(column, data),
38
+ )}
39
+ ${render({
40
+ on,
41
+ setOn,
42
+ descending,
43
+ setDescending,
44
+ column,
45
+ })}
46
+ </div>`,
47
+ html`<cosmoz-omnitable-resize-nub
48
+ .column="${column}"
49
+ name="${column.name}"
50
+ ></cosmoz-omnitable-resize-nub>`,
51
+ ],
51
52
  );
52
53
 
53
54
  const HeaderRow = ({ columns, settingsConfig, hideSelectAll, ...thru }) => {
@@ -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
- tweenedlayout = useTweenArray(layout, resizeSpeedFactor),
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
  };
@@ -1,55 +1,61 @@
1
- import { useCallback, useEffect, useRef, useState } from '@pionjs/pion';
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 = useRef({
7
- request: undefined,
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.current.running) {
14
- return;
15
- }
16
-
17
- state.current.request = requestAnimationFrame(animate);
43
+ if (!state.tween) state.tween = state.target;
18
44
 
19
- setTween((tween) => {
20
- const target = state.current.target;
45
+ if (state.target.every((t, idx) => state.tween[idx] === t)) {
46
+ callback(state.tween);
47
+ return true;
48
+ }
21
49
 
22
- if (target.every((t, idx) => tween[idx] === t)) {
23
- state.current.running = false;
24
- return tween;
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
- return target.map((t, idx) =>
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
- useEffect(() => {
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.1.0",
3
+ "version": "14.1.2",
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"