@atlaskit/prosemirror-input-rules 2.3.0 → 2.3.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 +6 -0
- package/dist/cjs/plugin.js +3 -3
- package/dist/cjs/utils.js +6 -6
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugin.js +1 -1
- package/dist/es2019/utils.js +2 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/utils.js +2 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/handler.d.ts +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types-ts4.5/handler.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +2 -2
- package/package.json +5 -8
- package/report.api.md +2 -2
- package/src/__tests__/unit/handler.ts +6 -3
- package/src/__tests__/unit/plugin.ts +2 -3
- package/src/handler.ts +5 -2
- package/src/plugin.ts +1 -2
- package/src/types.ts +5 -2
- package/src/utils.ts +3 -4
- package/tmp/api-report-tmp.d.ts +70 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/prosemirror-input-rules
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4e6f1bf8511`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4e6f1bf8511) - [ED-19233] Import prosemirror libraries from internal facade package
|
|
8
|
+
|
|
3
9
|
## 2.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createInputRulePlugin = createInputRulePlugin;
|
|
7
|
-
var _prosemirrorState = require("prosemirror-state");
|
|
8
7
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _constants = require("./constants");
|
|
10
10
|
var _handler = require("./handler");
|
|
11
11
|
function createInputRulePlugin(pluginName, rules) {
|
|
@@ -13,7 +13,7 @@ function createInputRulePlugin(pluginName, rules) {
|
|
|
13
13
|
var onInputEvent = options === null || options === void 0 ? void 0 : options.onInputEvent;
|
|
14
14
|
var onBeforeRegexMatch = options === null || options === void 0 ? void 0 : options.onBeforeRegexMatch;
|
|
15
15
|
var allowInsertTextOnDocument = Boolean(options === null || options === void 0 ? void 0 : options.allowInsertTextOnDocument);
|
|
16
|
-
var pluginKey = new
|
|
16
|
+
var pluginKey = new _state.PluginKey("inputRulePlugin__".concat(pluginName));
|
|
17
17
|
var inputEvent = (0, _handler.createInputEventHandler)({
|
|
18
18
|
allowInsertTextOnDocument: allowInsertTextOnDocument,
|
|
19
19
|
pluginKey: pluginKey,
|
|
@@ -71,7 +71,7 @@ function createInputRulePlugin(pluginName, rules) {
|
|
|
71
71
|
compositionend: function compositionend(view) {
|
|
72
72
|
setTimeout(function () {
|
|
73
73
|
var selection = view.state.selection;
|
|
74
|
-
if (!(selection instanceof
|
|
74
|
+
if (!(selection instanceof _state.TextSelection)) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
var $cursor = selection.$cursor;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createRule = exports.createPlugin = void 0;
|
|
7
|
-
var _prosemirrorHistory = require("prosemirror-history");
|
|
8
|
-
var _prosemirrorState = require("prosemirror-state");
|
|
9
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
|
+
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
9
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
10
|
var _plugin = require("./plugin");
|
|
11
11
|
var createRule = function createRule(match, handler) {
|
|
12
12
|
return {
|
|
13
13
|
match: match,
|
|
14
14
|
handler: handler,
|
|
15
15
|
onHandlerApply: function onHandlerApply(state, tr) {
|
|
16
|
-
(0,
|
|
16
|
+
(0, _history.closeHistory)(tr);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
};
|
|
@@ -30,7 +30,7 @@ var hasUnsupportedMarks = function hasUnsupportedMarks(state, start, end, marksN
|
|
|
30
30
|
var isCursorInsideUnsupportedMarks = function isCursorInsideUnsupportedMarks(state, marksNameUnsupported) {
|
|
31
31
|
var _$cursor$nodeBefore, _$cursor$nodeBefore$m;
|
|
32
32
|
var selection = state.selection;
|
|
33
|
-
if (!(selection instanceof
|
|
33
|
+
if (!(selection instanceof _state.TextSelection)) {
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
36
36
|
var $cursor = selection.$cursor;
|
|
@@ -51,7 +51,7 @@ var createPlugin = function createPlugin(pluginName, rules) {
|
|
|
51
51
|
to = _ref.to;
|
|
52
52
|
var unsupportedMarks = isBlockNodeRule ? ['code', 'link', 'typeAheadQuery'] : ['code'];
|
|
53
53
|
var $from = state.selection.$from;
|
|
54
|
-
if ($from.parent.type.spec.code || !(state.selection instanceof
|
|
54
|
+
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)) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
57
|
return true;
|
|
@@ -60,7 +60,7 @@ var createPlugin = function createPlugin(pluginName, rules) {
|
|
|
60
60
|
allowInsertTextOnDocument: allowInsertTextOnDocument,
|
|
61
61
|
onInputEvent: onInputEvent,
|
|
62
62
|
onBeforeRegexMatch: function onBeforeRegexMatch(tr) {
|
|
63
|
-
(0,
|
|
63
|
+
(0, _history.closeHistory)(tr);
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
};
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
4
4
|
import { createInputEventHandler } from './handler';
|
|
5
5
|
export function createInputRulePlugin(pluginName, rules, options = {}) {
|
package/dist/es2019/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { closeHistory } from 'prosemirror-history';
|
|
2
|
-
import { TextSelection } from 'prosemirror-state';
|
|
3
1
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
3
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { createInputRulePlugin } from './plugin';
|
|
5
5
|
export const createRule = (match, handler) => {
|
|
6
6
|
return {
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
4
4
|
import { createInputEventHandler } from './handler';
|
|
5
5
|
export function createInputRulePlugin(pluginName, rules) {
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { closeHistory } from 'prosemirror-history';
|
|
2
|
-
import { TextSelection } from 'prosemirror-state';
|
|
3
1
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
3
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { createInputRulePlugin } from './plugin';
|
|
5
5
|
export var createRule = function createRule(match, handler) {
|
|
6
6
|
return {
|
package/dist/esm/version.json
CHANGED
package/dist/types/handler.d.ts
CHANGED
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EditorState, Transaction } from 'prosemirror
|
|
2
|
-
import type { EditorView } from 'prosemirror
|
|
1
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
3
|
export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
|
|
4
4
|
export type HandleInputEvent = (props: {
|
|
5
5
|
view: EditorView;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EditorState, Transaction } from 'prosemirror
|
|
2
|
-
import type { EditorView } from 'prosemirror
|
|
1
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
3
|
export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
|
|
4
4
|
export type HandleInputEvent = (props: {
|
|
5
5
|
view: EditorView;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/prosemirror-input-rules",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
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,16 +28,13 @@
|
|
|
28
28
|
"releaseModel": "continuous"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"prosemirror-model": "1.16.0",
|
|
35
|
-
"prosemirror-state": "1.3.4"
|
|
31
|
+
"@atlaskit/editor-common": "^74.29.0",
|
|
32
|
+
"@atlaskit/editor-prosemirror": "1.0.2",
|
|
33
|
+
"@babel/runtime": "^7.0.0"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@atlaskit/editor-test-helpers": "^18.10.0",
|
|
39
|
-
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1"
|
|
40
|
-
"prosemirror-view": "1.23.7"
|
|
37
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1"
|
|
41
38
|
},
|
|
42
39
|
"techstack": {
|
|
43
40
|
"@atlassian/frontend": {
|
package/report.api.md
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
<!--SECTION START: Main Entry Types-->
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import type { EditorState } from 'prosemirror
|
|
18
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
19
19
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
20
|
-
import type { Transaction } from 'prosemirror
|
|
20
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
21
21
|
|
|
22
22
|
// @public (undocumented)
|
|
23
23
|
export function createInputRulePlugin(
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
EditorState,
|
|
3
|
+
PluginKey,
|
|
4
|
+
Transaction,
|
|
5
|
+
} from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
7
|
import { createEditorState } from '@atlaskit/editor-test-helpers/create-editor-state';
|
|
5
8
|
import { code_block, doc, p } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
6
9
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { EditorState } from 'prosemirror-state';
|
|
2
|
-
import { EditorView } from 'prosemirror-view';
|
|
3
|
-
|
|
4
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
4
|
import { createEditorState } from '@atlaskit/editor-test-helpers/create-editor-state';
|
|
6
5
|
import { doc, DocBuilder, p } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
7
6
|
|
package/src/handler.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { EditorState, PluginKey, Transaction } from 'prosemirror-state';
|
|
2
|
-
|
|
3
1
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import type {
|
|
3
|
+
EditorState,
|
|
4
|
+
PluginKey,
|
|
5
|
+
Transaction,
|
|
6
|
+
} from '@atlaskit/editor-prosemirror/state';
|
|
4
7
|
|
|
5
8
|
import {
|
|
6
9
|
leafNodeReplacementCharacter,
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
|
-
|
|
3
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
3
|
|
|
5
4
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
6
5
|
import { createInputEventHandler } from './handler';
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
EditorState,
|
|
3
|
+
Transaction,
|
|
4
|
+
} from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
6
|
|
|
4
7
|
export type InputRuleHandler = (
|
|
5
8
|
state: EditorState,
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { closeHistory } from 'prosemirror-history';
|
|
2
|
-
import { Mark as PMMark } from 'prosemirror-model';
|
|
3
|
-
import { EditorState, TextSelection } from 'prosemirror-state';
|
|
4
|
-
|
|
5
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
2
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
4
|
+
import { Mark as PMMark } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import { EditorState, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
6
|
|
|
8
7
|
import { createInputRulePlugin } from './plugin';
|
|
9
8
|
import type { InputRuleHandler, InputRuleWrapper, OnInputEvent } from './types';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
## API Report File for "@atlaskit/prosemirror-input-rules"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
10
|
+
|
|
11
|
+
// @public (undocumented)
|
|
12
|
+
export function createInputRulePlugin(pluginName: string, rules: InputRuleWrapper[], options?: Options): SafePlugin;
|
|
13
|
+
|
|
14
|
+
// @public (undocumented)
|
|
15
|
+
export const createPlugin: (pluginName: string, rules: Array<InputRuleWrapper>, options?: Options_2) => SafePlugin;
|
|
16
|
+
|
|
17
|
+
// @public (undocumented)
|
|
18
|
+
export const createRule: (match: RegExp, handler: InputRuleHandler) => InputRuleWrapper;
|
|
19
|
+
|
|
20
|
+
// @public (undocumented)
|
|
21
|
+
export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
|
|
22
|
+
|
|
23
|
+
// @public (undocumented)
|
|
24
|
+
export interface InputRuleWrapper {
|
|
25
|
+
// (undocumented)
|
|
26
|
+
handler: InputRuleHandler;
|
|
27
|
+
// (undocumented)
|
|
28
|
+
match: RegExp;
|
|
29
|
+
// (undocumented)
|
|
30
|
+
onHandlerApply?: OnHandlerApply;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// @public (undocumented)
|
|
34
|
+
export const leafNodeReplacementCharacter = "\uFFFC";
|
|
35
|
+
|
|
36
|
+
// @public (undocumented)
|
|
37
|
+
export const MAX_REGEX_MATCH = 500;
|
|
38
|
+
|
|
39
|
+
// @public (undocumented)
|
|
40
|
+
type OnBeforeRegexMatch = (tr: Transaction) => void;
|
|
41
|
+
|
|
42
|
+
// @public (undocumented)
|
|
43
|
+
export type OnHandlerApply = (state: EditorState, tr: Transaction, matchResult: RegExpExecArray) => void;
|
|
44
|
+
|
|
45
|
+
// @public (undocumented)
|
|
46
|
+
export type OnInputEvent = (props: {
|
|
47
|
+
state: EditorState;
|
|
48
|
+
from: number;
|
|
49
|
+
to: number;
|
|
50
|
+
}) => boolean;
|
|
51
|
+
|
|
52
|
+
// @public (undocumented)
|
|
53
|
+
type Options = {
|
|
54
|
+
allowInsertTextOnDocument?: boolean;
|
|
55
|
+
onInputEvent?: OnInputEvent;
|
|
56
|
+
onBeforeRegexMatch?: OnBeforeRegexMatch;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// @public (undocumented)
|
|
60
|
+
type Options_2 = {
|
|
61
|
+
isBlockNodeRule?: boolean;
|
|
62
|
+
allowInsertTextOnDocument?: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// @public (undocumented)
|
|
66
|
+
export const TEXT_INPUT_RULE_TRANSACTION_KEY = "input_rule_plugin_transaction";
|
|
67
|
+
|
|
68
|
+
// (No @packageDocumentation comment for this package)
|
|
69
|
+
|
|
70
|
+
```
|