@portabletext/editor 1.1.0 → 1.1.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/index.d.mts +13 -12
- package/lib/index.d.ts +13 -12
- package/lib/index.esm.js +6 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +6 -10
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6 -10
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -17
- package/src/editor/Editable.tsx +21 -19
- package/src/editor/PortableTextEditor.tsx +19 -20
- package/src/editor/__tests__/PortableTextEditor.test.tsx +2 -3
- package/src/editor/__tests__/RangeDecorations.test.tsx +4 -5
- package/src/editor/__tests__/insert-block.test.tsx +2 -2
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +1 -1
- package/src/editor/__tests__/utils.ts +0 -1
- package/src/editor/components/Element.tsx +15 -17
- package/src/editor/components/Leaf.tsx +12 -12
- package/src/editor/components/SlateContainer.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +3 -3
- package/src/editor/hooks/usePortableTextEditor.ts +1 -1
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
- package/src/editor/hooks/useSyncValue.ts +3 -7
- package/src/editor/nodes/DefaultAnnotation.tsx +1 -2
- package/src/editor/nodes/DefaultObject.tsx +1 -1
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +1 -4
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +1 -3
- package/src/editor/plugins/createWithEditableAPI.ts +8 -8
- package/src/editor/plugins/createWithHotKeys.ts +8 -12
- package/src/editor/plugins/createWithInsertBreak.ts +4 -4
- package/src/editor/plugins/createWithInsertData.ts +7 -8
- package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +3 -3
- package/src/editor/plugins/createWithPatches.ts +6 -8
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +3 -3
- package/src/editor/plugins/createWithPortableTextLists.ts +3 -4
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +6 -8
- package/src/editor/plugins/createWithPortableTextSelections.ts +7 -7
- package/src/editor/plugins/createWithSchemaTypes.ts +4 -4
- package/src/editor/plugins/createWithUndoRedo.ts +3 -7
- package/src/editor/plugins/createWithUtils.ts +6 -6
- package/src/editor/plugins/index.ts +3 -3
- package/src/types/editor.ts +33 -33
- package/src/types/options.ts +3 -3
- package/src/types/slate.ts +4 -4
- package/src/utils/__tests__/dmpToOperations.test.ts +3 -3
- package/src/utils/__tests__/operationToPatches.test.ts +1 -1
- package/src/utils/__tests__/patchToOperations.test.ts +1 -1
- package/src/utils/__tests__/ranges.test.ts +1 -1
- package/src/utils/applyPatch.ts +10 -12
- package/src/utils/getPortableTextMemberSchemaTypes.ts +8 -8
- package/src/utils/operationToPatches.ts +5 -9
- package/src/utils/paths.ts +5 -5
- package/src/utils/ranges.ts +4 -5
- package/src/utils/selection.ts +2 -2
- package/src/utils/ucs2Indices.ts +2 -2
- package/src/utils/validateValue.ts +3 -3
- package/src/utils/values.ts +7 -8
- package/src/utils/weakMaps.ts +2 -2
- package/src/utils/withChanges.ts +1 -1
- package/src/utils/withUndoRedo.ts +1 -1
- package/src/utils/withoutPatching.ts +1 -1
package/lib/index.mjs
CHANGED
|
@@ -724,7 +724,6 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
724
724
|
};
|
|
725
725
|
function DefaultAnnotation(props) {
|
|
726
726
|
const handleClick = useCallback(
|
|
727
|
-
// eslint-disable-next-line no-alert
|
|
728
727
|
() => alert(JSON.stringify(props.annotation)),
|
|
729
728
|
[props.annotation]
|
|
730
729
|
);
|
|
@@ -2456,7 +2455,7 @@ function toInt(num) {
|
|
|
2456
2455
|
const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
|
|
2457
2456
|
function createApplyPatch(schemaTypes) {
|
|
2458
2457
|
let previousPatch;
|
|
2459
|
-
return
|
|
2458
|
+
return (editor, patch) => {
|
|
2460
2459
|
let changed = !1;
|
|
2461
2460
|
debugVerbose$4 && (debug$i(
|
|
2462
2461
|
`
|
|
@@ -3618,7 +3617,7 @@ function createWithSchemaTypes({
|
|
|
3618
3617
|
keyGenerator
|
|
3619
3618
|
}) {
|
|
3620
3619
|
return function(editor) {
|
|
3621
|
-
editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => isPortableTextSpan$1(value) && value._type
|
|
3620
|
+
editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => isPortableTextSpan$1(value) && value._type === schemaTypes.span.name, editor.isListBlock = (value) => isPortableTextListBlock(value) && value._type === schemaTypes.block.name, editor.isVoid = (element) => schemaTypes.block.name !== element._type && (schemaTypes.blockObjects.map((obj) => obj.name).includes(element._type) || schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
3622
3621
|
const { normalizeNode } = editor;
|
|
3623
3622
|
return editor.normalizeNode = (entry) => {
|
|
3624
3623
|
const [node, path] = entry;
|
|
@@ -3656,7 +3655,7 @@ function createWithUtils({
|
|
|
3656
3655
|
return;
|
|
3657
3656
|
}
|
|
3658
3657
|
const { focus } = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
3659
|
-
if (!(newStartOffset === newEndOffset || isNaN(newStartOffset) || isNaN(newEndOffset))) {
|
|
3658
|
+
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
3660
3659
|
debug$9("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
3661
3660
|
anchor: { ...selection.anchor, offset: newStartOffset },
|
|
3662
3661
|
focus: { ...selection.focus, offset: newEndOffset }
|
|
@@ -4258,10 +4257,7 @@ function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTyp
|
|
|
4258
4257
|
return newNode.children = newNode.children.map(
|
|
4259
4258
|
(child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
4260
4259
|
...child,
|
|
4261
|
-
marks: child.marks && child.marks.includes(oldKey) ? (
|
|
4262
|
-
// eslint-disable-next-line max-nested-callbacks
|
|
4263
|
-
[...child.marks].filter((mark) => mark !== oldKey).concat(newKey)
|
|
4264
|
-
) : child.marks
|
|
4260
|
+
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
4265
4261
|
} : child
|
|
4266
4262
|
), { ...def, _key: newKey };
|
|
4267
4263
|
});
|
|
@@ -4780,7 +4776,7 @@ class PortableTextEditor extends Component {
|
|
|
4780
4776
|
return this.editable.getValue();
|
|
4781
4777
|
};
|
|
4782
4778
|
render() {
|
|
4783
|
-
const { onChange, value, children, patches$, incomingPatches$ } = this.props, { change$ } = this, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, keyGenerator = this.props.keyGenerator || defaultKeyGenerator;
|
|
4779
|
+
const { onChange, value, children, patches$, incomingPatches$ } = this.props, { change$ } = this, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, keyGenerator = this.props.keyGenerator || defaultKeyGenerator;
|
|
4784
4780
|
return /* @__PURE__ */ jsx(
|
|
4785
4781
|
SlateContainer,
|
|
4786
4782
|
{
|
|
@@ -5191,7 +5187,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5191
5187
|
return;
|
|
5192
5188
|
}
|
|
5193
5189
|
}
|
|
5194
|
-
setRangeDecorationsState([]);
|
|
5190
|
+
rangeDecorationState.length > 0 && setRangeDecorationsState([]);
|
|
5195
5191
|
},
|
|
5196
5192
|
[portableTextEditor, rangeDecorations, schemaTypes, slateEditor]
|
|
5197
5193
|
);
|