* open or create a document
(idOrDoc?: string | Document | RootSchema)
| 181 | * open or create a document |
| 182 | */ |
| 183 | open(idOrDoc?: string | Document | RootSchema) { |
| 184 | if (!idOrDoc) { |
| 185 | const got = this.documents.find(item => item.isBlank()) |
| 186 | if (got) { |
| 187 | return got.open() |
| 188 | } |
| 189 | return this.createDocument().open() |
| 190 | } |
| 191 | |
| 192 | if (typeof idOrDoc === 'string' || typeof idOrDoc === 'number') { |
| 193 | const got = this.documents.find(item => item.fileName === String(idOrDoc) || String(item.id) === String(idOrDoc)) |
| 194 | if (got) { |
| 195 | return got.open() |
| 196 | } |
| 197 | |
| 198 | const data = this.data.componentsTree.find(data => data.fileName === String(idOrDoc)) |
| 199 | if (data) { |
| 200 | const doc = this.createDocument(data) |
| 201 | return doc.open() |
| 202 | } |
| 203 | |
| 204 | return null |
| 205 | } |
| 206 | if (isDocument(idOrDoc)) { |
| 207 | return idOrDoc.open() |
| 208 | } |
| 209 | |
| 210 | const newDoc = this.createDocument(idOrDoc) |
| 211 | return newDoc.open() |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * suspense other documents |
no test coverage detected