@atlaskit/editor-core 187.23.2 → 187.24.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 (43) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/create-editor/ReactEditorViewInternal.js +2 -1
  3. package/dist/cjs/editor-next/editor-internal.js +3 -0
  4. package/dist/cjs/plugins/text-color/commands/toggle-color.js +1 -1
  5. package/dist/cjs/presets/context.js +40 -0
  6. package/dist/cjs/ui/EditorContext/index.js +2 -1
  7. package/dist/cjs/use-preset.js +51 -0
  8. package/dist/cjs/version-wrapper.js +1 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/create-editor/ReactEditorViewInternal.js +2 -1
  11. package/dist/es2019/editor-next/editor-internal.js +3 -0
  12. package/dist/es2019/plugins/text-color/commands/toggle-color.js +2 -2
  13. package/dist/es2019/presets/context.js +25 -0
  14. package/dist/es2019/ui/EditorContext/index.js +2 -1
  15. package/dist/es2019/use-preset.js +45 -0
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/create-editor/ReactEditorViewInternal.js +2 -1
  19. package/dist/esm/editor-next/editor-internal.js +3 -0
  20. package/dist/esm/plugins/text-color/commands/toggle-color.js +2 -2
  21. package/dist/esm/presets/context.js +26 -0
  22. package/dist/esm/ui/EditorContext/index.js +2 -1
  23. package/dist/esm/use-preset.js +45 -0
  24. package/dist/esm/version-wrapper.js +1 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/create-editor/ReactEditorViewInternal.d.ts +2 -0
  27. package/dist/types/labs/next/presets/default.d.ts +28 -28
  28. package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  29. package/dist/types/plugins/emoji/index.d.ts +2 -2
  30. package/dist/types/plugins/find-replace/index.d.ts +1 -1
  31. package/dist/types/presets/context.d.ts +15 -0
  32. package/dist/types/use-preset.d.ts +48 -0
  33. package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +2 -0
  34. package/dist/types-ts4.5/labs/next/presets/default.d.ts +28 -28
  35. package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  36. package/dist/types-ts4.5/plugins/emoji/index.d.ts +2 -2
  37. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +1 -1
  38. package/dist/types-ts4.5/presets/context.d.ts +15 -0
  39. package/dist/types-ts4.5/use-preset.d.ts +52 -0
  40. package/package.json +4 -4
  41. package/report.api.md +6 -0
  42. package/tmp/api-report-tmp.d.ts +6 -0
  43. package/use-preset/package.json +15 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 187.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`24fc3925d73`](https://bitbucket.org/atlassian/atlassian-frontend/commits/24fc3925d73) - Add a new hook called `usePreset` accesed via `@atlaskit/editor-core/use-preset`. This hook can be used to safely access state and commands from outside the editor using `EditorContext`.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 187.23.2
4
14
 
5
15
  ### Patch Changes
@@ -87,7 +87,7 @@ var ReactEditorView = /*#__PURE__*/function (_React$Component) {
87
87
  (0, _inherits2.default)(ReactEditorView, _React$Component);
88
88
  var _super = _createSuper(ReactEditorView);
89
89
  function ReactEditorView(props, context) {
90
- var _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
90
+ var _props$setEditorApi, _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
91
91
  var _this;
92
92
  (0, _classCallCheck2.default)(this, ReactEditorView);
93
93
  _this = _super.call(this, props, context);
@@ -536,6 +536,7 @@ var ReactEditorView = /*#__PURE__*/function (_React$Component) {
536
536
  getEditorState: _this.getEditorState,
537
537
  getEditorView: _this.getEditorView
538
538
  });
539
+ (_props$setEditorApi = props.setEditorApi) === null || _props$setEditorApi === void 0 ? void 0 : _props$setEditorApi.call(props, _this.pluginInjectionAPI.api());
539
540
  _this.eventDispatcher = new _eventDispatcher.EventDispatcher();
540
541
  _this.dispatch = (0, _eventDispatcher.createDispatch)(_this.eventDispatcher);
541
542
  _this.errorReporter = (0, _createEditor.createErrorReporter)(props.editorProps.errorReporterHandler);
@@ -18,6 +18,7 @@ var _featureFlagsFromProps = require("../create-editor/feature-flags-from-props"
18
18
  var _ReactEditorViewNext = _interopRequireDefault(require("../create-editor/ReactEditorViewNext"));
19
19
  var _contextAdapter = require("../nodeviews/context-adapter");
20
20
  var _EditorContext = _interopRequireDefault(require("../ui/EditorContext"));
21
+ var _context = require("../presets/context");
21
22
  var _RenderTracking = require("../utils/performance/components/RenderTracking");
22
23
  var _useMeasureEditorMountTime = _interopRequireDefault(require("./hooks/useMeasureEditorMountTime"));
23
24
  var _useProviderFactory = _interopRequireDefault(require("./hooks/useProviderFactory"));
@@ -57,6 +58,7 @@ function EditorInternalWithoutHooks(_ref) {
57
58
  onEditorDestroyed = _ref.onEditorDestroyed,
58
59
  preset = _ref.preset;
59
60
  var Component = (0, _createEditor.getUiComponent)(props.appearance);
61
+ var setEditorApi = (0, _context.useSetPresetContext)();
60
62
  var overriddenEditorProps = _objectSpread(_objectSpread({}, props), {}, {
61
63
  onSave: props.onSave ? handleSave : undefined,
62
64
  // noop all analytic events, even if a handler is still passed.
@@ -101,6 +103,7 @@ function EditorInternalWithoutHooks(_ref) {
101
103
  onEditorDestroyed: onEditorDestroyed,
102
104
  disabled: props.disabled,
103
105
  preset: preset,
106
+ setEditorApi: setEditorApi,
104
107
  render: function render(_ref2) {
105
108
  var _props$featureFlags, _props$featureFlags2;
106
109
  var editor = _ref2.editor,
@@ -27,7 +27,7 @@ var toggleColor = function toggleColor(color) {
27
27
  color: color
28
28
  });
29
29
  state.tr.scrollIntoView();
30
- (0, _preset.pluginCommandToPMCommand)((0, _mark.toggleMark)(textColor, {
30
+ (0, _preset.editorCommandToPMCommand)((0, _mark.toggleMark)(textColor, {
31
31
  color: color
32
32
  }))(state, dispatch);
33
33
  }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useSetPresetContext = exports.usePresetContext = exports.PresetContextProvider = exports.EditorAPIContext = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ var EditorAPIContext = /*#__PURE__*/_react.default.createContext({});
14
+ exports.EditorAPIContext = EditorAPIContext;
15
+ var PresetContextProvider = function PresetContextProvider(_ref) {
16
+ var children = _ref.children;
17
+ var _useState = (0, _react.useState)(),
18
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
19
+ editorApi = _useState2[0],
20
+ setEditorApi = _useState2[1];
21
+ return /*#__PURE__*/_react.default.createElement(EditorAPIContext.Provider, {
22
+ value: {
23
+ editorApi: editorApi,
24
+ setEditorApi: setEditorApi
25
+ }
26
+ }, children);
27
+ };
28
+ exports.PresetContextProvider = PresetContextProvider;
29
+ var usePresetContext = function usePresetContext() {
30
+ var _useContext = (0, _react.useContext)(EditorAPIContext),
31
+ editorApi = _useContext.editorApi;
32
+ return editorApi;
33
+ };
34
+ exports.usePresetContext = usePresetContext;
35
+ var useSetPresetContext = function useSetPresetContext() {
36
+ var _useContext2 = (0, _react.useContext)(EditorAPIContext),
37
+ setEditorApi = _useContext2.setEditorApi;
38
+ return setEditorApi;
39
+ };
40
+ exports.useSetPresetContext = useSetPresetContext;
@@ -14,6 +14,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
14
14
  var _react = _interopRequireDefault(require("react"));
15
15
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
16
  var _actions = _interopRequireDefault(require("../../actions"));
17
+ var _context = require("../../presets/context");
17
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); }; }
18
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; } }
19
20
  var EditorContext = /*#__PURE__*/_react.default.createContext({});
@@ -43,7 +44,7 @@ var LegacyEditorContext = /*#__PURE__*/function (_React$Component) {
43
44
  value: function render() {
44
45
  return /*#__PURE__*/_react.default.createElement(EditorContext.Provider, {
45
46
  value: this.getChildContext()
46
- }, this.props.children);
47
+ }, /*#__PURE__*/_react.default.createElement(_context.PresetContextProvider, null, this.props.children));
47
48
  }
48
49
  }]);
