wiki-formant 0.44.0 → 0.44.1

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.
Files changed (2) hide show
  1. package/dist/editor.js +17 -3
  2. package/package.json +1 -1
package/dist/editor.js CHANGED
@@ -15,6 +15,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
15
15
  // 2. Blur flushes the pending debounce. The change is debounced 150ms, and
16
16
  // clicking Save blurs the editor before the click lands, so without the
17
17
  // flush the final keystroke of an edit that ends in a click is dropped.
18
+ // It flushes only an edit still pending: Tiptap rewrites stored HTML into
19
+ // its own form, so reporting every blur told a page that had only been
20
+ // clicked through it had unsaved changes.
18
21
  //
19
22
  // Every @tiptap package here is an OPTIONAL PEER. A consumer that only wants
20
23
  // the taxonomy or the MCP transport installs none of them.
@@ -311,6 +314,9 @@ export function useWikiEditor({ value, onChange, placeholder = '', nodes = [], p
311
314
  const initialValueRef = useRef(value);
312
315
  const onChangeRef = useRef(onChange);
313
316
  const debounceRef = useRef(undefined);
317
+ // An edit made and not yet reported. `onUpdate` fires for edits only, never
318
+ // for the `setContent` that loads the stored value.
319
+ const pendingRef = useRef(false);
314
320
  // Written AFTER render, not during: a ref mutated mid-render can tear under
315
321
  // concurrent rendering. Only read from events and timeouts, which run later.
316
322
  useEffect(() => {
@@ -328,12 +334,20 @@ export function useWikiEditor({ value, onChange, placeholder = '', nodes = [], p
328
334
  },
329
335
  onUpdate: ({ editor }) => {
330
336
  clearTimeout(debounceRef.current);
331
- debounceRef.current = setTimeout(() => onChangeRef.current(editor.getHTML()), debounceMs);
337
+ pendingRef.current = true;
338
+ debounceRef.current = setTimeout(() => {
339
+ pendingRef.current = false;
340
+ onChangeRef.current(editor.getHTML());
341
+ }, debounceMs);
332
342
  },
333
- // Flush the pending debounce on blur, so a quick Save — which blurs the
334
- // editor before the click fires — never drops the final keystroke.
343
+ // Flush a pending edit on blur, so a quick Save — which blurs the editor
344
+ // before the click fires — never drops the final keystroke. A blur with no
345
+ // edit reports nothing.
335
346
  onBlur: ({ editor }) => {
336
347
  clearTimeout(debounceRef.current);
348
+ if (!pendingRef.current)
349
+ return;
350
+ pendingRef.current = false;
337
351
  onChangeRef.current(editor.getHTML());
338
352
  },
339
353
  immediatelyRender: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-formant",
3
- "version": "0.44.0",
3
+ "version": "0.44.1",
4
4
  "description": "The portable half of a wiki: derived taxonomy and facet controls, a version-negotiating MCP transport, markdown twins, block rendering, a rich-text editor engine, conditional-GET plumbing, and the headers and CSP every origin sends.",
5
5
  "type": "module",
6
6
  "license": "MIT",