@henryx/onedot-ui 0.2.0 → 0.4.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/README.md CHANGED
@@ -29,8 +29,8 @@ Components use the `od-` CSS namespace. Theme variables can be overridden on
29
29
 
30
30
  ### Tables
31
31
 
32
- `OdTable` supports local rows, function-backed remote data, and URL-backed
33
- Schema/query data. The three source modes are mutually exclusive:
32
+ `OdTable` provides local tables and remote queries. The example below uses
33
+ the existing local mode:
34
34
 
35
35
  ```vue
36
36
  <script setup lang="ts">
@@ -47,9 +47,16 @@ const rows = [{ id: 1, name: 'Ada' }]
47
47
  </template>
48
48
  ```
49
49
 
50
- For remote data, provide `load-schema` and `load-data`, or `schema-url` and
51
- `query-url`. Remote responses must follow `OdTableSchema` and
52
- `OdTableResult<T>`, including a stable, unique row key for every item.
50
+ Remote tables default to frontend columns and one POST query endpoint
51
+ returning paginated data plus `meta.fields` for query capabilities and enum
52
+ options. Use `query-url` or `load-data`, with the same `columns` and `row-key`
53
+ props. When the server determines columns, use `schema-url + query-url` or
54
+ `load-schema + load-data`; omit frontend columns and row-key. Both column modes
55
+ are supported starting in 0.4.0 (0.3.0 uses frontend columns).
56
+ Both modes share query metadata. Field slots such as `#cell-name` match existing
57
+ columns by field and let the page render links or dialog
58
+ buttons. See the [OdTable guide](./用户使用手册/OdTable.md) for complete examples,
59
+ and the [capability list](./用户使用手册/能力清单.md) for implementation status.
53
60
 
54
61
  ## Development
55
62
 
@@ -60,6 +67,9 @@ corepack pnpm dev
60
67
  ```
61
68
 
62
69
  Storybook is served at `http://localhost:6006`.
70
+ For browsing without development compilation or file watching, run
71
+ `corepack pnpm build:storybook` then `corepack pnpm preview:storybook`.
72
+ See the [Storybook guide](./用户使用手册/Storybook.md) for preview and icon search usage.
63
73
 