49
50
  return LegacyEditorContext;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePreset = usePreset;
7
+ var _react = require("react");
8
+ var _context = require("./presets/context");
9
+ /**
10
+ * Creates a preset.
11
+ *
12
+ * Takes an input function that returns a preset (and memoizes it) depending
13
+ * on the dependency array provided.
14
+ *
15
+ * Returns a pluginInjectionApi in order to apply actions and subscribe to plugin
16
+ * changes outside of the editor.
17
+ *
18
+ * @param createPreset
19
+ * @param dependencies
20
+ * @returns PresetAPI ({ pluginInjectionApi, preset, actionBuilder })
21
+ *
22
+ * Example:
23
+ * ```ts
24
+ * function ExampleEditor() {
25
+ * const { preset, editorApi } = usePreset(() =>
26
+ * new EditorPresetBuilder().add(plugin1).add(plugin2)
27
+ * , []);
28
+ *
29
+ * // Can execute typesafe commands based on plugin1 or 2
30
+ * const runCommand = () => editorApi.executeCommand(
31
+ * editorApi.dependencies.plugin1.commands.doSomething()
32
+ * )
33
+ * return (
34
+ * <>
35
+ * <Editor preset={preset} />
36
+ * <Button onClick={runCommand}>Run command</Button>
37
+ * </>
38
+ * )
39
+ * }
40
+ * ```
41
+ */
42
+ function usePreset(createPreset, dependencies) {
43
+ var editorApi = (0, _context.usePresetContext)();
44
+
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ var preset = (0, _react.useMemo)(createPreset, dependencies);
47
+ return {
48
+ editorApi: editorApi,
49
+ preset: preset
50
+ };
51
+ }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "187.23.2";
9
+ var version = "187.24.0";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.23.2",
3
+ "version": "187.24.0",
4
4
  "sideEffects": false
