@portabletext/editor 1.16.2 → 1.16.3

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.js CHANGED
@@ -19,13 +19,13 @@ import noop from "lodash/noop.js";
19
19
  import React, { useRef, useState, useEffect, useMemo, createContext, useContext, startTransition, Component, useCallback, forwardRef, useImperativeHandle } from "react";
20
20
  import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Operation, Node, createEditor as createEditor$1, deleteBackward, deleteForward, insertText } from "slate";
21
21
  import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
22
- import debug$m from "debug";
22
+ import debug$l from "debug";
23
23
  import { c } from "react-compiler-runtime";
24
24
  import { styled } from "styled-components";
25
25
  import uniq from "lodash/uniq.js";
26
26
  import { Subject } from "rxjs";
27
27
  import { useEffectEvent } from "use-effect-event";
28
- import { setup, emit, assign, fromCallback, assertEvent, and, not, or, enqueueActions, createActor } from "xstate";
28
+ import { setup, emit, assign, fromCallback, assertEvent, enqueueActions, createActor } from "xstate";
29
29
  import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
30
30
  import flatten from "lodash/flatten.js";
31
31
  import isPlainObject from "lodash/isPlainObject.js";
@@ -175,10 +175,10 @@ function compileSchemaDefinition(definition) {
175
175
  });
176
176
  }
177
177
  const rootName = "sanity-pte:";
178
- var debug$l = debug$m(rootName);
178
+ debug$l(rootName);
179
179
  function debugWithName(name) {
180
180
  const namespace = `${rootName}${name}`;
181
- return debug$m && debug$m.enabled(namespace) ? debug$m(namespace) : debug$m(rootName);
181
+ return debug$l && debug$l.enabled(namespace) ? debug$l(namespace) : debug$l(rootName);
182
182
  }
183
183
  function createKeyedPath(point, value, types) {
184
184
  const blockPath = [point.path[0]];
@@ -2335,24 +2335,20 @@ const syncValueCallback = ({
2335
2335
  event
2336
2336
  }) => (assertEvent(event, "done syncing"), event.value)
2337
2337
  }),
2338
- "emit done syncing": emit(({
2339
- event
2340
- }) => (assertEvent(event, "done syncing"), event))
2338
+ "emit done syncing initial value": emit({
2339
+ type: "done syncing initial value"
2340
+ })
2341
2341
  },
