@atlaskit/editor-plugin-paste-options-toolbar 0.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +9 -0
  4. package/dist/cjs/actions.js +15 -0
  5. package/dist/cjs/commands.js +146 -0
  6. package/dist/cjs/index.js +12 -0
  7. package/dist/cjs/messages.js +29 -0
  8. package/dist/cjs/plugin.js +67 -0
  9. package/dist/cjs/pm-plugins/constants.js +13 -0
  10. package/dist/cjs/pm-plugins/main.js +66 -0
  11. package/dist/cjs/pm-plugins/plugin-factory.js +31 -0
  12. package/dist/cjs/reducer.js +50 -0
  13. package/dist/cjs/styles.js +12 -0
  14. package/dist/cjs/toolbar.js +95 -0
  15. package/dist/cjs/types.js +15 -0
  16. package/dist/cjs/ui/paste-icon.js +22 -0
  17. package/dist/cjs/ui/styles.js +12 -0
  18. package/dist/cjs/util/format-handlers.js +186 -0
  19. package/dist/cjs/util/index.js +45 -0
  20. package/dist/es2019/actions.js +9 -0
  21. package/dist/es2019/commands.js +134 -0
  22. package/dist/es2019/index.js +1 -0
  23. package/dist/es2019/messages.js +23 -0
  24. package/dist/es2019/plugin.js +64 -0
  25. package/dist/es2019/pm-plugins/constants.js +7 -0
  26. package/dist/es2019/pm-plugins/main.js +63 -0
  27. package/dist/es2019/pm-plugins/plugin-factory.js +23 -0
  28. package/dist/es2019/reducer.js +44 -0
  29. package/dist/es2019/styles.js +1 -0
  30. package/dist/es2019/toolbar.js +92 -0
  31. package/dist/es2019/types.js +9 -0
  32. package/dist/es2019/ui/paste-icon.js +14 -0
  33. package/dist/es2019/ui/styles.js +10 -0
  34. package/dist/es2019/util/format-handlers.js +196 -0
  35. package/dist/es2019/util/index.js +37 -0
  36. package/dist/esm/actions.js +9 -0
  37. package/dist/esm/commands.js +140 -0
  38. package/dist/esm/index.js +1 -0
  39. package/dist/esm/messages.js +23 -0
  40. package/dist/esm/plugin.js +61 -0
  41. package/dist/esm/pm-plugins/constants.js +7 -0
  42. package/dist/esm/pm-plugins/main.js +60 -0
  43. package/dist/esm/pm-plugins/plugin-factory.js +25 -0
  44. package/dist/esm/reducer.js +43 -0
  45. package/dist/esm/styles.js +1 -0
  46. package/dist/esm/toolbar.js +88 -0
  47. package/dist/esm/types.js +9 -0
  48. package/dist/esm/ui/paste-icon.js +16 -0
  49. package/dist/esm/ui/styles.js +5 -0
  50. package/dist/esm/util/format-handlers.js +178 -0
  51. package/dist/esm/util/index.js +37 -0
  52. package/dist/types/actions.d.ts +34 -0
  53. package/dist/types/commands.d.ts +16 -0
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/messages.d.ts +22 -0
  56. package/dist/types/plugin.d.ts +6 -0
  57. package/dist/types/pm-plugins/constants.d.ts +7 -0
  58. package/dist/types/pm-plugins/main.d.ts +3 -0
  59. package/dist/types/pm-plugins/plugin-factory.d.ts +2 -0
  60. package/dist/types/reducer.d.ts +3 -0
  61. package/dist/types/styles.d.ts +1 -0
  62. package/dist/types/toolbar.d.ts +9 -0
  63. package/dist/types/types.d.ts +25 -0
  64. package/dist/types/ui/paste-icon.d.ts +5 -0
  65. package/dist/types/ui/styles.d.ts +1 -0
  66. package/dist/types/util/format-handlers.d.ts +9 -0
  67. package/dist/types/util/index.d.ts +7 -0
  68. package/dist/types-ts4.5/actions.d.ts +34 -0
  69. package/dist/types-ts4.5/commands.d.ts +16 -0
  70. package/dist/types-ts4.5/index.d.ts +1 -0
  71. package/dist/types-ts4.5/messages.d.ts +22 -0
  72. package/dist/types-ts4.5/plugin.d.ts +9 -0
  73. package/dist/types-ts4.5/pm-plugins/constants.d.ts +7 -0
  74. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -0
  75. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +2 -0
  76. package/dist/types-ts4.5/reducer.d.ts +3 -0
  77. package/dist/types-ts4.5/styles.d.ts +1 -0
  78. package/dist/types-ts4.5/toolbar.d.ts +9 -0
  79. package/dist/types-ts4.5/types.d.ts +25 -0
  80. package/dist/types-ts4.5/ui/paste-icon.d.ts +5 -0
  81. package/dist/types-ts4.5/ui/styles.d.ts +1 -0
  82. package/dist/types-ts4.5/util/format-handlers.d.ts +9 -0
  83. package/dist/types-ts4.5/util/index.d.ts +7 -0
  84. package/package.json +114 -0
  85. package/report.api.md +46 -0
  86. package/styles/package.json +15 -0
  87. package/tmp/api-report-tmp.d.ts +19 -0
