@ember-joinery/data-table 0.0.0-stage → 1.1.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/LICENSE.md +9 -0
  3. package/NOTICE +532 -0
  4. package/README.md +79 -2
  5. package/addon-main.cjs +4 -0
  6. package/declarations/-private/bound-methods.d.ts +23 -0
  7. package/declarations/-private/bound-methods.d.ts.map +1 -0
  8. package/declarations/-private/reactivity.d.ts +9 -0
  9. package/declarations/-private/reactivity.d.ts.map +1 -0
  10. package/declarations/components/data-table.d.ts +77 -0
  11. package/declarations/components/data-table.d.ts.map +1 -0
  12. package/declarations/components/flex-render.d.ts +103 -0
  13. package/declarations/components/flex-render.d.ts.map +1 -0
  14. package/declarations/index.d.ts +7 -0
  15. package/declarations/index.d.ts.map +1 -0
  16. package/declarations/table-core.d.ts +7 -0
  17. package/declarations/table-core.d.ts.map +1 -0
  18. package/declarations/table.d.ts +65 -0
  19. package/declarations/table.d.ts.map +1 -0
  20. package/declarations/test-support/data-table.d.ts +111 -0
  21. package/declarations/test-support/data-table.d.ts.map +1 -0
  22. package/declarations/test-support/index.d.ts +2 -0
  23. package/declarations/test-support/index.d.ts.map +1 -0
  24. package/declarations/test-support.d.ts +2 -0
  25. package/dist/components/data-table.js +107 -0
  26. package/dist/components/data-table.js.map +1 -0
  27. package/dist/components/flex-render.js +104 -0
  28. package/dist/components/flex-render.js.map +1 -0
  29. package/dist/index.js +5 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/table-core.js +2 -0
  32. package/dist/table-core.js.map +1 -0
  33. package/dist/table.js +300 -0
  34. package/dist/table.js.map +1 -0
  35. package/dist/test-support.js +304 -0
  36. package/dist/test-support.js.map +1 -0
  37. package/package.json +116 -3
