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

Method constructor

src/lib/editorFile.js:446–513  ·  view source on GitHub ↗

* * @param {string} [filename] name of file. * @param {FileOptions} [options] file create options

(filename, options)

Source from the content-addressed store, hash-verified

444 * @param {FileOptions} [options] file create options
445 */
446 constructor(filename, options) {
447 const { addFile, getFile } = editorManager;
448 let doesExists = null;
449
450 this.hideQuickTools = options?.hideQuickTools || false;
451
452 // if options are passed
453 if (options) {
454 // if options doesn't contains id, and provide a new id
455 if (!options.id) {
456 if (options.uri) this.#id = options.uri.hashCode();
457 else this.#id = helpers.uuid();
458 } else this.#id = options.id;
459 } else if (!options) {
460 // if options aren't passed, that means default file is being created
461 this.#id = config.DEFAULT_FILE_SESSION;
462 }
463
464 if (options?.type) {
465 this.#type = options.type;
466 if (this.#type !== "editor") {
467 let container;
468 let shadow;
469
470 if (this.#type === "terminal") {
471 container = tag("div", {
472 className: "tab-page-container",
473 });
474 const content = tag("div", {
475 className: "tab-page-content",
476 });
477 content.appendChild(options?.content);
478 container.appendChild(content);
479 this.#content = container;
480 } else {
481 container = <div className="tab-page-container" />;
482
483 // shadow dom
484 shadow = container.attachShadow({ mode: "open" });
485
486 // Add base styles to shadow DOM first
487 shadow.appendChild(<link rel="stylesheet" href="build/main.css" />);
488
489 // Handle custom stylesheets if provided
490 if (options.stylesheets) {
491 this.#addCustomStyles(options.stylesheets, shadow);
492 }
493
494 const content = <div className="tab-page-content" />;
495
496 if (typeof options.content === "string") {
497 content.innerHTML = DOMPurify.sanitize(options.content);
498 } else {
499 content.appendChild(options.content);
500 }
501
502 // Append content container to shadow DOM
503 shadow.appendChild(content);

Callers

nothing calls this directly

Calls 2

hashCodeMethod · 0.80
ifFunction · 0.50

Tested by

no test coverage detected