@universal-ember/table 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,9 @@ export interface TableConfig<DataType> {
96
96
  * you have a table representing "blog posts", your table key may be "blog-posts".
97
97
  *
98
98
  * And most importantly, the `adapter` is how you load and save the preferences.
99
- * This may bo to local storage, or some API.
99
+ * This may be to local storage, or some API.
100
+ *
101
+ * Can be provided as a thunk for reactive multi-table sync.
100
102
  */
101
103
  preferences?: {
102
104
  /**
@@ -117,6 +119,9 @@ export interface TableConfig<DataType> {
117
119
  * So it's best to load up the table preferences before rendering a table.
118
120
  */
119
121
  adapter?: PreferencesAdapter;
120
- };
122
+ } | (() => {
123
+ key: string;
124
+ adapter?: PreferencesAdapter;
125
+ });
121
126
  }
122
127
  //# sourceMappingURL=table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/-private/interfaces/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,SAAS;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,WAAW,CAAC,QAAQ;IACnC;;;;OAIG;IACH,OAAO,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,QAAQ,EAAE,CAAC;IAEvB;;;;;;;;;;;;;;;;;;;;;;;;;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AM,CAAC;IAEvC;;;;OAIG;IACc,IAAI,EAAE;QAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAE/D;;OAEG;IACH,sBAAsB,CAAC,EAAE,WAAW,CAAC;IAErC;;;OAGG;IACK,WAAW,EAAE,gBAAgB,CAAC;IAEtC;;OAEG;IACH,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;IAsB7D;;;;;;;;OAQG;IACH,SAAS;;;;;;;;;;;;;;;;;;;;;;MAuCP;IAEF;;;;;;OAMG;IACH,IACI,OAAO,IAAI,MAAM,EAAE,CA2BtB;IAED;;OAEG;IACH,QAAQ,CAAC,QAAQ,SAAS,UAAU,CAAC,GAAG,CAAC,EACvC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,GACrB,QAAQ,GAAG,SAAS;IAevB;;;;OAIG;IACH,IAAI,MAAM,0BAET;IAED,IAAI,mEASD;IAEH,OAAO,2GAqCJ;IAEH;;OAEG;IAEH,oBAAoB;IAOpB,eAAe;CAGhB"}
