@atlaskit/editor-common 94.20.0 → 94.22.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,34 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 94.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#163532](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/163532)
8
+ [`b80779d45e179`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b80779d45e179) -
9
+ moved processRawFragmentValue to editor-common
10
+ - [#165273](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165273)
11
+ [`665190aa04bde`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/665190aa04bde) -
12
+ Fix setting up editorApi with usePreset for react strict mode by adding new apiResolver for
13
+ preset.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
19
+ ## 94.21.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [#162829](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162829)
24
+ [`5bf267e7de21e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5bf267e7de21e) -
25
+ Introduce new usePluginStateEffect which can be used to run effects on plugin state change
26
+ (similar to useSharedPluginState but without re-renders)
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies
31
+
3
32
  ## 94.20.0
4
33
 
5
34
  ### Minor Changes
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.usePluginStateEffect = usePluginStateEffect;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = require("react");
11
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ /**
15
+ *
16
+ * Directly map object values
17
+ *
18
+ * @param object The object to transform
19
+ * @param mapFunction The function to map an old value to new one
20
+ * @returns Object with the same key but transformed values
21
+ *
22
+ */
23
+ function mapValues(object, mapFunction) {
24
+ return Object.entries(object).reduce(function (acc, _ref) {
25
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
26
+ key = _ref2[0],
27
+ value = _ref2[1];
28
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, key, mapFunction(value)));
29
+ }, {});
30
+ }
31
+
32
+ // When we use the `useSharedPluginState` example: `useSharedPluginState(api, ['width'])`
33
+ // it will re-render every time the component re-renders as the array "['width']" is seen as an update.
34
+ // This hook is used to prevent re-renders due to this.
35
+ function useStaticPlugins(plugins) {
36
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ return (0, _react.useMemo)(function () {
38
+ return plugins;
39
+ }, []);
40
+ }
41
+ /**
42
+ *
43
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
44
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
45
+ * your React Component will get only the last one.
46
+ *
47
+ * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this
48
+ * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called
49
+ * on initialisation and when the state changes (with the latest callback we are provided).
50
+ *
51
+ * Example in plugin:
52
+ *
53
+ * ```typescript
54
+ * function ExampleContent({ api }: Props) {
55
+ * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => {
56
+ * // Use as necessary ie. fire analytics or network requests
57
+ * console.log(dogState, exampleState)
58
+ * }, [])
59
+ * usePluginStateEffect(
60
+ * api,
61
+ * ['dog', 'example'],
62
+ * pluginStateCallback
63
+ * )
64
+ * return <p>Content</p>
65
+ * }
66
+ *
67
+ * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
68
+ * return {
69
+ * name: 'example',
70
+ * contentComponent: () =>
71
+ * <ExampleContent
72
+ * api={api}
73
+ * />
74
+ * }
75
+ * }
76
+ * ```
77
+ *
78
+ * @param injectionApi Plugin injection API from `NextEditorPlugin`
79
+ * @param plugins Plugin names to get the shared plugin state for
80
+ * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended,
81
+ * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed.
82
+ * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`,
83
+ * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes.
84
+ */
85
+ function usePluginStateEffect(injectionApi, plugins, effect) {
86
+ var pluginNames = useStaticPlugins(plugins);
87
+
88
+ // Create a memoized object containing the named plugins
89
+ var namedExternalPlugins = (0, _react.useMemo)(function () {
90
+ return pluginNames.reduce(function (acc, pluginName) {
91
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, "".concat(String(pluginName), "State"), injectionApi === null || injectionApi === void 0 ? void 0 : injectionApi[pluginName]));
92
+ }, {});
93
+ }, [injectionApi, pluginNames]);
94
+ usePluginStateEffectInternal(namedExternalPlugins, effect);
95
+ }
96
+ function usePluginStateEffectInternal(externalPlugins, effect) {
97
+ var refStates = (0, _react.useRef)();
98
+ var cleanup = (0, _react.useRef)();
99
+ var latestEffect = (0, _react.useRef)(effect);
100
+
101
+ // We should store the latest effect in a reference so it is more intuitive to the user
102
+ // and we are not causing a memory leak by having references to old state.
103
+ (0, _react.useEffect)(function () {
104
+ latestEffect.current = (0, _debounce.default)(effect);
105
+ return function () {
106
+ latestEffect.current = undefined;
107
+ };
108
+ }, [effect]);
109
+ (0, _react.useLayoutEffect)(function () {
110
+ var _latestEffect$current;
111
+ // Update the reference for this plugin and activate the effect
112
+ refStates.current = mapValues(externalPlugins, function (value) {
113
+ return value === null || value === void 0 ? void 0 : value.sharedState.currentState();
114
+ });
115
+ cleanup.current = (_latestEffect$current = latestEffect.current) === null || _latestEffect$current === void 0 ? void 0 : _latestEffect$current.call(latestEffect, refStates.current);
116
+ var unsubs = Object.entries(externalPlugins).map(function (_ref3) {
117
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
118
+ pluginKey = _ref4[0],
119
+ externalPlugin = _ref4[1];
120
+ return externalPlugin === null || externalPlugin === void 0 ? void 0 : externalPlugin.sharedState.onChange(function (_ref5) {
121
+ var nextSharedState = _ref5.nextSharedState,
122
+ prevSharedState = _ref5.prevSharedState;
123
+ if (prevSharedState !== nextSharedState && refStates.current) {
124
+ var _latestEffect$current2;
125
+ // Update the reference for this plugin and activate the effect
126
+ refStates.current[pluginKey] = nextSharedState;
127
+ cleanup.current = (_latestEffect$current2 = latestEffect.current) === null || _latestEffect$current2 === void 0 ? void 0 : _latestEffect$current2.call(latestEffect, refStates.current);
128
+ }
129
+ });
130
+ });
131
+ return function () {
132
+ var _cleanup$current;
133
+ refStates.current = undefined;
134
+ unsubs.forEach(function (cb) {
135
+ return cb === null || cb === void 0 ? void 0 : cb();
136
+ });
137
+ (_cleanup$current = cleanup.current) === null || _cleanup$current === void 0 || _cleanup$current.call(cleanup);
138
+ };
139
+ // Do not re-run if the `effect` changes - this is not expected with `useEffect` or similar hooks
140
+ // eslint-disable-next-line react-hooks/exhaustive-deps
141
+ }, [externalPlugins]);
142
+ }
@@ -17,7 +17,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
17
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
18
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
19
19
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
20
- var packageVersion = "94.20.0";
20
+ var packageVersion = "94.22.0";
21
21
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
22
22
  // Remove URL as it has UGC