@@ -0,0 +1,104 @@
1
+ import { isFunction, isObject, isBoolean, isString, isNumber } from '@sindresorhus/is';
2
+ import Component from '@glimmer/component';
3
+ import { setComponentTemplate, getComponentTemplate } from '@ember/component';
4
+ import { isHTMLSafe } from '@ember/template';
5
+ import { precompileTemplate } from '@ember/template-compilation';
6
+
7
+ /** What a FlexRender reads of a header or footer: its column's definition and its context. */
8
+ /**
9
+ * The arguments a component in a column's `cell` gets: the cell's context, and each of its
10
+ * members on its own, as a React cell function destructures them (`({ row }) => …`).
11
+ */
12
+ /** The arguments a component in a column's `header` or `footer` gets. */
13
+ /** A component for a column's `cell`: `cell: flexComponent(StatusCell)`. */
14
+ /** A component for a column's `header` or `footer`: `header: flexComponent(SelectAll)`. */
15
+ /** Whether a value is a component: one with a template, or a class (whose template it inherits). */function isComponent(value) {
16
+ if (!isObject(value)) return false;
17
+ return getComponentTemplate(value) !== undefined || isFunction(value) && /^class[\s{]/.test(Function.prototype.toString.call(value));
18
+ }
19
+ /**
20
+ * A column's `header`, `cell` or `footer` as a component: `cell: flexComponent(StatusCell)`.
21
+ * The component gets the context and each of its members as arguments (`@row`, `@column`,
22
+ * `@table`… see `CellComponentArgs` and `HeaderComponentArgs`). table-core's types take a
23
+ * string or a function there, so this hands it a function that returns the component, which
24
+ * `FlexRender` renders. It takes any context, since table-core checks a column's template
25
+ * against the column's own value type.
26
+ */
27
+ function flexComponent(component) {
28
+ return () => component;
29
+ }
30
+ /** What a FlexRender draws: a component with its arguments, or a value as text. */
31
+
32
+ /** `null`, `undefined` and booleans draw nothing, as in React; anything else draws as text. */function drawable(value) {
33
+ if (value === null || value === undefined || isBoolean(value)) return undefined;
34
+ if (isString(value) || isNumber(value) || isHTMLSafe(value)) {
35
+ return value;
36
+ }
37
+ return String(value);
38
+ }
39
+ function resolve(template, given) {
40
+ const context = given;
41
+ if (template === null || template === undefined) return {};
42
+ if (isComponent(template)) return {
43
+ component: template,
44
+ args: context
45
+ };
46
+ if (isFunction(template)) {
47
+ const result = template(context);
48
+ if (isComponent(result)) return {
49
+ component: result,
50
+ args: context
51
+ };
52
+ return {
53
+ text: drawable(result)
54
+ };
55
+ }
56
+ return {
57
+ text: drawable(template)
58
+ };
59
+ }
60
+ /**
61
+ * Renders a header, cell or footer from its column definition, as TanStack's `FlexRender`
62
+ * does in React: give it one of `@cell`, `@header` or `@footer`. The column's template may be a
63
+ * string, a function of the context (returning a string, a number, or a component), or a
64
+ * component, which gets the context's members as arguments.
65
+ *
66
+ * <t.Head><FlexRender @header={{header}} /></t.Head>
67
+ * <t.Cell><FlexRender @cell={{cell}} /></t.Cell>
68
+ *
69
+ * Every table `createTable()` makes carries it too, as `table.FlexRender`, as upstream's does.
70
+ * A placeholder cell (from column grouping) renders nothing.
71
+ */
72
+ class FlexRender extends Component {
73
+ get resolved() {
74
+ const {
75
+ cell,
76
+ header,
77
+ footer
78
+ } = this.args;
79
+ if (cell) {
80
+ const definition = cell.column.columnDef;
81
+ if (cell.getIsAggregated?.()) {
82
+ return resolve(definition.aggregatedCell ?? definition.cell, cell.getContext());
83
+ }
84
+ if (cell.getIsPlaceholder?.()) return {};
85
+ return resolve(definition.cell, cell.getContext());
86
+ }
87
+ if (header) {
88
+ return resolve(header.column.columnDef.header, header.getContext());
89
+ }
90
+ if (footer) {
91
+ return resolve(footer.column.columnDef.footer, footer.getContext());
92
+ }
93
+ return {};
94
+ }
95
+ // The whitespace control (~) leaves nothing around what it renders, as React's does.
96
+ static {
97
+ setComponentTemplate(precompileTemplate("{{~#let this.resolved as |r|~}}\n {{~#if r.component~}}\n <r.component @context={{r.args}} @table={{r.args.table}} @column={{r.args.column}} @header={{r.args.header}} @row={{r.args.row}} @cell={{r.args.cell}} @getValue={{r.args.getValue}} @renderValue={{r.args.renderValue}} />\n {{~else~}}\n {{r.text}}\n {{~/if~}}\n{{~/let~}}", {
98
+ strictMode: true
99
+ }), this);
100
+ }
101
+ }
102
+
103
+ export { FlexRender as default, flexComponent, isComponent };
104
+ //# sourceMappingURL=flex-render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flex-render.js","sources":["../../src/components/flex-render.gts"],"sourcesContent":["import { isBoolean, isFunction, isNumber, isObject, isString } from '@sindresorhus/is'\nimport Component from '@glimmer/component'\nimport { getComponentTemplate } from '@ember/component'\nimport { isHTMLSafe, type SafeString } from '@ember/template'\nimport type { ComponentLike } from '@glint/template'\nimport type {\n CellContext,\n CellData,\n HeaderContext,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\n\n/**\n * What a FlexRender reads of a cell, whatever its table's features: its column's definition and\n * its context (and, with column grouping, whether it is aggregated or a placeholder).\n */\nexport interface FlexCell {\n column: { columnDef: object }\n getContext(): object\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n}\n\n/** What a FlexRender reads of a header or footer: its column's definition and its context. */\nexport interface FlexHeader {\n column: { columnDef: object }\n getContext(): object\n}\n\n/**\n * The arguments a component in a column's `cell` gets: the cell's context, and each of its\n * members on its own, as a React cell function destructures them (`({ row }) => …`).\n */\nexport interface CellComponentArgs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** The whole context, as table-core's `cell.getContext()` makes it. */\n context: CellContext<TFeatures, TData, TValue>\n table: CellContext<TFeatures, TData, TValue>['table']\n column: CellContext<TFeatures, TData, TValue>['column']\n row: CellContext<TFeatures, TData, TValue>['row']\n cell: CellContext<TFeatures, TData, TValue>['cell']\n /** The cell's value. */\n getValue: CellContext<TFeatures, TData, TValue>['getValue']\n /** The cell's value, or the table's `renderFallbackValue` where it has none. */\n renderValue: CellContext<TFeatures, TData, TValue>['renderValue']\n}\n\n/** The arguments a component in a column's `header` or `footer` gets. */\nexport interface HeaderComponentArgs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** The whole context, as table-core's `header.getContext()` makes it. */\n context: HeaderContext<TFeatures, TData, TValue>\n table: HeaderContext<TFeatures, TData, TValue>['table']\n column: HeaderContext<TFeatures, TData, TValue>['column']\n header: HeaderContext<TFeatures, TData, TValue>['header']\n}\n\n/** A component for a column's `cell`: `cell: flexComponent(StatusCell)`. */\nexport interface CellComponentSignature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n Args: CellComponentArgs<TFeatures, TData, TValue>\n}\n\n/** A component for a column's `header` or `footer`: `header: flexComponent(SelectAll)`. */\nexport interface HeaderComponentSignature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n Args: HeaderComponentArgs<TFeatures, TData, TValue>\n}\n\ntype AnyContext = Record<string, unknown>\ntype Rendered = ComponentLike<{ Args: Record<string, unknown> }>\n\n/** Whether a value is a component: one with a template, or a class (whose template it inherits). */\nexport function isComponent(value: unknown): value is Rendered {\n if (!isObject(value)) return false\n return (\n getComponentTemplate(value as object) !== undefined ||\n (isFunction(value) && /^class[\\s{]/.test(Function.prototype.toString.call(value)))\n )\n}\n\n/**\n * A column's `header`, `cell` or `footer` as a component: `cell: flexComponent(StatusCell)`.\n * The component gets the context and each of its members as arguments (`@row`, `@column`,\n * `@table`… see `CellComponentArgs` and `HeaderComponentArgs`). table-core's types take a\n * string or a function there, so this hands it a function that returns the component, which\n * `FlexRender` renders. It takes any context, since table-core checks a column's template\n * against the column's own value type.\n */\nexport function flexComponent(component: object): (context: any) => unknown {\n return () => component\n}\n\n/** What a FlexRender draws: a component with its arguments, or a value as text. */\ninterface Resolved {\n component?: Rendered\n args?: AnyContext\n text?: string | number | SafeString\n}\n\n/** `null`, `undefined` and booleans draw nothing, as in React; anything else draws as text. */\nfunction drawable(value: unknown): string | number | SafeString | undefined {\n if (value === null || value === undefined || isBoolean(value)) return undefined\n if (isString(value) || isNumber(value) || isHTMLSafe(value)) {\n return value as string | number | SafeString\n }\n return String(value)\n}\n\nfunction resolve(template: unknown, given: object): Resolved {\n const context = given as AnyContext\n if (template === null || template === undefined) return {}\n if (isComponent(template)) return { component: template, args: context }\n if (isFunction(template)) {\n const result: unknown = (template as (context: AnyContext) => unknown)(context)\n if (isComponent(result)) return { component: result, args: context }\n return { text: drawable(result) }\n }\n return { text: drawable(template) }\n}\n\nexport interface FlexRenderSignature {\n Args: {\n /** A body cell: renders its column's `cell` (or `aggregatedCell`) with the cell's context. */\n cell?: FlexCell\n /** A header: renders its column's `header` with the header's context. */\n header?: FlexHeader\n /** A footer: renders its column's `footer` with the header's context. */\n footer?: FlexHeader\n }\n}\n\n/**\n * Renders a header, cell or footer from its column definition, as TanStack's `FlexRender`\n * does in React: give it one of `@cell`, `@header` or `@footer`. The column's template may be a\n * string, a function of the context (returning a string, a number, or a component), or a\n * component, which gets the context's members as arguments.\n *\n * <t.Head><FlexRender @header={{header}} /></t.Head>\n * <t.Cell><FlexRender @cell={{cell}} /></t.Cell>\n *\n * Every table `createTable()` makes carries it too, as `table.FlexRender`, as upstream's does.\n * A placeholder cell (from column grouping) renders nothing.\n */\nexport default class FlexRender extends Component<FlexRenderSignature> {\n get resolved(): Resolved {\n const { cell, header, footer } = this.args\n if (cell) {\n const definition = cell.column.columnDef as { cell?: unknown; aggregatedCell?: unknown }\n if (cell.getIsAggregated?.()) {\n return resolve(definition.aggregatedCell ?? definition.cell, cell.getContext())\n }\n if (cell.getIsPlaceholder?.()) return {}\n return resolve(definition.cell, cell.getContext())\n }\n if (header) {\n return resolve((header.column.columnDef as { header?: unknown }).header, header.getContext())\n }\n if (footer) {\n return resolve((footer.column.columnDef as { footer?: unknown }).footer, footer.getContext())\n }\n return {}\n }\n\n // The whitespace control (~) leaves nothing around what it renders, as React's does.\n <template>\n {{~#let this.resolved as |r|~}}\n {{~#if r.component~}}\n <r.component\n @context={{r.args}}\n @table={{r.args.table}}\n @column={{r.args.column}}\n @header={{r.args.header}}\n @row={{r.args.row}}\n @cell={{r.args.cell}}\n @getValue={{r.args.getValue}}\n @renderValue={{r.args.renderValue}}\n />\n {{~else~}}\n {{r.text}}\n {{~/if~}}\n {{~/let~}}\n </template>\n}\n"],"names":["isComponent","value","isObject","getComponentTemplate","undefined","isFunction","test","Function","prototype","toString","call","flexComponent","component","drawable","isBoolean","isString","isNumber","isHTMLSafe","String","resolve","template","given","context","args","result","text","FlexRender","Component","resolved","cell","header","footer","definition","column","columnDef","getIsAggregated","aggregatedCell","getContext","getIsPlaceholder","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;AAwBA;AAMA;;;AAGC;AAkBD;AAaA;AASA;AAYA,oGACO,SAASA,YAAYC,KAAc,EAAY;AACpD,EAAA,IAAI,CAACC,QAAA,CAASD,KAAA,CAAA,EAAQ,OAAO,KAAA;EAC7B,OACEE,qBAAqBF,KAAe,MAAMG,SAAA,IACzCC,WAAWJ,KAAA,CAAA,IAAU,aAAA,CAAcK,IAAI,CAACC,QAAA,CAASC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACT,OAC5E;AACF;AAEA;;;;;;;;AAQO,SAASU,aAAAA,CAAcC,SAAiB,EAA4B;AACzE,EAAA,OAAO,MAAMA,SAAA;AACf;AAEA;;AAOA,+FACA,SAASC,QAAAA,CAASZ,KAAc,EAA2C;AACzE,EAAA,IAAIA,UAAU,IAAA,IAAQA,KAAA,KAAUG,SAAA,IAAaU,SAAA,CAAUb,QAAQ,OAAOG,SAAA;AACtE,EAAA,IAAIW,QAAA,CAASd,KAAA,CAAA,IAAUe,QAAA,CAASf,KAAA,CAAA,IAAUgB,WAAWhB,KAAA,CAAA,EAAQ;AAC3D,IAAA,OAAOA,KAAA;AACT,EAAA;EACA,OAAOiB,MAAA,CAAOjB,KAAA,CAAA;AAChB;AAEA,SAASkB,QAAQC,QAAiB,EAAEC,KAAa,EAAG;EAClD,MAAMC,UAAUD,KAAS;EACzB,IAAID,QAAA,KAAa,IAAA,IAAQA,QAAA,KAAahB,SAAA,EAAW,OAAO,EAAC;AACzD,EAAA,IAAIJ,WAAA,CAAYoB,WAAW,OAAO;AAAER,IAAAA,SAAA,EAAWQ,QAAA;AAAUG,IAAAA,IAAA,EAAMD;GAAQ;AACvE,EAAA,IAAIjB,WAAWe,QAAA,CAAA,EAAW;AACxB,IAAA,MAAMI,MAAe,GAAIJ,SAA8CE,OAAA,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kVAAA,EAiBA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { default as DataTable, ariaSort } from './components/data-table.js';
2
+ export { default as FlexRender, flexComponent, isComponent } from './components/flex-render.js';
3
+ export * from '@tanstack/table-core';
4
+ export { TrackedState, createTable, emberReactivity, tableState } from './table.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/table-core';
2
+ //# sourceMappingURL=table-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-core.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/dist/table.js ADDED
@@ -0,0 +1,300 @@
1
+ import { isFunction } from '@sindresorhus/is';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { createCache, getValue } from '@glimmer/tracking/primitives/cache';
4
+ import { functionalUpdate, constructTable } from '@tanstack/table-core';
5
+ import FlexRender from './components/flex-render.js';
6
+ import { buildWaiter } from '@ember/test-waiters';
7
+ import { g, i } from 'decorator-transforms/runtime';
8
+
9
+ /**
10
+ * Makes each method on a table-core prototype (a row's, cell's, column's or header's) come back
11
+ * bound to the instance it is read from, the first time it is read there.
12
+ *
13
+ * table-core v9 shares one prototype per kind, and its methods read `this`. Ember's templates
14
+ * call a function without the object it came from (`{{(row.getIsSelected)}}`,
15
+ * `@onCheckedChange={{row.toggleSelected}}`), so an unbound method would lose its row. The
16
+ * bound copy is kept on the instance, not enumerable, so table-core's copies of a row (the
17
+ * sorted row model clones rows through their own enumerable properties) bind their own.
18
+ */
19
+ function bindMethods(prototype) {
20
+ for (const key of Object.keys(prototype)) {
21
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
22
+ const method = descriptor?.value;
23
+ if (!isFunction(method)) continue;
24
+ Object.defineProperty(prototype, key, {
25
+ configurable: true,
26
+ enumerable: descriptor.enumerable ?? true,
27
+ get() {
28
+ if (this === prototype) return method;
29
+ const bound = (...args) => method.apply(this, args);
30
+ Object.defineProperty(this, key, {
31
+ value: bound,
32
+ configurable: true,
33
+ writable: true
34
+ });
35
+ return bound;
36
+ },
37
+ set(value) {
38
+ Object.defineProperty(this, key, {
39
+ value,
40
+ configurable: true,
41
+ enumerable: true,
42
+ writable: true
43
+ });
44
+ }
45
+ });
46
+ }
47
+ }
48
+
49
+ /**
50
+ * A table feature, registered after every other, that binds the prototype methods the others
51
+ * assigned (see `bindMethods`). The table's own methods are closures already.
52
+ */
53
+ const boundMethodsFeature = {
54
+ assignRowPrototype: bindMethods,
55
+ assignCellPrototype: bindMethods,
56
+ assignColumnPrototype: bindMethods,
57
+ assignHeaderPrototype: bindMethods
58
+ };
59
+
60
+ /** How deep `untrack()` calls are nested: inside one, atoms are read without being tracked. */
61
+ let untracking = 0;
62
+
63
+ /** `settled()` waits for the work table-core puts off until after a render (its auto-resets). */
64
+ const waiter = buildWaiter('@ember-joinery/data-table:scheduled');
65
+ const notify = (listener, value) => isFunction(listener) ? listener(value) : listener.next?.(value);
66
+
67
+ /**
68
+ * A writable atom on Ember's autotracking: reading `get()` in a template or getter tracks it,
69
+ * and `set()` re-renders what read it. Table state (`table.baseAtoms`) lives in these.
70
+ */
71
+ class TrackedAtom {
72
+ static {
73
+ g(this.prototype, "current", [tracked]);
74
+ }
75
+ #current = (i(this, "current"), void 0);
76
+ /** The same value, read where nothing may track it (`untrack()`, and `set`'s updater). */
77
+ #raw;
78
+ #compare;
79
+ #listeners = new Set();
80
+ constructor(value, compare = Object.is) {
81
+ this.current = value;
82
+ this.#raw = value;
83
+ this.#compare = compare;
84
+ }
85
+ get = () => untracking > 0 ? this.#raw : this.current;
86
+ set = updater => {
87
+ const next = isFunction(updater) ? updater(this.#raw) : updater;
88
+ if (this.#compare(this.#raw, next)) return;
89
+ this.#raw = next;
90
+ this.current = next;
91
+ for (const listener of this.#listeners) notify(listener, next);
92
+ };
93
+ subscribe = listener => {
94
+ this.#listeners.add(listener);
95
+ return {
96
+ unsubscribe: () => void this.#listeners.delete(listener)
97
+ };
98
+ };
99
+ }
100
+
101
+ /**
102
+ * A derived atom: `get()` computes it afresh each time, so whatever it reads is tracked where it
103
+ * is read, and keeps handing back the same value while `compare` finds the new one equal (the
104
+ * table's `store` snapshot compares shallowly), so table-core's memos see stable references.
105
+ */
106
+ function derivedAtom(compute, compare = Object.is) {
107
+ let hasValue = false;
108
+ let value;
109
+ return {
110
+ get() {
111
+ const next = compute();
112
+ if (!hasValue || !compare(value, next)) {
113
+ value = next;
114
+ hasValue = true;
115
+ }
116
+ return value;
117
+ },
118
+ subscribe() {
119
+ throw new Error('Joinery data table: a derived table atom has no subscriptions in Ember. Read it (`table.store.state`, `table.atoms.<slice>.get()`) in a template or getter instead: autotracking re-renders what reads it.');
120
+ }
121
+ };
122
+ }
123
+
124
+ /**
125
+ * TanStack Table's reactivity bindings for Ember, which `createTable()` gives every table: its
126
+ * state lives in tracked atoms, so a template or getter that reads the table (a row model, a
127
+ * column's sort, `table.store.state`) re-renders when that state changes, and nothing else
128
+ * does. Pass them yourself to table-core's `constructTable()` as `coreReactivityFeature`.
129
+ */
130
+ function emberReactivity() {
131
+ return {
132
+ // Options come from the function `createTable()` is given, read through a tracked cache.
133
+ createOptionsStore: false,
134
+ wrapExternalAtoms: false,
135
+ addSubscription: () => {
136
+ throw new Error('Joinery data table: external atoms are not supported in Ember');
137
+ },
138
+ unmount: () => {},
139
+ batch: fn => fn(),
140
+ untrack(fn) {
141
+ untracking += 1;
142
+ try {
143
+ return fn();
144
+ } finally {
145
+ untracking -= 1;
146
+ }
147
+ },
148
+ // After the render that asked for it: an auto-reset writes state the render has read.
149
+ schedule(fn) {
150
+ const token = waiter.beginAsync();
151
+ queueMicrotask(() => {
152
+ try {
153
+ fn();
154
+ } finally {
155
+ waiter.endAsync(token);
156
+ }
157
+ });
158
+ },
159
+ createWritableAtom: (value, options) => new TrackedAtom(value, options?.compare),
160
+ createReadonlyAtom: (fn, options) => derivedAtom(fn, options?.compare)
161
+ };
162
+ }
163
+
164
+ /**
165
+ * A TanStack table made by `createTable()`: table-core's table, whose state is tracked, with
166
+ * `FlexRender` on it (`<this.table.FlexRender @cell={{cell}} />`, as upstream's
167
+ * `<table.FlexRender cell={cell} />`) and its whole state as `state`.
168
+ */
169
+
170
+ /** The table options `createTable()` takes, or a function that returns them. */
171
+
172
+ /** The options `table.setOptions()` changed, kept above the ones the function gives. */
173
+ class Overrides {
174
+ static {
175
+ g(this.prototype, "value", [tracked], function () {
176
+ return {};
177
+ });
178
+ }
179
+ #value = (i(this, "value"), void 0);
180
+ }
181
+
182
+ /**
183
+ * Makes a TanStack table that Ember tracks: shadcn's `useTable`, in Ember. Its state (sorting,
184
+ * filters, pagination, selection, visibility…) is tracked, so a template or getter that reads
185
+ * the table re-renders when what it read changes, and nothing else does.
186
+ *
187
+ * import { createTable, tableFeatures, rowSortingFeature, createSortedRowModel, … } from
188
+ * '@ember-joinery/data-table'
189
+ *
190
+ * const features = tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel() })
191
+ *
192
+ * class Payments extends Component {
193
+ * table = createTable(() => ({ features, columns, data: this.args.payments }))
194
+ * }
195
+ *
196
+ * Give it a function, as above, and it reads the options again whenever something the function
197
+ * read changes (`this.args.payments`, a `tableState()` value): that is how `data` and controlled
198
+ * `state` follow your component. Give it an object for options that never change. `features`
199
+ * is read once, when the table is made.
200
+ *
201
+ * Without `state`, the table keeps its own (`initialState` sets where it starts). To own a slice
202
+ * yourself, as upstream's examples own theirs with `useState`, pass it in `state` with its
203
+ * `on<Slice>Change`, from a `tableState()`.
204
+ *
205
+ * Templates can call the table's methods (`{{#each (this.table.getHeaderGroups) …}}`), and the
206
+ * methods of its rows, cells, columns and headers too (`{{(row.getIsSelected)}}`,
207
+ * `@onCheckedChange={{row.toggleSelected}}`): they come bound to their own object.
208
+ */
209
+ function createTable(options) {
210
+ const read = isFunction(options) ? options : () => options;
211
+ const initial = read();
212
+ const features = {
213
+ coreReactivityFeature: emberReactivity(),
214
+ ...initial.features,
215
+ // Last, so it sees the methods every other feature put on the prototypes.
216
+ boundMethodsFeature
217
+ };
218
+ const table = constructTable({
219
+ ...initial,
220
+ features
221
+ });
222
+
223
+ // What constructTable() merged under the options: each feature's defaults (the
224
+ // `on<Slice>Change` that write the table's own state, and the like).
225
+ const defaults = {};
226
+ for (const feature of Object.values(table._features)) {
227
+ Object.assign(defaults, feature.getDefaultTableOptions?.(table));
228
+ }
229
+ // As table-core's own merge does, these keep the values the table was made with.
230
+ const fixed = {
231
+ features: table.options['features'],
232
+ atoms: initial.atoms,
233
+ initialState: initial.initialState
234
+ };
235
+ const overrides = new Overrides();
236
+ const resolved = createCache(() => ({
237
+ ...defaults,
238
+ ...read(),
239
+ ...overrides.value,
240
+ ...fixed
241
+ }));
242
+ Object.defineProperty(table, 'options', {
243
+ configurable: true,
244
+ enumerable: true,
245
+ get: () => getValue(resolved),
246
+ // `table.setOptions()` hands over the whole set: keep what it changed.
247
+ set(next) {
248
+ const current = getValue(resolved) ?? {};
249
+ const changed = {
250
+ ...overrides.value
251
+ };
252
+ for (const [key, value] of Object.entries(next)) {
253
+ if (current[key] !== value) changed[key] = value;
254
+ }
255
+ overrides.value = changed;
256
+ }
257
+ });
258
+ Object.defineProperty(table, 'state', {
259
+ configurable: true,
260
+ enumerable: true,
261
+ get: () => table.store.get()
262
+ });
263
+ table.FlexRender = FlexRender;
264
+ return table;
265
+ }
266
+
267
+ /**
268
+ * A slice of table state you own, tracked: upstream's `React.useState` for a table. Pass its
269
+ * `value` in the table's `state` and its `set` as the slice's `on<Slice>Change`; `set` takes a
270
+ * value or an updater function, as table-core hands it either.
271
+ *
272
+ * sorting = tableState<SortingState>([])
273
+ * table = createTable(() => ({
274
+ * features, columns, data,
275
+ * onSortingChange: this.sorting.set,
276
+ * state: { sorting: this.sorting.value },
277
+ * }))
278
+ */
279
+ class TrackedState {
280
+ static {
281
+ g(this.prototype, "value", [tracked]);
282
+ }
283
+ #value = (i(this, "value"), void 0);
284
+ constructor(initial) {
285
+ this.value = initial;
286
+ }
287
+
288
+ /** Sets it to a value, or to what an updater makes of the current one. */
289
+ set = updater => {
290
+ this.value = functionalUpdate(updater, this.value);
291
+ };
292
+ }
293
+
294
+ /** A `TrackedState` that starts at `initial`. */
295
+ function tableState(initial) {
296
+ return new TrackedState(initial);
297
+ }
298
+
299
+ export { TrackedState, createTable, emberReactivity, tableState };
300
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sources":["../src/-private/bound-methods.ts","../src/-private/reactivity.ts","../src/table.ts"],"sourcesContent":["import { isFunction } from '@sindresorhus/is'\n/**\n * Makes each method on a table-core prototype (a row's, cell's, column's or header's) come back\n * bound to the instance it is read from, the first time it is read there.\n *\n * table-core v9 shares one prototype per kind, and its methods read `this`. Ember's templates\n * call a function without the object it came from (`{{(row.getIsSelected)}}`,\n * `@onCheckedChange={{row.toggleSelected}}`), so an unbound method would lose its row. The\n * bound copy is kept on the instance, not enumerable, so table-core's copies of a row (the\n * sorted row model clones rows through their own enumerable properties) bind their own.\n */\nfunction bindMethods(prototype: object): void {\n for (const key of Object.keys(prototype)) {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, key)\n const method: unknown = descriptor?.value\n if (!isFunction(method)) continue\n Object.defineProperty(prototype, key, {\n configurable: true,\n enumerable: descriptor!.enumerable ?? true,\n get(this: object) {\n if (this === prototype) return method\n const bound = (...args: unknown[]) =>\n (method as (...a: unknown[]) => unknown).apply(this, args)\n Object.defineProperty(this, key, { value: bound, configurable: true, writable: true })\n return bound\n },\n set(this: object, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n configurable: true,\n enumerable: true,\n writable: true,\n })\n },\n })\n }\n}\n\n/**\n * A table feature, registered after every other, that binds the prototype methods the others\n * assigned (see `bindMethods`). The table's own methods are closures already.\n */\nexport const boundMethodsFeature = {\n assignRowPrototype: bindMethods,\n assignCellPrototype: bindMethods,\n assignColumnPrototype: bindMethods,\n assignHeaderPrototype: bindMethods,\n}\n","import { isFunction } from '@sindresorhus/is'\nimport { tracked } from '@glimmer/tracking'\nimport { buildWaiter } from '@ember/test-waiters'\nimport type { TableReactivityBindings } from '@tanstack/table-core/reactivity'\n\n/** How deep `untrack()` calls are nested: inside one, atoms are read without being tracked. */\nlet untracking = 0\n\n/** `settled()` waits for the work table-core puts off until after a render (its auto-resets). */\nconst waiter = buildWaiter('@ember-joinery/data-table:scheduled')\n\ntype Observer<T> = { next?: (value: T) => void }\ntype Listener<T> = Observer<T> | ((value: T) => void)\ntype Subscription = { unsubscribe: () => void }\n\nconst notify = <T>(listener: Listener<T>, value: T): void =>\n isFunction(listener) ? listener(value) : listener.next?.(value)\n\n/**\n * A writable atom on Ember's autotracking: reading `get()` in a template or getter tracks it,\n * and `set()` re-renders what read it. Table state (`table.baseAtoms`) lives in these.\n */\nclass TrackedAtom<T> {\n @tracked private current: T\n /** The same value, read where nothing may track it (`untrack()`, and `set`'s updater). */\n #raw: T\n readonly #compare: (previous: T, next: T) => boolean\n readonly #listeners = new Set<Listener<T>>()\n\n constructor(value: T, compare: (previous: T, next: T) => boolean = Object.is) {\n this.current = value\n this.#raw = value\n this.#compare = compare\n }\n\n get = (): T => (untracking > 0 ? this.#raw : this.current)\n\n set = (updater: T | ((previous: T) => T)): void => {\n const next = isFunction(updater) ? (updater as (previous: T) => T)(this.#raw) : updater\n if (this.#compare(this.#raw, next)) return\n this.#raw = next\n this.current = next\n for (const listener of this.#listeners) notify(listener, next)\n }\n\n subscribe = (listener: Listener<T>): Subscription => {\n this.#listeners.add(listener)\n return { unsubscribe: () => void this.#listeners.delete(listener) }\n }\n}\n\n/**\n * A derived atom: `get()` computes it afresh each time, so whatever it reads is tracked where it\n * is read, and keeps handing back the same value while `compare` finds the new one equal (the\n * table's `store` snapshot compares shallowly), so table-core's memos see stable references.\n */\nfunction derivedAtom<T>(compute: () => T, compare: (previous: T, next: T) => boolean = Object.is) {\n let hasValue = false\n let value: T\n return {\n get(): T {\n const next = compute()\n if (!hasValue || !compare(value, next)) {\n value = next\n hasValue = true\n }\n return value\n },\n subscribe(): Subscription {\n throw new Error(\n 'Joinery data table: a derived table atom has no subscriptions in Ember. Read it (`table.store.state`, `table.atoms.<slice>.get()`) in a template or getter instead: autotracking re-renders what reads it.',\n )\n },\n }\n}\n\n/**\n * TanStack Table's reactivity bindings for Ember, which `createTable()` gives every table: its\n * state lives in tracked atoms, so a template or getter that reads the table (a row model, a\n * column's sort, `table.store.state`) re-renders when that state changes, and nothing else\n * does. Pass them yourself to table-core's `constructTable()` as `coreReactivityFeature`.\n */\nexport function emberReactivity(): TableReactivityBindings {\n return {\n // Options come from the function `createTable()` is given, read through a tracked cache.\n createOptionsStore: false,\n wrapExternalAtoms: false,\n addSubscription: () => {\n throw new Error('Joinery data table: external atoms are not supported in Ember')\n },\n unmount: () => {},\n batch: fn => fn(),\n untrack<T>(fn: () => T): T {\n untracking += 1\n try {\n return fn()\n } finally {\n untracking -= 1\n }\n },\n // After the render that asked for it: an auto-reset writes state the render has read.\n schedule(fn) {\n const token = waiter.beginAsync()\n queueMicrotask(() => {\n try {\n fn()\n } finally {\n waiter.endAsync(token)\n }\n })\n },\n createWritableAtom: (value, options) => new TrackedAtom(value, options?.compare) as never,\n createReadonlyAtom: (fn, options) => derivedAtom(fn, options?.compare) as never,\n }\n}\n","import { isFunction } from '@sindresorhus/is'\nimport { tracked } from '@glimmer/tracking'\nimport { createCache, getValue } from '@glimmer/tracking/primitives/cache'\nimport {\n constructTable,\n functionalUpdate,\n type RowData,\n type Table,\n type TableFeatures,\n type TableOptions,\n type TableState,\n type Updater,\n} from '@tanstack/table-core'\nimport FlexRender from './components/flex-render.gts'\nimport { boundMethodsFeature } from './-private/bound-methods.ts'\nimport { emberReactivity } from './-private/reactivity.ts'\n\nexport { emberReactivity } from './-private/reactivity.ts'\n\n/**\n * A TanStack table made by `createTable()`: table-core's table, whose state is tracked, with\n * `FlexRender` on it (`<this.table.FlexRender @cell={{cell}} />`, as upstream's\n * `<table.FlexRender cell={cell} />`) and its whole state as `state`.\n */\nexport type EmberTable<TFeatures extends TableFeatures, TData extends RowData> = Table<\n TFeatures,\n TData\n> & {\n /** `FlexRender`, so a template that has the table needs no import of its own. */\n FlexRender: typeof FlexRender\n /** The table's whole state, every slice its features hold (`table.store.state`). Tracked. */\n readonly state: TableState<TFeatures>\n}\n\n/** The table options `createTable()` takes, or a function that returns them. */\nexport type EmberTableOptions<TFeatures extends TableFeatures, TData extends RowData> =\n TableOptions<TFeatures, TData> | (() => TableOptions<TFeatures, TData>)\n\ninterface Internals {\n _features: Record<string, { getDefaultTableOptions?: (table: unknown) => object }>\n options: Record<string, unknown>\n}\n\n/** The options `table.setOptions()` changed, kept above the ones the function gives. */\nclass Overrides {\n @tracked value: Record<string, unknown> = {}\n}\n\n/**\n * Makes a TanStack table that Ember tracks: shadcn's `useTable`, in Ember. Its state (sorting,\n * filters, pagination, selection, visibility…) is tracked, so a template or getter that reads\n * the table re-renders when what it read changes, and nothing else does.\n *\n * import { createTable, tableFeatures, rowSortingFeature, createSortedRowModel, … } from\n * '@ember-joinery/data-table'\n *\n * const features = tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel() })\n *\n * class Payments extends Component {\n * table = createTable(() => ({ features, columns, data: this.args.payments }))\n * }\n *\n * Give it a function, as above, and it reads the options again whenever something the function\n * read changes (`this.args.payments`, a `tableState()` value): that is how `data` and controlled\n * `state` follow your component. Give it an object for options that never change. `features`\n * is read once, when the table is made.\n *\n * Without `state`, the table keeps its own (`initialState` sets where it starts). To own a slice\n * yourself, as upstream's examples own theirs with `useState`, pass it in `state` with its\n * `on<Slice>Change`, from a `tableState()`.\n *\n * Templates can call the table's methods (`{{#each (this.table.getHeaderGroups) …}}`), and the\n * methods of its rows, cells, columns and headers too (`{{(row.getIsSelected)}}`,\n * `@onCheckedChange={{row.toggleSelected}}`): they come bound to their own object.\n */\nexport function createTable<TFeatures extends TableFeatures, TData extends RowData>(\n options: EmberTableOptions<TFeatures, TData>,\n): EmberTable<TFeatures, TData> {\n const read = isFunction(options) ? options : () => options\n const initial = read()\n const features = {\n coreReactivityFeature: emberReactivity(),\n ...initial.features,\n // Last, so it sees the methods every other feature put on the prototypes.\n boundMethodsFeature,\n }\n\n const table = constructTable({ ...initial, features } as unknown as TableOptions<\n TFeatures,\n TData\n >) as unknown as EmberTable<TFeatures, TData> & Internals\n\n // What constructTable() merged under the options: each feature's defaults (the\n // `on<Slice>Change` that write the table's own state, and the like).\n const defaults: Record<string, unknown> = {}\n for (const feature of Object.values(table._features)) {\n Object.assign(defaults, feature.getDefaultTableOptions?.(table))\n }\n // As table-core's own merge does, these keep the values the table was made with.\n const fixed = {\n features: table.options['features'],\n atoms: initial.atoms,\n initialState: initial.initialState,\n }\n const overrides = new Overrides()\n const resolved = createCache((): Record<string, unknown> => ({\n ...defaults,\n ...(read() as Record<string, unknown>),\n ...overrides.value,\n ...fixed,\n }))\n\n Object.defineProperty(table, 'options', {\n configurable: true,\n enumerable: true,\n get: () => getValue(resolved),\n // `table.setOptions()` hands over the whole set: keep what it changed.\n set(next: Record<string, unknown>) {\n const current = getValue(resolved) ?? {}\n const changed: Record<string, unknown> = { ...overrides.value }\n for (const [key, value] of Object.entries(next)) {\n if (current[key] !== value) changed[key] = value\n }\n overrides.value = changed\n },\n })\n Object.defineProperty(table, 'state', {\n configurable: true,\n enumerable: true,\n get: () => table.store.get(),\n })\n table.FlexRender = FlexRender\n return table\n}\n\n/**\n * A slice of table state you own, tracked: upstream's `React.useState` for a table. Pass its\n * `value` in the table's `state` and its `set` as the slice's `on<Slice>Change`; `set` takes a\n * value or an updater function, as table-core hands it either.\n *\n * sorting = tableState<SortingState>([])\n * table = createTable(() => ({\n * features, columns, data,\n * onSortingChange: this.sorting.set,\n * state: { sorting: this.sorting.value },\n * }))\n */\nexport class TrackedState<T> {\n @tracked value: T\n\n constructor(initial: T) {\n this.value = initial\n }\n\n /** Sets it to a value, or to what an updater makes of the current one. */\n set = (updater: Updater<T>): void => {\n this.value = functionalUpdate(updater, this.value)\n }\n}\n\n/** A `TrackedState` that starts at `initial`. */\nexport function tableState<T>(initial: T): TrackedState<T> {\n return new TrackedState(initial)\n}\n"],"names":["bindMethods","prototype","key","Object","keys","descriptor","getOwnPropertyDescriptor","method","value","isFunction","defineProperty","configurable","enumerable","get","bound","args","apply","writable","set","boundMethodsFeature","assignRowPrototype","assignCellPrototype","assignColumnPrototype","assignHeaderPrototype","untracking","waiter","buildWaiter","notify","listener","next","TrackedAtom","g","tracked","i","Set","constructor","compare","is","current","updater","subscribe","add","unsubscribe","delete","derivedAtom","compute","hasValue","Error","emberReactivity","createOptionsStore","wrapExternalAtoms","addSubscription","unmount","batch","fn","untrack","schedule","token","beginAsync","queueMicrotask","endAsync","createWritableAtom","options","createReadonlyAtom","Overrides","createTable","read","initial","features","coreReactivityFeature","table","constructTable","defaults","feature","values","_features","assign","getDefaultTableOptions","fixed","atoms","initialState","overrides","resolved","createCache","getValue","changed","entries","store","FlexRender","TrackedState","functionalUpdate","tableState"],"mappings":";;;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAWA,CAACC,SAAiB,EAAQ;EAC5C,KAAK,MAAMC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACH,SAAS,CAAC,EAAE;IACxC,MAAMI,UAAU,GAAGF,MAAM,CAACG,wBAAwB,CAACL,SAAS,EAAEC,GAAG,CAAC;AAClE,IAAA,MAAMK,MAAe,GAAGF,UAAU,EAAEG,KAAK;AACzC,IAAA,IAAI,CAACC,UAAU,CAACF,MAAM,CAAC,EAAE;AACzBJ,IAAAA,MAAM,CAACO,cAAc,CAACT,SAAS,EAAEC,GAAG,EAAE;AACpCS,MAAAA,YAAY,EAAE,IAAI;AAClBC,MAAAA,UAAU,EAAEP,UAAU,CAAEO,UA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