diff --git a/.hugo_build.lock b/.hugo_build.lock new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..5e6a065 --- /dev/null +++ b/404.html @@ -0,0 +1,39 @@ + + + + +
+ +

+ 404

+
+

This page could not be found. +

+
+
+ + + diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index ba56fe5..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,101 +0,0 @@ -## [Unreleased] - -## v1.5.0 - -### Added - -- feat: add collection widget -- feat: refactoring and improvement of example - -## v1.4.0 - -### Added - -- feat: add json configuration - -### Fixed - -- fix: reset `GlobalFields` in `End()` - -## v1.3.0 - -### Added - -- feat: allow to handle request using json body" -- feat: add `WithJsonRequest` on form -- feat: add `MapToUrlValues` transformer - -## v1.2.0 - -### Added - -- feat: add tag `field` to specify the naming strategy (case) -- feat: add `ErrorsTree` methods on form and field - -## v1.1.6 - -### Fixed - -- fix(input/choice): add specific validation func - -## v1.1.5 - -### Fixed - -- fix(input/choice): add specific validation func - -## v1.1.4 - -### Fixed - -- fix(theme/bootstrap5): fix button class -- fix(theme/html5): remove div wrapper on form content - -## v1.1.3 - -### Fixed - -- fix(form): replace existing option in WithOptions - -## v1.1.2 - -### Added - -- chore(example): remove boostrap classes - -### Fixed - -- fix(theme): checkbox is check on nil value - -## v1.1.1 - -### Fixed - -- feat(form): add default options -- fix(choice): fix Match when field data is nil - -## v1.1.0 - -### Added - -- feat: add go template functions to render a form, a field, etc. -- feat: add constraints (isodd, iseven) -- refactor: refactor constraint (not blank check) - -### Changed - -- feat: replace templates with gomponents - -## v1.0.1 - -### Added - -- doc: add documentation - -## v1.0.0 - -### Added - -- feat: form builder -- feat: form validation -- feat: form renderer diff --git a/LICENCE b/LICENCE deleted file mode 100644 index be3f7b2..0000000 --- a/LICENCE +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff --git a/README.md b/README.md deleted file mode 100644 index 3754083..0000000 --- a/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# go-form - -Creating and processing HTML forms is hard and repetitive. You need to deal with rendering HTML form fields, validating submitted data, mapping the form data into objects and a lot more. [`go-form`][go-form] includes a powerful form feature that provides all these features. - -[`go-form`][go-form] is heavily influenced by [Symfony Form](https://symfony.com/doc/current/forms.html). It includes: - -* A form builder based on fields declarations and independent of structs -* Validation based on constraints -* Data mounting to populate a form from a struct instance -* Data binding to populate a struct instance from a submitted form -* Form renderer with customizable themes - -## Documentation - -* [Official documentation][doc] -* [Demo][demo] - -[go-form]: https://gitnet.fr/deblan/go-form -[demo]: https://gitnet.fr/deblan/go-form-demo -[doc]: https://deblan.gitnet.page/go-form/ diff --git a/android-chrome-192x192.png b/android-chrome-192x192.png new file mode 100644 index 0000000..7f0493c Binary files /dev/null and b/android-chrome-192x192.png differ diff --git a/android-chrome-512x512.png b/android-chrome-512x512.png new file mode 100644 index 0000000..faea4c2 Binary files /dev/null and b/android-chrome-512x512.png differ diff --git a/apple-touch-icon.png b/apple-touch-icon.png new file mode 100644 index 0000000..eb281cb Binary files /dev/null and b/apple-touch-icon.png differ diff --git a/categories/index.html b/categories/index.html new file mode 100644 index 0000000..7ba79ff --- /dev/null +++ b/categories/index.html @@ -0,0 +1,262 @@ + + + + + + + + + + + + +Categories – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+
+

Categories

+
+
+ +
+
+ +
+
+
+
+ +
+

