Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tree component #1693

Merged
merged 99 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
d8bba4f
🖍
jpzwarte Apr 5, 2024
4cfe7bc
🏉
jpzwarte Apr 8, 2024
167784a
Merge branch 'main' into feature/tree
jpzwarte Apr 21, 2024
adb09c9
🌪
jpzwarte Apr 21, 2024
03ebf8d
🎠
jpzwarte Apr 21, 2024
326a6e4
💥
jpzwarte Apr 21, 2024
9981a70
👻
jpzwarte Apr 22, 2024
dc9b933
Merge branch 'main' into feature/tree
jpzwarte Apr 23, 2024
7e54c2a
🦄
jpzwarte Apr 25, 2024
961cb16
🎭
jpzwarte Apr 25, 2024
3bf10af
🌈
jpzwarte Apr 29, 2024
821e0d6
Merge branch 'main' into feature/tree
jpzwarte Apr 29, 2024
ef2801f
🎺
jpzwarte Apr 30, 2024
cc070d5
🐺
jpzwarte May 3, 2024
868c8a8
Merge branch 'main' into feature/tree
jpzwarte May 3, 2024
4864770
🐞
jpzwarte May 3, 2024
dc834d2
🕹
jpzwarte May 3, 2024
83150c6
🍌
jpzwarte May 4, 2024
47929bd
🍎
jpzwarte May 4, 2024
68ee0ed
🛰
jpzwarte May 4, 2024
9cb9d52
⚽️
jpzwarte May 4, 2024
ef52472
🐂
jpzwarte May 4, 2024
0050483
Merge branch 'main' into feature/tree
jpzwarte Jul 4, 2024
7b835d2
Merge branch 'main' into feature/tree
jpzwarte Dec 30, 2024
df1ccc3
🌳
jpzwarte Dec 30, 2024
2205a9c
jpzwarte Dec 30, 2024
132d4a5
💍
jpzwarte Dec 30, 2024
4c69f23
🌼
jpzwarte Dec 30, 2024
946bae5
💛
jpzwarte Dec 30, 2024
d55d268
🖍
jpzwarte Dec 30, 2024
a3bedb4
👒
jpzwarte Dec 30, 2024
b386388
🚂
jpzwarte Dec 30, 2024
c7381c7
jpzwarte Dec 30, 2024
9e937cd
🐬
jpzwarte Dec 30, 2024
22f2880
🌞
jpzwarte Dec 30, 2024
eaf8efb
🌞
jpzwarte Dec 31, 2024
348a96a
🍻
jpzwarte Dec 31, 2024
9780362
🎇
jpzwarte Dec 31, 2024
810f327
🚖
jpzwarte Dec 31, 2024
af4263f
🌍
jpzwarte Jan 1, 2025
e74add9
🍜
jpzwarte Jan 1, 2025
a49e2d9
🍡
jpzwarte Jan 1, 2025
b17f941
🐳
jpzwarte Jan 1, 2025
7ec8223
🎤
jpzwarte Jan 1, 2025
c18f68a
🎇
jpzwarte Jan 2, 2025
0a3a2fd
🏅
jpzwarte Jan 2, 2025
fa0019e
🤖
jpzwarte Jan 2, 2025
8a15b6e
🤘
jpzwarte Jan 2, 2025
27c1fb5
🚕
jpzwarte Jan 2, 2025
6ea36f1
⚡️
jpzwarte Jan 2, 2025
259287c
🏅
jpzwarte Jan 2, 2025
43ca966
🍕
jpzwarte Jan 2, 2025
8fa64fc
🌝
jpzwarte Jan 3, 2025
0f418e2
🍉
jpzwarte Jan 3, 2025
4500538
🌙
jpzwarte Jan 3, 2025
e13244d
🐮
jpzwarte Jan 3, 2025
4f0f5ad
🚂
jpzwarte Jan 3, 2025
c7fe11a
🐗
jpzwarte Jan 3, 2025
451570a
Merge branch 'main' into feature/tree
jpzwarte Jan 3, 2025
032d8fb
♨️
jpzwarte Jan 6, 2025
f572a87
♨️
jpzwarte Jan 6, 2025
e0ed777
🐡
jpzwarte Jan 6, 2025
831f3bb
🌁
jpzwarte Jan 7, 2025
fbe11fb
Merge branch 'main' into feature/tree
jpzwarte Jan 8, 2025
6b7ced5
🔥
jpzwarte Jan 8, 2025
63a813c
🎪
jpzwarte Jan 9, 2025
3d8a083
🐕
jpzwarte Jan 13, 2025
6e308e7
🚩
jpzwarte Jan 13, 2025
b93fb88
🍯
jpzwarte Jan 13, 2025
78ef1c3
🐯
jpzwarte Jan 13, 2025
f729fbb
🏰
jpzwarte Jan 13, 2025
7efcce5
🎙
jpzwarte Jan 13, 2025
993fc41
👾
jpzwarte Jan 13, 2025
4e07c9c
🐯
jpzwarte Jan 14, 2025
2eeba0a
😈
jpzwarte Jan 14, 2025
6a3d24a
🌃
jpzwarte Jan 15, 2025
885edb0
🦀
jpzwarte Jan 16, 2025
0b49865
🍺
jpzwarte Jan 16, 2025
9d1cf3a
Merge branch 'main' into feature/tree
jpzwarte Jan 16, 2025
8cab6ee
🎇
jpzwarte Jan 17, 2025
5afc06a
🐓
jpzwarte Jan 17, 2025
29ac666
🏙
jpzwarte Jan 17, 2025
683215b
🦃
jpzwarte Jan 17, 2025
7983df2
🐂
jpzwarte Jan 17, 2025
91b3b51
🍮
jpzwarte Jan 17, 2025
e818703
🎹
jpzwarte Jan 17, 2025
15aeb4a
🌴
jpzwarte Jan 17, 2025
4863ef4
⛄️
jpzwarte Jan 17, 2025
55e32b2
Merge branch 'main' into feature/tree
jpzwarte Jan 21, 2025
0cac49e
🍮
jpzwarte Jan 21, 2025
8919cda
💥
jpzwarte Jan 21, 2025
2ac986f
🎉
jpzwarte Jan 21, 2025
4b06527
😎
jpzwarte Jan 22, 2025
7f8bda6
🦄
jpzwarte Jan 22, 2025
4bf2810
🚨
jpzwarte Jan 22, 2025
fb90d63
Merge branch 'main' into feature/tree
jpzwarte Jan 30, 2025
0eb27ac
🐩
jpzwarte Jan 30, 2025
fcfce24
🔥
jpzwarte Jan 30, 2025
e145cf9
🌅
jpzwarte Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/curvy-jeans-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sl-design-system/checkbox': patch
---

