@atlaskit/editor-core 188.0.12 → 188.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/labs/next/presets/universal.js +2 -1
- package/dist/cjs/plugins/annotation/toolbar.js +5 -23
- package/dist/cjs/plugins/code-block/index.js +3 -3
- package/dist/cjs/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +2 -2
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +4 -4
- package/dist/cjs/plugins/media/index.js +12 -6
- package/dist/cjs/plugins/media/utils/media-common.js +7 -109
- package/dist/cjs/plugins/media/utils/media-single.js +7 -68
- package/dist/cjs/plugins/panel/index.js +13 -13
- package/dist/cjs/plugins/paste/handlers.js +4 -4
- package/dist/cjs/plugins/paste/plugins/media.js +181 -0
- package/dist/cjs/plugins/paste/pm-plugins/analytics.js +2 -2
- package/dist/cjs/plugins/paste/pm-plugins/main.js +6 -7
- package/dist/cjs/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +3 -3
- package/dist/cjs/ui/Alignment/index.js +1 -1
- package/dist/cjs/ui/WithHelpTrigger/index.js +3 -7
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/labs/next/presets/universal.js +2 -1
- package/dist/es2019/plugins/annotation/toolbar.js +2 -18
- package/dist/es2019/plugins/code-block/index.js +3 -3
- package/dist/es2019/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +1 -1
- package/dist/es2019/plugins/media/index.js +13 -6
- package/dist/es2019/plugins/media/utils/media-common.js +2 -107
- package/dist/es2019/plugins/media/utils/media-single.js +6 -72
- package/dist/es2019/plugins/panel/index.js +13 -13
- package/dist/es2019/plugins/paste/handlers.js +4 -4
- package/dist/es2019/plugins/paste/plugins/media.js +176 -0
- package/dist/es2019/plugins/paste/pm-plugins/analytics.js +2 -2
- package/dist/es2019/plugins/paste/pm-plugins/main.js +3 -4
- package/dist/es2019/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +3 -3
- package/dist/es2019/ui/Alignment/index.js +1 -1
- package/dist/es2019/ui/WithHelpTrigger/index.js +2 -7
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/labs/next/presets/universal.js +2 -1
- package/dist/esm/plugins/annotation/toolbar.js +2 -18
- package/dist/esm/plugins/code-block/index.js +3 -3
- package/dist/esm/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +1 -1
- package/dist/esm/plugins/media/index.js +13 -6
- package/dist/esm/plugins/media/utils/media-common.js +2 -106
- package/dist/esm/plugins/media/utils/media-single.js +6 -66
- package/dist/esm/plugins/panel/index.js +13 -13
- package/dist/esm/plugins/paste/handlers.js +4 -4
- package/dist/esm/plugins/paste/plugins/media.js +172 -0
- package/dist/esm/plugins/paste/pm-plugins/analytics.js +2 -2
- package/dist/esm/plugins/paste/pm-plugins/main.js +3 -4
- package/dist/esm/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +3 -3
- package/dist/esm/ui/Alignment/index.js +1 -1
- package/dist/esm/ui/WithHelpTrigger/index.js +2 -7
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/labs/next/presets/default.d.ts +6 -0
- package/dist/types/plugins/annotation/toolbar.d.ts +0 -17
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/media/next-plugin-type.d.ts +4 -0
- package/dist/types/plugins/media/utils/media-common.d.ts +2 -10
- package/dist/types/plugins/media/utils/media-single.d.ts +2 -4
- package/dist/types/plugins/paste/handlers.d.ts +2 -2
- package/dist/types/plugins/paste/index.d.ts +5 -2
- package/dist/types/plugins/paste/plugins/media.d.ts +12 -0
- package/dist/types/plugins/paste/pm-plugins/analytics.d.ts +2 -2
- package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -2
- package/dist/types/ui/Alignment/index.d.ts +2 -2
- package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
- package/dist/types/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types/ui/WithHelpTrigger/index.d.ts +0 -4
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +6 -0
- package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +0 -17
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/media/next-plugin-type.d.ts +4 -0
- package/dist/types-ts4.5/plugins/media/utils/media-common.d.ts +2 -10
- package/dist/types-ts4.5/plugins/media/utils/media-single.d.ts +2 -4
- package/dist/types-ts4.5/plugins/paste/handlers.d.ts +2 -2
- package/dist/types-ts4.5/plugins/paste/index.d.ts +5 -2
- package/dist/types-ts4.5/plugins/paste/plugins/media.d.ts +12 -0
- package/dist/types-ts4.5/plugins/paste/pm-plugins/analytics.d.ts +2 -2
- package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +2 -2
- package/dist/types-ts4.5/ui/Alignment/index.d.ts +2 -2
- package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
- package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types-ts4.5/ui/WithHelpTrigger/index.d.ts +0 -4
- package/package.json +8 -7
- package/report.api.md +1 -1
- package/tmp/api-report-tmp.d.ts +1 -1
- package/dist/cjs/plugins/help-dialog/commands.js +0 -19
- package/dist/cjs/plugins/help-dialog/index.js +0 -138
- package/dist/cjs/plugins/help-dialog/plugin-key.js +0 -8
- package/dist/cjs/plugins/help-dialog/ui/HelpDialogLoader.js +0 -24
- package/dist/cjs/plugins/help-dialog/ui/index.js +0 -568
- package/dist/cjs/plugins/help-dialog/ui/styles.js +0 -50
- package/dist/cjs/plugins/undo-redo/messages.js +0 -19
- package/dist/cjs/ui/Alignment/messages.js +0 -24
- package/dist/es2019/plugins/help-dialog/commands.js +0 -13
- package/dist/es2019/plugins/help-dialog/index.js +0 -125
- package/dist/es2019/plugins/help-dialog/plugin-key.js +0 -2
- package/dist/es2019/plugins/help-dialog/ui/HelpDialogLoader.js +0 -6
- package/dist/es2019/plugins/help-dialog/ui/index.js +0 -446
- package/dist/es2019/plugins/help-dialog/ui/styles.js +0 -110
- package/dist/es2019/plugins/undo-redo/messages.js +0 -13
- package/dist/es2019/ui/Alignment/messages.js +0 -18
- package/dist/esm/plugins/help-dialog/commands.js +0 -13
- package/dist/esm/plugins/help-dialog/index.js +0 -130
- package/dist/esm/plugins/help-dialog/plugin-key.js +0 -2
- package/dist/esm/plugins/help-dialog/ui/HelpDialogLoader.js +0 -12
- package/dist/esm/plugins/help-dialog/ui/index.js +0 -557
- package/dist/esm/plugins/help-dialog/ui/styles.js +0 -40
- package/dist/esm/plugins/undo-redo/messages.js +0 -13
- package/dist/esm/ui/Alignment/messages.js +0 -18
- package/dist/types/plugins/help-dialog/commands.d.ts +0 -3
- package/dist/types/plugins/help-dialog/index.d.ts +0 -18
- package/dist/types/plugins/help-dialog/plugin-key.d.ts +0 -2
- package/dist/types/plugins/help-dialog/ui/HelpDialogLoader.d.ts +0 -4
- package/dist/types/plugins/help-dialog/ui/index.d.ts +0 -27
- package/dist/types/plugins/help-dialog/ui/styles.d.ts +0 -33
- package/dist/types/plugins/undo-redo/messages.d.ts +0 -12
- package/dist/types/ui/Alignment/messages.d.ts +0 -17
- package/dist/types-ts4.5/plugins/help-dialog/commands.d.ts +0 -3
- package/dist/types-ts4.5/plugins/help-dialog/index.d.ts +0 -18
- package/dist/types-ts4.5/plugins/help-dialog/plugin-key.d.ts +0 -2
- package/dist/types-ts4.5/plugins/help-dialog/ui/HelpDialogLoader.d.ts +0 -4
- package/dist/types-ts4.5/plugins/help-dialog/ui/index.d.ts +0 -27
- package/dist/types-ts4.5/plugins/help-dialog/ui/styles.d.ts +0 -33
- package/dist/types-ts4.5/plugins/undo-redo/messages.d.ts +0 -12
- package/dist/types-ts4.5/ui/Alignment/messages.d.ts +0 -17
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.isImage = void 0;
|
|
8
|
+
exports.transformSliceForMedia = transformSliceForMedia;
|
|
9
|
+
exports.unwrapNestedMediaElements = exports.transformSliceToCorrectMediaWrapper = void 0;
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
+
var _utils2 = require("@atlaskit/editor-common/utils");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function transformSliceForMedia(slice, schema) {
|
|
18
|
+
var _schema$nodes = schema.nodes,
|
|
19
|
+
mediaSingle = _schema$nodes.mediaSingle,
|
|
20
|
+
layoutSection = _schema$nodes.layoutSection,
|
|
21
|
+
table = _schema$nodes.table,
|
|
22
|
+
bulletList = _schema$nodes.bulletList,
|
|
23
|
+
orderedList = _schema$nodes.orderedList,
|
|
24
|
+
media = _schema$nodes.media,
|
|
25
|
+
mediaInline = _schema$nodes.mediaInline,
|
|
26
|
+
expand = _schema$nodes.expand,
|
|
27
|
+
nestedExpand = _schema$nodes.nestedExpand;
|
|
28
|
+
return function (selection) {
|
|
29
|
+
var newSlice = slice;
|
|
30
|
+
if ((0, _utils.hasParentNodeOfType)([layoutSection, table, bulletList, orderedList, expand, nestedExpand])(selection)) {
|
|
31
|
+
newSlice = (0, _utils2.mapSlice)(newSlice, function (node) {
|
|
32
|
+
var extendedOrLegacyAttrs = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.extended-resize-experience') ? {
|
|
33
|
+
layout: node.attrs.layout,
|
|
34
|
+
widthType: node.attrs.widthType,
|
|
35
|
+
width: node.attrs.width
|
|
36
|
+
} : {
|
|
37
|
+
layout: node.attrs.layout
|
|
38
|
+
};
|
|
39
|
+
var attrs = {};
|
|
40
|
+
if ((0, _utils.hasParentNodeOfType)([layoutSection, table])(selection)) {
|
|
41
|
+
// Supports layouts
|
|
42
|
+
attrs = _objectSpread({}, extendedOrLegacyAttrs);
|
|
43
|
+
} else if ((0, _utils.hasParentNodeOfType)([bulletList, orderedList, expand, nestedExpand])(selection)) {
|
|
44
|
+
// does not support other layouts
|
|
45
|
+
attrs = _objectSpread(_objectSpread({}, extendedOrLegacyAttrs), {}, {
|
|
46
|
+
layout: 'center'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return node.type.name === 'mediaSingle' ? mediaSingle.createChecked(attrs, node.content, node.marks) : node;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
var __mediaTraceId = (0, _mediaCommon.getRandomHex)(8);
|
|
53
|
+
newSlice = (0, _utils2.mapSlice)(newSlice, function (node) {
|
|
54
|
+
// This logic is duplicated in editor-plugin-ai where external images can be inserted
|
|
55
|
+
// from external sources through the use of AI. The editor-plugin-ai package is avoiding
|
|
56
|
+
// sharing dependencies with editor-core to support products using it with various versions
|
|
57
|
+
// of editor packages.
|
|
58
|
+
// The duplication is in the following file:
|
|
59
|
+
// packages/editor/editor-plugin-ai/src/prebuilt/content-transformers/markdown-to-pm/markdown-transformer.ts
|
|
60
|
+
if (node.type.name === 'media') {
|
|
61
|
+
return media.createChecked(_objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
62
|
+
__external: node.attrs.type === 'external',
|
|
63
|
+
__mediaTraceId: node.attrs.type === 'external' ? null : __mediaTraceId
|
|
64
|
+
}), node.content, node.marks);
|
|
65
|
+
}
|
|
66
|
+
if (node.type.name === 'mediaInline') {
|
|
67
|
+
return mediaInline.createChecked(_objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
68
|
+
__mediaTraceId: __mediaTraceId
|
|
69
|
+
}), node.content, node.marks);
|
|
70
|
+
}
|
|
71
|
+
return node;
|
|
72
|
+
});
|
|
73
|
+
return newSlice;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// TODO move this to editor-common
|
|
78
|
+
var isImage = exports.isImage = function isImage(fileType) {
|
|
79
|
+
return !!fileType && (fileType.indexOf('image/') > -1 || fileType.indexOf('video/') > -1);
|
|
80
|
+
};
|
|
81
|
+
var transformSliceToCorrectMediaWrapper = exports.transformSliceToCorrectMediaWrapper = function transformSliceToCorrectMediaWrapper(slice, schema) {
|
|
82
|
+
var _schema$nodes2 = schema.nodes,
|
|
83
|
+
mediaGroup = _schema$nodes2.mediaGroup,
|
|
84
|
+
mediaSingle = _schema$nodes2.mediaSingle,
|
|
85
|
+
media = _schema$nodes2.media;
|
|
86
|
+
return (0, _utils2.mapSlice)(slice, function (node, parent) {
|
|
87
|
+
if (!parent && node.type === media) {
|
|
88
|
+
if (mediaSingle && (isImage(node.attrs.__fileMimeType) || node.attrs.type === 'external')) {
|
|
89
|
+
return mediaSingle.createChecked({}, node);
|
|
90
|
+
} else {
|
|
91
|
+
return mediaGroup.createChecked({}, [node]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return node;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check base styles to see if an element will be invisible when rendered in a document.
|
|
100
|
+
* @param element
|
|
101
|
+
*/
|
|
102
|
+
var isElementInvisible = function isElementInvisible(element) {
|
|
103
|
+
return element.style.opacity === '0' || element.style.display === 'none' || element.style.visibility === 'hidden';
|
|
104
|
+
};
|
|
105
|
+
var VALID_TAGS_CONTAINER = ['DIV', 'TD'];
|
|
106
|
+
function canContainImage(element) {
|
|
107
|
+
if (!element) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return VALID_TAGS_CONTAINER.indexOf(element.tagName) !== -1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Given a html string, we attempt to hoist any nested `<img>` tags,
|
|
115
|
+
* not directly wrapped by a `<div>` as ProseMirror no-op's
|
|
116
|
+
* on those scenarios.
|
|
117
|
+
* @param html
|
|
118
|
+
*/
|
|
119
|
+
var unwrapNestedMediaElements = exports.unwrapNestedMediaElements = function unwrapNestedMediaElements(html) {
|
|
120
|
+
var parser = new DOMParser();
|
|
121
|
+
var doc = parser.parseFromString(html, 'text/html');
|
|
122
|
+
var wrapper = doc.body;
|
|
123
|
+
|
|
124
|
+
// Remove Google Doc's wrapper <b> el
|
|
125
|
+
var docsWrapper = wrapper.querySelector('b[id^="docs-internal-guid-"]');
|
|
126
|
+
if (docsWrapper) {
|
|
127
|
+
(0, _utils2.unwrap)(wrapper, docsWrapper);
|
|
128
|
+
}
|
|
129
|
+
var imageTags = wrapper.querySelectorAll('img');
|
|
130
|
+
if (!imageTags.length) {
|
|
131
|
+
return html;
|
|
132
|
+
}
|
|
133
|
+
imageTags.forEach(function (imageTag) {
|
|
134
|
+
// Capture the immediate parent, we may remove the media from here later.
|
|
135
|
+
var mediaParent = imageTag.parentElement;
|
|
136
|
+
if (!mediaParent) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// If either the parent or the image itself contains styles that would make
|
|
141
|
+
// them invisible on copy, dont paste them.
|
|
142
|
+
if (isElementInvisible(mediaParent) || isElementInvisible(imageTag)) {
|
|
143
|
+
mediaParent.removeChild(imageTag);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// If its wrapped by a valid container we assume its safe to bypass.
|
|
148
|
+
// ProseMirror should handle these cases properly.
|
|
149
|
+
if (canContainImage(mediaParent) || mediaParent instanceof HTMLSpanElement && mediaParent.closest('[class*="emoji-common"]')) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Find the top most element that the parent has a valid container for the image.
|
|
154
|
+
// Stop just before found the wrapper
|
|
155
|
+
var insertBeforeElement = (0, _utils2.walkUpTreeUntil)(mediaParent, function (element) {
|
|
156
|
+
// If is at the top just use this element as reference
|
|
157
|
+
if (element.parentElement === wrapper) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return canContainImage(element.parentElement);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Here we try to insert the media right after its top most valid parent element
|
|
164
|
+
// Unless its the last element in our structure then we will insert above it.
|
|
165
|
+
if (insertBeforeElement && insertBeforeElement.parentElement) {
|
|
166
|
+
// Insert as close as possible to the most closest valid element index in the tree.
|
|
167
|
+
insertBeforeElement.parentElement.insertBefore(imageTag, insertBeforeElement.nextElementSibling || insertBeforeElement);
|
|
168
|
+
|
|
169
|
+
// Attempt to clean up lines left behind by the image
|
|
170
|
+
mediaParent.innerText = mediaParent.innerText.trim();
|
|
171
|
+
// Walk up and delete empty elements left over after removing the image tag
|
|
172
|
+
(0, _utils2.removeNestedEmptyEls)(mediaParent);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// If last child is a hardbreak we don't want it
|
|
177
|
+
if (wrapper.lastElementChild && wrapper.lastElementChild.tagName === 'BR') {
|
|
178
|
+
wrapper.removeChild(wrapper.lastElementChild);
|
|
179
|
+
}
|
|
180
|
+
return wrapper.innerHTML;
|
|
181
|
+
};
|
|
@@ -253,10 +253,10 @@ var handleCodeBlockWithAnalytics = exports.handleCodeBlockWithAnalytics = functi
|
|
|
253
253
|
type: _analytics.PasteTypes.plain
|
|
254
254
|
}))((0, _handlers.handleCodeBlock)(text));
|
|
255
255
|
};
|
|
256
|
-
var handleMediaSingleWithAnalytics = exports.handleMediaSingleWithAnalytics = function handleMediaSingleWithAnalytics(view, event, slice, type,
|
|
256
|
+
var handleMediaSingleWithAnalytics = exports.handleMediaSingleWithAnalytics = function handleMediaSingleWithAnalytics(view, event, slice, type, insertMediaAsMediaSingle) {
|
|
257
257
|
return injectAnalyticsPayloadBeforeCommand(createPasteAnalyticsPayloadBySelection(event, slice, {
|
|
258
258
|
type: type
|
|
259
|
-
}))((0, _handlers.handleMediaSingle)(_analytics.INPUT_METHOD.CLIPBOARD,
|
|
259
|
+
}))((0, _handlers.handleMediaSingle)(_analytics.INPUT_METHOD.CLIPBOARD, insertMediaAsMediaSingle)(slice));
|
|
260
260
|
};
|
|
261
261
|
var handlePastePreservingMarksWithAnalytics = exports.handlePastePreservingMarksWithAnalytics = function handlePastePreservingMarksWithAnalytics(view, event, slice, type, pluginInjectionApi) {
|
|
262
262
|
var _pluginInjectionApi$c2;
|
|
@@ -21,7 +21,7 @@ var _card = require("@atlaskit/editor-common/card");
|
|
|
21
21
|
var _slice = require("../../../utils/slice");
|
|
22
22
|
var _extensions = require("@atlaskit/editor-common/extensions");
|
|
23
23
|
var _paste = require("@atlaskit/editor-common/paste");
|
|
24
|
-
var
|
|
24
|
+
var _media = require("../plugins/media");
|
|
25
25
|
var _util = require("../util");
|
|
26
26
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
27
27
|
var _utils2 = require("../../expand/utils");
|
|
@@ -30,7 +30,6 @@ var _utils3 = require("../../code-block/utils");
|
|
|
30
30
|
var _analytics = require("./analytics");
|
|
31
31
|
var _analytics2 = require("../../analytics");
|
|
32
32
|
var _utils4 = require("../../../utils");
|
|
33
|
-
var _mediaCommon = require("../../media/utils/media-common");
|
|
34
33
|
var _commands = require("../commands");
|
|
35
34
|
var _utils5 = require("../../tasks-and-decisions/utils");
|
|
36
35
|
var _utils6 = require("../../annotation/utils");
|
|
@@ -112,7 +111,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
112
111
|
}
|
|
113
112
|
},
|
|
114
113
|
handlePaste: function handlePaste(view, rawEvent, slice) {
|
|
115
|
-
var _text, _analyticsPlugin$perf, _schema$nodes, _schema$nodes2, _schema$nodes3, _pluginInjectionApi$
|
|
114
|
+
var _text, _analyticsPlugin$perf, _schema$nodes, _schema$nodes2, _schema$nodes3, _pluginInjectionApi$m;
|
|
116
115
|
var event = rawEvent;
|
|
117
116
|
if (!event.clipboardData) {
|
|
118
117
|
return false;
|
|
@@ -224,7 +223,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
224
223
|
}
|
|
225
224
|
|
|
226
225
|
// transform slices based on destination
|
|
227
|
-
slice = (0,
|
|
226
|
+
slice = (0, _media.transformSliceForMedia)(slice, schema)(state.selection);
|
|
228
227
|
var markdownSlice;
|
|
229
228
|
if (isPlainText) {
|
|
230
229
|
var _markdownSlice;
|
|
@@ -276,7 +275,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
276
275
|
if ((0, _analytics.handleCodeBlockWithAnalytics)(view, event, slice, text)(state, dispatch)) {
|
|
277
276
|
return true;
|
|
278
277
|
}
|
|
279
|
-
if ((0, _analytics.handleMediaSingleWithAnalytics)(view, event, slice, isPastedFile ? _analytics2.PasteTypes.binary : _analytics2.PasteTypes.richText, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
278
|
+
if ((0, _analytics.handleMediaSingleWithAnalytics)(view, event, slice, isPastedFile ? _analytics2.PasteTypes.binary : _analytics2.PasteTypes.richText, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.actions.insertMediaAsMediaSingle)(state, dispatch, view)) {
|
|
280
279
|
return true;
|
|
281
280
|
}
|
|
282
281
|
if ((0, _analytics.handleSelectedTableWithAnalytics)(view, event, slice)(state, dispatch)) {
|
|
@@ -395,7 +394,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
395
394
|
slice = (0, _utils3.transformSliceToJoinAdjacentCodeBlocks)(slice);
|
|
396
395
|
}
|
|
397
396
|
slice = (0, _utils3.transformSingleLineCodeBlockToCodeMark)(slice, schema);
|
|
398
|
-
slice = (0,
|
|
397
|
+
slice = (0, _media.transformSliceToCorrectMediaWrapper)(slice, schema);
|
|
399
398
|
slice = (0, _utils5.transformSliceToDecisionList)(slice, schema);
|
|
400
399
|
|
|
401
400
|
// splitting linebreaks into paragraphs must happen before upgrading text to lists
|
|
@@ -424,7 +423,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
|
|
|
424
423
|
}
|
|
425
424
|
}
|
|
426
425
|
if (!(0, _util.isPastedFromWord)(html) && !(0, _util.isPastedFromExcel)(html) && html.indexOf('<img ') >= 0) {
|
|
427
|
-
html = (0,
|
|
426
|
+
html = (0, _media.unwrapNestedMediaElements)(html);
|
|
428
427
|
}
|
|
429
428
|
|
|
430
429
|
// https://product-fabric.atlassian.net/browse/ED-11714
|
|
@@ -19,7 +19,7 @@ var _redo = _interopRequireDefault(require("@atlaskit/icon/glyph/redo"));
|
|
|
19
19
|
var _keymaps = require("../../../../keymaps");
|
|
20
20
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
21
21
|
var _ToolbarButton = _interopRequireWildcard(require("../../../../ui/ToolbarButton"));
|
|
22
|
-
var _messages = require("
|
|
22
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
23
23
|
var _api = require("../../../type-ahead/api");
|
|
24
24
|
var _commands = require("../../commands");
|
|
25
25
|
var _keymaps2 = require("@atlaskit/editor-common/keymaps");
|
|
@@ -73,8 +73,8 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = /*#__PURE__*/function (_PureComp
|
|
|
73
73
|
var handleRedo = function handleRedo() {
|
|
74
74
|
forceFocus(editorView)(_commands.redoFromToolbar);
|
|
75
75
|
};
|
|
76
|
-
var labelUndo = formatMessage(_messages.
|
|
77
|
-
var labelRedo = formatMessage(_messages.
|
|
76
|
+
var labelUndo = formatMessage(_messages.undoRedoMessages.undo);
|
|
77
|
+
var labelRedo = formatMessage(_messages.undoRedoMessages.redo);
|
|
78
78
|
var canUndo = historyState.canUndo,
|
|
79
79
|
canRedo = historyState.canRedo;
|
|
80
80
|
return (0, _react2.jsx)("span", {
|
|
@@ -15,7 +15,7 @@ var _react2 = require("react");
|
|
|
15
15
|
var _reactIntlNext = require("react-intl-next");
|
|
16
16
|
var _iconMap = require("../../plugins/alignment/ui/ToolbarAlignment/icon-map");
|
|
17
17
|
var _AlignmentButton = _interopRequireDefault(require("./AlignmentButton"));
|
|
18
|
-
var _messages = require("
|
|
18
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
19
19
|
var _styles = require("./styles");
|
|
20
20
|
var _keymaps = require("../../keymaps");
|
|
21
21
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
@@ -17,13 +17,9 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
17
17
|
var _analytics = require("../../plugins/analytics");
|
|
18
18
|
var _eventDispatcher = require("../../event-dispatcher");
|
|
19
19
|
var _consts = require("../../plugins/analytics/consts");
|
|
20
|
-
var
|
|
20
|
+
var _editorPluginHelpDialog = require("@atlaskit/editor-plugin-help-dialog");
|
|
21
21
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
22
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated
|
|
25
|
-
* Use WithHelpTrigger from @atlaskit/editor-plugin-help-dialog which uses pluginInjectionApi
|
|
26
|
-
*/
|
|
22
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
23
|
var WithHelpTrigger = exports.default = /*#__PURE__*/function (_React$Component) {
|
|
28
24
|
(0, _inherits2.default)(WithHelpTrigger, _React$Component);
|
|
29
25
|
var _super = _createSuper(WithHelpTrigger);
|
|
@@ -50,7 +46,7 @@ var WithHelpTrigger = exports.default = /*#__PURE__*/function (_React$Component)
|
|
|
50
46
|
});
|
|
51
47
|
var editorView = editorActions._privateGetEditorView();
|
|
52
48
|
if (editorView) {
|
|
53
|
-
(0,
|
|
49
|
+
(0, _editorPluginHelpDialog.deprecatedOpenHelpCommand)(editorView.state.tr, editorView.dispatch);
|
|
54
50
|
}
|
|
55
51
|
});
|
|
56
52
|
return _this;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.version = exports.nextMajorVersion = exports.name = void 0;
|
|
7
7
|
var name = exports.name = "@atlaskit/editor-core";
|
|
8
|
-
var version = exports.version = "188.0
|
|
8
|
+
var version = exports.version = "188.2.0";
|
|
9
9
|
var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
|
|
10
10
|
return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
|
|
11
11
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createEditorSelectionAPI } from '../../../selection-api/api';
|
|
2
|
-
import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, extensionPlugin, fragmentMarkPlugin,
|
|
2
|
+
import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, extensionPlugin, fragmentMarkPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, toolbarListsIndentationPlugin, macroPlugin, maxContentSizePlugin, mediaPlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, saveOnEnterPlugin, tasksAndDecisionsPlugin, textColorPlugin, statusPlugin, alignmentPlugin, indentationPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, mobileSelectionPlugin, annotationPlugin, captionPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin, beforePrimaryToolbarPlugin, codeBidiWarningPlugin, borderPlugin } from '../../../plugins';
|
|
3
|
+
import { helpDialogPlugin } from '@atlaskit/editor-plugin-help-dialog';
|
|
3
4
|
import { rulePlugin } from '@atlaskit/editor-plugin-rule';
|
|
4
5
|
import { emojiPlugin } from '@atlaskit/editor-plugin-emoji';
|
|
5
6
|
import { listPlugin } from '@atlaskit/editor-plugin-list';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { defineMessages } from 'react-intl-next';
|
|
3
2
|
import CommentIcon from '@atlaskit/icon/glyph/comment';
|
|
4
3
|
// AFP-2532 TODO: Fix automatic suppressions below
|
|
5
4
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
@@ -7,23 +6,8 @@ import { addInlineComment, ToolTipContent } from '../../keymaps';
|
|
|
7
6
|
import { setInlineCommentDraftState } from './commands';
|
|
8
7
|
import { AnnotationTestIds, AnnotationSelectionType } from './types';
|
|
9
8
|
import { isSelectionValid } from './utils';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
id: 'fabric.editor.createComment',
|
|
13
|
-
defaultMessage: 'Comment',
|
|
14
|
-
description: 'Create/add an inline comment based on the users selection'
|
|
15
|
-
},
|
|
16
|
-
createCommentInvalid: {
|
|
17
|
-
id: 'fabric.editor.createCommentInvalid',
|
|
18
|
-
defaultMessage: 'You can only comment on text and headings',
|
|
19
|
-
description: 'Error message to communicate to the user they can only do the current action in certain contexts'
|
|
20
|
-
},
|
|
21
|
-
toolbar: {
|
|
22
|
-
id: 'fabric.editor.annotationToolbar',
|
|
23
|
-
defaultMessage: 'Annotation toolbar',
|
|
24
|
-
description: 'A label for a toolbar (UI element) that creates annotations/comments in the document'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
9
|
+
import { annotationMessages } from '@atlaskit/editor-common/messages';
|
|
10
|
+
|
|
27
11
|
/**
|
|
28
12
|
* Returns the coordintes at the bottom the selection.
|
|
29
13
|
*/
|
|
@@ -7,7 +7,7 @@ import ideUX from './pm-plugins/ide-ux';
|
|
|
7
7
|
import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
8
8
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
9
9
|
import { IconCode } from '@atlaskit/editor-common/quick-insert';
|
|
10
|
-
import {
|
|
10
|
+
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
11
11
|
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
12
12
|
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
|
|
13
13
|
import { createCodeBlockInputRule } from './pm-plugins/input-rule';
|
|
@@ -75,8 +75,8 @@ const codeBlockPlugin = ({
|
|
|
75
75
|
formatMessage
|
|
76
76
|
}) => [{
|
|
77
77
|
id: 'codeblock',
|
|
78
|
-
title: formatMessage(
|
|
79
|
-
description: formatMessage(
|
|
78
|
+
title: formatMessage(blockTypeMessages.codeblock),
|
|
79
|
+
description: formatMessage(blockTypeMessages.codeblockDescription),
|
|
80
80
|
keywords: ['code block'],
|
|
81
81
|
priority: 700,
|
|
82
82
|
keyshortcut: '```',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import { getSelectedNodeOrNodeParentByNodeType } from '@atlaskit/editor-
|
|
4
|
+
import { getSelectedNodeOrNodeParentByNodeType } from '@atlaskit/editor-common/copy-button';
|
|
5
5
|
export const copySelectionPluginKey = new PluginKey('codeBlockCopySelectionPlugin');
|
|
6
6
|
function getSelectionDecorationStartAndEnd({
|
|
7
7
|
state,
|
|
@@ -5,7 +5,6 @@ export { default as collabEditPlugin } from './collab-edit';
|
|
|
5
5
|
export { default as datePlugin } from './date';
|
|
6
6
|
export { default as extensionPlugin } from './extension';
|
|
7
7
|
export { default as fakeTextCursorPlugin } from './fake-text-cursor';
|
|
8
|
-
export { default as helpDialogPlugin } from './help-dialog';
|
|
9
8
|
export { default as insertBlockPlugin } from './insert-block';
|
|
10
9
|
export { default as jiraIssuePlugin } from './jira-issue';
|
|
11
10
|
export { default as layoutPlugin } from './layout';
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import memoize from 'lodash/memoize';
|
|
3
3
|
import memoizeOne from 'memoize-one';
|
|
4
4
|
import { messages } from './messages';
|
|
5
|
-
import {
|
|
5
|
+
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
6
6
|
import { ToolTipContent } from '../../../../keymaps';
|
|
7
7
|
import { sortItems } from './sort-items';
|
|
8
8
|
import { action, link, media, mention, emoji, table, layout, codeblock, panel, blockquote, decision, horizontalrule, expand, date, placeholder, status, more, imageUpload } from './item';
|
|
@@ -23,6 +23,7 @@ import { ReactMediaNode } from './nodeviews/mediaNodeView';
|
|
|
23
23
|
import { ReactMediaInlineNode } from './nodeviews/mediaInline';
|
|
24
24
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
25
25
|
import { stateKey } from './pm-plugins/plugin-key';
|
|
26
|
+
import { insertMediaAsMediaSingle } from './utils/media-single';
|
|
26
27
|
export { insertMediaSingleNode } from './utils/media-single';
|
|
27
28
|
const MediaPickerFunctionalComponent = ({
|
|
28
29
|
api,
|
|
@@ -56,6 +57,12 @@ const mediaPlugin = ({
|
|
|
56
57
|
}
|
|
57
58
|
return stateKey.getState(editorState) || null;
|
|
58
59
|
},
|
|
60
|
+
actions: {
|
|
61
|
+
insertMediaAsMediaSingle: (view, node, inputMethod) => {
|
|
62
|
+
var _api$analytics;
|
|
63
|
+
return insertMediaAsMediaSingle(view, node, inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
59
66
|
nodes() {
|
|
60
67
|
const {
|
|
61
68
|
allowMediaGroup = true,
|
|
@@ -136,8 +143,8 @@ const mediaPlugin = ({
|
|
|
136
143
|
}, {
|
|
137
144
|
name: 'mediaKeymap',
|
|
138
145
|
plugin: () => {
|
|
139
|
-
var _api$
|
|
140
|
-
return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$
|
|
146
|
+
var _api$analytics2;
|
|
147
|
+
return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
141
148
|
}
|
|
142
149
|
}];
|
|
143
150
|
if (options && options.allowMediaSingle) {
|
|
@@ -158,8 +165,8 @@ const mediaPlugin = ({
|
|
|
158
165
|
plugin: ({
|
|
159
166
|
schema
|
|
160
167
|
}) => {
|
|
161
|
-
var _api$
|
|
162
|
-
return keymapMediaAltTextPlugin(schema, api === null || api === void 0 ? void 0 : (_api$
|
|
168
|
+
var _api$analytics3;
|
|
169
|
+
return keymapMediaAltTextPlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
163
170
|
}
|
|
164
171
|
});
|
|
165
172
|
}
|
|
@@ -245,11 +252,11 @@ const mediaPlugin = ({
|
|
|
245
252
|
keywords: ['attachment', 'gif', 'media', 'picture', 'image', 'video'],
|
|
246
253
|
icon: () => /*#__PURE__*/React.createElement(IconImages, null),
|
|
247
254
|
action(insert, state) {
|
|
248
|
-
var _api$
|
|
255
|
+
var _api$analytics4;
|
|
249
256
|
const pluginState = pluginKey.getState(state);
|
|
250
257
|
pluginState === null || pluginState === void 0 ? void 0 : pluginState.showMediaPicker();
|
|
251
258
|
const tr = insert('');
|
|
252
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
259
|
+
api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.attachAnalyticsEvent({
|
|
253
260
|
action: ACTION.OPENED,
|
|
254
261
|
actionSubject: ACTION_SUBJECT.PICKER,
|
|
255
262
|
actionSubjectId: ACTION_SUBJECT_ID.PICKER_CLOUD,
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, endPositionOfParent, GapCursorSelection, startPositionOfParent } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { createNewParagraphBelow, createParagraphNear } from '@atlaskit/editor-common/utils';
|
|
1
3
|
import { deleteSelection, splitBlock } from '@atlaskit/editor-prosemirror/commands';
|
|
2
4
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import { findPositionOfNodeBefore } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { createParagraphNear, createNewParagraphBelow } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { mapSlice } from '@atlaskit/editor-common/utils';
|
|
6
|
-
import { walkUpTreeUntil, removeNestedEmptyEls, unwrap } from '@atlaskit/editor-common/utils';
|
|
7
|
-
import { isImage } from './is-image';
|
|
8
|
-
import { GapCursorSelection, atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, endPositionOfParent, startPositionOfParent } from '@atlaskit/editor-common/selection';
|
|
9
6
|
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
10
7
|
const isTemporary = id => {
|
|
11
8
|
return id.indexOf('temporary:') === 0;
|
|
@@ -178,108 +175,6 @@ export const copyOptionalAttrsFromMediaState = (mediaState, node) => {
|
|
|
178
175
|
}
|
|
179
176
|
});
|
|
180
177
|
};
|
|
181
|
-
export const transformSliceToCorrectMediaWrapper = (slice, schema) => {
|
|
182
|
-
const {
|
|
183
|
-
mediaGroup,
|
|
184
|
-
mediaSingle,
|
|
185
|
-
media
|
|
186
|
-
} = schema.nodes;
|
|
187
|
-
return mapSlice(slice, (node, parent) => {
|
|
188
|
-
if (!parent && node.type === media) {
|
|
189
|
-
if (mediaSingle && (isImage(node.attrs.__fileMimeType) || node.attrs.type === 'external')) {
|
|
190
|
-
return mediaSingle.createChecked({}, node);
|
|
191
|
-
} else {
|
|
192
|
-
return mediaGroup.createChecked({}, [node]);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return node;
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Check base styles to see if an element will be invisible when rendered in a document.
|
|
201
|
-
* @param element
|
|
202
|
-
*/
|
|
203
|
-
const isElementInvisible = element => {
|
|
204
|
-
return element.style.opacity === '0' || element.style.display === 'none' || element.style.visibility === 'hidden';
|
|
205
|
-
};
|
|
206
|
-
const VALID_TAGS_CONTAINER = ['DIV', 'TD'];
|
|
207
|
-
function canContainImage(element) {
|
|
208
|
-
if (!element) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
return VALID_TAGS_CONTAINER.indexOf(element.tagName) !== -1;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Given a html string, we attempt to hoist any nested `<img>` tags,
|
|
216
|
-
* not directly wrapped by a `<div>` as ProseMirror no-op's
|
|
217
|
-
* on those scenarios.
|
|
218
|
-
* @param html
|
|
219
|
-
*/
|
|
220
|
-
export const unwrapNestedMediaElements = html => {
|
|
221
|
-
const parser = new DOMParser();
|
|
222
|
-
let doc = parser.parseFromString(html, 'text/html');
|
|
223
|
-
const wrapper = doc.body;
|
|
224
|
-
|
|
225
|
-
// Remove Google Doc's wrapper <b> el
|
|
226
|
-
const docsWrapper = wrapper.querySelector('b[id^="docs-internal-guid-"]');
|
|
227
|
-
if (docsWrapper) {
|
|
228
|
-
unwrap(wrapper, docsWrapper);
|
|
229
|
-
}
|
|
230
|
-
const imageTags = wrapper.querySelectorAll('img');
|
|
231
|
-
if (!imageTags.length) {
|
|
232
|
-
return html;
|
|
233
|
-
}
|
|
234
|
-
imageTags.forEach(imageTag => {
|
|
235
|
-
// Capture the immediate parent, we may remove the media from here later.
|
|
236
|
-
const mediaParent = imageTag.parentElement;
|
|
237
|
-
if (!mediaParent) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// If either the parent or the image itself contains styles that would make
|
|
242
|
-
// them invisible on copy, dont paste them.
|
|
243
|
-
if (isElementInvisible(mediaParent) || isElementInvisible(imageTag)) {
|
|
244
|
-
mediaParent.removeChild(imageTag);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// If its wrapped by a valid container we assume its safe to bypass.
|
|
249
|
-
// ProseMirror should handle these cases properly.
|
|
250
|
-
if (canContainImage(mediaParent) || mediaParent instanceof HTMLSpanElement && mediaParent.closest('[class*="emoji-common"]')) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Find the top most element that the parent has a valid container for the image.
|
|
255
|
-
// Stop just before found the wrapper
|
|
256
|
-
const insertBeforeElement = walkUpTreeUntil(mediaParent, element => {
|
|
257
|
-
// If is at the top just use this element as reference
|
|
258
|
-
if (element.parentElement === wrapper) {
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
return canContainImage(element.parentElement);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// Here we try to insert the media right after its top most valid parent element
|
|
265
|
-
// Unless its the last element in our structure then we will insert above it.
|
|
266
|
-
if (insertBeforeElement && insertBeforeElement.parentElement) {
|
|
267
|
-
// Insert as close as possible to the most closest valid element index in the tree.
|
|
268
|
-
insertBeforeElement.parentElement.insertBefore(imageTag, insertBeforeElement.nextElementSibling || insertBeforeElement);
|
|
269
|
-
|
|
270
|
-
// Attempt to clean up lines left behind by the image
|
|
271
|
-
mediaParent.innerText = mediaParent.innerText.trim();
|
|
272
|
-
// Walk up and delete empty elements left over after removing the image tag
|
|
273
|
-
removeNestedEmptyEls(mediaParent);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// If last child is a hardbreak we don't want it
|
|
278
|
-
if (wrapper.lastElementChild && wrapper.lastElementChild.tagName === 'BR') {
|
|
279
|
-
wrapper.removeChild(wrapper.lastElementChild);
|
|
280
|
-
}
|
|
281
|
-
return wrapper.innerHTML;
|
|
282
|
-
};
|
|
283
178
|
export const getMediaNodeFromSelection = state => {
|
|
284
179
|
if (!isSelectionMediaSingleNode(state)) {
|
|
285
180
|
return null;
|