@atlaskit/editor-core 187.18.0 → 187.18.2

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 (100) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/labs/next/presets/universal.js +2 -1
  3. package/dist/cjs/plugins/help-dialog/ui/index.js +26 -27
  4. package/dist/cjs/plugins/index.js +0 -7
  5. package/dist/cjs/plugins/list/index.js +5 -5
  6. package/dist/cjs/plugins/list/transforms.js +1 -223
  7. package/dist/cjs/plugins/paste/commands.js +224 -2
  8. package/dist/cjs/plugins/paste/pm-plugins/main.js +5 -9
  9. package/dist/cjs/plugins/toolbar-lists-indentation/ui/Toolbar.js +3 -3
  10. package/dist/cjs/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +4 -4
  11. package/dist/cjs/utils/clipboard.js +5 -27
  12. package/dist/cjs/version-wrapper.js +1 -1
  13. package/dist/cjs/version.json +1 -1
  14. package/dist/es2019/labs/next/presets/universal.js +2 -1
  15. package/dist/es2019/plugins/help-dialog/ui/index.js +1 -2
  16. package/dist/es2019/plugins/index.js +0 -1
  17. package/dist/es2019/plugins/list/index.js +1 -1
  18. package/dist/es2019/plugins/list/transforms.js +2 -210
  19. package/dist/es2019/plugins/paste/commands.js +210 -2
  20. package/dist/es2019/plugins/paste/pm-plugins/main.js +3 -3
  21. package/dist/es2019/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  22. package/dist/es2019/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  23. package/dist/es2019/utils/clipboard.js +0 -16
  24. package/dist/es2019/version-wrapper.js +1 -1
  25. package/dist/es2019/version.json +1 -1
  26. package/dist/esm/labs/next/presets/universal.js +2 -1
  27. package/dist/esm/plugins/help-dialog/ui/index.js +1 -2
  28. package/dist/esm/plugins/index.js +0 -1
  29. package/dist/esm/plugins/list/index.js +1 -1
  30. package/dist/esm/plugins/list/transforms.js +2 -219
  31. package/dist/esm/plugins/paste/commands.js +218 -1
  32. package/dist/esm/plugins/paste/pm-plugins/main.js +3 -3
  33. package/dist/esm/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  34. package/dist/esm/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  35. package/dist/esm/utils/clipboard.js +4 -23
  36. package/dist/esm/version-wrapper.js +1 -1
  37. package/dist/esm/version.json +1 -1
  38. package/dist/types/plugins/index.d.ts +0 -1
  39. package/dist/types/plugins/insert-block/index.d.ts +1 -1
  40. package/dist/types/plugins/list/transforms.d.ts +0 -13
  41. package/dist/types/plugins/paste/commands.d.ts +14 -0
  42. package/dist/types/plugins/paste/index.d.ts +2 -0
  43. package/dist/types/utils/clipboard.d.ts +0 -3
  44. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  45. package/dist/types-ts4.5/plugins/insert-block/index.d.ts +1 -1
  46. package/dist/types-ts4.5/plugins/list/transforms.d.ts +0 -13
  47. package/dist/types-ts4.5/plugins/paste/commands.d.ts +14 -0
  48. package/dist/types-ts4.5/plugins/paste/index.d.ts +2 -0
  49. package/dist/types-ts4.5/utils/clipboard.d.ts +0 -3
  50. package/package.json +4 -3
  51. package/dist/cjs/plugins/image-upload/index.js +0 -45
  52. package/dist/cjs/plugins/image-upload/pm-plugins/actions.js +0 -19
  53. package/dist/cjs/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -19
  54. package/dist/cjs/plugins/image-upload/pm-plugins/commands.js +0 -40
  55. package/dist/cjs/plugins/image-upload/pm-plugins/input-rule.js +0 -31
  56. package/dist/cjs/plugins/image-upload/pm-plugins/main.js +0 -194
  57. package/dist/cjs/plugins/image-upload/pm-plugins/plugin-key.js +0 -9
  58. package/dist/cjs/plugins/image-upload/types.js +0 -5
  59. package/dist/cjs/plugins/image-upload/utils.js +0 -40
  60. package/dist/cjs/utils/drag-drop.js +0 -19
  61. package/dist/es2019/plugins/image-upload/index.js +0 -34
  62. package/dist/es2019/plugins/image-upload/pm-plugins/actions.js +0 -8
  63. package/dist/es2019/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -12
  64. package/dist/es2019/plugins/image-upload/pm-plugins/commands.js +0 -28
  65. package/dist/es2019/plugins/image-upload/pm-plugins/input-rule.js +0 -25
  66. package/dist/es2019/plugins/image-upload/pm-plugins/main.js +0 -159
  67. package/dist/es2019/plugins/image-upload/pm-plugins/plugin-key.js +0 -2
  68. package/dist/es2019/plugins/image-upload/types.js +0 -1
  69. package/dist/es2019/plugins/image-upload/utils.js +0 -38
  70. package/dist/es2019/utils/drag-drop.js +0 -9
  71. package/dist/esm/plugins/image-upload/index.js +0 -37
  72. package/dist/esm/plugins/image-upload/pm-plugins/actions.js +0 -12
  73. package/dist/esm/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -12
  74. package/dist/esm/plugins/image-upload/pm-plugins/commands.js +0 -32
  75. package/dist/esm/plugins/image-upload/pm-plugins/input-rule.js +0 -23
  76. package/dist/esm/plugins/image-upload/pm-plugins/main.js +0 -186
  77. package/dist/esm/plugins/image-upload/pm-plugins/plugin-key.js +0 -2
  78. package/dist/esm/plugins/image-upload/types.js +0 -1
  79. package/dist/esm/plugins/image-upload/utils.js +0 -31
  80. package/dist/esm/utils/drag-drop.js +0 -11
  81. package/dist/types/plugins/image-upload/index.d.ts +0 -16
  82. package/dist/types/plugins/image-upload/pm-plugins/actions.d.ts +0 -3
  83. package/dist/types/plugins/image-upload/pm-plugins/commands-toolbar.d.ts +0 -3
  84. package/dist/types/plugins/image-upload/pm-plugins/commands.d.ts +0 -5
  85. package/dist/types/plugins/image-upload/pm-plugins/input-rule.d.ts +0 -5
  86. package/dist/types/plugins/image-upload/pm-plugins/main.d.ts +0 -4
  87. package/dist/types/plugins/image-upload/pm-plugins/plugin-key.d.ts +0 -3
  88. package/dist/types/plugins/image-upload/types.d.ts +0 -18
  89. package/dist/types/plugins/image-upload/utils.d.ts +0 -5
  90. package/dist/types/utils/drag-drop.d.ts +0 -2
  91. package/dist/types-ts4.5/plugins/image-upload/index.d.ts +0 -16
  92. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/actions.d.ts +0 -3
  93. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/commands-toolbar.d.ts +0 -3
  94. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/commands.d.ts +0 -5
  95. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/input-rule.d.ts +0 -5
  96. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/main.d.ts +0 -4
  97. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/plugin-key.d.ts +0 -3
  98. package/dist/types-ts4.5/plugins/image-upload/types.d.ts +0 -18
  99. package/dist/types-ts4.5/plugins/image-upload/utils.d.ts +0 -5
  100. package/dist/types-ts4.5/utils/drag-drop.d.ts +0 -2
