cc1-vue3 1.0.1 → 1.0.2
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/cc1-vue3.js +1 -1
- package/dist/utils/CVue3.d.ts +4 -2
- package/package.json +1 -1
- package/dist/tools-vue3.d.ts +0 -135
- package/dist/tools-vue3.js +0 -1
package/dist/cc1-vue3.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cc1-vue3"]={},e.vue)}(this,function(e,t){"use strict";const n="__scopeObjFun";class
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cc1-vue3"]={},e.vue)}(this,function(e,t){"use strict";class n{static id=1e3;static getId=()=>(this.id++,this.id+"");static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const c=setInterval(()=>{if(r)return void clearInterval(c);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(c),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let o=e.domOrIdOrClass||document.body;"string"==typeof o&&(o=document.querySelector(o));const r=document.createElement("div");r.id="com-custom-"+n.getId(),e.first?o.insertBefore(r,o.firstChild):o.appendChild(r);let c=null;const s=()=>{try{r.parentElement?.removeChild(r),c&&c.unmount(),c=null}catch(e){}};return c=t.createApp({render:()=>t.h(e.component,{...e.props,show:!0,remove:s})}),e.beforeMount?.(c,r),c.mount(r),{vm:c,remove:s}}}const o="__scopeObjFun";class r{static map={};static get(e,n){const o=r,c=t.getCurrentInstance();return c?(o.map[e]||(o.map[e]={value:n(),refs:new Set}),o.map[e].refs.add(c),t.onUnmounted(()=>{o.map[e]?.refs.delete(c),0===o.map[e]?.refs.size&&delete o.map[e]}),o.map[e].value):n()}}const c=window.Scope||class{static setConf=(e,n)=>{n||"string"==typeof e||(n=e,e="conf");const r=t.getCurrentInstance();let c=n;if("function"!=typeof c&&(c=()=>n),r){let t=r[o];t||(t=[]),t.push({key:e,fun:c}),r[o]=t}};static getConf=(e,n)=>{e?"number"==typeof e&&(n=e,e="conf"):e="conf",n||(n=1);let r=t.getCurrentInstance(),c=0,s=()=>null;for(;r=r.parent;){const t=r[o];if(t)for(let o=0;o<t.length;o++){const r=t[o];if(r.key===e&&(c++,s=r.fun,c===n))return r.fun()}}return s()};static CEventBean=null;static CEventBeanDeactivated=!1;static Event=()=>{if(!this.CEventBean)return null;const e=t.getCurrentInstance(),n=new this.CEventBean;return n.vm=()=>()=>e.isDeactivated?this.CEventBeanDeactivated:!e.isUnmounted,n};static TimerBean=null;static TimerBeanDeactivated="pause";static Timer=()=>{if(!this.TimerBean)return null;const e=new this.TimerBean,n=t.getCurrentInstance();return e.vm=()=>()=>n.isDeactivated?this.TimerBeanDeactivated:!n.isUnmounted,e}};window.TimerBean&&(c.TimerBean=window.TimerBean),window.CEventBean&&(c.CEventBean=window.CEventBean),window.Scope||(window.Scope=c),e.CRouter=class{static init=e=>{const t=e.root||"/src/views";if(!e.modules)throw new Error("modules is required");const n=e.modules,o={},r=e.diffModules||{},c={},s=e.pathHook||(e=>e),i=(n,o)=>{Object.keys(o).forEach(r=>{let c=r.replace(t,"").replace(".vue","");const i=e.mapKeyPathHook?.(c)||r;n[i]={path:s(c),component:o[r],useNum:0}})};i(o,n),i(c,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,c);const a=e.children||[],u=[],l=e=>{const t=Object.keys(o);for(let n=0;n<t.length;n++)if(o[t[n]].path===e)return o[t[n]]};if(a.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=l(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=l(t.component);e&&(t.component=e.component,e.useNum++)}if(t.childrenReg){const e=(n=t.childrenReg,Array.isArray(n)?n.map(e=>e instanceof RegExp?e:new RegExp(e)):n instanceof RegExp?[n]:n?[new RegExp(n)]:[]);Object.keys(o).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:o[n].component}),o[n].useNum++)})}var n};for(let t=0;t<a.length;t++){const n=a[t];e(n),u.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&u.push({path:e,component:o[e].component})});const p=t=>{t.path=o[t.path].path,e.setInfoHook?.(t),t.children&&t.children.forEach(e=>{p(e)})};u.forEach(e=>{p(e)});const d={};return Object.keys(o).forEach(e=>{d[o[e].path]=o[e]}),{array:u,map:d}}},e.CVue3=n,e.Minxins=r,e.Scope=c});
|
package/dist/utils/CVue3.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
export default class CVue3 {
|
|
3
|
+
private static id;
|
|
4
|
+
private static getId;
|
|
3
5
|
/**
|
|
4
6
|
* 注册销毁事件
|
|
5
7
|
*/
|
|
@@ -29,9 +31,9 @@ export default class CVue3 {
|
|
|
29
31
|
/**
|
|
30
32
|
* 挂载前处理
|
|
31
33
|
*/
|
|
32
|
-
beforeMount?: (vm: App<Element
|
|
34
|
+
beforeMount?: (vm: App<Element>, tempDiv: HTMLDivElement) => void;
|
|
33
35
|
}) => {
|
|
34
36
|
vm: App<Element>;
|
|
35
|
-
remove: (
|
|
37
|
+
remove: () => void;
|
|
36
38
|
};
|
|
37
39
|
}
|
package/package.json
CHANGED
package/dist/tools-vue3.d.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 事件管理对象
|
|
3
|
-
*/
|
|
4
|
-
interface CEventBeanInter {
|
|
5
|
-
/**
|
|
6
|
-
* 提供默认的挂载验证事件,默认为通过,需要手动销毁事件
|
|
7
|
-
* @returns
|
|
8
|
-
* @example
|
|
9
|
-
* //在vue3中使用
|
|
10
|
-
import { getCurrentInstance } from 'vue'
|
|
11
|
-
const findTopTag = (el: any, tag: string = 'html'): any => {
|
|
12
|
-
if (!el?.parentElement) return null
|
|
13
|
-
if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
|
|
14
|
-
else return findTopTag(el.parentElement, tag)
|
|
15
|
-
}
|
|
16
|
-
CEvent.eventbean.vm = function () {
|
|
17
|
-
const _vm = getCurrentInstance()
|
|
18
|
-
return () => findTopTag(_vm?.vnode.el?.parentElement)
|
|
19
|
-
}
|
|
20
|
-
*/
|
|
21
|
-
vm: () => () => boolean
|
|
22
|
-
eventMap: Map<any, any>
|
|
23
|
-
id: string
|
|
24
|
-
tag: string
|
|
25
|
-
/**
|
|
26
|
-
* 注册
|
|
27
|
-
* @param key 注册名称
|
|
28
|
-
* @param callback 执行回调
|
|
29
|
-
* @param target 附带信息
|
|
30
|
-
* @returns 返回唯一注册id
|
|
31
|
-
*/
|
|
32
|
-
on: (key: any, callback: (data: any) => any, vm?: any) => string
|
|
33
|
-
/**
|
|
34
|
-
* 调用
|
|
35
|
-
* @param key 注册名称
|
|
36
|
-
* @param data 回调函数传入参数
|
|
37
|
-
* @param emitAll 通知所有事件对象(CEvent和所有new CEventBean()),默认为true
|
|
38
|
-
*/
|
|
39
|
-
emit: (key: any, data?: any, emitAll?: boolean) => void
|
|
40
|
-
/**
|
|
41
|
-
* 销毁
|
|
42
|
-
* @mode 模式1:多id或者key名称传入-off('onid1')、off('onid1','getData'...)
|
|
43
|
-
* @mode 模式2:on方法传入的key和方法-off('getData',fun)
|
|
44
|
-
* @param uids-传入的是id或者key加方法清理的是key的单个注册,传入的是key清理key所有注册
|
|
45
|
-
*/
|
|
46
|
-
off: (...uids: any) => void
|
|
47
|
-
clear: () => void
|
|
48
|
-
}
|
|
49
|
-
interface CEventBeanObj {
|
|
50
|
-
new (): CEventBeanInter
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 定时器对象
|
|
55
|
-
*/
|
|
56
|
-
interface TimerBeanInter {
|
|
57
|
-
map: {
|
|
58
|
-
[key: string]: TimerInfo
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 提供默认的挂载验证事件,默认为通过,需要手动销毁定时时间对象
|
|
62
|
-
* @returns
|
|
63
|
-
* @example
|
|
64
|
-
* //在vue3中使用
|
|
65
|
-
import { getCurrentInstance } from 'vue'
|
|
66
|
-
const findTopTag = (el: any, tag: string = 'html'): any => {
|
|
67
|
-
if (!el?.parentElement) return null
|
|
68
|
-
if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
|
|
69
|
-
else return findTopTag(el.parentElement, tag)
|
|
70
|
-
}
|
|
71
|
-
const timer = new TimerBean()
|
|
72
|
-
timer.vm = function () {
|
|
73
|
-
const _vm = getCurrentInstance()
|
|
74
|
-
return () => findTopTag(_vm?.vnode.el?.parentElement)
|
|
75
|
-
}
|
|
76
|
-
*/
|
|
77
|
-
vm: () => () => boolean
|
|
78
|
-
/**
|
|
79
|
-
* 添加一个延时任务
|
|
80
|
-
* @param fun
|
|
81
|
-
* @param timeGap -延迟时间
|
|
82
|
-
*/
|
|
83
|
-
once: (fun: () => void, timeGap?: number, vm?: any) => any
|
|
84
|
-
/**
|
|
85
|
-
* 清空任务-仅能清理TimerBean中的任务
|
|
86
|
-
*/
|
|
87
|
-
clear: () => void
|
|
88
|
-
/**
|
|
89
|
-
* 等待时间单位 1-毫秒 1000-秒
|
|
90
|
-
*/
|
|
91
|
-
delayUnit: number
|
|
92
|
-
/**
|
|
93
|
-
* 等待时间
|
|
94
|
-
* @param millisecond
|
|
95
|
-
* @returns
|
|
96
|
-
*/
|
|
97
|
-
delay: (millisecond?: number, delayUnit?: number) => Promise<void>
|
|
98
|
-
/**
|
|
99
|
-
* 添加一个循环任务
|
|
100
|
-
* @param fun
|
|
101
|
-
* @param timeGap -循环时间
|
|
102
|
-
* @param firstRun -立即执行一次
|
|
103
|
-
*
|
|
104
|
-
*/
|
|
105
|
-
on: (fun: () => void, timeGap: number, firstRun?: boolean, vm?: any) => any
|
|
106
|
-
/**
|
|
107
|
-
* 清理循环-仅能清理TimerBean中的任务
|
|
108
|
-
*/
|
|
109
|
-
un: (...ids: any[]) => void
|
|
110
|
-
}
|
|
111
|
-
interface TimerBeanObj {
|
|
112
|
-
new (): TimerBeanInter
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
type TimerInfo = {
|
|
116
|
-
/**
|
|
117
|
-
* 任务内容
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
fun: () => void
|
|
121
|
-
/**
|
|
122
|
-
* 挂载节点验证
|
|
123
|
-
*/
|
|
124
|
-
vm: any
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 任务id
|
|
128
|
-
*/
|
|
129
|
-
id: string
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 清理
|
|
133
|
-
*/
|
|
134
|
-
remove: () => void
|
|
135
|
-
}
|
package/dist/tools-vue3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cc1-vue3"]={},e.vue)}(this,function(e,t){"use strict";const n="__scopeObjFun";class o{static map={};static get(e,n){const r=o,s=t.getCurrentInstance();return s?(r.map[e]||(r.map[e]={value:n(),refs:new Set}),r.map[e].refs.add(s),t.onUnmounted(()=>{r.map[e]?.refs.delete(s),0===r.map[e]?.refs.size&&delete r.map[e]}),r.map[e].value):n()}}e.CRouter=class{static init=e=>{const t=e.root||"/src/views";if(!e.modules)throw new Error("modules is required");const n=e.modules,o={},r=e.diffModules||{},s={},c=e.pathHook||(e=>e),a=(n,o)=>{Object.keys(o).forEach(r=>{let s=r.replace(t,"").replace(".vue","");const a=e.mapKeyPathHook?.(s)||r;n[a]={path:c(s),component:o[r],useNum:0}})};a(o,n),a(s,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,s);const i=e.children||[],u=[],l=e=>{const t=Object.keys(o);for(let n=0;n<t.length;n++)if(o[t[n]].path===e)return o[t[n]]};if(i.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=l(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=l(t.component);e&&(t.component=e.component,e.useNum++)}if(t.childrenReg){const e=(n=t.childrenReg,Array.isArray(n)?n.map(e=>e instanceof RegExp?e:new RegExp(e)):n instanceof RegExp?[n]:n?[new RegExp(n)]:[]);Object.keys(o).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:o[n].component}),o[n].useNum++)})}var n};for(let t=0;t<i.length;t++){const n=i[t];e(n),u.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&u.push({path:e,component:o[e].component})});const p=t=>{t.path=o[t.path].path,e.setInfoHook?.(t),t.children&&t.children.forEach(e=>{p(e)})};u.forEach(e=>{p(e)});const f={};return Object.keys(o).forEach(e=>{f[o[e].path]=o[e]}),{array:u,map:f}}},e.CVue3=class{static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const s=setInterval(()=>{if(r)return void clearInterval(s);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(s),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let n=e.domOrIdOrClass||document.body;"string"==typeof n&&(n=document.querySelector(n));const o=(...e)=>{r.unmount(),r=void 0,e.forEach(e=>{e&&n.removeChild(e)}),n.removeChild(s)};e.props||(e.props={}),e.props.remove=o;let r=t.createApp(e.component,e.props);const s=document.createElement("div");return e.beforeMount&&e.beforeMount(r),r.mount(s),e.first?n.insertBefore(s,n.firstChild):n.appendChild(s),{vm:r,remove:o}}},e.Minxins=o,e.Scope=class{static setConf=(e,o)=>{o||"string"==typeof e||(o=e,e="conf");const r=t.getCurrentInstance();let s=o;if("function"!=typeof s&&(s=()=>o),r){let t=r[n];t||(t=[]),t.push({key:e,fun:s}),r[n]=t}};static getConf=(e,o)=>{e?"number"==typeof e&&(o=e,e="conf"):e="conf",o||(o=1);let r=t.getCurrentInstance(),s=0,c=()=>null;for(;r=r.parent;){const t=r[n];if(t)for(let n=0;n<t.length;n++){const r=t[n];if(r.key===e&&(s++,c=r.fun,s===o))return r.fun()}}return c()};static CEventBean=null;static CEventBeanDeactivated=!1;static Event=()=>{if(!this.CEventBean)return null;const e=t.getCurrentInstance(),n=new this.CEventBean;return n.vm=()=>()=>e.isDeactivated?this.CEventBeanDeactivated:!e.isUnmounted,n};static TimerBean=null;static TimerBeanDeactivated="pause";static Timer=()=>{if(!this.TimerBean)return null;const e=new this.TimerBean,n=t.getCurrentInstance();return e.vm=()=>()=>n.isDeactivated?this.TimerBeanDeactivated:!n.isUnmounted,e}}});
|