@portabletext/editor 6.6.4 → 7.0.1
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.ts +683 -512
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/resolve-containers.d.ts +688 -0
- package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -0
- package/lib/_chunks-es/get-ancestor.js +192 -0
- package/lib/_chunks-es/get-ancestor.js.map +1 -0
- package/lib/_chunks-es/get-first-child.js +130 -0
- package/lib/_chunks-es/get-first-child.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +266 -0
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1021 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/use-editor.js +4 -13
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +15 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +347 -198
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5457 -5611
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +18 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +18 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +220 -5
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +62 -71
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +235 -0
- package/lib/traversal/index.d.ts.map +1 -0
- package/lib/traversal/index.js +30 -0
- package/lib/traversal/index.js.map +1 -0
- package/lib/utils/index.d.ts +11 -57
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +36 -107
- package/lib/utils/index.js.map +1 -1
- package/package.json +19 -17
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +0 -806
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/util.slice-text-block.js +0 -60
- package/lib/_chunks-es/util.slice-text-block.js.map +0 -1
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { F as BlockOffset,
|
|
1
|
+
import { F as BlockOffset, Q as EditorContext, ct as EditorSelection, lt as EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
|
|
2
|
+
import { A as ChildPath, M as Path, j as KeyedSegment, k as BlockPath, n as TraversalSnapshot } from "../_chunks-dts/resolve-containers.js";
|
|
2
3
|
import * as _portabletext_schema9 from "@portabletext/schema";
|
|
3
4
|
import { PortableTextBlock, PortableTextTextBlock, isSpan, isTextBlock } from "@portabletext/schema";
|
|
4
5
|
/**
|
|
5
6
|
* @public
|
|
6
7
|
*/
|
|
7
8
|
declare function blockOffsetToSpanSelectionPoint({
|
|
8
|
-
|
|
9
|
+
snapshot,
|
|
9
10
|
blockOffset,
|
|
10
11
|
direction
|
|
11
12
|
}: {
|
|
12
|
-
|
|
13
|
+
snapshot: TraversalSnapshot;
|
|
13
14
|
blockOffset: BlockOffset;
|
|
14
15
|
direction: 'forward' | 'backward';
|
|
15
16
|
}): {
|
|
@@ -20,43 +21,21 @@ declare function blockOffsetToSpanSelectionPoint({
|
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
23
|
declare function spanSelectionPointToBlockOffset({
|
|
23
|
-
|
|
24
|
+
snapshot,
|
|
24
25
|
selectionPoint
|
|
25
26
|
}: {
|
|
26
|
-
|
|
27
|
+
snapshot: TraversalSnapshot;
|
|
27
28
|
selectionPoint: EditorSelectionPoint;
|
|
28
29
|
}): BlockOffset | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
declare function blockOffsetToBlockSelectionPoint({
|
|
33
|
-
context,
|
|
34
|
-
blockOffset
|
|
35
|
-
}: {
|
|
36
|
-
context: Pick<EditorContext, 'value'>;
|
|
37
|
-
blockOffset: BlockOffset;
|
|
38
|
-
}): EditorSelectionPoint | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
declare function blockOffsetToSelectionPoint({
|
|
43
|
-
context,
|
|
44
|
-
blockOffset,
|
|
45
|
-
direction
|
|
46
|
-
}: {
|
|
47
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
48
|
-
blockOffset: BlockOffset;
|
|
49
|
-
direction: 'forward' | 'backward';
|
|
50
|
-
}): EditorSelectionPoint | undefined;
|
|
51
30
|
/**
|
|
52
31
|
* @public
|
|
53
32
|
*/
|
|
54
33
|
declare function blockOffsetsToSelection({
|
|
55
|
-
|
|
34
|
+
snapshot,
|
|
56
35
|
offsets,
|
|
57
36
|
backward
|
|
58
37
|
}: {
|
|
59
|
-
|
|
38
|
+
snapshot: TraversalSnapshot;
|
|
60
39
|
offsets: {
|
|
61
40
|
anchor: BlockOffset;
|
|
62
41
|
focus: BlockOffset;
|
|
@@ -67,10 +46,10 @@ declare function blockOffsetsToSelection({
|
|
|
67
46
|
* @public
|
|
68
47
|
*/
|
|
69
48
|
declare function childSelectionPointToBlockOffset({
|
|
70
|
-
|
|
49
|
+
snapshot,
|
|
71
50
|
selectionPoint
|
|
72
51
|
}: {
|
|
73
|
-
|
|
52
|
+
snapshot: TraversalSnapshot;
|
|
74
53
|
selectionPoint: EditorSelectionPoint;
|
|
75
54
|
}): BlockOffset | undefined;
|
|
76
55
|
/**
|
|
@@ -151,16 +130,6 @@ declare function mergeTextBlocks({
|
|
|
151
130
|
* @public
|
|
152
131
|
*/
|
|
153
132
|
declare function reverseSelection<TEditorSelection extends NonNullable<EditorSelection> | null>(selection: TEditorSelection): TEditorSelection;
|
|
154
|
-
/**
|
|
155
|
-
* @public
|
|
156
|
-
*/
|
|
157
|
-
declare function selectionPointToBlockOffset({
|
|
158
|
-
context,
|
|
159
|
-
selectionPoint
|
|
160
|
-
}: {
|
|
161
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
162
|
-
selectionPoint: EditorSelectionPoint;
|
|
163
|
-
}): BlockOffset | undefined;
|
|
164
133
|
/**
|
|
165
134
|
* @public
|
|
166
135
|
*/
|
|
@@ -173,20 +142,5 @@ declare function sliceBlocks({
|
|
|
173
142
|
};
|
|
174
143
|
blocks: Array<PortableTextBlock>;
|
|
175
144
|
}): Array<PortableTextBlock>;
|
|
176
|
-
|
|
177
|
-
* @beta
|
|
178
|
-
*/
|
|
179
|
-
declare function splitTextBlock({
|
|
180
|
-
context,
|
|
181
|
-
block,
|
|
182
|
-
point
|
|
183
|
-
}: {
|
|
184
|
-
context: Pick<EditorContext, 'schema'>;
|
|
185
|
-
block: PortableTextTextBlock;
|
|
186
|
-
point: EditorSelectionPoint;
|
|
187
|
-
}): {
|
|
188
|
-
before: PortableTextTextBlock;
|
|
189
|
-
after: PortableTextTextBlock;
|
|
190
|
-
} | undefined;
|
|
191
|
-
export { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetToSpanSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isEmptyTextBlock, isEqualPaths, isEqualSelectionPoints, isEqualSelections, isKeyedSegment, isSelectionCollapsed, isSpan, isTextBlock, mergeTextBlocks, reverseSelection, selectionPointToBlockOffset, sliceBlocks, spanSelectionPointToBlockOffset, splitTextBlock };
|
|
145
|
+
export { blockOffsetToSpanSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isEmptyTextBlock, isEqualPaths, isEqualSelectionPoints, isEqualSelections, isKeyedSegment, isSelectionCollapsed, isSpan, isTextBlock, mergeTextBlocks, reverseSelection, sliceBlocks, spanSelectionPointToBlockOffset };
|
|
192
146
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.block-
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-paths.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.merge-text-blocks.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.slice-blocks.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;;AAEE,iBAFc,+BAAA,CAEd;EAAA,QAAA;EAAA,WAAA;EAAA;CAAA,EAAA;EACA,QAAA,EAEU,iBAFV;EAEU,WAAA,EACG,WADH;EACG,SAAA,EAAA,SAAA,GAAA,UAAA;CAac,CAAA,EAAA;EAAS,IAAA,EAAT,SAAS;EA8DtB,MAAA,EAAA,MAAA;CACd,GAAA,SAAA;;;;AAKE,iBANY,+BAAA,CAMZ;EAAA,QAAA;EAAA;AC3FJ,CD2FI,EAAA;EAAW,QAAA,EAFH,iBAEG;kBADG;AC1FlB,CAAA,CAAA,ED2FI,WC3FY,GAAA,SAAA;;;ADIhB;AACE,iBCLc,uBAAA,CDKd;EAAA,QAAA;EAAA,OAAA;EAAA;AAgFF,CAhFE,EAAA;EACA,QAAA,ECDU,iBDCV;EACA,OAAA,EAAA;I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YAAgC;;;;AbMhC,iBcLA,eAAA,CdK+B;EAAA,OAAA;EAAA,WAAA;EAAA;CAAA,EAAA;EAC7C,OAAA,EcDS,IdCT,CcDc,adCd,EAAA,cAAA,GAAA,QAAA,CAAA;EACA,WAAA,EcDa,qBdCb;EACA,aAAA,EcDe,qBdCf;CAEU,CAAA,EcFX,qBdEW,CcH0B,qBAAA,CACrC,kBAAA,GAAA,qBAAA,CAAA,gBdEW,CAAA;;;;iBeZI,0CACW,YAAY,oCAC1B,mBAAmB;;;;AfKhB,iBgBEA,WAAA,ChBFA;EAA+B,OAAA;EAAA;CAAA,EAAA;EAC7C,OAAA,EgBKS,IhBLT,CgBKc,ahBLd,EAAA,QAAA,GAAA,WAAA,CAAA,GAAA;IACA,YAAA,CAAA,EAAA,GAAA,GAAA,MAAA;EACA,CAAA;EAEU,MAAA,EgBIF,KhBJE,CgBII,iBhBJJ,CAAA;CACG,CAAA,EgBIX,KhBJW,CgBIL,iBhBJK,CAAA"}
|
package/lib/utils/index.js
CHANGED
|
@@ -1,51 +1,45 @@
|
|
|
1
|
-
import { blockOffsetToSpanSelectionPoint,
|
|
2
|
-
import { getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, isEqualPaths,
|
|
3
|
-
import {
|
|
1
|
+
import { blockOffsetToSpanSelectionPoint, getAncestorTextBlock, isEqualSelectionPoints, parseBlock } from "../_chunks-es/util.slice-blocks.js";
|
|
2
|
+
import { getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, isEqualPaths, isSelectionCollapsed, sliceBlocks, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
3
|
+
import { getNode, isKeyedSegment } from "../_chunks-es/get-ancestor.js";
|
|
4
|
+
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
4
5
|
import { isSpan as isSpan2, isTextBlock as isTextBlock2 } from "@portabletext/schema";
|
|
5
|
-
import {
|
|
6
|
-
import { getTextBlockText, isEmptyTextBlock } from "../_chunks-es/util.slice-text-block.js";
|
|
6
|
+
import { getTextBlockText, isEmptyTextBlock } from "../_chunks-es/util.is-empty-text-block.js";
|
|
7
7
|
function blockOffsetToBlockSelectionPoint({
|
|
8
|
-
|
|
8
|
+
snapshot,
|
|
9
9
|
blockOffset
|
|
10
10
|
}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}],
|
|
18
|
-
offset: blockOffset.offset
|
|
19
|
-
};
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
return selectionPoint;
|
|
11
|
+
const blockEntry = getNode(snapshot, blockOffset.path);
|
|
12
|
+
if (blockEntry)
|
|
13
|
+
return {
|
|
14
|
+
path: blockEntry.path,
|
|
15
|
+
offset: blockOffset.offset
|
|
16
|
+
};
|
|
23
17
|
}
|
|
24
18
|
function blockOffsetToSelectionPoint({
|
|
25
|
-
|
|
19
|
+
snapshot,
|
|
26
20
|
blockOffset,
|
|
27
21
|
direction
|
|
28
22
|
}) {
|
|
29
23
|
return blockOffsetToSpanSelectionPoint({
|
|
30
|
-
|
|
24
|
+
snapshot,
|
|
31
25
|
blockOffset,
|
|
32
26
|
direction
|
|
33
27
|
}) || blockOffsetToBlockSelectionPoint({
|
|
34
|
-
|
|
28
|
+
snapshot,
|
|
35
29
|
blockOffset
|
|
36
30
|
});
|
|
37
31
|
}
|
|
38
32
|
function blockOffsetsToSelection({
|
|
39
|
-
|
|
33
|
+
snapshot,
|
|
40
34
|
offsets,
|
|
41
35
|
backward
|
|
42
36
|
}) {
|
|
43
37
|
const anchor = blockOffsetToSelectionPoint({
|
|
44
|
-
|
|
38
|
+
snapshot,
|
|
45
39
|
blockOffset: offsets.anchor,
|
|
46
40
|
direction: backward ? "backward" : "forward"
|
|
47
41
|
}), focus = blockOffsetToSelectionPoint({
|
|
48
|
-
|
|
42
|
+
snapshot,
|
|
49
43
|
blockOffset: offsets.focus,
|
|
50
44
|
direction: backward ? "forward" : "backward"
|
|
51
45
|
});
|
|
@@ -56,24 +50,23 @@ function blockOffsetsToSelection({
|
|
|
56
50
|
};
|
|
57
51
|
}
|
|
58
52
|
function childSelectionPointToBlockOffset({
|
|
59
|
-
|
|
53
|
+
snapshot,
|
|
60
54
|
selectionPoint
|
|
61
55
|
}) {
|
|
56
|
+
const childSegment = selectionPoint.path.at(-1);
|
|
57
|
+
if (!isKeyedSegment(childSegment))
|
|
58
|
+
return;
|
|
59
|
+
const textBlock = getAncestorTextBlock(snapshot, selectionPoint.path);
|
|
60
|
+
if (!textBlock)
|
|
61
|
+
return;
|
|
62
62
|
let offset = 0;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
path: [{
|
|
71
|
-
_key: block._key
|
|
72
|
-
}],
|
|
73
|
-
offset: offset + selectionPoint.offset
|
|
74
|
-
};
|
|
75
|
-
isSpan(context, child) && (offset += child.text.length);
|
|
76
|
-
}
|
|
63
|
+
for (const child of textBlock.node.children) {
|
|
64
|
+
if (child._key === childSegment._key)
|
|
65
|
+
return {
|
|
66
|
+
path: textBlock.path,
|
|
67
|
+
offset: offset + selectionPoint.offset
|
|
68
|
+
};
|
|
69
|
+
isSpan(snapshot.context, child) && (offset += child.text.length);
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
72
|
function isEqualSelections(a, b) {
|
|
@@ -85,13 +78,14 @@ function mergeTextBlocks({
|
|
|
85
78
|
incomingBlock
|
|
86
79
|
}) {
|
|
87
80
|
const parsedIncomingBlock = parseBlock({
|
|
88
|
-
context,
|
|
81
|
+
keyGenerator: context.keyGenerator,
|
|
89
82
|
block: incomingBlock,
|
|
90
83
|
options: {
|
|
91
84
|
normalize: !1,
|
|
92
85
|
removeUnusedMarkDefs: !0,
|
|
93
86
|
validateFields: !1
|
|
94
|
-
}
|
|
87
|
+
},
|
|
88
|
+
schema: context.schema
|
|
95
89
|
});
|
|
96
90
|
return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
|
|
97
91
|
...targetBlock,
|
|
@@ -110,70 +104,7 @@ function reverseSelection(selection) {
|
|
|
110
104
|
backward: !0
|
|
111
105
|
});
|
|
112
106
|
}
|
|
113
|
-
function selectionPointToBlockOffset({
|
|
114
|
-
context,
|
|
115
|
-
selectionPoint
|
|
116
|
-
}) {
|
|
117
|
-
const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
|
|
118
|
-
return selectionPoint.path.length === 1 && blockKey !== void 0 ? {
|
|
119
|
-
path: [{
|
|
120
|
-
_key: blockKey
|
|
121
|
-
}],
|
|
122
|
-
offset: selectionPoint.offset
|
|
123
|
-
} : childSelectionPointToBlockOffset({
|
|
124
|
-
context,
|
|
125
|
-
selectionPoint
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function splitTextBlock({
|
|
129
|
-
context,
|
|
130
|
-
block,
|
|
131
|
-
point
|
|
132
|
-
}) {
|
|
133
|
-
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
|
|
134
|
-
if (!firstChild || !lastChild)
|
|
135
|
-
return;
|
|
136
|
-
const before = sliceTextBlock({
|
|
137
|
-
context: {
|
|
138
|
-
schema: context.schema,
|
|
139
|
-
selection: {
|
|
140
|
-
anchor: {
|
|
141
|
-
path: [{
|
|
142
|
-
_key: block._key
|
|
143
|
-
}, "children", {
|
|
144
|
-
_key: firstChild._key
|
|
145
|
-
}],
|
|
146
|
-
offset: 0
|
|
147
|
-
},
|
|
148
|
-
focus: point
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
block
|
|
152
|
-
}), after = sliceTextBlock({
|
|
153
|
-
context: {
|
|
154
|
-
schema: context.schema,
|
|
155
|
-
selection: {
|
|
156
|
-
anchor: point,
|
|
157
|
-
focus: {
|
|
158
|
-
path: [{
|
|
159
|
-
_key: block._key
|
|
160
|
-
}, "children", {
|
|
161
|
-
_key: lastChild._key
|
|
162
|
-
}],
|
|
163
|
-
offset: isSpan(context, lastChild) ? lastChild.text.length : 0
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
block
|
|
168
|
-
});
|
|
169
|
-
return {
|
|
170
|
-
before,
|
|
171
|
-
after
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
107
|
export {
|
|
175
|
-
blockOffsetToBlockSelectionPoint,
|
|
176
|
-
blockOffsetToSelectionPoint,
|
|
177
108
|
blockOffsetToSpanSelectionPoint,
|
|
178
109
|
blockOffsetsToSelection,
|
|
179
110
|
childSelectionPointToBlockOffset,
|
|
@@ -192,9 +123,7 @@ export {
|
|
|
192
123
|
isTextBlock2 as isTextBlock,
|
|
193
124
|
mergeTextBlocks,
|
|
194
125
|
reverseSelection,
|
|
195
|
-
selectionPointToBlockOffset,
|
|
196
126
|
sliceBlocks,
|
|
197
|
-
spanSelectionPointToBlockOffset
|
|
198
|
-
splitTextBlock
|
|
127
|
+
spanSelectionPointToBlockOffset
|
|
199
128
|
};
|
|
200
129
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.merge-text-blocks.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n}: {\n context: Pick<EditorContext, 'value'>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of context.value) {\n if (block._key === blockOffset.path[0]._key) {\n selectionPoint = {\n path: [{_key: block._key}],\n offset: blockOffset.offset,\n }\n break\n }\n }\n\n return selectionPoint\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n context,\n offsets,\n backward,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const childKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isSpan(context, child)) {\n offset += child.text.length\n }\n }\n }\n\n return undefined\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {parseBlock} from './parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {\n normalize: false,\n removeUnusedMarkDefs: true,\n validateFields: false,\n },\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","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, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {sliceTextBlock} from './util.slice-text-block'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["blockOffsetToBlockSelectionPoint","context","blockOffset","selectionPoint","block","value","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","childKey","getChildKeyFromSelectionPoint","isTextBlock","child","children","isSpan","text","length","isEqualSelections","a","b","isEqualSelectionPoints","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","normalize","removeUnusedMarkDefs","validateFields","markDefs","reverseSelection","selection","selectionPointToBlockOffset","undefined","splitTextBlock","point","firstChild","at","lastChild","before","sliceTextBlock","schema","after"],"mappings":";;;;;;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AACnC,MAAIC;AAEJ,aAAWC,SAASH,QAAQI;AAC1B,QAAID,MAAME,SAASJ,YAAYK,KAAK,CAAC,EAAED,MAAM;AAC3CH,uBAAiB;AAAA,QACfI,MAAM,CAAC;AAAA,UAACD,MAAMF,MAAME;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQN,YAAYM;AAAAA,MAAAA;AAEtB;AAAA,IACF;AAGF,SAAOL;AACT;AClBO,SAASM,4BAA4B;AAAA,EAC1CR;AAAAA,EACAC;AAAAA,EACAQ;AAKF,GAAqC;AAOnC,SAN2BC,gCAAgC;AAAA,IACzDV;AAAAA,IACAC;AAAAA,IACAQ;AAAAA,EAAAA,CACD,KAGQV,iCAAiC;AAAA,IACtCC;AAAAA,IAC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AAMoB,SAASyB,GAAG7C,MAAMoB,SAASG,SAAS,CAAC;AAE7D,MAAI,CAACqB,cAAc,CAACE;AAClB;AAGF,QAAMC,SAASC,eAAe;AAAA,IAC5BnD,SAAS;AAAA,MACPoD,QAAQpD,QAAQoD;AAAAA,MAChBV,WAAW;AAAA,QACT5B,QAAQ;AAAA,UACNR,MAAM,CAAC;AAAA,YAACD,MAAMF,MAAME;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAM0C,WAAW1C;AAAAA,UAAAA,CAAK;AAAA,UAC9DE,QAAQ;AAAA,QAAA;AAAA,QAEVQ,OAAO+B;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEF3C;AAAAA,EAAAA,CACD,GACKkD,QAAQF,eAAe;AAAA,IAC3BnD,SAAS;AAAA,MACPoD,QAAQpD,QAAQoD;AAAAA,MAChBV,WAAW;AAAA,QACT5B,QAAQgC;AAAAA,QACR/B,OAAO;AAAA,UACLT,MAAM,CAAC;AAAA,YAACD,MAAMF,MAAME;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAM4C,UAAU5C;AAAAA,UAAAA,CAAK;AAAA,UAC7DE,QAAQiB,OAAOxB,SAASiD,SAAS,IAAIA,UAAUxB,KAAKC,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFvB;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAAC+C;AAAAA,IAAQG;AAAAA,EAAAA;AAClB;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.merge-text-blocks.ts","../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import {getNode} from '../node-traversal/get-node'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\nexport function blockOffsetToBlockSelectionPoint({\n snapshot,\n blockOffset,\n}: {\n snapshot: TraversalSnapshot\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n const blockEntry = getNode(snapshot, blockOffset.path)\n\n if (!blockEntry) {\n return undefined\n }\n\n return {\n path: blockEntry.path,\n offset: blockOffset.offset,\n }\n}\n","import type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\nexport function blockOffsetToSelectionPoint({\n snapshot,\n blockOffset,\n direction,\n}: {\n snapshot: TraversalSnapshot\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n snapshot,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n snapshot,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n snapshot,\n offsets,\n backward,\n}: {\n snapshot: TraversalSnapshot\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n snapshot,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n snapshot,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {isSpan} from '@portabletext/schema'\nimport {getAncestorTextBlock} from '../node-traversal/get-ancestor-text-block'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n snapshot,\n selectionPoint,\n}: {\n snapshot: TraversalSnapshot\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const childSegment = selectionPoint.path.at(-1)\n\n if (!isKeyedSegment(childSegment)) {\n return undefined\n }\n\n const textBlock = getAncestorTextBlock(snapshot, selectionPoint.path)\n\n if (!textBlock) {\n return undefined\n }\n\n let offset = 0\n\n for (const child of textBlock.node.children) {\n if (child._key === childSegment._key) {\n return {\n path: textBlock.path,\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isSpan(snapshot.context, child)) {\n offset += child.text.length\n }\n }\n\n return undefined\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {parseBlock} from './parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n keyGenerator: context.keyGenerator,\n block: incomingBlock,\n options: {\n normalize: false,\n removeUnusedMarkDefs: true,\n validateFields: false,\n },\n schema: context.schema,\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n"],"names":["blockOffsetToBlockSelectionPoint","snapshot","blockOffset","blockEntry","getNode","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","selectionPoint","childSegment","at","isKeyedSegment","textBlock","getAncestorTextBlock","child","node","children","_key","isSpan","context","text","length","isEqualSelections","a","b","isEqualSelectionPoints","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","keyGenerator","block","options","normalize","removeUnusedMarkDefs","validateFields","schema","isTextBlock","markDefs","reverseSelection","selection"],"mappings":";;;;;;AAKO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AACnC,QAAMC,aAAaC,QAAQH,UAAUC,YAAYG,IAAI;AAErD,MAAKF;AAIL,WAAO;AAAA,MACLE,MAAMF,WAAWE;AAAAA,MACjBC,QAAQJ,YAAYI;AAAAA,IAAAA;AAExB;AChBO,SAASC,4BAA4B;AAAA,EAC1CN;AAAAA,EACAC;AAAAA,EACAM;AAKF,GAAqC;AAOnC,SAN2BC,gCAAgC;AAAA,IACzDR;AAAAA,IACAC;AAAAA,IACAM;AAAAA,EAAAA,CAC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AQ;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrCC,cAAcZ,QAAQY;AAAAA,IACtBC,OAAOJ;AAAAA,IACPK,SAAS;AAAA,MACPC,WAAW;AAAA,MACXC,sBAAsB;AAAA,MACtBC,gBAAgB;AAAA,IAAA;AAAA,IAElBC,QAAQlB,QAAQkB;AAAAA,EAAAA,CACjB;AAED,SAAI,CAACR,uBAAuB,CAACS,YAAYnB,SAASU,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHX,UAAU,CAAC,GAAGW,YAAYX,UAAU,GAAGa,oBAAoBb,QAAQ;AAAA,IACnEuB,UAAU,CACR,GAAIZ,YAAYY,YAAY,CAAA,GAC5B,GAAIV,oBAAoBU,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;AClCO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUrC,WACL;AAAA,IACLC,QAAQoC,UAAUnC;AAAAA,IAClBA,OAAOmC,UAAUpC;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQoC,UAAUnC;AAAAA,IAClBA,OAAOmC,UAAUpC;AAAAA,IACjBD,UAAU;AAAA,EAAA;AAEd;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"./selectors": "./lib/selectors/index.js",
|
|
34
34
|
"./test": "./src/test/_exports/index.ts",
|
|
35
35
|
"./test/vitest": "./src/test/vitest/_exports/index.ts",
|
|
36
|
+
"./traversal": "./lib/traversal/index.js",
|
|
36
37
|
"./utils": "./lib/utils/index.js",
|
|
37
38
|
"./package.json": "./package.json"
|
|
38
39
|
},
|
|
@@ -46,42 +47,43 @@
|
|
|
46
47
|
"@xstate/react": "^6.1.0",
|
|
47
48
|
"debug": "^4.4.3",
|
|
48
49
|
"scroll-into-view-if-needed": "^3.1.0",
|
|
49
|
-
"xstate": "^5.
|
|
50
|
-
"@portabletext/html": "^1.0.
|
|
50
|
+
"xstate": "^5.31.1",
|
|
51
|
+
"@portabletext/html": "^1.0.2",
|
|
51
52
|
"@portabletext/keyboard-shortcuts": "^2.1.2",
|
|
52
|
-
"@portabletext/markdown": "^1.
|
|
53
|
+
"@portabletext/markdown": "^1.3.0",
|
|
53
54
|
"@portabletext/patches": "^2.0.4",
|
|
54
|
-
"@portabletext/schema": "^2.
|
|
55
|
+
"@portabletext/schema": "^2.2.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
58
59
|
"@sanity/pkg-utils": "^10.2.1",
|
|
59
60
|
"@sanity/tsconfig": "^2.1.0",
|
|
61
|
+
"@textspec/notation": "^1.0.1",
|
|
60
62
|
"@types/debug": "^4.1.12",
|
|
61
63
|
"@types/node": "^20",
|
|
62
|
-
"@types/react": "^19.2.
|
|
64
|
+
"@types/react": "^19.2.14",
|
|
63
65
|
"@types/react-dom": "^19.2.3",
|
|
64
|
-
"@vitejs/plugin-react": "^5.
|
|
65
|
-
"@vitest/browser": "^4.1.
|
|
66
|
-
"@vitest/browser-playwright": "^4.1.
|
|
67
|
-
"@vitest/coverage-istanbul": "^4.1.
|
|
66
|
+
"@vitejs/plugin-react": "^5.2.0",
|
|
67
|
+
"@vitest/browser": "^4.1.4",
|
|
68
|
+
"@vitest/browser-playwright": "^4.1.4",
|
|
69
|
+
"@vitest/coverage-istanbul": "^4.1.4",
|
|
68
70
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
69
71
|
"eslint": "^9.39.1",
|
|
70
72
|
"eslint-formatter-gha": "^1.6.0",
|
|
71
|
-
"eslint-plugin-react-hooks": "^7.
|
|
73
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
72
74
|
"jsdom": "^27.0.0",
|
|
73
|
-
"react": "^19.2.
|
|
74
|
-
"react-dom": "^19.2.
|
|
75
|
+
"react": "^19.2.5",
|
|
76
|
+
"react-dom": "^19.2.5",
|
|
75
77
|
"typescript": "5.9.3",
|
|
76
78
|
"typescript-eslint": "^8.48.0",
|
|
77
79
|
"vite": "^7.3.1",
|
|
78
|
-
"vitest": "^4.1.
|
|
79
|
-
"vitest-browser-react": "^2.
|
|
80
|
+
"vitest": "^4.1.4",
|
|
81
|
+
"vitest-browser-react": "^2.2.0",
|
|
80
82
|
"@portabletext/test": "^1.0.3",
|
|
81
|
-
"racejar": "2.0.
|
|
83
|
+
"racejar": "2.0.6"
|
|
82
84
|
},
|
|
83
85
|
"peerDependencies": {
|
|
84
|
-
"react": "^19.2.
|
|
86
|
+
"react": "^19.2.5"
|
|
85
87
|
},
|
|
86
88
|
"engines": {
|
|
87
89
|
"node": ">=20.19 <22 || >=22.12"
|