Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-d committed Jun 26, 2023
1 parent 20afdfc commit d365353
Show file tree
Hide file tree
Showing 82 changed files with 24,748 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.json]
indent_size = 2

[*.{html,js,md}]
block_comment_start = /**
block_comment = *
block_comment_end = */
30 changes: 30 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches:
- main
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: release-please-action
# The logic below handles the npm publication:
- uses: actions/checkout@v2
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: npm ci
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
- run: npm run deploy
if: ${{ steps.release.outputs.release_created }}
23 changes: 23 additions & 0 deletions .github/workflows/test-on-pr-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test on PR branch
on: pull_request

jobs:
test-on-pr-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm ci

- name: Install playwright browsers
run: npx playwright install --with-deps

- name: Run tests
run: npm run-script test
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test
on: push

jobs:
unit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm ci

- name: Install playwright browsers
run: npx playwright install --with-deps

- name: Run unit tests
run: npm run-script test:unit
visual:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm ci

- name: Install playwright browsers
run: npx playwright install --with-deps

- name: Run visual test
run: npm run-script test:visual

- name: Update screenshots
if: failure()
run: npm run test:update

- name: Commit changes
if: failure()
uses: EndBug/add-and-commit@v9
with:
message: 'ci: update screenshots'
add: 'screenshots'
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## editors
/.idea
/.vscode

## system files
.DS_Store

## npm
/node_modules/
/npm-debug.log

## testing
/coverage/
/visual-coverage/

## temp folders
/.tmp/

# build
/_site/
/dist/
/out-tsc/

storybook-static
custom-elements.json

# unpacked demo data
tree.json
15 changes: 15 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const copy = require('rollup-plugin-copy');

module.exports = {
stories: ['../dist/**/*.book.{js,md,mdx}'],
rollupConfig(config) {
// add a new plugin to the build
config.plugins.push(copy({
targets: [
{ src: 'tree.json', dest: 'storybook-static' },
]
}));

return config;
},
};
1 change: 1 addition & 0 deletions .storybook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "commonjs" }
12 changes: 12 additions & 0 deletions .storybook/preview-body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script type="module">
async function loadTreeData() {
await new Promise(res => setTimeout(res, 2500));
const tree = await fetch('./tree.json').then(r => r.json());
const oscdTree = document.querySelector('oscd-tree-grid');
await oscdTree.updateComplete;

oscdTree.tree = tree;
}

document.body.onload = loadTreeData;
</script>
2 changes: 2 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300&family=Roboto:wght@300;400;500&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons&display=block">
8 changes: 8 additions & 0 deletions .storybook/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { storybookPlugin } from '@web/dev-server-storybook';
import baseConfig from '../web-dev-server.config.mjs';

export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
...baseConfig,
open: '/',
plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
});
2 changes: 2 additions & 0 deletions README.foot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

&copy; 2023 OMICRON electronics GmbH
49 changes: 49 additions & 0 deletions README.head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# \<oscd-tree-grid>

## Installation

```bash
npm i oscd-tree-grid
```

## Usage

```html
<script type="module">
import 'oscd-tree-grid';
</script>

<oscd-tree-grid filterLabel="Regular Expression"></oscd-tree-grid>

<script type="module">
const oscdTree = document.querySelector('oscd-tree-grid');
await oscdTree.updateComplete;
const tree = await fetch('/tree.json').then(r => r.json());
oscdTree.tree = tree;
</script>
```

## TypeScript types

For use with [TypeScript](https://www.typescriptlang.org/), `oscd-tree-grid`
exports the following types:

```ts
export type TreeSelection = { [name: string]: TreeSelection };

export type Path = string[];

export type TreeNode = {
children?: Tree;
text?: string;
mandatory?: boolean;
};

export type Tree = Partial<Record<string, TreeNode>>;
```

> This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc)
> recommendation.
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# \<oscd-tree-grid>

## Installation

```bash
npm i oscd-tree-grid
```

