@atlaskit/editor-core 187.23.1 → 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 (73) hide show
  1. package/CHANGELOG.md +17 -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/block-type/index.js +3 -6
  5. package/dist/cjs/plugins/block-type/pm-plugins/keymap.js +12 -12
  6. package/dist/cjs/plugins/caption/pm-plugins/keymap.js +9 -12
  7. package/dist/cjs/plugins/help-dialog/index.js +3 -6
  8. package/dist/cjs/plugins/media/pm-plugins/alt-text/keymap.js +3 -6
  9. package/dist/cjs/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +4 -6
  10. package/dist/cjs/plugins/media/pm-plugins/keymap.js +8 -11
  11. package/dist/cjs/plugins/media/pm-plugins/linking/keymap.js +2 -5
  12. package/dist/cjs/plugins/status/keymap.js +3 -6
  13. package/dist/cjs/plugins/submit-editor/index.js +3 -6
  14. package/dist/cjs/plugins/text-color/commands/toggle-color.js +1 -1
  15. package/dist/cjs/presets/context.js +40 -0
  16. package/dist/cjs/ui/EditorContext/index.js +2 -1
  17. package/dist/cjs/use-preset.js +51 -0
  18. package/dist/cjs/version-wrapper.js +1 -1
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/create-editor/ReactEditorViewInternal.js +2 -1
  21. package/dist/es2019/editor-next/editor-internal.js +3 -0
  22. package/dist/es2019/plugins/block-type/index.js +3 -3
  23. package/dist/es2019/plugins/block-type/pm-plugins/keymap.js +11 -12
  24. package/dist/es2019/plugins/caption/pm-plugins/keymap.js +9 -9
  25. package/dist/es2019/plugins/help-dialog/index.js +2 -3
  26. package/dist/es2019/plugins/media/pm-plugins/alt-text/keymap.js +3 -3
  27. package/dist/es2019/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +2 -2
  28. package/dist/es2019/plugins/media/pm-plugins/keymap.js +8 -8
  29. package/dist/es2019/plugins/media/pm-plugins/linking/keymap.js +2 -2
  30. package/dist/es2019/plugins/status/keymap.js +3 -3
  31. package/dist/es2019/plugins/submit-editor/index.js +3 -3
  32. package/dist/es2019/plugins/text-color/commands/toggle-color.js +2 -2
  33. package/dist/es2019/presets/context.js +25 -0
  34. package/dist/es2019/ui/EditorContext/index.js +2 -1
  35. package/dist/es2019/use-preset.js +45 -0
  36. package/dist/es2019/version-wrapper.js +1 -1
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/create-editor/ReactEditorViewInternal.js +2 -1
  39. package/dist/esm/editor-next/editor-internal.js +3 -0
  40. package/dist/esm/plugins/block-type/index.js +3 -3
  41. package/dist/esm/plugins/block-type/pm-plugins/keymap.js +11 -12
  42. package/dist/esm/plugins/caption/pm-plugins/keymap.js +9 -9
  43. package/dist/esm/plugins/help-dialog/index.js +2 -3
  44. package/dist/esm/plugins/media/pm-plugins/alt-text/keymap.js +3 -3
  45. package/dist/esm/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +2 -2
  46. package/dist/esm/plugins/media/pm-plugins/keymap.js +8 -8
  47. package/dist/esm/plugins/media/pm-plugins/linking/keymap.js +2 -2
  48. package/dist/esm/plugins/status/keymap.js +3 -3
  49. package/dist/esm/plugins/submit-editor/index.js +3 -3
  50. package/dist/esm/plugins/text-color/commands/toggle-color.js +2 -2
  51. package/dist/esm/presets/context.js +26 -0
  52. package/dist/esm/ui/EditorContext/index.js +2 -1
  53. package/dist/esm/use-preset.js +45 -0
  54. package/dist/esm/version-wrapper.js +1 -1
  55. package/dist/esm/version.json +1 -1
  56. package/dist/types/create-editor/ReactEditorViewInternal.d.ts +2 -0
  57. package/dist/types/labs/next/presets/default.d.ts +28 -28
  58. package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  59. package/dist/types/plugins/emoji/index.d.ts +2 -2
  60. package/dist/types/plugins/find-replace/index.d.ts +1 -1
  61. package/dist/types/presets/context.d.ts +15 -0
  62. package/dist/types/use-preset.d.ts +48 -0
  63. package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +2 -0
  64. package/dist/types-ts4.5/labs/next/presets/default.d.ts +28 -28
  65. package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  66. package/dist/types-ts4.5/plugins/emoji/index.d.ts +2 -2
  67. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +1 -1
  68. package/dist/types-ts4.5/presets/context.d.ts +15 -0
  69. package/dist/types-ts4.5/use-preset.d.ts +52 -0
  70. package/package.json +4 -4
  71. package/report.api.md +6 -0
  72. package/tmp/api-report-tmp.d.ts +6 -0
  73. package/use-preset/package.json +15 -0
@@ -1,14 +1,14 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
3
- import * as keymaps from '../../keymaps';
4
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '../../plugins/analytics';
3
+ import { submit } from '@atlaskit/editor-common/keymaps';
4
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
5
  import { stateKey as mediaPluginKey } from '../../plugins/media/pm-plugins/plugin-key';
6
6
  import { analyticsEventKey } from '../analytics/consts';
7
7
  export function createPlugin(eventDispatch, onSave) {
8
8
  if (!onSave) {
9
9
  return;
10
10
  }
11
- return keymap(_defineProperty({}, "".concat(keymaps.submit.common), function _(state, _dispatch, editorView) {
11
+ return keymap(_defineProperty({}, "".concat(submit.common), function _(state, _dispatch, editorView) {
12
12
  var mediaState = mediaPluginKey.getState(state);
13
13
  if (mediaState && mediaState.waitForMediaUpload && !mediaState.allUploadsFinished) {
14
14
  return true;
@@ -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.1";
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.1",
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.1",
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