@atlaskit/prosemirror-input-rules 2.4.6 → 3.0.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,33 @@
1
1
  # @atlaskit/prosemirror-input-rules
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major 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
+
3
31
  ## 2.4.6
4
32
 
5
33
  ### Patch Changes
@@ -17,9 +17,5 @@
17
17
  "../src/**/*.test.*",
18
18
  "../src/**/test.*"
19
19
  ],
20
- "references": [
21
- {
22
- "path": "../../editor-common/afm-cc/tsconfig.json"
23
- }
24
- ]
20
+ "references": []
25
21
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isGapCursorSelection = void 0;
7
+ /**
8
+ * This file is to duplicate types that exist in editor-common
9
+ * so that input-rules does not depend on it.
10
+ *
11
+ * This simplifies our dependencies and makes adoption much easier.
12
+ */
13
+
14
+ // This is to workaround requiring editor-common in this repository which
15
+ // makes the dependency tree significantly more complex since editor-common
16
+ // needs to be a singleton
17
+ var isGapCursorSelection = exports.isGapCursorSelection = function isGapCursorSelection(selection) {
18
+ // @ts-expect-error
19
+ return Boolean(selection.jsonID === 'gapcursor');
20
+ };
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.createInputEventHandler = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _selection = require("@atlaskit/editor-common/selection");
10
9
  var _constants = require("./constants");
10
+ var _editorCommon = require("./editor-common");
11
11
  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; }
12
12
  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; }
