Skip to content

Commit 062a800

Browse files
committed
Add rich text field
1 parent 7f6ba36 commit 062a800

12 files changed

Lines changed: 2401 additions & 118 deletions

File tree

app-wizard/elm/Wizard/Components/Questionnaire2/Components/QuestionnaireContent.elm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Common.Components.DatePicker as DatePicker
1919
import Common.Components.FileDownloader as FileDownloader
2020
import Common.Components.Flash as Flash
2121
import Common.Components.FontAwesome exposing (fa, faAdd, faDelete, faError, faInfo, faKmQuestion, faNext, faPrev, faQuestionnaireClearAnswer, faQuestionnaireComments, faQuestionnaireCopyLink, faQuestionnaireDesirable, faQuestionnaireExperts, faQuestionnaireFollowUpsIndication, faQuestionnaireItemCollapse, faQuestionnaireItemCollapseAll, faQuestionnaireItemExpand, faQuestionnaireItemExpandAll, faQuestionnaireItemMoveDown, faQuestionnaireItemMoveUp, faQuestionnaireResourcePageReferences, faQuestionnaireUrlReferences, faRemove, faSearch, faSpinner)
22+
import Common.Components.MarkdownEditor as MarkdownEditor
2223
import Common.Components.Modal as Modal
2324
import Common.Components.Tooltip exposing (tooltip, tooltipLeft, tooltipRight)
2425
import Common.Ports.Copy as Copy
@@ -76,7 +77,6 @@ import Wizard.Api.Models.TypeHintRequest as TypeHintRequest
7677
import Wizard.Api.Models.User as User
7778
import Wizard.Api.ProjectFiles as ProjectFilesApi
7879
import Wizard.Api.TypeHints as TypeHintsApi
79-
import Wizard.Components.Html exposing (resizableTextarea)
8080
import Wizard.Components.Questionnaire2.Components.FileUploadModal as FileUploadModal
8181
import Wizard.Components.Questionnaire2.QuestionViewFlags as QuestionViewFlags
8282
import Wizard.Components.Questionnaire2.QuestionnaireRightPanel as QuestionnaireRightPanel exposing (PluginQuestionActionData, QuestionnaireRightPanel)
@@ -1668,8 +1668,18 @@ viewQuestionValueLazy locale pluginActions questionNodeData questionViewFlags re
16681668
]
16691669

16701670
Just QuestionValueType.TextQuestionValueType ->
1671-
[ resizableTextarea 3 replyValue (defaultAttrs ++ extraAttrs) [] ]
1671+
if isReadOnly then
1672+
[ Markdown.toHtml [ class "form-control bg-light text-secondary" ] replyValue ]
16721673