@@ -1,159 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { isClipboardEvent, isPastedFile } from '../../../utils/clipboard';
3
- import { isDragEvent, isDroppedFile } from '../../../utils/drag-drop';
4
- import { canInsertMedia, isMediaSelected } from '../utils';
5
- import { insertExternalImage, startImageUpload } from './commands';
6
- import { stateKey } from './plugin-key';
7
- /**
8
- * Microsoft Office includes a screenshot image when copying text content.
9
- *
10
- * This function determines whether or not we can ignore the image if it
11
- * came from MS Office. We do this by checking for
12
- *
13
- * - plain text
14
- * - HTML text which includes the MS Office namespace
15
- * - the number of files and the file name/type
16
- *
17
- * It is easy to manually verify this using by using Office on Mac
18
- * (or Excel if on Windows) and pasting into
19
- * https://evercoder.github.io/clipboard-inspector/
20
- *
21
- * Note: image content in Word is stored in the `text/html` portion
22
- * of the clipboard, not under `files` attachment like the screenshot.
23
- *
24
- * @returns boolean True if the paste event contains a screenshot from MS Office
25
- */
26
- const hasScreenshotImageFromMSOffice = ev => {
27
- const {
28
- clipboardData
29
- } = ev;
30
- if (!clipboardData || clipboardData.files.length !== 1) {
31
- return false;
32
- }
33
- const textPlain = !!clipboardData.getData('text/plain');
34
- const textHtml = clipboardData.getData('text/html');
35
- const isOfficeXMLNamespace = textHtml.includes('urn:schemas-microsoft-com:office:office');
36
- const file = clipboardData.files[0];
37
- const isImagePNG = file.type === 'image/png' && file.name === 'image.png';
38
- return isImagePNG && textPlain && isOfficeXMLNamespace;
39
- };
40
- const createReferenceEventFromEvent = event => {
41
- var _event$dataTransfer, _event$clipboardData;
42
- if (!isDragEvent(event) && !isClipboardEvent(event)) {
43
- return null;
44
- }
45
-
46
- // Get files list and early exit if files is undefined
47
- const files = isDragEvent(event) ? (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.files;
48
- if (!files) {
49
- return null;
50
- }
51
-
52
- // Convert filelist into an array
53
- const filesArray = Array.from(files);
54
-
55
- // Creating a new DataTransfer object should remove any mutation that could be possible from the original event
56
- const dataTransfer = filesArray.reduce((acc, value) => {
57
- acc.items.add(value);
58
- return acc;
59
- }, new DataTransfer());
60
- return {
61
- type: isDragEvent(event) ? 'drop' : 'paste',
62
- ...(isDragEvent(event) && {
63
- dataTransfer
64
- }),
65
- ...(isClipboardEvent(event) && {
66
- clipboardData: dataTransfer
67
- })
68
- };
69
- };
70
- const createDOMHandler = (pred, _eventName, uploadHandlerReference) => (view, event) => {
71
- if (!pred(event)) {
72
- return false;
73
- }
74
- const shouldUpload = !hasScreenshotImageFromMSOffice(event);
75
- const referenceEvent = createReferenceEventFromEvent(event);
76
- if (shouldUpload && referenceEvent) {
77
- event.preventDefault();
78
- event.stopPropagation();
79
-
80
- // Insert external image into document
81
- if (uploadHandlerReference.current) {
82
- uploadHandlerReference.current(referenceEvent, options => {
83
- insertExternalImage(options)(view.state, view.dispatch);
84
- });
85
- }
86
-
87
- // Start image upload
88
- startImageUpload(referenceEvent)(view.state, view.dispatch);
89
- }
90
- return shouldUpload;
91
- };
92
- const getNewActiveUpload = (tr, pluginState) => {
93
- const meta = tr.getMeta(stateKey);
94
- if (meta && meta.name === 'START_UPLOAD') {
95
- return {
96
- event: meta.event
97
- };
98
- }
99
- return pluginState.activeUpload;
100
- };
101
- export const createPlugin = uploadHandlerReference => ({
102
- dispatch,
103
- providerFactory
104
- }) => {
105
- return new SafePlugin({
106
- state: {
107
- init(_config, state) {
108
- return {
109
- active: false,
110
- enabled: canInsertMedia(state),
111
- hidden: !state.schema.nodes.media || !state.schema.nodes.mediaSingle
112
- };
113
- },
114
- apply(tr, pluginState, _oldState, newState) {
115
- const newActive = isMediaSelected(newState);
116
- const newEnabled = canInsertMedia(newState);
117
- const newActiveUpload = getNewActiveUpload(tr, pluginState);
118
- if (newActive !== pluginState.active || newEnabled !== pluginState.enabled || newActiveUpload !== pluginState.activeUpload) {
119
- const newPluginState = {
120
- ...pluginState,
121
- active: newActive,
122
- enabled: newEnabled,
123
- activeUpload: newActiveUpload
124
- };
125
- dispatch(stateKey, newPluginState);
126
- return newPluginState;
127
- }
128
- return pluginState;
129
- }
130
- },
131
- key: stateKey,
132
- view: () => {
133
- const handleProvider = async (name, provider) => {
134
- if (name !== 'imageUploadProvider' || !provider) {
135
- return;
136
- }
137
- try {
138
- const imageUploadProvider = await provider;
139
- uploadHandlerReference.current = imageUploadProvider;
140
- } catch (e) {
141
- uploadHandlerReference.current = null;
142
- }
143
- };
144
- providerFactory.subscribe('imageUploadProvider', handleProvider);
145
- return {
146
- destroy() {
147
- uploadHandlerReference.current = null;
148
- providerFactory.unsubscribe('imageUploadProvider', handleProvider);
149
- }
150
- };
151
- },
152
- props: {
153
- handleDOMEvents: {
154
- drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop', uploadHandlerReference),
155
- paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste', uploadHandlerReference)
156
- }
157
- }
158
- });
159
- };
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const stateKey = new PluginKey('imageUploadPlugin');
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
- export const isMediaSelected = state => {
3
- const {
4
- media
5
- } = state.schema.nodes;
6
- return state.selection instanceof NodeSelection && state.selection.node.type === media;
7
- };
8
- export const canInsertMedia = state => {
9
- const {
10
- mediaSingle
11
- } = state.schema.nodes;
12
- const {
13
- $to
14
- } = state.selection;
15
- if (mediaSingle) {
16
- for (let d = $to.depth; d >= 0; d--) {
17
- let index = $to.index(d);
18
- if ($to.node(d).canReplaceWith(index, index, mediaSingle)) {
19
- return true;
20
- }
21
- }
22
- }
23
- return false;
24
- };
25
- export const createExternalMediaNode = (url, schema) => {
26
- const {
27
- media,
28
- mediaSingle
29
- } = schema.nodes;
30
- if (!media || !mediaSingle) {
31
- return null;
32
- }
33
- const mediaNode = media.createChecked({
34
- type: 'external',
35
- url
36
- });
37
- return mediaSingle.createChecked({}, mediaNode);
38
- };
@@ -1,9 +0,0 @@
1
- // Typeguard Function
2
- export const isDragEvent = event => 'dataTransfer' in event;
3
- export function isDroppedFile(rawEvent) {
4
- const e = rawEvent;
5
- if (!e.dataTransfer) {
6
- return false;
7
- }
8
- return Array.prototype.slice.call(e.dataTransfer.types).indexOf('Files') !== -1;
9
- }
@@ -1,37 +0,0 @@
1
- import { createPlugin } from './pm-plugins/main';
2
- import inputRulePlugin from './pm-plugins/input-rule';
3
- import { stateKey } from './pm-plugins/plugin-key';
4
- import { insertActionForToolbar } from './pm-plugins/commands-toolbar';
5
- var imageUpload = function imageUpload() {
6
- var uploadHandlerReference = {
7
- current: null
8
- };
9
- return {
10
- name: 'imageUpload',
11
- getSharedState: function getSharedState(editorState) {
12
- if (!editorState) {
13
- return undefined;
14
- }
15
- return stateKey.getState(editorState);
16
- },
17
- actions: {
18
- startUpload: function startUpload() {
19
- return insertActionForToolbar(uploadHandlerReference);
20
- }
21
- },
22
- pmPlugins: function pmPlugins() {
23
- return [{
24
- name: 'imageUpload',
25
- plugin: createPlugin(uploadHandlerReference)
26
- }, {
27
- name: 'imageUploadInputRule',
28
- plugin: function plugin(_ref) {
29
- var schema = _ref.schema,
30
- featureFlags = _ref.featureFlags;
31
- return inputRulePlugin(schema, featureFlags);
32
- }
33
- }];
34
- }
35
- };
36
- };
37
- export default imageUpload;
@@ -1,12 +0,0 @@
1
- import { stateKey } from './plugin-key';
2
- var imageUploadAction = function imageUploadAction(tr, action) {
3
- return tr.setMeta(stateKey, action);
4
- };
5
- export var startUpload = function startUpload(event) {
6
- return function (tr) {
7
- return imageUploadAction(tr, {
8
- name: 'START_UPLOAD',
9
- event: event
10
- });
11
- };
12
- };
@@ -1,12 +0,0 @@
1
- import { insertExternalImage } from './commands';
2
- export var insertActionForToolbar = function insertActionForToolbar(uploadHandlerReference) {
3
- return function (state, dispatch) {
4
- if (!uploadHandlerReference.current) {
5
- return false;
6
- }
7
- uploadHandlerReference.current(undefined, function (options) {
8
- insertExternalImage(options)(state, dispatch);
9
- });
10
- return true;
11
- };
12
- };
@@ -1,32 +0,0 @@
1
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
2
- import { createExternalMediaNode } from '../utils';
3
- import { startUpload } from './actions';
4
- import { stateKey } from './plugin-key';
5
- export var insertExternalImage = function insertExternalImage(options) {
6
- return function (state, dispatch) {
7
- var pluginState = stateKey.getState(state);
8
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.enabled) || !options.src) {
9
- return false;
10
- }
11
- var mediaNode = createExternalMediaNode(options.src, state.schema);
12
- if (!mediaNode) {
13
- return false;
14
- }
15
- if (dispatch) {
16
- dispatch(safeInsert(mediaNode, state.selection.$to.pos)(state.tr).scrollIntoView());
17
- }
18
- return true;
19
- };
20
- };
21
- export var startImageUpload = function startImageUpload(event) {
22
- return function (state, dispatch) {
23
- var pluginState = stateKey.getState(state);
24
- if (pluginState && !pluginState.enabled) {
25
- return false;
26
- }
27
- if (dispatch) {
28
- dispatch(startUpload(event)(state.tr));
29
- }
30
- return true;
31
- };
32
- };
@@ -1,23 +0,0 @@
1
- import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
2
- import { createExternalMediaNode } from '../utils';
3
- export function inputRulePlugin(schema, featureFlags) {
4
- if (!schema.nodes.media || !schema.nodes.mediaSingle) {
5
- return;
6
- }
7
-
8
- // ![something](link) should convert to an image
9
- var imageRule = createRule(/!\[(.*)\]\((\S+)\)$/, function (state, match, start, end) {
10
- var schema = state.schema;
11
- var attrs = {
12
- src: match[2],
13
- alt: match[1]
14
- };
15
- var node = createExternalMediaNode(attrs.src, schema);
16
- if (node) {
17
- return state.tr.replaceWith(start, end, node);
18
- }
19
- return null;
20
- });
21
- return createPlugin('image-upload', [imageRule]);
22
- }
23
- export default inputRulePlugin;
@@ -1,186 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
- import { isClipboardEvent, isPastedFile } from '../../../utils/clipboard';
8
- import { isDragEvent, isDroppedFile } from '../../../utils/drag-drop';
9
- import { canInsertMedia, isMediaSelected } from '../utils';
10
- import { insertExternalImage, startImageUpload } from './commands';
11
- import { stateKey } from './plugin-key';
12
- /**
13
- * Microsoft Office includes a screenshot image when copying text content.
14
- *
15
- * This function determines whether or not we can ignore the image if it
16
- * came from MS Office. We do this by checking for
17
- *
18
- * - plain text
19
- * - HTML text which includes the MS Office namespace
20
- * - the number of files and the file name/type
21
- *
22
- * It is easy to manually verify this using by using Office on Mac
23
- * (or Excel if on Windows) and pasting into
24
- * https://evercoder.github.io/clipboard-inspector/
25
- *
26
- * Note: image content in Word is stored in the `text/html` portion
27
- * of the clipboard, not under `files` attachment like the screenshot.
28
- *
29
- * @returns boolean True if the paste event contains a screenshot from MS Office
30
- */
31
- var hasScreenshotImageFromMSOffice = function hasScreenshotImageFromMSOffice(ev) {
32
- var _ref = ev,
33
- clipboardData = _ref.clipboardData;
34
- if (!clipboardData || clipboardData.files.length !== 1) {
35
- return false;
36
- }
37
- var textPlain = !!clipboardData.getData('text/plain');
38
- var textHtml = clipboardData.getData('text/html');
39
- var isOfficeXMLNamespace = textHtml.includes('urn:schemas-microsoft-com:office:office');
40
- var file = clipboardData.files[0];
41
- var isImagePNG = file.type === 'image/png' && file.name === 'image.png';
42
- return isImagePNG && textPlain && isOfficeXMLNamespace;
43
- };
44
- var createReferenceEventFromEvent = function createReferenceEventFromEvent(event) {
45
- var _event$dataTransfer, _event$clipboardData;
46
- if (!isDragEvent(event) && !isClipboardEvent(event)) {
47
- return null;
48
- }
49
-
50
- // Get files list and early exit if files is undefined
51
- var files = isDragEvent(event) ? (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.files;
52
- if (!files) {
53
- return null;
54
- }
55
-
56
- // Convert filelist into an array
57
- var filesArray = Array.from(files);
58
-
59
- // Creating a new DataTransfer object should remove any mutation that could be possible from the original event
60
- var dataTransfer = filesArray.reduce(function (acc, value) {
61
- acc.items.add(value);
62
- return acc;
63
- }, new DataTransfer());
64
- return _objectSpread(_objectSpread({
65
- type: isDragEvent(event) ? 'drop' : 'paste'
66
- }, isDragEvent(event) && {
67
- dataTransfer: dataTransfer
68
- }), isClipboardEvent(event) && {
69
- clipboardData: dataTransfer
70
- });
71
- };
72
- var createDOMHandler = function createDOMHandler(pred, _eventName, uploadHandlerReference) {
73
- return function (view, event) {
74
- if (!pred(event)) {
75
- return false;
76
- }
77
- var shouldUpload = !hasScreenshotImageFromMSOffice(event);
78
- var referenceEvent = createReferenceEventFromEvent(event);
79
- if (shouldUpload && referenceEvent) {
80
- event.preventDefault();
81
- event.stopPropagation();
82
-
83
- // Insert external image into document
84
- if (uploadHandlerReference.current) {
85
- uploadHandlerReference.current(referenceEvent, function (options) {
86
- insertExternalImage(options)(view.state, view.dispatch);
87
- });
88
- }
89
-
90
- // Start image upload
91
- startImageUpload(referenceEvent)(view.state, view.dispatch);
92
- }
93
- return shouldUpload;
94
- };
95
- };
96
- var getNewActiveUpload = function getNewActiveUpload(tr, pluginState) {
97
- var meta = tr.getMeta(stateKey);
98
- if (meta && meta.name === 'START_UPLOAD') {
99
- return {
100
- event: meta.event
101
- };
102
- }
103
- return pluginState.activeUpload;
104
- };
105
- export var createPlugin = function createPlugin(uploadHandlerReference) {
106
- return function (_ref2) {
107
- var dispatch = _ref2.dispatch,
108
- providerFactory = _ref2.providerFactory;
109
- return new SafePlugin({
110
- state: {
111
- init: function init(_config, state) {
112
- return {
113
- active: false,
114
- enabled: canInsertMedia(state),
115
- hidden: !state.schema.nodes.media || !state.schema.nodes.mediaSingle
116
- };
117
- },
118
- apply: function apply(tr, pluginState, _oldState, newState) {
119
- var newActive = isMediaSelected(newState);
120
- var newEnabled = canInsertMedia(newState);
121
- var newActiveUpload = getNewActiveUpload(tr, pluginState);
122
- if (newActive !== pluginState.active || newEnabled !== pluginState.enabled || newActiveUpload !== pluginState.activeUpload) {
123
- var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
124
- active: newActive,
125
- enabled: newEnabled,
126
- activeUpload: newActiveUpload
127
- });
128
- dispatch(stateKey, newPluginState);
129
- return newPluginState;
130
- }
131
- return pluginState;
132
- }
133
- },
134
- key: stateKey,
135
- view: function view() {
136
- var handleProvider = /*#__PURE__*/function () {
137
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name, provider) {
138
- var imageUploadProvider;
139
- return _regeneratorRuntime.wrap(function _callee$(_context) {
140
- while (1) switch (_context.prev = _context.next) {
141
- case 0:
142
- if (!(name !== 'imageUploadProvider' || !provider)) {
143
- _context.next = 2;
144
- break;
145
- }
146
- return _context.abrupt("return");
147
- case 2:
148
- _context.prev = 2;
149
- _context.next = 5;
150
- return provider;
151
- case 5:
152
- imageUploadProvider = _context.sent;
153
- uploadHandlerReference.current = imageUploadProvider;
154
- _context.next = 12;
155
- break;
156
- case 9:
157
- _context.prev = 9;
158
- _context.t0 = _context["catch"](2);
159
- uploadHandlerReference.current = null;
160
- case 12:
161
- case "end":
162
- return _context.stop();
163
- }
164
- }, _callee, null, [[2, 9]]);
165
- }));
166
- return function handleProvider(_x, _x2) {
167
- return _ref3.apply(this, arguments);
168
- };
169
- }();
170
- providerFactory.subscribe('imageUploadProvider', handleProvider);
171
- return {
172
- destroy: function destroy() {
173
- uploadHandlerReference.current = null;
174
- providerFactory.unsubscribe('imageUploadProvider', handleProvider);
175
- }
176
- };
177
- },
178
- props: {
179
- handleDOMEvents: {
180
- drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop', uploadHandlerReference),
181
- paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste', uploadHandlerReference)
182
- }
183
- }
184
- });
185
- };
186
- };
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var stateKey = new PluginKey('imageUploadPlugin');
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
- export var isMediaSelected = function isMediaSelected(state) {
3
- var media = state.schema.nodes.media;
4
- return state.selection instanceof NodeSelection && state.selection.node.type === media;
5
- };
6
- export var canInsertMedia = function canInsertMedia(state) {
7
- var mediaSingle = state.schema.nodes.mediaSingle;
8
- var $to = state.selection.$to;
9
- if (mediaSingle) {
10
- for (var d = $to.depth; d >= 0; d--) {
11
- var index = $to.index(d);
12
- if ($to.node(d).canReplaceWith(index, index, mediaSingle)) {
13
- return true;
14
- }
15
- }
16
- }
17
- return false;
18
- };
19
- export var createExternalMediaNode = function createExternalMediaNode(url, schema) {
20
- var _schema$nodes = schema.nodes,
21
- media = _schema$nodes.media,
22
- mediaSingle = _schema$nodes.mediaSingle;
23
- if (!media || !mediaSingle) {
24
- return null;
25
- }
26
- var mediaNode = media.createChecked({
27
- type: 'external',
28
- url: url
29
- });
30
- return mediaSingle.createChecked({}, mediaNode);
31
- };
@@ -1,11 +0,0 @@
1
- // Typeguard Function
2
- export var isDragEvent = function isDragEvent(event) {
3
- return 'dataTransfer' in event;
4
- };
5
- export function isDroppedFile(rawEvent) {
6
- var e = rawEvent;
7
- if (!e.dataTransfer) {
8
- return false;
9
- }
10
- return Array.prototype.slice.call(e.dataTransfer.types).indexOf('Files') !== -1;
11
- }
@@ -1,16 +0,0 @@
1
- import type { Command, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
- type ImageUploadActions = {
3
- startUpload: () => Command;
4
- };
5
- type ImageUploadSharedState = {
6
- active: boolean;
7
- enabled: boolean;
8
- hidden: boolean;
9
- };
10
- type ImageUploadPlugin = NextEditorPlugin<'imageUpload', {
11
- actions: ImageUploadActions;
12
- sharedState: ImageUploadSharedState | undefined;
13
- }>;
14
- declare const imageUpload: ImageUploadPlugin;
15
- export default imageUpload;
16
- export type { ImageUploadPlugin };
@@ -1,3 +0,0 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import type { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
3
- export declare const startUpload: (event?: ImageUploadPluginReferenceEvent) => (tr: Transaction) => Transaction;
@@ -1,3 +0,0 @@
1
- import type { Command } from '../../../types';
2
- import type { UploadHandlerReference } from '../types';
3
- export declare const insertActionForToolbar: (uploadHandlerReference: UploadHandlerReference) => Command;
@@ -1,5 +0,0 @@
1
- import type { InsertedImageProperties } from '@atlaskit/editor-common/provider-factory';
2
- import type { Command } from '../../../types';
3
- import type { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
4
- export declare const insertExternalImage: (options: InsertedImageProperties) => Command;
5
- export declare const startImageUpload: (event?: ImageUploadPluginReferenceEvent) => Command;
@@ -1,5 +0,0 @@
1
- import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
- import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { FeatureFlags } from '../../../types/feature-flags';
4
- export declare function inputRulePlugin(schema: Schema, featureFlags: FeatureFlags): SafePlugin | undefined;
5
- export default inputRulePlugin;
@@ -1,4 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { ImageUploadPluginState, UploadHandlerReference } from '../types';
3
- import type { PMPluginFactoryParams } from '../../../types';
4
- export declare const createPlugin: (uploadHandlerReference: UploadHandlerReference) => ({ dispatch, providerFactory }: PMPluginFactoryParams) => SafePlugin<ImageUploadPluginState>;
@@ -1,3 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- import type { ImageUploadPluginState } from '../types';
3
- export declare const stateKey: PluginKey<ImageUploadPluginState>;
@@ -1,18 +0,0 @@
1
- import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
2
- import type { ImageUploadProvider } from '@atlaskit/editor-common/provider-factory';
3
- export type { InsertedImageProperties, ImageUploadProvider as ImageUploadHandler, } from '@atlaskit/editor-common/provider-factory';
4
- export type ImageUploadPluginAction = {
5
- name: 'START_UPLOAD';
6
- event?: ImageUploadPluginReferenceEvent;
7
- };
8
- export type ImageUploadPluginState = {
9
- active: boolean;
10
- enabled: boolean;
11
- hidden: boolean;
12
- activeUpload?: {
13
- event?: ImageUploadPluginReferenceEvent;
14
- };
15
- };
16
- export type UploadHandlerReference = {
17
- current: ImageUploadProvider | null;
18
- };
@@ -1,5 +0,0 @@
1
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- import type { Schema, Node } from '@atlaskit/editor-prosemirror/model';
3
- export declare const isMediaSelected: (state: EditorState) => boolean;
4
- export declare const canInsertMedia: (state: EditorState) => boolean;
5
- export declare const createExternalMediaNode: (url: string, schema: Schema) => Node | null;
@@ -1,2 +0,0 @@
1
- export declare const isDragEvent: (event: Event) => event is DragEvent;
2
- export declare function isDroppedFile(rawEvent: Event): boolean;