@atlaskit/editor-plugin-editor-disabled 6.0.0 → 6.1.1
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 +16 -1
- package/dist/cjs/editorDisabledPlugin.js +55 -14
- package/dist/cjs/pm-plugins/reducer.js +31 -0
- package/dist/es2019/editorDisabledPlugin.js +50 -7
- package/dist/es2019/pm-plugins/reducer.js +21 -0
- package/dist/esm/editorDisabledPlugin.js +53 -12
- package/dist/esm/pm-plugins/reducer.js +23 -0
- package/dist/types/editorDisabledPlugin.d.ts +3 -1
- package/dist/types/editorDisabledPluginType.d.ts +6 -2
- package/dist/types/pm-plugins/reducer.d.ts +10 -0
- package/dist/types-ts4.5/editorDisabledPlugin.d.ts +3 -1
- package/dist/types-ts4.5/editorDisabledPluginType.d.ts +6 -2
- package/dist/types-ts4.5/pm-plugins/reducer.d.ts +10 -0
- package/package.json +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-editor-disabled
|
|
2
2
|
|
|
3
|
+
## 6.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4d676bbdb3ce6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4d676bbdb3ce6) -
|
|
8
|
+
ts-ignore added temporarily to unblock local consumption for help-center, will be removed once
|
|
9
|
+
project refs are setup
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 6.1.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`237dbc5b33f36`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/237dbc5b33f36) -
|
|
17
|
+
EDITOR-1919 - add toggleDisabled command to editor-plugin-editor-disabled
|
|
18
|
+
|
|
3
19
|
## 6.0.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -42,7 +58,6 @@
|
|
|
42
58
|
shared context or singletons.
|
|
43
59
|
|
|
44
60
|
**HOW TO ADJUST:**
|
|
45
|
-
|
|
46
61
|
- Consumers must now explicitly install `@atlaskit/editor-common` in their own project if they use
|
|
47
62
|
any of these editor plugins.
|
|
48
63
|
- Ensure the version you install matches the version required by the plugins.
|
|
@@ -4,19 +4,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.editorDisabledPlugin = void 0;
|
|
7
|
+
exports.pluginKey = exports.editorDisabledPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
10
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
11
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
12
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
+
var _reducer = require("./pm-plugins/reducer");
|
|
13
15
|
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
16
|
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; }
|
|
15
|
-
var pluginKey = new _state.PluginKey('editorDisabledPlugin');
|
|
16
|
-
|
|
17
|
-
return meta;
|
|
18
|
-
}
|
|
19
|
-
var _pluginFactory = (0, _utils.pluginFactory)(pluginKey, reducer),
|
|
17
|
+
var pluginKey = exports.pluginKey = new _state.PluginKey('editorDisabledPlugin');
|
|
18
|
+
var _pluginFactory = (0, _utils.pluginFactory)(pluginKey, _reducer.reducer),
|
|
20
19
|
getPluginState = _pluginFactory.getPluginState;
|
|
21
20
|
|
|
22
21
|
/*
|
|
@@ -28,7 +27,8 @@ function createPlugin(dispatch, options) {
|
|
|
28
27
|
var scheduleEditorDisabledUpdate = (0, _rafSchd.default)(function (view) {
|
|
29
28
|
if (getPluginState(view.state).editorDisabled !== !view.editable) {
|
|
30
29
|
var disabledMeta = {
|
|
31
|
-
editorDisabled: !view.editable
|
|
30
|
+
editorDisabled: !view.editable,
|
|
31
|
+
disabledByPlugin: getPluginState(view.state).disabledByPlugin
|
|
32
32
|
};
|
|
33
33
|
var tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
|
|
34
34
|
tr.setMeta('isLocal', true);
|
|
@@ -41,24 +41,49 @@ function createPlugin(dispatch, options) {
|
|
|
41
41
|
init: function init() {
|
|
42
42
|
var _options$initialDisab;
|
|
43
43
|
return {
|
|
44
|
-
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
|
|
44
|
+
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false,
|
|
45
|
+
disabledByPlugin: false
|
|
45
46
|
};
|
|
46
47
|
},
|
|
48
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
49
|
+
|
|
47
50
|
apply: function apply(tr, pluginState) {
|
|
48
51
|
var meta = tr.getMeta(pluginKey);
|
|
49
52
|
if (meta) {
|
|
53
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
54
|
+
if ('action' in meta) {
|
|
55
|
+
return (0, _reducer.reducer)(pluginState, meta);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
50
58
|
return pluginState.editorDisabled !== meta.editorDisabled ? _objectSpread(_objectSpread({}, pluginState), meta) : pluginState;
|
|
51
59
|
}
|
|
52
60
|
return pluginState;
|
|
53
61
|
}
|
|
54
62
|
},
|
|
63
|
+
props: {
|
|
64
|
+
// If we set to undefined it respects the previous value.
|
|
65
|
+
// Prosemirror doesn't have this typed correctly for this type of behaviour
|
|
66
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
67
|
+
editable: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta') ? function (state) {
|
|
68
|
+
var _pluginKey$getState;
|
|
69
|
+
var _ref = (_pluginKey$getState = pluginKey.getState(state)) !== null && _pluginKey$getState !== void 0 ? _pluginKey$getState : {
|
|
70
|
+
disabledByPlugin: false
|
|
71
|
+
},
|
|
72
|
+
disabledByPlugin = _ref.disabledByPlugin;
|
|
73
|
+
return disabledByPlugin ? false : undefined;
|
|
74
|
+
} : undefined
|
|
75
|
+
},
|
|
76
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
77
|
+
|
|
55
78
|
view: function view(_view) {
|
|
56
79
|
// schedule on mount
|
|
57
80
|
scheduleEditorDisabledUpdate(_view);
|
|
58
81
|
return {
|
|
82
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
59
83
|
update: function update(view) {
|
|
60
84
|
scheduleEditorDisabledUpdate(view);
|
|
61
85
|
},
|
|
86
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
62
87
|
destroy: function destroy() {
|
|
63
88
|
scheduleEditorDisabledUpdate.cancel();
|
|
64
89
|
}
|
|
@@ -83,10 +108,10 @@ function createPlugin(dispatch, options) {
|
|
|
83
108
|
* .add(editorDisabledPlugin, { initialDisabledState: true })
|
|
84
109
|
* ```
|
|
85
110
|
*/
|
|
86
|
-
var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisabledPlugin(
|
|
87
|
-
var
|
|
88
|
-
options =
|
|
89
|
-
api =
|
|
111
|
+
var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisabledPlugin(_ref2) {
|
|
112
|
+
var _ref2$config = _ref2.config,
|
|
113
|
+
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
114
|
+
api = _ref2.api;
|
|
90
115
|
return {
|
|
91
116
|
name: 'editorDisabled',
|
|
92
117
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -101,16 +126,32 @@ var editorDisabledPlugin = exports.editorDisabledPlugin = function editorDisable
|
|
|
101
126
|
editorDisabled: false
|
|
102
127
|
};
|
|
103
128
|
}
|
|
129
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
130
|
+
return {
|
|
131
|
+
editorDisabled: pluginState.disabledByPlugin || pluginState.editorDisabled
|
|
132
|
+
};
|
|
133
|
+
}
|
|
104
134
|
return pluginState;
|
|
105
135
|
},
|
|
106
136
|
pmPlugins: function pmPlugins() {
|
|
107
137
|
return [{
|
|
108
138
|
name: 'editorDisabled',
|
|
109
|
-
plugin: function plugin(
|
|
110
|
-
var dispatch =
|
|
139
|
+
plugin: function plugin(_ref3) {
|
|
140
|
+
var dispatch = _ref3.dispatch;
|
|
111
141
|
return createPlugin(dispatch, options);
|
|
112
142
|
}
|
|
113
143
|
}];
|
|
144
|
+
},
|
|
145
|
+
commands: {
|
|
146
|
+
toggleDisabled: function toggleDisabled(disabled) {
|
|
147
|
+
return function (_ref4) {
|
|
148
|
+
var tr = _ref4.tr;
|
|
149
|
+
return (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta') ? tr.setMeta(pluginKey, {
|
|
150
|
+
action: _reducer.ACTION.TOGGLE_DISABLED,
|
|
151
|
+
disabled: disabled
|
|
152
|
+
}) : null;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
114
155
|
}
|
|
115
156
|
};
|
|
116
157
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ACTION = void 0;
|
|
8
|
+
exports.reducer = reducer;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
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; }
|
|
11
|
+
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
|
+
var ACTION = exports.ACTION = /*#__PURE__*/function (ACTION) {
|
|
13
|
+
ACTION["TOGGLE_DISABLED"] = "TOGGLE_DISABLED";
|
|
14
|
+
return ACTION;
|
|
15
|
+
}({});
|
|
16
|
+
function reducer(pluginState, meta) {
|
|
17
|
+
if (meta && 'action' in meta) {
|
|
18
|
+
switch (meta.action) {
|
|
19
|
+
case ACTION.TOGGLE_DISABLED:
|
|
20
|
+
if (meta.disabled === pluginState.disabledByPlugin) {
|
|
21
|
+
return pluginState;
|
|
22
|
+
}
|
|
23
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
24
|
+
disabledByPlugin: Boolean(meta.disabled)
|
|
25
|
+
});
|
|
26
|
+
default:
|
|
27
|
+
return pluginState;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return pluginState;
|
|
31
|
+
}
|
|
@@ -2,10 +2,9 @@ import rafSchedule from 'raf-schd';
|
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
+
import { ACTION, reducer } from './pm-plugins/reducer';
|
|
7
|
+
export const pluginKey = new PluginKey('editorDisabledPlugin');
|
|
9
8
|
const {
|
|
10
9
|
getPluginState
|
|
11
10
|
} = pluginFactory(pluginKey, reducer);
|
|
@@ -19,7 +18,8 @@ function createPlugin(dispatch, options) {
|
|
|
19
18
|
const scheduleEditorDisabledUpdate = rafSchedule(view => {
|
|
20
19
|
if (getPluginState(view.state).editorDisabled !== !view.editable) {
|
|
21
20
|
const disabledMeta = {
|
|
22
|
-
editorDisabled: !view.editable
|
|
21
|
+
editorDisabled: !view.editable,
|
|
22
|
+
disabledByPlugin: getPluginState(view.state).disabledByPlugin
|
|
23
23
|
};
|
|
24
24
|
const tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
|
|
25
25
|
tr.setMeta('isLocal', true);
|
|
@@ -32,12 +32,20 @@ function createPlugin(dispatch, options) {
|
|
|
32
32
|
init: () => {
|
|
33
33
|
var _options$initialDisab;
|
|
34
34
|
return {
|
|
35
|
-
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
|
|
35
|
+
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false,
|
|
36
|
+
disabledByPlugin: false
|
|
36
37
|
};
|
|
37
38
|
},
|
|
39
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
40
|
+
|
|
38
41
|
apply: (tr, pluginState) => {
|
|
39
42
|
const meta = tr.getMeta(pluginKey);
|
|
40
43
|
if (meta) {
|
|
44
|
+
if (fg('platform_editor_ai_aifc_patch_beta')) {
|
|
45
|
+
if ('action' in meta) {
|
|
46
|
+
return reducer(pluginState, meta);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
41
49
|
return pluginState.editorDisabled !== meta.editorDisabled ? {
|
|
42
50
|
...pluginState,
|
|
43
51
|
...meta
|
|
@@ -46,13 +54,33 @@ function createPlugin(dispatch, options) {
|
|
|
46
54
|
return pluginState;
|
|
47
55
|
}
|
|
48
56
|
},
|
|
57
|
+
props: {
|
|
58
|
+
// If we set to undefined it respects the previous value.
|
|
59
|
+
// Prosemirror doesn't have this typed correctly for this type of behaviour
|
|
60
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
61
|
+
editable: fg('platform_editor_ai_aifc_patch_beta') ? state => {
|
|
62
|
+
var _pluginKey$getState;
|
|
63
|
+
const {
|
|
64
|
+
disabledByPlugin
|
|
65
|
+
} = (_pluginKey$getState = pluginKey.getState(state)) !== null && _pluginKey$getState !== void 0 ? _pluginKey$getState : {
|
|
66
|
+
disabledByPlugin: false
|
|
67
|
+
};
|
|
68
|
+
return disabledByPlugin ? false : undefined;
|
|
69
|
+
} : undefined
|
|
70
|
+
},
|
|
71
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
72
|
+
|
|
49
73
|
view: view => {
|
|
50
74
|
// schedule on mount
|
|
51
75
|
scheduleEditorDisabledUpdate(view);
|
|
52
76
|
return {
|
|
77
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
78
|
+
|
|
53
79
|
update(view) {
|
|
54
80
|
scheduleEditorDisabledUpdate(view);
|
|
55
81
|
},
|
|
82
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
83
|
+
|
|
56
84
|
destroy() {
|
|
57
85
|
scheduleEditorDisabledUpdate.cancel();
|
|
58
86
|
}
|
|
@@ -94,6 +122,11 @@ export const editorDisabledPlugin = ({
|
|
|
94
122
|
editorDisabled: false
|
|
95
123
|
};
|
|
96
124
|
}
|
|
125
|
+
if (fg('platform_editor_ai_aifc_patch_beta')) {
|
|
126
|
+
return {
|
|
127
|
+
editorDisabled: pluginState.disabledByPlugin || pluginState.editorDisabled
|
|
128
|
+
};
|
|
129
|
+
}
|
|
97
130
|
return pluginState;
|
|
98
131
|
},
|
|
99
132
|
pmPlugins: () => [{
|
|
@@ -101,5 +134,15 @@ export const editorDisabledPlugin = ({
|
|
|
101
134
|
plugin: ({
|
|
102
135
|
dispatch
|
|
103
136
|
}) => createPlugin(dispatch, options)
|
|
104
|
-
}]
|
|
137
|
+
}],
|
|
138
|
+
commands: {
|
|
139
|
+
toggleDisabled: disabled => ({
|
|
140
|
+
tr
|
|
141
|
+
}) => {
|
|
142
|
+
return fg('platform_editor_ai_aifc_patch_beta') ? tr.setMeta(pluginKey, {
|
|
143
|
+
action: ACTION.TOGGLE_DISABLED,
|
|
144
|
+
disabled
|
|
145
|
+
}) : null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
105
148
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export let ACTION = /*#__PURE__*/function (ACTION) {
|
|
2
|
+
ACTION["TOGGLE_DISABLED"] = "TOGGLE_DISABLED";
|
|
3
|
+
return ACTION;
|
|
4
|
+
}({});
|
|
5
|
+
export function reducer(pluginState, meta) {
|
|
6
|
+
if (meta && 'action' in meta) {
|
|
7
|
+
switch (meta.action) {
|
|
8
|
+
case ACTION.TOGGLE_DISABLED:
|
|
9
|
+
if (meta.disabled === pluginState.disabledByPlugin) {
|
|
10
|
+
return pluginState;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
...pluginState,
|
|
14
|
+
disabledByPlugin: Boolean(meta.disabled)
|
|
15
|
+
};
|
|
16
|
+
default:
|
|
17
|
+
return pluginState;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return pluginState;
|
|
21
|
+
}
|
|
@@ -5,10 +5,9 @@ import rafSchedule from 'raf-schd';
|
|
|
5
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
6
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
|
+
import { ACTION, reducer } from './pm-plugins/reducer';
|
|
10
|
+
export var pluginKey = new PluginKey('editorDisabledPlugin');
|
|
12
11
|
var _pluginFactory = pluginFactory(pluginKey, reducer),
|
|
13
12
|
getPluginState = _pluginFactory.getPluginState;
|
|
14
13
|
|
|
@@ -21,7 +20,8 @@ function createPlugin(dispatch, options) {
|
|
|
21
20
|
var scheduleEditorDisabledUpdate = rafSchedule(function (view) {
|
|
22
21
|
if (getPluginState(view.state).editorDisabled !== !view.editable) {
|
|
23
22
|
var disabledMeta = {
|
|
24
|
-
editorDisabled: !view.editable
|
|
23
|
+
editorDisabled: !view.editable,
|
|
24
|
+
disabledByPlugin: getPluginState(view.state).disabledByPlugin
|
|
25
25
|
};
|
|
26
26
|
var tr = view.state.tr.setMeta(pluginKey, disabledMeta).setMeta('editorDisabledPlugin', disabledMeta);
|
|
27
27
|
tr.setMeta('isLocal', true);
|
|
@@ -34,24 +34,49 @@ function createPlugin(dispatch, options) {
|
|
|
34
34
|
init: function init() {
|
|
35
35
|
var _options$initialDisab;
|
|
36
36
|
return {
|
|
37
|
-
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false
|
|
37
|
+
editorDisabled: (_options$initialDisab = options === null || options === void 0 ? void 0 : options.initialDisabledState) !== null && _options$initialDisab !== void 0 ? _options$initialDisab : false,
|
|
38
|
+
disabledByPlugin: false
|
|
38
39
|
};
|
|
39
40
|
},
|
|
41
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
42
|
+
|
|
40
43
|
apply: function apply(tr, pluginState) {
|
|
41
44
|
var meta = tr.getMeta(pluginKey);
|
|
42
45
|
if (meta) {
|
|
46
|
+
if (fg('platform_editor_ai_aifc_patch_beta')) {
|
|
47
|
+
if ('action' in meta) {
|
|
48
|
+
return reducer(pluginState, meta);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
43
51
|
return pluginState.editorDisabled !== meta.editorDisabled ? _objectSpread(_objectSpread({}, pluginState), meta) : pluginState;
|
|
44
52
|
}
|
|
45
53
|
return pluginState;
|
|
46
54
|
}
|
|
47
55
|
},
|
|
56
|
+
props: {
|
|
57
|
+
// If we set to undefined it respects the previous value.
|
|
58
|
+
// Prosemirror doesn't have this typed correctly for this type of behaviour
|
|
59
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
60
|
+
editable: fg('platform_editor_ai_aifc_patch_beta') ? function (state) {
|
|
61
|
+
var _pluginKey$getState;
|
|
62
|
+
var _ref = (_pluginKey$getState = pluginKey.getState(state)) !== null && _pluginKey$getState !== void 0 ? _pluginKey$getState : {
|
|
63
|
+
disabledByPlugin: false
|
|
64
|
+
},
|
|
65
|
+
disabledByPlugin = _ref.disabledByPlugin;
|
|
66
|
+
return disabledByPlugin ? false : undefined;
|
|
67
|
+
} : undefined
|
|
68
|
+
},
|
|
69
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
70
|
+
|
|
48
71
|
view: function view(_view) {
|
|
49
72
|
// schedule on mount
|
|
50
73
|
scheduleEditorDisabledUpdate(_view);
|
|
51
74
|
return {
|
|
75
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
52
76
|
update: function update(view) {
|
|
53
77
|
scheduleEditorDisabledUpdate(view);
|
|
54
78
|
},
|
|
79
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
55
80
|
destroy: function destroy() {
|
|
56
81
|
scheduleEditorDisabledUpdate.cancel();
|
|
57
82
|
}
|
|
@@ -76,10 +101,10 @@ function createPlugin(dispatch, options) {
|
|
|
76
101
|
* .add(editorDisabledPlugin, { initialDisabledState: true })
|
|
77
102
|
* ```
|
|
78
103
|
*/
|
|
79
|
-
export var editorDisabledPlugin = function editorDisabledPlugin(
|
|
80
|
-
var
|
|
81
|
-
options =
|
|
82
|
-
api =
|
|
104
|
+
export var editorDisabledPlugin = function editorDisabledPlugin(_ref2) {
|
|
105
|
+
var _ref2$config = _ref2.config,
|
|
106
|
+
options = _ref2$config === void 0 ? {} : _ref2$config,
|
|
107
|
+
api = _ref2.api;
|
|
83
108
|
return {
|
|
84
109
|
name: 'editorDisabled',
|
|
85
110
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -94,16 +119,32 @@ export var editorDisabledPlugin = function editorDisabledPlugin(_ref) {
|
|
|
94
119
|
editorDisabled: false
|
|
95
120
|
};
|
|
96
121
|
}
|
|
122
|
+
if (fg('platform_editor_ai_aifc_patch_beta')) {
|
|
123
|
+
return {
|
|
124
|
+
editorDisabled: pluginState.disabledByPlugin || pluginState.editorDisabled
|
|
125
|
+
};
|
|
126
|
+
}
|
|
97
127
|
return pluginState;
|
|
98
128
|
},
|
|
99
129
|
pmPlugins: function pmPlugins() {
|
|
100
130
|
return [{
|
|
101
131
|
name: 'editorDisabled',
|
|
102
|
-
plugin: function plugin(
|
|
103
|
-
var dispatch =
|
|
132
|
+
plugin: function plugin(_ref3) {
|
|
133
|
+
var dispatch = _ref3.dispatch;
|
|
104
134
|
return createPlugin(dispatch, options);
|
|
105
135
|
}
|
|
106
136
|
}];
|
|
137
|
+
},
|
|
138
|
+
commands: {
|
|
139
|
+
toggleDisabled: function toggleDisabled(disabled) {
|
|
140
|
+
return function (_ref4) {
|
|
141
|
+
var tr = _ref4.tr;
|
|
142
|
+
return fg('platform_editor_ai_aifc_patch_beta') ? tr.setMeta(pluginKey, {
|
|
143
|
+
action: ACTION.TOGGLE_DISABLED,
|
|
144
|
+
disabled: disabled
|
|
145
|
+
}) : null;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
107
148
|
}
|
|
108
149
|
};
|
|
109
150
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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; }
|
|
4
|
+
export var ACTION = /*#__PURE__*/function (ACTION) {
|
|
5
|
+
ACTION["TOGGLE_DISABLED"] = "TOGGLE_DISABLED";
|
|
6
|
+
return ACTION;
|
|
7
|
+
}({});
|
|
8
|
+
export function reducer(pluginState, meta) {
|
|
9
|
+
if (meta && 'action' in meta) {
|
|
10
|
+
switch (meta.action) {
|
|
11
|
+
case ACTION.TOGGLE_DISABLED:
|
|
12
|
+
if (meta.disabled === pluginState.disabledByPlugin) {
|
|
13
|
+
return pluginState;
|
|
14
|
+
}
|
|
15
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
16
|
+
disabledByPlugin: Boolean(meta.disabled)
|
|
17
|
+
});
|
|
18
|
+
default:
|
|
19
|
+
return pluginState;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return pluginState;
|
|
23
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { EditorDisabledPlugin, EditorDisabledPluginState } from './editorDisabledPluginType';
|
|
3
|
+
export declare const pluginKey: PluginKey<EditorDisabledPluginState>;
|
|
2
4
|
/**
|
|
3
5
|
* Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
4
6
|
* from `@atlaskit/editor-core`.
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
export type EditorDisabledPluginState = {
|
|
3
|
+
disabledByPlugin: boolean;
|
|
3
4
|
editorDisabled: boolean;
|
|
4
5
|
};
|
|
5
6
|
export interface EditorDisabledPluginOptions {
|
|
6
7
|
initialDisabledState?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export type EditorDisabledPlugin = NextEditorPlugin<'editorDisabled', {
|
|
10
|
+
commands: {
|
|
11
|
+
toggleDisabled: (disabled: boolean) => EditorCommand;
|
|
12
|
+
};
|
|
9
13
|
pluginConfiguration: EditorDisabledPluginOptions | undefined;
|
|
10
|
-
sharedState: EditorDisabledPluginState
|
|
14
|
+
sharedState: Pick<EditorDisabledPluginState, 'editorDisabled'>;
|
|
11
15
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditorDisabledPluginState } from '../editorDisabledPluginType';
|
|
2
|
+
export declare enum ACTION {
|
|
3
|
+
TOGGLE_DISABLED = "TOGGLE_DISABLED"
|
|
4
|
+
}
|
|
5
|
+
type ToggleDisabledMeta = {
|
|
6
|
+
action: ACTION.TOGGLE_DISABLED;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function reducer(pluginState: EditorDisabledPluginState, meta: ToggleDisabledMeta | EditorDisabledPluginState): EditorDisabledPluginState;
|
|
10
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { EditorDisabledPlugin, EditorDisabledPluginState } from './editorDisabledPluginType';
|
|
3
|
+
export declare const pluginKey: PluginKey<EditorDisabledPluginState>;
|
|
2
4
|
/**
|
|
3
5
|
* Editor disabled plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
4
6
|
* from `@atlaskit/editor-core`.
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
export type EditorDisabledPluginState = {
|
|
3
|
+
disabledByPlugin: boolean;
|
|
3
4
|
editorDisabled: boolean;
|
|
4
5
|
};
|
|
5
6
|
export interface EditorDisabledPluginOptions {
|
|
6
7
|
initialDisabledState?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export type EditorDisabledPlugin = NextEditorPlugin<'editorDisabled', {
|
|
10
|
+
commands: {
|
|
11
|
+
toggleDisabled: (disabled: boolean) => EditorCommand;
|
|
12
|
+
};
|
|
9
13
|
pluginConfiguration: EditorDisabledPluginOptions | undefined;
|
|
10
|
-
sharedState: EditorDisabledPluginState
|
|
14
|
+
sharedState: Pick<EditorDisabledPluginState, 'editorDisabled'>;
|
|
11
15
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditorDisabledPluginState } from '../editorDisabledPluginType';
|
|
2
|
+
export declare enum ACTION {
|
|
3
|
+
TOGGLE_DISABLED = "TOGGLE_DISABLED"
|
|
4
|
+
}
|
|
5
|
+
type ToggleDisabledMeta = {
|
|
6
|
+
action: ACTION.TOGGLE_DISABLED;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function reducer(pluginState: EditorDisabledPluginState, meta: ToggleDisabledMeta | EditorDisabledPluginState): EditorDisabledPluginState;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-editor-disabled",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Editor disabled plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,13 +18,19 @@
|
|
|
18
18
|
"types": "dist/types/index.d.ts",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
|
+
"platform-feature-flags": {
|
|
22
|
+
"platform_editor_ai_aifc_patch_beta": {
|
|
23
|
+
"type": "boolean"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
21
26
|
"dependencies": {
|
|
22
27
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
28
|
+
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
23
29
|
"@babel/runtime": "^7.0.0",
|
|
24
30
|
"raf-schd": "^4.0.3"
|
|
25
31
|
},
|
|
26
32
|
"peerDependencies": {
|
|
27
|
-
"@atlaskit/editor-common": "^110.
|
|
33
|
+
"@atlaskit/editor-common": "^110.34.0",
|
|
28
34
|
"react": "^18.2.0",
|
|
29
35
|
"react-dom": "^18.2.0"
|
|
30
36
|
},
|