'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var engine = require('@aomao/engine');
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _regeneratorRuntime() {
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
_regeneratorRuntime = function () {
return exports;
};
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return generator._invoke = function (innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
exports.wrap = wrap;
var ContinueSentinel = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
this._invoke = function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
function doneResult() {
return {
value: undefined,
done: !0
};
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (object) {
var keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {
while (!Object.prototype.hasOwnProperty.call(object, property)) {
object = _getPrototypeOf(object);
if (object === null) break;
}
return object;
}
function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get.bind();
} else {
_get = function _get(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
var desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.get) {
return desc.get.call(arguments.length < 3 ? target : receiver);
}
return desc.value;
};
}
return _get.apply(this, arguments);
}
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css_248z = ".data-video {\r\n margin: 0 auto;\r\n position: relative;\r\n cursor: pointer;\r\n}\r\n .data-video-content {\r\n position: relative;\r\n height: 420px;\r\n background: #f7f7f7;\r\n }\r\n .data-video-content video {\r\n width: 100%;\r\n height: 100%;\r\n outline: none;\r\n position: relative;\r\n z-index: 1;\r\n background: #000;\r\n }\r\n .data-video-uploading,\r\n .data-video-uploaded,\r\n .data-video-error {\r\n border: 1px solid #e6e6e6;\r\n background: #f6f6f6;\r\n }\r\n .data-video-content .data-video-mask {\r\n width: 100%;\r\n height: 100%;\r\n position: absolute;\r\n left: 0;\r\n top: 0;\r\n z-index: 1;\r\n }\r\n .data-video-done {\r\n height: auto;\r\n border: none;\r\n background: none;\r\n line-height: 0;\r\n }\r\n .data-video-active {\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n user-select: none;\r\n }\r\n .data-video-center {\r\n position: absolute;\r\n top: 50%;\r\n margin-top: -48px;\r\n width: 100%;\r\n height: 96px;\r\n }\r\n .data-video-center .data-video-icon,\r\n .data-video-center .data-video-name,\r\n .data-video-center .data-video-message,\r\n .data-video-center .data-video-progress,\r\n .data-video-center .data-video-transcoding {\r\n text-align: center;\r\n }\r\n .data-video-center .data-video-icon {\r\n font-size: 24px;\r\n color: #BFBFBF;\r\n margin-bottom: 12px;\r\n }\r\n .data-video-center .data-video-name {\r\n color: #595959;\r\n margin-bottom: 12px;\r\n }\r\n .data-video-center .data-video-message {\r\n color: #595959;\r\n }\r\n .data-video-center .data-video-anticon {\r\n display: inline-block;\r\n font-style: normal;\r\n vertical-align: -0.125em;\r\n text-align: center;\r\n text-transform: none;\r\n line-height: 0;\r\n text-rendering: optimizeLegibility;\r\n -webkit-font-smoothing: antialiased;\r\n margin-right: 5px;\r\n }\r\n .data-video-center .data-video-anticon .data-video-anticon-spin {\r\n display: inline-block;\r\n -webkit-animation: loadingCircle 1s infinite linear;\r\n animation: loadingCircle 1s infinite linear;\r\n }\r\n .data-video-center .data-error-icon {\r\n width: 16px;\r\n height: 16px;\r\n display: inline-block;\r\n background: #F5222D;\r\n text-align: center;\r\n font-size: 12px;\r\n color: #ffffff;\r\n padding: 1px 0 0 0;\r\n line-height: 16px;\r\n border-radius: 100%;\r\n vertical-align: middle;\r\n margin: -2px 5px 0 0;\r\n }\r\n\r\n.data-video-title {\r\n text-align: center;\r\n}\r\n.data-video-title::-moz-selection {\r\n background: transparent\r\n}\r\n.data-video-title::selection {\r\n background: transparent\r\n}\r\n.data-video .data-resizer {\r\n z-index: inherit;\r\n}\r\n.data-video .data-resizer .data-resizer-holder {\r\n z-index: 2;\r\n}\r\n\r\n.data-video .data-resizing {\r\n z-index: 3;\r\n}";
styleInject(css_248z);
var VideoComponent = /*#__PURE__*/function (_Card) {
_inherits(VideoComponent, _Card);
var _super = _createSuper(VideoComponent);
function VideoComponent() {
var _this;
_classCallCheck(this, VideoComponent);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.maxWidth = 0;
_this.resizer = void 0;
_this.video = void 0;
_this.isLoad = false;
_this.container = void 0;
_this.videoContainer = void 0;
_this.title = void 0;
_this.mask = void 0;
_this.rate = 1;
_this._fullWidth = void 0;
_this._naturalSize = {
width: 0,
height: 0
};
_this.onBeforeRender = function (action, url) {
var videoPlugin = _this.editor.plugin.findPlugin('video');
if (videoPlugin) {
var _ref = videoPlugin.options || {},
onBeforeRender = _ref.onBeforeRender;
if (onBeforeRender) return onBeforeRender(action, url, _this.editor);
}
return url;
};
_this.downloadFile = function () {
var value = _this.getValue();
if (!(value === null || value === void 0 ? void 0 : value.download)) return;
window.open(engine.sanitizeUrl(_this.onBeforeRender('download', value.url)));
};
_this.onWindowResize = function () {
if (!engine.isEngine(_this.editor)) return;
_this.maxWidth = _this.getMaxWidth();
_this.resetSize();
if (_this.resizer) {
var _this$videoContainer, _this$videoContainer2;
_this.resizer.maxWidth = _this.maxWidth;
_this.resizer.setSize(((_this$videoContainer = _this.videoContainer) === null || _this$videoContainer === void 0 ? void 0 : _this$videoContainer.width()) || 0, ((_this$videoContainer2 = _this.videoContainer) === null || _this$videoContainer2 === void 0 ? void 0 : _this$videoContainer2.height()) || 0);
}
};
_this.handleClick = function (event) {
var editor = _this.editor;
if (engine.isEngine(editor) && !_this.activated) {
editor.card.activate(_this.root, engine.CardActiveTrigger.MOUSE_DOWN, event);
}
};
return _this;
}
_createClass(VideoComponent, [{
key: "getLocales",
value: function getLocales() {
return this.editor.language.get('video');
}
}, {
key: "renderTemplate",
value: function renderTemplate(value) {
var name = value.name,
status = value.status,
size = value.size,
message = value.message,
percent = value.percent;
var locales = this.getLocales();
var icons = {
video: "
",
spin: "",
warn: "",
error: 'X'
};
if (status === 'error') {
return "\n \n
\n
\n
".concat(engine.escape(name), "
\n
\n ").concat(icons.error, "\n ").concat(message || locales['loadError'], "\n
\n
\n
\n
");
}
var fileSize = size ? engine.getFileSize(size) : '';
var titleElement = name ? "".concat(engine.escape(name), "
") : '';
if (status === 'uploading') {
return "\n \n
\n
\n ".concat(icons.video, "\n
\n ").concat(engine.escape(name), " (").concat(engine.escape(fileSize), ")\n
\n
\n ").concat(icons.spin, "\n ").concat(percent || 0, "%\n
\n
\n
\n
");
}
var isLoading = typeof status === 'undefined';
if (status === 'transcoding' || isLoading) {
return "\n \n
\n
\n ".concat(icons.video, "\n
\n ").concat(engine.escape(name), " (").concat(engine.escape(fileSize), ")\n
\n
\n ").concat(icons.spin, "\n ").concat(isLoading ? locales['loading'] : locales['transcoding'], "%\n
\n
\n
\n
\n ");
}
var videoPlugin = this.editor.plugin.components['video'];
return "\n \n
\n\t\t\t".concat(videoPlugin && videoPlugin.options.showTitle !== false ? titleElement : '', "\n
\n ");
}
}, {
key: "initPlayer",
value: function initPlayer() {
var _this$container,
_this$container2,
_this2 = this,
_this$container3;
var value = this.getValue();
if (!value) return;
var url = engine.sanitizeUrl(this.onBeforeRender('query', value.url));
var video = document.createElement('video');
video.preload = 'metadata';
video.setAttribute('src', url);
video.setAttribute('webkit-playsinline', 'webkit-playsinline');
video.setAttribute('playsinline', 'playsinline');
var cover = value.cover;
if (cover) {
video.poster = engine.sanitizeUrl(this.onBeforeRender('cover', cover));
}
this.maxWidth = this.getMaxWidth();
var contentElement = (_this$container = this.container) === null || _this$container === void 0 ? void 0 : _this$container.find('.data-video-content');
if (!contentElement) return;
contentElement.append(video);
this.mask = engine.$('');
contentElement.append(this.mask);
this.videoContainer = (_this$container2 = this.container) === null || _this$container2 === void 0 ? void 0 : _this$container2.find('.data-video-content');
video.oncontextmenu = function () {
return false;
};
var videoPlugin = this.editor.plugin.findPlugin('video');
var fullEditor = videoPlugin === null || videoPlugin === void 0 ? void 0 : videoPlugin.options.fullEditor;
var editor = this.editor;
video.onloadedmetadata = function () {
if (!value.naturalWidth || !value.naturalHeight) {
value.naturalWidth = video.videoWidth;
value.naturalHeight = video.videoHeight;
_this2.setValue({
naturalWidth: value.naturalWidth,
naturalHeight: value.naturalHeight
});
}
if (fullEditor && _this2._fullWidth && (value.naturalWidth < _this2._fullWidth || typeof fullEditor === 'number')) {
if (typeof fullEditor === 'boolean') {
_this2.rate = video.videoHeight / video.videoWidth;
fullEditor = _this2._fullWidth * _this2.rate;
} else {
_this2.rate = fullEditor / _this2._fullWidth;
}
_this2._naturalSize = {
width: _this2._fullWidth,
height: fullEditor
};
} else {
_this2._naturalSize = {
width: value.naturalWidth || video.videoWidth,
height: value.naturalHeight || video.videoHeight
};
_this2.rate = _this2._naturalSize.height / _this2._naturalSize.width;
}
_this2.resetSize();
};
this.video = engine.$(video);
this.title = (_this$container3 = this.container) === null || _this$container3 === void 0 ? void 0 : _this$container3.find('.data-video-title');
if (value.width && value.height) {
this.rate = value.height / value.width;
}
this._naturalSize = {
width: value.naturalWidth || video.videoWidth,
height: value.naturalHeight || video.videoHeight
};
this.resetSize(); // 一次渲染时序开启 controls 会触发一次内容为空的 window.onerror,疑似 chrome bug
setTimeout(function () {
video.controls = true;
if (!engine.isEngine(editor)) video['controlsList'] = 'nodownload';
}, 0);
}
}, {
key: "toolbar",
value: function toolbar() {
var _this3 = this,
_editor$plugin$findPl;
var editor = this.editor;
var getItems = function getItems() {
var items = [];
var value = _this3.getValue();
if (!value) return items;
var status = value.status,
download = value.download;
var locale = _this3.getLocales();
if (status === 'done') {
if (!!download) {
items.push({
key: 'dropdown',
type: 'button',
content: '',
title: locale.download,
onClick: _this3.downloadFile
});
}
if (engine.isEngine(editor) && !editor.readonly) {
items.push({
key: 'copy',
type: 'copy'
});
items.push({
key: 'separator',
type: 'separator'
});
}
}
if (engine.isEngine(editor) && !editor.readonly) {
items.push({
key: 'delete',
type: 'delete'
});
}
return items;
};
var options = (_editor$plugin$findPl = editor.plugin.findPlugin('video')) === null || _editor$plugin$findPl === void 0 ? void 0 : _editor$plugin$findPl.options;
if (options === null || options === void 0 ? void 0 : options.cardToolbars) {
return options.cardToolbars(getItems(), this.editor);
}
return getItems();
}
}, {
key: "setProgressPercent",
value: function setProgressPercent(percent) {
var _this$container4;
(_this$container4 = this.container) === null || _this$container4 === void 0 ? void 0 : _this$container4.find('.percent').html("".concat(percent, "%"));
this.setValue({
percent: percent
});
}
}, {
key: "getMaxWidth",
value: function getMaxWidth() {
var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getCenter();
var block = this.editor.block.closest(node).get();
if (!block) return 0;
return block.clientWidth;
}
/**
* 重置大小
*/
}, {
key: "resetSize",
value: function resetSize() {
var _this$container5, _this$video, _this$container6;
if (!this.videoContainer) return;
var value = this.getValue();
if (!value) return;
this.videoContainer.css({
width: '',
height: ''
});
(_this$container5 = this.container) === null || _this$container5 === void 0 ? void 0 : _this$container5.css({
width: ''
});
var videoPlugin = this.editor.plugin.findPlugin('video');
var fullEditor = videoPlugin === null || videoPlugin === void 0 ? void 0 : videoPlugin.options.fullEditor;
var video = (_this$video = this.video) === null || _this$video === void 0 ? void 0 : _this$video.get();
if (!video) return;
var width = value.width,
height = value.height;
if (!height) {
width = this._naturalSize.width;
height = Math.round(this.rate * width);
} else if (!width) {
height = this._naturalSize.height;
width = Math.round(height / this.rate);
} else if (width && height) {
// 修正非正常的比例
height = Math.round(this.rate * width);
} else {
width = this._naturalSize.width;
height = this._naturalSize.height;
}
if (width > this.maxWidth) {
width = this.maxWidth;
height = Math.round(width * this.rate);
}
if (width === 0 || height === 0) return;
(_this$container6 = this.container) === null || _this$container6 === void 0 ? void 0 : _this$container6.css({
width: width > 0 ? "".concat(width, "px") : ''
});
this.videoContainer.css('width', width > 0 ? "".concat(width, "px") : '');
if (typeof fullEditor === 'number') this.videoContainer.css('height', height > 0 ? "".concat(height, "px") : '');
}
}, {
key: "changeSize",
value: function changeSize(width, height) {
var _this$videoContainer3, _this$container7, _this$resizer;
if (width < 24) {
width = 24;
height = width * this.rate;
}
if (width > this.maxWidth) {
width = this.maxWidth;
height = width * this.rate;
}
if (height < 24) {
height = 24;
width = height / this.rate;
}
width = Math.round(width);
height = Math.round(height);
(_this$videoContainer3 = this.videoContainer) === null || _this$videoContainer3 === void 0 ? void 0 : _this$videoContainer3.css({
width: width > 0 ? "".concat(width, "px") : ''
});
var videoPlugin = this.editor.plugin.findPlugin('video');
var fullEditor = videoPlugin === null || videoPlugin === void 0 ? void 0 : videoPlugin.options.fullEditor;
if (typeof fullEditor === 'number') {
var _this$videoContainer4;
(_this$videoContainer4 = this.videoContainer) === null || _this$videoContainer4 === void 0 ? void 0 : _this$videoContainer4.css({
height: "".concat(height, "px")
});
}
(_this$container7 = this.container) === null || _this$container7 === void 0 ? void 0 : _this$container7.css({
width: width > 0 ? "".concat(width, "px") : ''
});
this.setValue({
width: width,
height: height
});
(_this$resizer = this.resizer) === null || _this$resizer === void 0 ? void 0 : _this$resizer.destroy();
this.initResizer();
}
}, {
key: "initResizer",
value: function initResizer() {
var _this4 = this,
_this$videoContainer5;
var value = this.getValue();
if (!value) return;
var status = value.status;
if (status !== 'done') return;
var width = value.width,
height = value.height,
cover = value.cover;
this.maxWidth = this.getMaxWidth(); // 拖动调整视频大小
var resizer = new engine.Resizer({
imgUrl: cover,
width: width || this._naturalSize.width,
height: height || this._naturalSize.height,
rate: this.rate,
maxWidth: this.maxWidth,
onChange: function onChange(_ref2) {
var width = _ref2.width,
height = _ref2.height;
return _this4.changeSize(width, height);
}
});
this.resizer = resizer;
var resizerNode = resizer.render();
(_this$videoContainer5 = this.videoContainer) === null || _this$videoContainer5 === void 0 ? void 0 : _this$videoContainer5.append(resizerNode);
}
}, {
key: "onActivate",
value: function onActivate(activated) {
_get(_getPrototypeOf(VideoComponent.prototype), "onActivate", this).call(this, activated);
if (activated) {
var _this$container8, _this$mask;
(_this$container8 = this.container) === null || _this$container8 === void 0 ? void 0 : _this$container8.addClass('data-video-active');
(_this$mask = this.mask) === null || _this$mask === void 0 ? void 0 : _this$mask.hide();
this.initResizer();
} else {
var _this$container9, _this$mask2, _this$resizer2;
(_this$container9 = this.container) === null || _this$container9 === void 0 ? void 0 : _this$container9.removeClass('data-video-active');
(_this$mask2 = this.mask) === null || _this$mask2 === void 0 ? void 0 : _this$mask2.show();
(_this$resizer2 = this.resizer) === null || _this$resizer2 === void 0 ? void 0 : _this$resizer2.destroy();
}
}
}, {
key: "onSelectByOther",
value: function onSelectByOther(selected, value) {
var _this$container10;
(_this$container10 = this.container) === null || _this$container10 === void 0 ? void 0 : _this$container10.css('outline', selected ? '2px solid ' + value.color : '');
var className = 'card-selected-other';
if (selected) this.root.addClass(className);else this.root.removeClass(className);
return this.container;
}
}, {
key: "writeHistoryOnValueChange",
value: function writeHistoryOnValueChange() {
if (this.loading) return false;
return;
}
}, {
key: "checker",
value: function checker(video_id, success, failed) {
var command = this.editor.command;
var handle = function handle() {
command.executeMethod('video-uploader', 'query', video_id, function (data) {
if (data && data.status !== 'done') setTimeout(handle, 3000);else success(data);
}, function (message) {
failed(message);
});
};
handle();
}
}, {
key: "render",
value: function render() {
var _this5 = this;
var value = this.getValue();
var center = this.getCenter();
var editor = this.editor;
this._fullWidth = editor.container.width() - engine.removeUnit(editor.container.css('padding-left')) - engine.removeUnit(editor.container.css('padding-right'));
if (!value || this.container && this.container.inEditor()) {
//设置为加载状态
this.container = engine.$(this.renderTemplate(_objectSpread2({}, value)));
center.empty();
center.append(this.container);
this.initPlayer();
return;
} //先清空卡片内容容器
center.empty();
var command = editor.command,
plugin = editor.plugin;
var video_id = value.video_id,
status = value.status;
var locales = this.getLocales();
this.maxWidth = this.getMaxWidth(); //阅读模式
if (!engine.isEngine(editor)) {
if (status === 'done') {
//设置为加载状态
this.container = engine.$(this.renderTemplate(_objectSpread2(_objectSpread2({}, value), {}, {
status: undefined
})));
var updateValue = function updateValue(data) {
var newValue = _objectSpread2(_objectSpread2({}, value), {}, {
url: !!(data === null || data === void 0 ? void 0 : data.url) ? data.url : value.url,
name: !!(data === null || data === void 0 ? void 0 : data.name) ? data.name : value.name,
cover: !!(data === null || data === void 0 ? void 0 : data.cover) ? data.cover : value.cover,
download: !!(data === null || data === void 0 ? void 0 : data.download) ? data.download : value.download
});
_this5.container = engine.$(_this5.renderTemplate(newValue));
center.empty();
center.append(_this5.container);
_this5.initPlayer();
};
if (plugin.components['video-uploader']) {
command.executeMethod('video-uploader', 'query', video_id, function (data) {
updateValue(data);
}, function (error) {
_this5.container = engine.$(_this5.renderTemplate(_objectSpread2(_objectSpread2({}, value), {}, {
status: 'error',
message: error || locales['loadError']
})));
center.empty();
center.append(_this5.container);
});
} else {
updateValue();
}
return this.container;
} else if (status === 'error') {
return engine.$(this.renderTemplate(_objectSpread2(_objectSpread2({}, value), {}, {
message: value.message || locales['loadError']
})));
}
} //转换中
else if (status === 'transcoding') {
this.container = engine.$(this.renderTemplate(value));
if (!video_id) throw 'video id is undefined';
this.checker(video_id, function (data) {
var newValue = _objectSpread2(_objectSpread2({}, value), {}, {
url: !!(data === null || data === void 0 ? void 0 : data.url) ? data.url : value.url,
name: !!(data === null || data === void 0 ? void 0 : data.name) ? data.name : value.name,
cover: !!(data === null || data === void 0 ? void 0 : data.cover) ? data.cover : value.cover,
download: !!(data === null || data === void 0 ? void 0 : data.download) ? data.download : value.download,
status: 'done'
});
_this5.setValue(newValue);
_this5.container = engine.$(_this5.renderTemplate(newValue));
center.empty();
center.append(_this5.container);
_this5.initPlayer();
}, function (error) {
var newValue = _objectSpread2(_objectSpread2({}, value), {}, {
status: 'error',
message: error || locales['loadError']
});
_this5.setValue(newValue);
_this5.container = engine.$(_this5.renderTemplate(newValue));
center.empty();
center.append(_this5.container);
});
return this.container;
} //已完成
else if (status === 'done') {
//设置为加载状态
this.container = engine.$(this.renderTemplate(_objectSpread2(_objectSpread2({}, value), {}, {
status: undefined
})));
command.executeMethod('video-uploader', 'query', video_id, function (data) {
var newValue = _objectSpread2(_objectSpread2({}, value), {}, {
url: !!(data === null || data === void 0 ? void 0 : data.url) ? data.url : value.url,
name: !!(data === null || data === void 0 ? void 0 : data.name) ? data.name : value.name,
cover: !!(data === null || data === void 0 ? void 0 : data.cover) ? data.cover : value.cover,
download: !!(data === null || data === void 0 ? void 0 : data.download) ? data.download : value.download
});
_this5.container = engine.$(_this5.renderTemplate(newValue));
_this5.video = _this5.container.find('video');
center.empty();
center.append(_this5.container);
_this5.initPlayer();
}, function (error) {
_this5.container = engine.$(_this5.renderTemplate(_objectSpread2(_objectSpread2({}, value), {}, {
status: 'error',
message: error || locales['loadError']
})));
center.empty();
center.append(_this5.container);
});
return this.container;
} else {
this.container = engine.$(this.renderTemplate(value));
return this.container;
}
}
}, {
key: "didUpdate",
value: function didUpdate() {
var _this$toolbarModel;
_get(_getPrototypeOf(VideoComponent.prototype), "didUpdate", this).call(this);
(_this$toolbarModel = this.toolbarModel) === null || _this$toolbarModel === void 0 ? void 0 : _this$toolbarModel.setDefaultAlign('top');
}
}, {
key: "didRender",
value: function didRender() {
var _this$toolbarModel2, _this$container11;
var value = this.getValue();
if (value.status === 'done') _get(_getPrototypeOf(VideoComponent.prototype), "didRender", this).call(this);
this.onWindowResize();
var editor = this.editor;
window.addEventListener('resize', this.onWindowResize);
editor.on('editor:resize', this.onWindowResize);
(_this$toolbarModel2 = this.toolbarModel) === null || _this$toolbarModel2 === void 0 ? void 0 : _this$toolbarModel2.setDefaultAlign('top');
(_this$container11 = this.container) === null || _this$container11 === void 0 ? void 0 : _this$container11.on('mousedown', this.handleClick);
if (!engine.isEngine(editor) || editor.readonly) {
var _this$mask3;
(_this$mask3 = this.mask) === null || _this$mask3 === void 0 ? void 0 : _this$mask3.hide();
}
}
}, {
key: "destroy",
value: function destroy() {
var _this$container12;
_get(_getPrototypeOf(VideoComponent.prototype), "destroy", this).call(this);
(_this$container12 = this.container) === null || _this$container12 === void 0 ? void 0 : _this$container12.off('mousedown', this.handleClick);
window.removeEventListener('resize', this.onWindowResize);
this.editor.off('editor:resize', this.onWindowResize);
}
}], [{
key: "cardName",
get: function get() {
return 'video';
}
}, {
key: "cardType",
get: function get() {
return engine.CardType.BLOCK;
}
}, {
key: "autoSelected",
get: function get() {
return false;
}
}]);
return VideoComponent;
}(engine.Card);
var DROP_FILES = 'drop:files';
var PASTE_EVENT = 'paste:event';
var PASTE_EACH = 'paste:each';
var _default = /*#__PURE__*/function (_Plugin) {
_inherits(_default, _Plugin);
var _super = _createSuper(_default);
function _default() {
var _this;
_classCallCheck(this, _default);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.cardComponents = {};
_this.extensionNames = {
mp4: 'video/mp4'
};
_this.dropFiles = function (files) {
var editor = _this.editor;
if (!engine.isEngine(editor)) return;
files = files.filter(function (file) {
return _this.isVideo(file);
});
if (files.length === 0) return;
editor.command.execute('video-uploader', files);
return false;
};
_this.pasteFiles = function (_ref) {
var files = _ref.files;
var editor = _this.editor;
if (!engine.isEngine(editor)) return;
files = files.filter(function (file) {
return _this.isVideo(file);
});
if (files.length === 0) return;
editor.command.execute('video-uploader', files.filter(function (file) {
return _this.isVideo(file);
}), files);
return false;
};
_this.pasteEach = function (node) {
//是卡片,并且还没渲染
if (node.isCard() && node.attributes(engine.READY_CARD_KEY)) {
if (node.attributes(engine.READY_CARD_KEY) !== 'video') return;
var value = engine.decodeCardValue(node.attributes(engine.CARD_VALUE_KEY));
if (!value || !value.url) {
node.remove();
return;
}
if (value.status === 'uploading') {
//如果是上传状态,设置为正常状态
value.percent = 0;
node.attributes(engine.CARD_VALUE_KEY, engine.encodeCardValue(_objectSpread2(_objectSpread2({}, value), {}, {
status: 'done'
})));
}
return;
}
};
return _this;
}
_createClass(_default, [{
key: "init",
value: function init() {
var editor = this.editor;
if (engine.isEngine(editor)) {
editor.on(DROP_FILES, this.dropFiles);
editor.on(PASTE_EVENT, this.pasteFiles);
editor.on(PASTE_EACH, this.pasteEach);
}
var _ref2 = this.options.file || {},
accept = _ref2.accept;
if (typeof accept === 'string') accept = accept.split(',');
if (Array.isArray(accept)) {
var names = [];
(accept || []).forEach(function (name) {
name = name.trim();
var newName = name.split('.').pop();
if (newName) names.push(newName);
});
if (names.length > 0) this.extensionNames = names;
} else if (_typeof(accept) === 'object') {
this.extensionNames = accept;
}
}
}, {
key: "isVideo",
value: function isVideo(file) {
var name = engine.getExtensionName(file);
var names = Array.isArray(this.extensionNames) ? this.extensionNames : Object.keys(this.extensionNames);
return names.indexOf('*') >= 0 || names.indexOf(name) >= 0;
}
}, {
key: "execute",
value: function () {
var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(files) {
var _this2 = this;
var editor,
request,
card,
language,
_this$options,
action,
data,
type,
contentType,
multiple,
crossOrigin,
withCredentials,
headers,
name,
parse,
limitSize,
accepts,
_args = arguments;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(typeof files === 'string')) {
_context.next = 6;
break;
}
_context.t0 = files;
_context.next = _context.t0 === 'query' ? 4 : 5;
break;
case 4:
return _context.abrupt("return", this.query(_args.length <= 1 ? undefined : _args[1], _args.length <= 2 ? undefined : _args[2], _args.length <= 3 ? undefined : _args[3]));
case 5:
return _context.abrupt("return");
case 6:
editor = this.editor;
request = editor.request, card = editor.card, language = editor.language;
_this$options = this.options, action = _this$options.action, data = _this$options.data, type = _this$options.type, contentType = _this$options.contentType, multiple = _this$options.multiple, crossOrigin = _this$options.crossOrigin, withCredentials = _this$options.withCredentials, headers = _this$options.headers, name = _this$options.name;
parse = this.options.parse;
limitSize = this.options.limitSize || 5 * 1024 * 1024;
if (Array.isArray(files)) {
_context.next = 16;
break;
}
accepts = Array.isArray(this.extensionNames) ? '.' + this.extensionNames.join(',.') : Object.values(this.extensionNames).join(',');
_context.next = 15;
return request.getFiles({
event: files,
accept: engine.isAndroid ? 'video/*' : accepts.length > 0 ? accepts : '',
multiple: multiple
});
case 15:
files = _context.sent;
case 16:
if (!(files.length === 0)) {
_context.next = 18;
break;
}
return _context.abrupt("return");
case 18:
request.upload({
url: action,
data: data,
type: type,
contentType: contentType,
crossOrigin: crossOrigin,
withCredentials: withCredentials,
headers: headers,
onBefore: function onBefore(file) {
if (file.size > limitSize) {
editor.messageError('upload-limit', language.get('video', 'uploadLimitError').toString().replace('$size', (limitSize / 1024 / 1024).toFixed(0) + 'M'));
return false;
}
return true;
},
onReady: function onReady(fileInfo) {
if (!engine.isEngine(editor) || !!_this2.cardComponents[fileInfo.uid]) return;
var component = card.insert('video', {
status: 'uploading',
name: fileInfo.name,
size: fileInfo.size
});
_this2.cardComponents[fileInfo.uid] = component;
},
onUploading: function onUploading(file, _ref3) {
var percent = _ref3.percent;
var component = _this2.cardComponents[file.uid || ''];
if (!component) return;
component.setProgressPercent(percent);
},
onSuccess: function onSuccess(response, file) {
var component = _this2.cardComponents[file.uid || ''];
if (!component) return;
var id = response.id || response.data && response.data.id;
var url = response.url || response.data && response.data.url;
var cover = response.cover || response.data && response.data.cover;
var download = response.download || response.data && response.data.download;
var width = response.width || response.data && response.data.width;
var height = response.height || response.data && response.data.height;
var status = response.status || response.data && response.data.status;
status = status === 'transcoding' ? 'transcoding' : 'done';
var result = {
result: true,
data: {
video_id: id,
url: url,
cover: cover,
download: download,
status: status,
width: width,
height: height
}
};
if (parse) {
var customizeResult = parse(response);
if (customizeResult.result) {
var _data = result.data;
if (typeof customizeResult.data === 'string') result.data = _objectSpread2(_objectSpread2({}, _data), {}, {
url: customizeResult.data
});else {
_data.url = customizeResult.data.url;
if (customizeResult.data.status !== undefined) _data = _objectSpread2(_objectSpread2({}, _data), {}, {
status: customizeResult.data.status
});
if (customizeResult.data.id !== undefined) _data = _objectSpread2(_objectSpread2({}, _data), {}, {
video_id: customizeResult.data.id
});
if (customizeResult.data.cover !== undefined) _data = _objectSpread2(_objectSpread2({}, _data), {}, {
cover: customizeResult.data.cover
});
if (customizeResult.data.width !== undefined) _data = _objectSpread2(_objectSpread2({}, _data), {}, {
width: customizeResult.data.width
});
if (customizeResult.data.height !== undefined) _data = _objectSpread2(_objectSpread2({}, _data), {}, {
height: customizeResult.data.height
});
result.data = _objectSpread2({}, _data);
}
} else {
result = {
result: false,
data: customizeResult.data.toString()
};
}
} else if (!url) {
result = {
result: false,
data: response.data
};
} //失败
if (!result.result) {
card.update(component.id, {
status: 'error',
message: typeof result.data === 'string' ? result.data : language.get('video', 'uploadError')
});
} //成功
else {
editor.card.update(component.id, typeof result.data === 'string' ? {
url: result.data
} : _objectSpread2(_objectSpread2({}, result.data), {}, {
naturalWidth: result.data.width,
naturalHeight: result.data.height
}));
}
delete _this2.cardComponents[file.uid || ''];
},
onError: function onError(error, file) {
var component = _this2.cardComponents[file.uid || ''];
if (!component) return;
card.update(component.id, {
status: 'error',
message: error.message || language.get('video', 'uploadError')
});
delete _this2.cardComponents[file.uid || ''];
}
}, files, name);
return _context.abrupt("return");
case 20:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function execute(_x) {
return _execute.apply(this, arguments);
}
return execute;
}()
}, {
key: "query",
value: function query(video_id, _success) {
var failed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
var _this$editor = this.editor,
request = _this$editor.request,
language = _this$editor.language;
var _this$options2 = this.options,
query = _this$options2.query,
parse = _this$options2.parse;
if (!query || !video_id) return _success();
var action = query.action,
type = query.type,
contentType = query.contentType,
data = query.data,
headers = query.headers;
request.ajax({
url: action,
contentType: contentType || '',
type: type === undefined ? 'json' : type,
headers: headers,
data: typeof data === 'function' ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
var newData;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return data();
case 2:
newData = _context2.sent;
return _context2.abrupt("return", _objectSpread2(_objectSpread2({}, newData), {}, {
id: video_id
}));
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
})) : _objectSpread2(_objectSpread2({}, data), {}, {
id: video_id
}),
success: function success(response) {
var result = response.result,
data = response.data;
if (!result) {
failed(data);
} else {
var _result = parse ? parse(response) : response;
if (_result.result === false) {
failed(_result.data || language.get('video', 'loadError'));
} else _success(_objectSpread2(_objectSpread2({}, _result.data), {}, {
status: _result.data.status !== 'transcoding' ? 'done' : 'transcoding'
}));
}
},
error: function error(_error) {
failed(_error.message || language.get('video', 'loadError'));
},
method: 'GET'
});
}
}, {
key: "destroy",
value: function destroy() {
var editor = this.editor;
editor.off(DROP_FILES, this.dropFiles);
editor.off(PASTE_EVENT, this.pasteFiles);
editor.off(PASTE_EACH, this.pasteEach);
}
}], [{
key: "pluginName",
get: function get() {
return 'video-uploader';
}
}]);
return _default;
}(engine.Plugin);
var en = {
video: {
errorMessageCopy: 'Copy error message',
loadError: 'The video failed to load!',
uploadError: 'The video failed to upload!',
uploadLimitError: 'Upload video size is limited to $size',
download: 'Download',
preview: 'Preview',
loading: 'Loading...',
transcoding: 'Transcoding...'
}
};
var cn = {
video: {
errorMessageCopy: '复制错误信息',
loadError: '视频加载失败!',
uploadError: '上传视频失败!',
uploadLimitError: '上传视频大小限制为 $size',
download: '下载',
preview: '预览',
loading: '加载中...',
transcoding: '转码中...'
}
};
var locales = {
'en-US': en,
'zh-CN': cn
};
var PARSE_HTML = 'parse:html';
var PASTE_EACH$1 = 'paste:each';
var PASTE_SCHEMA = 'paste:schema';
var VideoPlugin = /*#__PURE__*/function (_Plugin) {
_inherits(VideoPlugin, _Plugin);
var _super = _createSuper(VideoPlugin);
function VideoPlugin() {
var _this;
_classCallCheck(this, VideoPlugin);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.pasteSchema = function (schema) {
schema.add({
type: 'block',
name: 'div',
attributes: {
'data-value': '*',
'data-type': {
required: true,
value: VideoComponent.cardName
}
}
});
};
_this.pasteHtml = function (node) {
var editor = _this.editor;
if (!engine.isEngine(editor)) return;
if (node.isElement()) {
var type = node.attributes('data-type');
if (type === VideoComponent.cardName) {
var value = node.attributes('data-value');
var cardValue = engine.decodeCardValue(value);
if (!cardValue.url) return;
editor.card.replaceNode(node, VideoComponent.cardName, cardValue);
node.remove();
return false;
}
}
return true;
};
_this.parseHtml = function (root, callback) {
var results = [];
root.find("[".concat(engine.CARD_KEY, "=\"").concat(VideoComponent.cardName, "\"],[").concat(engine.READY_CARD_KEY, "=\"").concat(VideoComponent.cardName, "\"]")).each(function (cardNode) {
var node = engine.$(cardNode);
var card = _this.editor.card.find(node);
var value = (card === null || card === void 0 ? void 0 : card.getValue()) || engine.decodeCardValue(node.attributes(engine.CARD_VALUE_KEY));
if ((value === null || value === void 0 ? void 0 : value.url) && value.status === 'done') {
var onBeforeRender = _this.options.onBeforeRender;
var cover = value.cover,
url = value.url;
var html = "");
node.empty();
var newNode = engine.$(html);
if (callback) {
newNode = callback(newNode, value);
}
node.replaceWith(newNode);
results.push(newNode);
} else node.remove();
});
return results;
};
return _this;
}
_createClass(VideoPlugin, [{
key: "init",
value: function init() {
var editor = this.editor;
editor.language.add(locales);
editor.on(PARSE_HTML, this.parseHtml);
editor.on(PASTE_EACH$1, this.pasteHtml);
editor.on(PASTE_SCHEMA, this.pasteSchema);
}
}, {
key: "execute",
value: function execute(status, url, name, video_id, cover, size, download, naturalWidth, naturalHeight, width, height) {
var value = {
status: status,
video_id: video_id,
cover: cover,
url: url,
name: name || url,
size: size,
download: download,
width: width,
height: height,
naturalWidth: naturalWidth,
naturalHeight: naturalHeight
};
if (status === 'error') {
value.url = '';
value.message = url;
}
this.editor.card.insert('video', value);
}
}, {
key: "waiting",
value: function () {
var _waiting = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(callback) {
var _this2 = this;
var card, check, find, waitCheck;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
card = this.editor.card; // 检测单个组件
check = function check(component) {
var _component$getValue;
return component.root.inEditor() && component.name === VideoComponent.cardName && ((_component$getValue = component.getValue()) === null || _component$getValue === void 0 ? void 0 : _component$getValue.status) === 'uploading';
}; // 找到不合格的组件
find = function find() {
return card.components.find(check);
};
waitCheck = function waitCheck(component) {
var time = 60000;
return new Promise(function (resolve, reject) {
if (callback) {
var result = callback(_this2.constructor.pluginName, component);
if (result === false) {
return reject({
name: _this2.constructor.pluginName,
card: component
});
} else if (typeof result === 'number') {
time = result;
}
}
var beginTime = new Date().getTime();
var now = new Date().getTime();
var timeout = function timeout() {
if (now - beginTime >= time) return resolve();
setTimeout(function () {
if (check(component)) timeout();else resolve();
}, 10);
};
timeout();
});
};
return _context2.abrupt("return", new Promise( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
var component, wait;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
component = find();
wait = function wait(component) {
waitCheck(component).then(function () {
var next = find();
if (next) wait(next);else resolve();
}).catch(reject);
};
if (component) wait(component);else resolve();
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x2, _x3) {
return _ref.apply(this, arguments);
};
}()));
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function waiting(_x) {
return _waiting.apply(this, arguments);
}
return waiting;
}()
}, {
key: "destroy",
value: function destroy() {
var editor = this.editor;
editor.off(PARSE_HTML, this.parseHtml);
editor.off(PASTE_EACH$1, this.pasteHtml);
editor.off(PASTE_SCHEMA, this.pasteSchema);
}
}], [{
key: "pluginName",
get: function get() {
return 'video';
}
}]);
return VideoPlugin;
}(engine.Plugin);
exports.VideoComponent = VideoComponent;
exports.VideoUploader = _default;
exports.default = VideoPlugin;