@atlaskit/editor-plugin-editor-disabled 2.0.6 → 2.1.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,17 @@
1
1
  # @atlaskit/editor-plugin-editor-disabled
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#170934](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/170934)
8
+ [`1b251997752cd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1b251997752cd) -
9
+ Expose editor disabled prop to reduce number of initial transactions.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 2.0.6
4
16
 
5
17
  ### Patch Changes
@@ -5,39 +5,56 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.editorDisabledPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
9
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
11
  var _utils = require("@atlaskit/editor-common/utils");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
13
+ 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; }
14
+ 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; }
12
15
  var pluginKey = new _state.PluginKey('editorDisabledPlugin');
13
16
  function reducer(_pluginState, meta) {
14
17
  return meta;
15
18
  }
16
19
  var _pluginFactory = (0, _utils.pluginFactory)(pluginKey, reducer),
17
- createPluginState = _pluginFactory.createPluginState,
18
20
  getPluginState = _pluginFactory.getPluginState;
19
- var scheduleEditorDisabledUpdate = (0, _rafSchd.default)(function (view) {
20
- if (getPluginState(view.state).editorDisabled !== !view.editable) {
21
- var tr = view.state.tr.setMeta(pluginKey, {
22
- editorDisabled: !view.editable
23
- });
24
- tr.setMeta('isLocal', true);
25
- view.dispatch(tr);
26
- }
27
- });
28
21
 
29
22
  /*
30
23
  Stores the state of the editor enabled/disabled for panel and floating
31
24
  toolbar to subscribe to through useSharedPluginState. Otherwise the NodeViews
32
25
  won't re-render when it changes.
33
26
  */
34
- function createPlugin(dispatch) {
27
+ function createPlugin(dispatch, options) {
28
+ var scheduleEditorDisabledUpdate = (0, _rafSchd.default)(function (view) {
29
+ if (getPluginState(view.state).editorDisabled !== !view.editable) {
30
+ var disabledMeta = {
31
+ editorDisabled: !view.editable
32
+ };
33
+ var tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
34
+ tr.setMeta('isLocal', true);
35
+ view.dispatch(tr);
36
+ }
37
+ });
35
38
  return new _safePlugin.SafePlugin({
36
39
  key: pluginKey,
37
- state: createPluginState(dispatch, {
38
- editorDisabled: false
39
- }),
40
- view: function view() {
40
+ state: {
41
+ init: function init() {
42
+ var _options$initialDisab;
43
+ return {
44
+ editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
45
+ };
46
+ },
47
+ apply: function apply(tr, pluginState) {
48
+ var meta = tr.getMeta(pluginKey);
49
+ if (meta) {
50
+ return pluginState.editorDisabled !== meta.editorDisabled ? _objectSpread(_objectSpread({}, pluginState), meta) : pluginState;
51
+ }
52
+ return pluginState;
53
+ }
54
+ },
55
+ view: function view(_view) {
56
+ // schedule on mount
57
+ scheduleEditorDisabledUpdate(_view);
41
58
  return {
42
59
  update: function update(view) {
43
60
  scheduleEditorDisabledUpdate(view);
@@ -53,8 +70,23 @@ function createPlugin(dispatch) {
53
70
  /**
54
71
  * Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
55
72
  * from `@atlaskit/editor-core`.
73
+ *
74
+ * @param options - Plugin configuration options
75
+ * @returns EditorDisabledPlugin
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Basic usage
80
+ * .add(editorDisabledPlugin)
81
+ *
82
+ * // With initial disabled state
83
+ * .add(editorDisabledPlugin, { initialDisabledState: true })
84
+ * ```
56
85
  */
57
- var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisabledPlugin() {
86
+ var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisabledPlugin(_ref) {
87
+ var _ref$config = _ref.config,
88
+ options = _ref$config === void 0 ? {} : _ref$config,
89
+ api = _ref.api;
58
90
  return {
59
91
  name: 'editorDisabled',
60
92
  getSharedState: function getSharedState(editorState) {
@@ -74,9 +106,9 @@ var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisable
74
106
  pmPlugins: function pmPlugins() {
75
107
  return [{
76
108
  name: 'editorDisabled',
77
- plugin: function plugin(_ref) {
78
- var dispatch = _ref.dispatch;
79
- return createPlugin(dispatch);
109
+ plugin: function plugin(_ref2) {
110
+ var dispatch = _ref2.dispatch;
111
+ return createPlugin(dispatch, options);
80
112
  }
81
113
  }];
82
114
  }
@@ -7,31 +7,48 @@ function reducer(_pluginState, meta) {
7
7
  return meta;
8
8
  }
9
9
  const {
10
- createPluginState,
11
10
  getPluginState
12
11
  } = pluginFactory(pluginKey, reducer);
13
- const scheduleEditorDisabledUpdate = rafSchedule(view => {
14
- if (getPluginState(view.state).editorDisabled !== !view.editable) {
15
- const tr = view.state.tr.setMeta(pluginKey, {
16
- editorDisabled: !view.editable
17
- });
18
- tr.setMeta('isLocal', true);
19
- view.dispatch(tr);
20
- }
21
- });
22
12
 
23
13
  /*
24
14
  Stores the state of the editor enabled/disabled for panel and floating
25
15
  toolbar to subscribe to through useSharedPluginState. Otherwise the NodeViews
26
16
  won't re-render when it changes.
27
17
  */
28
- function createPlugin(dispatch) {
18
+ function createPlugin(dispatch, options) {
19
+ const scheduleEditorDisabledUpdate = rafSchedule(view => {
20
+ if (getPluginState(view.state).editorDisabled !== !view.editable) {
21
+ const disabledMeta = {
22
+ editorDisabled: !view.editable
23
+ };
24
+ const tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
25
+ tr.setMeta('isLocal', true);
26
+ view.dispatch(tr);
27
+ }
28
+ });
29
29
  return new SafePlugin({
30
30
  key: pluginKey,
31
- state: createPluginState(dispatch, {
32
- editorDisabled: false
33
- }),
34
- view: () => {
31
+ state: {
32
+ init: () => {
33
+ var _options$initialDisab;
34
+ return {
35
+ editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
36
+ };
37
+ },
38
+ apply: (tr, pluginState) => {
39
+ const meta = tr.getMeta(pluginKey);
40
+ if (meta) {
41
+ return pluginState.editorDisabled !== meta.editorDisabled ? {
42
+ ...pluginState,
43
+ ...meta
44
+ } : pluginState;
45
+ }
46
+ return pluginState;
47
+ }
48
+ },
49
+ view: view => {
50
+ // schedule on mount
51
+ scheduleEditorDisabledUpdate(view);
35
52
  return {
36
53
  update(view) {
37
54
  scheduleEditorDisabledUpdate(view);
@@ -47,8 +64,23 @@ function createPlugin(dispatch) {
47
64
  /**
48
65
  * Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
49
66
  * from `@atlaskit/editor-core`.
67
+ *
68
+ * @param options - Plugin configuration options
69
+ * @returns EditorDisabledPlugin
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // Basic usage
74
+ * .add(editorDisabledPlugin)
75
+ *
76
+ * // With initial disabled state
77
+ * .add(editorDisabledPlugin, { initialDisabledState: true })
78
+ * ```
50
79
  */
51
- export const editorDisabledPlugin = () => ({
80
+ export const editorDisabledPlugin = ({
81
+ config: options = {},
82
+ api
83
+ }) => ({
52
84
  name: 'editorDisabled',
53
85
  getSharedState(editorState) {
54
86
  if (!editorState) {
@@ -68,6 +100,6 @@ export const editorDisabledPlugin = () => ({
68
100
  name: 'editorDisabled',
69
101
  plugin: ({
70
102
  dispatch
71
- }) => createPlugin(dispatch)
103
+ }) => createPlugin(dispatch, options)
72
104
  }]
73
105
  });
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  import rafSchedule from 'raf-schd';
2
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
6
  import { pluginFactory } from '@atlaskit/editor-common/utils';
@@ -7,30 +10,44 @@ function reducer(_pluginState, meta) {
7
10
  return meta;
8
11
  }
9
12
  var _pluginFactory = pluginFactory(pluginKey, reducer),
10
- createPluginState = _pluginFactory.createPluginState,
11
13
  getPluginState = _pluginFactory.getPluginState;
12
- var scheduleEditorDisabledUpdate = rafSchedule(function (view) {
13
- if (getPluginState(view.state).editorDisabled !== !view.editable) {
14
- var tr = view.state.tr.setMeta(pluginKey, {
15
- editorDisabled: !view.editable
16
- });
17
- tr.setMeta('isLocal', true);
18
- view.dispatch(tr);
19
- }
20
- });
21
14
 
22
15
  /*
23
16
  Stores the state of the editor enabled/disabled for panel and floating
24
17
  toolbar to subscribe to through useSharedPluginState. Otherwise the NodeViews
25
18
  won't re-render when it changes.
26
19
  */
27
- function createPlugin(dispatch) {
20
+ function createPlugin(dispatch, options) {
21
+ var scheduleEditorDisabledUpdate = rafSchedule(function (view) {
22
+ if (getPluginState(view.state).editorDisabled !== !view.editable) {
23
+ var disabledMeta = {
24
+ editorDisabled: !view.editable
25
+ };
26
+ var tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
27
+ tr.setMeta('isLocal', true);
28
+ view.dispatch(tr);
29
+ }
30
+ });
28
31
  return new SafePlugin({
29
32
  key: pluginKey,
30
- state: createPluginState(dispatch, {
31
- editorDisabled: false
32
- }),
33
- view: function view() {
33
+ state: {
34
+ init: function init() {
35
+ var _options$initialDisab;
36
+ return {
37
+ editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
38
+ };
39
+ },
40
+ apply: function apply(tr, pluginState) {
41
+ var meta = tr.getMeta(pluginKey);
42
+ if (meta) {
43
+ return pluginState.editorDisabled !== meta.editorDisabled ? _objectSpread(_objectSpread({}, pluginState), meta) : pluginState;
44
+ }
45
+ return pluginState;
46
+ }
47
+ },
48
+ view: function view(_view) {
49
+ // schedule on mount
50
+ scheduleEditorDisabledUpdate(_view);
34
51
  return {
35
52
  update: function update(view) {
36
53
  scheduleEditorDisabledUpdate(view);
@@ -46,8 +63,23 @@ function createPlugin(dispatch) {
46
63
  /**
47
64
  * Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
48
65
  * from `@atlaskit/editor-core`.
66
+ *
67
+ * @param options - Plugin configuration options
68
+ * @returns EditorDisabledPlugin
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * // Basic usage
73
+ * .add(editorDisabledPlugin)
74
+ *
75
+ * // With initial disabled state
76
+ * .add(editorDisabledPlugin, { initialDisabledState: true })
77
+ * ```
49
78
  */
50
- export var editorDisabledPlugin = function editorDisabledPlugin() {
79
+ export var editorDisabledPlugin = function editorDisabledPlugin(_ref) {
80
+ var _ref$config = _ref.config,
81
+ options = _ref$config === void 0 ? {} : _ref$config,
82
+ api = _ref.api;
51
83
  return {
52
84
  name: 'editorDisabled',
53
85
  getSharedState: function getSharedState(editorState) {
@@ -67,9 +99,9 @@ export var editorDisabledPlugin = function editorDisabledPlugin() {
67
99
  pmPlugins: function pmPlugins() {
68
100
  return [{
69
101
  name: 'editorDisabled',
70
- plugin: function plugin(_ref) {
71
- var dispatch = _ref.dispatch;
72
- return createPlugin(dispatch);
102
+ plugin: function plugin(_ref2) {
103
+ var dispatch = _ref2.dispatch;
104
+ return createPlugin(dispatch, options);
73
105
  }
74
106
  }];
75
107
  }
@@ -1,6 +1,18 @@
1
- import { type EditorDisabledPlugin } from './editorDisabledPluginType';
1
+ import type { EditorDisabledPlugin } from './editorDisabledPluginType';
2
2
  /**
3
3
  * Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
4
4
  * from `@atlaskit/editor-core`.
5
+ *
6
+ * @param options - Plugin configuration options
7
+ * @returns EditorDisabledPlugin
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Basic usage
12
+ * .add(editorDisabledPlugin)
13
+ *
14
+ * // With initial disabled state
15
+ * .add(editorDisabledPlugin, { initialDisabledState: true })
16
+ * ```
5
17
  */
6
18
  export declare const editorDisabledPlugin: EditorDisabledPlugin;
@@ -2,6 +2,10 @@ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  export type EditorDisabledPluginState = {
3
3
  editorDisabled: boolean;
4
4
  };
5
+ export interface EditorDisabledPluginOptions {
6
+ initialDisabledState?: boolean;
7
+ }
5
8
  export type EditorDisabledPlugin = NextEditorPlugin<'editorDisabled', {
6
9
  sharedState: EditorDisabledPluginState;
10
+ pluginConfiguration: EditorDisabledPluginOptions | undefined;
7
11
  }>;
@@ -1,2 +1,2 @@
1
1
  export { editorDisabledPlugin } from './editorDisabledPlugin';
2
- export type { EditorDisabledPluginState, EditorDisabledPlugin } from './editorDisabledPluginType';
2
+ export type { EditorDisabledPluginState, EditorDisabledPlugin, EditorDisabledPluginOptions, } from './editorDisabledPluginType';
@@ -1,6 +1,18 @@
1
- import { type EditorDisabledPlugin } from './editorDisabledPluginType';
1
+ import type { EditorDisabledPlugin } from './editorDisabledPluginType';
2
2
  /**
3
3
  * Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
4
4
  * from `@atlaskit/editor-core`.
5
+ *
6
+ * @param options - Plugin configuration options
7
+ * @returns EditorDisabledPlugin
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Basic usage
12
+ * .add(editorDisabledPlugin)
13
+ *
14
+ * // With initial disabled state
15
+ * .add(editorDisabledPlugin, { initialDisabledState: true })
16
+ * ```
5
17
  */
6
18
  export declare const editorDisabledPlugin: EditorDisabledPlugin;
@@ -2,6 +2,10 @@ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  export type EditorDisabledPluginState = {
3
3
  editorDisabled: boolean;
4
4
  };
5
+ export interface EditorDisabledPluginOptions {
6
+ initialDisabledState?: boolean;
7
+ }
5
8
  export type EditorDisabledPlugin = NextEditorPlugin<'editorDisabled', {
6
9
  sharedState: EditorDisabledPluginState;
10
+ pluginConfiguration: EditorDisabledPluginOptions | undefined;
7
11
  }>;
@@ -1,2 +1,2 @@
1
1
  export { editorDisabledPlugin } from './editorDisabledPlugin';
2
- export type { EditorDisabledPluginState, EditorDisabledPlugin } from './editorDisabledPluginType';
2
+ export type { EditorDisabledPluginState, EditorDisabledPlugin, EditorDisabledPluginOptions, } from './editorDisabledPluginType';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-editor-disabled",
3
- "version": "2.0.6",
3
+ "version": "2.1.0",
4
4
  "description": "Editor disabled plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -23,7 +23,7 @@
23
23
  ".": "./src/index.ts"
24
24
  },
25
25
  "dependencies": {
26
- "@atlaskit/editor-common": "^106.0.0",
26
+ "@atlaskit/editor-common": "^106.9.0",
27
27
  "@atlaskit/editor-prosemirror": "7.0.0",
28
28
  "@babel/runtime": "^7.0.0",
29
29
  "raf-schd": "^4.0.3"