UNPKG

@gaoding/editor-sdk

Version:

稿定编辑器对外 SDK

51 lines (50 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var promise_map_1 = require("./promise-map"); var Editor = /** @class */ (function () { function Editor(config) { this.config = config; } Object.defineProperty(Editor.prototype, "width", { get: function () { return this.config.width; }, enumerable: false, configurable: true }); Object.defineProperty(Editor.prototype, "height", { get: function () { return this.config.height; }, enumerable: false, configurable: true }); Editor.prototype.addElement = function (data) { var payload = JSON.parse(JSON.stringify(data)); var asyncId = Math.random(); return this.postMessage('editor.addElement', payload, asyncId); }; Editor.prototype.setWatermark = function (url) { var asyncId = Math.random(); return this.postMessage('editor.setWatermark', url, asyncId); }; Editor.prototype.postMessage = function (action, payload, asyncId) { var _this = this; var send = function () { _this.config.frame.contentWindow.postMessage({ action: action, asyncId: asyncId, payload: payload }, '*'); }; if (asyncId) { return new Promise(function (resolve) { send(); promise_map_1.default[asyncId] = resolve; }); } send(); }; return Editor; }()); exports.default = Editor;