ソースを参照

Fix ActionButton bug

main
Steve Ruiz 3年前
コミット
72b6fafcc1
2個のファイルの変更171行の追加24行の削除
  1. 147
    0
      packages/tldraw/README.md
  2. 24
    24
      packages/tldraw/src/components/ToolsPanel/ActionButton.tsx

+ 147
- 0
packages/tldraw/README.md ファイルの表示

@@ -0,0 +1,147 @@
1
+# @tldraw/tldraw
2
+
3
+> `This library is not yet released and these docs are partially out of date!`
4
+
5
+This package contains the [tldraw](https://tldraw.com) editor as a standalone React component.
6
+
7
+## Installation
8
+
9
+```bash
10
+npm i @tldraw/tldraw
11
+```
12
+
13
+or
14
+
15
+```bash
16
+yarn add @tldraw/tldraw
17
+```
18
+
19
+## Usage
20
+
21
+Import the `TLDraw` React component and use it in your app.
22
+
23
+```tsx
24
+import { TLDraw } from '@tldraw/tldraw'
25
+
26
+function App() {
27
+  return <TLDraw />
28
+}
29
+```
30
+
31
+## Documentation
32
+
33
+### `TLDraw`
34
+
35
+The `TLDraw` React component is the [tldraw](https://tldraw.com) editor exported as a standalone component. You can control the editor through props, or through the `TLDrawState`'s imperative API.
36
+
37
+| Prop            | Type                            | Description                                                                                                                                                             |
38
+| --------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39
+| `id`            | `string`                        | (optional) An id under which to persist the component's state.                                                                                                          |
40
+| `document`      | `TLDrawDocument`                | (optional) An initial [`TLDrawDocument`](#tldrawdocument) object.                                                                                                       |
41
+| `currentPageId` | `string`                        | (optional) A current page id, referencing the `TLDrawDocument` object provided via the `document` prop.                                                                 |
42
+| `onMount`       | `(TLDrawState) => void`         | (optional) A callback function that will be called when the editor first mounts, receiving the current `TLDrawState`.                                                   |
43
+| `onChange`      | `(TLDrawState, string) => void` | (optional) A callback function that will be called whenever the `TLDrawState` updates. The update will include the current `TLDrawState` and the reason for the change. |
44
+
45
+### `TLDrawDocument`
46
+
47
+A `TLDrawDocument` is an object with three properties:
48
+
49
+- `id` - A unique ID for this document
50
+- `pages` - A table of `TLPage` objects
51
+- `pageStates` - A table of `TLPageState` objects
52
+
53
+```ts
54
+const tldocument: TLDrawDocument = {
55
+  id: 'doc',
56
+  pages: {
57
+    page1: {
58
+      id: 'page1',
59
+      shapes: {},
60
+      bindings: {},
61
+    },
62
+  },
63
+  pageStates: {
64
+    page1: {
65
+      id: 'page1',
66
+      selectedIds: [],
67
+      currentParentId: 'page1',
68
+      camera: {
69
+        point: [0, 0],
70
+        zoom: 1,
71
+      },
72
+    },
73
+  },
74
+}
75
+```
76
+
77
+**Important:** In the `pages` object, each `TLPage` object must be keyed under its `id` property. Likewise, each `TLPageState` object must be keyed under its `id`. In addition, each `TLPageState` object must have an `id` that matches its corresponding page.
78
+
79
+In the example above, the page above with the id `page1`is at `tldocument.pages["page1"]`. Its corresponding page state has the same id (`page1`) and is at `tldocument.pageStates["page1"]`.
80
+
81
+### Shapes
82
+
83
+Your `TLPage` objects may include shapes: objects that fit one of the `TLDrawShape` interfaces listed below. All `TLDrawShapes` extends a common interface:
84
+
85
+| Property              | Type         | Description                                                     |
86
+| --------------------- | ------------ | --------------------------------------------------------------- |
87
+| `id`                  | `string`     | A unique ID for the shape.                                      |
88
+| `name`                | `string`     | The shape's name.                                               |
89
+| `type`                | `string`     | The shape's type.                                               |
90
+| `parentId`            | `string`     | The ID of the shape's parent (a shape or its page).             |
91
+| `childIndex`          | `number`     | The shape's order within its parent's children, indexed from 1. |
92
+| `point`               | `number[]`   | The `[x, y]` position of the shape.                             |
93
+| `rotation`            | `number[]`   | (optional) The shape's rotation in radians.                     |
94
+| `children`            | `string[]`   | (optional) The shape's child shape ids.                         |
95
+| `handles`             | `TLHandle{}` | (optional) A table of `TLHandle` objects.                       |
96
+| `isLocked`            | `boolean`    | True if the shape is locked.                                    |
97
+| `isHidden`            | `boolean`    | True if the shape is hidden.                                    |
98
+| `isEditing`           | `boolean`    | True if the shape is currently editing.                         |
99
+| `isGenerated`         | `boolean`    | True if the shape is generated.                                 |
100
+| `isAspectRatioLocked` | `boolean`    | True if the shape's aspect ratio is locked.                     |
101
+
102
+> **Important:** In order for re-ordering to work correctly, a shape's `childIndex` values _must_ start from 1, not 0. The page or parent shape's "bottom-most" child should have a `childIndex` of 1.
103
+
104
+The `ShapeStyle` object is a common style API for all shapes.
105
+
106
+| Property   | Type         | Description                             |
107
+| ---------- | ------------ | --------------------------------------- |
108
+| `size`     | `SizeStyle`  | The size of the shape's stroke.         |
109
+| `dash`     | `DashStyle`  | The style of the shape's stroke.        |
110
+| `color`    | `ColorStyle` | The shape's color.                      |
111
+| `isFilled` | `boolean`    | (optional) True if the shape is filled. |
112
+
113
+#### Draw
114
+
115
+| Property | Type         | Description                               |
116
+| -------- | ------------ | ----------------------------------------- |
117
+| `points` | `number[][]` | An array of points as `[x, y, pressure]`. |
118
+
119
+##### Rectangle
120
+
121
+| Property | Type       | Description                             |
122
+| -------- | ---------- | --------------------------------------- |
123
+| `size`   | `number[]` | The `[width, height]` of the rectangle. |
124
+
125
+#### Ellipse
126
+
127
+| Property | Type       | Description                         |
128
+| -------- | ---------- | ----------------------------------- |
129
+| `radius` | `number[]` | The `[x, y]` radius of the ellipse. |
130
+
131
+#### Arrow
132
+
133
+| Property  | Type     | Description                                                             |
134
+| --------- | -------- | ----------------------------------------------------------------------- |
135
+| `handles` | `object` | An object with three `TLHandle` properties: `start`, `end`, and `bend`. |
136
+
137
+#### Text
138
+
139
+| Property | Type     | Description               |
140
+| -------- | -------- | ------------------------- |
141
+| `text`   | `string` | The shape's text content. |
142
+
143
+## Development
144
+
145
+### Running unit tests
146
+
147
+Run `nx test tldraw` to execute the unit tests via [Jest](https://jestjs.io).

+ 24
- 24
packages/tldraw/src/components/ToolsPanel/ActionButton.tsx ファイルの表示

@@ -62,12 +62,12 @@ const isAllGroupedSelector = (s: Data) => {
62 62
   )
63 63
 }
64 64
 
65
-const hasSelectionSelector = (s: Data) => {
65
+const hasSelectionClickor = (s: Data) => {
66 66
   const { selectedIds } = s.document.pageStates[s.appState.currentPageId]
67 67
   return selectedIds.length > 0
68 68
 }
69 69
 
70
-const hasMultipleSelectionSelector = (s: Data) => {
70
+const hasMultipleSelectionClickor = (s: Data) => {
71 71
   const { selectedIds } = s.document.pageStates[s.appState.currentPageId]
72 72
   return selectedIds.length > 1
73 73
 }
@@ -81,9 +81,9 @@ export function ActionButton(): JSX.Element {
81 81
 
82 82
   const isAllGrouped = useSelector(isAllGroupedSelector)
83 83
 
84
-  const hasSelection = useSelector(hasSelectionSelector)
84
+  const hasSelection = useSelector(hasSelectionClickor)
85 85
 
86
-  const hasMultipleSelection = useSelector(hasMultipleSelectionSelector)
86
+  const hasMultipleSelection = useSelector(hasMultipleSelectionClickor)
87 87
 
88 88
   const handleRotate = React.useCallback(() => {
89 89
     tlstate.rotate()
@@ -180,55 +180,55 @@ export function ActionButton(): JSX.Element {
180 180
       <DMContent>
181 181
         <>
182 182
           <ButtonsRow>
183
-            <IconButton disabled={!hasSelection} onSelect={handleDuplicate}>
183
+            <IconButton disabled={!hasSelection} onClick={handleDuplicate}>
184 184
               <Tooltip label="Duplicate" kbd={`#D`}>
185 185
                 <CopyIcon />
186 186
               </Tooltip>
187 187
             </IconButton>
188
-            <IconButton disabled={!hasSelection} onSelect={handleRotate}>
188
+            <IconButton disabled={!hasSelection} onClick={handleRotate}>
189 189
               <Tooltip label="Rotate">
190 190
                 <RotateCounterClockwiseIcon />
191 191
               </Tooltip>
192 192
             </IconButton>
193
-            <IconButton disabled={!hasSelection} onSelect={handleToggleLocked}>
193
+            <IconButton disabled={!hasSelection} onClick={handleToggleLocked}>
194 194
               <Tooltip label="Toogle Locked" kbd={`#L`}>
195 195
                 {isAllLocked ? <LockClosedIcon /> : <LockOpen1Icon opacity={0.4} />}
196 196
               </Tooltip>
197 197
             </IconButton>
198
-            <IconButton disabled={!hasSelection} onSelect={handleToggleAspectRatio}>
198
+            <IconButton disabled={!hasSelection} onClick={handleToggleAspectRatio}>
199 199
               <Tooltip label="Toogle Aspect Ratio Lock">
200 200
                 <AspectRatioIcon opacity={isAllAspectLocked ? 1 : 0.4} />
201 201
               </Tooltip>
202 202
             </IconButton>
203
-            <IconButton disabled={!isAllGrouped && !hasMultipleSelection} onSelect={handleGroup}>
203
+            <IconButton disabled={!isAllGrouped && !hasMultipleSelection} onClick={handleGroup}>
204 204
               <Tooltip label="Group" kbd={`#G`}>
205 205
                 <GroupIcon opacity={isAllGrouped ? 1 : 0.4} />
206 206
               </Tooltip>
207 207
             </IconButton>
208 208
           </ButtonsRow>
209 209
           <ButtonsRow>
210
-            <IconButton disabled={!hasSelection} onSelect={handleMoveToBack}>
210
+            <IconButton disabled={!hasSelection} onClick={handleMoveToBack}>
211 211
               <Tooltip label="Move to Back" kbd={`#⇧[`}>
212 212
                 <PinBottomIcon />
213 213
               </Tooltip>
214 214
             </IconButton>
215 215
 
216
-            <IconButton disabled={!hasSelection} onSelect={handleMoveBackward}>
216
+            <IconButton disabled={!hasSelection} onClick={handleMoveBackward}>
217 217
               <Tooltip label="Move Backward" kbd={`#[`}>
218 218
                 <ArrowDownIcon />
219 219
               </Tooltip>
220 220
             </IconButton>
221
-            <IconButton disabled={!hasSelection} onSelect={handleMoveForward}>
221
+            <IconButton disabled={!hasSelection} onClick={handleMoveForward}>
222 222
               <Tooltip label="Move Forward" kbd={`#]`}>
223 223
                 <ArrowUpIcon />
224 224
               </Tooltip>
225 225
             </IconButton>
226
-            <IconButton disabled={!hasSelection} onSelect={handleMoveToFront}>
226
+            <IconButton disabled={!hasSelection} onClick={handleMoveToFront}>
227 227
               <Tooltip label="More to Front" kbd={`#⇧]`}>
228 228
                 <PinTopIcon />
229 229
               </Tooltip>
230 230
             </IconButton>
231
-            <IconButton disabled={!hasSelection} onSelect={handleDelete}>
231
+            <IconButton disabled={!hasSelection} onClick={handleDelete}>
232 232
               <Tooltip label="Delete" kbd="⌫">
233 233
                 <TrashIcon />
234 234
               </Tooltip>
@@ -236,36 +236,36 @@ export function ActionButton(): JSX.Element {
236 236
           </ButtonsRow>
237 237
           <Divider />
238 238
           <ButtonsRow>
239
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignLeft}>
239
+            <IconButton disabled={!hasTwoOrMore} onClick={alignLeft}>
240 240
               <AlignLeftIcon />
241 241
             </IconButton>
242
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignCenterHorizontal}>
242
+            <IconButton disabled={!hasTwoOrMore} onClick={alignCenterHorizontal}>
243 243
               <AlignCenterHorizontallyIcon />
244 244
             </IconButton>
245
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignRight}>
245
+            <IconButton disabled={!hasTwoOrMore} onClick={alignRight}>
246 246
               <AlignRightIcon />
247 247
             </IconButton>
248
-            <IconButton disabled={!hasTwoOrMore} onSelect={stretchHorizontally}>
248
+            <IconButton disabled={!hasTwoOrMore} onClick={stretchHorizontally}>
249 249
               <StretchHorizontallyIcon />
250 250
             </IconButton>
251
-            <IconButton disabled={!hasThreeOrMore} onSelect={distributeHorizontally}>
251
+            <IconButton disabled={!hasThreeOrMore} onClick={distributeHorizontally}>
252 252
               <SpaceEvenlyHorizontallyIcon />
253 253
             </IconButton>
254 254
           </ButtonsRow>
255 255
           <ButtonsRow>
256
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignTop}>
256
+            <IconButton disabled={!hasTwoOrMore} onClick={alignTop}>
257 257
               <AlignTopIcon />
258 258
             </IconButton>
259
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignCenterVertical}>
259
+            <IconButton disabled={!hasTwoOrMore} onClick={alignCenterVertical}>
260 260
               <AlignCenterVerticallyIcon />
261 261
             </IconButton>
262
-            <IconButton disabled={!hasTwoOrMore} onSelect={alignBottom}>
262
+            <IconButton disabled={!hasTwoOrMore} onClick={alignBottom}>
263 263
               <AlignBottomIcon />
264 264
             </IconButton>
265
-            <IconButton disabled={!hasTwoOrMore} onSelect={stretchVertically}>
265
+            <IconButton disabled={!hasTwoOrMore} onClick={stretchVertically}>
266 266
               <StretchVerticallyIcon />
267 267
             </IconButton>
268
-            <IconButton disabled={!hasThreeOrMore} onSelect={distributeVertically}>
268
+            <IconButton disabled={!hasThreeOrMore} onClick={distributeVertically}>
269 269
               <SpaceEvenlyVerticallyIcon />
270 270
             </IconButton>
271 271
           </ButtonsRow>

読み込み中…
キャンセル
保存