@aemforms/af-core 0.22.25 → 0.22.26

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 (76) 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/esm/BaseNode.d.ts +93 -0
  5. package/lib/esm/BaseNode.js +454 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/esm/CheckboxGroup.d.ts +18 -0
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/esm/Container.js +290 -0
  12. package/lib/esm/DateField.d.ts +5 -0
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/esm/Field.d.ts +206 -0
  15. package/lib/esm/Field.js +656 -0
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/esm/FileObject.d.ts +16 -0
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/esm/FileUpload.d.ts +22 -0
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  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/esm/Scriptable.js +163 -0
  34. package/lib/esm/controller/EventQueue.d.ts +17 -0
  35. package/lib/esm/controller/EventQueue.js +86 -0
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/esm/controller/Logger.d.ts +11 -0
  39. package/lib/esm/controller/Logger.js +30 -0
  40. package/lib/esm/data/DataGroup.d.ts +20 -0
  41. package/lib/esm/data/DataGroup.js +77 -0
  42. package/lib/esm/data/DataValue.d.ts +16 -0
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/esm/data/EmptyDataValue.d.ts +14 -0
  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/esm/rules/FunctionRuntime.d.ts +51 -0
  49. package/lib/esm/rules/FunctionRuntime.js +320 -0
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  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/esm/utils/DataRefParser.d.ts +27 -0
  59. package/lib/esm/utils/DataRefParser.js +222 -0
  60. package/lib/esm/utils/Fetch.d.ts +8 -0
  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/esm/utils/LogUtils.d.ts +4 -0
  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/esm/utils/ValidationUtils.js +274 -0
  76. package/package.json +1 -1
