@kwiz/fluentui 1.0.73 → 1.0.75
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/.github/workflows/npm-publish.yml +24 -24
- package/LICENSE +21 -21
- package/README.md +53 -53
- package/dist/@types/forwardRef.d.ts +0 -0
- package/dist/@types/forwardRef.js +1 -0
- package/dist/@types/forwardRef.js.map +1 -0
- package/dist/controls/error-boundary copy.d.ts +23 -0
- package/dist/controls/error-boundary copy.js +33 -0
- package/dist/controls/error-boundary copy.js.map +1 -0
- package/dist/controls/menu.js +2 -2
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/search.js +19 -11
- package/dist/controls/search.js.map +1 -1
- package/dist/controls/svg.js +21 -21
- package/dist/controls/svg.js.map +1 -1
- package/dist/helpers/common.d.ts +4 -0
- package/dist/helpers/common.js +2 -0
- package/dist/helpers/common.js.map +1 -0
- package/dist/helpers/context.d.ts +26 -0
- package/dist/helpers/context.js +15 -0
- package/dist/helpers/context.js.map +1 -0
- package/dist/helpers/drag-drop/exports.d.ts +12 -0
- package/dist/helpers/drag-drop/exports.js +3 -0
- package/dist/helpers/drag-drop/exports.js.map +1 -0
- package/dist/helpers/exports.d.ts +7 -0
- package/dist/helpers/exports.js +8 -0
- package/dist/helpers/exports.js.map +1 -0
- package/dist/helpers/use-editable-control.d.ts +1 -1
- package/dist/helpers/use-editable-control.js.map +1 -1
- package/package.json +85 -84
- package/src/_modules/config.ts +9 -9
- package/src/_modules/constants.ts +3 -3
- package/src/controls/ColorPickerDialog.tsx +83 -83
- package/src/controls/accordion.tsx +62 -62
- package/src/controls/button.tsx +180 -180
- package/src/controls/canvas/CustomEventTargetBase.ts +32 -32
- package/src/controls/canvas/DrawPad.tsx +296 -296
- package/src/controls/canvas/DrawPadManager.ts +694 -694
- package/src/controls/canvas/bezier.ts +109 -109
- package/src/controls/canvas/point.ts +44 -44
- package/src/controls/card-list.tsx +31 -31
- package/src/controls/card.tsx +77 -77
- package/src/controls/centered.tsx +14 -14
- package/src/controls/date.tsx +87 -87
- package/src/controls/diagram-picker.tsx +96 -96
- package/src/controls/divider.tsx +15 -15
- package/src/controls/dropdown.tsx +66 -66
- package/src/controls/error-boundary.tsx +41 -41
- package/src/controls/field-editor.tsx +42 -42
- package/src/controls/file-upload.tsx +155 -155
- package/src/controls/horizontal.tsx +48 -48
- package/src/controls/html-editor/editor.tsx +182 -182
- package/src/controls/index.ts +33 -33
- package/src/controls/input.tsx +160 -160
- package/src/controls/kwizoverflow.tsx +106 -106
- package/src/controls/list.tsx +119 -119
- package/src/controls/loading.tsx +10 -10
- package/src/controls/menu.tsx +173 -173
- package/src/controls/merge-text.tsx +126 -126
- package/src/controls/please-wait.tsx +32 -32
- package/src/controls/progress-bar.tsx +109 -109
- package/src/controls/prompt.tsx +121 -121
- package/src/controls/qrcode.tsx +36 -36
- package/src/controls/search.tsx +71 -61
- package/src/controls/section.tsx +133 -133
- package/src/controls/svg.tsx +138 -138
- package/src/controls/toolbar.tsx +46 -46
- package/src/controls/vertical-content.tsx +49 -49
- package/src/controls/vertical.tsx +42 -42
- package/src/helpers/block-nav.tsx +88 -88
- package/src/helpers/context-const.ts +29 -29
- package/src/helpers/context-export.tsx +77 -77
- package/src/helpers/context-internal.ts +13 -13
- package/src/helpers/drag-drop/drag-drop-container.tsx +53 -53
- package/src/helpers/drag-drop/drag-drop-context-internal.tsx +9 -9
- package/src/helpers/drag-drop/drag-drop-context.tsx +61 -61
- package/src/helpers/drag-drop/drag-drop.types.ts +21 -21
- package/src/helpers/drag-drop/index.ts +12 -12
- package/src/helpers/drag-drop/readme.md +75 -75
- package/src/helpers/drag-drop/use-draggable.ts +47 -47
- package/src/helpers/drag-drop/use-droppable.ts +38 -38
- package/src/helpers/forwardRef.ts +7 -7
- package/src/helpers/hooks-events.ts +149 -149
- package/src/helpers/hooks.tsx +141 -141
- package/src/helpers/index.ts +8 -8
- package/src/helpers/use-alerts.tsx +74 -74
- package/src/helpers/use-editable-control.tsx +37 -37
- package/src/helpers/use-toast.tsx +29 -29
- package/src/index.ts +2 -2
- package/src/styles/index.ts +1 -1
- package/src/styles/styles.ts +104 -104
- package/src/styles/theme.ts +90 -90
@@ -1,78 +1,78 @@
|
|
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>;
|
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
78
|
}
|
@@ -1,14 +1,14 @@
|
|
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;
|
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
14
|
}
|
@@ -1,54 +1,54 @@
|
|
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>;
|
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
54
|
}
|
@@ -1,10 +1,10 @@
|
|
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;
|
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
10
|
}
|
@@ -1,62 +1,62 @@
|
|
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>;
|
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
62
|
}
|
@@ -1,21 +1,21 @@
|
|
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
|
+
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 +1,12 @@
|
|
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
|
+
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 +1,76 @@
|
|
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>
|
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
76
|
```
|