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
package/img/favicon.svg CHANGED
@@ -1,19 +1,19 @@
1
1
  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
2
  <svg
3
- xmlns:dc="http://purl.org/dc/elements/1.1/"
4
- xmlns:cc="http://creativecommons.org/ns#"
5
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6
- xmlns:svg="http://www.w3.org/2000/svg"
7
- xmlns="http://www.w3.org/2000/svg"
8
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
9
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
10
3
  width="128"
11
4
  height="128"
12
5
  viewBox="0 0 33.866666 33.866668"
13
6
  version="1.1"
14
7
  id="svg8"
15
- inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07, custom)"
16
- sodipodi:docname="favicon.svg">
8
+ inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20, custom)"
9
+ sodipodi:docname="favicon.svg"
10
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
11
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
12
+ xmlns="http://www.w3.org/2000/svg"
13
+ xmlns:svg="http://www.w3.org/2000/svg"
14
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
15
+ xmlns:cc="http://creativecommons.org/ns#"
16
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
17
17
  <defs
18
18
  id="defs2">
19
19
  <meshgradient
@@ -136,126 +136,6 @@
136
136
  </meshpatch>
137
137
  </meshrow>
138
138
  </meshgradient>
139
- <meshgradient
140
- inkscape:collect="always"
141
- id="meshgradient9009"
142
- gradientUnits="userSpaceOnUse"
143
- gradientTransform="translate(34.739789,-3.9687501)"
144
- x="16.933334"
145
- y="15.875">
146
- <meshrow
147
- id="meshrow9021">
148
- <meshpatch
149
- id="meshpatch9019">
150
- <stop
151
- path="c 1.23913,-1.1377 7.05587,-10.5834 10.5833,-10.5833"
152
- style="stop-color:#916fd0;stop-opacity:1"
153
- id="stop9011" />
154
- <stop
155
- path="c 0.000261772,10.5833 7.92909e-05,10.5834 3.26994e-05,21.1666"
156
- style="stop-color:#0356f9;stop-opacity:1"
157
- id="stop9013" />
158
- <stop
159
- path="c -0.657012,0.635168 -7.05506,10.5835 -10.583,10.5836"
160
- style="stop-color:#00acba;stop-opacity:1"
161
- id="stop9015" />
162
- <stop
163
- path="c 5.79413e-05,-10.5833 -0.000541904,-10.5835 -0.000332699,-21.1669"
164
- style="stop-color:#6d02ad;stop-opacity:1"
165
- id="stop9017" />
166
- </meshpatch>
167
- </meshrow>
168
- </meshgradient>
169
- <meshgradient
170
- inkscape:collect="always"
171
- id="meshgradient9023"
172
- gradientUnits="userSpaceOnUse"
173
- gradientTransform="translate(34.739789,-3.9687501)"
174
- x="6.3500004"
175
- y="5.291667">
176
- <meshrow
177
- id="meshrow9035">
178
- <meshpatch
179
- id="meshpatch9033">
180
- <stop
181
- path="c 1.37143,0.64823 10.1115,10.0675 10.5833,10.5833"
182
- style="stop-color:#be1f00;stop-opacity:1"
183
- id="stop9025" />
184
- <stop
185
- path="c -1.19405e-05,10.5833 3.24005e-05,10.5834 3.31685e-05,21.1667"
186
- style="stop-color:#ff5a8c;stop-opacity:1"
187
- id="stop9027" />
188
- <stop
189
- path="c -0.855487,-0.330918 -9.89978,-9.988 -10.583,-10.5832"
190
- style="stop-color:#9218c5;stop-opacity:1"
191
- id="stop9029" />
192
- <stop
193
- path="c 0.000311319,-10.5833 8.5239e-05,-10.5833 -0.000333169,-21.1668"
194
- style="stop-color:#e31818;stop-opacity:1"
195
- id="stop9031" />
196
- </meshpatch>
197
- </meshrow>
198
- </meshgradient>
199
- <meshgradient
200
- inkscape:collect="always"
201
- id="meshgradient9037"
202
- gradientUnits="userSpaceOnUse"
203
- gradientTransform="matrix(1.2486707,0,0,1.2486707,30.528966,-9.3986788)"
204
- x="6.3500004"
205
- y="5.291667">
206
- <meshrow
207
- id="meshrow9049">
208
- <meshpatch
209
- id="meshpatch9047">
210
- <stop
211
- path="c 1.37143,0.64823 10.1115,10.0675 10.5833,10.5833"
212
- style="stop-color:#be1f00;stop-opacity:1"
213
- id="stop9039" />
214
- <stop
215
- path="c -1.19405e-05,10.5833 3.24005e-05,10.5834 3.31685e-05,21.1667"
216
- style="stop-color:#ff5a8c;stop-opacity:1"
217
- id="stop9041" />
218
- <stop
219
- path="c -0.855487,-0.330918 -9.89978,-9.988 -10.583,-10.5832"
220
- style="stop-color:#9218c5;stop-opacity:1"
221
- id="stop9043" />
222
- <stop
223
- path="c 0.000311319,-10.5833 8.5239e-05,-10.5833 -0.000333169,-21.1668"
224
- style="stop-color:#e31818;stop-opacity:1"
225
- id="stop9045" />
226
- </meshpatch>
227
- </meshrow>
228
- </meshgradient>
229
- <meshgradient
230
- inkscape:collect="always"
231
- id="meshgradient9051"
232
- gradientUnits="userSpaceOnUse"
233
- gradientTransform="matrix(1.2486706,0,0,1.2486706,30.528966,-9.3986787)"
234
- x="16.933334"
235
- y="15.875">
236
- <meshrow
237
- id="meshrow9063">
238
- <meshpatch
239
- id="meshpatch9061">
240
- <stop
241
- path="c 1.23913,-1.1377 7.05587,-10.5834 10.5833,-10.5833"
242
- style="stop-color:#916fd0;stop-opacity:1"
243
- id="stop9053" />
244
- <stop
245
- path="c 0.000261772,10.5833 7.92909e-05,10.5834 3.26994e-05,21.1666"
246
- style="stop-color:#0356f9;stop-opacity:1"
247
- id="stop9055" />
248
- <stop
249
- path="c -0.657012,0.635168 -7.05506,10.5835 -10.583,10.5836"
250
- style="stop-color:#00acba;stop-opacity:1"
251
- id="stop9057" />
252
- <stop
253
- path="c 5.79413e-05,-10.5833 -0.000541904,-10.5835 -0.000332699,-21.1669"
254
- style="stop-color:#6d02ad;stop-opacity:1"
255
- id="stop9059" />
256
- </meshpatch>
257
- </meshrow>
258
- </meshgradient>
259
139
  </defs>
