@aemforms/af-core 0.22.19 → 0.22.20

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.
Files changed (122) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
  5. package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +54 -116
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +39 -104
  15. package/lib/{Field.js → esm/Field.js} +142 -208
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/{Form.d.ts → esm/Form.d.ts} +19 -85
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +11 -54
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +10 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
  39. package/lib/{controller → esm/controller}/Logger.js +5 -11
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +15 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +41 -117
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/{types → esm/types}/Json.d.ts +3 -22
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
  59. package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +0 -6
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
  76. package/package.json +17 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/DateField.js +0 -35
  81. package/lib/Fieldset.d.ts +0 -24
  82. package/lib/Fieldset.js +0 -74
  83. package/lib/FileObject.js +0 -39
  84. package/lib/FileUpload.js +0 -155
  85. package/lib/Form.js +0 -252
  86. package/lib/FormInstance.d.ts +0 -38
  87. package/lib/FormInstance.js +0 -127
  88. package/lib/FormMetaData.d.ts +0 -11
  89. package/lib/FormMetaData.js +0 -28
  90. package/lib/InstanceManager.d.ts +0 -16
  91. package/lib/InstanceManager.js +0 -53
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -255
  96. package/lib/controller/Controller.js +0 -328
  97. package/lib/controller/index.d.ts +0 -1
  98. package/lib/controller/index.js +0 -24
  99. package/lib/data/DataValue.js +0 -56
  100. package/lib/data/EmptyDataValue.js +0 -46
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -63
  103. package/lib/rules/RuleEngine.d.ts +0 -23
  104. package/lib/rules/RuleEngine.js +0 -62
  105. package/lib/types/Json.js +0 -19
  106. package/lib/types/Model.d.ts +0 -393
  107. package/lib/types/Model.js +0 -20
  108. package/lib/types/index.d.ts +0 -2
  109. package/lib/types/index.js +0 -25
  110. package/lib/utils/Fetch.js +0 -87
  111. package/lib/utils/FormCreationUtils.d.ts +0 -11
  112. package/lib/utils/FormCreationUtils.js +0 -83
  113. package/lib/utils/FormUtils.d.ts +0 -47
  114. package/lib/utils/FormUtils.js +0 -257
  115. package/lib/utils/JsonUtils.d.ts +0 -63
  116. package/lib/utils/JsonUtils.js +0 -157
  117. package/lib/utils/LogUtils.js +0 -17
  118. package/lib/utils/SchemaUtils.d.ts +0 -16
  119. package/lib/utils/SchemaUtils.js +0 -92
  120. package/lib/utils/TranslationUtils.d.ts +0 -41
  121. package/lib/utils/TranslationUtils.js +0 -185
  122. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -0,0 +1,7 @@
