@atlaskit/editor-core 187.23.2 → 187.24.1
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 +17 -0
- package/dist/cjs/create-editor/ReactEditorViewInternal.js +2 -1
- package/dist/cjs/editor-next/editor-internal.js +3 -0
- package/dist/cjs/plugins/base/index.js +2 -1
- package/dist/cjs/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +58 -27
- package/dist/cjs/plugins/text-color/commands/toggle-color.js +1 -1
- package/dist/cjs/presets/context.js +40 -0
- package/dist/cjs/ui/EditorContext/index.js +2 -1
- package/dist/cjs/use-preset.js +51 -0
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/create-editor/ReactEditorViewInternal.js +2 -1
- package/dist/es2019/editor-next/editor-internal.js +3 -0
- package/dist/es2019/plugins/base/index.js +2 -1
- package/dist/es2019/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +46 -16
- package/dist/es2019/plugins/text-color/commands/toggle-color.js +2 -2
- package/dist/es2019/presets/context.js +25 -0
- package/dist/es2019/ui/EditorContext/index.js +2 -1
- package/dist/es2019/use-preset.js +45 -0
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/create-editor/ReactEditorViewInternal.js +2 -1
- package/dist/esm/editor-next/editor-internal.js +3 -0
- package/dist/esm/plugins/base/index.js +2 -1
- package/dist/esm/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +58 -28
- package/dist/esm/plugins/text-color/commands/toggle-color.js +2 -2
- package/dist/esm/presets/context.js +26 -0
- package/dist/esm/ui/EditorContext/index.js +2 -1
- package/dist/esm/use-preset.js +45 -0
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/create-editor/ReactEditorViewInternal.d.ts +2 -0
- package/dist/types/labs/next/presets/default.d.ts +28 -28
- package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
- package/dist/types/plugins/emoji/index.d.ts +2 -2
- package/dist/types/plugins/find-replace/index.d.ts +1 -1
- package/dist/types/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +7 -4
- package/dist/types/presets/context.d.ts +15 -0
- package/dist/types/use-preset.d.ts +48 -0
- package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +2 -0
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +28 -28
- package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
- package/dist/types-ts4.5/plugins/emoji/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/find-replace/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +7 -4
- package/dist/types-ts4.5/presets/context.d.ts +15 -0
- package/dist/types-ts4.5/use-preset.d.ts +52 -0
- package/package.json +7 -4
- package/report.api.md +6 -0
- package/tmp/api-report-tmp.d.ts +6 -0
- package/use-preset/package.json +15 -0
- package/dist/cjs/version.json +0 -5
- package/dist/es2019/version.json +0 -5
- package/dist/esm/version.json +0 -5
|
@@ -2,6 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import EditorActions from '../../actions';
|
|
5
|
+
import { PresetContextProvider } from '../../presets/context';
|
|
5
6
|
const EditorContext = /*#__PURE__*/React.createContext({});
|
|
6
7
|
export const useEditorContext = () => React.useContext(EditorContext);
|
|
7
8
|
export default class LegacyEditorContext extends React.Component {
|
|
@@ -17,7 +18,7 @@ export default class LegacyEditorContext extends React.Component {
|
|
|
17
18
|
render() {
|
|
18
19
|
return /*#__PURE__*/React.createElement(EditorContext.Provider, {
|
|
19
20
|
value: this.getChildContext()
|
|
20
|
-
}, this.props.children);
|
|
21
|
+
}, /*#__PURE__*/React.createElement(PresetContextProvider, null, this.props.children));
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
_defineProperty(LegacyEditorContext, "childContextTypes", {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { usePresetContext } from './presets/context';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a preset.
|
|
5
|
+
*
|
|
6
|
+
* Takes an input function that returns a preset (and memoizes it) depending
|
|
7
|
+
* on the dependency array provided.
|
|
8
|
+
*
|
|
9
|
+
* Returns a pluginInjectionApi in order to apply actions and subscribe to plugin
|
|
10
|
+
* changes outside of the editor.
|
|
11
|
+
*
|
|
12
|
+
* @param createPreset
|
|
13
|
+
* @param dependencies
|
|
14
|
+
* @returns PresetAPI ({ pluginInjectionApi, preset, actionBuilder })
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
* ```ts
|
|
18
|
+
* function ExampleEditor() {
|
|
19
|
+
* const { preset, editorApi } = usePreset(() =>
|
|
20
|
+
* new EditorPresetBuilder().add(plugin1).add(plugin2)
|
|
21
|
+
* , []);
|
|
22
|
+
*
|
|
23
|
+
* // Can execute typesafe commands based on plugin1 or 2
|
|
24
|
+
* const runCommand = () => editorApi.executeCommand(
|
|
25
|
+
* editorApi.dependencies.plugin1.commands.doSomething()
|
|
26
|
+
* )
|
|
27
|
+
* return (
|
|
28
|
+
* <>
|
|
29
|
+
* <Editor preset={preset} />
|
|
30
|
+
* <Button onClick={runCommand}>Run command</Button>
|
|
31
|
+
* </>
|
|
32
|
+
* )
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function usePreset(createPreset, dependencies) {
|
|
37
|
+
const editorApi = usePresetContext();
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
const preset = useMemo(createPreset, dependencies);
|
|
41
|
+
return {
|
|
42
|
+
editorApi,
|
|
43
|
+
preset
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -80,7 +80,7 @@ export var ReactEditorView = /*#__PURE__*/function (_React$Component) {
|
|
|
80
80
|
_inherits(ReactEditorView, _React$Component);
|
|
81
81
|
var _super = _createSuper(ReactEditorView);
|
|
82
82
|
function ReactEditorView(props, context) {
|
|
83
|
-
var _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
|
|
83
|
+
var _props$setEditorApi, _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
|
|
84
84
|
var _this;
|
|
85
85
|
_classCallCheck(this, ReactEditorView);
|
|
86
86
|
_this = _super.call(this, props, context);
|
|
@@ -529,6 +529,7 @@ export var ReactEditorView = /*#__PURE__*/function (_React$Component) {
|
|
|
529
529
|
getEditorState: _this.getEditorState,
|
|
530
530
|
getEditorView: _this.getEditorView
|
|
531
531
|
});
|
|
532
|
+
(_props$setEditorApi = props.setEditorApi) === null || _props$setEditorApi === void 0 ? void 0 : _props$setEditorApi.call(props, _this.pluginInjectionAPI.api());
|
|
532
533
|
_this.eventDispatcher = new EventDispatcher();
|
|
533
534
|
_this.dispatch = createDispatch(_this.eventDispatcher);
|
|
534
535
|
_this.errorReporter = createErrorReporter(props.editorProps.errorReporterHandler);
|
|
@@ -13,6 +13,7 @@ import { createFeatureFlagsFromProps } from '../create-editor/feature-flags-from
|
|
|
13
13
|
import ReactEditorView from '../create-editor/ReactEditorViewNext';
|
|
14
14
|
import { ContextAdapter } from '../nodeviews/context-adapter';
|
|
15
15
|
import EditorContext from '../ui/EditorContext';
|
|
16
|
+
import { useSetPresetContext } from '../presets/context';
|
|
16
17
|
import { RenderTracking } from '../utils/performance/components/RenderTracking';
|
|
17
18
|
import useMeasureEditorMountTime from './hooks/useMeasureEditorMountTime';
|
|
18
19
|
import useProviderFactory from './hooks/useProviderFactory';
|
|
@@ -50,6 +51,7 @@ export function EditorInternalWithoutHooks(_ref) {
|
|
|
50
51
|
onEditorDestroyed = _ref.onEditorDestroyed,
|
|
51
52
|
preset = _ref.preset;
|
|
52
53
|
var Component = getUiComponent(props.appearance);
|
|
54
|
+
var setEditorApi = useSetPresetContext();
|
|
53
55
|
var overriddenEditorProps = _objectSpread(_objectSpread({}, props), {}, {
|
|
54
56
|
onSave: props.onSave ? handleSave : undefined,
|
|
55
57
|
// noop all analytic events, even if a handler is still passed.
|
|
@@ -94,6 +96,7 @@ export function EditorInternalWithoutHooks(_ref) {
|
|
|
94
96
|
onEditorDestroyed: onEditorDestroyed,
|
|
95
97
|
disabled: props.disabled,
|
|
96
98
|
preset: preset,
|
|
99
|
+
setEditorApi: setEditorApi,
|
|
97
100
|
render: function render(_ref2) {
|
|
98
101
|
var _props$featureFlags, _props$featureFlags2;
|
|
99
102
|
var editor = _ref2.editor,
|
|
@@ -3,6 +3,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
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 { baseKeymap } from '@atlaskit/editor-prosemirror/commands';
|
|
5
5
|
import { history } from '@atlaskit/editor-prosemirror/history';
|
|
6
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
8
|
import { doc, paragraph, text } from '@atlaskit/adf-schema';
|
|
8
9
|
import filterStepsPlugin from './pm-plugins/filter-steps';
|
|
@@ -89,7 +90,7 @@ var basePlugin = function basePlugin(options, api) {
|
|
|
89
90
|
}
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
|
-
if (isChromeWithSelectionBug) {
|
|
93
|
+
if (isChromeWithSelectionBug && !getBooleanFF('platform.editor.disable-chrome-88-selection-fix_uk53m')) {
|
|
93
94
|
plugins.push({
|
|
94
95
|
name: 'fixChrome88SelectionPlugin',
|
|
95
96
|
plugin: function plugin() {
|
|
@@ -23,35 +23,40 @@ import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
|
23
23
|
import classnames from 'classnames';
|
|
24
24
|
import { richMediaClassName, resizerStyles } from '@atlaskit/editor-common/styles';
|
|
25
25
|
import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_RESIZE_THROTTLE_TIME, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH, calcMediaSingleMaxWidth } from '@atlaskit/editor-common/media-single';
|
|
26
|
-
import { findClosestSnap, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines, getGuidelineSnaps, getGuidelineTypeFromKey } from '@atlaskit/editor-common/guideline';
|
|
26
|
+
import { findClosestSnap, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines, getGuidelineSnaps, getGuidelineTypeFromKey, getRelativeGuideSnaps, getRelativeGuidelines } from '@atlaskit/editor-common/guideline';
|
|
27
27
|
import memoizeOne from 'memoize-one';
|
|
28
28
|
import { getMediaResizeAnalyticsEvent } from '../../utils/analytics';
|
|
29
29
|
import throttle from 'lodash/throttle';
|
|
30
30
|
import { MEDIA_PLUGIN_IS_RESIZING_KEY, MEDIA_PLUGIN_RESIZING_WIDTH_KEY } from '../../pm-plugins/main';
|
|
31
31
|
export var resizerNextTestId = 'mediaSingle.resizerNext.testid';
|
|
32
|
-
var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
32
|
+
export var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
33
33
|
_inherits(ResizableMediaSingleNext, _React$Component);
|
|
34
34
|
var _super = _createSuper(ResizableMediaSingleNext);
|
|
35
35
|
function ResizableMediaSingleNext(props) {
|
|
36
36
|
var _this;
|
|
37
37
|
_classCallCheck(this, ResizableMediaSingleNext);
|
|
38
38
|
_this = _super.call(this, props);
|
|
39
|
-
_defineProperty(_assertThisInitialized(_this), "guidelines", []);
|
|
40
39
|
_defineProperty(_assertThisInitialized(_this), "lastSnappedGuidelineKeys", []);
|
|
41
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "updateGuidelines", function () {
|
|
42
41
|
var _this$props = _this.props,
|
|
43
42
|
view = _this$props.view,
|
|
44
43
|
lineLength = _this$props.lineLength;
|
|
45
44
|
var defaultGuidelines = _this.getDefaultGuidelines();
|
|
45
|
+
var _generateDynamicGuide = generateDynamicGuidelines(view.state, lineLength, {
|
|
46
|
+
styles: {
|
|
47
|
+
lineStyle: 'dashed'
|
|
48
|
+
},
|
|
49
|
+
show: false
|
|
50
|
+
}),
|
|
51
|
+
relativeGuides = _generateDynamicGuide.relativeGuides,
|
|
52
|
+
dynamicGuides = _generateDynamicGuide.dynamicGuides;
|
|
53
|
+
|
|
46
54
|
// disable guidelines for nested media single node
|
|
47
|
-
var dynamicGuidelines = _this.isNestedNode() ? [] :
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
show: false
|
|
55
|
+
var dynamicGuidelines = _this.isNestedNode() ? [] : dynamicGuides;
|
|
56
|
+
_this.setState({
|
|
57
|
+
relativeGuides: relativeGuides,
|
|
58
|
+
guidelines: [].concat(_toConsumableArray(defaultGuidelines), _toConsumableArray(dynamicGuidelines))
|
|
52
59
|
});
|
|
53
|
-
var guidelines = [].concat(_toConsumableArray(defaultGuidelines), _toConsumableArray(dynamicGuidelines));
|
|
54
|
-
return guidelines;
|
|
55
60
|
});
|
|
56
61
|
_defineProperty(_assertThisInitialized(_this), "calcNewSize", function (newWidth, stop) {
|
|
57
62
|
var _this$props2 = _this.props,
|
|
@@ -60,7 +65,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
60
65
|
containerWidth = _this$props2.containerWidth,
|
|
61
66
|
lineLength = _this$props2.lineLength,
|
|
62
67
|
fullWidthMode = _this$props2.fullWidthMode;
|
|
63
|
-
var newPct = calcPctFromPx(newWidth,
|
|
68
|
+
var newPct = calcPctFromPx(newWidth, lineLength) * 100;
|
|
64
69
|
_this.setState({
|
|
65
70
|
resizedPctWidth: newPct
|
|
66
71
|
});
|
|
@@ -142,6 +147,13 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
142
147
|
}
|
|
143
148
|
return calcMediaSingleMaxWidth(containerWidth);
|
|
144
149
|
}));
|
|
150
|
+
_defineProperty(_assertThisInitialized(_this), "getRelativeGuides", function () {
|
|
151
|
+
var relativeGuides = _this.$pos && _this.$pos.nodeAfter && _this.state.size.width ? getRelativeGuidelines(_this.state.relativeGuides, {
|
|
152
|
+
node: _this.$pos.nodeAfter,
|
|
153
|
+
pos: _this.$pos.pos
|
|
154
|
+
}, _this.props.view, _this.props.lineLength, _this.state.size) : [];
|
|
155
|
+
return relativeGuides;
|
|
156
|
+
});
|
|
145
157
|
_defineProperty(_assertThisInitialized(_this), "updateActiveGuidelines", function () {
|
|
146
158
|
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
147
159
|
var guidelines = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -151,7 +163,8 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
151
163
|
gap = _findClosestSnap.gap,
|
|
152
164
|
activeGuidelineKeys = _findClosestSnap.keys;
|
|
153
165
|
_this.lastSnappedGuidelineKeys = activeGuidelineKeys;
|
|
154
|
-
|
|
166
|
+
var relativeGuidelines = activeGuidelineKeys.length ? [] : _this.getRelativeGuides();
|
|
167
|
+
_this.displayGuideline([].concat(_toConsumableArray(getGuidelinesWithHighlights(gap, MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines)), _toConsumableArray(relativeGuidelines)));
|
|
155
168
|
}
|
|
156
169
|
});
|
|
157
170
|
_defineProperty(_assertThisInitialized(_this), "roundPixelValue", function (value) {
|
|
@@ -214,7 +227,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
214
227
|
_this.setIsResizing(true);
|
|
215
228
|
_this.updateSizeInPluginState(_this.state.size.width);
|
|
216
229
|
// re-calucate guidelines
|
|
217
|
-
_this.
|
|
230
|
+
_this.updateGuidelines();
|
|
218
231
|
return 0;
|
|
219
232
|
});
|
|
220
233
|
_defineProperty(_assertThisInitialized(_this), "handleResize", throttle(function (size, delta) {
|
|
@@ -228,14 +241,17 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
228
241
|
width = _this$calculateSizeSt.width,
|
|
229
242
|
height = _this$calculateSizeSt.height,
|
|
230
243
|
calculatedWidthWithLayout = _this$calculateSizeSt.calculatedWidthWithLayout;
|
|
231
|
-
var guidelineSnaps = getGuidelineSnaps(_this.guidelines, lineLength, layout);
|
|
232
|
-
_this.updateActiveGuidelines(width, _this.guidelines, guidelineSnaps);
|
|
244
|
+
var guidelineSnaps = getGuidelineSnaps(_this.state.guidelines, lineLength, layout);
|
|
245
|
+
_this.updateActiveGuidelines(width, _this.state.guidelines, guidelineSnaps);
|
|
246
|
+
var relativeSnaps = getRelativeGuideSnaps(_this.state.relativeGuides, _this.aspectRatio);
|
|
233
247
|
_this.setState({
|
|
234
248
|
size: {
|
|
235
249
|
width: width,
|
|
236
250
|
height: height
|
|
237
251
|
},
|
|
238
|
-
snaps:
|
|
252
|
+
snaps: {
|
|
253
|
+
x: [].concat(_toConsumableArray(guidelineSnaps.snaps.x || []), _toConsumableArray(relativeSnaps))
|
|
254
|
+
}
|
|
239
255
|
});
|
|
240
256
|
_this.updateSizeInPluginState(width);
|
|
241
257
|
if (calculatedWidthWithLayout.layout !== layout) {
|
|
@@ -258,7 +274,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
258
274
|
width: width,
|
|
259
275
|
layout: calculatedWidthWithLayout.layout,
|
|
260
276
|
widthType: 'pixel',
|
|
261
|
-
snapType: getGuidelineTypeFromKey(_this.lastSnappedGuidelineKeys, _this.guidelines),
|
|
277
|
+
snapType: getGuidelineTypeFromKey(_this.lastSnappedGuidelineKeys, _this.state.guidelines),
|
|
262
278
|
parentNode: _this.getParentNodeTypeNameFromCurrentPositionNode()
|
|
263
279
|
});
|
|
264
280
|
if (event) {
|
|
@@ -287,7 +303,9 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
287
303
|
width: initialWidth,
|
|
288
304
|
height: _this.calcPxHeight(initialWidth)
|
|
289
305
|
},
|
|
290
|
-
snaps: {}
|
|
306
|
+
snaps: {},
|
|
307
|
+
relativeGuides: {},
|
|
308
|
+
guidelines: []
|
|
291
309
|
};
|
|
292
310
|
return _this;
|
|
293
311
|
}
|
|
@@ -406,6 +424,18 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
406
424
|
this.checkVideoFile(nextProps.viewMediaClientConfig);
|
|
407
425
|
}
|
|
408
426
|
}
|
|
427
|
+
}, {
|
|
428
|
+
key: "aspectRatio",
|
|
429
|
+
get: function get() {
|
|
430
|
+
var _this$props8 = this.props,
|
|
431
|
+
width = _this$props8.width,
|
|
432
|
+
height = _this$props8.height;
|
|
433
|
+
if (width) {
|
|
434
|
+
return width / height;
|
|
435
|
+
}
|
|
436
|
+
// TODO handle this case
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
409
439
|
}, {
|
|
410
440
|
key: "checkVideoFile",
|
|
411
441
|
value: function () {
|
|
@@ -508,15 +538,15 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
508
538
|
key: "render",
|
|
509
539
|
value: function render() {
|
|
510
540
|
var _this3 = this;
|
|
511
|
-
var _this$
|
|
512
|
-
origWidth = _this$
|
|
513
|
-
layout = _this$
|
|
514
|
-
pctWidth = _this$
|
|
515
|
-
containerWidth = _this$
|
|
516
|
-
fullWidthMode = _this$
|
|
517
|
-
selected = _this$
|
|
518
|
-
children = _this$
|
|
519
|
-
lineLength = _this$
|
|
541
|
+
var _this$props9 = this.props,
|
|
542
|
+
origWidth = _this$props9.width,
|
|
543
|
+
layout = _this$props9.layout,
|
|
544
|
+
pctWidth = _this$props9.pctWidth,
|
|
545
|
+
containerWidth = _this$props9.containerWidth,
|
|
546
|
+
fullWidthMode = _this$props9.fullWidthMode,
|
|
547
|
+
selected = _this$props9.selected,
|
|
548
|
+
children = _this$props9.children,
|
|
549
|
+
lineLength = _this$props9.lineLength;
|
|
520
550
|
var _this$state = this.state,
|
|
521
551
|
isResizing = _this$state.isResizing,
|
|
522
552
|
size = _this$state.size;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
2
2
|
import { ACTIONS, pluginKey } from '../pm-plugins/main';
|
|
3
3
|
import { getDisabledState } from '../utils/disabled';
|
|
4
|
-
import {
|
|
4
|
+
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
5
5
|
export var toggleColor = function toggleColor(color) {
|
|
6
6
|
return function (state, dispatch) {
|
|
7
7
|
var textColor = state.schema.marks.textColor;
|
|
@@ -21,7 +21,7 @@ export var toggleColor = function toggleColor(color) {
|
|
|
21
21
|
color: color
|
|
22
22
|
});
|
|
23
23
|
state.tr.scrollIntoView();
|
|
24
|
-
|
|
24
|
+
editorCommandToPMCommand(toggleMark(textColor, {
|
|
25
25
|
color: color
|
|
26
26
|
}))(state, dispatch);
|
|
27
27
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useState, useContext } from 'react';
|
|
3
|
+
export var EditorAPIContext = /*#__PURE__*/React.createContext({});
|
|
4
|
+
export var PresetContextProvider = function PresetContextProvider(_ref) {
|
|
5
|
+
var children = _ref.children;
|
|
6
|
+
var _useState = useState(),
|
|
7
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
8
|
+
editorApi = _useState2[0],
|
|
9
|
+
setEditorApi = _useState2[1];
|
|
10
|
+
return /*#__PURE__*/React.createElement(EditorAPIContext.Provider, {
|
|
11
|
+
value: {
|
|
12
|
+
editorApi: editorApi,
|
|
13
|
+
setEditorApi: setEditorApi
|
|
14
|
+
}
|
|
15
|
+
}, children);
|
|
16
|
+
};
|
|
17
|
+
export var usePresetContext = function usePresetContext() {
|
|
18
|
+
var _useContext = useContext(EditorAPIContext),
|
|
19
|
+
editorApi = _useContext.editorApi;
|
|
20
|
+
return editorApi;
|
|
21
|
+
};
|
|
22
|
+
export var useSetPresetContext = function useSetPresetContext() {
|
|
23
|
+
var _useContext2 = useContext(EditorAPIContext),
|
|
24
|
+
setEditorApi = _useContext2.setEditorApi;
|
|
25
|
+
return setEditorApi;
|
|
26
|
+
};
|
|
@@ -9,6 +9,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import EditorActions from '../../actions';
|
|
12
|
+
import { PresetContextProvider } from '../../presets/context';
|
|
12
13
|
var EditorContext = /*#__PURE__*/React.createContext({});
|
|
13
14
|
export var useEditorContext = function useEditorContext() {
|
|
14
15
|
return React.useContext(EditorContext);
|
|
@@ -35,7 +36,7 @@ var LegacyEditorContext = /*#__PURE__*/function (_React$Component) {
|
|
|
35
36
|
value: function render() {
|
|
36
37
|
return /*#__PURE__*/React.createElement(EditorContext.Provider, {
|
|
37
38
|
value: this.getChildContext()
|
|
38
|
-
}, this.props.children);
|
|
39
|
+
}, /*#__PURE__*/React.createElement(PresetContextProvider, null, this.props.children));
|
|
39
40
|
}
|
|
40
41
|
}]);
|
|
41
42
|
return LegacyEditorContext;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { usePresetContext } from './presets/context';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a preset.
|
|
5
|
+
*
|
|
6
|
+
* Takes an input function that returns a preset (and memoizes it) depending
|
|
7
|
+
* on the dependency array provided.
|
|
8
|
+
*
|
|
9
|
+
* Returns a pluginInjectionApi in order to apply actions and subscribe to plugin
|
|
10
|
+
* changes outside of the editor.
|
|
11
|
+
*
|
|
12
|
+
* @param createPreset
|
|
13
|
+
* @param dependencies
|
|
14
|
+
* @returns PresetAPI ({ pluginInjectionApi, preset, actionBuilder })
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
* ```ts
|
|
18
|
+
* function ExampleEditor() {
|
|
19
|
+
* const { preset, editorApi } = usePreset(() =>
|
|
20
|
+
* new EditorPresetBuilder().add(plugin1).add(plugin2)
|
|
21
|
+
* , []);
|
|
22
|
+
*
|
|
23
|
+
* // Can execute typesafe commands based on plugin1 or 2
|
|
24
|
+
* const runCommand = () => editorApi.executeCommand(
|
|
25
|
+
* editorApi.dependencies.plugin1.commands.doSomething()
|
|
26
|
+
* )
|
|
27
|
+
* return (
|
|
28
|
+
* <>
|
|
29
|
+
* <Editor preset={preset} />
|
|
30
|
+
* <Button onClick={runCommand}>Run command</Button>
|
|
31
|
+
* </>
|
|
32
|
+
* )
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function usePreset(createPreset, dependencies) {
|
|
37
|
+
var editorApi = usePresetContext();
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
var preset = useMemo(createPreset, dependencies);
|
|
41
|
+
return {
|
|
42
|
+
editorApi: editorApi,
|
|
43
|
+
preset: preset
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -16,6 +16,7 @@ import { FULL_WIDTH_MODE } from '@atlaskit/editor-common/analytics';
|
|
|
16
16
|
import type { EditorAppearance, EditorConfig, EditorReactContext, EditorPlugin, EditorProps } from '../types';
|
|
17
17
|
import type { EditorNextProps } from '../types/editor-props';
|
|
18
18
|
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
|
|
19
|
+
import type { SetEditorAPI } from '../presets/context';
|
|
19
20
|
import { TransactionTracker } from '../utils/performance/track-transactions';
|
|
20
21
|
import type { FireAnalyticsCallback, AnalyticsEventPayload, DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
21
22
|
import type { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
|
|
@@ -26,6 +27,7 @@ export interface EditorViewProps {
|
|
|
26
27
|
portalProviderAPI: PortalProviderAPI;
|
|
27
28
|
disabled?: boolean;
|
|
28
29
|
experienceStore?: ExperienceStore;
|
|
30
|
+
setEditorApi?: SetEditorAPI;
|
|
29
31
|
render?: (props: {
|
|
30
32
|
editor: JSX.Element;
|
|
31
33
|
view?: EditorView;
|
|
@@ -263,13 +263,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
263
263
|
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
264
264
|
}>>];
|
|
265
265
|
commands: {
|
|
266
|
-
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
267
|
-
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
268
|
-
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").
|
|
269
|
-
toggleCode: import("@atlaskit/editor-plugin-text-formatting").
|
|
270
|
-
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").
|
|
271
|
-
toggleEm: import("@atlaskit/editor-plugin-text-formatting").
|
|
272
|
-
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").
|
|
266
|
+
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
267
|
+
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
268
|
+
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
269
|
+
toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
270
|
+
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
271
|
+
toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
272
|
+
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
273
273
|
};
|
|
274
274
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"textFormatting", {
|
|
275
275
|
pluginConfiguration: TextFormattingOptions | undefined;
|
|
@@ -303,13 +303,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
303
303
|
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
304
304
|
}>>];
|
|
305
305
|
commands: {
|
|
306
|
-
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
307
|
-
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
308
|
-
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").
|
|
309
|
-
toggleCode: import("@atlaskit/editor-plugin-text-formatting").
|
|
310
|
-
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").
|
|
311
|
-
toggleEm: import("@atlaskit/editor-plugin-text-formatting").
|
|
312
|
-
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").
|
|
306
|
+
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
307
|
+
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
308
|
+
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
309
|
+
toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
310
|
+
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
311
|
+
toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
312
|
+
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
313
313
|
};
|
|
314
314
|
}>, (config?: HyperlinkPluginOptions | undefined, api?: import("@atlaskit/editor-common/types").PluginInjectionAPI<"hyperlink", {
|
|
315
315
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -634,13 +634,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
634
634
|
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
635
635
|
}>>];
|
|
636
636
|
commands: {
|
|
637
|
-
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
638
|
-
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
639
|
-
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").
|
|
640
|
-
toggleCode: import("@atlaskit/editor-plugin-text-formatting").
|
|
641
|
-
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").
|
|
642
|
-
toggleEm: import("@atlaskit/editor-plugin-text-formatting").
|
|
643
|
-
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").
|
|
637
|
+
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
638
|
+
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
639
|
+
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
640
|
+
toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
641
|
+
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
642
|
+
toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
643
|
+
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
644
644
|
};
|
|
645
645
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"textFormatting", {
|
|
646
646
|
pluginConfiguration: TextFormattingOptions | undefined;
|
|
@@ -674,13 +674,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
674
674
|
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
675
675
|
}>>];
|
|
676
676
|
commands: {
|
|
677
|
-
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
678
|
-
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").
|
|
679
|
-
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").
|
|
680
|
-
toggleCode: import("@atlaskit/editor-plugin-text-formatting").
|
|
681
|
-
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").
|
|
682
|
-
toggleEm: import("@atlaskit/editor-plugin-text-formatting").
|
|
683
|
-
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").
|
|
677
|
+
toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
678
|
+
toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
679
|
+
toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
680
|
+
toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
681
|
+
toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
682
|
+
toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
683
|
+
toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
|
|
684
684
|
};
|
|
685
685
|
}>, (config?: HyperlinkPluginOptions | undefined, api?: import("@atlaskit/editor-common/types").PluginInjectionAPI<"hyperlink", {
|
|
686
686
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EmojiId } from '@atlaskit/emoji';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { INPUT_METHOD, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
export declare const insertEmoji: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) =>
|
|
4
|
+
export declare const insertEmoji: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
@@ -2,7 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EmojiDescription, EmojiProvider, EmojiId } from '@atlaskit/emoji';
|
|
5
|
-
import type { Command, NextEditorPlugin, PMPluginFactoryParams, OptionalPlugin,
|
|
5
|
+
import type { Command, NextEditorPlugin, PMPluginFactoryParams, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
6
6
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
7
7
|
import type { TypeAheadItem } from '../type-ahead/types';
|
|
8
8
|
import type { EmojiPluginOptions, EmojiPluginState } from './types';
|
|
@@ -18,7 +18,7 @@ export type EmojiPlugin = NextEditorPlugin<'emoji', {
|
|
|
18
18
|
dependencies: [OptionalPlugin<typeof analyticsPlugin>];
|
|
19
19
|
sharedState: EmojiPluginState | undefined;
|
|
20
20
|
commands: {
|
|
21
|
-
insertEmoji: (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) =>
|
|
21
|
+
insertEmoji: (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
|
|
22
22
|
};
|
|
23
23
|
}>;
|
|
24
24
|
export declare const emojiPlugin: EmojiPlugin;
|
|
@@ -5,7 +5,7 @@ import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema'
|
|
|
5
5
|
import type { MediaClientConfig } from '@atlaskit/media-core';
|
|
6
6
|
import type { Props } from './types';
|
|
7
7
|
import type { Dimensions, HandleResize, HandleResizeStart, Position, Snap } from '@atlaskit/editor-common/resizer';
|
|
8
|
-
import type { GuidelineConfig, GuidelineSnapsReference } from '@atlaskit/editor-common/guideline';
|
|
8
|
+
import type { GuidelineConfig, RelativeGuides, GuidelineSnapsReference } from '@atlaskit/editor-common/guideline';
|
|
9
9
|
type State = {
|
|
10
10
|
offsetLeft: number;
|
|
11
11
|
isVideoFile: boolean;
|
|
@@ -13,11 +13,12 @@ type State = {
|
|
|
13
13
|
isResizing: boolean;
|
|
14
14
|
size: Dimensions;
|
|
15
15
|
snaps: Snap;
|
|
16
|
+
relativeGuides: RelativeGuides;
|
|
17
|
+
guidelines: GuidelineConfig[];
|
|
16
18
|
};
|
|
17
19
|
export declare const resizerNextTestId = "mediaSingle.resizerNext.testid";
|
|
18
20
|
type ResizableMediaSingleNextProps = Props;
|
|
19
|
-
declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSingleNextProps, State> {
|
|
20
|
-
private guidelines;
|
|
21
|
+
export declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSingleNextProps, State> {
|
|
21
22
|
private lastSnappedGuidelineKeys;
|
|
22
23
|
constructor(props: ResizableMediaSingleNextProps);
|
|
23
24
|
/**
|
|
@@ -30,10 +31,11 @@ declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSin
|
|
|
30
31
|
componentDidUpdate(prevProps: Props): boolean;
|
|
31
32
|
isNestedNode(): boolean;
|
|
32
33
|
private getDefaultGuidelines;
|
|
33
|
-
private
|
|
34
|
+
private updateGuidelines;
|
|
34
35
|
get wrappedLayout(): boolean;
|
|
35
36
|
componentDidMount(): Promise<void>;
|
|
36
37
|
UNSAFE_componentWillReceiveProps(nextProps: Props): void;
|
|
38
|
+
get aspectRatio(): number;
|
|
37
39
|
checkVideoFile(viewMediaClientConfig?: MediaClientConfig): Promise<void>;
|
|
38
40
|
calcNewSize: (newWidth: number, stop: boolean) => {
|
|
39
41
|
width: number | null;
|
|
@@ -55,6 +57,7 @@ declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSin
|
|
|
55
57
|
private setIsResizing;
|
|
56
58
|
private updateSizeInPluginState;
|
|
57
59
|
private calcMaxWidth;
|
|
60
|
+
private getRelativeGuides;
|
|
58
61
|
updateActiveGuidelines: (width: number | undefined, guidelines: GuidelineConfig[], guidelineSnapsReference: GuidelineSnapsReference) => void;
|
|
59
62
|
roundPixelValue: (value: number) => number;
|
|
60
63
|
getHeightFromNewWidth: (originalWidth: number, originalHeight: number, newWidth: number) => number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
export type SetEditorAPI = (editorApi: PublicPluginAPI<any>) => void;
|
|
4
|
+
export interface EditorAPIContextType {
|
|
5
|
+
editorApi?: PublicPluginAPI<any>;
|
|
6
|
+
setEditorApi?: SetEditorAPI;
|
|
7
|
+
}
|
|
8
|
+
export declare const EditorAPIContext: React.Context<EditorAPIContextType>;
|
|
9
|
+
interface EditorAPIProviderProps {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const PresetContextProvider: ({ children }: EditorAPIProviderProps) => JSX.Element;
|
|
13
|
+
export declare const usePresetContext: () => PublicPluginAPI<any> | undefined;
|
|
14
|
+
export declare const useSetPresetContext: () => SetEditorAPI | undefined;
|
|
15
|
+
export {};
|