260
140
  <sodipodi:namedview
261
141
  id="base"
@@ -264,23 +144,24 @@
264
144
  borderopacity="1.0"
265
145
  inkscape:pageopacity="0"
266
146
  inkscape:pageshadow="2"
267
- inkscape:zoom="4"
268
- inkscape:cx="2.3939181"
269
- inkscape:cy="55.008569"
147
+ inkscape:zoom="2.8284271"
148
+ inkscape:cx="61.871843"
149
+ inkscape:cy="42.77996"
270
150
  inkscape:document-units="px"
271
151
  inkscape:current-layer="layer1"
272
152
  inkscape:document-rotation="0"
273
153
  showgrid="false"
274
154
  units="px"
275
155
  inkscape:window-width="2560"
276
- inkscape:window-height="1402"
156
+ inkscape:window-height="1407"
277
157
  inkscape:window-x="0"
278
- inkscape:window-y="0"
158
+ inkscape:window-y="1070"
279
159
  inkscape:window-maximized="1"
280
160
  inkscape:snap-smooth-nodes="true"
281
161
  showguides="false"
282
162
  inkscape:guide-bbox="true"
283
- inkscape:snap-global="false">
163
+ inkscape:snap-global="false"
164
+ inkscape:pagecheckerboard="1">
284
165
  <inkscape:grid
