native-document 1.0.70 → 1.0.72

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 (117) hide show
  1. package/components.js +2 -0
  2. package/dist/native-document.components.min.js +5636 -0
  3. package/dist/native-document.dev.js +380 -321
  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/elements.js +3 -3
  8. package/index.js +17 -17
  9. package/package.json +1 -1
  10. package/rollup.config.js +17 -1
  11. package/src/components/fom-control/FormControl.js +247 -0
  12. package/src/components/fom-control/default/DefaultLayout.js +8 -0
  13. package/src/components/fom-control/default/collection/DefaultCollectionLayout.js +12 -0
  14. package/src/components/fom-control/default/collection/DefaultCollectionTemplate.js +6 -0
  15. package/src/components/fom-control/field/DefaultRender.js +91 -0
  16. package/src/components/fom-control/field/Field.js +396 -0
  17. package/src/components/fom-control/field/FieldCollection.js +260 -0
  18. package/src/components/fom-control/field/FieldFactory.js +107 -0
  19. package/src/components/fom-control/field/types/AutocompleteField.js +46 -0
  20. package/src/components/fom-control/field/types/CheckboxField.js +17 -0
  21. package/src/components/fom-control/field/types/CheckboxGroupField.js +78 -0
  22. package/src/components/fom-control/field/types/ColorField.js +39 -0
  23. package/src/components/fom-control/field/types/DateField.js +62 -0
  24. package/src/components/fom-control/field/types/EmailField.js +44 -0
  25. package/src/components/fom-control/field/types/FileField.js +66 -0
  26. package/src/components/fom-control/field/types/HiddenField.js +8 -0
  27. package/src/components/fom-control/field/types/ImageField.js +49 -0
  28. package/src/components/fom-control/field/types/NumberField.js +74 -0
  29. package/src/components/fom-control/field/types/PasswordField.js +72 -0
  30. package/src/components/fom-control/field/types/RadioField.js +44 -0
  31. package/src/components/fom-control/field/types/RangeField.js +17 -0
  32. package/src/components/fom-control/field/types/SearchField.js +17 -0
  33. package/src/components/fom-control/field/types/SelectField.js +41 -0
  34. package/src/components/fom-control/field/types/StringField.js +49 -0
  35. package/src/components/fom-control/field/types/TelField.js +38 -0
  36. package/src/components/fom-control/field/types/TextAreaField.js +56 -0
  37. package/src/components/fom-control/field/types/TimeField.js +45 -0
  38. package/src/components/fom-control/field/types/UrlField.js +53 -0
  39. package/src/components/fom-control/index.js +8 -0
  40. package/src/components/fom-control/merge +0 -0
  41. package/src/components/fom-control/utils.js +17 -0
  42. package/src/components/fom-control/validation/Validation.js +556 -0
  43. package/src/components/table/Column.js +106 -0
  44. package/src/components/table/ColumnGroup.js +54 -0
  45. package/src/components/table/DataTable.js +195 -0
  46. package/src/components/table/SimpleTable.js +184 -0
  47. package/src/components/table/index.js +9 -0
  48. package/src/{data → core/data}/ObservableArray.js +1 -0
  49. package/src/{data → core/data}/ObservableItem.js +49 -3
  50. package/src/{data → core/data}/observable-helpers/computed.js +2 -1
  51. package/src/{elements → core/elements}/anchor.js +32 -32
  52. package/src/{elements → core/elements}/control/for-each-array.js +4 -2
  53. package/src/core/utils/EventEmitter.js +46 -0
  54. package/src/{utils → core/utils}/helpers.js +12 -0
  55. package/src/{utils → core/utils}/validator.js +7 -0
  56. package/src/{wrappers → core/wrappers}/ElementCreator.js +10 -33
  57. package/src/{wrappers → core/wrappers}/NDElement.js +0 -127
  58. package/src/core/wrappers/NdPrototype.js +147 -0
  59. package/src/core/wrappers/TemplateBinding.js +7 -0
  60. package/src/{wrappers → core/wrappers}/TemplateCloner.js +5 -6
  61. package/src/core/wrappers/prototype-extensions.js +56 -0
  62. package/src/devtools/hrm/ComponentRegistry.js +1 -1
  63. package/src/router/Route.js +1 -1
  64. package/src/router/RouteGroupHelper.js +1 -1
  65. package/src/router/Router.js +4 -4
  66. package/src/router/RouterComponent.js +13 -2
  67. package/src/router/link.js +2 -2
  68. package/src/router/modes/HistoryRouter.js +2 -2
  69. package/types/forms.d.ts +2 -1
  70. package/types/validator.ts +2 -1
  71. package/utils.js +3 -3
  72. package/src/wrappers/NdPrototype.js +0 -71
  73. /package/src/{data → core/data}/MemoryManager.js +0 -0
  74. /package/src/{data → core/data}/Observable.js +0 -0
  75. /package/src/{data → core/data}/ObservableChecker.js +0 -0
  76. /package/src/{data → core/data}/ObservableWhen.js +0 -0
  77. /package/src/{data → core/data}/Store.js +0 -0
  78. /package/src/{data → core/data}/observable-helpers/array.js +0 -0
  79. /package/src/{data → core/data}/observable-helpers/batch.js +0 -0
  80. /package/src/{data → core/data}/observable-helpers/object.js +0 -0
  81. /package/src/{elements → core/elements}/content-formatter.js +0 -0
  82. /package/src/{elements → core/elements}/control/for-each.js +0 -0
  83. /package/src/{elements → core/elements}/control/show-if.js +0 -0
  84. /package/src/{elements → core/elements}/control/show-when.js +0 -0
  85. /package/src/{elements → core/elements}/control/switch.js +0 -0
  86. /package/src/{elements → core/elements}/description-list.js +0 -0
  87. /package/src/{elements → core/elements}/form.js +0 -0
  88. /package/src/{elements → core/elements}/html5-semantics.js +0 -0
  89. /package/src/{elements → core/elements}/img.js +0 -0
  90. /package/src/{elements → core/elements}/index.js +0 -0
  91. /package/src/{elements → core/elements}/interactive.js +0 -0
  92. /package/src/{elements → core/elements}/list.js +0 -0
  93. /package/src/{elements → core/elements}/medias.js +0 -0
  94. /package/src/{elements → core/elements}/meta-data.js +0 -0
  95. /package/src/{elements → core/elements}/table.js +0 -0
  96. /package/src/{errors → core/errors}/ArgTypesError.js +0 -0
  97. /package/src/{errors → core/errors}/NativeDocumentError.js +0 -0
  98. /package/src/{errors → core/errors}/RouterError.js +0 -0
  99. /package/src/{utils → core/utils}/args-types.js +0 -0
  100. /package/src/{utils → core/utils}/debug-manager.js +0 -0
  101. /package/src/{utils → core/utils}/events.js +0 -0
  102. /package/src/{utils → core/utils}/filters/date.js +0 -0
  103. /package/src/{utils → core/utils}/filters/index.js +0 -0
  104. /package/src/{utils → core/utils}/filters/standard.js +0 -0
  105. /package/src/{utils → core/utils}/filters/strings.js +0 -0
  106. /package/src/{utils → core/utils}/filters/utils.js +0 -0
  107. /package/src/{utils → core/utils}/memoize.js +0 -0
  108. /package/src/{utils → core/utils}/plugins-manager.js +0 -0
  109. /package/src/{utils → core/utils}/property-accumulator.js +0 -0
  110. /package/src/{utils → core/utils}/prototypes.js +0 -0
  111. /package/src/{utils → core/utils}/service.js +0 -0
  112. /package/src/{wrappers → core/wrappers}/AttributesWrapper.js +0 -0
  113. /package/src/{wrappers → core/wrappers}/DocumentObserver.js +0 -0
  114. /package/src/{wrappers → core/wrappers}/HtmlElementWrapper.js +0 -0
  115. /package/src/{wrappers → core/wrappers}/SingletonView.js +0 -0
  116. /package/src/{wrappers → core/wrappers}/constants.js +0 -0
  117. /package/src/{utils/fetch → fetch}/NativeFetch.js +0 -0
