adb-shared 6.2.21 → 6.2.25

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.
@@ -1912,8 +1912,10 @@ class AdbRichEditorComponent {
1912
1912
  value.slice(start);
1913
1913
  this.updateValue(newValue);
1914
1914
  const cursor = start + marker.length;
1915
- textarea.focus();
1916
- textarea.setSelectionRange(cursor, cursor);
1915
+ requestAnimationFrame(() => {
1916
+ textarea.focus();
1917
+ textarea.setSelectionRange(cursorStart, cursorEnd);
1918
+ });
1917
1919
  return;
1918
1920
  }
1919
1921
  const existingMarker = this.findWrappingMarker(value, start, end, FORMAT_MARKERS[type]);
@@ -1934,8 +1936,10 @@ class AdbRichEditorComponent {
1934
1936
  const cursorEnd = existingMarker
1935
1937
  ? end - marker.length
1936
1938
  : end + marker.length;
1937
- textarea.focus();
1938
- textarea.setSelectionRange(cursorStart, cursorEnd);
1939
+ requestAnimationFrame(() => {
1940
+ textarea.focus();
1941
+ textarea.setSelectionRange(cursorStart, cursorEnd);
1942
+ });
1939
1943
  }
1940
1944
  findWrappingMarker(value, start, end, markers) {
1941
1945
  return (markers.find(marker => value.substring(start - marker.length, start) === marker &&
@@ -2041,76 +2045,78 @@ class RichTextComponent {
2041
2045
  }
2042
2046
  parseCustomMarkdown(input) {
2043
2047
  const parts = [];
2044
- const boldRegex = /(\*\*|__)(.+?)\1/g;
2045
- const italicRegex = /(\*|_)([^*_]+?)\1/g;
2046
- const taxonRegex = /\[([^\]]+)\]\(taxon:([^)]+)\)/g;
2047
- const termRegex = /\[([^\]]+)\]\(term:([^)]+)\)/g;
2048
- const referenceRegex = /\[([^\]]+)\]\(reference:([^)]+)\)/g;
2049
- const combinedRegex = new RegExp([
2050
- boldRegex.source,
2051
- italicRegex.source,
2052
- taxonRegex.source,
2053
- termRegex.source,
2054
- referenceRegex.source
2055
- ].join('|'), 'g');
2056
- let lastIndex = 0;
2057
- let match;
2058
- while ((match = combinedRegex.exec(input)) !== null) {
2059
- if (match.index > lastIndex) {
2060
- parts.push({
2061
- type: 'text',
2062
- content: input.slice(lastIndex, match.index)
2063
- });
2048
+ let i = 0;
2049
+ const pushText = (text) => {
2050
+ if (text) {
2051
+ parts.push({ type: 'text', content: text });
2064
2052
  }
2065
- if (match[2]) {
2066
- parts.push({
2067
- type: 'bold',
2068
- content: match[2]
2069
- });
2053
+ };
2054
+ while (i < input.length) {
2055
+ if (input.startsWith('**', i) || input.startsWith('__', i)) {
2056
+ const marker = input.substr(i, 2);
2057
+ const end = input.indexOf(marker, i + 2);
2058
+ if (end !== -1) {
2059
+ parts.push({
2060
+ type: 'bold',
2061
+ content: input.slice(i + 2, end)
2062
+ });
2063
+ i = end + 2;
2064
+ continue;
2065
+ }
2070
2066
  }
2071
- else if (match[4]) {
2072
- parts.push({
2073
- type: 'italic',
2074
- content: match[4]
2075
- });
2067
+ if (input[i] === '*' || input[i] === '_') {
2068
+ const marker = input[i];
2069
+ const end = input.indexOf(marker, i + 1);
2070
+ if (end !== -1) {
2071
+ parts.push({
2072
+ type: 'italic',
2073
+ content: input.slice(i + 1, end)
2074
+ });
2075
+ i = end + 1;
2076
+ continue;
2077
+ }
2076
2078
  }
2077
- else if (match[5]) {
2078
- parts.push({
2079
- type: 'taxon',
2080
- content: match[5],
2081
- id: match[6]
2082
- });
2079
+ if (input[i] === '[') {
2080
+ const textEnd = input.indexOf(']', i);
2081
+ const linkStart = input.indexOf('(', textEnd);
2082
+ const linkEnd = input.indexOf(')', linkStart);
2083
+ if (textEnd !== -1 && linkStart !== -1 && linkEnd !== -1) {
2084
+ const label = input.slice(i + 1, textEnd);
2085
+ const link = input.slice(linkStart + 1, linkEnd);
2086
+ const [type, id] = link.split(':');
2087
+ if (type === 'taxon' || type === 'term' || type === 'reference') {
2088
+ parts.push({
2089
+ type: type,
2090
+ content: label,
2091
+ id
2092
+ });
2093
+ i = linkEnd + 1;
2094
+ continue;
2095
+ }
2096
+ }
2083
2097
  }
2084
- else if (match[7]) {
2085
- parts.push({
2086
- type: 'term',
2087
- content: match[7],
2088
- id: match[8]
2089
- });
2098
+ let next = input.length;
2099
+ for (const c of ['*', '_', '[']) {
2100
+ const idx = input.indexOf(c, i + 1);
2101
+ if (idx !== -1 && idx < next) {
2102
+ next = idx;
2103
+ }
2090
2104
  }
2091
- else if (match[9]) {
2092
- parts.push({
2093
- type: 'reference',
2094
- content: match[9],
2095
- id: match[10]
2096
- });
2105
+ if (next === input.length) {
2106
+ pushText(input.slice(i));
2107
+ break;
2097
2108
  }
2098
- lastIndex = combinedRegex.lastIndex;
2099
- }
2100
- if (lastIndex < input.length) {
2101
- parts.push({
2102
- type: 'text',
2103
- content: input.slice(lastIndex)
2104
- });
2109
+ pushText(input.slice(i, next));
2110
+ i = next;
2105
2111
  }
2106
2112
  return parts;
2107
2113
  }
2108
2114
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: RichTextComponent, deps: [{ token: RICH_MODULE_CONFIG }], target: i0.ɵɵFactoryTarget.Component });
2109
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.0", type: RichTextComponent, isStandalone: false, selector: "adb-rich-text", inputs: { text: "text" }, usesOnChanges: true, ngImport: i0, template: "<div style=\"white-space: pre-wrap;\">\r\n @for (part of parts; track part) {\r\n @if (part.type === 'text') {\r\n <span>{{ part.content }}</span>\r\n }\r\n @if (part.type === 'italic') {\r\n <em>{{ part.content }}</em>\r\n }\r\n @if (part.type === 'bold') {\r\n <b>{{ part.content }}</b>\r\n }\r\n @if (part.type === 'taxon') {\r\n <a [href]=\"taxonUrl + part.id\">{{ part.content }}</a>\r\n }\r\n @if (part.type === 'term') {\r\n <span>{{ part.content }}</span>\r\n }\r\n @if (part.type === 'reference') {\r\n <span>{{ part.content }}</span>\r\n }\r\n }\r\n</div>\r\n" });
2115
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.0", type: RichTextComponent, isStandalone: false, selector: "adb-rich-text", inputs: { text: "text" }, usesOnChanges: true, ngImport: i0, template: "<div style=\"white-space: pre-wrap;\">\r\n @for (part of parts; track $index) {\r\n @switch (part.type) {\r\n @case ('text') { <span>{{ part.content }}</span> }\r\n @case ('italic') { <em>{{ part.content }}</em> }\r\n @case ('bold') { <b>{{ part.content }}</b> }\r\n @case ('taxon') { <a [href]=\"taxonUrl + part.id\">{{ part.content }}</a> }\r\n @default { <span>{{ part.content }}</span> }\r\n }\r\n}\r\n</div>" });
2110
2116
  }
