@olenbetong/synergi-react 3.2.1 → 4.0.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.
Files changed (112) hide show
  1. package/es/chrome/AppShell/index.d.ts +10 -2
  2. package/es/chrome/AppShell/index.js +13 -97
  3. package/es/chrome/openReport.d.ts +22 -0
  4. package/es/chrome/openReport.js +21 -0
  5. package/es/colorScheme.d.ts +4 -4
  6. package/es/components/Toolbar/index.d.ts +20 -11
  7. package/es/components/Toolbar/index.js +47 -6
  8. package/es/elements/ElementLookup.d.ts +7 -2
  9. package/es/elements/ElementLookup.js +4 -6
  10. package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
  11. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
  13. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
  14. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
  15. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
  16. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
  17. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
  18. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
  19. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
  20. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
  21. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +10 -6
  22. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
  23. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +222 -116
  24. package/es/elements/ElementLookupDialog/index.d.ts +6 -0
  25. package/es/elements/ElementLookupDialog/index.js +2 -2
  26. package/es/index.d.ts +3 -4
  27. package/es/index.js +5 -4
  28. package/package.json +11 -10
  29. package/src/chrome/AppShell/index.tsx +13 -134
  30. package/src/chrome/openReport.ts +34 -0
  31. package/src/colorScheme.ts +4 -4
  32. package/src/components/Toolbar/index.tsx +65 -14
  33. package/src/elements/ElementLookup.tsx +12 -5
  34. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
  35. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
  36. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +29 -14
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +246 -136
  42. package/src/elements/ElementLookupDialog/index.tsx +12 -4
  43. package/src/index.ts +6 -37
  44. package/es/chrome/AppMenu/AppMenu.css +0 -648
  45. package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
  46. package/es/chrome/AppMenu/AppMenu.js +0 -145
  47. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
  48. package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
  49. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
  50. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
  51. package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
  52. package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
  53. package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
  54. package/es/chrome/AppMenu/AppMenuList.js +0 -39
  55. package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
  56. package/es/chrome/AppMenu/AppMenuRail.js +0 -30
  57. package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
  58. package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
  59. package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
  60. package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
  61. package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
  62. package/es/chrome/AppMenu/developerCategories.js +0 -116
  63. package/es/chrome/AppMenu/icons.d.ts +0 -15
  64. package/es/chrome/AppMenu/icons.js +0 -13
  65. package/es/chrome/AppMenu/index.d.ts +0 -12
  66. package/es/chrome/AppMenu/index.js +0 -10
  67. package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
  68. package/es/chrome/AppMenu/menuEntries.js +0 -93
  69. package/es/chrome/AppMenu/types.d.ts +0 -43
  70. package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
  71. package/es/chrome/AppMenu/useFavorites.js +0 -28
  72. package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
  73. package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
  74. package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
  75. package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
  76. package/es/report/ReportLauncher.css +0 -147
  77. package/es/report/ReportLauncher.d.ts +0 -55
  78. package/es/report/ReportLauncher.js +0 -142
  79. package/es/report/ReportLauncher.test.js +0 -231
  80. package/es/report/ReportParameters.css +0 -29
  81. package/es/report/ReportParameters.d.ts +0 -46
  82. package/es/report/ReportParameters.js +0 -65
  83. package/es/report/ReportParameters.test.d.ts +0 -1
  84. package/es/report/ReportParameters.test.js +0 -84
  85. package/es/report/index.d.ts +0 -2
  86. package/es/report/index.js +0 -2
  87. package/src/chrome/AppMenu/AppMenu.css +0 -648
  88. package/src/chrome/AppMenu/AppMenu.tsx +0 -285
  89. package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
  90. package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
  91. package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
  92. package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
  93. package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
  94. package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
  95. package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
  96. package/src/chrome/AppMenu/developerCategories.ts +0 -142
  97. package/src/chrome/AppMenu/icons.tsx +0 -76
  98. package/src/chrome/AppMenu/index.ts +0 -17
  99. package/src/chrome/AppMenu/menuEntries.ts +0 -128
  100. package/src/chrome/AppMenu/types.ts +0 -45
  101. package/src/chrome/AppMenu/useFavorites.ts +0 -40
  102. package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
  103. package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
  104. package/src/report/ReportLauncher.css +0 -147
  105. package/src/report/ReportLauncher.test.tsx +0 -281
  106. package/src/report/ReportLauncher.tsx +0 -420
  107. package/src/report/ReportParameters.css +0 -29
  108. package/src/report/ReportParameters.test.tsx +0 -133
  109. package/src/report/ReportParameters.tsx +0 -198
  110. package/src/report/index.ts +0 -2
  111. /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
  112. /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
