@timeax/form-palette 0.1.2 → 0.1.4

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/dist/extra.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import { O as ListerDefinition, Q as ListerRuntimeState, U as ListerProviderHost, W as PresetMap, X as ListerStoreState, Y as ListerSessionId, Z as ListerId, _ as ListerSearchMode, $ as ListerSearchTarget, a0 as ListerSearchPayload, a1 as ListerFilterCtx, a2 as ListerFilterOption, a3 as ListerMode, a4 as ListerApi, a5 as ShadcnJsonEditorProps, a6 as JsonEditorIndexHandle } from './variant-BGkGWsSy.mjs';
4
- export { ab as ListerChangeEvent, av as ListerDetails, al as ListerFilterApply, ak as ListerFilterApplyMode, am as ListerFilterBindKey, ao as ListerFilterGroupOption, an as ListerFilterInput, aq as ListerFilterInputOption, ar as ListerFilterSpec, ap as ListerFilterValueOption, ad as ListerLogCode, ae as ListerLogEntry, ac as ListerLogLevel, ah as ListerMapping, aw as ListerOpenOptions, a7 as ListerOpenReason, ax as ListerOpenResult, ag as ListerOption, au as ListerOptionsForMode, af as ListerPermissionCtx, at as ListerRawForMode, aj as ListerSearchSpec, aC as ListerSessionState, ai as ListerSource, as as ListerValueForMode, aa as OpenAnchor, aA as PresetFilters, aB as PresetMeta, ay as PresetRaw, az as PresetValue, a9 as Resolver, a8 as Selector } from './variant-BGkGWsSy.mjs';
3
+ import { Q as ListerSearchPayload, U as ListerId, W as ListerDefinition, X as ListerOption, Y as PresetMap, Z as ListerApi, _ as ListerStoreState, $ as ListerSessionId, a0 as ListerSearchTarget, a1 as ListerSearchMode, a2 as ListerFilterCtx, a3 as ListerDetails, a4 as ListerProviderHost, a5 as ListerRuntimeState, a6 as ShadcnJsonEditorProps, a7 as JsonEditorIndexHandle } from './core-EVtvQ-ma.mjs';
4
+ export { ad as ListerChangeEvent, am as ListerFilterApply, al as ListerFilterApplyMode, an as ListerFilterBindKey, ap as ListerFilterGroupOption, ao as ListerFilterInput, ar as ListerFilterInputOption, as as ListerFilterOption, at as ListerFilterSpec, aq as ListerFilterValueOption, af as ListerLogCode, ag as ListerLogEntry, ae as ListerLogLevel, ai as ListerMapping, a8 as ListerMode, ax as ListerOpenOptions, a9 as ListerOpenReason, ay as ListerOpenResult, aw as ListerOptionsForMode, ah as ListerPermissionCtx, av as ListerRawForMode, ak as ListerSearchSpec, aD as ListerSessionState, aj as ListerSource, au as ListerValueForMode, ac as OpenAnchor, aB as PresetFilters, aC as PresetMeta, az as PresetRaw, aA as PresetValue, ab as Resolver, aa as Selector } from './core-EVtvQ-ma.mjs';
5
5
  import 'zod';
6
6
  import './adapter-CvjXO9Gi.mjs';
7
7
  import '@inertiajs/core';
@@ -11,189 +11,155 @@ import 'class-variance-authority/types';
11
11
  import 'class-variance-authority';
12
12
  import '@radix-ui/react-switch';
13
13
 
14
+ type HttpMethod = "GET" | "POST";
14
15
  type HttpReq = {
15
16
  endpoint: string;
16
- method: "GET" | "POST";
17
+ method?: HttpMethod;
17
18
  params?: any;
18
19
  body?: any;
19
- headers?: any;
20
+ headers?: Record<string, string>;
21
+ signal?: AbortSignal;
22
+ requestId?: string;
20
23
  };
21
24
  type ListerHttpClient = (req: HttpReq) => Promise<any>;
22
25
 
