{"version":3,"file":"ListViewMode.mjs","names":[],"sources":["../../../../../../../../components-base/src/list/viewMode/ListViewMode.ts"],"sourcesContent":["import { action, makeObservable, observable } from \"mobx\";\nimport type { ListViewModeOptions, ListViewModeValue } from \"./types\";\n\n/**\n * Which layout the list is in, and its persistence.\n *\n * The value is a MobX observable rather than a binding's own state, so that the\n * rule it obeys — a stored mode wins over the default, and a change is written\n * back — is one implementation. A binding brings the subscription:\n * `useSelector` in React, `watchMobxValue` in Vue.\n */\nexport class ListViewMode {\n  public value: ListViewModeValue;\n  private storage: Pick<ListViewModeOptions, \"autosave\" | \"settings\">;\n\n  public constructor(options: ListViewModeOptions = {}) {\n    const { defaultValue, ...storage } = options;\n\n    this.storage = storage;\n    this.value =\n      this.storage.settings?.get(\"viewMode\", { autosave: this.autosave }) ??\n      defaultValue ??\n      \"list\";\n\n    makeObservable(this, {\n      value: observable,\n      set: action.bound,\n    });\n  }\n\n  public get autosave(): boolean {\n    return this.storage.autosave ?? true;\n  }\n\n  /**\n   * Where a change is written, for a binding whose list can change it without a\n   * new model — React rebuilds the list every render, the view mode lives on.\n   * The value itself is read only once, at construction.\n   */\n  public updateStorage(\n    storage: Pick<ListViewModeOptions, \"autosave\" | \"settings\">,\n  ): void {\n    this.storage = storage;\n  }\n\n  public get isTiles(): boolean {\n    return this.value === \"tiles\";\n  }\n\n  public get isTable(): boolean {\n    return this.value === \"table\";\n  }\n\n  public get isList(): boolean {\n    return this.value === \"list\";\n  }\n\n  public set(viewMode: ListViewModeValue): void {\n    this.value = viewMode;\n    this.storage.settings?.store(\"viewMode\", viewMode, {\n      autosave: this.autosave,\n    });\n  }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,eAAb,MAA0B;CACxB;CACA;CAEA,YAAmB,UAA+B,CAAC,GAAG;EACpD,MAAM,EAAE,cAAc,GAAG,YAAY;EAErC,KAAK,UAAU;EACf,KAAK,QACH,KAAK,QAAQ,UAAU,IAAI,YAAY,EAAE,UAAU,KAAK,SAAS,CAAC,KAClE,gBACA;EAEF,eAAe,MAAM;GACnB,OAAO;GACP,KAAK,OAAO;EACd,CAAC;CACH;CAEA,IAAW,WAAoB;EAC7B,OAAO,KAAK,QAAQ,YAAY;CAClC;;;;;;CAOA,cACE,SACM;EACN,KAAK,UAAU;CACjB;CAEA,IAAW,UAAmB;EAC5B,OAAO,KAAK,UAAU;CACxB;CAEA,IAAW,UAAmB;EAC5B,OAAO,KAAK,UAAU;CACxB;CAEA,IAAW,SAAkB;EAC3B,OAAO,KAAK,UAAU;CACxB;CAEA,IAAW,UAAmC;EAC5C,KAAK,QAAQ;EACb,KAAK,QAAQ,UAAU,MAAM,YAAY,UAAU,EACjD,UAAU,KAAK,SACjB,CAAC;CACH;AACF"}