# Treelab Revogrid

Grid component written using [Stencil](https://stenciljs.com/) for [Treelab Client](https://github.com/treelab/treelab-client). While highly customized, original code was branched from the open source [Revogrid](https://github.com/revolist/revogrid) library.

## Structure

All of the components are located in [src](src) folder.

## Development

### Setup

1. `git clone <this repo>`
1. `yarn install`
1. `yarn serve`

### Linking to this package directly from `treelab-client`

First build this project

1. `cd ..../treelab-revogrid`
1. `yarn build`

Then link into `treelab-client`

1. `cd ..../treelab-revogrid`
1. `yarn link`
1. `cd ..../treelab-client`
1. `yarn link @treelab/revogrid`

Restart `treelab-client` in order for the linked package to be properly included in the build.

## Testing

Currently we don't do any automated/unit testing.

## Publishing

All published versions can be found on [npmjs.com](https://www.npmjs.com/package/@treelab/revogrid)

Latest code can be built and published as an npm package using the [Create new release and publish to npm](https://github.com/treelab/treelab-revogrid/actions/workflows/npm-publish.yml) GitHub action. Please carefully choose a [semantic version](https://docs.npmjs.com/about-semantic-versioning) when executing `Run workflow` such that it is higher than the previous version published.

## i18n

- Add locale info in `src/locales/[lang].json`
- usage
  - import i18nState, such as `import { i18nState } from '../../locales/i18n.store';`
  - `i18nState.i18nStore.Intl?.formatMessage({ id: 'can.not.add.row.reminder' })`
- customize locale data
  - optionally pass the locale data with the `customizedMessage` property of `revogrid` to overwrite defaults
  - the customize localed data that must have the ids inclueded in default `src/locales/[lang].json` like something below,
  ```javascript
  const customizedMessage = {
    zh: { 'can.not.add.row.reminder': '同步表暂不支持添加行' },
    en: { 'can.not.add.row.reminder': 'Can not add row in sync table temporarily' },
  };
  ```