## Usage

```html
<script type="module">
import 'oscd-tree-grid';
</script>

<oscd-tree-grid filterLabel="Regular Expression"></oscd-tree-grid>

<script type="module">
const oscdTree = document.querySelector('oscd-tree-grid');
await oscdTree.updateComplete;
const tree = await fetch('/tree.json').then(r => r.json());
oscdTree.tree = tree;
</script>
```

## TypeScript types

For use with [TypeScript](https://www.typescriptlang.org/), `oscd-tree-grid`
exports the following types:

```ts
export type TreeSelection = { [name: string]: TreeSelection };

export type Path = string[];

export type TreeNode = {
children?: Tree;
text?: string;
mandatory?: boolean;
};

export type Tree = Partial<Record<string, TreeNode>>;
```

> This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc)
> recommendation.


## `oscd-tree-grid.ts`:

### class: `TreeGrid`

#### Superclass

| Name | Module | Package |
| ------------ | ------ | ------- |
| `LitElement` | | lit |

#### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ------------- | ------- | --------------- | ------- | ------------------------------------------ | -------------- |
| `tree` | | `Tree` | `{}` | The \`Tree\` to be selected from | |
| `selection` | | `TreeSelection` | `{}` | Selected rows as \`TreeSelection\` | |
| `paths` | | `Path[]` | | Selected rows as \`Path\[]\` | |
| `filter` | | `string` | | Regular expression by which to filter rows | |
| `filterLabel` | | `string` | `''` | Filter \`TextField\` label | |

<details><summary>Private API</summary>

#### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ------------- | ------- | ------------------------ | ------------------- | ----------- | -------------- |
| `depth` | private | `number` | | | |
| `filterUI` | private | `TextField \| undefined` | | | |
| `filterRegex` | private | `RegExp` | | | |
| `container` | private | `Element \| undefined` | | | |
| `collapsed` | private | | `new Set<string>()` | | |

#### Methods

| Name | Privacy | Description | Parameters | Return | Inherited From |
| ---------------------- | ------- | ----------- | ----------------------------------- | ---------------- | -------------- |
| `getPaths` | private | | `maxLength: number` | `Path[]` | |
| `treeNode` | private | | `path: Path` | `TreeNode` | |
| `rows` | private | | | `Path[]` | |
| `renderCell` | private | | `path: Path, previousPath: Path` | `TemplateResult` | |
| `select` | private | | `parentPath: Path, clicked: string` | `void` | |
| `selectAll` | private | | `clicked: ListItem` | `void` | |
| `handleSelected` | private | | `event: SingleSelectedEvent` | `Promise<void>` | |
| `scrollRight` | private | | | `Promise<void>` | |
| `renderColumn` | private | | `column: (Path \| undefined)[]` | `TemplateResult` | |
| `renderExpandCell` | private | | `path: Path` | `TemplateResult` | |
| `toggleCollapse` | private | | `serializedPath: string` | | |
| `renderExpandColumn` | private | | `rows: Path[]` | `TemplateResult` | |
| `renderCollapseColumn` | private | | `rows: Path[]` | `TemplateResult` | |
| `renderColumns` | private | | | `TemplateResult` | |
| `renderFilterField` | private | | | | |

</details>

<hr/>

### Exports

| Kind | Name | Declaration | Module | Package |
| ---- | ---------- | ----------- | ----------------- | ------- |
| `js` | `TreeGrid` | TreeGrid | oscd-tree-grid.ts | |



&copy; 2023 OMICRON electronics GmbH
13 changes: 13 additions & 0 deletions custom-elements-manifest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readmePlugin } from 'cem-plugin-readme';

export default {
globs: ['*.ts'],
exclude: ['**/*.spec.ts', '**/*.visual.ts', '**/*.book.ts'],
litelement: true,
plugins: [
readmePlugin({
header: 'README.head.md',
footer: 'README.foot.md',
}),
]
}
Loading

0 comments on commit d365353

Please sign in to comment.