@pie-element/ebsr 6.6.3-next.411 → 6.6.3-next.412

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 (146) hide show
  1. package/configure/node_modules/immutable/LICENSE +21 -0
  2. package/configure/node_modules/immutable/README.md +657 -0
  3. package/configure/node_modules/immutable/dist/immutable-nonambient.d.ts +5607 -0
  4. package/configure/node_modules/immutable/dist/immutable.d.ts +5611 -0
  5. package/configure/node_modules/immutable/dist/immutable.es.js +5893 -0
  6. package/configure/node_modules/immutable/dist/immutable.js +5948 -0
  7. package/configure/node_modules/immutable/dist/immutable.js.flow +2340 -0
  8. package/configure/node_modules/immutable/dist/immutable.min.js +55 -0
  9. package/configure/node_modules/immutable/package.json +41 -0
  10. package/configure/node_modules/slate-edit-list/CHANGELOG.md +124 -0
  11. package/configure/node_modules/slate-edit-list/LICENSE +201 -0
  12. package/configure/node_modules/slate-edit-list/README.md +159 -0
  13. package/configure/node_modules/slate-edit-list/dist/changes/decreaseItemDepth.js +73 -0
  14. package/configure/node_modules/slate-edit-list/dist/changes/decreaseItemDepth.js.flow +88 -0
  15. package/configure/node_modules/slate-edit-list/dist/changes/increaseItemDepth.js +70 -0
  16. package/configure/node_modules/slate-edit-list/dist/changes/increaseItemDepth.js.flow +77 -0
  17. package/configure/node_modules/slate-edit-list/dist/changes/index.js +34 -0
  18. package/configure/node_modules/slate-edit-list/dist/changes/index.js.flow +13 -0
  19. package/configure/node_modules/slate-edit-list/dist/changes/splitListItem.js +27 -0
  20. package/configure/node_modules/slate-edit-list/dist/changes/splitListItem.js.flow +26 -0
  21. package/configure/node_modules/slate-edit-list/dist/changes/unwrapList.js +52 -0
  22. package/configure/node_modules/slate-edit-list/dist/changes/unwrapList.js.flow +46 -0
  23. package/configure/node_modules/slate-edit-list/dist/changes/wrapInList.js +67 -0
  24. package/configure/node_modules/slate-edit-list/dist/changes/wrapInList.js.flow +67 -0
  25. package/configure/node_modules/slate-edit-list/dist/core.js +80 -0
  26. package/configure/node_modules/slate-edit-list/dist/core.js.flow +76 -0
  27. package/configure/node_modules/slate-edit-list/dist/handlers/index.js +24 -0
  28. package/configure/node_modules/slate-edit-list/dist/handlers/index.js.flow +5 -0
  29. package/configure/node_modules/slate-edit-list/dist/handlers/onBackspace.js +45 -0
  30. package/configure/node_modules/slate-edit-list/dist/handlers/onBackspace.js.flow +44 -0
  31. package/configure/node_modules/slate-edit-list/dist/handlers/onEnter.js +54 -0
  32. package/configure/node_modules/slate-edit-list/dist/handlers/onEnter.js.flow +54 -0
  33. package/configure/node_modules/slate-edit-list/dist/handlers/onTab.js +39 -0
  34. package/configure/node_modules/slate-edit-list/dist/handlers/onTab.js.flow +34 -0
  35. package/configure/node_modules/slate-edit-list/dist/index.js +58 -0
  36. package/configure/node_modules/slate-edit-list/dist/index.js.flow +45 -0
  37. package/configure/node_modules/slate-edit-list/dist/options.js +34 -0
  38. package/configure/node_modules/slate-edit-list/dist/options.js.flow +26 -0
  39. package/configure/node_modules/slate-edit-list/dist/utils/getCurrentItem.js +24 -0
  40. package/configure/node_modules/slate-edit-list/dist/utils/getCurrentItem.js.flow +20 -0
  41. package/configure/node_modules/slate-edit-list/dist/utils/getCurrentList.js +31 -0
  42. package/configure/node_modules/slate-edit-list/dist/utils/getCurrentList.js.flow +21 -0
  43. package/configure/node_modules/slate-edit-list/dist/utils/getItemDepth.js +34 -0
  44. package/configure/node_modules/slate-edit-list/dist/utils/getItemDepth.js.flow +24 -0
  45. package/configure/node_modules/slate-edit-list/dist/utils/getItemsAtRange.js +60 -0
  46. package/configure/node_modules/slate-edit-list/dist/utils/getItemsAtRange.js.flow +51 -0
  47. package/configure/node_modules/slate-edit-list/dist/utils/getListForItem.js +25 -0
  48. package/configure/node_modules/slate-edit-list/dist/utils/getListForItem.js.flow +16 -0
  49. package/configure/node_modules/slate-edit-list/dist/utils/getPreviousItem.js +39 -0
  50. package/configure/node_modules/slate-edit-list/dist/utils/getPreviousItem.js.flow +29 -0
  51. package/configure/node_modules/slate-edit-list/dist/utils/index.js +49 -0
  52. package/configure/node_modules/slate-edit-list/dist/utils/index.js.flow +19 -0
  53. package/configure/node_modules/slate-edit-list/dist/utils/isList.js +15 -0
  54. package/configure/node_modules/slate-edit-list/dist/utils/isList.js.flow +13 -0
  55. package/configure/node_modules/slate-edit-list/dist/utils/isSelectionInList.js +22 -0
  56. package/configure/node_modules/slate-edit-list/dist/utils/isSelectionInList.js.flow +14 -0
  57. package/configure/node_modules/slate-edit-list/dist/validation/index.js +19 -0
  58. package/configure/node_modules/slate-edit-list/dist/validation/index.js.flow +4 -0
  59. package/configure/node_modules/slate-edit-list/dist/validation/schema.js +83 -0
  60. package/configure/node_modules/slate-edit-list/dist/validation/schema.js.flow +81 -0
  61. package/configure/node_modules/slate-edit-list/dist/validation/validateNode.js +61 -0
  62. package/configure/node_modules/slate-edit-list/dist/validation/validateNode.js.flow +61 -0
  63. package/configure/node_modules/slate-edit-list/package.json +67 -0
  64. package/configure/node_modules/slate-edit-table/CHANGELOG.md +192 -0
  65. package/configure/node_modules/slate-edit-table/LICENSE +201 -0
  66. package/configure/node_modules/slate-edit-table/README.md +269 -0
  67. package/configure/node_modules/slate-edit-table/dist/changes/clearCell.js +29 -0
  68. package/configure/node_modules/slate-edit-table/dist/changes/clearCell.js.flow +26 -0
  69. package/configure/node_modules/slate-edit-table/dist/changes/index.js +69 -0
  70. package/configure/node_modules/slate-edit-table/dist/changes/index.js.flow +27 -0
  71. package/configure/node_modules/slate-edit-table/dist/changes/insertColumn.js +43 -0
  72. package/configure/node_modules/slate-edit-table/dist/changes/insertColumn.js.flow +46 -0
  73. package/configure/node_modules/slate-edit-table/dist/changes/insertRow.js +36 -0
  74. package/configure/node_modules/slate-edit-table/dist/changes/insertRow.js.flow +35 -0
  75. package/configure/node_modules/slate-edit-table/dist/changes/insertTable.js +29 -0
  76. package/configure/node_modules/slate-edit-table/dist/changes/insertTable.js.flow +27 -0
  77. package/configure/node_modules/slate-edit-table/dist/changes/moveSelection.js +32 -0
  78. package/configure/node_modules/slate-edit-table/dist/changes/moveSelection.js.flow +31 -0
  79. package/configure/node_modules/slate-edit-table/dist/changes/moveSelectionBy.js +84 -0
  80. package/configure/node_modules/slate-edit-table/dist/changes/moveSelectionBy.js.flow +80 -0
  81. package/configure/node_modules/slate-edit-table/dist/changes/removeColumn.js +36 -0
  82. package/configure/node_modules/slate-edit-table/dist/changes/removeColumn.js.flow +28 -0
  83. package/configure/node_modules/slate-edit-table/dist/changes/removeColumnByKey.js +52 -0
  84. package/configure/node_modules/slate-edit-table/dist/changes/removeColumnByKey.js.flow +40 -0
  85. package/configure/node_modules/slate-edit-table/dist/changes/removeRow.js +36 -0
  86. package/configure/node_modules/slate-edit-table/dist/changes/removeRow.js.flow +27 -0
  87. package/configure/node_modules/slate-edit-table/dist/changes/removeRowByKey.js +41 -0
  88. package/configure/node_modules/slate-edit-table/dist/changes/removeRowByKey.js.flow +30 -0
  89. package/configure/node_modules/slate-edit-table/dist/changes/removeTable.js +26 -0
  90. package/configure/node_modules/slate-edit-table/dist/changes/removeTable.js.flow +17 -0
  91. package/configure/node_modules/slate-edit-table/dist/changes/removeTableByKey.js +56 -0
  92. package/configure/node_modules/slate-edit-table/dist/changes/removeTableByKey.js.flow +54 -0
  93. package/configure/node_modules/slate-edit-table/dist/core.js +88 -0
  94. package/configure/node_modules/slate-edit-table/dist/core.js.flow +94 -0
  95. package/configure/node_modules/slate-edit-table/dist/handlers/index.js +39 -0
  96. package/configure/node_modules/slate-edit-table/dist/handlers/index.js.flow +8 -0
  97. package/configure/node_modules/slate-edit-table/dist/handlers/onBackspace.js +82 -0
  98. package/configure/node_modules/slate-edit-table/dist/handlers/onBackspace.js.flow +87 -0
  99. package/configure/node_modules/slate-edit-table/dist/handlers/onEnter.js +34 -0
  100. package/configure/node_modules/slate-edit-table/dist/handlers/onEnter.js.flow +37 -0
  101. package/configure/node_modules/slate-edit-table/dist/handlers/onKeyDown.js +71 -0
  102. package/configure/node_modules/slate-edit-table/dist/handlers/onKeyDown.js.flow +56 -0
  103. package/configure/node_modules/slate-edit-table/dist/handlers/onModEnter.js +35 -0
  104. package/configure/node_modules/slate-edit-table/dist/handlers/onModEnter.js.flow +38 -0
  105. package/configure/node_modules/slate-edit-table/dist/handlers/onTab.js +56 -0
  106. package/configure/node_modules/slate-edit-table/dist/handlers/onTab.js.flow +51 -0
  107. package/configure/node_modules/slate-edit-table/dist/handlers/onUpDown.js +38 -0
  108. package/configure/node_modules/slate-edit-table/dist/handlers/onUpDown.js.flow +41 -0
  109. package/configure/node_modules/slate-edit-table/dist/index.js +36 -0
  110. package/configure/node_modules/slate-edit-table/dist/index.js.flow +27 -0
  111. package/configure/node_modules/slate-edit-table/dist/options.js +61 -0
  112. package/configure/node_modules/slate-edit-table/dist/options.js.flow +42 -0
  113. package/configure/node_modules/slate-edit-table/dist/utils/TablePosition.js +306 -0
  114. package/configure/node_modules/slate-edit-table/dist/utils/TablePosition.js.flow +211 -0
  115. package/configure/node_modules/slate-edit-table/dist/utils/createCell.js +30 -0
  116. package/configure/node_modules/slate-edit-table/dist/utils/createCell.js.flow +26 -0
  117. package/configure/node_modules/slate-edit-table/dist/utils/createRow.js +30 -0
  118. package/configure/node_modules/slate-edit-table/dist/utils/createRow.js.flow +28 -0
  119. package/configure/node_modules/slate-edit-table/dist/utils/createTable.js +30 -0
  120. package/configure/node_modules/slate-edit-table/dist/utils/createTable.js.flow +33 -0
  121. package/configure/node_modules/slate-edit-table/dist/utils/forEachCells.js +21 -0
  122. package/configure/node_modules/slate-edit-table/dist/utils/forEachCells.js.flow +22 -0
  123. package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtColumn.js +22 -0
  124. package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtColumn.js.flow +19 -0
  125. package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtRow.js +20 -0
  126. package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtRow.js.flow +19 -0
  127. package/configure/node_modules/slate-edit-table/dist/utils/getPosition.js +24 -0
  128. package/configure/node_modules/slate-edit-table/dist/utils/getPosition.js.flow +19 -0
  129. package/configure/node_modules/slate-edit-table/dist/utils/getPositionByKey.js +26 -0
  130. package/configure/node_modules/slate-edit-table/dist/utils/getPositionByKey.js.flow +21 -0
  131. package/configure/node_modules/slate-edit-table/dist/utils/getRow.js +24 -0
  132. package/configure/node_modules/slate-edit-table/dist/utils/getRow.js.flow +19 -0
  133. package/configure/node_modules/slate-edit-table/dist/utils/index.js +64 -0
  134. package/configure/node_modules/slate-edit-table/dist/utils/index.js.flow +25 -0
  135. package/configure/node_modules/slate-edit-table/dist/utils/isSelectionInTable.js +34 -0
  136. package/configure/node_modules/slate-edit-table/dist/utils/isSelectionInTable.js.flow +27 -0
  137. package/configure/node_modules/slate-edit-table/dist/utils/isSelectionOutOfTable.js +30 -0
  138. package/configure/node_modules/slate-edit-table/dist/utils/isSelectionOutOfTable.js.flow +23 -0
  139. package/configure/node_modules/slate-edit-table/dist/validation/index.js +19 -0
  140. package/configure/node_modules/slate-edit-table/dist/validation/index.js.flow +4 -0
  141. package/configure/node_modules/slate-edit-table/dist/validation/schema.js +101 -0
  142. package/configure/node_modules/slate-edit-table/dist/validation/schema.js.flow +98 -0
  143. package/configure/node_modules/slate-edit-table/dist/validation/validateNode.js +56 -0
  144. package/configure/node_modules/slate-edit-table/dist/validation/validateNode.js.flow +49 -0
  145. package/configure/node_modules/slate-edit-table/package.json +69 -0
  146. package/package.json +2 -2
