native-document 1.0.76 → 1.0.77

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 (184) hide show
  1. package/components.js +26 -1
  2. package/dist/native-document.components.min.js +6360 -1925
  3. package/dist/native-document.dev.js +122 -56
  4. package/dist/native-document.dev.js.map +1 -1
  5. package/dist/native-document.devtools.min.js +1 -1
  6. package/dist/native-document.min.js +1 -1
  7. package/jsconfig.json +15 -0
  8. package/package.json +1 -1
  9. package/rollup.config.js +4 -2
  10. package/src/components/$traits/HasItems.js +38 -0
  11. package/src/components/BaseComponent.js +70 -0
  12. package/src/components/accordion/Accordion.js +133 -0
  13. package/src/components/accordion/AccordionItem.js +119 -0
  14. package/src/components/accordion/index.js +7 -0
  15. package/src/components/alert/Alert.js +155 -0
  16. package/src/components/alert/index.js +6 -0
  17. package/src/components/avatar/Avatar.js +178 -0
  18. package/src/components/avatar/index.js +5 -0
  19. package/src/components/badge/Badge.js +103 -0
  20. package/src/components/badge/index.js +6 -0
  21. package/src/components/breadcrumb/BreadCrumb.js +70 -0
  22. package/src/components/breadcrumb/index.js +5 -0
  23. package/src/components/button/Button.js +174 -0
  24. package/src/components/button/index.js +5 -0
  25. package/src/components/card/Card.js +110 -0
  26. package/src/components/card/index.js +5 -0
  27. package/src/components/context-menu/ContextMenu.js +60 -0
  28. package/src/components/context-menu/ContextMenuGroup.js +16 -0
  29. package/src/components/context-menu/ContextMenuItem.js +16 -0
  30. package/src/components/context-menu/index.js +10 -0
  31. package/src/components/divider/Divider.js +126 -0
  32. package/src/components/divider/index.js +6 -0
  33. package/src/components/dropdown/Dropdown.js +170 -0
  34. package/src/components/dropdown/DropdownDivider.js +24 -0
  35. package/src/components/dropdown/DropdownGroup.js +44 -0
  36. package/src/components/dropdown/DropdownItem.js +71 -0
  37. package/src/components/dropdown/DropdownTrigger.js +64 -0
  38. package/src/components/dropdown/index.js +13 -0
  39. package/src/components/{fom-control → form}/FormControl.js +30 -22
  40. package/src/components/{fom-control → form}/field/DefaultRender.js +2 -16
  41. package/src/components/{fom-control → form}/field/Field.js +67 -140
  42. package/src/components/{fom-control → form}/field/FieldCollection.js +42 -22
  43. package/src/components/{fom-control → form}/field/types/AutocompleteField.js +11 -0
  44. package/src/components/form/field/types/CheckboxField.js +36 -0
  45. package/src/components/{fom-control → form}/field/types/CheckboxGroupField.js +10 -0
  46. package/src/components/{fom-control → form}/field/types/ColorField.js +11 -1
  47. package/src/components/{fom-control → form}/field/types/DateField.js +11 -1
  48. package/src/components/{fom-control → form}/field/types/EmailField.js +11 -1
  49. package/src/components/{fom-control → form}/field/types/FileField.js +11 -1
  50. package/src/components/form/field/types/HiddenField.js +18 -0
  51. package/src/components/{fom-control → form}/field/types/ImageField.js +11 -1
  52. package/src/components/{fom-control → form}/field/types/NumberField.js +11 -1
  53. package/src/components/{fom-control → form}/field/types/PasswordField.js +11 -1
  54. package/src/components/{fom-control → form}/field/types/RadioField.js +28 -2
  55. package/src/components/{fom-control → form}/field/types/RangeField.js +10 -0
  56. package/src/components/{fom-control → form}/field/types/SearchField.js +10 -0
  57. package/src/components/{fom-control → form}/field/types/SelectField.js +10 -0
  58. package/src/components/{fom-control → form}/field/types/StringField.js +11 -1
  59. package/src/components/{fom-control → form}/field/types/TelField.js +11 -2
  60. package/src/components/{fom-control → form}/field/types/TextAreaField.js +10 -0
  61. package/src/components/{fom-control → form}/field/types/TimeField.js +11 -2
  62. package/src/components/{fom-control → form}/field/types/UrlField.js +10 -2
  63. package/src/components/form/index.js +49 -0
  64. package/src/components/{fom-control → form}/validation/Validation.js +1 -1
  65. package/src/components/list/List.js +106 -0
  66. package/src/components/list/ListGroup.js +67 -0
  67. package/src/components/list/ListItem.js +103 -0
  68. package/src/components/list/index.js +10 -0
  69. package/src/components/menu/Menu.js +82 -0
  70. package/src/components/menu/MenuDivider.js +22 -0
  71. package/src/components/menu/MenuGroup.js +42 -0
  72. package/src/components/menu/MenuItem.js +71 -0
  73. package/src/components/menu/index.js +13 -0
  74. package/src/components/modal/Modal.js +153 -0
  75. package/src/components/modal/index.js +5 -0
  76. package/src/components/pagination/Pagination.js +229 -0
  77. package/src/components/pagination/index.js +5 -0
  78. package/src/components/popover/Popover.js +185 -0
  79. package/src/components/popover/PopoverFooter.js +37 -0
  80. package/src/components/popover/PopoverHeader.js +43 -0
  81. package/src/components/popover/index.js +10 -0
  82. package/src/components/progress/Progress.js +220 -0
  83. package/src/components/progress/index.js +6 -0
  84. package/src/components/skeleton/Skeleton.js +98 -0
  85. package/src/components/skeleton/SkeletonCard.js +0 -0
  86. package/src/components/skeleton/SkeletonList.js +0 -0
  87. package/src/components/skeleton/SkeletonParagraph.js +0 -0
  88. package/src/components/skeleton/SkeletonTable.js +0 -0
  89. package/src/components/skeleton/index.js +6 -0
  90. package/src/components/slider/Slider.js +183 -0
  91. package/src/components/slider/index.js +5 -0
  92. package/src/components/spinner/Spinner.js +160 -0
  93. package/src/components/spinner/index.js +5 -0
  94. package/src/components/splitter/Splitter.js +95 -0
  95. package/src/components/splitter/SplitterGutter.js +57 -0
  96. package/src/components/splitter/SplitterPanel.js +82 -0
  97. package/src/components/splitter/index.js +8 -0
  98. package/src/components/stepper/Stepper.js +229 -0
  99. package/src/components/stepper/StepperStep.js +103 -0
  100. package/src/components/stepper/index.js +8 -0
  101. package/src/components/switch/Switch.js +99 -0
  102. package/src/components/switch/index.js +0 -0
  103. package/src/components/table/ColumnGroup.js +1 -1
  104. package/src/components/table/DataTable.js +1 -1
  105. package/src/components/table/SimpleTable.js +36 -32
  106. package/src/components/tabs/Tabs.js +110 -0
  107. package/src/components/tabs/index.js +6 -0
  108. package/src/components/toast/Toast.js +129 -0
  109. package/src/components/toast/ToastError.js +0 -0
  110. package/src/components/toast/ToastInfo.js +0 -0
  111. package/src/components/toast/ToastSuccess.js +0 -0
  112. package/src/components/toast/ToastWarning.js +0 -0
  113. package/src/components/toast/index.js +5 -0
  114. package/src/components/tooltip/Tooltip.js +98 -0
  115. package/src/components/tooltip/index.js +5 -0
  116. package/src/components/tooltip/prototypes.js +6 -0
  117. package/src/core/data/MemoryManager.js +2 -2
  118. package/src/core/data/Observable.js +1 -1
  119. package/src/core/data/ObservableArray.js +14 -8
  120. package/src/core/data/ObservableItem.js +5 -5
  121. package/src/core/data/observable-helpers/array.js +2 -2
  122. package/src/core/data/observable-helpers/batch.js +2 -2
  123. package/src/core/data/observable-helpers/computed.js +6 -6
  124. package/src/core/data/observable-helpers/object.js +2 -2
  125. package/src/core/elements/anchor.js +3 -3
  126. package/src/core/elements/content-formatter.js +1 -1
  127. package/src/core/elements/control/for-each-array.js +42 -68
  128. package/src/core/elements/control/for-each.js +7 -7
  129. package/src/core/elements/control/show-if.js +5 -5
  130. package/src/core/elements/control/show-when.js +2 -2
  131. package/src/core/elements/control/switch.js +4 -4
  132. package/src/core/elements/description-list.js +1 -1
  133. package/src/core/elements/form.js +1 -1
  134. package/src/core/elements/html5-semantics.js +1 -1
  135. package/src/core/elements/img.js +3 -3
  136. package/src/core/elements/index.js +1 -1
  137. package/src/core/elements/interactive.js +1 -1
  138. package/src/core/elements/list.js +1 -1
  139. package/src/core/elements/medias.js +1 -1
  140. package/src/core/elements/meta-data.js +1 -1
  141. package/src/core/elements/table.js +1 -1
  142. package/src/core/utils/EventEmitter.js +1 -1
  143. package/src/core/utils/args-types.js +2 -2
  144. package/src/core/utils/events.js +68 -0
  145. package/src/core/utils/filters/standard.js +1 -1
  146. package/src/core/utils/filters/utils.js +1 -1
  147. package/src/core/utils/helpers.js +10 -7
  148. package/src/core/utils/prototypes.js +2 -2
  149. package/src/core/utils/validator.js +6 -5
  150. package/src/core/wrappers/AttributesWrapper.js +21 -38
  151. package/src/core/wrappers/DocumentObserver.js +1 -1
  152. package/src/core/wrappers/ElementCreator.js +9 -14
  153. package/src/core/wrappers/HtmlElementWrapper.js +2 -2
  154. package/src/core/wrappers/NDElement.js +3 -3
  155. package/src/core/wrappers/NdPrototype.js +24 -31
  156. package/src/core/wrappers/SingletonView.js +1 -1
  157. package/src/core/wrappers/TemplateCloner.js +60 -18
  158. package/src/core/wrappers/constants.js +32 -1
  159. package/src/core/wrappers/prototypes/attributes-extensions.js +18 -5
  160. package/src/core/wrappers/prototypes/bind-class-extensions.js +18 -0
  161. package/src/core/wrappers/prototypes/nd-element-extensions.js +6 -6
  162. package/src/devtools/app/App.js +2 -2
  163. package/src/devtools/hrm/ComponentRegistry.js +2 -2
  164. package/src/devtools/plugin.js +1 -1
  165. package/src/devtools/widget/DevToolsWidget.js +2 -2
  166. package/src/router/Route.js +1 -1
  167. package/src/router/RouteGroupHelper.js +1 -1
  168. package/src/router/Router.js +4 -4
  169. package/src/router/RouterComponent.js +1 -1
  170. package/src/router/link.js +3 -3
  171. package/src/router/modes/HistoryRouter.js +1 -2
  172. package/types/filters/dates.d.ts +1 -1
  173. package/types/filters/standard.d.ts +0 -1
  174. package/types/filters/types.d.ts +1 -1
  175. package/utils.js +3 -3
  176. package/src/components/fom-control/default/DefaultLayout.js +0 -8
  177. package/src/components/fom-control/default/collection/DefaultCollectionLayout.js +0 -12
  178. package/src/components/fom-control/default/collection/DefaultCollectionTemplate.js +0 -6
  179. package/src/components/fom-control/field/types/CheckboxField.js +0 -17
  180. package/src/components/fom-control/field/types/HiddenField.js +0 -8
  181. package/src/components/fom-control/index.js +0 -8
  182. /package/src/components/{fom-control → form}/field/FieldFactory.js +0 -0
  183. /package/src/components/{fom-control → form}/merge +0 -0
  184. /package/src/components/{fom-control → form}/utils.js +0 -0