23
23
  // TODO: Sanitise the URL instead of just removing it
@@ -11,6 +11,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
11
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _eventDispatcher = require("../event-dispatcher");
14
15
  /*********************
15
16
  * *
16
17
  * BASE TYPES *
@@ -500,14 +501,17 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
500
501
  * If your code is inside an EditorPlugin you should be using the @see ExtractInjectionAPI.
501
502
  */
502
503
  var EditorPresetBuilder = exports.EditorPresetBuilder = /*#__PURE__*/function () {
503
- /**
504
- * Returns the editor API when resolved.
505
- * This occurs when the preset is initially built.
506
- */
507
-
508
504
  function EditorPresetBuilder() {
509
505
  var _this = this;
510
506
  (0, _classCallCheck2.default)(this, EditorPresetBuilder);
507
+ /**
508
+ * @deprecated Use `apiResolver` instead
509
+ */
510
+ /**
511
+ * Returns the editor API when resolved.
512
+ * This occurs when the preset is initially built.
513
+ */
514
+ (0, _defineProperty2.default)(this, "apiEmitter", function () {});
511
515
  (0, _defineProperty2.default)(this, "safeEntry", function (plugin) {
512
516
  return Array.isArray(plugin) ? plugin : [plugin, undefined];
513
517
  });
@@ -518,6 +522,9 @@ var EditorPresetBuilder = exports.EditorPresetBuilder = /*#__PURE__*/function ()
518
522
  this.apiPromise = new Promise(function (r) {
519
523
  return _this.resolver = r;
520
524
  });
525
+ this.apiResolver = new APIDispatcher(function (emitter) {
526
+ return _this.apiEmitter = emitter;
527
+ });
521
528
  }
522
529
  (0, _createClass2.default)(EditorPresetBuilder, [{
523
530
  key: "add",
@@ -575,6 +582,8 @@ var EditorPresetBuilder = exports.EditorPresetBuilder = /*#__PURE__*/function ()
575
582
  // The pluginInjectionAPI API doesn't have information enough to build a proper type for the API.
576
583
  // It is returning a generic type but on top of the Proxy system
577
584
  // So, we can safely recast it here
585
+ this.apiEmitter(pluginInjectionAPI.api());
586
+ // Deprecated approach
578
587
  (_this$resolver = this.resolver) === null || _this$resolver === void 0 || _this$resolver.call(this, pluginInjectionAPI.api());
579
588
  }
580
589
  return this.removeExcludedPlugins(editorPlugins, excludePlugins);
@@ -645,4 +654,58 @@ var EditorPresetBuilder = exports.EditorPresetBuilder = /*#__PURE__*/function ()
645
654
  }
646
655
  }]);
647
656
  return EditorPresetBuilder;
657
+ }();
658
+ /**
659
+ * WARNING: Internal object
660
+ *
661
+ * Dedicated wrapper around EventDispatcher for public API around the editor API.
662
+ * This only has the public method `on` which is used to listen to updates to the editor API.
663
+ *
664
+ * This shouldn't really be used externally - the `editorAPI` should be accessed via `usePreset`.
665
+ */
666
+ var APIDispatcher = /*#__PURE__*/function () {
667
+ function APIDispatcher(emitter) {
668
+ var _this3 = this;
669
+ (0, _classCallCheck2.default)(this, APIDispatcher);
670
+ (0, _defineProperty2.default)(this, "eventDispatcher", new _eventDispatcher.EventDispatcher());
671
+ (0, _defineProperty2.default)(this, "key", 'api-resolved-event');
672
+ // Need to store the last event created in case we subscribe after the fact
673
+ (0, _defineProperty2.default)(this, "initialEvent", undefined);
674
+ this.emitter = emitter;
675
+ this.emitter(function (v) {
676
+ _this3.initialEvent = v;
677
+ _this3.eventDispatcher.emit(_this3.key, v);
678
+ });
679
+ }
680
+
681
+ /**
682
+ * Used to observe Editor API events
683
+ *
684
+ * @param cb Callback to listen to the editor API.
685
+ * This will also emit the last event if the stream has already started.
686
+ * @returns Cleanup function to cleanup the listener
687
+ */
688
+ (0, _createClass2.default)(APIDispatcher, [{
689
+ key: "on",
690
+ value: function on(cb) {
691
+ var _this4 = this;
692
+ if (this.initialEvent !== undefined) {
693
+ // Keeps timing consistent with old approach - certain products
694
+ // ie. ai-mate relied on this.
695
+ Promise.resolve().then(function () {
696
+ return cb(_this4.initialEvent);
697
+ });
698
+ }
699
+ this.eventDispatcher.on(this.key, cb);
700
+ return function () {
701
+ _this4.eventDispatcher.off(_this4.key, cb);
702
+ };
703
+ }
704
+ }, {
705
+ key: "destroy",
706
+ value: function destroy() {
707
+ this.eventDispatcher.destroy();
708
+ }
709
+ }]);
710
+ return APIDispatcher;
648
711
  }();
@@ -24,7 +24,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
24
24
  * @jsx jsx
25
25
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "94.20.0";
27
+ var packageVersion = "94.22.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var DropList = /*#__PURE__*/function (_Component) {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.processRawFragmentValue = processRawFragmentValue;
6
7
  exports.processRawValue = processRawValue;
7
8
  exports.processRawValueWithoutValidation = processRawValueWithoutValidation;
8
9
  var _transforms = require("@atlaskit/adf-utils/transforms");
@@ -241,6 +242,20 @@ function processRawValue(schema, value, providerFactory, sanitizePrivateContent,
241
242
  return;
242
243
  }
243
244
  }
245
+ function processRawFragmentValue(schema, value, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent) {
246
+ if (!value) {
247
+ return;
248
+ }
249
+ var adfEntities = value.map(function (item) {
250
+ return processRawValue(schema, item, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent);
251
+ }).filter(function (item) {
252
+ return Boolean(item);
253
+ });
254
+ if (adfEntities.length === 0) {
255
+ return;
256
+ }
257
+ return _model.Fragment.from(adfEntities);
258
+ }
244
259
  function isProseMirrorSchemaCheckError(error) {
245
260
  return error instanceof RangeError && (!!error.message.match(/^Invalid collection of marks for node/) || !!error.message.match(/^Invalid content for node/));
246
261
  }
