@jsb188/react 1.1.12 → 1.1.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jsb188
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -7,10 +7,23 @@ import {
7
7
  type PageFilterValues,
8
8
  type InferPageFilters,
9
9
  } from './page-filters.ts';
10
- import { useCallback, useEffect, useMemo, useRef } from 'react';
11
- import { useLocation, useNavigate, type Location } from 'react-router';
10
+ import { createContext, useContext, useCallback, useEffect, useMemo, useRef } from 'react';
11
+ import { useLocation, useNavigate } from 'react-router';
12
12
 
13
- const committedLocations = new WeakMap<Location, Location>();
13
+ interface PageLocation {
14
+ pathname: string;
15
+ search: string;
16
+ hash?: string;
17
+ }
18
+
19
+ export interface ControlledPageLocation extends PageLocation {
20
+ onSearchChange: (search: string) => void;
21
+ }
22
+
23
+ // Routes that treat their search string as one unit can reset it on an invalid filter.
24
+ export const ResetInvalidPageSearchContext = createContext(false);
25
+
26
+ const committedLocations = new WeakMap<PageLocation, PageLocation>();
14
27
 
15
28
  export interface PageFilterController {
16
29
  schema: PageFilterSchema;
@@ -28,8 +41,16 @@ export interface PageFilterController {
28
41
  /*
29
42
  * Own URL-derived filter state, atomic invalid-input redirects, and updates shared by a page's toolbar and query.
30
43
  */
31
- export function usePageFilters<S extends PageFilterSchema>(schema: S, ready = true, scope = '') {
32
- const location = useLocation();
44
+ export function usePageFilters<S extends PageFilterSchema>(
45
+ schema: S,
46
+ ready = true,
47
+ scope = '',
48
+ controlled?: ControlledPageLocation | null,
49
+ ) {
50
+ const resetInvalidSearch = useContext(ResetInvalidPageSearchContext);
51
+ const routerLocation = useLocation();
52
+ const location = controlled ?? routerLocation;
53
+ const onSearchChange = controlled?.onSearchChange;
33
54
  const navigate = useNavigate();
34
55
  const parsed = useMemo(
35
56
  () => parsePageFilters(schema, new URLSearchParams(location.search), scope),
@@ -38,6 +59,18 @@ export function usePageFilters<S extends PageFilterSchema>(schema: S, ready = tr
38
59
  const current = useRef({ schema, location, ready, scope });
39
60
  current.current = { schema, location, ready: ready && parsed.valid, scope };
40
61
 
62
+ /*
63
+ * Publish the latest location before another control can read it, then update its owner.
64
+ */
65
+ const commitLocation = useCallback(
66
+ (next: PageLocation, replace = false) => {
67
+ committedLocations.set(current.current.location, next);
68
+ if (onSearchChange) onSearchChange(next.search);
69
+ else navigate(next, { replace, preventScrollReset: true });
70
+ },
71
+ [navigate, onSearchChange],
72
+ );
73
+
41
74
  useEffect(() => {
42
75
  return () => {
43
76
  committedLocations.delete(location);
@@ -47,11 +80,10 @@ export function usePageFilters<S extends PageFilterSchema>(schema: S, ready = tr
47
80
  useEffect(() => {
48
81
  if (!ready || parsed.valid) return;
49
82
  const latest = committedLocations.get(location) ?? location;
50
- const search = clearPageFilterSearch(new URLSearchParams(latest.search), scope);
83
+ const search = resetInvalidSearch ? '' : clearPageFilterSearch(new URLSearchParams(latest.search), scope);
51
84
  const next = { ...latest, search: search ? `?${search}` : '' };
52
- committedLocations.set(location, next);
53
- navigate(next, { replace: true, preventScrollReset: true });
54
- }, [location.pathname, location.search, location.hash, navigate, parsed.valid, ready, scope]);
85
+ commitLocation(next, true);
86
+ }, [location.pathname, location.search, location.hash, commitLocation, parsed.valid, ready, resetInvalidSearch, scope]);
55
87
 
56
88
  /*
57
89
  * Merge one control's committed changes against the latest URL, never a stale render snapshot.
@@ -75,17 +107,6 @@ export function usePageFilters<S extends PageFilterSchema>(schema: S, ready = tr
75
107
  };
76
108
  }, []);
77
109
 
78
- /*
79
- * Retain consecutive changes across independently scoped controls before the router publishes its next render.
80
- */
81
- const commitLocation = useCallback(
82
- (next: Pick<typeof location, 'pathname' | 'search' | 'hash'>) => {
83
- committedLocations.set(current.current.location, { ...current.current.location, ...next });
84
- navigate(next, { preventScrollReset: true });
85
- },
86
- [navigate],
87
- );
88
-
89
110
  /*
90
111
  * Apply a filter patch with one navigation and preserve all unrelated search parameters.
91
112
  */
@@ -129,7 +150,7 @@ export function usePageFilters<S extends PageFilterSchema>(schema: S, ready = tr
129
150
  const getFilterTo = useCallback(
130
151
  (update: PageFilterValues) => {
131
152
  const next = getNextLocation(update);
132
- return `${next.pathname}${next.search}${next.hash}`;
153
+ return `${next.pathname}${next.search}${next.hash || ''}`;
133
154
  },
134
155
  [getNextLocation],
135
156
  );
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@jsb188/react",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Contains react (and DOM) related utils and hooks.",
5
- "license": "ISC",
5
+ "license": "MIT",
6
6
  "author": "jsb188",
7
7
  "type": "module",
8
8
  "exports": {
@@ -15,12 +15,23 @@
15
15
  "./types/PopOver.d": "./types/PopOver.d.ts"
16
16
  },
17
17
  "peerDependencies": {
18
- "@jsb188/app": "1.1.12",
18
+ "@jsb188/app": "1.1.13",
19
19
  "jotai": "^2.20.2",
20
20
  "react": "^19.3.0",
21
21
  "react-router": "^8.4.0"
22
22
  },
23
23
  "scripts": {
24
24
  "test": "echo \"Error: no test specified\" && exit 1"
25
- }
25
+ },
26
+ "files": [
27
+ "libs/**/*.{ts,tsx,css,svg}",
28
+ "states/**/*.{ts,tsx,css,svg}",
29
+ "types/**/*.{ts,tsx,css,svg}",
30
+ "utils/**/*.{ts,tsx,css,svg}",
31
+ "!**/*.test.*",
32
+ "!**/*.spec.*",
33
+ "!**/tests/**",
34
+ "!**/*.md",
35
+ "!**/.DS_Store"
36
+ ]
26
37
  }
@@ -44,6 +44,7 @@ export type AppContextData = {
44
44
  // Required for app
45
45
  init: 0 | 1 | 2; // 0 = not initialized,; 1 = loading; 2 = initialized
46
46
  authorization: string; // This is token
47
+ storageToken: string | null;
47
48
  networkError: boolean;
48
49
 
49
50
  // Authentication data
@@ -56,7 +57,6 @@ export type AppContextData = {
56
57
  activated: boolean;
57
58
  hasPassword: boolean;
58
59
  webVersion: string | null;
59
- alertUpdatesOnMount: boolean;
60
60
 
61
61
  // Preview theme overrides active theme
62
62
  systemLightMode: 'LIGHT' | 'DARK';
@@ -71,6 +71,7 @@ export type AppContextData = {
71
71
  export const DEFAULT_APP_CONTEXT = {
72
72
  init: 0,
73
73
  authorization: '',
74
+ storageToken: null,
74
75
  networkError: false,
75
76
 
76
77
  account: null,
@@ -85,7 +86,6 @@ export const DEFAULT_APP_CONTEXT = {
85
86
  activated: false,
86
87
  hasPassword: false,
87
88
  webVersion: null,
88
- alertUpdatesOnMount: false,
89
89
 
90
90
  systemLightMode: 'LIGHT',
91
91
  previewLightMode: null,
@@ -188,7 +188,7 @@ export function mergeAuthToDefaultValues(auth?: AuthenticationData | null, authT
188
188
  systemLightMode = 'DARK';
189
189
  }
190
190
 
191
- setAuthToken(auth.token);
191
+ setAuthToken(auth.token, auth.storageToken);
192
192
 
193
193
  const authSettings = {
194
194
  ...DEFAULT_APP_CONTEXT.settings,
@@ -201,12 +201,12 @@ export function mergeAuthToDefaultValues(auth?: AuthenticationData | null, authT
201
201
  ...DEFAULT_APP_CONTEXT,
202
202
  init: 1, // Always 1 because we're always using SSR for authentication
203
203
  authorization: auth.token,
204
+ storageToken: auth.storageToken || null,
204
205
  account: auth.account,
205
206
  primaryOrganizationId: auth.primaryOrganizationId || null,
206
207
  cacheAuthorizationEpoch: auth.cacheAuthorizationEpoch || null,
207
208
  settings: authSettings,
208
209
 
209
- alertUpdatesOnMount: auth.alertUpdatesOnMount,
210
210
  hasPassword: auth.hasPassword,
211
211
  webVersion: auth.webVersion,
212
212
 
@@ -252,10 +252,11 @@ export const appReducer = (state: AppContextData, action: AppContextAction) => {
252
252
  return state;
253
253
  }
254
254
 
255
- setAuthToken(authorization);
255
+ setAuthToken(authorization, data.storageToken);
256
256
  return {
257
257
  ...state,
258
258
  authorization,
259
+ storageToken: data.storageToken || null,
259
260
  };
260
261
  }
261
262
  case 'APP_GUEST': {
@@ -383,7 +384,7 @@ export const AppContext = createContext({
383
384
 
384
385
  export function useCurrentAccount() {
385
386
  const {
386
- appState: { init, activated, hasPassword, webVersion, alertUpdatesOnMount, account, settings, primaryOrganizationId },
387
+ appState: { init, activated, hasPassword, webVersion, account, settings, primaryOrganizationId },
387
388
  dispatchApp,
388
389
  } = useContext(AppContext);
389
390
  const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
@@ -400,7 +401,6 @@ export function useCurrentAccount() {
400
401
  activated,
401
402
  hasPassword,
402
403
  webVersion,
403
- alertUpdatesOnMount,
404
404
 
405
405
  // Computed
406
406
  isLoggedIn: !!account?.id,
package/states/index.ts CHANGED
@@ -5,5 +5,4 @@ export * from './keyDown';
5
5
  export * from './keyboardLayer';
6
6
  export * from './modal';
7
7
  export * from './popOver';
8
- export * from './reactiveEvents';
9
8
  export * from './uploads';
package/states/keyDown.ts CHANGED
@@ -22,7 +22,16 @@ export interface KeyDownObserverObj {
22
22
  type SetKeyDown = (data: Partial<Omit<KeyDownObserverObj, 'eventId' | 'priorities'>>) => void;
23
23
  type KeyboardScope = { scopeId: string; layer: KeyboardLayer };
24
24
 
25
+ /*
26
+ * Report a blocking screen layer to legacy native keyboard handlers.
27
+ */
28
+ function hasModalBlocker(layer: KeyboardLayer, layers: { modal: boolean; pageOverlay: boolean }) {
29
+ return layer === 'page' ? layers.pageOverlay || layers.modal : layer === 'pageOverlay' && layers.modal;
30
+ }
31
+
25
32
  const keyDownState = atom({ eventId: 0, generation: 0, metaKey: false, pressed: null as string | null, shiftKey: false });
33
+ // A persistent navigation surface can observe ownership without rerendering for every app keystroke.
34
+ const idleKeyDownState = atom(null);
26
35
  const keyDownScopesState = atom<KeyboardScope[]>([]);
27
36
  const keyDownPrioritiesState = atom((get) => {
28
37
  const layer = get(activeKeyboardLayerState);
@@ -94,19 +103,22 @@ export function useSetKeyDown() {
94
103
  * Observe events only within the active layer and its highest-priority component scope.
95
104
  * Blocker flags describe overlays above this component, allowing modal-local shortcuts to keep working.
96
105
  */
97
- export function useKeyDown(scopeId?: string) {
106
+ export function useKeyDown(scopeId?: string, listen = true) {
98
107
  const layer = useContext(KeyboardLayerContext);
99
108
  const activeLayer = useAtomValue(activeKeyboardLayerState);
100
109
  const layers = useAtomValue(keyboardLayerState);
101
- const value = useAtomValue(keyDownState);
110
+ const value = useAtomValue(listen ? keyDownState : idleKeyDownState);
102
111
  const priorities = useAtomValue(keyDownPrioritiesState);
103
112
  const store = useStore();
104
113
  const observedValue = useMemo<KeyDownObserverObj>(() => {
105
114
  const canObserve =
106
- layer === activeLayer && value.generation === layers.generation && (priorities.length ? priorities[0] === scopeId : !scopeId);
115
+ !!value &&
116
+ layer === activeLayer &&
117
+ value.generation === layers.generation &&
118
+ (priorities.length ? priorities[0] === scopeId : !scopeId);
107
119
  return {
108
120
  alert: layers.popup && layer !== 'popup',
109
- modal: layers.modal && layer === 'page',
121
+ modal: hasModalBlocker(layer, layers),
110
122
  eventId: canObserve ? value.eventId : 0,
111
123
  metaKey: canObserve && value.metaKey,
112
124
  pressed: canObserve ? value.pressed : null,
@@ -142,7 +154,7 @@ export function useKeyDownBlockers() {
142
154
  const layers = useAtomValue(keyboardLayerState);
143
155
  const priorities = useAtomValue(keyDownPrioritiesState);
144
156
  const alert = layers.popup && layer !== 'popup';
145
- const modal = layers.modal && layer === 'page';
157
+ const modal = hasModalBlocker(layer, layers);
146
158
  return useMemo<Pick<KeyDownObserverObj, 'alert' | 'modal' | 'priorities'>>(
147
159
  () => ({ alert, modal, priorities }),
148
160
  [alert, modal, priorities],
@@ -1,14 +1,15 @@
1
1
  import { atom, useAtomValue, useStore } from 'jotai';
2
2
  import { createContext, useCallback, useContext } from 'react';
3
3
 
4
- export type KeyboardLayer = 'page' | 'modal' | 'popup';
4
+ export type KeyboardLayer = 'page' | 'pageOverlay' | 'modal' | 'popup';
5
5
 
6
6
  // Modal renderers provide their layer; ordinary route components inherit page ownership.
7
7
  export const KeyboardLayerContext = createContext<KeyboardLayer>('page');
8
- export const keyboardLayerState = atom({ modal: false, popup: false, generation: 0 });
8
+ export const keyboardLayerState = atom({ pageOverlay: false, modal: false, popup: false, generation: 0 });
9
+ export const pageOverlayKeyboardOpenState = atom((get) => get(keyboardLayerState).pageOverlay);
9
10
  export const activeKeyboardLayerState = atom<KeyboardLayer>((get) => {
10
11
  const state = get(keyboardLayerState);
11
- return state.popup ? 'popup' : state.modal ? 'modal' : 'page';
12
+ return state.popup ? 'popup' : state.modal ? 'modal' : state.pageOverlay ? 'pageOverlay' : 'page';
12
13
  });
13
14
 
14
15
  /*
package/states/modal.ts CHANGED
@@ -279,6 +279,17 @@ class ModalPopUp extends ModalScreen {
279
279
  const screenClass = new ModalScreen('screen');
280
280
  const popUpClass = new ModalPopUp('popup', POPUP_DEFAULT_VALUES);
281
281
 
282
+ // Remount the modal renderer to discard a screen already playing its exit animation.
283
+ export const modalScreenHostKeyState = atom(0);
284
+
285
+ /*
286
+ * Dismiss the current screen immediately, including an exit animation retained in its renderer.
287
+ */
288
+ export const resetModalScreenState = atom(null, (get, set) => {
289
+ set(screenClass.state, null);
290
+ set(modalScreenHostKeyState, get(modalScreenHostKeyState) + 1);
291
+ });
292
+
282
293
  /*
283
294
  * Return the resolved preset of a pop up request (e.g. 'force_reload') without opening it.
284
295
  */
package/states/popOver.ts CHANGED
@@ -257,6 +257,7 @@ function createPopOverStateAtoms() {
257
257
  }
258
258
 
259
259
  const sharedPopOverState = createPopOverStateAtoms();
260
+ export const resetPopOverState = sharedPopOverState.resetState;
260
261
  const inactivePopOverState = atom(false);
261
262
 
262
263
  /*
@@ -348,8 +348,9 @@ export interface PODateRangeObj extends PODateItemBase {
348
348
 
349
349
  export interface POInputObj extends POItemBase {
350
350
  __type: 'INPUT';
351
+ inputClassName?: string;
351
352
  name: string;
352
- preset?: 'tiny';
353
+ preset?: 'tiny' | 'smaller';
353
354
  type?: 'text' | 'search' | 'email' | 'url' | 'tel' | 'password';
354
355
  label?: string;
355
356
  ariaLabel?: string;
@@ -466,11 +467,6 @@ export interface POLabelsAndValuesIface {
466
467
  variables: POLabelsAndValuesVariables;
467
468
  }
468
469
 
469
- export interface POReactiveEventsIface {
470
- name: 'PO_REACTIVE_EVENTS';
471
- variables: Record<string, never>;
472
- }
473
-
474
470
  export interface POContentIface {
475
471
  name: 'PO_CONTENT';
476
472
  variables: {
@@ -478,13 +474,7 @@ export interface POContentIface {
478
474
  };
479
475
  }
480
476
 
481
- export type PopOverIface =
482
- | POListIface
483
- | POCheckListIface
484
- | POImageIface
485
- | POLabelsAndValuesIface
486
- | POReactiveEventsIface
487
- | POContentIface;
477
+ export type PopOverIface = POListIface | POCheckListIface | POImageIface | POLabelsAndValuesIface | POContentIface;
488
478
  export type PopOverName = PopOverIface['name'];
489
479
  export type PopOverVariables = PopOverIface['variables'];
490
480
 
package/libs/README.md DELETED
@@ -1,75 +0,0 @@
1
- # Page filters
2
-
3
- The pure schema/codec and React Router hook are independent of toolbars, tables, GraphQL, and app context.
4
-
5
- ```ts
6
- import { definePageFilterSchema, parsePageFilters } from '@jsb188/react/libs/page-filters';
7
- import { usePageFilters } from '@jsb188/react/libs/use-page-filters';
8
-
9
- const schema = definePageFilterSchema({
10
- filter: {
11
- status: { type: 'array', items: { type: 'string', values: ['ACTIVE', 'CLOSED'] } },
12
- archived: { type: 'boolean', default: false },
13
- minimumThreshold: { type: 'number', alias: 'mr', integer: true, min: 0 },
14
- startDate: { type: 'date' },
15
- query: { type: 'string' },
16
- },
17
- sort: { values: ['CREATED_AT_DESC', 'UPDATED_AT_DESC'], default: 'CREATED_AT_DESC' },
18
- });
19
-
20
- // Also works in a loader, server, CLI, or other non-React consumer.
21
- const parsed = parsePageFilters(schema, new URL(request.url).searchParams);
22
-
23
- /*
24
- * Drive a query and any custom controls from one committed URL snapshot.
25
- */
26
- const Page = () => {
27
- const state = usePageFilters(schema);
28
- const query = useYourQuery({ filter: state.filter, sort: state.sort }, { skip: !state.ready });
29
- // state.setFilter({ minimumThreshold: 123 });
30
- // state.setFilter({ status: ['ACTIVE'], archived: true });
31
- // state.setFilter({ startDate: undefined }); // reset one field to its default
32
- // state.setSort('UPDATED_AT_DESC');
33
- // state.reset(); // remove filter and sort; retain page and unrelated params
34
- return renderYourContent(query, state);
35
- };
36
- ```
37
-
38
- ## URL contract
39
-
40
- `?page=campaigns&filter=status,ACTIVE,CLOSED|archived,true|mr,123&sort=UPDATED_AT_DESC`
41
-
42
- - `filter` and `sort` are reserved. A filter group starts with its field name, followed by comma-separated values. Pipes separate groups.
43
- - Aliases are URL-only. `mr,123` produces `minimumThreshold: 123`; the full name is not accepted in the URL when an alias is configured. Controls and query adapters always use canonical field names.
44
- - Scalars accept one value. Booleans are exactly `true` or `false`; numbers must be finite; dates are real calendar dates in `YYYY-MM-DD` form. Strings can declare `values` and/or a `pattern`; numbers can declare `values`, `integer`, `min`, and `max`; dates can declare `min` and `max`.
45
- - Arrays use the `items` schema, and have set semantics: duplicates are removed and values are sorted deterministically. `status` represents an explicit empty array; `query,""` represents an empty string.
46
- - Values containing commas, pipes, quotes, backslashes, or whitespace are JSON-quoted **within the readable grammar**. For example, `filter=query,"north,south|west"` is one string, not extra filters. The serializer handles quoting and URL encoding; callers should not concatenate URL values by hand.
47
- - Default values are omitted when writing URLs and restored when reading. `undefined` resets a field to its declared default. A schema-level `validate(filter)` can reject invalid combinations such as reversed date ranges; its defaults must also be valid.
48
- - Unknown fields, invalid values, duplicate groups/reserved parameters, malformed grammar, and invalid sorts invalidate **both** parameters. `parsePageFilters` returns `valid: false` with defaults, never partial input. Pure callers decide how to redirect; the hook replaces the URL with both reserved parameters removed while retaining pathname, unrelated params, and hash.
49
- - Consumers must use `state.ready` to gate queries. Invalid input is never ready before the replacement URL renders. For dynamic choices, pass `usePageFilters(schema, optionsLoaded)` so incoming IDs are not discarded while options load. Handle option-loading errors/retries in the page's data layer.
50
- - Changes create browser history entries; invalid-URL corrections replace history. Browser Back/Forward immediately restores committed state. `queryKey` identifies normalized filter/sort values, independent of unrelated URL parameters.
51
- - Independent sections can pass a third argument: `usePageFilters(templateSchema, optionsLoaded, 'templates')` owns `templates.filter` and `templates.sort`. The default controller continues to own `filter` and `sort`. Each section validates and resets only its own pair, and consecutive changes from different sections preserve each other before the router renders. The pure parse/clear helpers accept a trailing scope argument; the update helper accepts it after `sort`.
52
-
53
- ## Optional toolbar adapter
54
-
55
- `@jsb188/react-web/modules/ToolbarFilters` exports `makePageToolbarFilters(controller, definitions)` and `PageToolbarFilter<typeof schema>`. Presentation definitions choose controls and labels; selectable values come directly from the schema so validation, selections, and query values agree.
56
-
57
- ```ts
58
- const controls = [
59
- { control: 'checklist', field: 'status', label: i18n.t('c.status') },
60
- { control: 'toggle', field: 'archived', label: i18n.t('campaign.status_archived') },
61
- { control: 'date', field: 'startDate', label: i18n.t('c.start') },
62
- { control: 'sort', label: i18n.t('c.sort_by') },
63
- ] satisfies PageToolbarFilter<typeof schema>[];
64
- const options = makePageToolbarFilters(state, controls);
65
- ```
66
-
67
- Built-in controls are `toggle`, `select`, `checklist`, `date`, `dateRange`, and `sort`. A date range maps two schema fields in a single update. Share schema field definitions and presentation definitions by importing them across pages. `ToolbarItems` also accepts typed actions, links, or `{ type: 'custom', id, content }` for arbitrary React controls, including free-text and numeric inputs using `state.setFilter`.
68
-
69
- ## Table-route integration
70
-
71
- Marketday's `TableRoute.filters.ts` contains page-specific schemas, reusable log/campaign/date configurations, asynchronous option sources, and API mappings. `FilteredTableRoute`, `StandardTableRoute`, and `TableRoute` apply this controller automatically. A page that owns a custom toolbar can pass its existing `pageFilterState` into `TableRoute` so it parses only once. The embedded template-campaign page shares the same campaign schema and adapter.
72
-
73
- Fixed scopes such as organization, template ID, campaign kind, or a route-specific activity group stay outside editable URL fields. Initial queries and pagination use the same mapped filter/sort values. The recent-weeks log preset defaults on only when no explicit dates/location/search are present; incompatible explicit combinations are invalid.
74
-
75
- Existing toolbar/table consumers use this contract throughout. Legacy standalone filter parameters and numeric sort indexes are no longer interpreted; unrelated search parameters remain untouched.
@@ -1,99 +0,0 @@
1
- import type {
2
- ReactiveMessageObj,
3
- WSDataUpdateObj,
4
- } from '@jsb188/app/types/app.d.ts';
5
- import { atom, useAtomValue, useSetAtom } from 'jotai';
6
-
7
- /**
8
- * Types; reactive events
9
- */
10
-
11
- export type ReactiveEventObj = ReactiveMessageObj & {
12
- id: string;
13
- seen?: boolean;
14
- timestamp: number;
15
- };
16
-
17
- type ReactiveEventInput = Pick<WSDataUpdateObj, 'id' | 'messages'> & {
18
- timestamp?: number;
19
- };
20
-
21
- /*
22
- * Expand one websocket update's messages into independently rendered history rows.
23
- */
24
- function makeReactiveEventRows(
25
- reactiveEvent: ReactiveEventInput,
26
- ): ReactiveEventObj[] {
27
- const timestamp = reactiveEvent.timestamp ?? Date.now();
28
-
29
- return (reactiveEvent.messages || []).map((message, index) => ({
30
- ...message,
31
- id: `${reactiveEvent.id}:${timestamp}:${index}`,
32
- timestamp,
33
- }));
34
- }
35
-
36
- /**
37
- * Reactive event state
38
- */
39
-
40
- const reactiveEventState = atom<ReactiveEventObj[]>([]);
41
- const hasUnseenReactiveEventState = atom((get) =>
42
- get(reactiveEventState).some((reactiveEvent) => !reactiveEvent.seen),
43
- );
44
- const setReactiveEventState = atom(
45
- null,
46
- (_get, set, reactiveEvent: ReactiveEventInput) => {
47
- const savedReactiveEvents = makeReactiveEventRows(reactiveEvent);
48
- if (!savedReactiveEvents.length) {
49
- return;
50
- }
51
-
52
- set(reactiveEventState, (reactiveEvents) =>
53
- [...savedReactiveEvents, ...reactiveEvents].slice(0, 50),
54
- );
55
- },
56
- );
57
- const markReactiveEventsSeenState = atom(null, (get, set) => {
58
- const reactiveEvents = get(reactiveEventState);
59
- if (reactiveEvents.some((reactiveEvent) => !reactiveEvent.seen)) {
60
- set(
61
- reactiveEventState,
62
- reactiveEvents.map((reactiveEvent) =>
63
- reactiveEvent.seen ? reactiveEvent : { ...reactiveEvent, seen: true },
64
- ),
65
- );
66
- }
67
- });
68
-
69
- /**
70
- * Return all reactive events from newest to oldest.
71
- */
72
-
73
- export function useReactiveEvents() {
74
- return useAtomValue(reactiveEventState);
75
- }
76
-
77
- /**
78
- * Return whether the capped event history contains an unseen event.
79
- */
80
-
81
- export function useHasUnseenReactiveEvent() {
82
- return useAtomValue(hasUnseenReactiveEventState);
83
- }
84
-
85
- /**
86
- * Return the setter that marks the current event history as seen.
87
- */
88
-
89
- export function useMarkReactiveEventsSeen() {
90
- return useSetAtom(markReactiveEventsSeenState);
91
- }
92
-
93
- /**
94
- * Return the setter that prepends one reactive event to the capped history.
95
- */
96
-
97
- export function useSetReactiveEvent() {
98
- return useSetAtom(setReactiveEventState);
99
- }