@hmcts/ccd-case-ui-toolkit 7.3.99-cot-1286 → 7.3.99

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.
@@ -6308,7 +6308,7 @@ class FormValidatorsService {
6308
6308
  // Matches: [text](url), ![alt](url), <img ...>, <a ...>...</a>
6309
6309
  const inlineMarkdownPattern = /(?:!?\[[^\]]{0,500}\]\([^)]{0,500}\)|<(?:img\b[^>]{0,500}>|a\b[^>]{0,500}>[\s\S]*?<\/a>))/i;
6310
6310
  // Matches: [text][id], ![alt][id], and the collapsed form [text][]
6311
- const referenceBoxPattern = /(!)?\[((?:[^[\]\\]|\\.){0,500})\]\s*\[([^\]]{0,100})\]/;
6311
+ const referenceBoxPattern = /(!)?\[((?:[^[\]\\]|\\.){0,500})\]\[([^\]]{0,100})\](?!\s*\/)/;
6312
6312
  // Matches: autolinks such as <http://example.com>
6313
6313
  const autolinkPattern = /<(?:[A-Za-z][A-Za-z0-9+.-]*:[^ <>\n]*|[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+)>/;
6314
6314
  // Matches: bare www.example.com autolinks
@@ -26578,6 +26578,7 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
26578
26578
  },