@@ -0,0 +1,118 @@
1
+ import { useEffect, useLayoutEffect, useMemo, useRef } from 'react';
2
+ import debounce from 'lodash/debounce';
3
+ /**
4
+ *
5
+ * Directly map object values
6
+ *
7
+ * @param object The object to transform
8
+ * @param mapFunction The function to map an old value to new one
9
+ * @returns Object with the same key but transformed values
10
+ *
11
+ */
12
+ function mapValues(object, mapFunction) {
13
+ return Object.entries(object).reduce((acc, [key, value]) => ({
14
+ ...acc,
15
+ [key]: mapFunction(value)
16
+ }), {});
17
+ }
18
+
19
+ // When we use the `useSharedPluginState` example: `useSharedPluginState(api, ['width'])`
20
+ // it will re-render every time the component re-renders as the array "['width']" is seen as an update.
21
+ // This hook is used to prevent re-renders due to this.
22
+ function useStaticPlugins(plugins) {
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ return useMemo(() => plugins, []);
25
+ }
26
+ /**
27
+ *
28
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
29
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
30
+ * your React Component will get only the last one.
31
+ *
32
+ * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this
33
+ * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called
34
+ * on initialisation and when the state changes (with the latest callback we are provided).
35
+ *
36
+ * Example in plugin:
37
+ *
38
+ * ```typescript
39
+ * function ExampleContent({ api }: Props) {
40
+ * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => {
41
+ * // Use as necessary ie. fire analytics or network requests
42
+ * console.log(dogState, exampleState)
43
+ * }, [])
44
+ * usePluginStateEffect(
45
+ * api,
46
+ * ['dog', 'example'],
47
+ * pluginStateCallback
48
+ * )
49
+ * return <p>Content</p>
50
+ * }
51
+ *
52
+ * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
53
+ * return {
54
+ * name: 'example',
55
+ * contentComponent: () =>
56
+ * <ExampleContent
57
+ * api={api}
58
+ * />
59
+ * }
60
+ * }
61
+ * ```
62
+ *
63
+ * @param injectionApi Plugin injection API from `NextEditorPlugin`
64
+ * @param plugins Plugin names to get the shared plugin state for
65
+ * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended,
66
+ * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed.
67
+ * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`,
68
+ * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes.
69
+ */
70
+ export function usePluginStateEffect(injectionApi, plugins, effect) {
71
+ const pluginNames = useStaticPlugins(plugins);
72
+
73
+ // Create a memoized object containing the named plugins
74
+ const namedExternalPlugins = useMemo(() => pluginNames.reduce((acc, pluginName) => ({
75
+ ...acc,
76
+ [`${String(pluginName)}State`]: injectionApi === null || injectionApi === void 0 ? void 0 : injectionApi[pluginName]
77
+ }), {}), [injectionApi, pluginNames]);
78
+ usePluginStateEffectInternal(namedExternalPlugins, effect);
79
+ }
80
+ function usePluginStateEffectInternal(externalPlugins, effect) {
81
+ const refStates = useRef();
82
+ const cleanup = useRef();
83
+ const latestEffect = useRef(effect);
84
+
85
+ // We should store the latest effect in a reference so it is more intuitive to the user
86
+ // and we are not causing a memory leak by having references to old state.
87
+ useEffect(() => {
88
+ latestEffect.current = debounce(effect);
89
+ return () => {
90
+ latestEffect.current = undefined;
91
+ };
92
+ }, [effect]);
93
+ useLayoutEffect(() => {
94
+ var _latestEffect$current;
95
+ // Update the reference for this plugin and activate the effect
96
+ refStates.current = mapValues(externalPlugins, value => value === null || value === void 0 ? void 0 : value.sharedState.currentState());
97
+ cleanup.current = (_latestEffect$current = latestEffect.current) === null || _latestEffect$current === void 0 ? void 0 : _latestEffect$current.call(latestEffect, refStates.current);
98
+ const unsubs = Object.entries(externalPlugins).map(([pluginKey, externalPlugin]) => externalPlugin === null || externalPlugin === void 0 ? void 0 : externalPlugin.sharedState.onChange(({
99
+ nextSharedState,
100
+ prevSharedState
101
+ }) => {
102
+ if (prevSharedState !== nextSharedState && refStates.current) {
103
+ var _latestEffect$current2;
104
+ // Update the reference for this plugin and activate the effect
105
+ refStates.current[pluginKey] = nextSharedState;
106
+ cleanup.current = (_latestEffect$current2 = latestEffect.current) === null || _latestEffect$current2 === void 0 ? void 0 : _latestEffect$current2.call(latestEffect, refStates.current);
107
+ }
108
+ }));
109
+ return () => {
110
+ var _cleanup$current;
111
+ refStates.current = undefined;
112
+ unsubs.forEach(cb => cb === null || cb === void 0 ? void 0 : cb());
113
+ (_cleanup$current = cleanup.current) === null || _cleanup$current === void 0 ? void 0 : _cleanup$current.call(cleanup);
114
+ };
115
+ // Do not re-run if the `effect` changes - this is not expected with `useEffect` or similar hooks
116
+ // eslint-disable-next-line react-hooks/exhaustive-deps
117
+ }, [externalPlugins]);
118
+ }
@@ -1,7 +1,7 @@
1
1
  import { isFedRamp } from './environment';
