@atlaskit/editor-plugin-block-controls 2.13.11 → 2.13.13

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 (34) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/commands/move-to-layout.js +50 -32
  3. package/dist/cjs/consts.js +3 -2
  4. package/dist/cjs/plugin.js +5 -16
  5. package/dist/cjs/pm-plugins/decorations-anchor.js +4 -3
  6. package/dist/cjs/ui/global-styles.js +86 -122
  7. package/dist/es2019/commands/move-to-layout.js +42 -23
  8. package/dist/es2019/consts.js +2 -1
  9. package/dist/es2019/plugin.js +1 -10
  10. package/dist/es2019/pm-plugins/decorations-anchor.js +4 -3
  11. package/dist/es2019/ui/global-styles.js +23 -20
  12. package/dist/esm/commands/move-to-layout.js +51 -33
  13. package/dist/esm/consts.js +2 -1
  14. package/dist/esm/plugin.js +5 -16
  15. package/dist/esm/pm-plugins/decorations-anchor.js +4 -3
  16. package/dist/esm/ui/global-styles.js +87 -122
  17. package/dist/types/consts.d.ts +1 -0
  18. package/dist/types-ts4.5/consts.d.ts +1 -0
  19. package/package.json +4 -7
  20. package/dist/cjs/pm-plugins/empty-block-experiment.js +0 -46
  21. package/dist/cjs/ui/empty-block-experiment/global-styles.js +0 -66
  22. package/dist/cjs/ui/empty-block-experiment/widget.js +0 -144
  23. package/dist/es2019/pm-plugins/empty-block-experiment.js +0 -38
  24. package/dist/es2019/ui/empty-block-experiment/global-styles.js +0 -77
  25. package/dist/es2019/ui/empty-block-experiment/widget.js +0 -138
  26. package/dist/esm/pm-plugins/empty-block-experiment.js +0 -40
  27. package/dist/esm/ui/empty-block-experiment/global-styles.js +0 -58
  28. package/dist/esm/ui/empty-block-experiment/widget.js +0 -133
  29. package/dist/types/pm-plugins/empty-block-experiment.d.ts +0 -13
  30. package/dist/types/ui/empty-block-experiment/global-styles.d.ts +0 -4
  31. package/dist/types/ui/empty-block-experiment/widget.d.ts +0 -13
  32. package/dist/types-ts4.5/pm-plugins/empty-block-experiment.d.ts +0 -13
  33. package/dist/types-ts4.5/ui/empty-block-experiment/global-styles.d.ts +0 -4
  34. package/dist/types-ts4.5/ui/empty-block-experiment/widget.d.ts +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.13.11",
3
+ "version": "2.13.13",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@atlaskit/adf-schema": "^44.2.0",
34
- "@atlaskit/editor-common": "^94.16.0",
34
+ "@atlaskit/editor-common": "^94.21.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -46,9 +46,9 @@
46
46
  "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
49
- "@atlaskit/primitives": "^13.1.0",
49
+ "@atlaskit/primitives": "^13.2.0",
50
50
  "@atlaskit/theme": "^14.0.0",
51
- "@atlaskit/tmp-editor-statsig": "^2.12.0",
51
+ "@atlaskit/tmp-editor-statsig": "^2.15.0",
52
52
  "@atlaskit/tokens": "^2.2.0",
53
53
  "@atlaskit/tooltip": "^18.9.0",
54
54
  "@babel/runtime": "^7.0.0",
@@ -130,9 +130,6 @@
130
130
  "platform_editor_element_drag_and_drop_ed_24885": {
131
131
  "type": "boolean"
132
132
  },