23
- type AnyDef = ListerDefinition<any, any, any, any>;
24
- /**
25
- * IMPORTANT:
26
- * Your types file may not yet include these runtime-only fields (searchSpec/searchTarget).
27
- * Without widening here, TS2353 will fire when we create session objects containing them.
28
- *
29
- * This keeps compilation green while you finish syncing the types.
30
- */
31
- type AnyState = ListerRuntimeState<any, any, any, any, any> & {
32
- searchSpec?: any;
33
- searchTarget?: any;
34
- searchPayload?: any;
35
- ownerKey?: string;
26
+ type ListerFetchOpts<TCtx = any> = {
27
+ query?: string;
28
+ search?: ListerSearchPayload;
29
+ cursor?: string | null;
30
+ /** request control */
31
+ signal?: AbortSignal;
32
+ requestId?: string;
33
+ /** mapping context override */
34
+ ctx?: TCtx;
36
35
  };
37
- type InternalContextValue = {
38
- host: ListerProviderHost;
36
+ declare function fetchListerList<TRaw, TValue extends ListerId, TFilters, TMeta, TCtx>(args: {
37
+ def: ListerDefinition<TRaw, TValue, TFilters, TMeta, TCtx>;
39
38
  http: ListerHttpClient;
40
- presetsRef: React.RefObject<PresetMap>;
41
- store: ListerStoreState;
42
- apiFetchAny: (kindOrDef: string | AnyDef, filters?: any, opts?: any) => Promise<any>;
43
- apiOpenAny: (kindOrDef: string | AnyDef, filters?: any, opts?: any) => Promise<any>;
44
- focus(id: ListerSessionId): void;
45
- dispose(id: ListerSessionId): void;
46
- apply(id: ListerSessionId): void;
47
- cancel(id: ListerSessionId): void;
48
- close(id: ListerSessionId): void;
49
- toggle(id: ListerSessionId, value: ListerId): void;
50
- select(id: ListerSessionId, value: ListerId): void;
51
- deselect(id: ListerSessionId, value: ListerId): void;
52
- clear(id: ListerSessionId): void;
53
- setQuery(id: ListerSessionId, q: string): void;
54
- setSearchMode(id: ListerSessionId, mode: ListerSearchMode): void;
55
- /**
56
- * Persist the user's current search target (subject/all/only)
57
- * so all searches (local/remote/hybrid) can include it.
58
- */
59
- setSearchTarget(id: ListerSessionId, target: ListerSearchTarget): void;
60
- /**
61
- * Backwards compatible signatures:
62
- * - existing calls still work: searchRemote(id, q)
63
- * - new calls can optionally override payload: searchRemote(id, q, payload)
64
- *
65
- * If payload is omitted, implementation should read from session.searchTarget.
66
- */
67
- searchLocal: {
68
- (id: ListerSessionId, q: string): void;
69
- (id: ListerSessionId, q: string, payload?: ListerSearchPayload): void;
70
- };
71
- searchRemote: {
72
- (id: ListerSessionId, q: string): void;
73
- (id: ListerSessionId, q: string, payload?: ListerSearchPayload): void;
74
- };
75
- refresh(id: ListerSessionId): void;
76
- setPosition(id: ListerSessionId, pos: {
77
- x: number;
78
- y: number;
79
- } | null): void;
80
- /** Filters (non-UI logic; per session) */
81
- getFilterCtx<TFilters>(id: ListerSessionId): ListerFilterCtx<TFilters>;
82
- /**
83
- * NEW semantics:
84
- * - `optionId` is the UI identifier of the filter option (NOT the db value)
85
- * - `selectedFilterValues` tracks selected option ids (for UI checkmarks/badge)
86
- */
87
- applyFilterOption(id: ListerSessionId, optionId: string | number): void;
88
- registerPreset(kind: string, def: AnyDef): void;
89
- getPreset(kind: string): AnyDef | undefined;
90
- /** Derived list for UI later (local/hybrid filtering) */
91
- getVisibleOptions(id: ListerSessionId): any[];
92
- };
93
- declare const Ctx: React.Context<InternalContextValue | null>;
94
- type ResolvedFilterNode<TFilters> = {
95
- option: ListerFilterOption<TFilters>;
96
- id: string;
97
- kind?: string;
98
- disabled?: boolean;
99
- bindKey?: string;
100
- dbValue?: any;
101
- apply?: {
102
- key?: string;
103
- mode?: "replace" | "merge" | "unset";
104
- toggleable?: boolean;
105
- value?: any;
106
- };
39
+ filters?: TFilters;
40
+ opts?: ListerFetchOpts<TCtx>;
41
+ }): Promise<{
42
+ rawList: TRaw[];
43
+ optionsList: Array<ListerOption<TRaw, TValue, TMeta>>;
44
+ responseBody: any;
45
+ requestId?: string;
46
+ }>;
47
+
48
+ type ListerEngine = {
49
+ http: ListerHttpClient;
50
+ fetch: <TRaw, TValue extends ListerId, TFilters, TMeta, TCtx>(args: {
51
+ def: ListerDefinition<TRaw, TValue, TFilters, TMeta, TCtx>;
52
+ filters?: TFilters;
53
+ opts?: ListerFetchOpts<TCtx> & {
54
+ search?: ListerSearchPayload;
55
+ };
56
+ }) => ReturnType<typeof fetchListerList<TRaw, TValue, TFilters, TMeta, TCtx>>;
107
57
  };
108
- declare function buildSearchPayloadFromTarget(target?: ListerSearchTarget | null): ListerSearchPayload | undefined;
109
- declare function ListerProvider(props: {
58
+
59
+ type CreateListerRuntimeOptions<P extends PresetMap> = {
110
60
  host: ListerProviderHost;
111
- presets?: PresetMap;
112
- http?: ListerHttpClient;
113
- /** provider-side debounce for remote search (default 300ms) */
61
+ /** Provide your own engine (for tests / custom http). */
62
+ engine?: ListerEngine;
63
+ /** Initial preset map (kind => definition). */
64
+ presets?: P;
65
+ /** Debounce used when searchMode is remote/hybrid and query changes. */
114
66
  remoteDebounceMs?: number;
115
- children: React.ReactNode;
116
- }): react_jsx_runtime.JSX.Element;
67
+ now?: () => number;
68
+ makeSessionId?: () => string;
69
+ };
70
+ type ListerRuntime<P extends PresetMap> = {
71
+ engine: ListerEngine;
72
+ api: ListerApi<P>;
73
+ getState(): ListerStoreState;
74
+ subscribe(fn: () => void): () => void;
75
+ actions: {
76
+ focus(sessionId: ListerSessionId): void;
77
+ close(sessionId: ListerSessionId): void;
78
+ cancel(sessionId: ListerSessionId): void;
79
+ apply(sessionId: ListerSessionId): void;
80
+ clear(sessionId: ListerSessionId): void;
81
+ toggle(sessionId: ListerSessionId, value: any): void;
82
+ select(sessionId: ListerSessionId, value: any): void;
83
+ deselect(sessionId: ListerSessionId, value: any): void;
84
+ setQuery(sessionId: ListerSessionId, query: string): void;
85
+ setSearchTarget(sessionId: ListerSessionId, target?: ListerSearchTarget): void;
86
+ setSearchMode(sessionId: ListerSessionId, mode: ListerSearchMode): void;
87
+ setFiltersPatch(sessionId: ListerSessionId, patch: any): void;
88
+ mergeFiltersPatch(sessionId: ListerSessionId, patch: any): void;
89
+ getFilterCtx<TFilters>(id: ListerSessionId): ListerFilterCtx<TFilters>;
90
+ applyFilterOption(id: ListerSessionId, optionId: string | number): void;
91
+ refresh(sessionId: ListerSessionId): void;
92
+ };
93
+ selectors: {
94
+ effectiveFilters(sessionId: ListerSessionId): any;
95
+ visibleOptions(sessionId: ListerSessionId): any[];
96
+ detailsPayload(sessionId: ListerSessionId, action: ListerDetails<any, any, any, any>["action"]): any;
97
+ };
98
+ };
117
99
 
118
100
  /**
119
- * Search bar + trailing controls:
120
- * - Search target (all/subject/only) popover (leading control)
121
- * - Search mode toggle (remote/local/hybrid)
122
- * - Filters UI (custom popover button)
101
+ * Context for Lister runtime bridge.
102
+ */
103
+ declare const ListerContext: React.Context<ListerRuntime<any> | null>;
104
+ type ListerProviderProps<P extends PresetMap> = React.PropsWithChildren<CreateListerRuntimeOptions<P>>;
105
+ /**
106
+ * ListerProvider — creates a singleton runtime and exposes it via React context.
123
107
  *
124
- * Notes:
125
- * - Search mode is bound to session.searchMode via actions.setSearchMode(id, mode)
126
- * - Search target is bound to session.searchTarget via actions.setSearchTarget(id, target)
127
- * - Filters live in session.filtersSpec?.options and session.selectedFilterValues
108
+ * Responsibilities:
109
+ * - instantiate `createListerRuntime` once per provider
110
+ * - subscribe to runtime store (if needed by descendants)
111
+ * - expose `api`, `actions`, `selectors`, and `state`
128
112
  */
129
- declare function SearchBar(props: {
130
- id: ListerSessionId;
131
- store: ListerStoreState;
132
- }): react_jsx_runtime.JSX.Element;
133
-
134
- declare function ListerUI(): react_jsx_runtime.JSX.Element | null;
135
- declare function HeaderBar(props: {
136
- id: ListerSessionId;
137
- title: string;
138
- loading: boolean;
139
- refreshing: boolean;
140
- showRefresh: boolean;
141
- draggable: boolean;
142
- onRefresh(): void;
143
- onClose(): void;
144
- }): react_jsx_runtime.JSX.Element;
113
+ declare function ListerProvider<P extends PresetMap>({ children, ...opts }: ListerProviderProps<P>): react_jsx_runtime.JSX.Element;
114
+ /**
115
+ * Helper: get current runtime or throw
116
+ */
117
+ declare function useListerRuntime<P extends PresetMap>(): ListerRuntime<P>;
145
118
 
146
- declare function OptionList(props: {
147
- id: ListerSessionId;
148
- className?: string;
149
- }): react_jsx_runtime.JSX.Element;
150
- declare function FooterBar(props: {
151
- id: ListerSessionId;
152
- mode: ListerMode;
153
- confirm: boolean;
154
- onClear(): void;
155
- onCancel(): void;
156
- onApply(): void;
157
- }): react_jsx_runtime.JSX.Element;
119
+ declare function ListerUI(): React.ReactPortal | null;
158
120
 
121
+ /**
122
+ * useLister — stable hook returning { api, store/state, actions, selectors }.
123
+ *
124
+ * It directly mirrors the current runtime, with stable reference equality
125
+ * for top-level properties (api/actions/selectors), while `state` updates on
126
+ * store changes.
127
+ */
159
128
  declare function useLister<P extends PresetMap>(): {
160
129
  api: ListerApi<P>;
161
- store: ListerStoreState;
162
- /** active session convenience (can be undefined if none open) */
163
- state: AnyState | undefined;
164
130
  actions: {
165
- focus(id: ListerSessionId): void;
166
- dispose(id: ListerSessionId): void;
167
- apply(id: ListerSessionId): void;
168
- cancel(id: ListerSessionId): void;
169
- close(id: ListerSessionId): void;
170
- toggle(id: ListerSessionId, value: ListerId): void;
171
- select(id: ListerSessionId, value: ListerId): void;
172
- deselect(id: ListerSessionId, value: ListerId): void;
173
- clear(id: ListerSessionId): void;
174
- setQuery(id: ListerSessionId, q: string): void;
175
- setSearchMode(id: ListerSessionId, mode: ListerSearchMode): void;
176
- setSearchTarget(id: ListerSessionId, target: ListerSearchTarget): void;
177
- searchLocal: {
178
- (id: ListerSessionId, q: string): void;
179
- (id: ListerSessionId, q: string, payload?: ListerSearchPayload): void;
180
- };
181
- searchRemote: {
182
- (id: ListerSessionId, q: string): void;
183
- (id: ListerSessionId, q: string, payload?: ListerSearchPayload): void;
184
- };
185
- refresh(id: ListerSessionId): void;
186
- setPosition(id: ListerSessionId, pos: {
187
- x: number;
188
- y: number;
189
- } | null): void;
190
- /** Filters (non-UI logic) */
131
+ focus(sessionId: ListerSessionId): void;
132
+ close(sessionId: ListerSessionId): void;
133
+ cancel(sessionId: ListerSessionId): void;
134
+ apply(sessionId: ListerSessionId): void;
135
+ clear(sessionId: ListerSessionId): void;
136
+ toggle(sessionId: ListerSessionId, value: any): void;
137
+ select(sessionId: ListerSessionId, value: any): void;
138
+ deselect(sessionId: ListerSessionId, value: any): void;
139
+ setQuery(sessionId: ListerSessionId, query: string): void;
140
+ setSearchTarget(sessionId: ListerSessionId, target?: ListerSearchTarget): void;
141
+ setSearchMode(sessionId: ListerSessionId, mode: ListerSearchMode): void;
142
+ setFiltersPatch(sessionId: ListerSessionId, patch: any): void;
143
+ mergeFiltersPatch(sessionId: ListerSessionId, patch: any): void;
191
144
  getFilterCtx<TFilters>(id: ListerSessionId): ListerFilterCtx<TFilters>;
192
145
  applyFilterOption(id: ListerSessionId, optionId: string | number): void;
193
- registerPreset(kind: string, def: AnyDef): void;
194
- getPreset(kind: string): AnyDef | undefined;
195
- getVisibleOptions(id: ListerSessionId): any[];
146
+ refresh(sessionId: ListerSessionId): void;
147
+ };
148
+ selectors: {
149
+ effectiveFilters(sessionId: ListerSessionId): any;
150
+ visibleOptions(sessionId: ListerSessionId): any[];
151
+ detailsPayload(sessionId: ListerSessionId, action: ListerDetails<any, any, any, any>["action"]): any;
196
152
  };
153
+ state: ListerStoreState;
154
+ store: ListerStoreState;
155
+ };
156
+ /**
157
+ * useListerSession — convenience hook for one active session.
158
+ * Example: UI overlays or modals can call this to get the current session.
159
+ */
160
+ declare function useListerSession<P extends PresetMap>(sessionId?: ListerSessionId): {
161
+ session: ListerRuntimeState<any, any, any, any, any> | undefined;
162
+ activeId: string | undefined;
197
163
  };
198
164
 
199
165
  /**
@@ -239,7 +205,7 @@ type UseDataOptions<TItem = any, TFilters = Record<string, any>> = {
239
205
  method?: "GET" | "POST";
240
206
  selector?: DataSelector<TItem>;
241
207
  /**
242
- * Passed through into the inline def source.buildRequest (same signature as provider)
208
+ * Passed through into request builder (same signature shape as legacy provider)
243
209
  */
244
210
  buildRequest?: (ctx: DataBuildRequestCtx<TFilters>) => DataBuildRequestResult;
245
211
  /**
@@ -260,6 +226,10 @@ type UseDataOptions<TItem = any, TFilters = Record<string, any>> = {
260
226
  * Optional selection support (by stable item key)
261
227
  */
262
228
  selection?: DataSelectionConfig<TItem>;
229
+ /**
230
+ * Optional override: custom http client (otherwise uses global axios / axios import)
231
+ */
232
+ http?: ListerHttpClient;
263
233
  };
264
234
  type UseDataResult<TItem = any, TFilters = Record<string, any>> = {
265
235
  id?: string;
@@ -291,10 +261,11 @@ type UseDataResult<TItem = any, TFilters = Record<string, any>> = {
291
261
  query?: string;
292
262
  filters?: TFilters;
293
263
  searchTarget?: ListerSearchTarget;
264
+ search?: ListerSearchPayload;
294
265
  }) => Promise<TItem[]>;
295
266
  };