@@ -0,0 +1,159 @@
1
+ # slate-edit-list
2
+
3
+ [![NPM version](https://badge.fury.io/js/slate-edit-list.svg)](http://badge.fury.io/js/slate-edit-list)
4
+ [![Linux Build Status](https://travis-ci.org/GitbookIO/slate-edit-list.png?branch=master)](https://travis-ci.org/GitbookIO/slate-edit-list)
5
+
6
+ A Slate plugin to handle keyboard events in lists. List items can contain blocks.
7
+
8
+ Demo: [gitbookio.github.io/slate-edit-list/](https://gitbookio.github.io/slate-edit-list/)
9
+
10
+ ### Install
11
+
12
+ ```
13
+ npm install slate-edit-list
14
+ ```
15
+
16
+ ### Features
17
+
18
+ Natural keybindings:
19
+
20
+ - Pressing <kbd>Enter</kbd> insert a new list item
21
+ - Pressing <kbd>Shift+Enter</kbd> split the block in the list item
22
+ - Pressing <kbd>Tab</kbd> increase the depth of the item (creates a sub-list)
23
+ - Pressing <kbd>Shift+Tab</kbd> decrease the depth of the item
24
+ - Pressing <kbd>Delete</kbd> (OSX) or <kbd>Backspace</kbd> at the start, remove the list item (or the list)
25
+
26
+ Simple validation/normalization (see [assumptions about the schema](#assumption-about-the-schema)):
27
+
28
+ - Lists can contain only list items, and at least one.
29
+ - List items can only be the direct children of a list.
30
+ - List items must always contain blocks.
31
+
32
+ Useful transforms: see [Utilities and Transform](#utilities-and-transform).
33
+
34
+ ### Simple Usage
35
+
36
+ ```js
37
+ import EditList from 'slate-edit-list'
38
+
39
+ const plugins = [
40
+ EditList()
41
+ ]
42
+ ```
43
+
44
+ #### Arguments
45
+
46
+ This plugin accepts options to redefine the following block types:
47
+
48
+ - `<String> types=["ol_list", "ul_list"]` — the array of possible types for list containers. First value will be used as default.
49
+ - `<String> typeItem="list_item"` — type for list items.
50
+ - `<String> typeDefault="paragraph"` — type for default block in list items.
51
+
52
+ #### Assumption about the schema
53
+
54
+ You can use this plugins with custom list block types (using plugin [arguments](#arguments)). But your lists structure should still conform to a few rules. These rules are implemented as schema.
55
+
56
+ Here is what a minimal list would look like:
57
+
58
+
59
+ ```yaml
60
+ nodes:
61
+ - kind: block
62
+ type: ul_list # Default type for bulleted lists container
63
+ nodes:
64
+ - kind: block
65
+ type: list_item # List containers can only contain list items
66
+ nodes:
67
+ # List items contain blocks. They cannot be the direct container of text.
68
+ - kind: block
69
+ type: paragraph # Default type of blocks in a list item
70
+ nodes:
71
+ - kind: text
72
+ text: Hello World
73
+ ```
74
+
75
+ And here is an example of a multi-level list:
76
+
77
+ ```yaml
78
+ nodes:
79
+ - kind: block
80
+ type: ol_list
81
+ nodes:
82
+ - kind: block
83
+ type: list_item
84
+ nodes:
85
+ - kind: block
86
+ type: paragraph
87
+ nodes:
88
+ - kind: text
89
+ text: Item 1
90
+ - kind: block
91
+ type: ol_list
92
+ nodes:
93
+ - kind: block
94
+ type: list_item
95
+ nodes:
96
+ - kind: block
97
+ type: paragraph
98
+ nodes:
99
+ - kind: text
100
+ text: Item 1.1
101
+ - kind: block
102
+ type: list_item
103
+ nodes:
104
+ - kind: block
105
+ type: paragraph
106
+ nodes:
107
+ - kind: text
108
+ text: Item 1.2
109
+ ```
110
+
111
+ ### Utilities and Transform
112
+
113
+ `slate-edit-list` exports utilities and transforms:
114
+
115
+ #### `plugin.utils.isSelectionInList(state: State) => Boolean`
116
+
117
+ Return true if selection is inside a list (and it can be unwrap).
118
+
119
+ #### `plugin.utils.isList(node: Node) => Boolean`
120
+
121
+ Return true if the node is one of the list type.
122
+
123
+ #### `plugin.utils.getItemDepth(state: State, block: Block?) => Number`
124
+
125
+ Returns the depth of the current item (or the depth of the given block) in a list. 0 means not in a list.
126
+
127
+ #### `plugin.utils.getCurrentItem(state: State, block: Block?) => Block || Void`
128
+
129
+ Returns the current item at selection (or at the given block).
130
+
131
+ #### `plugin.utils.getCurrentList(state: State, block: Block?) => Block || Void`
132
+
133
+ Returns the current list at selection (or at the given block).
134
+
135
+ #### `plugin.utils.getItemsAtRange(state: State, range: Selection?) => List<Node>`
136
+
137
+ Return the list of items at the given range. The returned items are the highest list of of successive items that cover the given range.
138
+
139
+ The returned list is empty if no such list can be found.
140
+
141
+ #### `plugin.changes.increaseItemDepth(transform: Transform) => Transform`
142
+
143
+ Increase the depth of the current item.
144
+
145
+ #### `plugin.changes.decreaseItemDepth(transform: Transform) => Transform`
146
+
147
+ Decrease the depth of the current item.
148
+
149
+ #### `plugin.changes.wrapInList(transform: Transform, type: String?, data: Object|Data?) => Transform`
150
+
151
+ Wrap the current blocks in list items of a list container of the given type. You can pass optional data for the created list container.
152
+
153
+ #### `plugin.changes.unwrapList(transform: Transform) => Transform`
154
+
155
+ Unwrap all items at range from their list.
156
+
157
+ #### `plugin.changes.splitListItem(transform: Transform) => Transform`
158
+
159
+ Split current block into a new list item.
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _slate = require('slate');
8
+
9
+ var _utils = require('../utils');
10
+
11
+ /**
12
+ * Decreases the depth of the current item. The following items will
13
+ * be moved as sublist of the decreased item.
14
+ *
15
+ * No-op for root items.
16
+ */
17
+ function decreaseItemDepth(opts, change) {
18
+ var value = change.value;
19
+ var document = value.document;
20
+
21
+ // Cannot decrease item depth of root items
22
+
23
+ var depth = (0, _utils.getItemDepth)(opts, value);
24
+ if (depth == 1) {
25
+ return change;
26
+ }
27
+
28
+ var currentItem = (0, _utils.getCurrentItem)(opts, value);
29
+ if (!currentItem) {
30
+ return change;
31
+ }
32
+
33
+ var currentList = document.getParent(currentItem.key);
34
+ var parentItem = document.getParent(currentList.key);
35
+ var parentList = document.getParent(parentItem.key);
36
+ // The items following the item will be moved to a sublist of currentItem
37
+ var followingItems = currentList.nodes.skipUntil(function (i) {
38
+ return i === currentItem;
39
+ }).rest();
40
+
41
+ // True if the currentItem and the followingItems make the whole
42
+ // currentList, and hence the currentList will be emptied
43
+ var willEmptyCurrentList = currentList.nodes.size === followingItems.size + 1;
44
+
45
+ if (!followingItems.isEmpty()) {
46
+ // Add them as sublist of currentItem
47
+ var sublist = _slate.Block.create({
48
+ object: 'block',
49
+ type: currentList.type,
50
+ data: currentList.data
51
+ });
52
+ // Add the sublist
53
+ change.insertNodeByKey(currentItem.key, currentItem.nodes.size, sublist, { normalize: false });
54
+
55
+ change.moveNodeByKey(currentItem.key, parentList.key, parentList.nodes.indexOf(parentItem) + 1, { normalize: false });
56
+
57
+ // Move the followingItems to the sublist
58
+ followingItems.forEach(function (item, index) {
59
+ return change.moveNodeByKey(item.key, sublist.key, sublist.nodes.size + index, { normalize: false });
60
+ });
61
+ } else {
62
+ change.moveNodeByKey(currentItem.key, parentList.key, parentList.nodes.indexOf(parentItem) + 1);
63
+ }
64
+
65
+ // Remove the currentList completely if needed
66
+ if (willEmptyCurrentList) {
67
+ change.removeNodeByKey(currentList.key);
68
+ }
69
+
70
+ return change;
71
+ }
72
+
73
+ exports.default = decreaseItemDepth;
@@ -0,0 +1,88 @@
1
+ // @flow
2
+ import { Block, type Change } from 'slate';
3
+
4
+ import type Options from '../options';
5
+ import { getItemDepth, getCurrentItem } from '../utils';
6
+
7
+ /**
8
+ * Decreases the depth of the current item. The following items will
9
+ * be moved as sublist of the decreased item.
10
+ *
11
+ * No-op for root items.
12
+ */
13
+ function decreaseItemDepth(opts: Options, change: Change): Change {
14
+ const { value } = change;
15
+ const { document } = value;
16
+
17
+ // Cannot decrease item depth of root items
18
+ const depth = getItemDepth(opts, value);
19
+ if (depth == 1) {
20
+ return change;
21
+ }
22
+
23
+ const currentItem = getCurrentItem(opts, value);
24
+ if (!currentItem) {
25
+ return change;
26
+ }
27
+
28
+ const currentList = document.getParent(currentItem.key);
29
+ const parentItem = document.getParent(currentList.key);
30
+ const parentList = document.getParent(parentItem.key);
31
+ // The items following the item will be moved to a sublist of currentItem
32
+ const followingItems = currentList.nodes
33
+ .skipUntil(i => i === currentItem)
34
+ .rest();
35
+
36
+ // True if the currentItem and the followingItems make the whole
37
+ // currentList, and hence the currentList will be emptied
38
+ const willEmptyCurrentList =
39
+ currentList.nodes.size === followingItems.size + 1;
40
+
41
+ if (!followingItems.isEmpty()) {
42
+ // Add them as sublist of currentItem
43
+ const sublist = Block.create({
44
+ object: 'block',
45
+ type: currentList.type,
46
+ data: currentList.data
47
+ });
48
+ // Add the sublist
49
+ change.insertNodeByKey(
50
+ currentItem.key,
51
+ currentItem.nodes.size,
52
+ sublist,
53
+ { normalize: false }
54
+ );
55
+
56
+ change.moveNodeByKey(
57
+ currentItem.key,
58
+ parentList.key,
59
+ parentList.nodes.indexOf(parentItem) + 1,
60
+ { normalize: false }
61
+ );
62
+
63
+ // Move the followingItems to the sublist
64
+ followingItems.forEach((item, index) =>
65
+ change.moveNodeByKey(
66
+ item.key,
67
+ sublist.key,
68
+ sublist.nodes.size + index,
69
+ { normalize: false }
70
+ )
71
+ );
72
+ } else {
73
+ change.moveNodeByKey(
74
+ currentItem.key,
75
+ parentList.key,
76
+ parentList.nodes.indexOf(parentItem) + 1
77
+ );
78
+ }
79
+
80
+ // Remove the currentList completely if needed
81
+ if (willEmptyCurrentList) {
82
+ change.removeNodeByKey(currentList.key);
83
+ }
84
+
85
+ return change;
86
+ }
87
+
88
+ export default decreaseItemDepth;
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _slate = require('slate');
8
+
9
+ var _utils = require('../utils');
10
+
11
+ /**
12
+ * Increase the depth of the current item by putting it in a sub-list
13
+ * of previous item.
14
+ * For first items in a list, does nothing.
15
+ */
16
+ function increaseItemDepth(opts, change) {
17
+ var previousItem = (0, _utils.getPreviousItem)(opts, change.value);
18
+ var currentItem = (0, _utils.getCurrentItem)(opts, change.value);
19
+
20
+ if (!previousItem) {
21
+ return change;
22
+ }
23
+
24
+ if (!currentItem) {
25
+ return change;
26
+ }
27
+
28
+ // Move the item in the sublist of previous item
29
+ return moveAsSubItem(opts, change, currentItem, previousItem.key);
30
+ }
31
+
32
+ /**
33
+ * Move the given item to the sublist at the end of destination item,
34
+ * creating a sublist if needed.
35
+ */
36
+ function moveAsSubItem(opts, change,
37
+ // The list item to add
38
+ item,
39
+ // The key of the destination node
40
+ destKey) {
41
+ var destination = change.value.document.getDescendant(destKey);
42
+ var lastIndex = destination.nodes.size;
43
+ var lastChild = destination.nodes.last();
44
+
45
+ // The potential existing last child list
46
+ var existingList = (0, _utils.isList)(opts, lastChild) ? lastChild : null;
47
+
48
+ if (existingList) {
49
+ return change.moveNodeByKey(item.key, existingList.key, existingList.nodes.size // as last item
50
+ );
51
+ }
52
+ var currentList = (0, _utils.getListForItem)(opts, change.value, destination);
53
+ if (!currentList) {
54
+ throw new Error('Destination is not in a list');
55
+ }
56
+
57
+ var newSublist = _slate.Block.create({
58
+ object: 'block',
59
+ type: currentList.type,
60
+ data: currentList.data
61
+ });
62
+
63
+ change.insertNodeByKey(destKey, lastIndex, newSublist, {
64
+ normalize: false
65
+ });
66
+
67
+ return change.moveNodeByKey(item.key, newSublist.key, 0);
68
+ }
69
+
70
+ exports.default = increaseItemDepth;
@@ -0,0 +1,77 @@
1
+ // @flow
2
+ import { Block, type Change } from 'slate';
3
+
4
+ import type Options from '../options';
5
+ import {
6
+ getPreviousItem,
7
+ getCurrentItem,
8
+ getListForItem,
9
+ isList
10
+ } from '../utils';
11
+
12
+ /**
13
+ * Increase the depth of the current item by putting it in a sub-list
14
+ * of previous item.
15
+ * For first items in a list, does nothing.
16
+ */
17
+ function increaseItemDepth(opts: Options, change: Change): Change {
18
+ const previousItem = getPreviousItem(opts, change.value);
19
+ const currentItem = getCurrentItem(opts, change.value);
20
+
21
+ if (!previousItem) {
22
+ return change;
23
+ }
24
+
25
+ if (!currentItem) {
26
+ return change;
27
+ }
28
+
29
+ // Move the item in the sublist of previous item
30
+ return moveAsSubItem(opts, change, currentItem, previousItem.key);
31
+ }
32
+
33
+ /**
34
+ * Move the given item to the sublist at the end of destination item,
35
+ * creating a sublist if needed.
36
+ */
37
+ function moveAsSubItem(
38
+ opts: Options,
39
+ change: Change,
40
+ // The list item to add
41
+ item: Block,
42
+ // The key of the destination node
43
+ destKey: string
44
+ ): Change {
45
+ const destination = change.value.document.getDescendant(destKey);
46
+ const lastIndex = destination.nodes.size;
47
+ const lastChild = destination.nodes.last();
48
+
49
+ // The potential existing last child list
50
+ const existingList = isList(opts, lastChild) ? lastChild : null;
51
+
52
+ if (existingList) {
53
+ return change.moveNodeByKey(
54
+ item.key,
55
+ existingList.key,
56
+ existingList.nodes.size // as last item
57
+ );
58
+ }
59
+ const currentList = getListForItem(opts, change.value, destination);
60
+ if (!currentList) {
61
+ throw new Error('Destination is not in a list');
62
+ }
63
+
64
+ const newSublist = Block.create({
65
+ object: 'block',
66
+ type: currentList.type,
67
+ data: currentList.data
68
+ });
69
+
70
+ change.insertNodeByKey(destKey, lastIndex, newSublist, {
71
+ normalize: false
72
+ });
73
+
74
+ return change.moveNodeByKey(item.key, newSublist.key, 0);
75
+ }
76
+
77
+ export default increaseItemDepth;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.decreaseItemDepth = exports.increaseItemDepth = exports.splitListItem = exports.unwrapList = exports.wrapInList = undefined;
7
+
8
+ var _wrapInList = require('./wrapInList');
9
+
10
+ var _wrapInList2 = _interopRequireDefault(_wrapInList);
11
+
12
+ var _unwrapList = require('./unwrapList');
13
+
14
+ var _unwrapList2 = _interopRequireDefault(_unwrapList);
15
+
16
+ var _splitListItem = require('./splitListItem');
17
+
18
+ var _splitListItem2 = _interopRequireDefault(_splitListItem);
19
+
20
+ var _increaseItemDepth = require('./increaseItemDepth');
21
+
22
+ var _increaseItemDepth2 = _interopRequireDefault(_increaseItemDepth);
23
+
24
+ var _decreaseItemDepth = require('./decreaseItemDepth');
25
+
26
+ var _decreaseItemDepth2 = _interopRequireDefault(_decreaseItemDepth);
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
30
+ exports.wrapInList = _wrapInList2.default;
31
+ exports.unwrapList = _unwrapList2.default;
32
+ exports.splitListItem = _splitListItem2.default;
33
+ exports.increaseItemDepth = _increaseItemDepth2.default;
34
+ exports.decreaseItemDepth = _decreaseItemDepth2.default;
@@ -0,0 +1,13 @@
1
+ import wrapInList from './wrapInList';
2
+ import unwrapList from './unwrapList';
3
+ import splitListItem from './splitListItem';
4
+ import increaseItemDepth from './increaseItemDepth';
5
+ import decreaseItemDepth from './decreaseItemDepth';
6
+
7
+ export {
8
+ wrapInList,
9
+ unwrapList,
10
+ splitListItem,
11
+ increaseItemDepth,
12
+ decreaseItemDepth
13
+ };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ require('slate');
8
+
9
+ var _utils = require('../utils');
10
+
11
+ /**
12
+ * Split a list item at the start of the current range.
13
+ */
14
+ function splitListItem(opts, change) {
15
+ var value = change.value;
16
+
17
+ var currentItem = (0, _utils.getCurrentItem)(opts, value);
18
+ if (!currentItem) {
19
+ return change;
20
+ }
21
+
22
+ var splitOffset = value.startOffset;
23
+
24
+ return change.splitDescendantsByKey(currentItem.key, value.startKey, splitOffset);
25
+ }
26
+
27
+ exports.default = splitListItem;
@@ -0,0 +1,26 @@
1
+ // @flow
2
+ import { type Change } from 'slate';
3
+
4
+ import type Options from '../options';
5
+ import { getCurrentItem } from '../utils';
6
+
7
+ /**
8
+ * Split a list item at the start of the current range.
9
+ */
10
+ function splitListItem(opts: Options, change: Change): Change {
11
+ const { value } = change;
12
+ const currentItem = getCurrentItem(opts, value);
13
+ if (!currentItem) {
14
+ return change;
15
+ }
16
+
17
+ const splitOffset = value.startOffset;
18
+
19
+ return change.splitDescendantsByKey(
20
+ currentItem.key,
21
+ value.startKey,
22
+ splitOffset
23
+ );
24
+ }
25
+
26
+ export default splitListItem;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ require('slate');
8
+
9
+ var _utils = require('../utils');
10
+
11
+ /**
12
+ * Unwrap items at range from their list.
13
+ */
14
+ function unwrapList(opts, change) {
15
+ var items = (0, _utils.getItemsAtRange)(opts, change.value);
16
+
17
+ if (items.isEmpty()) {
18
+ return change;
19
+ }
20
+
21
+ // Unwrap the items from their list
22
+ items.forEach(function (item) {
23
+ return change.unwrapNodeByKey(item.key, { normalize: false });
24
+ });
25
+
26
+ // Parent of the list of the items
27
+ var firstItem = items.first();
28
+ var parent = change.value.document.getParent(firstItem.key);
29
+
30
+ var index = parent.nodes.findIndex(function (node) {
31
+ return node.key === firstItem.key;
32
+ });
33
+
34
+ // Unwrap the items' children
35
+ items.forEach(function (item) {
36
+ item.nodes.forEach(function (node) {
37
+ change.moveNodeByKey(node.key, parent.key, index, {
38
+ normalize: false
39
+ });
40
+ index += 1;
41
+ });
42
+ });
43
+
44
+ // Finally, remove the now empty items
45
+ items.forEach(function (item) {
46
+ return change.removeNodeByKey(item.key, { normalize: false });
47
+ });
48
+
49
+ return change;
50
+ }
51
+
52
+ exports.default = unwrapList;
@@ -0,0 +1,46 @@
1
+ // @flow
2
+ import { type Change } from 'slate';
3
+
4
+ import type Options from '../options';
5
+ import { getItemsAtRange } from '../utils';
6
+
7
+ /**
8
+ * Unwrap items at range from their list.
9
+ */
10
+ function unwrapList(opts: Options, change: Change): Change {
11
+ const items = getItemsAtRange(opts, change.value);
12
+
13
+ if (items.isEmpty()) {
14
+ return change;
15
+ }
16
+
17
+ // Unwrap the items from their list
18
+ items.forEach(item =>
19
+ change.unwrapNodeByKey(item.key, { normalize: false })
20
+ );
21
+
22
+ // Parent of the list of the items
23
+ const firstItem = items.first();
24
+ const parent = change.value.document.getParent(firstItem.key);
25
+
26
+ let index = parent.nodes.findIndex(node => node.key === firstItem.key);
27
+
28
+ // Unwrap the items' children
29
+ items.forEach(item => {
30
+ item.nodes.forEach(node => {
31
+ change.moveNodeByKey(node.key, parent.key, index, {
32
+ normalize: false
33
+ });
34
+ index += 1;
35
+ });
36
+ });
37
+
38
+ // Finally, remove the now empty items
39
+ items.forEach(item =>
40
+ change.removeNodeByKey(item.key, { normalize: false })
41
+ );
42
+
43
+ return change;
44
+ }
45
+
46
+ export default unwrapList;