datastake-daf 0.6.422 → 0.6.424

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": "datastake-daf",
3
- "version": "0.6.422",
3
+ "version": "0.6.424",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -1,17 +1,42 @@
1
1
  import moment from "moment";
2
2
  import PropTypes from 'prop-types';
3
- import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { formatClassname } from "../../../../../helpers/ClassesHelper";
5
5
 
6
6
  const PAGE_HEIGHT = 1587;
7
7
  const FOOTER_HEIGHT = 70;
8
8
  const HEADER_HEIGHT = 100;
9
- const PAGE_MARGIN_TOP = 20;
10
- const PAGE_MARGIN_BOTTOM = 20;
11
- const CONTENT_HEIGHT = 1200; // 1397px
12
- const SECTION_GAP = 24;
9
+ const CONTENT_HEIGHT_PER_PAGE = 1200; // Maximum content height per page
10
+ const PAGE_TOP_MARGIN = 30; // Margin at the top of content on new pages
13
11
 
14
- const isHTMLElement = (node) => node instanceof HTMLElement;
12
+ const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
13
+ const ref = useRef();
14
+ const [height, setHeight] = useState(0);
15
+
16
+ useEffect(() => {
17
+ const observer = new ResizeObserver((entries) => {
18
+ for (const entry of entries) {
19
+ setHeight(entry.contentRect.height);
20
+ }
21
+ });
22
+
23
+ observer.observe(ref.current);
24
+
25
+ return () => observer.disconnect();
26
+ }, []);
27
+
28
+ useEffect(() => {
29
+ if (height) {
30
+ onChangeHeight(i, { height, ref });
31
+ }
32
+ }, [height])
33
+
34
+ return (
35
+ <section ref={ref} style={widgets.style}>
36
+ {typeof widgets.render === 'function' ? widgets.render() : null}
37
+ </section>
38
+ )
39
+ };
15
40
 