@@ -1,11 +1,12 @@
1
- import {Validation} from "../validation/Validation";
2
- import DefaultRender from "./DefaultRender";
3
- import {Validator} from "../../../../index";
4
- import {ShowIf} from "../../../../elements";
5
- import {resolveParams} from "../utils";
1
+ import {Validation} from "@components/form/validation/Validation";
2
+ import {Validator} from "@core";
3
+ import {resolveParams} from "@components/form/utils";
4
+ import BaseComponent from "@components/BaseComponent";
6
5
 
7
6
  export default function Field(name, type, defaultConfig) {
8
7
 
8
+ BaseComponent.call(this);
9
+
9
10
  this.$description = {
10
11
  name: name,
11
12
  type: type,
@@ -34,6 +35,7 @@ export default function Field(name, type, defaultConfig) {
34
35
  hint: null
35
36
  },
36
37
  events: {},
38
+ render: null,
37
39
  ...defaultConfig
38
40
  };
39
41
 
@@ -44,26 +46,29 @@ export default function Field(name, type, defaultConfig) {
44
46
 
45
47
  Field.renderers = {};
46
48
 
47
- Field.defaultRenderer = DefaultRender;
49
+ Field.defaultTemplate = null;
48
50
 
51
+ BaseComponent.extends(Field);
49
52
 
53
+ Field.use = function(template) {
54
+ Field.defaultTemplate = template.field;
55
+ };
50
56
 
51
57
  // ---------------------------------------------
52
58
  // COMMON METHODS
53
59
  // ---------------------------------------------
54
- Object.defineProperty( Field.prototype, 'nd', {
55
- get: function() {
56
- return this.field().nd;
57
- }
58
- });
59
60
 
60
- Field.prototype.id = function(value) {
61
- this.$description.id = value;
61
+ Field.prototype.$model = function() {
62
+ return this.$description.value || this.$description.checked;
63
+ };
64
+
65
+ Field.prototype.id = function(id) {
66
+ this.$description.id = id;
62
67
  return this;
63
68
  };
64
69
 
65
- Field.prototype.suffix = function(value) {
66
- this.$description.suffix = value;
70
+ Field.prototype.suffix = function(suffix) {
71
+ this.$description.suffix = suffix;
67
72
  return this;
68
73
  };
69
74
 
@@ -73,6 +78,7 @@ Field.prototype.field = function() {
73
78
  }
74
79
  return this.$element;
75
80
  };
81
+ Field.prototype.node = Field.prototype.field;
76
82
 
77
83
  Field.prototype.input = function(callback) {
78
84
  if(!this.$input) {
@@ -82,36 +88,6 @@ Field.prototype.input = function(callback) {
82
88
  return this;
83
89
  };
84
90
 
85
- Field.prototype.render = function(customRenderer) {
86
- if (typeof customRenderer !== 'function') {
87
- throw new Error('Custom renderer must be a function');
88
- }
89
-
90
- this.$description.customRenderer = customRenderer;
91
- return this;
92
- };
93
-
94
- Field.registerRenderer = function(type, renderer) {
95
- if (typeof renderer !== 'function') {
96
- throw new Error(`Renderer for type "${type}" must be a function`);
97
- }
98
-
99
- Field.renderers[type] = renderer;
100
- };
101
-
102
- Field.prototype.getRenderer = function() {
103
- if (this.$description.customRenderer) {
104
- return this.$description.customRenderer;
105
- }
106
-
107
- const typeRenderer = Field.renderers[this.$description.type];
108
- if (typeRenderer) {
109
- return typeRenderer;
110
- }
111
-
112
- return Field.defaultRenderer;
113
- };
114
-
115
91
  Field.prototype.showErrors = function(show = true) {
116
92
  this.$description.showErrors = show;
117
93
  return this;
@@ -122,8 +98,8 @@ Field.prototype.hideErrors = function() {
122
98
  return this;
123
99
  };
124
100
 
125
- Field.prototype.value = function(value) {
126
- this.$description.value = value;
101
+ Field.prototype.model = function(observable) {
102
+ this.$description.value = observable;
127
103
  return this;
128
104
  };
129
105
 
@@ -150,8 +126,8 @@ Field.prototype.key = function(keyInData) {
150
126
  return this;
151
127
  };
152
128
 
153
- Field.prototype.default = function(value) {
154
- this.$description.defaultValue = value;
129
+ Field.prototype.default = function(defaultValue) {
130
+ this.$description.defaultValue = defaultValue;
155
131
  return this;
156
132
  };
157
133
 
@@ -175,13 +151,13 @@ Field.prototype.placeholder = function(text) {
175
151
  return this;
176
152
  };
177
153
 
178
- Field.prototype.disabled = function(value) {
179
- this.$description.disabled = value;
154
+ Field.prototype.disabled = function(disabled) {
155
+ this.$description.disabled = disabled;
180
156
  return this;
181
157
  };
182
158
 
183
- Field.prototype.readonly = function(value) {
184
- this.$description.readonly = value;
159
+ Field.prototype.readonly = function(readonly) {
160
+ this.$description.readonly = readonly;
185
161
  return this;
186
162
  };
187
163
 
@@ -230,11 +206,21 @@ Field.prototype.addRule = function(validationFn, params, message) {
230
206
  return this;
231
207
  };
232
208
 
233
- Field.prototype.getValue = function() {
234
- const value = this.$description.value || this.$description.checked;
209
+ Field.prototype.value = function() {
210
+ const value = this.$model();
235
211
  return Validator.isObservable(value) ? value.val() : value;
236
212
  };
237
213
 
214
+ Field.prototype.setValue = function(newValue) {
215
+ const value = this.$model();
216
+ if(Validator.isObservable(value)) {
217
+ value.set(newValue);
218
+ return this;
219
+ }
220
+ this.$description.value = value;
221
+ return this;
222
+ };
223
+
238
224
  Field.prototype.validate = function(allValues = {}) {
239
225
  if (!this.$description.rules || this.$description.rules.length === 0) {
240
226
  this.$description.errors?.set(null);
@@ -242,7 +228,7 @@ Field.prototype.validate = function(allValues = {}) {
242
228
  }
243
229
 
244
230
  const errors = [];
245
- const value = this.getValue();
231
+ const value = this.value();
246
232
 
247
233
  for (const rule of this.$description.rules) {
248
234
  const paramsResolved = resolveParams(rule, allValues);
@@ -298,99 +284,40 @@ Field.prototype.hintClass = function(hintClass) {
298
284
  return this;
299
285
  };
300
286
 
301
- Field.prototype.toNdElement = function() {
302
- if(this.$element) {
303
- return this.$element;
304
- }
305
- const renderer = this.getRenderer();
306
- this.$element = renderer(this);
307
-
308
- if(this.$description.showIf) {
309
- ShowIf(this.$description.showIf, this.$element);
287
+ Field.prototype.render = function(renderFn) {
288
+ if (typeof renderFn !== 'function') {
289
+ throw new Error('Custom renderer must be a function');
310
290
  }
311
291
 
312
- return this.$element;
313
- };
314
-
315
- // ---------------------------------------------
316
- // Events METHODS
317
- // ---------------------------------------------
318
- Field.prototype.onChange = function(callback) {
319
- this.$description.events['change'] = callback;
320
- return this;
321
- };
322
-
323
- Field.prototype.onInput = function(callback) {
324
- this.$description.events['input'] = callback;
292
+ this.$description.render = renderFn;
325
293
  return this;
326
294
  };
327
295
 
328
- Field.prototype.onFocus = function(callback) {
329
- this.$description.events['focus'] = callback;
330
- return this;
331
- };
332
-
333
- Field.prototype.onBlur = function(callback) {
334
- this.$description.events['blur'] = callback;
335
- return this;
336
- };
337
-
338
-
339
- Field.prototype.onKeydown = function(callback) {
340
- this.$description.events['keydown'] = callback;
341
- return this;
342
- };
343
-
344
- Field.prototype.onKeyup = function(callback) {
345
- this.$description.events['keyup'] = callback;
346
- return this;
347
- };
348
-
349
- Field.prototype.onKeypress = function(callback) {
350
- this.$description.events['keypress'] = callback;
351
- return this;
352
- };
353
-
354
-
355
- Field.prototype.onPaste = function(callback) {
356
- this.$description.events['paste'] = callback;
357
- return this;
358
- };
359
-
360
- Field.prototype.onCut = function(callback) {
361
- this.$description.events['cut'] = callback;
362
- return this;
363
- };
364
-
365
- Field.prototype.onCopy = function(callback) {
366
- this.$description.events['copy'] = callback;
367
- return this;
368
- };
369
-
370
-
371
- Field.prototype.onFileSelect = function(callback) {
372
- this.$description.events['fileselect'] = callback;
373
- return this;
374
- };
296
+ Field.registerRenderer = function(type, renderer) {
297
+ if (typeof renderer !== 'function') {
298
+ throw new Error(`Renderer for type "${type}" must be a function`);
299
+ }
375
300
 
376
- Field.prototype.onDrop = function(callback) {
377
- this.$description.events['drop'] = callback;
378
- return this;
301
+ Field.renderers[type] = renderer;
379
302
  };
380
303
 
381
- Field.prototype.onDragover = function(callback) {
382
- this.$description.events['dragover'] = callback;
383
- return this;
384
- };
304
+ Field.prototype.getRenderer = function() {
305
+ if (this.$description.render) {
306
+ return this.$description.render;
307
+ }
385
308
 
309
+ const typeRenderer = Field.renderers[this.$description.type];
310
+ if (typeRenderer) {
311
+ return typeRenderer;
312
+ }
386
313
 
387
- // Autocomplete
388
- Field.prototype.onSearch = function(callback) {
389
- this.$description.events['search'] = callback;
390
- return this;
314
+ return this.constructor.defaultTemplate || Field.defaultTemplate;
391
315
  };
392
316
 
393
- Field.prototype.onSelect = function(callback) {
394
- this.$description.events['select'] = callback;
395
- return this;
396
- };
317
+ Field.prototype.$build = function() {
318
+ const renderer = this.getRenderer();
319
+ if(!renderer) {
320
+ return null;
321
+ }
322
+ return renderer(this);
323
+ };
@@ -1,12 +1,13 @@
1
- import { Observable as $, Validator } from "../../../../index";
2
- import { Button } from "../../../../elements";
3
- import NativeDocumentError from "../../../core/errors/NativeDocumentError";
4
- import {Validation} from "../validation/Validation";
5
- import DefaultCollectionLayout from "../default/collection/DefaultCollectionLayout";
6
- import DefaultCollectionTemplate from "../default/collection/DefaultCollectionTemplate";
7
- import {resolveParams} from "../utils";
1
+ import { Observable as $, Validator } from "@core";
2
+ import NativeDocumentError from "@src/core/errors/NativeDocumentError";
3
+ import {Validation} from "@components/form/validation/Validation";
4
+ import {resolveParams} from "@components/form/utils";
5
+ import BaseComponent from "@components/BaseComponent";
8
6
 
9
7
  export default function FieldCollection(name, config) {
8
+ if(!(this instanceof FieldCollection)) {
9
+ return new FieldCollection(name, config);
10
+ }
10
11
  this.$description = {
11
12
  name: name,
12
13
  defaultItem: null,
@@ -14,8 +15,8 @@ export default function FieldCollection(name, config) {
14
15
  ? config.data
15
16
  : $.array(config?.data || []),
16
17
  rules: null,
17
- layout: DefaultCollectionLayout,
18
- template: DefaultCollectionTemplate,
18
+ layout: null,
19
+ template: null,
19
20
  ...config
20
21
  };
21
22
 
@@ -23,18 +24,34 @@ export default function FieldCollection(name, config) {
23
24
  this.$currentRefId = 0;
24
25
  }
25
26
 
27
+ BaseComponent.extends(FieldCollection);
28
+
29
+ FieldCollection.defaultLayoutTemplate = null;
30
+ FieldCollection.defaultTemplate = null;
31
+
32
+ FieldCollection.use = function(template) {
33
+ FieldCollection.defaultTemplate = template.fieldCollection;
34
+ FieldCollection.defaultLayoutTemplate = template.fieldCollectionLayout;
35
+ };
36
+
26
37
 
27
38
  const setFieldValue = (field, name, proxyData) => {
28
- const value = field.$description.value || field.$description.checked;
39
+ const value = field.$model();
29
40
 
41
+ const data = proxyData[name];
30
42
  if(value != null) {
43
+ value.set(data);
44
+ return;
45
+ }
46
+ if(Validator.isObservable(data)) {
47
+ field.model(data);
31
48
  return;
32
49
  }
33
50
  if(typeof field.checked === 'function') {
34
- field.checked(proxyData[name]);
51
+ field.checked(data);
35
52
  return;
36
53
  }
37
- field.value(proxyData[name]);
54
+ field.value(data);
38
55
  };
39
56
 
40
57
  Object.defineProperty(FieldCollection.prototype, 'items', {
@@ -137,19 +154,19 @@ FieldCollection.prototype.clear = function() {
137
154
  this.$description.value.clear();
138
155
  };
139
156
 
140
- FieldCollection.prototype.value = function(value) {
141
- if(Validator.isObservable(value)) {
157
+ FieldCollection.prototype.model = function(newValue) {
158
+ if(Validator.isObservable(newValue)) {
142
159
  this.$description.value?.cleanup?.();
143
- this.$description.value = value;
160
+ this.$description.value = newValue;
144
161
  return this;
145
162
  }
146
- this.$description.value.set(value);
163
+ this.$description.value.set(newValue);
147
164
  return this;
148
165
  };
149
166
 
150
- FieldCollection.prototype.getValue = function() {
167
+ FieldCollection.prototype.value = function() {
151
168
  return this.$description.value.map((item) => {
152
- return typeof item?.val === 'function' ? item.val() : item;
169
+ return Validator.isObservable(item) ? item.val() : item;
153
170
  });
154
171
  };
155
172
 
@@ -247,14 +264,17 @@ FieldCollection.prototype.layout = function(layout) {
247
264
  };
248
265
 
249
266
 
250
- FieldCollection.prototype.toNdElement = function() {
251
- if (!this.$description.layout) {
267
+ FieldCollection.prototype.$build = function() {
268
+ const layout = this.$description.layout || FieldCollection.defaultLayoutTemplate;
269
+ if (!layout) {
252
270
  throw new NativeDocumentError(`Layout not defined for collection "${this.$description.name}"`);
253
271
  }
254
272
 
255
- return this.$description.layout({
273
+ const template = this.$description.template || FieldCollection.defaultTemplate;
274
+
275
+ return layout({
256
276
  collection: this,
257
277
  data: this.$description.value,
258
- Template: this.$description.template ? this.$description.template.bind(this) : null
278
+ Template: template ? template.bind(this) : null
259
279
  });
260
280
  };
@@ -1,6 +1,10 @@
1
1
  import StringField from "./StringField";
2
2
 
3
3
  export default function AutocompleteField(name, defaultConfig) {
4
+ if(!(this instanceof AutocompleteField)) {
5
+ return new AutocompleteField(name, defaultConfig);
6
+ }
7
+
4
8
  StringField.call(this, name, 'autocomplete', defaultConfig);
5
9
 
6
10
  Object.assign(this.$description, {
@@ -11,6 +15,13 @@ export default function AutocompleteField(name, defaultConfig) {
11
15
  });
12
16
  }
13
17
 
18
+ AutocompleteField.defaultTemplate = null;
19
+
20
+ AutocompleteField.use = function(template) {
21
+ AutocompleteField.defaultTemplate = template.autoCompleteField;
22
+ };
23
+
24
+
14
25
  AutocompleteField.prototype = Object.create(StringField.prototype);
15
26
  AutocompleteField.prototype.constructor = AutocompleteField;
16
27
 
@@ -0,0 +1,36 @@
1
+ import Field from "../Field";
2
+ import {Validator} from "@core";
3
+
4
+ export default function CheckboxField(name, defaultConfig) {
5
+ if(!(this instanceof CheckboxField)) {
6
+ return new CheckboxField(name, defaultConfig);
7
+ }
8
+
9
+ Field.call(this, name, 'checkbox', defaultConfig);
10
+
11
+ Object.assign(this.$description, {
12
+ checked: false,
13
+ });
14
+ }
15
+
16
+ CheckboxField.defaultTemplate = null;
17
+
18
+ CheckboxField.use = function(template) {
19
+ CheckboxField.defaultTemplate = template.checkboxField;
20
+ };
21
+
22
+ CheckboxField.prototype = Object.create(Field.prototype);
23
+ CheckboxField.prototype.constructor = CheckboxField;
24
+
25
+ CheckboxField.prototype.model = function(observable) {
26
+ this.$description.checked = observable;
27
+ return this;
28
+ };
29
+
30
+ CheckboxField.prototype.checked = function() {
31
+ const checked = this.$description.checked;
32
+ if(Validator.isObservable(checked)) {
33
+ return checked.val();
34
+ }
35
+ return checked;
36
+ };
@@ -1,6 +1,10 @@
1
1
  import Field from "../Field";
2
2
 
3
3
  export default function CheckboxGroupField(name, options, defaultConfig) {
4
+ if(!(this instanceof CheckboxGroupField)) {
5
+ return new CheckboxGroupField(name, defaultConfig);
6
+ }
7
+
4
8
  Field.call(this, name, 'checkbox-group', defaultConfig);
5
9
 
6
10
  Object.assign(this.$description, {
@@ -10,6 +14,12 @@ export default function CheckboxGroupField(name, options, defaultConfig) {
10
14
  });
11
15
  }
12
16
 
17
+ CheckboxGroupField.defaultTemplate = null;
18
+
19
+ CheckboxGroupField.use = function(template) {
20
+ CheckboxGroupField.defaultTemplate = template.checkboxGroupField;
21
+ };
22
+
13
23
  CheckboxGroupField.prototype = Object.create(Field.prototype);
14
24
  CheckboxGroupField.prototype.constructor = CheckboxGroupField;
15
25
 
@@ -1,8 +1,12 @@
1
1
  // ColorField.js
2
2
  import Field from "../Field";
3
- import {Validation} from "../../validation/Validation";
3
+ import {Validation} from "@components/form/validation/Validation";
4
4
 
5
5
  export default function ColorField(name, defaultConfig) {
6
+ if(!(this instanceof ColorField)) {
7
+ return new ColorField(name, defaultConfig);
8
+ }
9
+
6
10
  Field.call(this, name, 'color', defaultConfig);
7
11
 
8
12
  Object.assign(this.$description, {
@@ -11,6 +15,12 @@ export default function ColorField(name, defaultConfig) {
11
15
  });
12
16
  }
13
17
 
18
+ ColorField.defaultTemplate = null;
19
+
20
+ ColorField.use = function(template) {
21
+ ColorField.defaultTemplate = template.colorField;
22
+ };
23
+
14
24
  ColorField.prototype = Object.create(Field.prototype);
15
25
  ColorField.prototype.constructor = ColorField;
16
26
 
@@ -1,7 +1,11 @@
1
1
  import Field from "../Field";
2
- import {Validation} from "../../validation/Validation";
2
+ import {Validation} from "@components/form/validation/Validation";
3
3
 
4
4
  export default function DateField(name, defaultConfig) {
5
+ if(!(this instanceof DateField)) {
6
+ return new DateField(name, defaultConfig);
7
+ }
8
+
5
9
  Field.call(this, name, 'date', defaultConfig);
6
10
 
7
11
  Object.assign(this.$description, {
@@ -13,6 +17,12 @@ export default function DateField(name, defaultConfig) {
13
17
  });
14
18
  }
15
19
 
20
+ DateField.defaultTemplate = null;
21
+
22
+ DateField.use = function(template) {
23
+ DateField.defaultTemplate = template.dateField;
24
+ };
25
+
16
26
  DateField.prototype = Object.create(Field.prototype);
17
27
  DateField.prototype.constructor = DateField;
18
28
 
@@ -1,13 +1,23 @@
1
1
  import Field from "../Field";
2
- import {Validation} from "../../validation/Validation";
2
+ import {Validation} from "@components/form/validation/Validation";
3
3
 
4
4
  export default function EmailField(name, defaultConfig) {
5
+ if(!(this instanceof EmailField)) {
6
+ return new EmailField(name, defaultConfig);
7
+ }
8
+
5
9
  Field.call(this, name, 'email', defaultConfig);
6
10
 
7
11
  // Auto-apply email validation
8
12
  this.addRule(Validation.email, []);
9
13
  }
10
14
 
15
+ EmailField.defaultTemplate = null;
16
+
17
+ EmailField.use = function(template) {
18
+ EmailField.defaultTemplate = template.emailField;
19
+ };
20
+
11
21
  EmailField.prototype = Object.create(Field.prototype);
12
22
  EmailField.prototype.constructor = EmailField;
13
23
 
@@ -1,7 +1,11 @@
1
1
  import Field from "../Field";
2
- import {Validation} from "../../validation/Validation";
2
+ import {Validation} from "@components/form/validation/Validation";
3
3
 
4
4
  export default function FileField(name, type = 'file', defaultConfig = {}) {
5
+ if(!(this instanceof FileField)) {
6
+ return new FileField(name, defaultConfig);
7
+ }
8
+
5
9
  Field.call(this, name, type, defaultConfig);
6
10
 
7
11
  Object.assign(this.$description, {
@@ -13,6 +17,12 @@ export default function FileField(name, type = 'file', defaultConfig = {}) {
13
17
  });
14
18
  }
15
19
 
20
+ FileField.defaultTemplate = null;
21
+
22
+ FileField.use = function(template) {
23
+ FileField.defaultTemplate = template.fileField;
24
+ };
25
+
16
26
  FileField.prototype = Object.create(Field.prototype);
17
27
  FileField.prototype.constructor = FileField;
18
28
 
@@ -0,0 +1,18 @@
1
+ import Field from "../Field";
2
+
3
+ export default function HiddenField(name, defaultConfig) {
4
+ if(!(this instanceof HiddenField)) {
5
+ return new HiddenField(name, defaultConfig);
6
+ }
7
+
8
+ Field.call(this, name, 'hidden', defaultConfig);
9
+ }
10
+
11
+ HiddenField.defaultTemplate = null;
12
+
13
+ HiddenField.use = function(template) {
14
+ HiddenField.defaultTemplate = template.hiddenField;
15
+ };
16
+
17
+ HiddenField.prototype = Object.create(Field.prototype);
18
+ HiddenField.prototype.constructor = HiddenField;
@@ -1,7 +1,11 @@
1
1
  import FileField from "./FileField";
2
- import {Validation} from "../../validation/Validation";
2
+ import {Validation} from "@components/form/validation/Validation";
3
3
 
4
4
  export default function ImageField(name, defaultConfig) {
5
+ if(!(this instanceof ImageField)) {
6
+ return new ImageField(name, defaultConfig);
7
+ }
8
+
5
9
  FileField.call(this, name, 'image', defaultConfig);
6
10
 
7
11
  Object.assign(this.$description, {
@@ -14,6 +18,12 @@ export default function ImageField(name, defaultConfig) {
14
18
  this.accept(['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
15
19
  }
16
20
 
21
+ ImageField.defaultTemplate = null;
22
+
23
+ ImageField.use = function(template) {
24
+ ImageField.defaultTemplate = template.imageField;
25
+ };
26
+
17
27
  ImageField.prototype = Object.create(FileField.prototype);
18
28
  ImageField.prototype.constructor = ImageField;
19
29
 
@@ -1,7 +1,11 @@
1
- import {Validation} from "../../validation/Validation";
1
+ import {Validation} from "@components/form/validation/Validation";
2
2
  import Field from "../Field";
3
3
 
4
4
  export default function NumberField(name, type = 'number', defaultConfig = {}) {
5
+ if(!(this instanceof NumberField)) {
6
+ return new NumberField(name, defaultConfig);
7
+ }
8
+
5
9
  Field.call(this, name, type, defaultConfig);
6
10
 
7
11
  Object.assign(this.$description, {
@@ -13,6 +17,12 @@ export default function NumberField(name, type = 'number', defaultConfig = {}) {
13
17
  });
14
18
  }
15
19
 
20
+ NumberField.defaultTemplate = null;
21
+
22
+ NumberField.use = function(template) {
23
+ NumberField.defaultTemplate = template.numberField;
24
+ };
25
+
16
26
  NumberField.prototype = Object.create(Field.prototype);
17
27
  NumberField.prototype.constructor = NumberField;
18
28