2342
2342
  guards: {
2343
- "is readOnly": ({
2343
+ "initial value synced": ({
2344
2344
  context
2345
- }) => context.readOnly,
2346
- "is processing local changes": ({
2347
- context
2348
- }) => context.isProcessingLocalChanges,
2349
- "is processing remote changes": ({
2345
+ }) => context.initialValueSynced,
2346
+ "is busy": ({
2350
2347
  context
2351
2348
  }) => {
2352
2349
  var _a;
2353
- return (_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1;
2350
+ return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
2354
2351
  },
2355
- "is busy": and([not("is readOnly"), or(["is processing local changes", "is processing remote changes"])]),
2356
2352
  "value changed while syncing": ({
2357
2353
  context,
2358
2354
  event
@@ -2378,7 +2374,6 @@ const syncValueCallback = ({
2378
2374
  pendingValue: void 0,
2379
2375
  previousValue: void 0
2380
2376
  }),
2381
- initial: "idle",
2382
2377
  on: {
2383
2378
  "has pending patches": {
2384
2379
  actions: assign({
@@ -2394,94 +2389,105 @@ const syncValueCallback = ({
2394
2389
  actions: ["assign readOnly"]
2395
2390
  }
2396
2391
  },
2392
+ type: "parallel",
2397
2393
  states: {
2398
- idle: {
2399
- on: {
2400
- "update value": [{
2401
- guard: "is busy",
2402
- target: "busy",
2403
- actions: ["assign pending value"]
2404
- }, {
2405
- target: "syncing",
2406
- actions: ["assign pending value"]
2407
- }]
2408
- }
2409
- },
2410
- busy: {
2411
- after: {
2412
- 1e3: {
2413
- target: "syncing"
2394
+ "setting up": {
2395
+ initial: "syncing initial value",
2396
+ states: {
2397
+ "syncing initial value": {
2398
+ always: {
2399
+ guard: "initial value synced",
2400
+ target: "done syncing initial value"
2401
+ }
2402
+ },
2403
+ "done syncing initial value": {
2404
+ entry: ["emit done syncing initial value"],
2405
+ type: "final"
2414
2406
  }
2415
- },
2416
- on: {
2417
- "update value": [{
2418
- guard: "is busy",
2419
- actions: ["assign pending value"],
2420
- reenter: !0
2421
- }, {
2422
- target: "syncing",
2423
- actions: ["assign pending value"]
2424
- }]
2425
2407
  }
2426
2408
  },
2427
2409
  syncing: {
2428
- invoke: {
2429
- src: "sync value",
2430
- id: "sync value",
2431
- input: ({
2432
- context
2433
- }) => {
2434
- var _a;
2435
- return {
2436
- context: {
2437
- keyGenerator: context.keyGenerator,
2438
- previousValue: context.previousValue,
2439
- readOnly: context.readOnly,
2440
- schema: context.schema
2441
- },
2442
- slateEditor: context.slateEditor,
2443
- streamBlocks: !context.initialValueSynced,
2444
- value: (_a = context.pendingValue) != null ? _a : void 0
2445
- };
2446
- }
2447
- },
2448
- always: {
2449
- guard: "pending value equals previous value",
2450
- actions: [emit(({
2451
- context
2452
- }) => ({
2453
- type: "done syncing",
2454
- value: context.previousValue
2455
- }))],
2456
- target: "idle"
2457
- },
2458
- on: {
2459
- "update value": {
2460
- actions: ["assign pending value"]
2461
- },
2462
- patch: {
2463
- actions: [emit(({
2464
- event
2465
- }) => event)]
2466
- },
2467
- "invalid value": {
2468
- actions: [emit(({
2469
- event
2470
- }) => event)]
2410
+ initial: "idle",
2411
+ states: {
2412
+ idle: {
2413
+ on: {
2414
+ "update value": [{
2415
+ guard: "is busy",
2416
+ target: "busy",
2417
+ actions: ["assign pending value"]
2418
+ }, {
2419
+ target: "syncing",
2420
+ actions: ["assign pending value"]
2421
+ }]
2422
+ }
2471
2423
  },
2472
- "value changed": {
2473
- actions: [emit(({
2474
- event
2475
- }) => event)]
2424
+ busy: {
2425
+ after: {
2426
+ 1e3: [{
2427
+ guard: "is busy",
2428
+ reenter: !0
2429
+ }, {
2430
+ target: "syncing"
2431
+ }]
2432
+ },
2433
+ on: {
2434
+ "update value": [{
2435
+ actions: ["assign pending value"]
2436
+ }]
2437
+ }
2476
2438
  },
2477
- "done syncing": [{
2478
- guard: "value changed while syncing",
2479
- actions: ["assign previous value", "emit done syncing", "assign initial value synced"],
2480
- reenter: !0
2481
- }, {
2482
- target: "idle",
2483
- actions: ["clear pending value", "assign previous value", "emit done syncing", "assign initial value synced"]
2484
- }]
2439
+ syncing: {
2440
+ always: {
2441
+ guard: "pending value equals previous value",
2442
+ target: "idle",
2443
+ actions: ["clear pending value", "assign initial value synced"]
2444
+ },
2445
+ invoke: {
2446
+ src: "sync value",
2447
+ id: "sync value",
2448
+ input: ({
2449
+ context
2450
+ }) => ({
2451
+ context: {
2452
+ keyGenerator: context.keyGenerator,
2453
+ previousValue: context.previousValue,
2454
+ readOnly: context.readOnly,
2455
+ schema: context.schema
2456
+ },
2457
+ slateEditor: context.slateEditor,
2458
+ streamBlocks: !context.initialValueSynced,
2459
+ value: context.pendingValue
2460
+ })
2461
+ },
2462
+ on: {
2463
+ "update value": {
2464
+ actions: ["assign pending value"]
2465
+ },
2466
+ patch: {
2467
+ actions: [emit(({
2468
+ event
2469
+ }) => event)]
2470
+ },
2471
+ "invalid value": {
2472
+ actions: [emit(({
2473
+ event
2474
+ }) => event)]
2475
+ },
2476
+ "value changed": {
2477
+ actions: [emit(({
2478
+ event
2479
+ }) => event)]
2480
+ },
2481
+ "done syncing": [{
2482
+ guard: "value changed while syncing",
2483
+ actions: ["assign previous value", "assign initial value synced"],
2484
+ reenter: !0
2485
+ }, {
2486
+ target: "idle",
2487
+ actions: ["clear pending value", "assign previous value", "assign initial value synced"]
2488
+ }]
2489
+ }
2490
+ }
2485
2491
  }
2486
2492
  }
2487
2493
  }
@@ -5724,7 +5730,7 @@ function performAction({
5724
5730
  context,
5725
5731
  action
5726
5732
  }) {
5727
- switch (debug$l("Behavior action", action), action.type) {
5733
+ switch (action.type) {
5728
5734
  case "delete.block": {
5729
5735
  behaviorActionImplementations["delete.block"]({
5730
5736
  context,
@@ -6063,7 +6069,7 @@ const editorMachine = setup({
6063
6069
  enqueue
6064
6070
  }) => {
6065
6071
  var _a;
6066
- assertEvent(event, ["behavior event"]), debug$l("Behavior event", event);
6072
+ assertEvent(event, ["behavior event"]);
6067
6073
  const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : __spreadProps$4(__spreadValues$4({}, event.behaviorEvent), {
6068
6074
  editor: event.editor
6069
6075
  }), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
@@ -6251,7 +6257,7 @@ const editorMachine = setup({
6251
6257
  states: {
6252
6258
  "determine initial edit mode": {
6253
6259
  on: {
6254
- "done syncing": [{
6260
+ "done syncing initial value": [{
6255
6261
  target: "#editor.edit mode.read only.read only",
6256
6262
  guard: ({
6257
6263
  context
@@ -6347,7 +6353,7 @@ const editorMachine = setup({
6347
6353
  mutation: {
6348
6354
  actions: "defer event"
6349
6355
  },
6350
- "done syncing": {
6356
+ "done syncing initial value": {
6351
6357
  target: "pristine"
6352
6358
  }
6353
6359
  }