1674+
else
1675+
[ MarkdownEditor.markdownEditor
1676+
[ MarkdownEditor.value replyValue
1677+
, MarkdownEditor.onChange toMsg
1678+
, MarkdownEditor.labels locale
1679+
]
1680+
]
1681+
1682+
--[ resizableTextarea 3 replyValue (defaultAttrs ++ extraAttrs) [] ]
16731683
Just QuestionValueType.ColorQuestionValueType ->
16741684
[ input (type_ "color" :: defaultAttrs ++ extraAttrs) []
16751685
, warningView RegexPatterns.color (gettext "This is not a valid color." locale)

app-wizard/elm/Wizard/Pages/KMEditor/Editor/Components/KMEditor.elm

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ import Wizard.Utils.WizardGuideLinks as WizardGuideLinks
139139

140140
type alias Model =
141141
{ splitPane : SplitPane.State
142-
, markdownPreviews : List String
142+
, editorPreviews : List String
143143
, reorderableStates : Dict String Reorderable.State
144144
, deleteModalState : DeleteModalState
145145
, moveModalState : Maybe MoveModalState
@@ -191,7 +191,7 @@ type alias CurlImportModalState =
191191
initialModel : Model
192192
initialModel =
193193
{ splitPane = SplitPane.init SplitPane.Horizontal |> SplitPane.configureSplitter (SplitPane.percentage 0.2 (Just ( 0.05, 0.7 )))
194-
, markdownPreviews = []
194+
, editorPreviews = []
195195
, reorderableStates = Dict.empty
196196
, deleteModalState = Closed
197197
, moveModalState = Nothing
@@ -263,10 +263,10 @@ update appState cfg msg ( editorContext, model ) =
263263
let
264264
showHideMarkdownPreview visible field m =
265265
if visible then
266-
{ m | markdownPreviews = field :: m.markdownPreviews }
266+
{ m | editorPreviews = field :: m.editorPreviews }
267267

268268
else
269-
{ m | markdownPreviews = List.filter ((/=) field) m.markdownPreviews }
269+
{ m | editorPreviews = List.filter ((/=) field) m.editorPreviews }
270270
in
271271
case msg of
272272
SplitPaneMsg splitPaneMsg ->
@@ -478,7 +478,7 @@ update appState cfg msg ( editorContext, model ) =
478478
newModel =
479479
{ model
480480
| curlImportModalState = { integrationUuid = Nothing, curlString = "" }
481-
, markdownPreviews = (integrationUuid ++ ":requestAdvancedConfiguration") :: model.markdownPreviews
481+
, editorPreviews = (integrationUuid ++ ":requestAdvancedConfiguration") :: model.editorPreviews
482482
}
483483
in
484484
( editorContext, newModel, Task.dispatch setRequestBodyMsg )
@@ -1027,7 +1027,6 @@ viewChapterEditor { appState, wrapMsg, eventMsg, model, editorContext } chapter
10271027
, onInput = createEditEvent setText << String.toMaybe
10281028
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
10291029
, entityUuid = chapter.uuid
1030-
, markdownPreviews = model.markdownPreviews
10311030
}
10321031

10331032
questionsInput =
@@ -1258,7 +1257,6 @@ viewQuestionEditor { appState, wrapMsg, eventMsg, model, editorContext } questio
12581257
, onInput = createEditEvent setText setText setText setText setText setText setText << String.toMaybe
12591258
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
12601259
, entityUuid = questionUuid
1261-
, markdownPreviews = model.markdownPreviews
12621260
}
12631261

12641262
requiredPhaseUuidInput =
@@ -1689,7 +1687,7 @@ viewQuestionEditor { appState, wrapMsg, eventMsg, model, editorContext } questio
16891687

16901688

16911689
viewMetricEditor : EditorConfig msg -> Metric -> Html msg
1692-
viewMetricEditor { appState, wrapMsg, eventMsg, model, editorContext } metric =
1690+
viewMetricEditor { appState, wrapMsg, eventMsg, editorContext } metric =
16931691
let
16941692
parentUuid =
16951693
EditorContext.getParentUuid metric.uuid editorContext
@@ -1738,7 +1736,6 @@ viewMetricEditor { appState, wrapMsg, eventMsg, model, editorContext } metric =
17381736
, onInput = createEditEvent setDescription << String.toMaybe
17391737
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
17401738
, entityUuid = metric.uuid
1741-
, markdownPreviews = model.markdownPreviews
17421739
}
17431740

