@myrmidon/cadmus-core 20.0.0 → 20.1.0

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/README.md CHANGED
@@ -5,3 +5,9 @@
5
5
  This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.0.
6
6
 
7
7
  This library contains only shared Cadmus frontend models, generic services, pipes, and guards.
8
+
9
+ ## Text Layers
10
+
11
+ Token-based text layers use locations (`TokenLocation`, made of one or two `TokenPoint`'s) in the form `Y.X@AxR`, where `Y` is the line ordinal, `X` the token ordinal in the line, and optionally `A` the first character in the token and `R` the count of characters (see the documentation of `DecoratedTokenTextComponent` in `@myrmidon/cadmus-ui` for the details).
12
+
13
+ `TextLayerService` contains the legacy implementation of this coordinates system. Its `getLines` and `getTextFragment` methods are still used to extract the text of a location; while its DOM-based rendition and selection methods (`render`, `getSelectedLocationForNew`, `getSelectedLocationForEdit`, `getSelectedRange`) are deprecated, as the same logic is now implemented by `TokenTextSegmenter` in `@myrmidon/cadmus-ui`. They are kept for backwards compatibility, and as the reference which `TokenTextSegmenter` tests check their parity with.
@@ -18,6 +18,12 @@ var DataPinValueType;
18
18
  DataPinValueType[DataPinValueType["integer"] = 2] = "integer";
19
19
  DataPinValueType[DataPinValueType["decimal"] = 3] = "decimal";
20
20
  })(DataPinValueType || (DataPinValueType = {}));
