@atlaskit/editor-plugin-text-formatting 1.16.8 → 1.16.10

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/editor-commands/utils/marks.js +120 -0
  3. package/dist/cjs/pm-plugins/commands.js +18 -12
  4. package/dist/cjs/pm-plugins/input-rule.js +15 -7
  5. package/dist/cjs/textFormattingPlugin.js +1 -1
  6. package/dist/cjs/ui/Toolbar/index.js +9 -1
  7. package/dist/cjs/ui/Toolbar/more-button.js +1 -1
  8. package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +8 -1
  9. package/dist/es2019/editor-commands/utils/marks.js +117 -0
  10. package/dist/es2019/pm-plugins/commands.js +7 -2
  11. package/dist/es2019/pm-plugins/input-rule.js +15 -7
  12. package/dist/es2019/textFormattingPlugin.js +1 -1
  13. package/dist/es2019/ui/Toolbar/index.js +10 -2
  14. package/dist/es2019/ui/Toolbar/more-button.js +1 -1
  15. package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +9 -2
  16. package/dist/esm/editor-commands/utils/marks.js +114 -0
  17. package/dist/esm/pm-plugins/commands.js +18 -12
  18. package/dist/esm/pm-plugins/input-rule.js +15 -7
  19. package/dist/esm/textFormattingPlugin.js +1 -1
  20. package/dist/esm/ui/Toolbar/index.js +10 -2
  21. package/dist/esm/ui/Toolbar/more-button.js +1 -1
  22. package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +9 -2
  23. package/dist/types/editor-commands/utils/marks.d.ts +14 -0
  24. package/dist/types/pm-plugins/commands.d.ts +6 -3
  25. package/dist/types/pm-plugins/input-rule.d.ts +3 -1
  26. package/dist/types/textFormattingPluginType.d.ts +6 -1
  27. package/dist/types-ts4.5/editor-commands/utils/marks.d.ts +14 -0
  28. package/dist/types-ts4.5/pm-plugins/commands.d.ts +6 -3
  29. package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +3 -1
  30. package/dist/types-ts4.5/textFormattingPluginType.d.ts +3 -1
  31. package/package.json +12 -5
  32. package/dist/cjs/editor-commands/transform-to-code.js +0 -79
  33. package/dist/es2019/editor-commands/transform-to-code.js +0 -83
  34. package/dist/esm/editor-commands/transform-to-code.js +0 -73
  35. package/dist/types/editor-commands/transform-to-code.d.ts +0 -2
  36. package/dist/types-ts4.5/editor-commands/transform-to-code.d.ts +0 -2
