Detalhes do pacote

@substrate-system/tonic

substrate-system160MIT16.0.16

A component framework.

readme (leia-me)

tests GZip size install size dependencies module semantic versioning Common Changelog license

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/substrate-system/tonic/fork/readme-tonic-dark.png"> <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/substrate-system/tonic/fork/readme-tonic.png"> tonic </picture>

https://tonicframework.dev



Tonic is a low profile component framework for the web. It's one file, less than 3kb gzipped and has no dependencies. It's designed to be used with modern Javascript and is compatible with all modern browsers and built on top of Web Components.

See the API docs

<summary>

Contents

</summary> - Install - tl;dr - Use Bundler Pre-bundled - Examples - fork docs types tag emit static event dispatch - Useful links

Install

npm i -S @substrate-system/tonic

tl;dr

You can pass full JS objects into components, not just strings, as in HTML.

Use

Bundler

import Tonic from '@substrate-system/tonic'

Pre-bundled

This package exposes minified JS files too. Copy them so they are accessible to your web server, then link to them in HTML.

Copy

cp ./node_modules/@substrate-system/tonic/dist/index.min.js ./public/tonic.min.js

HTML

<script type="module" src="./tonic.min.js"></script>

Examples

You can use functions as components. They can be async or even an async generator function.

async function MyGreeting () {
  const data = await (await fetch('https://example.com/data')).text()
  return this.html`<h1>Hello, ${data}</h1>`
}

Or you can use classes. Every class must have a render method.

class MyGreeting extends Tonic {
  async * render () {
    yield this.html`<div>Loading...</div>`

    const data = await (await fetch('https://example.com/data')).text()
    return this.html`<div>Hello, ${data}.</div>`
  }
}
Tonic.add(MyGreeting, 'my-greeting')

After adding your Javascript to your HTML, you can use your component anywhere.

<html>
  <head>
    <script src="my-greeting.js"></script>
  </head>
  <body>
    <my-greeting></my-greeting>
  </body>
</html>

fork

This is a fork of @socketsupply/tonic.

docs

See API docs.

types

See src/index.ts.

tag

Get the HTML tag name given a Tonic class.

static get tag():string;
class ExampleTwo extends Tonic {
    render () {
        return this.html`<div>example two</div>`
    }
}

ExampleTwo.tag
// => 'example-two'

emit

Emit namespaced events, following a naming convention. The return value is the call to element.dispatchEvent().

Given an event name, the dispatched event will be prefixed with the element name, for example, my-element:event-name.

emit (type:string, detail:string|object|any[] = {}, opts:Partial<{
    bubbles:boolean;
    cancelable:boolean
}> = {}):boolean

emit example

class EventsExample extends Tonic {
  // ...
}

// EventsExample.event('name') will return the namespace event name
const evName = EventsExample.event('testing')

document.body.addEventListener(evName, ev => {
  // events bubble by default
  console.log(ev.type)  // => 'events-example:testing'
  console.log(ev.detail)  // => 'some data'
})

const el = document.querySelector('events-example')
// use default values for `bubbles = true` and `cancelable = true`
el.emit('testing', 'some data')

// override default values, `bubbles` and `cancelable`
el.emit('more testing', 'some data', {
  bubbles: false
  cancelable: false
})

static event

Return the namespaced event name given a string.

class {
  static event (type:string):string {
      return `${this.tag}:${type}`
  }
}

example

class EventsExample extends Tonic {
  // ...
}

EventsExample.event('testing')
//  => 'events-example:testing'

dispatch

Emit a regular, non-namespaced event.

{
  dispatch (eventName:string, detail = null):void
}

dispatch example

class EventsExample extends Tonic {
  // ...
}

document.body.addEventListener('testing', ev => {
  // events bubble by default
  console.log(ev.type)  // => 'testing'
  console.log(ev.detail)  // => 'some data'
})

const el = document.querySelector('events-example')
el.dispatch('testing', 'some data')

// override default values
el.dispatch('more testing', 'some data', {
  bubbles: false
  cancelable: false
})

Useful links

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Generated by auto-changelog.

v16.0.16

Commits

v16.0.15 - 2025-05-11

Commits

v16.0.14 - 2025-05-11

Commits

v16.0.13 - 2025-05-11

Commits

v16.0.12 - 2025-05-11

Commits

v16.0.11 - 2025-05-10

Commits

v16.0.10 - 2025-05-10

Commits

v16.0.9 - 2025-03-03

Commits

v16.0.8 - 2025-03-03

Commits

v16.0.7 - 2024-11-25

Commits

v16.0.6 - 2024-10-29

Commits

v16.0.5 - 2024-09-16

v16.0.4 - 2024-09-16

v16.0.3 - 2024-09-16

Commits

v16.0.2 - 2024-09-09

Commits

v16.0.1 - 2024-09-09

