@supernova-studio/client 1.0.0-alpha.2 → 1.0.0-alpha.3

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/dist/index.mjs CHANGED
@@ -12900,24 +12900,34 @@ var BackendVersionRoomYDoc = class {
12900
12900
  var LocalStorage = class {
12901
12901
  constructor() {
12902
12902
  __publicField(this, "pages", /* @__PURE__ */ new Map());
12903
+ __publicField(this, "deletedPageIds", /* @__PURE__ */ new Set());
12903
12904
  __publicField(this, "groups", /* @__PURE__ */ new Map());
12904
12905
  }
12905
- addPage(page) {
12906
+ setPage(page) {
12906
12907
  if (this.pages.has(page.persistentId)) {
12907
12908
  throw new Error(`Page with id ${page.persistentId} already exists`);
12908
12909
  }
12909
12910
  this.pages.set(page.persistentId, page);
12910
12911
  }
12912
+ deletePage(persistentId) {
12913
+ this.pages.delete(persistentId);
12914
+ this.deletedPageIds.add(persistentId);
12915
+ }
12916
+ tryGetPage(persistentId) {
12917
+ return this.pages.get(persistentId);
12918
+ }
12911
12919
  getPage(persistentId) {
12912
- const page = this.pages.get(persistentId);
12913
- if (!page) {
12920
+ const page = this.tryGetPage(persistentId);
12921
+ if (!page)
12914
12922
  throw new Error(`Page with id ${persistentId} doesn't exist`);
12915
- }
12916
12923
  return page;
12917
12924
  }
12918
12925
  getAllPages() {
12919
12926
  return Array.from(this.pages.values());
12920
12927
  }
12928
+ getAllDeletedPages() {
12929
+ return this.deletedPageIds;
12930
+ }
12921
12931
  removePage(persistentId) {
12922
12932
  this.pages.delete(persistentId);
12923
12933
  }
@@ -12960,7 +12970,7 @@ var DocsStructureRepository = class {
12960
12970
  void this.createPage(input);
12961
12971
  }
12962
12972
  createPagePromise(input) {
12963
- this.localState.addPage({
12973
+ this.localState.setPage({
12964
12974
  createdAt: /* @__PURE__ */ new Date(),
12965
12975
  parentPersistentId: input.parentPersistentId,
12966
12976
  persistentId: input.persistentId,
@@ -12972,7 +12982,8 @@ var DocsStructureRepository = class {
12972
12982
  sortOrder: this.calculateSortOrder(input.parentPersistentId, input.afterPersistentId),
12973
12983
  designSystemVersionId: ""
12974
12984
  });
12975
- const promise = this.trxQueue.enqueue({
12985
+ this.recalculateHierarchy();
12986
+ return this.trxQueue.enqueue({
12976
12987
  type: "DocumentationPageCreate",
12977
12988
  input: {
12978
12989
  persistentId: input.persistentId,
@@ -12982,19 +12993,81 @@ var DocsStructureRepository = class {
12982
12993
  configuration: input.configuration
12983
12994
  }
12984
12995
  });
12996
+ }
12997
+ updatePage(update) {
12998
+ void this.updatePagePromise(update);
12999
+ }
13000
+ updatePagePromise(update) {
13001
+ this.updatePageLocally(update);
13002
+ this.recalculateHierarchy();
13003
+ return this.trxQueue.enqueue({
13004
+ type: "DocumentationPageUpdate",
13005
+ input: {
13006
+ id: update.persistentId,
13007
+ configuration: update.configuration,
13008
+ title: update.title
13009
+ }
13010
+ });
13011
+ }
13012
+ updatePageLocally(update) {
13013
+ const basePage = this.lookupPage(update.persistentId);
13014
+ this.localState.setPage(this.createLocalPageUpdate(basePage, update));
13015
+ }
13016
+ deletePagePromise(persistentId) {
13017
+ this.lookupPage(persistentId);
13018
+ this.localState.deletePage(persistentId);
12985
13019
  this.recalculateHierarchy();
12986
- return promise;
13020
+ return this.trxQueue.enqueue({
13021
+ type: "DocumentationPageDelete",
13022
+ input: {
13023
+ id: persistentId
13024
+ }
13025
+ });
13026
+ }
13027
+ deletePage(persistentId) {
13028
+ void this.deletePagePromise(persistentId);
13029
+ }
13030
+ createLocalPageUpdate(basePage, update) {
13031
+ const { title, configuration } = update;
13032
+ return {
13033
+ createdAt: basePage.createdAt,
13034
+ data: {
13035
+ configuration: configuration ?? basePage.data.configuration
13036
+ },
13037
+ designSystemVersionId: basePage.designSystemVersionId,
13038
+ meta: { name: title ?? basePage.meta.name },
13039
+ parentPersistentId: basePage.parentPersistentId,
13040
+ persistentId: basePage.persistentId,
13041
+ shortPersistentId: basePage.shortPersistentId,
13042
+ sortOrder: basePage.sortOrder,
13043
+ updatedAt: /* @__PURE__ */ new Date(),
13044
+ slug: basePage.slug
13045
+ };
13046
+ }
13047
+ lookupPage(persistentId) {
13048
+ const localPageToUpdate = this.localState.tryGetPage(persistentId);
13049
+ if (localPageToUpdate)
13050
+ return localPageToUpdate;
13051
+ const remotePage = this.yState.pages.find((p) => p.persistentId === persistentId);
13052
+ if (remotePage)
13053
+ return remotePage;
13054
+ throw SupernovaException.notFound(`Page ${persistentId} was not found`);
12987
13055
  }
12988
13056
  //
12989
13057
  // Reactions
12990
13058
  //
12991
13059
  recalculateHierarchy() {
13060
+ const allPagesById = mapByUnique(this.yState.pages, (p) => p.persistentId);
13061
+ this.localState.getAllPages().forEach((p) => {
13062
+ allPagesById.set(p.persistentId, p);
13063
+ });
13064
+ this.localState.getAllDeletedPages().forEach((id) => allPagesById.delete(id));
12992
13065
  const hierarchy = computeDocsHierarchy({
12993
13066
  approvals: this.yState.approvals,
12994
13067
  groups: this.yState.groups,
12995
13068
  groupSnapshots: this.yState.groupSnapshots,
12996
13069
  pageContentHashes: this.yState.pageContentHashes,
12997
- pages: [...this.yState.pages, ...this.localState.getAllPages()],
13070
+ pages: Array.from(allPagesById.values()),
12998
13071
  pageSnapshots: this.yState.pageSnapshots,
12999
13072
  settings: this.yState.settings
13000
13073
  });