17441741
annotationsInput =
@@ -2121,7 +2118,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
21212118
{ identifier = "advancedConfiguration"
21222119
, openLabel = gettext "Advanced Integration Configuration" appState.locale
21232120
, content = allowCustomReplyGroup ++ variablesGroup ++ secretsGroup
2124-
, markdownPreviews = model.markdownPreviews
2121+
, markdownPreviews = model.editorPreviews
21252122
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
21262123
, entityUuid = integrationUuid
21272124
}
@@ -2156,7 +2153,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
21562153
{ identifier = "requestAdvancedConfiguration"
21572154
, openLabel = gettext "Advanced Request Configuration" appState.locale
21582155
, content = requestAdvancedConfigurationContent
2159-
, markdownPreviews = model.markdownPreviews
2156+
, markdownPreviews = model.editorPreviews
21602157
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
21612158
, entityUuid = integrationUuid
21622159
}
@@ -2252,7 +2249,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
22522249
{ identifier = "requestDetails"
22532250
, openLabel = gettext "Request Details" appState.locale
22542251
, content = requestDetailsGroupContent
2255-
, markdownPreviews = model.markdownPreviews
2252+
, markdownPreviews = model.editorPreviews
22562253
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
22572254
, entityUuid = integrationUuid
22582255
}
@@ -2441,7 +2438,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
24412438
, showPreviewMsg = wrapMsg << TestIntegrationPreview integrationUuid
24422439
, showTemplateMsg = wrapMsg << ShowHideMarkdownPreview False
24432440
, entityUuid = integrationUuid
2444-
, markdownPreviews = model.markdownPreviews
2441+
, editorPreviews = model.editorPreviews
24452442
, integrationTestPreviews = model.integrationTestPreviews
24462443
, cursorPositions = model.cursorPositions
24472444
, fieldSuggestions = TypeHintTestResponse.getSuggestedItemProperties (String.fromMaybe data.responseListField) responseData
@@ -2459,7 +2456,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
24592456
, showPreviewMsg = wrapMsg << TestIntegrationPreview integrationUuid
24602457
, showTemplateMsg = wrapMsg << ShowHideMarkdownPreview False
24612458
, entityUuid = integrationUuid
2462-
, markdownPreviews = model.markdownPreviews
2459+
, editorPreviews = model.editorPreviews
24632460
, integrationTestPreviews = model.integrationTestPreviews
24642461
, cursorPositions = model.cursorPositions
24652462
, fieldSuggestions = TypeHintTestResponse.getSuggestedItemProperties (String.fromMaybe data.responseListField) responseData
@@ -2472,7 +2469,7 @@ viewIntegrationEditorApi config parentUuid integrationUuid integration data =
24722469
{ identifier = "responseAdvancedConfiguration"
24732470
, openLabel = gettext "Advanced Response Configuration" appState.locale
24742471
, content = responseAdvancedConfigurationContent
2475-
, markdownPreviews = model.markdownPreviews
2472+
, markdownPreviews = model.editorPreviews
24762473
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
24772474
, entityUuid = integrationUuid
24782475
}
@@ -2676,7 +2673,6 @@ viewAnswerEditor { appState, wrapMsg, eventMsg, model, editorContext } answer =
26762673
, onInput = createEditEvent setAdvice << String.toMaybe
26772674
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
26782675
, entityUuid = answer.uuid
2679-
, markdownPreviews = model.markdownPreviews
26802676
}
26812677

26822678
followUpsInput =
@@ -3158,7 +3154,7 @@ viewResourceCollectionEditor { appState, wrapMsg, eventMsg, model, editorContext
31583154

31593155

31603156
viewResourcePageEditor : EditorConfig msg -> ResourcePage -> Html msg
3161-
viewResourcePageEditor { appState, wrapMsg, eventMsg, model, editorContext } resourcePage =
3157+
viewResourcePageEditor { appState, wrapMsg, eventMsg, editorContext } resourcePage =
31623158
let
31633159
parentUuid =
31643160
EditorContext.getParentUuid resourcePage.uuid editorContext
@@ -3199,7 +3195,6 @@ viewResourcePageEditor { appState, wrapMsg, eventMsg, model, editorContext } res
31993195
, onInput = createEditEvent setContent
32003196
, previewMsg = compose2 wrapMsg ShowHideMarkdownPreview
32013197
, entityUuid = resourcePage.uuid
3202-
, markdownPreviews = model.markdownPreviews
32033198
}
32043199

32053200
annotationsInput =

app-wizard/elm/Wizard/Pages/KMEditor/Editor/Components/KMEditor/Input.elm

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ import ActionResult exposing (ActionResult)
4343
import Common.Components.ActionResultBlock as ActionResultBlock
4444
import Common.Components.DatePicker as DatePicker
4545
import Common.Components.FontAwesome exposing (faAdd, faDelete, fas)
46+
import Common.Components.MarkdownEditor as MarkdownEditor
4647
import Common.Components.Tooltip exposing (tooltip, tooltipLeft)
4748
import Common.Utils.ByteUnits as ByteUnits
4849
import Common.Utils.Markdown as Markdown
4950
import Common.Utils.RegexPatterns as RegexPatterns
5051
import Dict exposing (Dict)
5152
import Gettext exposing (gettext)
5253
import Html exposing (Html, a, div, input, label, li, optgroup, option, span, text, ul)
53-
import Html.Attributes as Attribute exposing (attribute, checked, class, classList, for, href, id, name, placeholder, rows, selected, step, style, target, type_, value)
54+
import Html.Attributes as Attribute exposing (attribute, checked, class, classList, for, id, name, placeholder, rows, selected, step, style, type_, value)
5455
import Html.Attributes.Extensions exposing (dataCy)
5556
import Html.Events exposing (onCheck, onClick, onInput)
5657
import Html.Events.Extensions exposing (onBlurWithSelection)
@@ -347,62 +348,20 @@ type alias MarkdownInputConfig msg =
347348
, onInput : String -> msg
348349
, previewMsg : Bool -> String -> msg
349350
, entityUuid : String
350-
, markdownPreviews : List String
351+
352+
--, markdownPreviews : List String
351353
}
352354