2
2
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
3
3
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
4
- const packageVersion = "94.20.0";
4
+ const packageVersion = "94.22.0";
5
5
  const sanitiseSentryEvents = (data, _hint) => {
6
6
  // Remove URL as it has UGC
7
7
  // TODO: Sanitise the URL instead of just removing it
@@ -1,4 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { EventDispatcher } from '../event-dispatcher';
3
+
2
4
  /*********************
3
5
  * *
4
6
  * BASE TYPES *
@@ -525,15 +527,19 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
525
527
  * If your code is inside an EditorPlugin you should be using the @see ExtractInjectionAPI.
526
528
  */
527
529
  export class EditorPresetBuilder {
528
- /**
529
- * Returns the editor API when resolved.
530
- * This occurs when the preset is initially built.
531
- */
532
-
533
530
  constructor(...more) {
531
+ /**
532
+ * @deprecated Use `apiResolver` instead
533
+ */
534
+ /**
535
+ * Returns the editor API when resolved.
536
+ * This occurs when the preset is initially built.
537
+ */
538
+ _defineProperty(this, "apiEmitter", () => {});
534
539
  _defineProperty(this, "safeEntry", plugin => Array.isArray(plugin) ? plugin : [plugin, undefined]);
535
540
  this.data = [...more] || [];
536
541
  this.apiPromise = new Promise(r => this.resolver = r);
542
+ this.apiResolver = new APIDispatcher(emitter => this.apiEmitter = emitter);
537
543
  }
538
544
  add(nextOrTuple) {
539
545
  return new EditorPresetBuilder(
@@ -583,6 +589,8 @@ export class EditorPresetBuilder {
583
589
  // The pluginInjectionAPI API doesn't have information enough to build a proper type for the API.
584
590
  // It is returning a generic type but on top of the Proxy system
585
591
  // So, we can safely recast it here
592
+ this.apiEmitter(pluginInjectionAPI.api());
593
+ // Deprecated approach
586
594
  (_this$resolver = this.resolver) === null || _this$resolver === void 0 ? void 0 : _this$resolver.call(this, pluginInjectionAPI.api());
587
595
  }
588
596
  return this.removeExcludedPlugins(editorPlugins, excludePlugins);
@@ -637,4 +645,47 @@ export class EditorPresetBuilder {
637
645
  }
638
646
  return plugins;
639
647
  }
648
+ }
649
+ /**
650
+ * WARNING: Internal object
651
+ *
652
+ * Dedicated wrapper around EventDispatcher for public API around the editor API.
653
+ * This only has the public method `on` which is used to listen to updates to the editor API.
654
+ *
655
+ * This shouldn't really be used externally - the `editorAPI` should be accessed via `usePreset`.
656
+ */
657
+ class APIDispatcher {
658
+ constructor(emitter) {
659
+ _defineProperty(this, "eventDispatcher", new EventDispatcher());
660
+ _defineProperty(this, "key", 'api-resolved-event');
661
+ // Need to store the last event created in case we subscribe after the fact
662
+ _defineProperty(this, "initialEvent", undefined);
663
+ this.emitter = emitter;
664
+ this.emitter(v => {
665
+ this.initialEvent = v;
666
+ this.eventDispatcher.emit(this.key, v);
667
+ });
668
+ }
669
+
670
+ /**
671
+ * Used to observe Editor API events
672
+ *
673
+ * @param cb Callback to listen to the editor API.
674
+ * This will also emit the last event if the stream has already started.
675
+ * @returns Cleanup function to cleanup the listener
676
+ */
677
+ on(cb) {
678
+ if (this.initialEvent !== undefined) {
679
+ // Keeps timing consistent with old approach - certain products
680
+ // ie. ai-mate relied on this.
681
+ Promise.resolve().then(() => cb(this.initialEvent));
682
+ }
683
+ this.eventDispatcher.on(this.key, cb);
684
+ return () => {
685
+ this.eventDispatcher.off(this.key, cb);
686
+ };
687
+ }
688
+ destroy() {
689
+ this.eventDispatcher.destroy();
690
+ }
640
691
  }
@@ -13,7 +13,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
13
13
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import Layer from '../Layer';
15
15
  const packageName = "@atlaskit/editor-common";
16
- const packageVersion = "94.20.0";
16
+ const packageVersion = "94.22.0";
17
17
  const halfFocusRing = 1;
18
18
  const dropOffset = '0, 8';
19
19
  class DropList extends Component {
@@ -1,5 +1,5 @@
1
1
  import { transformDedupeMarks, transformIndentationMarks, transformInvalidMediaContent, transformMediaLinkMarks, transformNestedTablesIncomingDocument, transformNodesMissingContent, transformTextLinkCodeMarks } from '@atlaskit/adf-utils/transforms';
2
- import { Node } from '@atlaskit/editor-prosemirror/model';
2
+ import { Fragment, Node } from '@atlaskit/editor-prosemirror/model';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../analytics';
5
5
  import { sanitizeNodeForPrivacy } from './filter/privacy-filter';
@@ -241,6 +241,16 @@ export function processRawValue(schema, value, providerFactory, sanitizePrivateC
241
241
  return;
242
242
  }
243
243
  }
244
+ export function processRawFragmentValue(schema, value, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent) {
245
+ if (!value) {
246
+ return;
247
+ }
248
+ const adfEntities = value.map(item => processRawValue(schema, item, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent)).filter(item => Boolean(item));
249
+ if (adfEntities.length === 0) {
250
+ return;
251
+ }
252
+ return Fragment.from(adfEntities);
253
+ }
244
254
  function isProseMirrorSchemaCheckError(error) {
245
255
  return error instanceof RangeError && (!!error.message.match(/^Invalid collection of marks for node/) || !!error.message.match(/^Invalid content for node/));
246
256
  }
@@ -0,0 +1,135 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ import { useEffect, useLayoutEffect, useMemo, useRef } from 'react';
6
+ import debounce from 'lodash/debounce';
7
+ /**
8
+ *
9
+ * Directly map object values
10
+ *
11
+ * @param object The object to transform
12
+ * @param mapFunction The function to map an old value to new one
13
+ * @returns Object with the same key but transformed values
14
+ *
15
+ */
16
+ function mapValues(object, mapFunction) {
17
+ return Object.entries(object).reduce(function (acc, _ref) {
18
+ var _ref2 = _slicedToArray(_ref, 2),
19
+ key = _ref2[0],
20
+ value = _ref2[1];
21
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, mapFunction(value)));
22
+ }, {});
23
+ }
24
+
25
+ // When we use the `useSharedPluginState` example: `useSharedPluginState(api, ['width'])`
26
+ // it will re-render every time the component re-renders as the array "['width']" is seen as an update.
27
+ // This hook is used to prevent re-renders due to this.
28
+ function useStaticPlugins(plugins) {
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ return useMemo(function () {
31
+ return plugins;
32
+ }, []);
33
+ }
34
+ /**
35
+ *
36
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
37
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
38
+ * your React Component will get only the last one.
39
+ *
40
+ * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this
41
+ * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called
42
+ * on initialisation and when the state changes (with the latest callback we are provided).
43
+ *
44
+ * Example in plugin:
45
+ *
46
+ * ```typescript
47
+ * function ExampleContent({ api }: Props) {
48
+ * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => {
49
+ * // Use as necessary ie. fire analytics or network requests
50
+ * console.log(dogState, exampleState)
51
+ * }, [])
52
+ * usePluginStateEffect(
53
+ * api,
54
+ * ['dog', 'example'],
55
+ * pluginStateCallback
56
+ * )
57
+ * return <p>Content</p>
58
+ * }
59
+ *
60
+ * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
61
+ * return {
62
+ * name: 'example',
63
+ * contentComponent: () =>
64
+ * <ExampleContent
65
+ * api={api}
66
+ * />
67
+ * }
68
+ * }
69
+ * ```
70
+ *
71
+ * @param injectionApi Plugin injection API from `NextEditorPlugin`
72
+ * @param plugins Plugin names to get the shared plugin state for
73
+ * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended,
74
+ * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed.
75
+ * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`,
76
+ * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes.
77
+ */
78
+ export function usePluginStateEffect(injectionApi, plugins, effect) {
79
+ var pluginNames = useStaticPlugins(plugins);
80
+
81
+ // Create a memoized object containing the named plugins
82
+ var namedExternalPlugins = useMemo(function () {
83
+ return pluginNames.reduce(function (acc, pluginName) {
84
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, "".concat(String(pluginName), "State"), injectionApi === null || injectionApi === void 0 ? void 0 : injectionApi[pluginName]));
85
+ }, {});
86
+ }, [injectionApi, pluginNames]);
87
+ usePluginStateEffectInternal(namedExternalPlugins, effect);
88
+ }
89
+ function usePluginStateEffectInternal(externalPlugins, effect) {
90
+ var refStates = useRef();
91
+ var cleanup = useRef();
92
+ var latestEffect = useRef(effect);
93
+
94
+ // We should store the latest effect in a reference so it is more intuitive to the user
95
+ // and we are not causing a memory leak by having references to old state.
96
+ useEffect(function () {
97
+ latestEffect.current = debounce(effect);
98
+ return function () {
99
+ latestEffect.current = undefined;
100
+ };
101
+ }, [effect]);
102
+ useLayoutEffect(function () {
103
+ var _latestEffect$current;
104
+ // Update the reference for this plugin and activate the effect
105
+ refStates.current = mapValues(externalPlugins, function (value) {
106
+ return value === null || value === void 0 ? void 0 : value.sharedState.currentState();
107
+ });
108
+ cleanup.current = (_latestEffect$current = latestEffect.current) === null || _latestEffect$current === void 0 ? void 0 : _latestEffect$current.call(latestEffect, refStates.current);
109
+ var unsubs = Object.entries(externalPlugins).map(function (_ref3) {
110
+ var _ref4 = _slicedToArray(_ref3, 2),
111
+ pluginKey = _ref4[0],
112
+ externalPlugin = _ref4[1];
113
+ return externalPlugin === null || externalPlugin === void 0 ? void 0 : externalPlugin.sharedState.onChange(function (_ref5) {
114
+ var nextSharedState = _ref5.nextSharedState,
115
+ prevSharedState = _ref5.prevSharedState;
116
+ if (prevSharedState !== nextSharedState && refStates.current) {
117
+ var _latestEffect$current2;
118
+ // Update the reference for this plugin and activate the effect
119
+ refStates.current[pluginKey] = nextSharedState;
120
+ cleanup.current = (_latestEffect$current2 = latestEffect.current) === null || _latestEffect$current2 === void 0 ? void 0 : _latestEffect$current2.call(latestEffect, refStates.current);
121
+ }
122
+ });
123
+ });
124
+ return function () {
125
+ var _cleanup$current;
126
+ refStates.current = undefined;
127
+ unsubs.forEach(function (cb) {
128
+ return cb === null || cb === void 0 ? void 0 : cb();
129
+ });
130
+ (_cleanup$current = cleanup.current) === null || _cleanup$current === void 0 || _cleanup$current.call(cleanup);
131
+ };
132
+ // Do not re-run if the `effect` changes - this is not expected with `useEffect` or similar hooks
133
+ // eslint-disable-next-line react-hooks/exhaustive-deps
134
+ }, [externalPlugins]);
135
+ }
@@ -7,7 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
7
7
  import { isFedRamp } from './environment';
