@atlaskit/editor-plugin-list 0.2.0 → 1.0.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/.eslintrc.js +14 -0
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/cjs/actions/conversions.js +153 -0
- package/dist/cjs/actions/indent-list-items-selected.js +125 -0
- package/dist/cjs/actions/indent-list.js +49 -0
- package/dist/cjs/actions/join-list-items-forward.js +59 -0
- package/dist/cjs/actions/join-list-items-scenarios/index.js +40 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +88 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +85 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +79 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-paragraph-with-list.js +45 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-sibling-list-items.js +56 -0
- package/dist/cjs/actions/merge-lists.js +27 -0
- package/dist/cjs/actions/outdent-list-items-selected.js +291 -0
- package/dist/cjs/actions/wrap-and-join-lists.js +100 -0
- package/dist/cjs/commands/indent-list.js +71 -0
- package/dist/cjs/commands/index.js +350 -0
- package/dist/cjs/commands/isFirstChildOfParent.js +12 -0
- package/dist/cjs/commands/join-list-item-forward.js +61 -0
- package/dist/cjs/commands/listBackspace.js +284 -0
- package/dist/cjs/commands/outdent-list.js +70 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/messages.js +37 -0
- package/dist/cjs/plugin.js +133 -0
- package/dist/cjs/pm-plugins/input-rules/create-list-input-rule.js +63 -0
- package/dist/cjs/pm-plugins/input-rules/index.js +38 -0
- package/dist/cjs/pm-plugins/input-rules/wrapping-join-rule.js +60 -0
- package/dist/cjs/pm-plugins/keymap.js +27 -0
- package/dist/cjs/pm-plugins/main.js +166 -0
- package/dist/cjs/transforms.js +99 -0
- package/dist/cjs/types.js +4 -1
- package/dist/cjs/utils/analytics.js +22 -0
- package/dist/cjs/utils/find.js +68 -0
- package/dist/cjs/utils/indentation.js +22 -0
- package/dist/cjs/utils/mark.js +40 -0
- package/dist/cjs/utils/node.js +16 -0
- package/dist/cjs/utils/selection.js +95 -0
- package/dist/es2019/actions/conversions.js +160 -0
- package/dist/es2019/actions/indent-list-items-selected.js +124 -0
- package/dist/es2019/actions/indent-list.js +44 -0
- package/dist/es2019/actions/join-list-items-forward.js +54 -0
- package/dist/es2019/actions/join-list-items-scenarios/index.js +5 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +74 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +77 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +71 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-paragraph-with-list.js +37 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-sibling-list-items.js +48 -0
- package/dist/es2019/actions/merge-lists.js +24 -0
- package/dist/es2019/actions/outdent-list-items-selected.js +295 -0
- package/dist/es2019/actions/wrap-and-join-lists.js +93 -0
- package/dist/es2019/commands/indent-list.js +62 -0
- package/dist/es2019/commands/index.js +326 -0
- package/dist/es2019/commands/isFirstChildOfParent.js +7 -0
- package/dist/es2019/commands/join-list-item-forward.js +53 -0
- package/dist/es2019/commands/listBackspace.js +276 -0
- package/dist/es2019/commands/outdent-list.js +60 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/messages.js +29 -0
- package/dist/es2019/plugin.js +121 -0
- package/dist/es2019/pm-plugins/input-rules/create-list-input-rule.js +56 -0
- package/dist/es2019/pm-plugins/input-rules/index.js +35 -0
- package/dist/es2019/pm-plugins/input-rules/wrapping-join-rule.js +55 -0
- package/dist/es2019/pm-plugins/keymap.js +19 -0
- package/dist/es2019/pm-plugins/main.js +156 -0
- package/dist/es2019/transforms.js +101 -0
- package/dist/es2019/types.js +1 -1
- package/dist/es2019/utils/analytics.js +12 -0
- package/dist/es2019/utils/find.js +61 -0
- package/dist/es2019/utils/indentation.js +15 -0
- package/dist/es2019/utils/mark.js +30 -0
- package/dist/es2019/utils/node.js +12 -0
- package/dist/es2019/utils/selection.js +96 -0
- package/dist/esm/actions/conversions.js +147 -0
- package/dist/esm/actions/indent-list-items-selected.js +117 -0
- package/dist/esm/actions/indent-list.js +43 -0
- package/dist/esm/actions/join-list-items-forward.js +52 -0
- package/dist/esm/actions/join-list-items-scenarios/index.js +5 -0
- package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +81 -0
- package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +78 -0
- package/dist/esm/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +72 -0
- package/dist/esm/actions/join-list-items-scenarios/join-paragraph-with-list.js +38 -0
- package/dist/esm/actions/join-list-items-scenarios/join-sibling-list-items.js +49 -0
- package/dist/esm/actions/merge-lists.js +21 -0
- package/dist/esm/actions/outdent-list-items-selected.js +283 -0
- package/dist/esm/actions/wrap-and-join-lists.js +94 -0
- package/dist/esm/commands/indent-list.js +63 -0
- package/dist/esm/commands/index.js +324 -0
- package/dist/esm/commands/isFirstChildOfParent.js +5 -0
- package/dist/esm/commands/join-list-item-forward.js +53 -0
- package/dist/esm/commands/listBackspace.js +275 -0
- package/dist/esm/commands/outdent-list.js +62 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/messages.js +29 -0
- package/dist/esm/plugin.js +126 -0
- package/dist/esm/pm-plugins/input-rules/create-list-input-rule.js +57 -0
- package/dist/esm/pm-plugins/input-rules/index.js +32 -0
- package/dist/esm/pm-plugins/input-rules/wrapping-join-rule.js +54 -0
- package/dist/esm/pm-plugins/keymap.js +19 -0
- package/dist/esm/pm-plugins/main.js +156 -0
- package/dist/esm/transforms.js +91 -0
- package/dist/esm/types.js +1 -1
- package/dist/esm/utils/analytics.js +12 -0
- package/dist/esm/utils/find.js +59 -0
- package/dist/esm/utils/indentation.js +15 -0
- package/dist/esm/utils/mark.js +33 -0
- package/dist/esm/utils/node.js +10 -0
- package/dist/esm/utils/selection.js +81 -0
- package/dist/types/actions/conversions.d.ts +6 -0
- package/dist/types/actions/indent-list-items-selected.d.ts +2 -0
- package/dist/types/actions/indent-list.d.ts +2 -0
- package/dist/types/actions/join-list-items-forward.d.ts +13 -0
- package/dist/types/actions/join-list-items-scenarios/index.d.ts +5 -0
- package/dist/types/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
- package/dist/types/actions/merge-lists.d.ts +7 -0
- package/dist/types/actions/outdent-list-items-selected.d.ts +3 -0
- package/dist/types/actions/wrap-and-join-lists.d.ts +17 -0
- package/dist/types/commands/indent-list.d.ts +6 -0
- package/dist/types/commands/index.d.ts +16 -0
- package/dist/types/commands/isFirstChildOfParent.d.ts +2 -0
- package/dist/types/commands/join-list-item-forward.d.ts +3 -0
- package/dist/types/commands/listBackspace.d.ts +10 -0
- package/dist/types/commands/outdent-list.d.ts +6 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/messages.d.ts +27 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
- package/dist/types/pm-plugins/input-rules/index.d.ts +5 -0
- package/dist/types/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
- package/dist/types/pm-plugins/keymap.d.ts +5 -0
- package/dist/types/pm-plugins/main.d.ts +11 -0
- package/dist/types/transforms.d.ts +4 -0
- package/dist/types/types.d.ts +4 -6
- package/dist/types/utils/analytics.d.ts +5 -0
- package/dist/types/utils/find.d.ts +10 -0
- package/dist/types/utils/indentation.d.ts +2 -0
- package/dist/types/utils/mark.d.ts +8 -0
- package/dist/types/utils/node.d.ts +2 -0
- package/dist/types/utils/selection.d.ts +14 -0
- package/dist/types-ts4.5/actions/conversions.d.ts +6 -0
- package/dist/types-ts4.5/actions/indent-list-items-selected.d.ts +2 -0
- package/dist/types-ts4.5/actions/indent-list.d.ts +2 -0
- package/dist/types-ts4.5/actions/join-list-items-forward.d.ts +16 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/index.d.ts +5 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
- package/dist/types-ts4.5/actions/merge-lists.d.ts +7 -0
- package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +3 -0
- package/dist/types-ts4.5/actions/wrap-and-join-lists.d.ts +17 -0
- package/dist/types-ts4.5/commands/indent-list.d.ts +6 -0
- package/dist/types-ts4.5/commands/index.d.ts +16 -0
- package/dist/types-ts4.5/commands/isFirstChildOfParent.d.ts +2 -0
- package/dist/types-ts4.5/commands/join-list-item-forward.d.ts +3 -0
- package/dist/types-ts4.5/commands/listBackspace.d.ts +13 -0
- package/dist/types-ts4.5/commands/outdent-list.d.ts +6 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/messages.d.ts +27 -0
- package/dist/types-ts4.5/plugin.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/index.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +11 -0
- package/dist/types-ts4.5/transforms.d.ts +4 -0
- package/dist/types-ts4.5/types.d.ts +4 -6
- package/dist/types-ts4.5/utils/analytics.d.ts +5 -0
- package/dist/types-ts4.5/utils/find.d.ts +10 -0
- package/dist/types-ts4.5/utils/indentation.d.ts +2 -0
- package/dist/types-ts4.5/utils/mark.d.ts +8 -0
- package/dist/types-ts4.5/utils/node.d.ts +2 -0
- package/dist/types-ts4.5/utils/selection.d.ts +14 -0
- package/package.json +8 -5
- package/report.api.md +6 -2
- package/tmp/api-report-tmp.d.ts +4 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.listBackspace = exports.calcJoinListScenario = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
+
var _selection = require("../utils/selection");
|
|
13
|
+
var _BACKSPACE_COMMANDS;
|
|
14
|
+
//Cases below refer to the cases found in this document: https://product-fabric.atlassian.net/wiki/spaces/E/pages/1146954996/List+Backspace+and+Delete+Behaviour
|
|
15
|
+
//Case for two adjacent list items of the same indentation
|
|
16
|
+
var listBackspaceCase2 = function listBackspaceCase2(tr, dispatch, $prev, $head) {
|
|
17
|
+
/* CASE 2
|
|
18
|
+
* Initial Structure:
|
|
19
|
+
*
|
|
20
|
+
* List A {
|
|
21
|
+
* ListItem B {
|
|
22
|
+
* ...Children C
|
|
23
|
+
* Paragraph D { text1 |textInsertPos| } //Cant have children since that would be Case 4
|
|
24
|
+
* |$prev||childrenGInsertPos| }
|
|
25
|
+
* ListItem E {
|
|
26
|
+
* Paragraph F { |$head| text2 }
|
|
27
|
+
* ...Children G
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* Converts to:
|
|
32
|
+
*
|
|
33
|
+
* List A {
|
|
34
|
+
* ListItem B {
|
|
35
|
+
* ...Children C
|
|
36
|
+
* Paragraph C { text1text2 }
|
|
37
|
+
* ...Children G
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
var listItemE = $head.node(-1); //Head is inside listItem E so it must have a first and last child
|
|
44
|
+
if (!listItemE.firstChild) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var beforeListItemE = $head.before(-1);
|
|
48
|
+
var afterListItemE = $head.after(-1);
|
|
49
|
+
var textInsertPos = $prev.pos - 1; //Paragraph D must be directly behind $prev otherwise it would be case 4
|
|
50
|
+
var childrenGInsertPos = $prev.pos;
|
|
51
|
+
var textContent = $head.parent.content;
|
|
52
|
+
var childrenGContent = listItemE.content.cut(listItemE.firstChild.nodeSize);
|
|
53
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
54
|
+
return tr.doc.resolve(textInsertPos);
|
|
55
|
+
}, [[textContent, textInsertPos], [childrenGContent, childrenGInsertPos]], [[beforeListItemE, afterListItemE]]);
|
|
56
|
+
if (dispatch) {
|
|
57
|
+
dispatch(tr);
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//Case for two adjacent list items with the first being of lower indentation
|
|
63
|
+
var listBackspaceCase3 = function listBackspaceCase3(tr, dispatch, $prev, $head) {
|
|
64
|
+
/* CASE 3
|
|
65
|
+
* Initial Structure:
|
|
66
|
+
*
|
|
67
|
+
* List A {
|
|
68
|
+
* ListItem B {
|
|
69
|
+
* ...Children C
|
|
70
|
+
* Paragraph D { text1 |$prev||textInsertPos| } |childrenHInsertPos|
|
|
71
|
+
* List E { |childrenJInsertPos|
|
|
72
|
+
* ListItem F {
|
|
73
|
+
* Paragraph G { |$head| text2 }
|
|
74
|
+
* ...Children H
|
|
75
|
+
* List? I {
|
|
76
|
+
* ...Children J
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ...Children K
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* Converts to:
|
|
85
|
+
*
|
|
86
|
+
* List A {
|
|
87
|
+
* ListItem B {
|
|
88
|
+
* ...Children C
|
|
89
|
+
* Paragraph D { text1text2 }
|
|
90
|
+
* ...Children H
|
|
91
|
+
* List E {
|
|
92
|
+
* ...Children J
|
|
93
|
+
* ...Children K
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
var listE = $head.node(-2);
|
|
101
|
+
var listItemF = $head.node(-1); //Head is inside listItem F so it must have a first and last child
|
|
102
|
+
if (!listItemF.firstChild || !listItemF.lastChild) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
var beforeListE = $head.before(-2);
|
|
106
|
+
var beforeListItemF = $head.before(-1);
|
|
107
|
+
var afterParagraphD = $prev.after();
|
|
108
|
+
var afterListE = $head.after(-2);
|
|
109
|
+
var afterListItemF = $head.after(-1);
|
|
110
|
+
var startListE = $head.start(-2);
|
|
111
|
+
var containsChildrenJ = (0, _utils.isListNode)(listItemF.lastChild);
|
|
112
|
+
var shouldRemoveListE = listE.childCount === 1 && !containsChildrenJ; //Assures no Children J and K
|
|
113
|
+
var textInsertPos = $prev.pos;
|
|
114
|
+
var childrenHInsertPos = afterParagraphD;
|
|
115
|
+
var childrenJInsertPos = startListE;
|
|
116
|
+
var textContent = $head.parent.content;
|
|
117
|
+
var childrenHContent = containsChildrenJ ? listItemF.content.cut(listItemF.firstChild.nodeSize, listItemF.nodeSize - listItemF.lastChild.nodeSize - 2) : listItemF.content.cut(listItemF.firstChild.nodeSize); //If Children J doesn't exist then Children H will include the last node
|
|
118
|
+
var childrenJContent = listItemF.lastChild.content; //Will be invalid if there are no Children J but it will be unused
|
|
119
|
+
|
|
120
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
121
|
+
return tr.doc.resolve(textInsertPos);
|
|
122
|
+
}, containsChildrenJ ? [[textContent, textInsertPos], [childrenHContent, childrenHInsertPos], [childrenJContent, childrenJInsertPos]] : [[textContent, textInsertPos], [childrenHContent, childrenHInsertPos]], [shouldRemoveListE ? [beforeListE, afterListE] : [beforeListItemF, afterListItemF]]);
|
|
123
|
+
if (dispatch) {
|
|
124
|
+
dispatch(tr);
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
//Case for two adjacent list items with the first being of greater indentation
|
|
130
|
+
var listBackspaceCase4 = function listBackspaceCase4(tr, dispatch, $prev, $head, $last) {
|
|
131
|
+
/* CASE 4
|
|
132
|
+
* Initial Structure:
|
|
133
|
+
*
|
|
134
|
+
* List A {
|
|
135
|
+
* ListItem B {
|
|
136
|
+
* Paragraph C { text1 }
|
|
137
|
+
* ...Children D
|
|
138
|
+
* List E {
|
|
139
|
+
* ...
|
|
140
|
+
* List F { //May be multiple levels of lists
|
|
141
|
+
* ...Children G
|
|
142
|
+
* ListItem H { //Last node of the block
|
|
143
|
+
* ...Children I
|
|
144
|
+
* Paragraph J { text2 |$last||textInsertPos| } |childrenMInsertPos| //Cant have children since this ListItem is the last of the block
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ...
|
|
148
|
+
* |childrenOInsertPosition| }
|
|
149
|
+
* |$prev| }
|
|
150
|
+
* ListItem K {
|
|
151
|
+
* Paragraph L { |$head| text3 }
|
|
152
|
+
* ...Children M
|
|
153
|
+
* List? N {
|
|
154
|
+
* ...Children O
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
*
|
|
159
|
+
* Converts to:
|
|
160
|
+
*
|
|
161
|
+
* List A {
|
|
162
|
+
* ListItem B {
|
|
163
|
+
* Paragraph C { text1 }
|
|
164
|
+
* ...Children D
|
|
165
|
+
* List E {
|
|
166
|
+
* ...
|
|
167
|
+
* List F {
|
|
168
|
+
* ...Children G
|
|
169
|
+
* ListItem H {
|
|
170
|
+
* ...Children I
|
|
171
|
+
* Paragraph J { text2text3 }
|
|
172
|
+
* ...Children M
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* ...
|
|
176
|
+
* ...Children O
|
|
177
|
+
* }
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
if (!$last) {
|
|
184
|
+
//Exit if an invalid last was given as a parameter
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
var listItemK = $head.node(-1); //Head is inside listItem K so it must have a first and last child
|
|
188
|
+
if (!listItemK.firstChild || !listItemK.lastChild) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
var paragraphL = $head.parent;
|
|
192
|
+
var beforeListItemK = $head.before(-1);
|
|
193
|
+
var afterParagraphJ = $last.after();
|
|
194
|
+
var afterListItemK = $head.after(-1);
|
|
195
|
+
var containsChildrenO = (0, _utils.isListNode)(listItemK.lastChild);
|
|
196
|
+
var textInsertPos = $last.pos;
|
|
197
|
+
var childrenMInsertPos = afterParagraphJ;
|
|
198
|
+
var childrenOInsertPos = $prev.pos - 1; //Last item of listItem B must be a list therefore we can simply decrement $prev to get there
|
|
199
|
+
|
|
200
|
+
var textContent = paragraphL.content;
|
|
201
|
+
var childrenMContent = containsChildrenO ? listItemK.content.cut(listItemK.firstChild.nodeSize, listItemK.nodeSize - listItemK.lastChild.nodeSize - 2) : listItemK.content.cut(listItemK.firstChild.nodeSize);
|
|
202
|
+
var childrenOContent = listItemK.lastChild.content;
|
|
203
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
204
|
+
return tr.doc.resolve(textInsertPos);
|
|
205
|
+
}, containsChildrenO ? [[textContent, textInsertPos], [childrenMContent, childrenMInsertPos], [childrenOContent, childrenOInsertPos]] : [[textContent, textInsertPos], [childrenMContent, childrenMInsertPos]], [[beforeListItemK, afterListItemK]]);
|
|
206
|
+
if (dispatch) {
|
|
207
|
+
dispatch(tr);
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
};
|
|
211
|
+
var BACKSPACE_COMMANDS = (_BACKSPACE_COMMANDS = {}, (0, _defineProperty2.default)(_BACKSPACE_COMMANDS, _analytics.LIST_TEXT_SCENARIOS.JOIN_SIBLINGS, listBackspaceCase2), (0, _defineProperty2.default)(_BACKSPACE_COMMANDS, _analytics.LIST_TEXT_SCENARIOS.JOIN_DESCENDANT_TO_PARENT, listBackspaceCase3), (0, _defineProperty2.default)(_BACKSPACE_COMMANDS, _analytics.LIST_TEXT_SCENARIOS.JOIN_TO_SIBLING_DESCENDANT, listBackspaceCase4), _BACKSPACE_COMMANDS);
|
|
212
|
+
var calcJoinListScenario = function calcJoinListScenario(walkNode, $head, tr) {
|
|
213
|
+
var $prev = walkNode.$pos,
|
|
214
|
+
prevFoundNode = walkNode.foundNode;
|
|
215
|
+
var prevInList = (0, _selection.isPosInsideList)($prev);
|
|
216
|
+
var headInParagraph = (0, _selection.isPosInsideParagraph)($head);
|
|
217
|
+
var headInFirstChild = $head.index(-1) === 0;
|
|
218
|
+
var headInList = (0, _selection.isPosInsideList)($head);
|
|
219
|
+
|
|
220
|
+
//Must be at the start of the selection of the first child in the listItem
|
|
221
|
+
|
|
222
|
+
if (!prevFoundNode || !prevInList || !headInParagraph || !headInFirstChild || !headInList) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
var prevInParagraph = (0, _selection.isPosInsideParagraph)($prev);
|
|
226
|
+
if (prevInParagraph) {
|
|
227
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_DESCENDANT_TO_PARENT, null];
|
|
228
|
+
}
|
|
229
|
+
var prevParentLastChildIsList = $prev.parent.lastChild && (0, _utils.isListNode)($prev.parent.lastChild);
|
|
230
|
+
var prevParentLastChildIsParagraph = (0, _utils.isParagraphNode)($prev.parent.lastChild);
|
|
231
|
+
|
|
232
|
+
// Will search for the possible last node for case 4 (where the list could be indented multiple times)
|
|
233
|
+
// $last is required to determine whether we are in case 2 or 4
|
|
234
|
+
var $last = tr.doc.resolve($prev.pos);
|
|
235
|
+
var lastFoundNode;
|
|
236
|
+
do {
|
|
237
|
+
var _walkNode = (0, _utils.walkPrevNode)($last);
|
|
238
|
+
$last = _walkNode.$pos;
|
|
239
|
+
lastFoundNode = _walkNode.foundNode;
|
|
240
|
+
} while (lastFoundNode && !$last.parent.isTextblock);
|
|
241
|
+
var lastInParagraph = (0, _selection.isPosInsideParagraph)($last);
|
|
242
|
+
if (lastFoundNode && prevParentLastChildIsList && lastInParagraph) {
|
|
243
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_TO_SIBLING_DESCENDANT, $last];
|
|
244
|
+
} else if (prevParentLastChildIsParagraph) {
|
|
245
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_SIBLINGS, null];
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
};
|
|
249
|
+
exports.calcJoinListScenario = calcJoinListScenario;
|
|
250
|
+
var listBackspace = function listBackspace(editorAnalyticsAPI) {
|
|
251
|
+
return function (state, dispatch) {
|
|
252
|
+
var tr = state.tr,
|
|
253
|
+
$head = state.selection.$head;
|
|
254
|
+
var walkNode = (0, _utils.walkPrevNode)($head);
|
|
255
|
+
if (!(0, _utils.isEmptySelectionAtStart)(state)) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
var scenario = calcJoinListScenario(walkNode, $head, tr);
|
|
259
|
+
if (!scenario) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
263
|
+
bulletList = _state$schema$nodes.bulletList,
|
|
264
|
+
orderedList = _state$schema$nodes.orderedList;
|
|
265
|
+
var listParent = (0, _utils2.findParentNodeOfType)([bulletList, orderedList])(tr.selection);
|
|
266
|
+
var actionSubjectId = _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET;
|
|
267
|
+
if (listParent && listParent.node.type === orderedList) {
|
|
268
|
+
actionSubjectId = _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
269
|
+
}
|
|
270
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
271
|
+
action: _analytics.ACTION.LIST_ITEM_JOINED,
|
|
272
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
273
|
+
actionSubjectId: actionSubjectId,
|
|
274
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
275
|
+
attributes: {
|
|
276
|
+
inputMethod: _analytics.INPUT_METHOD.KEYBOARD,
|
|
277
|
+
direction: _analytics.DELETE_DIRECTION.BACKWARD,
|
|
278
|
+
scenario: scenario[0]
|
|
279
|
+
}
|
|
280
|
+
})(tr);
|
|
281
|
+
return BACKSPACE_COMMANDS[scenario[0]](tr, dispatch, walkNode.$pos, $head, scenario[1]);
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
exports.listBackspace = listBackspace;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.outdentList = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _lists = require("@atlaskit/editor-common/lists");
|
|
11
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
|
+
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
13
|
+
var _outdentListItemsSelected = require("../actions/outdent-list-items-selected");
|
|
14
|
+
var _analytics2 = require("../utils/analytics");
|
|
15
|
+
var _find = require("../utils/find");
|
|
16
|
+
var _selection = require("../utils/selection");
|
|
17
|
+
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; }
|
|
18
|
+
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
|
+
var outdentList = function outdentList(editorAnalyticsAPI) {
|
|
20
|
+
return function () {
|
|
21
|
+
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.KEYBOARD;
|
|
22
|
+
var featureFlags = arguments.length > 1 ? arguments[1] : undefined;
|
|
23
|
+
return function (state, dispatch) {
|
|
24
|
+
if (!(0, _selection.isInsideListItem)(state)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
var $from = state.selection.$from;
|
|
28
|
+
var parentListNode = (0, _find.findFirstParentListNode)($from);
|
|
29
|
+
if (!parentListNode) {
|
|
30
|
+
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Save the history, so it could undo/revert to the same state before the outdent, see https://product-fabric.atlassian.net/browse/ED-14753
|
|
35
|
+
(0, _history.closeHistory)(state.tr);
|
|
36
|
+
var actionSubjectId = (0, _utils.isBulletList)(parentListNode.node) ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
37
|
+
var customTr = state.tr;
|
|
38
|
+
(0, _outdentListItemsSelected.outdentListItemsSelected)(customTr, state, featureFlags);
|
|
39
|
+
if (!customTr || !customTr.docChanged) {
|
|
40
|
+
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
41
|
+
// If inside table cell and can't outdent list, then let it handle by table keymap
|
|
42
|
+
return !(0, _selection.isInsideTableCell)(state);
|
|
43
|
+
}
|
|
44
|
+
var restartListsAttributes = {};
|
|
45
|
+
if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
|
|
46
|
+
var _getRestartListsAttri = (0, _analytics2.getRestartListsAttributes)(customTr),
|
|
47
|
+
outdentScenario = _getRestartListsAttri.outdentScenario,
|
|
48
|
+
splitListStartNumber = _getRestartListsAttri.splitListStartNumber;
|
|
49
|
+
if (outdentScenario === _analytics.OUTDENT_SCENARIOS.SPLIT_LIST) {
|
|
50
|
+
restartListsAttributes.outdentScenario = outdentScenario;
|
|
51
|
+
restartListsAttributes.splitListStartNumber = splitListStartNumber;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
55
|
+
action: _analytics.ACTION.OUTDENTED,
|
|
56
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
57
|
+
actionSubjectId: actionSubjectId,
|
|
58
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
59
|
+
attributes: _objectSpread(_objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(state)), restartListsAttributes), {}, {
|
|
60
|
+
inputMethod: inputMethod
|
|
61
|
+
})
|
|
62
|
+
})(customTr);
|
|
63
|
+
if (dispatch) {
|
|
64
|
+
dispatch(customTr);
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.outdentList = outdentList;
|
package/dist/cjs/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
var _reactIntlNext = require("react-intl-next");
|
|
8
|
+
// Common Translations will live here
|
|
9
|
+
|
|
10
|
+
var messages = (0, _reactIntlNext.defineMessages)({
|
|
11
|
+
unorderedList: {
|
|
12
|
+
id: 'fabric.editor.unorderedList',
|
|
13
|
+
defaultMessage: 'Bullet list',
|
|
14
|
+
description: 'A list with bullets. Also known as an “unordered” list'
|
|
15
|
+
},
|
|
16
|
+
unorderedListDescription: {
|
|
17
|
+
id: 'fabric.editor.unorderedList.description',
|
|
18
|
+
defaultMessage: 'Create an unordered list',
|
|
19
|
+
description: ''
|
|
20
|
+
},
|
|
21
|
+
orderedList: {
|
|
22
|
+
id: 'fabric.editor.orderedList',
|
|
23
|
+
defaultMessage: 'Numbered list',
|
|
24
|
+
description: 'A list with ordered items 1… 2… 3…'
|
|
25
|
+
},
|
|
26
|
+
orderedListDescription: {
|
|
27
|
+
id: 'fabric.editor.orderedList.description',
|
|
28
|
+
defaultMessage: 'Create an ordered list',
|
|
29
|
+
description: ''
|
|
30
|
+
},
|
|
31
|
+
lists: {
|
|
32
|
+
id: 'fabric.editor.lists',
|
|
33
|
+
defaultMessage: 'Lists',
|
|
34
|
+
description: 'Menu shows ordered/bullet list and unordered/numbered lists'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.messages = messages;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.listPlugin = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
14
|
+
var _commands = require("./commands");
|
|
15
|
+
var _inputRules = _interopRequireDefault(require("./pm-plugins/input-rules"));
|
|
16
|
+
var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
17
|
+
var _main = require("./pm-plugins/main");
|
|
18
|
+
var _find = require("./utils/find");
|
|
19
|
+
var _selection = require("./utils/selection");
|
|
20
|
+
/*
|
|
21
|
+
Toolbar buttons to bullet and ordered list can be found in
|
|
22
|
+
packages/editor/editor-core/src/plugins/toolbar-lists-indentation/ui/Toolbar.tsx
|
|
23
|
+
*/
|
|
24
|
+
var listPlugin = function listPlugin(options, api) {
|
|
25
|
+
var _api$dependencies$ana;
|
|
26
|
+
var featureFlags = (api === null || api === void 0 ? void 0 : api.dependencies.featureFlags.sharedState.currentState()) || {};
|
|
27
|
+
var editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions;
|
|
28
|
+
return {
|
|
29
|
+
name: 'list',
|
|
30
|
+
actions: {
|
|
31
|
+
indentList: (0, _commands.indentList)(editorAnalyticsAPI),
|
|
32
|
+
outdentList: (0, _commands.outdentList)(editorAnalyticsAPI),
|
|
33
|
+
toggleOrderedList: (0, _commands.toggleOrderedList)(editorAnalyticsAPI),
|
|
34
|
+
toggleBulletList: (0, _commands.toggleBulletList)(editorAnalyticsAPI),
|
|
35
|
+
isInsideListItem: _selection.isInsideListItem,
|
|
36
|
+
findRootParentListNode: _find.findRootParentListNode
|
|
37
|
+
},
|
|
38
|
+
getSharedState: function getSharedState(editorState) {
|
|
39
|
+
if (!editorState) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return _main.pluginKey.getState(editorState);
|
|
43
|
+
},
|
|
44
|
+
nodes: function nodes() {
|
|
45
|
+
return [{
|
|
46
|
+
name: 'bulletList',
|
|
47
|
+
node: _adfSchema.bulletList
|
|
48
|
+
}, {
|
|
49
|
+
name: 'orderedList',
|
|
50
|
+
node: options !== null && options !== void 0 && options.restartNumberedLists ? _adfSchema.orderedListWithOrder : _adfSchema.orderedList
|
|
51
|
+
}, {
|
|
52
|
+
name: 'listItem',
|
|
53
|
+
node: _adfSchema.listItem
|
|
54
|
+
}];
|
|
55
|
+
},
|
|
56
|
+
pmPlugins: function pmPlugins() {
|
|
57
|
+
return [{
|
|
58
|
+
name: 'list',
|
|
59
|
+
plugin: function plugin(_ref) {
|
|
60
|
+
var dispatch = _ref.dispatch;
|
|
61
|
+
return (0, _main.createPlugin)(dispatch, featureFlags);
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
name: 'listInputRule',
|
|
65
|
+
plugin: function plugin(_ref2) {
|
|
66
|
+
var _api$dependencies$ana2;
|
|
67
|
+
var schema = _ref2.schema,
|
|
68
|
+
featureFlags = _ref2.featureFlags;
|
|
69
|
+
return (0, _inputRules.default)(schema, featureFlags, api === null || api === void 0 ? void 0 : (_api$dependencies$ana2 = api.dependencies.analytics) === null || _api$dependencies$ana2 === void 0 ? void 0 : _api$dependencies$ana2.actions);
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
name: 'listKeymap',
|
|
73
|
+
plugin: function plugin() {
|
|
74
|
+
var _api$dependencies$ana3;
|
|
75
|
+
return (0, _keymap.default)(featureFlags, api === null || api === void 0 ? void 0 : (_api$dependencies$ana3 = api.dependencies.analytics) === null || _api$dependencies$ana3 === void 0 ? void 0 : _api$dependencies$ana3.actions);
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
78
|
+
},
|
|
79
|
+
pluginsOptions: {
|
|
80
|
+
quickInsert: function quickInsert(_ref3) {
|
|
81
|
+
var formatMessage = _ref3.formatMessage;
|
|
82
|
+
return [{
|
|
83
|
+
id: 'unorderedList',
|
|
84
|
+
title: formatMessage(_messages.listMessages.unorderedList),
|
|
85
|
+
description: formatMessage(_messages.listMessages.unorderedListDescription),
|
|
86
|
+
keywords: ['ul', 'unordered'],
|
|
87
|
+
priority: 1100,
|
|
88
|
+
keyshortcut: (0, _keymaps.tooltip)(_keymaps.toggleBulletList),
|
|
89
|
+
icon: function icon() {
|
|
90
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconList, null);
|
|
91
|
+
},
|
|
92
|
+
action: function action(insert, state) {
|
|
93
|
+
var tr = insert(state.schema.nodes.bulletList.createChecked({}, state.schema.nodes.listItem.createChecked({}, state.schema.nodes.paragraph.createChecked())));
|
|
94
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
95
|
+
action: _analytics.ACTION.INSERTED,
|
|
96
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
97
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET,
|
|
98
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
99
|
+
attributes: {
|
|
100
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
101
|
+
}
|
|
102
|
+
})(tr);
|
|
103
|
+
return tr;
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
id: 'orderedList',
|
|
107
|
+
title: formatMessage(_messages.listMessages.orderedList),
|
|
108
|
+
description: formatMessage(_messages.listMessages.orderedListDescription),
|
|
109
|
+
keywords: ['ol', 'ordered'],
|
|
110
|
+
priority: 1200,
|
|
111
|
+
keyshortcut: (0, _keymaps.tooltip)(_keymaps.toggleOrderedList),
|
|
112
|
+
icon: function icon() {
|
|
113
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconListNumber, null);
|
|
114
|
+
},
|
|
115
|
+
action: function action(insert, state) {
|
|
116
|
+
var tr = insert(state.schema.nodes.orderedList.createChecked({}, state.schema.nodes.listItem.createChecked({}, state.schema.nodes.paragraph.createChecked())));
|
|
117
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
118
|
+
action: _analytics.ACTION.INSERTED,
|
|
119
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
120
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER,
|
|
121
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
122
|
+
attributes: {
|
|
123
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
124
|
+
}
|
|
125
|
+
})(tr);
|
|
126
|
+
return tr;
|
|
127
|
+
}
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
exports.listPlugin = listPlugin;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRuleForListType = createRuleForListType;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
+
var _wrappingJoinRule = require("./wrapping-join-rule");
|
|
10
|
+
var getOrder = function getOrder(matchResult) {
|
|
11
|
+
return Number(matchResult[1]);
|
|
12
|
+
};
|
|
13
|
+
function createRuleForListType(_ref) {
|
|
14
|
+
var listType = _ref.listType,
|
|
15
|
+
expression = _ref.expression,
|
|
16
|
+
featureFlags = _ref.featureFlags,
|
|
17
|
+
editorAnalyticsApi = _ref.editorAnalyticsApi;
|
|
18
|
+
var joinScenario = _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.NO_JOIN;
|
|
19
|
+
var isBulletList = listType.name === 'bulletList';
|
|
20
|
+
var actionSubjectId = isBulletList ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
21
|
+
var getAnalyticsPayload = function getAnalyticsPayload(state, matchResult) {
|
|
22
|
+
var analyticsPayload = {
|
|
23
|
+
action: _analytics.ACTION.INSERTED,
|
|
24
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
25
|
+
actionSubjectId: actionSubjectId,
|
|
26
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
27
|
+
attributes: {
|
|
28
|
+
inputMethod: _analytics.INPUT_METHOD.FORMATTING
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists && listType === state.schema.nodes.orderedList && analyticsPayload.attributes) {
|
|
32
|
+
analyticsPayload.attributes.listStartNumber = getOrder(matchResult);
|
|
33
|
+
analyticsPayload.attributes.joinScenario = joinScenario;
|
|
34
|
+
// we reset the tracked joinScenario after storing it in the event payload
|
|
35
|
+
joinScenario = _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.NO_JOIN;
|
|
36
|
+
}
|
|
37
|
+
return analyticsPayload;
|
|
38
|
+
};
|
|
39
|
+
var joinToNeighbourIfSameListType = function joinToNeighbourIfSameListType(_, node, scenario) {
|
|
40
|
+
var shouldJoin = node.type === listType;
|
|
41
|
+
if (shouldJoin) {
|
|
42
|
+
joinScenario = scenario;
|
|
43
|
+
}
|
|
44
|
+
return shouldJoin;
|
|
45
|
+
};
|
|
46
|
+
var getAttrs = {};
|
|
47
|
+
if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
getAttrs = function getAttrs(matchResult) {
|
|
50
|
+
return {
|
|
51
|
+
order: getOrder(matchResult)
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var inputRule = (0, _wrappingJoinRule.createWrappingJoinRule)({
|
|
56
|
+
featureFlags: featureFlags,
|
|
57
|
+
match: expression,
|
|
58
|
+
nodeType: listType,
|
|
59
|
+
getAttrs: getAttrs,
|
|
60
|
+
joinPredicate: joinToNeighbourIfSameListType
|
|
61
|
+
});
|
|
62
|
+
return (0, _utils.inputRuleWithAnalytics)(getAnalyticsPayload, editorAnalyticsApi)(inputRule);
|
|
63
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = inputRulePlugin;
|
|
7
|
+
var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
|
|
8
|
+
var _createListInputRule = require("./create-list-input-rule");
|
|
9
|
+
function inputRulePlugin(schema, featureFlags, editorAnalyticsApi) {
|
|
10
|
+
var _schema$nodes = schema.nodes,
|
|
11
|
+
bulletList = _schema$nodes.bulletList,
|
|
12
|
+
orderedList = _schema$nodes.orderedList;
|
|
13
|
+
var rules = [];
|
|
14
|
+
if (bulletList) {
|
|
15
|
+
rules.push((0, _createListInputRule.createRuleForListType)({
|
|
16
|
+
// Using UTF instead of • character
|
|
17
|
+
// because of issue where product converted the
|
|
18
|
+
// character into an escaped version.
|
|
19
|
+
expression: /^\s*([\*\-\u2022]) $/,
|
|
20
|
+
listType: bulletList,
|
|
21
|
+
featureFlags: featureFlags,
|
|
22
|
+
editorAnalyticsApi: editorAnalyticsApi
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
var expression = featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists ? /((^[1-9]{1}[0-9]{0,2})|^(0))[\.\)] $/ : /^(1)[\.\)] $/;
|
|
26
|
+
if (orderedList) {
|
|
27
|
+
rules.push((0, _createListInputRule.createRuleForListType)({
|
|
28
|
+
expression: expression,
|
|
29
|
+
listType: orderedList,
|
|
30
|
+
featureFlags: featureFlags,
|
|
31
|
+
editorAnalyticsApi: editorAnalyticsApi
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (rules.length !== 0) {
|
|
35
|
+
return (0, _prosemirrorInputRules.createPlugin)('lists', rules);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|