@atlaskit/prosemirror-input-rules 2.0.0 → 2.1.2
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 +40 -0
- package/build/tsconfig.json +10 -3
- package/dist/cjs/constants.js +4 -2
- package/dist/cjs/handler.js +5 -6
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/plugin.js +3 -1
- package/dist/cjs/types.js +5 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/constants.js +2 -1
- package/dist/es2019/handler.js +4 -4
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/constants.js +2 -1
- package/dist/esm/handler.js +6 -6
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugin.d.ts +2 -2
- package/package.json +12 -6
- package/src/__tests__/unit/handler.ts +3 -3
- package/src/__tests__/unit/plugin.ts +6 -5
- package/src/constants.ts +1 -0
- package/src/handler.ts +7 -4
- package/src/index.ts +1 -0
- package/src/plugin.ts +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @atlaskit/prosemirror-input-rules
|
|
2
2
|
|
|
3
|
+
## 2.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4e6fbaf5898`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4e6fbaf5898) - ED-14117 Change EditorState.apply type to receive readonly transaction
|
|
8
|
+
|
|
9
|
+
Transactions should not be mutated after being dispatched as it can lead to
|
|
10
|
+
unexpected behaviour. This change patches the relevant types declared in
|
|
11
|
+
prosemirror-state as a compile-time safeguard.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 2.1.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`19d72473dfb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/19d72473dfb) - ED-13025 Bump prosemirror-view 1.23.1 -> 1.23.2
|
|
20
|
+
|
|
21
|
+
## 2.1.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [`b230f366971`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b230f366971) - [ED-14008] Bump prosemirror-view from 1.20.2 to 1.23.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- [`c6feed82071`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c6feed82071) - ED-11632: Bump prosemirror packages;
|
|
30
|
+
|
|
31
|
+
- prosmirror-commands 1.1.4 -> 1.1.11,
|
|
32
|
+
- prosemirror-model 1.11.0 -> 1.14.3,
|
|
33
|
+
- prosemirror-state 1.3.3 -> 1.3.4,
|
|
34
|
+
- prosemirror-transform 1.2.8 -> 1.3.2,
|
|
35
|
+
- prosemirror-view 1.15.4 + 1.18.8 -> 1.20.2.
|
|
36
|
+
|
|
37
|
+
## 2.0.1
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- [`312a2810b0b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/312a2810b0b) - [ux] ED-12931 Fix input rules replacing text outside of matched word in a long paragraph
|
|
42
|
+
|
|
3
43
|
## 2.0.0
|
|
4
44
|
|
|
5
45
|
### Major Changes
|
package/build/tsconfig.json
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
"target": "es5",
|
|
6
6
|
"paths": {}
|
|
7
7
|
},
|
|
8
|
-
"include": [
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"include": [
|
|
9
|
+
"../src/**/*.ts",
|
|
10
|
+
"../src/**/*.tsx"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"../src/**/__tests__/*",
|
|
14
|
+
"../src/**/*.test.*",
|
|
15
|
+
"../src/**/test.*"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TEXT_INPUT_RULE_TRANSACTION_KEY = exports.
|
|
6
|
+
exports.leafNodeReplacementCharacter = exports.TEXT_INPUT_RULE_TRANSACTION_KEY = exports.MAX_REGEX_MATCH = void 0;
|
|
7
7
|
// ProseMirror uses the Unicode Character 'OBJECT REPLACEMENT CHARACTER' (U+FFFC) as text representation for
|
|
8
8
|
// leaf nodes, i.e. nodes that don't have any content or text property (e.g. hardBreak, emoji, mention, rule)
|
|
9
9
|
// It was introduced because of https://github.com/ProseMirror/prosemirror/issues/262
|
|
@@ -11,4 +11,6 @@ exports.TEXT_INPUT_RULE_TRANSACTION_KEY = exports.leafNodeReplacementCharacter =
|
|
|
11
11
|
var leafNodeReplacementCharacter = "\uFFFC";
|
|
12
12
|
exports.leafNodeReplacementCharacter = leafNodeReplacementCharacter;
|
|
13
13
|
var TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
14
|
-
exports.TEXT_INPUT_RULE_TRANSACTION_KEY = TEXT_INPUT_RULE_TRANSACTION_KEY;
|
|
14
|
+
exports.TEXT_INPUT_RULE_TRANSACTION_KEY = TEXT_INPUT_RULE_TRANSACTION_KEY;
|
|
15
|
+
var MAX_REGEX_MATCH = 500;
|
|
16
|
+
exports.MAX_REGEX_MATCH = MAX_REGEX_MATCH;
|
package/dist/cjs/handler.js
CHANGED
|
@@ -11,11 +11,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
11
11
|
|
|
12
12
|
var _constants = require("./constants");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
15
|
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
17
|
-
|
|
18
|
-
var MAX_MATCH = 500;
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
17
|
|
|
20
18
|
var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
21
19
|
var rules = _ref.rules,
|
|
@@ -48,7 +46,7 @@ var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
|
48
46
|
return false;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset -
|
|
49
|
+
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - _constants.MAX_REGEX_MATCH), $from.parentOffset, undefined, _constants.leafNodeReplacementCharacter) + text;
|
|
52
50
|
var result = findMatchOnRules({
|
|
53
51
|
rules: rules,
|
|
54
52
|
textBefore: textBefore,
|
|
@@ -97,7 +95,8 @@ function findMatchOnRules(_ref3) {
|
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
var parentNodeStartAt = state.selection.$from.start();
|
|
100
|
-
var
|
|
98
|
+
var offset = Math.max(0, state.selection.$from.parentOffset - _constants.MAX_REGEX_MATCH);
|
|
99
|
+
var fromFixed = Math.max(parentNodeStartAt + match.index + offset, 1);
|
|
101
100
|
var transform = rule.handler(state, match, fromFixed, to);
|
|
102
101
|
|
|
103
102
|
if (transform) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "MAX_REGEX_MATCH", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return _constants.
|
|
9
|
+
return _constants.MAX_REGEX_MATCH;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "TEXT_INPUT_RULE_TRANSACTION_KEY", {
|
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "createInputRulePlugin", {
|
|
|
21
21
|
return _plugin.createInputRulePlugin;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "leafNodeReplacementCharacter", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _constants.leafNodeReplacementCharacter;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
|
|
25
31
|
var _constants = require("./constants");
|
|
26
32
|
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.createInputRulePlugin = createInputRulePlugin;
|
|
|
7
7
|
|
|
8
8
|
var _prosemirrorState = require("prosemirror-state");
|
|
9
9
|
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
|
|
10
12
|
var _constants = require("./constants");
|
|
11
13
|
|
|
12
14
|
var _handler = require("./handler");
|
|
@@ -24,7 +26,7 @@ function createInputRulePlugin(pluginName, rules) {
|
|
|
24
26
|
onInputEvent: onInputEvent,
|
|
25
27
|
onBeforeRegexMatch: onBeforeRegexMatch
|
|
26
28
|
});
|
|
27
|
-
var plugin = new
|
|
29
|
+
var plugin = new _safePlugin.SafePlugin({
|
|
28
30
|
key: pluginKey,
|
|
29
31
|
state: {
|
|
30
32
|
init: function init() {
|
package/dist/cjs/types.js
CHANGED
package/dist/cjs/version.json
CHANGED
package/dist/es2019/constants.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
// It was introduced because of https://github.com/ProseMirror/prosemirror/issues/262
|
|
4
4
|
// This can be used in an input rule regex to be able to include or exclude such nodes.
|
|
5
5
|
export const leafNodeReplacementCharacter = '\ufffc';
|
|
6
|
-
export const TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
6
|
+
export const TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
7
|
+
export const MAX_REGEX_MATCH = 500;
|
package/dist/es2019/handler.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
2
|
-
const MAX_MATCH = 500;
|
|
1
|
+
import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
3
2
|
export const createInputEventHandler = ({
|
|
4
3
|
rules,
|
|
5
4
|
pluginKey,
|
|
@@ -31,7 +30,7 @@ export const createInputEventHandler = ({
|
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset -
|
|
33
|
+
const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_REGEX_MATCH), $from.parentOffset, undefined, leafNodeReplacementCharacter) + text;
|
|
35
34
|
const result = findMatchOnRules({
|
|
36
35
|
rules,
|
|
37
36
|
textBefore,
|
|
@@ -77,7 +76,8 @@ function findMatchOnRules({
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
const parentNodeStartAt = state.selection.$from.start();
|
|
80
|
-
const
|
|
79
|
+
const offset = Math.max(0, state.selection.$from.parentOffset - MAX_REGEX_MATCH);
|
|
80
|
+
const fromFixed = Math.max(parentNodeStartAt + match.index + offset, 1);
|
|
81
81
|
const transform = rule.handler(state, match, fromFixed, to);
|
|
82
82
|
|
|
83
83
|
if (transform) {
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
1
|
+
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH } from './constants';
|
|
2
2
|
export { createInputRulePlugin } from './plugin';
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
3
4
|
import { createInputEventHandler } from './handler';
|
|
4
5
|
export function createInputRulePlugin(pluginName, rules, options = {}) {
|
|
@@ -13,7 +14,7 @@ export function createInputRulePlugin(pluginName, rules, options = {}) {
|
|
|
13
14
|
onInputEvent,
|
|
14
15
|
onBeforeRegexMatch
|
|
15
16
|
});
|
|
16
|
-
const plugin = new
|
|
17
|
+
const plugin = new SafePlugin({
|
|
17
18
|
key: pluginKey,
|
|
18
19
|
state: {
|
|
19
20
|
init() {
|
package/dist/es2019/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/constants.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
// It was introduced because of https://github.com/ProseMirror/prosemirror/issues/262
|
|
4
4
|
// This can be used in an input rule regex to be able to include or exclude such nodes.
|
|
5
5
|
export var leafNodeReplacementCharacter = "\uFFFC";
|
|
6
|
-
export var TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
6
|
+
export var TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
7
|
+
export var MAX_REGEX_MATCH = 500;
|
package/dist/esm/handler.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
|
|
7
|
-
import { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
8
|
-
var MAX_MATCH = 500;
|
|
7
|
+
import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
9
8
|
export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
10
9
|
var rules = _ref.rules,
|
|
11
10
|
pluginKey = _ref.pluginKey,
|
|
@@ -37,7 +36,7 @@ export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
|
37
36
|
return false;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset -
|
|
39
|
+
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_REGEX_MATCH), $from.parentOffset, undefined, leafNodeReplacementCharacter) + text;
|
|
41
40
|
var result = findMatchOnRules({
|
|
42
41
|
rules: rules,
|
|
43
42
|
textBefore: textBefore,
|
|
@@ -84,7 +83,8 @@ function findMatchOnRules(_ref3) {
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
var parentNodeStartAt = state.selection.$from.start();
|
|
87
|
-
var
|
|
86
|
+
var offset = Math.max(0, state.selection.$from.parentOffset - MAX_REGEX_MATCH);
|
|
87
|
+
var fromFixed = Math.max(parentNodeStartAt + match.index + offset, 1);
|
|
88
88
|
var transform = rule.handler(state, match, fromFixed, to);
|
|
89
89
|
|
|
90
90
|
if (transform) {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
1
|
+
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH } from './constants';
|
|
2
2
|
export { createInputRulePlugin } from './plugin';
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
3
4
|
import { createInputEventHandler } from './handler';
|
|
4
5
|
export function createInputRulePlugin(pluginName, rules) {
|
|
@@ -14,7 +15,7 @@ export function createInputRulePlugin(pluginName, rules) {
|
|
|
14
15
|
onInputEvent: onInputEvent,
|
|
15
16
|
onBeforeRegexMatch: onBeforeRegexMatch
|
|
16
17
|
});
|
|
17
|
-
var plugin = new
|
|
18
|
+
var plugin = new SafePlugin({
|
|
18
19
|
key: pluginKey,
|
|
19
20
|
state: {
|
|
20
21
|
init: function init() {
|
package/dist/esm/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { InputRuleHandler, InputRuleWrapper, OnHandlerApply, OnInputEvent } from './types';
|
|
2
|
-
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, } from './constants';
|
|
2
|
+
export { leafNodeReplacementCharacter, TEXT_INPUT_RULE_TRANSACTION_KEY, MAX_REGEX_MATCH, } from './constants';
|
|
3
3
|
export { createInputRulePlugin } from './plugin';
|
|
4
4
|
export type { InputRuleWrapper, InputRuleHandler, OnInputEvent, OnHandlerApply, };
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import type { InputRuleWrapper, OnBeforeRegexMatch, OnInputEvent } from './types';
|
|
3
3
|
declare 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):
|
|
8
|
+
export declare function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePlugin;
|
|
9
9
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/prosemirror-input-rules",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A package that contains helpers to create autoformatting rules for ProseMirror",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -19,17 +19,19 @@
|
|
|
19
19
|
"releaseModel": "scheduled"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@atlaskit/editor-common": "^64.0.0",
|
|
22
23
|
"@babel/runtime": "^7.0.0",
|
|
23
|
-
"prosemirror-state": "1.3.
|
|
24
|
+
"prosemirror-state": "1.3.4"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@atlaskit/adf-schema": "^
|
|
27
|
-
"@atlaskit/editor-test-helpers": "^
|
|
27
|
+
"@atlaskit/adf-schema": "^22.0.0",
|
|
28
|
+
"@atlaskit/editor-test-helpers": "^16.1.0",
|
|
29
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
28
30
|
"@types/prosemirror-history": "^1.0.1",
|
|
29
31
|
"@types/prosemirror-model": "^1.11.0",
|
|
30
32
|
"@types/prosemirror-state": "^1.2.0",
|
|
31
33
|
"@types/prosemirror-view": "^1.9.0",
|
|
32
|
-
"prosemirror-view": "1.
|
|
34
|
+
"prosemirror-view": "1.23.2"
|
|
33
35
|
},
|
|
34
36
|
"techstack": {
|
|
35
37
|
"@atlassian/frontend": {
|
|
@@ -37,9 +39,13 @@
|
|
|
37
39
|
"file-level"
|
|
38
40
|
],
|
|
39
41
|
"import-structure": "atlassian-conventions"
|
|
42
|
+
},
|
|
43
|
+
"@repo/internal": {
|
|
44
|
+
"deprecation": "no-deprecated-imports"
|
|
40
45
|
}
|
|
41
46
|
},
|
|
42
47
|
"af:exports": {
|
|
43
48
|
".": "./src/index.ts"
|
|
44
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
|
|
45
51
|
}
|
|
@@ -33,7 +33,7 @@ describe('input-tule/handles/createInputEventHandler', () => {
|
|
|
33
33
|
|
|
34
34
|
dispatchSpy = jest.spyOn(editorView, 'dispatch');
|
|
35
35
|
|
|
36
|
-
ruleHandlerMock = jest.fn().mockImplementation(state => {
|
|
36
|
+
ruleHandlerMock = jest.fn().mockImplementation((state) => {
|
|
37
37
|
return state.tr;
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -90,7 +90,7 @@ describe('input-tule/handles/createInputEventHandler', () => {
|
|
|
90
90
|
beforeEach(() => {
|
|
91
91
|
const RULE_AFTER = {
|
|
92
92
|
match: /^(after).*/,
|
|
93
|
-
handler: jest.fn().mockImplementation(state => {
|
|
93
|
+
handler: jest.fn().mockImplementation((state) => {
|
|
94
94
|
return state.tr;
|
|
95
95
|
}),
|
|
96
96
|
};
|
|
@@ -131,7 +131,7 @@ describe('input-tule/handles/createInputEventHandler', () => {
|
|
|
131
131
|
|
|
132
132
|
describe.each([true, false])(
|
|
133
133
|
'and when allowInsertTextOnDocument is %s',
|
|
134
|
-
allowInsertTextOnDocument => {
|
|
134
|
+
(allowInsertTextOnDocument) => {
|
|
135
135
|
beforeEach(() => {
|
|
136
136
|
const {
|
|
137
137
|
selection: { from, to },
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EditorState
|
|
1
|
+
import { EditorState } from 'prosemirror-state';
|
|
2
2
|
import { EditorView } from 'prosemirror-view';
|
|
3
3
|
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
5
|
import { createEditorState } from '@atlaskit/editor-test-helpers/create-editor-state';
|
|
5
6
|
import { doc, DocBuilder, p } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
6
7
|
|
|
@@ -17,10 +18,10 @@ describe('input-tule/plugin/createInputRulePlugin', () => {
|
|
|
17
18
|
|
|
18
19
|
function insertText(view: EditorView, text: string) {
|
|
19
20
|
const { $from, $to } = view.state.selection;
|
|
20
|
-
view.someProp('handleTextInput', f => f(view, $from.pos, $to.pos, text));
|
|
21
|
+
view.someProp('handleTextInput', (f) => f(view, $from.pos, $to.pos, text));
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
function createEditorView(lol: DocBuilder, customInputRule:
|
|
24
|
+
function createEditorView(lol: DocBuilder, customInputRule: SafePlugin) {
|
|
24
25
|
const editorState = createEditorState(lol, customInputRule);
|
|
25
26
|
|
|
26
27
|
return new EditorView(editorViewElement, {
|
|
@@ -60,7 +61,7 @@ describe('input-tule/plugin/createInputRulePlugin', () => {
|
|
|
60
61
|
describe('when the handler is called', () => {
|
|
61
62
|
describe('during the textInput flow', () => {
|
|
62
63
|
it('should call the handler only once', () => {
|
|
63
|
-
jest.spyOn(editorView, 'dispatch').mockImplementation(tr => {});
|
|
64
|
+
jest.spyOn(editorView, 'dispatch').mockImplementation((tr) => {});
|
|
64
65
|
insertText(editorView, '`');
|
|
65
66
|
|
|
66
67
|
expect(handlerMock).toHaveBeenCalledTimes(1);
|
|
@@ -128,7 +129,7 @@ describe('input-tule/plugin/createInputRulePlugin', () => {
|
|
|
128
129
|
describe('when the handler is called', () => {
|
|
129
130
|
describe('during the textInput flow', () => {
|
|
130
131
|
it('should call the handler only once', () => {
|
|
131
|
-
jest.spyOn(editorView, 'dispatch').mockImplementation(tr => {});
|
|
132
|
+
jest.spyOn(editorView, 'dispatch').mockImplementation((tr) => {});
|
|
132
133
|
insertText(editorView, '```');
|
|
133
134
|
|
|
134
135
|
expect(handlerMock).toHaveBeenCalledTimes(1);
|
package/src/constants.ts
CHANGED
package/src/handler.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { EditorState, PluginKey, Transaction } from 'prosemirror-state';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
leafNodeReplacementCharacter,
|
|
5
|
+
MAX_REGEX_MATCH,
|
|
5
6
|
TEXT_INPUT_RULE_TRANSACTION_KEY,
|
|
6
7
|
} from './constants';
|
|
7
8
|
import type {
|
|
@@ -13,8 +14,6 @@ import type {
|
|
|
13
14
|
OnInputEvent,
|
|
14
15
|
} from './types';
|
|
15
16
|
|
|
16
|
-
const MAX_MATCH = 500;
|
|
17
|
-
|
|
18
17
|
type Options = {
|
|
19
18
|
pluginKey: PluginKey;
|
|
20
19
|
rules: InputRuleWrapper[];
|
|
@@ -46,7 +45,7 @@ export const createInputEventHandler = ({
|
|
|
46
45
|
|
|
47
46
|
const textBefore =
|
|
48
47
|
$from.parent.textBetween(
|
|
49
|
-
Math.max(0, $from.parentOffset -
|
|
48
|
+
Math.max(0, $from.parentOffset - MAX_REGEX_MATCH),
|
|
50
49
|
$from.parentOffset,
|
|
51
50
|
undefined,
|
|
52
51
|
leafNodeReplacementCharacter,
|
|
@@ -110,7 +109,11 @@ function findMatchOnRules({
|
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
const parentNodeStartAt = state.selection.$from.start();
|
|
113
|
-
const
|
|
112
|
+
const offset = Math.max(
|
|
113
|
+
0,
|
|
114
|
+
state.selection.$from.parentOffset - MAX_REGEX_MATCH,
|
|
115
|
+
);
|
|
116
|
+
const fromFixed = Math.max(parentNodeStartAt + match.index + offset, 1);
|
|
114
117
|
const transform: Transaction | null = rule.handler(
|
|
115
118
|
state,
|
|
116
119
|
match,
|
package/src/index.ts
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
|
+
|
|
3
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
4
|
|
|
3
5
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
4
6
|
import { createInputEventHandler } from './handler';
|
|
@@ -19,7 +21,7 @@ export function createInputRulePlugin(
|
|
|
19
21
|
pluginName: string,
|
|
20
22
|
rules: InputRuleWrapper[],
|
|
21
23
|
options: Options = {},
|
|
22
|
-
):
|
|
24
|
+
): SafePlugin {
|
|
23
25
|
const onInputEvent = options?.onInputEvent;
|
|
24
26
|
const onBeforeRegexMatch = options?.onBeforeRegexMatch;
|
|
25
27
|
const allowInsertTextOnDocument = Boolean(options?.allowInsertTextOnDocument);
|
|
@@ -33,7 +35,7 @@ export function createInputRulePlugin(
|
|
|
33
35
|
onBeforeRegexMatch,
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
const plugin
|
|
38
|
+
const plugin = new SafePlugin<InputRulePluginState>({
|
|
37
39
|
key: pluginKey,
|
|
38
40
|
state: {
|
|
39
41
|
init() {
|
|
@@ -50,7 +52,7 @@ export function createInputRulePlugin(
|
|
|
50
52
|
},
|
|
51
53
|
|
|
52
54
|
appendTransaction: (transactions, oldState, newState) => {
|
|
53
|
-
const transactionWithInputRuleMeta = transactions.find(tr =>
|
|
55
|
+
const transactionWithInputRuleMeta = transactions.find((tr) =>
|
|
54
56
|
tr.getMeta(pluginKey),
|
|
55
57
|
);
|
|
56
58
|
|
|
@@ -93,7 +95,7 @@ export function createInputRulePlugin(
|
|
|
93
95
|
});
|
|
94
96
|
},
|
|
95
97
|
handleDOMEvents: {
|
|
96
|
-
compositionend: view => {
|
|
98
|
+
compositionend: (view) => {
|
|
97
99
|
setTimeout(() => {
|
|
98
100
|
const selection = view.state.selection;
|
|
99
101
|
if (!(selection instanceof TextSelection)) {
|