Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 343 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@snapview/sunrise-dom",
"version": "1.0.0",
"version": "1.1.1",
"description": "A `sunrise`-based lib for DOM-manipulations",
"main": "index.js",
"main": "src/index.ts",
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check .",
Expand All @@ -14,19 +14,25 @@
"type": "git",
"url": "git+https://github.com/snapview/sunrise-dom.git"
},
"files": [
"src",
"package.json"
],
"author": "Snapview.de team",
"license": "MIT",
"devDependencies": {
"@snapview/sunrise": "^0.0.10",
"@types/jest": "^28.1.0",
"@types/lodash": "^4.14.182",
"csstype": "^3.1.0",
"jest-environment-jsdom": "^28.1.1",
"husky": "^8.0.1",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.1",
"lint-staged": "^13.0.0",
"lodash": "^4.17.21",
"prettier": "^2.6.2",
"ts-jest": "^28.0.4",
"typescript": "^4.7.2"
"typescript": "^4.7.3"
},
"bugs": {
"url": "https://github.com/snapview/sunrise-dom/issues"
Expand Down
27 changes: 6 additions & 21 deletions src/Nodes.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import { map, Value } from '@snapview/sunrise'
import { Property } from './Properties'

export interface Component<T extends HTMLElement> {
readonly element: T
}
import { Updater } from './Updaters/Constructors'

export function node<K extends keyof HTMLElementTagNameMap>(
tag: K,
): (attributes: Property<HTMLElementTagNameMap[K]>[]) => HTMLElementTagNameMap[K] {
return function (attributes) {
): (updaters: Updater<HTMLElementTagNameMap[K]>[]) => HTMLElementTagNameMap[K] {
return function (updaters) {
const element = document.createElement(tag)
for (const attr of attributes) {
attr(element)
for (const updater of updaters) {
updater(element)
}
return element
}
}

export function wrap<T extends HTMLElement>(el: T): (attributes: Property<T>[]) => HTMLElement {
return function (attributes) {
for (const attr of attributes) {
attr(el)
}
return el
}
}

// TODO: put `cell` as the first argument (like in Elm)
export function renderIf<T, E extends Node>(
renderFunction: ((val: T) => E) | E,
cell: Value<T | null>,
): E {
const emptyNode = getEmptyNode() as E
const emptyNode = document.createTextNode('') as Node as E
let el = emptyNode

map((val) => {
Expand All @@ -53,8 +40,6 @@ export function renderIf<T, E extends Node>(
return el
}

export const getEmptyNode: () => Node = () => document.createTextNode('')

export const div = node('div')
export const video = node('video')
export const select = node('select')
Expand Down
276 changes: 0 additions & 276 deletions src/Properties.ts

This file was deleted.

Loading