@@ -0,0 +1,25 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { pluginFactory } from '@atlaskit/editor-common/utils';
5
+ import { reducer } from '../reducer';
6
+ import { pasteOptionsPluginKey } from '../types';
7
+ var _pluginFactory = pluginFactory(pasteOptionsPluginKey, reducer, {
8
+ mapping: function mapping(tr, pluginState) {
9
+ return pluginState;
10
+ },
11
+ onSelectionChanged: function onSelectionChanged(tr, pluginState) {
12
+ // Detect click outside the editor
13
+ if (tr.getMeta('outsideProsemirrorEditorClicked')) {
14
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
15
+ showToolbar: false,
16
+ highlightContent: false
17
+ });
18
+ }
19
+ return pluginState;
20
+ }
21
+ }),
22
+ createPluginState = _pluginFactory.createPluginState,
23
+ createCommand = _pluginFactory.createCommand,
24
+ getPluginState = _pluginFactory.getPluginState;
25
+ export { createPluginState, createCommand, getPluginState };
@@ -0,0 +1,43 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { PastePluginActionTypes as ActionTypes } from './actions';
5
+ export var reducer = function reducer(state, action) {
6
+ switch (action.type) {
7
+ case ActionTypes.SHOW_PASTE_OPTIONS:
8
+ {
9
+ return _objectSpread(_objectSpread({}, state), {}, {
10
+ showToolbar: true,
11
+ highlightContent: false,
12
+ isPlainText: action.data.isPlainText,
13
+ plaintext: action.data.plaintext,
14
+ selectedOption: action.data.selectedOption,
15
+ richTextSlice: action.data.richTextSlice,
16
+ pasteStartPos: action.data.pasteStartPos,
17
+ pasteEndPos: action.data.pasteEndPos
18
+ });
19
+ }
20
+ case ActionTypes.HIDE_PASTE_OPTIONS:
21
+ {
22
+ return _objectSpread(_objectSpread({}, state), {}, {
23
+ highlightContent: false,
24
+ showToolbar: false
25
+ });
26
+ }
27
+ case ActionTypes.HIGHLIGHT_CONTENT:
28
+ {
29
+ return _objectSpread(_objectSpread({}, state), {}, {
30
+ highlightContent: true
31
+ });
32
+ }
33
+ case ActionTypes.CHANGE_FORMAT:
34
+ {
35
+ return _objectSpread(_objectSpread({}, state), {}, {
36
+ highlightContent: true,
37
+ selectedOption: action.data.selectedOption
38
+ });
39
+ }
40
+ default:
41
+ return state;
42
+ }
43
+ };
@@ -0,0 +1 @@
1
+ export { textHighlightStyle } from './ui/styles';
@@ -0,0 +1,88 @@
1
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
+ import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics, dropdownClickHandler } from './commands';
4
+ import { messages } from './messages';
5
+ import { PASTE_OPTIONS_TEST_ID, PASTE_TOOLBAR_CLASS, PASTE_TOOLBAR_ITEM_CLASS } from './pm-plugins/constants';
6
+ import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types';
7
+ import EditorPasteIcon from './ui/paste-icon';
8
+ import { hasLinkMark, hasMediaNode, hasRuleNode, isPastedFromFabricEditor } from './util';
9
+ export var isToolbarVisible = function isToolbarVisible(state, lastContentPasted) {
10
+ var _$from$node;
11
+ /**
12
+ * Conditions for not showing the toolbar:
13
+ * 1. Feature flag is disabled
14
+ * 2. Content is pasted at gap cursor
15
+ * 3. Pasting horizontal rule
16
+ * 4. Pasting link, media or text containing media(note: markdown link and images are allowed)
17
+ * 5. Content is pasted in a nested node(i.e. inside a table, panel etc.).
18
+ * (grandParent node should be root doc for showing up the toolbar)
19
+ */
20
+ if (!getBooleanFF('platform.editor.paste-options-toolbar')) {
21
+ return false;
22
+ }
23
+ var $from = state.selection.$from;
24
+ if (hasRuleNode(lastContentPasted.pastedSlice, state.schema)) {
25
+ return false;
26
+ }
27
+ var grandParentNodeType = (_$from$node = $from.node($from.depth - 1)) === null || _$from$node === void 0 ? void 0 : _$from$node.type;
28
+ if (grandParentNodeType && grandParentNodeType.name === state.schema.nodes.doc.name && !isPastedFromFabricEditor(lastContentPasted.pasteSource) && !hasLinkMark(state, lastContentPasted.pasteStartPos, lastContentPasted.pasteEndPos) && !hasMediaNode(lastContentPasted.pastedSlice)) {
29
+ return true;
30
+ }
31
+ return false;
32
+ };
33
+ export var getToolbarMenuConfig = function getToolbarMenuConfig(pluginState, pasteStartPos, plaintext, intl, editorAnalyticsAPI) {
34
+ var options = [{
35
+ id: 'editor.paste.richText',
36
+ title: intl.formatMessage(messages.richText),
37
+ selected: pluginState.selectedOption === ToolbarDropdownOption.RichText,
38
+ hidden: pluginState.isPlainText,
39
+ onClick: changeToRichTextWithAnalytics(editorAnalyticsAPI)(pasteStartPos)
40
+ }, {
41
+ id: 'editor.paste.markdown',
42
+ title: intl.formatMessage(messages.markdown),
43
+ selected: pluginState.selectedOption === ToolbarDropdownOption.Markdown,
44
+ onClick: changeToMarkdownWithAnalytics(editorAnalyticsAPI, plaintext.length)(pasteStartPos, plaintext)
45
+ }, {
46
+ id: 'editor.paste.plainText',
47
+ title: intl.formatMessage(messages.plainText),
48
+ selected: pluginState.selectedOption === ToolbarDropdownOption.PlainText,
49
+ onClick: changeToPlainTextWithAnalytics(editorAnalyticsAPI, plaintext.length)(pasteStartPos, plaintext)
50
+ }];
51
+ return {
52
+ id: PASTE_TOOLBAR_ITEM_CLASS,
53
+ icon: EditorPasteIcon,
54
+ type: 'dropdown',
55
+ testId: PASTE_OPTIONS_TEST_ID,
56
+ title: intl.formatMessage(messages.pasteOptions),
57
+ options: options,
58
+ onToggle: onToggleHandler
59
+ };
60
+ };
61
+ var onToggleHandler = function onToggleHandler(state, dispatch) {
62
+ return dropdownClickHandler()(state, dispatch);
63
+ };
64
+ export var buildToolbar = function buildToolbar(state, pasteStartPos, plaintext, intl, editorAnalyticsAPI) {
65
+ var schema = state.schema;
66
+ var validNodes = Object.values(schema.nodes);
67
+ var pluginState = pasteOptionsPluginKey.getState(state);
68
+ var menu = getToolbarMenuConfig(pluginState, pasteStartPos, plaintext, intl, editorAnalyticsAPI);
69
+ return {
70
+ title: intl.formatMessage(messages.pasteOptions),
71
+ nodeType: validNodes,
72
+ zIndex: akEditorFloatingPanelZIndex,
73
+ className: PASTE_TOOLBAR_CLASS,
74
+ items: [menu],
75
+ align: 'right',
76
+ onPositionCalculated: onPositionCalculated
77
+ };
78
+ };
79
+ var onPositionCalculated = function onPositionCalculated(editorView, nextPos) {
80
+ var toolbar = document.querySelector("div[aria-label=\"".concat(messages.pasteOptions.defaultMessage, "\"]"));
81
+ var cursorHeight = parseFloat(window.getComputedStyle(toolbar, undefined).lineHeight || '');
82
+ var from = editorView.state.tr.selection.from;
83
+ var fromCoords = editorView.coordsAtPos(from);
84
+ return {
85
+ top: fromCoords.top + cursorHeight,
86
+ left: fromCoords.left
87
+ };
88
+ };
@@ -0,0 +1,9 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var pasteOptionsPluginKey = new PluginKey('paste-options');
3
+ export var ToolbarDropdownOption = /*#__PURE__*/function (ToolbarDropdownOption) {
4
+ ToolbarDropdownOption[ToolbarDropdownOption["Markdown"] = 0] = "Markdown";
5
+ ToolbarDropdownOption[ToolbarDropdownOption["RichText"] = 1] = "RichText";
6
+ ToolbarDropdownOption[ToolbarDropdownOption["PlainText"] = 2] = "PlainText";
7
+ ToolbarDropdownOption[ToolbarDropdownOption["None"] = 3] = "None";
8
+ return ToolbarDropdownOption;
9
+ }({});
@@ -0,0 +1,16 @@
1
+ //Using a custom icon for now since Design System Team is in the process of updating the icon set for project griffin.
2
+
3
+ var _react = _interopRequireDefault(require('react'));
4
+ var _base = require('@atlaskit/icon/base');
5
+ function _interopRequireDefault(obj) {
6
+ return obj && obj.__esModule ? obj : {
7
+ default: obj
8
+ };
9
+ }
10
+ var EditorPasteIcon = function EditorPasteIcon(props) {
11
+ return /*#__PURE__*/_react.default.createElement(_base.Icon, Object.assign({
12
+ dangerouslySetGlyph: "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M14.8293 4C14.4175 2.83481 13.3062 2 12 2C10.6938 2 9.58254 2.83481 9.17071 4H9H6C4.89543 4 4 4.89543 4 6V18C4 19.1046 4.89543 20 6 20H18C19.1046 20 20 19.1046 20 18V6C20 4.89543 19.1046 4 18 4H15H14.8293ZM6 6H8V7C8 7.55228 8.44772 8 9 8H15C15.5523 8 16 7.55228 16 7V6H18V18H6V6ZM12 6C12.5523 6 13 5.55228 13 5C13 4.44772 12.5523 4 12 4C11.4477 4 11 4.44772 11 5C11 5.55228 11.4477 6 12 6Z\" fill=\"currentColor\"/><rect x=\"8\" y=\"11\" width=\"8\" height=\"2\" rx=\"1\" fill=\"currentColor\"/><rect x=\"8\" y=\"14\" width=\"5\" height=\"2\" rx=\"1\" fill=\"currentColor\"/></svg>"
13
+ }, props));
14
+ };
15
+ EditorPasteIcon.displayName = 'EditorPasteIcon';
16
+ export default EditorPasteIcon;
@@ -0,0 +1,5 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
+ var _templateObject;
3
+ import { css } from '@emotion/react';
4
+ import { TEXT_HIGHLIGHT_CLASS } from '../pm-plugins/constants';
5
+ export var textHighlightStyle = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .", " {\n background-color: ", ";\n\n border-bottom: 2px solid\n ", ";\n }\n"])), TEXT_HIGHLIGHT_CLASS, "var(--ds-background-accent-blue-subtlest, #E9F2FF)", "var(--ds-background-accent-blue-subtler, #cce0ff)");
@@ -0,0 +1,178 @@
1
+ import { logException } from '@atlaskit/editor-common/monitoring';
2
+ import { md } from '@atlaskit/editor-common/paste';
3
+ import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
4
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
5
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
6
+ import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
7
+ import { escapeLinks } from './index';
8
+ export var formatMarkdown = function formatMarkdown(state, pasteStartPos, plaintext) {
9
+ var schema = state.schema;
10
+ var tr = state.tr;
11
+ var selection = tr.selection;
12
+ if (pasteStartPos < 0) {
13
+ return tr;
14
+ }
15
+ var resolvedPasteStartPos = tr.doc.resolve(pasteStartPos);
16
+ var parentOffset = resolvedPasteStartPos.parentOffset;
17
+ if (parentOffset === 0 && resolvedPasteStartPos.depth > 0) {
18
+ pasteStartPos = resolvedPasteStartPos.before();
19
+ }
20
+ var markdownSlice = getMarkdownSlice(plaintext, schema, selection);
21
+ if (!markdownSlice) {
22
+ return tr;
23
+ }
24
+ var pasteEndPos = selection.$to.pos;
25
+ pasteSliceIntoTransactionWithSelectionAdjust({
26
+ tr: tr,
27
+ pasteStartPos: pasteStartPos,
28
+ pasteEndPos: pasteEndPos,
29
+ slice: markdownSlice
30
+ });
31
+ return tr;
32
+ };
33
+ export var getRichTextSlice = function getRichTextSlice(state, pasteStartPos) {
34
+ var tr = state.tr;
35
+ var selection = tr.selection;
36
+ var pasteEndPos = selection.$to.pos;
37
+ return state.doc.slice(pasteStartPos, pasteEndPos);
38
+ };
39
+ export var formatRichText = function formatRichText(state, pasteStartPos, richTextSlice) {
40
+ var tr = state.tr;
41
+ var selection = tr.selection;
42
+ if (pasteStartPos < 0) {
43
+ return tr;
44
+ }
45
+ if (richTextSlice === Slice.empty) {
46
+ return tr;
47
+ }
48
+ var pasteEndPos = selection.$to.pos;
49
+ var resolvedPasteStartPos = tr.doc.resolve(pasteStartPos);
50
+ var parentOffset = resolvedPasteStartPos.parentOffset;
51
+ if (parentOffset === 0 && resolvedPasteStartPos.depth > 0) {
52
+ pasteStartPos = resolvedPasteStartPos.before();
53
+ }
54
+ richTextSliceTransactionWithSelectionAdjust({
55
+ tr: tr,
56
+ pasteStartPos: pasteStartPos,
57
+ pasteEndPos: pasteEndPos,
58
+ slice: richTextSlice
59
+ });
60
+ return tr;
61
+ };
62
+ export var formatPlainText = function formatPlainText(state, pasteStartPos, plaintext) {
63
+ var tr = state.tr,
64
+ schema = state.schema;
65
+
66
+ //not possible to create plain text slice with empty string
67
+ if (pasteStartPos < 0 || plaintext === '') {
68
+ return tr;
69
+ }
70
+ var selection = tr.selection;
71
+ var pasteEndPos = selection.$to.pos;
72
+ var resolvedPasteStartPos = tr.doc.resolve(pasteStartPos);
73
+ var parentOffset = resolvedPasteStartPos.parentOffset;
74
+ if (parentOffset === 0 && resolvedPasteStartPos.depth > 0) {
75
+ pasteStartPos = resolvedPasteStartPos.before();
76
+ }
77
+ var plainTextNode = schema.text(plaintext);
78
+ var plainTextFragment = Fragment.from(schema.nodes.paragraph.createAndFill(null, plainTextNode));
79
+ var plainTextSlice = new Slice(plainTextFragment, resolvedPasteStartPos.depth, resolvedPasteStartPos.depth);
80
+ pasteSliceIntoTransactionWithSelectionAdjust({
81
+ tr: tr,
82
+ pasteStartPos: pasteStartPos,
83
+ pasteEndPos: pasteEndPos,
84
+ slice: plainTextSlice
85
+ });
86
+ return tr;
87
+ };
88
+ function pasteSliceIntoTransactionWithSelectionAdjust(_ref) {
89
+ var tr = _ref.tr,
90
+ pasteStartPos = _ref.pasteStartPos,
91
+ pasteEndPos = _ref.pasteEndPos,
92
+ slice = _ref.slice;
93
+ tr.replaceRange(pasteStartPos, pasteEndPos, slice);
94
+
95
+ // ProseMirror doesn't give a proper way to tell us where something was inserted.
96
+ // However, we can know "how" it inserted something.
97
+ //
98
+ // So, instead of weird depth calculations, we can use the step produced by the transform.
99
+ // For instance:
100
+ // The `replaceStep.to and replaceStep.from`, tell us the real position
101
+ // where the content will be insert.
102
+ // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
103
+ var replaceStep = tr.steps[0];
104
+ if (!(replaceStep instanceof ReplaceStep)) {
105
+ return tr;
106
+ }
107
+ var lastInsertNode = replaceStep.slice.content.lastChild;
108
+ var emptyNodeReference = lastInsertNode === null || lastInsertNode === void 0 ? void 0 : lastInsertNode.type.createAndFill();
109
+ var isLastNodeEmpty = (emptyNodeReference === null || emptyNodeReference === void 0 ? void 0 : emptyNodeReference.nodeSize) === (lastInsertNode === null || lastInsertNode === void 0 ? void 0 : lastInsertNode.nodeSize);
110
+ var isStepSplitingTarget = !(lastInsertNode !== null && lastInsertNode !== void 0 && lastInsertNode.isLeaf) && isLastNodeEmpty;
111
+ var $nextHead = tr.doc.resolve(tr.mapping.map(replaceStep.to));
112
+ var $nextPosition = isStepSplitingTarget && $nextHead.depth > 0 ? tr.doc.resolve($nextHead.before()) : $nextHead;
113
+
114
+ // The findFrom will make search for both: TextSelection and NodeSelections.
115
+ var nextSelection = Selection.findFrom($nextPosition, -1);
116
+ if (nextSelection) {
117
+ tr.setSelection(nextSelection);
118
+ }
119
+ }
120
+ function richTextSliceTransactionWithSelectionAdjust(_ref2) {
121
+ var tr = _ref2.tr,
122
+ pasteStartPos = _ref2.pasteStartPos,
123
+ pasteEndPos = _ref2.pasteEndPos,
124
+ slice = _ref2.slice;
125
+ tr.replaceRange(pasteStartPos, pasteEndPos, slice);
126
+
127
+ // ProseMirror doesn't give a proper way to tell us where something was inserted.
128
+ // However, we can know "how" it inserted something.
129
+ //
130
+ // So, instead of weird depth calculations, we can use the step produced by the transform.
131
+ // For instance:
132
+ // The `replaceStep.to and replaceStep.from`, tell us the real position
133
+ // where the content will be insert.
134
+ // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
135
+ var replaceStep = tr.steps[0];
136
+ if (!(replaceStep instanceof ReplaceStep)) {
137
+ return tr;
138
+ }
139
+ var nextPosition = tr.mapping.map(replaceStep.to);
140
+
141
+ // The findFrom will make search for both: TextSelection and NodeSelections.
142
+ var nextSelection = Selection.findFrom(tr.doc.resolve(Math.min(nextPosition, tr.doc.content.size)), -1);
143
+ if (nextSelection) {
144
+ tr.setSelection(nextSelection);
145
+ }
146
+ }
147
+ export function getMarkdownSlice(text, schema, selection) {
148
+ var targetOpenStartNode = selection.$from.parent;
149
+ var targetOpenEndNode = selection.$to.parent;
150
+ try {
151
+ var _doc$content$firstChi, _doc$content$lastChil;
152
+ var textInput = text;
153
+ var textSplitByCodeBlock = textInput.split(/```/);
154
+ for (var i = 0; i < textSplitByCodeBlock.length; i++) {
155
+ if (i % 2 === 0) {
156
+ textSplitByCodeBlock[i] = textSplitByCodeBlock[i].replace(/\\/g, '\\\\');
157
+ }
158
+ }
159
+ textInput = textSplitByCodeBlock.join('```');
160
+ var atlassianMarkDownParser = new MarkdownTransformer(schema, md);
161
+ var doc = atlassianMarkDownParser.parse(escapeLinks(textInput));
162
+ if (!doc || !doc.content) {
163
+ return;
164
+ }
165
+ var canMergeOpenStart = targetOpenStartNode.type === ((_doc$content$firstChi = doc.content.firstChild) === null || _doc$content$firstChi === void 0 ? void 0 : _doc$content$firstChi.type);
166
+ var canMergeOpenEnd = targetOpenEndNode.type === ((_doc$content$lastChil = doc.content.lastChild) === null || _doc$content$lastChil === void 0 ? void 0 : _doc$content$lastChil.type);
167
+ var $start = Selection.atStart(doc).$from;
168
+ var $end = Selection.atEnd(doc).$from;
169
+ var openStart = canMergeOpenStart ? $start.depth : 0;
170
+ var openEnd = canMergeOpenEnd ? $end.depth : 0;
171
+ return new Slice(doc.content, openStart, openEnd);
172
+ } catch (error) {
173
+ logException(error, {
174
+ location: 'editor-plugin-paste-options-toolbar/util'
175
+ });
176
+ return;
177
+ }
178
+ }
@@ -0,0 +1,37 @@
1
+ export function isPastedFromFabricEditor(pastedFrom) {
2
+ return pastedFrom === 'fabric-editor';
3
+ }
4
+
5
+ // @see https://product-fabric.atlassian.net/browse/ED-3159
6
+ // @see https://github.com/markdown-it/markdown-it/issues/38
7
+ export function escapeLinks(text) {
8
+ return text.replace(/(\[([^\]]+)\]\()?((https?|ftp|jamfselfservice):\/\/[^\s"'>]+)/g, function (str) {
9
+ return str.match(/^(https?|ftp|jamfselfservice):\/\/[^\s"'>]+$/) ? "<".concat(str, ">") : str;
10
+ });
11
+ }
12
+ export var hasMediaNode = function hasMediaNode(slice) {
13
+ if (!slice) {
14
+ return false;
15
+ }
16
+ var hasMedia = false;
17
+ slice.content.descendants(function (node) {
18
+ if (['media', 'mediaInline', 'mediaGroup', 'mediaSingle'].includes(node.type.name)) {
19
+ hasMedia = true;
20
+ return false;
21
+ }
22
+ return true;
23
+ });
24
+ return hasMedia;
25
+ };
26
+ export var hasRuleNode = function hasRuleNode(slice, schema) {
27
+ var hasRuleNode = false;
28
+ slice.content.nodesBetween(0, slice.content.size, function (node, start) {
29
+ if (node.type === schema.nodes.rule) {
30
+ hasRuleNode = true;
31
+ }
32
+ });
33
+ return hasRuleNode;
34
+ };
35
+ export var hasLinkMark = function hasLinkMark(state, pasteStartPos, pasteEndPos) {
36
+ return state.doc.rangeHasMark(pasteStartPos, pasteEndPos, state.schema.marks.link);
37
+ };
@@ -0,0 +1,34 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import type { ToolbarDropdownOption } from './types';
3
+ export declare enum PastePluginActionTypes {
4
+ START_TRACKING_PASTED_MACRO_POSITIONS = "START_TRACKING_PASTED_MACRO_POSITIONS",
5
+ STOP_TRACKING_PASTED_MACRO_POSITIONS = "STOP_TRACKING_PASTED_MACRO_POSITIONS",
6
+ SHOW_PASTE_OPTIONS = "SHOW_PASTE_OPTIONS",
7
+ HIDE_PASTE_OPTIONS = "HIDE_PASTE_OPTIONS",
8
+ HIGHLIGHT_CONTENT = "HIGHLIGHT_CONTENT",
9
+ CHANGE_FORMAT = "CHANGE_FORMAT"
10
+ }
11
+ export interface ShowPasteOptions {
12
+ type: PastePluginActionTypes.SHOW_PASTE_OPTIONS;
13
+ data: {
14
+ plaintext: string;
15
+ selectedOption: ToolbarDropdownOption;
16
+ isPlainText: boolean;
17
+ richTextSlice: Slice;
18
+ pasteStartPos: number;
19
+ pasteEndPos: number;
20
+ };
21
+ }
22
+ export interface HidePasteOptions {
23
+ type: PastePluginActionTypes.HIDE_PASTE_OPTIONS;
24
+ }
25
+ export interface HighlightContent {
26
+ type: PastePluginActionTypes.HIGHLIGHT_CONTENT;
27
+ }
28
+ export interface ChangeFormat {
29
+ type: PastePluginActionTypes.CHANGE_FORMAT;
30
+ data: {
31
+ selectedOption: ToolbarDropdownOption;
32
+ };
33
+ }
34
+ export type PastePluginAction = ShowPasteOptions | HidePasteOptions | HighlightContent | ChangeFormat;
@@ -0,0 +1,16 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { LastContentPasted } from '@atlaskit/editor-plugin-paste';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import { ToolbarDropdownOption } from './types';
6
+ export declare const showToolbar: (lastContentPasted: LastContentPasted, selectedOption: ToolbarDropdownOption) => Command;
7
+ export declare const changeToPlainText: (pasteStartPos: number, plaintext: string) => Command;
8
+ export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => (pasteStartPos: number, plaintext: string) => Command;
9
+ export declare const dropdownClickHandler: () => Command;
10
+ export declare const changeToRichText: (pasteStartPos: number) => Command;
11
+ export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (pasteStartPos: number) => Command;
12
+ export declare const changeToMarkDown: (pasteStartPos: number, plaintext: string) => Command;
13
+ export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => (pasteStartPos: number, plaintext: string) => Command;
14
+ export declare const highlightContent: () => Command;
15
+ export declare const hideToolbar: () => Command;
16
+ export declare const checkAndHideToolbar: (view: EditorView) => void;
@@ -0,0 +1 @@
1
+ export { pasteOptionsToolbarPlugin } from './plugin';
@@ -0,0 +1,22 @@
1
+ export declare const messages: {
2
+ pasteOptions: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ description: string;
6
+ };
7
+ plainText: {
8
+ id: string;
9
+ defaultMessage: string;
10
+ description: string;
11
+ };
12
+ markdown: {
13
+ id: string;
14
+ defaultMessage: string;
15
+ description: string;
16
+ };
17
+ richText: {
18
+ id: string;
19
+ defaultMessage: string;
20
+ description: string;
21
+ };
22
+ };
@@ -0,0 +1,6 @@
1
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
+ import type { PastePlugin } from '@atlaskit/editor-plugin-paste';
4
+ export declare const pasteOptionsToolbarPlugin: NextEditorPlugin<'pasteOptionsToolbarPlugin', {
5
+ dependencies: [OptionalPlugin<AnalyticsPlugin>, PastePlugin];
6
+ }>;
@@ -0,0 +1,7 @@
1
+ export declare const PASTE_TOOLBAR_CLASS = "ak-editor-paste-toolbar";
2
+ export declare const PASTE_TOOLBAR_MENU_ID = "ak-editor-paste-toolbar-item-dropdownList";
3
+ export declare const TEXT_HIGHLIGHT_CLASS = "text-highlight";
4
+ export declare const PASTE_HIGHLIGHT_DECORATION_KEY = "paste-highlight-decoration-key";
5
+ export declare const PASTE_TOOLBAR_ITEM_CLASS = "ak-editor-paste-toolbar-item";
6
+ export declare const EDITOR_WRAPPER_CLASS = "akEditor";
7
+ export declare const PASTE_OPTIONS_TEST_ID = "paste-options-testid";
@@ -0,0 +1,3 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ export declare function createPlugin(dispatch: Dispatch): SafePlugin<import("../types").PasteOtionsPluginState>;
@@ -0,0 +1,2 @@
1
+ import type { PasteOtionsPluginState } from '../types';
2
+ export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: PasteOtionsPluginState | ((state: import("prosemirror-state").EditorState) => PasteOtionsPluginState)) => import("prosemirror-state").SafeStateField<PasteOtionsPluginState>, createCommand: <A = import("../actions").PastePluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command, getPluginState: (state: import("prosemirror-state").EditorState) => PasteOtionsPluginState;
@@ -0,0 +1,3 @@
1
+ import type { PastePluginAction as Action } from './actions';
2
+ import type { PasteOtionsPluginState as State } from './types';
3
+ export declare const reducer: (state: State, action: Action) => State;
@@ -0,0 +1 @@
1
+ export { textHighlightStyle } from './ui/styles';
@@ -0,0 +1,9 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
+ import type { Command, FloatingToolbarConfig, FloatingToolbarDropdown } from '@atlaskit/editor-common/types';
4
+ import type { LastContentPasted } from '@atlaskit/editor-plugin-paste';
5
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
6
+ import type { PasteOtionsPluginState } from './types';
7
+ export declare const isToolbarVisible: (state: EditorState, lastContentPasted: LastContentPasted) => boolean;
8
+ export declare const getToolbarMenuConfig: (pluginState: PasteOtionsPluginState, pasteStartPos: number, plaintext: string, intl: IntlShape, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => FloatingToolbarDropdown<Command>;
9
+ export declare const buildToolbar: (state: EditorState, pasteStartPos: number, plaintext: string, intl: IntlShape, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => FloatingToolbarConfig | undefined;
@@ -0,0 +1,25 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const pasteOptionsPluginKey: PluginKey<any>;
5
+ export declare enum ToolbarDropdownOption {
6
+ Markdown = 0,
7
+ RichText = 1,
8
+ PlainText = 2,
9
+ None = 3
10
+ }
11
+ export interface PasteOtionsPluginState {
12
+ showToolbar: boolean;
13
+ pasteStartPos: number;
14
+ pasteEndPos: number;
15
+ plaintext: string;
16
+ richTextSlice: Slice;
17
+ isPlainText: boolean;
18
+ highlightContent: boolean;
19
+ highlightDecorationSet: DecorationSet;
20
+ selectedOption: ToolbarDropdownOption;
21
+ }
22
+ export interface Position {
23
+ top?: number;
24
+ left?: number;
25
+ }
@@ -0,0 +1,5 @@
1
+ declare const EditorPasteIcon: {
2
+ (props: any): any;
3
+ displayName: string;
4
+ };
5
+ export default EditorPasteIcon;
@@ -0,0 +1 @@
1
+ export declare const textHighlightStyle: import("@emotion/react").SerializedStyles;
@@ -0,0 +1,9 @@
1
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import { Slice } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ export declare const formatMarkdown: (state: EditorState, pasteStartPos: number, plaintext: string) => Transaction;
6
+ export declare const getRichTextSlice: (state: EditorState, pasteStartPos: number) => Slice;
7
+ export declare const formatRichText: (state: EditorState, pasteStartPos: number, richTextSlice: Slice) => Transaction;
8
+ export declare const formatPlainText: (state: EditorState, pasteStartPos: number, plaintext: string) => Transaction;
9
+ export declare function getMarkdownSlice(text: string, schema: Schema, selection: Selection): Slice | undefined;
@@ -0,0 +1,7 @@
1
+ import type { Schema, Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ export declare function isPastedFromFabricEditor(pastedFrom: string): boolean;
4
+ export declare function escapeLinks(text: string): string;
5
+ export declare const hasMediaNode: (slice: Slice | undefined) => boolean;
6
+ export declare const hasRuleNode: (slice: Slice, schema: Schema) => boolean;
7
+ export declare const hasLinkMark: (state: EditorState, pasteStartPos: number, pasteEndPos: number) => boolean;
@@ -0,0 +1,34 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import type { ToolbarDropdownOption } from './types';
3
+ export declare enum PastePluginActionTypes {
4
+ START_TRACKING_PASTED_MACRO_POSITIONS = "START_TRACKING_PASTED_MACRO_POSITIONS",
5
+ STOP_TRACKING_PASTED_MACRO_POSITIONS = "STOP_TRACKING_PASTED_MACRO_POSITIONS",
6
+ SHOW_PASTE_OPTIONS = "SHOW_PASTE_OPTIONS",
7
+ HIDE_PASTE_OPTIONS = "HIDE_PASTE_OPTIONS",
8
+ HIGHLIGHT_CONTENT = "HIGHLIGHT_CONTENT",
9
+ CHANGE_FORMAT = "CHANGE_FORMAT"
10
+ }
11
+ export interface ShowPasteOptions {
12
+ type: PastePluginActionTypes.SHOW_PASTE_OPTIONS;
13
+ data: {
14
+ plaintext: string;
15
+ selectedOption: ToolbarDropdownOption;
16
+ isPlainText: boolean;
17
+ richTextSlice: Slice;
18
+ pasteStartPos: number;
19
+ pasteEndPos: number;
20
+ };
21
+ }
22
+ export interface HidePasteOptions {
23
+ type: PastePluginActionTypes.HIDE_PASTE_OPTIONS;
24
+ }
25
+ export interface HighlightContent {
26
+ type: PastePluginActionTypes.HIGHLIGHT_CONTENT;
27
+ }
28
+ export interface ChangeFormat {
29
+ type: PastePluginActionTypes.CHANGE_FORMAT;
30
+ data: {
31
+ selectedOption: ToolbarDropdownOption;
32
+ };
33
+ }
34
+ export type PastePluginAction = ShowPasteOptions | HidePasteOptions | HighlightContent | ChangeFormat;
@@ -0,0 +1,16 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { LastContentPasted } from '@atlaskit/editor-plugin-paste';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import { ToolbarDropdownOption } from './types';
6
+ export declare const showToolbar: (lastContentPasted: LastContentPasted, selectedOption: ToolbarDropdownOption) => Command;
7
+ export declare const changeToPlainText: (pasteStartPos: number, plaintext: string) => Command;
8
+ export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => (pasteStartPos: number, plaintext: string) => Command;
9
+ export declare const dropdownClickHandler: () => Command;
10
+ export declare const changeToRichText: (pasteStartPos: number) => Command;
11
+ export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (pasteStartPos: number) => Command;
12
+ export declare const changeToMarkDown: (pasteStartPos: number, plaintext: string) => Command;
13
+ export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => (pasteStartPos: number, plaintext: string) => Command;
14
+ export declare const highlightContent: () => Command;
15
+ export declare const hideToolbar: () => Command;
16
+ export declare const checkAndHideToolbar: (view: EditorView) => void;