64
74
  Open [Capabilities](http://localhost:6006/?path=/story/capabilities--all) for the
65
75
  complete catalog, existing Od stories and PrimeVue 4.5.5 (MIT) previews with Aura.
@@ -109,7 +119,7 @@ The full Tabler Vue catalog and raw SVG assets are shipped inside this package,
109
119
  so moving the component library to another application does not require a
110
120
  second icon dependency or a network request.
111
121
 
112
- The `0.2.0` release is prepared for npm publication. Maintainers should run
122
+ The current package version is `0.4.0`. Maintainers should run
113
123
  `corepack pnpm release:check` before publishing subsequent versions.
114
124
 
115
125
  ## License
@@ -1,4 +1,4 @@
1
- /** Public contracts and input validation shared by OdTable's implementation. */
1
+ import { VNodeChild } from 'vue';
2
2
  export type OdTableRowKey = string | number;
3
3
  export type OdTableDataType = 'text' | 'number' | 'datetime' | 'boolean' | 'enum';
4
4
  export type OdTableOption = {
@@ -27,6 +27,16 @@ export type OdTableColumn = {
27
27
  false: string;
28
28
  };
29
29
  };
30
+ export type OdTableCellContext<T extends object> = {
31
+ row: T;
32
+ rowKey: OdTableRowKey;
33
+ column: OdTableColumn;
34
+ value: unknown;
35
+ text: string;
36
+ };
37
+ export type OdTableSlots<T extends object> = {
38
+ [name: `cell-${string}`]: ((context: OdTableCellContext<T>) => VNodeChild) | undefined;
39
+ };
30
40
  export type OdTableSorting = {
31
41
  field: string;
32
42
  direction: 'asc' | 'desc';
@@ -47,32 +57,46 @@ export type OdTableQuery = {
47
57
  sorting: OdTableSorting[];
48
58
  };
49
59
  export type OdTableInitialQuery = Partial<OdTableQuery>;
60
+ export type OdTableFieldMeta = {
61
+ sortable?: boolean;
62
+ searchable?: boolean;
63
+ filterable?: boolean;
64
+ options?: OdTableOption[];
65
+ };
66
+ export type OdTableMeta = {
67
+ fields: Record<string, OdTableFieldMeta>;
68
+ };
50
69
  export type OdTableResult<T> = {
51
70
  items: T[];
52
71
  total: number;
53
72
  page: number;
54
73
  pageSize: number;
74
+ meta: OdTableMeta;
55
75
  };
56
76
  export type OdTablePaginationConfig = {
57
77
  defaultPageSize?: number;
58
78
  pageSizeOptions?: number[];
59
79
  };
80
+ /** Structure only: query capabilities and enum options belong to Result.meta. */
81
+ export type OdTableSchemaColumn = Omit<OdTableColumn, 'sortable' | 'searchable' | 'filterable' | 'options'>;
60
82
  export type OdTableSchema = {
61
83
  rowKey: string;
62
- columns: OdTableColumn[];
63
- defaultSorting?: OdTableSorting[];
64
- pagination?: {
65
- defaultPageSize: number;
66
- pageSizeOptions: number[];
67
- };
84
+ columns: OdTableSchemaColumn[];
68
85
  };
69
- export type OdTableRequest = (url: string, options: {
70
- method: 'GET' | 'POST';
86
+ export type OdTableLoadSchema = (context: {
87
+ signal: AbortSignal;
88
+ }) => Promise<OdTableSchema>;
89
+ export type OdTableRequestOptions = {
71
90
  headers?: Record<string, string>;
72
- body?: unknown;
73
91
  signal: AbortSignal;
74
- }) => Promise<unknown>;
75
- export type OdTableLoadSchema = () => Promise<OdTableSchema>;
92
+ } & ({
93
+ method: 'GET';
94
+ body?: never;
95
+ } | {
96
+ method: 'POST';
97
+ body: OdTableQuery;
98
+ });
99
+ export type OdTableRequest = (url: string, options: OdTableRequestOptions) => Promise<unknown>;
76
100
  export type OdTableLoadData<T> = (query: OdTableQuery, context: {
77
101
  signal: AbortSignal;
78
102
  }) => Promise<OdTableResult<T>>;
@@ -118,8 +142,8 @@ export type OdTableProps<T extends object> = {
118
142
  rowKey?: string;
119
143
  pagination?: OdTablePaginationConfig;
120
144
  loadSchema?: OdTableLoadSchema;
121
- loadData?: OdTableLoadData<T>;
122
145
  schemaUrl?: string;
146
+ loadData?: OdTableLoadData<T>;
123
147
  queryUrl?: string;
124
148
  request?: OdTableRequest;
125
149
  initialQuery?: OdTableInitialQuery;
@@ -134,6 +158,7 @@ export type OdTableProps<T extends object> = {
134
158
  };
135
159
  export type OdTableExpose = {
136
160
  refresh: () => Promise<void>;
161
+ refreshSchema: () => Promise<void>;
137
162
  };
138
163
  export type OdTableEvents<T> = {
139
164
  'selection-change': (keys: OdTableRowKey[], rows: T[]) => void;
@@ -144,17 +169,17 @@ export type OdTableEvents<T> = {
144
169
  field: string;
145
170
  width: number;
146
171
  }) => void;
147
- 'schema-error': (error: unknown) => void;
148
172
  'data-error': (payload: {
149
173
  error: unknown;
150
174
  query: OdTableQuery;
151
175
  }) => void;
176
+ 'schema-error': (error: unknown) => void;
152
177
  retry: (payload: {
153
178
  stage: 'schema' | 'data';
154
179
  }) => void;
155
180
  'config-error': (error: OdTableConfigError) => void;
156
181
  };
157
- export type OdTableConfigErrorCode = 'MODE_MISSING' | 'MODE_PARTIAL' | 'MODE_CONFLICT' | 'REQUEST_WITHOUT_URL_MODE' | 'REMOTE_PAGINATION' | 'INVALID_COLUMNS' | 'DUPLICATE_COLUMN_FIELD' | 'INVALID_COLUMN_FIELD' | 'INVALID_COLUMN_WIDTH' | 'INVALID_NUMBER_FORMAT' | 'SEARCHABLE_NON_TEXT' | 'FILTERABLE_NON_ENUM' | 'ENUM_OPTIONS_REQUIRED' | 'DUPLICATE_ENUM_OPTION' | 'INVALID_DEFAULT_SORTING' | 'INVALID_PAGINATION' | 'INVALID_ROW_KEY_FIELD' | 'MISSING_ROW_KEY' | 'DUPLICATE_ROW_KEY' | 'INVALID_INITIAL_QUERY' | 'INVALID_ROWS' | 'INVALID_RESULT' | 'RESULT_TOTAL_INVALID' | 'RESULT_PAGE_INVALID' | 'RESULT_PAGE_SIZE_INVALID' | 'RESULT_ITEMS_OVERFLOW' | 'RESULT_EMPTY_CONFLICT';
182
+ export type OdTableConfigErrorCode = 'MODE_MISSING' | 'MODE_PARTIAL' | 'MODE_CONFLICT' | 'REQUEST_WITHOUT_URL_MODE' | 'INVALID_COLUMNS' | 'INVALID_SCHEMA' | 'INVALID_ROW_KEY_FIELD' | 'DUPLICATE_COLUMN_FIELD' | 'INVALID_COLUMN_FIELD' | 'INVALID_COLUMN_WIDTH' | 'INVALID_NUMBER_FORMAT' | 'SEARCHABLE_NON_TEXT' | 'FILTERABLE_NON_ENUM' | 'ENUM_OPTIONS_REQUIRED' | 'DUPLICATE_ENUM_OPTION' | 'INVALID_PAGINATION' | 'MISSING_ROW_KEY' | 'DUPLICATE_ROW_KEY' | 'INVALID_INITIAL_QUERY' | 'INVALID_ROWS' | 'INVALID_RESULT' | 'RESULT_TOTAL_INVALID' | 'RESULT_PAGE_INVALID' | 'RESULT_PAGE_SIZE_INVALID' | 'RESULT_ITEMS_OVERFLOW' | 'RESULT_EMPTY_CONFLICT' | 'INVALID_META' | 'META_QUERY_CONFLICT';
158
183
  export declare class OdTableConfigError extends Error {
159
184
  readonly name = "OdTableConfigError";
160
185
  readonly code: OdTableConfigErrorCode;
@@ -162,17 +187,16 @@ export declare class OdTableConfigError extends Error {
162
187
  constructor(code: OdTableConfigErrorCode, message: string, details?: unknown);
163
188
  }
164
189
  export type OdTableSourceMode = 'local' | 'function' | 'url';
165
- type OdTableSourceInput<T extends object> = Pick<OdTableProps<T>, 'columns' | 'rows' | 'rowKey' | 'pagination' | 'loadSchema' | 'loadData' | 'schemaUrl' | 'queryUrl' | 'request'>;
166
- export declare function validateOdTableColumns(columns: unknown): OdTableColumn[];
190
+ type OdTableSourceInput<T extends object> = Partial<Pick<OdTableProps<T>, 'columns' | 'rows' | 'rowKey' | 'pagination' | 'loadSchema' | 'schemaUrl' | 'loadData' | 'queryUrl' | 'request'>>;
191
+ export declare function validateOdTableColumns(columns: unknown, remote?: boolean): OdTableColumn[];
167
192
  export declare function validateOdTablePagination(pagination: unknown): OdTablePaginationConfig;
168
- export declare function validateOdTableSchema(schema: unknown): OdTableSchema;
169
193
  export declare function validateOdTableInitialQuery(query: unknown): OdTableInitialQuery | undefined;
170
194
  /**
171
- * Checks query conditions against the capabilities advertised by a Schema.
195
+ * Checks query conditions against resolved column capabilities.
172
196
  * Keeping this validation next to the shape validator prevents local and
173
197
  * remote modes from silently accepting conditions the column contract forbids.
174
198
  */
175
- export declare function validateOdTableInitialQueryForColumns(query: OdTableInitialQuery | undefined, columns: readonly OdTableColumn[]): OdTableInitialQuery | undefined;
199
+ export declare function validateOdTableInitialQueryForColumns(query: OdTableInitialQuery | undefined, columns: readonly OdTableColumn[], pending?: boolean, code?: 'INVALID_INITIAL_QUERY' | 'META_QUERY_CONFLICT'): OdTableInitialQuery | undefined;
176
200
  export declare function validateOdTableRows<T extends object>(rows: unknown, rowKey: string): T[];
177
201
  export declare function validateOdTableSourceMode<T extends object>(input: OdTableSourceInput<T>): OdTableSourceMode;
178
202
  /**
@@ -181,4 +205,10 @@ export declare function validateOdTableSourceMode<T extends object>(input: OdTab
181
205
  * so callers can route them to `data-error` without string matching.
182
206
  */
183
207
  export declare function validateOdTableResult<T>(payload: unknown): OdTableResult<T>;
208
+ /** Restored from the 0.2 Schema contract, restricted to the current structural role. */
209
+ export declare function validateOdTableSchema(payload: unknown): OdTableSchema;
210
+ /** Copy only supported metadata so extra response properties cannot define UI. */
211
+ export declare function validateOdTableMeta(payload: unknown): OdTableMeta;
212
+ /** A null snapshot means the first response has not arrived: all query UI is closed. */
213
+ export declare function resolveOdTableRemoteColumns(columns: readonly OdTableColumn[], meta: OdTableMeta | null): OdTableColumn[];
184
214
  export {};
@@ -1,4 +1,4 @@
1
- import { OdTableConfigError, OdTableProps, OdTableQuery, OdTableRowKey } from './OdTable.types';
1
+ import { OdTableConfigError, OdTableProps, OdTableQuery, OdTableRowKey, OdTableSlots } from './OdTable.types';
2
2
  declare const _default: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
3
3
  props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
4
4
  readonly onRetry?: ((payload: {
@@ -12,27 +12,28 @@ declare const _default: <T extends object>(__VLS_props: NonNullable<Awaited<type
12
12
  field: string;
13
13
  width: number;
14
14
  }) => any) | undefined;
15
- readonly "onSchema-error"?: ((error: unknown) => any) | undefined;
16
15
  readonly "onData-error"?: ((payload: {
17
16
  error: unknown;
18
17
  query: OdTableQuery;
19
18
  }) => any) | undefined;
19
+ readonly "onSchema-error"?: ((error: unknown) => any) | undefined;
20
20
  readonly "onConfig-error"?: ((error: OdTableConfigError) => any) | undefined;
21
- } & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onRetry" | "onSelection-change" | "onUpdate:selected-row-keys" | "onQuery-change" | "onColumn-visibility-change" | "onColumn-width-change" | "onSchema-error" | "onData-error" | "onConfig-error"> & OdTableProps<T> & Partial<{}>> & import('vue').PublicProps;
21
+ } & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onRetry" | "onSelection-change" | "onUpdate:selected-row-keys" | "onQuery-change" | "onColumn-visibility-change" | "onColumn-width-change" | "onData-error" | "onSchema-error" | "onConfig-error"> & OdTableProps<T> & Partial<{}>> & import('vue').PublicProps;
22
22
  expose(exposed: import('vue').ShallowUnwrapRef<{
23
23
  refresh: () => Promise<void>;
24
+ refreshSchema: () => Promise<void>;
24
25
  }>): void;
25
26
  attrs: any;
26
- slots: {};
27
+ slots: Readonly<OdTableSlots<T>> & OdTableSlots<T>;
27
28
  emit: ((evt: "retry", payload: {
28
29
  stage: "schema" | "data";
29
30
  }) => void) & ((evt: "selection-change", keys: OdTableRowKey[], rows: T[]) => void) & ((evt: "update:selected-row-keys", keys: OdTableRowKey[]) => void) & ((evt: "query-change", query: OdTableQuery) => void) & ((evt: "column-visibility-change", visibility: Record<string, boolean>) => void) & ((evt: "column-width-change", payload: {
30
31
  field: string;
31
32
  width: number;
32
- }) => void) & ((evt: "schema-error", error: unknown) => void) & ((evt: "data-error", payload: {
33
+ }) => void) & ((evt: "data-error", payload: {
33
34
  error: unknown;
34
35
  query: OdTableQuery;
35
- }) => void) & ((evt: "config-error", error: OdTableConfigError) => void);
36
+ }) => void) & ((evt: "schema-error", error: unknown) => void) & ((evt: "config-error", error: OdTableConfigError) => void);
36
37
  }>) => import('vue').VNode & {
37
38
  __ctx?: Awaited<typeof __VLS_setup>;
38
39
  };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { default as OdTable } from './components/OdTable.vue';