+ + + + + + diff --git a/categories/index.xml b/categories/index.xml new file mode 100644 index 0000000..69093ec --- /dev/null +++ b/categories/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Categories + https://deblan.gitnet.page/go-form/categories/ + Recent content in Categories on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/css/compiled/main.min.e0bb0f28123bf084d555fc9253c6d2aa1443b2dfcde6044741a207eabdc3ddb8.css b/css/compiled/main.min.e0bb0f28123bf084d555fc9253c6d2aa1443b2dfcde6044741a207eabdc3ddb8.css new file mode 100644 index 0000000..823130e --- /dev/null +++ b/css/compiled/main.min.e0bb0f28123bf084d555fc9253c6d2aa1443b2dfcde6044741a207eabdc3ddb8.css @@ -0,0 +1 @@ +*,::before,::after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}::before,::after{--tw-content:''}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,apple color emoji,segoe ui emoji,segoe ui symbol,noto color emoji;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,liberation mono,courier new,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::before,::after{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(59 130 246 / 0.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(59 130 246 / 0.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.hx-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.hx-pointer-events-none{pointer-events:none}.hx-fixed{position:fixed}.hx-absolute{position:absolute}.hx-relative{position:relative}.hx-sticky{position:sticky}.hx-inset-0{inset:0}.hx-inset-x-0{left:0;right:0}.hx-inset-y-0{top:0;bottom:0}.hx-bottom-0{bottom:0}.hx-left-\[24px\]{left:24px}.hx-left-\[36px\]{left:36px}.hx-right-0{right:0}.hx-top-0{top:0}.hx-top-16{top:4rem}.hx-top-8{top:2rem}.hx-top-\[40\%\]{top:40%}.hx-top-full{top:100%}.hx-z-10{z-index:10}.hx-z-20{z-index:20}.hx-z-\[-1\]{z-index:-1}.hx-order-last{order:9999}.hx-m-\[11px\]{margin:11px}.hx-mx-1{margin-left:.25rem;margin-right:.25rem}.hx-mx-4{margin-left:1rem;margin-right:1rem}.hx-mx-auto{margin-left:auto;margin-right:auto}.hx-my-1\.5{margin-top:.375rem;margin-bottom:.375rem}.hx-my-2{margin-top:.5rem;margin-bottom:.5rem}.-hx-mb-0\.5{margin-bottom:-.125rem}.-hx-ml-2{margin-left:-.5rem}.-hx-mr-2{margin-right:-.5rem}.-hx-mt-20{margin-top:-5rem}.hx-mb-10{margin-bottom:2.5rem}.hx-mb-12{margin-bottom:3rem}.hx-mb-16{margin-bottom:4rem}.hx-mb-2{margin-bottom:.5rem}.hx-mb-4{margin-bottom:1rem}.hx-mb-6{margin-bottom:1.5rem}.hx-mb-8{margin-bottom:2rem}.hx-ml-4{margin-left:1rem}.hx-mr-1{margin-right:.25rem}.hx-mr-2{margin-right:.5rem}.hx-mt-1{margin-top:.25rem}.hx-mt-1\.5{margin-top:.375rem}.hx-mt-12{margin-top:3rem}.hx-mt-16{margin-top:4rem}.hx-mt-2{margin-top:.5rem}.hx-mt-4{margin-top:1rem}.hx-mt-5{margin-top:1.25rem}.hx-mt-6{margin-top:1.5rem}.hx-mt-8{margin-top:2rem}.hx-line-clamp-3{overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3}.hx-block{display:block}.hx-inline-block{display:inline-block}.hx-inline{display:inline}.hx-flex{display:flex}.hx-inline-flex{display:inline-flex}.hx-grid{display:grid}.hx-hidden{display:none}.hx-aspect-auto{aspect-ratio:auto}.hx-h-0{height:0}.hx-h-16{height:4rem}.hx-h-2{height:.5rem}.hx-h-3\.5{height:.875rem}.hx-h-4{height:1rem}.hx-h-5{height:1.25rem}.hx-h-7{height:1.75rem}.hx-h-\[18px\]{height:18px}.hx-h-full{height:100%}.hx-max-h-64{max-height:16rem}.hx-max-h-\[calc\(100vh-var\(--navbar-height\)-env\(safe-area-inset-bottom\)\)\]{max-height:calc(100vh - var(--navbar-height) - env(safe-area-inset-bottom))}.hx-max-h-\[min\(calc\(50vh-11rem-env\(safe-area-inset-bottom\)\)\,400px\)\]{max-height:min(calc(50vh - 11rem - env(safe-area-inset-bottom)),400px)}.hx-min-h-\[100px\]{min-height:100px}.hx-min-h-\[calc\(100vh-var\(--navbar-height\)\)\]{min-height:calc(100vh - var(--navbar-height))}.hx-w-2{width:.5rem}.hx-w-3\.5{width:.875rem}.hx-w-4{width:1rem}.hx-w-64{width:16rem}.hx-w-\[110\%\]{width:110%}.hx-w-\[180\%\]{width:180%}.hx-w-full{width:100%}.hx-w-max{width:-moz-max-content;width:max-content}.hx-w-screen{width:100vw}.hx-min-w-0{min-width:0}.hx-min-w-\[18px\]{min-width:18px}.hx-min-w-\[24px\]{min-width:24px}.hx-min-w-full{min-width:100%}.hx-max-w-6xl{max-width:72rem}.hx-max-w-\[50\%\]{max-width:50%}.hx-max-w-\[90rem\]{max-width:90rem}.hx-max-w-\[min\(calc\(100vw-2rem\)\,calc\(100\%\+20rem\)\)\]{max-width:min(calc(100vw - 2rem),calc(100% + 20rem))}.hx-max-w-none{max-width:none}.hx-max-w-screen-xl{max-width:1280px}.hx-shrink-0{flex-shrink:0}.hx-grow{flex-grow:1}.hx-origin-center{transform-origin:center}.hx-cursor-default{cursor:default}.hx-cursor-pointer{cursor:pointer}.hx-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.hx-scroll-my-6{scroll-margin-top:1.5rem;scroll-margin-bottom:1.5rem}.hx-scroll-py-6{scroll-padding-top:1.5rem;scroll-padding-bottom:1.5rem}.hx-list-none{list-style-type:none}.hx-appearance-none{-webkit-appearance:none;-moz-appearance:none;appearance:none}.hx-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.hx-flex-col{flex-direction:column}.hx-flex-wrap{flex-wrap:wrap}.hx-items-start{align-items:flex-start}.hx-items-center{align-items:center}.hx-justify-start{justify-content:flex-start}.hx-justify-end{justify-content:flex-end}.hx-justify-center{justify-content:center}.hx-justify-between{justify-content:space-between}.hx-justify-items-start{justify-items:start}.hx-gap-1{gap:.25rem}.hx-gap-2{gap:.5rem}.hx-gap-4{gap:1rem}.hx-gap-x-1\.5{-moz-column-gap:.375rem;column-gap:.375rem}.hx-gap-y-2{row-gap:.5rem}.hx-overflow-auto{overflow:auto}.hx-overflow-hidden{overflow:hidden}.hx-overflow-x-auto{overflow-x:auto}.hx-overflow-y-auto{overflow-y:auto}.hx-overflow-x-hidden{overflow-x:hidden}.hx-overflow-y-hidden{overflow-y:hidden}.hx-overscroll-contain{overscroll-behavior:contain}.hx-overscroll-x-contain{overscroll-behavior-x:contain}.hx-text-ellipsis{text-overflow:ellipsis}.hx-whitespace-nowrap{white-space:nowrap}.hx-break-words{overflow-wrap:break-word}.hx-rounded{border-radius:.25rem}.hx-rounded-3xl{border-radius:1.5rem}.hx-rounded-full{border-radius:9999px}.hx-rounded-lg{border-radius:.5rem}.hx-rounded-md{border-radius:.375rem}.hx-rounded-sm{border-radius:.125rem}.hx-rounded-xl{border-radius:.75rem}.hx-rounded-t{border-top-left-radius:.25rem;border-top-right-radius:.25rem}.hx-border{border-width:1px}.hx-border-b{border-bottom-width:1px}.hx-border-b-2{border-bottom-width:2px}.hx-border-t{border-top-width:1px}.hx-border-amber-200{--tw-border-opacity:1;border-color:rgb(253 230 138/var(--tw-border-opacity))}.hx-border-black\/5{border-color:rgb(0 0 0/5%)}.hx-border-blue-200{--tw-border-opacity:1;border-color:rgb(191 219 254/var(--tw-border-opacity))}.hx-border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity))}.hx-border-gray-500{--tw-border-opacity:1;border-color:rgb(107 114 128/var(--tw-border-opacity))}.hx-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity))}.hx-border-indigo-200{--tw-border-opacity:1;border-color:rgb(199 210 254/var(--tw-border-opacity))}.hx-border-orange-100{--tw-border-opacity:1;border-color:rgb(255 237 213/var(--tw-border-opacity))}.hx-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity))}.hx-border-transparent{border-color:transparent}.hx-border-yellow-100{--tw-border-opacity:1;border-color:rgb(254 249 195/var(--tw-border-opacity))}.hx-bg-amber-100{--tw-bg-opacity:1;background-color:rgb(254 243 199/var(--tw-bg-opacity))}.hx-bg-black\/80{background-color:rgb(0 0 0/.8)}.hx-bg-black\/\[\.05\]{background-color:rgb(0 0 0/5%)}.hx-bg-blue-100{--tw-bg-opacity:1;background-color:rgb(219 234 254/var(--tw-bg-opacity))}.hx-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.hx-bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity))}.hx-bg-indigo-100{--tw-bg-opacity:1;background-color:rgb(224 231 255/var(--tw-bg-opacity))}.hx-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity))}.hx-bg-orange-50{--tw-bg-opacity:1;background-color:rgb(255 247 237/var(--tw-bg-opacity))}.hx-bg-primary-100{--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 44)/var(--tw-bg-opacity))}.hx-bg-primary-400{--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 16)/var(--tw-bg-opacity))}.hx-bg-primary-600{--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-bg-opacity))}.hx-bg-primary-700\/5{background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/.05)}.hx-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity))}.hx-bg-transparent{background-color:transparent}.hx-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.hx-bg-yellow-50{--tw-bg-opacity:1;background-color:rgb(254 252 232/var(--tw-bg-opacity))}.hx-bg-gradient-to-r{background-image:linear-gradient(to right,var(--tw-gradient-stops))}.hx-from-gray-900{--tw-gradient-from:#111827 var(--tw-gradient-from-position);--tw-gradient-to:rgb(17 24 39 / 0) var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-from), var(--tw-gradient-to)}.hx-to-gray-600{--tw-gradient-to:#4b5563 var(--tw-gradient-to-position)}.hx-bg-clip-text{-webkit-background-clip:text;background-clip:text}.hx-p-0\.5{padding:.125rem}.hx-p-1{padding:.25rem}.hx-p-1\.5{padding:.375rem}.hx-p-2{padding:.5rem}.hx-p-4{padding:1rem}.hx-p-6{padding:1.5rem}.hx-px-1\.5{padding-left:.375rem;padding-right:.375rem}.hx-px-2{padding-left:.5rem;padding-right:.5rem}.hx-px-2\.5{padding-left:.625rem;padding-right:.625rem}.hx-px-3{padding-left:.75rem;padding-right:.75rem}.hx-px-4{padding-left:1rem;padding-right:1rem}.hx-px-6{padding-left:1.5rem;padding-right:1.5rem}.hx-py-1{padding-top:.25rem;padding-bottom:.25rem}.hx-py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.hx-py-12{padding-top:3rem;padding-bottom:3rem}.hx-py-2{padding-top:.5rem;padding-bottom:.5rem}.hx-py-2\.5{padding-top:.625rem;padding-bottom:.625rem}.hx-py-3{padding-top:.75rem;padding-bottom:.75rem}.hx-py-4{padding-top:1rem;padding-bottom:1rem}.hx-pb-8{padding-bottom:2rem}.hx-pb-\[env\(safe-area-inset-bottom\)\]{padding-bottom:env(safe-area-inset-bottom)}.hx-pb-px{padding-bottom:1px}.hx-pl-\[max\(env\(safe-area-inset-left\)\,1\.5rem\)\]{padding-left:max(env(safe-area-inset-left),1.5rem)}.hx-pr-2{padding-right:.5rem}.hx-pr-4{padding-right:1rem}.hx-pr-\[calc\(env\(safe-area-inset-right\)-1\.5rem\)\]{padding-right:calc(env(safe-area-inset-right) - 1.5rem)}.hx-pr-\[max\(env\(safe-area-inset-left\)\,1\.5rem\)\]{padding-right:max(env(safe-area-inset-left),1.5rem)}.hx-pr-\[max\(env\(safe-area-inset-right\)\,1\.5rem\)\]{padding-right:max(env(safe-area-inset-right),1.5rem)}.hx-pt-4{padding-top:1rem}.hx-pt-6{padding-top:1.5rem}.hx-pt-8{padding-top:2rem}.hx-text-left{text-align:left}.hx-text-center{text-align:center}.hx-align-middle{vertical-align:middle}.hx-align-text-bottom{vertical-align:text-bottom}.hx-align-\[-2\.5px\]{vertical-align:-2.5px}.hx-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,liberation mono,courier new,monospace}.hx-text-2xl{font-size:1.5rem}.hx-text-4xl{font-size:2.25rem}.hx-text-\[\.65rem\]{font-size:.65rem}.hx-text-\[10px\]{font-size:10px}.hx-text-base{font-size:1rem}.hx-text-lg{font-size:1.125rem}.hx-text-sm{font-size:.875rem}.hx-text-xl{font-size:1.25rem}.hx-text-xs{font-size:.75rem}.hx-font-bold{font-weight:700}.hx-font-extrabold{font-weight:800}.hx-font-medium{font-weight:500}.hx-font-normal{font-weight:400}.hx-font-semibold{font-weight:600}.hx-capitalize{text-transform:capitalize}.hx-leading-5{line-height:1.25rem}.hx-leading-6{line-height:1.5rem}.hx-leading-7{line-height:1.75rem}.hx-leading-none{line-height:1}.hx-leading-tight{line-height:1.25}.hx-tracking-tight{letter-spacing:-.015em}.hx-text-\[color\:hsl\(var\(--primary-hue\)\,100\%\,50\%\)\]{--tw-text-opacity:1;color:hsl(var(--primary-hue) 100% 50%/var(--tw-text-opacity))}.hx-text-amber-900{--tw-text-opacity:1;color:rgb(120 53 15/var(--tw-text-opacity))}.hx-text-blue-900{--tw-text-opacity:1;color:rgb(30 58 138/var(--tw-text-opacity))}.hx-text-current{color:currentColor}.hx-text-gray-100{--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity))}.hx-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.hx-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.hx-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.hx-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.hx-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.hx-text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity))}.hx-text-indigo-900{--tw-text-opacity:1;color:rgb(49 46 129/var(--tw-text-opacity))}.hx-text-orange-800{--tw-text-opacity:1;color:rgb(154 52 18/var(--tw-text-opacity))}.hx-text-primary-800{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 32)/var(--tw-text-opacity))}.hx-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity))}.hx-text-slate-900{--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.hx-text-transparent{color:transparent}.hx-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.hx-text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity))}.hx-underline{text-decoration-line:underline}.hx-no-underline{text-decoration-line:none}.hx-decoration-from-font{text-decoration-thickness:from-font}.hx-underline-offset-2{text-underline-offset:2px}.hx-opacity-0{opacity:0}.hx-opacity-50{opacity:.5}.hx-opacity-80{opacity:.8}.hx-shadow{--tw-shadow:0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-\[0_-12px_16px_\#fff\]{--tw-shadow:0 -12px 16px #fff;--tw-shadow-colored:0 -12px 16px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-\[0_-12px_16px_white\]{--tw-shadow:0 -12px 16px white;--tw-shadow-colored:0 -12px 16px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-\[0_2px_4px_rgba\(0\,0\,0\,\.02\)\,0_1px_0_rgba\(0\,0\,0\,\.06\)\]{--tw-shadow:0 2px 4px rgba(0,0,0,.02),0 1px 0 rgba(0,0,0,.06);--tw-shadow-colored:0 2px 4px var(--tw-shadow-color), 0 1px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-lg{--tw-shadow:0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-sm{--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-xl{--tw-shadow:0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hx-shadow-gray-100{--tw-shadow-color:#f3f4f6;--tw-shadow:var(--tw-shadow-colored)}.hx-ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.hx-ring-black\/5{--tw-ring-color:rgb(0 0 0 / 0.05)}.hx-transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.hx-transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.hx-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.hx-transition-opacity{transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.hx-transition-transform{transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.hx-duration-200{transition-duration:200ms}.hx-duration-75{transition-duration:75ms}.hx-ease-in{transition-timing-function:cubic-bezier(.4,0,1,1)}.\[-webkit-tap-highlight-color\:transparent\]{-webkit-tap-highlight-color:transparent}.\[-webkit-touch-callout\:none\]{-webkit-touch-callout:none}.\[counter-reset\:step\]{counter-reset:step}.\[hyphens\:auto\]{-webkit-hyphens:auto;hyphens:auto}.\[transition\:background-color_1\.5s_ease\]{transition:background-color 1.5s ease}.\[word-break\:break-word\]{word-break:break-word}.content :where(h1):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:.5rem;font-size:2.25rem;font-weight:700;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.content :where(h1):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.content :where(h2):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:2.5rem;border-bottom-width:1px;border-color:rgb(229 229 229/.7);padding-bottom:.25rem;font-size:1.875rem;font-weight:600;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}@media(prefers-contrast:more){.content :where(h2):not(:where([class~=not-prose],[class~=not-prose] *)){--tw-border-opacity:1;border-color:rgb(163 163 163/var(--tw-border-opacity))}}.content :where(h2):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 44)/.1);--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}@media(prefers-contrast:more){.content :where(h2):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(163 163 163/var(--tw-border-opacity))}}.content :where(h3):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:2rem;font-size:1.5rem;font-weight:600;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.content :where(h3):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.content :where(h4):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:2rem;font-size:1.25rem;font-weight:600;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.content :where(h4):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.content :where(h5):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:2rem;font-size:1.125rem;font-weight:600;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.content :where(h5):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.content :where(h6):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:2rem;font-size:1rem;font-weight:600;letter-spacing:-.015em;--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.content :where(h6):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.content :where(p):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:1.5rem;line-height:1.75rem}.content :where(p):not(:where([class~=not-prose],[class~=not-prose] *)):first-child{margin-top:0}.content :where(a):not(:where([class~=not-prose],[class~=not-prose] *)){--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity));text-decoration-line:underline;text-decoration-thickness:from-font;text-underline-position:from-font}.content :where(blockquote):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:1.5rem;--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity));font-style:italic;--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.content :where(blockquote):not(:where([class~=not-prose],[class~=not-prose] *)):first-child{margin-top:0}.content :where(blockquote):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(55 65 81/var(--tw-border-opacity));--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.content :where(blockquote):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=ltr],[dir=ltr] *){border-left-width:2px;padding-left:1.5rem}.content :where(blockquote):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=rtl],[dir=rtl] *){border-right-width:2px;padding-right:1.5rem}.content :where(pre):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)){margin-bottom:1rem;overflow-x:auto;border-radius:.75rem;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/.05);padding-top:1rem;padding-bottom:1rem;font-size:.9em;font-weight:500;-webkit-font-smoothing:auto;-moz-osx-font-smoothing:auto}@media(prefers-contrast:more){.content :where(pre):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)){border-width:1px;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 24)/.2);--tw-contrast:contrast(1.5);filter:var(--tw-blur)var(--tw-brightness)var(--tw-contrast)var(--tw-grayscale)var(--tw-hue-rotate)var(--tw-invert)var(--tw-saturate)var(--tw-sepia)var(--tw-drop-shadow)}}.content :where(pre):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 27)/.1)}@media(prefers-contrast:more){.content :where(pre):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 44)/.4)}}.content :where(code):not(:where(.hextra-code-block code,[class~=not-prose],[class~=not-prose] *)){overflow-wrap:break-word;border-radius:.375rem;border-width:1px;border-color:rgb(0 0 0/var(--tw-border-opacity));--tw-border-opacity:0.04;background-color:rgb(0 0 0/var(--tw-bg-opacity));--tw-bg-opacity:0.03;padding-top:.125rem;padding-bottom:.125rem;padding-left:.25em;padding-right:.25em;font-size:.9em}.content :where(code):not(:where(.hextra-code-block code,[class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){border-color:rgb(255 255 255/.1);background-color:rgb(255 255 255/.1)}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)){margin-top:1.5rem;display:block;overflow-x:auto;padding:0}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)):first-child{margin-top:0}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) tr{margin:0;border-top-width:1px;--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity));padding:0}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) tr:nth-child(even){--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) tr:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(75 85 99/var(--tw-border-opacity))}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) tr:is(html[class~=dark] *):nth-child(even){background-color:rgb(75 85 99/.2)}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) th{margin:0;border-width:1px;--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity));padding-left:1rem;padding-right:1rem;padding-top:.5rem;padding-bottom:.5rem;font-weight:600}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) th:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(75 85 99/var(--tw-border-opacity))}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) td{margin:0;border-width:1px;--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity));padding-left:1rem;padding-right:1rem;padding-top:.5rem;padding-bottom:.5rem}.content :where(table):not(:where(.hextra-code-block table,[class~=not-prose],[class~=not-prose] *)) td:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(75 85 99/var(--tw-border-opacity))}.content :where(ol):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:1.5rem;list-style-type:decimal}.content :where(ol):not(:where([class~=not-prose],[class~=not-prose] *)):first-child{margin-top:0}.content :where(ol):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=ltr],[dir=ltr] *){margin-left:1.5rem}.content :where(ol):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=rtl],[dir=rtl] *){margin-right:1.5rem}.content :where(ol):not(:where([class~=not-prose],[class~=not-prose] *)) li{margin-top:.5rem;margin-bottom:.5rem}.content :where(ul):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:1.5rem;list-style-type:disc}.content :where(ul):not(:where([class~=not-prose],[class~=not-prose] *)):first-child{margin-top:0}.content :where(ul):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=ltr],[dir=ltr] *){margin-left:1.5rem}.content :where(ul):not(:where([class~=not-prose],[class~=not-prose] *)):where([dir=rtl],[dir=rtl] *){margin-right:1.5rem}.content :where(ul):not(:where([class~=not-prose],[class~=not-prose] *)) li{margin-top:.5rem;margin-bottom:.5rem}.content :where(ul,ol)>li>:where(ul,ol):not(:where([class~=not-prose],[class~=not-prose] *)){margin-top:0}.content :where(kbd):not(:where([class~=not-prose],[class~=not-prose] *)){overflow-wrap:break-word;border-radius:.375rem;border-width:1px;border-color:rgb(0 0 0/var(--tw-border-opacity));--tw-border-opacity:0.04;background-color:rgb(0 0 0/var(--tw-bg-opacity));--tw-bg-opacity:0.03;padding-top:.125rem;padding-bottom:.125rem;padding-left:.25em;padding-right:.25em;font-size:.9em}.content :where(kbd):not(:where([class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){border-color:rgb(255 255 255/.1);background-color:rgb(255 255 255/.1)}.content :where(pre.mermaid):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)){border-radius:0;background-color:transparent}.content :where(pre.mermaid):not(:where(.hextra-code-block pre,[class~=not-prose],[class~=not-prose] *)):is(html[class~=dark] *){background-color:transparent}.content :where(img):not(:where([class~=not-prose],[class~=not-prose] *)){margin-left:auto;margin-right:auto;margin-top:1rem;margin-bottom:1rem;border-radius:.375rem}.content :where(figure):not(:where([class~=not-prose],[class~=not-prose] *)) figcaption{margin-top:.5rem;display:block;text-align:center;font-size:.875rem;--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.content :where(figure):not(:where([class~=not-prose],[class~=not-prose] *)) figcaption:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.content :where(dl):not(:where([class~=not-prose],[class~=not-prose] *)) dt{margin-top:1.5rem;font-weight:600}.content :where(dl):not(:where([class~=not-prose],[class~=not-prose] *)) dd{margin-top:.5rem;margin-bottom:.5rem;padding-inline-start:1.5rem}.content .footnotes{margin-top:3rem;font-size:.875rem}.subheading-anchor{opacity:0;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.subheading-anchor:where([dir=ltr],[dir=ltr] *){margin-left:.25rem}.subheading-anchor:where([dir=rtl],[dir=rtl] *){margin-right:.25rem}span:target+.subheading-anchor,:hover>.subheading-anchor,.subheading-anchor:focus{opacity:1}span+.subheading-anchor,:hover>.subheading-anchor{text-decoration-line:none !important}.subheading-anchor:after{padding-left:.25rem;padding-right:.25rem;--tw-content:'#';content:var(--tw-content);--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}.subheading-anchor:is(html[class~=dark] *):after{--tw-text-opacity:1;color:rgb(64 64 64/var(--tw-text-opacity))}span:target+.subheading-anchor:after{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}span:target+.subheading-anchor:is(html[class~=dark] *):after{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity))}article details>summary::-webkit-details-marker{display:none}article details>summary::before{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='hx-h-5 hx-w-5' viewBox='0 0 20 20' fill='currentColor'%3E%3Cpath fill-rule='evenodd' d='M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z' clip-rule='evenodd' /%3E%3C/svg%3E");height:1.2em;width:1.2em;vertical-align:-4px;padding:0 .6em}:lang(fa) ol{list-style-type:persian}.highlight{}.highlight .chroma .err{color:#a61717;background-color:#e3d2d2}.highlight .chroma .lnlinks{outline:none;text-decoration:none;color:inherit}.highlight .chroma .line{display:flex}.highlight .chroma .k{color:#000;font-weight:700}.highlight .chroma .kc{color:#000;font-weight:700}.highlight .chroma .kd{color:#000;font-weight:700}.highlight .chroma .kn{color:#000;font-weight:700}.highlight .chroma .kp{color:#000;font-weight:700}.highlight .chroma .kr{color:#000;font-weight:700}.highlight .chroma .kt{color:#458;font-weight:700}.highlight .chroma .na{color:teal}.highlight .chroma .nb{color:#0086b3}.highlight .chroma .bp{color:#999}.highlight .chroma .nc{color:#458;font-weight:700}.highlight .chroma .no{color:teal}.highlight .chroma .nd{color:#3c5d5d;font-weight:700}.highlight .chroma .ni{color:purple}.highlight .chroma .ne{color:#900;font-weight:700}.highlight .chroma .nf{color:#900;font-weight:700}.highlight .chroma .nl{color:#900;font-weight:700}.highlight .chroma .nn{color:#555}.highlight .chroma .nt{color:navy}.highlight .chroma .nv{color:teal}.highlight .chroma .vc{color:teal}.highlight .chroma .vg{color:teal}.highlight .chroma .vi{color:teal}.highlight .chroma .s{color:#d14}.highlight .chroma .sa{color:#d14}.highlight .chroma .sb{color:#d14}.highlight .chroma .sc{color:#d14}.highlight .chroma .dl{color:#d14}.highlight .chroma .sd{color:#d14}.highlight .chroma .s2{color:#d14}.highlight .chroma .se{color:#d14}.highlight .chroma .sh{color:#d14}.highlight .chroma .si{color:#d14}.highlight .chroma .sx{color:#d14}.highlight .chroma .sr{color:#009926}.highlight .chroma .s1{color:#d14}.highlight .chroma .ss{color:#990073}.highlight .chroma .m{color:#099}.highlight .chroma .mb{color:#099}.highlight .chroma .mf{color:#099}.highlight .chroma .mh{color:#099}.highlight .chroma .mi{color:#099}.highlight .chroma .il{color:#099}.highlight .chroma .mo{color:#099}.highlight .chroma .o{color:#000;font-weight:700}.highlight .chroma .ow{color:#000;font-weight:700}.highlight .chroma .c{color:#998;font-style:italic}.highlight .chroma .ch{color:#998;font-style:italic}.highlight .chroma .cm{color:#998;font-style:italic}.highlight .chroma .c1{color:#998;font-style:italic}.highlight .chroma .cs{color:#999;font-weight:700;font-style:italic}.highlight .chroma .cp{color:#999;font-weight:700;font-style:italic}.highlight .chroma .cpf{color:#999;font-weight:700;font-style:italic}.highlight .chroma .gd{color:#000;background-color:#fdd}.highlight .chroma .ge{color:#000;font-style:italic}.highlight .chroma .gr{color:#a00}.highlight .chroma .gh{color:#999}.highlight .chroma .gi{color:#000;background-color:#dfd}.highlight .chroma .go{color:#888}.highlight .chroma .gp{color:#555}.highlight .chroma .gs{font-weight:700}.highlight .chroma .gu{color:#aaa}.highlight .chroma .gt{color:#a00}.highlight .chroma .gl{text-decoration:underline}.highlight .chroma .w{color:#bbb}.dark .highlight{}.dark .highlight .chroma .x{}.dark .highlight .chroma .err{color:#f85149}.dark .highlight .chroma .cl{}.dark .highlight .chroma .lnlinks{outline:none;text-decoration:none;color:inherit}.dark .highlight .chroma .line{display:flex}.dark .highlight .chroma .k{color:#ff7b72}.dark .highlight .chroma .kc{color:#79c0ff}.dark .highlight .chroma .kd{color:#ff7b72}.dark .highlight .chroma .kn{color:#ff7b72}.dark .highlight .chroma .kp{color:#79c0ff}.dark .highlight .chroma .kr{color:#ff7b72}.dark .highlight .chroma .kt{color:#ff7b72}.dark .highlight .chroma .n{}.dark .highlight .chroma .na{}.dark .highlight .chroma .nb{}.dark .highlight .chroma .bp{}.dark .highlight .chroma .nc{color:#f0883e;font-weight:700}.dark .highlight .chroma .no{color:#79c0ff;font-weight:700}.dark .highlight .chroma .nd{color:#d2a8ff;font-weight:700}.dark .highlight .chroma .ni{color:#ffa657}.dark .highlight .chroma .ne{color:#f0883e;font-weight:700}.dark .highlight .chroma .nf{color:#d2a8ff;font-weight:700}.dark .highlight .chroma .fm{}.dark .highlight .chroma .nl{color:#79c0ff;font-weight:700}.dark .highlight .chroma .nn{color:#ff7b72}.dark .highlight .chroma .nx{}.dark .highlight .chroma .py{color:#79c0ff}.dark .highlight .chroma .nt{color:#7ee787}.dark .highlight .chroma .nv{color:#79c0ff}.dark .highlight .chroma .vc{}.dark .highlight .chroma .vg{}.dark .highlight .chroma .vi{}.dark .highlight .chroma .vm{}.dark .highlight .chroma .l{color:#a5d6ff}.dark .highlight .chroma .ld{color:#79c0ff}.dark .highlight .chroma .s{color:#a5d6ff}.dark .highlight .chroma .sa{color:#79c0ff}.dark .highlight .chroma .sb{color:#a5d6ff}.dark .highlight .chroma .sc{color:#a5d6ff}.dark .highlight .chroma .dl{color:#79c0ff}.dark .highlight .chroma .sd{color:#a5d6ff}.dark .highlight .chroma .s2{color:#a5d6ff}.dark .highlight .chroma .se{color:#79c0ff}.dark .highlight .chroma .sh{color:#79c0ff}.dark .highlight .chroma .si{color:#a5d6ff}.dark .highlight .chroma .sx{color:#a5d6ff}.dark .highlight .chroma .sr{color:#79c0ff}.dark .highlight .chroma .s1{color:#a5d6ff}.dark .highlight .chroma .ss{color:#a5d6ff}.dark .highlight .chroma .m{color:#a5d6ff}.dark .highlight .chroma .mb{color:#a5d6ff}.dark .highlight .chroma .mf{color:#a5d6ff}.dark .highlight .chroma .mh{color:#a5d6ff}.dark .highlight .chroma .mi{color:#a5d6ff}.dark .highlight .chroma .il{color:#a5d6ff}.dark .highlight .chroma .mo{color:#a5d6ff}.dark .highlight .chroma .o{color:#ff7b72;font-weight:700}.dark .highlight .chroma .ow{color:#ff7b72;font-weight:700}.dark .highlight .chroma .p{}.dark .highlight .chroma .c{color:#8b949e;font-style:italic}.dark .highlight .chroma .ch{color:#8b949e;font-style:italic}.dark .highlight .chroma .cm{color:#8b949e;font-style:italic}.dark .highlight .chroma .c1{color:#8b949e;font-style:italic}.dark .highlight .chroma .cs{color:#8b949e;font-weight:700;font-style:italic}.dark .highlight .chroma .cp{color:#8b949e;font-weight:700;font-style:italic}.dark .highlight .chroma .cpf{color:#8b949e;font-weight:700;font-style:italic}.dark .highlight .chroma .g{}.dark .highlight .chroma .gd{color:#ffa198;background-color:#490202}.dark .highlight .chroma .ge{color:inherit;font-style:italic}.dark .highlight .chroma .gr{color:#ffa198}.dark .highlight .chroma .gh{color:#79c0ff;font-weight:700}.dark .highlight .chroma .gi{color:#56d364;background-color:#0f5323}.dark .highlight .chroma .go{color:#8b949e}.dark .highlight .chroma .gp{color:#8b949e}.dark .highlight .chroma .gs{font-weight:700}.dark .highlight .chroma .gu{color:#79c0ff}.dark .highlight .chroma .gt{color:#ff7b72}.dark .highlight .chroma .gl{text-decoration:underline}.dark .highlight .chroma .w{color:#6e7681}.hextra-code-block{font-size:.9em;line-height:1.25rem}.hextra-code-block pre{overflow-x:auto;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/.05);font-size:.9em;font-weight:500;-webkit-font-smoothing:auto;-moz-osx-font-smoothing:auto}@media(prefers-contrast:more){.hextra-code-block pre{border-width:1px;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 24)/.2);--tw-contrast:contrast(1.5);filter:var(--tw-blur)var(--tw-brightness)var(--tw-contrast)var(--tw-grayscale)var(--tw-hue-rotate)var(--tw-invert)var(--tw-saturate)var(--tw-sepia)var(--tw-drop-shadow)}}.hextra-code-block pre:is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 27)/.1)}@media(prefers-contrast:more){.hextra-code-block pre:is(html[class~=dark] *){border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 44)/.4)}}.hextra-code-block .filename{position:absolute;top:0;z-index:1;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-top-left-radius:.75rem;border-top-right-radius:.75rem;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/.05);padding-top:.5rem;padding-bottom:.5rem;padding-left:1rem;padding-right:1rem;font-size:.75rem;--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.hextra-code-block .filename:is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 27)/.1);--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity))}.hextra-code-block .filename+pre:not(.lntable pre){padding-top:3rem}.hextra-code-block pre:not(.lntable pre){margin-bottom:1rem;border-radius:.75rem;padding-left:1rem;padding-right:1rem;padding-top:1rem;padding-bottom:1rem}.hextra-code-block div:nth-of-type(2) pre{padding-top:3rem;padding-bottom:1rem}.chroma .lntable{margin:0;display:block;width:auto;overflow:auto;border-radius:.75rem}.chroma .lntable pre{padding-top:1rem;padding-bottom:1rem}.chroma .ln,.chroma .lnt:not(.hl>.lnt),.chroma .hl:not(.line){min-width:2.6rem;padding-left:1rem;padding-right:1rem;--tw-text-opacity:1;color:rgb(82 82 82/var(--tw-text-opacity))}.chroma .ln:is(html[class~=dark] *),.chroma .lnt:not(.hl>.lnt):is(html[class~=dark] *),.chroma .hl:not(.line):is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(212 212 212/var(--tw-text-opacity))}.chroma .lntd{padding:0;vertical-align:top}.chroma .lntd:last-of-type{width:100%}.chroma .hl{display:block;width:100%;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 32)/.1)}.hextra-cards{grid-template-columns:repeat(auto-fill,minmax(max(250px,calc((100% - 1rem * 2)/var(--hextra-cards-grid-cols))),1fr))}.hextra-card{position:relative}.hextra-card img{-webkit-user-select:none;-moz-user-select:none;user-select:none}.hextra-card:hover svg{color:currentColor}.hextra-card svg{width:1.5rem;color:#0003;transition:color .3s ease}.hextra-card p{margin-top:.5rem;position:relative}.dark .hextra-card svg{color:#fff6}.dark .hextra-card:hover svg{color:currentColor}.hextra-card-tag{position:absolute;top:5px;right:5px;z-index:10}.steps h3{counter-increment:step}.steps h3:before{position:absolute;height:33px;width:33px;border-width:4px;--tw-border-opacity:1;border-color:rgb(255 255 255/var(--tw-border-opacity));--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.steps h3:is(html[class~=dark] *):before{--tw-border-opacity:1;border-color:rgb(17 17 17/var(--tw-border-opacity));--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity))}.steps h3:before{border-radius:9999px;text-align:center;text-indent:-1px;font-size:1rem;font-weight:400;--tw-text-opacity:1;color:rgb(163 163 163/var(--tw-text-opacity));margin-top:3px}.steps h3:where([dir=ltr],[dir=ltr] *):before{margin-left:-41px}.steps h3:where([dir=rtl],[dir=rtl] *):before{margin-right:-44px}.steps h3:before{content:counter(step)}:lang(fa) .steps h3:before{content:counter(step,persian)}.search-wrapper li{margin-left:.625rem;margin-right:.625rem;overflow-wrap:break-word;border-radius:.375rem;--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}@media(prefers-contrast:more){.search-wrapper li{border-width:1px;border-color:transparent}}.search-wrapper li:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}.search-wrapper li a{display:block;scroll-margin:3rem;padding-left:.625rem;padding-right:.625rem;padding-top:.5rem;padding-bottom:.5rem}.search-wrapper li .title{font-size:1rem;font-weight:600;line-height:1.25rem}.search-wrapper li .active{border-radius:.375rem;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/.1)}@media(prefers-contrast:more){.search-wrapper li .active{--tw-border-opacity:1;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/var(--tw-border-opacity))}}.search-wrapper .no-result{display:block;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:2rem;text-align:center;font-size:.875rem;--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.search-wrapper .prefix{margin-left:.625rem;margin-right:.625rem;margin-bottom:.5rem;margin-top:1.5rem;-webkit-user-select:none;-moz-user-select:none;user-select:none;border-bottom-width:1px;border-color:rgb(0 0 0/.1);padding-left:.625rem;padding-right:.625rem;padding-bottom:.375rem;font-size:.75rem;font-weight:600;text-transform:uppercase;--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.search-wrapper .prefix:first-child{margin-top:0}@media(prefers-contrast:more){.search-wrapper .prefix{--tw-border-opacity:1;border-color:rgb(75 85 99/var(--tw-border-opacity));--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}}.search-wrapper .prefix:is(html[class~=dark] *){border-color:rgb(255 255 255/.2);--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}@media(prefers-contrast:more){.search-wrapper .prefix:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(249 250 251/var(--tw-border-opacity));--tw-text-opacity:1;color:rgb(249 250 251/var(--tw-text-opacity))}}.search-wrapper .excerpt{margin-top:.25rem;overflow:hidden;text-overflow:ellipsis;font-size:.875rem;line-height:1.35rem;--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.search-wrapper .excerpt:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}@media(prefers-contrast:more){.search-wrapper .excerpt:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(249 250 251/var(--tw-text-opacity))}}.search-wrapper .excerpt{display:-webkit-box;line-clamp:1;-webkit-line-clamp:1;-webkit-box-orient:vertical}.search-wrapper .match{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}@media(max-width:767px){.sidebar-container{position:fixed;top:0;bottom:0;z-index:15;width:100%;overscroll-behavior:contain;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));padding-top:calc(var(--navbar-height))}.sidebar-container:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(17 17 17/var(--tw-bg-opacity))}.sidebar-container{transition:transform .8s cubic-bezier(.52,.16,.04,1);will-change:transform,opacity;contain:layout style;backface-visibility:hidden}}.sidebar-container li>div{height:0}.sidebar-container li.open>div{height:auto;padding-top:.25rem}.sidebar-container li.open>a>span>svg>path{--tw-rotate:90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}nav .search-wrapper{display:none}@media(min-width:768px){nav .search-wrapper{display:inline-block}}@supports(((-webkit-backdrop-filter:blur(1px)) or (backdrop-filter:blur(1px)))){.nav-container-blur{background-color:rgb(255 255 255/.85);--tw-backdrop-blur:blur(12px);-webkit-backdrop-filter:var(--tw-backdrop-blur)var(--tw-backdrop-brightness)var(--tw-backdrop-contrast)var(--tw-backdrop-grayscale)var(--tw-backdrop-hue-rotate)var(--tw-backdrop-invert)var(--tw-backdrop-opacity)var(--tw-backdrop-saturate)var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur)var(--tw-backdrop-brightness)var(--tw-backdrop-contrast)var(--tw-backdrop-grayscale)var(--tw-backdrop-hue-rotate)var(--tw-backdrop-invert)var(--tw-backdrop-opacity)var(--tw-backdrop-saturate)var(--tw-backdrop-sepia)}.nav-container-blur:is(html[class~=dark] *){background-color:rgb(17 17 17/.8) !important}}.hamburger-menu svg g{transform-origin:center;transition:transform .2s cubic-bezier(.25,1,.5,1)}.hamburger-menu svg path{opacity:1;transition:transform .2s cubic-bezier(.25,1,.5,1).2s,opacity .2s ease .2s}.hamburger-menu svg.open path{transition:transform .2s cubic-bezier(.25,1,.5,1),opacity 0s ease .2s}.hamburger-menu svg.open g{transition:transform .2s cubic-bezier(.25,1,.5,1).2s}.hamburger-menu svg.open>path{opacity:0}.hamburger-menu svg.open>g:nth-of-type(1){--tw-rotate:45deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}.hamburger-menu svg.open>g:nth-of-type(1) path{transform:translate3d(0,4px,0)}.hamburger-menu svg.open>g:nth-of-type(2){--tw-rotate:-45deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}.hamburger-menu svg.open>g:nth-of-type(2) path{transform:translate3d(0,-4px,0)}.hextra-scrollbar,.hextra-scrollbar *{scrollbar-width:thin;scrollbar-color:oklch(55.55% 0 0/40%)transparent;scrollbar-gutter:stable}.hextra-scrollbar::-webkit-scrollbar,.hextra-scrollbar *::-webkit-scrollbar{height:.75rem;width:.75rem}.hextra-scrollbar::-webkit-scrollbar-track,.hextra-scrollbar *::-webkit-scrollbar-track{background-color:transparent}.hextra-scrollbar::-webkit-scrollbar-thumb,.hextra-scrollbar *::-webkit-scrollbar-thumb{border-radius:10px}.hextra-scrollbar:hover::-webkit-scrollbar-thumb,.hextra-scrollbar *:hover::-webkit-scrollbar-thumb{border:3px solid transparent;background-color:var(--tw-shadow-color);background-clip:content-box;--tw-shadow-color:rgb(115 115 115 / 0.2);--tw-shadow:var(--tw-shadow-colored)}.hextra-scrollbar:hover::-webkit-scrollbar-thumb:hover,.hextra-scrollbar *:hover::-webkit-scrollbar-thumb:hover{--tw-shadow-color:rgb(115 115 115 / 0.4);--tw-shadow:var(--tw-shadow-colored)}@supports(((-webkit-backdrop-filter:blur(1px)) or (backdrop-filter:blur(1px)))){.hextra-code-copy-btn{--tw-bg-opacity:.85;--tw-backdrop-blur:blur(12px);-webkit-backdrop-filter:var(--tw-backdrop-blur)var(--tw-backdrop-brightness)var(--tw-backdrop-contrast)var(--tw-backdrop-grayscale)var(--tw-backdrop-hue-rotate)var(--tw-backdrop-invert)var(--tw-backdrop-opacity)var(--tw-backdrop-saturate)var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur)var(--tw-backdrop-brightness)var(--tw-backdrop-contrast)var(--tw-backdrop-grayscale)var(--tw-backdrop-hue-rotate)var(--tw-backdrop-invert)var(--tw-backdrop-opacity)var(--tw-backdrop-saturate)var(--tw-backdrop-sepia)}.hextra-code-copy-btn:is(html[class~=dark] *){--tw-bg-opacity:0.8}}@media(min-width:1024px){.hextra-feature-grid{grid-template-columns:repeat(var(--hextra-feature-grid-cols),minmax(0,1fr))}}.hextra-jupyter-code-cell{scrollbar-gutter:auto;margin-top:1.5rem}.hextra-jupyter-code-cell .hextra-jupyter-code-cell-outputs-container{overflow:hidden;font-size:.75rem}.hextra-jupyter-code-cell .hextra-jupyter-code-cell-outputs-container .hextra-jupyter-code-cell-outputs{max-height:50vh;overflow:auto}.hextra-jupyter-code-cell .hextra-jupyter-code-cell-outputs-container .hextra-jupyter-code-cell-outputs pre{max-width:100%;overflow:auto;font-size:.75rem}.hextra-badge{display:inline-flex;align-items:center}html{font-size:1rem;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-feature-settings:"rlig" 1,"calt" 1,"ss01" 1;-webkit-tap-highlight-color:transparent}body{width:100%;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}body:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(17 17 17/var(--tw-bg-opacity));--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity))}:root{--primary-hue:212deg;--primary-saturation:100%;--primary-lightness:50%;--navbar-height:4rem;--menu-height:3.75rem}.dark{--primary-hue:204deg;--primary-saturation:100%;--primary-lightness:50%}.placeholder\:hx-text-gray-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.placeholder\:hx-text-gray-500::placeholder{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.before\:hx-pointer-events-none::before{content:var(--tw-content);pointer-events:none}.before\:hx-absolute::before{content:var(--tw-content);position:absolute}.before\:hx-inset-0::before{content:var(--tw-content);inset:0}.before\:hx-inset-y-1::before{content:var(--tw-content);top:.25rem;bottom:.25rem}.before\:hx-mr-1::before{content:var(--tw-content);margin-right:.25rem}.before\:hx-inline-block::before{content:var(--tw-content);display:inline-block}.before\:hx-w-px::before{content:var(--tw-content);width:1px}.before\:hx-bg-gray-200::before{content:var(--tw-content);--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.before\:hx-opacity-25::before{content:var(--tw-content);opacity:.25}.before\:hx-transition-transform::before{content:var(--tw-content);transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms}.before\:hx-content-\[\'\#\'\]::before{--tw-content:'#';content:var(--tw-content)}.before\:hx-content-\[\'\'\]::before{--tw-content:'';content:var(--tw-content)}.before\:hx-content-\[\\\"\\\"\]::before{--tw-content:\"\";content:var(--tw-content)}.first\:hx-mt-0:first-child{margin-top:0}.last-of-type\:hx-mb-0:last-of-type{margin-bottom:0}.hover\:hx-border-gray-200:hover{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity))}.hover\:hx-border-gray-300:hover{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.hover\:hx-border-gray-400:hover{--tw-border-opacity:1;border-color:rgb(156 163 175/var(--tw-border-opacity))}.hover\:hx-border-gray-900:hover{--tw-border-opacity:1;border-color:rgb(17 24 39/var(--tw-border-opacity))}.hover\:hx-bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.hover\:hx-bg-gray-800\/5:hover{background-color:rgb(31 41 55/5%)}.hover\:hx-bg-primary-50:hover{--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 47)/var(--tw-bg-opacity))}.hover\:hx-bg-primary-700:hover{--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/var(--tw-bg-opacity))}.hover\:hx-bg-slate-50:hover{--tw-bg-opacity:1;background-color:rgb(248 250 252/var(--tw-bg-opacity))}.hover\:hx-text-black:hover{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity))}.hover\:hx-text-gray-800:hover{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.hover\:hx-text-gray-900:hover{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.hover\:hx-text-primary-600:hover{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}.hover\:hx-opacity-60:hover{opacity:.6}.hover\:hx-opacity-75:hover{opacity:.75}.hover\:hx-shadow-lg:hover{--tw-shadow:0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hover\:hx-shadow-md:hover{--tw-shadow:0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.hover\:hx-shadow-gray-100:hover{--tw-shadow-color:#f3f4f6;--tw-shadow:var(--tw-shadow-colored)}.focus\:hx-bg-white:focus{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.focus\:hx-outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:hx-ring-4:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\:hx-ring-primary-300:focus{--tw-ring-opacity:1;--tw-ring-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness)) / 50) * 27) / var(--tw-ring-opacity))}.active\:hx-bg-gray-400\/20:active{background-color:rgb(156 163 175/.2)}.active\:hx-opacity-50:active{opacity:.5}.active\:hx-shadow-sm:active{--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.active\:hx-shadow-gray-200:active{--tw-shadow-color:#e5e7eb;--tw-shadow:var(--tw-shadow-colored)}.hx-group[open] .group-open\:before\:hx-rotate-90::before{content:var(--tw-content);--tw-rotate:90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}.hx-group:hover .group-hover\:hx-underline{text-decoration-line:underline}.hx-group\/code:hover .group-hover\/code\:hx-opacity-100{opacity:1}.hx-group\/copybtn.copied .group-\[\.copied\]\/copybtn\:hx-block{display:block}.hx-group\/copybtn.copied .group-\[\.copied\]\/copybtn\:hx-hidden{display:none}.data-\[state\=selected\]\:hx-block[data-state=selected]{display:block}.data-\[state\=closed\]\:hx-hidden[data-state=closed]{display:none}.data-\[state\=open\]\:hx-hidden[data-state=open]{display:none}.data-\[state\=selected\]\:hx-border-primary-500[data-state=selected]{--tw-border-opacity:1;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/var(--tw-border-opacity))}.data-\[state\=selected\]\:hx-text-primary-600[data-state=selected]{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}.hx-group[data-theme=dark] .group-data-\[theme\=dark\]\:hx-hidden{display:none}.hx-group[data-theme=light] .group-data-\[theme\=light\]\:hx-hidden{display:none}@media(prefers-contrast:more){.contrast-more\:hx-border{border-width:1px}.contrast-more\:hx-border-t{border-top-width:1px}.contrast-more\:hx-border-current{border-color:initial}.contrast-more\:hx-border-gray-800{--tw-border-opacity:1;border-color:rgb(31 41 55/var(--tw-border-opacity))}.contrast-more\:hx-border-gray-900{--tw-border-opacity:1;border-color:rgb(17 24 39/var(--tw-border-opacity))}.contrast-more\:hx-border-neutral-400{--tw-border-opacity:1;border-color:rgb(163 163 163/var(--tw-border-opacity))}.contrast-more\:hx-border-primary-500{--tw-border-opacity:1;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/var(--tw-border-opacity))}.contrast-more\:hx-border-transparent{border-color:transparent}.contrast-more\:hx-font-bold{font-weight:700}.contrast-more\:hx-text-current{color:currentColor}.contrast-more\:hx-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.contrast-more\:hx-text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.contrast-more\:hx-text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.contrast-more\:hx-underline{text-decoration-line:underline}.contrast-more\:hx-shadow-\[0_0_0_1px_\#000\]{--tw-shadow:0 0 0 1px #000;--tw-shadow-colored:0 0 0 1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.contrast-more\:hx-shadow-none{--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.contrast-more\:hover\:hx-border-gray-900:hover{--tw-border-opacity:1;border-color:rgb(17 24 39/var(--tw-border-opacity))}}.dark\:hx-block:is(html[class~=dark] *){display:block}.dark\:hx-hidden:is(html[class~=dark] *){display:none}.dark\:hx-border-amber-200\/30:is(html[class~=dark] *){border-color:rgb(253 230 138/.3)}.dark\:hx-border-blue-200\/30:is(html[class~=dark] *){border-color:rgb(191 219 254/.3)}.dark\:hx-border-gray-100\/20:is(html[class~=dark] *){border-color:rgb(243 244 246/.2)}.dark\:hx-border-gray-400:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(156 163 175/var(--tw-border-opacity))}.dark\:hx-border-green-200\/30:is(html[class~=dark] *){border-color:rgb(187 247 208/.3)}.dark\:hx-border-indigo-200\/30:is(html[class~=dark] *){border-color:rgb(199 210 254/.3)}.dark\:hx-border-neutral-700:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(64 64 64/var(--tw-border-opacity))}.dark\:hx-border-neutral-800:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(38 38 38/var(--tw-border-opacity))}.dark\:hx-border-orange-400\/30:is(html[class~=dark] *){border-color:rgb(251 146 60/.3)}.dark\:hx-border-red-200\/30:is(html[class~=dark] *){border-color:rgb(254 202 202/.3)}.dark\:hx-border-white\/10:is(html[class~=dark] *){border-color:rgb(255 255 255/.1)}.dark\:hx-border-yellow-200\/30:is(html[class~=dark] *){border-color:rgb(254 240 138/.3)}.dark\:hx-bg-amber-900\/30:is(html[class~=dark] *){background-color:rgb(120 53 15/.3)}.dark\:hx-bg-black\/60:is(html[class~=dark] *){background-color:rgb(0 0 0/.6)}.dark\:hx-bg-blue-900\/30:is(html[class~=dark] *){background-color:rgb(30 58 138/.3)}.dark\:hx-bg-dark:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(17 17 17/var(--tw-bg-opacity))}.dark\:hx-bg-dark\/50:is(html[class~=dark] *){background-color:rgb(17 17 17/.5)}.dark\:hx-bg-gray-50\/10:is(html[class~=dark] *){background-color:rgb(249 250 251/.1)}.dark\:hx-bg-green-900\/30:is(html[class~=dark] *){background-color:rgb(20 83 45/.3)}.dark\:hx-bg-indigo-900\/30:is(html[class~=dark] *){background-color:rgb(49 46 129/.3)}.dark\:hx-bg-neutral-800:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity))}.dark\:hx-bg-neutral-900:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity))}.dark\:hx-bg-orange-400\/20:is(html[class~=dark] *){background-color:rgb(251 146 60/.2)}.dark\:hx-bg-primary-300\/10:is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 27)/.1)}.dark\:hx-bg-primary-400\/10:is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 16)/.1)}.dark\:hx-bg-primary-600:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-bg-opacity))}.dark\:hx-bg-red-900\/30:is(html[class~=dark] *){background-color:rgb(127 29 29/.3)}.dark\:hx-bg-yellow-700\/30:is(html[class~=dark] *){background-color:rgb(161 98 7/.3)}.dark\:hx-from-gray-100:is(html[class~=dark] *){--tw-gradient-from:#f3f4f6 var(--tw-gradient-from-position);--tw-gradient-to:rgb(243 244 246 / 0) var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-from), var(--tw-gradient-to)}.dark\:hx-to-gray-400:is(html[class~=dark] *){--tw-gradient-to:#9ca3af var(--tw-gradient-to-position)}.dark\:hx-text-amber-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(253 230 138/var(--tw-text-opacity))}.dark\:hx-text-blue-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(191 219 254/var(--tw-text-opacity))}.dark\:hx-text-gray-100:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity))}.dark\:hx-text-gray-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity))}.dark\:hx-text-gray-300:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}.dark\:hx-text-gray-400:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.dark\:hx-text-gray-50:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(249 250 251/var(--tw-text-opacity))}.dark\:hx-text-green-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(187 247 208/var(--tw-text-opacity))}.dark\:hx-text-indigo-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(199 210 254/var(--tw-text-opacity))}.dark\:hx-text-neutral-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(229 229 229/var(--tw-text-opacity))}.dark\:hx-text-neutral-400:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(163 163 163/var(--tw-text-opacity))}.dark\:hx-text-orange-300:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(253 186 116/var(--tw-text-opacity))}.dark\:hx-text-primary-600:is(html[class~=dark] *){--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}.dark\:hx-text-red-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity))}.dark\:hx-text-slate-100:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity))}.dark\:hx-text-yellow-200:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(254 240 138/var(--tw-text-opacity))}.dark\:hx-opacity-80:is(html[class~=dark] *){opacity:.8}.dark\:hx-shadow-\[0_-12px_16px_\#111\]:is(html[class~=dark] *){--tw-shadow:0 -12px 16px #111;--tw-shadow-colored:0 -12px 16px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.dark\:hx-shadow-\[0_-1px_0_rgba\(255\2c 255\2c 255\2c \.1\)_inset\]:is(html[class~=dark] *){--tw-shadow:0 -1px 0 rgba(255,255,255,.1) inset;--tw-shadow-colored:inset 0 -1px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.dark\:hx-shadow-none:is(html[class~=dark] *){--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.dark\:hx-ring-white\/20:is(html[class~=dark] *){--tw-ring-color:rgb(255 255 255 / 0.2)}.dark\:placeholder\:hx-text-gray-400:is(html[class~=dark] *)::-moz-placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.dark\:placeholder\:hx-text-gray-400:is(html[class~=dark] *)::placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.dark\:before\:hx-bg-neutral-800:is(html[class~=dark] *)::before{content:var(--tw-content);--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity))}.dark\:before\:hx-invert:is(html[class~=dark] *)::before{content:var(--tw-content);--tw-invert:invert(100%);filter:var(--tw-blur)var(--tw-brightness)var(--tw-contrast)var(--tw-grayscale)var(--tw-hue-rotate)var(--tw-invert)var(--tw-saturate)var(--tw-sepia)var(--tw-drop-shadow)}.dark\:hover\:hx-border-gray-100:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(243 244 246/var(--tw-border-opacity))}.dark\:hover\:hx-border-gray-600:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(75 85 99/var(--tw-border-opacity))}.dark\:hover\:hx-border-neutral-500:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(115 115 115/var(--tw-border-opacity))}.dark\:hover\:hx-border-neutral-700:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(64 64 64/var(--tw-border-opacity))}.dark\:hover\:hx-border-neutral-800:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(38 38 38/var(--tw-border-opacity))}.dark\:hover\:hx-bg-gray-100\/5:hover:is(html[class~=dark] *){background-color:rgb(243 244 246/5%)}.dark\:hover\:hx-bg-neutral-700:hover:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(64 64 64/var(--tw-bg-opacity))}.dark\:hover\:hx-bg-neutral-800:hover:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity))}.dark\:hover\:hx-bg-neutral-900:hover:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity))}.dark\:hover\:hx-bg-primary-100\/5:hover:is(html[class~=dark] *){background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 44)/.05)}.dark\:hover\:hx-bg-primary-700:hover:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 39)/var(--tw-bg-opacity))}.hover\:dark\:hx-bg-primary-500\/10:is(html[class~=dark] *):hover{background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/.1)}.dark\:hover\:hx-text-gray-100:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity))}.dark\:hover\:hx-text-gray-200:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity))}.dark\:hover\:hx-text-gray-300:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}.dark\:hover\:hx-text-gray-50:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(249 250 251/var(--tw-text-opacity))}.dark\:hover\:hx-text-neutral-50:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity))}.dark\:hover\:hx-text-white:hover:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.hover\:dark\:hx-text-primary-600:is(html[class~=dark] *):hover{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}.dark\:hover\:hx-shadow-none:hover:is(html[class~=dark] *){--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.dark\:focus\:hx-bg-dark:focus:is(html[class~=dark] *){--tw-bg-opacity:1;background-color:rgb(17 17 17/var(--tw-bg-opacity))}.dark\:focus\:hx-ring-primary-800:focus:is(html[class~=dark] *){--tw-ring-opacity:1;--tw-ring-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness) / 50) * 32) / var(--tw-ring-opacity))}.data-\[state\=selected\]\:dark\:hx-border-primary-500:is(html[class~=dark] *)[data-state=selected]{--tw-border-opacity:1;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/var(--tw-border-opacity))}.data-\[state\=selected\]\:dark\:hx-text-primary-600:is(html[class~=dark] *)[data-state=selected]{--tw-text-opacity:1;color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 45)/var(--tw-text-opacity))}@media(prefers-contrast:more){.contrast-more\:dark\:hx-border-current:is(html[class~=dark] *){border-color:initial}.contrast-more\:dark\:hx-border-gray-50:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(249 250 251/var(--tw-border-opacity))}.contrast-more\:dark\:hx-border-neutral-400:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(163 163 163/var(--tw-border-opacity))}.contrast-more\:dark\:hx-border-primary-500:is(html[class~=dark] *){--tw-border-opacity:1;border-color:hsl(var(--primary-hue) var(--primary-saturation) calc(calc(var(--primary-lightness)/50) * 50)/var(--tw-border-opacity))}.dark\:contrast-more\:hx-border-neutral-400:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(163 163 163/var(--tw-border-opacity))}.contrast-more\:dark\:hx-text-current:is(html[class~=dark] *){color:currentColor}.contrast-more\:dark\:hx-text-gray-100:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity))}.contrast-more\:dark\:hx-text-gray-300:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity))}.contrast-more\:dark\:hx-text-gray-50:is(html[class~=dark] *){--tw-text-opacity:1;color:rgb(249 250 251/var(--tw-text-opacity))}.contrast-more\:dark\:hx-shadow-\[0_0_0_1px_\#fff\]:is(html[class~=dark] *){--tw-shadow:0 0 0 1px #fff;--tw-shadow-colored:0 0 0 1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.contrast-more\:dark\:hx-shadow-none:is(html[class~=dark] *){--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.contrast-more\:dark\:hover\:hx-border-gray-50:hover:is(html[class~=dark] *){--tw-border-opacity:1;border-color:rgb(249 250 251/var(--tw-border-opacity))}}@media not all and (min-width:1280px){.max-xl\:hx-hidden{display:none}}@media not all and (min-width:1024px){.max-lg\:hx-min-h-\[340px\]{min-height:340px}}@media not all and (min-width:768px){.max-md\:hx-hidden{display:none}.max-md\:hx-min-h-\[340px\]{min-height:340px}.max-md\:\[transform\:translate3d\(0\2c -100\%\2c 0\)\]{transform:translate3d(0,-100%,0)}}@media not all and (min-width:640px){.max-sm\:hx-grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}}@media(min-width:640px){.sm\:hx-block{display:block}.sm\:hx-flex{display:flex}.sm\:hx-w-\[110\%\]{width:110%}.sm\:hx-items-start{align-items:flex-start}.sm\:hx-text-xl{font-size:1.25rem}@media not all and (min-width:1024px){.sm\:max-lg\:hx-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}}@media(min-width:768px){.md\:hx-sticky{position:sticky}.md\:hx-top-16{top:4rem}.md\:hx-inline-block{display:inline-block}.md\:hx-hidden{display:none}.md\:hx-aspect-\[1\.1\/1\]{aspect-ratio:1.1/1}.md\:hx-h-\[calc\(100vh-var\(--navbar-height\)-var\(--menu-height\)\)\]{height:calc(100vh - var(--navbar-height) - var(--menu-height))}.md\:hx-max-h-\[min\(calc\(100vh-5rem-env\(safe-area-inset-bottom\)\)\2c 400px\)\]{max-height:min(calc(100vh - 5rem - env(safe-area-inset-bottom)),400px)}.md\:hx-w-64{width:16rem}.md\:hx-shrink-0{flex-shrink:0}.md\:hx-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:hx-justify-start{justify-content:flex-start}.md\:hx-self-start{align-self:flex-start}.md\:hx-px-12{padding-left:3rem;padding-right:3rem}.md\:hx-pt-12{padding-top:3rem}.md\:hx-text-5xl{font-size:3rem}.md\:hx-text-lg{font-size:1.125rem}.md\:hx-text-sm{font-size:.875rem}}@media(min-width:1024px){.lg\:hx-grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}}@media(min-width:1280px){.xl\:hx-block{display:block}.xl\:hx-grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}}.ltr\:hx-right-1\.5:where([dir=ltr],[dir=ltr] *){right:.375rem}.ltr\:hx-right-3:where([dir=ltr],[dir=ltr] *){right:.75rem}.ltr\:hx--mr-4:where([dir=ltr],[dir=ltr] *){margin-right:-1rem}.ltr\:hx-ml-1:where([dir=ltr],[dir=ltr] *){margin-left:.25rem}.ltr\:hx-ml-3:where([dir=ltr],[dir=ltr] *){margin-left:.75rem}.ltr\:hx-ml-auto:where([dir=ltr],[dir=ltr] *){margin-left:auto}.ltr\:hx-mr-auto:where([dir=ltr],[dir=ltr] *){margin-right:auto}.ltr\:hx-rotate-180:where([dir=ltr],[dir=ltr] *){--tw-rotate:180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}.ltr\:hx-border-l:where([dir=ltr],[dir=ltr] *){border-left-width:1px}.ltr\:hx-pl-12:where([dir=ltr],[dir=ltr] *){padding-left:3rem}.ltr\:hx-pl-16:where([dir=ltr],[dir=ltr] *){padding-left:4rem}.ltr\:hx-pl-3:where([dir=ltr],[dir=ltr] *){padding-left:.75rem}.ltr\:hx-pl-4:where([dir=ltr],[dir=ltr] *){padding-left:1rem}.ltr\:hx-pl-5:where([dir=ltr],[dir=ltr] *){padding-left:1.25rem}.ltr\:hx-pl-6:where([dir=ltr],[dir=ltr] *){padding-left:1.5rem}.ltr\:hx-pl-8:where([dir=ltr],[dir=ltr] *){padding-left:2rem}.ltr\:hx-pr-0:where([dir=ltr],[dir=ltr] *){padding-right:0}.ltr\:hx-pr-2:where([dir=ltr],[dir=ltr] *){padding-right:.5rem}.ltr\:hx-pr-4:where([dir=ltr],[dir=ltr] *){padding-right:1rem}.ltr\:hx-pr-9:where([dir=ltr],[dir=ltr] *){padding-right:2.25rem}.ltr\:hx-text-right:where([dir=ltr],[dir=ltr] *){text-align:right}.ltr\:before\:hx-left-0:where([dir=ltr],[dir=ltr] *)::before{content:var(--tw-content);left:0}@media(min-width:768px){.ltr\:md\:hx-left-auto:where([dir=ltr],[dir=ltr] *){left:auto}}.rtl\:hx-left-1\.5:where([dir=rtl],[dir=rtl] *){left:.375rem}.rtl\:hx-left-3:where([dir=rtl],[dir=rtl] *){left:.75rem}.rtl\:hx--ml-4:where([dir=rtl],[dir=rtl] *){margin-left:-1rem}.rtl\:hx-ml-auto:where([dir=rtl],[dir=rtl] *){margin-left:auto}.rtl\:hx-mr-1:where([dir=rtl],[dir=rtl] *){margin-right:.25rem}.rtl\:hx-mr-3:where([dir=rtl],[dir=rtl] *){margin-right:.75rem}.rtl\:hx-mr-auto:where([dir=rtl],[dir=rtl] *){margin-right:auto}.rtl\:-hx-rotate-180:where([dir=rtl],[dir=rtl] *){--tw-rotate:-180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}.rtl\:hx-border-r:where([dir=rtl],[dir=rtl] *){border-right-width:1px}.rtl\:hx-pl-2:where([dir=rtl],[dir=rtl] *){padding-left:.5rem}.rtl\:hx-pl-4:where([dir=rtl],[dir=rtl] *){padding-left:1rem}.rtl\:hx-pl-9:where([dir=rtl],[dir=rtl] *){padding-left:2.25rem}.rtl\:hx-pr-12:where([dir=rtl],[dir=rtl] *){padding-right:3rem}.rtl\:hx-pr-16:where([dir=rtl],[dir=rtl] *){padding-right:4rem}.rtl\:hx-pr-3:where([dir=rtl],[dir=rtl] *){padding-right:.75rem}.rtl\:hx-pr-4:where([dir=rtl],[dir=rtl] *){padding-right:1rem}.rtl\:hx-pr-5:where([dir=rtl],[dir=rtl] *){padding-right:1.25rem}.rtl\:hx-pr-6:where([dir=rtl],[dir=rtl] *){padding-right:1.5rem}.rtl\:hx-pr-8:where([dir=rtl],[dir=rtl] *){padding-right:2rem}.rtl\:hx-text-left:where([dir=rtl],[dir=rtl] *){text-align:left}.rtl\:before\:hx-right-0:where([dir=rtl],[dir=rtl] *)::before{content:var(--tw-content);right:0}.rtl\:before\:hx-rotate-180:where([dir=rtl],[dir=rtl] *)::before{content:var(--tw-content);--tw-rotate:180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y))rotate(var(--tw-rotate))skewX(var(--tw-skew-x))skewY(var(--tw-skew-y))scaleX(var(--tw-scale-x))scaleY(var(--tw-scale-y))}@media(min-width:768px){.rtl\:md\:hx-right-auto:where([dir=rtl],[dir=rtl] *){right:auto}}@media print{.print\:hx-hidden{display:none}.print\:hx-bg-transparent{background-color:transparent}} \ No newline at end of file diff --git a/css/custom.min.d779624fbc0af7e93dee6a38751bb9429da3f34e195b19542b6b5309ecf3a1e3.css b/css/custom.min.d779624fbc0af7e93dee6a38751bb9429da3f34e195b19542b6b5309ecf3a1e3.css new file mode 100644 index 0000000..e6baeb4 --- /dev/null +++ b/css/custom.min.d779624fbc0af7e93dee6a38751bb9429da3f34e195b19542b6b5309ecf3a1e3.css @@ -0,0 +1 @@ +.hidden{display:none}.hugo-goplay-summary{cursor:pointer}.hugo-goplay-textarea{padding:1rem;width:100%;border-radius:4px;margin:10px 0;background-color:hsl(var(--primary-hue) var(--primary-saturation) calc(var(--primary-lightness) + calc(calc(100% - var(--primary-lightness))/50) * 27)/.1);font-family:monospace}.hugo-goplay-result pre{padding:1rem}.hugo-goplay-result code{background:0 0 !important;border:0 !important}.hugo-goplay-result .system{color:green}.hugo-goplay-result .stderr{color:red}.hugo-goplay-toolbox{display:flex;justify-content:flex-start;margin-bottom:2rem}.hugo-goplay-toolbox .hugo-goplay-button{font-size:13px;font-weight:700;border:1px solid var(--primary);padding:.15rem .75rem;border-radius:4px;margin-left:.5rem;color:var(--primary);background-color:var(--theme)}.hugo-goplay-toolbox .hugo-goplay-button:hover{border:1px solid var(--theme);color:var(--theme);background-color:var(--primary)}.hugo-goplay-toolbox .hugo-goplay-button:first-child{margin-left:0} \ No newline at end of file diff --git a/doc.md b/doc.md deleted file mode 100644 index e08a3ab..0000000 --- a/doc.md +++ /dev/null @@ -1 +0,0 @@ -go doc -all -short form.Form | sed 's/^func \(.*\)$/### \0\n\n\`\`\`golang\n\0\n\`\`\`/g' | sed 's/^ \(.*\)/\n\1/g' | sed 's/^### func .* \(.*\)\((.*)\).*/### \1/' | xclip -sel c diff --git a/docs/constraints/index.html b/docs/constraints/index.html new file mode 100644 index 0000000..80ed5a5 --- /dev/null +++ b/docs/constraints/index.html @@ -0,0 +1,592 @@ + + + + + + + + + + + + +Constraints – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Constraints
+
+ +
+

