@cloudscape-design/components-themeable 3.0.976 → 3.0.978
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/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/drawer/styles.scss +1 -1
- package/lib/internal/scss/internal/components/selectable-item/styles.scss +21 -8
- package/lib/internal/template/alert/index.js +3 -3
- package/lib/internal/template/alert/index.js.map +1 -1
- package/lib/internal/template/alert/interfaces.d.ts +10 -0
- package/lib/internal/template/alert/interfaces.d.ts.map +1 -1
- package/lib/internal/template/alert/interfaces.js.map +1 -1
- package/lib/internal/template/drawer/styles.css.js +6 -6
- package/lib/internal/template/drawer/styles.scoped.css +12 -12
- package/lib/internal/template/drawer/styles.selectors.js +6 -6
- package/lib/internal/template/flashbar/flash.js +3 -5
- package/lib/internal/template/flashbar/flash.js.map +1 -1
- package/lib/internal/template/flashbar/interfaces.d.ts +2 -0
- package/lib/internal/template/flashbar/interfaces.d.ts.map +1 -1
- package/lib/internal/template/flashbar/interfaces.js.map +1 -1
- package/lib/internal/template/form/index.js +1 -1
- package/lib/internal/template/form/index.js.map +1 -1
- package/lib/internal/template/form/interfaces.d.ts +3 -1
- package/lib/internal/template/form/interfaces.d.ts.map +1 -1
- package/lib/internal/template/form/interfaces.js.map +1 -1
- package/lib/internal/template/form-field/index.d.ts.map +1 -1
- package/lib/internal/template/form-field/index.js +1 -0
- package/lib/internal/template/form-field/index.js.map +1 -1
- package/lib/internal/template/form-field/interfaces.d.ts +3 -1
- package/lib/internal/template/form-field/interfaces.d.ts.map +1 -1
- package/lib/internal/template/form-field/interfaces.js.map +1 -1
- package/lib/internal/template/form-field/internal.d.ts.map +1 -1
- package/lib/internal/template/form-field/internal.js +2 -3
- package/lib/internal/template/form-field/internal.js.map +1 -1
- package/lib/internal/template/internal/analytics/hooks/use-funnel.d.ts +1 -1
- package/lib/internal/template/internal/analytics/interfaces.d.ts +12 -5
- package/lib/internal/template/internal/analytics/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/drag-handle/hooks/interfaces.d.ts +66 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/interfaces.d.ts.map +1 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/interfaces.js +4 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/interfaces.js.map +1 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/use-drag-handle-interaction-state.d.ts +35 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/use-drag-handle-interaction-state.d.ts.map +1 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/use-drag-handle-interaction-state.js +259 -0
- package/lib/internal/template/internal/components/drag-handle/hooks/use-drag-handle-interaction-state.js.map +1 -0
- package/lib/internal/template/internal/components/drag-handle/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/drag-handle/index.js +2 -2
- package/lib/internal/template/internal/components/drag-handle/index.js.map +1 -1
- package/lib/internal/template/internal/components/drag-handle/interfaces.d.ts +1 -0
- package/lib/internal/template/internal/components/drag-handle/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/components/drag-handle/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/index.d.ts +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/index.js +4 -4
- package/lib/internal/template/internal/components/drag-handle-wrapper/index.js.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/interfaces.d.ts +1 -0
- package/lib/internal/template/internal/components/drag-handle-wrapper/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/portal-overlay.d.ts +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/portal-overlay.d.ts.map +1 -1
- package/lib/internal/template/internal/components/drag-handle-wrapper/portal-overlay.js +3 -3
- package/lib/internal/template/internal/components/drag-handle-wrapper/portal-overlay.js.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/styles.css.js +21 -21
- package/lib/internal/template/internal/components/selectable-item/styles.scoped.css +56 -43
- package/lib/internal/template/internal/components/selectable-item/styles.selectors.js +21 -21
- package/lib/internal/template/internal/do-not-use/drag-handle.d.ts +5 -0
- package/lib/internal/template/internal/do-not-use/drag-handle.d.ts.map +1 -0
- package/lib/internal/template/internal/do-not-use/drag-handle.js +6 -0
- package/lib/internal/template/internal/do-not-use/drag-handle.js.map +1 -0
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/internal/environment.json +1 -1
- package/lib/internal/template/package.json +1 -0
- package/lib/internal/template/table/index.d.ts.map +1 -1
- package/lib/internal/template/table/index.js +1 -0
- package/lib/internal/template/table/index.js.map +1 -1
- package/lib/internal/template/table/interfaces.d.ts +3 -0
- package/lib/internal/template/table/interfaces.d.ts.map +1 -1
- package/lib/internal/template/table/interfaces.js.map +1 -1
- package/lib/internal/template/table/internal.d.ts.map +1 -1
- package/lib/internal/template/table/internal.js +3 -2
- package/lib/internal/template/table/internal.js.map +1 -1
- package/lib/internal/template/wizard/interfaces.d.ts +3 -1
- package/lib/internal/template/wizard/interfaces.d.ts.map +1 -1
- package/lib/internal/template/wizard/interfaces.js.map +1 -1
- package/lib/internal/template/wizard/wizard-form.d.ts.map +1 -1
- package/lib/internal/template/wizard/wizard-form.js +2 -2
- package/lib/internal/template/wizard/wizard-form.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { useEffect, useReducer, useRef } from 'react';
|
|
4
|
+
export function calculateNextState(state, action) {
|
|
5
|
+
switch (action.type) {
|
|
6
|
+
case 'POINTER_DOWN': {
|
|
7
|
+
const { nativeEvent, metadata } = action.payload;
|
|
8
|
+
return {
|
|
9
|
+
value: 'dnd-start',
|
|
10
|
+
eventData: nativeEvent,
|
|
11
|
+
metadata,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
case 'POINTER_MOVE': {
|
|
15
|
+
const { nativeEvent } = action.payload;
|
|
16
|
+
if (state.value === 'dnd-start' || state.value === 'dnd-active') {
|
|
17
|
+
return Object.assign(Object.assign({}, state), { value: 'dnd-active', eventData: nativeEvent });
|
|
18
|
+
}
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
case 'POINTER_UP': {
|
|
22
|
+
if (state.value === 'dnd-start' || state.value === 'dnd-active') {
|
|
23
|
+
const dndSubStateBeforeUp = state.value;
|
|
24
|
+
if (dndSubStateBeforeUp === 'dnd-start') {
|
|
25
|
+
return {
|
|
26
|
+
value: 'uap-action-start',
|
|
27
|
+
metadata: state.metadata, // Preserve metadata when transitioning from dnd-start to uap-action-start
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return {
|
|
32
|
+
value: 'dnd-end',
|
|
33
|
+
eventData: state.eventData,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
case 'POINTER_CANCEL': {
|
|
40
|
+
if (state.value === 'dnd-start' || state.value === 'dnd-active') {
|
|
41
|
+
return {
|
|
42
|
+
value: 'dnd-end',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
case 'KEY_DOWN': {
|
|
48
|
+
const { key, metadata } = action.payload;
|
|
49
|
+
if (key === 'Enter' || key === ' ') {
|
|
50
|
+
if (state.value === null || state.value === 'uap-action-end' || state.value === 'dnd-end') {
|
|
51
|
+
return {
|
|
52
|
+
value: 'uap-action-start',
|
|
53
|
+
metadata,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (state.value === 'uap-action-start') {
|
|
57
|
+
return {
|
|
58
|
+
value: 'uap-action-end',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else if (state.value === 'dnd-start' || state.value === 'dnd-active') {
|
|
62
|
+
return {
|
|
63
|
+
value: 'uap-action-start',
|
|
64
|
+
metadata,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (key === 'Escape') {
|
|
69
|
+
if (state.value === 'uap-action-start') {
|
|
70
|
+
return {
|
|
71
|
+
value: 'uap-action-end',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return state;
|
|
76
|
+
}
|
|
77
|
+
case 'FOCUS':
|
|
78
|
+
return state;
|
|
79
|
+
case 'BLUR':
|
|
80
|
+
if (state.value === 'uap-action-start') {
|
|
81
|
+
return {
|
|
82
|
+
value: 'uap-action-end',
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return state;
|
|
86
|
+
default:
|
|
87
|
+
throw new Error(`The given action type [${action.type}] is not supported.`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function getCallbacksForTransition(prevState, nextState) {
|
|
91
|
+
const callbacks = [];
|
|
92
|
+
// Transitions from dnd-start or dnd-active to any other state
|
|
93
|
+
if ((prevState.value === 'dnd-start' || prevState.value === 'dnd-active') &&
|
|
94
|
+
nextState.value !== 'dnd-start' &&
|
|
95
|
+
nextState.value !== 'dnd-active') {
|
|
96
|
+
callbacks.push({ type: 'onDndEnd' });
|
|
97
|
+
}
|
|
98
|
+
// From uap-action-start to uap-action-end directly
|
|
99
|
+
if (prevState.value === 'uap-action-start' && nextState.value === 'uap-action-end') {
|
|
100
|
+
callbacks.push({ type: 'onUapActionEnd' });
|
|
101
|
+
}
|
|
102
|
+
// Transitions to dnd-start
|
|
103
|
+
if (nextState.value === 'dnd-start') {
|
|
104
|
+
callbacks.push({
|
|
105
|
+
type: 'onDndStart',
|
|
106
|
+
payload: nextState.eventData,
|
|
107
|
+
metadata: nextState.metadata,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Transitions to dnd-active
|
|
111
|
+
if (nextState.value === 'dnd-active' && prevState.value === 'dnd-start') {
|
|
112
|
+
callbacks.push({
|
|
113
|
+
type: 'onDndActive',
|
|
114
|
+
payload: nextState.eventData,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// Transitions to uap-action-start
|
|
118
|
+
if (nextState.value === 'uap-action-start') {
|
|
119
|
+
callbacks.push({
|
|
120
|
+
type: 'onUapActionStart',
|
|
121
|
+
metadata: nextState.metadata,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return callbacks;
|
|
125
|
+
}
|
|
126
|
+
function interactionReducer(state, action) {
|
|
127
|
+
const nextState = calculateNextState(state, action);
|
|
128
|
+
// Special handling for POINTER_MOVE to always trigger onDndActive callback
|
|
129
|
+
if (action.type === 'POINTER_MOVE' && action.payload.nativeEvent) {
|
|
130
|
+
const transitionCallbacks = getCallbacksForTransition(state, nextState);
|
|
131
|
+
// Check if there's already an onDndActive callback from the transition
|
|
132
|
+
const hasOnDndActiveCallback = transitionCallbacks.some(callback => callback.type === 'onDndActive');
|
|
133
|
+
const callbacks = hasOnDndActiveCallback
|
|
134
|
+
? transitionCallbacks
|
|
135
|
+
: [...transitionCallbacks, { type: 'onDndActive', payload: action.payload.nativeEvent }];
|
|
136
|
+
return Object.assign(Object.assign({}, nextState), { transitionCallbacks: callbacks });
|
|
137
|
+
}
|
|
138
|
+
// Return current state if state didn't change
|
|
139
|
+
const isDndState = (state) => {
|
|
140
|
+
return state.value === 'dnd-start' || state.value === 'dnd-active' || state.value === 'dnd-end';
|
|
141
|
+
};
|
|
142
|
+
if (nextState.value === state.value) {
|
|
143
|
+
if (isDndState(nextState) && isDndState(state)) {
|
|
144
|
+
if (nextState.eventData === state.eventData) {
|
|
145
|
+
return state;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return state;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const callbacks = getCallbacksForTransition(state, nextState);
|
|
153
|
+
return Object.assign(Object.assign({}, nextState), { transitionCallbacks: callbacks.length > 0 ? callbacks : undefined });
|
|
154
|
+
}
|
|
155
|
+
function useStateLogger(state, isEnabled) {
|
|
156
|
+
const prevStateRef = useRef(state);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (state.value !== prevStateRef.current.value && isEnabled) {
|
|
159
|
+
console.log(`State transition: ${prevStateRef.current.value} -> ${state.value}`, {
|
|
160
|
+
prevState: prevStateRef.current,
|
|
161
|
+
nextState: state,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
prevStateRef.current = state;
|
|
165
|
+
}, [state, isEnabled]);
|
|
166
|
+
}
|
|
167
|
+
function useCallbackHandler(pendingCallbacks, props, dispatch) {
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!(pendingCallbacks === null || pendingCallbacks === void 0 ? void 0 : pendingCallbacks.length)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
pendingCallbacks.forEach(callback => {
|
|
173
|
+
var _a, _b, _c, _d, _e;
|
|
174
|
+
switch (callback.type) {
|
|
175
|
+
case 'onDndStart':
|
|
176
|
+
(_a = props.onDndStartAction) === null || _a === void 0 ? void 0 : _a.call(props, callback.payload, callback.metadata);
|
|
177
|
+
break;
|
|
178
|
+
case 'onDndActive':
|
|
179
|
+
(_b = props.onDndActiveAction) === null || _b === void 0 ? void 0 : _b.call(props, callback.payload);
|
|
180
|
+
break;
|
|
181
|
+
case 'onDndEnd':
|
|
182
|
+
(_c = props.onDndEndAction) === null || _c === void 0 ? void 0 : _c.call(props);
|
|
183
|
+
break;
|
|
184
|
+
case 'onUapActionStart':
|
|
185
|
+
(_d = props.onUapActionStartAction) === null || _d === void 0 ? void 0 : _d.call(props, callback.metadata);
|
|
186
|
+
break;
|
|
187
|
+
case 'onUapActionEnd':
|
|
188
|
+
(_e = props.onUapActionEndAction) === null || _e === void 0 ? void 0 : _e.call(props);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}, [pendingCallbacks, props, dispatch]);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Manages interaction states for drag handle components.
|
|
196
|
+
*
|
|
197
|
+
* The hook implements a state machine for drag handles that supports:
|
|
198
|
+
* - Pointer-based drag-and-drop (DnD) interactions
|
|
199
|
+
* - Keyboard-based universal access pattern (UAP) interactions
|
|
200
|
+
* - State transitions with appropriate callbacks
|
|
201
|
+
* - Metadata passing between states
|
|
202
|
+
*
|
|
203
|
+
* States:
|
|
204
|
+
* - null: Idle state with no active interaction
|
|
205
|
+
* - dnd-start: Initial pointer down, beginning of potential drag
|
|
206
|
+
* - dnd-active: Active dragging with pointer movement
|
|
207
|
+
* - dnd-end: Completed drag operation
|
|
208
|
+
* - uap-action-start: Keyboard/accessibility action initiated
|
|
209
|
+
* - uap-action-end: Keyboard/accessibility action completed
|
|
210
|
+
*/
|
|
211
|
+
export default function useDragHandleInteractionState(props = {}, options = { debug: false }) {
|
|
212
|
+
const propsRef = useRef(props);
|
|
213
|
+
propsRef.current = props;
|
|
214
|
+
const [interaction, dispatch] = useReducer((interactionReducer), { value: null });
|
|
215
|
+
useStateLogger(interaction, options.debug);
|
|
216
|
+
useCallbackHandler(interaction.transitionCallbacks, propsRef.current, dispatch);
|
|
217
|
+
return {
|
|
218
|
+
interaction,
|
|
219
|
+
processPointerDown: (event, metadata) => {
|
|
220
|
+
dispatch({
|
|
221
|
+
type: 'POINTER_DOWN',
|
|
222
|
+
payload: { nativeEvent: event, metadata },
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
processPointerMove: (event) => {
|
|
226
|
+
dispatch({
|
|
227
|
+
type: 'POINTER_MOVE',
|
|
228
|
+
payload: { nativeEvent: event },
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
processPointerUp: (event) => {
|
|
232
|
+
dispatch({
|
|
233
|
+
type: 'POINTER_UP',
|
|
234
|
+
payload: { nativeEvent: event },
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
processPointerCancel: () => {
|
|
238
|
+
dispatch({
|
|
239
|
+
type: 'POINTER_CANCEL',
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
processKeyDown: (event, metadata) => {
|
|
243
|
+
const key = event.key;
|
|
244
|
+
if (key === 'Enter' || key === 'Escape' || key === ' ') {
|
|
245
|
+
dispatch({
|
|
246
|
+
type: 'KEY_DOWN',
|
|
247
|
+
payload: { key, metadata },
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
processFocus: () => {
|
|
252
|
+
dispatch({ type: 'FOCUS' });
|
|
253
|
+
},
|
|
254
|
+
processBlur: () => {
|
|
255
|
+
dispatch({ type: 'BLUR' });
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=use-drag-handle-interaction-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-drag-handle-interaction-state.js","sourceRoot":"","sources":["../../../../../../src/internal/components/drag-handle/hooks/use-drag-handle-interaction-state.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAWtD,MAAM,UAAU,kBAAkB,CAChC,KAAoC,EACpC,MAAiB;IAEjB,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,cAAc,CAAC,CAAC;YACnB,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YACjD,OAAO;gBACL,KAAK,EAAE,WAAW;gBAClB,SAAS,EAAE,WAAW;gBACtB,QAAQ;aACT,CAAC;SACH;QAED,KAAK,cAAc,CAAC,CAAC;YACnB,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YACvC,IAAI,KA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AAY,EAAE,GAAG,EAAE;YACjB,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9B,CAAC;QACD,WAAW,EAAE,GAAG,EAAE;YAChB,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React from 'react';\nimport { useEffect, useReducer, useRef } from 'react';\n\nimport type {\n Action,\n DragHandleInteractionState,\n StateTransitionCallbacks,\n UseDragHandleInteractionStateProps,\n} from './interfaces';\n\nexport { UseDragHandleInteractionStateProps };\n\nexport function calculateNextState<T = void>(\n state: DragHandleInteractionState<T>,\n action: Action<T>\n): DragHandleInteractionState<T> {\n switch (action.type) {\n case 'POINTER_DOWN': {\n const { nativeEvent, metadata } = action.payload;\n return {\n value: 'dnd-start',\n eventData: nativeEvent,\n metadata,\n };\n }\n\n case 'POINTER_MOVE': {\n const { nativeEvent } = action.payload;\n if (state.value === 'dnd-start' || state.value === 'dnd-active') {\n return {\n ...state,\n value: 'dnd-active',\n eventData: nativeEvent,\n };\n }\n return state;\n }\n\n case 'POINTER_UP': {\n if (state.value === 'dnd-start' || state.value === 'dnd-active') {\n const dndSubStateBeforeUp = state.value;\n if (dndSubStateBeforeUp === 'dnd-start') {\n return {\n value: 'uap-action-start',\n metadata: state.metadata, // Preserve metadata when transitioning from dnd-start to uap-action-start\n };\n } else {\n return {\n value: 'dnd-end',\n eventData: state.eventData,\n };\n }\n }\n return state;\n }\n\n case 'POINTER_CANCEL': {\n if (state.value === 'dnd-start' || state.value === 'dnd-active') {\n return {\n value: 'dnd-end',\n };\n }\n return state;\n }\n\n case 'KEY_DOWN': {\n const { key, metadata } = action.payload;\n\n if (key === 'Enter' || key === ' ') {\n if (state.value === null || state.value === 'uap-action-end' || state.value === 'dnd-end') {\n return {\n value: 'uap-action-start',\n metadata,\n };\n } else if (state.value === 'uap-action-start') {\n return {\n value: 'uap-action-end',\n };\n } else if (state.value === 'dnd-start' || state.value === 'dnd-active') {\n return {\n value: 'uap-action-start',\n metadata,\n };\n }\n } else if (key === 'Escape') {\n if (state.value === 'uap-action-start') {\n return {\n value: 'uap-action-end',\n };\n }\n }\n return state;\n }\n\n case 'FOCUS':\n return state;\n\n case 'BLUR':\n if (state.value === 'uap-action-start') {\n return {\n value: 'uap-action-end',\n };\n }\n return state;\n\n default:\n throw new Error(`The given action type [${action.type}] is not supported.`);\n }\n}\n\nexport function getCallbacksForTransition<T = void>(\n prevState: DragHandleInteractionState<T>,\n nextState: DragHandleInteractionState<T>\n): StateTransitionCallbacks<T>[] {\n const callbacks: StateTransitionCallbacks<T>[] = [];\n\n // Transitions from dnd-start or dnd-active to any other state\n if (\n (prevState.value === 'dnd-start' || prevState.value === 'dnd-active') &&\n nextState.value !== 'dnd-start' &&\n nextState.value !== 'dnd-active'\n ) {\n callbacks.push({ type: 'onDndEnd' });\n }\n\n // From uap-action-start to uap-action-end directly\n if (prevState.value === 'uap-action-start' && nextState.value === 'uap-action-end') {\n callbacks.push({ type: 'onUapActionEnd' });\n }\n\n // Transitions to dnd-start\n if (nextState.value === 'dnd-start') {\n callbacks.push({\n type: 'onDndStart',\n payload: nextState.eventData!,\n metadata: nextState.metadata,\n });\n }\n\n // Transitions to dnd-active\n if (nextState.value === 'dnd-active' && prevState.value === 'dnd-start') {\n callbacks.push({\n type: 'onDndActive',\n payload: nextState.eventData!,\n });\n }\n\n // Transitions to uap-action-start\n if (nextState.value === 'uap-action-start') {\n callbacks.push({\n type: 'onUapActionStart',\n metadata: nextState.metadata,\n });\n }\n\n return callbacks;\n}\n\nfunction interactionReducer<T = void>(\n state: DragHandleInteractionState<T>,\n action: Action<T>\n): DragHandleInteractionState<T> {\n const nextState = calculateNextState(state, action);\n\n // Special handling for POINTER_MOVE to always trigger onDndActive callback\n if (action.type === 'POINTER_MOVE' && action.payload.nativeEvent) {\n const transitionCallbacks = getCallbacksForTransition(state, nextState);\n // Check if there's already an onDndActive callback from the transition\n const hasOnDndActiveCallback = transitionCallbacks.some(callback => callback.type === 'onDndActive');\n const callbacks = hasOnDndActiveCallback\n ? transitionCallbacks\n : [...transitionCallbacks, { type: 'onDndActive' as const, payload: action.payload.nativeEvent }];\n\n return {\n ...nextState,\n transitionCallbacks: callbacks,\n };\n }\n\n // Return current state if state didn't change\n const isDndState = (state: DragHandleInteractionState<T>) => {\n return state.value === 'dnd-start' || state.value === 'dnd-active' || state.value === 'dnd-end';\n };\n if (nextState.value === state.value) {\n if (isDndState(nextState) && isDndState(state)) {\n if (nextState.eventData === state.eventData) {\n return state;\n }\n } else {\n return state;\n }\n }\n\n const callbacks = getCallbacksForTransition(state, nextState);\n return {\n ...nextState,\n transitionCallbacks: callbacks.length > 0 ? callbacks : undefined,\n };\n}\n\nfunction useStateLogger<T = void>(state: DragHandleInteractionState<T>, isEnabled: boolean) {\n const prevStateRef = useRef<DragHandleInteractionState<T>>(state);\n useEffect(() => {\n if (state.value !== prevStateRef.current.value && isEnabled) {\n console.log(`State transition: ${prevStateRef.current.value} -> ${state.value}`, {\n prevState: prevStateRef.current,\n nextState: state,\n });\n }\n prevStateRef.current = state;\n }, [state, isEnabled]);\n}\n\nfunction useCallbackHandler<T = void>(\n pendingCallbacks: StateTransitionCallbacks<T>[] | undefined,\n props: UseDragHandleInteractionStateProps<T>,\n dispatch: React.Dispatch<Action<T>>\n) {\n useEffect(() => {\n if (!pendingCallbacks?.length) {\n return;\n }\n pendingCallbacks.forEach(callback => {\n switch (callback.type) {\n case 'onDndStart':\n props.onDndStartAction?.(callback.payload, callback.metadata);\n break;\n case 'onDndActive':\n props.onDndActiveAction?.(callback.payload);\n break;\n case 'onDndEnd':\n props.onDndEndAction?.();\n break;\n case 'onUapActionStart':\n props.onUapActionStartAction?.(callback.metadata);\n break;\n case 'onUapActionEnd':\n props.onUapActionEndAction?.();\n break;\n }\n });\n }, [pendingCallbacks, props, dispatch]);\n}\n\n/**\n * Manages interaction states for drag handle components.\n *\n * The hook implements a state machine for drag handles that supports:\n * - Pointer-based drag-and-drop (DnD) interactions\n * - Keyboard-based universal access pattern (UAP) interactions\n * - State transitions with appropriate callbacks\n * - Metadata passing between states\n *\n * States:\n * - null: Idle state with no active interaction\n * - dnd-start: Initial pointer down, beginning of potential drag\n * - dnd-active: Active dragging with pointer movement\n * - dnd-end: Completed drag operation\n * - uap-action-start: Keyboard/accessibility action initiated\n * - uap-action-end: Keyboard/accessibility action completed\n */\nexport default function useDragHandleInteractionState<T = void>(\n props: UseDragHandleInteractionStateProps<T> = {},\n options = { debug: false }\n) {\n const propsRef = useRef<UseDragHandleInteractionStateProps<T>>(props);\n propsRef.current = props;\n\n const [interaction, dispatch] = useReducer(interactionReducer<T>, { value: null } as DragHandleInteractionState<T>);\n useStateLogger(interaction, options.debug);\n useCallbackHandler(interaction.transitionCallbacks, propsRef.current, dispatch);\n return {\n interaction,\n processPointerDown: (event: PointerEvent, metadata?: T) => {\n dispatch({\n type: 'POINTER_DOWN',\n payload: { nativeEvent: event, metadata },\n });\n },\n processPointerMove: (event: PointerEvent) => {\n dispatch({\n type: 'POINTER_MOVE',\n payload: { nativeEvent: event },\n });\n },\n processPointerUp: (event: PointerEvent) => {\n dispatch({\n type: 'POINTER_UP',\n payload: { nativeEvent: event },\n });\n },\n processPointerCancel: () => {\n dispatch({\n type: 'POINTER_CANCEL',\n });\n },\n processKeyDown: (event: React.KeyboardEvent<Element>, metadata?: T) => {\n const key = event.key;\n if (key === 'Enter' || key === 'Escape' || key === ' ') {\n dispatch({\n type: 'KEY_DOWN',\n payload: { key, metadata },\n });\n }\n },\n processFocus: () => {\n dispatch({ type: 'FOCUS' });\n },\n processBlur: () => {\n dispatch({ type: 'BLUR' });\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAK1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,QAAA,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAK1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,QAAA,MAAM,kBAAkB,iFA+CvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -6,9 +6,9 @@ import { getBaseProps } from '../../base-component';
|
|
|
6
6
|
import DragHandleWrapper from '../drag-handle-wrapper';
|
|
7
7
|
import DragHandleButton from './button';
|
|
8
8
|
const InternalDragHandle = forwardRef((_a, ref) => {
|
|
9
|
-
var { variant, size, ariaLabel, ariaLabelledBy, ariaDescribedby, tooltipText, ariaValue, disabled, directions = {}, onPointerDown, onKeyDown, onDirectionClick, triggerMode } = _a, rest = __rest(_a, ["variant", "size", "ariaLabel", "ariaLabelledBy", "ariaDescribedby", "tooltipText", "ariaValue", "disabled", "directions", "onPointerDown", "onKeyDown", "onDirectionClick", "triggerMode"]);
|
|
9
|
+
var { variant, size, ariaLabel, ariaLabelledBy, ariaDescribedby, tooltipText, ariaValue, disabled, directions = {}, onPointerDown, onKeyDown, onDirectionClick, triggerMode, initialShowButtons } = _a, rest = __rest(_a, ["variant", "size", "ariaLabel", "ariaLabelledBy", "ariaDescribedby", "tooltipText", "ariaValue", "disabled", "directions", "onPointerDown", "onKeyDown", "onDirectionClick", "triggerMode", "initialShowButtons"]);
|
|
10
10
|
const baseProps = getBaseProps(rest);
|
|
11
|
-
return (React.createElement(DragHandleWrapper, { directions: !disabled ? directions : {}, tooltipText: tooltipText, onDirectionClick: onDirectionClick, triggerMode: triggerMode },
|
|
11
|
+
return (React.createElement(DragHandleWrapper, { directions: !disabled ? directions : {}, tooltipText: tooltipText, onDirectionClick: onDirectionClick, triggerMode: triggerMode, initialShowButtons: initialShowButtons },
|
|
12
12
|
React.createElement(DragHandleButton, { ref: ref, className: baseProps.className, variant: variant, size: size, ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy, ariaDescribedby: ariaDescribedby, ariaValue: ariaValue, disabled: disabled, onPointerDown: onPointerDown, onKeyDown: onKeyDown })));
|
|
13
13
|
});
|
|
14
14
|
export default InternalDragHandle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,gBAAgB,MAAM,UAAU,CAAC;AAKxC,MAAM,kBAAkB,GAAG,UAAU,CACnC,CACE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,gBAAgB,MAAM,UAAU,CAAC;AAKxC,MAAM,kBAAkB,GAAG,UAAU,CACnC,CACE,EAgBkB,EAClB,GAAuB,EACvB,EAAE;QAlBF,EACE,OAAO,EACP,IAAI,EACJ,SAAS,EACT,cAAc,EACd,eAAe,EACf,WAAW,EACX,SAAS,EACT,QAAQ,EACR,UAAU,GAAG,EAAE,EACf,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,kBAAkB,OAEF,EADb,IAAI,cAfT,kNAgBC,CADQ;IAIT,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAErC,OAAO,CACL,oBAAC,iBAAiB,IAChB,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EACvC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,kBAAkB,EAAE,kBAAkB;QAEtC,oBAAC,gBAAgB,IACf,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,GACpB,CACgB,CACrB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef } from 'react';\n\nimport { getBaseProps } from '../../base-component';\nimport DragHandleWrapper from '../drag-handle-wrapper';\nimport DragHandleButton from './button';\nimport { DragHandleProps } from './interfaces';\n\nexport { DragHandleProps };\n\nconst InternalDragHandle = forwardRef(\n (\n {\n variant,\n size,\n ariaLabel,\n ariaLabelledBy,\n ariaDescribedby,\n tooltipText,\n ariaValue,\n disabled,\n directions = {},\n onPointerDown,\n onKeyDown,\n onDirectionClick,\n triggerMode,\n initialShowButtons,\n ...rest\n }: DragHandleProps,\n ref: React.Ref<Element>\n ) => {\n const baseProps = getBaseProps(rest);\n\n return (\n <DragHandleWrapper\n directions={!disabled ? directions : {}}\n tooltipText={tooltipText}\n onDirectionClick={onDirectionClick}\n triggerMode={triggerMode}\n initialShowButtons={initialShowButtons}\n >\n <DragHandleButton\n ref={ref}\n className={baseProps.className}\n variant={variant}\n size={size}\n ariaLabel={ariaLabel}\n ariaLabelledBy={ariaLabelledBy}\n ariaDescribedby={ariaDescribedby}\n ariaValue={ariaValue}\n disabled={disabled}\n onPointerDown={onPointerDown}\n onKeyDown={onKeyDown}\n />\n </DragHandleWrapper>\n );\n }\n);\n\nexport default InternalDragHandle;\n"]}
|
|
@@ -15,6 +15,7 @@ export interface DragHandleProps {
|
|
|
15
15
|
directions?: Partial<Record<DragHandleProps.Direction, DragHandleProps.DirectionState>>;
|
|
16
16
|
onDirectionClick?: (direction: DragHandleProps.Direction) => void;
|
|
17
17
|
triggerMode?: TriggerMode;
|
|
18
|
+
initialShowButtons?: boolean;
|
|
18
19
|
}
|
|
19
20
|
export declare namespace DragHandleProps {
|
|
20
21
|
type Variant = 'drag-indicator' | 'resize-area' | 'resize-horizontal' | 'resize-vertical';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/interfaces.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,SAAS,IAAI,gBAAgB,EAC7B,cAAc,IAAI,qBAAqB,EACvC,WAAW,EACZ,MAAM,mCAAmC,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC;IAClC,IAAI,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,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AAE,eAAe,CAAC,SAAS,KAAK,IAAI,CAAC;IAClE,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,yBAAiB,eAAe,CAAC;IAC/B,KAAY,OAAO,GAAG,gBAAgB,GAAG,aAAa,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;IAEjG,KAAY,SAAS,GAAG,gBAAgB,CAAC;IACzC,KAAY,cAAc,GAAG,qBAAqB,CAAC;IAEnD,KAAY,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC;IAEtC,UAAiB,SAAS;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n Direction as WrapperDirection,\n DirectionState as WrapperDirectionState,\n TriggerMode,\n} from '../drag-handle-wrapper/interfaces';\n\nexport interface DragHandleProps {\n variant?: DragHandleProps.Variant;\n size?: DragHandleProps.Size;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n ariaDescribedby?: string;\n ariaValue?: DragHandleProps.AriaValue;\n disabled?: boolean;\n className?: string;\n onPointerDown?: React.PointerEventHandler;\n onKeyDown?: React.KeyboardEventHandler;\n\n tooltipText?: string;\n directions?: Partial<Record<DragHandleProps.Direction, DragHandleProps.DirectionState>>;\n onDirectionClick?: (direction: DragHandleProps.Direction) => void;\n triggerMode?: TriggerMode;\n}\n\nexport namespace DragHandleProps {\n export type Variant = 'drag-indicator' | 'resize-area' | 'resize-horizontal' | 'resize-vertical';\n\n export type Direction = WrapperDirection;\n export type DirectionState = WrapperDirectionState;\n\n export type Size = 'small' | 'normal';\n\n export interface AriaValue {\n valueMin: number;\n valueMax: number;\n valueNow: number;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n Direction as WrapperDirection,\n DirectionState as WrapperDirectionState,\n TriggerMode,\n} from '../drag-handle-wrapper/interfaces';\n\nexport interface DragHandleProps {\n variant?: DragHandleProps.Variant;\n size?: DragHandleProps.Size;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n ariaDescribedby?: string;\n ariaValue?: DragHandleProps.AriaValue;\n disabled?: boolean;\n className?: string;\n onPointerDown?: React.PointerEventHandler;\n onKeyDown?: React.KeyboardEventHandler;\n\n tooltipText?: string;\n directions?: Partial<Record<DragHandleProps.Direction, DragHandleProps.DirectionState>>;\n onDirectionClick?: (direction: DragHandleProps.Direction) => void;\n triggerMode?: TriggerMode;\n initialShowButtons?: boolean;\n}\n\nexport namespace DragHandleProps {\n export type Variant = 'drag-indicator' | 'resize-area' | 'resize-horizontal' | 'resize-vertical';\n\n export type Direction = WrapperDirection;\n export type DirectionState = WrapperDirectionState;\n\n export type Size = 'small' | 'normal';\n\n export interface AriaValue {\n valueMin: number;\n valueMax: number;\n valueNow: number;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DragHandleWrapperProps } from './interfaces';
|
|
3
|
-
export default function DragHandleWrapper({ directions, tooltipText, children, onDirectionClick, triggerMode, }: DragHandleWrapperProps): JSX.Element;
|
|
3
|
+
export default function DragHandleWrapper({ directions, tooltipText, children, onDirectionClick, triggerMode, initialShowButtons, }: DragHandleWrapperProps): JSX.Element;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/index.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAa,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAWjE,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,UAAU,EACV,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,WAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/index.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAa,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAWjE,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,UAAU,EACV,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,WAAqB,EACrB,kBAA0B,GAC3B,EAAE,sBAAsB,eA8MxB"}
|
|
@@ -13,11 +13,11 @@ import styles from './styles.css.js';
|
|
|
13
13
|
// a drag. A little allowance is needed for usability reasons, but this number
|
|
14
14
|
// isn't set in stone.
|
|
15
15
|
const PRESS_DELTA_MAX = 3;
|
|
16
|
-
export default function DragHandleWrapper({ directions, tooltipText, children, onDirectionClick, triggerMode = 'focus', }) {
|
|
16
|
+
export default function DragHandleWrapper({ directions, tooltipText, children, onDirectionClick, triggerMode = 'focus', initialShowButtons = false, }) {
|
|
17
17
|
const wrapperRef = useRef(null);
|
|
18
18
|
const dragHandleRef = useRef(null);
|
|
19
19
|
const [showTooltip, setShowTooltip] = useState(false);
|
|
20
|
-
const [showButtons, setShowButtons] = useState(
|
|
20
|
+
const [showButtons, setShowButtons] = useState(initialShowButtons);
|
|
21
21
|
const isPointerDown = useRef(false);
|
|
22
22
|
const initialPointerPosition = useRef();
|
|
23
23
|
const didPointerDrag = useRef(false);
|
|
@@ -115,7 +115,7 @@ export default function DragHandleWrapper({ directions, tooltipText, children, o
|
|
|
115
115
|
}
|
|
116
116
|
else if (triggerMode === 'keyboard-activate' && (event.key === 'Enter' || event.key === ' ')) {
|
|
117
117
|
// toggle buttons when Enter or space is pressed in 'keyboard-activate' triggerMode
|
|
118
|
-
setShowButtons(
|
|
118
|
+
setShowButtons(prevshowButtons => !prevshowButtons);
|
|
119
119
|
}
|
|
120
120
|
else if (event.key !== 'Alt' && event.key !== 'Control' && event.key !== 'Meta' && event.key !== 'Shift') {
|
|
121
121
|
// Pressing any other key will display the focus-visible ring around the
|
|
@@ -137,7 +137,7 @@ export default function DragHandleWrapper({ directions, tooltipText, children, o
|
|
|
137
137
|
React.createElement("div", { onPointerEnter: onTooltipGroupPointerEnter, onPointerLeave: onTooltipGroupPointerLeave },
|
|
138
138
|
React.createElement("div", { className: styles['drag-handle'], ref: dragHandleRef, onPointerDown: onHandlePointerDown, onKeyDown: onDragHandleKeyDown }, children),
|
|
139
139
|
!isDisabled && !showButtons && showTooltip && tooltipText && (React.createElement(Tooltip, { trackRef: dragHandleRef, value: tooltipText, onDismiss: () => setShowTooltip(false) }))),
|
|
140
|
-
React.createElement(PortalOverlay, { track: dragHandleRef
|
|
140
|
+
React.createElement(PortalOverlay, { track: dragHandleRef, isDisabled: !showButtons },
|
|
141
141
|
directions['block-start'] && (React.createElement(DirectionButton, { show: !isDisabled && showButtons, direction: "block-start", state: directions['block-start'], onClick: () => onInternalDirectionClick('block-start') })),
|
|
142
142
|
directions['block-end'] && (React.createElement(DirectionButton, { show: !isDisabled && showButtons, direction: "block-end", state: directions['block-end'], onClick: () => onInternalDirectionClick('block-end') })),
|
|
143
143
|
directions['inline-start'] && (React.createElement(DirectionButton, { show: !isDisabled && showButtons, direction: "inline-start", state: directions['inline-start'], onClick: () => onInternalDirectionClick('inline-start') })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;A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AAc,CAAC,IAAI,CAC7B,oBAAC,eAAe,IACd,IAAI,EAAE,CAAC,UAAU,IAAI,WAAW,EAChC,SAAS,EAAC,cAAc,EACxB,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,EACjC,OAAO,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,cAAc,CAAC,GACvD,CACH;YACA,UAAU,CAAC,YAAY,CAAC,IAAI,CAC3B,oBAAC,eAAe,IACd,IAAI,EAAE,CAAC,UAAU,IAAI,WAAW,EAChC,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,EAC/B,OAAO,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,YAAY,CAAC,GACrD,CACH,CACa,CACZ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { nodeContains } from '@cloudscape-design/component-toolkit/dom';\n\nimport { getFirstFocusable } from '../focus-lock/utils';\nimport Tooltip from '../tooltip';\nimport DirectionButton from './direction-button';\nimport { Direction, DragHandleWrapperProps } from './interfaces';\nimport PortalOverlay from './portal-overlay';\n\nimport styles from './styles.css.js';\n\n// The amount of distance after pointer down that the cursor is allowed to\n// jitter for a subsequent mouseup to still register as a \"press\" instead of\n// a drag. A little allowance is needed for usability reasons, but this number\n// isn't set in stone.\nconst PRESS_DELTA_MAX = 3;\n\nexport default function DragHandleWrapper({\n directions,\n tooltipText,\n children,\n onDirectionClick,\n triggerMode = 'focus',\n}: DragHandleWrapperProps) {\n const wrapperRef = useRef<HTMLDivElement | null>(null);\n const dragHandleRef = useRef<HTMLDivElement | null>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n const [showButtons, setShowButtons] = useState(false);\n\n const isPointerDown = useRef(false);\n const initialPointerPosition = useRef<{ x: number; y: number } | undefined>();\n const didPointerDrag = useRef(false);\n\n // The tooltip (\"Drag or select to move/resize\") shouldn't show if clicking\n // on the handle wouldn't do anything.\n const isDisabled =\n !directions['block-start'] && !directions['block-end'] && !directions['inline-start'] && !directions['inline-end'];\n\n const onWrapperFocusIn: React.FocusEventHandler = event => {\n // The drag handle is focused when it's either tabbed to, or the pointer\n // is pressed on it. We exclude handling the pointer press in this handler,\n // since it could be the start of a drag event - the pointer stuff is\n // handled in the \"pointerup\" listener instead. In cases where focus is moved\n // to the button (by manually calling `.focus()`, the buttons should only appear)\n // if the action that triggered the focus move was the result of a keypress.\n if (document.body.dataset.awsuiFocusVisible && !nodeContains(wrapperRef.current, event.relatedTarget)) {\n setShowTooltip(false);\n if (triggerMode === 'focus') {\n setShowButtons(true);\n }\n }\n };\n\n const onWrapperFocusOut: React.FocusEventHandler = event => {\n // Close the directional buttons when the focus leaves the drag handle.\n // \"focusout\" is also triggered when the user leaves the current tab, but\n // since it'll be returned when they switch back anyway, we exclude that\n // case by checking for `document.hasFocus()`.\n if (document.hasFocus() && !nodeContains(wrapperRef.current, event.relatedTarget)) {\n setShowButtons(false);\n }\n };\n\n useEffect(() => {\n const controller = new AbortController();\n\n // See `PRESS_DELTA_MAX` above. We need to differentiate between a \"click\"\n // and a \"drag\" action. We can say a \"click\" happens when a \"pointerdown\"\n // is followed by a \"pointerup\" with no \"pointermove\" between the two.\n // However, it would be a poor usability experience if a \"click\" isn't\n // registered because, while pressing my mouse, I moved it by just one\n // pixel, making it a \"drag\" instead. So we allow the pointer to move by\n // `PRESS_DELTA_MAX` pixels before setting `didPointerDrag` to true.\n document.addEventListener(\n 'pointermove',\n event => {\n if (\n isPointerDown.current &&\n initialPointerPosition.current &&\n (event.clientX > initialPointerPosition.current.x + PRESS_DELTA_MAX ||\n event.clientX < initialPointerPosition.current.x - PRESS_DELTA_MAX ||\n event.clientY > initialPointerPosition.current.y + PRESS_DELTA_MAX ||\n event.clientY < initialPointerPosition.current.y - PRESS_DELTA_MAX)\n ) {\n didPointerDrag.current = true;\n }\n },\n { signal: controller.signal }\n );\n\n // Shared behavior when a \"pointerdown\" state ends. This is shared so it\n // can be called for both \"pointercancel\" and \"pointerup\" events.\n const resetPointerDownState = () => {\n isPointerDown.current = false;\n initialPointerPosition.current = undefined;\n };\n\n document.addEventListener(\n 'pointercancel',\n () => {\n resetPointerDownState();\n },\n { signal: controller.signal }\n );\n\n document.addEventListener(\n 'pointerup',\n () => {\n if (isPointerDown.current && !didPointerDrag.current) {\n // The cursor didn't move much between \"pointerdown\" and \"pointerup\".\n // Handle this as a \"click\" instead of a \"drag\".\n setShowButtons(true);\n }\n resetPointerDownState();\n },\n { signal: controller.signal }\n );\n\n return () => controller.abort();\n }, []);\n\n const onHandlePointerDown: React.PointerEventHandler = event => {\n // Tooltip behavior: the tooltip should appear on hover, but disappear when\n // the pointer starts dragging (having the tooltip get in the way while\n // you're trying to drag upwards is annoying). Additionally, the tooltip\n // shouldn't reappear when dragging ends, but only when the pointer leaves\n // the drag handle and comes back.\n\n isPointerDown.current = true;\n didPointerDrag.current = false;\n initialPointerPosition.current = { x: event.clientX, y: event.clientY };\n setShowTooltip(false);\n };\n\n // Tooltip behavior: the tooltip should stay open when the cursor moves\n // from the drag handle into the tooltip content itself. This is why the\n // handler is set on the wrapper for both the drag handle and the tooltip.\n const onTooltipGroupPointerEnter: React.PointerEventHandler = () => {\n if (!isPointerDown.current) {\n setShowTooltip(true);\n }\n };\n const onTooltipGroupPointerLeave: React.PointerEventHandler = () => {\n setShowTooltip(false);\n };\n\n const onDragHandleKeyDown: React.KeyboardEventHandler = event => {\n // For accessibility reasons, pressing escape should should always close\n // the floating controls.\n if (event.key === 'Escape') {\n setShowButtons(false);\n } else if (triggerMode === 'keyboard-activate' && (event.key === 'Enter' || event.key === ' ')) {\n // toggle buttons when Enter or space is pressed in 'keyboard-activate' triggerMode\n setShowButtons(prevShowButtons => !prevShowButtons);\n } else if (event.key !== 'Alt' && event.key !== 'Control' && event.key !== 'Meta' && event.key !== 'Shift') {\n // Pressing any other key will display the focus-visible ring around the\n // drag handle if it's in focus, so we should also show the buttons now.\n setShowButtons(true);\n }\n };\n\n const onInternalDirectionClick = (direction: Direction) => {\n // Move focus back to the wrapper on click. This prevents focus from staying\n // on an aria-hidden control, and allows future keyboard events to be handled\n // cleanly using the drag handle's own handlers.\n if (dragHandleRef.current) {\n getFirstFocusable(dragHandleRef.current)?.focus();\n }\n onDirectionClick?.(direction);\n };\n\n return (\n <div\n className={clsx(styles['drag-handle-wrapper'], showButtons && styles['drag-handle-wrapper-open'])}\n ref={wrapperRef}\n onFocus={onWrapperFocusIn}\n onBlur={onWrapperFocusOut}\n >\n <div onPointerEnter={onTooltipGroupPointerEnter} onPointerLeave={onTooltipGroupPointerLeave}>\n <div\n className={styles['drag-handle']}\n ref={dragHandleRef}\n onPointerDown={onHandlePointerDown}\n onKeyDown={onDragHandleKeyDown}\n >\n {children}\n </div>\n\n {!isDisabled && !showButtons && showTooltip && tooltipText && (\n <Tooltip trackRef={dragHandleRef} value={tooltipText} onDismiss={() => setShowTooltip(false)} />\n )}\n </div>\n\n <PortalOverlay track={dragHandleRef.current} isDisabled={!showButtons}>\n {directions['block-start'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"block-start\"\n state={directions['block-start']}\n onClick={() => onInternalDirectionClick('block-start')}\n />\n )}\n {directions['block-end'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"block-end\"\n state={directions['block-end']}\n onClick={() => onInternalDirectionClick('block-end')}\n />\n )}\n {directions['inline-start'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"inline-start\"\n state={directions['inline-start']}\n onClick={() => onInternalDirectionClick('inline-start')}\n />\n )}\n {directions['inline-end'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"inline-end\"\n state={directions['inline-end']}\n onClick={() => onInternalDirectionClick('inline-end')}\n />\n )}\n </PortalOverlay>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRo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C,WAAW,CAAC,EAC9B,OAAO,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,GACpD,CACH;YACA,UAAU,CAAC,cAAc,CAAC,IAAI,CAC7B,oBAAC,eAAe,IACd,IAAI,EAAE,CAAC,UAAU,IAAI,WAAW,EAChC,SAAS,EAAC,cAAc,EACxB,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,EACjC,OAAO,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,cAAc,CAAC,GACvD,CACH;YACA,UAAU,CAAC,YAAY,CAAC,IAAI,CAC3B,oBAAC,eAAe,IACd,IAAI,EAAE,CAAC,UAAU,IAAI,WAAW,EAChC,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,EAC/B,OAAO,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,YAAY,CAAC,GACrD,CACH,CACa,CACZ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { nodeContains } from '@cloudscape-design/component-toolkit/dom';\n\nimport { getFirstFocusable } from '../focus-lock/utils';\nimport Tooltip from '../tooltip';\nimport DirectionButton from './direction-button';\nimport { Direction, DragHandleWrapperProps } from './interfaces';\nimport PortalOverlay from './portal-overlay';\n\nimport styles from './styles.css.js';\n\n// The amount of distance after pointer down that the cursor is allowed to\n// jitter for a subsequent mouseup to still register as a \"press\" instead of\n// a drag. A little allowance is needed for usability reasons, but this number\n// isn't set in stone.\nconst PRESS_DELTA_MAX = 3;\n\nexport default function DragHandleWrapper({\n directions,\n tooltipText,\n children,\n onDirectionClick,\n triggerMode = 'focus',\n initialShowButtons = false,\n}: DragHandleWrapperProps) {\n const wrapperRef = useRef<HTMLDivElement | null>(null);\n const dragHandleRef = useRef<HTMLDivElement | null>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n const [showButtons, setShowButtons] = useState(initialShowButtons);\n\n const isPointerDown = useRef(false);\n const initialPointerPosition = useRef<{ x: number; y: number } | undefined>();\n const didPointerDrag = useRef(false);\n\n // The tooltip (\"Drag or select to move/resize\") shouldn't show if clicking\n // on the handle wouldn't do anything.\n const isDisabled =\n !directions['block-start'] && !directions['block-end'] && !directions['inline-start'] && !directions['inline-end'];\n\n const onWrapperFocusIn: React.FocusEventHandler = event => {\n // The drag handle is focused when it's either tabbed to, or the pointer\n // is pressed on it. We exclude handling the pointer press in this handler,\n // since it could be the start of a drag event - the pointer stuff is\n // handled in the \"pointerup\" listener instead. In cases where focus is moved\n // to the button (by manually calling `.focus()`, the buttons should only appear)\n // if the action that triggered the focus move was the result of a keypress.\n if (document.body.dataset.awsuiFocusVisible && !nodeContains(wrapperRef.current, event.relatedTarget)) {\n setShowTooltip(false);\n if (triggerMode === 'focus') {\n setShowButtons(true);\n }\n }\n };\n\n const onWrapperFocusOut: React.FocusEventHandler = event => {\n // Close the directional buttons when the focus leaves the drag handle.\n // \"focusout\" is also triggered when the user leaves the current tab, but\n // since it'll be returned when they switch back anyway, we exclude that\n // case by checking for `document.hasFocus()`.\n if (document.hasFocus() && !nodeContains(wrapperRef.current, event.relatedTarget)) {\n setShowButtons(false);\n }\n };\n\n useEffect(() => {\n const controller = new AbortController();\n\n // See `PRESS_DELTA_MAX` above. We need to differentiate between a \"click\"\n // and a \"drag\" action. We can say a \"click\" happens when a \"pointerdown\"\n // is followed by a \"pointerup\" with no \"pointermove\" between the two.\n // However, it would be a poor usability experience if a \"click\" isn't\n // registered because, while pressing my mouse, I moved it by just one\n // pixel, making it a \"drag\" instead. So we allow the pointer to move by\n // `PRESS_DELTA_MAX` pixels before setting `didPointerDrag` to true.\n document.addEventListener(\n 'pointermove',\n event => {\n if (\n isPointerDown.current &&\n initialPointerPosition.current &&\n (event.clientX > initialPointerPosition.current.x + PRESS_DELTA_MAX ||\n event.clientX < initialPointerPosition.current.x - PRESS_DELTA_MAX ||\n event.clientY > initialPointerPosition.current.y + PRESS_DELTA_MAX ||\n event.clientY < initialPointerPosition.current.y - PRESS_DELTA_MAX)\n ) {\n didPointerDrag.current = true;\n }\n },\n { signal: controller.signal }\n );\n\n // Shared behavior when a \"pointerdown\" state ends. This is shared so it\n // can be called for both \"pointercancel\" and \"pointerup\" events.\n const resetPointerDownState = () => {\n isPointerDown.current = false;\n initialPointerPosition.current = undefined;\n };\n\n document.addEventListener(\n 'pointercancel',\n () => {\n resetPointerDownState();\n },\n { signal: controller.signal }\n );\n\n document.addEventListener(\n 'pointerup',\n () => {\n if (isPointerDown.current && !didPointerDrag.current) {\n // The cursor didn't move much between \"pointerdown\" and \"pointerup\".\n // Handle this as a \"click\" instead of a \"drag\".\n setShowButtons(true);\n }\n resetPointerDownState();\n },\n { signal: controller.signal }\n );\n\n return () => controller.abort();\n }, []);\n\n const onHandlePointerDown: React.PointerEventHandler = event => {\n // Tooltip behavior: the tooltip should appear on hover, but disappear when\n // the pointer starts dragging (having the tooltip get in the way while\n // you're trying to drag upwards is annoying). Additionally, the tooltip\n // shouldn't reappear when dragging ends, but only when the pointer leaves\n // the drag handle and comes back.\n\n isPointerDown.current = true;\n didPointerDrag.current = false;\n initialPointerPosition.current = { x: event.clientX, y: event.clientY };\n setShowTooltip(false);\n };\n\n // Tooltip behavior: the tooltip should stay open when the cursor moves\n // from the drag handle into the tooltip content itself. This is why the\n // handler is set on the wrapper for both the drag handle and the tooltip.\n const onTooltipGroupPointerEnter: React.PointerEventHandler = () => {\n if (!isPointerDown.current) {\n setShowTooltip(true);\n }\n };\n const onTooltipGroupPointerLeave: React.PointerEventHandler = () => {\n setShowTooltip(false);\n };\n\n const onDragHandleKeyDown: React.KeyboardEventHandler = event => {\n // For accessibility reasons, pressing escape should should always close\n // the floating controls.\n if (event.key === 'Escape') {\n setShowButtons(false);\n } else if (triggerMode === 'keyboard-activate' && (event.key === 'Enter' || event.key === ' ')) {\n // toggle buttons when Enter or space is pressed in 'keyboard-activate' triggerMode\n setShowButtons(prevshowButtons => !prevshowButtons);\n } else if (event.key !== 'Alt' && event.key !== 'Control' && event.key !== 'Meta' && event.key !== 'Shift') {\n // Pressing any other key will display the focus-visible ring around the\n // drag handle if it's in focus, so we should also show the buttons now.\n setShowButtons(true);\n }\n };\n\n const onInternalDirectionClick = (direction: Direction) => {\n // Move focus back to the wrapper on click. This prevents focus from staying\n // on an aria-hidden control, and allows future keyboard events to be handled\n // cleanly using the drag handle's own handlers.\n if (dragHandleRef.current) {\n getFirstFocusable(dragHandleRef.current)?.focus();\n }\n onDirectionClick?.(direction);\n };\n\n return (\n <div\n className={clsx(styles['drag-handle-wrapper'], showButtons && styles['drag-handle-wrapper-open'])}\n ref={wrapperRef}\n onFocus={onWrapperFocusIn}\n onBlur={onWrapperFocusOut}\n >\n <div onPointerEnter={onTooltipGroupPointerEnter} onPointerLeave={onTooltipGroupPointerLeave}>\n <div\n className={styles['drag-handle']}\n ref={dragHandleRef}\n onPointerDown={onHandlePointerDown}\n onKeyDown={onDragHandleKeyDown}\n >\n {children}\n </div>\n\n {!isDisabled && !showButtons && showTooltip && tooltipText && (\n <Tooltip trackRef={dragHandleRef} value={tooltipText} onDismiss={() => setShowTooltip(false)} />\n )}\n </div>\n\n <PortalOverlay track={dragHandleRef} isDisabled={!showButtons}>\n {directions['block-start'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"block-start\"\n state={directions['block-start']}\n onClick={() => onInternalDirectionClick('block-start')}\n />\n )}\n {directions['block-end'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"block-end\"\n state={directions['block-end']}\n onClick={() => onInternalDirectionClick('block-end')}\n />\n )}\n {directions['inline-start'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"inline-start\"\n state={directions['inline-start']}\n onClick={() => onInternalDirectionClick('inline-start')}\n />\n )}\n {directions['inline-end'] && (\n <DirectionButton\n show={!isDisabled && showButtons}\n direction=\"inline-end\"\n state={directions['inline-end']}\n onClick={() => onInternalDirectionClick('inline-end')}\n />\n )}\n </PortalOverlay>\n </div>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/interfaces.ts"],"names":[],"mappings":";AAGA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,cAAc,GAAG,YAAY,CAAC;AACpF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,CAAC;AACnD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,mBAAmB,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/interfaces.ts"],"names":[],"mappings":";AAGA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,cAAc,GAAG,YAAY,CAAC;AACpF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,CAAC;AACnD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,mBAAmB,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport type Direction = 'block-start' | 'block-end' | 'inline-start' | 'inline-end';\nexport type DirectionState = 'active' | 'disabled';\nexport type TriggerMode = 'focus' | 'keyboard-activate';\n\nexport interface DragHandleWrapperProps {\n directions: Partial<Record<Direction, DirectionState>>;\n onDirectionClick?: (direction: Direction) => void;\n tooltipText?: string;\n children: React.ReactNode;\n triggerMode?: TriggerMode;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport type Direction = 'block-start' | 'block-end' | 'inline-start' | 'inline-end';\nexport type DirectionState = 'active' | 'disabled';\nexport type TriggerMode = 'focus' | 'keyboard-activate';\n\nexport interface DragHandleWrapperProps {\n directions: Partial<Record<Direction, DirectionState>>;\n onDirectionClick?: (direction: Direction) => void;\n tooltipText?: string;\n children: React.ReactNode;\n triggerMode?: TriggerMode;\n initialShowButtons?: boolean;\n}\n"]}
|
package/lib/internal/template/internal/components/drag-handle-wrapper/portal-overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal-overlay.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/portal-overlay.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAWjD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"portal-overlay.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/portal-overlay.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAWjD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,sBA4DA"}
|
|
@@ -6,7 +6,7 @@ import styles from './styles.css.js';
|
|
|
6
6
|
export default function PortalOverlay({ track, isDisabled, children, }) {
|
|
7
7
|
const ref = useRef(null);
|
|
8
8
|
useEffect(() => {
|
|
9
|
-
if (track === null || isDisabled) {
|
|
9
|
+
if (track.current === null || isDisabled) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
let cleanedUp = false;
|
|
@@ -16,9 +16,9 @@ export default function PortalOverlay({ track, isDisabled, children, }) {
|
|
|
16
16
|
let lastBlockSize;
|
|
17
17
|
const updateElement = () => {
|
|
18
18
|
// It could be that the portal hasn't been attached to the DOM yet - ensure the ref exists and is attached DOM tree.
|
|
19
|
-
if (ref.current && document.body.contains(ref.current)) {
|
|
19
|
+
if (track.current && ref.current && document.body.contains(ref.current)) {
|
|
20
20
|
const isRtl = getIsRtl(ref.current);
|
|
21
|
-
const { insetInlineStart, insetBlockStart, inlineSize, blockSize } = getLogicalBoundingClientRect(track);
|
|
21
|
+
const { insetInlineStart, insetBlockStart, inlineSize, blockSize } = getLogicalBoundingClientRect(track.current);
|
|
22
22
|
// For simplicity, we just make all our calculations independent of
|
|
23
23
|
// the browser's scrolling edge. When it comes to applying the changes,
|
|
24
24
|
// translate is independent of writing direction, so we need to invert
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal-overlay.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/portal-overlay.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EACL,QAAQ,EACR,4BAA4B,EAC5B,oBAAoB,EACpB,MAAM,GACP,MAAM,+CAA+C,CAAC;AAEvD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,UAAU,EACV,QAAQ,GAKT;IACC,MAAM,GAAG,GAAG,MAAM,CAAyB,IAAI,CAAC,CAAC;IAEjD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"portal-overlay.js","sourceRoot":"","sources":["../../../../../src/internal/components/drag-handle-wrapper/portal-overlay.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EACL,QAAQ,EACR,4BAA4B,EAC5B,oBAAoB,EACpB,MAAM,GACP,MAAM,+CAA+C,CAAC;AAEvD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,KAAK,EACL,UAAU,EACV,QAAQ,GAKT;IACC,MAAM,GAAG,GAAG,MAAM,CAAyB,IAAI,CAAC,CAAC;IAEjD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,CAAC,OAAO,KAAK,IAA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AAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,CAAC;oBAC5C,cAAc,GAAG,UAAU,CAAC;oBAC5B,aAAa,GAAG,SAAS,CAAC;iBAC3B;aACF;YACD,IAAI,CAAC,SAAS,EAAE;gBACd,qBAAqB,CAAC,aAAa,CAAC,CAAC;aACtC;QACH,CAAC,CAAC;QACF,aAAa,EAAE,CAAC;QAEhB,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;IAExB,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,oBAAC,MAAM;QACL,8BAAM,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC;YACjD,8BAAM,SAAS,EAAE,MAAM,CAAC,yBAAyB,CAAC,IAAG,QAAQ,CAAQ,CAChE,CACA,CACV,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef } from 'react';\n\nimport {\n getIsRtl,\n getLogicalBoundingClientRect,\n getScrollInlineStart,\n Portal,\n} from '@cloudscape-design/component-toolkit/internal';\n\nimport styles from './styles.css.js';\n\nexport default function PortalOverlay({\n track,\n isDisabled,\n children,\n}: {\n track: React.RefObject<HTMLElement | null>;\n isDisabled: boolean;\n children: React.ReactNode;\n}) {\n const ref = useRef<HTMLSpanElement | null>(null);\n\n useEffect(() => {\n if (track.current === null || isDisabled) {\n return;\n }\n\n let cleanedUp = false;\n let lastX: number | undefined;\n let lastY: number | undefined;\n let lastInlineSize: number | undefined;\n let lastBlockSize: number | undefined;\n const updateElement = () => {\n // It could be that the portal hasn't been attached to the DOM yet - ensure the ref exists and is attached DOM tree.\n if (track.current && ref.current && document.body.contains(ref.current)) {\n const isRtl = getIsRtl(ref.current);\n const { insetInlineStart, insetBlockStart, inlineSize, blockSize } = getLogicalBoundingClientRect(\n track.current\n );\n // For simplicity, we just make all our calculations independent of\n // the browser's scrolling edge. When it comes to applying the changes,\n // translate is independent of writing direction, so we need to invert\n // the X coordinate ourselves just before applying the values.\n const newX = (insetInlineStart + getScrollInlineStart(document.documentElement)) * (isRtl ? -1 : 1);\n const newY = insetBlockStart + document.documentElement.scrollTop;\n if (lastX !== newX || lastY !== newY) {\n ref.current.style.translate = `${newX}px ${newY}px`;\n lastX = newX;\n lastY = newY;\n }\n if (lastInlineSize !== inlineSize || lastBlockSize !== blockSize) {\n ref.current.style.width = `${inlineSize}px`;\n ref.current.style.height = `${blockSize}px`;\n lastInlineSize = inlineSize;\n lastBlockSize = blockSize;\n }\n }\n if (!cleanedUp) {\n requestAnimationFrame(updateElement);\n }\n };\n updateElement();\n\n return () => {\n cleanedUp = true;\n };\n }, [isDisabled, track]);\n\n if (track === null) {\n return null;\n }\n\n return (\n <Portal>\n <span ref={ref} className={styles['portal-overlay']}>\n <span className={styles['portal-overlay-contents']}>{children}</span>\n </span>\n </Portal>\n );\n}\n"]}
|