dishui 0.0.78 → 0.0.80

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.
Files changed (48) hide show
  1. package/dist/components/Avatar/index.d.ts +6 -4
  2. package/dist/components/Avatar/index.js +39 -28
  3. package/dist/components/Avatar/index.js.map +1 -1
  4. package/dist/components/Card/index.d.ts +16 -8
  5. package/dist/components/Card/index.js +81 -99
  6. package/dist/components/Card/index.js.map +1 -1
  7. package/dist/components/DateTimeInput/index.js +3 -2
  8. package/dist/components/DateTimeInput/index.js.map +1 -1
  9. package/dist/components/GroupedTable/index.d.ts +2 -1
  10. package/dist/components/GroupedTable/index.js +96 -37
  11. package/dist/components/GroupedTable/index.js.map +1 -1
  12. package/dist/components/Input/index.d.ts +2 -2
  13. package/dist/components/Input/index.js +129 -111
  14. package/dist/components/Input/index.js.map +1 -1
  15. package/dist/components/Label/index.js +1 -1
  16. package/dist/components/Label/index.js.map +1 -1
  17. package/dist/components/NavigationList/index.js +55 -24
  18. package/dist/components/NavigationList/index.js.map +1 -1
  19. package/dist/components/Resizable/index.d.ts +28 -0
  20. package/dist/components/Resizable/index.js +128 -0
  21. package/dist/components/Resizable/index.js.map +1 -0
  22. package/dist/components/Resizable/useResize.d.ts +21 -0
  23. package/dist/components/Resizable/useResize.js +60 -0
  24. package/dist/components/Resizable/useResize.js.map +1 -0
  25. package/dist/components/SidebarToggleButton/index.js +51 -43
  26. package/dist/components/SidebarToggleButton/index.js.map +1 -1
  27. package/dist/components/Slider/index.d.ts +17 -3
  28. package/dist/components/Slider/index.js +131 -28
  29. package/dist/components/Slider/index.js.map +1 -1
  30. package/dist/components/pro/RichTextEditor/RichTextEditor.js +62 -62
  31. package/dist/components/pro/RichTextEditor/RichTextEditor.js.map +1 -1
  32. package/dist/components/pro/RichTextEditor/extensions/ResizableImage.d.ts +2 -0
  33. package/dist/components/pro/RichTextEditor/extensions/ResizableImage.js +94 -0
  34. package/dist/components/pro/RichTextEditor/extensions/ResizableImage.js.map +1 -0
  35. package/dist/components/pro/RichTextEditor/index.d.ts +1 -0
  36. package/dist/dishui.css +1 -1
  37. package/dist/index-nostyled.d.ts +2 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +123 -121
  40. package/dist/layouts/Sidebar.js +34 -45
  41. package/dist/layouts/Sidebar.js.map +1 -1
  42. package/dist/lite.d.ts +2 -0
  43. package/dist/lite.js +20 -18
  44. package/dist/utils/i18n.js +145 -75
  45. package/dist/utils/i18n.js.map +1 -1
  46. package/dist/utils/menu.js +85 -8
  47. package/dist/utils/menu.js.map +1 -1
  48. package/package.json +1 -1
