@rolder/kit 3.0.0-alpha.16 → 3.0.0-alpha.17

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.
@@ -0,0 +1,3 @@
1
+ export declare const AppDefaults: ({ saveColorScheme, }: {
2
+ saveColorScheme: boolean;
3
+ }) => null;
@@ -0,0 +1,27 @@
1
+ import { useComputedColorScheme } from "@mantine/core";
2
+ import { useEffect } from "react";
3
+ import { setCookies } from "../functions/index.js";
4
+ const AppDefaults = ({ saveColorScheme })=>{
5
+ const colorScheme = useComputedColorScheme();
6
+ useEffect(()=>{
7
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
8
+ const cookies = [
9
+ {
10
+ name: 'tz',
11
+ value: tz,
12
+ expires: 365
13
+ }
14
+ ];
15
+ if (saveColorScheme) cookies.push({
16
+ name: 'colorScheme',
17
+ value: colorScheme,
18
+ expires: 365
19
+ });
20
+ setCookies(cookies);
21
+ }, [
22
+ colorScheme,
23
+ saveColorScheme
24
+ ]);
25
+ return null;
26
+ };
27
+ export { AppDefaults };
@@ -0,0 +1,6 @@
1
+ import { type MantineProviderProps } from '@mantine/core';
2
+ interface Props extends MantineProviderProps {
3
+ saveColorScheme?: boolean;
4
+ }
5
+ export declare const DefaultApp: ({ children, saveColorScheme, defaultColorScheme, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,43 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { ColorSchemeScript, MantineProvider } from "@mantine/core";
3
+ import { HeadContent, Scripts } from "@tanstack/react-router";
4
+ import { getCookie } from "../functions/index.js";
5
+ import { AppDefaults } from "./AppDefaults.js";
6
+ import { cookieColorSchemeManager } from "./cookieColorSchemeManager.js";
7
+ import { defaultTheme } from "./defaultTheme.js";
8
+ const colorSchemeManager = cookieColorSchemeManager();
9
+ const DefaultApp = ({ children, saveColorScheme = true, defaultColorScheme = 'auto', ...props })=>{
10
+ const colorScheme = saveColorScheme ? getCookie('colorScheme', defaultColorScheme) : defaultColorScheme;
11
+ return /*#__PURE__*/ jsxs("html", {
12
+ lang: "ru",
13
+ suppressHydrationWarning: true,
14
+ children: [
15
+ /*#__PURE__*/ jsxs("head", {
16
+ children: [
17
+ /*#__PURE__*/ jsx(HeadContent, {}),
18
+ /*#__PURE__*/ jsx(ColorSchemeScript, {
19
+ defaultColorScheme: colorScheme
20
+ })
21
+ ]
22
+ }),
23
+ /*#__PURE__*/ jsxs("body", {
24
+ children: [
25
+ /*#__PURE__*/ jsxs(MantineProvider, {
26
+ defaultColorScheme: colorScheme,
27
+ theme: defaultTheme,
28
+ colorSchemeManager: colorSchemeManager,
29
+ ...props,
30
+ children: [
31
+ /*#__PURE__*/ jsx(AppDefaults, {
32
+ saveColorScheme: saveColorScheme
33
+ }),
34
+ children
35
+ ]
36
+ }),
37
+ /*#__PURE__*/ jsx(Scripts, {})
38
+ ]
39
+ })
40
+ ]
41
+ });
42
+ };
43
+ export { DefaultApp };
@@ -0,0 +1,6 @@
1
+ import { type MantineColorSchemeManager } from '@mantine/core';
2
+ export interface CookieColorSchemeManager {
3
+ /** Название куки, `colorScheme` по умолчанию */
4
+ key?: string;
5
+ }
6
+ export declare const cookieColorSchemeManager: ({ key, }?: CookieColorSchemeManager) => MantineColorSchemeManager;
@@ -0,0 +1,46 @@
1
+ import { isMantineColorScheme } from "@mantine/core";
2
+ import { atom } from "nanostores";
3
+ import { setCookie } from "../functions/index.js";
4
+ const $colorScheme = atom();
5
+ let unsubscribeSystemTheme;
6
+ const cookieColorSchemeManager = ({ key = 'colorScheme' } = {})=>({
7
+ get: (defaultValue)=>{
8
+ try {
9
+ return $colorScheme.get() || defaultValue;
10
+ } catch {
11
+ return defaultValue;
12
+ }
13
+ },
14
+ set: (value)=>{
15
+ try {
16
+ setCookie(key, value);
17
+ $colorScheme.set(value);
18
+ } catch (error) {
19
+ console.warn('[cookieColorSchemeManager] Ошибка при сохранении цветовой схемы в куки.', error);
20
+ }
21
+ },
22
+ subscribe: (onUpdate)=>{
23
+ $colorScheme.listen((newValue)=>{
24
+ if (isMantineColorScheme(newValue)) {
25
+ setCookie(key, newValue);
26
+ onUpdate(newValue);
27
+ }
28
+ });
29
+ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
30
+ const handleSystemThemeChange = ()=>onUpdate('auto');
31
+ mediaQuery.addEventListener('change', handleSystemThemeChange);
32
+ unsubscribeSystemTheme = ()=>mediaQuery.removeEventListener('change', handleSystemThemeChange);
33
+ },
34
+ unsubscribe: ()=>{
35
+ $colorScheme.off();
36
+ if (unsubscribeSystemTheme) {
37
+ unsubscribeSystemTheme();
38
+ unsubscribeSystemTheme = void 0;
39
+ }
40
+ },
41
+ clear: ()=>{
42
+ setCookie(key);
43
+ $colorScheme.set(void 0);
44
+ }
45
+ });
46
+ export { cookieColorSchemeManager };
@@ -0,0 +1,4 @@
1
+ export declare const defaultRequestMiddlewares: import("@tanstack/start-client-core").RequestMiddlewareAfterServer<{}, undefined, {
2
+ locale: string;
3
+ timeZone: string;
4
+ }>[];
@@ -0,0 +1,24 @@
1
+ import { createMiddleware } from "@tanstack/react-start";
2
+ import { getCookie, getRequestHeader, setCookie } from "@tanstack/react-start/server";
3
+ const defaultRequestMiddlewares_locale = createMiddleware().server(async ({ next })=>{
4
+ const header = getRequestHeader('accept-language');
5
+ const headerLocale = header?.split(',')[0] || 'ru-RU';
6
+ const cookieLocale = getCookie('locale');
7
+ const cookieTz = getCookie('tz');
8
+ const locale = cookieLocale || headerLocale;
9
+ const timeZone = cookieTz || 'UTC';
10
+ setCookie('locale', locale, {
11
+ path: '/',
12
+ maxAge: 31536000
13
+ });
14
+ return next({
15
+ context: {
16
+ locale,
17
+ timeZone
18
+ }
19
+ });
20
+ });
21
+ const defaultRequestMiddlewares = [
22
+ defaultRequestMiddlewares_locale
23
+ ];
24
+ export { defaultRequestMiddlewares };
@@ -0,0 +1,141 @@
1
+ export declare const defaultTheme: {
2
+ focusRing?: "auto" | "always" | "never" | undefined;
3
+ scale?: number | undefined;
4
+ fontSmoothing?: boolean | undefined;
5
+ white?: string | undefined;
6
+ black?: string | undefined;
7
+ colors?: {
8
+ [x: string & {}]: import("@mantine/core").MantineColorsTuple | undefined;
9
+ dark?: import("@mantine/core").MantineColorsTuple | undefined;
10
+ gray?: import("@mantine/core").MantineColorsTuple | undefined;
11
+ red?: import("@mantine/core").MantineColorsTuple | undefined;
12
+ pink?: import("@mantine/core").MantineColorsTuple | undefined;
13
+ grape?: import("@mantine/core").MantineColorsTuple | undefined;
14
+ violet?: import("@mantine/core").MantineColorsTuple | undefined;
15
+ indigo?: import("@mantine/core").MantineColorsTuple | undefined;
16
+ blue?: import("@mantine/core").MantineColorsTuple | undefined;
17
+ cyan?: import("@mantine/core").MantineColorsTuple | undefined;
18
+ green?: import("@mantine/core").MantineColorsTuple | undefined;
19
+ lime?: import("@mantine/core").MantineColorsTuple | undefined;
20
+ yellow?: import("@mantine/core").MantineColorsTuple | undefined;
21
+ orange?: import("@mantine/core").MantineColorsTuple | undefined;
22
+ teal?: import("@mantine/core").MantineColorsTuple | undefined;
23
+ } | undefined;
24
+ primaryShade?: import("@mantine/core").MantineColorShade | {
25
+ light?: import("@mantine/core").MantineColorShade | undefined;
26
+ dark?: import("@mantine/core").MantineColorShade | undefined;
27
+ } | undefined;
28
+ primaryColor?: string | undefined;
29
+ variantColorResolver?: import("@mantine/core").VariantColorsResolver | undefined;
30
+ autoContrast?: boolean | undefined;
31
+ luminanceThreshold?: number | undefined;
32
+ fontFamily?: string | undefined;
33
+ fontFamilyMonospace?: string | undefined;
34
+ headings?: {
35
+ fontFamily?: string | undefined;
36
+ fontWeight?: string | undefined;
37
+ textWrap?: "wrap" | "nowrap" | "balance" | "pretty" | "stable" | undefined;
38
+ sizes?: {
39
+ h1?: {
40
+ fontSize?: string | undefined;
41
+ fontWeight?: string | undefined;
42
+ lineHeight?: string | undefined;
43
+ } | undefined;
44
+ h2?: {
45
+ fontSize?: string | undefined;
46
+ fontWeight?: string | undefined;
47
+ lineHeight?: string | undefined;
48
+ } | undefined;
49
+ h3?: {
50
+ fontSize?: string | undefined;
51
+ fontWeight?: string | undefined;
52
+ lineHeight?: string | undefined;
53
+ } | undefined;
54
+ h4?: {
55
+ fontSize?: string | undefined;
56
+ fontWeight?: string | undefined;
57
+ lineHeight?: string | undefined;
58
+ } | undefined;
59
+ h5?: {
60
+ fontSize?: string | undefined;
61
+ fontWeight?: string | undefined;
62
+ lineHeight?: string | undefined;
63
+ } | undefined;
64
+ h6?: {
65
+ fontSize?: string | undefined;
66
+ fontWeight?: string | undefined;
67
+ lineHeight?: string | undefined;
68
+ } | undefined;
69
+ } | undefined;
70
+ } | undefined;
71
+ radius?: {
72
+ [x: string & {}]: string | undefined;
73
+ xs?: string | undefined;
74
+ sm?: string | undefined;
75
+ md?: string | undefined;
76
+ lg?: string | undefined;
77
+ xl?: string | undefined;
78
+ } | undefined;
79
+ defaultRadius?: import("@mantine/core").MantineRadius | undefined;
80
+ spacing?: {
81
+ [x: number]: string | undefined;
82
+ [x: string & {}]: string | undefined;
83
+ xs?: string | undefined;
84
+ sm?: string | undefined;
85
+ md?: string | undefined;
86
+ lg?: string | undefined;
87
+ xl?: string | undefined;
88
+ } | undefined;
89
+ fontSizes?: {
90
+ [x: string & {}]: string | undefined;
91
+ xs?: string | undefined;
92
+ sm?: string | undefined;
93
+ md?: string | undefined;
94
+ lg?: string | undefined;
95
+ xl?: string | undefined;
96
+ } | undefined;
97
+ lineHeights?: {
98
+ [x: string & {}]: string | undefined;
99
+ xs?: string | undefined;
100
+ sm?: string | undefined;
101
+ md?: string | undefined;
102
+ lg?: string | undefined;
103
+ xl?: string | undefined;
104
+ } | undefined;
105
+ breakpoints?: {
106
+ [x: string & {}]: string | undefined;
107
+ xs?: string | undefined;
108
+ sm?: string | undefined;
109
+ md?: string | undefined;
110
+ lg?: string | undefined;
111
+ xl?: string | undefined;
112
+ } | undefined;
113
+ shadows?: {
114
+ [x: string & {}]: string | undefined;
115
+ xs?: string | undefined;
116
+ sm?: string | undefined;
117
+ md?: string | undefined;
118
+ lg?: string | undefined;
119
+ xl?: string | undefined;
120
+ } | undefined;
121
+ respectReducedMotion?: boolean | undefined;
122
+ cursorType?: "default" | "pointer" | undefined;
123
+ defaultGradient?: {
124
+ from?: string | undefined;
125
+ to?: string | undefined;
126
+ deg?: number | undefined;
127
+ } | undefined;
128
+ activeClassName?: string | undefined;
129
+ focusClassName?: string | undefined;
130
+ components?: {
131
+ [x: string]: {
132
+ classNames?: any;
133
+ styles?: any;
134
+ vars?: any;
135
+ defaultProps?: any;
136
+ } | undefined;
137
+ } | undefined;
138
+ other?: {
139
+ [x: string]: any;
140
+ } | undefined;
141
+ };
@@ -0,0 +1,24 @@
1
+ import { Modal, createTheme } from "@mantine/core";
2
+ const defaultTheme = createTheme({
3
+ components: {
4
+ Modal: Modal.extend({
5
+ defaultProps: {
6
+ centered: true,
7
+ padding: 'lg'
8
+ }
9
+ }),
10
+ ModalTitle: Modal.Title.extend({
11
+ defaultProps: {
12
+ pr: 24
13
+ }
14
+ }),
15
+ ModalCloseButton: Modal.CloseButton.extend({
16
+ defaultProps: {
17
+ pos: 'absolute',
18
+ top: 4,
19
+ right: 4
20
+ }
21
+ })
22
+ }
23
+ });
24
+ export { defaultTheme };
@@ -0,0 +1,4 @@
1
+ export * from './AppDefaults';
2
+ export * from './DefaultApp';
3
+ export * from './defaultRequestMiddlewares';
4
+ export * from './defaultTheme';
@@ -0,0 +1,4 @@
1
+ export * from "./AppDefaults.js";
2
+ export * from "./DefaultApp.js";
3
+ export * from "./defaultRequestMiddlewares.js";
4
+ export * from "./defaultTheme.js";
@@ -0,0 +1,3 @@
1
+ export declare function getCookie<T extends string>(name: string, defaultValue: T): T;
2
+ export declare function getCookie(name: string, defaultValue: string): string;
3
+ export declare function getCookie(name: string, defaultValue?: undefined): string | undefined;
@@ -0,0 +1,8 @@
1
+ import { createIsomorphicFn } from "@tanstack/react-start";
2
+ import { getCookie } from "@tanstack/react-start/server";
3
+ import js_cookie from "js-cookie";
4
+ const getCookieImpl = createIsomorphicFn().server((name, defaultValue)=>getCookie(name) || defaultValue).client((name, defaultValue)=>js_cookie.get(name) || defaultValue);
5
+ function getCookie_getCookie(name, defaultValue) {
6
+ return getCookieImpl(name, defaultValue);
7
+ }
8
+ export { getCookie_getCookie as getCookie };
@@ -0,0 +1,3 @@
1
+ export { getCookie } from './getCookie';
2
+ export { setCookie } from './setCookie';
3
+ export { setCookies } from './setCookies';
@@ -0,0 +1,4 @@
1
+ import { getCookie } from "./getCookie.js";
2
+ import { setCookie } from "./setCookie.js";
3
+ import { setCookies } from "./setCookies.js";
4
+ export { getCookie, setCookie, setCookies };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Изоморфная функция для установки значения куки.
3
+ * На клиенте использует библиотеку js-cookie для работы с куками.
4
+ * На сервере использует функции getCookie и setCookie из tanstack start.
5
+ *
6
+ * @param {string} name - Имя куки
7
+ * @param {string} value - Значение куки, если не указано, кука будет удалена
8
+ * @param {number} [expires=7] - Количество дней до истечения срока действия куки (по умолчанию 7 дней)
9
+ */
10
+ export declare const setCookie: import("@tanstack/start-fn-stubs").IsomorphicFn<[name: string, value?: string | undefined, expires?: number | undefined], void, void>;
@@ -0,0 +1,19 @@
1
+ import { createIsomorphicFn } from "@tanstack/react-start";
2
+ import { deleteCookie, setCookie } from "@tanstack/react-start/server";
3
+ import js_cookie from "js-cookie";
4
+ const setCookie_setCookie = createIsomorphicFn().server((name, value, expires)=>{
5
+ const expiresDate = new Date();
6
+ expiresDate.setDate(expiresDate.getDate() + (expires || 7));
7
+ if (value) setCookie(name, value, {
8
+ expires: expiresDate
9
+ });
10
+ else deleteCookie(name);
11
+ }).client((name, value, expires)=>{
12
+ const expiresDate = new Date();
13
+ expiresDate.setDate(expiresDate.getDate() + (expires || 7));
14
+ if (value) js_cookie.set(name, value, {
15
+ expires: expiresDate
16
+ });
17
+ else js_cookie.remove(name);
18
+ });
19
+ export { setCookie_setCookie as setCookie };
@@ -0,0 +1,14 @@
1
+ interface Cookie {
2
+ name: string;
3
+ value?: string;
4
+ expires?: number;
5
+ }
6
+ /**
7
+ * Клиентская функция для установки значения нескольких куки.
8
+ * На клиенте использует библиотеку js-cookie для работы с куками.
9
+ * На сервере использует функции getCookie и setCookie из tanstack start.
10
+ *
11
+ * @param {Cookie[]} cookies - Массив объектов с данными куки *
12
+ */
13
+ export declare const setCookies: (cookies: Cookie[]) => void;
14
+ export {};
@@ -0,0 +1,13 @@
1
+ import { createClientOnlyFn } from "@tanstack/react-start";
2
+ import js_cookie from "js-cookie";
3
+ const setCookies = createClientOnlyFn((cookies)=>{
4
+ cookies.forEach(({ name, value, expires })=>{
5
+ const expiresDate = new Date();
6
+ expiresDate.setDate(expiresDate.getDate() + (expires || 7));
7
+ if (value) js_cookie.set(name, value, {
8
+ expires: expiresDate
9
+ });
10
+ else js_cookie.remove(name);
11
+ });
12
+ });
13
+ export { setCookies };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { IconBrandAdobeAfterEffect } from '@tabler/icons-react';
1
+ export * from './app';
2
+ export * from './functions';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { IconBrandAdobeAfterEffect } from "@tabler/icons-react";
2
- export { IconBrandAdobeAfterEffect };
1
+ export * from "./app/index.js";
2
+ export * from "./functions/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha.16",
3
+ "version": "3.0.0-alpha.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1 +0,0 @@
1
- export declare const TestIcon: () => import("react/jsx-runtime").JSX.Element;
package/dist/TestIcon.js DELETED
@@ -1,4 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { IconBrandAdobeAfterEffect } from "@tabler/icons-react";
3
- const TestIcon = ()=>/*#__PURE__*/ jsx(IconBrandAdobeAfterEffect, {});
4
- export { TestIcon };