13
13
  var createInputEventHandler = exports.createInputEventHandler = function createInputEventHandler(_ref) {
@@ -77,7 +77,7 @@ function findMatchOnRules(_ref3) {
77
77
  // and `textBefore` contains the text in the previous block before the gap cursor.
78
78
  // Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
79
79
  // (which may be a typeahead trigger) and ignore the rest.
80
- var matchString = state.selection instanceof _selection.GapCursorSelection ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
80
+ var matchString = (0, _editorCommon.isGapCursorSelection)(state.selection) ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
81
81
  var match = rule.match.exec(matchString);
82
82
  if (!match) {
83
83
  continue;
package/dist/cjs/index.js CHANGED
@@ -27,12 +27,6 @@ Object.defineProperty(exports, "createPlugin", {
27
27
  return _utils.createPlugin;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "createRule", {
31
- enumerable: true,
32
- get: function get() {
33
- return _utils.createRule;
34
- }
35
- });
36
30
  Object.defineProperty(exports, "leafNodeReplacementCharacter", {
37
31
  enumerable: true,
38
32
  get: function get() {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createInputRulePlugin = createInputRulePlugin;
7
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
7
  var _state = require("@atlaskit/editor-prosemirror/state");
9
8
  var _constants = require("./constants");
10
9
  var _handler = require("./handler");
@@ -21,7 +20,7 @@ function createInputRulePlugin(pluginName, rules) {
21
20
  onInputEvent: onInputEvent,
22
21
  onBeforeRegexMatch: onBeforeRegexMatch
23
22
  });
24
- var plugin = new _safePlugin.SafePlugin({
23
+ return {
25
24
  key: pluginKey,
26
25
  state: {
27
26
  init: function init() {
@@ -91,6 +90,5 @@ function createInputRulePlugin(pluginName, rules) {
91
90
  // @ts-ignore This is used by prosemirror-view to apply input rules on text input event.
92
91
  // However, there is no typing ffor this, yet.
93
92
  isInputRules: true
94
- });
95
- return plugin;
93
+ };
96
94
  }
package/dist/cjs/utils.js CHANGED
@@ -4,17 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createPlugin = void 0;
7
- Object.defineProperty(exports, "createRule", {
8
- enumerable: true,
9
- get: function get() {
10
- return _utils.createRule;
11
- }
12
- });
13
- var _selection = require("@atlaskit/editor-common/selection");
14
7
  var _history = require("@atlaskit/editor-prosemirror/history");
15
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _editorCommon = require("./editor-common");
16
10
  var _plugin = require("./plugin");
17
- var _utils = require("@atlaskit/editor-common/utils");
18
11
  var hasUnsupportedMarks = function hasUnsupportedMarks(state, start, end, marksNameUnsupported) {
19
12
  var isUnsupportedMark = function isUnsupportedMark(node) {
20
13
  return (marksNameUnsupported || []).includes(node.type.name);
@@ -48,7 +41,7 @@ var createPlugin = exports.createPlugin = function createPlugin(pluginName, rule
48
41
  to = _ref.to;
49
42
  var unsupportedMarks = isBlockNodeRule ? ['code', 'link', 'typeAheadQuery'] : ['code'];
50
43
  var $from = state.selection.$from;
51
- if ($from.parent.type.spec.code || !(state.selection instanceof _state.TextSelection) && !(state.selection instanceof _selection.GapCursorSelection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
44
+ if ($from.parent.type.spec.code || !(state.selection instanceof _state.TextSelection) && !(0, _editorCommon.isGapCursorSelection)(state.selection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
52
45
  return false;
53
46
  }
54
47
  return true;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This file is to duplicate types that exist in editor-common
3
+ * so that input-rules does not depend on it.
4
+ *
5
+ * This simplifies our dependencies and makes adoption much easier.
6
+ */
7
+
8
+ // This is to workaround requiring editor-common in this repository which
9
+ // makes the dependency tree significantly more complex since editor-common
10
+ // needs to be a singleton
11
+ export const isGapCursorSelection = selection => {
12
+ // @ts-expect-error
13
+ return Boolean(selection.jsonID === 'gapcursor');
14
+ };
@@ -1,5 +1,5 @@
1
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
2
1
  import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
2
+ import { isGapCursorSelection } from './editor-common';
3
3
  export const createInputEventHandler = ({
4
4
  rules,
5
5
  pluginKey,
@@ -68,7 +68,7 @@ function findMatchOnRules({
68
68
  // and `textBefore` contains the text in the previous block before the gap cursor.
69
69
  // Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
70
70
  // (which may be a typeahead trigger) and ignore the rest.
71
- const matchString = state.selection instanceof GapCursorSelection ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
71
+ const matchString = isGapCursorSelection(state.selection) ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
72
72
  const match = rule.match.exec(matchString);
73
73
  if (!match) {
74
74
  continue;
@@ -1,3 +1,3 @@
1
1
  export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH } from './constants';
2
2
  export { createInputRulePlugin } from './plugin';
3
- export { createRule, createPlugin } from './utils';
3
+ export { createPlugin } from './utils';
@@ -1,4 +1,3 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
1
  import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
2
  import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
4
3
  import { createInputEventHandler } from './handler';
@@ -14,7 +13,7 @@ export function createInputRulePlugin(pluginName, rules, options = {}) {
14
13
  onInputEvent,
15
14
  onBeforeRegexMatch
16
15
  });
17
- const plugin = new SafePlugin({
16
+ return {
18
17
  key: pluginKey,
19
18
  state: {
20
19
  init() {
@@ -88,6 +87,5 @@ export function createInputRulePlugin(pluginName, rules, options = {}) {
88
87
  // @ts-ignore This is used by prosemirror-view to apply input rules on text input event.
89
88
  // However, there is no typing ffor this, yet.
90
89
  isInputRules: true
91
- });
92
- return plugin;
90
+ };
93
91
  }
@@ -1,8 +1,7 @@
1
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
2
1
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
3
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { isGapCursorSelection } from './editor-common';
4
4
  import { createInputRulePlugin } from './plugin';
5
- export { createRule } from '@atlaskit/editor-common/utils';
6
5
  const hasUnsupportedMarks = (state, start, end, marksNameUnsupported) => {
7
6
  const isUnsupportedMark = node => (marksNameUnsupported || []).includes(node.type.name);
8
7
  const $from = state.doc.resolve(start);
@@ -36,7 +35,7 @@ export const createPlugin = (pluginName, rules, options = {}) => {
36
35
  }) => {
37
36
  const unsupportedMarks = isBlockNodeRule ? ['code', 'link', 'typeAheadQuery'] : ['code'];
38
37
  const $from = state.selection.$from;
39
- if ($from.parent.type.spec.code || !(state.selection instanceof TextSelection) && !(state.selection instanceof GapCursorSelection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
38
+ if ($from.parent.type.spec.code || !(state.selection instanceof TextSelection) && !isGapCursorSelection(state.selection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
40
39
  return false;
41
40
  }
42
41
  return true;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This file is to duplicate types that exist in editor-common
3
+ * so that input-rules does not depend on it.
4
+ *
5
+ * This simplifies our dependencies and makes adoption much easier.
6
+ */
7
+
8
+ // This is to workaround requiring editor-common in this repository which
9
+ // makes the dependency tree significantly more complex since editor-common
10
+ // needs to be a singleton
11
+ export var isGapCursorSelection = function isGapCursorSelection(selection) {
12
+ // @ts-expect-error
13
+ return Boolean(selection.jsonID === 'gapcursor');
14
+ };
@@ -1,8 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
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
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
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
5
4
  import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
5
+ import { isGapCursorSelection } from './editor-common';
6
6
  export var createInputEventHandler = function createInputEventHandler(_ref) {
7
7
  var rules = _ref.rules,
8
8
  pluginKey = _ref.pluginKey,
@@ -70,7 +70,7 @@ function findMatchOnRules(_ref3) {
70
70
  // and `textBefore` contains the text in the previous block before the gap cursor.
71
71
  // Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
72
72
  // (which may be a typeahead trigger) and ignore the rest.
73
- var matchString = state.selection instanceof GapCursorSelection ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
73
+ var matchString = isGapCursorSelection(state.selection) ? (_textBefore$at = textBefore.at(-1)) !== null && _textBefore$at !== void 0 ? _textBefore$at : '' : textBefore;
74
74
  var match = rule.match.exec(matchString);
75
75
  if (!match) {
76
76
  continue;
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH } from './constants';
2
2
  export { createInputRulePlugin } from './plugin';
3
- export { createRule, createPlugin } from './utils';
3
+ export { createPlugin } from './utils';
@@ -1,4 +1,3 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
1
  import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
2
  import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
4
3
  import { createInputEventHandler } from './handler';
@@ -15,7 +14,7 @@ export function createInputRulePlugin(pluginName, rules) {
15
14
  onInputEvent: onInputEvent,
16
15
  onBeforeRegexMatch: onBeforeRegexMatch
17
16
  });
18
- var plugin = new SafePlugin({
17
+ return {
19
18
  key: pluginKey,
20
19
  state: {
21
20
  init: function init() {
@@ -85,6 +84,5 @@ export function createInputRulePlugin(pluginName, rules) {
85
84
  // @ts-ignore This is used by prosemirror-view to apply input rules on text input event.
86
85
  // However, there is no typing ffor this, yet.
87
86
  isInputRules: true
88
- });
89
- return plugin;
87
+ };
90
88
  }
package/dist/esm/utils.js CHANGED
@@ -1,8 +1,7 @@
1
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
2
1
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
3
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { isGapCursorSelection } from './editor-common';
4
4
  import { createInputRulePlugin } from './plugin';
5
- export { createRule } from '@atlaskit/editor-common/utils';
6
5
  var hasUnsupportedMarks = function hasUnsupportedMarks(state, start, end, marksNameUnsupported) {
7
6
  var isUnsupportedMark = function isUnsupportedMark(node) {
8
7
  return (marksNameUnsupported || []).includes(node.type.name);
@@ -36,7 +35,7 @@ export var createPlugin = function createPlugin(pluginName, rules) {
36
35
  to = _ref.to;
37
36
  var unsupportedMarks = isBlockNodeRule ? ['code', 'link', 'typeAheadQuery'] : ['code'];
38
37
  var $from = state.selection.$from;
39
- if ($from.parent.type.spec.code || !(state.selection instanceof TextSelection) && !(state.selection instanceof GapCursorSelection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
38
+ if ($from.parent.type.spec.code || !(state.selection instanceof TextSelection) && !isGapCursorSelection(state.selection) || hasUnsupportedMarks(state, from, to, unsupportedMarks) || isBlockNodeRule && isCursorInsideUnsupportedMarks(state, unsupportedMarks)) {
40
39
  return false;
41
40
  }
42
41
  return true;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file is to duplicate types that exist in editor-common
3
+ * so that input-rules does not depend on it.
4
+ *
5
+ * This simplifies our dependencies and makes adoption much easier.
6
+ */
7
+ import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
8
+ export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
9
+ export type OnHandlerApply = (state: EditorState, tr: Transaction, matchResult: RegExpExecArray) => void;
10
+ export interface InputRuleWrapper {
11
+ match: RegExp;
12
+ handler: InputRuleHandler;
13
+ onHandlerApply?: OnHandlerApply;
14
+ }
15
+ export declare const isGapCursorSelection: (selection: Selection) => boolean;
@@ -1,18 +1,5 @@
1
- import type { InputRuleHandler, InputRuleWrapper, OnHandlerApply } from '@atlaskit/editor-common/types';
2
1
  import type { OnInputEvent } from './types';
3
2
  export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH, } from './constants';
4
3
  export { createInputRulePlugin } from './plugin';
5
- export type {
6
- /**
7
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
8
- */
9
- InputRuleWrapper,
10
- /**
11
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
12
- */
13
- InputRuleHandler, OnInputEvent,
14
- /**
15
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
16
- */
17
- OnHandlerApply, };
18
- export { createRule, createPlugin } from './utils';
4
+ export type { OnInputEvent };
5
+ export { createPlugin } from './utils';
@@ -1,9 +1,9 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
1
+ import type { SafePluginSpec } from '@atlaskit/editor-prosemirror/state';
2
2
  import type { InputRuleWrapper, OnBeforeRegexMatch, OnInputEvent } from './types';
3
3
  type Options = {
4
4
  allowInsertTextOnDocument?: boolean;
5
5
  onInputEvent?: OnInputEvent;
6
6
  onBeforeRegexMatch?: OnBeforeRegexMatch;
7
7
  };
8
- export declare function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePlugin;
8
+ export declare function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePluginSpec;
9
9
  export {};
@@ -1,6 +1,7 @@
1
- import type { InputRuleHandler, InputRuleWrapper, OnHandlerApply } from '@atlaskit/editor-common/types';
2
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { InputRuleWrapper } from './editor-common';
4
+ export type { InputRuleHandler, InputRuleWrapper, OnHandlerApply, } from './editor-common';
4
5
  export type HandleInputEvent = (props: {
5
6
  view: EditorView;
6
7
  from: number;
@@ -22,16 +23,3 @@ export type OnInputEvent = (props: {
22
23
  to: number;
23
24
  }) => boolean;
24
25
  export type OnBeforeRegexMatch = (tr: Transaction) => void;
25
- export type {
26
- /**
27
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
28
- */
29
- InputRuleHandler,
30
- /**
31
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
32
- */
33
- OnHandlerApply,
34
- /**
35
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
36
- */
37
- InputRuleWrapper, };
@@ -1,8 +1,8 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { InputRuleWrapper } from '@atlaskit/editor-common/types';
3
- export { createRule } from '@atlaskit/editor-common/utils';
1
+ import type { SafePluginSpec } from '@atlaskit/editor-prosemirror/state';
2
+ import type { InputRuleWrapper } from './types';
4
3
  type Options = {
5
4
  isBlockNodeRule?: boolean;
6
5
  allowInsertTextOnDocument?: boolean;
7
6
  };
8
- export declare const createPlugin: (pluginName: string, rules: Array<InputRuleWrapper>, options?: Options) => SafePlugin;
7
+ export declare const createPlugin: (pluginName: string, rules: Array<InputRuleWrapper>, options?: Options) => SafePluginSpec;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file is to duplicate types that exist in editor-common
3
+ * so that input-rules does not depend on it.
4
+ *
5
+ * This simplifies our dependencies and makes adoption much easier.
6
+ */
7
+ import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
8
+ export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
9
+ export type OnHandlerApply = (state: EditorState, tr: Transaction, matchResult: RegExpExecArray) => void;
10
+ export interface InputRuleWrapper {
11
+ match: RegExp;
12
+ handler: InputRuleHandler;
13
+ onHandlerApply?: OnHandlerApply;
14
+ }
15
+ export declare const isGapCursorSelection: (selection: Selection) => boolean;
@@ -1,18 +1,5 @@
1
- import type { InputRuleHandler, InputRuleWrapper, OnHandlerApply } from '@atlaskit/editor-common/types';
2
1
  import type { OnInputEvent } from './types';
3
2
  export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH, } from './constants';
4
3
  export { createInputRulePlugin } from './plugin';
5
- export type {
6
- /**
7
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
8
- */
9
- InputRuleWrapper,
10
- /**
11
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
12
- */
13
- InputRuleHandler, OnInputEvent,
14
- /**
15
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
16
- */
17
- OnHandlerApply, };
18
- export { createRule, createPlugin } from './utils';
4
+ export type { OnInputEvent };
5
+ export { createPlugin } from './utils';
@@ -1,9 +1,9 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
1
+ import type { SafePluginSpec } from '@atlaskit/editor-prosemirror/state';
2
2
  import type { InputRuleWrapper, OnBeforeRegexMatch, OnInputEvent } from './types';
3
3
  type Options = {
4
4
  allowInsertTextOnDocument?: boolean;
5
5
  onInputEvent?: OnInputEvent;
6
6
  onBeforeRegexMatch?: OnBeforeRegexMatch;
7
7
  };
8
- export declare function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePlugin;
8
+ export declare function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePluginSpec;
9
9
  export {};
@@ -1,6 +1,7 @@
1
- import type { InputRuleHandler, InputRuleWrapper, OnHandlerApply } from '@atlaskit/editor-common/types';
2
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { InputRuleWrapper } from './editor-common';
4
+ export type { InputRuleHandler, InputRuleWrapper, OnHandlerApply, } from './editor-common';
4
5
  export type HandleInputEvent = (props: {
5
6
  view: EditorView;
6
7
  from: number;
@@ -22,16 +23,3 @@ export type OnInputEvent = (props: {
22
23
  to: number;
23
24
  }) => boolean;
24
25
  export type OnBeforeRegexMatch = (tr: Transaction) => void;
25
- export type {
26
- /**
27
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
28
- */
29
- InputRuleHandler,
30
- /**
31
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
32
- */
33
- OnHandlerApply,
34
- /**
35
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
36
- */
37
- InputRuleWrapper, };
@@ -1,8 +1,8 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { InputRuleWrapper } from '@atlaskit/editor-common/types';
3
- export { createRule } from '@atlaskit/editor-common/utils';
1
+ import type { SafePluginSpec } from '@atlaskit/editor-prosemirror/state';
2
+ import type { InputRuleWrapper } from './types';
4
3
  type Options = {
5
4
  isBlockNodeRule?: boolean;
6
5
  allowInsertTextOnDocument?: boolean;
7
6
  };
8
- export declare const createPlugin: (pluginName: string, rules: Array<InputRuleWrapper>, options?: Options) => SafePlugin;
7
+ export declare const createPlugin: (pluginName: string, rules: Array<InputRuleWrapper>, options?: Options) => SafePluginSpec;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/prosemirror-input-rules",
3
- "version": "2.4.6",
3
+ "version": "3.0.0",
4
4
  "description": "A package that contains helpers to create autoformatting rules for ProseMirror",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,11 +28,11 @@
28
28
  "releaseModel": "continuous"
29
29
  },
30
30
  "dependencies": {
31
- "@atlaskit/editor-common": "^78.0.0",
32
31
  "@atlaskit/editor-prosemirror": "3.0.0",
33
32
  "@babel/runtime": "^7.0.0"
34
33
  },
35
34
  "devDependencies": {
35
+ "@atlaskit/editor-common": "^78.4.0",
36
36
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1"
37
37
  },
38
38
  "techstack": {
@@ -1,4 +1,4 @@
1
- import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import type { DocBuilder } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -41,17 +41,19 @@ describe('input-tule/plugin/createInputRulePlugin', () => {
41
41
  });
42
42
 
43
43
  const INLINE_CODE_REGEX = /(\S*)(`[^\s][^`]*`)$/;
44
- const myCustomInputRule = createInputRulePlugin(
45
- 'lol',
46
- [
44
+ const myCustomInputRule = new SafePlugin(
45
+ createInputRulePlugin(
46
+ 'lol',
47
+ [
48
+ {
49
+ match: INLINE_CODE_REGEX,
50
+ handler: handlerMock,
51
+ },
52
+ ],
47
53
  {
48
- match: INLINE_CODE_REGEX,
49
- handler: handlerMock,
54
+ allowInsertTextOnDocument: true,
50
55
  },
51
- ],
52
- {
53
- allowInsertTextOnDocument: true,
54
- },
56
+ ),
55
57
  );
56
58
 
57
59
  editorView = createEditorView(
@@ -112,17 +114,19 @@ describe('input-tule/plugin/createInputRulePlugin', () => {
112
114
  });
113
115
 
114
116
  const CODE_BLOCK_REGEX = /(?!\s)(`{3,})/;
115
- const myCustomInputRule = createInputRulePlugin(
116
- 'lol',
117
- [
117
+ const myCustomInputRule = new SafePlugin(
118
+ createInputRulePlugin(
119
+ 'lol',
120
+ [
121
+ {
122
+ match: CODE_BLOCK_REGEX,
123
+ handler: handlerMock,
124
+ },
125
+ ],
118
126
  {
119
- match: CODE_BLOCK_REGEX,
120
- handler: handlerMock,
127
+ allowInsertTextOnDocument: true,
121
128
  },
122
- ],
123
- {
124
- allowInsertTextOnDocument: true,
125
- },
129
+ ),
126
130
  );
127
131
 
128
132
  editorView = createEditorView(doc(p('here {<>}')), myCustomInputRule);
@@ -0,0 +1,38 @@
1
+ /**
2
+ * This file is to duplicate types that exist in editor-common
3
+ * so that input-rules does not depend on it.
4
+ *
5
+ * This simplifies our dependencies and makes adoption much easier.
6
+ */
7
+ import type {
8
+ EditorState,
9
+ Selection,
10
+ Transaction,
11
+ } from '@atlaskit/editor-prosemirror/state';
12
+
13
+ export type InputRuleHandler = (
14
+ state: EditorState,
15
+ matchResult: RegExpExecArray,
16
+ start: number,
17
+ end: number,
18
+ ) => Transaction | null;
19
+
20
+ export type OnHandlerApply = (
21
+ state: EditorState,
22
+ tr: Transaction,
23
+ matchResult: RegExpExecArray,
24
+ ) => void;
25
+
26
+ export interface InputRuleWrapper {
27
+ match: RegExp;
28
+ handler: InputRuleHandler;
29
+ onHandlerApply?: OnHandlerApply;
30
+ }
31
+
32
+ // This is to workaround requiring editor-common in this repository which
33
+ // makes the dependency tree significantly more complex since editor-common
34
+ // needs to be a singleton
35
+ export const isGapCursorSelection = (selection: Selection): boolean => {
36
+ // @ts-expect-error
37
+ return Boolean(selection.jsonID === 'gapcursor');
38
+ };
package/src/handler.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
2
1
  import type {
3
2
  EditorState,
4
3
  PluginKey,
@@ -10,6 +9,7 @@ import {
10
9
  MAX_REGEX_MATCH,
11
10
  TEXT_INPUT_RULE_TRANSACTION_KEY,
12
11
  } from './constants';
12
+ import { isGapCursorSelection } from './editor-common';
13
13
  import type {
14
14
  HandleInputEvent,
15
15
  InputRulePluginState,
@@ -116,10 +116,9 @@ function findMatchOnRules({
116
116
  // and `textBefore` contains the text in the previous block before the gap cursor.
117
117
  // Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
118
118
  // (which may be a typeahead trigger) and ignore the rest.
119
- const matchString: string =
120
- state.selection instanceof GapCursorSelection
121
- ? textBefore.at(-1) ?? ''
122
- : textBefore;
119
+ const matchString: string = isGapCursorSelection(state.selection)
120
+ ? textBefore.at(-1) ?? ''
121
+ : textBefore;
123
122
 
124
123
  const match = rule.match.exec(matchString);
125
124
  if (!match) {
package/src/index.ts CHANGED
@@ -1,9 +1,3 @@
1
- import type {
2
- InputRuleHandler,
3
- InputRuleWrapper,
4
- OnHandlerApply,
5
- } from '@atlaskit/editor-common/types';
6
-
7
1
  import type { OnInputEvent } from './types';
8
2
 
9
3
  export {
@@ -12,20 +6,6 @@ export {
12
6
  MAX_REGEX_MATCH,
13
7
  } from './constants';
14
8
  export { createInputRulePlugin } from './plugin';
15
- export type {
16
- /**
17
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
18
- */
19
- InputRuleWrapper,
20
- /**
21
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
22
- */
23
- InputRuleHandler,
24
- OnInputEvent,
25
- /**
26
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
27
- */
28
- OnHandlerApply,
29
- };
9
+ export type { OnInputEvent };
30
10
 
31
- export { createRule, createPlugin } from './utils';
11
+ export { createPlugin } from './utils';
package/src/plugin.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
1
+ import type { SafePluginSpec } from '@atlaskit/editor-prosemirror/state';
2
2
  import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
3
 
4
4
  import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
@@ -20,7 +20,7 @@ export function createInputRulePlugin(
20
20
  pluginName: string,
21
21
  rules: InputRuleWrapper[],
22
22
  options: Options = {},
23
- ): SafePlugin {
23
+ ): SafePluginSpec {
24
24
  const onInputEvent = options?.onInputEvent;
25
25
  const onBeforeRegexMatch = options?.onBeforeRegexMatch;
26
26
  const allowInsertTextOnDocument = Boolean(options?.allowInsertTextOnDocument);
@@ -34,7 +34,7 @@ export function createInputRulePlugin(
34
34
  onBeforeRegexMatch,
35
35
  });
36
36
 
37
- const plugin = new SafePlugin<InputRulePluginState>({
37
+ return {
38
38
  key: pluginKey,
39
39
  state: {
40
40
  init() {
@@ -118,7 +118,5 @@ export function createInputRulePlugin(
118
118
  // @ts-ignore This is used by prosemirror-view to apply input rules on text input event.
119
119
  // However, there is no typing ffor this, yet.
120
120
  isInputRules: true,
121
- });
122
-
123
- return plugin;
121
+ };
124
122
  }
package/src/types.ts CHANGED
@@ -1,14 +1,17 @@
1
- import type {
2
- InputRuleHandler,
3
- InputRuleWrapper,
4
- OnHandlerApply,
5
- } from '@atlaskit/editor-common/types';
6
1
  import type {
7
2
  EditorState,
8
3
  Transaction,
9
4
  } from '@atlaskit/editor-prosemirror/state';
10
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
11
6
 
7
+ import type { InputRuleWrapper } from './editor-common';
8
+
9
+ export type {
10
+ InputRuleHandler,
11
+ InputRuleWrapper,
12
+ OnHandlerApply,
13
+ } from './editor-common';
14
+
12
15
  export type HandleInputEvent = (props: {
13
16
  view: EditorView;
14
17
  from: number;
@@ -34,18 +37,3 @@ export type OnInputEvent = (props: {
34
37
  }) => boolean;
35
38
 
36
39
  export type OnBeforeRegexMatch = (tr: Transaction) => void;
37
-
38
- export type {
39
- /**
40
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
41
- */
42
- InputRuleHandler,
43
- /**
44
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
45
- */
46
- OnHandlerApply,
47
- /**
48
- * @deprecated Please import this type from @atlaskit/editor-commmon/types
49
- */
50
- InputRuleWrapper,
51
- };
package/src/utils.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
3
- import type { InputRuleWrapper } from '@atlaskit/editor-common/types';
4
1
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
5
- import { Mark as PMMark } from '@atlaskit/editor-prosemirror/model';
6
- import { EditorState, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import type { Mark as PMMark } from '@atlaskit/editor-prosemirror/model';
3
+ import type {
4
+ EditorState,
5
+ SafePluginSpec,
6
+ } from '@atlaskit/editor-prosemirror/state';
7
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
8
 
9
+ import { isGapCursorSelection } from './editor-common';
8
10
  import { createInputRulePlugin } from './plugin';
9
- import type { OnInputEvent } from './types';
10
-
11
- export { createRule } from '@atlaskit/editor-common/utils';
11
+ import type { InputRuleWrapper, OnInputEvent } from './types';
12
12
 
13
13
  const hasUnsupportedMarks = (
14
14
  state: EditorState,
@@ -50,7 +50,7 @@ export const createPlugin = (
50
50
  pluginName: string,
51
51
  rules: Array<InputRuleWrapper>,
52
52
  options: Options = {},
53
- ): SafePlugin => {
53
+ ): SafePluginSpec => {
54
54
  const { isBlockNodeRule = false, allowInsertTextOnDocument = true } = options;
55
55
 
56
56
  const onInputEvent: OnInputEvent = ({ state, from, to }) => {
@@ -63,7 +63,7 @@ export const createPlugin = (
63
63
  if (
64
64
  $from.parent.type.spec.code ||
65
65
  (!(state.selection instanceof TextSelection) &&
66
- !(state.selection instanceof GapCursorSelection)) ||
66
+ !isGapCursorSelection(state.selection)) ||
67
67
  hasUnsupportedMarks(state, from, to, unsupportedMarks) ||
68
68
  (isBlockNodeRule &&
69
69
  isCursorInsideUnsupportedMarks(state, unsupportedMarks))
package/tsconfig.app.json CHANGED
@@ -31,9 +31,5 @@
31
31
  "composite": true,
32
32
  "outDir": "../../../tsDist/@atlaskit__prosemirror-input-rules/app"
33
33
  },
34
- "references": [
35
- {
36
- "path": "../editor-common/tsconfig.app.json"
37
- }
38
- ]
34
+ "references": []
39
35
  }