@rytass/wms-map-react-components 0.1.1

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/components/breadcrumb/breadcrumb-edit-modal.d.ts +9 -0
  4. package/components/breadcrumb/breadcrumb-edit-modal.js +92 -0
  5. package/components/breadcrumb/breadcrumb-edit-modal.module.scss.js +3 -0
  6. package/components/breadcrumb/breadcrumb.d.ts +8 -0
  7. package/components/breadcrumb/breadcrumb.js +167 -0
  8. package/components/breadcrumb/breadcrumb.module.scss.js +3 -0
  9. package/components/canvas/react-flow-canvas.d.ts +37 -0
  10. package/components/canvas/react-flow-canvas.js +317 -0
  11. package/components/canvas/react-flow-canvas.module.scss.js +3 -0
  12. package/components/modal/wms-map-content.d.ts +4 -0
  13. package/components/modal/wms-map-content.js +753 -0
  14. package/components/modal/wms-map-header.d.ts +6 -0
  15. package/components/modal/wms-map-header.js +19 -0
  16. package/components/modal/wms-map-header.module.scss.js +3 -0
  17. package/components/modal/wms-map-modal-container.d.ts +4 -0
  18. package/components/modal/wms-map-modal-container.js +95 -0
  19. package/components/modal/wms-map-modal-container.module.scss.js +3 -0
  20. package/components/nodes/base-node.d.ts +12 -0
  21. package/components/nodes/image-node.d.ts +17 -0
  22. package/components/nodes/image-node.js +233 -0
  23. package/components/nodes/image-node.module.scss.js +3 -0
  24. package/components/nodes/path-node.d.ts +19 -0
  25. package/components/nodes/path-node.js +550 -0
  26. package/components/nodes/path-node.module.scss.js +3 -0
  27. package/components/nodes/rectangle-node.d.ts +11 -0
  28. package/components/nodes/rectangle-node.js +236 -0
  29. package/components/nodes/rectangle-node.module.scss.js +3 -0
  30. package/components/ui/context-menu.d.ts +25 -0
  31. package/components/ui/context-menu.js +168 -0
  32. package/components/ui/context-menu.module.scss.js +3 -0
  33. package/components/ui/toolbar.d.ts +23 -0
  34. package/components/ui/toolbar.js +278 -0
  35. package/components/ui/toolbar.module.scss.js +3 -0
  36. package/components/ui/view-mode-toolbar.d.ts +9 -0
  37. package/components/ui/view-mode-toolbar.js +41 -0
  38. package/components/ui/view-mode-toolbar.module.scss.js +3 -0
  39. package/constants/index.d.ts +45 -0
  40. package/constants/index.js +37 -0
  41. package/constants/text-mappings.d.ts +181 -0
  42. package/constants/text-mappings.js +44 -0
  43. package/hooks/use-context-menu.d.ts +37 -0
  44. package/hooks/use-context-menu.js +228 -0
  45. package/hooks/use-direct-state-history.d.ts +58 -0
  46. package/hooks/use-direct-state-history.js +214 -0
  47. package/hooks/use-pen-drawing.d.ts +30 -0
  48. package/hooks/use-pen-drawing.js +363 -0
  49. package/hooks/use-rectangle-drawing.d.ts +19 -0
  50. package/hooks/use-rectangle-drawing.js +136 -0
  51. package/hooks/use-text-editing.d.ts +19 -0
  52. package/hooks/use-text-editing.js +153 -0
  53. package/icons/index.d.ts +15 -0
  54. package/icons/index.js +209 -0
  55. package/index.cjs.css +1 -0
  56. package/index.cjs.js +5033 -0
  57. package/index.css +1 -0
  58. package/index.d.ts +5 -0
  59. package/index.js +4 -0
  60. package/package.json +40 -0
  61. package/types/callback.types.d.ts +7 -0
  62. package/types/canvas.types.d.ts +35 -0
  63. package/types/component-props.types.d.ts +41 -0
  64. package/types/history.types.d.ts +24 -0
  65. package/types/index.d.ts +5 -0
  66. package/types/react-flow.types.d.ts +30 -0
  67. package/typings.d.ts +140 -0
  68. package/typings.js +37 -0
  69. package/utils/api-data-transform.d.ts +33 -0
  70. package/utils/api-data-transform.js +218 -0
  71. package/utils/color-utils.d.ts +17 -0
  72. package/utils/color-utils.js +55 -0
  73. package/utils/debug-logger.d.ts +33 -0
  74. package/utils/debug-logger.js +41 -0
  75. package/utils/map-data-transform.d.ts +18 -0
  76. package/utils/map-data-transform.js +342 -0
  77. package/utils/node-operations.d.ts +26 -0
  78. package/utils/node-operations.js +83 -0
  79. package/utils/node-utils.d.ts +10 -0
  80. package/utils/node-utils.js +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Rytass Co. Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @rytass/wms-map-react-components
