@myrmidon/cadmus-core 2.0.1 → 5.0.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/esm2022/lib/cadmus-core.module.mjs +21 -0
- package/esm2022/lib/guards/pending-changes.guard.mjs +27 -0
- package/esm2022/lib/models.mjs +24 -0
- package/esm2022/lib/pipes/sort.pipe.mjs +43 -0
- package/esm2022/lib/services/library-route.service.mjs +212 -0
- package/esm2022/lib/services/text-layer.service.mjs +732 -0
- package/esm2022/lib/text-range.mjs +58 -0
- package/esm2022/lib/token-location.mjs +74 -0
- package/esm2022/lib/token-point.mjs +65 -0
- package/{esm2020 → esm2022}/myrmidon-cadmus-core.mjs +4 -4
- package/{esm2020 → esm2022}/public-api.mjs +12 -12
- package/{fesm2020 → fesm2022}/myrmidon-cadmus-core.mjs +1218 -1168
- package/fesm2022/myrmidon-cadmus-core.mjs.map +1 -0
- package/index.d.ts +5 -5
- package/lib/cadmus-core.module.d.ts +10 -10
- package/lib/guards/pending-changes.guard.d.ts +18 -19
- package/lib/models.d.ts +284 -283
- package/lib/pipes/sort.pipe.d.ts +10 -10
- package/lib/services/library-route.service.d.ts +123 -123
- package/lib/services/text-layer.service.d.ts +162 -154
- package/lib/text-range.d.ts +36 -36
- package/lib/token-location.d.ts +18 -18
- package/lib/token-point.d.ts +19 -19
- package/package.json +8 -14
- package/public-api.d.ts +9 -9
- package/esm2020/lib/cadmus-core.module.mjs +0 -20
- package/esm2020/lib/guards/pending-changes.guard.mjs +0 -26
- package/esm2020/lib/models.mjs +0 -24
- package/esm2020/lib/pipes/sort.pipe.mjs +0 -42
- package/esm2020/lib/services/library-route.service.mjs +0 -211
- package/esm2020/lib/services/text-layer.service.mjs +0 -681
- package/esm2020/lib/text-range.mjs +0 -58
- package/esm2020/lib/token-location.mjs +0 -74
- package/esm2020/lib/token-point.mjs +0 -65
- package/fesm2015/myrmidon-cadmus-core.mjs +0 -1205
- package/fesm2015/myrmidon-cadmus-core.mjs.map +0 -1
- package/fesm2020/myrmidon-cadmus-core.mjs.map +0 -1
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import { PartDefinition, PartEditorKeys } from '../models';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
/**
|
|
4
|
-
* Library route service.
|
|
5
|
-
* This service is used to build routes to part and fragment editors,
|
|
6
|
-
* which are hosted in an open list of library modules in the Cadmus
|
|
7
|
-
* application.
|
|
8
|
-
* This architecture allows lazy-loading part- and fragment-editors
|
|
9
|
-
* only when they are required.
|
|
10
|
-
* Each part type with its dumb UI editor component is located in a
|
|
11
|
-
* library, named after the name of the group the part belongs to. For
|
|
12
|
-
* instance, the model and dumb UI editor component for a part belonging
|
|
13
|
-
* to the "general" group are located in the "parts/general/general-ui"
|
|
14
|
-
* library.
|
|
15
|
-
* In turn, the feature UI editor component for the same part is located
|
|
16
|
-
* in the "parts/general/general-feature" library. This library has
|
|
17
|
-
* a route for each part editor. For instance, the NotePart editor
|
|
18
|
-
* component route is "items/:iid/general/it.vedph.note/:pid", where
|
|
19
|
-
* ":iid" is the item ID and ":pid" the part ID.
|
|
20
|
-
*/
|
|
21
|
-
export declare class LibraryRouteService {
|
|
22
|
-
private _partEditorKeys;
|
|
23
|
-
constructor(_partEditorKeys: PartEditorKeys);
|
|
24
|
-
/**
|
|
25
|
-
* Strip the eventual fragment-role ID from the specified part's role ID.
|
|
26
|
-
* For instance, a part's role ID like "fr.it.vedph.comment:scholarly"
|
|
27
|
-
* becomes "fr.it.vedph.comment".
|
|
28
|
-
*
|
|
29
|
-
* @param roleId The part's role ID.
|
|
30
|
-
*/
|
|
31
|
-
stripFragmentRoleId(roleId: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* Get the fragment type and role from the part's role ID. This starts
|
|
34
|
-
* with "fr.", and might be followed by the role proper, introduced
|
|
35
|
-
* by the first dot if any. For instance, "fr.it.vedph.comment" would just
|
|
36
|
-
* return "fr.it.vedph.comment", while "fr.it.vedph.comment:scholarly"
|
|
37
|
-
* would return "fr.it.vedph.comment". This is required to navigate to
|
|
38
|
-
* the correct fragment editor, which is the same for each fragment type,
|
|
39
|
-
* independently from its role.
|
|
40
|
-
* @param roleId The part role ID.
|
|
41
|
-
* @returns An object where frTypeId=fragment type ID and frRoleId=fragment role
|
|
42
|
-
* ID, or null.
|
|
43
|
-
*/
|
|
44
|
-
getFragmentTypeAndRole(roleId?: string): {
|
|
45
|
-
frTypeId: string;
|
|
46
|
-
frRoleId?: string;
|
|
47
|
-
} | null;
|
|
48
|
-
/**
|
|
49
|
-
* Find among the specified parts definitions the one matching the specified
|
|
50
|
-
* type ID, and eventually role ID when specified.
|
|
51
|
-
*
|
|
52
|
-
* @param partDefs The parts definitions.
|
|
53
|
-
* @param typeId The type ID.
|
|
54
|
-
* @param roleId The role ID or null.
|
|
55
|
-
* @returns Part definition or undefined if not found.
|
|
56
|
-
*/
|
|
57
|
-
private findPartDefinition;
|
|
58
|
-
/**
|
|
59
|
-
* Get the library editor key from the specified part type, looking up
|
|
60
|
-
* the specified parts definitions.
|
|
61
|
-
*
|
|
62
|
-
* @param typeId The part's type ID.
|
|
63
|
-
* @param roleId The part's role ID.
|
|
64
|
-
*/
|
|
65
|
-
getEditorKeyFromPartType(typeId: string, roleId?: string): {
|
|
66
|
-
partKey: string;
|
|
67
|
-
frKey?: string;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Decompose the specified editor key into part and fragment.
|
|
71
|
-
* A simple editor key will just provide the same value for both.
|
|
72
|
-
*
|
|
73
|
-
* @param key The editor key to decompose.
|
|
74
|
-
*/
|
|
75
|
-
decomposeEditorKey(key: string): {
|
|
76
|
-
partKey: string;
|
|
77
|
-
frKey: string;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Build the route to the part editor corresponding to the specified
|
|
81
|
-
* part.
|
|
82
|
-
*
|
|
83
|
-
* A part editing route is like
|
|
84
|
-
* "/items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>",
|
|
85
|
-
* where the role ID is optional, and may include the fragment role ID
|
|
86
|
-
* as a suffix preceded by a colon.
|
|
87
|
-
*
|
|
88
|
-
* A fragment editing route is like
|
|
89
|
-
* "/items/<id>/<part-group>/fragment/<part-id>/<fr-typeid>/<loc>?frrid=<role-id>",
|
|
90
|
-
* where the role ID is as above, and the fragment's type ID is derived
|
|
91
|
-
* from the part's role ID, stripping the eventual fragment's role ID out.
|
|
92
|
-
*
|
|
93
|
-
* @param itemId The ID of the item the parts belongs to.
|
|
94
|
-
* @param partId The part's ID.
|
|
95
|
-
* @param typeId The part's type ID.
|
|
96
|
-
* @param roleId The optional part's role ID.
|
|
97
|
-
* @returns Object with a route property and an optional rid property
|
|
98
|
-
* representing the role ID, which will be rendered as a query parameter.
|
|
99
|
-
*/
|
|
100
|
-
buildPartEditorRoute(itemId: string, partId: string, typeId: string, roleId?: string): {
|
|
101
|
-
route: string;
|
|
102
|
-
rid?: string;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Build the route to the fragment editor corresponding to the specified
|
|
106
|
-
* layers part and location.
|
|
107
|
-
*
|
|
108
|
-
* @param partDefs The parts definitions.
|
|
109
|
-
* @param itemId The ID of the item the parts belongs to.
|
|
110
|
-
* @param partId The part's ID.
|
|
111
|
-
* @param typeId The part's type ID.
|
|
112
|
-
* @param roleId The part's role ID.
|
|
113
|
-
* @param loc The fragment's location.
|
|
114
|
-
* @returns Object with a route property and an optional rid property
|
|
115
|
-
* representing the role ID, which will be rendered as a query parameter.
|
|
116
|
-
*/
|
|
117
|
-
buildFragmentEditorRoute(partDefs: PartDefinition[], itemId: string, partId: string, typeId: string, roleId: string | undefined, loc: string): {
|
|
118
|
-
route: string;
|
|
119
|
-
rid?: string;
|
|
120
|
-
};
|
|
121
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LibraryRouteService, never>;
|
|
122
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LibraryRouteService>;
|
|
123
|
-
}
|
|
1
|
+
import { PartDefinition, PartEditorKeys } from '../models';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Library route service.
|
|
5
|
+
* This service is used to build routes to part and fragment editors,
|
|
6
|
+
* which are hosted in an open list of library modules in the Cadmus
|
|
7
|
+
* application.
|
|
8
|
+
* This architecture allows lazy-loading part- and fragment-editors
|
|
9
|
+
* only when they are required.
|
|
10
|
+
* Each part type with its dumb UI editor component is located in a
|
|
11
|
+
* library, named after the name of the group the part belongs to. For
|
|
12
|
+
* instance, the model and dumb UI editor component for a part belonging
|
|
13
|
+
* to the "general" group are located in the "parts/general/general-ui"
|
|
14
|
+
* library.
|
|
15
|
+
* In turn, the feature UI editor component for the same part is located
|
|
16
|
+
* in the "parts/general/general-feature" library. This library has
|
|
17
|
+
* a route for each part editor. For instance, the NotePart editor
|
|
18
|
+
* component route is "items/:iid/general/it.vedph.note/:pid", where
|
|
19
|
+
* ":iid" is the item ID and ":pid" the part ID.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LibraryRouteService {
|
|
22
|
+
private _partEditorKeys;
|
|
23
|
+
constructor(_partEditorKeys: PartEditorKeys);
|
|
24
|
+
/**
|
|
25
|
+
* Strip the eventual fragment-role ID from the specified part's role ID.
|
|
26
|
+
* For instance, a part's role ID like "fr.it.vedph.comment:scholarly"
|
|
27
|
+
* becomes "fr.it.vedph.comment".
|
|
28
|
+
*
|
|
29
|
+
* @param roleId The part's role ID.
|
|
30
|
+
*/
|
|
31
|
+
stripFragmentRoleId(roleId: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Get the fragment type and role from the part's role ID. This starts
|
|
34
|
+
* with "fr.", and might be followed by the role proper, introduced
|
|
35
|
+
* by the first dot if any. For instance, "fr.it.vedph.comment" would just
|
|
36
|
+
* return "fr.it.vedph.comment", while "fr.it.vedph.comment:scholarly"
|
|
37
|
+
* would return "fr.it.vedph.comment". This is required to navigate to
|
|
38
|
+
* the correct fragment editor, which is the same for each fragment type,
|
|
39
|
+
* independently from its role.
|
|
40
|
+
* @param roleId The part role ID.
|
|
41
|
+
* @returns An object where frTypeId=fragment type ID and frRoleId=fragment role
|
|
42
|
+
* ID, or null.
|
|
43
|
+
*/
|
|
44
|
+
getFragmentTypeAndRole(roleId?: string): {
|
|
45
|
+
frTypeId: string;
|
|
46
|
+
frRoleId?: string;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* Find among the specified parts definitions the one matching the specified
|
|
50
|
+
* type ID, and eventually role ID when specified.
|
|
51
|
+
*
|
|
52
|
+
* @param partDefs The parts definitions.
|
|
53
|
+
* @param typeId The type ID.
|
|
54
|
+
* @param roleId The role ID or null.
|
|
55
|
+
* @returns Part definition or undefined if not found.
|
|
56
|
+
*/
|
|
57
|
+
private findPartDefinition;
|
|
58
|
+
/**
|
|
59
|
+
* Get the library editor key from the specified part type, looking up
|
|
60
|
+
* the specified parts definitions.
|
|
61
|
+
*
|
|
62
|
+
* @param typeId The part's type ID.
|
|
63
|
+
* @param roleId The part's role ID.
|
|
64
|
+
*/
|
|
65
|
+
getEditorKeyFromPartType(typeId: string, roleId?: string): {
|
|
66
|
+
partKey: string;
|
|
67
|
+
frKey?: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Decompose the specified editor key into part and fragment.
|
|
71
|
+
* A simple editor key will just provide the same value for both.
|
|
72
|
+
*
|
|
73
|
+
* @param key The editor key to decompose.
|
|
74
|
+
*/
|
|
75
|
+
decomposeEditorKey(key: string): {
|
|
76
|
+
partKey: string;
|
|
77
|
+
frKey: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Build the route to the part editor corresponding to the specified
|
|
81
|
+
* part.
|
|
82
|
+
*
|
|
83
|
+
* A part editing route is like
|
|
84
|
+
* "/items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>",
|
|
85
|
+
* where the role ID is optional, and may include the fragment role ID
|
|
86
|
+
* as a suffix preceded by a colon.
|
|
87
|
+
*
|
|
88
|
+
* A fragment editing route is like
|
|
89
|
+
* "/items/<id>/<part-group>/fragment/<part-id>/<fr-typeid>/<loc>?frrid=<role-id>",
|
|
90
|
+
* where the role ID is as above, and the fragment's type ID is derived
|
|
91
|
+
* from the part's role ID, stripping the eventual fragment's role ID out.
|
|
92
|
+
*
|
|
93
|
+
* @param itemId The ID of the item the parts belongs to.
|
|
94
|
+
* @param partId The part's ID.
|
|
95
|
+
* @param typeId The part's type ID.
|
|
96
|
+
* @param roleId The optional part's role ID.
|
|
97
|
+
* @returns Object with a route property and an optional rid property
|
|
98
|
+
* representing the role ID, which will be rendered as a query parameter.
|
|
99
|
+
*/
|
|
100
|
+
buildPartEditorRoute(itemId: string, partId: string, typeId: string, roleId?: string): {
|
|
101
|
+
route: string;
|
|
102
|
+
rid?: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Build the route to the fragment editor corresponding to the specified
|
|
106
|
+
* layers part and location.
|
|
107
|
+
*
|
|
108
|
+
* @param partDefs The parts definitions.
|
|
109
|
+
* @param itemId The ID of the item the parts belongs to.
|
|
110
|
+
* @param partId The part's ID.
|
|
111
|
+
* @param typeId The part's type ID.
|
|
112
|
+
* @param roleId The part's role ID.
|
|
113
|
+
* @param loc The fragment's location.
|
|
114
|
+
* @returns Object with a route property and an optional rid property
|
|
115
|
+
* representing the role ID, which will be rendered as a query parameter.
|
|
116
|
+
*/
|
|
117
|
+
buildFragmentEditorRoute(partDefs: PartDefinition[], itemId: string, partId: string, typeId: string, roleId: string | undefined, loc: string): {
|
|
118
|
+
route: string;
|
|
119
|
+
rid?: string;
|
|
120
|
+
};
|
|
121
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LibraryRouteService, never>;
|
|
122
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LibraryRouteService>;
|
|
123
|
+
}
|
|
@@ -1,154 +1,162 @@
|
|
|
1
|
-
import { TokenLocation } from '../token-location';
|
|
2
|
-
import { TokenTextLayerLine } from '../models';
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
/**
|
|
5
|
-
* The selected range of text. This reflects rangy's Range useful properties;
|
|
6
|
-
* in fact, you can just pass a Range to any method requiring this parameter type,
|
|
7
|
-
* but this adds a level of indirection useful in testing.
|
|
8
|
-
*/
|
|
9
|
-
export interface SelectedRange {
|
|
10
|
-
commonAncestorContainer: Node;
|
|
11
|
-
startContainer: Node;
|
|
12
|
-
startOffset: number;
|
|
13
|
-
endContainer: Node;
|
|
14
|
-
endOffset: number;
|
|
15
|
-
}
|
|
16
|
-
export declare class TextLayerService {
|
|
17
|
-
private readonly _wsRegex;
|
|
18
|
-
constructor();
|
|
19
|
-
private isWhitespace;
|
|
20
|
-
/**
|
|
21
|
-
* Extract the lines with their tokens from the specified text.
|
|
22
|
-
* @param text the source text.
|
|
23
|
-
* @returns lines.
|
|
24
|
-
*/
|
|
25
|
-
getLines(text: string): TokenTextLayerLine[];
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
*
|
|
39
|
-
* @param sb
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
* @param
|
|
46
|
-
* @param token token.
|
|
47
|
-
* @param sb target
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @param
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
private
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
1
|
+
import { TokenLocation } from '../token-location';
|
|
2
|
+
import { TokenTextLayerLine } from '../models';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* The selected range of text. This reflects rangy's Range useful properties;
|
|
6
|
+
* in fact, you can just pass a Range to any method requiring this parameter type,
|
|
7
|
+
* but this adds a level of indirection useful in testing.
|
|
8
|
+
*/
|
|
9
|
+
export interface SelectedRange {
|
|
10
|
+
commonAncestorContainer: Node;
|
|
11
|
+
startContainer: Node;
|
|
12
|
+
startOffset: number;
|
|
13
|
+
endContainer: Node;
|
|
14
|
+
endOffset: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class TextLayerService {
|
|
17
|
+
private readonly _wsRegex;
|
|
18
|
+
constructor();
|
|
19
|
+
private isWhitespace;
|
|
20
|
+
/**
|
|
21
|
+
* Extract the lines with their tokens from the specified text.
|
|
22
|
+
* @param text the source text.
|
|
23
|
+
* @returns lines.
|
|
24
|
+
*/
|
|
25
|
+
getLines(text: string): TokenTextLayerLine[];
|
|
26
|
+
/**
|
|
27
|
+
* Get the fragment of text defined by the specified location.
|
|
28
|
+
*
|
|
29
|
+
* @param text The full base text.
|
|
30
|
+
* @param location The location to get text for.
|
|
31
|
+
* @returns A fragment of text corresponding to location.
|
|
32
|
+
*/
|
|
33
|
+
getTextFragment(text: string, location: TokenLocation): string;
|
|
34
|
+
/**
|
|
35
|
+
* Render the opening span for a layer fragment.
|
|
36
|
+
* @param loc location.
|
|
37
|
+
* @param locPortion the index of the token's portion (0-N). This is used
|
|
38
|
+
* to build a unique ID for each HTML span rendering a layer fragment.
|
|
39
|
+
* @param sb the target strings array.
|
|
40
|
+
* @param isSelected true if selected.
|
|
41
|
+
*/
|
|
42
|
+
private renderOpeningSpan;
|
|
43
|
+
/**
|
|
44
|
+
* Render the specified token intersecting the specified end-fragment location.
|
|
45
|
+
* @param pt The point.
|
|
46
|
+
* @param token The token.
|
|
47
|
+
* @param sb The target array.
|
|
48
|
+
*/
|
|
49
|
+
private renderTokenAtEnd;
|
|
50
|
+
/**
|
|
51
|
+
* Render the specified token intersecting the specified single-point location.
|
|
52
|
+
* The received token starts and ends a single-token range.
|
|
53
|
+
* @param loc location.
|
|
54
|
+
* @param token token.
|
|
55
|
+
* @param sb target strings array.
|
|
56
|
+
* @param isSelected True if the token is selected.
|
|
57
|
+
*/
|
|
58
|
+
private renderTokenAtPointStart;
|
|
59
|
+
/**
|
|
60
|
+
* Render the specified token intersecting the specified range start location.
|
|
61
|
+
* The received token starts a multi-tokens range.
|
|
62
|
+
* @param loc location.
|
|
63
|
+
* @param token token.
|
|
64
|
+
* @param sb target strings array.
|
|
65
|
+
* @param isSelected True if the token is selected.
|
|
66
|
+
*/
|
|
67
|
+
private renderTokenAtRangeStart;
|
|
68
|
+
private renderTokenAtStart;
|
|
69
|
+
/**
|
|
70
|
+
* Render to HTML the base text decorated with its layer fragments.
|
|
71
|
+
* @param text The base text.
|
|
72
|
+
* @param locations The locations of all the fragments
|
|
73
|
+
* of the same type to be rendered on top of the base text.
|
|
74
|
+
* @param selectedLoc The optional location of the selected
|
|
75
|
+
* fragment if any. The selected fragment gets decorated with an additional
|
|
76
|
+
* class value.
|
|
77
|
+
*/
|
|
78
|
+
render(text: string, locations?: TokenLocation[], selectedLoc?: TokenLocation): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the Y bounds from the specified selection.
|
|
81
|
+
* @param range The selection range.
|
|
82
|
+
* @param forNew True if getting bounds for a new fragment.
|
|
83
|
+
* @returns Range, inclusive, or undefined.
|
|
84
|
+
*/
|
|
85
|
+
private getYBoundsFromRange;
|
|
86
|
+
private locatePrevSpace;
|
|
87
|
+
private locateNextSpace;
|
|
88
|
+
/**
|
|
89
|
+
* Get the bounds of the token any character of which is indexed
|
|
90
|
+
* by index.
|
|
91
|
+
* @param line The text line.
|
|
92
|
+
* @param index The index to the text line to start from.
|
|
93
|
+
* @returns Bounds where start=index of the first character of the token,
|
|
94
|
+
* and end=index of the character past the token's last character;
|
|
95
|
+
* or null if index was not valid.
|
|
96
|
+
*/
|
|
97
|
+
private getTokenBounds;
|
|
98
|
+
/**
|
|
99
|
+
* Return the received selection bounds, adjusted to exclude spaces.
|
|
100
|
+
*/
|
|
101
|
+
private getAdjustedSelectionBounds;
|
|
102
|
+
/**
|
|
103
|
+
* Get the start coordinates for the selected range and line.
|
|
104
|
+
* @param range The selected range.
|
|
105
|
+
* @param line The reference text line.
|
|
106
|
+
*/
|
|
107
|
+
private getStartCoordsFromRange;
|
|
108
|
+
private getEndCoordsFromRange;
|
|
109
|
+
private getSpanLocFromId;
|
|
110
|
+
private visitNodes;
|
|
111
|
+
private findFirstDescendantSpan;
|
|
112
|
+
/**
|
|
113
|
+
* Get the base offset for the specified node. This is used
|
|
114
|
+
* when the start container of the selected range has any
|
|
115
|
+
* preceding sibling node, which happens only when you have
|
|
116
|
+
* any spans in the p element (=the line). In this case,
|
|
117
|
+
* the selection offset starts from the start container node,
|
|
118
|
+
* which is preceded by other nodes including other text.
|
|
119
|
+
* As we must get the line-based offset, we have to start
|
|
120
|
+
* from a base offset equal to the sum of the lengths of
|
|
121
|
+
* all the preceding siblings.
|
|
122
|
+
*/
|
|
123
|
+
private getNodeBaseOffset;
|
|
124
|
+
/**
|
|
125
|
+
* Get the location corresponding to the user selection,
|
|
126
|
+
* for editing the first fragment included in it.
|
|
127
|
+
* @param range The selected range. You can get it from the
|
|
128
|
+
* current selection using getSelectedRange().
|
|
129
|
+
* @returns The token location or null.
|
|
130
|
+
*/
|
|
131
|
+
getSelectedLocationForEdit(range: SelectedRange): TokenLocation | null;
|
|
132
|
+
private textLineToString;
|
|
133
|
+
private buildCoords;
|
|
134
|
+
/**
|
|
135
|
+
* Recursively find the node matching the specified matcher
|
|
136
|
+
* function, starting from the specified node (included).
|
|
137
|
+
*
|
|
138
|
+
* @param node The node to start from.
|
|
139
|
+
* @param matcher The matcher function, which receives a node
|
|
140
|
+
* to match, and returns 1=match, 0=no match, -1=stop the
|
|
141
|
+
* find operation with a no match.
|
|
142
|
+
* @return 1=match, 0=no match, -1=stop the find operation with a no match.
|
|
143
|
+
*/
|
|
144
|
+
private matchNode;
|
|
145
|
+
private selHasAnySpan;
|
|
146
|
+
/**
|
|
147
|
+
* Get the location corresponding to the user selection,
|
|
148
|
+
* for adding a new fragment with the same extension.
|
|
149
|
+
* @param range The selected range. You can get it from the
|
|
150
|
+
* current selection using getSelectedRange().
|
|
151
|
+
* @param text The full base text.
|
|
152
|
+
* @returns TokenLocation The token location or undefined.
|
|
153
|
+
*/
|
|
154
|
+
getSelectedLocationForNew(range: SelectedRange, text: string): TokenLocation | null;
|
|
155
|
+
/**
|
|
156
|
+
* Get the currently selected range in the browser's document.
|
|
157
|
+
* This uses the rangy library.
|
|
158
|
+
*/
|
|
159
|
+
getSelectedRange(): Range | null;
|
|
160
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TextLayerService, never>;
|
|
161
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<TextLayerService>;
|
|
162
|
+
}
|
package/lib/text-range.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple text range, expressed as start character index and characters
|
|
3
|
-
* length. This is used for misspellings operations.
|
|
4
|
-
*/
|
|
5
|
-
export declare class TextRange {
|
|
6
|
-
/**
|
|
7
|
-
* The start character index.
|
|
8
|
-
*/
|
|
9
|
-
start: number;
|
|
10
|
-
/**
|
|
11
|
-
* The length in characters.
|
|
12
|
-
*/
|
|
13
|
-
length: number;
|
|
14
|
-
/**
|
|
15
|
-
* Parse the specified text representing a range, in the form "startxlength"
|
|
16
|
-
* or just "start" when length is 1.
|
|
17
|
-
*
|
|
18
|
-
* @param text The text.
|
|
19
|
-
*/
|
|
20
|
-
static parse(text: string): TextRange | null;
|
|
21
|
-
constructor(start: number, length: number);
|
|
22
|
-
/**
|
|
23
|
-
* Get the inclusive end of the range.
|
|
24
|
-
*/
|
|
25
|
-
end(): number;
|
|
26
|
-
/**
|
|
27
|
-
* True if this range value is equal to the other range value.
|
|
28
|
-
* @param other The other range.
|
|
29
|
-
*/
|
|
30
|
-
isEqual(other: TextRange): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Get a parsable textual representation of this range.
|
|
33
|
-
* @returns Text.
|
|
34
|
-
*/
|
|
35
|
-
toString(): string;
|
|
36
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A simple text range, expressed as start character index and characters
|
|
3
|
+
* length. This is used for misspellings operations.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TextRange {
|
|
6
|
+
/**
|
|
7
|
+
* The start character index.
|
|
8
|
+
*/
|
|
9
|
+
start: number;
|
|
10
|
+
/**
|
|
11
|
+
* The length in characters.
|
|
12
|
+
*/
|
|
13
|
+
length: number;
|
|
14
|
+
/**
|
|
15
|
+
* Parse the specified text representing a range, in the form "startxlength"
|
|
16
|
+
* or just "start" when length is 1.
|
|
17
|
+
*
|
|
18
|
+
* @param text The text.
|
|
19
|
+
*/
|
|
20
|
+
static parse(text: string): TextRange | null;
|
|
21
|
+
constructor(start: number, length: number);
|
|
22
|
+
/**
|
|
23
|
+
* Get the inclusive end of the range.
|
|
24
|
+
*/
|
|
25
|
+
end(): number;
|
|
26
|
+
/**
|
|
27
|
+
* True if this range value is equal to the other range value.
|
|
28
|
+
* @param other The other range.
|
|
29
|
+
*/
|
|
30
|
+
isEqual(other: TextRange): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Get a parsable textual representation of this range.
|
|
33
|
+
* @returns Text.
|
|
34
|
+
*/
|
|
35
|
+
toString(): string;
|
|
36
|
+
}
|