285
166
  type="axonomgrid"
286
167
  id="grid833"
@@ -314,7 +195,7 @@
314
195
  <dc:format>image/svg+xml</dc:format>
315
196
  <dc:type
316
197
  rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
317
- <dc:title></dc:title>
198
+ <dc:title />
318
199
  </cc:Work>
319
200
  </rdf:RDF>
320
201
  </metadata>
@@ -352,74 +233,6 @@
352
233
  d="m 18.135611,10.951879 8.415944,-6.313094 c 1.202276,-0.9018707 2.404555,0 2.404555,1.8037415 V 17.264973 c 0,1.803743 -1.202279,4.509354 -2.404555,5.411225 l -8.415944,6.313095 c -1.202277,0.90187 -1.202277,0.90187 -1.202277,-0.90187 V 13.657491 c 0,-1.803741 0,-1.803741 1.202277,-2.705612 z"
353
234
  id="path3563"
354
235
  sodipodi:nodetypes="ccccccccc" />
355
- <path
356
- style="fill:none;fill-opacity:1;stroke:#626262;stroke-width:2.11667;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
357
- d="M -17.459463,16.793017 V 27.37635 c -0.32898,1.814392 -1.96621,2.207512 -3.175,1.058333 l -1.058334,-1.058333 c -0.943934,-1.001579 -1.110148,-1.943806 -1.058333,-3.175"
358
- id="path8923"
359
- sodipodi:nodetypes="ccccc" />
360
- <path
361
- style="fill:none;fill-opacity:1;stroke:#626262;stroke-width:2.11667;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
362
- d="m -11.66608,30.691666 3.1750002,-3.175 c 2.116666,-2.116667 1.134454,-4.897499 1.058333,-7.408334 l -4.2333332,4.233334 c -0.173754,-3.226578 -0.805766,-5.357149 1.058333,-7.408334 l 3.1750002,-3.175"
363
- id="path8925"
364
- sodipodi:nodetypes="cccccc" />
365
- <path
366
- style="fill:none;fill-opacity:1;stroke:#d4d4d4;stroke-width:2.11667;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
367
- d="M -16.933334,17.991667 V 28.575 c -0.32898,1.814392 -1.96621,2.207512 -3.175,1.058333 L -21.166668,28.575 c -0.943935,-1.001579 -1.110148,-1.943806 -1.058333,-3.175"
368
- id="path8927"
369
- sodipodi:nodetypes="ccccc" />
370
- <path
371
- style="fill:none;fill-opacity:1;stroke:#d4d4d4;stroke-width:2.11667;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
372
- d="m -12.700001,32.808334 3.1750002,-3.175 c 2.116666,-2.116667 1.134454,-4.897499 1.058333,-7.408334 l -4.2333332,4.233334 c -0.173754,-3.226578 -0.805766,-5.357149 1.058333,-7.408334 l 3.1750002,-3.175"
373
- id="path8929"
374
- sodipodi:nodetypes="cccccc" />
375
- <path
376
- style="fill:url(#meshgradient9051);fill-opacity:1;stroke:none;stroke-width:0.660755"
377
- d="M 52.994632,9.1024579 62.2452,-0.14811027 c 1.32151,-1.32150993 2.64302,10e-8 2.64302,2.64301917 V 18.353026 c 0,2.64302 -1.32151,6.60755 -2.64302,7.929059 l -9.250568,9.250569 c -1.321509,1.321509 -1.321509,1.321509 -1.321509,-1.321509 V 13.066988 c 0,-2.64302 0,-2.64302 1.321509,-3.9645301 z"
378
- id="path8991"
379
- sodipodi:nodetypes="ccccccccc" />
380
- <path
381
- style="fill:#000000;fill-opacity:0.624225;stroke:none;stroke-width:0.671131"
382
- d="m 53.015384,8.9648239 9.395834,-9.39583427 c 1.342262,-1.34226213 2.684524,1e-7 2.684524,2.68452367 V 18.360657 c 0,2.684525 -1.342262,6.711311 -2.684524,8.053572 l -9.395834,9.395835 c -1.342261,1.342261 -1.342261,1.342261 -1.342261,-1.342261 V 12.99161 c 0,-2.684524 0,-2.684524 1.342261,-4.0267861 z"
383
- id="path8993"
384
- sodipodi:nodetypes="ccccccccc" />
385
- <path
386
- style="fill:url(#meshgradient9037);fill-opacity:1;stroke:none;stroke-width:0.660755"
387
- d="m 41.101044,-0.14811017 9.250568,9.25056907 c 1.321511,1.3215091 1.321511,1.3215091 1.321511,3.9645291 v 21.144157 c 0,2.643019 0,2.643019 -1.321511,1.321509 l -9.250568,-9.250569 c -1.32151,-1.321509 -2.643019,-5.286039 -2.643019,-7.929059 V 2.4949089 c 0,-2.64301907 1.321509,-3.964529 2.643019,-2.64301907 z"
388
- id="path8995"
389
- sodipodi:nodetypes="ccccccccc" />
390
- <path
391
- style="fill:#000000;fill-opacity:0.624225;stroke:none;stroke-width:0.671131"
392
- d="M 40.935027,-0.43101027 50.33086,8.9648249 c 1.342263,1.3422611 1.342263,1.3422611 1.342263,4.0267851 v 21.476193 c 0,2.684523 0,2.684523 -1.342263,1.342261 L 40.935027,26.414229 C 39.592764,25.071968 38.250502,21.045182 38.250502,18.360657 V 2.2535133 c 0,-2.68452357 1.342262,-4.0267857 2.684525,-2.68452357 z"
393
- id="path8997"
394
- sodipodi:nodetypes="ccccccccc" />
395
- <path
396
- style="fill:url(#meshgradient9023);fill-opacity:1;stroke:none;stroke-width:0.529167"
397
- d="m 43.206456,3.4395834 7.408333,7.4083336 c 1.058334,1.058333 1.058334,1.058333 1.058334,3.175 v 16.933334 c 0,2.116666 0,2.116666 -1.058334,1.058333 L 43.206456,24.60625 c -1.058333,-1.058333 -2.116667,-4.233333 -2.116667,-6.35 V 5.5562501 c 0,-2.1166667 1.058334,-3.1750001 2.116667,-2.1166667 z"
398
- id="path8999"
399
- sodipodi:nodetypes="ccccccccc" />
400
- <path
401
- style="fill:url(#meshgradient9009);fill-opacity:1;stroke:none;stroke-width:0.529167"
402
- d="m 52.731456,10.847917 7.408333,-7.4083337 c 1.058333,-1.0583334 2.116667,1e-7 2.116667,2.1166668 V 18.25625 c 0,2.116667 -1.058334,5.291667 -2.116667,6.35 l -7.408333,7.408334 c -1.058333,1.058333 -1.058333,1.058333 -1.058333,-1.058333 V 14.022917 c 0,-2.116667 0,-2.116667 1.058333,-3.175 z"
403
- id="path9001"
404
- sodipodi:nodetypes="ccccccccc" />
405
- <circle
406
- style="fill:#ffffff;fill-opacity:0.624225;stroke:none;stroke-width:2.11667;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
407
- id="circle9003"
408
- cx="46.423473"
409
- cy="21.526756"
410
- r="2.9747102" />
411
- <circle
412
- style="fill:#ffffff;fill-opacity:0.624225;stroke:none;stroke-width:2.11667;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
413
- id="circle9005"
414
- cx="55.993061"
415
- cy="21.751263"
416
- r="2.9747102" />
417
- <circle
418
- style="fill:#ffffff;fill-opacity:0.624225;stroke:none;stroke-width:2.11667;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
419
- id="circle9007"
420
- cx="57.98555"
421
- cy="12.986158"
422
- r="2.9747102" />
423
236
  <circle
