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
:: DynamicEditorElement = DynamicCons !DynamicCons | DynamicConsGroup !String ![DynamicCons]
:: DynamicCons
:: DynamicConsOption = HideIfOnlyChoice | UseAsDefault | LayoutVertical
:: DynamicConsOption = HideIfOnlyChoice | UseAsDefault | ApplyCssClasses ![String]
(<<@@@) infixl 2 :: !DynamicCons !DynamicConsOption -> DynamicCons
(@@@>>) infixr 2 :: !DynamicConsOption !DynamicCons -> DynamicCons
......
......@@ -28,7 +28,8 @@ import Data.Functor
tunedDynamicConsEditor :: !DynamicConsOption !DynamicCons -> DynamicCons
tunedDynamicConsEditor HideIfOnlyChoice cons = {cons & showIfOnlyChoice = False}
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 consId label func = functionConsDyn consId label (dynamic func)
......@@ -309,7 +310,7 @@ where
# (E editor) = children !! argIdx
= editor.Editor.onEdit (dp ++ [argIdx]) (tp, e) (childSts !! (argIdx + 1)) vst
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
= editor.Editor.onEdit (dp ++ [0]) (tp, e) (childSts !! 1) vst
= case res of
......@@ -369,7 +370,7 @@ where
_ = repeat Nothing
ListCons lbuilder
# 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)
CustomEditorCons editor
# editorMode = mapEditMode
......@@ -429,8 +430,8 @@ where
(f :: [a] -> b, _ :: DynamicEditor b) = Just $ ListCons (dynamic f)
_ = Nothing
listBuilderEditor :: !Dynamic -> Editor [(!DynamicConsId, !DEVal)]
listBuilderEditor (lbuilder :: [a] -> b) = listEditor (Just $ const Nothing) True True Nothing childrenEd`
listBuilderEditor :: !Dynamic !UIAttributes -> Editor [(!DynamicConsId, !DEVal)]
listBuilderEditor (lbuilder :: [a] -> b) attrs = listEditor (Just $ const Nothing) True True Nothing childrenEd`
where
childrenEd = childrenEditorList lbuilder
childrenEd` = bijectEditorValue (\(cid, val) -> DynamicEditorValue cid val)
......@@ -439,14 +440,11 @@ where
// first argument only used for type
childrenEditorList :: ([a] -> b) -> Editor (DynamicEditorValue a) | TC a
childrenEditorList _ = dynamicEditor $ DynamicEditor elements
listBuilderEditor _ = abort "dynamic editors: invalid list builder value"
childrenEditorList _ = dynamicEditor (DynamicEditor elements) <<@ attrs
listBuilderEditor _ _ = abort "dynamic editors: invalid list builder value"
uiContainer :: !UIAttributes ![UI] -> UI
uiContainer attr uis =
UI UIContainer
('Map'.union attr $ 'Map'.fromList [("direction", JSONString "horizontal"), ("width", JSONString "wrap")])
uis
uiContainer attr uis = UI UIContainer attr uis
valueFromState :: !(Maybe (!DynamicConsId, !ConsType)) ![EditState] -> *Maybe (DynamicEditorValue a)
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