26579
26579
  plugins: [
26580
26580
  new Plugin({
26581
+ appendTransaction: (transactions, oldState, newState) => this.renumberContinuedOrderedLists(transactions, oldState, newState),
26581
26582
  props: {
26582
26583
  handlePaste: (_view, event) => this.handleEditorPaste(event),
26583
26584
  handleDOMEvents: {
@@ -27061,6 +27062,71 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27061
27062
  ? candidateOrder === adjacentOrder + adjacentList.childCount
27062
27063
  : candidateOrder + candidateList.childCount === adjacentOrder;
27063
27064
  }
27065
+ renumberContinuedOrderedLists(transactions, oldState, newState) {
27066
+ if (!transactions.some((transaction) => transaction.docChanged)) {
27067
+ return null;
27068
+ }
27069
+ const oldChildren = [];
27070
+ let oldPosition = 0;
27071
+ oldState.doc.forEach((node) => {
27072
+ oldChildren.push({ node, position: oldPosition });
27073
+ oldPosition += node.nodeSize;
27074
+ });
27075
+ const mapPosition = (position) => transactions.reduce((mappedPosition, transaction) => transaction.mapping.map(mappedPosition, 1), position);
27076
+ const effectiveOrders = new Map();
27077
+ let result = null;
27078
+ oldChildren.forEach(({ node: candidate, position: candidatePosition }, candidateIndex) => {
27079
+ if (candidate.type.name !== 'ordered_list') {
27080
+ return;
27081
+ }
27082
+ let previousIndex = candidateIndex - 1;
27083
+ while (previousIndex >= 0 &&
27084
+ this.isOrderedListContinuationSeparator(oldChildren[previousIndex].node, candidate)) {
27085
+ previousIndex--;
27086
+ }
27087
+ if (previousIndex < 0) {
27088
+ return;
27089
+ }
27090
+ const previous = oldChildren[previousIndex].node;
27091
+ const previousPosition = oldChildren[previousIndex].position;
27092
+ if (previous.type.name !== 'ordered_list' ||
27093
+ !this.hasMatchingListType(candidate, previous) ||
27094
+ candidate.attrs.indent !== previous.attrs.indent ||
27095
+ !this.isSequentialList(candidate, previous, 1)) {
27096
+ return;
27097
+ }
27098
+ const mappedPreviousPosition = mapPosition(previousPosition);
27099
+ const mappedCandidatePosition = mapPosition(candidatePosition);
27100
+ const newPrevious = newState.doc.nodeAt(mappedPreviousPosition);
27101
+ const newCandidate = newState.doc.nodeAt(mappedCandidatePosition);
27102
+ if (!newPrevious || !newCandidate ||
27103
+ newPrevious.type.name !== 'ordered_list' || newCandidate.type.name !== 'ordered_list' ||
27104
+ newPrevious.firstChild?.textContent !== previous.firstChild?.textContent ||
27105
+ newCandidate.firstChild?.textContent !== candidate.firstChild?.textContent ||
27106
+ !this.hasMatchingListType(newCandidate, newPrevious) ||
27107
+ newCandidate.attrs.indent !== newPrevious.attrs.indent) {
27108
+ return;
27109
+ }
27110
+ const previousOrder = effectiveOrders.get(previousPosition) ?? (Number(newPrevious.attrs.order) || 1);
27111
+ const expectedOrder = previousOrder + newPrevious.childCount;
27112
+ effectiveOrders.set(candidatePosition, expectedOrder);
27113
+ if (Number(newCandidate.attrs.order) === expectedOrder) {
27114
+ return;
27115
+ }
27116
+ result = (result || newState.tr).setNodeMarkup(mappedCandidatePosition, newCandidate.type, {
27117
+ ...newCandidate.attrs,
27118
+ order: expectedOrder
27119
+ });
27120
+ });
27121
+ return result;
27122
+ }
27123
+ isOrderedListContinuationSeparator(node, candidate) {
27124
+ if (this.isEmptyParagraph(node) || this.isListSectionHeading(node)) {
27125
+ return true;
27126
+ }
27127
+ return this.isList(node) &&
27128
+ (Number(node.attrs.indent) || 0) > (Number(candidate.attrs.indent) || 0);
27129
+ }
27064
27130
  hasListContinuation(list) {
27065
27131
  return list.type.name === 'ordered_list' || Boolean(list.attrs.continuationOrder);
27066
27132
  }
@@ -27326,7 +27392,10 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27326
27392
  this.removeUnsupportedMarkup(documentElement);
27327
27393
  this.normaliseDateRangeSpacing(documentElement);
27328
27394
  this.removeUnsupportedAttributes(documentElement);
27329
- return this.normalisePlainTextValue(sanitiseRichTextDocument(documentElement));
27395
+ const sanitisedValue = sanitiseRichTextDocument(documentElement);
27396
+ return this.hasMeaningfulRichTextContent(documentElement)
27397
+ ? this.normalisePlainTextValue(sanitisedValue)
27398
+ : '';
27330
27399
  }
27331
27400
  normaliseRichTextValue(value) {
27332
27401
  if (!value) {
@@ -27344,7 +27413,15 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27344
27413
  this.removeUnsupportedMarkup(documentElement);
27345
27414
  this.normaliseDateRangeSpacing(documentElement);
27346
27415
  this.removeUnsupportedAttributes(documentElement);
27347
- return this.normalisePlainTextValue(sanitiseRichTextDocument(documentElement));
27416
+ const sanitisedValue = sanitiseRichTextDocument(documentElement);
27417
+ return this.hasMeaningfulRichTextContent(documentElement)
27418
+ ? this.normalisePlainTextValue(sanitisedValue)
27419
+ : '';
27420
+ }
27421
+ hasMeaningfulRichTextContent(documentElement) {
27422
+ const visibleText = (documentElement.body.textContent || '')
27423
+ .replace(/[\s\u00a0\u200b-\u200d\ufeff]/g, '');
27424
+ return visibleText.length > 0 || Boolean(documentElement.body.querySelector('hr'));
27348
27425
  }
27349
27426
  syncAccessibilityLater() {
27350
27427
  setTimeout(() => this.syncAccessibilityState());
@@ -27457,13 +27534,31 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
27457
27534
  }
27458
27535
  this.isNormalisingValue = true;
27459
27536
  try {
27460
- this.richTextAreaControl.setValue(normalisedValue, { emitEvent: false });
27461
- this.editor.setContent(normalisedValue || '');
27537
+ this.richTextAreaControl.setValue(normalisedValue, {
27538
+ emitEvent: false,
27539
+ emitModelToViewChange: false
27540
+ });
27541
+ if (normalisedValue || this.editorHasMeaningfulRichTextContent()) {
27542
+ this.editor.setContent(normalisedValue || '');
27543
+ }
27462
27544
  }
27463
27545
  finally {
27464
27546
  this.isNormalisingValue = false;
27465
27547
  }
27466
27548
  }
27549
+ editorHasMeaningfulRichTextContent() {
27550
+ const documentNode = this.editor.view.state.doc;
27551
+ const visibleText = documentNode.textContent.replace(/[\s\u00a0\u200b-\u200d\ufeff]/g, '');
27552
+ let hasHorizontalRule = false;
27553
+ documentNode.descendants((node) => {
27554
+ if (node.type.name === 'horizontal_rule') {
27555
+ hasHorizontalRule = true;
27556
+ return false;
27557
+ }
27558
+ return !hasHorizontalRule;
27559
+ });
27560
+ return visibleText.length > 0 || hasHorizontalRule;
27561
+ }
27467
27562
  richTextRequiredValidator() {
27468
27563
  return (control) => {
27469
27564
  const textValue = this.htmlToText(control.value);
@@ -28114,7 +28209,7 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28114
28209
  }
28115
28210
  return value
28116
28211
  .replace(/!?\[([^\]]{0,500})\]\(([^)]{0,500})\)/g, (_match, text, url) => text || url)
28117
- .replace(/!?\[((?:[^[\]\\]|\\.){0,500})\]\s*\[[^\]]{0,100}\]/g, '$1');
28212
+ .replace(/!?\[((?:[^[\]\\]|\\.){0,500})\]\[[^\]]{0,100}\](?!\s*\/)/g, '$1');
28118
28213
  }
