mantine-double-click-editable 1.0.2 → 1.0.3
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.cjs +1 -1
- package/dist/index.js +29 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),i=require("react"),R=require("@mantine/core");function D({children:s,onSave:d,style:f,...m}){const[r,l]=i.useState(!1),a=i.useRef(null);i.useEffect(()=>{!r&&a.current&&(a.current.innerText=s)},[s,r]);const p=e=>{l(!0);const t=e.clientX,u=e.clientY;setTimeout(()=>{const o=window.getSelection();if(o){if(document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,u);n&&(o.removeAllRanges(),o.addRange(n))}else if(document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,u);if(n){const c=document.createRange();c.setStart(n.offsetNode,n.offset),c.collapse(!0),o.removeAllRanges(),o.addRange(c)}}}},0)},g=e=>{l(!1);const t=e.currentTarget.innerText;d?.(t)},b=e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)};return x.jsx(R.Text,{...m,ref:a,contentEditable:r?"plaintext-only":!1,suppressContentEditableWarning:!0,style:{border:"1px dashed #ccc",padding:"4px",cursor:r?"text":"pointer",whiteSpace:"pre-wrap",...f},onMouseDown:e=>{e.detail>1&&e.preventDefault()},onDoubleClick:p,onBlur:g,onPaste:b})}exports.DoubleClickEditable=D;
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { Text as
|
|
4
|
-
function
|
|
5
|
-
children:
|
|
6
|
-
onSave:
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { useState as b, useRef as R, useEffect as D } from "react";
|
|
3
|
+
import { Text as P } from "@mantine/core";
|
|
4
|
+
function T({
|
|
5
|
+
children: i,
|
|
6
|
+
onSave: u,
|
|
7
7
|
style: d,
|
|
8
|
-
...
|
|
8
|
+
...f
|
|
9
9
|
}) {
|
|
10
|
-
const [r,
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const [r, s] = b(!1), a = R(null);
|
|
11
|
+
D(() => {
|
|
12
|
+
!r && a.current && (a.current.innerText = i);
|
|
13
|
+
}, [i, r]);
|
|
14
|
+
const m = (e) => {
|
|
15
|
+
s(!0);
|
|
16
|
+
const t = e.clientX, l = e.clientY;
|
|
13
17
|
setTimeout(() => {
|
|
14
18
|
const o = window.getSelection();
|
|
15
19
|
if (o) {
|
|
16
20
|
if (document.caretRangeFromPoint) {
|
|
17
|
-
const n = document.caretRangeFromPoint(t,
|
|
21
|
+
const n = document.caretRangeFromPoint(t, l);
|
|
18
22
|
n && (o.removeAllRanges(), o.addRange(n));
|
|
19
23
|
} else if (document.caretPositionFromPoint) {
|
|
20
|
-
const n = document.caretPositionFromPoint(t,
|
|
24
|
+
const n = document.caretPositionFromPoint(t, l);
|
|
21
25
|
if (n) {
|
|
22
|
-
const
|
|
23
|
-
|
|
26
|
+
const c = document.createRange();
|
|
27
|
+
c.setStart(n.offsetNode, n.offset), c.collapse(!0), o.removeAllRanges(), o.addRange(c);
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
}, 0);
|
|
28
|
-
}, f = (e) => {
|
|
29
|
-
i(!1);
|
|
30
|
-
const t = e.currentTarget.innerText;
|
|
31
|
-
l?.(t);
|
|
32
32
|
}, p = (e) => {
|
|
33
|
+
s(!1);
|
|
34
|
+
const t = e.currentTarget.innerText;
|
|
35
|
+
u?.(t);
|
|
36
|
+
}, g = (e) => {
|
|
33
37
|
e.preventDefault();
|
|
34
38
|
const t = e.clipboardData.getData("text/plain");
|
|
35
39
|
document.execCommand("insertText", !1, t);
|
|
36
40
|
};
|
|
37
|
-
return /* @__PURE__ */
|
|
38
|
-
|
|
41
|
+
return /* @__PURE__ */ x(
|
|
42
|
+
P,
|
|
39
43
|
{
|
|
40
|
-
...
|
|
44
|
+
...f,
|
|
45
|
+
ref: a,
|
|
41
46
|
contentEditable: r ? "plaintext-only" : !1,
|
|
42
47
|
suppressContentEditableWarning: !0,
|
|
43
48
|
style: {
|
|
@@ -51,12 +56,11 @@ function w({
|
|
|
51
56
|
e.detail > 1 && e.preventDefault();
|
|
52
57
|
},
|
|
53
58
|
onDoubleClick: m,
|
|
54
|
-
onBlur:
|
|
55
|
-
onPaste:
|
|
56
|
-
children: s
|
|
59
|
+
onBlur: p,
|
|
60
|
+
onPaste: g
|
|
57
61
|
}
|
|
58
62
|
);
|
|
59
63
|
}
|
|
60
64
|
export {
|
|
61
|
-
|
|
65
|
+
T as DoubleClickEditable
|
|
62
66
|
};
|