21
+ var EditStatus;
22
+ (function(EditStatus) {
23
+ EditStatus[EditStatus["created"] = 0] = "created";
24
+ EditStatus[EditStatus["updated"] = 1] = "updated";
25
+ EditStatus[EditStatus["deleted"] = 2] = "deleted";
26
+ })(EditStatus || (EditStatus = {}));
21
27
  var TextRange = class TextRange {
22
28
  start;
23
29
  length;
@@ -134,7 +140,7 @@ var PendingChangesGuard = class PendingChangesGuard {
134
140
  }
135
141
  static ɵfac = i0.ɵɵngDeclareFactory({
136
142
  minVersion: "12.0.0",
137
- version: "22.2.0",
143
+ version: "22.3.0",
138
144
  ngImport: i0,
139
145
  type: PendingChangesGuard,
140
146
  deps: [{ token: i1.DialogService }],
@@ -142,7 +148,7 @@ var PendingChangesGuard = class PendingChangesGuard {
142
148
  });
143
149
  static ɵprov = i0.ɵɵngDeclareInjectable({
144
150
  minVersion: "12.0.0",
145
- version: "22.2.0",
151
+ version: "22.3.0",
146
152
  ngImport: i0,
147
153
  type: PendingChangesGuard,
148
154
  providedIn: "root"
@@ -150,7 +156,7 @@ var PendingChangesGuard = class PendingChangesGuard {
150
156
  };
151
157
  i0.ɵɵngDeclareClassMetadata({
152
158
  minVersion: "12.0.0",
153
- version: "22.2.0",
159
+ version: "22.3.0",
154
160
  ngImport: i0,
155
161
  type: PendingChangesGuard,
156
162
  decorators: [{
@@ -174,7 +180,7 @@ var SortPipe = class SortPipe {
174
180
  }
175
181
  static ɵfac = i0.ɵɵngDeclareFactory({
176
182
  minVersion: "12.0.0",
177
- version: "22.2.0",
183
+ version: "22.3.0",
178
184
  ngImport: i0,
179
185
  type: SortPipe,
180
186
  deps: [],
@@ -182,7 +188,7 @@ var SortPipe = class SortPipe {
182
188
  });
183
189
  static ɵpipe = i0.ɵɵngDeclarePipe({
184
190
  minVersion: "14.0.0",
185
- version: "22.2.0",
191
+ version: "22.3.0",
186
192
  ngImport: i0,
187
193
  type: SortPipe,
188
194
  isStandalone: true,
@@ -191,7 +197,7 @@ var SortPipe = class SortPipe {
191
197
  };
192
198
  i0.ɵɵngDeclareClassMetadata({
193
199
  minVersion: "12.0.0",
194
- version: "22.2.0",
200
+ version: "22.3.0",
195
201
  ngImport: i0,
196
202
  type: SortPipe,
197
203
  decorators: [{
@@ -278,7 +284,7 @@ var LibraryRouteService = class LibraryRouteService {
278
284
  }
279
285
  static ɵfac = i0.ɵɵngDeclareFactory({
280
286
  minVersion: "12.0.0",
281
- version: "22.2.0",
287
+ version: "22.3.0",
282
288
  ngImport: i0,
283
289
  type: LibraryRouteService,
284
290
  deps: [{ token: "partEditorKeys" }],
@@ -286,7 +292,7 @@ var LibraryRouteService = class LibraryRouteService {
286
292
  });
287
293
  static ɵprov = i0.ɵɵngDeclareInjectable({
288
294
  minVersion: "12.0.0",
289
- version: "22.2.0",
295
+ version: "22.3.0",
290
296
  ngImport: i0,
291
297
  type: LibraryRouteService,
292
298
  providedIn: "root"
@@ -294,7 +300,7 @@ var LibraryRouteService = class LibraryRouteService {
294
300
  };
295
301
  i0.ɵɵngDeclareClassMetadata({
296
302
  minVersion: "12.0.0",
297
- version: "22.2.0",
303
+ version: "22.3.0",
298
304
  ngImport: i0,
299
305
  type: LibraryRouteService,
300
306
  decorators: [{
@@ -658,7 +664,7 @@ var TextLayerService = class TextLayerService {
658
664
  }
659
665
  static ɵfac = i0.ɵɵngDeclareFactory({
660
666
  minVersion: "12.0.0",
661
- version: "22.2.0",
667
+ version: "22.3.0",
662
668
  ngImport: i0,
663
669
  type: TextLayerService,
664
670
  deps: [],
@@ -666,7 +672,7 @@ var TextLayerService = class TextLayerService {
666
672
  });
667
673
  static ɵprov = i0.ɵɵngDeclareInjectable({
668
674
  minVersion: "12.0.0",
669
- version: "22.2.0",
675
+ version: "22.3.0",
670
676
  ngImport: i0,
671
677
  type: TextLayerService,
672
678
  providedIn: "root"
@@ -674,7 +680,7 @@ var TextLayerService = class TextLayerService {
674
680
  };
675
681
  i0.ɵɵngDeclareClassMetadata({
676
682
  minVersion: "12.0.0",
677
- version: "22.2.0",
683
+ version: "22.3.0",
678
684
  ngImport: i0,
679
685
  type: TextLayerService,
680
686
  decorators: [{
@@ -683,6 +689,6 @@ i0.ɵɵngDeclareClassMetadata({
683
689
  }],
684
690
  ctorParameters: () => []
685
691
  });
686
- export { DataPinValueType, FlagMatching, LibraryRouteService, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint, pendingChangesGuard };
692
+ export { DataPinValueType, EditStatus, FlagMatching, LibraryRouteService, PendingChangesGuard, SortPipe, TextLayerService, TextRange, TokenLocation, TokenPoint, pendingChangesGuard };
687
693
 
688
694
  //# sourceMappingURL=myrmidon-cadmus-core.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"myrmidon-cadmus-core.mjs","names":[],"sources":["../../../../projects/myrmidon/cadmus-core/src/lib/models.ts","../../../../projects/myrmidon/cadmus-core/src/lib/text-range.ts","../../../../projects/myrmidon/cadmus-core/src/lib/token-point.ts","../../../../projects/myrmidon/cadmus-core/src/lib/token-location.ts","../../../../projects/myrmidon/cadmus-core/src/lib/guards/pending-changes.guard.ts","../../../../projects/myrmidon/cadmus-core/src/lib/pipes/sort.pipe.ts","../../../../projects/myrmidon/cadmus-core/src/lib/services/library-route.service.ts","../../../../projects/myrmidon/cadmus-core/src/lib/services/text-layer.service.ts"],"sourcesContent":["/**\r\n * Interface implemented by versioned storage objects.\r\n */\r\nexport interface HasVersion {\r\n timeCreated: Date;\r\n creatorId: string;\r\n timeModified: Date;\r\n userId: string;\r\n}\r\n\r\n/**\r\n * Item's properties, excluding its parts.\r\n */\r\nexport interface Item extends HasVersion {\r\n id: string;\r\n title: string;\r\n description: string;\r\n facetId: string;\r\n groupId: string;\r\n sortKey: string;\r\n flags: number;\r\n parts?: Part[];\r\n}\r\n\r\n/**\r\n * Flags matching mode.\r\n */\r\nexport enum FlagMatching {\r\n // the none value is frontend-side only, as in the backend\r\n // the flags property in ItemFilter is nullable\r\n none = -1,\r\n bitsAllSet = 0,\r\n bitsAnySet,\r\n bitsAllClear,\r\n bitsAnyClear,\r\n}\r\n\r\n/**\r\n * Filter for items.\r\n */\r\nexport interface ItemFilter {\r\n title?: string;\r\n description?: string;\r\n facetId?: string;\r\n groupId?: string;\r\n flags?: number;\r\n flagMatching?: FlagMatching;\r\n minModified?: Date;\r\n maxModified?: Date;\r\n userId?: string;\r\n}\r\n\r\n/**\r\n * Essential information about an item.\r\n */\r\nexport interface ItemInfo extends HasVersion {\r\n id: string;\r\n title: string;\r\n description: string;\r\n facetId: string;\r\n groupId: string;\r\n sortKey: string;\r\n flags: number;\r\n payload?: any;\r\n}\r\n\r\n/**\r\n * Information about a data pin; returned by pins search.\r\n */\r\nexport interface DataPinInfo {\r\n itemId: string;\r\n partId: string;\r\n roleId: string | null;\r\n partTypeId: string;\r\n name: string;\r\n value: string;\r\n tag?: string;\r\n}\r\n\r\n/**\r\n * Data pin value type in a DataPinDefinition.\r\n */\r\nexport enum DataPinValueType {\r\n string = 0,\r\n boolean,\r\n integer,\r\n decimal,\r\n}\r\n\r\n/**\r\n * Definition of a data pin.\r\n */\r\nexport interface DataPinDefinition {\r\n name: string;\r\n type: DataPinValueType;\r\n tip?: string;\r\n attributes?: string;\r\n}\r\n\r\n/**\r\n * Part type and role IDs.\r\n */\r\nexport interface PartTypeIds {\r\n typeId: string;\r\n roleId?: string;\r\n}\r\n\r\n/**\r\n * Part. This is the minimal set of properties present in all the\r\n * parts. Each part then adds its own properties, extending this interface.\r\n */\r\nexport interface Part extends HasVersion, PartTypeIds {\r\n id: string;\r\n itemId: string;\r\n thesaurusScope?: string;\r\n}\r\n\r\n/**\r\n * Essential information about a layer part.\r\n */\r\nexport interface LayerPartInfo extends HasVersion, PartTypeIds {\r\n id: string;\r\n itemId: string;\r\n fragmentCount: number;\r\n isAbsent: boolean;\r\n}\r\n\r\n/**\r\n * Text layer fragment. This is the minimal set of properties present in all the\r\n * fragments. Each fragment then adds its own properties, extending this\r\n * interface.\r\n * Every fragment has a location, and can be enriched with the corresponding\r\n * base text when used in views.\r\n */\r\nexport interface Fragment {\r\n location: string;\r\n baseText?: string;\r\n}\r\n\r\n/**\r\n * Text layer part. This represents a special type of part,\r\n * whose only content is a collection of fragments.\r\n */\r\nexport interface TextLayerPart extends Part {\r\n fragments: Fragment[];\r\n}\r\n\r\n/**\r\n * A text line in a base text part.\r\n */\r\nexport interface TokenTextLayerLine {\r\n y: number;\r\n tokens: string[];\r\n}\r\n\r\n/**\r\n * Token-based text coordinates.\r\n */\r\nexport interface TextCoords {\r\n y: number;\r\n x: number;\r\n at?: number;\r\n run?: number;\r\n}\r\n\r\n/**\r\n * Layer reconciliation hint for a single fragment.\r\n */\r\nexport interface LayerHint {\r\n location: string;\r\n editOperation: string;\r\n patchOperation?: string;\r\n impactLevel: number;\r\n description?: string;\r\n}\r\n\r\n/**\r\n * A single entry in a thesaurus.\r\n */\r\nexport interface ThesaurusEntry {\r\n id: string;\r\n value: string;\r\n}\r\n\r\n/**\r\n * A set of thesaurus entries.\r\n */\r\nexport interface Thesaurus {\r\n id: string;\r\n language?: string;\r\n targetId?: string;\r\n entries?: ThesaurusEntry[];\r\n}\r\n\r\n/**\r\n * A set of thesauri which get passed to an editor component.\r\n * In the set, each thesaurus is identified by an arbitrarily\r\n * defined key, which is unique only within the context of the editor\r\n * consuming the set, and refers to frontend only.\r\n */\r\nexport interface ThesauriSet {\r\n [key: string]: Thesaurus;\r\n}\r\n\r\n/**\r\n * Filter for thesauri.\r\n */\r\nexport interface ThesaurusFilter {\r\n id?: string;\r\n isAlias?: boolean;\r\n language?: string;\r\n}\r\n\r\n/**\r\n * Part definition in a facet.\r\n */\r\nexport interface PartDefinition extends PartTypeIds {\r\n name: string;\r\n description?: string;\r\n isRequired?: boolean;\r\n colorKey?: string;\r\n groupKey?: string;\r\n sortKey?: string;\r\n}\r\n\r\n/**\r\n * Fragment definition in a facet.\r\n */\r\n/**\r\n * Facet definition.\r\n */\r\nexport interface FacetDefinition {\r\n id: string;\r\n label: string;\r\n colorKey: string;\r\n description: string;\r\n partDefinitions: PartDefinition[];\r\n}\r\n\r\n/**\r\n * Flag definition.\r\n */\r\nexport interface FlagDefinition {\r\n id: number;\r\n label: string;\r\n description: string;\r\n colorKey: string;\r\n isAdmin?: boolean;\r\n}\r\n\r\n/**\r\n * The group key for a part type. This is used in EditorKeys objects\r\n * to map a specific part ID with all its fragment IDs into group key(s).\r\n * The part ID is used alone with normal parts; for layer parts, it is\r\n * used in conjunction with 1 or more fragment type IDs, each mapped to\r\n * a corresponding editor key.\r\n */\r\nexport interface PartGroupKey {\r\n part: string;\r\n fragments?: { [key: string]: string };\r\n}\r\n\r\n/**\r\n * Part type IDs to editor keys mappings. This contains a set of component\r\n * type IDs (parts and parts + fragments) mapped to editor keys, which are\r\n * used to build their routes in the UI.\r\n */\r\nexport interface PartEditorKeys {\r\n [key: string]: PartGroupKey;\r\n}\r\n\r\n/**\r\n * An index lookup definition, used in dynamic lookup to provide the set\r\n * of parameters required for a data pins based search.\r\n */\r\nexport interface IndexLookupDefinition {\r\n typeId?: string;\r\n roleId?: string;\r\n name: string;\r\n}\r\n\r\n/**\r\n * A dictionary of index lookup definitions.\r\n */\r\nexport interface IndexLookupDefinitions {\r\n [key: string]: IndexLookupDefinition;\r\n}\r\n\r\n/**\r\n * A group of parts. Usually the item's parts are grouped according\r\n * to their metadata, and presented in this way.\r\n */\r\nexport interface PartGroup {\r\n key: string;\r\n label: string;\r\n parts: Part[];\r\n}\r\n\r\n/**\r\n * Essential information about a user.\r\n */\r\nexport interface UserInfo {\r\n userName: string;\r\n firstName: string;\r\n lastName: string;\r\n}\r\n\r\n/**\r\n * Login credentials.\r\n */\r\nexport interface LoginCredentials {\r\n name: string;\r\n password: string;\r\n}\r\n\r\n// (from @myrmidon/cadmus-ui model editor component base)\r\n/**\r\n * The identifiers for an edited part.\r\n */\r\nexport interface PartIdentity {\r\n itemId: string;\r\n typeId: string;\r\n partId: string | null;\r\n roleId: string | null;\r\n}\r\n\r\n/**\r\n * The identifiers for an edited fragment.\r\n */\r\nexport interface FragmentIdentity extends PartIdentity {\r\n frTypeId: string;\r\n frRoleId: string | null;\r\n loc: string;\r\n}\r\n\r\n/**\r\n * An edited part or fragment.\r\n */\r\nexport interface EditedObject<T extends Part | Fragment> {\r\n value: T | null;\r\n thesauri: ThesauriSet;\r\n layerPart?: TextLayerPart;\r\n baseText?: string;\r\n}\r\n","/**\r\n * A simple text range, expressed as start character index and characters\r\n * length. This is used for misspellings operations.\r\n */\r\nexport class TextRange {\r\n /**\r\n * The start character index.\r\n */\r\n public start: number;\r\n\r\n /**\r\n * The length in characters.\r\n */\r\n public length: number;\r\n\r\n /**\r\n * Parse the specified text representing a range, in the form \"startxlength\"\r\n * or just \"start\" when length is 1.\r\n *\r\n * @param text The text.\r\n */\r\n public static parse(text: string): TextRange | null {\r\n if (!text) {\r\n return null;\r\n }\r\n // [1]=start, ([2]=length)\r\n const m = new RegExp('(\\\\d+)(?:[×x](\\\\d+))?', 'gm').exec(text);\r\n if (!m) {\r\n return null;\r\n }\r\n return new TextRange(parseInt(m[1], 10), m[2] ? parseInt(m[2], 10) : 1);\r\n }\r\n\r\n constructor(start: number, length: number) {\r\n if (start < 0) throw new RangeError('TextRange start less than 0');\r\n if (length < 0) throw new RangeError('TextRange length less than 0');\r\n\r\n this.start = start;\r\n this.length = length;\r\n }\r\n\r\n /**\r\n * Get the inclusive end of the range.\r\n */\r\n public end(): number {\r\n const n = this.start + this.length;\r\n return n > 0 ? n - 1 : 0;\r\n }\r\n\r\n /**\r\n * True if this range value is equal to the other range value.\r\n * @param other The other range.\r\n */\r\n public isEqual(other: TextRange): boolean {\r\n if (!other) {\r\n return false;\r\n }\r\n return this.start === other.start && this.length === other.length;\r\n }\r\n\r\n /**\r\n * Get a parsable textual representation of this range.\r\n * @returns Text.\r\n */\r\n public toString(): string {\r\n return this.length === 1\r\n ? this.start.toString()\r\n : `${this.start}×${this.length}`;\r\n }\r\n}\r\n","/**\r\n * A single point in a token-based textual location.\r\n */\r\nexport class TokenPoint {\r\n y: number;\r\n x: number;\r\n at?: number;\r\n run?: number;\r\n\r\n /**\r\n * Parse the specified text representing a token-based point location.\r\n * @param text The text to parse, in the forms Y.X or Y.X@AxR or\r\n * Y.X@A, where R=1.\r\n */\r\n public static parse(text: string): TokenPoint | null {\r\n const r = new RegExp('^(\\\\d+)\\\\.(\\\\d+)(?:@(\\\\d+)(?:x(\\\\d+))?)?$', 'g');\r\n const m = r.exec(text);\r\n if (!m) {\r\n return null;\r\n }\r\n const pt = new TokenPoint(\r\n parseInt(m[1], 10),\r\n parseInt(m[2], 10),\r\n m[3] ? parseInt(m[3], 10) : 0\r\n );\r\n\r\n if (m[3]) {\r\n if (m[4]) {\r\n pt.run = m[4] ? parseInt(m[4], 10) : 1;\r\n } else {\r\n pt.run = 1;\r\n }\r\n }\r\n return pt;\r\n }\r\n\r\n constructor(y: number, x: number, at = 0, run = 0) {\r\n this.y = y;\r\n this.x = x;\r\n this.at = at;\r\n this.run = run;\r\n }\r\n\r\n public toString(): string {\r\n let s = `${this.y}.${this.x}`;\r\n\r\n if (this.at && this.run) {\r\n s += `@${this.at}`;\r\n if (this.run !== 1) {\r\n s += `x${this.run}`;\r\n }\r\n }\r\n return s;\r\n }\r\n\r\n public compareTo(other: TokenPoint): number {\r\n if (this.y !== other.y) {\r\n return this.y - other.y;\r\n }\r\n if (this.x !== other.x) {\r\n return this.x - other.x;\r\n }\r\n\r\n if (this.at !== other.at) {\r\n return this.at! - other.at!;\r\n }\r\n return this.run! - other.run!;\r\n }\r\n\r\n public integralCompareTo(other: TokenPoint): number {\r\n if (this.y !== other.y) {\r\n return this.y - other.y;\r\n }\r\n if (this.x !== other.x) {\r\n return this.x - other.x;\r\n }\r\n return 0;\r\n }\r\n}\r\n","import { TokenPoint } from './token-point';\r\n\r\nexport class TokenLocation {\r\n public primary: TokenPoint;\r\n public secondary?: TokenPoint;\r\n\r\n /**\r\n * Parse the text representing a token-based location,\r\n * which has the form \"primary-secondary\", or just \"primary\",\r\n * where each of these points has the format required by\r\n * TokenPoint.parse (e.g. Y.X or Y.X@AxR or Y.X@A, where R=1).\r\n * @param text The text to parse.\r\n */\r\n public static parse(text: string): TokenLocation | null {\r\n if (!text) {\r\n return null;\r\n }\r\n const pair = text.split('-', 2);\r\n if (pair.length === 0) {\r\n return null;\r\n }\r\n\r\n // if the primary point cannot be parsed, the whole location is invalid;\r\n // returning a TokenLocation with a null primary here would violate the\r\n // non-nullable TokenPoint type and crash later on any method that\r\n // touches primary (toString, compareTo, overlaps...)\r\n const primary = TokenPoint.parse(pair[0]);\r\n if (!primary) {\r\n return null;\r\n }\r\n\r\n return new TokenLocation(\r\n primary,\r\n pair.length > 1 ? TokenPoint.parse(pair[1]) || undefined : undefined\r\n );\r\n }\r\n\r\n constructor(primary: TokenPoint, secondary?: TokenPoint) {\r\n this.primary = primary;\r\n this.secondary = secondary;\r\n }\r\n\r\n public isRange(): boolean {\r\n // note that != checks for both null and undefined, whereas !== does not\r\n return this.secondary != null;\r\n }\r\n\r\n public toString(): string {\r\n return this.secondary\r\n ? `${this.primary.toString()}-${this.secondary.toString()}`\r\n : this.primary.toString();\r\n }\r\n\r\n public compareTo(other: TokenLocation): number {\r\n const n1 = this.primary.compareTo(other.primary);\r\n if (n1 !== 0) {\r\n return n1;\r\n }\r\n if (this.secondary && other.secondary) {\r\n return this.secondary.compareTo(other.secondary);\r\n }\r\n if (!this.secondary && !other.secondary) {\r\n return 0;\r\n }\r\n return this.secondary ? 1 : -1;\r\n }\r\n\r\n public overlaps(other: TokenLocation): boolean {\r\n // empty coords never overlaps\r\n if (!other.primary) {\r\n return false;\r\n }\r\n\r\n // (in the following comments A=this and B=other)\r\n // 1) if B is a point, cases are:\r\n // 1.1. A is a point: A overlaps with B (both points) if they're equal.\r\n // 1.2. A is a range: A (range) overlaps with B (point)\r\n // when A-left is <= B-left and A-right is >= B-right.\r\n if (other.secondary == null) {\r\n return !this.secondary\r\n ? this.primary.integralCompareTo(other.primary) === 0\r\n : this.primary.compareTo(other.primary) <= 0 &&\r\n this.secondary.compareTo(other.primary) >= 0;\r\n }\r\n\r\n // 2) if B is a range, cases are:\r\n // 2.1. A is a point: A (point) overlaps with B (range) when B-left <= A and\r\n // B-right >= A\r\n // 2.2. A is a range: A (range) overlaps with B (range)\r\n // when B-right >= A-left and B-left <= A-right\r\n return !this.secondary\r\n ? other.primary.compareTo(this.primary) <= 0 &&\r\n other.secondary.compareTo(this.primary) >= 0\r\n : other.secondary.compareTo(this.primary) >= 0 &&\r\n other.primary.compareTo(this.secondary) <= 0;\r\n }\r\n}\r\n","import { inject, Injectable } from '@angular/core';\r\nimport { map, Observable, take } from 'rxjs';\r\nimport { CanDeactivateFn } from '@angular/router';\r\n\r\nimport { DialogService } from '@myrmidon/ngx-mat-tools';\r\n\r\n// https://stackoverflow.com/questions/35922071/warn-user-of-unsaved-changes-before-leaving-page\r\n\r\n/**\r\n * Interface implemented by those components which require a pending changes\r\n * guard. The implementor must keep its canDeactivate property up to date,\r\n * so that it reflects its dirty state.\r\n */\r\nexport interface ComponentCanDeactivate {\r\n canDeactivate: () => boolean | Observable<boolean>;\r\n}\r\n\r\n/**\r\n * Pending changes guard.\r\n * @param component The component to check.\r\n * @returns True if the user can deactivate the component, false otherwise.\r\n */\r\nexport const pendingChangesGuard: CanDeactivateFn<ComponentCanDeactivate> = (\r\n component: ComponentCanDeactivate\r\n) => {\r\n const dialogService = inject(DialogService);\r\n\r\n // if there are no pending changes, just allow deactivation; else confirm first\r\n return !component || component.canDeactivate()\r\n ? true\r\n : dialogService\r\n .confirm('Warning', 'There are unsaved changes. Do you want to leave?')\r\n .pipe(\r\n take(1),\r\n map((yes) => (yes ? true : false))\r\n );\r\n};\r\n\r\n/**\r\n * Legacy pending changes guard.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PendingChangesGuard {\r\n constructor(private _dialogService: DialogService) {}\r\n\r\n canDeactivate(\r\n component: ComponentCanDeactivate\r\n ): boolean | Observable<boolean> {\r\n // if there are no pending changes, just allow deactivation; else confirm first\r\n return !component || component.canDeactivate()\r\n ? true\r\n : this._dialogService\r\n .confirm(\r\n 'Warning',\r\n 'There are unsaved changes. Do you want to leave?'\r\n )\r\n .pipe(\r\n take(1),\r\n map((yes) => (yes ? true : false))\r\n );\r\n }\r\n}\r\n","import { Pipe, PipeTransform } from '@angular/core';\r\n\r\n/**\r\n * Sort pipe. Use like *ngFor=\"let i of items | sort:'propname'\".\r\n */\r\n@Pipe({ name: 'sort' })\r\nexport class SortPipe implements PipeTransform {\r\n transform(value: any[], propName: string): unknown {\r\n if (!value || !Array.isArray(value)) {\r\n return value;\r\n }\r\n return [...value].sort((a, b) => {\r\n if (!a && !b) {\r\n return 0;\r\n }\r\n if (!a && b) {\r\n return -1;\r\n }\r\n if (a && !b) {\r\n return 1;\r\n }\r\n if (a[propName] < b[propName]) {\r\n return -1;\r\n } else if (a[propName] === b[propName]) {\r\n return 0;\r\n } else if (a[propName] > b[propName]) {\r\n return 1;\r\n }\r\n return 0;\r\n });\r\n }\r\n}\r\n","import { Injectable, Inject } from '@angular/core';\r\n\r\nimport { PartDefinition, PartEditorKeys } from '../models';\r\n\r\n/**\r\n * Library route service.\r\n * This service is used to build routes to part and fragment editors,\r\n * which are hosted in an open list of library modules in the Cadmus\r\n * application.\r\n * This architecture allows lazy-loading part- and fragment-editors\r\n * only when they are required.\r\n * Each part type with its dumb UI editor component is located in a\r\n * library, named after the name of the group the part belongs to. For\r\n * instance, the model and dumb UI editor component for a part belonging\r\n * to the \"general\" group are located in the \"parts/general/general-ui\"\r\n * library.\r\n * In turn, the feature UI editor component for the same part is located\r\n * in the \"parts/general/general-feature\" library. This library has\r\n * a route for each part editor. For instance, the NotePart editor\r\n * component route is \"items/:iid/general/it.vedph.note/:pid\", where\r\n * \":iid\" is the item ID and \":pid\" the part ID.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LibraryRouteService {\r\n constructor(\r\n @Inject('partEditorKeys') private _partEditorKeys: PartEditorKeys\r\n ) {}\r\n\r\n /**\r\n * Strip the eventual fragment-role ID from the specified part's role ID.\r\n * For instance, a part's role ID like \"fr.it.vedph.comment:scholarly\"\r\n * becomes \"fr.it.vedph.comment\".\r\n *\r\n * @param roleId The part's role ID.\r\n */\r\n public stripFragmentRoleId(roleId: string): string {\r\n // remove the optional :fr-role from roleId\r\n const i = roleId.lastIndexOf(':');\r\n if (i > -1) {\r\n roleId = roleId.substring(0, i);\r\n }\r\n return roleId;\r\n }\r\n\r\n /**\r\n * Get the fragment type and role from the part's role ID. This starts\r\n * with \"fr.\", and might be followed by the role proper, introduced\r\n * by the first dot if any. For instance, \"fr.it.vedph.comment\" would just\r\n * return \"fr.it.vedph.comment\", while \"fr.it.vedph.comment:scholarly\"\r\n * would return \"fr.it.vedph.comment\". This is required to navigate to\r\n * the correct fragment editor, which is the same for each fragment type,\r\n * independently from its role.\r\n * @param roleId The part role ID.\r\n * @returns An object where frTypeId=fragment type ID and frRoleId=fragment role\r\n * ID, or null.\r\n */\r\n public getFragmentTypeAndRole(roleId?: string): {\r\n frTypeId: string;\r\n frRoleId?: string;\r\n } | null {\r\n if (!roleId || !roleId.startsWith('fr.')) {\r\n return null;\r\n }\r\n const i = roleId.indexOf(':');\r\n if (i > -1) {\r\n return {\r\n frTypeId: roleId.substring(0, i),\r\n frRoleId: roleId.substring(i + 1),\r\n };\r\n } else {\r\n return {\r\n frTypeId: roleId,\r\n frRoleId: undefined,\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Find among the specified parts definitions the one matching the specified\r\n * type ID, and eventually role ID when specified.\r\n *\r\n * @param partDefs The parts definitions.\r\n * @param typeId The type ID.\r\n * @param roleId The role ID or null.\r\n * @returns Part definition or undefined if not found.\r\n */\r\n private findPartDefinition(\r\n partDefs: PartDefinition[],\r\n typeId: string,\r\n roleId: string | null = null\r\n ): PartDefinition | undefined {\r\n if (!partDefs) {\r\n return undefined;\r\n }\r\n\r\n // if role ID is specified, find both type and role\r\n if (roleId) {\r\n const reqRoleId: string = this.stripFragmentRoleId(roleId);\r\n return partDefs.find((d) => {\r\n return (\r\n d.typeId === typeId &&\r\n d.roleId &&\r\n this.stripFragmentRoleId(d.roleId) === reqRoleId\r\n );\r\n });\r\n }\r\n // else just find type ID\r\n return partDefs.find((d) => {\r\n return d.typeId === typeId;\r\n });\r\n }\r\n\r\n /**\r\n * Get the library editor key from the specified part type, looking up\r\n * the specified parts definitions.\r\n *\r\n * @param typeId The part's type ID.\r\n * @param roleId The part's role ID.\r\n */\r\n public getEditorKeyFromPartType(\r\n typeId: string,\r\n roleId?: string\r\n ): { partKey: string; frKey?: string } {\r\n // find the part type ID\r\n const partGroupKey = this._partEditorKeys[typeId];\r\n if (!partGroupKey) {\r\n return {\r\n partKey: 'default',\r\n };\r\n }\r\n\r\n // additionally find the role ID if specified\r\n if (roleId) {\r\n const reqRoleId = this.stripFragmentRoleId(roleId);\r\n return {\r\n partKey: partGroupKey.part,\r\n // fragments may be undefined for part types with no fragments\r\n frKey: partGroupKey.fragments?.[reqRoleId],\r\n };\r\n }\r\n return {\r\n partKey: partGroupKey.part,\r\n };\r\n }\r\n\r\n /**\r\n * Decompose the specified editor key into part and fragment.\r\n * A simple editor key will just provide the same value for both.\r\n *\r\n * @param key The editor key to decompose.\r\n */\r\n public decomposeEditorKey(key: string): { partKey: string; frKey: string } {\r\n const i = key.indexOf(' ');\r\n if (i > -1) {\r\n return {\r\n partKey: key.substring(0, i),\r\n frKey: key.substring(i + 1),\r\n };\r\n } else {\r\n return {\r\n partKey: key,\r\n frKey: key,\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Build the route to the part editor corresponding to the specified\r\n * part.\r\n *\r\n * A part editing route is like\r\n * \"/items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>\",\r\n * where the role ID is optional, and may include the fragment role ID\r\n * as a suffix preceded by a colon.\r\n *\r\n * A fragment editing route is like\r\n * \"/items/<id>/<part-group>/fragment/<part-id>/<fr-typeid>/<loc>?frrid=<role-id>\",\r\n * where the role ID is as above, and the fragment's type ID is derived\r\n * from the part's role ID, stripping the eventual fragment's role ID out.\r\n *\r\n * @param itemId The ID of the item the parts belongs to.\r\n * @param partId The part's ID.\r\n * @param typeId The part's type ID.\r\n * @param roleId The optional part's role ID.\r\n * @returns Object with a route property and an optional rid property\r\n * representing the role ID, which will be rendered as a query parameter.\r\n */\r\n public buildPartEditorRoute(\r\n itemId: string,\r\n partId: string,\r\n typeId: string,\r\n roleId?: string\r\n ): { route: string; rid?: string } {\r\n let route: string;\r\n const editorKey = this.getEditorKeyFromPartType(typeId);\r\n\r\n // /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>\r\n route = `/items/${itemId}/${editorKey.partKey}/${typeId}/${partId}`;\r\n return {\r\n route: route,\r\n rid: roleId,\r\n };\r\n }\r\n\r\n /**\r\n * Build the route to the fragment editor corresponding to the specified\r\n * layers part and location.\r\n *\r\n * @param partDefs The parts definitions.\r\n * @param itemId The ID of the item the parts belongs to.\r\n * @param partId The part's ID.\r\n * @param typeId The part's type ID.\r\n * @param roleId The part's role ID.\r\n * @param loc The fragment's location.\r\n * @returns Object with a route property and an optional rid property\r\n * representing the role ID, which will be rendered as a query parameter.\r\n */\r\n public buildFragmentEditorRoute(\r\n partDefs: PartDefinition[],\r\n itemId: string,\r\n partId: string,\r\n typeId: string,\r\n roleId: string | undefined,\r\n loc: string\r\n ): { route: string; rid?: string } {\r\n let route: string;\r\n const editorKey = this.getEditorKeyFromPartType(typeId, roleId);\r\n // roleId may be undefined or not start with \"fr.\" (e.g. a layer part\r\n // with no specific role); fall back to typeId rather than crashing.\r\n const frInfo = this.getFragmentTypeAndRole(roleId);\r\n const frTypeId = frInfo?.frTypeId ?? typeId;\r\n const frRoleId = frInfo?.frRoleId;\r\n // frKey may be undefined when roleId is missing or has no matching\r\n // fragment mapping; fall back to the part's own group key.\r\n const frKey = editorKey.frKey ?? editorKey.partKey;\r\n\r\n route = `/items/${itemId}/${frKey}/fragment/${partId}/${frTypeId}/${loc}`;\r\n return {\r\n route: route,\r\n rid: frRoleId,\r\n };\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\nimport { TokenPoint } from '../token-point';\r\nimport { TokenLocation } from '../token-location';\r\nimport { TokenTextLayerLine, TextCoords } from '../models';\r\n\r\ninterface TextRange {\r\n start: number;\r\n end: number;\r\n}\r\n\r\n/**\r\n * The selected range of text. This reflects Range useful properties;\r\n * in fact, you can just pass a Range to any method requiring this parameter type,\r\n * but this adds a level of indirection useful in testing.\r\n */\r\nexport interface SelectedRange {\r\n commonAncestorContainer: Node;\r\n startContainer: Node;\r\n startOffset: number;\r\n endContainer: Node;\r\n endOffset: number;\r\n}\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class TextLayerService {\r\n private readonly _wsRegex: RegExp;\r\n\r\n constructor() {\r\n this._wsRegex = new RegExp('^\\\\s$', 'g');\r\n }\r\n\r\n private isWhitespace(c: string): boolean {\r\n if (!c) {\r\n return false;\r\n }\r\n if (c.length !== 1) {\r\n c = c.charAt(0);\r\n }\r\n return this._wsRegex.test(c);\r\n }\r\n\r\n /**\r\n * Extract the lines with their tokens from the specified text.\r\n * @param text the source text.\r\n * @returns lines.\r\n */\r\n public getLines(text: string): TokenTextLayerLine[] {\r\n const results: TokenTextLayerLine[] = [];\r\n if (!text) {\r\n return results;\r\n }\r\n const lines = text.split('\\n');\r\n\r\n for (let y = 0; y < lines.length; y++) {\r\n const line = lines[y].trim();\r\n const l: TokenTextLayerLine = {\r\n y: y + 1,\r\n tokens: [],\r\n };\r\n let x = 0;\r\n let xBeg = 0;\r\n\r\n while (x < line.length) {\r\n if (this.isWhitespace(line.charAt(x))) {\r\n // l.tokens.push(line.substr(xBeg, x - xBeg));\r\n l.tokens.push(line.substring(xBeg, x));\r\n x++;\r\n while (x < line.length && this.isWhitespace(line.charAt(x))) {\r\n x++;\r\n }\r\n xBeg = x;\r\n } else {\r\n x++;\r\n }\r\n }\r\n if (xBeg < x) {\r\n l.tokens.push(line.substring(xBeg));\r\n }\r\n results.push(l);\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Get the fragment of text defined by the specified location.\r\n *\r\n * @param text The full base text.\r\n * @param location The location to get text for.\r\n * @returns A fragment of text corresponding to location.\r\n */\r\n public getTextFragment(text: string, location: TokenLocation): string {\r\n const lines = this.getLines(text);\r\n\r\n if (location.isRange()) {\r\n const sb: string[] = [];\r\n // for each line\r\n let yn = 0;\r\n for (let y = location.primary.y; y <= location.secondary!.y; y++) {\r\n const headLine = location.primary.y === y;\r\n const tailLine = location.secondary!.y === y;\r\n\r\n if (++yn > 1) {\r\n sb.push(' ');\r\n }\r\n\r\n // for each token in line\r\n let xn = 0;\r\n for (\r\n let x = headLine ? location.primary.x : 1;\r\n x <= (tailLine ? location.secondary!.x : lines[y - 1].tokens.length);\r\n x++\r\n ) {\r\n if (++xn > 1) {\r\n sb.push(' ');\r\n }\r\n // get token bounds\r\n let start =\r\n location.primary.at && headLine && x === location.primary.x\r\n ? location.primary.at\r\n : 1;\r\n let len =\r\n location.secondary!.at && tailLine && x === location.secondary!.x\r\n ? location.secondary!.run || 1\r\n : -1;\r\n const token = lines[y - 1].tokens[x - 1];\r\n if (start === 1 && len === -1) {\r\n sb.push(token);\r\n } else {\r\n sb.push(\r\n token.substring(\r\n start - 1,\r\n len === -1 ? undefined : start - 1 + len\r\n )\r\n );\r\n }\r\n }\r\n }\r\n return sb.join('');\r\n } else {\r\n const token =\r\n lines[location.primary.y - 1].tokens[location.primary.x - 1];\r\n return location.primary.at\r\n ? token.substring(\r\n location.primary.at - 1,\r\n location.primary.at - 1 + (location.primary.run || 1)\r\n )\r\n : token;\r\n }\r\n }\r\n\r\n /*\r\n * Rendition: HTML rendering from a base text and a set of fragments locations.\r\n * Each line in the base text is rendered with p; each token in a line is\r\n * rendered with its text value, and tokens are separated by space. Layer\r\n * fragments are rendered inside a span, with an id equal to the fragment location\r\n * plus a suffix beginning with _, added only for the purpose of ensuring unique\r\n * IDs in the rendered HTML code. Example:\r\n * <div>\r\n * <p id=\"y1\">this is line 1.</p>\r\n * <p id=\"y2\">here's a <span id=\"f2.3_0\">fragment</span>.</p>\r\n * </div>\r\n */\r\n\r\n /**\r\n * Render the opening span for a layer fragment.\r\n * @param loc location.\r\n * @param locPortion the index of the token's portion (0-N). This is used\r\n * to build a unique ID for each HTML span rendering a layer fragment.\r\n * @param sb the target strings array.\r\n * @param isSelected true if selected.\r\n */\r\n private renderOpeningSpan(\r\n loc: TokenLocation,\r\n locPortion: number,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n sb.push(\r\n `<span id=\"f${loc.toString()}_${locPortion}\" class=\"fr${\r\n isSelected ? ' fr-sel' : ''\r\n }\">`\r\n );\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified end-fragment location.\r\n * @param pt The point.\r\n * @param token The token.\r\n * @param sb The target array.\r\n */\r\n private renderTokenAtEnd(pt: TokenPoint, token: string, sb: string[]): void {\r\n if (pt.at) {\r\n // ...to]\r\n // sb.push(token.substr(pt.at - 1, pt.run));\r\n sb.push(token.substring(pt.at - 1, (pt.run || 0) + pt.at - 1));\r\n sb.push('</span>');\r\n // ...ken\r\n if (pt.at - 1 + (pt.run || 0) < token.length) {\r\n // sb.push(token.substr(pt.at - 1 + (pt.run || 0)));\r\n sb.push(token.substring(pt.at - 1 + (pt.run || 0)));\r\n }\r\n } else {\r\n // ...token]\r\n sb.push(token);\r\n sb.push('</span>');\r\n }\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified single-point location.\r\n * The received token starts and ends a single-token range.\r\n * @param loc location.\r\n * @param token token.\r\n * @param sb target strings array.\r\n * @param isSelected True if the token is selected.\r\n */\r\n private renderTokenAtPointStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n // 1.token's left-part\r\n if (loc.primary.at) {\r\n // to...\r\n sb.push(token.substring(0, loc.primary.at - 1));\r\n }\r\n\r\n // 2.span: [\r\n this.renderOpeningSpan(loc, 0, sb, isSelected);\r\n\r\n // 3.token's right-part (...ken]/...ke]n or ...token])\r\n this.renderTokenAtEnd(loc.primary, token, sb);\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified range start location.\r\n * The received token starts a multi-tokens range.\r\n * @param loc location.\r\n * @param token token.\r\n * @param sb target strings array.\r\n * @param isSelected True if the token is selected.\r\n */\r\n private renderTokenAtRangeStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n // 1.token's left-part (=before at)\r\n if (loc.primary.at) {\r\n // to...\r\n sb.push(token.substring(0, loc.primary.at - 1));\r\n }\r\n\r\n // 2.span: [\r\n this.renderOpeningSpan(loc, 0, sb, isSelected);\r\n\r\n // 3.token's right-part (...ken or ...token)\r\n if (loc.primary.at) {\r\n // ...ken\r\n sb.push(token.substring(loc.primary.at - 1));\r\n } else {\r\n // ...token\r\n sb.push(token);\r\n }\r\n }\r\n\r\n private renderTokenAtStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): boolean {\r\n if (!loc.secondary) {\r\n // single\r\n this.renderTokenAtPointStart(loc, token, sb, isSelected);\r\n return false;\r\n } else {\r\n // range\r\n this.renderTokenAtRangeStart(loc, token, sb, isSelected);\r\n return true;\r\n }\r\n }\r\n\r\n /**\r\n * Render to HTML the base text decorated with its layer fragments.\r\n * @param text The base text.\r\n * @param locations The locations of all the fragments\r\n * of the same type to be rendered on top of the base text.\r\n * @param selectedLoc The optional location of the selected\r\n * fragment if any. The selected fragment gets decorated with an additional\r\n * class value.\r\n */\r\n public render(\r\n text: string,\r\n locations?: TokenLocation[],\r\n selectedLoc?: TokenLocation\r\n ): string {\r\n if (!text) {\r\n return '<div></div>';\r\n }\r\n\r\n // get lines from text\r\n const sb: string[] = [];\r\n const lines = this.getLines(text);\r\n let loc: TokenLocation | undefined = undefined;\r\n let tokenSelected = false;\r\n\r\n if (!locations) {\r\n locations = [];\r\n }\r\n\r\n // for each line in text\r\n sb.push('<div>');\r\n for (let y = 0; y < lines.length; y++) {\r\n sb.push(`<p id=\"y${y + 1}\">`);\r\n\r\n // reopen a span if continuing a fragment from prev line\r\n if (loc) {\r\n this.renderOpeningSpan(loc, y + 1 - loc.primary.y, sb, tokenSelected);\r\n }\r\n\r\n // for each token in line\r\n const line = lines[y];\r\n for (let x = 0; x < line.tokens.length; x++) {\r\n // add separator if required\r\n if (x > 0) {\r\n sb.push(' ');\r\n }\r\n\r\n const token = line.tokens[x];\r\n\r\n // if inside a fragment, check if this token is the last\r\n if (loc && loc.secondary) {\r\n if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {\r\n this.renderTokenAtEnd(loc.secondary, token, sb);\r\n loc = undefined;\r\n } else {\r\n sb.push(token);\r\n }\r\n } else {\r\n // else, check if this token starts a fragment\r\n loc = locations.find((l) => {\r\n return l.primary.y === y + 1 && l.primary.x === x + 1;\r\n });\r\n if (loc) {\r\n tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;\r\n if (!this.renderTokenAtStart(loc, token, sb, tokenSelected)) {\r\n loc = undefined;\r\n }\r\n } else {\r\n sb.push(token);\r\n }\r\n }\r\n }\r\n\r\n // close a span if pending at p end\r\n if (loc) {\r\n sb.push('</span>');\r\n }\r\n sb.push('</p>');\r\n }\r\n sb.push('</div>');\r\n return sb.join('');\r\n }\r\n\r\n /*\r\n Location: starting from user selection on a rendered text, get the corresponding\r\n layer fragment location. This differs according to the purpose of the location\r\n to be got: if getting a location for an existing fragment, at least 1 decorated\r\n text (span) should be included in the selection, which does not require to be\r\n exact; if getting a location for a new fragment, no decorated text (span) can be\r\n included in the selection (two fragments in the same layer can never overlap),\r\n which must be exact.\r\n */\r\n\r\n /**\r\n * Get the Y bounds from the specified selection.\r\n * @param range The selection range.\r\n * @param forNew True if getting bounds for a new fragment.\r\n * @returns Range, inclusive, or undefined.\r\n */\r\n private getYBoundsFromRange(\r\n range: SelectedRange,\r\n forNew: boolean\r\n ): TextRange | null {\r\n let p: Element | null = null;\r\n\r\n switch (range.commonAncestorContainer.nodeType) {\r\n case Node.TEXT_NODE:\r\n // single-p selection, parent=p\r\n p = range.commonAncestorContainer.parentElement;\r\n if (forNew && (p?.nodeName !== 'P' || !p.hasAttribute('id'))) {\r\n return null;\r\n }\r\n if (p?.nodeName === 'SPAN') {\r\n p = p.parentElement;\r\n }\r\n const y = parseInt(p!.getAttribute('id')!.substring(1), 10);\r\n // return [y, y];\r\n return { start: y, end: y };\r\n\r\n case Node.ELEMENT_NODE:\r\n // div only is allowed; in this case, it's a multi-p range\r\n if (range.commonAncestorContainer.nodeName !== 'DIV') {\r\n return null;\r\n }\r\n // for each div's child p element:\r\n let yMin = 0;\r\n let yMax = 0;\r\n let inside = false;\r\n for (\r\n let i = 0;\r\n i < range.commonAncestorContainer.childNodes.length;\r\n i++\r\n ) {\r\n const child = range.commonAncestorContainer.childNodes[i];\r\n if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== 'P') {\r\n continue;\r\n }\r\n // check if we're entering the start-p\r\n if (!inside && child.contains(range.startContainer)) {\r\n inside = true;\r\n }\r\n // collect y if inside\r\n if (inside) {\r\n const iy = parseInt(\r\n (child as Element)!.getAttribute('id')!.substring(1),\r\n 10\r\n );\r\n if (!yMin || iy < yMin) {\r\n yMin = iy;\r\n }\r\n if (!yMax || iy > yMax) {\r\n yMax = iy;\r\n }\r\n // check if we have exited the last p\r\n if (child.contains(range.endContainer)) {\r\n break;\r\n }\r\n }\r\n }\r\n return {\r\n start: yMin,\r\n end: yMax,\r\n };\r\n }\r\n return null;\r\n }\r\n\r\n private locatePrevSpace(line: string, index: number): number {\r\n while (index > -1 && line.charAt(index) !== ' ') {\r\n index--;\r\n }\r\n return index;\r\n }\r\n\r\n private locateNextSpace(line: string, index: number): number {\r\n while (index < line.length && line.charAt(index) !== ' ') {\r\n index++;\r\n }\r\n return index === line.length ? -1 : index;\r\n }\r\n\r\n /**\r\n * Get the bounds of the token any character of which is indexed\r\n * by index.\r\n * @param line The text line.\r\n * @param index The index to the text line to start from.\r\n * @returns Bounds where start=index of the first character of the token,\r\n * and end=index of the character past the token's last character;\r\n * or null if index was not valid.\r\n */\r\n private getTokenBounds(line: string, index: number): TextRange | null {\r\n if (line.charAt(index) === ' ') {\r\n return null;\r\n }\r\n let start = this.locatePrevSpace(line, index);\r\n if (start === -1) {\r\n start = 0;\r\n } else {\r\n start++;\r\n }\r\n let end = this.locateNextSpace(line, index);\r\n if (end === -1) {\r\n end = line.length;\r\n }\r\n // return [start, end];\r\n return {\r\n start,\r\n end,\r\n };\r\n }\r\n\r\n /**\r\n * Return the received selection bounds, adjusted to exclude spaces.\r\n */\r\n private getAdjustedSelectionBounds(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextRange {\r\n // corner case: if on space, move to right\r\n if (line.charAt(selStart) === ' ') {\r\n selStart++;\r\n }\r\n // corner case: if included trailing space, move to left\r\n if (selEnd > 0 && line.charAt(selEnd - 1) === ' ') {\r\n selEnd--;\r\n }\r\n // return [selStart, selEnd];\r\n return {\r\n start: selStart,\r\n end: selEnd,\r\n };\r\n }\r\n\r\n /**\r\n * Get the start coordinates for the selected range and line.\r\n * @param range The selected range.\r\n * @param line The reference text line.\r\n */\r\n private getStartCoordsFromRange(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextCoords {\r\n // get adjusted selection bounds\r\n const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);\r\n\r\n // get the bounds of the first selected token\r\n const tokBounds = this.getTokenBounds(line, selBounds.start)!;\r\n\r\n // calculate x by counting the tokens before the target token\r\n let x = 1;\r\n let j = tokBounds.start - 1;\r\n while (j > -1) {\r\n if (line.charAt(j) === ' ') {\r\n x++;\r\n }\r\n j--;\r\n }\r\n\r\n // calculate at,run only when either of these is true:\r\n // (a) selection starts past the 1st char of the token (al[pha);\r\n // (b) selection ends before the last char of the token (al]pha);\r\n // run is calculated only if (b) is true.\r\n let at = 0;\r\n let run = 0;\r\n if (selBounds.start > tokBounds.start || selBounds.end < tokBounds.end) {\r\n at = 1 + selBounds.start - tokBounds.start;\r\n run =\r\n (selBounds.end < tokBounds.end\r\n ? selBounds.end // al]pha\r\n : tokBounds.end) - // alpha]\r\n Math.max(tokBounds.start, selBounds.start);\r\n }\r\n\r\n return {\r\n y: 0,\r\n x,\r\n at,\r\n run,\r\n };\r\n }\r\n\r\n private getEndCoordsFromRange(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextCoords {\r\n // get adjusted selection bounds\r\n const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);\r\n // get the bounds of the last selected token\r\n const tokBounds = this.getTokenBounds(line, selBounds.end - 1)!;\r\n\r\n // calculate x by counting the tokens before the target token\r\n let x = 1;\r\n let j = selBounds.end - 1;\r\n while (j > -1) {\r\n if (line.charAt(j) === ' ') {\r\n x++;\r\n }\r\n j--;\r\n }\r\n\r\n // calculate at,run only when selection ends before the 1st char of the token\r\n // (al]pha); run is calculated only if at is calculated.\r\n let at = 0;\r\n let run = 0;\r\n if (selBounds.end < tokBounds.end) {\r\n at =\r\n selBounds.start > tokBounds.start\r\n ? 1 + selBounds.start - tokBounds.start\r\n : 1;\r\n run = selBounds.end - tokBounds.start;\r\n }\r\n\r\n return {\r\n y: 0,\r\n x,\r\n at,\r\n run,\r\n };\r\n }\r\n\r\n private getSpanLocFromId(id: string): TokenLocation | null {\r\n if (!id) {\r\n return null;\r\n }\r\n const r = new RegExp('^f([-\\\\d+.@x]+)', 'g');\r\n const m = r.exec(id);\r\n if (!m) {\r\n return null;\r\n }\r\n return TokenLocation.parse(m[1]);\r\n }\r\n\r\n private visitNodes(node: Node, visitor: (current: Node) => boolean): void {\r\n if (!visitor(node)) {\r\n return;\r\n }\r\n if (node.nodeType === Node.ELEMENT_NODE) {\r\n for (let i = 0; i < node.childNodes.length; i++) {\r\n const child = node.childNodes[i];\r\n this.visitNodes(child, visitor);\r\n }\r\n }\r\n }\r\n\r\n private findFirstDescendantSpan(range: SelectedRange): Element | null {\r\n let inside = false;\r\n let span = null;\r\n\r\n this.visitNodes(range.commonAncestorContainer, (current) => {\r\n if (current === range.startContainer) {\r\n inside = true;\r\n }\r\n if (\r\n current.nodeType === Node.ELEMENT_NODE &&\r\n current.nodeName === 'SPAN'\r\n ) {\r\n span = current;\r\n return false;\r\n }\r\n if (current === range.endContainer) {\r\n inside = false;\r\n }\r\n return true;\r\n });\r\n\r\n return span;\r\n }\r\n\r\n /**\r\n * Get the base offset for the specified node. This is used\r\n * when the start container of the selected range has any\r\n * preceding sibling node, which happens only when you have\r\n * any spans in the p element (=the line). In this case,\r\n * the selection offset starts from the start container node,\r\n * which is preceded by other nodes including other text.\r\n * As we must get the line-based offset, we have to start\r\n * from a base offset equal to the sum of the lengths of\r\n * all the preceding siblings.\r\n */\r\n private getNodeBaseOffset(node: Node): number {\r\n let offset = 0;\r\n let n: Node | null = node;\r\n n = node.previousSibling;\r\n while (n) {\r\n offset +=\r\n n.nodeType === Node.ELEMENT_NODE\r\n ? (n as any).innerText?.length || 0\r\n : n.textContent?.length || 0;\r\n n = n.previousSibling;\r\n }\r\n return offset;\r\n }\r\n\r\n /**\r\n * Get the location corresponding to the user selection,\r\n * for editing the first fragment included in it.\r\n * @param range The selected range. You can get it from the\r\n * current selection using getSelectedRange().\r\n * @returns The token location or null.\r\n */\r\n public getSelectedLocationForEdit(\r\n range: SelectedRange\r\n ): TokenLocation | null {\r\n if (!range) {\r\n return null;\r\n }\r\n // just find the first descendant span in selection\r\n let span: Element | null = null;\r\n switch (range.commonAncestorContainer.nodeType) {\r\n case Node.ELEMENT_NODE:\r\n span = range.commonAncestorContainer as Element;\r\n if (span.nodeName !== 'SPAN') {\r\n span = this.findFirstDescendantSpan(range);\r\n }\r\n break;\r\n case Node.TEXT_NODE:\r\n span = range.commonAncestorContainer.parentElement;\r\n if (\r\n span &&\r\n (span.nodeType !== Node.ELEMENT_NODE || span.nodeName !== 'SPAN')\r\n ) {\r\n span = null;\r\n }\r\n break;\r\n }\r\n\r\n return span ? this.getSpanLocFromId(span.getAttribute('id')!) : null;\r\n }\r\n\r\n private textLineToString(line: TokenTextLayerLine): string {\r\n if (!line || !line.tokens) {\r\n return '';\r\n }\r\n return line.tokens.join(' ');\r\n }\r\n\r\n private buildCoords(\r\n start: TextCoords,\r\n end: TextCoords,\r\n singleToken: boolean\r\n ): string {\r\n const sb = [];\r\n // start: y.x\r\n sb.push(`${start.y}.${start.x}`);\r\n\r\n if (singleToken) {\r\n // single token: check for at,run\r\n if (start.at) {\r\n sb.push(`@${start.at}`);\r\n if (start.run && start.run > 1) {\r\n sb.push(`x${start.run}`);\r\n }\r\n }\r\n } else {\r\n // not a single token\r\n // first token\r\n if (start.at) {\r\n sb.push(`@${start.at}x${start.run}`);\r\n }\r\n // last token\r\n sb.push(`-${end.y}.${end.x}`);\r\n if (end.at) {\r\n sb.push(`@1x${end.run}`);\r\n }\r\n }\r\n return sb.join('');\r\n }\r\n\r\n /**\r\n * Recursively find the node matching the specified matcher\r\n * function, starting from the specified node (included).\r\n *\r\n * @param node The node to start from.\r\n * @param matcher The matcher function, which receives a node\r\n * to match, and returns 1=match, 0=no match, -1=stop the\r\n * find operation with a no match.\r\n * @return 1=match, 0=no match, -1=stop the find operation with a no match.\r\n */\r\n private matchNode(node: Node, matcher: (n: Node) => number): number {\r\n // self\r\n const n = matcher(node);\r\n if (n) {\r\n return n;\r\n }\r\n\r\n // children\r\n if (node.hasChildNodes()) {\r\n for (let i = 0; i < node.childNodes.length; i++) {\r\n const child = node.childNodes[i];\r\n const m = this.matchNode(child, matcher);\r\n if (m) {\r\n return m;\r\n }\r\n }\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n private selHasAnySpan(range: SelectedRange): boolean {\r\n let inside = false;\r\n if (\r\n // the selected text node must not be child of a span\r\n range.startContainer.parentElement?.tagName === 'SPAN' ||\r\n range.endContainer.parentElement?.tagName === 'SPAN' ||\r\n // the nodes tree from the common ancestor, from the start node\r\n // up to the end node, must not include any span\r\n this.matchNode(range.commonAncestorContainer, (node: Node) => {\r\n // start checking only when start node reached\r\n if (node === range.startContainer) {\r\n inside = true;\r\n }\r\n if (!inside) {\r\n return 0;\r\n }\r\n // stop checking when end node reached\r\n if (node === range.endContainer) {\r\n return -1;\r\n }\r\n // node cannot be a span\r\n if (\r\n node.nodeType === Node.ELEMENT_NODE &&\r\n (node as Element).tagName === 'SPAN'\r\n ) {\r\n return 1;\r\n }\r\n return 0;\r\n }) === 1\r\n ) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Get the location corresponding to the user selection,\r\n * for adding a new fragment with the same extension.\r\n * @param range The selected range. You can get it from the\r\n * current selection using getSelectedRange().\r\n * @param text The full base text.\r\n * @returns TokenLocation The token location or undefined.\r\n */\r\n public getSelectedLocationForNew(\r\n range: SelectedRange,\r\n text: string\r\n ): TokenLocation | null {\r\n if (!range || this.selHasAnySpan(range)) {\r\n return null;\r\n }\r\n\r\n // get y bounds (min, max; equal if single-line)\r\n const yBounds = this.getYBoundsFromRange(range, true);\r\n if (!yBounds) {\r\n return null;\r\n }\r\n\r\n // get lines and calculate start/end coords\r\n const lines = this.getLines(text);\r\n const startLine = this.textLineToString(lines[yBounds.start - 1]);\r\n const endLine = this.textLineToString(lines[yBounds.end - 1]);\r\n\r\n // get the base offsets\r\n const startBaseOffset = this.getNodeBaseOffset(range.startContainer);\r\n const endBaseOffset = this.getNodeBaseOffset(range.endContainer);\r\n\r\n // get the start (including the base offset)\r\n const startLineEndOffset =\r\n yBounds.start !== yBounds.end\r\n ? startLine.length\r\n : range.endOffset + startBaseOffset;\r\n\r\n const start = this.getStartCoordsFromRange(\r\n range.startOffset + startBaseOffset,\r\n startLineEndOffset,\r\n startLine\r\n );\r\n start.y = yBounds.start;\r\n\r\n // get the end (including the base offset)\r\n const end =\r\n yBounds.start !== yBounds.end\r\n ? this.getEndCoordsFromRange(\r\n 0,\r\n range.endOffset + endBaseOffset,\r\n endLine\r\n )\r\n : this.getEndCoordsFromRange(\r\n range.startOffset + endBaseOffset,\r\n range.endOffset + endBaseOffset,\r\n endLine\r\n );\r\n end.y = yBounds.end;\r\n const singleLine = start.y === end.y;\r\n const singleToken = singleLine && start.x === end.x;\r\n\r\n const coords = this.buildCoords(start, end, singleToken);\r\n return TokenLocation.parse(coords);\r\n }\r\n\r\n /**\r\n * Get the currently selected range in the browser's document.\r\n */\r\n public getSelectedRange(): Range | null {\r\n const sel = window.getSelection();\r\n if (!sel || sel.isCollapsed) {\r\n return null;\r\n }\r\n return sel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BAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAgB,YADH;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAgB,YAAA,CAAA;EAD5B,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE"}
1
+ {"version":3,"file":"myrmidon-cadmus-core.mjs","names":[],"sources":["../../../../projects/myrmidon/cadmus-core/src/lib/models.ts","../../../../projects/myrmidon/cadmus-core/src/lib/text-range.ts","../../../../projects/myrmidon/cadmus-core/src/lib/token-point.ts","../../../../projects/myrmidon/cadmus-core/src/lib/token-location.ts","../../../../projects/myrmidon/cadmus-core/src/lib/guards/pending-changes.guard.ts","../../../../projects/myrmidon/cadmus-core/src/lib/pipes/sort.pipe.ts","../../../../projects/myrmidon/cadmus-core/src/lib/services/library-route.service.ts","../../../../projects/myrmidon/cadmus-core/src/lib/services/text-layer.service.ts"],"sourcesContent":["/**\r\n * Interface implemented by versioned storage objects.\r\n */\r\nexport interface HasVersion {\r\n timeCreated: Date;\r\n creatorId: string;\r\n timeModified: Date;\r\n userId: string;\r\n}\r\n\r\n/**\r\n * Item's properties, excluding its parts.\r\n */\r\nexport interface Item extends HasVersion {\r\n id: string;\r\n title: string;\r\n description: string;\r\n facetId: string;\r\n groupId: string;\r\n sortKey: string;\r\n flags: number;\r\n parts?: Part[];\r\n}\r\n\r\n/**\r\n * Flags matching mode.\r\n */\r\nexport enum FlagMatching {\r\n // the none value is frontend-side only, as in the backend\r\n // the flags property in ItemFilter is nullable\r\n none = -1,\r\n bitsAllSet = 0,\r\n bitsAnySet,\r\n bitsAllClear,\r\n bitsAnyClear,\r\n}\r\n\r\n/**\r\n * Filter for items.\r\n */\r\nexport interface ItemFilter {\r\n title?: string;\r\n description?: string;\r\n facetId?: string;\r\n groupId?: string;\r\n flags?: number;\r\n flagMatching?: FlagMatching;\r\n minModified?: Date;\r\n maxModified?: Date;\r\n userId?: string;\r\n}\r\n\r\n/**\r\n * Essential information about an item.\r\n */\r\nexport interface ItemInfo extends HasVersion {\r\n id: string;\r\n title: string;\r\n description: string;\r\n facetId: string;\r\n groupId: string;\r\n sortKey: string;\r\n flags: number;\r\n payload?: any;\r\n}\r\n\r\n/**\r\n * Information about a data pin; returned by pins search.\r\n */\r\nexport interface DataPinInfo {\r\n itemId: string;\r\n partId: string;\r\n roleId: string | null;\r\n partTypeId: string;\r\n name: string;\r\n value: string;\r\n tag?: string;\r\n}\r\n\r\n/**\r\n * Data pin value type in a DataPinDefinition.\r\n */\r\nexport enum DataPinValueType {\r\n string = 0,\r\n boolean,\r\n integer,\r\n decimal,\r\n}\r\n\r\n/**\r\n * Definition of a data pin.\r\n */\r\nexport interface DataPinDefinition {\r\n name: string;\r\n type: DataPinValueType;\r\n tip?: string;\r\n attributes?: string;\r\n}\r\n\r\n/**\r\n * Part type and role IDs.\r\n */\r\nexport interface PartTypeIds {\r\n typeId: string;\r\n roleId?: string;\r\n}\r\n\r\n/**\r\n * Part. This is the minimal set of properties present in all the\r\n * parts. Each part then adds its own properties, extending this interface.\r\n */\r\nexport interface Part extends HasVersion, PartTypeIds {\r\n id: string;\r\n itemId: string;\r\n thesaurusScope?: string;\r\n}\r\n\r\n/**\r\n * Essential information about a layer part.\r\n */\r\nexport interface LayerPartInfo extends HasVersion, PartTypeIds {\r\n id: string;\r\n itemId: string;\r\n fragmentCount: number;\r\n isAbsent: boolean;\r\n}\r\n\r\n/**\r\n * Text layer fragment. This is the minimal set of properties present in all the\r\n * fragments. Each fragment then adds its own properties, extending this\r\n * interface.\r\n * Every fragment has a location, and can be enriched with the corresponding\r\n * base text when used in views.\r\n */\r\nexport interface Fragment {\r\n location: string;\r\n baseText?: string;\r\n}\r\n\r\n/**\r\n * Text layer part. This represents a special type of part,\r\n * whose only content is a collection of fragments.\r\n */\r\nexport interface TextLayerPart extends Part {\r\n fragments: Fragment[];\r\n}\r\n\r\n/**\r\n * A text line in a base text part.\r\n */\r\nexport interface TokenTextLayerLine {\r\n y: number;\r\n tokens: string[];\r\n}\r\n\r\n/**\r\n * Token-based text coordinates.\r\n */\r\nexport interface TextCoords {\r\n y: number;\r\n x: number;\r\n at?: number;\r\n run?: number;\r\n}\r\n\r\n/**\r\n * Layer reconciliation hint for a single fragment.\r\n */\r\nexport interface LayerHint {\r\n location: string;\r\n editOperation: string;\r\n patchOperation?: string;\r\n impactLevel: number;\r\n description?: string;\r\n}\r\n\r\n/**\r\n * A single entry in a thesaurus.\r\n */\r\nexport interface ThesaurusEntry {\r\n id: string;\r\n value: string;\r\n}\r\n\r\n/**\r\n * A set of thesaurus entries.\r\n */\r\nexport interface Thesaurus {\r\n id: string;\r\n language?: string;\r\n targetId?: string;\r\n entries?: ThesaurusEntry[];\r\n}\r\n\r\n/**\r\n * A set of thesauri which get passed to an editor component.\r\n * In the set, each thesaurus is identified by an arbitrarily\r\n * defined key, which is unique only within the context of the editor\r\n * consuming the set, and refers to frontend only.\r\n */\r\nexport interface ThesauriSet {\r\n [key: string]: Thesaurus;\r\n}\r\n\r\n/**\r\n * Filter for thesauri.\r\n */\r\nexport interface ThesaurusFilter {\r\n id?: string;\r\n isAlias?: boolean;\r\n language?: string;\r\n}\r\n\r\n/**\r\n * Part definition in a facet.\r\n */\r\nexport interface PartDefinition extends PartTypeIds {\r\n name: string;\r\n description?: string;\r\n isRequired?: boolean;\r\n colorKey?: string;\r\n groupKey?: string;\r\n sortKey?: string;\r\n}\r\n\r\n/**\r\n * Fragment definition in a facet.\r\n */\r\n/**\r\n * Facet definition.\r\n */\r\nexport interface FacetDefinition {\r\n id: string;\r\n label: string;\r\n colorKey: string;\r\n description: string;\r\n partDefinitions: PartDefinition[];\r\n}\r\n\r\n/**\r\n * Flag definition.\r\n */\r\nexport interface FlagDefinition {\r\n id: number;\r\n label: string;\r\n description: string;\r\n colorKey: string;\r\n isAdmin?: boolean;\r\n}\r\n\r\n/**\r\n * The group key for a part type. This is used in EditorKeys objects\r\n * to map a specific part ID with all its fragment IDs into group key(s).\r\n * The part ID is used alone with normal parts; for layer parts, it is\r\n * used in conjunction with 1 or more fragment type IDs, each mapped to\r\n * a corresponding editor key.\r\n */\r\nexport interface PartGroupKey {\r\n part: string;\r\n fragments?: { [key: string]: string };\r\n}\r\n\r\n/**\r\n * Part type IDs to editor keys mappings. This contains a set of component\r\n * type IDs (parts and parts + fragments) mapped to editor keys, which are\r\n * used to build their routes in the UI.\r\n */\r\nexport interface PartEditorKeys {\r\n [key: string]: PartGroupKey;\r\n}\r\n\r\n/**\r\n * An index lookup definition, used in dynamic lookup to provide the set\r\n * of parameters required for a data pins based search.\r\n */\r\nexport interface IndexLookupDefinition {\r\n typeId?: string;\r\n roleId?: string;\r\n name: string;\r\n}\r\n\r\n/**\r\n * A dictionary of index lookup definitions.\r\n */\r\nexport interface IndexLookupDefinitions {\r\n [key: string]: IndexLookupDefinition;\r\n}\r\n\r\n/**\r\n * A group of parts. Usually the item's parts are grouped according\r\n * to their metadata, and presented in this way.\r\n */\r\nexport interface PartGroup {\r\n key: string;\r\n label: string;\r\n parts: Part[];\r\n}\r\n\r\n/**\r\n * Essential information about a user.\r\n */\r\nexport interface UserInfo {\r\n userName: string;\r\n firstName: string;\r\n lastName: string;\r\n}\r\n\r\n/**\r\n * Login credentials.\r\n */\r\nexport interface LoginCredentials {\r\n name: string;\r\n password: string;\r\n}\r\n\r\n// (from @myrmidon/cadmus-ui model editor component base)\r\n/**\r\n * The identifiers for an edited part.\r\n */\r\nexport interface PartIdentity {\r\n itemId: string;\r\n typeId: string;\r\n partId: string | null;\r\n roleId: string | null;\r\n}\r\n\r\n/**\r\n * The identifiers for an edited fragment.\r\n */\r\nexport interface FragmentIdentity extends PartIdentity {\r\n frTypeId: string;\r\n frRoleId: string | null;\r\n loc: string;\r\n}\r\n\r\n/**\r\n * An edited part or fragment.\r\n */\r\nexport interface EditedObject<T extends Part | Fragment> {\r\n value: T | null;\r\n thesauri: ThesauriSet;\r\n layerPart?: TextLayerPart;\r\n baseText?: string;\r\n}\r\n\n/**\n * The edit status of a history record.\n */\nexport enum EditStatus {\n created = 0,\n updated = 1,\n deleted = 2,\n}\n\n/**\n * Essential properties of a history record, i.e. of a saved version\n * of an item or part. History stores the state of the item or part\n * as it was saved, so the newest history record is the current state.\n */\nexport interface HistoryInfo extends HasVersion {\n /**\n * The ID of the history record (not of the item or part).\n */\n id: string;\n /**\n * The ID of the item or part this record refers to.\n */\n referenceId: string;\n /**\n * The edit status.\n */\n status: EditStatus;\n}\n\n/**\n * Information about a history item.\n */\nexport interface HistoryItemInfo extends HistoryInfo {\n title?: string;\n description?: string;\n facetId?: string;\n groupId?: string;\n sortKey?: string;\n flags: number;\n}\n\n/**\n * A history item, i.e. a saved version of an item's metadata (with no\n * parts).\n */\nexport interface HistoryItem extends HistoryInfo {\n title: string;\n description: string;\n facetId: string;\n groupId?: string;\n sortKey: string;\n flags: number;\n}\n\n/**\n * Information about a history part.\n */\nexport interface HistoryPartInfo extends HistoryInfo {\n itemId?: string;\n typeId?: string;\n roleId?: string;\n}\n\n/**\n * A history part, i.e. a saved version of a part, which is in its\n * part property.\n */\nexport interface HistoryPart<T extends Part = Part> extends HistoryPartInfo {\n part: T;\n}\n\n/**\n * Filter for the history of a single item or part.\n */\nexport interface HistoryFilter {\n minModified?: Date;\n maxModified?: Date;\n userId?: string;\n status?: EditStatus;\n}\n","/**\r\n * A simple text range, expressed as start character index and characters\r\n * length. This is used for misspellings operations.\r\n */\r\nexport class TextRange {\r\n /**\r\n * The start character index.\r\n */\r\n public start: number;\r\n\r\n /**\r\n * The length in characters.\r\n */\r\n public length: number;\r\n\r\n /**\r\n * Parse the specified text representing a range, in the form \"startxlength\"\r\n * or just \"start\" when length is 1.\r\n *\r\n * @param text The text.\r\n */\r\n public static parse(text: string): TextRange | null {\r\n if (!text) {\r\n return null;\r\n }\r\n // [1]=start, ([2]=length)\r\n const m = new RegExp('(\\\\d+)(?:[×x](\\\\d+))?', 'gm').exec(text);\r\n if (!m) {\r\n return null;\r\n }\r\n return new TextRange(parseInt(m[1], 10), m[2] ? parseInt(m[2], 10) : 1);\r\n }\r\n\r\n constructor(start: number, length: number) {\r\n if (start < 0) throw new RangeError('TextRange start less than 0');\r\n if (length < 0) throw new RangeError('TextRange length less than 0');\r\n\r\n this.start = start;\r\n this.length = length;\r\n }\r\n\r\n /**\r\n * Get the inclusive end of the range.\r\n */\r\n public end(): number {\r\n const n = this.start + this.length;\r\n return n > 0 ? n - 1 : 0;\r\n }\r\n\r\n /**\r\n * True if this range value is equal to the other range value.\r\n * @param other The other range.\r\n */\r\n public isEqual(other: TextRange): boolean {\r\n if (!other) {\r\n return false;\r\n }\r\n return this.start === other.start && this.length === other.length;\r\n }\r\n\r\n /**\r\n * Get a parsable textual representation of this range.\r\n * @returns Text.\r\n */\r\n public toString(): string {\r\n return this.length === 1\r\n ? this.start.toString()\r\n : `${this.start}×${this.length}`;\r\n }\r\n}\r\n","/**\r\n * A single point in a token-based textual location.\r\n */\r\nexport class TokenPoint {\r\n y: number;\r\n x: number;\r\n at?: number;\r\n run?: number;\r\n\r\n /**\r\n * Parse the specified text representing a token-based point location.\r\n * @param text The text to parse, in the forms Y.X or Y.X@AxR or\r\n * Y.X@A, where R=1.\r\n */\r\n public static parse(text: string): TokenPoint | null {\r\n const r = new RegExp('^(\\\\d+)\\\\.(\\\\d+)(?:@(\\\\d+)(?:x(\\\\d+))?)?$', 'g');\r\n const m = r.exec(text);\r\n if (!m) {\r\n return null;\r\n }\r\n const pt = new TokenPoint(\r\n parseInt(m[1], 10),\r\n parseInt(m[2], 10),\r\n m[3] ? parseInt(m[3], 10) : 0\r\n );\r\n\r\n if (m[3]) {\r\n if (m[4]) {\r\n pt.run = m[4] ? parseInt(m[4], 10) : 1;\r\n } else {\r\n pt.run = 1;\r\n }\r\n }\r\n return pt;\r\n }\r\n\r\n constructor(y: number, x: number, at = 0, run = 0) {\r\n this.y = y;\r\n this.x = x;\r\n this.at = at;\r\n this.run = run;\r\n }\r\n\r\n public toString(): string {\r\n let s = `${this.y}.${this.x}`;\r\n\r\n if (this.at && this.run) {\r\n s += `@${this.at}`;\r\n if (this.run !== 1) {\r\n s += `x${this.run}`;\r\n }\r\n }\r\n return s;\r\n }\r\n\r\n public compareTo(other: TokenPoint): number {\r\n if (this.y !== other.y) {\r\n return this.y - other.y;\r\n }\r\n if (this.x !== other.x) {\r\n return this.x - other.x;\r\n }\r\n\r\n if (this.at !== other.at) {\r\n return this.at! - other.at!;\r\n }\r\n return this.run! - other.run!;\r\n }\r\n\r\n public integralCompareTo(other: TokenPoint): number {\r\n if (this.y !== other.y) {\r\n return this.y - other.y;\r\n }\r\n if (this.x !== other.x) {\r\n return this.x - other.x;\r\n }\r\n return 0;\r\n }\r\n}\r\n","import { TokenPoint } from './token-point';\r\n\r\nexport class TokenLocation {\r\n public primary: TokenPoint;\r\n public secondary?: TokenPoint;\r\n\r\n /**\r\n * Parse the text representing a token-based location,\r\n * which has the form \"primary-secondary\", or just \"primary\",\r\n * where each of these points has the format required by\r\n * TokenPoint.parse (e.g. Y.X or Y.X@AxR or Y.X@A, where R=1).\r\n * @param text The text to parse.\r\n */\r\n public static parse(text: string): TokenLocation | null {\r\n if (!text) {\r\n return null;\r\n }\r\n const pair = text.split('-', 2);\r\n if (pair.length === 0) {\r\n return null;\r\n }\r\n\r\n // if the primary point cannot be parsed, the whole location is invalid;\r\n // returning a TokenLocation with a null primary here would violate the\r\n // non-nullable TokenPoint type and crash later on any method that\r\n // touches primary (toString, compareTo, overlaps...)\r\n const primary = TokenPoint.parse(pair[0]);\r\n if (!primary) {\r\n return null;\r\n }\r\n\r\n return new TokenLocation(\r\n primary,\r\n pair.length > 1 ? TokenPoint.parse(pair[1]) || undefined : undefined\r\n );\r\n }\r\n\r\n constructor(primary: TokenPoint, secondary?: TokenPoint) {\r\n this.primary = primary;\r\n this.secondary = secondary;\r\n }\r\n\r\n public isRange(): boolean {\r\n // note that != checks for both null and undefined, whereas !== does not\r\n return this.secondary != null;\r\n }\r\n\r\n public toString(): string {\r\n return this.secondary\r\n ? `${this.primary.toString()}-${this.secondary.toString()}`\r\n : this.primary.toString();\r\n }\r\n\r\n public compareTo(other: TokenLocation): number {\r\n const n1 = this.primary.compareTo(other.primary);\r\n if (n1 !== 0) {\r\n return n1;\r\n }\r\n if (this.secondary && other.secondary) {\r\n return this.secondary.compareTo(other.secondary);\r\n }\r\n if (!this.secondary && !other.secondary) {\r\n return 0;\r\n }\r\n return this.secondary ? 1 : -1;\r\n }\r\n\r\n public overlaps(other: TokenLocation): boolean {\r\n // empty coords never overlaps\r\n if (!other.primary) {\r\n return false;\r\n }\r\n\r\n // (in the following comments A=this and B=other)\r\n // 1) if B is a point, cases are:\r\n // 1.1. A is a point: A overlaps with B (both points) if they're equal.\r\n // 1.2. A is a range: A (range) overlaps with B (point)\r\n // when A-left is <= B-left and A-right is >= B-right.\r\n if (other.secondary == null) {\r\n return !this.secondary\r\n ? this.primary.integralCompareTo(other.primary) === 0\r\n : this.primary.compareTo(other.primary) <= 0 &&\r\n this.secondary.compareTo(other.primary) >= 0;\r\n }\r\n\r\n // 2) if B is a range, cases are:\r\n // 2.1. A is a point: A (point) overlaps with B (range) when B-left <= A and\r\n // B-right >= A\r\n // 2.2. A is a range: A (range) overlaps with B (range)\r\n // when B-right >= A-left and B-left <= A-right\r\n return !this.secondary\r\n ? other.primary.compareTo(this.primary) <= 0 &&\r\n other.secondary.compareTo(this.primary) >= 0\r\n : other.secondary.compareTo(this.primary) >= 0 &&\r\n other.primary.compareTo(this.secondary) <= 0;\r\n }\r\n}\r\n","import { inject, Injectable } from '@angular/core';\r\nimport { map, Observable, take } from 'rxjs';\r\nimport { CanDeactivateFn } from '@angular/router';\r\n\r\nimport { DialogService } from '@myrmidon/ngx-mat-tools';\r\n\r\n// https://stackoverflow.com/questions/35922071/warn-user-of-unsaved-changes-before-leaving-page\r\n\r\n/**\r\n * Interface implemented by those components which require a pending changes\r\n * guard. The implementor must keep its canDeactivate property up to date,\r\n * so that it reflects its dirty state.\r\n */\r\nexport interface ComponentCanDeactivate {\r\n canDeactivate: () => boolean | Observable<boolean>;\r\n}\r\n\r\n/**\r\n * Pending changes guard.\r\n * @param component The component to check.\r\n * @returns True if the user can deactivate the component, false otherwise.\r\n */\r\nexport const pendingChangesGuard: CanDeactivateFn<ComponentCanDeactivate> = (\r\n component: ComponentCanDeactivate\r\n) => {\r\n const dialogService = inject(DialogService);\r\n\r\n // if there are no pending changes, just allow deactivation; else confirm first\r\n return !component || component.canDeactivate()\r\n ? true\r\n : dialogService\r\n .confirm('Warning', 'There are unsaved changes. Do you want to leave?')\r\n .pipe(\r\n take(1),\r\n map((yes) => (yes ? true : false))\r\n );\r\n};\r\n\r\n/**\r\n * Legacy pending changes guard.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PendingChangesGuard {\r\n constructor(private _dialogService: DialogService) {}\r\n\r\n canDeactivate(\r\n component: ComponentCanDeactivate\r\n ): boolean | Observable<boolean> {\r\n // if there are no pending changes, just allow deactivation; else confirm first\r\n return !component || component.canDeactivate()\r\n ? true\r\n : this._dialogService\r\n .confirm(\r\n 'Warning',\r\n 'There are unsaved changes. Do you want to leave?'\r\n )\r\n .pipe(\r\n take(1),\r\n map((yes) => (yes ? true : false))\r\n );\r\n }\r\n}\r\n","import { Pipe, PipeTransform } from '@angular/core';\r\n\r\n/**\r\n * Sort pipe. Use like *ngFor=\"let i of items | sort:'propname'\".\r\n */\r\n@Pipe({ name: 'sort' })\r\nexport class SortPipe implements PipeTransform {\r\n transform(value: any[], propName: string): unknown {\r\n if (!value || !Array.isArray(value)) {\r\n return value;\r\n }\r\n return [...value].sort((a, b) => {\r\n if (!a && !b) {\r\n return 0;\r\n }\r\n if (!a && b) {\r\n return -1;\r\n }\r\n if (a && !b) {\r\n return 1;\r\n }\r\n if (a[propName] < b[propName]) {\r\n return -1;\r\n } else if (a[propName] === b[propName]) {\r\n return 0;\r\n } else if (a[propName] > b[propName]) {\r\n return 1;\r\n }\r\n return 0;\r\n });\r\n }\r\n}\r\n","import { Injectable, Inject } from '@angular/core';\r\n\r\nimport { PartDefinition, PartEditorKeys } from '../models';\r\n\r\n/**\r\n * Library route service.\r\n * This service is used to build routes to part and fragment editors,\r\n * which are hosted in an open list of library modules in the Cadmus\r\n * application.\r\n * This architecture allows lazy-loading part- and fragment-editors\r\n * only when they are required.\r\n * Each part type with its dumb UI editor component is located in a\r\n * library, named after the name of the group the part belongs to. For\r\n * instance, the model and dumb UI editor component for a part belonging\r\n * to the \"general\" group are located in the \"parts/general/general-ui\"\r\n * library.\r\n * In turn, the feature UI editor component for the same part is located\r\n * in the \"parts/general/general-feature\" library. This library has\r\n * a route for each part editor. For instance, the NotePart editor\r\n * component route is \"items/:iid/general/it.vedph.note/:pid\", where\r\n * \":iid\" is the item ID and \":pid\" the part ID.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LibraryRouteService {\r\n constructor(\r\n @Inject('partEditorKeys') private _partEditorKeys: PartEditorKeys\r\n ) {}\r\n\r\n /**\r\n * Strip the eventual fragment-role ID from the specified part's role ID.\r\n * For instance, a part's role ID like \"fr.it.vedph.comment:scholarly\"\r\n * becomes \"fr.it.vedph.comment\".\r\n *\r\n * @param roleId The part's role ID.\r\n */\r\n public stripFragmentRoleId(roleId: string): string {\r\n // remove the optional :fr-role from roleId\r\n const i = roleId.lastIndexOf(':');\r\n if (i > -1) {\r\n roleId = roleId.substring(0, i);\r\n }\r\n return roleId;\r\n }\r\n\r\n /**\r\n * Get the fragment type and role from the part's role ID. This starts\r\n * with \"fr.\", and might be followed by the role proper, introduced\r\n * by the first dot if any. For instance, \"fr.it.vedph.comment\" would just\r\n * return \"fr.it.vedph.comment\", while \"fr.it.vedph.comment:scholarly\"\r\n * would return \"fr.it.vedph.comment\". This is required to navigate to\r\n * the correct fragment editor, which is the same for each fragment type,\r\n * independently from its role.\r\n * @param roleId The part role ID.\r\n * @returns An object where frTypeId=fragment type ID and frRoleId=fragment role\r\n * ID, or null.\r\n */\r\n public getFragmentTypeAndRole(roleId?: string): {\r\n frTypeId: string;\r\n frRoleId?: string;\r\n } | null {\r\n if (!roleId || !roleId.startsWith('fr.')) {\r\n return null;\r\n }\r\n const i = roleId.indexOf(':');\r\n if (i > -1) {\r\n return {\r\n frTypeId: roleId.substring(0, i),\r\n frRoleId: roleId.substring(i + 1),\r\n };\r\n } else {\r\n return {\r\n frTypeId: roleId,\r\n frRoleId: undefined,\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Find among the specified parts definitions the one matching the specified\r\n * type ID, and eventually role ID when specified.\r\n *\r\n * @param partDefs The parts definitions.\r\n * @param typeId The type ID.\r\n * @param roleId The role ID or null.\r\n * @returns Part definition or undefined if not found.\r\n */\r\n private findPartDefinition(\r\n partDefs: PartDefinition[],\r\n typeId: string,\r\n roleId: string | null = null\r\n ): PartDefinition | undefined {\r\n if (!partDefs) {\r\n return undefined;\r\n }\r\n\r\n // if role ID is specified, find both type and role\r\n if (roleId) {\r\n const reqRoleId: string = this.stripFragmentRoleId(roleId);\r\n return partDefs.find((d) => {\r\n return (\r\n d.typeId === typeId &&\r\n d.roleId &&\r\n this.stripFragmentRoleId(d.roleId) === reqRoleId\r\n );\r\n });\r\n }\r\n // else just find type ID\r\n return partDefs.find((d) => {\r\n return d.typeId === typeId;\r\n });\r\n }\r\n\r\n /**\r\n * Get the library editor key from the specified part type, looking up\r\n * the specified parts definitions.\r\n *\r\n * @param typeId The part's type ID.\r\n * @param roleId The part's role ID.\r\n */\r\n public getEditorKeyFromPartType(\r\n typeId: string,\r\n roleId?: string\r\n ): { partKey: string; frKey?: string } {\r\n // find the part type ID\r\n const partGroupKey = this._partEditorKeys[typeId];\r\n if (!partGroupKey) {\r\n return {\r\n partKey: 'default',\r\n };\r\n }\r\n\r\n // additionally find the role ID if specified\r\n if (roleId) {\r\n const reqRoleId = this.stripFragmentRoleId(roleId);\r\n return {\r\n partKey: partGroupKey.part,\r\n // fragments may be undefined for part types with no fragments\r\n frKey: partGroupKey.fragments?.[reqRoleId],\r\n };\r\n }\r\n return {\r\n partKey: partGroupKey.part,\r\n };\r\n }\r\n\r\n /**\r\n * Decompose the specified editor key into part and fragment.\r\n * A simple editor key will just provide the same value for both.\r\n *\r\n * @param key The editor key to decompose.\r\n */\r\n public decomposeEditorKey(key: string): { partKey: string; frKey: string } {\r\n const i = key.indexOf(' ');\r\n if (i > -1) {\r\n return {\r\n partKey: key.substring(0, i),\r\n frKey: key.substring(i + 1),\r\n };\r\n } else {\r\n return {\r\n partKey: key,\r\n frKey: key,\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Build the route to the part editor corresponding to the specified\r\n * part.\r\n *\r\n * A part editing route is like\r\n * \"/items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>\",\r\n * where the role ID is optional, and may include the fragment role ID\r\n * as a suffix preceded by a colon.\r\n *\r\n * A fragment editing route is like\r\n * \"/items/<id>/<part-group>/fragment/<part-id>/<fr-typeid>/<loc>?frrid=<role-id>\",\r\n * where the role ID is as above, and the fragment's type ID is derived\r\n * from the part's role ID, stripping the eventual fragment's role ID out.\r\n *\r\n * @param itemId The ID of the item the parts belongs to.\r\n * @param partId The part's ID.\r\n * @param typeId The part's type ID.\r\n * @param roleId The optional part's role ID.\r\n * @returns Object with a route property and an optional rid property\r\n * representing the role ID, which will be rendered as a query parameter.\r\n */\r\n public buildPartEditorRoute(\r\n itemId: string,\r\n partId: string,\r\n typeId: string,\r\n roleId?: string\r\n ): { route: string; rid?: string } {\r\n let route: string;\r\n const editorKey = this.getEditorKeyFromPartType(typeId);\r\n\r\n // /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>\r\n route = `/items/${itemId}/${editorKey.partKey}/${typeId}/${partId}`;\r\n return {\r\n route: route,\r\n rid: roleId,\r\n };\r\n }\r\n\r\n /**\r\n * Build the route to the fragment editor corresponding to the specified\r\n * layers part and location.\r\n *\r\n * @param partDefs The parts definitions.\r\n * @param itemId The ID of the item the parts belongs to.\r\n * @param partId The part's ID.\r\n * @param typeId The part's type ID.\r\n * @param roleId The part's role ID.\r\n * @param loc The fragment's location.\r\n * @returns Object with a route property and an optional rid property\r\n * representing the role ID, which will be rendered as a query parameter.\r\n */\r\n public buildFragmentEditorRoute(\r\n partDefs: PartDefinition[],\r\n itemId: string,\r\n partId: string,\r\n typeId: string,\r\n roleId: string | undefined,\r\n loc: string\r\n ): { route: string; rid?: string } {\r\n let route: string;\r\n const editorKey = this.getEditorKeyFromPartType(typeId, roleId);\r\n // roleId may be undefined or not start with \"fr.\" (e.g. a layer part\r\n // with no specific role); fall back to typeId rather than crashing.\r\n const frInfo = this.getFragmentTypeAndRole(roleId);\r\n const frTypeId = frInfo?.frTypeId ?? typeId;\r\n const frRoleId = frInfo?.frRoleId;\r\n // frKey may be undefined when roleId is missing or has no matching\r\n // fragment mapping; fall back to the part's own group key.\r\n const frKey = editorKey.frKey ?? editorKey.partKey;\r\n\r\n route = `/items/${itemId}/${frKey}/fragment/${partId}/${frTypeId}/${loc}`;\r\n return {\r\n route: route,\r\n rid: frRoleId,\r\n };\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\nimport { TokenPoint } from '../token-point';\r\nimport { TokenLocation } from '../token-location';\r\nimport { TokenTextLayerLine, TextCoords } from '../models';\r\n\r\ninterface TextRange {\r\n start: number;\r\n end: number;\r\n}\r\n\r\n/**\r\n * The selected range of text. This reflects Range useful properties;\r\n * in fact, you can just pass a Range to any method requiring this parameter type,\r\n * but this adds a level of indirection useful in testing.\r\n *\r\n * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on\r\n * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in\r\n * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is\r\n * kept only for backwards compatibility.\r\n */\r\nexport interface SelectedRange {\r\n commonAncestorContainer: Node;\r\n startContainer: Node;\r\n startOffset: number;\r\n endContainer: Node;\r\n endOffset: number;\r\n}\r\n\r\n/**\r\n * Token-based text layers service. This contains the logic of the token-based\r\n * text model: `getLines` and `getTextFragment` are still used to extract the\r\n * text of a location. The DOM-based rendition (`render`) and selection logic\r\n * (`getSelectedLocationForNew`, `getSelectedLocationForEdit`,\r\n * `getSelectedRange`) was used by the legacy implementation of\r\n * `DecoratedTokenTextComponent`, and is deprecated: the same coordinates\r\n * system is now implemented by `TokenTextSegmenter` in `@myrmidon/cadmus-ui`,\r\n * whose tests ensure its parity with this service.\r\n */\r\n@Injectable({ providedIn: 'root' })\r\nexport class TextLayerService {\r\n private readonly _wsRegex: RegExp;\r\n\r\n constructor() {\r\n this._wsRegex = new RegExp('^\\\\s$', 'g');\r\n }\r\n\r\n private isWhitespace(c: string): boolean {\r\n if (!c) {\r\n return false;\r\n }\r\n if (c.length !== 1) {\r\n c = c.charAt(0);\r\n }\r\n return this._wsRegex.test(c);\r\n }\r\n\r\n /**\r\n * Extract the lines with their tokens from the specified text.\r\n * @param text the source text.\r\n * @returns lines.\r\n */\r\n public getLines(text: string): TokenTextLayerLine[] {\r\n const results: TokenTextLayerLine[] = [];\r\n if (!text) {\r\n return results;\r\n }\r\n const lines = text.split('\\n');\r\n\r\n for (let y = 0; y < lines.length; y++) {\r\n const line = lines[y].trim();\r\n const l: TokenTextLayerLine = {\r\n y: y + 1,\r\n tokens: [],\r\n };\r\n let x = 0;\r\n let xBeg = 0;\r\n\r\n while (x < line.length) {\r\n if (this.isWhitespace(line.charAt(x))) {\r\n // l.tokens.push(line.substr(xBeg, x - xBeg));\r\n l.tokens.push(line.substring(xBeg, x));\r\n x++;\r\n while (x < line.length && this.isWhitespace(line.charAt(x))) {\r\n x++;\r\n }\r\n xBeg = x;\r\n } else {\r\n x++;\r\n }\r\n }\r\n if (xBeg < x) {\r\n l.tokens.push(line.substring(xBeg));\r\n }\r\n results.push(l);\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Get the fragment of text defined by the specified location.\r\n *\r\n * @param text The full base text.\r\n * @param location The location to get text for.\r\n * @returns A fragment of text corresponding to location.\r\n */\r\n public getTextFragment(text: string, location: TokenLocation): string {\r\n const lines = this.getLines(text);\r\n\r\n if (location.isRange()) {\r\n const sb: string[] = [];\r\n // for each line\r\n let yn = 0;\r\n for (let y = location.primary.y; y <= location.secondary!.y; y++) {\r\n const headLine = location.primary.y === y;\r\n const tailLine = location.secondary!.y === y;\r\n\r\n if (++yn > 1) {\r\n sb.push(' ');\r\n }\r\n\r\n // for each token in line\r\n let xn = 0;\r\n for (\r\n let x = headLine ? location.primary.x : 1;\r\n x <= (tailLine ? location.secondary!.x : lines[y - 1].tokens.length);\r\n x++\r\n ) {\r\n if (++xn > 1) {\r\n sb.push(' ');\r\n }\r\n // get token bounds\r\n let start =\r\n location.primary.at && headLine && x === location.primary.x\r\n ? location.primary.at\r\n : 1;\r\n let len =\r\n location.secondary!.at && tailLine && x === location.secondary!.x\r\n ? location.secondary!.run || 1\r\n : -1;\r\n const token = lines[y - 1].tokens[x - 1];\r\n if (start === 1 && len === -1) {\r\n sb.push(token);\r\n } else {\r\n sb.push(\r\n token.substring(\r\n start - 1,\r\n len === -1 ? undefined : start - 1 + len\r\n )\r\n );\r\n }\r\n }\r\n }\r\n return sb.join('');\r\n } else {\r\n const token =\r\n lines[location.primary.y - 1].tokens[location.primary.x - 1];\r\n return location.primary.at\r\n ? token.substring(\r\n location.primary.at - 1,\r\n location.primary.at - 1 + (location.primary.run || 1)\r\n )\r\n : token;\r\n }\r\n }\r\n\r\n /*\r\n * Rendition: HTML rendering from a base text and a set of fragments locations.\r\n * Each line in the base text is rendered with p; each token in a line is\r\n * rendered with its text value, and tokens are separated by space. Layer\r\n * fragments are rendered inside a span, with an id equal to the fragment location\r\n * plus a suffix beginning with _, added only for the purpose of ensuring unique\r\n * IDs in the rendered HTML code. Example:\r\n * <div>\r\n * <p id=\"y1\">this is line 1.</p>\r\n * <p id=\"y2\">here's a <span id=\"f2.3_0\">fragment</span>.</p>\r\n * </div>\r\n */\r\n\r\n /**\r\n * Render the opening span for a layer fragment.\r\n * @param loc location.\r\n * @param locPortion the index of the token's portion (0-N). This is used\r\n * to build a unique ID for each HTML span rendering a layer fragment.\r\n * @param sb the target strings array.\r\n * @param isSelected true if selected.\r\n */\r\n private renderOpeningSpan(\r\n loc: TokenLocation,\r\n locPortion: number,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n sb.push(\r\n `<span id=\"f${loc.toString()}_${locPortion}\" class=\"fr${\r\n isSelected ? ' fr-sel' : ''\r\n }\">`\r\n );\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified end-fragment location.\r\n * @param pt The point.\r\n * @param token The token.\r\n * @param sb The target array.\r\n */\r\n private renderTokenAtEnd(pt: TokenPoint, token: string, sb: string[]): void {\r\n if (pt.at) {\r\n // ...to]\r\n // sb.push(token.substr(pt.at - 1, pt.run));\r\n sb.push(token.substring(pt.at - 1, (pt.run || 0) + pt.at - 1));\r\n sb.push('</span>');\r\n // ...ken\r\n if (pt.at - 1 + (pt.run || 0) < token.length) {\r\n // sb.push(token.substr(pt.at - 1 + (pt.run || 0)));\r\n sb.push(token.substring(pt.at - 1 + (pt.run || 0)));\r\n }\r\n } else {\r\n // ...token]\r\n sb.push(token);\r\n sb.push('</span>');\r\n }\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified single-point location.\r\n * The received token starts and ends a single-token range.\r\n * @param loc location.\r\n * @param token token.\r\n * @param sb target strings array.\r\n * @param isSelected True if the token is selected.\r\n */\r\n private renderTokenAtPointStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n // 1.token's left-part\r\n if (loc.primary.at) {\r\n // to...\r\n sb.push(token.substring(0, loc.primary.at - 1));\r\n }\r\n\r\n // 2.span: [\r\n this.renderOpeningSpan(loc, 0, sb, isSelected);\r\n\r\n // 3.token's right-part (...ken]/...ke]n or ...token])\r\n this.renderTokenAtEnd(loc.primary, token, sb);\r\n }\r\n\r\n /**\r\n * Render the specified token intersecting the specified range start location.\r\n * The received token starts a multi-tokens range.\r\n * @param loc location.\r\n * @param token token.\r\n * @param sb target strings array.\r\n * @param isSelected True if the token is selected.\r\n */\r\n private renderTokenAtRangeStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): void {\r\n // 1.token's left-part (=before at)\r\n if (loc.primary.at) {\r\n // to...\r\n sb.push(token.substring(0, loc.primary.at - 1));\r\n }\r\n\r\n // 2.span: [\r\n this.renderOpeningSpan(loc, 0, sb, isSelected);\r\n\r\n // 3.token's right-part (...ken or ...token)\r\n if (loc.primary.at) {\r\n // ...ken\r\n sb.push(token.substring(loc.primary.at - 1));\r\n } else {\r\n // ...token\r\n sb.push(token);\r\n }\r\n }\r\n\r\n private renderTokenAtStart(\r\n loc: TokenLocation,\r\n token: string,\r\n sb: string[],\r\n isSelected: boolean\r\n ): boolean {\r\n if (!loc.secondary) {\r\n // single\r\n this.renderTokenAtPointStart(loc, token, sb, isSelected);\r\n return false;\r\n } else {\r\n // range\r\n this.renderTokenAtRangeStart(loc, token, sb, isSelected);\r\n return true;\r\n }\r\n }\r\n\r\n /**\r\n * Render to HTML the base text decorated with its layer fragments.\r\n * @param text The base text.\r\n * @param locations The locations of all the fragments\r\n * of the same type to be rendered on top of the base text.\r\n * @param selectedLoc The optional location of the selected\r\n * fragment if any. The selected fragment gets decorated with an additional\r\n * class value.\r\n * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on\r\n * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in\r\n * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is\r\n * kept only for backwards compatibility.\r\n */\r\n public render(\r\n text: string,\r\n locations?: TokenLocation[],\r\n selectedLoc?: TokenLocation\r\n ): string {\r\n if (!text) {\r\n return '<div></div>';\r\n }\r\n\r\n // get lines from text\r\n const sb: string[] = [];\r\n const lines = this.getLines(text);\r\n let loc: TokenLocation | undefined = undefined;\r\n let tokenSelected = false;\r\n\r\n if (!locations) {\r\n locations = [];\r\n }\r\n\r\n // for each line in text\r\n sb.push('<div>');\r\n for (let y = 0; y < lines.length; y++) {\r\n sb.push(`<p id=\"y${y + 1}\">`);\r\n\r\n // reopen a span if continuing a fragment from prev line\r\n if (loc) {\r\n this.renderOpeningSpan(loc, y + 1 - loc.primary.y, sb, tokenSelected);\r\n }\r\n\r\n // for each token in line\r\n const line = lines[y];\r\n for (let x = 0; x < line.tokens.length; x++) {\r\n // add separator if required\r\n if (x > 0) {\r\n sb.push(' ');\r\n }\r\n\r\n const token = line.tokens[x];\r\n\r\n // if inside a fragment, check if this token is the last\r\n if (loc && loc.secondary) {\r\n if (loc.secondary.y === y + 1 && loc.secondary.x === x + 1) {\r\n this.renderTokenAtEnd(loc.secondary, token, sb);\r\n loc = undefined;\r\n } else {\r\n sb.push(token);\r\n }\r\n } else {\r\n // else, check if this token starts a fragment\r\n loc = locations.find((l) => {\r\n return l.primary.y === y + 1 && l.primary.x === x + 1;\r\n });\r\n if (loc) {\r\n tokenSelected = selectedLoc ? loc.overlaps(selectedLoc) : false;\r\n if (!this.renderTokenAtStart(loc, token, sb, tokenSelected)) {\r\n loc = undefined;\r\n }\r\n } else {\r\n sb.push(token);\r\n }\r\n }\r\n }\r\n\r\n // close a span if pending at p end\r\n if (loc) {\r\n sb.push('</span>');\r\n }\r\n sb.push('</p>');\r\n }\r\n sb.push('</div>');\r\n return sb.join('');\r\n }\r\n\r\n /*\r\n Location: starting from user selection on a rendered text, get the corresponding\r\n layer fragment location. This differs according to the purpose of the location\r\n to be got: if getting a location for an existing fragment, at least 1 decorated\r\n text (span) should be included in the selection, which does not require to be\r\n exact; if getting a location for a new fragment, no decorated text (span) can be\r\n included in the selection (two fragments in the same layer can never overlap),\r\n which must be exact.\r\n */\r\n\r\n /**\r\n * Get the Y bounds from the specified selection.\r\n * @param range The selection range.\r\n * @param forNew True if getting bounds for a new fragment.\r\n * @returns Range, inclusive, or undefined.\r\n */\r\n private getYBoundsFromRange(\r\n range: SelectedRange,\r\n forNew: boolean\r\n ): TextRange | null {\r\n let p: Element | null = null;\r\n\r\n switch (range.commonAncestorContainer.nodeType) {\r\n case Node.TEXT_NODE:\r\n // single-p selection, parent=p\r\n p = range.commonAncestorContainer.parentElement;\r\n if (forNew && (p?.nodeName !== 'P' || !p.hasAttribute('id'))) {\r\n return null;\r\n }\r\n if (p?.nodeName === 'SPAN') {\r\n p = p.parentElement;\r\n }\r\n const y = parseInt(p!.getAttribute('id')!.substring(1), 10);\r\n // return [y, y];\r\n return { start: y, end: y };\r\n\r\n case Node.ELEMENT_NODE:\r\n // div only is allowed; in this case, it's a multi-p range\r\n if (range.commonAncestorContainer.nodeName !== 'DIV') {\r\n return null;\r\n }\r\n // for each div's child p element:\r\n let yMin = 0;\r\n let yMax = 0;\r\n let inside = false;\r\n for (\r\n let i = 0;\r\n i < range.commonAncestorContainer.childNodes.length;\r\n i++\r\n ) {\r\n const child = range.commonAncestorContainer.childNodes[i];\r\n if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== 'P') {\r\n continue;\r\n }\r\n // check if we're entering the start-p\r\n if (!inside && child.contains(range.startContainer)) {\r\n inside = true;\r\n }\r\n // collect y if inside\r\n if (inside) {\r\n const iy = parseInt(\r\n (child as Element)!.getAttribute('id')!.substring(1),\r\n 10\r\n );\r\n if (!yMin || iy < yMin) {\r\n yMin = iy;\r\n }\r\n if (!yMax || iy > yMax) {\r\n yMax = iy;\r\n }\r\n // check if we have exited the last p\r\n if (child.contains(range.endContainer)) {\r\n break;\r\n }\r\n }\r\n }\r\n return {\r\n start: yMin,\r\n end: yMax,\r\n };\r\n }\r\n return null;\r\n }\r\n\r\n private locatePrevSpace(line: string, index: number): number {\r\n while (index > -1 && line.charAt(index) !== ' ') {\r\n index--;\r\n }\r\n return index;\r\n }\r\n\r\n private locateNextSpace(line: string, index: number): number {\r\n while (index < line.length && line.charAt(index) !== ' ') {\r\n index++;\r\n }\r\n return index === line.length ? -1 : index;\r\n }\r\n\r\n /**\r\n * Get the bounds of the token any character of which is indexed\r\n * by index.\r\n * @param line The text line.\r\n * @param index The index to the text line to start from.\r\n * @returns Bounds where start=index of the first character of the token,\r\n * and end=index of the character past the token's last character;\r\n * or null if index was not valid.\r\n */\r\n private getTokenBounds(line: string, index: number): TextRange | null {\r\n if (line.charAt(index) === ' ') {\r\n return null;\r\n }\r\n let start = this.locatePrevSpace(line, index);\r\n if (start === -1) {\r\n start = 0;\r\n } else {\r\n start++;\r\n }\r\n let end = this.locateNextSpace(line, index);\r\n if (end === -1) {\r\n end = line.length;\r\n }\r\n // return [start, end];\r\n return {\r\n start,\r\n end,\r\n };\r\n }\r\n\r\n /**\r\n * Return the received selection bounds, adjusted to exclude spaces.\r\n */\r\n private getAdjustedSelectionBounds(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextRange {\r\n // corner case: if on space, move to right\r\n if (line.charAt(selStart) === ' ') {\r\n selStart++;\r\n }\r\n // corner case: if included trailing space, move to left\r\n if (selEnd > 0 && line.charAt(selEnd - 1) === ' ') {\r\n selEnd--;\r\n }\r\n // return [selStart, selEnd];\r\n return {\r\n start: selStart,\r\n end: selEnd,\r\n };\r\n }\r\n\r\n /**\r\n * Get the start coordinates for the selected range and line.\r\n * @param range The selected range.\r\n * @param line The reference text line.\r\n */\r\n private getStartCoordsFromRange(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextCoords {\r\n // get adjusted selection bounds\r\n const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);\r\n\r\n // get the bounds of the first selected token\r\n const tokBounds = this.getTokenBounds(line, selBounds.start)!;\r\n\r\n // calculate x by counting the tokens before the target token\r\n let x = 1;\r\n let j = tokBounds.start - 1;\r\n while (j > -1) {\r\n if (line.charAt(j) === ' ') {\r\n x++;\r\n }\r\n j--;\r\n }\r\n\r\n // calculate at,run only when either of these is true:\r\n // (a) selection starts past the 1st char of the token (al[pha);\r\n // (b) selection ends before the last char of the token (al]pha);\r\n // run is calculated only if (b) is true.\r\n let at = 0;\r\n let run = 0;\r\n if (selBounds.start > tokBounds.start || selBounds.end < tokBounds.end) {\r\n at = 1 + selBounds.start - tokBounds.start;\r\n run =\r\n (selBounds.end < tokBounds.end\r\n ? selBounds.end // al]pha\r\n : tokBounds.end) - // alpha]\r\n Math.max(tokBounds.start, selBounds.start);\r\n }\r\n\r\n return {\r\n y: 0,\r\n x,\r\n at,\r\n run,\r\n };\r\n }\r\n\r\n private getEndCoordsFromRange(\r\n selStart: number,\r\n selEnd: number,\r\n line: string\r\n ): TextCoords {\r\n // get adjusted selection bounds\r\n const selBounds = this.getAdjustedSelectionBounds(selStart, selEnd, line);\r\n // get the bounds of the last selected token\r\n const tokBounds = this.getTokenBounds(line, selBounds.end - 1)!;\r\n\r\n // calculate x by counting the tokens before the target token\r\n let x = 1;\r\n let j = selBounds.end - 1;\r\n while (j > -1) {\r\n if (line.charAt(j) === ' ') {\r\n x++;\r\n }\r\n j--;\r\n }\r\n\r\n // calculate at,run only when selection ends before the 1st char of the token\r\n // (al]pha); run is calculated only if at is calculated.\r\n let at = 0;\r\n let run = 0;\r\n if (selBounds.end < tokBounds.end) {\r\n at =\r\n selBounds.start > tokBounds.start\r\n ? 1 + selBounds.start - tokBounds.start\r\n : 1;\r\n run = selBounds.end - tokBounds.start;\r\n }\r\n\r\n return {\r\n y: 0,\r\n x,\r\n at,\r\n run,\r\n };\r\n }\r\n\r\n private getSpanLocFromId(id: string): TokenLocation | null {\r\n if (!id) {\r\n return null;\r\n }\r\n const r = new RegExp('^f([-\\\\d+.@x]+)', 'g');\r\n const m = r.exec(id);\r\n if (!m) {\r\n return null;\r\n }\r\n return TokenLocation.parse(m[1]);\r\n }\r\n\r\n private visitNodes(node: Node, visitor: (current: Node) => boolean): void {\r\n if (!visitor(node)) {\r\n return;\r\n }\r\n if (node.nodeType === Node.ELEMENT_NODE) {\r\n for (let i = 0; i < node.childNodes.length; i++) {\r\n const child = node.childNodes[i];\r\n this.visitNodes(child, visitor);\r\n }\r\n }\r\n }\r\n\r\n private findFirstDescendantSpan(range: SelectedRange): Element | null {\r\n let inside = false;\r\n let span = null;\r\n\r\n this.visitNodes(range.commonAncestorContainer, (current) => {\r\n if (current === range.startContainer) {\r\n inside = true;\r\n }\r\n if (\r\n current.nodeType === Node.ELEMENT_NODE &&\r\n current.nodeName === 'SPAN'\r\n ) {\r\n span = current;\r\n return false;\r\n }\r\n if (current === range.endContainer) {\r\n inside = false;\r\n }\r\n return true;\r\n });\r\n\r\n return span;\r\n }\r\n\r\n /**\r\n * Get the base offset for the specified node. This is used\r\n * when the start container of the selected range has any\r\n * preceding sibling node, which happens only when you have\r\n * any spans in the p element (=the line). In this case,\r\n * the selection offset starts from the start container node,\r\n * which is preceded by other nodes including other text.\r\n * As we must get the line-based offset, we have to start\r\n * from a base offset equal to the sum of the lengths of\r\n * all the preceding siblings.\r\n */\r\n private getNodeBaseOffset(node: Node): number {\r\n let offset = 0;\r\n let n: Node | null = node;\r\n n = node.previousSibling;\r\n while (n) {\r\n offset +=\r\n n.nodeType === Node.ELEMENT_NODE\r\n ? (n as any).innerText?.length || 0\r\n : n.textContent?.length || 0;\r\n n = n.previousSibling;\r\n }\r\n return offset;\r\n }\r\n\r\n /**\r\n * Get the location corresponding to the user selection,\r\n * for editing the first fragment included in it.\r\n * @param range The selected range. You can get it from the\r\n * current selection using getSelectedRange().\r\n * @returns The token location or null.\r\n * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on\r\n * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in\r\n * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is\r\n * kept only for backwards compatibility.\r\n */\r\n public getSelectedLocationForEdit(\r\n range: SelectedRange\r\n ): TokenLocation | null {\r\n if (!range) {\r\n return null;\r\n }\r\n // just find the first descendant span in selection\r\n let span: Element | null = null;\r\n switch (range.commonAncestorContainer.nodeType) {\r\n case Node.ELEMENT_NODE:\r\n span = range.commonAncestorContainer as Element;\r\n if (span.nodeName !== 'SPAN') {\r\n span = this.findFirstDescendantSpan(range);\r\n }\r\n break;\r\n case Node.TEXT_NODE:\r\n span = range.commonAncestorContainer.parentElement;\r\n if (\r\n span &&\r\n (span.nodeType !== Node.ELEMENT_NODE || span.nodeName !== 'SPAN')\r\n ) {\r\n span = null;\r\n }\r\n break;\r\n }\r\n\r\n return span ? this.getSpanLocFromId(span.getAttribute('id')!) : null;\r\n }\r\n\r\n private textLineToString(line: TokenTextLayerLine): string {\r\n if (!line || !line.tokens) {\r\n return '';\r\n }\r\n return line.tokens.join(' ');\r\n }\r\n\r\n private buildCoords(\r\n start: TextCoords,\r\n end: TextCoords,\r\n singleToken: boolean\r\n ): string {\r\n const sb = [];\r\n // start: y.x\r\n sb.push(`${start.y}.${start.x}`);\r\n\r\n if (singleToken) {\r\n // single token: check for at,run\r\n if (start.at) {\r\n sb.push(`@${start.at}`);\r\n if (start.run && start.run > 1) {\r\n sb.push(`x${start.run}`);\r\n }\r\n }\r\n } else {\r\n // not a single token\r\n // first token\r\n if (start.at) {\r\n sb.push(`@${start.at}x${start.run}`);\r\n }\r\n // last token\r\n sb.push(`-${end.y}.${end.x}`);\r\n if (end.at) {\r\n sb.push(`@1x${end.run}`);\r\n }\r\n }\r\n return sb.join('');\r\n }\r\n\r\n /**\r\n * Recursively find the node matching the specified matcher\r\n * function, starting from the specified node (included).\r\n *\r\n * @param node The node to start from.\r\n * @param matcher The matcher function, which receives a node\r\n * to match, and returns 1=match, 0=no match, -1=stop the\r\n * find operation with a no match.\r\n * @return 1=match, 0=no match, -1=stop the find operation with a no match.\r\n */\r\n private matchNode(node: Node, matcher: (n: Node) => number): number {\r\n // self\r\n const n = matcher(node);\r\n if (n) {\r\n return n;\r\n }\r\n\r\n // children\r\n if (node.hasChildNodes()) {\r\n for (let i = 0; i < node.childNodes.length; i++) {\r\n const child = node.childNodes[i];\r\n const m = this.matchNode(child, matcher);\r\n if (m) {\r\n return m;\r\n }\r\n }\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n private selHasAnySpan(range: SelectedRange): boolean {\r\n let inside = false;\r\n if (\r\n // the selected text node must not be child of a span\r\n range.startContainer.parentElement?.tagName === 'SPAN' ||\r\n range.endContainer.parentElement?.tagName === 'SPAN' ||\r\n // the nodes tree from the common ancestor, from the start node\r\n // up to the end node, must not include any span\r\n this.matchNode(range.commonAncestorContainer, (node: Node) => {\r\n // start checking only when start node reached\r\n if (node === range.startContainer) {\r\n inside = true;\r\n }\r\n if (!inside) {\r\n return 0;\r\n }\r\n // stop checking when end node reached\r\n if (node === range.endContainer) {\r\n return -1;\r\n }\r\n // node cannot be a span\r\n if (\r\n node.nodeType === Node.ELEMENT_NODE &&\r\n (node as Element).tagName === 'SPAN'\r\n ) {\r\n return 1;\r\n }\r\n return 0;\r\n }) === 1\r\n ) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Get the location corresponding to the user selection,\r\n * for adding a new fragment with the same extension.\r\n * @param range The selected range. You can get it from the\r\n * current selection using getSelectedRange().\r\n * @param text The full base text.\r\n * @returns TokenLocation The token location or undefined.\r\n * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on\r\n * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in\r\n * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is\r\n * kept only for backwards compatibility.\r\n */\r\n public getSelectedLocationForNew(\r\n range: SelectedRange,\r\n text: string\r\n ): TokenLocation | null {\r\n if (!range || this.selHasAnySpan(range)) {\r\n return null;\r\n }\r\n\r\n // get y bounds (min, max; equal if single-line)\r\n const yBounds = this.getYBoundsFromRange(range, true);\r\n if (!yBounds) {\r\n return null;\r\n }\r\n\r\n // get lines and calculate start/end coords\r\n const lines = this.getLines(text);\r\n const startLine = this.textLineToString(lines[yBounds.start - 1]);\r\n const endLine = this.textLineToString(lines[yBounds.end - 1]);\r\n\r\n // get the base offsets\r\n const startBaseOffset = this.getNodeBaseOffset(range.startContainer);\r\n const endBaseOffset = this.getNodeBaseOffset(range.endContainer);\r\n\r\n // get the start (including the base offset)\r\n const startLineEndOffset =\r\n yBounds.start !== yBounds.end\r\n ? startLine.length\r\n : range.endOffset + startBaseOffset;\r\n\r\n const start = this.getStartCoordsFromRange(\r\n range.startOffset + startBaseOffset,\r\n startLineEndOffset,\r\n startLine\r\n );\r\n start.y = yBounds.start;\r\n\r\n // get the end (including the base offset)\r\n const end =\r\n yBounds.start !== yBounds.end\r\n ? this.getEndCoordsFromRange(\r\n 0,\r\n range.endOffset + endBaseOffset,\r\n endLine\r\n )\r\n : this.getEndCoordsFromRange(\r\n range.startOffset + endBaseOffset,\r\n range.endOffset + endBaseOffset,\r\n endLine\r\n );\r\n end.y = yBounds.end;\r\n const singleLine = start.y === end.y;\r\n const singleToken = singleLine && start.x === end.x;\r\n\r\n const coords = this.buildCoords(start, end, singleToken);\r\n return TokenLocation.parse(coords);\r\n }\r\n\r\n /**\r\n * Get the currently selected range in the browser's document.\r\n * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on\r\n * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in\r\n * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is\r\n * kept only for backwards compatibility.\r\n */\r\n public getSelectedRange(): Range | null {\r\n const sel = window.getSelection();\r\n if (!sel || sel.isCollapsed) {\r\n return null;\r\n }\r\n return sel.getRangeAt(0);\r\n }\r\n}\r\n"],"mappings":";;;;;AA2BA,IAAY;CAAZ,SAAY,cAAY;CAGtB,aAAA,aAAA,UAAA,MAAA;CACA,aAAA,aAAA,gBAAA,KAAA;CACA,aAAA,aAAA,gBAAA,KAAA;CACA,aAAA,aAAA,kBAAA,KAAA;CACA,aAAA,aAAA,kBAAA,KAAA;AACF,EAAA,CARY,iBAAA,eAAY,CAAA,EAAA;AAuDxB,IAAY;CAAZ,SAAY,kBAAgB;CAC1B,iBAAA,iBAAA,YAAA,KAAA;CACA,iBAAA,iBAAA,aAAA,KAAA;CACA,iBA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,CAAE"}
package/package.json CHANGED
@@ -1,6 +1,4 @@
1
1
  {
2
- "name": "@myrmidon/cadmus-core",
3
- "version": "20.0.0",
4
2
  "description": "Cadmus - core.",
5
3
  "keywords": [
6
4
  "Cadmus"
@@ -18,20 +16,21 @@
18
16
  "@angular/core": "^22.2.1",
19
17
  "@myrmidon/ngx-tools": "^3.0.2"
20
18
  },
21
- "dependencies": {
22
- "tslib": "^2.3.0"
23
- },
24
- "module": "fesm2022/myrmidon-cadmus-core.mjs",
25
- "typings": "types/myrmidon-cadmus-core.d.ts",
19
+ "name": "@myrmidon/cadmus-core",
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "main": "./fesm2022/myrmidon-cadmus-core.mjs",
23
+ "module": "./fesm2022/myrmidon-cadmus-core.mjs",
24
+ "typings": "./types/myrmidon-cadmus-core.d.ts",
25
+ "types": "./types/myrmidon-cadmus-core.d.ts",
26
26
  "exports": {
27
- "./package.json": {
28
- "default": "./package.json"
29
- },
30
27
  ".": {
31
28
  "types": "./types/myrmidon-cadmus-core.d.ts",
32
29
  "default": "./fesm2022/myrmidon-cadmus-core.mjs"
30
+ },
31
+ "./package.json": {
32
+ "default": "./package.json"
33
33
  }
34
34
  },
35
- "sideEffects": false,
36
- "type": "module"
37
- }
35
+ "version": "20.1.0"
36
+ }
@@ -314,6 +314,80 @@ export interface EditedObject<T extends Part | Fragment> {
314
314
  layerPart?: TextLayerPart;
315
315
  baseText?: string;
316
316
  }
317
+ /**
318
+ * The edit status of a history record.
319
+ */
320
+ export declare enum EditStatus {
321
+ created = 0,
322
+ updated = 1,
323
+ deleted = 2
324
+ }
325
+ /**
326
+ * Essential properties of a history record, i.e. of a saved version
327
+ * of an item or part. History stores the state of the item or part
328
+ * as it was saved, so the newest history record is the current state.
329
+ */
330
+ export interface HistoryInfo extends HasVersion {
331
+ /**
332
+ * The ID of the history record (not of the item or part).
333
+ */
334
+ id: string;
335
+ /**
336
+ * The ID of the item or part this record refers to.
337
+ */
338
+ referenceId: string;
339
+ /**
340
+ * The edit status.
341
+ */
342
+ status: EditStatus;
343
+ }
344
+ /**
345
+ * Information about a history item.
346
+ */
347
+ export interface HistoryItemInfo extends HistoryInfo {
348
+ title?: string;
349
+ description?: string;
350
+ facetId?: string;
351
+ groupId?: string;
352
+ sortKey?: string;
353
+ flags: number;
354
+ }
355
+ /**
356
+ * A history item, i.e. a saved version of an item's metadata (with no
357
+ * parts).
358
+ */
359
+ export interface HistoryItem extends HistoryInfo {
360
+ title: string;
361
+ description: string;
362
+ facetId: string;
363
+ groupId?: string;
364
+ sortKey: string;
365
+ flags: number;
366
+ }
367
+ /**
368
+ * Information about a history part.
369
+ */
370
+ export interface HistoryPartInfo extends HistoryInfo {
371
+ itemId?: string;
372
+ typeId?: string;
373
+ roleId?: string;
374
+ }
375
+ /**
376
+ * A history part, i.e. a saved version of a part, which is in its
377
+ * part property.
378
+ */
379
+ export interface HistoryPart<T extends Part = Part> extends HistoryPartInfo {
380
+ part: T;
381
+ }
382
+ /**
383
+ * Filter for the history of a single item or part.
384
+ */
385
+ export interface HistoryFilter {
386
+ minModified?: Date;
387
+ maxModified?: Date;
388
+ userId?: string;
389
+ status?: EditStatus;
390
+ }
317
391
  /**
318
392
  * A simple text range, expressed as start character index and characters
319
393
  * length. This is used for misspellings operations.
@@ -543,6 +617,11 @@ export declare class LibraryRouteService {
543
617
  * The selected range of text. This reflects Range useful properties;
544
618
  * in fact, you can just pass a Range to any method requiring this parameter type,
545
619
  * but this adds a level of indirection useful in testing.
620
+ *
621
+ * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on
622
+ * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in
623
+ * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is
624
+ * kept only for backwards compatibility.
546
625
  */
547
626
  export interface SelectedRange {
548
627
  commonAncestorContainer: Node;
@@ -551,6 +630,16 @@ export interface SelectedRange {
551
630
  endContainer: Node;
552
631
  endOffset: number;
553
632
  }
633
+ /**
634
+ * Token-based text layers service. This contains the logic of the token-based
635
+ * text model: `getLines` and `getTextFragment` are still used to extract the
636
+ * text of a location. The DOM-based rendition (`render`) and selection logic
637
+ * (`getSelectedLocationForNew`, `getSelectedLocationForEdit`,
638
+ * `getSelectedRange`) was used by the legacy implementation of
639
+ * `DecoratedTokenTextComponent`, and is deprecated: the same coordinates
640
+ * system is now implemented by `TokenTextSegmenter` in `@myrmidon/cadmus-ui`,
641
+ * whose tests ensure its parity with this service.
642
+ */
554
643
  export declare class TextLayerService {
555
644
  private readonly _wsRegex;
556
645
  constructor();
@@ -612,6 +701,10 @@ export declare class TextLayerService {
612
701
  * @param selectedLoc The optional location of the selected
613
702
  * fragment if any. The selected fragment gets decorated with an additional
614
703
  * class value.
704
+ * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on
705
+ * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in
706
+ * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is
707
+ * kept only for backwards compatibility.
615
708
  */
616
709
  render(text: string, locations?: TokenLocation[], selectedLoc?: TokenLocation): string;
617
710
  /**
@@ -665,6 +758,10 @@ export declare class TextLayerService {
665
758
  * @param range The selected range. You can get it from the
666
759
  * current selection using getSelectedRange().
667
760
  * @returns The token location or null.
761
+ * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on
762
+ * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in
763
+ * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is
764
+ * kept only for backwards compatibility.
668
765
  */
669
766
  getSelectedLocationForEdit(range: SelectedRange): TokenLocation | null;
670
767
  private textLineToString;
@@ -688,10 +785,18 @@ export declare class TextLayerService {
688
785
  * current selection using getSelectedRange().
689
786
  * @param text The full base text.
690
787
  * @returns TokenLocation The token location or undefined.
788
+ * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on
789
+ * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in
790
+ * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is
791
+ * kept only for backwards compatibility.
691
792
  */
692
793
  getSelectedLocationForNew(range: SelectedRange, text: string): TokenLocation | null;
693
794
  /**
694
795
  * Get the currently selected range in the browser's document.
796
+ * @deprecated Since the adoption of `DecoratedTokenTextComponent` based on
797
+ * `@myrmidon/cadmus-text-segment` (see `TokenTextSegmenter` in
798
+ * `@myrmidon/cadmus-ui`), this DOM-based logic is no longer used, and is
799
+ * kept only for backwards compatibility.
695
800
  */
696
801
  getSelectedRange(): Range | null;
697
802
  static ɵfac: i0.ɵɵFactoryDeclaration<TextLayerService, never>;