@portabletext/editor 2.17.1 → 2.18.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/lib/_chunks-dts/{behavior.types.action.d.cts → index.d.ts} +9 -9
- package/lib/_chunks-es/util.get-text-block-text.js +1 -2
- package/lib/_chunks-es/util.get-text-block-text.js.map +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/plugins/index.d.ts +2 -2
- package/lib/selectors/index.d.ts +2 -2
- package/lib/utils/index.d.ts +3 -3
- package/package.json +18 -30
- package/src/test/vitest/step-definitions.tsx +2 -0
- package/src/test/vitest/test-editor.tsx +18 -4
- package/src/utils/key-generator.ts +1 -3
- package/lib/_chunks-cjs/selector.get-selection-text.cjs +0 -89
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -34
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -875
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
- package/lib/_chunks-cjs/use-editor.cjs +0 -28
- package/lib/_chunks-cjs/use-editor.cjs.map +0 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +0 -79
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +0 -1
- package/lib/_chunks-cjs/util.get-text-block-text.cjs +0 -477
- package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +0 -38
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +0 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -23
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +0 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +0 -63
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +0 -1
- package/lib/_chunks-dts/behavior.types.action.d.ts +0 -3650
- package/lib/behaviors/index.cjs +0 -35
- package/lib/behaviors/index.cjs.map +0 -1
- package/lib/behaviors/index.d.cts +0 -2
- package/lib/index.cjs +0 -12952
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.cts +0 -2
- package/lib/plugins/index.cjs +0 -826
- package/lib/plugins/index.cjs.map +0 -1
- package/lib/plugins/index.d.cts +0 -196
- package/lib/selectors/index.cjs +0 -243
- package/lib/selectors/index.cjs.map +0 -1
- package/lib/selectors/index.d.cts +0 -357
- package/lib/utils/index.cjs +0 -97
- package/lib/utils/index.cjs.map +0 -1
- package/lib/utils/index.d.cts +0 -186
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs"), util_getTextBlockText = require("./util.get-text-block-text.cjs"), schema = require("@portabletext/schema");
|
|
3
|
-
function selectionPointToBlockOffset({
|
|
4
|
-
context,
|
|
5
|
-
selectionPoint
|
|
6
|
-
}) {
|
|
7
|
-
const blockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(selectionPoint);
|
|
8
|
-
return selectionPoint.path.length === 1 && blockKey !== void 0 ? {
|
|
9
|
-
path: [{
|
|
10
|
-
_key: blockKey
|
|
11
|
-
}],
|
|
12
|
-
offset: selectionPoint.offset
|
|
13
|
-
} : util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset({
|
|
14
|
-
context,
|
|
15
|
-
selectionPoint
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function sliceTextBlock({
|
|
19
|
-
context,
|
|
20
|
-
block
|
|
21
|
-
}) {
|
|
22
|
-
const startPoint = util_getTextBlockText.getSelectionStartPoint(context.selection), endPoint = util_getTextBlockText.getSelectionEndPoint(context.selection);
|
|
23
|
-
if (!startPoint || !endPoint)
|
|
24
|
-
return block;
|
|
25
|
-
const startBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(endPoint);
|
|
26
|
-
if (startBlockKey !== endBlockKey || startBlockKey !== block._key)
|
|
27
|
-
return block;
|
|
28
|
-
const startChildKey = util_getTextBlockText.getChildKeyFromSelectionPoint(startPoint), endChildKey = util_getTextBlockText.getChildKeyFromSelectionPoint(endPoint);
|
|
29
|
-
if (!startChildKey || !endChildKey)
|
|
30
|
-
return block;
|
|
31
|
-
let startChildFound = !1;
|
|
32
|
-
const children = [];
|
|
33
|
-
for (const child of block.children) {
|
|
34
|
-
if (child._key === startChildKey) {
|
|
35
|
-
if (startChildFound = !0, schema.isSpan(context, child)) {
|
|
36
|
-
const text = child._key === endChildKey ? child.text.slice(startPoint.offset, endPoint.offset) : child.text.slice(startPoint.offset);
|
|
37
|
-
children.push({
|
|
38
|
-
...child,
|
|
39
|
-
text
|
|
40
|
-
});
|
|
41
|
-
} else
|
|
42
|
-
children.push(child);
|
|
43
|
-
if (startChildKey === endChildKey)
|
|
44
|
-
break;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (child._key === endChildKey) {
|
|
48
|
-
schema.isSpan(context, child) ? children.push({
|
|
49
|
-
...child,
|
|
50
|
-
text: child.text.slice(0, endPoint.offset)
|
|
51
|
-
}) : children.push(child);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
startChildFound && children.push(child);
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
...block,
|
|
58
|
-
children
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
exports.selectionPointToBlockOffset = selectionPointToBlockOffset;
|
|
62
|
-
exports.sliceTextBlock = sliceTextBlock;
|
|
63
|
-
//# sourceMappingURL=util.slice-text-block.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.slice-text-block.cjs","sources":["../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.slice-text-block.ts"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\nimport {getBlockKeyFromSelectionPoint} from './util.selection-point'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\nexport function sliceTextBlock({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n block: PortableTextTextBlock\n}): PortableTextTextBlock {\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n\n if (!startPoint || !endPoint) {\n return block\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {\n return block\n }\n\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startChildKey || !endChildKey) {\n return block\n }\n\n let startChildFound = false\n const children: Array<PortableTextChild> = []\n\n for (const child of block.children) {\n if (child._key === startChildKey) {\n startChildFound = true\n\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n children.push({\n ...child,\n text,\n })\n } else {\n children.push(child)\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n\n continue\n }\n\n if (child._key === endChildKey) {\n if (isSpan(context, child)) {\n children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n children.push(child)\n }\n\n break\n }\n\n if (startChildFound) {\n children.push(child)\n }\n }\n\n return {\n ...block,\n children,\n }\n}\n"],"names":["selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","path","length","undefined","_key","offset","childSelectionPointToBlockOffset","sliceTextBlock","block","startPoint","getSelectionStartPoint","selection","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startChildKey","getChildKeyFromSelectionPoint","endChildKey","startChildFound","children","child","isSpan","text","slice","push"],"mappings":";;AASO,SAASA,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,sBAAAA,8BAA8BF,cAAc;AAE7D,SAAIA,eAAeG,KAAKC,WAAW,KAAKH,aAAaI,SAC5C;AAAA,IACLF,MAAM,CAAC;AAAA,MAACG,MAAML;AAAAA,IAAAA,CAAS;AAAA,IACvBM,QAAQP,eAAeO;AAAAA,EAAAA,IAIpBC,uEAAiC;AAAA,IACtCT;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;ACnBO,SAASS,eAAe;AAAA,EAC7BV;AAAAA,EACAW;AAIF,GAA0B;AACxB,QAAMC,aAAaC,sBAAAA,uBAAuBb,QAAQc,SAAS,GACrDC,WAAWC,sBAAAA,qBAAqBhB,QAAQc,SAAS;AAEvD,MAAI,CAACF,cAAc,CAACG;AAClB,WAAOJ;AAGT,QAAMM,gBAAgBd,sBAAAA,8BAA8BS,UAAU,GACxDM,cAAcf,sBAAAA,8BAA8BY,QAAQ;AAE1D,MAAIE,kBAAkBC,eAAeD,kBAAkBN,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