datastake-daf 0.6.302 → 0.6.304

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.
@@ -13274,23 +13274,6 @@ const PAGE_HEIGHT = 1587;
13274
13274
  // margin-top: 20, bottom: 20;
13275
13275
  const FOOTER_HEIGHT = 70;
13276
13276
  const HEADER_HEIGHT = 100;
13277
- const HEADER_CONTENT_OFFSET = HEADER_HEIGHT - 24;
13278
- const printFlags = ["puppeteer=true", "headless=true", "pdf=true"];
13279
- const isHeadlessEnvironment = () => {
13280
- if (typeof window === "undefined") return false;
13281
- const matchesPrint = typeof window.matchMedia === "function" && window.matchMedia("print").matches;
13282
- const search = typeof window.location !== "undefined" ? window.location.search : "";
13283
- const hasUrlFlag = printFlags.some(flag => {
13284
- var _search$includes;
13285
- return search === null || search === void 0 || (_search$includes = search.includes) === null || _search$includes === void 0 ? void 0 : _search$includes.call(search, flag);
13286
- });
13287
- let bodyFlag = false;
13288
- if (typeof document !== "undefined" && document.body) {
13289
- bodyFlag = document.body.getAttribute("data-puppeteer") === "true";
13290
- }
13291
- const webdriverFlag = typeof navigator !== "undefined" && navigator.webdriver && typeof navigator.userAgent === "string" && navigator.userAgent.includes("HeadlessChrome");
13292
- return Boolean(matchesPrint || hasUrlFlag || bodyFlag || webdriverFlag);
13293
- };
13294
13277
  const Row = _ref => {
13295
13278
  let {
13296
13279
  widgets,
@@ -13340,51 +13323,42 @@ function PdfView(_ref2) {
13340
13323
  let _pages = [1];
13341
13324
  let _page = 1;
13342
13325
  if (keys.length === config.length) {
13343
- const headless = isHeadlessEnvironment();
13344
- const headerOffset = headless ? 0 : HEADER_CONTENT_OFFSET;
13345
- const sectionGap = headless ? 16 : 24;
13346
- const maxContentHeight = headless ? PAGE_HEIGHT - FOOTER_HEIGHT - headerOffset : PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT;
13347
13326
  let incrHeight = 0;
13348
13327
  keys.forEach(k => {
13349
13328
  const {
13350
13329
  ref
13351
13330
  } = sectionsConfig[k];
13352
- if (ref !== null && ref !== void 0 && ref.current) {
13353
- ref.current.style.marginBottom = '0px';
13354
- ref.current.style.marginTop = '0px';
13355
- }
13331
+ ref.current.style.marginBottom = '0px';
13332
+ // ref.current.style.marginTop = '15px';
13356
13333
  });
13357
13334
  keys.forEach((k, i) => {
13358
13335
  const {
13359
13336
  height,
13360
13337
  ref
13361
13338
  } = sectionsConfig[k];
13362
- if (!(ref !== null && ref !== void 0 && ref.current)) return;
13363
13339
  if (i === 0) {
13364
- ref.current.style.marginTop = "".concat(headerOffset, "px");
13365
- incrHeight += headerOffset;
13340
+ ref.current.style.marginTop = "".concat(HEADER_HEIGHT, "px");
13341
+ incrHeight += HEADER_HEIGHT;
13366
13342
  }
13367
13343
  const newHeight = incrHeight + height;
13368
13344
  if (i === keys.length - 1) {
13369
13345
  ref.current.style.paddingBottom = '30px';
13370
13346
  }
13371
- if (newHeight > maxContentHeight && i !== 0) {
13347
+ if (newHeight > PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT) {
13372
13348
  const dif = Math.abs(PAGE_HEIGHT - incrHeight);
13373
- ref.current.style.marginTop = headless ? '16px' : '30px';
13349
+ ref.current.style.marginTop = '30px';
13374
13350
  _page += 1;
13375
13351
  _pages.push(_page);
13376
13352
  if (sectionsConfig[keys[i - 1]]) {
13377
13353
  const {
13378
13354
  ref: topRef
13379
13355
  } = sectionsConfig[keys[i - 1]];
13380
- if (topRef !== null && topRef !== void 0 && topRef.current) {
13381
- const spacing = Math.max(dif + headerOffset - sectionGap, headerOffset);
13382
- topRef.current.style.marginBottom = "".concat(spacing, "px");
13383
- }
13384
- incrHeight = height + sectionGap + headerOffset;
13356
+ topRef.current.style.marginBottom = "".concat(dif + HEADER_HEIGHT - 24, "px");
13357
+ incrHeight = height + 24 + HEADER_HEIGHT;
13358
+ // console.log('margin', dif);
13385
13359
  }
13386
13360
  } else {
13387
- incrHeight = newHeight + sectionGap;
13361
+ incrHeight = newHeight + 24;
13388
13362
  }
13389
13363
  // console.groupEnd();
13390
13364
  });
@@ -15459,439 +15433,35 @@ const PdfForm = _ref3 => {
15459
15433
  return organizedSections;
15460
15434
  };
15461
15435
  const organizedForm = React.useMemo(() => organizeFormByHeaders(form), [form]);
15462
-
15463
- // Constants for height calculations (same as PdfView)
15464
- const PAGE_HEIGHT = 1587;
15465
- const FOOTER_HEIGHT = 70;
15466
- const HEADER_HEIGHT = 100;
15467
-
15468
- // Detect if running in headless/Puppeteer environment (more conservative detection)
15469
- const isPuppeteerEnvironment = () => {
15470
- if (typeof window === 'undefined') return false;
15471
-
15472
- // Only trigger on explicit URL parameters (most reliable)
15473
- return window.location.search.includes('puppeteer=true') || window.location.search.includes('headless=true') || window.location.search.includes('pdf=true') ||
15474
- // Only very specific headless browser indicators
15475
- window.navigator.webdriver === true && window.navigator.userAgent.includes('HeadlessChrome');
15476
- };
15477
-
15478
- // Debug function to log detection results (can be removed later)
15479
- const debugEnvironment = () => {
15480
- if (typeof window !== 'undefined' && window.console) {
15481
- console.log('Environment Detection:', {
15482
- isPuppeteer: isPuppeteerEnvironment(),
15483
- userAgent: window.navigator.userAgent,
15484
- webdriver: window.navigator.webdriver,
15485
- resizeObserver: !!window.ResizeObserver,
15486
- urlParams: window.location.search
15487
- });
15488
- }
15489
- };
15490
-
15491
- // Balanced height estimation that prevents over-splitting while ensuring content fits
15492
- const estimateTreeNodeHeight = function (key, config, value) {
15493
- let level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
15494
- const isPuppeteer = isPuppeteerEnvironment();
15495
- // Call debug only once to avoid spam
15496
- if (level === 0 && key === Object.keys(form)[0]) {
15497
- debugEnvironment();
15498
- }
15499
-
15500
- // More accurate base heights that align better with PdfView's ResizeObserver measurements
15501
- const baseHeight = isPuppeteer ? 48 : 38; // More accurate base heights to match actual rendering
15502
- const indentHeight = level * (isPuppeteer ? 4 : 3.5); // More accurate indent space
15503
- let totalHeight = baseHeight + indentHeight;
15504
-
15505
- // Reasonable type-based adjustments based on actual rendered heights
15506
- if ((config === null || config === void 0 ? void 0 : config.type) === 'header') {
15507
- totalHeight += isPuppeteer ? 25 : 18; // Headers with reasonable padding
15508
- } else if ((config === null || config === void 0 ? void 0 : config.type) === 'textarea') {
15509
- totalHeight += isPuppeteer ? 60 : 45; // Textareas with multiline content
15510
- } else if ((config === null || config === void 0 ? void 0 : config.type) === 'dataLink' || (config === null || config === void 0 ? void 0 : config.type) === 'dataLinkGroup') {
15511
- totalHeight += isPuppeteer ? 35 : 25; // Data links with formatted content
15512
- } else if ((config === null || config === void 0 ? void 0 : config.type) === 'groupInputs') {
15513
- totalHeight += isPuppeteer ? 45 : 35; // Group inputs with structured layout
15514
- } else if ((config === null || config === void 0 ? void 0 : config.type) === 'ajaxSubGroup') {
15515
- totalHeight += isPuppeteer ? 50 : 40; // Ajax content with loading states
15516
- }
15517
-
15518
- // More accurate content height estimation that better matches actual DOM measurements
15519
- if (value && typeof value === 'string') {
15520
- const cleanValue = value.trim();
15521
- if (cleanValue.length > 150) {
15522
- // Long text: be more generous with line estimates
15523
- const estimatedLines = Math.ceil(cleanValue.length / 45); // Shorter assumed line length
15524
- const lineHeight = isPuppeteer ? 20 : 18; // Slightly taller line height
15525
- totalHeight += estimatedLines * lineHeight;
15526
- } else if (cleanValue.length > 60) {
15527
- // Medium text: likely spans 2-3 lines
15528
- totalHeight += isPuppeteer ? 35 : 28;
15529
- } else if (cleanValue.length > 15) {
15530
- // Short-medium text: single to double line
15531
- totalHeight += isPuppeteer ? 18 : 14;
15532
- } else if (cleanValue.length > 0) {
15533
- // Very short text: single line with padding
15534
- totalHeight += isPuppeteer ? 12 : 10;
15535
- }
15536
- }
15537
-
15538
- // Add height for children recursively with balanced multiplier
15539
- if (config !== null && config !== void 0 && config.inputs) {
15540
- const childKeys = Object.keys(config.inputs).filter(childKey => {
15541
- const childConfig = config.inputs[childKey];
15542
- // Check showIf condition
15543
- if (childConfig !== null && childConfig !== void 0 && childConfig.showIf && !evaluateShowIfCondition(childConfig.showIf, data)) {
15544
- return false;
15545
- }
15546
- return true;
15547
- }).sort((a, b) => {
15548
- var _config$inputs$a3, _config$inputs$b3;
15549
- const positionA = ((_config$inputs$a3 = config.inputs[a]) === null || _config$inputs$a3 === void 0 ? void 0 : _config$inputs$a3.position) || 0;
15550
- const positionB = ((_config$inputs$b3 = config.inputs[b]) === null || _config$inputs$b3 === void 0 ? void 0 : _config$inputs$b3.position) || 0;
15551
- return positionA - positionB;
15552
- });
15553
- let childrenHeight = 0;
15554
- childKeys.forEach(childKey => {
15555
- const childConfig = config.inputs[childKey];
15556
- const childValue = (value === null || value === void 0 ? void 0 : value[childKey]) || (data === null || data === void 0 ? void 0 : data[childKey]);
15557
- childrenHeight += estimateTreeNodeHeight(childKey, childConfig, childValue, level + 1);
15558
- });
15559
-
15560
- // More accurate multiplier that accounts for spacing and margins in actual DOM
15561
- totalHeight += childrenHeight * (isPuppeteer ? 1.25 : 1.15);
15562
- }
15563
-
15564
- // Handle array/repeated content with accurate estimates
15565
- if (Array.isArray(value) && value.length > 0) {
15566
- value.forEach(itemValue => {
15567
- const itemHeight = estimateTreeNodeHeight(key, config, itemValue, level);
15568
- totalHeight += itemHeight * (isPuppeteer ? 1.1 : 1.05); // Minimal buffer
15569
- });
15570
- }
15571
-
15572
- // Minimal buffer for deep nesting
15573
- if (level > 3) {
15574
- totalHeight *= isPuppeteer ? 1.08 : 1.05;
15575
- }
15576
- return Math.ceil(totalHeight);
15577
- };
15578
-
15579
- // Helper function to split section based on height constraints (aligned with PdfView calculations)
15580
- const createHeightConstrainedSections = (sectionKey, section) => {
15581
- const isPuppeteer = isPuppeteerEnvironment();
15582
-
15583
- // Align with PdfView but use a more conservative limit to prevent large margin calculations
15584
- // PdfView uses PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT = 1387px
15585
- // We'll use 85% of that to ensure sections fit comfortably and don't trigger large margins
15586
- const PDFVIEW_MAX_HEIGHT = PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT; // 1387px
15587
- const MAX_SECTION_HEIGHT = Math.floor(PDFVIEW_MAX_HEIGHT * 0.85); // ~1179px - more conservative
15588
- const MIN_SECTION_HEIGHT = 300; // Slightly larger minimum to ensure meaningful content
15589
- const subSections = [];
15590
-
15591
- // Get all top-level items in the section with detailed analysis
15592
- const topLevelItems = Object.keys(section).filter(key => !(key === 'id' || key === 'label' || key === 'position' || key === 'subTitle')).map(key => {
15593
- var _section$key;
15594
- return {
15595
- key,
15596
- config: section[key],
15597
- estimatedHeight: estimateTreeNodeHeight(key, section[key], data === null || data === void 0 ? void 0 : data[key]),
15598
- canSplit: ((_section$key = section[key]) === null || _section$key === void 0 ? void 0 : _section$key.inputs) && Object.keys(section[key].inputs).length > 3 // Only split if sufficient children
15599
- };
15600
- }).sort((a, b) => {
15601
- var _a$config, _b$config;
15602
- return (((_a$config = a.config) === null || _a$config === void 0 ? void 0 : _a$config.position) || 0) - (((_b$config = b.config) === null || _b$config === void 0 ? void 0 : _b$config.position) || 0);
15603
- });
15604
-
15605
- // If the entire section fits, don't split it
15606
- const totalSectionHeight = topLevelItems.reduce((sum, item) => sum + item.estimatedHeight, 0);
15607
-
15608
- // Add detailed debugging for height calculations
15609
- if (typeof window !== 'undefined' && window.console) {
15610
- console.log("Section ".concat(sectionKey, ":"), {
15611
- totalEstimatedHeight: totalSectionHeight,
15612
- maxAllowedHeight: MAX_SECTION_HEIGHT,
15613
- pdfViewMaxHeight: PDFVIEW_MAX_HEIGHT,
15614
- utilizationPercentage: Math.round(totalSectionHeight / MAX_SECTION_HEIGHT * 100) + '%',
15615
- shouldSplit: totalSectionHeight > MAX_SECTION_HEIGHT,
15616
- itemCount: topLevelItems.length,
15617
- itemSummary: topLevelItems.map(item => {
15618
- var _item$config;
15619
- return {
15620
- key: item.key,
15621
- height: item.estimatedHeight,
15622
- type: (_item$config = item.config) === null || _item$config === void 0 ? void 0 : _item$config.type
15623
- };
15624
- })
15625
- });
15626
- }
15627
- if (totalSectionHeight <= MAX_SECTION_HEIGHT) {
15628
- return [{
15629
- key: sectionKey,
15630
- section: section,
15631
- title: section.label
15632
- }];
15633
- }
15634
- let currentSubSection = _objectSpread2({}, section);
15635
-
15636
- // Remove all items from the base section structure
15637
- Object.keys(section).forEach(key => {
15638
- if (!(key === 'id' || key === 'label' || key === 'position' || key === 'subTitle')) {
15639
- delete currentSubSection[key];
15640
- }
15641
- });
15642
- let currentHeight = isPuppeteer ? 120 : 100; // More accurate base height including section headers and margins
15643
- let subSectionIndex = 0;
15644
- topLevelItems.forEach((item, index) => {
15645
- const {
15646
- key,
15647
- config,
15648
- estimatedHeight,
15649
- canSplit
15650
- } = item;
15651
-
15652
- // More conservative splitting thresholds to work better with PdfView
15653
- const SPLIT_THRESHOLD = 0.65; // Split if item takes up more than 65% of available space
15654
-
15655
- // If a single item is large and can be split, consider splitting it
15656
- if (estimatedHeight > MAX_SECTION_HEIGHT * SPLIT_THRESHOLD && canSplit && estimatedHeight > MIN_SECTION_HEIGHT * 1.5) {
15657
- // Split this large item into smaller parts
15658
- const childSplits = splitLargeItem(key, config, data === null || data === void 0 ? void 0 : data[key], MAX_SECTION_HEIGHT * 0.6);
15659
- childSplits.forEach((splitItem, splitIndex) => {
15660
- // Check if current subsection has room - be more lenient about splitting
15661
- if (currentHeight + splitItem.estimatedHeight > MAX_SECTION_HEIGHT && currentHeight > MIN_SECTION_HEIGHT && Object.keys(currentSubSection).length > 4) {
15662
- // Save current sub-section if it has meaningful content
15663
- subSections.push({
15664
- key: "".concat(sectionKey, "_part_").concat(subSectionIndex),
15665
- section: _objectSpread2({}, currentSubSection),
15666
- title: section.label
15667
- });
15668
-
15669
- // Start new sub-section
15670
- currentSubSection = {
15671
- id: section.id,
15672
- label: section.label,
15673
- position: section.position + subSectionIndex + 1,
15674
- subTitle: section.subTitle
15675
- };
15676
- currentHeight = isPuppeteer ? 120 : 100;
15677
- subSectionIndex++;
15678
- }
15679
-
15680
- // Add split item to current sub-section
15681
- currentSubSection[splitItem.key] = splitItem.config;
15682
- currentHeight += splitItem.estimatedHeight;
15683
- });
15684
- } else {
15685
- // Regular processing for items that fit or shouldn't be split
15686
- // More lenient threshold - only split if really necessary and ensures meaningful sections
15687
- const remainingItems = topLevelItems.length - index - 1;
15688
- const shouldSplitSection = currentHeight + estimatedHeight > MAX_SECTION_HEIGHT && currentHeight > MIN_SECTION_HEIGHT * 0.8 &&
15689
- // More lenient minimum
15690
- Object.keys(currentSubSection).length > 3 &&
15691
- // Fewer items required
15692
- remainingItems > 0; // Ensure there are items left for next section
15693
-
15694
- if (shouldSplitSection) {
15695
- // Save current sub-section
15696
- subSections.push({
15697
- key: "".concat(sectionKey, "_part_").concat(subSectionIndex),
15698
- section: _objectSpread2({}, currentSubSection),
15699
- title: section.label
15700
- });
15701
-
15702
- // Start new sub-section
15703
- currentSubSection = {
15704
- id: section.id,
15705
- label: section.label,
15706
- position: section.position + subSectionIndex + 1,
15707
- subTitle: section.subTitle
15708
- };
15709
- currentHeight = isPuppeteer ? 120 : 100;
15710
- subSectionIndex++;
15711
- }
15712
-
15713
- // Add item to current sub-section
15714
- currentSubSection[key] = config;
15715
- currentHeight += estimatedHeight;
15716
- }
15717
- });
15718
-
15719
- // Add the final sub-section if it has meaningful content
15720
- const finalSectionKeys = Object.keys(currentSubSection).filter(key => !(key === 'id' || key === 'label' || key === 'position' || key === 'subTitle'));
15721
- if (finalSectionKeys.length > 0) {
15722
- const finalSubSection = {
15723
- key: subSectionIndex === 0 ? sectionKey : "".concat(sectionKey, "_part_").concat(subSectionIndex),
15724
- section: currentSubSection,
15725
- title: section.label
15726
- };
15727
- subSections.push(finalSubSection);
15728
-
15729
- // Debug final section creation
15730
- if (typeof window !== 'undefined' && window.console) {
15731
- console.log("Final section ".concat(finalSubSection.key, ":"), {
15732
- itemCount: finalSectionKeys.length,
15733
- estimatedHeight: currentHeight,
15734
- utilizationPercentage: Math.round(currentHeight / MAX_SECTION_HEIGHT * 100) + '%',
15735
- isWithinLimits: currentHeight <= MAX_SECTION_HEIGHT
15736
- });
15737
- }
15738
- }
15739
-
15740
- // If we only have one section and it's not too large, return the original
15741
- if (subSections.length === 1 && subSections[0].key === sectionKey) {
15742
- return [{
15743
- key: sectionKey,
15744
- section: section,
15745
- title: section.label
15746
- }];
15747
- }
15748
- return subSections.length > 0 ? subSections : [{
15749
- key: sectionKey,
15750
- section: section,
15751
- title: section.label
15752
- }];
15753
- };
15754
-
15755
- // Helper function to split large items at the child level (more intelligent splitting)
15756
- const splitLargeItem = (parentKey, parentConfig, parentValue, maxHeight) => {
15757
- if (!(parentConfig !== null && parentConfig !== void 0 && parentConfig.inputs)) {
15758
- return [{
15759
- key: parentKey,
15760
- config: parentConfig,
15761
- estimatedHeight: estimateTreeNodeHeight(parentKey, parentConfig, parentValue)
15762
- }];
15763
- }
15764
- const childItems = Object.keys(parentConfig.inputs).filter(childKey => {
15765
- const childConfig = parentConfig.inputs[childKey];
15766
- return !(childConfig !== null && childConfig !== void 0 && childConfig.showIf) || evaluateShowIfCondition(childConfig.showIf, data);
15767
- }).map(childKey => ({
15768
- key: childKey,
15769
- config: parentConfig.inputs[childKey],
15770
- estimatedHeight: estimateTreeNodeHeight(childKey, parentConfig.inputs[childKey], parentValue === null || parentValue === void 0 ? void 0 : parentValue[childKey])
15771
- })).sort((a, b) => {
15772
- var _a$config2, _b$config2;
15773
- return (((_a$config2 = a.config) === null || _a$config2 === void 0 ? void 0 : _a$config2.position) || 0) - (((_b$config2 = b.config) === null || _b$config2 === void 0 ? void 0 : _b$config2.position) || 0);
15774
- });
15775
-
15776
- // If total children height is not that large, don't split
15777
- const totalChildrenHeight = childItems.reduce((sum, child) => sum + child.estimatedHeight, 0);
15778
- if (totalChildrenHeight <= maxHeight * 1.1) {
15779
- // More conservative threshold
15780
- return [{
15781
- key: parentKey,
15782
- config: parentConfig,
15783
- estimatedHeight: estimateTreeNodeHeight(parentKey, parentConfig, parentValue)
15784
- }];
15785
- }
15786
- const splits = [];
15787
- let currentSplit = {
15788
- key: "".concat(parentKey, "_part_0"),
15789
- config: _objectSpread2(_objectSpread2({}, parentConfig), {}, {
15790
- inputs: {}
15791
- }),
15792
- estimatedHeight: 60 // More accurate base height for parent structure with styling
15793
- };
15794
- let splitIndex = 0;
15795
- const minItemsPerSplit = 2; // Ensure at least 2 items per split to avoid tiny sections
15796
-
15797
- childItems.forEach((child, index) => {
15798
- const isLastChild = index === childItems.length - 1;
15799
- const currentSplitItemCount = Object.keys(currentSplit.config.inputs).length;
15800
-
15801
- // Only split if:
15802
- // 1. Adding this child would exceed max height
15803
- // 2. Current split has at least minimum items
15804
- // 3. There are enough remaining items to make another meaningful split
15805
- const remainingItems = childItems.length - index;
15806
- const shouldSplit = currentSplit.estimatedHeight + child.estimatedHeight > maxHeight && currentSplitItemCount >= minItemsPerSplit && (remainingItems > minItemsPerSplit || isLastChild);
15807
- if (shouldSplit) {
15808
- // Save current split if it has content
15809
- splits.push(currentSplit);
15810
- splitIndex++;
15811
-
15812
- // Start new split
15813
- currentSplit = {
15814
- key: "".concat(parentKey, "_part_").concat(splitIndex),
15815
- config: _objectSpread2(_objectSpread2({}, parentConfig), {}, {
15816
- label: parentConfig.label,
15817
- // Keep original label without part indicator
15818
- inputs: {}
15819
- }),
15820
- estimatedHeight: 60
15821
- };
15822
- }
15823
-
15824
- // Add child to current split
15825
- currentSplit.config.inputs[child.key] = child.config;
15826
- currentSplit.estimatedHeight += child.estimatedHeight;
15827
- });
15828
-
15829
- // Add the final split if it has content
15830
- if (Object.keys(currentSplit.config.inputs).length > 0) {
15831
- splits.push(currentSplit);
15832
- }
15833
-
15834
- // If we ended up with only one split, return original
15835
- if (splits.length <= 1) {
15836
- return [{
15837
- key: parentKey,
15838
- config: parentConfig,
15839
- estimatedHeight: estimateTreeNodeHeight(parentKey, parentConfig, parentValue)
15840
- }];
15841
- }
15842
- return splits;
15843
- };
15844
15436
  const pdfConfig = React.useMemo(() => {
15845
15437
  const sections = [];
15846
- const isPuppeteer = isPuppeteerEnvironment();
15847
-
15848
- // Apply Puppeteer-specific class to document body if needed
15849
- if (typeof document !== 'undefined') {
15850
- if (isPuppeteer) {
15851
- document.body.setAttribute('data-puppeteer', 'true');
15852
- } else {
15853
- document.body.removeAttribute('data-puppeteer');
15854
- }
15855
- }
15856
15438
  Object.keys(organizedForm).forEach(sectionKey => {
15857
15439
  const section = organizedForm[sectionKey];
15858
15440
  if (typeof section !== 'object' || !section.label) {
15859
15441
  return;
15860
15442
  }
15861
-
15862
- // Create height-constrained sub-sections
15863
- const subSections = createHeightConstrainedSections(sectionKey, section);
15864
- subSections.forEach(_ref4 => {
15865
- let {
15866
- key,
15867
- section: subSection,
15868
- title
15869
- } = _ref4;
15870
- sections.push({
15871
- render: () => /*#__PURE__*/jsxRuntime.jsx("div", {
15872
- className: "pdf-form-section ".concat(isPuppeteer ? 'puppeteer-mode' : ''),
15873
- children: /*#__PURE__*/jsxRuntime.jsx(PdfFormContent, {
15874
- form: {
15875
- [key]: _objectSpread2(_objectSpread2({}, subSection), {}, {
15876
- label: title
15877
- })
15878
- },
15879
- data: data,
15880
- t: t,
15881
- user: user,
15882
- title: formName,
15883
- source: source,
15884
- version: version,
15885
- getApiBaseUrl: getApiBaseUrl,
15886
- getAppHeader: getAppHeader,
15887
- app: app
15888
- })
15889
- }, key),
15890
- style: {
15891
- marginBottom: '20px',
15892
- padding: '0 20px'
15893
- }
15894
- });
15443
+ sections.push({
15444
+ render: () => /*#__PURE__*/jsxRuntime.jsx("div", {
15445
+ className: "pdf-form-section",
15446
+ children: /*#__PURE__*/jsxRuntime.jsx(PdfFormContent, {
15447
+ form: {
15448
+ [sectionKey]: section
15449
+ },
15450
+ data: data,
15451
+ t: t,
15452
+ user: user,
15453
+ title: formName,
15454
+ source: source,
15455
+ version: version,
15456
+ getApiBaseUrl: getApiBaseUrl,
15457
+ getAppHeader: getAppHeader,
15458
+ app: app
15459
+ })
15460
+ }, sectionKey),
15461
+ style: {
15462
+ marginBottom: '20px',
15463
+ padding: '0 20px'
15464
+ }
15895
15465
  });
15896
15466
  });
15897
15467
  return sections;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.302",
3
+ "version": "0.6.304",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -7,32 +7,6 @@ const PAGE_HEIGHT = 1587;
7
7
  // margin-top: 20, bottom: 20;
8
8
  const FOOTER_HEIGHT = 70;
9
9
  const HEADER_HEIGHT = 100;
10
- const HEADER_CONTENT_OFFSET = HEADER_HEIGHT - 24;
11
-
12
- const printFlags = ["puppeteer=true", "headless=true", "pdf=true"];
13
-
14
- const isHeadlessEnvironment = () => {
15
- if (typeof window === "undefined") return false;
16
-
17
- const matchesPrint =
18
- typeof window.matchMedia === "function" && window.matchMedia("print").matches;
19
-
20
- const search = typeof window.location !== "undefined" ? window.location.search : "";
21
- const hasUrlFlag = printFlags.some((flag) => search?.includes?.(flag));
22
-
23
- let bodyFlag = false;
24
- if (typeof document !== "undefined" && document.body) {
25
- bodyFlag = document.body.getAttribute("data-puppeteer") === "true";
26
- }
27
-
28
- const webdriverFlag =
29
- typeof navigator !== "undefined" &&
30
- navigator.webdriver &&
31
- typeof navigator.userAgent === "string" &&
32
- navigator.userAgent.includes("HeadlessChrome");
33
-
34
- return Boolean(matchesPrint || hasUrlFlag || bodyFlag || webdriverFlag);
35
- };
36
10
 
37
11
  const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
38
12
  const ref = useRef();
@@ -82,30 +56,20 @@ export default function PdfView({
82
56
  let _page = 1;
83
57
 
84
58
  if (keys.length === config.length) {
85
- const headless = isHeadlessEnvironment();
86
- const headerOffset = headless ? 0 : HEADER_CONTENT_OFFSET;
87
- const sectionGap = headless ? 16 : 24;
88
- const maxContentHeight = headless
89
- ? PAGE_HEIGHT - FOOTER_HEIGHT - headerOffset
90
- : PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT;
91
-
92
59
  let incrHeight = 0;
93
60
 
94
- keys.forEach((k) => {
61
+ keys.forEach(k => {
95
62
  const { ref } = sectionsConfig[k];
96
- if (ref?.current) {
97
- ref.current.style.marginBottom = '0px';
98
- ref.current.style.marginTop = '0px';
99
- }
100
- });
63
+ ref.current.style.marginBottom = '0px';
64
+ // ref.current.style.marginTop = '15px';
65
+ })
101
66
 
102
67
  keys.forEach((k, i) => {
103
68
  const { height, ref } = sectionsConfig[k];
104
- if (!ref?.current) return;
105
69
 
106
70
  if (i === 0) {
107
- ref.current.style.marginTop = `${headerOffset}px`;
108
- incrHeight += headerOffset;
71
+ ref.current.style.marginTop = `${HEADER_HEIGHT}px`;
72
+ incrHeight += HEADER_HEIGHT;
109
73
  }
110
74
 
111
75
  const newHeight = incrHeight + height;
@@ -114,25 +78,23 @@ export default function PdfView({
114
78
  ref.current.style.paddingBottom = '30px';
115
79
  }
116
80
 
117
- if (newHeight > maxContentHeight && i !== 0) {
81
+ if (newHeight > PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT) {
118
82
  const dif = Math.abs(PAGE_HEIGHT - incrHeight);
119
- ref.current.style.marginTop = headless ? '16px' : '30px';
83
+ ref.current.style.marginTop = '30px';
120
84
  _page += 1;
121
85
  _pages.push(_page);
122
86
 
123
87
  if (sectionsConfig[keys[i - 1]]) {
124
88
  const { ref: topRef } = sectionsConfig[keys[i - 1]];
125
- if (topRef?.current) {
126
- const spacing = Math.max(dif + headerOffset - sectionGap, headerOffset);
127
- topRef.current.style.marginBottom = `${spacing}px`;
128
- }
129
- incrHeight = height + sectionGap + headerOffset;
89
+ topRef.current.style.marginBottom = `${dif + HEADER_HEIGHT - 24}px`;
90
+ incrHeight = height + 24 + HEADER_HEIGHT;
91
+ // console.log('margin', dif);
130
92
  }
131
93
  } else {
132
- incrHeight = newHeight + sectionGap;
94
+ incrHeight = newHeight + 24;
133
95
  }
134
96
  // console.groupEnd();
135
- });
97
+ })
136
98
  setPages(_pages);
137
99
  }
138
100
  }, [sectionsConfig]);