8
8
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
9
9
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
10
- var packageVersion = "94.20.0";
10
+ var packageVersion = "94.22.0";
11
11
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
12
12
  // Remove URL as it has UGC
13
13
  // TODO: Sanitise the URL instead of just removing it
@@ -4,6 +4,8 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
5
  import _createClass from "@babel/runtime/helpers/createClass";
6
6
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ import { EventDispatcher } from '../event-dispatcher';
8
+
7
9
  /*********************
8
10
  * *
9
11
  * BASE TYPES *
@@ -530,14 +532,17 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
530
532
  * If your code is inside an EditorPlugin you should be using the @see ExtractInjectionAPI.
531
533
  */
532
534
  export var EditorPresetBuilder = /*#__PURE__*/function () {
533
- /**
534
- * Returns the editor API when resolved.
535
- * This occurs when the preset is initially built.
536
- */
537
-
538
535
  function EditorPresetBuilder() {
539
536
  var _this = this;
540
537
  _classCallCheck(this, EditorPresetBuilder);
538
+ /**
539
+ * @deprecated Use `apiResolver` instead
540
+ */
541
+ /**
542
+ * Returns the editor API when resolved.
543
+ * This occurs when the preset is initially built.
544
+ */
545
+ _defineProperty(this, "apiEmitter", function () {});
541
546
  _defineProperty(this, "safeEntry", function (plugin) {
542
547
  return Array.isArray(plugin) ? plugin : [plugin, undefined];
543
548
  });
@@ -548,6 +553,9 @@ export var EditorPresetBuilder = /*#__PURE__*/function () {
548
553
  this.apiPromise = new Promise(function (r) {
549
554
  return _this.resolver = r;
550
555
  });
556
+ this.apiResolver = new APIDispatcher(function (emitter) {
557
+ return _this.apiEmitter = emitter;
558
+ });
551
559
  }
552
560
  _createClass(EditorPresetBuilder, [{
553
561
  key: "add",
@@ -605,6 +613,8 @@ export var EditorPresetBuilder = /*#__PURE__*/function () {
605
613
  // The pluginInjectionAPI API doesn't have information enough to build a proper type for the API.
606
614
  // It is returning a generic type but on top of the Proxy system
607
615
  // So, we can safely recast it here
616
+ this.apiEmitter(pluginInjectionAPI.api());
617
+ // Deprecated approach
608
618
  (_this$resolver = this.resolver) === null || _this$resolver === void 0 || _this$resolver.call(this, pluginInjectionAPI.api());
609
619
  }
610
620
  return this.removeExcludedPlugins(editorPlugins, excludePlugins);
@@ -675,4 +685,58 @@ export var EditorPresetBuilder = /*#__PURE__*/function () {
675
685
  }
676
686
  }]);
677
687
  return EditorPresetBuilder;
688
+ }();
689
+ /**
690
+ * WARNING: Internal object
691
+ *
692
+ * Dedicated wrapper around EventDispatcher for public API around the editor API.
693
+ * This only has the public method `on` which is used to listen to updates to the editor API.
694
+ *
695
+ * This shouldn't really be used externally - the `editorAPI` should be accessed via `usePreset`.
696
+ */
697
+ var APIDispatcher = /*#__PURE__*/function () {
698
+ function APIDispatcher(emitter) {
699
+ var _this3 = this;
700
+ _classCallCheck(this, APIDispatcher);
701
+ _defineProperty(this, "eventDispatcher", new EventDispatcher());
702
+ _defineProperty(this, "key", 'api-resolved-event');
703
+ // Need to store the last event created in case we subscribe after the fact
704
+ _defineProperty(this, "initialEvent", undefined);
705
+ this.emitter = emitter;
706
+ this.emitter(function (v) {
707
+ _this3.initialEvent = v;
708
+ _this3.eventDispatcher.emit(_this3.key, v);
709
+ });
710
+ }
711
+
712
+ /**
713
+ * Used to observe Editor API events
714
+ *
715
+ * @param cb Callback to listen to the editor API.
716
+ * This will also emit the last event if the stream has already started.
717
+ * @returns Cleanup function to cleanup the listener
718
+ */
719
+ _createClass(APIDispatcher, [{
720
+ key: "on",
721
+ value: function on(cb) {
722
+ var _this4 = this;
723
+ if (this.initialEvent !== undefined) {
724
+ // Keeps timing consistent with old approach - certain products
725
+ // ie. ai-mate relied on this.
726
+ Promise.resolve().then(function () {
727
+ return cb(_this4.initialEvent);
728
+ });
729
+ }
730
+ this.eventDispatcher.on(this.key, cb);
731
+ return function () {
732
+ _this4.eventDispatcher.off(_this4.key, cb);
733
+ };
734
+ }
735
+ }, {
736
+ key: "destroy",
737
+ value: function destroy() {
738
+ this.eventDispatcher.destroy();
739
+ }
740
+ }]);
741
+ return APIDispatcher;
678
742
  }();
@@ -21,7 +21,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
21
21
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "94.20.0";
24
+ var packageVersion = "94.22.0";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var DropList = /*#__PURE__*/function (_Component) {
@@ -1,5 +1,5 @@
1
1
  import { transformDedupeMarks, transformIndentationMarks, transformInvalidMediaContent, transformMediaLinkMarks, transformNestedTablesIncomingDocument, transformNodesMissingContent, transformTextLinkCodeMarks } from '@atlaskit/adf-utils/transforms';
2
- import { Node } from '@atlaskit/editor-prosemirror/model';
2
+ import { Fragment, Node } from '@atlaskit/editor-prosemirror/model';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../analytics';
5
5
  import { sanitizeNodeForPrivacy } from './filter/privacy-filter';
@@ -234,6 +234,20 @@ export function processRawValue(schema, value, providerFactory, sanitizePrivateC
234
234
  return;
235
235
  }
236
236
  }
237
+ export function processRawFragmentValue(schema, value, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent) {
238
+ if (!value) {
239
+ return;
240
+ }
241
+ var adfEntities = value.map(function (item) {
242
+ return processRawValue(schema, item, providerFactory, sanitizePrivateContent, contentTransformer, dispatchAnalyticsEvent);
243
+ }).filter(function (item) {
244
+ return Boolean(item);
245
+ });
246
+ if (adfEntities.length === 0) {
247
+ return;
248
+ }
249
+ return Fragment.from(adfEntities);
250
+ }
237
251
  function isProseMirrorSchemaCheckError(error) {
238
252
  return error instanceof RangeError && (!!error.message.match(/^Invalid collection of marks for node/) || !!error.message.match(/^Invalid content for node/));
239
253
  }
@@ -0,0 +1,52 @@
1
+ import type { BasePluginDependenciesAPI, EditorInjectionAPI, ExtractInjectionAPI, NextEditorPlugin } from '../types/next-editor-plugin';
2
+ type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
3
+ [K in PluginNames as `${K extends string ? K : never}State`]: API[K] extends BasePluginDependenciesAPI<any> | undefined ? ReturnType<API[K]['sharedState']['currentState']> : never;
4
+ }>;
5
+ type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
6
+ type Cleanup = () => void;
7
+ /**
8
+ *
9
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
10
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
11
+ * your React Component will get only the last one.
12
+ *
13
+ * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this
14
+ * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called
15
+ * on initialisation and when the state changes (with the latest callback we are provided).
16
+ *
17
+ * Example in plugin:
18
+ *
19
+ * ```typescript
20
+ * function ExampleContent({ api }: Props) {
21
+ * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => {
22
+ * // Use as necessary ie. fire analytics or network requests
23
+ * console.log(dogState, exampleState)
24
+ * }, [])
25
+ * usePluginStateEffect(
26
+ * api,
27
+ * ['dog', 'example'],
28
+ * pluginStateCallback
29
+ * )
30
+ * return <p>Content</p>
31
+ * }
32
+ *
33
+ * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
34
+ * return {
35
+ * name: 'example',
36
+ * contentComponent: () =>
37
+ * <ExampleContent
38
+ * api={api}
39
+ * />
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * @param injectionApi Plugin injection API from `NextEditorPlugin`
45
+ * @param plugins Plugin names to get the shared plugin state for
46
+ * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended,
47
+ * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed.
48
+ * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`,
49
+ * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes.
50
+ */
51
+ export declare function usePluginStateEffect<API extends EditorInjectionAPI<any, any>, PluginNames extends ExtractPluginNames<API>>(injectionApi: API | null | undefined, plugins: PluginNames[], effect: (states: NamedPluginStatesFromInjectionAPI<API, PluginNames>) => Cleanup | void): void;
52
+ export {};
@@ -1,3 +1,4 @@
1
+ import { type Listener } from '../event-dispatcher';
1
2
  import type { CorePlugin, DefaultEditorPlugin, DependencyPlugin, NextEditorPlugin, NextEditorPluginMetadata, OptionalPlugin, PluginDependenciesAPI } from '../types';
