@olenbetong/appframe-ds 0.9.0 → 1.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.
- package/CHANGELOG.md +123 -0
- package/package.json +22 -17
- package/scripts/copyAssets.mjs +3 -0
- package/src/autocomplete/Autocomplete.css +13 -0
- package/src/autocomplete/Autocomplete.tsx +3 -1
- package/src/autocomplete/Combobox.tsx +16 -3
- package/src/binding/BoundTextField.tsx +9 -1
- package/src/filter/FieldFilterPanel.css +25 -2
- package/src/grid/AfGridColumnsPanel.tsx +1 -1
- package/src/grid/AfGridContext.tsx +1 -1
- package/src/grid/AfGridError.tsx +1 -1
- package/src/grid/AfHeaderFilterCell.tsx +1 -1
- package/src/grid/Toolbar.tsx +1 -1
- package/src/grid/editing.ts +17 -7
- package/src/grid/filter.ts +1 -1
- package/src/grid/index.css +59 -1
- package/src/grid/index.tsx +126 -18
- package/src/grid/localization.ts +1 -1
- package/src/grid/slots/index.tsx +27 -2
- package/src/grid/theme.tsx +3 -50
- package/src/grid/useAfColumns.tsx +103 -45
- package/src/grid/useAfCurrentIndex.ts +13 -5
- package/src/grid/useAfGridApi.ts +6 -1
- package/src/grid/useAfKeyBindings.ts +1 -1
- package/src/grid/useAfNewItemRow.ts +258 -0
- package/src/grid/useAfPagination.ts +2 -2
- package/src/grid/useAfPersistedState.ts +9 -1
- package/src/grid/useAfRowEditModel.ts +20 -12
- package/src/grid/useAfRowGrouping.ts +47 -0
- package/src/grid/useAfServerAggregation.ts +145 -0
- package/src/grid/useAfSortModel.ts +15 -3
- package/src/layout/AppMenuDrawer.css +70 -0
- package/src/layout/AppMenuDrawer.tsx +122 -0
- package/src/layout/index.tsx +1 -0
- package/src/mdi/Mdi.css +138 -0
- package/src/mdi/Mdi.test.tsx +87 -0
- package/src/mdi/Mdi.tsx +141 -0
- package/src/mdi/MdiConfirmCloseDialog.tsx +47 -0
- package/src/mdi/MdiContext.tsx +59 -0
- package/src/mdi/MdiDocumentContext.tsx +60 -0
- package/src/mdi/MdiPanel.tsx +61 -0
- package/src/mdi/MdiRestore.test.tsx +82 -0
- package/src/mdi/MdiTab.tsx +30 -0
- package/src/mdi/controller.test.ts +382 -0
- package/src/mdi/controller.ts +656 -0
- package/src/mdi/dockviewHost.ts +132 -0
- package/src/mdi/fakeHost.ts +200 -0
- package/src/mdi/host.ts +44 -0
- package/src/mdi/ids.test.ts +20 -0
- package/src/mdi/ids.ts +18 -0
- package/src/mdi/index.ts +31 -0
- package/src/mdi/layoutRestore.test.ts +156 -0
- package/src/mdi/layoutRestore.ts +311 -0
- package/src/mdi/layoutSpec.test.ts +143 -0
- package/src/mdi/layoutSpec.ts +214 -0
- package/src/mdi/layoutStore.test.ts +93 -0
- package/src/mdi/layoutStore.ts +99 -0
- package/src/mdi/memorySettingsStore.ts +21 -0
- package/src/mdi/registry.ts +34 -0
- package/src/mdi/testTypes.ts +37 -0
- package/src/mdi/theme.ts +22 -0
- package/src/mdi/types.ts +214 -0
- package/src/page/Page.css +10 -2
- package/src/page/PageBlock.css +5 -0
- package/src/page/PageBlock.tsx +14 -0
- package/src/page/PageHeader.css +0 -60
- package/src/page/PageHeader.tsx +6 -74
- package/src/test/happy-dom-document-class.ts +24 -0
- package/src/test/setup.ts +4 -0
- package/src/theme/useDsColorScheme.ts +53 -0
package/src/page/PageHeader.tsx
CHANGED
|
@@ -4,10 +4,9 @@ import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
|
4
4
|
|
|
5
5
|
import clsx from "clsx";
|
|
6
6
|
import type React from "react";
|
|
7
|
-
import { useEffect, useRef, useState } from "react";
|
|
8
|
-
import { useLocation } from "react-router";
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { type AppMenuProps } from "../layout/AppMenu.js";
|
|
9
|
+
import { AppMenuDrawer, useAppMenuDrawer } from "../layout/AppMenuDrawer.js";
|
|
11
10
|
import { PageBlock, type PageBlockWidth } from "./PageBlock.js";
|
|
12
11
|
|
|
13
12
|
export type PageHeaderVariant = "appbar" | "plain";
|
|
@@ -57,64 +56,6 @@ export type PageHeaderProps = Omit<React.HTMLAttributes<HTMLElement>, "title"> &
|
|
|
57
56
|
variant?: PageHeaderVariant;
|
|
58
57
|
};
|
|
59
58
|
|
|
60
|
-
function useIsMobile() {
|
|
61
|
-
let [isMobile, setIsMobile] = useState(() => {
|
|
62
|
-
if (typeof window === "undefined") return false;
|
|
63
|
-
return window.matchMedia("(max-width: 1199px)").matches;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
let mq = window.matchMedia("(max-width: 1199px)");
|
|
68
|
-
let handler = (e: MediaQueryListEvent) => setIsMobile(e.matches);
|
|
69
|
-
mq.addEventListener("change", handler);
|
|
70
|
-
return () => mq.removeEventListener("change", handler);
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
return isMobile;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type PageHeaderDrawerProps = {
|
|
77
|
-
AppMenuProps?: AppMenuProps;
|
|
78
|
-
menu: React.ReactNode;
|
|
79
|
-
onClose: () => void;
|
|
80
|
-
isMobile: boolean;
|
|
81
|
-
open: boolean;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
function PageHeaderDrawer({ AppMenuProps, menu, onClose, isMobile, open }: PageHeaderDrawerProps) {
|
|
85
|
-
let location = useLocation();
|
|
86
|
-
let prevLocation = useRef(location);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (location !== prevLocation.current) {
|
|
90
|
-
prevLocation.current = location;
|
|
91
|
-
if (isMobile) onClose();
|
|
92
|
-
}
|
|
93
|
-
}, [location, isMobile, onClose]);
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<>
|
|
97
|
-
{isMobile && (
|
|
98
|
-
<div
|
|
99
|
-
className={clsx("ObPageHeader-drawerOverlay", open && "ObPageHeader-drawerOpen")}
|
|
100
|
-
onClick={onClose}
|
|
101
|
-
aria-hidden="true"
|
|
102
|
-
/>
|
|
103
|
-
)}
|
|
104
|
-
<div
|
|
105
|
-
className={clsx(
|
|
106
|
-
"ObPageHeader-drawer",
|
|
107
|
-
"AppMenu-drawer",
|
|
108
|
-
isMobile ? "ObPageHeader-drawerOverlayMode" : "ObPageHeader-drawerDocked",
|
|
109
|
-
open && "ObPageHeader-drawerOpen",
|
|
110
|
-
)}
|
|
111
|
-
>
|
|
112
|
-
<AppMenu {...AppMenuProps}>{menu}</AppMenu>
|
|
113
|
-
</div>
|
|
114
|
-
</>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
59
|
/**
|
|
119
60
|
* Page header for use inside `Page`. See the `variant` prop for the two
|
|
120
61
|
* supported header styles.
|
|
@@ -131,12 +72,7 @@ export function PageHeader({
|
|
|
131
72
|
width,
|
|
132
73
|
...props
|
|
133
74
|
}: PageHeaderProps) {
|
|
134
|
-
let isMobile =
|
|
135
|
-
let [desktopOpen, setDesktopOpen] = useState(true);
|
|
136
|
-
let [mobileOpen, setMobileOpen] = useState(false);
|
|
137
|
-
|
|
138
|
-
let open = isMobile ? mobileOpen : desktopOpen;
|
|
139
|
-
let toggle = () => (isMobile ? setMobileOpen((o) => !o) : setDesktopOpen((o) => !o));
|
|
75
|
+
let { open, isMobile, toggle, close } = useAppMenuDrawer();
|
|
140
76
|
|
|
141
77
|
if (variant === "plain") {
|
|
142
78
|
return (
|
|
@@ -171,13 +107,9 @@ export function PageHeader({
|
|
|
171
107
|
</PageBlock>
|
|
172
108
|
{children}
|
|
173
109
|
{menu && (
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
onClose={() => setMobileOpen(false)}
|
|
178
|
-
isMobile={isMobile}
|
|
179
|
-
open={open}
|
|
180
|
-
/>
|
|
110
|
+
<AppMenuDrawer AppMenuProps={AppMenuProps} isMobile={isMobile} onClose={close} open={open}>
|
|
111
|
+
{menu}
|
|
112
|
+
</AppMenuDrawer>
|
|
181
113
|
)}
|
|
182
114
|
</header>
|
|
183
115
|
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* happy-dom exposes a `Document` constructor on the window that is *not* in the
|
|
3
|
+
* prototype chain of the actual `document` (which is an `HTMLDocument` built on
|
|
4
|
+
* happy-dom's internal `Document` class). `document instanceof Document` is
|
|
5
|
+
* therefore `false`, which is enough to hang libraries that walk up the tree
|
|
6
|
+
* until they reach the document — the `@oddbird/popover-polyfill` bundled into
|
|
7
|
+
* `@digdir/designsystemet-web` loops forever in `nearestInclusiveOpenPopover`,
|
|
8
|
+
* taking the whole worker with it.
|
|
9
|
+
*
|
|
10
|
+
* Point the global `Document` at the class the document really inherits from.
|
|
11
|
+
* Must run before anything that captures `Document`.
|
|
12
|
+
*/
|
|
13
|
+
export function fixHappyDomDocumentClass(): void {
|
|
14
|
+
if (typeof document === "undefined" || document instanceof Document) return;
|
|
15
|
+
|
|
16
|
+
for (let proto = Object.getPrototypeOf(document); proto; proto = Object.getPrototypeOf(proto)) {
|
|
17
|
+
let ctor = proto.constructor;
|
|
18
|
+
if (ctor?.name === "Document") {
|
|
19
|
+
globalThis.Document = ctor;
|
|
20
|
+
(globalThis as typeof globalThis & { window: typeof globalThis }).window.Document = ctor;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/test/setup.ts
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export function getDsColorScheme(element?: Element | null): "light" | "dark" {
|
|
4
|
+
let scoped = element?.closest<HTMLElement>("[data-color-scheme]");
|
|
5
|
+
let scheme =
|
|
6
|
+
scoped?.dataset.colorScheme ??
|
|
7
|
+
document.body?.dataset.colorScheme ??
|
|
8
|
+
document.documentElement?.dataset.colorScheme ??
|
|
9
|
+
"light";
|
|
10
|
+
|
|
11
|
+
if (scheme === "auto") {
|
|
12
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return scheme === "dark" ? "dark" : "light";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
20
|
+
* sets `data-color-scheme` on `<body>`, but it may also be scoped to a subtree,
|
|
21
|
+
* so resolve it from `element` upwards when one is given. The OS preference is
|
|
22
|
+
* watched too, since it decides the result when the scheme is `auto`.
|
|
23
|
+
*/
|
|
24
|
+
export function useDsColorScheme(element?: Element | null) {
|
|
25
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getDsColorScheme(element));
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
function update() {
|
|
29
|
+
setScheme(getDsColorScheme(element));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
update();
|
|
33
|
+
|
|
34
|
+
// `data-color-scheme` may sit on any ancestor, so watch the whole document
|
|
35
|
+
// for that one attribute rather than just `<html>` and `<body>`.
|
|
36
|
+
let observer = new MutationObserver(update);
|
|
37
|
+
observer.observe(document.documentElement, {
|
|
38
|
+
attributes: true,
|
|
39
|
+
attributeFilter: ["data-color-scheme"],
|
|
40
|
+
subtree: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
44
|
+
media?.addEventListener("change", update);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
observer.disconnect();
|
|
48
|
+
media?.removeEventListener("change", update);
|
|
49
|
+
};
|
|
50
|
+
}, [element]);
|
|
51
|
+
|
|
52
|
+
return scheme;
|
|
53
|
+
}
|