@atlaskit/editor-core 185.12.0 → 185.12.2
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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/plugins/block-type/commands/block-type.js +79 -44
- package/dist/cjs/plugins/card/ui/EditLinkToolbar.js +4 -3
- package/dist/cjs/plugins/card/ui/EditorSmartCardEventsNext.js +15 -36
- package/dist/cjs/plugins/code-block/index.js +7 -3
- package/dist/cjs/plugins/expand/commands.js +6 -2
- package/dist/cjs/plugins/expand/index.js +5 -1
- package/dist/cjs/plugins/hyperlink/Toolbar.js +1 -0
- package/dist/cjs/plugins/panel/index.js +81 -43
- package/dist/cjs/plugins/quick-insert/commands.js +2 -0
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/block-type/commands/block-type.js +86 -51
- package/dist/es2019/plugins/card/ui/EditLinkToolbar.js +4 -3
- package/dist/es2019/plugins/card/ui/EditorSmartCardEventsNext.js +21 -35
- package/dist/es2019/plugins/code-block/index.js +7 -2
- package/dist/es2019/plugins/expand/commands.js +6 -2
- package/dist/es2019/plugins/expand/index.js +5 -1
- package/dist/es2019/plugins/hyperlink/Toolbar.js +1 -0
- package/dist/es2019/plugins/panel/index.js +82 -41
- package/dist/es2019/plugins/quick-insert/commands.js +2 -0
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/block-type/commands/block-type.js +76 -43
- package/dist/esm/plugins/card/ui/EditLinkToolbar.js +4 -3
- package/dist/esm/plugins/card/ui/EditorSmartCardEventsNext.js +15 -36
- package/dist/esm/plugins/code-block/index.js +7 -2
- package/dist/esm/plugins/expand/commands.js +6 -2
- package/dist/esm/plugins/expand/index.js +5 -1
- package/dist/esm/plugins/hyperlink/Toolbar.js +1 -0
- package/dist/esm/plugins/panel/index.js +81 -43
- package/dist/esm/plugins/quick-insert/commands.js +2 -0
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/block-type/commands/block-type.d.ts +25 -0
- package/dist/types/plugins/card/types.d.ts +2 -3
- package/dist/types/plugins/card/ui/EditLinkToolbar.d.ts +2 -2
- package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +25 -0
- package/dist/types-ts4.5/plugins/card/types.d.ts +2 -3
- package/dist/types-ts4.5/plugins/card/ui/EditLinkToolbar.d.ts +2 -2
- package/package.json +2 -2
|
@@ -210,6 +210,40 @@ export var insertBlockTypesWithAnalytics = function insertBlockTypesWithAnalytic
|
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* This function creates a new transaction that wraps the current selection
|
|
215
|
+
* in the specified node type if it results in a valid transaction.
|
|
216
|
+
* If not valid, it performs a safe insert operation.
|
|
217
|
+
*
|
|
218
|
+
* Example of when wrapping might not be valid is when attempting to wrap
|
|
219
|
+
* content that is already inside a panel with another panel
|
|
220
|
+
*/
|
|
221
|
+
export function createWrapSelectionTransaction(_ref3) {
|
|
222
|
+
var state = _ref3.state,
|
|
223
|
+
type = _ref3.type,
|
|
224
|
+
nodeAttributes = _ref3.nodeAttributes;
|
|
225
|
+
var tr = state.tr;
|
|
226
|
+
var _state$selection = state.selection,
|
|
227
|
+
$from = _state$selection.$from,
|
|
228
|
+
$to = _state$selection.$to;
|
|
229
|
+
var _state$schema$marks = state.schema.marks,
|
|
230
|
+
alignment = _state$schema$marks.alignment,
|
|
231
|
+
indentation = _state$schema$marks.indentation;
|
|
232
|
+
|
|
233
|
+
/** Alignment or Indentation is not valid inside block types */
|
|
234
|
+
var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
|
|
235
|
+
tr = removeAlignTr || tr;
|
|
236
|
+
var range = $from.blockRange($to);
|
|
237
|
+
var wrapping = range && findWrapping(range, type, nodeAttributes);
|
|
238
|
+
if (range && wrapping) {
|
|
239
|
+
tr.wrap(range, wrapping).scrollIntoView();
|
|
240
|
+
} else {
|
|
241
|
+
/** We always want to append a block type */
|
|
242
|
+
safeInsert(type.createAndFill())(tr).scrollIntoView();
|
|
243
|
+
}
|
|
244
|
+
return tr;
|
|
245
|
+
}
|
|
246
|
+
|
|
213
247
|
/**
|
|
214
248
|
* Function will add wrapping node.
|
|
215
249
|
* 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
|
|
@@ -218,25 +252,10 @@ export var insertBlockTypesWithAnalytics = function insertBlockTypesWithAnalytic
|
|
|
218
252
|
*/
|
|
219
253
|
function wrapSelectionIn(type) {
|
|
220
254
|
return function (state, dispatch) {
|
|
221
|
-
var tr =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var _state$schema$marks = state.schema.marks,
|
|
226
|
-
alignment = _state$schema$marks.alignment,
|
|
227
|
-
indentation = _state$schema$marks.indentation;
|
|
228
|
-
|
|
229
|
-
/** Alignment or Indentation is not valid inside block types */
|
|
230
|
-
var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
|
|
231
|
-
tr = removeAlignTr || tr;
|
|
232
|
-
var range = $from.blockRange($to);
|
|
233
|
-
var wrapping = range && findWrapping(range, type);
|
|
234
|
-
if (range && wrapping) {
|
|
235
|
-
tr.wrap(range, wrapping).scrollIntoView();
|
|
236
|
-
} else {
|
|
237
|
-
/** We always want to append a block type */
|
|
238
|
-
safeInsert(type.createAndFill())(tr).scrollIntoView();
|
|
239
|
-
}
|
|
255
|
+
var tr = createWrapSelectionTransaction({
|
|
256
|
+
state: state,
|
|
257
|
+
type: type
|
|
258
|
+
});
|
|
240
259
|
if (dispatch) {
|
|
241
260
|
dispatch(tr);
|
|
242
261
|
}
|
|
@@ -244,39 +263,53 @@ function wrapSelectionIn(type) {
|
|
|
244
263
|
};
|
|
245
264
|
}
|
|
246
265
|
|
|
266
|
+
/**
|
|
267
|
+
* This function creates a new transaction that inserts a code block,
|
|
268
|
+
* if there is text selected it will wrap the current selection if not it will
|
|
269
|
+
* append the codeblock to the end of the document.
|
|
270
|
+
*/
|
|
271
|
+
export function createInsertCodeBlockTransaction(_ref4) {
|
|
272
|
+
var _state$selection$$fro;
|
|
273
|
+
var state = _ref4.state;
|
|
274
|
+
var tr = state.tr;
|
|
275
|
+
var from = state.selection.from;
|
|
276
|
+
var codeBlock = state.schema.nodes.codeBlock;
|
|
277
|
+
var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
|
|
278
|
+
var parentNodeType = state.selection.$from.parent.type;
|
|
279
|
+
|
|
280
|
+
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
281
|
+
* AND it's a valid child of the grandparent node.
|
|
282
|
+
* Insert the current selection as codeBlock content unless it contains nodes other
|
|
283
|
+
* than paragraphs and inline.
|
|
284
|
+
*/
|
|
285
|
+
var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
|
|
286
|
+
parentNodeType: parentNodeType,
|
|
287
|
+
grandParentNodeType: grandParentNodeType,
|
|
288
|
+
content: codeBlock.createAndFill()
|
|
289
|
+
}) && contentAllowedInCodeBlock(state);
|
|
290
|
+
if (canInsertCodeBlock) {
|
|
291
|
+
tr = transformToCodeBlockAction(state, from);
|
|
292
|
+
} else {
|
|
293
|
+
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
294
|
+
}
|
|
295
|
+
return tr;
|
|
296
|
+
}
|
|
297
|
+
|
|
247
298
|
/**
|
|
248
299
|
* Function will insert code block at current selection if block is empty or below current selection and set focus on it.
|
|
249
300
|
*/
|
|
250
301
|
function insertCodeBlock() {
|
|
251
302
|
return function (state, dispatch) {
|
|
252
|
-
var
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
var codeBlock = state.schema.nodes.codeBlock;
|
|
256
|
-
var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
|
|
257
|
-
var parentNodeType = state.selection.$from.parent.type;
|
|
258
|
-
|
|
259
|
-
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
260
|
-
* AND it's a valid child of the grandparent node.
|
|
261
|
-
* Insert the current selection as codeBlock content unless it contains nodes other
|
|
262
|
-
* than paragraphs and inline.
|
|
263
|
-
*/
|
|
264
|
-
var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
|
|
265
|
-
parentNodeType: parentNodeType,
|
|
266
|
-
grandParentNodeType: grandParentNodeType,
|
|
267
|
-
content: codeBlock.createAndFill()
|
|
268
|
-
}) && contentAllowedInCodeBlock(state);
|
|
269
|
-
if (canInsertCodeBlock) {
|
|
270
|
-
tr = transformToCodeBlockAction(state, from);
|
|
271
|
-
} else {
|
|
272
|
-
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
273
|
-
}
|
|
303
|
+
var tr = createInsertCodeBlockTransaction({
|
|
304
|
+
state: state
|
|
305
|
+
});
|
|
274
306
|
if (dispatch) {
|
|
275
307
|
dispatch(tr);
|
|
276
308
|
}
|
|
277
309
|
return true;
|
|
278
310
|
};
|
|
279
311
|
}
|
|
312
|
+
|
|
280
313
|
/**
|
|
281
314
|
* Check if the current selection contains any nodes that are not permitted
|
|
282
315
|
* as codeBlock child nodes. Note that this allows paragraphs and inline nodes
|
|
@@ -296,8 +329,8 @@ function contentAllowedInCodeBlock(state) {
|
|
|
296
329
|
return isAllowedChild;
|
|
297
330
|
}
|
|
298
331
|
export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
|
|
299
|
-
var
|
|
300
|
-
$cursor =
|
|
332
|
+
var _ref5 = state.selection,
|
|
333
|
+
$cursor = _ref5.$cursor;
|
|
301
334
|
if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
|
|
302
335
|
var tr = state.tr,
|
|
303
336
|
schema = state.schema;
|
|
@@ -81,10 +81,10 @@ export var EditLinkToolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
81
81
|
,
|
|
82
82
|
invokeMethod: INPUT_METHOD.FLOATING_TB,
|
|
83
83
|
featureFlags: featureFlags,
|
|
84
|
-
onSubmit: function onSubmit(href, title, displayText,
|
|
84
|
+
onSubmit: function onSubmit(href, title, displayText, inputMethod, analytic) {
|
|
85
85
|
_this2.hideLinkToolbar();
|
|
86
86
|
if (_onSubmit) {
|
|
87
|
-
_onSubmit(href, displayText || title, analytic);
|
|
87
|
+
_onSubmit(href, displayText || title, inputMethod, analytic);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
});
|
|
@@ -134,7 +134,7 @@ export var buildEditLinkToolbar = function buildEditLinkToolbar(_ref) {
|
|
|
134
134
|
node: node,
|
|
135
135
|
featureFlags: featureFlags,
|
|
136
136
|
forceFocusSelector: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.floatingToolbar.actions) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.forceFocusSelector,
|
|
137
|
-
onSubmit: function onSubmit(newHref, newText, analytic) {
|
|
137
|
+
onSubmit: function onSubmit(newHref, newText, inputMethod, analytic) {
|
|
138
138
|
var urlChanged = newHref !== displayInfo.url;
|
|
139
139
|
var titleChanged = newText !== displayInfo.title;
|
|
140
140
|
|
|
@@ -144,6 +144,7 @@ export var buildEditLinkToolbar = function buildEditLinkToolbar(_ref) {
|
|
|
144
144
|
var _pluginInjectionApi$d2;
|
|
145
145
|
return commandWithMetadata(changeSelectedCardToLink(newText, newHref, undefined, undefined, undefined, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions), {
|
|
146
146
|
action: ACTION.UPDATED,
|
|
147
|
+
inputMethod: inputMethod,
|
|
147
148
|
sourceEvent: analytic
|
|
148
149
|
})(view.state, view.dispatch);
|
|
149
150
|
}
|
|
@@ -4,10 +4,6 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
4
4
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
5
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
6
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
8
|
-
var _excluded = ["url", "display", "nodeContext"],
|
|
9
|
-
_excluded2 = ["url", "display", "previousDisplay", "nodeContext"],
|
|
10
|
-
_excluded3 = ["url", "display", "nodeContext"];
|
|
11
7
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
8
|
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; } }
|
|
13
9
|
import React from 'react';
|
|
@@ -38,14 +34,7 @@ var withHistoryMethod = function withHistoryMethod(fn) {
|
|
|
38
34
|
};
|
|
39
35
|
};
|
|
40
36
|
var getMethod = withHistoryMethod(function (_ref) {
|
|
41
|
-
var inputMethod = _ref.inputMethod
|
|
42
|
-
sourceEvent = _ref.sourceEvent;
|
|
43
|
-
/**
|
|
44
|
-
* If sourceEvent is present, don't provide a custom method
|
|
45
|
-
*/
|
|
46
|
-
if (sourceEvent) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
37
|
+
var inputMethod = _ref.inputMethod;
|
|
49
38
|
switch (inputMethod) {
|
|
50
39
|
case INPUT_METHOD.CLIPBOARD:
|
|
51
40
|
return 'editor_paste';
|
|
@@ -59,14 +48,7 @@ var getMethod = withHistoryMethod(function (_ref) {
|
|
|
59
48
|
}
|
|
60
49
|
});
|
|
61
50
|
var getUpdateType = withHistoryMethod(function (_ref2) {
|
|
62
|
-
var action = _ref2.action
|
|
63
|
-
sourceEvent = _ref2.sourceEvent;
|
|
64
|
-
/**
|
|
65
|
-
* If sourceEvent is present, don't provide a custom method
|
|
66
|
-
*/
|
|
67
|
-
if (sourceEvent) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
51
|
+
var action = _ref2.action;
|
|
70
52
|
switch (action) {
|
|
71
53
|
case ACTION.CHANGED_TYPE:
|
|
72
54
|
return 'display_update';
|
|
@@ -115,11 +97,10 @@ export var EventsBinding = function EventsBinding(_ref4) {
|
|
|
115
97
|
linkDeleted = _useSmartLinkLifecycl.linkDeleted;
|
|
116
98
|
var events = useMemo(function () {
|
|
117
99
|
return {
|
|
118
|
-
created: function created(
|
|
119
|
-
var url =
|
|
120
|
-
display =
|
|
121
|
-
nodeContext =
|
|
122
|
-
metadata = _objectWithoutProperties(_ref5, _excluded);
|
|
100
|
+
created: function created(metadata) {
|
|
101
|
+
var url = metadata.url,
|
|
102
|
+
display = metadata.display,
|
|
103
|
+
nodeContext = metadata.nodeContext;
|
|
123
104
|
var displayCategory = displayCategoryFromDisplay(display);
|
|
124
105
|
var sourceEvent = getSourceEventFromMetadata(metadata);
|
|
125
106
|
var creationMethod = getMethod(metadata);
|
|
@@ -132,12 +113,11 @@ export var EventsBinding = function EventsBinding(_ref4) {
|
|
|
132
113
|
creationMethod: creationMethod
|
|
133
114
|
});
|
|
134
115
|
},
|
|
135
|
-
updated: function updated(
|
|
136
|
-
var url =
|
|
137
|
-
display =
|
|
138
|
-
previousDisplay =
|
|
139
|
-
nodeContext =
|
|
140
|
-
metadata = _objectWithoutProperties(_ref6, _excluded2);
|
|
116
|
+
updated: function updated(metadata) {
|
|
117
|
+
var url = metadata.url,
|
|
118
|
+
display = metadata.display,
|
|
119
|
+
previousDisplay = metadata.previousDisplay,
|
|
120
|
+
nodeContext = metadata.nodeContext;
|
|
141
121
|
var displayCategory = displayCategoryFromDisplay(display);
|
|
142
122
|
var sourceEvent = getSourceEventFromMetadata(metadata);
|
|
143
123
|
var updateMethod = getMethod(metadata);
|
|
@@ -153,11 +133,10 @@ export var EventsBinding = function EventsBinding(_ref4) {
|
|
|
153
133
|
updateType: updateType
|
|
154
134
|
});
|
|
155
135
|
},
|
|
156
|
-
deleted: function deleted(
|
|
157
|
-
var url =
|
|
158
|
-
display =
|
|
159
|
-
nodeContext =
|
|
160
|
-
metadata = _objectWithoutProperties(_ref7, _excluded3);
|
|
136
|
+
deleted: function deleted(metadata) {
|
|
137
|
+
var url = metadata.url,
|
|
138
|
+
display = metadata.display,
|
|
139
|
+
nodeContext = metadata.nodeContext;
|
|
161
140
|
var displayCategory = displayCategoryFromDisplay(display);
|
|
162
141
|
var sourceEvent = getSourceEventFromMetadata(metadata);
|
|
163
142
|
var deleteMethod = getMethod(metadata);
|
|
@@ -12,6 +12,10 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } f
|
|
|
12
12
|
import { IconCode } from '../quick-insert/assets';
|
|
13
13
|
import { messages } from '../block-type/messages';
|
|
14
14
|
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
15
|
+
// Theres an existing interelationship between these files, where the imported function is being called for code-block
|
|
16
|
+
// Insertions via the drop down menu
|
|
17
|
+
// tslint-ignore-next-line
|
|
18
|
+
import { createInsertCodeBlockTransaction } from '../block-type/commands/block-type';
|
|
15
19
|
var codeBlockPlugin = function codeBlockPlugin(options, api) {
|
|
16
20
|
return {
|
|
17
21
|
name: 'codeBlock',
|
|
@@ -69,8 +73,9 @@ var codeBlockPlugin = function codeBlockPlugin(options, api) {
|
|
|
69
73
|
},
|
|
70
74
|
action: function action(insert, state) {
|
|
71
75
|
var _api$dependencies$ana;
|
|
72
|
-
var
|
|
73
|
-
|
|
76
|
+
var tr = createInsertCodeBlockTransaction({
|
|
77
|
+
state: state
|
|
78
|
+
});
|
|
74
79
|
api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions.attachAnalyticsEvent({
|
|
75
80
|
action: ACTION.INSERTED,
|
|
76
81
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -2,12 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
import { TextSelection } from 'prosemirror-state';
|
|
5
|
-
import { safeInsert } from 'prosemirror-utils';
|
|
6
5
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
7
6
|
import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE, PLATFORMS, MODE } from '../analytics';
|
|
8
7
|
import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
|
|
9
8
|
import { findExpand } from './utils';
|
|
10
9
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
10
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
11
11
|
export var setExpandRef = function setExpandRef(ref) {
|
|
12
12
|
return createCommand({
|
|
13
13
|
type: 'SET_EXPAND_REF',
|
|
@@ -105,6 +105,10 @@ export var createExpandNode = function createExpandNode(state) {
|
|
|
105
105
|
};
|
|
106
106
|
export var insertExpand = function insertExpand(state, dispatch) {
|
|
107
107
|
var expandNode = createExpandNode(state);
|
|
108
|
+
var tr = createWrapSelectionTransaction({
|
|
109
|
+
state: state,
|
|
110
|
+
type: state.schema.nodes.expand
|
|
111
|
+
});
|
|
108
112
|
var payload = {
|
|
109
113
|
action: ACTION.INSERTED,
|
|
110
114
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -115,7 +119,7 @@ export var insertExpand = function insertExpand(state, dispatch) {
|
|
|
115
119
|
eventType: EVENT_TYPE.TRACK
|
|
116
120
|
};
|
|
117
121
|
if (dispatch && expandNode) {
|
|
118
|
-
dispatch(addAnalytics(state,
|
|
122
|
+
dispatch(addAnalytics(state, tr, payload));
|
|
119
123
|
}
|
|
120
124
|
return true;
|
|
121
125
|
};
|
|
@@ -8,6 +8,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, IN
|
|
|
8
8
|
import { getToolbarConfig } from './toolbar';
|
|
9
9
|
import { createExpandNode } from './commands';
|
|
10
10
|
import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
|
|
11
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
11
12
|
var expandPlugin = function expandPlugin() {
|
|
12
13
|
var _api$dependencies, _api$dependencies$fea;
|
|
13
14
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -58,7 +59,10 @@ var expandPlugin = function expandPlugin() {
|
|
|
58
59
|
if (!node) {
|
|
59
60
|
return false;
|
|
60
61
|
}
|
|
61
|
-
var tr =
|
|
62
|
+
var tr = createWrapSelectionTransaction({
|
|
63
|
+
state: state,
|
|
64
|
+
type: state.schema.nodes.expand
|
|
65
|
+
});
|
|
62
66
|
return addAnalytics(state, tr, {
|
|
63
67
|
action: ACTION.INSERTED,
|
|
64
68
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -215,6 +215,7 @@ export var getToolbarConfig = function getToolbarConfig(options, featureFlags, p
|
|
|
215
215
|
var action = isEdit ? ACTION.UPDATED : ACTION.INSERTED;
|
|
216
216
|
var command = isEdit ? commandWithMetadata(updateLink(href, displayText || title, activeLinkMark.pos), {
|
|
217
217
|
action: action,
|
|
218
|
+
inputMethod: inputMethod,
|
|
218
219
|
sourceEvent: analytic
|
|
219
220
|
}) : insertLinkWithAnalytics(inputMethod, activeLinkMark.from, activeLinkMark.to, href, title, displayText, !!(options !== null && options !== void 0 && (_options$cardOptions = options.cardOptions) !== null && _options$cardOptions !== void 0 && _options$cardOptions.provider), analytic);
|
|
220
221
|
command(view.state, view.dispatch, view);
|
|
@@ -8,25 +8,10 @@ import { IconPanel, IconPanelNote, IconPanelSuccess, IconPanelWarning, IconPanel
|
|
|
8
8
|
import { messages } from '../block-type/messages';
|
|
9
9
|
import IconCustomPanel from '../quick-insert/assets/custom-panel';
|
|
10
10
|
import { T50 } from '@atlaskit/theme/colors';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
action: ACTION.INSERTED,
|
|
16
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
17
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
18
|
-
attributes: {
|
|
19
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
20
|
-
panelType: panelAttributes.panelType
|
|
21
|
-
},
|
|
22
|
-
eventType: EVENT_TYPE.TRACK
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return tr;
|
|
26
|
-
};
|
|
27
|
-
var insertPanelType = function insertPanelType(panelAttributes, state) {
|
|
28
|
-
return state.schema.nodes.panel.createChecked(panelAttributes, state.schema.nodes.paragraph.createChecked());
|
|
29
|
-
};
|
|
11
|
+
// Theres an existing interelationship between these files, where the imported function is being called for panel
|
|
12
|
+
// Insertions via the drop down menu
|
|
13
|
+
// tslint-ignore-next-line
|
|
14
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
30
15
|
var panelPlugin = function panelPlugin() {
|
|
31
16
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
17
|
var api = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -67,9 +52,12 @@ var panelPlugin = function panelPlugin() {
|
|
|
67
52
|
return /*#__PURE__*/React.createElement(IconPanel, null);
|
|
68
53
|
},
|
|
69
54
|
action: function action(insert, state) {
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
return createPanelAction({
|
|
56
|
+
state: state,
|
|
57
|
+
attributes: {
|
|
58
|
+
panelType: PanelType.INFO
|
|
59
|
+
}
|
|
60
|
+
});
|
|
73
61
|
}
|
|
74
62
|
}, {
|
|
75
63
|
id: 'notepanel',
|
|
@@ -80,9 +68,12 @@ var panelPlugin = function panelPlugin() {
|
|
|
80
68
|
return /*#__PURE__*/React.createElement(IconPanelNote, null);
|
|
81
69
|
},
|
|
82
70
|
action: function action(insert, state) {
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
return createPanelAction({
|
|
72
|
+
state: state,
|
|
73
|
+
attributes: {
|
|
74
|
+
panelType: PanelType.NOTE
|
|
75
|
+
}
|
|
76
|
+
});
|
|
86
77
|
}
|
|
87
78
|
}, {
|
|
88
79
|
id: 'successpanel',
|
|
@@ -94,9 +85,12 @@ var panelPlugin = function panelPlugin() {
|
|
|
94
85
|
return /*#__PURE__*/React.createElement(IconPanelSuccess, null);
|
|
95
86
|
},
|
|
96
87
|
action: function action(insert, state) {
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
return createPanelAction({
|
|
89
|
+
state: state,
|
|
90
|
+
attributes: {
|
|
91
|
+
panelType: PanelType.SUCCESS
|
|
92
|
+
}
|
|
93
|
+
});
|
|
100
94
|
}
|
|
101
95
|
}, {
|
|
102
96
|
id: 'warningpanel',
|
|
@@ -107,9 +101,12 @@ var panelPlugin = function panelPlugin() {
|
|
|
107
101
|
return /*#__PURE__*/React.createElement(IconPanelWarning, null);
|
|
108
102
|
},
|
|
109
103
|
action: function action(insert, state) {
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
return createPanelAction({
|
|
105
|
+
state: state,
|
|
106
|
+
attributes: {
|
|
107
|
+
panelType: PanelType.WARNING
|
|
108
|
+
}
|
|
109
|
+
});
|
|
113
110
|
}
|
|
114
111
|
}, {
|
|
115
112
|
id: 'errorpanel',
|
|
@@ -120,9 +117,12 @@ var panelPlugin = function panelPlugin() {
|
|
|
120
117
|
return /*#__PURE__*/React.createElement(IconPanelError, null);
|
|
121
118
|
},
|
|
122
119
|
action: function action(insert, state) {
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
return createPanelAction({
|
|
121
|
+
state: state,
|
|
122
|
+
attributes: {
|
|
123
|
+
panelType: PanelType.ERROR
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
126
|
}
|
|
127
127
|
}];
|
|
128
128
|
if (options.allowCustomPanel && options.allowCustomPanelEdit) {
|
|
@@ -135,15 +135,18 @@ var panelPlugin = function panelPlugin() {
|
|
|
135
135
|
return /*#__PURE__*/React.createElement(IconCustomPanel, null);
|
|
136
136
|
},
|
|
137
137
|
action: function action(insert, state) {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
return createPanelAction({
|
|
139
|
+
state: state,
|
|
140
|
+
attributes: {
|
|
141
|
+
panelType: PanelType.CUSTOM,
|
|
142
|
+
panelIcon: ':rainbow:',
|
|
143
|
+
panelIconId: '1f308',
|
|
144
|
+
panelIconText: '🌈',
|
|
145
|
+
// TODO: https://product-fabric.atlassian.net/browse/DSP-7268
|
|
146
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
147
|
+
panelColor: T50
|
|
148
|
+
}
|
|
149
|
+
});
|
|
147
150
|
}
|
|
148
151
|
});
|
|
149
152
|
}
|
|
@@ -155,4 +158,39 @@ var panelPlugin = function panelPlugin() {
|
|
|
155
158
|
}
|
|
156
159
|
};
|
|
157
160
|
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Creates panel action and wrap selection transaction with analytics for the panel insertion.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* const tr = createPanelAction({
|
|
167
|
+
* state: editorState,
|
|
168
|
+
* attributes: { panelType: 'info' },
|
|
169
|
+
* });
|
|
170
|
+
* if (tr) {
|
|
171
|
+
* applyTransaction(tr);
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
function createPanelAction(_ref3) {
|
|
175
|
+
var state = _ref3.state,
|
|
176
|
+
attributes = _ref3.attributes;
|
|
177
|
+
var tr = createWrapSelectionTransaction({
|
|
178
|
+
state: state,
|
|
179
|
+
type: state.schema.nodes.panel,
|
|
180
|
+
nodeAttributes: attributes
|
|
181
|
+
});
|
|
182
|
+
if (tr) {
|
|
183
|
+
addAnalytics(state, tr, {
|
|
184
|
+
action: ACTION.INSERTED,
|
|
185
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
186
|
+
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
187
|
+
attributes: {
|
|
188
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
189
|
+
panelType: attributes.panelType
|
|
190
|
+
},
|
|
191
|
+
eventType: EVENT_TYPE.TRACK
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return tr;
|
|
195
|
+
}
|
|
158
196
|
export default panelPlugin;
|
|
@@ -31,6 +31,8 @@ export var insertItem = function insertItem(item) {
|
|
|
31
31
|
return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
|
|
32
32
|
};
|
|
33
33
|
var tr = item.action(insert, state);
|
|
34
|
+
|
|
35
|
+
/** @note There is no transaction when called without a search currently (different insert) */
|
|
34
36
|
if (tr && dispatch) {
|
|
35
37
|
dispatch(tr);
|
|
36
38
|
}
|
|
@@ -40,6 +40,10 @@ var InsertMenu = function InsertMenu(_ref) {
|
|
|
40
40
|
name: item.value.name
|
|
41
41
|
}) || item.elemBefore;
|
|
42
42
|
},
|
|
43
|
+
/**
|
|
44
|
+
* @note This transformed items action is only used when a quick insert item has been
|
|
45
|
+
* called from the quick insert menu and a search has not been performed.
|
|
46
|
+
*/
|
|
43
47
|
action: function action() {
|
|
44
48
|
return onInsert({
|
|
45
49
|
item: item
|
|
@@ -62,6 +66,12 @@ var InsertMenu = function InsertMenu(_ref) {
|
|
|
62
66
|
var getItems = useCallback(function (quickInsertState) {
|
|
63
67
|
return function (query, category) {
|
|
64
68
|
var result;
|
|
69
|
+
/**
|
|
70
|
+
* @warning The results if there is a query are not the same as the results if there is no query.
|
|
71
|
+
* For example: If you have a typed panel and then select the panel item then it will call a different action
|
|
72
|
+
* than is specified on the editor plugins quick insert
|
|
73
|
+
* @see above transform function for more details.
|
|
74
|
+
*/
|
|
65
75
|
if (query) {
|
|
66
76
|
result = searchQuickInsertItems(quickInsertState, {})(query, category);
|
|
67
77
|
} else {
|
package/dist/esm/version.json
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/// <reference path="../../../../../../../../typings/prosemirror.d.ts" />
|
|
2
|
+
/// <reference path="../../../../../../../../typings/prosemirror-state.d.ts" />
|
|
3
|
+
import { EditorState } from 'prosemirror-state';
|
|
4
|
+
import { NodeType } from 'prosemirror-model';
|
|
1
5
|
import { Command } from '../../../types';
|
|
2
6
|
import { HeadingLevelsAndNormalText } from '../types';
|
|
3
7
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
@@ -19,4 +23,25 @@ export declare function insertBlockType(name: string): Command;
|
|
|
19
23
|
* @returns - command that inserts block type
|
|
20
24
|
*/
|
|
21
25
|
export declare const insertBlockTypesWithAnalytics: (name: string, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
26
|
+
/**
|
|
27
|
+
* This function creates a new transaction that wraps the current selection
|
|
28
|
+
* in the specified node type if it results in a valid transaction.
|
|
29
|
+
* If not valid, it performs a safe insert operation.
|
|
30
|
+
*
|
|
31
|
+
* Example of when wrapping might not be valid is when attempting to wrap
|
|
32
|
+
* content that is already inside a panel with another panel
|
|
33
|
+
*/
|
|
34
|
+
export declare function createWrapSelectionTransaction({ state, type, nodeAttributes, }: {
|
|
35
|
+
state: EditorState;
|
|
36
|
+
type: NodeType;
|
|
37
|
+
nodeAttributes?: Record<string, any>;
|
|
38
|
+
}): import("prosemirror-state").Transaction;
|
|
39
|
+
/**
|
|
40
|
+
* This function creates a new transaction that inserts a code block,
|
|
41
|
+
* if there is text selected it will wrap the current selection if not it will
|
|
42
|
+
* append the codeblock to the end of the document.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createInsertCodeBlockTransaction({ state, }: {
|
|
45
|
+
state: EditorState;
|
|
46
|
+
}): import("prosemirror-state").Transaction;
|
|
22
47
|
export declare const cleanUpAtTheStartOfDocument: Command;
|
|
@@ -64,7 +64,7 @@ export type Request = {
|
|
|
64
64
|
*/
|
|
65
65
|
sourceEvent?: UIAnalyticsEvent | null | undefined;
|
|
66
66
|
};
|
|
67
|
-
type Metadata<T = {}> = {
|
|
67
|
+
export type Metadata<T = {}> = {
|
|
68
68
|
url: string;
|
|
69
69
|
display: string;
|
|
70
70
|
isUndo?: boolean;
|
|
@@ -74,7 +74,7 @@ type Metadata<T = {}> = {
|
|
|
74
74
|
sourceEvent?: unknown;
|
|
75
75
|
nodeContext?: string;
|
|
76
76
|
} & T;
|
|
77
|
-
type UpdateMetadata = {
|
|
77
|
+
export type UpdateMetadata = {
|
|
78
78
|
previousDisplay?: string;
|
|
79
79
|
};
|
|
80
80
|
export type SmartLinkEventsNext = {
|
|
@@ -162,4 +162,3 @@ export type SetCardLayoutAndDatasourceTableRef = {
|
|
|
162
162
|
datasourceTableRef?: HTMLElement;
|
|
163
163
|
};
|
|
164
164
|
export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | RegisterSmartCardEventsNext | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef;
|
|
165
|
-
export {};
|