2
3
  import type { EditorPlugin } from '../types/editor-plugin';
3
4
  import type { EditorPluginInjectionAPI } from './plugin-injection-api';
@@ -553,11 +554,16 @@ type BuildProps = {
553
554
  export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] = [], StackPlugins extends AllEditorPresetPluginTypes[] = []> {
554
555
  private readonly data;
555
556
  /**
556
- * Returns the editor API when resolved.
557
- * This occurs when the preset is initially built.
557
+ * @deprecated Use `apiResolver` instead
558
558
  */
559
559
  apiPromise: Promise<unknown>;
560
560
  private resolver;
561
+ /**
562
+ * Returns the editor API when resolved.
563
+ * This occurs when the preset is initially built.
564
+ */
565
+ apiResolver: APIDispatcher;
566
+ private apiEmitter;
561
567
  constructor(...more: [...StackPlugins]);
562
568
  add<NewPlugin extends PresetPlugin>(nextOrTuple: SafePresetCheck<NewPlugin, StackPlugins>): EditorPresetBuilder<[
563
569
  ExtractPluginNameFromAllBuilderPlugins<NewPlugin>,
@@ -580,4 +586,29 @@ export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] =
580
586
  private removeExcludedPlugins;
581
587
  private safeEntry;
582
588
  }
