@bfrs/agentic-components 0.6.4 → 0.6.6
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/BFRS_AGENTIC_COMPONENTS.md +56 -12
- package/README.md +13 -0
- package/dist/components/data-display/DataTable/DataTable.types.d.ts +1 -1
- package/dist/components/data-display/DataTable/TableViewSelector.d.ts +44 -0
- package/dist/components/data-display/DataTable/index.d.ts +2 -0
- package/dist/components/data-display/DataTable/saveViewApi.d.ts +22 -10
- package/dist/components/data-display/DataTable/viewStore.d.ts +55 -0
- package/dist/custom-elements.d.ts +7 -0
- package/dist/custom-elements.js +9998 -9113
- package/dist/custom-elements.js.map +1 -1
- package/dist/index.js +6368 -5552
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +9 -6
- package/scripts/lint/cli.cjs +894 -0
- package/scripts/postinstall.cjs +79 -2
|
@@ -14,6 +14,19 @@ Install from the public npm registry:
|
|
|
14
14
|
npm install @bfrs/agentic-components
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
During install, the package copies this file into the consuming project, updates `AGENTS.md` and `CLAUDE.md` with a reference to it, and wires the shared BFRS lint guard into `package.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"scripts": {
|
|
22
|
+
"check:bfrs-agentic-lint": "bfrs-agentic-lint all",
|
|
23
|
+
"build": "bfrs-agentic-lint all && ..."
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The guard is shipped by the package as the `bfrs-agentic-lint` binary. It fails builds when app code bypasses the component library, uses raw color tokens, defines local components with library names, or overrides library styling through raw tag selectors, `:has()`, `.bfrs-*` / Emotion / Radix internals, structural attributes, library token declarations, or `!important`. Set `BFRS_AGENTIC_COMPONENTS_SKIP_SETUP=1` during install to skip automatic docs and lint script setup.
|
|
29
|
+
|
|
17
30
|
## Setup
|
|
18
31
|
|
|
19
32
|
Import the stylesheet once at your app entry point:
|
|
@@ -58,7 +71,10 @@ import {
|
|
|
58
71
|
DataTable,
|
|
59
72
|
TableColumnVisibility,
|
|
60
73
|
TableSaveView,
|
|
74
|
+
TableViewSelector,
|
|
61
75
|
TableToolbar,
|
|
76
|
+
createLocalSaveView,
|
|
77
|
+
createLocalViewStore,
|
|
62
78
|
DateRangePicker,
|
|
63
79
|
ToastProvider,
|
|
64
80
|
useToast
|
|
@@ -145,7 +161,7 @@ Registered tags cover the documented component surface, including
|
|
|
145
161
|
`bfrs-button-group`, `bfrs-toast-provider`, `bfrs-table-toolbar`,
|
|
146
162
|
`bfrs-table-empty-state`, `bfrs-table-error-state`, `bfrs-table-skeleton`,
|
|
147
163
|
`bfrs-table-row-actions`, `bfrs-table-bulk-actions`,
|
|
148
|
-
`bfrs-table-column-visibility`,
|
|
164
|
+
`bfrs-table-column-visibility`, `bfrs-table-save-view`, and `bfrs-table-view-selector` in addition to the existing component tags.
|
|
149
165
|
Primitive table building blocks `bfrs-table`, `bfrs-thead`, `bfrs-tbody`, `bfrs-tfoot`,
|
|
150
166
|
`bfrs-tr`, `bfrs-th`, and `bfrs-td` are also registered for custom layouts where `bfrs-data-table`
|
|
151
167
|
is too prescriptive.
|
|
@@ -506,7 +522,7 @@ Standalone label. Prefer `FormField` which renders this automatically.
|
|
|
506
522
|
Standard text input.
|
|
507
523
|
|
|
508
524
|
Inputs use the same 28px Figma trigger height as select controls across native input types such as `text`, `number`, `email`, and `search`. Placeholders render in secondary text (`#64737E`).
|
|
509
|
-
|
|
525
|
+
Text-entry input boxes, affixed input chrome, and select-family triggers use a single active border without an additional focus outline/ring. Open select popovers keep that same visual state through `aria-expanded`.
|
|
510
526
|
|
|
511
527
|
```tsx
|
|
512
528
|
<Input
|
|
@@ -560,7 +576,7 @@ Accepts all native `<textarea>` props.
|
|
|
560
576
|
Single-value dropdown. Options are `{ value: string; label: string }`.
|
|
561
577
|
|
|
562
578
|
The Figma trigger style is the only select size: 28px high with 12.5px text, 7px radius, and a 10px chevron.
|
|
563
|
-
The trigger chevron rotates 180deg while open. This open/close motion and focused/open border treatment is shared by `Select`, `SearchableSelect`, and `MultiSelect`.
|
|
579
|
+
The trigger chevron rotates 180deg while open. This open/close motion and focused/open single-border treatment is shared by `Select`, `SearchableSelect`, and `MultiSelect`.
|
|
564
580
|
Selected option rows render with bold text across select-style listboxes: `Select`, `SearchableSelect`, `MultiSelect`, and `SuggestInput`.
|
|
565
581
|
|
|
566
582
|
```tsx
|
|
@@ -1722,20 +1738,48 @@ For pinned columns, declare `width` / `minWidth` for predictable layout. `DataTa
|
|
|
1722
1738
|
|
|
1723
1739
|
When `loading` is true, `DataTable` renders built-in table-row skeleton placeholders rather than a spinner. The consumer app only owns the loading boolean.
|
|
1724
1740
|
|
|
1725
|
-
Use `
|
|
1741
|
+
Use `TableViewSelector` with `TableSaveView` when a list page needs named saved views. Put the selector in the `ListPageLayout` filter band beside the filters, not inside `TableToolbar`. The selector uses a free-form `screenName`, reads/writes the matching local view store, selects the primary view by default, and stays hidden until that screen has at least one saved view. `TableSaveView` opens the "Save this view" modal and submits an API-shaped `SaveViewPayload` with `{ view_type, name, columns, filters, priority }`.
|
|
1742
|
+
|
|
1743
|
+
```tsx
|
|
1744
|
+
const screenName = "orders.list";
|
|
1745
|
+
const saveCurrentView = createLocalSaveView(screenName);
|
|
1746
|
+
|
|
1747
|
+
<ListPageLayout
|
|
1748
|
+
title="Orders"
|
|
1749
|
+
filters={
|
|
1750
|
+
<>
|
|
1751
|
+
<TableViewSelector
|
|
1752
|
+
screenName={screenName}
|
|
1753
|
+
onValueChange={(_, view) => {
|
|
1754
|
+
if (!view) return;
|
|
1755
|
+
setVisibleColumnIds(view.columns.filter((column) => column.visible).map((column) => column.key));
|
|
1756
|
+
setFilters(view.filters ?? []);
|
|
1757
|
+
}}
|
|
1758
|
+
/>
|
|
1759
|
+
<Select size="sm" value={status} onValueChange={setStatus} options={statusOptions} />
|
|
1760
|
+
<TableSaveView
|
|
1761
|
+
viewType={screenName}
|
|
1762
|
+
columns={visibilityColumns}
|
|
1763
|
+
visibleColumnIds={visibleColumnIds}
|
|
1764
|
+
filters={filters}
|
|
1765
|
+
filtersCount={filters.length}
|
|
1766
|
+
onSave={saveCurrentView}
|
|
1767
|
+
/>
|
|
1768
|
+
</>
|
|
1769
|
+
}
|
|
1770
|
+
table={<DataTable data={orders} columns={columns} visibleColumnIds={visibleColumnIds} />}
|
|
1771
|
+
/>
|
|
1772
|
+
```
|
|
1773
|
+
|
|
1774
|
+
Use `createLocalViewStore(screenName, { saveApi })` instead of `createLocalSaveView(screenName)` when save should call the library API adapter first and then mirror the saved view in localStorage. The selector's rename/delete/primary actions remain local unless you pass a custom `ViewStore`.
|
|
1775
|
+
|
|
1776
|
+
Column visibility still belongs in `TableToolbar`; keep that table-local save/discard flow separate from saved-view listing controls.
|
|
1726
1777
|
|
|
1727
1778
|
```tsx
|
|
1728
1779
|
<TableToolbar
|
|
1729
1780
|
title="Orders"
|
|
1730
1781
|
actions={
|
|
1731
1782
|
<div className="bfrs-flex bfrs-items-center bfrs-gap-2">
|
|
1732
|
-
{dirty && (
|
|
1733
|
-
<TableSaveView
|
|
1734
|
-
columns={visibilityColumns}
|
|
1735
|
-
visibleColumnIds={visibleColumnIds}
|
|
1736
|
-
onSave={({ visibleColumnIds: nextSavedIds }) => setSavedColumnIds(nextSavedIds)}
|
|
1737
|
-
/>
|
|
1738
|
-
)}
|
|
1739
1783
|
<TableColumnVisibility
|
|
1740
1784
|
columns={visibilityColumns}
|
|
1741
1785
|
visibleColumnIds={visibleColumnIds}
|
|
@@ -1747,7 +1791,7 @@ Use `TableSaveView` with `TableColumnVisibility` when the user changes columns o
|
|
|
1747
1791
|
/>
|
|
1748
1792
|
```
|
|
1749
1793
|
|
|
1750
|
-
Angular custom-element consumers can use `<bfrs-table-save-view>`
|
|
1794
|
+
Angular custom-element consumers can use `<bfrs-table-view-selector>` and `<bfrs-table-save-view>` with the same `screen-name`. The selector emits `value-change`, `view-select`, `primary-view-change`, `rename-view`, `delete-view`, and `reset-saved-filters`; `bfrs-table-save-view` emits `saved-view` after a successful save.
|
|
1751
1795
|
|
|
1752
1796
|
Custom-element DataTable action cells must be declarative because Angular/HTML cannot pass React `cell` functions through JSON. Use `cellType: "button"` for one inline button, `cellType: "buttons"` for multiple inline buttons, or `cellType: "actions"` for an action menu. Action clicks emit `cell-action` with `{ actionId, columnId, row, rowId, rowIndex }` and do not trigger `row-click`.
|
|
1753
1797
|
|
package/README.md
CHANGED
|
@@ -20,6 +20,19 @@ During install, the package writes `BFRS_AGENTIC_COMPONENTS.md` into the consumi
|
|
|
20
20
|
Use BFRS_AGENTIC_COMPONENTS.md for knowledge regarding the component library.
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
The same install hook also wires the shared BFRS lint guard into the consumer package:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"scripts": {
|
|
28
|
+
"check:bfrs-agentic-lint": "bfrs-agentic-lint all",
|
|
29
|
+
"build": "bfrs-agentic-lint all && ..."
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The guard fails builds when app code bypasses the component library, uses raw color tokens, defines local components with library names, or overrides library styling through raw tag selectors, `:has()`, `.bfrs-*` / Emotion / Radix internals, structural attributes, library token declarations, or `!important`. Set `BFRS_AGENTIC_COMPONENTS_SKIP_SETUP=1` during install to skip automatic docs and lint script setup.
|
|
35
|
+
|
|
23
36
|
## React Usage
|
|
24
37
|
|
|
25
38
|
```tsx
|
|
@@ -169,7 +169,7 @@ export type TableBulkActionsProps = {
|
|
|
169
169
|
label?: ReactNode;
|
|
170
170
|
className?: string;
|
|
171
171
|
};
|
|
172
|
-
export type ViewType =
|
|
172
|
+
export type ViewType = string;
|
|
173
173
|
export type ViewColumn = {
|
|
174
174
|
key: string;
|
|
175
175
|
order: number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SavedView } from './DataTable.types';
|
|
3
|
+
import { ViewStore } from './viewStore';
|
|
4
|
+
export type TableViewSelectorProps = {
|
|
5
|
+
/** Free-form screen key used for localStorage scoping, e.g. "orders_new". */
|
|
6
|
+
screenName: string;
|
|
7
|
+
/** Optional store adapter. Defaults to localStorage via createLocalViewStore(screenName). */
|
|
8
|
+
store?: ViewStore;
|
|
9
|
+
/** Controlled selected view id. Selection is separate from the persisted primary view. */
|
|
10
|
+
value?: string | null;
|
|
11
|
+
/** Initial selected view id for uncontrolled mode. Falls back to the store's primary view. */
|
|
12
|
+
defaultValue?: string | null;
|
|
13
|
+
/** Select and emit the screen's primary view when no selected value is present. Defaults to true. */
|
|
14
|
+
selectPrimaryByDefault?: boolean;
|
|
15
|
+
onValueChange?: (viewId: string | null, view: SavedView | null) => void;
|
|
16
|
+
onViewSelect?: (view: SavedView) => void;
|
|
17
|
+
onPrimaryViewChange?: (view: SavedView) => void;
|
|
18
|
+
onRenameView?: (view: SavedView) => void;
|
|
19
|
+
onDeleteView?: (viewId: string) => void;
|
|
20
|
+
onResetSavedFilters?: () => void;
|
|
21
|
+
onError?: (error: unknown) => void;
|
|
22
|
+
triggerLabel?: ReactNode;
|
|
23
|
+
placeholder?: ReactNode;
|
|
24
|
+
viewsLabel?: ReactNode;
|
|
25
|
+
emptyLabel?: ReactNode;
|
|
26
|
+
loadingLabel?: ReactNode;
|
|
27
|
+
resetLabel?: ReactNode;
|
|
28
|
+
setPrimaryLabel?: ReactNode;
|
|
29
|
+
renameLabel?: ReactNode;
|
|
30
|
+
deleteLabel?: ReactNode;
|
|
31
|
+
renameTitle?: ReactNode;
|
|
32
|
+
renameDescription?: ReactNode;
|
|
33
|
+
renameInputLabel?: ReactNode;
|
|
34
|
+
renameCancelLabel?: ReactNode;
|
|
35
|
+
renameSaveLabel?: ReactNode;
|
|
36
|
+
/** Trigger size. Matches select-family sizing: sm = 28px, md = 36px. */
|
|
37
|
+
size?: "sm" | "md";
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
className?: string;
|
|
40
|
+
triggerClassName?: string;
|
|
41
|
+
contentClassName?: string;
|
|
42
|
+
actionMenuClassName?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function TableViewSelector({ screenName, store, value, defaultValue, selectPrimaryByDefault, onValueChange, onViewSelect, onPrimaryViewChange, onRenameView, onDeleteView, onResetSavedFilters, onError, triggerLabel, placeholder, viewsLabel, emptyLabel, loadingLabel, resetLabel, setPrimaryLabel, renameLabel, deleteLabel, renameTitle, renameDescription, renameInputLabel, renameCancelLabel, renameSaveLabel, size, disabled, className, triggerClassName, contentClassName, actionMenuClassName }: TableViewSelectorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { SaveViewPayload, SaveViewResult } from './DataTable.types';
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export type SaveViewHeaderSource = Record<string, string | null | undefined> | (() => Record<string, string | null | undefined>);
|
|
3
|
+
export type SaveViewTokenSource = string | null | undefined | (() => string | null | undefined);
|
|
4
|
+
export type SaveViewApiConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Base URL of the API service. Both host roots and `/api/v1` roots are
|
|
7
|
+
* supported, e.g. `https://platform.shiprocket.in` or
|
|
8
|
+
* `https://platform.shiprocket.in/api/v1/`.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** Endpoint path. Defaults to `api/v1/saveview` and de-dupes `/api/v1`. */
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/** Auth token or lazy token reader. Defaults to common Shiprocket localStorage keys. */
|
|
14
|
+
token?: SaveViewTokenSource;
|
|
15
|
+
/** Extra headers or lazy header reader. */
|
|
16
|
+
headers?: SaveViewHeaderSource;
|
|
17
|
+
credentials?: RequestCredentials;
|
|
18
|
+
fetcher?: typeof globalThis.fetch;
|
|
19
|
+
};
|
|
20
|
+
export type SaveViewOptions = SaveViewApiConfig & {
|
|
6
21
|
payload: SaveViewPayload;
|
|
7
22
|
};
|
|
8
23
|
/**
|
|
@@ -11,16 +26,13 @@ export type SaveViewOptions = {
|
|
|
11
26
|
* Saves a user view. Returns the saved view and whether it was a duplicate.
|
|
12
27
|
* Throws on HTTP error (auth, validation, network).
|
|
13
28
|
*/
|
|
14
|
-
export declare function saveView({ baseUrl, token, payload }: SaveViewOptions): Promise<SaveViewResult>;
|
|
29
|
+
export declare function saveView({ baseUrl, endpoint, token, headers, credentials, fetcher, payload, }: SaveViewOptions): Promise<SaveViewResult>;
|
|
15
30
|
/**
|
|
16
31
|
* Creates a pre-configured save function bound to a base URL and token.
|
|
17
32
|
* The returned function matches the `TableSaveView.onSave` signature directly.
|
|
18
33
|
*
|
|
19
34
|
* @example
|
|
20
|
-
* const save = createSaveView({ baseUrl: import.meta.env.
|
|
35
|
+
* const save = createSaveView({ baseUrl: import.meta.env.VITE_AGENTIC_BASE_URL });
|
|
21
36
|
* <TableSaveView onSave={save} onSaved={...} />
|
|
22
37
|
*/
|
|
23
|
-
export declare function createSaveView(
|
|
24
|
-
baseUrl: string;
|
|
25
|
-
token: string;
|
|
26
|
-
}): (payload: SaveViewPayload) => Promise<SaveViewResult>;
|
|
38
|
+
export declare function createSaveView(config?: SaveViewApiConfig): (payload: SaveViewPayload) => Promise<SaveViewResult>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SavedView, SaveViewPayload, SaveViewResult } from './DataTable.types';
|
|
2
|
+
import { SaveViewApiConfig } from './saveViewApi';
|
|
3
|
+
/**
|
|
4
|
+
* A persistence backend for a single screen's saved views.
|
|
5
|
+
*
|
|
6
|
+
* Every method is async so an HTTP-backed adapter (e.g. `createApiViewStore`)
|
|
7
|
+
* can be swapped in later without touching a single call site — the localStorage
|
|
8
|
+
* adapter simply resolves synchronously. `TableViewSelector` depends only on this
|
|
9
|
+
* interface, never on `localStorage` directly.
|
|
10
|
+
*/
|
|
11
|
+
export interface ViewStore {
|
|
12
|
+
/** All saved views for the screen, in stored order. */
|
|
13
|
+
list(): Promise<SavedView[]>;
|
|
14
|
+
/** A single view by id, or `null` if it isn't stored. */
|
|
15
|
+
get(viewId: string): Promise<SavedView | null>;
|
|
16
|
+
/** The primary view (`is_default: true`) for the screen, or `null`. */
|
|
17
|
+
getActive(): Promise<SavedView | null>;
|
|
18
|
+
/** Upsert by name — mirrors `saveView`'s `{ view, alreadyExists }` shape. */
|
|
19
|
+
save(payload: SaveViewPayload): Promise<SaveViewResult>;
|
|
20
|
+
/** Change a view's name in place. Rejects if the id isn't found. */
|
|
21
|
+
rename(viewId: string, name: string): Promise<SavedView>;
|
|
22
|
+
/** Delete a view. Promotes a new primary if the deleted one was primary. */
|
|
23
|
+
remove(viewId: string): Promise<void>;
|
|
24
|
+
/** Mark a view primary (`is_default: true`), clearing it on all others. */
|
|
25
|
+
setPrimary(viewId: string): Promise<SavedView>;
|
|
26
|
+
/** Remove every saved view for the screen ("Reset saved filters"). */
|
|
27
|
+
reset(): Promise<void>;
|
|
28
|
+
/** Subscribe to same-tab and cross-tab changes; returns an unsubscribe fn. */
|
|
29
|
+
subscribe(listener: () => void): () => void;
|
|
30
|
+
}
|
|
31
|
+
export type RemoteSaveView = (payload: SaveViewPayload) => Promise<SaveViewResult | void>;
|
|
32
|
+
export type LocalViewStoreOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* Optional remote save adapter. When supplied, `save()` calls this first and
|
|
35
|
+
* only mirrors the view into localStorage after the remote save succeeds.
|
|
36
|
+
*/
|
|
37
|
+
remoteSave?: RemoteSaveView;
|
|
38
|
+
/** Convenience API config that uses the library `saveView()` implementation. */
|
|
39
|
+
saveApi?: SaveViewApiConfig;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Creates a localStorage-backed {@link ViewStore} scoped to `screenName`.
|
|
43
|
+
* Views for a screen live under `bfrs.savedViews.<screenName>`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createLocalViewStore(screenName: string, options?: LocalViewStoreOptions): ViewStore;
|
|
46
|
+
/**
|
|
47
|
+
* A pre-bound save function for a screen's local store, matching the
|
|
48
|
+
* `TableSaveView.onSave` signature — the localStorage counterpart of
|
|
49
|
+
* `createSaveView`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const onSave = createLocalSaveView("orders_new");
|
|
53
|
+
* <TableSaveView viewType="orders_new" onSave={onSave} />
|
|
54
|
+
*/
|
|
55
|
+
export declare function createLocalSaveView(screenName: string, options?: LocalViewStoreOptions): (payload: SaveViewPayload) => Promise<SaveViewResult>;
|
|
@@ -629,6 +629,12 @@ export declare class BfrsTableSaveViewElement extends OpenCustomElement {
|
|
|
629
629
|
protected defaultDisplay(): string;
|
|
630
630
|
protected renderElement(): unknown;
|
|
631
631
|
}
|
|
632
|
+
export declare class BfrsTableViewSelectorElement extends ReactCustomElement {
|
|
633
|
+
static readonly tagName = "table-view-selector";
|
|
634
|
+
static get observedAttributes(): string[];
|
|
635
|
+
protected defaultDisplay(): string;
|
|
636
|
+
protected renderElement(): unknown;
|
|
637
|
+
}
|
|
632
638
|
export declare class BfrsDataTableElement extends ReactCustomElement {
|
|
633
639
|
static readonly tagName = "data-table";
|
|
634
640
|
static get observedAttributes(): string[];
|
|
@@ -976,6 +982,7 @@ declare global {
|
|
|
976
982
|
"bfrs-table-bulk-actions": BfrsTableBulkActionsElement;
|
|
977
983
|
"bfrs-table-column-visibility": BfrsTableColumnVisibilityElement;
|
|
978
984
|
"bfrs-table-save-view": BfrsTableSaveViewElement;
|
|
985
|
+
"bfrs-table-view-selector": BfrsTableViewSelectorElement;
|
|
979
986
|
"bfrs-tabs": BfrsTabsElement;
|
|
980
987
|
"bfrs-tabs-list": BfrsTabsListElement;
|
|
981
988
|
"bfrs-tabs-trigger": BfrsTabsTriggerElement;
|