vasille 1.2.6 → 2.0.0

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 (122) hide show
  1. package/LICENSE.md +21 -0
  2. package/flow-typed/vasille.js +836 -0
  3. package/img/favicon.svg +17 -204
  4. package/lib/binding/attribute.js +32 -0
  5. package/lib/binding/binding.js +39 -0
  6. package/lib/binding/class.js +51 -0
  7. package/lib/binding/style.js +29 -0
  8. package/lib/core/core.js +178 -0
  9. package/lib/core/destroyable.js +45 -0
  10. package/lib/core/errors.js +16 -0
  11. package/lib/core/executor.js +154 -0
  12. package/lib/core/ivalue.js +56 -0
  13. package/lib/core/signal.js +50 -0
  14. package/lib/core/slot.js +47 -0
  15. package/lib/index.js +27 -22
  16. package/lib/models/array-model.js +208 -0
  17. package/lib/models/listener.js +130 -0
  18. package/lib/models/map-model.js +66 -0
  19. package/lib/models/model.js +1 -0
  20. package/lib/models/object-model.js +78 -0
  21. package/lib/models/set-model.js +62 -0
  22. package/lib/node/app.js +38 -0
  23. package/lib/node/interceptor.js +83 -0
  24. package/lib/node/node.js +1185 -0
  25. package/lib/node/watch.js +27 -0
  26. package/lib/value/expression.js +83 -0
  27. package/lib/value/mirror.js +58 -0
  28. package/lib/value/pointer.js +26 -0
  29. package/lib/value/reference.js +55 -0
  30. package/lib/views/array-view.js +24 -0
  31. package/lib/views/base-view.js +49 -0
  32. package/lib/views/map-view.js +20 -0
  33. package/lib/views/object-view.js +20 -0
  34. package/lib/views/repeat-node.js +106 -0
  35. package/lib/views/repeater.js +63 -0
  36. package/lib/views/set-view.js +23 -0
  37. package/package.json +16 -15
  38. package/types/binding/attribute.d.ts +23 -0
  39. package/types/binding/binding.d.ts +30 -0
  40. package/types/binding/class.d.ts +23 -0
  41. package/types/binding/style.d.ts +23 -0
  42. package/types/core/core.d.ts +140 -0
  43. package/types/core/destroyable.d.ts +15 -0
  44. package/types/core/errors.d.ts +4 -0
  45. package/types/core/executor.d.ts +87 -0
  46. package/types/core/ivalue.d.ts +45 -0
  47. package/types/core/signal.d.ts +35 -0
  48. package/types/core/slot.d.ts +45 -0
  49. package/types/index.d.ts +27 -21
  50. package/types/models/array-model.d.ts +103 -0
  51. package/types/models/listener.d.ts +74 -0
  52. package/types/models/map-model.d.ts +35 -0
  53. package/types/models/model.d.ts +19 -0
  54. package/types/models/object-model.d.ts +36 -0
  55. package/types/models/set-model.d.ts +34 -0
  56. package/types/node/app.d.ts +37 -0
  57. package/types/node/interceptor.d.ts +50 -0
  58. package/types/node/node.d.ts +739 -0
  59. package/types/node/watch.d.ts +23 -0
  60. package/types/value/expression.d.ts +60 -0
  61. package/types/value/mirror.d.ts +35 -0
  62. package/types/value/pointer.d.ts +19 -0
  63. package/types/value/reference.d.ts +30 -0
  64. package/types/views/array-view.d.ts +13 -0
  65. package/types/views/base-view.d.ts +44 -0
  66. package/types/views/map-view.d.ts +11 -0
  67. package/types/views/object-view.d.ts +11 -0
  68. package/types/views/repeat-node.d.ts +35 -0
  69. package/types/views/repeater.d.ts +38 -0
  70. package/types/views/set-view.d.ts +11 -0
  71. package/CHANGELOG.md +0 -23
  72. package/lib/attribute.js +0 -71
  73. package/lib/attribute.js.map +0 -1
  74. package/lib/bind.js +0 -286
  75. package/lib/bind.js.map +0 -1
  76. package/lib/class.js +0 -97
  77. package/lib/class.js.map +0 -1
  78. package/lib/executor.js +0 -167
  79. package/lib/executor.js.map +0 -1
  80. package/lib/index.js.map +0 -1
  81. package/lib/interfaces/core.js +0 -247
  82. package/lib/interfaces/core.js.map +0 -1
  83. package/lib/interfaces/destroyable.js +0 -39
  84. package/lib/interfaces/destroyable.js.map +0 -1
  85. package/lib/interfaces/errors.js +0 -49
  86. package/lib/interfaces/errors.js.map +0 -1
  87. package/lib/interfaces/ibind.js +0 -31
  88. package/lib/interfaces/ibind.js.map +0 -1
  89. package/lib/interfaces/idefinition.js +0 -64
  90. package/lib/interfaces/idefinition.js.map +0 -1
  91. package/lib/interfaces/ivalue.js +0 -60
  92. package/lib/interfaces/ivalue.js.map +0 -1
  93. package/lib/models.js +0 -579
  94. package/lib/models.js.map +0 -1
  95. package/lib/node.js +0 -2155
  96. package/lib/node.js.map +0 -1
  97. package/lib/property.js +0 -38
  98. package/lib/property.js.map +0 -1
  99. package/lib/style.js +0 -66
  100. package/lib/style.js.map +0 -1
  101. package/lib/value.js +0 -203
  102. package/lib/value.js.map +0 -1
  103. package/lib/views.js +0 -688
  104. package/lib/views.js.map +0 -1
  105. package/types/attribute.d.ts +0 -18
  106. package/types/bind.d.ts +0 -72
  107. package/types/class.d.ts +0 -19
  108. package/types/data.d.ts +0 -11
  109. package/types/event.d.ts +0 -10
  110. package/types/executor.d.ts +0 -57
  111. package/types/interfaces/core.d.ts +0 -129
  112. package/types/interfaces/destroyable.d.ts +0 -11
  113. package/types/interfaces/errors.d.ts +0 -24
  114. package/types/interfaces/ibind.d.ts +0 -19
  115. package/types/interfaces/idefinition.d.ts +0 -29
  116. package/types/interfaces/ivalue.d.ts +0 -40
  117. package/types/models.d.ts +0 -179
  118. package/types/node.d.ts +0 -906
  119. package/types/property.d.ts +0 -9
  120. package/types/style.d.ts +0 -28
  121. package/types/value.d.ts +0 -43
  122. package/types/views.d.ts +0 -135