133
- "platform_editor_empty_line_prompt_delay": {
134
- "type": "boolean"
135
- },
136
133
  "platform_editor_element_dnd_nested_fix_patch_1": {
137
134
  "type": "boolean"
138
135
  },
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.emptyBlockExperimentPluginKey = exports.createEmptyBlockExperimentPlugin = void 0;
7
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _view = require("@atlaskit/editor-prosemirror/view");
10
- var _widget = require("../ui/empty-block-experiment/widget");
11
- var emptyBlockExperimentPluginKey = exports.emptyBlockExperimentPluginKey = new _state.PluginKey('emptyBlockExperiment');
12
- var getDecorations = function getDecorations(tr, api, getIntl) {
13
- var _api$editorDisabled;
14
- var isEditorDisabled = api === null || api === void 0 || (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 || (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.editorDisabled;
15
- if (isEditorDisabled) {
16
- return _view.DecorationSet.empty;
17
- }
18
- var widget = (0, _widget.createEmptyBlockWidgetDecoration)(tr.selection, api, getIntl);
19
- if (widget) {
20
- return _view.DecorationSet.create(tr.doc, [widget]);
21
- }
22
- return _view.DecorationSet.empty;
23
- };
24
- var createEmptyBlockExperimentPlugin = exports.createEmptyBlockExperimentPlugin = function createEmptyBlockExperimentPlugin(api, getIntl) {
25
- return new _safePlugin.SafePlugin({
26
- key: emptyBlockExperimentPluginKey,
27
- state: {
28
- init: function init(_, _editorState) {
29
- return {
30
- decorations: _view.DecorationSet.empty
31
- };
32
- },
33
- apply: function apply(tr, _currentState) {
34
- return {
35
- decorations: getDecorations(tr, api, getIntl)
36
- };
37
- }
38
- },
39
- props: {
40
- decorations: function decorations(state) {
41
- var _emptyBlockExperiment;
42
- return (_emptyBlockExperiment = emptyBlockExperimentPluginKey.getState(state)) === null || _emptyBlockExperiment === void 0 ? void 0 : _emptyBlockExperiment.decorations;
43
- }
44
- }
45
- });
46
- };
@@ -1,66 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.emptyBlockExperimentGlobalStyles = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _react = require("@emotion/react");
10
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
- /* eslint-disable @atlaskit/ui-styling-standard/no-exported-styles */
12
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
13
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
14
- /* eslint-disable @atlaskit/ui-styling-standard/no-important-styles */
15
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
16
-
17
- var emptyBlockExperimentWidget = '.ProseMirror-widget[data-empty-block-experiment="true"]';
18
- var quickInsertWidget = '.ProseMirror-widget[data-type-ahead="typeaheadDecoration"]';
19
- var formattingElement = 'div.fabric-editor-block-mark';
20
- var markFragment = 'div[data-mark-type="fragment"]';
21
- var breakoutMark = 'div.fabric-editor-breakout-mark';
22
- var breakoutMarkDom = 'div.fabric-editor-breakout-mark-dom';
23
- var elementWithEmptyBlockExperiment = "+ p > ".concat(emptyBlockExperimentWidget, ", + h1 > ").concat(emptyBlockExperimentWidget, ", + h2 > ").concat(emptyBlockExperimentWidget, ", + h3 > ").concat(emptyBlockExperimentWidget, ", + h4 > ").concat(emptyBlockExperimentWidget, ", + h5 > ").concat(emptyBlockExperimentWidget, ", + h6 > ").concat(emptyBlockExperimentWidget);
24
- // Selectors for when contained withing a formatting container mark (eg. indent, centering, right-align)
25
- var elementWithEmptyBlockExperimentFormatted = "+ ".concat(formattingElement, " > p > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h1 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h2 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h3 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h4 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h5 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h6 > ").concat(emptyBlockExperimentWidget);
26
- var dragHandleContainer = '.ProseMirror-widget[data-blocks-drag-handle-container="true"]';
27
- var dragHandleSelector = 'button[data-testid="block-ctrl-drag-handle"]';
28
-
29
- // Hides the drag handle when the block contains the empty block experiment
30
- // Override is consistent with how the drag handle is hidden when the block contains a placeholder
31
- var dragHandleWithInlineNodeStyle = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperiment, "),\n\t\t").concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperimentFormatted, "),") + // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
32
- // is nested in the previous div. These selectors are to handle those cases.
33
- // -------------------
34
- // Empty block in new paragraph after indent
35
- "".concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child,\n\t").concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child,") + // Empty block in new paragraph after table
36
- "".concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child,\n\t\t").concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child,") + // Empty block in new paragraph after breakout mark
37
- "".concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child,\n\t").concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child"), {
38
- display: 'none !important'
39
- }));
40
-
41
- // Alternate styling for hiding the drag handle when the block contains the empty block experiment
42
- // Override is consistent with a feature-gated bugfix that hides the drag handle when the block contains a placeholder
43
- /**
44
- * Please do not change change transform to display:none, or visibility:hidden
45
- * Otherwise it might break composition input for Chrome
46
- * https://product-fabric.atlassian.net/browse/ED-24136
47
- */
48
- var dragHandleWithInlineNodeStyleWithChromeFix = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperiment, ") ").concat(dragHandleSelector, ",\n\t\t").concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperimentFormatted, ") ").concat(dragHandleSelector, ",") + // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
49
- // is nested in the previous div. These selectors are to handle those cases.
50
- // -------------------
51
- // Empty block in new paragraph after indent
52
- "".concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t").concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",") + // Empty block in new paragraph after table
53
- "".concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t\t").concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",") + // Empty block in new paragraph after breakout mark
54
- "".concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t\t").concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector), {
55
- transform: 'scale(0)'
56
- }));
57
- var getDragHandleOverrides = function getDragHandleOverrides() {
58
- return (0, _platformFeatureFlags.fg)('platform_editor_element_controls_chrome_input_fix') ? dragHandleWithInlineNodeStyleWithChromeFix : dragHandleWithInlineNodeStyle;
59
- };
60
-
61
- /**
62
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
63
- */
64
- var emptyBlockExperimentGlobalStyles = exports.emptyBlockExperimentGlobalStyles = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(emptyBlockExperimentWidget, ":has(+ ").concat(quickInsertWidget, ") button"), {
65
- transform: 'scale(0)'
66
- }), getDragHandleOverrides());
@@ -1,144 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createEmptyBlockWidgetDecoration = exports.TypeAheadControl = void 0;
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _react2 = require("@emotion/react");
12
- var _reactDom = _interopRequireDefault(require("react-dom"));
13
- var _reactIntlNext = require("react-intl-next");
14
- var _keymaps = require("@atlaskit/editor-common/keymaps");
15
- var _messages = require("@atlaskit/editor-common/messages");
16
- var _whitespace = require("@atlaskit/editor-common/whitespace");
17
- var _state = require("@atlaskit/editor-prosemirror/state");
18
- var _view2 = require("@atlaskit/editor-prosemirror/view");
19
- var _add = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/add"));
20
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
- var _primitives = require("@atlaskit/primitives");
22
- var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
23
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
- /* eslint-disable @atlaskit/ui-styling-standard/use-compiled */
26
-
27
- var wrapperStyles = (0, _primitives.xcss)({
28
- position: 'absolute',
29
- top: "calc('50%' - ".concat("var(--ds-space-150, 12px)", ")"),
30
- left: "calc(".concat("var(--ds-space-negative-300, -24px)", " + ", "var(--ds-space-negative-100, -8px)", ")")
31
- });
32
- var appear = (0, _react2.keyframes)({
33
- from: {
34
- visibility: 'hidden'
35
- },
36
- to: {
37
- visibility: 'visible'
38
- }
39
- });
40
- var delayedAppearance = (0, _primitives.xcss)({
41
- visibility: 'hidden',
42
- animation: "".concat(appear, " 0.1s"),
43
- animationDelay: '2s',
44
- animationFillMode: 'forwards'
45
- });
46
- var buttonStyles = (0, _primitives.xcss)({
47
- boxSizing: 'border-box',
48
- display: 'flex',
49
- flexDirection: 'column',
50
- justifyContent: 'center',
51
- alignItems: 'center',
52
- height: "var(--ds-space-300, 24px)",
53
- width: "var(--ds-space-300, 24px)",
54
- border: 'none',
55
- backgroundColor: 'color.background.neutral',
56
- borderRadius: '50%',
57
- color: 'color.text.accent.gray',
58
- zIndex: 'card',
59
- outline: 'none',
60
- ':hover': {
61
- backgroundColor: 'color.background.neutral.hovered'
62
- },
63
- ':active': {
64
- backgroundColor: 'color.background.neutral.pressed'
65
- },
66
- ':focus': {
67
- outline: "2px solid ".concat("var(--ds-border-focused, #388BFF)")
68
- }
69
- });
70
- var TypeAheadControl = exports.TypeAheadControl = function TypeAheadControl(_ref) {
71
- var api = _ref.api,
72
- getPos = _ref.getPos,
73
- formatMessage = _ref.intl.formatMessage;
74
- return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
75
- xcss: [wrapperStyles],
76
- testId: "editor-empty-line-prompt-experiment"
77
- }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
78
- content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
79
- description: formatMessage(_messages.blockControlsMessages.insert),
80
- shortcutOverride: "/"
81
- })
82
- }, /*#__PURE__*/_react.default.createElement(_primitives.Pressable, {
83
- type: "button",
84
- "aria-label": formatMessage(_messages.blockControlsMessages.insert),
85
- xcss: [buttonStyles].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.fg)('platform_editor_empty_line_prompt_delay') ? [delayedAppearance] : [])),
86
- onClick: function onClick() {
87
- var _api$core, _api$quickInsert;
88
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
89
- var tr = _ref2.tr;
90
- var start = getPos();
91
- if (!start) {
92
- return null;
93
- }
94
- return tr.setSelection(_state.TextSelection.create(tr.doc, start));
95
- });
96
- api === null || api === void 0 || (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl');
97
- }
98
- }, /*#__PURE__*/_react.default.createElement(_add.default, {
99
- label: "add",
100
- size: "medium"
101
- }))));
102
- };
103
- var TypeAheadControlWithIntl = (0, _reactIntlNext.injectIntl)(TypeAheadControl);
104
- var toDOM = function toDOM(api, getPos, getIntl) {
105
- var wrapper = document.createElement('span');
106
- wrapper.contentEditable = 'false';
107
- wrapper.setAttribute('data-empty-block-experiment', 'true');
108
- wrapper.setAttribute('class', 'empty-block-experiment');
109
- var element = document.createElement('span');
110
- element.contentEditable = 'false';
111
- element.setAttribute('style', 'position: absolute;');
112
- wrapper.appendChild(element);
113
- _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_reactIntlNext.RawIntlProvider, {
114
- value: getIntl()
115
- }, /*#__PURE__*/(0, _react.createElement)(TypeAheadControlWithIntl, {
116
- api: api,
117
- getPos: getPos
118
- })), element);
119
-
120
- // // This is a hack to ensure that the cursor in Chrome does not take on the height of the widget button.
121
- // // Cursor height cannot be controlled via CSS and is handled by the browser.
122
- // // see Prosemirror forum: https://discuss.prosemirror.net/t/chrome-caret-cursor-larger-than-the-text-with-inlined-items/5946
123
- var cursorHack = document.createTextNode(_whitespace.ZERO_WIDTH_SPACE);
124
- wrapper.appendChild(cursorHack);
125
- return wrapper;
126
- };
127
- var createEmptyBlockWidgetDecoration = exports.createEmptyBlockWidgetDecoration = function createEmptyBlockWidgetDecoration(selection, api, getIntl) {
128
- if (selection instanceof _state.TextSelection && selection.$cursor) {
129
- var _$cursor$parent, _$cursor$parent2;
130
- var $cursor = selection.$cursor;
131
- var depth = $cursor.depth;
132
- var cursorAtRoot = depth === 1;
133
- var nodeIsEmpty = ((_$cursor$parent = $cursor.parent) === null || _$cursor$parent === void 0 ? void 0 : _$cursor$parent.nodeSize) === 2;
134
- var supportedNodeTypes = ['paragraph', 'heading'];
135
- if (cursorAtRoot && nodeIsEmpty && supportedNodeTypes.includes((_$cursor$parent2 = $cursor.parent) === null || _$cursor$parent2 === void 0 ? void 0 : _$cursor$parent2.type.name)) {
136
- return _view2.Decoration.widget(selection.$cursor.posAtIndex($cursor.depth - 1), function (_view, getPos) {
137
- return toDOM(api, getPos, getIntl);
138
- }, {
139
- key: 'emptyBlockWidgetDecoration',
140
- side: -1
141
- });
142
- }
143
- }
144
- };
@@ -1,38 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { createEmptyBlockWidgetDecoration } from '../ui/empty-block-experiment/widget';
5
- export const emptyBlockExperimentPluginKey = new PluginKey('emptyBlockExperiment');
6
- const getDecorations = (tr, api, getIntl) => {
7
- var _api$editorDisabled, _api$editorDisabled$s;
8
- const isEditorDisabled = api === null || api === void 0 ? void 0 : (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 ? void 0 : (_api$editorDisabled$s = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled$s === void 0 ? void 0 : _api$editorDisabled$s.editorDisabled;
9
- if (isEditorDisabled) {
10
- return DecorationSet.empty;
11
- }
12
- const widget = createEmptyBlockWidgetDecoration(tr.selection, api, getIntl);
13
- if (widget) {
14
- return DecorationSet.create(tr.doc, [widget]);
15
- }
16
- return DecorationSet.empty;
17
- };
18
- export const createEmptyBlockExperimentPlugin = (api, getIntl) => {
19
- return new SafePlugin({
20
- key: emptyBlockExperimentPluginKey,
21
- state: {
22
- init: (_, _editorState) => ({
23
- decorations: DecorationSet.empty
24
- }),
25
- apply: (tr, _currentState) => {
26
- return {
27
- decorations: getDecorations(tr, api, getIntl)
28
- };
29
- }
30
- },
31
- props: {
32
- decorations: state => {
33
- var _emptyBlockExperiment;
34
- return (_emptyBlockExperiment = emptyBlockExperimentPluginKey.getState(state)) === null || _emptyBlockExperiment === void 0 ? void 0 : _emptyBlockExperiment.decorations;
35
- }
36
- }
37
- });
38
- };
@@ -1,77 +0,0 @@
1
- /* eslint-disable @atlaskit/ui-styling-standard/no-exported-styles */
2
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
3
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
4
- /* eslint-disable @atlaskit/ui-styling-standard/no-important-styles */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
6
- import { css } from '@emotion/react';
7
- import { fg } from '@atlaskit/platform-feature-flags';
8
- const emptyBlockExperimentWidget = '.ProseMirror-widget[data-empty-block-experiment="true"]';
9
- const quickInsertWidget = '.ProseMirror-widget[data-type-ahead="typeaheadDecoration"]';
10
- const formattingElement = 'div.fabric-editor-block-mark';
11
- const markFragment = 'div[data-mark-type="fragment"]';
12
- const breakoutMark = 'div.fabric-editor-breakout-mark';
13
- const breakoutMarkDom = 'div.fabric-editor-breakout-mark-dom';
14
- const elementWithEmptyBlockExperiment = `+ p > ${emptyBlockExperimentWidget}, + h1 > ${emptyBlockExperimentWidget}, + h2 > ${emptyBlockExperimentWidget}, + h3 > ${emptyBlockExperimentWidget}, + h4 > ${emptyBlockExperimentWidget}, + h5 > ${emptyBlockExperimentWidget}, + h6 > ${emptyBlockExperimentWidget}`;
15
- // Selectors for when contained withing a formatting container mark (eg. indent, centering, right-align)
16
- const elementWithEmptyBlockExperimentFormatted = `+ ${formattingElement} > p > ${emptyBlockExperimentWidget}, + ${formattingElement} > h1 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h2 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h3 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h4 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h5 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h6 > ${emptyBlockExperimentWidget}`;
17
- const dragHandleContainer = '.ProseMirror-widget[data-blocks-drag-handle-container="true"]';
18
- const dragHandleSelector = 'button[data-testid="block-ctrl-drag-handle"]';
19
-
20
- // Hides the drag handle when the block contains the empty block experiment
21
- // Override is consistent with how the drag handle is hidden when the block contains a placeholder
22
- const dragHandleWithInlineNodeStyle = css({
23
- [`${dragHandleContainer}:has(${elementWithEmptyBlockExperiment}),
24
- ${dragHandleContainer}:has(${elementWithEmptyBlockExperimentFormatted}),` +
25
- // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
26
- // is nested in the previous div. These selectors are to handle those cases.
27
- // -------------------
28
- // Empty block in new paragraph after indent
29
- `${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child,
30
- ${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child,` +
31
- // Empty block in new paragraph after table
32
- `${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child,
33
- ${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child,` +
34
- // Empty block in new paragraph after breakout mark
35
- `${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child,
36
- ${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child`]: {
37
- display: 'none !important'
38
- }
39
- });
40
-
41
- // Alternate styling for hiding the drag handle when the block contains the empty block experiment
42
- // Override is consistent with a feature-gated bugfix that hides the drag handle when the block contains a placeholder
43
- /**
44
- * Please do not change change transform to display:none, or visibility:hidden
45
- * Otherwise it might break composition input for Chrome
46
- * https://product-fabric.atlassian.net/browse/ED-24136
47
- */
48
- const dragHandleWithInlineNodeStyleWithChromeFix = css({
49
- [`${dragHandleContainer}:has(${elementWithEmptyBlockExperiment}) ${dragHandleSelector},
50
- ${dragHandleContainer}:has(${elementWithEmptyBlockExperimentFormatted}) ${dragHandleSelector},` +
51
- // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
52
- // is nested in the previous div. These selectors are to handle those cases.
53
- // -------------------
54
- // Empty block in new paragraph after indent
55
- `${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child ${dragHandleSelector},
56
- ${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child ${dragHandleSelector},` +
57
- // Empty block in new paragraph after table
58
- `${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child ${dragHandleSelector},
59
- ${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child ${dragHandleSelector},` +
60
- // Empty block in new paragraph after breakout mark
61
- `${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child ${dragHandleSelector},
62
- ${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child ${dragHandleSelector}`]: {
63
- transform: 'scale(0)'
64
- }
65
- });
66
- const getDragHandleOverrides = () => {
67
- return fg('platform_editor_element_controls_chrome_input_fix') ? dragHandleWithInlineNodeStyleWithChromeFix : dragHandleWithInlineNodeStyle;
68
- };
69
-
70
- /**
71
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
72
- */
73
- export const emptyBlockExperimentGlobalStyles = css({
74
- [`${emptyBlockExperimentWidget}:has(+ ${quickInsertWidget}) button`]: {
75
- transform: 'scale(0)'
76
- }
77
- }, getDragHandleOverrides());
@@ -1,138 +0,0 @@
1
- /* eslint-disable @atlaskit/ui-styling-standard/use-compiled */
2
- import React, { createElement } from 'react';
3
- import { keyframes } from '@emotion/react';
4
- import ReactDOM from 'react-dom';
5
- import { injectIntl, RawIntlProvider } from 'react-intl-next';
6
- import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
7
- import { blockControlsMessages as messages } from '@atlaskit/editor-common/messages';
8
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
9
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
10
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
11
- import EditorAddIcon from '@atlaskit/icon/glyph/editor/add';
12
- import { fg } from '@atlaskit/platform-feature-flags';
13
- import { Box, Pressable, xcss } from '@atlaskit/primitives';
14
- import Tooltip from '@atlaskit/tooltip';
15
- const wrapperStyles = xcss({
16
- position: 'absolute',
17
- top: `calc('50%' - ${"var(--ds-space-150, 12px)"})`,
18
- left: `calc(${"var(--ds-space-negative-300, -24px)"} + ${"var(--ds-space-negative-100, -8px)"})`
19
- });
20
- const appear = keyframes({
21
- from: {
22
- visibility: 'hidden'
23
- },
24
- to: {
25
- visibility: 'visible'
26
- }
27
- });
28
- const delayedAppearance = xcss({
29
- visibility: 'hidden',
30
- animation: `${appear} 0.1s`,
31
- animationDelay: '2s',
32
- animationFillMode: 'forwards'
33
- });
34
- const buttonStyles = xcss({
35
- boxSizing: 'border-box',
36
- display: 'flex',
37
- flexDirection: 'column',
38
- justifyContent: 'center',
39
- alignItems: 'center',
40
- height: "var(--ds-space-300, 24px)",
41
- width: "var(--ds-space-300, 24px)",
42
- border: 'none',
43
- backgroundColor: 'color.background.neutral',
44
- borderRadius: '50%',
45
- color: 'color.text.accent.gray',
46
- zIndex: 'card',
47
- outline: 'none',
48
- ':hover': {
49
- backgroundColor: 'color.background.neutral.hovered'
50
- },
51
- ':active': {
52
- backgroundColor: 'color.background.neutral.pressed'
53
- },
54
- ':focus': {
55
- outline: `2px solid ${"var(--ds-border-focused, #388BFF)"}`
56
- }
57
- });
58
- export const TypeAheadControl = ({
59
- api,
60
- getPos,
61
- intl: {
62
- formatMessage
63
- }
64
- }) => {
65
- return /*#__PURE__*/React.createElement(Box, {
66
- xcss: [wrapperStyles],
67
- testId: "editor-empty-line-prompt-experiment"
68
- }, /*#__PURE__*/React.createElement(Tooltip, {
69
- content: /*#__PURE__*/React.createElement(ToolTipContent, {
70
- description: formatMessage(messages.insert),
71
- shortcutOverride: "/"
72
- })
73
- }, /*#__PURE__*/React.createElement(Pressable, {
74
- type: "button",
75
- "aria-label": formatMessage(messages.insert),
76
- xcss: [buttonStyles, ...(fg('platform_editor_empty_line_prompt_delay') ? [delayedAppearance] : [])],
77
- onClick: () => {
78
- var _api$core, _api$quickInsert;
79
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
80
- tr
81
- }) => {
82
- const start = getPos();
83
- if (!start) {
84
- return null;
85
- }
86
- return tr.setSelection(TextSelection.create(tr.doc, start));
87
- });
88
- api === null || api === void 0 ? void 0 : (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.actions.openTypeAhead('blockControl');
89
- }
90
- }, /*#__PURE__*/React.createElement(EditorAddIcon, {
91
- label: "add",
92
- size: "medium"
93
- }))));
94
- };
95
- const TypeAheadControlWithIntl = injectIntl(TypeAheadControl);
96
- const toDOM = (api, getPos, getIntl) => {
97
- const wrapper = document.createElement('span');
98
- wrapper.contentEditable = 'false';
99
- wrapper.setAttribute('data-empty-block-experiment', 'true');
100
- wrapper.setAttribute('class', 'empty-block-experiment');
101
- const element = document.createElement('span');
102
- element.contentEditable = 'false';
103
- element.setAttribute('style', 'position: absolute;');
104
- wrapper.appendChild(element);
105
- ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
106
- value: getIntl()
107
- }, /*#__PURE__*/createElement(TypeAheadControlWithIntl, {
108
- api,
109
- getPos
110
- })), element);
111
-
112
- // // This is a hack to ensure that the cursor in Chrome does not take on the height of the widget button.
113
- // // Cursor height cannot be controlled via CSS and is handled by the browser.
114
- // // see Prosemirror forum: https://discuss.prosemirror.net/t/chrome-caret-cursor-larger-than-the-text-with-inlined-items/5946
115
- const cursorHack = document.createTextNode(ZERO_WIDTH_SPACE);
116
- wrapper.appendChild(cursorHack);
117
- return wrapper;
118
- };
119
- export const createEmptyBlockWidgetDecoration = (selection, api, getIntl) => {
120
- if (selection instanceof TextSelection && selection.$cursor) {
121
- var _$cursor$parent, _$cursor$parent2;
122
- const {
123
- $cursor
124
- } = selection;
125
- const {
126
- depth
127
- } = $cursor;
128
- const cursorAtRoot = depth === 1;
129
- const nodeIsEmpty = ((_$cursor$parent = $cursor.parent) === null || _$cursor$parent === void 0 ? void 0 : _$cursor$parent.nodeSize) === 2;
130
- const supportedNodeTypes = ['paragraph', 'heading'];
131
- if (cursorAtRoot && nodeIsEmpty && supportedNodeTypes.includes((_$cursor$parent2 = $cursor.parent) === null || _$cursor$parent2 === void 0 ? void 0 : _$cursor$parent2.type.name)) {
132
- return Decoration.widget(selection.$cursor.posAtIndex($cursor.depth - 1), (_view, getPos) => toDOM(api, getPos, getIntl), {
133
- key: 'emptyBlockWidgetDecoration',
134
- side: -1
135
- });
136
- }
137
- }
138
- };
@@ -1,40 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { createEmptyBlockWidgetDecoration } from '../ui/empty-block-experiment/widget';
5
- export var emptyBlockExperimentPluginKey = new PluginKey('emptyBlockExperiment');
6
- var getDecorations = function getDecorations(tr, api, getIntl) {
7
- var _api$editorDisabled;
8
- var isEditorDisabled = api === null || api === void 0 || (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 || (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.editorDisabled;
9
- if (isEditorDisabled) {
10
- return DecorationSet.empty;
11
- }
12
- var widget = createEmptyBlockWidgetDecoration(tr.selection, api, getIntl);
13
- if (widget) {
14
- return DecorationSet.create(tr.doc, [widget]);
15
- }
16
- return DecorationSet.empty;
17
- };
18
- export var createEmptyBlockExperimentPlugin = function createEmptyBlockExperimentPlugin(api, getIntl) {
19
- return new SafePlugin({
20
- key: emptyBlockExperimentPluginKey,
21
- state: {
22
- init: function init(_, _editorState) {
23
- return {
24
- decorations: DecorationSet.empty
25
- };
26
- },
27
- apply: function apply(tr, _currentState) {
28
- return {
29
- decorations: getDecorations(tr, api, getIntl)
30
- };
31
- }
32
- },
33
- props: {
34
- decorations: function decorations(state) {
35
- var _emptyBlockExperiment;
36
- return (_emptyBlockExperiment = emptyBlockExperimentPluginKey.getState(state)) === null || _emptyBlockExperiment === void 0 ? void 0 : _emptyBlockExperiment.decorations;
37
- }
38
- }
39
- });
40
- };