cynx-lib 1.3.106 → 1.3.107

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cynx-lib",
3
- "version": "1.3.106",
3
+ "version": "1.3.107",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -0,0 +1,245 @@
1
+ import React, { forwardRef, useState, useEffect, useLayoutEffect, useRef, useCallback } from 'react';
2
+ import { Pagination } from './Pagination';
3
+
4
+ const DATAVIEW_STYLES = `
5
+ .cynx-dataview-body table tbody tr.cynx-tr:hover {
6
+ background: var(--hover-bg, rgba(0, 0, 0, 0.025));
7
+ }
8
+ .cynx-dataview-body table tr > th:first-child,
9
+ .cynx-dataview-body table tr > td:first-child {
10
+ padding-left: 24px;
11
+ }
12
+ .cynx-dataview-body table tr > th:last-child,
13
+ .cynx-dataview-body table tr > td:last-child {
14
+ padding-right: 24px;
15
+ }
16
+ `;
17
+
18
+ let _dv_style_id = 'cynx-dataview-styles';
19
+ function ensureDataViewStyles() {
20
+ if (typeof document === 'undefined') return;
21
+ if (document.getElementById(_dv_style_id)) return;
22
+ const tag = document.createElement('style');
23
+ tag.id = _dv_style_id;
24
+ tag.textContent = DATAVIEW_STYLES;
25
+ document.head.appendChild(tag);
26
+ }
27
+ if (typeof document !== 'undefined') ensureDataViewStyles();
28
+
29
+ export function DataView({ children, style = {}, className = '', ...props }) {
30
+ ensureDataViewStyles();
31
+ return (
32
+ <div
33
+ className={`cynx-dataview ${className}`.trim()}
34
+ style={{
35
+ flex: 1,
36
+ display: 'flex',
37
+ flexDirection: 'column',
38
+ height: '100%',
39
+ minHeight: 0,
40
+ overflow: 'hidden',
41
+ background: 'var(--bg, #f4f4f5)',
42
+ boxSizing: 'border-box',
43
+ ...style,
44
+ }}
45
+ {...props}
46
+ >
47
+ {children}
48
+ </div>
49
+ );
50
+ }
51
+
52
+ export function DataViewHeader({ title, icon: Icon, badge, tabs, children, style = {}, className = '', ...props }) {
53
+ ensureDataViewStyles();
54
+ return (
55
+ <div
56
+ className={`cynx-dataview-header ${className}`.trim()}
57
+ style={{
58
+ flexShrink: 0,
59
+ display: 'flex',
60
+ alignItems: 'center',
61
+ justifyContent: 'space-between',
62
+ height: 52,
63
+ minHeight: 52,
64
+ padding: '0 24px',
65
+ borderBottom: '1px solid var(--border-light, #ebebf0)',
66
+ background: 'var(--bg, #f4f4f5)',
67
+ boxSizing: 'border-box',
68
+ ...style,
69
+ }}
70
+ {...props}
71
+ >
72
+ <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
73
+ {Icon && <Icon size={16} style={{ color: 'var(--primary-text, #0f111c)' }} />}
74
+ {title && (
75
+ <span style={{ fontSize: '.88rem', fontWeight: 600, color: 'var(--primary-text, #0f111c)', letterSpacing: '-.01em' }}>
76
+ {title}
77
+ </span>
78
+ )}
79
+ {badge}
80
+ {tabs && <div style={{ marginLeft: 6 }}>{tabs}</div>}
81
+ </div>
82
+ {children && (
83
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
84
+ {children}
85
+ </div>
86
+ )}
87
+ </div>
88
+ );
89
+ }
90
+
91
+ export function DataViewFilters({ children, style = {}, className = '', ...props }) {
92
+ ensureDataViewStyles();
93
+ return (
94
+ <div
95
+ className={`cynx-dataview-filters ${className}`.trim()}
96
+ style={{
97
+ flexShrink: 0,
98
+ display: 'flex',
99
+ alignItems: 'center',
100
+ gap: 8,
101
+ height: 48,
102
+ minHeight: 48,
103
+ padding: '0 24px',
104
+ borderBottom: '1px solid var(--border-light, #ebebf0)',
105
+ background: 'var(--bg, #f4f4f5)',
106
+ boxSizing: 'border-box',
107
+ ...style,
108
+ }}
109
+ {...props}
110
+ >
111
+ {children}
112
+ </div>
113
+ );
114
+ }
115
+
116
+ export const DataViewBody = forwardRef(function DataViewBody({ children, style = {}, className = '', ...props }, ref) {
117
+ ensureDataViewStyles();
118
+ return (
119
+ <div
120
+ ref={ref}
121
+ className={`cynx-dataview-body ${className}`.trim()}
122
+ style={{
123
+ flex: 1,
124
+ overflowY: 'auto',
125
+ minHeight: 0,
126
+ padding: 0,
127
+ scrollbarWidth: 'thin',
128
+ scrollbarColor: 'var(--grey-2, #d7d8e0) transparent',
129
+ background: 'var(--bg, #f4f4f5)',
130
+ boxSizing: 'border-box',
131
+ ...style,
132
+ }}
133
+ {...props}
134
+ >
135
+ {children}
136
+ </div>
137
+ );
138
+ });
139
+
140
+ export function DataViewTh({ children, style = {}, className = '', bg = 'var(--bg, #f4f4f5)', ...props }) {
141
+ ensureDataViewStyles();
142
+ return (
143
+ <th
144
+ className={className}
145
+ style={{
146
+ position: 'sticky',
147
+ top: 0,
148
+ zIndex: 10,
149
+ background: bg,
150
+ textAlign: 'left',
151
+ padding: '10px 10px',
152
+ fontSize: '.68rem',
153
+ fontWeight: 600,
154
+ textTransform: 'uppercase',
155
+ letterSpacing: '.06em',
156
+ color: 'var(--muted, #9b9daa)',
157
+ borderBottom: '1px solid var(--border-light, #ebebf0)',
158
+ boxSizing: 'border-box',
159
+ ...style,
160
+ }}
161
+ {...props}
162
+ >
163
+ {children}
164
+ </th>
165
+ );
166
+ }
167
+
168
+ export function DataViewFooter({ total = 0, page = 1, limit = 100, pages = 1, onChange, style = {}, className = '', ...props }) {
169
+ ensureDataViewStyles();
170
+ const from = total === 0 ? 0 : (page - 1) * limit + 1;
171
+ const to = Math.min(page * limit, total);
172
+ return (
173
+ <div
174
+ className={`cynx-dataview-footer ${className}`.trim()}
175
+ style={{
176
+ flexShrink: 0,
177
+ marginTop: 'auto',
178
+ display: 'flex',
179
+ alignItems: 'center',
180
+ justifyContent: 'space-between',
181
+ height: 44,
182
+ minHeight: 44,
183
+ padding: '0 24px',
184
+ borderTop: '1px solid var(--border-light, #ebebf0)',
185
+ background: 'var(--bg, #f4f4f5)',
186
+ fontSize: '.78rem',
187
+ color: 'var(--muted, #9b9daa)',
188
+ boxSizing: 'border-box',
189
+ ...style,
190
+ }}
191
+ {...props}
192
+ >
193
+ <span style={{ whiteSpace: 'nowrap', flexShrink: 0 }}>
194
+ {total === 0 ? '0 записей' : `${from}–${to} из ${total}`}
195
+ </span>
196
+ <Pagination page={page} pages={pages} onChange={onChange} size="sm" />
197
+ </div>
198
+ );
199
+ }
200
+
201
+ export function useDataViewRuler({ rowHeight = 52, minRows = 3, maxRows = 100 } = {}) {
202
+ const containerRef = useRef(null);
203
+ const [rows, setRows] = useState(15);
204
+
205
+ const calculate = useCallback(() => {
206
+ if (!containerRef.current) return;
207
+ const clientHeight = containerRef.current.clientHeight;
208
+ if (clientHeight <= 0) return;
209
+
210
+ const thead = containerRef.current.querySelector('thead');
211
+ const theadHeight = thead ? thead.offsetHeight : 37;
212
+
213
+ const firstRow = containerRef.current.querySelector('tbody tr');
214
+ const actualRowHeight = firstRow && firstRow.offsetHeight > 0 ? firstRow.offsetHeight : rowHeight;
215
+
216
+ const avail = clientHeight - theadHeight;
217
+ if (avail > 0) {
218
+ const calculated = Math.floor(avail / actualRowHeight);
219
+ const nextRows = Math.max(minRows, Math.min(maxRows, calculated));
220
+ setRows((prev) => (prev !== nextRows ? nextRows : prev));
221
+ }
222
+ }, [rowHeight, minRows, maxRows]);
223
+
224
+ useLayoutEffect(() => {
225
+ calculate();
226
+ }, [calculate]);
227
+
228
+ useEffect(() => {
229
+ if (!containerRef.current) return;
230
+ let observer = null;
231
+ if (typeof ResizeObserver !== 'undefined') {
232
+ observer = new ResizeObserver(() => {
233
+ calculate();
234
+ });
235
+ observer.observe(containerRef.current);
236
+ }
237
+ window.addEventListener('resize', calculate);
238
+ return () => {
239
+ if (observer) observer.disconnect();
240
+ window.removeEventListener('resize', calculate);
241
+ };
242
+ }, [calculate]);
243
+
244
+ return { containerRef, rows };
245
+ }
@@ -1,94 +1,94 @@
1
- import { useState, useLayoutEffect, useEffect, useRef, useCallback } from 'react';
2
-
3
- /**
4
- * Universal display and viewport measurement hook (Ruler).
5
- * Measures element rect relative to window viewport, computes remaining available height,
6
- * and dynamically calculates rows for grid / table / skeleton layouts.
7
- *
8
- * @param {Object|number} arg1 - Options object or rowHeight (for backward compatibility)
9
- * @param {number} [arg2] - initialOffset (for backward compatibility)
10
- */
11
- export function useRuler(arg1 = 51, arg2 = 240) {
12
- const isObject = arg1 && typeof arg1 === 'object' && !Array.isArray(arg1);
13
- const options = isObject ? arg1 : {};
14
- const rowHeight = isObject ? (options.rowHeight ?? 51) : (typeof arg1 === 'number' ? arg1 : 51);
15
- const initialOffset = isObject ? (options.initialOffset ?? 240) : (typeof arg2 === 'number' ? arg2 : 240);
16
- const bottomBuffer = options.bottomBuffer ?? 24;
17
- const minLimit = options.minHeight ?? 200;
18
- const maxLimit = options.maxHeight ?? null;
19
- const minRows = options.minRows ?? 3;
20
- const maxRows = options.maxRows ?? 25;
21
-
22
- const containerRef = useRef(null);
23
-
24
- const [availableHeight, setAvailableHeight] = useState(() => {
25
- if (typeof window === 'undefined') return minLimit;
26
- return Math.max(minLimit, window.innerHeight - initialOffset - bottomBuffer);
27
- });
28
-
29
- const [rows, setRows] = useState(() => {
30
- if (typeof window === 'undefined') return 8;
31
- return Math.max(minRows, Math.floor((window.innerHeight - initialOffset) / rowHeight));
32
- });
33
-
34
- const calculate = useCallback(() => {
35
- if (!containerRef.current) return;
36
- const rect = containerRef.current.getBoundingClientRect();
37
-
38
- let avail = window.innerHeight - rect.top - bottomBuffer;
39
- if (avail < minLimit) avail = minLimit;
40
- if (maxLimit && avail > maxLimit) avail = maxLimit;
41
- const roundedAvail = Math.round(avail);
42
-
43
- // Guard against infinite re-renders from subpixel fluctuations
44
- setAvailableHeight((prev) => (Math.abs(prev - roundedAvail) > 1 ? roundedAvail : prev));
45
-
46
- const thead = containerRef.current.querySelector('thead');
47
- const theadHeight = thead ? thead.offsetHeight : 0;
48
- const cardHeader =
49
- containerRef.current.firstElementChild !== thead?.parentElement &&
50
- !containerRef.current.firstElementChild?.contains(thead)
51
- ? containerRef.current.querySelector(':scope > div:first-child')
52
- : null;
53
- const cardHeaderHeight = cardHeader ? cardHeader.offsetHeight : 0;
54
-
55
- const bodyAvailable = roundedAvail - theadHeight - cardHeaderHeight;
56
- if (bodyAvailable > 0) {
57
- const calculated = Math.floor(bodyAvailable / rowHeight);
58
- const nextRows = Math.max(minRows, Math.min(maxRows, calculated));
59
- setRows((prev) => (prev !== nextRows ? nextRows : prev));
60
- }
61
- }, [rowHeight, bottomBuffer, minLimit, maxLimit, minRows, maxRows]);
62
-
63
- useLayoutEffect(() => {
64
- calculate();
65
- }, [calculate]);
66
-
67
- useEffect(() => {
68
- calculate();
69
- window.addEventListener('resize', calculate);
70
-
71
- let observer = null;
72
- if (typeof ResizeObserver !== 'undefined' && containerRef.current?.parentElement) {
73
- observer = new ResizeObserver(() => {
74
- calculate();
75
- });
76
- observer.observe(containerRef.current.parentElement);
77
- }
78
-
79
- return () => {
80
- window.removeEventListener('resize', calculate);
81
- if (observer) observer.disconnect();
82
- };
83
- }, [calculate]);
84
-
85
- return {
86
- containerRef,
87
- availableHeight,
88
- minHeight: availableHeight,
89
- rows,
90
- };
91
- }
92
-
93
- export const useAutoSkeletonRows = useRuler;
94
- export default useRuler;
1
+ import { useState, useLayoutEffect, useEffect, useRef, useCallback } from 'react';
2
+
3
+ /**
4
+ * Universal display and viewport measurement hook (Ruler).
5
+ * Measures element rect relative to window viewport, computes remaining available height,
6
+ * and dynamically calculates rows for grid / table / skeleton layouts.
7
+ *
8
+ * @param {Object|number} arg1 - Options object or rowHeight (for backward compatibility)
9
+ * @param {number} [arg2] - initialOffset (for backward compatibility)
10
+ */
11
+ export function useRuler(arg1 = 51, arg2 = 240) {
12
+ const isObject = arg1 && typeof arg1 === 'object' && !Array.isArray(arg1);
13
+ const options = isObject ? arg1 : {};
14
+ const rowHeight = isObject ? (options.rowHeight ?? 51) : (typeof arg1 === 'number' ? arg1 : 51);
15
+ const initialOffset = isObject ? (options.initialOffset ?? 240) : (typeof arg2 === 'number' ? arg2 : 240);
16
+ const bottomBuffer = options.bottomBuffer ?? 24;
17
+ const minLimit = options.minHeight ?? 200;
18
+ const maxLimit = options.maxHeight ?? null;
19
+ const minRows = options.minRows ?? 3;
20
+ const maxRows = options.maxRows ?? 25;
21
+
22
+ const containerRef = useRef(null);
23
+
24
+ const [availableHeight, setAvailableHeight] = useState(() => {
25
+ if (typeof window === 'undefined') return minLimit;
26
+ return Math.max(minLimit, window.innerHeight - initialOffset - bottomBuffer);
27
+ });
28
+
29
+ const [rows, setRows] = useState(() => {
30
+ if (typeof window === 'undefined') return 8;
31
+ return Math.max(minRows, Math.floor((window.innerHeight - initialOffset) / rowHeight));
32
+ });
33
+
34
+ const calculate = useCallback(() => {
35
+ if (!containerRef.current) return;
36
+ const rect = containerRef.current.getBoundingClientRect();
37
+
38
+ let avail = window.innerHeight - rect.top - bottomBuffer;
39
+ if (avail < minLimit) avail = minLimit;
40
+ if (maxLimit && avail > maxLimit) avail = maxLimit;
41
+ const roundedAvail = Math.round(avail);
42
+
43
+ // Guard against infinite re-renders from subpixel fluctuations
44
+ setAvailableHeight((prev) => (Math.abs(prev - roundedAvail) > 1 ? roundedAvail : prev));
45
+
46
+ const thead = containerRef.current.querySelector('thead');
47
+ const theadHeight = thead ? thead.offsetHeight : 0;
48
+ const cardHeader =
49
+ containerRef.current.firstElementChild !== thead?.parentElement &&
50
+ !containerRef.current.firstElementChild?.contains(thead)
51
+ ? containerRef.current.querySelector(':scope > div:first-child')
52
+ : null;
53
+ const cardHeaderHeight = cardHeader ? cardHeader.offsetHeight : 0;
54
+
55
+ const bodyAvailable = roundedAvail - theadHeight - cardHeaderHeight;
56
+ if (bodyAvailable > 0) {
57
+ const calculated = Math.floor(bodyAvailable / rowHeight);
58
+ const nextRows = Math.max(minRows, Math.min(maxRows, calculated));
59
+ setRows((prev) => (prev !== nextRows ? nextRows : prev));
60
+ }
61
+ }, [rowHeight, bottomBuffer, minLimit, maxLimit, minRows, maxRows]);
62
+
63
+ useLayoutEffect(() => {
64
+ calculate();
65
+ }, [calculate]);
66
+
67
+ useEffect(() => {
68
+ calculate();
69
+ window.addEventListener('resize', calculate);
70
+
71
+ let observer = null;
72
+ if (typeof ResizeObserver !== 'undefined' && containerRef.current?.parentElement) {
73
+ observer = new ResizeObserver(() => {
74
+ calculate();
75
+ });
76
+ observer.observe(containerRef.current.parentElement);
77
+ }
78
+
79
+ return () => {
80
+ window.removeEventListener('resize', calculate);
81
+ if (observer) observer.disconnect();
82
+ };
83
+ }, [calculate]);
84
+
85
+ return {
86
+ containerRef,
87
+ availableHeight,
88
+ minHeight: availableHeight,
89
+ rows,
90
+ };
91
+ }
92
+
93
+ export const useAutoSkeletonRows = useRuler;
94
+ export default useRuler;
package/ui/index.cjs CHANGED
@@ -39,6 +39,12 @@ __export(index_exports, {
39
39
  CircularProgress: () => CircularProgress,
40
40
  Confirm: () => Confirm,
41
41
  ConfirmRoot: () => ConfirmRoot,
42
+ DataView: () => DataView,
43
+ DataViewBody: () => DataViewBody,
44
+ DataViewFilters: () => DataViewFilters,
45
+ DataViewFooter: () => DataViewFooter,
46
+ DataViewHeader: () => DataViewHeader,
47
+ DataViewTh: () => DataViewTh,
42
48
  DatePicker: () => DatePicker,
43
49
  Divider: () => Divider,
44
50
  Drawer: () => Drawer,
@@ -91,6 +97,7 @@ __export(index_exports, {
91
97
  createGlobe: () => createGlobe,
92
98
  toast: () => toast,
93
99
  useAutoSkeletonRows: () => useAutoSkeletonRows,
100
+ useDataViewRuler: () => useDataViewRuler,
94
101
  useRuler: () => useRuler,
95
102
  useToast: () => useToast
96
103
  });
@@ -130,6 +137,7 @@ var import_Tabs = require("./components/Tabs.jsx");
130
137
  var import_Skeleton2 = require("./components/Skeleton.jsx");
131
138
  var import_XTable = require("./components/XTable.jsx");
132
139
  var import_Card = require("./components/Card.jsx");
140
+ var import_DataView = require("./components/DataView.jsx");
133
141
  var import_FilePicker = __toESM(require("./components/FilePicker.jsx"), 1);
134
142
  var import_Divider = __toESM(require("./components/Divider.jsx"), 1);
135
143
  var import_InfoBadge = __toESM(require("./components/InfoBadge.jsx"), 1);
@@ -205,3 +213,10 @@ const Globe = import_Globe.default || import_Globe.Globe;
205
213
  const createGlobe = import_Globe.createGlobe;
206
214
  const useRuler = import_useRuler.useRuler;
207
215
  const useAutoSkeletonRows = import_useRuler.useAutoSkeletonRows;
216
+ const DataView = import_DataView.DataView;
217
+ const DataViewHeader = import_DataView.DataViewHeader;
218
+ const DataViewFilters = import_DataView.DataViewFilters;
219
+ const DataViewBody = import_DataView.DataViewBody;
220
+ const DataViewTh = import_DataView.DataViewTh;
221
+ const DataViewFooter = import_DataView.DataViewFooter;
222
+ const useDataViewRuler = import_DataView.useDataViewRuler;
package/ui/index.js CHANGED
@@ -34,6 +34,7 @@ import { Tabs as _Tabs } from './components/Tabs.jsx';
34
34
  import { SkeletonText as _SkeletonText, SkeletonCard as _SkeletonCard, SkeletonRows as _SkeletonRows, SkeletonStats as _SkeletonStats } from './components/Skeleton.jsx';
35
35
  import { XTable as _XTable, XThead as _XThead, XTbody as _XTbody, XTr as _XTr, XTh as _XTh, XTd as _XTd, SkeletonTable as _SkeletonTable } from './components/XTable.jsx';
36
36
  import { PageShell as _PageShell, TableCard as _TableCard, TableCardFilters as _TableCardFilters, TableCardBody as _TableCardBody, TableCardFooter as _TableCardFooter, CardHdr as _CardHdr, StatCard as _StatCard, StatCardSkeleton as _StatCardSkeleton } from './components/Card.jsx';
37
+ import { DataView as _DataView, DataViewHeader as _DataViewHeader, DataViewFilters as _DataViewFilters, DataViewBody as _DataViewBody, DataViewTh as _DataViewTh, DataViewFooter as _DataViewFooter, useDataViewRuler as _useDataViewRuler } from './components/DataView.jsx';
37
38
 
38
39
  import { default as _FilePicker } from './components/FilePicker.jsx';
39
40
  import { default as _Divider } from './components/Divider.jsx';
@@ -111,3 +112,10 @@ export const Globe = _Globe || _GlobeNamed;
111
112
  export const createGlobe = _createGlobe;
112
113
  export const useRuler = _useRuler;
113
114
  export const useAutoSkeletonRows = _useAutoSkeletonRows;
115
+ export const DataView = _DataView;
116
+ export const DataViewHeader = _DataViewHeader;
117
+ export const DataViewFilters = _DataViewFilters;
118
+ export const DataViewBody = _DataViewBody;
119
+ export const DataViewTh = _DataViewTh;
120
+ export const DataViewFooter = _DataViewFooter;
121
+ export const useDataViewRuler = _useDataViewRuler;