@@ -0,0 +1,195 @@
1
+ import SimpleTable from "./SimpleTable";
2
+ import { Observable as $ } from "../../../index";
3
+
4
+ export default function DataTable(name, configs) {
5
+ SimpleTable.call(this, name, configs);
6
+
7
+ Object.assign(this.$description, {
8
+ pageSize: 0,
9
+ layout: null,
10
+ selectable: false,
11
+ expandable: false,
12
+ paginationTemplate: null,
13
+ toolbarTemplate: null,
14
+ ...configs
15
+ });
16
+
17
+ this.$currentPage = null;
18
+ this.$selectedRows = [];
19
+ this.$expandedRows = [];
20
+ }
21
+
22
+ DataTable.defaultToolbarTemplate = null;
23
+ DataTable.defaultPaginationTemplate = null;
24
+ DataTable.defaultLayout = null;
25
+
26
+ DataTable.use = function(template) {
27
+ SimpleTable.use(template);
28
+ DataTable.defaultToolbarTemplate = template.toolbar;
29
+ DataTable.defaultPaginationTemplate = template.pagination;
30
+ DataTable.defaultLayout = template.layout;
31
+ };
32
+
33
+ DataTable.prototype = Object.create(SimpleTable.prototype);
34
+ DataTable.prototype.constructor = DataTable;
35
+
36
+ DataTable.prototype.paginate = function(size) {
37
+ this.$description.pageSize = size;
38
+ if(size > 0) {
39
+ this.$currentPage = $(1);
40
+ }
41
+ return this;
42
+ };
43
+
44
+ DataTable.prototype.selectable = function() {
45
+ this.$description.selectable = true
46
+ return this;
47
+ };
48
+
49
+
50
+ DataTable.prototype.layout = function(layoutFn) {
51
+ this.$description.layout = layoutFn;
52
+ return this;
53
+ };
54
+
55
+ DataTable.prototype.toolbarTemplate = function(template) {
56
+ this.$description.toolbarTemplate = template;
57
+ return this;
58
+ };
59
+
60
+ DataTable.prototype.paginationTemplate = function(template) {
61
+ this.$description.paginationTemplate = template;
62
+ return this;
63
+ };
64
+
65
+
66
+ DataTable.prototype.buildToolbar = function() {
67
+ const toolbarTemplate = this.$description.toolbarTemplate || DataTable.defaultToolbarTemplate;
68
+ if(typeof toolbarTemplate === 'function') {
69
+ return toolbarTemplate(this);
70
+ }
71
+ return null;
72
+ };
73
+
74
+ DataTable.prototype.buildPagination = function() {
75
+ const paginationTemplate = this.$description.paginationTemplate || DataTable.defaultPaginationTemplate;
76
+ if(typeof paginationTemplate === 'function') {
77
+ return paginationTemplate(this);
78
+ }
79
+ return null;
80
+ };
81
+
82
+
83
+ DataTable.prototype.toNdElement = function() {
84
+ const layout = this.$description.layout || DataTable.defaultLayout;
85
+ if (typeof layout === 'function') {
86
+ return layout(this);
87
+ }
88
+ return Div({ class: 'data-table-container' }, [
89
+ this.buildToolbar(),
90
+ this.build(),
91
+ this.buildPagination()
92
+ ]);
93
+ };
94
+
95
+
96
+ //-----------------------------------------------------------------
97
+ // Page Actions
98
+ //-----------------------------------------------------------------
99
+
100
+ DataTable.prototype.goToPage = function(page) {
101
+ // TODO: implement this action
102
+ return this;
103
+ };
104
+
105
+ DataTable.prototype.goToLastPage = function(page) {
106
+ // TODO: implement this action
107
+ return this;
108
+ };
109
+
110
+ DataTable.prototype.goToFistPage = function(page) {
111
+ // TODO: implement this action
112
+ return this;
113
+ };
114
+
115
+ DataTable.prototype.nextPage = function() {
116
+ // TODO: implement this action
117
+ return this;
118
+ };
119
+
120
+ DataTable.prototype.previousPage = function() {
121
+ // TODO: implement this action
122
+ return this;
123
+ };
124
+
125
+ DataTable.prototype.paginationConfig = function() {
126
+ return {
127
+ size: this.$description.pageSize
128
+ };
129
+ };
130
+
131
+
132
+ //-----------------------------------------------------------------
133
+ // Sort Actions
134
+ //-----------------------------------------------------------------
135
+
136
+ DataTable.prototype.defaultSort = function() {
137
+ // TODO: implement this action
138
+ return this;
139
+ };
140
+
141
+ DataTable.prototype.sortBy = function() {
142
+ // TODO: implement this action
143
+ return this;
144
+ };
145
+
146
+ DataTable.prototype.clearSort = function() {
147
+ // TODO: implement this action
148
+ return this;
149
+ };
150
+
151
+ DataTable.prototype.getSortState = function() {
152
+ // TODO: implement this action
153
+ return this;
154
+ };
155
+
156
+
157
+ //-----------------------------------------------------------------
158
+ // Selectable Actions
159
+ //-----------------------------------------------------------------
160
+
161
+ DataTable.prototype.select = function(row) {
162
+ // TODO: implement this action
163
+ return this;
164
+ };
165
+
166
+ DataTable.prototype.deselect = function(row) {
167
+ // TODO: implement this action
168
+ return this;
169
+ };
170
+
171
+ DataTable.prototype.selectAll = function() {
172
+ // TODO: implement this action
173
+ return this;
174
+ };
175
+
176
+ DataTable.prototype.deselectAll = function() {
177
+ // TODO: implement this action
178
+ return this;
179
+ };
180
+
181
+ DataTable.prototype.clearSelection = function() {
182
+ // TODO: implement this action
183
+ return this;
184
+ };
185
+
186
+ DataTable.prototype.getSelectedRows = function() {
187
+ // TODO: implement this action
188
+ return this;
189
+ };
190
+
191
+ DataTable.prototype.isRowSelected = function(row) {
192
+ // TODO: implement this action
193
+ return this;
194
+ };
195
+
@@ -0,0 +1,184 @@
1
+ import Column from "./Column";
2
+ import ColumnGroup from "./ColumnGroup";
3
+ import {Table, TFoot, TRow} from "../../../elements";
4
+ import DataTable from "./DataTable";
5
+
6
+
7
+ export default function SimpleTable(configs = {}) {
8
+ this.$description = {
9
+ header: [],
10
+ columns: [],
11
+ hasGroups: false,
12
+ rowTemplate: null,
13
+ tableTemplate: null,
14
+ data: null,
15
+ layout: null,
16
+ expandable: false,
17
+ ...configs
18
+ };
19
+
20
+ this.$element = null;
21
+ this.$thead = null;
22
+ this.$tbody = null;
23
+ this.$tfoot = null;
24
+ }
25
+
26
+ SimpleTable.defaultTableTemplate = null;
27
+ SimpleTable.defaultRowTemplate = null;
28
+ SimpleTable.defaultEmptyTemplate = null;
29
+
30
+ /**
31
+ *
32
+ * @param {{
33
+ * column: { header: string|Function|null, render: string|Function|null },
34
+ * columnGroup: { header: string|Function|null },
35
+ * row: string|Function|null,
36
+ * table: string|Function|null
37
+ * empty: string|Function|null
38
+ * }} template
39
+ */
40
+ SimpleTable.use = function(template) {
41
+ Column.use(template.column || {});
42
+ ColumnGroup.use(template.columnGroup || {});
43
+ SimpleTable.defaultRowTemplate = template.row || SimpleTable.defaultRowTemplate;
44
+ SimpleTable.defaultTableTemplate = template.table || SimpleTable.defaultTableTemplate;
45
+ SimpleTable.defaultEmptyTemplate = template.empty || SimpleTable.defaultEmptyTemplate;
46
+ };
47
+
48
+ SimpleTable.create = function(configs) {
49
+ return new SimpleTable(configs);
50
+ };
51
+
52
+ SimpleTable.prototype.column = function(key, title, callback) {
53
+ const column = new Column(key);
54
+ column.title(title);
55
+ callback && callback(column);
56
+ this.$description.columns.push(column);
57
+ this.$description.header.push(column);
58
+ return this;
59
+ };
60
+
61
+ SimpleTable.prototype.group = function(title, callback) {
62
+ const group = new ColumnGroup(title);
63
+ callback && callback(group);
64
+ this.$description.columns.push(...group.columns());
65
+ this.$description.header.push(group);
66
+ this.$description.hasGroups = true;
67
+ return this;
68
+ };
69
+
70
+ SimpleTable.prototype.columns = function(columnsArray) {
71
+ columnsArray.forEach(column => this.column(column.key, column.title, column.callback));
72
+ return this;
73
+ };
74
+
75
+ SimpleTable.prototype.data = function(data) {
76
+ this.$description.data = data;
77
+ return this;
78
+ };
79
+
80
+ DataTable.prototype.expandable = function() {
81
+ this.$description.expandable = true
82
+ return this;
83
+ };
84
+
85
+ SimpleTable.prototype.renderRow = function(template) {
86
+ this.$description.rowTemplate = template;
87
+ return this;
88
+ }
89
+
90
+ SimpleTable.prototype.buildRow = function(rowData) {
91
+ const rowTemplate = this.$description.rowTemplate || SimpleTable.defaultRowTemplate;
92
+
93
+ if(typeof rowTemplate === 'function') {
94
+ return rowTemplate(rowData, this);
95
+ }
96
+
97
+ return TRow(this.$description.columns.map(
98
+ column => TBodyCell({}, column.buildCell(rowData))
99
+ ));
100
+ };
101
+
102
+ SimpleTable.prototype.renderTable = function(template) {
103
+ this.$description.tableTemplate = template;
104
+ return this;
105
+ };
106
+
107
+ SimpleTable.prototype.buildTable = function(slots = {}) {
108
+ const { headerRows } = slots;
109
+
110
+ const tableTemplate = this.$description.tableTemplate || SimpleTable.defaultTableTemplate;
111
+ if(typeof tableTemplate === 'function') {
112
+ return tableTemplate(slots, this);
113
+ }
114
+
115
+ return Table({ border: 2 }, [
116
+ THead(headerRows),
117
+ TBody(
118
+ ForEachArray(this.$description.data, rowData => {
119
+ return this.buildRow(rowData, this);
120
+ })
121
+ )
122
+ ]);
123
+ };
124
+
125
+ SimpleTable.prototype.build = function() {
126
+ const header = [];
127
+ if(this.$description.hasGroups) {
128
+ const firstRow = [];
129
+ const secondRow = [];
130
+
131
+ this.$description.header.forEach(columnOrGroup => {
132
+ if(columnOrGroup.isGroup) {
133
+ const columns = columnOrGroup.columns();
134
+ firstRow.push(columnOrGroup.buildHeader());
135
+ secondRow.push(columns.map(column => THeadCell({}, column.buildHeader())));
136
+ } else {
137
+ firstRow.push(columnOrGroup.buildHeader(2));
138
+ }
139
+ });
140
+
141
+ header.push(TRow(firstRow));
142
+ header.push(TRow(secondRow));
143
+ } else {
144
+ header.push(TRow(
145
+ this.$description.columns.map(column => column.buildHeader())
146
+ ));
147
+ }
148
+
149
+ return this.buildTable({ headerRows: header });
150
+ };
151
+
152
+ SimpleTable.prototype.toNdElement = function() {
153
+ return this.build();
154
+ };
155
+
156
+ SimpleTable.prototype.onClick = function(callback) {
157
+ this.$description.onClick = callback;
158
+ };
159
+
160
+
161
+
162
+ //-----------------------------------------------------------------
163
+ // Expandable Actions
164
+ //-----------------------------------------------------------------
165
+
166
+ DataTable.prototype.expand = function(row) {
167
+ // TODO: implement this action
168
+ return this;
169
+ };
170
+
171
+ DataTable.prototype.collapse = function(row) {
172
+ // TODO: implement this action
173
+ return this;
174
+ };
175
+
176
+ DataTable.prototype.collapseAll = function() {
177
+ // TODO: implement this action
178
+ return this;
179
+ };
180
+
181
+ DataTable.prototype.isRowExpanded = function(row) {
182
+ // TODO: implement this action
183
+ return this;
184
+ };
@@ -0,0 +1,9 @@
1
+ import SimpleTable from './SimpleTable';
2
+ import DataTable from './DataTable';
3
+
4
+
5
+
6
+ export {
7
+ SimpleTable,
8
+ DataTable
9
+ }
@@ -25,6 +25,7 @@ const ObservableArray = function (target, configs = null) {
25
25
  };
