@atlaskit/editor-plugin-alignment 0.1.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 (75) hide show
  1. package/.eslintrc.js +18 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +30 -0
  5. package/dist/cjs/commands/index.js +62 -0
  6. package/dist/cjs/index.js +12 -0
  7. package/dist/cjs/plugin.js +69 -0
  8. package/dist/cjs/pm-plugins/keymap.js +14 -0
  9. package/dist/cjs/pm-plugins/main.js +45 -0
  10. package/dist/cjs/pm-plugins/types.js +5 -0
  11. package/dist/cjs/ui/Alignment/AlignmentButton/index.js +38 -0
  12. package/dist/cjs/ui/Alignment/index.js +57 -0
  13. package/dist/cjs/ui/Alignment/styles.js +11 -0
  14. package/dist/cjs/ui/ToolbarAlignment/icon-map.js +36 -0
  15. package/dist/cjs/ui/ToolbarAlignment/index.js +174 -0
  16. package/dist/cjs/ui/ToolbarAlignment/messages.js +29 -0
  17. package/dist/cjs/ui/ToolbarAlignment/styles.js +13 -0
  18. package/dist/cjs/utils/index.js +27 -0
  19. package/dist/es2019/commands/index.js +56 -0
  20. package/dist/es2019/index.js +1 -0
  21. package/dist/es2019/plugin.js +57 -0
  22. package/dist/es2019/pm-plugins/keymap.js +8 -0
  23. package/dist/es2019/pm-plugins/main.js +34 -0
  24. package/dist/es2019/pm-plugins/types.js +1 -0
  25. package/dist/es2019/ui/Alignment/AlignmentButton/index.js +32 -0
  26. package/dist/es2019/ui/Alignment/index.js +52 -0
  27. package/dist/es2019/ui/Alignment/styles.js +7 -0
  28. package/dist/es2019/ui/ToolbarAlignment/icon-map.js +30 -0
  29. package/dist/es2019/ui/ToolbarAlignment/index.js +145 -0
  30. package/dist/es2019/ui/ToolbarAlignment/messages.js +23 -0
  31. package/dist/es2019/ui/ToolbarAlignment/styles.js +14 -0
  32. package/dist/es2019/utils/index.js +15 -0
  33. package/dist/esm/commands/index.js +56 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/plugin.js +62 -0
  36. package/dist/esm/pm-plugins/keymap.js +8 -0
  37. package/dist/esm/pm-plugins/main.js +36 -0
  38. package/dist/esm/pm-plugins/types.js +1 -0
  39. package/dist/esm/ui/Alignment/AlignmentButton/index.js +31 -0
  40. package/dist/esm/ui/Alignment/index.js +49 -0
  41. package/dist/esm/ui/Alignment/styles.js +4 -0
  42. package/dist/esm/ui/ToolbarAlignment/icon-map.js +29 -0
  43. package/dist/esm/ui/ToolbarAlignment/index.js +168 -0
  44. package/dist/esm/ui/ToolbarAlignment/messages.js +23 -0
  45. package/dist/esm/ui/ToolbarAlignment/styles.js +6 -0
  46. package/dist/esm/utils/index.js +21 -0
  47. package/dist/types/commands/index.d.ts +4 -0
  48. package/dist/types/index.d.ts +2 -0
  49. package/dist/types/plugin.d.ts +5 -0
  50. package/dist/types/pm-plugins/keymap.d.ts +2 -0
  51. package/dist/types/pm-plugins/main.d.ts +8 -0
  52. package/dist/types/pm-plugins/types.d.ts +5 -0
  53. package/dist/types/ui/Alignment/AlignmentButton/index.d.ts +13 -0
  54. package/dist/types/ui/Alignment/index.d.ts +12 -0
  55. package/dist/types/ui/Alignment/styles.d.ts +1 -0
  56. package/dist/types/ui/ToolbarAlignment/icon-map.d.ts +6 -0
  57. package/dist/types/ui/ToolbarAlignment/index.d.ts +33 -0
  58. package/dist/types/ui/ToolbarAlignment/messages.d.ts +22 -0
  59. package/dist/types/ui/ToolbarAlignment/styles.d.ts +3 -0
  60. package/dist/types/utils/index.d.ts +3 -0
  61. package/dist/types-ts4.5/commands/index.d.ts +4 -0
  62. package/dist/types-ts4.5/index.d.ts +2 -0
  63. package/dist/types-ts4.5/plugin.d.ts +5 -0
  64. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -0
  65. package/dist/types-ts4.5/pm-plugins/main.d.ts +8 -0
  66. package/dist/types-ts4.5/pm-plugins/types.d.ts +5 -0
  67. package/dist/types-ts4.5/ui/Alignment/AlignmentButton/index.d.ts +13 -0
  68. package/dist/types-ts4.5/ui/Alignment/index.d.ts +12 -0
  69. package/dist/types-ts4.5/ui/Alignment/styles.d.ts +1 -0
  70. package/dist/types-ts4.5/ui/ToolbarAlignment/icon-map.d.ts +6 -0
  71. package/dist/types-ts4.5/ui/ToolbarAlignment/index.d.ts +33 -0
  72. package/dist/types-ts4.5/ui/ToolbarAlignment/messages.d.ts +22 -0
  73. package/dist/types-ts4.5/ui/ToolbarAlignment/styles.d.ts +3 -0
  74. package/dist/types-ts4.5/utils/index.d.ts +3 -0
  75. package/package.json +96 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ rules: {
3
+ '@typescript-eslint/no-duplicate-imports': 'error',
4
+ '@typescript-eslint/no-explicit-any': 'error',
5
+ '@typescript-eslint/ban-types': [
6
+ 'error',
7
+ {
8
+ types: {
9
+ 'React.FC':
10
+ 'Please use types directly on props instead, and explicitly define children if required',
11
+ 'React.FunctionalComponent':
12
+ 'Please use types directly on props instead, and explicitly define children if required',
13
+ },
14
+ extendDefaults: false,
15
+ },
16
+ ],
17
+ },
18
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @atlaskit/editor-plugin-alignment
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Editor plugin alignment
2
+
3
+ Alignment plugin for @atlaskit/editor-core
4
+
5
+ **Note:** This component is designed for internal Atlassian development.
6
+ External contributors will be able to use this component but will not be able to submit issues.
7
+
8
+ ## Install
9
+ ---
10
+ - **Install** - *yarn add @atlaskit/editor-plugin-alignment*
11
+ - **npm** - [@atlaskit/editor-plugin-alignment](https://www.npmjs.com/package/@atlaskit/editor-plugin-alignment)
12
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-alignment)
13
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-alignment/dist/)
14
+
15
+ ## Usage
16
+ ---
17
+ **Internal use only**
18
+
19
+ @atlaskit/editor-plugin-alignment is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
20
+
21
+ Direct use of this component is not supported.
22
+
23
+ Please see [Atlaskit - Editor plugin alignment](https://atlaskit.atlassian.com/packages/editor/editor-plugin-alignment) for documentation and examples for this package.
24
+
25
+ ## Support
26
+ ---
27
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
28
+ ## License
29
+ ---
30
+ Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isAlignable = exports.changeAlignment = void 0;
7
+ var _commands = require("@atlaskit/editor-common/commands");
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ /**
10
+ * Iterates over the commands one after the other,
11
+ * passes the tr through and dispatches the cumulated transaction
12
+ */
13
+ function cascadeCommands(cmds) {
14
+ return function (state, dispatch) {
15
+ var baseTr = state.tr;
16
+ var shouldDispatch = false;
17
+ var onDispatchAction = function onDispatchAction(tr) {
18
+ var selectionJSON = tr.selection.toJSON();
19
+ baseTr.setSelection(_state.Selection.fromJSON(baseTr.doc, selectionJSON));
20
+ tr.steps.forEach(function (st) {
21
+ baseTr.step(st);
22
+ });
23
+ shouldDispatch = true;
24
+ };
25
+ cmds.forEach(function (cmd) {
26
+ return cmd(state, onDispatchAction);
27
+ });
28
+ if (dispatch && shouldDispatch) {
29
+ dispatch(baseTr);
30
+ return true;
31
+ }
32
+ return false;
33
+ };
34
+ }
35
+ var isAlignable = exports.isAlignable = function isAlignable(align) {
36
+ return function (state, dispatch) {
37
+ var _state$schema = state.schema,
38
+ _state$schema$nodes = _state$schema.nodes,
39
+ paragraph = _state$schema$nodes.paragraph,
40
+ heading = _state$schema$nodes.heading,
41
+ alignment = _state$schema.marks.alignment;
42
+ return (0, _commands.toggleBlockMark)(alignment, function () {
43
+ return !align ? undefined : align === 'start' ? false : {
44
+ align: align
45
+ };
46
+ }, [paragraph, heading])(state, dispatch);
47
+ };
48
+ };
49
+ var changeAlignment = exports.changeAlignment = function changeAlignment(align) {
50
+ return function (state, dispatch) {
51
+ var _state$schema2 = state.schema,
52
+ _state$schema2$nodes = _state$schema2.nodes,
53
+ paragraph = _state$schema2$nodes.paragraph,
54
+ heading = _state$schema2$nodes.heading,
55
+ alignment = _state$schema2.marks.alignment;
56
+ return cascadeCommands([(0, _commands.changeImageAlignment)(align), (0, _commands.toggleBlockMark)(alignment, function () {
57
+ return !align ? undefined : align === 'start' ? false : {
58
+ align: align
59
+ };
60
+ }, [paragraph, heading])])(state, dispatch);
61
+ };
62
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "alignmentPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.alignmentPlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.defaultConfig = exports.alignmentPlugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
11
+ var _commands = require("./commands");
12
+ var _keymap = require("./pm-plugins/keymap");
13
+ var _main = require("./pm-plugins/main");
14
+ var _ToolbarAlignment = _interopRequireDefault(require("./ui/ToolbarAlignment"));
15
+ var defaultConfig = exports.defaultConfig = {
16
+ align: 'start'
17
+ };
18
+ var alignmentPlugin = exports.alignmentPlugin = function alignmentPlugin() {
19
+ return {
20
+ name: 'alignment',
21
+ marks: function marks() {
22
+ return [{
23
+ name: 'alignment',
24
+ mark: _adfSchema.alignment
25
+ }];
26
+ },
27
+ pmPlugins: function pmPlugins() {
28
+ return [{
29
+ name: 'alignmentPlugin',
30
+ plugin: function plugin(_ref) {
31
+ var dispatch = _ref.dispatch;
32
+ return (0, _main.createPlugin)(dispatch, defaultConfig);
33
+ }
34
+ }, {
35
+ name: 'annotationKeymap',
36
+ plugin: function plugin() {
37
+ return (0, _keymap.keymapPlugin)();
38
+ }
39
+ }];
40
+ },
41
+ primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
42
+ var editorView = _ref2.editorView,
43
+ popupsMountPoint = _ref2.popupsMountPoint,
44
+ popupsBoundariesElement = _ref2.popupsBoundariesElement,
45
+ popupsScrollableElement = _ref2.popupsScrollableElement,
46
+ disabled = _ref2.disabled,
47
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing;
48
+ return /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
49
+ plugins: {
50
+ align: _main.pluginKey
51
+ },
52
+ render: function render(_ref3) {
53
+ var align = _ref3.align;
54
+ return /*#__PURE__*/_react.default.createElement(_ToolbarAlignment.default, {
55
+ pluginState: align,
56
+ isReducedSpacing: isToolbarReducedSpacing,
57
+ changeAlignment: function changeAlignment(align) {
58
+ return (0, _commands.changeAlignment)(align)(editorView.state, editorView.dispatch);
59
+ },
60
+ disabled: disabled || !align.isEnabled,
61
+ popupsMountPoint: popupsMountPoint,
62
+ popupsBoundariesElement: popupsBoundariesElement,
63
+ popupsScrollableElement: popupsScrollableElement
64
+ });
65
+ }
66
+ });
67
+ }
68
+ };
69
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.keymapPlugin = keymapPlugin;
7
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
8
+ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
9
+ var _commands = require("../commands");
10
+ function keymapPlugin() {
11
+ var list = {};
12
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.alignLeft.common, (0, _commands.changeAlignment)('start'), list);
13
+ return (0, _keymap.keymap)(list);
14
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createInitialPluginState = createInitialPluginState;
8
+ exports.createPlugin = createPlugin;
9
+ exports.pluginKey = void 0;
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
+ var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _commands = require("../commands");
14
+ var _utils = require("../utils");
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ function createInitialPluginState(editorState, pluginConfig) {
18
+ return {
19
+ align: (0, _utils.getActiveAlignment)(editorState) || pluginConfig.align,
20
+ isEnabled: true
21
+ };
22
+ }
23
+ var pluginKey = exports.pluginKey = new _state.PluginKey('alignmentPlugin');
24
+ function createPlugin(dispatch, pluginConfig) {
25
+ return new _safePlugin.SafePlugin({
26
+ key: pluginKey,
27
+ state: {
28
+ init: function init(_, editorState) {
29
+ return createInitialPluginState(editorState, pluginConfig);
30
+ },
31
+ apply: function apply(_tr, state, _prevState, nextState) {
32
+ var nextPluginState = (0, _utils.getActiveAlignment)(nextState);
33
+ var isEnabled = (0, _commands.isAlignable)(nextPluginState)(nextState);
34
+ var newState = _objectSpread(_objectSpread({}, state), {}, {
35
+ align: nextPluginState,
36
+ isEnabled: isEnabled
37
+ });
38
+ if (nextPluginState !== state.align || isEnabled !== state.isEnabled) {
39
+ dispatch(pluginKey, newState);
40
+ }
41
+ return newState;
42
+ }
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
10
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
11
+ function AlignmentButton(_ref) {
12
+ var label = _ref.label,
13
+ isSelected = _ref.isSelected,
14
+ content = _ref.content,
15
+ shortcut = _ref.shortcut,
16
+ onClick = _ref.onClick,
17
+ value = _ref.value;
18
+ var onClickCallback = function onClickCallback(e) {
19
+ // detect if the click event comes from keyboard where screenX and screenY are 0
20
+ var isMouseEvent = e instanceof MouseEvent;
21
+ e.preventDefault();
22
+ onClick(value, isMouseEvent);
23
+ };
24
+ return /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
25
+ disabled: false,
26
+ selected: isSelected,
27
+ title: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
28
+ description: label,
29
+ keymap: shortcut
30
+ }),
31
+ "aria-label": shortcut ? (0, _keymaps.tooltip)(shortcut, label) : label,
32
+ "aria-pressed": isSelected,
33
+ "aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(shortcut),
34
+ onClick: onClickCallback,
35
+ iconBefore: content
36
+ });
37
+ }
38
+ var _default = exports.default = AlignmentButton;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = require("@emotion/react");
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _iconMap = require("../ToolbarAlignment/icon-map");
13
+ var _AlignmentButton = _interopRequireDefault(require("./AlignmentButton"));
14
+ var _styles = require("./styles");
15
+ /** @jsx jsx */
16
+
17
+ var alignmentOptions = [{
18
+ title: _messages.alignmentMessages.alignLeft,
19
+ shortcut: _keymaps.alignLeft,
20
+ value: 'start'
21
+ }, {
22
+ title: _messages.alignmentMessages.alignCenter,
23
+ value: 'center'
24
+ }, {
25
+ title: _messages.alignmentMessages.alignRight,
26
+ value: 'end'
27
+ }];
28
+ function Alignment(_ref) {
29
+ var onClick = _ref.onClick,
30
+ selectedAlignment = _ref.selectedAlignment,
31
+ className = _ref.className,
32
+ intl = _ref.intl;
33
+ return (0, _react.jsx)("div", {
34
+ "data-testid": "alignment-buttons"
35
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
36
+ ,
37
+ css: _styles.alignmentWrapper,
38
+ className: className
39
+ }, alignmentOptions.map(function (alignment) {
40
+ var value = alignment.value,
41
+ title = alignment.title,
42
+ shortcut = alignment.shortcut;
43
+ var message = intl.formatMessage(title);
44
+ return (0, _react.jsx)(_AlignmentButton.default, {
45
+ content: (0, _react.jsx)(_iconMap.IconMap, {
46
+ alignment: value
47
+ }),
48
+ key: value,
49
+ value: value,
50
+ label: message,
51
+ shortcut: shortcut,
52
+ onClick: onClick,
53
+ isSelected: value === selectedAlignment
54
+ });
55
+ }));
56
+ }
57
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(Alignment);
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.alignmentWrapper = void 0;
8
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
+ var _react = require("@emotion/react");
10
+ var _templateObject;
11
+ var alignmentWrapper = exports.alignmentWrapper = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n padding: 0 ", ";\n display: flex;\n flex-wrap: wrap;\n max-width: ", "px;\n"])), "var(--ds-space-100, 8px)", 3 * 32);
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.IconMap = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _alignCenter = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/align-center"));
11
+ var _alignLeft = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/align-left"));
12
+ var _alignRight = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/align-right"));
13
+ var _messages = require("./messages");
14
+ var iconAndMessageMap = {
15
+ start: {
16
+ Component: _alignLeft.default,
17
+ label: _messages.messages.alignLeft
18
+ },
19
+ end: {
20
+ Component: _alignRight.default,
21
+ label: _messages.messages.alignRight
22
+ },
23
+ center: {
24
+ Component: _alignCenter.default,
25
+ label: _messages.messages.alignCenter
26
+ }
27
+ };
28
+ var IconMap = exports.IconMap = function IconMap(props) {
29
+ var _iconAndMessageMap$pr = iconAndMessageMap[props.alignment],
30
+ Component = _iconAndMessageMap$pr.Component,
31
+ label = _iconAndMessageMap$pr.label;
32
+ var intl = (0, _reactIntlNext.useIntl)();
33
+ return /*#__PURE__*/_react.default.createElement(Component, {
34
+ label: intl.formatMessage(label)
35
+ });
36
+ };
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.AlignmentToolbar = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+ var _react = _interopRequireDefault(require("react"));
16
+ var _react2 = require("@emotion/react");
17
+ var _reactIntlNext = require("react-intl-next");
18
+ var _styles = require("@atlaskit/editor-common/styles");
19
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
20
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
21
+ var _Alignment = _interopRequireDefault(require("../Alignment"));
22
+ var _iconMap = require("./icon-map");
23
+ var _messages = require("./messages");
24
+ var _styles2 = require("./styles");
25
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
26
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** @jsx jsx */
27
+ // eslint-disable-next-line @repo/internal/react/no-class-components
28
+ var AlignmentToolbar = exports.AlignmentToolbar = /*#__PURE__*/function (_React$Component) {
29
+ (0, _inherits2.default)(AlignmentToolbar, _React$Component);
30
+ var _super = _createSuper(AlignmentToolbar);
31
+ function AlignmentToolbar() {
32
+ var _this;
33
+ (0, _classCallCheck2.default)(this, AlignmentToolbar);
34
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
35
+ args[_key] = arguments[_key];
36
+ }
37
+ _this = _super.call.apply(_super, [this].concat(args));
38
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toolbarItemRef", /*#__PURE__*/_react.default.createRef());
39
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
40
+ isOpen: false
41
+ });
42
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "changeAlignment", function (align, togglePopup) {
43
+ if (togglePopup) {
44
+ _this.toggleOpen();
45
+ }
46
+ return _this.props.changeAlignment(align);
47
+ });
48
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleOpen", function () {
49
+ _this.setState({
50
+ isOpen: !_this.state.isOpen
51
+ });
52
+ });
53
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleOpenByKeyboard", function (event) {
54
+ if (event.key === 'Enter' || event.key === ' ') {
55
+ event.preventDefault();
56
+ _this.setState({
57
+ isOpen: !_this.state.isOpen
58
+ });
59
+ }
60
+ });
61
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hide", function (attrs) {
62
+ if (_this.state.isOpen) {
63
+ _this.setState({
64
+ isOpen: false
65
+ });
66
+ if ((attrs === null || attrs === void 0 ? void 0 : attrs.event) instanceof KeyboardEvent && attrs.event.key === 'Escape') {
67
+ var _this$toolbarItemRef;
68
+ (_this$toolbarItemRef = _this.toolbarItemRef) === null || _this$toolbarItemRef === void 0 || (_this$toolbarItemRef = _this$toolbarItemRef.current) === null || _this$toolbarItemRef === void 0 || _this$toolbarItemRef.focus();
69
+ }
70
+ }
71
+ });
72
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hideOnEscape", function () {
73
+ var _this$toolbarItemRef2;
74
+ _this.hide();
75
+ (_this$toolbarItemRef2 = _this.toolbarItemRef) === null || _this$toolbarItemRef2 === void 0 || (_this$toolbarItemRef2 = _this$toolbarItemRef2.current) === null || _this$toolbarItemRef2 === void 0 || _this$toolbarItemRef2.focus();
76
+ });
77
+ return _this;
78
+ }
79
+ (0, _createClass2.default)(AlignmentToolbar, [{
80
+ key: "render",
81
+ value: function render() {
82
+ var _this2 = this;
83
+ var isOpen = this.state.isOpen;
84
+ var _this$props = this.props,
85
+ popupsMountPoint = _this$props.popupsMountPoint,
86
+ popupsBoundariesElement = _this$props.popupsBoundariesElement,
87
+ popupsScrollableElement = _this$props.popupsScrollableElement,
88
+ isReducedSpacing = _this$props.isReducedSpacing,
89
+ pluginState = _this$props.pluginState,
90
+ disabled = _this$props.disabled,
91
+ intl = _this$props.intl;
92
+ var title = intl.formatMessage(_messages.messages.alignment);
93
+ return (
94
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
95
+ (0, _react2.jsx)("span", {
96
+ css: _styles2.wrapper
97
+ }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
98
+ mountTo: popupsMountPoint,
99
+ boundariesElement: popupsBoundariesElement,
100
+ scrollableElement: popupsScrollableElement,
101
+ isOpen: isOpen,
102
+ handleClickOutside: function handleClickOutside(event) {
103
+ if (event instanceof MouseEvent) {
104
+ _this2.hide({
105
+ isOpen: false,
106
+ event: event
107
+ });
108
+ }
109
+ },
110
+ handleEscapeKeydown: this.hideOnEscape,
111
+ arrowKeyNavigationProviderOptions: {
112
+ type: _uiMenu.ArrowKeyNavigationType.MENU
113
+ },
114
+ fitWidth: 112,
115
+ fitHeight: 80,
116
+ closeOnTab: true,
117
+ trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
118
+ spacing: isReducedSpacing ? 'none' : 'default',
119
+ disabled: disabled,
120
+ selected: isOpen,
121
+ title: title,
122
+ className: "align-btn",
123
+ "aria-label": title,
124
+ "aria-expanded": isOpen,
125
+ "aria-haspopup": true,
126
+ onClick: this.toggleOpen,
127
+ onKeyDown: this.toggleOpenByKeyboard,
128
+ iconBefore:
129
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
130
+ (0, _react2.jsx)("div", {
131
+ css: _styles2.triggerWrapper
132
+ }, (0, _react2.jsx)(_iconMap.IconMap, {
133
+ alignment: pluginState.align
134
+ }), (0, _react2.jsx)("span", {
135
+ css: _styles2.expandIconWrapper
136
+ }, (0, _react2.jsx)(_chevronDown.default, {
137
+ label: ""
138
+ }))),
139
+ ref: this.toolbarItemRef
140
+ })
141
+ }, (0, _react2.jsx)(_Alignment.default, {
142
+ onClick: function onClick(align) {
143
+ return _this2.changeAlignment(align, false);
144
+ },
145
+ selectedAlignment: pluginState.align
146
+ })), (0, _react2.jsx)("span", {
147
+ css: _styles.separatorStyles
148
+ }))
149
+ );
150
+ }
151
+ }, {
152
+ key: "componentDidUpdate",
153
+ value: function componentDidUpdate(prevProps) {
154
+ var _this3 = this;
155
+ if (this.state.isOpen) {
156
+ // by triggering the keyboard event with a setTimeout, we ensure that the tooltip
157
+ // associated with the alignment button doesn't render until the next render cycle
158
+ // where the popup will be correctly positioned and the relative position of the tooltip
159
+ // will not overlap with the button.
160
+ setTimeout(function () {
161
+ var _this3$toolbarItemRef;
162
+ var keyboardEvent = new KeyboardEvent('keydown', {
163
+ bubbles: true,
164
+ key: 'ArrowDown'
165
+ });
166
+ (_this3$toolbarItemRef = _this3.toolbarItemRef.current) === null || _this3$toolbarItemRef === void 0 || _this3$toolbarItemRef.dispatchEvent(keyboardEvent);
167
+ }, 0);
168
+ }
169
+ }
170
+ }]);
171
+ return AlignmentToolbar;
172
+ }(_react.default.Component);
173
+ (0, _defineProperty2.default)(AlignmentToolbar, "displayName", 'AlignmentToolbar');
174
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(AlignmentToolbar);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.messages = void 0;
7
+ var _reactIntlNext = require("react-intl-next");
8
+ var messages = exports.messages = (0, _reactIntlNext.defineMessages)({
9
+ alignment: {
10
+ id: 'fabric.editor.alignment',
11
+ defaultMessage: 'Text alignment',
12
+ description: 'Opens drop down menu of options to configure text alignment'
13
+ },
14
+ alignLeft: {
15
+ id: 'fabric.editor.alignLeft',
16
+ defaultMessage: 'Align left',
17
+ description: 'label stating that text is aligned left'
18
+ },
19
+ alignRight: {
20
+ id: 'fabric.editor.alignRight',
21
+ defaultMessage: 'Align Right',
22
+ description: 'label stating that text is aligned right'
23
+ },
24
+ alignCenter: {
25
+ id: 'fabric.editor.alignCenter',
26
+ defaultMessage: 'Align Center',
27
+ description: 'label stating that text is aligned center'
28
+ }
29
+ });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.wrapper = exports.triggerWrapper = exports.expandIconWrapper = void 0;
8
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
+ var _react = require("@emotion/react");
10
+ var _templateObject, _templateObject2, _templateObject3;
11
+ var triggerWrapper = exports.triggerWrapper = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n"])));
12
+ var wrapper = exports.wrapper = (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n align-items: center;\n div {\n display: flex;\n }\n"])));
13
+ var expandIconWrapper = exports.expandIconWrapper = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n margin-left: ", ";\n"])), "var(--ds-space-negative-100, -8px)");