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

|
|
11
|
+
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
7
14
|
```bash
|
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 g=require("react/jsx-runtime"),b=require("react"),x=require("@mantine/core");function D({children:s,onSave:l,style:u,...d}){const[r,c]=b.useState(!1),f=e=>{c(!0);const t=e.clientX,i=e.clientY;setTimeout(()=>{const o=window.getSelection();if(o){if(document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,i);n&&(o.removeAllRanges(),o.addRange(n))}else if(document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,i);if(n){const a=document.createRange();a.setStart(n.offsetNode,n.offset),a.collapse(!0),o.removeAllRanges(),o.addRange(a)}}}},0)},m=e=>{c(!1);const t=e.currentTarget.innerText;l?.(t)},p=e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)};return g.jsx(x.Text,{...d,contentEditable:r?"plaintext-only":!1,suppressContentEditableWarning:!0,style:{border:"1px dashed #ccc",padding:"4px",cursor:r?"text":"pointer",whiteSpace:"pre-wrap",...u},onMouseDown:e=>{e.detail>1&&e.preventDefault()},onDoubleClick:f,onBlur:m,onPaste:p,children:s})}exports.DoubleClickEditable=D;
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,50 @@
|
|
|
1
1
|
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as x } from "react";
|
|
3
3
|
import { Text as b } from "@mantine/core";
|
|
4
|
-
function
|
|
5
|
-
children:
|
|
4
|
+
function w({
|
|
5
|
+
children: s,
|
|
6
6
|
onSave: l,
|
|
7
7
|
style: d,
|
|
8
8
|
...u
|
|
9
9
|
}) {
|
|
10
|
-
const [
|
|
11
|
-
|
|
12
|
-
const
|
|
10
|
+
const [r, i] = x(!1), m = (e) => {
|
|
11
|
+
i(!0);
|
|
12
|
+
const t = e.clientX, c = e.clientY;
|
|
13
13
|
setTimeout(() => {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
14
|
+
const o = window.getSelection();
|
|
15
|
+
if (o) {
|
|
16
16
|
if (document.caretRangeFromPoint) {
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const n = document.caretRangeFromPoint(t, c);
|
|
18
|
+
n && (o.removeAllRanges(), o.addRange(n));
|
|
19
19
|
} else if (document.caretPositionFromPoint) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
|
|
20
|
+
const n = document.caretPositionFromPoint(t, c);
|
|
21
|
+
if (n) {
|
|
22
|
+
const a = document.createRange();
|
|
23
|
+
a.setStart(n.offsetNode, n.offset), a.collapse(!0), o.removeAllRanges(), o.addRange(a);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}, 0);
|
|
28
28
|
}, f = (e) => {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
l?.(
|
|
29
|
+
i(!1);
|
|
30
|
+
const t = e.currentTarget.innerText;
|
|
31
|
+
l?.(t);
|
|
32
|
+
}, p = (e) => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
const t = e.clipboardData.getData("text/plain");
|
|
35
|
+
document.execCommand("insertText", !1, t);
|
|
32
36
|
};
|
|
33
37
|
return /* @__PURE__ */ g(
|
|
34
38
|
b,
|
|
35
39
|
{
|
|
36
40
|
...u,
|
|
37
|
-
contentEditable:
|
|
41
|
+
contentEditable: r ? "plaintext-only" : !1,
|
|
38
42
|
suppressContentEditableWarning: !0,
|
|
39
43
|
style: {
|
|
40
44
|
border: "1px dashed #ccc",
|
|
41
45
|
padding: "4px",
|
|
42
|
-
cursor:
|
|
46
|
+
cursor: r ? "text" : "pointer",
|
|
47
|
+
whiteSpace: "pre-wrap",
|
|
43
48
|
...d
|
|
44
49
|
},
|
|
45
50
|
onMouseDown: (e) => {
|
|
@@ -47,10 +52,11 @@ function C({
|
|
|
47
52
|
},
|
|
48
53
|
onDoubleClick: m,
|
|
49
54
|
onBlur: f,
|
|
50
|
-
|
|
55
|
+
onPaste: p,
|
|
56
|
+
children: s
|
|
51
57
|
}
|
|
52
58
|
);
|
|
53
59
|
}
|
|
54
60
|
export {
|
|
55
|
-
|
|
61
|
+
w as DoubleClickEditable
|
|
56
62
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mantine-double-click-editable",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/ypyl/DoubleClickEditable.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/ypyl/DoubleClickEditable/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/ypyl/DoubleClickEditable#readme",
|
|
5
13
|
"type": "module",
|
|
6
14
|
"main": "./dist/index.cjs",
|
|
7
15
|
"module": "./dist/index.js",
|