@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -59,8 +59,6 @@
|
|
|
59
59
|
"@portabletext/toolkit": "^2.0.15",
|
|
60
60
|
"@sanity/block-tools": "^3.55.0",
|
|
61
61
|
"@sanity/diff-match-patch": "^3.1.1",
|
|
62
|
-
"@sanity/eslint-config-i18n": "^1.1.0",
|
|
63
|
-
"@sanity/eslint-config-studio": "^4.0.0",
|
|
64
62
|
"@sanity/pkg-utils": "^6.10.10",
|
|
65
63
|
"@sanity/schema": "^3.55.0",
|
|
66
64
|
"@sanity/test": "0.0.1-alpha.1",
|
|
@@ -78,20 +76,8 @@
|
|
|
78
76
|
"@types/react": "^18.3.3",
|
|
79
77
|
"@types/react-dom": "^18.3.0",
|
|
80
78
|
"@types/ws": "~8.5.12",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "^8.2.0",
|
|
82
|
-
"@typescript-eslint/parser": "^8.2.0",
|
|
83
79
|
"@vitejs/plugin-react": "^4.3.1",
|
|
84
80
|
"dotenv": "^16.4.5",
|
|
85
|
-
"eslint": "^8.57.0",
|
|
86
|
-
"eslint-config-prettier": "^9.1.0",
|
|
87
|
-
"eslint-config-sanity": "^7.1.2",
|
|
88
|
-
"eslint-import-resolver-typescript": "^3.6.1",
|
|
89
|
-
"eslint-plugin-import": "^2.29.1",
|
|
90
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
91
|
-
"eslint-plugin-react-compiler": "0.0.0-experimental-eeb1b2a-20240818",
|
|
92
|
-
"eslint-plugin-tsdoc": "^0.3.0",
|
|
93
|
-
"eslint-plugin-unicorn": "^55.0.0",
|
|
94
|
-
"eslint-plugin-unused-imports": "^4.1.3",
|
|
95
81
|
"express": "^4.19.2",
|
|
96
82
|
"express-ws": "^5.0.2",
|
|
97
83
|
"jest": "^29.7.0",
|
|
@@ -125,12 +111,12 @@
|
|
|
125
111
|
},
|
|
126
112
|
"scripts": {
|
|
127
113
|
"build": "pkg-utils build --strict --check --clean",
|
|
128
|
-
"check:lint": "
|
|
114
|
+
"check:lint": "biome lint .",
|
|
129
115
|
"check:types": "tsc",
|
|
130
116
|
"clean": "del .turbo && del lib && del node_modules",
|
|
131
117
|
"dev": "pkg-utils watch",
|
|
132
118
|
"dev:e2e-server": "cd ./e2e-tests/ && tsx serve",
|
|
133
|
-
"lint:fix": "
|
|
119
|
+
"lint:fix": "biome lint --write .",
|
|
134
120
|
"test": "jest",
|
|
135
121
|
"test:e2e": "jest --config=e2e-tests/e2e.config.ts",
|
|
136
122
|
"test:e2e:watch": "jest --config=e2e-tests/e2e.config.ts --watch",
|
package/src/editor/Editable.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {isEqual, noop} from 'lodash'
|
|
3
3
|
import {
|
|
4
4
|
forwardRef,
|
|
@@ -35,23 +35,23 @@ import {
|
|
|
35
35
|
type RenderElementProps,
|
|
36
36
|
type RenderLeafProps,
|
|
37
37
|
} from 'slate-react'
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
import type {
|
|
39
|
+
EditorChange,
|
|
40
|
+
EditorSelection,
|
|
41
|
+
OnCopyFn,
|
|
42
|
+
OnPasteFn,
|
|
43
|
+
RangeDecoration,
|
|
44
|
+
RenderAnnotationFunction,
|
|
45
|
+
RenderBlockFunction,
|
|
46
|
+
RenderChildFunction,
|
|
47
|
+
RenderDecoratorFunction,
|
|
48
|
+
RenderListItemFunction,
|
|
49
|
+
RenderPlaceholderFunction,
|
|
50
|
+
RenderStyleFunction,
|
|
51
|
+
ScrollSelectionIntoViewFunction,
|
|
52
52
|
} from '../types/editor'
|
|
53
|
-
import
|
|
54
|
-
import
|
|
53
|
+
import type {HotkeyOptions} from '../types/options'
|
|
54
|
+
import type {SlateTextBlock, VoidElement} from '../types/slate'
|
|
55
55
|
import {debugWithName} from '../utils/debug'
|
|
56
56
|
import {
|
|
57
57
|
moveRangeByOperation,
|
|
@@ -341,7 +341,9 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
|
|
|
341
341
|
return
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
if (rangeDecorationState.length > 0) {
|
|
345
|
+
setRangeDecorationsState([])
|
|
346
|
+
}
|
|
345
347
|
},
|
|
346
348
|
[portableTextEditor, rangeDecorations, schemaTypes, slateEditor],
|
|
347
349
|
)
|
|
@@ -470,7 +472,7 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
|
|
|
470
472
|
}
|
|
471
473
|
})
|
|
472
474
|
.catch((error) => {
|
|
473
|
-
console.error(error)
|
|
475
|
+
console.error(error)
|
|
474
476
|
return error
|
|
475
477
|
})
|
|
476
478
|
.finally(() => {
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ArrayDefinition,
|
|
3
|
+
ArraySchemaType,
|
|
4
|
+
BlockSchemaType,
|
|
5
|
+
ObjectSchemaType,
|
|
6
|
+
Path,
|
|
7
|
+
PortableTextBlock,
|
|
8
|
+
PortableTextChild,
|
|
9
|
+
PortableTextObject,
|
|
10
|
+
SpanSchemaType,
|
|
11
11
|
} from '@sanity/types'
|
|
12
12
|
import {Component, type MutableRefObject, type PropsWithChildren} from 'react'
|
|
13
13
|
import {Subject} from 'rxjs'
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
import type {
|
|
15
|
+
EditableAPI,
|
|
16
|
+
EditableAPIDeleteOptions,
|
|
17
|
+
EditorChange,
|
|
18
|
+
EditorChanges,
|
|
19
|
+
EditorSelection,
|
|
20
|
+
PatchObservable,
|
|
21
|
+
PortableTextMemberSchemaTypes,
|
|
22
22
|
} from '../types/editor'
|
|
23
23
|
import {debugWithName} from '../utils/debug'
|
|
24
24
|
import {getPortableTextMemberSchemaTypes} from '../utils/getPortableTextMemberSchemaTypes'
|
|
@@ -161,7 +161,7 @@ export class PortableTextEditor extends Component<PortableTextEditorProps> {
|
|
|
161
161
|
const maxBlocks =
|
|
162
162
|
typeof this.props.maxBlocks === 'undefined'
|
|
163
163
|
? undefined
|
|
164
|
-
: parseInt(this.props.maxBlocks.toString(), 10) || undefined
|
|
164
|
+
: Number.parseInt(this.props.maxBlocks.toString(), 10) || undefined
|
|
165
165
|
|
|
166
166
|
const readOnly = Boolean(this.props.readOnly)
|
|
167
167
|
const keyGenerator = this.props.keyGenerator || defaultKeyGenerator
|
|
@@ -239,7 +239,6 @@ export class PortableTextEditor extends Component<PortableTextEditorProps> {
|
|
|
239
239
|
editor: PortableTextEditor,
|
|
240
240
|
element: PortableTextBlock | PortableTextChild,
|
|
241
241
|
) => {
|
|
242
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
243
242
|
return editor.editable?.findDOMNode(element)
|
|
244
243
|
}
|
|
245
244
|
static findByPath = (editor: PortableTextEditor, path: Path) => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
|
-
|
|
3
|
-
import {type PortableTextBlock} from '@sanity/types'
|
|
2
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
4
3
|
import {render, waitFor} from '@testing-library/react'
|
|
5
4
|
import {createRef, type RefObject} from 'react'
|
|
6
|
-
import
|
|
5
|
+
import type {EditorSelection} from '../..'
|
|
7
6
|
import {PortableTextEditor} from '../PortableTextEditor'
|
|
8
7
|
import {PortableTextEditorTester, schemaType} from './PortableTextEditorTester'
|
|
9
8
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
|
-
|
|
3
|
-
import {type PortableTextBlock} from '@sanity/types'
|
|
2
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
4
3
|
import {render, waitFor} from '@testing-library/react'
|
|
5
4
|
import {createRef, type ReactNode, type RefObject} from 'react'
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import type {RangeDecoration} from '../..'
|
|
6
|
+
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
8
7
|
import {PortableTextEditorTester, schemaType} from './PortableTextEditorTester'
|
|
9
8
|
|
|
10
9
|
const helloBlock: PortableTextBlock = {
|
|
@@ -22,7 +21,7 @@ const RangeDecorationTestComponent = ({children}: {children?: ReactNode}) => {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
describe('RangeDecorations', () => {
|
|
25
|
-
it
|
|
24
|
+
it('only render range decorations as necessary', async () => {
|
|
26
25
|
const editorRef: RefObject<PortableTextEditor> = createRef()
|
|
27
26
|
const onChange = jest.fn()
|
|
28
27
|
const value = [helloBlock]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {describe, expect, jest, test} from '@jest/globals'
|
|
2
2
|
import {Schema} from '@sanity/schema'
|
|
3
|
-
import
|
|
3
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
4
4
|
import {render, waitFor} from '@testing-library/react'
|
|
5
5
|
import {createRef, type RefObject} from 'react'
|
|
6
|
-
import
|
|
6
|
+
import type {EditorChange, EditorSelection} from '../../types/editor'
|
|
7
7
|
import {PortableTextEditable} from '../Editable'
|
|
8
8
|
import {PortableTextEditor} from '../PortableTextEditor'
|
|
9
9
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
|
-
import
|
|
2
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {render, waitFor} from '@testing-library/react'
|
|
4
4
|
import {createRef, type RefObject} from 'react'
|
|
5
5
|
import {PortableTextEditor} from '../PortableTextEditor'
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type PortableTextObject,
|
|
7
|
-
type PortableTextTextBlock,
|
|
1
|
+
import type {
|
|
2
|
+
Path,
|
|
3
|
+
PortableTextChild,
|
|
4
|
+
PortableTextObject,
|
|
5
|
+
PortableTextTextBlock,
|
|
8
6
|
} from '@sanity/types'
|
|
9
7
|
import {useMemo, useRef, type FunctionComponent, type ReactElement} from 'react'
|
|
10
8
|
import {Editor, Range, Element as SlateElement} from 'slate'
|
|
@@ -14,13 +12,13 @@ import {
|
|
|
14
12
|
useSlateStatic,
|
|
15
13
|
type RenderElementProps,
|
|
16
14
|
} from 'slate-react'
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
import type {
|
|
16
|
+
BlockRenderProps,
|
|
17
|
+
PortableTextMemberSchemaTypes,
|
|
18
|
+
RenderBlockFunction,
|
|
19
|
+
RenderChildFunction,
|
|
20
|
+
RenderListItemFunction,
|
|
21
|
+
RenderStyleFunction,
|
|
24
22
|
} from '../../types/editor'
|
|
25
23
|
import {debugWithName} from '../../utils/debug'
|
|
26
24
|
import {fromSlateValue} from '../../utils/values'
|
|
@@ -91,7 +89,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
91
89
|
|
|
92
90
|
let renderedBlock = children
|
|
93
91
|
|
|
94
|
-
let className
|
|
92
|
+
let className: string | undefined
|
|
95
93
|
|
|
96
94
|
const blockPath: Path = useMemo(() => [{_key: element._key}], [element])
|
|
97
95
|
|
|
@@ -180,7 +178,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
180
178
|
editorElementRef: blockRef,
|
|
181
179
|
})
|
|
182
180
|
}
|
|
183
|
-
let level
|
|
181
|
+
let level: number | undefined
|
|
184
182
|
if (isListItem) {
|
|
185
183
|
if (typeof element.level === 'number') {
|
|
186
184
|
level = element.level
|
|
@@ -276,7 +274,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
276
274
|
schemaTypes.block.name,
|
|
277
275
|
KEY_TO_VALUE_ELEMENT.get(editor),
|
|
278
276
|
)[0]
|
|
279
|
-
let renderedBlockFromProps
|
|
277
|
+
let renderedBlockFromProps: JSX.Element | undefined
|
|
280
278
|
if (renderBlock) {
|
|
281
279
|
const _props: Omit<BlockRenderProps, 'type'> = Object.defineProperty(
|
|
282
280
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Path,
|
|
3
|
+
PortableTextObject,
|
|
4
|
+
PortableTextTextBlock,
|
|
5
5
|
} from '@sanity/types'
|
|
6
6
|
import {isEqual, uniq} from 'lodash'
|
|
7
7
|
import {
|
|
@@ -15,14 +15,14 @@ import {
|
|
|
15
15
|
} from 'react'
|
|
16
16
|
import {Text} from 'slate'
|
|
17
17
|
import {useSelected, type RenderLeafProps} from 'slate-react'
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
import type {
|
|
19
|
+
BlockAnnotationRenderProps,
|
|
20
|
+
BlockChildRenderProps,
|
|
21
|
+
BlockDecoratorRenderProps,
|
|
22
|
+
PortableTextMemberSchemaTypes,
|
|
23
|
+
RenderAnnotationFunction,
|
|
24
|
+
RenderChildFunction,
|
|
25
|
+
RenderDecoratorFunction,
|
|
26
26
|
} from '../../types/editor'
|
|
27
27
|
import {debugWithName} from '../../utils/debug'
|
|
28
28
|
import {usePortableTextEditor} from '../hooks/usePortableTextEditor'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {useEffect, useMemo, useState, type PropsWithChildren} from 'react'
|
|
2
2
|
import {createEditor} from 'slate'
|
|
3
3
|
import {Slate, withReact} from 'slate-react'
|
|
4
|
-
import
|
|
4
|
+
import type {PatchObservable} from '../../types/editor'
|
|
5
5
|
import {debugWithName} from '../../utils/debug'
|
|
6
6
|
import {KEY_TO_SLATE_ELEMENT, KEY_TO_VALUE_ELEMENT} from '../../utils/weakMaps'
|
|
7
7
|
import {withPlugins} from '../plugins'
|
|
8
|
-
import
|
|
8
|
+
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
9
9
|
|
|
10
10
|
const debug = debugWithName('component:PortableTextEditor:SlateContainer')
|
|
11
11
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type {Patch} from '@portabletext/patches'
|
|
2
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {throttle} from 'lodash'
|
|
4
4
|
import {useCallback, useEffect, useMemo, useRef} from 'react'
|
|
5
5
|
import {Editor} from 'slate'
|
|
6
6
|
import {useSlate} from 'slate-react'
|
|
7
|
-
import
|
|
7
|
+
import type {EditorChange, EditorChanges} from '../../types/editor'
|
|
8
8
|
import {debugWithName} from '../../utils/debug'
|
|
9
9
|
import {IS_PROCESSING_LOCAL_CHANGES} from '../../utils/weakMaps'
|
|
10
10
|
import {usePortableTextEditor} from '../hooks/usePortableTextEditor'
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {type PortableTextBlock} from '@sanity/types'
|
|
1
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
3
2
|
import {debounce, isEqual} from 'lodash'
|
|
4
3
|
import {useCallback, useMemo, useRef} from 'react'
|
|
5
4
|
import {Editor, Text, Transforms, type Descendant, type Node} from 'slate'
|
|
6
5
|
import {useSlate} from 'slate-react'
|
|
7
|
-
import {
|
|
8
|
-
type EditorChange,
|
|
9
|
-
type PortableTextSlateEditor,
|
|
10
|
-
} from '../../types/editor'
|
|
6
|
+
import type {EditorChange, PortableTextSlateEditor} from '../../types/editor'
|
|
11
7
|
import {debugWithName} from '../../utils/debug'
|
|
12
8
|
import {validateValue} from '../../utils/validateValue'
|
|
13
9
|
import {toSlateValue, VOID_CHILD_KEY} from '../../utils/values'
|
|
@@ -18,7 +14,7 @@ import {
|
|
|
18
14
|
} from '../../utils/withChanges'
|
|
19
15
|
import {withoutPatching} from '../../utils/withoutPatching'
|
|
20
16
|
import {withoutSaving} from '../plugins/createWithUndoRedo'
|
|
21
|
-
import
|
|
17
|
+
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
22
18
|
|
|
23
19
|
const debug = debugWithName('hook:useSyncValue')
|
|
24
20
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type {PortableTextObject} from '@sanity/types'
|
|
2
2
|
import {useCallback, type ReactNode} from 'react'
|
|
3
3
|
|
|
4
4
|
type Props = {
|
|
@@ -7,7 +7,6 @@ type Props = {
|
|
|
7
7
|
}
|
|
8
8
|
export function DefaultAnnotation(props: Props) {
|
|
9
9
|
const handleClick = useCallback(
|
|
10
|
-
// eslint-disable-next-line no-alert
|
|
11
10
|
() => alert(JSON.stringify(props.annotation)),
|
|
12
11
|
[props.annotation],
|
|
13
12
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it} from '@jest/globals'
|
|
2
2
|
import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'
|
|
3
|
-
import
|
|
3
|
+
import type {Descendant} from 'slate'
|
|
4
4
|
import {exportedForTesting} from '../createWithInsertData'
|
|
5
5
|
|
|
6
6
|
const initialValue = [
|
|
@@ -60,14 +60,12 @@ describe('plugin: createWithInsertData _regenerateKeys', () => {
|
|
|
60
60
|
name: 'color',
|
|
61
61
|
jsonType: 'object',
|
|
62
62
|
fields: [],
|
|
63
|
-
// eslint-disable-next-line camelcase
|
|
64
63
|
__experimental_search: [],
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
66
|
name: 'link',
|
|
68
67
|
jsonType: 'object',
|
|
69
68
|
fields: [],
|
|
70
|
-
// eslint-disable-next-line camelcase
|
|
71
69
|
__experimental_search: [],
|
|
72
70
|
},
|
|
73
71
|
],
|
|
@@ -155,7 +153,6 @@ describe('plugin: createWithInsertData _regenerateKeys', () => {
|
|
|
155
153
|
name: 'color',
|
|
156
154
|
jsonType: 'object',
|
|
157
155
|
fields: [],
|
|
158
|
-
// eslint-disable-next-line camelcase
|
|
159
156
|
__experimental_search: [],
|
|
160
157
|
},
|
|
161
158
|
],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
|
-
import
|
|
2
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {render, waitFor} from '@testing-library/react'
|
|
4
4
|
import {createRef, type RefObject} from 'react'
|
|
5
5
|
import {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
|
-
/* eslint-disable max-nested-callbacks */
|
|
3
2
|
import {render, waitFor} from '@testing-library/react'
|
|
4
3
|
import {createRef, type RefObject} from 'react'
|
|
5
4
|
import {
|
|
@@ -7,7 +6,7 @@ import {
|
|
|
7
6
|
schemaType,
|
|
8
7
|
schemaTypeWithColorAndLink,
|
|
9
8
|
} from '../../__tests__/PortableTextEditorTester'
|
|
10
|
-
import
|
|
9
|
+
import type {EditorSelection} from '../../../types/editor'
|
|
11
10
|
import {PortableTextEditor} from '../../PortableTextEditor'
|
|
12
11
|
|
|
13
12
|
describe('plugin:withPortableTextMarksModel', () => {
|
|
@@ -739,7 +738,6 @@ Array [
|
|
|
739
738
|
},
|
|
740
739
|
})
|
|
741
740
|
|
|
742
|
-
// // eslint-disable-next-line max-nested-callbacks
|
|
743
741
|
const linkType = editorRef.current.schemaTypes.annotations.find(
|
|
744
742
|
(a) => a.name === 'link',
|
|
745
743
|
)
|
|
@@ -19,13 +19,13 @@ import {
|
|
|
19
19
|
Transforms,
|
|
20
20
|
} from 'slate'
|
|
21
21
|
import {ReactEditor} from 'slate-react'
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
import type {DOMNode} from 'slate-react/dist/utils/dom'
|
|
23
|
+
import type {
|
|
24
|
+
EditableAPI,
|
|
25
|
+
EditableAPIDeleteOptions,
|
|
26
|
+
EditorSelection,
|
|
27
|
+
PortableTextMemberSchemaTypes,
|
|
28
|
+
PortableTextSlateEditor,
|
|
29
29
|
} from '../../types/editor'
|
|
30
30
|
import {debugWithName} from '../../utils/debug'
|
|
31
31
|
import {toPortableTextRange, toSlateRange} from '../../utils/ranges'
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
KEY_TO_VALUE_ELEMENT,
|
|
39
39
|
SLATE_TO_PORTABLE_TEXT_RANGE,
|
|
40
40
|
} from '../../utils/weakMaps'
|
|
41
|
-
import
|
|
41
|
+
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
42
42
|
|
|
43
43
|
const debug = debugWithName('API:editable')
|
|
44
44
|
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
/* eslint-disable complexity */
|
|
3
1
|
import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'
|
|
4
2
|
import {isHotkey} from 'is-hotkey-esm'
|
|
5
|
-
import
|
|
3
|
+
import type {KeyboardEvent} from 'react'
|
|
6
4
|
import {Editor, Node, Path, Range, Transforms} from 'slate'
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import type {ReactEditor} from 'slate-react'
|
|
6
|
+
import type {
|
|
7
|
+
PortableTextMemberSchemaTypes,
|
|
8
|
+
PortableTextSlateEditor,
|
|
11
9
|
} from '../../types/editor'
|
|
12
|
-
import
|
|
13
|
-
import
|
|
10
|
+
import type {HotkeyOptions} from '../../types/options'
|
|
11
|
+
import type {SlateTextBlock, VoidElement} from '../../types/slate'
|
|
14
12
|
import {debugWithName} from '../../utils/debug'
|
|
15
|
-
import
|
|
13
|
+
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
16
14
|
|
|
17
15
|
const debug = debugWithName('plugin:withHotKeys')
|
|
18
16
|
|
|
@@ -42,7 +40,6 @@ export function createWithHotkeys(
|
|
|
42
40
|
// Wire up custom marks hotkeys
|
|
43
41
|
Object.keys(activeHotkeys).forEach((cat) => {
|
|
44
42
|
if (cat === 'marks') {
|
|
45
|
-
// eslint-disable-next-line guard-for-in
|
|
46
43
|
for (const hotkey in activeHotkeys[cat]) {
|
|
47
44
|
if (reservedHotkeys.includes(hotkey)) {
|
|
48
45
|
throw new Error(`The hotkey ${hotkey} is reserved!`)
|
|
@@ -59,7 +56,6 @@ export function createWithHotkeys(
|
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
if (cat === 'custom') {
|
|
62
|
-
// eslint-disable-next-line guard-for-in
|
|
63
59
|
for (const hotkey in activeHotkeys[cat]) {
|
|
64
60
|
if (reservedHotkeys.includes(hotkey)) {
|
|
65
61
|
throw new Error(`The hotkey ${hotkey} is reserved!`)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {isEqual} from 'lodash'
|
|
2
2
|
import {Editor, Node, Path, Range, Transforms} from 'slate'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type {
|
|
4
|
+
PortableTextMemberSchemaTypes,
|
|
5
|
+
PortableTextSlateEditor,
|
|
6
6
|
} from '../../types/editor'
|
|
7
|
-
import
|
|
7
|
+
import type {SlateTextBlock, VoidElement} from '../../types/slate'
|
|
8
8
|
|
|
9
9
|
export function createWithInsertBreak(
|
|
10
10
|
types: PortableTextMemberSchemaTypes,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {htmlToBlocks, normalizeBlock} from '@sanity/block-tools'
|
|
2
|
-
import
|
|
2
|
+
import type {PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
3
3
|
import {isEqual, uniq} from 'lodash'
|
|
4
4
|
import {Editor, Range, Transforms, type Descendant, type Node} from 'slate'
|
|
5
5
|
import {ReactEditor} from 'slate-react'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import type {
|
|
7
|
+
EditorChanges,
|
|
8
|
+
PortableTextMemberSchemaTypes,
|
|
9
|
+
PortableTextSlateEditor,
|
|
10
10
|
} from '../../types/editor'
|
|
11
11
|
import {debugWithName} from '../../utils/debug'
|
|
12
12
|
import {validateValue} from '../../utils/validateValue'
|
|
@@ -188,7 +188,7 @@ export function createWithInsertData(
|
|
|
188
188
|
debug('Inserting data', data)
|
|
189
189
|
let portableText: PortableTextBlock[]
|
|
190
190
|
let fragment: Node[]
|
|
191
|
-
let insertedType
|
|
191
|
+
let insertedType: string | undefined
|
|
192
192
|
|
|
193
193
|
if (html) {
|
|
194
194
|
portableText = htmlToBlocks(html, schemaTypes.portableText, {
|
|
@@ -335,8 +335,7 @@ function _regenerateKeys(
|
|
|
335
335
|
...child,
|
|
336
336
|
marks:
|
|
337
337
|
child.marks && child.marks.includes(oldKey)
|
|
338
|
-
?
|
|
339
|
-
[...child.marks]
|
|
338
|
+
? [...child.marks]
|
|
340
339
|
.filter((mark) => mark !== oldKey)
|
|
341
340
|
.concat(newKey)
|
|
342
341
|
: child.marks,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Editor, Element, Node, Transforms} from 'slate'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type {
|
|
3
|
+
PortableTextMemberSchemaTypes,
|
|
4
|
+
PortableTextSlateEditor,
|
|
5
5
|
} from '../../types/editor'
|
|
6
6
|
import {isChangingRemotely} from '../../utils/withChanges'
|
|
7
7
|
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|