({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType)
| 171 | env: PreviewEnv; |
| 172 | |
| 173 | constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) { |
| 174 | this.viewType = "preview"; |
| 175 | this.blockId = blockId; |
| 176 | this.nodeModel = nodeModel; |
| 177 | this.tabModel = tabModel; |
| 178 | this.env = waveEnv; |
| 179 | let showHiddenFiles = globalStore.get(this.env.getSettingsKeyAtom("preview:showhiddenfiles")) ?? true; |
| 180 | this.showHiddenFiles = atom<boolean>(showHiddenFiles); |
| 181 | this.refreshVersion = atom(0); |
| 182 | this.directorySearchActive = atom(false); |
| 183 | this.previewTextRef = createRef(); |
| 184 | this.openFileModal = atom(false); |
| 185 | this.openFileModalDelay = atom(false); |
| 186 | this.openFileError = atom(null) as PrimitiveAtom<string>; |
| 187 | this.openFileModalGiveFocusRef = createRef(); |
| 188 | this.manageConnection = atom(true); |
| 189 | this.blockAtom = this.env.wos.getWaveObjectAtom<Block>(`block:${blockId}`); |
| 190 | this.markdownShowToc = atom(false); |
| 191 | this.filterOutNowsh = atom(true); |
| 192 | this.monacoRef = createRef(); |
| 193 | this.connectionError = atom(""); |
| 194 | this.errorMsgAtom = atom(null) as PrimitiveAtom<ErrorMsg | null>; |
| 195 | this.viewIcon = atom((get) => { |
| 196 | const blockData = get(this.blockAtom); |
| 197 | if (blockData?.meta?.icon) { |
| 198 | return blockData.meta.icon; |
| 199 | } |
| 200 | const connStatus = get(this.connStatus); |
| 201 | if (connStatus?.status != "connected") { |
| 202 | return null; |
| 203 | } |
| 204 | const mimeTypeLoadable = get(this.fileMimeTypeLoadable); |
| 205 | const mimeType = jotaiLoadableValue(mimeTypeLoadable, ""); |
| 206 | if (mimeType == "directory") { |
| 207 | return { |
| 208 | elemtype: "iconbutton", |
| 209 | icon: "folder-open", |
| 210 | longClick: (e: React.MouseEvent<any>) => { |
| 211 | const menuItems: ContextMenuItem[] = BOOKMARKS.map((bookmark) => ({ |
| 212 | label: `Go to ${bookmark.label} (${bookmark.path})`, |
| 213 | click: () => this.goHistory(bookmark.path), |
| 214 | })); |
| 215 | ContextMenuModel.getInstance().showContextMenu(menuItems, e); |
| 216 | }, |
| 217 | }; |
| 218 | } |
| 219 | return iconForFile(mimeType); |
| 220 | }); |
| 221 | this.editMode = atom((get) => { |
| 222 | const blockData = get(this.blockAtom); |
| 223 | return blockData?.meta?.edit ?? false; |
| 224 | }); |
| 225 | this.viewName = atom("Preview"); |
| 226 | this.hideViewName = atom(true); |
| 227 | this.viewText = atom((get) => { |
| 228 | let headerPath = get(this.metaFilePath); |
| 229 | const connStatus = get(this.connStatus); |
| 230 | if (connStatus?.status != "connected") { |
nothing calls this directly
no test coverage detected