Constraints

+

The validation is designed to validate data against constraints.

+

Import +

+ +
import (
+	"gitnet.fr/deblan/go-form/validation"
+)
+ +
+
+

Constraints +

Length +

Validate the length of an array, a slice or a string

+
+ +
c := validation.NewLength()
+
+// Define minimum
+c.WithMin(1)
+
+// Define minimum
+c.WithMax(100)
+
+// Define min and max
+// Equivalent to c.WithMin(50).WithMax(50)
+c.WithExact(50)
+ +
+
+

Mail +

+ +
validation.NewMail()
+ +
+
+

Not blank +

+ +
validation.NewNotBlank()
+ +
+
+

Range +

Validate a number

+
+ +
c := validation.NewRange()
+
+// Define minimum
+c.WithMin(1)
+
+// Define minimum
+c.WithMax(100)
+
+// Define min and max
+// Equivalent to c.WithMin(1).WithMax(100)
+c.WithRange(1, 100)
+ +
+
+

Regex +

Validate a string with a regex

+
+ +
c := validation.NewRegex(`expression`)
+
+// The value must match
+c.MustMatch()
+
+// The value must not match
+c.MustNotMatch()
+ +
+
+

Is even +

Validate that a number is even.

+
+ +
validation.NewIsEven()
+ +
+
+

