@portabletext/editor 1.55.13 → 1.55.15
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-cjs/{selector.is-selection-expanded.cjs → selector.get-focus-span.cjs} +27 -27
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +291 -168
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.is-equal-selection-points.cjs → util.is-selection-collapsed.cjs} +7 -3
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.slice-text-block.cjs +2 -6
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-focus-span.js} +27 -27
- package/lib/_chunks-es/selector.get-focus-span.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +266 -143
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/{util.is-equal-selection-points.js → util.is-selection-collapsed.js} +7 -3
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/_chunks-es/util.slice-text-block.js +1 -5
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/behaviors/index.d.cts +3 -6
- package/lib/behaviors/index.d.ts +3 -6
- package/lib/index.cjs +357 -322
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +11 -20
- package/lib/index.d.ts +11 -20
- package/lib/index.js +296 -261
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -16
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3 -6
- package/lib/plugins/index.d.ts +3 -6
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +14 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +3 -6
- package/lib/selectors/index.d.ts +3 -6
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.cjs +9 -9
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3 -6
- package/lib/utils/index.d.ts +3 -6
- package/lib/utils/index.js +5 -5
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.ts +2 -1
- package/src/behaviors/behavior.core.dnd.ts +4 -4
- package/src/editor/Editable.tsx +8 -1
- package/src/editor/create-slate-editor.tsx +0 -1
- package/src/editor/editor-dom.ts +3 -3
- package/src/editor/editor-selector.ts +1 -13
- package/src/editor/editor-snapshot.ts +4 -19
- package/src/editor/plugins/createWithEditableAPI.ts +52 -13
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +13 -4
- package/src/editor/plugins/with-plugins.ts +4 -8
- package/src/editor/range-decorations-machine.ts +24 -12
- package/src/internal-utils/create-test-snapshot.ts +2 -5
- package/src/internal-utils/paths.ts +65 -17
- package/src/internal-utils/ranges.test.ts +179 -0
- package/src/internal-utils/ranges.ts +39 -22
- package/src/internal-utils/test-editor.tsx +16 -1
- package/src/operations/behavior.operation.block.set.ts +10 -6
- package/src/operations/behavior.operation.block.unset.ts +10 -6
- package/src/operations/behavior.operation.child.set.ts +10 -6
- package/src/operations/behavior.operation.child.unset.ts +10 -6
- package/src/operations/behavior.operation.decorator.add.ts +17 -6
- package/src/operations/behavior.operation.delete.ts +8 -1
- package/src/operations/behavior.operation.insert.text.ts +34 -20
- package/src/operations/behavior.operation.move.block.ts +25 -3
- package/src/operations/behavior.operation.select.ts +9 -2
- package/src/selectors/selector.get-active-annotation-marks.ts +12 -0
- package/src/selectors/selector.get-active-annotations.ts +8 -20
- package/src/{editor/get-active-decorators.ts → selectors/selector.get-active-decorators.ts} +6 -11
- package/src/{internal-utils/mark-state.ts → selectors/selector.get-mark-state.ts} +41 -67
- package/src/selectors/selector.get-next-span.ts +56 -0
- package/src/selectors/selector.get-previous-span.ts +53 -0
- package/src/selectors/selector.is-active-annotation.ts +3 -1
- package/src/selectors/selector.is-active-decorator.ts +4 -1
- package/src/types/editor.ts +0 -2
- package/src/utils/util.is-selection-expanded.ts +13 -0
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
- package/src/editor/get-active-annotations.ts +0 -15
- package/src/editor/plugins/slate-plugin.update-mark-state.ts +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getAnchorBlock: 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.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\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 type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: 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 anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getValue"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getAnchorBlock: 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.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\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 type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: 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 anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getValue"],"mappings":"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"}
|
|
@@ -172,15 +172,12 @@ declare type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected
|
|
|
172
172
|
*/
|
|
173
173
|
declare type EditorSnapshot = {
|
|
174
174
|
context: EditorContext
|
|
175
|
+
blockIndexMap: Map<string, number>
|
|
175
176
|
/**
|
|
176
177
|
* @beta
|
|
177
|
-
*
|
|
178
|
+
* Subject to change
|
|
178
179
|
*/
|
|
179
|
-
|
|
180
|
-
activeAnnotations: Array<string>
|
|
181
|
-
activeDecorators: Array<string>
|
|
182
|
-
}
|
|
183
|
-
blockIndexMap: Map<string, number>
|
|
180
|
+
decoratorState: Record<string, boolean | undefined>
|
|
184
181
|
}
|
|
185
182
|
|
|
186
183
|
/**
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -172,15 +172,12 @@ declare type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected
|
|
|
172
172
|
*/
|
|
173
173
|
declare type EditorSnapshot = {
|
|
174
174
|
context: EditorContext
|
|
175
|
+
blockIndexMap: Map<string, number>
|
|
175
176
|
/**
|
|
176
177
|
* @beta
|
|
177
|
-
*
|
|
178
|
+
* Subject to change
|
|
178
179
|
*/
|
|
179
|
-
|
|
180
|
-
activeAnnotations: Array<string>
|
|
181
|
-
activeDecorators: Array<string>
|
|
182
|
-
}
|
|
183
|
-
blockIndexMap: Map<string, number>
|
|
180
|
+
decoratorState: Record<string, boolean | undefined>
|
|
184
181
|
}
|
|
185
182
|
|
|
186
183
|
/**
|
package/lib/selectors/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire
|
|
|
2
2
|
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
3
3
|
import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
4
4
|
import { isPortableTextSpan } from "@sanity/types";
|
|
5
|
-
import { getSelectionStartPoint, getFocusTextBlock, getSelectedValue } from "../_chunks-es/selector.
|
|
6
|
-
import { getFocusBlock, getFocusChild, getFocusSpan, getPreviousInlineObject, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.
|
|
5
|
+
import { getSelectionStartPoint, getFocusTextBlock, getSelectedValue } from "../_chunks-es/selector.get-focus-span.js";
|
|
6
|
+
import { getFocusBlock, getFocusChild, getFocusSpan, getPreviousInlineObject, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.get-focus-span.js";
|
|
7
7
|
import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
|
|
8
8
|
const getAnchorBlock = (snapshot) => {
|
|
9
9
|
if (!snapshot.context.selection)
|
package/lib/utils/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"),
|
|
3
|
+
var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isSelectionCollapsed = require("../_chunks-cjs/util.is-selection-collapsed.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs"), util_sliceTextBlock = require("../_chunks-cjs/util.slice-text-block.cjs");
|
|
4
4
|
function isEqualSelections(a, b) {
|
|
5
|
-
return !a && !b ? !0 : !a || !b ? !1 :
|
|
5
|
+
return !a && !b ? !0 : !a || !b ? !1 : util_isSelectionCollapsed.isEqualSelectionPoints(a.anchor, b.anchor) && util_isSelectionCollapsed.isEqualSelectionPoints(a.focus, b.focus);
|
|
6
6
|
}
|
|
7
7
|
function reverseSelection(selection) {
|
|
8
8
|
return selection && (selection.backward ? {
|
|
@@ -50,7 +50,7 @@ function splitTextBlock({
|
|
|
50
50
|
}, "children", {
|
|
51
51
|
_key: lastChild._key
|
|
52
52
|
}],
|
|
53
|
-
offset: util_sliceBlocks.isSpan(context, lastChild) ? lastChild.text.length : 0
|
|
53
|
+
offset: util_sliceBlocks.isSpan$1(context, lastChild) ? lastChild.text.length : 0
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
@@ -67,20 +67,20 @@ exports.getSelectionEndPoint = util_sliceBlocks.getSelectionEndPoint;
|
|
|
67
67
|
exports.getSelectionStartPoint = util_sliceBlocks.getSelectionStartPoint;
|
|
68
68
|
exports.getTextBlockText = util_sliceBlocks.getTextBlockText;
|
|
69
69
|
exports.isKeyedSegment = util_sliceBlocks.isKeyedSegment;
|
|
70
|
-
exports.isSpan = util_sliceBlocks.isSpan;
|
|
70
|
+
exports.isSpan = util_sliceBlocks.isSpan$1;
|
|
71
71
|
exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
|
|
72
72
|
exports.spanSelectionPointToBlockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset;
|
|
73
73
|
exports.blockOffsetToBlockSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
|
|
74
74
|
exports.blockOffsetToSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToSelectionPoint;
|
|
75
75
|
exports.blockOffsetsToSelection = util_childSelectionPointToBlockOffset.blockOffsetsToSelection;
|
|
76
76
|
exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset;
|
|
77
|
-
exports.getBlockEndPoint =
|
|
78
|
-
exports.isEmptyTextBlock =
|
|
79
|
-
exports.isEqualSelectionPoints =
|
|
80
|
-
exports.isSelectionCollapsed =
|
|
81
|
-
exports.selectionPointToBlockOffset = util_sliceTextBlock.selectionPointToBlockOffset;
|
|
77
|
+
exports.getBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint;
|
|
78
|
+
exports.isEmptyTextBlock = util_isSelectionCollapsed.isEmptyTextBlock;
|
|
79
|
+
exports.isEqualSelectionPoints = util_isSelectionCollapsed.isEqualSelectionPoints;
|
|
80
|
+
exports.isSelectionCollapsed = util_isSelectionCollapsed.isSelectionCollapsed;
|
|
82
81
|
exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
|
|
83
82
|
exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
|
|
83
|
+
exports.selectionPointToBlockOffset = util_sliceTextBlock.selectionPointToBlockOffset;
|
|
84
84
|
exports.isEqualSelections = isEqualSelections;
|
|
85
85
|
exports.reverseSelection = reverseSelection;
|
|
86
86
|
exports.splitTextBlock = splitTextBlock;
|
package/lib/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {sliceTextBlock} from './util.slice-text-block'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {sliceTextBlock} from './util.slice-text-block'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,0BAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,0BAAAA,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,oBAAAA,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,mCAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,iBAAAA,SAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -237,15 +237,12 @@ declare type EditorSelectionPoint = {
|
|
|
237
237
|
*/
|
|
238
238
|
declare type EditorSnapshot = {
|
|
239
239
|
context: EditorContext
|
|
240
|
+
blockIndexMap: Map<string, number>
|
|
240
241
|
/**
|
|
241
242
|
* @beta
|
|
242
|
-
*
|
|
243
|
+
* Subject to change
|
|
243
244
|
*/
|
|
244
|
-
|
|
245
|
-
activeAnnotations: Array<string>
|
|
246
|
-
activeDecorators: Array<string>
|
|
247
|
-
}
|
|
248
|
-
blockIndexMap: Map<string, number>
|
|
245
|
+
decoratorState: Record<string, boolean | undefined>
|
|
249
246
|
}
|
|
250
247
|
|
|
251
248
|
/**
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -237,15 +237,12 @@ declare type EditorSelectionPoint = {
|
|
|
237
237
|
*/
|
|
238
238
|
declare type EditorSnapshot = {
|
|
239
239
|
context: EditorContext
|
|
240
|
+
blockIndexMap: Map<string, number>
|
|
240
241
|
/**
|
|
241
242
|
* @beta
|
|
242
|
-
*
|
|
243
|
+
* Subject to change
|
|
243
244
|
*/
|
|
244
|
-
|
|
245
|
-
activeAnnotations: Array<string>
|
|
246
|
-
activeDecorators: Array<string>
|
|
247
|
-
}
|
|
248
|
-
blockIndexMap: Map<string, number>
|
|
245
|
+
decoratorState: Record<string, boolean | undefined>
|
|
249
246
|
}
|
|
250
247
|
|
|
251
248
|
/**
|
package/lib/utils/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isSpan } from "../_chunks-es/util.slice-blocks.js";
|
|
1
|
+
import { isSpan$1 as isSpan } from "../_chunks-es/util.slice-blocks.js";
|
|
2
2
|
import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, sliceBlocks, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
3
3
|
import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
4
|
-
import { isEqualSelectionPoints } from "../_chunks-es/util.is-
|
|
5
|
-
import { getBlockEndPoint, isEmptyTextBlock } from "../_chunks-es/util.is-
|
|
6
|
-
import { sliceTextBlock } from "../_chunks-es/util.slice-text-block.js";
|
|
7
|
-
import { isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.slice-text-block.js";
|
|
4
|
+
import { isEqualSelectionPoints } from "../_chunks-es/util.is-selection-collapsed.js";
|
|
5
|
+
import { getBlockEndPoint, isEmptyTextBlock, isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
|
|
8
6
|
import { isTextBlock, mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
|
|
7
|
+
import { sliceTextBlock } from "../_chunks-es/util.slice-text-block.js";
|
|
8
|
+
import { selectionPointToBlockOffset } from "../_chunks-es/util.slice-text-block.js";
|
|
9
9
|
function isEqualSelections(a, b) {
|
|
10
10
|
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.55.
|
|
3
|
+
"version": "1.55.15",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"slate-react": "0.117.3",
|
|
81
81
|
"use-effect-event": "^1.0.2",
|
|
82
82
|
"xstate": "^5.20.0",
|
|
83
|
-
"@portabletext/
|
|
84
|
-
"@portabletext/
|
|
83
|
+
"@portabletext/block-tools": "1.1.34",
|
|
84
|
+
"@portabletext/patches": "1.1.5"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@portabletext/toolkit": "^2.0.17",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {ConverterEvent} from '../converters/converter.types'
|
|
2
2
|
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
|
+
import {getActiveDecorators} from '../selectors/selector.get-active-decorators'
|
|
4
5
|
import type {PickFromUnion} from '../type-utils'
|
|
5
6
|
import {getTextBlockText} from '../utils'
|
|
6
7
|
import {abstractAnnotationBehaviors} from './behavior.abstract.annotation'
|
|
@@ -214,7 +215,7 @@ export const abstractBehaviors = [
|
|
|
214
215
|
event.mimeType === 'text/plain' &&
|
|
215
216
|
event.originEvent.type === 'clipboard.paste'
|
|
216
217
|
) {
|
|
217
|
-
const activeDecorators = snapshot
|
|
218
|
+
const activeDecorators = getActiveDecorators(snapshot)
|
|
218
219
|
const activeAnnotations = selectors.getActiveAnnotations(snapshot)
|
|
219
220
|
|
|
220
221
|
return {
|
|
@@ -320,6 +320,10 @@ export const coreDndBehaviors = [
|
|
|
320
320
|
originEvent,
|
|
321
321
|
},
|
|
322
322
|
) => [
|
|
323
|
+
raise({
|
|
324
|
+
type: 'select',
|
|
325
|
+
at: dropPosition,
|
|
326
|
+
}),
|
|
323
327
|
...(draggingEntireBlocks
|
|
324
328
|
? draggedBlocks.map((block) =>
|
|
325
329
|
raise({
|
|
@@ -333,10 +337,6 @@ export const coreDndBehaviors = [
|
|
|
333
337
|
at: dragOrigin.selection,
|
|
334
338
|
}),
|
|
335
339
|
]),
|
|
336
|
-
raise({
|
|
337
|
-
type: 'select',
|
|
338
|
-
at: dropPosition,
|
|
339
|
-
}),
|
|
340
340
|
raise({
|
|
341
341
|
type: 'insert.blocks',
|
|
342
342
|
blocks: event.data,
|
package/src/editor/Editable.tsx
CHANGED
|
@@ -266,7 +266,14 @@ export const PortableTextEditable = forwardRef<
|
|
|
266
266
|
debug(
|
|
267
267
|
`Normalized selection from props ${JSON.stringify(normalizedSelection)}`,
|
|
268
268
|
)
|
|
269
|
-
const slateRange = toSlateRange(
|
|
269
|
+
const slateRange = toSlateRange({
|
|
270
|
+
context: {
|
|
271
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
272
|
+
value: slateEditor.value,
|
|
273
|
+
selection: normalizedSelection,
|
|
274
|
+
},
|
|
275
|
+
blockIndexMap: slateEditor.blockIndexMap,
|
|
276
|
+
})
|
|
270
277
|
if (slateRange) {
|
|
271
278
|
Transforms.select(slateEditor, slateRange)
|
|
272
279
|
// Output selection here in those cases where the editor selection was the same, and there are no set_selection operations made.
|
|
@@ -40,7 +40,6 @@ export function createSlateEditor(config: SlateEditorConfig): SlateEditor {
|
|
|
40
40
|
|
|
41
41
|
instance.decoratedRanges = []
|
|
42
42
|
instance.decoratorState = {}
|
|
43
|
-
instance.markState = undefined
|
|
44
43
|
|
|
45
44
|
const placeholderBlock = createPlaceholderBlock(
|
|
46
45
|
config.editorActor.getSnapshot().context,
|
package/src/editor/editor-dom.ts
CHANGED
|
@@ -45,7 +45,7 @@ function getBlockNodes(
|
|
|
45
45
|
return []
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const range = toSlateRange(snapshot
|
|
48
|
+
const range = toSlateRange(snapshot)
|
|
49
49
|
|
|
50
50
|
if (!range) {
|
|
51
51
|
return []
|
|
@@ -76,7 +76,7 @@ function getChildNodes(
|
|
|
76
76
|
return []
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const range = toSlateRange(snapshot
|
|
79
|
+
const range = toSlateRange(snapshot)
|
|
80
80
|
|
|
81
81
|
if (!range) {
|
|
82
82
|
return []
|
|
@@ -118,7 +118,7 @@ export function getSelectionDomNodes({
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const range = toSlateRange(snapshot
|
|
121
|
+
const range = toSlateRange(snapshot)
|
|
122
122
|
|
|
123
123
|
if (!range) {
|
|
124
124
|
return {
|
|
@@ -4,8 +4,6 @@ import type {PortableTextSlateEditor} from '../types/editor'
|
|
|
4
4
|
import type {InternalEditor} from './create-editor'
|
|
5
5
|
import type {EditorActor} from './editor-machine'
|
|
6
6
|
import type {EditorSnapshot} from './editor-snapshot'
|
|
7
|
-
import {getActiveAnnotations} from './get-active-annotations'
|
|
8
|
-
import {getActiveDecorators} from './get-active-decorators'
|
|
9
7
|
|
|
10
8
|
function defaultCompare<T>(a: T, b: T) {
|
|
11
9
|
return a === b
|
|
@@ -77,16 +75,6 @@ export function getEditorSnapshot({
|
|
|
77
75
|
selection: editorActorSnapshot.context.selection,
|
|
78
76
|
value: slateEditorInstance.value,
|
|
79
77
|
},
|
|
80
|
-
|
|
81
|
-
activeAnnotations: getActiveAnnotations({
|
|
82
|
-
markState: slateEditorInstance.markState,
|
|
83
|
-
schema: editorActorSnapshot.context.schema,
|
|
84
|
-
}),
|
|
85
|
-
activeDecorators: getActiveDecorators({
|
|
86
|
-
decoratorState: slateEditorInstance.decoratorState,
|
|
87
|
-
markState: slateEditorInstance.markState,
|
|
88
|
-
schema: editorActorSnapshot.context.schema,
|
|
89
|
-
}),
|
|
90
|
-
},
|
|
78
|
+
decoratorState: slateEditorInstance.decoratorState,
|
|
91
79
|
}
|
|
92
80
|
}
|
|
@@ -3,8 +3,6 @@ import type {Converter} from '../converters/converter.types'
|
|
|
3
3
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
4
4
|
import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
|
|
5
5
|
import type {EditorSchema} from './editor-schema'
|
|
6
|
-
import {getActiveAnnotations} from './get-active-annotations'
|
|
7
|
-
import {getActiveDecorators} from './get-active-decorators'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* @public
|
|
@@ -23,15 +21,12 @@ export type EditorContext = {
|
|
|
23
21
|
*/
|
|
24
22
|
export type EditorSnapshot = {
|
|
25
23
|
context: EditorContext
|
|
24
|
+
blockIndexMap: Map<string, number>
|
|
26
25
|
/**
|
|
27
26
|
* @beta
|
|
28
|
-
*
|
|
27
|
+
* Subject to change
|
|
29
28
|
*/
|
|
30
|
-
|
|
31
|
-
activeAnnotations: Array<string>
|
|
32
|
-
activeDecorators: Array<string>
|
|
33
|
-
}
|
|
34
|
-
blockIndexMap: Map<string, number>
|
|
29
|
+
decoratorState: Record<string, boolean | undefined>
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
export function createEditorSnapshot({
|
|
@@ -67,16 +62,6 @@ export function createEditorSnapshot({
|
|
|
67
62
|
return {
|
|
68
63
|
blockIndexMap: editor.blockIndexMap,
|
|
69
64
|
context,
|
|
70
|
-
|
|
71
|
-
activeAnnotations: getActiveAnnotations({
|
|
72
|
-
markState: editor.markState,
|
|
73
|
-
schema,
|
|
74
|
-
}),
|
|
75
|
-
activeDecorators: getActiveDecorators({
|
|
76
|
-
decoratorState: editor.decoratorState,
|
|
77
|
-
markState: editor.markState,
|
|
78
|
-
schema,
|
|
79
|
-
}),
|
|
80
|
-
},
|
|
65
|
+
decoratorState: editor.decoratorState,
|
|
81
66
|
} satisfies EditorSnapshot
|
|
82
67
|
}
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
} from '../../internal-utils/weakMaps'
|
|
30
30
|
import {addAnnotationOperationImplementation} from '../../operations/behavior.operation.annotation.add'
|
|
31
31
|
import {isActiveAnnotation} from '../../selectors'
|
|
32
|
+
import {getActiveAnnotationsMarks} from '../../selectors/selector.get-active-annotation-marks'
|
|
33
|
+
import {getActiveDecorators} from '../../selectors/selector.get-active-decorators'
|
|
32
34
|
import type {
|
|
33
35
|
EditableAPI,
|
|
34
36
|
EditableAPIDeleteOptions,
|
|
@@ -95,7 +97,9 @@ export function createEditableAPI(
|
|
|
95
97
|
slateEditorInstance: editor,
|
|
96
98
|
})
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
const activeDecorators = getActiveDecorators(snapshot)
|
|
101
|
+
|
|
102
|
+
return activeDecorators.includes(mark)
|
|
99
103
|
},
|
|
100
104
|
marks: (): string[] => {
|
|
101
105
|
const snapshot = getEditorSnapshot({
|
|
@@ -103,10 +107,10 @@ export function createEditableAPI(
|
|
|
103
107
|
slateEditorInstance: editor,
|
|
104
108
|
})
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]
|
|
110
|
+
const activeAnnotations = getActiveAnnotationsMarks(snapshot)
|
|
111
|
+
const activeDecorators = getActiveDecorators(snapshot)
|
|
112
|
+
|
|
113
|
+
return [...activeAnnotations, ...activeDecorators]
|
|
110
114
|
},
|
|
111
115
|
undo: (): void => {
|
|
112
116
|
editorActor.send({
|
|
@@ -127,12 +131,21 @@ export function createEditableAPI(
|
|
|
127
131
|
})
|
|
128
132
|
},
|
|
129
133
|
select: (selection: EditorSelection): void => {
|
|
130
|
-
const slateSelection = toSlateRange(
|
|
134
|
+
const slateSelection = toSlateRange({
|
|
135
|
+
context: {
|
|
136
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
137
|
+
value: editor.value,
|
|
138
|
+
selection,
|
|
139
|
+
},
|
|
140
|
+
blockIndexMap: editor.blockIndexMap,
|
|
141
|
+
})
|
|
142
|
+
|
|
131
143
|
if (slateSelection) {
|
|
132
144
|
Transforms.select(editor, slateSelection)
|
|
133
145
|
} else {
|
|
134
146
|
Transforms.deselect(editor)
|
|
135
147
|
}
|
|
148
|
+
|
|
136
149
|
editor.onChange()
|
|
137
150
|
},
|
|
138
151
|
focusBlock: (): PortableTextBlock | undefined => {
|
|
@@ -308,10 +321,15 @@ export function createEditableAPI(
|
|
|
308
321
|
PortableTextBlock | PortableTextChild | undefined,
|
|
309
322
|
Path | undefined,
|
|
310
323
|
] => {
|
|
311
|
-
const slatePath = toSlateRange(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
324
|
+
const slatePath = toSlateRange({
|
|
325
|
+
context: {
|
|
326
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
327
|
+
value: editor.value,
|
|
328
|
+
selection: {focus: {path, offset: 0}, anchor: {path, offset: 0}},
|
|
329
|
+
},
|
|
330
|
+
blockIndexMap: editor.blockIndexMap,
|
|
331
|
+
})
|
|
332
|
+
|
|
315
333
|
if (slatePath) {
|
|
316
334
|
const [block, blockPath] = Editor.node(
|
|
317
335
|
editor,
|
|
@@ -428,7 +446,14 @@ export function createEditableAPI(
|
|
|
428
446
|
options?: EditableAPIDeleteOptions,
|
|
429
447
|
): void => {
|
|
430
448
|
if (selection) {
|
|
431
|
-
const range = toSlateRange(
|
|
449
|
+
const range = toSlateRange({
|
|
450
|
+
context: {
|
|
451
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
452
|
+
value: editor.value,
|
|
453
|
+
selection,
|
|
454
|
+
},
|
|
455
|
+
blockIndexMap: editor.blockIndexMap,
|
|
456
|
+
})
|
|
432
457
|
const hasRange =
|
|
433
458
|
range && range.anchor.path.length > 0 && range.focus.path.length > 0
|
|
434
459
|
if (!hasRange) {
|
|
@@ -536,8 +561,22 @@ export function createEditableAPI(
|
|
|
536
561
|
selectionB: EditorSelection,
|
|
537
562
|
) => {
|
|
538
563
|
// Convert the selections to Slate ranges
|
|
539
|
-
const rangeA = toSlateRange(
|
|
540
|
-
|
|
564
|
+
const rangeA = toSlateRange({
|
|
565
|
+
context: {
|
|
566
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
567
|
+
value: editor.value,
|
|
568
|
+
selection: selectionA,
|
|
569
|
+
},
|
|
570
|
+
blockIndexMap: editor.blockIndexMap,
|
|
571
|
+
})
|
|
572
|
+
const rangeB = toSlateRange({
|
|
573
|
+
context: {
|
|
574
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
575
|
+
value: editor.value,
|
|
576
|
+
selection: selectionB,
|
|
577
|
+
},
|
|
578
|
+
blockIndexMap: editor.blockIndexMap,
|
|
579
|
+
})
|
|
541
580
|
|
|
542
581
|
// Make sure the ranges are valid
|
|
543
582
|
const isValidRanges = Range.isRange(rangeA) && Range.isRange(rangeB)
|
|
@@ -13,6 +13,8 @@ import {getNextSpan, getPreviousSpan} from '../../internal-utils/sibling-utils'
|
|
|
13
13
|
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
14
14
|
import {isRedoing, isUndoing} from '../../internal-utils/withUndoRedo'
|
|
15
15
|
import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
|
|
16
|
+
import {getActiveDecorators} from '../../selectors/selector.get-active-decorators'
|
|
17
|
+
import {getMarkState} from '../../selectors/selector.get-mark-state'
|
|
16
18
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
17
19
|
import type {EditorActor} from '../editor-machine'
|
|
18
20
|
import {getEditorSnapshot} from '../editor-selector'
|
|
@@ -412,12 +414,19 @@ export function createWithPortableTextMarkModel(
|
|
|
412
414
|
}
|
|
413
415
|
|
|
414
416
|
if (op.type === 'insert_text') {
|
|
415
|
-
|
|
417
|
+
const snapshot = getEditorSnapshot({
|
|
418
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
419
|
+
slateEditorInstance: editor,
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
const markState = getMarkState(snapshot)
|
|
423
|
+
|
|
424
|
+
if (!markState) {
|
|
416
425
|
apply(op)
|
|
417
426
|
return
|
|
418
427
|
}
|
|
419
428
|
|
|
420
|
-
if (
|
|
429
|
+
if (markState.state === 'unchanged') {
|
|
421
430
|
apply(op)
|
|
422
431
|
return
|
|
423
432
|
}
|
|
@@ -426,7 +435,7 @@ export function createWithPortableTextMarkModel(
|
|
|
426
435
|
_type: 'span',
|
|
427
436
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
428
437
|
text: op.text,
|
|
429
|
-
marks:
|
|
438
|
+
marks: markState.marks,
|
|
430
439
|
})
|
|
431
440
|
|
|
432
441
|
return
|
|
@@ -488,7 +497,7 @@ export function createWithPortableTextMarkModel(
|
|
|
488
497
|
apply(op)
|
|
489
498
|
Transforms.setNodes(
|
|
490
499
|
editor,
|
|
491
|
-
{marks: snapshot
|
|
500
|
+
{marks: getActiveDecorators(snapshot)},
|
|
492
501
|
{at: op.path},
|
|
493
502
|
)
|
|
494
503
|
})
|
|
@@ -11,7 +11,6 @@ import {createWithPortableTextMarkModel} from './createWithPortableTextMarkModel
|
|
|
11
11
|
import {createWithSchemaTypes} from './createWithSchemaTypes'
|
|
12
12
|
import {createWithUndoRedo} from './createWithUndoRedo'
|
|
13
13
|
import {createWithUtils} from './createWithUtils'
|
|
14
|
-
import {pluginUpdateMarkState} from './slate-plugin.update-mark-state'
|
|
15
14
|
import {pluginUpdateSelection} from './slate-plugin.update-selection'
|
|
16
15
|
import {pluginUpdateValue} from './slate-plugin.update-value'
|
|
17
16
|
|
|
@@ -68,13 +67,10 @@ export const withPlugins = <T extends Editor>(
|
|
|
68
67
|
withPatches(
|
|
69
68
|
pluginUpdateValue(
|
|
70
69
|
editorActor.getSnapshot().context,
|
|
71
|
-
|
|
72
|
-
editorActor
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
editor: e,
|
|
76
|
-
}),
|
|
77
|
-
),
|
|
70
|
+
pluginUpdateSelection({
|
|
71
|
+
editorActor,
|
|
72
|
+
editor: e,
|
|
73
|
+
}),
|
|
78
74
|
),
|
|
79
75
|
),
|
|
80
76
|
),
|