@hmcts/ccd-case-ui-toolkit 7.4.3-redact → 7.4.4-5290-rc-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.
@@ -14766,6 +14766,9 @@ class CaseFileViewFieldComponent {
14766
14766
  ngAfterViewInit() {
14767
14767
  const slider = this.elementRef.nativeElement.querySelector('.slider');
14768
14768
  const documentTreeContainer = this.elementRef.nativeElement.querySelector('.document-tree-container');
14769
+ if (!slider || !documentTreeContainer) {
14770
+ return;
14771
+ }
14769
14772
  const mousedown$ = fromEvent(slider, 'mousedown');
14770
14773
  const mousemove$ = fromEvent(document, 'mousemove');
14771
14774
  const mouseup$ = fromEvent(document, 'mouseup');
@@ -27404,8 +27407,12 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27404
27407
  this.removeUnsupportedMarkup(documentElement);
27405
27408
  this.normaliseDateRangeSpacing(documentElement);
27406
27409
  this.removeUnsupportedAttributes(documentElement);
27410
+ const hasMeaningfulContent = this.hasMeaningfulRichTextContent(documentElement);
27411
+ if (hasMeaningfulContent) {
27412
+ this.preserveDocmosisBlankParagraphs(documentElement);
27413
+ }
27407
27414
  const sanitisedValue = sanitiseRichTextDocument(documentElement);
27408
- return this.hasMeaningfulRichTextContent(documentElement)
27415
+ return hasMeaningfulContent
27409
27416
  ? this.normalisePlainTextValue(sanitisedValue)
27410
27417
  : '';
27411
27418
  }
@@ -27425,11 +27432,22 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27425
27432
  this.removeUnsupportedMarkup(documentElement);
27426
27433
  this.normaliseDateRangeSpacing(documentElement);
27427
27434
  this.removeUnsupportedAttributes(documentElement);
27435
+ const hasMeaningfulContent = this.hasMeaningfulRichTextContent(documentElement);
27436
+ if (hasMeaningfulContent) {
27437
+ this.preserveDocmosisBlankParagraphs(documentElement);
27438
+ }
27428
27439
  const sanitisedValue = sanitiseRichTextDocument(documentElement);
27429
- return this.hasMeaningfulRichTextContent(documentElement)
27440
+ return hasMeaningfulContent
27430
27441
  ? this.normalisePlainTextValue(sanitisedValue)
27431
27442
  : '';
27432
27443
  }
27444
+ /**
27445
+ * Gives intentionally blank paragraphs content so Docmosis preserves them as blank lines.
27446
+ * This runs only when the document has meaningful content, so a completely empty field remains empty.
27447
+ */
27448
+ preserveDocmosisBlankParagraphs(documentElement) {
27449
+ this.replaceBlankParagraphContent(documentElement, '\u00a0');
27450
+ }
27433
27451
  hasMeaningfulRichTextContent(documentElement) {
27434
27452
  const visibleText = (documentElement.body.textContent || '')
27435
27453
  .replace(/[\s\u00a0\u200b-\u200d\ufeff]/g, '');
@@ -27550,7 +27568,8 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27550
27568
  emitEvent: false,
27551
27569
  emitModelToViewChange: false
27552
27570
  });
27553
- if (normalisedValue || this.editorHasMeaningfulRichTextContent()) {
27571
+ if ((normalisedValue || this.editorHasMeaningfulRichTextContent())
27572
+ && !this.differsOnlyByDocmosisBlankParagraphs(value, normalisedValue)) {
27554
27573
  this.editor.setContent(normalisedValue || '');
27555
27574
  }
27556
27575
  }
@@ -27558,6 +27577,34 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27558
27577
  this.isNormalisingValue = false;
27559
27578
  }
27560
27579
  }
27580
+ differsOnlyByDocmosisBlankParagraphs(value, normalisedValue) {
27581
+ if (!value || !normalisedValue) {
27582
+ return false;
27583
+ }
27584
+ const originalDocument = new DOMParser().parseFromString(value, 'text/html');
27585
+ const normalisedDocument = new DOMParser().parseFromString(normalisedValue, 'text/html');
27586
+ this.clearBlankParagraphs(originalDocument);
27587
+ this.clearBlankParagraphs(normalisedDocument);
27588
+ return originalDocument.body.innerHTML === normalisedDocument.body.innerHTML;
27589
+ }
27590
+ /**
27591
+ * Canonicalises visually blank paragraphs to <p></p> before comparing two HTML values.
27592
+ * This lets the editor avoid reloading when only the Docmosis blank-line representation changed.
27593
+ */
27594
+ clearBlankParagraphs(documentElement) {
27595
+ this.replaceBlankParagraphContent(documentElement, '');
27596
+ }
27597
+ replaceBlankParagraphContent(documentElement, replacement) {
27598
+ const paragraphs = Array.prototype.slice.call(documentElement.body.querySelectorAll('p'));
27599
+ paragraphs.forEach((paragraph) => {
27600
+ // Ignore standard whitespace (\s), non-breaking spaces (U+00A0), zero-width characters
27601
+ // (U+200B–U+200D), and the byte-order mark (U+FEFF) when checking for visible text.
27602
+ const visibleText = (paragraph.textContent || '').replace(/[\s\u00a0\u200b-\u200d\ufeff]/g, '');
27603
+ if (!visibleText && !paragraph.querySelector('hr')) {
27604
+ paragraph.textContent = replacement;
27605
+ }
27606
+ });
27607
+ }
27561
27608
  editorHasMeaningfulRichTextContent() {
27562
27609
  const documentNode = this.editor.view.state.doc;
27563
27610
  const visibleText = documentNode.textContent.replace(/[\s\u00a0\u200b-\u200d\ufeff]/g, '');