Is odd +

Validate that a number is odd.

+
+ +
validation.NewIsOdd()
+ +
+
+

Custom constraint +

Use case: you want to validate that the data equals “example”

+
+ +
package validation
+
+import (
+	"reflect"
+
+	v "gitnet.fr/deblan/go-form/validation"
+)
+
+// Define a struct
+type IsExample struct {
+	Message          string
+	TypeErrorMessage string
+}
+
+// Create a factory
+func NewIsExample() IsEven {
+	return IsEven{
+		Message:          "This value does not equal \"example\".",
+		TypeErrorMessage: "This value can not be processed.",
+	}
+}
+
+// Implement the validation
+func (c IsExample) Validate(data any) []Error {
+	errors := []Error{}
+
+    // Should not validate blank data
+    if len(v.NewNotBlank().Validate(data)) != 0 {
+		return []Error{}
+	}
+
+	t := reflect.TypeOf(data)
+
+	if t.Kind() == reflect.Ptr {
+		t = t.Elem()
+	}
+
+	switch t.Kind() {
+	case reflect.String:
+		if data.(string) != "example" {
+    		errors = append(errors, Error(c.Message))
+        }
+
+	default:
+		errors = append(errors, Error(c.TypeErrorMessage))
+	}
+
+    return errors
+}
+ +
+
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/constraints/index.xml b/docs/constraints/index.xml new file mode 100644 index 0000000..279659e --- /dev/null +++ b/docs/constraints/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Constraints + https://deblan.gitnet.page/go-form/docs/constraints/ + Recent content in Constraints on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/docs/fields/index.html b/docs/fields/index.html new file mode 100644 index 0000000..96412df --- /dev/null +++ b/docs/fields/index.html @@ -0,0 +1,1462 @@ + + + + + + + + + + + + +Fields – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Fields
+
+ +
+

Fields

+

A field represents a field in a form.

+

Checkbox +

+ +
func NewFieldCheckbox(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=checkbox]

+

Choice +

