Frontend 

Every package brings its own frontend, written in TypeScript. The core collects the frontends of all installed packages into one import map. A package ships its built files, so an installation needs no Node.js.

Declare the frontend 

A package with a public/ directory and a config/frontend.php contributes a frontend. The file returns an array:

return [
    'imports' => [
        '@adsum/working-time/' => 'js/',
    ],
    'module' => '@adsum/working-time/main.js',
];
Copied!
imports
Maps an import prefix to a directory below public/. Every .js file in it is importable as @adsum/<package>/<path>.
module
The entry module of the package. The core imports it on every page, after the translations are loaded.
styles
Optional. Style sheets below public/ added to every page, for example css/main.css.
importMaps
Optional. Files below public/ that contain further import map entries for built vendor modules.
favicon
Optional. A file below public/ used as the favicon.

The name of the package is the directory name without the adsum- prefix: the package in adsum-working-time is working-time. Its public/ directory is published as /bundles/<name>/.

Files found by convention 

The core also reads two directories in public/:

  • public/translations/<locale>.json: the frontend catalogues, built from the XLIFF files of the package (see Translations and Icons).
  • public/icons/<name>.svg: the icons, usable by name in navigation entries and screens.

Source layout in this repository 

In this repository the sources live outside the package; Vite builds them into public/ of the package.

Build/Sources/TypeScript/<package>/   TypeScript, one JavaScript file per file
Build/Sources/Icons/<package>/        icons.json and own SVG icons
Build/Sources/Scss/<package>/         main.scss, built into css/main.css
packages/web-vision/adsum-<package>/public/   js/, icons/, translations/, css/
Copied!

A package developed elsewhere ships its built public/ directory in the same shape, built with any tool.

Entry module 

The entry module registers the screens and defines the web components of the package. The entry module of the attendance package:

import './screens.js';
import { Clock } from './Clock.js';

if (customElements.get('tt-clock') === undefined) {
    customElements.define('tt-clock', Clock);
}
Copied!

Importing ./screens.js runs the registerScreen() calls (see Screens).

Web components 

Components are Lit elements. lit and Web Awesome come from the import map; do not bundle them. Components use the translations and the API client of the core. The clock of the attendance package, <tt-clock>, shortened:

import { LitElement, html, nothing, type TemplateResult } from 'lit';
import { ApiClient } from '@adsum/core/api/ApiClient.js';
import { translate } from '@adsum/core/i18n/translations.js';

export class Clock extends LitElement {
    public static override properties = {
        status: { state: true },
    };

    public declare status: { state: string } | undefined;

    private readonly api = new ApiClient();

    public override connectedCallback(): void {
        super.connectedCallback();
        void this.reload();
    }

    protected override render(): TemplateResult | typeof nothing {
        return this.status === undefined ? nothing : html`<span>${translate(`clock.state.${this.status.state}`)}</span>`;
    }

    private async reload(): Promise<void> {
        this.status = await this.api.get<{ state: string }>('/me/clock');
    }
}
Copied!

ApiClient has get(), read(), post(), patch(), put() and delete(). It prefixes /api/v1, sends the session cookie and throws on error responses. patch(), put() and delete() take the ETag of the resource as the option ifMatch.

Icons in components 

Show an icon with Web Awesome's wa-icon and the icon library adsum:

<wa-icon library="adsum" name="clock" aria-hidden="true"></wa-icon>
Copied!