ToastModule Fixes in the styles and small tweaks, also lib renamed to MWinLib
This commit is contained in:
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
"version": "0.0.69",
|
"version": "0.0.69",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev --host",
|
"dev": "vite dev",
|
||||||
|
"dev-host": "vite dev --host",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"prepare": "svelte-kit sync || echo ''",
|
"prepare": "svelte-kit sync || echo ''",
|
||||||
|
|||||||
+33
-28
@@ -1,17 +1,17 @@
|
|||||||
import {
|
import {
|
||||||
getWrapperManager,
|
getWrapperManager,
|
||||||
MOVABLE_MANAGER,
|
MWIN_MANAGER,
|
||||||
resolveElement,
|
resolveElement,
|
||||||
type MovableAPI,
|
type MWinAPI,
|
||||||
type MovableOptions,
|
type MWinNormalizedParams,
|
||||||
type MovableState,
|
type MWinParams,
|
||||||
type NormalisedOptions,
|
type MWinState,
|
||||||
type ResizeDirection
|
type ResizeDirection
|
||||||
} from './util';
|
} from './mwin_util';
|
||||||
|
|
||||||
export function movable(node: HTMLElement, options: MovableOptions) {
|
export function mwin_movable(node: HTMLElement, options: MWinParams) {
|
||||||
const controller = new MovableController(node, options);
|
const controller = new MWinController(node, options);
|
||||||
const api: MovableAPI = {
|
const api: MWinAPI = {
|
||||||
state: controller.state,
|
state: controller.state,
|
||||||
minimize: () => controller.minimize(),
|
minimize: () => controller.minimize(),
|
||||||
maximize: () => controller.maximize(),
|
maximize: () => controller.maximize(),
|
||||||
@@ -24,13 +24,13 @@ export function movable(node: HTMLElement, options: MovableOptions) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class MovableController {
|
class MWinController {
|
||||||
#rafID: number | null = null;
|
#rafID: number | null = null;
|
||||||
#pendingApply = false;
|
#pendingApply = false;
|
||||||
|
|
||||||
#node: HTMLElement;
|
#node: HTMLElement;
|
||||||
#wrapper: HTMLElement;
|
#wrapper: HTMLElement;
|
||||||
#opts: NormalisedOptions;
|
#opts: MWinNormalizedParams;
|
||||||
#savedTransition: string;
|
#savedTransition: string;
|
||||||
#savedStyles: string;
|
#savedStyles: string;
|
||||||
#wrapperObserver: ResizeObserver | null = null;
|
#wrapperObserver: ResizeObserver | null = null;
|
||||||
@@ -39,6 +39,8 @@ class MovableController {
|
|||||||
#wrapperHeight: number = 0;
|
#wrapperHeight: number = 0;
|
||||||
#wrapperLeft: number = 0;
|
#wrapperLeft: number = 0;
|
||||||
#wrapperTop: number = 0;
|
#wrapperTop: number = 0;
|
||||||
|
#wrapperBorderLeft: number = 0;
|
||||||
|
#wrapperBorderTop: number = 0;
|
||||||
|
|
||||||
#dragOffsetX: number = 0;
|
#dragOffsetX: number = 0;
|
||||||
#dragOffsetY: number = 0;
|
#dragOffsetY: number = 0;
|
||||||
@@ -47,7 +49,7 @@ class MovableController {
|
|||||||
#resizeStartPos = { x: 0, y: 0 };
|
#resizeStartPos = { x: 0, y: 0 };
|
||||||
#restoreRect: { x: number; y: number; width: number; height: number } | null = null;
|
#restoreRect: { x: number; y: number; width: number; height: number } | null = null;
|
||||||
|
|
||||||
state = $state<MovableState>({
|
state = $state<MWinState>({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
@@ -59,13 +61,17 @@ class MovableController {
|
|||||||
zIndex: 0
|
zIndex: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(node: HTMLElement, options: MovableOptions) {
|
constructor(node: HTMLElement, options: MWinParams) {
|
||||||
this.#node = node;
|
this.#node = node;
|
||||||
|
|
||||||
const wrapper = resolveElement(options.wrapper, node);
|
const wrapper = resolveElement(options.wrapper, node);
|
||||||
if (!wrapper) throw new Error('[Movable] - Wrapper element not found!');
|
if (!wrapper) throw new Error('[Movable] - Wrapper element not found!');
|
||||||
this.#wrapper = wrapper;
|
this.#wrapper = wrapper;
|
||||||
|
|
||||||
|
const wrapperStyle = getComputedStyle(this.#wrapper);
|
||||||
|
this.#wrapperBorderLeft = parseFloat(wrapperStyle.borderLeftWidth);
|
||||||
|
this.#wrapperBorderTop = parseFloat(wrapperStyle.borderTopWidth);
|
||||||
|
|
||||||
const resizableOpts = typeof options.resizable === 'object' ? options.resizable : {};
|
const resizableOpts = typeof options.resizable === 'object' ? options.resizable : {};
|
||||||
|
|
||||||
this.#opts = {
|
this.#opts = {
|
||||||
@@ -78,17 +84,15 @@ class MovableController {
|
|||||||
resizeHandle: resolveElement(options.resizeHandle, node),
|
resizeHandle: resolveElement(options.resizeHandle, node),
|
||||||
resizable: !!options.resizable,
|
resizable: !!options.resizable,
|
||||||
threshold: resizableOpts.threshold ?? 8,
|
threshold: resizableOpts.threshold ?? 8,
|
||||||
minWidth: resizableOpts.minWidth ?? 0,
|
minWidth: resizableOpts.minWidth ?? 24, //MinWidth should be min-content
|
||||||
minHeight: resizableOpts.minHeight ?? 0,
|
minHeight: resizableOpts.minHeight ?? 24, //MinHeight should be min-content
|
||||||
maxWidth: resizableOpts.maxWidth ?? Infinity,
|
maxWidth: resizableOpts.maxWidth ?? Infinity,
|
||||||
maxHeight: resizableOpts.maxHeight ?? Infinity,
|
maxHeight: resizableOpts.maxHeight ?? Infinity,
|
||||||
onClose: options.onClose,
|
onClose: options.onClose,
|
||||||
onMinimize: options.onMinimize,
|
onMinimize: options.onMinimize,
|
||||||
onMaximize: options.onMaximize
|
onMaximize: options.onMaximize
|
||||||
};
|
};
|
||||||
|
|
||||||
this.#savedStyles = this.#node.style.cssText;
|
this.#savedStyles = this.#node.style.cssText;
|
||||||
|
|
||||||
this.#savedTransition = this.#node.style.transition;
|
this.#savedTransition = this.#node.style.transition;
|
||||||
this.#node.style.transition = 'none';
|
this.#node.style.transition = 'none';
|
||||||
|
|
||||||
@@ -121,7 +125,6 @@ class MovableController {
|
|||||||
node.addEventListener('pointerdown', this.#onPointerDown);
|
node.addEventListener('pointerdown', this.#onPointerDown);
|
||||||
node.addEventListener('pointermove', this.#updateCursor);
|
node.addEventListener('pointermove', this.#updateCursor);
|
||||||
node.addEventListener('pointerleave', this.#resetCursor);
|
node.addEventListener('pointerleave', this.#resetCursor);
|
||||||
//node.addEventListener('keydown', this.#onKeyDown);
|
|
||||||
|
|
||||||
this.#clampAndApply();
|
this.#clampAndApply();
|
||||||
this.#bringToFront();
|
this.#bringToFront();
|
||||||
@@ -129,6 +132,7 @@ class MovableController {
|
|||||||
this.#wrapperObserver = new ResizeObserver(() => {
|
this.#wrapperObserver = new ResizeObserver(() => {
|
||||||
this.#wrapperWidth = this.#wrapper.clientWidth;
|
this.#wrapperWidth = this.#wrapper.clientWidth;
|
||||||
this.#wrapperHeight = this.#wrapper.clientHeight;
|
this.#wrapperHeight = this.#wrapper.clientHeight;
|
||||||
|
|
||||||
this.#onWrapperResize();
|
this.#onWrapperResize();
|
||||||
});
|
});
|
||||||
this.#wrapperObserver.observe(this.#wrapper);
|
this.#wrapperObserver.observe(this.#wrapper);
|
||||||
@@ -136,10 +140,9 @@ class MovableController {
|
|||||||
|
|
||||||
#cacheWrapperRect() {
|
#cacheWrapperRect() {
|
||||||
const wrapperRect = this.#wrapper.getBoundingClientRect();
|
const wrapperRect = this.#wrapper.getBoundingClientRect();
|
||||||
const style = getComputedStyle(this.#wrapper);
|
|
||||||
|
|
||||||
this.#wrapperLeft = wrapperRect.left + parseFloat(style.borderLeftWidth);
|
this.#wrapperLeft = wrapperRect.left + this.#wrapperBorderLeft;
|
||||||
this.#wrapperTop = wrapperRect.top + parseFloat(style.borderTopWidth);
|
this.#wrapperTop = wrapperRect.top + this.#wrapperBorderTop;
|
||||||
this.#wrapperWidth = this.#wrapper.clientWidth;
|
this.#wrapperWidth = this.#wrapper.clientWidth;
|
||||||
this.#wrapperHeight = this.#wrapper.clientHeight;
|
this.#wrapperHeight = this.#wrapper.clientHeight;
|
||||||
}
|
}
|
||||||
@@ -183,17 +186,15 @@ class MovableController {
|
|||||||
|
|
||||||
#getCornerDirection(e: PointerEvent): ResizeDirection {
|
#getCornerDirection(e: PointerEvent): ResizeDirection {
|
||||||
if (!this.#opts.resizable) return null;
|
if (!this.#opts.resizable) return null;
|
||||||
|
|
||||||
const rect = this.#node.getBoundingClientRect();
|
|
||||||
const t = this.#opts.threshold;
|
const t = this.#opts.threshold;
|
||||||
|
|
||||||
let dirY: string = '';
|
let dirY: string = '';
|
||||||
if (e.clientY - rect.top < t) dirY = 'n';
|
if (e.clientY - this.state.y < t) dirY = 'n';
|
||||||
else if (rect.bottom - e.clientY < t) dirY = 's';
|
else if (this.state.y + this.state.height - e.clientY < t) dirY = 's';
|
||||||
|
|
||||||
let dirX: string = '';
|
let dirX: string = '';
|
||||||
if (e.clientX - rect.left < t) dirX = 'w';
|
if (e.clientX - this.state.x < t) dirX = 'w';
|
||||||
else if (rect.right - e.clientX < t) dirX = 'e';
|
else if (this.state.x + this.state.width - e.clientX < t) dirX = 'e';
|
||||||
|
|
||||||
if (dirY && dirX) {
|
if (dirY && dirX) {
|
||||||
return (dirY + dirX) as ResizeDirection;
|
return (dirY + dirX) as ResizeDirection;
|
||||||
@@ -438,6 +439,10 @@ class MovableController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#onWrapperResize(): void {
|
#onWrapperResize(): void {
|
||||||
|
const style = getComputedStyle(this.#wrapper);
|
||||||
|
this.#wrapperBorderLeft = parseFloat(style.borderLeftWidth);
|
||||||
|
this.#wrapperBorderTop = parseFloat(style.borderTopWidth);
|
||||||
|
|
||||||
if (this.state.maximized) {
|
if (this.state.maximized) {
|
||||||
this.state.width = this.#wrapperWidth;
|
this.state.width = this.#wrapperWidth;
|
||||||
this.state.height = this.#wrapperHeight;
|
this.state.height = this.#wrapperHeight;
|
||||||
@@ -545,7 +550,7 @@ class MovableController {
|
|||||||
const mgr = getWrapperManager(this.#wrapper);
|
const mgr = getWrapperManager(this.#wrapper);
|
||||||
mgr.refCount--;
|
mgr.refCount--;
|
||||||
if (mgr.refCount === 0) {
|
if (mgr.refCount === 0) {
|
||||||
delete (this.#wrapper as any)[MOVABLE_MANAGER];
|
delete (this.#wrapper as any)[MWIN_MANAGER];
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.style.userSelect = '';
|
document.body.style.userSelect = '';
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export interface MovableOptions {
|
export interface MWinParams {
|
||||||
wrapper: HTMLElement | (() => HTMLElement) | string; // changed
|
wrapper: HTMLElement | (() => HTMLElement) | string; // changed
|
||||||
handle?: HTMLElement | (() => HTMLElement) | string;
|
handle?: HTMLElement | (() => HTMLElement) | string;
|
||||||
initX?: number;
|
initX?: number;
|
||||||
@@ -6,15 +6,15 @@ export interface MovableOptions {
|
|||||||
initWidth?: number;
|
initWidth?: number;
|
||||||
initHeight?: number;
|
initHeight?: number;
|
||||||
baseZIndex?: number;
|
baseZIndex?: number;
|
||||||
resizable?: boolean | ResizeOptions;
|
resizable?: boolean | MWinResizeParams;
|
||||||
resizeHandle?: HTMLElement | (() => HTMLElement) | string;
|
resizeHandle?: HTMLElement | (() => HTMLElement) | string;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
onMinimize?: () => void;
|
onMinimize?: () => void;
|
||||||
onMaximize?: () => void;
|
onMaximize?: () => void;
|
||||||
onAPI?: (api: MovableAPI) => void;
|
onAPI?: (api: MWinAPI) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalisedOptions {
|
export interface MWinNormalizedParams {
|
||||||
handle: HTMLElement | null;
|
handle: HTMLElement | null;
|
||||||
initX?: number;
|
initX?: number;
|
||||||
initY?: number;
|
initY?: number;
|
||||||
@@ -33,7 +33,7 @@ export interface NormalisedOptions {
|
|||||||
onMaximize?: () => void;
|
onMaximize?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResizeOptions {
|
export interface MWinResizeParams {
|
||||||
threshold?: number;
|
threshold?: number;
|
||||||
minWidth?: number;
|
minWidth?: number;
|
||||||
minHeight?: number;
|
minHeight?: number;
|
||||||
@@ -41,7 +41,7 @@ export interface ResizeOptions {
|
|||||||
maxHeight?: number;
|
maxHeight?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MovableState {
|
export interface MWinState {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -53,8 +53,8 @@ export interface MovableState {
|
|||||||
zIndex: number;
|
zIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MovableAPI {
|
export interface MWinAPI {
|
||||||
state: MovableState;
|
state: MWinState;
|
||||||
minimize: () => void;
|
minimize: () => void;
|
||||||
maximize: () => void;
|
maximize: () => void;
|
||||||
close: () => void;
|
close: () => void;
|
||||||
@@ -67,13 +67,13 @@ export class WrapperManager {
|
|||||||
|
|
||||||
export type ResizeDirection = 'ne' | 'se' | 'sw' | 'nw' | null;
|
export type ResizeDirection = 'ne' | 'se' | 'sw' | 'nw' | null;
|
||||||
|
|
||||||
export const MOVABLE_MANAGER = Symbol('movable');
|
export const MWIN_MANAGER = Symbol('mwinlib');
|
||||||
|
|
||||||
export function getWrapperManager(wrapper: HTMLElement): WrapperManager {
|
export function getWrapperManager(wrapper: HTMLElement): WrapperManager {
|
||||||
let mgr = (wrapper as any)[MOVABLE_MANAGER] as WrapperManager | undefined;
|
let mgr = (wrapper as any)[MWIN_MANAGER] as WrapperManager | undefined;
|
||||||
if (!mgr) {
|
if (!mgr) {
|
||||||
mgr = { zCounter: 0, refCount: 0 };
|
mgr = { zCounter: 0, refCount: 0 };
|
||||||
(wrapper as any)[MOVABLE_MANAGER] = mgr;
|
(wrapper as any)[MWIN_MANAGER] = mgr;
|
||||||
}
|
}
|
||||||
return mgr;
|
return mgr;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { movable } from '$lib/movable/movable_controller.svelte';
|
import { movable } from '$lib/mwinlib/mwin_controller.svelte';
|
||||||
import type { MovableAPI } from '$lib/movable/util';
|
import type { MovableAPI } from '$lib/mwinlib/mwin_util';
|
||||||
import Input from './terminal/Input.svelte';
|
import Input from './terminal/Input.svelte';
|
||||||
|
|
||||||
let { username }: { username: string } = $props();
|
let { username }: { username: string } = $props();
|
||||||
@@ -54,9 +54,7 @@
|
|||||||
let inputValue = $state('');
|
let inputValue = $state('');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class="terminal-wrapper relative flex h-screen w-full flex-col items-center justify-center">
|
||||||
class="terminal-wrapper relative flex h-screen w-1/2 flex-col items-center justify-center bg-red-400"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="absolute flex size-full h-256 w-512 flex-col rounded-md shadow-subtle transition-discrete will-change-auto"
|
class="absolute flex size-full h-256 w-512 flex-col rounded-md shadow-subtle transition-discrete will-change-auto"
|
||||||
use:movable={{
|
use:movable={{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<div
|
<div
|
||||||
transition:fly={{ x: 20, y: 0, duration: 300 }}
|
transition:fly={{ x: 20, y: 0, duration: 300 }}
|
||||||
id={`toast-${toast.id.toString()}`}
|
id={`toast-${toast.id.toString()}`}
|
||||||
class="w-md overflow-hidden rounded-md bg-bg-lighter-dark"
|
class="w-md overflow-hidden rounded-md bg-surface-2"
|
||||||
onclick={() => toast.onClick?.(toast)}
|
onclick={() => toast.onClick?.(toast)}
|
||||||
role="button"
|
role="button"
|
||||||
tabindex={toast.onClick ? 0 : undefined}
|
tabindex={toast.onClick ? 0 : undefined}
|
||||||
@@ -30,18 +30,18 @@
|
|||||||
<div class="flex items-center justify-start">
|
<div class="flex items-center justify-start">
|
||||||
<div class="mx-4 my-8">
|
<div class="mx-4 my-8">
|
||||||
{#if toast.type === 'info'}
|
{#if toast.type === 'info'}
|
||||||
<Info class=" text-info-dark"></Info>
|
<Info class=" text-info"></Info>
|
||||||
{:else if toast.type === 'error'}
|
{:else if toast.type === 'error'}
|
||||||
<CircleX class="text-danger-dark"></CircleX>
|
<CircleX class="text-error"></CircleX>
|
||||||
{:else if toast.type === 'warn'}
|
{:else if toast.type === 'warn'}
|
||||||
<TriangleAlert class="text-warning-dark"></TriangleAlert>
|
<TriangleAlert class="text-warning"></TriangleAlert>
|
||||||
{:else}
|
{:else}
|
||||||
<CircleCheckBig class="text-success-dark"></CircleCheckBig>
|
<CircleCheckBig class="text-success"></CircleCheckBig>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="my-2 mr-auto mb-auto ml-2 flex flex-col items-start justify-start select-none">
|
<div class="my-2 mr-auto mb-auto ml-2 flex flex-col items-start justify-start select-none">
|
||||||
<h5 class=" text- text-md font-bold text-text-dark">{toast.title}</h5>
|
<h5 class=" text- text-md text-text-dark font-bold">{toast.title}</h5>
|
||||||
<p class=" text-md mb-2 overflow-x-hidden overflow-y-scroll text-text-muted-dark">
|
<p class=" text-md mb-2 overflow-x-hidden overflow-y-scroll text-muted">
|
||||||
{toast.message}
|
{toast.message}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -56,16 +56,13 @@
|
|||||||
<X
|
<X
|
||||||
stroke-width={3}
|
stroke-width={3}
|
||||||
size={18}
|
size={18}
|
||||||
class=" transition-all duration-200 hover:text-text-muted-dark active:scale-90"
|
class=" transition-all duration-200 hover:text-muted active:scale-90"
|
||||||
></X>
|
></X>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if !toast.hideProgress && toast.tween}
|
{#if !toast.hideProgress && toast.tween}
|
||||||
<div
|
<div style:padding-right={`${toast.tween.current}%`} class=" h-[2px] w-0 bg-primary"></div>
|
||||||
style:padding-right={`${toast.tween.current}%`}
|
|
||||||
class=" h-[2px] w-0 bg-primary-hover-dark"
|
|
||||||
></div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -1,27 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { addToast } from '$lib/stores/toasts';
|
import { mwin_movable } from '$lib/mwinlib/mwin_controller.svelte';
|
||||||
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
import type { MWinAPI } from '$lib/mwinlib/mwin_util';
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import Terminal from '../../modules/Terminal.svelte';
|
|
||||||
import type { ToastMessage } from '../admin/util';
|
|
||||||
|
|
||||||
function bye(tm: ToastMessage): void {
|
let API: MWinAPI;
|
||||||
console.log('Funkcja wywolana');
|
|
||||||
}
|
|
||||||
|
|
||||||
let wrapper = $state<HTMLElement>();
|
|
||||||
|
|
||||||
let username = 'test';
|
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
await FileSystem.init();
|
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
addToast('success', 'Hi~', '', 5000, undefined, undefined, true, false, bye, bye);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Terminal {username}></Terminal>
|
<div class="wrapper relative h-screen w-1/2 bg-blue-500">
|
||||||
|
<div
|
||||||
|
class="absolute h-128 w-5xl bg-red-400 will-change-auto"
|
||||||
|
use:mwin_movable={{
|
||||||
|
wrapper: '.wrapper',
|
||||||
|
baseZIndex: 10,
|
||||||
|
resizable: { threshold: 24 },
|
||||||
|
onAPI: (api) => (API = api)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div></div>
|
||||||
|
<button onclick={() => API.maximize()}>click me</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user