UNPKG

wft-generate-form

Version:

基于web端xps-formmaking生成的json在uniapp中动态解析

97 lines (96 loc) 3.9 kB
"use strict"; /** * Copyright (c) 2018-present, Ephox, Inc. * * This source code is licensed under the Apache 2 license found in the * LICENSE file in the root directory of this source tree. * */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var ScriptLoader_1 = require("../ScriptLoader"); var TinyMCE_1 = require("../TinyMCE"); var Utils_1 = require("../Utils"); var EditorPropTypes_1 = require("./EditorPropTypes"); var renderInline = function (h, id, tagName) { return h(tagName ? tagName : 'div', { attrs: { id: id } }); }; var renderIframe = function (h, id) { return h('textarea', { attrs: { id: id }, style: { visibility: 'hidden' } }); }; var initialise = function (ctx) { return function () { var finalInit = __assign(__assign({}, ctx.$props.init), { readonly: ctx.$props.disabled, selector: "#" + ctx.elementId, plugins: Utils_1.mergePlugins(ctx.$props.init && ctx.$props.init.plugins, ctx.$props.plugins), toolbar: ctx.$props.toolbar || (ctx.$props.init && ctx.$props.init.toolbar), inline: ctx.inlineEditor, setup: function (editor) { ctx.editor = editor; editor.on('init', function (e) { return Utils_1.initEditor(e, ctx, editor); }); if (ctx.$props.init && typeof ctx.$props.init.setup === 'function') { ctx.$props.init.setup(editor); } } }); if (Utils_1.isTextarea(ctx.element)) { ctx.element.style.visibility = ''; ctx.element.style.display = ''; } TinyMCE_1.getTinymce().init(finalInit); }; }; exports.Editor = { props: EditorPropTypes_1.editorProps, created: function () { this.elementId = this.$props.id || Utils_1.uuid('tiny-vue'); this.inlineEditor = (this.$props.init && this.$props.init.inline) || this.$props.inline; this.initialized = false; }, watch: { disabled: function () { this.editor.setMode(this.disabled ? 'readonly' : 'design'); } }, mounted: function () { this.element = this.$el; if (TinyMCE_1.getTinymce() !== null) { initialise(this)(); } else if (this.element && this.element.ownerDocument) { var channel = this.$props.cloudChannel ? this.$props.cloudChannel : '5'; var apiKey = this.$props.apiKey ? this.$props.apiKey : 'no-api-key'; var scriptSrc = Utils_1.isNullOrUndefined(this.$props.tinymceScriptSrc) ? "https://admin.al1ydb.com/static/tinymce5.7/js/tinymce/tinymce.min.js" : this.$props.tinymceScriptSrc; ScriptLoader_1.ScriptLoader.load(this.element.ownerDocument, scriptSrc, initialise(this)); } }, beforeDestroy: function () { if (TinyMCE_1.getTinymce() !== null) { TinyMCE_1.getTinymce().remove(this.editor); } }, deactivated: function () { var _a; if (!this.inlineEditor) { this.cache = this.editor.getContent(); (_a = TinyMCE_1.getTinymce()) === null || _a === void 0 ? void 0 : _a.remove(this.editor); } }, activated: function () { if (!this.inlineEditor && this.initialized) { initialise(this)(); } }, render: function (h) { return this.inlineEditor ? renderInline(h, this.elementId, this.$props.tagName) : renderIframe(h, this.elementId); } };