@atlaskit/editor-core 190.1.9 → 190.1.12
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 +15 -0
- package/afm-cc/tsconfig.json +3 -0
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/ui/ConfigPanel/utils.js +4 -3
- package/dist/cjs/ui/ContentStyles/code-block.js +2 -2
- package/dist/cjs/ui/ContentStyles/expand.js +10 -45
- package/dist/cjs/ui/ContentStyles/index.js +3 -3
- package/dist/cjs/ui/ContentStyles/panel.js +2 -2
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/ui/ConfigPanel/utils.js +5 -2
- package/dist/es2019/ui/ContentStyles/code-block.js +2 -2
- package/dist/es2019/ui/ContentStyles/expand.js +19 -64
- package/dist/es2019/ui/ContentStyles/index.js +8 -8
- package/dist/es2019/ui/ContentStyles/panel.js +2 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/ui/ConfigPanel/utils.js +3 -2
- package/dist/esm/ui/ContentStyles/code-block.js +2 -2
- package/dist/esm/ui/ContentStyles/expand.js +10 -46
- package/dist/esm/ui/ContentStyles/index.js +3 -3
- package/dist/esm/ui/ContentStyles/panel.js +2 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/ui/ConfigPanel/utils.d.ts +1 -0
- package/dist/types/ui/ContentStyles/code-block.d.ts +1 -2
- package/dist/types/ui/ContentStyles/expand.d.ts +1 -2
- package/dist/types/ui/ContentStyles/panel.d.ts +1 -2
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/ui/ConfigPanel/utils.d.ts +1 -0
- package/dist/types-ts4.5/ui/ContentStyles/code-block.d.ts +1 -2
- package/dist/types-ts4.5/ui/ContentStyles/expand.d.ts +1 -2
- package/dist/types-ts4.5/ui/ContentStyles/panel.d.ts +1 -2
- package/package.json +3 -2
- package/dist/cjs/plugins/custom-autoformat/doc.js +0 -91
- package/dist/cjs/plugins/custom-autoformat/index.js +0 -131
- package/dist/cjs/plugins/custom-autoformat/input-rules.js +0 -35
- package/dist/cjs/plugins/custom-autoformat/reducers.js +0 -56
- package/dist/cjs/plugins/custom-autoformat/types.js +0 -5
- package/dist/cjs/plugins/custom-autoformat/utils.js +0 -14
- package/dist/es2019/plugins/custom-autoformat/doc.js +0 -71
- package/dist/es2019/plugins/custom-autoformat/index.js +0 -101
- package/dist/es2019/plugins/custom-autoformat/input-rules.js +0 -31
- package/dist/es2019/plugins/custom-autoformat/reducers.js +0 -40
- package/dist/es2019/plugins/custom-autoformat/types.js +0 -1
- package/dist/es2019/plugins/custom-autoformat/utils.js +0 -6
- package/dist/esm/plugins/custom-autoformat/doc.js +0 -84
- package/dist/esm/plugins/custom-autoformat/index.js +0 -124
- package/dist/esm/plugins/custom-autoformat/input-rules.js +0 -29
- package/dist/esm/plugins/custom-autoformat/reducers.js +0 -49
- package/dist/esm/plugins/custom-autoformat/types.js +0 -1
- package/dist/esm/plugins/custom-autoformat/utils.js +0 -8
- package/dist/types/plugins/custom-autoformat/doc.d.ts +0 -6
- package/dist/types/plugins/custom-autoformat/index.d.ts +0 -6
- package/dist/types/plugins/custom-autoformat/input-rules.d.ts +0 -9
- package/dist/types/plugins/custom-autoformat/reducers.d.ts +0 -4
- package/dist/types/plugins/custom-autoformat/types.d.ts +0 -31
- package/dist/types/plugins/custom-autoformat/utils.d.ts +0 -6
- package/dist/types-ts4.5/plugins/custom-autoformat/doc.d.ts +0 -6
- package/dist/types-ts4.5/plugins/custom-autoformat/index.d.ts +0 -6
- package/dist/types-ts4.5/plugins/custom-autoformat/input-rules.d.ts +0 -9
- package/dist/types-ts4.5/plugins/custom-autoformat/reducers.d.ts +0 -4
- package/dist/types-ts4.5/plugins/custom-autoformat/types.d.ts +0 -31
- package/dist/types-ts4.5/plugins/custom-autoformat/utils.d.ts +0 -6
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
|
-
import reducers from './reducers';
|
|
4
|
-
import { triggerInputRule } from './input-rules';
|
|
5
|
-
import { completeReplacements, buildHandler } from './doc';
|
|
6
|
-
import { getPluginState, pluginKey } from './utils';
|
|
7
|
-
export const createPMPlugin = ({
|
|
8
|
-
providerFactory
|
|
9
|
-
}) => {
|
|
10
|
-
const rules = [];
|
|
11
|
-
return new SafePlugin({
|
|
12
|
-
state: {
|
|
13
|
-
init() {
|
|
14
|
-
return {
|
|
15
|
-
resolving: [],
|
|
16
|
-
matches: []
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
apply(tr, prevPluginState) {
|
|
20
|
-
if (!prevPluginState) {
|
|
21
|
-
return prevPluginState;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// remap positions
|
|
25
|
-
const remappedPluginState = {
|
|
26
|
-
...prevPluginState,
|
|
27
|
-
resolving: prevPluginState.resolving.map(candidate => ({
|
|
28
|
-
...candidate,
|
|
29
|
-
start: tr.mapping.map(candidate.start),
|
|
30
|
-
end: tr.mapping.map(candidate.end, -1)
|
|
31
|
-
}))
|
|
32
|
-
};
|
|
33
|
-
const meta = tr.getMeta(pluginKey);
|
|
34
|
-
if (!meta) {
|
|
35
|
-
return remappedPluginState;
|
|
36
|
-
}
|
|
37
|
-
return reducers(remappedPluginState, meta);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
props: {
|
|
41
|
-
handleTextInput(view, from, to, text) {
|
|
42
|
-
triggerInputRule(view, rules, from, to, text);
|
|
43
|
-
return false;
|
|
44
|
-
},
|
|
45
|
-
handleKeyDown: keydownHandler({
|
|
46
|
-
Enter: (_state, _dispatch, view) => {
|
|
47
|
-
if (view) {
|
|
48
|
-
triggerInputRule(view, rules, view.state.selection.from, view.state.selection.to, '');
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
},
|
|
54
|
-
view() {
|
|
55
|
-
const handleProvider = (name, provider) => {
|
|
56
|
-
if (name !== 'autoformattingProvider' || !provider) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
provider.then(async autoformattingProvider => {
|
|
60
|
-
const ruleset = await autoformattingProvider.getRules();
|
|
61
|
-
Object.keys(ruleset).forEach(rule => {
|
|
62
|
-
const inputRule = {
|
|
63
|
-
matchTyping: new RegExp('(\\s+|^)' + rule + '(\\s|,|\\.)$'),
|
|
64
|
-
matchEnter: new RegExp('(\\s+|^)' + rule + '()$'),
|
|
65
|
-
handler: buildHandler(rule, ruleset[rule])
|
|
66
|
-
};
|
|
67
|
-
rules.push(inputRule);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
providerFactory.subscribe('autoformattingProvider', handleProvider);
|
|
72
|
-
return {
|
|
73
|
-
update(view) {
|
|
74
|
-
const currentState = getPluginState(view.state);
|
|
75
|
-
if (!currentState) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// make replacements in document for finished autoformats
|
|
80
|
-
if (currentState.matches) {
|
|
81
|
-
completeReplacements(view, currentState);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
destroy() {
|
|
85
|
-
providerFactory.unsubscribe('autoformattingProvider', handleProvider);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
key: pluginKey
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
const customAutoformatPlugin = () => ({
|
|
93
|
-
name: 'customAutoformat',
|
|
94
|
-
pmPlugins() {
|
|
95
|
-
return [{
|
|
96
|
-
name: 'customAutoformat',
|
|
97
|
-
plugin: createPMPlugin
|
|
98
|
-
}];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
export default customAutoformatPlugin;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const MAX_MATCH = 500;
|
|
2
|
-
|
|
3
|
-
// this is a modified version of
|
|
4
|
-
// https://github.com/ProseMirror/prosemirror-inputrules/blob/master/src/inputrules.js#L53
|
|
5
|
-
export const triggerInputRule = (view, rules, from, to, text) => {
|
|
6
|
-
const {
|
|
7
|
-
state
|
|
8
|
-
} = view;
|
|
9
|
-
const $from = state.doc.resolve(from);
|
|
10
|
-
if ($from.parent.type.spec.code) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, undefined, '\ufffc') + text;
|
|
14
|
-
|
|
15
|
-
// loop through rules trying to find one that matches
|
|
16
|
-
for (let i = 0; i < rules.length; i++) {
|
|
17
|
-
let match;
|
|
18
|
-
if (text.length) {
|
|
19
|
-
match = rules[i].matchTyping.exec(textBefore);
|
|
20
|
-
} else {
|
|
21
|
-
match = rules[i].matchEnter.exec(textBefore);
|
|
22
|
-
}
|
|
23
|
-
if (match) {
|
|
24
|
-
// kick off the handler
|
|
25
|
-
const pos = from - (match[0].length - text.length);
|
|
26
|
-
rules[i].handler(view, match, pos, to);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// queues a match at a given position in the document
|
|
2
|
-
const matched = (state, action) => ({
|
|
3
|
-
...state,
|
|
4
|
-
resolving: [...state.resolving, {
|
|
5
|
-
start: action.start,
|
|
6
|
-
end: action.end,
|
|
7
|
-
match: action.match
|
|
8
|
-
}]
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// store the replacement for a match
|
|
12
|
-
const resolved = (state, action) => ({
|
|
13
|
-
...state,
|
|
14
|
-
matches: [...state.matches, {
|
|
15
|
-
replacement: action.replacement,
|
|
16
|
-
matchString: action.matchString
|
|
17
|
-
}]
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// indicates a replacement in the document has been completed, and removes the match from both resolving and matches
|
|
21
|
-
const finish = (state, action) => {
|
|
22
|
-
return {
|
|
23
|
-
...state,
|
|
24
|
-
resolving: state.resolving.filter(resolving => resolving.match[0] !== action.matchString),
|
|
25
|
-
matches: state.matches.filter(matching => matching.matchString !== action.matchString)
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const reduce = (state, action) => {
|
|
29
|
-
switch (action.action) {
|
|
30
|
-
case 'matched':
|
|
31
|
-
return matched(state, action);
|
|
32
|
-
case 'resolved':
|
|
33
|
-
return resolved(state, action);
|
|
34
|
-
case 'finish':
|
|
35
|
-
return finish(state, action);
|
|
36
|
-
default:
|
|
37
|
-
return state;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
export default reduce;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
export const pluginKey = new PluginKey('customAutoformatPlugin');
|
|
3
|
-
export const getPluginState = editorState => pluginKey.getState(editorState);
|
|
4
|
-
export const autoformatAction = (tr, action) => {
|
|
5
|
-
return tr.setMeta(pluginKey, action);
|
|
6
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
4
|
-
import { processRawValue } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { autoformatAction } from './utils';
|
|
6
|
-
export var buildHandler = function buildHandler(_regex, handler) {
|
|
7
|
-
return /*#__PURE__*/function () {
|
|
8
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(view, match, start, end) {
|
|
9
|
-
var replacementPromise, replacementData, replacementNode;
|
|
10
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
|
-
while (1) switch (_context.prev = _context.next) {
|
|
12
|
-
case 0:
|
|
13
|
-
replacementPromise = handler(match.slice(1, match.length - 1)); // queue the position and match pair so that we can remap across transactions
|
|
14
|
-
// while we wait for the replacmentPromise to resolve
|
|
15
|
-
view.dispatch(autoformatAction(view.state.tr, {
|
|
16
|
-
action: 'matched',
|
|
17
|
-
match: match,
|
|
18
|
-
start: start,
|
|
19
|
-
end: end
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// ask the provider to give us an ADF node to replace the text with
|
|
23
|
-
_context.next = 4;
|
|
24
|
-
return replacementPromise;
|
|
25
|
-
case 4:
|
|
26
|
-
replacementData = _context.sent;
|
|
27
|
-
replacementNode = processRawValue(view.state.schema, replacementData);
|
|
28
|
-
view.dispatch(autoformatAction(view.state.tr, {
|
|
29
|
-
action: 'resolved',
|
|
30
|
-
matchString: match[0],
|
|
31
|
-
replacement: replacementNode
|
|
32
|
-
}));
|
|
33
|
-
return _context.abrupt("return", replacementData);
|
|
34
|
-
case 8:
|
|
35
|
-
case "end":
|
|
36
|
-
return _context.stop();
|
|
37
|
-
}
|
|
38
|
-
}, _callee);
|
|
39
|
-
}));
|
|
40
|
-
return function (_x, _x2, _x3, _x4) {
|
|
41
|
-
return _ref.apply(this, arguments);
|
|
42
|
-
};
|
|
43
|
-
}();
|
|
44
|
-
};
|
|
45
|
-
export var completeReplacements = function completeReplacements(view, state) {
|
|
46
|
-
var inlineCard = view.state.schema.nodes.inlineCard;
|
|
47
|
-
state.matches.forEach(function (completedMatch) {
|
|
48
|
-
var matchingRequests = state.resolving.filter(function (candidate) {
|
|
49
|
-
return candidate.match[0] === completedMatch.matchString;
|
|
50
|
-
});
|
|
51
|
-
var tr = view.state.tr;
|
|
52
|
-
matchingRequests.forEach(function (request) {
|
|
53
|
-
var match = request.match,
|
|
54
|
-
start = request.start,
|
|
55
|
-
end = request.end;
|
|
56
|
-
var replacement = completedMatch.replacement;
|
|
57
|
-
var prefix = match[1];
|
|
58
|
-
var suffix = match[match.length - 1];
|
|
59
|
-
var matchEndPos = end + suffix.length;
|
|
60
|
-
|
|
61
|
-
// only permit inlineCard as replacement target for now
|
|
62
|
-
if (!replacement || replacement.type !== inlineCard && !replacement.isText) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// get the current document text, adding # or | if we cross node boundaries
|
|
67
|
-
var docText = view.state.doc.textBetween(start, matchEndPos, '#', '|');
|
|
68
|
-
|
|
69
|
-
// only replace if text still remains the same as when typed at the start
|
|
70
|
-
if (docText === match[0]) {
|
|
71
|
-
tr = tr.replaceWith(tr.mapping.map(start + prefix.length), tr.mapping.map(end, -1), replacement);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// clear this match from plugin state now that we've processed it
|
|
76
|
-
tr = autoformatAction(tr, {
|
|
77
|
-
action: 'finish',
|
|
78
|
-
matchString: completedMatch.matchString
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// and dispatch the replacement, closing history for cmd+z to allow undo separately
|
|
82
|
-
view.dispatch(closeHistory(tr));
|
|
83
|
-
});
|
|
84
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
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; }
|
|
5
|
-
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; }
|
|
6
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
-
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
8
|
-
import reducers from './reducers';
|
|
9
|
-
import { triggerInputRule } from './input-rules';
|
|
10
|
-
import { completeReplacements, buildHandler } from './doc';
|
|
11
|
-
import { getPluginState, pluginKey } from './utils';
|
|
12
|
-
export var createPMPlugin = function createPMPlugin(_ref) {
|
|
13
|
-
var providerFactory = _ref.providerFactory;
|
|
14
|
-
var rules = [];
|
|
15
|
-
return new SafePlugin({
|
|
16
|
-
state: {
|
|
17
|
-
init: function init() {
|
|
18
|
-
return {
|
|
19
|
-
resolving: [],
|
|
20
|
-
matches: []
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
apply: function apply(tr, prevPluginState) {
|
|
24
|
-
if (!prevPluginState) {
|
|
25
|
-
return prevPluginState;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// remap positions
|
|
29
|
-
var remappedPluginState = _objectSpread(_objectSpread({}, prevPluginState), {}, {
|
|
30
|
-
resolving: prevPluginState.resolving.map(function (candidate) {
|
|
31
|
-
return _objectSpread(_objectSpread({}, candidate), {}, {
|
|
32
|
-
start: tr.mapping.map(candidate.start),
|
|
33
|
-
end: tr.mapping.map(candidate.end, -1)
|
|
34
|
-
});
|
|
35
|
-
})
|
|
36
|
-
});
|
|
37
|
-
var meta = tr.getMeta(pluginKey);
|
|
38
|
-
if (!meta) {
|
|
39
|
-
return remappedPluginState;
|
|
40
|
-
}
|
|
41
|
-
return reducers(remappedPluginState, meta);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
props: {
|
|
45
|
-
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
46
|
-
triggerInputRule(view, rules, from, to, text);
|
|
47
|
-
return false;
|
|
48
|
-
},
|
|
49
|
-
handleKeyDown: keydownHandler({
|
|
50
|
-
Enter: function Enter(_state, _dispatch, view) {
|
|
51
|
-
if (view) {
|
|
52
|
-
triggerInputRule(view, rules, view.state.selection.from, view.state.selection.to, '');
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
},
|
|
58
|
-
view: function view() {
|
|
59
|
-
var handleProvider = function handleProvider(name, provider) {
|
|
60
|
-
if (name !== 'autoformattingProvider' || !provider) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
provider.then( /*#__PURE__*/function () {
|
|
64
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(autoformattingProvider) {
|
|
65
|
-
var ruleset;
|
|
66
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
67
|
-
while (1) switch (_context.prev = _context.next) {
|
|
68
|
-
case 0:
|
|
69
|
-
_context.next = 2;
|
|
70
|
-
return autoformattingProvider.getRules();
|
|
71
|
-
case 2:
|
|
72
|
-
ruleset = _context.sent;
|
|
73
|
-
Object.keys(ruleset).forEach(function (rule) {
|
|
74
|
-
var inputRule = {
|
|
75
|
-
matchTyping: new RegExp('(\\s+|^)' + rule + '(\\s|,|\\.)$'),
|
|
76
|
-
matchEnter: new RegExp('(\\s+|^)' + rule + '()$'),
|
|
77
|
-
handler: buildHandler(rule, ruleset[rule])
|
|
78
|
-
};
|
|
79
|
-
rules.push(inputRule);
|
|
80
|
-
});
|
|
81
|
-
case 4:
|
|
82
|
-
case "end":
|
|
83
|
-
return _context.stop();
|
|
84
|
-
}
|
|
85
|
-
}, _callee);
|
|
86
|
-
}));
|
|
87
|
-
return function (_x) {
|
|
88
|
-
return _ref2.apply(this, arguments);
|
|
89
|
-
};
|
|
90
|
-
}());
|
|
91
|
-
};
|
|
92
|
-
providerFactory.subscribe('autoformattingProvider', handleProvider);
|
|
93
|
-
return {
|
|
94
|
-
update: function update(view) {
|
|
95
|
-
var currentState = getPluginState(view.state);
|
|
96
|
-
if (!currentState) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// make replacements in document for finished autoformats
|
|
101
|
-
if (currentState.matches) {
|
|
102
|
-
completeReplacements(view, currentState);
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
destroy: function destroy() {
|
|
106
|
-
providerFactory.unsubscribe('autoformattingProvider', handleProvider);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
key: pluginKey
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
var customAutoformatPlugin = function customAutoformatPlugin() {
|
|
114
|
-
return {
|
|
115
|
-
name: 'customAutoformat',
|
|
116
|
-
pmPlugins: function pmPlugins() {
|
|
117
|
-
return [{
|
|
118
|
-
name: 'customAutoformat',
|
|
119
|
-
plugin: createPMPlugin
|
|
120
|
-
}];
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
export default customAutoformatPlugin;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var MAX_MATCH = 500;
|
|
2
|
-
|
|
3
|
-
// this is a modified version of
|
|
4
|
-
// https://github.com/ProseMirror/prosemirror-inputrules/blob/master/src/inputrules.js#L53
|
|
5
|
-
export var triggerInputRule = function triggerInputRule(view, rules, from, to, text) {
|
|
6
|
-
var state = view.state;
|
|
7
|
-
var $from = state.doc.resolve(from);
|
|
8
|
-
if ($from.parent.type.spec.code) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, undefined, "\uFFFC") + text;
|
|
12
|
-
|
|
13
|
-
// loop through rules trying to find one that matches
|
|
14
|
-
for (var i = 0; i < rules.length; i++) {
|
|
15
|
-
var _match = void 0;
|
|
16
|
-
if (text.length) {
|
|
17
|
-
_match = rules[i].matchTyping.exec(textBefore);
|
|
18
|
-
} else {
|
|
19
|
-
_match = rules[i].matchEnter.exec(textBefore);
|
|
20
|
-
}
|
|
21
|
-
if (_match) {
|
|
22
|
-
// kick off the handler
|
|
23
|
-
var pos = from - (_match[0].length - text.length);
|
|
24
|
-
rules[i].handler(view, _match, pos, to);
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
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; }
|
|
4
|
-
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; }
|
|
5
|
-
// queues a match at a given position in the document
|
|
6
|
-
var matched = function matched(state, action) {
|
|
7
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
8
|
-
resolving: [].concat(_toConsumableArray(state.resolving), [{
|
|
9
|
-
start: action.start,
|
|
10
|
-
end: action.end,
|
|
11
|
-
match: action.match
|
|
12
|
-
}])
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// store the replacement for a match
|
|
17
|
-
var resolved = function resolved(state, action) {
|
|
18
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
19
|
-
matches: [].concat(_toConsumableArray(state.matches), [{
|
|
20
|
-
replacement: action.replacement,
|
|
21
|
-
matchString: action.matchString
|
|
22
|
-
}])
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// indicates a replacement in the document has been completed, and removes the match from both resolving and matches
|
|
27
|
-
var finish = function finish(state, action) {
|
|
28
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
29
|
-
resolving: state.resolving.filter(function (resolving) {
|
|
30
|
-
return resolving.match[0] !== action.matchString;
|
|
31
|
-
}),
|
|
32
|
-
matches: state.matches.filter(function (matching) {
|
|
33
|
-
return matching.matchString !== action.matchString;
|
|
34
|
-
})
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var reduce = function reduce(state, action) {
|
|
38
|
-
switch (action.action) {
|
|
39
|
-
case 'matched':
|
|
40
|
-
return matched(state, action);
|
|
41
|
-
case 'resolved':
|
|
42
|
-
return resolved(state, action);
|
|
43
|
-
case 'finish':
|
|
44
|
-
return finish(state, action);
|
|
45
|
-
default:
|
|
46
|
-
return state;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export default reduce;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
export var pluginKey = new PluginKey('customAutoformatPlugin');
|
|
3
|
-
export var getPluginState = function getPluginState(editorState) {
|
|
4
|
-
return pluginKey.getState(editorState);
|
|
5
|
-
};
|
|
6
|
-
export var autoformatAction = function autoformatAction(tr, action) {
|
|
7
|
-
return tr.setMeta(pluginKey, action);
|
|
8
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { CustomAutoformatState } from './types';
|
|
3
|
-
import type { InputRuleHander } from './input-rules';
|
|
4
|
-
import type { AutoformatHandler } from '@atlaskit/editor-common/provider-factory';
|
|
5
|
-
export declare const buildHandler: (_regex: string, handler: AutoformatHandler) => InputRuleHander;
|
|
6
|
-
export declare const completeReplacements: (view: EditorView, state: CustomAutoformatState) => void;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type { NextEditorPlugin, PMPluginFactoryParams } from '../../types';
|
|
3
|
-
import type { CustomAutoformatState } from './types';
|
|
4
|
-
export declare const createPMPlugin: ({ providerFactory }: PMPluginFactoryParams) => SafePlugin<CustomAutoformatState>;
|
|
5
|
-
declare const customAutoformatPlugin: NextEditorPlugin<'customAutoformat'>;
|
|
6
|
-
export default customAutoformatPlugin;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { AutoformatReplacement } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
export type InputRuleHander = (view: EditorView, match: string[], start: number, end: number) => Promise<AutoformatReplacement>;
|
|
4
|
-
export type InputRule = {
|
|
5
|
-
matchTyping: RegExp;
|
|
6
|
-
matchEnter: RegExp;
|
|
7
|
-
handler: InputRuleHander;
|
|
8
|
-
};
|
|
9
|
-
export declare const triggerInputRule: (view: EditorView, rules: Array<InputRule>, from: number, to: number, text: string) => boolean;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Node as ProsemirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export type { AutoformatHandler, AutoformatReplacement, AutoformattingProvider, AutoformatRuleset as Ruleset, } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
export type AutoformatCandidate = {
|
|
4
|
-
start: number;
|
|
5
|
-
end: number;
|
|
6
|
-
match: string[];
|
|
7
|
-
};
|
|
8
|
-
export type AutoformatMatch = {
|
|
9
|
-
matchString: string;
|
|
10
|
-
replacement?: ProsemirrorNode;
|
|
11
|
-
};
|
|
12
|
-
export type CustomAutoformatState = {
|
|
13
|
-
resolving: Array<AutoformatCandidate>;
|
|
14
|
-
matches: Array<AutoformatMatch>;
|
|
15
|
-
};
|
|
16
|
-
export type CustomAutoformatMatched = {
|
|
17
|
-
action: 'matched';
|
|
18
|
-
start: number;
|
|
19
|
-
end: number;
|
|
20
|
-
match: string[];
|
|
21
|
-
};
|
|
22
|
-
export type CustomAutoformatResolved = {
|
|
23
|
-
action: 'resolved';
|
|
24
|
-
matchString: string;
|
|
25
|
-
replacement?: ProsemirrorNode;
|
|
26
|
-
};
|
|
27
|
-
export type CustomAutoformatFinish = {
|
|
28
|
-
action: 'finish';
|
|
29
|
-
matchString: string;
|
|
30
|
-
};
|
|
31
|
-
export type CustomAutoformatAction = CustomAutoformatMatched | CustomAutoformatResolved | CustomAutoformatFinish;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import type { CustomAutoformatState, CustomAutoformatAction } from './types';
|
|
4
|
-
export declare const pluginKey: PluginKey<any>;
|
|
5
|
-
export declare const getPluginState: (editorState: EditorState) => CustomAutoformatState | undefined;
|
|
6
|
-
export declare const autoformatAction: (tr: Transaction, action: CustomAutoformatAction) => Transaction;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { CustomAutoformatState } from './types';
|
|
3
|
-
import type { InputRuleHander } from './input-rules';
|
|
4
|
-
import type { AutoformatHandler } from '@atlaskit/editor-common/provider-factory';
|
|
5
|
-
export declare const buildHandler: (_regex: string, handler: AutoformatHandler) => InputRuleHander;
|
|
6
|
-
export declare const completeReplacements: (view: EditorView, state: CustomAutoformatState) => void;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type { NextEditorPlugin, PMPluginFactoryParams } from '../../types';
|
|
3
|
-
import type { CustomAutoformatState } from './types';
|
|
4
|
-
export declare const createPMPlugin: ({ providerFactory }: PMPluginFactoryParams) => SafePlugin<CustomAutoformatState>;
|
|
5
|
-
declare const customAutoformatPlugin: NextEditorPlugin<'customAutoformat'>;
|
|
6
|
-
export default customAutoformatPlugin;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { AutoformatReplacement } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
export type InputRuleHander = (view: EditorView, match: string[], start: number, end: number) => Promise<AutoformatReplacement>;
|
|
4
|
-
export type InputRule = {
|
|
5
|
-
matchTyping: RegExp;
|
|
6
|
-
matchEnter: RegExp;
|
|
7
|
-
handler: InputRuleHander;
|
|
8
|
-
};
|
|
9
|
-
export declare const triggerInputRule: (view: EditorView, rules: Array<InputRule>, from: number, to: number, text: string) => boolean;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Node as ProsemirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export type { AutoformatHandler, AutoformatReplacement, AutoformattingProvider, AutoformatRuleset as Ruleset, } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
export type AutoformatCandidate = {
|
|
4
|
-
start: number;
|
|
5
|
-
end: number;
|
|
6
|
-
match: string[];
|
|
7
|
-
};
|
|
8
|
-
export type AutoformatMatch = {
|
|
9
|
-
matchString: string;
|
|
10
|
-
replacement?: ProsemirrorNode;
|
|
11
|
-
};
|
|
12
|
-
export type CustomAutoformatState = {
|
|
13
|
-
resolving: Array<AutoformatCandidate>;
|
|
14
|
-
matches: Array<AutoformatMatch>;
|
|
15
|
-
};
|
|
16
|
-
export type CustomAutoformatMatched = {
|
|
17
|
-
action: 'matched';
|
|
18
|
-
start: number;
|
|
19
|
-
end: number;
|
|
20
|
-
match: string[];
|
|
21
|
-
};
|
|
22
|
-
export type CustomAutoformatResolved = {
|
|
23
|
-
action: 'resolved';
|
|
24
|
-
matchString: string;
|
|
25
|
-
replacement?: ProsemirrorNode;
|
|
26
|
-
};
|
|
27
|
-
export type CustomAutoformatFinish = {
|
|
28
|
-
action: 'finish';
|
|
29
|
-
matchString: string;
|
|
30
|
-
};
|
|
31
|
-
export type CustomAutoformatAction = CustomAutoformatMatched | CustomAutoformatResolved | CustomAutoformatFinish;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import type { CustomAutoformatState, CustomAutoformatAction } from './types';
|
|
4
|
-
export declare const pluginKey: PluginKey<any>;
|
|
5
|
-
export declare const getPluginState: (editorState: EditorState) => CustomAutoformatState | undefined;
|
|
6
|
-
export declare const autoformatAction: (tr: Transaction, action: CustomAutoformatAction) => Transaction;
|