@sepveneto/mpd-core
Version:
## 安装 ```cmd pnpm i @sepveneto/mpd-core npm i @sepveneto/mpd-core yarn add @sepveneto/mpd-core ```
258 lines (250 loc) • 7.39 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/vue/index.ts
var vue_exports = {};
__export(vue_exports, {
VueEditor: () => VueEditor
});
module.exports = __toCommonJS(vue_exports);
// src/vue/Editor.ts
var import_vue_demi = require("vue-demi");
// src/helper.ts
var import_micro_app = __toESM(require("@micro-zoe/micro-app"), 1);
// src/emitter.ts
var Emitter = class {
constructor() {
this.listeners = /* @__PURE__ */ new Map();
}
on(name, fn) {
if (this.listeners.has(name)) {
const list = this.listeners.get(name);
list.push(fn);
this.listeners.set(name, list);
} else {
this.listeners.set(name, [fn]);
}
}
emit(name, ...args) {
const list = this.listeners.get(name);
if (!list) {
return;
}
list.forEach((fn) => fn.apply(this, args));
}
off(name) {
this.listeners.delete(name);
}
};
// src/helper.ts
function initEmitter(config) {
const baseEvent = new Emitter();
const appEvent = new Emitter();
baseEvent.on("SET_CONFIG", (val) => {
var _a;
(_a = config == null ? void 0 : config.SET_CONFIG) == null ? void 0 : _a.call(config, val);
});
baseEvent.on("SET_DELETE", (val) => {
var _a;
(_a = config == null ? void 0 : config.SET_DELETE) == null ? void 0 : _a.call(config, val);
});
baseEvent.on("SET_SELECTED", (val) => {
var _a;
(_a = config == null ? void 0 : config.SET_SELECTED) == null ? void 0 : _a.call(config, val);
});
import_micro_app.default.setGlobalData({
BASE_EMITTER: baseEvent,
MPD_EMITTER: appEvent
});
return { baseEvent, appEvent };
}
// src/vue/Editor.ts
var import_micro_app2 = __toESM(require("@micro-zoe/micro-app"), 1);
var Editor_default = (0, import_vue_demi.defineComponent)({
props: {
name: {
type: String,
default: "miniprogram-design"
},
url: {
type: String,
required: true
},
inline: Boolean,
modelValue: {
type: Object,
default: () => ({
globalConfig: {},
body: {}
})
},
upload: {
type: Function,
default: () => ({})
},
remoteUrl: {
type: String,
required: true
},
schema: {
type: Object,
default: () => ({})
},
widgets: {
type: Array,
default: () => []
},
routes: {
type: Array,
default: () => [{ name: "Home", path: "/" }]
},
settings: {
type: Object,
default: () => ({})
},
extra: {
type: Object,
default: () => ({})
}
},
emits: [
"mounted",
"delete",
"change",
"update:modelValue",
"selected"
],
expose: ["clearSelected"],
setup(props, { emit, expose }) {
const isPrepare = (0, import_vue_demi.ref)(false);
import_micro_app2.default.addDataListener(props.name, (val) => {
const { event } = val;
if (event === "mounted") {
emit("mounted");
isPrepare.value = true;
}
});
(0, import_vue_demi.onMounted)(() => {
(0, import_micro_app2.renderApp)({
name: props.name,
url: props.url,
container: `#${props.name}`,
inline: props.inline,
"disable-patch-request": true,
// 关闭对子应用请求的拦截
"disable-memory-router": true,
// 关闭虚拟路由
data: __spreadValues({
upload: props.upload,
remoteUrl: props.remoteUrl
}, props.extra)
});
});
const { appEvent } = initEmitter({
SET_CONFIG(val) {
emit("update:modelValue", val);
emit("change", val);
},
SET_SELECTED(val) {
emit("selected", val);
},
SET_DELETE(val) {
emit("delete", val);
}
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_WIDGETS", props.widgets);
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_REMOTE_URL", props.remoteUrl);
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_SETTINGS", props.settings);
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_SCHEMA", props.schema);
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_ROUTES", props.routes);
});
(0, import_vue_demi.watchEffect)(() => {
isPrepare.value && setData("SET_CONFIG", props.modelValue);
});
function setData(name, data) {
return __async(this, null, function* () {
appEvent.emit(name, data);
});
}
expose({
clearSelected() {
setData("CLEAR_SELECTED");
}
});
return () => (0, import_vue_demi.h)("div", { id: props.name });
}
});
// src/vue/index.ts
var VueEditor = Editor_default;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
VueEditor
});