Skip to content

Commit

Permalink
Add tailwindcss and @tailwindcss/typography dependencies
Browse files Browse the repository at this point in the history
Remove IsFunction.vue component
Add IsAlphabetic.vue component
Update Code.vue component
Update isAlpha function to isAlphabetic
Update package-lock.json with shikiji dependency
  • Loading branch information
jrmybtlr committed Jan 26, 2024
1 parent bbbe0a2 commit 6c4ba11
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 98 deletions.
8 changes: 5 additions & 3 deletions docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ function generateMarkdown(tsContent: string): string {
const functions = tsContent.matchAll(functionPattern)

for (const match of functions) {
const name = /export\s+function\s+([a-zA-Z0-9_]+)\s*\(/.exec(match[0])?.[1] || ''
const params = /export\s+function\s+[a-zA-Z0-9_]+\s*\(([^)]*)\)/.exec(match[0])?.[1] || ''
const func = /export\s+function\s+([a-zA-Z0-9_]+)\s*\((.*?)\)\s*:\s*(.*?)\s*\{/.exec(match[0])
const name = func?.[1] || ''
const params = func?.[2] || ''
const returns = func?.[3] || ''
const jsDoc = /\/\*\*([\s\S]*?)\*\//.exec(match[0])?.[1].trim() || ''

const description = jsDoc
Expand All @@ -63,7 +65,7 @@ function generateMarkdown(tsContent: string): string {

const component = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()

markdownContent += `::page-function{name="${name}" description="${description}" params="${params}"}\n`
markdownContent += `::page-function{name="${name}" description="${description}" params="${params}" returns="${returns}"}\n`
markdownContent += `:::${component}\n`
markdownContent += `:::\n`
markdownContent += `::\n\n`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<FormInput label="Value" type="text" v-model="value" />
</ExampleInputs>
<ExampleResult>
{{ isAlpha(value) }}
{{ isAlphabetic(value) }}
</ExampleResult>
</Example>
</template>
Expand Down
14 changes: 0 additions & 14 deletions nuxt-module/docs/components/content/validators/IsFunction.vue

This file was deleted.

7 changes: 7 additions & 0 deletions nuxt-module/docs/components/form/Code.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
</template>

<script setup lang="ts">
import { codeToHtml } from 'shikiji'
const props = defineProps({
modelValue: {
type: [String, Number, Array, Object]
Expand All @@ -32,4 +34,9 @@
type: String
}
})
// const code = await codeToHtml(props.modelValue, {
// lang: 'javascript',
// theme: 'dark-plus'
// })
</script>
45 changes: 37 additions & 8 deletions nuxt-module/docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions nuxt-module/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
},
"devDependencies": {
"@nuxt/image": "^1.2.0",
"@nuxtjs/tailwindcss": "^6.10.4",
"@tailwindcss/typography": "^0.5.10",
"nuxt": "latest",
"nuxt-icon": "^0.6.8",
"@nuxtjs/tailwindcss": "^6.10.4",
"@tailwindcss/typography": "^0.5.10"
"shikiji": "^0.10.1"
},
"dependencies": {
"@nuxt/content": "^2.10.0"
Expand Down
77 changes: 25 additions & 52 deletions src/1.actions.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,58 @@
// title: Actions
// description: A collection of useful actions
// icon: lightning-bolt

/**
* Scrolls to the element with the specified ID.
*/
export function scrollToAnchor(id: string, callback?: () => void): void {
setTimeout(() => {
const element = document.querySelector(id)
if (!element) return
element.scrollIntoView({
behavior: 'smooth'
})
}, 180)

if (callback) {
setTimeout(callback, 180)
}
export function formatNumber(value: number): string {
return 'up'
}

/**
* Smoothly scroll to the top of the page
* Scrolls to the element with the specified ID.
*/
export function scrollToTop(callback?: () => void) {
export function scrollToAnchor(id: string): void {
setTimeout(() => {
window.scrollTo({
top: 0,
const element = document.querySelector(id)
if (!element) return
element.scrollIntoView({
behavior: 'smooth'
})
}, 180)

if (callback) {
setTimeout(callback, 180)
}
}

/**
* Smoothly scroll to the bottom of the page
* Smoothly scroll to the top or bottom of the page
*/
export function scrollToBottom(callback?: () => void) {
export function scrollTo(position: string = 'top'): void {
setTimeout(() => {
window.scrollTo({
top: document.body.scrollHeight,
top: position === 'top' ? 0 : document.body.scrollHeight,
behavior: 'smooth'
})
}, 180)

if (callback) {
setTimeout(callback, 180)
}
}

/**
* Toggles the body scroll with the specified class name
*/
export function toggleBodyScroll(className: string) {
export function toggleBodyScroll(className: string): void {
document.body.classList.toggle(className)
}

/**
* Toggles the element scroll
*/
export function toggleElementScroll(element: HTMLElement, className: string) {
export function toggleElementScroll(element: HTMLElement, className: string): void {
element.classList.toggle(className)
}

/**
* Copies a text to the clipboard
*/
export async function copyToClipboard(text: string): Promise<void> {
export function copyToClipboard(text: string): void {
try {
await navigator.clipboard.writeText(String(text))
navigator.clipboard.writeText(String(text))
} catch (error) {
console.error(error)
}
Expand All @@ -79,78 +61,69 @@ export async function copyToClipboard(text: string): Promise<void> {
/**
* Toggles the fullscreen mode
*/
export function toggleFullScreen() {
export function toggleFullScreen(): void {
if (document.fullscreenElement) document.exitFullscreen()
else document.documentElement.requestFullscreen()
}

/**
* Toggles the dark mode
*/
export function toggleDarkMode() {
export function toggleDarkMode(): void {
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
document.documentElement.classList.toggle('dark', !prefersDarkMode)
}

/**
* Redirects to a new URL
*/
export function redirect(url: string) {
export function redirect(url: string): void {
window.location.href = url
}

/**
* Resets a form
*/
export function resetForm(form: HTMLFormElement) {
export function resetForm(form: HTMLFormElement): void {
form.reset()
}

/**
* Focuses on an element
*/
export function focusOn(element: HTMLElement) {
export function focusOn(element: HTMLElement): void {
element.focus()
}

/**
* Focuses on the first element
*/
export function focusOnFirst(element: HTMLElement) {
export function focusOnFirst(element: HTMLElement): void {
const input = element.querySelector('input')
if (input) {
input.focus()
}
if (input) input.focus()
}

/**
* Focuses on the last element
*/
export function focusOnLast(element: HTMLElement) {
export function focusOnLast(element: HTMLElement): void {
const inputs = element.querySelectorAll('input')
const input = inputs[inputs.length - 1]
if (input) {
input.focus()
}
if (input) input.focus()
}

/**
* Sets up a keyboard trap within an HTML element, allowing the focus to cycle between the first and last focusable elements when the Tab key is pressed.
*/
export function focusTrap(element: HTMLElement) {
export function focusTrap(element: HTMLElement): void {
const focusableElements = element.querySelectorAll('a[href], button, textarea, input[type="text"], input[type="radio"], input[type="checkbox"], select')

const firstFocusableElement = focusableElements[0] as HTMLElement
const lastFocusableElement = focusableElements[focusableElements.length - 1] as HTMLElement

const KEYCODE_TAB = 9

element.addEventListener('keydown', (event) => {
const isTabPressed = event.key === 'Tab' || event.keyCode === KEYCODE_TAB

if (!isTabPressed) {
return
}
if (!isTabPressed) return

if (event.shiftKey) {
if (document.activeElement === firstFocusableElement) {
Expand Down
23 changes: 9 additions & 14 deletions src/7.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export function isHex(value: any): boolean {
/**
* Check if any given value contains only alphabetic characters.
*/
export function isAlpha(value: any): boolean {
export function isAlphabetic(value: any): boolean {
const regex = /^[a-zA-Z]+$/
return regex.test(value)
}

/**
* Check if any given value contains only alphanumeric characters.
*/
export function isAlphanumeric(value: string): boolean {
export function isAlphanumeric(value: any): boolean {
const regex = /^[a-zA-Z0-9]+$/
return regex.test(value)
}
Expand All @@ -106,17 +106,6 @@ export function isBoolean(value: any): boolean {
return typeof value === 'boolean' || value === 'false' || value === 'true'
}

/**
* Check if any given value is a function
*/
export function isFunction(value: any): boolean {
try {
return typeof value === 'function'
} catch (error) {
return false
}
}

/**
* Check if any given value is undefined.
*/
Expand All @@ -135,7 +124,13 @@ export function isNull(value: any): boolean {
* Check if any given value is a valid Date object.
*/
export function isDate(value: any): boolean {
return value instanceof Date || !isNaN(Date.parse(value))
if (value instanceof Date) {
return !isNaN(value.getTime())
} else if (typeof value === 'string' || typeof value === 'number') {
const date = new Date(value)
return !isNaN(date.getTime())
}
return false
}

/**
Expand Down
Loading

0 comments on commit 6c4ba11

Please sign in to comment.