ivue 1.2.0 → 1.2.1

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/dist/index.es.js CHANGED
@@ -3,50 +3,50 @@ const d = /* @__PURE__ */ new Map();
3
3
  function D(e) {
4
4
  if (d.has(e))
5
5
  return d.get(e);
6
- const o = /* @__PURE__ */ new Map();
6
+ const n = /* @__PURE__ */ new Map();
7
7
  let t = e.prototype;
8
8
  for (; t.constructor !== Object; )
9
9
  Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([f, r]) => {
10
- const i = o.get(f);
11
- i !== r && (r != null && r.get || r != null && r.set) && (i != null && i.get && (r.get = i == null ? void 0 : i.get), i != null && i.set && (r.set = i == null ? void 0 : i.set), o.set(f, r));
10
+ const i = n.get(f);
11
+ i !== r && (r != null && r.get || r != null && r.set) && (i != null && i.get && (r.get = i == null ? void 0 : i.get), i != null && i.set && (r.set = i == null ? void 0 : i.set), n.set(f, r));
12
12
  }), t = Object.getPrototypeOf(t);
13
- return d.set(e, o), o;
13
+ return d.set(e, n), n;
14
14
  }
15
- function E(e, ...o) {
15
+ function E(e, ...n) {
16
16
  var i, O;
17
- const t = D(e), f = t != null && t.size ? {} : null, r = v(new e(...o));
18
- for (const [n, l] of t)
19
- ((i = e == null ? void 0 : e.ivue) == null ? void 0 : i[n]) !== !1 && Object.defineProperty(r, n, { get: l.get ? () => {
17
+ const t = D(e), f = t != null && t.size ? {} : null, r = v(new e(...n));
18
+ for (const [o, p] of t)
19
+ ((i = e == null ? void 0 : e.ivue) == null ? void 0 : i[o]) !== !1 && Object.defineProperty(r, o, { get: p.get ? () => {
20
20
  var u, g;
21
- return n in f ? f[n] : f[n] = b({ get: (u = l.get) == null ? void 0 : u.bind(r), set: (g = l.set) == null ? void 0 : g.bind(r) });
22
- } : void 0, set: (O = l.set) == null ? void 0 : O.bind(r), enumerable: !1 });
23
- return Object.defineProperty(r, "toRefs", { get: () => function(n, l, u) {
21
+ return o in f ? f[o] : f[o] = b({ get: (u = p.get) == null ? void 0 : u.bind(r), set: (g = p.set) == null ? void 0 : g.bind(r) });
22
+ } : void 0, set: (O = p.set) == null ? void 0 : O.bind(r), enumerable: !1 });
23
+ return Object.defineProperty(r, "toRefs", { get: () => function(o, p, u) {
24
24
  return function(g) {
25
25
  var h, j;
26
- const p = {};
26
+ const l = {};
27
27
  if (Array.isArray(g) && g.length)
28
28
  for (let a = 0; a < g.length; a++) {
29
29
  const s = g[a];
30
- if (l.has(s))
30
+ if (p.has(s))
31
31
  if (s in u)
32
- p[s] = u[s];
32
+ l[s] = u[s];
33
33
  else {
34
- const c = l.get(s);
35
- p[s] = u[s] = b({ get: (h = c == null ? void 0 : c.get) == null ? void 0 : h.bind(n), set: (j = c == null ? void 0 : c.set) == null ? void 0 : j.bind(n) });
34
+ const c = p.get(s);
35
+ l[s] = u[s] = b({ get: (h = c == null ? void 0 : c.get) == null ? void 0 : h.bind(o), set: (j = c == null ? void 0 : c.set) == null ? void 0 : j.bind(o) });
36
36
  }
37
37
  else
38
- typeof n[s] == "function" ? p[s] = n[s].bind(n) : p[s] = m(n, s);
38
+ typeof o[s] == "function" ? l[s] = o[s].bind(o) : l[s] = m(o, s);
39
39
  }
40
40
  else {
41
- let a = new Set(C(n));
42
- l.forEach((s, c) => {
41
+ let a = new Set(C(o));
42
+ p.forEach((s, c) => {
43
43
  var w, P;
44
- p[c] = c in u ? u[c] : u[c] = b({ get: (w = s.get) == null ? void 0 : w.bind(n), set: (P = s.set) == null ? void 0 : P.bind(n) }), a == null || a.delete(c);
44
+ l[c] = c in u ? u[c] : u[c] = b({ get: (w = s.get) == null ? void 0 : w.bind(o), set: (P = s.set) == null ? void 0 : P.bind(o) }), a == null || a.delete(c);
45
45
  }), a.forEach((s) => {
46
- typeof n[s] == "function" ? p[s] = n[s].bind(n) : p[s] = m(n, s);
46
+ typeof o[s] == "function" ? l[s] = o[s].bind(o) : l[s] = m(o, s);
47
47
  }), a = null;
48
48
  }
49
- return p;
49
+ return l;
50
50
  };
51
51
  }(r, t, f), enumerable: !1 }), "init" in r && r.init(), r;
52
52
  }
@@ -54,26 +54,26 @@ const y = /* @__PURE__ */ new Map();
54
54
  function C(e) {
55
55
  if (y.has(e.constructor))
56
56
  return y.get(e.constructor);
57
- const o = e.constructor, t = /* @__PURE__ */ new Set();
57
+ const n = e.constructor, t = /* @__PURE__ */ new Set();
58
58
  do
59
59
  Object.getOwnPropertyNames(e).forEach((f) => {
60
60
  ["caller", "callee", "arguments", "constructor"].includes(f) || t.add(f);
61
61
  }), e = Object.getPrototypeOf(e);
62
62
  while (e.constructor !== Object);
63
- return y.set(o, t), t;
63
+ return y.set(n, t), t;
64
64
  }
65
65
  const S = A;
66
- function x(e, ...o) {
67
- return M(e) ? E(e, ...o).toRefs() : e;
66
+ function x(e, ...n) {
67
+ return typeof e == "function" ? M(e) ? E(e, ...n).toRefs() : e(...n) : e;
68
68
  }
69
69
  function M(e) {
70
- var o;
71
- return typeof e == "function" && !!e.prototype && !((o = Object.getOwnPropertyDescriptor(e, "prototype")) != null && o.writable);
70
+ var n;
71
+ return typeof e == "function" && !!e.prototype && !((n = Object.getOwnPropertyDescriptor(e, "prototype")) != null && n.writable);
72
72
  }
73
- function z(e, o) {
74
- for (const t in o)
75
- typeof (e == null ? void 0 : e[t]) == "object" && (e == null ? void 0 : e[t]) !== null || M(e == null ? void 0 : e[t]) ? o[t].default = () => e == null ? void 0 : e[t] : o[t].default = e == null ? void 0 : e[t];
76
- return o;
73
+ function z(e, n) {
74
+ for (const t in n)
75
+ typeof (e == null ? void 0 : e[t]) == "object" && (e == null ? void 0 : e[t]) !== null || M(e == null ? void 0 : e[t]) ? n[t].default = () => e == null ? void 0 : e[t] : n[t].default = e == null ? void 0 : e[t];
76
+ return n;
77
77
  }
78
78
  export {
79
79
  d as descriptorsMap,
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(i,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):f((i=typeof globalThis<"u"?globalThis:i||self).ivue={},i.Vue)})(this,function(i,f){"use strict";const y=new Map;function j(t){if(y.has(t))return y.get(t);const s=new Map;let e=t.prototype;for(;e.constructor!==Object;)Object.entries(Object.getOwnPropertyDescriptors(e)).forEach(([l,n])=>{const c=s.get(l);c!==n&&(n!=null&&n.get||n!=null&&n.set)&&(c!=null&&c.get&&(n.get=c==null?void 0:c.get),c!=null&&c.set&&(n.set=c==null?void 0:c.set),s.set(l,n))}),e=Object.getPrototypeOf(e);return y.set(t,s),s}function w(t,...s){var c,P;const e=j(t),l=e!=null&&e.size?{}:null,n=f.reactive(new t(...s));for(const[r,d]of e)((c=t==null?void 0:t.ivue)==null?void 0:c[r])!==!1&&Object.defineProperty(n,r,{get:d.get?()=>{var p,b;return r in l?l[r]:l[r]=f.computed({get:(p=d.get)==null?void 0:p.bind(n),set:(b=d.set)==null?void 0:b.bind(n)})}:void 0,set:(P=d.set)==null?void 0:P.bind(n),enumerable:!1});return Object.defineProperty(n,"toRefs",{get:()=>function(r,d,p){return function(b){var v,M;const g={};if(Array.isArray(b)&&b.length)for(let a=0;a<b.length;a++){const o=b[a];if(d.has(o))if(o in p)g[o]=p[o];else{const u=d.get(o);g[o]=p[o]=f.computed({get:(v=u==null?void 0:u.get)==null?void 0:v.bind(r),set:(M=u==null?void 0:u.set)==null?void 0:M.bind(r)})}else typeof r[o]=="function"?g[o]=r[o].bind(r):g[o]=f.toRef(r,o)}else{let a=new Set(m(r));d.forEach((o,u)=>{var A,D;g[u]=u in p?p[u]:p[u]=f.computed({get:(A=o.get)==null?void 0:A.bind(r),set:(D=o.set)==null?void 0:D.bind(r)}),a==null||a.delete(u)}),a.forEach(o=>{typeof r[o]=="function"?g[o]=r[o].bind(r):g[o]=f.toRef(r,o)}),a=null}return g}}(n,e,l),enumerable:!1}),"init"in n&&n.init(),n}const O=new Map;function m(t){if(O.has(t.constructor))return O.get(t.constructor);const s=t.constructor,e=new Set;do Object.getOwnPropertyNames(t).forEach(l=>{["caller","callee","arguments","constructor"].includes(l)||e.add(l)}),t=Object.getPrototypeOf(t);while(t.constructor!==Object);return O.set(s,e),e}const E=f.ref;function h(t){var s;return typeof t=="function"&&!!t.prototype&&!((s=Object.getOwnPropertyDescriptor(t,"prototype"))!=null&&s.writable)}i.descriptorsMap=y,i.getAllClassDescriptors=j,i.getAllClassProperties=m,i.iref=E,i.isClass=h,i.iuse=function(t,...s){return h(t)?w(t,...s).toRefs():t},i.ivue=w,i.propsMap=O,i.propsWithDefaults=function(t,s){for(const e in s)typeof(t==null?void 0:t[e])=="object"&&(t==null?void 0:t[e])!==null||h(t==null?void 0:t[e])?s[e].default=()=>t==null?void 0:t[e]:s[e].default=t==null?void 0:t[e];return s},Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):u((i=typeof globalThis<"u"?globalThis:i||self).ivue={},i.Vue)})(this,function(i,u){"use strict";const y=new Map;function j(t){if(y.has(t))return y.get(t);const r=new Map;let e=t.prototype;for(;e.constructor!==Object;)Object.entries(Object.getOwnPropertyDescriptors(e)).forEach(([l,n])=>{const c=r.get(l);c!==n&&(n!=null&&n.get||n!=null&&n.set)&&(c!=null&&c.get&&(n.get=c==null?void 0:c.get),c!=null&&c.set&&(n.set=c==null?void 0:c.set),r.set(l,n))}),e=Object.getPrototypeOf(e);return y.set(t,r),r}function w(t,...r){var c,P;const e=j(t),l=e!=null&&e.size?{}:null,n=u.reactive(new t(...r));for(const[s,d]of e)((c=t==null?void 0:t.ivue)==null?void 0:c[s])!==!1&&Object.defineProperty(n,s,{get:d.get?()=>{var p,b;return s in l?l[s]:l[s]=u.computed({get:(p=d.get)==null?void 0:p.bind(n),set:(b=d.set)==null?void 0:b.bind(n)})}:void 0,set:(P=d.set)==null?void 0:P.bind(n),enumerable:!1});return Object.defineProperty(n,"toRefs",{get:()=>function(s,d,p){return function(b){var v,M;const g={};if(Array.isArray(b)&&b.length)for(let a=0;a<b.length;a++){const o=b[a];if(d.has(o))if(o in p)g[o]=p[o];else{const f=d.get(o);g[o]=p[o]=u.computed({get:(v=f==null?void 0:f.get)==null?void 0:v.bind(s),set:(M=f==null?void 0:f.set)==null?void 0:M.bind(s)})}else typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=u.toRef(s,o)}else{let a=new Set(m(s));d.forEach((o,f)=>{var A,D;g[f]=f in p?p[f]:p[f]=u.computed({get:(A=o.get)==null?void 0:A.bind(s),set:(D=o.set)==null?void 0:D.bind(s)}),a==null||a.delete(f)}),a.forEach(o=>{typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=u.toRef(s,o)}),a=null}return g}}(n,e,l),enumerable:!1}),"init"in n&&n.init(),n}const O=new Map;function m(t){if(O.has(t.constructor))return O.get(t.constructor);const r=t.constructor,e=new Set;do Object.getOwnPropertyNames(t).forEach(l=>{["caller","callee","arguments","constructor"].includes(l)||e.add(l)}),t=Object.getPrototypeOf(t);while(t.constructor!==Object);return O.set(r,e),e}const E=u.ref;function h(t){var r;return typeof t=="function"&&!!t.prototype&&!((r=Object.getOwnPropertyDescriptor(t,"prototype"))!=null&&r.writable)}i.descriptorsMap=y,i.getAllClassDescriptors=j,i.getAllClassProperties=m,i.iref=E,i.isClass=h,i.iuse=function(t,...r){return typeof t=="function"?h(t)?w(t,...r).toRefs():t(...r):t},i.ivue=w,i.propsMap=O,i.propsWithDefaults=function(t,r){for(const e in r)typeof(t==null?void 0:t[e])=="object"&&(t==null?void 0:t[e])!==null||h(t==null?void 0:t[e])?r[e].default=()=>t==null?void 0:t[e]:r[e].default=t==null?void 0:t[e];return r},Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
@@ -159,18 +159,23 @@ export declare function getAllClassProperties(obj: object): Set<string>;
159
159
  * @param val T
160
160
  * @returns {UnwrapRef<T>}
161
161
  */
162
- export declare const iref: <T = any>(value: T) => T;
162
+ export declare const iref: <T = any>(value?: T | undefined) => T;
163
163
  /**
164
- * Two modes of operation:
164
+ * Three modes of operation:
165
165
  * 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw type definition.
166
166
  * Returns for all properties of an object an unwrapped raw type definition,
167
167
  * unwraps direct Refs & ComputedRefs as well down to their raw types.
168
168
  *
169
- * 2. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments like so `iuse(AnyClass, ...args)`,
170
- * it returns an 'ivue(AnyClass, ...args).toRefs()` ivue object in Vee 3 Composable standard form for all properties but casts
171
- * their types as raw (non-Ref) types to fit with reactive() structure of the ivue class context.
169
+ * 2. `iuse(useComposable, arg, arg2, arg3, ...)` for cleaner syntax for #1, it does exactly the same thing but
170
+ * here the TypeScript inference works for composable function arguments to assist you with intellisence,
171
+ * like they work for constructor arguments in the cause of `ivue()` core function,
172
+ * making the API cleaner to look at and make it compatible with how this function operates with classes, see #3.
173
+ *
174
+ * 3. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments into `iuse(AnyClass, ...args)`,
175
+ * it returns an 'ivue(AnyClass, ...args).toRefs()` object for all properties but casts
176
+ * their types as raw (no-Ref) types to fit with reactive() structure of the ivue class context.
172
177
  */
173
- export declare function iuse<T extends AnyClass | Object>(val?: T, ...args: InferredArgs<T>): T extends AnyClass ? InstanceType<T> : UnwrapComposableReturn<T>;
178
+ export declare function iuse<T extends AnyClass | AnyFn | Object>(classFunctionObject?: T, ...args: T extends AnyClass ? InferredArgs<T> : T extends AnyFn ? Parameters<T extends (...args: any[]) => any ? T : any> : any): T extends AnyClass ? InstanceType<T> : T extends AnyFn ? UseComposable<T> : UnwrapComposableReturn<T>;
174
179
  /**
175
180
  * Vue props interface in defineComponent() style.
176
181
  */
@@ -1,5 +1,5 @@
1
1
  import { useMouse } from '@vueuse/core';
2
- import { iref, iuse, type UseComposable } from '../../../../../src/ivue';
2
+ import { iref, iuse, type UseComposable } from 'ivue';
3
3
 
4
4
  type UseMouse = UseComposable<typeof useMouse>;
5
5
 
package/docs/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "eslint-plugin-import": "^2.29.1",
19
19
  "eslint-plugin-vue": "^9.14.1",
20
20
  "execa": "^8.0.0",
21
- "ivue": "^1.1.21",
21
+ "ivue": "^1.2.0",
22
22
  "typescript": "^4.5.4",
23
23
  "vite-plugin-dynamic-import": "^1.5.0",
24
24
  "vite-tsconfig-paths": "^4.3.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ivue",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Infinite Vue – Class Based Architecture for Vue 3",
5
5
  "type": "module",
6
6
  "exports": {
package/src/ivue.ts CHANGED
@@ -57,8 +57,9 @@ export type UnwrapComposableReturn<T> = T extends Ref | DemiRef
57
57
  /**
58
58
  * Fully unwraps to bare value types any Vue 3 composable return definition type.
59
59
  */
60
- export type UseComposable<T extends AnyFn> =
61
- UnwrapComposableReturn<ReturnType<T>>;
60
+ export type UseComposable<T extends AnyFn> = UnwrapComposableReturn<
61
+ ReturnType<T>
62
+ >;
62
63
 
63
64
  /**
64
65
  * Extracts object defined emit types by converting them to a plain interface
@@ -139,10 +140,7 @@ export type IFnParameter<
139
140
  /**
140
141
  * Get function arguments Parmeters<F> parameter by key K
141
142
  */
142
- export type FnParameter<
143
- F extends AnyFn,
144
- K extends number
145
- > = Parameters<F>[K];
143
+ export type FnParameter<F extends AnyFn, K extends number> = Parameters<F>[K];
146
144
 
147
145
  /**
148
146
  * Convert Union Type to Intersection Type.
@@ -322,28 +320,45 @@ export function getAllClassProperties(obj: object): Set<string> {
322
320
  * @param val T
323
321
  * @returns {UnwrapRef<T>}
324
322
  */
325
- export const iref = ref as <T = any>(value: T) => T;
323
+ export const iref = ref as <T = any>(value?: T) => T;
326
324
 
327
325
  /**
328
- * Two modes of operation:
326
+ * Three modes of operation:
329
327
  * 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw type definition.
330
328
  * Returns for all properties of an object an unwrapped raw type definition,
331
329
  * unwraps direct Refs & ComputedRefs as well down to their raw types.
332
330
  *
333
- * 2. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments like so `iuse(AnyClass, ...args)`,
334
- * it returns an 'ivue(AnyClass, ...args).toRefs()` ivue object in Vee 3 Composable standard form for all properties but casts
335
- * their types as raw (non-Ref) types to fit with reactive() structure of the ivue class context.
336
- */
337
- export function iuse<T extends AnyClass | Object>(
338
- val?: T,
339
- ...args: InferredArgs<T>
340
- ): T extends AnyClass ? InstanceType<T> : UnwrapComposableReturn<T> {
341
- return isClass(val)
342
- ? ivue(
343
- val as T extends AnyClass ? T : any,
344
- ...(args as InferredArgs<T>)
345
- ).toRefs()
346
- : (val as unknown as UnwrapComposableReturn<T>);
331
+ * 2. `iuse(useComposable, arg, arg2, arg3, ...)` for cleaner syntax for #1, it does exactly the same thing but
332
+ * here the TypeScript inference works for composable function arguments to assist you with intellisence,
333
+ * like they work for constructor arguments in the cause of `ivue()` core function,
334
+ * making the API cleaner to look at and make it compatible with how this function operates with classes, see #3.
335
+ *
336
+ * 3. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments into `iuse(AnyClass, ...args)`,
337
+ * it returns an 'ivue(AnyClass, ...args).toRefs()` object for all properties but casts
338
+ * their types as raw (no-Ref) types to fit with reactive() structure of the ivue class context.
339
+ */
340
+ export function iuse<T extends AnyClass | AnyFn | Object>(
341
+ classFunctionObject?: T,
342
+ ...args: T extends AnyClass
343
+ ? InferredArgs<T>
344
+ : T extends AnyFn
345
+ ? Parameters<T extends (...args: any[]) => any ? T : any>
346
+ : any
347
+ ): T extends AnyClass
348
+ ? InstanceType<T>
349
+ : T extends AnyFn
350
+ ? UseComposable<T>
351
+ : UnwrapComposableReturn<T> {
352
+ return typeof classFunctionObject === 'function'
353
+ ? isClass(classFunctionObject)
354
+ ? ivue(
355
+ classFunctionObject as T extends AnyClass ? T : any,
356
+ ...(args as InferredArgs<T extends AnyClass ? T : any>)
357
+ ).toRefs()
358
+ : (classFunctionObject as AnyFn)(
359
+ ...(args as Parameters<T extends AnyFn ? AnyFn : any>)
360
+ )
361
+ : (classFunctionObject as unknown as UnwrapComposableReturn<T>);
347
362
  }
348
363
 
349
364
  /**