@@ -1,9 +1,15 @@
1
- import { type ReactNode } from "react";
1
+ import type { ReactNode } from "react";
2
2
  export type AppShellProps = {
3
3
  children: ReactNode;
4
4
  };
5
5
  /**
6
- * Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
6
+ * Standard Synergi app shell: the error boundary around the app.
7
+ *
8
+ * The site chrome (app menu, user menu, colour scheme, service worker update)
9
+ * is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
10
+ * bundle the `ob.2026.application` template loads, which marks the page with
11
+ * `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
12
+ * `ToolbarPortal` and `ToolbarBreadcrumbs`.
7
13
  *
8
14
  * This component is Designsystemet-only. Apps that still render MUI components
9
15
  * should additionally wrap it in `MuiThemeProvider` from
@@ -11,3 +17,5 @@ export type AppShellProps = {
11
17
  * tokens into a MUI theme.
12
18
  */
13
19
  export declare function AppShell({ children }: AppShellProps): import("react").JSX.Element;
20
+ /** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
21
+ export declare function hasSiteChrome(): boolean;
@@ -1,85 +1,13 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { getLocalizedString } from "@olenbetong/appframe-core";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import { AppErrorBoundary } from "@olenbetong/appframe-ds";
4
- import { useCallback, useMemo, useState } from "react";
5
- import { createPortal } from "react-dom";
6
- import { AppMenu } from "../AppMenu/AppMenu.js";
7
- import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
8
- import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
9
- import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
10
- const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
11
- /*
12
- * `aviw_WebShared_Articles` stores every published version of an article as its
13
- * own row, and rows for all sites share the view. Without the host name filter
14
- * and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
15
- * canonical article) every app shows up once per published version.
16
- */
17
- const menuArticlesWhereClause = [
18
- `HostName = '${hostName.replace(/'/g, "''")}'`,
19
- "ArticleVersion IS NULL",
20
- "LastPublished IS NOT NULL",
21
- "Authenticated = 1",
22
- "ListOnFrontPage = 1",
23
- "SysApp = 0",
24
- "HideFromNav = 0",
25
- "Hidden = 0",
26
- "ISNULL(ParentArticleId, '') <> 'news'",
27
- ].join(" AND ");
28
- // Created once — shared across all AppShell instances on a page.
29
- const dsMenuArticles = af.data.generateApiDataObject({
30
- resource: "aviw_WebShared_Articles",
31
- id: "dsMenuArticles",
32
- allowUpdate: false,
33
- allowInsert: false,
34
- allowDelete: false,
35
- dynamicLoading: false,
36
- fields: [
37
- { name: "ArticleId", type: "string", nullable: false },
38
- { name: "Title", type: "string", nullable: true },
39
- { name: "MenuGroup", type: "string", nullable: true },
40
- { name: "Path", type: "string", nullable: true },
41
- { name: "IsFavorite", type: "boolean", nullable: true },
42
- ],
43
- parameters: {
44
- maxRecords: -1,
45
- whereClause: menuArticlesWhereClause,
46
- sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
47
- },
48
- });
49
- // Toggles the current user's favorite state for an article.
50
- const procSetArticleFavorite = new af.ProcedureAPI({
51
- procedureId: "astp_WebShared_SetArticleFavorite",
52
- parameters: [
53
- { name: "HostName", type: "string", required: true, hasDefault: false },
54
- { name: "ArticleID", type: "string", required: true, hasDefault: false },
55
- { name: "Favorite", type: "boolean", required: false, hasDefault: true },
56
- ],
57
- timeout: 30000,
58
- });
59
- // The current user's employee record, used for the photo and full name.
60
- const dsAppMenuUser = af.data.generateApiDataObject({
61
- resource: "aviw_Personnel_Employees_Lookup",
62
- id: "dsAppMenuUser",
63
- allowUpdate: false,
64
- allowInsert: false,
65
- allowDelete: false,
66
- dynamicLoading: false,
67
- fields: [
68
- { name: "PrimKey", type: "string", nullable: false },
69
- { name: "PersonID", type: "string", nullable: false },
70
- { name: "FirstName", type: "string", nullable: true },
71
- { name: "LastName", type: "string", nullable: true },
72
- { name: "Fullname", type: "string", nullable: true },
73
- { name: "ImageHash", type: "number", nullable: true },
74
- ],
75
- parameters: {
76
- maxRecords: 1,
77
- // Resolved server side so it doesn't depend on the session being hydrated.
78
- whereClause: "PersonID = SUSER_SNAME()",
79
- },
80
- });
81
3
  /**
82
- * Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
4
+ * Standard Synergi app shell: the error boundary around the app.
5
+ *
6
+ * The site chrome (app menu, user menu, colour scheme, service worker update)
7
+ * is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
8
+ * bundle the `ob.2026.application` template loads, which marks the page with
9
+ * `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
10
+ * `ToolbarPortal` and `ToolbarBreadcrumbs`.
83
11
  *
84
12
  * This component is Designsystemet-only. Apps that still render MUI components
85
13
  * should additionally wrap it in `MuiThemeProvider` from
@@ -87,21 +15,9 @@ const dsAppMenuUser = af.data.generateApiDataObject({
87
15
  * tokens into a MUI theme.
88
16
  */
