@portabletext/editor 3.3.12 → 3.3.14
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/index.d.ts +20 -3
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +40 -21
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/index.js +8375 -8466
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.js +12 -30
- package/lib/selectors/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _portabletext_schema12 from "@portabletext/schema";
|
|
2
2
|
import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, TypedObject, defineSchema } from "@portabletext/schema";
|
|
3
|
-
import { BaseRange, Descendant, Operation } from "slate";
|
|
3
|
+
import { BaseRange, Descendant, Operation, Range } from "slate";
|
|
4
4
|
import * as xstate228 from "xstate";
|
|
5
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
6
6
|
import * as react18 from "react";
|
|
@@ -126,19 +126,36 @@ interface History {
|
|
|
126
126
|
redos: HistoryItem[];
|
|
127
127
|
undos: HistoryItem[];
|
|
128
128
|
}
|
|
129
|
+
type RemotePatch = {
|
|
130
|
+
patch: Patch;
|
|
131
|
+
time: Date;
|
|
132
|
+
snapshot: PortableTextBlock[] | undefined;
|
|
133
|
+
previousSnapshot: PortableTextBlock[] | undefined;
|
|
134
|
+
};
|
|
129
135
|
interface PortableTextSlateEditor extends ReactEditor {
|
|
130
136
|
_key: 'editor';
|
|
131
137
|
_type: 'editor';
|
|
132
138
|
createPlaceholderBlock: () => Descendant;
|
|
133
|
-
history: History;
|
|
134
139
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock;
|
|
135
140
|
isTextSpan: (value: unknown) => value is PortableTextSpan;
|
|
136
141
|
isListBlock: (value: unknown) => value is PortableTextListBlock;
|
|
137
|
-
value: Array<PortableTextBlock>;
|
|
138
142
|
decoratedRanges: Array<DecoratedRange>;
|
|
139
143
|
decoratorState: Record<string, boolean | undefined>;
|
|
140
144
|
blockIndexMap: Map<string, number>;
|
|
145
|
+
history: History;
|
|
146
|
+
lastSelection: EditorSelection;
|
|
147
|
+
lastSlateSelection: Range | null;
|
|
141
148
|
listIndexMap: Map<string, number>;
|
|
149
|
+
remotePatches: Array<RemotePatch>;
|
|
150
|
+
undoStepId: string | undefined;
|
|
151
|
+
value: Array<PortableTextBlock>;
|
|
152
|
+
isNormalizingNode: boolean;
|
|
153
|
+
isPatching: boolean;
|
|
154
|
+
isPerformingBehaviorOperation: boolean;
|
|
155
|
+
isProcessingRemoteChanges: boolean;
|
|
156
|
+
isRedoing: boolean;
|
|
157
|
+
isUndoing: boolean;
|
|
158
|
+
withHistory: boolean;
|
|
142
159
|
/**
|
|
143
160
|
* Use hotkeys
|
|
144
161
|
*/
|
|
@@ -545,6 +545,10 @@ const getNextSpan = (snapshot) => {
|
|
|
545
545
|
marks
|
|
546
546
|
};
|
|
547
547
|
};
|
|
548
|
+
function getActiveAnnotationsMarks(snapshot) {
|
|
549
|
+
const schema = snapshot.context.schema;
|
|
550
|
+
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
551
|
+
}
|
|
548
552
|
function getActiveDecorators(snapshot) {
|
|
549
553
|
const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
|
|
550
554
|
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
@@ -552,6 +556,14 @@ function getActiveDecorators(snapshot) {
|
|
|
552
556
|
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
553
557
|
return activeDecorators;
|
|
554
558
|
}
|
|
559
|
+
function isActiveAnnotation(annotation, options) {
|
|
560
|
+
return (snapshot) => {
|
|
561
|
+
if ((options?.mode ?? "full") === "partial")
|
|
562
|
+
return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
563
|
+
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
564
|
+
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
555
567
|
const getActiveAnnotations = (snapshot) => {
|
|
556
568
|
if (!snapshot.context.selection)
|
|
557
569
|
return [];
|
|
@@ -681,14 +693,6 @@ const getActiveAnnotations = (snapshot) => {
|
|
|
681
693
|
selection: caretWordSelection
|
|
682
694
|
}
|
|
683
695
|
}) ? caretWordSelection : null;
|
|
684
|
-
}, getFirstBlock = (snapshot) => {
|
|
685
|
-
const node = snapshot.context.value[0];
|
|
686
|
-
return node ? {
|
|
687
|
-
node,
|
|
688
|
-
path: [{
|
|
689
|
-
_key: node._key
|
|
690
|
-
}]
|
|
691
|
-
} : void 0;
|
|
692
696
|
}, getFocusBlockObject = (snapshot) => {
|
|
693
697
|
const focusBlock = getFocusBlock(snapshot);
|
|
694
698
|
return focusBlock && !isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
@@ -775,19 +779,33 @@ const getActiveAnnotations = (snapshot) => {
|
|
|
775
779
|
});
|
|
776
780
|
}
|
|
777
781
|
return selectedTextBlocks;
|
|
782
|
+
}, getSelectionEndChild = (snapshot) => {
|
|
783
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
784
|
+
if (endPoint)
|
|
785
|
+
return getFocusChild({
|
|
786
|
+
...snapshot,
|
|
787
|
+
context: {
|
|
788
|
+
...snapshot.context,
|
|
789
|
+
selection: {
|
|
790
|
+
anchor: endPoint,
|
|
791
|
+
focus: endPoint
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}, getSelectionStartChild = (snapshot) => {
|
|
796
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
797
|
+
if (startPoint)
|
|
798
|
+
return getFocusChild({
|
|
799
|
+
...snapshot,
|
|
800
|
+
context: {
|
|
801
|
+
...snapshot.context,
|
|
802
|
+
selection: {
|
|
803
|
+
anchor: startPoint,
|
|
804
|
+
focus: startPoint
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
});
|
|
778
808
|
};
|
|
779
|
-
function getActiveAnnotationsMarks(snapshot) {
|
|
780
|
-
const schema = snapshot.context.schema;
|
|
781
|
-
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
782
|
-
}
|
|
783
|
-
function isActiveAnnotation(annotation, options) {
|
|
784
|
-
return (snapshot) => {
|
|
785
|
-
if ((options?.mode ?? "full") === "partial")
|
|
786
|
-
return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
787
|
-
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
788
|
-
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
809
|
function isActiveDecorator(decorator) {
|
|
792
810
|
return (snapshot) => {
|
|
793
811
|
if (isSelectionExpanded$1(snapshot)) {
|
|
@@ -832,7 +850,6 @@ export {
|
|
|
832
850
|
getActiveListItem,
|
|
833
851
|
getActiveStyle,
|
|
834
852
|
getCaretWordSelection,
|
|
835
|
-
getFirstBlock,
|
|
836
853
|
getFocusBlock,
|
|
837
854
|
getFocusBlockObject,
|
|
838
855
|
getFocusChild,
|
|
@@ -853,8 +870,10 @@ export {
|
|
|
853
870
|
getSelectedTextBlocks,
|
|
854
871
|
getSelectedValue,
|
|
855
872
|
getSelectionEndBlock,
|
|
873
|
+
getSelectionEndChild,
|
|
856
874
|
getSelectionEndPoint,
|
|
857
875
|
getSelectionStartBlock,
|
|
876
|
+
getSelectionStartChild,
|
|
858
877
|
getSelectionStartPoint,
|
|
859
878
|
getSelectionText,
|
|
860
879
|
isActiveAnnotation,
|