d2coreui 23.0.56 → 23.0.57
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 +29 -0
- package/components/date/dateRangeInputAdvancedPanel.js +19 -19
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +12 -3
- package/components/date/dateTimeInput.js +133 -72
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +4 -3
- package/components/grid/config/dataGridEditor.js +16 -4
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/dataGrid.d.ts +19 -5
- package/components/grid/dataGrid.js +9 -5
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +3 -2
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/extendedDataGrid.d.ts +11 -4
- package/components/grid/extendedDataGrid.js +34 -24
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/modal/impl/draggableModalInner.js +22 -10
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +2 -3
- package/components/modal/impl/draggableModalReducer.js +9 -7
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/modalDialog.d.ts +2 -1
- package/components/modal/modalDialog.js +2 -1
- package/components/modal/modalDialog.js.map +1 -1
- package/i18n/components.cs.json +2 -0
- package/i18n/components.sk.json +2 -0
- package/i18n/components.uk.json +2 -0
- package/package.json +1 -1
|
@@ -23,6 +23,8 @@ export interface ModalsState {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
export declare const initialModalsState: ModalsState;
|
|
26
|
+
/** Free space in total (half on each side) a maximized dialog, or one opened larger than the window, leaves around it. */
|
|
27
|
+
export declare const WINDOW_MARGIN = 32;
|
|
26
28
|
export declare const initialModalState: ModalState;
|
|
27
29
|
export type Action = {
|
|
28
30
|
type: 'show';
|
|
@@ -30,9 +32,6 @@ export type Action = {
|
|
|
30
32
|
} | {
|
|
31
33
|
type: 'hide';
|
|
32
34
|
id: ModalID;
|
|
33
|
-
} | {
|
|
34
|
-
type: 'focus';
|
|
35
|
-
id: ModalID;
|
|
36
35
|
} | {
|
|
37
36
|
type: 'unmount';
|
|
38
37
|
id: ModalID;
|
|
@@ -6,6 +6,8 @@ export const initialModalsState = {
|
|
|
6
6
|
windowSize: getWindowSize(),
|
|
7
7
|
modals: {},
|
|
8
8
|
};
|
|
9
|
+
/** Free space in total (half on each side) a maximized dialog, or one opened larger than the window, leaves around it. */
|
|
10
|
+
export const WINDOW_MARGIN = 32;
|
|
9
11
|
export const initialModalState = {
|
|
10
12
|
x: 0,
|
|
11
13
|
y: 0,
|
|
@@ -61,15 +63,15 @@ export const draggableModalReducer = (state, action) => {
|
|
|
61
63
|
return Object.assign(Object.assign({}, state), { modals: Object.assign(Object.assign({}, state.modals), { [action.id]: Object.assign(Object.assign({}, state.modals[action.id]), clampDrag(state.windowSize.width, state.windowSize.height, action.x, action.y, state.modals[action.id].width, state.modals[action.id].height)) }) });
|
|
62
64
|
case 'show': {
|
|
63
65
|
const modalState = state.modals[action.id];
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
66
|
+
// a dialog larger than the window opens shrunk to it, with the margin a maximized one keeps
|
|
67
|
+
const width = Math.min(modalState.width, state.windowSize.width - WINDOW_MARGIN);
|
|
68
|
+
const height = Math.min(modalState.height, state.windowSize.height - WINDOW_MARGIN);
|
|
69
|
+
const centerX = state.windowSize.width / 2 - width / 2;
|
|
70
|
+
const centerY = state.windowSize.height / 2 - height / 2;
|
|
71
|
+
const position = clampDrag(state.windowSize.width, state.windowSize.height, centerX, centerY, width, height);
|
|
72
|
+
const size = clampResize(state.windowSize.width, state.windowSize.height, position.x, position.y, width, height);
|
|
68
73
|
return Object.assign(Object.assign({}, state), { modals: Object.assign(Object.assign({}, state.modals), { [action.id]: Object.assign(Object.assign(Object.assign(Object.assign({}, modalState), position), size), { visible: true }) }) });
|
|
69
74
|
}
|
|
70
|
-
case 'focus':
|
|
71
|
-
const modalState = state.modals[action.id];
|
|
72
|
-
return Object.assign(Object.assign({}, state), { modals: Object.assign(Object.assign({}, state.modals), { [action.id]: Object.assign({}, modalState) }) });
|
|
73
75
|
case 'hide': {
|
|
74
76
|
const modalState = state.modals[action.id];
|
|
75
77
|
return Object.assign(Object.assign({}, state), { modals: Object.assign(Object.assign({}, state.modals), { [action.id]: Object.assign(Object.assign({}, modalState), { visible: false }) }) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draggableModalReducer.js","sourceRoot":"","sources":["../../../../../components/modal/impl/draggableModalReducer.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAA;AAE7B,MAAM,SAAS,GAAG,CAAI,CAAuB,EAAE,CAAkB,EAAwB,EAAE,CACvF,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAA;AA2BnE,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC3C,UAAU,EAAE,aAAa,EAAE;IAC3B,MAAM,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAe;IACzC,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,KAAK;CACjB,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,EACI,YAAY,GAAG,iBAAiB,CAAC,KAAK,EACt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MAAM,EACvB,QAAQ,CAAC,CAAC,EACV,QAAQ,CAAC,CAAC,EACV,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,CACpB,CAAA;oBACD,qDACO,UAAU,GACV,QAAQ,GACR,IAAI,EACV;gBACL,CAAC,CAAC,IACL;QACL;YACI,MAAM,IAAI,KAAK,EAAE,CAAA;IACzB,CAAC;AACL,CAAC,CAAA","sourcesContent":["// https://github.com/CUBETIQ/antd-modal/\r\n\r\nimport {getWindowSize} from './getWindowSize'\r\nimport {clamp} from './clamp'\r\n\r\nconst mapObject = <T>(o: { [key: string]: T }, f: (value: T) => T): { [key: string]: T } =>\r\n Object.assign({}, ...Object.keys(o).map(k => ({[k]: f(o[k])})))\r\n\r\n// ID for a specific modal.\r\nexport type ModalID = string\r\n\r\n// State for a specific modal.\r\nexport interface ModalState {\r\n x: number\r\n y: number\r\n width: number\r\n height: number\r\n visible: boolean\r\n /** rectangle to return to when un-maximizing; set only while the dialog is maximized */\r\n restore?: { x: number; y: number; width: number; height: number }\r\n}\r\n\r\n// State of all modals.\r\nexport interface ModalsState {\r\n windowSize: {\r\n width: number\r\n height: number\r\n }\r\n modals: {\r\n [key: string]: ModalState\r\n }\r\n}\r\n\r\nexport const initialModalsState: ModalsState = {\r\n windowSize: getWindowSize(),\r\n modals: {},\r\n};\r\n\r\nexport const initialModalState: ModalState = {\r\n x: 0,\r\n y: 0,\r\n width: 400,\r\n height: 400,\r\n visible: false,\r\n};\r\n\r\nconst getInitialModalState = ({\r\n initialWidth = initialModalState.width,\r\n initialHeight = initialModalState.height,\r\n }: {\r\n initialWidth?: number\r\n initialHeight?: number\r\n}) => {\r\n return {\r\n ...initialModalState,\r\n width: initialWidth,\r\n height: initialHeight,\r\n }\r\n}\r\n\r\nexport type Action =\r\n | { type: 'show'; id: ModalID }\r\n | { type: 'hide'; id: ModalID }\r\n | { type: 'focus'; id: ModalID }\r\n | { type: 'unmount'; id: ModalID }\r\n | { type: 'mount'; id: ModalID, intialState: { initialWidth?: number; initialHeight?: number } }\r\n | { type: 'windowResize'; size: { width: number; height: number } }\r\n | { type: 'drag'; id: ModalID; x: number; y: number }\r\n /**\r\n * Toggle: fills the window leaving `margin` px of free space in total (half of it on each side),\r\n * or returns to the rectangle from before maximizing.\r\n */\r\n | { type: 'maximize'; id: ModalID; margin: number }\r\n | {\r\n type: 'resize'\r\n id: ModalID\r\n x: number\r\n y: number\r\n width: number\r\n height: number\r\n}\r\n\r\nexport const getModalState = ({\r\n state,\r\n id,\r\n initialWidth,\r\n initialHeight,\r\n }: {\r\n state: ModalsState\r\n id: ModalID\r\n initialWidth?: number\r\n initialHeight?: number\r\n}): ModalState => state.modals[id] || getInitialModalState({ initialWidth, initialHeight })\r\n\r\nconst clampDrag = (\r\n windowWidth: number,\r\n windowHeight: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n): { x: number; y: number } => {\r\n const maxX = windowWidth - width;\r\n const maxY = windowHeight - height;\r\n const clampedX = clamp(0, maxX, x);\r\n const clampedY = clamp(0, maxY, y);\r\n return {x: clampedX, y: clampedY}\r\n}\r\n\r\nconst clampResize = (\r\n windowWidth: number,\r\n windowHeight: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n): { width: number; height: number } => {\r\n const maxWidth = windowWidth - x;\r\n const maxHeight = windowHeight - y;\r\n const clampedWidth = clamp(200, maxWidth, width);\r\n const clampedHeight = clamp(200, maxHeight, height);\r\n return {width: clampedWidth, height: clampedHeight}\r\n}\r\n\r\nexport const draggableModalReducer = (state: ModalsState, action: Action): ModalsState => {\r\n switch (action.type) {\r\n case 'resize':\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n action.x,\r\n action.y,\r\n action.width,\r\n action.height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...state.modals[action.id],\r\n ...size,\r\n // resizing by hand takes the dialog out of the maximized state\r\n restore: undefined,\r\n },\r\n },\r\n }\r\n case 'maximize': {\r\n const modalState = state.modals[action.id];\r\n const {restore} = modalState;\r\n if (restore) {\r\n // the window may have shrunk in the meantime, so the old rectangle goes through the\r\n // same clamping as a manual drag/resize\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n restore.x,\r\n restore.y,\r\n restore.width,\r\n restore.height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n restore.width,\r\n restore.height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n restore: undefined,\r\n },\r\n },\r\n }\r\n }\r\n const inset = action.margin / 2;\r\n const maximized = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n inset,\r\n inset,\r\n state.windowSize.width - action.margin,\r\n state.windowSize.height - action.margin,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n x: inset,\r\n y: inset,\r\n ...maximized,\r\n restore: {\r\n x: modalState.x,\r\n y: modalState.y,\r\n width: modalState.width,\r\n height: modalState.height,\r\n },\r\n },\r\n },\r\n }\r\n }\r\n case 'drag':\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...state.modals[action.id],\r\n ...clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n action.x,\r\n action.y,\r\n state.modals[action.id].width,\r\n state.modals[action.id].height,\r\n ),\r\n },\r\n },\r\n }\r\n case 'show': {\r\n const modalState = state.modals[action.id]\r\n const centerX = state.windowSize.width / 2 - modalState.width / 2\r\n const centerY = state.windowSize.height / 2 - modalState.height / 2\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n centerX,\r\n centerY,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n visible: true,\r\n },\r\n },\r\n }\r\n }\r\n case 'focus':\r\n const modalState = state.modals[action.id]\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n },\r\n },\r\n }\r\n case 'hide': {\r\n const modalState = state.modals[action.id]\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n visible: false,\r\n },\r\n },\r\n }\r\n }\r\n case 'mount':\r\n const initialState = getInitialModalState(action.intialState);\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...initialState,\r\n x: state.windowSize.width / 2 - initialState.width / 2,\r\n y: state.windowSize.height / 2 - initialState.height / 2,\r\n },\r\n },\r\n };\r\n case 'unmount':\r\n const modalsClone = {...state.modals};\r\n delete modalsClone[action.id];\r\n return {\r\n ...state,\r\n modals: modalsClone,\r\n };\r\n case 'windowResize':\r\n return {\r\n ...state,\r\n windowSize: action.size,\r\n modals: mapObject(state.modals, (modalState: ModalState) => {\r\n if (!modalState.visible) {\r\n return modalState\r\n }\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n modalState.x,\r\n modalState.y,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n return {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n }\r\n }),\r\n }\r\n default:\r\n throw new Error()\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"draggableModalReducer.js","sourceRoot":"","sources":["../../../../../components/modal/impl/draggableModalReducer.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,E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UAAU,CAAC,MAAM,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,UAGlE;QACN,KAAK,SAAS;YACV,MAAM,WAAW,qBAAO,KAAK,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC9B,uCACO,KAAK,KACR,MAAM,EAAE,WAAW,IACrB;QACN,KAAK,cAAc;YACf,uCACO,KAAK,KACR,UAAU,EAAE,MAAM,CAAC,IAAI,EACvB,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,UAAsB,EAAE,EAAE;oBACvD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;wBACtB,OAAO,UAAU,CAAA;oBACrB,CAAC;oBACD,MAAM,QAAQ,GAAG,SAAS,CACtB,KAAK,CAAC,UAAU,CAAC,KAAK,EACtB,KAAK,CAAC,UAAU,CAAC,MAAM,EACvB,UAAU,CAAC,CAAC,EACZ,UAAU,CAAC,CAAC,EACZ,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,CACpB,CAAA;oBACD,MAAM,IAAI,GAAG,WAAW,CACpB,KAAK,CAAC,UAAU,CAAC,KAAK,EACtB,KAAK,CAAC,UAAU,CAAC,MAAM,EACvB,QAAQ,CAAC,CAAC,EACV,QAAQ,CAAC,CAAC,EACV,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,CACpB,CAAA;oBACD,qDACO,UAAU,GACV,QAAQ,GACR,IAAI,EACV;gBACL,CAAC,CAAC,IACL;QACL;YACI,MAAM,IAAI,KAAK,EAAE,CAAA;IACzB,CAAC;AACL,CAAC,CAAA","sourcesContent":["// https://github.com/CUBETIQ/antd-modal/\r\n\r\nimport {getWindowSize} from './getWindowSize'\r\nimport {clamp} from './clamp'\r\n\r\nconst mapObject = <T>(o: { [key: string]: T }, f: (value: T) => T): { [key: string]: T } =>\r\n Object.assign({}, ...Object.keys(o).map(k => ({[k]: f(o[k])})))\r\n\r\n// ID for a specific modal.\r\nexport type ModalID = string\r\n\r\n// State for a specific modal.\r\nexport interface ModalState {\r\n x: number\r\n y: number\r\n width: number\r\n height: number\r\n visible: boolean\r\n /** rectangle to return to when un-maximizing; set only while the dialog is maximized */\r\n restore?: { x: number; y: number; width: number; height: number }\r\n}\r\n\r\n// State of all modals.\r\nexport interface ModalsState {\r\n windowSize: {\r\n width: number\r\n height: number\r\n }\r\n modals: {\r\n [key: string]: ModalState\r\n }\r\n}\r\n\r\nexport const initialModalsState: ModalsState = {\r\n windowSize: getWindowSize(),\r\n modals: {},\r\n};\r\n\r\n/** Free space in total (half on each side) a maximized dialog, or one opened larger than the window, leaves around it. */\r\nexport const WINDOW_MARGIN = 32\r\n\r\nexport const initialModalState: ModalState = {\r\n x: 0,\r\n y: 0,\r\n width: 400,\r\n height: 400,\r\n visible: false,\r\n};\r\n\r\nconst getInitialModalState = ({\r\n initialWidth = initialModalState.width,\r\n initialHeight = initialModalState.height,\r\n }: {\r\n initialWidth?: number\r\n initialHeight?: number\r\n}) => {\r\n return {\r\n ...initialModalState,\r\n width: initialWidth,\r\n height: initialHeight,\r\n }\r\n}\r\n\r\nexport type Action =\r\n | { type: 'show'; id: ModalID }\r\n | { type: 'hide'; id: ModalID }\r\n | { type: 'unmount'; id: ModalID }\r\n | { type: 'mount'; id: ModalID, intialState: { initialWidth?: number; initialHeight?: number } }\r\n | { type: 'windowResize'; size: { width: number; height: number } }\r\n | { type: 'drag'; id: ModalID; x: number; y: number }\r\n /**\r\n * Toggle: fills the window leaving `margin` px of free space in total (half of it on each side),\r\n * or returns to the rectangle from before maximizing.\r\n */\r\n | { type: 'maximize'; id: ModalID; margin: number }\r\n | {\r\n type: 'resize'\r\n id: ModalID\r\n x: number\r\n y: number\r\n width: number\r\n height: number\r\n}\r\n\r\nexport const getModalState = ({\r\n state,\r\n id,\r\n initialWidth,\r\n initialHeight,\r\n }: {\r\n state: ModalsState\r\n id: ModalID\r\n initialWidth?: number\r\n initialHeight?: number\r\n}): ModalState => state.modals[id] || getInitialModalState({ initialWidth, initialHeight })\r\n\r\nconst clampDrag = (\r\n windowWidth: number,\r\n windowHeight: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n): { x: number; y: number } => {\r\n const maxX = windowWidth - width;\r\n const maxY = windowHeight - height;\r\n const clampedX = clamp(0, maxX, x);\r\n const clampedY = clamp(0, maxY, y);\r\n return {x: clampedX, y: clampedY}\r\n}\r\n\r\nconst clampResize = (\r\n windowWidth: number,\r\n windowHeight: number,\r\n x: number,\r\n y: number,\r\n width: number,\r\n height: number,\r\n): { width: number; height: number } => {\r\n const maxWidth = windowWidth - x;\r\n const maxHeight = windowHeight - y;\r\n const clampedWidth = clamp(200, maxWidth, width);\r\n const clampedHeight = clamp(200, maxHeight, height);\r\n return {width: clampedWidth, height: clampedHeight}\r\n}\r\n\r\nexport const draggableModalReducer = (state: ModalsState, action: Action): ModalsState => {\r\n switch (action.type) {\r\n case 'resize':\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n action.x,\r\n action.y,\r\n action.width,\r\n action.height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...state.modals[action.id],\r\n ...size,\r\n // resizing by hand takes the dialog out of the maximized state\r\n restore: undefined,\r\n },\r\n },\r\n }\r\n case 'maximize': {\r\n const modalState = state.modals[action.id];\r\n const {restore} = modalState;\r\n if (restore) {\r\n // the window may have shrunk in the meantime, so the old rectangle goes through the\r\n // same clamping as a manual drag/resize\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n restore.x,\r\n restore.y,\r\n restore.width,\r\n restore.height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n restore.width,\r\n restore.height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n restore: undefined,\r\n },\r\n },\r\n }\r\n }\r\n const inset = action.margin / 2;\r\n const maximized = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n inset,\r\n inset,\r\n state.windowSize.width - action.margin,\r\n state.windowSize.height - action.margin,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n x: inset,\r\n y: inset,\r\n ...maximized,\r\n restore: {\r\n x: modalState.x,\r\n y: modalState.y,\r\n width: modalState.width,\r\n height: modalState.height,\r\n },\r\n },\r\n },\r\n }\r\n }\r\n case 'drag':\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...state.modals[action.id],\r\n ...clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n action.x,\r\n action.y,\r\n state.modals[action.id].width,\r\n state.modals[action.id].height,\r\n ),\r\n },\r\n },\r\n }\r\n case 'show': {\r\n const modalState = state.modals[action.id]\r\n // a dialog larger than the window opens shrunk to it, with the margin a maximized one keeps\r\n const width = Math.min(modalState.width, state.windowSize.width - WINDOW_MARGIN)\r\n const height = Math.min(modalState.height, state.windowSize.height - WINDOW_MARGIN)\r\n const centerX = state.windowSize.width / 2 - width / 2\r\n const centerY = state.windowSize.height / 2 - height / 2\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n centerX,\r\n centerY,\r\n width,\r\n height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n width,\r\n height,\r\n )\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n visible: true,\r\n },\r\n },\r\n }\r\n }\r\n case 'hide': {\r\n const modalState = state.modals[action.id]\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...modalState,\r\n visible: false,\r\n },\r\n },\r\n }\r\n }\r\n case 'mount':\r\n const initialState = getInitialModalState(action.intialState);\r\n return {\r\n ...state,\r\n modals: {\r\n ...state.modals,\r\n [action.id]: {\r\n ...initialState,\r\n x: state.windowSize.width / 2 - initialState.width / 2,\r\n y: state.windowSize.height / 2 - initialState.height / 2,\r\n },\r\n },\r\n };\r\n case 'unmount':\r\n const modalsClone = {...state.modals};\r\n delete modalsClone[action.id];\r\n return {\r\n ...state,\r\n modals: modalsClone,\r\n };\r\n case 'windowResize':\r\n return {\r\n ...state,\r\n windowSize: action.size,\r\n modals: mapObject(state.modals, (modalState: ModalState) => {\r\n if (!modalState.visible) {\r\n return modalState\r\n }\r\n const position = clampDrag(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n modalState.x,\r\n modalState.y,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n const size = clampResize(\r\n state.windowSize.width,\r\n state.windowSize.height,\r\n position.x,\r\n position.y,\r\n modalState.width,\r\n modalState.height,\r\n )\r\n return {\r\n ...modalState,\r\n ...position,\r\n ...size,\r\n }\r\n }),\r\n }\r\n default:\r\n throw new Error()\r\n }\r\n}\r\n"]}
|
|
@@ -51,7 +51,8 @@ export interface ModalDialogProps extends DraggableModalProps {
|
|
|
51
51
|
* Dialog with a predefined, localized button set (see {@link ModalDialogMode}).
|
|
52
52
|
*
|
|
53
53
|
* As a component it renders a draggable (by the title), resizable (bottom-right handle) and maximizable antd
|
|
54
|
-
* `Modal` that is kept inside the window and destroyed when hidden
|
|
54
|
+
* `Modal` that is kept inside the window and destroyed when hidden, unless `destroyOnHidden={false}` keeps its content
|
|
55
|
+
* mounted. Every opening brings it on top of the modals opened before. It must be rendered inside a
|
|
55
56
|
* `DraggableModalProvider` (`d2coreui/components/modal/draggableModalProvider`), otherwise it throws.
|
|
56
57
|
* Note that in {@link ModalDialogMode.OK} mode the component still renders the Cancel button; only the static
|
|
57
58
|
* methods hide it.
|
|
@@ -40,7 +40,8 @@ export var ModalDialogMode;
|
|
|
40
40
|
* Dialog with a predefined, localized button set (see {@link ModalDialogMode}).
|
|
41
41
|
*
|
|
42
42
|
* As a component it renders a draggable (by the title), resizable (bottom-right handle) and maximizable antd
|
|
43
|
-
* `Modal` that is kept inside the window and destroyed when hidden
|
|
43
|
+
* `Modal` that is kept inside the window and destroyed when hidden, unless `destroyOnHidden={false}` keeps its content
|
|
44
|
+
* mounted. Every opening brings it on top of the modals opened before. It must be rendered inside a
|
|
44
45
|
* `DraggableModalProvider` (`d2coreui/components/modal/draggableModalProvider`), otherwise it throws.
|
|
45
46
|
* Note that in {@link ModalDialogMode.OK} mode the component still renders the Cancel button; only the static
|
|
46
47
|
* methods hide it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modalDialog.js","sourceRoot":"","sources":["../../../../components/modal/modalDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,MAAM,CAAC;AAEnC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,cAAc,EAAsB,MAAM,gCAAgC,CAAC;AAGnF;;;GAGG;AACH,MAAM,CAAN,IAAkB,eAiBjB;AAjBD,WAAkB,eAAe;IAC7B;;;OAGG;IACH,4CAAyB,CAAA;IACzB,iCAAiC;IACjC,0CAAuB,CAAA;IACvB,mDAAmD;IACnD,oCAAiB,CAAA;IACjB;;;OAGG;IACH,kDAA+B,CAAA;IAC/B,qFAAqF;IACrF,4BAAS,CAAA;AACb,CAAC,EAjBiB,eAAe,KAAf,eAAe,QAiBhC;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,SAA+B;IAGlE,YAAY,KAAiC;QACzC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,gBAAgB,CAAC,QAAiB;QA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C,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAC,KAAK,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC,EAAC,CAAC,CAAC;QAC1I,CAAC;QAED,IAAI,IAAI,wDAAkC,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;gBACzD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;gBACzC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;gBAChD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC;YAC5D,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import React from \"react\";\r\nimport {Button, Modal} from \"antd\";\r\nimport {ModalFuncProps} from \"antd/es/modal\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport {DraggableModal, DraggableModalProps} from \"d2coreui/components/modal/impl\";\r\nimport {HookAPI} from \"antd/es/modal/useModal\";\r\n\r\n/**\r\n * Button set of a {@link ModalDialog}. Button labels are localized and can be overridden with `okText` /\r\n * `cancelText` (and `denyText`).\r\n */\r\nexport const enum ModalDialogMode {\r\n /**\r\n * No footer, unless a `footer` is given explicitly. Honored only by the component; the static methods show\r\n * antd's default buttons.\r\n */\r\n NO_BUTTONS = \"NO_BUTTONS\",\r\n /** \"OK\" and \"Cancel\" buttons. */\r\n OK_CANCEL = \"OK_CANCEL\",\r\n /** \"Yes\" and \"No\" buttons; \"No\" acts as cancel. */\r\n YES_NO = \"YES_NO\",\r\n /**\r\n * \"Yes\", \"No\" and \"Cancel\" buttons: \"Yes\" calls `onOk`, \"No\" calls `onDeny` and \"Cancel\" `onCancel`.\r\n * Supported only by the static methods; the component renders antd's default buttons in this mode.\r\n */\r\n YES_NO_CANCEL = \"YES_NO_CANCEL\",\r\n /** Only an \"OK\" button (see the note at {@link ModalDialog} about the component). */\r\n OK = \"OK\",\r\n}\r\n\r\n/**\r\n * Options of the static {@link ModalDialog} methods: antd `ModalFuncProps` plus the button mode.\r\n * `autoFocusButton` defaults to `\"ok\"`.\r\n */\r\nexport interface ModalDialogFuncProps extends ModalFuncProps {\r\n /** Button set of the dialog. */\r\n mode: ModalDialogMode\r\n /** Label of the \"No\" button in {@link ModalDialogMode.YES_NO_CANCEL} mode; defaults to localized \"No\". */\r\n denyText?: string\r\n /**\r\n * Called with the click event when the \"No\" button is clicked in {@link ModalDialogMode.YES_NO_CANCEL} mode;\r\n * the dialog is closed afterwards.\r\n */\r\n onDeny?: (...args: any[]) => any;\r\n}\r\n\r\n/**\r\n * Props of the {@link ModalDialog} component: antd `ModalProps` (except `width`) plus `initialWidth`,\r\n * `initialHeight`, `maximizable` and `onResize` of the draggable modal, and the button mode.\r\n */\r\nexport interface ModalDialogProps extends DraggableModalProps {\r\n /** Button set of the dialog. */\r\n mode: ModalDialogMode\r\n}\r\n\r\n/**\r\n * Dialog with a predefined, localized button set (see {@link ModalDialogMode}).\r\n *\r\n * As a component it renders a draggable (by the title), resizable (bottom-right handle) and maximizable antd\r\n * `Modal` that is kept inside the window and destroyed when hidden. It must be rendered inside a\r\n * `DraggableModalProvider` (`d2coreui/components/modal/draggableModalProvider`), otherwise it throws.\r\n * Note that in {@link ModalDialogMode.OK} mode the component still renders the Cancel button; only the static\r\n * methods hide it.\r\n *\r\n * The static methods open imperative antd dialogs; register the app's modal API once with\r\n * {@link ModalDialog.setModalInstance}. They modify the passed `okButtonProps` / `cancelButtonProps` objects and\r\n * replace their `style`.\r\n *\r\n * @example\r\n * <DraggableModalProvider>\r\n * <ModalDialog mode={ModalDialogMode.OK_CANCEL} open={open} title=\"Rename\"\r\n * initialWidth={480} initialHeight={240}\r\n * onOk={save} onCancel={() => setOpen(false)}>\r\n * <Input value={name} onChange={e => setName(e.target.value)}/>\r\n * </ModalDialog>\r\n * </DraggableModalProvider>\r\n *\r\n * @example\r\n * ModalDialog.confirm({\r\n * mode: ModalDialogMode.YES_NO_CANCEL,\r\n * title: \"Save changes?\",\r\n * onOk: save,\r\n * onDeny: discard,\r\n * });\r\n */\r\nexport class ModalDialog extends React.Component<ModalDialogProps, {}> {\r\n private static modalStatic: HookAPI;\r\n\r\n constructor(props: Readonly<ModalDialogProps>) {\r\n super(props);\r\n }\r\n\r\n /**\r\n * Registers the antd `modal` API from `App.useApp()` for the static methods, so that their dialogs inherit the app's\r\n * theme, locale and context. Until it is called they fall back to antd's static `Modal` functions.\r\n */\r\n public static setModalInstance(instance: HookAPI) {\r\n ModalDialog.modalStatic = instance;\r\n }\r\n\r\n /**\r\n * Opens a confirmation dialog (antd `confirm`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static confirm(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.confirm : Modal.confirm;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens an error dialog (antd `error`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static error(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.error : Modal.error;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens a confirmation dialog like {@link ModalDialog.confirm} with a danger OK button. The button is marked as\r\n * danger only when `props.okButtonProps` is passed (an empty object is enough).\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static delete(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.confirm : Modal.confirm;\r\n if (props.okButtonProps) {\r\n props.okButtonProps.danger = true;\r\n }\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens a success dialog (antd `success`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static success(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.success : Modal.success;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens an information dialog (antd `info`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static info(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.info : Modal.info;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n render() {\r\n const modalDialogProperties = ModalDialog.getModalProperties(this.props);\r\n return (\r\n <DraggableModal {...modalDialogProperties}>\r\n {this.props.children}\r\n </DraggableModal>);\r\n }\r\n\r\n private static getModalProperties(props: ModalDialogProps) {\r\n const {mode, ...rest} = props;\r\n if (mode === ModalDialogMode.NO_BUTTONS) {\r\n if (rest.footer === undefined) {\r\n rest.footer = null;\r\n }\r\n } else {\r\n switch (mode) {\r\n case ModalDialogMode.OK_CANCEL:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelText = props.cancelText ?? i18n(\"Cancel\");\r\n break;\r\n case ModalDialogMode.YES_NO:\r\n rest.okText = props.okText ?? i18n(\"Yes\");\r\n rest.cancelText = props.cancelText ?? i18n(\"No\");\r\n break;\r\n case ModalDialogMode.OK:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelButtonProps = undefined;\r\n break;\r\n }\r\n\r\n rest.okButtonProps = Object.assign(rest.okButtonProps !== undefined ? rest.okButtonProps : {}, {style: {marginRight: 8}});\r\n rest.cancelButtonProps = Object.assign(rest.cancelButtonProps !== undefined ? rest.cancelButtonProps : {}, {style: {float: \"right\"}});\r\n }\r\n return rest;\r\n }\r\n\r\n private static getModalFuncProperties(props: ModalDialogFuncProps, performClose: () => void) {\r\n const {mode, denyText, onDeny, ...rest} = props;\r\n switch (mode) {\r\n case ModalDialogMode.OK_CANCEL:\r\n rest.okText = rest.okText ?? i18n(\"OK\");\r\n rest.cancelText = rest.cancelText ?? i18n(\"Cancel\");\r\n break;\r\n case ModalDialogMode.YES_NO:\r\n rest.okText = rest.okText ?? i18n(\"Yes\");\r\n rest.cancelText = rest.cancelText ?? i18n(\"No\");\r\n break;\r\n case ModalDialogMode.YES_NO_CANCEL:\r\n rest.okText = rest.okText ?? i18n(\"Yes\");\r\n rest.cancelText = (<React.Fragment>\r\n <Button onClick={(e) => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n e.nativeEvent.stopImmediatePropagation();\r\n onDeny?.(e);\r\n performClose();\r\n }}>{denyText ?? i18n(\"No\")}</Button>\r\n <Button>{rest.cancelText ?? i18n(\"Cancel\")}</Button>\r\n </React.Fragment>\r\n );\r\n if (!rest.cancelButtonProps) {\r\n rest.cancelButtonProps = {};\r\n }\r\n rest.cancelButtonProps.type = \"text\";\r\n break;\r\n case ModalDialogMode.OK:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelButtonProps = {style: {display: \"none\"}};\r\n }\r\n if (rest.autoFocusButton === undefined) {\r\n rest.autoFocusButton = \"ok\";\r\n }\r\n\r\n rest.okButtonProps = Object.assign(rest.okButtonProps !== undefined ? rest.okButtonProps : {}, {style: {marginRight: 8}});\r\n\r\n if (mode !== ModalDialogMode.OK) {\r\n rest.cancelButtonProps = Object.assign(rest.cancelButtonProps !== undefined ? rest.cancelButtonProps : {}, {style: {float: \"right\"}});\r\n }\r\n\r\n if (mode === ModalDialogMode.YES_NO_CANCEL) {\r\n if (rest.cancelButtonProps && rest.cancelButtonProps.style) {\r\n rest.cancelButtonProps.style.padding = 0;\r\n rest.cancelButtonProps.style.marginTop = -1;\r\n rest.cancelButtonProps.style.cursor = \"default\";\r\n rest.cancelButtonProps.style.background = \"transparent\";\r\n }\r\n }\r\n return rest;\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"file":"modalDialog.js","sourceRoot":"","sources":["../../../../components/modal/modalDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,MAAM,CAAC;AAEnC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,cAAc,EAAsB,MAAM,gCAAgC,CAAC;AAGnF;;;GAGG;AACH,MAAM,CAAN,IAAkB,eAiBjB;AAjBD,WAAkB,eAAe;IAC7B;;;OAGG;IACH,4CAAyB,CAAA;IACzB,iCAAiC;IACjC,0CAAuB,CAAA;IACvB,mDAAmD;IACnD,oCAAiB,CAAA;IACjB;;;OA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AAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,EAAC,KAAK,EAAE,EAAC,WAAW,EAAE,CAAC,EAAC,EAAC,CAAC,CAAC;QAE1H,IAAI,IAAI,kCAAuB,EAAE,CAAC;YAC9B,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAC,KAAK,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC,EAAC,CAAC,CAAC;QAC1I,CAAC;QAED,IAAI,IAAI,wDAAkC,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;gBACzD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;gBACzC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;gBAChD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC;YAC5D,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import React from \"react\";\r\nimport {Button, Modal} from \"antd\";\r\nimport {ModalFuncProps} from \"antd/es/modal\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport {DraggableModal, DraggableModalProps} from \"d2coreui/components/modal/impl\";\r\nimport {HookAPI} from \"antd/es/modal/useModal\";\r\n\r\n/**\r\n * Button set of a {@link ModalDialog}. Button labels are localized and can be overridden with `okText` /\r\n * `cancelText` (and `denyText`).\r\n */\r\nexport const enum ModalDialogMode {\r\n /**\r\n * No footer, unless a `footer` is given explicitly. Honored only by the component; the static methods show\r\n * antd's default buttons.\r\n */\r\n NO_BUTTONS = \"NO_BUTTONS\",\r\n /** \"OK\" and \"Cancel\" buttons. */\r\n OK_CANCEL = \"OK_CANCEL\",\r\n /** \"Yes\" and \"No\" buttons; \"No\" acts as cancel. */\r\n YES_NO = \"YES_NO\",\r\n /**\r\n * \"Yes\", \"No\" and \"Cancel\" buttons: \"Yes\" calls `onOk`, \"No\" calls `onDeny` and \"Cancel\" `onCancel`.\r\n * Supported only by the static methods; the component renders antd's default buttons in this mode.\r\n */\r\n YES_NO_CANCEL = \"YES_NO_CANCEL\",\r\n /** Only an \"OK\" button (see the note at {@link ModalDialog} about the component). */\r\n OK = \"OK\",\r\n}\r\n\r\n/**\r\n * Options of the static {@link ModalDialog} methods: antd `ModalFuncProps` plus the button mode.\r\n * `autoFocusButton` defaults to `\"ok\"`.\r\n */\r\nexport interface ModalDialogFuncProps extends ModalFuncProps {\r\n /** Button set of the dialog. */\r\n mode: ModalDialogMode\r\n /** Label of the \"No\" button in {@link ModalDialogMode.YES_NO_CANCEL} mode; defaults to localized \"No\". */\r\n denyText?: string\r\n /**\r\n * Called with the click event when the \"No\" button is clicked in {@link ModalDialogMode.YES_NO_CANCEL} mode;\r\n * the dialog is closed afterwards.\r\n */\r\n onDeny?: (...args: any[]) => any;\r\n}\r\n\r\n/**\r\n * Props of the {@link ModalDialog} component: antd `ModalProps` (except `width`) plus `initialWidth`,\r\n * `initialHeight`, `maximizable` and `onResize` of the draggable modal, and the button mode.\r\n */\r\nexport interface ModalDialogProps extends DraggableModalProps {\r\n /** Button set of the dialog. */\r\n mode: ModalDialogMode\r\n}\r\n\r\n/**\r\n * Dialog with a predefined, localized button set (see {@link ModalDialogMode}).\r\n *\r\n * As a component it renders a draggable (by the title), resizable (bottom-right handle) and maximizable antd\r\n * `Modal` that is kept inside the window and destroyed when hidden, unless `destroyOnHidden={false}` keeps its content\r\n * mounted. Every opening brings it on top of the modals opened before. It must be rendered inside a\r\n * `DraggableModalProvider` (`d2coreui/components/modal/draggableModalProvider`), otherwise it throws.\r\n * Note that in {@link ModalDialogMode.OK} mode the component still renders the Cancel button; only the static\r\n * methods hide it.\r\n *\r\n * The static methods open imperative antd dialogs; register the app's modal API once with\r\n * {@link ModalDialog.setModalInstance}. They modify the passed `okButtonProps` / `cancelButtonProps` objects and\r\n * replace their `style`.\r\n *\r\n * @example\r\n * <DraggableModalProvider>\r\n * <ModalDialog mode={ModalDialogMode.OK_CANCEL} open={open} title=\"Rename\"\r\n * initialWidth={480} initialHeight={240}\r\n * onOk={save} onCancel={() => setOpen(false)}>\r\n * <Input value={name} onChange={e => setName(e.target.value)}/>\r\n * </ModalDialog>\r\n * </DraggableModalProvider>\r\n *\r\n * @example\r\n * ModalDialog.confirm({\r\n * mode: ModalDialogMode.YES_NO_CANCEL,\r\n * title: \"Save changes?\",\r\n * onOk: save,\r\n * onDeny: discard,\r\n * });\r\n */\r\nexport class ModalDialog extends React.Component<ModalDialogProps, {}> {\r\n private static modalStatic: HookAPI;\r\n\r\n constructor(props: Readonly<ModalDialogProps>) {\r\n super(props);\r\n }\r\n\r\n /**\r\n * Registers the antd `modal` API from `App.useApp()` for the static methods, so that their dialogs inherit the app's\r\n * theme, locale and context. Until it is called they fall back to antd's static `Modal` functions.\r\n */\r\n public static setModalInstance(instance: HookAPI) {\r\n ModalDialog.modalStatic = instance;\r\n }\r\n\r\n /**\r\n * Opens a confirmation dialog (antd `confirm`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static confirm(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.confirm : Modal.confirm;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens an error dialog (antd `error`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static error(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.error : Modal.error;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens a confirmation dialog like {@link ModalDialog.confirm} with a danger OK button. The button is marked as\r\n * danger only when `props.okButtonProps` is passed (an empty object is enough).\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static delete(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.confirm : Modal.confirm;\r\n if (props.okButtonProps) {\r\n props.okButtonProps.danger = true;\r\n }\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens a success dialog (antd `success`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static success(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.success : Modal.success;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n /**\r\n * Opens an information dialog (antd `info`) with the buttons of `props.mode`.\r\n * @returns a handle to close or update the dialog.\r\n */\r\n public static info(props: ModalDialogFuncProps): { destroy: () => void; update: (newConfig: ModalFuncProps) => void } {\r\n let dialogHandler: { destroy: () => void; update: (newConfig: ModalFuncProps) => void };\r\n const modalDialogProperties = ModalDialog.getModalFuncProperties(props, () => {\r\n dialogHandler?.destroy();\r\n });\r\n const method = ModalDialog.modalStatic ? ModalDialog.modalStatic.info : Modal.info;\r\n dialogHandler = method(modalDialogProperties);\r\n return dialogHandler;\r\n }\r\n\r\n render() {\r\n const modalDialogProperties = ModalDialog.getModalProperties(this.props);\r\n return (\r\n <DraggableModal {...modalDialogProperties}>\r\n {this.props.children}\r\n </DraggableModal>);\r\n }\r\n\r\n private static getModalProperties(props: ModalDialogProps) {\r\n const {mode, ...rest} = props;\r\n if (mode === ModalDialogMode.NO_BUTTONS) {\r\n if (rest.footer === undefined) {\r\n rest.footer = null;\r\n }\r\n } else {\r\n switch (mode) {\r\n case ModalDialogMode.OK_CANCEL:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelText = props.cancelText ?? i18n(\"Cancel\");\r\n break;\r\n case ModalDialogMode.YES_NO:\r\n rest.okText = props.okText ?? i18n(\"Yes\");\r\n rest.cancelText = props.cancelText ?? i18n(\"No\");\r\n break;\r\n case ModalDialogMode.OK:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelButtonProps = undefined;\r\n break;\r\n }\r\n\r\n rest.okButtonProps = Object.assign(rest.okButtonProps !== undefined ? rest.okButtonProps : {}, {style: {marginRight: 8}});\r\n rest.cancelButtonProps = Object.assign(rest.cancelButtonProps !== undefined ? rest.cancelButtonProps : {}, {style: {float: \"right\"}});\r\n }\r\n return rest;\r\n }\r\n\r\n private static getModalFuncProperties(props: ModalDialogFuncProps, performClose: () => void) {\r\n const {mode, denyText, onDeny, ...rest} = props;\r\n switch (mode) {\r\n case ModalDialogMode.OK_CANCEL:\r\n rest.okText = rest.okText ?? i18n(\"OK\");\r\n rest.cancelText = rest.cancelText ?? i18n(\"Cancel\");\r\n break;\r\n case ModalDialogMode.YES_NO:\r\n rest.okText = rest.okText ?? i18n(\"Yes\");\r\n rest.cancelText = rest.cancelText ?? i18n(\"No\");\r\n break;\r\n case ModalDialogMode.YES_NO_CANCEL:\r\n rest.okText = rest.okText ?? i18n(\"Yes\");\r\n rest.cancelText = (<React.Fragment>\r\n <Button onClick={(e) => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n e.nativeEvent.stopImmediatePropagation();\r\n onDeny?.(e);\r\n performClose();\r\n }}>{denyText ?? i18n(\"No\")}</Button>\r\n <Button>{rest.cancelText ?? i18n(\"Cancel\")}</Button>\r\n </React.Fragment>\r\n );\r\n if (!rest.cancelButtonProps) {\r\n rest.cancelButtonProps = {};\r\n }\r\n rest.cancelButtonProps.type = \"text\";\r\n break;\r\n case ModalDialogMode.OK:\r\n rest.okText = props.okText ?? i18n(\"OK\");\r\n rest.cancelButtonProps = {style: {display: \"none\"}};\r\n }\r\n if (rest.autoFocusButton === undefined) {\r\n rest.autoFocusButton = \"ok\";\r\n }\r\n\r\n rest.okButtonProps = Object.assign(rest.okButtonProps !== undefined ? rest.okButtonProps : {}, {style: {marginRight: 8}});\r\n\r\n if (mode !== ModalDialogMode.OK) {\r\n rest.cancelButtonProps = Object.assign(rest.cancelButtonProps !== undefined ? rest.cancelButtonProps : {}, {style: {float: \"right\"}});\r\n }\r\n\r\n if (mode === ModalDialogMode.YES_NO_CANCEL) {\r\n if (rest.cancelButtonProps && rest.cancelButtonProps.style) {\r\n rest.cancelButtonProps.style.padding = 0;\r\n rest.cancelButtonProps.style.marginTop = -1;\r\n rest.cancelButtonProps.style.cursor = \"default\";\r\n rest.cancelButtonProps.style.background = \"transparent\";\r\n }\r\n }\r\n return rest;\r\n }\r\n}"]}
|
package/i18n/components.cs.json
CHANGED
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
"Set No Color": "Nastavit žádnou barvu",
|
|
60
60
|
"Show time with milliseconds": "Zobrazit čas s milisekundami",
|
|
61
61
|
"Show time with time zone": "Zobrazit čas s časovou zónou",
|
|
62
|
+
"Only at the change to winter time": "Jen při přechodu na zimní čas",
|
|
63
|
+
"A2:00 / B2:00 at the change to winter time": "A2:00 / B2:00 při přechodu na zimní čas",
|
|
62
64
|
"Show time with year": "Zobrazit čas s rokem",
|
|
63
65
|
"Show/Hide filter panel": "Zobrazit/skrýt panel s filtrem",
|
|
64
66
|
"Show/Hide panel with modified filter": "Zobrazit/skrýt panel s modifikovaným filtrem",
|
package/i18n/components.sk.json
CHANGED
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
"Set No Color": "Nastaviť žiadnu farbu",
|
|
60
60
|
"Show time with milliseconds": "Zobraziť čas s milisekundami",
|
|
61
61
|
"Show time with time zone": "Zobraziť čas s časovou zónou",
|
|
62
|
+
"Only at the change to winter time": "Len pri prechode na zimný čas",
|
|
63
|
+
"A2:00 / B2:00 at the change to winter time": "A2:00 / B2:00 pri prechode na zimný čas",
|
|
62
64
|
"Show time with year": "Zobraziť čas s rokom",
|
|
63
65
|
"Show/Hide filter panel": "Zobraziť/skryť panel s filtrom",
|
|
64
66
|
"Show/Hide panel with modified filter": "Zobraziť/skryť panel s modifikovaným filtrom",
|
package/i18n/components.uk.json
CHANGED
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
"Set No Color": "Не встановлюйте колір",
|
|
60
60
|
"Show time with milliseconds": "Показувати час у мілісекундах",
|
|
61
61
|
"Show time with time zone": "Показувати час із часовим поясом",
|
|
62
|
+
"Only at the change to winter time": "Лише під час переходу на зимовий час",
|
|
63
|
+
"A2:00 / B2:00 at the change to winter time": "A2:00 / B2:00 під час переходу на зимовий час",
|
|
62
64
|
"Show time with year": "Покажіть час роком",
|
|
63
65
|
"Show/Hide filter panel": "Показати/сховати панель фільтрів",
|
|
64
66
|
"Show/Hide panel with modified filter": "Показати/сховати панель із зміненим фільтром",
|