ivue 0.0.32 → 0.1.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 (157) hide show
  1. package/.babelrc.json +14 -0
  2. package/.eslintrc.cjs +24 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/compiler.xml +7 -0
  5. package/.idea/infinite-vue.iml +10 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +11 -0
  7. package/.idea/modules.xml +8 -0
  8. package/.idea/php.xml +20 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/.vscode/extensions.json +3 -0
  11. package/LICENSE +19 -0
  12. package/README.md +31 -0
  13. package/demo/App.vue +72 -0
  14. package/demo/components/IVueTest.vue +298 -0
  15. package/demo/components/PreComponent.vue +13 -0
  16. package/demo/components/SubComponent2.vue +45 -0
  17. package/demo/components/TraitsComponent.vue +120 -0
  18. package/demo/components/useIVueTest.vue +136 -0
  19. package/demo/main.ts +21 -0
  20. package/demo/router/index.ts +14 -0
  21. package/demo/tests/IVueTests.ts +255 -0
  22. package/demo/tests/Mouse.ts +79 -0
  23. package/demo/tests/ParentIVueTests.ts +36 -0
  24. package/demo/tests/TApp.ts +15 -0
  25. package/demo/tests/TAuth.ts +23 -0
  26. package/demo/tests/TField.ts +84 -0
  27. package/demo/tests/TMessage.ts +52 -0
  28. package/demo/tests/TRouter.ts +18 -0
  29. package/demo/tests/TUser.ts +19 -0
  30. package/demo/tests/Test.ts +86 -0
  31. package/demo/tests/useField.ts +82 -0
  32. package/demo/tests/useIVueTests.ts +57 -0
  33. package/demo/vite.config.ts +13 -0
  34. package/dist/favicon.ico +0 -0
  35. package/dist/index.es.js +518 -0
  36. package/dist/index.umd.js +1 -0
  37. package/dist/src/behavior.d.ts +72 -0
  38. package/dist/src/config.d.ts +6 -0
  39. package/dist/src/index.d.ts +21 -0
  40. package/dist/src/ivue.d.ts +35 -0
  41. package/dist/src/kernel.d.ts +182 -0
  42. package/dist/src/traits/UseCapsule.d.ts +9 -0
  43. package/dist/src/traits/UseEmit.d.ts +3 -0
  44. package/dist/src/traits/UseInstance.d.ts +6 -0
  45. package/dist/src/traits/UseMounting.d.ts +11 -0
  46. package/dist/src/traits/UseRefs.d.ts +8 -0
  47. package/dist/src/traits/UseRoute.d.ts +3 -0
  48. package/dist/src/traits/UseRouter.d.ts +3 -0
  49. package/dist/src/traits/UseRouting.d.ts +6 -0
  50. package/dist/src/traits/UseTick.d.ts +4 -0
  51. package/dist/src/traits/UseVue.d.ts +13 -0
  52. package/dist/src/types/core.d.ts +46 -0
  53. package/dist/src/utils/dispose-garbage.d.ts +12 -0
  54. package/dist/src/utils/extend.d.ts +12 -0
  55. package/dist/src/utils/getters.d.ts +21 -0
  56. package/dist/src/utils/index.d.ts +7 -0
  57. package/dist/src/utils/is.d.ts +14 -0
  58. package/dist/src/utils/pre.d.ts +9 -0
  59. package/dist/src/utils/raw.d.ts +12 -0
  60. package/dist/src/utils/safe-class-name.d.ts +7 -0
  61. package/dist/src/utils/traits.d.ts +41 -0
  62. package/env.d.ts +1 -0
  63. package/index.html +13 -0
  64. package/package-lock.json +14305 -0
  65. package/package.json +89 -10
  66. package/public/favicon.ico +0 -0
  67. package/src/App/App.ts +27 -0
  68. package/src/App/Auth/Auth.ts +105 -0
  69. package/src/App/Auth/Auth.vue +98 -0
  70. package/src/App/Auth/Logout.vue +14 -0
  71. package/src/App/Auth/User.ts +6 -0
  72. package/src/App/BlackBox.ts +75 -0
  73. package/src/App/Config.ts +6 -0
  74. package/src/App/Generators/generators.ts +47 -0
  75. package/src/App/Home/Home.vue +16 -0
  76. package/src/App/Services/Http/FakeHttp.ts +8 -0
  77. package/src/App/Services/Http/Http.ts +51 -0
  78. package/src/App/Services/Message/Message.ts +49 -0
  79. package/src/App/Services/Message/Message.vue +15 -0
  80. package/src/App/Services/Navigation/Navigation.ts +83 -0
  81. package/src/App/Services/Navigation/Navigation.vue +59 -0
  82. package/src/App/Services/Routing/FakeRouter.ts +7 -0
  83. package/src/App/Services/Routing/NotFoundRoute.vue +13 -0
  84. package/src/App/Services/Routing/Router.ts +262 -0
  85. package/src/App/Services/Routing/Routes.ts +49 -0
  86. package/src/App/Stubs/SingleBookResultStub.ts +13 -0
  87. package/src/App/Traits/UseApp.ts +6 -0
  88. package/src/App/Traits/UseBlackline.ts +0 -0
  89. package/src/App/Traits/UseQuasar.ts +8 -0
  90. package/src/behavior.ts +269 -0
  91. package/src/config.ts +15 -0
  92. package/src/dev/dev-utils.ts +78 -0
  93. package/src/index.ts +83 -0
  94. package/src/ivue.ts +296 -0
  95. package/src/kernel.ts +810 -0
  96. package/src/tests/auth.spec.ts +48 -0
  97. package/src/traits/UseCapsule.ts +28 -0
  98. package/src/traits/UseEmit.ts +3 -0
  99. package/src/traits/UseInstance.ts +17 -0
  100. package/src/traits/UseMounting.ts +23 -0
  101. package/src/traits/UseRefs.ts +17 -0
  102. package/src/traits/UseRoute.ts +6 -0
  103. package/src/traits/UseRouter.ts +5 -0
  104. package/src/traits/UseRouting.ts +7 -0
  105. package/src/traits/UseTick.ts +5 -0
  106. package/src/traits/UseVue.ts +38 -0
  107. package/src/types/core.ts +64 -0
  108. package/src/utils/dispose-garbage.ts +34 -0
  109. package/src/utils/extend.ts +85 -0
  110. package/src/utils/getters.ts +62 -0
  111. package/src/utils/index.ts +16 -0
  112. package/src/utils/is.ts +22 -0
  113. package/src/utils/pre.ts +29 -0
  114. package/src/utils/raw.ts +19 -0
  115. package/src/utils/safe-class-name.ts +15 -0
  116. package/src/utils/traits.ts +121 -0
  117. package/tsconfig.app.json +47 -0
  118. package/tsconfig.json +14 -0
  119. package/tsconfig.node.json +14 -0
  120. package/tsconfig.vitest.json +9 -0
  121. package/vite.config.ts +55 -0
  122. package/vitest.config.ts +18 -0
  123. package/dist/index.js +0 -218
  124. package/docs/index.html +0 -195
  125. package/docs/index.json +0 -3
  126. package/docs/input.html +0 -41
  127. package/docs/items.html +0 -42
  128. package/gulpfile.js +0 -5
  129. package/src/components/checkbox.js +0 -47
  130. package/src/components/data.js +0 -6
  131. package/src/components/file.js +0 -40
  132. package/src/components/form.js +0 -7
  133. package/src/components/index.js +0 -15
  134. package/src/components/input.js +0 -80
  135. package/src/components/items.js +0 -65
  136. package/src/components/modal.js +0 -42
  137. package/src/components/paginate-old.js +0 -88
  138. package/src/components/paginate.js +0 -35
  139. package/src/components/select-search.js +0 -152
  140. package/src/components/select.js +0 -62
  141. package/src/components/submit.js +0 -10
  142. package/src/components/textarea.js +0 -72
  143. package/src/components/upload.js +0 -49
  144. package/src/directives/href.js +0 -10
  145. package/src/directives/index.js +0 -1
  146. package/src/filters/date.js +0 -3
  147. package/src/filters/datetime.js +0 -3
  148. package/src/filters/index.js +0 -4
  149. package/src/filters/json.js +0 -3
  150. package/src/filters/money.js +0 -3
  151. package/src/index.js +0 -4
  152. package/src/mixins/data.js +0 -13
  153. package/src/mixins/form.js +0 -85
  154. package/src/mixins/resource.js +0 -31
  155. package/src/services/client.js +0 -32
  156. package/src/services/flash.js +0 -17
  157. package/src/services/index.js +0 -2
