Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
- allow to provide custom observable or computed search-box to `table-state`
- clean up release-build folder

Signed-off-by: Roman <[email protected]>
  • Loading branch information
ixrock committed May 11, 2023
1 parent 4b55070 commit d361c68
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
backup
dist
dev
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-react-table-grid",
"version": "1.0.5",
"version": "1.0.6",
"description": "Easy to use and powerful react table-grid layout based on CSS-grid",
"license": "MIT",
"author": "ixrock",
Expand All @@ -9,15 +9,15 @@
"build": "npm run build:clean && npm run build-lib && npm run build-types",
"build-lib": "NODE_ENV=production webpack --mode production",
"build-types": "tsc --project tsconfig-build-types.json",
"build:clean": "rimraf dist/",
"release-pack": "npm run build && npm pack dist/src/table",
"release-publish": "npm run build && npm publish dist/src/table"
"build:clean": "rimraf ./dist/",
"release-pack": "npm run build && npm pack ./dist",
"release-publish": "npm run build && npm publish ./dist"
},
"main": "index.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"files": [
"index.css",
"*.*(js|d.ts|.css|.json)"
"types",
"*.*"
],
"repository": {
"type": "git",
Expand Down
15 changes: 11 additions & 4 deletions src/table/table-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type React from "react";
import { action, computed, IComputedValue, observable } from "mobx"
import { action, computed, IComputedValue, IObservableValue, observable } from "mobx"
import type { TableColumnId, TableDataColumn, TableDataRow, TableRowId } from "./index";
import orderBy from "lodash/orderBy";

Expand All @@ -22,10 +22,17 @@ export interface CreateTableStateParams<ResourceItem = any> {
* By default, tries to get unique ID via `dataItem.getById()` or `dataItem.id`
*/
getRowId?: (dataItem: ResourceItem) => TableRowId;
/**
* Handle filtering results with search field
* mobx.computed() or mobx.observable.box() that participates in filtered rows state.
*/
searchBox?: IComputedValue<string> | IObservableValue<string>;
}

export function createTableState<DataItem = any>({ headingColumns, dataItems, customizeRows, getRowId }: CreateTableStateParams<DataItem>) {
let tableColumnsAll: TableDataColumn<DataItem>[] = headingColumns.map((headColumn) => {
export function createTableState<DataItem = any>(params: CreateTableStateParams<DataItem>) {
const { headingColumns, dataItems, customizeRows, getRowId, searchBox } = params;

const tableColumnsAll: TableDataColumn<DataItem>[] = headingColumns.map((headColumn) => {
return {
// copy heading columns definition
...headColumn,
Expand Down Expand Up @@ -65,7 +72,7 @@ export function createTableState<DataItem = any>({ headingColumns, dataItems, cu
}
});

const searchText = observable.box("");
const searchText = searchBox ?? observable.box("");
const hiddenColumns = observable.set<TableColumnId>();
const selectedRowsId = observable.set<TableRowId>();
const sortedColumns = observable.map<TableColumnId, "asc" | "desc">();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig-build-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"declarationDir": "dist/types"
},
"include": [
"types",
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist/",
"baseUrl": ".",
"jsx": "react",
"target": "ES2019",
"lib": ["ESNext", "DOM", "DOM.Iterable"],
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
devtool: "source-map",
externals: isDevelopment ? [] : externals, // exclude bundling with lib "react", "mobx", etc.
output: {
path: path.resolve(__dirname, 'dist/src/table'),
path: path.resolve(__dirname, isDevelopment ? "dev" : "dist"),
filename: '[name].js',
libraryTarget: "this",
library: {
Expand Down

0 comments on commit d361c68

Please sign in to comment.