296
267
  declare function useData<TItem = any, TFilters = Record<string, any>>(opts: UseDataOptions<TItem, TFilters>): UseDataResult<TItem, TFilters>;
297
268
 
298
269
  declare const ShadcnJsonEditorVariant: React.ForwardRefExoticComponent<ShadcnJsonEditorProps & React.RefAttributes<JsonEditorIndexHandle>>;
299
270
 
300
- export { type AnyDef, type AnyState, Ctx, type DataBuildRequestCtx, type DataBuildRequestResult, type DataKey, type DataSearchConfig, type DataSelectionConfig, type DataSelectionKey, type DataSelectionMode, type DataSelector, FooterBar, HeaderBar, type InternalContextValue, ShadcnJsonEditorVariant as JsonEditor, ListerApi, ListerDefinition, ListerFilterCtx, ListerFilterOption, ListerId, ListerMode, ListerProvider, ListerProviderHost, ListerRuntimeState, ListerSearchMode, ListerSearchPayload, ListerSearchTarget, ListerSessionId, ListerStoreState, ListerUI, OptionList, PresetMap, type ResolvedFilterNode, SearchBar, type UseDataOptions, type UseDataResult, buildSearchPayloadFromTarget, useData, useLister };
271
+ export { type DataBuildRequestCtx, type DataBuildRequestResult, type DataKey, type DataSearchConfig, type DataSelectionConfig, type DataSelectionKey, type DataSelectionMode, type DataSelector, ShadcnJsonEditorVariant as JsonEditor, ListerApi, ListerContext, ListerDefinition, ListerDetails, ListerFilterCtx, ListerId, ListerOption, ListerProvider, ListerProviderHost, type ListerProviderProps, ListerRuntimeState, ListerSearchMode, ListerSearchPayload, ListerSearchTarget, ListerSessionId, ListerStoreState, ListerUI, PresetMap, type UseDataOptions, type UseDataResult, useData, useLister, useListerRuntime, useListerSession };