mantine-double-click-editable 1.0.1 → 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/README.md +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +40 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,9 @@ A double-click-to-edit text component for [Mantine](https://mantine.dev/), with
|
|
|
5
5
|
[](https://www.npmjs.com/package/mantine-double-click-editable)
|
|
6
6
|
[](https://github.com/ypyl/DoubleClickEditable)
|
|
7
7
|
|
|
8
|
+
## Demo
|
|
9
|
+
|
|
10
|
+

|
|
8
11
|
|
|
9
12
|
## Installation
|
|
10
13
|
|
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,56 +1,66 @@
|
|
|
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 [
|
|
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
|
-
const
|
|
15
|
-
if (
|
|
18
|
+
const o = window.getSelection();
|
|
19
|
+
if (o) {
|
|
16
20
|
if (document.caretRangeFromPoint) {
|
|
17
|
-
const
|
|
18
|
-
|
|
21
|
+
const n = document.caretRangeFromPoint(t, l);
|
|
22
|
+
n && (o.removeAllRanges(), o.addRange(n));
|
|
19
23
|
} else if (document.caretPositionFromPoint) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
+
const n = document.caretPositionFromPoint(t, l);
|
|
25
|
+
if (n) {
|
|
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
|
-
},
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
+
}, p = (e) => {
|
|
33
|
+
s(!1);
|
|
34
|
+
const t = e.currentTarget.innerText;
|
|
35
|
+
u?.(t);
|
|
36
|
+
}, g = (e) => {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
const t = e.clipboardData.getData("text/plain");
|
|
39
|
+
document.execCommand("insertText", !1, t);
|
|
32
40
|
};
|
|
33
|
-
return /* @__PURE__ */
|
|
34
|
-
|
|
41
|
+
return /* @__PURE__ */ x(
|
|
42
|
+
P,
|
|
35
43
|
{
|
|
36
|
-
...
|
|
37
|
-
|
|
44
|
+
...f,
|
|
45
|
+
ref: a,
|
|
46
|
+
contentEditable: r ? "plaintext-only" : !1,
|
|
38
47
|
suppressContentEditableWarning: !0,
|
|
39
48
|
style: {
|
|
40
49
|
border: "1px dashed #ccc",
|
|
41
50
|
padding: "4px",
|
|
42
|
-
cursor:
|
|
51
|
+
cursor: r ? "text" : "pointer",
|
|
52
|
+
whiteSpace: "pre-wrap",
|
|
43
53
|
...d
|
|
44
54
|
},
|
|
45
55
|
onMouseDown: (e) => {
|
|
46
56
|
e.detail > 1 && e.preventDefault();
|
|
47
57
|
},
|
|
48
58
|
onDoubleClick: m,
|
|
49
|
-
onBlur:
|
|
50
|
-
|
|
59
|
+
onBlur: p,
|
|
60
|
+
onPaste: g
|
|
51
61
|
}
|
|
52
62
|
);
|
|
53
63
|
}
|
|
54
64
|
export {
|
|
55
|
-
|
|
65
|
+
T as DoubleClickEditable
|
|
56
66
|
};
|