@atlaskit/prosemirror-input-rules 3.4.2 → 3.6.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 +22 -3
- package/dist/cjs/constants.js +3 -2
- package/dist/cjs/handler.js +50 -7
- package/dist/cjs/plugin.js +10 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/es2019/constants.js +2 -1
- package/dist/es2019/handler.js +53 -9
- package/dist/es2019/plugin.js +10 -1
- package/dist/es2019/utils.js +1 -1
- package/dist/esm/constants.js +2 -1
- package/dist/esm/handler.js +51 -8
- package/dist/esm/plugin.js +10 -1
- package/dist/esm/utils.js +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/editor-common.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types-ts4.5/constants.d.ts +1 -0
- package/dist/types-ts4.5/editor-common.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atlaskit/prosemirror-input-rules
|
|
2
2
|
|
|
3
|
+
## 3.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`3c501a06f7c8b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3c501a06f7c8b) -
|
|
8
|
+
[ux] [EDITOR-2460] detect and format backticks that close strings on the LHS
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 3.5.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [`0ac75e0d28c72`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0ac75e0d28c72) -
|
|
19
|
+
Migrate @atlaskit/editor-prosemirror/history to @atlaskit/prosemirror-history package
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
|
|
3
25
|
## 3.4.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -99,7 +121,6 @@
|
|
|
99
121
|
|
|
100
122
|
These are no longer available via `@atlaskit/prosemirror-input-rules` but are available from
|
|
101
123
|
`@atlaskit/editor-common/types`:
|
|
102
|
-
|
|
103
124
|
- InputRuleWrapper
|
|
104
125
|
- InputRuleHandler
|
|
105
126
|
- OnHandlerApply
|
|
@@ -109,7 +130,6 @@
|
|
|
109
130
|
need to instantiate a `SafePlugin` (ie. `new SafePlugin(createPlugin( ... ))`).
|
|
110
131
|
|
|
111
132
|
`SafePlugin` exists in `@atlaskit/editor-common/safe-plugin`.
|
|
112
|
-
|
|
113
133
|
- createPlugin
|
|
114
134
|
- createInputRulePlugin
|
|
115
135
|
|
|
@@ -357,7 +377,6 @@
|
|
|
357
377
|
|
|
358
378
|
- [`c6feed82071`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c6feed82071) -
|
|
359
379
|
ED-11632: Bump prosemirror packages;
|
|
360
|
-
|
|
361
380
|
- prosmirror-commands 1.1.4 -> 1.1.11,
|
|
362
381
|
- prosemirror-model 1.11.0 -> 1.14.3,
|
|
363
382
|
- prosemirror-state 1.3.3 -> 1.3.4,
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.leafNodeReplacementCharacter = exports.TEXT_INPUT_RULE_TRANSACTION_KEY = exports.MAX_REGEX_MATCH = void 0;
|
|
6
|
+
exports.leafNodeReplacementCharacter = exports.TYPEAHEAD_TRIGGERS = 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
|
|
10
10
|
// This can be used in an input rule regex to be able to include or exclude such nodes.
|
|
11
11
|
var leafNodeReplacementCharacter = exports.leafNodeReplacementCharacter = "\uFFFC";
|
|
12
12
|
var TEXT_INPUT_RULE_TRANSACTION_KEY = exports.TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
13
|
-
var MAX_REGEX_MATCH = exports.MAX_REGEX_MATCH = 500;
|
|
13
|
+
var MAX_REGEX_MATCH = exports.MAX_REGEX_MATCH = 500;
|
|
14
|
+
var TYPEAHEAD_TRIGGERS = exports.TYPEAHEAD_TRIGGERS = [':', '/', '@'];
|
package/dist/cjs/handler.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createInputEventHandler = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
9
10
|
var _constants = require("./constants");
|
|
10
11
|
var _editorCommon = require("./editor-common");
|
|
11
12
|
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; }
|
|
@@ -39,11 +40,30 @@ var createInputEventHandler = exports.createInputEventHandler = function createI
|
|
|
39
40
|
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - _constants.MAX_REGEX_MATCH), $from.parentOffset, undefined, _constants.leafNodeReplacementCharacter) + text;
|
|
40
41
|
var result = findMatchOnRules({
|
|
41
42
|
rules: rules,
|
|
42
|
-
|
|
43
|
+
textToMatch: textBefore,
|
|
43
44
|
from: from,
|
|
44
45
|
to: to,
|
|
45
46
|
state: state
|
|
46
47
|
});
|
|
48
|
+
var isBackwardMatch;
|
|
49
|
+
if (!result && (0, _expValEquals.expValEquals)('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
50
|
+
if (_constants.TYPEAHEAD_TRIGGERS.includes(text)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
var textAfter = text + $from.parent.textBetween($from.parentOffset, Math.min($from.parent.content.size, $from.parentOffset + _constants.MAX_REGEX_MATCH), undefined, _constants.leafNodeReplacementCharacter);
|
|
54
|
+
isBackwardMatch = true;
|
|
55
|
+
result = findMatchOnRules({
|
|
56
|
+
rules: rules,
|
|
57
|
+
textToMatch: textAfter,
|
|
58
|
+
from: from,
|
|
59
|
+
to: to,
|
|
60
|
+
state: state,
|
|
61
|
+
isBackwardMatch: isBackwardMatch
|
|
62
|
+
});
|
|
63
|
+
if (!result) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
47
67
|
if (!result) {
|
|
48
68
|
return false;
|
|
49
69
|
}
|
|
@@ -53,7 +73,8 @@ var createInputEventHandler = exports.createInputEventHandler = function createI
|
|
|
53
73
|
textInserted: text,
|
|
54
74
|
from: result.from,
|
|
55
75
|
to: result.to,
|
|
56
|
-
matchedRule: result.matchedRule
|
|
76
|
+
matchedRule: result.matchedRule,
|
|
77
|
+
isBackwardMatch: isBackwardMatch
|
|
57
78
|
});
|
|
58
79
|
if (onBeforeRegexMatch) {
|
|
59
80
|
onBeforeRegexMatch(tr);
|
|
@@ -64,20 +85,42 @@ var createInputEventHandler = exports.createInputEventHandler = function createI
|
|
|
64
85
|
};
|
|
65
86
|
function findMatchOnRules(_ref3) {
|
|
66
87
|
var rules = _ref3.rules,
|
|
67
|
-
|
|
88
|
+
textToMatch = _ref3.textToMatch,
|
|
68
89
|
from = _ref3.from,
|
|
69
90
|
to = _ref3.to,
|
|
70
|
-
state = _ref3.state
|
|
91
|
+
state = _ref3.state,
|
|
92
|
+
isBackwardMatch = _ref3.isBackwardMatch;
|
|
71
93
|
for (var i = 0; i < rules.length; i++) {
|
|
72
|
-
var
|
|
94
|
+
var _textToMatch$at;
|
|
73
95
|
var rule = rules[i];
|
|
74
96
|
|
|
75
97
|
// Some plugins like Typeahead require a whitespace before a trigger character.
|
|
76
98
|
// We want them to fire inside a gap cursor. Yet, a gap cursor is not considered a whitespace,
|
|
77
|
-
// and `
|
|
99
|
+
// and `textToMatch` contains the text in the previous block before the gap cursor.
|
|
78
100
|
// Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
|
|
79
101
|
// (which may be a typeahead trigger) and ignore the rest.
|
|
80
|
-
var matchString = (0, _editorCommon.isGapCursorSelection)(state.selection) ? (
|
|
102
|
+
var matchString = (0, _editorCommon.isGapCursorSelection)(state.selection) ? (_textToMatch$at = textToMatch.at(-1)) !== null && _textToMatch$at !== void 0 ? _textToMatch$at : '' : textToMatch;
|
|
103
|
+
|
|
104
|
+
// EDITOR-2460
|
|
105
|
+
// if the user is formatting text to inline code from R to L i.e. backwards
|
|
106
|
+
if (rule.allowsBackwardMatch && isBackwardMatch && (0, _expValEquals.expValEquals)('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
107
|
+
var _match = rule.match.exec(matchString);
|
|
108
|
+
if (!_match) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
var matchEndPos = from + _match[0].length - 1;
|
|
112
|
+
var _transform = rule.handler(state, _match, from, matchEndPos);
|
|
113
|
+
if (_transform) {
|
|
114
|
+
return {
|
|
115
|
+
from: from,
|
|
116
|
+
to: matchEndPos,
|
|
117
|
+
matchedRule: _objectSpread(_objectSpread({}, rule), {}, {
|
|
118
|
+
result: _match
|
|
119
|
+
})
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
81
124
|
var match = rule.match.exec(matchString);
|
|
82
125
|
if (!match) {
|
|
83
126
|
continue;
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createInputRulePlugin = createInputRulePlugin;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
8
9
|
var _constants = require("./constants");
|
|
9
10
|
var _handler = require("./handler");
|
|
10
11
|
function createInputRulePlugin(pluginName, rules) {
|
|
@@ -44,7 +45,8 @@ function createInputRulePlugin(pluginName, rules) {
|
|
|
44
45
|
}
|
|
45
46
|
var matchedRule = pluginState.matchedRule,
|
|
46
47
|
from = pluginState.from,
|
|
47
|
-
to = pluginState.to
|
|
48
|
+
to = pluginState.to,
|
|
49
|
+
isBackwardMatch = pluginState.isBackwardMatch;
|
|
48
50
|
var result = matchedRule.result;
|
|
49
51
|
var mappedTo = transactionWithInputRuleMeta.mapping.map(to);
|
|
50
52
|
var tr = matchedRule.handler(newState, result, from, mappedTo);
|
|
@@ -55,6 +57,13 @@ function createInputRulePlugin(pluginName, rules) {
|
|
|
55
57
|
if (matchedRule.onHandlerApply) {
|
|
56
58
|
matchedRule.onHandlerApply(newState, tr, matchedRule.result);
|
|
57
59
|
}
|
|
60
|
+
|
|
61
|
+
// after inserting inline code, we need to reset the selection back
|
|
62
|
+
// else, we set the selection at the end of the inline code which doesn't make sense if we are closing the inline code from R to L
|
|
63
|
+
if (isBackwardMatch && (0, _expValEquals.expValEquals)('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
64
|
+
var prevSelection = oldState.selection.map(tr.doc, tr.mapping);
|
|
65
|
+
tr.setSelection(prevSelection);
|
|
66
|
+
}
|
|
58
67
|
return tr;
|
|
59
68
|
},
|
|
60
69
|
props: {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createPlugin = void 0;
|
|
7
|
-
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
8
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var _prosemirrorHistory = require("@atlaskit/prosemirror-history");
|
|
9
9
|
var _editorCommon = require("./editor-common");
|
|
10
10
|
var _plugin = require("./plugin");
|
|
11
11
|
var hasUnsupportedMarks = function hasUnsupportedMarks(state, start, end, marksNameUnsupported) {
|
|
@@ -53,7 +53,7 @@ var createPlugin = exports.createPlugin = function createPlugin(pluginName, rule
|
|
|
53
53
|
allowInsertTextOnDocument: allowInsertTextOnDocument,
|
|
54
54
|
onInputEvent: onInputEvent,
|
|
55
55
|
onBeforeRegexMatch: function onBeforeRegexMatch(tr) {
|
|
56
|
-
(0,
|
|
56
|
+
(0, _prosemirrorHistory.closeHistory)(tr);
|
|
57
57
|
},
|
|
58
58
|
checkOnBlur: checkOnBlur,
|
|
59
59
|
appendTextOnBlur: appendTextOnBlur
|
package/dist/es2019/constants.js
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
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
6
|
export const TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
7
|
-
export const MAX_REGEX_MATCH = 500;
|
|
7
|
+
export const MAX_REGEX_MATCH = 500;
|
|
8
|
+
export const TYPEAHEAD_TRIGGERS = [':', '/', '@'];
|
package/dist/es2019/handler.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
2
|
+
import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY, TYPEAHEAD_TRIGGERS } from './constants';
|
|
2
3
|
import { isGapCursorSelection } from './editor-common';
|
|
3
4
|
export const createInputEventHandler = ({
|
|
4
5
|
rules,
|
|
@@ -28,13 +29,32 @@ export const createInputEventHandler = ({
|
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
31
|
const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_REGEX_MATCH), $from.parentOffset, undefined, leafNodeReplacementCharacter) + text;
|
|
31
|
-
|
|
32
|
+
let result = findMatchOnRules({
|
|
32
33
|
rules,
|
|
33
|
-
textBefore,
|
|
34
|
+
textToMatch: textBefore,
|
|
34
35
|
from,
|
|
35
36
|
to,
|
|
36
37
|
state
|
|
37
38
|
});
|
|
39
|
+
let isBackwardMatch;
|
|
40
|
+
if (!result && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
41
|
+
if (TYPEAHEAD_TRIGGERS.includes(text)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const textAfter = text + $from.parent.textBetween($from.parentOffset, Math.min($from.parent.content.size, $from.parentOffset + MAX_REGEX_MATCH), undefined, leafNodeReplacementCharacter);
|
|
45
|
+
isBackwardMatch = true;
|
|
46
|
+
result = findMatchOnRules({
|
|
47
|
+
rules,
|
|
48
|
+
textToMatch: textAfter,
|
|
49
|
+
from,
|
|
50
|
+
to,
|
|
51
|
+
state,
|
|
52
|
+
isBackwardMatch
|
|
53
|
+
});
|
|
54
|
+
if (!result) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
38
58
|
if (!result) {
|
|
39
59
|
return false;
|
|
40
60
|
}
|
|
@@ -44,7 +64,8 @@ export const createInputEventHandler = ({
|
|
|
44
64
|
textInserted: text,
|
|
45
65
|
from: result.from,
|
|
46
66
|
to: result.to,
|
|
47
|
-
matchedRule: result.matchedRule
|
|
67
|
+
matchedRule: result.matchedRule,
|
|
68
|
+
isBackwardMatch: isBackwardMatch
|
|
48
69
|
});
|
|
49
70
|
if (onBeforeRegexMatch) {
|
|
50
71
|
onBeforeRegexMatch(tr);
|
|
@@ -54,21 +75,44 @@ export const createInputEventHandler = ({
|
|
|
54
75
|
};
|
|
55
76
|
function findMatchOnRules({
|
|
56
77
|
rules,
|
|
57
|
-
|
|
78
|
+
textToMatch,
|
|
58
79
|
from,
|
|
59
80
|
to,
|
|
60
|
-
state
|
|
81
|
+
state,
|
|
82
|
+
isBackwardMatch
|
|
61
83
|
}) {
|
|
62
84
|
for (let i = 0; i < rules.length; i++) {
|
|
63
|
-
var
|
|
85
|
+
var _textToMatch$at;
|
|
64
86
|
const rule = rules[i];
|
|
65
87
|
|
|
66
88
|
// Some plugins like Typeahead require a whitespace before a trigger character.
|
|
67
89
|
// We want them to fire inside a gap cursor. Yet, a gap cursor is not considered a whitespace,
|
|
68
|
-
// and `
|
|
90
|
+
// and `textToMatch` contains the text in the previous block before the gap cursor.
|
|
69
91
|
// Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
|
|
70
92
|
// (which may be a typeahead trigger) and ignore the rest.
|
|
71
|
-
const matchString = isGapCursorSelection(state.selection) ? (
|
|
93
|
+
const matchString = isGapCursorSelection(state.selection) ? (_textToMatch$at = textToMatch.at(-1)) !== null && _textToMatch$at !== void 0 ? _textToMatch$at : '' : textToMatch;
|
|
94
|
+
|
|
95
|
+
// EDITOR-2460
|
|
96
|
+
// if the user is formatting text to inline code from R to L i.e. backwards
|
|
97
|
+
if (rule.allowsBackwardMatch && isBackwardMatch && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
98
|
+
const match = rule.match.exec(matchString);
|
|
99
|
+
if (!match) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const matchEndPos = from + match[0].length - 1;
|
|
103
|
+
const transform = rule.handler(state, match, from, matchEndPos);
|
|
104
|
+
if (transform) {
|
|
105
|
+
return {
|
|
106
|
+
from: from,
|
|
107
|
+
to: matchEndPos,
|
|
108
|
+
matchedRule: {
|
|
109
|
+
...rule,
|
|
110
|
+
result: match
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
72
116
|
const match = rule.match.exec(matchString);
|
|
73
117
|
if (!match) {
|
|
74
118
|
continue;
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
2
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
3
4
|
import { createInputEventHandler } from './handler';
|
|
4
5
|
export function createInputRulePlugin(pluginName, rules, options = {}) {
|
|
@@ -36,7 +37,8 @@ export function createInputRulePlugin(pluginName, rules, options = {}) {
|
|
|
36
37
|
const {
|
|
37
38
|
matchedRule,
|
|
38
39
|
from,
|
|
39
|
-
to
|
|
40
|
+
to,
|
|
41
|
+
isBackwardMatch
|
|
40
42
|
} = pluginState;
|
|
41
43
|
const {
|
|
42
44
|
result
|
|
@@ -50,6 +52,13 @@ export function createInputRulePlugin(pluginName, rules, options = {}) {
|
|
|
50
52
|
if (matchedRule.onHandlerApply) {
|
|
51
53
|
matchedRule.onHandlerApply(newState, tr, matchedRule.result);
|
|
52
54
|
}
|
|
55
|
+
|
|
56
|
+
// after inserting inline code, we need to reset the selection back
|
|
57
|
+
// else, we set the selection at the end of the inline code which doesn't make sense if we are closing the inline code from R to L
|
|
58
|
+
if (isBackwardMatch && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
59
|
+
const prevSelection = oldState.selection.map(tr.doc, tr.mapping);
|
|
60
|
+
tr.setSelection(prevSelection);
|
|
61
|
+
}
|
|
53
62
|
return tr;
|
|
54
63
|
},
|
|
55
64
|
props: {
|
package/dist/es2019/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
2
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { closeHistory } from '@atlaskit/prosemirror-history';
|
|
3
3
|
import { isGapCursorSelection } from './editor-common';
|
|
4
4
|
import { createInputRulePlugin } from './plugin';
|
|
5
5
|
const hasUnsupportedMarks = (state, start, end, marksNameUnsupported) => {
|
package/dist/esm/constants.js
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
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
6
|
export var TEXT_INPUT_RULE_TRANSACTION_KEY = 'input_rule_plugin_transaction';
|
|
7
|
-
export var MAX_REGEX_MATCH = 500;
|
|
7
|
+
export var MAX_REGEX_MATCH = 500;
|
|
8
|
+
export var TYPEAHEAD_TRIGGERS = [':', '/', '@'];
|
package/dist/esm/handler.js
CHANGED
|
@@ -1,7 +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 {
|
|
4
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
5
|
+
import { leafNodeReplacementCharacter, MAX_REGEX_MATCH, TEXT_INPUT_RULE_TRANSACTION_KEY, TYPEAHEAD_TRIGGERS } from './constants';
|
|
5
6
|
import { isGapCursorSelection } from './editor-common';
|
|
6
7
|
export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
7
8
|
var rules = _ref.rules,
|
|
@@ -32,11 +33,30 @@ export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
|
32
33
|
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_REGEX_MATCH), $from.parentOffset, undefined, leafNodeReplacementCharacter) + text;
|
|
33
34
|
var result = findMatchOnRules({
|
|
34
35
|
rules: rules,
|
|
35
|
-
|
|
36
|
+
textToMatch: textBefore,
|
|
36
37
|
from: from,
|
|
37
38
|
to: to,
|
|
38
39
|
state: state
|
|
39
40
|
});
|
|
41
|
+
var isBackwardMatch;
|
|
42
|
+
if (!result && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
43
|
+
if (TYPEAHEAD_TRIGGERS.includes(text)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var textAfter = text + $from.parent.textBetween($from.parentOffset, Math.min($from.parent.content.size, $from.parentOffset + MAX_REGEX_MATCH), undefined, leafNodeReplacementCharacter);
|
|
47
|
+
isBackwardMatch = true;
|
|
48
|
+
result = findMatchOnRules({
|
|
49
|
+
rules: rules,
|
|
50
|
+
textToMatch: textAfter,
|
|
51
|
+
from: from,
|
|
52
|
+
to: to,
|
|
53
|
+
state: state,
|
|
54
|
+
isBackwardMatch: isBackwardMatch
|
|
55
|
+
});
|
|
56
|
+
if (!result) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
40
60
|
if (!result) {
|
|
41
61
|
return false;
|
|
42
62
|
}
|
|
@@ -46,7 +66,8 @@ export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
|
46
66
|
textInserted: text,
|
|
47
67
|
from: result.from,
|
|
48
68
|
to: result.to,
|
|
49
|
-
matchedRule: result.matchedRule
|
|
69
|
+
matchedRule: result.matchedRule,
|
|
70
|
+
isBackwardMatch: isBackwardMatch
|
|
50
71
|
});
|
|
51
72
|
if (onBeforeRegexMatch) {
|
|
52
73
|
onBeforeRegexMatch(tr);
|
|
@@ -57,20 +78,42 @@ export var createInputEventHandler = function createInputEventHandler(_ref) {
|
|
|
57
78
|
};
|
|
58
79
|
function findMatchOnRules(_ref3) {
|
|
59
80
|
var rules = _ref3.rules,
|
|
60
|
-
|
|
81
|
+
textToMatch = _ref3.textToMatch,
|
|
61
82
|
from = _ref3.from,
|
|
62
83
|
to = _ref3.to,
|
|
63
|
-
state = _ref3.state
|
|
84
|
+
state = _ref3.state,
|
|
85
|
+
isBackwardMatch = _ref3.isBackwardMatch;
|
|
64
86
|
for (var i = 0; i < rules.length; i++) {
|
|
65
|
-
var
|
|
87
|
+
var _textToMatch$at;
|
|
66
88
|
var rule = rules[i];
|
|
67
89
|
|
|
68
90
|
// Some plugins like Typeahead require a whitespace before a trigger character.
|
|
69
91
|
// We want them to fire inside a gap cursor. Yet, a gap cursor is not considered a whitespace,
|
|
70
|
-
// and `
|
|
92
|
+
// and `textToMatch` contains the text in the previous block before the gap cursor.
|
|
71
93
|
// Here is a workaround: if we inside a gap cursor, match the input rule only against the last typed character
|
|
72
94
|
// (which may be a typeahead trigger) and ignore the rest.
|
|
73
|
-
var matchString = isGapCursorSelection(state.selection) ? (
|
|
95
|
+
var matchString = isGapCursorSelection(state.selection) ? (_textToMatch$at = textToMatch.at(-1)) !== null && _textToMatch$at !== void 0 ? _textToMatch$at : '' : textToMatch;
|
|
96
|
+
|
|
97
|
+
// EDITOR-2460
|
|
98
|
+
// if the user is formatting text to inline code from R to L i.e. backwards
|
|
99
|
+
if (rule.allowsBackwardMatch && isBackwardMatch && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
100
|
+
var _match = rule.match.exec(matchString);
|
|
101
|
+
if (!_match) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
var matchEndPos = from + _match[0].length - 1;
|
|
105
|
+
var _transform = rule.handler(state, _match, from, matchEndPos);
|
|
106
|
+
if (_transform) {
|
|
107
|
+
return {
|
|
108
|
+
from: from,
|
|
109
|
+
to: matchEndPos,
|
|
110
|
+
matchedRule: _objectSpread(_objectSpread({}, rule), {}, {
|
|
111
|
+
result: _match
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
74
117
|
var match = rule.match.exec(matchString);
|
|
75
118
|
if (!match) {
|
|
76
119
|
continue;
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
2
3
|
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from './constants';
|
|
3
4
|
import { createInputEventHandler } from './handler';
|
|
4
5
|
export function createInputRulePlugin(pluginName, rules) {
|
|
@@ -38,7 +39,8 @@ export function createInputRulePlugin(pluginName, rules) {
|
|
|
38
39
|
}
|
|
39
40
|
var matchedRule = pluginState.matchedRule,
|
|
40
41
|
from = pluginState.from,
|
|
41
|
-
to = pluginState.to
|
|
42
|
+
to = pluginState.to,
|
|
43
|
+
isBackwardMatch = pluginState.isBackwardMatch;
|
|
42
44
|
var result = matchedRule.result;
|
|
43
45
|
var mappedTo = transactionWithInputRuleMeta.mapping.map(to);
|
|
44
46
|
var tr = matchedRule.handler(newState, result, from, mappedTo);
|
|
@@ -49,6 +51,13 @@ export function createInputRulePlugin(pluginName, rules) {
|
|
|
49
51
|
if (matchedRule.onHandlerApply) {
|
|
50
52
|
matchedRule.onHandlerApply(newState, tr, matchedRule.result);
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
// after inserting inline code, we need to reset the selection back
|
|
56
|
+
// else, we set the selection at the end of the inline code which doesn't make sense if we are closing the inline code from R to L
|
|
57
|
+
if (isBackwardMatch && expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
|
|
58
|
+
var prevSelection = oldState.selection.map(tr.doc, tr.mapping);
|
|
59
|
+
tr.setSelection(prevSelection);
|
|
60
|
+
}
|
|
52
61
|
return tr;
|
|
53
62
|
},
|
|
54
63
|
props: {
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
2
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { closeHistory } from '@atlaskit/prosemirror-history';
|
|
3
3
|
import { isGapCursorSelection } from './editor-common';
|
|
4
4
|
import { createInputRulePlugin } from './plugin';
|
|
5
5
|
var hasUnsupportedMarks = function hasUnsupportedMarks(state, start, end, marksNameUnsupported) {
|
|
@@ -8,6 +8,7 @@ import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prose
|
|
|
8
8
|
export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
|
|
9
9
|
export type OnHandlerApply = (state: EditorState, tr: Transaction, matchResult: RegExpExecArray) => void;
|
|
10
10
|
export interface InputRuleWrapper {
|
|
11
|
+
allowsBackwardMatch?: boolean;
|
|
11
12
|
handler: InputRuleHandler;
|
|
12
13
|
match: RegExp;
|
|
13
14
|
onHandlerApply?: OnHandlerApply;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prose
|
|
|
8
8
|
export type InputRuleHandler = (state: EditorState, matchResult: RegExpExecArray, start: number, end: number) => Transaction | null;
|
|
9
9
|
export type OnHandlerApply = (state: EditorState, tr: Transaction, matchResult: RegExpExecArray) => void;
|
|
10
10
|
export interface InputRuleWrapper {
|
|
11
|
+
allowsBackwardMatch?: boolean;
|
|
11
12
|
handler: InputRuleHandler;
|
|
12
13
|
match: RegExp;
|
|
13
14
|
onHandlerApply?: OnHandlerApply;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/prosemirror-input-rules",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.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,10 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
31
|
+
"@atlaskit/prosemirror-history": "^0.2.0",
|
|
32
|
+
"@atlaskit/tmp-editor-statsig": "^13.27.0",
|
|
31
33
|
"@babel/runtime": "^7.0.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
36
|
+
"@atlaskit/editor-common": "^110.22.0"
|
|
35
37
|
},
|
|
36
38
|
"techstack": {
|
|
37
39
|
"@atlassian/frontend": {
|
|
@@ -46,8 +48,5 @@
|
|
|
46
48
|
"emotion"
|
|
47
49
|
]
|
|
48
50
|
}
|
|
49
|
-
},
|
|
50
|
-
"af:exports": {
|
|
51
|
-
".": "./src/index.ts"
|
|
52
51
|
}
|
|
53
52
|
}
|