diff --git a/handlers/handlers.go b/handlers/handlers.go index 6a2f709..d9d8bfd 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -30,8 +30,17 @@ var ErrFieldIDNotFound = errors.New("a field ID was not found in the request con // StaticAssetHandler handles requests for assets embedded in frm's static file system func StaticAssetHandler(w http.ResponseWriter, r *http.Request) { mp := r.Context().Value(internal.MountPointContextKey).(string) - // Remove the mount point from the path so the static filesystem paths are resolved relative to its root - r.URL.Path = strings.ReplaceAll(r.URL.Path, mp, "") + + // mp ends in a slash (e.g. foo/bar/), and we want to remove /foo/bar/static from the path prefix before searching for + // paths in the static file system. Join mp with "static" to form foo/bar/static as path prefix to be removed + // before searching inside the file system for files. + pathPrefix := fmt.Sprintf("%s%s", mp, "static") + + // Remove the mount point and static prefix from the path so the static filesystem paths are resolved relative to + // the file system's root, e.g. if frm is mounted at /foo/bar, /foo/bar/static is removed from the URL path before + // searching inside the file system. + r.URL.Path = strings.ReplaceAll(r.URL.Path, pathPrefix, "") + http.FileServer(http.FS(static.Assets)).ServeHTTP(w, r) } diff --git a/routers/frmchi/router.go b/routers/frmchi/router.go index 38ee3c1..0a6586c 100644 --- a/routers/frmchi/router.go +++ b/routers/frmchi/router.go @@ -28,20 +28,21 @@ func Mount(router chi.Router, mountPoint string, f *frm.Frm) { r := chi.NewRouter() r.Use(addFrmContext(f)) router.Mount(mountPoint, r) - r.NotFound(handlers.StaticAssetHandler) - rc := r.With(addRequestContext) - rc.Post("/draft", handlers.NewDraft) - rc.Get(fmt.Sprintf("/{%s}", urlParamFormID), handlers.DraftEditor) - rc.Delete(fmt.Sprintf("/{%s}", urlParamFormID), handlers.DeleteForm) - rc.Post(fmt.Sprintf("/{%s}/draft", urlParamFormID), handlers.NewDraft) - rc.Put(fmt.Sprintf("/{%s}/publish", urlParamFormID), handlers.PublishDraft) - rc.Put(fmt.Sprintf("/{%s}/fields/order", urlParamFormID), handlers.UpdateFieldOrder) - rc.Get(fmt.Sprintf("/{%s}/logic_configurator/{%s}/step3", urlParamFormID, urlParamFieldID), handlers.LogicConfiguratorStep3) - rc.Put(fmt.Sprintf("/{%s}/settings", urlParamFormID), handlers.UpdateSettings) - rc.Post(fmt.Sprintf("/{%s}/fields", urlParamFormID), handlers.NewField) - rc.Put(fmt.Sprintf("/{%s}/fields", urlParamFormID), handlers.UpdateFields) - rc.Delete(fmt.Sprintf("/{%s}/fields/{%s}", urlParamFormID, urlParamFieldID), handlers.DeleteField) + rc.NotFound(handlers.StaticAssetHandler) + rc.Route(fmt.Sprintf("/forms/{%s}", urlParamFormID), func(form chi.Router) { + form.Get("/", handlers.DraftEditor) + form.Delete("/", handlers.DeleteForm) + form.Post("/draft", handlers.NewDraft) + form.Put("/publish", handlers.PublishDraft) + form.Put("/fields/order", handlers.UpdateFieldOrder) + form.Put("/settings", handlers.UpdateSettings) + form.Post("/fields", handlers.NewField) + form.Put("/fields", handlers.UpdateFields) + form.Delete(fmt.Sprintf("/fields/{%s}", urlParamFieldID), handlers.DeleteField) + form.Get(fmt.Sprintf("/logic_configurator/{%s}/step3", urlParamFieldID), handlers.LogicConfiguratorStep3) + form.NotFound(handlers.StaticAssetHandler) + }) } // addFrmContext adds all the context necessary for its handlers to function diff --git a/ui/common.templ b/ui/common.templ index c41095d..065b622 100644 --- a/ui/common.templ +++ b/ui/common.templ @@ -131,11 +131,13 @@ func SafePath(ctx context.Context, path string) templ.SafeURL { return templ.SafeURL(fmt.Sprintf("%s%s", ctx.Value(internal.MountPointContextKey).(string), path)) } -// Path returns mountpoint-aware string paths for the given path +// Path returns paths relative to frm's mount point func Path(ctx context.Context, path string) string { - base := ctx.Value(internal.MountPointContextKey).(string) - base = filepath.Clean(base) - return fmt.Sprintf("%s/%s", base, path) + base, ok := ctx.Value(internal.MountPointContextKey).(string) + if !ok { + return "/" + } + return filepath.Clean(fmt.Sprintf("%s/%s", base, path)) } // head simply provides the element @@ -145,11 +147,12 @@ templ head(pageTitle string) { @loadDependenciesOnce.Once() { - - - - - + + + + + + - } } @@ -468,7 +470,7 @@ func formUrl[T string | templ.SafeURL](ctx context.Context, form frm.Form, path if len(path) == 1 { p = path[0] } - return T(Path(ctx, fmt.Sprintf("%d%s", form.ID, p))) + return T(Path(ctx, f("/forms/%d%s", form.ID, p))) } templ FormFieldConfigurator(form frm.Form) { @@ -921,3 +923,8 @@ func sortFields(fields types.FormFields) (sorted []types.FormField) { sort.Sort(types.FormFieldSortByOrder(sorted)) return } + +// f is shorthand for fmt.Sprintf, for readability +func f(s string, args ...any) string { + return fmt.Sprintf(s, args...) +} diff --git a/ui/common_templ.go b/ui/common_templ.go index 3a09d3c..9f57cbe 100644 --- a/ui/common_templ.go +++ b/ui/common_templ.go @@ -84,7 +84,7 @@ func HeroIcon(style string, name string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -137,7 +137,7 @@ func button(args buttonArgs, attrs templ.Attributes) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -175,7 +175,7 @@ func button(args buttonArgs, attrs templ.Attributes) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -209,7 +209,7 @@ func mutedButton(args buttonArgs, attrs templ.Attributes) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -247,7 +247,7 @@ func mutedButton(args buttonArgs, attrs templ.Attributes) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -277,7 +277,7 @@ func FormBuilderNavTitle(form frm.Form) templ.Component { templ_7745c5c3_Var11 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -290,7 +290,7 @@ func FormBuilderNavTitle(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -320,7 +320,7 @@ func FormBuilderNav(form frm.Form) templ.Component { templ_7745c5c3_Var13 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -340,7 +340,7 @@ func FormBuilderNav(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -348,7 +348,7 @@ func FormBuilderNav(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -374,11 +374,13 @@ func SafePath(ctx context.Context, path string) templ.SafeURL { return templ.SafeURL(fmt.Sprintf("%s%s", ctx.Value(internal.MountPointContextKey).(string), path)) } -// Path returns mountpoint-aware string paths for the given path +// Path returns paths relative to frm's mount point func Path(ctx context.Context, path string) string { - base := ctx.Value(internal.MountPointContextKey).(string) - base = filepath.Clean(base) - return fmt.Sprintf("%s/%s", base, path) + base, ok := ctx.Value(internal.MountPointContextKey).(string) + if !ok { + return "/" + } + return filepath.Clean(fmt.Sprintf("%s/%s", base, path)) } // head simply provides the element @@ -403,33 +405,33 @@ func head(pageTitle string) templ.Component { templ_7745c5c3_Var15 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 17) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var16 string templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(ApplicationName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 144, Col: 26} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 146, Col: 26} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" :: ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 18) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var17 string templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(pageTitle) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 144, Col: 43} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 146, Col: 43} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 19) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -445,176 +447,176 @@ func head(pageTitle string) templ.Component { }() } ctx = templ.InitializeContext(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 33) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -624,7 +626,7 @@ func head(pageTitle string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 34) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -679,7 +681,7 @@ func App(pageTitle string) templ.Component { templ_7745c5c3_Var33 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 35) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -687,7 +689,7 @@ func App(pageTitle string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 36) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -695,7 +697,7 @@ func App(pageTitle string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 37) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -703,7 +705,7 @@ func App(pageTitle string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 38) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -745,7 +747,7 @@ func Builder(form frm.Form) templ.Component { }() } ctx = templ.InitializeContext(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 39) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -753,7 +755,7 @@ func Builder(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 40) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -761,7 +763,7 @@ func Builder(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 41) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -769,7 +771,7 @@ func Builder(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 42) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -777,7 +779,7 @@ func Builder(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 43) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -813,33 +815,33 @@ func FormSettings(form frm.Form) templ.Component { templ_7745c5c3_Var36 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 46) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -847,33 +849,33 @@ func FormSettings(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 49) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -903,7 +905,7 @@ func builderColumnLeft(form frm.Form) templ.Component { templ_7745c5c3_Var41 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 50) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -915,7 +917,7 @@ func builderColumnLeft(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 51) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -945,7 +947,7 @@ func FormPreview(form frm.Form) templ.Component { templ_7745c5c3_Var42 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
https://your-form-domain.com/form
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 52) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -953,7 +955,7 @@ func FormPreview(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 53) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -982,7 +984,7 @@ func FieldTypeIcon(fieldType types.FormFieldType) templ.Component { templ_7745c5c3_Var43 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 54) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -998,7 +1000,7 @@ func FieldTypeIcon(fieldType types.FormFieldType) templ.Component { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 55) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1028,7 +1030,7 @@ func FormFields(form frm.Form) templ.Component { templ_7745c5c3_Var44 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 56) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1036,7 +1038,7 @@ func FormFields(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 57) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1065,7 +1067,7 @@ func FormFieldsForm(form frm.Form) templ.Component { templ_7745c5c3_Var45 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 58) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1096,74 +1098,74 @@ func FormFieldsForm(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 60) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, field := range sortFields(form.Fields) { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 63) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var50 string templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(field.Label) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 379, Col: 65} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 381, Col: 65} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 64) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if field.Required { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 65) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 66) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1171,12 +1173,12 @@ func FormFieldsForm(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 67) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 68) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1205,7 +1207,7 @@ func requiredFieldIndicator() templ.Component { templ_7745c5c3_Var51 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("*") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 69) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1267,51 +1269,51 @@ func builderColumnRight(form frm.Form) templ.Component { templ_7745c5c3_Var52 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Add field
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 70) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for i, fieldType := range types.FormFieldTypeValues() { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 75) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 76) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1332,7 +1334,7 @@ func builderColumnRight(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 77) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1345,7 +1347,7 @@ func formUrl[T string | templ.SafeURL](ctx context.Context, form frm.Form, path if len(path) == 1 { p = path[0] } - return T(Path(ctx, fmt.Sprintf("%d%s", form.ID, p))) + return T(Path(ctx, f("/forms/%d%s", form.ID, p))) } func FormFieldConfigurator(form frm.Form) templ.Component { @@ -1369,51 +1371,51 @@ func FormFieldConfigurator(form frm.Form) templ.Component { templ_7745c5c3_Var56 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 80) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, field := range sortFields(form.Fields) { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 82) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1421,20 +1423,20 @@ func FormFieldConfigurator(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 84) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1455,7 +1457,7 @@ func FormFieldConfigurator(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 85) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1463,7 +1465,7 @@ func FormFieldConfigurator(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 86) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1471,12 +1473,12 @@ func FormFieldConfigurator(form frm.Form) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 87) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 88) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1505,111 +1507,111 @@ func fieldSettingsConfiguration(form frm.Form, field types.FormField) templ.Comp templ_7745c5c3_Var61 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 97) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1617,142 +1619,142 @@ func fieldSettingsConfiguration(form frm.Form, field types.FormField) templ.Comp if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 107) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if field.Type == types.FormFieldTypeSingleSelect || field.Type == types.FormFieldTypeMultiSelect { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 109) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1769,56 +1771,56 @@ func fieldSettingsConfiguration(form frm.Form, field types.FormField) templ.Comp return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 122) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1917,7 +1919,7 @@ func fieldSettingsConfiguration(form frm.Form, field types.FormField) templ.Comp if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 123) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1946,59 +1948,59 @@ func fieldLogicConfiguration(form frm.Form, field types.FormField) templ.Compone templ_7745c5c3_Var88 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 128) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2013,7 +2015,7 @@ func fieldLogicConfiguration(form frm.Form, field types.FormField) templ.Compone if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 129) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2028,20 +2030,20 @@ func fieldLogicConfiguration(form frm.Form, field types.FormField) templ.Compone if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 131) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2051,43 +2053,43 @@ func fieldLogicConfiguration(form frm.Form, field types.FormField) templ.Compone return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Choose an action

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 138) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2184,69 +2186,69 @@ func LogicConfiguratorStepThree(form frm.Form, field types.FormField, targetFiel return templ_7745c5c3_Err } case types.FormFieldTypeTextSingle, types.FormFieldTypeTextMultiple: - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 145) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2327,7 +2329,7 @@ func formFieldTypeLabel(fieldType types.FormFieldType) templ.Component { templ_7745c5c3_Var103 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 146) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2335,38 +2337,38 @@ func formFieldTypeLabel(fieldType types.FormFieldType) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 153) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2395,33 +2397,33 @@ func fieldLabel(field types.FormField) templ.Component { templ_7745c5c3_Var104 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 157) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2475,33 +2477,33 @@ func FormView(form frm.Form, isPreview bool) templ.Component { templ_7745c5c3_Var107 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 159) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var109 string templ_7745c5c3_Var109, templ_7745c5c3_Err = templ.JoinStringErrs(form.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 830, Col: 14} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 832, Col: 14} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var109)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 161) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, field := range sortFields(form.Fields) { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 166) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2553,59 +2555,59 @@ func FormView(form frm.Form, isPreview bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 171) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2614,59 +2616,59 @@ func FormView(form frm.Form, isPreview bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 176) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2685,12 +2687,12 @@ func FormView(form frm.Form, isPreview bool) templ.Component { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 177) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 178) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2709,7 +2711,7 @@ func FormView(form frm.Form, isPreview bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 179) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2743,4 +2745,9 @@ func sortFields(fields types.FormFields) (sorted []types.FormField) { return } +// f is shorthand for fmt.Sprintf, for readability +func f(s string, args ...any) string { + return fmt.Sprintf(s, args...) +} + var _ = templruntime.GeneratedTemplate diff --git a/ui/common_templ.txt b/ui/common_templ.txt new file mode 100644 index 0000000..6355e7b --- /dev/null +++ b/ui/common_templ.txt @@ -0,0 +1,179 @@ + + +
+
+

+

+
+
+
+ + :: + + + + +
+
+ +
+
+ + +
+
+
+
+
+
https://your-form-domain.com/form
+
+
+
+
+
+
+
+

+

+
+
+
+
+* +
Add field
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+

Choose an action

+ +
+
+ +

+

+
+ + +
+
+
diff --git a/ui/selector/selector_templ.go b/ui/selector/selector_templ.go index 65e4f57..bd807fb 100644 --- a/ui/selector/selector_templ.go +++ b/ui/selector/selector_templ.go @@ -154,7 +154,7 @@ func Selector(args SelectArgs) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 19) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(args.OptionsContent) > 0 { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 20) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for item, component := range args.OptionsContent { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -356,17 +356,17 @@ func Selector(args SelectArgs) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 23) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 24) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 25) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/ui/selector/selector_templ.txt b/ui/selector/selector_templ.txt new file mode 100644 index 0000000..42bf2ff --- /dev/null +++ b/ui/selector/selector_templ.txt @@ -0,0 +1,25 @@ + +
+
+
+
+
+