-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a565550
commit 0efb896
Showing
6 changed files
with
127 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@websublime/vitamin-core': minor | ||
--- | ||
|
||
Init htmx component for testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
|-------------------------------------------------------------------------- | ||
| Copyright Websublime All Rights Reserved. | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Use of this source code is governed by an MIT-style license that can be | ||
| found in the LICENSE file at https://websublime.dev/license | ||
| | ||
*/ | ||
|
||
import { PropertyValues, ReactiveElement } from 'lit'; | ||
|
||
import type { ComponentMixinInterface } from '../types/component'; | ||
import type { Constructor } from '../types/general'; | ||
import { property } from '../utilities/decorators'; | ||
|
||
export function ComponentMixin<T extends Constructor<ReactiveElement>>( | ||
constructor: T | ||
): T & Constructor<ComponentMixinInterface> { | ||
class SuperElement extends constructor { | ||
/** | ||
* @public | ||
*/ | ||
@property({ reflect: true }) | ||
public override dir: 'ltr' | 'rtl' = 'ltr'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
@property({ reflect: true, type: Boolean }) | ||
public inspect = false; | ||
|
||
/** | ||
* @public | ||
*/ | ||
public get isLTR(): boolean { | ||
return this.dir === 'ltr'; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @readonly | ||
*/ | ||
public override connectedCallback(): void { | ||
super.connectedCallback(); | ||
} | ||
|
||
/** | ||
* @internal | ||
* @readonly | ||
*/ | ||
public override disconnectedCallback(): void { | ||
super.disconnectedCallback(); | ||
} | ||
|
||
/** | ||
* @internal | ||
* @readonly | ||
*/ | ||
public override updated(changedProperties: PropertyValues) { | ||
super.updated?.(changedProperties); | ||
} | ||
} | ||
|
||
return SuperElement as Constructor<SuperElement> & T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
|-------------------------------------------------------------------------- | ||
| Copyright Websublime All Rights Reserved. | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Use of this source code is governed by an MIT-style license that can be | ||
| found in the LICENSE file at https://websublime.dev/license | ||
| | ||
*/ | ||
|
||
import type { ComponentMetadata, WebComponentOptions } from '../types/component'; | ||
import { Constructor } from '../types/general'; | ||
|
||
import { ComponentElement } from './web-component'; | ||
|
||
export class ComponentHtmx extends ComponentElement<WebComponentOptions> { | ||
constructor(registry: ComponentMetadata) { | ||
super(registry); | ||
} | ||
} | ||
|
||
/** | ||
* Register a custom element Lit class component. This function will | ||
* also add the component options to the prototype. | ||
* | ||
* @public | ||
*/ | ||
export function defineHtmxComponent<ComponentHtmx extends ComponentElement>( | ||
name: string, | ||
component: Constructor<ComponentHtmx>, | ||
options: WebComponentOptions = {} | ||
): Constructor<ComponentHtmx> { | ||
Object.defineProperty(component.prototype, 'componentOptions', { | ||
enumerable: true, | ||
value: options, | ||
writable: true | ||
}); | ||
|
||
if (!window.customElements.get(name)) { | ||
window.customElements.define(name, component); | ||
} | ||
|
||
return component; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters