@supernova-studio/client 1.0.0-alpha.3 → 1.0.0-alpha.5
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.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +68 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8074,12 +8074,15 @@ var VersionRoomBaseYDoc = class {
|
|
|
8074
8074
|
this.yDoc = yDoc;
|
|
8075
8075
|
}
|
|
8076
8076
|
getState() {
|
|
8077
|
+
const groups = this.getGroups();
|
|
8078
|
+
const isLoaded = !!groups.length;
|
|
8077
8079
|
return {
|
|
8080
|
+
isLoaded,
|
|
8081
|
+
groups,
|
|
8082
|
+
pages: this.getPages(),
|
|
8078
8083
|
approvals: this.getApprovals(),
|
|
8079
|
-
groups: this.getGroups(),
|
|
8080
8084
|
groupSnapshots: this.getGroupSnapshots(),
|
|
8081
8085
|
pageContentHashes: this.getDocumentationPageContentHashes(),
|
|
8082
|
-
pages: this.getPages(),
|
|
8083
8086
|
pageSnapshots: this.getPageSnapshots(),
|
|
8084
8087
|
settings: this.getDocumentationInternalSettings()
|
|
8085
8088
|
};
|
|
@@ -12941,19 +12944,42 @@ var DocsStructureRepository = class {
|
|
|
12941
12944
|
__publicField(this, "localState", new LocalStorage());
|
|
12942
12945
|
__publicField(this, "yDoc");
|
|
12943
12946
|
__publicField(this, "yObserver");
|
|
12944
|
-
__publicField(this, "
|
|
12947
|
+
__publicField(this, "_yState");
|
|
12948
|
+
__publicField(this, "_currentHierarchy");
|
|
12945
12949
|
__publicField(this, "trxQueue");
|
|
12946
12950
|
__publicField(this, "hierarchyObservers", /* @__PURE__ */ new Set());
|
|
12951
|
+
__publicField(this, "initCallbacks", /* @__PURE__ */ new Set());
|
|
12947
12952
|
this.yDoc = yDoc;
|
|
12948
|
-
this.yState = new VersionRoomBaseYDoc(this.yDoc).getState();
|
|
12949
12953
|
this.yObserver = yDoc.on("update", () => this.onYUpdate());
|
|
12954
|
+
this.onYUpdate();
|
|
12950
12955
|
this.trxQueue = new TransactionQueue(transactionExecutor);
|
|
12951
12956
|
}
|
|
12952
12957
|
//
|
|
12958
|
+
// Convenience
|
|
12959
|
+
//
|
|
12960
|
+
get yState() {
|
|
12961
|
+
const yState = this._yState;
|
|
12962
|
+
if (!yState)
|
|
12963
|
+
throw SupernovaException.shouldNotHappen(`Accessing Y state before it was loaded`);
|
|
12964
|
+
return yState;
|
|
12965
|
+
}
|
|
12966
|
+
//
|
|
12953
12967
|
// Lifecycle
|
|
12954
12968
|
//
|
|
12969
|
+
get isInitialized() {
|
|
12970
|
+
return !!this._currentHierarchy;
|
|
12971
|
+
}
|
|
12972
|
+
onInitialized() {
|
|
12973
|
+
if (this.isInitialized)
|
|
12974
|
+
return Promise.resolve();
|
|
12975
|
+
return new Promise((resolve) => {
|
|
12976
|
+
this.initCallbacks.add(resolve);
|
|
12977
|
+
});
|
|
12978
|
+
}
|
|
12955
12979
|
addHierarchyObserver(observer) {
|
|
12956
12980
|
this.hierarchyObservers.add(observer);
|
|
12981
|
+
if (this._currentHierarchy)
|
|
12982
|
+
observer(this._currentHierarchy);
|
|
12957
12983
|
}
|
|
12958
12984
|
removeHierarchyObserver(observer) {
|
|
12959
12985
|
this.hierarchyObservers.delete(observer);
|
|
@@ -12964,6 +12990,15 @@ var DocsStructureRepository = class {
|
|
|
12964
12990
|
this.trxQueue.clear();
|
|
12965
12991
|
}
|
|
12966
12992
|
//
|
|
12993
|
+
// Accessors
|
|
12994
|
+
//
|
|
12995
|
+
get currentHierarchy() {
|
|
12996
|
+
const hierarchy = this._currentHierarchy;
|
|
12997
|
+
if (!hierarchy)
|
|
12998
|
+
throw new Error(`Hierarchy cannot be accessed while it's still loading`);
|
|
12999
|
+
return hierarchy;
|
|
13000
|
+
}
|
|
13001
|
+
//
|
|
12967
13002
|
// Actions
|
|
12968
13003
|
//
|
|
12969
13004
|
createPage(input) {
|
|
@@ -12982,7 +13017,7 @@ var DocsStructureRepository = class {
|
|
|
12982
13017
|
sortOrder: this.calculateSortOrder(input.parentPersistentId, input.afterPersistentId),
|
|
12983
13018
|
designSystemVersionId: ""
|
|
12984
13019
|
});
|
|
12985
|
-
this.
|
|
13020
|
+
this.refreshHierarchy();
|
|
12986
13021
|
return this.trxQueue.enqueue({
|
|
12987
13022
|
type: "DocumentationPageCreate",
|
|
12988
13023
|
input: {
|
|
@@ -12999,7 +13034,7 @@ var DocsStructureRepository = class {
|
|
|
12999
13034
|
}
|
|
13000
13035
|
updatePagePromise(update) {
|
|
13001
13036
|
this.updatePageLocally(update);
|
|
13002
|
-
this.
|
|
13037
|
+
this.refreshHierarchy();
|
|
13003
13038
|
return this.trxQueue.enqueue({
|
|
13004
13039
|
type: "DocumentationPageUpdate",
|
|
13005
13040
|
input: {
|
|
@@ -13016,7 +13051,7 @@ var DocsStructureRepository = class {
|
|
|
13016
13051
|
deletePagePromise(persistentId) {
|
|
13017
13052
|
this.lookupPage(persistentId);
|
|
13018
13053
|
this.localState.deletePage(persistentId);
|
|
13019
|
-
this.
|
|
13054
|
+
this.refreshHierarchy();
|
|
13020
13055
|
return this.trxQueue.enqueue({
|
|
13021
13056
|
type: "DocumentationPageDelete",
|
|
13022
13057
|
input: {
|
|
@@ -13056,26 +13091,41 @@ var DocsStructureRepository = class {
|
|
|
13056
13091
|
//
|
|
13057
13092
|
// Reactions
|
|
13058
13093
|
//
|
|
13059
|
-
|
|
13060
|
-
const
|
|
13094
|
+
refreshHierarchy() {
|
|
13095
|
+
const hierarchy = this.calculateHierarchy();
|
|
13096
|
+
if (!hierarchy)
|
|
13097
|
+
return;
|
|
13098
|
+
this._currentHierarchy = hierarchy;
|
|
13099
|
+
this.initCallbacks.forEach((f) => f());
|
|
13100
|
+
this.initCallbacks.clear();
|
|
13101
|
+
this.hierarchyObservers.forEach((o) => o(hierarchy));
|
|
13102
|
+
}
|
|
13103
|
+
calculateHierarchy() {
|
|
13104
|
+
const yState = this._yState;
|
|
13105
|
+
if (!yState)
|
|
13106
|
+
return;
|
|
13107
|
+
const allPagesById = mapByUnique(yState.pages, (p) => p.persistentId);
|
|
13061
13108
|
this.localState.getAllPages().forEach((p) => {
|
|
13062
13109
|
allPagesById.set(p.persistentId, p);
|
|
13063
13110
|
});
|
|
13064
13111
|
this.localState.getAllDeletedPages().forEach((id) => allPagesById.delete(id));
|
|
13065
13112
|
const hierarchy = computeDocsHierarchy({
|
|
13066
|
-
approvals:
|
|
13067
|
-
groups:
|
|
13068
|
-
groupSnapshots:
|
|
13069
|
-
pageContentHashes:
|
|
13113
|
+
approvals: yState.approvals,
|
|
13114
|
+
groups: yState.groups,
|
|
13115
|
+
groupSnapshots: yState.groupSnapshots,
|
|
13116
|
+
pageContentHashes: yState.pageContentHashes,
|
|
13070
13117
|
pages: Array.from(allPagesById.values()),
|
|
13071
|
-
pageSnapshots:
|
|
13072
|
-
settings:
|
|
13118
|
+
pageSnapshots: yState.pageSnapshots,
|
|
13119
|
+
settings: yState.settings
|
|
13073
13120
|
});
|
|
13074
|
-
|
|
13121
|
+
return hierarchy;
|
|
13075
13122
|
}
|
|
13076
13123
|
onYUpdate() {
|
|
13077
|
-
|
|
13078
|
-
|
|
13124
|
+
const newState = new VersionRoomBaseYDoc(this.yDoc).getState();
|
|
13125
|
+
if (newState.groups.length) {
|
|
13126
|
+
this._yState = newState;
|
|
13127
|
+
this.refreshHierarchy();
|
|
13128
|
+
}
|
|
13079
13129
|
}
|
|
13080
13130
|
//
|
|
13081
13131
|
// Utils
|