@portabletext/editor 1.33.2 → 1.33.4
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-cjs/behavior.core.cjs +11 -204
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +7 -7
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +208 -33
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +246 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +31 -200
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +7 -5
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -116
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +138 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +9 -202
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +205 -31
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +2 -1
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +249 -0
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +20 -189
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js +5 -3
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.reverse-selection.js +1 -117
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +140 -3
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.d.cts +1 -115
- package/lib/index.d.ts +1 -115
- package/lib/plugins/index.cjs +19 -15
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +1 -115
- package/lib/plugins/index.d.ts +1 -115
- package/lib/plugins/index.js +9 -5
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +16 -21
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -0
- package/lib/selectors/index.d.ts +2 -0
- package/lib/selectors/index.js +7 -11
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +13 -13
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +3 -3
- package/package.json +2 -2
- package/src/behaviors/behavior.core.annotations.ts +0 -24
- package/src/behaviors/behavior.core.decorators.ts +0 -19
- package/src/behaviors/behavior.core.insert-break.ts +4 -4
- package/src/behaviors/behavior.core.lists.ts +0 -30
- package/src/behaviors/behavior.core.ts +2 -17
- package/src/behaviors/behavior.default.ts +198 -0
- package/src/behaviors/behavior.foundational.ts +12 -12
- package/src/behaviors/behavior.markdown-emphasis.ts +4 -0
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +1 -1
- package/src/editor/editor-machine.ts +8 -8
- package/src/plugins/plugin.event-listener.tsx +1 -1
- package/src/selectors/selector.get-caret-word-selection.ts +9 -0
- package/src/selectors/selector.get-selection-text.test.ts +383 -36
- package/src/selectors/selector.get-selection-text.ts +13 -73
- package/src/utils/util.block-offset.test.ts +312 -0
- package/src/utils/util.block-offset.ts +39 -7
- package/src/utils/util.block-offsets-to-selection.ts +2 -0
- package/src/utils/util.slice-blocks.ts +12 -1
- package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs +0 -97
- package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-trimmed-selection.js +0 -100
- package/lib/_chunks-es/selector.get-trimmed-selection.js.map +0 -1
- package/src/behaviors/behavior.core.deserialize.ts +0 -60
- package/src/behaviors/behavior.core.serialize.ts +0 -44
- package/src/behaviors/behavior.core.style.ts +0 -19
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
|
|
2
|
-
import { isEmptyTextBlock, isKeyedSegment } from "./util.reverse-selection.js";
|
|
3
|
-
import { isSelectionCollapsed, getFocusTextBlock, getSelectionStartPoint, getSelectionEndPoint } from "./selector.is-at-the-start-of-block.js";
|
|
4
|
-
const getTrimmedSelection = ({
|
|
5
|
-
context
|
|
6
|
-
}) => {
|
|
7
|
-
if (!context.selection)
|
|
8
|
-
return context.selection;
|
|
9
|
-
const startPoint = getSelectionStartPoint({
|
|
10
|
-
context
|
|
11
|
-
}), endPoint = getSelectionEndPoint({
|
|
12
|
-
context
|
|
13
|
-
});
|
|
14
|
-
if (!startPoint || !endPoint)
|
|
15
|
-
return context.selection;
|
|
16
|
-
const startBlockKey = isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : null, startChildKey = isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : null, endBlockKey = isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : null, endChildKey = isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : null;
|
|
17
|
-
if (!startBlockKey || !endBlockKey)
|
|
18
|
-
return context.selection;
|
|
19
|
-
let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
|
|
20
|
-
for (const block of context.value)
|
|
21
|
-
if (!(block._key === startBlockKey && (startBlockFound = !0, isPortableTextTextBlock(block) && isEmptyTextBlock(block))) && startBlockFound && isPortableTextTextBlock(block)) {
|
|
22
|
-
if (block._key === endBlockKey && isEmptyTextBlock(block))
|
|
23
|
-
break;
|
|
24
|
-
for (const child of block.children) {
|
|
25
|
-
if (child._key === endChildKey && (!isPortableTextSpan(child) || endPoint.offset === 0)) {
|
|
26
|
-
adjustedEndPoint = previousPotentialEndpoint ? {
|
|
27
|
-
path: [{
|
|
28
|
-
_key: previousPotentialEndpoint.blockKey
|
|
29
|
-
}, "children", {
|
|
30
|
-
_key: previousPotentialEndpoint.span._key
|
|
31
|
-
}],
|
|
32
|
-
offset: previousPotentialEndpoint.span.text.length
|
|
33
|
-
} : void 0, trimEndPoint = !0;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
if (trimStartPoint) {
|
|
37
|
-
const lonelySpan = isPortableTextSpan(child) && block.children.length === 1;
|
|
38
|
-
(isPortableTextSpan(child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
|
|
39
|
-
path: [{
|
|
40
|
-
_key: block._key
|
|
41
|
-
}, "children", {
|
|
42
|
-
_key: child._key
|
|
43
|
-
}],
|
|
44
|
-
offset: 0
|
|
45
|
-
}, previousPotentialEndpoint = {
|
|
46
|
-
blockKey: block._key,
|
|
47
|
-
span: child
|
|
48
|
-
}, trimStartPoint = !1);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (child._key === startChildKey) {
|
|
52
|
-
if (!isPortableTextSpan(child)) {
|
|
53
|
-
trimStartPoint = !0;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (startPoint.offset === child.text.length) {
|
|
57
|
-
trimStartPoint = !0, previousPotentialEndpoint = child.text.length > 0 ? {
|
|
58
|
-
blockKey: block._key,
|
|
59
|
-
span: child
|
|
60
|
-
} : previousPotentialEndpoint;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
previousPotentialEndpoint = isPortableTextSpan(child) && child.text.length > 0 ? {
|
|
65
|
-
blockKey: block._key,
|
|
66
|
-
span: child
|
|
67
|
-
} : previousPotentialEndpoint;
|
|
68
|
-
}
|
|
69
|
-
if (block._key === endBlockKey)
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
const trimmedSelection = context.selection.backward ? {
|
|
73
|
-
anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,
|
|
74
|
-
focus: adjustedStartPoint ?? startPoint,
|
|
75
|
-
backward: !0
|
|
76
|
-
} : {
|
|
77
|
-
anchor: adjustedStartPoint ?? startPoint,
|
|
78
|
-
focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
|
|
79
|
-
};
|
|
80
|
-
if (isSelectionCollapsed({
|
|
81
|
-
context: {
|
|
82
|
-
...context,
|
|
83
|
-
selection: trimmedSelection
|
|
84
|
-
}
|
|
85
|
-
})) {
|
|
86
|
-
const focusTextBlock = getFocusTextBlock({
|
|
87
|
-
context: {
|
|
88
|
-
...context,
|
|
89
|
-
selection: trimmedSelection
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node))
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return trimmedSelection;
|
|
96
|
-
};
|
|
97
|
-
export {
|
|
98
|
-
getTrimmedSelection
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=selector.get-trimmed-selection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-trimmed-selection.js","sources":["../../src/selectors/selector.get-trimmed-selection.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {isEmptyTextBlock, isKeyedSegment} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getTrimmedSelection: EditorSelector<EditorSelection> = ({\n context,\n}) => {\n if (!context.selection) {\n return context.selection\n }\n\n const startPoint = getSelectionStartPoint({context})\n const endPoint = getSelectionEndPoint({context})\n\n if (!startPoint || !endPoint) {\n return context.selection\n }\n\n const startBlockKey = isKeyedSegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : null\n const startChildKey = isKeyedSegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : null\n const endBlockKey = isKeyedSegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : null\n const endChildKey = isKeyedSegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : null\n\n if (!startBlockKey || !endBlockKey) {\n return context.selection\n }\n\n let startBlockFound = false\n let adjustedStartPoint: EditorSelectionPoint | undefined\n let trimStartPoint = false\n let adjustedEndPoint: EditorSelectionPoint | undefined\n let trimEndPoint = false\n let previousPotentialEndpoint:\n | {blockKey: string; span: PortableTextSpan}\n | undefined\n\n for (const block of context.value) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n\n if (isPortableTextTextBlock(block) && isEmptyTextBlock(block)) {\n continue\n }\n }\n\n if (!startBlockFound) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === endBlockKey && isEmptyTextBlock(block)) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (!isPortableTextSpan(child) || endPoint.offset === 0) {\n adjustedEndPoint = previousPotentialEndpoint\n ? {\n path: [\n {_key: previousPotentialEndpoint.blockKey},\n 'children',\n {_key: previousPotentialEndpoint.span._key},\n ],\n offset: previousPotentialEndpoint.span.text.length,\n }\n : undefined\n\n trimEndPoint = true\n break\n }\n }\n\n if (trimStartPoint) {\n const lonelySpan =\n isPortableTextSpan(child) && block.children.length === 1\n\n if (\n (isPortableTextSpan(child) && child.text.length > 0) ||\n lonelySpan\n ) {\n adjustedStartPoint = {\n path: [{_key: block._key}, 'children', {_key: child._key}],\n offset: 0,\n }\n previousPotentialEndpoint = {blockKey: block._key, span: child}\n trimStartPoint = false\n }\n\n continue\n }\n\n if (child._key === startChildKey) {\n if (!isPortableTextSpan(child)) {\n trimStartPoint = true\n continue\n }\n\n if (startPoint.offset === child.text.length) {\n trimStartPoint = true\n previousPotentialEndpoint =\n child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n continue\n }\n }\n\n previousPotentialEndpoint =\n isPortableTextSpan(child) && child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n }\n\n if (block._key === endBlockKey) {\n break\n }\n }\n\n const trimmedSelection = context.selection.backward\n ? {\n anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n focus: adjustedStartPoint ?? startPoint,\n backward: true,\n }\n : {\n anchor: adjustedStartPoint ?? startPoint,\n focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n }\n\n if (\n isSelectionCollapsed({\n context: {\n ...context,\n selection: trimmedSelection,\n },\n })\n ) {\n const focusTextBlock = getFocusTextBlock({\n context: {\n ...context,\n selection: trimmedSelection,\n },\n })\n\n if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node)) {\n return null\n }\n }\n\n return trimmedSelection\n}\n"],"names":["getTrimmedSelection","context","selection","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","startBlockKey","isKeyedSegment","path","_key","startChildKey","endBlockKey","endChildKey","startBlockFound","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","block","value","isPortableTextTextBlock","isEmptyTextBlock","child","children","isPortableTextSpan","offset","blockKey","span","text","length","undefined","lonelySpan","trimmedSelection","backward","anchor","focus","is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BAAsBZ;AAAAA,IAC7BgC,UAAU;AAAA,EAAA,IAEZ;AAAA,IACEC,QAAQrB,sBAAsBZ;AAAAA,IAC9BkC,OAAOnB,gBAAgBD,mBAAmBA,mBAAmBZ;AAAAA,EAC/D;AAEJ,MACEiC,qBAAqB;AAAA,IACnBrC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHC,WAAWgC;AAAAA,IAAAA;AAAAA,EACb,CACD,GACD;AACA,UAAMK,iBAAiBC,kBAAkB;AAAA,MACvCvC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC,WAAWgC;AAAAA,MAAAA;AAAAA,IACb,CACD;AAED,QAAIK,kBAAkB,CAAChB,iBAAiBgB,eAAeE,IAAI;AAClD,aAAA;AAAA,EAAA;AAIJP,SAAAA;AACT;"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {defineBehavior, raise} from './behavior.types'
|
|
2
|
-
|
|
3
|
-
export const coreDeserializeBehaviors = {
|
|
4
|
-
'deserialize': defineBehavior({
|
|
5
|
-
on: 'deserialize',
|
|
6
|
-
guard: ({context, event}) => {
|
|
7
|
-
const deserializeEvents = context.converters.flatMap((converter) => {
|
|
8
|
-
const data = event.dataTransfer.getData(converter.mimeType)
|
|
9
|
-
|
|
10
|
-
if (!data) {
|
|
11
|
-
return []
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return [
|
|
15
|
-
converter.deserialize({context, event: {type: 'deserialize', data}}),
|
|
16
|
-
]
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const firstSuccess = deserializeEvents.find(
|
|
20
|
-
(deserializeEvent) =>
|
|
21
|
-
deserializeEvent.type === 'deserialization.success',
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
if (!firstSuccess) {
|
|
25
|
-
return {
|
|
26
|
-
type: 'deserialization.failure',
|
|
27
|
-
mimeType: '*/*',
|
|
28
|
-
reason: deserializeEvents
|
|
29
|
-
.map((deserializeEvent) =>
|
|
30
|
-
deserializeEvent.type === 'deserialization.failure'
|
|
31
|
-
? deserializeEvent.reason
|
|
32
|
-
: '',
|
|
33
|
-
)
|
|
34
|
-
.join(', '),
|
|
35
|
-
} as const
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return firstSuccess
|
|
39
|
-
},
|
|
40
|
-
actions: [
|
|
41
|
-
({event}, deserializeEvent) => [
|
|
42
|
-
raise({
|
|
43
|
-
...deserializeEvent,
|
|
44
|
-
dataTransfer: event.dataTransfer,
|
|
45
|
-
}),
|
|
46
|
-
],
|
|
47
|
-
],
|
|
48
|
-
}),
|
|
49
|
-
'deserialization.success': defineBehavior({
|
|
50
|
-
on: 'deserialization.success',
|
|
51
|
-
actions: [
|
|
52
|
-
({event}) => [
|
|
53
|
-
raise({
|
|
54
|
-
type: 'insert.blocks',
|
|
55
|
-
blocks: event.data,
|
|
56
|
-
}),
|
|
57
|
-
],
|
|
58
|
-
],
|
|
59
|
-
}),
|
|
60
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {defineBehavior, raise} from './behavior.types'
|
|
2
|
-
|
|
3
|
-
export const coreSerializeBehaviors = {
|
|
4
|
-
'serialize': defineBehavior({
|
|
5
|
-
on: 'serialize',
|
|
6
|
-
guard: ({context, event}) => {
|
|
7
|
-
if (context.converters.length === 0) {
|
|
8
|
-
return false
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const serializeEvents = context.converters.map((converter) =>
|
|
12
|
-
converter.serialize({context, event}),
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
if (serializeEvents.length === 0) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return serializeEvents
|
|
20
|
-
},
|
|
21
|
-
actions: [
|
|
22
|
-
({event}, serializeEvents) =>
|
|
23
|
-
serializeEvents.map((serializeEvent) =>
|
|
24
|
-
raise({
|
|
25
|
-
...serializeEvent,
|
|
26
|
-
dataTransfer: event.dataTransfer,
|
|
27
|
-
}),
|
|
28
|
-
),
|
|
29
|
-
],
|
|
30
|
-
}),
|
|
31
|
-
'serialization.success': defineBehavior({
|
|
32
|
-
on: 'serialization.success',
|
|
33
|
-
actions: [
|
|
34
|
-
({event}) => [
|
|
35
|
-
raise({
|
|
36
|
-
type: 'data transfer.set',
|
|
37
|
-
data: event.data,
|
|
38
|
-
dataTransfer: event.dataTransfer,
|
|
39
|
-
mimeType: event.mimeType,
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
],
|
|
43
|
-
}),
|
|
44
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as selectors from '../selectors'
|
|
2
|
-
import {defineBehavior, raise} from './behavior.types'
|
|
3
|
-
|
|
4
|
-
const toggleStyleOff = defineBehavior({
|
|
5
|
-
on: 'style.toggle',
|
|
6
|
-
guard: ({context, event}) => selectors.isActiveStyle(event.style)({context}),
|
|
7
|
-
actions: [({event}) => [raise({type: 'style.remove', style: event.style})]],
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
const toggleStyleOn = defineBehavior({
|
|
11
|
-
on: 'style.toggle',
|
|
12
|
-
guard: ({context, event}) => !selectors.isActiveStyle(event.style)({context}),
|
|
13
|
-
actions: [({event}) => [raise({type: 'style.add', style: event.style})]],
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export const coreStyleBehaviors = {
|
|
17
|
-
toggleStyleOff,
|
|
18
|
-
toggleStyleOn,
|
|
19
|
-
}
|