@@ -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';
@@ -0,0 +1,27 @@
1
+ import DataGroup from '../data/DataGroup.js';
2
+ import DataValue from '../data/DataValue.js';
3
+ declare type TokenType = string;
4
+ export declare const TOK_GLOBAL: TokenType;
5
+ export declare type Token = {
6
+ type: TokenType;
7
+ value: string | number;
8
+ start: number;
9
+ };
10
+ export declare const identifier: (value: string, start: number) => {
11
+ type: string;
12
+ value: string;
13
+ start: number;
14
+ };
15
+ export declare const bracket: (value: number, start: number) => {
16
+ type: string;
17
+ value: number;
18
+ start: number;
19
+ };
20
+ export declare const global$: () => {
21
+ type: string;
22
+ start: number;
23
+ value: string;
24
+ };
25
+ export declare const tokenize: (stream: string) => Token[];
26
+ export declare const resolveData: <T extends DataValue>(data: DataGroup, input: Token[] | string, create?: T | undefined) => DataGroup | DataValue | undefined;
27
+ export {};
@@ -0,0 +1,222 @@
1
+ import DataGroup from '../data/DataGroup.js';
2
+ const TOK_DOT = 'DOT';
3
+ const TOK_IDENTIFIER = 'Identifier';
4
+ export const TOK_GLOBAL = 'Global';
5
+ const TOK_BRACKET = 'bracket';
6
+ const TOK_NUMBER = 'Number';
7
+ const globalStartToken = '$';
8
+ export const identifier = (value, start) => {
9
+ return {
10
+ type: TOK_IDENTIFIER,
11
+ value,
12
+ start
13
+ };
14
+ };
15
+ export const bracket = (value, start) => {
16
+ return {
17
+ type: TOK_BRACKET,
18
+ value,
19
+ start
20
+ };
21
+ };
22
+ export const global$ = () => {
23
+ return {
24
+ type: TOK_GLOBAL,
25
+ start: 0,
26
+ value: globalStartToken
27
+ };
28
+ };
29
+ const isAlphaNum = function (ch) {
30
+ return (ch >= 'a' && ch <= 'z')
31
+ || (ch >= 'A' && ch <= 'Z')
32
+ || (ch >= '0' && ch <= '9')
33
+ || ch === '_';
34
+ };
35
+ const isGlobal = (prev, stream, pos) => {
36
+ return prev === null && stream[pos] === globalStartToken;
37
+ };
38
+ const isIdentifier = (stream, pos) => {
39
+ const ch = stream[pos];
40
+ if (ch === '$') {
41
+ return stream.length > pos && isAlphaNum(stream[pos + 1]);
42
+ }
43
+ return (ch >= 'a' && ch <= 'z')
44
+ || (ch >= 'A' && ch <= 'Z')
45
+ || ch === '_';
46
+ };
47
+ const isNum = (ch) => {
48
+ return (ch >= '0' && ch <= '9');
49
+ };
50
+ class Tokenizer {
51
+ stream;
52
+ _current;
53
+ _tokens = [];
54
+ _result_tokens = [];
55
+ constructor(stream) {
56
+ this.stream = stream;
57
+ this._current = 0;
58
+ }
59
+ _consumeGlobal() {
60
+ this._current += 1;
61
+ return global$();
62
+ }
63
+ _consumeUnquotedIdentifier(stream) {
64
+ const start = this._current;
65
+ this._current += 1;
66
+ while (this._current < stream.length && isAlphaNum(stream[this._current])) {
67
+ this._current += 1;
68
+ }
69
+ return identifier(stream.slice(start, this._current), start);
70
+ }
71
+ _consumeQuotedIdentifier(stream) {
72
+ const start = this._current;
73
+ this._current += 1;
74
+ const maxLength = stream.length;
75
+ while (stream[this._current] !== '"' && this._current < maxLength) {
76
+ let current = this._current;
77
+ if (stream[current] === '\\' && (stream[current + 1] === '\\'
78
+ || stream[current + 1] === '"')) {
79
+ current += 2;
80
+ }
81
+ else {
82
+ current += 1;
83
+ }
84
+ this._current = current;
85
+ }
86
+ this._current += 1;
87
+ return identifier(JSON.parse(stream.slice(start, this._current)), start);
88
+ }
89
+ _consumeNumber(stream) {
90
+ const start = this._current;
91
+ this._current += 1;
92
+ const maxLength = stream.length;
93
+ while (isNum(stream[this._current]) && this._current < maxLength) {
94
+ this._current += 1;
95
+ }
96
+ const n = stream.slice(start, this._current);
97
+ const value = parseInt(n, 10);
98
+ return { type: TOK_NUMBER, value, start };
99
+ }
100
+ _consumeBracket(stream) {
101
+ const start = this._current;
102
+ this._current += 1;
103
+ let value;
104
+ if (isNum(stream[this._current])) {
105
+ value = this._consumeNumber(stream).value;
106
+ }
107
+ else {
108
+ throw new Error(`unexpected exception at position ${this._current}. Must be a character`);
109
+ }
110
+ if (this._current < this.stream.length && stream[this._current] !== ']') {
111
+ throw new Error(`unexpected exception at position ${this._current}. Must be a character`);
112
+ }
113
+ this._current++;
114
+ return bracket(value, start);
115
+ }
116
+ tokenize() {
117
+ const stream = this.stream;
118
+ while (this._current < stream.length) {
119
+ const prev = this._tokens.length ? this._tokens.slice(-1)[0] : null;
120
+ if (isGlobal(prev, stream, this._current)) {
121
+ const token = this._consumeGlobal();
122
+ this._tokens.push(token);
123
+ this._result_tokens.push(token);
124
+ }
125
+ else if (isIdentifier(stream, this._current)) {
126
+ const token = this._consumeUnquotedIdentifier(stream);
127
+ this._tokens.push(token);
128
+ this._result_tokens.push(token);
129
+ }
130
+ else if (stream[this._current] === '.' && prev != null && prev.type !== TOK_DOT) {
131
+ this._tokens.push({
132
+ type: TOK_DOT,
133
+ value: '.',
134
+ start: this._current
135
+ });
136
+ this._current += 1;
137
+ }
138
+ else if (stream[this._current] === '[') {
139
+ const token = this._consumeBracket(stream);
140
+ this._tokens.push(token);
141
+ this._result_tokens.push(token);
142
+ }
143
+ else if (stream[this._current] === '"') {
144
+ const token = this._consumeQuotedIdentifier(stream);
145
+ this._tokens.push(token);
146
+ this._result_tokens.push(token);
147
+ }
148
+ else {
149
+ const p = Math.max(0, this._current - 2);
150
+ const s = Math.min(this.stream.length, this._current + 2);
151
+ throw new Error(`Exception at parsing stream ${this.stream.slice(p, s)}`);
152
+ }
153
+ }
154
+ return this._result_tokens;
155
+ }
156
+ }
157
+ export const tokenize = (stream) => {
158
+ return new Tokenizer(stream).tokenize();
159
+ };
160
+ export const resolveData = (data, input, create) => {
161
+ let tokens;
162
+ if (typeof input === 'string') {
163
+ tokens = tokenize(input);
164
+ }
165
+ else {
166
+ tokens = input;
167
+ }
168
+ let result = data;
169
+ let i = 0;
170
+ const createIntermediateNode = (token, nextToken, create) => {
171
+ return nextToken === null ? create :
172
+ (nextToken.type === TOK_BRACKET) ? new DataGroup(token.value, [], 'array') :
173
+ new DataGroup(token.value, {});
174
+ };
175
+ while (i < tokens.length && result != null) {
176
+ const token = tokens[i];
177
+ if (token.type === TOK_GLOBAL) {
178
+ result = data;
179
+ }
180
+ else if (token.type === TOK_IDENTIFIER) {
181
+ if (result instanceof DataGroup && result.$type === 'object') {
182
+ if (result.$containsDataNode(token.value) && result.$getDataNode(token.value).$value !== null) {
183
+ result = result.$getDataNode(token.value);
184
+ }
185
+ else if (create) {
186
+ const nextToken = i < tokens.length - 1 ? tokens[i + 1] : null;
187
+ const toCreate = createIntermediateNode(token, nextToken, create);
188
+ result.$addDataNode(token.value, toCreate);
189
+ result = toCreate;
190
+ }
191
+ else {
192
+ result = undefined;
193
+ }
194
+ }
195
+ else {
196
+ throw new Error(`Looking for ${token.value} in ${result.$value}`);
197
+ }
198
+ }
199
+ else if (token.type === TOK_BRACKET) {
200
+ if (result instanceof DataGroup && result.$type === 'array') {
201
+ const index = token.value;
202
+ if (index < result.$length) {
203
+ result = result.$getDataNode(index);
204
+ }
205
+ else if (create) {
206
+ const nextToken = i < tokens.length - 1 ? tokens[i + 1] : null;
207
+ const toCreate = createIntermediateNode(token, nextToken, create);
208
+ result.$addDataNode(index, toCreate);
209
+ result = toCreate;
210
+ }
211
+ else {
212
+ result = undefined;
213
+ }
214
+ }
215
+ else {
216
+ throw new Error(`Looking for index ${token.value} in non array${result.$value}`);
217
+ }
218
+ }
219
+ i += 1;
220
+ }
221
+ return result;
222
+ };
@@ -0,0 +1,8 @@
1
+ export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
2
+ export declare type RequestOptions = {
3
+ contentType?: string;
4
+ method?: 'POST' | 'GET';
5
+ headers?: any;
6
+ mode?: string;
7
+ };
8
+ export declare const convertQueryString: (endpoint: string, payload: string | null) => 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;