28119
28214
  unwrapElement(element) {
28120
28215
  const parentNode = element.parentNode;
@@ -28133,6 +28228,8 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28133
28228
  const state = {
28134
28229
  listStack: [],
28135
28230
  listParents: [],
28231
+ listRunDeclaredLevel: null,
28232
+ listRunVisualLevel: null,
28136
28233
  resetListLevels: new Map(),
28137
28234
  previousListId: null
28138
28235
  };
@@ -28161,12 +28258,19 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28161
28258
  resetWordListConversionState(state) {
28162
28259
  state.listStack.length = 0;
28163
28260
  state.listParents.length = 0;
28261
+ state.listRunDeclaredLevel = null;
28262
+ state.listRunVisualLevel = null;
28164
28263
  state.resetListLevels.clear();
28165
28264
  state.previousListId = null;
28166
28265
  }
28167
28266
  wordListRequestedLevel(paragraph, listId, wordListIndents, state) {
28168
28267
  const declaredLevel = this.wordListDeclaredLevel(paragraph);
28169
- let requestedLevel = this.wordListLevel(paragraph, wordListIndents);
28268
+ const visualLevel = this.wordListVisualLevel(paragraph, wordListIndents);
28269
+ if (state.listRunDeclaredLevel === null || state.listRunVisualLevel === null) {
28270
+ state.listRunDeclaredLevel = declaredLevel;
28271
+ state.listRunVisualLevel = visualLevel;
28272
+ }
28273
+ let requestedLevel = Math.max(1, declaredLevel - state.listRunDeclaredLevel + 1, visualLevel - state.listRunVisualLevel + 1);
28170
28274
  const rememberedResetLevel = declaredLevel === 1 ? state.resetListLevels.get(listId) : null;
28171
28275
  if (rememberedResetLevel) {
28172
28276
  return Math.max(requestedLevel, rememberedResetLevel);
@@ -28187,7 +28291,8 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28187
28291
  let currentList = state.listStack[stackIndex];
28188
28292
  if (currentList?.tagName.toLowerCase() !== listType || currentList?.getAttribute('type') !== orderedListType ||
28189
28293
  state.listParents[stackIndex] !== listParent) {
28190
- currentList = this.createWordList(documentElement, paragraph, listType, orderedListType, parentListItem);
28294
+ const rootIndent = level === 1 ? state.listRunVisualLevel - 1 : 0;
28295
+ currentList = this.createWordList(documentElement, paragraph, listType, orderedListType, parentListItem, rootIndent);
28191
28296
  state.listStack[stackIndex] = currentList;
28192
28297
  state.listParents[stackIndex] = listParent;
28193
28298
  }
@@ -28195,15 +28300,18 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28195
28300
  state.listParents.length = level;
28196
28301
  return currentList;
28197
28302
  }
28198
- createWordList(documentElement, paragraph, listType, orderedListType, parentListItem) {
28303
+ createWordList(documentElement, paragraph, listType, orderedListType, parentListItem, rootIndent) {
28199
28304
  const list = documentElement.createElement(listType);
28200
- const listStart = this.wordListStart(paragraph);
28305
+ const listStart = this.wordListStart(paragraph, orderedListType);
28201
28306
  if (listType === 'ol' && listStart > 1) {
28202
28307
  list.setAttribute('start', listStart.toString());
28203
28308
  }
28204
28309
  if (orderedListType) {
28205
28310
  list.setAttribute('type', orderedListType);
28206
28311
  }
28312
+ if (rootIndent > 0) {
28313
+ list.dataset.indent = Math.min(6, rootIndent).toString();
28314
+ }
28207
28315
  if (parentListItem) {
28208
28316
  parentListItem.appendChild(list);
28209
28317
  }
@@ -28262,11 +28370,10 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28262
28370
  .find((element) => /mso-list:\s*Ignore/i.test(element.getAttribute('style') || ''));
28263
28371
  return (markerElement ? markerElement.textContent : paragraph.textContent).trim();
28264
28372
  }
28265
- wordListLevel(paragraph, wordListIndents) {
28266
- const declaredLevel = this.wordListDeclaredLevel(paragraph);
28373
+ wordListVisualLevel(paragraph, wordListIndents) {
28267
28374
  const indent = this.wordListIndent(paragraph);
28268
28375
  const visualLevel = wordListIndents.indexOf(indent) + 1;
28269
- return Math.max(declaredLevel, visualLevel || 1);
28376
+ return visualLevel || 1;
28270
28377
  }
28271
28378
  wordListDeclaredLevel(paragraph) {
28272
28379
  const match = (paragraph.getAttribute('style') || '').match(/mso-list:[^;]*\blevel(\d+)/i);
@@ -28287,9 +28394,18 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
28287
28394
  const indent = Math.max(this.cssLengthToPixels(this.cssStyleLength(style, 'margin-left')), this.cssLengthToPixels(this.cssStyleLength(style, 'margin-inline-start')), this.cssLengthToPixels(this.cssStyleLength(style, 'mso-para-margin-left')), this.cssLengthToPixels(this.cssStyleLength(style, 'mso-margin-left-alt')), this.cssLengthToPixels(this.cssMarginLeftLength(style)));
28288
28395
  return Math.round(indent);
28289
28396
  }
28290
- wordListStart(paragraph) {
28291
- const match = /^(\d+)[.)]/.exec(this.wordListMarker(paragraph));
28292
- return match ? Number(match[1]) : 1;
28397
+ wordListStart(paragraph, orderedListType) {
28398
+ const match = /^\(?([a-z]+|\d+)[.)]/i.exec(this.wordListMarker(paragraph));
28399
+ if (!match) {
28400
+ return 1;
28401
+ }
28402
+ if (/^\d+$/.test(match[1])) {
28403
+ return Number(match[1]);
28404
+ }
28405
+ if (orderedListType === 'a') {
28406
+ return match[1].toLowerCase().split('').reduce((start, character) => (start * 26) + character.charCodeAt(0) - 96, 0);
28407
+ }
28408
+ return 1;
28293
28409
  }
28294
28410
  copyListItemContents(documentElement, paragraph, listItem) {
28295
28411
  Array.prototype.slice.call(paragraph.childNodes).forEach((childNode) => {
@@ -29008,7 +29124,7 @@ class WriteRichTextAreaFieldComponent extends AbstractFieldWriteComponent {
29008
29124
  type: ViewChild,
29009
29125
  args: ['editorHost']
29010
29126
  }] }); })();
29011
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteRichTextAreaFieldComponent, { className: "WriteRichTextAreaFieldComponent", filePath: "lib/shared/components/palette/rich-text-area/write-rich-text-area-field.component.ts", lineNumber: 137 }); })();
29127
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteRichTextAreaFieldComponent, { className: "WriteRichTextAreaFieldComponent", filePath: "lib/shared/components/palette/rich-text-area/write-rich-text-area-field.component.ts", lineNumber: 139 }); })();
29012
29128
 
