@kwiz/fluentui 1.0.78 → 1.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +53 -53
  3. package/dist/controls/svg.js +21 -21
  4. package/dist/controls/svg.js.map +1 -1
  5. package/package.json +85 -85
  6. package/.dependency-cruiser.js +0 -399
  7. package/.github/workflows/npm-publish.yml +0 -24
  8. package/dist/@types/forwardRef.d.ts +0 -0
  9. package/dist/@types/forwardRef.js +0 -1
  10. package/dist/@types/forwardRef.js.map +0 -1
  11. package/dist/controls/error-boundary copy.d.ts +0 -23
  12. package/dist/controls/error-boundary copy.js +0 -33
  13. package/dist/controls/error-boundary copy.js.map +0 -1
  14. package/dist/helpers/common.d.ts +0 -4
  15. package/dist/helpers/common.js +0 -2
  16. package/dist/helpers/common.js.map +0 -1
  17. package/dist/helpers/context.d.ts +0 -26
  18. package/dist/helpers/context.js +0 -15
  19. package/dist/helpers/context.js.map +0 -1
  20. package/dist/helpers/drag-drop/exports.d.ts +0 -12
  21. package/dist/helpers/drag-drop/exports.js +0 -3
  22. package/dist/helpers/drag-drop/exports.js.map +0 -1
  23. package/dist/helpers/exports.d.ts +0 -7
  24. package/dist/helpers/exports.js +0 -8
  25. package/dist/helpers/exports.js.map +0 -1
  26. package/src/_modules/config.ts +0 -9
  27. package/src/_modules/constants.ts +0 -3
  28. package/src/controls/ColorPickerDialog.tsx +0 -84
  29. package/src/controls/accordion.tsx +0 -62
  30. package/src/controls/button.tsx +0 -181
  31. package/src/controls/canvas/CustomEventTargetBase.ts +0 -33
  32. package/src/controls/canvas/DrawPad.tsx +0 -297
  33. package/src/controls/canvas/DrawPadManager.ts +0 -695
  34. package/src/controls/canvas/bezier.ts +0 -110
  35. package/src/controls/canvas/point.ts +0 -45
  36. package/src/controls/card-list.tsx +0 -32
  37. package/src/controls/card.tsx +0 -78
  38. package/src/controls/centered.tsx +0 -15
  39. package/src/controls/date.tsx +0 -88
  40. package/src/controls/diagram-picker.tsx +0 -97
  41. package/src/controls/divider.tsx +0 -16
  42. package/src/controls/dropdown.tsx +0 -67
  43. package/src/controls/error-boundary.tsx +0 -42
  44. package/src/controls/field-editor.tsx +0 -43
  45. package/src/controls/file-upload.tsx +0 -156
  46. package/src/controls/horizontal.tsx +0 -49
  47. package/src/controls/html-editor/editor.tsx +0 -182
  48. package/src/controls/index.ts +0 -33
  49. package/src/controls/input.tsx +0 -161
  50. package/src/controls/kwizoverflow.tsx +0 -107
  51. package/src/controls/list.tsx +0 -120
  52. package/src/controls/loading.tsx +0 -11
  53. package/src/controls/menu.tsx +0 -196
  54. package/src/controls/merge-text.tsx +0 -126
  55. package/src/controls/please-wait.tsx +0 -33
  56. package/src/controls/progress-bar.tsx +0 -110
  57. package/src/controls/prompt.tsx +0 -122
  58. package/src/controls/qrcode.tsx +0 -37
  59. package/src/controls/search.tsx +0 -72
  60. package/src/controls/section.tsx +0 -134
  61. package/src/controls/svg.tsx +0 -139
  62. package/src/controls/toolbar.tsx +0 -47
  63. package/src/controls/vertical-content.tsx +0 -50
  64. package/src/controls/vertical.tsx +0 -43
  65. package/src/helpers/block-nav.tsx +0 -89
  66. package/src/helpers/context-const.ts +0 -30
  67. package/src/helpers/context-export.tsx +0 -78
  68. package/src/helpers/context-internal.ts +0 -14
  69. package/src/helpers/drag-drop/drag-drop-container.tsx +0 -54
  70. package/src/helpers/drag-drop/drag-drop-context-internal.tsx +0 -10
  71. package/src/helpers/drag-drop/drag-drop-context.tsx +0 -62
  72. package/src/helpers/drag-drop/drag-drop.types.ts +0 -21
  73. package/src/helpers/drag-drop/index.ts +0 -12
  74. package/src/helpers/drag-drop/readme.md +0 -76
  75. package/src/helpers/drag-drop/use-draggable.ts +0 -48
  76. package/src/helpers/drag-drop/use-droppable.ts +0 -39
  77. package/src/helpers/forwardRef.ts +0 -7
  78. package/src/helpers/hooks-events.ts +0 -150
  79. package/src/helpers/hooks.tsx +0 -175
  80. package/src/helpers/index.ts +0 -8
  81. package/src/helpers/use-alerts.tsx +0 -75
  82. package/src/helpers/use-editable-control.tsx +0 -38
  83. package/src/helpers/use-toast.tsx +0 -30
  84. package/src/index.ts +0 -3
  85. package/src/styles/index.ts +0 -1
  86. package/src/styles/styles.ts +0 -105
  87. package/src/styles/theme.ts +0 -91
