wft-generate-form
Version:
基于web端xps-formmaking生成的json在uniapp中动态解析
95 lines (94 loc) • 3.75 kB
JavaScript
/**
* 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);
};
import { ScriptLoader } from '../ScriptLoader';
import { getTinymce } from '../TinyMCE';
import { initEditor, isTextarea, mergePlugins, uuid, isNullOrUndefined } from '../Utils';
import { editorProps } from './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: 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 initEditor(e, ctx, editor); });
if (ctx.$props.init && typeof ctx.$props.init.setup === 'function') {
ctx.$props.init.setup(editor);
}
} });
if (isTextarea(ctx.element)) {
ctx.element.style.visibility = '';
ctx.element.style.display = '';
}
getTinymce().init(finalInit);
}; };
export var Editor = {
props: editorProps,
created: function () {
this.elementId = this.$props.id || 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 (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 = isNullOrUndefined(this.$props.tinymceScriptSrc) ?
"https://admin.al1ydb.com/static/tinymce5.7/js/tinymce/tinymce.min.js" :
this.$props.tinymceScriptSrc;
ScriptLoader.load(this.element.ownerDocument, scriptSrc, initialise(this));
}
},
beforeDestroy: function () {
if (getTinymce() !== null) {
getTinymce().remove(this.editor);
}
},
deactivated: function () {
var _a;
if (!this.inlineEditor) {
this.cache = this.editor.getContent();
(_a = 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);
}
};