dishui 0.0.69 → 0.0.72

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.
@@ -7,6 +7,7 @@ export declare function useUndoRedo(doc: FlowDocument, setDoc: React.Dispatch<Re
7
7
  canUndo: boolean;
8
8
  canRedo: boolean;
9
9
  wrappedSetDoc: import("react").Dispatch<import("react").SetStateAction<FlowDocument>>;
10
+ setDocTransient: import("react").Dispatch<import("react").SetStateAction<FlowDocument>>;
10
11
  undo: () => void;
11
12
  redo: () => void;
12
13
  };
@@ -14,24 +14,28 @@ function o(o, s) {
14
14
  canUndo: c.current.length > 0,
15
15
  canRedo: l.current.length > 0
16
16
  });
17
- }, [s]);
17
+ }, [s]), h = e((e) => {
18
+ let t = d.current, n = typeof e == "function" ? e(t) : e;
19
+ if (n === t) return;
20
+ let r = Date.now();
21
+ (r - u.current >= a || c.current.length === 0) && (c.current.push(t), c.current.length > i && c.current.shift()), u.current = r, l.current = [], m(n);
22
+ }, [m]), g = e(() => {
23
+ if (c.current.length === 0) return;
24
+ let e = c.current.pop();
25
+ l.current.push(d.current), u.current = -Infinity, m(e);
26
+ }, [m]), _ = e(() => {
27
+ if (l.current.length === 0) return;
28
+ let e = l.current.pop();
29
+ c.current.push(d.current), u.current = -Infinity, m(e);
30
+ }, [m]);
18
31
  return {
19
- wrappedSetDoc: e((e) => {
32
+ wrappedSetDoc: h,
33
+ setDocTransient: e((e) => {
20
34
  let t = d.current, n = typeof e == "function" ? e(t) : e;
21
- if (n === t) return;
22
- let r = Date.now();
23
- (r - u.current >= a || c.current.length === 0) && (c.current.push(t), c.current.length > i && c.current.shift()), u.current = r, l.current = [], m(n);
24
- }, [m]),
25
- undo: e(() => {
26
- if (c.current.length === 0) return;
27
- let e = c.current.pop();
28
- l.current.push(d.current), u.current = -Infinity, m(e);
29
- }, [m]),
30
- redo: e(() => {
31
- if (l.current.length === 0) return;
32
- let e = l.current.pop();
33
- c.current.push(d.current), u.current = -Infinity, m(e);
35
+ n !== t && m(n);
34
36
  }, [m]),
37
+ undo: g,
38
+ redo: _,
35
39
  ...f
36
40
  };
37
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useUndoRedo.js","names":[],"sources":["../../../../../src/components/pro/Flow/hooks/useUndoRedo.ts"],"sourcesContent":["import { useRef, useCallback, useLayoutEffect, useState } from 'react';\nimport type { FlowDocument } from '../types';\n\nconst MAX_HISTORY = 50;\nconst COALESCE_MS = 300;\n\n/**\n * Time-coalesced undo/redo for FlowDocument.\n * Commands capture history outside React updaters, which React may replay.\n */\nexport function useUndoRedo(\n doc: FlowDocument,\n setDoc: React.Dispatch<React.SetStateAction<FlowDocument>>,\n) {\n const historyRef = useRef<FlowDocument[]>([]);\n const futureRef = useRef<FlowDocument[]>([]);\n const lastPushRef = useRef(-Infinity);\n const currentRef = useRef(doc);\n const [availability, setAvailability] = useState({ canUndo: false, canRedo: false });\n\n // Track externally committed documents too, without writing refs in render.\n useLayoutEffect(() => {\n currentRef.current = doc;\n }, [doc]);\n\n const commit = useCallback((next: FlowDocument) => {\n // Advance immediately so commands in one React batch see preceding commands.\n currentRef.current = next;\n setDoc(next);\n setAvailability({\n canUndo: historyRef.current.length > 0,\n canRedo: futureRef.current.length > 0,\n });\n }, [setDoc]);\n\n const wrappedSetDoc: React.Dispatch<React.SetStateAction<FlowDocument>> = useCallback(\n (action) => {\n const prev = currentRef.current;\n const next = typeof action === 'function' ? action(prev) : action;\n if (next === prev) return;\n\n const now = Date.now();\n // A coalesced edit retains the snapshot from before the first edit.\n if (now - lastPushRef.current >= COALESCE_MS || historyRef.current.length === 0) {\n historyRef.current.push(prev);\n if (historyRef.current.length > MAX_HISTORY) historyRef.current.shift();\n }\n lastPushRef.current = now;\n futureRef.current = [];\n commit(next);\n },\n [commit],\n );\n\n const undo = useCallback(() => {\n if (historyRef.current.length === 0) return;\n const prev = historyRef.current.pop()!;\n futureRef.current.push(currentRef.current);\n lastPushRef.current = -Infinity;\n commit(prev);\n }, [commit]);\n\n const redo = useCallback(() => {\n if (futureRef.current.length === 0) return;\n const next = futureRef.current.pop()!;\n historyRef.current.push(currentRef.current);\n lastPushRef.current = -Infinity;\n commit(next);\n }, [commit]);\n\n return { wrappedSetDoc, undo, redo, ...availability };\n}\n"],"mappings":";;AAGA,IAAM,IAAc,IACd,IAAc;AAMpB,SAAgB,EACd,GACA,GACA;CACA,IAAM,IAAa,EAAuB,CAAC,CAAC,GACtC,IAAY,EAAuB,CAAC,CAAC,GACrC,IAAc,EAAO,SAAS,GAC9B,IAAa,EAAO,CAAG,GACvB,CAAC,GAAc,KAAmB,EAAS;EAAE,SAAS;EAAO,SAAS;CAAM,CAAC;CAGnF,QAAsB;EACpB,EAAW,UAAU;CACvB,GAAG,CAAC,CAAG,CAAC;CAER,IAAM,IAAS,GAAa,MAAuB;EAIjD,AAFA,EAAW,UAAU,GACrB,EAAO,CAAI,GACX,EAAgB;GACd,SAAS,EAAW,QAAQ,SAAS;GACrC,SAAS,EAAU,QAAQ,SAAS;EACtC,CAAC;CACH,GAAG,CAAC,CAAM,CAAC;CAqCX,OAAO;EAAE,eAnCiE,GACvE,MAAW;GACV,IAAM,IAAO,EAAW,SAClB,IAAO,OAAO,KAAW,aAAa,EAAO,CAAI,IAAI;GAC3D,IAAI,MAAS,GAAM;GAEnB,IAAM,IAAM,KAAK,IAAI;GAQrB,CANI,IAAM,EAAY,WAAW,KAAe,EAAW,QAAQ,WAAW,OAC5E,EAAW,QAAQ,KAAK,CAAI,GACxB,EAAW,QAAQ,SAAS,KAAa,EAAW,QAAQ,MAAM,IAExE,EAAY,UAAU,GACtB,EAAU,UAAU,CAAC,GACrB,EAAO,CAAI;EACb,GACA,CAAC,CAAM,CAmBA;EAAe,MAhBX,QAAkB;GAC7B,IAAI,EAAW,QAAQ,WAAW,GAAG;GACrC,IAAM,IAAO,EAAW,QAAQ,IAAI;GAGpC,AAFA,EAAU,QAAQ,KAAK,EAAW,OAAO,GACzC,EAAY,UAAU,WACtB,EAAO,CAAI;EACb,GAAG,CAAC,CAAM,CAUc;EAAM,MARjB,QAAkB;GAC7B,IAAI,EAAU,QAAQ,WAAW,GAAG;GACpC,IAAM,IAAO,EAAU,QAAQ,IAAI;GAGnC,AAFA,EAAW,QAAQ,KAAK,EAAW,OAAO,GAC1C,EAAY,UAAU,WACtB,EAAO,CAAI;EACb,GAAG,CAAC,CAAM,CAEoB;EAAM,GAAG;CAAa;AACtD"}
1
+ {"version":3,"file":"useUndoRedo.js","names":[],"sources":["../../../../../src/components/pro/Flow/hooks/useUndoRedo.ts"],"sourcesContent":["import { useRef, useCallback, useLayoutEffect, useState } from 'react';\nimport type { FlowDocument } from '../types';\n\nconst MAX_HISTORY = 50;\nconst COALESCE_MS = 300;\n\n/**\n * Time-coalesced undo/redo for FlowDocument.\n * Commands capture history outside React updaters, which React may replay.\n */\nexport function useUndoRedo(\n doc: FlowDocument,\n setDoc: React.Dispatch<React.SetStateAction<FlowDocument>>,\n) {\n const historyRef = useRef<FlowDocument[]>([]);\n const futureRef = useRef<FlowDocument[]>([]);\n const lastPushRef = useRef(-Infinity);\n const currentRef = useRef(doc);\n const [availability, setAvailability] = useState({ canUndo: false, canRedo: false });\n\n // Track externally committed documents too, without writing refs in render.\n useLayoutEffect(() => {\n currentRef.current = doc;\n }, [doc]);\n\n const commit = useCallback((next: FlowDocument) => {\n // Advance immediately so commands in one React batch see preceding commands.\n currentRef.current = next;\n setDoc(next);\n setAvailability({\n canUndo: historyRef.current.length > 0,\n canRedo: futureRef.current.length > 0,\n });\n }, [setDoc]);\n\n const wrappedSetDoc: React.Dispatch<React.SetStateAction<FlowDocument>> = useCallback(\n (action) => {\n const prev = currentRef.current;\n const next = typeof action === 'function' ? action(prev) : action;\n if (next === prev) return;\n\n const now = Date.now();\n // A coalesced edit retains the snapshot from before the first edit.\n if (now - lastPushRef.current >= COALESCE_MS || historyRef.current.length === 0) {\n historyRef.current.push(prev);\n if (historyRef.current.length > MAX_HISTORY) historyRef.current.shift();\n }\n lastPushRef.current = now;\n futureRef.current = [];\n commit(next);\n },\n [commit],\n );\n\n const undo = useCallback(() => {\n if (historyRef.current.length === 0) return;\n const prev = historyRef.current.pop()!;\n futureRef.current.push(currentRef.current);\n lastPushRef.current = -Infinity;\n commit(prev);\n }, [commit]);\n\n const redo = useCallback(() => {\n if (futureRef.current.length === 0) return;\n const next = futureRef.current.pop()!;\n historyRef.current.push(currentRef.current);\n lastPushRef.current = -Infinity;\n commit(next);\n }, [commit]);\n\n // Navigation-style updates (e.g. PDF export paging through sub-canvases):\n // commit the document without recording history or clearing redo, so\n // temporary canvas switches stay transparent to undo.\n const setDocTransient: React.Dispatch<React.SetStateAction<FlowDocument>> = useCallback(\n (action) => {\n const prev = currentRef.current;\n const next = typeof action === 'function' ? action(prev) : action;\n if (next === prev) return;\n commit(next);\n },\n [commit],\n );\n\n return { wrappedSetDoc, setDocTransient, undo, redo, ...availability };\n}\n"],"mappings":";;AAGA,IAAM,IAAc,IACd,IAAc;AAMpB,SAAgB,EACd,GACA,GACA;CACA,IAAM,IAAa,EAAuB,CAAC,CAAC,GACtC,IAAY,EAAuB,CAAC,CAAC,GACrC,IAAc,EAAO,SAAS,GAC9B,IAAa,EAAO,CAAG,GACvB,CAAC,GAAc,KAAmB,EAAS;EAAE,SAAS;EAAO,SAAS;CAAM,CAAC;CAGnF,QAAsB;EACpB,EAAW,UAAU;CACvB,GAAG,CAAC,CAAG,CAAC;CAER,IAAM,IAAS,GAAa,MAAuB;EAIjD,AAFA,EAAW,UAAU,GACrB,EAAO,CAAI,GACX,EAAgB;GACd,SAAS,EAAW,QAAQ,SAAS;GACrC,SAAS,EAAU,QAAQ,SAAS;EACtC,CAAC;CACH,GAAG,CAAC,CAAM,CAAC,GAEL,IAAoE,GACvE,MAAW;EACV,IAAM,IAAO,EAAW,SAClB,IAAO,OAAO,KAAW,aAAa,EAAO,CAAI,IAAI;EAC3D,IAAI,MAAS,GAAM;EAEnB,IAAM,IAAM,KAAK,IAAI;EA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