@portabletext/editor 2.17.2 → 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.ts → index.d.ts} +9 -9
- 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 +1 -1
- package/package.json +14 -25
- package/src/test/vitest/step-definitions.tsx +2 -0
- package/src/test/vitest/test-editor.tsx +18 -4
- 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 -473
- 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.cts +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
|
@@ -17,10 +17,10 @@ type MIMEType = `${string}/${string}`;
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
type PickFromUnion<TUnion, TTagKey extends keyof TUnion, TPickedTags extends TUnion[TTagKey]> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never;
|
|
20
|
-
type NamespaceEvent<TEvent, TNamespace extends string> = TEvent extends {
|
|
20
|
+
type NamespaceEvent<TEvent, TNamespace$1 extends string> = TEvent extends {
|
|
21
21
|
type: infer TEventType;
|
|
22
|
-
} ? { [K in keyof TEvent]: K extends 'type' ? `${TNamespace}.${TEventType & string}` : TEvent[K] } : never;
|
|
23
|
-
type StrictExtract<T, U extends T> = U;
|
|
22
|
+
} ? { [K in keyof TEvent]: K extends 'type' ? `${TNamespace$1}.${TEventType & string}` : TEvent[K] } : never;
|
|
23
|
+
type StrictExtract<T$1, U extends T$1> = U;
|
|
24
24
|
type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
25
25
|
mimeType: TMIMEType;
|
|
26
26
|
serialize: Serializer<TMIMEType>;
|
|
@@ -3189,12 +3189,12 @@ type EventPosition = {
|
|
|
3189
3189
|
*/
|
|
3190
3190
|
type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent | CustomBehaviorEvent;
|
|
3191
3191
|
type BehaviorEventTypeNamespace = SyntheticBehaviorEventNamespace | NativeBehaviorEventNamespace | CustomBehaviorEventNamespace;
|
|
3192
|
-
type NamespacedBehaviorEventType<TNamespace extends BehaviorEventTypeNamespace | ''> = TNamespace extends '' ? BehaviorEvent['type'] : Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>;
|
|
3192
|
+
type NamespacedBehaviorEventType<TNamespace$1 extends BehaviorEventTypeNamespace | ''> = TNamespace$1 extends '' ? BehaviorEvent['type'] : Extract<BehaviorEvent['type'], TNamespace$1 | `${TNamespace$1}.${string}`>;
|
|
3193
3193
|
/**************************************
|
|
3194
3194
|
* External events
|
|
3195
3195
|
**************************************/
|
|
3196
3196
|
type ExternalBehaviorEventNamespace = 'blur' | 'focus' | 'insert';
|
|
3197
|
-
type ExternalBehaviorEventType<TNamespace extends ExternalBehaviorEventNamespace, TType extends string = ''> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`;
|
|
3197
|
+
type ExternalBehaviorEventType<TNamespace$1 extends ExternalBehaviorEventNamespace, TType$1 extends string = ''> = TType$1 extends '' ? `${TNamespace$1}` : `${TNamespace$1}.${TType$1}`;
|
|
3198
3198
|
type ExternalBehaviorEvent = {
|
|
3199
3199
|
type: ExternalBehaviorEventType<'blur'>;
|
|
3200
3200
|
} | {
|
|
@@ -3548,18 +3548,18 @@ type MouseBehaviorEvent = {
|
|
|
3548
3548
|
* Custom events
|
|
3549
3549
|
**************************************/
|
|
3550
3550
|
type CustomBehaviorEventNamespace = 'custom';
|
|
3551
|
-
type CustomBehaviorEventType<TNamespace extends CustomBehaviorEventNamespace, TType extends string = ''> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`;
|
|
3551
|
+
type CustomBehaviorEventType<TNamespace$1 extends CustomBehaviorEventNamespace, TType$1 extends string = ''> = TType$1 extends '' ? `${TNamespace$1}` : `${TNamespace$1}.${TType$1}`;
|
|
3552
3552
|
/**
|
|
3553
3553
|
* @beta
|
|
3554
3554
|
*/
|
|
3555
|
-
type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<string, unknown>, TType extends string = string, TInternalType extends CustomBehaviorEventType<'custom', TType> = CustomBehaviorEventType<'custom', TType>> = {
|
|
3555
|
+
type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<string, unknown>, TType$1 extends string = string, TInternalType extends CustomBehaviorEventType<'custom', TType$1> = CustomBehaviorEventType<'custom', TType$1>> = {
|
|
3556
3556
|
type: TInternalType;
|
|
3557
3557
|
} & TPayload;
|
|
3558
3558
|
/**************************************
|
|
3559
3559
|
* Resolve behavior event
|
|
3560
3560
|
**************************************/
|
|
3561
3561
|
type ResolveBehaviorEvent<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TPayload extends Record<string, unknown> = Record<string, unknown>> = TBehaviorEventType extends '*' ? BehaviorEvent : TBehaviorEventType extends `${infer TNamespace}.*` ? TNamespace extends BehaviorEventTypeNamespace ? PickFromUnion<BehaviorEvent, 'type', NamespacedBehaviorEventType<TNamespace>> : never : TBehaviorEventType extends `custom.${infer TType}` ? CustomBehaviorEvent<TPayload, TType> : TBehaviorEventType extends BehaviorEvent['type'] ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType> : never;
|
|
3562
|
-
type ExtractNamespace<TType extends string> = TType extends `${infer Namespace}.${string}` ? Namespace : TType;
|
|
3562
|
+
type ExtractNamespace<TType$1 extends string> = TType$1 extends `${infer Namespace}.${string}` ? Namespace : TType$1;
|
|
3563
3563
|
type EditorDom = {
|
|
3564
3564
|
getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
3565
3565
|
getChildNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
@@ -3647,4 +3647,4 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
3647
3647
|
event: TBehaviorEvent;
|
|
3648
3648
|
dom: EditorDom;
|
|
3649
3649
|
}, guardResponse: TGuardResponse) => Array<BehaviorAction>;
|
|
3650
|
-
export {
|
|
3650
|
+
export { AddedAnnotationPaths as $, PortableTextEditorProps as $t, PortableTextTextBlock$2 as A, RangeDecorationOnMovedDetails as At, EditorSelector as B, RenderStyleFunction as Bt, ListDefinition as C, OnPasteResult as Ct, PortableTextChild$1 as D, PatchObservable as Dt, PortableTextBlock$1 as E, PatchChange as Et, BlockOffset as F, RenderChildFunction as Ft, Editor as G, ValueChange as Gt, EditorProvider as H, SelectionChange as Ht, useEditor as I, RenderDecoratorFunction as It, Behavior as J, ChildPath as Jt, EditorConfig as K, AnnotationPath as Kt, defaultKeyGenerator as L, RenderEditableFunction as Lt, StyleDefinition as M, RedoChange as Mt, StyleSchemaType as N, RenderAnnotationFunction as Nt, PortableTextObject$2 as O, PortableTextMemberSchemaTypes as Ot, defineSchema as P, RenderBlockFunction as Pt, EditorSnapshot as Q, PortableTextEditor as Qt, usePortableTextEditorSelection as R, RenderListItemFunction as Rt, InlineObjectSchemaType as S, OnPasteFn as St, Patch$1 as T, PasteData as Tt, EditorProviderProps as U, UndoChange as Ut, useEditorSelector as V, ScrollSelectionIntoViewFunction as Vt, EditorEventListener as W, UnsetChange as Wt, BehaviorGuard as X, PortableTextEditableProps as Xt, defineBehavior as Y, PortableTextEditable as Yt, EditorContext as Z, HotkeyOptions as Zt, BlockObjectSchemaType as _, InvalidValueResolution as _t, forward as a, BlockStyleRenderProps as at, FieldDefinition as b, OnBeforeInputFn as bt, CustomBehaviorEvent as c, EditableAPI as ct, SyntheticBehaviorEvent as d, EditorChanges as dt, EditorSchema as en, BlockAnnotationRenderProps as et, PatchesEvent as f, EditorSelection as ft, BlockObjectDefinition as g, InvalidValue as gt, BaseDefinition as h, FocusChange as ht, execute as i, BlockRenderProps as it, SchemaDefinition$1 as j, ReadyChange as jt, PortableTextSpan$2 as k, RangeDecoration as kt, InsertPlacement as l, EditableAPIDeleteOptions as lt, AnnotationSchemaType as m, ErrorChange as mt, BehaviorActionSet as n, MutationEvent as nn, BlockDecoratorRenderProps as nt, raise as o, BlurChange as ot, AnnotationDefinition as p, EditorSelectionPoint as pt, EditorEvent as q, BlockPath as qt, effect as r, BlockListItemRenderProps as rt, BehaviorEvent as s, ConnectionChange as st, BehaviorAction as t, EditorEmittedEvent as tn, BlockChildRenderProps as tt, NativeBehaviorEvent as u, EditorChange as ut, DecoratorDefinition as v, LoadingChange as vt, ListSchemaType as w, OnPasteResultOrPromise as wt, InlineObjectDefinition as x, OnCopyFn as xt, DecoratorSchemaType as y, MutationChange as yt, usePortableTextEditor as z, RenderPlaceholderFunction as zt };
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Behavior,
|
|
1
|
+
import { J as Behavior, X as BehaviorGuard, Y as defineBehavior, a as forward, c as CustomBehaviorEvent, d as SyntheticBehaviorEvent, i as execute, l as InsertPlacement, n as BehaviorActionSet, o as raise, r as effect, s as BehaviorEvent, t as BehaviorAction, u as NativeBehaviorEvent } from "../_chunks-dts/index.js";
|
|
2
2
|
export { Behavior, BehaviorAction, BehaviorActionSet, BehaviorEvent, BehaviorGuard, CustomBehaviorEvent, InsertPlacement, NativeBehaviorEvent, SyntheticBehaviorEvent, defineBehavior, effect, execute, forward, raise };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AddedAnnotationPaths,
|
|
1
|
+
import { $ as AddedAnnotationPaths, $t as PortableTextEditorProps, A as PortableTextTextBlock, At as RangeDecorationOnMovedDetails, B as EditorSelector, Bt as RenderStyleFunction, C as ListDefinition, Ct as OnPasteResult, D as PortableTextChild, Dt as PatchObservable, E as PortableTextBlock, Et as PatchChange, F as BlockOffset, Ft as RenderChildFunction, G as Editor, Gt as ValueChange, H as EditorProvider, Ht as SelectionChange, I as useEditor, It as RenderDecoratorFunction, Jt as ChildPath, K as EditorConfig, Kt as AnnotationPath, L as defaultKeyGenerator, Lt as RenderEditableFunction, M as StyleDefinition, Mt as RedoChange, N as StyleSchemaType, Nt as RenderAnnotationFunction, O as PortableTextObject, Ot as PortableTextMemberSchemaTypes, P as defineSchema, Pt as RenderBlockFunction, Q as EditorSnapshot, Qt as PortableTextEditor, R as usePortableTextEditorSelection, Rt as RenderListItemFunction, S as InlineObjectSchemaType, St as OnPasteFn, T as Patch, Tt as PasteData, U as EditorProviderProps, Ut as UndoChange, V as useEditorSelector, Vt as ScrollSelectionIntoViewFunction, W as EditorEventListener, Wt as UnsetChange, Xt as PortableTextEditableProps, Yt as PortableTextEditable, Z as EditorContext, Zt as HotkeyOptions, _ as BlockObjectSchemaType, _t as InvalidValueResolution, at as BlockStyleRenderProps, b as FieldDefinition, bt as OnBeforeInputFn, ct as EditableAPI, dt as EditorChanges, en as EditorSchema, et as BlockAnnotationRenderProps, f as PatchesEvent, ft as EditorSelection, g as BlockObjectDefinition, gt as InvalidValue, h as BaseDefinition, ht as FocusChange, it as BlockRenderProps, j as SchemaDefinition, jt as ReadyChange, k as PortableTextSpan, kt as RangeDecoration, lt as EditableAPIDeleteOptions, m as AnnotationSchemaType, mt as ErrorChange, nn as MutationEvent, nt as BlockDecoratorRenderProps, ot as BlurChange, p as AnnotationDefinition, pt as EditorSelectionPoint, q as EditorEvent, qt as BlockPath, rt as BlockListItemRenderProps, st as ConnectionChange, tn as EditorEmittedEvent, tt as BlockChildRenderProps, ut as EditorChange, v as DecoratorDefinition, vt as LoadingChange, w as ListSchemaType, wt as OnPasteResultOrPromise, x as InlineObjectDefinition, xt as OnCopyFn, y as DecoratorSchemaType, yt as MutationChange, z as usePortableTextEditor, zt as RenderPlaceholderFunction } from "./_chunks-dts/index.js";
|
|
2
2
|
export { AddedAnnotationPaths, AnnotationDefinition, AnnotationPath, AnnotationSchemaType, BaseDefinition, BlockAnnotationRenderProps, BlockChildRenderProps, BlockDecoratorRenderProps, BlockListItemRenderProps, BlockObjectDefinition, BlockObjectSchemaType, BlockOffset, BlockPath, BlockRenderProps, BlockStyleRenderProps, BlurChange, ChildPath, ConnectionChange, DecoratorDefinition, DecoratorSchemaType, EditableAPI, EditableAPIDeleteOptions, Editor, EditorChange, EditorChanges, EditorConfig, EditorContext, EditorEmittedEvent, EditorEvent, EditorEventListener, EditorProvider, EditorProviderProps, EditorSchema, EditorSelection, EditorSelectionPoint, EditorSelector, EditorSnapshot, ErrorChange, FieldDefinition, FocusChange, HotkeyOptions, InlineObjectDefinition, InlineObjectSchemaType, InvalidValue, InvalidValueResolution, ListDefinition, ListSchemaType, LoadingChange, MutationChange, MutationEvent, OnBeforeInputFn, OnCopyFn, OnPasteFn, OnPasteResult, OnPasteResultOrPromise, PasteData, Patch, PatchChange, PatchObservable, PatchesEvent, PortableTextBlock, PortableTextChild, PortableTextEditable, PortableTextEditableProps, PortableTextEditor, PortableTextEditorProps, PortableTextMemberSchemaTypes, PortableTextObject, PortableTextSpan, PortableTextTextBlock, RangeDecoration, RangeDecorationOnMovedDetails, ReadyChange, RedoChange, RenderAnnotationFunction, RenderBlockFunction, RenderChildFunction, RenderDecoratorFunction, RenderEditableFunction, RenderListItemFunction, RenderPlaceholderFunction, RenderStyleFunction, SchemaDefinition, ScrollSelectionIntoViewFunction, SelectionChange, StyleDefinition, StyleSchemaType, UndoChange, UnsetChange, ValueChange, defineSchema, defaultKeyGenerator as keyGenerator, useEditor, useEditorSelector, usePortableTextEditor, usePortableTextEditorSelection };
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as Editor, J as Behavior, en as EditorSchema, tn as EditorEmittedEvent } from "../_chunks-dts/index.js";
|
|
2
2
|
import * as react22 from "react";
|
|
3
3
|
import React from "react";
|
|
4
4
|
/**
|
|
@@ -193,4 +193,4 @@ declare function MarkdownPlugin(props: {
|
|
|
193
193
|
* @deprecated Install the plugin from `@portabletext/plugin-one-line`
|
|
194
194
|
*/
|
|
195
195
|
declare function OneLinePlugin(): react22.JSX.Element;
|
|
196
|
-
export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, MarkdownPluginConfig, OneLinePlugin };
|
|
196
|
+
export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as EditorSelector, F as BlockOffset, Jt as ChildPath, ft as EditorSelection, pt as EditorSelectionPoint, qt as BlockPath } from "../_chunks-dts/index.js";
|
|
2
2
|
import { KeyedSegment, PortableTextBlock, PortableTextListBlock, PortableTextObject, PortableTextSpan, PortableTextTextBlock } from "@sanity/types";
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
@@ -354,4 +354,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
|
|
|
354
354
|
* @public
|
|
355
355
|
*/
|
|
356
356
|
declare const isSelectionExpanded: EditorSelector<boolean>;
|
|
357
|
-
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
|
|
357
|
+
export { type MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockOffset,
|
|
1
|
+
import { F as BlockOffset, Jt as ChildPath, Z as EditorContext, ft as EditorSelection, pt as EditorSelectionPoint, qt as BlockPath } from "../_chunks-dts/index.js";
|
|
2
2
|
import * as _sanity_types8 from "@sanity/types";
|
|
3
3
|
import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
|
|
4
4
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -29,26 +29,18 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"source": "./src/index.ts",
|
|
32
|
-
"import": "./lib/index.js",
|
|
33
|
-
"require": "./lib/index.cjs",
|
|
34
32
|
"default": "./lib/index.js"
|
|
35
33
|
},
|
|
36
34
|
"./behaviors": {
|
|
37
35
|
"source": "./src/behaviors/_exports/index.ts",
|
|
38
|
-
"import": "./lib/behaviors/index.js",
|
|
39
|
-
"require": "./lib/behaviors/index.cjs",
|
|
40
36
|
"default": "./lib/behaviors/index.js"
|
|
41
37
|
},
|
|
42
38
|
"./plugins": {
|
|
43
39
|
"source": "./src/plugins/_exports/index.ts",
|
|
44
|
-
"import": "./lib/plugins/index.js",
|
|
45
|
-
"require": "./lib/plugins/index.cjs",
|
|
46
40
|
"default": "./lib/plugins/index.js"
|
|
47
41
|
},
|
|
48
42
|
"./selectors": {
|
|
49
43
|
"source": "./src/selectors/_exports/index.ts",
|
|
50
|
-
"import": "./lib/selectors/index.js",
|
|
51
|
-
"require": "./lib/selectors/index.cjs",
|
|
52
44
|
"default": "./lib/selectors/index.js"
|
|
53
45
|
},
|
|
54
46
|
"./test": {
|
|
@@ -59,14 +51,11 @@
|
|
|
59
51
|
},
|
|
60
52
|
"./utils": {
|
|
61
53
|
"source": "./src/utils/_exports/index.ts",
|
|
62
|
-
"import": "./lib/utils/index.js",
|
|
63
|
-
"require": "./lib/utils/index.cjs",
|
|
64
54
|
"default": "./lib/utils/index.js"
|
|
65
55
|
},
|
|
66
56
|
"./package.json": "./package.json"
|
|
67
57
|
},
|
|
68
|
-
"main": "./lib/index.
|
|
69
|
-
"module": "./lib/index.js",
|
|
58
|
+
"main": "./lib/index.js",
|
|
70
59
|
"types": "./lib/index.d.ts",
|
|
71
60
|
"files": [
|
|
72
61
|
"lib",
|
|
@@ -84,16 +73,16 @@
|
|
|
84
73
|
"slate-dom": "^0.118.1",
|
|
85
74
|
"slate-react": "0.118.2",
|
|
86
75
|
"xstate": "^5.23.0",
|
|
87
|
-
"@portabletext/block-tools": "^
|
|
88
|
-
"@portabletext/keyboard-shortcuts": "^
|
|
89
|
-
"@portabletext/patches": "^
|
|
90
|
-
"@portabletext/schema": "^
|
|
76
|
+
"@portabletext/block-tools": "^4.0.0",
|
|
77
|
+
"@portabletext/keyboard-shortcuts": "^2.0.0",
|
|
78
|
+
"@portabletext/patches": "^2.0.0",
|
|
79
|
+
"@portabletext/schema": "^2.0.0"
|
|
91
80
|
},
|
|
92
81
|
"devDependencies": {
|
|
93
82
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
94
|
-
"@sanity/pkg-utils": "^
|
|
95
|
-
"@sanity/schema": "^4.
|
|
96
|
-
"@sanity/types": "^4.
|
|
83
|
+
"@sanity/pkg-utils": "^9.0.0",
|
|
84
|
+
"@sanity/schema": "^4.13.0",
|
|
85
|
+
"@sanity/types": "^4.13.0",
|
|
97
86
|
"@types/debug": "^4.1.12",
|
|
98
87
|
"@types/lodash": "^4.17.20",
|
|
99
88
|
"@types/lodash.startcase": "^4.4.9",
|
|
@@ -117,14 +106,14 @@
|
|
|
117
106
|
"vite": "^7.1.10",
|
|
118
107
|
"vitest": "^4.0.5",
|
|
119
108
|
"vitest-browser-react": "^2.0.2",
|
|
120
|
-
"@portabletext/sanity-bridge": "1.
|
|
109
|
+
"@portabletext/sanity-bridge": "1.2.0",
|
|
121
110
|
"@portabletext/test": "^0.0.0",
|
|
122
|
-
"racejar": "
|
|
111
|
+
"racejar": "2.0.0"
|
|
123
112
|
},
|
|
124
113
|
"peerDependencies": {
|
|
125
|
-
"@portabletext/sanity-bridge": "^1.
|
|
126
|
-
"@sanity/schema": "^4.
|
|
127
|
-
"@sanity/types": "^4.
|
|
114
|
+
"@portabletext/sanity-bridge": "^1.2.0",
|
|
115
|
+
"@sanity/schema": "^4.13.0",
|
|
116
|
+
"@sanity/types": "^4.13.0",
|
|
128
117
|
"react": "^18.3 || ^19",
|
|
129
118
|
"rxjs": "^7.8.2"
|
|
130
119
|
},
|
|
@@ -223,6 +223,7 @@ export const stepDefinitions = [
|
|
|
223
223
|
'{button} is pressed',
|
|
224
224
|
async (_: Context, button: Parameter['button']) => {
|
|
225
225
|
await userEvent.keyboard(button)
|
|
226
|
+
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
226
227
|
},
|
|
227
228
|
),
|
|
228
229
|
When(
|
|
@@ -230,6 +231,7 @@ export const stepDefinitions = [
|
|
|
230
231
|
async (_: Context, button: Parameter['button'], times: number) => {
|
|
231
232
|
for (let i = 0; i < times; i++) {
|
|
232
233
|
await userEvent.keyboard(button)
|
|
234
|
+
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
233
235
|
}
|
|
234
236
|
},
|
|
235
237
|
),
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type PortableTextEditableProps,
|
|
12
12
|
} from '../../editor/Editable'
|
|
13
13
|
import {EditorProvider} from '../../editor/editor-provider'
|
|
14
|
+
import type {EditorEmittedEvent} from '../../editor/relay-machine'
|
|
14
15
|
import {EventListenerPlugin} from '../../plugins'
|
|
15
16
|
import {EditorRefPlugin} from '../../plugins/plugin.editor-ref'
|
|
16
17
|
import type {Context} from './step-context'
|
|
@@ -94,11 +95,20 @@ export async function createTestEditor(
|
|
|
94
95
|
* @internal
|
|
95
96
|
*/
|
|
96
97
|
export async function createTestEditors(
|
|
97
|
-
options: CreateTestEditorOptions,
|
|
98
|
-
): Promise<
|
|
98
|
+
options: CreateTestEditorOptions = {},
|
|
99
|
+
): Promise<
|
|
100
|
+
Pick<Context, 'editor' | 'locator' | 'editorB' | 'locatorB'> & {
|
|
101
|
+
onEditorEvent: (event: EditorEmittedEvent) => void
|
|
102
|
+
onEditorBEvent: (event: EditorEmittedEvent) => void
|
|
103
|
+
}
|
|
104
|
+
> {
|
|
99
105
|
const editorRef = React.createRef<Editor>()
|
|
100
106
|
const editorBRef = React.createRef<Editor>()
|
|
101
|
-
|
|
107
|
+
|
|
108
|
+
const keyGenerator = options.keyGenerator ?? createTestKeyGenerator('ea-')
|
|
109
|
+
const keyGeneratorB = options.keyGenerator ?? createTestKeyGenerator('eb-')
|
|
110
|
+
const onEditorEvent = vi.fn<(event: EditorEmittedEvent) => void>()
|
|
111
|
+
const onEditorBEvent = vi.fn<(event: EditorEmittedEvent) => void>()
|
|
102
112
|
|
|
103
113
|
render(
|
|
104
114
|
<>
|
|
@@ -116,6 +126,7 @@ export async function createTestEditors(
|
|
|
116
126
|
/>
|
|
117
127
|
<EventListenerPlugin
|
|
118
128
|
on={(event) => {
|
|
129
|
+
onEditorEvent(event)
|
|
119
130
|
if (event.type === 'mutation') {
|
|
120
131
|
editorBRef.current?.send({
|
|
121
132
|
type: 'patches',
|
|
@@ -136,7 +147,7 @@ export async function createTestEditors(
|
|
|
136
147
|
</EditorProvider>
|
|
137
148
|
<EditorProvider
|
|
138
149
|
initialConfig={{
|
|
139
|
-
keyGenerator:
|
|
150
|
+
keyGenerator: keyGeneratorB,
|
|
140
151
|
schemaDefinition: options.schemaDefinition ?? defineSchema({}),
|
|
141
152
|
initialValue: options.initialValue,
|
|
142
153
|
}}
|
|
@@ -148,6 +159,7 @@ export async function createTestEditors(
|
|
|
148
159
|
/>
|
|
149
160
|
<EventListenerPlugin
|
|
150
161
|
on={(event) => {
|
|
162
|
+
onEditorBEvent(event)
|
|
151
163
|
if (event.type === 'mutation') {
|
|
152
164
|
editorRef.current?.send({
|
|
153
165
|
type: 'patches',
|
|
@@ -178,7 +190,9 @@ export async function createTestEditors(
|
|
|
178
190
|
return {
|
|
179
191
|
editor: editorRef.current!,
|
|
180
192
|
locator,
|
|
193
|
+
onEditorEvent,
|
|
181
194
|
editorB: editorBRef.current!,
|
|
182
195
|
locatorB,
|
|
196
|
+
onEditorBEvent,
|
|
183
197
|
}
|
|
184
198
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var schema = require("@portabletext/schema"), util_getTextBlockText = require("./util.get-text-block-text.cjs"), types = require("@sanity/types");
|
|
3
|
-
const getFocusBlock = (snapshot) => {
|
|
4
|
-
if (!snapshot.context.selection)
|
|
5
|
-
return;
|
|
6
|
-
const key = util_getTextBlockText.getBlockKeyFromSelectionPoint(snapshot.context.selection.focus), index = key ? snapshot.blockIndexMap.get(key) : void 0, node = index !== void 0 ? snapshot.context.value.at(index) : void 0;
|
|
7
|
-
return node && key ? {
|
|
8
|
-
node,
|
|
9
|
-
path: [{
|
|
10
|
-
_key: key
|
|
11
|
-
}]
|
|
12
|
-
} : void 0;
|
|
13
|
-
}, getFocusTextBlock = (snapshot) => {
|
|
14
|
-
const focusBlock = getFocusBlock(snapshot);
|
|
15
|
-
return focusBlock && schema.isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
16
|
-
node: focusBlock.node,
|
|
17
|
-
path: focusBlock.path
|
|
18
|
-
} : void 0;
|
|
19
|
-
}, getFocusChild = (snapshot) => {
|
|
20
|
-
if (!snapshot.context.selection)
|
|
21
|
-
return;
|
|
22
|
-
const focusBlock = getFocusTextBlock(snapshot);
|
|
23
|
-
if (!focusBlock)
|
|
24
|
-
return;
|
|
25
|
-
const key = util_getTextBlockText.getChildKeyFromSelectionPoint(snapshot.context.selection.focus), node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
26
|
-
return node && key ? {
|
|
27
|
-
node,
|
|
28
|
-
path: [...focusBlock.path, "children", {
|
|
29
|
-
_key: key
|
|
30
|
-
}]
|
|
31
|
-
} : void 0;
|
|
32
|
-
}, getFocusSpan = (snapshot) => {
|
|
33
|
-
const focusChild = getFocusChild(snapshot);
|
|
34
|
-
return focusChild && schema.isSpan(snapshot.context, focusChild.node) ? {
|
|
35
|
-
node: focusChild.node,
|
|
36
|
-
path: focusChild.path
|
|
37
|
-
} : void 0;
|
|
38
|
-
}, getSelectionStartPoint = (snapshot) => {
|
|
39
|
-
if (snapshot.context.selection)
|
|
40
|
-
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
41
|
-
}, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
|
|
42
|
-
const selection = snapshot.context.selection;
|
|
43
|
-
if (!selection)
|
|
44
|
-
return [];
|
|
45
|
-
const startPoint = util_getTextBlockText.getSelectionStartPoint(selection), endPoint = util_getTextBlockText.getSelectionEndPoint(selection), startBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(endPoint);
|
|
46
|
-
if (!startBlockKey || !endBlockKey)
|
|
47
|
-
return [];
|
|
48
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
49
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
50
|
-
return [];
|
|
51
|
-
const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? util_getTextBlockText.sliceBlocks({
|
|
52
|
-
context: snapshot.context,
|
|
53
|
-
blocks: [startBlock]
|
|
54
|
-
}).at(0) : void 0;
|
|
55
|
-
if (startBlockIndex === endBlockIndex)
|
|
56
|
-
return slicedStartBlock ? [slicedStartBlock] : [];
|
|
57
|
-
const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? util_getTextBlockText.sliceBlocks({
|
|
58
|
-
context: snapshot.context,
|
|
59
|
-
blocks: [endBlock]
|
|
60
|
-
}).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
|
|
61
|
-
return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
|
|
62
|
-
}, getPreviousInlineObject = (snapshot) => {
|
|
63
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
64
|
-
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
65
|
-
return;
|
|
66
|
-
let inlineObject;
|
|
67
|
-
for (const child of focusTextBlock.node.children) {
|
|
68
|
-
if (child._key === selectionStartPointChildKey)
|
|
69
|
-
break;
|
|
70
|
-
schema.isSpan(snapshot.context, child) || (inlineObject = {
|
|
71
|
-
node: child,
|
|
72
|
-
path: [...focusTextBlock.path, "children", {
|
|
73
|
-
_key: child._key
|
|
74
|
-
}]
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return inlineObject;
|
|
78
|
-
}, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => schema.isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => schema.isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, "");
|
|
79
|
-
exports.getFocusBlock = getFocusBlock;
|
|
80
|
-
exports.getFocusChild = getFocusChild;
|
|
81
|
-
exports.getFocusSpan = getFocusSpan;
|
|
82
|
-
exports.getFocusTextBlock = getFocusTextBlock;
|
|
83
|
-
exports.getPreviousInlineObject = getPreviousInlineObject;
|
|
84
|
-
exports.getSelectedValue = getSelectedValue;
|
|
85
|
-
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
86
|
-
exports.getSelectionText = getSelectionText;
|
|
87
|
-
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
88
|
-
exports.isSelectionExpanded = isSelectionExpanded;
|
|
89
|
-
//# sourceMappingURL=selector.get-selection-text.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-selection-text.cjs","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return snapshot.context.selection !== null && !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,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AAE;;;;;;;;;;;"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var util_getTextBlockText = require("./util.get-text-block-text.cjs"), selector_getSelectionText = require("./selector.get-selection-text.cjs");
|
|
3
|
-
const getBlockTextBefore = (snapshot) => {
|
|
4
|
-
if (!snapshot.context.selection)
|
|
5
|
-
return "";
|
|
6
|
-
const startPoint = util_getTextBlockText.getSelectionStartPoint(snapshot.context.selection), block = selector_getSelectionText.getFocusBlock({
|
|
7
|
-
...snapshot,
|
|
8
|
-
context: {
|
|
9
|
-
...snapshot.context,
|
|
10
|
-
selection: {
|
|
11
|
-
anchor: startPoint,
|
|
12
|
-
focus: startPoint
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
if (!block)
|
|
17
|
-
return "";
|
|
18
|
-
const startOfBlock = util_getTextBlockText.getBlockStartPoint({
|
|
19
|
-
context: snapshot.context,
|
|
20
|
-
block
|
|
21
|
-
});
|
|
22
|
-
return selector_getSelectionText.getSelectionText({
|
|
23
|
-
...snapshot,
|
|
24
|
-
context: {
|
|
25
|
-
...snapshot.context,
|
|
26
|
-
selection: {
|
|
27
|
-
anchor: startOfBlock,
|
|
28
|
-
focus: startPoint
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
exports.getBlockTextBefore = getBlockTextBefore;
|
|
34
|
-
//# sourceMappingURL=selector.get-text-before.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,sBAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,wCAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,sBAAAA,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,2CAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
|