|
|
@@ -218,7 +218,7 @@ export class TLApp<
|
|
|
currentPageId: this.currentPageId,
|
|
|
selectedIds: Array.from(this.selectedIds.values()),
|
|
|
pages: Array.from(this.pages.values()).map(page => page.serialized),
|
|
|
- assets: Object.values(this.assets),
|
|
|
+ assets: this.getCleanUpAssets()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -340,6 +340,21 @@ export class TLApp<
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
+ getCleanUpAssets<T extends TLAsset>(): T[] {
|
|
|
+ let deleted = false
|
|
|
+ const usedAssets = new Set<T>()
|
|
|
+
|
|
|
+ this.pages.forEach(p =>
|
|
|
+ p.shapes.forEach(s => {
|
|
|
+ if (s.props.assetId && this.assets[s.props.assetId]) {
|
|
|
+ // @ts-expect-error ???
|
|
|
+ usedAssets.add(this.assets[s.props.assetId])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ return Array.from(usedAssets)
|
|
|
+ }
|
|
|
+
|
|
|
createAssets<T extends TLAsset>(assets: T[]): this {
|
|
|
this.addAssets(assets)
|
|
|
this.notify('create-assets', { assets })
|