@atlaskit/editor-core 193.16.0 → 193.17.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 193.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#98727](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98727)
8
+ [`057b3d93e3d4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/057b3d93e3d4) -
9
+ The `usePreset` hook from editor-core previously required the EditorContext in order to have a
10
+ valid editorApi as a return value (otherwise it is undefined). This is confusing to developers
11
+ so this improvement allows the API value to be resolved without EditorContext - simplifying what
12
+ is required to setup the editor.
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 193.16.0
4
19
 
5
20
  ### Minor Changes
@@ -43,17 +43,12 @@ var EditorInternal = exports.EditorInternal = /*#__PURE__*/(0, _react.memo)(func
43
43
  onEditorDestroyed = _ref.onEditorDestroyed,
44
44
  preset = _ref.preset;
45
45
  var Component = (0, _createEditor.getUiComponent)(props.appearance);
46
- var _setInternalEditorApi = (0, _context.useSetPresetContext)();
47
46
  var setEditorApi = (0, _react.useCallback)(function (api) {
48
- if (_setInternalEditorApi) {
49
- _setInternalEditorApi(api);
50
- }
51
-
52
47
  // This is an workaround to unblock Editor Lego Decoupling project, if you have questions ping us #cc-editor-lego
53
48
  // We may clean up this code when EditorActions deprecation process starts
54
49
  // @ts-expect-error 2339: Property '__EDITOR_INTERNALS_DO_NOT_USE__API' does not exist on type 'EditorActions<any>'.
55
50
  editorActions.__EDITOR_INTERNALS_DO_NOT_USE__API = api;
56
- }, [_setInternalEditorApi, editorActions]);
51
+ }, [editorActions]);
57
52
  var overriddenEditorProps = _objectSpread(_objectSpread({}, props), {}, {
58
53
  onSave: props.onSave ? handleSave : undefined,
59
54
  // noop all analytic events, even if a handler is still passed.
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.usePreset = usePreset;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
7
9
  var _react = require("react");
8
10
  var _preset = require("@atlaskit/editor-common/preset");
9
- var _context = require("./presets/context");
10
11
  /**
11
12
  * Creates a preset.
12
13
  *
@@ -23,8 +24,8 @@ var _context = require("./presets/context");
23
24
  * Example:
24
25
  * ```ts
25
26
  * function ExampleEditor() {
26
- * const { preset, editorApi } = usePreset(() =>
27
- * new EditorPresetBuilder().add(plugin1).add(plugin2)
27
+ * const { preset, editorApi } = usePreset((builder) =>
28
+ * builder.add(plugin1).add(plugin2)
28
29
  * , []);
29
30
  *
30
31
  * // Can execute typesafe commands based on plugin1 or 2
@@ -42,12 +43,20 @@ var _context = require("./presets/context");
42
43
  */
43
44
  function usePreset(createPreset) {
44
45
  var dependencies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
45
- var editorApi = (0, _context.usePresetContext)();
46
+ var _useState = (0, _react.useState)(undefined),
47
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
48
+ editorApi = _useState2[0],
49
+ setAPI = _useState2[1];
46
50
  var preset = (0, _react.useMemo)(function () {
47
51
  return createPreset(new _preset.EditorPresetBuilder());
48
52
  },
49
53
  // eslint-disable-next-line react-hooks/exhaustive-deps
50
54
  dependencies);
55
+ (0, _react.useLayoutEffect)(function () {
56
+ preset.apiPromise.then(function (api) {
57
+ setAPI(api);
58
+ });
59
+ }, [preset.apiPromise]);
51
60
  return {
52
61
  editorApi: editorApi,
53
62
  preset: preset
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "193.16.0";
8
+ var version = exports.version = "193.17.0";
@@ -34,17 +34,12 @@ export const EditorInternal = /*#__PURE__*/memo(({
34
34
  }) => {
35
35
  var _props$performanceTra, _props$performanceTra2, _props$performanceTra3, _props$performanceTra4;
36
36
  const Component = getUiComponent(props.appearance);
37
- const _setInternalEditorApi = useSetPresetContext();
38
37
  const setEditorApi = useCallback(api => {
39
- if (_setInternalEditorApi) {
40
- _setInternalEditorApi(api);
41
- }
42
-
43
38
  // This is an workaround to unblock Editor Lego Decoupling project, if you have questions ping us #cc-editor-lego
44
39
  // We may clean up this code when EditorActions deprecation process starts
45
40
  // @ts-expect-error 2339: Property '__EDITOR_INTERNALS_DO_NOT_USE__API' does not exist on type 'EditorActions<any>'.
46
41
  editorActions.__EDITOR_INTERNALS_DO_NOT_USE__API = api;
47
- }, [_setInternalEditorApi, editorActions]);
42
+ }, [editorActions]);
48
43
  const overriddenEditorProps = {
49
44
  ...props,
50
45
  onSave: props.onSave ? handleSave : undefined,
@@ -1,6 +1,5 @@
1
- import { useMemo } from 'react';
1
+ import { useLayoutEffect, useMemo, useState } from 'react';
2
2
  import { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
3
- import { usePresetContext } from './presets/context';
4
3
  /**
5
4
  * Creates a preset.
6
5
  *
@@ -17,8 +16,8 @@ import { usePresetContext } from './presets/context';
17
16
  * Example:
18
17
  * ```ts
19
18
  * function ExampleEditor() {
20
- * const { preset, editorApi } = usePreset(() =>
21
- * new EditorPresetBuilder().add(plugin1).add(plugin2)
19
+ * const { preset, editorApi } = usePreset((builder) =>
20
+ * builder.add(plugin1).add(plugin2)
22
21
  * , []);
23
22
  *
24
23
  * // Can execute typesafe commands based on plugin1 or 2
@@ -35,10 +34,15 @@ import { usePresetContext } from './presets/context';
35
34
  * ```
36
35
  */
37
36
  export function usePreset(createPreset, dependencies = []) {
38
- const editorApi = usePresetContext();
37
+ const [editorApi, setAPI] = useState(undefined);
39
38
  const preset = useMemo(() => createPreset(new EditorPresetBuilder()),
40
39
  // eslint-disable-next-line react-hooks/exhaustive-deps
41
40
  dependencies);
41
+ useLayoutEffect(() => {
42
+ preset.apiPromise.then(api => {
43
+ setAPI(api);
44
+ });
45
+ }, [preset.apiPromise]);
42
46
  return {
43
47
  editorApi,
44
48
  preset
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "193.16.0";
2
+ export const version = "193.17.0";
@@ -37,17 +37,12 @@ export var EditorInternal = /*#__PURE__*/memo(function (_ref) {
37
37
  onEditorDestroyed = _ref.onEditorDestroyed,
38
38
  preset = _ref.preset;
39
39
  var Component = getUiComponent(props.appearance);
40
- var _setInternalEditorApi = useSetPresetContext();
41
40
  var setEditorApi = useCallback(function (api) {
42
- if (_setInternalEditorApi) {
43
- _setInternalEditorApi(api);
44
- }
45
-
46
41
  // This is an workaround to unblock Editor Lego Decoupling project, if you have questions ping us #cc-editor-lego
47
42
  // We may clean up this code when EditorActions deprecation process starts
48
43
  // @ts-expect-error 2339: Property '__EDITOR_INTERNALS_DO_NOT_USE__API' does not exist on type 'EditorActions<any>'.
49
44
  editorActions.__EDITOR_INTERNALS_DO_NOT_USE__API = api;
50
- }, [_setInternalEditorApi, editorActions]);
45
+ }, [editorActions]);
51
46
  var overriddenEditorProps = _objectSpread(_objectSpread({}, props), {}, {
52
47
  onSave: props.onSave ? handleSave : undefined,
53
48
  // noop all analytic events, even if a handler is still passed.
@@ -1,6 +1,6 @@
1
- import { useMemo } from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useLayoutEffect, useMemo, useState } from 'react';
2
3
  import { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
3
- import { usePresetContext } from './presets/context';
4
4
  /**
5
5
  * Creates a preset.
6
6
  *
@@ -17,8 +17,8 @@ import { usePresetContext } from './presets/context';
17
17
  * Example:
18
18
  * ```ts
19
19
  * function ExampleEditor() {
20
- * const { preset, editorApi } = usePreset(() =>
21
- * new EditorPresetBuilder().add(plugin1).add(plugin2)
20
+ * const { preset, editorApi } = usePreset((builder) =>
21
+ * builder.add(plugin1).add(plugin2)
22
22
  * , []);
23
23
  *
24
24
  * // Can execute typesafe commands based on plugin1 or 2
@@ -36,12 +36,20 @@ import { usePresetContext } from './presets/context';
36
36
  */
37
37
  export function usePreset(createPreset) {
38
38
  var dependencies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
39
- var editorApi = usePresetContext();
39
+ var _useState = useState(undefined),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ editorApi = _useState2[0],
42
+ setAPI = _useState2[1];
40
43
  var preset = useMemo(function () {
41
44
  return createPreset(new EditorPresetBuilder());
42
45
  },
43
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
44
47
  dependencies);
48
+ useLayoutEffect(function () {
49
+ preset.apiPromise.then(function (api) {
50
+ setAPI(api);
51
+ });
52
+ }, [preset.apiPromise]);
45
53
  return {
46
54
  editorApi: editorApi,
47
55
  preset: preset
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "193.16.0";
2
+ export var version = "193.17.0";
@@ -22,7 +22,9 @@ import type { EditorAppearance, EditorConfig, EditorPlugin, EditorProps, EditorR
22
22
  import type { EditorNextProps } from '../types/editor-props';
23
23
  import { TransactionTracker } from '../utils/performance/track-transactions';
24
24
  export interface EditorViewProps {
25
- editorProps: EditorProps | EditorNextProps;
25
+ editorProps: (EditorProps | EditorNextProps) & {
26
+ preset?: EditorNextProps['preset'];
27
+ };
26
28
  createAnalyticsEvent?: CreateUIAnalyticsEvent;
27
29
  providerFactory: ProviderFactory;
28
30
  portalProviderAPI: LegacyPortalProviderAPI | PortalProviderAPI;
@@ -21,8 +21,8 @@ interface PresetAPI<PluginNames extends string[] = [], StackPlugins extends AllE
21
21
  * Example:
22
22
  * ```ts
23
23
  * function ExampleEditor() {
24
- * const { preset, editorApi } = usePreset(() =>
25
- * new EditorPresetBuilder().add(plugin1).add(plugin2)
24
+ * const { preset, editorApi } = usePreset((builder) =>
25
+ * builder.add(plugin1).add(plugin2)
26
26
  * , []);
27
27
  *
28
28
  * // Can execute typesafe commands based on plugin1 or 2
@@ -22,7 +22,9 @@ import type { EditorAppearance, EditorConfig, EditorPlugin, EditorProps, EditorR
22
22
  import type { EditorNextProps } from '../types/editor-props';
23
23
  import { TransactionTracker } from '../utils/performance/track-transactions';
24
24
  export interface EditorViewProps {
25
- editorProps: EditorProps | EditorNextProps;
25
+ editorProps: (EditorProps | EditorNextProps) & {
26
+ preset?: EditorNextProps['preset'];
27
+ };
26
28
  createAnalyticsEvent?: CreateUIAnalyticsEvent;
27
29
  providerFactory: ProviderFactory;
28
30
  portalProviderAPI: LegacyPortalProviderAPI | PortalProviderAPI;
@@ -23,8 +23,8 @@ interface PresetAPI<PluginNames extends string[] = [
23
23
  * Example:
24
24
  * ```ts
25
25
  * function ExampleEditor() {
26
- * const { preset, editorApi } = usePreset(() =>
27
- * new EditorPresetBuilder().add(plugin1).add(plugin2)
26
+ * const { preset, editorApi } = usePreset((builder) =>
27
+ * builder.add(plugin1).add(plugin2)
28
28
  * , []);
29
29
  *
30
30
  * // Can execute typesafe commands based on plugin1 or 2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "193.16.0",
3
+ "version": "193.17.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -45,7 +45,7 @@
45
45
  "@atlaskit/analytics-next": "^9.3.0",
46
46
  "@atlaskit/analytics-next-stable-react-context": "1.0.1",
47
47
  "@atlaskit/button": "^17.14.0",
48
- "@atlaskit/editor-common": "^79.5.0",
48
+ "@atlaskit/editor-common": "^79.6.0",
49
49
  "@atlaskit/editor-json-transformer": "^8.12.0",
50
50
  "@atlaskit/editor-plugins": "^2.5.0",
51
51
  "@atlaskit/editor-prosemirror": "4.0.1",