89
17
  export function AppShell({ children }) {
90
- const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
91
- const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
92
- // The developer tools are only reachable for developers, so hide them for
93
- // everyone else instead of showing links that all return 403.
94
- const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
95
- // The portal isn't listed with the apps, so link to it from the menu itself
96
- // unless that's the article we're already on.
97
- const homeLink = useMemo(() => {
98
- const articleId = (globalThis.af?.article?.id ?? "").replace(/\.\d+$/, "");
99
- return articleId === "portal" ? undefined : { label: getLocalizedString("Front page"), href: "/portal" };
100
- }, []);
101
- const toggleFavorite = useCallback(async (articleId, favorite) => {
102
- await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
103
- }, []);
104
- const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
105
- return (_jsxs(AppErrorBoundary, { children: [appMenuSlot &&
106
- createPortal(_jsx(AppMenuToggle, { open: isAppMenuOpen, hasUpdate: isUpdateAvailable, "aria-controls": "ob-app-menu", onClick: () => setIsAppMenuOpen((open) => !open) }), appMenuSlot), _jsx(AppMenu, { id: "ob-app-menu", dataObject: dsMenuArticles, userDataObject: dsAppMenuUser, categories: categories, homeLink: homeLink, onToggleFavorite: toggleFavorite, hasUpdate: isUpdateAvailable, onInstallUpdate: installUpdate, open: isAppMenuOpen, onClose: () => setIsAppMenuOpen(false) }), children] }));
18
+ return _jsx(AppErrorBoundary, { children: children });
19
+ }
20
+ /** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
21
+ export function hasSiteChrome() {
22
+ return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
107
23
  }
@@ -0,0 +1,22 @@
1
+ export type OpenReportOptions = {
2
+ /**
3
+ * Overrides the filter the report was designed with, as a criteria string.
4
+ * An empty string starts the launcher with no filter at all.
5
+ */
6
+ initialFilter?: string | null;
7
+ /** The tab shown first. */
8
+ defaultTab?: "parameters" | "filter";
9
+ };
10
+ /**
11
+ * Opens a report in the site chrome's report launcher, the way the app menu does.
12
+ *
13
+ * The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
14
+ * so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
15
+ * On a page without the chrome (a legacy template) the call is logged and ignored.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
20
+ * ```
21
+ */
22
+ export declare function openReport(reportId: string, options?: OpenReportOptions): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Opens a report in the site chrome's report launcher, the way the app menu does.
3
+ *
4
+ * The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
5
+ * so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
6
+ * On a page without the chrome (a legacy template) the call is logged and ignored.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
11
+ * ```
12
+ */
13
+ export function openReport(reportId, options) {
14
+ let chrome = globalThis.ob?.chrome;
15
+ if (chrome?.openReport) {
16
+ chrome.openReport(reportId, options);
17
+ }
18
+ else {
19
+ console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
20
+ }
21
+ }
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * The preference lives in the `ob-color-scheme` cookie so the article template
5
5
  * can read it server side and render `data-color-scheme` on `<html>` and
6
- * `<body>` before the first paint. The site script for the 2026 template
7
- * (`ob.2026.application.min.js`) owns the same cookie for the toolbar user menu
8
- * toggle, so both write the cookie, apply the attributes, and dispatch
9
- * `COLOR_SCHEME_CHANGE_EVENT` to keep every toggle on the page in sync.
6
+ * `<body>` before the first paint. The site chrome bundle
7
+ * (`@olenbetong/synergi-chrome`) owns the same cookie for the toolbar user menu
8
+ * and app menu toggles, so all of them write the cookie, apply the attributes,
9
+ * and dispatch `COLOR_SCHEME_CHANGE_EVENT` to keep every toggle on the page in sync.
10
10
  */
11
11
  export type ColorSchemePreference = "auto" | "light" | "dark";
12
12
  /** Dispatched on `window` whenever the preference changes. */
@@ -1,19 +1,27 @@
1
1
  import "./Toolbar.css";
2
2
  import { type To } from "react-router";
3
- /**
4
- * The named regions of the site toolbar an app can render into.
5
- *
6
- * `menu-toggle` sits at the very start of the toolbar, before the logo: it is where an app that
7
- * has a navigation drawer of its own hangs the button that opens it. That belongs on the same
8
- * edge as the drawer it controls — a toggle in `actions`, at the opposite end of the toolbar,
9
- * reads as unrelated to the panel that slides in on the left.
10
- */
11
- export type ToolbarPortalSlot = "menu-toggle" | "breadcrumbs" | "search" | "actions";
12
3
  export type ToolbarPortalProps = {
13
- slot: ToolbarPortalSlot;
14
4
  children: React.ReactNode;
15
5
  };
16
- export declare function ToolbarPortal({ slot, children }: ToolbarPortalProps): import("react").ReactPortal | null;
6
+ /**
7
+ * Renders its children into the toolbar's app region. Render `ToolbarBreadcrumbs` before any
8
+ * other `ToolbarPortal`, since the region lays its children out in mount order with the first
9
+ * one taking the free space. Renders nothing on a template without a toolbar.
10
+ */
11
+ export declare function ToolbarPortal({ children }: ToolbarPortalProps): import("react").ReactPortal | null;
12
+ export type ToolbarDrawerToggleProps = {
13
+ /** Whether the drawer is open; sets `aria-expanded`. */
14
+ open: boolean;
15
+ onToggle: () => void;
16
+ /** Accessible name. Defaults to the localized "Toggle menu". */
17
+ label?: string;
18
+ };
19
+ /**
20
+ * The hamburger button for the app's navigation drawer, rendered into the toolbar's drawer slot.
21
+ * Styled by the site stylesheet (`.ob-toolbar__icon-button`) so it inherits the toolbar's
22
+ * contrast colour on every brand. Renders nothing on a template without a toolbar.
23
+ */
24
+ export declare function ToolbarDrawerToggle({ open, onToggle, label }: ToolbarDrawerToggleProps): import("react").ReactPortal | null;
17
25
  export type BreadcrumbItem = {
18
26
  label: string;
19
27
  /**
@@ -32,4 +40,5 @@ export type BreadcrumbItem = {
32
40
  export type ToolbarBreadcrumbsProps = {
33
41
  items: BreadcrumbItem[];
34
42
  };
43
+ /** The app's breadcrumb trail, rendered into the toolbar's app region. The last item is the current page. */
35
44
  export declare function ToolbarBreadcrumbs({ items }: ToolbarBreadcrumbsProps): import("react").JSX.Element;
@@ -1,17 +1,57 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import "./Toolbar.css";
3
+ import { MenuHamburgerIcon } from "@navikt/aksel-icons";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
3
5
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
4
6
  import { createPortal } from "react-dom";
5
7
  import { Link } from "react-router";
6
- export function ToolbarPortal({ slot, children }) {
7
- // Target element IDs: ob-toolbar-menu-toggle, ob-toolbar-breadcrumbs, ob-toolbar-search,
8
- // ob-toolbar-actions. Older templates do not render every slot, so a missing one is not an
9
- // error — the app simply renders nothing there.
10
- const target = document.getElementById(`ob-toolbar-${slot}`);
8
+ /*
9
+ * The site template (`ob.2026.application`) renders the toolbar and leaves two regions to the
10
+ * app. Both are filled through portals, so the app's React tree (router, contexts, state) is
11
+ * preserved inside them:
12
+ *
13
+ * - the app region (`#ob-toolbar-app`): breadcrumbs first, then any per-app controls;
14
+ * - the drawer slot (`#ob-toolbar-drawer`) at the far left of the toolbar, reserved for the
15
+ * toggle of the app's navigation drawer — the same edge the drawer slides in from.
16
+ *
17
+ * Everything else in the toolbar (brand, Apps button, user menu) is the site's, rendered by the
18
+ * chrome bundle. The phase 1 template rendered separate slots instead; those ids are kept as
19
+ * fallbacks until every site runs the current template.
20
+ */
21
+ const APP_REGION_IDS = ["ob-toolbar-app", "ob-toolbar-breadcrumbs"];
22
+ const DRAWER_SLOT_IDS = ["ob-toolbar-drawer", "ob-toolbar-menu-toggle"];
23
+ function findTarget(ids) {
24
+ if (typeof document === "undefined")
25
+ return null;
26
+ for (let id of ids) {
27
+ let element = document.getElementById(id);
28
+ if (element)
29
+ return element;
30
+ }
31
+ return null;
32
+ }
33
+ /**
34
+ * Renders its children into the toolbar's app region. Render `ToolbarBreadcrumbs` before any
35
+ * other `ToolbarPortal`, since the region lays its children out in mount order with the first
36
+ * one taking the free space. Renders nothing on a template without a toolbar.
37
+ */
38
+ export function ToolbarPortal({ children }) {
39
+ let target = findTarget(APP_REGION_IDS);
11
40
  if (!target)
12
41
  return null;
13
42
  return createPortal(children, target);
14
43
  }
44
+ /**
45
+ * The hamburger button for the app's navigation drawer, rendered into the toolbar's drawer slot.
46
+ * Styled by the site stylesheet (`.ob-toolbar__icon-button`) so it inherits the toolbar's
47
+ * contrast colour on every brand. Renders nothing on a template without a toolbar.
48
+ */
49
+ export function ToolbarDrawerToggle({ open, onToggle, label }) {
50
+ let target = findTarget(DRAWER_SLOT_IDS);
51
+ if (!target)
52
+ return null;
53
+ return createPortal(_jsx("button", { type: "button", className: "ob-toolbar__icon-button", "aria-label": label ?? getLocalizedString("Toggle menu"), "aria-expanded": open, onClick: onToggle, children: _jsx(MenuHamburgerIcon, { "aria-hidden": true, fontSize: "1.5rem" }) }), target);
54
+ }
15
55
  /**
16
56
  * A crumb the user can follow. `to` goes through the router; `href` is an ordinary link.
17
57
  *
@@ -75,6 +115,7 @@ function BreadcrumbsInner({ items }) {
75
115
  return (_jsx("li", { className: "ob-breadcrumbs__item", children: isCurrent ? _jsx("span", { "aria-current": "page", children: item.label }) : _jsx(BreadcrumbLink, { item: item }) }, actualIndex));
76
116
  })] }) }));
77
117
  }
118
+ /** The app's breadcrumb trail, rendered into the toolbar's app region. The last item is the current page. */
78
119
  export function ToolbarBreadcrumbs({ items }) {
79
- return (_jsx(ToolbarPortal, { slot: "breadcrumbs", children: _jsx(BreadcrumbsInner, { items: items }) }));
120
+ return (_jsx(ToolbarPortal, { children: _jsx(BreadcrumbsInner, { items: items }) }));
80
121
  }