@@ -1,89 +0,0 @@
1
- import { IDictionary, isNotEmptyArray, isNullOrEmptyString, jsonClone, objectsEqual } from "@kwiz/common";
2
- import { useCallback, useEffect } from "react";
3
- import { IPrompterProps, Prompter } from "../controls/prompt";
4
- import { useEffectOnlyOnMount, useStateEX } from "./hooks";
5
-
6
- export interface iBlockNav {
7
- setMessage: (id: string, message?: string) => void;
8
- onNav: (nav: () => void) => void;
9
- navPrompt?: JSX.Element;
10
-
11
- }
12
- /** set block message if you want to block nav.
13
- * - call setMessage to add a blocker message
14
- * - call onNav when you have internal navigation (open / close popups)
15
- * - render the navPrompt control to your page
16
- * FYI for page unload, most modern browsers won't show your message but a generic one instead. */
17
- export function useBlockNav(): iBlockNav {
18
- const [, setBlockNavMessages, blockNavMessagesRef] = useStateEX<IDictionary<string>>({});
19
- const [_prompt, setPrompt] = useStateEX<IPrompterProps>(null);
20
-
21
- const getMessagesArr = useCallback(() => {
22
- return Object.keys(blockNavMessagesRef.current).map(id => blockNavMessagesRef.current[id]);
23
- }, useEffectOnlyOnMount);
24
-
25
- const getMessages = useCallback(() => {
26
- return getMessagesArr().join();
27
- }, useEffectOnlyOnMount);
28
-
29
- const onNav = useCallback((nav: () => void) => {
30
- let messages = getMessagesArr();
31
- if (isNotEmptyArray(messages)) {
32
- //need to release react to re-render the prompt
33
- window.setTimeout(() => {
34
- //prompt, if ok - clear messages and nav.
35
- setPrompt({
36
- okButtonText: "Leave",
37
- cancelButtonText: "Cancel",
38
- title: "Leave page?",
39
- children: messages.length > 1
40
- ? <ul>
41
- {messages.map((m, i) => <li key={`m${i}`}>{m}</li>)}
42
- </ul>
43
- : <p>{messages[0]}</p>,
44
- onCancel: () => setPrompt(null),
45
- onOK: () => {
46
- setPrompt(null);
47
- setBlockNavMessages({});//clear messages
48
- nav();
49
- }
50
- });
51
- }, 1);
52
- }
53
- else nav();
54
- }, useEffectOnlyOnMount);
55
-
56
-
57
- useEffect(() => {
58
- function handleBeforeUnload(e: BeforeUnloadEvent) {
59
- //todo: use blockMessageRef.current so that we don't have to re-register every time message changes.
60
- //otherwise we would have to add blockMessage as a dependency for this useEffect
61
- const message = getMessages();
62
- if (!isNullOrEmptyString(message)) {
63
- e.preventDefault();
64
- e.returnValue = message;
65
- }
66
- }
67
- // Add event listener
68
- window.addEventListener("beforeunload", handleBeforeUnload);
69
- // Remove event listener on cleanup
70
- return () => window.removeEventListener("beforeunload", handleBeforeUnload);
71
- }, useEffectOnlyOnMount);
72
- return {
73
- setMessage: (id: string, message?: string) => {
74
- let current = jsonClone(blockNavMessagesRef.current);
75
- if (isNullOrEmptyString(message))
76
- delete current[id];
77
- else current[id] = message;
78
- if (!objectsEqual(current, blockNavMessagesRef.current))
79
- setBlockNavMessages(current);
80
- },
81
- // clearMessages: () => {
82
- // setBlockNavMessages({});
83
- // },
84
- // getMessages,
85
- // getMessagesArr,
86
- onNav,
87
- navPrompt: _prompt ? <Prompter {..._prompt} /> : undefined
88
- };
89
- }
@@ -1,30 +0,0 @@
1
- import React from "react";
2
- export interface iKWIZFluentContext {
3
- /**
4
- * Where the portal children are mounted on DOM
5
- *
6
- * @default a new element on document.body without any styling
7
- */
8
- mountNode?: HTMLElement | null | {
9
- element?: HTMLElement | null;
10
- className?: string;
11
- }
12
- /**
13
- * Controls the colors and borders of the input.
14
- *
15
- * @default 'underline'
16
- */
17
- inputAppearance?: 'outline' | 'underline' | 'filled-darker' | 'filled-lighter';
18
-
19
- /**
20
- * A button can be rounded, circular, or square.
21
- *
22
- * @default 'rounded'
23
- */
24
- buttonShape?: 'rounded' | 'circular' | 'square';
25
- /** true if using dark theme */
26
- dark?: boolean;
27
- }
28
-
29
- //create context
30
- export const KWIZFluentContext = React.createContext<iKWIZFluentContext>(null);
@@ -1,78 +0,0 @@
1
- import { makeStaticStyles, makeStyles, tokens } from "@fluentui/react-components";
2
- import React, { PropsWithChildren, useEffect, useState } from "react";
3
- import { GetLogger } from "../_modules/config";
4
- import { KnownClassNames } from "../styles";
5
- import { iKWIZFluentContext, KWIZFluentContext } from "./context-const";
6
- import { DragDropContextProvider } from "./drag-drop";
7
- export type { iKWIZFluentContext } from "./context-const";
8
- const logger = GetLogger("KWIZFluentContextProvider");
9
- const useContextStyles = makeStyles({
10
- root: {
11
- "& *": {
12
- scrollbarWidth: "thin",
13
- //if we can make sure this applies only to fui-FluentProvider, do this too, since public forms might take over the entire page we don't want to to affect other sites:
14
- //maybe make KWIZFluentProvider automatically wrap in a root and apply to it
15
- //scrollbarColor: `${tokens.colorBrandForeground2} ${tokens.colorBrandBackground2}`
16
- },
17
- [`& .${KnownClassNames.printShow}`]: {
18
- '@media print': {
19
- display: 'unset',
20
- }
21
- },
22
- [`& .${KnownClassNames.printHide}`]: {
23
- '@media print': {
24
- display: 'none !important'
25
- }
26
- },
27
- },
28
- });
29
- export const useStaticStyles = makeStaticStyles({
30
- [`.${KnownClassNames.printShow}`]: {
31
- display: 'none'
32
- },
33
- [`body.${KnownClassNames.print} .${KnownClassNames.printHide}`]: {
34
- display: "none !important"
35
- },
36
- [`body.${KnownClassNames.print} .${KnownClassNames.printShow}`]: {
37
- display: "unset"
38
- }
39
- });
40
-
41
- /** @deprecated - use KWIZFluentProvider instead of using this + DragDropContextProvider */
42
- export function useKWIZFluentContextProvider(options: {
43
- root?: React.MutableRefObject<HTMLDivElement>;
44
- ctx?: iKWIZFluentContext;
45
- }) {
46
- useStaticStyles();
47
- const classes = useContextStyles();
48
- let v: iKWIZFluentContext = options && options.ctx || {};
49
- const [kwizFluentContext, setKwizFluentContext] = useState<iKWIZFluentContext>(v);
50
- useEffect(() => {
51
- if (options.root?.current) logger.warn('Sending a root node is not recommended, if you have set up your packages correctly to mark react and fluent UI as external dialogs should open correctly.');
52
- let styleRoot = options.root?.current || document.body;
53
- styleRoot.classList.add(...classes.root.split(' '));
54
- // ref only updates in useEffect, not in useMemo or anything else.
55
- // we need to set it into state so it will trigger a ui update
56
- setKwizFluentContext({
57
- ...v,
58
- mountNode: options.root?.current
59
- });
60
- }, [options.root]);
61
- return {
62
- KWIZFluentContext,
63
- value: kwizFluentContext
64
- };
65
- }
66
-
67
- export const KWIZFluentProvider = (props: PropsWithChildren<{
68
- ctx?: iKWIZFluentContext;
69
- }>) => {
70
-
71
- const cp = useKWIZFluentContextProvider({ ctx: props.ctx });
72
-
73
- return <cp.KWIZFluentContext.Provider value={cp.value}>
74
- <DragDropContextProvider>
75
- {props.children}
76
- </DragDropContextProvider>
77
- </cp.KWIZFluentContext.Provider>;
78
- }
@@ -1,14 +0,0 @@
1
- import { isNullOrUndefined } from "@kwiz/common";
2
- import React from "react";
3
- import { KWIZFluentContext } from "./context-const";
4
-
5
- //use context from within controls
6
- export function useKWIZFluentContext() {
7
- let ctx = React.useContext(KWIZFluentContext) || {};
8
- //set defaults
9
- if (isNullOrUndefined(ctx.inputAppearance))
10
- ctx.inputAppearance = "underline";
11
- if (isNullOrUndefined(ctx.buttonShape))
12
- ctx.buttonShape = "circular";
13
- return ctx;
14
- }
@@ -1,54 +0,0 @@
1
- import { mergeClasses } from "@fluentui/react-components";
2
- import { useDragDropContext } from "./drag-drop-context";
3
- import { iDraggableProps, iDraggedItemType, iDroppableProps } from "./drag-drop.types";
4
-
5
- interface one<DragItemType extends iDraggedItemType<string>> {
6
- dragInfo: iDraggableProps<DragItemType>;
7
- }
8
- interface other<
9
- DropInfoTypes extends string = never,
10
- DropInfoItemTypes extends iDraggedItemType<DropInfoTypes> = never,
11
- > {
12
- dropInfo: iDroppableProps<DropInfoTypes, DropInfoItemTypes>;
13
- }
14
- type iDragDropProps<
15
- DragItemType extends iDraggedItemType<string>,
16
- DropInfoTypes extends string = never,
17
- DropInfoItemTypes extends iDraggedItemType<DropInfoTypes> = never,
18
- > = one<DragItemType> & Partial<other<DropInfoTypes, DropInfoItemTypes>>
19
- | Partial<one<DragItemType>> & other<DropInfoTypes, DropInfoItemTypes>
20
- | (one<DragItemType> & other<DropInfoTypes, DropInfoItemTypes>);
21
-
22
- type iProps<DragItemType extends iDraggedItemType<string>, DropInfoTypes extends string, DropInfoItemTypes extends iDraggedItemType<DropInfoTypes>> =
23
- //all DIV props, except ref - we need ref.
24
- Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">
25
- //pass drag class names
26
- & {
27
- onDraggingClassName?: string;
28
- onDragOverClassName?: string;
29
- }
30
- //drag/drop info
31
- & iDragDropProps<DragItemType, DropInfoTypes, DropInfoItemTypes>
32
-
33
- export function DragDropContainer<
34
- DragItemType extends iDraggedItemType<string> = never,
35
- DropInfoTypes extends string = never,
36
- DropInfoItemTypes extends iDraggedItemType<DropInfoTypes> = never
37
- >(props: React.PropsWithChildren<iProps<DragItemType, DropInfoTypes, DropInfoItemTypes>>) {
38
-
39
- const { drag, drop, dragDropRef } = useDragDropContext(props);
40
-
41
- const classNames: string[] = [];
42
- if (drag.isDragging && props.onDraggingClassName) classNames.push(props.onDraggingClassName);
43
- if (drop.isOver && props.onDragOverClassName) classNames.push(props.onDragOverClassName);
44
-
45
- const propsWithoutExtras = {
46
- ...props
47
- };
48
- delete propsWithoutExtras.dragInfo;
49
- delete propsWithoutExtras.dropInfo;
50
- delete propsWithoutExtras.onDraggingClassName;
51
- delete propsWithoutExtras.onDragOverClassName;
52
-
53
- return <div {...propsWithoutExtras} ref={dragDropRef} className={mergeClasses(...classNames, props.className)}>{props.children}</div>;
54
- }
@@ -1,10 +0,0 @@
1
- import React, { useContext } from "react";
2
- import { iDragDropContext } from "./drag-drop.types";
3
-
4
- //create context
5
- export const DragDropContext = React.createContext<iDragDropContext>(null);
6
- //use context from within controls
7
- export function useDragDropContextInternal() {
8
- const dragDropContext = useContext(DragDropContext);
9
- return dragDropContext;
10
- }
@@ -1,62 +0,0 @@
1
- import { isNullOrUndefined } from "@kwiz/common";
2
- import React from "react";
3
- import { DndProvider } from "react-dnd";
4
- import { HTML5Backend } from "react-dnd-html5-backend";
5
- import { useStateEX } from "../hooks";
6
- import { DragDropContext, useDragDropContextInternal } from "./drag-drop-context-internal";
7
- import { iDragDropContext, iDraggableProps, iDraggedItemType, iDroppableProps } from "./drag-drop.types";
8
- import { useDraggable } from "./use-draggable";
9
- import { useDroppable } from "./use-droppable";
10
-
11
- export function useDragDropContext<
12
- DragItemType extends iDraggedItemType<string> = never,
13
- DropInfoType extends iDroppableProps<string, any> = never
14
- >(info: {
15
- dragInfo?: iDraggableProps<DragItemType>;
16
- dropInfo?: DropInfoType;
17
- }) {
18
- const dragDropContext = useDragDropContextInternal();
19
- const isDraggable = !isNullOrUndefined(info.dragInfo);
20
- const isDroppable = !isNullOrUndefined(info.dropInfo);
21
- const drag = useDraggable(info?.dragInfo);
22
- const drop = useDroppable(info?.dropInfo);
23
- const expectingDrop = isDroppable && !drag.isDragging && dragDropContext.isDragging
24
- //check if item being dragged is allowed in this context...
25
- && info.dropInfo.acceptTypes.indexOf(dragDropContext.dragItem.type) >= 0;
26
-
27
- return {
28
- dragDropContext,
29
- drag,
30
- drop,
31
- /** an item that this control can handler is being dragged */
32
- expectingDrop,
33
- dragDropRef: isDraggable && !isDroppable
34
- ? drag.dragRef
35
- : !isDraggable && isDroppable
36
- ? drop.dropRef
37
- //both drag and drop allowed
38
- : expectingDrop ? drop.dropRef : drag.dragRef
39
- };
40
- }
41
- export function useDragDropContextProvider(): iDragDropContext {
42
- const [dragItem, setDragItem] = useStateEX<iDraggedItemType<string>>(null);
43
-
44
- //build context
45
- const ctx: iDragDropContext = {
46
- isDragging: !isNullOrUndefined(dragItem),
47
- dragItem, setDragItem
48
- };
49
-
50
- return ctx;
51
- }
52
-
53
- interface iProps {
54
- }
55
- export const DragDropContextProvider: React.FunctionComponent<React.PropsWithChildren<iProps>> = (props) => {
56
- const provider = useDragDropContextProvider();
57
- return <DragDropContext.Provider value={provider}>
58
- <DndProvider backend={HTML5Backend} context={window}>
59
- {props.children}
60
- </DndProvider>
61
- </DragDropContext.Provider>;
62
- }
@@ -1,21 +0,0 @@
1
- export interface iDraggedItemType<DragType extends string> {
2
- type: DragType;
3
- }
4
- export interface iDraggableProps<ItemType extends iDraggedItemType<string>> {
5
- item: ItemType;
6
- onBeginDrag?: () => void;
7
- onEndDrag?: (dropResult: any) => void;
8
- }
9
-
10
- export interface iDroppableProps<DropTypes extends string, ItemTypes extends iDraggedItemType<DropTypes>> {
11
- acceptTypes: DropTypes[];
12
- onItemDrop: (item: ItemTypes) => void;
13
- onHover?: (item: ItemTypes) => void;
14
- onDrop?: () => void;
15
- }
16
-
17
- export interface iDragDropContext {
18
- isDragging: boolean;
19
- dragItem: iDraggedItemType<string>;
20
- setDragItem: (value: iDraggedItemType<string>) => void;
21
- }
@@ -1,12 +0,0 @@
1
- import { NativeTypes } from 'react-dnd-html5-backend';
2
- import { iDraggedItemType, iDroppableProps } from './drag-drop.types';
3
-
4
- export { DragDropContainer } from './drag-drop-container';
5
- export { DragDropContextProvider, useDragDropContext } from "./drag-drop-context";
6
- export type { iDraggedItemType, iDroppableProps } from "./drag-drop.types";
7
-
8
- type fileNativeType = typeof NativeTypes.FILE;
9
- interface dragFiles extends iDraggedItemType<fileNativeType> {
10
- files: FileList;
11
- }
12
- export type dropFiles = iDroppableProps<fileNativeType, dragFiles>;
@@ -1,76 +0,0 @@
1
- Use drag drop with types examples:
2
-
3
- Wrap everything within drag/drop context:
4
- ```tsx
5
- <DragDropContextProvider>
6
- ...
7
- </DragDropContextProvider>
8
- ```
9
-
10
- Define the types you want to allow drag/drop:
11
- ```tsx
12
- export type dragColumnType = "column";
13
- export type dragCellType = "cell";
14
- export interface dragColumn extends iDraggedItemType<dragColumnType> {
15
- data: iDesignerContextFields
16
- }
17
-
18
- export interface dragCell extends iDraggedItemType<dragCellType> {
19
- row: number;
20
- cell: number;
21
- }
22
- export interface dropCellOrColumn extends iDroppableProps<dragColumnType | dragCellType, dragColumn | dragCell> {
23
- }
24
- ```
25
-
26
- use within a control:
27
- ```tsx
28
- const { drag, drop, dragDropRef } = useDragDropContext<
29
- dragCell, dropCellOrColumn
30
- >({
31
- dragInfo: {
32
- item: {
33
- type: "cell",
34
- cell: props.index,
35
- row: props.rowIndex
36
- },
37
- },
38
- dropInfo: {
39
- acceptTypes: ["cell", "column"],
40
- onItemDrop: item => {
41
- switch (item.type) {
42
- case "cell":
43
- alert(item.cell);
44
- break;
45
- case "column":
46
- alert(item.data.title);
47
- break;
48
- }
49
- }
50
- }
51
- });
52
-
53
- ...
54
-
55
- <Section css={[
56
- drop.isOver && classes.hover,
57
- drag.isDragging && classes.dragging
58
- ]}
59
- ref={dragDropRef}>
60
- ...
61
- </Section>
62
- ```
63
-
64
- Use with a wrapper:
65
-
66
- ```tsx
67
- <DragDropContainer<dragColumn>
68
- dragInfo={{
69
- item: {
70
- type: "column",
71
- data: f
72
- }
73
- }}>
74
- <ButtonEX ... />
75
- </DragDropContainer>
76
- ```
@@ -1,48 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { ConnectDragSource, DragSourceMonitor, useDrag } from 'react-dnd';
3
- import { useDragDropContextInternal } from './drag-drop-context-internal';
4
- import { iDraggableProps, iDraggedItemType } from './drag-drop.types';
5
-
6
- export function useDraggable<ItemType extends iDraggedItemType<string>>(props?: iDraggableProps<ItemType>): {
7
- isDragging: boolean;
8
- dragRef: ConnectDragSource
9
- } {
10
- const {
11
- item,
12
- onBeginDrag,
13
- onEndDrag,
14
- } = props || {
15
- item: {
16
- type: "~invalid~"
17
- }
18
- };
19
-
20
- const dragDropContext = useDragDropContextInternal();
21
-
22
- const [{ isDragging }, dragRef] = useDrag(
23
- () => ({
24
- type: item.type,
25
- item,
26
- collect: (monitor: DragSourceMonitor) => ({
27
- isDragging: monitor.isDragging(),
28
- }),
29
- end: (item, monitor) => {
30
- dragDropContext.setDragItem(null);
31
- onEndDrag && onEndDrag(monitor.getDropResult());
32
- },
33
- }),
34
- [item, item.type]
35
- );
36
-
37
- useEffect(() => {
38
- if (isDragging) {
39
- dragDropContext.setDragItem(item);
40
- onBeginDrag && onBeginDrag();
41
- }
42
- }, [isDragging, onBeginDrag])
43
-
44
- return {
45
- isDragging,
46
- dragRef,
47
- };
48
- }
@@ -1,39 +0,0 @@
1
- import { ConnectDropTarget, DropTargetMonitor, useDrop } from 'react-dnd';
2
- import { iDraggedItemType, iDroppableProps } from './drag-drop.types';
3
-
4
- export function useDroppable<DropType extends string, ItemType extends iDraggedItemType<DropType>>(props?: iDroppableProps<DropType, ItemType>): {
5
- canDrop: boolean;
6
- isOver: boolean;
7
- dropRef: ConnectDropTarget;
8
- } {
9
- const {
10
- acceptTypes,
11
- onItemDrop,
12
- onHover,
13
- onDrop,
14
- } = props || {
15
- acceptTypes: [],
16
- onItemDrop: () => { }
17
- };
18
-
19
- const [{ canDrop, isOver }, dropRef] = useDrop({
20
- accept: acceptTypes,
21
- drop: (item: ItemType) => {
22
- onItemDrop(item);
23
- onDrop?.();
24
- },
25
- hover: (item: ItemType) => {
26
- onHover?.(item);
27
- },
28
- collect: (monitor: DropTargetMonitor) => ({
29
- canDrop: monitor.canDrop(),
30
- isOver: monitor.isOver(),
31
- }),
32
- });
33
-
34
- return {
35
- canDrop,
36
- isOver,
37
- dropRef,
38
- };
39
- }
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- //need to redeclare to support forward ref with generic types
3
- declare module "react" {
4
- function forwardRef<T, P = {}>(
5
- render: (props: P, ref: React.Ref<T>) => React.JSX.Element | null
6
- ): (props: P & React.RefAttributes<T>) => React.JSX.Element | null;
7
- }