@atlaskit/editor-plugin-expand 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 (66) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +30 -0
  4. package/dist/cjs/commands.js +184 -0
  5. package/dist/cjs/index.js +12 -0
  6. package/dist/cjs/nodeviews/index.js +494 -0
  7. package/dist/cjs/plugin.js +101 -0
  8. package/dist/cjs/pm-plugins/keymap.js +170 -0
  9. package/dist/cjs/pm-plugins/main.js +85 -0
  10. package/dist/cjs/pm-plugins/plugin-factory.js +15 -0
  11. package/dist/cjs/reducer.js +20 -0
  12. package/dist/cjs/toolbar.js +59 -0
  13. package/dist/cjs/types.js +5 -0
  14. package/dist/cjs/ui/ExpandIconButton.js +107 -0
  15. package/dist/cjs/utils.js +24 -0
  16. package/dist/es2019/commands.js +161 -0
  17. package/dist/es2019/index.js +1 -0
  18. package/dist/es2019/nodeviews/index.js +484 -0
  19. package/dist/es2019/plugin.js +86 -0
  20. package/dist/es2019/pm-plugins/keymap.js +197 -0
  21. package/dist/es2019/pm-plugins/main.js +73 -0
  22. package/dist/es2019/pm-plugins/plugin-factory.js +9 -0
  23. package/dist/es2019/reducer.js +11 -0
  24. package/dist/es2019/toolbar.js +52 -0
  25. package/dist/es2019/types.js +1 -0
  26. package/dist/es2019/ui/ExpandIconButton.js +88 -0
  27. package/dist/es2019/utils.js +1 -0
  28. package/dist/esm/commands.js +177 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/nodeviews/index.js +486 -0
  31. package/dist/esm/plugin.js +88 -0
  32. package/dist/esm/pm-plugins/keymap.js +165 -0
  33. package/dist/esm/pm-plugins/main.js +77 -0
  34. package/dist/esm/pm-plugins/plugin-factory.js +9 -0
  35. package/dist/esm/reducer.js +13 -0
  36. package/dist/esm/toolbar.js +52 -0
  37. package/dist/esm/types.js +1 -0
  38. package/dist/esm/ui/ExpandIconButton.js +98 -0
  39. package/dist/esm/utils.js +1 -0
  40. package/dist/types/commands.d.ts +13 -0
  41. package/dist/types/index.d.ts +3 -0
  42. package/dist/types/nodeviews/index.d.ts +55 -0
  43. package/dist/types/plugin.d.ts +24 -0
  44. package/dist/types/pm-plugins/keymap.d.ts +4 -0
  45. package/dist/types/pm-plugins/main.d.ts +7 -0
  46. package/dist/types/pm-plugins/plugin-factory.d.ts +3 -0
  47. package/dist/types/reducer.d.ts +3 -0
  48. package/dist/types/toolbar.d.ts +3 -0
  49. package/dist/types/types.d.ts +31 -0
  50. package/dist/types/ui/ExpandIconButton.d.ts +43 -0
  51. package/dist/types/utils.d.ts +1 -0
  52. package/dist/types-ts4.5/commands.d.ts +13 -0
  53. package/dist/types-ts4.5/index.d.ts +3 -0
  54. package/dist/types-ts4.5/nodeviews/index.d.ts +55 -0
  55. package/dist/types-ts4.5/plugin.d.ts +24 -0
  56. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
  57. package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
  58. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +3 -0
  59. package/dist/types-ts4.5/reducer.d.ts +3 -0
  60. package/dist/types-ts4.5/toolbar.d.ts +3 -0
  61. package/dist/types-ts4.5/types.d.ts +31 -0
  62. package/dist/types-ts4.5/ui/ExpandIconButton.d.ts +43 -0
  63. package/dist/types-ts4.5/utils.d.ts +1 -0
  64. package/package.json +104 -0
  65. package/report.api.md +93 -0
  66. package/tmp/api-report-tmp.d.ts +62 -0
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.expandKeymap = expandKeymap;
7
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
8
+ var _selection = require("@atlaskit/editor-common/selection");
9
+ var _styles = require("@atlaskit/editor-common/styles");
10
+ var _utils = require("@atlaskit/editor-common/utils");
11
+ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
12
+ var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _commands = require("../commands");
14
+ var _utils2 = require("../utils");
15
+ var isExpandNode = function isExpandNode(node) {
16
+ return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
17
+ };
18
+ var isExpandSelected = function isExpandSelected(selection) {
19
+ return selection instanceof _state.NodeSelection && isExpandNode(selection.node);
20
+ };
21
+ function expandKeymap(api) {
22
+ var list = {};
23
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, function (state, dispatch, editorView) {
24
+ if (!editorView) {
25
+ return false;
26
+ }
27
+ var selection = state.selection;
28
+ var selectionSharedState = (api === null || api === void 0 ? void 0 : api.selection.sharedState.currentState()) || {};
29
+ var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
30
+ if (isExpandSelected(selection) && selectionRelativeToNode === _selection.RelativeSelectionPos.Start) {
31
+ return (0, _commands.focusTitle)(selection.from + 1)(state, dispatch, editorView);
32
+ }
33
+ return false;
34
+ }, list);
35
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, function (state, dispatch, editorView) {
36
+ if (!editorView) {
37
+ return false;
38
+ }
39
+ var selection = state.selection;
40
+ var selectionSharedState = (api === null || api === void 0 ? void 0 : api.selection.sharedState.currentState()) || {};
41
+ var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
42
+ if (isExpandSelected(selection) && (selectionRelativeToNode === undefined || selectionRelativeToNode === _selection.RelativeSelectionPos.End)) {
43
+ return (0, _commands.focusTitle)(selection.from + 1)(state, dispatch, editorView);
44
+ }
45
+ return false;
46
+ }, list);
47
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.tab.common, function (state, dispatch, editorView) {
48
+ if (state.selection instanceof _state.NodeSelection && state.selection.node.type === state.schema.nodes.expand && editorView && editorView.dom instanceof HTMLElement) {
49
+ var from = state.selection.from;
50
+ var expand = editorView.nodeDOM(from);
51
+ if (!expand || !(expand instanceof HTMLElement)) {
52
+ return false;
53
+ }
54
+ var iconContainer = expand.querySelector(".".concat(_styles.expandClassNames.iconContainer));
55
+ if (iconContainer && iconContainer.focus) {
56
+ var tr = state.tr;
57
+ var pos = state.selection.from;
58
+ tr.setSelection(new _state.TextSelection(tr.doc.resolve(pos)));
59
+ if (dispatch) {
60
+ dispatch(tr);
61
+ }
62
+ editorView.dom.blur();
63
+ iconContainer.focus();
64
+ }
65
+ return true;
66
+ }
67
+ return false;
68
+ }, list);
69
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, function (state, dispatch, editorView) {
70
+ if (!editorView) {
71
+ return false;
72
+ }
73
+ var selection = state.selection,
74
+ schema = state.schema;
75
+ var nodeBefore = selection.$from.nodeBefore;
76
+ if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand) && !nodeBefore.attrs.__expanded) {
77
+ var _$from = selection.$from;
78
+ return (0, _commands.focusTitle)(Math.max(_$from.pos - 1, 0))(state, dispatch, editorView);
79
+ }
80
+ var $from = state.selection.$from;
81
+ if (editorView.endOfTextblock('up')) {
82
+ var expand = (0, _utils2.findExpand)(state);
83
+
84
+ // Moving UP in a table should move the cursor to the row above
85
+ // however when an expand is in a table cell to the left of the
86
+ // current table cell, arrow UP moves the cursor to the left
87
+ // see ED-15425
88
+ if ((0, _utils.isPositionNearTableRow)($from, schema, 'before') && !expand) {
89
+ return false;
90
+ }
91
+ var prevCursorPos = Math.max($from.pos - $from.parentOffset - 1, 0);
92
+ // move cursor from expand's content to its title
93
+ if (expand && expand.start === prevCursorPos) {
94
+ return (0, _commands.focusTitle)(expand.start)(state, dispatch, editorView);
95
+ }
96
+ var sel = _state.Selection.findFrom(state.doc.resolve(prevCursorPos), -1);
97
+ var expandBefore = (0, _utils2.findExpand)(state, sel);
98
+ if (sel && expandBefore) {
99
+ // moving cursor from outside of an expand to the title when it is collapsed
100
+ if (!expandBefore.node.attrs.__expanded) {
101
+ return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
102
+ }
103
+ // moving cursor from outside of an expand to the content when it is expanded
104
+ else if (dispatch) {
105
+ dispatch(state.tr.setSelection(sel));
106
+ }
107
+ return true;
108
+ }
109
+ }
110
+ return false;
111
+ }, list);
112
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveDown.common, function (state, dispatch, editorView) {
113
+ if (!editorView) {
114
+ return false;
115
+ }
116
+ var _state$schema$nodes = state.schema.nodes,
117
+ expand = _state$schema$nodes.expand,
118
+ nestedExpand = _state$schema$nodes.nestedExpand;
119
+ var selection = state.selection;
120
+ var nodeAfter = selection.$from.nodeAfter;
121
+ if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand) && !nodeAfter.attrs.__expanded) {
122
+ var $from = selection.$from;
123
+ return (0, _commands.focusTitle)($from.pos + 1)(state, dispatch, editorView);
124
+ }
125
+ if (editorView.endOfTextblock('down')) {
126
+ var _$from2 = state.selection.$from;
127
+ if (_$from2.depth === 0) {
128
+ return false;
129
+ }
130
+ var $after = state.doc.resolve(_$from2.after());
131
+ if ($after.nodeAfter && ($after.nodeAfter.type === expand || $after.nodeAfter.type === nestedExpand)) {
132
+ return (0, _commands.focusTitle)($after.pos + 1)(state, dispatch, editorView);
133
+ }
134
+ }
135
+ return false;
136
+ }, list);
137
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, function (state, dispatch, editorView) {
138
+ var selection = state.selection;
139
+ var $from = selection.$from;
140
+ if (!editorView || !selection.empty) {
141
+ return false;
142
+ }
143
+ var _state$schema$nodes2 = state.schema.nodes,
144
+ expand = _state$schema$nodes2.expand,
145
+ nestedExpand = _state$schema$nodes2.nestedExpand;
146
+ var expandNode = (0, _utils2.findExpand)(state);
147
+ if (!expandNode) {
148
+ // @see ED-7977
149
+ var sel = _state.Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
150
+ var expandBefore = (0, _utils2.findExpand)(state, sel);
151
+ if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand) && !expandBefore.node.attrs.__expanded) {
152
+ return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
153
+ }
154
+ return false;
155
+ }
156
+ var parentNode = state.doc.nodeAt($from.before(Math.max($from.depth - 1, 1)));
157
+ // ED-10012 catch cases where the expand has another node nested within it and
158
+ // the backspace should be applied only to the inner node instead of the expand
159
+ if (parentNode && !isExpandNode(parentNode)) {
160
+ return false;
161
+ }
162
+ var textSel = _state.Selection.findFrom(state.doc.resolve(expandNode.pos), 1, true);
163
+ if (textSel && selection.$from.pos === textSel.$from.pos && (0, _utils.isEmptyNode)(state.schema)(expandNode.node) && dispatch) {
164
+ var _api$analytics;
165
+ return (0, _commands.deleteExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(state, dispatch);
166
+ }
167
+ return false;
168
+ }, list);
169
+ return (0, _keymap.keymap)(list);
170
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.containsClass = containsClass;
8
+ exports.createPlugin = void 0;
9
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
+ var _selection = require("@atlaskit/editor-common/selection");
11
+ var _styles = require("@atlaskit/editor-common/styles");
12
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
13
+ var _commands = require("../commands");
14
+ var _nodeviews = _interopRequireDefault(require("../nodeviews"));
15
+ var _utils2 = require("../utils");
16
+ var _pluginFactory = require("./plugin-factory");
17
+ function containsClass(element, className) {
18
+ var _element$classList;
19
+ return Boolean(element === null || element === void 0 || (_element$classList = element.classList) === null || _element$classList === void 0 ? void 0 : _element$classList.contains(className));
20
+ }
21
+ var createPlugin = exports.createPlugin = function createPlugin(dispatch, getIntl) {
22
+ var appearance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'full-page';
23
+ var useLongPressSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
24
+ var featureFlags = arguments.length > 4 ? arguments[4] : undefined;
25
+ var api = arguments.length > 5 ? arguments[5] : undefined;
26
+ var state = (0, _pluginFactory.createPluginState)(dispatch, {});
27
+ var isMobile = appearance === 'mobile';
28
+ return new _safePlugin.SafePlugin({
29
+ state: state,
30
+ key: _pluginFactory.pluginKey,
31
+ props: {
32
+ nodeViews: {
33
+ expand: (0, _nodeviews.default)({
34
+ getIntl: getIntl,
35
+ isMobile: isMobile,
36
+ featureFlags: featureFlags,
37
+ api: api
38
+ }),
39
+ nestedExpand: (0, _nodeviews.default)({
40
+ getIntl: getIntl,
41
+ isMobile: isMobile,
42
+ featureFlags: featureFlags,
43
+ api: api
44
+ })
45
+ },
46
+ handleKeyDown: function handleKeyDown(_view, event) {
47
+ return containsClass(event.target, _styles.expandClassNames.titleContainer);
48
+ },
49
+ handleKeyPress: function handleKeyPress(_view, event) {
50
+ return containsClass(event.target, _styles.expandClassNames.titleContainer);
51
+ },
52
+ handleScrollToSelection: function handleScrollToSelection() {
53
+ return containsClass(document.activeElement, _styles.expandClassNames.titleInput);
54
+ },
55
+ handleClickOn: (0, _selection.createSelectionClickHandler)(['expand', 'nestedExpand'], function (target) {
56
+ return target.classList.contains(_styles.expandClassNames.prefix);
57
+ }, {
58
+ useLongPressSelection: useLongPressSelection
59
+ })
60
+ },
61
+ // @see ED-8027 to follow up on this work-around
62
+ filterTransaction: function filterTransaction(tr) {
63
+ if (containsClass(document.activeElement, _styles.expandClassNames.titleInput) && tr.selectionSet && (!tr.steps.length || tr.isGeneric)) {
64
+ return false;
65
+ }
66
+ return true;
67
+ },
68
+ view: function view(editorView) {
69
+ var domAtPos = editorView.domAtPos.bind(editorView);
70
+ return {
71
+ update: function update(view) {
72
+ var state = view.state,
73
+ dispatch = view.dispatch;
74
+ var node = (0, _utils2.findExpand)(state);
75
+ if (node) {
76
+ var expandRef = (0, _utils.findDomRefAtPos)(node.pos, domAtPos);
77
+ if ((0, _pluginFactory.getPluginState)(state).expandRef !== expandRef) {
78
+ (0, _commands.setExpandRef)(expandRef)(state, dispatch);
79
+ }
80
+ }
81
+ }
82
+ };
83
+ }
84
+ });
85
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.pluginKey = exports.getPluginState = exports.createPluginState = exports.createCommand = void 0;
8
+ var _utils = require("@atlaskit/editor-common/utils");
9
+ var _state = require("@atlaskit/editor-prosemirror/state");
10
+ var _reducer = _interopRequireDefault(require("../reducer"));
11
+ var pluginKey = exports.pluginKey = new _state.PluginKey('expandPlugin');
12
+ var _pluginFactory = (0, _utils.pluginFactory)(pluginKey, _reducer.default),
13
+ createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
14
+ createCommand = exports.createCommand = _pluginFactory.createCommand,
15
+ getPluginState = exports.getPluginState = _pluginFactory.getPluginState;
@@ -0,0 +1,20 @@
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ 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; }
10
+ 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; }
11
+ var _default = exports.default = function _default(pluginState, action) {
12
+ switch (action.type) {
13
+ case 'SET_EXPAND_REF':
14
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
15
+ expandRef: action.data.ref
16
+ });
17
+ default:
18
+ return pluginState;
19
+ }
20
+ };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarConfig = void 0;
8
+ var _messages = _interopRequireDefault(require("@atlaskit/editor-common/messages"));
9
+ var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
10
+ var _commands = require("./commands");
11
+ var _pluginFactory = require("./pm-plugins/plugin-factory");
12
+ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(api) {
13
+ return function (state, _ref) {
14
+ var _api$decorations$acti, _api$decorations, _api$analytics;
15
+ var formatMessage = _ref.formatMessage;
16
+ var _ref2 = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
17
+ hoverDecoration = _ref2.hoverDecoration;
18
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
19
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
20
+ expandRef = _getPluginState.expandRef;
21
+ if (expandRef) {
22
+ var _state$schema$nodes = state.schema.nodes,
23
+ nestedExpand = _state$schema$nodes.nestedExpand,
24
+ expand = _state$schema$nodes.expand;
25
+ return {
26
+ title: 'Expand toolbar',
27
+ getDomRef: function getDomRef() {
28
+ return expandRef;
29
+ },
30
+ nodeType: [nestedExpand, expand],
31
+ offset: [0, 6],
32
+ items: [{
33
+ type: 'copy-button',
34
+ items: [{
35
+ state: state,
36
+ formatMessage: formatMessage,
37
+ nodeType: [nestedExpand, expand]
38
+ }, {
39
+ type: 'separator'
40
+ }]
41
+ }, {
42
+ id: 'editor.expand.delete',
43
+ type: 'button',
44
+ appearance: 'danger',
45
+ focusEditoronEnter: true,
46
+ icon: _remove.default,
47
+ onClick: (0, _commands.deleteExpand)(editorAnalyticsAPI),
48
+ onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
49
+ onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
50
+ onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
51
+ onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
52
+ title: formatMessage(_messages.default.remove),
53
+ tabIndex: null
54
+ }]
55
+ };
56
+ }
57
+ return;
58
+ };
59
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,107 @@
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.withTooltip = exports.ExpandIconButton = exports.CustomButton = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
16
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
+ var _react = _interopRequireWildcard(require("react"));
18
+ var _react2 = require("@emotion/react");
19
+ var _customThemeButton = _interopRequireDefault(require("@atlaskit/button/custom-theme-button"));
20
+ var _styles = require("@atlaskit/editor-common/styles");
21
+ var _ui = require("@atlaskit/editor-common/ui");
22
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
23
+ var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-right"));
24
+ var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
25
+ var _excluded = ["buttonStyles"];
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ 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; }
29
+ 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; }
30
+ 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); }; }
31
+ 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 */
32
+ var withTooltip = exports.withTooltip = function withTooltip(WrapperComponent) {
33
+ return /*#__PURE__*/function (_React$Component) {
34
+ (0, _inherits2.default)(WithSortableColumn, _React$Component);
35
+ var _super = _createSuper(WithSortableColumn);
36
+ function WithSortableColumn(props) {
37
+ (0, _classCallCheck2.default)(this, WithSortableColumn);
38
+ return _super.call(this, props);
39
+ }
40
+ (0, _createClass2.default)(WithSortableColumn, [{
41
+ key: "render",
42
+ value: function render() {
43
+ var label = this.props.label;
44
+ return (0, _react2.jsx)(_tooltip.default, {
45
+ content: label,
46
+ position: "top",
47
+ tag: _ui.ExpandLayoutWrapperWithRef
48
+ }, (0, _react2.jsx)(WrapperComponent, this.props));
49
+ }
50
+ }]);
51
+ return WithSortableColumn;
52
+ }(_react.default.Component);
53
+ };
54
+ var CustomButton = exports.CustomButton = function CustomButton(props) {
55
+ var label = props.label,
56
+ allowInteractiveExpand = props.allowInteractiveExpand;
57
+ var useTheme = (0, _react.useCallback)(function (currentTheme, themeProps) {
58
+ var _currentTheme = currentTheme(themeProps),
59
+ buttonStyles = _currentTheme.buttonStyles,
60
+ rest = (0, _objectWithoutProperties2.default)(_currentTheme, _excluded);
61
+ return _objectSpread({
62
+ buttonStyles: _objectSpread(_objectSpread({}, buttonStyles), {}, {
63
+ height: '100%',
64
+ '& svg': {
65
+ transform: props.expanded ? 'transform: rotate(90deg);' : 'transform: rotate(0deg);',
66
+ transition: "transform 0.2s ".concat(_editorSharedStyles.akEditorSwoopCubicBezier, ";")
67
+ }
68
+ })
69
+ }, rest);
70
+ }, [props]);
71
+ return (0, _react2.jsx)(_customThemeButton.default, {
72
+ appearance: "subtle",
73
+ className: _styles.expandClassNames.iconContainer,
74
+ iconBefore: (0, _react2.jsx)(_chevronRight.default, {
75
+ label: label
76
+ }),
77
+ shouldFitContainer: true,
78
+ theme: useTheme,
79
+ isDisabled: !allowInteractiveExpand
80
+ });
81
+ };
82
+ var ButtonWithTooltip = withTooltip(CustomButton);
83
+ var ButtonWithoutTooltip = CustomButton;
84
+ var ExpandIconButton = exports.ExpandIconButton = function ExpandIconButton(props) {
85
+ var expanded = props.expanded,
86
+ intl = props.intl;
87
+ var message = expanded ? _ui.expandMessages.collapseNode : _ui.expandMessages.expandNode;
88
+ var label = intl && intl.formatMessage(message) || message.defaultMessage;
89
+ // check to ensure device supports any-hover
90
+ var supportsAnyHover = !!window.matchMedia ? window.matchMedia('(any-hover: hover)').matches !== window.matchMedia('(any-hover: none)').matches : false;
91
+ var hoverEventCheck = supportsAnyHover ? window.matchMedia('(any-hover: hover)').matches : true;
92
+
93
+ // hoverEventCheck is to disable tooltips for mobile to prevent incorrect hover state causing issues on iOS
94
+ if (props.allowInteractiveExpand && hoverEventCheck) {
95
+ return (0, _react2.jsx)(ButtonWithTooltip, (0, _extends2.default)({
96
+ label: label
97
+ }, props));
98
+ }
99
+ return (
100
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
101
+ (0, _react2.jsx)("div", {
102
+ css: _ui.expandLayoutWrapperStyle
103
+ }, (0, _react2.jsx)(ButtonWithoutTooltip, (0, _extends2.default)({
104
+ label: label
105
+ }, props)))
106
+ );
107
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "findExpand", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _transforms.findExpand;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "transformSliceNestedExpandToExpand", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _transforms.transformSliceNestedExpandToExpand;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "transformSliceToRemoveOpenExpand", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _transforms.transformSliceToRemoveOpenExpand;
22
+ }
23
+ });
24
+ var _transforms = require("@atlaskit/editor-common/transforms");
@@ -0,0 +1,161 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
2
+ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
3
+ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
4
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
+ import { findTable } from '@atlaskit/editor-tables/utils';
7
+ import { createCommand } from './pm-plugins/plugin-factory';
8
+ import { findExpand } from './utils';
9
+ export const setExpandRef = ref => createCommand({
10
+ type: 'SET_EXPAND_REF',
11
+ data: {
12
+ ref
13
+ }
14
+ }, tr => tr.setMeta('addToHistory', false));
15
+ export const deleteExpandAtPos = editorAnalyticsAPI => (expandNodePos, expandNode) => (state, dispatch) => {
16
+ if (!expandNode || isNaN(expandNodePos)) {
17
+ return false;
18
+ }
19
+ const payload = {
20
+ action: ACTION.DELETED,
21
+ actionSubject: expandNode.type === state.schema.nodes.expand ? ACTION_SUBJECT.EXPAND : ACTION_SUBJECT.NESTED_EXPAND,
22
+ attributes: {
23
+ inputMethod: INPUT_METHOD.TOOLBAR
24
+ },
25
+ eventType: EVENT_TYPE.TRACK
26
+ };
27
+ if (expandNode && dispatch) {
28
+ const {
29
+ tr
30
+ } = state;
31
+ tr.delete(expandNodePos, expandNodePos + expandNode.nodeSize);
32
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
33
+ dispatch(tr);
34
+ }
35
+ return true;
36
+ };
37
+ export const deleteExpand = editorAnalyticsAPI => (state, dispatch) => {
38
+ const expandNode = findExpand(state);
39
+ if (!expandNode) {
40
+ return false;
41
+ }
42
+ return deleteExpandAtPos(editorAnalyticsAPI)(expandNode.pos, expandNode.node)(state, dispatch);
43
+ };
44
+ export const updateExpandTitle = (title, pos, nodeType) => (state, dispatch) => {
45
+ const node = state.doc.nodeAt(pos);
46
+ if (node && node.type === nodeType && dispatch) {
47
+ const {
48
+ tr
49
+ } = state;
50
+ tr.setNodeMarkup(pos, node.type, {
51
+ ...node.attrs,
52
+ title
53
+ }, node.marks);
54
+ dispatch(tr);
55
+ }
56
+ return true;
57
+ };
58
+ export const toggleExpandExpanded = editorAnalyticsAPI => (pos, nodeType) => (state, dispatch) => {
59
+ const node = state.doc.nodeAt(pos);
60
+ if (node && node.type === nodeType && dispatch) {
61
+ const {
62
+ tr
63
+ } = state;
64
+ const isExpandedNext = !node.attrs.__expanded;
65
+ tr.setNodeMarkup(pos, node.type, {
66
+ ...node.attrs,
67
+ __expanded: isExpandedNext
68
+ }, node.marks);
69
+
70
+ // If we're going to collapse the expand and our cursor is currently inside
71
+ // Move to a right gap cursor, if the toolbar is interacted (or an API),
72
+ // it will insert below rather than inside (which will be invisible).
73
+ if (isExpandedNext === false && findExpand(state)) {
74
+ tr.setSelection(new GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), Side.RIGHT));
75
+ }
76
+
77
+ // log when people open/close expands
78
+ // TODO: ED-8523 make platform/mode global attributes?
79
+ const payload = {
80
+ action: ACTION.TOGGLE_EXPAND,
81
+ actionSubject: nodeType === state.schema.nodes.expand ? ACTION_SUBJECT.EXPAND : ACTION_SUBJECT.NESTED_EXPAND,
82
+ attributes: {
83
+ platform: PLATFORMS.WEB,
84
+ mode: MODE.EDITOR,
85
+ expanded: isExpandedNext
86
+ },
87
+ eventType: EVENT_TYPE.TRACK
88
+ };
89
+
90
+ // `isRemote` meta prevents this step from being
91
+ // sync'd between sessions in collab edit
92
+ tr.setMeta('isRemote', true);
93
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
94
+ dispatch(tr);
95
+ }
96
+ return true;
97
+ };
98
+
99
+ // Creates either an expand or a nestedExpand node based on the current selection
100
+ export const createExpandNode = state => {
101
+ const {
102
+ expand,
103
+ nestedExpand
104
+ } = state.schema.nodes;
105
+ const expandType = findTable(state.selection) ? nestedExpand : expand;
106
+ return expandType.createAndFill({});
107
+ };
108
+ export const insertExpand = editorAnalyticsAPI => (state, dispatch) => {
109
+ const expandNode = createExpandNode(state);
110
+ if (!expandNode) {
111
+ return false;
112
+ }
113
+ const tr = state.selection.empty ? safeInsert(expandNode)(state.tr).scrollIntoView() : createWrapSelectionTransaction({
114
+ state,
115
+ type: expandNode.type
116
+ });
117
+ const payload = {
118
+ action: ACTION.INSERTED,
119
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
120
+ actionSubjectId: (expandNode === null || expandNode === void 0 ? void 0 : expandNode.type) === state.schema.nodes.expand ? ACTION_SUBJECT_ID.EXPAND : ACTION_SUBJECT_ID.NESTED_EXPAND,
121
+ attributes: {
122
+ inputMethod: INPUT_METHOD.INSERT_MENU
123
+ },
124
+ eventType: EVENT_TYPE.TRACK
125
+ };
126
+ if (dispatch && expandNode) {
127
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
128
+ dispatch(tr);
129
+ }
130
+ return true;
131
+ };
132
+ export const focusTitle = pos => (state, dispatch, editorView) => {
133
+ if (editorView) {
134
+ const dom = editorView.domAtPos(pos);
135
+ const expandWrapper = dom.node.parentElement;
136
+ if (expandWrapper) {
137
+ setSelectionInsideExpand(pos)(state, dispatch, editorView);
138
+ const input = expandWrapper.querySelector('input');
139
+ if (input) {
140
+ input.focus();
141
+ return true;
142
+ }
143
+ }
144
+ }
145
+ return false;
146
+ };
147
+
148
+ // Used to clear any node or cell selection when expand title is focused
149
+ export const setSelectionInsideExpand = expandPos => (state, dispatch, editorView) => {
150
+ if (editorView) {
151
+ if (!editorView.hasFocus()) {
152
+ editorView.focus();
153
+ }
154
+ const sel = Selection.findFrom(editorView.state.doc.resolve(expandPos), 1, true);
155
+ if (sel && dispatch) {
156
+ dispatch(editorView.state.tr.setSelection(sel));
157
+ }
158
+ return true;
159
+ }
160
+ return false;
161
+ };
@@ -0,0 +1 @@
1
+ export { expandPlugin } from './plugin';