@portabletext/editor 1.48.9 → 1.48.11
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/editor-provider.cjs +879 -169
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +464 -19
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +9 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-es/editor-provider.js +773 -65
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +448 -3
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +9 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/behaviors/index.cjs +27 -377
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +3696 -13915
- package/lib/behaviors/index.d.ts +3696 -13915
- package/lib/behaviors/index.js +22 -377
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +17 -17
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3008 -394
- package/lib/index.d.ts +3008 -394
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +347 -30
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3008 -395
- package/lib/plugins/index.d.ts +3008 -395
- package/lib/plugins/index.js +324 -8
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +29 -29
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +3007 -387
- package/lib/selectors/index.d.ts +3007 -387
- package/lib/selectors/index.js +2 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3008 -389
- package/lib/utils/index.d.ts +3008 -389
- package/lib/utils/index.js +2 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.emoji-picker.ts +0 -6
- package/src/behaviors/behavior.markdown.ts +0 -48
- package/src/behaviors/index.ts +0 -15
- package/src/editor/create-editor.ts +0 -3
- package/src/editor/editor-machine.ts +105 -52
- package/src/editor/sync-machine.ts +10 -4
- package/src/internal-utils/__tests__/operationToPatches.test.ts +0 -2
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -2
- package/src/plugins/plugin.core.tsx +1 -1
- package/lib/_chunks-cjs/behavior.core.cjs +0 -700
- package/lib/_chunks-cjs/behavior.core.cjs.map +0 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +0 -321
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -449
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +0 -1
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs +0 -10
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +0 -1
- package/lib/_chunks-es/behavior.core.js +0 -703
- package/lib/_chunks-es/behavior.core.js.map +0 -1
- package/lib/_chunks-es/behavior.markdown.js +0 -325
- package/lib/_chunks-es/behavior.markdown.js.map +0 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +0 -451
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +0 -1
- package/lib/_chunks-es/util.get-selection-start-point.js +0 -11
- package/lib/_chunks-es/util.get-selection-start-point.js.map +0 -1
- package/src/behaviors/behavior.code-editor.ts +0 -77
- package/src/behaviors/behavior.links.ts +0 -84
- package/src/internal-utils/looks-like-url.test.ts +0 -19
- package/src/internal-utils/looks-like-url.ts +0 -15
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {EditorSchema} from '../editor/editor-schema'
|
|
2
|
-
import {looksLikeUrl} from '../internal-utils/looks-like-url'
|
|
3
|
-
import * as selectors from '../selectors'
|
|
4
|
-
import {execute} from './behavior.types.action'
|
|
5
|
-
import {defineBehavior} from './behavior.types.behavior'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export type LinkBehaviorsConfig = {
|
|
11
|
-
linkAnnotation?: (context: {
|
|
12
|
-
schema: EditorSchema
|
|
13
|
-
url: string
|
|
14
|
-
}) => {name: string; value: {[prop: string]: unknown}} | undefined
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @beta
|
|
19
|
-
*/
|
|
20
|
-
export function createLinkBehaviors(config: LinkBehaviorsConfig) {
|
|
21
|
-
const pasteLinkOnSelection = defineBehavior({
|
|
22
|
-
on: 'clipboard.paste',
|
|
23
|
-
guard: ({snapshot, event}) => {
|
|
24
|
-
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)
|
|
25
|
-
const text = event.originEvent.dataTransfer.getData('text/plain')
|
|
26
|
-
const url = looksLikeUrl(text) ? text : undefined
|
|
27
|
-
const annotation =
|
|
28
|
-
url !== undefined
|
|
29
|
-
? config.linkAnnotation?.({url, schema: snapshot.context.schema})
|
|
30
|
-
: undefined
|
|
31
|
-
|
|
32
|
-
if (annotation && !selectionCollapsed) {
|
|
33
|
-
return {annotation}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return false
|
|
37
|
-
},
|
|
38
|
-
actions: [
|
|
39
|
-
(_, {annotation}) => [
|
|
40
|
-
execute({
|
|
41
|
-
type: 'annotation.add',
|
|
42
|
-
annotation,
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
],
|
|
46
|
-
})
|
|
47
|
-
const pasteLinkAtCaret = defineBehavior({
|
|
48
|
-
on: 'clipboard.paste',
|
|
49
|
-
guard: ({snapshot, event}) => {
|
|
50
|
-
const focusSpan = selectors.getFocusSpan(snapshot)
|
|
51
|
-
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)
|
|
52
|
-
|
|
53
|
-
if (!focusSpan || !selectionCollapsed) {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const text = event.originEvent.dataTransfer.getData('text/plain')
|
|
58
|
-
const url = looksLikeUrl(text) ? text : undefined
|
|
59
|
-
const annotation =
|
|
60
|
-
url !== undefined
|
|
61
|
-
? config.linkAnnotation?.({url, schema: snapshot.context.schema})
|
|
62
|
-
: undefined
|
|
63
|
-
|
|
64
|
-
if (url && annotation && selectionCollapsed) {
|
|
65
|
-
return {focusSpan, annotation, url}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return false
|
|
69
|
-
},
|
|
70
|
-
actions: [
|
|
71
|
-
(_, {annotation, url}) => [
|
|
72
|
-
execute({
|
|
73
|
-
type: 'insert.span',
|
|
74
|
-
text: url,
|
|
75
|
-
annotations: [annotation],
|
|
76
|
-
}),
|
|
77
|
-
],
|
|
78
|
-
],
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
const linkBehaviors = [pasteLinkOnSelection, pasteLinkAtCaret]
|
|
82
|
-
|
|
83
|
-
return linkBehaviors
|
|
84
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {expect, test} from 'vitest'
|
|
2
|
-
import {looksLikeUrl} from './looks-like-url'
|
|
3
|
-
|
|
4
|
-
test(looksLikeUrl.name, () => {
|
|
5
|
-
expect(looksLikeUrl('https://example.com')).toBe(true)
|
|
6
|
-
expect(looksLikeUrl('http://example.com')).toBe(true)
|
|
7
|
-
expect(looksLikeUrl('mailto:foo@example.com')).toBe(true)
|
|
8
|
-
expect(looksLikeUrl('tel:+123456789')).toBe(true)
|
|
9
|
-
expect(looksLikeUrl('https://example')).toBe(true)
|
|
10
|
-
expect(looksLikeUrl('http://example')).toBe(true)
|
|
11
|
-
expect(looksLikeUrl('http:example')).toBe(true)
|
|
12
|
-
|
|
13
|
-
expect(looksLikeUrl('http: example')).toBe(false)
|
|
14
|
-
expect(looksLikeUrl('https://example. com')).toBe(false)
|
|
15
|
-
expect(looksLikeUrl('example.com')).toBe(false)
|
|
16
|
-
expect(looksLikeUrl('example. com')).toBe(false)
|
|
17
|
-
expect(looksLikeUrl('a:b')).toBe(false)
|
|
18
|
-
expect(looksLikeUrl('a: b')).toBe(false)
|
|
19
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function looksLikeUrl(text: string) {
|
|
2
|
-
let looksLikeUrl = false
|
|
3
|
-
try {
|
|
4
|
-
const url = new URL(text)
|
|
5
|
-
|
|
6
|
-
if (!sensibleProtocols.includes(url.protocol)) {
|
|
7
|
-
return false
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
looksLikeUrl = true
|
|
11
|
-
} catch {}
|
|
12
|
-
return looksLikeUrl
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const sensibleProtocols = ['http:', 'https:', 'mailto:', 'tel:']
|