@servicetitan/form 22.2.0 → 22.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/date-range-picker/date-range-picker.d.ts +1 -1
  3. package/dist/date-range-picker/date-range-picker.d.ts.map +1 -1
  4. package/dist/date-range-picker/date-range-picker.js.map +1 -1
  5. package/dist/demo/date-range-picker.js.map +1 -1
  6. package/dist/demo/index.d.ts +0 -1
  7. package/dist/demo/index.d.ts.map +1 -1
  8. package/dist/demo/index.js +0 -1
  9. package/dist/demo/index.js.map +1 -1
  10. package/dist/demo/input-date-mask.d.ts.map +1 -1
  11. package/dist/demo/input-date-mask.js.map +1 -1
  12. package/dist/form-state-error-banner/form-state-error-banner.js +1 -1
  13. package/dist/form-state-error-banner/form-state-error-banner.js.map +1 -1
  14. package/dist/index.d.ts +1 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -4
  17. package/dist/index.js.map +1 -1
  18. package/package.json +15 -16
  19. package/src/date-range-picker/date-range-picker.tsx +1 -1
  20. package/src/demo/date-range-picker.tsx +1 -1
  21. package/src/demo/index.ts +0 -1
  22. package/src/demo/input-date-mask.tsx +0 -1
  23. package/src/form-state-error-banner/form-state-error-banner.tsx +1 -1
  24. package/src/index.ts +2 -4
  25. package/dist/date-range.d.ts +0 -5
  26. package/dist/date-range.d.ts.map +0 -1
  27. package/dist/date-range.js +0 -2
  28. package/dist/date-range.js.map +0 -1
  29. package/dist/demo/dropdown-state.d.ts +0 -3
  30. package/dist/demo/dropdown-state.d.ts.map +0 -1
  31. package/dist/demo/dropdown-state.js +0 -133
  32. package/dist/demo/dropdown-state.js.map +0 -1
  33. package/dist/dropdown-state.d.ts +0 -42
  34. package/dist/dropdown-state.d.ts.map +0 -1
  35. package/dist/dropdown-state.js +0 -314
  36. package/dist/dropdown-state.js.map +0 -1
  37. package/dist/form-helpers.d.ts +0 -70
  38. package/dist/form-helpers.d.ts.map +0 -1
  39. package/dist/form-helpers.js +0 -232
  40. package/dist/form-helpers.js.map +0 -1
  41. package/dist/form-validators.d.ts +0 -30
  42. package/dist/form-validators.d.ts.map +0 -1
  43. package/dist/form-validators.js +0 -56
  44. package/dist/form-validators.js.map +0 -1
  45. package/dist/persistent-form-state/domain-storage.d.ts +0 -14
  46. package/dist/persistent-form-state/domain-storage.d.ts.map +0 -1
  47. package/dist/persistent-form-state/domain-storage.js +0 -42
  48. package/dist/persistent-form-state/domain-storage.js.map +0 -1
  49. package/dist/persistent-form-state/in-memory-storage.d.ts +0 -13
  50. package/dist/persistent-form-state/in-memory-storage.d.ts.map +0 -1
  51. package/dist/persistent-form-state/in-memory-storage.js +0 -30
  52. package/dist/persistent-form-state/in-memory-storage.js.map +0 -1
  53. package/dist/persistent-form-state/index.d.ts +0 -2
  54. package/dist/persistent-form-state/index.d.ts.map +0 -1
  55. package/dist/persistent-form-state/index.js +0 -2
  56. package/dist/persistent-form-state/index.js.map +0 -1
  57. package/dist/persistent-form-state/persistent-form-state.d.ts +0 -18
  58. package/dist/persistent-form-state/persistent-form-state.d.ts.map +0 -1
  59. package/dist/persistent-form-state/persistent-form-state.js +0 -93
  60. package/dist/persistent-form-state/persistent-form-state.js.map +0 -1
  61. package/src/__tests__/__snapshots__/form-helpers.test.ts.snap +0 -37
  62. package/src/__tests__/form-helpers.test.ts +0 -229
  63. package/src/__tests__/form-validators.test.ts +0 -55
  64. package/src/date-range.ts +0 -4
  65. package/src/demo/dropdown-state.tsx +0 -233
  66. package/src/dropdown-state.ts +0 -205
  67. package/src/form-helpers.ts +0 -259
  68. package/src/form-validators.ts +0 -106
  69. package/src/persistent-form-state/__tests__/domain-storage.test.ts +0 -81
  70. package/src/persistent-form-state/domain-storage.ts +0 -43
  71. package/src/persistent-form-state/in-memory-storage.ts +0 -32
  72. package/src/persistent-form-state/index.ts +0 -1
  73. package/src/persistent-form-state/persistent-form-state.ts +0 -68
