@streamscloud/kit 0.0.1-1770364570820
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/dist/core/continuation-token.d.ts +10 -0
- package/dist/core/continuation-token.js +32 -0
- package/dist/core/css/index.d.ts +1 -0
- package/dist/core/css/index.js +1 -0
- package/dist/core/css/style-functions.d.ts +5 -0
- package/dist/core/css/style-functions.js +12 -0
- package/dist/core/cursor-result.d.ts +9 -0
- package/dist/core/cursor-result.js +1 -0
- package/dist/core/data-loaders/cursor-data-loader-with-search.svelte.d.ts +19 -0
- package/dist/core/data-loaders/cursor-data-loader-with-search.svelte.js +57 -0
- package/dist/core/data-loaders/cursor-data-loader.svelte.d.ts +13 -0
- package/dist/core/data-loaders/cursor-data-loader.svelte.js +33 -0
- package/dist/core/data-loaders/data-loader.d.ts +4 -0
- package/dist/core/data-loaders/data-loader.js +1 -0
- package/dist/core/data-loaders/index.d.ts +4 -0
- package/dist/core/data-loaders/index.js +4 -0
- package/dist/core/data-loaders/page-data-loader.svelte.d.ts +15 -0
- package/dist/core/data-loaders/page-data-loader.svelte.js +37 -0
- package/dist/core/deferred.d.ts +6 -0
- package/dist/core/deferred.js +13 -0
- package/dist/core/event-dispatcher.d.ts +9 -0
- package/dist/core/event-dispatcher.js +28 -0
- package/dist/core/files/base64-helper.d.ts +4 -0
- package/dist/core/files/base64-helper.js +22 -0
- package/dist/core/files/blob-storage.d.ts +1 -0
- package/dist/core/files/blob-storage.js +19 -0
- package/dist/core/files/file-helper.d.ts +6 -0
- package/dist/core/files/file-helper.js +27 -0
- package/dist/core/files/file-service.d.ts +4 -0
- package/dist/core/files/file-service.js +54 -0
- package/dist/core/files/file-types.d.ts +16 -0
- package/dist/core/files/file-types.js +28 -0
- package/dist/core/files/file-with-blob-data-helper.d.ts +19 -0
- package/dist/core/files/file-with-blob-data-helper.js +86 -0
- package/dist/core/files/files-provider.d.ts +8 -0
- package/dist/core/files/files-provider.js +38 -0
- package/dist/core/files/image-resizer.d.ts +31 -0
- package/dist/core/files/image-resizer.js +92 -0
- package/dist/core/files/index.d.ts +9 -0
- package/dist/core/files/index.js +9 -0
- package/dist/core/files/types.d.ts +12 -0
- package/dist/core/files/types.js +10 -0
- package/dist/core/graphql.d.ts +4 -0
- package/dist/core/graphql.js +10 -0
- package/dist/core/handle-generator.d.ts +1 -0
- package/dist/core/handle-generator.js +32 -0
- package/dist/core/i18n/index.d.ts +1 -0
- package/dist/core/i18n/index.js +1 -0
- package/dist/core/i18n/plural.d.ts +14 -0
- package/dist/core/i18n/plural.js +18 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +6 -0
- package/dist/core/repository/index.d.ts +2 -0
- package/dist/core/repository/index.js +2 -0
- package/dist/core/repository/map-container.svelte.d.ts +9 -0
- package/dist/core/repository/map-container.svelte.js +22 -0
- package/dist/core/repository/repository-notifier.d.ts +19 -0
- package/dist/core/repository/repository-notifier.js +88 -0
- package/dist/core/repository/repository.svelte.d.ts +2 -0
- package/dist/core/repository/repository.svelte.js +59 -0
- package/dist/core/repository/types.d.ts +15 -0
- package/dist/core/repository/types.js +1 -0
- package/dist/core/theme/app-theme.svelte.d.ts +15 -0
- package/dist/core/theme/app-theme.svelte.js +48 -0
- package/dist/core/theme/index.d.ts +4 -0
- package/dist/core/theme/index.js +3 -0
- package/dist/core/theme/theme-cookie.d.ts +5 -0
- package/dist/core/theme/theme-cookie.js +19 -0
- package/dist/core/theme/types.d.ts +5 -0
- package/dist/core/theme/types.js +8 -0
- package/dist/core/toastr/index.d.ts +3 -0
- package/dist/core/toastr/index.js +2 -0
- package/dist/core/toastr/toaster-host.svelte.d.ts +5 -0
- package/dist/core/toastr/toaster-host.svelte.js +40 -0
- package/dist/core/toastr/toastr.scss +27 -0
- package/dist/core/toastr/toastr.svelte.d.ts +8 -0
- package/dist/core/toastr/toastr.svelte.js +27 -0
- package/dist/core/toastr/types.d.ts +14 -0
- package/dist/core/toastr/types.js +1 -0
- package/dist/core/transitions/index.d.ts +1 -0
- package/dist/core/transitions/index.js +1 -0
- package/dist/core/transitions/slide-horizontally.d.ts +8 -0
- package/dist/core/transitions/slide-horizontally.js +54 -0
- package/dist/core/utils/array-helper.d.ts +21 -0
- package/dist/core/utils/array-helper.js +130 -0
- package/dist/core/utils/base64-serializer.d.ts +4 -0
- package/dist/core/utils/base64-serializer.js +21 -0
- package/dist/core/utils/browser.d.ts +1 -0
- package/dist/core/utils/browser.js +1 -0
- package/dist/core/utils/date-helper.d.ts +51 -0
- package/dist/core/utils/date-helper.js +244 -0
- package/dist/core/utils/dom-helper.d.ts +10 -0
- package/dist/core/utils/dom-helper.js +34 -0
- package/dist/core/utils/href-validator.d.ts +22 -0
- package/dist/core/utils/href-validator.js +52 -0
- package/dist/core/utils/html-helper.d.ts +12 -0
- package/dist/core/utils/html-helper.js +104 -0
- package/dist/core/utils/index.d.ts +13 -0
- package/dist/core/utils/index.js +13 -0
- package/dist/core/utils/lazy-init.d.ts +1 -0
- package/dist/core/utils/lazy-init.js +7 -0
- package/dist/core/utils/number-helper.d.ts +5 -0
- package/dist/core/utils/number-helper.js +32 -0
- package/dist/core/utils/string-generator.d.ts +2 -0
- package/dist/core/utils/string-generator.js +5 -0
- package/dist/core/utils/string-helper.d.ts +12 -0
- package/dist/core/utils/string-helper.js +75 -0
- package/dist/core/utils/url-helper.d.ts +3 -0
- package/dist/core/utils/url-helper.js +13 -0
- package/dist/core/utils/utils.d.ts +29 -0
- package/dist/core/utils/utils.js +108 -0
- package/dist/core/validation/form-validation-handler/form-validation-handler.svelte.d.ts +47 -0
- package/dist/core/validation/form-validation-handler/form-validation-handler.svelte.js +182 -0
- package/dist/core/validation/form-validation-handler/index.d.ts +4 -0
- package/dist/core/validation/form-validation-handler/index.js +3 -0
- package/dist/core/validation/form-validation-handler/stub-form-validator.d.ts +5 -0
- package/dist/core/validation/form-validation-handler/stub-form-validator.js +12 -0
- package/dist/core/validation/form-validation-handler/types.d.ts +10 -0
- package/dist/core/validation/form-validation-handler/types.js +1 -0
- package/dist/core/validation/form-validation-handler/yup-form-validator.d.ts +11 -0
- package/dist/core/validation/form-validation-handler/yup-form-validator.js +49 -0
- package/dist/core/validation/form-validator.svelte.d.ts +12 -0
- package/dist/core/validation/form-validator.svelte.js +21 -0
- package/dist/core/validation/i-validator.d.ts +6 -0
- package/dist/core/validation/i-validator.js +1 -0
- package/dist/core/validation/index.d.ts +5 -0
- package/dist/core/validation/index.js +4 -0
- package/dist/core/validation/validation-schemas/email-validation.d.ts +3 -0
- package/dist/core/validation/validation-schemas/email-validation.js +17 -0
- package/dist/core/validation/validation-schemas/handle-validations.d.ts +3 -0
- package/dist/core/validation/validation-schemas/handle-validations.js +16 -0
- package/dist/core/validation/validation-schemas/index.d.ts +6 -0
- package/dist/core/validation/validation-schemas/index.js +5 -0
- package/dist/core/validation/validation-schemas/number-validations.d.ts +4 -0
- package/dist/core/validation/validation-schemas/number-validations.js +30 -0
- package/dist/core/validation/validation-schemas/text-validations.d.ts +4 -0
- package/dist/core/validation/validation-schemas/text-validations.js +19 -0
- package/dist/core/validation/validation-schemas/types.d.ts +19 -0
- package/dist/core/validation/validation-schemas/types.js +1 -0
- package/dist/core/validation/validation-schemas/validation-messages.d.ts +11 -0
- package/dist/core/validation/validation-schemas/validation-messages.js +14 -0
- package/dist/core/validation/validators-hub.svelte.d.ts +14 -0
- package/dist/core/validation/validators-hub.svelte.js +51 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +2 -0
- package/package.json +125 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isBrowser } from '../utils';
|
|
2
|
+
import { APP_THEME_COOKIE, APP_THEME_VALUES } from './types';
|
|
3
|
+
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365; // 1 year
|
|
4
|
+
export const ThemeCookie = {
|
|
5
|
+
get: () => {
|
|
6
|
+
if (!isBrowser()) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const match = document.cookie.match(new RegExp(`${APP_THEME_COOKIE}=([^;]+)`));
|
|
10
|
+
const value = match?.[1];
|
|
11
|
+
return APP_THEME_VALUES.find((theme) => theme === value) ?? null;
|
|
12
|
+
},
|
|
13
|
+
set: (value) => {
|
|
14
|
+
if (!isBrowser()) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
document.cookie = `${APP_THEME_COOKIE}=${value};path=/;max-age=${COOKIE_MAX_AGE};SameSite=Lax`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const APP_THEME_COOKIE = "app-theme";
|
|
2
|
+
export declare const APP_THEME_VALUES: readonly ["auto", "light", "dark"];
|
|
3
|
+
export type AppThemeValue = (typeof APP_THEME_VALUES)[number];
|
|
4
|
+
export declare const isValidTheme: (value: string | undefined) => value is AppThemeValue;
|
|
5
|
+
export declare const getColorScheme: (theme: AppThemeValue) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const APP_THEME_COOKIE = 'app-theme';
|
|
2
|
+
export const APP_THEME_VALUES = ['auto', 'light', 'dark'];
|
|
3
|
+
export const isValidTheme = (value) => {
|
|
4
|
+
return APP_THEME_VALUES.some((theme) => theme === value);
|
|
5
|
+
};
|
|
6
|
+
export const getColorScheme = (theme) => {
|
|
7
|
+
return theme === 'auto' ? 'light dark' : theme;
|
|
8
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AppTheme } from '../theme';
|
|
2
|
+
import { mount, tick } from 'svelte';
|
|
3
|
+
import { Toaster } from 'svelte-sonner';
|
|
4
|
+
export class ToasterHost {
|
|
5
|
+
static _ready = false;
|
|
6
|
+
static _mountPromise = null;
|
|
7
|
+
static async ensure() {
|
|
8
|
+
if (this._ready) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (this._mountPromise) {
|
|
12
|
+
return this._mountPromise;
|
|
13
|
+
}
|
|
14
|
+
if (typeof document === 'undefined') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this._mountPromise = (async () => {
|
|
18
|
+
const container = document.createElement('div');
|
|
19
|
+
container.id = 'toastr-container';
|
|
20
|
+
document.body.appendChild(container);
|
|
21
|
+
mount(Toaster, {
|
|
22
|
+
target: container,
|
|
23
|
+
props: {
|
|
24
|
+
richColors: true,
|
|
25
|
+
position: 'bottom-right',
|
|
26
|
+
closeButton: true,
|
|
27
|
+
visibleToasts: 4,
|
|
28
|
+
get theme() {
|
|
29
|
+
return AppTheme.isDarkMode ? 'dark' : 'light';
|
|
30
|
+
},
|
|
31
|
+
style: 'font-family: inherit;',
|
|
32
|
+
toastOptions: { class: 'sc-toast' }
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
await tick();
|
|
36
|
+
this._ready = true;
|
|
37
|
+
})();
|
|
38
|
+
return this._mountPromise;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.sc-toast[data-sonner-toast] {
|
|
2
|
+
font-family: inherit;
|
|
3
|
+
--toast-close-button-start: auto;
|
|
4
|
+
--toast-close-button-end: 0;
|
|
5
|
+
--toast-close-button-transform: translate(35%, -35%);
|
|
6
|
+
|
|
7
|
+
// Action button - type-specific styles (inverted colors for contrast)
|
|
8
|
+
&[data-type='success'] [data-button] {
|
|
9
|
+
background: var(--success-text);
|
|
10
|
+
color: var(--success-bg);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&[data-type='error'] [data-button] {
|
|
14
|
+
background: var(--error-text);
|
|
15
|
+
color: var(--error-bg);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&[data-type='warning'] [data-button] {
|
|
19
|
+
background: var(--warning-text);
|
|
20
|
+
color: var(--warning-bg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&[data-type='info'] [data-button] {
|
|
24
|
+
background: var(--info-text);
|
|
25
|
+
color: var(--info-bg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToastrOptions, ToastrPromiseMessages } from './types';
|
|
2
|
+
export declare class Toastr {
|
|
3
|
+
static error(message: string, options?: ToastrOptions): Promise<void>;
|
|
4
|
+
static success(message: string, options?: ToastrOptions): Promise<void>;
|
|
5
|
+
static warning(message: string, options?: ToastrOptions): Promise<void>;
|
|
6
|
+
static info(message: string, options?: ToastrOptions): Promise<void>;
|
|
7
|
+
static promise<T>(promise: Promise<T> | (() => Promise<T>), messages: ToastrPromiseMessages<T>): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ToasterHost } from './toaster-host.svelte';
|
|
2
|
+
import { toast } from 'svelte-sonner';
|
|
3
|
+
export class Toastr {
|
|
4
|
+
static async error(message, options) {
|
|
5
|
+
await ToasterHost.ensure();
|
|
6
|
+
toast.error(message, patchOptions(options));
|
|
7
|
+
}
|
|
8
|
+
static async success(message, options) {
|
|
9
|
+
await ToasterHost.ensure();
|
|
10
|
+
toast.success(message, patchOptions(options));
|
|
11
|
+
}
|
|
12
|
+
static async warning(message, options) {
|
|
13
|
+
await ToasterHost.ensure();
|
|
14
|
+
toast.warning(message, patchOptions(options));
|
|
15
|
+
}
|
|
16
|
+
static async info(message, options) {
|
|
17
|
+
await ToasterHost.ensure();
|
|
18
|
+
toast.info(message, patchOptions(options));
|
|
19
|
+
}
|
|
20
|
+
static async promise(promise, messages) {
|
|
21
|
+
await ToasterHost.ensure();
|
|
22
|
+
toast.promise(promise, messages);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const patchOptions = (options) => {
|
|
26
|
+
return { ...options, duration: 100000 };
|
|
27
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ToastrAction {
|
|
2
|
+
label: string;
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
}
|
|
5
|
+
export interface ToastrOptions {
|
|
6
|
+
action?: ToastrAction;
|
|
7
|
+
description?: string;
|
|
8
|
+
duration?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ToastrPromiseMessages<T> {
|
|
11
|
+
loading: string;
|
|
12
|
+
success: string | ((data: T) => string);
|
|
13
|
+
error: string | ((error: unknown) => string);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { slideHorizontally } from './slide-horizontally';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { slideHorizontally } from './slide-horizontally';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TransitionConfig } from 'svelte/transition';
|
|
2
|
+
interface SlideHorizontallyOptions {
|
|
3
|
+
delay?: number;
|
|
4
|
+
duration?: number;
|
|
5
|
+
easing?: (t: number) => number;
|
|
6
|
+
}
|
|
7
|
+
export declare const slideHorizontally: (node: HTMLElement, { delay, duration, easing }?: SlideHorizontallyOptions) => TransitionConfig;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { sineInOut } from 'svelte/easing';
|
|
2
|
+
export const slideHorizontally = (node, { delay = 0, duration = 400, easing = sineInOut } = {}) => {
|
|
3
|
+
const style = getComputedStyle(node);
|
|
4
|
+
const isHtmlElement = (n) => n.nodeType === Node.ELEMENT_NODE;
|
|
5
|
+
const children = Array.from(node.children).filter(isHtmlElement);
|
|
6
|
+
children.forEach((child) => {
|
|
7
|
+
const childStyle = getComputedStyle(child);
|
|
8
|
+
child.style.width = childStyle.width;
|
|
9
|
+
child.style.minWidth = childStyle.width;
|
|
10
|
+
child.style.maxWidth = childStyle.maxWidth;
|
|
11
|
+
});
|
|
12
|
+
const opacity = +style.opacity;
|
|
13
|
+
const width = parseFloat(style.width);
|
|
14
|
+
const paddingLeft = parseFloat(style.paddingLeft);
|
|
15
|
+
const paddingRight = parseFloat(style.paddingRight);
|
|
16
|
+
const marginLeft = parseFloat(style.marginLeft);
|
|
17
|
+
const marginRight = parseFloat(style.marginRight);
|
|
18
|
+
const borderLeftWidth = parseFloat(style.borderLeftWidth);
|
|
19
|
+
const borderRightWidth = parseFloat(style.borderRightWidth);
|
|
20
|
+
let initialT = undefined;
|
|
21
|
+
let initialU = undefined;
|
|
22
|
+
return {
|
|
23
|
+
delay,
|
|
24
|
+
duration,
|
|
25
|
+
easing,
|
|
26
|
+
css: (t, u) => {
|
|
27
|
+
if (initialT === undefined) {
|
|
28
|
+
initialT = t;
|
|
29
|
+
}
|
|
30
|
+
if (initialU === undefined) {
|
|
31
|
+
initialU = u;
|
|
32
|
+
}
|
|
33
|
+
return ('overflow: hidden;' +
|
|
34
|
+
`opacity: ${Math.min(t, 1) * opacity};` +
|
|
35
|
+
`width: ${t * width}px;` +
|
|
36
|
+
`min-width: ${t * width}px;` +
|
|
37
|
+
`padding-left: ${t * paddingLeft}px;` +
|
|
38
|
+
`padding-right: ${t * paddingRight}px;` +
|
|
39
|
+
`margin-left: ${t * marginLeft}px;` +
|
|
40
|
+
`margin-right: ${t * marginRight}px;` +
|
|
41
|
+
`border-left-width: ${t * borderLeftWidth}px;` +
|
|
42
|
+
`border-right-width: ${t * borderRightWidth}px;`);
|
|
43
|
+
},
|
|
44
|
+
tick: (t, u) => {
|
|
45
|
+
if ((initialT === 0 && t === 1) || (initialU === 0 && u === 1)) {
|
|
46
|
+
children.forEach((child) => {
|
|
47
|
+
child.style.width = '';
|
|
48
|
+
child.style.minWidth = '';
|
|
49
|
+
child.style.maxWidth = '';
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class ArrayHelper {
|
|
2
|
+
static distinct<T>(items: T[]): T[];
|
|
3
|
+
static distinctBy<T>(items: T[], keyFn: (elem: T) => unknown): T[];
|
|
4
|
+
static intersect<T>(arrays: T[][]): T[];
|
|
5
|
+
static assertHasValue<T>(value: T | null | undefined): value is T;
|
|
6
|
+
/**
|
|
7
|
+
* Find position ("from" and "to" indexes) of the element that was moved inside array (only one element should be moved)
|
|
8
|
+
*/
|
|
9
|
+
static findMovedElement(initial: unknown[], modified: unknown[]): {
|
|
10
|
+
from: number;
|
|
11
|
+
to: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
static moveArrayItem<T>(arr: ReadonlyArray<T>, from: number, to: number): T[];
|
|
14
|
+
static replaceArrayItem<T>(arr: T[], originalItem: T, newItem: T): T[];
|
|
15
|
+
static sortArray<T>(array: Array<T> | ReadonlyArray<T>, propertyFunc: (elem: T) => unknown): T[];
|
|
16
|
+
static sortArrayDescending<T>(array: T[], propertyFunc: (elem: T) => unknown): T[];
|
|
17
|
+
static groupBy<T>(array: T[], keyResolver: (elem: T) => string): Record<string, T[]>;
|
|
18
|
+
static repeat<T>(itemFn: (i: number) => T, length: number): T[];
|
|
19
|
+
static areEqual<T>(array1?: T[] | null, array2?: T[] | null): boolean;
|
|
20
|
+
private static sortArrayInternal;
|
|
21
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export class ArrayHelper {
|
|
2
|
+
static distinct(items) {
|
|
3
|
+
return Array.from(new Set(items));
|
|
4
|
+
}
|
|
5
|
+
static distinctBy(items, keyFn) {
|
|
6
|
+
return Array.from(new Map(items.map((item) => [keyFn(item), item])).values());
|
|
7
|
+
}
|
|
8
|
+
static intersect(arrays) {
|
|
9
|
+
if (!arrays?.length) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return arrays.reduce((result, current) => result.filter((item) => current.includes(item)));
|
|
13
|
+
}
|
|
14
|
+
static assertHasValue(value) {
|
|
15
|
+
return value !== null && value !== undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Find position ("from" and "to" indexes) of the element that was moved inside array (only one element should be moved)
|
|
19
|
+
*/
|
|
20
|
+
static findMovedElement(initial, modified) {
|
|
21
|
+
if (initial.length !== modified.length) {
|
|
22
|
+
throw new Error('Arrays should have the same number of elements.');
|
|
23
|
+
}
|
|
24
|
+
if (initial.length !== new Set(initial).size || modified.length !== new Set(modified).size) {
|
|
25
|
+
throw new Error("Arrays shouldn't have duplicates.");
|
|
26
|
+
}
|
|
27
|
+
const res = { from: -1, to: -1 };
|
|
28
|
+
let i = 0;
|
|
29
|
+
for (i; i < initial.length; i++) {
|
|
30
|
+
if (initial[i] !== modified[i]) {
|
|
31
|
+
if (initial[i] === modified[i + 1]) {
|
|
32
|
+
res.to = i;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
res.from = i;
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (i === initial.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let j = initial.length;
|
|
44
|
+
for (j; j > i; j--) {
|
|
45
|
+
if (initial[j] !== modified[j]) {
|
|
46
|
+
if (res.from === -1) {
|
|
47
|
+
res.from = j;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
res.to = j;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
static moveArrayItem(arr, from, to) {
|
|
58
|
+
if (!arr?.length || from < 0 || from >= arr.length || to < 0 || to >= arr.length || from === to) {
|
|
59
|
+
return [...arr];
|
|
60
|
+
}
|
|
61
|
+
const cloned = [...arr];
|
|
62
|
+
cloned.splice(to, 0, cloned.splice(from, 1)[0]);
|
|
63
|
+
return cloned;
|
|
64
|
+
}
|
|
65
|
+
static replaceArrayItem(arr, originalItem, newItem) {
|
|
66
|
+
const index = arr.indexOf(originalItem);
|
|
67
|
+
if (index < 0) {
|
|
68
|
+
return arr;
|
|
69
|
+
}
|
|
70
|
+
const cloned = [...arr];
|
|
71
|
+
cloned.splice(index, 1, newItem);
|
|
72
|
+
return cloned;
|
|
73
|
+
}
|
|
74
|
+
static sortArray(array, propertyFunc) {
|
|
75
|
+
return ArrayHelper.sortArrayInternal(array, true, propertyFunc);
|
|
76
|
+
}
|
|
77
|
+
static sortArrayDescending(array, propertyFunc) {
|
|
78
|
+
return ArrayHelper.sortArrayInternal(array, false, propertyFunc);
|
|
79
|
+
}
|
|
80
|
+
static groupBy(array, keyResolver) {
|
|
81
|
+
return array.reduce((resultValue, value) => {
|
|
82
|
+
const groupKey = keyResolver(value);
|
|
83
|
+
(resultValue[groupKey] = resultValue[groupKey] || []).push(value);
|
|
84
|
+
return resultValue;
|
|
85
|
+
}, {});
|
|
86
|
+
}
|
|
87
|
+
static repeat(itemFn, length) {
|
|
88
|
+
return [...Array(length)].map((_, i) => itemFn(i));
|
|
89
|
+
}
|
|
90
|
+
static areEqual(array1, array2) {
|
|
91
|
+
if (array1 === array2) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (!array1 && !array2) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (!array1 || !array2) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return array1.length === array2.length && array1.every((element, index) => element === array2[index]);
|
|
101
|
+
}
|
|
102
|
+
static sortArrayInternal(array, ascending, propertyFunc) {
|
|
103
|
+
const clone = [...array];
|
|
104
|
+
return clone.sort((val1, val2) => {
|
|
105
|
+
const a = propertyFunc(val1);
|
|
106
|
+
const b = propertyFunc(val2);
|
|
107
|
+
const left = ascending ? a : b;
|
|
108
|
+
const right = ascending ? b : a;
|
|
109
|
+
if (!left && !right) {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
if (!left) {
|
|
113
|
+
return -1;
|
|
114
|
+
}
|
|
115
|
+
if (!right) {
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
if (typeof left === 'string' && typeof right === 'string') {
|
|
119
|
+
return left.localeCompare(right);
|
|
120
|
+
}
|
|
121
|
+
if (left < right) {
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
124
|
+
if (left > right) {
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
return 0;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class Base64Serializer {
|
|
2
|
+
// Encode a Unicode string to base64 (browser safe)
|
|
3
|
+
static encodeString = (str) => {
|
|
4
|
+
// Convert string to UTF-8 bytes
|
|
5
|
+
const utf8Bytes = new TextEncoder().encode(str);
|
|
6
|
+
// Convert bytes to binary string
|
|
7
|
+
let binary = '';
|
|
8
|
+
utf8Bytes.forEach((b) => (binary += String.fromCharCode(b)));
|
|
9
|
+
// Encode binary string to base64
|
|
10
|
+
return btoa(binary);
|
|
11
|
+
};
|
|
12
|
+
// Decode a base64 string back to Unicode (browser safe)
|
|
13
|
+
static decodeToString = (b64) => {
|
|
14
|
+
// Decode base64 to binary string
|
|
15
|
+
const binary = atob(b64);
|
|
16
|
+
// Convert binary string to UTF-8 bytes
|
|
17
|
+
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
18
|
+
// Decode UTF-8 bytes back to string
|
|
19
|
+
return new TextDecoder().decode(bytes);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isBrowser: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isBrowser = () => typeof window !== 'undefined';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare class DateHelper {
|
|
2
|
+
static toDate(date: LikeDate, resetTime?: boolean): Date;
|
|
3
|
+
static addMonths(date: LikeDate, months?: number): Date;
|
|
4
|
+
static addDays(date: LikeDate, days: number): Date;
|
|
5
|
+
static secondsToTimeRepresentation(seconds: number, duration: number): string;
|
|
6
|
+
static getDate(date: LikeDate): number;
|
|
7
|
+
static getYear(date: LikeDate): number;
|
|
8
|
+
static getDiffInDays(date1: LikeDate, date2: LikeDate): number;
|
|
9
|
+
static getMonthName(date: LikeDate, locale: string, short?: boolean): string;
|
|
10
|
+
static getWeekdayName(date: LikeDate, locale: string, short?: boolean): string;
|
|
11
|
+
static getMonthRange(date: LikeDate): MonthRange;
|
|
12
|
+
static daysInMonth(date: LikeDate): number;
|
|
13
|
+
static getDayOfWeek(date: LikeDate): number;
|
|
14
|
+
static getShiftedDate(date: LikeDate, daysShift: number): Date;
|
|
15
|
+
static getDateOnlyString(date: LikeDate): string;
|
|
16
|
+
static formatDateRange(startDate: LikeDate, endDate: LikeDate, locale: string): string;
|
|
17
|
+
static dateRangeDescriptionString(startDate: LikeDate, endDate: LikeDate | null | undefined, locale: string): string;
|
|
18
|
+
static toDefaultDateTimeRepresentation: (val: LikeDate, locale: string, alwaysIncludeYear?: boolean) => string;
|
|
19
|
+
static addYears(dateToModify: LikeDate, yearsToAdd: number, resetTime?: boolean): Date;
|
|
20
|
+
static startOfLastWeek(): string;
|
|
21
|
+
static endOfLastWeek(): string;
|
|
22
|
+
static startOfLastMonth(): string;
|
|
23
|
+
static endOfLastMonth(): string;
|
|
24
|
+
static startOfLastYear(): string;
|
|
25
|
+
static endOfLastYear(): string;
|
|
26
|
+
static startOfRollingDays(days: number): string;
|
|
27
|
+
static endOfRollingDays(): string;
|
|
28
|
+
static startOfCurrentMonthToNow(): {
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
};
|
|
32
|
+
static startOfCurrentYearToNow(): {
|
|
33
|
+
from: string;
|
|
34
|
+
to: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare class DateFormatOptions {
|
|
38
|
+
static dateTimeFormat: Intl.DateTimeFormatOptions;
|
|
39
|
+
static dateTimeWithoutYearFormat: Intl.DateTimeFormatOptions;
|
|
40
|
+
static timeFormat: Intl.DateTimeFormatOptions;
|
|
41
|
+
static dateFormat: Intl.DateTimeFormatOptions;
|
|
42
|
+
static dateNumericFormat: Intl.DateTimeFormatOptions;
|
|
43
|
+
static dateFormatWithoutYear: Intl.DateTimeFormatOptions;
|
|
44
|
+
static dateFullMonthFormat: Intl.DateTimeFormatOptions;
|
|
45
|
+
}
|
|
46
|
+
export type MonthRange = {
|
|
47
|
+
firstDay: Date;
|
|
48
|
+
lastDay: Date;
|
|
49
|
+
};
|
|
50
|
+
type LikeDate = string | number | Date;
|
|
51
|
+
export {};
|