slate 0.101.5 → 0.102.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/dist/core/apply.d.ts.map +1 -1
- package/dist/core/batch-dirty-paths.d.ts +4 -0
- package/dist/core/batch-dirty-paths.d.ts.map +1 -0
- package/dist/core/update-dirty-paths.d.ts +10 -0
- package/dist/core/update-dirty-paths.d.ts.map +1 -0
- package/dist/index.es.js +104 -25
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +194 -97
- package/dist/index.js.map +1 -1
- package/dist/interfaces/transforms/node.d.ts +1 -0
- package/dist/interfaces/transforms/node.d.ts.map +1 -1
- package/dist/interfaces/transforms/text.d.ts +1 -0
- package/dist/interfaces/transforms/text.d.ts.map +1 -1
- package/dist/slate.js +194 -97
- package/dist/slate.min.js +1 -1
- package/dist/transforms-node/insert-nodes.d.ts.map +1 -1
- package/dist/transforms-text/insert-fragment.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core/apply.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../../packages/slate/src/core/apply.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../../packages/slate/src/core/apply.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAI7C,eAAO,MAAM,KAAK,EAAE,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAyCrD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-dirty-paths.d.ts","sourceRoot":"","sources":["../../../../packages/slate/src/core/batch-dirty-paths.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAI7C,eAAO,MAAM,oBAAoB,WAAY,MAAM,YAElD,CAAA;AAED,eAAO,MAAM,eAAe,WAClB,MAAM,MACV,MAAM,IAAI,UACN,MAAM,IAAI,SAUnB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Path } from '../interfaces/path';
|
|
2
|
+
import { Editor } from '../interfaces/editor';
|
|
3
|
+
/**
|
|
4
|
+
* update editor dirty paths
|
|
5
|
+
*
|
|
6
|
+
* @param newDirtyPaths: Path[]; new dirty paths
|
|
7
|
+
* @param transform: (p: Path) => Path | null; how to transform existing dirty paths
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateDirtyPaths(editor: Editor, newDirtyPaths: Path[], transform?: (p: Path) => Path | null): void;
|
|
10
|
+
//# sourceMappingURL=update-dirty-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-dirty-paths.d.ts","sourceRoot":"","sources":["../../../../packages/slate/src/core/update-dirty-paths.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,IAAI,EAAE,EACrB,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI,QAoCrC"}
|
package/dist/index.es.js
CHANGED
|
@@ -2182,16 +2182,29 @@ function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymb
|
|
|
2182
2182
|
function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2183
2183
|
var Transforms = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, GeneralTransforms), NodeTransforms), SelectionTransforms), TextTransforms);
|
|
2184
2184
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2185
|
+
// perf
|
|
2186
|
+
var BATCHING_DIRTY_PATHS = new WeakMap();
|
|
2187
|
+
var isBatchingDirtyPaths = editor => {
|
|
2188
|
+
return BATCHING_DIRTY_PATHS.get(editor) || false;
|
|
2189
|
+
};
|
|
2190
|
+
var batchDirtyPaths = (editor, fn, update) => {
|
|
2191
|
+
var value = BATCHING_DIRTY_PATHS.get(editor) || false;
|
|
2192
|
+
BATCHING_DIRTY_PATHS.set(editor, true);
|
|
2193
|
+
try {
|
|
2194
|
+
fn();
|
|
2195
|
+
update();
|
|
2196
|
+
} finally {
|
|
2197
|
+
BATCHING_DIRTY_PATHS.set(editor, value);
|
|
2194
2198
|
}
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
/**
|
|
2202
|
+
* update editor dirty paths
|
|
2203
|
+
*
|
|
2204
|
+
* @param newDirtyPaths: Path[]; new dirty paths
|
|
2205
|
+
* @param transform: (p: Path) => Path | null; how to transform existing dirty paths
|
|
2206
|
+
*/
|
|
2207
|
+
function updateDirtyPaths(editor, newDirtyPaths, transform) {
|
|
2195
2208
|
var oldDirtyPaths = DIRTY_PATHS.get(editor) || [];
|
|
2196
2209
|
var oldDirtyPathKeys = DIRTY_PATH_KEYS.get(editor) || new Set();
|
|
2197
2210
|
var dirtyPaths;
|
|
@@ -2205,23 +2218,39 @@ var apply = (editor, op) => {
|
|
|
2205
2218
|
}
|
|
2206
2219
|
}
|
|
2207
2220
|
};
|
|
2208
|
-
if (
|
|
2221
|
+
if (transform) {
|
|
2209
2222
|
dirtyPaths = [];
|
|
2210
2223
|
dirtyPathKeys = new Set();
|
|
2211
2224
|
for (var path of oldDirtyPaths) {
|
|
2212
|
-
var newPath =
|
|
2225
|
+
var newPath = transform(path);
|
|
2213
2226
|
add(newPath);
|
|
2214
2227
|
}
|
|
2215
2228
|
} else {
|
|
2216
2229
|
dirtyPaths = oldDirtyPaths;
|
|
2217
2230
|
dirtyPathKeys = oldDirtyPathKeys;
|
|
2218
2231
|
}
|
|
2219
|
-
var newDirtyPaths = editor.getDirtyPaths(op);
|
|
2220
2232
|
for (var _path of newDirtyPaths) {
|
|
2221
2233
|
add(_path);
|
|
2222
2234
|
}
|
|
2223
2235
|
DIRTY_PATHS.set(editor, dirtyPaths);
|
|
2224
2236
|
DIRTY_PATH_KEYS.set(editor, dirtyPathKeys);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
var apply = (editor, op) => {
|
|
2240
|
+
for (var ref of Editor.pathRefs(editor)) {
|
|
2241
|
+
PathRef.transform(ref, op);
|
|
2242
|
+
}
|
|
2243
|
+
for (var _ref of Editor.pointRefs(editor)) {
|
|
2244
|
+
PointRef.transform(_ref, op);
|
|
2245
|
+
}
|
|
2246
|
+
for (var _ref2 of Editor.rangeRefs(editor)) {
|
|
2247
|
+
RangeRef.transform(_ref2, op);
|
|
2248
|
+
}
|
|
2249
|
+
// update dirty paths
|
|
2250
|
+
if (!isBatchingDirtyPaths(editor)) {
|
|
2251
|
+
var transform = Path.operationCanTransformPath(op) ? p => Path.transform(p, op) : undefined;
|
|
2252
|
+
updateDirtyPaths(editor, editor.getDirtyPaths(op), transform);
|
|
2253
|
+
}
|
|
2225
2254
|
Transforms.transform(editor, op);
|
|
2226
2255
|
editor.operations.push(op);
|
|
2227
2256
|
Editor.normalize(editor, {
|
|
@@ -3816,7 +3845,8 @@ var insertFragment = function insertFragment(editor, fragment) {
|
|
|
3816
3845
|
voids = false
|
|
3817
3846
|
} = options;
|
|
3818
3847
|
var {
|
|
3819
|
-
at = getDefaultInsertLocation(editor)
|
|
3848
|
+
at = getDefaultInsertLocation(editor),
|
|
3849
|
+
batchDirty = true
|
|
3820
3850
|
} = options;
|
|
3821
3851
|
if (!fragment.length) {
|
|
3822
3852
|
return;
|
|
@@ -3951,7 +3981,8 @@ var insertFragment = function insertFragment(editor, fragment) {
|
|
|
3951
3981
|
at: startRef.current,
|
|
3952
3982
|
match: n => Text.isText(n) || Editor.isInline(editor, n),
|
|
3953
3983
|
mode: 'highest',
|
|
3954
|
-
voids
|
|
3984
|
+
voids,
|
|
3985
|
+
batchDirty
|
|
3955
3986
|
});
|
|
3956
3987
|
if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
|
|
3957
3988
|
Transforms.delete(editor, {
|
|
@@ -3963,13 +3994,15 @@ var insertFragment = function insertFragment(editor, fragment) {
|
|
|
3963
3994
|
at: middleRef.current,
|
|
3964
3995
|
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
3965
3996
|
mode: 'lowest',
|
|
3966
|
-
voids
|
|
3997
|
+
voids,
|
|
3998
|
+
batchDirty
|
|
3967
3999
|
});
|
|
3968
4000
|
Transforms.insertNodes(editor, ends, {
|
|
3969
4001
|
at: endRef.current,
|
|
3970
4002
|
match: n => Text.isText(n) || Editor.isInline(editor, n),
|
|
3971
4003
|
mode: 'highest',
|
|
3972
|
-
voids
|
|
4004
|
+
voids,
|
|
4005
|
+
batchDirty
|
|
3973
4006
|
});
|
|
3974
4007
|
if (!options.at) {
|
|
3975
4008
|
var path;
|
|
@@ -4152,7 +4185,8 @@ var insertNodes = function insertNodes(editor, nodes) {
|
|
|
4152
4185
|
var {
|
|
4153
4186
|
hanging = false,
|
|
4154
4187
|
voids = false,
|
|
4155
|
-
mode = 'lowest'
|
|
4188
|
+
mode = 'lowest',
|
|
4189
|
+
batchDirty = true
|
|
4156
4190
|
} = options;
|
|
4157
4191
|
var {
|
|
4158
4192
|
at,
|
|
@@ -4231,15 +4265,60 @@ var insertNodes = function insertNodes(editor, nodes) {
|
|
|
4231
4265
|
})) {
|
|
4232
4266
|
return;
|
|
4233
4267
|
}
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4268
|
+
if (batchDirty) {
|
|
4269
|
+
// PERF: batch update dirty paths
|
|
4270
|
+
// batched ops used to transform existing dirty paths
|
|
4271
|
+
var batchedOps = [];
|
|
4272
|
+
var newDirtyPaths = Path.levels(parentPath);
|
|
4273
|
+
batchDirtyPaths(editor, () => {
|
|
4274
|
+
var _loop = function _loop() {
|
|
4275
|
+
var path = parentPath.concat(index);
|
|
4276
|
+
index++;
|
|
4277
|
+
var op = {
|
|
4278
|
+
type: 'insert_node',
|
|
4279
|
+
path,
|
|
4280
|
+
node: _node
|
|
4281
|
+
};
|
|
4282
|
+
editor.apply(op);
|
|
4283
|
+
at = Path.next(at);
|
|
4284
|
+
batchedOps.push(op);
|
|
4285
|
+
if (!Text.isText) {
|
|
4286
|
+
newDirtyPaths.push(path);
|
|
4287
|
+
} else {
|
|
4288
|
+
newDirtyPaths.push(...Array.from(Node.nodes(_node), _ref => {
|
|
4289
|
+
var [, p] = _ref;
|
|
4290
|
+
return path.concat(p);
|
|
4291
|
+
}));
|
|
4292
|
+
}
|
|
4293
|
+
};
|
|
4294
|
+
for (var _node of nodes) {
|
|
4295
|
+
_loop();
|
|
4296
|
+
}
|
|
4297
|
+
}, () => {
|
|
4298
|
+
updateDirtyPaths(editor, newDirtyPaths, p => {
|
|
4299
|
+
var newPath = p;
|
|
4300
|
+
for (var op of batchedOps) {
|
|
4301
|
+
if (Path.operationCanTransformPath(op)) {
|
|
4302
|
+
newPath = Path.transform(newPath, op);
|
|
4303
|
+
if (!newPath) {
|
|
4304
|
+
return null;
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
return newPath;
|
|
4309
|
+
});
|
|
4241
4310
|
});
|
|
4242
|
-
|
|
4311
|
+
} else {
|
|
4312
|
+
for (var _node2 of nodes) {
|
|
4313
|
+
var _path = parentPath.concat(index);
|
|
4314
|
+
index++;
|
|
4315
|
+
editor.apply({
|
|
4316
|
+
type: 'insert_node',
|
|
4317
|
+
path: _path,
|
|
4318
|
+
node: _node2
|
|
4319
|
+
});
|
|
4320
|
+
at = Path.next(at);
|
|
4321
|
+
}
|
|
4243
4322
|
}
|
|
4244
4323
|
at = Path.previous(at);
|
|
4245
4324
|
if (select) {
|