Add Biome for lint and code quality check #2
80
src/main.ts
80
src/main.ts
|
@ -66,7 +66,11 @@ export default (options: ComponentOptions) => {
|
||||||
this._states = new Proxy(
|
this._states = new Proxy(
|
||||||
{ ...(states || {}) },
|
{ ...(states || {}) },
|
||||||
{
|
{
|
||||||
set: (target: Record<string, unknown>, keyPath: string, value: unknown) => {
|
set: (
|
||||||
|
target: Record<string, unknown>,
|
||||||
|
keyPath: string,
|
||||||
|
value: unknown,
|
||||||
|
) => {
|
||||||
const valueRoute = keyPath.split('.')
|
const valueRoute = keyPath.split('.')
|
||||||
let currentTarget = target
|
let currentTarget = target
|
||||||
for (const i in valueRoute) {
|
for (const i in valueRoute) {
|
||||||
|
@ -74,8 +78,7 @@ export default (options: ComponentOptions) => {
|
||||||
if (Number.parseInt(i) === valueRoute.length - 1) {
|
if (Number.parseInt(i) === valueRoute.length - 1) {
|
||||||
currentTarget[key] = value
|
currentTarget[key] = value
|
||||||
} else {
|
} else {
|
||||||
if (!currentTarget[key])
|
if (!currentTarget[key]) currentTarget[key] = {}
|
||||||
currentTarget[key] = {}
|
|
||||||
currentTarget = currentTarget[key] as Record<string, unknown>
|
currentTarget = currentTarget[key] as Record<string, unknown>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,8 +116,7 @@ export default (options: ComponentOptions) => {
|
||||||
if (Number.parseInt(i) === valueRoute.length - 1)
|
if (Number.parseInt(i) === valueRoute.length - 1)
|
||||||
return currentTarget[key]
|
return currentTarget[key]
|
||||||
|
|
||||||
if (!currentTarget[key])
|
if (!currentTarget[key]) currentTarget[key] = {}
|
||||||
currentTarget[key] = {}
|
|
||||||
currentTarget = currentTarget[key] as Record<string, unknown>
|
currentTarget = currentTarget[key] as Record<string, unknown>
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
|
@ -192,19 +194,19 @@ export default (options: ComponentOptions) => {
|
||||||
if (value !== undefined)
|
if (value !== undefined)
|
||||||
binding.element.setAttribute(binding.attrName, String(value))
|
binding.element.setAttribute(binding.attrName, String(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _scheduleUpdate(elements: Set<HTMLElement>) {
|
private _scheduleUpdate(elements: Set<HTMLElement>) {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
for (const element of elements)
|
for (const element of elements) this._updateElement(element)
|
||||||
this._updateElement(element)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private _updateElement(element: HTMLElement) {
|
private _updateElement(element: HTMLElement) {
|
||||||
const renderFunction = (element as { _renderFunction?: () => string | Node })._renderFunction
|
const renderFunction = (
|
||||||
|
element as { _renderFunction?: () => string | Node }
|
||||||
|
)._renderFunction
|
||||||
if (renderFunction) {
|
if (renderFunction) {
|
||||||
// Set rendering context
|
// Set rendering context
|
||||||
this._currentRenderingElement = element
|
this._currentRenderingElement = element
|
||||||
|
@ -213,8 +215,7 @@ export default (options: ComponentOptions) => {
|
||||||
const result = renderFunction()
|
const result = renderFunction()
|
||||||
|
|
||||||
// Update DOM
|
// Update DOM
|
||||||
if (typeof result === 'string')
|
if (typeof result === 'string') element.innerHTML = result
|
||||||
element.innerHTML = result
|
|
||||||
else if (result instanceof Node) {
|
else if (result instanceof Node) {
|
||||||
element.innerHTML = ''
|
element.innerHTML = ''
|
||||||
element.appendChild(result)
|
element.appendChild(result)
|
||||||
|
@ -349,11 +350,19 @@ export default (options: ComponentOptions) => {
|
||||||
eventName,
|
eventName,
|
||||||
handlerValue,
|
handlerValue,
|
||||||
)
|
)
|
||||||
} else if (typeof (this as Record<string, unknown>)[handlerValue] === 'function') {
|
} else if (
|
||||||
|
typeof (this as Record<string, unknown>)[handlerValue] ===
|
||||||
|
'function'
|
||||||
|
) {
|
||||||
// Handle method reference: @click="handleClick"
|
// Handle method reference: @click="handleClick"
|
||||||
currentElementNode.addEventListener(
|
currentElementNode.addEventListener(
|
||||||
eventName,
|
eventName,
|
||||||
((this as unknown as Record<string, (...args: unknown[]) => void>)[handlerValue]).bind(this),
|
(
|
||||||
|
this as unknown as Record<
|
||||||
|
string,
|
||||||
|
(...args: unknown[]) => void
|
||||||
|
>
|
||||||
|
)[handlerValue].bind(this),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Handle simple expression: @click="count++" or @input="name = $event.target.value"
|
// Handle simple expression: @click="count++" or @input="name = $event.target.value"
|
||||||
|
@ -427,8 +436,7 @@ export default (options: ComponentOptions) => {
|
||||||
this._statesListeners[expr] = (newValue: unknown) => {
|
this._statesListeners[expr] = (newValue: unknown) => {
|
||||||
if (element instanceof HTMLInputElement)
|
if (element instanceof HTMLInputElement)
|
||||||
element.value = newValue as string
|
element.value = newValue as string
|
||||||
else
|
else element.setAttribute('data-laterano-connect', String(newValue))
|
||||||
element.setAttribute('data-laterano-connect', String(newValue))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,15 +518,14 @@ export default (options: ComponentOptions) => {
|
||||||
const keyAttr = template.getAttribute('%key')
|
const keyAttr = template.getAttribute('%key')
|
||||||
if (!keyAttr)
|
if (!keyAttr)
|
||||||
console.warn(
|
console.warn(
|
||||||
'%key attribute not found in the template, which is not a recommended practice.'
|
'%key attribute not found in the template, which is not a recommended practice.',
|
||||||
)
|
)
|
||||||
|
|
||||||
// Store a map of existing items by key for reuse
|
// Store a map of existing items by key for reuse
|
||||||
const existingElementsByKey = new Map()
|
const existingElementsByKey = new Map()
|
||||||
// renderedItems.forEach((item) => {
|
// renderedItems.forEach((item) => {
|
||||||
for (const item of renderedItems)
|
for (const item of renderedItems)
|
||||||
if (item.key !== undefined)
|
if (item.key !== undefined) existingElementsByKey.set(item.key, item)
|
||||||
existingElementsByKey.set(item.key, item)
|
|
||||||
|
|
||||||
// Clear rendered items
|
// Clear rendered items
|
||||||
renderedItems.length = 0
|
renderedItems.length = 0
|
||||||
|
@ -621,7 +628,8 @@ export default (options: ComponentOptions) => {
|
||||||
itemContext: Record<string, unknown>,
|
itemContext: Record<string, unknown>,
|
||||||
) {
|
) {
|
||||||
// 1. Store the item context of the element so that subsequent updates can find it
|
// 1. Store the item context of the element so that subsequent updates can find it
|
||||||
; (element as { _itemContext?: Record<string, unknown> })._itemContext = itemContext
|
;(element as { _itemContext?: Record<string, unknown> })._itemContext =
|
||||||
|
itemContext
|
||||||
|
|
||||||
// 2. Process bindings in text nodes
|
// 2. Process bindings in text nodes
|
||||||
const processTextNodes = (node: Node) => {
|
const processTextNodes = (node: Node) => {
|
||||||
|
@ -647,8 +655,7 @@ export default (options: ComponentOptions) => {
|
||||||
// Process the text nodes of the element itself
|
// Process the text nodes of the element itself
|
||||||
// Array.from(element.childNodes).forEach((node) => {
|
// Array.from(element.childNodes).forEach((node) => {
|
||||||
for (const node of Array.from(element.childNodes))
|
for (const node of Array.from(element.childNodes))
|
||||||
if (node.nodeType === Node.TEXT_NODE)
|
if (node.nodeType === Node.TEXT_NODE) processTextNodes(node)
|
||||||
processTextNodes(node)
|
|
||||||
|
|
||||||
// 3. Process attribute bindings (:attr)
|
// 3. Process attribute bindings (:attr)
|
||||||
// Array.from(element.attributes).forEach((attr) => {
|
// Array.from(element.attributes).forEach((attr) => {
|
||||||
|
@ -661,8 +668,7 @@ export default (options: ComponentOptions) => {
|
||||||
itemContext,
|
itemContext,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (value !== undefined)
|
if (value !== undefined) element.setAttribute(attrName, String(value))
|
||||||
element.setAttribute(attrName, String(value))
|
|
||||||
|
|
||||||
// Remove the original binding attribute (execute only for cloned templates once)
|
// Remove the original binding attribute (execute only for cloned templates once)
|
||||||
element.removeAttribute(attr.name)
|
element.removeAttribute(attr.name)
|
||||||
|
@ -724,8 +730,7 @@ export default (options: ComponentOptions) => {
|
||||||
shouldDisplay = Boolean(result)
|
shouldDisplay = Boolean(result)
|
||||||
|
|
||||||
// Apply the condition (in the list item context, we use display style to simplify)
|
// Apply the condition (in the list item context, we use display style to simplify)
|
||||||
if (!shouldDisplay)
|
if (!shouldDisplay) (element as HTMLElement).style.display = 'none'
|
||||||
(element as HTMLElement).style.display = 'none'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,8 +758,7 @@ export default (options: ComponentOptions) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this element is a list element, skip child element processing (they will be processed by the list processor)
|
// If this element is a list element, skip child element processing (they will be processed by the list processor)
|
||||||
if (hasForDirective)
|
if (hasForDirective) return
|
||||||
return
|
|
||||||
|
|
||||||
// 7. Recursively process all child elements
|
// 7. Recursively process all child elements
|
||||||
// Array.from(element.children).forEach((child) => {
|
// Array.from(element.children).forEach((child) => {
|
||||||
|
@ -853,9 +857,8 @@ export default (options: ComponentOptions) => {
|
||||||
let value = itemContext[itemVar]
|
let value = itemContext[itemVar]
|
||||||
|
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (value === undefined || value === null)
|
if (value === undefined || value === null) return undefined
|
||||||
return undefined
|
value = (value as { [key: string]: unknown })[part]
|
||||||
value = (value as { [key: string]: unknown})[part]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -954,8 +957,7 @@ export default (options: ComponentOptions) => {
|
||||||
throw new Error(`Invalid arrow function syntax: ${handlerValue}`)
|
throw new Error(`Invalid arrow function syntax: ${handlerValue}`)
|
||||||
}
|
}
|
||||||
const paramsStr = (() => {
|
const paramsStr = (() => {
|
||||||
if (splitted[0].includes('('))
|
if (splitted[0].includes('(')) return splitted[0].trim()
|
||||||
return splitted[0].trim()
|
|
||||||
return `(${splitted[0].trim()})`
|
return `(${splitted[0].trim()})`
|
||||||
})()
|
})()
|
||||||
const bodyStr = splitted[1].trim()
|
const bodyStr = splitted[1].trim()
|
||||||
|
@ -1028,12 +1030,16 @@ export default (options: ComponentOptions) => {
|
||||||
// Add all methods of the component
|
// Add all methods of the component
|
||||||
// Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach(
|
// Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach(
|
||||||
// (name) => {
|
// (name) => {
|
||||||
for (const name of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))
|
for (const name of Object.getOwnPropertyNames(
|
||||||
|
Object.getPrototypeOf(this),
|
||||||
|
))
|
||||||
if (
|
if (
|
||||||
typeof (this as Record<string, unknown>)[name] === 'function' &&
|
typeof (this as Record<string, unknown>)[name] === 'function' &&
|
||||||
name !== 'constructor'
|
name !== 'constructor'
|
||||||
)
|
)
|
||||||
context[name] = (this as unknown as Record<string, (...args: unknown[]) => void>)[name].bind(this)
|
context[name] = (
|
||||||
|
this as unknown as Record<string, (...args: unknown[]) => void>
|
||||||
|
)[name].bind(this)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
@ -1151,8 +1157,7 @@ export default (options: ComponentOptions) => {
|
||||||
let result = this._states
|
let result = this._states
|
||||||
|
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (result === undefined || result === null)
|
if (result === undefined || result === null) return undefined
|
||||||
return undefined
|
|
||||||
result = (result as { [key: string]: Record<string, unknown> })[part]
|
result = (result as { [key: string]: Record<string, unknown> })[part]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1188,8 +1193,7 @@ export default (options: ComponentOptions) => {
|
||||||
const parts = keyPath.split('.')
|
const parts = keyPath.split('.')
|
||||||
let result = this._states
|
let result = this._states
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (result === undefined || result === null)
|
if (result === undefined || result === null) return undefined
|
||||||
return undefined
|
|
||||||
result = (result as { [key: string]: Record<string, unknown> })[part]
|
result = (result as { [key: string]: Record<string, unknown> })[part]
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -11,8 +11,11 @@
|
||||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||||
|
|
||||||
/* Language and Environment */
|
/* Language and Environment */
|
||||||
"target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||||
"lib": ["DOM", "ES2024"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
"lib": [
|
||||||
|
"DOM",
|
||||||
|
"ES2024"
|
||||||
|
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||||
// "libReplacement": true, /* Enable lib replacement. */
|
// "libReplacement": true, /* Enable lib replacement. */
|
||||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||||
|
@ -26,7 +29,7 @@
|
||||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||||
|
|
||||||
/* Modules */
|
/* Modules */
|
||||||
"module": "ES2022", /* Specify what module code is generated. */
|
"module": "ES2022" /* Specify what module code is generated. */,
|
||||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
|
@ -52,14 +55,14 @@
|
||||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||||
|
|
||||||
/* Emit */
|
/* Emit */
|
||||||
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
||||||
"declarationMap": true, /* Create sourcemaps for d.ts files. */
|
"declarationMap": true /* Create sourcemaps for d.ts files. */,
|
||||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||||
// "removeComments": true, /* Disable emitting comments. */
|
// "removeComments": true, /* Disable emitting comments. */
|
||||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||||
|
@ -72,7 +75,7 @@
|
||||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||||
"declarationDir": "./dist/types", /* Specify the output directory for generated declaration files. */
|
"declarationDir": "./dist/types" /* Specify the output directory for generated declaration files. */,
|
||||||
|
|
||||||
/* Interop Constraints */
|
/* Interop Constraints */
|
||||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||||
|
@ -80,12 +83,12 @@
|
||||||
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
||||||
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||||
|
|
||||||
/* Type Checking */
|
/* Type Checking */
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
"strict": true /* Enable all strict type-checking options. */,
|
||||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||||
|
@ -110,11 +113,6 @@
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["./src/**/*"],
|
||||||
"./src/**/*"
|
"exclude": ["node_modules", "dist"]
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
"dist"
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user