package/src/ivue.ts ADDED
@@ -0,0 +1,296 @@
1
+ import { computed, reactive, toRef, effectScope, type EffectScope, getCurrentScope, onScopeDispose } from 'vue';
2
+
3
+ import type { Null, IVue, IVueToRefsObj, AnyClass, InferredArgs, Getters, Computeds } from "./types/core";
4
+
5
+ import { IVUE } from "./behavior";
6
+
7
+ import { getPrototypeGetters, getInstanceGetters } from './utils/getters'
8
+
9
+ /**
10
+ * Create ivue instance from class constructor.
11
+ *
12
+ * @param className
13
+ * @param args
14
+ * @returns @see IVue<T>
15
+ */
16
+ export function ivue<T extends AnyClass> (className: T, ...args: InferredArgs<T>): IVue<T> {
17
+ /**
18
+ * Define context variables.
19
+ */
20
+ let current: any = getCurrentScope(),
21
+ scope: EffectScope = effectScope(!!current),
22
+ getters = getPrototypeGetters(className.prototype),
23
+ computeds: any = getters.size ? {} : null
24
+ /**
25
+ * Initialize ivue reactive.
26
+ *
27
+ * This function is the same inside init(), ivue(), iobj() and ivueTransform() functions.
28
+ * It is copied over for performance reasons.
29
+ *
30
+ * The key idea is to keep this function as simple as possible.
31
+ */
32
+ // @ts-ignore
33
+ let vue = new Proxy(reactive(new className(...args)), {
34
+ get (target, prop) {
35
+ /**
36
+ * Is the prop a getter?
37
+ */
38
+ if (
39
+ getters.has(prop) // Prop is a getter
40
+ && vue.constructor?.behavior?.[prop] !== IVUE.OFF // Prop is not disabled
41
+ ) {
42
+ /**
43
+ * Convert getters to computeds lazily.
44
+ */
45
+ if (prop in computeds) {
46
+ /**
47
+ * Computed defined? Return .value of the computed.
48
+ */
49
+ return computeds[prop].value
50
+ } else {
51
+ /*
52
+ * Computed not defined? Define and run `.get` method inside computed while `.bind(vue)`.
53
+ */
54
+ scope?.run(() => computeds[prop] = computed(() => getters.get(prop).get!.bind(vue)()))
55
+ /**
56
+ * Return .value
57
+ */
58
+ return computeds[prop].value
59
+ }
60
+ }
61
+ /**
62
+ * toRefs() implementation.
63
+ */
64
+ if (prop === 'toRefs') {
65
+ return ivueToRefs(vue, getters, computeds, scope)
66
+ }
67
+ /**
68
+ * Return the default reactive vue prop.
69
+ */
70
+ return target[prop]
71
+ }
72
+ })
73
+ /**
74
+ * Functional way to perform the same as above, but less performant:
75
+ * vue = ivueTransform(reactive(new className(...args)), getters, computeds, scope, ...args)
76
+ */
77
+ /**
78
+ * Does vue.init() exist? Run it, reactive references can already be used inside .init()
79
+ */
80
+ if ('init' in vue) scope.run(() => vue.init())
81
+ /**
82
+ * Advanced garabage collection and disposal mechanism.
83
+ */
84
+ current ? onScopeDispose(() => {
85
+ scope?.stop()
86
+ let prop
87
+ for (prop in vue) delete vue[prop]
88
+ for (prop in computeds) delete computeds[prop]
89
+ current = (scope as any) = getters = computeds = vue = prop = null
90
+ }) : null
91
+ /**
92
+ * Return ivue instance.
93
+ */
94
+ return vue
95
+ }
96
+ /**
97
+ * Create ivue instance from an object.
98
+ *
99
+ * @param obj
100
+ * @returns
101
+ */
102
+ export function iobj<T extends object> (obj: T): T & IVueToRefsObj<T> {
103
+ /**
104
+ * Define context variables.
105
+ */
106
+ let current: Null<EffectScope | undefined> = getCurrentScope(),
107
+ scope: Null<EffectScope> = effectScope(!!current),
108
+ getters: Getters | null = getInstanceGetters(obj),
109
+ computeds: Computeds | any = getters.size ? {} : null,
110
+ vue = ivueTransform(reactive(obj), getters, computeds, scope)
111
+ /**
112
+ * Does vue.init() exist? Run it, reactive references can already be used inside .init()
113
+ */
114
+ if ('init' in vue) scope.run(() => vue.init())
115
+ /**
116
+ * Advanced garabage collection and disposal mechanism.
117
+ */
118
+ current ? onScopeDispose(() => {
119
+ scope?.stop()
120
+ let prop
121
+ for (prop in vue) delete vue[prop]
122
+ for (prop in computeds) delete computeds[prop]
123
+ current = scope = getters = computeds = (obj as any) = vue = prop = null
124
+ }) : null
125
+ /**
126
+ * Return ivue instance.
127
+ */
128
+ return vue
129
+ }
130
+ /**
131
+ * Pure VueJS Reactive Observable Class-based Architecture System.
132
+ *
133
+ * @param vue
134
+ * @param getters
135
+ * @param args Arguments are available when used via ivue(obj, ...args)
136
+ */
137
+ export function ivueTransform (vue: any, getters: Getters, computeds: Computeds, scope: EffectScope, ...args: undefined[]) {
138
+ /**
139
+ * Initialize ivue reactive.
140
+ *
141
+ * This function is the same inside init(), ivue(), iobj() and ivueTransform() functions.
142
+ * It is copied over for performance reasons.
143
+ *
144
+ * The key idea is to keep this function as simple as possible.
145
+ */
146
+ return new Proxy(vue, {
147
+ get (target, prop) {
148
+ /**
149
+ * Is the prop a getter?
150
+ */
151
+ if (
152
+ getters.has(prop) // Prop is a getter
153
+ && vue.constructor?.behavior?.[prop] !== IVUE.OFF // Prop is not disabled
154
+ ) {
155
+ /**
156
+ * Convert getters to computeds lazily.
157
+ */
158
+ if (prop in computeds) {
159
+ /**
160
+ * Computed defined? Return .value of the computed.
161
+ */
162
+ return computeds[prop].value
163
+ } else {
164
+ /*
165
+ * Computed not defined? Define and run `.get` method inside computed while `.bind(vue)`.
166
+ */
167
+ scope?.run(() => computeds[prop] = computed(() => getters.get(prop)?.get!.bind(vue)()))
168
+ /**
169
+ * Return .value
170
+ */
171
+ return computeds[prop].value
172
+ }
173
+ }
174
+ /**
175
+ * toRefs() implementation.
176
+ */
177
+ if (prop === 'toRefs') {
178
+ return ivueToRefs(vue, getters, computeds, scope)
179
+ }
180
+ /**
181
+ * Return the default reactive vue prop.
182
+ */
183
+ return target[prop]
184
+ }
185
+ })
186
+ }
187
+ /**
188
+ * Convert reactive to refs.
189
+ *
190
+ * @param vue @see IVue
191
+ * @param getters @see Getters
192
+ * @param computeds @see Computeds
193
+ * @param scope @see EffectScope
194
+ * @returns
195
+ */
196
+ export function ivueToRefs<T extends AnyClass> (vue: IVue<T>, getters: Getters, computeds: Computeds, scope: EffectScope) {
197
+
198
+ return function (...props: string[]) {
199
+ /**
200
+ * Resulting refs store.
201
+ */
202
+ const result: Record<string | symbol, any> = {}
203
+ /**
204
+ * Output specific props only, if props are specified.
205
+ */
206
+ if (props.length) {
207
+ for (let i = 0; i < props.length; i++) {
208
+ const prop = props[i]
209
+ /**
210
+ * Handle getters.
211
+ */
212
+ if (getters.has(prop)) {
213
+ if (prop in computeds) {
214
+ /**
215
+ * Store whole vue computed with .value
216
+ */
217
+ result[prop] = computeds[prop]
218
+ } else {
219
+ /**
220
+ * Initialize & store vue computed.
221
+ */
222
+ scope.run(() => result[prop] = computeds[prop] = computed(() => getters.get(prop)?.get!.bind(vue)()))
223
+ }
224
+ } else {
225
+ if (typeof vue[prop] === 'function') {
226
+ /**
227
+ * Bind method to vue, makes method destructuring point to right instance.
228
+ */
229
+ result[prop] = vue[prop].bind(vue)
230
+ } else {
231
+ /**
232
+ * Convert simple reactive prop to a Ref.
233
+ */
234
+ result[prop] = toRef(vue, prop)
235
+ }
236
+ }
237
+ }
238
+ } else {
239
+ /**
240
+ * Convert simple enumerable props.
241
+ */
242
+ for (const prop in vue) {
243
+ /**
244
+ * Skip a getter, it might be a computed, accessing it will cause a computation.
245
+ */
246
+ if (getters.has(prop)) continue;
247
+
248
+ if (typeof vue[prop] === 'function') {
249
+ /**
250
+ * Bind method to vue, makes method destructuring point to right instance.
251
+ */
252
+ result[prop] = vue[prop].bind(vue)
253
+ } else {
254
+ /**
255
+ * Convert simple reactive prop to a Ref.
256
+ */
257
+ result[prop] = toRef(vue, prop)
258
+ }
259
+ }
260
+ /**
261
+ * Convert getters (non enumerable by default in JS).
262
+ */
263
+ getters.forEach((getter, prop) => {
264
+ if (prop in computeds) {
265
+ /**
266
+ * Store whole vue computed with .value
267
+ */
268
+ result[prop] = computeds[prop]
269
+ } else {
270
+ /**
271
+ * Initialize vue computed.
272
+ */
273
+ scope.run(() => result[prop] = computeds[prop] = computed(() => getter.get!.bind(vue)()))
274
+ }
275
+ })
276
+ }
277
+ /**
278
+ * Return a Proxy to correctly forward the method calls to the vue object.
279
+ */
280
+ return new Proxy(vue, {
281
+ get: (target, key): any => {
282
+ if (key in result) {
283
+ /**
284
+ * Return a Ref.
285
+ */
286
+ return result[key]
287
+ } else if (key in target) {
288
+ /**
289
+ * Return a bound to vue method property, makes destructuring point to right instance.
290
+ */
291
+ return target[key].bind(vue)
292
+ }
293
+ }
294
+ })
295
+ }
296
+ }