@atlaskit/editor-plugin-rule 1.0.0 → 1.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 CHANGED
@@ -1,5 +1,66 @@
1
1
  # @atlaskit/editor-plugin-rule
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#75482](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/75482) [`18b5a6fb910a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/18b5a6fb910a) - # MAJOR CHANGE to `@atlaskit/prosemirror-input-rules` package.
8
+
9
+ ## WHY?
10
+
11
+ Removing editor-common dependencies from prosemirror-input-rules package.
12
+
13
+ This makes it easier for editor updates because it simplifies our dependency graph.
14
+
15
+ ## WHAT and HOW?
16
+
17
+ These are no longer available via `@atlaskit/prosemirror-input-rules` but are available from `@atlaskit/editor-common/types`:
18
+
19
+ - InputRuleWrapper
20
+ - InputRuleHandler
21
+ - OnHandlerApply
22
+ - createRule
23
+
24
+ These have changed from a `SafePlugin` to a `SafePluginSpec`. In order to update your code you need to instantiate a `SafePlugin` (ie. `new SafePlugin(createPlugin( ... ))`).
25
+
26
+ `SafePlugin` exists in `@atlaskit/editor-common/safe-plugin`.
27
+
28
+ - createPlugin
29
+ - createInputRulePlugin
30
+
31
+ - Updated dependencies
32
+
33
+ ## 1.1.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [#72122](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72122) [`c3186450404a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3186450404a) - Breaking change:
38
+
39
+ ## WHAT?:
40
+
41
+ Removing feature flags:
42
+
43
+ - singleLayout
44
+ - newInsertionBehaviour
45
+ - interactiveExpand
46
+ - findReplace
47
+ - findReplaceMatchCase
48
+ - extendFloatingToolbar
49
+
50
+ ## WHY?:
51
+
52
+ Because the flags and props are unused/by default active. Removing them will reduce our maintenance burden
53
+
54
+ ## HOW to update your code:
55
+
56
+ - If you were using the feature flag - the behaviour is now default and you can remove the flags
57
+ - If you were not using the feature flag - the behaviour is now default.
58
+ - If you have opted out of using the feature flag - we have been careful to ensure no-one has opted out of the behaviours. If you do have an issue please reach out to #help-editor.
59
+
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies
63
+
3
64
  ## 1.0.0
4
65
 
5
66
  ### Major Changes
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.insertHorizontalRule = void 0;
7
7
  var _inputRule = require("./pm-plugins/input-rule");
