* Open a folder in the sidebar * @param {string} _path * @param {object} opts * @param {string} opts.name * @param {string} [opts.id] * @param {boolean} [opts.saveState] * @param {boolean} [opts.listFiles] * @param {Map } [opts.listState]
(_path, opts = {})
| 126 | * @param {Map<string, boolean>} [opts.listState] |
| 127 | */ |
| 128 | function openFolder(_path, opts = {}) { |
| 129 | if (addedFolder.find((folder) => folder.url === _path)) { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | const saveState = opts.saveState ?? true; |
| 134 | const listState = opts.listState || {}; |
| 135 | const title = opts.name; |
| 136 | let listFiles = opts.listFiles; |
| 137 | |
| 138 | if (!title) { |
| 139 | throw new Error("Folder name is required"); |
| 140 | } |
| 141 | |
| 142 | const $root = collapsableList(title, "folder", { |
| 143 | allCaps: true, |
| 144 | ontoggle: () => expandList($root), |
| 145 | }); |
| 146 | const $text = $root.$title.get(":scope>span.text"); |
| 147 | |
| 148 | $root.id = "r" + _path.hashCode(); |
| 149 | $text.style.overflow = "hidden"; |
| 150 | $text.style.whiteSpace = "nowrap"; |
| 151 | $text.style.textOverflow = "ellipsis"; |
| 152 | $root.$title.dataset.type = "root"; |
| 153 | $root.$title.dataset.url = _path; |
| 154 | $root.$title.dataset.name = title; |
| 155 | |
| 156 | $root.$ul.onclick = |
| 157 | $root.$ul.oncontextmenu = |
| 158 | $root.$title.onclick = |
| 159 | $root.$title.oncontextmenu = |
| 160 | handleItems; |
| 161 | |
| 162 | recents.addFolder(_path, opts); |
| 163 | sidebarApps.get("files").append($root); |
| 164 | |
| 165 | const event = { |
| 166 | url: _path, |
| 167 | name: title, |
| 168 | }; |
| 169 | |
| 170 | const folder = { |
| 171 | title, |
| 172 | remove, |
| 173 | listFiles, |
| 174 | saveState, |
| 175 | listState, |
| 176 | url: _path, |
| 177 | $node: $root, |
| 178 | id: opts.id, |
| 179 | clipBoard: {}, |
| 180 | reload() { |
| 181 | $root.collapse(); |
| 182 | $root.expand(); |
| 183 | }, |
| 184 | }; |
| 185 |
no test coverage detected