@@ -1,247 +0,0 @@
1
- //
2
- import { Destroyable } from "./destroyable.js";
3
- import { internalError, notFound } from "./errors";
4
- import { IValue } from "./ivalue.js";
5
-
6
-
7
-
8
-
9
-
10
- /**
11
- * Destroy all destroyable object fields
12
- * @param obj {Object<any, any>} Object to be iterated
13
- */
14
- export function $destroyObject (obj) {
15
- for (let i in obj) {
16
- if (obj.hasOwnProperty(i)) {
17
- let prop = obj[i];
18
- if (prop instanceof Destroyable && !(prop instanceof VasilleNode)) {
19
- prop.$destroy();
20
- }
21
- delete obj[i];
22
- }
23
- }
24
- }
25
-
26
- /**
27
- * Represents a Vasille.js node
28
- * @implements Destroyable
29
- */
30
- export class VasilleNodePrivate extends Destroyable {
31
- /**
32
- * The encapsulated element
33
- * @type {HTMLElement | Text | Comment}
34
- * @see VasilleNode#coreEl
35
- * @see VasilleNode#el
36
- * @see VasilleNode#text
37
- * @see VasilleNode#comment
38
- */
39
- $el;
40
-
41
- /**
42
- * The collection of attributes
43
- * @type {Object<String, IValue>}
44
- * @see VasilleNode#attr
45
- */
46
- $attrs = {};
47
-
48
- /**
49
- * The collection of style attributes
50
- * @type {Object<String, IValue>}
51
- * @see VasilleNode#style
52
- */
53
- $style = {};
54
- /**
55
- * The root node
56
- * @type {INode}
57
- */
58
- root;
59
-
60
- /**
61
- * The this node
62
- * @type {INode}
63
- */
64
- ts;
65
-
66
- /**
67
- * The app node
68
- * @type {VasilleNode}
69
- */
70
- app;
71
-
72
- /**
73
- * A link to a parent node
74
- * @type {VasilleNode}
75
- */
76
- parent;
77
-
78
- /**
79
- * The next node
80
- * @type {?VasilleNode}
81
- */
82
- next;
83
-
84
- /**
85
- * The previous node
86
- * @type {?VasilleNode}
87
- */
88
- prev;
89
-
90
- constructor () {
91
- super();
92
-
93
- this.seal();
94
- }
95
-
96
- /**
97
- * Gets the encapsulated element anyway
98
- * @type {HTMLElement | Text | Comment}
99
- * @see VasilleNode#$el
100
- */
101
- get coreEl () {
102
- return this.$el;
103
- }
104
-
105
- /**
106
- * Gets the encapsulated element if it is a html element, otherwise undefined
107
- * @type {HTMLElement}
108
- * @see VasilleNode#$el
109
- */
110
- get el () {
111
- let el = this.coreEl;
112
- if (el instanceof HTMLElement) {
113
- return el;
114
- }
115
-
116
- throw internalError("wrong VasilleNode.$el() call");
117
- }
118
-
119
- /**
120
- * Gets the encapsulated element if it is a html text node, otherwise undefined
121
- * @type {Text}
122
- * @see VasilleNode#$el
123
- */
124
- get text () {
125
- let el = this.coreEl;
126
- if (el instanceof Text) {
127
- return el;
128
- }
129
-
130
- throw internalError("wrong VasilleNode.$text() call");
131
- }
132
-
133
- /**
134
- * Gets the encapsulated element if it is a html comment, otherwise undefined
135
- * @type {Comment}
136
- * @see VasilleNode#$el
137
- */
138
- get comment () {
139
- let el = this.coreEl;
140
- if (el instanceof Comment) {
141
- return el;
142
- }
143
-
144
- throw internalError("wrong VasilleNode.$comment() call");
145
- }
146
-
147
- /**
148
- * Encapsulate element
149
- * @param el {HTMLElement | Text | Comment} element to encapsulate
150
- * @private
151
- */
152
- encapsulate (el) {
153
- this.$el = el;
154
- return this;
155
- }
156
-
157
- /**
158
- * Pre-initializes the base of a node
159
- * @param app {App} the app node
160
- * @param rt {INode} The root node
161
- * @param ts {INode} The this node
162
- * @param before {?VasilleNode} VasilleNode to paste this after
163
- */
164
- preinit (app, rt, ts, before) {
165
- this.app = app;
166
- this.root = rt;
167
- this.ts = ts;
168
- }
169
-
170
- /**
171
- * Gets the component life attribute value
172
- * @param field {string} attribute name
173
- * @return {IValue}
174
- */
175
- attr (field) {
176
- let v = this.$attrs[field];
177
-
178
- if (v instanceof IValue) {
179
- return v;
180
- }
181
-
182
- throw notFound("no such attribute: " + field);
183
- }
184
-
185
- /**
186
- * Gets the component life style attribute
187
- * @param field {Object<String, IValue>}
188
- * @return {IValue<string>}
189
- * @see VasilleNode#$style
190
- */
191
- style (field) {
192
- let v = this.$style[field];
193
-
194
- if (v instanceof IValue) {
195
- return v;
196
- }
197
-
198
- throw notFound("no such style attribute: " + field);
199
- }
200
-
201
- /**
202
- * Unlinks all bindings
203
- */
204
- $destroy () {
205
- $destroyObject(this.$attrs);
206
- $destroyObject(this.$style);
207
- //$FlowFixMe
208
- this.$el = null;
209
- //$FlowFixMe
210
- this.$attrs = null;
211
- //$FlowFixMe
212
- this.$style = null;
213
- //$FlowFixMe
214
- this.root = null;
215
- //$FlowFixMe
216
- this.ts = null;
217
- //$FlowFixMe
218
- this.app = null;
219
- //$FlowFixMe
220
- this.parent = null;
221
- //$FlowFixMe
222
- this.next = null;
223
- //$FlowFixMe
224
- this.prev = null;
225
- }
226
- }
227
-
228
- /**
229
- * This class is symbolic
230
- */
231
- export class VasilleNode extends Destroyable {
232
- /**
233
- * @type {VasilleNodePrivate}
234
- */
235
- $;
236
-
237
- /**
238
- * Constructs a Vasille Node
239
- * @param $ {VasilleNodePrivate}
240
- */
241
- constructor ($) {
242
- super();
243
- this.$ = $ || new VasilleNodePrivate;
244
- }
245
- }
246
-
247
- //# sourceMappingURL=core.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/core.js"],"names":[],"mappings":"GAAG,AAAK;AACR,AAAkD,AAAA;;;;;;;AAOlD,AAA0D,AAAA;AAC1D,AAAkD,AAAA;;;;;;;oCAOd,AAAA,AAAQ;;;;;;;;;;;;;;;;;;;;;;;;;QAyBpC,AAAA,AAAQ;;;;;;;WAOL,AAAA,AAAY;;;;;;;WAOZ,AAAA,AAAY;;;;;SAKd,AAAA,AAAO;;;;;;OAMT,AAAA,AAAO;;;;;;QAMN,AAAA,AAAK;;;;;;WAMF,AAAA,AAAO;;;;;;SAMT,AAAA,AAAc;;;;;;SAMd,AAAA,AAAc;;;;;;;;;;;;;kBAaL,AAAA,AAAQ;;;;;;;;;cASZ,AAAA,AAAa;;;;;;;;;;;;;;gBAcX,AAAA,AAAM;;;;;;;;;;;;;;mBAcH,AAAA,AAAS;;;;;;;;;;;;;;oBAcR,AAAA,AAAQ,EAAE,AAAA,AAAM;;;;;;;;;;;;iBAYnB,AAAA,AAAK,KAAK,AAAA,AAAO,KAAK,AAAA,AAAO,SAAS,AAAA,AAAc;;;;;;;;;;;gBAWrD,AAAA,AAAQ,EAAE,AAAA,AAAgB;;;;;;;;;;;;;;;;iBAgBzB,AAAA,AAAQ,EAAE,AAAA,AAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA4CrC,AAAA,AAAK;;;;;;mBAMQ,AAAA,AAAqB"}
@@ -1,39 +0,0 @@
1
- //
2
-
3
- /**
4
- * Mark an object which can be destroyed
5
- * @class
6
- */
7
- export class Destroyable {
8
- seal () {
9
- let $ = this;
10
-
11
- for (let i in $) {
12
- if (this.hasOwnProperty(i)) {
13
- let config = Object.getOwnPropertyDescriptor($, i);
14
-
15
- if (!config || config.configurable) {
16
- Object.defineProperty($, i, config?.set || config?.get ? {
17
- configurable: false,
18
- get: config?.get,
19
- set: config?.set,
20
- enumerable: config?.enumerable ?? false
21
- } : {
22
- value: $[i],
23
- configurable: false,
24
- writable: config?.writable ?? false,
25
- enumerable: config?.enumerable ?? false
26
- });
27
- }
28
- }
29
- }
30
- }
31
-
32
- /**
33
- * Garbage collector method
34
- */
35
- $destroy () {
36
- }
37
- }
38
-
39
- //# sourceMappingURL=destroyable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/destroyable.js"],"names":[],"mappings":"GAAG,AAAK;;;;;;;;cAQM,AAAA,AAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;gBA0BN,AAAA,AAAM"}
@@ -1,49 +0,0 @@
1
- //
2
- const reportIt = "Report it here: https://gitlab.com/vasille-js/vasille-js/-/issues";
3
-
4
- /**
5
- * @return {string}
6
- */
7
- export function notOverwritten () {
8
- console.error("Vasille.js: Internal error", "Must be overwritten", reportIt);
9
- return "not-overwritten";
10
- }
11
-
12
- /**
13
- * @return {string}
14
- */
15
- export function internalError (msg) {
16
- console.error("Vasille.js: Internal error", msg, reportIt);
17
- return "internal-error";
18
- }
19
-
20
- /**
21
- * @return {string}
22
- */
23
- export function userError (msg, err) {
24
- console.error("Vasille.js: User error", msg);
25
- return err;
26
- }
27
-
28
- /**
29
- * @return {string}
30
- */
31
- export function typeError (msg) {
32
- return userError(msg, "type-error");
33
- }
34
-
35
- /**
36
- * @return {string}
37
- */
38
- export function notFound (msg) {
39
- return userError(msg, "not-found");
40
- }
41
-
42
- /**
43
- * @return {string}
44
- */
45
- export function wrongBinding (msg) {
46
- return userError(msg, "wrong-binding");
47
- }
48
-
49
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/errors.js"],"names":[],"mappings":"GAAG,AAAK;;;;;;kCAM0B,AAAA,AAAQ;;;;;;;;mCAQP,AAAA,AAAQ,EAAE,AAAA,AAAQ;;;;;;;;+BAQtB,AAAA,AAAQ,MAAM,AAAA,AAAQ,EAAE,AAAA,AAAQ;;;;;;;;+BAQhC,AAAA,AAAQ,EAAE,AAAA,AAAQ;;;;;;;8BAOnB,AAAA,AAAQ,EAAE,AAAA,AAAQ;;;;;;;kCAOd,AAAA,AAAQ,EAAE,AAAA,AAAQ"}
@@ -1,31 +0,0 @@
1
- //
2
- import { notOverwritten } from "./errors";
3
- import { IValue } from "./ivalue.js";
4
-
5
-
6
-
7
- /**
8
- * Mark an object which can be bound
9
- * @interface
10
- */
11
- export class IBind extends IValue {
12
- /**
13
- * Ensure the binding to be bound
14
- * @return a pointer to this
15
- * @throws must be overwritten
16
- */
17
- link () {
18
- throw notOverwritten();
19
- }
20
-
21
- /**
22
- * Ensure the binding to be unbound
23
- * @return a pointer to this
24
- * @throws must be overwritten
25
- */
26
- unlink () {
27
- throw notOverwritten();
28
- }
29
- }
30
-
31
- //# sourceMappingURL=ibind.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/ibind.js"],"names":[],"mappings":"GAAG,AAAK;;;;;;;;;;iCAUyB,AAAK;;;;;;YAM1B,AAAA,AAAM;;;;;;;;;cASJ,AAAA,AAAM"}
@@ -1,64 +0,0 @@
1
- //
2
-
3
- import { IValue } from "../index";
4
-
5
-
6
-
7
- /**
8
- * Represent a function encapsulated to a class
9
- */
10
- export class Callable {
11
- /**
12
- * Function which will resolve value
13
- * @type {Function}
14
- */
15
- func;
16
-
17
- /**
18
- * Encapsulates a function
19
- * @param func {Function} function to encapsulate
20
- */
21
- constructor (func) {
22
- Object.defineProperty(this, 'func', {
23
- value: func,
24
- writable: false,
25
- configurable: false
26
- });
27
- }
28
- }
29
-
30
- /**
31
- * Check the type of value
32
- * @param v {*} value
33
- * @param t {Function} type constructor
34
- * @return {boolean}
35
- */
36
- export function checkType (v, t) {
37
- if (v instanceof IValue) {
38
- v = v.$;
39
- }
40
- return (v instanceof t) || v === null ||
41
- (typeof v === "number" && t === Number) ||
42
- (typeof v === "string" && t === String) ||
43
- (typeof v === "boolean" && t === Boolean);
44
- }
45
-
46
- /**
47
- * Check if a type is a subtype
48
- * @param parent {Function} potential superclass
49
- * @param child {Function} potential subclass
50
- * @return {boolean}
51
- */
52
- export function isSubclassOf (parent, child) {
53
- let it = child;
54
- let isParent = false;
55
-
56
- while (it && !isParent) {
57
- isParent = it.prototype instanceof parent;
58
- it = it.prototype;
59
- }
60
-
61
- return isParent;
62
- }
63
-
64
- //# sourceMappingURL=idefinition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/idefinition.js"],"names":[],"mappings":"GAAG,AAAK;;;;;;;;;;;;;;SAcC,AAAA,AAAU;;;;;;sBAMG,AAAA,AAAU;;;;;;;;;;;;;;;6BAeH,AAAA,AAAK,IAAI,AAAA,AAAU,EAAE,AAAA,AAAS;;;;;;;;;;;;;;;;qCAgBtB,AAAA,AAAU,QAAQ,AAAA,AAAU,EAAE,AAAA,AAAS;WACjE,AAAA,AAAU"}
@@ -1,60 +0,0 @@
1
- //
2
- import { Destroyable } from "./destroyable.js";
3
- import { notOverwritten } from "./errors";
4
-
5
-
6
-
7
- /**
8
- * A interface which describes a value
9
- * @interface
10
- * @extends Destroyable
11
- */
12
- export class IValue extends Destroyable {
13
-
14
- /**
15
- * Used for strong type checking
16
- * @type {?Function}
17
- */
18
- type = null;
19
-
20
- /**
21
- * Gets the encapsulated value
22
- * @return {*} Must return a value
23
- * @throws Must be overwritten
24
- */
25
- get $ () {
26
- throw notOverwritten();
27
- }
28
-
29
- /**
30
- * Sets the encapsulated value
31
- * @param value {*} Reference to encapsulate
32
- * @return {IValue} A pointer to this
33
- * @throws Must be overwritten
34
- */
35
- set $ (value) {
36
- throw notOverwritten();
37
- }
38
-
39
- /**
40
- * Add a new handler to value change
41
- * @param handler {Function} The handler to add
42
- * @return {IValue} a pointer to this
43
- * @throws Must be overwritten
44
- */
45
- on (handler) {
46
- throw notOverwritten();
47
- }
48
-
49
- /**
50
- * Removes a handler of value change
51
- * @param handler {Function} the handler to remove
52
- * @return {IValue} a pointer to this
53
- * @throws Must be overwritten
54
- */
55
- off (handler) {
56
- throw notOverwritten();
57
- }
58
- }
59
-
60
- //# sourceMappingURL=ivalue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/interfaces/ivalue.js"],"names":[],"mappings":"GAAG,AAAK;;;;;;;;;;;mBAWW,AAAG;;;;;;SAMb,AAAA,AAAW;;;;;;;aAOP,AAAA,AAAG;;;;;;;;;;iBAUC,AAAA,AAAG,EAAE,AAAA,AAAM;;;;;;;;;;gBAUZ,AAAA,AAAU,EAAE,AAAA,AAAM;;;;;;;;;;iBAUjB,AAAA,AAAU,EAAE,AAAA,AAAM"}