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 CHANGED
@@ -1 +1 @@
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;
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 g } from "react/jsx-runtime";
2
- import { useState as x } from "react";
3
- import { Text as b } from "@mantine/core";
4
- function w({
5
- children: s,
6
- onSave: l,
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
- ...u
8
+ ...f
9
9
  }) {
10
- const [r, i] = x(!1), m = (e) => {
11
- i(!0);
12
- const t = e.clientX, c = e.clientY;
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, c);
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, c);
24
+ const n = document.caretPositionFromPoint(t, l);
21
25
  if (n) {
22
- const a = document.createRange();
23
- a.setStart(n.offsetNode, n.offset), a.collapse(!0), o.removeAllRanges(), o.addRange(a);
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__ */ g(
38
- b,
41
+ return /* @__PURE__ */ x(
42
+ P,
39
43
  {
40
- ...u,
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: f,
55
- onPaste: p,
56
- children: s
59
+ onBlur: p,
60
+ onPaste: g
57
61
  }
58
62
  );
59
63
  }
60
64
  export {
61
- w as DoubleClickEditable
65
+ T as DoubleClickEditable
62
66
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mantine-double-click-editable",
3
3
  "private": false,
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ypyl/DoubleClickEditable.git"