29013
29129
  class ReadTextFieldComponent extends AbstractFieldReadComponent {
29014
29130
  static ɵfac = /*@__PURE__*/ (() => { let ɵReadTextFieldComponent_BaseFactory; return function ReadTextFieldComponent_Factory(__ngFactoryType__) { return (ɵReadTextFieldComponent_BaseFactory || (ɵReadTextFieldComponent_BaseFactory = i0.ɵɵgetInheritedFactory(ReadTextFieldComponent)))(__ngFactoryType__ || ReadTextFieldComponent); }; })();
@@ -42619,12 +42735,9 @@ class EventStartStateMachineService {
42619
42735
  }
42620
42736
  entryActionForStateNoTask(state, context) {
42621
42737
  // Trigger final state to complete processing of state machine
42622
- const task = context.tasks[0];
42623
- const jurisdiction = task?.jurisdiction ?? context.caseDetails?.case_type?.jurisdiction?.id;
42624
- const caseTypeId = task?.case_type_id ?? context.caseDetails?.case_type?.id;
42625
42738
  state.trigger(EventStartStates.FINAL);
42626
42739
  // Navigate to no tasks available error page
42627
- context.router.navigate([`/cases/case-details/${jurisdiction}/${caseTypeId}/${context.caseId}/no-tasks-available`], { relativeTo: context.route });
42740
+ context.router.navigate([`/cases/case-details/${context.tasks[0]?.jurisdiction}/${context.tasks[0]?.case_type_id}/${context.caseId}/no-tasks-available`], { relativeTo: context.route });
42628
42741
  }
42629
42742
  entryActionForStateOneOrMoreTasks(state, context) {
42630
42743
  state.trigger(EventStartStates.TASK_ASSIGNED_TO_USER);
@@ -42782,9 +42895,8 @@ class EventStartComponent {
42782
42895
  }
42783
42896
  ngOnInit() {
42784
42897
  // Get task and case id payload from route data
42785
- const caseDetails = this.route.snapshot.data.case;
42786
42898
  const tasks = this.route.snapshot.data.tasks;
42787
- const caseId = caseDetails.case_id;
42899
+ const caseId = this.route.snapshot.data.case.case_id;
42788
42900
  const eventId = this.route.snapshot.queryParams['eventId'];
42789
42901
  const taskId = this.route.snapshot.queryParams['taskId'];
42790
42902
  // Setup the context
@@ -42793,7 +42905,6 @@ class EventStartComponent {
42793
42905
  caseId,
42794
42906
  eventId,
42795
42907
  taskId,
42796
- caseDetails,
42797
42908
  router: this.router,
42798
42909
  route: this.route,
42799
42910
  sessionStorageService: this.sessionStorageService,