1.0.45 • Published 2 years ago

tzer v1.0.45

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

TZer - Web Components Micro Framework

** WIP **

Node.js CI

Purpose

WC is not the most dev-friendly API, but still I ran into cases I need a custom WC without using a framework.

How It Works

TZer rely on decorators declaration to compile the component into a JS CustomElement Class and then bundle all using esbuild.

Features

  • 100% native vanilla js code - no libraries!
  • Manging attribute easily - with observed attributes.
  • Event binding.
  • Supporting all WC lifecycles - added multiple callbacks.
  • SCSS/SASS.
  • Minifying & Optimizing.
  • No Shadow Dom - partially encapsulated.
  • Supporting imports - from utils folder - WIP
  • Seed project generator from cli.

Install

npm i -g tzer
npx tzer init newProject
cd newProject
npm i
npm run dev

Compiling

Run npx tzer compile.

Importing

Import like any other js file.

Config

// tzer.config.ts

import { ExampleComponent } from "./example/component";

export default {
  components: [ExampleComponent]
}

CLI

  • tzer init PROJECT_NAME - create a new TZer project.
  • tzer generate COMPONENT_NAME - create a new component.

Project NPM Commands

  • dev run a dev server, watch & environment
  • build build final output
  • tzer:build:debug build debuggable output before bundling and renaming
  • tzer:build:dev build debuggable output after bundling and renaming

Decorators

@TzerComponent({componentElementTag: string, style: string, domHelpers?: boolean})

Main declaration of a component.

@TzerAttribute({observed?: boolean})

Create an element attribute, with getter and setter.

Attribute can set to observed to invoke the attributeChangedCallback(optional).

@TzerAttributeChangedCallback(attribute?: string)

Trigger whenever an observed attribute has changed.

attribute(optional) the callback will run only for that attribute change, otherwise for all changes.

@TzerConnectedCallback()

Trigger whenever the component has mounted in the document.

@TzerDisconnectedCallback()

Trigger whenever the component has dismounted from the document.

@TzerAdoptedCallback()

Trigger whenever the component has moved to a new document.

@TzerEventBind(eventName: string)

Binds a method to a custom event.

Example Component

// component.ts

import {
  TzerAdoptedCallback,
  TzerAttribute,
  TzerAttributeChangedCallback,
  TzerComponent,
  TzerConnectedCallback,
  TzerDisconnectedCallback, TzerEventBind
} from "tzer";

@TzerComponent({ 
  componentElementTag: 'tzer-example-component',
  style: './src/example/example.scss'
})
export class Example {
  declare container: HTMLElement;
  declare DOM: TzerDOM;

  @TzerAttribute({ observed: true })
  testattr: string | undefined;

  @TzerConnectedCallback()
  connected() {
    console.log('connected!');
  }

  @TzerDisconnectedCallback()
  disconnected() {
    console.log('disconnected!');
  }

  @TzerAdoptedCallback()
  adopted() {
    console.log('adopted!');
  }

  @TzerEventBind('click')
  eventListener() {
    console.log('clicked!');
  }

  @TzerConnectedCallback()
  @TzerAttributeChangedCallback()
  render() {
    this.container.innerHTML = `<p>Hello ${this.testattr}!</p>`;
  }
}
1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago