structured-fw 1.3.1 → 1.3.3

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.
@@ -79,8 +79,11 @@ export class ClientComponent extends EventEmitter {
79
79
  }
80
80
  this.isReady = true;
81
81
  if (this.isRoot || isRedrawRoot) {
82
- this.on('initializerExecuted', () => {
82
+ this.on('initializerExecuted', async () => {
83
83
  this.emit('ready');
84
+ if (isRedraw) {
85
+ await this.emit('afterRedraw');
86
+ }
84
87
  });
85
88
  requestAnimationFrame(() => {
86
89
  this.runInitializer(isRedraw);
@@ -243,7 +246,6 @@ export class ClientComponent extends EventEmitter {
243
246
  });
244
247
  }
245
248
  }
246
- await this.emit('afterRedraw');
247
249
  }
248
250
  initConditionals(node) {
249
251
  const isSelf = node === undefined;
@@ -2,5 +2,5 @@ import { IncomingMessage, ServerResponse } from "node:http";
2
2
  import { LooseObject } from '../types/general.types.js';
3
3
  export declare class Cookies {
4
4
  parse(request: IncomingMessage): LooseObject;
5
- set(response: ServerResponse, name: string, value: string | number, lifetimeSeconds: number, path?: string, sameSite?: 'Strict' | 'Lax' | 'None', domain?: string): void;
5
+ set(response: ServerResponse, name: string, value: string | number, lifetimeSeconds: number, path?: string, sameSite?: 'Strict' | 'Lax' | 'None', domain?: string | null, secure?: boolean): void;
6
6
  }
@@ -12,8 +12,19 @@ export class Cookies {
12
12
  });
13
13
  return cookies;
14
14
  }
15
- set(response, name, value, lifetimeSeconds, path = '/', sameSite = 'Strict', domain) {
15
+ set(response, name, value, lifetimeSeconds, path = '/', sameSite = 'Strict', domain = null, secure = false) {
16
16
  const expiresAt = lifetimeSeconds > 0 ? new Date(new Date().getTime() + lifetimeSeconds * 1000).toUTCString() : 0;
17
- response.appendHeader('Set-Cookie', `${name}=${value}; Expires=${expiresAt}; Path=${path}; SameSite=${sameSite}${domain ? `; domain=${domain}` : ''}`);
17
+ const parts = [];
18
+ parts.push(`${name}=${value}`);
19
+ parts.push(`Expires=${expiresAt}`);
20
+ parts.push(`Path=${path}`);
21
+ parts.push(`SameSite=${sameSite}`);
22
+ if (typeof domain === 'string') {
23
+ parts.push(`domain=${domain}`);
24
+ }
25
+ if (secure) {
26
+ parts.push('Secure=true');
27
+ }
28
+ response.appendHeader('Set-Cookie', parts.join('; '));
18
29
  }
19
30
  }
@@ -6,7 +6,8 @@ export declare class Layout {
6
6
  layoutComponent: string;
7
7
  app: Application;
8
8
  language: string;
9
- constructor(app: Application, layoutComponent: string, language?: string);
9
+ attributes: Record<string, string>;
10
+ constructor(app: Application, layoutComponent: string, language?: string, attributes?: Record<string, string>);
10
11
  private layoutComponentExists;
11
- document(ctx: RequestContext, title: string, componentName: string, data?: LooseObject): Promise<Document>;
12
+ document(ctx: RequestContext, title: string, componentName: string, data?: LooseObject, attributes?: Record<string, string>): Promise<Document>;
12
13
  }
@@ -1,10 +1,11 @@
1
1
  import { Component } from "./Component.js";
2
2
  import { Document } from "./Document.js";
3
3
  export class Layout {
4
- constructor(app, layoutComponent, language = 'en') {
4
+ constructor(app, layoutComponent, language = 'en', attributes) {
5
5
  this.app = app;
6
6
  this.layoutComponent = layoutComponent;
7
7
  this.language = language;
8
+ this.attributes = attributes || {};
8
9
  if (this.app.initialized) {
9
10
  this.layoutComponentExists();
10
11
  }
@@ -17,7 +18,7 @@ export class Layout {
17
18
  throw new Error(`Layout component "${this.layoutComponent}" not found`);
18
19
  }
19
20
  }
20
- async document(ctx, title, componentName, data) {
21
+ async document(ctx, title, componentName, data, attributes) {
21
22
  const doc = new Document(this.app, title, ctx);
22
23
  doc.language = this.language;
23
24
  await doc.loadComponent(this.layoutComponent, data);
@@ -27,6 +28,13 @@ export class Layout {
27
28
  }
28
29
  const component = new Component(componentName, layoutComponent[0], doc, false);
29
30
  await component.init(`<${componentName}></${componentName}>`, data);
31
+ if (doc.children.length > 0) {
32
+ const attributesObject = {
33
+ ...this.attributes,
34
+ ...(attributes || {})
35
+ };
36
+ doc.children[0].setAttributes(attributesObject, '', false);
37
+ }
30
38
  const conditionals = component.dom.queryByHasAttribute('data-if');
31
39
  for (let i = 0; i < conditionals.length; i++) {
32
40
  const className = conditionals[i].getAttribute('class');
@@ -18,6 +18,7 @@ export declare class HTMLParser {
18
18
  private lineChar;
19
19
  private isLetter;
20
20
  private isNumber;
21
+ private isWordBreak;
21
22
  dom(): DOMFragment;
22
23
  private error;
23
24
  }
@@ -29,7 +29,7 @@ export class HTMLParser {
29
29
  const char = this.char();
30
30
  const charCode = char.charCodeAt(0);
31
31
  if (this.state === 'idle') {
32
- if (char === ' ') {
32
+ if (this.isWordBreak(char)) {
33
33
  return true;
34
34
  }
35
35
  if (char === '<') {
@@ -78,7 +78,7 @@ export class HTMLParser {
78
78
  this.attributeContext = node;
79
79
  return true;
80
80
  }
81
- if (char === ' ') {
81
+ if (this.isWordBreak(char)) {
82
82
  if (this.tokenCurrent.length === 0) {
83
83
  return true;
84
84
  }
@@ -223,6 +223,9 @@ export class HTMLParser {
223
223
  isNumber(charCode) {
224
224
  return charCode > 47 && charCode < 58;
225
225
  }
226
+ isWordBreak(char) {
227
+ return char === ' ' || char === '\n' || char === '\t';
228
+ }
226
229
  dom() {
227
230
  return this.fragment;
228
231
  }
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "main": "build/index",
22
- "version": "1.3.1",
22
+ "version": "1.3.3",
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",
@@ -36,7 +36,7 @@
36
36
  "typescript": "^5.7.2"
37
37
  },
38
38
  "dependencies": {
39
- "handlebars": "^4.7.8",
39
+ "handlebars": "^4.7.9",
40
40
  "mime-types": "^3.0.0"
41
41
  },
42
42
  "files": [