424
237
  style="fill:#ffffff;fill-opacity:0.624225;stroke:none;stroke-width:1.80374;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
425
238
  id="circle9065"
@@ -0,0 +1,32 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Represents an Attribute binding description
4
+ * @class AttributeBinding
5
+ * @extends Binding
6
+ */
7
+ export class AttributeBinding extends Binding {
8
+ /**
9
+ * Constructs an attribute binding description
10
+ * @param node {INode} the vasille node
11
+ * @param name {String} the name of attribute
12
+ * @param value {IValue} value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ }
17
+ /**
18
+ * Generates a function which updates the attribute value
19
+ * @param name {String} The name of attribute
20
+ * @returns {Function} a function which will update attribute value
21
+ */
22
+ bound(name) {
23
+ return function (node, value) {
24
+ if (value) {
25
+ node.app.$run.setAttribute(node.node, name, value);
26
+ }
27
+ else {
28
+ node.app.$run.removeAttribute(node.node, name);
29
+ }
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,39 @@
1
+ import { Destroyable } from "../core/destroyable";
2
+ import { notOverwritten } from "../core/errors";
3
+ /**
4
+ * Describe a common binding logic
5
+ * @class Binding
6
+ * @extends Destroyable
7
+ */
8
+ export class Binding extends Destroyable {
9
+ /**
10
+ * Constructs a common binding logic
11
+ * @param node {INode} the vasille node
12
+ * @param name {String} the name of property/attribute/class
13
+ * @param value {IValue} the value to bind
14
+ */
15
+ constructor(node, name, value) {
16
+ super();
17
+ this.updateFunc = this.bound(name).bind(null, node);
18
+ this.binding = value;
19
+ this.binding.on(this.updateFunc);
20
+ this.updateFunc(this.binding.$);
21
+ this.$seal();
22
+ }
23
+ /**
24
+ * Is a virtual function to get the specific bind function
25
+ * @param name {String} the name of attribute/property
26
+ * @returns {Function} a function to update attribute/property value
27
+ * @throws Always throws and must be overloaded in child class
28
+ */
29
+ bound(name) {
30
+ throw notOverwritten();
31
+ }
32
+ /**
33
+ * Just clear bindings
34
+ */
35
+ $destroy() {
36
+ this.binding.off(this.updateFunc);
37
+ super.$destroy();
38
+ }
39
+ }
@@ -0,0 +1,51 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Represents a HTML class binding description
4
+ * @class ClassBinding
5
+ * @extends Binding
6
+ */
7
+ export class ClassBinding extends Binding {
8
+ /**
9
+ * Constructs an HTML class binding description
10
+ * @param node {INode} the vasille node
11
+ * @param name {String} the name of class
12
+ * @param value {IValue} the value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ this.$seal();
17
+ }
18
+ /**
19
+ * Generates a function which updates the html class value
20
+ * @param name {String} The name of attribute
21
+ * @returns {Function} a function which will update attribute value
22
+ */
23
+ bound(name) {
24
+ let current = null;
25
+ function addClass(node, cl) {
26
+ node.app.$run.addClass(node.node, cl);
27
+ }
28
+ function removeClass(node, cl) {
29
+ node.app.$run.removeClass(node.node, cl);
30
+ }
31
+ return (node, value) => {
32
+ if (value !== current) {
33
+ if (typeof current === "string" && current !== "") {
34
+ removeClass(node, current);
35
+ }
36
+ if (typeof value === "boolean") {
37
+ if (value) {
38
+ addClass(node, name);
39
+ }
40
+ else {
41
+ removeClass(node, name);
42
+ }
43
+ }
44
+ else if (typeof value === "string" && value !== "") {
45
+ addClass(node, value);
46
+ }
47
+ current = value;
48
+ }
49
+ };
50
+ }
51
+ }
@@ -0,0 +1,29 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Describes a style attribute binding
4
+ * @class StyleBinding
5
+ * @extends Binding
6
+ */
7
+ export class StyleBinding extends Binding {
8
+ /**
9
+ * Constructs a style binding attribute
10
+ * @param node {INode} the vasille node
11
+ * @param name {string} the name of style property
12
+ * @param value {IValue} the value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ }
17
+ /**
18
+ * Generates a function to update style property value
19
+ * @param name {string}
20
+ * @returns {Function} a function to update style property
21
+ */
22
+ bound(name) {
23
+ return function (node, value) {
24
+ if (node.node instanceof HTMLElement) {
25
+ node.app.$run.setStyle(node.node, name, value);
26
+ }
27
+ };
28
+ }
29
+ }
@@ -0,0 +1,178 @@
1
+ import { Destroyable } from "./destroyable.js";
2
+ import { wrongBinding } from "./errors";
3
+ import { IValue } from "./ivalue.js";
4
+ import { Expression } from "../value/expression";
5
+ import { Reference } from "../value/reference";
6
+ import { Pointer } from "../value/pointer";
7
+ import { Mirror } from "../value/mirror";
8
+ /**
9
+ * Private stuff of a reactive object
10
+ * @class ReactivePrivate
11
+ * @extends Destroyable
12
+ */
13
+ export class ReactivePrivate extends Destroyable {
14
+ constructor() {
15
+ super();
16
+ /**
17
+ * A list of user-defined values
18
+ * @type {Set}
19
+ */
20
+ this.watch = new Set;
21
+ /**
22
+ * A list of user-defined bindings
23
+ * @type {Set}
24
+ */
25
+ this.bindings = new Set;
26
+ /**
27
+ * A list of user defined models
28
+ */
29
+ this.models = new Set;
30
+ /**
31
+ * Reactivity switch state
32
+ * @type {boolean}
33
+ */
34
+ this.enabled = true;
35
+ /**
36
+ * The frozen state of object
37
+ * @type {boolean}
38
+ */
39
+ this.frozen = false;
40
+ this.$seal();
41
+ }
42
+ $destroy() {
43
+ var _a;
44
+ this.watch.forEach(value => value.$destroy());
45
+ this.watch.clear();
46
+ this.bindings.forEach(binding => binding.$destroy());
47
+ this.bindings.clear();
48
+ (_a = this.freezeExpr) === null || _a === void 0 ? void 0 : _a.$destroy();
49
+ super.$destroy();
50
+ }
51
+ }
52
+ /**
53
+ * A reactive object
54
+ * @class Reactive
55
+ * @extends Destroyable
56
+ */
57
+ export class Reactive extends Destroyable {
58
+ constructor($) {
59
+ super();
60
+ this.$ = $ || new ReactivePrivate;
61
+ }
62
+ /**
63
+ * Create a reference
64
+ * @param value {*} value to reference
65
+ */
66
+ $ref(value) {
67
+ const $ = this.$;
68
+ const ref = new Reference(value);
69
+ $.watch.add(ref);
70
+ return ref;
71
+ }
72
+ /**
73
+ * Create a mirror
74
+ * @param value {IValue} value to mirror
75
+ * @param forwardOnly {boolean} forward only sync
76
+ */
77
+ $mirror(value, forwardOnly = false) {
78
+ const mirror = new Mirror(value, forwardOnly);
79
+ this.$.watch.add(mirror);
80
+ return mirror;
81
+ }
82
+ /**
83
+ * Creates a pointer
84
+ * @param value {*} default value to point
85
+ * @param forwardOnly {boolean} forward only sync
86
+ */
87
+ $point(value, forwardOnly = false) {
88
+ const $ = this.$;
89
+ const ref = value instanceof IValue ? value : new Reference(value);
90
+ const pointer = new Pointer(ref, forwardOnly);
91
+ // when value is an ivalue will be equal to ref
92
+ if (value !== ref) {
93
+ $.watch.add(ref);
94
+ }
95
+ $.watch.add(pointer);
96
+ return pointer;
97
+ }
98
+ /**
99
+ * Register a model
100
+ * @param model
101
+ */
102
+ $register(model) {
103
+ this.$.models.add(model);
104
+ return model;
105
+ }
106
+ $watch(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
107
+ const $ = this.$;
108
+ $.watch.add(new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9));
109
+ }
110
+ $bind(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
111
+ const res = new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9);
112
+ const $ = this.$;
113
+ $.watch.add(res);
114
+ return res;
115
+ }
116
+ /**
117
+ * Enable reactivity of fields
118
+ */
119
+ $enable() {
120
+ const $ = this.$;
121
+ if (!$.enabled) {
122
+ $.watch.forEach(watcher => {
123
+ watcher.enable();
124
+ });
125
+ $.models.forEach(model => {
126
+ model.enableReactivity();
127
+ });
128
+ $.enabled = true;
129
+ }
130
+ }
131
+ /**
132
+ * Disable reactivity of fields
133
+ */
134
+ $disable() {
135
+ const $ = this.$;
136
+ if ($.enabled) {
137
+ $.watch.forEach(watcher => {
138
+ watcher.disable();
139
+ });
140
+ $.models.forEach(model => {
141
+ model.disableReactivity();
142
+ });
143
+ $.enabled = false;
144
+ }
145
+ }
146
+ /**
147
+ * Disable/Enable reactivity of object fields with feedback
148
+ * @param cond {IValue} show condition
149
+ * @param onOff {function} on show feedback
150
+ * @param onOn {function} on hide feedback
151
+ */
152
+ $bindAlive(cond, onOff, onOn) {
153
+ const $ = this.$;
154
+ if ($.freezeExpr) {
155
+ throw wrongBinding("this component already have a freeze state");
156
+ }
157
+ if ($.watch.has(cond)) {
158
+ throw wrongBinding("freeze state must be bound to an external component");
159
+ }
160
+ $.freezeExpr = new Expression((cond) => {
161
+ $.frozen = !cond;
162
+ if (cond) {
163
+ onOn === null || onOn === void 0 ? void 0 : onOn();
164
+ this.$enable();
165
+ }
166
+ else {
167
+ onOff === null || onOff === void 0 ? void 0 : onOff();
168
+ this.$disable();
169
+ }
170
+ }, true, cond);
171
+ return this;
172
+ }
173
+ $destroy() {
174
+ super.$destroy();
175
+ this.$.$destroy();
176
+ this.$ = null;
177
+ }
178
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Mark an object which can be destroyed
3
+ * @class Destroyable
4
+ */
5
+ export class Destroyable {
6
+ /**
7
+ * Make object fields non configurable
8
+ * @protected
9
+ */
10
+ $seal() {
11
+ const $ = this;
12
+ Object.keys($).forEach(i => {
13
+ // eslint-disable-next-line no-prototype-builtins
14
+ if (this.hasOwnProperty(i)) {
15
+ const config = Object.getOwnPropertyDescriptor($, i);
16
+ if (config.configurable) {
17
+ let descriptor;
18
+ if (config.set || config.get) {
19
+ descriptor = {
20
+ configurable: false,
21
+ get: config.get,
22
+ set: config.set,
23
+ enumerable: config.enumerable
24
+ };
25
+ }
26
+ else {
27
+ descriptor = {
28
+ value: $[i],
29
+ configurable: false,
30
+ writable: config.writable,
31
+ enumerable: config.enumerable
32
+ };
33
+ }
34
+ Object.defineProperty($, i, descriptor);
35
+ }
36
+ }
37
+ });
38
+ }
39
+ /**
40
+ * Garbage collector method
41
+ */
42
+ $destroy() {
43
+ // nothing here
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ const reportIt = "Report it here: https://gitlab.com/vasille-js/vasille-js/-/issues";
2
+ export function notOverwritten() {
3
+ console.error("Vasille-SFP: Internal error", "Must be overwritten", reportIt);
4
+ return "not-overwritten";
5
+ }
6
+ export function internalError(msg) {
7
+ console.error("Vasille-SFP: Internal error", msg, reportIt);
8
+ return "internal-error";
9
+ }
10
+ export function userError(msg, err) {
11
+ console.error("Vasille-SFP: User error", msg);
12
+ return err;
13
+ }
14
+ export function wrongBinding(msg) {
15
+ return userError(msg, "wrong-binding");
16
+ }