@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
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @atlaskit/editor-plugin-expand
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 expand
2
+
3
+ Expand 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-expand*
11
+ - **npm** - [@atlaskit/editor-plugin-expand](https://www.npmjs.com/package/@atlaskit/editor-plugin-expand)
12
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-expand)
13
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-expand/dist/)
14
+
15
+ ## Usage
16
+ ---
17
+ **Internal use only**
18
+
19
+ @atlaskit/editor-plugin-expand 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 expand](https://atlaskit.atlassian.com/packages/editor/editor-plugin-expand) 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://developer.atlassian.com/cloud/framework/atlassian-frontend/#license) for more licensing information.
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.updateExpandTitle = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.setExpandRef = exports.insertExpand = exports.focusTitle = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
10
+ var _selection = require("@atlaskit/editor-common/selection");
11
+ var _utils = require("@atlaskit/editor-common/utils");
12
+ var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
14
+ var _utils3 = require("@atlaskit/editor-tables/utils");
15
+ var _pluginFactory = require("./pm-plugins/plugin-factory");
16
+ var _utils4 = require("./utils");
17
+ 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; }
18
+ 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; }
19
+ var setExpandRef = exports.setExpandRef = function setExpandRef(ref) {
20
+ return (0, _pluginFactory.createCommand)({
21
+ type: 'SET_EXPAND_REF',
22
+ data: {
23
+ ref: ref
24
+ }
25
+ }, function (tr) {
26
+ return tr.setMeta('addToHistory', false);
27
+ });
28
+ };
29
+ var deleteExpandAtPos = exports.deleteExpandAtPos = function deleteExpandAtPos(editorAnalyticsAPI) {
30
+ return function (expandNodePos, expandNode) {
31
+ return function (state, dispatch) {
32
+ if (!expandNode || isNaN(expandNodePos)) {
33
+ return false;
34
+ }
35
+ var payload = {
36
+ action: _analytics.ACTION.DELETED,
37
+ actionSubject: expandNode.type === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT.EXPAND : _analytics.ACTION_SUBJECT.NESTED_EXPAND,
38
+ attributes: {
39
+ inputMethod: _analytics.INPUT_METHOD.TOOLBAR
40
+ },
41
+ eventType: _analytics.EVENT_TYPE.TRACK
42
+ };
43
+ if (expandNode && dispatch) {
44
+ var tr = state.tr;
45
+ tr.delete(expandNodePos, expandNodePos + expandNode.nodeSize);
46
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
47
+ dispatch(tr);
48
+ }
49
+ return true;
50
+ };
51
+ };
52
+ };
53
+ var deleteExpand = exports.deleteExpand = function deleteExpand(editorAnalyticsAPI) {
54
+ return function (state, dispatch) {
55
+ var expandNode = (0, _utils4.findExpand)(state);
56
+ if (!expandNode) {
57
+ return false;
58
+ }
59
+ return deleteExpandAtPos(editorAnalyticsAPI)(expandNode.pos, expandNode.node)(state, dispatch);
60
+ };
61
+ };
62
+ var updateExpandTitle = exports.updateExpandTitle = function updateExpandTitle(title, pos, nodeType) {
63
+ return function (state, dispatch) {
64
+ var node = state.doc.nodeAt(pos);
65
+ if (node && node.type === nodeType && dispatch) {
66
+ var tr = state.tr;
67
+ tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
68
+ title: title
69
+ }), node.marks);
70
+ dispatch(tr);
71
+ }
72
+ return true;
73
+ };
74
+ };
75
+ var toggleExpandExpanded = exports.toggleExpandExpanded = function toggleExpandExpanded(editorAnalyticsAPI) {
76
+ return function (pos, nodeType) {
77
+ return function (state, dispatch) {
78
+ var node = state.doc.nodeAt(pos);
79
+ if (node && node.type === nodeType && dispatch) {
80
+ var tr = state.tr;
81
+ var isExpandedNext = !node.attrs.__expanded;
82
+ tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
83
+ __expanded: isExpandedNext
84
+ }), node.marks);
85
+
86
+ // If we're going to collapse the expand and our cursor is currently inside
87
+ // Move to a right gap cursor, if the toolbar is interacted (or an API),
88
+ // it will insert below rather than inside (which will be invisible).
89
+ if (isExpandedNext === false && (0, _utils4.findExpand)(state)) {
90
+ tr.setSelection(new _selection.GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), _selection.Side.RIGHT));
91
+ }
92
+
93
+ // log when people open/close expands
94
+ // TODO: ED-8523 make platform/mode global attributes?
95
+ var payload = {
96
+ action: _analytics.ACTION.TOGGLE_EXPAND,
97
+ actionSubject: nodeType === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT.EXPAND : _analytics.ACTION_SUBJECT.NESTED_EXPAND,
98
+ attributes: {
99
+ platform: _analytics.PLATFORMS.WEB,
100
+ mode: _analytics.MODE.EDITOR,
101
+ expanded: isExpandedNext
102
+ },
103
+ eventType: _analytics.EVENT_TYPE.TRACK
104
+ };
105
+
106
+ // `isRemote` meta prevents this step from being
107
+ // sync'd between sessions in collab edit
108
+ tr.setMeta('isRemote', true);
109
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
110
+ dispatch(tr);
111
+ }
112
+ return true;
113
+ };
114
+ };
115
+ };
116
+
117
+ // Creates either an expand or a nestedExpand node based on the current selection
118
+ var createExpandNode = exports.createExpandNode = function createExpandNode(state) {
119
+ var _state$schema$nodes = state.schema.nodes,
120
+ expand = _state$schema$nodes.expand,
121
+ nestedExpand = _state$schema$nodes.nestedExpand;
122
+ var expandType = (0, _utils3.findTable)(state.selection) ? nestedExpand : expand;
123
+ return expandType.createAndFill({});
124
+ };
125
+ var insertExpand = exports.insertExpand = function insertExpand(editorAnalyticsAPI) {
126
+ return function (state, dispatch) {
127
+ var expandNode = createExpandNode(state);
128
+ if (!expandNode) {
129
+ return false;
130
+ }
131
+ var tr = state.selection.empty ? (0, _utils2.safeInsert)(expandNode)(state.tr).scrollIntoView() : (0, _utils.createWrapSelectionTransaction)({
132
+ state: state,
133
+ type: expandNode.type
134
+ });
135
+ var payload = {
136
+ action: _analytics.ACTION.INSERTED,
137
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
138
+ actionSubjectId: (expandNode === null || expandNode === void 0 ? void 0 : expandNode.type) === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT_ID.EXPAND : _analytics.ACTION_SUBJECT_ID.NESTED_EXPAND,
139
+ attributes: {
140
+ inputMethod: _analytics.INPUT_METHOD.INSERT_MENU
141
+ },
142
+ eventType: _analytics.EVENT_TYPE.TRACK
143
+ };
144
+ if (dispatch && expandNode) {
145
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
146
+ dispatch(tr);
147
+ }
148
+ return true;
149
+ };
150
+ };
151
+ var focusTitle = exports.focusTitle = function focusTitle(pos) {
152
+ return function (state, dispatch, editorView) {
153
+ if (editorView) {
154
+ var dom = editorView.domAtPos(pos);
155
+ var expandWrapper = dom.node.parentElement;
156
+ if (expandWrapper) {
157
+ setSelectionInsideExpand(pos)(state, dispatch, editorView);
158
+ var input = expandWrapper.querySelector('input');
159
+ if (input) {
160
+ input.focus();
161
+ return true;
162
+ }
163
+ }
164
+ }
165
+ return false;
166
+ };
167
+ };
168
+
169
+ // Used to clear any node or cell selection when expand title is focused
170
+ var setSelectionInsideExpand = exports.setSelectionInsideExpand = function setSelectionInsideExpand(expandPos) {
171
+ return function (state, dispatch, editorView) {
172
+ if (editorView) {
173
+ if (!editorView.hasFocus()) {
174
+ editorView.focus();
175
+ }
176
+ var sel = _state.Selection.findFrom(editorView.state.doc.resolve(expandPos), 1, true);
177
+ if (sel && dispatch) {
178
+ dispatch(editorView.state.tr.setSelection(sel));
179
+ }
180
+ return true;
181
+ }
182
+ return false;
183
+ };
184
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "expandPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.expandPlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");