structured-fw 1.0.4 → 1.0.6

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.
@@ -161,7 +161,7 @@ export type InitializerFunctionContext = {
161
161
  export type StoreChangeCallback = (key: string, value: any, oldValue: any, componentId: string) => void;
162
162
  export type ClientComponentEventCallback<T> = T extends undefined ? (e: Event) => void : (e: Event, data: T) => void;
163
163
  export type ClientComponentBoundEvent<T extends LooseObject | undefined = undefined> = {
164
- element: HTMLElement;
164
+ element: HTMLElement | Window;
165
165
  event: keyof HTMLElementEventMap;
166
166
  callback: (e: Event) => void;
167
167
  callbackOriginal: ClientComponentEventCallback<T>;
@@ -56,7 +56,7 @@ export declare class ClientComponent extends EventEmitter {
56
56
  private transitionAttributes;
57
57
  private transitionAxis;
58
58
  private destroy;
59
- bind<T extends LooseObject | undefined = undefined>(element: HTMLElement, event: keyof HTMLElementEventMap | Array<keyof HTMLElementEventMap>, callback: ClientComponentEventCallback<T>): void;
59
+ bind<T extends LooseObject | undefined = undefined>(element: HTMLElement | Window, event: keyof HTMLElementEventMap | Array<keyof HTMLElementEventMap>, callback: ClientComponentEventCallback<T>): void;
60
60
  unbind<T extends LooseObject | undefined = undefined>(element: HTMLElement, event: keyof HTMLElementEventMap | Array<keyof HTMLElementEventMap>, callback: ClientComponentEventCallback<T>): void;
61
61
  private unbindAll;
62
62
  }
@@ -727,9 +727,10 @@ export class ClientComponent extends EventEmitter {
727
727
  });
728
728
  return;
729
729
  }
730
- if (element instanceof HTMLElement) {
730
+ const isWindow = element instanceof Window;
731
+ if (element instanceof HTMLElement || isWindow) {
731
732
  const callbackWrapper = (e) => {
732
- callback.apply(this, [e, this.attributeData(element)]);
733
+ callback.apply(this, [e, isWindow ? {} : this.attributeData(element)]);
733
734
  };
734
735
  this.bound.push({
735
736
  element,
@@ -1,4 +1,4 @@
1
- import { FormValidationEntry, PostedDataDecoded, ValidationResult, ValidationRuleWithArguments, ValidatorErrorDecorator, ValidatorFunction } from '../Types.js';
1
+ import { FormValidationEntry, LooseObject, ValidationResult, ValidationRuleWithArguments, ValidatorErrorDecorator, ValidatorFunction } from '../Types.js';
2
2
  export declare class FormValidation {
3
3
  fieldRules: Array<FormValidationEntry>;
4
4
  singleError: boolean;
@@ -12,6 +12,6 @@ export declare class FormValidation {
12
12
  addRule(fieldName: string, nameHumanReadable: string, rules: Array<string | ValidationRuleWithArguments | ValidatorFunction>): void;
13
13
  registerValidator(name: string, validator: ValidatorFunction, decorator?: ValidatorErrorDecorator): void;
14
14
  registerDecorator(name: string, decorator: ValidatorErrorDecorator): void;
15
- validate(data: PostedDataDecoded): Promise<ValidationResult>;
15
+ validate(data: LooseObject): Promise<ValidationResult>;
16
16
  private addError;
17
17
  }
@@ -9,13 +9,18 @@ export class FormValidation {
9
9
  return false;
10
10
  }
11
11
  const value = data[field];
12
- if (typeof value !== 'string') {
12
+ if (value === null ||
13
+ value === undefined ||
14
+ (typeof value === 'string' && value.trim().length === 0)) {
13
15
  return false;
14
16
  }
15
- return value.trim().length > 0;
17
+ return true;
16
18
  },
17
19
  'number': async (data, field) => {
18
20
  const value = data[field];
21
+ if (typeof value === 'number') {
22
+ return true;
23
+ }
19
24
  if (typeof value !== 'string') {
20
25
  return false;
21
26
  }
@@ -23,6 +28,9 @@ export class FormValidation {
23
28
  },
24
29
  'float': async (data, field) => {
25
30
  const value = data[field];
31
+ if (typeof value === 'number') {
32
+ return true;
33
+ }
26
34
  if (typeof value !== 'string') {
27
35
  return false;
28
36
  }
@@ -33,6 +41,9 @@ export class FormValidation {
33
41
  },
34
42
  'min': async (data, field, arg, rules) => {
35
43
  const value = data[field];
44
+ if (typeof value === 'number') {
45
+ return value >= arg;
46
+ }
36
47
  if (typeof value !== 'string') {
37
48
  return false;
38
49
  }
@@ -43,6 +54,9 @@ export class FormValidation {
43
54
  },
44
55
  'max': async (data, field, arg, rules) => {
45
56
  const value = data[field];
57
+ if (typeof value === 'number') {
58
+ return value <= arg;
59
+ }
46
60
  if (typeof value !== 'string') {
47
61
  return false;
48
62
  }
package/package.json CHANGED
@@ -19,12 +19,13 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "main": "build/index",
22
- "version": "1.0.4",
22
+ "version": "1.0.6",
23
23
  "scripts": {
24
24
  "develop": "tsc --watch",
25
25
  "startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,css index.js",
26
26
  "start": "cd build && node index.js",
27
- "prepublish": "tsc"
27
+ "pack": "tsc && npm pack",
28
+ "publish": "tsc && npm publish"
28
29
  },
29
30
  "bin": {
30
31
  "structured": "./build/system/bin/structured.js"
@@ -55,6 +56,7 @@
55
56
  "./Component": "./build/system/server/Component.js",
56
57
  "./Layout": "./build/system/server/Layout.js",
57
58
  "./FormValidation": "./build/system/server/FormValidation.js",
58
- "./ClientComponent": "./build/system/client/ClientComponent.js"
59
+ "./ClientComponent": "./build/system/client/ClientComponent.js",
60
+ "./Net": "./build/system/client/Net.js"
59
61
  }
60
62
  }