@@ -1,83 +0,0 @@
1
- import { filterChildrenBetween } from '@atlaskit/editor-common/mark';
2
- const SMART_TO_ASCII = {
3
- '…': '...',
4
- '→': '->',
5
- '←': '<-',
6
- '–': '--',
7
- '“': '"',
8
- '”': '"',
9
- '‘': "'",
10
- '’': "'"
11
- };
12
-
13
- // Ignored via go/ees005
14
- // eslint-disable-next-line require-unicode-regexp
15
- const FIND_SMART_CHAR = new RegExp(`[${Object.keys(SMART_TO_ASCII).join('')}]`, 'g');
16
- const replaceMentionOrEmojiForTextContent = (position, nodeSize, textContent, tr
17
- // Ignored via go/ees005
18
- // eslint-disable-next-line @typescript-eslint/max-params
19
- ) => {
20
- const currentPos = tr.mapping.map(position);
21
- const {
22
- schema
23
- } = tr.doc.type;
24
- tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
25
- };
26
- const replaceSmartCharsToAscii = (position, textContent, tr) => {
27
- const {
28
- schema
29
- } = tr.doc.type;
30
- let match;
31
-
32
- // Ignored via go/ees005
33
- // eslint-disable-next-line no-cond-assign
34
- while (match = FIND_SMART_CHAR.exec(textContent)) {
35
- const {
36
- 0: smartChar,
37
- index: offset
38
- } = match;
39
- const replacePos = tr.mapping.map(position + offset);
40
- const replacementText = schema.text(SMART_TO_ASCII[smartChar]);
41
- tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
42
- }
43
- };
44
- const isNodeTextBlock = schema => {
45
- const {
46
- mention,
47
- text,
48
- emoji
49
- } = schema.nodes;
50
-
51
- // Ignored via go/ees005
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- return (node, _, parent) => {
54
- if (node.type === mention || node.type === emoji || node.type === text) {
55
- return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
56
- }
57
- return;
58
- };
59
- };
60
- export const transformSmartCharsMentionsAndEmojis = (from, to, tr) => {
61
- const {
62
- schema
63
- } = tr.doc.type;
64
- const {
65
- mention,
66
- text,
67
- emoji
68
- } = schema.nodes;
69
- // Traverse through all the nodes within the range and replace them with their plaintext counterpart
70
- const children = filterChildrenBetween(tr.doc, from, to, isNodeTextBlock(schema));
71
- children.forEach(({
72
- node,
73
- pos
74
- }) => {
75
- if (node.type === mention || node.type === emoji) {
76
- replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
77
- } else if (node.type === text && node.text) {
78
- const replacePosition = pos > from ? pos : from;
79
- const textToReplace = pos > from ? node.text : node.text.substr(from - pos);
80
- replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
81
- }
82
- });
83
- };
@@ -1,73 +0,0 @@
1
- import { filterChildrenBetween } from '@atlaskit/editor-common/mark';
2
- var SMART_TO_ASCII = {
3
- '…': '...',
4
- '→': '->',
5
- '←': '<-',
6
- '–': '--',
7
- '“': '"',
8
- '”': '"',
9
- '‘': "'",
10
- '’': "'"
11
- };
12
-
13
- // Ignored via go/ees005
14
- // eslint-disable-next-line require-unicode-regexp
15
- var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
16
- var replaceMentionOrEmojiForTextContent = function replaceMentionOrEmojiForTextContent(position, nodeSize, textContent, tr
17
- // Ignored via go/ees005
18
- // eslint-disable-next-line @typescript-eslint/max-params
19
- ) {
20
- var currentPos = tr.mapping.map(position);
21
- var schema = tr.doc.type.schema;
22
- tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
23
- };
24
- var replaceSmartCharsToAscii = function replaceSmartCharsToAscii(position, textContent, tr) {
25
- var schema = tr.doc.type.schema;
26
- var match;
27
-
28
- // Ignored via go/ees005
29
- // eslint-disable-next-line no-cond-assign
30
- while (match = FIND_SMART_CHAR.exec(textContent)) {
31
- var _match = match,
32
- smartChar = _match[0],
33
- offset = _match.index;
34
- var replacePos = tr.mapping.map(position + offset);
35
- var replacementText = schema.text(SMART_TO_ASCII[smartChar]);
36
- tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
37
- }
38
- };
39
- var isNodeTextBlock = function isNodeTextBlock(schema) {
40
- var _schema$nodes = schema.nodes,
41
- mention = _schema$nodes.mention,
42
- text = _schema$nodes.text,
43
- emoji = _schema$nodes.emoji;
44
-
45
- // Ignored via go/ees005
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- return function (node, _, parent) {
48
- if (node.type === mention || node.type === emoji || node.type === text) {
49
- return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
50
- }
51
- return;
52
- };
53
- };
54
- export var transformSmartCharsMentionsAndEmojis = function transformSmartCharsMentionsAndEmojis(from, to, tr) {
55
- var schema = tr.doc.type.schema;
56
- var _schema$nodes2 = schema.nodes,
57
- mention = _schema$nodes2.mention,
58
- text = _schema$nodes2.text,
59
- emoji = _schema$nodes2.emoji;
60
- // Traverse through all the nodes within the range and replace them with their plaintext counterpart
61
- var children = filterChildrenBetween(tr.doc, from, to, isNodeTextBlock(schema));
62
- children.forEach(function (_ref) {
63
- var node = _ref.node,
64
- pos = _ref.pos;
65
- if (node.type === mention || node.type === emoji) {
66
- replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
67
- } else if (node.type === text && node.text) {
68
- var replacePosition = pos > from ? pos : from;
69
- var textToReplace = pos > from ? node.text : node.text.substr(from - pos);
70
- replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
71
- }
72
- });
73
- };
@@ -1,2 +0,0 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const transformSmartCharsMentionsAndEmojis: (from: number, to: number, tr: Transaction) => void;
@@ -1,2 +0,0 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const transformSmartCharsMentionsAndEmojis: (from: number, to: number, tr: Transaction) => void;