@creative-web-solution/front-library 7.1.41 → 7.1.43

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 7.1.43
4
+
5
+ * [Validator]: Add max file size validation
6
+
7
+ ## 7.1.42
8
+
9
+ * [Popin]: Add popin element in callback function param
10
+
3
11
  ## 7.1.41
4
12
 
5
13
  * [Validator]: Add feature to cancel validation on a field. Do not validate a disabled field.
@@ -342,7 +342,7 @@ export default class Popin {
342
342
  data => {
343
343
  const [ body, response ] = data;
344
344
  const isHttpError = response.status < 200 || response.status >= 300;
345
- const normResponse = this.#options.normalize( body, response, isHttpError );
345
+ const normResponse = this.#options.normalize( body, response, isHttpError, this.#$popin );
346
346
 
347
347
  if ( normResponse.success ) {
348
348
  this.#setPopin( normResponse.data ).then( () => {
@@ -378,7 +378,7 @@ export default class Popin {
378
378
  #_loadLink = ( $link: HTMLAnchorElement ): Promise<void> => {
379
379
  return this.#_load(
380
380
  $link.href,
381
- this.#options.setLinkResponseType( $link.href, $link ),
381
+ this.#options.setLinkResponseType( $link.href, $link, this.#$popin ),
382
382
  );
383
383
  }
384
384
 
@@ -387,7 +387,7 @@ export default class Popin {
387
387
  let validationResult;
388
388
 
389
389
  if ( this.#options.checkValidity ) {
390
- validationResult = this.#options.checkValidity( $form );
390
+ validationResult = this.#options.checkValidity( $form, this.#$popin );
391
391
  if ( validationResult === false ) {
392
392
  return Promise.reject();
393
393
  }
@@ -400,7 +400,7 @@ export default class Popin {
400
400
  .then( () => {
401
401
  return this.#_load(
402
402
  $form.action,
403
- this.#options.setFormResponseType( $form ),
403
+ this.#options.setFormResponseType( $form, this.#$popin ),
404
404
  {
405
405
  "body": new FormData( $form ),
406
406
  "method": $form.method || 'POST'
@@ -0,0 +1,30 @@
1
+ import { addValidator } from './index';
2
+
3
+ /**
4
+ * File size validation
5
+ */
6
+ addValidator( 'maxfilesize', '[data-max-file-size]', ( $input, value, isLiveValidation ) => {
7
+ if (!($input as HTMLInputElement).files?.length) {
8
+ return Promise.resolve({
9
+ $input,
10
+ value,
11
+ "isValid": true,
12
+ "label": "maxfilesize",
13
+ isLiveValidation
14
+ });
15
+ }
16
+
17
+ const size = ($input as HTMLInputElement).files![0].size;
18
+ const maxSize = Number($input.getAttribute('data-max-file-size') ?? "0");
19
+ console.log({size, maxSize})
20
+ return Promise.resolve({
21
+ $input,
22
+ value,
23
+ "isValid": ($input as HTMLInputElement).files?.length === 0 ||
24
+ size <= 0 ||
25
+ maxSize <= 0 ||
26
+ size <= maxSize,
27
+ "label": "maxfilesize",
28
+ isLiveValidation
29
+ });
30
+ } );
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.41
3
+ @version: 7.1.43
4
4
 
5
5
 
6
6
  ## Use
package/Types/Popin.d.ts CHANGED
@@ -83,13 +83,13 @@ declare namespace FLib {
83
83
  onClose?: ( $popin: HTMLElement ) => void;
84
84
  onLoad: ( $popin: HTMLElement ) => Promise<void>;
85
85
  /** @defaultValue `() => 'text'` */
86
- setLinkResponseType: ( url: string, $link: HTMLAnchorElement ) => ResponseType;
86
+ setLinkResponseType: ( url: string, $link: HTMLAnchorElement, $popin: HTMLElement ) => ResponseType;
87
87
  /** @defaultValue `() => 'text'` */
88
- setFormResponseType: ( $form: HTMLElement ) => ResponseType;
88
+ setFormResponseType: ( $form: HTMLElement, $popin: HTMLElement ) => ResponseType;
89
89
  /** @defaultValue `() => true` */
90
- checkValidity: ( $form: HTMLElement ) => boolean | Promise<void>;
90
+ checkValidity: ( $form: HTMLElement, $popin: HTMLElement ) => boolean | Promise<void>;
91
91
  /** @defaultValue `(body) => { return { success: true, data: body }` */
92
- normalize: ( body, response, isHttpError: boolean ) => { success: boolean, data };
92
+ normalize: ( body, response, isHttpError: boolean, $popin: HTMLElement ) => { success: boolean, data };
93
93
  /**
94
94
  * If false, ajax http error (404, 500, ...) should be handled in the normalize function
95
95
  * @defaultValue true
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@creative-web-solution/front-library",
3
3
  "title": "Frontend library",
4
4
  "description": "Frontend functions and modules",
5
- "version": "7.1.41",
5
+ "version": "7.1.43",
6
6
  "homepage": "https://github.com/creative-web-solution/front-library",
7
7
  "author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
8
8
  "keywords": [],