mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19:44 +02:00
parent
0b3b6a30fc
commit
309c2ed762
4 changed files with 52 additions and 39 deletions
|
@ -28,7 +28,7 @@ const AttachmentAddStep = React.memo(({ onCreate, onClose }) => {
|
||||||
</Popup.Header>
|
</Popup.Header>
|
||||||
<Popup.Content>
|
<Popup.Content>
|
||||||
<Menu secondary vertical className={styles.menu}>
|
<Menu secondary vertical className={styles.menu}>
|
||||||
<FilePicker onSelect={handleFileSelect}>
|
<FilePicker multiple onSelect={handleFileSelect}>
|
||||||
<Menu.Item className={styles.menuItem}>
|
<Menu.Item className={styles.menuItem}>
|
||||||
{t('common.fromComputer', {
|
{t('common.fromComputer', {
|
||||||
context: 'title',
|
context: 'title',
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
|
||||||
import { closePopup } from '../../../lib/popup';
|
import { closePopup } from '../../../lib/popup';
|
||||||
|
|
||||||
import { useModal } from '../../../hooks';
|
import { useModal } from '../../../hooks';
|
||||||
|
import { isActiveTextElement } from '../../../utils/element-helpers';
|
||||||
import TextFileAddModal from './TextFileAddModal';
|
import TextFileAddModal from './TextFileAddModal';
|
||||||
|
|
||||||
import styles from './AttachmentAddZone.module.scss';
|
import styles from './AttachmentAddZone.module.scss';
|
||||||
|
@ -24,13 +25,14 @@ const AttachmentAddZone = React.memo(({ children, onCreate }) => {
|
||||||
|
|
||||||
const handleDropAccepted = useCallback(
|
const handleDropAccepted = useCallback(
|
||||||
(files) => {
|
(files) => {
|
||||||
submit(files[0]);
|
files.forEach((file) => {
|
||||||
|
submit(file);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[submit],
|
[submit],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
||||||
multiple: false,
|
|
||||||
noClick: true,
|
noClick: true,
|
||||||
noKeyboard: true,
|
noKeyboard: true,
|
||||||
onDropAccepted: handleDropAccepted,
|
onDropAccepted: handleDropAccepted,
|
||||||
|
@ -49,38 +51,43 @@ const AttachmentAddZone = React.memo(({ children, onCreate }) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = event.clipboardData.files[0];
|
const { files, items } = event.clipboardData;
|
||||||
|
|
||||||
if (file) {
|
if (files.length > 0) {
|
||||||
submit(file);
|
[...files].forEach((file) => {
|
||||||
return;
|
submit(file);
|
||||||
}
|
|
||||||
|
|
||||||
const item = event.clipboardData.items[0];
|
|
||||||
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.kind === 'file') {
|
|
||||||
submit(item.getAsFile());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
['input', 'textarea'].includes(event.target.tagName.toLowerCase()) &&
|
|
||||||
event.target === document.activeElement
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
closePopup();
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
item.getAsString((content) => {
|
|
||||||
openModal({
|
|
||||||
content,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items[0].kind === 'string') {
|
||||||
|
if (isActiveTextElement(event.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
closePopup();
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
items[0].getAsString((content) => {
|
||||||
|
openModal({
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[...items].forEach((item) => {
|
||||||
|
if (item.kind !== 'file') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
submit(item.getAsFile());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import styles from './FilePicker.module.css';
|
import styles from './FilePicker.module.css';
|
||||||
|
|
||||||
const FilePicker = React.memo(({ children, accept, onSelect }) => {
|
const FilePicker = React.memo(({ children, accept, multiple, onSelect }) => {
|
||||||
const field = useRef(null);
|
const field = useRef(null);
|
||||||
|
|
||||||
const handleTriggerClick = useCallback(() => {
|
const handleTriggerClick = useCallback(() => {
|
||||||
|
@ -12,11 +12,11 @@ const FilePicker = React.memo(({ children, accept, onSelect }) => {
|
||||||
|
|
||||||
const handleFieldChange = useCallback(
|
const handleFieldChange = useCallback(
|
||||||
({ target }) => {
|
({ target }) => {
|
||||||
if (target.files[0]) {
|
[...target.files].forEach((file) => {
|
||||||
onSelect(target.files[0]);
|
onSelect(file);
|
||||||
|
});
|
||||||
|
|
||||||
target.value = null; // eslint-disable-line no-param-reassign
|
target.value = null; // eslint-disable-line no-param-reassign
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[onSelect],
|
[onSelect],
|
||||||
);
|
);
|
||||||
|
@ -32,6 +32,7 @@ const FilePicker = React.memo(({ children, accept, onSelect }) => {
|
||||||
ref={field}
|
ref={field}
|
||||||
type="file"
|
type="file"
|
||||||
accept={accept}
|
accept={accept}
|
||||||
|
multiple={multiple}
|
||||||
className={styles.field}
|
className={styles.field}
|
||||||
onChange={handleFieldChange}
|
onChange={handleFieldChange}
|
||||||
/>
|
/>
|
||||||
|
@ -42,11 +43,13 @@ const FilePicker = React.memo(({ children, accept, onSelect }) => {
|
||||||
FilePicker.propTypes = {
|
FilePicker.propTypes = {
|
||||||
children: PropTypes.element.isRequired,
|
children: PropTypes.element.isRequired,
|
||||||
accept: PropTypes.string,
|
accept: PropTypes.string,
|
||||||
|
multiple: PropTypes.bool,
|
||||||
onSelect: PropTypes.func.isRequired,
|
onSelect: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
FilePicker.defaultProps = {
|
FilePicker.defaultProps = {
|
||||||
accept: undefined,
|
accept: undefined,
|
||||||
|
multiple: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FilePicker;
|
export default FilePicker;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
|
||||||
export const focusEnd = (element) => {
|
export const focusEnd = (element) => {
|
||||||
element.focus();
|
element.focus();
|
||||||
element.setSelectionRange(element.value.length + 1, element.value.length + 1);
|
element.setSelectionRange(element.value.length + 1, element.value.length + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isActiveTextElement = (element) =>
|
||||||
|
['input', 'textarea'].includes(element.tagName.toLowerCase()) &&
|
||||||
|
element === document.activeElement;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue