mirror of
https://github.com/plankanban/planka.git
synced 2025-12-25 09:15:00 +03:00
@@ -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';
|
||||
|
||||
|
||||
15
client/src/utils/build-search-parts.js
Normal file
15
client/src/utils/build-search-parts.js
Normal 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();
|
||||
});
|
||||
@@ -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');
|
||||
|
||||
9
client/src/utils/event-helpers.js
Normal file
9
client/src/utils/event-helpers.js
Normal 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);
|
||||
@@ -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;
|
||||
|
||||
@@ -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:');
|
||||
|
||||
27
client/src/utils/markdown-to-text.js
Normal file
27
client/src/utils/markdown-to-text.js
Normal 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');
|
||||
};
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
6
client/src/utils/parse-dnd-id.js
Normal file
6
client/src/utils/parse-dnd-id.js
Normal 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];
|
||||
@@ -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 =
|
||||
|
||||
14
client/src/utils/record-helpers.js
Normal file
14
client/src/utils/record-helpers.js
Normal 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);
|
||||
@@ -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(':');
|
||||
};
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user