feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev
2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import Cookies from 'js-cookie';
import { jwtDecode } from 'jwt-decode';

View File

@@ -0,0 +1,15 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const SEARCH_PARTS_REGEX = /[ ,;]+/; // TODO: move to utils
export default (search) =>
search.split(SEARCH_PARTS_REGEX).flatMap((searchPart) => {
if (!searchPart) {
return [];
}
return searchPart.toLowerCase();
});

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
export const focusEnd = (element) => {
element.focus();
element.setSelectionRange(element.value.length + 1, element.value.length + 1);
@@ -6,3 +11,6 @@ export const focusEnd = (element) => {
export const isActiveTextElement = (element) =>
['input', 'textarea'].includes(element.tagName.toLowerCase()) &&
element === document.activeElement;
export const isUsableMarkdownElement = (element) =>
!!element.closest('.yfm a, .yfm-clipboard-button, .yfm-cut-title');

View File

@@ -0,0 +1,9 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import Config from '../constants/Config';
// eslint-disable-next-line import/prefer-default-export
export const isModifierKeyPressed = (event) => (Config.IS_MAC ? event.metaKey : event.ctrlKey);

View File

@@ -1,5 +1,10 @@
export default (value, longDateFormat = 'longDateTime', fullDateFormat = 'fullDateTime') => {
const year = value.getFullYear();
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
export default (date, longDateFormat = 'longDateTime', fullDateFormat = 'fullDateTime') => {
const year = date.getFullYear();
const currentYear = new Date().getFullYear();
return year === currentYear ? longDateFormat : fullDateFormat;

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
export const createLocalId = () => `local:${Date.now()}`;
export const isLocalId = (id) => id.startsWith('local:');

View File

@@ -0,0 +1,27 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import transform from '@diplodoc/transform';
import plugins from '../configs/markdown-plugins';
export default (markdown) => {
const tokens = transform(markdown, {
plugins,
tokens: true,
});
return tokens
.flatMap((token) => {
if (!token.children) {
return [];
}
return token.children
.flatMap((childrenToken) => (childrenToken.type === 'text' ? childrenToken.content : []))
.join('');
})
.join('\n');
};

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import { matchPath } from 'react-router-dom';
export default (pathname, paths) => {

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const mergeRecords = (target, ...sources) => {
if (sources.length === 0) {
return target;

View File

@@ -0,0 +1,6 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
export default (dndId) => dndId.split(':')[1];

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import parseDate from 'date-fns/parse';
const TIME_REGEX =

View File

@@ -0,0 +1,14 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import { ListTypes, UserRoles } from '../constants/Enums';
export const isUserAdminOrProjectOwner = (user) =>
[UserRoles.ADMIN, UserRoles.PROJECT_OWNER].includes(user.role);
export const isListArchiveOrTrash = (list) =>
[ListTypes.ARCHIVE, ListTypes.TRASH].includes(list.type);
export const isListFinite = (list) => [ListTypes.ACTIVE, ListTypes.CLOSED].includes(list.type);

View File

@@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const getFullSeconds = ({ startedAt, total }) => {
if (startedAt) {
return Math.floor((new Date() - startedAt) / 1000) + total;
@@ -42,6 +47,5 @@ export const getStopwatchParts = (stopwatch) => {
export const formatStopwatch = (stopwatch) => {
const { hours, minutes, seconds } = getStopwatchParts(stopwatch);
return [hours, ...[minutes, seconds].map((part) => (part < 10 ? `0${part}` : part))].join(':');
};

View File

@@ -1,7 +1,20 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import isURL from 'validator/lib/isURL';
import zxcvbn from 'zxcvbn';
const USERNAME_REGEX = /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/;
export const isUrl = (string) =>
isURL(string, {
protocols: ['http', 'https'],
require_protocol: true,
max_allowed_length: 2048,
});
export const isPassword = (string) => zxcvbn(string).score >= 2; // TODO: move to config
export const isUsername = (string) =>