@wangeditor-next/video-module 4.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/src/config/interface.d.ts +32 -2
- package/dist/core/src/editor/interface.d.ts +16 -3
- package/dist/core/src/index.d.ts +4 -2
- package/dist/core/src/render/helper.d.ts +1 -2
- package/dist/core/src/to-html/index.d.ts +12 -0
- package/dist/core/src/utils/dom.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/video-module/src/utils/dom.d.ts +1 -1
- package/package.json +3 -3
- package/dist/basic-modules/src/modules/image/custom-types.d.ts +0 -22
- package/dist/table-module/src/utils/has-common.d.ts +0 -7
- package/dist/table-module/src/utils/index.d.ts +0 -5
- package/dist/table-module/src/utils/is-of-type.d.ts +0 -6
- package/dist/table-module/src/utils/matrices.d.ts +0 -9
- package/dist/table-module/src/utils/options.d.ts +0 -25
- package/dist/table-module/src/utils/point.d.ts +0 -7
- package/dist/table-module/src/utils/types.d.ts +0 -19
|
@@ -2,13 +2,41 @@
|
|
|
2
2
|
* @description config interface
|
|
3
3
|
* @author wangfupeng
|
|
4
4
|
*/
|
|
5
|
-
import type { ImageElement } from 'packages/basic-modules/src/modules/image/custom-types';
|
|
6
|
-
import type { VideoElement } from 'packages/video-module/src/module/custom-types';
|
|
7
5
|
import type { Descendant, Node, NodeEntry, Range } from 'slate';
|
|
8
6
|
import type { IDomEditor } from '../editor/interface';
|
|
9
7
|
import type { IMenuGroup } from '../menus/interface';
|
|
10
8
|
import type { IUploadConfig } from '../upload/interface';
|
|
11
9
|
import type { DOMElement } from '../utils/dom';
|
|
10
|
+
type EmptyText = {
|
|
11
|
+
text: '';
|
|
12
|
+
};
|
|
13
|
+
type ImageElement = {
|
|
14
|
+
type: 'image';
|
|
15
|
+
src: string;
|
|
16
|
+
alt?: string;
|
|
17
|
+
href?: string;
|
|
18
|
+
width?: string;
|
|
19
|
+
height?: string;
|
|
20
|
+
style?: {
|
|
21
|
+
width?: string;
|
|
22
|
+
height?: string;
|
|
23
|
+
};
|
|
24
|
+
children: EmptyText[];
|
|
25
|
+
};
|
|
26
|
+
type VideoElement = {
|
|
27
|
+
type: 'video';
|
|
28
|
+
key?: string;
|
|
29
|
+
src: string;
|
|
30
|
+
poster?: string;
|
|
31
|
+
align?: 'left' | 'center' | 'right';
|
|
32
|
+
width?: string;
|
|
33
|
+
height?: string;
|
|
34
|
+
style?: {
|
|
35
|
+
width?: string;
|
|
36
|
+
height?: string;
|
|
37
|
+
};
|
|
38
|
+
children: EmptyText[];
|
|
39
|
+
};
|
|
12
40
|
interface IHoverbarConf {
|
|
13
41
|
[key: string]: {
|
|
14
42
|
match?: (editor: IDomEditor, n: Node) => boolean;
|
|
@@ -127,6 +155,8 @@ interface ICodeBlockConfig {
|
|
|
127
155
|
export interface IMenuConfig {
|
|
128
156
|
bold: ISingleMenuConfig;
|
|
129
157
|
underline: ISingleMenuConfig;
|
|
158
|
+
wavyUnderline: ISingleMenuConfig;
|
|
159
|
+
emphasisDot: ISingleMenuConfig;
|
|
130
160
|
italic: ISingleMenuConfig;
|
|
131
161
|
through: ISingleMenuConfig;
|
|
132
162
|
code: ISingleMenuConfig;
|
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
* @description editor interface
|
|
3
3
|
* @author wangfupeng
|
|
4
4
|
*/
|
|
5
|
-
import { NodeEntryWithContext } from '@wangeditor-next/table-module/src/utils';
|
|
6
5
|
import ee from 'event-emitter';
|
|
7
|
-
import { Ancestor, Editor, Element, Location, Node } from 'slate';
|
|
6
|
+
import { Ancestor, Editor, Element, Location, Node, NodeEntry } from 'slate';
|
|
8
7
|
import { AlertType, IEditorConfig, IMenuConfig, ISingleMenuConfig } from '../config/interface';
|
|
9
8
|
import { IPositionStyle } from '../menus/interface';
|
|
10
9
|
import { DOMElement } from '../utils/dom';
|
|
11
10
|
export type ElementWithId = Element & {
|
|
12
11
|
id: string;
|
|
13
12
|
};
|
|
13
|
+
export type TableSelectionEntry = [
|
|
14
|
+
NodeEntry<Element & {
|
|
15
|
+
type: unknown;
|
|
16
|
+
rowSpan?: number;
|
|
17
|
+
colSpan?: number;
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
}>,
|
|
20
|
+
{
|
|
21
|
+
rtl: number;
|
|
22
|
+
ltr: number;
|
|
23
|
+
ttb: number;
|
|
24
|
+
btt: number;
|
|
25
|
+
}
|
|
26
|
+
];
|
|
14
27
|
type MoveOptions = Parameters<Editor['move']>[0];
|
|
15
28
|
export type getMenuConfigReturnType<K> = K extends keyof IMenuConfig ? IMenuConfig[K] : ISingleMenuConfig;
|
|
16
29
|
/**
|
|
@@ -59,7 +72,7 @@ export interface IDomEditor extends Editor {
|
|
|
59
72
|
move(distance: number, reverse?: boolean): void;
|
|
60
73
|
moveReverse: (distance: number) => void;
|
|
61
74
|
restoreSelection: () => void;
|
|
62
|
-
getTableSelection?: () =>
|
|
75
|
+
getTableSelection?: () => TableSelectionEntry[][] | null;
|
|
63
76
|
getSelectionPosition: () => Partial<IPositionStyle>;
|
|
64
77
|
getNodePosition: (node: Node) => Partial<IPositionStyle>;
|
|
65
78
|
isSelectedAll: () => boolean;
|
package/dist/core/src/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type { IDomEditor } from './editor/interface';
|
|
|
7
7
|
import type { IRegisterMenuConf } from './menus/index';
|
|
8
8
|
import type { IParseElemHtmlConf, IPreParseHtmlConf, ParseStyleHtmlFnType } from './parse-html/index';
|
|
9
9
|
import type { IRenderElemConf, RenderStyleFnType } from './render/index';
|
|
10
|
-
import type { IElemToHtmlConf, styleToHtmlFnType } from './to-html/index';
|
|
10
|
+
import type { HtmlTransformFnType, IElemToHtmlConf, styleToHtmlFnType } from './to-html/index';
|
|
11
11
|
import createUploaderRuntime from './upload/createUploader';
|
|
12
12
|
import type { IUploadConfig } from './upload/interface';
|
|
13
13
|
export * from './create/index';
|
|
14
|
-
export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
|
|
14
|
+
export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, ISingleMenuConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
|
|
15
|
+
export { EditorEvents } from './config/interface';
|
|
15
16
|
export * from './config/style-mode';
|
|
16
17
|
export * from './editor/dom-editor';
|
|
17
18
|
export * from './editor/interface';
|
|
@@ -35,6 +36,7 @@ export interface IModuleConf {
|
|
|
35
36
|
renderStyle: RenderStyleFnType;
|
|
36
37
|
renderElems: Array<IRenderElemConf>;
|
|
37
38
|
styleToHtml: styleToHtmlFnType;
|
|
39
|
+
htmlTransform?: HtmlTransformFnType;
|
|
38
40
|
elemsToHtml: Array<IElemToHtmlConf>;
|
|
39
41
|
preParseHtml: Array<IPreParseHtmlConf>;
|
|
40
42
|
parseStyleHtml: ParseStyleHtmlFnType;
|
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
* @description formats helper
|
|
3
3
|
* @author wangfupeng
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
export declare function genElemId(type: ElementType, id: string): string;
|
|
5
|
+
export declare function genElemId(type: string, id: string): string;
|
|
7
6
|
export declare function genTextId(id: string): string;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Descendant, Element as SlateElement } from 'slate';
|
|
6
6
|
import { IDomEditor } from '../editor/interface';
|
|
7
|
+
import type { INodeToHtmlOptions } from './node2html';
|
|
7
8
|
export type styleToHtmlFnType = (node: Descendant, elemHtml: string, editor?: IDomEditor) => string;
|
|
8
9
|
export declare const STYLE_TO_HTML_FN_LIST: styleToHtmlFnType[];
|
|
9
10
|
/**
|
|
@@ -11,6 +12,17 @@ export declare const STYLE_TO_HTML_FN_LIST: styleToHtmlFnType[];
|
|
|
11
12
|
* @param fn 处理 toHtml 文本样式的函数
|
|
12
13
|
*/
|
|
13
14
|
export declare function registerStyleToHtmlHandler(fn: styleToHtmlFnType): void;
|
|
15
|
+
/**
|
|
16
|
+
* Transform the HTML fragments of the document's top-level nodes.
|
|
17
|
+
*
|
|
18
|
+
* Element serializers intentionally stay node-local. Modules that need
|
|
19
|
+
* neighboring blocks to produce valid HTML (for example semantic lists) use
|
|
20
|
+
* this hook after every node has been serialized.
|
|
21
|
+
*/
|
|
22
|
+
export type HtmlTransformFnType = (htmlList: string[], nodes: Descendant[], editor: IDomEditor, options: INodeToHtmlOptions) => string[];
|
|
23
|
+
export declare const HTML_TRANSFORM_HANDLER_LIST: HtmlTransformFnType[];
|
|
24
|
+
export declare function registerHtmlTransformHandler(fn: HtmlTransformFnType): void;
|
|
25
|
+
export declare function transformHtml(htmlList: string[], nodes: Descendant[], editor: IDomEditor, options?: INodeToHtmlOptions): string[];
|
|
14
26
|
interface IElemToHtmlRes {
|
|
15
27
|
html: string;
|
|
16
28
|
prefix?: string;
|
|
@@ -10,7 +10,7 @@ import DOMText = globalThis.Text;
|
|
|
10
10
|
import DOMRange = globalThis.Range;
|
|
11
11
|
import DOMSelection = globalThis.Selection;
|
|
12
12
|
import DOMStaticRange = globalThis.StaticRange;
|
|
13
|
-
export { Dom7Array } from 'dom7';
|
|
13
|
+
export type { Dom7Array } from 'dom7';
|
|
14
14
|
export default $;
|
|
15
15
|
export declare enum NodeType {
|
|
16
16
|
ELEMENT_NODE = 1,
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@wangeditor-next/core"),require("dom7"),require("slate"),require("nanoid"),require("@wangeditor-next/core/upload"),require("snabbdom")):"function"==typeof define&&define.amd?define(["@wangeditor-next/core","dom7","slate","nanoid","@wangeditor-next/core/upload","snabbdom"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).WangEditorVideoModule=t(e.core,e.$,e.slate,e.nanoid,e.upload,e.snabbdom)}(this,function(e,t,o,n,r,i){"use strict";function a(e){return e.length?e[0].tagName.toLowerCase():""}function d(e,o,n,r,i){void 0===o&&(o="auto"),void 0===n&&(n="auto"),void 0===r&&(r={}),void 0===i&&(i=!1);var a=t(e),d=r.width,u=void 0===d?"":d,c=r.height,l=void 0===c?"":c,s=u?'data-w-e-style-width="'.concat(u,'"'):"",v=l?'data-w-e-style-height="'.concat(l,'"'):"";if(a.attr("width",o),a.attr("height",n),i)s&&a.attr("data-w-e-style-width",u),v&&a.attr("data-w-e-style-height",l),a.removeAttr("style");else{var f="display: block; max-width: 100%;";u&&(f+=" width: ".concat(u,";")),l&&(f+=" height: ".concat(l,";")),a.attr("style",f)}return a[0].outerHTML}e.i18nAddResources("en",{videoModule:{delete:"Delete",uploadVideo:"Upload video",insertVideo:"Insert video",videoSrc:"Video source",videoSrcPlaceHolder:"Video file url, or third-party <iframe>",videoPoster:"Video poster",videoPosterPlaceHolder:"Poster image url",ok:"Ok",editSize:"Edit size",edit:"Edit video",width:"Width",height:"Height",alignLeft:"Align video left",alignCenter:"Center video",alignRight:"Align video right"}}),e.i18nAddResources("zh-CN",{videoModule:{delete:"删除视频",uploadVideo:"上传视频",insertVideo:"插入视频",videoSrc:"视频地址",videoSrcPlaceHolder:"视频文件 url 或第三方 <iframe>",videoPoster:"视频封面",videoPosterPlaceHolder:"封面图片 url",ok:"确定",editSize:"修改尺寸",edit:"编辑视频",width:"宽度",height:"高度",alignLeft:"视频左对齐",alignCenter:"视频居中",alignRight:"视频右对齐"}}),t.append&&(t.fn.append=t.append),t.on&&(t.fn.on=t.on),t.focus&&(t.fn.focus=t.focus),t.attr&&(t.fn.attr=t.attr),t.val&&(t.fn.val=t.val),t.html&&(t.fn.html=t.html),t.parent&&(t.fn.parent=t.parent),t.hasClass&&(t.fn.hasClass=t.hasClass),t.empty&&(t.fn.empty=t.empty);var u="center",c=["left","center","right"];function l(e){if("string"!=typeof e)return u;var t=e.trim().toLowerCase();return c.includes(t)?t:u}function s(e){var t=e.align;return l(t||e.textAlign)}function v(e){return"w-e-video-align-".concat(e)}var f={type:"video",elemToHtml:function(t,o,n){var r=t,i=r.src,a=void 0===i?"":i,u=r.poster,c=void 0===u?"":u,l=r.width,f=void 0===l?"auto":l,h=r.height,p=void 0===h?"auto":h,g=r.style,y=void 0===g?{}:g,m=e.getTextStyleMode(n),w=s(t),b=' data-w-e-align="'.concat(w,'"'),M="class"===m?"".concat(b,' class="w-e-video ').concat(v(w),'"'):"".concat(b,' style="display: flex; justify-content: ').concat(function(e){return"left"===e?"flex-start":"right"===e?"flex-end":"center"}(w),'; margin: 0; max-width: 100%; width: 100%;"'),S='<figure data-w-e-type="video" data-w-e-is-void'.concat(M,">\n");if(0===a.trim().indexOf("<iframe ")){S+=d(a,f,p,y,"class"===m)}else{var x=y.width,V=void 0===x?"":x,E=y.height,I=void 0===E?"":E;if("class"===m){var N=V?' data-w-e-style-width="'.concat(V,'"'):"",P=I?' data-w-e-style-height="'.concat(I,'"'):"";S+='<video poster="'.concat(c,'" controls="true" width="').concat(f,'" height="').concat(p,'"').concat(N).concat(P,'><source src="').concat(a,'" type="video/mp4"/></video>')}else{var k="display: block; max-width: 100%;";V&&(k+=" width: ".concat(V,";")),I&&(k+=" height: ".concat(I,";")),S+='<video poster="'.concat(c,'" controls="true" width="').concat(f,'" height="').concat(p,'" style="').concat(k,'"><source src="').concat(a,'" type="video/mp4"/></video>')}}return S+="\n</figure>"}};var h=function(){return h=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},h.apply(this,arguments)};function p(e,t,o,n){return new(o||(o=Promise))(function(r,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function d(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(a,d)}u((n=n.apply(e,t||[])).next())})}function g(e,t){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=d(0),a.throw=d(1),a.return=d(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function d(d){return function(u){return function(d){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,d[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&d[0]?n.return:d[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,d[1])).done)return r;switch(n=0,r&&(d=[2&d[0],r.value]),d[0]){case 0:case 1:r=d;break;case 4:return i.label++,{value:d[1],done:!1};case 5:i.label++,n=d[1],d=[0];continue;case 7:d=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==d[0]&&2!==d[0])){i=0;continue}if(3===d[0]&&(!r||d[1]>r[0]&&d[1]<r[3])){i.label=d[1];break}if(6===d[0]&&i.label<r[1]){i.label=r[1],r=d;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(d);break}r[2]&&i.ops.pop(),i.trys.pop();continue}d=t.call(e,i)}catch(e){d=[6,e],n=0}finally{o=r=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,u])}}}function y(e){var t="function"==typeof Symbol&&Symbol.iterator,o=t&&e[t],n=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,i=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return a}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,o=e[Symbol.asyncIterator];return o?o.call(e):(e=y(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=e[o]&&function(t){return new Promise(function(n,r){(function(e,t,o,n){Promise.resolve(n).then(function(t){e({value:t,done:o})},t)})(n,r,(t=e[o](t)).done,t.value)})}}}function b(e){return void 0===e&&(e="r"),"".concat(e,"-").concat(n.nanoid())}function M(e){var t={};return e.trim().split(";").forEach(function(e){if(e){var o=m(e.split(":"),2),n=o[0],r=o[1];n&&r&&(t[n.trim()]=r.trim())}}),t}function S(){return b("w-e-insert-video")}"function"==typeof SuppressedError&&SuppressedError;var x=function(){function n(){this.title=e.t("videoModule.editSize"),this.tag="button",this.showModal=!0,this.modalWidth=320,this.$content=null,this.widthInputId=S(),this.heightInputId=S(),this.buttonId=S()}return n.prototype.getSelectedVideoNode=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideoNode(e)},n.prototype.getModalPositionNode=function(e){return this.getSelectedVideoNode(e)},n.prototype.getModalContentElem=function(n){var r=this,i=r.widthInputId,a=r.heightInputId,d=r.buttonId,u=m(e.genModalInputElems(e.t("videoModule.width"),i,"auto"),2),c=u[0],l=u[1],s=t(l),v=m(e.genModalInputElems(e.t("videoModule.height"),a,"auto"),2),f=v[0],p=v[1],g=t(p),y=m(e.genModalButtonElems(d,e.t("videoModule.ok")),1)[0],w=this.getSelectedVideoNode(n);if(null==this.$content){var b=t("<div></div>");b.on("click","#".concat(d),function(t){t.preventDefault();var r=b.find("#".concat(i)).val().trim(),d=b.find("#".concat(a)).val().trim(),u=function(e){return/^\d+(\.\d+)?%$/.test(e)},c=function(e){return/^\d+(\.\d+)?$/.test(e)},l="auto",s="auto";u(r)?l=r:c(r)&&(l="".concat(parseInt(r,10),"px")),u(d)?s=d:c(d)&&(s="".concat(parseInt(d,10),"px"));var v=w.style,f=void 0===v?{}:v;n.restoreSelection();var p={style:h(h({},f),{width:l,height:s})};o.Transforms.setNodes(n,p,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}}),n.hidePanelOrModal()}),this.$content=b}var M=this.$content;if(M.empty(),M.append(c),M.append(f),M.append(y),null==w)return M[0];var S=w.style,x=void 0===S?{}:S,V=x.width,E=void 0===V?"":V,I=x.height,N=void 0===I?"":I;return s.val(E),g.val(N),setTimeout(function(){s.focus()}),M[0]},n}();function V(){return b("w-e-edit-video")}var E=function(){function n(){this.title=e.t("videoModule.edit"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M864 0a160 160 0 0 1 128 256l-64 64-224-224 64-64c26.752-20.096 59.968-32 96-32zM64 736l-64 288 288-64 592-592-224-224L64 736z m651.584-372.416l-448 448-55.168-55.168 448-448 55.168 55.168z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.srcInputId=V(),this.posterInputId=V(),this.buttonId=V()}return n.prototype.getSelectedVideoNode=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideoNode(e)},n.prototype.getModalPositionNode=function(e){return this.getSelectedVideoNode(e)},n.prototype.getModalContentElem=function(n){var r=this,i=this,a=i.srcInputId,d=i.posterInputId,u=i.buttonId,c=m(e.genModalInputElems(e.t("videoModule.videoSrc"),a,e.t("videoModule.videoSrcPlaceHolder")),2),l=c[0],s=c[1],v=m(e.genModalInputElems(e.t("videoModule.videoPoster"),d,e.t("videoModule.videoPosterPlaceHolder")),2),f=v[0],h=v[1],y=t(s),w=t(h),M=m(e.genModalButtonElems(u,e.t("videoModule.ok")),1)[0];if(null==this.$content){var S=t("<div></div>");S.on("click","#".concat(u),function(t){return p(r,void 0,void 0,function(){var r,i,u,c;return g(this,function(l){return t.preventDefault(),r=S.find("#".concat(a)).val().trim(),i=S.find("#".concat(d)).val().trim(),u=b("video-"),c={src:r,poster:i,key:u},n.restoreSelection(),o.Transforms.setNodes(n,c,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}}),n.hidePanelOrModal(),[2]})})}),this.$content=S}var x=this.$content;x.empty(),x.append(l),x.append(f),x.append(M);var V=this.getSelectedVideoNode(n);if(null==V)return x[0];var E=V.src,I=void 0===E?"":E,N=V.poster,P=void 0===N?"":N;return y.val(I),w.val(P),setTimeout(function(){y.focus()}),x[0]},n}();function I(t,n){return p(this,arguments,void 0,function(t,n,r,i,a){var d,u,c,l,s,v,f;return void 0===r&&(r=""),void 0===i&&(i=""),void 0===a&&(a=""),g(this,function(h){switch(h.label){case 0:return n?(t.restoreSelection(),d=t.getMenuConfig("insertVideo"),u=d.onInsertedVideo,c=d.checkVideo,l=d.parseVideoSrc,[4,c(n,r)]):[2];case 1:return"string"==typeof(s=h.sent())?(t.alert(s,"error"),[2]):null==s?[2]:[4,l(n)];case 2:return 0!==(v=h.sent()).trim().indexOf("<iframe ")&&(v=v.replace(/</g,"<").replace(/>/g,">")),f={type:"video",src:v,poster:r,align:"center",children:[{text:""}],style:{width:i,height:a}},Promise.resolve().then(function(){e.DomEditor.isSelectedEmptyParagraph(t)&&o.Transforms.removeNodes(t,{mode:"highest"}),o.Transforms.insertNodes(t,f,{mode:"highest"})}),u(f),[2]}})})}function N(){return b("w-e-insert-video")}var P=function(){function n(){this.title=e.t("videoModule.insertVideo"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M981.184 160.096C837.568 139.456 678.848 128 512 128S186.432 139.456 42.816 160.096C15.296 267.808 0 386.848 0 512s15.264 244.16 42.816 351.904C186.464 884.544 345.152 896 512 896s325.568-11.456 469.184-32.096C1008.704 756.192 1024 637.152 1024 512s-15.264-244.16-42.816-351.904zM384 704V320l320 192-320 192z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=320,this.$content=null,this.srcInputId=N(),this.posterInputId=N(),this.buttonId=N()}return n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!o.Range.isCollapsed(n)||!!e.DomEditor.getSelectedElems(t).some(function(o){return"pre"===e.DomEditor.getNodeType(o)||!!t.isVoid(o)}))},n.prototype.getModalPositionNode=function(e){return null},n.prototype.getModalContentElem=function(o){var n=this,r=this,i=r.srcInputId,a=r.posterInputId,d=r.buttonId,u=m(e.genModalInputElems(e.t("videoModule.videoSrc"),i,e.t("videoModule.videoSrcPlaceHolder")),2),c=u[0],l=u[1],s=m(e.genModalInputElems(e.t("videoModule.videoPoster"),a,e.t("videoModule.videoPosterPlaceHolder")),2),v=s[0],f=s[1],h=t(l),y=t(f),w=m(e.genModalButtonElems(d,e.t("videoModule.ok")),1)[0];if(null==this.$content){var b=t("<div></div>");b.on("click","#".concat(d),function(e){return p(n,void 0,void 0,function(){var t,n;return g(this,function(r){switch(r.label){case 0:return e.preventDefault(),t=b.find("#".concat(i)).val().trim(),n=b.find("#".concat(a)).val().trim(),[4,I(o,t,n)];case 1:return r.sent(),o.hidePanelOrModal(),[2]}})})}),this.$content=b}var M=this.$content;return M.empty(),M.append(c),M.append(v),M.append(w),h.val(""),y.val(""),setTimeout(function(){h.focus()}),M[0]},n}();function k(e){return e.getMenuConfig("uploadVideo")}var z=new WeakMap;function H(e,t){return p(this,void 0,void 0,function(){var o,n;return g(this,function(i){switch(i.label){case 0:return o=function(e){var t=z.get(e);if(null!=t)return t;var o=k(e),n=o.onSuccess,i=o.onProgress,a=o.onFailed,d=o.customInsert,u=o.onError;return t=r.createUploader(h(h({},o),{onProgress:function(t){e.showProgressBar(t),i&&i(t)},onSuccess:function(t,o){if(d)return d(o,function(t,o){return I(e,t,o)}),void n(t,o);var r=o.errno,i=void 0===r?1:r,u=o.data,c=void 0===u?{}:u;if(0===i){var l=c.url,s=void 0===l?"":l,v=c.poster;I(e,s,void 0===v?"":v),n(t,o)}else a(t,o)},onError:function(e,t,o){u(e,t,o)}}),e),z.set(e,t),t}(e),n=t.map(function(e){return{name:e.name,type:e.type,size:e.size,data:e}}),o.addFiles(n),[4,o.upload()];case 1:return i.sent(),[2]}})})}var T=function(){function n(){this.title=e.t("videoModule.uploadVideo"),this.iconSvg='<svg viewBox="0 0 1056 1024"><path d="M805.902261 521.819882a251.441452 251.441452 0 0 0-251.011972 246.600033 251.051015 251.051015 0 1 0 502.023944 8.823877 253.237463 253.237463 0 0 0-251.011972-255.42391z m59.463561 240.001647v129.898403h-116.701631v-129.898403h-44.041298l101.279368-103.504859 101.279368 103.504859z" p-id="6802"></path><path d="M788.254507 0.000781H99.094092A98.663439 98.663439 0 0 0 0.001171 99.093701v590.067495a98.663439 98.663439 0 0 0 99.092921 99.092921h411.7549a266.434235 266.434235 0 0 1-2.186448-41.815807 275.843767 275.843767 0 0 1 275.180024-270.729042 270.650955 270.650955 0 0 1 103.504859 19.834201V99.093701A101.51363 101.51363 0 0 0 788.254507 0.000781zM295.054441 640.747004V147.507894l394.146189 246.600033z"></path></svg>',this.tag="button"}return n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,o){var n=this.getMenuConfig(e),r=n.allowedFileTypes,i=void 0===r?[]:r,a=n.customBrowseAndUpload;if(a)a(function(t,o){return I(e,t,o)});else{var d="";i.length>0&&(d='accept="'.concat(i.join(", "),'"'));var u=t("body"),c=t('<input type="file" '.concat(d," multiple/>"));c.hide(),u.append(c),c.click(),c.on("change",function(){var t=c[0].files;!function(e,t){p(this,void 0,void 0,function(){var o,n,r,i,a,d,u,c,l,s,v,f;return g(this,function(h){switch(h.label){case 0:if(null==t)return[2];o=Array.prototype.slice.call(t),n=[],r=k(e).customUpload,h.label=1;case 1:h.trys.push([1,8,9,14]),i=!0,a=w(o),h.label=2;case 2:return[4,a.next()];case 3:return d=h.sent(),(l=d.done)?[3,7]:(f=d.value,i=!1,u=f,r?[4,r(u,function(t,o){return I(e,t,o)},e)]:[3,5]);case 4:return h.sent(),[3,6];case 5:n.push(u),h.label=6;case 6:return i=!0,[3,2];case 7:return[3,14];case 8:return c=h.sent(),s={error:c},[3,14];case 9:return h.trys.push([9,,12,13]),i||l||!(v=a.return)?[3,11]:[4,v.call(a)];case 10:h.sent(),h.label=11;case 11:return[3,13];case 12:if(s)throw s.error;return[7];case 13:return[7];case 14:return n.length>0?[4,H(e,n)]:[3,16];case 15:h.sent(),h.label=16;case 16:return[2]}})})}(e,t)})}},n.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!o.Range.isCollapsed(n)||!!e.DomEditor.getSelectedElems(t).some(function(o){return"pre"===e.DomEditor.getNodeType(o)||!!t.isVoid(o)}))},n.prototype.getMenuConfig=function(e){return e.getMenuConfig("uploadVideo")},n}(),C=function(){function t(t,o,n){this.align=t,this.iconSvg=n,this.tag="button",this.title=e.t(o)}return t.prototype.getSelectedVideo=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},t.prototype.getValue=function(e){var t=this.getSelectedVideo(e);return!!t&&s(t)},t.prototype.isActive=function(e){return this.getValue(e)===this.align},t.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideo(e)},t.prototype.exec=function(t,n){if(!this.isDisabled(t)){var r={align:this.align};o.Transforms.setNodes(t,r,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}})}},t}();function D(e,t,o,n,r,i){return void 0===t&&(t=""),void 0===o&&(o="auto"),void 0===n&&(n="auto"),void 0===r&&(r={}),void 0===i&&(i="center"),{type:"video",src:e,poster:t,width:o,height:n,style:r,children:[{text:""}],align:i}}function A(e){var t=(e.attr("data-w-e-align")||"").trim();if(t)return l(t);var o=M(e.attr("style")||""),n=o["justify-content"];if("flex-start"===n)return"left";if("flex-end"===n)return"right";if("center"===n)return"center";var r=function(e){for(var t=(e.attr("class")||"").trim().split(/\s+/).filter(Boolean),o=0;o<t.length;o+=1){var n=t[o];if(n.startsWith("w-e-video-align-"))return n.replace("w-e-video-align-","")}return""}(e);if(r)return l(r);var i=o["text-align"],a=(e.attr("data-w-e-text-align")||"").trim();return l(i||a)}function B(e){var t=M(e),o={};return t.width&&(o.width=t.width),t.height&&(o.height=t.height),o}return{renderElems:[{type:"video",renderElem:function(t,o,n){var r,a=t,u=a.src,c=void 0===u?"":u,l=a.poster,f=void 0===l?"":l,h=a.key,p=void 0===h?"":h,g=a.width,y=void 0===g?"auto":g,m=a.height,w=void 0===m?"auto":m,b=a.style,M=void 0===b?{}:b,S=s(t),x=["w-e-video","w-e-textarea-video-container",v(S)].join(" "),V=e.DomEditor.isNodeSelected(n,t);if(0===c.trim().indexOf("<iframe ")){var E=d(c,y,w,M);r=i.jsx("figure",{className:x,"data-selected":V?"true":"","data-w-e-align":S,innerHTML:E})}else{var I=i.jsx("video",{key:p,poster:f,controls:!0,style:M},i.jsx("source",{src:c,type:"video/mp4"}),"Sorry, your browser doesn't support embedded videos.\n 抱歉,浏览器不支持 video 视频");"auto"!==y&&(I.data.width=y),"auto"!==w&&(I.data.height=w),r=i.jsx("figure",{className:x,"data-selected":V?"true":"","data-w-e-align":S},I)}return i.h("div",{props:{contentEditable:!1},on:{mousedown:function(e){return e.preventDefault()}}},r)}}],elemsToHtml:[f],preParseHtml:[{selector:"iframe,video,p",preParseHtml:function(e){var o=t(e),n=o;if("p"===a(o)){var r=o.children();if(1===r.length){var i=r[0],d=i.tagName.toLowerCase();["iframe","video"].includes(d)&&(n=t(i))}}var u=a(n);if("iframe"!==u&&"video"!==u)return n[0];if("video"===n.parent().attr("data-w-e-type"))return n[0];var c=t('<figure data-w-e-type="video" data-w-e-is-void data-w-e-align="center" class="w-e-video w-e-video-align-center"></figure>');return c.append(n),c[0]}}],parseElemsHtml:[{selector:'figure[data-w-e-type="video"],div[data-w-e-type="video"]',parseElemHtml:function(e,o,n){var r=t(e),i="",a="",d="auto",u="auto",c={},l=r.find("iframe");if(l.length>0){d=l.attr("width")||"auto",u=l.attr("height")||"auto",c=B(l.attr("style")||"");var s=l.attr("data-w-e-style-width")||"",v=l.attr("data-w-e-style-height")||"";return!c.width&&s&&(c.width=s),!c.height&&v&&(c.height=v),D(i=l[0].outerHTML,a,d,u,c,A(r))}var f=r.find("video");(i=f.attr("src")||"")||f.length>0&&(i=f.find("source").attr("src")||""),d=f.attr("width")||"auto",u=f.attr("height")||"auto",a=f.attr("poster")||"",c=B(f.attr("style")||"");var h=f.attr("data-w-e-style-width")||"",p=f.attr("data-w-e-style-height")||"";return!c.width&&h&&(c.width=h),!c.height&&p&&(c.height=p),D(i,a,d,u,c,A(r))}}],menus:[{key:"insertVideo",factory:function(){return new P},config:{onInsertedVideo:function(e){},checkVideo:function(e,t){return!0},parseVideoSrc:function(e){return e}}},{key:"uploadVideo",factory:function(){return new T},config:{server:"",fieldName:"wangeditor-uploaded-video",maxFileSize:10485760,maxNumberOfFiles:5,allowedFileTypes:["video/*"],meta:{},metaWithUrl:!1,withCredentials:!1,timeout:3e4,onBeforeUpload:function(e){return e},onProgress:function(e){},onSuccess:function(e,t){},onFailed:function(e,t){console.error("'".concat(e.name,"' upload failed"),t)},onError:function(e,t,o){console.error("'".concat(e.name," upload error"),t,o)}}},{key:"editVideoSize",factory:function(){return new x}},{key:"editVideoSrc",factory:function(){return new E}},{key:"videoAlignLeft",factory:function(){return new C("left","videoModule.alignLeft",'<svg viewBox="0 0 1024 1024"><path d="M768 793.6v102.4H51.2v-102.4h716.8z m204.8-230.4v102.4H51.2v-102.4h921.6z m-204.8-230.4v102.4H51.2v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}},{key:"videoAlignCenter",factory:function(){return new C("center","videoModule.alignCenter",'<svg viewBox="0 0 1024 1024"><path d="M870.4 793.6v102.4H153.6v-102.4h716.8z m102.4-230.4v102.4H51.2v-102.4h921.6z m-102.4-230.4v102.4H153.6v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}},{key:"videoAlignRight",factory:function(){return new C("right","videoModule.alignRight",'<svg viewBox="0 0 1024 1024"><path d="M972.8 793.6v102.4H256v-102.4h716.8z m0-230.4v102.4H51.2v-102.4h921.6z m0-230.4v102.4H256v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}}],editorPlugin:function(t){var n=t.isVoid,r=t.normalizeNode,i=t;return i.isVoid=function(e){return"video"===e.type||n(e)},i.normalizeNode=function(t){var n=m(t,2),a=n[0],d=n[1];"video"===e.DomEditor.getNodeType(a)&&(e.DomEditor.isLastNode(i,a)&&o.Transforms.insertNodes(i,e.DomEditor.genEmptyParagraph(),{at:[d[0]+1]}));return r([a,d])},i}}});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@wangeditor-next/core"),require("dom7"),require("slate"),require("nanoid"),require("@wangeditor-next/core/upload"),require("snabbdom")):"function"==typeof define&&define.amd?define(["@wangeditor-next/core","dom7","slate","nanoid","@wangeditor-next/core/upload","snabbdom"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).WangEditorVideoModule=t(e.WangEditorCore,e.$,e.slate,e.nanoid,e.WangEditorCoreUpload,e.snabbdom)}(this,function(e,t,o,n,r,i){"use strict";function a(e){return e.length?e[0].tagName.toLowerCase():""}function d(e,o,n,r,i){void 0===o&&(o="auto"),void 0===n&&(n="auto"),void 0===r&&(r={}),void 0===i&&(i=!1);var a=t(e),d=r.width,u=void 0===d?"":d,c=r.height,l=void 0===c?"":c,s=u?'data-w-e-style-width="'.concat(u,'"'):"",v=l?'data-w-e-style-height="'.concat(l,'"'):"";if(a.attr("width",o),a.attr("height",n),i)s&&a.attr("data-w-e-style-width",u),v&&a.attr("data-w-e-style-height",l),a.removeAttr("style");else{var f="display: block; max-width: 100%;";u&&(f+=" width: ".concat(u,";")),l&&(f+=" height: ".concat(l,";")),a.attr("style",f)}return a[0].outerHTML}e.i18nAddResources("en",{videoModule:{delete:"Delete",uploadVideo:"Upload video",insertVideo:"Insert video",videoSrc:"Video source",videoSrcPlaceHolder:"Video file url, or third-party <iframe>",videoPoster:"Video poster",videoPosterPlaceHolder:"Poster image url",ok:"Ok",editSize:"Edit size",edit:"Edit video",width:"Width",height:"Height",alignLeft:"Align video left",alignCenter:"Center video",alignRight:"Align video right"}}),e.i18nAddResources("zh-CN",{videoModule:{delete:"删除视频",uploadVideo:"上传视频",insertVideo:"插入视频",videoSrc:"视频地址",videoSrcPlaceHolder:"视频文件 url 或第三方 <iframe>",videoPoster:"视频封面",videoPosterPlaceHolder:"封面图片 url",ok:"确定",editSize:"修改尺寸",edit:"编辑视频",width:"宽度",height:"高度",alignLeft:"视频左对齐",alignCenter:"视频居中",alignRight:"视频右对齐"}}),t.append&&(t.fn.append=t.append),t.on&&(t.fn.on=t.on),t.focus&&(t.fn.focus=t.focus),t.attr&&(t.fn.attr=t.attr),t.val&&(t.fn.val=t.val),t.html&&(t.fn.html=t.html),t.parent&&(t.fn.parent=t.parent),t.hasClass&&(t.fn.hasClass=t.hasClass),t.empty&&(t.fn.empty=t.empty);var u="center",c=["left","center","right"];function l(e){if("string"!=typeof e)return u;var t=e.trim().toLowerCase();return c.includes(t)?t:u}function s(e){var t=e.align;return l(t||e.textAlign)}function v(e){return"w-e-video-align-".concat(e)}var f={type:"video",elemToHtml:function(t,o,n){var r=t,i=r.src,a=void 0===i?"":i,u=r.poster,c=void 0===u?"":u,l=r.width,f=void 0===l?"auto":l,h=r.height,p=void 0===h?"auto":h,g=r.style,y=void 0===g?{}:g,m=e.getTextStyleMode(n),w=s(t),b=' data-w-e-align="'.concat(w,'"'),M="class"===m?"".concat(b,' class="w-e-video ').concat(v(w),'"'):"".concat(b,' style="display: flex; justify-content: ').concat(function(e){return"left"===e?"flex-start":"right"===e?"flex-end":"center"}(w),'; margin: 0; max-width: 100%; width: 100%;"'),S='<figure data-w-e-type="video" data-w-e-is-void'.concat(M,">\n");if(0===a.trim().indexOf("<iframe ")){S+=d(a,f,p,y,"class"===m)}else{var x=y.width,E=void 0===x?"":x,V=y.height,I=void 0===V?"":V;if("class"===m){var N=E?' data-w-e-style-width="'.concat(E,'"'):"",P=I?' data-w-e-style-height="'.concat(I,'"'):"";S+='<video poster="'.concat(c,'" controls="true" width="').concat(f,'" height="').concat(p,'"').concat(N).concat(P,'><source src="').concat(a,'" type="video/mp4"/></video>')}else{var k="display: block; max-width: 100%;";E&&(k+=" width: ".concat(E,";")),I&&(k+=" height: ".concat(I,";")),S+='<video poster="'.concat(c,'" controls="true" width="').concat(f,'" height="').concat(p,'" style="').concat(k,'"><source src="').concat(a,'" type="video/mp4"/></video>')}}return S+="\n</figure>"}};var h=function(){return h=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},h.apply(this,arguments)};function p(e,t,o,n){return new(o||(o=Promise))(function(r,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function d(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(a,d)}u((n=n.apply(e,t||[])).next())})}function g(e,t){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=d(0),a.throw=d(1),a.return=d(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function d(d){return function(u){return function(d){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,d[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&d[0]?n.return:d[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,d[1])).done)return r;switch(n=0,r&&(d=[2&d[0],r.value]),d[0]){case 0:case 1:r=d;break;case 4:return i.label++,{value:d[1],done:!1};case 5:i.label++,n=d[1],d=[0];continue;case 7:d=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==d[0]&&2!==d[0])){i=0;continue}if(3===d[0]&&(!r||d[1]>r[0]&&d[1]<r[3])){i.label=d[1];break}if(6===d[0]&&i.label<r[1]){i.label=r[1],r=d;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(d);break}r[2]&&i.ops.pop(),i.trys.pop();continue}d=t.call(e,i)}catch(e){d=[6,e],n=0}finally{o=r=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,u])}}}function y(e){var t="function"==typeof Symbol&&Symbol.iterator,o=t&&e[t],n=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,i=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return a}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,o=e[Symbol.asyncIterator];return o?o.call(e):(e=y(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=e[o]&&function(t){return new Promise(function(n,r){(function(e,t,o,n){Promise.resolve(n).then(function(t){e({value:t,done:o})},t)})(n,r,(t=e[o](t)).done,t.value)})}}}function b(e){return void 0===e&&(e="r"),"".concat(e,"-").concat(n.nanoid())}function M(e){var t={};return e.trim().split(";").forEach(function(e){if(e){var o=m(e.split(":"),2),n=o[0],r=o[1];n&&r&&(t[n.trim()]=r.trim())}}),t}function S(){return b("w-e-insert-video")}"function"==typeof SuppressedError&&SuppressedError;var x=function(){function n(){this.title=e.t("videoModule.editSize"),this.tag="button",this.showModal=!0,this.modalWidth=320,this.$content=null,this.widthInputId=S(),this.heightInputId=S(),this.buttonId=S()}return n.prototype.getSelectedVideoNode=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideoNode(e)},n.prototype.getModalPositionNode=function(e){return this.getSelectedVideoNode(e)},n.prototype.getModalContentElem=function(n){var r=this,i=r.widthInputId,a=r.heightInputId,d=r.buttonId,u=m(e.genModalInputElems(e.t("videoModule.width"),i,"auto"),2),c=u[0],l=u[1],s=t(l),v=m(e.genModalInputElems(e.t("videoModule.height"),a,"auto"),2),f=v[0],p=v[1],g=t(p),y=m(e.genModalButtonElems(d,e.t("videoModule.ok")),1)[0],w=this.getSelectedVideoNode(n);if(null==this.$content){var b=t("<div></div>");b.on("click","#".concat(d),function(t){t.preventDefault();var r=b.find("#".concat(i)).val().trim(),d=b.find("#".concat(a)).val().trim(),u=function(e){return/^\d+(\.\d+)?%$/.test(e)},c=function(e){return/^\d+(\.\d+)?$/.test(e)},l="auto",s="auto";u(r)?l=r:c(r)&&(l="".concat(parseInt(r,10),"px")),u(d)?s=d:c(d)&&(s="".concat(parseInt(d,10),"px"));var v=w.style,f=void 0===v?{}:v;n.restoreSelection();var p={style:h(h({},f),{width:l,height:s})};o.Transforms.setNodes(n,p,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}}),n.hidePanelOrModal()}),this.$content=b}var M=this.$content;if(M.empty(),M.append(c),M.append(f),M.append(y),null==w)return M[0];var S=w.style,x=void 0===S?{}:S,E=x.width,V=void 0===E?"":E,I=x.height,N=void 0===I?"":I;return s.val(V),g.val(N),setTimeout(function(){s.focus()}),M[0]},n}();function E(){return b("w-e-edit-video")}var V=function(){function n(){this.title=e.t("videoModule.edit"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M864 0a160 160 0 0 1 128 256l-64 64-224-224 64-64c26.752-20.096 59.968-32 96-32zM64 736l-64 288 288-64 592-592-224-224L64 736z m651.584-372.416l-448 448-55.168-55.168 448-448 55.168 55.168z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.srcInputId=E(),this.posterInputId=E(),this.buttonId=E()}return n.prototype.getSelectedVideoNode=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideoNode(e)},n.prototype.getModalPositionNode=function(e){return this.getSelectedVideoNode(e)},n.prototype.getModalContentElem=function(n){var r=this,i=this,a=i.srcInputId,d=i.posterInputId,u=i.buttonId,c=m(e.genModalInputElems(e.t("videoModule.videoSrc"),a,e.t("videoModule.videoSrcPlaceHolder")),2),l=c[0],s=c[1],v=m(e.genModalInputElems(e.t("videoModule.videoPoster"),d,e.t("videoModule.videoPosterPlaceHolder")),2),f=v[0],h=v[1],y=t(s),w=t(h),M=m(e.genModalButtonElems(u,e.t("videoModule.ok")),1)[0];if(null==this.$content){var S=t("<div></div>");S.on("click","#".concat(u),function(t){return p(r,void 0,void 0,function(){var r,i,u,c;return g(this,function(l){return t.preventDefault(),r=S.find("#".concat(a)).val().trim(),i=S.find("#".concat(d)).val().trim(),u=b("video-"),c={src:r,poster:i,key:u},n.restoreSelection(),o.Transforms.setNodes(n,c,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}}),n.hidePanelOrModal(),[2]})})}),this.$content=S}var x=this.$content;x.empty(),x.append(l),x.append(f),x.append(M);var E=this.getSelectedVideoNode(n);if(null==E)return x[0];var V=E.src,I=void 0===V?"":V,N=E.poster,P=void 0===N?"":N;return y.val(I),w.val(P),setTimeout(function(){y.focus()}),x[0]},n}();function I(t,n){return p(this,arguments,void 0,function(t,n,r,i,a){var d,u,c,l,s,v,f;return void 0===r&&(r=""),void 0===i&&(i=""),void 0===a&&(a=""),g(this,function(h){switch(h.label){case 0:return n?(t.restoreSelection(),d=t.getMenuConfig("insertVideo"),u=d.onInsertedVideo,c=d.checkVideo,l=d.parseVideoSrc,[4,c(n,r)]):[2];case 1:return"string"==typeof(s=h.sent())?(t.alert(s,"error"),[2]):null==s?[2]:[4,l(n)];case 2:return 0!==(v=h.sent()).trim().indexOf("<iframe ")&&(v=v.replace(/</g,"<").replace(/>/g,">")),f={type:"video",src:v,poster:r,align:"center",children:[{text:""}],style:{width:i,height:a}},Promise.resolve().then(function(){e.DomEditor.isSelectedEmptyParagraph(t)&&o.Transforms.removeNodes(t,{mode:"highest"}),o.Transforms.insertNodes(t,f,{mode:"highest"})}),u(f),[2]}})})}function N(){return b("w-e-insert-video")}var P=function(){function n(){this.title=e.t("videoModule.insertVideo"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M981.184 160.096C837.568 139.456 678.848 128 512 128S186.432 139.456 42.816 160.096C15.296 267.808 0 386.848 0 512s15.264 244.16 42.816 351.904C186.464 884.544 345.152 896 512 896s325.568-11.456 469.184-32.096C1008.704 756.192 1024 637.152 1024 512s-15.264-244.16-42.816-351.904zM384 704V320l320 192-320 192z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=320,this.$content=null,this.srcInputId=N(),this.posterInputId=N(),this.buttonId=N()}return n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,t){},n.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!o.Range.isCollapsed(n)||!!e.DomEditor.getSelectedElems(t).some(function(o){return"pre"===e.DomEditor.getNodeType(o)||!!t.isVoid(o)}))},n.prototype.getModalPositionNode=function(e){return null},n.prototype.getModalContentElem=function(o){var n=this,r=this,i=r.srcInputId,a=r.posterInputId,d=r.buttonId,u=m(e.genModalInputElems(e.t("videoModule.videoSrc"),i,e.t("videoModule.videoSrcPlaceHolder")),2),c=u[0],l=u[1],s=m(e.genModalInputElems(e.t("videoModule.videoPoster"),a,e.t("videoModule.videoPosterPlaceHolder")),2),v=s[0],f=s[1],h=t(l),y=t(f),w=m(e.genModalButtonElems(d,e.t("videoModule.ok")),1)[0];if(null==this.$content){var b=t("<div></div>");b.on("click","#".concat(d),function(e){return p(n,void 0,void 0,function(){var t,n;return g(this,function(r){switch(r.label){case 0:return e.preventDefault(),t=b.find("#".concat(i)).val().trim(),n=b.find("#".concat(a)).val().trim(),[4,I(o,t,n)];case 1:return r.sent(),o.hidePanelOrModal(),[2]}})})}),this.$content=b}var M=this.$content;return M.empty(),M.append(c),M.append(v),M.append(w),h.val(""),y.val(""),setTimeout(function(){h.focus()}),M[0]},n}();function k(e){return e.getMenuConfig("uploadVideo")}var z=new WeakMap;function H(e,t){return p(this,void 0,void 0,function(){var o,n;return g(this,function(i){switch(i.label){case 0:return o=function(e){var t=z.get(e);if(null!=t)return t;var o=k(e),n=o.onSuccess,i=o.onProgress,a=o.onFailed,d=o.customInsert,u=o.onError;return t=r.createUploader(h(h({},o),{onProgress:function(t){e.showProgressBar(t),i&&i(t)},onSuccess:function(t,o){if(d)return d(o,function(t,o){return I(e,t,o)}),void n(t,o);var r=o.errno,i=void 0===r?1:r,u=o.data,c=void 0===u?{}:u;if(0===i){var l=c.url,s=void 0===l?"":l,v=c.poster;I(e,s,void 0===v?"":v),n(t,o)}else a(t,o)},onError:function(e,t,o){u(e,t,o)}}),e),z.set(e,t),t}(e),n=t.map(function(e){return{name:e.name,type:e.type,size:e.size,data:e}}),o.addFiles(n),[4,o.upload()];case 1:return i.sent(),[2]}})})}var T=function(){function n(){this.title=e.t("videoModule.uploadVideo"),this.iconSvg='<svg viewBox="0 0 1056 1024"><path d="M805.902261 521.819882a251.441452 251.441452 0 0 0-251.011972 246.600033 251.051015 251.051015 0 1 0 502.023944 8.823877 253.237463 253.237463 0 0 0-251.011972-255.42391z m59.463561 240.001647v129.898403h-116.701631v-129.898403h-44.041298l101.279368-103.504859 101.279368 103.504859z" p-id="6802"></path><path d="M788.254507 0.000781H99.094092A98.663439 98.663439 0 0 0 0.001171 99.093701v590.067495a98.663439 98.663439 0 0 0 99.092921 99.092921h411.7549a266.434235 266.434235 0 0 1-2.186448-41.815807 275.843767 275.843767 0 0 1 275.180024-270.729042 270.650955 270.650955 0 0 1 103.504859 19.834201V99.093701A101.51363 101.51363 0 0 0 788.254507 0.000781zM295.054441 640.747004V147.507894l394.146189 246.600033z"></path></svg>',this.tag="button"}return n.prototype.getValue=function(e){return""},n.prototype.isActive=function(e){return!1},n.prototype.exec=function(e,o){var n=this.getMenuConfig(e),r=n.allowedFileTypes,i=void 0===r?[]:r,a=n.customBrowseAndUpload;if(a)a(function(t,o){return I(e,t,o)});else{var d="";i.length>0&&(d='accept="'.concat(i.join(", "),'"'));var u=t("body"),c=t('<input type="file" '.concat(d," multiple/>"));c.hide(),u.append(c),c.click(),c.on("change",function(){var t=c[0].files;!function(e,t){p(this,void 0,void 0,function(){var o,n,r,i,a,d,u,c,l,s,v,f;return g(this,function(h){switch(h.label){case 0:if(null==t)return[2];o=Array.prototype.slice.call(t),n=[],r=k(e).customUpload,h.label=1;case 1:h.trys.push([1,8,9,14]),i=!0,a=w(o),h.label=2;case 2:return[4,a.next()];case 3:return d=h.sent(),(l=d.done)?[3,7]:(f=d.value,i=!1,u=f,r?[4,r(u,function(t,o){return I(e,t,o)},e)]:[3,5]);case 4:return h.sent(),[3,6];case 5:n.push(u),h.label=6;case 6:return i=!0,[3,2];case 7:return[3,14];case 8:return c=h.sent(),s={error:c},[3,14];case 9:return h.trys.push([9,,12,13]),i||l||!(v=a.return)?[3,11]:[4,v.call(a)];case 10:h.sent(),h.label=11;case 11:return[3,13];case 12:if(s)throw s.error;return[7];case 13:return[7];case 14:return n.length>0?[4,H(e,n)]:[3,16];case 15:h.sent(),h.label=16;case 16:return[2]}})})}(e,t)})}},n.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!o.Range.isCollapsed(n)||!!e.DomEditor.getSelectedElems(t).some(function(o){return"pre"===e.DomEditor.getNodeType(o)||!!t.isVoid(o)}))},n.prototype.getMenuConfig=function(e){return e.getMenuConfig("uploadVideo")},n}(),C=function(){function t(t,o,n){this.align=t,this.iconSvg=n,this.tag="button",this.title=e.t(o)}return t.prototype.getSelectedVideo=function(t){return e.DomEditor.getSelectedNodeByType(t,"video")},t.prototype.getValue=function(e){var t=this.getSelectedVideo(e);return!!t&&s(t)},t.prototype.isActive=function(e){return this.getValue(e)===this.align},t.prototype.isDisabled=function(e){return null==e.selection||null==this.getSelectedVideo(e)},t.prototype.exec=function(t,n){if(!this.isDisabled(t)){var r={align:this.align};o.Transforms.setNodes(t,r,{match:function(t){return e.DomEditor.checkNodeType(t,"video")}})}},t}();function D(e,t,o,n,r,i){return void 0===t&&(t=""),void 0===o&&(o="auto"),void 0===n&&(n="auto"),void 0===r&&(r={}),void 0===i&&(i="center"),{type:"video",src:e,poster:t,width:o,height:n,style:r,children:[{text:""}],align:i}}function A(e){var t=(e.attr("data-w-e-align")||"").trim();if(t)return l(t);var o=M(e.attr("style")||""),n=o["justify-content"];if("flex-start"===n)return"left";if("flex-end"===n)return"right";if("center"===n)return"center";var r=function(e){for(var t=(e.attr("class")||"").trim().split(/\s+/).filter(Boolean),o=0;o<t.length;o+=1){var n=t[o];if(n.startsWith("w-e-video-align-"))return n.replace("w-e-video-align-","")}return""}(e);if(r)return l(r);var i=o["text-align"],a=(e.attr("data-w-e-text-align")||"").trim();return l(i||a)}function B(e){var t=M(e),o={};return t.width&&(o.width=t.width),t.height&&(o.height=t.height),o}return{renderElems:[{type:"video",renderElem:function(t,o,n){var r,a=t,u=a.src,c=void 0===u?"":u,l=a.poster,f=void 0===l?"":l,h=a.key,p=void 0===h?"":h,g=a.width,y=void 0===g?"auto":g,m=a.height,w=void 0===m?"auto":m,b=a.style,M=void 0===b?{}:b,S=s(t),x=["w-e-video","w-e-textarea-video-container",v(S)].join(" "),E=e.DomEditor.isNodeSelected(n,t);if(0===c.trim().indexOf("<iframe ")){var V=d(c,y,w,M);r=i.jsx("figure",{className:x,"data-selected":E?"true":"","data-w-e-align":S,innerHTML:V})}else{var I=i.jsx("video",{key:p,poster:f,controls:!0,style:M},i.jsx("source",{src:c,type:"video/mp4"}),"Sorry, your browser doesn't support embedded videos.\n 抱歉,浏览器不支持 video 视频");"auto"!==y&&(I.data.width=y),"auto"!==w&&(I.data.height=w),r=i.jsx("figure",{className:x,"data-selected":E?"true":"","data-w-e-align":S},I)}return i.h("div",{props:{contentEditable:!1},on:{mousedown:function(e){return e.preventDefault()}}},r)}}],elemsToHtml:[f],preParseHtml:[{selector:"iframe,video,p",preParseHtml:function(e){var o=t(e),n=o;if("p"===a(o)){var r=o.children();if(1===r.length){var i=r[0],d=i.tagName.toLowerCase();["iframe","video"].includes(d)&&(n=t(i))}}var u=a(n);if("iframe"!==u&&"video"!==u)return n[0];if("video"===n.parent().attr("data-w-e-type"))return n[0];var c=t('<figure data-w-e-type="video" data-w-e-is-void data-w-e-align="center" class="w-e-video w-e-video-align-center"></figure>');return c.append(n),c[0]}}],parseElemsHtml:[{selector:'figure[data-w-e-type="video"],div[data-w-e-type="video"]',parseElemHtml:function(e,o,n){var r=t(e),i="",a="",d="auto",u="auto",c={},l=r.find("iframe");if(l.length>0){d=l.attr("width")||"auto",u=l.attr("height")||"auto",c=B(l.attr("style")||"");var s=l.attr("data-w-e-style-width")||"",v=l.attr("data-w-e-style-height")||"";return!c.width&&s&&(c.width=s),!c.height&&v&&(c.height=v),D(i=l[0].outerHTML,a,d,u,c,A(r))}var f=r.find("video");(i=f.attr("src")||"")||f.length>0&&(i=f.find("source").attr("src")||""),d=f.attr("width")||"auto",u=f.attr("height")||"auto",a=f.attr("poster")||"",c=B(f.attr("style")||"");var h=f.attr("data-w-e-style-width")||"",p=f.attr("data-w-e-style-height")||"";return!c.width&&h&&(c.width=h),!c.height&&p&&(c.height=p),D(i,a,d,u,c,A(r))}}],menus:[{key:"insertVideo",factory:function(){return new P},config:{onInsertedVideo:function(e){},checkVideo:function(e,t){return!0},parseVideoSrc:function(e){return e}}},{key:"uploadVideo",factory:function(){return new T},config:{server:"",fieldName:"wangeditor-uploaded-video",maxFileSize:10485760,maxNumberOfFiles:5,allowedFileTypes:["video/*"],meta:{},metaWithUrl:!1,withCredentials:!1,timeout:3e4,onBeforeUpload:function(e){return e},onProgress:function(e){},onSuccess:function(e,t){},onFailed:function(e,t){console.error("'".concat(e.name,"' upload failed"),t)},onError:function(e,t,o){console.error("'".concat(e.name," upload error"),t,o)}}},{key:"editVideoSize",factory:function(){return new x}},{key:"editVideoSrc",factory:function(){return new V}},{key:"videoAlignLeft",factory:function(){return new C("left","videoModule.alignLeft",'<svg viewBox="0 0 1024 1024"><path d="M768 793.6v102.4H51.2v-102.4h716.8z m204.8-230.4v102.4H51.2v-102.4h921.6z m-204.8-230.4v102.4H51.2v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}},{key:"videoAlignCenter",factory:function(){return new C("center","videoModule.alignCenter",'<svg viewBox="0 0 1024 1024"><path d="M870.4 793.6v102.4H153.6v-102.4h716.8z m102.4-230.4v102.4H51.2v-102.4h921.6z m-102.4-230.4v102.4H153.6v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}},{key:"videoAlignRight",factory:function(){return new C("right","videoModule.alignRight",'<svg viewBox="0 0 1024 1024"><path d="M972.8 793.6v102.4H256v-102.4h716.8z m0-230.4v102.4H51.2v-102.4h921.6z m0-230.4v102.4H256v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>')}}],editorPlugin:function(t){var n=t.isVoid,r=t.normalizeNode,i=t;return i.isVoid=function(e){return"video"===e.type||n(e)},i.normalizeNode=function(t){var n=m(t,2),a=n[0],d=n[1];"video"===e.DomEditor.getNodeType(a)&&(e.DomEditor.isLastNode(i,a)&&o.Transforms.insertNodes(i,e.DomEditor.genEmptyParagraph(),{at:[d[0]+1]}));return r([a,d])},i}}});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|