@planningcenter/react-beautiful-dnd 13.2.0
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/CHANGELOG.md +35 -0
- package/LICENSE +13 -0
- package/README.md +178 -0
- package/dist/react-beautiful-dnd.cjs.js +8728 -0
- package/dist/react-beautiful-dnd.cjs.js.flow +3 -0
- package/dist/react-beautiful-dnd.esm.js +8715 -0
- package/dist/react-beautiful-dnd.js +11726 -0
- package/dist/react-beautiful-dnd.min.js +1 -0
- package/package.json +155 -0
- package/src/animation.js +75 -0
- package/src/debug/middleware/action-timing-average.js +52 -0
- package/src/debug/middleware/action-timing.js +16 -0
- package/src/debug/middleware/log.js +26 -0
- package/src/debug/middleware/user-timing.js +16 -0
- package/src/debug/timings.js +86 -0
- package/src/dev-warning.js +50 -0
- package/src/empty.js +6 -0
- package/src/index.js +67 -0
- package/src/invariant.js +33 -0
- package/src/native-with-fallback.js +69 -0
- package/src/screen-reader-message-preset.js +134 -0
- package/src/state/action-creators.js +328 -0
- package/src/state/auto-scroller/auto-scroller-types.js +8 -0
- package/src/state/auto-scroller/can-scroll.js +160 -0
- package/src/state/auto-scroller/fluid-scroller/config.js +25 -0
- package/src/state/auto-scroller/fluid-scroller/did-start-in-scrollable-area.js +1 -0
- package/src/state/auto-scroller/fluid-scroller/get-best-scrollable-droppable.js +77 -0
- package/src/state/auto-scroller/fluid-scroller/get-droppable-scroll-change.js +50 -0
- package/src/state/auto-scroller/fluid-scroller/get-percentage.js +25 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/adjust-for-size-limits.js +30 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/buffer-thresholds/calc-axis-scroll-conditions.js +68 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/buffer-thresholds/get-scroll-conditions.js +56 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/buffer-thresholds/index.js +66 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/dampen-value-by-time.js +48 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-distance-thresholds.js +31 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value-from-distance.js +67 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value.js +51 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/index.js +50 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/min-scroll.js +4 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/index.js +139 -0
- package/src/state/auto-scroller/fluid-scroller/get-window-scroll-change.js +43 -0
- package/src/state/auto-scroller/fluid-scroller/index.js +99 -0
- package/src/state/auto-scroller/fluid-scroller/scroll.js +80 -0
- package/src/state/auto-scroller/index.js +59 -0
- package/src/state/auto-scroller/jump-scroller.js +139 -0
- package/src/state/axis.js +26 -0
- package/src/state/calculate-drag-impact/calculate-reorder-impact.js +136 -0
- package/src/state/can-start-drag.js +29 -0
- package/src/state/create-store.js +97 -0
- package/src/state/did-start-after-critical.js +9 -0
- package/src/state/dimension-marshal/dimension-marshal-types.js +46 -0
- package/src/state/dimension-marshal/dimension-marshal.js +218 -0
- package/src/state/dimension-marshal/get-initial-publish.js +66 -0
- package/src/state/dimension-marshal/while-dragging-publisher.js +146 -0
- package/src/state/dimension-structures.js +35 -0
- package/src/state/droppable/get-droppable.js +101 -0
- package/src/state/droppable/is-home-of.js +7 -0
- package/src/state/droppable/scroll-droppable.js +53 -0
- package/src/state/droppable/should-use-placeholder.js +7 -0
- package/src/state/droppable/util/clip.js +17 -0
- package/src/state/droppable/util/get-subject.js +63 -0
- package/src/state/droppable/what-is-dragged-over-from-result.js +16 -0
- package/src/state/droppable/what-is-dragged-over.js +16 -0
- package/src/state/droppable/with-placeholder.js +174 -0
- package/src/state/get-center-from-impact/get-client-border-box-center/get-client-from-page-border-box-center.js +29 -0
- package/src/state/get-center-from-impact/get-client-border-box-center/index.js +44 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/index.js +70 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/when-combining.js +39 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/when-reordering.js +112 -0
- package/src/state/get-center-from-impact/move-relative-to.js +66 -0
- package/src/state/get-combined-item-displacement.js +34 -0
- package/src/state/get-displaced-by.js +17 -0
- package/src/state/get-displacement-groups.js +130 -0
- package/src/state/get-drag-impact/get-combine-impact.js +130 -0
- package/src/state/get-drag-impact/get-reorder-impact.js +143 -0
- package/src/state/get-drag-impact/index.js +93 -0
- package/src/state/get-draggables-inside-droppable.js +31 -0
- package/src/state/get-droppable-over.js +158 -0
- package/src/state/get-frame.js +10 -0
- package/src/state/get-home-location.js +7 -0
- package/src/state/get-impact-location.js +16 -0
- package/src/state/get-is-displaced.js +11 -0
- package/src/state/get-lift-effect.js +82 -0
- package/src/state/get-max-scroll.js +30 -0
- package/src/state/is-movement-allowed.js +6 -0
- package/src/state/is-within.js +9 -0
- package/src/state/middleware/auto-scroll.js +38 -0
- package/src/state/middleware/dimension-marshal-stopper.js +20 -0
- package/src/state/middleware/drop/drop-animation-finish-middleware.js +21 -0
- package/src/state/middleware/drop/drop-animation-flush-on-scroll-middleware.js +63 -0
- package/src/state/middleware/drop/drop-middleware.js +146 -0
- package/src/state/middleware/drop/get-drop-duration.js +47 -0
- package/src/state/middleware/drop/get-drop-impact.js +77 -0
- package/src/state/middleware/drop/get-new-home-client-offset.js +54 -0
- package/src/state/middleware/drop/index.js +2 -0
- package/src/state/middleware/focus.js +42 -0
- package/src/state/middleware/lift.js +66 -0
- package/src/state/middleware/pending-drop.js +37 -0
- package/src/state/middleware/responders/async-marshal.js +55 -0
- package/src/state/middleware/responders/expiring-announce.js +44 -0
- package/src/state/middleware/responders/index.js +2 -0
- package/src/state/middleware/responders/is-equal.js +57 -0
- package/src/state/middleware/responders/publisher.js +253 -0
- package/src/state/middleware/responders/responders-middleware.js +75 -0
- package/src/state/middleware/scroll-listener.js +31 -0
- package/src/state/middleware/style.js +22 -0
- package/src/state/middleware/util/validate-dimensions.js +71 -0
- package/src/state/move-in-direction/index.js +84 -0
- package/src/state/move-in-direction/move-cross-axis/get-best-cross-axis-droppable.js +168 -0
- package/src/state/move-in-direction/move-cross-axis/get-closest-draggable.js +79 -0
- package/src/state/move-in-direction/move-cross-axis/index.js +109 -0
- package/src/state/move-in-direction/move-cross-axis/move-to-new-droppable.js +121 -0
- package/src/state/move-in-direction/move-cross-axis/without-starting-displacement.js +31 -0
- package/src/state/move-in-direction/move-in-direction-types.js +9 -0
- package/src/state/move-in-direction/move-to-next-place/index.js +132 -0
- package/src/state/move-in-direction/move-to-next-place/is-totally-visible-in-new-location.js +52 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-combine/index.js +97 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/from-combine.js +52 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/from-reorder.js +43 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/index.js +86 -0
- package/src/state/no-impact.js +33 -0
- package/src/state/patch-dimension-map.js +11 -0
- package/src/state/patch-droppable-map.js +10 -0
- package/src/state/position.js +58 -0
- package/src/state/post-reducer/when-moving/refresh-snap.js +67 -0
- package/src/state/post-reducer/when-moving/update.js +120 -0
- package/src/state/publish-while-dragging-in-virtual/adjust-additions-for-scroll-changes.js +58 -0
- package/src/state/publish-while-dragging-in-virtual/index.js +158 -0
- package/src/state/publish-while-dragging-in-virtual/offset-draggable.js +35 -0
- package/src/state/recompute-placeholders.js +99 -0
- package/src/state/rect.js +7 -0
- package/src/state/reducer.js +457 -0
- package/src/state/registry/create-registry.js +162 -0
- package/src/state/registry/registry-types.js +98 -0
- package/src/state/registry/use-registry.js +20 -0
- package/src/state/remove-draggable-from-list.js +13 -0
- package/src/state/scroll-viewport.js +34 -0
- package/src/state/spacing.js +45 -0
- package/src/state/store-types.js +16 -0
- package/src/state/update-displacement-visibility/recompute.js +54 -0
- package/src/state/update-displacement-visibility/speculatively-increase.js +111 -0
- package/src/state/visibility/is-partially-visible-through-frame.js +60 -0
- package/src/state/visibility/is-position-in-frame.js +12 -0
- package/src/state/visibility/is-totally-visible-through-frame-on-axis.js +19 -0
- package/src/state/visibility/is-totally-visible-through-frame.js +18 -0
- package/src/state/visibility/is-visible.js +102 -0
- package/src/state/with-scroll-change/with-all-displacement.js +15 -0
- package/src/state/with-scroll-change/with-droppable-displacement.js +13 -0
- package/src/state/with-scroll-change/with-droppable-scroll.js +13 -0
- package/src/state/with-scroll-change/with-viewport-displacement.js +7 -0
- package/src/types.js +542 -0
- package/src/view/animate-in-out/animate-in-out.jsx +95 -0
- package/src/view/animate-in-out/index.js +2 -0
- package/src/view/check-is-valid-inner-ref.js +15 -0
- package/src/view/context/app-context.js +19 -0
- package/src/view/context/droppable-context.js +11 -0
- package/src/view/context/store-context.js +5 -0
- package/src/view/data-attributes.js +37 -0
- package/src/view/drag-drop-context/app.jsx +273 -0
- package/src/view/drag-drop-context/check-doctype.js +39 -0
- package/src/view/drag-drop-context/check-react-version.js +71 -0
- package/src/view/drag-drop-context/drag-drop-context-types.js +7 -0
- package/src/view/drag-drop-context/drag-drop-context.jsx +68 -0
- package/src/view/drag-drop-context/error-boundary.jsx +88 -0
- package/src/view/drag-drop-context/index.js +2 -0
- package/src/view/drag-drop-context/use-startup-validation.js +13 -0
- package/src/view/drag-drop-context/use-unique-context-id.js +13 -0
- package/src/view/draggable/connected-draggable.js +372 -0
- package/src/view/draggable/draggable-api.jsx +48 -0
- package/src/view/draggable/draggable-types.js +191 -0
- package/src/view/draggable/draggable.jsx +171 -0
- package/src/view/draggable/get-style.js +109 -0
- package/src/view/draggable/index.js +2 -0
- package/src/view/draggable/use-validation.js +70 -0
- package/src/view/droppable/connected-droppable.js +280 -0
- package/src/view/droppable/droppable-types.js +91 -0
- package/src/view/droppable/droppable.jsx +167 -0
- package/src/view/droppable/index.js +2 -0
- package/src/view/droppable/use-validation.js +101 -0
- package/src/view/event-bindings/bind-events.js +39 -0
- package/src/view/event-bindings/event-types.js +14 -0
- package/src/view/get-body-element.js +8 -0
- package/src/view/get-border-box-center-position.js +5 -0
- package/src/view/get-document-element.js +8 -0
- package/src/view/get-elements/find-drag-handle.js +38 -0
- package/src/view/get-elements/find-draggable.js +30 -0
- package/src/view/is-strict-equal.js +2 -0
- package/src/view/is-type-of-element/is-element.js +6 -0
- package/src/view/is-type-of-element/is-html-element.js +6 -0
- package/src/view/is-type-of-element/is-svg-element.js +12 -0
- package/src/view/key-codes.js +13 -0
- package/src/view/placeholder/index.js +2 -0
- package/src/view/placeholder/placeholder-types.js +16 -0
- package/src/view/placeholder/placeholder.jsx +198 -0
- package/src/view/scroll-listener.js +72 -0
- package/src/view/throw-if-invalid-inner-ref.js +15 -0
- package/src/view/use-announcer/index.js +2 -0
- package/src/view/use-announcer/use-announcer.js +80 -0
- package/src/view/use-dev-setup-warning.js +22 -0
- package/src/view/use-dev.js +9 -0
- package/src/view/use-draggable-publisher/get-dimension.js +44 -0
- package/src/view/use-draggable-publisher/index.js +2 -0
- package/src/view/use-draggable-publisher/use-draggable-publisher.js +87 -0
- package/src/view/use-droppable-publisher/check-for-nested-scroll-container.js +27 -0
- package/src/view/use-droppable-publisher/get-closest-scrollable.js +95 -0
- package/src/view/use-droppable-publisher/get-dimension.js +139 -0
- package/src/view/use-droppable-publisher/get-env.js +31 -0
- package/src/view/use-droppable-publisher/get-listener-options.js +12 -0
- package/src/view/use-droppable-publisher/get-scroll.js +7 -0
- package/src/view/use-droppable-publisher/index.js +2 -0
- package/src/view/use-droppable-publisher/is-in-fixed-container.js +21 -0
- package/src/view/use-droppable-publisher/use-droppable-publisher.js +283 -0
- package/src/view/use-focus-marshal/focus-marshal-types.js +13 -0
- package/src/view/use-focus-marshal/index.js +2 -0
- package/src/view/use-focus-marshal/use-focus-marshal.js +129 -0
- package/src/view/use-hidden-text-element/index.js +2 -0
- package/src/view/use-hidden-text-element/use-hidden-text-element.js +60 -0
- package/src/view/use-isomorphic-layout-effect.js +18 -0
- package/src/view/use-previous-ref.js +14 -0
- package/src/view/use-required-context.js +9 -0
- package/src/view/use-sensor-marshal/closest.js +50 -0
- package/src/view/use-sensor-marshal/find-closest-draggable-id-from-event.js +50 -0
- package/src/view/use-sensor-marshal/index.js +5 -0
- package/src/view/use-sensor-marshal/is-event-in-interactive-element.js +66 -0
- package/src/view/use-sensor-marshal/lock.js +48 -0
- package/src/view/use-sensor-marshal/sensors/use-keyboard-sensor.js +243 -0
- package/src/view/use-sensor-marshal/sensors/use-mouse-sensor.js +386 -0
- package/src/view/use-sensor-marshal/sensors/use-touch-sensor.js +461 -0
- package/src/view/use-sensor-marshal/sensors/util/prevent-standard-key-events.js +19 -0
- package/src/view/use-sensor-marshal/sensors/util/supported-page-visibility-event-name.js +29 -0
- package/src/view/use-sensor-marshal/use-sensor-marshal.js +495 -0
- package/src/view/use-sensor-marshal/use-validate-sensor-hooks.js +20 -0
- package/src/view/use-style-marshal/get-styles.js +170 -0
- package/src/view/use-style-marshal/index.js +2 -0
- package/src/view/use-style-marshal/style-marshal-types.js +8 -0
- package/src/view/use-style-marshal/use-style-marshal.js +126 -0
- package/src/view/use-unique-id.js +25 -0
- package/src/view/visually-hidden-style.js +16 -0
- package/src/view/window/get-max-window-scroll.js +19 -0
- package/src/view/window/get-viewport.js +49 -0
- package/src/view/window/get-window-from-el.js +3 -0
- package/src/view/window/get-window-scroll.js +30 -0
- package/src/view/window/scroll-window.js +7 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
type Records = {
|
|
3
|
+
[key: string]: number,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const records: Records = {};
|
|
7
|
+
let isEnabled: boolean = false;
|
|
8
|
+
|
|
9
|
+
const isTimingsEnabled = (): boolean => isEnabled;
|
|
10
|
+
|
|
11
|
+
export const forceEnable = () => {
|
|
12
|
+
isEnabled = true;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Debug: uncomment to enable
|
|
16
|
+
// forceEnable();
|
|
17
|
+
|
|
18
|
+
export const start = (key: string) => {
|
|
19
|
+
// we want to strip all the code out for production builds
|
|
20
|
+
// draw back: can only do timings in dev env (which seems to be fine for now)
|
|
21
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
22
|
+
if (!isTimingsEnabled()) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const now: number = performance.now();
|
|
26
|
+
|
|
27
|
+
records[key] = now;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type Style = {|
|
|
32
|
+
textColor: string,
|
|
33
|
+
symbol: string,
|
|
34
|
+
|};
|
|
35
|
+
|
|
36
|
+
export const finish = (key: string) => {
|
|
37
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
38
|
+
if (!isTimingsEnabled()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const now: number = performance.now();
|
|
42
|
+
|
|
43
|
+
const previous: ?number = records[key];
|
|
44
|
+
|
|
45
|
+
if (!previous) {
|
|
46
|
+
// eslint-disable-next-line no-console
|
|
47
|
+
console.warn('cannot finish timing as no previous time found', key);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result: number = now - previous;
|
|
52
|
+
const rounded: string = result.toFixed(2);
|
|
53
|
+
|
|
54
|
+
const style: Style = (() => {
|
|
55
|
+
if (result < 12) {
|
|
56
|
+
return {
|
|
57
|
+
textColor: 'green',
|
|
58
|
+
symbol: '✅',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (result < 40) {
|
|
62
|
+
return {
|
|
63
|
+
textColor: 'orange',
|
|
64
|
+
symbol: '⚠️',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
textColor: 'red',
|
|
69
|
+
symbol: '❌',
|
|
70
|
+
};
|
|
71
|
+
})();
|
|
72
|
+
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.log(
|
|
75
|
+
`${style.symbol} %cTiming %c${rounded} %cms %c${key}`,
|
|
76
|
+
// title
|
|
77
|
+
'color: blue; font-weight: bold;',
|
|
78
|
+
// result
|
|
79
|
+
`color: ${style.textColor}; font-size: 1.1em;`,
|
|
80
|
+
// ms
|
|
81
|
+
'color: grey;',
|
|
82
|
+
// key
|
|
83
|
+
'color: purple; font-weight: bold;',
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
const isProduction: boolean = process.env.NODE_ENV === 'production';
|
|
4
|
+
|
|
5
|
+
// not replacing newlines (which \s does)
|
|
6
|
+
const spacesAndTabs: RegExp = /[ \t]{2,}/g;
|
|
7
|
+
const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
|
|
8
|
+
|
|
9
|
+
// using .trim() to clear the any newlines before the first text and after last text
|
|
10
|
+
const clean = (value: string): string =>
|
|
11
|
+
value.replace(spacesAndTabs, ' ').replace(lineStartWithSpaces, '').trim();
|
|
12
|
+
|
|
13
|
+
const getDevMessage = (message: string): string =>
|
|
14
|
+
clean(`
|
|
15
|
+
%creact-beautiful-dnd
|
|
16
|
+
|
|
17
|
+
%c${clean(message)}
|
|
18
|
+
|
|
19
|
+
%c👷 This is a development only message. It will be removed in production builds.
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
export const getFormattedMessage = (message: string): string[] => [
|
|
23
|
+
getDevMessage(message),
|
|
24
|
+
// title (green400)
|
|
25
|
+
'color: #00C584; font-size: 1.2em; font-weight: bold;',
|
|
26
|
+
// message
|
|
27
|
+
'line-height: 1.5',
|
|
28
|
+
// footer (purple300)
|
|
29
|
+
'color: #723874;',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const isDisabledFlag: string = '__react-beautiful-dnd-disable-dev-warnings';
|
|
33
|
+
|
|
34
|
+
export function log(type: 'error' | 'warn', message: string) {
|
|
35
|
+
// no warnings in production
|
|
36
|
+
if (isProduction) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// manual opt out of warnings
|
|
41
|
+
if (typeof window !== 'undefined' && window[isDisabledFlag]) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console[type](...getFormattedMessage(message));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const warning = log.bind(null, 'warn');
|
|
50
|
+
export const error = log.bind(null, 'error');
|
package/src/empty.js
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
// Components
|
|
4
|
+
|
|
5
|
+
export { default as DragDropContext } from './view/drag-drop-context';
|
|
6
|
+
export { default as Droppable } from './view/droppable';
|
|
7
|
+
export { default as Draggable } from './view/draggable';
|
|
8
|
+
|
|
9
|
+
// Default sensors
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
useMouseSensor,
|
|
13
|
+
useTouchSensor,
|
|
14
|
+
useKeyboardSensor,
|
|
15
|
+
} from './view/use-sensor-marshal';
|
|
16
|
+
|
|
17
|
+
// Utils
|
|
18
|
+
|
|
19
|
+
export { resetServerContext } from './view/drag-drop-context';
|
|
20
|
+
|
|
21
|
+
// Public flow types
|
|
22
|
+
|
|
23
|
+
export type {
|
|
24
|
+
Id,
|
|
25
|
+
TypeId,
|
|
26
|
+
DraggableId,
|
|
27
|
+
DroppableId,
|
|
28
|
+
DraggableRubric,
|
|
29
|
+
MovementMode,
|
|
30
|
+
BeforeCapture,
|
|
31
|
+
DragStart,
|
|
32
|
+
DragUpdate,
|
|
33
|
+
DropResult,
|
|
34
|
+
Direction,
|
|
35
|
+
ResponderProvided,
|
|
36
|
+
Announce,
|
|
37
|
+
DraggableLocation,
|
|
38
|
+
OnBeforeCaptureResponder,
|
|
39
|
+
OnBeforeDragStartResponder,
|
|
40
|
+
OnDragStartResponder,
|
|
41
|
+
OnDragUpdateResponder,
|
|
42
|
+
OnDragEndResponder,
|
|
43
|
+
SensorAPI,
|
|
44
|
+
Sensor,
|
|
45
|
+
TryGetLock,
|
|
46
|
+
TryGetLockOptions,
|
|
47
|
+
} from './types';
|
|
48
|
+
|
|
49
|
+
// Droppable types
|
|
50
|
+
export type {
|
|
51
|
+
Provided as DroppableProvided,
|
|
52
|
+
StateSnapshot as DroppableStateSnapshot,
|
|
53
|
+
DroppableProps,
|
|
54
|
+
} from './view/droppable/droppable-types';
|
|
55
|
+
|
|
56
|
+
// Draggable types
|
|
57
|
+
export type {
|
|
58
|
+
Provided as DraggableProvided,
|
|
59
|
+
StateSnapshot as DraggableStateSnapshot,
|
|
60
|
+
DragHandleProps,
|
|
61
|
+
DropAnimation,
|
|
62
|
+
DraggableProps,
|
|
63
|
+
DraggableStyle,
|
|
64
|
+
DraggingStyle,
|
|
65
|
+
NotDraggingStyle,
|
|
66
|
+
ChildrenFn as DraggableChildrenFn,
|
|
67
|
+
} from './view/draggable/draggable-types';
|
package/src/invariant.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
const isProduction: boolean = process.env.NODE_ENV === 'production';
|
|
4
|
+
const prefix: string = 'Invariant failed';
|
|
5
|
+
|
|
6
|
+
// Want to use this:
|
|
7
|
+
// export class RbdInvariant extends Error { }
|
|
8
|
+
// But it causes babel to bring in a lot of code
|
|
9
|
+
|
|
10
|
+
export function RbdInvariant(message: string) {
|
|
11
|
+
this.message = message;
|
|
12
|
+
}
|
|
13
|
+
// $FlowFixMe
|
|
14
|
+
RbdInvariant.prototype.toString = function toString() {
|
|
15
|
+
return this.message;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// A copy-paste of tiny-invariant but with a custom error type
|
|
19
|
+
// Throw an error if the condition fails
|
|
20
|
+
export function invariant(condition: mixed, message?: string) {
|
|
21
|
+
if (condition) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isProduction) {
|
|
26
|
+
// In production we strip the message but still throw
|
|
27
|
+
throw new RbdInvariant(prefix);
|
|
28
|
+
} else {
|
|
29
|
+
// When not in production we allow the message to pass through
|
|
30
|
+
// *This block will be removed in production builds*
|
|
31
|
+
throw new RbdInvariant(`${prefix}: ${message || ''}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
/* eslint-disable es5/no-es6-methods */
|
|
3
|
+
/* eslint-disable es5/no-es6-static-methods */
|
|
4
|
+
/* eslint-disable no-restricted-globals */
|
|
5
|
+
|
|
6
|
+
type Map<T> = {
|
|
7
|
+
[key: string]: T,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function isInteger(value: mixed): boolean {
|
|
11
|
+
if (Number.isInteger) {
|
|
12
|
+
return Number.isInteger(value);
|
|
13
|
+
}
|
|
14
|
+
return (
|
|
15
|
+
typeof value === 'number' && isFinite(value) && Math.floor(value) === value
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Using this helper to ensure there are correct flow types
|
|
20
|
+
// https://github.com/facebook/flow/issues/2221
|
|
21
|
+
export function values<T>(map: Map<T>): T[] {
|
|
22
|
+
if (Object.values) {
|
|
23
|
+
// $FlowFixMe - Object.values currently does not have good flow support
|
|
24
|
+
return Object.values(map);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Object.keys(map).map((key) => map[key]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Could also extend to pass index and list
|
|
31
|
+
type PredicateFn<T> = (value: T) => boolean;
|
|
32
|
+
|
|
33
|
+
// TODO: swap order
|
|
34
|
+
export function findIndex<T>(
|
|
35
|
+
list: Array<T>,
|
|
36
|
+
predicate: PredicateFn<T>,
|
|
37
|
+
): number {
|
|
38
|
+
if (list.findIndex) {
|
|
39
|
+
return list.findIndex(predicate);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Using a for loop so that we can exit early
|
|
43
|
+
for (let i = 0; i < list.length; i++) {
|
|
44
|
+
if (predicate(list[i])) {
|
|
45
|
+
return i;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Array.prototype.find returns -1 when nothing is found
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function find<T>(list: Array<T>, predicate: PredicateFn<T>): ?T {
|
|
53
|
+
if (list.find) {
|
|
54
|
+
return list.find(predicate);
|
|
55
|
+
}
|
|
56
|
+
const index: number = findIndex(list, predicate);
|
|
57
|
+
if (index !== -1) {
|
|
58
|
+
return list[index];
|
|
59
|
+
}
|
|
60
|
+
// Array.prototype.find returns undefined when nothing is found
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Using this rather than Array.from as Array.from adds 2kb to the gzip
|
|
65
|
+
// document.querySelector actually returns Element[], but flow thinks it is HTMLElement[]
|
|
66
|
+
// So we downcast the result to Element[]
|
|
67
|
+
export function toArray(list: NodeList<HTMLElement>): Element[] {
|
|
68
|
+
return Array.prototype.slice.call(list);
|
|
69
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
DraggableId,
|
|
4
|
+
DragStart,
|
|
5
|
+
DragUpdate,
|
|
6
|
+
DropResult,
|
|
7
|
+
DraggableLocation,
|
|
8
|
+
Combine,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
export type MessagePreset = {|
|
|
12
|
+
dragHandleUsageInstructions: string,
|
|
13
|
+
onDragStart: (start: DragStart) => string,
|
|
14
|
+
onDragUpdate: (update: DragUpdate) => string,
|
|
15
|
+
onDragEnd: (result: DropResult) => string,
|
|
16
|
+
|};
|
|
17
|
+
|
|
18
|
+
const dragHandleUsageInstructions: string = `
|
|
19
|
+
Press space bar to start a drag.
|
|
20
|
+
When dragging you can use the arrow keys to move the item around and escape to cancel.
|
|
21
|
+
Some screen readers may require you to be in focus mode or to use your pass through key
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const position = (index: number): number => index + 1;
|
|
25
|
+
|
|
26
|
+
// We cannot list what index the Droppable is in automatically as we are not sure how
|
|
27
|
+
// the Droppable's have been configured
|
|
28
|
+
const onDragStart = (start: DragStart): string => `
|
|
29
|
+
You have lifted an item in position ${position(start.source.index)}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const withLocation = (
|
|
33
|
+
source: DraggableLocation,
|
|
34
|
+
destination: DraggableLocation,
|
|
35
|
+
) => {
|
|
36
|
+
const isInHomeList: boolean = source.droppableId === destination.droppableId;
|
|
37
|
+
|
|
38
|
+
const startPosition: number = position(source.index);
|
|
39
|
+
const endPosition: number = position(destination.index);
|
|
40
|
+
|
|
41
|
+
if (isInHomeList) {
|
|
42
|
+
return `
|
|
43
|
+
You have moved the item from position ${startPosition}
|
|
44
|
+
to position ${endPosition}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `
|
|
49
|
+
You have moved the item from position ${startPosition}
|
|
50
|
+
in list ${source.droppableId}
|
|
51
|
+
to list ${destination.droppableId}
|
|
52
|
+
in position ${endPosition}
|
|
53
|
+
`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const withCombine = (
|
|
57
|
+
id: DraggableId,
|
|
58
|
+
source: DraggableLocation,
|
|
59
|
+
combine: Combine,
|
|
60
|
+
): string => {
|
|
61
|
+
const inHomeList: boolean = source.droppableId === combine.droppableId;
|
|
62
|
+
|
|
63
|
+
if (inHomeList) {
|
|
64
|
+
return `
|
|
65
|
+
The item ${id}
|
|
66
|
+
has been combined with ${combine.draggableId}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return `
|
|
70
|
+
The item ${id}
|
|
71
|
+
in list ${source.droppableId}
|
|
72
|
+
has been combined with ${combine.draggableId}
|
|
73
|
+
in list ${combine.droppableId}
|
|
74
|
+
`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const onDragUpdate = (update: DragUpdate): string => {
|
|
78
|
+
const location: ?DraggableLocation = update.destination;
|
|
79
|
+
if (location) {
|
|
80
|
+
return withLocation(update.source, location);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const combine: ?Combine = update.combine;
|
|
84
|
+
if (combine) {
|
|
85
|
+
return withCombine(update.draggableId, update.source, combine);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return 'You are over an area that cannot be dropped on';
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const returnedToStart = (source: DraggableLocation): string => `
|
|
92
|
+
The item has returned to its starting position
|
|
93
|
+
of ${position(source.index)}
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
const onDragEnd = (result: DropResult): string => {
|
|
97
|
+
if (result.reason === 'CANCEL') {
|
|
98
|
+
return `
|
|
99
|
+
Movement cancelled.
|
|
100
|
+
${returnedToStart(result.source)}
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const location: ?DraggableLocation = result.destination;
|
|
105
|
+
const combine: ?Combine = result.combine;
|
|
106
|
+
|
|
107
|
+
if (location) {
|
|
108
|
+
return `
|
|
109
|
+
You have dropped the item.
|
|
110
|
+
${withLocation(result.source, location)}
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (combine) {
|
|
115
|
+
return `
|
|
116
|
+
You have dropped the item.
|
|
117
|
+
${withCombine(result.draggableId, result.source, combine)}
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return `
|
|
122
|
+
The item has been dropped while not over a drop area.
|
|
123
|
+
${returnedToStart(result.source)}
|
|
124
|
+
`;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const preset: MessagePreset = {
|
|
128
|
+
dragHandleUsageInstructions,
|
|
129
|
+
onDragStart,
|
|
130
|
+
onDragUpdate,
|
|
131
|
+
onDragEnd,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default preset;
|