Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/eslint-parser": "^7.11.0",
"@crowdstrike/ember-toucan-styles": "^2.0.0",
"@crowdstrike/tailwind-toucan-base": "^4.0.0",
"@docfy/core": "^0.7.0",
Expand Down Expand Up @@ -69,7 +70,6 @@
"@types/qunit": "^2.19.3",
"@types/rsvp": "^4.0.4",
"autoprefixer": "^10.4.14",
"@babel/eslint-parser": "^7.11.0",
"broccoli-asset-rev": "^3.0.0",
"concurrently": "^8.0.0",
"cssnano": "^6.0.0",
Expand Down Expand Up @@ -117,6 +117,7 @@
},
"dependencies": {
"@crowdstrike/ember-oss-docs": "^1.1.4",
"@ember/string": "^3.0.0",
"@ember/test-waiters": "^3.0.2",
"@embroider/router": "^2.0.0",
"dompurify": "^2.4.5",
Expand Down
2 changes: 1 addition & 1 deletion ember-headless-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@ember/string": "^3.0.0",
"@embroider/addon-shim": "^1.0.0",
"@embroider/macros": "1.10.0",
"ember-modifier": "^3.2.7",
"ember-modifier": "^4.1.0",
"ember-resources": "^5.4.0",
"ember-tracked-storage-polyfill": "^1.0.0",
"tracked-built-ins": "^3.1.0"
Expand Down
8 changes: 5 additions & 3 deletions ember-headless-table/src/-private/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TrackedMap } from 'tracked-built-ins';

import type {
PluginClass,
PluginPreferenceFor,
PluginPreferences,
PreferencesAdapter as Adapter,
Expand Down Expand Up @@ -63,12 +64,13 @@ class TrackedPreferences {
return [...this.plugins.values()].every((pluginPrefs) => pluginPrefs.isAtDefault);
}

forPlugin(name: string) {
let existing = this.plugins.get(name);
forPlugin(klass: PluginClass<any>) {
let instance = Reflect.construct(klass, []) as PluginClass<any>;
let existing = this.plugins.get(instance.name);

if (!existing) {
existing = new TrackedPluginPrefs();
this.plugins.set(name, existing);
this.plugins.set(instance.name, existing);
}

return existing;
Expand Down
45 changes: 18 additions & 27 deletions ember-headless-table/src/-private/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,12 @@ export class Table<DataType = unknown> extends Resource<Signature<DataType>> {
* These are all no-use, no-cost utilities
*/
modifiers = {
container: modifier(
(element: HTMLElement): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.containerModifier);
let composed = composeFunctionModifiers([attachContainer, ...modifiers]);
container: modifier((element: HTMLElement): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.containerModifier);
let composed = composeFunctionModifiers([attachContainer, ...modifiers]);

return composed(element, this);
},
{ eager: false }
),
return composed(element, this);
}),

// resize: ResizeModifier,
// TODO: switch to composing real modifiers once "curry" and "compose"
Expand All @@ -150,25 +147,19 @@ export class Table<DataType = unknown> extends Resource<Signature<DataType>> {
//
// With curried+composed modifiers, only the plugin's headerModifier
// that has tracked changes would run, leaving the other modifiers alone
columnHeader: modifier(
(element: HTMLElement, [column]: [Column<DataType>]): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.headerCellModifier);
let composed = composeFunctionModifiers(modifiers);

return composed(element, { column, table: this });
},
{ eager: false }
),

row: modifier(
(element: HTMLElement, [row]: [Row<DataType>]): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.rowModifier);
let composed = composeFunctionModifiers(modifiers);

return composed(element, { row, table: this });
},
{ eager: false }
),
columnHeader: modifier((element: HTMLElement, [column]: [Column<DataType>]): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.headerCellModifier);
let composed = composeFunctionModifiers(modifiers);

return composed(element, { column, table: this });
}),

row: modifier((element: HTMLElement, [row]: [Row<DataType>]): Destructor => {
let modifiers = this.plugins.map((plugin) => plugin.rowModifier);
let composed = composeFunctionModifiers(modifiers);

return composed(element, { row, table: this });
}),
};

/**
Expand Down
37 changes: 7 additions & 30 deletions ember-headless-table/src/plugins/-private/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const preferences = {
*/
delete(key: string) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.delete(key);
Expand All @@ -170,7 +170,7 @@ export const preferences = {
*/
get(key: string) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

return columnPrefs.get(key);
Expand All @@ -180,7 +180,7 @@ export const preferences = {
*/
set(key: string, value: unknown) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.set(key, value);
Expand All @@ -206,7 +206,7 @@ export const preferences = {

for (let column of table.columns) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.delete(key);
Expand Down Expand Up @@ -234,7 +234,7 @@ export const preferences = {
*/
delete(key: string) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

existing.table.delete(key);

Expand All @@ -245,7 +245,7 @@ export const preferences = {
*/
get(key: string) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

return existing.table.get(key);
},
Expand All @@ -254,7 +254,7 @@ export const preferences = {
*/
set(key: string, value: unknown) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

existing.table.set(key, value);

Expand Down Expand Up @@ -289,7 +289,6 @@ function columnsFor<DataType = any>(

let visibility = findPlugin(table.plugins, 'columnVisibility');
let reordering = findPlugin(table.plugins, 'columnOrder');
let sizing = findPlugin(table.plugins, 'columnResizing');

// TODO: actually resolve the graph, rather than use the hardcoded feature names
// atm, this only "happens" to work based on expectations of
Expand All @@ -302,10 +301,6 @@ function columnsFor<DataType = any>(
table.plugins.some((plugin) => plugin instanceof (requester as Class<Plugin>))
);

if (sizing && sizing.constructor === requester) {
return table.columns.values();
}

if (visibility && visibility.constructor === requester) {
return table.columns.values();
}
Expand Down Expand Up @@ -341,15 +336,6 @@ function columnsFor<DataType = any>(
return visibility.columns;
}

if (sizing) {
assert(
`<#${sizing.name}> defined a 'columns' property, but did not return valid data.`,
sizing.columns && Array.isArray(sizing.columns)
);

return sizing.columns;
}

return table.columns.values();
}

Expand All @@ -375,15 +361,6 @@ function columnsFor<DataType = any>(
return visibility.columns;
}

if (sizing) {
assert(
`<#${sizing.name}> defined a 'columns' property, but did not return valid data.`,
sizing.columns && Array.isArray(sizing.columns)
);

return sizing.columns;
}

return table.columns.values();
}

Expand Down
2 changes: 1 addition & 1 deletion ember-headless-table/src/plugins/column-resizing/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class TableMeta {
let tablePrefs = this.table.preferences;

for (let column of visibleColumnMetas) {
let existing = tablePrefs.storage.forPlugin('ColumnResizing');
let existing = tablePrefs.storage.forPlugin(ColumnResizing);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.set('width', column.width.toString());
Expand Down
Loading