@map-colonies/react-components 3.10.0 → 3.10.1
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 +11 -0
- package/dist/file-picker/file-picker.d.ts +3 -3
- package/dist/file-picker/file-picker.js +10 -5
- package/dist/file-picker/localization.js +51 -32
- package/package.json +2 -2
- package/src/lib/cesium-map/terrain-providers/terrain-provider-heights-tool.stories.tsx +1 -1
- package/src/lib/file-picker/file-picker.stories.tsx +63 -0
- package/src/lib/file-picker/file-picker.tsx +115 -101
- package/src/lib/file-picker/localization.ts +40 -38
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.10.1](https://github.com/MapColonies/shared-components/compare/@map-colonies/react-components@3.10.0...@map-colonies/react-components@3.10.1) (2022-02-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* file picker ref formatters ([#116](https://github.com/MapColonies/shared-components/issues/116)) ([1432b6a](https://github.com/MapColonies/shared-components/commit/1432b6a65290d0e170d9e956eddabbe1d909e744))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.10.0](https://github.com/MapColonies/shared-components/compare/@map-colonies/react-components@3.8.0...@map-colonies/react-components@3.10.0) (2022-02-09)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ChonkyFileActionData, FileArray as ChonkyFileArray, FileBrowserProps, FileData as ChonkyFileData, FileHelper as ChonkyFileHelper } from 'chonky';
|
|
2
|
+
import { ChonkyFileActionData, FileArray as ChonkyFileArray, FileBrowserHandle, FileBrowserProps, FileData as ChonkyFileData, FileHelper as ChonkyFileHelper } from 'chonky';
|
|
3
3
|
import { SupportedLocales } from '../models';
|
|
4
4
|
import './file-picker.css';
|
|
5
|
+
export declare type FilePickerHandle = FileBrowserHandle;
|
|
5
6
|
export declare type FileActionData = ChonkyFileActionData;
|
|
6
7
|
export declare type FileArray = ChonkyFileArray;
|
|
7
8
|
export declare type FileData = ChonkyFileData;
|
|
@@ -264,7 +265,7 @@ export interface FilePickerTheme {
|
|
|
264
265
|
textOnBackground: string;
|
|
265
266
|
selectionBackground: string;
|
|
266
267
|
}
|
|
267
|
-
interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
268
|
+
export interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
268
269
|
theme?: FilePickerTheme;
|
|
269
270
|
styles?: Record<string, string>;
|
|
270
271
|
defaultView?: FilePickerView;
|
|
@@ -272,4 +273,3 @@ interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
|
272
273
|
locale?: SupportedLocales;
|
|
273
274
|
}
|
|
274
275
|
export declare const FilePicker: React.FC<FilePickerProps>;
|
|
275
|
-
export {};
|
|
@@ -85,7 +85,7 @@ exports.FilePickerView = {
|
|
|
85
85
|
// IMPLEMENTATION NOTES: Currently FilePicker component works with his own icon set.
|
|
86
86
|
// In future might be tweaked.
|
|
87
87
|
chonky_1.setChonkyDefaults({ iconComponent: chonky_icon_fontawesome_1.ChonkyIconFA });
|
|
88
|
-
exports.FilePicker = react_1.default.memo(function (_a) {
|
|
88
|
+
exports.FilePicker = react_1.default.memo(react_1.default.forwardRef(function (_a, ref) {
|
|
89
89
|
var theme = _a.theme, _b = _a.styles, styles = _b === void 0 ? { height: '100%', minWidth: '600px' } : _b, _c = _a.defaultView, defaultView = _c === void 0 ? exports.FilePickerView.listView : _c, _d = _a.readOnlyMode, readOnlyMode = _d === void 0 ? false : _d, locale = _a.locale, files = _a.files, folderChain = _a.folderChain, onFileAction = _a.onFileAction, props = __rest(_a, ["theme", "styles", "defaultView", "readOnlyMode", "locale", "files", "folderChain", "onFileAction"]);
|
|
90
90
|
// IMPLEMENTATION NOTES: Currently FilePicker component discards the ability to show file thumbnail.
|
|
91
91
|
// In future might be tweaked.
|
|
@@ -109,7 +109,9 @@ exports.FilePicker = react_1.default.memo(function (_a) {
|
|
|
109
109
|
if (theme !== undefined) {
|
|
110
110
|
var processedColors = Object.keys(theme).reduce(function (acc, key) {
|
|
111
111
|
var val = theme[key];
|
|
112
|
-
key = key.startsWith('--')
|
|
112
|
+
key = key.startsWith('--')
|
|
113
|
+
? key
|
|
114
|
+
: "--fp-theme-" + toDashCase(key);
|
|
113
115
|
acc[key] = val;
|
|
114
116
|
return acc;
|
|
115
117
|
}, {});
|
|
@@ -131,16 +133,19 @@ exports.FilePicker = react_1.default.memo(function (_a) {
|
|
|
131
133
|
setDisableDragAndDrop(true);
|
|
132
134
|
}
|
|
133
135
|
else {
|
|
134
|
-
setFileActions([
|
|
136
|
+
setFileActions([
|
|
137
|
+
chonky_1.ChonkyActions.CreateFolder,
|
|
138
|
+
chonky_1.ChonkyActions.DeleteFiles,
|
|
139
|
+
]);
|
|
135
140
|
}
|
|
136
141
|
if (locale !== undefined) {
|
|
137
142
|
setI18n(localization_1.default[locale]);
|
|
138
143
|
}
|
|
139
144
|
}, [theme, defaultView, readOnlyMode, locale]);
|
|
140
145
|
return (react_1.default.createElement(box_1.Box, { style: __assign(__assign({}, styles), themeObject) },
|
|
141
|
-
react_1.default.createElement(chonky_1.FullFileBrowser, __assign({ files: files !== null && files !== void 0 ? files : [], folderChain: folderChain, onFileAction: function (data) {
|
|
146
|
+
react_1.default.createElement(chonky_1.FullFileBrowser, __assign({ ref: ref, files: files !== null && files !== void 0 ? files : [], folderChain: folderChain, onFileAction: function (data) {
|
|
142
147
|
if (typeof onFileAction === 'function') {
|
|
143
148
|
void onFileAction(data);
|
|
144
149
|
}
|
|
145
150
|
}, thumbnailGenerator: thumbnailGenerator, defaultFileViewActionId: defaultFileViewActionId, disableDragAndDrop: disableDragAndDrop, fileActions: fileActions, darkMode: darkMode, i18n: i18n }, props))));
|
|
146
|
-
});
|
|
151
|
+
}));
|
|
@@ -1,26 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
2
16
|
var _a, _b, _c;
|
|
3
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
/* eslint-disable */
|
|
4
19
|
var chonky_1 = require("chonky");
|
|
20
|
+
var filesize_1 = __importDefault(require("filesize"));
|
|
5
21
|
var models_1 = require("../models");
|
|
22
|
+
var defaultFormatters = {
|
|
23
|
+
formatFileModDate: function (intl, file) {
|
|
24
|
+
var safeModDate = chonky_1.FileHelper.getModDate(file);
|
|
25
|
+
if (safeModDate) {
|
|
26
|
+
return intl.formatDate(safeModDate, {
|
|
27
|
+
dateStyle: 'short',
|
|
28
|
+
timeStyle: 'short',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
formatFileSize: function (intl, file) {
|
|
36
|
+
if (!file || typeof file.size !== 'number')
|
|
37
|
+
return null;
|
|
38
|
+
var size = file.size;
|
|
39
|
+
var sizeData = filesize_1.default(size, { bits: false, output: 'object' });
|
|
40
|
+
if (sizeData.symbol === 'B') {
|
|
41
|
+
return Math.round(sizeData.value / 10) / 100.0 + " KB";
|
|
42
|
+
}
|
|
43
|
+
else if (sizeData.symbol === 'KB') {
|
|
44
|
+
return Math.round(sizeData.value) + " " + sizeData.symbol;
|
|
45
|
+
}
|
|
46
|
+
return sizeData.value + " " + sizeData.symbol;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
var englishI18n = {
|
|
50
|
+
locale: models_1.SupportedLocales.EN,
|
|
51
|
+
formatters: __assign({}, defaultFormatters),
|
|
52
|
+
};
|
|
6
53
|
var russianI18n = {
|
|
7
54
|
locale: models_1.SupportedLocales.RU,
|
|
8
|
-
formatters: {
|
|
9
|
-
formatFileModDate: function (intl, file) {
|
|
10
|
-
var safeModDate = chonky_1.FileHelper.getModDate(file);
|
|
11
|
-
if (safeModDate) {
|
|
12
|
-
return intl.formatDate(safeModDate) + ", " + intl.formatTime(safeModDate);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
formatFileSize: function (intl, file) {
|
|
19
|
-
if (!file || typeof file.size !== 'number')
|
|
20
|
-
return null;
|
|
21
|
-
return "\u0420\u0430\u0437\u043C\u0435\u0440: " + file.size;
|
|
22
|
-
},
|
|
23
|
-
},
|
|
55
|
+
formatters: __assign({}, defaultFormatters),
|
|
24
56
|
messages: (_a = {
|
|
25
57
|
'chonky.toolbar.searchPlaceholder': 'Поиск',
|
|
26
58
|
'chonky.toolbar.visibleFileCount': "{fileCount, plural,\n one {# \u0444\u0430\u0439\u043B}\n few {# \u0444\u0430\u0439\u043B\u0430}\n other {# \u0444\u0430\u0439\u043B\u043E\u0432}\n }",
|
|
@@ -50,22 +82,7 @@ var russianI18n = {
|
|
|
50
82
|
};
|
|
51
83
|
var hebrewI18n = {
|
|
52
84
|
locale: models_1.SupportedLocales.HE,
|
|
53
|
-
formatters: {
|
|
54
|
-
formatFileModDate: function (intl, file) {
|
|
55
|
-
var safeModDate = chonky_1.FileHelper.getModDate(file);
|
|
56
|
-
if (safeModDate) {
|
|
57
|
-
return intl.formatTime(safeModDate) + " ," + intl.formatDate(safeModDate);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
formatFileSize: function (intl, file) {
|
|
64
|
-
if (!file || typeof file.size !== 'number')
|
|
65
|
-
return null;
|
|
66
|
-
return "\u05D2\u05D5\u05D3\u05DC: " + file.size;
|
|
67
|
-
},
|
|
68
|
-
},
|
|
85
|
+
formatters: __assign({}, defaultFormatters),
|
|
69
86
|
messages: (_b = {
|
|
70
87
|
'chonky.toolbar.searchPlaceholder': 'חיפוש',
|
|
71
88
|
'chonky.toolbar.visibleFileCount': "{fileCount, plural,\n one {\u05E4\u05E8\u05D9\u05D8 #}\n other {# \u05E4\u05E8\u05D9\u05D8\u05D9\u05DD}\n }",
|
|
@@ -94,7 +111,9 @@ var hebrewI18n = {
|
|
|
94
111
|
_b),
|
|
95
112
|
};
|
|
96
113
|
var localization = (_c = {},
|
|
114
|
+
_c[models_1.SupportedLocales.EN] = englishI18n,
|
|
97
115
|
_c[models_1.SupportedLocales.RU] = russianI18n,
|
|
98
116
|
_c[models_1.SupportedLocales.HE] = hebrewI18n,
|
|
99
117
|
_c);
|
|
100
118
|
exports.default = localization;
|
|
119
|
+
/* eslint-enable */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@map-colonies/react-components",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.1",
|
|
4
4
|
"module": "dist/index.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"jest-enzyme": "^7.1.2",
|
|
93
93
|
"react-test-renderer": "^16.13.1"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "3f12e71175ab9296724335c77ce353ce4ce89f48",
|
|
96
96
|
"jest": {
|
|
97
97
|
"coverageReporters": [
|
|
98
98
|
"text",
|
|
@@ -10,8 +10,8 @@ import { Story, Meta } from '@storybook/react/types-6-0';
|
|
|
10
10
|
import { CesiumMap, useCesiumMap } from '../map';
|
|
11
11
|
import { CesiumSceneMode } from '../map.types';
|
|
12
12
|
import { Cesium3DTileset } from '../layers';
|
|
13
|
-
import { TerrainianHeightTool } from '../tools/terranian-height.tool';
|
|
14
13
|
import { InspectorTool } from '../tools/inspector.tool';
|
|
14
|
+
import { TerrainianHeightTool } from '../tools/terranian-height.tool';
|
|
15
15
|
import { LayerType } from '../layers-manager';
|
|
16
16
|
|
|
17
17
|
export default {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
FileData,
|
|
24
24
|
FileHelper,
|
|
25
25
|
FilePickerActions,
|
|
26
|
+
FilePickerHandle,
|
|
26
27
|
} from './file-picker';
|
|
27
28
|
import FsMap from './fs-map.json';
|
|
28
29
|
|
|
@@ -379,3 +380,65 @@ export const Localized: Story = () => {
|
|
|
379
380
|
</>
|
|
380
381
|
);
|
|
381
382
|
};
|
|
383
|
+
|
|
384
|
+
export const FilesSelection: Story = () => {
|
|
385
|
+
const {
|
|
386
|
+
fileMap,
|
|
387
|
+
currentFolderId,
|
|
388
|
+
setCurrentFolderId,
|
|
389
|
+
// resetFileMap,
|
|
390
|
+
deleteFiles,
|
|
391
|
+
moveFiles,
|
|
392
|
+
createFolder,
|
|
393
|
+
} = useCustomFileMap();
|
|
394
|
+
const files = useFiles(fileMap, currentFolderId as string);
|
|
395
|
+
const folderChain = useFolderChain(fileMap, currentFolderId as string);
|
|
396
|
+
const handleFileAction = useFileActionHandler(
|
|
397
|
+
setCurrentFolderId,
|
|
398
|
+
deleteFiles,
|
|
399
|
+
moveFiles,
|
|
400
|
+
createFolder
|
|
401
|
+
);
|
|
402
|
+
const fileBrowserRef = useRef<FilePickerHandle>(null);
|
|
403
|
+
|
|
404
|
+
const getSelection = React.useCallback(
|
|
405
|
+
(event: React.MouseEvent) => {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
event.stopPropagation();
|
|
408
|
+
if (!fileBrowserRef.current) return;
|
|
409
|
+
console.log(fileBrowserRef.current.getFileSelection());
|
|
410
|
+
},
|
|
411
|
+
[files, fileBrowserRef]
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
const randomizeSelection = React.useCallback(
|
|
415
|
+
(event: React.MouseEvent) => {
|
|
416
|
+
event.preventDefault();
|
|
417
|
+
event.stopPropagation();
|
|
418
|
+
if (!fileBrowserRef.current) return;
|
|
419
|
+
const randomFileIds = new Set<string>();
|
|
420
|
+
for (const file of files) {
|
|
421
|
+
if (file && Math.random() > 0.5) randomFileIds.add(file.id);
|
|
422
|
+
}
|
|
423
|
+
fileBrowserRef.current.setFileSelection(randomFileIds);
|
|
424
|
+
},
|
|
425
|
+
[files, fileBrowserRef]
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<Box style={{ height: '600px' }}>
|
|
430
|
+
<button type="button" onClick={randomizeSelection}>
|
|
431
|
+
Select files
|
|
432
|
+
</button>
|
|
433
|
+
<button type="button" onClick={getSelection}>
|
|
434
|
+
Get selected files
|
|
435
|
+
</button>
|
|
436
|
+
<FilePicker
|
|
437
|
+
ref={fileBrowserRef}
|
|
438
|
+
files={files}
|
|
439
|
+
folderChain={folderChain}
|
|
440
|
+
onFileAction={handleFileAction}
|
|
441
|
+
/>
|
|
442
|
+
</Box>
|
|
443
|
+
);
|
|
444
|
+
};
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
ChonkyFileActionData,
|
|
5
5
|
FileAction,
|
|
6
6
|
FileArray as ChonkyFileArray,
|
|
7
|
+
FileBrowserHandle,
|
|
7
8
|
FileBrowserProps,
|
|
8
9
|
FileData as ChonkyFileData,
|
|
9
10
|
FileHelper as ChonkyFileHelper,
|
|
@@ -19,6 +20,8 @@ import localization from './localization';
|
|
|
19
20
|
|
|
20
21
|
import './file-picker.css';
|
|
21
22
|
|
|
23
|
+
export type FilePickerHandle = FileBrowserHandle;
|
|
24
|
+
|
|
22
25
|
export type FileActionData = ChonkyFileActionData;
|
|
23
26
|
|
|
24
27
|
export type FileArray = ChonkyFileArray;
|
|
@@ -48,7 +51,7 @@ export interface FilePickerTheme {
|
|
|
48
51
|
// IMPLEMENTATION NOTES: Currently FilePicker component works with his own icon set.
|
|
49
52
|
// In future might be tweaked.
|
|
50
53
|
setChonkyDefaults({ iconComponent: ChonkyIconFA });
|
|
51
|
-
interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
54
|
+
export interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
52
55
|
theme?: FilePickerTheme;
|
|
53
56
|
styles?: Record<string, string>;
|
|
54
57
|
defaultView?: FilePickerView;
|
|
@@ -57,107 +60,118 @@ interface FilePickerProps extends Partial<FileBrowserProps> {
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
export const FilePicker: React.FC<FilePickerProps> = React.memo(
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// In future might be tweaked.
|
|
73
|
-
const thumbnailGenerator = useCallback(
|
|
74
|
-
(file: FileData) => null,
|
|
75
|
-
// file.thumbnailUrl ? `https://chonky.io${file.thumbnailUrl}` : null,
|
|
76
|
-
[]
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
makeStyles({
|
|
80
|
-
'@global': {
|
|
81
|
-
'.chonky-dropdownList': {
|
|
82
|
-
backgroundColor: `${theme?.surface as string} !important`,
|
|
83
|
-
},
|
|
84
|
-
'li[class*="chonky-activeButton"]': {
|
|
85
|
-
color: `${theme?.primary as string} !important`,
|
|
86
|
-
},
|
|
63
|
+
React.forwardRef<FileBrowserHandle, FilePickerProps>(
|
|
64
|
+
(
|
|
65
|
+
{
|
|
66
|
+
theme,
|
|
67
|
+
styles = { height: '100%', minWidth: '600px' },
|
|
68
|
+
defaultView = FilePickerView.listView,
|
|
69
|
+
readOnlyMode = false,
|
|
70
|
+
locale,
|
|
71
|
+
files,
|
|
72
|
+
folderChain,
|
|
73
|
+
onFileAction,
|
|
74
|
+
...props
|
|
87
75
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
76
|
+
ref
|
|
77
|
+
) => {
|
|
78
|
+
// IMPLEMENTATION NOTES: Currently FilePicker component discards the ability to show file thumbnail.
|
|
79
|
+
// In future might be tweaked.
|
|
80
|
+
const thumbnailGenerator = useCallback(
|
|
81
|
+
(file: FileData) => null,
|
|
82
|
+
// file.thumbnailUrl ? `https://chonky.io${file.thumbnailUrl}` : null,
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
makeStyles({
|
|
87
|
+
'@global': {
|
|
88
|
+
'.chonky-dropdownList': {
|
|
89
|
+
backgroundColor: `${theme?.surface as string} !important`,
|
|
102
90
|
},
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
91
|
+
'li[class*="chonky-activeButton"]': {
|
|
92
|
+
color: `${theme?.primary as string} !important`,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
})();
|
|
96
|
+
|
|
97
|
+
const toDashCase = (str: string): string => {
|
|
98
|
+
return str.replace(/([A-Z])/g, ($1) => '-' + $1.toLowerCase());
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const themeObject = useMemo((): Record<string, string> => {
|
|
102
|
+
if (theme !== undefined) {
|
|
103
|
+
const processedColors = Object.keys(theme).reduce(
|
|
104
|
+
(acc: Record<string, string>, key) => {
|
|
105
|
+
const val = ((theme as unknown) as Record<string, string>)[key];
|
|
106
|
+
key = key.startsWith('--')
|
|
107
|
+
? key
|
|
108
|
+
: `--fp-theme-${toDashCase(key)}`;
|
|
109
|
+
acc[key] = val;
|
|
110
|
+
return acc;
|
|
111
|
+
},
|
|
112
|
+
{}
|
|
113
|
+
);
|
|
114
|
+
return processedColors;
|
|
115
|
+
}
|
|
116
|
+
return {};
|
|
117
|
+
}, [theme]);
|
|
118
|
+
|
|
119
|
+
const [darkMode, setDarkMode] = useState<boolean>(false);
|
|
120
|
+
const [defaultFileViewActionId, setDefaultFileViewActionId] = useState<
|
|
121
|
+
FilePickerView
|
|
122
|
+
>();
|
|
123
|
+
const [disableDragAndDrop, setDisableDragAndDrop] = useState<boolean>(
|
|
124
|
+
false
|
|
125
|
+
);
|
|
126
|
+
const [fileActions, setFileActions] = useState<FileAction[]>();
|
|
127
|
+
const [i18n, setI18n] = useState<I18nConfig>();
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (theme) {
|
|
130
|
+
setDarkMode(true);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setDefaultFileViewActionId(defaultView);
|
|
134
|
+
|
|
135
|
+
if (readOnlyMode) {
|
|
136
|
+
setDisableDragAndDrop(true);
|
|
137
|
+
} else {
|
|
138
|
+
setFileActions([
|
|
139
|
+
ChonkyActions.CreateFolder,
|
|
140
|
+
ChonkyActions.DeleteFiles,
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (locale !== undefined) {
|
|
145
|
+
setI18n(localization[locale]);
|
|
146
|
+
}
|
|
147
|
+
}, [theme, defaultView, readOnlyMode, locale]);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<Box
|
|
151
|
+
style={{
|
|
152
|
+
...styles,
|
|
153
|
+
...themeObject,
|
|
151
154
|
}}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
>
|
|
156
|
+
<FullFileBrowser
|
|
157
|
+
ref={ref}
|
|
158
|
+
files={files ?? []}
|
|
159
|
+
folderChain={folderChain}
|
|
160
|
+
onFileAction={(data: ChonkyFileActionData): void => {
|
|
161
|
+
if (typeof onFileAction === 'function') {
|
|
162
|
+
void onFileAction(data);
|
|
163
|
+
}
|
|
164
|
+
}}
|
|
165
|
+
thumbnailGenerator={thumbnailGenerator}
|
|
166
|
+
defaultFileViewActionId={defaultFileViewActionId}
|
|
167
|
+
disableDragAndDrop={disableDragAndDrop}
|
|
168
|
+
fileActions={fileActions}
|
|
169
|
+
darkMode={darkMode}
|
|
170
|
+
i18n={i18n}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
</Box>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
)
|
|
163
177
|
);
|
|
@@ -1,32 +1,50 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
1
2
|
import { ChonkyActions, FileData, FileHelper, I18nConfig } from 'chonky';
|
|
2
3
|
import { IntlShape } from 'react-intl';
|
|
4
|
+
import filesize from 'filesize';
|
|
3
5
|
import { SupportedLocales } from '../models';
|
|
4
6
|
|
|
5
7
|
interface ILocalization {
|
|
6
8
|
[key: string]: I18nConfig;
|
|
7
9
|
}
|
|
8
10
|
|
|
11
|
+
const defaultFormatters = {
|
|
12
|
+
formatFileModDate: (
|
|
13
|
+
intl: IntlShape,
|
|
14
|
+
file: FileData | null
|
|
15
|
+
): string | null => {
|
|
16
|
+
const safeModDate = FileHelper.getModDate(file);
|
|
17
|
+
if (safeModDate) {
|
|
18
|
+
return intl.formatDate(safeModDate, {
|
|
19
|
+
dateStyle: 'short',
|
|
20
|
+
timeStyle: 'short',
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
formatFileSize: (intl: IntlShape, file: FileData | null): string | null => {
|
|
27
|
+
if (!file || typeof file.size !== 'number') return null;
|
|
28
|
+
|
|
29
|
+
const size = file.size;
|
|
30
|
+
const sizeData = filesize(size, { bits: false, output: 'object' }) as any;
|
|
31
|
+
if (sizeData.symbol === 'B') {
|
|
32
|
+
return `${Math.round(sizeData.value / 10) / 100.0} KB`;
|
|
33
|
+
} else if (sizeData.symbol === 'KB') {
|
|
34
|
+
return `${Math.round(sizeData.value)} ${sizeData.symbol}`;
|
|
35
|
+
}
|
|
36
|
+
return `${sizeData.value} ${sizeData.symbol}`;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const englishI18n: I18nConfig = {
|
|
41
|
+
locale: SupportedLocales.EN,
|
|
42
|
+
formatters: { ...defaultFormatters },
|
|
43
|
+
};
|
|
44
|
+
|
|
9
45
|
const russianI18n: I18nConfig = {
|
|
10
46
|
locale: SupportedLocales.RU,
|
|
11
|
-
formatters: {
|
|
12
|
-
formatFileModDate: (
|
|
13
|
-
intl: IntlShape,
|
|
14
|
-
file: FileData | null
|
|
15
|
-
): string | null => {
|
|
16
|
-
const safeModDate = FileHelper.getModDate(file);
|
|
17
|
-
if (safeModDate) {
|
|
18
|
-
return `${intl.formatDate(safeModDate)}, ${intl.formatTime(
|
|
19
|
-
safeModDate
|
|
20
|
-
)}`;
|
|
21
|
-
} else {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
formatFileSize: (intl: IntlShape, file: FileData | null): string | null => {
|
|
26
|
-
if (!file || typeof file.size !== 'number') return null;
|
|
27
|
-
return `Размер: ${file.size}`;
|
|
28
|
-
},
|
|
29
|
-
},
|
|
47
|
+
formatters: { ...defaultFormatters },
|
|
30
48
|
messages: {
|
|
31
49
|
'chonky.toolbar.searchPlaceholder': 'Поиск',
|
|
32
50
|
'chonky.toolbar.visibleFileCount': `{fileCount, plural,
|
|
@@ -69,25 +87,7 @@ const russianI18n: I18nConfig = {
|
|
|
69
87
|
|
|
70
88
|
const hebrewI18n: I18nConfig = {
|
|
71
89
|
locale: SupportedLocales.HE,
|
|
72
|
-
formatters: {
|
|
73
|
-
formatFileModDate: (
|
|
74
|
-
intl: IntlShape,
|
|
75
|
-
file: FileData | null
|
|
76
|
-
): string | null => {
|
|
77
|
-
const safeModDate = FileHelper.getModDate(file);
|
|
78
|
-
if (safeModDate) {
|
|
79
|
-
return `${intl.formatTime(safeModDate)} ,${intl.formatDate(
|
|
80
|
-
safeModDate
|
|
81
|
-
)}`;
|
|
82
|
-
} else {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
formatFileSize: (intl: IntlShape, file: FileData | null): string | null => {
|
|
87
|
-
if (!file || typeof file.size !== 'number') return null;
|
|
88
|
-
return `גודל: ${file.size}`;
|
|
89
|
-
},
|
|
90
|
-
},
|
|
90
|
+
formatters: { ...defaultFormatters },
|
|
91
91
|
messages: {
|
|
92
92
|
'chonky.toolbar.searchPlaceholder': 'חיפוש',
|
|
93
93
|
'chonky.toolbar.visibleFileCount': `{fileCount, plural,
|
|
@@ -128,8 +128,10 @@ const hebrewI18n: I18nConfig = {
|
|
|
128
128
|
};
|
|
129
129
|
|
|
130
130
|
const localization: ILocalization = {
|
|
131
|
+
[SupportedLocales.EN]: englishI18n,
|
|
131
132
|
[SupportedLocales.RU]: russianI18n,
|
|
132
133
|
[SupportedLocales.HE]: hebrewI18n,
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
export default localization;
|
|
137
|
+
/* eslint-enable */
|