1
+ export const translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value', 'constraintMessages.accept',
2
+ 'constraintMessages.enum', 'constraintMessages.exclusiveMinimum', 'constraintMessages.exclusiveMaximum', 'constraintMessages.format', 'constraintMessages.maxFileSize', 'constraintMessages.maxLength',
3
+ 'constraintMessages.maximum', 'constraintMessages.maxItems', 'constraintMessages.minLength', 'constraintMessages.minimum', 'constraintMessages.minItems', 'constraintMessages.pattern', 'constraintMessages.required',
4
+ 'constraintMessages.step', 'constraintMessages.type', 'constraintMessages.validationExpression'];
5
+ export const constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
6
+ 'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
7
+ 'minLength', 'minimum', 'minItems', 'pattern', 'required', 'step', 'validationExpression', 'enumNames'];
@@ -0,0 +1,131 @@
1
+ import { ConstraintsJson, ContainerJson, FieldJson, FieldsetJson, FormJson, Label, MetaDataJson } from './Json.js';
2
+ import RuleEngine from '../rules/RuleEngine.js';
3
+ import EventQueue from '../controller/EventQueue.js';
4
+ import DataGroup from '../data/DataGroup.js';
5
+ import { Logger } from '../controller/Logger.js';
6
+ export interface ScriptableField {
7
+ rules?: {
8
+ [key: string]: string;
9
+ };
10
+ events?: {
11
+ [key: string]: string;
12
+ };
13
+ ruleEngine: RuleEngine;
14
+ }
15
+ interface WithState<T> {
16
+ getState: () => any;
17
+ }
18
+ declare type stateProps = {
19
+ id: string;
20
+ index: number;
21
+ ':type': string;
22
+ };
23
+ export declare type State<T> = stateProps & (T extends ContainerJson ? T & {
24
+ items: Array<State<FieldJson | ContainerJson>>;
25
+ } : T);
26
+ export declare type Subscription = {
27
+ unsubscribe(): void;
28
+ };
29
+ export interface Action {
30
+ type: string;
31
+ payload: any;
32
+ metadata: any;
33
+ readonly isCustomEvent: boolean;
34
+ readonly target: FormModel | FieldModel | FieldsetModel;
35
+ readonly originalAction?: Action;
36
+ }
37
+ export declare type callbackFn = (action: Action) => void;
38
+ export interface WithController {
39
+ subscribe(callback: callbackFn, eventName?: string): Subscription;
40
+ dispatch(action: Action): void;
41
+ }
42
+ export interface BaseModel extends ConstraintsJson, WithController {
43
+ readonly name?: string;
44
+ readonly dataRef?: string | null;
45
+ readonly id: string;
46
+ readonly index: number;
47
+ readonly qualifiedName: string;
48
+ label?: Label;
49
+ description?: string;
50
+ readOnly?: boolean;
51
+ enabled?: boolean;
52
+ visible?: boolean;
53
+ placeholder?: string;
54
+ valid?: boolean;
55
+ readonly ':type': string;
56
+ readonly 'fieldType': string;
57
+ properties: {
58
+ [key: string]: any;
59
+ };
60
+ readonly isContainer: boolean;
61
+ readonly parent: ContainerModel | null;
62
+ readonly items?: Array<FieldsetModel | FieldModel>;
63
+ value: any;
64
+ readonly default?: any;
65
+ readonly repeatable?: boolean;
66
+ readonly language?: string;
67
+ validate(): Array<ValidationError>;
68
+ reset(): any;
69
+ importData(a?: DataGroup): any;
70
+ getRuleNode(): any;
71
+ ruleNodeReference(): any;
72
+ _initialize(): any;
73
+ _addDependent(dependent: BaseModel): any;
74
+ }
75
+ export interface FieldModel extends BaseModel, ScriptableField, WithState<FieldJson> {
76
+ parent: ContainerModel;
77
+ readonly editFormat?: string;
78
+ readonly displayFormat?: string;
79
+ readonly displayValue?: string;
80
+ readonly editValue?: string;
81
+ }
82
+ export interface FormMetaDataModel {
83
+ readonly version: string;
84
+ readonly grammar: string;
85
+ }
86
+ export interface ContainerModel extends BaseModel, ScriptableField {
87
+ items: Array<FieldsetModel | FieldModel>;
88
+ parent: ContainerModel;
89
+ indexOf(f: FieldModel | FieldsetModel): number;
90
+ isTransparent(): boolean;
91
+ activeChild: BaseModel | null;
92
+ }
93
+ export interface FieldsetModel extends ContainerModel, WithState<FieldsetJson> {
94
+ type?: 'array' | 'object';
95
+ }
96
+ export interface FormModel extends ContainerModel, WithState<FormJson> {
97
+ readonly id: string;
98
+ readonly data?: any;
99
+ readonly metadata?: MetaDataJson;
100
+ readonly title: string;
101
+ readonly logger: Logger;
102
+ importData(data: any): any;
103
+ exportData(): any;
104
+ getElement(id: string): FieldModel | FormModel | FieldsetModel;
105
+ getUniqueId(): string;
106
+ getEventQueue(): EventQueue;
107
+ visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
108
+ fieldAdded(field: FieldModel | FieldsetModel): void;
109
+ }
110
+ export interface IFormFieldFactory {
111
+ createField(child: FieldsetJson | FieldJson, options: {
112
+ form: FormModel;
113
+ parent: ContainerModel;
114
+ }): FieldModel | FieldsetModel;
115
+ }
116
+ export interface IFileObject {
117
+ name: string;
118
+ mediaType: string;
119
+ data?: any;
120
+ size?: number;
121
+ }
122
+ export interface IValidationError {
123
+ fieldName: string;
124
+ errorMessages: Array<string>;
125
+ }
126
+ export declare class ValidationError implements IValidationError {
127
+ fieldName: string;
128
+ errorMessages: Array<string>;
129
+ constructor(fieldName?: string, errorMessages?: Array<any>);
130
+ }
131
+ export {};
@@ -0,0 +1,8 @@
1
+ export class ValidationError {
2
+ fieldName;
3
+ errorMessages;
4
+ constructor(fieldName = '', errorMessages = []) {
5
+ this.errorMessages = errorMessages;
6
+ this.fieldName = fieldName;
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Json.js';
2
+ export * from './Model.js';
@@ -0,0 +1,2 @@
1
+ export * from './Json.js';
2
+ export * from './Model.js';
@@ -1,8 +1,5 @@
1
- /**
2
- * Defines utilities to parse form data
3
- */
4
- import DataGroup from '../data/DataGroup';
5
- import DataValue from '../data/DataValue';
1
+ import DataGroup from '../data/DataGroup.js';
2
+ import DataValue from '../data/DataValue.js';
6
3
  declare type TokenType = string;
7
4
  export declare const TOK_GLOBAL: TokenType;
8
5
  export declare type Token = {
@@ -1,50 +1,31 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- var __importDefault = (this && this.__importDefault) || function (mod) {
10
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.resolveData = exports.tokenize = exports.global$ = exports.bracket = exports.identifier = exports.TOK_GLOBAL = void 0;
14
- /**
15
- * Defines utilities to parse form data
16
- */
17
- const DataGroup_1 = __importDefault(require("../data/DataGroup"));
1
+ import DataGroup from '../data/DataGroup.js';
18
2
  const TOK_DOT = 'DOT';
19
3
  const TOK_IDENTIFIER = 'Identifier';
20
- exports.TOK_GLOBAL = 'Global';
4
+ export const TOK_GLOBAL = 'Global';
21
5
  const TOK_BRACKET = 'bracket';
22
6
  const TOK_NUMBER = 'Number';
23
7
  const globalStartToken = '$';
24
- const identifier = (value, start) => {
8
+ export const identifier = (value, start) => {
25
9
  return {
26
10
  type: TOK_IDENTIFIER,
27
11
  value,
28
12
  start
29
13
  };
30
14
  };
31
- exports.identifier = identifier;
32
- const bracket = (value, start) => {
15
+ export const bracket = (value, start) => {
33
16
  return {
34
17
  type: TOK_BRACKET,
35
18
  value,
36
19
  start
37
20
  };
38
21
  };
39
- exports.bracket = bracket;
40
- const global$ = () => {
22
+ export const global$ = () => {
41
23
  return {
42
- type: exports.TOK_GLOBAL,
24
+ type: TOK_GLOBAL,
43
25
  start: 0,
44
26
  value: globalStartToken
45
27
  };
46
28
  };
47
- exports.global$ = global$;
48
29
  const isAlphaNum = function (ch) {
49
30
  return (ch >= 'a' && ch <= 'z')
50
31
  || (ch >= 'A' && ch <= 'Z')
@@ -52,16 +33,13 @@ const isAlphaNum = function (ch) {
52
33
  || ch === '_';
53
34
  };
54
35
  const isGlobal = (prev, stream, pos) => {
55
- // global tokens occur only at the start of an expression
56
36
  return prev === null && stream[pos] === globalStartToken;
57
37
  };
58
38
  const isIdentifier = (stream, pos) => {
59
39
  const ch = stream[pos];
60
- // $ is special -- it's allowed to be part of an identifier if it's the first character
61
40
  if (ch === '$') {
62
41
  return stream.length > pos && isAlphaNum(stream[pos + 1]);
63
42
  }
64
- // return whether character 'isAlpha'
65
43
  return (ch >= 'a' && ch <= 'z')
66
44
  || (ch >= 'A' && ch <= 'Z')
67
45
  || ch === '_';
@@ -70,15 +48,17 @@ const isNum = (ch) => {
70
48
  return (ch >= '0' && ch <= '9');
71
49
  };
72
50
  class Tokenizer {
51
+ stream;
52
+ _current;
53
+ _tokens = [];
54
+ _result_tokens = [];
73
55
  constructor(stream) {
74
56
  this.stream = stream;
75
- this._tokens = [];
76
- this._result_tokens = [];
77
57
  this._current = 0;
78
58
  }
79
59
  _consumeGlobal() {
80
60
  this._current += 1;
81
- return (0, exports.global$)();
61
+ return global$();
82
62
  }
83
63
  _consumeUnquotedIdentifier(stream) {
84
64
  const start = this._current;
@@ -86,14 +66,13 @@ class Tokenizer {
86
66
  while (this._current < stream.length && isAlphaNum(stream[this._current])) {
87
67
  this._current += 1;
88
68
  }
89
- return (0, exports.identifier)(stream.slice(start, this._current), start);
69
+ return identifier(stream.slice(start, this._current), start);
90
70
  }
91
71
  _consumeQuotedIdentifier(stream) {
92
72
  const start = this._current;
93
73
  this._current += 1;
94
74
  const maxLength = stream.length;
95
75
  while (stream[this._current] !== '"' && this._current < maxLength) {
96
- // You can escape a double quote and you can escape an escape.
97
76
  let current = this._current;
98
77
  if (stream[current] === '\\' && (stream[current + 1] === '\\'
99
78
  || stream[current + 1] === '"')) {
@@ -105,7 +84,7 @@ class Tokenizer {
105
84
  this._current = current;
106
85
  }
107
86
  this._current += 1;
108
- return (0, exports.identifier)(JSON.parse(stream.slice(start, this._current)), start);
87
+ return identifier(JSON.parse(stream.slice(start, this._current)), start);
109
88
  }
110
89
  _consumeNumber(stream) {
111
90
  const start = this._current;
@@ -132,7 +111,7 @@ class Tokenizer {
132
111
  throw new Error(`unexpected exception at position ${this._current}. Must be a character`);
133
112
  }
134
113
  this._current++;
135
- return (0, exports.bracket)(value, start);
114
+ return bracket(value, start);
136
115
  }
137
116
  tokenize() {
138
117
  const stream = this.stream;
@@ -157,8 +136,6 @@ class Tokenizer {
157
136
  this._current += 1;
158
137
  }
159
138
  else if (stream[this._current] === '[') {
160
- // No need to increment this._current. This happens
161
- // in _consumeLBracket
162
139
  const token = this._consumeBracket(stream);
163
140
  this._tokens.push(token);
164
141
  this._result_tokens.push(token);
@@ -177,14 +154,13 @@ class Tokenizer {
177
154
  return this._result_tokens;
178
155
  }
179
156
  }
180
- const tokenize = (stream) => {
157
+ export const tokenize = (stream) => {
181
158
  return new Tokenizer(stream).tokenize();
182
159
  };
183
- exports.tokenize = tokenize;
184
- const resolveData = (data, input, create) => {
160
+ export const resolveData = (data, input, create) => {
185
161
  let tokens;
186
162
  if (typeof input === 'string') {
187
- tokens = (0, exports.tokenize)(input);
163
+ tokens = tokenize(input);
188
164
  }
189
165
  else {
190
166
  tokens = input;
@@ -193,17 +169,16 @@ const resolveData = (data, input, create) => {
193
169
  let i = 0;
194
170
  const createIntermediateNode = (token, nextToken, create) => {
195
171
  return nextToken === null ? create :
196
- (nextToken.type === TOK_BRACKET) ? new DataGroup_1.default(token.value, [], 'array') :
197
- new DataGroup_1.default(token.value, {});
172
+ (nextToken.type === TOK_BRACKET) ? new DataGroup(token.value, [], 'array') :
173
+ new DataGroup(token.value, {});
198
174
  };
199
175
  while (i < tokens.length && result != null) {
200
176
  const token = tokens[i];
201
- if (token.type === exports.TOK_GLOBAL) {
177
+ if (token.type === TOK_GLOBAL) {
202
178
  result = data;
203
179
  }
204
180
  else if (token.type === TOK_IDENTIFIER) {
205
- if (result instanceof DataGroup_1.default && result.$type === 'object') {
206
- //@ts-ignore
181
+ if (result instanceof DataGroup && result.$type === 'object') {
207
182
  if (result.$containsDataNode(token.value) && result.$getDataNode(token.value).$value !== null) {
208
183
  result = result.$getDataNode(token.value);
209
184
  }
@@ -222,10 +197,9 @@ const resolveData = (data, input, create) => {
222
197
  }
223
198
  }
224
199
  else if (token.type === TOK_BRACKET) {
225
- if (result instanceof DataGroup_1.default && result.$type === 'array') {
200
+ if (result instanceof DataGroup && result.$type === 'array') {
226
201
  const index = token.value;
227
202
  if (index < result.$length) {
228
- //@ts-ignore
229
203
  result = result.$getDataNode(index);
230
204
  }
231
205
  else if (create) {
@@ -246,4 +220,3 @@ const resolveData = (data, input, create) => {
246
220
  }
247
221
  return result;
248
222
  };
249
- exports.resolveData = resolveData;
@@ -1,9 +1,3 @@
1
- /**
2
- *
3
- * @param url
4
- * @param data
5
- * @param options
6
- */
7
1
  export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
8
2
  export declare type RequestOptions = {
9
3
  contentType?: string;
@@ -0,0 +1,61 @@
1
+ export const request = (url, data = null, options = {}) => {
2
+ const opts = { ...defaultRequestOptions, ...options };
3
+ const updatedUrl = opts.method === 'GET' && data ? convertQueryString(url, data) : url;
4
+ if (opts.method !== 'GET') {
5
+ opts.body = data;
6
+ }
7
+ return fetch(updatedUrl, {
8
+ ...opts
9
+ }).then(async (response) => {
10
+ let body;
11
+ if (!response.ok) {
12
+ console.error(`Error fetching response from ${url} : ${response.statusText}`);
13
+ body = response.statusText;
14
+ }
15
+ else {
16
+ if (response?.headers?.get('Content-Type')?.includes('application/json')) {
17
+ body = await response.json();
18
+ }
19
+ else {
20
+ body = await response.text();
21
+ }
22
+ }
23
+ const headers = {};
24
+ response?.headers?.forEach((value, key) => {
25
+ headers[key] = value;
26
+ });
27
+ return {
28
+ status: response.status,
29
+ body,
30
+ headers
31
+ };
32
+ });
33
+ };
34
+ const defaultRequestOptions = {
35
+ method: 'GET'
36
+ };
37
+ export const convertQueryString = (endpoint, payload) => {
38
+ if (!payload) {
39
+ return endpoint;
40
+ }
41
+ let updatedPayload = {};
42
+ try {
43
+ updatedPayload = JSON.parse(payload);
44
+ }
45
+ catch (err) {
46
+ console.log('Query params invalid');
47
+ }
48
+ const params = [];
49
+ Object.keys(updatedPayload).forEach((key) => {
50
+ if (Array.isArray(updatedPayload[key])) {
51
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(updatedPayload[key]))}`);
52
+ }
53
+ else {
54
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(updatedPayload[key])}`);
55
+ }
56
+ });
57
+ if (!params.length) {
58
+ return endpoint;
59
+ }
60
+ return endpoint.includes('?') ? `${endpoint}&${params.join('&')}` : `${endpoint}?${params.join('&')}`;
61
+ };
@@ -0,0 +1,9 @@
1
+ import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from '../types/index.js';
2
+ declare class FormFieldFactoryImpl implements IFormFieldFactory {
3
+ createField(child: FieldsetJson | FieldJson, _options: {
4
+ form: FormModel;
5
+ parent: ContainerModel;
6
+ }): FieldModel | FieldsetModel;
7
+ }
8
+ export declare const FormFieldFactory: FormFieldFactoryImpl;
9
+ export {};
@@ -0,0 +1,74 @@
1
+ import { InstanceManager } from '../InstanceManager.js';
2
+ import { Fieldset } from '../Fieldset.js';
3
+ import { isCheckbox, isCheckboxGroup, isDateField, isFile, isRepeatable } from './JsonUtils.js';
4
+ import FileUpload from '../FileUpload.js';
5
+ import Checkbox from '../Checkbox.js';
6
+ import CheckboxGroup from '../CheckboxGroup.js';
7
+ import DateField from '../DateField.js';
8
+ import Field from '../Field.js';
9
+ const alternateFieldTypeMapping = {
10
+ 'text': 'text-input',
11
+ 'number': 'number-input',
12
+ 'email': 'text-input',
13
+ 'file': 'file-input',
14
+ 'range': 'range',
15
+ 'textarea': 'multiline-input'
16
+ };
17
+ class FormFieldFactoryImpl {
18
+ createField(child, _options) {
19
+ let retVal;
20
+ const options = {
21
+ ..._options,
22
+ fieldFactory: this
23
+ };
24
+ child.fieldType = child.fieldType ? (child.fieldType in alternateFieldTypeMapping ?
25
+ alternateFieldTypeMapping[child.fieldType] : child.fieldType)
26
+ : 'text-input';
27
+ if (isRepeatable(child)) {
28
+ const newChild = {
29
+ ...child,
30
+ ...('items' in child && { 'type': 'object' }),
31
+ minOccur: undefined,
32
+ maxOccur: undefined,
33
+ repeatable: undefined,
34
+ name: undefined
35
+ };
36
+ const newJson = {
37
+ ...{
38
+ minItems: child.minOccur || 0,
39
+ maxItems: child.maxOccur || -1,
40
+ fieldType: child.fieldType,
41
+ type: 'array',
42
+ name: child.name,
43
+ dataRef: child.dataRef
44
+ },
45
+ ...{
46
+ 'items': [newChild]
47
+ }
48
+ };
49
+ retVal = new InstanceManager(newJson, options);
50
+ }
51
+ else if ('items' in child) {
52
+ retVal = new Fieldset(child, options);
53
+ }
54
+ else {
55
+ if (isFile(child) || child.fieldType === 'file-input') {
56
+ retVal = new FileUpload(child, options);
57
+ }
58
+ else if (isCheckbox(child)) {
59
+ retVal = new Checkbox(child, options);
60
+ }
61
+ else if (isCheckboxGroup(child)) {
62
+ retVal = new CheckboxGroup(child, options);
63
+ }
64
+ else if (isDateField(child)) {
65
+ retVal = new DateField(child, options);
66
+ }
67
+ else {
68
+ retVal = new Field(child, options);
69
+ }
70
+ }
71
+ return retVal;
72
+ }
73
+ }
74
+ export const FormFieldFactory = new FormFieldFactoryImpl();
@@ -0,0 +1,12 @@
1
+ import { ContainerModel } from '../types/index.js';
2
+ export declare const randomWord: (l: number) => string;
3
+ export declare const isEmpty: (value: any) => boolean;
4
+ export declare const getAttachments: (input: ContainerModel) => any;
5
+ export declare const getFileSizeInBytes: (str: any) => number;
6
+ export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
7
+ export declare const isDataUrl: (str: string) => boolean;
8
+ export declare const extractFileInfo: (file: any) => any;
9
+ export declare const dataURItoBlob: (dataURI: string) => {
10
+ name: string;
11
+ blob: Blob;
12
+ } | null;