@portabletext/editor 2.12.1 → 2.12.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.
@@ -1,5 +1,5 @@
1
1
  import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.js";
2
- import * as react22 from "react";
2
+ import * as react12 from "react";
3
3
  import React from "react";
4
4
  /**
5
5
  * @beta
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
181
181
  */
182
182
  declare function MarkdownPlugin(props: {
183
183
  config: MarkdownPluginConfig;
184
- }): react22.JSX.Element;
184
+ }): react12.JSX.Element;
185
185
  /**
186
186
  * @beta
187
187
  * Restrict the editor to one line. The plugin takes care of blocking
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
192
192
  *
193
193
  * @deprecated Install the plugin from `@portabletext/plugin-one-line`
194
194
  */
195
- declare function OneLinePlugin(): react22.JSX.Element;
195
+ declare function OneLinePlugin(): react12.JSX.Element;
196
196
  export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
@@ -1,5 +1,5 @@
1
1
  import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.cjs";
2
- import * as _sanity_types8 from "@sanity/types";
2
+ import * as _sanity_types9 from "@sanity/types";
3
3
  import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  /**
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
143
143
  context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
144
144
  targetBlock: PortableTextTextBlock;
145
145
  incomingBlock: PortableTextTextBlock;
146
- }): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
146
+ }): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
147
147
  /**
148
148
  * @public
149
149
  */
@@ -1,5 +1,5 @@
1
1
  import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
