@portabletext/editor 5.1.0-canary.0 → 5.1.0

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
@@ -7,8 +7,6 @@ import { isHotkey as isHotkey$1 } from "is-hotkey";
7
7
  import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, isTypedObject, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isEqualPathSegments } from "./_chunks-es/util.slice-blocks.js";
8
8
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
9
9
  import { defineSchema } from "@portabletext/schema";
10
- import debounce from "lodash/debounce";
11
- import throttle from "lodash/throttle";
12
10
  import scrollIntoView from "scroll-into-view-if-needed";
13
11
  import { ResizeObserver } from "@juggle/resize-observer";
14
12
  import { isEmptyTextBlock, sliceTextBlock, getTextBlockText } from "./_chunks-es/util.slice-text-block.js";
@@ -6544,6 +6542,49 @@ function useTrackUserInput() {
6544
6542
  onUserInput
6545
6543
  };
6546
6544
  }
6545
+ function debounce(func, wait) {
6546
+ let timeoutId, lastArgs;
6547
+ const debounced = (...args) => {
6548
+ lastArgs = args, timeoutId !== void 0 && clearTimeout(timeoutId), timeoutId = setTimeout(() => {
6549
+ timeoutId = void 0;
6550
+ const args2 = lastArgs;
6551
+ lastArgs = void 0, args2 && func(...args2);
6552
+ }, wait);
6553
+ };
6554
+ return debounced.cancel = () => {
6555
+ timeoutId !== void 0 && (clearTimeout(timeoutId), timeoutId = void 0), lastArgs = void 0;
6556
+ }, debounced.flush = () => {
6557
+ if (timeoutId !== void 0) {
6558
+ clearTimeout(timeoutId), timeoutId = void 0;
6559
+ const args = lastArgs;
6560
+ lastArgs = void 0, args && func(...args);
6561
+ }
6562
+ }, debounced;
6563
+ }
6564
+ function throttle(func, wait) {
6565
+ let timeoutId, lastArgs, lastCallTime;
6566
+ const invoke = () => {
6567
+ const args = lastArgs;
6568
+ lastArgs = void 0, lastCallTime = Date.now(), args && func(...args);
6569
+ }, startTimer = (remaining) => {
6570
+ timeoutId = setTimeout(() => {
6571
+ timeoutId = void 0, lastArgs && invoke();
6572
+ }, remaining);
6573
+ }, throttled = (...args) => {
6574
+ const now = Date.now();
6575
+ if (lastArgs = args, lastCallTime === void 0) {
6576
+ invoke();
6577
+ return;
6578
+ }
6579
+ const elapsed = now - lastCallTime;
6580
+ elapsed >= wait ? (timeoutId !== void 0 && (clearTimeout(timeoutId), timeoutId = void 0), invoke()) : timeoutId === void 0 && startTimer(wait - elapsed);
6581
+ };
6582
+ return throttled.cancel = () => {
6583
+ timeoutId !== void 0 && (clearTimeout(timeoutId), timeoutId = void 0), lastArgs = void 0, lastCallTime = void 0;
6584
+ }, throttled.flush = () => {
6585
+ timeoutId !== void 0 && (clearTimeout(timeoutId), timeoutId = void 0), lastArgs && invoke();
6586
+ }, throttled;
6587
+ }
6547
6588
  const createRestoreDomManager = (editor, receivedUserInput) => {
6548
6589
  let bufferedMutations = [];
6549
6590
  const clear = () => {
@@ -14440,10 +14481,23 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
14440
14481
  inheritListLevel,
14441
14482
  inheritListItem,
14442
14483
  inheritListProperties
14443
- }, coreBehaviorsConfig = [...coreAnnotationBehaviors, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, ...coreInsertBehaviors, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
14444
- behavior,
14445
- priority: corePriority
14446
- }));
14484
+ }, coreBehaviors = [...coreAnnotationBehaviors, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, ...coreInsertBehaviors, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject];
14485
+ let previousPriority = corePriority;
14486
+ const coreBehaviorsConfigArray = [];
14487
+ for (const behavior of coreBehaviors) {
14488
+ const priority = createEditorPriority({
14489
+ name: "core",
14490
+ reference: {
14491
+ priority: previousPriority,
14492
+ importance: "lower"
14493
+ }
14494
+ });
14495
+ coreBehaviorsConfigArray.push({
14496
+ behavior,
14497
+ priority
14498
+ }), previousPriority = priority;
14499
+ }
14500
+ const coreBehaviorsConfig = coreBehaviorsConfigArray;
14447
14501
  function createEditorSnapshot({
14448
14502
  converters,
14449
14503
  editor,