@atlaskit/editor-common 96.4.0 → 96.5.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 +18 -0
- package/dist/cjs/analytics/analytics-queue.js +4 -5
- package/dist/cjs/annotation/index.js +9 -10
- package/dist/cjs/element-browser/ElementBrowser.js +11 -14
- package/dist/cjs/event-dispatcher/index.js +1 -2
- package/dist/cjs/extensibility/Extension/Lozenge/index.js +7 -10
- package/dist/cjs/extensibility/Extension.js +6 -9
- package/dist/cjs/extensibility/ExtensionComponent.js +25 -30
- package/dist/cjs/extensibility/extensionNodeView.js +5 -7
- package/dist/cjs/extensions/default-extension-provider.js +1 -2
- package/dist/cjs/hooks/useSharedPluginState.js +3 -0
- package/dist/cjs/hooks/useSharedPluginStateSelector/index.js +12 -0
- package/dist/cjs/hooks/useSharedPluginStateSelector/useSharedPluginStateSelector.js +114 -0
- package/dist/cjs/lazy-node-view/lazy-scheduler.js +1 -1
- package/dist/cjs/lazy-node-view/node-view.js +1 -2
- package/dist/cjs/link/LinkPicker/HyperlinkAddToolbar/HyperlinkAddToolbar.js +39 -45
- package/dist/cjs/link/LinkSearch/LinkSearchList.js +5 -7
- package/dist/cjs/link/LinkSearch/LinkSearchListItem.js +9 -12
- package/dist/cjs/link/LinkSearch/index.js +13 -16
- package/dist/cjs/link/LinkSearch/withActivityProvider.js +6 -9
- package/dist/cjs/media-inline/inline-image-wrapper.js +1 -2
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/portal/PortalManager.js +1 -2
- package/dist/cjs/preset/builder.js +2 -4
- package/dist/cjs/preset/editor-commands.js +4 -5
- package/dist/cjs/preset/plugin-injection-api.js +4 -8
- package/dist/cjs/provider-factory/provider-factory.js +1 -2
- package/dist/cjs/provider-factory/with-providers.js +8 -11
- package/dist/cjs/react-node-view/index.js +1 -2
- package/dist/cjs/safe-plugin/index.js +4 -5
- package/dist/cjs/selection/gap-cursor/selection.js +7 -11
- package/dist/cjs/selection-based-node-view/SelectionBasedNodeView.js +10 -13
- package/dist/cjs/styles/shared/media-single.js +21 -20
- package/dist/cjs/styles/shared/paragraph.js +1 -1
- package/dist/cjs/styles/shared/shadow.js +9 -8
- package/dist/cjs/styles/shared/table.js +1 -1
- package/dist/cjs/types/annotation/emitter.js +1 -2
- package/dist/cjs/ui/Caption/index.js +5 -7
- package/dist/cjs/ui/ContextPanel/context.js +8 -11
- package/dist/cjs/ui/DropList/index.js +22 -25
- package/dist/cjs/ui/ErrorBoundary/index.js +6 -9
- package/dist/cjs/ui/Expand/sharedStyles.js +1 -1
- package/dist/cjs/ui/IntlErrorBoundary/index.js +6 -9
- package/dist/cjs/ui/Layer/index.js +9 -12
- package/dist/cjs/ui/Mention/index.js +6 -9
- package/dist/cjs/ui/Mention/mention-with-providers.js +6 -9
- package/dist/cjs/ui/Messages/index.js +1 -1
- package/dist/cjs/ui/OverflowShadow/index.js +13 -16
- package/dist/cjs/ui/OverflowShadow/shadowObserver.js +3 -5
- package/dist/cjs/ui/PanelTextInput/index.js +10 -13
- package/dist/cjs/ui/Popup/index.js +14 -17
- package/dist/cjs/ui/ResizerLegacy/index.js +12 -16
- package/dist/cjs/ui/WithCreateAnalyticsEvent/index.js +5 -7
- package/dist/cjs/ui/with-outer-listeners.js +10 -13
- package/dist/cjs/ui-menu/Dropdown/index.js +9 -12
- package/dist/cjs/ui-menu/DropdownMenu/index.js +11 -14
- package/dist/cjs/ui-react/with-react-editor-view-outer-listeners.js +8 -11
- package/dist/cjs/utils/error-reporter.js +1 -2
- package/dist/cjs/utils/hyperlink.js +2 -4
- package/dist/cjs/utils/imageLoader.js +14 -19
- package/dist/cjs/utils/profiler/render-count.js +3 -2
- package/dist/cjs/utils/traversor.js +1 -2
- package/dist/cjs/with-plugin-state/index.js +28 -35
- package/dist/es2019/analytics/analytics-queue.js +3 -3
- package/dist/es2019/hooks/useSharedPluginState.js +3 -0
- package/dist/es2019/hooks/useSharedPluginStateSelector/index.js +2 -0
- package/dist/es2019/hooks/useSharedPluginStateSelector/useSharedPluginStateSelector.js +98 -0
- package/dist/es2019/lazy-node-view/lazy-scheduler.js +1 -1
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/styles/shared/paragraph.js +1 -1
- package/dist/es2019/styles/shared/table.js +1 -1
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/es2019/ui/Expand/sharedStyles.js +1 -1
- package/dist/es2019/ui/Messages/index.js +1 -1
- package/dist/es2019/utils/profiler/render-count.js +2 -0
- package/dist/esm/analytics/analytics-queue.js +4 -5
- package/dist/esm/annotation/index.js +9 -10
- package/dist/esm/element-browser/ElementBrowser.js +11 -14
- package/dist/esm/event-dispatcher/index.js +1 -2
- package/dist/esm/extensibility/Extension/Lozenge/index.js +7 -10
- package/dist/esm/extensibility/Extension.js +6 -9
- package/dist/esm/extensibility/ExtensionComponent.js +25 -30
- package/dist/esm/extensibility/extensionNodeView.js +5 -7
- package/dist/esm/extensions/default-extension-provider.js +1 -2
- package/dist/esm/hooks/useSharedPluginState.js +3 -0
- package/dist/esm/hooks/useSharedPluginStateSelector/index.js +2 -0
- package/dist/esm/hooks/useSharedPluginStateSelector/useSharedPluginStateSelector.js +108 -0
- package/dist/esm/lazy-node-view/lazy-scheduler.js +1 -1
- package/dist/esm/lazy-node-view/node-view.js +1 -2
- package/dist/esm/link/LinkPicker/HyperlinkAddToolbar/HyperlinkAddToolbar.js +39 -45
- package/dist/esm/link/LinkSearch/LinkSearchList.js +5 -7
- package/dist/esm/link/LinkSearch/LinkSearchListItem.js +9 -12
- package/dist/esm/link/LinkSearch/index.js +13 -16
- package/dist/esm/link/LinkSearch/withActivityProvider.js +6 -9
- package/dist/esm/media-inline/inline-image-wrapper.js +1 -2
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/portal/PortalManager.js +1 -2
- package/dist/esm/preset/builder.js +2 -4
- package/dist/esm/preset/editor-commands.js +4 -5
- package/dist/esm/preset/plugin-injection-api.js +4 -8
- package/dist/esm/provider-factory/provider-factory.js +1 -2
- package/dist/esm/provider-factory/with-providers.js +8 -11
- package/dist/esm/react-node-view/index.js +1 -2
- package/dist/esm/safe-plugin/index.js +4 -5
- package/dist/esm/selection/gap-cursor/selection.js +7 -11
- package/dist/esm/selection-based-node-view/SelectionBasedNodeView.js +10 -13
- package/dist/esm/styles/shared/media-single.js +19 -20
- package/dist/esm/styles/shared/paragraph.js +1 -1
- package/dist/esm/styles/shared/shadow.js +7 -8
- package/dist/esm/styles/shared/table.js +1 -1
- package/dist/esm/types/annotation/emitter.js +1 -2
- package/dist/esm/ui/Caption/index.js +5 -7
- package/dist/esm/ui/ContextPanel/context.js +8 -11
- package/dist/esm/ui/DropList/index.js +22 -25
- package/dist/esm/ui/ErrorBoundary/index.js +6 -9
- package/dist/esm/ui/Expand/sharedStyles.js +1 -1
- package/dist/esm/ui/IntlErrorBoundary/index.js +6 -9
- package/dist/esm/ui/Layer/index.js +9 -12
- package/dist/esm/ui/Mention/index.js +6 -9
- package/dist/esm/ui/Mention/mention-with-providers.js +6 -9
- package/dist/esm/ui/Messages/index.js +1 -1
- package/dist/esm/ui/OverflowShadow/index.js +13 -16
- package/dist/esm/ui/OverflowShadow/shadowObserver.js +3 -5
- package/dist/esm/ui/PanelTextInput/index.js +10 -13
- package/dist/esm/ui/Popup/index.js +14 -17
- package/dist/esm/ui/ResizerLegacy/index.js +12 -16
- package/dist/esm/ui/WithCreateAnalyticsEvent/index.js +5 -7
- package/dist/esm/ui/with-outer-listeners.js +10 -13
- package/dist/esm/ui-menu/Dropdown/index.js +9 -12
- package/dist/esm/ui-menu/DropdownMenu/index.js +11 -14
- package/dist/esm/ui-react/with-react-editor-view-outer-listeners.js +8 -11
- package/dist/esm/utils/error-reporter.js +1 -2
- package/dist/esm/utils/hyperlink.js +2 -4
- package/dist/esm/utils/imageLoader.js +14 -19
- package/dist/esm/utils/profiler/render-count.js +3 -2
- package/dist/esm/utils/traversor.js +1 -2
- package/dist/esm/with-plugin-state/index.js +28 -35
- package/dist/types/hooks/useSharedPluginState.d.ts +5 -3
- package/dist/types/hooks/useSharedPluginStateSelector/index.d.ts +1 -0
- package/dist/types/hooks/useSharedPluginStateSelector/useSharedPluginStateSelector.d.ts +74 -0
- package/dist/types-ts4.5/hooks/useSharedPluginState.d.ts +5 -3
- package/dist/types-ts4.5/hooks/useSharedPluginStateSelector/index.d.ts +1 -0
- package/dist/types-ts4.5/hooks/useSharedPluginStateSelector/useSharedPluginStateSelector.d.ts +74 -0
- package/package.json +4 -3
- package/use-shared-plugin-state-selector/package.json +15 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
4
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
5
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
6
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
9
8
|
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; }
|
|
10
9
|
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; }
|
|
11
|
-
function
|
|
10
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
12
11
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
13
12
|
import React from 'react';
|
|
14
13
|
import PropTypes from 'prop-types';
|
|
@@ -62,13 +61,12 @@ var DEFAULT_SLOW_THRESHOLD = 4;
|
|
|
62
61
|
*
|
|
63
62
|
*/
|
|
64
63
|
var WithPluginState = /*#__PURE__*/function (_React$Component) {
|
|
65
|
-
_inherits(WithPluginState, _React$Component);
|
|
66
|
-
var _super = _createSuper(WithPluginState);
|
|
67
64
|
function WithPluginState(props) {
|
|
68
65
|
_classCallCheck(this, WithPluginState);
|
|
69
|
-
return
|
|
66
|
+
return _callSuper(this, WithPluginState, [props]);
|
|
70
67
|
}
|
|
71
|
-
|
|
68
|
+
_inherits(WithPluginState, _React$Component);
|
|
69
|
+
return _createClass(WithPluginState, [{
|
|
72
70
|
key: "render",
|
|
73
71
|
value: function render() {
|
|
74
72
|
if (fg('platform_editor_react18_phase2_v2')) {
|
|
@@ -77,7 +75,6 @@ var WithPluginState = /*#__PURE__*/function (_React$Component) {
|
|
|
77
75
|
return /*#__PURE__*/React.createElement(WithPluginStateOld, this.props);
|
|
78
76
|
}
|
|
79
77
|
}]);
|
|
80
|
-
return WithPluginState;
|
|
81
78
|
}(React.Component);
|
|
82
79
|
function WithPluginStateNew(props) {
|
|
83
80
|
var context = React.useContext(EditorContext);
|
|
@@ -86,18 +83,16 @@ function WithPluginStateNew(props) {
|
|
|
86
83
|
}));
|
|
87
84
|
}
|
|
88
85
|
export var WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
|
|
89
|
-
_inherits(WithPluginStateInner, _React$Component2);
|
|
90
|
-
var _super2 = _createSuper(WithPluginStateInner);
|
|
91
86
|
function WithPluginStateInner(props) {
|
|
92
87
|
var _this;
|
|
93
88
|
_classCallCheck(this, WithPluginStateInner);
|
|
94
|
-
_this =
|
|
95
|
-
_defineProperty(
|
|
96
|
-
_defineProperty(
|
|
97
|
-
_defineProperty(
|
|
98
|
-
_defineProperty(
|
|
99
|
-
_defineProperty(
|
|
100
|
-
_defineProperty(
|
|
89
|
+
_this = _callSuper(this, WithPluginStateInner, [props]);
|
|
90
|
+
_defineProperty(_this, "listeners", {});
|
|
91
|
+
_defineProperty(_this, "debounce", null);
|
|
92
|
+
_defineProperty(_this, "notAppliedState", {});
|
|
93
|
+
_defineProperty(_this, "isSubscribed", false);
|
|
94
|
+
_defineProperty(_this, "callsCount", 0);
|
|
95
|
+
_defineProperty(_this, "handlePluginStateChange", function (propName, pluginName, performanceOptions, skipEqualityCheck) {
|
|
101
96
|
return function (pluginState) {
|
|
102
97
|
// skipEqualityCheck is being used for old plugins since they are mutating plugin state instead of creating a new one
|
|
103
98
|
if (_this.state[propName] !== pluginState || skipEqualityCheck) {
|
|
@@ -112,7 +107,7 @@ export var WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
|
|
|
112
107
|
/**
|
|
113
108
|
* Debounces setState calls in order to reduce number of re-renders caused by several plugin state changes.
|
|
114
109
|
*/
|
|
115
|
-
_defineProperty(
|
|
110
|
+
_defineProperty(_this, "updateState", function (_ref) {
|
|
116
111
|
var stateSubset = _ref.stateSubset,
|
|
117
112
|
pluginName = _ref.pluginName,
|
|
118
113
|
performanceOptions = _ref.performanceOptions;
|
|
@@ -148,7 +143,7 @@ export var WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
|
|
|
148
143
|
_this.notAppliedState = {};
|
|
149
144
|
});
|
|
150
145
|
});
|
|
151
|
-
_defineProperty(
|
|
146
|
+
_defineProperty(_this, "dispatchAnalyticsEvent", function (payload) {
|
|
152
147
|
var eventDispatcher = _this.getEventDispatcher();
|
|
153
148
|
if (eventDispatcher) {
|
|
154
149
|
var dispatch = createDispatch(eventDispatcher);
|
|
@@ -160,7 +155,8 @@ export var WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
|
|
|
160
155
|
_this.state = _this.getPluginsStates(_this.props.plugins, _this.getEditorView(props));
|
|
161
156
|
return _this;
|
|
162
157
|
}
|
|
163
|
-
|
|
158
|
+
_inherits(WithPluginStateInner, _React$Component2);
|
|
159
|
+
return _createClass(WithPluginStateInner, [{
|
|
164
160
|
key: "getEditorView",
|
|
165
161
|
value: function getEditorView(maybeProps) {
|
|
166
162
|
var props = maybeProps || this.props;
|
|
@@ -310,22 +306,19 @@ export var WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
|
|
|
310
306
|
return render(this.state);
|
|
311
307
|
}
|
|
312
308
|
}]);
|
|
313
|
-
return WithPluginStateInner;
|
|
314
309
|
}(React.Component);
|
|
315
310
|
_defineProperty(WithPluginStateInner, "displayName", 'WithPluginState');
|
|
316
311
|
export var WithPluginStateOld = /*#__PURE__*/function (_React$Component3) {
|
|
317
|
-
_inherits(WithPluginStateOld, _React$Component3);
|
|
318
|
-
var _super3 = _createSuper(WithPluginStateOld);
|
|
319
312
|
function WithPluginStateOld(props, context) {
|
|
320
313
|
var _this6;
|
|
321
314
|
_classCallCheck(this, WithPluginStateOld);
|
|
322
|
-
_this6 =
|
|
323
|
-
_defineProperty(
|
|
324
|
-
_defineProperty(
|
|
325
|
-
_defineProperty(
|
|
326
|
-
_defineProperty(
|
|
327
|
-
_defineProperty(
|
|
328
|
-
_defineProperty(
|
|
315
|
+
_this6 = _callSuper(this, WithPluginStateOld, [props, context]);
|
|
316
|
+
_defineProperty(_this6, "listeners", {});
|
|
317
|
+
_defineProperty(_this6, "debounce", null);
|
|
318
|
+
_defineProperty(_this6, "notAppliedState", {});
|
|
319
|
+
_defineProperty(_this6, "isSubscribed", false);
|
|
320
|
+
_defineProperty(_this6, "callsCount", 0);
|
|
321
|
+
_defineProperty(_this6, "handlePluginStateChange", function (propName, pluginName, performanceOptions, skipEqualityCheck) {
|
|
329
322
|
return function (pluginState) {
|
|
330
323
|
// skipEqualityCheck is being used for old plugins since they are mutating plugin state instead of creating a new one
|
|
331
324
|
if (_this6.state[propName] !== pluginState || skipEqualityCheck) {
|
|
@@ -340,7 +333,7 @@ export var WithPluginStateOld = /*#__PURE__*/function (_React$Component3) {
|
|
|
340
333
|
/**
|
|
341
334
|
* Debounces setState calls in order to reduce number of re-renders caused by several plugin state changes.
|
|
342
335
|
*/
|
|
343
|
-
_defineProperty(
|
|
336
|
+
_defineProperty(_this6, "updateState", function (_ref2) {
|
|
344
337
|
var stateSubset = _ref2.stateSubset,
|
|
345
338
|
pluginName = _ref2.pluginName,
|
|
346
339
|
performanceOptions = _ref2.performanceOptions;
|
|
@@ -376,7 +369,7 @@ export var WithPluginStateOld = /*#__PURE__*/function (_React$Component3) {
|
|
|
376
369
|
_this6.notAppliedState = {};
|
|
377
370
|
});
|
|
378
371
|
});
|
|
379
|
-
_defineProperty(
|
|
372
|
+
_defineProperty(_this6, "dispatchAnalyticsEvent", function (payload) {
|
|
380
373
|
var eventDispatcher = _this6.getEventDispatcher();
|
|
381
374
|
if (eventDispatcher) {
|
|
382
375
|
var dispatch = createDispatch(eventDispatcher);
|
|
@@ -385,13 +378,14 @@ export var WithPluginStateOld = /*#__PURE__*/function (_React$Component3) {
|
|
|
385
378
|
});
|
|
386
379
|
}
|
|
387
380
|
});
|
|
388
|
-
_defineProperty(
|
|
381
|
+
_defineProperty(_this6, "onContextUpdate", function () {
|
|
389
382
|
_this6.subscribe(_this6.props);
|
|
390
383
|
});
|
|
391
384
|
_this6.state = _this6.getPluginsStates(_this6.props.plugins, _this6.getEditorView(props, context));
|
|
392
385
|
return _this6;
|
|
393
386
|
}
|
|
394
|
-
|
|
387
|
+
_inherits(WithPluginStateOld, _React$Component3);
|
|
388
|
+
return _createClass(WithPluginStateOld, [{
|
|
395
389
|
key: "getEditorView",
|
|
396
390
|
value: function getEditorView(maybeProps, maybeContext) {
|
|
397
391
|
var props = maybeProps || this.props;
|
|
@@ -536,7 +530,6 @@ export var WithPluginStateOld = /*#__PURE__*/function (_React$Component3) {
|
|
|
536
530
|
return render(this.state);
|
|
537
531
|
}
|
|
538
532
|
}]);
|
|
539
|
-
return WithPluginStateOld;
|
|
540
533
|
}(React.Component);
|
|
541
534
|
_defineProperty(WithPluginStateOld, "displayName", 'WithPluginState');
|
|
542
535
|
_defineProperty(WithPluginStateOld, "contextTypes", {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { BasePluginDependenciesAPI, EditorInjectionAPI, ExtractInjectionAPI, ExtractPluginSharedState, NextEditorPlugin, NextEditorPluginMetadata } from '../types/next-editor-plugin';
|
|
2
|
-
type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
|
|
2
|
+
export type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
|
|
3
3
|
[K in PluginNames as `${K extends string ? K : never}State`]: API[K] extends BasePluginDependenciesAPI<any> | undefined ? Exclude<API[K], undefined> extends BasePluginDependenciesAPI<infer Metadata> ? Metadata extends NextEditorPluginMetadata ? ExtractPluginSharedState<Metadata> | undefined : never : never : never;
|
|
4
4
|
}>;
|
|
5
|
-
type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
5
|
+
export type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
6
6
|
/**
|
|
7
|
+
*
|
|
8
|
+
* NOTE: Generally you may want to use `usePluginStateSelector` over this which behaves similarly
|
|
9
|
+
* but selects a slice of the state which is more performant.
|
|
7
10
|
*
|
|
8
11
|
* ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
|
|
9
12
|
* If the plugins you are listening to generate multiple shared states while the user is typing,
|
|
@@ -65,4 +68,3 @@ type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
|
65
68
|
* the values are the shared state exposed by that plugin.
|
|
66
69
|
*/
|
|
67
70
|
export declare function useSharedPluginState<API extends EditorInjectionAPI<any, any>, PluginNames extends ExtractPluginNames<API>>(injectionApi: API | null | undefined, plugins: PluginNames[]): NamedPluginStatesFromInjectionAPI<API, PluginNames>;
|
|
68
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSharedPluginStateSelector } from './useSharedPluginStateSelector';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { EditorInjectionAPI } from '../../types/next-editor-plugin';
|
|
2
|
+
type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API extends string ? keyof API : never;
|
|
3
|
+
/**
|
|
4
|
+
* This is designed to iterate through an object to get the path of its result
|
|
5
|
+
* based on separation via "."
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* type Test = { deepObject: { value: number } };
|
|
10
|
+
* // Type should be `"deepObject" | "deepObject.value"`
|
|
11
|
+
* type Result = NestedKeys<Test>;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type NestedKeys<T> = {
|
|
15
|
+
[K in keyof T]: T[K] extends object ? T[K] extends any[] ? K extends string ? K : never : T[K] extends object ? K extends string ? K | `${K}.${NestedKeys<T[K]>}` : never : never : K extends string ? K : never;
|
|
16
|
+
}[keyof T];
|
|
17
|
+
/**
|
|
18
|
+
* This is designed to iterate through a path of an object to get the type of its result
|
|
19
|
+
* based on separation via "."
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* type Test = { deepObject: { value: number } }
|
|
24
|
+
* // Type should be `number`
|
|
25
|
+
* type Result = Path<Test, 'deepObject.value'>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
type Path<T, K extends string> = K extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Path<T[Key], Rest> : never : K extends keyof T ? T[K] : never;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
|
|
32
|
+
* If the plugins you are listening to generate multiple shared states while the user is typing,
|
|
33
|
+
* your React Component will get only the last one.
|
|
34
|
+
*
|
|
35
|
+
* Used to return the current plugin state of input dependencies.
|
|
36
|
+
* It will recursively retrieve a slice of the state using a "." to separate
|
|
37
|
+
* parts of the state.
|
|
38
|
+
*
|
|
39
|
+
* Example:
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const pluginA: NextEditorPlugin<
|
|
43
|
+
'pluginA',
|
|
44
|
+
{
|
|
45
|
+
sharedState: { deepObj: { value: number | undefined } };
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
* ```
|
|
49
|
+
* You can use `const value = useSharedPluginStateSelector(api, 'pluginA.deepObj.value')` to retrieve the value
|
|
50
|
+
*
|
|
51
|
+
* Example in plugin:
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* function ExampleContent({ api }: Props) {
|
|
55
|
+
* const title = useSharedPluginStateSelector(api, 'dog.title')
|
|
56
|
+
* return <p>{ title } { exampleState.description }</p>
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
|
|
60
|
+
* return {
|
|
61
|
+
* name: 'example',
|
|
62
|
+
* contentComponent: () => <ExampleContent api={api} />
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* NOTE: If you pass an invalid path, `undefined` will be returned
|
|
68
|
+
*
|
|
69
|
+
* @param api
|
|
70
|
+
* @param plugin
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare function useSharedPluginStateSelector<API extends EditorInjectionAPI<any, any>, PluginName extends ExtractPluginNames<API>, SharedState extends ReturnType<Exclude<API[PluginName], null | undefined>['sharedState']['currentState']>, Key extends NestedKeys<Exclude<SharedState, null | undefined>>, Result extends Path<Exclude<SharedState, null | undefined>, Key>>(api: API | undefined | null, plugin: `${PluginName}.${Key}`): Result | undefined;
|
|
74
|
+
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { BasePluginDependenciesAPI, EditorInjectionAPI, ExtractInjectionAPI, ExtractPluginSharedState, NextEditorPlugin, NextEditorPluginMetadata } from '../types/next-editor-plugin';
|
|
2
|
-
type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
|
|
2
|
+
export type NamedPluginStatesFromInjectionAPI<API extends ExtractInjectionAPI<NextEditorPlugin<any, any>>, PluginNames extends string | number | symbol> = Readonly<{
|
|
3
3
|
[K in PluginNames as `${K extends string ? K : never}State`]: API[K] extends BasePluginDependenciesAPI<any> | undefined ? Exclude<API[K], undefined> extends BasePluginDependenciesAPI<infer Metadata> ? Metadata extends NextEditorPluginMetadata ? ExtractPluginSharedState<Metadata> | undefined : never : never : never;
|
|
4
4
|
}>;
|
|
5
|
-
type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
5
|
+
export type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
6
6
|
/**
|
|
7
|
+
*
|
|
8
|
+
* NOTE: Generally you may want to use `usePluginStateSelector` over this which behaves similarly
|
|
9
|
+
* but selects a slice of the state which is more performant.
|
|
7
10
|
*
|
|
8
11
|
* ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
|
|
9
12
|
* If the plugins you are listening to generate multiple shared states while the user is typing,
|
|
@@ -65,4 +68,3 @@ type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API;
|
|
|
65
68
|
* the values are the shared state exposed by that plugin.
|
|
66
69
|
*/
|
|
67
70
|
export declare function useSharedPluginState<API extends EditorInjectionAPI<any, any>, PluginNames extends ExtractPluginNames<API>>(injectionApi: API | null | undefined, plugins: PluginNames[]): NamedPluginStatesFromInjectionAPI<API, PluginNames>;
|
|
68
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSharedPluginStateSelector } from './useSharedPluginStateSelector';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { EditorInjectionAPI } from '../../types/next-editor-plugin';
|
|
2
|
+
type ExtractPluginNames<API extends EditorInjectionAPI<any, any>> = keyof API extends string ? keyof API : never;
|
|
3
|
+
/**
|
|
4
|
+
* This is designed to iterate through an object to get the path of its result
|
|
5
|
+
* based on separation via "."
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* type Test = { deepObject: { value: number } };
|
|
10
|
+
* // Type should be `"deepObject" | "deepObject.value"`
|
|
11
|
+
* type Result = NestedKeys<Test>;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type NestedKeys<T> = {
|
|
15
|
+
[K in keyof T]: T[K] extends object ? T[K] extends any[] ? K extends string ? K : never : T[K] extends object ? K extends string ? K | `${K}.${NestedKeys<T[K]>}` : never : never : K extends string ? K : never;
|
|
16
|
+
}[keyof T];
|
|
17
|
+
/**
|
|
18
|
+
* This is designed to iterate through a path of an object to get the type of its result
|
|
19
|
+
* based on separation via "."
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* type Test = { deepObject: { value: number } }
|
|
24
|
+
* // Type should be `number`
|
|
25
|
+
* type Result = Path<Test, 'deepObject.value'>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
type Path<T, K extends string> = K extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Path<T[Key], Rest> : never : K extends keyof T ? T[K] : never;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
|
|
32
|
+
* If the plugins you are listening to generate multiple shared states while the user is typing,
|
|
33
|
+
* your React Component will get only the last one.
|
|
34
|
+
*
|
|
35
|
+
* Used to return the current plugin state of input dependencies.
|
|
36
|
+
* It will recursively retrieve a slice of the state using a "." to separate
|
|
37
|
+
* parts of the state.
|
|
38
|
+
*
|
|
39
|
+
* Example:
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const pluginA: NextEditorPlugin<
|
|
43
|
+
'pluginA',
|
|
44
|
+
{
|
|
45
|
+
sharedState: { deepObj: { value: number | undefined } };
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
* ```
|
|
49
|
+
* You can use `const value = useSharedPluginStateSelector(api, 'pluginA.deepObj.value')` to retrieve the value
|
|
50
|
+
*
|
|
51
|
+
* Example in plugin:
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* function ExampleContent({ api }: Props) {
|
|
55
|
+
* const title = useSharedPluginStateSelector(api, 'dog.title')
|
|
56
|
+
* return <p>{ title } { exampleState.description }</p>
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const examplePlugin: NextEditorPlugin<'example', { dependencies: [typeof pluginDog] }> = ({ api }) => {
|
|
60
|
+
* return {
|
|
61
|
+
* name: 'example',
|
|
62
|
+
* contentComponent: () => <ExampleContent api={api} />
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* NOTE: If you pass an invalid path, `undefined` will be returned
|
|
68
|
+
*
|
|
69
|
+
* @param api
|
|
70
|
+
* @param plugin
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare function useSharedPluginStateSelector<API extends EditorInjectionAPI<any, any>, PluginName extends ExtractPluginNames<API>, SharedState extends ReturnType<Exclude<API[PluginName], null | undefined>['sharedState']['currentState']>, Key extends NestedKeys<Exclude<SharedState, null | undefined>>, Result extends Path<Exclude<SharedState, null | undefined>, Key>>(api: API | undefined | null, plugin: `${PluginName}.${Key}`): Result | undefined;
|
|
74
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-common",
|
|
3
|
-
"version": "96.
|
|
3
|
+
"version": "96.5.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/"
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"./code-block": "./src/code-block/index.ts",
|
|
106
106
|
"./table": "./src/table/index.ts",
|
|
107
107
|
"./use-plugin-state-effect": "./src/hooks/usePluginStateEffect.ts",
|
|
108
|
+
"./use-shared-plugin-state-selector": "./src/hooks/useSharedPluginStateSelector/index.ts",
|
|
108
109
|
"./lazy-node-view": "./src/lazy-node-view/index.ts",
|
|
109
110
|
"./nesting": "./src/nesting/utilities.ts",
|
|
110
111
|
"./UNSAFE_do_not_use_editor_context": "./src/ui/EditorContext/index.ts"
|
|
@@ -139,7 +140,7 @@
|
|
|
139
140
|
"@atlaskit/media-file-preview": "^0.9.0",
|
|
140
141
|
"@atlaskit/media-picker": "^67.0.0",
|
|
141
142
|
"@atlaskit/media-ui": "^27.0.0",
|
|
142
|
-
"@atlaskit/media-viewer": "49.4.
|
|
143
|
+
"@atlaskit/media-viewer": "49.4.5",
|
|
143
144
|
"@atlaskit/mention": "^23.4.0",
|
|
144
145
|
"@atlaskit/menu": "^2.13.0",
|
|
145
146
|
"@atlaskit/onboarding": "^12.2.0",
|
|
@@ -153,7 +154,7 @@
|
|
|
153
154
|
"@atlaskit/spinner": "^16.3.0",
|
|
154
155
|
"@atlaskit/task-decision": "^17.11.0",
|
|
155
156
|
"@atlaskit/textfield": "^6.7.0",
|
|
156
|
-
"@atlaskit/tmp-editor-statsig": "^2.
|
|
157
|
+
"@atlaskit/tmp-editor-statsig": "^2.26.0",
|
|
157
158
|
"@atlaskit/tokens": "^2.4.0",
|
|
158
159
|
"@atlaskit/tooltip": "^19.0.0",
|
|
159
160
|
"@atlaskit/width-detector": "^4.3.0",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-common/use-shared-plugin-state-selector",
|
|
3
|
+
"main": "../dist/cjs/hooks/useSharedPluginStateSelector/index.js",
|
|
4
|
+
"module": "../dist/esm/hooks/useSharedPluginStateSelector/index.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/hooks/useSharedPluginStateSelector/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/hooks/useSharedPluginStateSelector/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.4": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/hooks/useSharedPluginStateSelector/index.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|