@atlaskit/editor-plugin-tasks-and-decisions 0.1.0 → 0.2.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 (105) hide show
  1. package/.eslintrc.js +26 -0
  2. package/CHANGELOG.md +10 -0
  3. package/dist/cjs/commands.js +288 -0
  4. package/dist/cjs/index.js +8 -1
  5. package/dist/cjs/nodeviews/decisionItem.js +117 -0
  6. package/dist/cjs/nodeviews/hooks/use-show-placeholder.js +40 -0
  7. package/dist/cjs/nodeviews/taskItem.js +211 -0
  8. package/dist/cjs/plugin.js +166 -0
  9. package/dist/cjs/pm-plugins/commands.js +96 -0
  10. package/dist/cjs/pm-plugins/helpers.js +299 -0
  11. package/dist/cjs/pm-plugins/input-rules.js +94 -0
  12. package/dist/cjs/pm-plugins/keymaps.js +376 -0
  13. package/dist/cjs/pm-plugins/main.js +263 -0
  14. package/dist/cjs/pm-plugins/plugin-key.js +8 -0
  15. package/dist/cjs/pm-plugins/types.js +11 -0
  16. package/dist/cjs/types.js +5 -0
  17. package/dist/cjs/ui/Decision/index.js +30 -0
  18. package/dist/cjs/ui/Task/index.js +81 -0
  19. package/dist/cjs/ui/Task/task-item-with-providers.js +138 -0
  20. package/dist/cjs/ui/ToolbarDecision/index.js +41 -0
  21. package/dist/cjs/ui/ToolbarTask/index.js +40 -0
  22. package/dist/cjs/utils.js +41 -0
  23. package/dist/es2019/commands.js +279 -0
  24. package/dist/es2019/index.js +1 -1
  25. package/dist/es2019/nodeviews/decisionItem.js +76 -0
  26. package/dist/es2019/nodeviews/hooks/use-show-placeholder.js +36 -0
  27. package/dist/es2019/nodeviews/taskItem.js +173 -0
  28. package/dist/es2019/plugin.js +154 -0
  29. package/dist/es2019/pm-plugins/commands.js +94 -0
  30. package/dist/es2019/pm-plugins/helpers.js +316 -0
  31. package/dist/es2019/pm-plugins/input-rules.js +91 -0
  32. package/dist/es2019/pm-plugins/keymaps.js +370 -0
  33. package/dist/es2019/pm-plugins/main.js +262 -0
  34. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  35. package/dist/es2019/pm-plugins/types.js +5 -0
  36. package/dist/es2019/types.js +1 -0
  37. package/dist/es2019/ui/Decision/index.js +26 -0
  38. package/dist/es2019/ui/Task/index.js +55 -0
  39. package/dist/es2019/ui/Task/task-item-with-providers.js +72 -0
  40. package/dist/es2019/ui/ToolbarDecision/index.js +37 -0
  41. package/dist/es2019/ui/ToolbarTask/index.js +36 -0
  42. package/dist/es2019/utils.js +32 -0
  43. package/dist/esm/commands.js +281 -0
  44. package/dist/esm/index.js +1 -1
  45. package/dist/esm/nodeviews/decisionItem.js +110 -0
  46. package/dist/esm/nodeviews/hooks/use-show-placeholder.js +34 -0
  47. package/dist/esm/nodeviews/taskItem.js +204 -0
  48. package/dist/esm/plugin.js +155 -0
  49. package/dist/esm/pm-plugins/commands.js +90 -0
  50. package/dist/esm/pm-plugins/helpers.js +285 -0
  51. package/dist/esm/pm-plugins/input-rules.js +87 -0
  52. package/dist/esm/pm-plugins/keymaps.js +368 -0
  53. package/dist/esm/pm-plugins/main.js +256 -0
  54. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  55. package/dist/esm/pm-plugins/types.js +5 -0
  56. package/dist/esm/types.js +1 -0
  57. package/dist/esm/ui/Decision/index.js +23 -0
  58. package/dist/esm/ui/Task/index.js +71 -0
  59. package/dist/esm/ui/Task/task-item-with-providers.js +129 -0
  60. package/dist/esm/ui/ToolbarDecision/index.js +34 -0
  61. package/dist/esm/ui/ToolbarTask/index.js +33 -0
  62. package/dist/esm/utils.js +30 -0
  63. package/dist/types/commands.d.ts +16 -0
  64. package/dist/types/index.d.ts +2 -1
  65. package/dist/types/nodeviews/decisionItem.d.ts +10 -0
  66. package/dist/types/nodeviews/hooks/use-show-placeholder.d.ts +11 -0
  67. package/dist/types/nodeviews/taskItem.d.ts +14 -0
  68. package/dist/types/plugin.d.ts +2 -0
  69. package/dist/types/pm-plugins/commands.d.ts +15 -0
  70. package/dist/types/pm-plugins/helpers.d.ts +76 -0
  71. package/dist/types/pm-plugins/input-rules.d.ts +6 -0
  72. package/dist/types/pm-plugins/keymaps.d.ts +11 -0
  73. package/dist/types/pm-plugins/main.d.ts +7 -0
  74. package/dist/types/pm-plugins/plugin-key.d.ts +2 -0
  75. package/dist/types/pm-plugins/types.d.ts +8 -0
  76. package/dist/types/types.d.ts +49 -0
  77. package/dist/types/ui/Decision/index.d.ts +15 -0
  78. package/dist/types/ui/Task/index.d.ts +28 -0
  79. package/dist/types/ui/Task/task-item-with-providers.d.ts +29 -0
  80. package/dist/types/ui/ToolbarDecision/index.d.ts +18 -0
  81. package/dist/types/ui/ToolbarTask/index.d.ts +18 -0
  82. package/dist/types/utils.d.ts +4 -0
  83. package/dist/types-ts4.5/commands.d.ts +16 -0
  84. package/dist/types-ts4.5/index.d.ts +2 -1
  85. package/dist/types-ts4.5/nodeviews/decisionItem.d.ts +10 -0
  86. package/dist/types-ts4.5/nodeviews/hooks/use-show-placeholder.d.ts +11 -0
  87. package/dist/types-ts4.5/nodeviews/taskItem.d.ts +14 -0
  88. package/dist/types-ts4.5/plugin.d.ts +2 -0
  89. package/dist/types-ts4.5/pm-plugins/commands.d.ts +15 -0
  90. package/dist/types-ts4.5/pm-plugins/helpers.d.ts +76 -0
  91. package/dist/types-ts4.5/pm-plugins/input-rules.d.ts +6 -0
  92. package/dist/types-ts4.5/pm-plugins/keymaps.d.ts +11 -0
  93. package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
  94. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +2 -0
  95. package/dist/types-ts4.5/pm-plugins/types.d.ts +8 -0
  96. package/dist/types-ts4.5/types.d.ts +49 -0
  97. package/dist/types-ts4.5/ui/Decision/index.d.ts +15 -0
  98. package/dist/types-ts4.5/ui/Task/index.d.ts +28 -0
  99. package/dist/types-ts4.5/ui/Task/task-item-with-providers.d.ts +29 -0
  100. package/dist/types-ts4.5/ui/ToolbarDecision/index.d.ts +18 -0
  101. package/dist/types-ts4.5/ui/ToolbarTask/index.d.ts +18 -0
  102. package/dist/types-ts4.5/utils.d.ts +4 -0
  103. package/package.json +16 -6
  104. package/report.api.md +100 -1
  105. package/tmp/api-report-tmp.d.ts +78 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,26 @@
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
+ overrides: [
19
+ {
20
+ files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
21
+ rules: {
22
+ '@typescript-eslint/no-explicit-any': 'off',
23
+ },
24
+ },
25
+ ],
26
+ };
package/CHANGELOG.md CHANGED
@@ -1 +1,11 @@
1
1
  # @atlaskit/editor-plugin-tasks-and-decisions
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#43405](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43405) [`150827259db`](https://bitbucket.org/atlassian/atlassian-frontend/commits/150827259db) - Extracting tasks and decisions code from editor-core to new plugin package.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isSupportedSourceNode = exports.insertTaskDecisionWithAnalytics = exports.insertTaskDecisionCommand = exports.insertTaskDecisionAction = exports.getListTypes = exports.createListAtSelection = exports.changeInDepth = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _selection = require("@atlaskit/editor-common/selection");
12
+ var _utils = require("@atlaskit/editor-common/utils");
13
+ var _model = require("@atlaskit/editor-prosemirror/model");
14
+ var _state = require("@atlaskit/editor-prosemirror/state");
15
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
16
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
17
+ var _pluginKey = require("./pm-plugins/plugin-key");
18
+ 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; }
19
+ 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; }
20
+ var getContextData = function getContextData() {
21
+ var contextProvider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
22
+ var objectId = contextProvider.objectId,
23
+ containerId = contextProvider.containerId;
24
+ var userContext = objectId ? _analytics.USER_CONTEXT.EDIT : _analytics.USER_CONTEXT.NEW;
25
+ return {
26
+ objectId: objectId,
27
+ containerId: containerId,
28
+ userContext: userContext
29
+ };
30
+ };
31
+ var generateAnalyticsPayload = function generateAnalyticsPayload(listType, contextData, inputMethod, itemLocalId, listLocalId, itemIdx, listSize) {
32
+ var containerId;
33
+ var objectId;
34
+ var userContext;
35
+ if (contextData) {
36
+ containerId = contextData.containerId;
37
+ objectId = contextData.objectId;
38
+ userContext = contextData.userContext;
39
+ }
40
+ return {
41
+ action: _analytics.ACTION.INSERTED,
42
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
43
+ actionSubjectId: listType === 'taskList' ? _analytics.ACTION_SUBJECT_ID.ACTION : _analytics.ACTION_SUBJECT_ID.DECISION,
44
+ eventType: _analytics.EVENT_TYPE.TRACK,
45
+ attributes: {
46
+ inputMethod: inputMethod,
47
+ containerAri: containerId,
48
+ objectAri: objectId,
49
+ userContext: userContext,
50
+ localId: itemLocalId,
51
+ listLocalId: listLocalId,
52
+ position: itemIdx,
53
+ listSize: listSize
54
+ }
55
+ };
56
+ };
57
+ var getListTypes = exports.getListTypes = function getListTypes(listType, schema) {
58
+ var _schema$nodes = schema.nodes,
59
+ decisionList = _schema$nodes.decisionList,
60
+ decisionItem = _schema$nodes.decisionItem,
61
+ taskList = _schema$nodes.taskList,
62
+ taskItem = _schema$nodes.taskItem;
63
+ if (listType === 'taskList') {
64
+ return {
65
+ list: taskList,
66
+ item: taskItem
67
+ };
68
+ }
69
+ return {
70
+ list: decisionList,
71
+ item: decisionItem
72
+ };
73
+ };
74
+ var insertTaskDecisionAction = exports.insertTaskDecisionAction = function insertTaskDecisionAction(editorAnalyticsAPI) {
75
+ return function (state, listType) {
76
+ var inputMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _analytics.INPUT_METHOD.TOOLBAR;
77
+ var addItem = arguments.length > 3 ? arguments[3] : undefined;
78
+ var listLocalId = arguments.length > 4 ? arguments[4] : undefined;
79
+ var itemLocalId = arguments.length > 5 ? arguments[5] : undefined;
80
+ var itemAttrs = arguments.length > 6 ? arguments[6] : undefined;
81
+ var schema = state.schema;
82
+ var addAndCreateList = function addAndCreateList(_ref) {
83
+ var tr = _ref.tr,
84
+ list = _ref.list,
85
+ item = _ref.item,
86
+ listLocalId = _ref.listLocalId,
87
+ itemLocalId = _ref.itemLocalId;
88
+ return createListAtSelection(tr, list, item, schema, state, listLocalId, itemLocalId, itemAttrs);
89
+ };
90
+ var addToList = function addToList(_ref2) {
91
+ var state = _ref2.state,
92
+ tr = _ref2.tr,
93
+ item = _ref2.item,
94
+ itemLocalId = _ref2.itemLocalId;
95
+ var $to = state.selection.$to;
96
+ var endPos = $to.end($to.depth);
97
+ var newItemParagraphPos = endPos + 2;
98
+ return tr.split(endPos, 1, [{
99
+ type: item,
100
+ attrs: {
101
+ localId: itemLocalId
102
+ }
103
+ }]).setSelection(new _state.TextSelection(tr.doc.resolve(newItemParagraphPos)));
104
+ };
105
+ var addAndCreateListFn = addItem !== null && addItem !== void 0 ? addItem : addAndCreateList;
106
+ var tr = insertTaskDecisionWithAnalytics(editorAnalyticsAPI)(state, listType, inputMethod, addAndCreateListFn, addToList, listLocalId, itemLocalId, itemAttrs);
107
+ if (!tr) {
108
+ return state.tr;
109
+ }
110
+ (0, _utils.autoJoinTr)(tr, ['taskList', 'decisionList']);
111
+ return tr;
112
+ };
113
+ };
114
+ var insertTaskDecisionCommand = exports.insertTaskDecisionCommand = function insertTaskDecisionCommand(editorAnalyticsAPI) {
115
+ return function (listType) {
116
+ var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _analytics.INPUT_METHOD.TOOLBAR;
117
+ var addItem = arguments.length > 2 ? arguments[2] : undefined;
118
+ var listLocalId = arguments.length > 3 ? arguments[3] : undefined;
119
+ var itemLocalId = arguments.length > 4 ? arguments[4] : undefined;
120
+ return function (state, dispatch) {
121
+ var tr = insertTaskDecisionAction(editorAnalyticsAPI)(state, listType, inputMethod, addItem, listLocalId, itemLocalId);
122
+ if (dispatch) {
123
+ dispatch(tr);
124
+ }
125
+ return true;
126
+ };
127
+ };
128
+ };
129
+ var insertTaskDecisionWithAnalytics = exports.insertTaskDecisionWithAnalytics = function insertTaskDecisionWithAnalytics(editorAnalyticsAPI) {
130
+ return function (state, listType, inputMethod, addAndCreateList, addToList, listLocalId, itemLocalId, itemAttrs) {
131
+ var schema = state.schema;
132
+ var _getListTypes = getListTypes(listType, schema),
133
+ list = _getListTypes.list,
134
+ item = _getListTypes.item;
135
+ var tr = state.tr;
136
+ var $to = state.selection.$to;
137
+ var listNode = (0, _utils2.findParentNodeOfType)(list)(state.selection);
138
+ var contextIdentifierProvider = _pluginKey.stateKey.getState(state).contextIdentifierProvider;
139
+ var contextData = getContextData(contextIdentifierProvider);
140
+ var insertTrCreator;
141
+ var itemIdx;
142
+ var listSize;
143
+ if (!listNode) {
144
+ // Not a list - convert to one.
145
+ itemIdx = 0;
146
+ listSize = 1;
147
+ insertTrCreator = addAndCreateList;
148
+ } else if ($to.node().textContent.length >= 0) {
149
+ listSize = listNode.node.childCount + 1;
150
+ listLocalId = listLocalId || listNode.node.attrs.localId;
151
+ var listItemNode = (0, _utils2.findParentNodeOfType)(item)(state.selection); // finds current item in list
152
+ itemIdx = listItemNode ? state.doc.resolve(listItemNode.pos).index() + 1 : 0;
153
+ insertTrCreator = addToList ? addToList : addAndCreateList;
154
+ }
155
+ listLocalId = listLocalId || _adfSchema.uuid.generate();
156
+ itemLocalId = itemLocalId || _adfSchema.uuid.generate();
157
+ if (insertTrCreator) {
158
+ var insertTr = insertTrCreator({
159
+ state: state,
160
+ tr: tr,
161
+ list: list,
162
+ item: item,
163
+ listLocalId: listLocalId,
164
+ itemLocalId: itemLocalId,
165
+ itemAttrs: itemAttrs
166
+ });
167
+ if (insertTr) {
168
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(generateAnalyticsPayload(listType, contextData, inputMethod, itemLocalId, listLocalId, itemIdx || 0, listSize || 0))(insertTr);
169
+ }
170
+ return insertTr;
171
+ }
172
+ return null;
173
+ };
174
+ };
175
+ var isSupportedSourceNode = exports.isSupportedSourceNode = function isSupportedSourceNode(schema, selection) {
176
+ var _schema$nodes2 = schema.nodes,
177
+ paragraph = _schema$nodes2.paragraph,
178
+ blockquote = _schema$nodes2.blockquote,
179
+ decisionList = _schema$nodes2.decisionList,
180
+ taskList = _schema$nodes2.taskList;
181
+ return (0, _utils2.hasParentNodeOfType)([blockquote, paragraph, decisionList, taskList])(selection);
182
+ };
183
+ var changeInDepth = exports.changeInDepth = function changeInDepth(before, after) {
184
+ return after.depth - before.depth;
185
+ };
186
+ var createListAtSelection = exports.createListAtSelection = function createListAtSelection(tr, list, item, schema, state) {
187
+ var listLocalId = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _adfSchema.uuid.generate();
188
+ var itemLocalId = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : _adfSchema.uuid.generate();
189
+ var itemAttrs = arguments.length > 7 ? arguments[7] : undefined;
190
+ var selection = state.selection;
191
+ var $from = selection.$from,
192
+ $to = selection.$to;
193
+ if ($from.parent !== $to.parent) {
194
+ // ignore selections across multiple nodes
195
+ return null;
196
+ }
197
+ var _schema$nodes3 = schema.nodes,
198
+ paragraph = _schema$nodes3.paragraph,
199
+ blockquote = _schema$nodes3.blockquote,
200
+ decisionList = _schema$nodes3.decisionList,
201
+ taskList = _schema$nodes3.taskList,
202
+ decisionItem = _schema$nodes3.decisionItem,
203
+ taskItem = _schema$nodes3.taskItem,
204
+ mediaGroup = _schema$nodes3.mediaGroup;
205
+ if ($from.parent.type === mediaGroup) {
206
+ return null;
207
+ }
208
+ var emptyList = list.create({
209
+ localId: listLocalId
210
+ }, [item.create(_objectSpread({
211
+ localId: itemLocalId
212
+ }, itemAttrs))]);
213
+
214
+ // we don't take the content of a block node next to the gap cursor and always create an empty task
215
+ if (selection instanceof _selection.GapCursorSelection) {
216
+ return (0, _utils2.safeInsert)(emptyList)(tr);
217
+ }
218
+
219
+ // try to replace when selection is in nodes which support it
220
+ if (isSupportedSourceNode(schema, selection)) {
221
+ var _selection$$from$node = selection.$from.node(),
222
+ nodeType = _selection$$from$node.type,
223
+ childCount = _selection$$from$node.childCount;
224
+ var newListNode = list.create({
225
+ localId: _adfSchema.uuid.generate()
226
+ }, [item.create({
227
+ localId: _adfSchema.uuid.generate()
228
+ }, $from.node($from.depth).content)]);
229
+ var hasBlockquoteParent = (0, _utils2.findParentNodeOfType)(blockquote)(selection);
230
+ if (hasBlockquoteParent) {
231
+ var liftedDepth = $from.depth - 1;
232
+ var range = new _model.NodeRange($from, $to, liftedDepth);
233
+ tr.lift(range, (0, _transform.liftTarget)(range));
234
+ }
235
+ var listParent = (0, _utils2.findParentNodeOfType)(taskList)(selection) || (0, _utils2.findParentNodeOfType)(decisionList)(selection);
236
+ var listItem = (0, _utils2.findParentNodeOfType)(taskItem)(selection) || (0, _utils2.findParentNodeOfType)(decisionItem)(selection);
237
+
238
+ // For a selection inside a task/decision list, we can't just simply replace the
239
+ // node type as it will mess up lists with > 1 item
240
+ if (listParent && listItem) {
241
+ var start;
242
+ var end;
243
+ var selectionPos = selection.from;
244
+
245
+ // if selection is in first item in list, we need to delete extra so that
246
+ // this list isn't split
247
+ if (listParent.node.firstChild === listItem.node) {
248
+ start = listParent.start - 1;
249
+ end = listItem.start + listItem.node.nodeSize;
250
+ if (listParent.node.childCount === 1) {
251
+ end = listParent.start + listParent.node.nodeSize - 1;
252
+ }
253
+ } else {
254
+ start = listItem.start - 1;
255
+ end = listItem.start + listItem.node.nodeSize;
256
+ selectionPos += 2; // as we have added the new list node
257
+ }
258
+
259
+ tr.replaceWith(start, end, newListNode);
260
+ tr = (0, _utils2.setTextSelection)(selectionPos)(tr);
261
+ return tr;
262
+ }
263
+
264
+ // For a selection inside one of these node types we can just convert the node type
265
+ var nodeTypesToReplace = [blockquote];
266
+ if (nodeType === paragraph && childCount > 0 || hasBlockquoteParent) {
267
+ // Only convert paragraphs containing content.
268
+ // Empty paragraphs use the default flow.
269
+ // This distinction ensures the text selection remains in the correct location.
270
+
271
+ // We also want to replace the paragraph type when we are inside a blockQuote
272
+ // to avoid inserting an extra taskList whilst keeping the paragraph
273
+ nodeTypesToReplace.push(paragraph);
274
+ }
275
+ var newTr = tr;
276
+ newTr = (0, _utils2.replaceParentNodeOfType)(nodeTypesToReplace, newListNode)(tr);
277
+
278
+ // Adjust depth for new selection, if it has changed (e.g. paragraph to list (ol > li))
279
+ var depthAdjustment = changeInDepth($to, newTr.selection.$to);
280
+ tr = tr.setSelection(new _state.TextSelection(tr.doc.resolve($to.pos + depthAdjustment)));
281
+
282
+ // replacing successful
283
+ if (newTr !== tr) {
284
+ return tr;
285
+ }
286
+ }
287
+ return (0, _utils2.safeInsert)(emptyList)(tr);
288
+ };
package/dist/cjs/index.js CHANGED
@@ -2,4 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ Object.defineProperty(exports, "tasksAndDecisionsPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.tasksAndDecisionsPlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.decisionItemNodeView = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
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 _react = _interopRequireDefault(require("react"));
15
+ var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
16
+ var _Decision = _interopRequireDefault(require("../ui/Decision"));
17
+ var _useShowPlaceholder = require("./hooks/use-show-placeholder");
18
+ 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); }; }
19
+ 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; } }
20
+ var DecisionItemWrapper = function DecisionItemWrapper(_ref) {
21
+ var api = _ref.api,
22
+ editorView = _ref.editorView,
23
+ forwardRef = _ref.forwardRef,
24
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
25
+ getPos = _ref.getPos;
26
+ var showPlaceholder = (0, _useShowPlaceholder.useShowPlaceholder)({
27
+ editorView: editorView,
28
+ isContentNodeEmpty: isContentNodeEmpty,
29
+ getPos: getPos,
30
+ api: api
31
+ });
32
+ return /*#__PURE__*/_react.default.createElement(_Decision.default, {
33
+ contentRef: forwardRef,
34
+ showPlaceholder: showPlaceholder
35
+ });
36
+ };
37
+ var Decision = /*#__PURE__*/function (_ReactNodeView) {
38
+ (0, _inherits2.default)(Decision, _ReactNodeView);
39
+ var _super = _createSuper(Decision);
40
+ function Decision() {
41
+ (0, _classCallCheck2.default)(this, Decision);
42
+ return _super.apply(this, arguments);
43
+ }
44
+ (0, _createClass2.default)(Decision, [{
45
+ key: "isContentEmpty",
46
+ value: function isContentEmpty(node) {
47
+ return node.content.childCount === 0;
48
+ }
49
+ }, {
50
+ key: "initWithAPI",
51
+ value: function initWithAPI(api) {
52
+ this.api = api;
53
+ this.init();
54
+ return this;
55
+ }
56
+ }, {
57
+ key: "createDomRef",
58
+ value: function createDomRef() {
59
+ var domRef = document.createElement('li');
60
+ domRef.style.listStyleType = 'none';
61
+ return domRef;
62
+ }
63
+ }, {
64
+ key: "getContentDOM",
65
+ value: function getContentDOM() {
66
+ var dom = document.createElement('div');
67
+ // setting a className prevents PM/Chrome mutation observer from
68
+ // incorrectly deleting nodes
69
+ dom.className = 'decision-item';
70
+ return {
71
+ dom: dom
72
+ };
73
+ }
74
+ }, {
75
+ key: "render",
76
+ value: function render(_props, forwardRef) {
77
+ var isContentNodeEmpty = this.isContentEmpty(this.node);
78
+ return /*#__PURE__*/_react.default.createElement(DecisionItemWrapper, {
79
+ forwardRef: forwardRef,
80
+ isContentNodeEmpty: isContentNodeEmpty,
81
+ api: this.api
82
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
83
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
84
+ ,
85
+ getPos: this.getPos,
86
+ editorView: this.view
87
+ });
88
+ }
89
+ }, {
90
+ key: "viewShouldUpdate",
91
+ value: function viewShouldUpdate(nextNode) {
92
+ /**
93
+ * To ensure the placeholder is correctly toggled we need to allow react to re-render
94
+ * on first character insertion.
95
+ * Note: last character deletion is handled externally and automatically re-renders.
96
+ */
97
+ return this.isContentEmpty(this.node) && !!nextNode.content.childCount;
98
+ }
99
+ }, {
100
+ key: "update",
101
+ value: function update(node, decorations) {
102
+ var _this = this;
103
+ return (0, _get2.default)((0, _getPrototypeOf2.default)(Decision.prototype), "update", this).call(this, node, decorations, undefined,
104
+ // Toggle the placeholder based on whether user input exists.
105
+ function (_currentNode, _newNode) {
106
+ return !_this.isContentEmpty(_newNode);
107
+ });
108
+ }
109
+ }]);
110
+ return Decision;
111
+ }(_reactNodeView.default);
112
+ var decisionItemNodeView = exports.decisionItemNodeView = function decisionItemNodeView(portalProviderAPI, eventDispatcher, api) {
113
+ return function (node, view, getPos) {
114
+ var hasIntlContext = true;
115
+ return new Decision(node, view, getPos, portalProviderAPI, eventDispatcher, {}, undefined, undefined, undefined, hasIntlContext).initWithAPI(api);
116
+ };
117
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useShowPlaceholder = void 0;
7
+ var _react = require("react");
8
+ var _hooks = require("@atlaskit/editor-common/hooks");
9
+ var _state = require("@atlaskit/editor-prosemirror/state");
10
+ var useShowPlaceholder = exports.useShowPlaceholder = function useShowPlaceholder(_ref) {
11
+ var editorView = _ref.editorView,
12
+ api = _ref.api,
13
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
14
+ getPos = _ref.getPos;
15
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['typeAhead']),
16
+ typeAheadState = _useSharedPluginState.typeAheadState;
17
+ var isTypeAheadOpen = Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen);
18
+ var isTypeAheadOpenedInsideItem = (0, _react.useMemo)(function () {
19
+ var _selection$$cursor;
20
+ if (!isTypeAheadOpen) {
21
+ return false;
22
+ }
23
+ var itemPosition = getPos();
24
+ if (typeof itemPosition !== 'number') {
25
+ return false;
26
+ }
27
+ var selection = editorView.state.selection;
28
+ if (!(selection instanceof _state.TextSelection)) {
29
+ return false;
30
+ }
31
+ var maybeItemNode = editorView.state.doc.nodeAt(itemPosition);
32
+ var maybeParentItemNode = (_selection$$cursor = selection.$cursor) === null || _selection$$cursor === void 0 ? void 0 : _selection$$cursor.node();
33
+ if (maybeItemNode && maybeParentItemNode && maybeItemNode.eq(maybeParentItemNode)) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }, [isTypeAheadOpen, getPos, editorView]);
38
+ var showPlaceholder = Boolean(!isTypeAheadOpenedInsideItem && isContentNodeEmpty);
39
+ return showPlaceholder;
40
+ };