@portabletext/editor 2.1.8 → 2.1.10
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/_chunks-dts/behavior.types.action.d.ts +9 -9
- package/lib/index.cjs +35 -47
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +35 -47
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +4 -4
- package/src/internal-utils/build-index-maps.test.ts +52 -0
- package/src/internal-utils/build-index-maps.ts +50 -37
|
@@ -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 react20 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(): react20.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: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.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: react20.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: react20.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: react20.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: react20.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: react20.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: react20.FocusEvent<HTMLDivElement, Element>;
|
|
3034
3034
|
} | {
|
|
3035
3035
|
type: "invalid value";
|
|
3036
3036
|
resolution: InvalidValueResolution | null;
|
|
@@ -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 react20 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(): react20.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: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.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: react20.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: react20.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: react20.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: react20.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: react20.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: react20.FocusEvent<HTMLDivElement, Element>;
|
|
3034
3034
|
} | {
|
|
3035
3035
|
type: "invalid value";
|
|
3036
3036
|
resolution: InvalidValueResolution | null;
|
package/lib/index.cjs
CHANGED
|
@@ -1287,61 +1287,49 @@ function compileType(rawType) {
|
|
|
1287
1287
|
types: [rawType]
|
|
1288
1288
|
}).get(rawType.name);
|
|
1289
1289
|
}
|
|
1290
|
-
const
|
|
1290
|
+
const levelIndexMaps = /* @__PURE__ */ new Map();
|
|
1291
1291
|
function buildIndexMaps(context, {
|
|
1292
1292
|
blockIndexMap,
|
|
1293
1293
|
listIndexMap
|
|
1294
1294
|
}) {
|
|
1295
|
-
blockIndexMap.clear(), listIndexMap.clear(),
|
|
1295
|
+
blockIndexMap.clear(), listIndexMap.clear(), levelIndexMaps.clear();
|
|
1296
1296
|
let previousListItem;
|
|
1297
1297
|
for (let blockIndex = 0; blockIndex < context.value.length; blockIndex++) {
|
|
1298
1298
|
const block = context.value.at(blockIndex);
|
|
1299
|
-
if (block
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
levelIndexMap.set(block.level, levelCounter + 1), previousListItem = {
|
|
1325
|
-
listItem: block.listItem,
|
|
1326
|
-
level: block.level
|
|
1327
|
-
}, listIndexMap.set(block._key, levelCounter + 1);
|
|
1328
|
-
continue;
|
|
1329
|
-
}
|
|
1330
|
-
if (previousListItem.level < block.level) {
|
|
1331
|
-
levelIndexMap.set(block.level, 1), previousListItem = {
|
|
1332
|
-
listItem: block.listItem,
|
|
1333
|
-
level: block.level
|
|
1334
|
-
}, listIndexMap.set(block._key, 1);
|
|
1335
|
-
continue;
|
|
1336
|
-
}
|
|
1337
|
-
if (previousListItem.level > block.level) {
|
|
1338
|
-
const levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
1339
|
-
levelIndexMap.set(block.level, levelCounter + 1), previousListItem = {
|
|
1340
|
-
listItem: block.listItem,
|
|
1341
|
-
level: block.level
|
|
1342
|
-
}, listIndexMap.set(block._key, levelCounter + 1);
|
|
1343
|
-
}
|
|
1299
|
+
if (block === void 0)
|
|
1300
|
+
continue;
|
|
1301
|
+
if (blockIndexMap.set(block._key, blockIndex), !util_sliceBlocks.isTextBlock(context, block)) {
|
|
1302
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (block.listItem === void 0 || block.level === void 0) {
|
|
1306
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
if (!previousListItem) {
|
|
1310
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
1311
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
1312
|
+
listItem: block.listItem,
|
|
1313
|
+
level: block.level
|
|
1314
|
+
};
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (previousListItem.listItem === block.listItem && previousListItem.level < block.level) {
|
|
1318
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
1319
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
1320
|
+
listItem: block.listItem,
|
|
1321
|
+
level: block.level
|
|
1322
|
+
};
|
|
1323
|
+
continue;
|
|
1344
1324
|
}
|
|
1325
|
+
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
1326
|
+
listItem !== block.listItem && levelIndexMap2.set(block.level, 0);
|
|
1327
|
+
});
|
|
1328
|
+
const levelIndexMap = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map(), levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
1329
|
+
levelIndexMap.set(block.level, levelCounter + 1), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
1330
|
+
listItem: block.listItem,
|
|
1331
|
+
level: block.level
|
|
1332
|
+
};
|
|
1345
1333
|
}
|
|
1346
1334
|
}
|
|
1347
1335
|
function createPlaceholderBlock(context) {
|