@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.
- package/configure/node_modules/immutable/LICENSE +21 -0
- package/configure/node_modules/immutable/README.md +657 -0
- package/configure/node_modules/immutable/dist/immutable-nonambient.d.ts +5607 -0
- package/configure/node_modules/immutable/dist/immutable.d.ts +5611 -0
- package/configure/node_modules/immutable/dist/immutable.es.js +5893 -0
- package/configure/node_modules/immutable/dist/immutable.js +5948 -0
- package/configure/node_modules/immutable/dist/immutable.js.flow +2340 -0
- package/configure/node_modules/immutable/dist/immutable.min.js +55 -0
- package/configure/node_modules/immutable/package.json +41 -0
- package/configure/node_modules/slate-edit-list/CHANGELOG.md +124 -0
- package/configure/node_modules/slate-edit-list/LICENSE +201 -0
- package/configure/node_modules/slate-edit-list/README.md +159 -0
- package/configure/node_modules/slate-edit-list/dist/changes/decreaseItemDepth.js +73 -0
- package/configure/node_modules/slate-edit-list/dist/changes/decreaseItemDepth.js.flow +88 -0
- package/configure/node_modules/slate-edit-list/dist/changes/increaseItemDepth.js +70 -0
- package/configure/node_modules/slate-edit-list/dist/changes/increaseItemDepth.js.flow +77 -0
- package/configure/node_modules/slate-edit-list/dist/changes/index.js +34 -0
- package/configure/node_modules/slate-edit-list/dist/changes/index.js.flow +13 -0
- package/configure/node_modules/slate-edit-list/dist/changes/splitListItem.js +27 -0
- package/configure/node_modules/slate-edit-list/dist/changes/splitListItem.js.flow +26 -0
- package/configure/node_modules/slate-edit-list/dist/changes/unwrapList.js +52 -0
- package/configure/node_modules/slate-edit-list/dist/changes/unwrapList.js.flow +46 -0
- package/configure/node_modules/slate-edit-list/dist/changes/wrapInList.js +67 -0
- package/configure/node_modules/slate-edit-list/dist/changes/wrapInList.js.flow +67 -0
- package/configure/node_modules/slate-edit-list/dist/core.js +80 -0
- package/configure/node_modules/slate-edit-list/dist/core.js.flow +76 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/index.js +24 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/index.js.flow +5 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onBackspace.js +45 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onBackspace.js.flow +44 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onEnter.js +54 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onEnter.js.flow +54 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onTab.js +39 -0
- package/configure/node_modules/slate-edit-list/dist/handlers/onTab.js.flow +34 -0
- package/configure/node_modules/slate-edit-list/dist/index.js +58 -0
- package/configure/node_modules/slate-edit-list/dist/index.js.flow +45 -0
- package/configure/node_modules/slate-edit-list/dist/options.js +34 -0
- package/configure/node_modules/slate-edit-list/dist/options.js.flow +26 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getCurrentItem.js +24 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getCurrentItem.js.flow +20 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getCurrentList.js +31 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getCurrentList.js.flow +21 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getItemDepth.js +34 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getItemDepth.js.flow +24 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getItemsAtRange.js +60 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getItemsAtRange.js.flow +51 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getListForItem.js +25 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getListForItem.js.flow +16 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getPreviousItem.js +39 -0
- package/configure/node_modules/slate-edit-list/dist/utils/getPreviousItem.js.flow +29 -0
- package/configure/node_modules/slate-edit-list/dist/utils/index.js +49 -0
- package/configure/node_modules/slate-edit-list/dist/utils/index.js.flow +19 -0
- package/configure/node_modules/slate-edit-list/dist/utils/isList.js +15 -0
- package/configure/node_modules/slate-edit-list/dist/utils/isList.js.flow +13 -0
- package/configure/node_modules/slate-edit-list/dist/utils/isSelectionInList.js +22 -0
- package/configure/node_modules/slate-edit-list/dist/utils/isSelectionInList.js.flow +14 -0
- package/configure/node_modules/slate-edit-list/dist/validation/index.js +19 -0
- package/configure/node_modules/slate-edit-list/dist/validation/index.js.flow +4 -0
- package/configure/node_modules/slate-edit-list/dist/validation/schema.js +83 -0
- package/configure/node_modules/slate-edit-list/dist/validation/schema.js.flow +81 -0
- package/configure/node_modules/slate-edit-list/dist/validation/validateNode.js +61 -0
- package/configure/node_modules/slate-edit-list/dist/validation/validateNode.js.flow +61 -0
- package/configure/node_modules/slate-edit-list/package.json +67 -0
- package/configure/node_modules/slate-edit-table/CHANGELOG.md +192 -0
- package/configure/node_modules/slate-edit-table/LICENSE +201 -0
- package/configure/node_modules/slate-edit-table/README.md +269 -0
- package/configure/node_modules/slate-edit-table/dist/changes/clearCell.js +29 -0
- package/configure/node_modules/slate-edit-table/dist/changes/clearCell.js.flow +26 -0
- package/configure/node_modules/slate-edit-table/dist/changes/index.js +69 -0
- package/configure/node_modules/slate-edit-table/dist/changes/index.js.flow +27 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertColumn.js +43 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertColumn.js.flow +46 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertRow.js +36 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertRow.js.flow +35 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertTable.js +29 -0
- package/configure/node_modules/slate-edit-table/dist/changes/insertTable.js.flow +27 -0
- package/configure/node_modules/slate-edit-table/dist/changes/moveSelection.js +32 -0
- package/configure/node_modules/slate-edit-table/dist/changes/moveSelection.js.flow +31 -0
- package/configure/node_modules/slate-edit-table/dist/changes/moveSelectionBy.js +84 -0
- package/configure/node_modules/slate-edit-table/dist/changes/moveSelectionBy.js.flow +80 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeColumn.js +36 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeColumn.js.flow +28 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeColumnByKey.js +52 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeColumnByKey.js.flow +40 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeRow.js +36 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeRow.js.flow +27 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeRowByKey.js +41 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeRowByKey.js.flow +30 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeTable.js +26 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeTable.js.flow +17 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeTableByKey.js +56 -0
- package/configure/node_modules/slate-edit-table/dist/changes/removeTableByKey.js.flow +54 -0
- package/configure/node_modules/slate-edit-table/dist/core.js +88 -0
- package/configure/node_modules/slate-edit-table/dist/core.js.flow +94 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/index.js +39 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/index.js.flow +8 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onBackspace.js +82 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onBackspace.js.flow +87 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onEnter.js +34 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onEnter.js.flow +37 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onKeyDown.js +71 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onKeyDown.js.flow +56 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onModEnter.js +35 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onModEnter.js.flow +38 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onTab.js +56 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onTab.js.flow +51 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onUpDown.js +38 -0
- package/configure/node_modules/slate-edit-table/dist/handlers/onUpDown.js.flow +41 -0
- package/configure/node_modules/slate-edit-table/dist/index.js +36 -0
- package/configure/node_modules/slate-edit-table/dist/index.js.flow +27 -0
- package/configure/node_modules/slate-edit-table/dist/options.js +61 -0
- package/configure/node_modules/slate-edit-table/dist/options.js.flow +42 -0
- package/configure/node_modules/slate-edit-table/dist/utils/TablePosition.js +306 -0
- package/configure/node_modules/slate-edit-table/dist/utils/TablePosition.js.flow +211 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createCell.js +30 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createCell.js.flow +26 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createRow.js +30 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createRow.js.flow +28 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createTable.js +30 -0
- package/configure/node_modules/slate-edit-table/dist/utils/createTable.js.flow +33 -0
- package/configure/node_modules/slate-edit-table/dist/utils/forEachCells.js +21 -0
- package/configure/node_modules/slate-edit-table/dist/utils/forEachCells.js.flow +22 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtColumn.js +22 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtColumn.js.flow +19 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtRow.js +20 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getCellsAtRow.js.flow +19 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getPosition.js +24 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getPosition.js.flow +19 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getPositionByKey.js +26 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getPositionByKey.js.flow +21 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getRow.js +24 -0
- package/configure/node_modules/slate-edit-table/dist/utils/getRow.js.flow +19 -0
- package/configure/node_modules/slate-edit-table/dist/utils/index.js +64 -0
- package/configure/node_modules/slate-edit-table/dist/utils/index.js.flow +25 -0
- package/configure/node_modules/slate-edit-table/dist/utils/isSelectionInTable.js +34 -0
- package/configure/node_modules/slate-edit-table/dist/utils/isSelectionInTable.js.flow +27 -0
- package/configure/node_modules/slate-edit-table/dist/utils/isSelectionOutOfTable.js +30 -0
- package/configure/node_modules/slate-edit-table/dist/utils/isSelectionOutOfTable.js.flow +23 -0
- package/configure/node_modules/slate-edit-table/dist/validation/index.js +19 -0
- package/configure/node_modules/slate-edit-table/dist/validation/index.js.flow +4 -0
- package/configure/node_modules/slate-edit-table/dist/validation/schema.js +101 -0
- package/configure/node_modules/slate-edit-table/dist/validation/schema.js.flow +98 -0
- package/configure/node_modules/slate-edit-table/dist/validation/validateNode.js +56 -0
- package/configure/node_modules/slate-edit-table/dist/validation/validateNode.js.flow +49 -0
- package/configure/node_modules/slate-edit-table/package.json +69 -0
- package/package.json +2 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _slate = require('slate');
|
|
8
|
+
|
|
9
|
+
var _immutable = require('immutable');
|
|
10
|
+
|
|
11
|
+
var _utils = require('../utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrap the blocks in the current selection in a new list. Selected
|
|
15
|
+
* lists are merged together.
|
|
16
|
+
*/
|
|
17
|
+
function wrapInList(opts, change, type, data) {
|
|
18
|
+
var selectedBlocks = getHighestSelectedBlocks(change.value);
|
|
19
|
+
type = type || opts.types[0];
|
|
20
|
+
|
|
21
|
+
// Wrap in container
|
|
22
|
+
change.wrapBlock({
|
|
23
|
+
type: type,
|
|
24
|
+
data: _slate.Data.create(data)
|
|
25
|
+
}, { normalize: false });
|
|
26
|
+
|
|
27
|
+
// Wrap in list items
|
|
28
|
+
selectedBlocks.forEach(function (node) {
|
|
29
|
+
if ((0, _utils.isList)(opts, node)) {
|
|
30
|
+
// Merge its items with the created list
|
|
31
|
+
node.nodes.forEach(function (_ref) {
|
|
32
|
+
var key = _ref.key;
|
|
33
|
+
return change.unwrapNodeByKey(key, { normalize: false });
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
change.wrapBlockByKey(node.key, opts.typeItem, {
|
|
37
|
+
normalize: false
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return change.normalize();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the highest list of blocks that cover the current selection
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
function getHighestSelectedBlocks(value) {
|
|
50
|
+
var range = value.selection;
|
|
51
|
+
var document = value.document;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
var startBlock = document.getClosestBlock(range.startKey);
|
|
55
|
+
var endBlock = document.getClosestBlock(range.endKey);
|
|
56
|
+
|
|
57
|
+
if (startBlock === endBlock) {
|
|
58
|
+
return (0, _immutable.List)([startBlock]);
|
|
59
|
+
}
|
|
60
|
+
var ancestor = document.getCommonAncestor(startBlock.key, endBlock.key);
|
|
61
|
+
var startPath = ancestor.getPath(startBlock.key);
|
|
62
|
+
var endPath = ancestor.getPath(endBlock.key);
|
|
63
|
+
|
|
64
|
+
return ancestor.nodes.slice(startPath[0], endPath[0] + 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.default = wrapInList;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { Data, type Value, type Change, type Block } from 'slate';
|
|
3
|
+
import { List } from 'immutable';
|
|
4
|
+
|
|
5
|
+
import type Options from '../options';
|
|
6
|
+
import { isList } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wrap the blocks in the current selection in a new list. Selected
|
|
10
|
+
* lists are merged together.
|
|
11
|
+
*/
|
|
12
|
+
function wrapInList(
|
|
13
|
+
opts: Options,
|
|
14
|
+
change: Change,
|
|
15
|
+
type?: string,
|
|
16
|
+
data?: Object | Data
|
|
17
|
+
): Change {
|
|
18
|
+
const selectedBlocks = getHighestSelectedBlocks(change.value);
|
|
19
|
+
type = type || opts.types[0];
|
|
20
|
+
|
|
21
|
+
// Wrap in container
|
|
22
|
+
change.wrapBlock(
|
|
23
|
+
{
|
|
24
|
+
type,
|
|
25
|
+
data: Data.create(data)
|
|
26
|
+
},
|
|
27
|
+
{ normalize: false }
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Wrap in list items
|
|
31
|
+
selectedBlocks.forEach(node => {
|
|
32
|
+
if (isList(opts, node)) {
|
|
33
|
+
// Merge its items with the created list
|
|
34
|
+
node.nodes.forEach(({ key }) =>
|
|
35
|
+
change.unwrapNodeByKey(key, { normalize: false })
|
|
36
|
+
);
|
|
37
|
+
} else {
|
|
38
|
+
change.wrapBlockByKey(node.key, opts.typeItem, {
|
|
39
|
+
normalize: false
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return change.normalize();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the highest list of blocks that cover the current selection
|
|
49
|
+
*/
|
|
50
|
+
function getHighestSelectedBlocks(value: Value): List<Block> {
|
|
51
|
+
const range = value.selection;
|
|
52
|
+
const { document } = value;
|
|
53
|
+
|
|
54
|
+
const startBlock = document.getClosestBlock(range.startKey);
|
|
55
|
+
const endBlock = document.getClosestBlock(range.endKey);
|
|
56
|
+
|
|
57
|
+
if (startBlock === endBlock) {
|
|
58
|
+
return List([startBlock]);
|
|
59
|
+
}
|
|
60
|
+
const ancestor = document.getCommonAncestor(startBlock.key, endBlock.key);
|
|
61
|
+
const startPath = ancestor.getPath(startBlock.key);
|
|
62
|
+
const endPath = ancestor.getPath(endBlock.key);
|
|
63
|
+
|
|
64
|
+
return ancestor.nodes.slice(startPath[0], endPath[0] + 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default wrapInList;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _options = require('./options');
|
|
8
|
+
|
|
9
|
+
var _options2 = _interopRequireDefault(_options);
|
|
10
|
+
|
|
11
|
+
var _validation = require('./validation');
|
|
12
|
+
|
|
13
|
+
var _changes = require('./changes');
|
|
14
|
+
|
|
15
|
+
var _utils = require('./utils');
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the core of the plugin, limited to the validation and normalization
|
|
23
|
+
* part of `slate-edit-list`, and utils.
|
|
24
|
+
*
|
|
25
|
+
* Import this directly: `import EditListCore from 'slate-edit-table/lib/core'`
|
|
26
|
+
* if you don't care about behavior/rendering and you
|
|
27
|
+
* are only manipulating `Slate.Values` without rendering them.
|
|
28
|
+
* That way you do not depend on importing `slate-react`.
|
|
29
|
+
*/
|
|
30
|
+
function core() {
|
|
31
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
+
|
|
33
|
+
opts = new _options2.default(opts);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
schema: (0, _validation.schema)(opts),
|
|
37
|
+
validateNode: (0, _validation.validateNode)(opts),
|
|
38
|
+
|
|
39
|
+
utils: {
|
|
40
|
+
getCurrentItem: _utils.getCurrentItem.bind(null, opts),
|
|
41
|
+
getCurrentList: _utils.getCurrentList.bind(null, opts),
|
|
42
|
+
getItemDepth: _utils.getItemDepth.bind(null, opts),
|
|
43
|
+
getItemsAtRange: _utils.getItemsAtRange.bind(null, opts),
|
|
44
|
+
getPreviousItem: _utils.getPreviousItem.bind(null, opts),
|
|
45
|
+
isList: _utils.isList.bind(null, opts),
|
|
46
|
+
isSelectionInList: _utils.isSelectionInList.bind(null, opts)
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
changes: {
|
|
50
|
+
decreaseItemDepth: bindAndScopeChange(opts, _changes.decreaseItemDepth),
|
|
51
|
+
increaseItemDepth: bindAndScopeChange(opts, _changes.increaseItemDepth),
|
|
52
|
+
splitListItem: bindAndScopeChange(opts, _changes.splitListItem),
|
|
53
|
+
unwrapList: bindAndScopeChange(opts, _changes.unwrapList),
|
|
54
|
+
wrapInList: _changes.wrapInList.bind(null, opts)
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Bind a change to given options, and scope it to act only inside a list
|
|
61
|
+
*/
|
|
62
|
+
function bindAndScopeChange(opts, fn) {
|
|
63
|
+
return function (change) {
|
|
64
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
65
|
+
args[_key - 1] = arguments[_key];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var value = change.value;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if (!(0, _utils.isSelectionInList)(opts, value)) {
|
|
72
|
+
return change;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// $FlowFixMe
|
|
76
|
+
return fn.apply(undefined, _toConsumableArray([opts, change].concat(args)));
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.default = core;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import Options, { type OptionsFormat } from './options';
|
|
3
|
+
import { schema, validateNode } from './validation';
|
|
4
|
+
import {
|
|
5
|
+
wrapInList,
|
|
6
|
+
unwrapList,
|
|
7
|
+
splitListItem,
|
|
8
|
+
increaseItemDepth,
|
|
9
|
+
decreaseItemDepth
|
|
10
|
+
} from './changes';
|
|
11
|
+
import {
|
|
12
|
+
getItemDepth,
|
|
13
|
+
isList,
|
|
14
|
+
isSelectionInList,
|
|
15
|
+
getCurrentItem,
|
|
16
|
+
getCurrentList,
|
|
17
|
+
getItemsAtRange,
|
|
18
|
+
getPreviousItem
|
|
19
|
+
} from './utils';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the core of the plugin, limited to the validation and normalization
|
|
23
|
+
* part of `slate-edit-list`, and utils.
|
|
24
|
+
*
|
|
25
|
+
* Import this directly: `import EditListCore from 'slate-edit-table/lib/core'`
|
|
26
|
+
* if you don't care about behavior/rendering and you
|
|
27
|
+
* are only manipulating `Slate.Values` without rendering them.
|
|
28
|
+
* That way you do not depend on importing `slate-react`.
|
|
29
|
+
*/
|
|
30
|
+
function core(
|
|
31
|
+
// Options for the plugin
|
|
32
|
+
opts: OptionsFormat = {}
|
|
33
|
+
): Object {
|
|
34
|
+
opts = new Options(opts);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
schema: schema(opts),
|
|
38
|
+
validateNode: validateNode(opts),
|
|
39
|
+
|
|
40
|
+
utils: {
|
|
41
|
+
getCurrentItem: getCurrentItem.bind(null, opts),
|
|
42
|
+
getCurrentList: getCurrentList.bind(null, opts),
|
|
43
|
+
getItemDepth: getItemDepth.bind(null, opts),
|
|
44
|
+
getItemsAtRange: getItemsAtRange.bind(null, opts),
|
|
45
|
+
getPreviousItem: getPreviousItem.bind(null, opts),
|
|
46
|
+
isList: isList.bind(null, opts),
|
|
47
|
+
isSelectionInList: isSelectionInList.bind(null, opts)
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
changes: {
|
|
51
|
+
decreaseItemDepth: bindAndScopeChange(opts, decreaseItemDepth),
|
|
52
|
+
increaseItemDepth: bindAndScopeChange(opts, increaseItemDepth),
|
|
53
|
+
splitListItem: bindAndScopeChange(opts, splitListItem),
|
|
54
|
+
unwrapList: bindAndScopeChange(opts, unwrapList),
|
|
55
|
+
wrapInList: wrapInList.bind(null, opts)
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Bind a change to given options, and scope it to act only inside a list
|
|
62
|
+
*/
|
|
63
|
+
function bindAndScopeChange(opts: Options, fn: *): * {
|
|
64
|
+
return (change, ...args) => {
|
|
65
|
+
const { value } = change;
|
|
66
|
+
|
|
67
|
+
if (!isSelectionInList(opts, value)) {
|
|
68
|
+
return change;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// $FlowFixMe
|
|
72
|
+
return fn(...[opts, change].concat(args));
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default core;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.onBackspace = exports.onTab = exports.onEnter = undefined;
|
|
7
|
+
|
|
8
|
+
var _onEnter = require('./onEnter');
|
|
9
|
+
|
|
10
|
+
var _onEnter2 = _interopRequireDefault(_onEnter);
|
|
11
|
+
|
|
12
|
+
var _onTab = require('./onTab');
|
|
13
|
+
|
|
14
|
+
var _onTab2 = _interopRequireDefault(_onTab);
|
|
15
|
+
|
|
16
|
+
var _onBackspace = require('./onBackspace');
|
|
17
|
+
|
|
18
|
+
var _onBackspace2 = _interopRequireDefault(_onBackspace);
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
exports.onEnter = _onEnter2.default;
|
|
23
|
+
exports.onTab = _onTab2.default;
|
|
24
|
+
exports.onBackspace = _onBackspace2.default;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
require('slate');
|
|
8
|
+
|
|
9
|
+
var _changes = require('../changes');
|
|
10
|
+
|
|
11
|
+
var _utils = require('../utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* User pressed Delete in an editor
|
|
15
|
+
*/
|
|
16
|
+
function onBackspace(event, change, editor, opts) {
|
|
17
|
+
var value = change.value;
|
|
18
|
+
var startOffset = value.startOffset,
|
|
19
|
+
selection = value.selection;
|
|
20
|
+
|
|
21
|
+
// Only unwrap...
|
|
22
|
+
// ... with a collapsed selection
|
|
23
|
+
|
|
24
|
+
if (selection.isExpanded) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ... when at the beginning of nodes
|
|
29
|
+
if (startOffset > 0) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
// ... in a list
|
|
33
|
+
var currentItem = (0, _utils.getCurrentItem)(opts, value);
|
|
34
|
+
if (!currentItem) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
// ... more precisely at the beginning of the current item
|
|
38
|
+
if (!selection.isAtStartOf(currentItem)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
return (0, _changes.unwrapList)(opts, change);
|
|
44
|
+
}
|
|
45
|
+
exports.default = onBackspace;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { type Change } from 'slate';
|
|
3
|
+
|
|
4
|
+
import type Options from '../options';
|
|
5
|
+
import { unwrapList } from '../changes';
|
|
6
|
+
import { getCurrentItem } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* User pressed Delete in an editor
|
|
10
|
+
*/
|
|
11
|
+
function onBackspace(
|
|
12
|
+
event: *,
|
|
13
|
+
change: Change,
|
|
14
|
+
editor: *,
|
|
15
|
+
opts: Options
|
|
16
|
+
): void | any {
|
|
17
|
+
const { value } = change;
|
|
18
|
+
const { startOffset, selection } = value;
|
|
19
|
+
|
|
20
|
+
// Only unwrap...
|
|
21
|
+
// ... with a collapsed selection
|
|
22
|
+
if (selection.isExpanded) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ... when at the beginning of nodes
|
|
27
|
+
if (startOffset > 0) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
// ... in a list
|
|
31
|
+
const currentItem = getCurrentItem(opts, value);
|
|
32
|
+
if (!currentItem) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
// ... more precisely at the beginning of the current item
|
|
36
|
+
if (!selection.isAtStartOf(currentItem)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
return unwrapList(opts, change);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default onBackspace;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
require('slate');
|
|
8
|
+
|
|
9
|
+
var _changes = require('../changes');
|
|
10
|
+
|
|
11
|
+
var _utils = require('../utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* User pressed Enter in an editor
|
|
15
|
+
*
|
|
16
|
+
* Enter in a list item should split the list item
|
|
17
|
+
* Enter in an empty list item should remove it
|
|
18
|
+
* Shift+Enter in a list item should make a new line
|
|
19
|
+
*/
|
|
20
|
+
function onEnter(event, change, editor, opts) {
|
|
21
|
+
// Pressing Shift+Enter
|
|
22
|
+
// should split block normally
|
|
23
|
+
if (event.shiftKey) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var value = change.value;
|
|
28
|
+
|
|
29
|
+
var currentItem = (0, _utils.getCurrentItem)(opts, value);
|
|
30
|
+
|
|
31
|
+
// Not in a list
|
|
32
|
+
if (!currentItem) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
|
|
38
|
+
// If expanded, delete first.
|
|
39
|
+
if (value.isExpanded) {
|
|
40
|
+
change.delete();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (currentItem.isEmpty) {
|
|
44
|
+
// Block is empty, we exit the list
|
|
45
|
+
if ((0, _utils.getItemDepth)(opts, value) > 1) {
|
|
46
|
+
return (0, _changes.decreaseItemDepth)(opts, change);
|
|
47
|
+
}
|
|
48
|
+
// Exit list
|
|
49
|
+
return (0, _changes.unwrapList)(opts, change);
|
|
50
|
+
}
|
|
51
|
+
// Split list item
|
|
52
|
+
return (0, _changes.splitListItem)(opts, change);
|
|
53
|
+
}
|
|
54
|
+
exports.default = onEnter;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { type Change } from 'slate';
|
|
3
|
+
|
|
4
|
+
import type Options from '../options';
|
|
5
|
+
import { unwrapList, splitListItem, decreaseItemDepth } from '../changes';
|
|
6
|
+
import { getCurrentItem, getItemDepth } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* User pressed Enter in an editor
|
|
10
|
+
*
|
|
11
|
+
* Enter in a list item should split the list item
|
|
12
|
+
* Enter in an empty list item should remove it
|
|
13
|
+
* Shift+Enter in a list item should make a new line
|
|
14
|
+
*/
|
|
15
|
+
function onEnter(
|
|
16
|
+
event: *,
|
|
17
|
+
change: Change,
|
|
18
|
+
editor: *,
|
|
19
|
+
opts: Options
|
|
20
|
+
): void | any {
|
|
21
|
+
// Pressing Shift+Enter
|
|
22
|
+
// should split block normally
|
|
23
|
+
if (event.shiftKey) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { value } = change;
|
|
28
|
+
const currentItem = getCurrentItem(opts, value);
|
|
29
|
+
|
|
30
|
+
// Not in a list
|
|
31
|
+
if (!currentItem) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
|
|
37
|
+
// If expanded, delete first.
|
|
38
|
+
if (value.isExpanded) {
|
|
39
|
+
change.delete();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (currentItem.isEmpty) {
|
|
43
|
+
// Block is empty, we exit the list
|
|
44
|
+
if (getItemDepth(opts, value) > 1) {
|
|
45
|
+
return decreaseItemDepth(opts, change);
|
|
46
|
+
}
|
|
47
|
+
// Exit list
|
|
48
|
+
return unwrapList(opts, change);
|
|
49
|
+
}
|
|
50
|
+
// Split list item
|
|
51
|
+
return splitListItem(opts, change);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default onEnter;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
require('slate');
|
|
8
|
+
|
|
9
|
+
var _changes = require('../changes');
|
|
10
|
+
|
|
11
|
+
var _utils = require('../utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* User pressed Tab in an editor.
|
|
15
|
+
* Tab -> Increase item depth if inside a list item
|
|
16
|
+
* Shift+Tab -> Decrease item depth if inside a list item
|
|
17
|
+
*/
|
|
18
|
+
function onTab(event, change, editor, opts) {
|
|
19
|
+
var value = change.value;
|
|
20
|
+
var isCollapsed = value.isCollapsed;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if (!isCollapsed || !(0, _utils.getCurrentItem)(opts, value)) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Shift+tab reduce depth
|
|
28
|
+
if (event.shiftKey) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
|
|
31
|
+
return (0, _changes.decreaseItemDepth)(opts, change);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Tab increases depth
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
|
|
37
|
+
return (0, _changes.increaseItemDepth)(opts, change);
|
|
38
|
+
}
|
|
39
|
+
exports.default = onTab;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { type Change } from 'slate';
|
|
3
|
+
|
|
4
|
+
import type Options from '../options';
|
|
5
|
+
import { decreaseItemDepth, increaseItemDepth } from '../changes';
|
|
6
|
+
import { getCurrentItem } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* User pressed Tab in an editor.
|
|
10
|
+
* Tab -> Increase item depth if inside a list item
|
|
11
|
+
* Shift+Tab -> Decrease item depth if inside a list item
|
|
12
|
+
*/
|
|
13
|
+
function onTab(event: *, change: Change, editor: *, opts: Options): void | any {
|
|
14
|
+
const { value } = change;
|
|
15
|
+
const { isCollapsed } = value;
|
|
16
|
+
|
|
17
|
+
if (!isCollapsed || !getCurrentItem(opts, value)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Shift+tab reduce depth
|
|
22
|
+
if (event.shiftKey) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
|
|
25
|
+
return decreaseItemDepth(opts, change);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Tab increases depth
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
|
|
31
|
+
return increaseItemDepth(opts, change);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default onTab;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
+
|
|
9
|
+
var _options = require('./options');
|
|
10
|
+
|
|
11
|
+
var _options2 = _interopRequireDefault(_options);
|
|
12
|
+
|
|
13
|
+
var _handlers = require('./handlers');
|
|
14
|
+
|
|
15
|
+
var _core = require('./core');
|
|
16
|
+
|
|
17
|
+
var _core2 = _interopRequireDefault(_core);
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
var KEY_ENTER = 'Enter';
|
|
22
|
+
var KEY_TAB = 'Tab';
|
|
23
|
+
var KEY_BACKSPACE = 'Backspace';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A Slate plugin to handle keyboard events in lists.
|
|
27
|
+
*/
|
|
28
|
+
function EditList() {
|
|
29
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
+
|
|
31
|
+
opts = new _options2.default(opts);
|
|
32
|
+
var corePlugin = (0, _core2.default)(opts);
|
|
33
|
+
|
|
34
|
+
return _extends({}, corePlugin, {
|
|
35
|
+
|
|
36
|
+
onKeyDown: onKeyDown.bind(null, opts)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* User is pressing a key in the editor
|
|
42
|
+
*/
|
|
43
|
+
function onKeyDown(opts, event, change, editor) {
|
|
44
|
+
var args = [event, change, editor, opts];
|
|
45
|
+
|
|
46
|
+
switch (event.key) {
|
|
47
|
+
case KEY_ENTER:
|
|
48
|
+
return _handlers.onEnter.apply(undefined, args);
|
|
49
|
+
case KEY_TAB:
|
|
50
|
+
return _handlers.onTab.apply(undefined, args);
|
|
51
|
+
case KEY_BACKSPACE:
|
|
52
|
+
return _handlers.onBackspace.apply(undefined, args);
|
|
53
|
+
default:
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.default = EditList;
|