+ +
func NewFieldChoice(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates inputs (checkbox or radio) or selects

+

Csrf +

+ +
func NewFieldCsrf(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Date +

+ +
func NewFieldDate(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=date] with default transformers

+

Datetime +

+ +
func NewFieldDatetime(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=datetime] with default transformers

+

DatetimeLocal +

+ +
func NewFieldDatetimeLocal(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=datetime-local] with default transformers

+

Hidden +

+ +
func NewFieldHidden(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=hidden]

+

Mail +

+ +
func NewFieldMail(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=email]

+

Number +

+ +
func NewFieldNumber(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=number] with default transformers

+

Password +

+ +
func NewFieldPassword(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=password]

+

Range +

+ +
func NewFieldRange(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=range]

+

Sub Form +

+ +
func NewFieldSubForm(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Alias:

+
+ +
func NewSubForm(name string) *Field
+ +
+
+

Generates a sub form

+

Text +

+ +
func NewFieldText(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=text]

+

Textarea +

+ +
func NewFieldTextarea(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates a textarea

+

Time +

+ +
func NewFieldTime(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=time] with default transformers

+

Submit +

+ +
func NewSubmit(name string) *Field
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Generates an input[type=submit]

+

Methods +

Add +

+ +
func (f *Field) Add(children ...*Field) *Field
+ +
+
+

Appends children

+

Bind +

+ +
func (f *Field) Bind(data map[string]any, key *string) error
+ +
+
+

Bind the data into the given map

+

GetChild +

+ +
func (f *Field) GetChild(name string) *Field
+ +
+
+

Returns a child using its name

+

GetId +

+ +
func (f *Field) GetId() string
+ +
+
+

Computes the id of the field

+

GetName +

+ +
func (f *Field) GetName() string
+ +
+
+

Computes the name of the field

+

GetOption +

+ +
func (f *Field) GetOption(name string) *Option
+ +
+
+

Returns an option using its name

+

HasChild +

+ +
func (f *Field) HasChild(name string) bool
+ +
+
+

Checks if the field contains a child using its name

+

HasOption +

+ +
func (f *Field) HasOption(name string) bool
+ +
+
+

Checks if the field contains an option using its name

+

Mount +

+ +
func (f *Field) Mount(data any) error
+ +
+
+

Populates the field with data

+

ResetErrors +

+ +
func (f *Field) ResetErrors() *Field
+ +
+
+

Resets the field errors

+

WithBeforeBind +

+ +
func (f *Field) WithBeforeBind(callback func(data any) (any, error)) *Field
+ +
+
+

Sets a transformer applied to the data of a field before defining it in a structure

+

WithBeforeMount +

+ +
func (f *Field) WithBeforeMount(callback func(data any) (any, error)) *Field
+ +
+
+

Sets a transformer applied to the structure data before displaying it in a field

+

WithConstraints +

+ +
func (f *Field) WithConstraints(constraints ...validation.Constraint) *Field
+ +
+
+

Appends constraints

+

WithData +

+ +
func (f *Field) WithData(data any) *Field
+ +
+
+

Sets data the field

+

WithFixedName +

+ +
func (f *Field) WithFixedName() *Field
+ +
+
+

Sets that the name of the field is not computed

+

WithOptions +

+ +
func (f *Field) WithOptions(options ...*Option) *Field
+ +
+
+

Common options +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NametypedescriptionInfo
requiredboolAdd required="true"Does not apply a constraint
attrform.AttrsList of extra attributes of the field
row_attrform.AttrsList of extra attributes of the field’s top container
labelstringThe label of the fieldUsually show before the field
label_attrform.AttrsList of extra attributes of the label
helpstringHelper of the field
help_attrform.AttrsList of extra attributes of the help
+

Appends options to the field

+

WithSlice +

+ +
func (f *Field) WithSlice() *Field
+ +
+
+

Sets that the field represents a data slice

+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/fields/index.xml b/docs/fields/index.xml new file mode 100644 index 0000000..e0f00a2 --- /dev/null +++ b/docs/fields/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Fields + https://deblan.gitnet.page/go-form/docs/fields/ + Recent content in Fields on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/docs/form/index.html b/docs/form/index.html new file mode 100644 index 0000000..b658230 --- /dev/null +++ b/docs/form/index.html @@ -0,0 +1,845 @@ + + + + + + + + + + + + +Form – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Form
+
+ +
+

Form

+

Example +

Prerequisites +

+ +
import (
+	"gitnet.fr/deblan/go-form/form"
+	"gitnet.fr/deblan/go-form/validation"
+)
+
+type Person struct {
+    Name string
+    Age  int
+}
+ +
+
+

Creating a form +

+ +
myForm := form.NewForm(
+    form.NewFieldText("Name").
+        WithConstraints(
+            validation.NewNotBlank(),
+        ),
+    form.NewFieldNumber("Age").
+        WithConstraints(
+            validation.NewNotBlank(),
+            validation.NewRange().WithMin(18),
+        ),
+).End()
+ +
+
+

Validating a struct +

+ +
data := Person{}
+
+myForm.Mount(data)
+myForm.IsValid() // false
+
+data = Person{
+    Name: "Alice",
+    Age:  42,
+}
+
+myForm.Mount(data)
+myForm.IsValid() // true
+ +
+
+

Validating a request +

+ +
import (
+    "net/http"
+)
+
+myForm.WithMethod(http.MethodPost)
+
+// req *http.Request
+if req.Method == myForm.Method {
+    myForm.HandleRequest(req)
+
+    if myForm.IsSubmitted() && myForm.IsValid() {
+        myForm.Bind(&data)
+    }
+}
+ +
+
+

Struct +

+ +
type Form struct {
+	Fields       []*Field
+	GlobalFields []*Field
+	Errors       []validation.Error
+	Method       string
+	Action       string
+	Name         string
+	Options      []*Option
+	RequestData  *url.Values
+}
+ +
+
+

Methods +

NewForm +

+ +
func NewForm(fields ...*Field) *Form
+ +
+
+

Generates a new form with default properties

+

Add +

+ +
func (f *Form) Add(fields ...*Field)
+ +
+
+

Appends children

+

AddGlobalField +

+ +
func (f *Form) AddGlobalField(field *Field)
+ +
+
+

Configures its children deeply

+

Bind +

+ +
func (f *Form) Bind(data any) error
+ +
+
+

Copies datas from the form to a struct

+

End +

+ +
func (f *Form) End() *Form
+ +
+
+

Configures its children deeply This function must be called after adding all

+

fields

+

GetField +

+ +
func (f *Form) GetField(name string) *Field
+ +
+
+

Returns a child using its name

+

GetOption +

+ +
func (f *Form) GetOption(name string) *Option
+ +
+
+

Returns an option using its name

+

HandleRequest +

+ +
func (f *Form) HandleRequest(req *http.Request)
+ +
+
+

Processes a request

+

HasField +

+ +
func (f *Form) HasField(name string) bool
+ +
+
+

Checks if the form contains a child using its name

+

HasOption +

+ +
func (f *Form) HasOption(name string) bool
+ +
+
+

Checks if the form contains an option using its name

+

IsSubmitted +

+ +
func (f *Form) IsSubmitted() bool
+ +
+
+

Checks if the form is submitted

+

IsValid +

+ +
func (f *Form) IsValid() bool
+ +
+
+

Checks the a form is valid

+

Mount +

+ +
func (f *Form) Mount(data any) error
+ +
+
+

Copies datas from a struct to the form

+

ResetErrors +

+ +
func (f *Form) ResetErrors() *Form
+ +
+
+

Resets the form errors

+

WithAction +

+ +
func (f *Form) WithAction(v string) *Form
+ +
+
+

Sets the action of the form (eg: “/”)

+

WithMethod +

+ +
func (f *Form) WithMethod(v string) *Form
+ +
+
+

Sets the method of the format (http.MethodPost, http.MethodGet, …)

+

WithName +

+ +
func (f *Form) WithName(v string) *Form
+ +
+
+

Sets the name of the form (used to compute name of fields)

+

WithOptions +

+ +
func (f *Form) WithOptions(options ...*Option) *Form
+ +
+
+

Appends options to the form

+

Options +

+ + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attrmap[string]stringList of extra attributes
helpstringHelper
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/form/index.xml b/docs/form/index.xml new file mode 100644 index 0000000..4e02c53 --- /dev/null +++ b/docs/form/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Form + https://deblan.gitnet.page/go-form/docs/form/ + Recent content in Form on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..cf2c7f4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,340 @@ + + + + + + + + + + + + +Introduction – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
Documentation
+
+ +
+

Introduction

+

Creating and processing HTML forms is hard and repetitive. You need to deal with rendering HTML form fields, validating submitted data, mapping the form data into objects and a lot more. go-form includes a powerful form feature that provides all these features.

+

go-form is heavily influenced by Symfony Form. It includes:

+
    +
  • A form builder based on fields declarations and independent of structs
  • +
  • Validation based on constraints
  • +
  • Data mounting to populate a form from a struct instance
  • +
  • Data binding to populate a struct instance from a submitted form
  • +
  • Form renderer with customizable themes
  • +
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/index.xml b/docs/index.xml new file mode 100644 index 0000000..cfdff96 --- /dev/null +++ b/docs/index.xml @@ -0,0 +1,62 @@ + + + deblan/go-form – Introduction + https://deblan.gitnet.page/go-form/docs/ + Recent content in Introduction on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + Installation + https://deblan.gitnet.page/go-form/docs/installation/ + Mon, 01 Jan 0001 00:00:00 +0000 + + https://deblan.gitnet.page/go-form/docs/installation/ + + + + <div class="hextra-code-block hx-relative hx-mt-6 first:hx-mt-0 hx-group/code"> + +<div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-golang" data-lang="golang"><span class="line"><span class="cl"><span class="k">go</span> <span class="nx">get</span> <span class="nx">gitnet</span><span class="p">.</span><span class="nx">fr</span><span class="o">/</span><span class="nx">deblan</span><span class="o">/</span><span class="k">go</span><span class="o">-</span><span class="nx">form</span></span></span></code></pre></div></div><div class="hextra-code-copy-btn-container hx-opacity-0 hx-transition group-hover/code:hx-opacity-100 hx-flex hx-gap-1 hx-absolute hx-m-[11px] hx-right-0 hx-top-0"> + <button + class="hextra-code-copy-btn hx-group/copybtn hx-transition-all active:hx-opacity-50 hx-bg-primary-700/5 hx-border hx-border-black/5 hx-text-gray-600 hover:hx-text-gray-900 hx-rounded-md hx-p-1.5 dark:hx-bg-primary-300/10 dark:hx-border-white/10 dark:hx-text-gray-400 dark:hover:hx-text-gray-50" + title="Copy code" + > + <div class="copy-icon group-[.copied]/copybtn:hx-hidden hx-pointer-events-none hx-h-4 hx-w-4"></div> + <div class="success-icon hx-hidden group-[.copied]/copybtn:hx-block hx-pointer-events-none hx-h-4 hx-w-4"></div> + </button> +</div> +</div> + + + + + + Theming + https://deblan.gitnet.page/go-form/docs/rendering/theming/ + Mon, 01 Jan 0001 00:00:00 +0000 + + https://deblan.gitnet.page/go-form/docs/rendering/theming/ + + + + <p><strong>go-form</strong> provides 2 themes:</p> +<ul> +<li><code>theme.Html5</code>: a basic view without classes</li> +<li><code>theme.Bootstrap5</code>: a theme for <a href="https://getbootstrap.com/" target="_blank" rel="noopener">Bootstrap 5</a></li> +</ul> +<p>You can add a custom theme. Learn by reading the <a href="https://gitnet.fr/deblan/go-form/src/branch/main/theme/bootstrap5.go" target="_blank" rel="noopener">Bootstrap5</a> theme.</p> + + + + + + diff --git a/docs/installation/index.html b/docs/installation/index.html new file mode 100644 index 0000000..5a6122f --- /dev/null +++ b/docs/installation/index.html @@ -0,0 +1,350 @@ + + + + + + + + + + + + +Installation – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Installation
+
+ +
+

Installation

+
+ +
go get gitnet.fr/deblan/go-form
+ +
+
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/rendering/index.html b/docs/rendering/index.html new file mode 100644 index 0000000..0649020 --- /dev/null +++ b/docs/rendering/index.html @@ -0,0 +1,422 @@ + + + + + + + + + + + + +Rendering – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Rendering
+
+ +
+

Rendering

+

go-form allows you to render a form using Go’s built-in template engine. +Here is a simple example that displays a form:

+
+ +
myForm := form.NewForm(...)
+
+render := theme.NewRenderer(theme.Bootstrap5)
+
+tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(`
+    <html>
+        <head>
+            <title>My form</title>
+        </head>
+        <body>
+            {{ form .Form }}
+        </body>
+    </html>
+`)
+
+b := new(strings.Builder)
+
+tpl.Execute(w, map[string]any{
+    "Form": myForm,
+})
+
+fmt.Println(b.String())
+ +
+
+ +
+ Test me + +
+
+ + + +
+
+ +

Other helper functions are available to render specific parts of the form:

+
    +
  • form_errors: displays the form’s global errors
  • +
  • form_row : renders the label, errors, and widget of a field
  • +
  • form_label: renders only the label of a field
  • +
  • form_widget: renders only the widget of a field
  • +
  • form_widget_errors: renders only the errors of a specific field
  • +
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/rendering/index.xml b/docs/rendering/index.xml new file mode 100644 index 0000000..1a42779 --- /dev/null +++ b/docs/rendering/index.xml @@ -0,0 +1,37 @@ + + + deblan/go-form – Rendering + https://deblan.gitnet.page/go-form/docs/rendering/ + Recent content in Rendering on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + Theming + https://deblan.gitnet.page/go-form/docs/rendering/theming/ + Mon, 01 Jan 0001 00:00:00 +0000 + + https://deblan.gitnet.page/go-form/docs/rendering/theming/ + + + + <p><strong>go-form</strong> provides 2 themes:</p> +<ul> +<li><code>theme.Html5</code>: a basic view without classes</li> +<li><code>theme.Bootstrap5</code>: a theme for <a href="https://getbootstrap.com/" target="_blank" rel="noopener">Bootstrap 5</a></li> +</ul> +<p>You can add a custom theme. Learn by reading the <a href="https://gitnet.fr/deblan/go-form/src/branch/main/theme/bootstrap5.go" target="_blank" rel="noopener">Bootstrap5</a> theme.</p> + + + + + + diff --git a/docs/rendering/theming/index.html b/docs/rendering/theming/index.html new file mode 100644 index 0000000..14af2e6 --- /dev/null +++ b/docs/rendering/theming/index.html @@ -0,0 +1,347 @@ + + + + + + + + + + + + +Theming – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+ +
+ Rendering +
Theming
+
+ +
+

Theming

+

go-form provides 2 themes:

+
    +
  • theme.Html5: a basic view without classes
  • +
  • theme.Bootstrap5: a theme for Bootstrap 5
  • +
+

You can add a custom theme. Learn by reading the Bootstrap5 theme.

+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/workflow/index.html b/docs/workflow/index.html new file mode 100644 index 0000000..ead0a36 --- /dev/null +++ b/docs/workflow/index.html @@ -0,0 +1,512 @@ + + + + + + + + + + + + +Workflow – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
Workflow
+
+ +
+

Workflow

+
+

Import +

+ +
import (
+    "html/template"
+	"net/http"
+
+    "gitnet.fr/deblan/go-form/form"
+    "gitnet.fr/deblan/go-form/theme"
+)
+ +
+
+

Create a form +

+ +
// Let's create a new form
+// You can pass *form.Field as arguments
+myForm := form.NewForm(field1, field2, ...)
+
+// Add somes fields
+myForm.Add(field3, field4, ...)
+
+// Set the method
+// <form method="POST" ...>
+myForm.WithMethod(http.MethodPost)
+
+// Define the action
+// <form action="/" ...>
+myForm.WithAction("/")
+
+// Set a name
+myForm.WithName("myForm")
+
+// Add options
+myForm.WithOptions(option1, option2, ...)
+
+// When all fields are added, call End()
+myForm.End()
+ +
+
+

Attributes +

Some options are natively supported in go-form themes.

+
+ +
myForm.WithOptions(
+    form.NewOption("help", "A help for the form"),
+    // <form data-foo="bar" data-bar="bar" ...
+    form.NewOption("attr", form.Attrs{
+        "data-foo": "foo",
+        "data-bar": "bar",
+    }),
+)
+ +
+
+

Data mounting +

This step is not required when you does not want to pre-fill the form. +Your struct can be complexe and the form only map existing properties.

+
+ +
type Person struct {
+    Name string
+    Age  int
+}
+
+data := Person{
+    Name: "Alice",
+    Age:  42,
+}
+
+// Assuming 2 fields named "Name" and "Age" exist
+myForm.Mount(data)
+ +
+
+

Rendering +

+ +
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+    // myForm := form.NewForm(...)
+
+    render := theme.NewRenderer(theme.Html5)
+    tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(`{{ form .Form }}`)
+
+    w.Header().Set("Content-Type", "text/html; charset=utf-8")
+
+    tpl.Execute(w, map[string]any{
+        "Form": myForm,
+    })
+}
+ +
+
+

Data binding +

This is the final step. After the form handles the request, you can check if the form has been submitted, check the values are valid and finally populate your struct.

+
+ +
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+    // data := Person{...}
+    // myForm := form.NewForm(...)
+
+    if r.Method == myForm.Method {
+        myForm.HandleRequest(r)
+
+        if myForm.IsSubmitted() && myForm.IsValid() {
+            myForm.Bind(&data)
+        }
+    }
+})
+ +
+
+
+ +
+
+ + +
+
+
+ +
+ + + + + + diff --git a/docs/workflow/index.xml b/docs/workflow/index.xml new file mode 100644 index 0000000..617c026 --- /dev/null +++ b/docs/workflow/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Workflow + https://deblan.gitnet.page/go-form/docs/workflow/ + Recent content in Workflow on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/en.search-data.json b/en.search-data.json new file mode 100644 index 0000000..e62a58b --- /dev/null +++ b/en.search-data.json @@ -0,0 +1 @@ +{"/go-form/docs/":{"data":{"":"Creating and processing HTML forms is hard and repetitive. You need to deal with rendering HTML form fields, validating submitted data, mapping the form data into objects and a lot more. go-form includes a powerful form feature that provides all these features.\ngo-form is heavily influenced by Symfony Form. It includes:\nA form builder based on fields declarations and independent of structs Validation based on constraints Data mounting to populate a form from a struct instance Data binding to populate a struct instance from a submitted form Form renderer with customizable themes "},"title":"Documentation"},"/go-form/docs/constraints/":{"data":{"":"The validation is designed to validate data against constraints.","constraints#Constraints":"Length Validate the length of an array, a slice or a string\nc := validation.NewLength() // Define minimum c.WithMin(1) // Define minimum c.WithMax(100) // Define min and max // Equivalent to c.WithMin(50).WithMax(50) c.WithExact(50) Mail validation.NewMail() Not blank validation.NewNotBlank() Range Validate a number\nc := validation.NewRange() // Define minimum c.WithMin(1) // Define minimum c.WithMax(100) // Define min and max // Equivalent to c.WithMin(1).WithMax(100) c.WithRange(1, 100) Regex Validate a string with a regex\nc := validation.NewRegex(`expression`) // The value must match c.MustMatch() // The value must not match c.MustNotMatch() Is even Validate that a number is even.\nvalidation.NewIsEven() Is odd Validate that a number is odd.\nvalidation.NewIsOdd() ","custom-constraint#Custom constraint":"Use case: you want to validate that the data equals “example”\npackage validation import ( \"reflect\" v \"gitnet.fr/deblan/go-form/validation\" ) // Define a struct type IsExample struct { Message string TypeErrorMessage string } // Create a factory func NewIsExample() IsEven { return IsEven{ Message: \"This value does not equal \\\"example\\\".\", TypeErrorMessage: \"This value can not be processed.\", } } // Implement the validation func (c IsExample) Validate(data any) []Error { errors := []Error{} // Should not validate blank data if len(v.NewNotBlank().Validate(data)) != 0 { return []Error{} } t := reflect.TypeOf(data) if t.Kind() == reflect.Ptr { t = t.Elem() } switch t.Kind() { case reflect.String: if data.(string) != \"example\" { errors = append(errors, Error(c.Message)) } default: errors = append(errors, Error(c.TypeErrorMessage)) } return errors } ","import#Import":" import ( \"gitnet.fr/deblan/go-form/validation\" ) "},"title":"Constraints"},"/go-form/docs/fields/":{"data":{"":"","#":"A field represents a field in a form.\nCheckbox func NewFieldCheckbox(name string) *Field field := form.NewFieldCheckbox(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=checkbox]\nChoice func NewFieldChoice(name string) *Field field := form.NewFieldChoice(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates inputs (checkbox or radio) or selects\nCsrf func NewFieldCsrf(name string) *Field field := form.NewFieldCsrf(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Date func NewFieldDate(name string) *Field field := form.NewFieldDate(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=date] with default transformers\nDatetime func NewFieldDatetime(name string) *Field field := form.NewFieldDatetime(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=datetime] with default transformers\nDatetimeLocal func NewFieldDatetimeLocal(name string) *Field field := form.NewFieldDatetimeLocal(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=datetime-local] with default transformers\nHidden func NewFieldHidden(name string) *Field field := form.NewFieldHidden(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=hidden]\nMail func NewFieldMail(name string) *Field field := form.NewFieldMail(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=email]\nNumber func NewFieldNumber(name string) *Field field := form.NewFieldNumber(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=number] with default transformers\nPassword func NewFieldPassword(name string) *Field field := form.NewFieldPassword(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=password]\nRange func NewFieldRange(name string) *Field field := form.NewFieldRange(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=range]\nSub Form func NewFieldSubForm(name string) *Field field := form.NewFieldSubForm(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Alias:\nfunc NewSubForm(name string) *Field Generates a sub form\nText func NewFieldText(name string) *Field field := form.NewFieldText(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=text]\nTextarea func NewFieldTextarea(name string) *Field field := form.NewFieldTextarea(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates a textarea\nTime func NewFieldTime(name string) *Field field := form.NewFieldTime(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=time] with default transformers\nSubmit func NewSubmit(name string) *Field field := form.NewSubmit(\"Foo\") Test me Run Try it yourself ↗ Share ↗ Generates an input[type=submit]","methods#Methods":"Add func (f *Field) Add(children ...*Field) *Field Appends children\nBind func (f *Field) Bind(data map[string]any, key *string) error Bind the data into the given map\nGetChild func (f *Field) GetChild(name string) *Field Returns a child using its name\nGetId func (f *Field) GetId() string Computes the id of the field\nGetName func (f *Field) GetName() string Computes the name of the field\nGetOption func (f *Field) GetOption(name string) *Option Returns an option using its name\nHasChild func (f *Field) HasChild(name string) bool Checks if the field contains a child using its name\nHasOption func (f *Field) HasOption(name string) bool Checks if the field contains an option using its name\nMount func (f *Field) Mount(data any) error Populates the field with data\nResetErrors func (f *Field) ResetErrors() *Field Resets the field errors\nWithBeforeBind func (f *Field) WithBeforeBind(callback func(data any) (any, error)) *Field Sets a transformer applied to the data of a field before defining it in a structure\nWithBeforeMount func (f *Field) WithBeforeMount(callback func(data any) (any, error)) *Field Sets a transformer applied to the structure data before displaying it in a field\nWithConstraints func (f *Field) WithConstraints(constraints ...validation.Constraint) *Field Appends constraints\nWithData func (f *Field) WithData(data any) *Field Sets data the field\nWithFixedName func (f *Field) WithFixedName() *Field Sets that the name of the field is not computed\nWithOptions func (f *Field) WithOptions(options ...*Option) *Field Common options Name type description Info required bool Add required=\"true\" Does not apply a constraint attr form.Attrs List of extra attributes of the field row_attr form.Attrs List of extra attributes of the field’s top container label string The label of the field Usually show before the field label_attr form.Attrs List of extra attributes of the label help string Helper of the field help_attr form.Attrs List of extra attributes of the help Appends options to the field\nWithSlice func (f *Field) WithSlice() *Field Sets that the field represents a data slice"},"title":"Fields"},"/go-form/docs/form/":{"data":{"":"","example#Example":"Prerequisites import ( \"gitnet.fr/deblan/go-form/form\" \"gitnet.fr/deblan/go-form/validation\" ) type Person struct { Name string Age int } Creating a form myForm := form.NewForm( form.NewFieldText(\"Name\"). WithConstraints( validation.NewNotBlank(), ), form.NewFieldNumber(\"Age\"). WithConstraints( validation.NewNotBlank(), validation.NewRange().WithMin(18), ), ).End() Validating a struct data := Person{} myForm.Mount(data) myForm.IsValid() // false data = Person{ Name: \"Alice\", Age: 42, } myForm.Mount(data) myForm.IsValid() // true Validating a request import ( \"net/http\" ) myForm.WithMethod(http.MethodPost) // req *http.Request if req.Method == myForm.Method { myForm.HandleRequest(req) if myForm.IsSubmitted() \u0026\u0026 myForm.IsValid() { myForm.Bind(\u0026data) } } ","methods#Methods":"NewForm func NewForm(fields ...*Field) *Form Generates a new form with default properties\nAdd func (f *Form) Add(fields ...*Field) Appends children\nAddGlobalField func (f *Form) AddGlobalField(field *Field) Configures its children deeply\nBind func (f *Form) Bind(data any) error Copies datas from the form to a struct\nEnd func (f *Form) End() *Form Configures its children deeply This function must be called after adding all\nfields\nGetField func (f *Form) GetField(name string) *Field Returns a child using its name\nGetOption func (f *Form) GetOption(name string) *Option Returns an option using its name\nHandleRequest func (f *Form) HandleRequest(req *http.Request) Processes a request\nHasField func (f *Form) HasField(name string) bool Checks if the form contains a child using its name\nHasOption func (f *Form) HasOption(name string) bool Checks if the form contains an option using its name\nIsSubmitted func (f *Form) IsSubmitted() bool Checks if the form is submitted\nIsValid func (f *Form) IsValid() bool Checks the a form is valid\nMount func (f *Form) Mount(data any) error Copies datas from a struct to the form\nResetErrors func (f *Form) ResetErrors() *Form Resets the form errors\nWithAction func (f *Form) WithAction(v string) *Form Sets the action of the form (eg: “/”)\nWithMethod func (f *Form) WithMethod(v string) *Form Sets the method of the format (http.MethodPost, http.MethodGet, …)\nWithName func (f *Form) WithName(v string) *Form Sets the name of the form (used to compute name of fields)\nWithOptions func (f *Form) WithOptions(options ...*Option) *Form Appends options to the form\nOptions Name Type Description attr map[string]string List of extra attributes help string Helper ","struct#Struct":" type Form struct { Fields []*Field GlobalFields []*Field Errors []validation.Error Method string Action string Name string Options []*Option RequestData *url.Values } "},"title":"Form"},"/go-form/docs/installation/":{"data":{"":" go get gitnet.fr/deblan/go-form "},"title":"Installation"},"/go-form/docs/rendering/":{"data":{"":"go-form allows you to render a form using Go’s built-in template engine. Here is a simple example that displays a form:\nmyForm := form.NewForm(...) render := theme.NewRenderer(theme.Bootstrap5) tpl, _ := template.New(\"page\").Funcs(render.FuncMap()).Parse(` \u003chtml\u003e \u003chead\u003e \u003ctitle\u003eMy form\u003c/title\u003e \u003c/head\u003e \u003cbody\u003e {{ form .Form }} \u003c/body\u003e \u003c/html\u003e `) b := new(strings.Builder) tpl.Execute(w, map[string]any{ \"Form\": myForm, }) fmt.Println(b.String()) @import \"fmt\" @import \"html/template\" @import \"strings\" @import @import \"github.com/yosssi/gohtml\" @import \"gitnet.fr/deblan/go-form/example\" @import \"gitnet.fr/deblan/go-form/theme\" form := example.CreateDataForm() render := theme.NewRenderer(theme.Html5) // render := theme.NewRenderer(theme.Bootstrap5) tpl, _ := template.New(\"page\").Funcs(render.FuncMap()).Parse(`{{ form .Form }}`) buff := new(strings.Builder) tpl.Execute(buff, map[string]any{ \"Form\": form, }) fmt.Println(gohtml.Format(buff.String())) Test me Run Try it yourself ↗ Share ↗ Other helper functions are available to render specific parts of the form:\nform_errors: displays the form’s global errors form_row : renders the label, errors, and widget of a field form_label: renders only the label of a field form_widget: renders only the widget of a field form_widget_errors: renders only the errors of a specific field "},"title":"Rendering"},"/go-form/docs/rendering/theming/":{"data":{"":"go-form provides 2 themes:\ntheme.Html5: a basic view without classes theme.Bootstrap5: a theme for Bootstrap 5 You can add a custom theme. Learn by reading the Bootstrap5 theme."},"title":"Theming"},"/go-form/docs/workflow/":{"data":{"":"","#":" Import import ( \"html/template\" \"net/http\" \"gitnet.fr/deblan/go-form/form\" \"gitnet.fr/deblan/go-form/theme\" ) Create a form // Let's create a new form // You can pass *form.Field as arguments myForm := form.NewForm(field1, field2, ...) // Add somes fields myForm.Add(field3, field4, ...) // Set the method // \u003cform method=\"POST\" ...\u003e myForm.WithMethod(http.MethodPost) // Define the action // \u003cform action=\"/\" ...\u003e myForm.WithAction(\"/\") // Set a name myForm.WithName(\"myForm\") // Add options myForm.WithOptions(option1, option2, ...) // When all fields are added, call End() myForm.End() Attributes Some options are natively supported in go-form themes.\nmyForm.WithOptions( form.NewOption(\"help\", \"A help for the form\"), // \u003cform data-foo=\"bar\" data-bar=\"bar\" ... form.NewOption(\"attr\", form.Attrs{ \"data-foo\": \"foo\", \"data-bar\": \"bar\", }), ) Data mounting This step is not required when you does not want to pre-fill the form. Your struct can be complexe and the form only map existing properties.\ntype Person struct { Name string Age int } data := Person{ Name: \"Alice\", Age: 42, } // Assuming 2 fields named \"Name\" and \"Age\" exist myForm.Mount(data) Rendering http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) { // myForm := form.NewForm(...) render := theme.NewRenderer(theme.Html5) tpl, _ := template.New(\"page\").Funcs(render.FuncMap()).Parse(`{{ form .Form }}`) w.Header().Set(\"Content-Type\", \"text/html; charset=utf-8\") tpl.Execute(w, map[string]any{ \"Form\": myForm, }) } Data binding This is the final step. After the form handles the request, you can check if the form has been submitted, check the values are valid and finally populate your struct.\nhttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) { // data := Person{...} // myForm := form.NewForm(...) if r.Method == myForm.Method { myForm.HandleRequest(r) if myForm.IsSubmitted() \u0026\u0026 myForm.IsValid() { myForm.Bind(\u0026data) } } }) "},"title":"Workflow"}} \ No newline at end of file diff --git a/en.search.min.fe55059febf424bd0ddfb7f9af8f25d872bed2eae488d8626311a4dcf87bff9b.js b/en.search.min.fe55059febf424bd0ddfb7f9af8f25d872bed2eae488d8626311a4dcf87bff9b.js new file mode 100644 index 0000000..8f89402 --- /dev/null +++ b/en.search.min.fe55059febf424bd0ddfb7f9af8f25d872bed2eae488d8626311a4dcf87bff9b.js @@ -0,0 +1,8 @@ +document.addEventListener("DOMContentLoaded",function(){if(/iPad|iPhone|Macintosh/.test(navigator.userAgent)){const e=document.querySelectorAll(".search-wrapper kbd");e.forEach(e=>{e.innerHTML='K'})}}),function(){const h="/go-form/en.search-data.json",u=document.querySelectorAll(".search-input");for(const e of u)e.addEventListener("focus",o),e.addEventListener("keyup",p),e.addEventListener("keydown",n),e.addEventListener("input",m);const d=document.querySelectorAll(".search-wrapper kbd");function a(e){d.forEach(t=>{t.style.opacity=e})}function m(e){const t=e.target.value.length>0?0:100;a(t)}function e(){const e=Array.from(document.querySelectorAll(".search-wrapper")).filter(e=>e.clientHeight>0);return e.length===1?{wrapper:e[0],inputElement:e[0].querySelector(".search-input"),resultsElement:e[0].querySelector(".search-results")}:0[0]}const l=["input","select","button","textarea"];document.addEventListener("keydown",function(t){const{inputElement:n}=e();if(!n)return;const s=document.activeElement,o=s&&s.tagName;if(n===s||!o||l.includes(o)||s&&s.isContentEditable)return;t.key==="/"||t.key==="k"&&(t.metaKey||t.ctrlKey)?(t.preventDefault(),n.focus()):t.key==="Escape"&&n.value&&n.blur()}),document.addEventListener("mousedown",function(n){const{inputElement:o,resultsElement:s}=e();if(!o||!s)return;n.target!==o&&n.target!==s&&!s.contains(n.target)&&(a(100),t())});function r(){const{resultsElement:n}=e();if(!n)return{result:0[0],index:-1};const t=n.querySelector(".active");if(!t)return{result:0[0],index:-1};const s=parseInt(t.dataset.index,10);return{result:t,index:s}}function s(t){const{resultsElement:s}=e();if(!s)return;const{result:o}=r();o&&o.classList.remove("active");const n=s.querySelector(`[data-index="${t}"]`);n&&(n.classList.add("active"),n.focus())}function c(){const{resultsElement:t}=e();return t?t.dataset.count:0}function i(){const{inputElement:n}=e();if(!n)return;t(),n.value="",n.blur()}function t(){const{resultsElement:t}=e();if(!t)return;t.classList.add("hx-hidden")}function n(n){const{inputElement:o}=e();if(!o)return;const d=c(),{result:l,index:a}=r();switch(n.key){case"ArrowUp":n.preventDefault(),a>0&&s(a-1);break;case"ArrowDown":n.preventDefault(),a+1{const e=document.documentElement.lang||"en";return e.startsWith("zh")||e.startsWith("ja")||e.startsWith("ko")},i=e=>e.replace(/[\x00-\x7F]/g,"").split(""),a=e=>(""+e).toLocaleLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u),s=o()?i:a;window.pageIndex=new FlexSearch.Document({tokenize:n,encode:s,cache:100,document:{id:"id",store:["title","crumb"],index:"content"}}),window.sectionIndex=new FlexSearch.Document({tokenize:n,encode:s,cache:100,document:{id:"id",store:["title","content","url","display","crumb"],index:"content",tag:"pageId"}});const r=await fetch(h),e=await r.json();let t=0;for(const n in e){let a="";++t;const i=n.split("/").filter(e=>e!=""&&!e.startsWith("#"));let s="",o="/";for(let t=0;te).join(" ")),s+=a,t ")}for(const c in e[n].data){const[l,u]=c.split("#"),o=n.trimEnd("/")+(l?"#"+l:""),i=u||e[n].title,d=e[n].data[c]||"",r=d.split(` +`).filter(Boolean);sectionIndex.add({id:o,url:o,title:i,crumb:s,pageId:`page_${t}`,content:i,...r[0]&&{display:r[0]}});for(let e=0;ee._page_rk===t._page_rk?e._section_rk-t._section_rk:s[e._page_rk]!==s[t._page_rk]?s[t._page_rk]-s[e._page_rk]:e._page_rk-t._page_rk).map(e=>({id:`${e._page_rk}_${e._section_rk}`,route:e.route,prefix:e.prefix,children:e.children}));g(c,i)}function g(t,s){const{resultsElement:o}=e();if(!o)return;if(!t.length){o.innerHTML=`No results found.`;return}function r(e,t){const n=t.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&"),s=new RegExp(n,"gi");return e.replace(s,e=>`${e}`)}function c(e){const t=document.createElement("div");return t.innerHTML=e.trim(),t.firstChild}function l(e){const t=e.target.closest("a");if(t){const e=o.querySelector("a.active");e&&e.classList.remove("active"),t.classList.add("active")}}const a=document.createDocumentFragment();for(let o=0;o${e.prefix}`));let d=c(` +
  • + +
    `+r(e.children.title,s)+`
    `+(e.children.content?`
    `+r(e.children.content,s)+`
    `:"")+` +
    +
  • `);d.addEventListener("mousemove",l),d.addEventListener("keydown",n),d.querySelector("a").addEventListener("click",i),a.appendChild(d)}o.appendChild(a),o.dataset.count=t.length}}() \ No newline at end of file diff --git a/example.go b/example.go deleted file mode 100644 index 91918d4..0000000 --- a/example.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import ( - "embed" - "encoding/json" - "html/template" - "log" - "net/http" - - "github.com/yassinebenaid/godump" - "gitnet.fr/deblan/go-form/example" - "gitnet.fr/deblan/go-form/theme" -) - -//go:embed example/view/*.html -var templates embed.FS - -func handler(view, action string, formRenderer *theme.Renderer, w http.ResponseWriter, r *http.Request) { - entity := example.ExampleData{} - entityForm := example.CreateDataForm(action) - entityForm.Mount(entity) - - style := example.NewTheme(action) - styleForm := example.CreateThemeSelectorForm() - styleForm.Mount(style) - - if r.Method == entityForm.Method { - entityForm.HandleRequest(r) - - if entityForm.IsSubmitted() && entityForm.IsValid() { - entityForm.Bind(&entity) - } - } - - content, _ := templates.ReadFile(view) - - formAsJson, _ := json.MarshalIndent(entityForm, " ", " ") - - tpl, _ := template.New("page"). - Funcs(formRenderer.FuncMap()). - Parse(string(content)) - - w.Header().Set("Content-Type", "text/html; charset=utf-8") - - var dump godump.Dumper - dump.Theme = godump.Theme{} - - tpl.Execute(w, map[string]any{ - "isSubmitted": entityForm.IsSubmitted(), - "isValid": entityForm.IsValid(), - "form": entityForm, - "styleForm": styleForm, - "json": string(formAsJson), - "dump": template.HTML(dump.Sprint(entity)), - }) -} - -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - handler( - "example/view/html5.html", - "/", - theme.NewRenderer(theme.Html5), - w, - r, - ) - }) - - http.HandleFunc("/bootstrap", func(w http.ResponseWriter, r *http.Request) { - handler( - "example/view/bootstrap.html", - "/bootstrap", - theme.NewRenderer(theme.Bootstrap5), - w, - r, - ) - }) - - log.Println("Browse: http://localhost:1122") - log.Fatal(http.ListenAndServe(":1122", nil)) -} diff --git a/example/form.go b/example/form.go deleted file mode 100644 index fc6e8bf..0000000 --- a/example/form.go +++ /dev/null @@ -1,251 +0,0 @@ -package example - -import ( - "net/http" - "time" - - "github.com/spf13/cast" - "gitnet.fr/deblan/go-form/form" - "gitnet.fr/deblan/go-form/validation" -) - -type Item struct { - Id uint - Name string -} - -type ExampleOtherInputs struct { - Number float32 - Range uint - Mail string - Password string -} - -type ExampleChoices struct { - Select *Item - SelectExpanded *Item - MultipleSelect []Item - MultipleSelectExpanded []Item -} - -type ExampleDates struct { - Date *time.Time - DateTime *time.Time - DateTimeLocal *time.Time - Time *time.Time -} - -type ExampleData struct { - Collection []CollectionItem - Bytes []byte - Text string - Checkbox bool - Dates ExampleDates - Choices ExampleChoices - Inputs ExampleOtherInputs -} - -type CollectionItem struct { - ValueA string - ValueB string -} - -type Theme struct { - Value string `field:"lowerCamel"` -} - -func CreateDataForm(action string) *form.Form { - items := []Item{ - Item{Id: 1, Name: "Item 1"}, - Item{Id: 2, Name: "Item 2"}, - Item{Id: 3, Name: "Item 3"}, - } - - itemsChoices := form.NewChoices(items). - WithValueBuilder(func(key int, item any) string { - return cast.ToString(item.(Item).Id) - }). - WithLabelBuilder(func(key int, item any) string { - return item.(Item).Name - }) - - return form.NewForm( - form.NewFieldText("Bytes"). - WithOptions( - form.NewOption("label", "Bytes"), - form.NewOption("required", true), - ). - WithBeforeMount(func(data any) (any, error) { - return cast.ToString(data), nil - }). - WithBeforeBind(func(data any) (any, error) { - return []byte(cast.ToString(data)), nil - }). - WithConstraints( - validation.NewNotBlank(), - ), - form.NewFieldTextarea("Text"). - WithOptions( - form.NewOption("label", "Text"), - form.NewOption("help", "Must contain 'deblan'"), - ). - WithConstraints( - validation.NewRegex(`deblan`), - ), - form.NewFieldCheckbox("Checkbox"). - WithOptions( - form.NewOption("label", "Checkbox"), - ), - form.NewSubForm("Inputs"). - WithOptions( - form.NewOption("label", "Inputs"), - ). - Add( - form.NewFieldNumber("Number"). - WithOptions( - form.NewOption("label", "Number"), - ). - WithConstraints( - validation.NewRange().WithRange(1, 20), - validation.NewIsEven(), - ), - form.NewFieldRange("Range"). - WithOptions( - form.NewOption("label", "Range"), - ), - form.NewFieldMail("Mail"). - WithOptions( - form.NewOption("label", "Mail"), - ). - WithConstraints( - validation.Mail{}, - ), - form.NewFieldPassword("Password"). - WithOptions( - form.NewOption("label", "Password"), - ). - WithConstraints( - validation.NewLength().WithMin(10), - ), - ), - form.NewSubForm("Dates"). - WithOptions( - form.NewOption("label", "Dates"), - ). - Add( - form.NewFieldDate("Date"). - WithOptions( - form.NewOption("label", "Date"), - ), - form.NewFieldDatetime("DateTime"). - WithOptions( - form.NewOption("label", "Datetime"), - ), - form.NewFieldDatetimeLocal("DateTimeLocal"). - WithOptions( - form.NewOption("label", "DateTime local"), - ), - form.NewFieldTime("Time"). - WithOptions( - form.NewOption("label", "Time"), - ), - ), - form.NewSubForm("Choices"). - WithOptions(form.NewOption("label", "Choices")). - Add( - form.NewFieldChoice("Select"). - WithOptions( - form.NewOption("choices", itemsChoices), - form.NewOption("label", "Select"), - ). - WithConstraints( - validation.NewNotBlank(), - ), - form.NewFieldChoice("SelectExpanded"). - WithOptions( - form.NewOption("choices", itemsChoices), - form.NewOption("label", "Select (expanded)"), - form.NewOption("expanded", true), - ), - form.NewFieldChoice("MultipleSelect"). - WithSlice(). - WithOptions( - form.NewOption("choices", itemsChoices), - form.NewOption("label", "Multiple select"), - form.NewOption("multiple", true), - ). - WithConstraints( - validation.NewNotBlank(), - validation.NewLength().WithExact(2), - ), - form.NewFieldChoice("MultipleSelectExpanded"). - WithSlice(). - WithOptions( - form.NewOption("choices", itemsChoices), - form.NewOption("label", "Multiple select (expanded)"), - form.NewOption("expanded", true), - form.NewOption("multiple", true), - ), - ), - form.NewFieldCollection("Collection"). - WithOptions( - form.NewOption("label", "Collection"), - form.NewOption("form", form.NewForm( - form.NewFieldText("ValueA"). - WithOptions(form.NewOption("label", "Value A")). - WithConstraints( - validation.NewNotBlank(), - ), - form.NewFieldText("ValueB"). - WithOptions(form.NewOption("label", "Value B")), - )), - ), - form.NewFieldCsrf("_csrf_token").WithData("my-token"), - form.NewSubmit("submit"). - WithOptions( - form.NewOption("attr", form.Attrs{ - "class": "btn btn-primary", - }), - ), - ). - End(). - WithOptions( - form.NewOption("help", "Form global help"), - ). - WithMethod(http.MethodPost). - WithAction(action) -} - -func NewTheme(value string) *Theme { - return &Theme{Value: value} -} - -func CreateThemeSelectorForm() *form.Form { - choices := form.NewChoices([]map[string]string{ - map[string]string{"value": "/", "label": "Html5"}, - map[string]string{"value": "/bootstrap", "label": "Bootstrap5"}, - }) - - choices.LabelBuilder = func(key int, item any) string { - return item.(map[string]string)["label"] - } - - choices.ValueBuilder = func(key int, item any) string { - return item.(map[string]string)["value"] - } - - return form.NewForm( - form.NewFieldChoice("value"). - WithOptions( - form.NewOption("choices", choices), - form.NewOption("label", "Select a theme"), - form.NewOption("required", true), - form.NewOption("attr", form.Attrs{ - "onchange": "document.location.href = this.value", - }), - ), - ). - End(). - WithName(""). - WithMethod(http.MethodGet) -} diff --git a/example/view/bootstrap.html b/example/view/bootstrap.html deleted file mode 100644 index 23543fd..0000000 --- a/example/view/bootstrap.html +++ /dev/null @@ -1,119 +0,0 @@ - - - - - Demo of go-form with Bootstrap - - - - -
    - {{ form_widget (.styleForm.GetField "value") }} -
    - -

    Demo of go-form with Bootstrap

    - -
    - Debug view -
    - Submitted: - {{ .isSubmitted }} -
    -
    - Valid: - {{ .isValid }} -
    - -
    - Dump of data -
    {{ .dump }}
    -
    - -
    - Form as JSON -
    {{ .json }}
    -
    -
    - - {{if .isValid}} -
    The form is valid!
    - {{else}} -
    The form is invalid!
    - {{end}} - - {{ form .form }} -
    - - - - diff --git a/example/view/html5.html b/example/view/html5.html deleted file mode 100644 index 88db2d8..0000000 --- a/example/view/html5.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - Demo of go-form (pure HTML5 and Pico) - - - - - - - - - {{ form_widget (.styleForm.GetField "value") }} -
    - -

    Demo of go-form (pure HTML5 and Pico)

    - -
    - Debug view - -
    - Submitted: - {{ .isSubmitted }} -
    -
    - Valid: - {{ .isValid }} -
    - -
    - Dump of data -
    {{ .dump }}
    -
    - -
    - Form as JSON -
    {{ .json }}
    -
    - -
    - - {{if .isValid}} -

    The form is valid!

    - {{else}} -

    The form is invalid!

    - {{end}} - - {{ form .form }} - - - - - diff --git a/favicon-16x16.png b/favicon-16x16.png new file mode 100644 index 0000000..0f2dd2b Binary files /dev/null and b/favicon-16x16.png differ diff --git a/favicon-32x32.png b/favicon-32x32.png new file mode 100644 index 0000000..5c1aea5 Binary files /dev/null and b/favicon-32x32.png differ diff --git a/favicon-dark.svg b/favicon-dark.svg new file mode 100644 index 0000000..3b49e35 --- /dev/null +++ b/favicon-dark.svg @@ -0,0 +1,13 @@ + + + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..553fa15 Binary files /dev/null and b/favicon.ico differ diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 0000000..6a08d10 --- /dev/null +++ b/favicon.svg @@ -0,0 +1,13 @@ + + + diff --git a/form/field.go b/form/field.go deleted file mode 100644 index fe63326..0000000 --- a/form/field.go +++ /dev/null @@ -1,423 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "fmt" - "maps" - "slices" - "strings" - - "gitnet.fr/deblan/go-form/util" - "gitnet.fr/deblan/go-form/validation" -) - -// Generic function for field.Validation -func DefaultFieldValidation(f *Field) bool { - if len(f.Children) > 0 { - isValid := true - - for _, c := range f.Children { - c.ResetErrors() - isChildValid, errs := validation.Validate(c.Data, c.Constraints) - - if len(errs) > 0 { - c.Errors = errs - } - - isValid = isChildValid && isValid - - for _, sc := range c.Children { - isValid = DefaultFieldValidation(sc) && isValid - } - } - - return isValid - } else { - f.ResetErrors() - isValid, errs := validation.Validate(f.Data, f.Constraints) - - if len(errs) > 0 { - f.Errors = errs - } - - return isValid - } -} - -// Field represents a field in a form -type Field struct { - Name string `json:"name"` - NamePrefix string `json:"name_prefix"` - Widget string `json:"widget"` - Data any `json:"-"` - Options []*Option `json:"options"` - Children []*Field `json:"children"` - Constraints []validation.Constraint `json:"-"` - Errors []validation.Error `json:"-"` - BeforeMount func(data any) (any, error) `json:"-"` - BeforeBind func(data any) (any, error) `json:"-"` - Validate func(f *Field) bool `json:"-"` - IsSlice bool `json:"is_slice"` - IsCollection bool `json:"is_collection"` - IsFixedName bool `json:"is_fixed_name"` - Form *Form `json:"-"` - Parent *Field `json:"-"` -} - -// Generates a new field with default properties -// It should not be used directly but inside function like in form.NewFieldText -func NewField(name, widget string) *Field { - f := &Field{ - Name: name, - IsFixedName: false, - Widget: widget, - Data: nil, - } - - f.BeforeMount = func(data any) (any, error) { - return data, nil - } - - f.BeforeBind = func(data any) (any, error) { - return data, nil - } - - f.WithOptions( - NewOption("attr", Attrs{}), - NewOption("row_attr", Attrs{}), - NewOption("label_attr", Attrs{}), - NewOption("help_attr", Attrs{}), - ) - - f.Validate = DefaultFieldValidation - - return f -} - -func (f *Field) Copy() *Field { - return &Field{ - Name: f.Name, - Form: f.Form, - Widget: f.Widget, - Options: f.Options, - Constraints: f.Constraints, - BeforeMount: f.BeforeMount, - BeforeBind: f.BeforeBind, - Validate: f.Validate, - IsSlice: f.IsSlice, - IsFixedName: f.IsFixedName, - } -} - -// Checks if the field contains an option using its name -func (f *Field) HasOption(name string) bool { - for _, option := range f.Options { - if option.Name == name { - return true - } - } - - return false -} - -// Returns an option using its name -func (f *Field) GetOption(name string) *Option { - for _, option := range f.Options { - if option.Name == name { - return option - } - } - - return nil -} - -// Appends options to the field -func (f *Field) WithOptions(options ...*Option) *Field { - for _, option := range options { - if f.HasOption(option.Name) { - f.GetOption(option.Name).Value = option.Value - } else { - f.Options = append(f.Options, option) - } - } - - return f -} - -// Remove an option if exists -func (f *Field) RemoveOption(name string) *Field { - var options []*Option - - for _, option := range f.Options { - if option.Name != name { - options = append(options, option) - } - } - - f.Options = options - - return f -} - -// Sets data the field -func (f *Field) WithData(data any) *Field { - f.Data = data - - return f -} - -// Resets the field errors -func (f *Field) ResetErrors() *Field { - f.Errors = []validation.Error{} - - return f -} - -// Sets that the field represents a data slice -func (f *Field) WithSlice() *Field { - f.IsSlice = true - - return f -} - -// Sets that the field represents a collection -func (f *Field) WithCollection() *Field { - f.IsCollection = true - - return f -} - -// Sets that the name of the field is not computed -func (f *Field) WithFixedName() *Field { - f.IsFixedName = true - - return f -} - -// Appends constraints -func (f *Field) WithConstraints(constraints ...validation.Constraint) *Field { - for _, constraint := range constraints { - f.Constraints = append(f.Constraints, constraint) - } - - return f -} - -// Sets a transformer applied to the structure data before displaying it in a field -func (f *Field) WithBeforeMount(callback func(data any) (any, error)) *Field { - f.BeforeMount = callback - - return f -} - -// Sets a transformer applied to the data of a field before defining it in a structure -func (f *Field) WithBeforeBind(callback func(data any) (any, error)) *Field { - f.BeforeBind = callback - - return f -} - -// Appends children -func (f *Field) Add(children ...*Field) *Field { - for _, child := range children { - child.Parent = f - f.Children = append(f.Children, child) - } - - return f -} - -// Checks if the field contains a child using its name -func (f *Field) HasChild(name string) bool { - for _, child := range f.Children { - if name == child.Name { - return true - } - } - - return false -} - -// Returns a child using its name -func (f *Field) GetChild(name string) *Field { - var result *Field - - for _, child := range f.Children { - if name == child.Name { - result = child - - break - } - } - - return result -} - -// Computes the name of the field -func (f *Field) GetName() string { - var name string - - if f.IsFixedName { - return f.Name - } - - if f.Form != nil && f.Form.Name != "" { - name = fmt.Sprintf("%s%s[%s]", f.Form.Name, f.NamePrefix, f.Name) - } else if f.Parent != nil { - name = fmt.Sprintf("%s%s[%s]", f.Parent.GetName(), f.NamePrefix, f.Name) - } else { - name = f.Name - } - - return name -} - -// Computes the id of the field -func (f *Field) GetId() string { - name := f.GetName() - name = strings.ReplaceAll(name, "[", "-") - name = strings.ReplaceAll(name, "]", "") - name = strings.ToLower(name) - - return name -} - -// Populates the field with data -func (f *Field) Mount(data any) error { - data, err := f.BeforeMount(data) - - if err != nil { - return err - } - - if len(f.Children) == 0 { - f.Data = data - - return nil - } - - props, err := util.InspectStruct(data) - - if err != nil { - return err - } - - for key, value := range props { - if f.HasChild(key) { - err = f.GetChild(key).Mount(value) - - if err != nil { - return err - } - } - } - - return nil -} - -// Bind the data into the given map -func (f *Field) Bind(data map[string]any, key *string, parentIsSlice bool) error { - if len(f.Children) == 0 { - v, err := f.BeforeBind(f.Data) - - if err != nil { - return err - } - - if key != nil { - data[*key] = v - } else { - data[f.Name] = v - } - - return nil - } - - data[f.Name] = make(map[string]any) - - for _, child := range f.Children { - child.Bind(data[f.Name].(map[string]any), key, f.IsCollection) - } - - if f.IsCollection { - var nextData []any - values := data[f.Name].(map[string]any) - var keys []string - - for key, _ := range values { - keys = append(keys, key) - } - - slices.Sort(keys) - - for _, key := range keys { - for valueKey, value := range values { - if valueKey == key { - nextData = append(nextData, value) - } - } - } - - data[f.Name] = nextData - } - - return nil -} - -// Generates a tree of errors -func (f *Field) ErrorsTree(tree map[string]any, key *string) { - var index string - - if key != nil { - index = *key - } else { - index = f.Name - } - - if len(f.Children) == 0 { - if len(f.Errors) > 0 { - tree[index] = map[string]any{ - "meta": map[string]any{ - "id": f.GetId(), - "name": f.Name, - "formName": f.GetName(), - }, - "errors": f.Errors, - } - } - } else { - errors := make(map[string]any) - - for _, child := range f.Children { - if len(child.Errors) > 0 { - child.ErrorsTree(errors, &child.Name) - } - } - - if len(errors) > 0 { - tree[index] = map[string]any{ - "meta": map[string]any{ - "id": f.GetId(), - "name": f.Name, - "formName": f.GetName(), - }, - "errors": []validation.Error{}, - "children": slices.Collect(maps.Values(errors)), - } - } - } -} diff --git a/form/field_checkbox.go b/form/field_checkbox.go deleted file mode 100644 index b4b903c..0000000 --- a/form/field_checkbox.go +++ /dev/null @@ -1,48 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "github.com/spf13/cast" -) - -// Generates an input[type=checkbox] -func NewFieldCheckbox(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "checkbox")). - WithBeforeMount(func(data any) (any, error) { - switch data.(type) { - case string: - data = data == "1" - case bool: - return data, nil - } - - return cast.ToInt(data), nil - }). - WithBeforeBind(func(data any) (any, error) { - switch data.(type) { - case string: - return data == "1", nil - case bool: - return data, nil - } - - return cast.ToBool(data), nil - }) - - return f -} diff --git a/form/field_choice.go b/form/field_choice.go deleted file mode 100644 index 16c06fc..0000000 --- a/form/field_choice.go +++ /dev/null @@ -1,200 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "encoding/json" - "reflect" - - "github.com/spf13/cast" - "gitnet.fr/deblan/go-form/validation" -) - -type Choice struct { - Value string - Label string - Data any -} - -func (c Choice) Match(value string) bool { - return c.Value == value -} - -type Choices struct { - Data any `json:"data"` - ValueBuilder func(key int, item any) string `json:"-"` - LabelBuilder func(key int, item any) string `json:"-"` -} - -func (c *Choices) Match(f *Field, value string) bool { - if f.Data == nil { - return false - } - - if f.IsSlice { - v := reflect.ValueOf(f.Data) - - for key, _ := range c.GetChoices() { - for i := 0; i < v.Len(); i++ { - item := v.Index(i).Interface() - - switch item.(type) { - case string: - if item == value { - return true - } - default: - if c.ValueBuilder(key, item) == value { - return true - } - } - } - } - - return false - } - - return f.Data == value -} - -func (c *Choices) WithValueBuilder(builder func(key int, item any) string) *Choices { - c.ValueBuilder = builder - - return c -} - -func (c *Choices) WithLabelBuilder(builder func(key int, item any) string) *Choices { - c.LabelBuilder = builder - - return c -} - -func (c *Choices) GetChoices() []Choice { - choices := []Choice{} - - v := reflect.ValueOf(c.Data) - - switch v.Kind() { - case reflect.Slice, reflect.Array, reflect.String, reflect.Map: - for i := 0; i < v.Len(); i++ { - choices = append(choices, Choice{ - Value: c.ValueBuilder(i, v.Index(i).Interface()), - Label: c.LabelBuilder(i, v.Index(i).Interface()), - Data: v.Index(i).Interface(), - }) - } - } - - return choices -} - -func (c Choices) MarshalJSON() ([]byte, error) { - var choices []map[string]string - - v := reflect.ValueOf(c.Data) - - switch v.Kind() { - case reflect.Slice, reflect.Array, reflect.String, reflect.Map: - for i := 0; i < v.Len(); i++ { - choices = append(choices, map[string]string{ - "value": c.ValueBuilder(i, v.Index(i).Interface()), - "label": c.LabelBuilder(i, v.Index(i).Interface()), - }) - } - } - - return json.Marshal(choices) -} - -// Generates an instance of Choices -func NewChoices(items any) *Choices { - builder := func(key int, item any) string { - return cast.ToString(key) - } - - choices := Choices{ - ValueBuilder: builder, - LabelBuilder: builder, - Data: items, - } - - return &choices -} - -// Generates inputs (checkbox or radio) or selects -func NewFieldChoice(name string) *Field { - f := NewField(name, "choice"). - WithOptions( - NewOption("choices", &Choices{}), - NewOption("expanded", false), - NewOption("multiple", false), - NewOption("empty_choice_label", "None"), - ) - - f.Validate = func(field *Field) bool { - isValid := field.Validate(field) - - if len(validation.NewNotBlank().Validate(field.Data)) == 0 { - choices := field.GetOption("choices").Value.(*Choices) - isValidChoice := false - - for _, choice := range choices.GetChoices() { - if choices.Match(field, choice.Value) { - isValidChoice = true - } - } - - if !isValidChoice { - field.Errors = append(field.Errors, validation.Error("This value is not valid.")) - isValid = false - } - } - - return isValid - } - - f.WithBeforeBind(func(data any) (any, error) { - choices := f.GetOption("choices").Value.(*Choices) - - switch data.(type) { - case string: - v := data.(string) - for _, c := range choices.GetChoices() { - if c.Match(v) { - return c.Data, nil - } - } - case []string: - v := reflect.ValueOf(data) - var res []interface{} - - for _, choice := range choices.GetChoices() { - for i := 0; i < v.Len(); i++ { - item := v.Index(i).Interface().(string) - if choice.Match(item) { - res = append(res, choice.Data) - } - } - } - - return res, nil - } - - return data, nil - }) - - return f -} diff --git a/form/field_collection.go b/form/field_collection.go deleted file mode 100644 index 3f3ece1..0000000 --- a/form/field_collection.go +++ /dev/null @@ -1,80 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "fmt" - "reflect" -) - -// Generates a sub form -func NewFieldCollection(name string) *Field { - f := NewField(name, "collection"). - WithOptions( - NewOption("allow_add", true), - NewOption("allow_delete", true), - NewOption("form", nil), - ). - WithCollection() - - f.WithBeforeMount(func(data any) (any, error) { - if opt := f.GetOption("form"); opt != nil { - if src, ok := opt.Value.(*Form); ok { - src.Name = f.GetName() - t := reflect.TypeOf(data) - - switch t.Kind() { - case reflect.Slice: - slice := reflect.ValueOf(data) - - for i := 0; i < slice.Len(); i++ { - name := fmt.Sprintf("%d", i) - value := slice.Index(i).Interface() - - if f.HasChild(name) { - f.GetChild(name).Mount(value) - } else { - form := src.Copy() - form.Mount(value) - - field := f.Copy() - field.Widget = "sub_form" - field.Name = name - field.Add(form.Fields...) - field. - RemoveOption("form"). - RemoveOption("label") - - for _, c := range field.Children { - c.NamePrefix = fmt.Sprintf("[%d]", i) - } - - f.Add(field) - } - } - } - } - } - - return data, nil - }) - - return f -} - -func NewCollection(name string) *Field { - return NewFieldCollection(name) -} diff --git a/form/field_input.go b/form/field_input.go deleted file mode 100644 index ca42873..0000000 --- a/form/field_input.go +++ /dev/null @@ -1,84 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "github.com/spf13/cast" -) - -// Generates an input[type=text] -func NewFieldText(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "text")) - - return f -} - -// Generates an input[type=number] with default transformers -func NewFieldNumber(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "number")). - WithBeforeBind(func(data any) (any, error) { - return cast.ToFloat64(data), nil - }) - - return f -} - -// Generates an input[type=email] -func NewFieldMail(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "email")) - - return f -} - -// Generates an input[type=range] -func NewFieldRange(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "range")). - WithBeforeBind(func(data any) (any, error) { - return cast.ToFloat64(data), nil - }) - - return f -} - -// Generates an input[type=password] -func NewFieldPassword(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "password")) - - return f -} - -// Generates an input[type=hidden] -func NewFieldHidden(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "hidden")) - - return f -} - -// Generates an input[type=submit] -func NewSubmit(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "submit")) - - f.Data = "Submit" - - return f -} diff --git a/form/field_input_csrf.go b/form/field_input_csrf.go deleted file mode 100644 index fc3bc3a..0000000 --- a/form/field_input_csrf.go +++ /dev/null @@ -1,23 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -func NewFieldCsrf(name string) *Field { - f := NewFieldHidden(name). - WithFixedName() - - return f -} diff --git a/form/field_input_date.go b/form/field_input_date.go deleted file mode 100644 index 893c59d..0000000 --- a/form/field_input_date.go +++ /dev/null @@ -1,109 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "fmt" - "time" -) - -func DateBeforeMount(data any, format string) (any, error) { - if data == nil { - return nil, nil - } - - switch data.(type) { - case string: - return data, nil - case time.Time: - return data.(time.Time).Format(format), nil - case *time.Time: - v := data.(*time.Time) - if v != nil { - return v.Format(format), nil - } - } - - return nil, nil -} - -// Generates an input[type=date] with default transformers -func NewFieldDate(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "date")). - WithBeforeMount(func(data any) (any, error) { - return DateBeforeMount(data, "2006-01-02") - }). - WithBeforeBind(func(data any) (any, error) { - return time.Parse(time.DateOnly, data.(string)) - }) - - return f -} - -// Generates an input[type=datetime] with default transformers -func NewFieldDatetime(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "datetime")). - WithBeforeMount(func(data any) (any, error) { - return DateBeforeMount(data, "2006-01-02 15:04") - }). - WithBeforeBind(func(data any) (any, error) { - return time.Parse("2006-01-02T15:04", data.(string)) - }) - - return f -} - -// Generates an input[type=datetime-local] with default transformers -func NewFieldDatetimeLocal(name string) *Field { - f := NewField(name, "input"). - WithOptions( - NewOption("type", "datetime-local"), - ). - WithBeforeMount(func(data any) (any, error) { - return DateBeforeMount(data, "2006-01-02 15:04") - }). - WithBeforeBind(func(data any) (any, error) { - a, b := time.Parse("2006-01-02T15:04", data.(string)) - - return a, b - }) - - return f -} - -// Generates an input[type=time] with default transformers -func NewFieldTime(name string) *Field { - f := NewField(name, "input"). - WithOptions(NewOption("type", "time")). - WithBeforeMount(func(data any) (any, error) { - return DateBeforeMount(data, "15:04") - }). - WithBeforeBind(func(data any) (any, error) { - if data != nil { - v := data.(string) - - if len(v) > 0 { - return time.Parse(time.TimeOnly, fmt.Sprintf("%s:00", v)) - } - } - - return nil, nil - }) - - return f -} diff --git a/form/field_subform.go b/form/field_subform.go deleted file mode 100644 index 6762ef6..0000000 --- a/form/field_subform.go +++ /dev/null @@ -1,27 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Generates a sub form -func NewFieldSubForm(name string) *Field { - f := NewField(name, "sub_form") - - return f -} - -func NewSubForm(name string) *Field { - return NewFieldSubForm(name) -} diff --git a/form/field_textarea.go b/form/field_textarea.go deleted file mode 100644 index b9045bb..0000000 --- a/form/field_textarea.go +++ /dev/null @@ -1,21 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Generates a textarea -func NewFieldTextarea(name string) *Field { - return NewField(name, "textarea") -} diff --git a/form/form.go b/form/form.go deleted file mode 100644 index 04016d3..0000000 --- a/form/form.go +++ /dev/null @@ -1,321 +0,0 @@ -package form - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "encoding/json" - "io/ioutil" - "maps" - "net/http" - "net/url" - "slices" - "strings" - - "github.com/mitchellh/mapstructure" - "gitnet.fr/deblan/go-form/util" - "gitnet.fr/deblan/go-form/validation" -) - -// Field represents a form -type Form struct { - Fields []*Field `json:"children"` - GlobalFields []*Field `json:"-"` - Errors []validation.Error `json:"-"` - Method string `json:"method"` - JsonRequest bool `json:"json_request"` - Action string `json:"action"` - Name string `json:"name"` - Options []*Option `json:"options"` - RequestData *url.Values `json:"-"` -} - -// Generates a new form with default properties -func NewForm(fields ...*Field) *Form { - f := new(Form) - f.Method = "POST" - f.Name = "form" - f.Add(fields...) - f.WithOptions( - NewOption("attr", Attrs{}), - NewOption("help_attr", Attrs{}), - ) - - return f -} - -// Checks if the form contains an option using its name -func (f *Form) HasOption(name string) bool { - for _, option := range f.Options { - if option.Name == name { - return true - } - } - - return false -} - -// Returns an option using its name -func (f *Form) GetOption(name string) *Option { - for _, option := range f.Options { - if option.Name == name { - return option - } - } - - return nil -} - -// Resets the form errors -func (f *Form) ResetErrors() *Form { - f.Errors = []validation.Error{} - - return f -} - -// Appends children -func (f *Form) Add(fields ...*Field) { - for _, field := range fields { - field.Form = f - f.Fields = append(f.Fields, field) - } -} - -// Configures its children deeply -// This function must be called after adding all fields -func (f *Form) End() *Form { - f.GlobalFields = []*Field{} - - for _, c := range f.Fields { - f.AddGlobalField(c) - } - - return f -} - -// Configures its children deeply -func (f *Form) AddGlobalField(field *Field) { - f.GlobalFields = append(f.GlobalFields, field) - - for _, c := range field.Children { - f.AddGlobalField(c) - } -} - -// Checks if the form contains a child using its name -func (f *Form) HasField(name string) bool { - for _, field := range f.Fields { - if name == field.Name { - return true - } - } - - return false -} - -// Returns a child using its name -func (f *Form) GetField(name string) *Field { - var result *Field - - for _, field := range f.Fields { - if name == field.Name { - result = field - break - } - } - - return result -} - -// Sets the method of the format (http.MethodPost, http.MethodGet, ...) -func (f *Form) WithMethod(v string) *Form { - f.Method = v - - return f -} - -// Sets the name of the form (used to compute name of fields) -func (f *Form) WithName(v string) *Form { - f.Name = v - - return f -} - -// Sets the action of the form (eg: "/") -func (f *Form) WithAction(v string) *Form { - f.Action = v - - return f -} - -// Appends options to the form -func (f *Form) WithOptions(options ...*Option) *Form { - for _, option := range options { - if f.HasOption(option.Name) { - f.GetOption(option.Name).Value = option.Value - } else { - f.Options = append(f.Options, option) - } - } - - return f -} - -// Checks the a form is valid -func (f *Form) IsValid() bool { - isValid := true - f.ResetErrors() - - for _, field := range f.Fields { - fieldIsValid := field.Validate(field) - isValid = isValid && fieldIsValid - } - - return isValid -} - -// Copies datas from a struct to the form -func (f *Form) Mount(data any) error { - props, err := util.InspectStruct(data) - - if err != nil { - return err - } - - for key, value := range props { - if f.HasField(key) { - err = f.GetField(key).Mount(value) - - if err != nil { - return err - } - } - } - - return nil -} - -func (f *Form) WithJsonRequest() *Form { - f.JsonRequest = true - - return f -} - -// Copies datas from the form to a struct -func (f *Form) Bind(data any) error { - toBind := make(map[string]any) - - for _, field := range f.Fields { - field.Bind(toBind, nil, false) - } - - return mapstructure.Decode(toBind, data) -} - -// Processes a request -func (f *Form) HandleRequest(req *http.Request) { - var data url.Values - - if f.JsonRequest { - body, err := ioutil.ReadAll(req.Body) - - if err != nil { - return - } - - mapping := make(map[string]any) - err = json.Unmarshal(body, &mapping) - - if err != nil { - return - } - - data = url.Values{} - util.MapToUrlValues(&data, f.Name, mapping) - } else { - switch f.Method { - case "GET": - data = req.URL.Query() - default: - req.ParseForm() - data = req.Form - } - } - - isSubmitted := false - - type collectionData map[string]any - - for _, c := range f.GlobalFields { - if c.IsCollection { - collection := util.NewCollection() - - for key, _ := range data { - if strings.HasPrefix(key, c.GetName()) { - root := strings.Replace(key, c.GetName(), "", 1) - indexes := util.ExtractDataIndexes(root) - - collection.Add(indexes, data.Get(key)) - } - } - - c.Mount(collection.Slice()) - } else if data.Has(c.GetName()) { - isSubmitted = true - - if c.IsSlice { - c.Mount(data[c.GetName()]) - } else { - c.Mount(data.Get(c.GetName())) - } - } - } - - if isSubmitted { - f.RequestData = &data - } -} - -// Checks if the form is submitted -func (f *Form) IsSubmitted() bool { - return f.RequestData != nil -} - -// Generates a tree of errors -func (f *Form) ErrorsTree() map[string]any { - errors := make(map[string]any) - - for _, field := range f.Fields { - field.ErrorsTree(errors, nil) - } - - return map[string]any{ - "errors": f.Errors, - "children": slices.Collect(maps.Values(errors)), - } -} - -func (f *Form) Copy() *Form { - var fields []*Field - - for _, i := range f.Fields { - f := *i - fields = append(fields, &f) - } - - return &Form{ - Fields: fields, - } -} diff --git a/form/option.go b/form/option.go deleted file mode 100644 index 95eee67..0000000 --- a/form/option.go +++ /dev/null @@ -1,78 +0,0 @@ -package form - -import "strings" - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -type Option struct { - Name string `json:"name"` - Value any `json:"value"` -} - -func NewOption(name string, value any) *Option { - return &Option{ - Name: name, - Value: value, - } -} - -func (o *Option) AsBool() bool { - return o.Value.(bool) -} - -func (o *Option) AsString() string { - return o.Value.(string) -} - -func (o *Option) AsAttrs() Attrs { - return o.Value.(Attrs) -} - -type Attrs map[string]string - -func (a Attrs) Append(name, value string) { - v, ok := a[name] - - if !ok { - v = value - } else { - v = value + " " + v - } - - a[name] = v -} - -func (a Attrs) Prepend(name, value string) { - v, ok := a[name] - - if !ok { - v = value - } else { - v += " " + value - } - - a[name] = v -} - -func (a Attrs) Remove(name, value string) { - v, ok := a[name] - - if !ok { - v = strings.ReplaceAll(v, value, "") - } - - a[name] = v -} diff --git a/go.mod b/go.mod deleted file mode 100644 index 20dda1e..0000000 --- a/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module gitnet.fr/deblan/go-form - -go 1.23.0 - -require ( - github.com/iancoleman/strcase v0.3.0 - github.com/mitchellh/mapstructure v1.5.0 - github.com/spf13/cast v1.9.2 - github.com/yassinebenaid/godump v0.11.1 - maragu.dev/gomponents v1.1.0 -) diff --git a/go.sum b/go.sum deleted file mode 100644 index c6c8a71..0000000 --- a/go.sum +++ /dev/null @@ -1,20 +0,0 @@ -github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= -github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE= -github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= -github.com/yassinebenaid/godump v0.11.1 h1:SPujx/XaYqGDfmNh7JI3dOyCUVrG0bG2duhO3Eh2EhI= -github.com/yassinebenaid/godump v0.11.1/go.mod h1:dc/0w8wmg6kVIvNGAzbKH1Oa54dXQx8SNKh4dPRyW44= -maragu.dev/gomponents v1.1.0 h1:iCybZZChHr1eSlvkWp/JP3CrZGzctLudQ/JI3sBcO4U= -maragu.dev/gomponents v1.1.0/go.mod h1:oEDahza2gZoXDoDHhw8jBNgH+3UR5ni7Ur648HORydM= diff --git a/images/logo-dark.svg b/images/logo-dark.svg new file mode 100644 index 0000000..2857264 --- /dev/null +++ b/images/logo-dark.svg @@ -0,0 +1,3 @@ + + + diff --git a/images/logo.svg b/images/logo.svg new file mode 100644 index 0000000..1ed7daf --- /dev/null +++ b/images/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..3cf9594 --- /dev/null +++ b/index.html @@ -0,0 +1,337 @@ + + + + + + + + + + + + + +deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + +
    + +
    +

    + + + + + + diff --git a/js/custom.js b/js/custom.js new file mode 100644 index 0000000..e8d886e --- /dev/null +++ b/js/custom.js @@ -0,0 +1,126 @@ +function normalizeCode(code) { + return code + .trim() + .replace(/^```go/, '') + .replace(/^```/, '') + .replace(/```$/, '') + .replace(/<([^>]+)>/g, '') + .trim() +} + +function updatePlaygroundView(goplay, id, code) { + const textarea = document.getElementById(`textarea-${id}`) + + textarea.value = code + textarea.style.height = textarea.scrollHeight + 'px'; + textarea.style.overflowY = 'hidden'; + + textarea.addEventListener('input', function() { + this.style.height = 'auto'; + this.style.height = this.scrollHeight + 'px'; + }) + + const toolRun = document.getElementById(`hugo-goplay-tool-${id}-run`) + const toolTry = document.getElementById(`hugo-goplay-tool-${id}-try`) + const toolShare = document.getElementById(`hugo-goplay-tool-${id}-share`) + + toolRun.addEventListener('click', () => { + const parent = document.getElementById(id) + const pre = document.createElement('pre') + const container = document.createElement('code') + + container.classList.add('text') + pre.appendChild(container) + parent.replaceChildren(pre) + + goplay.renderCompile(container, textarea.value); + }); + + [toolTry, toolShare].forEach((v) => { + v.addEventListener('click', async () => { + const shareUrl = await goplay.share(code) + window.open(shareUrl, '_blank').focus(); + }) + }); +} + +function createFieldPlayground(goplay, id, code) { + code = createFieldPlaygroundCode(code) + + updatePlaygroundView(goplay, id, code) +} + +function createPlaygroundWithAutoImportMail(goplay, id, code) { + let lines = normalizeCode(code).split("\n") + let results = ["package main", ""] + let imports = [] + let body = [] + + lines.forEach((line) => { + if (line.substr(0, 7) === '@import') { + imports.push(' ' + line.replace('@import', '').trim()) + } else { + body.push(" " + line) + } + }) + + if (imports.length > 0) { + results.push("import (") + + imports.forEach((v) => { + results.push(v) + }) + + results.push(")", "") + } + + results.push("func main() {") + + body.forEach((v, i) => { + if (i == 0 && v.trim() == "") { + return + } + + results.push(v) + }) + + results.push("}", "") + + updatePlaygroundView(goplay, id, results.join("\n")) +} + +function createFieldPlaygroundCode(code) { + code = normalizeCode(code) + let lines = code.split("\n"); + + for (let i in lines) { + lines[i] = [' ', lines[i]].join('') + } + + code = lines.join("\n"); + + return `package main + +import ( + "fmt" + "html/template" + "strings" + + "gitnet.fr/deblan/go-form/form" + "gitnet.fr/deblan/go-form/theme" +) + +func main() { +${code} + + r(form.NewForm(field)) +} + +func r(f *form.Form) { + render := theme.NewRenderer(theme.Html5) + tpl, _ := template.New("example").Funcs(render.FuncMap()).Parse(\`{{ form_widget (.Form.GetField "Foo") }}\`) + b := new(strings.Builder) + tpl.Execute(b, map[string]any{"Form": f}) + fmt.Println(b.String()) +}` +} diff --git a/js/main.min.0942239592f0795dc7213dd1057fd229d7edc19c0ef1a285396eb292d9ca9842.js b/js/main.min.0942239592f0795dc7213dd1057fd229d7edc19c0ef1a285396eb292d9ca9842.js new file mode 100644 index 0000000..3ed1b78 --- /dev/null +++ b/js/main.min.0942239592f0795dc7213dd1057fd229d7edc19c0ef1a285396eb292d9ca9842.js @@ -0,0 +1,6 @@ +(function(){const t="system",e=document.querySelectorAll(".theme-toggle");localStorage.getItem("color-theme")==="dark"||!("color-theme"in localStorage)&&(window.matchMedia("(prefers-color-scheme: dark)").matches&&t==="system"||t==="dark")?e.forEach(e=>e.dataset.theme="dark"):e.forEach(e=>e.dataset.theme="light"),e.forEach(e=>{e.addEventListener("click",function(){localStorage.getItem("color-theme")?localStorage.getItem("color-theme")==="light"?(setDarkTheme(),localStorage.setItem("color-theme","dark")):(setLightTheme(),localStorage.setItem("color-theme","light")):document.documentElement.classList.contains("dark")?(setLightTheme(),localStorage.setItem("color-theme","light")):(setDarkTheme(),localStorage.setItem("color-theme","dark")),e.dataset.theme=document.documentElement.classList.contains("dark")?"dark":"light"})}),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",n=>{t==="system"&&!("color-theme"in localStorage)&&(n.matches?setDarkTheme():setLightTheme(),e.forEach(e=>e.dataset.theme=document.documentElement.classList.contains("dark")?"dark":"light"))})})(),document.addEventListener("DOMContentLoaded",function(){const i=document.querySelector(".hamburger-menu"),e=document.querySelector(".mobile-menu-overlay"),t=document.querySelector(".sidebar-container"),n=["hx-fixed","hx-inset-0","hx-z-10","hx-bg-black/80","dark:hx-bg-black/60"];e.classList.add("hx-bg-transparent"),e.classList.remove("hx-hidden",...n);function s(){i.querySelector("svg").classList.toggle("open"),t.classList.toggle("max-md:[transform:translate3d(0,-100%,0)]"),t.classList.toggle("max-md:[transform:translate3d(0,0,0)]"),document.body.classList.toggle("hx-overflow-hidden"),document.body.classList.toggle("md:hx-overflow-auto")}function o(){e.classList.remove(...n),e.classList.add("hx-bg-transparent")}i.addEventListener("click",t=>{t.preventDefault(),s(),e.classList.contains("hx-bg-transparent")?(e.classList.add(...n),e.classList.remove("hx-bg-transparent")):o()}),e.addEventListener("click",e=>{e.preventDefault(),s(),o()});const a=t.querySelectorAll("a");a.forEach(e=>{e.addEventListener("click",t=>{e.getAttribute("href")&&e.getAttribute("href").startsWith("#")&&window.innerWidth<768&&(s(),o())})})}),document.addEventListener("DOMContentLoaded",function(){const e=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.innerHTML=` + + `,e.setAttribute("fill","none"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e},t=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.innerHTML=` + + `,e.setAttribute("fill","none"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e};document.querySelectorAll(".hextra-code-copy-btn").forEach(function(n){n.querySelector(".copy-icon")?.appendChild(e()),n.querySelector(".success-icon")?.appendChild(t()),n.addEventListener("click",function(e){e.preventDefault();const s=n.parentElement.previousElementSibling;let t;if(s.tagName==="CODE")t=s;else{const e=s.querySelectorAll("code");t=e[e.length-1]}if(t){let e=t.innerText;"lang"in t.dataset&&(e=e.replace(/\n\n/g,` +`)),navigator.clipboard.writeText(e).then(function(){n.classList.add("copied"),setTimeout(function(){n.classList.remove("copied")},1e3)}).catch(function(e){console.error("Failed to copy text: ",e)})}else console.error("Target element not found")})})}),document.querySelectorAll(".hextra-tabs-toggle").forEach(function(e){e.addEventListener("click",function(e){const n=Array.from(e.target.parentElement.querySelectorAll(".hextra-tabs-toggle"));n.map(e=>e.dataset.state=""),e.target.dataset.state="selected";const t=e.target.parentElement.parentElement.nextElementSibling;Array.from(t.children).forEach(function(e){e.dataset.state=""});const s=e.target.getAttribute("aria-controls"),o=t.querySelector(`#${s}`);o.dataset.state="selected"})}),function(){const e=document.querySelectorAll(".language-switcher");e.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),e.dataset.state=e.dataset.state==="open"?"closed":"open";const n=e.nextElementSibling;n.classList.toggle("hx-hidden");const s=e.getBoundingClientRect(),o=s.top-window.innerHeight-15;n.style.transform=`translate3d(${s.left}px, ${o}px, 0)`,n.style.minWidth=`${Math.max(s.width,50)}px`})}),document.addEventListener("click",t=>{t.target.closest(".language-switcher")===null&&e.forEach(e=>{e.dataset.state="closed";const t=e.nextElementSibling;t.classList.add("hx-hidden")})})}(),document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".hextra-filetree-folder");e.forEach(function(e){e.addEventListener("click",function(){Array.from(e.children).forEach(function(e){e.dataset.state=e.dataset.state==="open"?"closed":"open"}),e.nextElementSibling.dataset.state=e.nextElementSibling.dataset.state==="open"?"closed":"open"})})}),document.addEventListener("DOMContentLoaded",function(){scrollToActiveItem(),enableCollapsibles()});function enableCollapsibles(){const e=document.querySelectorAll(".hextra-sidebar-collapsible-button");e.forEach(function(e){e.addEventListener("click",function(t){t.preventDefault();const n=e.parentElement.parentElement;n&&n.classList.toggle("open")})})}function scrollToActiveItem(){const t=document.querySelector("aside.sidebar-container > .hextra-scrollbar"),n=document.querySelectorAll(".sidebar-active-item"),e=Array.from(n).find(function(e){return e.getBoundingClientRect().height>0});if(!e)return;const s=e.clientHeight,o=e.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTo({behavior:"instant",top:o-s})}document.addEventListener("DOMContentLoaded",function(){const e=document.querySelector("#backToTop");e&&document.addEventListener("scroll",t=>{window.scrollY>300?e.classList.remove("hx-opacity-0"):e.classList.add("hx-opacity-0")})});function scrollUp(){window.scroll({top:0,left:0,behavior:"smooth"})} \ No newline at end of file diff --git a/lib/flexsearch/flexsearch.bundle.min.0425860527cc9968f9f049421c7a56b39327d475e2e3a8f550416be3a9134327.js b/lib/flexsearch/flexsearch.bundle.min.0425860527cc9968f9f049421c7a56b39327d475e2e3a8f550416be3a9134327.js new file mode 100644 index 0000000..4ebf76e --- /dev/null +++ b/lib/flexsearch/flexsearch.bundle.min.0425860527cc9968f9f049421c7a56b39327d475e2e3a8f550416be3a9134327.js @@ -0,0 +1,39 @@ +/** + * Skipped minification because the original files appears to be already minified. + * Original file: /npm/flexsearch@0.7.31/dist/flexsearch.bundle.js + * + * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files + */ +/**! + * FlexSearch.js v0.7.31 (Bundle) + * Copyright 2018-2022 Nextapps GmbH + * Author: Thomas Wilkerling + * Licence: Apache-2.0 + * https://github.com/nextapps-de/flexsearch + */ +(function _f(self){'use strict';try{if(module)self=module}catch(e){}self._factory=_f;var t;function u(a){return"undefined"!==typeof a?a:!0}function aa(a){const b=Array(a);for(let c=0;c=this.B&&(w||!n[l])){var f=L(q,d,r),g="";switch(this.G){case "full":if(2f;h--)if(h-f>=this.B){var k=L(q,d,r,e,f);g=l.substring(f,h);M(this,n,g,k,a,c)}break}case "reverse":if(1=this.B&&M(this,n, +g,L(q,d,r,e,h),a,c);g=""}case "forward":if(1=this.B&&M(this,n,g,f,a,c);break}default:if(this.C&&(f=Math.min(f/this.C(b,l,r)|0,q-1)),M(this,n,l,f,a,c),w&&1=this.B&&!e[l]){e[l]=1;const p=this.l&&l>f;M(this,m,p?f:l,L(g+(d/2>g?0:1),d,r,h-1,k-1),a,c,p?l:f)}}}}this.m||(this.register[a]=1)}}return this}; +function L(a,b,c,d,e){return c&&1=this.B&&!c[q])if(this.s||f||this.map[q])k[w++]=q,c[q]=1;else return d;a=k;e=a.length}if(!e)return d;b||(b=100);h=this.depth&&1=d)))break;if(n){if(f)return ta(k,d,0);b[b.length]=k;return}}return!c&&k}function ta(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} +function ua(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)}; +t.remove=function(a,b){const c=this.register[a];if(c){if(this.m)for(let d=0,e;db||c)e=e.slice(c,c+b);d&&(e=za.call(this,e));return{tag:a,result:e}}}function za(a){const b=Array(a.length);for(let c=0,d;c + + + https://deblan.gitnet.page/go-form/docs/installation/ + + https://deblan.gitnet.page/go-form/docs/workflow/ + + https://deblan.gitnet.page/go-form/docs/form/ + + https://deblan.gitnet.page/go-form/docs/fields/ + + https://deblan.gitnet.page/go-form/docs/constraints/ + + https://deblan.gitnet.page/go-form/docs/rendering/ + + https://deblan.gitnet.page/go-form/categories/ + + https://deblan.gitnet.page/go-form/docs/ + + https://deblan.gitnet.page/go-form/tags/ + + https://deblan.gitnet.page/go-form/docs/rendering/theming/ + + https://deblan.gitnet.page/go-form/ + + diff --git a/tags/index.html b/tags/index.html new file mode 100644 index 0000000..494f437 --- /dev/null +++ b/tags/index.html @@ -0,0 +1,262 @@ + + + + + + + + + + + + +Tags – deblan/go-form + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + +
    +
    +
    +

    Tags

    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +

    + + + + + + diff --git a/tags/index.xml b/tags/index.xml new file mode 100644 index 0000000..1df074e --- /dev/null +++ b/tags/index.xml @@ -0,0 +1,18 @@ + + + deblan/go-form – Tags + https://deblan.gitnet.page/go-form/tags/ + Recent content in Tags on deblan/go-form + Hugo -- gohugo.io + en-us + + + + + + + + + + + diff --git a/theme/bootstrap5.go b/theme/bootstrap5.go deleted file mode 100644 index 525bdb8..0000000 --- a/theme/bootstrap5.go +++ /dev/null @@ -1,134 +0,0 @@ -package theme - -import ( - "gitnet.fr/deblan/go-form/form" - "gitnet.fr/deblan/go-form/validation" - . "maragu.dev/gomponents" - . "maragu.dev/gomponents/html" -) - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -var Bootstrap5 = ExtendTheme(Html5, func() map[string]RenderFunc { - theme := make(map[string]RenderFunc) - - theme["form_help"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - form.GetOption("help_attr").AsAttrs().Append("class", "form-text") - - return parent["base_form_help"](parent, form) - } - - theme["form_widget_help"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - field.GetOption("help_attr").AsAttrs().Append("class", "form-text") - - return parent["base_form_widget_help"](parent, field) - } - - theme["input"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - fieldType := field.GetOption("type").AsString() - - var class string - - if fieldType == "checkbox" || fieldType == "radio" { - class = "form-check-input" - } else if fieldType == "range" { - class = "form-range" - } else if fieldType == "button" || fieldType == "submit" || fieldType == "reset" { - class = "btn" - } else { - class = "form-control" - } - - field.GetOption("attr").AsAttrs().Append("class", class) - - return parent["base_input"](parent, field) - } - - theme["form_label"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - var class string - - if field.Widget == "choice" && field.HasOption("expanded") && field.GetOption("expanded").AsBool() { - class = "form-check-label" - } else { - class = "form-label" - } - - field.GetOption("label_attr").AsAttrs().Append("class", class) - - return parent["base_form_label"](parent, field) - } - - theme["choice"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - if !field.HasOption("expanded") || !field.GetOption("expanded").AsBool() { - field.GetOption("attr").AsAttrs().Append("class", "form-control") - } - - return parent["base_choice"](parent, field) - } - - theme["choice_expanded_item"] = func(parent map[string]RenderFunc, args ...any) Node { - return Div(Class("form-check"), args[0].(Node)) - } - - theme["textarea"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - field.GetOption("attr").AsAttrs().Append("class", "form-control") - - return parent["base_textarea"](parent, field) - } - - theme["form_row"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - if field.HasOption("type") { - fieldType := field.GetOption("type").AsString() - - if fieldType == "checkbox" || fieldType == "radio" { - field.GetOption("row_attr").AsAttrs().Append("class", "form-check") - } - } - - return parent["base_form_row"](parent, field) - } - - theme["errors"] = func(parent map[string]RenderFunc, args ...any) Node { - errors := args[0].([]validation.Error) - - var result []Node - - for _, v := range errors { - result = append(result, Text(string(v))) - result = append(result, Br()) - } - - return Div( - Class("invalid-feedback d-block"), - Group(result), - ) - } - - return theme -}) diff --git a/theme/html5.go b/theme/html5.go deleted file mode 100644 index 2d7889e..0000000 --- a/theme/html5.go +++ /dev/null @@ -1,466 +0,0 @@ -package theme - -import ( - "bytes" - "fmt" - - "github.com/spf13/cast" - "gitnet.fr/deblan/go-form/form" - "gitnet.fr/deblan/go-form/validation" - . "maragu.dev/gomponents" - . "maragu.dev/gomponents/html" -) - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -var Html5 = CreateTheme(func() map[string]RenderFunc { - theme := make(map[string]RenderFunc) - - theme["attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - var result []Node - - for i, v := range args[0].(form.Attrs) { - result = append(result, Attr(i, v)) - } - - return Group(result) - } - - theme["form_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - if !form.HasOption("attr") { - return Raw("") - } - - return parent["attributes"](parent, form.GetOption("attr").AsAttrs()) - } - - theme["errors"] = func(parent map[string]RenderFunc, args ...any) Node { - errors := args[0].([]validation.Error) - - var result []Node - - for _, v := range errors { - result = append(result, Li(Text(string(v)))) - } - - return Ul( - Class("gf-errors"), - Group(result), - ) - } - - theme["form_errors"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - return If( - len(form.Errors) > 0, - parent["errors"](parent, form.Errors), - ) - } - - theme["form_widget_errors"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return If( - len(field.Errors) > 0, - parent["errors"](parent, field.Errors), - ) - } - - theme["help"] = func(parent map[string]RenderFunc, args ...any) Node { - help := args[0].(string) - var extra Node - - if len(help) == 0 { - return Raw("") - } - - if len(args) == 2 { - extra = args[1].(Node) - } - - return Div( - Class("gf-help"), - Text(help), - extra, - ) - } - - theme["form_help"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - if !form.HasOption("help") { - return Raw("") - } - - return parent["help"]( - parent, - form.GetOption("help").AsString(), - parent["attributes"](parent, form.GetOption("help_attr").AsAttrs()), - ) - } - - theme["form_widget_help"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - if !field.HasOption("help") { - return Raw("") - } - - return parent["help"]( - parent, - field.GetOption("help").AsString(), - parent["attributes"](parent, field.GetOption("help_attr").AsAttrs()), - ) - } - - theme["label_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return parent["attributes"](parent, field.GetOption("label_attr").AsAttrs()) - } - - theme["form_label"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - if !field.HasOption("label") { - return Raw("") - } - - label := field.GetOption("label").AsString() - - return If(len(label) > 0, Label( - For(field.GetId()), - parent["label_attributes"](parent, field), - Text(label), - )) - } - - theme["field_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return parent["attributes"](parent, field.GetOption("attr").AsAttrs()) - } - - theme["textarea_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - return parent["field_attributes"](parent, args...) - } - - theme["input_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - return parent["field_attributes"](parent, args...) - } - - theme["sub_form_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - return parent["field_attributes"](parent, args...) - } - - theme["input"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - fieldType := "text" - - if field.HasOption("type") { - fieldType = field.GetOption("type").AsString() - } - - value := cast.ToString(field.Data) - - if fieldType == "checkbox" { - value = "1" - } - - return Input( - Name(field.GetName()), - ID(field.GetId()), - Type(fieldType), - Value(value), - If(fieldType == "checkbox" && field.Data != nil && field.Data != false, Checked()), - If(field.HasOption("required") && field.GetOption("required").AsBool(), Required()), - parent["input_attributes"](parent, field), - ) - } - - theme["choice_options"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - choices := field.GetOption("choices").Value.(*form.Choices) - - isRequired := field.HasOption("required") && field.GetOption("required").AsBool() - isMultiple := field.GetOption("multiple").AsBool() - - var options []Node - - if !isMultiple && !isRequired { - options = append(options, Option( - Text(field.GetOption("empty_choice_label").AsString()), - )) - } - - for _, choice := range choices.GetChoices() { - options = append(options, Option( - Value(choice.Value), - Text(choice.Label), - If(choices.Match(field, choice.Value), Selected()), - )) - } - - return Group(options) - } - - theme["choice_expanded_item"] = func(parent map[string]RenderFunc, args ...any) Node { - return args[0].(Node) - } - - theme["choice_attributes"] = func(parent map[string]RenderFunc, args ...any) Node { - return parent["field_attributes"](parent, args...) - } - - theme["choice_expanded"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - choices := field.GetOption("choices").Value.(*form.Choices) - - isRequired := field.HasOption("required") && field.GetOption("required").AsBool() - isMultiple := field.GetOption("multiple").AsBool() - noneLabel := field.GetOption("empty_choice_label").AsString() - - var items []Node - - if !isMultiple && !isRequired { - id := fmt.Sprintf("%s-%s", field.GetId(), "none") - - items = append(items, parent["choice_expanded_item"](parent, Group([]Node{ - Input( - Name(field.GetName()), - ID(id), - Value(""), - Type("radio"), - parent["choice_attributes"](parent, field), - If(cast.ToString(field.Data) == "", Checked()), - ), - Label( - For(id), - Text(noneLabel), - parent["label_attributes"](parent, field), - ), - }))) - } - - for key, choice := range choices.GetChoices() { - id := fmt.Sprintf("%s-%d", field.GetId(), key) - - items = append(items, parent["choice_expanded_item"](parent, Group([]Node{ - Input( - Name(field.GetName()), - ID(id), - Value(choice.Value), - If(isMultiple, Type("checkbox")), - If(!isMultiple, Type("radio")), - parent["choice_attributes"](parent, field), - If(choices.Match(field, choice.Value), Checked()), - ), - Label( - For(id), - Text(choice.Label), - parent["label_attributes"](parent, field), - ), - }))) - } - - return Group(items) - } - - theme["choice"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - isRequired := field.HasOption("required") && field.GetOption("required").AsBool() - isExpanded := field.GetOption("expanded").AsBool() - isMultiple := field.GetOption("multiple").AsBool() - noneLabel := field.GetOption("empty_choice_label").AsString() - - _ = noneLabel - - if isExpanded { - return parent["choice_expanded"](parent, field) - } else { - return Select( - ID(field.GetId()), - If(isRequired, Required()), - If(isMultiple, Multiple()), - Name(field.GetName()), - parent["choice_attributes"](parent, field), - parent["choice_options"](parent, field), - ) - } - } - - theme["textarea"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return Textarea( - Name(field.GetName()), - ID(field.GetId()), - If(field.HasOption("required") && field.GetOption("required").AsBool(), Required()), - parent["textarea_attributes"](parent, field), - Text(cast.ToString(field.Data)), - ) - } - - theme["sub_form_label"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - if !field.HasOption("label") { - return Raw("") - } - - label := field.GetOption("label").AsString() - - return If(len(label) > 0, Legend( - parent["label_attributes"](parent, field), - Text(label), - )) - - } - - theme["sub_form_content"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return parent["form_fields"](parent, field.Children) - } - - theme["sub_form"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - return FieldSet( - ID(field.GetId()), - parent["sub_form_label"](parent, field), - parent["sub_form_attributes"](parent, field), - parent["sub_form_content"](parent, field), - ) - } - - theme["collection"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - var prototype string - - if opt := field.GetOption("form"); opt != nil { - if val, ok := opt.Value.(*form.Form); ok { - var buffer bytes.Buffer - dest := form.NewFieldSubForm(field.Name) - - for _, c := range val.Fields { - child := c.Copy() - child.NamePrefix = "[__name__]" - dest.Add(child) - } - - fieldPrototype := parent["form_row"](parent, dest) - fieldPrototype.Render(&buffer) - - prototype = buffer.String() - } - } - - field.WithOptions(form.NewOption("prototype", prototype)) - field.Widget = "collection_build" - - return parent["form_widget"](parent, field) - } - - theme["collection_build"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - prototype := field.GetOption("prototype").AsString() - var items []Node - - for _, child := range field.Children { - items = append(items, parent["form_row"](parent, child)) - } - - return Div( - Attr("data-prototype", prototype), - Group(items), - ) - } - - theme["form_widget"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - tpl, ok := parent[field.Widget] - - if !ok { - return Raw("Invalid field widget: " + field.Widget) - } - - return tpl(parent, field) - } - - theme["form_row"] = func(parent map[string]RenderFunc, args ...any) Node { - field := args[0].(*form.Field) - - isCheckbox := field.HasOption("type") && field.GetOption("type").AsString() == "checkbox" - hasChildren := len(field.Children) > 0 - labelAfter := isCheckbox && !hasChildren - label := parent["form_label"](parent, field) - attrs := Raw("") - - if field.HasOption("row_attr") { - attrs = parent["attributes"](parent, field.GetOption("row_attr").AsAttrs()) - } - - return Div( - attrs, - If(!labelAfter, label), - parent["form_widget_errors"](parent, field), - parent["form_widget"](parent, field), - If(labelAfter, label), - parent["form_widget_help"](parent, field), - ) - } - - theme["form_fields"] = func(parent map[string]RenderFunc, args ...any) Node { - var items []Node - - for _, item := range args[0].([]*form.Field) { - items = append(items, parent["form_row"](parent, item)) - } - - return Group(items) - } - - theme["form_content"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - return Group([]Node{ - parent["form_errors"](parent, form), - parent["form_help"](parent, form), - parent["form_fields"](parent, form.Fields), - }) - } - - theme["form"] = func(parent map[string]RenderFunc, args ...any) Node { - form := args[0].(*form.Form) - - return Form( - Class("gf-form"), - Action(form.Action), - Method(form.Method), - parent["form_attributes"](parent, form), - parent["form_content"](parent, form), - ) - } - - return theme -}) diff --git a/theme/renderer.go b/theme/renderer.go deleted file mode 100644 index d90b7b7..0000000 --- a/theme/renderer.go +++ /dev/null @@ -1,84 +0,0 @@ -package theme - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "bytes" - "html/template" - - "gitnet.fr/deblan/go-form/form" - "maragu.dev/gomponents" -) - -type RenderFunc func(parent map[string]RenderFunc, args ...any) gomponents.Node - -type Renderer struct { - Theme map[string]RenderFunc -} - -func NewRenderer(theme map[string]RenderFunc) *Renderer { - r := new(Renderer) - r.Theme = theme - - return r -} - -func toTemplateHtml(n gomponents.Node) template.HTML { - var buf bytes.Buffer - - n.Render(&buf) - - return template.HTML(buf.String()) -} - -func (r *Renderer) RenderForm(form *form.Form) template.HTML { - return toTemplateHtml(r.Theme["form"](r.Theme, form)) -} - -func (r *Renderer) FuncMap() template.FuncMap { - funcs := template.FuncMap{} - - for _, name := range []string{"form", "form_errors"} { - funcs[name] = func(form *form.Form) template.HTML { - return toTemplateHtml(r.Theme[name](r.Theme, form)) - } - } - - for _, name := range []string{"form_row", "form_widget", "form_label", "form_widget_errors"} { - funcs[name] = func(field *form.Field) template.HTML { - return toTemplateHtml(r.Theme[name](r.Theme, field)) - } - } - - return funcs -} - -func (r *Renderer) Render(name, tpl string, args any) template.HTML { - t, err := template.New(name).Funcs(r.FuncMap()).Parse(tpl) - - if err != nil { - return template.HTML(err.Error()) - } - - var buf bytes.Buffer - err = t.Execute(&buf, args) - - if err != nil { - return template.HTML(err.Error()) - } - - return template.HTML(buf.String()) -} diff --git a/theme/theme.go b/theme/theme.go deleted file mode 100644 index 9416346..0000000 --- a/theme/theme.go +++ /dev/null @@ -1,21 +0,0 @@ -package theme - -func CreateTheme(generator func() map[string]RenderFunc) map[string]RenderFunc { - return generator() -} - -func ExtendTheme(base map[string]RenderFunc, generator func() map[string]RenderFunc) map[string]RenderFunc { - extended := CreateTheme(generator) - - for i, v := range base { - _, ok := extended[i] - - if ok { - extended["base_"+i] = v - } else { - extended[i] = v - } - } - - return extended -} diff --git a/util/collection.go b/util/collection.go deleted file mode 100644 index f0aa649..0000000 --- a/util/collection.go +++ /dev/null @@ -1,111 +0,0 @@ -package util - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "regexp" - "strings" - - "github.com/spf13/cast" -) - -type CollectionValue struct { - Name string - Value string - Children map[string]*CollectionValue -} - -type Collection struct { - Children map[int]*CollectionValue -} - -func NewCollection() *Collection { - return &Collection{ - Children: make(map[int]*CollectionValue), - } -} - -func NewCollectionValue(name string) *CollectionValue { - return &CollectionValue{ - Name: name, - Children: make(map[string]*CollectionValue), - } -} - -func (c *Collection) Add(indexes []string, value string) { - firstIndex := cast.ToInt(indexes[0]) - size := len(indexes) - child := c.Children[firstIndex] - - if child == nil { - child = NewCollectionValue(indexes[0]) - c.Children[firstIndex] = child - } - - child.Add(indexes[1:size], value, nil) -} - -func (c *Collection) Slice() []any { - var result []any - - for _, child := range c.Children { - result = append(result, child.Map()) - } - - return result -} - -func (c *CollectionValue) Map() any { - if len(c.Children) == 0 { - return c.Value - } - - results := make(map[string]any) - - for _, child := range c.Children { - results[child.Name] = child.Map() - } - - return results -} - -func (c *CollectionValue) Add(indexes []string, value string, lastChild *CollectionValue) { - size := len(indexes) - - if size > 0 { - firstIndex := indexes[0] - child := c.Children[firstIndex] - - child = NewCollectionValue(indexes[0]) - c.Children[firstIndex] = child - - child.Add(indexes[1:size], value, child) - } else { - lastChild.Value = value - } -} - -func ExtractDataIndexes(value string) []string { - re := regexp.MustCompile(`\[[^\]]+\]`) - items := re.FindAll([]byte(value), -1) - var results []string - - for _, i := range items { - results = append(results, strings.Trim(string(i), "[]")) - } - - return results -} diff --git a/util/inspect.go b/util/inspect.go deleted file mode 100644 index 22fa4f4..0000000 --- a/util/inspect.go +++ /dev/null @@ -1,59 +0,0 @@ -package util - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "errors" - "reflect" - - "github.com/iancoleman/strcase" -) - -func InspectStruct(input interface{}) (map[string]interface{}, error) { - val := reflect.ValueOf(input) - - if val.Kind() == reflect.Ptr { - val = val.Elem() - } - - if val.Kind() == reflect.Map { - return input.(map[string]interface{}), nil - } - - if val.Kind() != reflect.Struct { - return nil, errors.New("Invalid type") - } - - result := make(map[string]interface{}) - - typ := val.Type() - for i := 0; i < val.NumField(); i++ { - field := typ.Field(i) - value := val.Field(i) - tags := typ.Field(i).Tag - name := field.Name - - fieldTag := tags.Get("field") - - if fieldTag == "lowerCamel" { - name = strcase.ToLowerCamel(name) - } - - result[name] = value.Interface() - } - - return result, nil -} diff --git a/util/transformer.go b/util/transformer.go deleted file mode 100644 index a942fa1..0000000 --- a/util/transformer.go +++ /dev/null @@ -1,57 +0,0 @@ -package util - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "fmt" - "net/url" -) - -func MapToUrlValues(values *url.Values, prefix string, data map[string]any) { - keyFormater := "%s" - - if prefix != "" { - keyFormater = prefix + "[%s]" - } - - for key, value := range data { - keyValue := fmt.Sprintf(keyFormater, key) - - switch v := value.(type) { - case string: - values.Add(keyValue, v) - case []string: - case []int: - case []int32: - case []int64: - case []any: - for _, s := range v { - values.Add(keyValue, fmt.Sprintf("%v", s)) - } - case bool: - if v { - values.Add(keyValue, "1") - } else { - values.Add(keyValue, "0") - } - case int, int64, float64: - values.Add(keyValue, fmt.Sprintf("%v", v)) - case map[string]any: - MapToUrlValues(values, keyValue, v) - default: - } - } -} diff --git a/validation/constraint.go b/validation/constraint.go deleted file mode 100644 index 8854921..0000000 --- a/validation/constraint.go +++ /dev/null @@ -1,20 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -type Constraint interface { - Validate(data any) []Error -} diff --git a/validation/error.go b/validation/error.go deleted file mode 100644 index f73d341..0000000 --- a/validation/error.go +++ /dev/null @@ -1,18 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -type Error string diff --git a/validation/iseven.go b/validation/iseven.go deleted file mode 100644 index 306cae2..0000000 --- a/validation/iseven.go +++ /dev/null @@ -1,34 +0,0 @@ -package validation - -import ( - "strconv" -) - -type IsEven struct { - Message string - TypeErrorMessage string -} - -func NewIsEven() IsEven { - return IsEven{ - Message: "This value is not an even number.", - TypeErrorMessage: "This value can not be processed.", - } -} - -func (c IsEven) Validate(data any) []Error { - errors := []Error{} - - // The constraint should not validate an empty data - if len(NewNotBlank().Validate(data)) == 0 { - i, err := strconv.Atoi(data.(string)) - - if err != nil { - errors = append(errors, Error(c.TypeErrorMessage)) - } else if i%2 != 0 { - errors = append(errors, Error(c.Message)) - } - } - - return errors -} diff --git a/validation/isodd.go b/validation/isodd.go deleted file mode 100644 index d7e3b53..0000000 --- a/validation/isodd.go +++ /dev/null @@ -1,34 +0,0 @@ -package validation - -import ( - "strconv" -) - -type IsOdd struct { - Message string - TypeErrorMessage string -} - -func NewIsOdd() IsOdd { - return IsOdd{ - Message: "This value is not a odd number.", - TypeErrorMessage: "This value can not be processed.", - } -} - -func (c IsOdd) Validate(data any) []Error { - errors := []Error{} - - // The constraint should not validate an empty data - if len(NewNotBlank().Validate(data)) == 0 { - i, err := strconv.Atoi(data.(string)) - - if err != nil { - errors = append(errors, Error(c.TypeErrorMessage)) - } else if i%2 != 1 { - errors = append(errors, Error(c.Message)) - } - } - - return errors -} diff --git a/validation/length.go b/validation/length.go deleted file mode 100644 index 66d5a1f..0000000 --- a/validation/length.go +++ /dev/null @@ -1,110 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "reflect" - "strings" - - "github.com/spf13/cast" -) - -type Length struct { - Min *int - Max *int - MinMessage string - MaxMessage string - ExactMessage string - TypeErrorMessage string -} - -func NewLength() Length { - return Length{ - MinMessage: "This value is too short (min: {{ min }}).", - MaxMessage: "This value is too long (max: {{ max }}).", - ExactMessage: "This value is not valid (expected: {{ min }}).", - TypeErrorMessage: "This value can not be processed.", - } -} - -func (c Length) WithMin(v int) Length { - c.Min = &v - - return c -} - -func (c Length) WithMax(v int) Length { - c.Max = &v - - return c -} - -func (c Length) WithExact(v int) Length { - c.Min = &v - c.Max = &v - - return c -} - -func (c Length) Validate(data any) []Error { - if (c.Min == nil && c.Max == nil) || len(NewNotBlank().Validate(data)) != 0 { - return []Error{} - } - - errors := []Error{} - - t := reflect.TypeOf(data) - - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - var size *int - - switch t.Kind() { - case reflect.Array: - case reflect.Slice: - s := reflect.ValueOf(data).Len() - size = &s - case reflect.String: - s := len(data.(string)) - size = &s - - default: - errors = append(errors, Error(c.TypeErrorMessage)) - } - - if size != nil { - if c.Max != nil && c.Min != nil { - if *c.Max == *c.Min && *size != *c.Max { - errors = append(errors, Error(c.BuildMessage(c.ExactMessage))) - } - } else if c.Min != nil && *size < *c.Min { - errors = append(errors, Error(c.BuildMessage(c.MinMessage))) - } else if c.Max != nil && *size > *c.Max { - errors = append(errors, Error(c.BuildMessage(c.MaxMessage))) - } - } - - return errors -} - -func (c *Length) BuildMessage(message string) string { - message = strings.ReplaceAll(message, "{{ min }}", cast.ToString(c.Min)) - message = strings.ReplaceAll(message, "{{ max }}", cast.ToString(c.Max)) - - return message -} diff --git a/validation/mail.go b/validation/mail.go deleted file mode 100644 index 136ee6d..0000000 --- a/validation/mail.go +++ /dev/null @@ -1,42 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import "net/mail" - -type Mail struct { - Message string -} - -func NewMail() Mail { - return Mail{ - Message: "This value is not a valid email address.", - } -} - -func (c Mail) Validate(data any) []Error { - errors := []Error{} - - if len(NewNotBlank().Validate(data)) == 0 { - _, err := mail.ParseAddress(data.(string)) - - if err != nil { - errors = append(errors, Error(c.Message)) - } - } - - return errors -} diff --git a/validation/notblank.go b/validation/notblank.go deleted file mode 100644 index 1962cb2..0000000 --- a/validation/notblank.go +++ /dev/null @@ -1,84 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "reflect" - - "github.com/spf13/cast" -) - -type NotBlank struct { - Message string - TypeErrorMessage string -} - -func NewNotBlank() NotBlank { - return NotBlank{ - Message: "This value should not be blank.", - TypeErrorMessage: "This value can not be processed.", - } -} - -func (c NotBlank) Validate(data any) []Error { - isValid := true - errors := []Error{} - - v := reflect.ValueOf(data) - - if data == nil || v.IsZero() { - errors = append(errors, Error(c.Message)) - - return errors - } - - t := reflect.TypeOf(data) - - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - switch t.Kind() { - case reflect.Bool: - isValid = data == false - case reflect.Array: - case reflect.Slice: - isValid = reflect.ValueOf(data).Len() > 0 - case reflect.String: - isValid = len(data.(string)) > 0 - case reflect.Float32: - case reflect.Float64: - case reflect.Int: - case reflect.Int16: - case reflect.Int32: - case reflect.Int64: - case reflect.Int8: - case reflect.Uint: - case reflect.Uint16: - case reflect.Uint32: - case reflect.Uint64: - case reflect.Uint8: - isValid = cast.ToFloat64(data.(string)) == float64(0) - default: - errors = append(errors, Error(c.TypeErrorMessage)) - } - - if !isValid { - errors = append(errors, Error(c.Message)) - } - - return errors -} diff --git a/validation/range.go b/validation/range.go deleted file mode 100644 index ccb95b0..0000000 --- a/validation/range.go +++ /dev/null @@ -1,117 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "reflect" - "strings" - - "github.com/spf13/cast" -) - -type Range struct { - Min *float64 - Max *float64 - MinMessage string - MaxMessage string - RangeMessage string - TypeErrorMessage string -} - -func NewRange() Range { - return Range{ - MinMessage: "This value must be greater than or equal to {{ min }}.", - MaxMessage: "This value must be less than or equal to {{ max }}.", - RangeMessage: "This value should be between {{ min }} and {{ max }}.", - TypeErrorMessage: "This value can not be processed.", - } -} - -func (c Range) WithMin(v float64) Range { - c.Min = &v - - return c -} - -func (c Range) WithMax(v float64) Range { - c.Max = &v - - return c -} - -func (c Range) WithRange(vMin, vMax float64) Range { - c.Min = &vMin - c.Max = &vMax - - return c -} - -func (c Range) Validate(data any) []Error { - if c.Min == nil && c.Max == nil || len(NewNotBlank().Validate(data)) != 0 { - return []Error{} - } - - errors := []Error{} - - t := reflect.TypeOf(data) - - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - switch t.Kind() { - case reflect.Float32: - case reflect.Float64: - case reflect.Int: - case reflect.Int16: - case reflect.Int32: - case reflect.Int64: - case reflect.Int8: - case reflect.Uint: - case reflect.Uint16: - case reflect.Uint32: - case reflect.Uint64: - case reflect.Uint8: - case reflect.String: - isValidMin := c.Min == nil || *c.Min <= cast.ToFloat64(data.(string)) - isValidMax := c.Max == nil || *c.Max >= cast.ToFloat64(data.(string)) - - if !isValidMin || !isValidMax { - errors = append(errors, Error(c.BuildMessage())) - } - default: - errors = append(errors, Error(c.TypeErrorMessage)) - } - - return errors -} - -func (c *Range) BuildMessage() string { - var message string - - if c.Min != nil && c.Max == nil { - message = c.MinMessage - } else if c.Max != nil && c.Min == nil { - message = c.MaxMessage - } else { - message = c.RangeMessage - } - - message = strings.ReplaceAll(message, "{{ min }}", cast.ToString(c.Min)) - message = strings.ReplaceAll(message, "{{ max }}", cast.ToString(c.Max)) - - return message -} diff --git a/validation/regex.go b/validation/regex.go deleted file mode 100644 index 28815b1..0000000 --- a/validation/regex.go +++ /dev/null @@ -1,75 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import ( - "reflect" - "regexp" -) - -type Regex struct { - Message string - TypeErrorMessage string - Match bool - Expression string -} - -func NewRegex(expr string) Regex { - return Regex{ - Message: "This value is not valid.", - TypeErrorMessage: "This value can not be processed.", - Match: true, - Expression: expr, - } -} - -func (c Regex) MustMatch() Regex { - c.Match = true - - return c -} - -func (c Regex) MustNotMatch() Regex { - c.Match = false - - return c -} - -func (c Regex) Validate(data any) []Error { - errors := []Error{} - - if len(NewNotBlank().Validate(data)) == 0 { - t := reflect.TypeOf(data) - - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - switch t.Kind() { - case reflect.String: - matched, _ := regexp.MatchString(c.Expression, data.(string)) - - if !matched && c.Match || matched && !c.Match { - errors = append(errors, Error(c.Message)) - } - - default: - errors = append(errors, Error(c.TypeErrorMessage)) - } - } - - return errors -} diff --git a/validation/validation.go b/validation/validation.go deleted file mode 100644 index 97dfd17..0000000 --- a/validation/validation.go +++ /dev/null @@ -1,28 +0,0 @@ -package validation - -// @license GNU AGPL version 3 or any later version -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -func Validate(data any, constraints []Constraint) (bool, []Error) { - errs := []Error{} - - for _, constraint := range constraints { - for _, e := range constraint.Validate(data) { - errs = append(errs, e) - } - } - - return len(errs) == 0, errs -}