@portabletext/editor 2.6.3 → 2.6.4
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-selecting-entire-blocks.cjs +29 -29
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +5 -5
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +3 -3
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +5 -5
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -6
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +106 -117
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +3 -3
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/_chunks-dts/behavior.types.action.d.ts +9 -9
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +3 -2
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +3 -2
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +2 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +2 -5
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +101 -112
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js +2 -1
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.cjs +132 -95
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +41 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +5 -5
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/lib/plugins/index.js +6 -5
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +3 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -1
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +14 -4
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2 -9
- package/lib/utils/index.d.ts +4 -11
- package/lib/utils/index.js +4 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +10 -9
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.deserialize.ts +1 -1
- package/src/behaviors/behavior.abstract.split.ts +2 -1
- package/src/behaviors/behavior.core.block-objects.ts +1 -1
- package/src/behaviors/behavior.core.lists.ts +2 -1
- package/src/behaviors/behavior.markdown.ts +1 -1
- package/src/converters/converter.text-plain.ts +2 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +1 -1
- package/src/editor/__tests__/RangeDecorations.test.tsx +1 -1
- package/src/editor/__tests__/self-solving.test.tsx +1 -1
- package/src/editor/components/render-element.tsx +1 -1
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -3
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +1 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
- package/src/editor/plugins/createWithSchemaTypes.ts +2 -5
- package/src/internal-utils/__tests__/valueNormalization.test.tsx +1 -1
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +1 -1
- package/src/internal-utils/build-index-maps.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/editor-selection.ts +1 -1
- package/src/internal-utils/operation-to-patches.ts +1 -1
- package/src/internal-utils/parse-blocks.test.ts +1 -1
- package/src/internal-utils/parse-blocks.ts +1 -38
- package/src/internal-utils/selection-focus-text.ts +1 -1
- package/src/internal-utils/selection-text.ts +1 -1
- package/src/internal-utils/test-editor.tsx +1 -1
- package/src/internal-utils/text-block-key.ts +1 -1
- package/src/internal-utils/text-marks.ts +1 -1
- package/src/internal-utils/text-selection.ts +1 -1
- package/src/internal-utils/to-slate-range.test.ts +1 -1
- package/src/internal-utils/to-slate-range.ts +1 -1
- package/src/internal-utils/validateValue.ts +1 -1
- package/src/internal-utils/value-annotations.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -1
- package/src/operations/behavior.operation.delete.ts +98 -2
- package/src/operations/behavior.operation.insert.block.ts +2 -1
- package/src/plugins/plugin.behavior.tsx +3 -1
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +1 -2
- package/src/plugins/plugin.markdown.test.tsx +1 -2
- package/src/selectors/selector.get-active-annotations.ts +1 -1
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selector.get-active-style.ts +1 -1
- package/src/selectors/selector.get-anchor-text-block.ts +1 -1
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-focus-block-object.ts +1 -1
- package/src/selectors/selector.get-focus-span.ts +1 -1
- package/src/selectors/selector.get-focus-text-block.ts +1 -1
- package/src/selectors/selector.get-list-state.ts +1 -1
- package/src/selectors/selector.get-next-span.ts +1 -1
- package/src/selectors/selector.get-previous-span.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +1 -1
- package/src/selectors/selector.get-selected-text-blocks.ts +1 -1
- package/src/selectors/selector.get-selection-text.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +1 -1
- package/src/selectors/selector.is-active-annotation.ts +1 -1
- package/src/selectors/selector.is-point-after-selection.ts +1 -1
- package/src/selectors/selector.is-point-before-selection.ts +1 -1
- package/src/utils/index.ts +1 -2
- package/src/utils/util.at-the-beginning-of-block.ts +1 -1
- package/src/utils/util.block-offset.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
- package/src/utils/util.get-block-end-point.ts +1 -1
- package/src/utils/util.get-block-start-point.ts +1 -1
- package/src/utils/util.is-empty-text-block.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +2 -2
- package/src/utils/util.slice-text-block.ts +2 -2
- package/src/utils/util.split-text-block.ts +1 -1
- package/src/internal-utils/terse-pt.test.ts +0 -175
- package/src/internal-utils/terse-pt.ts +0 -150
- package/src/internal-utils/test-key-generator.ts +0 -9
- package/src/utils/util.is-span.ts +0 -12
- package/src/utils/util.is-text-block.ts +0 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSchema} from '../editor/editor-schema'
|
|
3
|
-
import {isSpan, isTextBlock} from './parse-blocks'
|
|
4
4
|
|
|
5
5
|
export function getValueAnnotations(
|
|
6
6
|
schema: EditorSchema,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import {omit} from 'lodash'
|
|
2
3
|
import {Editor, Transforms} from 'slate'
|
|
3
|
-
import {
|
|
4
|
+
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
4
5
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
5
6
|
import {fromSlateValue} from '../internal-utils/values'
|
|
6
7
|
import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
2
|
+
import {
|
|
3
|
+
deleteText,
|
|
4
|
+
Editor,
|
|
5
|
+
Element,
|
|
6
|
+
Range,
|
|
7
|
+
setSelection,
|
|
8
|
+
Transforms,
|
|
9
|
+
} from 'slate'
|
|
10
|
+
import {DOMEditor} from 'slate-dom'
|
|
2
11
|
import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
12
|
import {getBlockPath} from '../internal-utils/slate-utils'
|
|
5
13
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
6
14
|
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
15
|
+
import {PortableTextSlateEditor} from '../types/editor'
|
|
7
16
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
8
17
|
|
|
9
18
|
export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -98,6 +107,32 @@ export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
|
98
107
|
)
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
if (operation.direction === 'backward' && operation.unit === 'line') {
|
|
111
|
+
const parentBlockEntry = Editor.above(operation.editor, {
|
|
112
|
+
match: (n) => Element.isElement(n) && Editor.isBlock(operation.editor, n),
|
|
113
|
+
at: range,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
if (parentBlockEntry) {
|
|
117
|
+
const [, parentBlockPath] = parentBlockEntry
|
|
118
|
+
const parentElementRange = Editor.range(
|
|
119
|
+
operation.editor,
|
|
120
|
+
parentBlockPath,
|
|
121
|
+
range.anchor,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
const currentLineRange = findCurrentLineRange(
|
|
125
|
+
operation.editor,
|
|
126
|
+
parentElementRange,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
if (!Range.isCollapsed(currentLineRange)) {
|
|
130
|
+
Transforms.delete(operation.editor, {at: currentLineRange})
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
101
136
|
const hanging = isTextBlock(context, endBlock) && endOffset === 0
|
|
102
137
|
|
|
103
138
|
deleteText(operation.editor, {
|
|
@@ -118,3 +153,64 @@ export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
|
118
153
|
})
|
|
119
154
|
}
|
|
120
155
|
}
|
|
156
|
+
|
|
157
|
+
function findCurrentLineRange(
|
|
158
|
+
editor: PortableTextSlateEditor,
|
|
159
|
+
parentRange: Range,
|
|
160
|
+
): Range {
|
|
161
|
+
const parentRangeBoundary = Editor.range(editor, Range.end(parentRange))
|
|
162
|
+
const positions = Array.from(Editor.positions(editor, {at: parentRange}))
|
|
163
|
+
|
|
164
|
+
let left = 0
|
|
165
|
+
let right = positions.length
|
|
166
|
+
let middle = Math.floor(right / 2)
|
|
167
|
+
|
|
168
|
+
if (
|
|
169
|
+
rangesAreOnSameLine(
|
|
170
|
+
editor,
|
|
171
|
+
Editor.range(editor, positions[left]),
|
|
172
|
+
parentRangeBoundary,
|
|
173
|
+
)
|
|
174
|
+
) {
|
|
175
|
+
return Editor.range(editor, positions[left], parentRangeBoundary)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (positions.length < 2) {
|
|
179
|
+
return Editor.range(
|
|
180
|
+
editor,
|
|
181
|
+
positions[positions.length - 1],
|
|
182
|
+
parentRangeBoundary,
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
while (middle !== positions.length && middle !== left) {
|
|
187
|
+
if (
|
|
188
|
+
rangesAreOnSameLine(
|
|
189
|
+
editor,
|
|
190
|
+
Editor.range(editor, positions[middle]),
|
|
191
|
+
parentRangeBoundary,
|
|
192
|
+
)
|
|
193
|
+
) {
|
|
194
|
+
right = middle
|
|
195
|
+
} else {
|
|
196
|
+
left = middle
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
middle = Math.floor((left + right) / 2)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Editor.range(editor, positions[left], parentRangeBoundary)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function rangesAreOnSameLine(editor: DOMEditor, range1: Range, range2: Range) {
|
|
206
|
+
const rect1 = DOMEditor.toDOMRange(editor, range1).getBoundingClientRect()
|
|
207
|
+
const rect2 = DOMEditor.toDOMRange(editor, range2).getBoundingClientRect()
|
|
208
|
+
|
|
209
|
+
return domRectsIntersect(rect1, rect2) && domRectsIntersect(rect2, rect1)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function domRectsIntersect(rect: DOMRect, compareRect: DOMRect) {
|
|
213
|
+
const middle = (compareRect.top + compareRect.bottom) / 2
|
|
214
|
+
|
|
215
|
+
return rect.top <= middle && rect.bottom >= middle
|
|
216
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import {isSpan} from '@portabletext/schema'
|
|
1
2
|
import {isEqual} from 'lodash'
|
|
2
3
|
import {Editor, Path, Point, Range, Transforms, type Descendant} from 'slate'
|
|
3
4
|
import {DOMEditor} from 'slate-dom'
|
|
4
|
-
import {
|
|
5
|
+
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
5
6
|
import {
|
|
6
7
|
getFocusBlock,
|
|
7
8
|
getFocusChild,
|
|
@@ -14,7 +14,9 @@ export function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {
|
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
return () => {
|
|
17
|
-
unregisterBehaviors.forEach((unregister) =>
|
|
17
|
+
unregisterBehaviors.forEach((unregister) => {
|
|
18
|
+
unregister()
|
|
19
|
+
})
|
|
18
20
|
}
|
|
19
21
|
}, [editor, props.behaviors])
|
|
20
22
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {defineSchema} from '@portabletext/schema'
|
|
2
|
+
import {createTestKeyGenerator, getTersePt} from '@portabletext/test'
|
|
2
3
|
import {page, userEvent} from '@vitest/browser/context'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
import {describe, expect, test, vi} from 'vitest'
|
|
5
6
|
import {render} from 'vitest-browser-react'
|
|
6
7
|
import {EditorProvider, PortableTextEditable, type Editor} from '..'
|
|
7
|
-
import {getTersePt} from '../internal-utils/terse-pt'
|
|
8
|
-
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
9
8
|
import {EditorRefPlugin} from './plugin.editor-ref'
|
|
10
9
|
import {AutoCloseBracketsPlugin} from './plugin.internal.auto-close-brackets'
|
|
11
10
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {defineSchema} from '@portabletext/schema'
|
|
2
|
+
import {createTestKeyGenerator, getTersePt} from '@portabletext/test'
|
|
2
3
|
import {page, userEvent} from '@vitest/browser/context'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
import {describe, expect, test, vi} from 'vitest'
|
|
5
6
|
import {render} from 'vitest-browser-react'
|
|
6
7
|
import {PortableTextEditable, type Editor} from '..'
|
|
7
8
|
import {EditorProvider} from '../editor/editor-provider'
|
|
8
|
-
import {getTersePt} from '../internal-utils/terse-pt'
|
|
9
|
-
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
10
9
|
import {getTextMarks} from '../internal-utils/text-marks'
|
|
11
10
|
import {EditorRefPlugin} from './plugin.editor-ref'
|
|
12
11
|
import {MarkdownPlugin} from './plugin.markdown'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextObject} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getMarkState} from './selector.get-mark-state'
|
|
5
5
|
import {getSelectedBlocks} from './selector.get-selected-blocks'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextListBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getSelectedBlocks} from './selector.get-selected-blocks'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getSelectedBlocks} from './selector.get-selected-blocks'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {BlockPath} from '../types/paths'
|
|
5
5
|
import {getAnchorBlock} from './selector.get-anchor-block'
|
|
6
6
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import {createTestKeyGenerator} from '@portabletext/test'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import {describe, expect, test} from 'vitest'
|
|
3
4
|
import type {EditorSelection} from '..'
|
|
4
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
5
|
-
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
6
6
|
import {getCaretWordSelection} from './selector.get-caret-word-selection'
|
|
7
7
|
|
|
8
8
|
const keyGenerator = createTestKeyGenerator()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextObject} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {BlockPath} from '../types/paths'
|
|
5
5
|
import {getFocusBlock} from './selector.get-focus-block'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextSpan} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isSpan} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {ChildPath} from '../types/paths'
|
|
5
5
|
import {getFocusChild} from './selector.get-focus-child'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {BlockPath} from '../types/paths'
|
|
5
5
|
import {getFocusBlock} from './selector.get-focus-block'
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
3
3
|
import type {BlockPath} from '../types/paths'
|
|
4
4
|
import {getFocusTextBlock} from './selector.get-focus-text-block'
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
|
|
5
5
|
import {getSelectionEndBlock} from './selector.get-selection-end-block'
|
|
6
6
|
import {getSelectionEndPoint} from './selector.get-selection-end-point'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
|
|
5
5
|
import {getSelectionStartBlock} from './selector.get-selection-start-block'
|
|
6
6
|
import {getSelectionStartPoint} from './selector.get-selection-start-point'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextSpan} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {
|
|
5
5
|
getBlockKeyFromSelectionPoint,
|
|
6
6
|
getChildKeyFromSelectionPoint,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
5
5
|
import type {BlockPath} from '../types/paths'
|
|
6
6
|
import {getSelectionEndPoint, getSelectionStartPoint} from '../utils'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
|
+
import {createTestKeyGenerator} from '@portabletext/test'
|
|
2
3
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
4
|
import {describe, expect, test} from 'vitest'
|
|
4
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
5
6
|
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
6
|
-
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
7
7
|
import type {EditorSelection} from '../types/editor'
|
|
8
8
|
import {getTrimmedSelection} from './selector.get-trimmed-selection'
|
|
9
9
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextSpan} from '@sanity/types'
|
|
2
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {
|
|
5
5
|
getBlockKeyFromSelectionPoint,
|
|
6
6
|
getChildKeyFromSelectionPoint,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
3
3
|
import {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'
|
|
4
4
|
import {getSelectedBlocks} from './selector.get-selected-blocks'
|
|
5
5
|
|
package/src/utils/index.ts
CHANGED
|
@@ -16,8 +16,7 @@ export {isEqualSelectionPoints} from './util.is-equal-selection-points'
|
|
|
16
16
|
export {isEqualSelections} from './util.is-equal-selections'
|
|
17
17
|
export {isKeyedSegment} from './util.is-keyed-segment'
|
|
18
18
|
export {isSelectionCollapsed} from './util.is-selection-collapsed'
|
|
19
|
-
export {isSpan} from '
|
|
20
|
-
export {isTextBlock} from './util.is-text-block'
|
|
19
|
+
export {isSpan, isTextBlock} from '@portabletext/schema'
|
|
21
20
|
export {mergeTextBlocks} from './util.merge-text-blocks'
|
|
22
21
|
export {reverseSelection} from './util.reverse-selection'
|
|
23
22
|
export {selectionPointToBlockOffset} from './util.selection-point-to-block-offset'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
|
|
5
5
|
import {isSelectionCollapsed} from './util.is-selection-collapsed'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
5
5
|
import type {BlockPath} from '../types/paths'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
-
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
5
5
|
import type {BlockPath} from '../types/paths'
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
4
4
|
import {getTextBlockText} from './util.get-text-block-text'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorContext} from '..'
|
|
3
4
|
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
4
|
-
import {isTextBlock} from './util.is-text-block'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @beta
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
|
-
import type {EditorContext} from '
|
|
3
|
-
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
3
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
4
|
import {
|
|
5
5
|
getBlockKeyFromSelectionPoint,
|
|
6
6
|
getChildKeyFromSelectionPoint,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSpan} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'
|
|
2
|
-
import type {EditorContext} from '
|
|
3
|
-
import {isSpan} from '../internal-utils/parse-blocks'
|
|
3
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
4
|
import {
|
|
5
5
|
getBlockKeyFromSelectionPoint,
|
|
6
6
|
getChildKeyFromSelectionPoint,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import {isSpan} from '@portabletext/schema'
|
|
1
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
3
|
import type {EditorSelectionPoint} from '..'
|
|
3
4
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
-
import {isSpan} from './util.is-span'
|
|
5
5
|
import {sliceTextBlock} from './util.slice-text-block'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
|
-
import {expect, test} from 'vitest'
|
|
3
|
-
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
4
|
-
import {getTersePt, parseTersePt, parseTersePtString} from './terse-pt'
|
|
5
|
-
|
|
6
|
-
const keyGenerator = createTestKeyGenerator()
|
|
7
|
-
|
|
8
|
-
test(getTersePt.name, () => {
|
|
9
|
-
const schema = compileSchema(defineSchema({}))
|
|
10
|
-
const fooBlock = {
|
|
11
|
-
_key: 'b1',
|
|
12
|
-
_type: 'block',
|
|
13
|
-
children: [{_key: 's1', _type: 'span', text: 'foo'}],
|
|
14
|
-
}
|
|
15
|
-
const emptyBlock = {
|
|
16
|
-
_key: 'b2',
|
|
17
|
-
_type: 'block',
|
|
18
|
-
children: [{_key: 's2', _type: 'span', text: ''}],
|
|
19
|
-
}
|
|
20
|
-
const barBlock = {
|
|
21
|
-
_key: 'b3',
|
|
22
|
-
_type: 'block',
|
|
23
|
-
children: [{_key: 's3', _type: 'span', text: 'bar'}],
|
|
24
|
-
}
|
|
25
|
-
const softReturnBlock = {
|
|
26
|
-
_key: 'b4',
|
|
27
|
-
_type: 'block',
|
|
28
|
-
children: [{_key: 's4', _type: 'span', text: 'foo\nbar'}],
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
expect(getTersePt({schema, value: [fooBlock, barBlock]})).toEqual([
|
|
32
|
-
'foo',
|
|
33
|
-
'bar',
|
|
34
|
-
])
|
|
35
|
-
expect(getTersePt({schema, value: [emptyBlock, barBlock]})).toEqual([
|
|
36
|
-
'',
|
|
37
|
-
'bar',
|
|
38
|
-
])
|
|
39
|
-
expect(getTersePt({schema, value: [fooBlock, emptyBlock, barBlock]})).toEqual(
|
|
40
|
-
['foo', '', 'bar'],
|
|
41
|
-
)
|
|
42
|
-
expect(getTersePt({schema, value: [fooBlock, softReturnBlock]})).toEqual([
|
|
43
|
-
'foo',
|
|
44
|
-
'foo\nbar',
|
|
45
|
-
])
|
|
46
|
-
|
|
47
|
-
expect(
|
|
48
|
-
getTersePt({
|
|
49
|
-
schema,
|
|
50
|
-
value: [
|
|
51
|
-
{
|
|
52
|
-
_key: keyGenerator(),
|
|
53
|
-
_type: 'block',
|
|
54
|
-
children: [{_key: keyGenerator(), _type: 'span', text: 'foo'}],
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
}),
|
|
58
|
-
).toEqual(['foo'])
|
|
59
|
-
expect(
|
|
60
|
-
getTersePt({
|
|
61
|
-
schema,
|
|
62
|
-
value: [
|
|
63
|
-
{
|
|
64
|
-
_key: keyGenerator(),
|
|
65
|
-
_type: 'block',
|
|
66
|
-
children: [{_key: keyGenerator(), _type: 'span', text: 'foo'}],
|
|
67
|
-
listItem: 'number',
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
}),
|
|
71
|
-
).toEqual(['#:foo'])
|
|
72
|
-
expect(
|
|
73
|
-
getTersePt({
|
|
74
|
-
schema,
|
|
75
|
-
value: [
|
|
76
|
-
{
|
|
77
|
-
_key: keyGenerator(),
|
|
78
|
-
_type: 'block',
|
|
79
|
-
children: [{_key: keyGenerator(), _type: 'span', text: 'foo'}],
|
|
80
|
-
listItem: 'number',
|
|
81
|
-
style: 'h3',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
}),
|
|
85
|
-
).toEqual(['#h3:foo'])
|
|
86
|
-
expect(
|
|
87
|
-
getTersePt({
|
|
88
|
-
schema,
|
|
89
|
-
value: [
|
|
90
|
-
{
|
|
91
|
-
_key: keyGenerator(),
|
|
92
|
-
_type: 'block',
|
|
93
|
-
children: [{_key: keyGenerator(), _type: 'span', text: 'foo'}],
|
|
94
|
-
level: 2,
|
|
95
|
-
listItem: 'number',
|
|
96
|
-
style: 'h3',
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
}),
|
|
100
|
-
).toEqual(['>>#h3:foo'])
|
|
101
|
-
expect(
|
|
102
|
-
getTersePt({
|
|
103
|
-
schema,
|
|
104
|
-
value: [
|
|
105
|
-
{
|
|
106
|
-
_key: keyGenerator(),
|
|
107
|
-
_type: 'block',
|
|
108
|
-
children: [{_key: keyGenerator(), _type: 'span', text: 'foo'}],
|
|
109
|
-
style: 'h3',
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
}),
|
|
113
|
-
).toEqual(['h3:foo'])
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
test(parseTersePtString.name, () => {
|
|
117
|
-
expect(parseTersePtString('foo')).toEqual(['foo'])
|
|
118
|
-
expect(parseTersePtString('foo,bar')).toEqual(['foo,bar'])
|
|
119
|
-
expect(parseTersePtString('foo,bar|baz')).toEqual(['foo,bar', 'baz'])
|
|
120
|
-
expect(parseTersePtString('|foo')).toEqual(['', 'foo'])
|
|
121
|
-
expect(parseTersePtString('foo|')).toEqual(['foo', ''])
|
|
122
|
-
expect(parseTersePtString('foo|bar\nbaz')).toEqual(['foo', 'bar\nbaz'])
|
|
123
|
-
expect(parseTersePtString('f,oo||ba,r')).toEqual(['f,oo', '', 'ba,r'])
|
|
124
|
-
expect(parseTersePtString('|')).toEqual(['', ''])
|
|
125
|
-
expect(parseTersePtString('||')).toEqual(['', '', ''])
|
|
126
|
-
expect(parseTersePtString('>>#h3:foo')).toEqual(['>>#h3:foo'])
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test(parseTersePt.name, () => {
|
|
130
|
-
expect(
|
|
131
|
-
parseTersePt(
|
|
132
|
-
{
|
|
133
|
-
schema: compileSchema(defineSchema({})),
|
|
134
|
-
keyGenerator: createTestKeyGenerator(),
|
|
135
|
-
},
|
|
136
|
-
parseTersePtString('{image}|foo|>>#h4:bar|-:baz,fizz|,{stock-ticker},'),
|
|
137
|
-
),
|
|
138
|
-
).toEqual([
|
|
139
|
-
{
|
|
140
|
-
_key: 'k0',
|
|
141
|
-
_type: 'image',
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
_key: 'k1',
|
|
145
|
-
_type: 'block',
|
|
146
|
-
children: [{_key: 'k2', _type: 'span', text: 'foo'}],
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
_key: 'k3',
|
|
150
|
-
_type: 'block',
|
|
151
|
-
children: [{_key: 'k4', _type: 'span', text: 'bar'}],
|
|
152
|
-
level: 2,
|
|
153
|
-
listItem: 'number',
|
|
154
|
-
style: 'h4',
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
_key: 'k5',
|
|
158
|
-
_type: 'block',
|
|
159
|
-
children: [
|
|
160
|
-
{_key: 'k6', _type: 'span', text: 'baz'},
|
|
161
|
-
{_key: 'k7', _type: 'span', text: 'fizz'},
|
|
162
|
-
],
|
|
163
|
-
listItem: 'bullet',
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
_key: 'k8',
|
|
167
|
-
_type: 'block',
|
|
168
|
-
children: [
|
|
169
|
-
{_key: 'k9', _type: 'span', text: ''},
|
|
170
|
-
{_key: 'k10', _type: 'stock-ticker'},
|
|
171
|
-
{_key: 'k11', _type: 'span', text: ''},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
])
|
|
175
|
-
})
|