Compare commits

..

No commits in common. "d5562a4d424441690908cb2fbae57ba038a0b608" and "14c6c0a1ab14b9e79a2cb56be6b600e28a285854" have entirely different histories.

6 changed files with 211 additions and 215 deletions

View File

@ -12,18 +12,16 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Set up Node.js - name: Setup Biome
uses: actions/setup-node@v2 uses: biomejs/setup-biome@v2
with: with:
node-version: '22' version: latest
- name: Install dependencies
run: npm ci
- name: Run Biome - name: Run Biome
run: biome ci . run: biome ci .
publish: publish:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: quality
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2

View File

@ -1,6 +1,6 @@
import resolve from '@rollup/plugin-node-resolve' import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript' import typescript from '@rollup/plugin-typescript'
import terser from '@rollup/plugin-terser'
import dts from 'rollup-plugin-dts' import dts from 'rollup-plugin-dts'
export default [ export default [

View File

@ -66,11 +66,7 @@ export default (options: ComponentOptions) => {
this._states = new Proxy( this._states = new Proxy(
{ ...(states || {}) }, { ...(states || {}) },
{ {
set: ( set: (target: Record<string, unknown>, keyPath: string, value: unknown) => {
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) {
@ -78,7 +74,8 @@ 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]) currentTarget[key] = {} if (!currentTarget[key])
currentTarget[key] = {}
currentTarget = currentTarget[key] as Record<string, unknown> currentTarget = currentTarget[key] as Record<string, unknown>
} }
} }
@ -116,7 +113,8 @@ 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]) currentTarget[key] = {} if (!currentTarget[key])
currentTarget[key] = {}
currentTarget = currentTarget[key] as Record<string, unknown> currentTarget = currentTarget[key] as Record<string, unknown>
} }
return undefined return undefined
@ -194,19 +192,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) this._updateElement(element) for (const element of elements)
this._updateElement(element)
}) })
} }
private _updateElement(element: HTMLElement) { private _updateElement(element: HTMLElement) {
const renderFunction = ( const renderFunction = (element as { _renderFunction?: () => string | Node })._renderFunction
element as { _renderFunction?: () => string | Node }
)._renderFunction
if (renderFunction) { if (renderFunction) {
// Set rendering context // Set rendering context
this._currentRenderingElement = element this._currentRenderingElement = element
@ -215,7 +213,8 @@ export default (options: ComponentOptions) => {
const result = renderFunction() const result = renderFunction()
// Update DOM // Update DOM
if (typeof result === 'string') element.innerHTML = result if (typeof result === 'string')
element.innerHTML = result
else if (result instanceof Node) { else if (result instanceof Node) {
element.innerHTML = '' element.innerHTML = ''
element.appendChild(result) element.appendChild(result)
@ -350,19 +349,11 @@ export default (options: ComponentOptions) => {
eventName, eventName,
handlerValue, handlerValue,
) )
} else if ( } else if (typeof (this as Record<string, unknown>)[handlerValue] === 'function') {
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"
@ -436,7 +427,8 @@ 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 element.setAttribute('data-laterano-connect', String(newValue)) else
element.setAttribute('data-laterano-connect', String(newValue))
} }
} }
@ -518,14 +510,15 @@ 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) existingElementsByKey.set(item.key, item) if (item.key !== undefined)
existingElementsByKey.set(item.key, item)
// Clear rendered items // Clear rendered items
renderedItems.length = 0 renderedItems.length = 0
@ -628,8 +621,7 @@ 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 = ; (element as { _itemContext?: Record<string, unknown> })._itemContext = itemContext
itemContext
// 2. Process bindings in text nodes // 2. Process bindings in text nodes
const processTextNodes = (node: Node) => { const processTextNodes = (node: Node) => {
@ -655,7 +647,8 @@ 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) processTextNodes(node) if (node.nodeType === Node.TEXT_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) => {
@ -668,7 +661,8 @@ export default (options: ComponentOptions) => {
itemContext, itemContext,
) )
if (value !== undefined) element.setAttribute(attrName, String(value)) if (value !== undefined)
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)
@ -730,7 +724,8 @@ 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) (element as HTMLElement).style.display = 'none' if (!shouldDisplay)
(element as HTMLElement).style.display = 'none'
} }
} }
@ -758,7 +753,8 @@ 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) return if (hasForDirective)
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) => {
@ -857,8 +853,9 @@ 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) return undefined if (value === undefined || value === null)
value = (value as { [key: string]: unknown })[part] return undefined
value = (value as { [key: string]: unknown})[part]
} }
return value return value
@ -957,7 +954,8 @@ 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('(')) return splitted[0].trim() if (splitted[0].includes('('))
return splitted[0].trim()
return `(${splitted[0].trim()})` return `(${splitted[0].trim()})`
})() })()
const bodyStr = splitted[1].trim() const bodyStr = splitted[1].trim()
@ -1030,16 +1028,12 @@ 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( for (const name of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))
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] = ( context[name] = (this as unknown as Record<string, (...args: unknown[]) => void>)[name].bind(this)
this as unknown as Record<string, (...args: unknown[]) => void>
)[name].bind(this)
return context return context
} }
@ -1157,7 +1151,8 @@ 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) return undefined if (result === undefined || result === null)
return undefined
result = (result as { [key: string]: Record<string, unknown> })[part] result = (result as { [key: string]: Record<string, unknown> })[part]
} }
@ -1193,7 +1188,8 @@ 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) return undefined if (result === undefined || result === null)
return undefined
result = (result as { [key: string]: Record<string, unknown> })[part] result = (result as { [key: string]: Record<string, unknown> })[part]
} }
return result return result

View File

@ -11,11 +11,8 @@
// "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": [ "lib": ["DOM", "ES2024"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"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. */
@ -29,7 +26,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. */
@ -55,14 +52,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. */
@ -75,7 +72,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. */
@ -83,12 +80,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. */
@ -113,6 +110,11 @@
// "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": ["./src/**/*"], "include": [
"exclude": ["node_modules", "dist"] "./src/**/*"
],
"exclude": [
"node_modules",
"dist"
],
} }