@myrmidon/cadmus-part-general-pg 0.2.0 → 0.3.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.
Files changed (24) hide show
  1. package/esm2020/lib/bibliography-part-feature/edit-bibliography-part.store.mjs +2 -3
  2. package/esm2020/lib/categories-part-feature/edit-categories-part.store.mjs +2 -3
  3. package/esm2020/lib/comment-part-feature/edit-comment-part.store.mjs +2 -3
  4. package/esm2020/lib/doc-references-part-feature/edit-doc-references-part.store.mjs +2 -3
  5. package/esm2020/lib/historical-date-part-feature/edit-historical-date-part.store.mjs +3 -4
  6. package/esm2020/lib/index-keywords-part-feature/edit-index-keywords-part.store.mjs +2 -3
  7. package/esm2020/lib/keywords-part-feature/edit-keywords-part.store.mjs +2 -3
  8. package/esm2020/lib/note-part-feature/edit-note-part.store.mjs +2 -3
  9. package/esm2020/lib/tiled-text-layer-part-feature/tiled-text-layer-part-feature.component.mjs +60 -24
  10. package/esm2020/lib/tiled-text-layer-part-feature/tiled-text-layer-view.mjs +6 -6
  11. package/esm2020/lib/tiled-text-part-feature/edit-tiled-text-part.service.mjs +3 -3
  12. package/esm2020/lib/tiled-text-part-feature/edit-tiled-text-part.store.mjs +2 -3
  13. package/esm2020/lib/tiled-text-part-feature/tiled-text-part-feature.component.mjs +2 -2
  14. package/esm2020/lib/token-text-layer-part-feature/token-text-layer-part-feature.component.mjs +51 -22
  15. package/esm2020/lib/token-text-part-feature/edit-token-text-part.store.mjs +2 -3
  16. package/esm2020/lib/token-text-part-feature/token-text-part-feature.component.mjs +2 -2
  17. package/fesm2015/myrmidon-cadmus-part-general-pg.mjs +134 -64
  18. package/fesm2015/myrmidon-cadmus-part-general-pg.mjs.map +1 -1
  19. package/fesm2020/myrmidon-cadmus-part-general-pg.mjs +129 -64
  20. package/fesm2020/myrmidon-cadmus-part-general-pg.mjs.map +1 -1
  21. package/lib/tiled-text-layer-part-feature/tiled-text-layer-part-feature.component.d.ts +12 -12
  22. package/lib/tiled-text-part-feature/edit-tiled-text-part.service.d.ts +2 -2
  23. package/lib/token-text-layer-part-feature/token-text-layer-part-feature.component.d.ts +10 -10
  24. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, Component, NgModule } from '@angular/core';
3
3
  import * as i5 from '@myrmidon/cadmus-state';
4
- import { editPartInitialState, EditPartQueryBase, EditPartServiceBase, EditPartFeatureBase, editFragmentInitialState, EditFragmentQueryBase, EditFragmentServiceBase, EditFragmentFeatureBase, CadmusStateModule } from '@myrmidon/cadmus-state';
4
+ import { EditPartQueryBase, EditPartServiceBase, EditPartFeatureBase, editFragmentInitialState, EditFragmentQueryBase, EditFragmentServiceBase, EditFragmentFeatureBase, CadmusStateModule } from '@myrmidon/cadmus-state';
5
5
  import * as i1 from '@angular/router';
6
6
  import { RouterModule } from '@angular/router';
7
7
  import * as i2$1 from '@angular/material/snack-bar';
@@ -34,7 +34,7 @@ import { NgToolsModule } from '@myrmidon/ng-tools';
34
34
 
