npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@elf-framework/sapa

v0.0.263

Published

Fantastic UI library for vanilla JS

Downloads

60

Readme

@elf-framework/sapa

Fantastic UI library

Install

npm install @elf-framework/sapa 

// or 

yarn add @elf-framework/sapa 

ready to use JSX

vite config


esbuild: {
    jsxFactory: "createElementJsx",
    jsxFragment: "FragmentInstance",
    jsxInject: `import { createElementJsx, FragmentInstance } from "@elf-framework/sapa"`,
},

use jsx-runtime

tsconfig.json

"compilerOptions": {
  "jsx": "react-jsx",
  "jsxImportSource": "@elf-framework/sapa",
}

Core Concept

Sapa is a library for easily creating DOM-based UIs. However, since it uses JSX as a grammar, it can be used as data.

The basic template uses JSX, and many functions are structured similarly to React, providing a structure that anyone who has used React can move comfortably.

JSX

It uses JSX as the template engine.

function MyApp() {
  return <div>Sample Text</div>
}

 

JSX basically exists in a form similar to html. For example, instead of using the class attribute as className , apply it as class .

function MyApp() {
  return <div class="layout">SampleText</div>
}

 

You can also use the className attribute as is. If you use the className attribute, it is automatically linked to the class attribute.

Component

Sapa consists of two components.

  • Class component
  • Function component

Class Component

import {UIElement} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template () {
    return <div>My App</div>
  }
}

Function Component

function MyApp() {
  return <div>My App</div>
}

Hook

You can use a Hook similar to React.

  • useState
  • useCallback
  • useMemo
  • useReducer
  • useContext
  • useRef
  • useEffect

See here for details.

DOM

It has several features that allow you to directly control the DOM.

  • ref - Provides a selector to directly access the dom node.
  • event - Provides a magic method to easily set the dom event.

DOM Event

You can set various DOM events using Magic Methods.

import {CLICK, ALT} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template() {
    return <div>My App</div>
  }

  [CLICK() + ALT] (e) {
    console.log(e);
  }
}

Store

Sapa basically provides 3 types of store.

  • state : Rendering control through the instance state and setState function used inside the component
  • useState: Sorted storage used inside the component, rendering control with update function
  • $store : Message passing through subscribe, a public repository used in component inheritance

The above three types allow us to handle data in various ways.

instance state

class MyApp extends UIElement {
  template () {
    return <div>{this.state.myVariable}</div>
  }

  [CLICK()] () {
    const { myVariable = 0 } = this.state;
    myVariable++;
    this.setState({ myVariable })
  }
}

hook state

function MyApp () {
  const [myVariable, setMyVariable] = useState(0);

  return <div onClick={() => setMyVariable(myVariable+1)}>{myVariable}</div>
}

hierarchy store

import {useStoreValue} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template () {

    // subscribe event for $store
    const [myVariable, setMyVariable] = useStoreValue("myVariable", 0);

    return <div onClick={() => {
      setMyVariable((v) => v + 1);
    }}>{myVariable}</div>
  }
}

Message

Sapa provides a way to send messages from an internal component hierarchy.

import {useComponentRender} from "@elf-framework/sapa";

function MyApp () {

  useComponentRender("refreshComponent");

  return <div onClick={() => {
    this.emit("refreshComponent");
  }}></div>
}

Sapa focuses on how to store data, how to send messages, and how to render DOM through JSX.

start, hydrate, renderToHtml

Hot Module Reloader

License : MIT