589
+ type Emitter = (value: unknown) => void;
590
+ /**
591
+ * WARNING: Internal object
592
+ *
593
+ * Dedicated wrapper around EventDispatcher for public API around the editor API.
594
+ * This only has the public method `on` which is used to listen to updates to the editor API.
595
+ *
596
+ * This shouldn't really be used externally - the `editorAPI` should be accessed via `usePreset`.
597
+ */
598
+ declare class APIDispatcher {
599
+ private emitter;
600
+ private eventDispatcher;
601
+ private key;
602
+ private initialEvent;
603
+ constructor(emitter: (emitter: Emitter) => void);
604
+ /**
605
+ * Used to observe Editor API events
606
+ *
607
+ * @param cb Callback to listen to the editor API.
608
+ * This will also emit the last event if the stream has already started.
609
+ * @returns Cleanup function to cleanup the listener
610
+ */
611
+ on(cb: Listener<unknown>): () => void;
612
+ destroy(): void;
613
+ }
583
614
  export {};
@@ -1,7 +1,7 @@
1
- import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
- import { Node } from '@atlaskit/editor-prosemirror/model';
1
+ import { Fragment, Node, type Schema } from '@atlaskit/editor-prosemirror/model';
3
2
  import type { DispatchAnalyticsEvent } from '../analytics';
4
3
  import type { ProviderFactory } from '../provider-factory';
5
4
  import type { ReplaceRawValue, Transformer } from '../types';
6
5
  export declare function processRawValueWithoutValidation(schema: Schema, value?: ReplaceRawValue, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Node | undefined;
7
6
  export declare function processRawValue(schema: Schema, value?: ReplaceRawValue, providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Node | undefined;
7
+ export declare function processRawFragmentValue(schema: Schema, value?: ReplaceRawValue[], providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Fragment | undefined;
@@ -0,0 +1,52 @@
1
+ import type { BasePluginDependenciesAPI, EditorInjectionAPI, ExtractInjectionAPI, NextEditorPlugin } from '../types/next-editor-plugin';
2
+ type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
3
+ [K in PluginNames as `${K extends string ? K : never}State`]: API[K] extends BasePluginDependenciesAPI<any> | undefined ? ReturnType<API[K]['sharedState']['currentState']> : never;
4
+ }>;
5
+ type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
6
+ type Cleanup = () => void;
7
+ /**
8
+ *
9
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
10
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
11
+ * your React Component will get only the last one.
12
+ *
13
+ * Used to run effects on changes in editor state - similar to `useSharedPluginState` except this
14
+ * is for reacting to state changes so does not cause re-renders. The effect callback passed will be called
15
+ * on initialisation and when the state changes (with the latest callback we are provided).
16
+ *
17
+ * Example in plugin:
18
+ *
19
+ * ```typescript
20
+ * function ExampleContent({ api }: Props) {
21
+ * const pluginStateCallback = useCallback(( { dogState, exampleState } ) => {
22
+ * // Use as necessary ie. fire analytics or network requests
23
+ * console.log(dogState, exampleState)
24
+ * }, [])
25
+ * usePluginStateEffect(
26
+ * api,
27
+ * ['dog', 'example'],
28
+ * pluginStateCallback
29
+ * )
30
+ * return <p>Content</p>
31
+ * }
32
+ *
33
+ * const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
34
+ * return {
35
+ * name: 'example',
36
+ * contentComponent: () =>
37
+ * <ExampleContent
38
+ * api={api}
39
+ * />
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * @param injectionApi Plugin injection API from `NextEditorPlugin`
45
+ * @param plugins Plugin names to get the shared plugin state for
46
+ * @param effect A callback, the parameter is a corresponding object, the keys are names of the plugin with `State` appended,
47
+ * the values are the shared state exposed by that plugin. This effect fires when the state changes and runs the most recent callback passed.
48
+ * If the callback changes the effect is not re-run - it is still recommended however to wrap your effect in `useCallback`,
49
+ * You can return a function from your effect to call any cleanup activities which will be called on unmount and when `editorApi` changes.
50
+ */
51
+ export declare function usePluginStateEffect<API extends EditorInjectionAPI<any, any>, PluginNames extends ExtractPluginNames<API>>(injectionApi: API | null | undefined, plugins: PluginNames[], effect: (states: NamedPluginStatesFromInjectionAPI<API, PluginNames>) => Cleanup | void): void;
52
+ export {};
@@ -1,3 +1,4 @@
1
+ import { type Listener } from '../event-dispatcher';
1
2
  import type { CorePlugin, DefaultEditorPlugin, DependencyPlugin, NextEditorPlugin, NextEditorPluginMetadata, OptionalPlugin, PluginDependenciesAPI } from '../types';
2
3
  import type { EditorPlugin } from '../types/editor-plugin';
3
4
  import type { EditorPluginInjectionAPI } from './plugin-injection-api';
@@ -582,11 +583,16 @@ export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] =
582
583
  ]> {
583
584
  private readonly data;
584
585
  /**
585
- * Returns the editor API when resolved.
586
- * This occurs when the preset is initially built.
586
+ * @deprecated Use `apiResolver` instead
587
587
  */
588
588
  apiPromise: Promise<unknown>;
589
589
  private resolver;
590
+ /**
591
+ * Returns the editor API when resolved.
592
+ * This occurs when the preset is initially built.
593
+ */
594
+ apiResolver: APIDispatcher;
595
+ private apiEmitter;
590
596
  constructor(...more: [
591
597
  ...StackPlugins
592
598
  ]);
@@ -611,4 +617,29 @@ export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] =
611
617
  private removeExcludedPlugins;