2
+
3
+ WMS (Warehouse Management System) Map React Components for interactive warehouse space editing.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @rytass/wms-map-react-components
9
+ ```
10
+
11
+ ## Peer Dependencies
12
+
13
+ ```bash
14
+ npm install @mezzanine-ui/react @xyflow/react react react-dom
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```tsx
20
+ import React, { useState } from 'react';
21
+ import WmsMapModal from '@rytass/wms-map-react-components';
22
+ import { ViewMode } from '@rytass/wms-map-react-components/typings';
23
+
24
+ const App = () => {
25
+ const [isOpen, setIsOpen] = useState(false);
26
+
27
+ return (
28
+ <div>
29
+ <button onClick={() => setIsOpen(true)}>Open Map Editor</button>
30
+
31
+ <WmsMapModal
32
+ open={isOpen}
33
+ onClose={() => setIsOpen(false)}
34
+ viewMode={ViewMode.EDIT}
35
+ onSave={mapData => {
36
+ console.log('Saved map data:', mapData);
37
+ }}
38
+ onNodeClick={nodeInfo => {
39
+ console.log('Node clicked:', nodeInfo);
40
+ }}
41
+ />
42
+ </div>
43
+ );
44
+ };
45
+
46
+ export default App;
47
+ ```
48
+
49
+ ## Props
50
+
51
+ | Prop | Type | Default | Description |
52
+ | --------------------- | --------------------------------------------------------------- | ---------------- | ------------------------------------ |
53
+ | `open` | `boolean` | - | Controls modal visibility |
54
+ | `onClose` | `() => void` | - | Called when modal should close |
55
+ | `viewMode` | `ViewMode` | `ViewMode.EDIT` | Initial view mode (EDIT/VIEW) |
56
+ | `colorPalette` | `string[]` | - | Available colors for drawing tools |
57
+ | `onNodeClick` | `(nodeInfo: WmsNodeClickInfo) => void` | - | Called when a node is clicked |
58
+ | `onSave` | `(mapData: Map) => void` | - | Called when save button is clicked |
59
+ | `onBreadcrumbClick` | `(warehouseId: string, index: number) => void` | - | Called when breadcrumb is clicked |
60
+ | `onWarehouseNameEdit` | `(warehouseId: string, newName: string, index: number) => void` | - | Called when warehouse name is edited |
61
+ | `initialNodes` | `any[]` | `[]` | Initial nodes for the canvas |
62
+ | `initialEdges` | `any[]` | `[]` | Initial edges for the canvas |
63
+ | `debugMode` | `boolean` | `false` | Enable debug logging |
64
+ | `title` | `string` | `'編輯倉儲空間'` | Modal title |
65
+
66
+ ## Features
67
+
68
+ - **Interactive Canvas**: Built with ReactFlow for smooth interactions
69
+ - **Drawing Tools**: Rectangle and pen tools for creating warehouse areas
70
+ - **Background Images**: Upload and manage warehouse floor plans
71
+ - **Layer Management**: Separate background and layer editing modes
72
+ - **History System**: Complete undo/redo functionality
73
+ - **Export**: Transform canvas data to structured warehouse map format
74
+
75
+ ## License
76
+
77
+ MIT
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ interface BreadcrumbEditModalProps {
3
+ open: boolean;
4
+ warehouseId: string;
5
+ onClose: () => void;
6
+ onConfirm: (newName: string) => void;
7
+ }
8
+ declare const BreadcrumbEditModal: FC<BreadcrumbEditModalProps>;
9
+ export default BreadcrumbEditModal;
@@ -0,0 +1,92 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useState, useEffect } from 'react';
3
+ import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from '@mezzanine-ui/react';
4
+ import styles from './breadcrumb-edit-modal.module.scss.js';
5
+ import { useForm } from 'react-hook-form';
6
+
7
+ const BreadcrumbEditModal = ({ open, warehouseId, onClose, onConfirm })=>{
8
+ const [editingValue, setEditingValue] = useState(warehouseId);
9
+ const methods = useForm({
10
+ mode: 'onChange',
11
+ defaultValues: {
12
+ editingValue: warehouseId
13
+ }
14
+ });
15
+ // 當 modal 開啟時更新編輯值
16
+ useEffect(()=>{
17
+ if (open) {
18
+ setEditingValue(warehouseId);
19
+ methods.reset({
20
+ editingValue: warehouseId
21
+ });
22
+ }
23
+ }, [
24
+ open,
25
+ warehouseId,
26
+ methods
27
+ ]);
28
+ const handleConfirm = ()=>{
29
+ const formData = methods.getValues();
30
+ const newValue = formData.editingValue?.trim() || editingValue?.trim();
31
+ onConfirm(newValue);
32
+ onClose();
33
+ };
34
+ const handleCancel = ()=>{
35
+ setEditingValue(warehouseId); // 重置為原始值
36
+ onClose();
37
+ };
38
+ return /*#__PURE__*/ jsxs(Modal, {
39
+ open: open,
40
+ onClose: handleCancel,
41
+ children: [
42
+ /*#__PURE__*/ jsx(ModalHeader, {
43
+ children: "修改當前區域名稱"
44
+ }),
45
+ /*#__PURE__*/ jsx(ModalBody, {
46
+ children: /*#__PURE__*/ jsxs("div", {
47
+ className: styles.modalContent,
48
+ children: [
49
+ /*#__PURE__*/ jsx("label", {
50
+ className: styles.fieldLabel,
51
+ children: "名稱"
52
+ }),
53
+ /*#__PURE__*/ jsx("input", {
54
+ ...methods.register('editingValue', {
55
+ required: true
56
+ }),
57
+ type: "text",
58
+ placeholder: "請輸入區域名稱",
59
+ style: {
60
+ width: '100%',
61
+ padding: '8px',
62
+ border: '1px solid #ccc',
63
+ borderRadius: '4px',
64
+ fontSize: '14px'
65
+ }
66
+ })
67
+ ]
68
+ })
69
+ }),
70
+ /*#__PURE__*/ jsxs(ModalFooter, {
71
+ className: styles.modalFooter,
72
+ children: [
73
+ /*#__PURE__*/ jsx(Button, {
74
+ size: "large",
75
+ variant: "outlined",
76
+ onClick: handleCancel,
77
+ children: "取消"
78
+ }),
79
+ /*#__PURE__*/ jsx(Button, {
80
+ size: "large",
81
+ variant: "contained",
82
+ color: "primary",
83
+ onClick: handleConfirm,
84
+ children: "確認"
85
+ })
86
+ ]
87
+ })
88
+ ]
89
+ });
90
+ };
91
+
92
+ export { BreadcrumbEditModal as default };
@@ -0,0 +1,3 @@
1
+ var styles = {"modalContent":"breadcrumb-edit-modal-module_modalContent__WOycg","fieldLabel":"breadcrumb-edit-modal-module_fieldLabel__Qdy7y","modalFooter":"breadcrumb-edit-modal-module_modalFooter__Bp6Dg"};
2
+
3
+ export { styles as default };
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ interface BreadcrumbProps {
3
+ warehouseIds: string[];
4
+ onWarehouseClick?: (warehouseId: string, index: number) => void;
5
+ onNameChange?: (name: string) => Promise<void>;
6
+ }
7
+ declare const Breadcrumb: FC<BreadcrumbProps>;
8
+ export default Breadcrumb;
@@ -0,0 +1,167 @@
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import React, { useState, useRef, useEffect } from 'react';
3
+ import BreadcrumbEditModal from './breadcrumb-edit-modal.js';
4
+ import styles from './breadcrumb.module.scss.js';
5
+
6
+ const Breadcrumb = ({ warehouseIds, onWarehouseClick, onNameChange })=>{
7
+ const [showDropdown, setShowDropdown] = useState(false);
8
+ const [showEditModal, setShowEditModal] = useState(false);
9
+ const [editingIndex, setEditingIndex] = useState(-1);
10
+ const dropdownRef = useRef(null);
11
+ // 當超過3個項目時,需要收合顯示
12
+ const shouldCollapse = warehouseIds.length > 3;
13
+ // 點擊外部關閉 dropdown
14
+ useEffect(()=>{
15
+ const handleClickOutside = (event)=>{
16
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
17
+ setShowDropdown(false);
18
+ }
19
+ };
20
+ if (showDropdown) {
21
+ document.addEventListener('mousedown', handleClickOutside);
22
+ }
23
+ return ()=>{
24
+ document.removeEventListener('mousedown', handleClickOutside);
25
+ };
26
+ }, [
27
+ showDropdown
28
+ ]);
29
+ const handleEditClick = ()=>{
30
+ // 預設編輯最後一個項目
31
+ const lastIndex = warehouseIds.length - 1;
32
+ setEditingIndex(lastIndex);
33
+ setShowEditModal(true);
34
+ };
35
+ const handleEditConfirm = async (newName)=>{
36
+ if (onNameChange) {
37
+ await onNameChange(newName);
38
+ }
39
+ setShowEditModal(false);
40
+ setEditingIndex(-1);
41
+ };
42
+ const handleEditCancel = ()=>{
43
+ setShowEditModal(false);
44
+ setEditingIndex(-1);
45
+ };
46
+ const renderCollapsedBreadcrumb = ()=>{
47
+ const first = warehouseIds[0];
48
+ const secondLast = warehouseIds[warehouseIds.length - 2];
49
+ const last = warehouseIds[warehouseIds.length - 1];
50
+ const hiddenItems = warehouseIds.slice(1, warehouseIds.length - 2);
51
+ const handleItemClick = (warehouseId, index)=>{
52
+ onWarehouseClick?.(warehouseId, index);
53
+ };
54
+ return /*#__PURE__*/ jsxs(Fragment, {
55
+ children: [
56
+ /*#__PURE__*/ jsx("span", {
57
+ className: `${styles.warehouseIdText} ${styles.clickable}`,
58
+ onClick: ()=>handleItemClick(first, 0),
59
+ children: first
60
+ }),
61
+ /*#__PURE__*/ jsx("span", {
62
+ className: styles.separator,
63
+ children: "/"
64
+ }),
65
+ /*#__PURE__*/ jsxs("div", {
66
+ className: styles.ellipsisContainer,
67
+ ref: dropdownRef,
68
+ children: [
69
+ /*#__PURE__*/ jsx("span", {
70
+ className: styles.ellipsis,
71
+ onClick: ()=>setShowDropdown(!showDropdown),
72
+ children: "..."
73
+ }),
74
+ showDropdown && hiddenItems.length > 0 && /*#__PURE__*/ jsx("div", {
75
+ className: styles.dropdown,
76
+ children: hiddenItems.map((id, index)=>/*#__PURE__*/ jsx("div", {
77
+ className: styles.dropdownItem,
78
+ onClick: (e)=>{
79
+ e.preventDefault();
80
+ e.stopPropagation();
81
+ handleItemClick(id, index + 1);
82
+ setShowDropdown(false); // 點擊後隱藏 dropdown
83
+ },
84
+ children: id
85
+ }, index))
86
+ })
87
+ ]
88
+ }),
89
+ /*#__PURE__*/ jsx("span", {
90
+ className: styles.separator,
91
+ children: "/"
92
+ }),
93
+ /*#__PURE__*/ jsx("span", {
94
+ className: `${styles.warehouseIdText} ${styles.clickable}`,
95
+ onClick: ()=>handleItemClick(secondLast, warehouseIds.length - 2),
96
+ children: secondLast
97
+ }),
98
+ /*#__PURE__*/ jsx("span", {
99
+ className: styles.separator,
100
+ children: "/"
101
+ }),
102
+ /*#__PURE__*/ jsx("span", {
103
+ className: `${styles.warehouseIdText} ${styles.lastItem} ${styles.clickable}`,
104
+ onClick: ()=>handleItemClick(last, warehouseIds.length - 1),
105
+ children: last
106
+ })
107
+ ]
108
+ });
109
+ };
110
+ const renderFullBreadcrumb = ()=>{
111
+ const handleItemClick = (warehouseId, index)=>{
112
+ onWarehouseClick?.(warehouseId, index);
113
+ };
114
+ return warehouseIds.map((id, index)=>/*#__PURE__*/ jsxs(React.Fragment, {
115
+ children: [
116
+ /*#__PURE__*/ jsx("span", {
117
+ className: `${styles.warehouseIdText} ${styles.clickable} ${index === warehouseIds.length - 1 ? styles.lastItem : ''}`,
118
+ onClick: ()=>handleItemClick(id, index),
119
+ children: id
120
+ }),
121
+ index < warehouseIds.length - 1 && /*#__PURE__*/ jsx("span", {
122
+ className: styles.separator,
123
+ children: "/"
124
+ })
125
+ ]
126
+ }, index));
127
+ };
128
+ return /*#__PURE__*/ jsxs(Fragment, {
129
+ children: [
130
+ /*#__PURE__*/ jsx("div", {
131
+ className: styles.breadcrumbSection,
132
+ children: /*#__PURE__*/ jsxs("div", {
133
+ className: styles.warehouseIdSection,
134
+ children: [
135
+ shouldCollapse ? renderCollapsedBreadcrumb() : renderFullBreadcrumb(),
136
+ /*#__PURE__*/ jsx("button", {
137
+ className: styles.editButton,
138
+ onClick: handleEditClick,
139
+ title: "編輯當前區域名稱",
140
+ children: /*#__PURE__*/ jsx("svg", {
141
+ width: "16",
142
+ height: "16",
143
+ viewBox: "0 0 16 16",
144
+ fill: "none",
145
+ children: /*#__PURE__*/ jsx("path", {
146
+ d: "M11.7803 2.21967C12.0732 1.92678 12.5481 1.92678 12.841 2.21967L13.7803 3.15901C14.0732 3.45191 14.0732 3.92678 13.7803 4.21967L5.11364 12.8863L2.66697 13.3333L3.11364 10.8863L11.7803 2.21967Z",
147
+ stroke: "currentColor",
148
+ strokeWidth: "1.33",
149
+ strokeLinecap: "round",
150
+ strokeLinejoin: "round"
151
+ })
152
+ })
153
+ })
154
+ ]
155
+ })
156
+ }),
157
+ /*#__PURE__*/ jsx(BreadcrumbEditModal, {
158
+ open: showEditModal,
159
+ warehouseId: editingIndex >= 0 ? warehouseIds[editingIndex] : '',
160
+ onClose: handleEditCancel,
161
+ onConfirm: handleEditConfirm
162
+ })
163
+ ]
164
+ });
165
+ };
166
+
167
+ export { Breadcrumb as default };
@@ -0,0 +1,3 @@
1
+ var styles = {"breadcrumbSection":"breadcrumb-module_breadcrumbSection__Qn8A3","warehouseIdSection":"breadcrumb-module_warehouseIdSection__7CzsY","separator":"breadcrumb-module_separator__uLhtn","warehouseIdText":"breadcrumb-module_warehouseIdText__QOxRw","lastItem":"breadcrumb-module_lastItem__OGKzD","clickable":"breadcrumb-module_clickable__YD5aj","ellipsisContainer":"breadcrumb-module_ellipsisContainer__4hIiu","ellipsis":"breadcrumb-module_ellipsis__NYd8X","dropdown":"breadcrumb-module_dropdown__BqvP8","dropdownItem":"breadcrumb-module_dropdownItem__YdggW","editButton":"breadcrumb-module_editButton__Wuk8T"};
2
+
3
+ export { styles as default };
@@ -0,0 +1,37 @@
1
+ import React, { FC } from 'react';
2
+ import { Connection, Edge, EdgeChange, Node as ReactFlowNode, NodeChange, OnSelectionChangeParams } from '@xyflow/react';
3
+ import { DrawingMode, EditMode, ViewMode } from '../../typings';
4
+ interface ReactFlowCanvasProps {
5
+ nodes: ReactFlowNode[];
6
+ edges: Edge[];
7
+ onNodesChange: (changes: NodeChange[]) => void;
8
+ onEdgesChange: (changes: EdgeChange[]) => void;
9
+ onConnect: (connection: Connection) => void;
10
+ editMode: EditMode;
11
+ drawingMode: DrawingMode;
12
+ viewMode: ViewMode;
13
+ selectedColor?: string;
14
+ onCreateRectangle: (startX: number, startY: number, endX: number, endY: number) => void;
15
+ onCreatePath: (points: {
16
+ x: number;
17
+ y: number;
18
+ }[]) => void;
19
+ onSelectionChange?: (params: OnSelectionChangeParams) => void;
20
+ onTextEditComplete?: (id: string, oldText: string, newText: string) => void;
21
+ onPathPointsChange?: (id: string, oldPoints: {
22
+ x: number;
23
+ y: number;
24
+ }[], newPoints: {
25
+ x: number;
26
+ y: number;
27
+ }[]) => void;
28
+ onPathPointDragStateChange?: (isDragging: boolean) => void;
29
+ isEditingPathPoints?: boolean;
30
+ hoveredNodeId?: string | null;
31
+ onNodeMouseEnter?: (event: React.MouseEvent, node: ReactFlowNode) => void;
32
+ onNodeMouseLeave?: (event: React.MouseEvent, node: ReactFlowNode) => void;
33
+ onNodeClick?: (event: React.MouseEvent, node: ReactFlowNode) => void;
34
+ showBackground?: boolean;
35
+ }
36
+ declare const ReactFlowCanvas: FC<ReactFlowCanvasProps>;
37
+ export default ReactFlowCanvas;