@ctzhian/tiptap 2.0.0 → 2.1.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/Editor/demo.js +133 -123
- package/dist/EditorToolbar/index.js +11 -9
- package/dist/asset/css/index.css +5 -7
- package/dist/component/ActionDropdown/index.d.ts +5 -0
- package/dist/component/ActionDropdown/index.js +8 -3
- package/dist/component/FloatingPopover/index.d.ts +2 -2
- package/dist/component/HoverPopover/index.d.ts +2 -0
- package/dist/component/HoverPopover/index.js +22 -3
- package/dist/component/Icons/{expand-horizontal-line.js → expand-horizontal-line-icon.js} +1 -1
- package/dist/component/Icons/index.d.ts +3 -2
- package/dist/component/Icons/index.js +4 -3
- package/dist/extension/component/Alert/index.js +141 -137
- package/dist/extension/component/Flow/Edit.d.ts +1 -1
- package/dist/extension/component/Flow/Edit.js +3 -31
- package/dist/extension/component/Flow/index.js +20 -19
- package/dist/extension/component/Image/index.d.ts +1 -0
- package/dist/extension/component/Image/index.js +16 -2
- package/dist/extension/component/Link/index.js +1 -1
- package/dist/extension/component/TableCellHandleMenu/index.js +60 -3
- package/dist/extension/component/TableHandle/TableHandleMenu.js +1 -1
- package/dist/extension/component/TableSelectionOverlay/index.js +4 -12
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/component/Video/Insert.js +4 -2
- package/dist/extension/component/Video/Readonly.js +4 -11
- package/dist/extension/component/Video/index.d.ts +2 -1
- package/dist/extension/component/Video/index.js +447 -65
- package/dist/extension/extension/ImeComposition.d.ts +2 -0
- package/dist/extension/extension/ImeComposition.js +145 -0
- package/dist/extension/extension/index.d.ts +1 -0
- package/dist/extension/extension/index.js +1 -0
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/Flow/index.d.ts +0 -3
- package/dist/extension/node/Flow/index.js +7 -4
- package/dist/extension/node/Link/index.js +4 -3
- package/dist/extension/node/Table.js +18 -82
- package/dist/extension/node/TableOfContents/index.d.ts +5 -3
- package/dist/extension/node/TableOfContents/index.js +22 -2
- package/dist/extension/node/Video.d.ts +1 -0
- package/dist/extension/node/Video.js +38 -6
- package/dist/hook/index.js +1 -1
- package/dist/index.css +16 -19
- package/dist/util/index.d.ts +9 -0
- package/dist/util/index.js +26 -0
- package/package.json +1 -1
- /package/dist/component/Icons/{expand-horizontal-line.d.ts → expand-horizontal-line-icon.d.ts} +0 -0
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
1
10
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
14
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
16
|
+
import { ActionDropdown, FloatingPopover, HoverPopover } from "../../../component";
|
|
17
|
+
import { AlignCenterIcon, AlignLeftIcon, AlignRightIcon, DeleteLineIcon, DownloadLineIcon, EditLineIcon } from "../../../component/Icons";
|
|
18
|
+
import { ToolbarItem } from "../../../component/Toolbar";
|
|
19
|
+
import { alpha, Box, Button, Divider, Stack, TextField, useTheme } from "@mui/material";
|
|
9
20
|
import { NodeViewWrapper } from '@tiptap/react';
|
|
10
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
21
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
11
22
|
import InsertVideo from "./Insert";
|
|
12
23
|
import ReadonlyVideo from "./Readonly";
|
|
13
24
|
var VideoViewWrapper = function VideoViewWrapper(_ref) {
|
|
@@ -21,6 +32,9 @@ var VideoViewWrapper = function VideoViewWrapper(_ref) {
|
|
|
21
32
|
onValidateUrl = _ref.onValidateUrl;
|
|
22
33
|
var attrs = node.attrs;
|
|
23
34
|
var videoRef = useRef(null);
|
|
35
|
+
var videoContentRef = useRef(null);
|
|
36
|
+
var editButtonRef = useRef(null);
|
|
37
|
+
var theme = useTheme();
|
|
24
38
|
var _useState = useState(false),
|
|
25
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
26
40
|
isDragging = _useState2[0],
|
|
@@ -29,31 +43,125 @@ var VideoViewWrapper = function VideoViewWrapper(_ref) {
|
|
|
29
43
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
44
|
isHovering = _useState4[0],
|
|
31
45
|
setIsHovering = _useState4[1];
|
|
32
|
-
var _useState5 = useState(
|
|
46
|
+
var _useState5 = useState(null),
|
|
33
47
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var
|
|
48
|
+
dragCorner = _useState6[0],
|
|
49
|
+
setDragCorner = _useState6[1];
|
|
50
|
+
var dragStartXRef = useRef(0);
|
|
51
|
+
var dragStartWidthRef = useRef(0);
|
|
52
|
+
var maxWidthRef = useRef(0);
|
|
53
|
+
var _useState7 = useState(attrs.src),
|
|
37
54
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var
|
|
55
|
+
editSrc = _useState8[0],
|
|
56
|
+
setEditSrc = _useState8[1];
|
|
57
|
+
var _useState9 = useState(null),
|
|
58
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
59
|
+
anchorEl = _useState10[0],
|
|
60
|
+
setAnchorEl = _useState10[1];
|
|
61
|
+
var _useState11 = useState(false),
|
|
62
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
63
|
+
keepHoverPopoverOpen = _useState12[0],
|
|
64
|
+
setKeepHoverPopoverOpen = _useState12[1];
|
|
65
|
+
var handleShowPopover = function handleShowPopover() {
|
|
66
|
+
setKeepHoverPopoverOpen(true);
|
|
67
|
+
setAnchorEl(editButtonRef.current);
|
|
68
|
+
};
|
|
69
|
+
var handleClosePopover = function handleClosePopover() {
|
|
70
|
+
setAnchorEl(null);
|
|
71
|
+
setKeepHoverPopoverOpen(false);
|
|
72
|
+
};
|
|
73
|
+
var isPercentWidth = function isPercentWidth() {
|
|
74
|
+
if (!attrs.width) return true;
|
|
75
|
+
if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
};
|
|
80
|
+
var getCurrentWidthPercent = function getCurrentWidthPercent() {
|
|
81
|
+
if (isPercentWidth()) {
|
|
82
|
+
if (!attrs.width) return '100';
|
|
83
|
+
if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
|
|
84
|
+
return attrs.width.replace('%', '');
|
|
85
|
+
}
|
|
86
|
+
return '100';
|
|
87
|
+
}
|
|
88
|
+
return 'pixel';
|
|
89
|
+
};
|
|
90
|
+
var getCurrentDisplayWidth = function getCurrentDisplayWidth() {
|
|
91
|
+
if (!videoRef.current) {
|
|
92
|
+
return getEditorWidth();
|
|
93
|
+
}
|
|
94
|
+
var computedStyle = window.getComputedStyle(videoRef.current);
|
|
95
|
+
var displayWidth = videoRef.current.offsetWidth;
|
|
96
|
+
if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
|
|
97
|
+
return displayWidth;
|
|
98
|
+
}
|
|
99
|
+
if (typeof attrs.width === 'number') {
|
|
100
|
+
if (computedStyle.maxWidth === '100%' && displayWidth < attrs.width) {
|
|
101
|
+
return displayWidth;
|
|
102
|
+
}
|
|
103
|
+
return attrs.width;
|
|
104
|
+
}
|
|
105
|
+
return getEditorWidth();
|
|
106
|
+
};
|
|
107
|
+
var getEditorWidth = function getEditorWidth() {
|
|
108
|
+
var _editor$view;
|
|
109
|
+
if (videoContentRef.current) {
|
|
110
|
+
var current = videoContentRef.current;
|
|
111
|
+
while (current) {
|
|
112
|
+
var _current$classList;
|
|
113
|
+
if ((_current$classList = current.classList) !== null && _current$classList !== void 0 && _current$classList.contains('node-video')) {
|
|
114
|
+
var style = window.getComputedStyle(current);
|
|
115
|
+
var paddingLeft = parseFloat(style.paddingLeft) || 0;
|
|
116
|
+
var paddingRight = parseFloat(style.paddingRight) || 0;
|
|
117
|
+
return current.clientWidth - paddingLeft - paddingRight;
|
|
118
|
+
}
|
|
119
|
+
current = current.parentElement;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (editor !== null && editor !== void 0 && (_editor$view = editor.view) !== null && _editor$view !== void 0 && _editor$view.dom) {
|
|
123
|
+
var editorElement = editor.view.dom;
|
|
124
|
+
var _style = window.getComputedStyle(editorElement);
|
|
125
|
+
var _paddingLeft = parseFloat(_style.paddingLeft) || 0;
|
|
126
|
+
var _paddingRight = parseFloat(_style.paddingRight) || 0;
|
|
127
|
+
var editorWidth = editorElement.clientWidth - _paddingLeft - _paddingRight;
|
|
128
|
+
if (editorWidth > 0) {
|
|
129
|
+
return editorWidth;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return 800;
|
|
133
|
+
};
|
|
134
|
+
var handleMouseDown = function handleMouseDown(e, corner) {
|
|
41
135
|
e.preventDefault();
|
|
136
|
+
e.stopPropagation();
|
|
42
137
|
setIsDragging(true);
|
|
43
|
-
|
|
44
|
-
|
|
138
|
+
setDragCorner(corner);
|
|
139
|
+
dragStartXRef.current = e.clientX;
|
|
140
|
+
var width = getCurrentDisplayWidth();
|
|
141
|
+
dragStartWidthRef.current = width;
|
|
142
|
+
maxWidthRef.current = getEditorWidth();
|
|
45
143
|
};
|
|
46
|
-
var handleMouseMove = function
|
|
47
|
-
if (!isDragging) return;
|
|
48
|
-
var deltaX = e.clientX -
|
|
49
|
-
var newWidth
|
|
144
|
+
var handleMouseMove = useCallback(function (e) {
|
|
145
|
+
if (!isDragging || !dragCorner) return;
|
|
146
|
+
var deltaX = e.clientX - dragStartXRef.current;
|
|
147
|
+
var newWidth;
|
|
148
|
+
if (dragCorner === 'top-right' || dragCorner === 'bottom-right') {
|
|
149
|
+
newWidth = dragStartWidthRef.current + deltaX;
|
|
150
|
+
} else {
|
|
151
|
+
newWidth = dragStartWidthRef.current - deltaX;
|
|
152
|
+
}
|
|
153
|
+
newWidth = Math.max(200, Math.min(maxWidthRef.current, newWidth));
|
|
50
154
|
updateAttributes({
|
|
51
155
|
width: newWidth
|
|
52
156
|
});
|
|
53
|
-
};
|
|
54
|
-
var handleMouseUp = function
|
|
157
|
+
}, [isDragging, dragCorner, updateAttributes]);
|
|
158
|
+
var handleMouseUp = useCallback(function () {
|
|
55
159
|
setIsDragging(false);
|
|
56
|
-
|
|
160
|
+
setDragCorner(null);
|
|
161
|
+
}, []);
|
|
162
|
+
useEffect(function () {
|
|
163
|
+
setEditSrc(attrs.src);
|
|
164
|
+
}, [attrs.src]);
|
|
57
165
|
useEffect(function () {
|
|
58
166
|
if (isDragging) {
|
|
59
167
|
document.addEventListener('mousemove', handleMouseMove);
|
|
@@ -63,7 +171,57 @@ var VideoViewWrapper = function VideoViewWrapper(_ref) {
|
|
|
63
171
|
document.removeEventListener('mouseup', handleMouseUp);
|
|
64
172
|
};
|
|
65
173
|
}
|
|
66
|
-
}, [isDragging]);
|
|
174
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
175
|
+
var handleSave = /*#__PURE__*/function () {
|
|
176
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
177
|
+
var validatedUrl;
|
|
178
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
179
|
+
while (1) switch (_context.prev = _context.next) {
|
|
180
|
+
case 0:
|
|
181
|
+
if (!editSrc.trim()) {
|
|
182
|
+
_context.next = 14;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
_context.prev = 1;
|
|
186
|
+
validatedUrl = editSrc.trim();
|
|
187
|
+
if (!onValidateUrl) {
|
|
188
|
+
_context.next = 7;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
_context.next = 6;
|
|
192
|
+
return Promise.resolve(onValidateUrl(validatedUrl, 'video'));
|
|
193
|
+
case 6:
|
|
194
|
+
validatedUrl = _context.sent;
|
|
195
|
+
case 7:
|
|
196
|
+
updateAttributes({
|
|
197
|
+
src: validatedUrl,
|
|
198
|
+
width: attrs.width,
|
|
199
|
+
controls: attrs.controls,
|
|
200
|
+
autoplay: attrs.autoplay,
|
|
201
|
+
loop: attrs.loop,
|
|
202
|
+
muted: attrs.muted,
|
|
203
|
+
poster: attrs.poster,
|
|
204
|
+
align: attrs.align
|
|
205
|
+
});
|
|
206
|
+
setEditSrc(validatedUrl);
|
|
207
|
+
_context.next = 14;
|
|
208
|
+
break;
|
|
209
|
+
case 11:
|
|
210
|
+
_context.prev = 11;
|
|
211
|
+
_context.t0 = _context["catch"](1);
|
|
212
|
+
_onError === null || _onError === void 0 || _onError(_context.t0);
|
|
213
|
+
case 14:
|
|
214
|
+
handleClosePopover();
|
|
215
|
+
case 15:
|
|
216
|
+
case "end":
|
|
217
|
+
return _context.stop();
|
|
218
|
+
}
|
|
219
|
+
}, _callee, null, [[1, 11]]);
|
|
220
|
+
}));
|
|
221
|
+
return function handleSave() {
|
|
222
|
+
return _ref2.apply(this, arguments);
|
|
223
|
+
};
|
|
224
|
+
}();
|
|
67
225
|
if (!attrs.src && !editor.isEditable) {
|
|
68
226
|
return null;
|
|
69
227
|
}
|
|
@@ -87,81 +245,305 @@ var VideoViewWrapper = function VideoViewWrapper(_ref) {
|
|
|
87
245
|
className: "video-wrapper ".concat(selected ? 'ProseMirror-selectednode' : '')
|
|
88
246
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
89
247
|
sx: {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
248
|
+
backgroundColor: 'transparent !important',
|
|
249
|
+
textAlign: attrs.align || undefined
|
|
250
|
+
}
|
|
251
|
+
}, /*#__PURE__*/React.createElement(HoverPopover, {
|
|
252
|
+
keepOpen: keepHoverPopoverOpen,
|
|
253
|
+
placement: "top",
|
|
254
|
+
offset: 4,
|
|
255
|
+
actions: /*#__PURE__*/React.createElement(Stack, {
|
|
256
|
+
direction: 'row',
|
|
257
|
+
alignItems: 'center',
|
|
258
|
+
sx: {
|
|
259
|
+
p: 0.5
|
|
99
260
|
}
|
|
100
|
-
},
|
|
261
|
+
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
262
|
+
ref: editButtonRef,
|
|
263
|
+
icon: /*#__PURE__*/React.createElement(EditLineIcon, {
|
|
264
|
+
sx: {
|
|
265
|
+
fontSize: '1rem'
|
|
266
|
+
}
|
|
267
|
+
}),
|
|
268
|
+
tip: "\u66F4\u6362\u89C6\u9891\u94FE\u63A5",
|
|
269
|
+
onClick: handleShowPopover
|
|
270
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
271
|
+
icon: /*#__PURE__*/React.createElement(DownloadLineIcon, {
|
|
272
|
+
sx: {
|
|
273
|
+
fontSize: '1rem'
|
|
274
|
+
}
|
|
275
|
+
}),
|
|
276
|
+
tip: "\u4E0B\u8F7D\u89C6\u9891",
|
|
277
|
+
onClick: function onClick() {
|
|
278
|
+
var video = document.createElement('a');
|
|
279
|
+
video.href = attrs.src;
|
|
280
|
+
video.target = '_blank';
|
|
281
|
+
video.download = attrs.src.split('/').pop() || 'video.mp4';
|
|
282
|
+
document.body.appendChild(video);
|
|
283
|
+
video.click();
|
|
284
|
+
document.body.removeChild(video);
|
|
285
|
+
}
|
|
286
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
287
|
+
icon: /*#__PURE__*/React.createElement(AlignLeftIcon, {
|
|
288
|
+
sx: {
|
|
289
|
+
fontSize: '1rem'
|
|
290
|
+
}
|
|
291
|
+
}),
|
|
292
|
+
tip: "\u5DE6\u4FA7\u5BF9\u9F50",
|
|
293
|
+
className: attrs.align === 'left' ? 'tool-active' : '',
|
|
294
|
+
onClick: function onClick() {
|
|
295
|
+
return updateAttributes({
|
|
296
|
+
align: attrs.align === 'left' ? null : 'left'
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
300
|
+
icon: /*#__PURE__*/React.createElement(AlignCenterIcon, {
|
|
301
|
+
sx: {
|
|
302
|
+
fontSize: '1rem'
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
tip: "\u5C45\u4E2D\u5BF9\u9F50",
|
|
306
|
+
className: attrs.align === 'center' ? 'tool-active' : '',
|
|
307
|
+
onClick: function onClick() {
|
|
308
|
+
return updateAttributes({
|
|
309
|
+
align: attrs.align === 'center' ? null : 'center'
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
313
|
+
icon: /*#__PURE__*/React.createElement(AlignRightIcon, {
|
|
314
|
+
sx: {
|
|
315
|
+
fontSize: '1rem'
|
|
316
|
+
}
|
|
317
|
+
}),
|
|
318
|
+
tip: "\u53F3\u4FA7\u5BF9\u9F50",
|
|
319
|
+
className: attrs.align === 'right' ? 'tool-active' : '',
|
|
320
|
+
onClick: function onClick() {
|
|
321
|
+
return updateAttributes({
|
|
322
|
+
align: attrs.align === 'right' ? null : 'right'
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}), /*#__PURE__*/React.createElement(Divider, {
|
|
326
|
+
orientation: "vertical",
|
|
327
|
+
flexItem: true,
|
|
328
|
+
sx: {
|
|
329
|
+
height: '1rem',
|
|
330
|
+
mx: 0.5,
|
|
331
|
+
alignSelf: 'center',
|
|
332
|
+
borderColor: 'divider'
|
|
333
|
+
}
|
|
334
|
+
}), /*#__PURE__*/React.createElement(ActionDropdown, {
|
|
335
|
+
id: "video-width-dropdown",
|
|
336
|
+
selected: getCurrentWidthPercent(),
|
|
337
|
+
defaultDisplay: !isPercentWidth() ? {
|
|
338
|
+
label: '固定宽度'
|
|
339
|
+
} : undefined,
|
|
340
|
+
list: [{
|
|
341
|
+
key: '50',
|
|
342
|
+
label: '自适应宽度(50%)',
|
|
343
|
+
onClick: function onClick() {
|
|
344
|
+
return updateAttributes({
|
|
345
|
+
width: '50%'
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}, {
|
|
349
|
+
key: '75',
|
|
350
|
+
label: '自适应宽度(75%)',
|
|
351
|
+
onClick: function onClick() {
|
|
352
|
+
return updateAttributes({
|
|
353
|
+
width: '75%'
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}, {
|
|
357
|
+
key: '100',
|
|
358
|
+
label: '自适应宽度(100%)',
|
|
359
|
+
onClick: function onClick() {
|
|
360
|
+
return updateAttributes({
|
|
361
|
+
width: '100%'
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}]
|
|
365
|
+
}), /*#__PURE__*/React.createElement(Divider, {
|
|
366
|
+
orientation: "vertical",
|
|
367
|
+
flexItem: true,
|
|
368
|
+
sx: {
|
|
369
|
+
height: '1rem',
|
|
370
|
+
mx: 0.5,
|
|
371
|
+
alignSelf: 'center',
|
|
372
|
+
borderColor: 'divider'
|
|
373
|
+
}
|
|
374
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
375
|
+
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
376
|
+
sx: {
|
|
377
|
+
fontSize: '1rem'
|
|
378
|
+
}
|
|
379
|
+
}),
|
|
380
|
+
tip: "\u5220\u9664\u89C6\u9891",
|
|
381
|
+
onClick: deleteNode
|
|
382
|
+
})),
|
|
383
|
+
style: _objectSpread({
|
|
384
|
+
display: 'inline-block'
|
|
385
|
+
}, typeof attrs.width === 'string' && attrs.width.endsWith('%') ? {
|
|
386
|
+
width: attrs.width
|
|
387
|
+
} : {})
|
|
388
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
389
|
+
ref: videoContentRef,
|
|
101
390
|
onMouseEnter: function onMouseEnter() {
|
|
102
391
|
return setIsHovering(true);
|
|
103
392
|
},
|
|
104
393
|
onMouseLeave: function onMouseLeave() {
|
|
105
394
|
return setIsHovering(false);
|
|
395
|
+
},
|
|
396
|
+
sx: {
|
|
397
|
+
position: 'relative'
|
|
106
398
|
}
|
|
107
399
|
}, /*#__PURE__*/React.createElement("video", {
|
|
108
400
|
ref: videoRef,
|
|
109
401
|
src: attrs.src,
|
|
110
|
-
width: attrs.width,
|
|
111
|
-
poster: attrs.poster || undefined,
|
|
112
|
-
controls: attrs.controls,
|
|
113
|
-
autoPlay: attrs.autoplay,
|
|
114
|
-
loop: attrs.loop,
|
|
115
|
-
muted: attrs.muted,
|
|
402
|
+
width: typeof attrs.width === 'number' ? attrs.width : undefined,
|
|
116
403
|
style: {
|
|
404
|
+
width: typeof attrs.width === 'string' && attrs.width.endsWith('%') ? '100%' : undefined,
|
|
117
405
|
maxWidth: '100%',
|
|
118
406
|
height: 'auto',
|
|
407
|
+
cursor: isDragging ? 'default' : 'pointer',
|
|
408
|
+
border: '2px solid',
|
|
409
|
+
borderColor: isHovering || isDragging ? alpha(theme.palette.primary.main, 0.3) : 'transparent',
|
|
119
410
|
display: 'block'
|
|
120
411
|
},
|
|
412
|
+
poster: attrs.poster || undefined,
|
|
413
|
+
controls: attrs.controls,
|
|
414
|
+
autoPlay: attrs.autoplay,
|
|
415
|
+
loop: attrs.loop,
|
|
416
|
+
muted: attrs.muted,
|
|
121
417
|
onError: function onError(e) {
|
|
122
418
|
_onError === null || _onError === void 0 || _onError(e);
|
|
123
419
|
}
|
|
124
|
-
}), (isHovering || isDragging) && /*#__PURE__*/React.createElement(Box, {
|
|
125
|
-
onMouseDown:
|
|
420
|
+
}), (isHovering || isDragging) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
421
|
+
onMouseDown: function onMouseDown(e) {
|
|
422
|
+
return handleMouseDown(e, 'top-left');
|
|
423
|
+
},
|
|
126
424
|
sx: {
|
|
127
425
|
position: 'absolute',
|
|
128
|
-
|
|
129
|
-
top:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
426
|
+
left: -4,
|
|
427
|
+
top: -4,
|
|
428
|
+
width: 12,
|
|
429
|
+
height: 12,
|
|
430
|
+
bgcolor: 'background.default',
|
|
431
|
+
cursor: 'nwse-resize',
|
|
432
|
+
borderRadius: '50%',
|
|
433
|
+
border: '2px solid',
|
|
434
|
+
borderColor: isDragging && dragCorner === 'top-left' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
|
|
136
435
|
'&:hover': {
|
|
137
|
-
|
|
436
|
+
borderColor: 'primary.main'
|
|
138
437
|
},
|
|
139
438
|
transition: 'background-color 0.2s ease',
|
|
140
439
|
zIndex: 10
|
|
141
440
|
}
|
|
142
|
-
}),
|
|
143
|
-
|
|
441
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
442
|
+
onMouseDown: function onMouseDown(e) {
|
|
443
|
+
return handleMouseDown(e, 'top-right');
|
|
444
|
+
},
|
|
144
445
|
sx: {
|
|
145
446
|
position: 'absolute',
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
447
|
+
right: -4,
|
|
448
|
+
top: -4,
|
|
449
|
+
width: 12,
|
|
450
|
+
height: 12,
|
|
451
|
+
bgcolor: 'background.default',
|
|
452
|
+
cursor: 'nesw-resize',
|
|
453
|
+
borderRadius: '50%',
|
|
454
|
+
border: '2px solid',
|
|
455
|
+
borderColor: isDragging && dragCorner === 'top-right' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
|
|
456
|
+
'&:hover': {
|
|
457
|
+
borderColor: 'primary.main'
|
|
458
|
+
},
|
|
459
|
+
transition: 'background-color 0.2s ease',
|
|
460
|
+
zIndex: 10
|
|
461
|
+
}
|
|
462
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
463
|
+
onMouseDown: function onMouseDown(e) {
|
|
464
|
+
return handleMouseDown(e, 'bottom-left');
|
|
465
|
+
},
|
|
466
|
+
sx: {
|
|
467
|
+
position: 'absolute',
|
|
468
|
+
left: -4,
|
|
469
|
+
bottom: -2,
|
|
470
|
+
width: 12,
|
|
471
|
+
height: 12,
|
|
472
|
+
cursor: 'nesw-resize',
|
|
473
|
+
borderRadius: '50%',
|
|
474
|
+
border: '2px solid',
|
|
475
|
+
bgcolor: 'background.default',
|
|
476
|
+
borderColor: isDragging && dragCorner === 'bottom-left' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
|
|
477
|
+
'&:hover': {
|
|
478
|
+
borderColor: 'primary.main'
|
|
479
|
+
},
|
|
480
|
+
transition: 'background-color 0.2s ease',
|
|
481
|
+
zIndex: 10
|
|
482
|
+
}
|
|
483
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
484
|
+
onMouseDown: function onMouseDown(e) {
|
|
485
|
+
return handleMouseDown(e, 'bottom-right');
|
|
486
|
+
},
|
|
487
|
+
sx: {
|
|
488
|
+
position: 'absolute',
|
|
489
|
+
right: -4,
|
|
490
|
+
bottom: -2,
|
|
491
|
+
width: 12,
|
|
492
|
+
height: 12,
|
|
493
|
+
bgcolor: 'background.default',
|
|
494
|
+
cursor: 'nwse-resize',
|
|
495
|
+
borderRadius: '50%',
|
|
496
|
+
border: '2px solid',
|
|
497
|
+
borderColor: isDragging && dragCorner === 'bottom-right' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
|
|
498
|
+
'&:hover': {
|
|
499
|
+
borderColor: 'primary.main'
|
|
500
|
+
},
|
|
501
|
+
transition: 'background-color 0.2s ease',
|
|
502
|
+
zIndex: 10
|
|
503
|
+
}
|
|
504
|
+
}))))), /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
505
|
+
open: Boolean(anchorEl),
|
|
506
|
+
anchorEl: anchorEl,
|
|
507
|
+
onClose: handleClosePopover,
|
|
508
|
+
placement: "bottom"
|
|
509
|
+
}, /*#__PURE__*/React.createElement(Stack, {
|
|
157
510
|
sx: {
|
|
158
|
-
|
|
159
|
-
|
|
511
|
+
p: 2,
|
|
512
|
+
width: 350
|
|
160
513
|
}
|
|
161
|
-
}, /*#__PURE__*/React.createElement(
|
|
514
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
162
515
|
sx: {
|
|
163
|
-
fontSize:
|
|
516
|
+
fontSize: '0.75rem',
|
|
517
|
+
color: 'text.secondary',
|
|
518
|
+
lineHeight: '1.5',
|
|
519
|
+
mb: 1
|
|
164
520
|
}
|
|
165
|
-
})
|
|
521
|
+
}, "\u89C6\u9891\u5730\u5740"), /*#__PURE__*/React.createElement(TextField, {
|
|
522
|
+
fullWidth: true,
|
|
523
|
+
size: "small",
|
|
524
|
+
value: editSrc,
|
|
525
|
+
onChange: function onChange(e) {
|
|
526
|
+
return setEditSrc(e.target.value);
|
|
527
|
+
},
|
|
528
|
+
placeholder: "\u8F93\u5165\u89C6\u9891\u7684 URL"
|
|
529
|
+
}), /*#__PURE__*/React.createElement(Stack, {
|
|
530
|
+
direction: 'row',
|
|
531
|
+
gap: 1,
|
|
532
|
+
alignItems: 'center',
|
|
533
|
+
sx: {
|
|
534
|
+
mt: 2
|
|
535
|
+
}
|
|
536
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
537
|
+
variant: "outlined",
|
|
538
|
+
size: "small",
|
|
539
|
+
fullWidth: true,
|
|
540
|
+
onClick: handleClosePopover
|
|
541
|
+
}, "\u53D6\u6D88"), /*#__PURE__*/React.createElement(Button, {
|
|
542
|
+
variant: "contained",
|
|
543
|
+
size: "small",
|
|
544
|
+
fullWidth: true,
|
|
545
|
+
onClick: handleSave,
|
|
546
|
+
disabled: !editSrc.trim()
|
|
547
|
+
}, "\u4FDD\u5B58")))));
|
|
166
548
|
};
|
|
167
549
|
export default VideoViewWrapper;
|