5
5
  }
@@ -86,7 +86,7 @@ export class ReactEditorView extends React.Component {
86
86
  return ((_this$props$editorPro3 = this.props.editorProps) === null || _this$props$editorPro3 === void 0 ? void 0 : (_this$props$editorPro4 = _this$props$editorPro3.performanceTracking) === null || _this$props$editorPro4 === void 0 ? void 0 : (_this$props$editorPro5 = _this$props$editorPro4.transactionTracking) === null || _this$props$editorPro5 === void 0 ? void 0 : _this$props$editorPro5.enabled) === false;
87
87
  }
88
88
  constructor(props, context) {
89
- var _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
89
+ var _props$setEditorApi, _props$editorProps, _props$editorProps$pe, _props$editorProps$pe2;
90
90
  super(props, context);
91
91
  _defineProperty(this, "editorRef", /*#__PURE__*/React.createRef());
92
92
  // ProseMirror is instantiated prior to the initial React render cycle,
@@ -532,6 +532,7 @@ export class ReactEditorView extends React.Component {
532
532
  getEditorState: this.getEditorState,
533
533
  getEditorView: this.getEditorView
534
534
  });
535
+ (_props$setEditorApi = props.setEditorApi) === null || _props$setEditorApi === void 0 ? void 0 : _props$setEditorApi.call(props, this.pluginInjectionAPI.api());
535
536
  this.eventDispatcher = new EventDispatcher();
536
537
  this.dispatch = createDispatch(this.eventDispatcher);
537
538
  this.errorReporter = createErrorReporter(props.editorProps.errorReporterHandler);
@@ -10,6 +10,7 @@ import { createFeatureFlagsFromProps } from '../create-editor/feature-flags-from
10
10
  import ReactEditorView from '../create-editor/ReactEditorViewNext';
11
11
  import { ContextAdapter } from '../nodeviews/context-adapter';
12
12
  import EditorContext from '../ui/EditorContext';
13
+ import { useSetPresetContext } from '../presets/context';
13
14
  import { RenderTracking } from '../utils/performance/components/RenderTracking';
14
15
  import useMeasureEditorMountTime from './hooks/useMeasureEditorMountTime';
15
16
  import useProviderFactory from './hooks/useProviderFactory';