2111
2117
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: RichTextComponent, decorators: [{
2112
2118
  type: Component,
2113
- args: [{ selector: 'adb-rich-text', standalone: false, template: "<div style=\"white-space: pre-wrap;\">\r\n @for (part of parts; track part) {\r\n @if (part.type === 'text') {\r\n <span>{{ part.content }}</span>\r\n }\r\n @if (part.type === 'italic') {\r\n <em>{{ part.content }}</em>\r\n }\r\n @if (part.type === 'bold') {\r\n <b>{{ part.content }}</b>\r\n }\r\n @if (part.type === 'taxon') {\r\n <a [href]=\"taxonUrl + part.id\">{{ part.content }}</a>\r\n }\r\n @if (part.type === 'term') {\r\n <span>{{ part.content }}</span>\r\n }\r\n @if (part.type === 'reference') {\r\n <span>{{ part.content }}</span>\r\n }\r\n }\r\n</div>\r\n" }]
2119
+ args: [{ selector: 'adb-rich-text', standalone: false, template: "<div style=\"white-space: pre-wrap;\">\r\n @for (part of parts; track $index) {\r\n @switch (part.type) {\r\n @case ('text') { <span>{{ part.content }}</span> }\r\n @case ('italic') { <em>{{ part.content }}</em> }\r\n @case ('bold') { <b>{{ part.content }}</b> }\r\n @case ('taxon') { <a [href]=\"taxonUrl + part.id\">{{ part.content }}</a> }\r\n @default { <span>{{ part.content }}</span> }\r\n }\r\n}\r\n</div>" }]
2114
2120
  }], ctorParameters: () => [{ type: undefined, decorators: [{
2115
2121
  type: Inject,
2116
2122
  args: [RICH_MODULE_CONFIG]