Various fixes:
- Fix bug where clicking a checkbox in a tree-node will not check it
- Fix `sl-change` event firing multiple times for a single click
8 changes: 8 additions & 0 deletions .changeset/mean-kids-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sl-design-system/eslint-config': patch
---

Bump typescript-eslint version to fix false positive

Updating to the latest version fixes a false positive error that
was being thrown related to the `RovingTabindexController` having an `any` type.
5 changes: 5 additions & 0 deletions .changeset/real-bugs-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sl-design-system/grid': patch
---

Fix incorrect type import using absolute path
9 changes: 9 additions & 0 deletions .changeset/shy-wombats-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@sl-design-system/shared': minor
---

Add new `focusToElement` method to `FocusGroupController`

This allows you to focus on a specific element within a focus group. This is
useful when you want to focus on a specific element within a focus group, but still
maintain the roving tabindex behavior.
12 changes: 12 additions & 0 deletions .changeset/tender-ways-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@sl-design-system/data-source': patch
'@sl-design-system/grid': patch
'@sl-design-system/paginator': patch
---

Refactor existing data sources into list specific datasources, clearing
the way to add `TreeDataSource` in the `@sl-design-system/tree` package.

- The base `DataSource` class has support for sorting and filtering
- Grouping and pagination has been moved to the `ListDataSource` class
- `ArrayDataSource` and `FetchDataSource` have been renamed to `ArrayListDataSource` and `FetchListDataSource` respectively
7 changes: 7 additions & 0 deletions .changeset/yellow-islands-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sl-design-system/tree': patch
---

New tree component:
- Added a new `<sl-tree>` component
- Added `abstract` `TreeModel`, `FlatTreeModel` and `NestedTreeModel` classes
9 changes: 8 additions & 1 deletion packages/components/checkbox/src/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,15 @@ export class Checkbox<T = unknown> extends ObserveAttributesMixin(FormControlMix
return;
}

