reburn-ui 0.1.7 → 0.2.0
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/adapter/adapter-bun/build.d.ts +1 -0
- package/dist/adapter/adapter-bun/build.js +22 -0
- package/dist/adapter/adapter-bun/files/handler.d.ts +3 -0
- package/dist/adapter/adapter-bun/files/handler.js +109 -0
- package/dist/adapter/adapter-bun/files/index.d.ts +1 -0
- package/dist/adapter/adapter-bun/files/index.js +89 -0
- package/dist/adapter/adapter-bun/tsconfig.json +1 -1
- package/dist/core/Notifications/NotificationContainer.svelte +56 -0
- package/dist/core/Notifications/NotificationContainer.svelte.d.ts +10 -0
- package/dist/core/Notifications/Notifications.svelte +156 -0
- package/dist/core/Notifications/Notifications.svelte.d.ts +28 -0
- package/dist/core/Notifications/NotificationsStore.svelte.d.ts +46 -0
- package/dist/core/Notifications/NotificationsStore.svelte.js +71 -0
- package/dist/core/Notifications/get-auto-close.d.ts +1 -0
- package/dist/core/Notifications/get-auto-close.js +9 -0
- package/dist/core/Notifications/notificationStackAnimation.d.ts +5 -0
- package/dist/core/Notifications/notificationStackAnimation.js +11 -0
- package/dist/core/components/CloseButton/CloseButton.svelte +6 -1
- package/dist/core/components/Floating/CreateFloating.svelte.d.ts +27 -0
- package/dist/core/components/Floating/CreateFloating.svelte.js +47 -0
- package/dist/core/components/Notification/Notification.svelte +216 -0
- package/dist/core/components/Notification/Notification.svelte.d.ts +33 -0
- package/dist/core/components/Popover/Popover.svelte +18 -24
- package/dist/core/components/Portal/Portal.svelte +8 -4
- package/dist/core/components/Progress/Progress.svelte +28 -0
- package/dist/core/components/Progress/Progress.svelte.d.ts +15 -0
- package/dist/core/components/Progress/ProgressContext.svelte.d.ts +8 -0
- package/dist/core/components/Progress/ProgressContext.svelte.js +12 -0
- package/dist/core/components/Progress/ProgressLabel.svelte +25 -0
- package/dist/core/components/Progress/ProgressLabel.svelte.d.ts +6 -0
- package/dist/core/components/Progress/ProgressRoot.svelte +72 -0
- package/dist/core/components/Progress/ProgressRoot.svelte.d.ts +17 -0
- package/dist/core/components/Progress/ProgressSection.svelte +83 -0
- package/dist/core/components/Progress/ProgressSection.svelte.d.ts +17 -0
- package/dist/core/components/Progress/index.d.ts +12 -0
- package/dist/core/components/Progress/index.js +9 -0
- package/dist/core/components/Tooltip/CreateTooltip.svelte.d.ts +20 -0
- package/dist/core/components/Tooltip/CreateTooltip.svelte.js +19 -0
- package/dist/core/components/Tooltip/Tooltip.svelte +235 -0
- package/dist/core/components/Tooltip/Tooltip.svelte.d.ts +46 -0
- package/dist/core/components/Tooltip/Tooltip.types.d.ts +47 -0
- package/dist/core/components/Tooltip/Tooltip.types.js +1 -0
- package/dist/core/components/Tooltip/getTooltipMiddleware.d.ts +15 -0
- package/dist/core/components/Tooltip/getTooltipMiddleware.js +32 -0
- package/dist/core/components/index.d.ts +3 -0
- package/dist/core/components/index.js +3 -0
- package/dist/tools/icon-vite-plugin/utils/generateIconComponent.js +1 -2
- package/package.json +9 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Bun from 'bun';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
await fs.rm('./files', { recursive: true, force: true });
|
|
4
|
+
await Bun.build({
|
|
5
|
+
entrypoints: ['src/index.ts', 'src/handler.ts'],
|
|
6
|
+
outdir: './files',
|
|
7
|
+
splitting: true,
|
|
8
|
+
external: ['SERVER', 'MANIFEST', 'SERVER_HOOKS'],
|
|
9
|
+
format: 'esm',
|
|
10
|
+
target: 'bun',
|
|
11
|
+
minify: false,
|
|
12
|
+
});
|
|
13
|
+
await Bun.build({
|
|
14
|
+
entrypoints: ['./adapter.ts'],
|
|
15
|
+
outdir: './',
|
|
16
|
+
splitting: true,
|
|
17
|
+
format: 'esm',
|
|
18
|
+
target: 'bun',
|
|
19
|
+
minify: false,
|
|
20
|
+
external: ['*'],
|
|
21
|
+
});
|
|
22
|
+
console.log('done');
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../node_modules/@sveltejs/kit/src/exports/node/index.js
|
|
3
|
+
import { createReadStream } from "fs";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
function createReadableStream(file) {
|
|
6
|
+
return Readable.toWeb(createReadStream(file));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/handler.ts
|
|
10
|
+
var {fileURLToPath } = globalThis.Bun;
|
|
11
|
+
import { base, manifest } from "MANIFEST";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { Server } from "SERVER";
|
|
14
|
+
|
|
15
|
+
// src/env.ts
|
|
16
|
+
import process2 from "process";
|
|
17
|
+
var expected = new Set([
|
|
18
|
+
"SOCKET_PATH",
|
|
19
|
+
"HOST",
|
|
20
|
+
"PORT",
|
|
21
|
+
"ORIGIN",
|
|
22
|
+
"XFF_DEPTH",
|
|
23
|
+
"ADDRESS_HEADER",
|
|
24
|
+
"PROTOCOL_HEADER",
|
|
25
|
+
"HOST_HEADER",
|
|
26
|
+
"PORT_HEADER",
|
|
27
|
+
"BODY_SIZE_LIMIT",
|
|
28
|
+
"SHUTDOWN_TIMEOUT",
|
|
29
|
+
"IDLE_TIMEOUT"
|
|
30
|
+
]);
|
|
31
|
+
var expected_unprefixed = new Set(["LISTEN_PID", "LISTEN_FDS"]);
|
|
32
|
+
if (ENV_PREFIX) {
|
|
33
|
+
for (const name in process2.env) {
|
|
34
|
+
if (name.startsWith(ENV_PREFIX)) {
|
|
35
|
+
const unprefixed = name.slice(ENV_PREFIX.length);
|
|
36
|
+
if (!expected.has(unprefixed)) {
|
|
37
|
+
throw new Error(`You should change envPrefix (${ENV_PREFIX}) to avoid conflicts with existing environment variables \u2014 unexpectedly saw ${name}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function env(name, fallback) {
|
|
43
|
+
const prefix = expected_unprefixed.has(name) ? "" : ENV_PREFIX;
|
|
44
|
+
const prefixed = prefix + name;
|
|
45
|
+
return prefixed in process2.env ? process2.env[prefixed] : fallback;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/utils.ts
|
|
49
|
+
function parse_as_bytes(value) {
|
|
50
|
+
const multiplier = {
|
|
51
|
+
K: 1024,
|
|
52
|
+
M: 1024 * 1024,
|
|
53
|
+
G: 1024 * 1024 * 1024
|
|
54
|
+
}[value[value.length - 1]?.toUpperCase()] ?? 1;
|
|
55
|
+
return Number(multiplier != 1 ? value.substring(0, value.length - 1) : value) * multiplier;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/handler.ts
|
|
59
|
+
var server = new Server(manifest);
|
|
60
|
+
var xff_depth = parseInt(env("XFF_DEPTH", "1"));
|
|
61
|
+
var address_header = env("ADDRESS_HEADER", "").toLowerCase();
|
|
62
|
+
var host_header = env("HOST_HEADER", "host").toLowerCase();
|
|
63
|
+
var body_size_limit = parse_as_bytes(env("BODY_SIZE_LIMIT", "512K"));
|
|
64
|
+
if (isNaN(body_size_limit)) {
|
|
65
|
+
throw new Error(`Invalid BODY_SIZE_LIMIT: '${env("BODY_SIZE_LIMIT", "")}'. Please provide a numeric value.`);
|
|
66
|
+
}
|
|
67
|
+
var dir = path.dirname(fileURLToPath(import.meta.url));
|
|
68
|
+
var asset_dir = `${dir}/client${base}`;
|
|
69
|
+
await server.init({
|
|
70
|
+
env: process.env,
|
|
71
|
+
read: (file) => createReadableStream(`${asset_dir}/${file}`)
|
|
72
|
+
});
|
|
73
|
+
function ssr(request, bunServer) {
|
|
74
|
+
if (address_header && request.headers.get(host_header) !== "127.0.0.1" && !request.headers.has(address_header)) {
|
|
75
|
+
throw new Error(`Address header was specified with ${ENV_PREFIX + "ADDRESS_HEADER"}=${address_header} but is absent from request`);
|
|
76
|
+
}
|
|
77
|
+
return server.respond(request, {
|
|
78
|
+
getClientAddress: () => {
|
|
79
|
+
if (address_header) {
|
|
80
|
+
if (!request.headers.has(address_header)) {
|
|
81
|
+
throw new Error(`Address header was specified with ${ENV_PREFIX + "ADDRESS_HEADER"}=${address_header} but is absent from request`);
|
|
82
|
+
}
|
|
83
|
+
const value = request.headers.get(address_header) || "";
|
|
84
|
+
if (address_header === "x-forwarded-for") {
|
|
85
|
+
const addresses = value.split(",");
|
|
86
|
+
if (xff_depth < 1) {
|
|
87
|
+
throw new Error(`${ENV_PREFIX + "XFF_DEPTH"} must be a positive integer`);
|
|
88
|
+
}
|
|
89
|
+
if (xff_depth > addresses.length) {
|
|
90
|
+
throw new Error(`${ENV_PREFIX + "XFF_DEPTH"} is ${xff_depth}, but only found ${addresses.length} addresses`);
|
|
91
|
+
}
|
|
92
|
+
return addresses[addresses.length - xff_depth].trim();
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
return bunServer.requestIP(request)?.address || request.connection?.remoteAddress || request.connection?.socket?.remoteAddress || request.socket?.remoteAddress || request.info?.remoteAddress;
|
|
97
|
+
},
|
|
98
|
+
platform: {
|
|
99
|
+
isBun() {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
ssr as default
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { env, ssr };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
env,
|
|
4
|
+
ssr
|
|
5
|
+
} from "./handler.js";
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
var {serve } = globalThis.Bun;
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import url from "url";
|
|
12
|
+
import * as websocketHooks from "SERVER_HOOKS";
|
|
13
|
+
var hostname = env("HOST", "0.0.0.0");
|
|
14
|
+
var port = parseInt(env("PORT", "3000"));
|
|
15
|
+
var maxRequestBodySize = parseInt(env("BODY_SIZE_LIMIT", 1024 * 1024 * 2048));
|
|
16
|
+
var __dirname2 = path.dirname(url.fileURLToPath(import.meta.url));
|
|
17
|
+
var staticPath = path.join(__dirname2, "./client");
|
|
18
|
+
var prerenderedPath = path.join(__dirname2, "./prerendered");
|
|
19
|
+
var allStaticFiles = {};
|
|
20
|
+
function getAllFiles(dirPath, arrayOfFiles = []) {
|
|
21
|
+
const files = fs.readdirSync(dirPath);
|
|
22
|
+
files.forEach((file) => {
|
|
23
|
+
const fullPath = path.join(dirPath, file);
|
|
24
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
25
|
+
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles);
|
|
26
|
+
} else {
|
|
27
|
+
arrayOfFiles.push(fullPath);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return arrayOfFiles;
|
|
31
|
+
}
|
|
32
|
+
async function staticHTMLFile(file, url2) {
|
|
33
|
+
allStaticFiles["/" + url2] = new Response(await Bun.file(file).bytes(), {
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "text/html",
|
|
36
|
+
"Cache-Control": "public, max-age=0, s-maxage=0"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const staticFiles = getAllFiles(staticPath);
|
|
42
|
+
for await (const file of staticFiles) {
|
|
43
|
+
const relativePath = path.relative(staticPath, file);
|
|
44
|
+
const readFile = Bun.file(file);
|
|
45
|
+
const stats = await readFile.stat();
|
|
46
|
+
allStaticFiles["/" + relativePath] = new Response(await readFile.bytes(), {
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": readFile.type,
|
|
49
|
+
Etag: `W/"${readFile.size}-${stats.mtime.getTime()}"`,
|
|
50
|
+
"Last-Modified": stats.mtime.toUTCString(),
|
|
51
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
52
|
+
...relativePath.endsWith(".gz") ? { "Content-Encoding": "gzip" } : {},
|
|
53
|
+
...relativePath.endsWith(".br") ? { "Content-Encoding": "br" } : {}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (fs.existsSync(prerenderedPath)) {
|
|
58
|
+
const prerenderedFiles = getAllFiles(prerenderedPath);
|
|
59
|
+
for await (const file of prerenderedFiles) {
|
|
60
|
+
const relativePath = path.relative(prerenderedPath, file);
|
|
61
|
+
await staticHTMLFile(file, relativePath);
|
|
62
|
+
await staticHTMLFile(file, relativePath.replace(".html", ""));
|
|
63
|
+
if (relativePath === "index.html") {
|
|
64
|
+
await staticHTMLFile(file, "");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.warn("No static files found:", error);
|
|
70
|
+
}
|
|
71
|
+
serve({
|
|
72
|
+
routes: { ...allStaticFiles, ...websocketHooks.WS_PATH ? { [websocketHooks.WS_PATH]: websocketHooks.handleWebsocket.upgrade } : {} },
|
|
73
|
+
fetch(req, bunServer) {
|
|
74
|
+
const originHeader = req.headers.get("origin");
|
|
75
|
+
if (originHeader) {
|
|
76
|
+
req.headers.set("origin", originHeader.replace("https://", "http://"));
|
|
77
|
+
}
|
|
78
|
+
return ssr(req, bunServer);
|
|
79
|
+
},
|
|
80
|
+
websocket: websocketHooks.handleWebsocket ? websocketHooks.handleWebsocket : undefined,
|
|
81
|
+
hostname,
|
|
82
|
+
port,
|
|
83
|
+
development: false,
|
|
84
|
+
error(error) {
|
|
85
|
+
console.error(error);
|
|
86
|
+
return new Response("Uh oh!!", { status: 500 });
|
|
87
|
+
},
|
|
88
|
+
maxRequestBodySize: isNaN(maxRequestBodySize) ? undefined : maxRequestBodySize
|
|
89
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
4
|
+
import Notification from '../components/Notification/Notification.svelte';
|
|
5
|
+
import { getAutoClose } from './get-auto-close.js';
|
|
6
|
+
import type { NotificationData } from './NotificationsStore.svelte.js';
|
|
7
|
+
|
|
8
|
+
export interface NotificationContainerProps extends NotificationProps {
|
|
9
|
+
data: NotificationData;
|
|
10
|
+
onHide: (id: string) => void;
|
|
11
|
+
autoClose: number | false;
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
let { data, onHide, autoClose, ...props }: NotificationContainerProps = $props();
|
|
17
|
+
|
|
18
|
+
const { autoClose: _autoClose, message, children, ...notificationProps } = $derived(data);
|
|
19
|
+
|
|
20
|
+
const autoCloseDuration = $derived(getAutoClose(autoClose, data.autoClose));
|
|
21
|
+
|
|
22
|
+
let autoCloseTimeout = $state<number>(-1);
|
|
23
|
+
|
|
24
|
+
function cancelAutoClose() {
|
|
25
|
+
window.clearTimeout(autoCloseTimeout);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleHide() {
|
|
29
|
+
onHide(data.id!);
|
|
30
|
+
cancelAutoClose();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleAutoClose() {
|
|
34
|
+
if (typeof autoCloseDuration === 'number') {
|
|
35
|
+
autoCloseTimeout = window.setTimeout(handleHide, autoCloseDuration);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onMount(() => {
|
|
40
|
+
data.onopen?.(data);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
$effect(() => {
|
|
44
|
+
handleAutoClose();
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
cancelAutoClose();
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<Notification {...props} {...notificationProps} onclose={handleHide} onmouseenter={cancelAutoClose} onmouseleave={handleAutoClose}>
|
|
53
|
+
{data.message}
|
|
54
|
+
|
|
55
|
+
{@render children?.()}
|
|
56
|
+
</Notification>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
2
|
+
import type { NotificationData } from './NotificationsStore.svelte.js';
|
|
3
|
+
export interface NotificationContainerProps extends NotificationProps {
|
|
4
|
+
data: NotificationData;
|
|
5
|
+
onHide: (id: string) => void;
|
|
6
|
+
autoClose: number | false;
|
|
7
|
+
}
|
|
8
|
+
declare const NotificationContainer: import("svelte").Component<NotificationContainerProps, {}, "">;
|
|
9
|
+
type NotificationContainer = ReturnType<typeof NotificationContainer>;
|
|
10
|
+
export default NotificationContainer;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cubicOut } from 'svelte/easing';
|
|
3
|
+
import type { TransitionConfig } from 'svelte/transition';
|
|
4
|
+
import { transitions } from '../components/index.js';
|
|
5
|
+
import OptionalPortal from '../components/Portal/OptionalPortal.svelte';
|
|
6
|
+
import type { BasePortalProps } from '../components/Portal/Portal.svelte';
|
|
7
|
+
import type { DivElement } from '../element-types.js';
|
|
8
|
+
import { reducedMotion } from '../hooks/use-reduced-motion.svelte.js';
|
|
9
|
+
import { theme } from '../MantineProvider/theme.svelte.js';
|
|
10
|
+
import { getDefaultZIndex } from '../utils/get-default-z-index.js';
|
|
11
|
+
import { rem } from '../utils/index.js';
|
|
12
|
+
import NotificationContainer from './NotificationContainer.svelte';
|
|
13
|
+
import { notifications, type CreateNotificationStore, type NotificationData, type NotificationPosition } from './NotificationsStore.svelte.js';
|
|
14
|
+
import { notificationStackAnimation } from './notificationStackAnimation.js';
|
|
15
|
+
|
|
16
|
+
export interface NotificationsProps extends DivElement {
|
|
17
|
+
/** Notifications default position, `'bottom-right'` by default */
|
|
18
|
+
position?: NotificationPosition;
|
|
19
|
+
|
|
20
|
+
/** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function, `4000` by default */
|
|
21
|
+
autoClose?: number | false;
|
|
22
|
+
|
|
23
|
+
/** Notification transition duration in ms, `250` by default */
|
|
24
|
+
transitionDuration?: number;
|
|
25
|
+
|
|
26
|
+
/** Notification width, cannot exceed 100%, `440` by default */
|
|
27
|
+
containerWidth?: number | string;
|
|
28
|
+
|
|
29
|
+
/** Notification `max-height`, used for transitions, `200` by default */
|
|
30
|
+
notificationMaxHeight?: number | string;
|
|
31
|
+
|
|
32
|
+
/** Maximum number of notifications displayed at a time, other new notifications will be added to queue, `5` by default */
|
|
33
|
+
limit?: number;
|
|
34
|
+
|
|
35
|
+
/** Notifications container z-index, `400` by default */
|
|
36
|
+
zIndex?: string | number;
|
|
37
|
+
|
|
38
|
+
/** Props passed down to the `Portal` component */
|
|
39
|
+
portalProps?: BasePortalProps;
|
|
40
|
+
|
|
41
|
+
/** Store for notifications state, can be used to create multiple instances of notifications system in your application */
|
|
42
|
+
store?: CreateNotificationStore;
|
|
43
|
+
|
|
44
|
+
/** Determines whether notifications container should be rendered inside `Portal`, `true` by default */
|
|
45
|
+
withinPortal?: boolean;
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<script lang="ts">
|
|
50
|
+
let {
|
|
51
|
+
position = 'bottom-right',
|
|
52
|
+
autoClose = 4000,
|
|
53
|
+
transitionDuration = 250,
|
|
54
|
+
containerWidth = 440,
|
|
55
|
+
notificationMaxHeight = 200,
|
|
56
|
+
limit = 5,
|
|
57
|
+
zIndex = getDefaultZIndex('overlay'),
|
|
58
|
+
store = notifications,
|
|
59
|
+
withinPortal = true,
|
|
60
|
+
portalProps,
|
|
61
|
+
}: NotificationsProps = $props();
|
|
62
|
+
|
|
63
|
+
const groupedNotifications = $derived.by(() => {
|
|
64
|
+
const groups: Record<NotificationPosition, NotificationData[]> = {
|
|
65
|
+
'top-left': [],
|
|
66
|
+
'top-right': [],
|
|
67
|
+
'top-center': [],
|
|
68
|
+
'bottom-left': [],
|
|
69
|
+
'bottom-right': [],
|
|
70
|
+
'bottom-center': [],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < store.notifications.length; i++) {
|
|
74
|
+
const notification = store.notifications[i];
|
|
75
|
+
|
|
76
|
+
groups[notification.position || position].push(notification);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return groups;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const styles = $derived(`--notifications-z-index: ${zIndex}; --notifications-container-width: ${rem(containerWidth)};`);
|
|
83
|
+
|
|
84
|
+
const duration = $derived.by(() => {
|
|
85
|
+
const shouldReduceMotion = reducedMotion.current;
|
|
86
|
+
const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;
|
|
87
|
+
return reduceMotion ? 1 : transitionDuration;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const { 'slide-up': slideUp, 'slide-down': slideDown, 'slide-left': slideLeft, 'slide-right': slideRight } = transitions;
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#snippet renderGroup(group: NotificationData[], transition: typeof slideLeft | typeof slideRight)}
|
|
94
|
+
{#each group as notification (notification.id)}
|
|
95
|
+
<div animate:notificationStackAnimation class="notification-container" transition:transition={{ duration: duration }}>
|
|
96
|
+
<NotificationContainer class="notification" data={notification} onHide={() => store.hide(notification.id!)} {autoClose} />
|
|
97
|
+
</div>
|
|
98
|
+
{/each}
|
|
99
|
+
{/snippet}
|
|
100
|
+
|
|
101
|
+
<OptionalPortal {withinPortal} {...portalProps}>
|
|
102
|
+
<div class="root" data-position="top-center" style={styles}>
|
|
103
|
+
{@render renderGroup(groupedNotifications['top-center'], slideDown)}
|
|
104
|
+
</div>
|
|
105
|
+
<div class="root" data-position="top-left" style={styles}>
|
|
106
|
+
{@render renderGroup(groupedNotifications['top-left'], slideRight)}
|
|
107
|
+
</div>
|
|
108
|
+
<div class="root" data-position="top-right" style={styles}>
|
|
109
|
+
{@render renderGroup(groupedNotifications['top-right'], slideLeft)}
|
|
110
|
+
</div>
|
|
111
|
+
<div class="root" data-position="bottom-right" style={styles}>
|
|
112
|
+
{@render renderGroup(groupedNotifications['bottom-right'], slideLeft)}
|
|
113
|
+
</div>
|
|
114
|
+
<div class="root" data-position="bottom-left" style={styles}>
|
|
115
|
+
{@render renderGroup(groupedNotifications['bottom-left'], slideRight)}
|
|
116
|
+
</div>
|
|
117
|
+
<div class="root" data-position="bottom-center" style={styles}>
|
|
118
|
+
{@render renderGroup(groupedNotifications['bottom-center'], slideUp)}
|
|
119
|
+
</div>
|
|
120
|
+
</OptionalPortal>
|
|
121
|
+
|
|
122
|
+
<style>.root {
|
|
123
|
+
width: calc(100% - var(--mantine-spacing-md) * 2);
|
|
124
|
+
position: fixed;
|
|
125
|
+
z-index: var(--notifications-z-index);
|
|
126
|
+
max-width: var(--notifications-container-width);
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
gap: var(--mantine-spacing-md);
|
|
130
|
+
}
|
|
131
|
+
.root:where([data-position=top-center]) {
|
|
132
|
+
top: var(--mantine-spacing-md);
|
|
133
|
+
left: 50%;
|
|
134
|
+
transform: translateX(-50%);
|
|
135
|
+
}
|
|
136
|
+
.root:where([data-position=top-left]) {
|
|
137
|
+
top: var(--mantine-spacing-md);
|
|
138
|
+
left: var(--mantine-spacing-md);
|
|
139
|
+
}
|
|
140
|
+
.root:where([data-position=top-right]) {
|
|
141
|
+
top: var(--mantine-spacing-md);
|
|
142
|
+
right: var(--mantine-spacing-md);
|
|
143
|
+
}
|
|
144
|
+
.root:where([data-position=bottom-center]) {
|
|
145
|
+
bottom: var(--mantine-spacing-md);
|
|
146
|
+
left: 50%;
|
|
147
|
+
transform: translateX(-50%);
|
|
148
|
+
}
|
|
149
|
+
.root:where([data-position=bottom-left]) {
|
|
150
|
+
bottom: var(--mantine-spacing-md);
|
|
151
|
+
left: var(--mantine-spacing-md);
|
|
152
|
+
}
|
|
153
|
+
.root:where([data-position=bottom-right]) {
|
|
154
|
+
bottom: var(--mantine-spacing-md);
|
|
155
|
+
right: var(--mantine-spacing-md);
|
|
156
|
+
}</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BasePortalProps } from '../components/Portal/Portal.svelte';
|
|
2
|
+
import type { DivElement } from '../element-types.js';
|
|
3
|
+
import { type CreateNotificationStore, type NotificationPosition } from './NotificationsStore.svelte.js';
|
|
4
|
+
export interface NotificationsProps extends DivElement {
|
|
5
|
+
/** Notifications default position, `'bottom-right'` by default */
|
|
6
|
+
position?: NotificationPosition;
|
|
7
|
+
/** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function, `4000` by default */
|
|
8
|
+
autoClose?: number | false;
|
|
9
|
+
/** Notification transition duration in ms, `250` by default */
|
|
10
|
+
transitionDuration?: number;
|
|
11
|
+
/** Notification width, cannot exceed 100%, `440` by default */
|
|
12
|
+
containerWidth?: number | string;
|
|
13
|
+
/** Notification `max-height`, used for transitions, `200` by default */
|
|
14
|
+
notificationMaxHeight?: number | string;
|
|
15
|
+
/** Maximum number of notifications displayed at a time, other new notifications will be added to queue, `5` by default */
|
|
16
|
+
limit?: number;
|
|
17
|
+
/** Notifications container z-index, `400` by default */
|
|
18
|
+
zIndex?: string | number;
|
|
19
|
+
/** Props passed down to the `Portal` component */
|
|
20
|
+
portalProps?: BasePortalProps;
|
|
21
|
+
/** Store for notifications state, can be used to create multiple instances of notifications system in your application */
|
|
22
|
+
store?: CreateNotificationStore;
|
|
23
|
+
/** Determines whether notifications container should be rendered inside `Portal`, `true` by default */
|
|
24
|
+
withinPortal?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare const Notifications: import("svelte").Component<NotificationsProps, {}, "">;
|
|
27
|
+
type Notifications = ReturnType<typeof Notifications>;
|
|
28
|
+
export default Notifications;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
3
|
+
import { type MaybeGetter } from '../context/extract.js';
|
|
4
|
+
export type NotificationPosition = 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center';
|
|
5
|
+
export interface NotificationData extends Omit<NotificationProps, 'onclose'> {
|
|
6
|
+
/** Notification id, can be used to close or update notification */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Position of the notification, if not set, the position is determined based on `position` prop on Notifications component */
|
|
9
|
+
position?: NotificationPosition;
|
|
10
|
+
/** Notification message, required for all notifications */
|
|
11
|
+
message: string | Snippet;
|
|
12
|
+
/** Determines whether notification should be closed automatically,
|
|
13
|
+
* number is auto close timeout in ms, overrides `autoClose` from `Notifications`
|
|
14
|
+
* */
|
|
15
|
+
autoClose?: boolean | number;
|
|
16
|
+
/** Called when notification closes */
|
|
17
|
+
onclose?: (props: NotificationData) => void;
|
|
18
|
+
/** Called when notification opens */
|
|
19
|
+
onopen?: (props: NotificationData) => void;
|
|
20
|
+
}
|
|
21
|
+
interface NotificationStore {
|
|
22
|
+
notifications?: MaybeGetter<NotificationData[]>;
|
|
23
|
+
queue?: MaybeGetter<NotificationData[]>;
|
|
24
|
+
defaultPosition?: MaybeGetter<NotificationPosition>;
|
|
25
|
+
limit?: MaybeGetter<number>;
|
|
26
|
+
}
|
|
27
|
+
interface NotificationShowResult {
|
|
28
|
+
id: string;
|
|
29
|
+
position: NotificationPosition;
|
|
30
|
+
}
|
|
31
|
+
export declare class CreateNotificationStore {
|
|
32
|
+
#private;
|
|
33
|
+
notifications: NotificationData[];
|
|
34
|
+
queue: NotificationData[];
|
|
35
|
+
defaultPosition: "bottom-left" | "bottom-right" | "top-left" | "top-right" | "top-center" | "bottom-center";
|
|
36
|
+
limit: number;
|
|
37
|
+
constructor(props?: NotificationStore);
|
|
38
|
+
show: (notification: NotificationData) => NotificationShowResult;
|
|
39
|
+
hide: (id: string) => string;
|
|
40
|
+
update: (notification: NotificationData) => string | undefined;
|
|
41
|
+
clean: () => void;
|
|
42
|
+
cleanQueue: () => void;
|
|
43
|
+
updateState: (update: (notifications: NotificationData[]) => NotificationData[]) => void;
|
|
44
|
+
}
|
|
45
|
+
export declare const notifications: CreateNotificationStore;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import { extract } from '../context/extract.js';
|
|
3
|
+
function getDistributedNotifications(data, defaultPosition, limit) {
|
|
4
|
+
const queue = [];
|
|
5
|
+
const notifications = [];
|
|
6
|
+
const count = {};
|
|
7
|
+
for (const item of data) {
|
|
8
|
+
const position = item.position || defaultPosition;
|
|
9
|
+
count[position] = count[position] || 0;
|
|
10
|
+
count[position] += 1;
|
|
11
|
+
if (count[position] <= limit) {
|
|
12
|
+
notifications.push(item);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
queue.push(item);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { notifications, queue };
|
|
19
|
+
}
|
|
20
|
+
export class CreateNotificationStore {
|
|
21
|
+
#props;
|
|
22
|
+
notifications = $derived(extract(this.#props.notifications, []));
|
|
23
|
+
queue = $derived(extract(this.#props.queue, []));
|
|
24
|
+
defaultPosition = $derived(extract(this.#props.defaultPosition, 'bottom-right'));
|
|
25
|
+
limit = $derived(extract(this.#props.limit, 5));
|
|
26
|
+
constructor(props = {}) {
|
|
27
|
+
this.#props = props;
|
|
28
|
+
}
|
|
29
|
+
show = (notification) => {
|
|
30
|
+
const id = notification.id || nanoid();
|
|
31
|
+
this.updateState((notifications) => {
|
|
32
|
+
if (notification.id && notifications.some((n) => n.id === notification.id)) {
|
|
33
|
+
return notifications;
|
|
34
|
+
}
|
|
35
|
+
return [...notifications, { ...notification, id }];
|
|
36
|
+
});
|
|
37
|
+
return { id, position: notification.position || this.defaultPosition };
|
|
38
|
+
};
|
|
39
|
+
hide = (id) => {
|
|
40
|
+
this.updateState((notifications) => notifications.filter((notification) => {
|
|
41
|
+
if (notification.id === id) {
|
|
42
|
+
notification.onclose?.(notification);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}));
|
|
47
|
+
return id;
|
|
48
|
+
};
|
|
49
|
+
update = (notification) => {
|
|
50
|
+
this.updateState((notifications) => notifications.map((item) => {
|
|
51
|
+
if (item.id === notification.id) {
|
|
52
|
+
return { ...item, ...notification };
|
|
53
|
+
}
|
|
54
|
+
return item;
|
|
55
|
+
}));
|
|
56
|
+
return notification.id;
|
|
57
|
+
};
|
|
58
|
+
clean = () => {
|
|
59
|
+
this.updateState(() => []);
|
|
60
|
+
};
|
|
61
|
+
cleanQueue = () => {
|
|
62
|
+
this.updateState((notifications) => notifications.slice(0, this.limit));
|
|
63
|
+
};
|
|
64
|
+
updateState = (update) => {
|
|
65
|
+
const notifications = update([...this.notifications, ...this.queue]);
|
|
66
|
+
const updated = getDistributedNotifications(notifications, this.defaultPosition, this.limit);
|
|
67
|
+
this.notifications = updated.notifications;
|
|
68
|
+
this.queue = updated.queue;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export const notifications = new CreateNotificationStore();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAutoClose(autoClose: boolean | number | undefined, notificationAutoClose: boolean | number | undefined): number | boolean | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cubicOut } from 'svelte/easing';
|
|
2
|
+
export function notificationStackAnimation(node, { from, to }) {
|
|
3
|
+
const dx = from.left - to.left;
|
|
4
|
+
const dy = from.top - to.top;
|
|
5
|
+
return {
|
|
6
|
+
delay: 0,
|
|
7
|
+
duration: 200,
|
|
8
|
+
easing: cubicOut,
|
|
9
|
+
css: (t, u) => `transform: translate(${u * dx}px, ${u * dy}px);`,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
{#if icon}
|
|
57
57
|
{@render icon?.()}
|
|
58
58
|
{:else}
|
|
59
|
-
<icon name="tabler:x"
|
|
59
|
+
<icon class="icon" name="tabler:x"></icon>
|
|
60
60
|
{/if}
|
|
61
61
|
</button>
|
|
62
62
|
|
|
@@ -107,4 +107,9 @@
|
|
|
107
107
|
:global(:where([data-mantine-color-scheme="dark"])) .root--subtle:where(:not([data-disabled], :disabled)):active {
|
|
108
108
|
background-color: var(--mantine-color-dark-6);
|
|
109
109
|
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
* :global(.icon) {
|
|
113
|
+
width: var(--cb-icon-size, 70%);
|
|
114
|
+
height: var(--cb-icon-size, 70%);
|
|
110
115
|
}</style>
|