@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/src/loaders.ts CHANGED
@@ -17,11 +17,16 @@
17
17
  * @docs extending/ui-kit
18
18
  */
19
19
 
20
- /** A module the runtime imports on first use, keyed as the kit's documents spell their `$src`. */
21
- export type KitModuleLoader = () => Promise<Record<string, unknown>>;
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: Readonly<Record<string, KitModuleLoader>> = {
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, ...(source ? { source } : {}) });
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 as HTMLElement & {
63
- showPopover?: (options?: { source?: Element }) => void;
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 as JxStyle;
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[`@layer ${THEME_LAYER}`] ?? {}) as JxStyle;
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 (typeof CSSStyleSheet === "function" && "replaceSync" in CSSStyleSheet.prototype) {
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];