Comparing version 2.2.1 to 2.2.11
{ | ||
"name": "new-dream", | ||
"version": "2.2.1", | ||
"version": "2.2.11", | ||
"description": "The pop-up UI component of Vue2", | ||
@@ -5,0 +5,0 @@ "main": "src/main", |
@@ -14,2 +14,5 @@ # new-dream | ||
## 2022-11-09 | ||
- 优化`Win`实例属性的可访问性,将`config`更新为可访问属性 | ||
# HTML使用 | ||
@@ -16,0 +19,0 @@ - 参考`demo`下的使用方法 |
@@ -19,4 +19,4 @@ import { WinEl } from "./WinEl"; | ||
function Win(config) { | ||
this.config = defaultConfig; | ||
this.status = "initial"; | ||
this.config = defaultConfig; | ||
this.children = {}; | ||
@@ -28,3 +28,4 @@ this.upStatus = "initial"; | ||
this.__config = config || defaultConfig; | ||
this.id = this.__config.id || Win.createId(); | ||
var component = this.__config.component; | ||
this.id = this.__config.id ? this.__config.id : component && component.id ? component.id : Win.createId(); | ||
if (Win.WinIdMap[this.id]) { | ||
@@ -35,3 +36,3 @@ var errMsg = "相同ID窗口已存在!无法继续创建"; | ||
} | ||
this.__Els = new WinEl(this.__config); | ||
this.elements = new WinEl(this.__config); | ||
this.addMoveEvent(); | ||
@@ -64,9 +65,9 @@ this.addButtonEvent(); | ||
case "initial": | ||
this.__Els.setInitial(this.upStatus); | ||
this.elements.setInitial(this.upStatus); | ||
break; | ||
case "max": | ||
this.__Els.setMax(this.upStatus); | ||
this.elements.setMax(this.upStatus); | ||
break; | ||
case "mini": | ||
this.__Els.setMini(); | ||
this.elements.setMini(); | ||
break; | ||
@@ -87,3 +88,3 @@ case "close": | ||
set: function (v) { | ||
this.__Els.box.style.zIndex = String(v); | ||
this.elements.box.style.zIndex = String(v); | ||
this.zIndex = v; | ||
@@ -101,10 +102,10 @@ }, | ||
} | ||
parentWin.__Els.content.appendChild(this.__Els.box); | ||
parentWin.elements.content.appendChild(this.elements.box); | ||
parentWin.children[this.id] = this; | ||
} | ||
else { | ||
Win.defaultContentBox.appendChild(this.__Els.box); | ||
Win.defaultContentBox.appendChild(this.elements.box); | ||
} | ||
this.__Els.setPosition(this.__config); | ||
this.__Els.setContent(this.__config); | ||
this.elements.setPosition(this.__config); | ||
this.elements.setContent(this.__config); | ||
Win.WinIdMap[this.id] = this; | ||
@@ -119,3 +120,3 @@ requestAnimationFrame(function () { | ||
var _this = this; | ||
moveWin(this, function () { | ||
moveWin(this, this.__status, this.elements, function () { | ||
requestAnimationFrame(function () { | ||
@@ -130,9 +131,9 @@ if (_this.callbacks.move) { | ||
var _this = this; | ||
this.__Els.minimize.addEventListener("click", function () { | ||
this.elements.minimize.addEventListener("click", function () { | ||
_this.setMini(); | ||
}); | ||
this.__Els.maximize.addEventListener("click", function () { | ||
this.elements.maximize.addEventListener("click", function () { | ||
_this.setMax(); | ||
}); | ||
this.__Els.close.addEventListener("click", function () { | ||
this.elements.close.addEventListener("click", function () { | ||
_this.close(); | ||
@@ -151,5 +152,5 @@ }); | ||
} | ||
var parentElement = this.__Els.box.parentElement; | ||
var parentElement = this.elements.box.parentElement; | ||
if (parentElement) { | ||
parentElement.removeChild(this.__Els.box); | ||
parentElement.removeChild(this.elements.box); | ||
} | ||
@@ -167,4 +168,4 @@ delete Win.WinIdMap[this.id]; | ||
if (this.__config.parentId && Win.WinIdMap[this.__config.parentId]) { | ||
parentNode = Win.WinIdMap[this.__config.parentId].__Els.content; | ||
parentMiniEl = Win.WinIdMap[this.__config.parentId].__Els.miniEl; | ||
parentNode = Win.WinIdMap[this.__config.parentId].elements.content; | ||
parentMiniEl = Win.WinIdMap[this.__config.parentId].elements.miniEl; | ||
} | ||
@@ -176,6 +177,6 @@ else { | ||
if (this.__status === "mini") { | ||
parentMiniEl.appendChild(this.__Els.box); | ||
parentMiniEl.appendChild(this.elements.box); | ||
} | ||
else { | ||
parentNode.appendChild(this.__Els.box); | ||
parentNode.appendChild(this.elements.box); | ||
} | ||
@@ -182,0 +183,0 @@ }; |
@@ -33,5 +33,5 @@ import { WinEl } from "./WinEl"; | ||
public id: string; | ||
public __Els: WinEl; | ||
public status: Status = "initial"; | ||
private config: Config = defaultConfig; | ||
public config: Config = defaultConfig; | ||
private elements: WinEl; | ||
private status: Status = "initial"; | ||
private children: { [key: string]: Win } = {}; | ||
@@ -45,3 +45,4 @@ private upStatus: Status = "initial"; // 上一次的状态 | ||
this.__config = config || defaultConfig; | ||
this.id = this.__config.id || Win.createId() | ||
const component = this.__config.component as { [key: string]: any }; | ||
this.id = this.__config.id ? this.__config.id : component && component.id ? component.id : Win.createId(); | ||
// 判断窗口是否已经存在 | ||
@@ -53,3 +54,3 @@ if (Win.WinIdMap[this.id]) { | ||
} | ||
this.__Els = new WinEl(this.__config); // 创建元素 | ||
this.elements = new WinEl(this.__config); // 创建元素 | ||
this.addMoveEvent(); // 添加移动事件 | ||
@@ -79,9 +80,9 @@ this.addButtonEvent(); // 为按钮添加事件 | ||
case "initial": | ||
this.__Els.setInitial(this.upStatus) | ||
this.elements.setInitial(this.upStatus) | ||
break; | ||
case "max": | ||
this.__Els.setMax(this.upStatus) | ||
this.elements.setMax(this.upStatus) | ||
break; | ||
case "mini": | ||
this.__Els.setMini(); | ||
this.elements.setMini(); | ||
break; | ||
@@ -100,3 +101,3 @@ case "close": | ||
private set __zIndex(v) { | ||
this.__Els.box.style.zIndex = String(v) | ||
this.elements.box.style.zIndex = String(v) | ||
this.zIndex = v | ||
@@ -117,9 +118,9 @@ } | ||
} | ||
parentWin.__Els.content.appendChild(this.__Els.box) | ||
parentWin.elements.content.appendChild(this.elements.box) | ||
parentWin.children[this.id] = this; | ||
} else { | ||
Win.defaultContentBox.appendChild(this.__Els.box) | ||
Win.defaultContentBox.appendChild(this.elements.box) | ||
} | ||
this.__Els.setPosition(this.__config); // 设置窗口位置 | ||
this.__Els.setContent(this.__config); // 加载内容 | ||
this.elements.setPosition(this.__config); // 设置窗口位置 | ||
this.elements.setContent(this.__config); // 加载内容 | ||
Win.WinIdMap[this.id] = this | ||
@@ -137,3 +138,3 @@ // 下一帧,触发生命周期函数 | ||
private addMoveEvent() { | ||
moveWin(this, () => { | ||
moveWin(this, this.__status, this.elements, () => { | ||
// 下一帧,触发生命周期函数 | ||
@@ -151,9 +152,9 @@ requestAnimationFrame(() => { | ||
private addButtonEvent() { | ||
this.__Els.minimize.addEventListener("click", () => { | ||
this.elements.minimize.addEventListener("click", () => { | ||
this.setMini() | ||
}) | ||
this.__Els.maximize.addEventListener("click", () => { | ||
this.elements.maximize.addEventListener("click", () => { | ||
this.setMax() | ||
}) | ||
this.__Els.close.addEventListener("click", () => { | ||
this.elements.close.addEventListener("click", () => { | ||
this.close() | ||
@@ -182,5 +183,5 @@ }) | ||
// 先将元素从页面移除 | ||
const parentElement = this.__Els.box.parentElement; | ||
const parentElement = this.elements.box.parentElement; | ||
if (parentElement) { | ||
parentElement.removeChild(this.__Els.box) | ||
parentElement.removeChild(this.elements.box) | ||
} | ||
@@ -203,4 +204,4 @@ // 释放引用内存 | ||
if (this.__config.parentId && Win.WinIdMap[this.__config.parentId]) { | ||
parentNode = Win.WinIdMap[this.__config.parentId].__Els.content; | ||
parentMiniEl = Win.WinIdMap[this.__config.parentId].__Els.miniEl; | ||
parentNode = Win.WinIdMap[this.__config.parentId].elements.content; | ||
parentMiniEl = Win.WinIdMap[this.__config.parentId].elements.miniEl; | ||
} else { | ||
@@ -211,5 +212,5 @@ parentNode = Win.defaultContentBox; | ||
if (this.__status === "mini") { | ||
parentMiniEl.appendChild(this.__Els.box); | ||
parentMiniEl.appendChild(this.elements.box); | ||
} else { | ||
parentNode.appendChild(this.__Els.box); | ||
parentNode.appendChild(this.elements.box); | ||
} | ||
@@ -216,0 +217,0 @@ } |
import { Win } from ".."; | ||
export default function (win, endCallback) { | ||
win.__Els.move.addEventListener("mousedown", function (move) { | ||
export default function (win, status, winEl, endCallback) { | ||
winEl.move.addEventListener("mousedown", function (move) { | ||
win.setTop(); | ||
if (win.status === "max") { | ||
if (status === "max") { | ||
console.warn("最大化窗口无法移动"); | ||
return; | ||
} | ||
var tW = win.__Els.title.offsetWidth; | ||
var tW = winEl.title.offsetWidth; | ||
var hX = move.offsetX + tW, hY = move.offsetY; | ||
if (win.__Els.box.parentNode === document.body) { | ||
if (winEl.box.parentNode === document.body) { | ||
Win.Shade.style["position"] = "fixed"; | ||
@@ -17,4 +17,4 @@ } | ||
} | ||
if (win.__Els.box.parentNode) { | ||
win.__Els.box.parentNode.appendChild(Win.Shade); | ||
if (winEl.box.parentNode) { | ||
winEl.box.parentNode.appendChild(Win.Shade); | ||
} | ||
@@ -30,4 +30,4 @@ Win.Shade.onmousemove = function (shade) { | ||
} | ||
win.__Els.box.style["left"] = "".concat(left, "px"); | ||
win.__Els.box.style["top"] = "".concat(top, "px"); | ||
winEl.box.style["left"] = "".concat(left, "px"); | ||
winEl.box.style["top"] = "".concat(top, "px"); | ||
}; | ||
@@ -34,0 +34,0 @@ }); |
import { Win } from ".."; | ||
import { WinEl } from "../WinEl"; | ||
export default function (win: Win, endCallback: () => void) { | ||
export default function (win: Win, status: string, winEl: WinEl, endCallback: () => void) { | ||
// 鼠标按下 | ||
win.__Els.move.addEventListener("mousedown", (move) => { | ||
winEl.move.addEventListener("mousedown", (move) => { | ||
win.setTop() | ||
if (win.status === "max") { | ||
if (status === "max") { | ||
console.warn("最大化窗口无法移动") | ||
return | ||
} | ||
const tW = win.__Els.title.offsetWidth; | ||
const tW = winEl.title.offsetWidth; | ||
const hX = move.offsetX + tW, hY = move.offsetY; | ||
if (win.__Els.box.parentNode === document.body) { | ||
if (winEl.box.parentNode === document.body) { | ||
Win.Shade.style["position"] = "fixed" | ||
@@ -18,4 +19,4 @@ } else { | ||
} | ||
if (win.__Els.box.parentNode) { | ||
win.__Els.box.parentNode.appendChild(Win.Shade) | ||
if (winEl.box.parentNode) { | ||
winEl.box.parentNode.appendChild(Win.Shade) | ||
} | ||
@@ -31,4 +32,4 @@ Win.Shade.onmousemove = (shade) => { | ||
} | ||
win.__Els.box.style["left"] = `${left}px`; | ||
win.__Els.box.style["top"] = `${top}px`; | ||
winEl.box.style["left"] = `${left}px`; | ||
winEl.box.style["top"] = `${top}px`; | ||
} | ||
@@ -35,0 +36,0 @@ }) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416609
2680
429