8
- var insertHorizontalRule = exports.insertHorizontalRule = function insertHorizontalRule(featureFlags, editorAnalyticsAPI) {
8
+ var insertHorizontalRule = exports.insertHorizontalRule = function insertHorizontalRule(editorAnalyticsAPI) {
9
9
  return function (inputMethod) {
10
10
  return function (state, dispatch) {
11
- var tr = (0, _inputRule.createHorizontalRule)(state, featureFlags, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
11
+ var tr = (0, _inputRule.createHorizontalRule)(state, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
12
12
  if (tr) {
13
13
  if (dispatch) {
14
14
  dispatch(tr);
@@ -14,9 +14,8 @@ var _commands = require("./commands");
14
14
  var _inputRule = _interopRequireDefault(require("./pm-plugins/input-rule"));
15
15
  var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
16
16
  var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
17
- var _api$featureFlags, _api$analytics;
17
+ var _api$analytics;
18
18
  var api = _ref.api;
19
- var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
20
19
  return {
21
20
  name: 'rule',
22
21
  nodes: function nodes() {
@@ -26,7 +25,7 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
26
25
  }];
27
26
  },
28
27
  actions: {
29
- insertHorizontalRule: (0, _commands.insertHorizontalRule)(featureFlags, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
28
+ insertHorizontalRule: (0, _commands.insertHorizontalRule)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
30
29
  },
31
30
  pmPlugins: function pmPlugins() {
32
31
  return [{
@@ -34,13 +33,13 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
34
33
  plugin: function plugin(_ref2) {
35
34
  var _api$analytics2;
36
35
  var schema = _ref2.schema;
37
- return (0, _inputRule.default)(schema, featureFlags, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
36
+ return (0, _inputRule.default)(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
38
37
  }
39
38
  }, {
40
39
  name: 'ruleKeymap',
41
40
  plugin: function plugin() {
42
41
  var _api$analytics3;
43
- return (0, _keymap.default)(featureFlags, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
42
+ return (0, _keymap.default)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
44
43
  }
45
44
  }];
46
45
  },
@@ -7,25 +7,24 @@ exports.default = exports.createHorizontalRule = void 0;
7
7
  exports.inputRulePlugin = inputRulePlugin;
8
8
  var _analytics = require("@atlaskit/editor-common/analytics");
9
9
  var _insert = require("@atlaskit/editor-common/insert");
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _utils = require("@atlaskit/editor-common/utils");
10
12
  var _model = require("@atlaskit/editor-prosemirror/model");
11
- var _utils = require("@atlaskit/editor-prosemirror/utils");
13
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
12
14
  var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
13
- var createHorizontalRule = exports.createHorizontalRule = function createHorizontalRule(state, featureFlags, start, end, inputMethod, editorAnalyticsAPI) {
15
+ var createHorizontalRule = exports.createHorizontalRule = function createHorizontalRule(state, start, end, inputMethod, editorAnalyticsAPI) {
14
16
  if (!state.selection.empty) {
15
17
  return null;
16
18
  }
17
19
  var tr = null;
18
20
  var rule = state.schema.nodes.rule;
19
- var newInsertionBehaviour = featureFlags.newInsertionBehaviour;
20
- if (newInsertionBehaviour) {
21
- /**
22
- * This is a workaround to get rid of the typeahead text when using quick insert
23
- * Once we insert *nothing*, we get a new transaction, so we can use the new selection
24
- * without considering the extra text after the `/` command.
25
- **/
26
- tr = state.tr.replaceWith(start, end, _model.Fragment.empty);
27
- tr = (0, _insert.safeInsert)(rule.createChecked(), tr.selection.from)(tr);
28
- }
21
+ /**
22
+ * This is a workaround to get rid of the typeahead text when using quick insert
23
+ * Once we insert *nothing*, we get a new transaction, so we can use the new selection
24
+ * without considering the extra text after the `/` command.
25
+ **/
26
+ tr = state.tr.replaceWith(start, end, _model.Fragment.empty);
27
+ tr = (0, _insert.safeInsert)(rule.createChecked(), tr.selection.from)(tr);
29
28
  if (!tr) {
30
29
  tr = state.tr.replaceRange(start, end, new _model.Slice(_model.Fragment.from(state.schema.nodes.rule.createChecked()), 0, 0));
31
30
  }
@@ -40,34 +39,34 @@ var createHorizontalRule = exports.createHorizontalRule = function createHorizon
40
39
  })(tr);
41
40
  return tr;
42
41
  };
43
- var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI) {
42
+ var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI) {
44
43
  var listItem = state.schema.nodes.listItem;
45
- if ((0, _utils.hasParentNodeOfType)(listItem)(state.selection)) {
44
+ if ((0, _utils2.hasParentNodeOfType)(listItem)(state.selection)) {
46
45
  return null;
47
46
  }
48
- return createHorizontalRule(state, featureFlags, start, end, _analytics.INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
47
+ return createHorizontalRule(state, start, end, _analytics.INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
49
48
  };
50
- function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
49
+ function inputRulePlugin(schema, editorAnalyticsAPI) {
51
50
  var rules = [];
52
51
  if (schema.nodes.rule) {
53
52
  // '---' and '***' for hr
54
- rules.push((0, _prosemirrorInputRules.createRule)(/^(\-\-\-|\*\*\*)$/, function (state, _match, start, end) {
55
- return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
53
+ rules.push((0, _utils.createRule)(/^(\-\-\-|\*\*\*)$/, function (state, _match, start, end) {
54
+ return createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI);
56
55
  }));
57
56
 
58
57
  // '---' and '***' after shift+enter for hr
59
- rules.push((0, _prosemirrorInputRules.createRule)(new RegExp("".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "(\\-\\-\\-|\\*\\*\\*)")), function (state, _match, start, end) {
58
+ rules.push((0, _utils.createRule)(new RegExp("".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "(\\-\\-\\-|\\*\\*\\*)")), function (state, _match, start, end) {
60
59
  var hardBreak = state.schema.nodes.hardBreak;
61
60
  if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
62
61
  return null;
63
62
  }
64
- return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
63
+ return createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI);
65
64
  }));
66
65
  }
67
66
  if (rules.length !== 0) {
68
- return (0, _prosemirrorInputRules.createPlugin)('rule', rules, {
67
+ return new _safePlugin.SafePlugin((0, _prosemirrorInputRules.createPlugin)('rule', rules, {
69
68
  isBlockNodeRule: true
70
- });
69
+ }));
71
70
  }
72
71
  return;
73
72
  }
@@ -9,9 +9,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
9
9
  var _keymaps = require("@atlaskit/editor-common/keymaps");
10
10
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
11
11
  var _commands = require("../commands");
12
- function keymapPlugin(featureFlags, editorAnalyticsAPI) {
12
+ function keymapPlugin(editorAnalyticsAPI) {
13
13
  var list = {};
14
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.insertRule.common, (0, _commands.insertHorizontalRule)(featureFlags, editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
14
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.insertRule.common, (0, _commands.insertHorizontalRule)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.SHORTCUT), list);
15
15
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.escape.common, function () {
16
16
  return true;
17
17
  }, list);
@@ -1,6 +1,6 @@
1
1
  import { createHorizontalRule } from './pm-plugins/input-rule';
2
- export const insertHorizontalRule = (featureFlags, editorAnalyticsAPI) => inputMethod => (state, dispatch) => {
3
- const tr = createHorizontalRule(state, featureFlags, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
2
+ export const insertHorizontalRule = editorAnalyticsAPI => inputMethod => (state, dispatch) => {
3
+ const tr = createHorizontalRule(state, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
4
4
  if (tr) {
5
5
  if (dispatch) {
6
6
  dispatch(tr);
@@ -9,8 +9,7 @@ import keymapPlugin from './pm-plugins/keymap';
9
9
  export const rulePlugin = ({
10
10
  api
11
11
  }) => {
12
- var _api$featureFlags, _api$analytics;
13
- const featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
12
+ var _api$analytics;
14
13
  return {
15
14
  name: 'rule',
16
15
  nodes() {
@@ -20,7 +19,7 @@ export const rulePlugin = ({
20
19
  }];
21
20
  },
22
21
  actions: {
23
- insertHorizontalRule: insertHorizontalRule(featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
22
+ insertHorizontalRule: insertHorizontalRule(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
24
23
  },
25
24
  pmPlugins() {
26
25
  return [{
@@ -29,13 +28,13 @@ export const rulePlugin = ({
29
28
  schema
30
29
  }) => {
31
30
  var _api$analytics2;
32
- return inputRulePlugin(schema, featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
31
+ return inputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
33
32
  }
34
33
  }, {
35
34
  name: 'ruleKeymap',
36
35
  plugin: () => {
37
36
  var _api$analytics3;
38
- return keymapPlugin(featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
37
+ return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
39
38
  }
40
39
  }];
41
40
  },
@@ -1,9 +1,11 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { safeInsert } from '@atlaskit/editor-common/insert';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { createRule } from '@atlaskit/editor-common/utils';
3
5
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
4
6
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { createPlugin, createRule, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
6
- export const createHorizontalRule = (state, featureFlags, start, end, inputMethod, editorAnalyticsAPI) => {
7
+ import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
8
+ export const createHorizontalRule = (state, start, end, inputMethod, editorAnalyticsAPI) => {
7
9
  if (!state.selection.empty) {
8
10
  return null;
9
11
  }
@@ -11,18 +13,13 @@ export const createHorizontalRule = (state, featureFlags, start, end, inputMetho
11
13
  const {
12
14
  rule
13
15
  } = state.schema.nodes;
14
- const {
15
- newInsertionBehaviour
16
- } = featureFlags;
17
- if (newInsertionBehaviour) {
18
- /**
19
- * This is a workaround to get rid of the typeahead text when using quick insert
20
- * Once we insert *nothing*, we get a new transaction, so we can use the new selection
21
- * without considering the extra text after the `/` command.
22
- **/
23
- tr = state.tr.replaceWith(start, end, Fragment.empty);
24
- tr = safeInsert(rule.createChecked(), tr.selection.from)(tr);
25
- }
16
+ /**
17
+ * This is a workaround to get rid of the typeahead text when using quick insert
18
+ * Once we insert *nothing*, we get a new transaction, so we can use the new selection
19
+ * without considering the extra text after the `/` command.
20
+ **/
21
+ tr = state.tr.replaceWith(start, end, Fragment.empty);
22
+ tr = safeInsert(rule.createChecked(), tr.selection.from)(tr);
26
23
  if (!tr) {
27
24
  tr = state.tr.replaceRange(start, end, new Slice(Fragment.from(state.schema.nodes.rule.createChecked()), 0, 0));
28
25
  }
@@ -37,20 +34,20 @@ export const createHorizontalRule = (state, featureFlags, start, end, inputMetho
37
34
  })(tr);
38
35
  return tr;
39
36
  };
40
- const createHorizontalRuleAutoformat = (state, featureFlags, start, end, editorAnalyticsAPI) => {
37
+ const createHorizontalRuleAutoformat = (state, start, end, editorAnalyticsAPI) => {
41
38
  const {
42
39
  listItem
43
40
  } = state.schema.nodes;
44
41
  if (hasParentNodeOfType(listItem)(state.selection)) {
45
42
  return null;
46
43
  }
47
- return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
44
+ return createHorizontalRule(state, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
48
45
  };
49
- export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
46
+ export function inputRulePlugin(schema, editorAnalyticsAPI) {
50
47
  const rules = [];
51
48
  if (schema.nodes.rule) {
52
49
  // '---' and '***' for hr
53
- rules.push(createRule(/^(\-\-\-|\*\*\*)$/, (state, _match, start, end) => createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI)));
50
+ rules.push(createRule(/^(\-\-\-|\*\*\*)$/, (state, _match, start, end) => createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI)));
54
51
 
55
52
  // '---' and '***' after shift+enter for hr
56
53
  rules.push(createRule(new RegExp(`${leafNodeReplacementCharacter}(\\-\\-\\-|\\*\\*\\*)`), (state, _match, start, end) => {
@@ -60,13 +57,13 @@ export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
60
57
  if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
61
58
  return null;
62
59
  }
63
- return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
60
+ return createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI);
64
61
  }));
65
62
  }
66
63
  if (rules.length !== 0) {
67
- return createPlugin('rule', rules, {
64
+ return new SafePlugin(createPlugin('rule', rules, {
68
65
  isBlockNodeRule: true
69
- });
66
+ }));
70
67
  }
71
68
  return;
72
69
  }
@@ -2,9 +2,9 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { bindKeymapWithCommand, escape, insertRule } from '@atlaskit/editor-common/keymaps';
3
3
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { insertHorizontalRule } from '../commands';
5
- export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
5
+ export function keymapPlugin(editorAnalyticsAPI) {
6
6
  const list = {};
7
- bindKeymapWithCommand(insertRule.common, insertHorizontalRule(featureFlags, editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
7
+ bindKeymapWithCommand(insertRule.common, insertHorizontalRule(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
8
8
  bindKeymapWithCommand(escape.common, () => true, list);
9
9
  return keymap(list);
10
10
  }
@@ -1,8 +1,8 @@
1
1
  import { createHorizontalRule } from './pm-plugins/input-rule';
2
- export var insertHorizontalRule = function insertHorizontalRule(featureFlags, editorAnalyticsAPI) {
2
+ export var insertHorizontalRule = function insertHorizontalRule(editorAnalyticsAPI) {
3
3
  return function (inputMethod) {
4
4
  return function (state, dispatch) {
5
- var tr = createHorizontalRule(state, featureFlags, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
5
+ var tr = createHorizontalRule(state, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
6
6
  if (tr) {
7
7
  if (dispatch) {
8
8
  dispatch(tr);
@@ -7,9 +7,8 @@ import { insertHorizontalRule } from './commands';
7
7
  import inputRulePlugin from './pm-plugins/input-rule';
8
8
  import keymapPlugin from './pm-plugins/keymap';
9
9
  export var rulePlugin = function rulePlugin(_ref) {
10
- var _api$featureFlags, _api$analytics;
10
+ var _api$analytics;
11
11
  var api = _ref.api;
12
- var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
13
12
  return {
14
13
  name: 'rule',
15
14
  nodes: function nodes() {
@@ -19,7 +18,7 @@ export var rulePlugin = function rulePlugin(_ref) {
19
18
  }];
20
19
  },
21
20
  actions: {
22
- insertHorizontalRule: insertHorizontalRule(featureFlags, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
21
+ insertHorizontalRule: insertHorizontalRule(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
23
22
  },
24
23
  pmPlugins: function pmPlugins() {
25
24
  return [{
@@ -27,13 +26,13 @@ export var rulePlugin = function rulePlugin(_ref) {
27
26
  plugin: function plugin(_ref2) {
28
27
  var _api$analytics2;
29
28
  var schema = _ref2.schema;
30
- return inputRulePlugin(schema, featureFlags, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
29
+ return inputRulePlugin(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
31
30
  }
32
31
  }, {
33
32
  name: 'ruleKeymap',
34
33
  plugin: function plugin() {
35
34
  var _api$analytics3;
36
- return keymapPlugin(featureFlags, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
35
+ return keymapPlugin(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
37
36
  }
38
37
  }];
39
38
  },
@@ -1,24 +1,23 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { safeInsert } from '@atlaskit/editor-common/insert';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { createRule } from '@atlaskit/editor-common/utils';
3
5
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
4
6
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { createPlugin, createRule, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
6
- export var createHorizontalRule = function createHorizontalRule(state, featureFlags, start, end, inputMethod, editorAnalyticsAPI) {
7
+ import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
8
+ export var createHorizontalRule = function createHorizontalRule(state, start, end, inputMethod, editorAnalyticsAPI) {
7
9
  if (!state.selection.empty) {
8
10
  return null;
9
11
  }
10
12
  var tr = null;
11
13
  var rule = state.schema.nodes.rule;
12
- var newInsertionBehaviour = featureFlags.newInsertionBehaviour;
13
- if (newInsertionBehaviour) {
14
- /**
15
- * This is a workaround to get rid of the typeahead text when using quick insert
16
- * Once we insert *nothing*, we get a new transaction, so we can use the new selection
17
- * without considering the extra text after the `/` command.
18
- **/
19
- tr = state.tr.replaceWith(start, end, Fragment.empty);
20
- tr = safeInsert(rule.createChecked(), tr.selection.from)(tr);
21
- }
14
+ /**
15
+ * This is a workaround to get rid of the typeahead text when using quick insert
16
+ * Once we insert *nothing*, we get a new transaction, so we can use the new selection
17
+ * without considering the extra text after the `/` command.
18
+ **/
19
+ tr = state.tr.replaceWith(start, end, Fragment.empty);
20
+ tr = safeInsert(rule.createChecked(), tr.selection.from)(tr);
22
21
  if (!tr) {
23
22
  tr = state.tr.replaceRange(start, end, new Slice(Fragment.from(state.schema.nodes.rule.createChecked()), 0, 0));
24
23
  }
@@ -33,19 +32,19 @@ export var createHorizontalRule = function createHorizontalRule(state, featureFl
33
32
  })(tr);
34
33
  return tr;
35
34
  };
36
- var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI) {
35
+ var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI) {
37
36
  var listItem = state.schema.nodes.listItem;
38
37
  if (hasParentNodeOfType(listItem)(state.selection)) {
39
38
  return null;
40
39
  }
41
- return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
40
+ return createHorizontalRule(state, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
42
41
  };
43
- export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
42
+ export function inputRulePlugin(schema, editorAnalyticsAPI) {
44
43
  var rules = [];
45
44
  if (schema.nodes.rule) {
46
45
  // '---' and '***' for hr
47
46
  rules.push(createRule(/^(\-\-\-|\*\*\*)$/, function (state, _match, start, end) {
48
- return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
47
+ return createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI);
49
48
  }));
50
49
 
51
50
  // '---' and '***' after shift+enter for hr
@@ -54,13 +53,13 @@ export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
54
53
  if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
55
54
  return null;
56
55
  }
57
- return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
56
+ return createHorizontalRuleAutoformat(state, start, end, editorAnalyticsAPI);
58
57
  }));
59
58
  }
60
59
  if (rules.length !== 0) {
61
- return createPlugin('rule', rules, {
60
+ return new SafePlugin(createPlugin('rule', rules, {
62
61
  isBlockNodeRule: true
63
- });
62
+ }));
64
63
  }
65
64
  return;
66
65
  }
@@ -2,9 +2,9 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { bindKeymapWithCommand, escape, insertRule } from '@atlaskit/editor-common/keymaps';
3
3
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { insertHorizontalRule } from '../commands';
5
- export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
5
+ export function keymapPlugin(editorAnalyticsAPI) {
6
6
  var list = {};
7
- bindKeymapWithCommand(insertRule.common, insertHorizontalRule(featureFlags, editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
7
+ bindKeymapWithCommand(insertRule.common, insertHorizontalRule(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
8
8
  bindKeymapWithCommand(escape.common, function () {
9
9
  return true;
10
10
  }, list);
@@ -1,3 +1,3 @@
1
1
  import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { Command, FeatureFlags } from '@atlaskit/editor-common/types';
3
- export declare const insertHorizontalRule: (featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ export declare const insertHorizontalRule: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
@@ -1,13 +1,9 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
- import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
3
  import { insertHorizontalRule } from './commands';
5
4
  export type RulePlugin = NextEditorPlugin<'rule', {
6
5
  pluginConfiguration: undefined;
7
- dependencies: [
8
- OptionalPlugin<FeatureFlagsPlugin>,
9
- OptionalPlugin<AnalyticsPlugin>
10
- ];
6
+ dependencies: [OptionalPlugin<AnalyticsPlugin>];
11
7
  actions: {
12
8
  insertHorizontalRule: ReturnType<typeof insertHorizontalRule>;
13
9
  };
@@ -1,9 +1,8 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
- import type { FeatureFlags } from '@atlaskit/editor-common/types';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
4
  import type { Schema } from '@atlaskit/editor-prosemirror/model';
6
5
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
7
- export declare const createHorizontalRule: (state: EditorState, featureFlags: FeatureFlags, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
8
- export declare function inputRulePlugin(schema: Schema, featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
6
+ export declare const createHorizontalRule: (state: EditorState, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
7
+ export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
9
8
  export default inputRulePlugin;
@@ -1,5 +1,4 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { FeatureFlags } from '@atlaskit/editor-common/types';
4
- export declare function keymapPlugin(featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
3
+ export declare function keymapPlugin(editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
5
4
  export default keymapPlugin;
@@ -1,3 +1,3 @@
1
1
  import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { Command, FeatureFlags } from '@atlaskit/editor-common/types';
3
- export declare const insertHorizontalRule: (featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ export declare const insertHorizontalRule: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
@@ -1,11 +1,9 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
- import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
3
  import { insertHorizontalRule } from './commands';
5
4
  export type RulePlugin = NextEditorPlugin<'rule', {
6
5
  pluginConfiguration: undefined;
7
6
  dependencies: [
8
- OptionalPlugin<FeatureFlagsPlugin>,
9
7
  OptionalPlugin<AnalyticsPlugin>
10
8
  ];
11
9
  actions: {
@@ -1,9 +1,8 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
- import type { FeatureFlags } from '@atlaskit/editor-common/types';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
4
  import type { Schema } from '@atlaskit/editor-prosemirror/model';
6
5
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
7
- export declare const createHorizontalRule: (state: EditorState, featureFlags: FeatureFlags, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
8
- export declare function inputRulePlugin(schema: Schema, featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
6
+ export declare const createHorizontalRule: (state: EditorState, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
7
+ export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
9
8
  export default inputRulePlugin;
@@ -1,5 +1,4 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { FeatureFlags } from '@atlaskit/editor-common/types';
4
- export declare function keymapPlugin(featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
3
+ export declare function keymapPlugin(editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
5
4
  export default keymapPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-rule",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Rule plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,11 +33,10 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^35.5.1",
36
- "@atlaskit/editor-common": "^77.4.0",
36
+ "@atlaskit/editor-common": "^78.4.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
38
- "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
39
38
  "@atlaskit/editor-prosemirror": "3.0.0",
40
- "@atlaskit/prosemirror-input-rules": "^2.4.0",
39
+ "@atlaskit/prosemirror-input-rules": "^3.0.0",
41
40
  "@babel/runtime": "^7.0.0"
42
41
  },
43
42
  "peerDependencies": {