Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Applelo committed Mar 6, 2024
1 parent 35f5338 commit 19da689
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 184 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"@antfu/eslint-config": "2.8.0",
"eslint": "^8.57.0",
"playwright": "^1.42.1",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"vite": "^5.1.5",
"vitepress": "1.0.0-rc.44",
"vitepress": "1.0.0-rc.45",
"vitest": "^1.3.1",
"vue": "^3.4.21",
"vue-tsc": "^2.0.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
"tabbable": "^6.2.0"
},
"devDependencies": {
"@types/node": "^20.11.24",
"@types/node": "^20.11.25",
"fast-glob": "^3.3.2",
"lightningcss": "^1.24.0",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"vite": "^5.1.5",
"vite-plugin-dts": "^3.7.3"
}
Expand Down
31 changes: 16 additions & 15 deletions packages/core/src/components/_parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export interface ParentOptions<E extends string> {
*/
initEvents?: boolean
/**
* An Object of with events listener
* An object to instantiate events listeners
* @default undefined
*/
on?: Record<E, (e: CustomEvent<Parent>) => void>
on?: Partial<Record<E, (e: CustomEvent<Parent>) => void | undefined>>
}

export interface ParentEvent {
Expand All @@ -51,19 +51,6 @@ export default abstract class Parent<E extends string = 'init' | 'destroy'> {
throw this.error('The element/selector provided cannot be found.')

this.el = checkEl

if (options.on) {
for (const key in options.on) {
if (Object.prototype.hasOwnProperty.call(options.on, key)) {
const element = options.on[key]
this.el.addEventListener(
`c.${this.name}.${key}`,
e => element(e as CustomEvent<Parent>),
)
}
}
}

this.opts = options
}

Expand Down Expand Up @@ -107,6 +94,20 @@ export default abstract class Parent<E extends string = 'init' | 'destroy'> {
* Init the component
*/
public init() {
if (this.opts.on) {
for (const key in this.opts.on) {
if (Object.prototype.hasOwnProperty.call(this.opts.on, key)) {
const element = this.opts.on[key]
if (!element)
continue
this.el.addEventListener(
`c.${this.name}.${key}`,
e => element(e as CustomEvent<Parent>),
)
}
}
}

this.emitEvent('init')
if (this.accessibilityStatus.styles)
this.el.classList.add(`c-${this.name}--a11y`)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare global {

export interface CollapseOptions extends ParentOptions<Events> {}

export default class Collapse extends Parent {
export default class Collapse extends Parent<Events> {
declare public opts: CollapseOptions
private triggers: HTMLElement[] = []
private expanded = false
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare global {

export interface DragOptions extends ParentOptions<Events> {}

export default class Drag extends Parent {
export default class Drag extends Parent<Events> {
declare public opts: DragOptions
private isDown = false
private draggableClass = 'c-drag--draggable'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/drilldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface DrilldownItem {
level: number
}

export default class Drilldown extends Parent {
export default class Drilldown extends Parent<Events> {
declare public opts: DrilldownOptions
private currentEl: HTMLUListElement | null = null
private wrapper: HTMLUListElement | null = null
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DropdownOptions extends ParentOptions<Events> {
mutationObserver?: boolean
}

export default class Dropdown extends Parent {
export default class Dropdown extends Parent<Events> {
declare public opts: DropdownOptions
private triggerEl: HTMLButtonElement | HTMLLinkElement | null = null
private menuEl: HTMLUListElement | null = null
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/marquee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface MarqueeOptions extends ParentOptions<Events> {
mutationObserver?: boolean
}

export default class Marquee extends Parent {
export default class Marquee extends Parent<Events> {
declare public opts: MarqueeOptions
private containerEl: HTMLElement | null = null
private resizeObserver?: ResizeObserver
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@compotes/vue": "workspace:*",
"@vitejs/plugin-vue": "^5.0.4",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"vite": "^5.1.5",
"vue-tsc": "^2.0.5"
}
Expand Down
9 changes: 8 additions & 1 deletion packages/vue/demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<script setup lang="ts">
import { useCollapse } from '@compotes/vue'
import { shallowRef } from 'vue'
import 'compotes/css/collapse'
const collapseEl = shallowRef<null | HTMLElement>(null)
useCollapse(collapseEl)
useCollapse(collapseEl, {
on: {
init: () => {
console.log('init')

Check failure on line 10 in packages/vue/demo/src/App.vue

View workflow job for this annotation

GitHub Actions / Lint: node-18, ubuntu-latest

Unexpected console statement
},
},
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"vite": "^5.1.5",
"vue": "^3.4.21",
"vue-tsc": "^2.0.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/composables/_parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { Ref, ShallowRef } from 'vue'
import { onMounted, onUnmounted, onUpdated, shallowRef } from 'vue'

export function useParent<T extends Parent>(
ComponentClass: new (el: HTMLElement, options: ParentOptions<'init' | 'destroy'>) => T,
ComponentClass: new (el: HTMLElement, options: ParentOptions<string>) => T,
el: Ref<HTMLElement | null>,
options: ParentOptions<'init' | 'destroy'> = {},
options: ParentOptions<string> = {},
) {
const component: ShallowRef<T | null> = shallowRef(null)

Expand Down
Loading

0 comments on commit 19da689

Please sign in to comment.