@ember-lattice/state 0.0.0-stage → 1.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # @ember-lattice/state
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 7ce4af2: Lattice 1.0: one grid for every collection in Ember. Lists, feeds, tables, boards and
8
+ spreadsheets come from one headless engine, a port of TanStack Table. It has 80 of the 81
9
+ AG Grid features in the parity matrix; the external filter runs after grouping. The release has the client row models, the Lattice wire protocol with servers for Node,
10
+ Rails and Python, an IronCalc spreadsheet with live collaboration, themes, test harnesses, Jig
11
+ stories and Marquetry catalog entries.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [7ce4af2]
16
+ - @ember-lattice/core@1.0.0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ Lattice
2
+ Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
3
+
4
+ Lattice ports code from two MIT-licensed TanStack projects into Ember-native code. Lattice does
5
+ not depend on either package. PORT_MAP.md names each ported file and its source.
6
+
7
+ TanStack Table (@tanstack/table-core 9.3.1)
8
+ https://github.com/TanStack/table
9
+ Copyright (c) 2016 Tanner Linsley
10
+
11
+ TanStack Virtual (@tanstack/virtual-core 3.19.16)
12
+ https://github.com/TanStack/virtual
13
+ Copyright (c) 2021-present Tanner Linsley
14
+
15
+ Both are licensed under the MIT License:
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
18
+ and associated documentation files (the "Software"), to deal in the Software without
19
+ restriction, including without limitation the rights to use, copy, modify, merge, publish,
20
+ distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
21
+ Software is furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all copies or
24
+ substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
27
+ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,110 @@
1
- # Temporary Holding Version
1
+ # @ember-lattice/state
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Grid state that lasts. This package keeps the state of a Lattice grid in the URL, in
4
+ localStorage and in saved views on a server. All stores use one `StateStore` interface.
5
+
6
+ Part of [Lattice](https://joegaudet.com/ember-lattice/). Not released yet.
7
+
8
+ ## The state
9
+
10
+ `gridState(table, host?)` reads the state as JSON. `applyGridState(table, state, host?)` sets it
11
+ back. The state has these keys:
12
+
13
+ | Key | Owner |
14
+ | ------------------ | --------------------------- |
15
+ | `v` | The schema version. |
16
+ | `columnOrder` | The table. |
17
+ | `columnPinning` | The table. |
18
+ | `columnSizing` | The table. |
19
+ | `columnVisibility` | The table. |
20
+ | `sorting` | The table. |
21
+ | `columnFilters` | The table. |
22
+ | `globalFilter` | The table. |
23
+ | `grouping` | The table. |
24
+ | `expanded` | The table. |
25
+ | `rowSelection` | The table. |
26
+ | `pagination` | The table. |
27
+ | `scroll` | The Grid, through the host. |
28
+ | `activeCell` | The Grid, through the host. |
29
+
30
+ The table has a key only when its feature is registered. The Grid gives its own keys through a
31
+ `GridStateHost`: `read()`, `apply(state)` and an optional `subscribe(listener)`.
32
+
33
+ ## Versions and migrations
34
+
35
+ Each state has a schema version, `v`. `migrate(state)` upgrades an old state one version at a
36
+ time. The entry `migrations[v]` changes a state from version `v` to version `v + 1`.
37
+
38
+ After the upgrade, `migrate` checks each key. It drops an unknown key or a key with a bad value,
39
+ and it shows a warning. It never drops the full state for one bad key. When the input is not a
40
+ state, `migrate` gives `undefined`. It never throws, because the input can come from a URL.
41
+
42
+ When you change the shape of a key, do these steps:
43
+
44
+ 1. Increase `SCHEMA_VERSION`.
45
+ 2. Add a migration from the old version.
46
+ 3. Add a test that upgrades a state of the old version.
47
+
48
+ ## Stores
49
+
50
+ A `StateStore` has `load(key)`, `save(key, state)` and an optional `subscribe(key, listener)`.
51
+
52
+ - `urlStore({ router? })` keeps the state in one query param. The name of the param is the store
53
+ key. The value is short and stable: JSON with one-letter keys and sorted keys, as base64url.
54
+ A typical state (column order, one sort, two filters, three hidden columns, three column
55
+ widths) is 346 characters.
56
+ - With the Ember router service, the store reads `router.currentRoute.queryParams` and writes
57
+ through `router.replaceWith`. The route must declare the query param, because Ember drops a
58
+ query param that no controller declares.
59
+ - Without a router, the store uses `location` and `history.replaceState`.
60
+ - `localStore({ prefix?, storage? })` keeps the state in localStorage. It never throws. When
61
+ storage is not available (private mode), is full or holds bad JSON, the store does nothing.
62
+ - `serverStore(source, { view? })` keeps saved views through an async `ViewSource`:
63
+ `listViews()`, `saveView(view)` and `deleteView(id)`.
64
+ - `save(key, state)` writes only the personal view. It never writes over a locked view.
65
+ - `saveView(key, { name, scope: 'shared', state })` saves a view for everyone. Only an explicit
66
+ call does this.
67
+ - To change a locked view, the call must set `locked`.
68
+
69
+ ## Precedence
70
+
71
+ `resolveState({ url, personal, shared, defaults })` gives the state to show. The first layer that
72
+ is available wins as a whole, in this order: URL, personal view, shared view. Its missing keys
73
+ come from the defaults, not from a lower layer. Thus a shared link shows the same grid to each
74
+ person.
75
+
76
+ ## Load and save
77
+
78
+ `persistGridState(table, { key, stores, host?, wait? })` loads the state from the first store
79
+ that has one. Then it saves each change to all stores, after a debounce (`wait`, 300 ms by
80
+ default). A store keeps only the keys that are different from the defaults. A store that
81
+ pushes a change (for example, the back button) applies it to the grid.
82
+
83
+ Call `persistGridState` before the grid renders. A sync store (URL, localStorage) then applies
84
+ before the first read of the table. An async store applies when it resolves. If the user changes
85
+ the grid before that, the change of the user wins. No save occurs during a render.
86
+
87
+ ```ts
88
+ import Component from '@glimmer/component'
89
+ import { registerDestructor } from '@ember/destroyable'
90
+ import { service } from '@ember/service'
91
+ import type RouterService from '@ember/routing/router-service'
92
+ import { localStore, persistGridState, urlStore } from '@ember-lattice/state'
93
+
94
+ export default class Orders extends Component {
95
+ @service declare router: RouterService
96
+ table = makeOrdersTable()
97
+
98
+ constructor(owner: unknown, args: object) {
99
+ super(owner, args)
100
+ const persist = persistGridState(this.table, {
101
+ key: 'orders',
102
+ stores: [urlStore({ router: this.router }), localStore()],
103
+ })
104
+ registerDestructor(this, () => persist.stop())
105
+ }
106
+ }
107
+ ```
108
+
109
+ In a test, use `await persist.flush()` to save at once. `settled()` does not wait for the
110
+ debounce timer.
package/addon-main.cjs ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict'
2
+
3
+ const { addonV1Shim } = require('@embroider/addon-shim')
4
+ module.exports = addonV1Shim(__dirname)
@@ -0,0 +1,61 @@
1
+ import type { ColumnFiltersState, ColumnPinningState, ColumnSizingState, ColumnVisibilityState, ExpandedState, GroupingState, PaginationState, RowSelectionState, SortingState } from '@ember-lattice/core';
2
+ /** The schema version of a `GridState`. Add a migration when you change the shape. */
3
+ export declare const SCHEMA_VERSION = 1;
4
+ export interface ScrollOffset {
5
+ top: number;
6
+ left: number;
7
+ }
8
+ export interface CellRef {
9
+ rowId: string;
10
+ columnId: string;
11
+ }
12
+ /** The state keys that the Grid owns, not the table. */
13
+ export interface HostState {
14
+ scroll?: ScrollOffset;
15
+ activeCell?: CellRef | null;
16
+ }
17
+ /**
18
+ * The Grid implements this to persist its own keys (scroll offset and active cell).
19
+ * `subscribe` is optional: without it, a change to these keys saves with the next table change.
20
+ */
21
+ export interface GridStateHost {
22
+ read(): HostState;
23
+ apply(state: HostState): void;
24
+ subscribe?(listener: () => void): () => void;
25
+ }
26
+ /** The persistable grid state as JSON. Each key is optional: a missing key keeps its default. */
27
+ export interface GridState extends HostState {
28
+ v: number;
29
+ columnOrder?: string[];
30
+ columnPinning?: ColumnPinningState;
31
+ columnSizing?: ColumnSizingState;
32
+ columnVisibility?: ColumnVisibilityState;
33
+ sorting?: SortingState;
34
+ columnFilters?: ColumnFiltersState;
35
+ globalFilter?: unknown;
36
+ grouping?: GroupingState;
37
+ expanded?: ExpandedState;
38
+ rowSelection?: RowSelectionState;
39
+ pagination?: PaginationState;
40
+ }
41
+ /** The table slices in a `GridState`. The table has a slice only when its feature is registered. */
42
+ export declare const TABLE_KEYS: readonly ["columnOrder", "columnPinning", "columnSizing", "columnVisibility", "sorting", "columnFilters", "globalFilter", "grouping", "expanded", "rowSelection", "pagination"];
43
+ export declare const HOST_KEYS: readonly ["scroll", "activeCell"];
44
+ /**
45
+ * The part of a Lattice table that this package uses. Any table from `constructTable` has it.
46
+ * The feature setters (`setSorting` and the others) are found by name at run time.
47
+ */
48
+ export interface TableLike {
49
+ readonly store: {
50
+ readonly state: object;
51
+ subscribe(listener: () => void): {
52
+ unsubscribe: () => void;
53
+ };
54
+ };
55
+ readonly atoms: object;
56
+ }
57
+ /** Reads the persistable state of `table` (and of `host`, when given) as JSON. */
58
+ export declare function gridState(table: TableLike, host?: GridStateHost): GridState;
59
+ /** Sets each key of `state` on `table` (and on `host`). A key the table has no feature for stays unused. */
60
+ export declare function applyGridState(table: TableLike, state: GridState, host?: GridStateHost): void;
61
+ //# sourceMappingURL=grid-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-state.d.ts","sourceRoot":"","sources":["../src/grid-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,YAAY,EACb,MAAM,qBAAqB,CAAA;AAE5B,sFAAsF;AACtF,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,IAAI,SAAS,CAAA;IACjB,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAA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';
2
+ export * from './migrate.ts';
3
+ export * from './stores.ts';
4
+ export * from './persist.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare function canonical(value: unknown): unknown;
2
+ export declare const sameJson: (a: unknown, b: unknown) => boolean;
3
+ export declare const consoleWarn: (message: string) => void;
4
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQjD;AAED,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,YACgB,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,SAA0B,CAAA"}
@@ -0,0 +1,20 @@
1
+ import type { GridState } from './grid-state.ts';
2
+ type Raw = Record<string, unknown>;
3
+ /** `migrations[v]` upgrades a state from version `v` to version `v + 1`. */
4
+ export type Migrations = Record<number, (state: Raw) => Raw>;
5
+ /** The migrations of this release. Version 1 is the first schema, so there is none yet. */
6
+ export declare const migrations: Migrations;
7
+ export interface MigrateOptions {
8
+ migrations?: Migrations;
9
+ version?: number;
10
+ /** Gets each dev warning. The default is `console.warn`. */
11
+ warn?: (message: string) => void;
12
+ }
13
+ /**
14
+ * Upgrades `input` to the current schema, one version at a time, then checks each key.
15
+ * An unknown key or a key with a bad value drops only that key, with a dev warning. A value
16
+ * that is not a state at all gives `undefined`. It never throws: the input can come from a URL.
17
+ */
18
+ export declare function migrate(input: unknown, options?: MigrateOptions): GridState | undefined;
19
+ export {};
20
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAElC,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,CAAA;AAE5D,2FAA2F;AAC3F,eAAO,MAAM,UAAU,EAAE,UAAe,CAAA;AAExC,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AA4CD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,SAAS,GAAG,SAAS,CA2B3F"}
@@ -0,0 +1,44 @@
1
+ import type { GridState, GridStateHost, TableLike } from './grid-state.ts';
2
+ import type { StateStore } from './stores.ts';
3
+ export interface StateLayers {
4
+ url?: GridState;
5
+ personal?: GridState;
6
+ shared?: GridState;
7
+ /** The column defaults: the state of the grid before any store loads. */
8
+ defaults: GridState;
9
+ }
10
+ /**
11
+ * The state to show. The first layer that is there wins as a whole: URL, then the personal
12
+ * view, then the shared view. Its missing keys come from the defaults, never from a lower
13
+ * layer, so a shared link shows the same grid to each person.
14
+ */
15
+ export declare function resolveState({ url, personal, shared, defaults }: StateLayers): GridState;
16
+ /** The keys of `state` that differ from `defaults`. A store keeps only these. */
17
+ export declare function withoutDefaults(state: GridState, defaults: GridState): GridState;
18
+ export interface PersistOptions {
19
+ /** The name of this grid's state in each store (the query param, for the URL store). */
20
+ key: string;
21
+ /** The stores, highest precedence first: for example URL, localStorage, server. */
22
+ stores: StateStore[];
23
+ /** The Grid, for its own keys (scroll offset and active cell). */
24
+ host?: GridStateHost;
25
+ /** The milliseconds to wait after the last change before a save. The default is 300. */
26
+ wait?: number;
27
+ warn?: (message: string) => void;
28
+ }
29
+ export interface Persistence {
30
+ /** Resolves when the load is done, also when an async store gave the state. */
31
+ ready: Promise<void>;
32
+ /** Saves a pending change now. */
33
+ flush(): Promise<void>;
34
+ /** Stops all saves and subscriptions. Call it when the grid goes away. */
35
+ stop(): void;
36
+ }
37
+ /**
38
+ * Loads the state of `table` from the first store that has one, and saves each change to all
39
+ * stores after a debounce. Call it before the grid renders: a sync store (URL, localStorage)
40
+ * then applies before the first read of the table, and an async store applies when it
41
+ * resolves. No save runs during a render, because each save waits for a timer.
42
+ */
43
+ export declare function persistGridState(table: TableLike, options: PersistOptions): Persistence;
44
+ //# sourceMappingURL=persist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../src/persist.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,SAAS,CAAA;IACf,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,yEAAyE;IACzE,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW,GAAG,SAAS,CAExF;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,CAOhF;AAED,MAAM,WAAW,cAAc;IAC7B,wFAAwF;IACxF,GAAG,EAAE,MAAM,CAAA;IACX,mFAAmF;IACnF,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB,kEAAkE;IAClE,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB,kCAAkC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,0EAA0E;IAC1E,IAAI,IAAI,IAAI,CAAA;CACb;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,GAAG,WAAW,CA+FvF"}
@@ -0,0 +1,120 @@
1
+ import type { GridState } from './grid-state.ts';
2
+ /** One place that keeps grid state. `load` can be sync (URL, localStorage) or async (server). */
3
+ export interface StateStore {
4
+ load(key: string): GridState | undefined | Promise<GridState | undefined>;
5
+ save(key: string, state: GridState): void | Promise<void>;
6
+ /** Calls `listener` when the state changes outside the grid (the back button, for example). */
7
+ subscribe?(key: string, listener: (state: GridState | undefined) => void): () => void;
8
+ }
9
+ interface WarnOption {
10
+ /** Gets each dev warning. The default is `console.warn`. */
11
+ warn?: (message: string) => void;
12
+ }
13
+ /**
14
+ * A short and stable string for `state`: JSON with one-letter top-level keys and sorted keys,
15
+ * as base64url with no padding.
16
+ */
17
+ export declare function encodeState(state: GridState): string;
18
+ /** The state in `text`, or `undefined` when the text is not a valid state. It never throws. */
19
+ export declare function decodeState(text: string, options?: WarnOption): GridState | undefined;
20
+ /** True when `state` has no key other than the version. */
21
+ export declare const isEmptyState: (state: GridState) => boolean;
22
+ /** The part of the Ember router service that `urlStore` uses. */
23
+ export interface RouterLike {
24
+ currentRoute?: {
25
+ queryParams: Record<string, unknown>;
26
+ } | null;
27
+ replaceWith(options: {
28
+ queryParams: Record<string, string | null>;
29
+ }): unknown;
30
+ on?(event: 'routeDidChange', listener: () => void): unknown;
31
+ off?(event: 'routeDidChange', listener: () => void): unknown;
32
+ }
33
+ /** The part of `window` that `urlStore` uses when there is no router. */
34
+ export interface WindowLike {
35
+ location: {
36
+ href: string;
37
+ };
38
+ history: {
39
+ state: unknown;
40
+ replaceState(state: unknown, unused: string, url: string): void;
41
+ };
42
+ addEventListener(type: 'popstate', listener: () => void): void;
43
+ removeEventListener(type: 'popstate', listener: () => void): void;
44
+ }
45
+ export interface UrlStoreOptions extends WarnOption {
46
+ /**
47
+ * The Ember router service. The route must declare the query param (the `key`), because
48
+ * Ember drops a query param that no controller declares.
49
+ */
50
+ router?: RouterLike;
51
+ /** The window to use when there is no router. The default is the global `window`. */
52
+ window?: WindowLike;
53
+ }
54
+ /**
55
+ * Keeps the state in one query param, named by the store key. The param holds the encoded
56
+ * state (see `encodeState`); a state with no key removes the param.
57
+ */
58
+ export declare function urlStore(options?: UrlStoreOptions): StateStore;
59
+ /** The part of `Storage` that `localStore` uses. */
60
+ export type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
61
+ export interface LocalStoreOptions extends WarnOption {
62
+ /** The default is `globalThis.localStorage`. A function is called on each use. */
63
+ storage?: StorageLike | (() => StorageLike);
64
+ /** The prefix of each storage key. The default is `lattice:`. */
65
+ prefix?: string;
66
+ }
67
+ /**
68
+ * Keeps the state in localStorage. It never throws: when storage is not there (private mode),
69
+ * is full (quota) or holds bad JSON, `load` gives `undefined` and `save` does nothing.
70
+ */
71
+ export declare function localStore(options?: LocalStoreOptions): StateStore;
72
+ export type ViewScope = 'personal' | 'shared';
73
+ /** A saved view. A shared view is for everyone; a locked view changes only by an explicit call. */
74
+ export interface SavedView {
75
+ id: string;
76
+ /** The grid that the view is for: the store key. */
77
+ key: string;
78
+ name: string;
79
+ scope: ViewScope;
80
+ locked?: boolean;
81
+ state: GridState;
82
+ }
83
+ /** The async views API of a data source. The server decides who can see a personal view. */
84
+ export interface ViewSource {
85
+ listViews(): Promise<SavedView[]>;
86
+ saveView(view: Omit<SavedView, 'id'> & {
87
+ id?: string;
88
+ }): Promise<SavedView>;
89
+ deleteView(id: string): Promise<void>;
90
+ }
91
+ export interface ViewInput {
92
+ name: string;
93
+ scope: ViewScope;
94
+ locked?: boolean;
95
+ state: GridState;
96
+ }
97
+ export interface ServerStore extends StateStore {
98
+ load(key: string): Promise<GridState | undefined>;
99
+ save(key: string, state: GridState): Promise<void>;
100
+ /** The personal and the shared view with the current view name. */
101
+ loadLayers(key: string): Promise<{
102
+ personal?: GridState;
103
+ shared?: GridState;
104
+ }>;
105
+ listViews(key: string): Promise<SavedView[]>;
106
+ /** Saves a view. A `shared` scope is "save for everyone": only this call writes one. */
107
+ saveView(key: string, view: ViewInput): Promise<SavedView>;
108
+ deleteView(id: string): Promise<void>;
109
+ }
110
+ export interface ServerStoreOptions extends WarnOption {
111
+ /** The name of the view that the grid shows and that `save` writes. The default is `Default`. */
112
+ view?: string;
113
+ }
114
+ /**
115
+ * Saved views through a data source. `save` (the automatic save) writes only the personal
116
+ * view, and never over a locked view. `load` gives the personal view, then the shared view.
117
+ */
118
+ export declare function serverStore(source: ViewSource, options?: ServerStoreOptions): ServerStore;
119
+ export {};
120
+ //# sourceMappingURL=stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,iGAAiG;AACjG,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAA;IACzE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,I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"}
package/dist/index.js ADDED
@@ -0,0 +1,453 @@
1
+ import is from '@sindresorhus/is';
2
+
3
+ /** The schema version of a `GridState`. Add a migration when you change the shape. */
4
+ const SCHEMA_VERSION = 1;
5
+
6
+ /** The state keys that the Grid owns, not the table. */
7
+
8
+ /**
9
+ * The Grid implements this to persist its own keys (scroll offset and active cell).
10
+ * `subscribe` is optional: without it, a change to these keys saves with the next table change.
11
+ */
12
+
13
+ /** The persistable grid state as JSON. Each key is optional: a missing key keeps its default. */
14
+
15
+ /** The table slices in a `GridState`. The table has a slice only when its feature is registered. */
16
+ const TABLE_KEYS = ['columnOrder', 'columnPinning', 'columnSizing', 'columnVisibility', 'sorting', 'columnFilters', 'globalFilter', 'grouping', 'expanded', 'rowSelection', 'pagination'];
17
+ const HOST_KEYS = ['scroll', 'activeCell'];
18
+
19
+ /**
20
+ * The part of a Lattice table that this package uses. Any table from `constructTable` has it.
21
+ * The feature setters (`setSorting` and the others) are found by name at run time.
22
+ */
23
+
24
+ // `columnOrder` → `setColumnOrder`: each feature setter goes through the slice owner.
25
+ const setterOf = key => `set${key[0].toUpperCase()}${key.slice(1)}`;
26
+
27
+ /** Reads the persistable state of `table` (and of `host`, when given) as JSON. */
28
+ function gridState(table, host) {
29
+ const slices = table.store.state;
30
+ const state = {
31
+ v: SCHEMA_VERSION
32
+ };
33
+ for (const key of TABLE_KEYS) {
34
+ if (key in table.atoms && slices[key] !== undefined) state[key] = slices[key];
35
+ }
36
+ return {
37
+ ...state,
38
+ ...host?.read()
39
+ };
40
+ }
41
+
42
+ /** Sets each key of `state` on `table` (and on `host`). A key the table has no feature for stays unused. */
43
+ function applyGridState(table, state, host) {
44
+ const api = table;
45
+ for (const key of TABLE_KEYS) {
46
+ if (!(key in state) || !(key in table.atoms)) continue;
47
+ const set = api[setterOf(key)];
48
+ if (is.function(set)) set.call(table, state[key]);
49
+ }
50
+ const own = {};
51
+ for (const key of HOST_KEYS) if (key in state) Object.assign(own, {
52
+ [key]: state[key]
53
+ });
54
+ if (host && Object.keys(own).length > 0) host.apply(own);
55
+ }
56
+
57
+ /** `migrations[v]` upgrades a state from version `v` to version `v + 1`. */
58
+
59
+ /** The migrations of this release. Version 1 is the first schema, so there is none yet. */
60
+ const migrations = {};
61
+ const strings = x => is.array(x) && x.every(is.string);
62
+ const record = (x, value) => is.plainObject(x) && Object.values(x).every(value);
63
+ const finite = x => is.number(x) && Number.isFinite(x);
64
+ const intAtLeast = min => x => is.integer(x) && x >= min;
65
+ const optional = check => x => x === undefined || check(x);
66
+ const json = x => is.string(x) || is.boolean(x) || is.null(x) || finite(x) || is.array(x) && x.every(json) || record(x, json);
67
+
68
+ // One check for each known key. A key that is not here is unknown, also `__proto__`.
69
+ const VALID = {
70
+ columnOrder: strings,
71
+ columnPinning: x => is.plainObject(x) && Object.keys(x).every(k => k === 'start' || k === 'end') && optional(strings)(x['start']) && optional(strings)(x['end']),
72
+ columnSizing: x => record(x, finite),
73
+ columnVisibility: x => record(x, is.boolean),
74
+ sorting: x => is.array(x) && x.every(s => is.plainObject(s) && is.string(s['id']) && is.boolean(s['desc'])),
75
+ columnFilters: x => is.array(x) && x.every(f => is.plainObject(f) && is.string(f['id']) && f['value'] !== undefined && json(f['value'])),
76
+ globalFilter: json,
77
+ grouping: strings,
78
+ expanded: x => x === true || record(x, is.boolean),
79
+ rowSelection: x => record(x, v => v === true),
80
+ pagination: x => is.plainObject(x) && intAtLeast(0)(x['pageIndex']) && intAtLeast(1)(x['pageSize']),
81
+ scroll: x => is.plainObject(x) && finite(x['top']) && finite(x['left']),
82
+ activeCell: x => x === null || is.plainObject(x) && is.string(x['rowId']) && is.string(x['columnId'])
83
+ };
84
+
85
+ /**
86
+ * Upgrades `input` to the current schema, one version at a time, then checks each key.
87
+ * An unknown key or a key with a bad value drops only that key, with a dev warning. A value
88
+ * that is not a state at all gives `undefined`. It never throws: the input can come from a URL.
89
+ */
90
+ function migrate(input, options = {}) {
91
+ const {
92
+ migrations: steps = migrations,
93
+ version = SCHEMA_VERSION,
94
+ warn = message => console.warn(message)
95
+ } = options;
96
+ if (!is.plainObject(input) || !is.integer(input['v']) || input['v'] < 1) return undefined;
97
+ let state = input;
98
+ try {
99
+ for (let v = input['v']; v < version; v++) {
100
+ const step = steps[v];
101
+ if (step) state = step(state);else warn(`Lattice state: no migration from version ${v}; the keys are checked as they are.`);
102
+ }
103
+ } catch (error) {
104
+ warn(`Lattice state: a migration failed, so the state is not used. ${String(error)}`);
105
+ return undefined;
106
+ }
107
+ const out = {
108
+ v: version
109
+ };
110
+ for (const [key, value] of Object.entries(state)) {
111
+ if (key === 'v') continue;
112
+ const check = VALID[key];
113
+ if (!check) warn(`Lattice state: unknown key "${key}" is dropped.`);else if (!check(value)) warn(`Lattice state: key "${key}" has a bad value and is dropped.`);else out[key] = value;
114
+ }
115
+ return out;
116
+ }
117
+
118
+ // JSON with sorted object keys, so the same state always gives the same string.
119
+ function canonical(value) {
120
+ if (is.array(value)) return value.map(canonical);
121
+ if (!is.plainObject(value)) return value;
122
+ return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]));
123
+ }
124
+ const sameJson = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
125
+ const consoleWarn = message => console.warn(message);
126
+
127
+ /** One place that keeps grid state. `load` can be sync (URL, localStorage) or async (server). */
128
+
129
+ // One-letter names for the top-level keys in the URL. Never change a name: old links use it.
130
+ const SHORT = {
131
+ columnOrder: 'o',
132
+ columnPinning: 'p',
133
+ columnSizing: 'w',
134
+ columnVisibility: 'h',
135
+ sorting: 's',
136
+ columnFilters: 'f',
137
+ globalFilter: 'q',
138
+ grouping: 'g',
139
+ expanded: 'e',
140
+ rowSelection: 'r',
141
+ pagination: 'n',
142
+ scroll: 'y',
143
+ activeCell: 'a'
144
+ };
145
+ const LONG = Object.fromEntries(Object.entries(SHORT).map(([long, short]) => [short, long]));
146
+ const rename = (state, names) => Object.fromEntries(Object.entries(state).map(([key, value]) => [names[key] ?? key, value]));
147
+
148
+ /**
149
+ * A short and stable string for `state`: JSON with one-letter top-level keys and sorted keys,
150
+ * as base64url with no padding.
151
+ */
152
+ function encodeState(state) {
153
+ const bytes = new TextEncoder().encode(JSON.stringify(canonical(rename(state, SHORT))));
154
+ let binary = '';
155
+ for (const byte of bytes) binary += String.fromCharCode(byte);
156
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
157
+ }
158
+
159
+ /** The state in `text`, or `undefined` when the text is not a valid state. It never throws. */
160
+ function decodeState(text, options = {}) {
161
+ try {
162
+ const binary = atob(text.replace(/-/g, '+').replace(/_/g, '/'));
163
+ const bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
164
+ const json = new TextDecoder('utf-8', {
165
+ fatal: true
166
+ }).decode(bytes);
167
+ const parsed = JSON.parse(json);
168
+ return migrate(is.plainObject(parsed) ? rename(parsed, LONG) : parsed, options);
169
+ } catch {
170
+ return undefined;
171
+ }
172
+ }
173
+
174
+ /** True when `state` has no key other than the version. */
175
+ const isEmptyState = state => Object.keys(state).every(key => key === 'v');
176
+
177
+ /** The part of the Ember router service that `urlStore` uses. */
178
+
179
+ /** The part of `window` that `urlStore` uses when there is no router. */
180
+
181
+ /**
182
+ * Keeps the state in one query param, named by the store key. The param holds the encoded
183
+ * state (see `encodeState`); a state with no key removes the param.
184
+ */
185
+ function urlStore(options = {}) {
186
+ const {
187
+ router,
188
+ warn = consoleWarn
189
+ } = options;
190
+ const win = () => options.window ?? globalThis.window;
191
+ const read = key => {
192
+ const value = router ? router.currentRoute?.queryParams[key] : new URL(win().location.href).searchParams.get(key);
193
+ return is.string(value) && value !== '' ? value : undefined;
194
+ };
195
+ const load = key => {
196
+ const text = read(key);
197
+ return text === undefined ? undefined : decodeState(text, {
198
+ warn
199
+ });
200
+ };
201
+ return {
202
+ load,
203
+ save(key, state) {
204
+ const text = isEmptyState(state) ? null : encodeState(state);
205
+ if ((read(key) ?? null) === text) return;
206
+ if (router) {
207
+ router.replaceWith({
208
+ queryParams: {
209
+ [key]: text
210
+ }
211
+ });
212
+ return;
213
+ }
214
+ const url = new URL(win().location.href);
215
+ if (text === null) url.searchParams.delete(key);else url.searchParams.set(key, text);
216
+ win().history.replaceState(win().history.state, '', url.href);
217
+ },
218
+ subscribe(key, listener) {
219
+ let last = read(key);
220
+ const changed = () => {
221
+ const text = read(key);
222
+ if (text === last) return;
223
+ last = text;
224
+ listener(load(key));
225
+ };
226
+ if (router) {
227
+ router.on?.('routeDidChange', changed);
228
+ return () => void router.off?.('routeDidChange', changed);
229
+ }
230
+ win().addEventListener('popstate', changed);
231
+ return () => win().removeEventListener('popstate', changed);
232
+ }
233
+ };
234
+ }
235
+
236
+ /** The part of `Storage` that `localStore` uses. */
237
+
238
+ /**
239
+ * Keeps the state in localStorage. It never throws: when storage is not there (private mode),
240
+ * is full (quota) or holds bad JSON, `load` gives `undefined` and `save` does nothing.
241
+ */
242
+ function localStore(options = {}) {
243
+ const {
244
+ prefix = 'lattice:',
245
+ warn = consoleWarn
246
+ } = options;
247
+ // Even a read of `localStorage` can throw (a sandboxed frame), so it is inside the try.
248
+ const storage = () => is.function(options.storage) ? options.storage() : options.storage ?? globalThis.localStorage;
249
+ return {
250
+ load(key) {
251
+ try {
252
+ const text = storage().getItem(prefix + key);
253
+ return text === null ? undefined : migrate(JSON.parse(text), {
254
+ warn
255
+ });
256
+ } catch {
257
+ return undefined;
258
+ }
259
+ },
260
+ save(key, state) {
261
+ try {
262
+ if (isEmptyState(state)) storage().removeItem(prefix + key);else storage().setItem(prefix + key, JSON.stringify(state));
263
+ } catch (error) {
264
+ warn(`Lattice state: localStorage did not save "${key}". ${String(error)}`);
265
+ }
266
+ }
267
+ };
268
+ }
269
+
270
+ /** A saved view. A shared view is for everyone; a locked view changes only by an explicit call. */
271
+
272
+ /** The async views API of a data source. The server decides who can see a personal view. */
273
+
274
+ /**
275
+ * Saved views through a data source. `save` (the automatic save) writes only the personal
276
+ * view, and never over a locked view. `load` gives the personal view, then the shared view.
277
+ */
278
+ function serverStore(source, options = {}) {
279
+ const {
280
+ view: name = 'Default',
281
+ warn = consoleWarn
282
+ } = options;
283
+ const listViews = async key => (await source.listViews()).filter(view => view.key === key).map(view => ({
284
+ ...view,
285
+ state: migrate(view.state, {
286
+ warn
287
+ }) ?? {
288
+ v: view.state.v
289
+ }
290
+ }));
291
+ const find = (views, viewName, scope) => views.find(view => view.name === viewName && view.scope === scope);
292
+ const store = {
293
+ listViews,
294
+ deleteView: id => source.deleteView(id),
295
+ async loadLayers(key) {
296
+ const views = await listViews(key);
297
+ return {
298
+ personal: find(views, name, 'personal')?.state,
299
+ shared: find(views, name, 'shared')?.state
300
+ };
301
+ },
302
+ async load(key) {
303
+ const {
304
+ personal,
305
+ shared
306
+ } = await store.loadLayers(key);
307
+ return personal ?? shared;
308
+ },
309
+ async saveView(key, input) {
310
+ const old = find(await source.listViews().then(all => all.filter(v => v.key === key)), input.name, input.scope);
311
+ if (old?.locked && input.locked === undefined) {
312
+ throw new Error(`Lattice state: the view "${input.name}" is locked.`);
313
+ }
314
+ return source.saveView({
315
+ locked: old?.locked,
316
+ ...input,
317
+ id: old?.id,
318
+ key
319
+ });
320
+ },
321
+ async save(key, state) {
322
+ try {
323
+ await store.saveView(key, {
324
+ name,
325
+ scope: 'personal',
326
+ state
327
+ });
328
+ } catch (error) {
329
+ warn(`Lattice state: the personal view did not save. ${String(error)}`);
330
+ }
331
+ }
332
+ };
333
+ return store;
334
+ }
335
+
336
+ /**
337
+ * The state to show. The first layer that is there wins as a whole: URL, then the personal
338
+ * view, then the shared view. Its missing keys come from the defaults, never from a lower
339
+ * layer, so a shared link shows the same grid to each person.
340
+ */
341
+ function resolveState({
342
+ url,
343
+ personal,
344
+ shared,
345
+ defaults
346
+ }) {
347
+ return {
348
+ ...defaults,
349
+ ...(url ?? personal ?? shared)
350
+ };
351
+ }
352
+
353
+ /** The keys of `state` that differ from `defaults`. A store keeps only these. */
354
+ function withoutDefaults(state, defaults) {
355
+ const record = defaults;
356
+ return Object.fromEntries(Object.entries(state).filter(([key, value]) => key === 'v' || !(key in record) || !sameJson(value, record[key])));
357
+ }
358
+ /**
359
+ * Loads the state of `table` from the first store that has one, and saves each change to all
360
+ * stores after a debounce. Call it before the grid renders: a sync store (URL, localStorage)
361
+ * then applies before the first read of the table, and an async store applies when it
362
+ * resolves. No save runs during a render, because each save waits for a timer.
363
+ */
364
+ function persistGridState(table, options) {
365
+ const {
366
+ key,
367
+ stores,
368
+ host,
369
+ wait = 300,
370
+ warn = consoleWarn
371
+ } = options;
372
+ const defaults = gridState(table, host);
373
+ const current = () => withoutDefaults(gridState(table, host), defaults);
374
+ let last = current();
375
+ let timer;
376
+ let stopped = false;
377
+ const apply = state => {
378
+ if (stopped) return;
379
+ applyGridState(table, resolveState({
380
+ url: state,
381
+ defaults
382
+ }), host);
383
+ last = current();
384
+ };
385
+ const loadFrom = index => {
386
+ const store = stores[index];
387
+ if (!store) return undefined;
388
+ let result;
389
+ try {
390
+ result = store.load(key);
391
+ } catch (error) {
392
+ warn(`Lattice state: a store did not load "${key}". ${String(error)}`);
393
+ return loadFrom(index + 1);
394
+ }
395
+ if (!is.promise(result)) return result ?? loadFrom(index + 1);
396
+ return result.then(state => state ?? loadFrom(index + 1), error => {
397
+ warn(`Lattice state: a store did not load "${key}". ${String(error)}`);
398
+ return loadFrom(index + 1);
399
+ });
400
+ };
401
+ const save = async () => {
402
+ timer = undefined;
403
+ const state = current();
404
+ if (stopped || sameJson(state, last)) return;
405
+ last = state;
406
+ await Promise.all(stores.map(store => Promise.resolve().then(() => store.save(key, state)).catch(error => {
407
+ warn(`Lattice state: a store did not save "${key}". ${String(error)}`);
408
+ })));
409
+ };
410
+ const schedule = () => {
411
+ if (stopped) return;
412
+ clearTimeout(timer);
413
+ timer = setTimeout(() => void save(), wait);
414
+ };
415
+ const loaded = loadFrom(0);
416
+ let ready;
417
+ if (is.promise(loaded)) {
418
+ const before = current();
419
+ ready = loaded.then(state => {
420
+ // A change by the user while the store loaded wins over the stored state.
421
+ if (state && sameJson(current(), before)) apply(state);
422
+ });
423
+ } else {
424
+ if (loaded) apply(loaded);
425
+ ready = Promise.resolve();
426
+ }
427
+ const subscriptions = [table.store.subscribe(schedule).unsubscribe, host?.subscribe?.(schedule),
428
+ // A store also tells about its own save (the router fires `routeDidChange` later). That
429
+ // echo is skipped, so it cannot undo a change that the user made after the save.
430
+ ...stores.map(store => store.subscribe?.(key, state => {
431
+ if (!sameJson(withoutDefaults(resolveState({
432
+ url: state,
433
+ defaults
434
+ }), defaults), last)) {
435
+ apply(state);
436
+ }
437
+ }))];
438
+ return {
439
+ ready,
440
+ flush() {
441
+ clearTimeout(timer);
442
+ return save();
443
+ },
444
+ stop() {
445
+ stopped = true;
446
+ clearTimeout(timer);
447
+ for (const unsubscribe of subscriptions) unsubscribe?.();
448
+ }
449
+ };
450
+ }
451
+
452
+ export { HOST_KEYS, SCHEMA_VERSION, TABLE_KEYS, applyGridState, decodeState, encodeState, gridState, isEmptyState, localStore, migrate, migrations, persistGridState, resolveState, serverStore, urlStore, withoutDefaults };
453
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/grid-state.ts","../src/migrate.ts","../src/internal.ts","../src/stores.ts","../src/persist.ts"],"sourcesContent":["import is from '@sindresorhus/is'\nimport type {\n ColumnFiltersState,\n ColumnPinningState,\n ColumnSizingState,\n ColumnVisibilityState,\n ExpandedState,\n GroupingState,\n PaginationState,\n RowSelectionState,\n SortingState,\n} from '@ember-lattice/core'\n\n/** The schema version of a `GridState`. Add a migration when you change the shape. */\nexport const SCHEMA_VERSION = 1\n\nexport interface ScrollOffset {\n top: number\n left: number\n}\n\nexport interface CellRef {\n rowId: string\n columnId: string\n}\n\n/** The state keys that the Grid owns, not the table. */\nexport interface HostState {\n scroll?: ScrollOffset\n activeCell?: CellRef | null\n}\n\n/**\n * The Grid implements this to persist its own keys (scroll offset and active cell).\n * `subscribe` is optional: without it, a change to these keys saves with the next table change.\n */\nexport interface GridStateHost {\n read(): HostState\n apply(state: HostState): void\n subscribe?(listener: () => void): () => void\n}\n\n/** The persistable grid state as JSON. Each key is optional: a missing key keeps its default. */\nexport interface GridState extends HostState {\n v: number\n columnOrder?: string[]\n columnPinning?: ColumnPinningState\n columnSizing?: ColumnSizingState\n columnVisibility?: ColumnVisibilityState\n sorting?: SortingState\n columnFilters?: ColumnFiltersState\n globalFilter?: unknown\n grouping?: GroupingState\n expanded?: ExpandedState\n rowSelection?: RowSelectionState\n pagination?: PaginationState\n}\n\n/** The table slices in a `GridState`. The table has a slice only when its feature is registered. */\nexport const TABLE_KEYS = [\n 'columnOrder',\n 'columnPinning',\n 'columnSizing',\n 'columnVisibility',\n 'sorting',\n 'columnFilters',\n 'globalFilter',\n 'grouping',\n 'expanded',\n 'rowSelection',\n 'pagination',\n] as const\n\nexport const HOST_KEYS = ['scroll', 'activeCell'] as const\n\n/**\n * The part of a Lattice table that this package uses. Any table from `constructTable` has it.\n * The feature setters (`setSorting` and the others) are found by name at run time.\n */\nexport interface TableLike {\n readonly store: {\n readonly state: object\n subscribe(listener: () => void): { unsubscribe: () => void }\n }\n readonly atoms: object\n}\n\n// `columnOrder` → `setColumnOrder`: each feature setter goes through the slice owner.\nconst setterOf = (key: string) => `set${key[0]!.toUpperCase()}${key.slice(1)}`\n\n/** Reads the persistable state of `table` (and of `host`, when given) as JSON. */\nexport function gridState(table: TableLike, host?: GridStateHost): GridState {\n const slices = table.store.state as Record<string, unknown>\n const state: Record<string, unknown> = { v: SCHEMA_VERSION }\n for (const key of TABLE_KEYS) {\n if (key in table.atoms && slices[key] !== undefined) state[key] = slices[key]\n }\n return { ...(state as unknown as GridState), ...host?.read() }\n}\n\n/** Sets each key of `state` on `table` (and on `host`). A key the table has no feature for stays unused. */\nexport function applyGridState(table: TableLike, state: GridState, host?: GridStateHost): void {\n const api = table as unknown as Record<string, unknown>\n for (const key of TABLE_KEYS) {\n if (!(key in state) || !(key in table.atoms)) continue\n const set = api[setterOf(key)]\n if (is.function(set)) set.call(table, state[key])\n }\n const own: HostState = {}\n for (const key of HOST_KEYS) if (key in state) Object.assign(own, { [key]: state[key] })\n if (host && Object.keys(own).length > 0) host.apply(own)\n}\n","import is from '@sindresorhus/is'\nimport { SCHEMA_VERSION } from './grid-state.ts'\nimport type { GridState } from './grid-state.ts'\n\ntype Raw = Record<string, unknown>\n\n/** `migrations[v]` upgrades a state from version `v` to version `v + 1`. */\nexport type Migrations = Record<number, (state: Raw) => Raw>\n\n/** The migrations of this release. Version 1 is the first schema, so there is none yet. */\nexport const migrations: Migrations = {}\n\nexport interface MigrateOptions {\n migrations?: Migrations\n version?: number\n /** Gets each dev warning. The default is `console.warn`. */\n warn?: (message: string) => void\n}\n\nconst strings = (x: unknown) => is.array(x) && x.every(is.string)\nconst record = (x: unknown, value: (v: unknown) => boolean) =>\n is.plainObject(x) && Object.values(x).every(value)\nconst finite = (x: unknown): x is number => is.number(x) && Number.isFinite(x)\nconst intAtLeast = (min: number) => (x: unknown) => is.integer(x) && x >= min\nconst optional = (check: (x: unknown) => boolean) => (x: unknown) => x === undefined || check(x)\nconst json = (x: unknown): boolean =>\n is.string(x) ||\n is.boolean(x) ||\n is.null(x) ||\n finite(x) ||\n (is.array(x) && x.every(json)) ||\n record(x, json)\n\n// One check for each known key. A key that is not here is unknown, also `__proto__`.\nconst VALID: Record<string, (x: unknown) => boolean> = {\n columnOrder: strings,\n columnPinning: x =>\n is.plainObject(x) &&\n Object.keys(x).every(k => k === 'start' || k === 'end') &&\n optional(strings)(x['start']) &&\n optional(strings)(x['end']),\n columnSizing: x => record(x, finite),\n columnVisibility: x => record(x, is.boolean),\n sorting: x =>\n is.array(x) && x.every(s => is.plainObject(s) && is.string(s['id']) && is.boolean(s['desc'])),\n columnFilters: x =>\n is.array(x) &&\n x.every(\n f => is.plainObject(f) && is.string(f['id']) && f['value'] !== undefined && json(f['value']),\n ),\n globalFilter: json,\n grouping: strings,\n expanded: x => x === true || record(x, is.boolean),\n rowSelection: x => record(x, v => v === true),\n pagination: x =>\n is.plainObject(x) && intAtLeast(0)(x['pageIndex']) && intAtLeast(1)(x['pageSize']),\n scroll: x => is.plainObject(x) && finite(x['top']) && finite(x['left']),\n activeCell: x =>\n x === null || (is.plainObject(x) && is.string(x['rowId']) && is.string(x['columnId'])),\n}\n\n/**\n * Upgrades `input` to the current schema, one version at a time, then checks each key.\n * An unknown key or a key with a bad value drops only that key, with a dev warning. A value\n * that is not a state at all gives `undefined`. It never throws: the input can come from a URL.\n */\nexport function migrate(input: unknown, options: MigrateOptions = {}): GridState | undefined {\n const {\n migrations: steps = migrations,\n version = SCHEMA_VERSION,\n warn = (message: string) => console.warn(message),\n } = options\n if (!is.plainObject(input) || !is.integer(input['v']) || input['v'] < 1) return undefined\n let state: Raw = input\n try {\n for (let v = input['v']; v < version; v++) {\n const step = steps[v]\n if (step) state = step(state)\n else warn(`Lattice state: no migration from version ${v}; the keys are checked as they are.`)\n }\n } catch (error) {\n warn(`Lattice state: a migration failed, so the state is not used. ${String(error)}`)\n return undefined\n }\n const out: Raw = { v: version }\n for (const [key, value] of Object.entries(state)) {\n if (key === 'v') continue\n const check = VALID[key]\n if (!check) warn(`Lattice state: unknown key \"${key}\" is dropped.`)\n else if (!check(value)) warn(`Lattice state: key \"${key}\" has a bad value and is dropped.`)\n else out[key] = value\n }\n return out as unknown as GridState\n}\n","import is from '@sindresorhus/is'\n\n// JSON with sorted object keys, so the same state always gives the same string.\nexport function canonical(value: unknown): unknown {\n if (is.array(value)) return value.map(canonical)\n if (!is.plainObject(value)) return value\n return Object.fromEntries(\n Object.keys(value)\n .sort()\n .map(key => [key, canonical(value[key])]),\n )\n}\n\nexport const sameJson = (a: unknown, b: unknown) =>\n JSON.stringify(canonical(a)) === JSON.stringify(canonical(b))\n\nexport const consoleWarn = (message: string) => console.warn(message)\n","import is from '@sindresorhus/is'\nimport { canonical, consoleWarn } from './internal.ts'\nimport { migrate } from './migrate.ts'\nimport type { GridState } from './grid-state.ts'\n\n/** One place that keeps grid state. `load` can be sync (URL, localStorage) or async (server). */\nexport interface StateStore {\n load(key: string): GridState | undefined | Promise<GridState | undefined>\n save(key: string, state: GridState): void | Promise<void>\n /** Calls `listener` when the state changes outside the grid (the back button, for example). */\n subscribe?(key: string, listener: (state: GridState | undefined) => void): () => void\n}\n\ninterface WarnOption {\n /** Gets each dev warning. The default is `console.warn`. */\n warn?: (message: string) => void\n}\n\n// One-letter names for the top-level keys in the URL. Never change a name: old links use it.\nconst SHORT: Record<string, string> = {\n columnOrder: 'o',\n columnPinning: 'p',\n columnSizing: 'w',\n columnVisibility: 'h',\n sorting: 's',\n columnFilters: 'f',\n globalFilter: 'q',\n grouping: 'g',\n expanded: 'e',\n rowSelection: 'r',\n pagination: 'n',\n scroll: 'y',\n activeCell: 'a',\n}\nconst LONG = Object.fromEntries(Object.entries(SHORT).map(([long, short]) => [short, long]))\nconst rename = (state: object, names: Record<string, string>) =>\n Object.fromEntries(Object.entries(state).map(([key, value]) => [names[key] ?? key, value]))\n\n/**\n * A short and stable string for `state`: JSON with one-letter top-level keys and sorted keys,\n * as base64url with no padding.\n */\nexport function encodeState(state: GridState): string {\n const bytes = new TextEncoder().encode(JSON.stringify(canonical(rename(state, SHORT))))\n let binary = ''\n for (const byte of bytes) binary += String.fromCharCode(byte)\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\n\n/** The state in `text`, or `undefined` when the text is not a valid state. It never throws. */\nexport function decodeState(text: string, options: WarnOption = {}): GridState | undefined {\n try {\n const binary = atob(text.replace(/-/g, '+').replace(/_/g, '/'))\n const bytes = Uint8Array.from(binary, char => char.charCodeAt(0))\n const json = new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n const parsed: unknown = JSON.parse(json)\n return migrate(is.plainObject(parsed) ? rename(parsed, LONG) : parsed, options)\n } catch {\n return undefined\n }\n}\n\n/** True when `state` has no key other than the version. */\nexport const isEmptyState = (state: GridState) => Object.keys(state).every(key => key === 'v')\n\n/** The part of the Ember router service that `urlStore` uses. */\nexport interface RouterLike {\n currentRoute?: { queryParams: Record<string, unknown> } | null\n replaceWith(options: { queryParams: Record<string, string | null> }): unknown\n on?(event: 'routeDidChange', listener: () => void): unknown\n off?(event: 'routeDidChange', listener: () => void): unknown\n}\n\n/** The part of `window` that `urlStore` uses when there is no router. */\nexport interface WindowLike {\n location: { href: string }\n history: { state: unknown; replaceState(state: unknown, unused: string, url: string): void }\n addEventListener(type: 'popstate', listener: () => void): void\n removeEventListener(type: 'popstate', listener: () => void): void\n}\n\nexport interface UrlStoreOptions extends WarnOption {\n /**\n * The Ember router service. The route must declare the query param (the `key`), because\n * Ember drops a query param that no controller declares.\n */\n router?: RouterLike\n /** The window to use when there is no router. The default is the global `window`. */\n window?: WindowLike\n}\n\n/**\n * Keeps the state in one query param, named by the store key. The param holds the encoded\n * state (see `encodeState`); a state with no key removes the param.\n */\nexport function urlStore(options: UrlStoreOptions = {}): StateStore {\n const { router, warn = consoleWarn } = options\n const win = () => options.window ?? (globalThis as unknown as { window: WindowLike }).window\n const read = (key: string): string | undefined => {\n const value = router\n ? router.currentRoute?.queryParams[key]\n : new URL(win().location.href).searchParams.get(key)\n return is.string(value) && value !== '' ? value : undefined\n }\n const load = (key: string) => {\n const text = read(key)\n return text === undefined ? undefined : decodeState(text, { warn })\n }\n return {\n load,\n save(key, state) {\n const text = isEmptyState(state) ? null : encodeState(state)\n if ((read(key) ?? null) === text) return\n if (router) {\n router.replaceWith({ queryParams: { [key]: text } })\n return\n }\n const url = new URL(win().location.href)\n if (text === null) url.searchParams.delete(key)\n else url.searchParams.set(key, text)\n win().history.replaceState(win().history.state, '', url.href)\n },\n subscribe(key, listener) {\n let last = read(key)\n const changed = () => {\n const text = read(key)\n if (text === last) return\n last = text\n listener(load(key))\n }\n if (router) {\n router.on?.('routeDidChange', changed)\n return () => void router.off?.('routeDidChange', changed)\n }\n win().addEventListener('popstate', changed)\n return () => win().removeEventListener('popstate', changed)\n },\n }\n}\n\n/** The part of `Storage` that `localStore` uses. */\nexport type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>\n\nexport interface LocalStoreOptions extends WarnOption {\n /** The default is `globalThis.localStorage`. A function is called on each use. */\n storage?: StorageLike | (() => StorageLike)\n /** The prefix of each storage key. The default is `lattice:`. */\n prefix?: string\n}\n\n/**\n * Keeps the state in localStorage. It never throws: when storage is not there (private mode),\n * is full (quota) or holds bad JSON, `load` gives `undefined` and `save` does nothing.\n */\nexport function localStore(options: LocalStoreOptions = {}): StateStore {\n const { prefix = 'lattice:', warn = consoleWarn } = options\n // Even a read of `localStorage` can throw (a sandboxed frame), so it is inside the try.\n const storage = (): StorageLike =>\n is.function(options.storage) ? options.storage() : (options.storage ?? globalThis.localStorage)\n return {\n load(key) {\n try {\n const text = storage().getItem(prefix + key)\n return text === null ? undefined : migrate(JSON.parse(text), { warn })\n } catch {\n return undefined\n }\n },\n save(key, state) {\n try {\n if (isEmptyState(state)) storage().removeItem(prefix + key)\n else storage().setItem(prefix + key, JSON.stringify(state))\n } catch (error) {\n warn(`Lattice state: localStorage did not save \"${key}\". ${String(error)}`)\n }\n },\n }\n}\n\nexport type ViewScope = 'personal' | 'shared'\n\n/** A saved view. A shared view is for everyone; a locked view changes only by an explicit call. */\nexport interface SavedView {\n id: string\n /** The grid that the view is for: the store key. */\n key: string\n name: string\n scope: ViewScope\n locked?: boolean\n state: GridState\n}\n\n/** The async views API of a data source. The server decides who can see a personal view. */\nexport interface ViewSource {\n listViews(): Promise<SavedView[]>\n saveView(view: Omit<SavedView, 'id'> & { id?: string }): Promise<SavedView>\n deleteView(id: string): Promise<void>\n}\n\nexport interface ViewInput {\n name: string\n scope: ViewScope\n locked?: boolean\n state: GridState\n}\n\nexport interface ServerStore extends StateStore {\n load(key: string): Promise<GridState | undefined>\n save(key: string, state: GridState): Promise<void>\n /** The personal and the shared view with the current view name. */\n loadLayers(key: string): Promise<{ personal?: GridState; shared?: GridState }>\n listViews(key: string): Promise<SavedView[]>\n /** Saves a view. A `shared` scope is \"save for everyone\": only this call writes one. */\n saveView(key: string, view: ViewInput): Promise<SavedView>\n deleteView(id: string): Promise<void>\n}\n\nexport interface ServerStoreOptions extends WarnOption {\n /** The name of the view that the grid shows and that `save` writes. The default is `Default`. */\n view?: string\n}\n\n/**\n * Saved views through a data source. `save` (the automatic save) writes only the personal\n * view, and never over a locked view. `load` gives the personal view, then the shared view.\n */\nexport function serverStore(source: ViewSource, options: ServerStoreOptions = {}): ServerStore {\n const { view: name = 'Default', warn = consoleWarn } = options\n const listViews = async (key: string) =>\n (await source.listViews())\n .filter(view => view.key === key)\n .map(view => ({ ...view, state: migrate(view.state, { warn }) ?? { v: view.state.v } }))\n const find = (views: SavedView[], viewName: string, scope: ViewScope) =>\n views.find(view => view.name === viewName && view.scope === scope)\n\n const store: ServerStore = {\n listViews,\n deleteView: id => source.deleteView(id),\n async loadLayers(key) {\n const views = await listViews(key)\n return {\n personal: find(views, name, 'personal')?.state,\n shared: find(views, name, 'shared')?.state,\n }\n },\n async load(key) {\n const { personal, shared } = await store.loadLayers(key)\n return personal ?? shared\n },\n async saveView(key, input) {\n const old = find(\n await source.listViews().then(all => all.filter(v => v.key === key)),\n input.name,\n input.scope,\n )\n if (old?.locked && input.locked === undefined) {\n throw new Error(`Lattice state: the view \"${input.name}\" is locked.`)\n }\n return source.saveView({ locked: old?.locked, ...input, id: old?.id, key })\n },\n async save(key, state) {\n try {\n await store.saveView(key, { name, scope: 'personal', state })\n } catch (error) {\n warn(`Lattice state: the personal view did not save. ${String(error)}`)\n }\n },\n }\n return store\n}\n","import is from '@sindresorhus/is'\nimport { applyGridState, gridState } from './grid-state.ts'\nimport type { GridState, GridStateHost, TableLike } from './grid-state.ts'\nimport { consoleWarn, sameJson } from './internal.ts'\nimport type { StateStore } from './stores.ts'\n\nexport interface StateLayers {\n url?: GridState\n personal?: GridState\n shared?: GridState\n /** The column defaults: the state of the grid before any store loads. */\n defaults: GridState\n}\n\n/**\n * The state to show. The first layer that is there wins as a whole: URL, then the personal\n * view, then the shared view. Its missing keys come from the defaults, never from a lower\n * layer, so a shared link shows the same grid to each person.\n */\nexport function resolveState({ url, personal, shared, defaults }: StateLayers): GridState {\n return { ...defaults, ...(url ?? personal ?? shared) }\n}\n\n/** The keys of `state` that differ from `defaults`. A store keeps only these. */\nexport function withoutDefaults(state: GridState, defaults: GridState): GridState {\n const record = defaults as unknown as Record<string, unknown>\n return Object.fromEntries(\n Object.entries(state).filter(\n ([key, value]) => key === 'v' || !(key in record) || !sameJson(value, record[key]),\n ),\n ) as unknown as GridState\n}\n\nexport interface PersistOptions {\n /** The name of this grid's state in each store (the query param, for the URL store). */\n key: string\n /** The stores, highest precedence first: for example URL, localStorage, server. */\n stores: StateStore[]\n /** The Grid, for its own keys (scroll offset and active cell). */\n host?: GridStateHost\n /** The milliseconds to wait after the last change before a save. The default is 300. */\n wait?: number\n warn?: (message: string) => void\n}\n\nexport interface Persistence {\n /** Resolves when the load is done, also when an async store gave the state. */\n ready: Promise<void>\n /** Saves a pending change now. */\n flush(): Promise<void>\n /** Stops all saves and subscriptions. Call it when the grid goes away. */\n stop(): void\n}\n\ntype Loaded = GridState | undefined\n\n/**\n * Loads the state of `table` from the first store that has one, and saves each change to all\n * stores after a debounce. Call it before the grid renders: a sync store (URL, localStorage)\n * then applies before the first read of the table, and an async store applies when it\n * resolves. No save runs during a render, because each save waits for a timer.\n */\nexport function persistGridState(table: TableLike, options: PersistOptions): Persistence {\n const { key, stores, host, wait = 300, warn = consoleWarn } = options\n const defaults = gridState(table, host)\n const current = () => withoutDefaults(gridState(table, host), defaults)\n let last = current()\n let timer: ReturnType<typeof setTimeout> | undefined\n let stopped = false\n\n const apply = (state: Loaded) => {\n if (stopped) return\n applyGridState(table, resolveState({ url: state, defaults }), host)\n last = current()\n }\n\n const loadFrom = (index: number): Loaded | Promise<Loaded> => {\n const store = stores[index]\n if (!store) return undefined\n let result: Loaded | Promise<Loaded>\n try {\n result = store.load(key)\n } catch (error) {\n warn(`Lattice state: a store did not load \"${key}\". ${String(error)}`)\n return loadFrom(index + 1)\n }\n if (!is.promise(result)) return result ?? loadFrom(index + 1)\n return result.then(\n state => state ?? loadFrom(index + 1),\n (error: unknown) => {\n warn(`Lattice state: a store did not load \"${key}\". ${String(error)}`)\n return loadFrom(index + 1)\n },\n )\n }\n\n const save = async () => {\n timer = undefined\n const state = current()\n if (stopped || sameJson(state, last)) return\n last = state\n await Promise.all(\n stores.map(store =>\n Promise.resolve()\n .then(() => store.save(key, state))\n .catch((error: unknown) => {\n warn(`Lattice state: a store did not save \"${key}\". ${String(error)}`)\n }),\n ),\n )\n }\n\n const schedule = () => {\n if (stopped) return\n clearTimeout(timer)\n timer = setTimeout(() => void save(), wait)\n }\n\n const loaded = loadFrom(0)\n let ready: Promise<void>\n if (is.promise(loaded)) {\n const before = current()\n ready = loaded.then(state => {\n // A change by the user while the store loaded wins over the stored state.\n if (state && sameJson(current(), before)) apply(state)\n })\n } else {\n if (loaded) apply(loaded)\n ready = Promise.resolve()\n }\n\n const subscriptions = [\n table.store.subscribe(schedule).unsubscribe,\n host?.subscribe?.(schedule),\n // A store also tells about its own save (the router fires `routeDidChange` later). That\n // echo is skipped, so it cannot undo a change that the user made after the save.\n ...stores.map(store =>\n store.subscribe?.(key, state => {\n if (!sameJson(withoutDefaults(resolveState({ url: state, defaults }), defaults), last)) {\n apply(state)\n }\n }),\n ),\n ]\n\n return {\n ready,\n flush() {\n clearTimeout(timer)\n return save()\n },\n stop() {\n stopped = true\n clearTimeout(timer)\n for (const unsubscribe of subscriptions) unsubscribe?.()\n },\n }\n}\n"],"names":["SCHEMA_VERSION","TABLE_KEYS","HOST_KEYS","setterOf","key","toUpperCase","slice","gridState","table","host","slices","store","state","v","atoms","undefined","read","applyGridState","api","set","is","function","call","own","Object","assign","keys","length","apply","migrations","strings","x","array","every","string","record","value","plainObject","values","finite","number","Number","isFinite","intAtLeast","min","integer","optional","check","json","boolean","null","VALID","columnOrder","columnPinning","k","columnSizing","columnVisibility","sorting","s","columnFilters","f","globalFilter","grouping","expanded","rowSelection","pagination","scroll","activeCell","migrate","input","options","steps","version","warn","message","console","step","error","String","out","entries","canonical","map","fromEntries","sort","sameJson","a","b","JSON","stringify","consoleWarn","SHORT","LONG","long","short","rename","names","encodeState","bytes","TextEncoder","encode","binary","byte","fromCharCode","btoa","replace","decodeState","text","atob","Uint8Array","from","char","charCodeAt","TextDecoder","fatal","decode","parsed","parse","isEmptyState","urlStore","router","win","window","globalThis","currentRoute","queryParams","URL","location","href","searchParams","get","load","save","replaceWith","url","delete","history","replaceState","subscribe","listener","last","changed","on","off","addEventListener","removeEventListener","localStore","prefix","storage","localStorage","getItem","removeItem","setItem","serverStore","source","view","name","listViews","filter","find","views","viewName","scope","deleteView","id","loadLayers","personal","shared","saveView","old","then","all","locked","Error","resolveState","defaults","withoutDefaults","persistGridState","stores","wait","current","timer","stopped","loadFrom","index","result","promise","Promise","resolve","catch","schedule","clearTimeout","setTimeout","loaded","ready","before","subscriptions","unsubscribe","flush","stop"],"mappings":";;AAaA;AACO,MAAMA,cAAc,GAAG;;AAY9B;;AAMA;AACA;AACA;AACA;;AAOA;;AAgBA;AACO,MAAMC,UAAU,GAAG,CACxB,aAAa,EACb,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,cAAc,EACd,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY;MAGDC,SAAS,GAAG,CAAC,QAAQ,EAAE,YAAY;;AAEhD;AACA;AACA;AACA;;AASA;AACA,MAAMC,QAAQ,GAAIC,GAAW,IAAK,MAAMA,GAAG,CAAC,CAAC,CAAC,CAAEC,WAAW,EAAE,GAAGD,GAAG,CAACE,KAAK,CAAC,CAAC,CAAC,CAAA,CAAE;;AAE9E;AACO,SAASC,SAASA,CAACC,KAAgB,EAAEC,IAAoB,EAAa;AAC3E,EAAA,MAAMC,MAAM,GAAGF,KAAK,CAACG,KAAK,CAACC,KA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,aAAa,EAAEC,WAAW,IAAI;AAC1D,IAAA;GACD;AACH;;"}
package/package.json CHANGED
@@ -1,6 +1,89 @@
1
1
  {
2
2
  "name": "@ember-lattice/state",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Grid state that lasts: a StateStore interface with URL, localStorage and server adapters, saved views and state migrations.",
5
+ "keywords": [
6
+ "ember-addon",
7
+ "ember",
8
+ "data-grid",
9
+ "table",
10
+ "virtual-scroll"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Joe Gaudet <joe@joegaudet.com>",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/joegaudet/ember-lattice.git",
17
+ "directory": "packages/state"
18
+ },
19
+ "homepage": "https://joegaudet.com/ember-lattice/",
20
+ "bugs": "https://github.com/joegaudet/ember-lattice/issues",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./declarations/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./addon-main.js": "./addon-main.cjs"
27
+ },
28
+ "typesVersions": {
29
+ "*": {
30
+ "*": [
31
+ "declarations/*"
32
+ ]
33
+ }
34
+ },
35
+ "files": [
36
+ "addon-main.cjs",
37
+ "declarations",
38
+ "dist",
39
+ "README.md",
40
+ "CHANGELOG.md",
41
+ "LICENSE.md",
42
+ "NOTICE"
43
+ ],
44
+ "dependencies": {
45
+ "@ember-lattice/core": "1.0.0",
46
+ "@embroider/addon-shim": "^1.10.3",
47
+ "@sindresorhus/is": "^7.2.0",
48
+ "decorator-transforms": "^2.4.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@glimmer/component": ">= 2.0.0",
52
+ "ember-source": ">= 6.12.0"
53
+ },
54
+ "devDependencies": {
55
+ "@babel/core": "^7.29.7",
56
+ "@babel/plugin-transform-typescript": "^7.29.7",
57
+ "@babel/runtime": "^7.29.7",
58
+ "@ember/library-tsconfig": "^3.0.0",
59
+ "@embroider/addon-dev": "^8.4.2",
60
+ "@glimmer/component": "^2.2.1",
61
+ "@glimmer/tracking": "^1.1.2",
62
+ "@glint/ember-tsc": "^1.14.2",
63
+ "@glint/template": "^1.9.0",
64
+ "@rollup/plugin-babel": "^7.1.0",
65
+ "babel-plugin-ember-template-compilation": "^4.0.1",
66
+ "ember-source": "~7.3.0",
67
+ "rollup": "^4.64.6",
68
+ "typescript": "~6.0.3"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ },
73
+ "engines": {
74
+ "node": ">=22.12.0"
75
+ },
76
+ "ember": {
77
+ "edition": "octane"
78
+ },
79
+ "ember-addon": {
80
+ "version": 2,
81
+ "type": "addon",
82
+ "main": "addon-main.cjs"
83
+ },
84
+ "scripts": {
85
+ "build": "rm -rf declarations && rollup --config",
86
+ "start": "rm -rf declarations && rollup --config --watch",
87
+ "typecheck": "ember-tsc --noEmit"
88
+ }
6
89
  }