@pixerate/editor-react 0.10.2 → 0.10.4

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/dist/index.d.cts CHANGED
@@ -137,7 +137,8 @@ interface UseHistoryResult extends HistoryState {
137
137
  }
138
138
  /**
139
139
  * React hook that subscribes to a HistoryManager instance.
140
- * Accepts an existing HistoryManager or config options to create an instance.
140
+ * Accepts an existing HistoryManager or config options to create an instance
141
+ * (options are read on first render only).
141
142
  */
142
143
  declare function useHistory(managerOrOptions?: HistoryManager | HistoryManagerOptions): UseHistoryResult;
143
144
 
package/dist/index.d.ts CHANGED
@@ -137,7 +137,8 @@ interface UseHistoryResult extends HistoryState {
137
137
  }
138
138
  /**
139
139
  * React hook that subscribes to a HistoryManager instance.
140
- * Accepts an existing HistoryManager or config options to create an instance.
140
+ * Accepts an existing HistoryManager or config options to create an instance
141
+ * (options are read on first render only).
141
142
  */
142
143
  declare function useHistory(managerOrOptions?: HistoryManager | HistoryManagerOptions): UseHistoryResult;
143
144
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ImageEditor,
3
3
  useImageEditor
4
- } from "./chunk-UYT5EQU6.js";
4
+ } from "./chunk-H7HCHLZU.js";
5
5
 
6
6
  // src/hooks/usePromptEditor.ts
7
7
  import { useMemo, useEffect, useRef } from "react";