Commits

v16.0.0 - 2024-09-09

Commits

v15.5.8 - 2024-09-08

Commits

v15.5.7 - 2024-09-08

Commits

v15.5.6 - 2024-09-08

Commits

v15.5.5 - 2024-09-01

v15.5.4 - 2024-09-01

Commits

v15.5.3 - 2024-07-25

Commits

v15.5.2 - 2024-07-25

Commits

v15.5.1 - 2024-07-25

Commits

v15.5.0 - 2024-07-07

Commits

v15.4.17 - 2024-06-13

Commits

v15.4.16 - 2024-05-13

Commits

v15.4.15 - 2024-05-12

Commits

v15.4.14 - 2024-05-04

Commits

v15.4.13 - 2024-05-04

Commits

v15.4.12 - 2024-05-04

Commits

v15.4.11 - 2024-04-06

Commits

v15.4.10 - 2024-04-06

Commits

v15.4.9 - 2024-04-06

Commits

v15.4.8 - 2024-04-06

Commits

v15.4.7 - 2024-04-06

Commits

v15.4.6 - 2024-04-06

Commits

v15.4.5 - 2024-04-06

v15.4.4 - 2024-04-06

Commits

  • expand tonic component type 4055488

v15.4.3 - 2024-04-06

Commits

v15.4.2 - 2024-04-05

Commits

v15.4.1 - 2024-04-05

Commits

v15.4.0 - 2024-04-05

Commits

v15.3.4 - 2023-12-25

Commits

v15.3.3 - 2023-12-25

Commits

v15.3.2 - 2023-12-25

Commits

v15.3.1 - 2023-12-22

Commits

v15.3.0 - 2023-12-22

Commits

v15.2.0 - 2023-12-22

Merged

  • Support placeholders on File instances #121

Commits

v15.1.8 - 2023-12-21

Commits

v15.1.7 - 2023-11-10

Commits

v15.1.6 - 2023-11-09

Commits

v15.1.5 - 2023-11-09

Commits

v15.1.4 - 2023-11-09

Merged

  • Bump actions/setup-node from 3 to 4 #120
  • Add dark mode logo #116

Commits

v15.1.3 - 2023-10-19

Commits

v15.1.2 - 2023-10-11

Merged

  • Fix async functions #114
  • Improve CI config #115
  • Bump @socketsupply/tapzero from 0.7.1 to 0.8.0 #112
  • Bump tape-run from 10.0.0 to 11.0.0 #111
  • Bump actions/checkout from 3 to 4 #110
  • Bump esbuild from 0.18.20 to 0.19.0 #109
  • Update deps, fix tests, enable dep updates #108