35
35
  let EditBibliographyPartStore = class EditBibliographyPartStore extends Store {
36
36
  constructor() {
37
- super(editPartInitialState);
37
+ super({});
38
38
  }
39
39
  setDirty(value) {
40
40
  this.update({ dirty: value });
@@ -100,7 +100,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
100
100
 
101
101
  let EditCategoriesPartStore = class EditCategoriesPartStore extends Store {
102
102
  constructor() {
103
- super(editPartInitialState);
103
+ super({});
104
104
  }
105
105
  setDirty(value) {
106
106
  this.update({ dirty: value });
@@ -293,7 +293,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
293
293
 
294
294
  let EditCommentPartStore = class EditCommentPartStore extends Store {
295
295
  constructor() {
296
- super(editPartInitialState);
296
+ super({});
297
297
  }
298
298
  setDirty(value) {
299
299
  this.update({ dirty: value });
@@ -361,7 +361,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
361
361
 
362
362
  let EditDocReferencesPartStore = class EditDocReferencesPartStore extends Store {
363
363
  constructor() {
364
- super(editPartInitialState);
364
+ super({});
365
365
  }
366
366
  setDirty(value) {
367
367
  this.update({ dirty: value });
@@ -422,7 +422,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
422
422
 
423
423
  let EditHistoricalDatePartStore = class EditHistoricalDatePartStore extends Store {
424
424
  constructor() {
425
- super(editPartInitialState);
425
+ super({});
426
426
  }
427
427
  setDirty(value) {
428
428
  this.update({ dirty: value });
@@ -483,7 +483,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
483
483
 
484
484
  let EditIndexKeywordsPartStore = class EditIndexKeywordsPartStore extends Store {
485
485
  constructor() {
486
- super(editPartInitialState);
486
+ super({});
487
487
  }
488
488
  setDirty(value) {
489
489
  this.update({ dirty: value });
@@ -544,7 +544,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
544
544
 
545
545
  let EditKeywordsPartStore = class EditKeywordsPartStore extends Store {
546
546
  constructor() {
547
- super(editPartInitialState);
547
+ super({});
548
548
  }
549
549
  setDirty(value) {
550
550
  this.update({ dirty: value });
@@ -605,7 +605,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
605
605
 
606
606
  let EditNotePartStore = class EditNotePartStore extends Store {
607
607
  constructor() {
608
- super(editPartInitialState);
608
+ super({});
609
609
  }
610
610
  setDirty(value) {
611
611
  this.update({ dirty: value });
@@ -727,8 +727,8 @@ class TiledTextLayerView {
727
727
  for (let j = 0; j < row.tiles.length; j++) {
728
728
  const tile = row.tiles[j];
729
729
  row.tiles[j] = {
730
- checked: hasChecked ? state.checked : tile.checked,
731
- frIndex: hasFrIndex ? state.frIndex : tile.frIndex,
730
+ checked: (hasChecked ? state.checked : tile.checked) ? true : false,
731
+ frIndex: hasFrIndex ? state.frIndex || -1 : tile.frIndex,
732
732
  model: tile.model,
733
733
  };
734
734
  }
@@ -965,12 +965,12 @@ class TiledTextLayerView {
965
965
  y1 = next.y;
966
966
  x1 = next.x;
967
967
  }
968
+ this.linearSetCheck(y1, x1, yx.y, yx.x, false);
968
969
  }
969
970
  else {
970
971
  y1 = 1;
971
972
  x1 = 1;
972
973
  }
973
- this.linearSetCheck(y1, x1, yx.y, yx.x, false);
974
974
  }
975
975
  }
976
976
  /**
@@ -987,10 +987,10 @@ class TiledTextLayerView {
987
987
  }
988
988
  const end = this.findFirstCheckedCoords(start.y, start.x, false);
989
989
  if (!end || (end.y === start.y && end.x === start.x)) {
990
- return;
990
+ return null;
991
991
  }
992
992
  const last = this.getPrevTileCoords(end.y, end.x);
993
- return last.y === start.y && last.x === start.x
993
+ return !last || (last.y === start.y && last.x === start.x)
994
994
  ? new TokenLocation(new TokenPoint(start.y, start.x))
995
995
  : new TokenLocation(new TokenPoint(start.y, start.x), new TokenPoint(last.y, last.x));
996
996
  }
@@ -1068,25 +1068,13 @@ class TiledTextLayerPartFeatureComponent {
1068
1068
  this.itemId = route.snapshot.params['iid'];
1069
1069
  this.partId = route.snapshot.params['pid'];
1070
1070
  if (this.partId === 'new') {
1071
- this.partId = null;
1071
+ this.partId = undefined;
1072
1072
  }
1073
1073
  this.roleId = route.snapshot.queryParams['rid'];
1074
1074
  if (this.roleId === 'default') {
1075
- this.roleId = null;
1075
+ this.roleId = undefined;
1076
1076
  }
1077
1077
  this.userLevel = authService.getCurrentUserLevel();
1078
- }
1079
- canDeactivate() {
1080
- return true;
1081
- }
1082
- ensureItemLoaded(id) {
1083
- if (!this._editItemQuery.hasItem(id)) {
1084
- this._editItemService.load(id);
1085
- }
1086
- }
1087
- ngOnInit() {
1088
- // base text: connect rows to the base text part
1089
- this.rows$ = this._editQuery.select((state) => { var _a; return (_a = state.baseTextPart) === null || _a === void 0 ? void 0 : _a.rows; });
1090
1078
  // layers part
1091
1079
  this.loading$ = this._editQuery.selectLoading();
1092
1080
  this.error$ = this._editQuery.selectError();
@@ -1097,23 +1085,39 @@ class TiledTextLayerPartFeatureComponent {
1097
1085
  this.layerHints$ = this._editQuery.selectLayerHints();
1098
1086
  this.patchingLayer$ = this._editQuery.selectPatchingLayers();
1099
1087
  this.deletingFragment$ = this._editQuery.selectDeletingFragment();
1088
+ // base text: connect rows to the base text part
1089
+ this.rows$ = this._editQuery.select((state) => { var _a; return (_a = state.baseTextPart) === null || _a === void 0 ? void 0 : _a.rows; });
1090
+ }
1091
+ canDeactivate() {
1092
+ return true;
1093
+ }
1094
+ ensureItemLoaded(id) {
1095
+ if (!this._editItemQuery.hasItem(id)) {
1096
+ this._editItemService.load(id);
1097
+ }
1098
+ }
1099
+ ngOnInit() {
1100
1100
  // when the base text changes, load all the fragments locations
1101
1101
  // and setup their UI state
1102
1102
  this.rows$.subscribe((rows) => {
1103
1103
  var _a;
1104
- this.view = rows ? new TiledTextLayerView(rows) : null;
1104
+ this.view = rows ? new TiledTextLayerView(rows) : undefined;
1105
1105
  (_a = this.view) === null || _a === void 0 ? void 0 : _a.setFragmentLocations(this._editQuery.getValue().locations);
1106
1106
  });
1107
1107
  // ensure that the container item is loaded
1108
1108
  this.ensureItemLoaded(this.itemId);
1109
1109
  // load the layer part
1110
- this._editService.load(this.itemId, this.partId);
1110
+ if (this.partId) {
1111
+ this._editService.load(this.itemId, this.partId);
1112
+ }
1111
1113
  }
1112
1114
  refreshBreakChance() {
1113
1115
  this._editService.refreshBreakChance();
1114
1116
  }
1115
1117
  onTileChecked(y, x, checked) {
1116
- this.view.toggleLinearTileCheck(y, x, checked);
1118
+ if (this.view) {
1119
+ this.view.toggleLinearTileCheck(y, x, checked);
1120
+ }
1117
1121
  }
1118
1122
  getSelectedTileCoords() {
1119
1123
  if (!this.selectedTile || !this.view) {
@@ -1128,6 +1132,9 @@ class TiledTextLayerPartFeatureComponent {
1128
1132
  return null;
1129
1133
  }
1130
1134
  selectPrevTile() {
1135
+ if (!this.view) {
1136
+ return;
1137
+ }
1131
1138
  let yx = this.getSelectedTileCoords();
1132
1139
  if (yx) {
1133
1140
  yx = this.view.getPrevTileCoords(yx.y, yx.x);
@@ -1137,6 +1144,9 @@ class TiledTextLayerPartFeatureComponent {
1137
1144
  }
1138
1145
  }
1139
1146
  selectNextTile() {
1147
+ if (!this.view) {
1148
+ return;
1149
+ }
1140
1150
  let yx = this.getSelectedTileCoords();
1141
1151
  if (yx) {
1142
1152
  yx = this.view.getNextTileCoords(yx.y, yx.x);
@@ -1146,6 +1156,9 @@ class TiledTextLayerPartFeatureComponent {
1146
1156
  }
1147
1157
  }
1148
1158
  deleteFragment() {
1159
+ if (!this.view) {
1160
+ return;
1161
+ }
1149
1162
  const lf = this.view.getCheckedLocationAndFragment();
1150
1163
  if (!lf || lf.fragment === -1) {
1151
1164
  return;
@@ -1155,10 +1168,14 @@ class TiledTextLayerPartFeatureComponent {
1155
1168
  this._dialogService
1156
1169
  .confirm('Delete Fragment', `Delete the fragment at ${loc}?`)
1157
1170
  .subscribe((ok) => {
1171
+ var _a;
1158
1172
  if (ok) {
1159
1173
  // find the fragment and remove it from the part
1160
- const i = this._editQuery.getValue().part.fragments.findIndex((p) => {
1161
- return TokenLocation.parse(p.location).overlaps(loc);
1174
+ const i = (_a = this._editQuery
1175
+ .getValue()
1176
+ .part) === null || _a === void 0 ? void 0 : _a.fragments.findIndex((p) => {
1177
+ var _a;
1178
+ return (_a = TokenLocation.parse(p.location)) === null || _a === void 0 ? void 0 : _a.overlaps(loc);
1162
1179
  });
1163
1180
  if (i === -1) {
1164
1181
  return;
@@ -1169,10 +1186,15 @@ class TiledTextLayerPartFeatureComponent {
1169
1186
  }
1170
1187
  deleteFragmentFromHint(hint) {
1171
1188
  const loc = TokenLocation.parse(hint.location);
1172
- this._editService.deleteFragment(loc);
1189
+ if (loc) {
1190
+ this._editService.deleteFragment(loc);
1191
+ }
1173
1192
  }
1174
1193
  navigateToFragmentEditor(loc) {
1175
1194
  const part = this._editQuery.getValue().part;
1195
+ if (!part) {
1196
+ return;
1197
+ }
1176
1198
  const { route, rid } = this._libraryRouteService.buildFragmentEditorRoute(this._editItemQuery.getValue().facet.partDefinitions, part.itemId, part.id, part.typeId, part.roleId, loc);
1177
1199
  // navigate to the editor
1178
1200
  this._router.navigate([route], rid
@@ -1184,6 +1206,9 @@ class TiledTextLayerPartFeatureComponent {
1184
1206
  : {});
1185
1207
  }
1186
1208
  editFragment() {
1209
+ if (!this.view) {
1210
+ return;
1211
+ }
1187
1212
  const lf = this.view.getCheckedLocationAndFragment();
1188
1213
  if (!lf || lf.fragment === -1) {
1189
1214
  return;
@@ -1195,7 +1220,9 @@ class TiledTextLayerPartFeatureComponent {
1195
1220
  this.navigateToFragmentEditor(hint.location);
1196
1221
  }
1197
1222
  moveFragmentFromHint(hint) {
1198
- if (!this.pickedLocation || this.pickedLocation === hint.location) {
1223
+ if (!this.pickedLocation ||
1224
+ this.pickedLocation === hint.location ||
1225
+ !this.partId) {
1199
1226
  return;
1200
1227
  }
1201
1228
  this._editService.applyLayerPatches(this.partId, [
@@ -1203,6 +1230,9 @@ class TiledTextLayerPartFeatureComponent {
1203
1230
  ]);
1204
1231
  }
1205
1232
  addFragment() {
1233
+ if (!this.view) {
1234
+ return;
1235
+ }
1206
1236
  const lf = this.view.getCheckedLocationAndFragment();
1207
1237
  if (!lf || lf.fragment > -1) {
1208
1238
  return;
@@ -1210,6 +1240,9 @@ class TiledTextLayerPartFeatureComponent {
1210
1240
  this.navigateToFragmentEditor(lf.location.toString());
1211
1241
  }
1212
1242
  pickLocation() {
1243
+ if (!this.view) {
1244
+ return;
1245
+ }
1213
1246
  const lf = this.view.getCheckedLocationAndFragment();
1214
1247
  if (!lf) {
1215
1248
  return;
@@ -1218,11 +1251,16 @@ class TiledTextLayerPartFeatureComponent {
1218
1251
  this.pickedLocation = (lf.fragment === -1 ? lf.location : locations[lf.fragment]).toString();
1219
1252
  }
1220
1253
  clearTileChecks() {
1254
+ if (!this.view) {
1255
+ return;
1256
+ }
1221
1257
  this.view.setAllTilesViewState({ checked: false });
1222
- this.pickedLocation = null;
1258
+ this.pickedLocation = undefined;
1223
1259
  }
1224
1260
  applyLayerPatches(patches) {
1225
- this._editService.applyLayerPatches(this.partId, patches);
1261
+ if (this.partId) {
1262
+ this._editService.applyLayerPatches(this.partId, patches);
1263
+ }
1226
1264
  }
1227
1265
  close() {
1228
1266
  this._router.navigate(['/items', this.itemId]);
@@ -1237,7 +1275,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
1237
1275
 
1238
1276
  let EditTiledTextPartStore = class EditTiledTextPartStore extends Store {
1239
1277
  constructor() {
1240
- super(editPartInitialState);
1278
+ super({});
1241
1279
  }
1242
1280
  setDirty(value) {
1243
1281
  this.update({ dirty: value });
@@ -1281,10 +1319,10 @@ class EditTiledTextPartService extends EditPartServiceBase {
1281
1319
  * @param itemId The item's ID.
1282
1320
  * @param thesauriIds The optional thesauri IDs.
1283
1321
  */
1284
- loadBaseTextPart(itemId, thesauriIds = null) {
1322
+ loadBaseTextPart(itemId, thesauriIds) {
1285
1323
  // get the base text part ID from the item's ID
1286
1324
  this.itemService
1287
- .getPartFromTypeAndRole(itemId, null, 'base-text')
1325
+ .getPartFromTypeAndRole(itemId, 'any', 'base-text')
1288
1326
  .subscribe((part) => {
1289
1327
  this.load(part.id, thesauriIds);
1290
1328
  }, (error) => {
@@ -1304,7 +1342,7 @@ class TiledTextPartFeatureComponent extends EditPartFeatureBase {
1304
1342
  super(router, route, snackbar, editPartQuery, editPartService, editItemQuery, editItemService);
1305
1343
  }
1306
1344
  ngOnInit() {
1307
- this.initEditor(null);
1345
+ this.initEditor();
1308
1346
  }
1309
1347
  }
1310
1348
  TiledTextPartFeatureComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TiledTextPartFeatureComponent, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }, { token: i2$1.MatSnackBar }, { token: EditTiledTextPartQuery }, { token: EditTiledTextPartService }, { token: i5.EditItemQuery }, { token: i5.EditItemService }], target: i0.ɵɵFactoryTarget.Component });
@@ -1335,13 +1373,22 @@ class TokenTextLayerPartFeatureComponent {
1335
1373
  this.itemId = route.snapshot.params.iid;
1336
1374
  this.partId = route.snapshot.params.pid;
1337
1375
  if (this.partId === 'new') {
1338
- this.partId = null;
1376
+ this.partId = undefined;
1339
1377
  }
1340
1378
  this.roleId = route.snapshot.queryParams.rid;
1341
1379
  if (this.roleId === 'default') {
1342
- this.roleId = null;
1380
+ this.roleId = undefined;
1343
1381
  }
1344
1382
  this.userLevel = authService.getCurrentUserLevel();
1383
+ this.loading$ = this._editQuery.selectLoading();
1384
+ this.error$ = this._editQuery.selectError();
1385
+ this.baseText$ = this._editQuery.select((state) => state.baseText);
1386
+ this.locations$ = this._editQuery.select((state) => state.locations);
1387
+ this.refreshingBreakChance$ = this._editQuery.selectRefreshingBreakChance();
1388
+ this.breakChance$ = this._editQuery.selectBreakChance();
1389
+ this.layerHints$ = this._editQuery.selectLayerHints();
1390
+ this.patchingLayer$ = this._editQuery.selectPatchingLayers();
1391
+ this.deletingFragment$ = this._editQuery.selectDeletingFragment();
1345
1392
  }
1346
1393
  canDeactivate() {
1347
1394
  return true;
@@ -1366,15 +1413,6 @@ class TokenTextLayerPartFeatureComponent {
1366
1413
  this.textSize = size;
1367
1414
  }
1368
1415
  ngOnInit() {
1369
- this.loading$ = this._editQuery.selectLoading();
1370
- this.error$ = this._editQuery.selectError();
1371
- this.baseText$ = this._editQuery.select((state) => state.baseText);
1372
- this.locations$ = this._editQuery.select((state) => state.locations);
1373
- this.refreshingBreakChance$ = this._editQuery.selectRefreshingBreakChance();
1374
- this.breakChance$ = this._editQuery.selectBreakChance();
1375
- this.layerHints$ = this._editQuery.selectLayerHints();
1376
- this.patchingLayer$ = this._editQuery.selectPatchingLayers();
1377
- this.deletingFragment$ = this._editQuery.selectDeletingFragment();
1378
1416
  // when the base text changes, load all the fragments locations
1379
1417
  // this.baseText$.subscribe(_ => {
1380
1418
  // this.loadAllFragmentLocations();
@@ -1382,10 +1420,16 @@ class TokenTextLayerPartFeatureComponent {
1382
1420
  // ensure the container item is loaded
1383
1421
  this.ensureItemLoaded(this.itemId);
1384
1422
  // load the layer part data
1385
- this._editService.load(this.itemId, this.partId);
1423
+ if (this.partId) {
1424
+ this._editService.load(this.itemId, this.partId);
1425
+ }
1386
1426
  }
1387
1427
  deleteFragment() {
1388
- const location = this._textLayerService.getSelectedLocationForEdit(this._textLayerService.getSelectedRange());
1428
+ const range = this._textLayerService.getSelectedRange();
1429
+ if (!range) {
1430
+ return;
1431
+ }
1432
+ const location = this._textLayerService.getSelectedLocationForEdit(range);
1389
1433
  if (!location) {
1390
1434
  return;
1391
1435
  }
@@ -1394,8 +1438,11 @@ class TokenTextLayerPartFeatureComponent {
1394
1438
  .subscribe((ok) => {
1395
1439
  if (ok) {
1396
1440
  // find the fragment and remove it from the part
1397
- const i = this._editQuery.getValue().part.fragments.findIndex((p) => {
1398
- return TokenLocation.parse(p.location).overlaps(location);
1441
+ const i = this._editQuery
1442
+ .getValue()
1443
+ .part.fragments.findIndex((p) => {
1444
+ var _a;
1445
+ return (_a = TokenLocation.parse(p.location)) === null || _a === void 0 ? void 0 : _a.overlaps(location);
1399
1446
  });
1400
1447
  if (i === -1) {
1401
1448
  return;
@@ -1406,13 +1453,18 @@ class TokenTextLayerPartFeatureComponent {
1406
1453
  }
1407
1454
  deleteFragmentFromHint(hint) {
1408
1455
  const loc = TokenLocation.parse(hint.location);
1409
- this._editService.deleteFragment(loc);
1456
+ if (loc) {
1457
+ this._editService.deleteFragment(loc);
1458
+ }
1410
1459
  }
1411
1460
  refreshBreakChance() {
1412
1461
  this._editService.refreshBreakChance();
1413
1462
  }
1414
1463
  navigateToFragmentEditor(loc) {
1415
1464
  const part = this._editQuery.getValue().part;
1465
+ if (!part) {
1466
+ return;
1467
+ }
1416
1468
  const { route, rid } = this._libraryRouteService.buildFragmentEditorRoute(this._editItemQuery.getValue().facet.partDefinitions, part.itemId, part.id, part.typeId, part.roleId, loc);
1417
1469
  // navigate to the editor
1418
1470
  this._router.navigate([route], rid
@@ -1424,7 +1476,11 @@ class TokenTextLayerPartFeatureComponent {
1424
1476
  : {});
1425
1477
  }
1426
1478
  editFragment() {
1427
- const location = this._textLayerService.getSelectedLocationForEdit(this._textLayerService.getSelectedRange());
1479
+ const range = this._textLayerService.getSelectedRange();
1480
+ if (!range) {
1481
+ return;
1482
+ }
1483
+ const location = this._textLayerService.getSelectedLocationForEdit(range);
1428
1484
  if (location) {
1429
1485
  this.navigateToFragmentEditor(location.toString());
1430
1486
  }
@@ -1433,13 +1489,20 @@ class TokenTextLayerPartFeatureComponent {
1433
1489
  this.navigateToFragmentEditor(hint.location);
1434
1490
  }
1435
1491
  addFragment() {
1436
- const location = this._textLayerService.getSelectedLocationForNew(this._textLayerService.getSelectedRange(), this._editQuery.getValue().baseText);
1492
+ var _a;
1493
+ const range = this._textLayerService.getSelectedRange();
1494
+ if (!range) {
1495
+ return;
1496
+ }
1497
+ const location = this._textLayerService.getSelectedLocationForNew(range, ((_a = this._editQuery.getValue()) === null || _a === void 0 ? void 0 : _a.baseText) || '');
1437
1498
  if (location) {
1438
1499
  this.navigateToFragmentEditor(location.toString());
1439
1500
  }
1440
1501
  }
1441
1502
  moveFragmentFromHint(hint) {
1442
- if (!this.pickedLocation || this.pickedLocation === hint.location) {
1503
+ if (!this.pickedLocation ||
1504
+ this.pickedLocation === hint.location ||
1505
+ !this.partId) {
1443
1506
  return;
1444
1507
  }
1445
1508
  this._editService.applyLayerPatches(this.partId, [
@@ -1447,10 +1510,17 @@ class TokenTextLayerPartFeatureComponent {
1447
1510
  ]);
1448
1511
  }
1449
1512
  applyLayerPatches(patches) {
1450
- this._editService.applyLayerPatches(this.partId, patches);
1513
+ if (this.partId) {
1514
+ this._editService.applyLayerPatches(this.partId, patches);
1515
+ }
1451
1516
  }
1452
1517
  pickLocation() {
1453
- const location = this._textLayerService.getSelectedLocationForNew(this._textLayerService.getSelectedRange(), this._editQuery.getValue().baseText);
1518
+ var _a;
1519
+ const range = this._textLayerService.getSelectedRange();
1520
+ if (!range) {
1521
+ return;
1522
+ }
1523
+ const location = this._textLayerService.getSelectedLocationForNew(range, ((_a = this._editQuery.getValue()) === null || _a === void 0 ? void 0 : _a.baseText) || '');
1454
1524
  if (location) {
1455
1525
  this.pickedLocation = location.toString();
1456
1526
  }
@@ -1468,7 +1538,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.2", ngImpor
1468
1538
 
1469
1539
  let EditTokenTextPartStore = class EditTokenTextPartStore extends Store {
1470
1540
  constructor() {
1471
- super(editPartInitialState);
1541
+ super({});
1472
1542
  }
1473
1543
  setDirty(value) {
1474
1544
  this.update({ dirty: value });
@@ -1517,7 +1587,7 @@ class TokenTextPartFeatureComponent extends EditPartFeatureBase {
1517
1587
  super(router, route, snackbar, editPartQuery, editPartService, editItemQuery, editItemService);
1518
1588
  }
1519
1589
  ngOnInit() {
1520
- this.initEditor(null);
1590
+ this.initEditor();
1521
1591
  }
1522
1592
  }
1523
1593
  TokenTextPartFeatureComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.2", ngImport: i0, type: TokenTextPartFeatureComponent, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }, { token: i2$1.MatSnackBar }, { token: EditTokenTextPartQuery }, { token: EditTokenTextPartService }, { token: i5.EditItemQuery }, { token: i5.EditItemService }], target: i0.ɵɵFactoryTarget.Component });