init - add project files
This commit is contained in:
15
vendor/maragu.dev/gomponents-htmx/.editorconfig
vendored
Normal file
15
vendor/maragu.dev/gomponents-htmx/.editorconfig
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
[{*.go,*.md}]
|
||||
indent_style = tab
|
||||
1
vendor/maragu.dev/gomponents-htmx/.gitignore
vendored
Normal file
1
vendor/maragu.dev/gomponents-htmx/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cover.out
|
||||
21
vendor/maragu.dev/gomponents-htmx/LICENSE
vendored
Normal file
21
vendor/maragu.dev/gomponents-htmx/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Maragu ApS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
12
vendor/maragu.dev/gomponents-htmx/Makefile
vendored
Normal file
12
vendor/maragu.dev/gomponents-htmx/Makefile
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
.PHONY: cover
|
||||
cover:
|
||||
go tool cover -html=cover.out
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
golangci-lint run
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -coverprofile=cover.out -shuffle on ./...
|
||||
|
||||
99
vendor/maragu.dev/gomponents-htmx/README.md
vendored
Normal file
99
vendor/maragu.dev/gomponents-htmx/README.md
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
# gomponents-htmx
|
||||
|
||||
<img src="logo.png" alt="Logo" width="300" align="right">
|
||||
|
||||
[](https://pkg.go.dev/maragu.dev/gomponents-htmx)
|
||||
[](https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml)
|
||||
|
||||
[HTMX](https://htmx.org) attributes and helpers for [gomponents](https://www.gomponents.com).
|
||||
|
||||
Made with ✨sparkles✨ by [maragu](https://www.maragu.dev/).
|
||||
|
||||
Does your company depend on this project? [Contact me at markus@maragu.dk](mailto:markus@maragu.dk?Subject=Supporting%20your%20project) to discuss options for a one-time or recurring invoice to ensure its continued thriving.
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
go get maragu.dev/gomponents-htmx
|
||||
```
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/components"
|
||||
. "maragu.dev/gomponents/html"
|
||||
. "maragu.dev/gomponents/http"
|
||||
|
||||
hx "maragu.dev/gomponents-htmx"
|
||||
hxhttp "maragu.dev/gomponents-htmx/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := start(); err != nil {
|
||||
log.Fatalln("Error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func start() error {
|
||||
now := time.Now()
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", Adapt(func(w http.ResponseWriter, r *http.Request) (Node, error) {
|
||||
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) {
|
||||
now = time.Now()
|
||||
|
||||
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly))
|
||||
|
||||
return partial(now), nil
|
||||
}
|
||||
return page(now), nil
|
||||
}))
|
||||
|
||||
log.Println("Starting on http://localhost:8080")
|
||||
if err := http.ListenAndServe("localhost:8080", mux); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const timeOnly = "15:04:05"
|
||||
|
||||
func page(now time.Time) Node {
|
||||
return HTML5(HTML5Props{
|
||||
Title: now.Format(timeOnly),
|
||||
|
||||
Head: []Node{
|
||||
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")),
|
||||
Script(Src("https://unpkg.com/htmx.org")),
|
||||
},
|
||||
|
||||
Body: []Node{
|
||||
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"),
|
||||
H1(Text(`gomponents + HTMX`)),
|
||||
|
||||
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))),
|
||||
|
||||
partial(now),
|
||||
|
||||
Form(Method("post"), Action("/"),
|
||||
hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"),
|
||||
|
||||
Button(Type("submit"), Text(`Update time`),
|
||||
Class("rounded-md border border-transparent bg-orange-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-2"),
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func partial(now time.Time) Node {
|
||||
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly)))
|
||||
}
|
||||
```
|
||||
226
vendor/maragu.dev/gomponents-htmx/htmx.go
vendored
Normal file
226
vendor/maragu.dev/gomponents-htmx/htmx.go
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
// Package htmx provides HTMX attributes and helpers for gomponents.
|
||||
// See https://htmx.org/
|
||||
package htmx
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
g "maragu.dev/gomponents"
|
||||
)
|
||||
|
||||
// Boost to add or remove progressive enhancement for links and forms.
|
||||
// See https://htmx.org/attributes/hx-boost
|
||||
func Boost(v string) g.Node {
|
||||
return attr("boost", v)
|
||||
}
|
||||
|
||||
// Get from the specified URL.
|
||||
// See https://htmx.org/attributes/hx-get
|
||||
func Get(url string) g.Node {
|
||||
return attr("get", url)
|
||||
}
|
||||
|
||||
// On handles any event with a script inline.
|
||||
// See https://htmx.org/attributes/hx-on
|
||||
func On(name string, v string) g.Node {
|
||||
return &rawAttr{name: "on:" + name, value: v}
|
||||
}
|
||||
|
||||
// Post to the specified URL.
|
||||
// See https://htmx.org/attributes/hx-post
|
||||
func Post(url string) g.Node {
|
||||
return attr("post", url)
|
||||
}
|
||||
|
||||
// PushURL into the browser location bar, creating a new history entry.
|
||||
// See https://htmx.org/attributes/hx-push-url
|
||||
func PushURL(v string) g.Node {
|
||||
return attr("push-url", v)
|
||||
}
|
||||
|
||||
// Select content to swap in from a response.
|
||||
// See https://htmx.org/attributes/hx-select
|
||||
func Select(v string) g.Node {
|
||||
return attr("select", v)
|
||||
}
|
||||
|
||||
// SelectOOB content to swap in from a response, out of band (somewhere other than the target).
|
||||
// See https://htmx.org/attributes/hx-select-oob
|
||||
func SelectOOB(v string) g.Node {
|
||||
return attr("select-oob", v)
|
||||
}
|
||||
|
||||
// Swap controls how content is swapped in.
|
||||
// See https://htmx.org/attributes/hx-swap
|
||||
func Swap(v string) g.Node {
|
||||
return attr("swap", v)
|
||||
}
|
||||
|
||||
// SwapOOB marks content in a response to be out of band (should swap in somewhere other than the target).
|
||||
// See https://htmx.org/attributes/hx-swap-oob
|
||||
func SwapOOB(v string) g.Node {
|
||||
return attr("swap-oob", v)
|
||||
}
|
||||
|
||||
// Target specifies the target element to be swapped.
|
||||
// See https://htmx.org/attributes/hx-target
|
||||
func Target(v string) g.Node {
|
||||
return attr("target", v)
|
||||
}
|
||||
|
||||
// Trigger specifies the event that triggers the request.
|
||||
// See https://htmx.org/attributes/hx-trigger
|
||||
func Trigger(v string) g.Node {
|
||||
return attr("trigger", v)
|
||||
}
|
||||
|
||||
// Vals adds values to the parameters to submit with the request (JSON-formatted).
|
||||
// See https://htmx.org/attributes/hx-vals
|
||||
func Vals(v string) g.Node {
|
||||
return attr("vals", v)
|
||||
}
|
||||
|
||||
// Confirm shows a confirm() dialog before issuing a request.
|
||||
// See https://htmx.org/attributes/hx-confirm
|
||||
func Confirm(v string) g.Node {
|
||||
return attr("confirm", v)
|
||||
}
|
||||
|
||||
// Delete will issue a DELETE to the specified URL and swap the HTML into the DOM using a swap strategy.
|
||||
// See https://htmx.org/attributes/hx-delete
|
||||
func Delete(v string) g.Node {
|
||||
return attr("delete", v)
|
||||
}
|
||||
|
||||
// Disable htmx processing for the given node and any children nodes.
|
||||
// See https://htmx.org/attributes/hx-disable
|
||||
func Disable(v string) g.Node {
|
||||
return attr("disable", v)
|
||||
}
|
||||
|
||||
// Disable element until htmx request completes.
|
||||
// See https://htmx.org/attributes/hx-disabled-elt/
|
||||
func DisabledElt(v string) g.Node {
|
||||
return attr("disabled-elt", v)
|
||||
}
|
||||
|
||||
// Disinherit controls and disables automatic attribute inheritance for child nodes.
|
||||
// See https://htmx.org/attributes/hx-disinherit
|
||||
func Disinherit(v string) g.Node {
|
||||
return attr("disinherit", v)
|
||||
}
|
||||
|
||||
// Encoding changes the request encoding type.
|
||||
// See https://htmx.org/attributes/hx-encoding
|
||||
func Encoding(v string) g.Node {
|
||||
return attr("encoding", v)
|
||||
}
|
||||
|
||||
// Ext sets extensions to use for this element.
|
||||
// See https://htmx.org/attributes/hx-ext
|
||||
func Ext(v string) g.Node {
|
||||
return attr("ext", v)
|
||||
}
|
||||
|
||||
// Headers adds to the headers that will be submitted with the request.
|
||||
// See https://htmx.org/attributes/hx-headers
|
||||
func Headers(v string) g.Node {
|
||||
return attr("headers", v)
|
||||
}
|
||||
|
||||
// History prevents sensitive data being saved to the history cache.
|
||||
// See https://htmx.org/attributes/hx-history
|
||||
func History(v string) g.Node {
|
||||
return attr("history", v)
|
||||
}
|
||||
|
||||
// HistoryElt sets the element to snapshot and restore during history navigation.
|
||||
// See https://htmx.org/attributes/hx-history-elt
|
||||
func HistoryElt(v string) g.Node {
|
||||
return attr("history-elt", v)
|
||||
}
|
||||
|
||||
// Include additional data in requests.
|
||||
// See https://htmx.org/attributes/hx-include
|
||||
func Include(v string) g.Node {
|
||||
return attr("include", v)
|
||||
}
|
||||
|
||||
// Indicator sets the element to put the htmx-request class on during the request.
|
||||
// See https://htmx.org/attributes/hx-indicator
|
||||
func Indicator(v string) g.Node {
|
||||
return attr("indicator", v)
|
||||
}
|
||||
|
||||
// Params filters the parameters that will be submitted with a request.
|
||||
// See https://htmx.org/attributes/hx-params
|
||||
func Params(v string) g.Node {
|
||||
return attr("params", v)
|
||||
}
|
||||
|
||||
// Patch issues a PATCH to the specified URL.
|
||||
// See https://htmx.org/attributes/hx-patch
|
||||
func Patch(v string) g.Node {
|
||||
return attr("patch", v)
|
||||
}
|
||||
|
||||
// Preserve specifies elements to keep unchanged between requests.
|
||||
// See https://htmx.org/attributes/hx-preserve
|
||||
func Preserve(v string) g.Node {
|
||||
return attr("preserve", v)
|
||||
}
|
||||
|
||||
// Prompt shows a prompt() before submitting a request.
|
||||
// See https://htmx.org/attributes/hx-prompt
|
||||
func Prompt(v string) g.Node {
|
||||
return attr("prompt", v)
|
||||
}
|
||||
|
||||
// Put issues a PUT to the specified URL.
|
||||
// See https://htmx.org/attributes/hx-put
|
||||
func Put(v string) g.Node {
|
||||
return attr("put", v)
|
||||
}
|
||||
|
||||
// ReplaceURL replaces the URL in the browser location bar.
|
||||
// See https://htmx.org/attributes/hx-replace-url
|
||||
func ReplaceURL(v string) g.Node {
|
||||
return attr("replace-url", v)
|
||||
}
|
||||
|
||||
// Request configures various aspects of the request.
|
||||
// See https://htmx.org/attributes/hx-request
|
||||
func Request(v string) g.Node {
|
||||
return attr("request", v)
|
||||
}
|
||||
|
||||
// Sync controls how requests made by different elements are synchronized.
|
||||
// See https://htmx.org/attributes/hx-sync
|
||||
func Sync(v string) g.Node {
|
||||
return attr("sync", v)
|
||||
}
|
||||
|
||||
// Validate forces elements to validate themselves before a request.
|
||||
// See https://htmx.org/attributes/hx-validate
|
||||
func Validate(v string) g.Node {
|
||||
return attr("validate", v)
|
||||
}
|
||||
|
||||
func attr(name, value string) g.Node {
|
||||
return g.Attr("hx-"+name, value)
|
||||
}
|
||||
|
||||
// rawAttr is an attribute that doesn't escape its value.
|
||||
type rawAttr struct {
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
func (r *rawAttr) Render(w io.Writer) error {
|
||||
_, err := w.Write([]byte(" hx-" + r.name + `="` + r.value + `"`))
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *rawAttr) Type() g.NodeType {
|
||||
return g.AttributeType
|
||||
}
|
||||
BIN
vendor/maragu.dev/gomponents-htmx/logo.png
vendored
Normal file
BIN
vendor/maragu.dev/gomponents-htmx/logo.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 238 KiB |
Reference in New Issue
Block a user