Fixed

  • Fix async functions (#114) #113

v15.1.1 - 2023-01-17

Commits

  • reduce npm package size and update copywrite d545931

v15.1.0 - 2023-01-13

Merged

  • fix GH workflow #104
  • add support for passing Map, Set, and WeakMap instances as props #102
  • ignore compiled code #101

Commits

v15.0.0 - 2022-12-21

Merged

  • Update documentation for v15 release #99
  • Make ESM the default format #90
  • Expose a static method to get the tag name of a component #94
  • fix for #92 -- npm install #93
  • add package.json instead of package #89

Commits

v14.1.5 - 2022-03-02

Commits

v14.1.4 - 2022-03-02

Commits

v14.1.3 - 2022-03-02

Commits

v14.1.2 - 2022-03-02

Commits

v14.1.1 - 2022-02-23

Commits

v14.1.0 - 2022-02-10

Commits

  • chore(): 'operatortc ~> socketsupply' 14b0579

v14.0.0 - 2021-11-03

Merged

  • Remove redundant getter/setter #80
  • simply accessing a the id property should not throw an error #79

Commits

v13.3.6 - 2021-09-21

Commits

  • option to pass html and props as args 06bd109

v13.3.5 - 2021-03-03

Commits

  • regen dist files 9a000fe
  • tonic: Support numbers in class name 995f1d0

v13.3.4 - 2021-02-08

Commits

v13.3.3 - 2021-02-08

Commits

v13.3.2 - 2021-02-03

Commits

v13.3.1 - 2021-02-01

Merged

  • Use .js file extension. #71

Commits

v13.3.0 - 2021-01-28

Merged

  • Tape tapzero #70

Commits

v13.2.0 - 2021-01-28

Commits

v13.1.4 - 2021-01-23

Commits

v13.1.3 - 2020-11-23

Merged

  • src: Add dispatch method #64

Commits

v13.1.2 - 2020-10-30

Merged

  • src: Tonic.add() should throw err with double add #66

v13.1.1 - 2020-09-18

Merged

  • remove wrap #62
  • update migration docs #61

Commits

v13.1.0 - 2020-09-02

Merged

  • Allow passing an array of templates #59
  • Add TonicTemplate to reduce confusion. #60

Commits

  • test: add test for array use case 30fb698
  • add new field and one class cc212db
  • src: Use explicit TonicTemplate 68ffd4d

v13.0.0 - 2020-08-31

Merged

  • Add default escaping to Tonic #58

Commits

v12.1.0 - 2020-08-18

Merged

  • src: Do not call render if not in document #56

Commits

v12.0.4 - 2020-08-18

Merged

  • src: Ensure this.root is not undefined #55
  • Connected after render #54

Commits

  • cleanup 6c0532b
  • remove async keyword from interal connectedCallback 7cce6ca
  • src: Add comment about back compat 1efd5a7

v12.0.3 - 2020-07-13

Commits

  • make life-cycle event connected happen after render if render is async or a generator function 8577520

v12.0.2 - 2020-07-10

Merged

  • src: Allow component to set preventRenderOnReconnect to true #53

Commits

  • still call connected() 7fbc142
  • src: Allow component to set shouldRender to false 4b784a4
  • rename to preventRender b8843b4

v12.0.1 - 2020-05-28

Merged

  • src: Use window.setTimeout() #51
  • print the outerHTML #50

Commits

v12.0.0 - 2020-05-18

Merged

  • src: Enforce mandatory id if this.state #49
  • provide a way for nonce to be passed to stylesheets, satisfy csp #48

Commits

  • document migration to v12 12ebef6
  • src: Check the coupling between state & id. 81f8634
  • improve warning 850162f

v11.3.0 - 2020-05-05

Merged

  • Do not null elements array #47

Commits

  • regenerate dist 84fb963
  • src/index.js: Do not null elements array fcd3cee

v11.2.0 - 2020-04-15

Merged

  • Tonic: Expose template strings from this.html #46
  • WIP — render-only components #45

Commits

  • render-only components b39939e
  • src: Handle SPREAD at html() time. 9462ea6
  • src: Tonic.raw() expose template strings 36c2be8

v11.1.1 - 2020-03-06

Merged

  • src: Change the way we handle static stylesheet. #44

Commits

v11.1.0 - 2020-03-06

Merged

  • src: Add Tonic.addStyles() #43

Commits

v11.0.5 - 2020-03-06

Merged

  • tonic: Only append stylesheet if own property #42

Commits

  • regen dist 4753edf
  • tonic: Only append stylesheet if own property. 59a2851

v11.0.4 - 2020-02-26

Merged

  • Improve promises stuff. #41

Commits

  • src: Make reRender() wait for render to complete 8bad2a0
  • src: Reduce number of unnecessary promises b4df52d
  • regenerate dist 43a627e

v11.0.3 - 2020-02-20

Merged

  • Do not cloneNode() in constructor. #40

Commits

v11.0.2 - 2020-01-24

Commits

v11.0.1 - 2020-01-24

Merged

  • Make require-check work via typeof #38

v11.0.0 - 2020-01-22

Merged

  • Improve saniziation + Tonic.raw() #36
  • support passing null value as prop #37

Commits

  • docs: Document migration + links in readme 3c262ee
  • src: Have html() return a raw string 8624801
  • static definition of stylesheets method 6f16c52

v10.3.0 - 2020-01-08

Merged

  • Add support for placeholding children #34

Commits

  • test: add test for placeholding 1d538cf
  • tests: add another test 4e35a3a
  • src: Improve placeholding 69e889d

v10.2.3 - 2019-12-17

Merged

  • src: use setTimeout(fn, 0) #33

Commits

v10.2.2 - 2019-12-11

Commits

v10.2.1 - 2019-12-11

Commits

v10.2.0 - 2019-12-11

Merged

  • bug: Fix persistence of state by id #31
  • src: Fix reRender + updated event order bug #30
  • src: Handle err from _set #29
  • src: Find event handler methods on proto #28

Commits

v10.1.4 - 2019-11-13

Merged

  • Update test approach #25
  • tonic: debounce reRender #26

Commits

v10.1.3 - 2019-11-10

Merged

  • tonic: Gaurd against non-component #24

Commits

v10.1.2 - 2019-11-07

Merged

  • refs: Store ref by instead of elem. #22
  • handle promises in connected #21
  • tonic: Allow component ref in props #20
  • Only reRender in RAF #18
  • Add support for async event handlers #17
  • async generators wip #16

Commits

v9.0.0 - 2019-03-05

Commits

8.0.0 - 2019-01-29

Merged

  • fixes nested initialization #13
  • V7.3.0 #12
  • Bug Fix for Sanitize Method When The Object Being Sanitized Is Null #8
  • Update HELP.md #7

Commits

7.2.1 - 2018-09-13

Merged

  • Update index.js #4
  • Update HELP.md #3
  • Fix typos #2
  • Add new header image to README #1

Commits