MCPcopy
hub / github.com/codex-team/editor.js / make

Method make

src/components/dom.ts:57–75  ·  view source on GitHub ↗

* Helper for making Elements with class name and attributes * * @param {string} tagName - new Element tag name * @param {string[]|string} [classNames] - list or name of CSS class name(s) * @param {object} [attributes] - any attributes * @returns {HTMLElement}

(tagName: string, classNames: string | (string | undefined)[] | null = null, attributes: object = {})

Source from the content-addressed store, hash-verified

55 * @returns {HTMLElement}
56 */
57 public static make(tagName: string, classNames: string | (string | undefined)[] | null = null, attributes: object = {}): HTMLElement {
58 const el = document.createElement(tagName);
59
60 if (Array.isArray(classNames)) {
61 const validClassnames = classNames.filter(className => className !== undefined) as string[];
62
63 el.classList.add(...validClassnames);
64 } else if (classNames) {
65 el.classList.add(classNames);
66 }
67
68 for (const attrName in attributes) {
69 if (Object.prototype.hasOwnProperty.call(attributes, attrName)) {
70 el[attrName] = attributes[attrName];
71 }
72 }
73
74 return el;
75 }
76
77 /**
78 * Creates Text Node with the passed content

Callers 4

renderMethod · 0.45
copyTextToClipboardFunction · 0.45
addFakeCursorMethod · 0.45
isHTMLStringMethod · 0.45

Calls 2

callMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected