@mintplayer/react-bootstrap 19.20.0 → 19.22.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.
@@ -1,10 +1,11 @@
1
+ import { jsx as l } from "react/jsx-runtime";
1
2
  import * as a from "react";
2
- import { createComponent as e } from "@lit/react";
3
- import { MpDatatable as t } from "@mintplayer/web-components/datatable";
4
- const l = e({
3
+ import { createComponent as r } from "@lit/react";
4
+ import { MpDatatable as p } from "@mintplayer/web-components/datatable";
5
+ const m = r({
5
6
  react: a,
6
7
  tagName: "mp-datatable",
7
- elementClass: t,
8
+ elementClass: p,
8
9
  events: {
9
10
  onPageChange: "mp-datatable-page-change",
10
11
  onPerPageChange: "mp-datatable-per-page-change",
@@ -20,7 +21,14 @@ const l = e({
20
21
  onFilterClose: "mp-datatable-filter-close",
21
22
  onFilterChange: "mp-datatable-filter-change"
22
23
  }
23
- });
24
+ }), s = a.forwardRef(
25
+ function({ selectedRows: t, ...n }, o) {
26
+ const e = a.useRef(null);
27
+ return a.useImperativeHandle(o, () => e.current), a.useLayoutEffect(() => {
28
+ e.current && t !== void 0 && (e.current.selectedRows = t);
29
+ }, [t]), /* @__PURE__ */ l(m, { ref: e, ...n });
30
+ }
31
+ );
24
32
  export {
25
- l as BsDatatable
33
+ s as BsDatatable
26
34
  };
@@ -1,5 +1,6 @@
1
1
  import { EventName } from '@lit/react';
2
2
  import { MpDatatable, RowEventDetail, SortChangeEventDetail, SelectionChangeEventDetail, TreeRowExpandDetail, TreeExpandedIdsChangeDetail, FilterChangeDetail } from '@mintplayer/web-components/datatable';
3
+ import * as React from 'react';
3
4
  /**
4
5
  * React wrapper for `<mp-datatable>`. Side-effect-registers the WC via
5
6
  * the import above. The `events` map surfaces each CustomEvent the WC
@@ -15,8 +16,27 @@ import { MpDatatable, RowEventDetail, SortChangeEventDetail, SelectionChangeEven
15
16
  * `{ data, totalRecords }`. `createComponent` forwards it to the element's
16
17
  * `fetch` property, and the web component owns the whole loop — initial page,
17
18
  * on-demand windows, tree children, pagination, sort/perPage reloads. The
18
- * consumer wires nothing else (no `totalRecords`, no event bridge). Selected
19
- * row objects arrive on `onSelectionChange`'s `detail.selectedRows`.
19
+ * consumer wires nothing else (no `totalRecords`, no event bridge). To
20
+ * re-query with an unchanged callback, call `reload({ resetPage? })` on the
21
+ * element ref; `applyFetchState({ fetch, sortColumns, page, perPage })` applies
22
+ * several of those as one change (one request). Pass a stable `fetch`
23
+ * (`useCallback`): a new function is a new source and reloads.
24
+ *
25
+ * Selection: `selectionMode` is `'none' | 'single' | 'multiple' | 'checkbox'`
26
+ * (`'checkbox'` selects only through the checkbox column; a row click just
27
+ * opens the row). Act on `onSelectionChange`'s `detail.selectedIds` — it is
28
+ * authoritative and holds every selected key, across pages. `detail.selectedRows`
29
+ * is index-aligned with it and covers every key whose row the element has ever
30
+ * seen, off-page rows included; it is `undefined` where a key's row was never
31
+ * seen, so narrow before use. The `selectedRows` prop REPLACES the selection
32
+ * with the given rows (keys derived through `rowKey`, rows remembered even
33
+ * when not loaded) and emits no event; it is pushed when its reference changes,
34
+ * never on an unrelated re-render. **Memoise it** (`useMemo`, or state): an
35
+ * inline literal such as `selectedRows={[row]}` is a new array on every render,
36
+ * so every render pushes it again and reverts the user's clicks. `rowKey` is
37
+ * required to be stable too (an id-less row that is not loaded is keyed
38
+ * `rowKey(row, -1)`, so they all collapse onto `row--1`). `rowLabel: (row) => string` names each
39
+ * row's checkbox ("Select {label}"); it defaults to the first cell's text.
20
40
  *
21
41
  * Filtering: mark a column `filterable` and it gets the built-in panel — search,
22
42
  * include/exclude, checkbox list, clear — with no wrapper code, because the
@@ -26,7 +46,7 @@ import { MpDatatable, RowEventDetail, SortChangeEventDetail, SelectionChangeEven
26
46
  * entirely, and must return a STABLE node: it is mounted once per open, and
27
47
  * repainting it is the renderer's job via `context.onChange`.
28
48
  */
29
- export declare const BsDatatable: import('@lit/react').ReactWebComponent<MpDatatable, {
49
+ declare const BsDatatableElement: import('@lit/react').ReactWebComponent<MpDatatable, {
30
50
  onPageChange: EventName<CustomEvent<{
31
51
  page: number;
32
52
  }>>;
@@ -49,3 +69,17 @@ export declare const BsDatatable: import('@lit/react').ReactWebComponent<MpDatat
49
69
  }>>;
50
70
  onFilterChange: EventName<CustomEvent<FilterChangeDetail>>;
51
71
  }>;
72
+ export type BsDatatableProps = Omit<React.ComponentProps<typeof BsDatatableElement>, 'ref'>;
73
+ /**
74
+ * `createComponent` re-assigns every element property on every render (it
75
+ * leaves dirty-checking to the element). That is harmless for every prop but
76
+ * `selectedRows`, whose setter REPLACES the selection: an unrelated re-render
77
+ * would revert the user's clicks to the stale prop. So `selectedRows` is held
78
+ * back and pushed only when its own reference changes (as the Vue wrapper does).
79
+ * That only helps a MEMOISED array: an inline `selectedRows={[row]}` is a new
80
+ * reference on every render and still reverts clicks.
81
+ * The effect runs after the inner element's, so `rowKey` and `data` are set
82
+ * before the keys are derived.
83
+ */
84
+ export declare const BsDatatable: React.ForwardRefExoticComponent<BsDatatableProps & React.RefAttributes<MpDatatable>>;
85
+ export {};
@@ -1,4 +1,4 @@
1
- import { jsx as a } from "react/jsx-runtime";
1
+ import { jsx as d } from "react/jsx-runtime";
2
2
  import * as n from "react";
3
3
  import { createComponent as f } from "@lit/react";
4
4
  import { MpDropdownMenu as u } from "@mintplayer/web-components/dropdown-menu";
@@ -9,8 +9,8 @@ const m = f({
9
9
  events: {
10
10
  onSelect: "select"
11
11
  }
12
- }), v = n.forwardRef(function({ maxHeight: e, ...o }, r) {
13
- return /* @__PURE__ */ a(
12
+ }), R = n.forwardRef(function({ maxHeight: e, ...o }, r) {
13
+ return /* @__PURE__ */ d(
14
14
  m,
15
15
  {
16
16
  ref: r,
@@ -18,29 +18,29 @@ const m = f({
18
18
  ...o
19
19
  }
20
20
  );
21
- }), R = n.forwardRef(
22
- function({ active: e, disabled: o, value: r, className: t, children: i, ...c }, l) {
21
+ }), v = n.forwardRef(
22
+ function({ active: e, disabled: o, value: r, className: t, children: i, ...c }, p) {
23
23
  const s = n.useRef(null);
24
- n.useImperativeHandle(l, () => s.current), n.useEffect(() => {
25
- s.current && (s.current.value = r);
24
+ n.useImperativeHandle(p, () => s.current), n.useEffect(() => {
25
+ s.current && (s.current.dropdownValue = r);
26
26
  }, [r]);
27
- const p = ["dropdown-item", e ? "active" : "", o ? "disabled" : "", t ?? ""].filter(Boolean).join(" ");
28
- return /* @__PURE__ */ a("li", { ref: s, className: p, "aria-disabled": o ? !0 : void 0, ...c, children: i });
27
+ const l = ["dropdown-item", e ? "active" : "", o ? "disabled" : "", t ?? ""].filter(Boolean).join(" ");
28
+ return /* @__PURE__ */ d("li", { ref: s, className: l, "aria-disabled": o ? !0 : void 0, ...c, children: i });
29
29
  }
30
30
  ), M = n.forwardRef(
31
31
  function({ className: e, ...o }, r) {
32
32
  const t = ["dropdown-divider", e ?? ""].filter(Boolean).join(" ");
33
- return /* @__PURE__ */ a("li", { ref: r, role: "separator", className: t, ...o });
33
+ return /* @__PURE__ */ d("li", { ref: r, role: "separator", className: t, ...o });
34
34
  }
35
35
  ), j = n.forwardRef(
36
36
  function({ className: e, children: o, ...r }, t) {
37
37
  const i = ["dropdown-header", e ?? ""].filter(Boolean).join(" ");
38
- return /* @__PURE__ */ a("li", { ref: t, className: i, ...r, children: o });
38
+ return /* @__PURE__ */ d("li", { ref: t, className: i, ...r, children: o });
39
39
  }
40
40
  );
41
41
  export {
42
42
  M as BsDropdownDivider,
43
43
  j as BsDropdownHeader,
44
- R as BsDropdownItem,
45
- v as BsDropdownMenu
44
+ v as BsDropdownItem,
45
+ R as BsDropdownMenu
46
46
  };
@@ -13,7 +13,9 @@ export interface BsDropdownItemProps extends Omit<React.LiHTMLAttributes<HTMLLIE
13
13
  * light-DOM `<li class="dropdown-item">` that the menu WC styles via its shadow
14
14
  * `::slotted(.dropdown-item)` rule. Put the navigable content inside, e.g.
15
15
  * `<BsDropdownItem><a href="/x">Action</a></BsDropdownItem>` (the companion
16
- * stylesheet resets the nested link). The opaque `value` is assigned as a `value`
17
- * property on the `<li>` so the menu can carry it in its `select` event.
16
+ * stylesheet resets the nested link). The opaque `value` is assigned as the
17
+ * `dropdownValue` property on the `<li>` so the menu can carry it in its `select`
18
+ * event — not as `value`, which `HTMLLIElement` owns as a native long (an object
19
+ * or a string written there becomes 0).
18
20
  */
19
21
  export declare const BsDropdownItem: React.ForwardRefExoticComponent<BsDropdownItemProps & React.RefAttributes<HTMLLIElement>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/react-bootstrap",
3
- "version": "19.20.0",
3
+ "version": "19.22.0",
4
4
  "description": "React 19 wrappers around @mintplayer/web-components. Each sub-entry maps one-to-one with a WC sub-entry and exposes typed React components via @lit/react's createComponent.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -150,6 +150,10 @@
150
150
  "types": "./tab-control/src/index.d.ts",
151
151
  "import": "./tab-control/index.mjs"
152
152
  },
153
+ "./theming": {
154
+ "types": "./theming/src/index.d.ts",
155
+ "import": "./theming/index.mjs"
156
+ },
153
157
  "./tile-manager": {
154
158
  "types": "./tile-manager/src/index.d.ts",
155
159
  "import": "./tile-manager/index.mjs"
@@ -179,7 +183,7 @@
179
183
  "react": "^19.0.0",
180
184
  "react-dom": "^19.0.0",
181
185
  "@lit/react": "^1.0.0",
182
- "@mintplayer/web-components": "^2.0.0"
186
+ "@mintplayer/web-components": "^2.18.0"
183
187
  },
184
188
  "dependencies": {
185
189
  "tslib": "^2.3.0"
@@ -0,0 +1,49 @@
1
+ import * as f from "react";
2
+ import { useSyncExternalStore as c, useMemo as d } from "react";
3
+ import { getBsThemeStore as s, resolveMode as M, MpThemeToggle as T, BS_THEME_DEFAULT_MODES as a } from "@mintplayer/web-components/theming";
4
+ import { BS_THEME_COOKIE_NAME as w, BS_THEME_DEFAULT_MODES as H, BS_THEME_DEFAULT_MODE_META as x, configureBsTheme as R, getBsThemeStore as j, injectThemeAttribute as F, isValidThemeMode as L, readDefaultModeMeta as N, readThemeCookie as U, resolveMode as k, resolveServerTheme as y, writeThemeCookie as V } from "@mintplayer/web-components/theming";
5
+ import { jsx as E } from "react/jsx-runtime";
6
+ import { createComponent as h } from "@lit/react";
7
+ const m = Object.freeze({
8
+ mode: "auto",
9
+ effectiveMode: M("auto", !1)
10
+ }), n = () => typeof window < "u", u = (e) => n() ? s().subscribe(e) : () => {
11
+ };
12
+ let r = m;
13
+ const S = () => {
14
+ if (!n()) return m;
15
+ const e = s(), o = e.getMode(), t = e.effectiveMode();
16
+ return (r.mode !== o || r.effectiveMode !== t) && (r = { mode: o, effectiveMode: t }), r;
17
+ }, g = () => m, p = (e) => {
18
+ n() && s().setMode(e);
19
+ };
20
+ function D() {
21
+ const e = c(u, S, g);
22
+ return d(
23
+ () => ({ mode: e.mode, effectiveMode: e.effectiveMode, setMode: p }),
24
+ [e]
25
+ );
26
+ }
27
+ const l = h({
28
+ react: f,
29
+ tagName: "mp-theme-toggle",
30
+ elementClass: T
31
+ }), O = f.forwardRef(function({ modes: o, ...t }, i) {
32
+ return /* @__PURE__ */ E(l, { ref: i, modes: o ?? a, ...t });
33
+ });
34
+ export {
35
+ w as BS_THEME_COOKIE_NAME,
36
+ H as BS_THEME_DEFAULT_MODES,
37
+ x as BS_THEME_DEFAULT_MODE_META,
38
+ O as BsThemeToggle,
39
+ R as configureBsTheme,
40
+ j as getBsThemeStore,
41
+ F as injectThemeAttribute,
42
+ L as isValidThemeMode,
43
+ N as readDefaultModeMeta,
44
+ U as readThemeCookie,
45
+ k as resolveMode,
46
+ y as resolveServerTheme,
47
+ D as useBsTheme,
48
+ V as writeThemeCookie
49
+ };
@@ -0,0 +1,22 @@
1
+ import { MpThemeToggle, BsThemeToggleMode } from '@mintplayer/web-components/theming';
2
+ import * as React from 'react';
3
+ export interface BsThemeToggleProps extends React.HTMLAttributes<MpThemeToggle> {
4
+ /**
5
+ * The modes the toggle cycles through, in order. Defaults to
6
+ * `BS_THEME_DEFAULT_MODES` (auto, light, dark). Assigned to the element as a
7
+ * JS property: an array cannot travel as an attribute.
8
+ */
9
+ modes?: readonly BsThemeToggleMode[];
10
+ }
11
+ /**
12
+ * React wrapper for `<mp-theme-toggle>`, the colour-mode toggle button.
13
+ * Side-effect-registers the WC on import.
14
+ *
15
+ * The toggle talks to the shared theme store itself, so it needs no props to
16
+ * work; read or drive the same state from code with `useBsTheme()`. Any other
17
+ * prop (`aria-label`, `id`, `className`, ...) is forwarded to the element.
18
+ *
19
+ * <BsThemeToggle />
20
+ * <BsThemeToggle modes={[...BS_THEME_DEFAULT_MODES, sepia]} />
21
+ */
22
+ export declare const BsThemeToggle: React.ForwardRefExoticComponent<BsThemeToggleProps & React.RefAttributes<MpThemeToggle>>;
@@ -0,0 +1,3 @@
1
+ export { useBsTheme, type UseBsThemeResult } from './useBsTheme';
2
+ export { BsThemeToggle, type BsThemeToggleProps } from './BsThemeToggle';
3
+ export { BS_THEME_COOKIE_NAME, BS_THEME_DEFAULT_MODE_META, BS_THEME_DEFAULT_MODES, configureBsTheme, getBsThemeStore, injectThemeAttribute, isValidThemeMode, readDefaultModeMeta, readThemeCookie, resolveMode, resolveServerTheme, writeThemeCookie, type BsEffectiveThemeMode, type BsThemeConfig, type BsThemeMode, type BsThemeStore, type BsThemeToggleMode, type ResolveServerThemeOptions, type WriteThemeCookieOptions, } from '@mintplayer/web-components/theming';
@@ -0,0 +1,19 @@
1
+ import { BsEffectiveThemeMode, BsThemeMode } from '@mintplayer/web-components/theming';
2
+ export interface UseBsThemeResult {
3
+ /** The mode the user picked: `auto`, `light`, `dark` or a custom mode. */
4
+ mode: BsThemeMode;
5
+ /** The mode applied to `<html data-bs-theme>`: `auto` resolved against the OS preference. */
6
+ effectiveMode: BsEffectiveThemeMode;
7
+ /** Set, persist and apply a mode. An invalid mode is a no-op with a warning; a no-op on the server. */
8
+ setMode: (mode: BsThemeMode) => void;
9
+ }
10
+ /**
11
+ * The document's colour mode, backed by the shared browser store
12
+ * (`@mintplayer/web-components/theming`). Re-renders when the mode changes
13
+ * from anywhere: this hook, a `<BsThemeToggle>`, another framework's adapter
14
+ * on the same page, another tab, or the OS preference while in `auto`.
15
+ *
16
+ * SSR-safe: on the server the store is never touched and the hook returns
17
+ * the server snapshot documented on `SERVER_SNAPSHOT`.
18
+ */
19
+ export declare function useBsTheme(): UseBsThemeResult;