16
41
  export default function PdfView({
17
42
  config = [],
@@ -23,224 +48,120 @@ export default function PdfView({
23
48
  documentId = 'IDD-0000000',
24
49
  downloadId = 'DWL-00000123',
25
50
  }) {
51
+ const [sectionsConfig, setSectionsConfig] = useState({});
26
52
  const [pages, setPages] = useState([1]);
27
- const contentRef = useRef(null);
28
- const sectionsRef = useRef([]);
29
53
 
30
- const resetPaginationStyles = useCallback((sections) => {
31
- sections.forEach((section) => {
32
- if (!section) return;
33
- section.style.marginTop = '';
34
- section.style.marginBottom = '';
35
- section.style.pageBreakBefore = '';
36
- section.style.breakBefore = '';
37
- section.removeAttribute('data-pdf-page');
38
-
39
- // Reset all children
40
- const allElements = section.querySelectorAll('*');
41
- allElements.forEach((el) => {
42
- if (!isHTMLElement(el)) return;
43
- el.style.marginTop = '';
44
- el.style.marginBottom = '';
45
- el.style.pageBreakBefore = '';
46
- el.style.breakBefore = '';
47
- el.removeAttribute('data-pdf-page');
54
+ const doSizing = useCallback(() => {
55
+ const keys = Object.keys(sectionsConfig);
56
+ let _pages = [1];
57
+ let _page = 1;
58
+
59
+ if (keys.length === config.length) {
60
+ // Reset all margins and padding first
61
+ keys.forEach(k => {
62
+ const { ref } = sectionsConfig[k];
63
+ ref.current.style.marginTop = '0px';
64
+ ref.current.style.marginBottom = '0px';
65
+ ref.current.style.paddingBottom = '0px';
48
66
  });
49
- });
50
- }, []);
51
67
 
52
- const getAllBreakableElements = useCallback((section) => {
53
- const elements = [];
54
-
55
- const shouldInclude = (el) => {
56
- if (!isHTMLElement(el)) return false;
57
- const style = window.getComputedStyle(el);
58
- if (style.display === 'inline' || style.display === 'contents') return false;
59
- if (style.position === 'absolute' || style.position === 'fixed') return false;
60
- if (el.offsetHeight === 0) return false;
61
- return true;
62
- };
68
+ let currentPageHeight = 0; // Track height accumulated on current page
69
+ const sectionGap = 24; // Gap between sections
63
70
 
64
- const traverse = (parent) => {
65
- Array.from(parent.children).forEach((child) => {
66
- if (shouldInclude(child)) {
67
- elements.push(child);
68
- traverse(child);
69
- }
70
- });
71
- };
71
+ keys.forEach((k, i) => {
72
+ const { height, ref } = sectionsConfig[k];
73
+ const isFirstSection = i === 0;
74
+ const isLastSection = i === keys.length - 1;
72
75
 
73
- traverse(section);
74
- return elements;
75
- }, []);
76
-
77
- const paginateContent = useCallback(() => {
78
- const sections = sectionsRef.current.filter(Boolean);
79
- if (sections.length === 0) return;
80
-
81
- resetPaginationStyles(sections);
76
+ // First section on first page needs header space
77
+ if (isFirstSection) {
78
+ ref.current.style.marginTop = `${HEADER_HEIGHT}px`;
79
+ currentPageHeight = 0; // Content height tracking starts fresh
80
+ }
82
81
 
83
- // Force layout recalc
84
- sections.forEach(s => s.offsetHeight);
82
+ // Check if this section would exceed the page content limit
83
+ const willExceedPageLimit = currentPageHeight + height > CONTENT_HEIGHT_PER_PAGE;
85
84
 
86
- let currentPage = 1;
87
- let currentPageHeight = 0;
88
- const breaks = [];
85
+ if (willExceedPageLimit && !isFirstSection) {
86
+ // Need to break to a new page
87
+ _page += 1;
88
+ _pages.push(_page);
89
89
 
90
- sections.forEach((section, sectionIndex) => {
91
- // Measure height after reset
92
- const sectionHeight = section.offsetHeight;
93
- const isFirstOnPage = currentPageHeight === 0;
94
- const gapBefore = isFirstOnPage ? 0 : SECTION_GAP;
95
-
96
- if (currentPageHeight + gapBefore + sectionHeight <= CONTENT_HEIGHT) {
97
- // Fits in current page
98
- section.setAttribute('data-pdf-page', currentPage.toString());
99
-
100
- if (isFirstOnPage) {
101
- // First item on page
102
- if (currentPage === 1) {
103
- // Very first section on first page - needs to be below header
104
- section.style.marginTop = '0px'; // Container padding handles this
105
- } else {
106
- // First section on subsequent pages - no margin (container padding handles it)
107
- section.style.marginTop = '0px';
108
- }
109
- } else {
110
- // Not first item on page - add gap
111
- section.style.marginTop = `${SECTION_GAP}px`;
112
- }
113
- currentPageHeight += gapBefore + sectionHeight;
114
- } else {
115
- // Doesn't fit - need to move to next page
116
- const remainingSpace = CONTENT_HEIGHT - currentPageHeight;
117
-
118
- // Calculate margin needed to push this section to the next page
119
- // remainingSpace = space left on current page
120
- // Then we need to skip: footer margin + footer + header margin + header
121
- const pushMargin = remainingSpace + PAGE_MARGIN_BOTTOM + FOOTER_HEIGHT + PAGE_MARGIN_TOP + HEADER_HEIGHT;
122
-
123
- // Move entire section to next page
124
- currentPage += 1;
125
- breaks.push({ section, type: 'section', page: currentPage });
126
- section.setAttribute('data-pdf-page', currentPage.toString());
127
- section.style.pageBreakBefore = 'always';
128
- section.style.breakBefore = 'page';
129
- section.style.marginTop = `${pushMargin}px`;
130
-
131
- // Start fresh height counter for new page
132
- currentPageHeight = sectionHeight;
133
-
134
- // Check if section is too tall and needs internal breaks
135
- if (sectionHeight > CONTENT_HEIGHT) {
136
- // Try to break within section
137
- const innerElements = getAllBreakableElements(section);
138
- let pageHeightInSection = 0;
139
- let sectionPage = currentPage;
90
+ // Calculate remaining space on current page
91
+ const remainingSpace = PAGE_HEIGHT - currentPageHeight - HEADER_HEIGHT - FOOTER_HEIGHT;
140
92
 
141
- for (const el of innerElements) {
142
- const rect = el.getBoundingClientRect();
143
- const sectionRect = section.getBoundingClientRect();
144
- const relativeTop = rect.top - sectionRect.top;
145
- const elHeight = rect.height;
146
-
147
- // Check if this element would exceed the page
148
- if (pageHeightInSection + elHeight > CONTENT_HEIGHT && relativeTop > 50) {
149
- // Calculate remaining space on this page within the section
150
- const remainingInSection = CONTENT_HEIGHT - pageHeightInSection;
151
- const pushMarginInner = remainingInSection + PAGE_MARGIN_BOTTOM + FOOTER_HEIGHT + PAGE_MARGIN_TOP + HEADER_HEIGHT;
152
-
153
- sectionPage += 1;
154
- breaks.push({ element: el, type: 'inner', page: sectionPage });
155
- el.setAttribute('data-pdf-page', sectionPage.toString());
156
- el.style.pageBreakBefore = 'always';
157
- el.style.breakBefore = 'page';
158
- el.style.marginTop = `${pushMarginInner}px`;
159
-
160
- // Reset page height for new page within section
161
- pageHeightInSection = elHeight;
162
- } else {
163
- pageHeightInSection += elHeight;
164
- }
93
+ // Add margin to previous section to push current section to next page
94
+ if (sectionsConfig[keys[i - 1]]) {
95
+ const { ref: prevRef } = sectionsConfig[keys[i - 1]];
96
+ prevRef.current.style.marginBottom = `${remainingSpace}px`;
165
97
  }
98
+
99
+ // Position this section at the top of the new page
100
+ ref.current.style.marginTop = `${HEADER_HEIGHT + PAGE_TOP_MARGIN}px`;
166
101
 
167
- // Update current page if we created additional pages
168
- if (sectionPage > currentPage) {
169
- currentPage = sectionPage;
170
- currentPageHeight = pageHeightInSection;
171
- }
102
+ // Reset page height counter for new page
103
+ currentPageHeight = height + sectionGap;
104
+ } else {
105
+ // Section fits on current page
106
+ currentPageHeight += height + sectionGap;
172
107
  }
173
- }
174
- });
175
108
 
176
- setPages(Array.from({ length: currentPage }, (_, idx) => idx + 1));
177
- }, [getAllBreakableElements, resetPaginationStyles]);
109
+ // Add padding to last section
110
+ if (isLastSection) {
111
+ ref.current.style.paddingBottom = `${PAGE_TOP_MARGIN}px`;
112
+ }
113
+ });
178
114
 
179
- useLayoutEffect(() => {
180
- // Use requestAnimationFrame to ensure DOM is painted
181
- const rafId = requestAnimationFrame(() => {
182
- paginateContent();
183
- });
184
-
185
- return () => cancelAnimationFrame(rafId);
186
- }, [paginateContent, config]);
115
+ setPages(_pages);
116
+ }
117
+ }, [sectionsConfig, config.length]);
187
118
 
188
119
  useEffect(() => {
189
- const sections = sectionsRef.current.filter(Boolean);
190
- if (sections.length === 0) return undefined;
191
-
192
- const observer = new ResizeObserver(() => {
193
- paginateContent();
194
- });
120
+ doSizing();
121
+ }, [doSizing]);
195
122
 
196
- sections.forEach(section => observer.observe(section));
197
-
198
- return () => observer.disconnect();
199
- }, [paginateContent, config.length]);
123
+ const onChangeHeight = useCallback((index, conf) => {
124
+ setSectionsConfig((prev) => ({ ...prev, [index]: conf }))
125
+ }, []);
200
126
 
201
127
  const contClassName = formatClassname(['daf-analysis daf-pdf-view', customClassName]);
202
128
 
203
- return (
204
- <div className={contClassName} style={{ position: 'relative', minHeight: `${PAGE_HEIGHT}px` }}>
129
+ const renderDashboard = useCallback(() => {
130
+ return (
205
131
  <div className="view-content">
206
132
  <div className="daf-analysis-layout">
207
- <div
208
- className='sections-cont'
209
- ref={contentRef}
210
- data-pdf-content-root="true"
211
- style={{
212
- marginTop: `${HEADER_HEIGHT + PAGE_MARGIN_TOP}px`,
213
- // paddingBottom: `${FOOTER_HEIGHT + PAGE_MARGIN_BOTTOM}px !important`,
214
- position: 'relative',
215
- }}
216
- >
217
- {config.map((widgets, index) => (
218
- <section
219
- key={`dashboard-section-${index + 1}`}
220
- ref={(el) => {
221
- sectionsRef.current[index] = el;
222
- }}
223
- style={widgets.style}
224
- data-pdf-section="true"
225
- >
226
- {typeof widgets.render === 'function' ? widgets.render() : null}
227
- </section>
133
+ <div className='sections-cont'>
134
+ {config.map((widgets, i) => (
135
+ <Row
136
+ widgets={widgets}
137
+ key={`dashboard-sections=${i + 1}`}
138
+ i={i}
139
+ onChangeHeight={onChangeHeight}
140
+ />
228
141
  ))}
229
142
  </div>
230
143
  </div>
231
144
  </div>
145
+ );
146
+ }, [config, onChangeHeight]);
147
+
148
+ // <div className="daf-analysis">
149
+ // <Header title={t('Dashboard Title')} />
150
+
151
+ // <div className="content">
152
+ // <div className="view-content">
153
+ // <div className="daf-analysis-layout">
154
+ // <div className='sections-cont w-pt'>
155
+ // <section>
156
+
157
+ return (
158
+ <div className={contClassName} style={{ position: 'relative' }}>
159
+ {renderDashboard()}
232
160
  {pages.map((page) => (
233
- <Fragment key={`pdf-decor-${page}`}>
161
+ <>
234
162
  <div
235
- style={{
236
- top: ((page - 1) * PAGE_HEIGHT) + PAGE_MARGIN_TOP,
237
- width: '100%',
238
- height: HEADER_HEIGHT,
239
- position: 'absolute',
240
- left: 0,
241
- zIndex: 1000000,
242
- pointerEvents: 'none'
243
- }}
163
+ style={{ top: ((page - 1) * PAGE_HEIGHT), width: '100%', height: HEADER_HEIGHT - 24, position: 'absolute', left: 0, zIndex: 1000000 }}
164
+ key={`headers-${page}`}
244
165
  className="flex-row dashboard-header"
245
166
  >
246
167
  <div className="flex flex-column justify-center flex-1">
@@ -251,15 +172,8 @@ export default function PdfView({
251
172
  </div>
252
173
  </div>
253
174
  <div
254
- style={{
255
- top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT - PAGE_MARGIN_BOTTOM,
256
- width: '100%',
257
- height: FOOTER_HEIGHT,
258
- position: 'absolute',
259
- left: 0,
260
- zIndex: 1000000,
261
- pointerEvents: 'none'
262
- }}
175
+ style={{ top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT, width: '100%', height: FOOTER_HEIGHT, position: 'absolute', left: 0, zIndex: 1000000 }}
176
+ key={`footers-${page}`}
263
177
  className="dashboard-footer flex-row"
264
178
  >
265
179
  <div className="flex flex-column justify-center">
@@ -293,7 +207,7 @@ export default function PdfView({
293
207
  <h5>{page}</h5>
294
208
  </div>
295
209
  </div>
296
- </Fragment>
210
+ </>
297
211
  ))}
298
212
  </div>
299
213
  );
@@ -0,0 +1,16 @@
1
+ const config = {
2
+ viewBox: "0 0 11 10",
3
+ children: (
4
+ <>
5
+ <path d="M4.55036 5.13086H3.04412C2.90368 6.64626 1.90846 7.86667 0.666504 8.04569V10C1.1941 9.95303 1.70415 9.78769 2.1747 9.51827V7.7727L2.28734 7.76259C3.45566 7.65494 4.40651 6.53623 4.55036 5.13086Z" fill="#016C6E" />
6
+ <path d="M5.87407 1.32153C6.21589 0.903428 6.605 0.560262 7.02679 0.296791V0.000610352C5.995 0.09339 5.02903 0.633415 4.29468 1.53147C3.55985 2.43013 3.12002 3.61069 3.04736 4.86976H4.55653C4.62968 3.531 5.09388 2.2755 5.87407 1.32153Z" fill="#016C6E" />
7
+ <path d="M6.34668 5.64589C6.37058 5.47579 6.38813 5.30391 6.39789 5.13025H4.79607C4.78144 5.28845 4.75706 5.44368 4.72439 5.59474C4.65807 5.90044 4.55714 6.18948 4.42597 6.45533C4.00174 7.31355 3.26788 7.92315 2.41846 8.04567V9.99999C2.99677 9.94825 3.55411 9.75555 4.06172 9.43856V7.77269L4.17436 7.76257C4.17436 7.76257 4.17485 7.76257 4.17533 7.76257C5.1964 7.66801 6.05119 6.80147 6.3462 5.64648L6.34668 5.64589Z" fill="#016C6E" />
8
+ <path d="M7.14889 0.554894C7.10793 0.580468 7.06746 0.607231 7.02699 0.633995C6.67054 0.872486 6.33994 1.17343 6.04688 1.53146C5.57779 2.10539 5.22964 2.7941 5.01947 3.54526C4.93902 3.83252 4.87904 4.1287 4.84052 4.43142C4.82199 4.57654 4.80785 4.72284 4.79956 4.87034H6.40138C6.4199 4.6711 6.45355 4.47662 6.50036 4.28928C6.60471 3.55715 6.82804 2.8613 7.15718 2.23861C7.19375 2.16902 7.23178 2.10122 7.27079 2.03342C7.41708 1.78185 7.58043 1.54335 7.76182 1.32152C8.06658 0.948613 8.40938 0.633994 8.77948 0.383608V0C8.25188 0.0469846 7.74183 0.212323 7.27128 0.481741C7.23032 0.504936 7.18985 0.52932 7.14938 0.5543L7.14889 0.554894Z" fill="#016C6E" />
9
+ <path d="M6.58478 5.71192C6.517 5.98431 6.42094 6.24184 6.30099 6.47973C6.21809 6.64388 6.12447 6.79852 6.02012 6.94244C5.58809 7.53956 4.98394 7.94756 4.30615 8.04569V10C5.33795 9.90723 6.30391 9.3672 7.03826 8.46914C7.7731 7.57049 8.21293 6.38993 8.28558 5.13086H6.68376C6.66524 5.3301 6.63159 5.52458 6.58478 5.71192Z" fill="#016C6E" />
10
+ <path d="M9.02269 0.562626C8.98173 0.5882 8.94126 0.615558 8.90078 0.642916C8.85982 0.670869 8.81935 0.699417 8.77888 0.728559C8.47412 0.950992 8.18984 1.21922 7.93384 1.53206C7.56813 1.9793 7.27556 2.49673 7.06491 3.05876C7.00299 3.2235 6.94935 3.39241 6.90156 3.56429C6.83037 3.82121 6.77576 4.08588 6.73821 4.35529C6.71432 4.52539 6.69676 4.69727 6.68701 4.87034H8.28883C8.42926 3.35494 9.42448 2.13453 10.6664 1.95551V0.00119019C10.0881 0.0529327 9.53078 0.245629 9.02269 0.562626Z" fill="#016C6E" />
11
+ </>
12
+ ),
13
+ tag: ["logo"],
14
+ };
15
+
16
+ export default config;
@@ -209,6 +209,7 @@ import Hedera01 from "./Hedera01";
209
209
  import Records from "./Records";
210
210
  import Lightning from "./Lightning";
211
211
  import MagicWand from "./MagicWant";
212
+ import Straatos from "./Straatos";
212
213
 
213
214
  const config = {
214
215
  Right,
@@ -422,6 +423,7 @@ const config = {
422
423
  Records,
423
424
  Lightning,
424
425
  MagicWand,
426
+ Straatos,
425
427
  };
426
428
 
427
429
  export default config;