5
5
  export { OdButton, OdIcon, OdTable };
6
6
  export { OdTableConfigError } from './components/OdTable.types';
7
7
  export type { OdButtonVariant, OdSize } from './components/OdButton.vue';
8
- export type { OdTableColumn, OdTableConfigErrorCode, OdTableDataType, OdTableEvents, OdTableExpose, OdTableFilter, OdTableInitialQuery, OdTableLocale, OdTableOption, OdTablePaginationConfig, OdTableProps, OdTableQuery, OdTableRequest, OdTableResult, OdTableRowKey, OdTableSchema, OdTableSearch, OdTableSorting, OdTableLoadData, OdTableLoadSchema, } from './components/OdTable.types';
8
+ export type { OdTableCellContext, OdTableColumn, OdTableConfigErrorCode, OdTableDataType, OdTableEvents, OdTableExpose, OdTableFilter, OdTableFieldMeta, OdTableInitialQuery, OdTableLocale, OdTableMeta, OdTableOption, OdTablePaginationConfig, OdTableProps, OdTableQuery, OdTableRequest, OdTableResult, OdTableRowKey, OdTableSearch, OdTableSorting, OdTableSlots, OdTableLoadData, OdTableSchemaColumn, OdTableSchema, OdTableLoadSchema, OdTableRequestOptions, } from './components/OdTable.types';
9
9
  export declare const OnedotUI: {
10
10
  install(app: App): void;
11
11
  };