structured-fw 1.2.0 → 1.2.2

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.
@@ -102,10 +102,15 @@ export class ClientComponent extends EventEmitter {
102
102
  }
103
103
  const initializer = this.app.getInitializer(this.name);
104
104
  if (initializer !== null) {
105
- await initializer.apply(this, [{
106
- net: this.net,
107
- isRedraw
108
- }]);
105
+ try {
106
+ await initializer.apply(this, [{
107
+ net: this.net,
108
+ isRedraw
109
+ }]);
110
+ }
111
+ catch (e) {
112
+ this.error(`Initializer error: ${e.stack}`);
113
+ }
109
114
  this.updateConditionals(false);
110
115
  }
111
116
  await this.emitterReady();
@@ -588,10 +593,10 @@ export class ClientComponent extends EventEmitter {
588
593
  }
589
594
  show(domNode, enableTransition = true) {
590
595
  if (!enableTransition) {
591
- domNode.style.display = '';
596
+ domNode.classList.remove('structured-hidden');
592
597
  return;
593
598
  }
594
- if (domNode.style.display !== 'none') {
599
+ if (!domNode.classList.contains('structured-hidden')) {
595
600
  return;
596
601
  }
597
602
  const transitions = this.transitionAttributes(domNode).show;
@@ -602,11 +607,10 @@ export class ClientComponent extends EventEmitter {
602
607
  prev[key] = transitions[key];
603
608
  return prev;
604
609
  }, {});
610
+ domNode.classList.remove('structured-hidden');
605
611
  if (Object.keys(transitionsActive).length === 0) {
606
- domNode.style.display = '';
607
612
  return;
608
613
  }
609
- domNode.style.display = '';
610
614
  const onTransitionEnd = (e) => {
611
615
  domNode.style.opacity = '1';
612
616
  domNode.style.transition = '';
@@ -652,10 +656,10 @@ export class ClientComponent extends EventEmitter {
652
656
  }
653
657
  hide(domNode, enableTransition = true) {
654
658
  if (!enableTransition) {
655
- domNode.style.display = 'none';
659
+ domNode.classList.add('structured-hidden');
656
660
  return;
657
661
  }
658
- if (domNode.style.display === 'none') {
662
+ if (domNode.classList.contains('structured-hidden')) {
659
663
  return;
660
664
  }
661
665
  const transitions = this.transitionAttributes(domNode).hide;
@@ -667,11 +671,11 @@ export class ClientComponent extends EventEmitter {
667
671
  return prev;
668
672
  }, {});
669
673
  if (Object.keys(transitionsActive).length === 0) {
670
- domNode.style.display = 'none';
674
+ domNode.classList.add('structured-hidden');
671
675
  }
672
676
  else {
673
677
  const onTransitionEnd = (e) => {
674
- domNode.style.display = 'none';
678
+ domNode.classList.add('structured-hidden');
675
679
  domNode.style.opacity = '1';
676
680
  domNode.style.transition = '';
677
681
  domNode.style.transformOrigin = 'unset';
@@ -1,11 +1,9 @@
1
1
  import { Document } from './Document.js';
2
2
  import { LooseObject } from '../types/general.types.js';
3
- import { ComponentEntry } from "../types/component.types.js";
3
+ import { ComponentEntry, ComponentEvents } from "../types/component.types.js";
4
4
  import { DOMNode } from './dom/DOMNode.js';
5
5
  import { EventEmitter } from '../EventEmitter.js';
6
- export declare class Component<Events extends Record<string, any> = {
7
- 'componentCreated': Component;
8
- }> extends EventEmitter<Events> {
6
+ export declare class Component<Events extends Record<string, any> = ComponentEvents> extends EventEmitter<Events> {
9
7
  id: string;
10
8
  name: string;
11
9
  document: Document;
@@ -134,9 +134,16 @@ export class Component extends EventEmitter {
134
134
  if (this.isRoot) {
135
135
  const dataIf = this.dom.queryByHasAttribute('data-if');
136
136
  for (let i = 0; i < dataIf.length; i++) {
137
- dataIf[i].style.display = 'none';
137
+ const className = dataIf[i].getAttribute('class');
138
+ if (typeof className === 'string') {
139
+ dataIf[i].setAttribute('class', `${className} structured-hidden`);
140
+ }
141
+ else {
142
+ dataIf[i].setAttribute('class', 'structured-hidden');
143
+ }
138
144
  }
139
145
  }
146
+ await this.emit('ready');
140
147
  }
141
148
  setAttributes(attributes, prefix = '', encode = true) {
142
149
  if (typeof attributes === 'object' && attributes !== null) {
@@ -7,6 +7,7 @@ import { DocumentHead } from './DocumentHead.js';
7
7
  import { Component } from './Component.js';
8
8
  export declare class Document extends Component<{
9
9
  'componentCreated': Component;
10
+ 'beforeRender': void;
10
11
  }> {
11
12
  head: DocumentHead;
12
13
  language: string;
@@ -19,6 +19,13 @@ export class Document extends Component {
19
19
  this.document = this;
20
20
  this.head = new DocumentHead(title);
21
21
  this.head.addJS('/assets/client-js/client/Client.js', 0, { type: 'module' });
22
+ this.head.add(`
23
+ <style>
24
+ .structured-hidden {
25
+ display: none !important;
26
+ }
27
+ </style>
28
+ `);
22
29
  this.application.emit('documentCreated', this);
23
30
  }
24
31
  push(response) {
@@ -53,6 +60,7 @@ export class Document extends Component {
53
60
  this.head.add(clientConfString);
54
61
  }
55
62
  toString() {
63
+ this.emit('beforeRender');
56
64
  if (!this.initializersInitialized) {
57
65
  this.initInitializers();
58
66
  this.initClientConfig();
@@ -29,7 +29,13 @@ export class Layout {
29
29
  await component.init(`<${componentName}></${componentName}>`, data);
30
30
  const conditionals = component.dom.queryByHasAttribute('data-if');
31
31
  for (let i = 0; i < conditionals.length; i++) {
32
- conditionals[i].style.display = 'none';
32
+ const className = conditionals[i].getAttribute('class');
33
+ if (typeof className === 'string') {
34
+ conditionals[i].setAttribute('class', `${className} structured-hidden`);
35
+ }
36
+ else {
37
+ conditionals[i].setAttribute('class', 'structured-hidden');
38
+ }
33
39
  }
34
40
  return doc;
35
41
  }
@@ -131,6 +131,7 @@ export class Request {
131
131
  },
132
132
  show404: async () => {
133
133
  this.app.emit('pageNotFound', context);
134
+ response.statusCode = 404;
134
135
  const res = await this.pageNotFoundCallback.apply(this.app, [context]);
135
136
  if (res instanceof Document) {
136
137
  context.respondWith(res);
@@ -25,6 +25,7 @@ export declare class DOMNode {
25
25
  potentialComponentChildren: Array<DOMNode>;
26
26
  constructor(root: DOMFragment | null, parentNode: DOMNode | null, tagName: string);
27
27
  appendChild(node: DOMNode | string): void;
28
+ getAttribute(attrName: string): string | true | null;
28
29
  setAttribute(attributeName: string, attributeValue: string | true): void;
29
30
  hasAttribute(attributeName: string): boolean;
30
31
  queryByTagName(...tagNames: Array<string>): Array<DOMNode>;
@@ -30,6 +30,12 @@ export class DOMNode {
30
30
  }
31
31
  this.children.push(node);
32
32
  }
33
+ getAttribute(attrName) {
34
+ if (!this.hasAttribute(attrName)) {
35
+ return null;
36
+ }
37
+ return this.attributeMap[attrName].value;
38
+ }
33
39
  setAttribute(attributeName, attributeValue) {
34
40
  const attributeExisting = this.attributeMap[attributeName];
35
41
  if (!attributeExisting) {
@@ -36,6 +36,10 @@ export interface ComponentScaffold<T extends LooseObject = LooseObject, K extend
36
36
  getData: (this: ComponentScaffold, data: LooseObject, ctx: undefined | RequestContext, app: Application, component: Component) => Promise<T | void>;
37
37
  [key: string]: any;
38
38
  }
39
+ export type ComponentEvents = {
40
+ componentCreated: Component;
41
+ ready: undefined;
42
+ };
39
43
  export type ClientComponentTransition = {
40
44
  fade: false | number;
41
45
  slide: false | number;
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "main": "build/index",
22
- "version": "1.2.0",
22
+ "version": "1.2.2",
23
23
  "scripts": {
24
24
  "develop": "tsc --watch",
25
25
  "startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,hbs,css index.js",