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.
- package/.babelrc.json +14 -0
- package/.eslintrc.cjs +24 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/compiler.xml +7 -0
- package/.idea/infinite-vue.iml +10 -0
- package/.idea/inspectionProfiles/Project_Default.xml +11 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +20 -0
- package/.idea/vcs.xml +6 -0
- package/.vscode/extensions.json +3 -0
- package/LICENSE +19 -0
- package/README.md +31 -0
- package/demo/App.vue +72 -0
- package/demo/components/IVueTest.vue +298 -0
- package/demo/components/PreComponent.vue +13 -0
- package/demo/components/SubComponent2.vue +45 -0
- package/demo/components/TraitsComponent.vue +120 -0
- package/demo/components/useIVueTest.vue +136 -0
- package/demo/main.ts +21 -0
- package/demo/router/index.ts +14 -0
- package/demo/tests/IVueTests.ts +255 -0
- package/demo/tests/Mouse.ts +79 -0
- package/demo/tests/ParentIVueTests.ts +36 -0
- package/demo/tests/TApp.ts +15 -0
- package/demo/tests/TAuth.ts +23 -0
- package/demo/tests/TField.ts +84 -0
- package/demo/tests/TMessage.ts +52 -0
- package/demo/tests/TRouter.ts +18 -0
- package/demo/tests/TUser.ts +19 -0
- package/demo/tests/Test.ts +86 -0
- package/demo/tests/useField.ts +82 -0
- package/demo/tests/useIVueTests.ts +57 -0
- package/demo/vite.config.ts +13 -0
- package/dist/favicon.ico +0 -0
- package/dist/index.es.js +518 -0
- package/dist/index.umd.js +1 -0
- package/dist/src/behavior.d.ts +72 -0
- package/dist/src/config.d.ts +6 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/ivue.d.ts +35 -0
- package/dist/src/kernel.d.ts +182 -0
- package/dist/src/traits/UseCapsule.d.ts +9 -0
- package/dist/src/traits/UseEmit.d.ts +3 -0
- package/dist/src/traits/UseInstance.d.ts +6 -0
- package/dist/src/traits/UseMounting.d.ts +11 -0
- package/dist/src/traits/UseRefs.d.ts +8 -0
- package/dist/src/traits/UseRoute.d.ts +3 -0
- package/dist/src/traits/UseRouter.d.ts +3 -0
- package/dist/src/traits/UseRouting.d.ts +6 -0
- package/dist/src/traits/UseTick.d.ts +4 -0
- package/dist/src/traits/UseVue.d.ts +13 -0
- package/dist/src/types/core.d.ts +46 -0
- package/dist/src/utils/dispose-garbage.d.ts +12 -0
- package/dist/src/utils/extend.d.ts +12 -0
- package/dist/src/utils/getters.d.ts +21 -0
- package/dist/src/utils/index.d.ts +7 -0
- package/dist/src/utils/is.d.ts +14 -0
- package/dist/src/utils/pre.d.ts +9 -0
- package/dist/src/utils/raw.d.ts +12 -0
- package/dist/src/utils/safe-class-name.d.ts +7 -0
- package/dist/src/utils/traits.d.ts +41 -0
- package/env.d.ts +1 -0
- package/index.html +13 -0
- package/package-lock.json +14305 -0
- package/package.json +89 -10
- package/public/favicon.ico +0 -0
- package/src/App/App.ts +27 -0
- package/src/App/Auth/Auth.ts +105 -0
- package/src/App/Auth/Auth.vue +98 -0
- package/src/App/Auth/Logout.vue +14 -0
- package/src/App/Auth/User.ts +6 -0
- package/src/App/BlackBox.ts +75 -0
- package/src/App/Config.ts +6 -0
- package/src/App/Generators/generators.ts +47 -0
- package/src/App/Home/Home.vue +16 -0
- package/src/App/Services/Http/FakeHttp.ts +8 -0
- package/src/App/Services/Http/Http.ts +51 -0
- package/src/App/Services/Message/Message.ts +49 -0
- package/src/App/Services/Message/Message.vue +15 -0
- package/src/App/Services/Navigation/Navigation.ts +83 -0
- package/src/App/Services/Navigation/Navigation.vue +59 -0
- package/src/App/Services/Routing/FakeRouter.ts +7 -0
- package/src/App/Services/Routing/NotFoundRoute.vue +13 -0
- package/src/App/Services/Routing/Router.ts +262 -0
- package/src/App/Services/Routing/Routes.ts +49 -0
- package/src/App/Stubs/SingleBookResultStub.ts +13 -0
- package/src/App/Traits/UseApp.ts +6 -0
- package/src/App/Traits/UseBlackline.ts +0 -0
- package/src/App/Traits/UseQuasar.ts +8 -0
- package/src/behavior.ts +269 -0
- package/src/config.ts +15 -0
- package/src/dev/dev-utils.ts +78 -0
- package/src/index.ts +83 -0
- package/src/ivue.ts +296 -0
- package/src/kernel.ts +810 -0
- package/src/tests/auth.spec.ts +48 -0
- package/src/traits/UseCapsule.ts +28 -0
- package/src/traits/UseEmit.ts +3 -0
- package/src/traits/UseInstance.ts +17 -0
- package/src/traits/UseMounting.ts +23 -0
- package/src/traits/UseRefs.ts +17 -0
- package/src/traits/UseRoute.ts +6 -0
- package/src/traits/UseRouter.ts +5 -0
- package/src/traits/UseRouting.ts +7 -0
- package/src/traits/UseTick.ts +5 -0
- package/src/traits/UseVue.ts +38 -0
- package/src/types/core.ts +64 -0
- package/src/utils/dispose-garbage.ts +34 -0
- package/src/utils/extend.ts +85 -0
- package/src/utils/getters.ts +62 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/is.ts +22 -0
- package/src/utils/pre.ts +29 -0
- package/src/utils/raw.ts +19 -0
- package/src/utils/safe-class-name.ts +15 -0
- package/src/utils/traits.ts +121 -0
- package/tsconfig.app.json +47 -0
- package/tsconfig.json +14 -0
- package/tsconfig.node.json +14 -0
- package/tsconfig.vitest.json +9 -0
- package/vite.config.ts +55 -0
- package/vitest.config.ts +18 -0
- package/dist/index.js +0 -218
- package/docs/index.html +0 -195
- package/docs/index.json +0 -3
- package/docs/input.html +0 -41
- package/docs/items.html +0 -42
- package/gulpfile.js +0 -5
- package/src/components/checkbox.js +0 -47
- package/src/components/data.js +0 -6
- package/src/components/file.js +0 -40
- package/src/components/form.js +0 -7
- package/src/components/index.js +0 -15
- package/src/components/input.js +0 -80
- package/src/components/items.js +0 -65
- package/src/components/modal.js +0 -42
- package/src/components/paginate-old.js +0 -88
- package/src/components/paginate.js +0 -35
- package/src/components/select-search.js +0 -152
- package/src/components/select.js +0 -62
- package/src/components/submit.js +0 -10
- package/src/components/textarea.js +0 -72
- package/src/components/upload.js +0 -49
- package/src/directives/href.js +0 -10
- package/src/directives/index.js +0 -1
- package/src/filters/date.js +0 -3
- package/src/filters/datetime.js +0 -3
- package/src/filters/index.js +0 -4
- package/src/filters/json.js +0 -3
- package/src/filters/money.js +0 -3
- package/src/index.js +0 -4
- package/src/mixins/data.js +0 -13
- package/src/mixins/form.js +0 -85
- package/src/mixins/resource.js +0 -31
- package/src/services/client.js +0 -32
- package/src/services/flash.js +0 -17
- 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
|
+
}
|