{"version":3,"file":"ListTable.mjs","names":[],"sources":["../../../../../../../../components-base/src/list/table/ListTable.ts"],"sourcesContent":["import { action, makeObservable, observable } from \"mobx\";\nimport { createTable } from \"@tanstack/table-core\";\nimport type {\n  RowData,\n  Table,\n  TableOptions,\n  TableOptionsResolved,\n  TableState,\n  Updater,\n} from \"@tanstack/table-core\";\n\n/**\n * A TanStack table whose state is MobX.\n *\n * `useReactTable` is `createTable` plus a `useState` for the table's own state\n * and a `setOptions` on every render that folds that state back in. Only the\n * `useState` is React, and `@tanstack/vue-table` reimplements the same twenty\n * lines against Vue's reactivity — so the state lives here instead and each\n * binding brings its subscription.\n *\n * Options still arrive from the binding on every render, because that is where\n * they come from: the loaded data, the column definitions the list's filters\n * and sortings produce, a controlled piece of state. `setOptions` is therefore\n * called by the binding, and re-applied here whenever the state changes.\n */\nexport class ListTable<T extends RowData> {\n  public readonly table: Table<T>;\n  public state: TableState;\n  /**\n   * Bumped whenever the state _or_ the options changed.\n   *\n   * The row models are derived from both, and the options are plain data that\n   * arrives from the binding — so a binding observing only `state` keeps\n   * rendering the previous rows after new data was handed in. It is the one\n   * signal that says \"ask the table again\".\n   */\n  public revision = 0;\n  private options: TableOptions<T>;\n\n  public constructor(options: TableOptions<T>) {\n    const resolved: TableOptionsResolved<T> = {\n      state: {},\n      onStateChange: () => {\n        // replaced by `applyOptions` below\n      },\n      renderFallbackValue: null,\n      ...options,\n    };\n\n    this.table = createTable<T>(resolved);\n    this.state = this.table.initialState;\n    this.options = options;\n\n    makeObservable(this, {\n      state: observable.ref,\n      revision: observable,\n      setState: action.bound,\n      setOptions: action.bound,\n    });\n\n    this.applyOptions();\n  }\n\n  public setState(updater: Updater<TableState>): void {\n    this.state = typeof updater === \"function\" ? updater(this.state) : updater;\n    this.applyOptions();\n  }\n\n  /** Called by the binding on every render, with that render's options. */\n  public setOptions(options: TableOptions<T>): void {\n    this.options = options;\n    this.applyOptions();\n  }\n\n  private applyOptions(): void {\n    const options = this.options;\n    this.revision += 1;\n\n    this.table.setOptions((prev) => ({\n      ...prev,\n      ...options,\n      state: {\n        ...this.state,\n        ...options.state,\n      },\n      onStateChange: (updater) => {\n        this.setState(updater);\n        options.onStateChange?.(updater);\n      },\n    }));\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,IAAa,YAAb,MAA0C;CACxC;CACA;;;;;;;;;CASA,WAAkB;CAClB;CAEA,YAAmB,SAA0B;EAC3C,MAAM,WAAoC;GACxC,OAAO,CAAC;GACR,qBAAqB,CAErB;GACA,qBAAqB;GACrB,GAAG;EACL;EAEA,KAAK,QAAQ,YAAe,QAAQ;EACpC,KAAK,QAAQ,KAAK,MAAM;EACxB,KAAK,UAAU;EAEf,eAAe,MAAM;GACnB,OAAO,WAAW;GAClB,UAAU;GACV,UAAU,OAAO;GACjB,YAAY,OAAO;EACrB,CAAC;EAED,KAAK,aAAa;CACpB;CAEA,SAAgB,SAAoC;EAClD,KAAK,QAAQ,OAAO,YAAY,aAAa,QAAQ,KAAK,KAAK,IAAI;EACnE,KAAK,aAAa;CACpB;;CAGA,WAAkB,SAAgC;EAChD,KAAK,UAAU;EACf,KAAK,aAAa;CACpB;CAEA,eAA6B;EAC3B,MAAM,UAAU,KAAK;EACrB,KAAK,YAAY;EAEjB,KAAK,MAAM,YAAY,UAAU;GAC/B,GAAG;GACH,GAAG;GACH,OAAO;IACL,GAAG,KAAK;IACR,GAAG,QAAQ;GACb;GACA,gBAAgB,YAAY;IAC1B,KAAK,SAAS,OAAO;IACrB,QAAQ,gBAAgB,OAAO;GACjC;EACF,EAAE;CACJ;AACF"}