mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
impr: Miglioramenti ai manager
- Aggiunti constructor della classe base nella classe derivata - Alcune proprietà dei manager sono ora protected invece che private - Migliorata identificazione loading button (non si basa più sul tipo ma su un attributo custom) - Migliorata tipizzazione
This commit is contained in:
@@ -21,8 +21,8 @@ type Attributes = JSXElement<Button> & {
|
|||||||
|
|
||||||
export class LoadingButton extends Component<Attributes> {
|
export class LoadingButton extends Component<Attributes> {
|
||||||
view() {
|
view() {
|
||||||
return ( // @ts-ignore
|
return (
|
||||||
<mwc-button type="loading-button" {...this.attrs.all()}>
|
<mwc-button data-component-type="loading-button" {...this.attrs.all()}>
|
||||||
<span slot="icon" style="display: inline;">
|
<span slot="icon" style="display: inline;">
|
||||||
<mwc-circular-progress
|
<mwc-circular-progress
|
||||||
indeterminate
|
indeterminate
|
||||||
|
@@ -4,9 +4,10 @@ import {Manager} from './Manager';
|
|||||||
|
|
||||||
export class CircularProgressManager extends Manager {
|
export class CircularProgressManager extends Manager {
|
||||||
static selector = 'mwc-circular-progress';
|
static selector = 'mwc-circular-progress';
|
||||||
static filter = (element: CircularProgress) => element.closest('mwc-button').type !== 'loading-button';
|
static filter = (element: CircularProgress) => element.closest('mwc-button')?.dataset.componentType !== 'loading-button';
|
||||||
|
|
||||||
constructor(private loading: CircularProgress) {
|
constructor(protected loading: CircularProgress) {
|
||||||
|
super(loading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public show() {
|
public show() {
|
||||||
|
@@ -5,7 +5,8 @@ import {Manager} from './Manager';
|
|||||||
export class DialogManager extends Manager {
|
export class DialogManager extends Manager {
|
||||||
static selector = 'dialog';
|
static selector = 'dialog';
|
||||||
|
|
||||||
constructor(private dialog: Dialog) {
|
constructor(protected dialog: Dialog) {
|
||||||
|
super(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public show(dialog: Dialog) {
|
public show(dialog: Dialog) {
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
import {Button} from '@material/mwc-button';
|
import {Button} from '@material/mwc-button';
|
||||||
import {CircularProgress} from '@material/mwc-circular-progress';
|
|
||||||
import {CircularProgressManager} from '@osm/Components/Managers';
|
import {CircularProgressManager} from '@osm/Components/Managers';
|
||||||
|
|
||||||
export class LoadingButtonManager extends CircularProgressManager {
|
export class LoadingButtonManager extends CircularProgressManager {
|
||||||
static selector = 'mwc-button[type="loading-button"]';
|
static selector = 'mwc-button[data-component-type="loading-button"]';
|
||||||
|
|
||||||
private loading: CircularProgress;
|
|
||||||
|
|
||||||
constructor(private button: Button) {
|
constructor(private button: Button) {
|
||||||
this.loading = button.querySelector('mwc-circular-progress');
|
const loading = button.querySelector('mwc-circular-progress');
|
||||||
|
if (loading) {
|
||||||
|
super(loading);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,11 @@
|
|||||||
|
export type ComponentManager =
|
||||||
|
{new(element: any | HTMLElement): Manager}
|
||||||
|
& Omit<typeof Manager, 'new'>;
|
||||||
|
|
||||||
export abstract class Manager {
|
export abstract class Manager {
|
||||||
abstract static selector: string;
|
static selector: string;
|
||||||
static filter: (element: HTMLElement) => boolean = () => true;
|
static filter: (element: any | HTMLElement) => boolean = () => true;
|
||||||
|
|
||||||
|
protected constructor(protected element: HTMLElement) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import type {Dialog as MWCDialog} from '@material/mwc-dialog';
|
|||||||
import {Menu as MWCMenu} from '@material/mwc-menu';
|
import {Menu as MWCMenu} from '@material/mwc-menu';
|
||||||
import {
|
import {
|
||||||
CircularProgressManager,
|
CircularProgressManager,
|
||||||
|
ComponentManager,
|
||||||
DialogManager,
|
DialogManager,
|
||||||
LoadingButtonManager
|
LoadingButtonManager
|
||||||
} from '@osm/Components/Managers';
|
} from '@osm/Components/Managers';
|
||||||
@@ -51,7 +52,11 @@ function loadTriggers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadManagers() {
|
function loadManagers() {
|
||||||
const managers = [DialogManager, CircularProgressManager, LoadingButtonManager];
|
const managers: ComponentManager[] = [
|
||||||
|
DialogManager,
|
||||||
|
CircularProgressManager,
|
||||||
|
LoadingButtonManager
|
||||||
|
];
|
||||||
|
|
||||||
for (const Manager of managers) {
|
for (const Manager of managers) {
|
||||||
for (const element of document.querySelectorAll<HTMLElement>(Manager.selector)) {
|
for (const element of document.querySelectorAll<HTMLElement>(Manager.selector)) {
|
||||||
|
10
resources/js/globals.d.ts
vendored
10
resources/js/globals.d.ts
vendored
@@ -18,11 +18,7 @@ import {LinearProgress as MWCLinearProgress} from '@material/mwc-linear-progress
|
|||||||
import {List as MWCList} from '@material/mwc-list';
|
import {List as MWCList} from '@material/mwc-list';
|
||||||
import {ListItem as MWCListItem} from '@material/mwc-list/mwc-list-item.js';
|
import {ListItem as MWCListItem} from '@material/mwc-list/mwc-list-item.js';
|
||||||
import {Menu as MWCMenu} from '@material/mwc-menu';
|
import {Menu as MWCMenu} from '@material/mwc-menu';
|
||||||
import {
|
import {Manager} from '@osm/Components/Managers';
|
||||||
CircularProgressManager,
|
|
||||||
DialogManager,
|
|
||||||
LoadingButtonManager
|
|
||||||
} from '@osm/Components/Managers';
|
|
||||||
import type cash from 'cash-dom';
|
import type cash from 'cash-dom';
|
||||||
import type Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
import type router from 'ziggy-js';
|
import type router from 'ziggy-js';
|
||||||
@@ -41,13 +37,11 @@ import {
|
|||||||
TopAppBar
|
TopAppBar
|
||||||
} from './WebComponents';
|
} from './WebComponents';
|
||||||
|
|
||||||
type ComponentManager = CircularProgressManager | DialogManager | LoadingButtonManager;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const route: typeof router;
|
const route: typeof router;
|
||||||
|
|
||||||
let app: {
|
let app: {
|
||||||
components: Record<string, ComponentManager>
|
components: Record<string, Manager>
|
||||||
events: Record<string, Event>,
|
events: Record<string, Event>,
|
||||||
locale: string,
|
locale: string,
|
||||||
modules: OpenSTAManager.Modules,
|
modules: OpenSTAManager.Modules,
|
||||||
|
Reference in New Issue
Block a user