@yoopta/embed 1.9.8-rc → 1.9.9-rc

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1637
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,1637 +1 @@
1
- import { getElementClassname, UI_HELPERS, cx, createYooptaPlugin, getElementByPath, generateId } from '@yoopta/editor';
2
- import { Transforms, Element } from 'slate';
3
- import { jsx, jsxs } from 'react/jsx-runtime';
4
- import * as React from 'react';
5
- import { useState, useEffect, useRef, useMemo } from 'react';
6
- import { flushSync } from 'react-dom';
7
- import { ReactEditor, useSelected, useReadOnly } from 'slate-react';
8
-
9
- /******************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
-
24
- function __rest(s, e) {
25
- var t = {};
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
27
- t[p] = s[p];
28
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
29
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
31
- t[p[i]] = s[p[i]];
32
- }
33
- return t;
34
- }
35
-
36
- function __awaiter(thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- }
45
-
46
- /**
47
- *
48
- * @param {DOM Ref} elementRef - DOM ref for checking the intersection
49
- * @param {Observer Params} - https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
50
- * @returns {IntersectionObserverEntry} - https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry
51
- */
52
- function useIntersectionObserver(elementRef, { threshold = 0, root = null, rootMargin = '0%', freezeOnceVisible = false } = {}) {
53
- const [entry, setEntry] = useState({});
54
- const frozen = entry.isIntersecting && freezeOnceVisible;
55
- const updateEntry = ([e]) => setEntry(e);
56
- useEffect(() => {
57
- const node = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current;
58
- const hasNotIOSupport = !window.IntersectionObserver;
59
- if (hasNotIOSupport || frozen || !node)
60
- return;
61
- const observerParams = { threshold, root, rootMargin };
62
- const observer = new IntersectionObserver(updateEntry, observerParams);
63
- observer.observe(node);
64
- return () => observer.disconnect();
65
- }, [elementRef, threshold, root, rootMargin, frozen]);
66
- return entry;
67
- }
68
-
69
- function styleInject(css, ref) {
70
- if ( ref === void 0 ) ref = {};
71
- var insertAt = ref.insertAt;
72
-
73
- if (!css || typeof document === 'undefined') { return; }
74
-
75
- var head = document.head || document.getElementsByTagName('head')[0];
76
- var style = document.createElement('style');
77
- style.type = 'text/css';
78
-
79
- if (insertAt === 'top') {
80
- if (head.firstChild) {
81
- head.insertBefore(style, head.firstChild);
82
- } else {
83
- head.appendChild(style);
84
- }
85
- } else {
86
- head.appendChild(style);
87
- }
88
-
89
- if (style.styleSheet) {
90
- style.styleSheet.cssText = css;
91
- } else {
92
- style.appendChild(document.createTextNode(css));
93
- }
94
- }
95
-
96
- var css_248z$9 = ".DayliMotion-module_root{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.DayliMotion-module_iframe{background-color:#fff}.DayliMotion-module_container,.DayliMotion-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.DayliMotion-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.DayliMotion-module_embed{height:100%;position:relative;width:100%}";
97
- var s$9 = {"root":"DayliMotion-module_root","iframe":"DayliMotion-module_iframe","container":"DayliMotion-module_container","iframePreview":"DayliMotion-module_iframePreview","embed":"DayliMotion-module_embed"};
98
- styleInject(css_248z$9);
99
-
100
- const getDayliMotionAPI = (providerId) => `https://api.dailymotion.com/video/${providerId}?fields=thumbnail_url`;
101
- function DailyMotion(_a) {
102
- var { providerId } = _a, other = __rest(_a, ["providerId"]);
103
- const dailyMotionRootRef = useRef(null);
104
- const [src, setSrc] = useState(null);
105
- const [isFrameLoaded, setFrameLoaded] = useState(false);
106
- const { isIntersecting: isInViewport } = useIntersectionObserver(dailyMotionRootRef, {
107
- freezeOnceVisible: true,
108
- rootMargin: '50%',
109
- });
110
- useEffect(() => {
111
- fetch(getDayliMotionAPI(providerId))
112
- .then((data) => data.json())
113
- .then((data) => setSrc(data.thumbnail_url))
114
- .catch(() => setSrc(null));
115
- }, [providerId]);
116
- return (jsx("div", Object.assign({ className: s$9.root, ref: dailyMotionRootRef }, { children: jsx("div", Object.assign({ className: s$9.container }, { children: jsxs("div", Object.assign({ className: s$9.embed }, { children: [jsx("img", { src: src || '', alt: "daylimotion_video_preview", width: "100%", height: "100%", className: s$9.iframePreview, style: {
117
- opacity: isInViewport && isFrameLoaded ? 0 : 1,
118
- zIndex: isInViewport && isFrameLoaded ? -1 : 0,
119
- } }), isInViewport && (jsx("iframe", Object.assign({ title: "Dailymotion Video Player", frameBorder: 0, onLoad: () => setFrameLoaded(true), src: `https://www.dailymotion.com/embed/video/${providerId}`, allowFullScreen: true, className: s$9.iframe }, other)))] })) })) })));
120
- }
121
-
122
- var css_248z$8 = ".DefaultEmbed-module_root{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.DefaultEmbed-module_iframe{background-color:#fff}.DefaultEmbed-module_container,.DefaultEmbed-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.DefaultEmbed-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.DefaultEmbed-module_embed{height:100%;position:relative;width:100%}";
123
- var s$8 = {"root":"DefaultEmbed-module_root","iframe":"DefaultEmbed-module_iframe","container":"DefaultEmbed-module_container","iframePreview":"DefaultEmbed-module_iframePreview","embed":"DefaultEmbed-module_embed"};
124
- styleInject(css_248z$8);
125
-
126
- function DefaultEmbed(_a) {
127
- var { providerId, url } = _a; __rest(_a, ["providerId", "url"]);
128
- const embedRootRef = useRef(null);
129
- const { isIntersecting: isInViewport } = useIntersectionObserver(embedRootRef, {
130
- freezeOnceVisible: true,
131
- rootMargin: '50%',
132
- });
133
- return (jsx("div", Object.assign({ className: s$8.root, ref: embedRootRef }, { children: jsx("div", Object.assign({ className: s$8.container }, { children: jsx("div", Object.assign({ className: s$8.embed }, { children: isInViewport && jsx("iframe", { src: url, frameBorder: 0, allowFullScreen: true, className: s$8.iframe, height: "450px" }) })) })) })));
134
- }
135
-
136
- var css_248z$7 = ".FigmaEmbed-module_root{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.FigmaEmbed-module_iframe{background-color:#fff}.FigmaEmbed-module_container,.FigmaEmbed-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.FigmaEmbed-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.FigmaEmbed-module_embed{height:100%;position:relative;width:100%}";
137
- var s$7 = {"root":"FigmaEmbed-module_root","iframe":"FigmaEmbed-module_iframe","container":"FigmaEmbed-module_container","iframePreview":"FigmaEmbed-module_iframePreview","embed":"FigmaEmbed-module_embed"};
138
- styleInject(css_248z$7);
139
-
140
- function FigmaEmbed(_a) {
141
- var { providerId, url } = _a; __rest(_a, ["providerId", "url"]);
142
- const figmaRootRef = useRef(null);
143
- const { isIntersecting: isInViewport } = useIntersectionObserver(figmaRootRef, {
144
- freezeOnceVisible: true,
145
- rootMargin: '50%',
146
- });
147
- return (jsx("div", Object.assign({ className: s$7.root, ref: figmaRootRef }, { children: jsx("div", Object.assign({ className: s$7.container }, { children: jsx("div", Object.assign({ className: s$7.embed }, { children: isInViewport && (jsx("iframe", { src: `https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(url)}`, frameBorder: 0, allowFullScreen: true, className: s$7.iframe, height: "450px" })) })) })) })));
148
- }
149
-
150
- var css_248z$6 = ".TweetEmbed-module_root{display:flex;height:100%;justify-content:center;min-height:100px;padding-bottom:86%;position:relative;width:100%}.TweetEmbed-module_iframe{background-color:#fff}.TweetEmbed-module_container,.TweetEmbed-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.TweetEmbed-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.TweetEmbed-module_embed{height:100%;position:relative;width:100%}.TweetEmbed-module_embed>div,.TweetEmbed-module_embed>div>div{height:100%}.TweetEmbed-module_embed iframe{height:100%!important;width:100%!important}";
151
- var s$6 = {"root":"TweetEmbed-module_root","iframe":"TweetEmbed-module_iframe","container":"TweetEmbed-module_container","iframePreview":"TweetEmbed-module_iframePreview","embed":"TweetEmbed-module_embed"};
152
- styleInject(css_248z$6);
153
-
154
- function TweetEmbed({ providerId }) {
155
- const twitterRootRef = useRef(null);
156
- const { isIntersecting: isInViewport } = useIntersectionObserver(twitterRootRef, {
157
- freezeOnceVisible: true,
158
- rootMargin: '50%',
159
- });
160
- useEffect(() => {
161
- var _a;
162
- if (!isInViewport)
163
- return;
164
- const script = document.createElement('script');
165
- script.src = 'https://platform.twitter.com/widgets.js';
166
- (_a = twitterRootRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(script);
167
- script.onload = () => {
168
- if (window.twttr) {
169
- window.twttr.widgets.createTweet(providerId, document.getElementById(providerId), {
170
- align: 'center',
171
- conversation: 'none',
172
- dnt: true,
173
- theme: 'dark',
174
- height: 300,
175
- });
176
- }
177
- };
178
- }, [providerId, isInViewport]);
179
- return (jsx("div", Object.assign({ className: s$6.root, ref: twitterRootRef }, { children: jsx("div", Object.assign({ className: s$6.container }, { children: jsx("div", Object.assign({ className: s$6.embed }, { children: jsx("div", { id: providerId }) })) })) })));
180
- }
181
-
182
- var css_248z$5 = ".VimeoPlayer-module_root{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.VimeoPlayer-module_iframe{background-color:#fff}.VimeoPlayer-module_container,.VimeoPlayer-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.VimeoPlayer-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.VimeoPlayer-module_embed{height:100%;position:relative;width:100%}";
183
- var s$5 = {"root":"VimeoPlayer-module_root","iframe":"VimeoPlayer-module_iframe","container":"VimeoPlayer-module_container","iframePreview":"VimeoPlayer-module_iframePreview","embed":"VimeoPlayer-module_embed"};
184
- styleInject(css_248z$5);
185
-
186
- const VIMEO_API_URI = 'https://vimeo.com/api/v2/video';
187
- function VimeoPlayer(_a) {
188
- var { providerId } = _a, other = __rest(_a, ["providerId"]);
189
- const vimeoRootRef = useRef(null);
190
- const [src, setSrc] = useState(null);
191
- const [isFrameLoaded, setFrameLoaded] = useState(false);
192
- const { isIntersecting: isInViewport } = useIntersectionObserver(vimeoRootRef, {
193
- freezeOnceVisible: true,
194
- rootMargin: '50%',
195
- });
196
- useEffect(() => {
197
- fetch(`${VIMEO_API_URI}/${providerId}.json`)
198
- .then((data) => data.json())
199
- .then((data) => setSrc(data[0].thumbnail_medium))
200
- .catch(() => setSrc(null));
201
- }, [providerId]);
202
- return (jsx("div", Object.assign({ className: s$5.root, ref: vimeoRootRef }, { children: jsx("div", Object.assign({ className: s$5.container }, { children: jsxs("div", Object.assign({ className: s$5.embed }, { children: [jsx("img", { src: src || '', alt: "vimeo_video_preview", width: "100%", height: "100%", className: s$5.iframePreview, style: {
203
- opacity: isInViewport && isFrameLoaded ? 0 : 1,
204
- zIndex: isInViewport && isFrameLoaded ? -1 : 0,
205
- } }), isInViewport && (jsx("iframe", Object.assign({ title: "Vimeo Player",
206
- // https://developer.vimeo.com/player/embedding
207
- src: `https://player.vimeo.com/video/${providerId}?badge=0&byline=0&portrait=0&title=0`, frameBorder: 0, allowFullScreen: true, onLoad: () => setFrameLoaded(true), className: s$5.iframe }, other)))] })) })) })));
208
- }
209
-
210
- var css_248z$4 = ".YoutubePlayer-module_root{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.YoutubePlayer-module_iframe{background-color:#fff}.YoutubePlayer-module_container,.YoutubePlayer-module_iframe{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}.YoutubePlayer-module_iframePreview{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.YoutubePlayer-module_embed{height:100%;position:relative;width:100%}";
211
- var s$4 = {"root":"YoutubePlayer-module_root","iframe":"YoutubePlayer-module_iframe","container":"YoutubePlayer-module_container","iframePreview":"YoutubePlayer-module_iframePreview","embed":"YoutubePlayer-module_embed"};
212
- styleInject(css_248z$4);
213
-
214
- function YouTubePlayer(_a) {
215
- var { providerId } = _a, other = __rest(_a, ["providerId"]);
216
- const youtubeRootRef = useRef(null);
217
- const [isFrameLoaded, setFrameLoaded] = useState(false);
218
- const { isIntersecting: isInViewport } = useIntersectionObserver(youtubeRootRef, {
219
- freezeOnceVisible: true,
220
- rootMargin: '50%',
221
- });
222
- return (jsx("div", Object.assign({ className: s$4.root, ref: youtubeRootRef }, { children: jsx("div", Object.assign({ className: s$4.container }, { children: jsxs("div", Object.assign({ className: s$4.embed }, { children: [jsx("img", { src: `https://i.ytimg.com/vi/${providerId}/default.jpg`, alt: "youtube_video_preview", width: "100%", height: "100%", className: s$4.iframePreview, style: {
223
- opacity: isInViewport && isFrameLoaded ? 0 : 1,
224
- zIndex: isInViewport && isFrameLoaded ? -1 : 0,
225
- } }), isInViewport && (jsx("iframe", Object.assign({ title: "Youtube Player",
226
- // https://developers.google.com/youtube/player_parameters?hl=en
227
- src: `https://www.youtube.com/embed/${providerId}?hl=no&rel=0`, frameBorder: 0, onLoad: () => setFrameLoaded(true), allowFullScreen: true, className: s$4.iframe }, other)))] })) })) })));
228
- }
229
-
230
- var css_248z$3 = ".Embed-module_embedElement{margin:20px 0 10px;position:relative}";
231
- var s$3 = {"embedElement":"Embed-module_embedElement"};
232
- styleInject(css_248z$3);
233
-
234
- const PROVIDERS = {
235
- vimeo: VimeoPlayer,
236
- youtube: YouTubePlayer,
237
- dailymotion: DailyMotion,
238
- twitter: TweetEmbed,
239
- figma: FigmaEmbed,
240
- };
241
- const Embed$1 = ({ attributes, element, children, HTMLAttributes }) => {
242
- if (typeof element.data.provider === 'string' && element.data.providerId && PROVIDERS[element.data.provider]) {
243
- const ProviderComponent = PROVIDERS[element.data.provider];
244
- return (jsxs("div", Object.assign({}, attributes, { contentEditable: false, draggable: false }, HTMLAttributes, { className: getElementClassname({ element, HTMLAttributes, className: s$3.embedElement }) }, { children: [jsx(ProviderComponent, Object.assign({}, element.data, { providerId: element.data.providerId })), children] })));
245
- }
246
- if (!element.data.url)
247
- return jsx("div", {});
248
- return (jsxs("div", Object.assign({}, attributes, { contentEditable: false, draggable: false }, HTMLAttributes, { className: getElementClassname({ element, HTMLAttributes, className: s$3.embedElement }) }, { children: [jsx(DefaultEmbed, Object.assign({}, element.data, { providerId: element.data.providerId })), children] })));
249
- };
250
-
251
- var __extends$1 = (undefined && undefined.__extends) || (function () {
252
- var extendStatics = function (d, b) {
253
- extendStatics = Object.setPrototypeOf ||
254
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
255
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
256
- return extendStatics(d, b);
257
- };
258
- return function (d, b) {
259
- extendStatics(d, b);
260
- function __() { this.constructor = d; }
261
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
262
- };
263
- })();
264
- var __assign$1 = (undefined && undefined.__assign) || function () {
265
- __assign$1 = Object.assign || function(t) {
266
- for (var s, i = 1, n = arguments.length; i < n; i++) {
267
- s = arguments[i];
268
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
269
- t[p] = s[p];
270
- }
271
- return t;
272
- };
273
- return __assign$1.apply(this, arguments);
274
- };
275
- var rowSizeBase = {
276
- width: '100%',
277
- height: '10px',
278
- top: '0px',
279
- left: '0px',
280
- cursor: 'row-resize',
281
- };
282
- var colSizeBase = {
283
- width: '10px',
284
- height: '100%',
285
- top: '0px',
286
- left: '0px',
287
- cursor: 'col-resize',
288
- };
289
- var edgeBase = {
290
- width: '20px',
291
- height: '20px',
292
- position: 'absolute',
293
- };
294
- var styles = {
295
- top: __assign$1(__assign$1({}, rowSizeBase), { top: '-5px' }),
296
- right: __assign$1(__assign$1({}, colSizeBase), { left: undefined, right: '-5px' }),
297
- bottom: __assign$1(__assign$1({}, rowSizeBase), { top: undefined, bottom: '-5px' }),
298
- left: __assign$1(__assign$1({}, colSizeBase), { left: '-5px' }),
299
- topRight: __assign$1(__assign$1({}, edgeBase), { right: '-10px', top: '-10px', cursor: 'ne-resize' }),
300
- bottomRight: __assign$1(__assign$1({}, edgeBase), { right: '-10px', bottom: '-10px', cursor: 'se-resize' }),
301
- bottomLeft: __assign$1(__assign$1({}, edgeBase), { left: '-10px', bottom: '-10px', cursor: 'sw-resize' }),
302
- topLeft: __assign$1(__assign$1({}, edgeBase), { left: '-10px', top: '-10px', cursor: 'nw-resize' }),
303
- };
304
- var Resizer = /** @class */ (function (_super) {
305
- __extends$1(Resizer, _super);
306
- function Resizer() {
307
- var _this = _super !== null && _super.apply(this, arguments) || this;
308
- _this.onMouseDown = function (e) {
309
- _this.props.onResizeStart(e, _this.props.direction);
310
- };
311
- _this.onTouchStart = function (e) {
312
- _this.props.onResizeStart(e, _this.props.direction);
313
- };
314
- return _this;
315
- }
316
- Resizer.prototype.render = function () {
317
- return (React.createElement("div", { className: this.props.className || '', style: __assign$1(__assign$1({ position: 'absolute', userSelect: 'none' }, styles[this.props.direction]), (this.props.replaceStyles || {})), onMouseDown: this.onMouseDown, onTouchStart: this.onTouchStart }, this.props.children));
318
- };
319
- return Resizer;
320
- }(React.PureComponent));
321
-
322
- var __extends = (undefined && undefined.__extends) || (function () {
323
- var extendStatics = function (d, b) {
324
- extendStatics = Object.setPrototypeOf ||
325
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
326
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
327
- return extendStatics(d, b);
328
- };
329
- return function (d, b) {
330
- extendStatics(d, b);
331
- function __() { this.constructor = d; }
332
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
333
- };
334
- })();
335
- var __assign = (undefined && undefined.__assign) || function () {
336
- __assign = Object.assign || function(t) {
337
- for (var s, i = 1, n = arguments.length; i < n; i++) {
338
- s = arguments[i];
339
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
340
- t[p] = s[p];
341
- }
342
- return t;
343
- };
344
- return __assign.apply(this, arguments);
345
- };
346
- var DEFAULT_SIZE = {
347
- width: 'auto',
348
- height: 'auto',
349
- };
350
- var clamp = function (n, min, max) { return Math.max(Math.min(n, max), min); };
351
- var snap = function (n, size) { return Math.round(n / size) * size; };
352
- var hasDirection = function (dir, target) {
353
- return new RegExp(dir, 'i').test(target);
354
- };
355
- // INFO: In case of window is a Proxy and does not porxy Events correctly, use isTouchEvent & isMouseEvent to distinguish event type instead of `instanceof`.
356
- var isTouchEvent = function (event) {
357
- return Boolean(event.touches && event.touches.length);
358
- };
359
- var isMouseEvent = function (event) {
360
- return Boolean((event.clientX || event.clientX === 0) &&
361
- (event.clientY || event.clientY === 0));
362
- };
363
- var findClosestSnap = function (n, snapArray, snapGap) {
364
- if (snapGap === void 0) { snapGap = 0; }
365
- var closestGapIndex = snapArray.reduce(function (prev, curr, index) { return (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev); }, 0);
366
- var gap = Math.abs(snapArray[closestGapIndex] - n);
367
- return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
368
- };
369
- var getStringSize = function (n) {
370
- n = n.toString();
371
- if (n === 'auto') {
372
- return n;
373
- }
374
- if (n.endsWith('px')) {
375
- return n;
376
- }
377
- if (n.endsWith('%')) {
378
- return n;
379
- }
380
- if (n.endsWith('vh')) {
381
- return n;
382
- }
383
- if (n.endsWith('vw')) {
384
- return n;
385
- }
386
- if (n.endsWith('vmax')) {
387
- return n;
388
- }
389
- if (n.endsWith('vmin')) {
390
- return n;
391
- }
392
- return n + "px";
393
- };
394
- var getPixelSize = function (size, parentSize, innerWidth, innerHeight) {
395
- if (size && typeof size === 'string') {
396
- if (size.endsWith('px')) {
397
- return Number(size.replace('px', ''));
398
- }
399
- if (size.endsWith('%')) {
400
- var ratio = Number(size.replace('%', '')) / 100;
401
- return parentSize * ratio;
402
- }
403
- if (size.endsWith('vw')) {
404
- var ratio = Number(size.replace('vw', '')) / 100;
405
- return innerWidth * ratio;
406
- }
407
- if (size.endsWith('vh')) {
408
- var ratio = Number(size.replace('vh', '')) / 100;
409
- return innerHeight * ratio;
410
- }
411
- }
412
- return size;
413
- };
414
- var calculateNewMax = function (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) {
415
- maxWidth = getPixelSize(maxWidth, parentSize.width, innerWidth, innerHeight);
416
- maxHeight = getPixelSize(maxHeight, parentSize.height, innerWidth, innerHeight);
417
- minWidth = getPixelSize(minWidth, parentSize.width, innerWidth, innerHeight);
418
- minHeight = getPixelSize(minHeight, parentSize.height, innerWidth, innerHeight);
419
- return {
420
- maxWidth: typeof maxWidth === 'undefined' ? undefined : Number(maxWidth),
421
- maxHeight: typeof maxHeight === 'undefined' ? undefined : Number(maxHeight),
422
- minWidth: typeof minWidth === 'undefined' ? undefined : Number(minWidth),
423
- minHeight: typeof minHeight === 'undefined' ? undefined : Number(minHeight),
424
- };
425
- };
426
- var definedProps = [
427
- 'as',
428
- 'style',
429
- 'className',
430
- 'grid',
431
- 'snap',
432
- 'bounds',
433
- 'boundsByDirection',
434
- 'size',
435
- 'defaultSize',
436
- 'minWidth',
437
- 'minHeight',
438
- 'maxWidth',
439
- 'maxHeight',
440
- 'lockAspectRatio',
441
- 'lockAspectRatioExtraWidth',
442
- 'lockAspectRatioExtraHeight',
443
- 'enable',
444
- 'handleStyles',
445
- 'handleClasses',
446
- 'handleWrapperStyle',
447
- 'handleWrapperClass',
448
- 'children',
449
- 'onResizeStart',
450
- 'onResize',
451
- 'onResizeStop',
452
- 'handleComponent',
453
- 'scale',
454
- 'resizeRatio',
455
- 'snapGap',
456
- ];
457
- // HACK: This class is used to calculate % size.
458
- var baseClassName = '__resizable_base__';
459
- var Resizable = /** @class */ (function (_super) {
460
- __extends(Resizable, _super);
461
- function Resizable(props) {
462
- var _this = _super.call(this, props) || this;
463
- _this.ratio = 1;
464
- _this.resizable = null;
465
- // For parent boundary
466
- _this.parentLeft = 0;
467
- _this.parentTop = 0;
468
- // For boundary
469
- _this.resizableLeft = 0;
470
- _this.resizableRight = 0;
471
- _this.resizableTop = 0;
472
- _this.resizableBottom = 0;
473
- // For target boundary
474
- _this.targetLeft = 0;
475
- _this.targetTop = 0;
476
- _this.appendBase = function () {
477
- if (!_this.resizable || !_this.window) {
478
- return null;
479
- }
480
- var parent = _this.parentNode;
481
- if (!parent) {
482
- return null;
483
- }
484
- var element = _this.window.document.createElement('div');
485
- element.style.width = '100%';
486
- element.style.height = '100%';
487
- element.style.position = 'absolute';
488
- element.style.transform = 'scale(0, 0)';
489
- element.style.left = '0';
490
- element.style.flex = '0 0 100%';
491
- if (element.classList) {
492
- element.classList.add(baseClassName);
493
- }
494
- else {
495
- element.className += baseClassName;
496
- }
497
- parent.appendChild(element);
498
- return element;
499
- };
500
- _this.removeBase = function (base) {
501
- var parent = _this.parentNode;
502
- if (!parent) {
503
- return;
504
- }
505
- parent.removeChild(base);
506
- };
507
- _this.ref = function (c) {
508
- if (c) {
509
- _this.resizable = c;
510
- }
511
- };
512
- _this.state = {
513
- isResizing: false,
514
- width: typeof (_this.propsSize && _this.propsSize.width) === 'undefined'
515
- ? 'auto'
516
- : _this.propsSize && _this.propsSize.width,
517
- height: typeof (_this.propsSize && _this.propsSize.height) === 'undefined'
518
- ? 'auto'
519
- : _this.propsSize && _this.propsSize.height,
520
- direction: 'right',
521
- original: {
522
- x: 0,
523
- y: 0,
524
- width: 0,
525
- height: 0,
526
- },
527
- backgroundStyle: {
528
- height: '100%',
529
- width: '100%',
530
- backgroundColor: 'rgba(0,0,0,0)',
531
- cursor: 'auto',
532
- opacity: 0,
533
- position: 'fixed',
534
- zIndex: 9999,
535
- top: '0',
536
- left: '0',
537
- bottom: '0',
538
- right: '0',
539
- },
540
- flexBasis: undefined,
541
- };
542
- _this.onResizeStart = _this.onResizeStart.bind(_this);
543
- _this.onMouseMove = _this.onMouseMove.bind(_this);
544
- _this.onMouseUp = _this.onMouseUp.bind(_this);
545
- return _this;
546
- }
547
- Object.defineProperty(Resizable.prototype, "parentNode", {
548
- get: function () {
549
- if (!this.resizable) {
550
- return null;
551
- }
552
- return this.resizable.parentNode;
553
- },
554
- enumerable: false,
555
- configurable: true
556
- });
557
- Object.defineProperty(Resizable.prototype, "window", {
558
- get: function () {
559
- if (!this.resizable) {
560
- return null;
561
- }
562
- if (!this.resizable.ownerDocument) {
563
- return null;
564
- }
565
- return this.resizable.ownerDocument.defaultView;
566
- },
567
- enumerable: false,
568
- configurable: true
569
- });
570
- Object.defineProperty(Resizable.prototype, "propsSize", {
571
- get: function () {
572
- return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
573
- },
574
- enumerable: false,
575
- configurable: true
576
- });
577
- Object.defineProperty(Resizable.prototype, "size", {
578
- get: function () {
579
- var width = 0;
580
- var height = 0;
581
- if (this.resizable && this.window) {
582
- var orgWidth = this.resizable.offsetWidth;
583
- var orgHeight = this.resizable.offsetHeight;
584
- // HACK: Set position `relative` to get parent size.
585
- // This is because when re-resizable set `absolute`, I can not get base width correctly.
586
- var orgPosition = this.resizable.style.position;
587
- if (orgPosition !== 'relative') {
588
- this.resizable.style.position = 'relative';
589
- }
590
- // INFO: Use original width or height if set auto.
591
- width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
592
- height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
593
- // Restore original position
594
- this.resizable.style.position = orgPosition;
595
- }
596
- return { width: width, height: height };
597
- },
598
- enumerable: false,
599
- configurable: true
600
- });
601
- Object.defineProperty(Resizable.prototype, "sizeStyle", {
602
- get: function () {
603
- var _this = this;
604
- var size = this.props.size;
605
- var getSize = function (key) {
606
- if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
607
- return 'auto';
608
- }
609
- if (_this.propsSize && _this.propsSize[key] && _this.propsSize[key].toString().endsWith('%')) {
610
- if (_this.state[key].toString().endsWith('%')) {
611
- return _this.state[key].toString();
612
- }
613
- var parentSize = _this.getParentSize();
614
- var value = Number(_this.state[key].toString().replace('px', ''));
615
- var percent = (value / parentSize[key]) * 100;
616
- return percent + "%";
617
- }
618
- return getStringSize(_this.state[key]);
619
- };
620
- var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
621
- ? getStringSize(size.width)
622
- : getSize('width');
623
- var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
624
- ? getStringSize(size.height)
625
- : getSize('height');
626
- return { width: width, height: height };
627
- },
628
- enumerable: false,
629
- configurable: true
630
- });
631
- Resizable.prototype.getParentSize = function () {
632
- if (!this.parentNode) {
633
- if (!this.window) {
634
- return { width: 0, height: 0 };
635
- }
636
- return { width: this.window.innerWidth, height: this.window.innerHeight };
637
- }
638
- var base = this.appendBase();
639
- if (!base) {
640
- return { width: 0, height: 0 };
641
- }
642
- // INFO: To calculate parent width with flex layout
643
- var wrapChanged = false;
644
- var wrap = this.parentNode.style.flexWrap;
645
- if (wrap !== 'wrap') {
646
- wrapChanged = true;
647
- this.parentNode.style.flexWrap = 'wrap';
648
- // HACK: Use relative to get parent padding size
649
- }
650
- base.style.position = 'relative';
651
- base.style.minWidth = '100%';
652
- base.style.minHeight = '100%';
653
- var size = {
654
- width: base.offsetWidth,
655
- height: base.offsetHeight,
656
- };
657
- if (wrapChanged) {
658
- this.parentNode.style.flexWrap = wrap;
659
- }
660
- this.removeBase(base);
661
- return size;
662
- };
663
- Resizable.prototype.bindEvents = function () {
664
- if (this.window) {
665
- this.window.addEventListener('mouseup', this.onMouseUp);
666
- this.window.addEventListener('mousemove', this.onMouseMove);
667
- this.window.addEventListener('mouseleave', this.onMouseUp);
668
- this.window.addEventListener('touchmove', this.onMouseMove, {
669
- capture: true,
670
- passive: false,
671
- });
672
- this.window.addEventListener('touchend', this.onMouseUp);
673
- }
674
- };
675
- Resizable.prototype.unbindEvents = function () {
676
- if (this.window) {
677
- this.window.removeEventListener('mouseup', this.onMouseUp);
678
- this.window.removeEventListener('mousemove', this.onMouseMove);
679
- this.window.removeEventListener('mouseleave', this.onMouseUp);
680
- this.window.removeEventListener('touchmove', this.onMouseMove, true);
681
- this.window.removeEventListener('touchend', this.onMouseUp);
682
- }
683
- };
684
- Resizable.prototype.componentDidMount = function () {
685
- if (!this.resizable || !this.window) {
686
- return;
687
- }
688
- var computedStyle = this.window.getComputedStyle(this.resizable);
689
- this.setState({
690
- width: this.state.width || this.size.width,
691
- height: this.state.height || this.size.height,
692
- flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
693
- });
694
- };
695
- Resizable.prototype.componentWillUnmount = function () {
696
- if (this.window) {
697
- this.unbindEvents();
698
- }
699
- };
700
- Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
701
- var propsSize = this.propsSize && this.propsSize[kind];
702
- return this.state[kind] === 'auto' &&
703
- this.state.original[kind] === newSize &&
704
- (typeof propsSize === 'undefined' || propsSize === 'auto')
705
- ? 'auto'
706
- : newSize;
707
- };
708
- Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
709
- var boundsByDirection = this.props.boundsByDirection;
710
- var direction = this.state.direction;
711
- var widthByDirection = boundsByDirection && hasDirection('left', direction);
712
- var heightByDirection = boundsByDirection && hasDirection('top', direction);
713
- var boundWidth;
714
- var boundHeight;
715
- if (this.props.bounds === 'parent') {
716
- var parent_1 = this.parentNode;
717
- if (parent_1) {
718
- boundWidth = widthByDirection
719
- ? this.resizableRight - this.parentLeft
720
- : parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
721
- boundHeight = heightByDirection
722
- ? this.resizableBottom - this.parentTop
723
- : parent_1.offsetHeight + (this.parentTop - this.resizableTop);
724
- }
725
- }
726
- else if (this.props.bounds === 'window') {
727
- if (this.window) {
728
- boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
729
- boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
730
- }
731
- }
732
- else if (this.props.bounds) {
733
- boundWidth = widthByDirection
734
- ? this.resizableRight - this.targetLeft
735
- : this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
736
- boundHeight = heightByDirection
737
- ? this.resizableBottom - this.targetTop
738
- : this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
739
- }
740
- if (boundWidth && Number.isFinite(boundWidth)) {
741
- maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
742
- }
743
- if (boundHeight && Number.isFinite(boundHeight)) {
744
- maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
745
- }
746
- return { maxWidth: maxWidth, maxHeight: maxHeight };
747
- };
748
- Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
749
- var scale = this.props.scale || 1;
750
- var resizeRatio = this.props.resizeRatio || 1;
751
- var _a = this.state, direction = _a.direction, original = _a.original;
752
- var _b = this.props, lockAspectRatio = _b.lockAspectRatio, lockAspectRatioExtraHeight = _b.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _b.lockAspectRatioExtraWidth;
753
- var newWidth = original.width;
754
- var newHeight = original.height;
755
- var extraHeight = lockAspectRatioExtraHeight || 0;
756
- var extraWidth = lockAspectRatioExtraWidth || 0;
757
- if (hasDirection('right', direction)) {
758
- newWidth = original.width + ((clientX - original.x) * resizeRatio) / scale;
759
- if (lockAspectRatio) {
760
- newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
761
- }
762
- }
763
- if (hasDirection('left', direction)) {
764
- newWidth = original.width - ((clientX - original.x) * resizeRatio) / scale;
765
- if (lockAspectRatio) {
766
- newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
767
- }
768
- }
769
- if (hasDirection('bottom', direction)) {
770
- newHeight = original.height + ((clientY - original.y) * resizeRatio) / scale;
771
- if (lockAspectRatio) {
772
- newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
773
- }
774
- }
775
- if (hasDirection('top', direction)) {
776
- newHeight = original.height - ((clientY - original.y) * resizeRatio) / scale;
777
- if (lockAspectRatio) {
778
- newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
779
- }
780
- }
781
- return { newWidth: newWidth, newHeight: newHeight };
782
- };
783
- Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
784
- var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
785
- var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
786
- var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
787
- var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
788
- var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
789
- var extraHeight = lockAspectRatioExtraHeight || 0;
790
- var extraWidth = lockAspectRatioExtraWidth || 0;
791
- if (lockAspectRatio) {
792
- var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
793
- var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
794
- var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
795
- var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
796
- var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
797
- var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
798
- var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
799
- var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
800
- newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
801
- newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
802
- }
803
- else {
804
- newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
805
- newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
806
- }
807
- return { newWidth: newWidth, newHeight: newHeight };
808
- };
809
- Resizable.prototype.setBoundingClientRect = function () {
810
- // For parent boundary
811
- if (this.props.bounds === 'parent') {
812
- var parent_2 = this.parentNode;
813
- if (parent_2) {
814
- var parentRect = parent_2.getBoundingClientRect();
815
- this.parentLeft = parentRect.left;
816
- this.parentTop = parentRect.top;
817
- }
818
- }
819
- // For target(html element) boundary
820
- if (this.props.bounds && typeof this.props.bounds !== 'string') {
821
- var targetRect = this.props.bounds.getBoundingClientRect();
822
- this.targetLeft = targetRect.left;
823
- this.targetTop = targetRect.top;
824
- }
825
- // For boundary
826
- if (this.resizable) {
827
- var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
828
- this.resizableLeft = left;
829
- this.resizableRight = right;
830
- this.resizableTop = top_1;
831
- this.resizableBottom = bottom;
832
- }
833
- };
834
- Resizable.prototype.onResizeStart = function (event, direction) {
835
- if (!this.resizable || !this.window) {
836
- return;
837
- }
838
- var clientX = 0;
839
- var clientY = 0;
840
- if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
841
- clientX = event.nativeEvent.clientX;
842
- clientY = event.nativeEvent.clientY;
843
- }
844
- else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
845
- clientX = event.nativeEvent.touches[0].clientX;
846
- clientY = event.nativeEvent.touches[0].clientY;
847
- }
848
- if (this.props.onResizeStart) {
849
- if (this.resizable) {
850
- var startResize = this.props.onResizeStart(event, direction, this.resizable);
851
- if (startResize === false) {
852
- return;
853
- }
854
- }
855
- }
856
- // Fix #168
857
- if (this.props.size) {
858
- if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
859
- this.setState({ height: this.props.size.height });
860
- }
861
- if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
862
- this.setState({ width: this.props.size.width });
863
- }
864
- }
865
- // For lockAspectRatio case
866
- this.ratio =
867
- typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
868
- var flexBasis;
869
- var computedStyle = this.window.getComputedStyle(this.resizable);
870
- if (computedStyle.flexBasis !== 'auto') {
871
- var parent_3 = this.parentNode;
872
- if (parent_3) {
873
- var dir = this.window.getComputedStyle(parent_3).flexDirection;
874
- this.flexDir = dir.startsWith('row') ? 'row' : 'column';
875
- flexBasis = computedStyle.flexBasis;
876
- }
877
- }
878
- // For boundary
879
- this.setBoundingClientRect();
880
- this.bindEvents();
881
- var state = {
882
- original: {
883
- x: clientX,
884
- y: clientY,
885
- width: this.size.width,
886
- height: this.size.height,
887
- },
888
- isResizing: true,
889
- backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
890
- direction: direction,
891
- flexBasis: flexBasis,
892
- };
893
- this.setState(state);
894
- };
895
- Resizable.prototype.onMouseMove = function (event) {
896
- var _this = this;
897
- if (!this.state.isResizing || !this.resizable || !this.window) {
898
- return;
899
- }
900
- if (this.window.TouchEvent && isTouchEvent(event)) {
901
- try {
902
- event.preventDefault();
903
- event.stopPropagation();
904
- }
905
- catch (e) {
906
- // Ignore on fail
907
- }
908
- }
909
- var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
910
- var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
911
- var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
912
- var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
913
- var parentSize = this.getParentSize();
914
- var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
915
- maxWidth = max.maxWidth;
916
- maxHeight = max.maxHeight;
917
- minWidth = max.minWidth;
918
- minHeight = max.minHeight;
919
- // Calculate new size
920
- var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
921
- // Calculate max size from boundary settings
922
- var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
923
- if (this.props.snap && this.props.snap.x) {
924
- newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
925
- }
926
- if (this.props.snap && this.props.snap.y) {
927
- newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
928
- }
929
- // Calculate new size from aspect ratio
930
- var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
931
- newWidth = newSize.newWidth;
932
- newHeight = newSize.newHeight;
933
- if (this.props.grid) {
934
- var newGridWidth = snap(newWidth, this.props.grid[0]);
935
- var newGridHeight = snap(newHeight, this.props.grid[1]);
936
- var gap = this.props.snapGap || 0;
937
- newWidth = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
938
- newHeight = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
939
- }
940
- var delta = {
941
- width: newWidth - original.width,
942
- height: newHeight - original.height,
943
- };
944
- if (width && typeof width === 'string') {
945
- if (width.endsWith('%')) {
946
- var percent = (newWidth / parentSize.width) * 100;
947
- newWidth = percent + "%";
948
- }
949
- else if (width.endsWith('vw')) {
950
- var vw = (newWidth / this.window.innerWidth) * 100;
951
- newWidth = vw + "vw";
952
- }
953
- else if (width.endsWith('vh')) {
954
- var vh = (newWidth / this.window.innerHeight) * 100;
955
- newWidth = vh + "vh";
956
- }
957
- }
958
- if (height && typeof height === 'string') {
959
- if (height.endsWith('%')) {
960
- var percent = (newHeight / parentSize.height) * 100;
961
- newHeight = percent + "%";
962
- }
963
- else if (height.endsWith('vw')) {
964
- var vw = (newHeight / this.window.innerWidth) * 100;
965
- newHeight = vw + "vw";
966
- }
967
- else if (height.endsWith('vh')) {
968
- var vh = (newHeight / this.window.innerHeight) * 100;
969
- newHeight = vh + "vh";
970
- }
971
- }
972
- var newState = {
973
- width: this.createSizeForCssProperty(newWidth, 'width'),
974
- height: this.createSizeForCssProperty(newHeight, 'height'),
975
- };
976
- if (this.flexDir === 'row') {
977
- newState.flexBasis = newState.width;
978
- }
979
- else if (this.flexDir === 'column') {
980
- newState.flexBasis = newState.height;
981
- }
982
- // For v18, update state sync
983
- flushSync(function () {
984
- _this.setState(newState);
985
- });
986
- if (this.props.onResize) {
987
- this.props.onResize(event, direction, this.resizable, delta);
988
- }
989
- };
990
- Resizable.prototype.onMouseUp = function (event) {
991
- var _a = this.state, isResizing = _a.isResizing, direction = _a.direction, original = _a.original;
992
- if (!isResizing || !this.resizable) {
993
- return;
994
- }
995
- var delta = {
996
- width: this.size.width - original.width,
997
- height: this.size.height - original.height,
998
- };
999
- if (this.props.onResizeStop) {
1000
- this.props.onResizeStop(event, direction, this.resizable, delta);
1001
- }
1002
- if (this.props.size) {
1003
- this.setState(this.props.size);
1004
- }
1005
- this.unbindEvents();
1006
- this.setState({
1007
- isResizing: false,
1008
- backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: 'auto' }),
1009
- });
1010
- };
1011
- Resizable.prototype.updateSize = function (size) {
1012
- this.setState({ width: size.width, height: size.height });
1013
- };
1014
- Resizable.prototype.renderResizer = function () {
1015
- var _this = this;
1016
- var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;
1017
- if (!enable) {
1018
- return null;
1019
- }
1020
- var resizers = Object.keys(enable).map(function (dir) {
1021
- if (enable[dir] !== false) {
1022
- return (React.createElement(Resizer, { key: dir, direction: dir, onResizeStart: _this.onResizeStart, replaceStyles: handleStyles && handleStyles[dir], className: handleClasses && handleClasses[dir] }, handleComponent && handleComponent[dir] ? handleComponent[dir] : null));
1023
- }
1024
- return null;
1025
- });
1026
- // #93 Wrap the resize box in span (will not break 100% width/height)
1027
- return (React.createElement("div", { className: handleWrapperClass, style: handleWrapperStyle }, resizers));
1028
- };
1029
- Resizable.prototype.render = function () {
1030
- var _this = this;
1031
- var extendsProps = Object.keys(this.props).reduce(function (acc, key) {
1032
- if (definedProps.indexOf(key) !== -1) {
1033
- return acc;
1034
- }
1035
- acc[key] = _this.props[key];
1036
- return acc;
1037
- }, {});
1038
- var style = __assign(__assign(__assign({ position: 'relative', userSelect: this.state.isResizing ? 'none' : 'auto' }, this.props.style), this.sizeStyle), { maxWidth: this.props.maxWidth, maxHeight: this.props.maxHeight, minWidth: this.props.minWidth, minHeight: this.props.minHeight, boxSizing: 'border-box', flexShrink: 0 });
1039
- if (this.state.flexBasis) {
1040
- style.flexBasis = this.state.flexBasis;
1041
- }
1042
- var Wrapper = this.props.as || 'div';
1043
- return (React.createElement(Wrapper, __assign({ ref: this.ref, style: style, className: this.props.className }, extendsProps),
1044
- this.state.isResizing && React.createElement("div", { style: this.state.backgroundStyle }),
1045
- this.props.children,
1046
- this.renderResizer()));
1047
- };
1048
- Resizable.defaultProps = {
1049
- as: 'div',
1050
- onResizeStart: function () { },
1051
- onResize: function () { },
1052
- onResizeStop: function () { },
1053
- enable: {
1054
- top: true,
1055
- right: true,
1056
- bottom: true,
1057
- left: true,
1058
- topRight: true,
1059
- bottomRight: true,
1060
- bottomLeft: true,
1061
- topLeft: true,
1062
- },
1063
- style: {},
1064
- grid: [1, 1],
1065
- lockAspectRatio: false,
1066
- lockAspectRatioExtraWidth: 0,
1067
- lockAspectRatioExtraHeight: 0,
1068
- scale: 1,
1069
- resizeRatio: 1,
1070
- snapGap: 0,
1071
- };
1072
- return Resizable;
1073
- }(React.PureComponent));
1074
-
1075
- var _path;
1076
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1077
- var SvgUpload = function SvgUpload(props) {
1078
- return /*#__PURE__*/React.createElement("svg", _extends({
1079
- fill: "currentColor",
1080
- "aria-hidden": "true",
1081
- viewBox: "0 0 24 24",
1082
- "data-testid": "uploadImage"
1083
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
1084
- d: "M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"
1085
- })));
1086
- };
1087
-
1088
- var css_248z$2 = ".EditorUploader-module_container{position:fixed}.EditorUploader-module_content{background:#fff;box-shadow:0 0 0 1px hsla(0,0%,6%,.05),0 3px 6px hsla(0,0%,6%,.1),0 9px 24px hsla(0,0%,6%,.2);display:flex;flex-direction:column;height:100%;max-height:420px;max-width:calc(100vw - 24px);min-width:540px}.EditorUploader-module_tabs{box-shadow:inset 0 -1px 0 rgba(55,53,47,.09);display:flex;font-size:14px;height:40px;padding:0 8px;position:relative;width:100%;z-index:1}.EditorUploader-module_tab{align-items:center;background-color:inherit;border:none;border-radius:4px;color:#37352f;cursor:pointer;display:inline-flex;flex-shrink:0;font-size:14px;height:100%;line-height:1.2;min-width:0;padding:6px 8px;position:relative;transition:height 20ms ease-in 0s;user-select:none;white-space:nowrap}.EditorUploader-module_activeTab:after{background-color:#37352f;bottom:0;content:\"\";height:2px;left:0;position:absolute;width:100%}.EditorUploader-module_uploadContent{display:flex;justify-content:center;margin-left:12px;margin-right:12px;margin-top:4px;padding-bottom:6px;padding-top:6px}.EditorUploader-module_uploader{border:1px solid rgba(55,53,47,.16);border-radius:4px;cursor:pointer;height:32px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap;width:100%}.EditorUploader-module_embed{border:none!important;cursor:pointer!important;height:auto!important;padding-left:0!important;padding-right:0!important}.EditorUploader-module_uploaderLabel{align-items:center;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;height:100%;justify-content:center;line-height:1.2;width:100%}.EditorUploader-module_uploaderInput{left:0;position:absolute;top:0;visibility:hidden}.EditorUploader-module_embedInput{background:hsla(45,13%,94%,.6);box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1);cursor:text;height:32px;line-height:20px;padding:3px 6px;position:relative}.EditorUploader-module_embedButton,.EditorUploader-module_embedInput{align-items:center;border:none;border-radius:4px;display:flex;font-size:14px;width:100%}.EditorUploader-module_embedButton{fill:#fff;background:#2383e2;box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1),0 1px 2px hsla(0,0%,6%,.1);color:#fff;cursor:pointer;flex-shrink:0;font-weight:500;height:28px;justify-content:center;line-height:1.2;margin:12px auto 6px;max-width:300px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap}";
1089
- var s$2 = {"container":"EditorUploader-module_container","content":"EditorUploader-module_content","tabs":"EditorUploader-module_tabs","tab":"EditorUploader-module_tab","activeTab":"EditorUploader-module_activeTab","uploadContent":"EditorUploader-module_uploadContent","uploader":"EditorUploader-module_uploader","embed":"EditorUploader-module_embed EditorUploader-module_uploader","uploaderLabel":"EditorUploader-module_uploaderLabel","uploaderInput":"EditorUploader-module_uploaderInput","embedInput":"EditorUploader-module_embedInput","embedButton":"EditorUploader-module_embedButton"};
1090
- styleInject(css_248z$2);
1091
-
1092
- const EmbedLink = ({ onEmbed }) => {
1093
- const [value, setValue] = useState('');
1094
- const onChange = (e) => setValue(e.target.value);
1095
- const onEmbedLink = () => onEmbed(value);
1096
- return (jsxs("div", Object.assign({ className: s$2.embed }, { children: [jsx("input", { type: "text", placeholder: "Paste embed link", value: value, className: s$2.embedInput, onChange: onChange }), jsx("button", Object.assign({ type: "button", className: s$2.embedButton, onClick: onEmbedLink }, { children: "Embed" }))] })));
1097
- };
1098
- const EditorUploader = ({ style, onEmbed, onClose }) => {
1099
- return (jsxs(UI_HELPERS.Overlay, Object.assign({ onClose: onClose }, { children: [jsx("div", Object.assign({ className: s$2.container, style: style }, { children: jsxs("div", Object.assign({ className: s$2.content }, { children: [jsx("div", Object.assign({ className: s$2.tabs }, { children: jsx("button", Object.assign({ type: "button", className: cx(s$2.tab, { [s$2.activeTab]: true }) }, { children: "Embed link" })) })), jsx("div", Object.assign({ className: s$2.uploadContent }, { children: jsx(EmbedLink, { onEmbed: onEmbed }) }))] })) })), jsx("div", {})] })));
1100
- };
1101
-
1102
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
1103
-
1104
- // Older browsers don't support event options, feature detect it.
1105
-
1106
- // Adopted and modified solution from Bohdan Didukh (2017)
1107
- // https://stackoverflow.com/questions/41594997/ios-10-safari-prevent-scrolling-behind-a-fixed-overlay-and-maintain-scroll-posi
1108
-
1109
- var hasPassiveEvents = false;
1110
- if (typeof window !== 'undefined') {
1111
- var passiveTestOptions = {
1112
- get passive() {
1113
- hasPassiveEvents = true;
1114
- return undefined;
1115
- }
1116
- };
1117
- window.addEventListener('testPassive', null, passiveTestOptions);
1118
- window.removeEventListener('testPassive', null, passiveTestOptions);
1119
- }
1120
-
1121
- var isIosDevice = typeof window !== 'undefined' && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1);
1122
-
1123
-
1124
- var locks = [];
1125
- var documentListenerAdded = false;
1126
- var initialClientY = -1;
1127
- var previousBodyOverflowSetting = void 0;
1128
- var previousBodyPosition = void 0;
1129
- var previousBodyPaddingRight = void 0;
1130
-
1131
- // returns true if `el` should be allowed to receive touchmove events.
1132
- var allowTouchMove = function allowTouchMove(el) {
1133
- return locks.some(function (lock) {
1134
- if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {
1135
- return true;
1136
- }
1137
-
1138
- return false;
1139
- });
1140
- };
1141
-
1142
- var preventDefault = function preventDefault(rawEvent) {
1143
- var e = rawEvent || window.event;
1144
-
1145
- // For the case whereby consumers adds a touchmove event listener to document.
1146
- // Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })
1147
- // in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then
1148
- // the touchmove event on document will break.
1149
- if (allowTouchMove(e.target)) {
1150
- return true;
1151
- }
1152
-
1153
- // Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
1154
- if (e.touches.length > 1) return true;
1155
-
1156
- if (e.preventDefault) e.preventDefault();
1157
-
1158
- return false;
1159
- };
1160
-
1161
- var setOverflowHidden = function setOverflowHidden(options) {
1162
- // If previousBodyPaddingRight is already set, don't set it again.
1163
- if (previousBodyPaddingRight === undefined) {
1164
- var _reserveScrollBarGap = !!options && options.reserveScrollBarGap === true;
1165
- var scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
1166
-
1167
- if (_reserveScrollBarGap && scrollBarGap > 0) {
1168
- var computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);
1169
- previousBodyPaddingRight = document.body.style.paddingRight;
1170
- document.body.style.paddingRight = computedBodyPaddingRight + scrollBarGap + 'px';
1171
- }
1172
- }
1173
-
1174
- // If previousBodyOverflowSetting is already set, don't set it again.
1175
- if (previousBodyOverflowSetting === undefined) {
1176
- previousBodyOverflowSetting = document.body.style.overflow;
1177
- document.body.style.overflow = 'hidden';
1178
- }
1179
- };
1180
-
1181
- var restoreOverflowSetting = function restoreOverflowSetting() {
1182
- if (previousBodyPaddingRight !== undefined) {
1183
- document.body.style.paddingRight = previousBodyPaddingRight;
1184
-
1185
- // Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it
1186
- // can be set again.
1187
- previousBodyPaddingRight = undefined;
1188
- }
1189
-
1190
- if (previousBodyOverflowSetting !== undefined) {
1191
- document.body.style.overflow = previousBodyOverflowSetting;
1192
-
1193
- // Restore previousBodyOverflowSetting to undefined
1194
- // so setOverflowHidden knows it can be set again.
1195
- previousBodyOverflowSetting = undefined;
1196
- }
1197
- };
1198
-
1199
- var setPositionFixed = function setPositionFixed() {
1200
- return window.requestAnimationFrame(function () {
1201
- // If previousBodyPosition is already set, don't set it again.
1202
- if (previousBodyPosition === undefined) {
1203
- previousBodyPosition = {
1204
- position: document.body.style.position,
1205
- top: document.body.style.top,
1206
- left: document.body.style.left
1207
- };
1208
-
1209
- // Update the dom inside an animation frame
1210
- var _window = window,
1211
- scrollY = _window.scrollY,
1212
- scrollX = _window.scrollX,
1213
- innerHeight = _window.innerHeight;
1214
-
1215
- document.body.style.position = 'fixed';
1216
- document.body.style.top = -scrollY;
1217
- document.body.style.left = -scrollX;
1218
-
1219
- setTimeout(function () {
1220
- return window.requestAnimationFrame(function () {
1221
- // Attempt to check if the bottom bar appeared due to the position change
1222
- var bottomBarHeight = innerHeight - window.innerHeight;
1223
- if (bottomBarHeight && scrollY >= innerHeight) {
1224
- // Move the content further up so that the bottom bar doesn't hide it
1225
- document.body.style.top = -(scrollY + bottomBarHeight);
1226
- }
1227
- });
1228
- }, 300);
1229
- }
1230
- });
1231
- };
1232
-
1233
- var restorePositionSetting = function restorePositionSetting() {
1234
- if (previousBodyPosition !== undefined) {
1235
- // Convert the position from "px" to Int
1236
- var y = -parseInt(document.body.style.top, 10);
1237
- var x = -parseInt(document.body.style.left, 10);
1238
-
1239
- // Restore styles
1240
- document.body.style.position = previousBodyPosition.position;
1241
- document.body.style.top = previousBodyPosition.top;
1242
- document.body.style.left = previousBodyPosition.left;
1243
-
1244
- // Restore scroll
1245
- window.scrollTo(x, y);
1246
-
1247
- previousBodyPosition = undefined;
1248
- }
1249
- };
1250
-
1251
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
1252
- var isTargetElementTotallyScrolled = function isTargetElementTotallyScrolled(targetElement) {
1253
- return targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false;
1254
- };
1255
-
1256
- var handleScroll = function handleScroll(event, targetElement) {
1257
- var clientY = event.targetTouches[0].clientY - initialClientY;
1258
-
1259
- if (allowTouchMove(event.target)) {
1260
- return false;
1261
- }
1262
-
1263
- if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {
1264
- // element is at the top of its scroll.
1265
- return preventDefault(event);
1266
- }
1267
-
1268
- if (isTargetElementTotallyScrolled(targetElement) && clientY < 0) {
1269
- // element is at the bottom of its scroll.
1270
- return preventDefault(event);
1271
- }
1272
-
1273
- event.stopPropagation();
1274
- return true;
1275
- };
1276
-
1277
- var disableBodyScroll = function disableBodyScroll(targetElement, options) {
1278
- // targetElement must be provided
1279
- if (!targetElement) {
1280
- // eslint-disable-next-line no-console
1281
- console.error('disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.');
1282
- return;
1283
- }
1284
-
1285
- // disableBodyScroll must not have been called on this targetElement before
1286
- if (locks.some(function (lock) {
1287
- return lock.targetElement === targetElement;
1288
- })) {
1289
- return;
1290
- }
1291
-
1292
- var lock = {
1293
- targetElement: targetElement,
1294
- options: options || {}
1295
- };
1296
-
1297
- locks = [].concat(_toConsumableArray(locks), [lock]);
1298
-
1299
- if (isIosDevice) {
1300
- setPositionFixed();
1301
- } else {
1302
- setOverflowHidden(options);
1303
- }
1304
-
1305
- if (isIosDevice) {
1306
- targetElement.ontouchstart = function (event) {
1307
- if (event.targetTouches.length === 1) {
1308
- // detect single touch.
1309
- initialClientY = event.targetTouches[0].clientY;
1310
- }
1311
- };
1312
- targetElement.ontouchmove = function (event) {
1313
- if (event.targetTouches.length === 1) {
1314
- // detect single touch.
1315
- handleScroll(event, targetElement);
1316
- }
1317
- };
1318
-
1319
- if (!documentListenerAdded) {
1320
- document.addEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);
1321
- documentListenerAdded = true;
1322
- }
1323
- }
1324
- };
1325
-
1326
- var enableBodyScroll = function enableBodyScroll(targetElement) {
1327
- if (!targetElement) {
1328
- // eslint-disable-next-line no-console
1329
- console.error('enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.');
1330
- return;
1331
- }
1332
-
1333
- locks = locks.filter(function (lock) {
1334
- return lock.targetElement !== targetElement;
1335
- });
1336
-
1337
- if (isIosDevice) {
1338
- targetElement.ontouchstart = null;
1339
- targetElement.ontouchmove = null;
1340
-
1341
- if (documentListenerAdded && locks.length === 0) {
1342
- document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);
1343
- documentListenerAdded = false;
1344
- }
1345
- }
1346
-
1347
- if (isIosDevice) {
1348
- restorePositionSetting();
1349
- } else {
1350
- restoreOverflowSetting();
1351
- }
1352
- };
1353
-
1354
- var css_248z$1 = ".EditorPlaceholder-module_editor{margin:20px 0 10px;position:relative;user-select:none;width:100%}.EditorPlaceholder-module_content{align-items:center;background-color:#efefef;border:none;border-radius:3px;color:rgba(55,53,47,.65);cursor:pointer;display:flex;font-size:14px;overflow:hidden;padding:12px 36px 12px 12px;position:relative;text-align:left;transition:background-color .1s ease-in;width:100%}.EditorPlaceholder-module_content:hover{background-color:#e3e3e3}.EditorPlaceholder-module_icon{margin-right:8px;user-select:none}";
1355
- var s$1 = {"editor":"EditorPlaceholder-module_editor","content":"EditorPlaceholder-module_content","icon":"EditorPlaceholder-module_icon"};
1356
- styleInject(css_248z$1);
1357
-
1358
- const getYoutubeId = (url) => {
1359
- const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
1360
- const match = url.match(regExp);
1361
- return match && match[2].length === 11 ? match[2] : null;
1362
- };
1363
- const getVimeoId = (url) => {
1364
- const vimeoUrl = new URL(url);
1365
- const vimeoVideoId = vimeoUrl.pathname.split('/')[1];
1366
- return vimeoVideoId;
1367
- };
1368
- const getDailymotionId = (url) => {
1369
- var m = url.match(/^.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/);
1370
- if (m !== null) {
1371
- if (m[4] !== undefined) {
1372
- return m[4];
1373
- }
1374
- return m[2];
1375
- }
1376
- return null;
1377
- };
1378
- function getTwitterEmbedId(url) {
1379
- const match = url.match(/\/status\/(\d+)/);
1380
- if (match) {
1381
- return match[1];
1382
- }
1383
- return null;
1384
- }
1385
- function getFigmaUrl(url) {
1386
- const search = new URL(url).searchParams;
1387
- const nodeId = search.get('node-id');
1388
- if (search.get('node-id')) {
1389
- return nodeId;
1390
- }
1391
- return 'unknown';
1392
- }
1393
- function getProvider(url) {
1394
- if (url.includes('youtube.com') || url.includes('youtu.be')) {
1395
- return 'youtube';
1396
- }
1397
- else if (url.includes('vimeo.com')) {
1398
- return 'vimeo';
1399
- }
1400
- else if (url.includes('dailymotion.com') || url.includes('dai.ly')) {
1401
- return 'dailymotion';
1402
- }
1403
- else if (url.includes('twitter')) {
1404
- return 'twitter';
1405
- }
1406
- else if (url.includes('figma')) {
1407
- return 'figma';
1408
- }
1409
- else {
1410
- return null;
1411
- }
1412
- }
1413
-
1414
- const UPLOADER_HEIGHT = 88;
1415
- const EditorPlaceholder = ({ element, attributes, maxSizes, children, editor }) => {
1416
- const [uploaderPos, setUploaderPos] = useState(null);
1417
- const imageEditorRef = useRef(null);
1418
- const toggleUploaderOpen = (e) => {
1419
- var _a;
1420
- e.stopPropagation();
1421
- if (uploaderPos !== null) {
1422
- enableBodyScroll(document.body);
1423
- setUploaderPos(null);
1424
- return;
1425
- }
1426
- const imageEditorRect = (_a = imageEditorRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
1427
- if (imageEditorRect) {
1428
- const showAtTop = imageEditorRect.top + imageEditorRect.height + UPLOADER_HEIGHT + 20 > window.innerHeight;
1429
- const showAtBottom = !showAtTop;
1430
- console.log({ showAtTop, showAtBottom });
1431
- disableBodyScroll(document.body, { reserveScrollBarGap: true });
1432
- setUploaderPos({
1433
- left: imageEditorRect.left,
1434
- top: showAtTop ? imageEditorRect.top - UPLOADER_HEIGHT - 5 : imageEditorRect.top + imageEditorRect.height + 5,
1435
- });
1436
- }
1437
- };
1438
- const onEmbed = (src) => __awaiter(void 0, void 0, void 0, function* () {
1439
- if (src.length === 0)
1440
- return;
1441
- const provider = getProvider(src);
1442
- let providerId = null;
1443
- if (provider === 'youtube')
1444
- providerId = getYoutubeId(src);
1445
- else if (provider === 'vimeo')
1446
- providerId = getVimeoId(src);
1447
- else if (provider === 'dailymotion')
1448
- providerId = getDailymotionId(src);
1449
- else if (provider === 'twitter')
1450
- providerId = getTwitterEmbedId(src);
1451
- else if (provider === 'figma')
1452
- providerId = getFigmaUrl(src);
1453
- console.log({ provider, providerId });
1454
- try {
1455
- enableBodyScroll(document.body);
1456
- setUploaderPos(null);
1457
- const updatedEmbedNode = {
1458
- data: Object.assign(Object.assign({}, element.data), { url: src, size: { width: element.data.size.width, height: element.data.size.height }, provider: provider, providerId }),
1459
- };
1460
- Transforms.setNodes(editor, updatedEmbedNode, {
1461
- at: ReactEditor.findPath(editor, element),
1462
- match: (n) => Element.isElement(n) && n.type === 'embed',
1463
- });
1464
- }
1465
- catch (error) {
1466
- enableBodyScroll(document.body);
1467
- setUploaderPos(null);
1468
- }
1469
- });
1470
- return (jsxs("div", Object.assign({ className: s$1.editor }, attributes, { contentEditable: false }, { children: [jsxs("div", Object.assign({ ref: imageEditorRef }, { children: [jsxs("button", Object.assign({ className: s$1.content, onClick: toggleUploaderOpen }, { children: [jsx(SvgUpload, { className: s$1.icon, width: 24, height: 24 }), jsx("span", { children: "Click to add embed" })] })), uploaderPos !== null && jsx(EditorUploader, { onEmbed: onEmbed, onClose: toggleUploaderOpen, style: uploaderPos })] })), children] })));
1471
- };
1472
-
1473
- var css_248z = ".EmbedEditor-module_root{cursor:pointer;display:block;position:relative}.EmbedEditor-module_root:hover .EmbedEditor-module_dotsOptions,.EmbedEditor-module_root:hover .EmbedEditor-module_resizer{opacity:1}.EmbedEditor-module_loadingState{pointer-events:none}.EmbedEditor-module_extraMargin{margin:20px 0 30px}.EmbedEditor-module_resizeLib{margin:0 auto}.EmbedEditor-module_resizer{align-items:center;cursor:col-resize;display:flex;height:100%;justify-content:center;opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;width:15px;z-index:1}.EmbedEditor-module_leftResizer{left:0;top:0}.EmbedEditor-module_rightResizer{right:0;top:0}.EmbedEditor-module_resizeItem{background:hsla(0,0%,6%,.6);border:1px solid hsla(0,0%,100%,.9);border-radius:20px;box-shadow:0 0 0 .5px #fff;height:48px;max-height:50%;opacity:1;transition:opacity .3s ease-in 0s;width:6px}.EmbedEditor-module_selectImg{opacity:0}.EmbedEditor-module_selected{background:rgba(35,131,226,.14);border-radius:3px;inset:0;opacity:1;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;z-index:81}.EmbedEditor-module_loader{left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}.EmbedEditor-module_dotsOptions{align-items:center;background-color:#eee;border:none;border-radius:2px;cursor:pointer;display:flex;height:22px;justify-content:space-between;opacity:0;padding:0 4px;position:absolute;right:10px;top:10px;transition:opacity .15s ease-in 0s;width:22px;z-index:1}.EmbedEditor-module_dot{background-color:gray;border-radius:50%;min-height:3px;min-width:3px}";
1474
- var s = {"root":"EmbedEditor-module_root","resizer":"EmbedEditor-module_resizer","dotsOptions":"EmbedEditor-module_dotsOptions","loadingState":"EmbedEditor-module_loadingState","extraMargin":"EmbedEditor-module_extraMargin","resizeLib":"EmbedEditor-module_resizeLib","leftResizer":"EmbedEditor-module_leftResizer EmbedEditor-module_resizer","rightResizer":"EmbedEditor-module_rightResizer EmbedEditor-module_resizer","resizeItem":"EmbedEditor-module_resizeItem","selectImg":"EmbedEditor-module_selectImg","selected":"EmbedEditor-module_selected","loader":"EmbedEditor-module_loader","dot":"EmbedEditor-module_dot"};
1475
- styleInject(css_248z);
1476
-
1477
- const OPTIONS_WIDTH = 265;
1478
- const EmbedEditorFactory = (editor, plugin) => (props) => jsx(EmbedEditor, Object.assign({ editor: editor, plugin: plugin }, props));
1479
- function EmbedEditor(props) {
1480
- var _a, _b, _c, _d, _e;
1481
- const { element, editor, plugin } = props;
1482
- const selected = useSelected();
1483
- const readOnly = useReadOnly();
1484
- const [optionsPos, setOptionsPos] = useState(null);
1485
- const [size, setSize] = useState({
1486
- width: ((_b = (_a = element.data) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 750,
1487
- height: ((_d = (_c = element.data) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.height) || 440,
1488
- });
1489
- const updateSize = (updatedSize) => setSize(Object.assign(Object.assign({}, size), updatedSize));
1490
- useEffect(() => {
1491
- var _a, _b, _c, _d;
1492
- if (element.data) {
1493
- updateSize({
1494
- width: ((_b = (_a = element.data) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 750,
1495
- height: ((_d = (_c = element.data) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.height) || 440,
1496
- });
1497
- }
1498
- }, [(_e = element.data) === null || _e === void 0 ? void 0 : _e.size]);
1499
- const resizeProps = useMemo(() => {
1500
- var _a, _b;
1501
- return ({
1502
- minWidth: 300,
1503
- size: { width: size.width, height: size.height },
1504
- maxWidth: ((_a = plugin.options) === null || _a === void 0 ? void 0 : _a.maxWidth) || 800,
1505
- maxHeight: ((_b = plugin.options) === null || _b === void 0 ? void 0 : _b.maxHeight) || 720,
1506
- lockAspectRatio: true,
1507
- resizeRatio: 2,
1508
- enable: {
1509
- left: !readOnly,
1510
- right: !readOnly,
1511
- },
1512
- handleStyles: {
1513
- left: { left: 0 },
1514
- right: { right: 0 },
1515
- },
1516
- onResize: (e, direction, ref) => {
1517
- updateSize({ width: ref.offsetWidth, height: ref.offsetHeight });
1518
- },
1519
- onResizeStop: (e, direction, ref) => {
1520
- console.log('image editor editor.children', editor.children);
1521
- console.log('ReactEditor.findPath(editor, element)', ReactEditor.findPath(editor, element));
1522
- console.log('element', element);
1523
- Transforms.setNodes(editor, { data: Object.assign(Object.assign({}, element.data), { size: { width: ref.offsetWidth, height: ref.offsetHeight } }) }, {
1524
- at: ReactEditor.findPath(editor, element),
1525
- match: (n) => Element.isElement(n) && n.type === 'embed',
1526
- });
1527
- },
1528
- handleComponent: {
1529
- left: (jsx("div", Object.assign({ contentEditable: false, className: s.leftResizer }, { children: jsx("div", { className: s.resizeItem }) }))),
1530
- right: (jsx("div", Object.assign({ contentEditable: false, className: s.rightResizer }, { children: jsx("div", { className: s.resizeItem }) }))),
1531
- },
1532
- });
1533
- }, [size.width, size.height, editor]);
1534
- const closeOptions = () => {
1535
- enableBodyScroll(document.body);
1536
- setOptionsPos(null);
1537
- };
1538
- const toggleOptionsOpen = (e) => {
1539
- var _a;
1540
- e === null || e === void 0 ? void 0 : e.stopPropagation();
1541
- if (optionsPos !== null) {
1542
- return closeOptions();
1543
- }
1544
- const optionsButtonRect = (_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
1545
- const UPLOADER_HEIGHT = 164;
1546
- if (optionsButtonRect) {
1547
- const showAtTop = optionsButtonRect.top + optionsButtonRect.height + UPLOADER_HEIGHT + 20 > window.innerHeight;
1548
- disableBodyScroll(document.body, { reserveScrollBarGap: true });
1549
- setOptionsPos({
1550
- left: optionsButtonRect.right - optionsButtonRect.width + OPTIONS_WIDTH > window.innerWidth
1551
- ? window.innerWidth - OPTIONS_WIDTH - optionsButtonRect.width
1552
- : optionsButtonRect.right - optionsButtonRect.width,
1553
- top: showAtTop
1554
- ? optionsButtonRect.top - UPLOADER_HEIGHT / 2 - optionsButtonRect.height
1555
- : optionsButtonRect.top + optionsButtonRect.height + 5,
1556
- });
1557
- }
1558
- };
1559
- if (!element.data.url && !element.data['data-src']) {
1560
- const { maxWidth = 750, maxHeight = 800 } = plugin.options || {};
1561
- return (jsxs("div", Object.assign({ className: s.root, contentEditable: false, draggable: false }, { children: [jsx("div", { className: cx(s.selectImg, { [s.selected]: selected }) }), jsx(EditorPlaceholder, Object.assign({ attributes: props.attributes, element: element, editor: editor, maxSizes: { maxWidth, maxHeight } }, { children: !readOnly && (jsxs("div", { children: [jsxs("button", Object.assign({ type: "button", className: s.dotsOptions, onClick: toggleOptionsOpen }, { children: [jsx("span", { className: s.dot }), jsx("span", { className: s.dot }), jsx("span", { className: s.dot })] })), optionsPos !== null && (jsx(UI_HELPERS.ElementOptions, { onClose: closeOptions, style: optionsPos, element: element, onCopy: closeOptions, onDelete: closeOptions, onDuplicate: closeOptions }, element.id))] })) })), props.children] }), element.id));
1562
- }
1563
- return (jsx("div", Object.assign({ contentEditable: false, draggable: false, className: s.root }, { children: jsxs(Resizable, Object.assign({}, resizeProps, { className: s.resizeLib }, { children: [plugin.renderer.render(Object.assign(Object.assign({}, props), { size })), jsx("div", { className: cx(s.selectImg, { [s.selected]: selected }) }), !readOnly && (jsxs("div", { children: [jsxs("button", Object.assign({ type: "button", className: s.dotsOptions, onClick: toggleOptionsOpen }, { children: [jsx("span", { className: s.dot }), jsx("span", { className: s.dot }), jsx("span", { className: s.dot })] })), optionsPos !== null && (jsx(UI_HELPERS.ElementOptions, { onClose: closeOptions, style: optionsPos, element: element, onCopy: closeOptions, onDelete: closeOptions, onDuplicate: closeOptions }, element.id))] }))] })) }), element.id));
1564
- }
1565
-
1566
- const Embed = createYooptaPlugin({
1567
- type: 'embed',
1568
- shortcut: 'embed',
1569
- renderer: {
1570
- // @ts-ignore [TODO: fix types]
1571
- editor: EmbedEditorFactory,
1572
- render: Embed$1,
1573
- },
1574
- extendEditor(editor) {
1575
- const { isVoid } = editor;
1576
- editor.isVoid = (element) => {
1577
- return element.type === Embed.getPlugin.type ? true : isVoid(element);
1578
- };
1579
- return editor;
1580
- },
1581
- events: {
1582
- onKeyDown: (editor, { defaultNode, hotkeys }) => (event) => {
1583
- var _a;
1584
- const currentNode = getElementByPath(editor, (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor.path, 'highest');
1585
- if (currentNode.type !== 'embed' || !editor.selection)
1586
- return;
1587
- if (hotkeys.isEnter(event)) {
1588
- event.preventDefault();
1589
- Transforms.insertNodes(editor, defaultNode, { mode: 'highest' });
1590
- return;
1591
- }
1592
- },
1593
- },
1594
- defineElement: () => ({
1595
- id: generateId(),
1596
- type: 'embed',
1597
- nodeType: 'void',
1598
- data: { url: null, size: { width: 'auto', height: 'auto' }, providerId: null },
1599
- children: [{ text: '' }],
1600
- }),
1601
- createElement: (editor, elementData) => {
1602
- var _a;
1603
- const node = Object.assign(Object.assign({}, Embed.getPlugin.defineElement()), elementData);
1604
- Transforms.setNodes(editor, node, {
1605
- at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
1606
- });
1607
- },
1608
- exports: {
1609
- markdown: {
1610
- serialize: (node, text) => {
1611
- return `[embed-url](${node.data.url})\n`;
1612
- },
1613
- },
1614
- html: {
1615
- serialize: (node, children) => {
1616
- var _a, _b;
1617
- return `<iframe src="https://player.vimeo.com/video/807053663?badge=0&amp;byline=0&amp;portrait=0&amp;title=0" frameborder="0" height="${(_a = node.data.size) === null || _a === void 0 ? void 0 : _a.height}" width="${(_b = node.data.size) === null || _b === void 0 ? void 0 : _b.width}" allowfullscreen="" url="https://vimeo.com/807053663" provider="${node.data.provider || ''}" />`;
1618
- },
1619
- deserialize: {
1620
- nodeName: 'IFRAME',
1621
- parse: (el) => ({
1622
- url: el.getAttribute('src'),
1623
- size: {
1624
- height: typeof el.getAttribute('height') === 'string' ? Number(el.getAttribute('height')) : 'auto',
1625
- width: typeof el.getAttribute('width') === 'string' ? Number(el.getAttribute('width')) : 'auto',
1626
- },
1627
- }),
1628
- },
1629
- },
1630
- },
1631
- options: {
1632
- searchString: 'Embed media',
1633
- displayLabel: 'Embed',
1634
- },
1635
- });
1636
-
1637
- export { Embed as default };
1
+ import{getElementClassname as e,UI_HELPERS as t,cx as i,createYooptaPlugin as o,getElementByPath as n,generateId as s}from"@yoopta/editor";import{Transforms as r,Element as a}from"slate";import{jsx as d,jsxs as l}from"react/jsx-runtime";import*as h from"react";import{useState as c,useEffect as p,useRef as u,useMemo as g}from"react";import{flushSync as m}from"react-dom";import{ReactEditor as f,useSelected as v,useReadOnly as b}from"slate-react";function w(e,t){var i={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(i[o[n]]=e[o[n]])}return i}function y(e,t,i,o){return new(i||(i=Promise))((function(n,s){function r(e){try{d(o.next(e))}catch(e){s(e)}}function a(e){try{d(o.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}d((o=o.apply(e,t||[])).next())}))}function x(e,{threshold:t=0,root:i=null,rootMargin:o="0%",freezeOnceVisible:n=!1}={}){const[s,r]=c({}),a=s.isIntersecting&&n,d=([e])=>r(e);return p((()=>{const n=null==e?void 0:e.current;if(!window.IntersectionObserver||a||!n)return;const s=new IntersectionObserver(d,{threshold:t,root:i,rootMargin:o});return s.observe(n),()=>s.disconnect()}),[e,t,i,o,a]),s}function z(e,t){void 0===t&&(t={});var i=t.insertAt;if(e&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&o.firstChild?o.insertBefore(n,o.firstChild):o.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}var O={root:"ypSFFbjd",iframe:"DQszzmj7",container:"yc58m72J",iframePreview:"DYsS-Bbu",embed:"a1CpYHeG"};z(".ypSFFbjd{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.DQszzmj7{background-color:#fff}.DQszzmj7,.yc58m72J{border-radius:1px;height:100%;pointer-events:auto;width:100%}.DQszzmj7,.DYsS-Bbu,.yc58m72J{left:0;position:absolute;top:0}.DYsS-Bbu{filter:blur(10px);object-fit:cover;transition:opacity .15s ease-in,filter .15s ease-in}.a1CpYHeG{height:100%;position:relative;width:100%}");const S=e=>`https://api.dailymotion.com/video/${e}?fields=thumbnail_url`;var N={root:"C8Z8IWw5",iframe:"aGHn-pry",container:"-qZtVrzy",iframePreview:"kmC7RiaF",embed:"srCuArtd"};function j(e){var{providerId:t,url:i}=e;w(e,["providerId","url"]);const o=u(null),{isIntersecting:n}=x(o,{freezeOnceVisible:!0,rootMargin:"50%"});return d("div",Object.assign({className:N.root,ref:o},{children:d("div",Object.assign({className:N.container},{children:d("div",Object.assign({className:N.embed},{children:n&&d("iframe",{src:i,frameBorder:0,allowFullScreen:!0,className:N.iframe,height:"450px"})}))}))}))}z(".C8Z8IWw5{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.aGHn-pry{background-color:#fff}.-qZtVrzy,.aGHn-pry{border-radius:1px;height:100%;pointer-events:auto;width:100%}.-qZtVrzy,.aGHn-pry,.kmC7RiaF{left:0;position:absolute;top:0}.kmC7RiaF{filter:blur(10px);object-fit:cover;transition:opacity .15s ease-in,filter .15s ease-in}.srCuArtd{height:100%;position:relative;width:100%}");var R={root:"w4l4tKlB",iframe:"cbJcegGv",container:"g8V-uGLl",iframePreview:"hZuYZ7vp",embed:"j6pRoOC1"};z(".w4l4tKlB{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.cbJcegGv{background-color:#fff}.cbJcegGv,.g8V-uGLl{border-radius:1px;height:100%;pointer-events:auto;width:100%}.cbJcegGv,.g8V-uGLl,.hZuYZ7vp{left:0;position:absolute;top:0}.hZuYZ7vp{filter:blur(10px);object-fit:cover;transition:opacity .15s ease-in,filter .15s ease-in}.j6pRoOC1{height:100%;position:relative;width:100%}");var E={root:"e3lQDjTT",iframe:"O5Z0OWN-",container:"zxjqcq4y",iframePreview:"_5kC3Lf5J",embed:"ymOgdXs4"};z(".e3lQDjTT{display:flex;height:100%;justify-content:center;min-height:100px;padding-bottom:86%;position:relative;width:100%}.O5Z0OWN-{background-color:#fff}.O5Z0OWN-,.zxjqcq4y{border-radius:1px;height:100%;left:0;pointer-events:auto;position:absolute;top:0;width:100%}._5kC3Lf5J{filter:blur(10px);left:0;object-fit:cover;position:absolute;top:0;transition:opacity .15s ease-in,filter .15s ease-in}.ymOgdXs4{position:relative;width:100%}.ymOgdXs4,.ymOgdXs4>div,.ymOgdXs4>div>div{height:100%}.ymOgdXs4 iframe{height:100%!important;width:100%!important}");var W={root:"sD5QN14F",iframe:"mRrF4hwM",container:"LyyH1fsE",iframePreview:"U9EPxemn",embed:"_4AQiBYad"};z(".sD5QN14F{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.mRrF4hwM{background-color:#fff}.LyyH1fsE,.mRrF4hwM{border-radius:1px;height:100%;pointer-events:auto;width:100%}.LyyH1fsE,.U9EPxemn,.mRrF4hwM{left:0;position:absolute;top:0}.U9EPxemn{filter:blur(10px);object-fit:cover;transition:opacity .15s ease-in,filter .15s ease-in}._4AQiBYad{height:100%;position:relative;width:100%}");const H="https://vimeo.com/api/v2/video";var L={root:"zoqyIXwI",iframe:"WgoSECbO",container:"m07CnIxO",iframePreview:"NSr-cxfm",embed:"Cv1rIJbN"};z(".zoqyIXwI{display:flex;height:0;justify-content:center;min-height:100px;padding-bottom:56.25%;position:relative;width:100%}.WgoSECbO{background-color:#fff}.WgoSECbO,.m07CnIxO{border-radius:1px;height:100%;pointer-events:auto;width:100%}.NSr-cxfm,.WgoSECbO,.m07CnIxO{left:0;position:absolute;top:0}.NSr-cxfm{filter:blur(10px);object-fit:cover;transition:opacity .15s ease-in,filter .15s ease-in}.Cv1rIJbN{height:100%;position:relative;width:100%}");var P="HUtGPcJq";z(".HUtGPcJq{margin:20px 0 10px;position:relative}");const C={vimeo:function(e){var{providerId:t}=e,i=w(e,["providerId"]);const o=u(null),[n,s]=c(null),[r,a]=c(!1),{isIntersecting:h}=x(o,{freezeOnceVisible:!0,rootMargin:"50%"});return p((()=>{fetch(`${H}/${t}.json`).then((e=>e.json())).then((e=>s(e[0].thumbnail_medium))).catch((()=>s(null)))}),[t]),d("div",Object.assign({className:W.root,ref:o},{children:d("div",Object.assign({className:W.container},{children:l("div",Object.assign({className:W.embed},{children:[d("img",{src:n||"",alt:"vimeo_video_preview",width:"100%",height:"100%",className:W.iframePreview,style:{opacity:h&&r?0:1,zIndex:h&&r?-1:0}}),h&&d("iframe",Object.assign({title:"Vimeo Player",src:`https://player.vimeo.com/video/${t}?badge=0&byline=0&portrait=0&title=0`,frameBorder:0,allowFullScreen:!0,onLoad:()=>a(!0),className:W.iframe},i))]}))}))}))},youtube:function(e){var{providerId:t}=e,i=w(e,["providerId"]);const o=u(null),[n,s]=c(!1),{isIntersecting:r}=x(o,{freezeOnceVisible:!0,rootMargin:"50%"});return d("div",Object.assign({className:L.root,ref:o},{children:d("div",Object.assign({className:L.container},{children:l("div",Object.assign({className:L.embed},{children:[d("img",{src:`https://i.ytimg.com/vi/${t}/default.jpg`,alt:"youtube_video_preview",width:"100%",height:"100%",className:L.iframePreview,style:{opacity:r&&n?0:1,zIndex:r&&n?-1:0}}),r&&d("iframe",Object.assign({title:"Youtube Player",src:`https://www.youtube.com/embed/${t}?hl=no&rel=0`,frameBorder:0,onLoad:()=>s(!0),allowFullScreen:!0,className:L.iframe},i))]}))}))}))},dailymotion:function(e){var{providerId:t}=e,i=w(e,["providerId"]);const o=u(null),[n,s]=c(null),[r,a]=c(!1),{isIntersecting:h}=x(o,{freezeOnceVisible:!0,rootMargin:"50%"});return p((()=>{fetch(S(t)).then((e=>e.json())).then((e=>s(e.thumbnail_url))).catch((()=>s(null)))}),[t]),d("div",Object.assign({className:O.root,ref:o},{children:d("div",Object.assign({className:O.container},{children:l("div",Object.assign({className:O.embed},{children:[d("img",{src:n||"",alt:"daylimotion_video_preview",width:"100%",height:"100%",className:O.iframePreview,style:{opacity:h&&r?0:1,zIndex:h&&r?-1:0}}),h&&d("iframe",Object.assign({title:"Dailymotion Video Player",frameBorder:0,onLoad:()=>a(!0),src:`https://www.dailymotion.com/embed/video/${t}`,allowFullScreen:!0,className:O.iframe},i))]}))}))}))},twitter:function({providerId:e}){const t=u(null),{isIntersecting:i}=x(t,{freezeOnceVisible:!0,rootMargin:"50%"});return p((()=>{var o;if(!i)return;const n=document.createElement("script");n.src="https://platform.twitter.com/widgets.js",null===(o=t.current)||void 0===o||o.appendChild(n),n.onload=()=>{window.twttr&&window.twttr.widgets.createTweet(e,document.getElementById(e),{align:"center",conversation:"none",dnt:!0,theme:"dark",height:300})}}),[e,i]),d("div",Object.assign({className:E.root,ref:t},{children:d("div",Object.assign({className:E.container},{children:d("div",Object.assign({className:E.embed},{children:d("div",{id:e})}))}))}))},figma:function(e){var{providerId:t,url:i}=e;w(e,["providerId","url"]);const o=u(null),{isIntersecting:n}=x(o,{freezeOnceVisible:!0,rootMargin:"50%"});return d("div",Object.assign({className:R.root,ref:o},{children:d("div",Object.assign({className:R.container},{children:d("div",Object.assign({className:R.embed},{children:n&&d("iframe",{src:`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(i)}`,frameBorder:0,allowFullScreen:!0,className:R.iframe,height:"450px"})}))}))}))}};var k,M,B=(k=function(e,t){return k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},k(e,t)},function(e,t){function i(){this.constructor=e}k(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}),I=function(){return I=Object.assign||function(e){for(var t,i=1,o=arguments.length;i<o;i++)for(var n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},I.apply(this,arguments)},_={width:"100%",height:"10px",top:"0px",left:"0px",cursor:"row-resize"},A={width:"10px",height:"100%",top:"0px",left:"0px",cursor:"col-resize"},V={width:"20px",height:"20px",position:"absolute"},T={top:I(I({},_),{top:"-5px"}),right:I(I({},A),{left:void 0,right:"-5px"}),bottom:I(I({},_),{top:void 0,bottom:"-5px"}),left:I(I({},A),{left:"-5px"}),topRight:I(I({},V),{right:"-10px",top:"-10px",cursor:"ne-resize"}),bottomRight:I(I({},V),{right:"-10px",bottom:"-10px",cursor:"se-resize"}),bottomLeft:I(I({},V),{left:"-10px",bottom:"-10px",cursor:"sw-resize"}),topLeft:I(I({},V),{left:"-10px",top:"-10px",cursor:"nw-resize"})},F=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.onMouseDown=function(e){t.props.onResizeStart(e,t.props.direction)},t.onTouchStart=function(e){t.props.onResizeStart(e,t.props.direction)},t}return B(t,e),t.prototype.render=function(){return h.createElement("div",{className:this.props.className||"",style:I(I({position:"absolute",userSelect:"none"},T[this.props.direction]),this.props.replaceStyles||{}),onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart},this.props.children)},t}(h.PureComponent),G=function(){var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};return function(t,i){function o(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}}(),U=function(){return U=Object.assign||function(e){for(var t,i=1,o=arguments.length;i<o;i++)for(var n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},U.apply(this,arguments)},D={width:"auto",height:"auto"},Y=function(e,t,i){return Math.max(Math.min(e,i),t)},Z=function(e,t){return Math.round(e/t)*t},q=function(e,t){return new RegExp(e,"i").test(t)},J=function(e){return Boolean(e.touches&&e.touches.length)},X=function(e,t,i){void 0===i&&(i=0);var o=t.reduce((function(i,o,n){return Math.abs(o-e)<Math.abs(t[i]-e)?n:i}),0),n=Math.abs(t[o]-e);return 0===i||n<i?t[o]:e},Q=function(e){return"auto"===(e=e.toString())||e.endsWith("px")||e.endsWith("%")||e.endsWith("vh")||e.endsWith("vw")||e.endsWith("vmax")||e.endsWith("vmin")?e:e+"px"},$=function(e,t,i,o){if(e&&"string"==typeof e){if(e.endsWith("px"))return Number(e.replace("px",""));if(e.endsWith("%"))return t*(Number(e.replace("%",""))/100);if(e.endsWith("vw"))return i*(Number(e.replace("vw",""))/100);if(e.endsWith("vh"))return o*(Number(e.replace("vh",""))/100)}return e},K=["as","style","className","grid","snap","bounds","boundsByDirection","size","defaultSize","minWidth","minHeight","maxWidth","maxHeight","lockAspectRatio","lockAspectRatioExtraWidth","lockAspectRatioExtraHeight","enable","handleStyles","handleClasses","handleWrapperStyle","handleWrapperClass","children","onResizeStart","onResize","onResizeStop","handleComponent","scale","resizeRatio","snapGap"],ee="__resizable_base__",te=function(e){function t(t){var i=e.call(this,t)||this;return i.ratio=1,i.resizable=null,i.parentLeft=0,i.parentTop=0,i.resizableLeft=0,i.resizableRight=0,i.resizableTop=0,i.resizableBottom=0,i.targetLeft=0,i.targetTop=0,i.appendBase=function(){if(!i.resizable||!i.window)return null;var e=i.parentNode;if(!e)return null;var t=i.window.document.createElement("div");return t.style.width="100%",t.style.height="100%",t.style.position="absolute",t.style.transform="scale(0, 0)",t.style.left="0",t.style.flex="0 0 100%",t.classList?t.classList.add(ee):t.className+=ee,e.appendChild(t),t},i.removeBase=function(e){var t=i.parentNode;t&&t.removeChild(e)},i.ref=function(e){e&&(i.resizable=e)},i.state={isResizing:!1,width:void 0===(i.propsSize&&i.propsSize.width)?"auto":i.propsSize&&i.propsSize.width,height:void 0===(i.propsSize&&i.propsSize.height)?"auto":i.propsSize&&i.propsSize.height,direction:"right",original:{x:0,y:0,width:0,height:0},backgroundStyle:{height:"100%",width:"100%",backgroundColor:"rgba(0,0,0,0)",cursor:"auto",opacity:0,position:"fixed",zIndex:9999,top:"0",left:"0",bottom:"0",right:"0"},flexBasis:void 0},i.onResizeStart=i.onResizeStart.bind(i),i.onMouseMove=i.onMouseMove.bind(i),i.onMouseUp=i.onMouseUp.bind(i),i}return G(t,e),Object.defineProperty(t.prototype,"parentNode",{get:function(){return this.resizable?this.resizable.parentNode:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"window",{get:function(){return this.resizable&&this.resizable.ownerDocument?this.resizable.ownerDocument.defaultView:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"propsSize",{get:function(){return this.props.size||this.props.defaultSize||D},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){var e=0,t=0;if(this.resizable&&this.window){var i=this.resizable.offsetWidth,o=this.resizable.offsetHeight,n=this.resizable.style.position;"relative"!==n&&(this.resizable.style.position="relative"),e="auto"!==this.resizable.style.width?this.resizable.offsetWidth:i,t="auto"!==this.resizable.style.height?this.resizable.offsetHeight:o,this.resizable.style.position=n}return{width:e,height:t}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeStyle",{get:function(){var e=this,t=this.props.size,i=function(t){if(void 0===e.state[t]||"auto"===e.state[t])return"auto";if(e.propsSize&&e.propsSize[t]&&e.propsSize[t].toString().endsWith("%")){if(e.state[t].toString().endsWith("%"))return e.state[t].toString();var i=e.getParentSize();return Number(e.state[t].toString().replace("px",""))/i[t]*100+"%"}return Q(e.state[t])};return{width:t&&void 0!==t.width&&!this.state.isResizing?Q(t.width):i("width"),height:t&&void 0!==t.height&&!this.state.isResizing?Q(t.height):i("height")}},enumerable:!1,configurable:!0}),t.prototype.getParentSize=function(){if(!this.parentNode)return this.window?{width:this.window.innerWidth,height:this.window.innerHeight}:{width:0,height:0};var e=this.appendBase();if(!e)return{width:0,height:0};var t=!1,i=this.parentNode.style.flexWrap;"wrap"!==i&&(t=!0,this.parentNode.style.flexWrap="wrap"),e.style.position="relative",e.style.minWidth="100%",e.style.minHeight="100%";var o={width:e.offsetWidth,height:e.offsetHeight};return t&&(this.parentNode.style.flexWrap=i),this.removeBase(e),o},t.prototype.bindEvents=function(){this.window&&(this.window.addEventListener("mouseup",this.onMouseUp),this.window.addEventListener("mousemove",this.onMouseMove),this.window.addEventListener("mouseleave",this.onMouseUp),this.window.addEventListener("touchmove",this.onMouseMove,{capture:!0,passive:!1}),this.window.addEventListener("touchend",this.onMouseUp))},t.prototype.unbindEvents=function(){this.window&&(this.window.removeEventListener("mouseup",this.onMouseUp),this.window.removeEventListener("mousemove",this.onMouseMove),this.window.removeEventListener("mouseleave",this.onMouseUp),this.window.removeEventListener("touchmove",this.onMouseMove,!0),this.window.removeEventListener("touchend",this.onMouseUp))},t.prototype.componentDidMount=function(){if(this.resizable&&this.window){var e=this.window.getComputedStyle(this.resizable);this.setState({width:this.state.width||this.size.width,height:this.state.height||this.size.height,flexBasis:"auto"!==e.flexBasis?e.flexBasis:void 0})}},t.prototype.componentWillUnmount=function(){this.window&&this.unbindEvents()},t.prototype.createSizeForCssProperty=function(e,t){var i=this.propsSize&&this.propsSize[t];return"auto"!==this.state[t]||this.state.original[t]!==e||void 0!==i&&"auto"!==i?e:"auto"},t.prototype.calculateNewMaxFromBoundary=function(e,t){var i,o,n=this.props.boundsByDirection,s=this.state.direction,r=n&&q("left",s),a=n&&q("top",s);if("parent"===this.props.bounds){var d=this.parentNode;d&&(i=r?this.resizableRight-this.parentLeft:d.offsetWidth+(this.parentLeft-this.resizableLeft),o=a?this.resizableBottom-this.parentTop:d.offsetHeight+(this.parentTop-this.resizableTop))}else"window"===this.props.bounds?this.window&&(i=r?this.resizableRight:this.window.innerWidth-this.resizableLeft,o=a?this.resizableBottom:this.window.innerHeight-this.resizableTop):this.props.bounds&&(i=r?this.resizableRight-this.targetLeft:this.props.bounds.offsetWidth+(this.targetLeft-this.resizableLeft),o=a?this.resizableBottom-this.targetTop:this.props.bounds.offsetHeight+(this.targetTop-this.resizableTop));return i&&Number.isFinite(i)&&(e=e&&e<i?e:i),o&&Number.isFinite(o)&&(t=t&&t<o?t:o),{maxWidth:e,maxHeight:t}},t.prototype.calculateNewSizeFromDirection=function(e,t){var i=this.props.scale||1,o=this.props.resizeRatio||1,n=this.state,s=n.direction,r=n.original,a=this.props,d=a.lockAspectRatio,l=a.lockAspectRatioExtraHeight,h=a.lockAspectRatioExtraWidth,c=r.width,p=r.height,u=l||0,g=h||0;return q("right",s)&&(c=r.width+(e-r.x)*o/i,d&&(p=(c-g)/this.ratio+u)),q("left",s)&&(c=r.width-(e-r.x)*o/i,d&&(p=(c-g)/this.ratio+u)),q("bottom",s)&&(p=r.height+(t-r.y)*o/i,d&&(c=(p-u)*this.ratio+g)),q("top",s)&&(p=r.height-(t-r.y)*o/i,d&&(c=(p-u)*this.ratio+g)),{newWidth:c,newHeight:p}},t.prototype.calculateNewSizeFromAspectRatio=function(e,t,i,o){var n=this.props,s=n.lockAspectRatio,r=n.lockAspectRatioExtraHeight,a=n.lockAspectRatioExtraWidth,d=void 0===o.width?10:o.width,l=void 0===i.width||i.width<0?e:i.width,h=void 0===o.height?10:o.height,c=void 0===i.height||i.height<0?t:i.height,p=r||0,u=a||0;if(s){var g=(h-p)*this.ratio+u,m=(c-p)*this.ratio+u,f=(d-u)/this.ratio+p,v=(l-u)/this.ratio+p,b=Math.max(d,g),w=Math.min(l,m),y=Math.max(h,f),x=Math.min(c,v);e=Y(e,b,w),t=Y(t,y,x)}else e=Y(e,d,l),t=Y(t,h,c);return{newWidth:e,newHeight:t}},t.prototype.setBoundingClientRect=function(){if("parent"===this.props.bounds){var e=this.parentNode;if(e){var t=e.getBoundingClientRect();this.parentLeft=t.left,this.parentTop=t.top}}if(this.props.bounds&&"string"!=typeof this.props.bounds){var i=this.props.bounds.getBoundingClientRect();this.targetLeft=i.left,this.targetTop=i.top}if(this.resizable){var o=this.resizable.getBoundingClientRect(),n=o.left,s=o.top,r=o.right,a=o.bottom;this.resizableLeft=n,this.resizableRight=r,this.resizableTop=s,this.resizableBottom=a}},t.prototype.onResizeStart=function(e,t){if(this.resizable&&this.window){var i,o=0,n=0;if(e.nativeEvent&&function(e){return Boolean((e.clientX||0===e.clientX)&&(e.clientY||0===e.clientY))}(e.nativeEvent)?(o=e.nativeEvent.clientX,n=e.nativeEvent.clientY):e.nativeEvent&&J(e.nativeEvent)&&(o=e.nativeEvent.touches[0].clientX,n=e.nativeEvent.touches[0].clientY),this.props.onResizeStart)if(this.resizable)if(!1===this.props.onResizeStart(e,t,this.resizable))return;this.props.size&&(void 0!==this.props.size.height&&this.props.size.height!==this.state.height&&this.setState({height:this.props.size.height}),void 0!==this.props.size.width&&this.props.size.width!==this.state.width&&this.setState({width:this.props.size.width})),this.ratio="number"==typeof this.props.lockAspectRatio?this.props.lockAspectRatio:this.size.width/this.size.height;var s=this.window.getComputedStyle(this.resizable);if("auto"!==s.flexBasis){var r=this.parentNode;if(r){var a=this.window.getComputedStyle(r).flexDirection;this.flexDir=a.startsWith("row")?"row":"column",i=s.flexBasis}}this.setBoundingClientRect(),this.bindEvents();var d={original:{x:o,y:n,width:this.size.width,height:this.size.height},isResizing:!0,backgroundStyle:U(U({},this.state.backgroundStyle),{cursor:this.window.getComputedStyle(e.target).cursor||"auto"}),direction:t,flexBasis:i};this.setState(d)}},t.prototype.onMouseMove=function(e){var t=this;if(this.state.isResizing&&this.resizable&&this.window){if(this.window.TouchEvent&&J(e))try{e.preventDefault(),e.stopPropagation()}catch(e){}var i=this.props,o=i.maxWidth,n=i.maxHeight,s=i.minWidth,r=i.minHeight,a=J(e)?e.touches[0].clientX:e.clientX,d=J(e)?e.touches[0].clientY:e.clientY,l=this.state,h=l.direction,c=l.original,p=l.width,u=l.height,g=this.getParentSize(),f=function(e,t,i,o,n,s,r){return o=$(o,e.width,t,i),n=$(n,e.height,t,i),s=$(s,e.width,t,i),r=$(r,e.height,t,i),{maxWidth:void 0===o?void 0:Number(o),maxHeight:void 0===n?void 0:Number(n),minWidth:void 0===s?void 0:Number(s),minHeight:void 0===r?void 0:Number(r)}}(g,this.window.innerWidth,this.window.innerHeight,o,n,s,r);o=f.maxWidth,n=f.maxHeight,s=f.minWidth,r=f.minHeight;var v=this.calculateNewSizeFromDirection(a,d),b=v.newHeight,w=v.newWidth,y=this.calculateNewMaxFromBoundary(o,n);this.props.snap&&this.props.snap.x&&(w=X(w,this.props.snap.x,this.props.snapGap)),this.props.snap&&this.props.snap.y&&(b=X(b,this.props.snap.y,this.props.snapGap));var x=this.calculateNewSizeFromAspectRatio(w,b,{width:y.maxWidth,height:y.maxHeight},{width:s,height:r});if(w=x.newWidth,b=x.newHeight,this.props.grid){var z=Z(w,this.props.grid[0]),O=Z(b,this.props.grid[1]),S=this.props.snapGap||0;w=0===S||Math.abs(z-w)<=S?z:w,b=0===S||Math.abs(O-b)<=S?O:b}var N={width:w-c.width,height:b-c.height};if(p&&"string"==typeof p)if(p.endsWith("%"))w=w/g.width*100+"%";else if(p.endsWith("vw")){w=w/this.window.innerWidth*100+"vw"}else if(p.endsWith("vh")){w=w/this.window.innerHeight*100+"vh"}if(u&&"string"==typeof u)if(u.endsWith("%"))b=b/g.height*100+"%";else if(u.endsWith("vw")){b=b/this.window.innerWidth*100+"vw"}else if(u.endsWith("vh")){b=b/this.window.innerHeight*100+"vh"}var j={width:this.createSizeForCssProperty(w,"width"),height:this.createSizeForCssProperty(b,"height")};"row"===this.flexDir?j.flexBasis=j.width:"column"===this.flexDir&&(j.flexBasis=j.height),m((function(){t.setState(j)})),this.props.onResize&&this.props.onResize(e,h,this.resizable,N)}},t.prototype.onMouseUp=function(e){var t=this.state,i=t.isResizing,o=t.direction,n=t.original;if(i&&this.resizable){var s={width:this.size.width-n.width,height:this.size.height-n.height};this.props.onResizeStop&&this.props.onResizeStop(e,o,this.resizable,s),this.props.size&&this.setState(this.props.size),this.unbindEvents(),this.setState({isResizing:!1,backgroundStyle:U(U({},this.state.backgroundStyle),{cursor:"auto"})})}},t.prototype.updateSize=function(e){this.setState({width:e.width,height:e.height})},t.prototype.renderResizer=function(){var e=this,t=this.props,i=t.enable,o=t.handleStyles,n=t.handleClasses,s=t.handleWrapperStyle,r=t.handleWrapperClass,a=t.handleComponent;if(!i)return null;var d=Object.keys(i).map((function(t){return!1!==i[t]?h.createElement(F,{key:t,direction:t,onResizeStart:e.onResizeStart,replaceStyles:o&&o[t],className:n&&n[t]},a&&a[t]?a[t]:null):null}));return h.createElement("div",{className:r,style:s},d)},t.prototype.render=function(){var e=this,t=Object.keys(this.props).reduce((function(t,i){return-1!==K.indexOf(i)||(t[i]=e.props[i]),t}),{}),i=U(U(U({position:"relative",userSelect:this.state.isResizing?"none":"auto"},this.props.style),this.sizeStyle),{maxWidth:this.props.maxWidth,maxHeight:this.props.maxHeight,minWidth:this.props.minWidth,minHeight:this.props.minHeight,boxSizing:"border-box",flexShrink:0});this.state.flexBasis&&(i.flexBasis=this.state.flexBasis);var o=this.props.as||"div";return h.createElement(o,U({ref:this.ref,style:i,className:this.props.className},t),this.state.isResizing&&h.createElement("div",{style:this.state.backgroundStyle}),this.props.children,this.renderResizer())},t.defaultProps={as:"div",onResizeStart:function(){},onResize:function(){},onResizeStop:function(){},enable:{top:!0,right:!0,bottom:!0,left:!0,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},style:{},grid:[1,1],lockAspectRatio:!1,lockAspectRatioExtraWidth:0,lockAspectRatioExtraHeight:0,scale:1,resizeRatio:1,snapGap:0},t}(h.PureComponent);function ie(){return ie=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(e[o]=i[o])}return e},ie.apply(this,arguments)}var oe=function(e){return h.createElement("svg",ie({fill:"currentColor","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"uploadImage"},e),M||(M=h.createElement("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"})))},ne="_5ZnGUwAU",se="wlwFaZpx",re="Obm15-qh",ae="gJ5-oVLV",de="_6jUel99o",le="HZgHUcV-",he="GF1PbH1g gU1gU-Wq",ce="i7UwLauz",pe="cJSOiHYH";z('._5ZnGUwAU{position:fixed}.wlwFaZpx{background:#fff;box-shadow:0 0 0 1px hsla(0,0%,6%,.05),0 3px 6px hsla(0,0%,6%,.1),0 9px 24px hsla(0,0%,6%,.2);display:flex;flex-direction:column;height:100%;max-height:420px;max-width:calc(100vw - 24px);min-width:540px}.Obm15-qh{box-shadow:inset 0 -1px 0 rgba(55,53,47,.09);display:flex;height:40px;padding:0 8px;width:100%;z-index:1}.Obm15-qh,.gJ5-oVLV{font-size:14px;position:relative}.gJ5-oVLV{align-items:center;background-color:inherit;border:none;border-radius:4px;color:#37352f;cursor:pointer;display:inline-flex;flex-shrink:0;height:100%;line-height:1.2;min-width:0;padding:6px 8px;transition:height 20ms ease-in 0s;user-select:none;white-space:nowrap}._6jUel99o:after{background-color:#37352f;bottom:0;content:"";height:2px;left:0;position:absolute;width:100%}.HZgHUcV-{display:flex;justify-content:center;margin-left:12px;margin-right:12px;margin-top:4px;padding-bottom:6px;padding-top:6px}.gU1gU-Wq{border:1px solid rgba(55,53,47,.16);border-radius:4px;cursor:pointer;height:32px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap;width:100%}.GF1PbH1g{border:none!important;cursor:pointer!important;height:auto!important;padding-left:0!important;padding-right:0!important}.i2lz5EKx{align-items:center;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;height:100%;justify-content:center;line-height:1.2;width:100%}._3cPFLttW{left:0;position:absolute;top:0;visibility:hidden}.i7UwLauz{background:hsla(45,13%,94%,.6);box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1);cursor:text;height:32px;line-height:20px;padding:3px 6px;position:relative}.cJSOiHYH,.i7UwLauz{align-items:center;border:none;border-radius:4px;display:flex;font-size:14px;width:100%}.cJSOiHYH{fill:#fff;background:#2383e2;box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1),0 1px 2px hsla(0,0%,6%,.1);color:#fff;cursor:pointer;flex-shrink:0;font-weight:500;height:28px;justify-content:center;line-height:1.2;margin:12px auto 6px;max-width:300px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap}');const ue=({onEmbed:e})=>{const[t,i]=c("");return l("div",Object.assign({className:he},{children:[d("input",{type:"text",placeholder:"Paste embed link",value:t,className:ce,onChange:e=>i(e.target.value)}),d("button",Object.assign({type:"button",className:pe,onClick:()=>e(t)},{children:"Embed"}))]}))},ge=({style:e,onEmbed:o,onClose:n})=>l(t.Overlay,Object.assign({onClose:n},{children:[d("div",Object.assign({className:ne,style:e},{children:l("div",Object.assign({className:se},{children:[d("div",Object.assign({className:re},{children:d("button",Object.assign({type:"button",className:i(ae,{[de]:!0})},{children:"Embed link"}))})),d("div",Object.assign({className:le},{children:d(ue,{onEmbed:o})}))]}))})),d("div",{})]}));var me=!1;if("undefined"!=typeof window){var fe={get passive(){me=!0}};window.addEventListener("testPassive",null,fe),window.removeEventListener("testPassive",null,fe)}var ve="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),be=[],we=!1,ye=-1,xe=void 0,ze=void 0,Oe=void 0,Se=function(e){return be.some((function(t){return!(!t.options.allowTouchMove||!t.options.allowTouchMove(e))}))},Ne=function(e){var t=e||window.event;return!!Se(t.target)||(t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1))},je=function(e,t){if(e){if(!be.some((function(t){return t.targetElement===e}))){var i={targetElement:e,options:t||{}};be=[].concat(function(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}return Array.from(e)}(be),[i]),ve?window.requestAnimationFrame((function(){if(void 0===ze){ze={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left};var e=window,t=e.scrollY,i=e.scrollX,o=e.innerHeight;document.body.style.position="fixed",document.body.style.top=-t,document.body.style.left=-i,setTimeout((function(){return window.requestAnimationFrame((function(){var e=o-window.innerHeight;e&&t>=o&&(document.body.style.top=-(t+e))}))}),300)}})):function(e){if(void 0===Oe){var t=!!e&&!0===e.reserveScrollBarGap,i=window.innerWidth-document.documentElement.clientWidth;if(t&&i>0){var o=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);Oe=document.body.style.paddingRight,document.body.style.paddingRight=o+i+"px"}}void 0===xe&&(xe=document.body.style.overflow,document.body.style.overflow="hidden")}(t),ve&&(e.ontouchstart=function(e){1===e.targetTouches.length&&(ye=e.targetTouches[0].clientY)},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){var i=e.targetTouches[0].clientY-ye;!Se(e.target)&&(t&&0===t.scrollTop&&i>0||function(e){return!!e&&e.scrollHeight-e.scrollTop<=e.clientHeight}(t)&&i<0?Ne(e):e.stopPropagation())}(t,e)},we||(document.addEventListener("touchmove",Ne,me?{passive:!1}:void 0),we=!0))}}else console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},Re=function(e){e?(be=be.filter((function(t){return t.targetElement!==e})),ve&&(e.ontouchstart=null,e.ontouchmove=null,we&&0===be.length&&(document.removeEventListener("touchmove",Ne,me?{passive:!1}:void 0),we=!1)),ve?function(){if(void 0!==ze){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=ze.position,document.body.style.top=ze.top,document.body.style.left=ze.left,window.scrollTo(t,e),ze=void 0}}():(void 0!==Oe&&(document.body.style.paddingRight=Oe,Oe=void 0),void 0!==xe&&(document.body.style.overflow=xe,xe=void 0))):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")},Ee="PoOhS4FU",We="PcGiiPpV",He="iQZH4Lf-";z(".PoOhS4FU{margin:20px 0 10px;user-select:none}.PcGiiPpV,.PoOhS4FU{position:relative;width:100%}.PcGiiPpV{align-items:center;background-color:#efefef;border:none;border-radius:3px;color:rgba(55,53,47,.65);cursor:pointer;display:flex;font-size:14px;overflow:hidden;padding:12px 36px 12px 12px;text-align:left;transition:background-color .1s ease-in}.PcGiiPpV:hover{background-color:#e3e3e3}.iQZH4Lf-{margin-right:8px;user-select:none}");const Le=({element:e,attributes:t,maxSizes:i,children:o,editor:n})=>{const[s,h]=c(null),p=u(null),g=e=>{var t;if(e.stopPropagation(),null!==s)return Re(document.body),void h(null);const i=null===(t=p.current)||void 0===t?void 0:t.getBoundingClientRect();if(i){const e=i.top+i.height+88+20>window.innerHeight,t=!e;console.log({showAtTop:e,showAtBottom:t}),je(document.body,{reserveScrollBarGap:!0}),h({left:i.left,top:e?i.top-88-5:i.top+i.height+5})}};return l("div",Object.assign({className:Ee},t,{contentEditable:!1},{children:[l("div",Object.assign({ref:p},{children:[l("button",Object.assign({className:We,onClick:g},{children:[d(oe,{className:He,width:24,height:24}),d("span",{children:"Click to add embed"})]})),null!==s&&d(ge,{onEmbed:t=>y(void 0,void 0,void 0,(function*(){if(0===t.length)return;const i=(o=t).includes("youtube.com")||o.includes("youtu.be")?"youtube":o.includes("vimeo.com")?"vimeo":o.includes("dailymotion.com")||o.includes("dai.ly")?"dailymotion":o.includes("twitter")?"twitter":o.includes("figma")?"figma":null;var o;let s=null;"youtube"===i?s=(e=>{const t=e.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/);return t&&11===t[2].length?t[2]:null})(t):"vimeo"===i?s=(e=>new URL(e).pathname.split("/")[1])(t):"dailymotion"===i?s=(e=>{var t=e.match(/^.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/);return null!==t?void 0!==t[4]?t[4]:t[2]:null})(t):"twitter"===i?s=function(e){const t=e.match(/\/status\/(\d+)/);return t?t[1]:null}(t):"figma"===i&&(s=function(e){const t=new URL(e).searchParams,i=t.get("node-id");return t.get("node-id")?i:"unknown"}(t)),console.log({provider:i,providerId:s});try{Re(document.body),h(null);const o={data:Object.assign(Object.assign({},e.data),{url:t,size:{width:e.data.size.width,height:e.data.size.height},provider:i,providerId:s})};r.setNodes(n,o,{at:f.findPath(n,e),match:e=>a.isElement(e)&&"embed"===e.type})}catch(e){Re(document.body),h(null)}})),onClose:g,style:s})]})),o]}))};var Pe={root:"s8SlWwrL",resizer:"OLRmQVp3",dotsOptions:"_5qhGnBQW",loadingState:"_0z3X-ysz",extraMargin:"_9GorNz7R",resizeLib:"_6GzVi0JR",leftResizer:"HLz36qUX OLRmQVp3",rightResizer:"Tv1Fs118 OLRmQVp3",resizeItem:"_33V0MBSa",selectImg:"VdsHNo29",selected:"WARAR91D",loader:"_8VNstZwX",dot:"_92ciCRYx"};z(".s8SlWwrL{cursor:pointer;display:block;position:relative}.s8SlWwrL:hover .OLRmQVp3,.s8SlWwrL:hover ._5qhGnBQW{opacity:1}._0z3X-ysz{pointer-events:none}._9GorNz7R{margin:20px 0 30px}._6GzVi0JR{margin:0 auto}.OLRmQVp3{align-items:center;cursor:col-resize;display:flex;height:100%;justify-content:center;opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;width:15px;z-index:1}.HLz36qUX{left:0;top:0}.Tv1Fs118{right:0;top:0}._33V0MBSa{background:hsla(0,0%,6%,.6);border:1px solid hsla(0,0%,100%,.9);border-radius:20px;box-shadow:0 0 0 .5px #fff;height:48px;max-height:50%;opacity:1;transition:opacity .3s ease-in 0s;width:6px}.VdsHNo29{opacity:0}.WARAR91D{background:rgba(35,131,226,.14);border-radius:3px;inset:0;opacity:1;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;z-index:81}._8VNstZwX{left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}._5qhGnBQW{align-items:center;background-color:#eee;border:none;border-radius:2px;cursor:pointer;display:flex;height:22px;justify-content:space-between;opacity:0;padding:0 4px;position:absolute;right:10px;top:10px;transition:opacity .15s ease-in 0s;width:22px;z-index:1}._92ciCRYx{background-color:gray;border-radius:50%;min-height:3px;min-width:3px}");const Ce=265;function ke(e){var o,n,s,h,u;const{element:m,editor:w,plugin:y}=e,x=v(),z=b(),[O,S]=c(null),[N,j]=c({width:(null===(n=null===(o=m.data)||void 0===o?void 0:o.size)||void 0===n?void 0:n.width)||750,height:(null===(h=null===(s=m.data)||void 0===s?void 0:s.size)||void 0===h?void 0:h.height)||440}),R=e=>j(Object.assign(Object.assign({},N),e));p((()=>{var e,t,i,o;m.data&&R({width:(null===(t=null===(e=m.data)||void 0===e?void 0:e.size)||void 0===t?void 0:t.width)||750,height:(null===(o=null===(i=m.data)||void 0===i?void 0:i.size)||void 0===o?void 0:o.height)||440})}),[null===(u=m.data)||void 0===u?void 0:u.size]);const E=g((()=>{var e,t;return{minWidth:300,size:{width:N.width,height:N.height},maxWidth:(null===(e=y.options)||void 0===e?void 0:e.maxWidth)||800,maxHeight:(null===(t=y.options)||void 0===t?void 0:t.maxHeight)||720,lockAspectRatio:!0,resizeRatio:2,enable:{left:!z,right:!z},handleStyles:{left:{left:0},right:{right:0}},onResize:(e,t,i)=>{R({width:i.offsetWidth,height:i.offsetHeight})},onResizeStop:(e,t,i)=>{console.log("image editor editor.children",w.children),console.log("ReactEditor.findPath(editor, element)",f.findPath(w,m)),console.log("element",m),r.setNodes(w,{data:Object.assign(Object.assign({},m.data),{size:{width:i.offsetWidth,height:i.offsetHeight}})},{at:f.findPath(w,m),match:e=>a.isElement(e)&&"embed"===e.type})},handleComponent:{left:d("div",Object.assign({contentEditable:!1,className:Pe.leftResizer},{children:d("div",{className:Pe.resizeItem})})),right:d("div",Object.assign({contentEditable:!1,className:Pe.rightResizer},{children:d("div",{className:Pe.resizeItem})}))}}}),[N.width,N.height,w]),W=()=>{Re(document.body),S(null)},H=e=>{var t;if(null==e||e.stopPropagation(),null!==O)return W();const i=null===(t=null==e?void 0:e.currentTarget)||void 0===t?void 0:t.getBoundingClientRect();if(i){const e=i.top+i.height+164+20>window.innerHeight;je(document.body,{reserveScrollBarGap:!0}),S({left:i.right-i.width+Ce>window.innerWidth?window.innerWidth-Ce-i.width:i.right-i.width,top:e?i.top-82-i.height:i.top+i.height+5})}};if(!m.data.url&&!m.data["data-src"]){const{maxWidth:o=750,maxHeight:n=800}=y.options||{};return l("div",Object.assign({className:Pe.root,contentEditable:!1,draggable:!1},{children:[d("div",{className:i(Pe.selectImg,{[Pe.selected]:x})}),d(Le,Object.assign({attributes:e.attributes,element:m,editor:w,maxSizes:{maxWidth:o,maxHeight:n}},{children:!z&&l("div",{children:[l("button",Object.assign({type:"button",className:Pe.dotsOptions,onClick:H},{children:[d("span",{className:Pe.dot}),d("span",{className:Pe.dot}),d("span",{className:Pe.dot})]})),null!==O&&d(t.ElementOptions,{onClose:W,style:O,element:m,onCopy:W,onDelete:W,onDuplicate:W},m.id)]})})),e.children]}),m.id)}return d("div",Object.assign({contentEditable:!1,draggable:!1,className:Pe.root},{children:l(te,Object.assign({},E,{className:Pe.resizeLib},{children:[y.renderer.render(Object.assign(Object.assign({},e),{size:N})),d("div",{className:i(Pe.selectImg,{[Pe.selected]:x})}),!z&&l("div",{children:[l("button",Object.assign({type:"button",className:Pe.dotsOptions,onClick:H},{children:[d("span",{className:Pe.dot}),d("span",{className:Pe.dot}),d("span",{className:Pe.dot})]})),null!==O&&d(t.ElementOptions,{onClose:W,style:O,element:m,onCopy:W,onDelete:W,onDuplicate:W},m.id)]})]}))}),m.id)}const Me=o({type:"embed",shortcut:"embed",renderer:{editor:(e,t)=>i=>d(ke,Object.assign({editor:e,plugin:t},i)),render:({attributes:t,element:i,children:o,HTMLAttributes:n})=>{if("string"==typeof i.data.provider&&i.data.providerId&&C[i.data.provider]){const s=C[i.data.provider];return l("div",Object.assign({},t,{contentEditable:!1,draggable:!1},n,{className:e({element:i,HTMLAttributes:n,className:P})},{children:[d(s,Object.assign({},i.data,{providerId:i.data.providerId})),o]}))}return i.data.url?l("div",Object.assign({},t,{contentEditable:!1,draggable:!1},n,{className:e({element:i,HTMLAttributes:n,className:P})},{children:[d(j,Object.assign({},i.data,{providerId:i.data.providerId})),o]})):d("div",{})}},extendEditor(e){const{isVoid:t}=e;return e.isVoid=e=>e.type===Me.getPlugin.type||t(e),e},events:{onKeyDown:(e,{defaultNode:t,hotkeys:i})=>o=>{var s;if("embed"===n(e,null===(s=e.selection)||void 0===s?void 0:s.anchor.path,"highest").type&&e.selection)return i.isEnter(o)?(o.preventDefault(),void r.insertNodes(e,t,{mode:"highest"})):void 0}},defineElement:()=>({id:s(),type:"embed",nodeType:"void",data:{url:null,size:{width:"auto",height:"auto"},providerId:null},children:[{text:""}]}),createElement:(e,t)=>{var i;const o=Object.assign(Object.assign({},Me.getPlugin.defineElement()),t);r.setNodes(e,o,{at:null===(i=e.selection)||void 0===i?void 0:i.anchor})},exports:{markdown:{serialize:(e,t)=>`[embed-url](${e.data.url})\n`},html:{serialize:(e,t)=>{var i,o;return`<iframe src="https://player.vimeo.com/video/807053663?badge=0&amp;byline=0&amp;portrait=0&amp;title=0" frameborder="0" height="${null===(i=e.data.size)||void 0===i?void 0:i.height}" width="${null===(o=e.data.size)||void 0===o?void 0:o.width}" allowfullscreen="" url="https://vimeo.com/807053663" provider="${e.data.provider||""}" />`},deserialize:{nodeName:"IFRAME",parse:e=>({url:e.getAttribute("src"),size:{height:"string"==typeof e.getAttribute("height")?Number(e.getAttribute("height")):"auto",width:"string"==typeof e.getAttribute("width")?Number(e.getAttribute("width")):"auto"}})}}},options:{searchString:"Embed media",displayLabel:"Embed"}});export{Me as default};