{"id":23024453,"url":"https://github.com/thipages/m-element","last_synced_at":"2026-02-12T02:08:06.042Z","repository":{"id":260914813,"uuid":"882554582","full_name":"thipages/m-element","owner":"thipages","description":"custom-element class with (a)sync loading, slots, error handling and level-up","archived":false,"fork":false,"pushed_at":"2024-12-25T08:56:46.000Z","size":32,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T09:15:33.059Z","etag":null,"topics":["asynchronous","custom-elements","error-handling","level-up","life-cycle","load-event-handling","slots","synchronous"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thipages.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-03T05:00:15.000Z","updated_at":"2024-12-25T08:56:17.000Z","dependencies_parsed_at":"2025-05-31T23:02:24.717Z","dependency_job_id":"a67a9d94-9720-4df5-83cc-d43f8d2d4d10","html_url":"https://github.com/thipages/m-element","commit_stats":null,"previous_names":["thipages/define-parsed-element","thipages/m-element"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/thipages/m-element","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fm-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fm-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fm-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fm-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thipages","download_url":"https://codeload.github.com/thipages/m-element/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fm-element/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260133673,"owners_count":22963767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","custom-elements","error-handling","level-up","life-cycle","load-event-handling","slots","synchronous"],"created_at":"2024-12-15T13:18:44.946Z","updated_at":"2026-02-12T02:08:01.012Z","avatar_url":"https://github.com/thipages.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# m-element\n\n`MElement` class extends [HTMLParsedElement](https://github.com/WebReflection/html-parsed-element) with the following addition:\n- constructor argument\n  - `{ onLoadHtml }` html string used in async initialization (default ''),\n  - `{ onErrorHtml }` html string used for async errors (default ''),\n- methods\n  - `init()` (sync or async) called by `parsedCallback`\n  - `originalText(remove)` for getting the original `textContent`,\n  - `originalFragment(remove)` for getting the original `childNodes` appended to a document fragment,\n    - `remove` argument to delete from memory the text or fragment (default : true),\n  - `getSlotByName(name)` to get all mamed slots present as custom-element children but removed and stored for later use,\n- events\n  - `onload` triggers when async init finishes (sync init also)\n- attributes\n  - a boolean `level-up` attribute to replace the *just created* custom-element by its children.\n\n\n## Usage\n\n``` javascript\nimport MElement from `@titsoft/m-element`\n\ncustomElements.define('a-custom-element', class extends MElement {\n    constructor () {\n        super() \n        // or super( { onLoadHtml: '\u003cp\u003ea waiting message\u003c/p\u003e' } )\n    }\n    init() {}\n    // or async init() {}\n})\n\n```\n\u003e - Do not call `connectedCallback` or `parsedCallback` or override them,\n\u003e - Use `disconnectedCallback` or `attributeChangedCallback` as usual\n``` html\n\u003ca-custom-element\u003e\u003c/a-custom-element\u003e\n```\n\n### level-up attribute example\n``` javascript\nimport MElement from `@titsoft/m-element`\n\ncustomElements.define('a-custom-element', class extends MElement {\n    constructor () {\n        super()\n    }\n    // or async init() {}\n    init() {\n        this.innerHTML = `\n            \u003cdiv\u003eI will replace my transient parent\u003c/div\u003e\n            \u003cdiv\u003eThis one as well\u003c/div\u003e\n        `\n    }\n})\n```\n```html\n\u003c!-- finally, this will create the two divs only --\u003e\n\u003ca-custom-element level-up\u003e\u003c/a-custom-element\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fm-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthipages%2Fm-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fm-element/lists"}