@@ -0,0 +1,94 @@
1
+ import { useNodeEditable as e } from "./MarkdownBlock.js";
2
+ import { useCallback as t, useRef as n, useState as r } from "react";
3
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
4
+ import { NodeViewWrapper as o, ReactNodeViewRenderer as s } from "@tiptap/react";
5
+ import c from "@tiptap/extension-image";
6
+ //#region src/components/pro/RichTextEditor/extensions/ResizableImage.tsx
7
+ var l = 40, u = ({ node: s, updateAttributes: c, selected: u, editor: d }) => {
8
+ let f = e(d), p = n(null), [m, h] = r(!1), { src: g, alt: _, title: v, width: y, align: b } = s.attrs, x = t((e) => (t) => {
9
+ if (!f) return;
10
+ t.preventDefault(), t.stopPropagation();
11
+ let n = p.current;
12
+ if (!n) return;
13
+ let r = "touches" in t ? t.touches[0].clientX : t.clientX, i = n.getBoundingClientRect().width, a = n.naturalHeight && n.naturalWidth ? n.naturalHeight / n.naturalWidth : 0, o = e === "nw" || e === "sw" ? -1 : 1, s = n.parentElement?.parentElement?.getBoundingClientRect().width ?? Infinity;
14
+ h(!0);
15
+ let u = (e) => {
16
+ let t = (e - r) * o, n = Math.round(Math.min(s, Math.max(l, i + t)));
17
+ c({
18
+ width: n,
19
+ height: a ? Math.round(n * a) : null
20
+ });
21
+ }, d = (e) => u(e.clientX), m = (e) => {
22
+ e.cancelable && e.preventDefault(), u(e.touches[0].clientX);
23
+ }, g = () => {
24
+ h(!1), window.removeEventListener("mousemove", d), window.removeEventListener("mouseup", g), window.removeEventListener("touchmove", m), window.removeEventListener("touchend", g), window.removeEventListener("touchcancel", g);
25
+ };
26
+ window.addEventListener("mousemove", d), window.addEventListener("mouseup", g), window.addEventListener("touchmove", m, { passive: !1 }), window.addEventListener("touchend", g), window.addEventListener("touchcancel", g);
27
+ }, [f, c]), S = f && (u || m);
28
+ return /* @__PURE__ */ i(o, {
29
+ className: "rte-resizable-image",
30
+ "data-align": b || "left",
31
+ "data-active": S ? "true" : void 0,
32
+ children: /* @__PURE__ */ a("span", {
33
+ className: "rte-resizable-image__frame",
34
+ style: { width: y ? `${y}px` : void 0 },
35
+ children: [/* @__PURE__ */ i("img", {
36
+ ref: p,
37
+ src: g,
38
+ alt: _ || "",
39
+ title: v || void 0,
40
+ draggable: !1,
41
+ style: { width: y ? `${y}px` : void 0 }
42
+ }), S && [
43
+ "nw",
44
+ "ne",
45
+ "sw",
46
+ "se"
47
+ ].map((e) => /* @__PURE__ */ i("span", {
48
+ className: `rte-resizable-image__handle rte-resizable-image__handle--${e}`,
49
+ onMouseDown: x(e),
50
+ onTouchStart: x(e),
51
+ role: "presentation"
52
+ }, e))]
53
+ })
54
+ });
55
+ }, d = c.extend({
56
+ addAttributes() {
57
+ return {
58
+ ...this.parent?.(),
59
+ width: {
60
+ default: null,
61
+ parseHTML: (e) => {
62
+ let t = e.getAttribute("width");
63
+ if (t) return parseInt(t, 10) || null;
64
+ let n = e.style.width;
65
+ return n && parseInt(n, 10) || null;
66
+ },
67
+ renderHTML: (e) => e.width ? {
68
+ width: e.width,
69
+ style: `width: ${e.width}px`
70
+ } : {}
71
+ },
72
+ height: {
73
+ default: null,
74
+ parseHTML: (e) => {
75
+ let t = e.getAttribute("height");
76
+ return t && parseInt(t, 10) || null;
77
+ },
78
+ renderHTML: (e) => e.height ? { height: e.height } : {}
79
+ },
80
+ align: {
81
+ default: "left",
82
+ parseHTML: (e) => e.getAttribute("data-align") || "left",
83
+ renderHTML: (e) => e.align ? { "data-align": e.align } : {}
84
+ }
85
+ };
86
+ },
87
+ addNodeView() {
88
+ return s(u);
89
+ }
90
+ });
91
+ //#endregion
92
+ export { d as ResizableImage, d as default };
93
+
94
+ //# sourceMappingURL=ResizableImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResizableImage.js","names":[],"sources":["../../../../../src/components/pro/RichTextEditor/extensions/ResizableImage.tsx"],"sourcesContent":["import React, { useCallback, useRef, useState } from 'react';\nimport Image from '@tiptap/extension-image';\nimport { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';\nimport type { NodeViewProps } from '@tiptap/react';\nimport { useNodeEditable } from './MarkdownBlock';\n\n/**\n * ResizableImage extends the stock Tiptap Image node with:\n * - persisted `width` / `height` / `align` attributes (serialized to HTML)\n * - a React NodeView that renders drag handles on the four corners so users can\n * resize the image by dragging (mouse + touch), keeping the aspect ratio.\n *\n * The public API is unchanged: `editor.chain().setImage({ src })` still works,\n * and existing documents (plain `<img>`) upgrade transparently.\n */\n\nconst MIN_WIDTH = 40;\n\ntype Corner = 'nw' | 'ne' | 'sw' | 'se';\n\nconst ResizableImageNodeView: React.FC<NodeViewProps> = ({ node, updateAttributes, selected, editor }) => {\n const editable = useNodeEditable(editor);\n const imgRef = useRef<HTMLImageElement>(null);\n const [resizing, setResizing] = useState(false);\n\n const { src, alt, title, width, align } = node.attrs as {\n src: string;\n alt?: string;\n title?: string;\n width?: number | null;\n height?: number | null;\n align?: 'left' | 'center' | 'right' | null;\n };\n\n const startResize = useCallback(\n (corner: Corner) => (event: React.MouseEvent | React.TouchEvent) => {\n if (!editable) return;\n event.preventDefault();\n event.stopPropagation();\n\n const img = imgRef.current;\n if (!img) return;\n\n const isTouch = 'touches' in event;\n const startX = isTouch ? event.touches[0].clientX : (event as React.MouseEvent).clientX;\n const startWidth = img.getBoundingClientRect().width;\n const ratio = img.naturalHeight && img.naturalWidth ? img.naturalHeight / img.naturalWidth : 0;\n // Left-side handles grow the image when dragged leftwards.\n const dir = corner === 'nw' || corner === 'sw' ? -1 : 1;\n const maxWidth = img.parentElement?.parentElement?.getBoundingClientRect().width ?? Infinity;\n\n setResizing(true);\n\n const move = (clientX: number) => {\n const delta = (clientX - startX) * dir;\n const next = Math.round(Math.min(maxWidth, Math.max(MIN_WIDTH, startWidth + delta)));\n updateAttributes({ width: next, height: ratio ? Math.round(next * ratio) : null });\n };\n\n const onMouseMove = (e: MouseEvent) => move(e.clientX);\n const onTouchMove = (e: TouchEvent) => {\n if (e.cancelable) e.preventDefault();\n move(e.touches[0].clientX);\n };\n const stop = () => {\n setResizing(false);\n window.removeEventListener('mousemove', onMouseMove);\n window.removeEventListener('mouseup', stop);\n window.removeEventListener('touchmove', onTouchMove);\n window.removeEventListener('touchend', stop);\n window.removeEventListener('touchcancel', stop);\n };\n\n window.addEventListener('mousemove', onMouseMove);\n window.addEventListener('mouseup', stop);\n window.addEventListener('touchmove', onTouchMove, { passive: false });\n window.addEventListener('touchend', stop);\n window.addEventListener('touchcancel', stop);\n },\n [editable, updateAttributes],\n );\n\n const active = editable && (selected || resizing);\n const corners: Corner[] = ['nw', 'ne', 'sw', 'se'];\n\n return (\n <NodeViewWrapper\n className=\"rte-resizable-image\"\n data-align={align || 'left'}\n data-active={active ? 'true' : undefined}\n >\n <span className=\"rte-resizable-image__frame\" style={{ width: width ? `${width}px` : undefined }}>\n <img\n ref={imgRef}\n src={src}\n alt={alt || ''}\n title={title || undefined}\n draggable={false}\n style={{ width: width ? `${width}px` : undefined }}\n />\n {active &&\n corners.map((corner) => (\n <span\n key={corner}\n className={`rte-resizable-image__handle rte-resizable-image__handle--${corner}`}\n onMouseDown={startResize(corner)}\n onTouchStart={startResize(corner)}\n role=\"presentation\"\n />\n ))}\n </span>\n </NodeViewWrapper>\n );\n};\n\nexport const ResizableImage = Image.extend({\n addAttributes() {\n return {\n ...this.parent?.(),\n width: {\n default: null,\n parseHTML: (element) => {\n const attr = element.getAttribute('width');\n if (attr) return parseInt(attr, 10) || null;\n const style = element.style.width;\n return style ? parseInt(style, 10) || null : null;\n },\n renderHTML: (attributes) =>\n attributes.width ? { width: attributes.width, style: `width: ${attributes.width}px` } : {},\n },\n height: {\n default: null,\n parseHTML: (element) => {\n const attr = element.getAttribute('height');\n return attr ? parseInt(attr, 10) || null : null;\n },\n renderHTML: (attributes) => (attributes.height ? { height: attributes.height } : {}),\n },\n align: {\n default: 'left',\n parseHTML: (element) => element.getAttribute('data-align') || 'left',\n renderHTML: (attributes) => (attributes.align ? { 'data-align': attributes.align } : {}),\n },\n };\n },\n addNodeView() {\n return ReactNodeViewRenderer(ResizableImageNodeView);\n },\n});\n\nexport default ResizableImage;\n"],"mappings":";;;;;;AAgBA,IAAM,IAAY,IAIZ,KAAmD,EAAE,SAAM,qBAAkB,aAAU,gBAAa;CACxG,IAAM,IAAW,EAAgB,CAAM,GACjC,IAAS,EAAyB,IAAI,GACtC,CAAC,GAAU,KAAe,EAAS,EAAK,GAExC,EAAE,QAAK,QAAK,UAAO,UAAO,aAAU,EAAK,OASzC,IAAc,GACjB,OAAoB,MAA+C;EAClE,IAAI,CAAC,GAAU;EAEf,AADA,EAAM,eAAe,GACrB,EAAM,gBAAgB;EAEtB,IAAM,IAAM,EAAO;EACnB,IAAI,CAAC,GAAK;EAGV,IAAM,IADU,aAAa,IACJ,EAAM,QAAQ,EAAE,CAAC,UAAW,EAA2B,SAC1E,IAAa,EAAI,sBAAsB,CAAC,CAAC,OACzC,IAAQ,EAAI,iBAAiB,EAAI,eAAe,EAAI,gBAAgB,EAAI,eAAe,GAEvF,IAAM,MAAW,QAAQ,MAAW,OAAO,KAAK,GAChD,IAAW,EAAI,eAAe,eAAe,sBAAsB,CAAC,CAAC,SAAS;EAEpF,EAAY,EAAI;EAEhB,IAAM,KAAQ,MAAoB;GAChC,IAAM,KAAS,IAAU,KAAU,GAC7B,IAAO,KAAK,MAAM,KAAK,IAAI,GAAU,KAAK,IAAI,GAA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IAChC,MAAK;GACN,GALM,CAKN,CACF,CACC;;CACS,CAAA;AAErB,GAEa,IAAiB,EAAM,OAAO;CACzC,gBAAgB;EACd,OAAO;GACL,GAAG,KAAK,SAAS;GACjB,OAAO;IACL,SAAS;IACT,YAAY,MAAY;KACtB,IAAM,IAAO,EAAQ,aAAa,OAAO;KACzC,IAAI,GAAM,OAAO,SAAS,GAAM,EAAE,KAAK;KACvC,IAAM,IAAQ,EAAQ,MAAM;KAC5B,OAAO,KAAQ,SAAS,GAAO,EAAE,KAAY;IAC/C;IACA,aAAa,MACX,EAAW,QAAQ;KAAE,OAAO,EAAW;KAAO,OAAO,UAAU,EAAW,MAAM;IAAI,IAAI,CAAC;GAC7F;GACA,QAAQ;IACN,SAAS;IACT,YAAY,MAAY;KACtB,IAAM,IAAO,EAAQ,aAAa,QAAQ;KAC1C,OAAO,KAAO,SAAS,GAAM,EAAE,KAAY;IAC7C;IACA,aAAa,MAAgB,EAAW,SAAS,EAAE,QAAQ,EAAW,OAAO,IAAI,CAAC;GACpF;GACA,OAAO;IACL,SAAS;IACT,YAAY,MAAY,EAAQ,aAAa,YAAY,KAAK;IAC9D,aAAa,MAAgB,EAAW,QAAQ,EAAE,cAAc,EAAW,MAAM,IAAI,CAAC;GACxF;EACF;CACF;CACA,cAAc;EACZ,OAAO,EAAsB,CAAsB;CACrD;AACF,CAAC"}
@@ -10,6 +10,7 @@ export { default as ContextMenu } from './ContextMenu';
10
10
  export { MarkdownBlockExtension } from './extensions/MarkdownBlock';
11
11
  export { CodeBlockExtension } from './extensions/CodeBlockView';
12
12
  export { default as FontSizeExtension } from './extensions/FontSize';
13
+ export { ResizableImage } from './extensions/ResizableImage';
13
14
  export { FloatingDialogExtension, getNextFloatZIndex } from './extensions/FloatingDialog';
14
15
  export { CommentMark } from './extensions/CommentMark';
15
16
  export { default as RichTextToolbar } from './Toolbar';