if (event.target instanceof HTMLLabelElement) {
const label = event.composedPath().find((el): el is HTMLLabelElement => el instanceof HTMLLabelElement);
if (label?.parentElement === this) {
this.input.click();

event.preventDefault();
event.stopPropagation();

// Return early to prevent the checkbox from being toggled twice
return;
}

event.stopPropagation();
Expand Down
5 changes: 3 additions & 2 deletions packages/components/data-source/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './src/array-data-source.js';
export * from './src/array-list-data-source.js';
export * from './src/data-source.js';
export * from './src/fetch-data-source.js';
export * from './src/fetch-list-data-source.js';
export * from './src/list-data-source.js';
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from '@open-wc/testing';
import { spy } from 'sinon';
import { ArrayDataSource } from './array-data-source.js';
import { ArrayListDataSource } from './array-list-data-source.js';
import { type Person, people } from './data-source.spec.js';

describe('ArrayDataSource', () => {
let ds: ArrayDataSource<Person>;
describe('ArrayListDataSource', () => {
let ds: ArrayListDataSource<Person>;

describe('basics', () => {
beforeEach(() => {
ds = new ArrayDataSource(people);
ds = new ArrayListDataSource(people);
});

it('should have items', () => {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('ArrayDataSource', () => {

describe('filtering', () => {
beforeEach(() => {
ds = new ArrayDataSource(people);
ds = new ArrayListDataSource(people);
});

it('should filter by path', () => {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('ArrayDataSource', () => {

describe('sorting', () => {
beforeEach(() => {
ds = new ArrayDataSource(people);
ds = new ArrayListDataSource(people);
});

it('should sort by path', () => {
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('ArrayDataSource', () => {

describe('pagination', () => {
beforeEach(() => {
ds = new ArrayDataSource(people, { pagination: true });
ds = new ArrayListDataSource(people, { pagination: true });
ds.setPage(1);
ds.setPageSize(3);
ds.update();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { type PathKeys, getStringByPath, getValueByPath } from '@sl-design-system/shared';
import {
DataSource,
type DataSourceFilterByFunction,
type DataSourceFilterByPath,
type DataSourceOptions,
type DataSourceSortFunction
} from './data-source.js';

export type ArrayDataSourceOptions = DataSourceOptions;
import { ListDataSource, type ListDataSourceOptions } from './list-data-source.js';

/**
* A data source that can be used to filter, group by, sort,
Expand All @@ -16,7 +13,7 @@ export type ArrayDataSourceOptions = DataSourceOptions;
* to load any additional data.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ArrayDataSource<T = any> extends DataSource<T> {
export class ArrayListDataSource<T = any> extends ListDataSource<T> {
/**
* The array of items after filtering, sorting, grouping and
* pagination has been applied.
Expand All @@ -30,16 +27,11 @@ export class ArrayDataSource<T = any> extends DataSource<T> {
return this.#filteredItems;
}

set items(items: T[]) {
this.#items = items;
this.update();
}

get size(): number {
return this.#items.length;
}

constructor(items: T[], options: ArrayDataSourceOptions = {}) {
constructor(items: T[], options: ListDataSourceOptions = {}) {
super(options);
this.#filteredItems = [...items];
this.#items = [...items];
Expand Down
29 changes: 0 additions & 29 deletions packages/components/data-source/src/data-source.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from '@open-wc/testing';
import { spy } from 'sinon';
import { DataSource } from './data-source.js';

// eslint-disable-next-line mocha/no-exports
Expand Down Expand Up @@ -116,23 +115,6 @@ describe('DataSource', () => {
expect(ds.filters).to.be.empty;
});

it('should not group by by default', () => {
expect(ds.groupBy).to.be.undefined;
});

it('should group by after setting one', () => {
ds.setGroupBy('profession');

expect(ds.groupBy).to.deep.equal({ path: 'profession', sorter: undefined, direction: undefined });
});

it('should not group by after removing it', () => {
ds.setGroupBy('profession');
ds.removeGroupBy();

expect(ds.groupBy).to.be.undefined;
});

it('should not sort by default', () => {
expect(ds.sort).to.be.undefined;
});
Expand All @@ -149,15 +131,4 @@ describe('DataSource', () => {

expect(ds.sort).to.be.undefined;
});

it('should reorder items', () => {
spy(ds, 'update');

expect(ds.items.map(({ id }) => id)).to.deep.equal([1, 2, 3, 4, 5]);

ds.reorder(people[0], people[4], 'before');

expect(ds.items.map(({ id }) => id)).to.deep.equal([2, 3, 4, 1, 5]);
expect(ds.update).to.have.been.calledOnce;
});
});
Loading
Loading