612
618
  private safeEntry;
613
619
  }
620
+ type Emitter = (value: unknown) => void;
621
+ /**
622
+ * WARNING: Internal object
623
+ *
624
+ * Dedicated wrapper around EventDispatcher for public API around the editor API.
625
+ * This only has the public method `on` which is used to listen to updates to the editor API.
626
+ *
627
+ * This shouldn't really be used externally - the `editorAPI` should be accessed via `usePreset`.
628
+ */
629
+ declare class APIDispatcher {
630
+ private emitter;
631
+ private eventDispatcher;
632
+ private key;
633
+ private initialEvent;
634
+ constructor(emitter: (emitter: Emitter) => void);
635
+ /**
636
+ * Used to observe Editor API events
637
+ *
638
+ * @param cb Callback to listen to the editor API.
639
+ * This will also emit the last event if the stream has already started.
640
+ * @returns Cleanup function to cleanup the listener
641
+ */
642
+ on(cb: Listener<unknown>): () => void;
643
+ destroy(): void;
644
+ }
614
645
  export {};
@@ -1,7 +1,7 @@
1
- import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
- import { Node } from '@atlaskit/editor-prosemirror/model';
1
+ import { Fragment, Node, type Schema } from '@atlaskit/editor-prosemirror/model';
3
2
  import type { DispatchAnalyticsEvent } from '../analytics';
4
3
  import type { ProviderFactory } from '../provider-factory';
5
4
  import type { ReplaceRawValue, Transformer } from '../types';
6
5
  export declare function processRawValueWithoutValidation(schema: Schema, value?: ReplaceRawValue, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Node | undefined;
7
6
  export declare function processRawValue(schema: Schema, value?: ReplaceRawValue, providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Node | undefined;
7
+ export declare function processRawFragmentValue(schema: Schema, value?: ReplaceRawValue[], providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Fragment | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "94.20.0",
3
+ "version": "94.22.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -104,6 +104,7 @@
104
104
  "./intl-error-boundary": "./src/ui/IntlErrorBoundary/index.tsx",
105
105
  "./code-block": "./src/code-block/index.ts",
106
106
  "./table": "./src/table/index.ts",
107
+ "./use-plugin-state-effect": "./src/hooks/usePluginStateEffect.ts",
107
108
  "./lazy-node-view": "./src/lazy-node-view/index.ts",
108
109
  "./nesting": "./src/nesting/utilities.ts",
109
110
  "./UNSAFE_do_not_use_editor_context": "./src/ui/EditorContext/index.ts"
@@ -126,33 +127,33 @@
126
127
  "@atlaskit/editor-prosemirror": "6.0.0",
127
128
  "@atlaskit/editor-shared-styles": "^3.2.0",
128
129
  "@atlaskit/editor-tables": "^2.8.0",
129
- "@atlaskit/emoji": "^67.9.0",
130
+ "@atlaskit/emoji": "^67.10.0",
130
131
  "@atlaskit/icon": "^22.24.0",
131
132
  "@atlaskit/icon-object": "^6.7.0",
132
- "@atlaskit/link-datasource": "^3.8.0",
133
+ "@atlaskit/link-datasource": "^3.10.0",
133
134
  "@atlaskit/link-picker": "^1.47.0",
134
- "@atlaskit/media-card": "^78.13.0",
135
+ "@atlaskit/media-card": "^78.14.0",
135
136
  "@atlaskit/media-client": "^28.3.0",
136
137
  "@atlaskit/media-client-react": "^2.3.0",
137
138
  "@atlaskit/media-common": "^11.7.0",
138
139
  "@atlaskit/media-file-preview": "^0.9.0",
139
140
  "@atlaskit/media-picker": "^67.0.0",
140
141
  "@atlaskit/media-ui": "^26.2.0",
141
- "@atlaskit/media-viewer": "49.4.0",
142
- "@atlaskit/mention": "^23.3.0",
142
+ "@atlaskit/media-viewer": "49.4.1",
143
+ "@atlaskit/mention": "^23.4.0",
143
144
  "@atlaskit/menu": "^2.13.0",
144
145
  "@atlaskit/onboarding": "^12.1.0",
145
146
  "@atlaskit/platform-feature-flags": "^0.3.0",
146
147
  "@atlaskit/popper": "^6.3.0",
147
- "@atlaskit/primitives": "^13.1.0",
148
- "@atlaskit/profilecard": "^20.11.0",
148
+ "@atlaskit/primitives": "^13.2.0",
149
+ "@atlaskit/profilecard": "^20.12.0",
149
150
  "@atlaskit/section-message": "^6.6.0",
150
151
  "@atlaskit/smart-card": "^30.2.0",
151
152
  "@atlaskit/smart-user-picker": "^6.11.0",
152
153
  "@atlaskit/spinner": "^16.3.0",
153
154
  "@atlaskit/task-decision": "^17.11.0",
154
155
  "@atlaskit/textfield": "^6.5.0",
155
- "@atlaskit/tmp-editor-statsig": "^2.14.0",
156
+ "@atlaskit/tmp-editor-statsig": "^2.17.0",
156
157
  "@atlaskit/tokens": "^2.2.0",
157
158
  "@atlaskit/tooltip": "^18.9.0",
158
159
  "@atlaskit/width-detector": "^4.3.0",
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-common/use-plugin-state-effect",
3
+ "main": "../dist/cjs/hooks/usePluginStateEffect.js",
4
+ "module": "../dist/esm/hooks/usePluginStateEffect.js",
5
+ "module:es2019": "../dist/es2019/hooks/usePluginStateEffect.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/hooks/usePluginStateEffect.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.4": {
10
+ "*": [
11
+ "../dist/types-ts4.5/hooks/usePluginStateEffect.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }