@jxsuite/ui 0.5.1 → 0.7.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/package.json +5 -4
- package/src/behaviors/action-group.ts +0 -1
- package/src/behaviors/color-area.ts +19 -21
- package/src/behaviors/color-field.ts +63 -28
- package/src/behaviors/color-slider.ts +13 -11
- package/src/behaviors/combobox.ts +8 -9
- package/src/behaviors/dialog.ts +2 -2
- package/src/behaviors/listbox.ts +4 -3
- package/src/behaviors/menu.ts +14 -15
- package/src/behaviors/number-field.ts +7 -9
- package/src/behaviors/popover.ts +33 -47
- package/src/behaviors/select.ts +22 -9
- package/src/behaviors/split.ts +41 -25
- package/src/behaviors/swatch-group.ts +4 -7
- package/src/behaviors/tabs.ts +4 -7
- package/src/behaviors/textfield.ts +35 -14
- package/src/behaviors/toast-host.ts +11 -8
- package/src/behaviors/toast.ts +22 -21
- package/src/behaviors/toolbar.ts +2 -3
- package/src/behaviors/tooltip.ts +52 -30
- package/src/behaviors/tree.ts +19 -9
- package/src/color.ts +17 -2
- package/src/documents.ts +68 -42
- package/src/icons.ts +10 -8
- package/src/index.ts +8 -3
- package/src/loaders.ts +9 -4
- package/src/testing/popover-shim.ts +18 -7
- package/src/theme.ts +4 -3
package/src/loaders.ts
CHANGED
|
@@ -17,11 +17,16 @@
|
|
|
17
17
|
* @docs extending/ui-kit
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
import type { JxScope } from "@jxsuite/runtime/types";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A module the runtime imports on first use, keyed as the kit's documents spell their `$src`. The
|
|
24
|
+
* namespace it resolves to is read into scope, export by export, as `KIT_MODULES` entries are.
|
|
25
|
+
*/
|
|
26
|
+
export type KitModuleLoader = () => Promise<JxScope>;
|
|
22
27
|
|
|
23
28
|
/** Behaviour modules as loaders, under the `$src` specifiers the documents use. */
|
|
24
|
-
export const KIT_LOADERS
|
|
29
|
+
export const KIT_LOADERS = {
|
|
25
30
|
"jx-ui:/behaviors/color-area.ts": () => import("./behaviors/color-area.ts"),
|
|
26
31
|
"jx-ui:/behaviors/color-field.ts": () => import("./behaviors/color-field.ts"),
|
|
27
32
|
"jx-ui:/behaviors/color-slider.ts": () => import("./behaviors/color-slider.ts"),
|
|
@@ -44,4 +49,4 @@ export const KIT_LOADERS: Readonly<Record<string, KitModuleLoader>> = {
|
|
|
44
49
|
"jx-ui:/behaviors/toast-host.ts": () => import("./behaviors/toast-host.ts"),
|
|
45
50
|
"jx-ui:/color.ts": () => import("./color.ts"),
|
|
46
51
|
"jx-ui:/icons.ts": () => import("./icons.ts"),
|
|
47
|
-
}
|
|
52
|
+
} as const satisfies Readonly<Record<string, KitModuleLoader>>;
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* are the browser's to verify.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import { isFunction } from "@jxsuite/schema/guards";
|
|
17
|
+
|
|
16
18
|
interface PopoverState {
|
|
17
19
|
open: Set<HTMLElement>;
|
|
18
20
|
/** The invoker each showing popover was shown from, when `showPopover({ source })` named one. */
|
|
@@ -37,7 +39,10 @@ function toggleEvent(
|
|
|
37
39
|
source?: Element | null,
|
|
38
40
|
): Event {
|
|
39
41
|
const event = new Event(type, { bubbles: false, cancelable: type === "beforetoggle" });
|
|
40
|
-
Object.assign(event, { newState, oldState
|
|
42
|
+
Object.assign(event, { newState, oldState });
|
|
43
|
+
if (source) {
|
|
44
|
+
Object.assign(event, { source });
|
|
45
|
+
}
|
|
41
46
|
return event;
|
|
42
47
|
}
|
|
43
48
|
|
|
@@ -58,13 +63,19 @@ function modeOf(el: HTMLElement): "auto" | "hint" | "manual" {
|
|
|
58
63
|
return raw === "auto" || raw === "" ? "auto" : "manual";
|
|
59
64
|
}
|
|
60
65
|
|
|
66
|
+
/**
|
|
67
|
+
* `HTMLElement.prototype` as a DOM without the popover API presents it: the methods this shim
|
|
68
|
+
* installs may be absent, which the DOM lib's own `HTMLElement` type cannot say.
|
|
69
|
+
*/
|
|
70
|
+
interface PopoverPrototype {
|
|
71
|
+
showPopover?: (options?: ShowPopoverOptions) => void;
|
|
72
|
+
hidePopover?: () => void;
|
|
73
|
+
togglePopover?: (force?: boolean) => boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
61
76
|
export function installPopoverShim(): void {
|
|
62
|
-
const proto = HTMLElement.prototype
|
|
63
|
-
|
|
64
|
-
hidePopover?: () => void;
|
|
65
|
-
togglePopover?: (force?: boolean) => boolean;
|
|
66
|
-
};
|
|
67
|
-
if (typeof proto.showPopover === "function") {
|
|
77
|
+
const proto: PopoverPrototype = HTMLElement.prototype;
|
|
78
|
+
if (isFunction(proto.showPopover)) {
|
|
68
79
|
return;
|
|
69
80
|
}
|
|
70
81
|
const state: PopoverState = { invokers: new WeakMap(), open: new Set() };
|
package/src/theme.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @docs extending/ui-kit
|
|
11
11
|
*/
|
|
12
12
|
import { buildStyleRules } from "@jxsuite/runtime/css";
|
|
13
|
+
import { getNestedStyle, isFunction } from "@jxsuite/schema/guards";
|
|
13
14
|
import type { JxStyle } from "@jxsuite/schema/types";
|
|
14
15
|
import project from "../project.json";
|
|
15
16
|
|
|
@@ -17,7 +18,7 @@ import project from "../project.json";
|
|
|
17
18
|
export const THEME_LAYER = "jx-ui";
|
|
18
19
|
|
|
19
20
|
/** The `style` block as authored: one key, the cascade layer, holding every declaration. */
|
|
20
|
-
const themeStyle = project.style
|
|
21
|
+
const themeStyle: JxStyle = project.style;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* The tokens themselves, from inside the layer.
|
|
@@ -27,7 +28,7 @@ const themeStyle = project.style as JxStyle;
|
|
|
27
28
|
* jx-ui` and let it look up a token that is one level down, which returns `undefined` rather than
|
|
28
29
|
* failing.
|
|
29
30
|
*/
|
|
30
|
-
export const themeTokens = (themeStyle
|
|
31
|
+
export const themeTokens: JxStyle = getNestedStyle(themeStyle, `@layer ${THEME_LAYER}`) ?? {};
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* The theme as CSS text: every token on `:root`, inside `@layer jx-ui`.
|
|
@@ -67,7 +68,7 @@ export function installTheme(doc: Document = document): void {
|
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
const css = themeCSS();
|
|
70
|
-
if (
|
|
71
|
+
if (isFunction(globalThis.CSSStyleSheet) && "replaceSync" in CSSStyleSheet.prototype) {
|
|
71
72
|
const sheet = new CSSStyleSheet();
|
|
72
73
|
sheet.replaceSync(css);
|
|
73
74
|
doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];
|