@packtrack/layout 1.3.2 → 1.4.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.
@@ -206,12 +206,12 @@ export class Layout {
206
206
  findSection(path, base, source = base) {
207
207
  const parts = path.split('.');
208
208
  if (parts.length == 0) {
209
- throw `section '${path}' not found from '${source.name}': invalid name`;
209
+ throw new Error(`Section '${path}' not found from '${source.domainName}': invalid name`);
210
210
  }
211
211
  if (parts.length == 1) {
212
212
  const localSection = base.sections.find(section => section.name == parts[0]);
213
213
  if (!localSection) {
214
- throw new Error(`Section '${path}' not found from '${source.name}': section does not exist in '${base.name}'`);
214
+ throw new Error(`Section '${path}' not found from '${source.domainName}': section does not exist in '${base.name}'`);
215
215
  }
216
216
  return localSection;
217
217
  }
@@ -219,19 +219,19 @@ export class Layout {
219
219
  let pool = base;
220
220
  for (let index = 0; index < parts.length; index++) {
221
221
  if (pool instanceof Layout || !pool.parent) {
222
- throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a parent`);
222
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': district '${pool.name}' does not have a parent`);
223
223
  }
224
224
  pool = pool.parent;
225
225
  }
226
226
  for (let part of parts) {
227
227
  const child = (pool instanceof District ? pool.children : pool.districts).find(child => child.name == part);
228
228
  if (!child) {
229
- throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
229
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': district '${pool.name}' does not have a child named '${part}'`);
230
230
  }
231
231
  pool = child;
232
232
  }
233
233
  if (pool instanceof Layout) {
234
- throw new Error(`Section '${path}' could not be found from '${source.name}': a layout cannot directly include a section`);
234
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': a layout cannot directly include a section`);
235
235
  }
236
236
  return this.findSection(sectionName, pool, source);
237
237
  }
@@ -241,7 +241,6 @@ export class Layout {
241
241
  }
242
242
  linkRouter(source, router) {
243
243
  let child = source.firstChild;
244
- let active;
245
244
  while (child) {
246
245
  if (child.tagName == 'route') {
247
246
  const route = new Route(child.getAttribute('name'), router);
@@ -249,17 +248,18 @@ export class Layout {
249
248
  route.in.out = router;
250
249
  route.out = this.findSection(child.getAttribute('out'), router.district);
251
250
  route.out.in = router;
252
- if (child.hasAttribute('active')) {
253
- if (active) {
254
- throw new Error(`Router '${router.domainName}' has multiple active routes (${active.name}, ${route.name}).`);
255
- }
256
- active = route;
257
- }
258
251
  router.routes.push(route);
259
252
  }
260
253
  child = child.nextSibling;
261
254
  }
262
- router.activeRoute = active;
255
+ const active = source.getAttribute('active');
256
+ if (active) {
257
+ const route = router.routes.find(route => route.name == active);
258
+ if (!route) {
259
+ throw new Error(`Router '${router.domainName}' cannot have active route '${active}': Router has no such route (available: ${router.routes.map(route => route.name).join(', ')})`);
260
+ }
261
+ router.activeRoute = route;
262
+ }
263
263
  }
264
264
  loadPowerDistrict(source, district) {
265
265
  const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@packtrack/layout",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": ".built/index.js",
6
6
  "typings": ".built/index.d.ts",
package/source/layout.ts CHANGED
@@ -293,14 +293,14 @@ export class Layout {
293
293
  const parts = path.split('.');
294
294
 
295
295
  if (parts.length == 0) {
296
- throw `section '${path}' not found from '${source.name}': invalid name`;
296
+ throw new Error(`Section '${path}' not found from '${source.domainName}': invalid name`);
297
297
  }
298
298
 
299
299
  if (parts.length == 1) {
300
300
  const localSection = base.sections.find(section => section.name == parts[0]);
301
301
 
302
302
  if (!localSection) {
303
- throw new Error(`Section '${path}' not found from '${source.name}': section does not exist in '${base.name}'`);
303
+ throw new Error(`Section '${path}' not found from '${source.domainName}': section does not exist in '${base.name}'`);
304
304
  }
305
305
 
306
306
  return localSection;
@@ -312,7 +312,7 @@ export class Layout {
312
312
 
313
313
  for (let index = 0; index < parts.length; index++) {
314
314
  if (pool instanceof Layout || !pool.parent) {
315
- throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a parent`);
315
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': district '${pool.name}' does not have a parent`);
316
316
  }
317
317
 
318
318
  pool = pool.parent!;
@@ -322,14 +322,14 @@ export class Layout {
322
322
  const child = (pool instanceof District ? pool.children : pool.districts).find(child => child.name == part);
323
323
 
324
324
  if (!child) {
325
- throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
325
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': district '${pool.name}' does not have a child named '${part}'`);
326
326
  }
327
327
 
328
328
  pool = child;
329
329
  }
330
330
 
331
331
  if (pool instanceof Layout) {
332
- throw new Error(`Section '${path}' could not be found from '${source.name}': a layout cannot directly include a section`);
332
+ throw new Error(`Section '${path}' could not be found from '${source.domainName}': a layout cannot directly include a section`);
333
333
  }
334
334
 
335
335
  return this.findSection(sectionName, pool, source);
@@ -343,7 +343,6 @@ export class Layout {
343
343
 
344
344
  linkRouter(source, router: Router) {
345
345
  let child = source.firstChild;
346
- let active: Route;
347
346
 
348
347
  while (child) {
349
348
  if (child.tagName == 'route') {
@@ -355,21 +354,23 @@ export class Layout {
355
354
  route.out = this.findSection(child.getAttribute('out'), router.district);
356
355
  route.out.in = router;
357
356
 
358
- if (child.hasAttribute('active')) {
359
- if (active) {
360
- throw new Error(`Router '${router.domainName}' has multiple active routes (${active.name}, ${route.name}).`);
361
- }
362
-
363
- active = route;
364
- }
365
-
366
357
  router.routes.push(route);
367
358
  }
368
359
 
369
360
  child = child.nextSibling;
370
361
  }
371
362
 
372
- router.activeRoute = active;
363
+ const active = source.getAttribute('active');
364
+
365
+ if (active) {
366
+ const route = router.routes.find(route => route.name == active);
367
+
368
+ if (!route) {
369
+ throw new Error(`Router '${router.domainName}' cannot have active route '${active}': Router has no such route (available: ${router.routes.map(route => route.name).join(', ')})`);
370
+ }
371
+
372
+ router.activeRoute = route;
373
+ }
373
374
  }
374
375
 
375
376
  loadPowerDistrict(source, district: District) {