elbe-ui 0.4.14 → 0.4.16

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.
@@ -15,7 +15,10 @@ export interface PostArgs extends GetArgs {
15
15
  */
16
16
  export declare class ApiWorker {
17
17
  private apiURL;
18
- constructor(apiURL: string);
18
+ private o?;
19
+ constructor(apiURL: string, o?: {
20
+ credentials?: "omit" | "include" | "same-origin";
21
+ } | undefined);
19
22
  private _fetch;
20
23
  get(path: string, args?: GetArgs): Promise<any>;
21
24
  post(path: string, args: PostArgs): Promise<any>;
@@ -14,11 +14,13 @@ const _noArgs = {};
14
14
  * to use it, you must first call `ApiService.init(apiURL)` with the base URL of your API.
15
15
  */
16
16
  export class ApiWorker {
17
- constructor(apiURL) {
17
+ constructor(apiURL, o) {
18
18
  this.apiURL = apiURL;
19
+ this.o = o;
19
20
  }
20
21
  _fetch(p_1, method_1, _a) {
21
22
  return __awaiter(this, arguments, void 0, function* (p, method, { path, query, body }) {
23
+ var _b, _c;
22
24
  try {
23
25
  p = path
24
26
  ? p.replace(/:([a-zA-Z0-9_]+)/g, (m, p1) => {
@@ -32,7 +34,7 @@ export class ApiWorker {
32
34
  const queryStr = query != null ? "?" + new URLSearchParams(query).toString() : "";
33
35
  const response = yield fetch(this.apiURL + p + queryStr, {
34
36
  method,
35
- credentials: "include",
37
+ credentials: (_c = (_b = this.o) === null || _b === void 0 ? void 0 : _b.credentials) !== null && _c !== void 0 ? _c : "same-origin",
36
38
  headers: { "Content-Type": "application/json" },
37
39
  body: body ? JSON.stringify(body) : undefined,
38
40
  });
@@ -1,10 +1,12 @@
1
- import { ElbeChild, ElbeChildren, HeaderLogos } from "../../..";
1
+ import { VNode } from "preact";
2
+ import { NestedArray } from "preact-iso";
3
+ import { ElbeChild, HeaderLogos } from "../../..";
2
4
  import { MenuItem } from "./menu";
3
5
  export type AppBaseProps = HeaderLogos & {
4
6
  initial?: string;
5
7
  menu: MenuItem[];
6
8
  globalActions?: ElbeChild[];
7
- children: ElbeChildren;
9
+ children: NestedArray<VNode>;
8
10
  };
9
11
  /**
10
12
  * app base is a layout component that provides a side menu and a content area.
@@ -12,4 +14,8 @@ export type AppBaseProps = HeaderLogos & {
12
14
  * used to create a consistent layout for pages. You can also pass global actions
13
15
  * that will be displayed in the header of all pages.
14
16
  */
15
- export declare function AppBase(p: AppBaseProps): import("preact/compat").JSX.Element;
17
+ export declare function AppBase(p: AppBaseProps): import("preact").JSX.Element;
18
+ export declare const Redirect: (p: {
19
+ path: string;
20
+ to: string;
21
+ }) => null;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useState } from "preact/compat";
2
+ import { Router, useLocation } from "preact-iso";
3
+ import { useEffect, useState } from "preact/compat";
3
4
  import { Box } from "../../..";
4
5
  import { AppBaseContext } from "./ctx_app_base";
5
6
  import { Menu } from "./menu";
@@ -10,7 +11,7 @@ import { Menu } from "./menu";
10
11
  * that will be displayed in the header of all pages.
11
12
  */
12
13
  export function AppBase(p) {
13
- var _a;
14
+ var _a, _b;
14
15
  const [menuOpen, setMenuOpen] = useState(false);
15
16
  return (_jsx(AppBaseContext.Provider, { value: {
16
17
  menuOpen: menuOpen,
@@ -26,5 +27,12 @@ export function AppBase(p) {
26
27
  display: "flex",
27
28
  width: "100%",
28
29
  minHeight: "100vh",
29
- }, children: [_jsx(Menu, { items: p.menu }), _jsx("div", { style: { flex: 1 }, children: p.children })] }) }));
30
+ }, children: [_jsx(Menu, { items: p.menu }), _jsx("div", { style: { flex: 1 }, children: _jsxs(Router, { children: [_jsx(Redirect, { path: "/", to: `/${(_b = p.initial) !== null && _b !== void 0 ? _b : p.menu[0].id}` }), p.children] }) })] }) }));
30
31
  }
32
+ export const Redirect = (p) => {
33
+ const location = useLocation();
34
+ useEffect(() => {
35
+ location.route(p.to, true);
36
+ }, [p.to]);
37
+ return null; // This component doesn't render anything
38
+ };
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useComputed } from "@preact/signals";
3
2
  import { MenuIcon } from "lucide-react";
4
- import { route } from "preact-router";
3
+ import { useLocation } from "preact-iso";
5
4
  import { useLayoutMode, useTheme, useThemeConfig } from "../../..";
6
5
  import { Card, elevatedShadow } from "../base/card";
7
6
  import { Button } from "../button/button";
@@ -54,10 +53,7 @@ export function Menu(p) {
54
53
  } }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i) => (_jsx(_MenuItemView, { item: i }))) }), topBot.bottom.map((i) => (_jsx(_MenuItemView, { item: i })))] })) })] }));
55
54
  }
56
55
  function _MenuItemView({ item }) {
57
- const selected = useComputed(() => {
58
- const log = document.location.pathname;
59
- return log.startsWith(`/${item.id}`);
60
- });
56
+ const location = useLocation();
61
57
  const appBase = useAppBase();
62
- return (_jsx(Button, { ariaLabel: item.label, contentAlign: "start", manner: selected.value ? "major" : "plain", label: appBase.menuOpen ? item.label : undefined, icon: item.icon, onTap: item.disabled ? undefined : () => route(`/${item.id}`, true) }));
58
+ return (_jsx(Button, { ariaLabel: item.label, contentAlign: "start", manner: location.path.startsWith(`/${item.id}`) ? "major" : "plain", label: appBase.menuOpen ? item.label : undefined, icon: item.icon, onTap: item.disabled ? undefined : () => location.route(`/${item.id}`, true) }));
63
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,6 +38,7 @@
38
38
  "colors-convert": "^1.4.1",
39
39
  "lucide-react": "^0.438.0",
40
40
  "preact": "^10.24.2",
41
+ "preact-iso": "^2.9.1",
41
42
  "preact-router": "^4.1.2",
42
43
  "vite": "^5.4.10"
43
44
  }