353355

354356
markdown : AppState -> MarkdownInputConfig msg -> Html msg
355357
markdown appState config =
356-
let
357-
fieldIdentifier =
358-
createFieldId config.entityUuid config.name
359-
360-
previewActive =
361-
List.member fieldIdentifier config.markdownPreviews
362-
363-
content =
364-
if previewActive then
365-
Markdown.toHtml [] config.value
366-
367-
else
368-
Html.textarea
369-
[ class "form-control"
370-
, id config.name
371-
, name config.name
372-
, onInput config.onInput
373-
, value config.value
374-
, rows <| List.length <| String.lines config.value
375-
]
376-
[]
377-
in
378358
div [ class "form-group form-group-markup-editor" ]
379359
[ label [ for config.name ] [ text config.label ]
380-
, div [ class "card" ]
381-
[ div [ class "card-header" ]
382-
[ ul [ class "nav nav-tabs card-header-tabs" ]
383-
[ li [ class "nav-item" ]
384-
[ a
385-
[ onClick (config.previewMsg False fieldIdentifier)
386-
, class "nav-link"
387-
, classList [ ( "active", not previewActive ) ]
388-
]
389-
[ text (gettext "Editor" appState.locale) ]
390-
]
391-
, li [ class "nav-item" ]
392-
[ a
393-
[ onClick (config.previewMsg True fieldIdentifier)
394-
, class "nav-link"
395-
, classList [ ( "active", previewActive ) ]
396-
]
397-
[ text (gettext "Preview" appState.locale) ]
398-
]
399-
]
400-
]
401-
, div [ class "card-body" ] [ content ]
402-
, div [ class "card-footer text-muted" ]
403-
(String.formatHtml (gettext "You can use %s and see the result in the preview tab." appState.locale)
404-
[ a [ href (WizardGuideLinks.markdownCheatsheet appState.guideLinks), target "_blank" ] [ text "Markdown" ] ]
405-
)
360+
, MarkdownEditor.markdownEditor
361+
[ id config.name
362+
, MarkdownEditor.value config.value
363+
, MarkdownEditor.onChange config.onInput
364+
, MarkdownEditor.labels appState.locale
406365
]
407366
]
408367

@@ -420,7 +379,7 @@ type alias ItemTemplateEditorConfig msg =
420379
, showPreviewMsg : String -> msg
421380
, showTemplateMsg : String -> msg
422381
, entityUuid : String
423-
, markdownPreviews : List String
382+
, editorPreviews : List String
424383
, integrationTestPreviews : Dict String (ActionResult (List TypeHint))
425384
, cursorPositions : Dict String ( Int, Int )
426385
, fieldSuggestions : List String
@@ -435,7 +394,7 @@ itemTemplateEditor appState config =
435394
createFieldId config.entityUuid config.name
436395

437396
previewActive =
438-
List.member fieldIdentifier config.markdownPreviews
397+
List.member fieldIdentifier config.editorPreviews
439398

440399
content =
441400
if previewActive then

app-wizard/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const program = require('./elm/Wizard.elm')
1212
require('./js/components/charts')
1313
require('./js/components/code-editor')
1414
require('../shared/common/js/components/datetime-pickers')
15+
require('../shared/common/js/components/markdown-editor')
1516
require('../shared/common/js/components/shortcut-element')
1617

1718
const cookies = require('./js/ports/cookies')

app-wizard/scss/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $fa-font-path: '~@fortawesome/fontawesome-free/webfonts' !default;
2626
@import '../../shared/common/scss/components/alert';
2727
@import '../../shared/common/scss/components/guide-link';
2828
@import '../../shared/common/scss/components/forms';
29+
@import '../../shared/common/scss/components/markdown-editor';
2930
@import '../../shared/common/scss/components/modal-news';
3031
@import '../../shared/common/scss/components/page';
3132
@import '../../shared/common/scss/components/tooltips';

app-wizard/scss/modules/Shared/_Markdown.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import '../../variables';
22
@import '../../mixins';
33

4-
.Markdown {
4+
.Markdown, .ProseMirror {
55
img {
66
max-width: 100%;
77
}
@@ -71,4 +71,8 @@
7171
margin-bottom: 0;
7272
}
7373
}
74+
75+
p:last-child {
76+
margin-bottom: 0;
77+
}
7478
}

0 commit comments

Comments
 (0)