mantine-double-click-editable 1.0.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/README.md +45 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +56 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# mantine-double-click-editable
|
|
2
|
+
|
|
3
|
+
A double-click-to-edit text component for [Mantine](https://mantine.dev/), with precise caret placement.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install mantine-double-click-editable
|
|
9
|
+
# or
|
|
10
|
+
yarn add mantine-double-click-editable
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Peer Dependencies
|
|
14
|
+
|
|
15
|
+
Ensure you have `@mantine/core`, `@mantine/hooks`, `react`, and `react-dom` installed in your project.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { DoubleClickEditable } from 'mantine-double-click-editable';
|
|
21
|
+
import '@mantine/core/styles.css';
|
|
22
|
+
|
|
23
|
+
function MyComponent() {
|
|
24
|
+
return (
|
|
25
|
+
<DoubleClickEditable
|
|
26
|
+
onSave={(content) => console.log('Saved:', content)}
|
|
27
|
+
c="blue"
|
|
28
|
+
fw={700}
|
|
29
|
+
>
|
|
30
|
+
Double-click to edit me!
|
|
31
|
+
</DoubleClickEditable>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **Double-click to edit:** Seamlessly transition between view and edit modes.
|
|
39
|
+
- **Precise Caret Placement:** The cursor is placed exactly where you double-click, even in the middle of text.
|
|
40
|
+
- **Mantine Integration:** Inherits all props from Mantine's `Text` component.
|
|
41
|
+
- **TypeScript Support:** Fully typed out of the box.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),b=require("react"),p=require("@mantine/core");function R({children:l,onSave:a,style:u,...d}){const[i,c]=b.useState(!1),f=e=>{c(!0);const o=e.clientX,s=e.clientY;setTimeout(()=>{const n=window.getSelection();if(n){if(document.caretRangeFromPoint){const t=document.caretRangeFromPoint(o,s);t&&(n.removeAllRanges(),n.addRange(t))}else if(document.caretPositionFromPoint){const t=document.caretPositionFromPoint(o,s);if(t){const r=document.createRange();r.setStart(t.offsetNode,t.offset),r.collapse(!0),n.removeAllRanges(),n.addRange(r)}}}},0)},g=e=>{c(!1);const o=e.currentTarget.innerHTML;a?.(o)};return m.jsx(p.Text,{...d,contentEditable:i,suppressContentEditableWarning:!0,style:{border:"1px dashed #ccc",padding:"4px",cursor:i?"text":"pointer",...u},onMouseDown:e=>{e.detail>1&&e.preventDefault()},onDoubleClick:f,onBlur:g,children:l})}exports.DoubleClickEditable=R;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import { useState as p } from "react";
|
|
3
|
+
import { Text as b } from "@mantine/core";
|
|
4
|
+
function C({
|
|
5
|
+
children: a,
|
|
6
|
+
onSave: l,
|
|
7
|
+
style: d,
|
|
8
|
+
...u
|
|
9
|
+
}) {
|
|
10
|
+
const [i, c] = p(!1), m = (e) => {
|
|
11
|
+
c(!0);
|
|
12
|
+
const o = e.clientX, s = e.clientY;
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
const n = window.getSelection();
|
|
15
|
+
if (n) {
|
|
16
|
+
if (document.caretRangeFromPoint) {
|
|
17
|
+
const t = document.caretRangeFromPoint(o, s);
|
|
18
|
+
t && (n.removeAllRanges(), n.addRange(t));
|
|
19
|
+
} else if (document.caretPositionFromPoint) {
|
|
20
|
+
const t = document.caretPositionFromPoint(o, s);
|
|
21
|
+
if (t) {
|
|
22
|
+
const r = document.createRange();
|
|
23
|
+
r.setStart(t.offsetNode, t.offset), r.collapse(!0), n.removeAllRanges(), n.addRange(r);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, 0);
|
|
28
|
+
}, f = (e) => {
|
|
29
|
+
c(!1);
|
|
30
|
+
const o = e.currentTarget.innerHTML;
|
|
31
|
+
l?.(o);
|
|
32
|
+
};
|
|
33
|
+
return /* @__PURE__ */ g(
|
|
34
|
+
b,
|
|
35
|
+
{
|
|
36
|
+
...u,
|
|
37
|
+
contentEditable: i,
|
|
38
|
+
suppressContentEditableWarning: !0,
|
|
39
|
+
style: {
|
|
40
|
+
border: "1px dashed #ccc",
|
|
41
|
+
padding: "4px",
|
|
42
|
+
cursor: i ? "text" : "pointer",
|
|
43
|
+
...d
|
|
44
|
+
},
|
|
45
|
+
onMouseDown: (e) => {
|
|
46
|
+
e.detail > 1 && e.preventDefault();
|
|
47
|
+
},
|
|
48
|
+
onDoubleClick: m,
|
|
49
|
+
onBlur: f,
|
|
50
|
+
children: a
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
C as DoubleClickEditable
|
|
56
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mantine-double-click-editable",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite",
|
|
21
|
+
"build": "tsc -b && vite build",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"preview": "vite preview"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@mantine/core": ">=7.0.0",
|
|
27
|
+
"@mantine/hooks": ">=7.0.0",
|
|
28
|
+
"react": ">=18.0.0",
|
|
29
|
+
"react-dom": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@eslint/js": "^9.39.1",
|
|
33
|
+
"@mantine/core": "^8.3.10",
|
|
34
|
+
"@mantine/hooks": "^8.3.10",
|
|
35
|
+
"@types/node": "^24.10.1",
|
|
36
|
+
"@types/react": "^19.2.5",
|
|
37
|
+
"@types/react-dom": "^19.2.3",
|
|
38
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
39
|
+
"eslint": "^9.39.1",
|
|
40
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
41
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
42
|
+
"globals": "^16.5.0",
|
|
43
|
+
"postcss": "^8.5.6",
|
|
44
|
+
"postcss-preset-mantine": "^1.18.0",
|
|
45
|
+
"postcss-simple-vars": "^7.0.1",
|
|
46
|
+
"react": "^19.2.0",
|
|
47
|
+
"react-dom": "^19.2.0",
|
|
48
|
+
"typescript": "~5.9.3",
|
|
49
|
+
"typescript-eslint": "^8.46.4",
|
|
50
|
+
"vite": "^7.3.0",
|
|
51
|
+
"vite-plugin-dts": "^4.5.1"
|
|
52
|
+
}
|
|
53
|
+
}
|