@estiva-app/ui 0.73.0-inline-text.1 → 0.73.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/dist/InlineText.d.ts.map +1 -1
- package/dist/editor.js +17 -4
- package/dist/editor.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +1 -1
- package/src/InlineText.test.tsx +21 -0
- package/src/InlineText.tsx +21 -4
package/dist/InlineText.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineText.d.ts","sourceRoot":"","sources":["../src/InlineText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AAM/F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,eAAe;IAC9B,oGAAoG;IACpG,KAAK,EAAE,MAAM,CAAA;IACb,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAA;IACnB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;IACvD,sGAAsG;IACtG,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACtC,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,oGAAoG;IACpG,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAA;CAC5B;AAED,KAAK,OAAO,GAAG,OAAO,GAAG,KAAK,CAA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MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CAC9B;AAmCD,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAiB,EAAE,SAAiB,EAAE,QAAgB,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,eAAe,+BA6G3K"}
|
package/dist/editor.js
CHANGED
|
@@ -560,13 +560,19 @@ var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
|
560
560
|
function InlineText({ value, placeholder, label, onCommit, onText, onEnter, variant = "title", clearable = false, readOnly = false, className, ref }) {
|
|
561
561
|
const saved = useRef3(value);
|
|
562
562
|
const [empty, setEmpty] = useState3(!value);
|
|
563
|
-
const latest = useRef3({ onEnter, onText, onCommit, clearable });
|
|
564
|
-
latest.current = { onEnter, onText, onCommit, clearable };
|
|
563
|
+
const latest = useRef3({ onEnter, onText, onCommit, clearable, value });
|
|
564
|
+
latest.current = { onEnter, onText, onCommit, clearable, value };
|
|
565
|
+
const pending = useRef3(null);
|
|
565
566
|
const save = useCallback3(async (text) => {
|
|
566
567
|
const next = oneLine(text);
|
|
567
|
-
if (next === saved.current) return;
|
|
568
|
+
if (next === saved.current || next === pending.current) return;
|
|
568
569
|
if (!next && !latest.current.clearable) return;
|
|
569
|
-
|
|
570
|
+
pending.current = next;
|
|
571
|
+
try {
|
|
572
|
+
if (await latest.current.onCommit(next)) saved.current = next;
|
|
573
|
+
} finally {
|
|
574
|
+
if (pending.current === next) pending.current = null;
|
|
575
|
+
}
|
|
570
576
|
}, []);
|
|
571
577
|
const editor = useEditor({
|
|
572
578
|
extensions: [OneLine, Paragraph, Text, Undo],
|
|
@@ -614,6 +620,13 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
614
620
|
setEmpty(false);
|
|
615
621
|
return;
|
|
616
622
|
}
|
|
623
|
+
const { value: current } = latest.current;
|
|
624
|
+
if (oneLine(e.getText()) === saved.current && current !== saved.current && pending.current === null) {
|
|
625
|
+
e.commands.setContent(doc(current), { emitUpdate: false });
|
|
626
|
+
saved.current = current;
|
|
627
|
+
setEmpty(!current);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
617
630
|
void save(e.getText());
|
|
618
631
|
}
|
|
619
632
|
}, [readOnly]);
|