@aemforms/af-core 0.22.30 → 0.22.32

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 (100) hide show
  1. package/lib/{esm/BaseNode.d.ts → BaseNode.d.ts} +8 -8
  2. package/lib/{esm/BaseNode-d78cc1b0.js → BaseNode.js} +72 -97
  3. package/lib/{esm/Checkbox.d.ts → Checkbox.d.ts} +1 -1
  4. package/lib/Checkbox.js +29 -0
  5. package/lib/{esm/CheckboxGroup.d.ts → CheckboxGroup.d.ts} +2 -2
  6. package/lib/CheckboxGroup.js +24 -0
  7. package/lib/{esm/Container.d.ts → Container.d.ts} +4 -4
  8. package/lib/{esm/Container.js → Container.js} +51 -77
  9. package/lib/{esm/DateField.d.ts → DateField.d.ts} +1 -1
  10. package/lib/DateField.js +26 -0
  11. package/lib/{esm/Field.d.ts → Field.d.ts} +10 -9
  12. package/lib/{esm/Field.js → Field.js} +97 -105
  13. package/lib/Fieldset.d.ts +72 -0
  14. package/lib/Fieldset.js +89 -0
  15. package/lib/{esm/FileObject.d.ts → FileObject.d.ts} +1 -1
  16. package/lib/FileObject.js +29 -0
  17. package/lib/{esm/FileUpload.d.ts → FileUpload.d.ts} +3 -3
  18. package/lib/FileUpload.js +124 -0
  19. package/lib/{esm/Form.d.ts → Form.d.ts} +13 -13
  20. package/lib/{esm/Form.js → Form.js} +34 -68
  21. package/lib/{esm/FormInstance.d.ts → FormInstance.d.ts} +3 -3
  22. package/lib/FormInstance.js +94 -0
  23. package/lib/{esm/FormMetaData.d.ts → FormMetaData.d.ts} +2 -2
  24. package/lib/FormMetaData.js +15 -0
  25. package/lib/{esm/InstanceManager.d.ts → InstanceManager.d.ts} +2 -2
  26. package/lib/InstanceManager.js +35 -0
  27. package/lib/{esm/Node.d.ts → Node.d.ts} +0 -0
  28. package/lib/Node.js +15 -0
  29. package/lib/{esm/Scriptable.d.ts → Scriptable.d.ts} +3 -3
  30. package/lib/{esm/Scriptable.js → Scriptable.js} +17 -38
  31. package/lib/{esm/controller → controller}/EventQueue.d.ts +3 -3
  32. package/lib/{esm/controller → controller}/EventQueue.js +8 -32
  33. package/lib/{esm/controller → controller}/Events.d.ts +2 -2
  34. package/lib/{esm/controller → controller}/Events.js +22 -26
  35. package/lib/{esm/controller → controller}/Logger.d.ts +2 -2
  36. package/lib/controller/Logger.js +33 -0
  37. package/lib/{esm/data → data}/DataGroup.d.ts +1 -1
  38. package/lib/{esm/data → data}/DataGroup.js +20 -38
  39. package/lib/{esm/data → data}/DataValue.d.ts +1 -1
  40. package/lib/{esm/data → data}/DataValue.js +4 -26
  41. package/lib/{esm/data → data}/EmptyDataValue.d.ts +1 -1
  42. package/lib/data/EmptyDataValue.js +34 -0
  43. package/lib/index.d.ts +21 -0
  44. package/lib/index.js +57 -0
  45. package/lib/{esm/rules → rules}/FunctionRuntime.d.ts +3 -3
  46. package/lib/{esm/rules → rules}/FunctionRuntime.js +52 -63
  47. package/lib/{esm/rules → rules}/RuleEngine.d.ts +1 -1
  48. package/lib/rules/RuleEngine.js +51 -0
  49. package/lib/{esm/types → types}/Json.d.ts +18 -16
  50. package/lib/types/Json.js +10 -0
  51. package/lib/{esm/types → types}/Model.d.ts +10 -10
  52. package/lib/types/Model.js +10 -0
  53. package/lib/types/index.d.ts +2 -0
  54. package/lib/types/index.js +18 -0
  55. package/lib/{esm/utils → utils}/DataRefParser.d.ts +10 -4
  56. package/lib/{esm/utils → utils}/DataRefParser.js +48 -42
  57. package/lib/{esm/utils → utils}/Fetch.d.ts +1 -1
  58. package/lib/utils/Fetch.js +74 -0
  59. package/lib/{esm/utils → utils}/FormCreationUtils.d.ts +1 -1
  60. package/lib/utils/FormCreationUtils.js +67 -0
  61. package/lib/{esm/utils → utils}/FormUtils.d.ts +2 -1
  62. package/lib/{esm/utils → utils}/FormUtils.js +62 -46
  63. package/lib/{esm/utils → utils}/JsonUtils.d.ts +1 -1
  64. package/lib/utils/JsonUtils.js +89 -0
  65. package/lib/{esm/utils → utils}/LogUtils.d.ts +1 -1
  66. package/lib/utils/LogUtils.js +10 -0
  67. package/lib/{esm/utils → utils}/SchemaUtils.d.ts +1 -1
  68. package/lib/{esm/utils → utils}/SchemaUtils.js +9 -29
  69. package/lib/{esm/utils → utils}/TranslationUtils.d.ts +2 -2
  70. package/lib/utils/TranslationUtils.js +125 -0
  71. package/lib/{esm/utils → utils}/ValidationUtils.d.ts +4 -4
  72. package/lib/{esm/utils → utils}/ValidationUtils.js +13 -35
  73. package/package.json +8 -13
  74. package/lib/cjs/index.cjs +0 -7345
  75. package/lib/esm/BaseNode.js +0 -26
  76. package/lib/esm/Checkbox.js +0 -63
  77. package/lib/esm/CheckboxGroup.js +0 -60
  78. package/lib/esm/DateField.js +0 -57
  79. package/lib/esm/Fieldset.d.ts +0 -16
  80. package/lib/esm/Fieldset.js +0 -78
  81. package/lib/esm/FileObject.js +0 -48
  82. package/lib/esm/FileUpload.js +0 -141
  83. package/lib/esm/FormInstance.js +0 -129
  84. package/lib/esm/FormMetaData.js +0 -35
  85. package/lib/esm/InstanceManager.js +0 -58
  86. package/lib/esm/Node.js +0 -40
  87. package/lib/esm/controller/Logger.js +0 -52
  88. package/lib/esm/data/EmptyDataValue.js +0 -51
  89. package/lib/esm/index.d.ts +0 -21
  90. package/lib/esm/index.js +0 -55
  91. package/lib/esm/rules/RuleEngine.js +0 -76
  92. package/lib/esm/types/Json.js +0 -29
  93. package/lib/esm/types/Model.js +0 -30
  94. package/lib/esm/types/index.d.ts +0 -2
  95. package/lib/esm/types/index.js +0 -22
  96. package/lib/esm/utils/Fetch.js +0 -83
  97. package/lib/esm/utils/FormCreationUtils.js +0 -112
  98. package/lib/esm/utils/JsonUtils.js +0 -99
  99. package/lib/esm/utils/LogUtils.js +0 -28
  100. package/lib/esm/utils/TranslationUtils.js +0 -138
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const Events_1 = require("./controller/Events");
16
+ const Field_1 = __importDefault(require("./Field"));
17
+ const FormUtils_1 = require("./utils/FormUtils");
18
+ const FileObject_1 = require("./FileObject");
19
+ const ValidationUtils_1 = require("./utils/ValidationUtils");
20
+ function addNameToDataURL(dataURL, name) {
21
+ return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
22
+ }
23
+ function processFiles(files) {
24
+ return Promise.all([].map.call(files, processFile));
25
+ }
26
+ function processFile(file) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const { name, size, type } = file;
29
+ const fileObj = yield new Promise((resolve, reject) => {
30
+ const reader = new FileReader();
31
+ reader.onload = event => {
32
+ resolve(new FileObject_1.FileObject({
33
+ data: addNameToDataURL(event.target.result, name),
34
+ type,
35
+ name,
36
+ size
37
+ }));
38
+ };
39
+ reader.readAsDataURL(file.data);
40
+ });
41
+ return fileObj;
42
+ });
43
+ }
44
+ class FileUpload extends Field_1.default {
45
+ _getDefaults() {
46
+ return Object.assign(Object.assign({}, super._getDefaults()), { accept: ['audio/*', 'video/*', 'image/*', 'text/*', 'application/pdf'], maxFileSize: '2MB' });
47
+ }
48
+ _getFallbackType() {
49
+ return 'file';
50
+ }
51
+ get maxFileSize() {
52
+ return (0, FormUtils_1.getFileSizeInBytes)(this._jsonModel.maxFileSize);
53
+ }
54
+ get accept() {
55
+ return this._jsonModel.accept;
56
+ }
57
+ _applyUpdates(propNames, updates) {
58
+ return propNames.reduce((acc, propertyName) => {
59
+ const prevValue = this._jsonModel[propertyName];
60
+ const currentValue = updates[propertyName];
61
+ if (currentValue !== prevValue) {
62
+ acc[propertyName] = {
63
+ propertyName,
64
+ currentValue,
65
+ prevValue
66
+ };
67
+ if (prevValue instanceof FileObject_1.FileObject && typeof currentValue === 'object' && propertyName === 'value') {
68
+ this._jsonModel[propertyName] = new FileObject_1.FileObject(Object.assign(Object.assign({}, prevValue), { 'data': currentValue.data }));
69
+ }
70
+ else {
71
+ this._jsonModel[propertyName] = currentValue;
72
+ }
73
+ }
74
+ return acc;
75
+ }, {});
76
+ }
77
+ getInternalType() {
78
+ var _a;
79
+ return ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) ? 'file[]' : 'file';
80
+ }
81
+ getDataNodeValue(typedValue) {
82
+ var _a;
83
+ let dataNodeValue = typedValue;
84
+ if (dataNodeValue != null) {
85
+ if (this.type === 'string') {
86
+ dataNodeValue = (_a = dataNodeValue.data) === null || _a === void 0 ? void 0 : _a.toString();
87
+ }
88
+ else if (this.type === 'string[]') {
89
+ dataNodeValue = dataNodeValue instanceof Array ? dataNodeValue : [dataNodeValue];
90
+ dataNodeValue = dataNodeValue.map((_) => { var _a; return (_a = _ === null || _ === void 0 ? void 0 : _.data) === null || _a === void 0 ? void 0 : _a.toString(); });
91
+ }
92
+ }
93
+ return dataNodeValue;
94
+ }
95
+ _serialize() {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const val = this._jsonModel.value;
98
+ if (val === undefined) {
99
+ return null;
100
+ }
101
+ const filesInfo = yield processFiles(val instanceof Array ? val : [val]);
102
+ return filesInfo;
103
+ });
104
+ }
105
+ importData(dataModel) {
106
+ this._bindToDataModel(dataModel);
107
+ const dataNode = this.getDataNode();
108
+ if (dataNode !== undefined) {
109
+ const value = dataNode === null || dataNode === void 0 ? void 0 : dataNode.$value;
110
+ if (value != null) {
111
+ const res = ValidationUtils_1.Constraints.type(this.getInternalType(), value);
112
+ if (!res.valid) {
113
+ this.form.logger.debug(`unable to bind ${this.name} to data`);
114
+ }
115
+ this.form.getEventQueue().queue(this, (0, Events_1.propertyChange)('value', res.value, this._jsonModel.value));
116
+ this._jsonModel.value = res.value;
117
+ }
118
+ else {
119
+ this._jsonModel.value = null;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ exports.default = FileUpload;
@@ -1,9 +1,9 @@
1
- import Container from './Container.js';
2
- import { Action, BaseModel, FieldModel, FieldsetModel, FormJson, FormModel, IFormFieldFactory } from './types/index.js';
3
- import FormMetaData from './FormMetaData.js';
4
- import EventQueue from './controller/EventQueue.js';
5
- import { Logger, LogLevel } from './controller/Logger.js';
6
- import RuleEngine from './rules/RuleEngine.js';
1
+ import Container from './Container';
2
+ import { Action, BaseModel, FieldModel, FieldsetModel, FormJson, FormModel, IFormFieldFactory } from './types/index';
3
+ import FormMetaData from './FormMetaData';
4
+ import EventQueue from './controller/EventQueue';
5
+ import { Logger, LogLevel } from './controller/Logger';
6
+ import RuleEngine from './rules/RuleEngine';
7
7
  declare class Form extends Container<FormJson> implements FormModel {
8
8
  private _ruleEngine;
9
9
  private _eventQueue;
@@ -16,13 +16,12 @@ declare class Form extends Container<FormJson> implements FormModel {
16
16
  private dataRefRegex;
17
17
  get metaData(): FormMetaData;
18
18
  get action(): string | undefined;
19
- get lang(): string;
20
19
  importData(dataModel: any): void;
21
20
  exportData(): any;
22
21
  setFocus(field: BaseModel): void;
23
22
  getState(): {
24
23
  description?: string | undefined;
25
- } & import("./types/Json.js").RulesJson & {
24
+ } & import("./types/Json").RulesJson & {
26
25
  enumNames?: string[] | undefined;
27
26
  enum?: any[] | undefined;
28
27
  } & {
@@ -48,12 +47,13 @@ declare class Form extends Container<FormJson> implements FormModel {
48
47
  uniqueItems?: boolean | undefined;
49
48
  } & {
50
49
  dataRef?: string | null | undefined;
50
+ lang?: string | undefined;
51
51
  ':type'?: string | undefined;
52
- label?: import("./types/Json.js").Label | undefined;
52
+ label?: import("./types/Json").Label | undefined;
53
53
  enabled?: boolean | undefined;
54
54
  visible?: boolean | undefined;
55
55
  name?: string | undefined;
56
- constraintMessages?: import("./types/Json.js").ConstraintsMessages | undefined;
56
+ constraintMessages?: import("./types/Json").ConstraintsMessages | undefined;
57
57
  fieldType?: string | undefined;
58
58
  errorMessage?: string | undefined;
59
59
  properties?: {
@@ -65,11 +65,11 @@ declare class Form extends Container<FormJson> implements FormModel {
65
65
  altText?: string | undefined;
66
66
  viewType?: string | undefined;
67
67
  } & {
68
- items: (import("./types/Json.js").FieldJson | import("./types/Json.js").ContainerJson)[];
68
+ items: (import("./types/Json").FieldJson | import("./types/Json").ContainerJson)[];
69
69
  initialItems?: number | undefined;
70
70
  activeChild?: string | undefined;
71
71
  } & {
72
- metadata?: import("./types/Json.js").MetaDataJson | undefined;
72
+ metadata?: import("./types/Json").MetaDataJson | undefined;
73
73
  data?: any;
74
74
  title?: string | undefined;
75
75
  action?: string | undefined;
@@ -97,7 +97,7 @@ declare class Form extends Container<FormJson> implements FormModel {
97
97
  fieldAdded(field: FieldModel | FieldsetModel): void;
98
98
  visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
99
99
  traverseChild(container: Container<any>, callBack: (field: FieldModel | FieldsetModel) => void): void;
100
- validate(): import("./types/Model.js").ValidationError[];
100
+ validate(): import("./types/Model").ValidationError[];
101
101
  isValid(): boolean;
102
102
  dispatch(action: Action): void;
103
103
  submit(action: Action, context: any): void;
@@ -1,83 +1,50 @@
1
- /*************************************************************************
2
- * ADOBE CONFIDENTIAL
3
- * ___________________
4
- *
5
- * Copyright 2022 Adobe
6
- * All Rights Reserved.
7
- *
8
- * NOTICE: All information contained herein is, and remains
9
- * the property of Adobe and its suppliers, if any. The intellectual
10
- * and technical concepts contained herein are proprietary to Adobe
11
- * and its suppliers and are protected by all applicable intellectual
12
- * property laws, including trade secret and copyright laws.
13
- * Dissemination of this information or reproduction of this material
14
- * is strictly forbidden unless prior written permission is obtained
15
- * from Adobe.
16
-
17
- * Adobe permits you to use and modify this file solely in accordance with
18
- * the terms of the Adobe license agreement accompanying it.
19
- *************************************************************************/
20
-
21
- import Container from './Container.js';
22
- import FormMetaData from './FormMetaData.js';
23
- import EventQueue from './controller/EventQueue.js';
24
- import { Logger } from './controller/Logger.js';
25
- import { IdGenerator, getAttachments } from './utils/FormUtils.js';
26
- import DataGroup from './data/DataGroup.js';
27
- import { submit } from './rules/FunctionRuntime.js';
28
- import { Initialize, ExecuteRule, FormLoad, FieldChanged, ValidationComplete } from './controller/Events.js';
29
- import './BaseNode-d78cc1b0.js';
30
- import './utils/DataRefParser.js';
31
- import './data/DataValue.js';
32
- import './data/EmptyDataValue.js';
33
- import './utils/JsonUtils.js';
34
- import './types/Json.js';
35
- import './utils/SchemaUtils.js';
36
- import './Scriptable.js';
37
- import './Node.js';
38
- import './FileObject.js';
39
- import './utils/Fetch.js';
40
-
41
- class Form extends Container {
42
- _ruleEngine;
43
- _eventQueue;
44
- _fields = {};
45
- _ids;
46
- _invalidFields = [];
47
- _logger;
48
- constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue(), logLevel = 'off') {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Container_1 = __importDefault(require("./Container"));
7
+ const FormMetaData_1 = __importDefault(require("./FormMetaData"));
8
+ const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
9
+ const Logger_1 = require("./controller/Logger");
10
+ const FormUtils_1 = require("./utils/FormUtils");
11
+ const DataGroup_1 = __importDefault(require("./data/DataGroup"));
12
+ const FunctionRuntime_1 = require("./rules/FunctionRuntime");
13
+ const Events_1 = require("./controller/Events");
14
+ class Form extends Container_1.default {
15
+ constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off') {
49
16
  super(n, { fieldFactory: fieldFactory });
50
17
  this._ruleEngine = _ruleEngine;
51
18
  this._eventQueue = _eventQueue;
52
- this._logger = new Logger(logLevel);
53
- this.queueEvent(new Initialize());
54
- this.queueEvent(new ExecuteRule());
55
- this._ids = IdGenerator();
56
- this._bindToDataModel(new DataGroup('$form', {}));
19
+ this._fields = {};
20
+ this._invalidFields = [];
21
+ this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
22
+ this._logger = new Logger_1.Logger(logLevel);
23
+ this.queueEvent(new Events_1.Initialize());
24
+ this.queueEvent(new Events_1.ExecuteRule());
25
+ this._ids = (0, FormUtils_1.IdGenerator)();
26
+ this._bindToDataModel(new DataGroup_1.default('$form', {}));
57
27
  this._initialize();
58
- this.queueEvent(new FormLoad());
28
+ this.queueEvent(new Events_1.FormLoad());
59
29
  }
60
30
  get logger() {
61
31
  return this._logger;
62
32
  }
63
- dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
64
33
  get metaData() {
65
34
  const metaData = this._jsonModel.metadata || {};
66
- return new FormMetaData(metaData);
35
+ return new FormMetaData_1.default(metaData);
67
36
  }
68
37
  get action() {
69
38
  return this._jsonModel.action;
70
39
  }
71
- get lang() {
72
- return this._jsonModel.lang || 'en';
73
- }
74
40
  importData(dataModel) {
75
- this._bindToDataModel(new DataGroup('$form', dataModel));
41
+ this._bindToDataModel(new DataGroup_1.default('$form', dataModel));
76
42
  this.syncDataAndFormModel(this.getDataNode());
77
43
  this._eventQueue.runPendingQueue();
78
44
  }
79
45
  exportData() {
80
- return this.getDataNode()?.$value;
46
+ var _a;
47
+ return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
81
48
  }
82
49
  setFocus(field) {
83
50
  const parent = field.parent;
@@ -97,7 +64,7 @@ class Form extends Container {
97
64
  });
98
65
  Object.defineProperty(res, 'attachments', {
99
66
  get: function () {
100
- return getAttachments(self);
67
+ return (0, FormUtils_1.getAttachments)(self);
101
68
  }
102
69
  });
103
70
  return res;
@@ -136,7 +103,7 @@ class Form extends Container {
136
103
  field.subscribe((action) => {
137
104
  const field = action.target.getState();
138
105
  if (field) {
139
- const fieldChangedAction = new FieldChanged(action.payload.changes, field);
106
+ const fieldChangedAction = new Events_1.FieldChanged(action.payload.changes, field);
140
107
  this.dispatch(fieldChangedAction);
141
108
  }
142
109
  });
@@ -154,7 +121,7 @@ class Form extends Container {
154
121
  }
155
122
  validate() {
156
123
  const validationErrors = super.validate();
157
- this.dispatch(new ValidationComplete(validationErrors));
124
+ this.dispatch(new Events_1.ValidationComplete(validationErrors));
158
125
  return validationErrors;
159
126
  }
160
127
  isValid() {
@@ -171,8 +138,8 @@ class Form extends Container {
171
138
  }
172
139
  submit(action, context) {
173
140
  if (this.validate().length === 0) {
174
- const payload = action?.payload || {};
175
- submit(context, payload?.success, payload?.error, payload?.submit_as, payload?.data);
141
+ const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
142
+ (0, FunctionRuntime_1.submit)(context, payload === null || payload === void 0 ? void 0 : payload.success, payload === null || payload === void 0 ? void 0 : payload.error, payload === null || payload === void 0 ? void 0 : payload.submit_as, payload === null || payload === void 0 ? void 0 : payload.data);
176
143
  }
177
144
  }
178
145
  reset() {
@@ -204,5 +171,4 @@ class Form extends Container {
204
171
  return this._jsonModel.title || '';
205
172
  }
206
173
  }
207
-
208
- export { Form as default };
174
+ exports.default = Form;
@@ -1,6 +1,6 @@
1
- import { FormModel } from './types/index.js';
2
- import { LogLevel } from './controller/Logger.js';
3
- import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime.js';
1
+ import { FormModel } from './types/index';
2
+ import { LogLevel } from './controller/Logger';
3
+ import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
4
4
  export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
5
5
  export declare const validateFormInstance: (formModel: any, data: any) => boolean;
6
6
  export declare const validateFormData: (formModel: any, data: any) => {
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.createFormInstance = void 0;
7
+ const Form_1 = __importDefault(require("./Form"));
8
+ const JsonUtils_1 = require("./utils/JsonUtils");
9
+ const Fetch_1 = require("./utils/Fetch");
10
+ const RuleEngine_1 = __importDefault(require("./rules/RuleEngine"));
11
+ const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
12
+ const Logger_1 = require("./controller/Logger");
13
+ const FormCreationUtils_1 = require("./utils/FormCreationUtils");
14
+ const FunctionRuntime_1 = require("./rules/FunctionRuntime");
15
+ const FormUtils_1 = require("./utils/FormUtils");
16
+ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
17
+ try {
18
+ let f = fModel;
19
+ if (f == null) {
20
+ formModel = (0, FormUtils_1.sitesModelToFormModel)(formModel);
21
+ f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel);
22
+ }
23
+ const formData = formModel === null || formModel === void 0 ? void 0 : formModel.data;
24
+ if (formData) {
25
+ f.importData(formData);
26
+ }
27
+ if (typeof callback === 'function') {
28
+ callback(f);
29
+ }
30
+ f.getEventQueue().runPendingQueue();
31
+ return f;
32
+ }
33
+ catch (e) {
34
+ console.error(`Unable to create an instance of the Form ${e}`);
35
+ throw new Error(e);
36
+ }
37
+ };
38
+ exports.createFormInstance = createFormInstance;
39
+ const validateFormInstance = (formModel, data) => {
40
+ try {
41
+ const f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default());
42
+ if (data) {
43
+ f.importData(data);
44
+ }
45
+ return f.validate().length === 0;
46
+ }
47
+ catch (e) {
48
+ throw new Error(e);
49
+ }
50
+ };
51
+ exports.validateFormInstance = validateFormInstance;
52
+ const validateFormData = (formModel, data) => {
53
+ try {
54
+ const f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default());
55
+ if (data) {
56
+ f.importData(data);
57
+ }
58
+ const res = f.validate();
59
+ return {
60
+ messages: res,
61
+ valid: res.length === 0
62
+ };
63
+ }
64
+ catch (e) {
65
+ throw new Error(e);
66
+ }
67
+ };
68
+ exports.validateFormData = validateFormData;
69
+ const fetchForm = (url, headers = {}) => {
70
+ const headerObj = new Headers();
71
+ Object.entries(headers).forEach(([key, value]) => {
72
+ headerObj.append(key, value);
73
+ });
74
+ return new Promise((resolve, reject) => {
75
+ (0, Fetch_1.request)(`${url}.model.json`, null, { headers }).then((response) => {
76
+ if (response.status !== 200) {
77
+ reject('Not Found');
78
+ }
79
+ else {
80
+ let formObj = response.body;
81
+ if ('model' in formObj) {
82
+ const { model } = formObj;
83
+ formObj = model;
84
+ }
85
+ resolve((0, JsonUtils_1.jsonString)(formObj));
86
+ }
87
+ });
88
+ });
89
+ };
90
+ exports.fetchForm = fetchForm;
91
+ const registerFunctions = (functions) => {
92
+ FunctionRuntime_1.FunctionRuntime.registerFunctions(functions);
93
+ };
94
+ exports.registerFunctions = registerFunctions;
@@ -1,5 +1,5 @@
1
- import { FormMetaDataModel, MetaDataJson } from './types/index.js';
2
- import Node from './Node.js';
1
+ import { FormMetaDataModel, MetaDataJson } from './types/index';
2
+ import Node from './Node';
3
3
  declare class FormMetaData extends Node<MetaDataJson> implements FormMetaDataModel {
4
4
  get version(): string;
5
5
  get grammar(): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Node_1 = __importDefault(require("./Node"));
7
+ class FormMetaData extends Node_1.default {
8
+ get version() {
9
+ return this.getP('version', '');
10
+ }
11
+ get grammar() {
12
+ return this.getP('grammar', '');
13
+ }
14
+ }
15
+ exports.default = FormMetaData;
@@ -1,5 +1,5 @@
1
- import { Action, FieldsetModel } from './types/index.js';
2
- import { Fieldset } from './Fieldset.js';
1
+ import { Action, FieldsetModel } from './types/index';
2
+ import { Fieldset } from './Fieldset';
3
3
  export declare class InstanceManager extends Fieldset implements FieldsetModel {
4
4
  get maxOccur(): number;
5
5
  set maxOccur(m: number);
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.InstanceManager = void 0;
10
+ const Fieldset_1 = require("./Fieldset");
11
+ const BaseNode_1 = require("./BaseNode");
12
+ class InstanceManager extends Fieldset_1.Fieldset {
13
+ get maxOccur() {
14
+ return this._jsonModel.maxItems;
15
+ }
16
+ set maxOccur(m) {
17
+ this.maxItems = m;
18
+ }
19
+ get minOccur() {
20
+ return this.minItems;
21
+ }
22
+ addInstance(action) {
23
+ return this.addItem(action);
24
+ }
25
+ removeInstance(action) {
26
+ return this.removeItem(action);
27
+ }
28
+ }
29
+ __decorate([
30
+ (0, BaseNode_1.dependencyTracked)()
31
+ ], InstanceManager.prototype, "maxOccur", null);
32
+ __decorate([
33
+ (0, BaseNode_1.dependencyTracked)()
34
+ ], InstanceManager.prototype, "minOccur", null);
35
+ exports.InstanceManager = InstanceManager;
File without changes
package/lib/Node.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const JsonUtils_1 = require("./utils/JsonUtils");
4
+ class Node {
5
+ constructor(inputModel) {
6
+ this._jsonModel = Object.assign({}, inputModel);
7
+ }
8
+ getP(key, def) {
9
+ return (0, JsonUtils_1.getProperty)(this._jsonModel, key, def);
10
+ }
11
+ get isContainer() {
12
+ return false;
13
+ }
14
+ }
15
+ exports.default = Node;
@@ -1,9 +1,9 @@
1
- import { Action, RulesJson, ScriptableField } from './types/index.js';
2
- import { BaseNode } from './BaseNode.js';
1
+ import { Action, RulesJson, ScriptableField } from './types/index';
2
+ import { BaseNode } from './BaseNode';
3
3
  declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> implements ScriptableField {
4
4
  private _events;
5
5
  private _rules;
6
- getRules(): import("./types/Json.js").Items<string>;
6
+ getRules(): import("./types/Json").Items<string>;
7
7
  private getCompiledRule;
8
8
  private getCompiledEvent;
9
9
  private applyUpdates;
@@ -1,33 +1,12 @@
1
- /*************************************************************************
2
- * ADOBE CONFIDENTIAL
3
- * ___________________
4
- *
5
- * Copyright 2022 Adobe
6
- * All Rights Reserved.
7
- *
8
- * NOTICE: All information contained herein is, and remains
9
- * the property of Adobe and its suppliers, if any. The intellectual
10
- * and technical concepts contained herein are proprietary to Adobe
11
- * and its suppliers and are protected by all applicable intellectual
12
- * property laws, including trade secret and copyright laws.
13
- * Dissemination of this information or reproduction of this material
14
- * is strictly forbidden unless prior written permission is obtained
15
- * from Adobe.
16
-
17
- * Adobe permits you to use and modify this file solely in accordance with
18
- * the terms of the Adobe license agreement accompanying it.
19
- *************************************************************************/
20
-
21
- import { B as BaseNode, a as editableProperties } from './BaseNode-d78cc1b0.js';
22
- import './controller/Events.js';
23
- import './utils/DataRefParser.js';
24
- import './data/DataGroup.js';
25
- import './data/DataValue.js';
26
- import './data/EmptyDataValue.js';
27
-
28
- class Scriptable extends BaseNode {
29
- _events = {};
30
- _rules = {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const BaseNode_1 = require("./BaseNode");
4
+ class Scriptable extends BaseNode_1.BaseNode {
5
+ constructor() {
6
+ super(...arguments);
7
+ this._events = {};
8
+ this._rules = {};
9
+ }
31
10
  getRules() {
32
11
  return typeof this._jsonModel.rules !== 'object' ? {} : this._jsonModel.rules;
33
12
  }
@@ -49,8 +28,9 @@ class Scriptable extends BaseNode {
49
28
  return this._rules[eName];
50
29
  }
51
30
  getCompiledEvent(eName) {
31
+ var _a;
52
32
  if (!(eName in this._events)) {
53
- let eString = this._jsonModel.events?.[eName];
33
+ let eString = (_a = this._jsonModel.events) === null || _a === void 0 ? void 0 : _a[eName];
54
34
  if (typeof eString === 'string' && eString.length > 0) {
55
35
  eString = [eString];
56
36
  }
@@ -70,7 +50,7 @@ class Scriptable extends BaseNode {
70
50
  }
71
51
  applyUpdates(updates) {
72
52
  Object.entries(updates).forEach(([key, value]) => {
73
- if (key in editableProperties || (key in this && typeof this[key] !== 'function')) {
53
+ if (key in BaseNode_1.editableProperties || (key in this && typeof this[key] !== 'function')) {
74
54
  try {
75
55
  this[key] = value;
76
56
  }
@@ -88,7 +68,7 @@ class Scriptable extends BaseNode {
88
68
  const node = this.getCompiledRule(prop, rule);
89
69
  if (node) {
90
70
  const newVal = this.ruleEngine.execute(node, scope, context, true);
91
- if (editableProperties.indexOf(prop) > -1) {
71
+ if (BaseNode_1.editableProperties.indexOf(prop) > -1) {
92
72
  this[prop] = newVal;
93
73
  }
94
74
  else {
@@ -102,7 +82,7 @@ class Scriptable extends BaseNode {
102
82
  const parent = this.getNonTransparentParent();
103
83
  const target = {
104
84
  self: this.getRuleNode(),
105
- siblings: parent?.ruleNodeReference() || {}
85
+ siblings: (parent === null || parent === void 0 ? void 0 : parent.ruleNodeReference()) || {}
106
86
  };
107
87
  const scope = new Proxy(target, {
108
88
  get: (target, prop) => {
@@ -112,11 +92,11 @@ class Scriptable extends BaseNode {
112
92
  prop = prop;
113
93
  if (prop.startsWith('$')) {
114
94
  const retValue = target.self[prop];
115
- if (retValue instanceof BaseNode) {
95
+ if (retValue instanceof BaseNode_1.BaseNode) {
116
96
  return retValue.getRuleNode();
117
97
  }
118
98
  else if (retValue instanceof Array) {
119
- return retValue.map(r => r instanceof BaseNode ? r.getRuleNode() : r);
99
+ return retValue.map(r => r instanceof BaseNode_1.BaseNode ? r.getRuleNode() : r);
120
100
  }
121
101
  else {
122
102
  return retValue;
@@ -186,5 +166,4 @@ class Scriptable extends BaseNode {
186
166
  this.notifyDependents(action);
187
167
  }
188
168
  }
189
-
190
- export { Scriptable as default };
169
+ exports.default = Scriptable;