interface FeatureAPI {
title: string
description: string
pattern: string
}
const getPromptFromFeatures = (feats: FeatureAPI[]) =>
feats.map(({ title, description, pattern }) => `## "${title}": ${description}.\nExample: \`${pattern}\``).join("\n")
export const attributes: FeatureAPI[] = [
{
title: "x-data",
description: "Declare a new Alpine component and its data for a block of HTML",
pattern:
`
...
`
},
{
title: "x-bind",
description: "Dynamically set HTML attributes on an element",
pattern:
`
...
`
},
{
title: "x-on",
description: "Listen for browser events on an element",
pattern:
``
},
{
title: "x-text",
description: "Set the text content of an element",
pattern:
`
`
},
{
title: "x-html",
description: "Set the inner HTML of an element",
pattern:
`
...
`
},
{
title: "x-model",
description: "Synchronize a piece of data with an input element",
pattern:
`
Searching for:
`
},
{
title: "x-show",
description: "Toggle the visibility of an element",
pattern:
`
...
`
},
{
title: "x-transition",
description: "Transition an element in and out using CSS transitions",
pattern:
`
...
`
},
{
title: "x-for",
description: "Repeat a block of HTML based on a data set",
pattern:
`
`
},
{
title: "x-if",
description: "Conditionally add/remove a block of HTML from the page entirely",
pattern:
`
...
`
},
{
title: "x-init",
description: "Run code when an element is initialized by Alpine",
pattern:
``
},
{
title: "x-effect",
description: "Execute a script each time one of its dependencies change",
pattern:
``
},
{
title: "x-ref",
description: "Reference elements directly by their specified keys using the $refs magic property",
pattern:
`
`
},
{
title: "x-cloak",
description: "Hide a block of HTML until after Alpine is finished initializing its contents",
pattern:
`
...
`
},
{
title: "x-ignore",
description: "Prevent a block of HTML from being initialized by Alpine",
pattern:
`
...
`
},
]
export const attributesPrompt = getPromptFromFeatures(attributes)
export const properties: FeatureAPI[] = [
{
title: "$store",
description: "Access a global store registered using Alpine.store(...)",
pattern: ``
},
{
title: "$el",
description: "Reference the current DOM element",
pattern:``
},
{
title: "$dispatch",
description: "Dispatch a custom browser event from the current element",
pattern:
`
`
},
{
title: "$watch",
description: "Watch a piece of data and run the provided callback anytime it changes",
pattern:
`
...
`
},
{
title: "$refs",
description: "Reference an element by key (specified using x-ref)",
pattern:
`
`
},
{
title: "$nextTick",
description: "Wait until the next \"tick\" (browser paint) to run a bit of code",
pattern:
`
...
`
},
]
export const propertiesPrompt = getPromptFromFeatures(properties)
export const methods: FeatureAPI[] = [
{
title: "Alpine.data",
description: "Reuse a data object and reference it using x-data",
pattern:
`
...
`
},
{
title: "Alpine.store",
description: "Declare a piece of global, reactive, data that can be accessed from anywhere using $store",
pattern:
`
...
Alpine.store('notifications', {
items: [],
notify(message) {
this.items.push(message)
}
})`
},
]
export const methodsPrompt = getPromptFromFeatures(methods)
export const alpine = '' // "# Alpine.js docs\n"+ attributesPrompt + propertiesPrompt + methodsPrompt