@@ -1,4 +1,5 @@
1
- import { type RefObject } from "react";
1
+ import { type ReactNode, type RefObject } from "react";
2
+ import type { DecoderFactory } from "./ElementLookupDialog/BarcodeScanner";
2
3
  export type Element = {
3
4
  Domain: string;
4
5
  PrimKey: string;
@@ -18,5 +19,9 @@ export type ElementLookupProps = {
18
19
  openLookupDialogIcon?: boolean;
19
20
  onChange?: (value: Element | null) => void;
20
21
  onDialogChange?: (open: boolean) => void;
22
+ /** Engine for the camera tab of the lookup dialog. Defaults to zxing-wasm. */
23
+ decoder?: DecoderFactory;
24
+ /** Extra controls in the camera tab footer, e.g. an engine picker. */
25
+ scannerActions?: ReactNode;
21
26
  };
22
- export declare function ElementLookup({ value, defaultValue, ref, elementIDRequired, openLookupDialogIcon, onChange, onDialogChange, }: ElementLookupProps): import("react").JSX.Element;
27
+ export declare function ElementLookup({ value, defaultValue, ref, elementIDRequired, openLookupDialogIcon, onChange, onDialogChange, decoder, scannerActions, }: ElementLookupProps): import("react").JSX.Element;
@@ -4,12 +4,11 @@ import { IconButton, TextField } from "@mui/material";
4
4
  import { getLocalizedString } from "@olenbetong/appframe-core";
5
5
  import { useEffect, useImperativeHandle, useRef, useState } from "react";
6
6
  import { ElementLookupDialog } from "./ElementLookupDialog";
7
- export function ElementLookup({ value, defaultValue, ref, elementIDRequired = false, openLookupDialogIcon, onChange, onDialogChange, }) {
7
+ export function ElementLookup({ value, defaultValue, ref, elementIDRequired = false, openLookupDialogIcon, onChange, onDialogChange, decoder, scannerActions, }) {
8
8
  let initializedRef = useRef(false);
9
9
  let [openElementLookupDialog, setOpenElementLookupDialog] = useState(false);
10
10
  let [element, setElement] = useState(defaultValue ?? null);
11
11
  let elementValue = value === undefined ? element : value;
12
- // biome-ignore lint: intentionally skipping "value" dependency as this shouldn't run when "value" changes
13
12
  useEffect(() => {
14
13
  if (initializedRef.current) {
15
14
  return;
@@ -18,7 +17,7 @@ export function ElementLookup({ value, defaultValue, ref, elementIDRequired = fa
18
17
  setElement(defaultValue);
19
18
  initializedRef.current = true;
20
19
  }
21
- }, [defaultValue]);
20
+ }, [defaultValue]); // oxlint-disable-line react-hooks/exhaustive-deps (intentionally skipping "value" dependency as this shouldn't run when "value" changes)
22
21
  useImperativeHandle(ref, () => ({
23
22
  openDialog: () => setOpenElementLookupDialog(true),
24
23
  closeDialog: () => setOpenElementLookupDialog(false),
@@ -27,11 +26,10 @@ export function ElementLookup({ value, defaultValue, ref, elementIDRequired = fa
27
26
  onChange?.(addElement.element);
28
27
  setElement(addElement.element);
29
28
  }
30
- // biome-ignore lint: only run when openElementLookupDialog changes
31
29
  useEffect(() => {
32
30
  onDialogChange?.(openElementLookupDialog);
33
- }, [openElementLookupDialog]);
34
- return (_jsxs(_Fragment, { children: [_jsx(ElementLookupDialog, { open: openElementLookupDialog, mode: "single", onClose: () => setOpenElementLookupDialog(false), onAdd: handleAddElement, allowEmptyElement: !elementIDRequired }), _jsx("input", { type: "hidden", name: "ProjectID", value: elementValue?.ProjectID ?? "" }), _jsx("input", { type: "hidden", name: "ElementRef", value: elementValue?.PrimKey ?? "" }), _jsx(TextField, { id: "NewElementDamge_Project", value: elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : "", label: getLocalizedString("Project"), fullWidth: true, required: true, autoComplete: "off", slotProps: { htmlInput: { readOnly: true } } }), _jsx(TextField, { name: "ElementID", id: "NewElementDamage_ElementID", value: elementValue ? elementValue.ElementID : "", label: getLocalizedString("Element ID"), fullWidth: true, required: elementIDRequired, autoComplete: "off", slotProps: {
31
+ }, [openElementLookupDialog]); // oxlint-disable-line react-hooks/exhaustive-deps (only run when openElementLookupDialog changes)
32
+ return (_jsxs(_Fragment, { children: [_jsx(ElementLookupDialog, { open: openElementLookupDialog, mode: "single", onClose: () => setOpenElementLookupDialog(false), onAdd: handleAddElement, allowEmptyElement: !elementIDRequired, decoder: decoder, scannerActions: scannerActions }), _jsx("input", { type: "hidden", name: "ProjectID", value: elementValue?.ProjectID ?? "" }), _jsx("input", { type: "hidden", name: "ElementRef", value: elementValue?.PrimKey ?? "" }), _jsx(TextField, { id: "NewElementDamge_Project", value: elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : "", label: getLocalizedString("Project"), fullWidth: true, required: true, autoComplete: "off", slotProps: { htmlInput: { readOnly: true } } }), _jsx(TextField, { name: "ElementID", id: "NewElementDamage_ElementID", value: elementValue ? elementValue.ElementID : "", label: getLocalizedString("Element ID"), fullWidth: true, required: elementIDRequired, autoComplete: "off", slotProps: {
35
33
  htmlInput: { readOnly: true },
36
34
  input: {
37
35
  endAdornment: openLookupDialogIcon ? (_jsx(IconButton, { onClick: () => setOpenElementLookupDialog(true), children: _jsx(SearchIcon, {}) })) : undefined,
@@ -0,0 +1,32 @@
1
+ export type DecodedPoint = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export type DecodedBarcode = {
6
+ /** Decoded text. GS1 DataMatrix keeps the FNC1 separators as U+001D. */
7
+ text: string;
8
+ /** Corners of the symbol in frame pixel coordinates: top-left, top-right, bottom-right, bottom-left. */
9
+ corners: [DecodedPoint, DecodedPoint, DecodedPoint, DecodedPoint];
10
+ /** Engine-specific format name, when reported. */
11
+ format?: string;
12
+ };
13
+ /**
14
+ * A barcode decoding engine. `BarcodeScanner` owns the camera and the frame loop and only hands
15
+ * frames to the decoder, so any engine that can read a canvas or an image file can be plugged in.
16
+ */
17
+ export interface BarcodeDecoder {
18
+ /** Short identifier shown in the scanner UI, e.g. "zxing", "native" or "dbr". */
19
+ readonly name: string;
20
+ /** Decode one camera frame drawn on a canvas. The scanner never has more than one call in flight. */
21
+ decodeFrame(frame: HTMLCanvasElement): Promise<DecodedBarcode[]>;
22
+ /** Decode a still image, such as a photo upload. May use slower, more thorough settings. */
23
+ decodeImage(file: Blob): Promise<DecodedBarcode[]>;
24
+ /** Release engine resources. Called when the scanner unmounts. */
25
+ dispose?(): void;
26
+ }
27
+ /**
28
+ * Creates a decoder. The heavy work — downloading a WebAssembly build or a vendor script — happens
29
+ * here, not when the factory itself is created, so the factory is cheap to pass around and nothing
30
+ * is loaded until the scanner mounts.
31
+ */
32
+ export type DecoderFactory = () => Promise<BarcodeDecoder>;
@@ -0,0 +1,28 @@
1
+ import type { DecodedBarcode, DecoderFactory } from "../decoder";
2
+ export type DbrDecoderOptions = {
3
+ /** URL of the Dynamsoft Barcode Reader 6.x script, e.g. `/lib/dbr/dbr-6.5.1.min.js`. */
4
+ scriptUrl: string;
5
+ licenseKey: string;
6
+ };
7
+ /** The parts of a Dynamsoft `TextResult` the mapper reads, typed locally so the vendor types stay out of the public API. */
8
+ export type DbrTextResult = {
9
+ BarcodeText: string;
10
+ BarcodeFormat: number;
11
+ LocalizationResult: {
12
+ X1: number;
13
+ Y1: number;
14
+ X2: number;
15
+ Y2: number;
16
+ X3: number;
17
+ Y3: number;
18
+ X4: number;
19
+ Y4: number;
20
+ };
21
+ };
22
+ export declare function mapDbrResult(result: DbrTextResult): DecodedBarcode;
23
+ /**
24
+ * Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
25
+ * comparison against the free engines; the script is loaded on demand rather than by the article
26
+ * so users who never scan do not pay for it.
27
+ */
28
+ export declare function createDbrDecoder({ scriptUrl, licenseKey }: DbrDecoderOptions): DecoderFactory;
@@ -0,0 +1,81 @@
1
+ let scriptLoading;
2
+ function getGlobal() {
3
+ return window.BarcodeReader;
4
+ }
5
+ /** Loads the vendor script once, reusing `window.BarcodeReader` if the page already has it. */
6
+ function loadBarcodeReader(scriptUrl) {
7
+ let existing = getGlobal();
8
+ if (existing)
9
+ return Promise.resolve(existing);
10
+ if (!scriptLoading) {
11
+ scriptLoading = new Promise((resolve, reject) => {
12
+ let script = document.createElement("script");
13
+ script.src = scriptUrl;
14
+ script.async = true;
15
+ script.onload = () => {
16
+ let loaded = getGlobal();
17
+ if (loaded) {
18
+ resolve(loaded);
19
+ }
20
+ else {
21
+ scriptLoading = undefined;
22
+ reject(new Error(`${scriptUrl} did not define BarcodeReader`));
23
+ }
24
+ };
25
+ script.onerror = () => {
26
+ scriptLoading = undefined;
27
+ script.remove();
28
+ reject(new Error(`Failed to load ${scriptUrl}`));
29
+ };
30
+ document.head.append(script);
31
+ });
32
+ }
33
+ return scriptLoading;
34
+ }
35
+ export function mapDbrResult(result) {
36
+ let { X1, Y1, X2, Y2, X3, Y3, X4, Y4 } = result.LocalizationResult;
37
+ return {
38
+ text: result.BarcodeText,
39
+ format: String(result.BarcodeFormat),
40
+ corners: [
41
+ { x: X1, y: Y1 },
42
+ { x: X2, y: Y2 },
43
+ { x: X3, y: Y3 },
44
+ { x: X4, y: Y4 },
45
+ ],
46
+ };
47
+ }
48
+ /**
49
+ * Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
50
+ * comparison against the free engines; the script is loaded on demand rather than by the article
51
+ * so users who never scan do not pay for it.
52
+ */
53
+ export function createDbrDecoder({ scriptUrl, licenseKey }) {
54
+ return async () => {
55
+ if (typeof WebAssembly === "undefined") {
56
+ throw new Error("WebAssembly is not supported");
57
+ }
58
+ let BarcodeReader = await loadBarcodeReader(scriptUrl);
59
+ BarcodeReader.licenseKey = licenseKey;
60
+ let reader = await BarcodeReader.createInstance();
61
+ let settings = reader.getRuntimeSettings();
62
+ settings.mBarcodeFormatIds = BarcodeReader.EnumBarcodeFormat.DATAMATRIX;
63
+ settings.mAntiDamageLevel = 3;
64
+ settings.mDeblurLevel = 0;
65
+ await reader.updateRuntimeSettings(settings);
66
+ return {
67
+ name: "dbr",
68
+ async decodeFrame(frame) {
69
+ let results = await reader.decode(frame);
70
+ return results.map(mapDbrResult);
71
+ },
72
+ async decodeImage(file) {
73
+ let results = await reader.decode(file);
74
+ return results.map(mapDbrResult);
75
+ },
76
+ dispose() {
77
+ reader.deleteInstance();
78
+ },
79
+ };
80
+ };
81
+ }
@@ -0,0 +1,26 @@
1
+ import type { DecodedBarcode, DecoderFactory } from "../decoder";
2
+ /**
3
+ * Minimal typing of the Barcode Detection API. It is not part of the TypeScript DOM lib because
4
+ * only Chromium-based browsers implement it.
5
+ */
6
+ export type NativeDetectedBarcode = {
7
+ rawValue: string;
8
+ format: string;
9
+ cornerPoints: Array<{
10
+ x: number;
11
+ y: number;
12
+ }>;
13
+ boundingBox: DOMRectReadOnly;
14
+ };
15
+ /**
16
+ * Whether the browser can detect DataMatrix codes natively. Chrome on desktop exposes the
17
+ * `BarcodeDetector` class without any formats, so the class alone is not enough.
18
+ */
19
+ export declare function isNativeDecoderAvailable(): Promise<boolean>;
20
+ export declare function mapNativeResult(result: NativeDetectedBarcode): DecodedBarcode;
21
+ /**
22
+ * Decoder backed by the browser's own Barcode Detection API (ML Kit on Android). Nothing to
23
+ * download, but only available where the browser supports it — check `isNativeDecoderAvailable`
24
+ * first and fall back to another decoder when it returns false.
25
+ */
26
+ export declare function createNativeDecoder(): DecoderFactory;
@@ -0,0 +1,70 @@
1
+ import { getLocalizedString } from "@olenbetong/appframe-core";
2
+ const DATA_MATRIX = "data_matrix";
3
+ function getNativeDetector() {
4
+ return globalThis.BarcodeDetector;
5
+ }
6
+ /**
7
+ * Whether the browser can detect DataMatrix codes natively. Chrome on desktop exposes the
8
+ * `BarcodeDetector` class without any formats, so the class alone is not enough.
9
+ */
10
+ export async function isNativeDecoderAvailable() {
11
+ try {
12
+ let detector = getNativeDetector();
13
+ if (!detector)
14
+ return false;
15
+ let formats = await detector.getSupportedFormats();
16
+ return formats.includes(DATA_MATRIX);
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ export function mapNativeResult(result) {
23
+ let points = result.cornerPoints;
24
+ let { left, top, right, bottom } = result.boundingBox;
25
+ let corners = points.length >= 4
26
+ ? [
27
+ { x: points[0].x, y: points[0].y },
28
+ { x: points[1].x, y: points[1].y },
29
+ { x: points[2].x, y: points[2].y },
30
+ { x: points[3].x, y: points[3].y },
31
+ ]
32
+ : [
33
+ { x: left, y: top },
34
+ { x: right, y: top },
35
+ { x: right, y: bottom },
36
+ { x: left, y: bottom },
37
+ ];
38
+ return { text: result.rawValue, format: result.format, corners };
39
+ }
40
+ /**
41
+ * Decoder backed by the browser's own Barcode Detection API (ML Kit on Android). Nothing to
42
+ * download, but only available where the browser supports it — check `isNativeDecoderAvailable`
43
+ * first and fall back to another decoder when it returns false.
44
+ */
45
+ export function createNativeDecoder() {
46
+ return async () => {
47
+ let Detector = getNativeDetector();
48
+ if (!Detector || !(await isNativeDecoderAvailable())) {
49
+ throw new Error(getLocalizedString("This browser cannot detect barcodes natively"));
50
+ }
51
+ let detector = new Detector({ formats: [DATA_MATRIX] });
52
+ return {
53
+ name: "native",
54
+ async decodeFrame(frame) {
55
+ let results = await detector.detect(frame);
56
+ return results.map(mapNativeResult);
57
+ },
58
+ async decodeImage(file) {
59
+ let bitmap = await createImageBitmap(file);
60
+ try {
61
+ let results = await detector.detect(bitmap);
62
+ return results.map(mapNativeResult);
63
+ }
64
+ finally {
65
+ bitmap.close();
66
+ }
67
+ },
68
+ };
69
+ };
70
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReaderOptions, ReadResult } from "zxing-wasm/reader";
2
+ import type { DecodedBarcode, DecoderFactory } from "../decoder";
3
+ export type ZxingDecoderOptions = {
4
+ /**
5
+ * URL of `zxing_reader.wasm`. When omitted, zxing-wasm fetches the binary matching its own version
6
+ * from the jsDelivr CDN.
7
+ */
8
+ wasmUrl?: string;
9
+ /** Reader options for live camera frames. Merged over the defaults. */
10
+ frameOptions?: ReaderOptions;
11
+ /** Reader options for still images. Merged over the defaults. */
12
+ imageOptions?: ReaderOptions;
13
+ };
14
+ export declare function mapZxingResult(result: ReadResult): DecodedBarcode;
15
+ /**
16
+ * Decoder backed by zxing-cpp compiled to WebAssembly (`zxing-wasm`). Free, runs everywhere
17
+ * WebAssembly does, including iOS Safari. The module is imported when the factory runs, so apps
18
+ * that never open the scanner do not download it.
19
+ */
20
+ export declare function createZxingDecoder(options?: ZxingDecoderOptions): DecoderFactory;