UNPKG

epic-designer

Version:

基于vue3的设计器,可视化开发页面表单

94 lines (93 loc) 2.65 kB
import { ref as i } from "vue"; import { debounce as H } from "../../utils/src/common/common.js"; /* empty css */ /* empty css */ /* empty css */ import "@vueuse/core"; import "../../hooks/src/store/index.js"; import "./pluginManager.js"; /* empty css */ import "vue-draggable-plus"; import { deepCompareAndModify as L, findSchemaById as O } from "../../utils/src/common/data.js"; import "../../git/epic/epic-designer/node_modules/.pnpm/jsep@1.4.0/node_modules/jsep/dist/jsep.js"; function X(c, d, v) { const o = i([]), u = i([]), t = i(null), p = 60, m = 200, n = (e) => { try { const r = JSON.parse(e.pageSchema); L(c, r); const l = e.selectedId ? O(c.schemas, e.selectedId) : void 0; v(l ?? void 0); } catch (r) { console.error("解析历史记录失败:", r); } }, s = (e) => { var r; return { pageSchema: JSON.stringify(c), selectedId: (r = d.selectedNode) == null ? void 0 : r.id, timestamp: Date.now(), type: e }; }, f = H( a, m ); function R(e = "插入组件", r = !1) { var l; if (e === "加载数据" && ((l = t.value) == null ? void 0 : l.type) === "初始化") { t.value = s(e); return; } if (r) { a(e); return; } f(e); } function a(e) { t.value !== null && (o.value.push(t.value), u.value = []), t.value = s(e), o.value.length > p && o.value.shift(); } function g() { if (o.value.length === 0) return !1; const e = o.value.pop(); return t.value !== null && u.value.push(t.value), t.value = e, n(e), !0; } function h() { if (u.value.length === 0) return !1; const e = u.value.pop(); return t.value !== null && o.value.push(t.value), t.value = e, n(e), !0; } function C() { o.value = [], u.value = [], t.value = null; } return { currentRecord: t, exportHistory: () => ({ currentRecord: t.value, recordList: [...o.value], undoList: [...u.value] }), getRedoCount: () => u.value.length, getUndoCount: () => o.value.length, importHistory: (e) => { o.value = [...e.recordList], u.value = [...e.undoList], t.value = e.currentRecord, e.currentRecord && n(e.currentRecord); }, previewHistory: (e) => { const r = t.value; return n(e), () => { r && n(r); }; }, push: R, recordList: o, redo: h, reset: C, undo: g, undoList: u }; } export { X as useRevoke };