@atlaskit/editor-plugin-floating-toolbar 3.0.2 → 3.1.1
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 +21 -0
- package/dist/cjs/floatingToolbarPlugin.js +8 -2
- package/dist/cjs/pm-plugins/commands.js +59 -0
- package/dist/cjs/ui/Toolbar.js +21 -9
- package/dist/es2019/floatingToolbarPlugin.js +4 -0
- package/dist/es2019/pm-plugins/commands.js +52 -0
- package/dist/es2019/ui/Toolbar.js +21 -9
- package/dist/esm/floatingToolbarPlugin.js +6 -0
- package/dist/esm/pm-plugins/commands.js +53 -0
- package/dist/esm/ui/Toolbar.js +21 -9
- package/dist/types/pm-plugins/commands.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/commands.d.ts +6 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-floating-toolbar
|
|
2
2
|
|
|
3
|
+
## 3.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 3.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#121533](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/121533)
|
|
14
|
+
[`9efef36af09aa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9efef36af09aa) -
|
|
15
|
+
Wire up the copy functionality in floating toolbar overflow menu
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#121662](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/121662)
|
|
20
|
+
[`9b32bffcee007`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9b32bffcee007) -
|
|
21
|
+
[ux] [ED-26870] Allow toolbar height to expand
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 3.0.2
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -21,8 +21,9 @@ var _ui = require("@atlaskit/editor-common/ui");
|
|
|
21
21
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
22
22
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
23
23
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
24
|
+
var _commands = require("./pm-plugins/commands");
|
|
24
25
|
var _forceFocus = _interopRequireWildcard(require("./pm-plugins/force-focus"));
|
|
25
|
-
var
|
|
26
|
+
var _commands2 = require("./pm-plugins/toolbar-data/commands");
|
|
26
27
|
var _plugin = require("./pm-plugins/toolbar-data/plugin");
|
|
27
28
|
var _pluginKey = require("./pm-plugins/toolbar-data/plugin-key");
|
|
28
29
|
var _utils2 = require("./pm-plugins/utils");
|
|
@@ -164,6 +165,11 @@ var floatingToolbarPlugin = exports.floatingToolbarPlugin = function floatingToo
|
|
|
164
165
|
actions: {
|
|
165
166
|
forceFocusSelector: _forceFocus.forceFocusSelector
|
|
166
167
|
},
|
|
168
|
+
commands: {
|
|
169
|
+
copyNode: function copyNode(nodeType) {
|
|
170
|
+
return (0, _commands.copyNode)(nodeType);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
167
173
|
getSharedState: function getSharedState(editorState) {
|
|
168
174
|
var _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
|
|
169
175
|
if (!editorState) {
|
|
@@ -399,7 +405,7 @@ function ContentComponent(_ref5) {
|
|
|
399
405
|
}
|
|
400
406
|
},
|
|
401
407
|
onClose: function onClose() {
|
|
402
|
-
dispatchCommand((0,
|
|
408
|
+
dispatchCommand((0, _commands2.hideConfirmDialog)());
|
|
403
409
|
// Need to set focus to Editor here,
|
|
404
410
|
// As when the Confirmation dialog pop up, and user interacts with the dialog, Editor loses focus.
|
|
405
411
|
// So when Confirmation dialog is closed, Editor does not have the focus, then cursor goes to the position 1 of the doc,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copyNode = void 0;
|
|
7
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
8
|
+
var _clipboard = require("@atlaskit/editor-common/clipboard");
|
|
9
|
+
var _copyButton = require("@atlaskit/editor-common/copy-button");
|
|
10
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var copyNode = exports.copyNode = function copyNode(nodeType, editorAnalyticsAp) {
|
|
12
|
+
return function (_ref) {
|
|
13
|
+
var tr = _ref.tr;
|
|
14
|
+
// const { tr, schema } = state;
|
|
15
|
+
|
|
16
|
+
// This command should only be triggered by the Copy button in the floating toolbar
|
|
17
|
+
// which is only visible when selection is inside the target node
|
|
18
|
+
var contentNodeWithPos = (0, _copyButton.getSelectedNodeOrNodeParentByNodeType)({
|
|
19
|
+
nodeType: nodeType,
|
|
20
|
+
selection: tr.selection
|
|
21
|
+
});
|
|
22
|
+
if (!contentNodeWithPos) {
|
|
23
|
+
return tr;
|
|
24
|
+
}
|
|
25
|
+
var schema = tr.doc.type.schema;
|
|
26
|
+
var copyToClipboardTr = tr;
|
|
27
|
+
var domNode = (0, _copyButton.toDOM)(contentNodeWithPos.node, schema);
|
|
28
|
+
if (domNode) {
|
|
29
|
+
var div = document.createElement('div');
|
|
30
|
+
div.appendChild(domNode);
|
|
31
|
+
|
|
32
|
+
// if copying inline content
|
|
33
|
+
if (contentNodeWithPos.node.type.inlineContent) {
|
|
34
|
+
// The "1 1" refers to the start and end depth of the slice
|
|
35
|
+
// since we're copying the text inside a paragraph, it will always be 1 1
|
|
36
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
37
|
+
// Ignored via go/ees005
|
|
38
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
39
|
+
div.firstChild.setAttribute('data-pm-slice', '1 1 []');
|
|
40
|
+
} else {
|
|
41
|
+
// The "0 0" refers to the start and end depth of the slice
|
|
42
|
+
// since we're copying the block node only, it will always be 0 0
|
|
43
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
44
|
+
// Ignored via go/ees005
|
|
45
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
46
|
+
div.firstChild.setAttribute('data-pm-slice', '0 0 []');
|
|
47
|
+
}
|
|
48
|
+
// ED-17083 safari seems have bugs for extension copy because exntension do not have a child text(innerText) and it will not recognized as html in clipboard, this could be merge into one if this extension fixed children issue or safari fix the copy bug
|
|
49
|
+
// MEX-2528 safari has a bug related to the mediaSingle node with border or link. The image tag within the clipboard is not recognized as HTML when using the ClipboardItem API. To address this, we have to switch to ClipboardPolyfill
|
|
50
|
+
if (_browser.browser.safari && tr.selection instanceof _state.NodeSelection && (tr.selection.node.type === schema.nodes.extension || tr.selection.node.type === schema.nodes.mediaSingle)) {
|
|
51
|
+
(0, _clipboard.copyHTMLToClipboardPolyfill)(div);
|
|
52
|
+
} else {
|
|
53
|
+
(0, _clipboard.copyHTMLToClipboard)(div);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
copyToClipboardTr.setMeta('scrollIntoView', false);
|
|
57
|
+
return copyToClipboardTr;
|
|
58
|
+
};
|
|
59
|
+
};
|
package/dist/cjs/ui/Toolbar.js
CHANGED
|
@@ -352,16 +352,19 @@ var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
|
352
352
|
var groupedItems = groupItems(items.filter(function (item) {
|
|
353
353
|
return !item.hidden;
|
|
354
354
|
}));
|
|
355
|
-
return (0, _react2.jsx)(_buttonGroup.default,
|
|
355
|
+
return (0, _react2.jsx)(_buttonGroup.default, {
|
|
356
|
+
testId: "editor-floating-toolbar-items"
|
|
357
|
+
}, groupedItems.map(function (element, index) {
|
|
356
358
|
var isGroup = Array.isArray(element);
|
|
357
359
|
if (isGroup) {
|
|
358
360
|
return (0, _react2.jsx)("div", {
|
|
359
361
|
// Ignored via go/ees005
|
|
360
362
|
// eslint-disable-next-line react/no-array-index-key
|
|
361
363
|
key: index,
|
|
362
|
-
css: buttonGroupStyles,
|
|
364
|
+
css: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? buttonGroupStylesNew : buttonGroupStyles,
|
|
363
365
|
role: "radiogroup",
|
|
364
|
-
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined
|
|
366
|
+
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined,
|
|
367
|
+
"data-testid": "editor-floating-toolbar-grouped-buttons"
|
|
365
368
|
}, element.map(function (element) {
|
|
366
369
|
var indexInAllItems = items.findIndex(function (item) {
|
|
367
370
|
return item === element;
|
|
@@ -387,6 +390,10 @@ var buttonGroupStyles = (0, _react2.css)({
|
|
|
387
390
|
display: 'flex',
|
|
388
391
|
gap: "var(--ds-space-050, 4px)"
|
|
389
392
|
});
|
|
393
|
+
var buttonGroupStylesNew = (0, _react2.css)({
|
|
394
|
+
display: 'flex',
|
|
395
|
+
gap: "var(--ds-space-075, 6px)"
|
|
396
|
+
});
|
|
390
397
|
|
|
391
398
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
392
399
|
var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstElementIsSelect) {
|
|
@@ -433,7 +440,7 @@ var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstEle
|
|
|
433
440
|
(0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ?
|
|
434
441
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
435
442
|
(0, _react2.css)({
|
|
436
|
-
|
|
443
|
+
minHeight: "var(--ds-space-500, 40px)"
|
|
437
444
|
}) : undefined);
|
|
438
445
|
};
|
|
439
446
|
|
|
@@ -485,13 +492,18 @@ var toolbarOverflow = function toolbarOverflow(_ref2) {
|
|
|
485
492
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
486
493
|
(0, _react2.css)({
|
|
487
494
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
488
|
-
padding:
|
|
495
|
+
padding: "var(--ds-space-0, 0)".concat(" 4px ", "var(--ds-space-600, 48px)", " 4px"),
|
|
489
496
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
490
497
|
'> div': {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
498
|
+
minHeight: "var(--ds-space-500, 40px)",
|
|
499
|
+
gap: "var(--ds-space-075, 6px)",
|
|
500
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
501
|
+
'> div:first-child': {
|
|
502
|
+
marginLeft: 0
|
|
503
|
+
},
|
|
504
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
505
|
+
'> div:last-child': {
|
|
506
|
+
marginRight: 0
|
|
495
507
|
}
|
|
496
508
|
}
|
|
497
509
|
}) : undefined) :
|
|
@@ -9,6 +9,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
|
|
|
9
9
|
import { AllSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
10
10
|
import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
11
11
|
import { editorExperiment, unstable_editorExperimentParam } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
12
|
+
import { copyNode } from './pm-plugins/commands';
|
|
12
13
|
import forceFocusPlugin, { forceFocusSelector } from './pm-plugins/force-focus';
|
|
13
14
|
import { hideConfirmDialog } from './pm-plugins/toolbar-data/commands';
|
|
14
15
|
import { createPlugin as floatingToolbarDataPluginFactory } from './pm-plugins/toolbar-data/plugin';
|
|
@@ -147,6 +148,9 @@ export const floatingToolbarPlugin = ({
|
|
|
147
148
|
actions: {
|
|
148
149
|
forceFocusSelector
|
|
149
150
|
},
|
|
151
|
+
commands: {
|
|
152
|
+
copyNode: nodeType => copyNode(nodeType)
|
|
153
|
+
},
|
|
150
154
|
getSharedState(editorState) {
|
|
151
155
|
var _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
|
|
152
156
|
if (!editorState) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
2
|
+
import { copyHTMLToClipboard, copyHTMLToClipboardPolyfill } from '@atlaskit/editor-common/clipboard';
|
|
3
|
+
import { getSelectedNodeOrNodeParentByNodeType, toDOM } from '@atlaskit/editor-common/copy-button';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
export const copyNode = (nodeType, editorAnalyticsAp) => ({
|
|
6
|
+
tr
|
|
7
|
+
}) => {
|
|
8
|
+
// const { tr, schema } = state;
|
|
9
|
+
|
|
10
|
+
// This command should only be triggered by the Copy button in the floating toolbar
|
|
11
|
+
// which is only visible when selection is inside the target node
|
|
12
|
+
const contentNodeWithPos = getSelectedNodeOrNodeParentByNodeType({
|
|
13
|
+
nodeType,
|
|
14
|
+
selection: tr.selection
|
|
15
|
+
});
|
|
16
|
+
if (!contentNodeWithPos) {
|
|
17
|
+
return tr;
|
|
18
|
+
}
|
|
19
|
+
const schema = tr.doc.type.schema;
|
|
20
|
+
const copyToClipboardTr = tr;
|
|
21
|
+
const domNode = toDOM(contentNodeWithPos.node, schema);
|
|
22
|
+
if (domNode) {
|
|
23
|
+
const div = document.createElement('div');
|
|
24
|
+
div.appendChild(domNode);
|
|
25
|
+
|
|
26
|
+
// if copying inline content
|
|
27
|
+
if (contentNodeWithPos.node.type.inlineContent) {
|
|
28
|
+
// The "1 1" refers to the start and end depth of the slice
|
|
29
|
+
// since we're copying the text inside a paragraph, it will always be 1 1
|
|
30
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
31
|
+
// Ignored via go/ees005
|
|
32
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
33
|
+
div.firstChild.setAttribute('data-pm-slice', '1 1 []');
|
|
34
|
+
} else {
|
|
35
|
+
// The "0 0" refers to the start and end depth of the slice
|
|
36
|
+
// since we're copying the block node only, it will always be 0 0
|
|
37
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
38
|
+
// Ignored via go/ees005
|
|
39
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
40
|
+
div.firstChild.setAttribute('data-pm-slice', '0 0 []');
|
|
41
|
+
}
|
|
42
|
+
// ED-17083 safari seems have bugs for extension copy because exntension do not have a child text(innerText) and it will not recognized as html in clipboard, this could be merge into one if this extension fixed children issue or safari fix the copy bug
|
|
43
|
+
// MEX-2528 safari has a bug related to the mediaSingle node with border or link. The image tag within the clipboard is not recognized as HTML when using the ClipboardItem API. To address this, we have to switch to ClipboardPolyfill
|
|
44
|
+
if (browser.safari && tr.selection instanceof NodeSelection && (tr.selection.node.type === schema.nodes.extension || tr.selection.node.type === schema.nodes.mediaSingle)) {
|
|
45
|
+
copyHTMLToClipboardPolyfill(div);
|
|
46
|
+
} else {
|
|
47
|
+
copyHTMLToClipboard(div);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
copyToClipboardTr.setMeta('scrollIntoView', false);
|
|
51
|
+
return copyToClipboardTr;
|
|
52
|
+
};
|
|
@@ -319,16 +319,19 @@ const ToolbarItems = /*#__PURE__*/React.memo(({
|
|
|
319
319
|
}
|
|
320
320
|
};
|
|
321
321
|
const groupedItems = groupItems(items.filter(item => !item.hidden));
|
|
322
|
-
return jsx(ButtonGroup,
|
|
322
|
+
return jsx(ButtonGroup, {
|
|
323
|
+
testId: "editor-floating-toolbar-items"
|
|
324
|
+
}, groupedItems.map((element, index) => {
|
|
323
325
|
const isGroup = Array.isArray(element);
|
|
324
326
|
if (isGroup) {
|
|
325
327
|
return jsx("div", {
|
|
326
328
|
// Ignored via go/ees005
|
|
327
329
|
// eslint-disable-next-line react/no-array-index-key
|
|
328
330
|
key: index,
|
|
329
|
-
css: buttonGroupStyles,
|
|
331
|
+
css: editorExperiment('platform_editor_controls', 'variant1') ? buttonGroupStylesNew : buttonGroupStyles,
|
|
330
332
|
role: "radiogroup",
|
|
331
|
-
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined
|
|
333
|
+
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined,
|
|
334
|
+
"data-testid": "editor-floating-toolbar-grouped-buttons"
|
|
332
335
|
}, element.map(element => {
|
|
333
336
|
const indexInAllItems = items.findIndex(item => item === element);
|
|
334
337
|
return renderItem(element, indexInAllItems);
|
|
@@ -350,6 +353,10 @@ const buttonGroupStyles = css({
|
|
|
350
353
|
display: 'flex',
|
|
351
354
|
gap: "var(--ds-space-050, 4px)"
|
|
352
355
|
});
|
|
356
|
+
const buttonGroupStylesNew = css({
|
|
357
|
+
display: 'flex',
|
|
358
|
+
gap: "var(--ds-space-075, 6px)"
|
|
359
|
+
});
|
|
353
360
|
|
|
354
361
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
355
362
|
const toolbarContainer = (scrollable, hasSelect, firstElementIsSelect) => css({
|
|
@@ -395,7 +402,7 @@ css({
|
|
|
395
402
|
editorExperiment('platform_editor_controls', 'variant1') ?
|
|
396
403
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
397
404
|
css({
|
|
398
|
-
|
|
405
|
+
minHeight: "var(--ds-space-500, 40px)"
|
|
399
406
|
}) : undefined);
|
|
400
407
|
|
|
401
408
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
@@ -446,13 +453,18 @@ editorExperiment('platform_editor_controls', 'variant1') ?
|
|
|
446
453
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
447
454
|
css({
|
|
448
455
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
449
|
-
padding:
|
|
456
|
+
padding: `${"var(--ds-space-0, 0)"} 4px ${"var(--ds-space-600, 48px)"} 4px`,
|
|
450
457
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
451
458
|
'> div': {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
459
|
+
minHeight: "var(--ds-space-500, 40px)",
|
|
460
|
+
gap: "var(--ds-space-075, 6px)",
|
|
461
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
462
|
+
'> div:first-child': {
|
|
463
|
+
marginLeft: 0
|
|
464
|
+
},
|
|
465
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
466
|
+
'> div:last-child': {
|
|
467
|
+
marginRight: 0
|
|
456
468
|
}
|
|
457
469
|
}
|
|
458
470
|
}) : undefined) :
|
|
@@ -12,6 +12,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
|
|
|
12
12
|
import { AllSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
13
13
|
import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
14
14
|
import { editorExperiment, unstable_editorExperimentParam } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
15
|
+
import { copyNode as _copyNode } from './pm-plugins/commands';
|
|
15
16
|
import forceFocusPlugin, { forceFocusSelector } from './pm-plugins/force-focus';
|
|
16
17
|
import { hideConfirmDialog } from './pm-plugins/toolbar-data/commands';
|
|
17
18
|
import { createPlugin as floatingToolbarDataPluginFactory } from './pm-plugins/toolbar-data/plugin';
|
|
@@ -152,6 +153,11 @@ export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
|
|
|
152
153
|
actions: {
|
|
153
154
|
forceFocusSelector: forceFocusSelector
|
|
154
155
|
},
|
|
156
|
+
commands: {
|
|
157
|
+
copyNode: function copyNode(nodeType) {
|
|
158
|
+
return _copyNode(nodeType);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
155
161
|
getSharedState: function getSharedState(editorState) {
|
|
156
162
|
var _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
|
|
157
163
|
if (!editorState) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
2
|
+
import { copyHTMLToClipboard, copyHTMLToClipboardPolyfill } from '@atlaskit/editor-common/clipboard';
|
|
3
|
+
import { getSelectedNodeOrNodeParentByNodeType, toDOM } from '@atlaskit/editor-common/copy-button';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
export var copyNode = function copyNode(nodeType, editorAnalyticsAp) {
|
|
6
|
+
return function (_ref) {
|
|
7
|
+
var tr = _ref.tr;
|
|
8
|
+
// const { tr, schema } = state;
|
|
9
|
+
|
|
10
|
+
// This command should only be triggered by the Copy button in the floating toolbar
|
|
11
|
+
// which is only visible when selection is inside the target node
|
|
12
|
+
var contentNodeWithPos = getSelectedNodeOrNodeParentByNodeType({
|
|
13
|
+
nodeType: nodeType,
|
|
14
|
+
selection: tr.selection
|
|
15
|
+
});
|
|
16
|
+
if (!contentNodeWithPos) {
|
|
17
|
+
return tr;
|
|
18
|
+
}
|
|
19
|
+
var schema = tr.doc.type.schema;
|
|
20
|
+
var copyToClipboardTr = tr;
|
|
21
|
+
var domNode = toDOM(contentNodeWithPos.node, schema);
|
|
22
|
+
if (domNode) {
|
|
23
|
+
var div = document.createElement('div');
|
|
24
|
+
div.appendChild(domNode);
|
|
25
|
+
|
|
26
|
+
// if copying inline content
|
|
27
|
+
if (contentNodeWithPos.node.type.inlineContent) {
|
|
28
|
+
// The "1 1" refers to the start and end depth of the slice
|
|
29
|
+
// since we're copying the text inside a paragraph, it will always be 1 1
|
|
30
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
31
|
+
// Ignored via go/ees005
|
|
32
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
33
|
+
div.firstChild.setAttribute('data-pm-slice', '1 1 []');
|
|
34
|
+
} else {
|
|
35
|
+
// The "0 0" refers to the start and end depth of the slice
|
|
36
|
+
// since we're copying the block node only, it will always be 0 0
|
|
37
|
+
// https://github.com/ProseMirror/prosemirror-view/blob/master/src/clipboard.ts#L32
|
|
38
|
+
// Ignored via go/ees005
|
|
39
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
40
|
+
div.firstChild.setAttribute('data-pm-slice', '0 0 []');
|
|
41
|
+
}
|
|
42
|
+
// ED-17083 safari seems have bugs for extension copy because exntension do not have a child text(innerText) and it will not recognized as html in clipboard, this could be merge into one if this extension fixed children issue or safari fix the copy bug
|
|
43
|
+
// MEX-2528 safari has a bug related to the mediaSingle node with border or link. The image tag within the clipboard is not recognized as HTML when using the ClipboardItem API. To address this, we have to switch to ClipboardPolyfill
|
|
44
|
+
if (browser.safari && tr.selection instanceof NodeSelection && (tr.selection.node.type === schema.nodes.extension || tr.selection.node.type === schema.nodes.mediaSingle)) {
|
|
45
|
+
copyHTMLToClipboardPolyfill(div);
|
|
46
|
+
} else {
|
|
47
|
+
copyHTMLToClipboard(div);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
copyToClipboardTr.setMeta('scrollIntoView', false);
|
|
51
|
+
return copyToClipboardTr;
|
|
52
|
+
};
|
|
53
|
+
};
|
package/dist/esm/ui/Toolbar.js
CHANGED
|
@@ -345,16 +345,19 @@ var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
345
345
|
var groupedItems = groupItems(items.filter(function (item) {
|
|
346
346
|
return !item.hidden;
|
|
347
347
|
}));
|
|
348
|
-
return jsx(ButtonGroup,
|
|
348
|
+
return jsx(ButtonGroup, {
|
|
349
|
+
testId: "editor-floating-toolbar-items"
|
|
350
|
+
}, groupedItems.map(function (element, index) {
|
|
349
351
|
var isGroup = Array.isArray(element);
|
|
350
352
|
if (isGroup) {
|
|
351
353
|
return jsx("div", {
|
|
352
354
|
// Ignored via go/ees005
|
|
353
355
|
// eslint-disable-next-line react/no-array-index-key
|
|
354
356
|
key: index,
|
|
355
|
-
css: buttonGroupStyles,
|
|
357
|
+
css: editorExperiment('platform_editor_controls', 'variant1') ? buttonGroupStylesNew : buttonGroupStyles,
|
|
356
358
|
role: "radiogroup",
|
|
357
|
-
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined
|
|
359
|
+
"aria-label": groupLabel !== null && groupLabel !== void 0 ? groupLabel : undefined,
|
|
360
|
+
"data-testid": "editor-floating-toolbar-grouped-buttons"
|
|
358
361
|
}, element.map(function (element) {
|
|
359
362
|
var indexInAllItems = items.findIndex(function (item) {
|
|
360
363
|
return item === element;
|
|
@@ -380,6 +383,10 @@ var buttonGroupStyles = css({
|
|
|
380
383
|
display: 'flex',
|
|
381
384
|
gap: "var(--ds-space-050, 4px)"
|
|
382
385
|
});
|
|
386
|
+
var buttonGroupStylesNew = css({
|
|
387
|
+
display: 'flex',
|
|
388
|
+
gap: "var(--ds-space-075, 6px)"
|
|
389
|
+
});
|
|
383
390
|
|
|
384
391
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
385
392
|
var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstElementIsSelect) {
|
|
@@ -426,7 +433,7 @@ var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstEle
|
|
|
426
433
|
editorExperiment('platform_editor_controls', 'variant1') ?
|
|
427
434
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
428
435
|
css({
|
|
429
|
-
|
|
436
|
+
minHeight: "var(--ds-space-500, 40px)"
|
|
430
437
|
}) : undefined);
|
|
431
438
|
};
|
|
432
439
|
|
|
@@ -478,13 +485,18 @@ var toolbarOverflow = function toolbarOverflow(_ref2) {
|
|
|
478
485
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values
|
|
479
486
|
css({
|
|
480
487
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
481
|
-
padding:
|
|
488
|
+
padding: "var(--ds-space-0, 0)".concat(" 4px ", "var(--ds-space-600, 48px)", " 4px"),
|
|
482
489
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
483
490
|
'> div': {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
491
|
+
minHeight: "var(--ds-space-500, 40px)",
|
|
492
|
+
gap: "var(--ds-space-075, 6px)",
|
|
493
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
494
|
+
'> div:first-child': {
|
|
495
|
+
marginLeft: 0
|
|
496
|
+
},
|
|
497
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
498
|
+
'> div:last-child': {
|
|
499
|
+
marginRight: 0
|
|
488
500
|
}
|
|
489
501
|
}
|
|
490
502
|
}) : undefined) :
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
export declare const copyNode: (nodeType: NodeType | Array<NodeType>, editorAnalyticsAp?: EditorAnalyticsAPI | undefined) => ({ tr }: {
|
|
5
|
+
tr: Transaction;
|
|
6
|
+
}) => Transaction;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
export declare const copyNode: (nodeType: NodeType | Array<NodeType>, editorAnalyticsAp?: EditorAnalyticsAPI | undefined) => ({ tr }: {
|
|
5
|
+
tr: Transaction;
|
|
6
|
+
}) => Transaction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-floating-toolbar",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Floating toolbar plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,20 +25,20 @@
|
|
|
25
25
|
".": "./src/index.ts"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@atlaskit/adf-utils": "^19.
|
|
28
|
+
"@atlaskit/adf-utils": "^19.19.0",
|
|
29
29
|
"@atlaskit/button": "^21.1.0",
|
|
30
30
|
"@atlaskit/checkbox": "^17.0.0",
|
|
31
|
-
"@atlaskit/editor-common": "^
|
|
31
|
+
"@atlaskit/editor-common": "^101.0.0",
|
|
32
32
|
"@atlaskit/editor-palette": "2.0.0",
|
|
33
|
-
"@atlaskit/editor-plugin-block-controls": "^3.
|
|
33
|
+
"@atlaskit/editor-plugin-block-controls": "^3.2.0",
|
|
34
34
|
"@atlaskit/editor-plugin-context-panel": "^3.0.0",
|
|
35
35
|
"@atlaskit/editor-plugin-copy-button": "^2.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-decorations": "^2.0.0",
|
|
37
37
|
"@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-editor-viewmode": "^3.0.0",
|
|
39
|
-
"@atlaskit/editor-plugin-emoji": "^3.
|
|
40
|
-
"@atlaskit/editor-plugin-extension": "^4.
|
|
41
|
-
"@atlaskit/editor-plugin-table": "^10.
|
|
39
|
+
"@atlaskit/editor-plugin-emoji": "^3.1.0",
|
|
40
|
+
"@atlaskit/editor-plugin-extension": "^4.1.0",
|
|
41
|
+
"@atlaskit/editor-plugin-table": "^10.3.0",
|
|
42
42
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
43
43
|
"@atlaskit/emoji": "^68.0.0",
|
|
44
44
|
"@atlaskit/icon": "^24.1.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/primitives": "^14.1.0",
|
|
49
49
|
"@atlaskit/select": "^20.0.0",
|
|
50
50
|
"@atlaskit/theme": "^17.0.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^3.
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^3.4.0",
|
|
52
52
|
"@atlaskit/tokens": "^4.3.0",
|
|
53
53
|
"@atlaskit/tooltip": "^20.0.0",
|
|
54
54
|
"@babel/runtime": "^7.0.0",
|