@@ -172,20 +172,23 @@ let Table = (_class = class Table extends Resource {
172
172
  this.args = {
173
173
  named
174
174
  };
175
+ const preferences = named?.preferences;
176
+ const {
177
+ key = guidFor(this),
178
+ adapter
179
+ } = (typeof preferences === 'function' ? preferences() : preferences) ?? {};
175
180
 
176
181
  // only set the preferences once
177
182
  if (!this.preferences) {
178
- const {
179
- key = guidFor(this),
180
- adapter
181
- } = named?.preferences ?? {};
182
-
183
183
  // TODO: when no key is present,
184
184
  // use "local-storage" preferences.
185
185
  // it does not make sense to use a guid in a user's preferences
186
186
  this.preferences = new TablePreferences(key, adapter);
187
187
  } else {
188
188
  // subsequent updates to args
189
+ if (typeof preferences === 'function' && adapter) {
190
+ this.preferences.restore(adapter);
191
+ }
189
192
  this.resetScrollContainer();
190
193
  }
191
194
  }
@@ -1 +1 @@
1
- {"version":3,"file":"table.js","sources":["../../src/-private/table.ts"],"sourcesContent":["import { cached, tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { action } from '@ember/object';\nimport { guidFor } from '@ember/object/internals';\n\nimport { isDevelopingApp, macroCondition } from '@embroider/macros';\nimport { modifier } from 'ember-modifier';\nimport { Resource } from 'ember-modify-based-class-resource';\nimport { map } from 'reactiveweb/map';\n\nimport {\n normalizePluginsConfig,\n verifyPlugins,\n} from '../plugins/-private/utils.ts';\nimport { Column } from './column.ts';\nimport { TablePreferences } from './preferences.ts';\nimport { Row } from './row.ts';\nimport { composeFunctionModifiers } from './utils.ts';\n\nimport type { BasePlugin, Plugin } from '../plugins/index.ts';\nimport type { Class } from './private-types.ts';\nimport type { Destructor, TableConfig } from './interfaces';\nimport { compatOwner } from './ember-compat.ts';\n\nconst getOwner = compatOwner.getOwner;\nconst setOwner = compatOwner.setOwner;\n\nconst DEFAULT_COLUMN_CONFIG = {\n isVisible: true,\n minWidth: 128,\n};\n\ninterface Signature<DataType> {\n Named: TableConfig<DataType>;\n}\n\n/**\n * Because the table is our entry-point object to all the table behaviors,\n * we need a stable way to know which table we have.\n * Normally, this could be done with referential integrity / identity.\n * However, due to how resources are implemented, if the consumer opts to\n * not use the `@use` decorator, then proxies get involved.\n * The proxies don't maintain instanceof checks, which may be a bug in\n * ember-resources.\n */\nexport const TABLE_KEY = Symbol('__TABLE_KEY__');\nexport const TABLE_META_KEY = Symbol('__TABLE_META__');\nexport const COLUMN_META_KEY = Symbol('__COLUMN_META__');\nexport const ROW_META_KEY = Symbol('__ROW_META__');\n\nconst attachContainer = (element: Element, table: Table) => {\n assert('Must be installed on an HTMLElement', element instanceof HTMLElement);\n\n table.scrollContainerElement = element;\n};\n\nexport class Table<DataType = unknown> extends Resource<Signature<DataType>> {\n /**\n * @private\n */\n [TABLE_KEY] = guidFor(this);\n /**\n * @private\n */\n [TABLE_META_KEY] = new Map<Class<unknown>, any>();\n /**\n * @private\n */\n [COLUMN_META_KEY] = new WeakMap<Column, Map<Class<unknown>, any>>();\n /**\n * @private\n */\n [ROW_META_KEY] = new WeakMap<Row, Map<Class<unknown>, any>>();\n\n /**\n * @private\n *\n * Unused for now, may be used in the future.\n * This data is collected along with the scrollContainerWidth, (which is currently in use)\n */\n @tracked scrollContainerHeight?: number;\n\n /**\n * @private\n *\n * Used to help determine how much space we can give to columns.\n * As we generate widths for columns, the columns' widths must\n * add up to about this number.\n */\n @tracked scrollContainerWidth?: number;\n\n /**\n * @private\n *\n * Lazy way to delay consuming arguments until they are needed.\n */\n @tracked declare args: { named: Signature<DataType>['Named'] };\n\n /**\n * @private\n */\n scrollContainerElement?: HTMLElement;\n\n /**\n * Interact with, save, modify, etc the preferences for the table,\n * plugins, columns, etc\n */\n declare preferences: TablePreferences;\n\n /**\n * @private\n */\n modify(_: [] | undefined, named: Signature<DataType>['Named']) {\n this.args = { named };\n\n // only set the preferences once\n if (!this.preferences) {\n const { key = guidFor(this), adapter } = named?.preferences ?? {};\n\n // TODO: when no key is present,\n // use \"local-storage\" preferences.\n // it does not make sense to use a guid in a user's preferences\n this.preferences = new TablePreferences(key, adapter);\n } else {\n // subsequent updates to args\n this.resetScrollContainer();\n }\n }\n\n /**\n * Collection of utility modifiers that are the result of composing modifiers\n * from plugins.\n *\n * Using this is optional, and you can \"just\" use modifiers from specific plugins\n * in specific places if you wish -- but these exists as a \"convenience\".\n *\n * These are all no-use, no-cost utilities\n */\n modifiers = {\n container: modifier((element: HTMLElement): Destructor => {\n const modifiers = this.plugins.map((plugin) => plugin.containerModifier);\n const composed = composeFunctionModifiers([\n attachContainer,\n ...modifiers,\n ]);\n\n return composed(element, this as Table<unknown>);\n }),\n\n // resize: ResizeModifier,\n // TODO: switch to composing real modifiers once \"curry\" and \"compose\"\n // RFCs are accepted and implemented\n //\n // Atm the moment, if _any_ header modifier's tracked data changes,\n // all the functions for all of the plugins run again.\n //\n // With curried+composed modifiers, only the plugin's headerModifier\n // that has tracked changes would run, leaving the other modifiers alone\n columnHeader: modifier(\n (element: HTMLElement, [column]: [Column<DataType>]): Destructor => {\n const modifiers = this.plugins.map(\n (plugin) => plugin.headerCellModifier,\n );\n const composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { column, table: this });\n },\n ),\n\n row: modifier(\n (element: HTMLElement, [row]: [Row<DataType>]): Destructor => {\n const modifiers = this.plugins.map((plugin) => plugin.rowModifier);\n const composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { row, table: this });\n },\n ),\n };\n\n /**\n * @private\n *\n * For all configured plugins, instantiates each one.\n * If the plugins argument changes to the Table (either directly or through\n * headlessTable, all state is lost and re-created)\n */\n @cached\n get plugins(): Plugin[] {\n const plugins = normalizePluginsConfig(this.args.named?.plugins);\n\n verifyPlugins(plugins);\n\n return plugins.map((tuple) => {\n // We don't need the options here\n const [PluginClass] = tuple;\n\n if (typeof PluginClass === 'function') {\n const plugin = new PluginClass(this);\n\n const owner = getOwner(this);\n\n assert(\n `The Table does not have an owner. cannot create a plugin without an owner`,\n owner,\n );\n setOwner(plugin, owner);\n\n return plugin;\n }\n\n // This is a plugin object, rather than a class\n // TODO: add test coverage around using classless plugins\n return PluginClass;\n });\n }\n\n /**\n * Get the active plugin instance for the given plugin class\n */\n pluginOf<Instance extends BasePlugin<any>>(\n klass: Class<Instance>,\n ): Instance | undefined {\n const result = this.plugins.find((plugin) => plugin instanceof klass);\n\n /**\n * This is an unsafe cast, because Instance could be unrelated to any of the types\n * that matches Plugin[]\n *\n * For example, `table.pluginOf(MyCustomPlugin)`, where MyCustomPlugin isn't in the\n * `plugins` list. This partially a problem with how Array.prototype.find doesn't\n * effectively narrow for what we want (combined with TS being clunky around\n * comparing Instance and Class types).\n */\n return result as unknown as Instance | undefined;\n }\n\n /**\n * @private\n *\n * used by other private APIs\n */\n get config() {\n return this.args.named;\n }\n\n rows = map(this, {\n data: () => {\n const dataFn = this.args.named?.data;\n\n if (!dataFn) return [];\n\n return dataFn() ?? [];\n },\n map: (datum) => new Row(this, datum),\n });\n\n columns = map(this, {\n data: () => {\n const configFn = this.args.named?.columns;\n\n if (!configFn) return [];\n\n const result = configFn() ?? [];\n\n if (macroCondition(isDevelopingApp())) {\n /**\n * Assertions for a column config to be valid:\n * - every key must be unique\n */\n const keys = new Set();\n const allKeys = result.map((columnConfig) => columnConfig.key);\n\n result.forEach((columnConfig) => {\n if (keys.has(columnConfig.key)) {\n throw new Error(\n `Every column key in the table's column config must be unique. ` +\n `Found duplicate entry: ${columnConfig.key}. ` +\n `All keys used: ${allKeys}`,\n );\n }\n\n keys.add(columnConfig.key);\n });\n }\n\n return result;\n },\n map: (config) => {\n return new Column<DataType>(this, {\n ...DEFAULT_COLUMN_CONFIG,\n ...config,\n });\n },\n });\n\n /**\n * @private\n */\n @action\n resetScrollContainer() {\n if (!this.scrollContainerElement) return;\n\n this.scrollContainerElement.scrollTop = 0;\n }\n\n @action\n resetToDefaults() {\n this.plugins.forEach((plugin) => plugin.reset?.());\n }\n}\n"],"names":["getOwner","compatOwner","setOwner","DEFAULT_COLUMN_CONFIG","isVisible","minWidth","TABLE_KEY","Symbol","TABLE_META_KEY","COLUMN_META_KEY","ROW_META_KEY","attachContainer","element","table","assert","HTMLElement","scrollContainerElement","Table","_class","Resource","constructor","args","_defineProperty","guidFor","Map","WeakMap","_initializerDefineProperty","_descriptor","_descriptor2","_descriptor3","container","modifier","modifiers","plugins","map","plugin","containerModifier","composed","composeFunctionModifiers","columnHeader","column","headerCellModifier","row","rowModifier","data","dataFn","named","datum","Row","configFn","columns","result","macroCondition","isDevelopingApp","keys","Set","allKeys","columnConfig","key","forEach","has","Error","add","config","Column","modify","_","preferences","adapter","TablePreferences","resetScrollContainer","normalizePluginsConfig","verifyPlugins","tuple","PluginClass","owner","pluginOf","klass","find","scrollTop","resetToDefaults","reset","_applyDecoratedDescriptor","prototype","tracked","configurable","enumerable","writable","initializer","cached","Object","getOwnPropertyDescriptor","action"],"mappings":";;;;;;;;;;;;;;;;;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EAAAA,YAAA,GAAAsD,yBAAA,CAAAhE,MAAA,CAAAiE,SAAA,2BASPC,OAAO,CAAA,EAAA;EAAAC,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA3D,CAAAA,EAAAA,YAAA,GAAAqD,yBAAA,CAAAhE,MAAA,CAAAiE,SAAA,WAOPC,OAAO,CAAA,EAAA;EAAAC,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA,CAAA,EAAAN,yBAAA,CAAAhE,MAAA,CAAAiE,SAAA,EAAA,SAAA,EAAA,CA0FPM,MAAM,CAAA,EAAAC,MAAA,CAAAC,wBAAA,CAAAzE,MAAA,CAAAiE,SAAA,EAAA,SAAA,CAAA,EAAAjE,MAAA,CAAAiE,SAAA,CAAA,EAAAD,yBAAA,CAAAhE,MAAA,CAAAiE,SAAA,EAAA,sBAAA,EAAA,CAgHNS,MAAM,CAAA,EAAAF,MAAA,CAAAC,wBAAA,CAAAzE,MAAA,CAAAiE,SAAA,EAAA,sBAAA,CAAA,EAAAjE,MAAA,CAAAiE,SAAA,CAAA,EAAAD,yBAAA,CAAAhE,MAAA,CAAAiE,SAAA,EAAA,iBAAA,EAAA,CAONS,MAAM,CAAA,EAAAF,MAAA,CAAAC,wBAAA,CAAAzE,MAAA,CAAAiE,SAAA,EAAA,iBAAA,CAAA,EAAAjE,MAAA,CAAAiE,SAAA,CAAA,EAAAjE,MAAA;;;;"}
1
+ {"version":3,"file":"table.js","sources":["../../src/-private/table.ts"],"sourcesContent":["import { cached, tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { action } from '@ember/object';\nimport { guidFor } from '@ember/object/internals';\n\nimport { isDevelopingApp, macroCondition } from '@embroider/macros';\nimport { modifier } from 'ember-modifier';\nimport { Resource } from 'ember-modify-based-class-resource';\nimport { map } from 'reactiveweb/map';\n\nimport {\n normalizePluginsConfig,\n verifyPlugins,\n} from '../plugins/-private/utils.ts';\nimport { Column } from './column.ts';\nimport { TablePreferences } from './preferences.ts';\nimport { Row } from './row.ts';\nimport { composeFunctionModifiers } from './utils.ts';\n\nimport type { BasePlugin, Plugin } from '../plugins/index.ts';\nimport type { Class } from './private-types.ts';\nimport type { Destructor, TableConfig } from './interfaces';\nimport { compatOwner } from './ember-compat.ts';\n\nconst getOwner = compatOwner.getOwner;\nconst setOwner = compatOwner.setOwner;\n\nconst DEFAULT_COLUMN_CONFIG = {\n isVisible: true,\n minWidth: 128,\n};\n\ninterface Signature<DataType> {\n Named: TableConfig<DataType>;\n}\n\n/**\n * Because the table is our entry-point object to all the table behaviors,\n * we need a stable way to know which table we have.\n * Normally, this could be done with referential integrity / identity.\n * However, due to how resources are implemented, if the consumer opts to\n * not use the `@use` decorator, then proxies get involved.\n * The proxies don't maintain instanceof checks, which may be a bug in\n * ember-resources.\n */\nexport const TABLE_KEY = Symbol('__TABLE_KEY__');\nexport const TABLE_META_KEY = Symbol('__TABLE_META__');\nexport const COLUMN_META_KEY = Symbol('__COLUMN_META__');\nexport const ROW_META_KEY = Symbol('__ROW_META__');\n\nconst attachContainer = (element: Element, table: Table) => {\n assert('Must be installed on an HTMLElement', element instanceof HTMLElement);\n\n table.scrollContainerElement = element;\n};\n\nexport class Table<DataType = unknown> extends Resource<Signature<DataType>> {\n /**\n * @private\n */\n [TABLE_KEY] = guidFor(this);\n /**\n * @private\n */\n [TABLE_META_KEY] = new Map<Class<unknown>, any>();\n /**\n * @private\n */\n [COLUMN_META_KEY] = new WeakMap<Column, Map<Class<unknown>, any>>();\n /**\n * @private\n */\n [ROW_META_KEY] = new WeakMap<Row, Map<Class<unknown>, any>>();\n\n /**\n * @private\n *\n * Unused for now, may be used in the future.\n * This data is collected along with the scrollContainerWidth, (which is currently in use)\n */\n @tracked scrollContainerHeight?: number;\n\n /**\n * @private\n *\n * Used to help determine how much space we can give to columns.\n * As we generate widths for columns, the columns' widths must\n * add up to about this number.\n */\n @tracked scrollContainerWidth?: number;\n\n /**\n * @private\n *\n * Lazy way to delay consuming arguments until they are needed.\n */\n @tracked declare args: { named: Signature<DataType>['Named'] };\n\n /**\n * @private\n */\n scrollContainerElement?: HTMLElement;\n\n /**\n * Interact with, save, modify, etc the preferences for the table,\n * plugins, columns, etc\n */\n declare preferences: TablePreferences;\n\n /**\n * @private\n */\n modify(_: [] | undefined, named: Signature<DataType>['Named']) {\n this.args = { named };\n\n const preferences = named?.preferences;\n const { key = guidFor(this), adapter } =\n (typeof preferences === 'function' ? preferences() : preferences) ?? {};\n\n // only set the preferences once\n if (!this.preferences) {\n // TODO: when no key is present,\n // use \"local-storage\" preferences.\n // it does not make sense to use a guid in a user's preferences\n this.preferences = new TablePreferences(key, adapter);\n } else {\n // subsequent updates to args\n if (typeof preferences === 'function' && adapter) {\n this.preferences.restore(adapter);\n }\n this.resetScrollContainer();\n }\n }\n\n /**\n * Collection of utility modifiers that are the result of composing modifiers\n * from plugins.\n *\n * Using this is optional, and you can \"just\" use modifiers from specific plugins\n * in specific places if you wish -- but these exists as a \"convenience\".\n *\n * These are all no-use, no-cost utilities\n */\n modifiers = {\n container: modifier((element: HTMLElement): Destructor => {\n const modifiers = this.plugins.map((plugin) => plugin.containerModifier);\n const composed = composeFunctionModifiers([\n attachContainer,\n ...modifiers,\n ]);\n\n return composed(element, this as Table<unknown>);\n }),\n\n // resize: ResizeModifier,\n // TODO: switch to composing real modifiers once \"curry\" and \"compose\"\n // RFCs are accepted and implemented\n //\n // Atm the moment, if _any_ header modifier's tracked data changes,\n // all the functions for all of the plugins run again.\n //\n // With curried+composed modifiers, only the plugin's headerModifier\n // that has tracked changes would run, leaving the other modifiers alone\n columnHeader: modifier(\n (element: HTMLElement, [column]: [Column<DataType>]): Destructor => {\n const modifiers = this.plugins.map(\n (plugin) => plugin.headerCellModifier,\n );\n const composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { column, table: this });\n },\n ),\n\n row: modifier(\n (element: HTMLElement, [row]: [Row<DataType>]): Destructor => {\n const modifiers = this.plugins.map((plugin) => plugin.rowModifier);\n const composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { row, table: this });\n },\n ),\n };\n\n /**\n * @private\n *\n * For all configured plugins, instantiates each one.\n * If the plugins argument changes to the Table (either directly or through\n * headlessTable, all state is lost and re-created)\n */\n @cached\n get plugins(): Plugin[] {\n const plugins = normalizePluginsConfig(this.args.named?.plugins);\n\n verifyPlugins(plugins);\n\n return plugins.map((tuple) => {\n // We don't need the options here\n const [PluginClass] = tuple;\n\n if (typeof PluginClass === 'function') {\n const plugin = new PluginClass(this);\n\n const owner = getOwner(this);\n\n assert(\n `The Table does not have an owner. cannot create a plugin without an owner`,\n owner,\n );\n setOwner(plugin, owner);\n\n return plugin;\n }\n\n // This is a plugin object, rather than a class\n // TODO: add test coverage around using classless plugins\n return PluginClass;\n });\n }\n\n /**\n * Get the active plugin instance for the given plugin class\n */\n pluginOf<Instance extends BasePlugin<any>>(\n klass: Class<Instance>,\n ): Instance | undefined {\n const result = this.plugins.find((plugin) => plugin instanceof klass);\n\n /**\n * This is an unsafe cast, because Instance could be unrelated to any of the types\n * that matches Plugin[]\n *\n * For example, `table.pluginOf(MyCustomPlugin)`, where MyCustomPlugin isn't in the\n * `plugins` list. This partially a problem with how Array.prototype.find doesn't\n * effectively narrow for what we want (combined with TS being clunky around\n * comparing Instance and Class types).\n */\n return result as unknown as Instance | undefined;\n }\n\n /**\n * @private\n *\n * used by other private APIs\n */\n get config() {\n return this.args.named;\n }\n\n rows = map(this, {\n data: () => {\n const dataFn = this.args.named?.data;\n\n if (!dataFn) return [];\n\n return dataFn() ?? [];\n },\n map: (datum) => new Row(this, datum),\n });\n\n columns = map(this, {\n data: () => {\n const configFn = this.args.named?.columns;\n\n if (!configFn) return [];\n\n const result = configFn() ?? [];\n\n if (macroCondition(isDevelopingApp())) {\n /**\n * Assertions for a column config to be valid:\n * - every key must be unique\n */\n const keys = new Set();\n const allKeys = result.map((columnConfig) => columnConfig.key);\n\n result.forEach((columnConfig) => {\n if (keys.has(columnConfig.key)) {\n throw new Error(\n `Every column key in the table's column config must be unique. ` +\n `Found duplicate entry: ${columnConfig.key}. ` +\n `All keys used: ${allKeys}`,\n );\n }\n\n keys.add(columnConfig.key);\n });\n }\n\n return result;\n },\n map: (config) => {\n return new Column<DataType>(this, {\n ...DEFAULT_COLUMN_CONFIG,\n ...config,\n });\n },\n });\n\n /**\n * @private\n */\n @action\n resetScrollContainer() {\n if (!this.scrollContainerElement) return;\n\n this.scrollContainerElement.scrollTop = 0;\n }\n\n @action\n resetToDefaults() {\n this.plugins.forEach((plugin) => plugin.reset?.());\n }\n}\n"],"names":["getOwner","compatOwner","setOwner","DEFAULT_COLUMN_CONFIG","isVisible","minWidth","TABLE_KEY","Symbol","TABLE_META_KEY","COLUMN_META_KEY","ROW_META_KEY","attachContainer","element","table","assert","HTMLElement","scrollContainerElement","Table","_class","Resource","constructor","args","_defineProperty","guidFor","Map","WeakMap","_initializerDefineProperty","_descriptor","_descriptor2","_descriptor3","container","modifier","modifiers","plugins","map","plugin","containerModifier","composed","composeFunctionModifiers","columnHeader","column","headerCellModifier","row","rowModifier","data","dataFn","named","datum","Row","configFn","columns","result","macroCondition","isDevelopingApp","keys","Set","allKeys","columnConfig","key","forEach","has","Error","add","config","Column","modify","_","preferences","adapter","TablePreferences","restore","resetScrollContainer","normalizePluginsConfig","verifyPlugins","tuple","PluginClass","owner","pluginOf","klass","find","scrollTop","resetToDefaults","reset","_applyDecoratedDescriptor","prototype","tracked","configurable","enumerable","writable","initializer","cached","Object","getOwnPropertyDescriptor","action"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,MAAMA,QAAQ,GAAGC,WAAW,CAACD,QAAQ;AACrC,MAAME,QAAQ,GAAGD,WAAW,CAACC,QAAQ;AAErC,MAAMC,qBAAqB,GAAG;AAC5BC,EAAAA,SAAS,EAAE,IAAI;AAC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C,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA7D,CAAAA,EAAAA,YAAA,GAAAuD,yBAAA,CAAAjE,MAAA,CAAAkE,SAAA,2BASPC,OAAO,CAAA,EAAA;EAAAC,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA5D,CAAAA,EAAAA,YAAA,GAAAsD,yBAAA,CAAAjE,MAAA,CAAAkE,SAAA,WAOPC,OAAO,CAAA,EAAA;EAAAC,YAAA,EAAA,IAAA;EAAAC,UAAA,EAAA,IAAA;EAAAC,QAAA,EAAA,IAAA;EAAAC,WAAA,EAAA;AAAA,CAAA,CAAA,EAAAN,yBAAA,CAAAjE,MAAA,CAAAkE,SAAA,EAAA,SAAA,EAAA,CA+FPM,MAAM,CAAA,EAAAC,MAAA,CAAAC,wBAAA,CAAA1E,MAAA,CAAAkE,SAAA,EAAA,SAAA,CAAA,EAAAlE,MAAA,CAAAkE,SAAA,CAAA,EAAAD,yBAAA,CAAAjE,MAAA,CAAAkE,SAAA,EAAA,sBAAA,EAAA,CAgHNS,MAAM,CAAA,EAAAF,MAAA,CAAAC,wBAAA,CAAA1E,MAAA,CAAAkE,SAAA,EAAA,sBAAA,CAAA,EAAAlE,MAAA,CAAAkE,SAAA,CAAA,EAAAD,yBAAA,CAAAjE,MAAA,CAAAkE,SAAA,EAAA,iBAAA,EAAA,CAONS,MAAM,CAAA,EAAAF,MAAA,CAAAC,wBAAA,CAAA1E,MAAA,CAAAkE,SAAA,EAAA,iBAAA,CAAA,EAAAlE,MAAA,CAAAkE,SAAA,CAAA,EAAAlE,MAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@universal-ember/table",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "An implementation of table behaviors for driving any table or table-like UI -- all without a UI (headless)",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -110,26 +110,30 @@ export interface TableConfig<DataType> {
110
110
  * you have a table representing "blog posts", your table key may be "blog-posts".
111
111
  *
112
112
  * And most importantly, the `adapter` is how you load and save the preferences.
113
- * This may bo to local storage, or some API.
113
+ * This may be to local storage, or some API.
114
+ *
115
+ * Can be provided as a thunk for reactive multi-table sync.
114
116
  */
115
- preferences?: {
116
- /**
117
- * What to name the table in the preferences storage of your choice.
118
- * Any string is valid provided that the storage adapter of your choice supports
119
- * the format.
120
- *
121
- * For example, if you have a table of "blog posts", the preferences key might be
122
- * `"all-blog-posts"`
123
- */
124
- key: string;
125
- /**
126
- * Configuration for how you wish to `persist` and `restore` the configuration for your table.
127
- *
128
- * `persist` may be async as it is a fire-and-forget type of action.
129
- *
130
- * However, `restore` must be synchronous, as this is a blocking operation for rendering the table.
131
- * So it's best to load up the table preferences before rendering a table.
132
- */
133
- adapter?: PreferencesAdapter;
134
- };
117
+ preferences?:
118
+ | {
119
+ /**
120
+ * What to name the table in the preferences storage of your choice.
121
+ * Any string is valid provided that the storage adapter of your choice supports
122
+ * the format.
123
+ *
124
+ * For example, if you have a table of "blog posts", the preferences key might be
125
+ * `"all-blog-posts"`
126
+ */
127
+ key: string;
128
+ /**
129
+ * Configuration for how you wish to `persist` and `restore` the configuration for your table.
130
+ *
131
+ * `persist` may be async as it is a fire-and-forget type of action.
132
+ *
133
+ * However, `restore` must be synchronous, as this is a blocking operation for rendering the table.
134
+ * So it's best to load up the table preferences before rendering a table.
135
+ */
136
+ adapter?: PreferencesAdapter;
137
+ }
138
+ | (() => { key: string; adapter?: PreferencesAdapter });
135
139
  }
@@ -113,16 +113,21 @@ export class Table<DataType = unknown> extends Resource<Signature<DataType>> {
113
113
  modify(_: [] | undefined, named: Signature<DataType>['Named']) {
114
114
  this.args = { named };
115
115
 
116
+ const preferences = named?.preferences;
117
+ const { key = guidFor(this), adapter } =
118
+ (typeof preferences === 'function' ? preferences() : preferences) ?? {};
119
+
116
120
  // only set the preferences once
117
121
  if (!this.preferences) {
118
- const { key = guidFor(this), adapter } = named?.preferences ?? {};
119
-
120
122
  // TODO: when no key is present,
121
123
  // use "local-storage" preferences.
122
124
  // it does not make sense to use a guid in a user's preferences
123
125
  this.preferences = new TablePreferences(key, adapter);
124
126
  } else {
125
127
  // subsequent updates to args
128
+ if (typeof preferences === 'function' && adapter) {
129
+ this.preferences.restore(adapter);
130
+ }
126
131
  this.resetScrollContainer();
127
132
  }
128
133
  }