@@ -1,30 +0,0 @@
1
- import { DatetimeFieldState, FormValues } from './form-helpers';
2
- import { DateRange } from './date-range';
3
- interface DateRangeFieldStates {
4
- startDate: DatetimeFieldState;
5
- endDate: DatetimeFieldState;
6
- }
7
- export declare const FormValidators: {
8
- required: (value?: FormValues | undefined) => string | false;
9
- requiredWithCustomMessage: (errorMessage: string) => (value?: FormValues | undefined) => string | false;
10
- hasLowerCase: (str: string) => boolean;
11
- hasUpperCase: (str: string) => boolean;
12
- hasNumber: (str: string) => boolean;
13
- passwordIsValidFormat: (password: string) => boolean;
14
- emailFormatIsValid: (email: string) => boolean;
15
- website: (errorMessage?: string) => (value: string) => string | false;
16
- minDate: Date;
17
- maxDate: Date;
18
- isDateValid: (date: Date | null) => false | "Please provide a valid date";
19
- isDateRangeValid: (dateRange: DateRangeFieldStates) => false | "Start Date should not be after End Date" | null;
20
- dateRangeRequired: (errorMessage?: string) => (dateRange: DateRange | undefined) => string | false;
21
- dateRangeValid: (errorMessage?: string) => (dateRange: DateRange | undefined) => string | false;
22
- isDateRangeLessThanMaxLength: (maxDays: number) => (val: DateRange | undefined) => string | false | undefined;
23
- isAlphaNumeric: (str: string) => boolean;
24
- isMatchingRegex: (regexp: RegExp, entity: string) => (str: string) => string | false;
25
- minLength: (minLength: number) => (value: string | any[] | undefined) => string | false;
26
- maxLength: (maxLength: number) => (value: string | any[] | undefined) => string | false;
27
- exactLength: (exactLength: number) => (value: string | any[] | undefined) => string | false;
28
- };
29
- export {};
30
- //# sourceMappingURL=form-validators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"form-validators.d.ts","sourceRoot":"","sources":["../src/form-validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,UAAU,oBAAoB;IAC1B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,OAAO,EAAE,kBAAkB,CAAC;CAC/B;AAcD,eAAO,MAAM,cAAc;;8CAImB,MAAM;wBAG5B,MAAM;wBAEN,MAAM;qBAET,MAAM;sCAEW,MAAM;gCAMZ,MAAM;gDAQf,MAAM;;;wBAUL,IAAI,GAAG,IAAI;kCAID,oBAAoB;8DAQlC,SAAS,GAAG,SAAS;2DAKrB,SAAS,GAAG,SAAS;4CAOG,MAAM,WAAW,SAAS,GAAG,SAAS;0BAUxD,MAAM;8BAEF,MAAM,UAAU,MAAM,WAAW,MAAM;2BAG1C,MAAM,aAAa,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS;2BAG7C,MAAM,aAAa,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS;+BAGzC,MAAM,aAAa,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS;CAE3E,CAAC"}
@@ -1,56 +0,0 @@
1
- import { isObservableArray } from 'mobx';
2
- const isDefined = (value) => {
3
- if (value === undefined) {
4
- return false;
5
- }
6
- if (Array.isArray(value) || isObservableArray(value)) {
7
- return !!value.length;
8
- }
9
- return typeof value === 'string' ? !!value.trim() : !!value;
10
- };
11
- export const FormValidators = {
12
- required: (value) => FormValidators.requiredWithCustomMessage('Value is required')(value),
13
- requiredWithCustomMessage: (errorMessage) => (value) => !isDefined(value) && errorMessage,
14
- hasLowerCase: (str) => /[a-z]/.test(str),
15
- hasUpperCase: (str) => /[A-Z]/.test(str),
16
- hasNumber: (str) => /\d/.test(str),
17
- passwordIsValidFormat: (password) => password.length > 7 &&
18
- FormValidators.hasLowerCase(password) &&
19
- FormValidators.hasUpperCase(password) &&
20
- FormValidators.hasNumber(password),
21
- emailFormatIsValid: (email) => {
22
- /* tslint:disable: ter-max-len */
23
- const regex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
24
- return email.length !== 0 && regex.test(email);
25
- },
26
- website: (errorMessage = 'Enter valid website') => {
27
- return (value) => !/^(https?:\/\/)?(www\.)?([a-zA-Z0-9]+(-?[a-zA-Z0-9])*\.)+[\w]{2,}(\/\S*)?$/i.test(value) && errorMessage;
28
- },
29
- minDate: new Date(1900, 0, 1),
30
- maxDate: new Date(2099, 11, 31),
31
- isDateValid: (date) => (!date || date > FormValidators.maxDate || date < FormValidators.minDate) &&
32
- 'Please provide a valid date',
33
- isDateRangeValid: (dateRange) => dateRange.startDate.$ &&
34
- dateRange.endDate.$ &&
35
- dateRange.startDate.$ > dateRange.endDate.$ &&
36
- 'Start Date should not be after End Date',
37
- dateRangeRequired: (errorMessage = 'Date Range is required') => (dateRange) => (!dateRange || !dateRange.from || !dateRange.to) && errorMessage,
38
- dateRangeValid: (errorMessage = 'Start cannot be after End') => (dateRange) => !!dateRange &&
39
- !!dateRange.from &&
40
- !!dateRange.to &&
41
- dateRange.from > dateRange.to &&
42
- errorMessage,
43
- isDateRangeLessThanMaxLength: (maxDays) => (val) => {
44
- const dayInMillseconds = 1000 * 60 * 60 * 24;
45
- return ((val === null || val === void 0 ? void 0 : val.from) &&
46
- val.to &&
47
- (val.to.getTime() - val.from.getTime()) / dayInMillseconds >= maxDays &&
48
- `Only ${maxDays} days can be displayed at time`);
49
- },
50
- isAlphaNumeric: (str) => /^(\w+,?)*$/.test(str),
51
- isMatchingRegex: (regexp, entity) => (str) => !regexp.test(str) && `Invalid format for ${entity}`,
52
- minLength: (minLength) => (value) => value && value.length < minLength ? `Value's min length is ${minLength}` : false,
53
- maxLength: (maxLength) => (value) => value && value.length > maxLength ? `Value's max length is ${maxLength}` : false,
54
- exactLength: (exactLength) => (value) => value && value.length !== exactLength ? `Value's length must be ${exactLength}` : false,
55
- };
56
- //# sourceMappingURL=form-validators.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"form-validators.js","sourceRoot":"","sources":["../src/form-validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAQzC,MAAM,SAAS,GAAG,CAA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@
1
- import { FormStateShape } from '../form-helpers';
2
- import { ValidatableMapOrArray } from 'formstate';
3
- export declare class DomainStorage<T extends ValidatableMapOrArray> {
4
- private readonly version;
5
- private readonly cacheKey;
6
- constructor({ cacheKey, version }: {
7
- cacheKey: string;
8
- version: number;
9
- });
10
- getItem(): FormStateShape<T> | null;
11
- removeItem(): void;
12
- setItem(_: string, value: FormStateShape<T>): void;
13
- }
14
- //# sourceMappingURL=domain-storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"domain-storage.d.ts","sourceRoot":"","sources":["../../src/persistent-form-state/domain-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAOlD,qBAAa,aAAa,CAAC,CAAC,SAAS,qBAAqB;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAKxE,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;IAiBnC,UAAU,IAAI,IAAI;IAIlB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;CAIrD"}
@@ -1,42 +0,0 @@
1
- export class DomainStorage {
2
- constructor({ cacheKey, version }) {
3
- Object.defineProperty(this, "version", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: void 0
8
- });
9
- Object.defineProperty(this, "cacheKey", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: void 0
14
- });
15
- this.version = version;
16
- this.cacheKey = cacheKey;
17
- }
18
- getItem() {
19
- try {
20
- const cachedData = localStorage.getItem(this.cacheKey);
21
- if (cachedData) {
22
- const formData = JSON.parse(cachedData);
23
- if (formData.version === this.version) {
24
- return formData.value;
25
- }
26
- this.removeItem();
27
- }
28
- }
29
- catch (e) {
30
- this.removeItem();
31
- }
32
- return null;
33
- }
34
- removeItem() {
35
- localStorage.removeItem(this.cacheKey);
36
- }
37
- setItem(_, value) {
38
- const formData = { value, version: this.version };
39
- localStorage.setItem(this.cacheKey, JSON.stringify(formData));
40
- }
41
- }
42
- //# sourceMappingURL=domain-storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"domain-storage.js","sourceRoot":"","sources":["../../src/persistent-form-state/domain-storage.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,aAAa;IAItB,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAyC;QAHxE;;;;;WAAiC;QACjC;;;;;WAAkC;QAG9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,OAAO;QACH,IAAI;YACA,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvD,IAAI,UAAU,EAAE;gBACZ,MAAM,QAAQ,GAAsB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC3D,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE;oBACnC,OAAO,QAAQ,CAAC,KAAK,CAAC;iBACzB;gBACD,IAAI,CAAC,UAAU,EAAE,CAAC;aACrB;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,UAAU,EAAE,CAAC;SACrB;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,UAAU;QACN,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,CAAC,CAAS,EAAE,KAAwB;QACvC,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAClD,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,CAAC;CACJ"}
@@ -1,13 +0,0 @@
1
- import { FormStateShape } from '../form-helpers';
2
- import { ValidatableMapOrArray } from 'formstate';
3
- export declare class InMemoryStorage<T extends ValidatableMapOrArray> {
4
- private storage;
5
- get length(): number;
6
- clear(): void;
7
- getItem(key: string): FormStateShape<T> | null;
8
- key(index: number): string | null;
9
- removeItem(key: string): void;
10
- setItem(key: string, value: FormStateShape<T>): void;
11
- }
12
- export declare const MemoryStorage: InMemoryStorage<any>;
13
- //# sourceMappingURL=in-memory-storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"in-memory-storage.d.ts","sourceRoot":"","sources":["../../src/persistent-form-state/in-memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,qBAAa,eAAe,CAAC,CAAC,SAAS,qBAAqB;IACxD,OAAO,CAAC,OAAO,CAAwC;IAEvD,IAAI,MAAM,WAET;IAED,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;IAI9C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIjC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI7B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;CAGvD;AAED,eAAO,MAAM,aAAa,sBAA6B,CAAC"}
@@ -1,30 +0,0 @@
1
- export class InMemoryStorage {
2
- constructor() {
3
- Object.defineProperty(this, "storage", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: new Map()
8
- });
9
- }
10
- get length() {
11
- return this.storage.size;
12
- }
13
- clear() {
14
- this.storage.clear();
15
- }
16
- getItem(key) {
17
- return this.storage.get(key) !== undefined ? this.storage.get(key) : null;
18
- }
19
- key(index) {
20
- return this.length < index ? null : Array.from(this.storage.keys())[index];
21
- }
22
- removeItem(key) {
23
- this.storage.delete(key);
24
- }
25
- setItem(key, value) {
26
- this.storage.set(key, value);
27
- }
28
- }
29
- export const MemoryStorage = new InMemoryStorage();
30
- //# sourceMappingURL=in-memory-storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"in-memory-storage.js","sourceRoot":"","sources":["../../src/persistent-form-state/in-memory-storage.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,eAAe;IAA5B;QACI;;;;mBAAkB,IAAI,GAAG,EAA6B;WAAC;IAyB3D,CAAC;IAvBG,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/E,CAAC;IAED,GAAG,CAAC,KAAa;QACb,OAAO,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;IAED,UAAU,CAAC,GAAW;QAClB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,KAAwB;QACzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,eAAe,EAAO,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './persistent-form-state';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/persistent-form-state/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './persistent-form-state';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persistent-form-state/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -1,18 +0,0 @@
1
- import { FormState, ValidatableMapOrArray } from 'formstate';
2
- export declare enum PersistenceMode {
3
- Session = 0,
4
- Domain = 1,
5
- InMemory = 2
6
- }
7
- export declare class PersistentFormState<T extends ValidatableMapOrArray> extends FormState<T> {
8
- private cacheKey;
9
- private persistenceMode;
10
- private storageSystem;
11
- private resetFormSuper;
12
- constructor($: T, cacheKey: string, persistenceMode: PersistenceMode, autoSave?: boolean, version?: number);
13
- save: () => void;
14
- resetForm: () => void;
15
- private trackChange;
16
- private getCached;
17
- }
18
- //# sourceMappingURL=persistent-form-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistent-form-state.d.ts","sourceRoot":"","sources":["../../src/persistent-form-state/persistent-form-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAU7D,oBAAY,eAAe;IACvB,OAAO,IAAA;IACP,MAAM,IAAA;IACN,QAAQ,IAAA;CACX;AAED,qBAAa,mBAAmB,CAAC,CAAC,SAAS,qBAAqB,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAM9E,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,eAAe;IAN3B,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAAc;gBAGhC,CAAC,EAAE,CAAC,EACI,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,eAAe,EACxC,QAAQ,CAAC,EAAE,OAAO,EAClB,OAAO,CAAC,EAAE,MAAM;IAqBpB,IAAI,aAEF;IAEF,SAAS,aAGP;IAEF,OAAO,CAAC,WAAW,CAEjB;IAEF,OAAO,CAAC,SAAS,CAMf;CACL"}
@@ -1,93 +0,0 @@
1
- import { autorun } from 'mobx';
2
- import { FormState } from 'formstate';
3
- import { MemoryStorage } from './in-memory-storage';
4
- import { setFormStateValues, formStateToJS, } from '../form-helpers';
5
- import { DomainStorage } from './domain-storage';
6
- export var PersistenceMode;
7
- (function (PersistenceMode) {
8
- PersistenceMode[PersistenceMode["Session"] = 0] = "Session";
9
- PersistenceMode[PersistenceMode["Domain"] = 1] = "Domain";
10
- PersistenceMode[PersistenceMode["InMemory"] = 2] = "InMemory";
11
- })(PersistenceMode || (PersistenceMode = {}));
12
- export class PersistentFormState extends FormState {
13
- constructor($, cacheKey, persistenceMode, autoSave, version) {
14
- super($);
15
- Object.defineProperty(this, "cacheKey", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: cacheKey
20
- });
21
- Object.defineProperty(this, "persistenceMode", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: persistenceMode
26
- });
27
- Object.defineProperty(this, "storageSystem", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: void 0
32
- });
33
- Object.defineProperty(this, "resetFormSuper", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: this.reset
38
- });
39
- Object.defineProperty(this, "save", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: () => {
44
- this.storageSystem.setItem(this.cacheKey, formStateToJS(this));
45
- }
46
- });
47
- Object.defineProperty(this, "resetForm", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: () => {
52
- this.resetFormSuper();
53
- this.storageSystem.removeItem(this.cacheKey);
54
- }
55
- });
56
- Object.defineProperty(this, "trackChange", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: () => {
61
- autorun(() => this.save(), { delay: 500 });
62
- }
63
- });
64
- Object.defineProperty(this, "getCached", {
65
- enumerable: true,
66
- configurable: true,
67
- writable: true,
68
- value: () => {
69
- const data = this.storageSystem.getItem(this.cacheKey);
70
- if (data) {
71
- setFormStateValues(this, data);
72
- }
73
- }
74
- });
75
- if (PersistenceMode.Domain === this.persistenceMode) {
76
- if (!version) {
77
- throw 'Set a data structure version.';
78
- }
79
- this.storageSystem = new DomainStorage({ cacheKey, version });
80
- }
81
- else if (PersistenceMode.Session === this.persistenceMode) {
82
- throw 'Use of Session storage is currently unsafe';
83
- }
84
- else {
85
- this.storageSystem = MemoryStorage;
86
- }
87
- this.getCached();
88
- if (autoSave) {
89
- this.trackChange();
90
- }
91
- }
92
- }
93
- //# sourceMappingURL=persistent-form-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistent-form-state.js","sourceRoot":"","sources":["../../src/persistent-form-state/persistent-form-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAyB,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAmB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAGH,kBAAkB,EAClB,aAAa,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACvB,2DAAO,CAAA;IACP,yDAAM,CAAA;IACN,6DAAQ,CAAA;AACZ,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED,MAAM,OAAO,mBAAqD,SA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aAAa,GAAG,aAAa,CAAC;SACtC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,QAAQ,EAAE;YACV,IAAI,CAAC,WAAW,EAAE,CAAC;SACtB;IACL,CAAC;CAsBJ"}
@@ -1,37 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`formStateToJS 1`] = `
4
- Object {
5
- "field": 0,
6
- "subForm": Object {
7
- "subField": 1,
8
- "subSubForm": Object {
9
- "subSubField": 1,
10
- "subSubField2": 2,
11
- },
12
- "subSubFormArray": Array [
13
- Object {
14
- "veryNestedField": 1,
15
- },
16
- ],
17
- "subSubFormMap": Object {
18
- "subSubMapField": "x",
19
- "subSubMapField2": "y",
20
- },
21
- },
22
- "subFormArray": Array [
23
- Object {
24
- "a": 1,
25
- },
26
- ],
27
- "subFormArray2": Array [
28
- 1,
29
- 2,
30
- ],
31
- "subFormMap": Object {
32
- "subMapField": "one",
33
- "subMapField2": "two",
34
- "subMapField3": "three",
35
- },
36
- }
37
- `;
@@ -1,229 +0,0 @@
1
- import { FormState, FieldState } from 'formstate';
2
- import {
3
- commitFormState,
4
- formStateToJS,
5
- BAD_formStateToJS,
6
- InputFieldState,
7
- traverseFormState,
8
- setFormStateValues,
9
- } from '../form-helpers';
10
-
11
- const getFormState = () =>
12
- new FormState({
13
- field: new InputFieldState(0),
14
- subForm: new FormState({
15
- subField: new InputFieldState(1),
16
- subSubForm: new FormState({
17
- subSubField: new InputFieldState(1),
18
- subSubField2: new InputFieldState(2),
19
- }),
20
- subSubFormArray: new FormState([
21
- new FormState({
22
- veryNestedField: new FieldState(1),
23
- }),
24
- ]),
25
- subSubFormMap: new FormState(
26
- new Map([
27
- ['subSubMapField', new FieldState('x')],
28
- ['subSubMapField2', new FieldState('y')],
29
- ])
30
- ),
31
- }),
32
- subFormArray: new FormState([
33
- new FormState({
34
- a: new InputFieldState(1),
35
- }),
36
- ]),
37
- subFormArray2: new FormState([new InputFieldState(1), new InputFieldState(2)]),
38
- subFormMap: new FormState(
39
- new Map([
40
- ['subMapField', new FieldState('one')],
41
- ['subMapField2', new FieldState('two')],
42
- ['subMapField3', new FieldState('three')],
43
- ])
44
- ),
45
- });
46
-
47
- test('traverseFormState recursive', () => {
48
- const form = getFormState();
49
- const traverseResult: string[] = [];
50
- traverseFormState(
51
- true,
52
- form,
53
- key => {
54
- traverseResult.push(key);
55
- },
56
- key => {
57
- traverseResult.push(key);
58
- }
59
- );
60
-
61
- expect(traverseResult).toContain('field');
62
- expect(traverseResult).toContain('subForm');
63
- expect(traverseResult).toContain('subField');
64
- expect(traverseResult).toContain('veryNestedField');
65
- expect(traverseResult).toContain('subSubMapField');
66
- });
67
-
68
- test('traverseFormState non recursive', () => {
69
- const form = getFormState();
70
- const traverseResult: string[] = [];
71
- traverseFormState(
72
- false,
73
- form,
74
- key => {
75
- traverseResult.push(key);
76
- },
77
- key => {
78
- traverseResult.push(key);
79
- }
80
- );
81
-
82
- expect(traverseResult).toContain('field');
83
- expect(traverseResult).toContain('subForm');
84
- expect(traverseResult).not.toContain('subField');
85
- });
86
-
87
- test('formStateToJS', () => {
88
- const form = getFormState();
89
- const formStateAsJS = formStateToJS(form);
90
-
91
- expect(formStateAsJS).toMatchSnapshot();
92
- });
93
-
94
- test('formStateToJS complex types', () => {
95
- const data = {
96
- a: {
97
- '1': 1,
98
- 'string': 'string',
99
- 'true': true,
100
- },
101
- b: [3, 5, 7],
102
- c: {
103
- x: 1,
104
- y: 'string',
105
- z: true,
106
- },
107
- d: {
108
- '1': true,
109
- '2': {
110
- x: 2,
111
- },
112
- },
113
- };
114
-
115
- const mapForm = new Map<string, FieldState<boolean> | FormState<{ x: FieldState<number> }>>([
116
- ['1', new FieldState<boolean>(true)],
117
- [
118
- '2',
119
- new FormState({
120
- x: new FieldState(2),
121
- }),
122
- ],
123
- ]);
124
-
125
- const form = new FormState({
126
- a: new FieldState(data.a),
127
- b: new FieldState(data.b),
128
- c: new FieldState(data.c),
129
- d: new FormState(mapForm),
130
- });
131
-
132
- expect(formStateToJS(form)).toEqual(data);
133
- expect(BAD_formStateToJS(form)).toEqual(data);
134
- });
135
-
136
- test('setFormStateValues', () => {
137
- const form = setFormStateValues(getFormState(), {
138
- field: 2,
139
- subForm: {
140
- subSubForm: {
141
- subSubField: undefined,
142
- },
143
- subSubFormMap: { subSubMapField2: 'z' },
144
- },
145
- subFormArray2: [3, 4],
146
- subFormMap: { subMapField: 'infinity' },
147
- });
148
-
149
- expect(form.$.field.value).toBe(2);
150
- expect(form.$.subForm.$.subSubForm.$.subSubField.value).toBe(undefined);
151
- expect(form.$.subForm.$.subSubForm.$.subSubField2.value).toBe(2);
152
- expect(form.$.subForm.$.subSubFormMap.$.get('subSubMapField2')!.value).toBe('z');
153
- expect(form.$.subFormArray2.$.map(item => item.value)).toEqual([3, 4]);
154
- expect(form.$.subFormMap.$.get('subMapField')!.value).toBe('infinity');
155
- });
156
-
157
- test('setFormStateValues array length mismatch', () => {
158
- const form = new FormState([
159
- new FormState({
160
- a: new FieldState(1),
161
- b: new FormState([
162
- new FormState({
163
- c: new FieldState(1),
164
- d: new FieldState(1),
165
- }),
166
- ]),
167
- }),
168
- ]);
169
-
170
- expect(() => setFormStateValues(form, [{ a: 1 }, { a: 2 }])).toThrowError(/Number of elements/);
171
- expect(() => setFormStateValues(form, [{ a: 1, b: [{ c: 1 }, { c: 1 }] }])).toThrowError(
172
- /Number of elements/
173
- );
174
- });
175
-
176
- test('setFormStateValues top level array', () => {
177
- const formState = new FormState([
178
- new FormState({ a: new FieldState(1), b: new FieldState(2) }),
179
- new FormState({ a: new FieldState(1), b: new FieldState(2) }),
180
- ]);
181
- setFormStateValues(formState, [
182
- { a: 4, b: 5 },
183
- { a: 5, b: 6 },
184
- ]);
185
-
186
- expect(formState.$[0].$.a.value).toBe(4);
187
- expect(formState.$[0].$.b.value).toBe(5);
188
- expect(formState.$[1].$.a.value).toBe(5);
189
- expect(formState.$[1].$.b.value).toBe(6);
190
- });
191
-
192
- test('setFormStateValues top level map', () => {
193
- const formState = new FormState(
194
- new Map([
195
- ['a', new FormState({ a: new FieldState(1), b: new FieldState(2) })],
196
- ['b', new FormState({ a: new FieldState(1), b: new FieldState(2) })],
197
- ])
198
- );
199
- setFormStateValues(formState, {
200
- a: { a: 4, b: 5 },
201
- b: { a: 5, b: 6 },
202
- });
203
-
204
- expect(formState.$.get('a')!.$.a.value).toBe(4);
205
- expect(formState.$.get('a')!.$.b.value).toBe(5);
206
- expect(formState.$.get('b')!.$.a.value).toBe(5);
207
- expect(formState.$.get('b')!.$.b.value).toBe(6);
208
- });
209
-
210
- test('commitFormState', () => {
211
- const form = getFormState();
212
- const oldFieldValue = form.$.field.value;
213
- const newFieldValue = oldFieldValue + 1;
214
- const oldSubFieldValue = form.$.subForm.$.subField.value;
215
- const newSubFieldValue = oldSubFieldValue + 1;
216
-
217
- form.$.field.value = newFieldValue;
218
- form.$.subForm.$.subField.value = newSubFieldValue;
219
- form.reset();
220
- expect(form.$.field.value).toBe(oldFieldValue);
221
- expect(form.$.subForm.$.subField.value).toBe(oldSubFieldValue);
222
-
223
- form.$.field.value = newFieldValue;
224
- form.$.subForm.$.subField.value = newSubFieldValue;
225
- commitFormState(form);
226
- form.reset();
227
- expect(form.$.field.value).toBe(newFieldValue);
228
- expect(form.$.subForm.$.subField.value).toBe(newSubFieldValue);
229
- });