about summary refs log tree commit diff stats
path: root/src/html/enums.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-19 16:11:37 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-19 16:11:37 +0200
commite8da184531c774a6388576dab3dbe4182eab9473 (patch)
treefe4fa9f0135c3f946341bfe38b26d547c329b385 /src/html/enums.nim
parentda019595a59a0bfa9d82e0faea915f7d739aa01b (diff)
downloadchawan-e8da184531c774a6388576dab3dbe4182eab9473.tar.gz
update chame
and with that, resolve the unknown input type issue
Diffstat (limited to 'src/html/enums.nim')
-rw-r--r--src/html/enums.nim44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/html/enums.nim b/src/html/enums.nim
new file mode 100644
index 00000000..54de6af6
--- /dev/null
+++ b/src/html/enums.nim
@@ -0,0 +1,44 @@
+import strutils
+import tables
+
+import chame/tags
+
+type
+  InputType* = enum
+    INPUT_TEXT, INPUT_BUTTON, INPUT_CHECKBOX, INPUT_COLOR, INPUT_DATE,
+    INPUT_DATETIME_LOCAL, INPUT_EMAIL, INPUT_FILE, INPUT_HIDDEN, INPUT_IMAGE,
+    INPUT_MONTH, INPUT_NUMBER, INPUT_PASSWORD, INPUT_RADIO, INPUT_RANGE,
+    INPUT_RESET, INPUT_SEARCH, INPUT_SUBMIT, INPUT_TEL, INPUT_TIME, INPUT_URL,
+    INPUT_WEEK
+
+  ButtonType* = enum
+    BUTTON_SUBMIT, BUTTON_RESET, BUTTON_BUTTON
+
+#TODO support all the other ones
+const SupportedFormAssociatedElements* = {
+  TAG_BUTTON, TAG_INPUT, TAG_SELECT, TAG_TEXTAREA
+}
+
+const InputTypeWithSize* = {
+  INPUT_SEARCH, INPUT_TEXT, INPUT_EMAIL, INPUT_PASSWORD, INPUT_URL, INPUT_TEL
+}
+
+const AutocapitalizeInheritingElements* = {
+  TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA
+}
+
+const LabelableElements* = {
+  # input only if type not hidden
+  TAG_BUTTON, TAG_INPUT, TAG_METER, TAG_OUTPUT, TAG_PROGRESS, TAG_SELECT, TAG_TEXTAREA
+}
+
+func getInputTypeMap(): Table[string, InputType] =
+  for i in InputType:
+    let enumname = $InputType(i)
+    let tagname = enumname.split('_')[1..^1].join("_").toLowerAscii()
+    result[tagname] = InputType(i)
+
+const inputTypeMap = getInputTypeMap()
+
+func inputType*(s: string): InputType =
+  return inputTypeMap.getOrDefault(s.toLowerAscii())