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 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
+ [![npm version](https://img.shields.io/npm/v/mantine-double-click-editable.svg)](https://www.npmjs.com/package/mantine-double-click-editable)
6
+ [![github](https://img.shields.io/badge/github-repo-black?logo=github)](https://github.com/ypyl/DoubleClickEditable)
7
+
8
+ ## Demo
9
+
10
+ ![demo](./msedge_g0RHaauDdc.gif)
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 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;
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 p } from "react";
2
+ import { useState as x } from "react";
3
3
  import { Text as b } from "@mantine/core";
4
- function C({
5
- children: a,
4
+ function w({
5
+ children: s,
6
6
  onSave: l,
7
7
  style: d,
8
8
  ...u
9
9
  }) {
10
- const [i, c] = p(!1), m = (e) => {
11
- c(!0);
12
- const o = e.clientX, s = e.clientY;
10
+ const [r, i] = x(!1), m = (e) => {
11
+ i(!0);
12
+ const t = e.clientX, c = e.clientY;
13
13
  setTimeout(() => {
14
- const n = window.getSelection();
15
- if (n) {
14
+ const o = window.getSelection();
15
+ if (o) {
16
16
  if (document.caretRangeFromPoint) {
17
- const t = document.caretRangeFromPoint(o, s);
18
- t && (n.removeAllRanges(), n.addRange(t));
17
+ const n = document.caretRangeFromPoint(t, c);
18
+ n && (o.removeAllRanges(), o.addRange(n));
19
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);
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
- c(!1);
30
- const o = e.currentTarget.innerHTML;
31
- l?.(o);
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: i,
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: i ? "text" : "pointer",
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
- children: a
55
+ onPaste: p,
56
+ children: s
51
57
  }
52
58
  );
53
59
  }
54
60
  export {
55
- C as DoubleClickEditable
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.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",