Skip to content

Commit

Permalink
fix: too many to list
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Nov 4, 2022
1 parent 2179420 commit 7ad1e4c
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 97 deletions.
19 changes: 17 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,28 @@ module.exports = {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/no-inferrable-types': 'warn',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unused-vars': ['error', { args: 'all', argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'off',
'@typescript-eslint/prefer-as-const': 'off',
'react/jsx-curly-brace-presence': 'off',
'react/jsx-pascal-case': 'off',
'react/jsx-fragments': 'off',
'react/jsx-uses-react': 'off',
'react/jsx-no-target-blank': 'off',
'react/jsx-no-comment-textnodes': 'off',
'no-mixed-spaces-and-tabs': 'off',
'no-regex-spaces': 'off',
'no-unexpected-multiline': 'off',
'no-constant-condition': 'off',
'no-cond-assign': 'off',
'no-empty': 'off',
'prefer-spread': 'off',
},
}
4 changes: 2 additions & 2 deletions .pull-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ merge('package.json', (prev, next) => {
delete prev.devDependencies['terser']
delete prev.devDependencies['vite-web-test-runner-plugin']
delete prev.devDependencies['@swc-node/jest']
delete prev.devDependencies['chokidar']
delete prev.devDependencies['jest']
delete prev.devDependencies['jest-browser-globals']
delete prev.devDependencies['ts-jest']
delete prev.devDependencies['ts-node']
delete prev.devDependencies['wtr-plugin-vite']
delete prev.devDependencies['@stagas/jest-node-exports-resolver']
delete prev.devDependencies['vite-open']
})
replace('.gitattributes')
replace('.gitignore')
Expand All @@ -61,7 +61,7 @@ const deprecated = [
'jest.config.js',
'web-test-runner.config.js',
]
deprecated.forEach(x => {
deprecated.forEach((x) => {
try {
fs.rmSync(x, { recursive: true })
console.log('removed', x)
Expand Down
31 changes: 0 additions & 31 deletions dprint.json

This file was deleted.

27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,24 @@
"!**/*.tsbuildinfo"
],
"scripts": {
"start:web": "vite-open example/web --https",
"start:web:debugging": "vite-open example/web --https --debugging-this",
"start:web": "devito example/web",
"start:web:debugging": "devito example/web --debugging-this",
"start:node": "onchange -i src example -- swcno example/node.ts",
"build:watch": "fastpm autolink && tsc -p tsconfig.dist.json --outDir dist/types --watch & swc -w -C module.type=commonjs ./src -d dist/cjs -w & swc -w -C module.type=es6 ./src -d dist/esm",
"build:dist": "npm run build:bundle && npm run build:min",
"cov:watch": "utr --coverage --watch",
"clean": "rimraf dist",
"docs": "dokio -o README.md && dprint fmt README.md",
"test": "npm run test:node && npm run test:web",
"test:node": "if find test -type f -iregex '.*\\.spec\\.\\(js\\|jsx\\|ts\\|tsx\\)$' | grep -q .; then utr 'test/*.spec.{js,jsx,ts,tsx}'; else echo no node tests; fi",
"test:web": "if find test -type f -iregex '.*\\.spec\\.web\\.\\(js\\|jsx\\|ts\\|tsx\\)$' | grep -q .; then utr --browser 'test/*.spec.web.{js,jsx,ts,tsx}'; else echo no web tests; fi",
"docs": "dokio -o README.md",
"test": "utr",
"cov": "utr --coverage",
"build": "npm run build:cjs & npm run build:esm & npm run build:types && echo done.",
"build:cjs": "swc -C module.type=commonjs ./src -d dist/cjs",
"build:esm": "swc -C module.type=es6 ./src -d dist/esm && echo '{\"type\":\"module\"}' >dist/esm/package.json",
"build:types": "tsc -p tsconfig.dist.json --outDir dist/types",
"build:bundle": "bunzee src/index.ts \"dist/$(cat package.json | jq -r '.name').js\"",
"build:min": "bunzee -m src/index.ts \"dist/$(cat package.json | jq -r '.name').min.js\"",
"lint": "eslint src && dprint check",
"lint:fix": "eslint --fix src && dprint fmt",
"lint": "eslint src",
"lint:fix": "eslint --fix src",
"prepack": "npm run clean && npm run build && (npm run build:dist || echo unable to bundle)",
"prepack:dry": "npm pack --dry-run",
"prepush": "npm run lint && npm run test",
Expand All @@ -83,7 +81,9 @@
"@typescript-eslint/eslint-plugin": "5.31.0",
"@typescript-eslint/parser": "5.31.0",
"bunzee": "^1.0.0",
"dokio": "^0.0.2",
"chokidar": "3.5.3",
"devito": "^2.0.0",
"dokio": "^1.1.0",
"dprint": "0.30.3",
"eslint": "8.20.0",
"eslint-config-html-jsx": "^1.0.0",
Expand All @@ -92,16 +92,15 @@
"husky": "7.0.4",
"onchange": "7.1.0",
"preact": "^10.6.6",
"pull-configs": "^0.2.0",
"pull-configs": "^1.0.0",
"rimraf": "3.0.2",
"swcno": "0.1.1",
"typescript": "4.7.3",
"utr": "^0.2.0",
"vite-open": "^3.0.1"
"utr": "^1.3.3"
},
"dependencies": {
"everyday-types": "^1.0.0",
"everyday-utils": "^1.0.0",
"everyday-types": "^1.1.0",
"everyday-utils": "^1.3.0",
"html-jsx": "^0.3.7"
}
}
20 changes: 9 additions & 11 deletions src/from-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type * as jsxi from 'html-jsx'

import { jsx } from './jsx-runtime'

const components: WeakMap<typeof HTMLElement, any> = new WeakMap()

// until a getName() is implemented or similar
// we polyfill it to capture the tagNames
// of foreign custom elements
Expand All @@ -17,15 +15,15 @@ declare const customElements: CustomElementRegistry & {
if (!customElements.getName) {
const tags: WeakMap<typeof HTMLElement, string> = new WeakMap()
const { define } = customElements
customElements.define = function(
customElements.define = function (
name: string,
ctor: CustomElementConstructor,
options?: ElementDefinitionOptions,
): void {
tags.set(ctor, name)
return define.call(customElements, name, ctor, options)
}
customElements.getName = function(ctor: CustomElementConstructor) {
customElements.getName = function (ctor: CustomElementConstructor) {
return tags.get(ctor)
}
}
Expand All @@ -34,21 +32,23 @@ export interface Options<T> extends ElementDefinitionOptions {
interface?: Class<T>
}

export type ComponentProps<T, I> = Partial<Omit<T & I, keyof HTMLElement>> & jsxi.HTMLAttributes<T>

export type Component<T, I> =
& {
/** Returns the tag name of the component. */
toString(): string
}
& ((props: Partial<Omit<T & I, keyof HTMLElement>> & jsxi.HTMLAttributes<T>) => JSX.Element)
& ((props: ComponentProps<T, I>) => JSX.Element)

let suffixKey = 0

export const fromElement = <T extends HTMLElement, I = HTMLElement>(
ctor: Class<T> & { elementOptions?: Options<I> },
options: Options<I> = ctor.elementOptions ?? {},
defaultProps: ComponentProps<T, I> = {},
): Component<T, I> => {
let fn: Component<T, I> = components.get(ctor)
if (fn) return fn
let fn: Component<T, I>

let tag = customElements.getName(ctor)

Expand All @@ -62,11 +62,9 @@ export const fromElement = <T extends HTMLElement, I = HTMLElement>(
}

if (options.extends)
fn = props => jsx(options.extends, Object.assign(props, { is: tag }), void 0)
fn = props => jsx(options.extends, Object.assign({}, defaultProps, props, { is: tag }), void 0)
else
fn = props => jsx(tag, props, void 0)

components.set(ctor, fn)
fn = props => jsx(tag, Object.assign({}, defaultProps, props), void 0)

fn.toString = () => tag!

Expand Down

0 comments on commit 7ad1e4c

Please sign in to comment.