Commit 86254ce5 authored by Steffen Michels's avatar Steffen Michels

dynamic editors: make it possible to tune dynamic conses with arbitrary CSS classes

parent 4b14c990
Pipeline #22652 passed with stage
in 9 minutes and 49 seconds
...@@ -13,7 +13,7 @@ derive class iTask DynamicEditorValue ...@@ -13,7 +13,7 @@ derive class iTask DynamicEditorValue
:: DynamicEditorElement = DynamicCons !DynamicCons | DynamicConsGroup !String ![DynamicCons] :: DynamicEditorElement = DynamicCons !DynamicCons | DynamicConsGroup !String ![DynamicCons]
:: DynamicCons :: DynamicCons
:: DynamicConsOption = HideIfOnlyChoice | UseAsDefault | LayoutVertical :: DynamicConsOption = HideIfOnlyChoice | UseAsDefault | ApplyCssClasses ![String]
(<<@@@) infixl 2 :: !DynamicCons !DynamicConsOption -> DynamicCons (<<@@@) infixl 2 :: !DynamicCons !DynamicConsOption -> DynamicCons
(@@@>>) infixr 2 :: !DynamicConsOption !DynamicCons -> DynamicCons (@@@>>) infixr 2 :: !DynamicConsOption !DynamicCons -> DynamicCons
......
...@@ -28,7 +28,8 @@ import Data.Functor ...@@ -28,7 +28,8 @@ import Data.Functor
tunedDynamicConsEditor :: !DynamicConsOption !DynamicCons -> DynamicCons tunedDynamicConsEditor :: !DynamicConsOption !DynamicCons -> DynamicCons
tunedDynamicConsEditor HideIfOnlyChoice cons = {cons & showIfOnlyChoice = False} tunedDynamicConsEditor HideIfOnlyChoice cons = {cons & showIfOnlyChoice = False}
tunedDynamicConsEditor UseAsDefault cons = {cons & useAsDefault = True} tunedDynamicConsEditor UseAsDefault cons = {cons & useAsDefault = True}
tunedDynamicConsEditor LayoutVertical cons = {cons & uiAttributes = 'Map'.union (classAttr ["itasks-vertical"]) cons.uiAttributes} tunedDynamicConsEditor (ApplyCssClasses classes) cons
= {cons & uiAttributes = 'Map'.union (classAttr classes) cons.uiAttributes}
functionCons :: !String !String !a -> DynamicCons | TC a functionCons :: !String !String !a -> DynamicCons | TC a
functionCons consId label func = functionConsDyn consId label (dynamic func) functionCons consId label func = functionConsDyn consId label (dynamic func)
...@@ -309,7 +310,7 @@ where ...@@ -309,7 +310,7 @@ where
# (E editor) = children !! argIdx # (E editor) = children !! argIdx
= editor.Editor.onEdit (dp ++ [argIdx]) (tp, e) (childSts !! (argIdx + 1)) vst = editor.Editor.onEdit (dp ++ [argIdx]) (tp, e) (childSts !! (argIdx + 1)) vst
ListCons lbuilder ListCons lbuilder
= (listBuilderEditor lbuilder).Editor.onEdit (dp ++ [0]) (tp, e) (childSts !! 1) vst = (listBuilderEditor lbuilder cons.uiAttributes).Editor.onEdit (dp ++ [0]) (tp, e) (childSts !! 1) vst
CustomEditorCons editor CustomEditorCons editor
= editor.Editor.onEdit (dp ++ [0]) (tp, e) (childSts !! 1) vst = editor.Editor.onEdit (dp ++ [0]) (tp, e) (childSts !! 1) vst
= case res of = case res of
...@@ -369,7 +370,7 @@ where ...@@ -369,7 +370,7 @@ where
_ = repeat Nothing _ = repeat Nothing
ListCons lbuilder ListCons lbuilder
# listEditorMode = mapEditMode (\(DEApplication listElems) -> listElems) mode # listEditorMode = mapEditMode (\(DEApplication listElems) -> listElems) mode
# (mbUi, vst) = (listBuilderEditor lbuilder).Editor.genUI cons.uiAttributes (dp ++ [0]) listEditorMode vst # (mbUi, vst) = (listBuilderEditor lbuilder cons.uiAttributes).Editor.genUI 'Map'.newMap (dp ++ [0]) listEditorMode vst
= ((\(ui, st) -> ([ui], [st])) <$> mbUi, idx, type, cons.DynamicCons.label, vst) = ((\(ui, st) -> ([ui], [st])) <$> mbUi, idx, type, cons.DynamicCons.label, vst)
CustomEditorCons editor CustomEditorCons editor
# editorMode = mapEditMode # editorMode = mapEditMode
...@@ -429,8 +430,8 @@ where ...@@ -429,8 +430,8 @@ where
(f :: [a] -> b, _ :: DynamicEditor b) = Just $ ListCons (dynamic f) (f :: [a] -> b, _ :: DynamicEditor b) = Just $ ListCons (dynamic f)
_ = Nothing _ = Nothing
listBuilderEditor :: !Dynamic -> Editor [(!DynamicConsId, !DEVal)] listBuilderEditor :: !Dynamic !UIAttributes -> Editor [(!DynamicConsId, !DEVal)]
listBuilderEditor (lbuilder :: [a] -> b) = listEditor (Just $ const Nothing) True True Nothing childrenEd` listBuilderEditor (lbuilder :: [a] -> b) attrs = listEditor (Just $ const Nothing) True True Nothing childrenEd`
where where
childrenEd = childrenEditorList lbuilder childrenEd = childrenEditorList lbuilder
childrenEd` = bijectEditorValue (\(cid, val) -> DynamicEditorValue cid val) childrenEd` = bijectEditorValue (\(cid, val) -> DynamicEditorValue cid val)
...@@ -439,14 +440,11 @@ where ...@@ -439,14 +440,11 @@ where
// first argument only used for type // first argument only used for type
childrenEditorList :: ([a] -> b) -> Editor (DynamicEditorValue a) | TC a childrenEditorList :: ([a] -> b) -> Editor (DynamicEditorValue a) | TC a
childrenEditorList _ = dynamicEditor $ DynamicEditor elements childrenEditorList _ = dynamicEditor (DynamicEditor elements) <<@ attrs
listBuilderEditor _ = abort "dynamic editors: invalid list builder value" listBuilderEditor _ _ = abort "dynamic editors: invalid list builder value"
uiContainer :: !UIAttributes ![UI] -> UI uiContainer :: !UIAttributes ![UI] -> UI
uiContainer attr uis = uiContainer attr uis = UI UIContainer attr uis
UI UIContainer
('Map'.union attr $ 'Map'.fromList [("direction", JSONString "horizontal"), ("width", JSONString "wrap")])
uis
valueFromState :: !(Maybe (!DynamicConsId, !ConsType)) ![EditState] -> *Maybe (DynamicEditorValue a) valueFromState :: !(Maybe (!DynamicConsId, !ConsType)) ![EditState] -> *Maybe (DynamicEditorValue a)
valueFromState (Just (cid, CustomEditor)) [_: [editorSt]] = valueFromState (Just (cid, CustomEditor)) [_: [editorSt]] =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment