@ctzhian/tiptap 2.1.12 → 2.1.13

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.
@@ -1,4 +1,9 @@
1
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); }
2
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; }
3
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); } }
4
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); }); }; }
@@ -8,11 +13,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
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; }
9
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; } }
10
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { FloatingPopover } from "../../../component/FloatingPopover";
12
- import { DeleteLineIcon, EditBoxLineIcon } from "../../../component/Icons";
13
- import { Box, Button, IconButton, Stack, TextField, Tooltip } from "@mui/material";
16
+ import { ActionDropdown, FloatingPopover, HoverPopover } from "../../../component";
17
+ import { AlignCenterIcon, AlignLeftIcon, AlignRightIcon, DeleteLineIcon, EditLineIcon } from "../../../component/Icons";
18
+ import { ToolbarItem } from "../../../component/Toolbar";
19
+ import { extractSrcFromIframe } from "../../../util";
20
+ import { alpha, Box, Button, Divider, Stack, TextField, useTheme } from "@mui/material";
14
21
  import { NodeViewWrapper } from '@tiptap/react';
15
- import React, { useEffect, useState } from "react";
22
+ import React, { useCallback, useEffect, useRef, useState } from "react";
16
23
  import InsertIframe from "./Insert";
17
24
  import ReadonlyIframe from "./Readonly";
18
25
  var IframeViewWrapper = function IframeViewWrapper(_ref) {
@@ -23,48 +30,167 @@ var IframeViewWrapper = function IframeViewWrapper(_ref) {
23
30
  selected = _ref.selected,
24
31
  onValidateUrl = _ref.onValidateUrl;
25
32
  var attrs = node.attrs;
33
+ var iframeRef = useRef(null);
34
+ var iframeContentRef = useRef(null);
35
+ var editButtonRef = useRef(null);
36
+ var theme = useTheme();
26
37
  var _useState = useState(false),
27
38
  _useState2 = _slicedToArray(_useState, 2),
28
- isHovering = _useState2[0],
29
- setIsHovering = _useState2[1];
39
+ isDragging = _useState2[0],
40
+ setIsDragging = _useState2[1];
30
41
  var _useState3 = useState(false),
31
42
  _useState4 = _slicedToArray(_useState3, 2),
32
- isDraggingWidth = _useState4[0],
33
- setIsDraggingWidth = _useState4[1];
34
- var _useState5 = useState(false),
43
+ isHovering = _useState4[0],
44
+ setIsHovering = _useState4[1];
45
+ var _useState5 = useState(null),
35
46
  _useState6 = _slicedToArray(_useState5, 2),
36
- isDraggingHeight = _useState6[0],
37
- setIsDraggingHeight = _useState6[1];
38
- var _useState7 = useState(0),
47
+ dragCorner = _useState6[0],
48
+ setDragCorner = _useState6[1];
49
+ var dragStartXRef = useRef(0);
50
+ var dragStartYRef = useRef(0);
51
+ var dragStartWidthRef = useRef(0);
52
+ var dragStartHeightRef = useRef(0);
53
+ var maxWidthRef = useRef(0);
54
+ var _useState7 = useState(attrs.src),
39
55
  _useState8 = _slicedToArray(_useState7, 2),
40
- dragStartX = _useState8[0],
41
- setDragStartX = _useState8[1];
42
- var _useState9 = useState(0),
56
+ editSrc = _useState8[0],
57
+ setEditSrc = _useState8[1];
58
+ var _useState9 = useState(null),
43
59
  _useState10 = _slicedToArray(_useState9, 2),
44
- dragStartY = _useState10[0],
45
- setDragStartY = _useState10[1];
46
- var _useState11 = useState(0),
60
+ anchorEl = _useState10[0],
61
+ setAnchorEl = _useState10[1];
62
+ var _useState11 = useState(false),
47
63
  _useState12 = _slicedToArray(_useState11, 2),
48
- dragStartWidth = _useState12[0],
49
- setDragStartWidth = _useState12[1];
50
- var _useState13 = useState(0),
51
- _useState14 = _slicedToArray(_useState13, 2),
52
- dragStartHeight = _useState14[0],
53
- setDragStartHeight = _useState14[1];
54
- var _useState15 = useState(null),
55
- _useState16 = _slicedToArray(_useState15, 2),
56
- anchorEl = _useState16[0],
57
- setAnchorEl = _useState16[1];
58
- var _useState17 = useState(attrs.src),
59
- _useState18 = _slicedToArray(_useState17, 2),
60
- editSrc = _useState18[0],
61
- setEditSrc = _useState18[1];
62
- var handleShowPopover = function handleShowPopover(event) {
63
- return setAnchorEl(event.currentTarget);
64
+ keepHoverPopoverOpen = _useState12[0],
65
+ setKeepHoverPopoverOpen = _useState12[1];
66
+ var handleShowPopover = function handleShowPopover() {
67
+ setKeepHoverPopoverOpen(true);
68
+ setAnchorEl(editButtonRef.current);
64
69
  };
65
70
  var handleClosePopover = function handleClosePopover() {
66
- return setAnchorEl(null);
71
+ setAnchorEl(null);
72
+ setKeepHoverPopoverOpen(false);
67
73
  };
74
+ var isPercentWidth = function isPercentWidth() {
75
+ if (!attrs.width) return true;
76
+ if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
77
+ return true;
78
+ }
79
+ return false;
80
+ };
81
+ var getCurrentWidthPercent = function getCurrentWidthPercent() {
82
+ if (isPercentWidth()) {
83
+ if (!attrs.width) return '100';
84
+ if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
85
+ return attrs.width.replace('%', '');
86
+ }
87
+ return '100';
88
+ }
89
+ return 'pixel';
90
+ };
91
+ var getCurrentDisplayWidth = function getCurrentDisplayWidth() {
92
+ if (!iframeRef.current) {
93
+ return getEditorWidth();
94
+ }
95
+ var computedStyle = window.getComputedStyle(iframeRef.current);
96
+ var displayWidth = iframeRef.current.offsetWidth;
97
+ if (typeof attrs.width === 'string' && attrs.width.endsWith('%')) {
98
+ return displayWidth;
99
+ }
100
+ if (typeof attrs.width === 'number') {
101
+ if (computedStyle.maxWidth === '100%' && displayWidth < attrs.width) {
102
+ return displayWidth;
103
+ }
104
+ return attrs.width;
105
+ }
106
+ return getEditorWidth();
107
+ };
108
+ var getCurrentDisplayHeight = function getCurrentDisplayHeight() {
109
+ if (!iframeRef.current) {
110
+ return typeof attrs.height === 'number' ? attrs.height : 400;
111
+ }
112
+ return iframeRef.current.offsetHeight;
113
+ };
114
+ var getEditorWidth = function getEditorWidth() {
115
+ var _editor$view;
116
+ if (iframeContentRef.current) {
117
+ var current = iframeContentRef.current;
118
+ while (current) {
119
+ var _current$classList;
120
+ if ((_current$classList = current.classList) !== null && _current$classList !== void 0 && _current$classList.contains('node-iframe')) {
121
+ var style = window.getComputedStyle(current);
122
+ var paddingLeft = parseFloat(style.paddingLeft) || 0;
123
+ var paddingRight = parseFloat(style.paddingRight) || 0;
124
+ return current.clientWidth - paddingLeft - paddingRight;
125
+ }
126
+ current = current.parentElement;
127
+ }
128
+ }
129
+ if (editor !== null && editor !== void 0 && (_editor$view = editor.view) !== null && _editor$view !== void 0 && _editor$view.dom) {
130
+ var editorElement = editor.view.dom;
131
+ var _style = window.getComputedStyle(editorElement);
132
+ var _paddingLeft = parseFloat(_style.paddingLeft) || 0;
133
+ var _paddingRight = parseFloat(_style.paddingRight) || 0;
134
+ var editorWidth = editorElement.clientWidth - _paddingLeft - _paddingRight;
135
+ if (editorWidth > 0) {
136
+ return editorWidth;
137
+ }
138
+ }
139
+ return 800;
140
+ };
141
+ var handleMouseDown = function handleMouseDown(e, corner) {
142
+ e.preventDefault();
143
+ e.stopPropagation();
144
+ setIsDragging(true);
145
+ setDragCorner(corner);
146
+ dragStartXRef.current = e.clientX;
147
+ dragStartYRef.current = e.clientY;
148
+ var width = getCurrentDisplayWidth();
149
+ var height = getCurrentDisplayHeight();
150
+ dragStartWidthRef.current = width;
151
+ dragStartHeightRef.current = height;
152
+ maxWidthRef.current = getEditorWidth();
153
+ };
154
+ var handleMouseMove = useCallback(function (e) {
155
+ if (!isDragging || !dragCorner) return;
156
+ var deltaX = e.clientX - dragStartXRef.current;
157
+ var deltaY = e.clientY - dragStartYRef.current;
158
+ var newWidth;
159
+ var newHeight;
160
+ if (dragCorner === 'top-right' || dragCorner === 'bottom-right') {
161
+ newWidth = dragStartWidthRef.current + deltaX;
162
+ } else {
163
+ newWidth = dragStartWidthRef.current - deltaX;
164
+ }
165
+ if (dragCorner === 'bottom-left' || dragCorner === 'bottom-right') {
166
+ newHeight = dragStartHeightRef.current + deltaY;
167
+ } else {
168
+ newHeight = dragStartHeightRef.current - deltaY;
169
+ }
170
+ newWidth = Math.max(200, Math.min(maxWidthRef.current, newWidth));
171
+ newHeight = Math.max(100, Math.min(2000, newHeight));
172
+ updateAttributes({
173
+ width: newWidth,
174
+ height: newHeight
175
+ });
176
+ }, [isDragging, dragCorner, updateAttributes]);
177
+ var handleMouseUp = useCallback(function () {
178
+ setIsDragging(false);
179
+ setDragCorner(null);
180
+ }, []);
181
+ useEffect(function () {
182
+ setEditSrc(attrs.src);
183
+ }, [attrs.src]);
184
+ useEffect(function () {
185
+ if (isDragging) {
186
+ document.addEventListener('mousemove', handleMouseMove);
187
+ document.addEventListener('mouseup', handleMouseUp);
188
+ return function () {
189
+ document.removeEventListener('mousemove', handleMouseMove);
190
+ document.removeEventListener('mouseup', handleMouseUp);
191
+ };
192
+ }
193
+ }, [isDragging, handleMouseMove, handleMouseUp]);
68
194
  var handleSave = /*#__PURE__*/function () {
69
195
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
70
196
  var validatedUrl;
@@ -72,11 +198,11 @@ var IframeViewWrapper = function IframeViewWrapper(_ref) {
72
198
  while (1) switch (_context.prev = _context.next) {
73
199
  case 0:
74
200
  if (!editSrc.trim()) {
75
- _context.next = 12;
201
+ _context.next = 13;
76
202
  break;
77
203
  }
78
204
  _context.prev = 1;
79
- validatedUrl = editSrc.trim();
205
+ validatedUrl = extractSrcFromIframe(editSrc);
80
206
  if (!onValidateUrl) {
81
207
  _context.next = 7;
82
208
  break;
@@ -89,72 +215,30 @@ var IframeViewWrapper = function IframeViewWrapper(_ref) {
89
215
  updateAttributes({
90
216
  src: validatedUrl,
91
217
  width: attrs.width,
92
- height: attrs.height
218
+ height: attrs.height,
219
+ align: attrs.align
93
220
  });
94
- _context.next = 12;
221
+ setEditSrc(validatedUrl);
222
+ _context.next = 13;
95
223
  break;
96
- case 10:
97
- _context.prev = 10;
224
+ case 11:
225
+ _context.prev = 11;
98
226
  _context.t0 = _context["catch"](1);
99
- case 12:
100
- handleClosePopover();
101
227
  case 13:
228
+ handleClosePopover();
229
+ case 14:
102
230
  case "end":
103
231
  return _context.stop();
104
232
  }
105
- }, _callee, null, [[1, 10]]);
233
+ }, _callee, null, [[1, 11]]);
106
234
  }));
107
235
  return function handleSave() {
108
236
  return _ref2.apply(this, arguments);
109
237
  };
110
238
  }();
111
- var handleMouseDownWidth = function handleMouseDownWidth(e) {
112
- e.preventDefault();
113
- setIsDraggingWidth(true);
114
- setDragStartX(e.clientX);
115
- setDragStartWidth(attrs.width);
116
- };
117
- var handleMouseDownHeight = function handleMouseDownHeight(e) {
118
- e.preventDefault();
119
- setIsDraggingHeight(true);
120
- setDragStartY(e.clientY);
121
- setDragStartHeight(attrs.height);
122
- };
123
- var handleMouseMove = function handleMouseMove(e) {
124
- if (isDraggingWidth) {
125
- var deltaX = e.clientX - dragStartX;
126
- var newWidth = Math.max(200, Math.min(1920, dragStartWidth + deltaX));
127
- updateAttributes({
128
- width: newWidth,
129
- height: attrs.height,
130
- src: attrs.src
131
- });
132
- }
133
- if (isDraggingHeight) {
134
- var deltaY = e.clientY - dragStartY;
135
- var newHeight = Math.max(100, Math.min(2000, dragStartHeight + deltaY));
136
- updateAttributes({
137
- width: attrs.width,
138
- height: newHeight,
139
- src: attrs.src
140
- });
141
- }
142
- };
143
- var handleMouseUp = function handleMouseUp() {
144
- setIsDraggingWidth(false);
145
- setIsDraggingHeight(false);
146
- };
147
- useEffect(function () {
148
- if (isDraggingWidth || isDraggingHeight) {
149
- document.addEventListener('mousemove', handleMouseMove);
150
- document.addEventListener('mouseup', handleMouseUp);
151
- return function () {
152
- document.removeEventListener('mousemove', handleMouseMove);
153
- document.removeEventListener('mouseup', handleMouseUp);
154
- };
155
- }
156
- }, [isDraggingWidth, isDraggingHeight]);
157
- if (!attrs.src && !editor.isEditable) return null;
239
+ if (!attrs.src && !editor.isEditable) {
240
+ return null;
241
+ }
158
242
  if (!editor.isEditable) {
159
243
  return /*#__PURE__*/React.createElement(ReadonlyIframe, {
160
244
  attrs: attrs
@@ -169,115 +253,247 @@ var IframeViewWrapper = function IframeViewWrapper(_ref) {
169
253
  });
170
254
  }
171
255
  return /*#__PURE__*/React.createElement(NodeViewWrapper, {
172
- className: "iframe-wrapper ".concat(selected ? 'ProseMirror-selectednode' : ''),
173
- "data-drag-handle": true
256
+ className: "iframe-wrapper ".concat(selected ? 'ProseMirror-selectednode' : '')
174
257
  }, /*#__PURE__*/React.createElement(Box, {
175
258
  sx: {
176
- position: 'relative',
177
- display: 'inline-block',
178
- border: '1px solid',
179
- borderColor: 'divider',
180
- borderRadius: 'var(--mui-shape-borderRadius)',
181
- p: '0.25rem',
182
- bgcolor: 'background.paper',
183
- '&:hover .iframe-controls': {
184
- opacity: 1
259
+ backgroundColor: 'transparent !important',
260
+ textAlign: attrs.align || undefined
261
+ }
262
+ }, /*#__PURE__*/React.createElement(HoverPopover, {
263
+ keepOpen: keepHoverPopoverOpen,
264
+ placement: "top",
265
+ offset: 4,
266
+ actions: /*#__PURE__*/React.createElement(Stack, {
267
+ direction: 'row',
268
+ alignItems: 'center',
269
+ sx: {
270
+ p: 0.5
185
271
  }
186
- },
272
+ }, /*#__PURE__*/React.createElement(ToolbarItem, {
273
+ ref: editButtonRef,
274
+ icon: /*#__PURE__*/React.createElement(EditLineIcon, {
275
+ sx: {
276
+ fontSize: '1rem'
277
+ }
278
+ }),
279
+ tip: "\u66F4\u6362\u94FE\u63A5",
280
+ onClick: handleShowPopover
281
+ }), /*#__PURE__*/React.createElement(Divider, {
282
+ orientation: "vertical",
283
+ flexItem: true,
284
+ sx: {
285
+ height: '1rem',
286
+ mx: 0.5,
287
+ alignSelf: 'center',
288
+ borderColor: 'divider'
289
+ }
290
+ }), /*#__PURE__*/React.createElement(ToolbarItem, {
291
+ icon: /*#__PURE__*/React.createElement(AlignLeftIcon, {
292
+ sx: {
293
+ fontSize: '1rem'
294
+ }
295
+ }),
296
+ tip: "\u5DE6\u4FA7\u5BF9\u9F50",
297
+ className: attrs.align === 'left' ? 'tool-active' : '',
298
+ onClick: function onClick() {
299
+ return updateAttributes({
300
+ align: attrs.align === 'left' ? null : 'left'
301
+ });
302
+ }
303
+ }), /*#__PURE__*/React.createElement(ToolbarItem, {
304
+ icon: /*#__PURE__*/React.createElement(AlignCenterIcon, {
305
+ sx: {
306
+ fontSize: '1rem'
307
+ }
308
+ }),
309
+ tip: "\u5C45\u4E2D\u5BF9\u9F50",
310
+ className: attrs.align === 'center' ? 'tool-active' : '',
311
+ onClick: function onClick() {
312
+ return updateAttributes({
313
+ align: attrs.align === 'center' ? null : 'center'
314
+ });
315
+ }
316
+ }), /*#__PURE__*/React.createElement(ToolbarItem, {
317
+ icon: /*#__PURE__*/React.createElement(AlignRightIcon, {
318
+ sx: {
319
+ fontSize: '1rem'
320
+ }
321
+ }),
322
+ tip: "\u53F3\u4FA7\u5BF9\u9F50",
323
+ className: attrs.align === 'right' ? 'tool-active' : '',
324
+ onClick: function onClick() {
325
+ return updateAttributes({
326
+ align: attrs.align === 'right' ? null : 'right'
327
+ });
328
+ }
329
+ }), /*#__PURE__*/React.createElement(Divider, {
330
+ orientation: "vertical",
331
+ flexItem: true,
332
+ sx: {
333
+ height: '1rem',
334
+ mx: 0.5,
335
+ alignSelf: 'center',
336
+ borderColor: 'divider'
337
+ }
338
+ }), /*#__PURE__*/React.createElement(ActionDropdown, {
339
+ id: "iframe-width-dropdown",
340
+ selected: getCurrentWidthPercent(),
341
+ defaultDisplay: !isPercentWidth() ? {
342
+ label: '固定宽度'
343
+ } : undefined,
344
+ list: [{
345
+ key: '50',
346
+ label: '自适应宽度(50%)',
347
+ onClick: function onClick() {
348
+ return updateAttributes({
349
+ width: '50%'
350
+ });
351
+ }
352
+ }, {
353
+ key: '75',
354
+ label: '自适应宽度(75%)',
355
+ onClick: function onClick() {
356
+ return updateAttributes({
357
+ width: '75%'
358
+ });
359
+ }
360
+ }, {
361
+ key: '100',
362
+ label: '自适应宽度(100%)',
363
+ onClick: function onClick() {
364
+ return updateAttributes({
365
+ width: '100%'
366
+ });
367
+ }
368
+ }]
369
+ }), /*#__PURE__*/React.createElement(Divider, {
370
+ orientation: "vertical",
371
+ flexItem: true,
372
+ sx: {
373
+ height: '1rem',
374
+ mx: 0.5,
375
+ alignSelf: 'center',
376
+ borderColor: 'divider'
377
+ }
378
+ }), /*#__PURE__*/React.createElement(ToolbarItem, {
379
+ icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
380
+ sx: {
381
+ fontSize: '1rem'
382
+ }
383
+ }),
384
+ tip: "\u5220\u9664",
385
+ onClick: deleteNode
386
+ })),
387
+ style: _objectSpread({
388
+ display: 'inline-block'
389
+ }, typeof attrs.width === 'string' && attrs.width.endsWith('%') ? {
390
+ width: attrs.width
391
+ } : {})
392
+ }, /*#__PURE__*/React.createElement(Box, {
393
+ ref: iframeContentRef,
187
394
  onMouseEnter: function onMouseEnter() {
188
395
  return setIsHovering(true);
189
396
  },
190
397
  onMouseLeave: function onMouseLeave() {
191
398
  return setIsHovering(false);
192
- }
193
- }, (isDraggingWidth || isDraggingHeight) && /*#__PURE__*/React.createElement(Box, {
399
+ },
194
400
  sx: {
195
- position: 'absolute',
196
- inset: 0,
197
- zIndex: 8,
198
- cursor: isDraggingWidth ? 'ew-resize' : 'ns-resize',
199
- backgroundColor: 'transparent'
401
+ position: 'relative'
200
402
  }
201
- }), /*#__PURE__*/React.createElement("iframe", {
403
+ }, /*#__PURE__*/React.createElement("iframe", {
404
+ ref: iframeRef,
202
405
  src: attrs.src,
203
- width: attrs.width,
406
+ width: typeof attrs.width === 'number' ? attrs.width : undefined,
204
407
  height: attrs.height,
205
408
  style: {
206
- display: 'block',
207
- border: 0,
409
+ width: typeof attrs.width === 'string' && attrs.width.endsWith('%') ? '100%' : undefined,
208
410
  maxWidth: '100%',
209
- pointerEvents: isDraggingWidth || isDraggingHeight ? 'none' : 'auto'
210
- }
211
- }), (isHovering || isDraggingWidth) && /*#__PURE__*/React.createElement(Box, {
212
- onMouseDown: handleMouseDownWidth,
411
+ cursor: isDragging ? 'default' : 'pointer',
412
+ border: '2px solid',
413
+ borderColor: isHovering || isDragging ? alpha(theme.palette.primary.main, 0.3) : 'transparent',
414
+ display: 'block'
415
+ },
416
+ frameBorder: "0",
417
+ allowFullScreen: true
418
+ }), (isHovering || isDragging) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
419
+ onMouseDown: function onMouseDown(e) {
420
+ return handleMouseDown(e, 'top-left');
421
+ },
213
422
  sx: {
214
423
  position: 'absolute',
215
- right: -2,
216
- top: '50%',
217
- transform: 'translateY(-50%)',
218
- width: 4,
219
- height: 50,
220
- bgcolor: isDraggingWidth ? 'primary.main' : 'text.primary',
221
- cursor: 'ew-resize',
222
- borderRadius: 2,
424
+ left: -4,
425
+ top: -4,
426
+ width: 12,
427
+ height: 12,
428
+ bgcolor: 'background.default',
429
+ cursor: 'nwse-resize',
430
+ borderRadius: '50%',
431
+ border: '2px solid',
432
+ borderColor: isDragging && dragCorner === 'top-left' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
223
433
  '&:hover': {
224
- bgcolor: 'primary.main'
434
+ borderColor: 'primary.main'
225
435
  },
226
436
  transition: 'background-color 0.2s ease'
227
437
  }
228
- }), (isHovering || isDraggingHeight) && /*#__PURE__*/React.createElement(Box, {
229
- onMouseDown: handleMouseDownHeight,
438
+ }), /*#__PURE__*/React.createElement(Box, {
439
+ onMouseDown: function onMouseDown(e) {
440
+ return handleMouseDown(e, 'top-right');
441
+ },
230
442
  sx: {
231
443
  position: 'absolute',
232
- left: '50%',
233
- bottom: -2,
234
- transform: 'translateX(-50%)',
235
- height: 4,
236
- width: 60,
237
- bgcolor: isDraggingHeight ? 'primary.main' : 'text.primary',
238
- cursor: 'ns-resize',
239
- borderRadius: 2,
444
+ right: -4,
445
+ top: -4,
446
+ width: 12,
447
+ height: 12,
448
+ bgcolor: 'background.default',
449
+ cursor: 'nesw-resize',
450
+ borderRadius: '50%',
451
+ border: '2px solid',
452
+ borderColor: isDragging && dragCorner === 'top-right' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
240
453
  '&:hover': {
241
- bgcolor: 'primary.main'
454
+ borderColor: 'primary.main'
242
455
  },
243
456
  transition: 'background-color 0.2s ease'
244
457
  }
245
- }), (isHovering || !!anchorEl) && /*#__PURE__*/React.createElement(Box, {
246
- className: "iframe-controls",
458
+ }), /*#__PURE__*/React.createElement(Box, {
459
+ onMouseDown: function onMouseDown(e) {
460
+ return handleMouseDown(e, 'bottom-left');
461
+ },
247
462
  sx: {
248
463
  position: 'absolute',
249
- top: '0.5rem',
250
- right: '0.5rem',
251
- display: 'flex',
252
- gap: '0.25rem'
253
- }
254
- }, /*#__PURE__*/React.createElement(Tooltip, {
255
- arrow: true,
256
- title: "\u66F4\u6362\u94FE\u63A5"
257
- }, /*#__PURE__*/React.createElement(IconButton, {
258
- size: "small",
259
- onClick: handleShowPopover,
260
- sx: {
261
- color: 'text.primary',
262
- bgcolor: 'background.paper'
263
- }
264
- }, /*#__PURE__*/React.createElement(EditBoxLineIcon, {
265
- sx: {
266
- fontSize: 18
267
- }
268
- }))), /*#__PURE__*/React.createElement(Tooltip, {
269
- arrow: true,
270
- title: "\u5220\u9664"
271
- }, /*#__PURE__*/React.createElement(IconButton, {
272
- size: "small",
273
- onClick: deleteNode,
274
- sx: {
275
- color: 'text.primary',
276
- bgcolor: 'background.paper'
464
+ left: -4,
465
+ bottom: -2,
466
+ width: 12,
467
+ height: 12,
468
+ cursor: 'nesw-resize',
469
+ borderRadius: '50%',
470
+ border: '2px solid',
471
+ bgcolor: 'background.default',
472
+ borderColor: isDragging && dragCorner === 'bottom-left' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
473
+ '&:hover': {
474
+ borderColor: 'primary.main'
475
+ },
476
+ transition: 'background-color 0.2s ease'
277
477
  }
278
- }, /*#__PURE__*/React.createElement(DeleteLineIcon, {
478
+ }), /*#__PURE__*/React.createElement(Box, {
479
+ onMouseDown: function onMouseDown(e) {
480
+ return handleMouseDown(e, 'bottom-right');
481
+ },
279
482
  sx: {
280
- fontSize: 18
483
+ position: 'absolute',
484
+ right: -4,
485
+ bottom: -2,
486
+ width: 12,
487
+ height: 12,
488
+ bgcolor: 'background.default',
489
+ cursor: 'nwse-resize',
490
+ borderRadius: '50%',
491
+ border: '2px solid',
492
+ borderColor: isDragging && dragCorner === 'bottom-right' ? 'primary.main' : alpha(theme.palette.primary.main, 0.3),
493
+ '&:hover': {
494
+ borderColor: 'primary.main'
495
+ },
496
+ transition: 'background-color 0.2s ease'
281
497
  }
282
498
  }))))), /*#__PURE__*/React.createElement(FloatingPopover, {
283
499
  open: Boolean(anchorEl),
@@ -291,13 +507,15 @@ var IframeViewWrapper = function IframeViewWrapper(_ref) {
291
507
  }
292
508
  }, /*#__PURE__*/React.createElement(Box, {
293
509
  sx: {
294
- fontSize: '0.875rem',
510
+ fontSize: '0.75rem',
295
511
  color: 'text.secondary',
296
512
  lineHeight: '1.5',
297
513
  mb: 1
298
514
  }
299
515
  }, "\u94FE\u63A5\u5730\u5740"), /*#__PURE__*/React.createElement(TextField, {
300
516
  fullWidth: true,
517
+ multiline: true,
518
+ rows: 5,
301
519
  size: "small",
302
520
  value: editSrc,
303
521
  onChange: function onChange(e) {