26
26
 
27
27
  ObservableArray.prototype = Object.create(ObservableItem.prototype);
28
+ ObservableArray.prototype.constructor = ObservableArray;
28
29
  ObservableArray.prototype.__$isObservableArray = true;
29
30
 
30
31
  mutationMethods.forEach((method) => {
@@ -14,6 +14,8 @@ import {deepClone} from "../utils/helpers.js";
14
14
  * @class ObservableItem
15
15
  */
16
16
  export default function ObservableItem(value, configs = null) {
17
+ value = Validator.isObservable(value) ? value.val() : value;
18
+
17
19
  this.$previousValue = null;
18
20
  this.$currentValue = value;
19
21
  this.$isCleanedUp = false;
@@ -47,9 +49,15 @@ ObservableItem.prototype.__$isObservable = true;
47
49
  const DEFAULT_OPERATIONS = {};
48
50
  const noneTrigger = function() {};
49
51
 
52
+ ObservableItem.prototype.intercept = function(callback) {
53
+ this.$interceptor = callback;
54
+ return this;
55
+ };
56
+
50
57
  ObservableItem.prototype.triggerFirstListener = function(operations) {
51
58
  this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
52
- }
59
+ };
60
+
53
61
  ObservableItem.prototype.triggerListeners = function(operations) {
54
62
  const $listeners = this.$listeners;
55
63
  const $previousValue = this.$previousValue;
@@ -74,7 +82,7 @@ const handleWatcherCallback = function(callbacks, value) {
74
82
  callbacks.forEach(callback => {
75
83
  callback.set ? callback.set(value) : callback(value);
76
84
  });
77
- }
85
+ };
78
86
 
79
87
  ObservableItem.prototype.triggerWatchers = function() {
80
88
  if(!this.$watchers) {
@@ -126,7 +134,17 @@ ObservableItem.prototype.trigger = noneTrigger;
126
134
  * @param {*} data
127
135
  */
128
136
  ObservableItem.prototype.set = function(data) {
129
- const newValue = (typeof data === 'function') ? data(this.$currentValue) : data;
137
+ let newValue = (typeof data === 'function') ? data(this.$currentValue) : data;
138
+ newValue = Validator.isObservable(newValue) ? newValue.val() : newValue;
139
+
140
+ if (this.$interceptor) {
141
+ const result = this.$interceptor(newValue, this.$currentValue);
142
+
143
+ if (result !== undefined) {
144
+ newValue = result;
145
+ }
146
+ }
147
+
130
148
  if(this.$currentValue === newValue) {
131
149
  return;
132
150
  }
@@ -159,7 +177,18 @@ ObservableItem.prototype.disconnectAll = function() {
159
177
  this.trigger = noneTrigger;
160
178
  };
161
179
 
180
+ ObservableItem.prototype.onCleanup = function(callback) {
181
+ this.$cleanupListeners = this.$cleanupListeners ?? [];
182
+ this.$cleanupListeners.push(callback);
183
+ };
184
+
162
185
  ObservableItem.prototype.cleanup = function() {
186
+ if (this.$cleanupListeners) {
187
+ for (let i = 0; i < this.$cleanupListeners.length; i++) {
188
+ this.$cleanupListeners[i]();
189
+ }
190
+ this.$cleanupListeners = null;
191
+ }
163
192
  MemoryManager.unregister(this.$memoryId);
164
193
  this.disconnectAll();
165
194
  this.$isCleanedUp = true;
@@ -222,6 +251,18 @@ ObservableItem.prototype.on = function(value, callback) {
222
251
  };
223
252
  };
224
253
 
254
+ ObservableItem.prototype.once = function(predicate, callback) {
255
+ const fn = typeof predicate === 'function' ? predicate : (v) => v === predicate;
256
+
257
+ const unsub = this.subscribe((val) => {
258
+ if (fn(val)) {
259
+ unsub();
260
+ callback(val);
261
+ }
262
+ });
263
+ return unsub;
264
+ };
265
+
225
266
  /**
226
267
  * Unsubscribe from an observable.
227
268
  * @param {Function} callback
@@ -284,3 +325,8 @@ ObservableItem.prototype.reset = function() {
284
325
  : this.$initialValue;
285
326
  this.set(resetValue)
286
327
  };
328
+
329
+
330
+ ObservableItem.prototype.toString = function() {
331
+ return String(this.$currentValue);
332
+ };
@@ -3,6 +3,7 @@ import Validator from "../../utils/validator";
3
3
  import NativeDocumentError from "../../errors/NativeDocumentError";
4
4
  import {Observable} from "../Observable";
5
5
  import PluginsManager from "../../utils/plugins-manager";
6
+ import {nextTick} from "../../utils/helpers";
6
7
 
7
8
  /**
8
9
  *
@@ -13,7 +14,7 @@ import PluginsManager from "../../utils/plugins-manager";
13
14
  Observable.computed = function(callback, dependencies = []) {
14
15
  const initialValue = callback();
15
16
  const observable = new ObservableItem(initialValue);
16
- const updatedValue = () => observable.set(callback());
17
+ const updatedValue = nextTick(() => observable.set(callback()));
17
18
 
18
19
  PluginsManager.emit('CreateObservableComputed', observable, dependencies)
19
20
 
@@ -4,23 +4,23 @@ import {ElementCreator} from "../wrappers/ElementCreator";
4
4
 
5
5
 
6
6
  export default function Anchor(name, isUniqueChild = false) {
7
- const element = document.createDocumentFragment();
8
- element.__Anchor__ = true;
7
+ const anchorFragment = document.createDocumentFragment();
8
+ anchorFragment.__Anchor__ = true;
9
9
 
10
10
  const anchorStart = document.createComment('Anchor Start : '+name);
11
11
  const anchorEnd = document.createComment('/ Anchor End '+name);
12
12
 
13
- element.appendChild(anchorStart);
14
- element.appendChild(anchorEnd);
13
+ anchorFragment.appendChild(anchorStart);
14
+ anchorFragment.appendChild(anchorEnd);
15
15
 
16
- element.nativeInsertBefore = element.insertBefore;
17
- element.nativeAppendChild = element.appendChild;
16
+ anchorFragment.nativeInsertBefore = anchorFragment.insertBefore;
17
+ anchorFragment.nativeAppendChild = anchorFragment.appendChild;
18
18
 
19
19
  const isParentUniqueChild = (parent) => (isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd))
20
20
 
21
21
  const insertBefore = function(parent, child, target) {
22
22
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
23
- if(parent === element) {
23
+ if(parent === anchorFragment) {
24
24
  parent.nativeInsertBefore(childElement, target);
25
25
  return;
26
26
  }
@@ -31,17 +31,17 @@ export default function Anchor(name, isUniqueChild = false) {
31
31
  parent.insertBefore(childElement, target);
32
32
  };
33
33
 
34
- element.appendElement = function(child, before = null) {
34
+ anchorFragment.appendElement = function(child, before = null) {
35
35
  const parentNode = anchorStart.parentNode;
36
36
  const targetBefore = before || anchorEnd;
37
- if(parentNode === element) {
37
+ if(parentNode === anchorFragment) {
38
38
  parentNode.nativeInsertBefore(child, targetBefore);
39
39
  return;
40
40
  }
41
41
  parentNode?.insertBefore(child, targetBefore);
42
42
  };
43
43
 
44
- element.appendChild = function(child, before = null) {
44
+ anchorFragment.appendChild = function(child, before = null) {
45
45
  const parent = anchorEnd.parentNode;
46
46
  if(!parent) {
47
47
  DebugManager.error('Anchor', 'Anchor : parent not found', child);
@@ -50,13 +50,13 @@ export default function Anchor(name, isUniqueChild = false) {
50
50
  before = before ?? anchorEnd;
51
51
  insertBefore(parent, child, before);
52
52
  };
53
- element.append = function(...args ) {
54
- return element.appendChild(args);
53
+ anchorFragment.append = function(...args ) {
54
+ return anchorFragment.appendChild(args);
55
55
  }
56
56
 
57
- element.removeChildren = function() {
57
+ anchorFragment.removeChildren = function() {
58
58
  const parent = anchorEnd.parentNode;
59
- if(parent === element) {
59
+ if(parent === anchorFragment) {
60
60
  return;
61
61
  }
62
62
  if(isParentUniqueChild(parent)) {
@@ -73,26 +73,26 @@ export default function Anchor(name, isUniqueChild = false) {
73
73
  }
74
74
  fragment.replaceChildren();
75
75
  }
76
- element.remove = function() {
76
+ anchorFragment.remove = function() {
77
77
  const parent = anchorEnd.parentNode;
78
- if(parent === element) {
78
+ if(parent === anchorFragment) {
79
79
  return;
80
80
  }
81
81
  let itemToRemove = anchorStart.nextSibling, tempItem;
82
82
  while(itemToRemove && itemToRemove !== anchorEnd) {
83
83
  tempItem = itemToRemove.nextSibling;
84
- element.nativeAppendChild(itemToRemove);
84
+ anchorFragment.nativeAppendChild(itemToRemove);
85
85
  itemToRemove = tempItem;
86
86
  }
87
87
  };
88
88
 
89
- element.removeWithAnchors = function() {
90
- element.removeChildren();
89
+ anchorFragment.removeWithAnchors = function() {
90
+ anchorFragment.removeChildren();
91
91
  anchorStart.remove();
92
92
  anchorEnd.remove();
93
93
  };
94
94
 
95
- element.replaceContent = function(child) {
95
+ anchorFragment.replaceContent = function(child) {
96
96
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
97
97
  const parent = anchorEnd.parentNode;
98
98
  if(!parent) {
@@ -102,31 +102,31 @@ export default function Anchor(name, isUniqueChild = false) {
102
102
  parent.replaceChildren(anchorStart, childElement, anchorEnd);
103
103
  return;
104
104
  }
105
- element.removeChildren();
105
+ anchorFragment.removeChildren();
106
106
  parent.insertBefore(childElement, anchorEnd);
107
107
  };
108
108
 
109
- element.setContent = element.replaceContent;
109
+ anchorFragment.setContent = anchorFragment.replaceContent;
110
110
 
111
- element.insertBefore = function(child, anchor = null) {
112
- element.appendChild(child, anchor);
111
+ anchorFragment.insertBefore = function(child, anchor = null) {
112
+ anchorFragment.appendChild(child, anchor);
113
113
  };
114
114
 
115
115
 
116
- element.endElement = function() {
116
+ anchorFragment.endElement = function() {
117
117
  return anchorEnd;
118
118
  };
119
119
 
120
- element.startElement = function() {
120
+ anchorFragment.startElement = function() {
121
121
  return anchorStart;
122
122
  };
123
- element.restore = function() {
124
- element.appendChild(element);
123
+ anchorFragment.restore = function() {
124
+ anchorFragment.appendChild(anchorFragment);
125
125
  };
126
- element.clear = element.remove;
127
- element.detach = element.remove;
126
+ anchorFragment.clear = anchorFragment.remove;
127
+ anchorFragment.detach = anchorFragment.remove;
128
128
 
129
- element.getByIndex = function(index) {
129
+ anchorFragment.getByIndex = function(index) {
130
130
  let currentNode = anchorStart;
131
131
  for(let i = 0; i <= index; i++) {
132
132
  if(!currentNode.nextSibling) {
@@ -137,7 +137,7 @@ export default function Anchor(name, isUniqueChild = false) {
137
137
  return currentNode !== anchorStart ? currentNode : null;
138
138
  };
139
139
 
140
- return element;
140
+ return anchorFragment;
141
141
  };
142
142
 
143
143
  /**
@@ -21,12 +21,14 @@ export function ForEachArray(data, callback, key, configs = {}) {
21
21
  cleanCache();
22
22
  lastNumberOfItems = 0;
23
23
  };
24
+
24
25
  const getItemKey = (item, indexKey) => {
25
26
  if(keysCache.has(item)) {
26
27
  return keysCache.get(item);
27
28
  }
28
29
  return getKey(item, indexKey, key);
29
30
  };
31
+
30
32
  const getItemChild = (item) => {
31
33
  return getChildByKey(getItemKey(item));
32
34
  };
@@ -143,9 +145,9 @@ export function ForEachArray(data, callback, key, configs = {}) {
143
145
  },
144
146
  add(items, delay = 2) {
145
147
  const fragment = Actions.toFragment(items);
146
- setTimeout(() => {
148
+ Promise.resolve().then(() => {
147
149
  element.appendElement(fragment);
148
- }, delay);
150
+ });
149
151
  },
150
152
  replace(items) {
151
153
  clear();