MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createFolderElement

Method createFolderElement

src/components/fileTree/index.js:121–252  ·  view source on GitHub ↗

* Create folder element (collapsible) * @param {string} name * @param {string} url * @param {HTMLElement} [recycledEl] - Optional recycled element for reuse * @returns {HTMLElement}

(name, url, recycledEl)

Source from the content-addressed store, hash-verified

119 * @returns {HTMLElement}
120 */
121 createFolderElement(name, url, recycledEl) {
122 // Try to recycle existing folder element
123 if (recycledEl && recycledEl.classList.contains("collapsible")) {
124 const $title = recycledEl.$title;
125 if ($title) {
126 $title.dataset.url = url;
127 $title.dataset.name = name;
128 const textEl = $title.querySelector(".text");
129 if (textEl) textEl.textContent = name;
130
131 // Collapse if expanded and clear children
132 if (!recycledEl.classList.contains("hidden")) {
133 recycledEl.classList.add("hidden");
134 const childTree = this.childTrees.get(recycledEl._folderUrl);
135 if (childTree) {
136 childTree.destroy();
137 this.childTrees.delete(recycledEl._folderUrl);
138 }
139 recycledEl.$ul.innerHTML = "";
140 }
141
142 recycledEl._folderUrl = url;
143 return recycledEl;
144 }
145 }
146
147 const $wrapper = tag("div", {
148 className: "list collapsible hidden",
149 });
150 $wrapper._folderUrl = url;
151
152 const $indicator = tag("span", { className: "icon folder" });
153
154 const $title = tile({
155 lead: $indicator,
156 type: "div",
157 text: name,
158 });
159
160 $title.classList.add("light");
161 $title.dataset.url = url;
162 $title.dataset.name = name;
163 $title.dataset.type = "dir";
164
165 const $content = tag("ul", { className: "scroll folder-content" });
166 $wrapper.append($title, $content);
167
168 // Child file tree for nested folders
169 let childTree = null;
170 $content._fileTree = null;
171
172 const toggle = async () => {
173 const isExpanded = !$wrapper.classList.contains("hidden");
174
175 if (isExpanded) {
176 // Collapse
177 $wrapper.classList.add("hidden");
178

Callers 1

createEntryElementMethod · 0.95

Calls 8

tileFunction · 0.85
addMethod · 0.80
appendMethod · 0.80
deleteMethod · 0.65
toggleFunction · 0.50
getMethod · 0.45
destroyMethod · 0.45
stopPropagationMethod · 0.45

Tested by

no test coverage detected