@bgroup/wise-form 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +23 -4
- package/postcss.config.js +6 -0
- package/src/form/styles.css +11 -37
- package/src/form/view/components/containers/index.tsx +33 -4
- package/src/form/view/components/error.tsx +0 -3
- package/src/form/view/components/field/container.tsx +1 -1
- package/src/form/view/components/field/index.tsx +42 -7
- package/src/form/view/components/rows/row-container.tsx +37 -9
- package/src/form/view/components/rows/wrapper.tsx +17 -6
- package/src/form/view/components/wrapped-form.tsx +38 -5
- package/src/form/view/hooks/use-model.ts +91 -25
- package/src/form/view/index.tsx +15 -3
- package/src/models/field.ts +504 -458
- package/tailwind.config.js +11 -0
- package/tsconfig.json +2 -0
- package/vite.config.ts +59 -0
- package/dist/components/ui/Checkbox.d.ts +0 -14
- package/dist/components/ui/Checkbox.d.ts.map +0 -1
- package/dist/components/ui/Checkbox.js +0 -43
- package/dist/components/ui/Checkbox.js.map +0 -1
- package/dist/components/ui/CheckboxGroup.d.ts +0 -15
- package/dist/components/ui/CheckboxGroup.d.ts.map +0 -1
- package/dist/components/ui/CheckboxGroup.js +0 -33
- package/dist/components/ui/CheckboxGroup.js.map +0 -1
- package/dist/components/ui/Input.d.ts +0 -14
- package/dist/components/ui/Input.d.ts.map +0 -1
- package/dist/components/ui/Input.js +0 -49
- package/dist/components/ui/Input.js.map +0 -1
- package/dist/components/ui/Radio.d.ts +0 -14
- package/dist/components/ui/Radio.d.ts.map +0 -1
- package/dist/components/ui/Radio.js +0 -43
- package/dist/components/ui/Radio.js.map +0 -1
- package/dist/components/ui/Select.d.ts +0 -18
- package/dist/components/ui/Select.d.ts.map +0 -1
- package/dist/components/ui/Select.js +0 -44
- package/dist/components/ui/Select.js.map +0 -1
- package/dist/components/ui/Textarea.d.ts +0 -13
- package/dist/components/ui/Textarea.d.ts.map +0 -1
- package/dist/components/ui/Textarea.js +0 -42
- package/dist/components/ui/Textarea.js.map +0 -1
- package/dist/components/ui/index.d.ts +0 -13
- package/dist/components/ui/index.d.ts.map +0 -1
- package/dist/components/ui/index.js +0 -7
- package/dist/components/ui/index.js.map +0 -1
- package/dist/form/index.d.ts +0 -10
- package/dist/form/index.d.ts.map +0 -1
- package/dist/form/index.js +0 -5
- package/dist/form/index.js.map +0 -1
- package/dist/form/interfaces/field-container.d.ts +0 -8
- package/dist/form/interfaces/field-container.d.ts.map +0 -1
- package/dist/form/interfaces/field-container.js +0 -2
- package/dist/form/interfaces/field-container.js.map +0 -1
- package/dist/form/interfaces/interfaces.d.ts +0 -8
- package/dist/form/interfaces/interfaces.d.ts.map +0 -1
- package/dist/form/interfaces/interfaces.js +0 -2
- package/dist/form/interfaces/interfaces.js.map +0 -1
- package/dist/form/interfaces/settings.d.ts +0 -10
- package/dist/form/interfaces/settings.d.ts.map +0 -1
- package/dist/form/interfaces/settings.js +0 -2
- package/dist/form/interfaces/settings.js.map +0 -1
- package/dist/form/interfaces/template.d.ts +0 -6
- package/dist/form/interfaces/template.d.ts.map +0 -1
- package/dist/form/interfaces/template.js +0 -2
- package/dist/form/interfaces/template.js.map +0 -1
- package/dist/form/interfaces/wise-form-specs.d.ts +0 -9
- package/dist/form/interfaces/wise-form-specs.d.ts.map +0 -1
- package/dist/form/interfaces/wise-form-specs.js +0 -2
- package/dist/form/interfaces/wise-form-specs.js.map +0 -1
- package/dist/form/view/components/containers/index.d.ts +0 -3
- package/dist/form/view/components/containers/index.d.ts.map +0 -1
- package/dist/form/view/components/containers/index.js +0 -12
- package/dist/form/view/components/containers/index.js.map +0 -1
- package/dist/form/view/components/error.d.ts +0 -5
- package/dist/form/view/components/error.d.ts.map +0 -1
- package/dist/form/view/components/error.js +0 -8
- package/dist/form/view/components/error.js.map +0 -1
- package/dist/form/view/components/field/container.d.ts +0 -5
- package/dist/form/view/components/field/container.d.ts.map +0 -1
- package/dist/form/view/components/field/container.js +0 -5
- package/dist/form/view/components/field/container.js.map +0 -1
- package/dist/form/view/components/field/index.d.ts +0 -18
- package/dist/form/view/components/field/index.d.ts.map +0 -1
- package/dist/form/view/components/field/index.js +0 -89
- package/dist/form/view/components/field/index.js.map +0 -1
- package/dist/form/view/components/field/selection.d.ts +0 -2
- package/dist/form/view/components/field/selection.d.ts.map +0 -1
- package/dist/form/view/components/field/selection.js +0 -35
- package/dist/form/view/components/field/selection.js.map +0 -1
- package/dist/form/view/components/field/use-field.d.ts +0 -4
- package/dist/form/view/components/field/use-field.d.ts.map +0 -1
- package/dist/form/view/components/field/use-field.js +0 -41
- package/dist/form/view/components/field/use-field.js.map +0 -1
- package/dist/form/view/components/rows/row-container.d.ts +0 -18
- package/dist/form/view/components/rows/row-container.d.ts.map +0 -1
- package/dist/form/view/components/rows/row-container.js +0 -89
- package/dist/form/view/components/rows/row-container.js.map +0 -1
- package/dist/form/view/components/rows/wrapper.d.ts +0 -12
- package/dist/form/view/components/rows/wrapper.d.ts.map +0 -1
- package/dist/form/view/components/rows/wrapper.js +0 -27
- package/dist/form/view/components/rows/wrapper.js.map +0 -1
- package/dist/form/view/components/wrapped-form.d.ts +0 -6
- package/dist/form/view/components/wrapped-form.d.ts.map +0 -1
- package/dist/form/view/components/wrapped-form.js +0 -26
- package/dist/form/view/components/wrapped-form.js.map +0 -1
- package/dist/form/view/context.d.ts +0 -23
- package/dist/form/view/context.d.ts.map +0 -1
- package/dist/form/view/context.js +0 -7
- package/dist/form/view/context.js.map +0 -1
- package/dist/form/view/hooks/use-model.d.ts +0 -10
- package/dist/form/view/hooks/use-model.d.ts.map +0 -1
- package/dist/form/view/hooks/use-model.js +0 -31
- package/dist/form/view/hooks/use-model.js.map +0 -1
- package/dist/form/view/hooks/use-template.d.ts +0 -14
- package/dist/form/view/hooks/use-template.d.ts.map +0 -1
- package/dist/form/view/hooks/use-template.js +0 -57
- package/dist/form/view/hooks/use-template.js.map +0 -1
- package/dist/form/view/hooks/use-types.d.ts +0 -2
- package/dist/form/view/hooks/use-types.d.ts.map +0 -1
- package/dist/form/view/hooks/use-types.js +0 -19
- package/dist/form/view/hooks/use-types.js.map +0 -1
- package/dist/form/view/index.d.ts +0 -3
- package/dist/form/view/index.d.ts.map +0 -1
- package/dist/form/view/index.js +0 -38
- package/dist/form/view/index.js.map +0 -1
- package/dist/formulas/helpers/condition-types.d.ts +0 -5
- package/dist/formulas/helpers/condition-types.d.ts.map +0 -1
- package/dist/formulas/helpers/condition-types.js +0 -5
- package/dist/formulas/helpers/condition-types.js.map +0 -1
- package/dist/formulas/helpers/evaluations.d.ts +0 -15
- package/dist/formulas/helpers/evaluations.d.ts.map +0 -1
- package/dist/formulas/helpers/evaluations.js +0 -44
- package/dist/formulas/helpers/evaluations.js.map +0 -1
- package/dist/formulas/helpers/formula.d.ts +0 -6
- package/dist/formulas/helpers/formula.d.ts.map +0 -1
- package/dist/formulas/helpers/formula.js +0 -26
- package/dist/formulas/helpers/formula.js.map +0 -1
- package/dist/formulas/helpers/lexer.d.ts +0 -10
- package/dist/formulas/helpers/lexer.d.ts.map +0 -1
- package/dist/formulas/helpers/lexer.js +0 -73
- package/dist/formulas/helpers/lexer.js.map +0 -1
- package/dist/formulas/helpers/parser.d.ts +0 -24
- package/dist/formulas/helpers/parser.d.ts.map +0 -1
- package/dist/formulas/helpers/parser.js +0 -48
- package/dist/formulas/helpers/parser.js.map +0 -1
- package/dist/formulas/helpers/token.d.ts +0 -14
- package/dist/formulas/helpers/token.d.ts.map +0 -1
- package/dist/formulas/helpers/token.js +0 -14
- package/dist/formulas/helpers/token.js.map +0 -1
- package/dist/formulas/index.d.ts +0 -59
- package/dist/formulas/index.d.ts.map +0 -1
- package/dist/formulas/index.js +0 -186
- package/dist/formulas/index.js.map +0 -1
- package/dist/formulas/types/formulas.d.ts +0 -68
- package/dist/formulas/types/formulas.d.ts.map +0 -1
- package/dist/formulas/types/formulas.js +0 -2
- package/dist/formulas/types/formulas.js.map +0 -1
- package/dist/formulas/types/index.d.ts +0 -5
- package/dist/formulas/types/index.d.ts.map +0 -1
- package/dist/formulas/types/index.js +0 -2
- package/dist/formulas/types/index.js.map +0 -1
- package/dist/formulas/variants/array-formula.d.ts +0 -24
- package/dist/formulas/variants/array-formula.d.ts.map +0 -1
- package/dist/formulas/variants/array-formula.js +0 -142
- package/dist/formulas/variants/array-formula.js.map +0 -1
- package/dist/formulas/variants/base.d.ts +0 -6
- package/dist/formulas/variants/base.d.ts.map +0 -1
- package/dist/formulas/variants/base.js +0 -3
- package/dist/formulas/variants/base.js.map +0 -1
- package/dist/formulas/variants/basic.d.ts +0 -18
- package/dist/formulas/variants/basic.d.ts.map +0 -1
- package/dist/formulas/variants/basic.js +0 -128
- package/dist/formulas/variants/basic.js.map +0 -1
- package/dist/formulas/variants/comparison.d.ts +0 -25
- package/dist/formulas/variants/comparison.d.ts.map +0 -1
- package/dist/formulas/variants/comparison.js +0 -153
- package/dist/formulas/variants/comparison.js.map +0 -1
- package/dist/formulas/variants/conditional.d.ts +0 -18
- package/dist/formulas/variants/conditional.d.ts.map +0 -1
- package/dist/formulas/variants/conditional.js +0 -183
- package/dist/formulas/variants/conditional.js.map +0 -1
- package/dist/formulas/variants/iterative-array.d.ts +0 -20
- package/dist/formulas/variants/iterative-array.d.ts.map +0 -1
- package/dist/formulas/variants/iterative-array.js +0 -155
- package/dist/formulas/variants/iterative-array.js.map +0 -1
- package/dist/formulas/variants/per-value.d.ts +0 -20
- package/dist/formulas/variants/per-value.d.ts.map +0 -1
- package/dist/formulas/variants/per-value.js +0 -154
- package/dist/formulas/variants/per-value.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/models/base.d.ts +0 -55
- package/dist/models/base.d.ts.map +0 -1
- package/dist/models/base.js +0 -146
- package/dist/models/base.js.map +0 -1
- package/dist/models/callback-manager.d.ts +0 -7
- package/dist/models/callback-manager.d.ts.map +0 -1
- package/dist/models/callback-manager.js +0 -89
- package/dist/models/callback-manager.js.map +0 -1
- package/dist/models/field.d.ts +0 -121
- package/dist/models/field.d.ts.map +0 -1
- package/dist/models/field.js +0 -443
- package/dist/models/field.js.map +0 -1
- package/dist/models/index.d.ts +0 -13
- package/dist/models/index.d.ts.map +0 -1
- package/dist/models/index.js +0 -7
- package/dist/models/index.js.map +0 -1
- package/dist/models/model.d.ts +0 -37
- package/dist/models/model.d.ts.map +0 -1
- package/dist/models/model.js +0 -245
- package/dist/models/model.js.map +0 -1
- package/dist/models/plugins/base.d.ts +0 -9
- package/dist/models/plugins/base.d.ts.map +0 -1
- package/dist/models/plugins/base.js +0 -3
- package/dist/models/plugins/base.js.map +0 -1
- package/dist/models/plugins/formula.d.ts +0 -18
- package/dist/models/plugins/formula.d.ts.map +0 -1
- package/dist/models/plugins/formula.js +0 -82
- package/dist/models/plugins/formula.js.map +0 -1
- package/dist/models/plugins/index.d.ts +0 -11
- package/dist/models/plugins/index.d.ts.map +0 -1
- package/dist/models/plugins/index.js +0 -52
- package/dist/models/plugins/index.js.map +0 -1
- package/dist/models/plugins/plugins.d.ts +0 -7
- package/dist/models/plugins/plugins.d.ts.map +0 -1
- package/dist/models/plugins/plugins.js +0 -7
- package/dist/models/plugins/plugins.js.map +0 -1
- package/dist/models/types/base-wise-model.d.ts +0 -7
- package/dist/models/types/base-wise-model.d.ts.map +0 -1
- package/dist/models/types/base-wise-model.js +0 -2
- package/dist/models/types/base-wise-model.js.map +0 -1
- package/dist/models/types/callbacks.d.ts +0 -19
- package/dist/models/types/callbacks.d.ts.map +0 -1
- package/dist/models/types/callbacks.js +0 -2
- package/dist/models/types/callbacks.js.map +0 -1
- package/dist/models/types/disabled.d.ts +0 -8
- package/dist/models/types/disabled.d.ts.map +0 -1
- package/dist/models/types/disabled.js +0 -2
- package/dist/models/types/disabled.js.map +0 -1
- package/dist/models/types/form-field.d.ts +0 -25
- package/dist/models/types/form-field.d.ts.map +0 -1
- package/dist/models/types/form-field.js +0 -2
- package/dist/models/types/form-field.js.map +0 -1
- package/dist/models/types/model.d.ts +0 -13
- package/dist/models/types/model.d.ts.map +0 -1
- package/dist/models/types/model.js +0 -2
- package/dist/models/types/model.js.map +0 -1
- package/dist/models/types/plugins.d.ts +0 -13
- package/dist/models/types/plugins.d.ts.map +0 -1
- package/dist/models/types/plugins.js +0 -2
- package/dist/models/types/plugins.js.map +0 -1
- package/dist/models/types/wrapped-form-model-props.d.ts +0 -11
- package/dist/models/types/wrapped-form-model-props.d.ts.map +0 -1
- package/dist/models/types/wrapped-form-model-props.js +0 -2
- package/dist/models/types/wrapped-form-model-props.js.map +0 -1
- package/dist/models/wrapper.d.ts +0 -30
- package/dist/models/wrapper.d.ts.map +0 -1
- package/dist/models/wrapper.js +0 -213
- package/dist/models/wrapper.js.map +0 -1
- package/dist/settings/index.d.ts +0 -7
- package/dist/settings/index.d.ts.map +0 -1
- package/dist/settings/index.js +0 -26
- package/dist/settings/index.js.map +0 -1
- package/dist/utils/pending-promise.d.ts +0 -6
- package/dist/utils/pending-promise.d.ts.map +0 -1
- package/dist/utils/pending-promise.js +0 -24
- package/dist/utils/pending-promise.js.map +0 -1
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _CallbackManager_field, _CallbackManager_model, _CallbackManager_callbacks, _CallbackManager_listeners;
|
|
13
|
-
export class CallbackManager {
|
|
14
|
-
constructor(model, field) {
|
|
15
|
-
_CallbackManager_field.set(this, void 0);
|
|
16
|
-
_CallbackManager_model.set(this, void 0);
|
|
17
|
-
_CallbackManager_callbacks.set(this, []);
|
|
18
|
-
_CallbackManager_listeners.set(this, []);
|
|
19
|
-
this.executeCallback = async (settings) => {
|
|
20
|
-
const params = {
|
|
21
|
-
...settings,
|
|
22
|
-
form: __classPrivateFieldGet(this, _CallbackManager_model, "f"),
|
|
23
|
-
field: __classPrivateFieldGet(this, _CallbackManager_field, "f"),
|
|
24
|
-
settings,
|
|
25
|
-
};
|
|
26
|
-
if (!settings) {
|
|
27
|
-
console.warn('the field does not have dependentOn settings');
|
|
28
|
-
}
|
|
29
|
-
const callback = __classPrivateFieldGet(this, _CallbackManager_callbacks, "f")[settings.callback];
|
|
30
|
-
const dependency = __classPrivateFieldGet(this, _CallbackManager_model, "f").getField(__classPrivateFieldGet(this, _CallbackManager_model, "f").getFieldName(settings.field));
|
|
31
|
-
await dependency.isReady;
|
|
32
|
-
const fields = { [dependency.name]: dependency };
|
|
33
|
-
if (settings.hasOwnProperty('fields')) {
|
|
34
|
-
for (const field of settings.fields) {
|
|
35
|
-
const instance = __classPrivateFieldGet(this, _CallbackManager_model, "f").getField(__classPrivateFieldGet(this, _CallbackManager_model, "f").getFieldName(field));
|
|
36
|
-
if (instance)
|
|
37
|
-
await instance.isReady;
|
|
38
|
-
const propName = typeof field === 'string' ? field : field.alias;
|
|
39
|
-
fields[propName] = instance;
|
|
40
|
-
}
|
|
41
|
-
params.fields = fields;
|
|
42
|
-
}
|
|
43
|
-
params.dependency = dependency;
|
|
44
|
-
//global wiseForm params
|
|
45
|
-
if (settings.hasOwnProperty('params')) {
|
|
46
|
-
const specs = {};
|
|
47
|
-
settings.params.forEach((param) => {
|
|
48
|
-
if (!__classPrivateFieldGet(this, _CallbackManager_model, "f")?.getParams(param)) {
|
|
49
|
-
console.warn(`param ${param} is not registered in the form`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
specs[param] = __classPrivateFieldGet(this, _CallbackManager_model, "f").getParams(param);
|
|
53
|
-
});
|
|
54
|
-
params.specs = specs;
|
|
55
|
-
}
|
|
56
|
-
callback(params);
|
|
57
|
-
};
|
|
58
|
-
__classPrivateFieldSet(this, _CallbackManager_field, field, "f");
|
|
59
|
-
__classPrivateFieldSet(this, _CallbackManager_model, model, "f");
|
|
60
|
-
__classPrivateFieldSet(this, _CallbackManager_callbacks, model.callbacks, "f");
|
|
61
|
-
this.initialize();
|
|
62
|
-
}
|
|
63
|
-
initialize() {
|
|
64
|
-
const instance = __classPrivateFieldGet(this, _CallbackManager_field, "f");
|
|
65
|
-
const checkField = async (settings) => {
|
|
66
|
-
const dependency = __classPrivateFieldGet(this, _CallbackManager_model, "f").getField(__classPrivateFieldGet(this, _CallbackManager_model, "f").getFieldName(settings.field));
|
|
67
|
-
await dependency.isReady;
|
|
68
|
-
const required = ['field', 'callback'];
|
|
69
|
-
required.forEach((prop) => {
|
|
70
|
-
if (!settings[prop])
|
|
71
|
-
throw new Error(`${settings?.field} is missing ${prop}`);
|
|
72
|
-
});
|
|
73
|
-
if (!dependency)
|
|
74
|
-
throw new Error(`${settings?.field} is not a registered field`);
|
|
75
|
-
if (!__classPrivateFieldGet(this, _CallbackManager_callbacks, "f")[settings.callback]) {
|
|
76
|
-
throw new Error(`${settings.callback} is not a registered callback ${settings.name}`);
|
|
77
|
-
}
|
|
78
|
-
// saved in listener array to be able to remove the listener if is required.
|
|
79
|
-
const event = settings.event || 'value.change';
|
|
80
|
-
const caller = () => this.executeCallback(settings);
|
|
81
|
-
__classPrivateFieldGet(this, _CallbackManager_listeners, "f").push(caller);
|
|
82
|
-
dependency.on(event, caller);
|
|
83
|
-
//callback({ dependency, settings, field: instance, form: this });
|
|
84
|
-
};
|
|
85
|
-
instance?.specs?.dependentOn.forEach(checkField);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
_CallbackManager_field = new WeakMap(), _CallbackManager_model = new WeakMap(), _CallbackManager_callbacks = new WeakMap(), _CallbackManager_listeners = new WeakMap();
|
|
89
|
-
//# sourceMappingURL=callback-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callback-manager.js","sourceRoot":"","sources":["../../src/models/callback-manager.ts"],"names":[],"mappings":"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"}
|
package/dist/models/field.d.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { ReactiveModel } from '@beyond-js/reactive/model';
|
|
2
|
-
import type { WrappedFormModel } from './wrapper';
|
|
3
|
-
import { FormModel } from './model';
|
|
4
|
-
import { IFormField, IFormFieldProps } from './types/form-field';
|
|
5
|
-
import { IDisabled } from './types/disabled';
|
|
6
|
-
/**
|
|
7
|
-
* Represents a single form field within a `FormModel` or `WrappedFormModel`, providing mechanisms for data binding, validation, and interaction.
|
|
8
|
-
* This class extends `ReactiveModel` to enable reactive updates and interactions within the form's lifecycle.
|
|
9
|
-
*
|
|
10
|
-
* @extends ReactiveModel<IFormField>
|
|
11
|
-
*/
|
|
12
|
-
export declare class FormField extends ReactiveModel<IFormField> {
|
|
13
|
-
#private;
|
|
14
|
-
get parent(): FormModel | WrappedFormModel;
|
|
15
|
-
setEvents(events: string[]): void;
|
|
16
|
-
/**
|
|
17
|
-
* Evaluates and returns the disabled state of the field. If `#disabled` is an object, it checks the specified fields' values to determine the disabled state dynamically.
|
|
18
|
-
* @returns {boolean} The disabled state of the field.
|
|
19
|
-
*/
|
|
20
|
-
get disabled(): boolean | IDisabled;
|
|
21
|
-
set disabled(value: boolean | IDisabled);
|
|
22
|
-
get specs(): Record<string, any>;
|
|
23
|
-
get attributes(): {
|
|
24
|
-
disabled: boolean | IDisabled;
|
|
25
|
-
value: string;
|
|
26
|
-
name?: string;
|
|
27
|
-
type?: string;
|
|
28
|
-
placeholder?: string;
|
|
29
|
-
required?: boolean;
|
|
30
|
-
label?: string;
|
|
31
|
-
variant?: string;
|
|
32
|
-
hidden?: boolean;
|
|
33
|
-
options?: Array<{
|
|
34
|
-
value: any;
|
|
35
|
-
label?: string;
|
|
36
|
-
[key: string]: any;
|
|
37
|
-
}>;
|
|
38
|
-
className?: string;
|
|
39
|
-
checked?: boolean;
|
|
40
|
-
id?: string;
|
|
41
|
-
icon?: string;
|
|
42
|
-
};
|
|
43
|
-
get value(): string;
|
|
44
|
-
set value(value: string);
|
|
45
|
-
/**
|
|
46
|
-
* Constructs a FormField instance with specified properties and parent form model.
|
|
47
|
-
* @param {Object} params - Construction parameters including the parent form model and field specifications.
|
|
48
|
-
*/
|
|
49
|
-
constructor({ parent, specs }: {
|
|
50
|
-
parent: any;
|
|
51
|
-
specs: IFormFieldProps;
|
|
52
|
-
});
|
|
53
|
-
getProperties(): {
|
|
54
|
-
value: string;
|
|
55
|
-
name?: string;
|
|
56
|
-
type?: string;
|
|
57
|
-
placeholder?: string;
|
|
58
|
-
required?: boolean;
|
|
59
|
-
label?: string;
|
|
60
|
-
variant?: string;
|
|
61
|
-
disabled?: boolean;
|
|
62
|
-
hidden?: boolean;
|
|
63
|
-
options?: Array<{
|
|
64
|
-
value: any;
|
|
65
|
-
label?: string;
|
|
66
|
-
[key: string]: any;
|
|
67
|
-
}>;
|
|
68
|
-
className?: string;
|
|
69
|
-
checked?: boolean;
|
|
70
|
-
id?: string;
|
|
71
|
-
icon?: string;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* This method is used to set the value property of the field and fire the value.change event
|
|
75
|
-
*
|
|
76
|
-
* @param value
|
|
77
|
-
* @returns
|
|
78
|
-
*/
|
|
79
|
-
setValue(value: string): void;
|
|
80
|
-
generateRandomNumber: () => number;
|
|
81
|
-
/**
|
|
82
|
-
* Performs initial setup based on the field's specifications, setting up validation, default values, and any specified dynamic behavior.
|
|
83
|
-
*/
|
|
84
|
-
initialize: () => void;
|
|
85
|
-
/**
|
|
86
|
-
* Resets the field to its initial value and state, including resetting the disabled state if it's statically defined.
|
|
87
|
-
*/
|
|
88
|
-
clear: () => void;
|
|
89
|
-
/**
|
|
90
|
-
* Checks and applies the field's settings, particularly for dynamic disabling, establishing listeners on related fields as necessary.
|
|
91
|
-
* @param {Object} props - The field's properties and settings to check and apply.
|
|
92
|
-
*/
|
|
93
|
-
checkSettings(props: any): void;
|
|
94
|
-
/**
|
|
95
|
-
* Metodo para identificar si es field con multiples eventos configurados o solo es un evento configurado
|
|
96
|
-
* hace la busqueda del evento lanzado al haber multiples
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
listenerEvents: (event2: any) => void;
|
|
100
|
-
/**
|
|
101
|
-
* Cleans up any established listeners and internal state when the field is removed or the form is reset, ensuring no memory leaks or stale data.
|
|
102
|
-
*/
|
|
103
|
-
cleanUp(): void;
|
|
104
|
-
/**
|
|
105
|
-
* The `set` method sets one or more properties on the model.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* This method overwrites the original reactiveModel set to pass the object as param
|
|
109
|
-
* when the change event is fired.
|
|
110
|
-
* Eventually this method will be removed and the original set method will be used, but
|
|
111
|
-
* it requires an upgrade in the reactive model package.
|
|
112
|
-
* @param {keyof ReactiveModelPublic<T>} property - The name of the property to set.
|
|
113
|
-
* @param {*} value - The value to set the property to.
|
|
114
|
-
* @returns {void}
|
|
115
|
-
*/
|
|
116
|
-
set(properties: Partial<IFormField>): any;
|
|
117
|
-
hide: () => void;
|
|
118
|
-
show: () => void;
|
|
119
|
-
private evaluations;
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/models/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,aAAa,CAAC,UAAU,CAAC;;IAGpD,IAAI,MAAM,iCAET;IAID,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE;IAO1B;;;OAGG;IACH,IAAI,QAAQ,wBAsBX;IAED,IAAI,QAAQ,CAAC,KAAK,qBAAA,EAIjB;IAID,IAAI,KAAK,wBAER;IAED,IAAI,UAAU;;;;;;;;;;;;iBAhEQ,CAAA;;;;;;;MAsErB;IAGD,IAAI,KAAK,WAER;IAED,IAAI,KAAK,CAAC,KAAK,QAAA,EAEd;IAKD;;;OAGG;gBACS,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QAAE,MAAM,MAAC;QAAC,KAAK,EAAE,eAAe,CAAA;KAAE;IAsDjE,aAAa;;;;;;;;;;;;iBA9IS,CAAA;;;;;;;;IAmJtB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM;IAOtB,oBAAoB,eAElB;IAEF;;OAEG;IACH,UAAU,aAIR;IAEF;;OAEG;IACH,KAAK,aAOH;IAWF;;;OAGG;IACH,aAAa,CAAC,KAAK,KAAA;IA8GnB;;;;OAIG;IACH,cAAc,GAAI,WAAM,UAoBtB;IAEF;;OAEG;IACH,OAAO;IAOP;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG;IA+GzC,IAAI,aAKF;IAEF,IAAI,aAOF;IAEF,OAAO,CAAC,WAAW,CAoBjB;CACL"}
|
package/dist/models/field.js
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _FormField_instances, _FormField_parent, _FormField_NATIVE_ACTIONS, _FormField_EVENTS, _FormField_isReady, _FormField_disabled, _FormField_specs, _FormField_value, _FormField_listeningItems, _FormField_listenSiblings, _FormField_executeEvent, _FormField_getEvent;
|
|
13
|
-
import { ReactiveModel } from '@beyond-js/reactive/model';
|
|
14
|
-
/**
|
|
15
|
-
* Represents a single form field within a `FormModel` or `WrappedFormModel`, providing mechanisms for data binding, validation, and interaction.
|
|
16
|
-
* This class extends `ReactiveModel` to enable reactive updates and interactions within the form's lifecycle.
|
|
17
|
-
*
|
|
18
|
-
* @extends ReactiveModel<IFormField>
|
|
19
|
-
*/
|
|
20
|
-
export class FormField extends ReactiveModel {
|
|
21
|
-
get parent() {
|
|
22
|
-
return __classPrivateFieldGet(this, _FormField_parent, "f");
|
|
23
|
-
}
|
|
24
|
-
setEvents(events) {
|
|
25
|
-
__classPrivateFieldGet(this, _FormField_EVENTS, "f").concat(events);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Evaluates and returns the disabled state of the field. If `#disabled` is an object, it checks the specified fields' values to determine the disabled state dynamically.
|
|
29
|
-
* @returns {boolean} The disabled state of the field.
|
|
30
|
-
*/
|
|
31
|
-
get disabled() {
|
|
32
|
-
if (typeof __classPrivateFieldGet(this, _FormField_disabled, "f") !== 'object' || !__classPrivateFieldGet(this, _FormField_disabled, "f")?.fields)
|
|
33
|
-
return __classPrivateFieldGet(this, _FormField_disabled, "f");
|
|
34
|
-
const validate = (field) => {
|
|
35
|
-
if (typeof field !== 'object')
|
|
36
|
-
return !__classPrivateFieldGet(this, _FormField_parent, "f").form.getField(field).value;
|
|
37
|
-
const { name, value } = field;
|
|
38
|
-
const fieldInstance = __classPrivateFieldGet(this, _FormField_parent, "f").getField(name);
|
|
39
|
-
if (!fieldInstance)
|
|
40
|
-
return false;
|
|
41
|
-
if (field.hasOwnProperty('condition')) {
|
|
42
|
-
const compare = this.evaluations[field.condition](fieldInstance.value, field.value);
|
|
43
|
-
return compare;
|
|
44
|
-
}
|
|
45
|
-
const { value: fieldValue } = fieldInstance;
|
|
46
|
-
return value !== fieldValue;
|
|
47
|
-
};
|
|
48
|
-
return __classPrivateFieldGet(this, _FormField_disabled, "f").fields.some(validate);
|
|
49
|
-
}
|
|
50
|
-
set disabled(value) {
|
|
51
|
-
if (value === __classPrivateFieldGet(this, _FormField_disabled, "f"))
|
|
52
|
-
return;
|
|
53
|
-
__classPrivateFieldSet(this, _FormField_disabled, value, "f");
|
|
54
|
-
this.triggerEvent();
|
|
55
|
-
}
|
|
56
|
-
get specs() {
|
|
57
|
-
return __classPrivateFieldGet(this, _FormField_specs, "f");
|
|
58
|
-
}
|
|
59
|
-
get attributes() {
|
|
60
|
-
const props = this.getProperties();
|
|
61
|
-
return {
|
|
62
|
-
...props,
|
|
63
|
-
disabled: __classPrivateFieldGet(this, _FormField_disabled, "f"),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
get value() {
|
|
67
|
-
return __classPrivateFieldGet(this, _FormField_value, "f");
|
|
68
|
-
}
|
|
69
|
-
set value(value) {
|
|
70
|
-
this.setValue(value);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Constructs a FormField instance with specified properties and parent form model.
|
|
74
|
-
* @param {Object} params - Construction parameters including the parent form model and field specifications.
|
|
75
|
-
*/
|
|
76
|
-
constructor({ parent, specs }) {
|
|
77
|
-
let { properties, disabled, ...props } = specs;
|
|
78
|
-
super({
|
|
79
|
-
...props,
|
|
80
|
-
properties: [
|
|
81
|
-
'name',
|
|
82
|
-
'type',
|
|
83
|
-
'placeholder',
|
|
84
|
-
'required',
|
|
85
|
-
'label',
|
|
86
|
-
'variant',
|
|
87
|
-
'options',
|
|
88
|
-
'className',
|
|
89
|
-
'checked',
|
|
90
|
-
'id',
|
|
91
|
-
'icon',
|
|
92
|
-
'hidden',
|
|
93
|
-
...properties,
|
|
94
|
-
],
|
|
95
|
-
});
|
|
96
|
-
_FormField_instances.add(this);
|
|
97
|
-
// The parent model, either FormModel or WrappedFormModel, containing this field.
|
|
98
|
-
_FormField_parent.set(this, void 0);
|
|
99
|
-
_FormField_NATIVE_ACTIONS.set(this, ['hide', 'disable', 'enable', 'show', 'reset']);
|
|
100
|
-
_FormField_EVENTS.set(this, ['onClick', 'onChange', 'onKeyup']);
|
|
101
|
-
_FormField_isReady.set(this, false);
|
|
102
|
-
// Can be a boolean or an object specifying dynamic disablingvas logic based on other fields' values.
|
|
103
|
-
_FormField_disabled.set(this, false);
|
|
104
|
-
// Field specifications including its type, validation rules, and other metadata.
|
|
105
|
-
_FormField_specs.set(this, void 0);
|
|
106
|
-
_FormField_value.set(this, void 0);
|
|
107
|
-
// Tracks other fields this field listens to for changes, enabling reactive behavior and allowing the cleanup of event listeners.
|
|
108
|
-
_FormField_listeningItems.set(this, new Map());
|
|
109
|
-
this.generateRandomNumber = () => {
|
|
110
|
-
return Math.floor(Math.random() * (1000000 - 10000 + 1)) + 10000;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Performs initial setup based on the field's specifications, setting up validation, default values, and any specified dynamic behavior.
|
|
114
|
-
*/
|
|
115
|
-
this.initialize = () => {
|
|
116
|
-
this.checkSettings(__classPrivateFieldGet(this, _FormField_specs, "f"));
|
|
117
|
-
this.on('change', this.listenerEvents);
|
|
118
|
-
// this.on('value.change', this.listenerEvents);
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Resets the field to its initial value and state, including resetting the disabled state if it's statically defined.
|
|
122
|
-
*/
|
|
123
|
-
this.clear = () => {
|
|
124
|
-
// Get initial values from specs or use empty object
|
|
125
|
-
const initValues = __classPrivateFieldGet(this, _FormField_specs, "f") || {};
|
|
126
|
-
this.set(initValues);
|
|
127
|
-
if (initValues.hasOwnProperty('disabled'))
|
|
128
|
-
this.disabled = initValues.disabled;
|
|
129
|
-
this.triggerEvent('clear');
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Listens to changes in sibling fields (specified in dynamic disabling logic) and updates its state accordingly.
|
|
133
|
-
*/
|
|
134
|
-
_FormField_listenSiblings.set(this, () => {
|
|
135
|
-
this.triggerEvent('change');
|
|
136
|
-
this.triggerEvent();
|
|
137
|
-
this.triggerEvent('value.change');
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* Metodo para identificar si es field con multiples eventos configurados o solo es un evento configurado
|
|
141
|
-
* hace la busqueda del evento lanzado al haber multiples
|
|
142
|
-
* @returns
|
|
143
|
-
*/
|
|
144
|
-
this.listenerEvents = (event2) => {
|
|
145
|
-
if (!__classPrivateFieldGet(this, _FormField_isReady, "f")) {
|
|
146
|
-
__classPrivateFieldSet(this, _FormField_isReady, true, "f");
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!this.specs?.events) {
|
|
150
|
-
const event = __classPrivateFieldGet(this, _FormField_instances, "m", _FormField_getEvent).call(this, this.specs);
|
|
151
|
-
if (!event)
|
|
152
|
-
return;
|
|
153
|
-
__classPrivateFieldGet(this, _FormField_instances, "m", _FormField_executeEvent).call(this, this.specs[event]);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const event = __classPrivateFieldGet(this, _FormField_instances, "m", _FormField_getEvent).call(this, this.specs.events);
|
|
157
|
-
if (!event)
|
|
158
|
-
return;
|
|
159
|
-
const item = this.specs.events[event].hasOwnProperty(this.value)
|
|
160
|
-
? this.specs.events[event][this.value]
|
|
161
|
-
: null;
|
|
162
|
-
if (!item)
|
|
163
|
-
return;
|
|
164
|
-
__classPrivateFieldGet(this, _FormField_instances, "m", _FormField_executeEvent).call(this, item);
|
|
165
|
-
};
|
|
166
|
-
this.hide = () => {
|
|
167
|
-
const className = this.getProperties().className || '';
|
|
168
|
-
const isHidden = className.includes('hidden');
|
|
169
|
-
const cls = isHidden ? className : `${className} hidden`;
|
|
170
|
-
if (cls !== className)
|
|
171
|
-
this.set({ className: cls });
|
|
172
|
-
};
|
|
173
|
-
this.show = () => {
|
|
174
|
-
const className = this.getProperties().className || '';
|
|
175
|
-
const isHidden = className.includes('hidden');
|
|
176
|
-
const cls = isHidden
|
|
177
|
-
? className.replace(/\bhidden\b/g, '').trim()
|
|
178
|
-
: className;
|
|
179
|
-
if (cls !== className)
|
|
180
|
-
this.set({ className: cls });
|
|
181
|
-
};
|
|
182
|
-
this.evaluations = {
|
|
183
|
-
equal: (value, comparisonValue) => value == comparisonValue,
|
|
184
|
-
lower: (value, comparisonValue) => Number(value) < Number(comparisonValue),
|
|
185
|
-
upper: (value, comparisonValue) => Number(value) > Number(comparisonValue),
|
|
186
|
-
between: (value, [min, max]) => {
|
|
187
|
-
const numValue = Number(value);
|
|
188
|
-
return numValue >= Number(min) && numValue <= Number(max);
|
|
189
|
-
},
|
|
190
|
-
different: (value, comparisonValue) => value != comparisonValue,
|
|
191
|
-
hasValue: (value) => ![undefined, null, '', false].includes(value),
|
|
192
|
-
empty: (value) => [undefined, null, ''].includes(value),
|
|
193
|
-
lessOrEqual: (value, comparisonValue) => Number(value) <= Number(comparisonValue),
|
|
194
|
-
greaterOrEqual: (value, comparisonValue) => Number(value) >= Number(comparisonValue),
|
|
195
|
-
};
|
|
196
|
-
this.__instanceID = `${specs.name}.${this.generateRandomNumber()}`;
|
|
197
|
-
__classPrivateFieldSet(this, _FormField_specs, specs, "f");
|
|
198
|
-
__classPrivateFieldSet(this, _FormField_parent, parent, "f");
|
|
199
|
-
this.__instance = Math.random();
|
|
200
|
-
const toSet = {};
|
|
201
|
-
/**
|
|
202
|
-
* @todo: review this code
|
|
203
|
-
*/
|
|
204
|
-
Object.keys(props).forEach((key) => {
|
|
205
|
-
if (key === 'properties')
|
|
206
|
-
return;
|
|
207
|
-
if (typeof props[key] === 'string' &&
|
|
208
|
-
props[key]?.includes('state:')) {
|
|
209
|
-
const state = props[key].split('state:')[1];
|
|
210
|
-
if (state === 'create' && !__classPrivateFieldGet(this, _FormField_parent, "f").form.update) {
|
|
211
|
-
props[key] = true;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
toSet[key] = props[key];
|
|
215
|
-
});
|
|
216
|
-
// this.#disabled = disabled;
|
|
217
|
-
// this.set(toSet);
|
|
218
|
-
this.set(specs);
|
|
219
|
-
}
|
|
220
|
-
getProperties() {
|
|
221
|
-
const properties = super.getProperties();
|
|
222
|
-
return { ...properties, value: __classPrivateFieldGet(this, _FormField_value, "f") };
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* This method is used to set the value property of the field and fire the value.change event
|
|
226
|
-
*
|
|
227
|
-
* @param value
|
|
228
|
-
* @returns
|
|
229
|
-
*/
|
|
230
|
-
setValue(value) {
|
|
231
|
-
if (value === this.value)
|
|
232
|
-
return;
|
|
233
|
-
__classPrivateFieldSet(this, _FormField_value, value, "f");
|
|
234
|
-
this.trigger('change');
|
|
235
|
-
this.trigger('value.change', this);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Checks and applies the field's settings, particularly for dynamic disabling, establishing listeners on related fields as necessary.
|
|
239
|
-
* @param {Object} props - The field's properties and settings to check and apply.
|
|
240
|
-
*/
|
|
241
|
-
checkSettings(props) {
|
|
242
|
-
if (props.hasOwnProperty('disabled')) {
|
|
243
|
-
if (typeof props.disabled === 'boolean') {
|
|
244
|
-
__classPrivateFieldSet(this, _FormField_disabled, props.disabled, "f");
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (typeof props.disabled !== 'object') {
|
|
248
|
-
throw new Error(`The disabled property of the field ${props.name} must be a boolean or an object`);
|
|
249
|
-
}
|
|
250
|
-
if (!props.disabled.fields && !props.disabled.mode) {
|
|
251
|
-
throw new Error(`The disabled property of the field ${props.name} must have a fields property or a mode defined`);
|
|
252
|
-
}
|
|
253
|
-
if (props.disabled.mode) {
|
|
254
|
-
// posible modes : create, update;
|
|
255
|
-
__classPrivateFieldSet(this, _FormField_disabled, __classPrivateFieldGet(this, _FormField_parent, "f").form.mode === props.disabled.mode, "f");
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
let allValid;
|
|
259
|
-
props.disabled.fields.forEach((item) => {
|
|
260
|
-
const name = typeof item === 'string' ? item : item.name;
|
|
261
|
-
const instance = __classPrivateFieldGet(this, _FormField_parent, "f").form.getField(name);
|
|
262
|
-
allValid = instance;
|
|
263
|
-
if (!allValid)
|
|
264
|
-
return;
|
|
265
|
-
instance.on('change', __classPrivateFieldGet(this, _FormField_listenSiblings, "f"));
|
|
266
|
-
instance.on('value.change', __classPrivateFieldGet(this, _FormField_listenSiblings, "f"));
|
|
267
|
-
__classPrivateFieldGet(this, _FormField_listeningItems, "f").set(name, {
|
|
268
|
-
item: instance,
|
|
269
|
-
listener: __classPrivateFieldGet(this, _FormField_listenSiblings, "f"),
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
if (!allValid) {
|
|
273
|
-
const fieldName = this.getProperties().name || 'unknown';
|
|
274
|
-
throw new Error(`the field ${allValid} does not exist in the form ${__classPrivateFieldGet(this, _FormField_parent, "f").name}, field passed in invalid settings of field "${fieldName}"`);
|
|
275
|
-
}
|
|
276
|
-
__classPrivateFieldSet(this, _FormField_disabled, props.disabled, "f");
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Cleans up any established listeners and internal state when the field is removed or the form is reset, ensuring no memory leaks or stale data.
|
|
281
|
-
*/
|
|
282
|
-
cleanUp() {
|
|
283
|
-
__classPrivateFieldGet(this, _FormField_listeningItems, "f").forEach(({ item, listener }) => item.off('change', listener));
|
|
284
|
-
// todo: remove all events
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* The `set` method sets one or more properties on the model.
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
* This method overwrites the original reactiveModel set to pass the object as param
|
|
291
|
-
* when the change event is fired.
|
|
292
|
-
* Eventually this method will be removed and the original set method will be used, but
|
|
293
|
-
* it requires an upgrade in the reactive model package.
|
|
294
|
-
* @param {keyof ReactiveModelPublic<T>} property - The name of the property to set.
|
|
295
|
-
* @param {*} value - The value to set the property to.
|
|
296
|
-
* @returns {void}
|
|
297
|
-
*/
|
|
298
|
-
set(properties) {
|
|
299
|
-
let updated = false;
|
|
300
|
-
try {
|
|
301
|
-
Object.keys(properties).forEach((prop) => {
|
|
302
|
-
const currentProperties = Object.keys(this.getProperties());
|
|
303
|
-
// Verificar si la propiedad está registrada en el modelo reactivo
|
|
304
|
-
// Si no está en getProperties(), verificar si está en la lista de properties del constructor
|
|
305
|
-
const isRegisteredProperty = currentProperties.includes(prop) ||
|
|
306
|
-
(__classPrivateFieldGet(this, _FormField_specs, "f")?.properties &&
|
|
307
|
-
__classPrivateFieldGet(this, _FormField_specs, "f").properties.includes(prop));
|
|
308
|
-
if (!isRegisteredProperty) {
|
|
309
|
-
console.warn(`Property "${prop}" is not registered in field "${this.getProperties().name || 'unknown'}"`);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const newValue = properties[prop];
|
|
313
|
-
const currentValue = this[prop];
|
|
314
|
-
// Si los valores son iguales por referencia, no actualizar
|
|
315
|
-
if (currentValue === newValue)
|
|
316
|
-
return;
|
|
317
|
-
// Si el tipo cambia (array a string, string a array, etc.), siempre actualizar
|
|
318
|
-
const currentIsArray = Array.isArray(currentValue);
|
|
319
|
-
const newIsArray = Array.isArray(newValue);
|
|
320
|
-
const currentIsObject = typeof currentValue === 'object' &&
|
|
321
|
-
currentValue !== null &&
|
|
322
|
-
!currentIsArray;
|
|
323
|
-
const newIsObject = typeof newValue === 'object' &&
|
|
324
|
-
newValue !== null &&
|
|
325
|
-
!newIsArray;
|
|
326
|
-
if ((currentIsArray && !newIsArray) ||
|
|
327
|
-
(!currentIsArray && newIsArray) ||
|
|
328
|
-
(currentIsObject && !newIsObject) ||
|
|
329
|
-
(!currentIsObject && newIsObject)) {
|
|
330
|
-
this[prop] = newValue;
|
|
331
|
-
updated = true;
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
// Para arrays y objetos, hacer comparación más robusta
|
|
335
|
-
if (typeof newValue === 'object' && newValue !== null) {
|
|
336
|
-
// Si currentValue es undefined/null, siempre actualizar
|
|
337
|
-
if (currentValue === undefined || currentValue === null) {
|
|
338
|
-
this[prop] = newValue;
|
|
339
|
-
updated = true;
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
// Comparar arrays
|
|
343
|
-
if (newIsArray && currentIsArray) {
|
|
344
|
-
// Si las longitudes son diferentes, actualizar
|
|
345
|
-
if (newValue.length !== currentValue.length) {
|
|
346
|
-
this[prop] = newValue;
|
|
347
|
-
updated = true;
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
// Comparar contenido del array
|
|
351
|
-
const arraysEqual = newValue.every((val, idx) => {
|
|
352
|
-
if (typeof val === 'object' && val !== null) {
|
|
353
|
-
return (JSON.stringify(val) ===
|
|
354
|
-
JSON.stringify(currentValue[idx]));
|
|
355
|
-
}
|
|
356
|
-
return val === currentValue[idx];
|
|
357
|
-
});
|
|
358
|
-
if (arraysEqual)
|
|
359
|
-
return;
|
|
360
|
-
this[prop] = newValue;
|
|
361
|
-
updated = true;
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
// Para objetos, comparar con JSON.stringify pero manejar undefined
|
|
365
|
-
if (newIsObject && currentIsObject) {
|
|
366
|
-
try {
|
|
367
|
-
const currentStr = JSON.stringify(currentValue);
|
|
368
|
-
const newStr = JSON.stringify(newValue);
|
|
369
|
-
if (currentStr === newStr)
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
catch (e) {
|
|
373
|
-
// Si JSON.stringify falla (por ejemplo, con funciones), comparar por referencia
|
|
374
|
-
if (currentValue === newValue)
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
const descriptor = Object.getOwnPropertyDescriptor(this, prop);
|
|
380
|
-
if (descriptor?.set)
|
|
381
|
-
return;
|
|
382
|
-
this[prop] = newValue;
|
|
383
|
-
updated = true;
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
catch (e) {
|
|
387
|
-
console.error(`Error setting properties:`, e);
|
|
388
|
-
throw new Error(`Error setting properties: ${e}`);
|
|
389
|
-
}
|
|
390
|
-
finally {
|
|
391
|
-
if (updated)
|
|
392
|
-
this.trigger('change', this);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
_FormField_parent = new WeakMap(), _FormField_NATIVE_ACTIONS = new WeakMap(), _FormField_EVENTS = new WeakMap(), _FormField_isReady = new WeakMap(), _FormField_disabled = new WeakMap(), _FormField_specs = new WeakMap(), _FormField_value = new WeakMap(), _FormField_listeningItems = new WeakMap(), _FormField_listenSiblings = new WeakMap(), _FormField_instances = new WeakSet(), _FormField_executeEvent =
|
|
397
|
-
/**
|
|
398
|
-
* En este metodo se recorre el objeto asociado al evento y ejecuta cada una de las acciones asociadas
|
|
399
|
-
* como las acciones nativas del FormModel (HIDE, SHOW, DISABLE, ENABLE), hace el seteo de propiedades
|
|
400
|
-
* en caso de recibir field y ejecuta las callbacks asociadas
|
|
401
|
-
* @param actions objeto con las acciones que se van a realizar al ejecutarse el evento asociado
|
|
402
|
-
* @returns
|
|
403
|
-
*/
|
|
404
|
-
async function _FormField_executeEvent(actions) {
|
|
405
|
-
if (typeof actions !== 'object' || Array.isArray(actions))
|
|
406
|
-
return;
|
|
407
|
-
const formModel = __classPrivateFieldGet(this, _FormField_parent, "f").form;
|
|
408
|
-
const sortedKeys = Object.keys(actions).sort((a, b) => actions[a]?.__order - actions[b]?.__order);
|
|
409
|
-
for (let action of sortedKeys) {
|
|
410
|
-
if (action === 'fields') {
|
|
411
|
-
for (let fieldName in actions[action]) {
|
|
412
|
-
const field = __classPrivateFieldGet(this, _FormField_parent, "f").form.getField(fieldName);
|
|
413
|
-
if (!field)
|
|
414
|
-
continue;
|
|
415
|
-
await field.isReady;
|
|
416
|
-
field.set(actions[action][fieldName]);
|
|
417
|
-
}
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
if (formModel.callbacks.hasOwnProperty(action)) {
|
|
421
|
-
formModel.callbacks[action]({
|
|
422
|
-
...actions[action],
|
|
423
|
-
form: formModel,
|
|
424
|
-
});
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
if (__classPrivateFieldGet(this, _FormField_NATIVE_ACTIONS, "f").includes(action) &&
|
|
428
|
-
formModel.hasOwnProperty(action)) {
|
|
429
|
-
formModel[action](actions[action].target);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}, _FormField_getEvent = function _FormField_getEvent(item) {
|
|
433
|
-
let event;
|
|
434
|
-
const keys = Object.keys(item);
|
|
435
|
-
keys.forEach((key) => {
|
|
436
|
-
if (event)
|
|
437
|
-
return;
|
|
438
|
-
if (__classPrivateFieldGet(this, _FormField_EVENTS, "f").includes(key))
|
|
439
|
-
event = key;
|
|
440
|
-
});
|
|
441
|
-
return event;
|
|
442
|
-
};
|
|
443
|
-
//# sourceMappingURL=field.js.map
|