@portabletext/editor 2.17.0 → 2.17.2

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.
@@ -0,0 +1,63 @@
1
+ import {describe, expect, test} from 'vitest'
2
+ import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
3
+ import {isSelectionExpanded} from './selector.is-selection-expanded'
4
+
5
+ describe(isSelectionExpanded.name, () => {
6
+ test('no selection', () => {
7
+ const snapshot = createTestSnapshot({})
8
+
9
+ expect(isSelectionExpanded(snapshot)).toBe(false)
10
+ })
11
+
12
+ test('collapsed selection', () => {
13
+ const snapshot = createTestSnapshot({
14
+ context: {
15
+ value: [
16
+ {
17
+ _key: 'k0',
18
+ _type: 'block',
19
+ children: [
20
+ {
21
+ _key: 'k1',
22
+ _type: 'span',
23
+ text: 'foo',
24
+ },
25
+ ],
26
+ },
27
+ ],
28
+ selection: {
29
+ anchor: {path: [{_key: 'k0'}, 'children', {_key: 'k1'}], offset: 0},
30
+ focus: {path: [{_key: 'k0'}, 'children', {_key: 'k1'}], offset: 0},
31
+ },
32
+ },
33
+ })
34
+
35
+ expect(isSelectionExpanded(snapshot)).toBe(false)
36
+ })
37
+
38
+ test('expanded selection', () => {
39
+ const snapshot = createTestSnapshot({
40
+ context: {
41
+ value: [
42
+ {
43
+ _key: 'k0',
44
+ _type: 'block',
45
+ children: [
46
+ {
47
+ _key: 'k1',
48
+ _type: 'span',
49
+ text: 'foo',
50
+ },
51
+ ],
52
+ },
53
+ ],
54
+ selection: {
55
+ anchor: {path: [{_key: 'k0'}, 'children', {_key: 'k1'}], offset: 0},
56
+ focus: {path: [{_key: 'k0'}, 'children', {_key: 'k1'}], offset: 3},
57
+ },
58
+ },
59
+ })
60
+
61
+ expect(isSelectionExpanded(snapshot)).toBe(true)
62
+ })
63
+ })
@@ -5,5 +5,5 @@ import {isSelectionCollapsed} from './selector.is-selection-collapsed'
5
5
  * @public
6
6
  */
7
7
  export const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {
8
- return !isSelectionCollapsed(snapshot)
8
+ return snapshot.context.selection !== null && !isSelectionCollapsed(snapshot)
9
9
  }
@@ -1,5 +1,3 @@
1
- import getRandomValues from 'get-random-values-esm'
2
-
3
1
  /**
4
2
  * @public
5
3
  */
@@ -23,7 +21,7 @@ const getByteHexTable = (() => {
23
21
  // WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html
24
22
  function whatwgRNG(length = 16) {
25
23
  const rnds8 = new Uint8Array(length)
26
- getRandomValues(rnds8)
24
+ crypto.getRandomValues(rnds8)
27
25
  return rnds8
28
26
  }
29
27