2
- import * as _sanity_types9 from "@sanity/types";
2
+ import * as _sanity_types8 from "@sanity/types";
3
3
  import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  /**
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
143
143
  context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
144
144
  targetBlock: PortableTextTextBlock;
145
145
  incomingBlock: PortableTextTextBlock;
146
- }): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
146
+ }): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
147
147
  /**
148
148
  * @public
149
149
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -84,7 +84,7 @@
84
84
  "slate": "0.118.1",
85
85
  "slate-dom": "^0.118.1",
86
86
  "slate-react": "0.117.4",
87
- "xstate": "^5.21.0",
87
+ "xstate": "^5.22.0",
88
88
  "@portabletext/block-tools": "^3.5.6",
89
89
  "@portabletext/keyboard-shortcuts": "^1.1.1",
90
90
  "@portabletext/patches": "^1.1.8",
@@ -118,7 +118,7 @@
118
118
  "vitest-browser-react": "^1.0.1",
119
119
  "@portabletext/sanity-bridge": "1.1.10",
120
120
  "@portabletext/test": "^0.0.0",
121
- "racejar": "1.2.15"
121
+ "racejar": "1.3.0"
122
122
  },
123
123
  "peerDependencies": {
124
124
  "@portabletext/sanity-bridge": "^1.1.10",
@@ -6,6 +6,7 @@ import {
6
6
  getFocusInlineObject,
7
7
  getPreviousBlock,
8
8
  isSelectionCollapsed,
9
+ isSelectionExpanded,
9
10
  } from '../selectors'
10
11
  import {getBlockEndPoint, isEmptyTextBlock} from '../utils'
11
12
  import {raise} from './behavior.types.action'
@@ -37,6 +38,18 @@ export const abstractKeyboardBehaviors = [
37
38
  actions: [() => [raise({type: 'insert.break'})]],
38
39
  }),
39
40
 
41
+ /**
42
+ * On Firefox, Enter might collapse the selection. To mitigate this, we
43
+ * `raise` an `insert.break` event manually.
44
+ */
45
+ defineBehavior({
46
+ on: 'keyboard.keydown',
47
+ guard: ({snapshot, event}) =>
48
+ defaultKeyboardShortcuts.break.guard(event.originEvent) &&
49
+ isSelectionExpanded(snapshot),
50
+ actions: [() => [raise({type: 'insert.break'})]],
51
+ }),
52
+
40
53
  /**
41
54
  * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
42
55
  * than an `insertLineBreak` input event. This Behavior makes sure we catch
@@ -172,7 +172,11 @@ export function performEvent({
172
172
  nativeEventPrevented = true
173
173
  }
174
174
 
175
+ let actionSetIndex = -1
176
+
175
177
  for (const actionSet of eventBehavior.actions) {
178
+ actionSetIndex++
179
+
176
180
  const actionsSnapshot = getSnapshot()
177
181
 
178
182
  let actions: Array<BehaviorAction> = []
@@ -205,7 +209,17 @@ export function performEvent({
205
209
 
206
210
  let undoStepCreated = false
207
211
 
208
- if (actions.some((action) => action.type === 'execute')) {
212
+ if (actionSetIndex > 0) {
213
+ // Since there are multiple action sets
214
+ createUndoStep(editor)
215
+
216
+ undoStepCreated = true
217
+ }
218
+
219
+ if (
220
+ !undoStepCreated &&
221
+ actions.some((action) => action.type === 'execute')
222
+ ) {
209
223
  // Since at least one action is about to `execute` changes in the editor,
210
224
  // we set up a new undo step.
211
225
  // All actions performed recursively from now will be squashed into this
@@ -0,0 +1,76 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
2
+ import {createTestKeyGenerator} from '@portabletext/test'
3
+ import {describe, expect, test} from 'vitest'
4
+ import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
5
+ import {getMarkState} from './selector.get-mark-state'
6
+
7
+ describe(getMarkState.name, () => {
8
+ test('Scenario: Caret after annotated decorator', () => {
9
+ const keyGenerator = createTestKeyGenerator()
10
+ const blockKey = keyGenerator()
11
+ const fooSpanKey = keyGenerator()
12
+ const barSpanKey = keyGenerator()
13
+ const bazSpanKey = keyGenerator()
14
+ const linkKey = keyGenerator()
15
+ const snapshot = createTestSnapshot({
16
+ context: {
17
+ keyGenerator,
18
+ value: [
19
+ {
20
+ _type: 'block',
21
+ _key: blockKey,
22
+ children: [
23
+ {
24
+ _type: 'span',
25
+ _key: fooSpanKey,
26
+ text: 'foo ',
27
+ },
28
+ {
29
+ _type: 'span',
30
+ _key: barSpanKey,
31
+ text: 'bar',
32
+ marks: [linkKey, 'strong'],
33
+ },
34
+ {
35
+ _type: 'span',
36
+ _key: bazSpanKey,
37
+ text: ' baz',
38
+ },
39
+ ],
40
+ markDefs: [
41
+ {
42
+ _type: 'link',
43
+ _key: linkKey,
44
+ href: 'https://portabletext.org',
45
+ },
46
+ ],
47
+ style: 'normal',
48
+ },
49
+ ],
50
+ selection: {
51
+ anchor: {
52
+ path: [{_key: blockKey}, 'children', {_key: bazSpanKey}],
53
+ offset: 0,
54
+ },
55
+ focus: {
56
+ path: [{_key: blockKey}, 'children', {_key: bazSpanKey}],
57
+ offset: 0,
58
+ },
59
+ backward: false,
60
+ },
61
+ schema: compileSchema(
62
+ defineSchema({
63
+ annotations: [{name: 'link'}],
64
+ decorators: [{name: 'strong'}],
65
+ }),
66
+ ),
67
+ },
68
+ })
69
+
70
+ expect(getMarkState(snapshot)).toEqual({
71
+ state: 'changed',
72
+ marks: [],
73
+ previousMarks: [linkKey, 'strong'],
74
+ })
75
+ })
76
+ })
@@ -164,7 +164,7 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
164
164
  if (previousSpanHasAnnotations) {
165
165
  return {
166
166
  state: 'changed',
167
- previousMarks: marks,
167
+ previousMarks: previousSpan.node.marks ?? [],
168
168
  marks: [],
169
169
  }
170
170
  } else {
@@ -70,7 +70,7 @@ const parameterType = {
70
70
  }),
71
71
  tersePt: createParameterType<Array<string>>({
72
72
  name: 'terse-pt',
73
- matcher: /"([a-z-,#>:\\n \d|{}'"‘’“”?]*)"/u,
73
+ matcher: /"([a-z-,#>:\\n \d|{}'"‘’“”?—]*)"/u,
74
74
  type: Array,
75
75
  transform: parseTersePtString,
76
76
  }),
@@ -181,6 +181,9 @@ export const stepDefinitions = [
181
181
  When('{string} is typed', async (context: Context, text: string) => {
182
182
  await userEvent.type(context.locator, text)
183
183
  }),
184
+ When('{string} is inserted', (context: Context, text: string) => {
185
+ context.editor.send({type: 'insert.text', text})
186
+ }),
184
187
  Then(
185
188
  '{terse-pt} is in block {key}',
186
189
  (context: Context, text: Array<string>, key: string) => {