@onesy/ui-react 1.0.144 → 1.0.146

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.
@@ -129,7 +129,6 @@ const useStyle = (0, _styleReact.style)(theme => ({
129
129
  });
130
130
  const TableCell = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
131
131
  const theme = (0, _styleReact.useOnesyTheme)();
132
- const windowWidth = (0, _useResize.default)();
133
132
  const l = theme.l;
134
133
  const props = _react.default.useMemo(() => {
135
134
  var _theme$ui, _theme$ui2;
@@ -181,13 +180,19 @@ const TableCell = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
181
180
  const {
182
181
  classes
183
182
  } = useStyle();
183
+ const windowWidth = (0, _useResize.default)();
184
184
  const [root, setRoot] = _react.default.useState();
185
185
  const [stickyActive, setStickyActive] = _react.default.useState(false);
186
186
  const [offset, setOffset] = _react.default.useState(0);
187
187
  const [sortedBy, setSortedBy] = _react.default.useState(sortedByDefault);
188
188
  const refs = {
189
- root: _react.default.useRef(undefined)
189
+ root: _react.default.useRef(undefined),
190
+ offset: _react.default.useRef(null),
191
+ observer: _react.default.useRef(null),
192
+ sticky: _react.default.useRef(sticky)
190
193
  };
194
+ refs.root.current = root;
195
+ refs.sticky.current = sticky;
191
196
  const init = _react.default.useCallback(() => {
192
197
  setTimeout(() => {
193
198
  if (sticky) {
@@ -214,34 +219,67 @@ const TableCell = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
214
219
  _react.default.useEffect(() => {
215
220
  if (sortedBy !== sortedBy_) setSortedBy(sortedBy_);
216
221
  }, [sortedBy_]);
217
- _react.default.useEffect(() => {
218
- if (sticky) {
219
- if (root) {
220
- let offsetOriginal = root.offsetLeft;
221
- const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
222
- root.style.position = 'unset';
223
- offsetOriginal = root.offsetLeft;
224
- root.style.position = 'sticky';
225
- const method = () => {
226
- const offsetNew = root.offsetLeft;
227
- setStickyActive(offsetOriginal !== offsetNew);
228
- };
222
+ const onStickyMove = _react.default.useCallback(() => {
223
+ const offsetNew = refs.root.current.offsetLeft;
224
+ setStickyActive(refs.offset.current !== offsetNew);
225
+ }, []);
226
+ const onStickyInit = _react.default.useCallback(() => {
227
+ if (refs.sticky.current && refs.root.current) {
228
+ refs.root.current.style.position = 'unset';
229
+ refs.offset.current = refs.root.current.offsetLeft;
230
+ refs.root.current.style.position = 'sticky';
231
+ onStickyMove();
232
+ }
233
+ }, []);
234
+ const onObserve = _react.default.useCallback(() => {
235
+ var _refs$root$current2;
236
+ const element = (_refs$root$current2 = refs.root.current) === null || _refs$root$current2 === void 0 ? void 0 : _refs$root$current2.closest('table');
237
+
238
+ // clean up
239
+ if (refs.observer.current) refs.observer.current.disconnect();
240
+ if (!element) return;
229
241
 
230
- // initial
231
- method();
232
- setTimeout(() => {
233
- root.style.position = 'unset';
234
- offsetOriginal = root.offsetLeft;
235
- root.style.position = 'sticky';
236
- method();
237
- }, timeout);
238
- if (parentOverflow) parentOverflow.addEventListener('scroll', method, {
239
- passive: false
240
- });
241
- return () => {
242
- if (parentOverflow) parentOverflow.removeEventListener('scroll', method);
243
- };
242
+ // init
243
+ const config = {
244
+ childList: true,
245
+ subtree: true,
246
+ attributes: true,
247
+ attributeFilter: ['data-*'],
248
+ characterData: true
249
+ };
250
+ const method = mutations => {
251
+ for (const mutation of mutations) {
252
+ switch (mutation.type) {
253
+ case 'childList':
254
+ case 'attributes':
255
+ case 'characterData':
256
+ onStickyInit();
257
+ break;
258
+ }
244
259
  }
260
+ };
261
+ refs.observer.current = new MutationObserver(method);
262
+ refs.observer.current.observe(element, config);
263
+ return refs.observer.current;
264
+ }, []);
265
+ _react.default.useEffect(() => {
266
+ if (root && sticky) {
267
+ onStickyInit();
268
+ setTimeout(() => {
269
+ onStickyInit();
270
+ }, 250);
271
+
272
+ // observer
273
+ onObserve();
274
+
275
+ // scroll
276
+ const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
277
+ if (parentOverflow) parentOverflow.addEventListener('scroll', onStickyMove, {
278
+ passive: false
279
+ });
280
+ return () => {
281
+ if (parentOverflow) parentOverflow.removeEventListener('scroll', onStickyMove);
282
+ };
245
283
  }
246
284
  }, [timeout, windowWidth, sticky, stickyPosition, root]);
247
285
  const onSort = _react.default.useCallback(() => {
@@ -15,6 +15,7 @@ var _Surface = _interopRequireDefault(require("../Surface"));
15
15
  var _utils2 = require("../utils");
16
16
  var _TableRow = _interopRequireDefault(require("../TableRow"));
17
17
  var _LinearProgress = _interopRequireDefault(require("../LinearProgress"));
18
+ var _useResize = _interopRequireDefault(require("../useResize"));
18
19
  const _excluded = ["tonal", "color", "size", "sticky", "stickyOffset", "timeout", "loading", "LinearGradientProps", "TableRowLoaderProps", "Component", "className", "style", "children"];
19
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -83,43 +84,82 @@ const TableHead = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
83
84
  const {
84
85
  classes
85
86
  } = useStyle();
87
+ const windowWidth = (0, _useResize.default)();
86
88
  const [root, setRoot] = _react.default.useState();
87
89
  const [stickyActive, setStickyActive] = _react.default.useState(false);
88
90
  const refs = {
89
- root: _react.default.useRef(undefined)
91
+ root: _react.default.useRef(undefined),
92
+ offset: _react.default.useRef(null),
93
+ observer: _react.default.useRef(null),
94
+ sticky: _react.default.useRef(sticky)
90
95
  };
96
+ refs.root.current = root;
97
+ refs.sticky.current = sticky;
91
98
  const styleOther = {};
92
99
  if (sticky && stickyOffset !== undefined) styleOther.top = stickyOffset;
93
- _react.default.useEffect(() => {
94
- if (sticky) {
95
- if (root) {
96
- let offsetOriginal = root.offsetTop;
97
- const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
98
- root.style.position = 'unset';
99
- offsetOriginal = root.offsetTop;
100
- root.style.position = 'sticky';
101
- const method = () => {
102
- const offsetNew = root.offsetTop;
103
- setStickyActive(offsetOriginal !== offsetNew);
104
- };
100
+ const onStickyMove = _react.default.useCallback(() => {
101
+ const offsetNew = refs.root.current.offsetLeft;
102
+ setStickyActive(refs.offset.current !== offsetNew);
103
+ }, []);
104
+ const onStickyInit = _react.default.useCallback(() => {
105
+ if (refs.sticky.current && refs.root.current) {
106
+ refs.root.current.style.position = 'unset';
107
+ refs.offset.current = refs.root.current.offsetLeft;
108
+ refs.root.current.style.position = 'sticky';
109
+ onStickyMove();
110
+ }
111
+ }, []);
112
+ const onObserve = _react.default.useCallback(() => {
113
+ var _refs$root$current;
114
+ const element = (_refs$root$current = refs.root.current) === null || _refs$root$current === void 0 ? void 0 : _refs$root$current.closest('table');
115
+
116
+ // clean up
117
+ if (refs.observer.current) refs.observer.current.disconnect();
118
+ if (!element) return;
105
119
 
106
- // initial
107
- method();
108
- setTimeout(() => {
109
- root.style.position = 'unset';
110
- offsetOriginal = root.offsetTop;
111
- root.style.position = 'sticky';
112
- method();
113
- }, timeout);
114
- if (parentOverflow) parentOverflow.addEventListener('scroll', method, {
115
- passive: false
116
- });
117
- return () => {
118
- if (parentOverflow) parentOverflow.removeEventListener('scroll', method);
119
- };
120
+ // init
121
+ const config = {
122
+ childList: true,
123
+ subtree: true,
124
+ attributes: true,
125
+ attributeFilter: ['data-*'],
126
+ characterData: true
127
+ };
128
+ const method = mutations => {
129
+ for (const mutation of mutations) {
130
+ switch (mutation.type) {
131
+ case 'childList':
132
+ case 'attributes':
133
+ case 'characterData':
134
+ onStickyInit();
135
+ break;
136
+ }
120
137
  }
138
+ };
139
+ refs.observer.current = new MutationObserver(method);
140
+ refs.observer.current.observe(element, config);
141
+ return refs.observer.current;
142
+ }, []);
143
+ _react.default.useEffect(() => {
144
+ if (root && sticky) {
145
+ onStickyInit();
146
+ setTimeout(() => {
147
+ onStickyInit();
148
+ }, 250);
149
+
150
+ // observer
151
+ onObserve();
152
+
153
+ // scroll
154
+ const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
155
+ if (parentOverflow) parentOverflow.addEventListener('scroll', onStickyMove, {
156
+ passive: false
157
+ });
158
+ return () => {
159
+ if (parentOverflow) parentOverflow.removeEventListener('scroll', onStickyMove);
160
+ };
121
161
  }
122
- }, [timeout, sticky, root]);
162
+ }, [timeout, windowWidth, sticky, root]);
123
163
  return /*#__PURE__*/_react.default.createElement(Surface, (0, _extends2.default)({
124
164
  ref: item => {
125
165
  if (ref) {
@@ -122,7 +122,6 @@ const useStyle = styleMethod(theme => ({
122
122
  });
123
123
  const TableCell = /*#__PURE__*/React.forwardRef((props_, ref) => {
124
124
  const theme = useOnesyTheme();
125
- const windowWidth = useResize();
126
125
  const l = theme.l;
127
126
  const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyTableCell?.props?.default), props_), [props_]);
128
127
  const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]);
@@ -159,13 +158,19 @@ const TableCell = /*#__PURE__*/React.forwardRef((props_, ref) => {
159
158
  const {
160
159
  classes
161
160
  } = useStyle();
161
+ const windowWidth = useResize();
162
162
  const [root, setRoot] = React.useState();
163
163
  const [stickyActive, setStickyActive] = React.useState(false);
164
164
  const [offset, setOffset] = React.useState(0);
165
165
  const [sortedBy, setSortedBy] = React.useState(sortedByDefault);
166
166
  const refs = {
167
- root: React.useRef(undefined)
167
+ root: React.useRef(undefined),
168
+ offset: React.useRef(null),
169
+ observer: React.useRef(null),
170
+ sticky: React.useRef(sticky)
168
171
  };
172
+ refs.root.current = root;
173
+ refs.sticky.current = sticky;
169
174
  const init = React.useCallback(() => {
170
175
  setTimeout(() => {
171
176
  if (sticky) {
@@ -191,34 +196,66 @@ const TableCell = /*#__PURE__*/React.forwardRef((props_, ref) => {
191
196
  React.useEffect(() => {
192
197
  if (sortedBy !== sortedBy_) setSortedBy(sortedBy_);
193
198
  }, [sortedBy_]);
194
- React.useEffect(() => {
195
- if (sticky) {
196
- if (root) {
197
- let offsetOriginal = root.offsetLeft;
198
- const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
199
- root.style.position = 'unset';
200
- offsetOriginal = root.offsetLeft;
201
- root.style.position = 'sticky';
202
- const method = () => {
203
- const offsetNew = root.offsetLeft;
204
- setStickyActive(offsetOriginal !== offsetNew);
205
- };
199
+ const onStickyMove = React.useCallback(() => {
200
+ const offsetNew = refs.root.current.offsetLeft;
201
+ setStickyActive(refs.offset.current !== offsetNew);
202
+ }, []);
203
+ const onStickyInit = React.useCallback(() => {
204
+ if (refs.sticky.current && refs.root.current) {
205
+ refs.root.current.style.position = 'unset';
206
+ refs.offset.current = refs.root.current.offsetLeft;
207
+ refs.root.current.style.position = 'sticky';
208
+ onStickyMove();
209
+ }
210
+ }, []);
211
+ const onObserve = React.useCallback(() => {
212
+ const element = refs.root.current?.closest('table');
213
+
214
+ // clean up
215
+ if (refs.observer.current) refs.observer.current.disconnect();
216
+ if (!element) return;
206
217
 
207
- // initial
208
- method();
209
- setTimeout(() => {
210
- root.style.position = 'unset';
211
- offsetOriginal = root.offsetLeft;
212
- root.style.position = 'sticky';
213
- method();
214
- }, timeout);
215
- if (parentOverflow) parentOverflow.addEventListener('scroll', method, {
216
- passive: false
217
- });
218
- return () => {
219
- if (parentOverflow) parentOverflow.removeEventListener('scroll', method);
220
- };
218
+ // init
219
+ const config = {
220
+ childList: true,
221
+ subtree: true,
222
+ attributes: true,
223
+ attributeFilter: ['data-*'],
224
+ characterData: true
225
+ };
226
+ const method = mutations => {
227
+ for (const mutation of mutations) {
228
+ switch (mutation.type) {
229
+ case 'childList':
230
+ case 'attributes':
231
+ case 'characterData':
232
+ onStickyInit();
233
+ break;
234
+ }
221
235
  }
236
+ };
237
+ refs.observer.current = new MutationObserver(method);
238
+ refs.observer.current.observe(element, config);
239
+ return refs.observer.current;
240
+ }, []);
241
+ React.useEffect(() => {
242
+ if (root && sticky) {
243
+ onStickyInit();
244
+ setTimeout(() => {
245
+ onStickyInit();
246
+ }, 250);
247
+
248
+ // observer
249
+ onObserve();
250
+
251
+ // scroll
252
+ const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
253
+ if (parentOverflow) parentOverflow.addEventListener('scroll', onStickyMove, {
254
+ passive: false
255
+ });
256
+ return () => {
257
+ if (parentOverflow) parentOverflow.removeEventListener('scroll', onStickyMove);
258
+ };
222
259
  }
223
260
  }, [timeout, windowWidth, sticky, stickyPosition, root]);
224
261
  const onSort = React.useCallback(() => {
@@ -11,6 +11,7 @@ import SurfaceElement from '../Surface';
11
11
  import { staticClassName } from '../utils';
12
12
  import TableRowElement from '../TableRow';
13
13
  import LinearProgressElement from '../LinearProgress';
14
+ import useResize from '../useResize';
14
15
  const useStyle = styleMethod(theme => ({
15
16
  root: {
16
17
  display: 'table-header-group',
@@ -64,43 +65,81 @@ const TableHead = /*#__PURE__*/React.forwardRef((props_, ref) => {
64
65
  const {
65
66
  classes
66
67
  } = useStyle();
68
+ const windowWidth = useResize();
67
69
  const [root, setRoot] = React.useState();
68
70
  const [stickyActive, setStickyActive] = React.useState(false);
69
71
  const refs = {
70
- root: React.useRef(undefined)
72
+ root: React.useRef(undefined),
73
+ offset: React.useRef(null),
74
+ observer: React.useRef(null),
75
+ sticky: React.useRef(sticky)
71
76
  };
77
+ refs.root.current = root;
78
+ refs.sticky.current = sticky;
72
79
  const styleOther = {};
73
80
  if (sticky && stickyOffset !== undefined) styleOther.top = stickyOffset;
74
- React.useEffect(() => {
75
- if (sticky) {
76
- if (root) {
77
- let offsetOriginal = root.offsetTop;
78
- const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
79
- root.style.position = 'unset';
80
- offsetOriginal = root.offsetTop;
81
- root.style.position = 'sticky';
82
- const method = () => {
83
- const offsetNew = root.offsetTop;
84
- setStickyActive(offsetOriginal !== offsetNew);
85
- };
81
+ const onStickyMove = React.useCallback(() => {
82
+ const offsetNew = refs.root.current.offsetLeft;
83
+ setStickyActive(refs.offset.current !== offsetNew);
84
+ }, []);
85
+ const onStickyInit = React.useCallback(() => {
86
+ if (refs.sticky.current && refs.root.current) {
87
+ refs.root.current.style.position = 'unset';
88
+ refs.offset.current = refs.root.current.offsetLeft;
89
+ refs.root.current.style.position = 'sticky';
90
+ onStickyMove();
91
+ }
92
+ }, []);
93
+ const onObserve = React.useCallback(() => {
94
+ const element = refs.root.current?.closest('table');
95
+
96
+ // clean up
97
+ if (refs.observer.current) refs.observer.current.disconnect();
98
+ if (!element) return;
86
99
 
87
- // initial
88
- method();
89
- setTimeout(() => {
90
- root.style.position = 'unset';
91
- offsetOriginal = root.offsetTop;
92
- root.style.position = 'sticky';
93
- method();
94
- }, timeout);
95
- if (parentOverflow) parentOverflow.addEventListener('scroll', method, {
96
- passive: false
97
- });
98
- return () => {
99
- if (parentOverflow) parentOverflow.removeEventListener('scroll', method);
100
- };
100
+ // init
101
+ const config = {
102
+ childList: true,
103
+ subtree: true,
104
+ attributes: true,
105
+ attributeFilter: ['data-*'],
106
+ characterData: true
107
+ };
108
+ const method = mutations => {
109
+ for (const mutation of mutations) {
110
+ switch (mutation.type) {
111
+ case 'childList':
112
+ case 'attributes':
113
+ case 'characterData':
114
+ onStickyInit();
115
+ break;
116
+ }
101
117
  }
118
+ };
119
+ refs.observer.current = new MutationObserver(method);
120
+ refs.observer.current.observe(element, config);
121
+ return refs.observer.current;
122
+ }, []);
123
+ React.useEffect(() => {
124
+ if (root && sticky) {
125
+ onStickyInit();
126
+ setTimeout(() => {
127
+ onStickyInit();
128
+ }, 250);
129
+
130
+ // observer
131
+ onObserve();
132
+
133
+ // scroll
134
+ const parentOverflow = window.document.querySelector('.onesy-Table-wrapper');
135
+ if (parentOverflow) parentOverflow.addEventListener('scroll', onStickyMove, {
136
+ passive: false
137
+ });
138
+ return () => {
139
+ if (parentOverflow) parentOverflow.removeEventListener('scroll', onStickyMove);
140
+ };
102
141
  }
103
- }, [timeout, sticky, root]);
142
+ }, [timeout, windowWidth, sticky, root]);
104
143
  return /*#__PURE__*/React.createElement(Surface, _extends({
105
144
  ref: item => {
106
145
  if (ref) {
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.143
1
+ /** @license UiReact v1.0.145
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.143
1
+ /** @license UiReact v1.0.145
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onesy/ui-react",
3
- "version": "1.0.144",
3
+ "version": "1.0.146",
4
4
  "description": "UI for React",
5
5
  "repository": "https://github.com/onesy-me/onesy.git",
6
6
  "author": "Lazar Erić <lazareric1@proton.me>",