@@ -373,18 +373,20 @@ function useDismissGuard({
373
373
  }
374
374
 
375
375
  // src/hooks/useHistory.ts
376
- import { useSyncExternalStore, useMemo as useMemo2, useCallback as useCallback3 } from "react";
376
+ import { useSyncExternalStore, useRef as useRef4, useCallback as useCallback3 } from "react";
377
377
  import {
378
378
  HistoryManager,
379
379
  createHistoryManager
380
380
  } from "@pixerate/editor";
381
381
  function useHistory(managerOrOptions) {
382
- const manager = useMemo2(() => {
383
- if (managerOrOptions instanceof HistoryManager) {
384
- return managerOrOptions;
385
- }
386
- return createHistoryManager(managerOrOptions);
387
- }, [managerOrOptions]);
382
+ const ownManagerRef = useRef4(null);
383
+ let manager;
384
+ if (managerOrOptions instanceof HistoryManager) {
385
+ manager = managerOrOptions;
386
+ } else {
387
+ ownManagerRef.current ??= createHistoryManager(managerOrOptions);
388
+ manager = ownManagerRef.current;
389
+ }
388
390
  const state = useSyncExternalStore(
389
391
  useCallback3(
390
392
  (onStoreChange) => manager.subscribe(onStoreChange),
@@ -485,7 +487,7 @@ var EditorContent = ({
485
487
  };
486
488
 
487
489
  // src/components/BubbleMenu.tsx
488
- import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
490
+ import { useEffect as useEffect4, useRef as useRef5, useState as useState3 } from "react";
489
491
  import { createPortal } from "react-dom";
490
492
  import {
491
493
  BubbleMenuPlugin
@@ -499,7 +501,7 @@ var BubbleMenu = ({
499
501
  pluginKey = "bubbleMenu",
500
502
  updateDelay
501
503
  }) => {
502
- const menuEl = useRef4(null);
504
+ const menuEl = useRef5(null);
503
505
  const [mounted, setMounted] = useState3(false);
504
506
  if (!menuEl.current && typeof document !== "undefined") {
505
507
  menuEl.current = document.createElement("div");
@@ -535,7 +537,7 @@ var BubbleMenu = ({
535
537
  };
536
538
 
537
539
  // src/components/TemplateRenderer.tsx
538
- import { useMemo as useMemo3 } from "react";
540
+ import { useMemo as useMemo2 } from "react";
539
541
  import {
540
542
  tokenizePrompt as tokenizePrompt2,
541
543
  resolveTemplates
@@ -550,11 +552,11 @@ var TemplateRenderer = ({
550
552
  onTemplateClick,
551
553
  onVariableClick
552
554
  }) => {
553
- const displayText = useMemo3(() => {
555
+ const displayText = useMemo2(() => {
554
556
  if (!resolve || templates.length === 0) return content;
555
557
  return resolveTemplates(content, templates);
556
558
  }, [content, templates, resolve]);
557
- const tokens = useMemo3(() => {
559
+ const tokens = useMemo2(() => {
558
560
  return tokenizePrompt2(displayText);
559
561
  }, [displayText]);
560
562
  return /* @__PURE__ */ jsx2("div", { className, children: tokens.map((token, index) => {
@@ -616,14 +618,14 @@ import {
616
618
  } from "@pixerate/editor";
617
619
 
618
620
  // src/spreadsheet/useSpreadsheetEditor.ts
619
- import { useState as useState4, useRef as useRef5, useCallback as useCallback4 } from "react";
621
+ import { useState as useState4, useRef as useRef6, useCallback as useCallback4 } from "react";
620
622
  import {
621
623
  SpreadsheetController
622
624
  } from "@pixerate/editor";
623
625
  function useSpreadsheetEditor(options = {}) {
624
- const optionsRef = useRef5(options);
626
+ const optionsRef = useRef6(options);
625
627
  optionsRef.current = options;
626
- const settersRef = useRef5({});
628
+ const settersRef = useRef6({});
627
629
  const [controller] = useState4(
628
630
  () => new SpreadsheetController({
629
631
  ...options,
@@ -775,7 +777,7 @@ function useSpreadsheetEditor(options = {}) {
775
777
  }
776
778
 
777
779
  // src/spreadsheet/SpreadsheetEditor.tsx
778
- import { useRef as useRef6, useState as useState5, useMemo as useMemo4, useEffect as useEffect5, useCallback as useCallback5 } from "react";
780
+ import { useRef as useRef7, useState as useState5, useMemo as useMemo3, useEffect as useEffect5, useCallback as useCallback5 } from "react";
779
781
  import {
780
782
  indexToColName
781
783
  } from "@pixerate/editor";
@@ -790,19 +792,19 @@ var SpreadsheetEditor = ({
790
792
  }) => {
791
793
  const defaultState = useSpreadsheetEditor();
792
794
  const state = externalState || defaultState;
793
- const gridRef = useRef6(null);
795
+ const gridRef = useRef7(null);
794
796
  const [resizingColId, setResizingColId] = useState5(null);
795
797
  const [hoveredColId, setHoveredColId] = useState5(null);
796
798
  const [resizeStartX, setResizeStartX] = useState5(0);
797
799
  const [resizeStartWidth, setResizeStartWidth] = useState5(0);
798
- const activeRawValue = useMemo4(() => {
800
+ const activeRawValue = useMemo3(() => {
799
801
  if (!state.activeCell) return "";
800
802
  const row = state.document.rows[state.activeCell.row];
801
803
  const col = state.document.columns[state.activeCell.col];
802
804
  if (!row || !col) return "";
803
805
  return state.getCell(row.id, col.id).raw;
804
806
  }, [state.activeCell, state.document]);
805
- const coordLabel = useMemo4(() => {
807
+ const coordLabel = useMemo3(() => {
806
808
  if (!state.activeCell) return "--";
807
809
  const colName = indexToColName(state.activeCell.col);
808
810
  return `${colName}${state.activeCell.row + 1}`;
@@ -905,9 +907,9 @@ var SpreadsheetEditor = ({
905
907
  }
906
908
  }
907
909
  }, [readOnly, state]);
908
- const stateRef = useRef6(state);
910
+ const stateRef = useRef7(state);
909
911
  stateRef.current = state;
910
- const onColumnResizeRef = useRef6(onColumnResize);
912
+ const onColumnResizeRef = useRef7(onColumnResize);
911
913
  onColumnResizeRef.current = onColumnResize;
912
914
  useEffect5(() => {
913
915
  if (!resizingColId) return;
@@ -1239,7 +1241,7 @@ var SpreadsheetEditor = ({
1239
1241
  };
1240
1242
 
1241
1243
  // src/slots.tsx
1242
- import { createContext, useContext, useMemo as useMemo5 } from "react";
1244
+ import { createContext, useContext, useMemo as useMemo4 } from "react";
1243
1245
  import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1244
1246
  var defaultSlots = {
1245
1247
  Button: (props) => /* @__PURE__ */ jsx4(
@@ -1263,7 +1265,7 @@ var defaultSlots = {
1263
1265
  };
1264
1266
  var EditorSlotsContext = createContext(defaultSlots);
1265
1267
  function EditorSlotsProvider({ slots, children }) {
1266
- const mergedSlots = useMemo5(() => ({ ...defaultSlots, ...slots }), [slots]);
1268
+ const mergedSlots = useMemo4(() => ({ ...defaultSlots, ...slots }), [slots]);
1267
1269
  return /* @__PURE__ */ jsx4(EditorSlotsContext.Provider, { value: mergedSlots, children });
1268
1270
  }
1269
1271
  function useEditorSlots() {