@@ -51,6 +52,7 @@ export function EditorInternalWithoutHooks({
51
52
  }) {
52
53
  var _props$performanceTra, _props$performanceTra2, _props$performanceTra3, _props$performanceTra4;
53
54
  const Component = getUiComponent(props.appearance);
55
+ const setEditorApi = useSetPresetContext();
54
56
  const overriddenEditorProps = {
55
57
  ...props,
56
58
  onSave: props.onSave ? handleSave : undefined,
@@ -95,6 +97,7 @@ export function EditorInternalWithoutHooks({
95
97
  onEditorDestroyed: onEditorDestroyed,
96
98
  disabled: props.disabled,
97
99
  preset: preset,
100
+ setEditorApi: setEditorApi,
98
101
  render: ({
99
102
  editor,
100
103
  view,
@@ -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 { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
4
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
5
5
  export const toggleColor = color => (state, dispatch) => {
6
6
  const {
7
7
  textColor
@@ -22,7 +22,7 @@ export const toggleColor = color => (state, dispatch) => {
22
22
  color
23
23
  });
24
24
  state.tr.scrollIntoView();
25
- pluginCommandToPMCommand(toggleMark(textColor, {
25
+ editorCommandToPMCommand(toggleMark(textColor, {
26
26
  color
27
27
  }))(state, dispatch);
28
28
  }
@@ -0,0 +1,25 @@
1
+ import React, { useState, useContext } from 'react';
2
+ export const EditorAPIContext = /*#__PURE__*/React.createContext({});
3
+ export const PresetContextProvider = ({
4
+ children
5
+ }) => {
6
+ const [editorApi, setEditorApi] = useState();
7
+ return /*#__PURE__*/React.createElement(EditorAPIContext.Provider, {
8
+ value: {
9
+ editorApi,
10
+ setEditorApi
11
+ }
12
+ }, children);
13
+ };
14
+ export const usePresetContext = () => {
15
+ const {
16
+ editorApi
17
+ } = useContext(EditorAPIContext);
18
+ return editorApi;
19
+ };
20
+ export const useSetPresetContext = () => {
21
+ const {
22
+ setEditorApi
23
+ } = useContext(EditorAPIContext);
24
+ return setEditorApi;
25
+ };
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.23.2";
2
+ export const version = "187.24.0";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.23.2",
3
+ "version": "187.24.0",
4
4
  "sideEffects": false
5
5
  }
@@ -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,
@@ -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 { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
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
- pluginCommandToPMCommand(toggleMark(textColor, {
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
+ }
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "187.23.2";
2
+ export var version = "187.24.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.23.2",
3
+ "version": "187.24.0",
4
4
  "sideEffects": false
5
5
  }
@@ -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").ToggleMarkPluginCommand;
267
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
268
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
269
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
270
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
271
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
272
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
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").ToggleMarkPluginCommand;
307
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
308
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
309
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
310
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
311
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
312
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
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").ToggleMarkPluginCommand;
638
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
639
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
640
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
641
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
642
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
643
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
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").ToggleMarkPluginCommand;
678
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
679
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
680
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
681
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
682
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
683
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
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 { PluginCommand } from '@atlaskit/editor-common/types';
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) => PluginCommand;
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, PluginCommand } from '@atlaskit/editor-common/types';
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) => PluginCommand;
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;
@@ -1,4 +1,4 @@
1
- import { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
3
3
  type Config = {
4
4
  takeFullWidth: boolean;
@@ -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 {};
@@ -0,0 +1,48 @@
1
+ import type { DependencyList } from 'react';
2
+ import type { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
3
+ import type { AllEditorPresetPluginTypes, PublicPluginAPI, NextEditorPlugin } from '@atlaskit/editor-common/types';
4
+ type ExtractNextEditorPlugins<Plugins extends AllEditorPresetPluginTypes[]> = {
5
+ [PluginNumber in keyof Plugins]: Plugins[PluginNumber] extends NextEditorPlugin<infer Name, infer Metadata> ? NextEditorPlugin<Name, Metadata> : Plugins[PluginNumber] extends [
6
+ NextEditorPlugin<infer Name, infer Metadata>,
7
+ any
8
+ ] ? NextEditorPlugin<Name, Metadata> : never;
9
+ };
10
+ interface PresetAPI<PluginNames extends string[] = [], StackPlugins extends AllEditorPresetPluginTypes[] = []> {
11
+ editorApi: PublicPluginAPI<ExtractNextEditorPlugins<StackPlugins>> | undefined;
12
+ preset: EditorPresetBuilder<PluginNames, StackPlugins>;
13
+ }
14
+ /**
15
+ * Creates a preset.
16
+ *
17
+ * Takes an input function that returns a preset (and memoizes it) depending
18
+ * on the dependency array provided.
19
+ *
20
+ * Returns a pluginInjectionApi in order to apply actions and subscribe to plugin
21
+ * changes outside of the editor.
22
+ *
23
+ * @param createPreset
24
+ * @param dependencies
25
+ * @returns PresetAPI ({ pluginInjectionApi, preset, actionBuilder })
26
+ *
27
+ * Example:
28
+ * ```ts
29
+ * function ExampleEditor() {
30
+ * const { preset, editorApi } = usePreset(() =>
31
+ * new EditorPresetBuilder().add(plugin1).add(plugin2)
32
+ * , []);
33
+ *
34
+ * // Can execute typesafe commands based on plugin1 or 2
35
+ * const runCommand = () => editorApi.executeCommand(
36
+ * editorApi.dependencies.plugin1.commands.doSomething()
37
+ * )
38
+ * return (
39
+ * <>
40
+ * <Editor preset={preset} />
41
+ * <Button onClick={runCommand}>Run command</Button>
42
+ * </>
43
+ * )
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function usePreset<PluginNames extends string[] = [], StackPlugins extends AllEditorPresetPluginTypes[] = []>(createPreset: () => EditorPresetBuilder<PluginNames, StackPlugins>, dependencies: DependencyList): PresetAPI<PluginNames, StackPlugins>;
48
+ export {};
@@ -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;
@@ -320,13 +320,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
320
320
  }>>
321
321
  ];
322
322
  commands: {
323
- toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
324
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
325
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
326
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
327
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
328
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
329
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
323
+ toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
324
+ toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
325
+ toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
326
+ toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
327
+ toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
328
+ toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
329
+ toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
330
330
  };
331
331
  }> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"textFormatting", {
332
332
  pluginConfiguration: TextFormattingOptions | undefined;
@@ -366,13 +366,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
366
366
  }>>
367
367
  ];
368
368
  commands: {
369
- toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
370
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
371
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
372
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
373
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
374
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
375
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
369
+ toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
370
+ toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
371
+ toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
372
+ toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
373
+ toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
374
+ toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
375
+ toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
376
376
  };
377
377
  }>,
378
378
  (config?: HyperlinkPluginOptions | undefined, api?: import("@atlaskit/editor-common/types").PluginInjectionAPI<"hyperlink", {
@@ -771,13 +771,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
771
771
  }>>
772
772
  ];
773
773
  commands: {
774
- toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
775
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
776
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
777
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
778
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
779
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
780
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
774
+ toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
775
+ toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
776
+ toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
777
+ toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
778
+ toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
779
+ toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
780
+ toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
781
781
  };
782
782
  }> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"textFormatting", {
783
783
  pluginConfiguration: TextFormattingOptions | undefined;
@@ -817,13 +817,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
817
817
  }>>
818
818
  ];
819
819
  commands: {
820
- toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
821
- toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
822
- toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
823
- toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
824
- toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
825
- toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
826
- toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkPluginCommand;
820
+ toggleSuperscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
821
+ toggleSubscript: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
822
+ toggleStrike: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
823
+ toggleCode: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
824
+ toggleUnderline: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
825
+ toggleEm: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
826
+ toggleStrong: import("@atlaskit/editor-plugin-text-formatting").ToggleMarkEditorCommand;
827
827
  };
828
828
  }>,
829
829
  (config?: HyperlinkPluginOptions | undefined, api?: import("@atlaskit/editor-common/types").PluginInjectionAPI<"hyperlink", {
@@ -1,4 +1,4 @@
1
1
  import type { EmojiId } from '@atlaskit/emoji';
2
- import type { PluginCommand } from '@atlaskit/editor-common/types';
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) => PluginCommand;
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, PluginCommand } from '@atlaskit/editor-common/types';
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';
@@ -20,7 +20,7 @@ export type EmojiPlugin = NextEditorPlugin<'emoji', {
20
20
  ];
21
21
  sharedState: EmojiPluginState | undefined;
22
22
  commands: {
23
- insertEmoji: (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => PluginCommand;
23
+ insertEmoji: (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => EditorCommand;
24
24
  };
25
25
  }>;
26
26
  export declare const emojiPlugin: EmojiPlugin;
@@ -1,4 +1,4 @@
1
- import { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
3
3
  type Config = {
4
4
  takeFullWidth: boolean;
@@ -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 {};
@@ -0,0 +1,52 @@
1
+ import type { DependencyList } from 'react';
2
+ import type { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
3
+ import type { AllEditorPresetPluginTypes, PublicPluginAPI, NextEditorPlugin } from '@atlaskit/editor-common/types';
4
+ type ExtractNextEditorPlugins<Plugins extends AllEditorPresetPluginTypes[]> = {
5
+ [PluginNumber in keyof Plugins]: Plugins[PluginNumber] extends NextEditorPlugin<infer Name, infer Metadata> ? NextEditorPlugin<Name, Metadata> : Plugins[PluginNumber] extends [
6
+ NextEditorPlugin<infer Name, infer Metadata>,
7
+ any
8
+ ] ? NextEditorPlugin<Name, Metadata> : never;
9
+ };
10
+ interface PresetAPI<PluginNames extends string[] = [
11
+ ], StackPlugins extends AllEditorPresetPluginTypes[] = [
12
+ ]> {
13
+ editorApi: PublicPluginAPI<ExtractNextEditorPlugins<StackPlugins>> | undefined;
14
+ preset: EditorPresetBuilder<PluginNames, StackPlugins>;
15
+ }
16
+ /**
17
+ * Creates a preset.
18
+ *
19
+ * Takes an input function that returns a preset (and memoizes it) depending
20
+ * on the dependency array provided.
21
+ *
22
+ * Returns a pluginInjectionApi in order to apply actions and subscribe to plugin
23
+ * changes outside of the editor.
24
+ *
25
+ * @param createPreset
26
+ * @param dependencies
27
+ * @returns PresetAPI ({ pluginInjectionApi, preset, actionBuilder })
28
+ *
29
+ * Example:
30
+ * ```ts
31
+ * function ExampleEditor() {
32
+ * const { preset, editorApi } = usePreset(() =>
33
+ * new EditorPresetBuilder().add(plugin1).add(plugin2)
34
+ * , []);
35
+ *
36
+ * // Can execute typesafe commands based on plugin1 or 2
37
+ * const runCommand = () => editorApi.executeCommand(
38
+ * editorApi.dependencies.plugin1.commands.doSomething()
39
+ * )
40
+ * return (
41
+ * <>
42
+ * <Editor preset={preset} />
43
+ * <Button onClick={runCommand}>Run command</Button>
44
+ * </>
45
+ * )
46
+ * }
47
+ * ```
48
+ */
49
+ export declare function usePreset<PluginNames extends string[] = [
50
+ ], StackPlugins extends AllEditorPresetPluginTypes[] = [
51
+ ]>(createPreset: () => EditorPresetBuilder<PluginNames, StackPlugins>, dependencies: DependencyList): PresetAPI<PluginNames, StackPlugins>;
52
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.23.2",
3
+ "version": "187.24.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -55,7 +55,7 @@
55
55
  "@atlaskit/code": "^14.6.0",
56
56
  "@atlaskit/date": "^0.10.0",
57
57
  "@atlaskit/datetime-picker": "^12.7.0",
58
- "@atlaskit/editor-common": "^74.45.0",
58
+ "@atlaskit/editor-common": "^74.46.0",
59
59
  "@atlaskit/editor-json-transformer": "^8.10.0",
60
60
  "@atlaskit/editor-markdown-transformer": "^5.2.5",
61
61
  "@atlaskit/editor-palette": "1.5.1",
@@ -72,7 +72,7 @@
72
72
  "@atlaskit/editor-plugin-guideline": "^0.3.4",
73
73
  "@atlaskit/editor-plugin-hyperlink": "^0.3.0",
74
74
  "@atlaskit/editor-plugin-image-upload": "^0.1.0",
75
- "@atlaskit/editor-plugin-table": "^2.8.0",
75
+ "@atlaskit/editor-plugin-table": "^2.9.0",
76
76
  "@atlaskit/editor-plugin-text-formatting": "^0.2.0",
77
77
  "@atlaskit/editor-plugin-width": "^0.1.0",
78
78
  "@atlaskit/editor-prosemirror": "1.1.0",
@@ -146,7 +146,7 @@
146
146
  "@atlaskit/collab-provider": "9.10.1",
147
147
  "@atlaskit/dropdown-menu": "^11.11.0",
148
148
  "@atlaskit/editor-extension-dropbox": "^0.4.0",
149
- "@atlaskit/editor-plugin-table": "^2.8.0",
149
+ "@atlaskit/editor-plugin-table": "^2.9.0",
150
150
  "@atlaskit/editor-test-helpers": "^18.11.0",
151
151
  "@atlaskit/flag": "^15.2.0",
152
152
  "@atlaskit/icon-object": "^6.3.0",
package/report.api.md CHANGED
@@ -130,6 +130,7 @@ import { PresenceResource } from '@atlaskit/mention/resource';
130
130
  import PropTypes from 'prop-types';
131
131
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
132
132
  import type { Providers } from '@atlaskit/editor-common/provider-factory';
133
+ import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
133
134
  import { PureComponent } from 'react';
134
135
  import { QuickInsertActionInsert } from '@atlaskit/editor-common/provider-factory';
135
136
  import { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
@@ -974,6 +975,8 @@ interface EditorViewProps {
974
975
  dispatchAnalyticsEvent: DispatchAnalyticsEvent;
975
976
  editorRef: React_2.RefObject<HTMLDivElement>;
976
977
  }) => JSX.Element;
978
+ // (undocumented)
979
+ setEditorApi?: SetEditorAPI;
977
980
  }
978
981
 
979
982
  // @public (undocumented)
@@ -1957,6 +1960,9 @@ export function setBlockTypeWithAnalytics(
1957
1960
  editorAnalyticsApi: EditorAnalyticsAPI | undefined,
1958
1961
  ): Command_2;
1959
1962
 
1963
+ // @public (undocumented)
1964
+ type SetEditorAPI = (editorApi: PublicPluginAPI<any>) => void;
1965
+
1960
1966
  // @public (undocumented)
1961
1967
  export const setIsExpanded: (isExpanded: boolean) => Command_2;
1962
1968
 
@@ -119,6 +119,7 @@ import { PresenceResource } from '@atlaskit/mention/resource';
119
119
  import PropTypes from 'prop-types';
120
120
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
121
121
  import type { Providers } from '@atlaskit/editor-common/provider-factory';
122
+ import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
122
123
  import { PureComponent } from 'react';
123
124
  import { QuickInsertActionInsert } from '@atlaskit/editor-common/provider-factory';
124
125
  import { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
@@ -898,6 +899,8 @@ interface EditorViewProps {
898
899
  dispatchAnalyticsEvent: DispatchAnalyticsEvent;
899
900
  editorRef: React_2.RefObject<HTMLDivElement>;
900
901
  }) => JSX.Element;
902
+ // (undocumented)
903
+ setEditorApi?: SetEditorAPI;
901
904
  }
902
905
 
903
906
  // @public (undocumented)
@@ -1737,6 +1740,9 @@ export function setBlockType(name: string): Command_2;
1737
1740
  // @public (undocumented)
1738
1741
  export function setBlockTypeWithAnalytics(name: string, inputMethod: BlockTypeInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command_2;
1739
1742
 
1743
+ // @public (undocumented)
1744
+ type SetEditorAPI = (editorApi: PublicPluginAPI<any>) => void;
1745
+
1740
1746
  // @public (undocumented)
1741
1747
  export const setIsExpanded: (isExpanded: boolean) => Command_2;
1742
1748
 
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-core/use-preset",
3
+ "main": "../dist/cjs/use-preset.js",
4
+ "module": "../dist/esm/use-preset.js",
5
+ "module:es2019": "../dist/es2019/use-preset.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/use-preset.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <4.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/use-preset.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }