@portabletext/editor 2.0.0 → 2.1.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 +9 -9
- package/lib/index.cjs +22 -7
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +22 -7
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/package.json +8 -8
- package/src/behaviors/behavior.core.lists.ts +22 -9
- package/src/editor/__tests__/RangeDecorations.test.tsx +60 -0
- package/src/editor/range-decorations-machine.ts +2 -0
- package/src/utils/util.at-the-beginning-of-block.ts +32 -0
|
@@ -4,7 +4,7 @@ import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDe
|
|
|
4
4
|
import * as xstate227 from "xstate";
|
|
5
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
6
6
|
import { BaseRange, Descendant, Operation } from "slate";
|
|
7
|
-
import * as
|
|
7
|
+
import * as react22 from "react";
|
|
8
8
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
9
9
|
import * as xstate_guards12 from "xstate/guards";
|
|
10
10
|
import { Observable, Subject } from "rxjs";
|
|
@@ -352,7 +352,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
|
|
|
352
352
|
componentDidUpdate(prevProps: PortableTextEditorProps): void;
|
|
353
353
|
componentWillUnmount(): void;
|
|
354
354
|
setEditable: (editable: EditableAPI) => void;
|
|
355
|
-
render():
|
|
355
|
+
render(): react22.JSX.Element;
|
|
356
356
|
/**
|
|
357
357
|
* @deprecated
|
|
358
358
|
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
@@ -747,7 +747,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
747
747
|
* ```
|
|
748
748
|
* @group Components
|
|
749
749
|
*/
|
|
750
|
-
declare const PortableTextEditable:
|
|
750
|
+
declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
751
751
|
type DecoratedRange = BaseRange & {
|
|
752
752
|
rangeDecoration: RangeDecoration;
|
|
753
753
|
};
|
|
@@ -1476,7 +1476,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1476
1476
|
initialValue?: Array<PortableTextBlock>;
|
|
1477
1477
|
}, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1478
1478
|
type: "blurred";
|
|
1479
|
-
event:
|
|
1479
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
1480
1480
|
} | {
|
|
1481
1481
|
type: "done loading";
|
|
1482
1482
|
} | {
|
|
@@ -1488,7 +1488,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1488
1488
|
data: unknown;
|
|
1489
1489
|
} | {
|
|
1490
1490
|
type: "focused";
|
|
1491
|
-
event:
|
|
1491
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
1492
1492
|
} | {
|
|
1493
1493
|
type: "invalid value";
|
|
1494
1494
|
resolution: InvalidValueResolution | null;
|
|
@@ -2135,7 +2135,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2135
2135
|
type: "drop";
|
|
2136
2136
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2137
2137
|
type: "blurred";
|
|
2138
|
-
event:
|
|
2138
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2139
2139
|
} | {
|
|
2140
2140
|
type: "done loading";
|
|
2141
2141
|
} | {
|
|
@@ -2147,7 +2147,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2147
2147
|
data: unknown;
|
|
2148
2148
|
} | {
|
|
2149
2149
|
type: "focused";
|
|
2150
|
-
event:
|
|
2150
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2151
2151
|
} | {
|
|
2152
2152
|
type: "invalid value";
|
|
2153
2153
|
resolution: InvalidValueResolution | null;
|
|
@@ -3018,7 +3018,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
3018
3018
|
type: "drop";
|
|
3019
3019
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
3020
3020
|
type: "blurred";
|
|
3021
|
-
event:
|
|
3021
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
3022
3022
|
} | {
|
|
3023
3023
|
type: "done loading";
|
|
3024
3024
|
} | {
|
|
@@ -3030,7 +3030,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
3030
3030
|
data: unknown;
|
|
3031
3031
|
} | {
|
|
3032
3032
|
type: "focused";
|
|
3033
|
-
event:
|
|
3033
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
3034
3034
|
} | {
|
|
3035
3035
|
type: "invalid value";
|
|
3036
3036
|
resolution: InvalidValueResolution | null;
|
package/lib/index.cjs
CHANGED
|
@@ -6075,15 +6075,25 @@ const coreDndBehaviors = [
|
|
|
6075
6075
|
breakingEntireDocument,
|
|
6076
6076
|
breakingEntireBlocks,
|
|
6077
6077
|
breakingInlineObject
|
|
6078
|
-
}
|
|
6078
|
+
};
|
|
6079
|
+
function isAtTheBeginningOfBlock({
|
|
6080
|
+
context,
|
|
6081
|
+
block
|
|
6082
|
+
}) {
|
|
6083
|
+
return !util_sliceBlocks.isTextBlock(context, block) || !context.selection || !util_isSelectionCollapsed.isSelectionCollapsed(context.selection) ? !1 : util_sliceBlocks.getChildKeyFromSelectionPoint(context.selection.focus) === block.children[0]._key && context.selection.focus.offset === 0;
|
|
6084
|
+
}
|
|
6085
|
+
const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior({
|
|
6079
6086
|
on: "delete.backward",
|
|
6080
6087
|
guard: ({
|
|
6081
6088
|
snapshot
|
|
6082
6089
|
}) => {
|
|
6083
|
-
const
|
|
6084
|
-
return !
|
|
6090
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
6091
|
+
return !focusTextBlock || focusTextBlock.node.level !== 1 || !isAtTheBeginningOfBlock({
|
|
6092
|
+
context: snapshot.context,
|
|
6093
|
+
block: focusTextBlock.node
|
|
6094
|
+
}) ? !1 : {
|
|
6085
6095
|
focusTextBlock
|
|
6086
|
-
}
|
|
6096
|
+
};
|
|
6087
6097
|
},
|
|
6088
6098
|
actions: [(_, {
|
|
6089
6099
|
focusTextBlock
|
|
@@ -6141,7 +6151,10 @@ const coreDndBehaviors = [
|
|
|
6141
6151
|
snapshot
|
|
6142
6152
|
}) => {
|
|
6143
6153
|
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
6144
|
-
if (!focusTextBlock || !previousBlock || !
|
|
6154
|
+
if (!focusTextBlock || !previousBlock || !isAtTheBeginningOfBlock({
|
|
6155
|
+
context: snapshot.context,
|
|
6156
|
+
block: focusTextBlock.node
|
|
6157
|
+
}) || !util_sliceBlocks.isListBlock(snapshot.context, previousBlock.node) || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, previousBlock.node))
|
|
6145
6158
|
return !1;
|
|
6146
6159
|
const previousBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
6147
6160
|
context: snapshot.context,
|
|
@@ -11041,10 +11054,12 @@ const slateOperationCallback = ({
|
|
|
11041
11054
|
return !1;
|
|
11042
11055
|
const existingRangeDecorations = context.slateEditor.decoratedRanges.map((decoratedRange) => ({
|
|
11043
11056
|
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
11044
|
-
focus: decoratedRange.rangeDecoration.selection?.focus
|
|
11057
|
+
focus: decoratedRange.rangeDecoration.selection?.focus,
|
|
11058
|
+
payload: decoratedRange.rangeDecoration.payload
|
|
11045
11059
|
})), newRangeDecorations = event.rangeDecorations.map((rangeDecoration) => ({
|
|
11046
11060
|
anchor: rangeDecoration.selection?.anchor,
|
|
11047
|
-
focus: rangeDecoration.selection?.focus
|
|
11061
|
+
focus: rangeDecoration.selection?.focus,
|
|
11062
|
+
payload: rangeDecoration.payload
|
|
11048
11063
|
}));
|
|
11049
11064
|
return !isEqual__default.default(existingRangeDecorations, newRangeDecorations);
|
|
11050
11065
|
},
|