Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
151471a3
Commit
151471a3
authored
Jan 24, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CodeEditor] add Haskell
parent
b4e0cd86
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
34 deletions
+64
-34
CodeEditor.css
dist/styles/CodeEditor.css
+8
-4
CodeEditor.sass
dist/styles/CodeEditor.sass
+6
-3
CodeEditor.purs
src/Gargantext/Components/CodeEditor.purs
+23
-15
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+9
-9
Types.purs
src/Gargantext/Components/Nodes/Corpus/Types.purs
+18
-3
No files found.
dist/styles/CodeEditor.css
View file @
151471a3
...
@@ -90,15 +90,19 @@
...
@@ -90,15 +90,19 @@
margin-left
:
25px
;
margin-left
:
25px
;
padding-left
:
25px
;
padding-left
:
25px
;
}
}
.code-editor
.editor
.html.language-haskell
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
.code-editor
.editor
.html.language-json
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
.code-editor
.editor
.html.language-md
ul
li
{
.code-editor
.editor
.html.language-md
ul
li
{
list-style
:
disc
!important
;
list-style
:
disc
!important
;
}
}
.code-editor
.editor
.html.language-md
ol
li
{
.code-editor
.editor
.html.language-md
ol
li
{
list-style
:
decimal
!important
;
list-style
:
decimal
!important
;
}
}
.code-editor
.editor
.html.language-json
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
/*# sourceMappingURL=CodeEditor.css.map */
/*# sourceMappingURL=CodeEditor.css.map */
dist/styles/CodeEditor.sass
View file @
151471a3
...
@@ -74,6 +74,12 @@
...
@@ -74,6 +74,12 @@
flex-grow
:
2
flex-grow
:
2
margin-left
:
25px
margin-left
:
25px
padding-left
:
25px
padding-left
:
25px
&
.language-haskell
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
&
.language-json
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
&
.language-md
&
.language-md
ul
ul
li
li
...
@@ -81,6 +87,3 @@
...
@@ -81,6 +87,3 @@
ol
ol
li
li
list-style
:
decimal
!
important
list-style
:
decimal
!
important
&
.language-json
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
src/Gargantext/Components/CodeEditor.purs
View file @
151471a3
...
@@ -18,7 +18,7 @@ import Reactix.DOM.HTML as H
...
@@ -18,7 +18,7 @@ import Reactix.DOM.HTML as H
import Text.Markdown.SlamDown.Parser (parseMd)
import Text.Markdown.SlamDown.Parser (parseMd)
import Text.Markdown.SlamDown.Smolder as MD
import Text.Markdown.SlamDown.Smolder as MD
import Text.Markdown.SlamDown.Syntax (SlamDownP)
import Text.Markdown.SlamDown.Syntax (SlamDownP)
import Text.Smolder.Renderer.String
(render)
import Text.Smolder.Renderer.String
as Smolder
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Utils.HighlightJS as HLJS
import Gargantext.Utils.HighlightJS as HLJS
...
@@ -28,7 +28,7 @@ type Code = String
...
@@ -28,7 +28,7 @@ type Code = String
type Html = String
type Html = String
type Error = String
type Error = String
data CodeType = JSON | Markdown
data CodeType =
Haskell |
JSON | Markdown
derive instance genericCodeType :: Generic CodeType _
derive instance genericCodeType :: Generic CodeType _
instance eqCodeType :: Eq CodeType where
instance eqCodeType :: Eq CodeType where
eq = genericEq
eq = genericEq
...
@@ -54,29 +54,35 @@ codeNlFix :: CodeType -> Code -> Code
...
@@ -54,29 +54,35 @@ codeNlFix :: CodeType -> Code -> Code
codeNlFix _ "" = " "
codeNlFix _ "" = " "
codeNlFix _ c = if endsWith "\n" c then (c <> " ") else c
codeNlFix _ c = if endsWith "\n" c then (c <> " ") else c
compile :: CodeType -> Code -> Either Error Html
render :: CodeType -> Code -> Either Error Html
compile JSON code = result
render Haskell code = Right $ renderHaskell $ codeNlFix Haskell code
render JSON code = result
where
where
parsedE = jsonParser code
parsedE = jsonParser code
result = case parsedE of
result = case parsedE of
Left err -> Left err
Left err -> Left err
Right parsed -> Right $ R2.stringify parsed 2
Right parsed -> Right $ R2.stringify parsed 2
compile Markdown code = Right $ compile
Md $ codeNlFix Markdown code
render Markdown code = Right $ render
Md $ codeNlFix Markdown code
previewPostProcess :: CodeType -> Element -> Effect Unit
previewPostProcess :: CodeType -> Element -> Effect Unit
previewPostProcess Markdown _ = pure unit
previewPostProcess Haskell htmlEl = do
HLJS.highlightBlock htmlEl
previewPostProcess JSON htmlEl = do
previewPostProcess JSON htmlEl = do
HLJS.highlightBlock htmlEl
HLJS.highlightBlock htmlEl
previewPostProcess Markdown _ = pure unit
-- TODO Replace with markdown-it?
-- TODO Replace with markdown-it?
-- https://pursuit.purescript.org/packages/purescript-markdown-it
-- https://pursuit.purescript.org/packages/purescript-markdown-it
compile
Md' :: forall e. MD.ToMarkupOptions e -> String -> String
render
Md' :: forall e. MD.ToMarkupOptions e -> String -> String
compile
Md' options input =
render
Md' options input =
either identity (MD.toMarkup' options >>> render)
either identity (MD.toMarkup' options >>>
Smolder.
render)
(parseMd input :: Either String (SlamDownP String))
(parseMd input :: Either String (SlamDownP String))
compileMd :: String -> String
renderMd :: String -> String
compileMd = compileMd' MD.defaultToMarkupOptions
renderMd = renderMd' MD.defaultToMarkupOptions
renderHaskell :: String -> String
renderHaskell s = s
codeEditor :: Record Props -> R.Element
codeEditor :: Record Props -> R.Element
codeEditor p = R.createElement codeEditorCpt p []
codeEditor p = R.createElement codeEditorCpt p []
...
@@ -142,6 +148,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
...
@@ -142,6 +148,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
dividerHidden _ = " hidden"
dividerHidden _ = " hidden"
langClass :: CodeType -> String
langClass :: CodeType -> String
langClass Haskell = " language-haskell"
langClass JSON = " language-json"
langClass JSON = " language-json"
langClass Markdown = " language-md"
langClass Markdown = " language-md"
...
@@ -174,12 +181,12 @@ renderHtml code {codeType: (codeType /\ _), htmlElRef, error: (_ /\ setError)} =
...
@@ -174,12 +181,12 @@ renderHtml code {codeType: (codeType /\ _), htmlElRef, error: (_ /\ setError)} =
case (toMaybe $ R.readRef htmlElRef) of
case (toMaybe $ R.readRef htmlElRef) of
Nothing -> pure unit
Nothing -> pure unit
Just htmlEl -> do
Just htmlEl -> do
case
compile
codeType code of
case
render
codeType code of
Left err -> do
Left err -> do
setError $ const $ Just err
setError $ const $ Just err
Right
compil
ed -> do
Right
render
ed -> do
setError $ const Nothing
setError $ const Nothing
_ <- pure $ (htmlEl .= "innerHTML")
compil
ed
_ <- pure $ (htmlEl .= "innerHTML")
render
ed
previewPostProcess codeType htmlEl
previewPostProcess codeType htmlEl
pure unit
pure unit
...
@@ -239,7 +246,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
...
@@ -239,7 +246,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
, on: { change: onSelectChange codeType onChange }
, on: { change: onSelectChange codeType onChange }
, style: { width: "150px" }
, style: { width: "150px" }
, value: show $ fst codeType }
, value: show $ fst codeType }
(option <$> [JSON, Markdown])
(option <$> [
Haskell,
JSON, Markdown])
option :: CodeType -> R.Element
option :: CodeType -> R.Element
option value = H.option { value: show value } [ H.text $ show value ]
option value = H.option { value: show value } [ H.text $ show value ]
...
@@ -247,6 +254,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
...
@@ -247,6 +254,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
onSelectChange :: forall e. R.State CodeType -> (CodeType -> Effect Unit) -> e -> Effect Unit
onSelectChange :: forall e. R.State CodeType -> (CodeType -> Effect Unit) -> e -> Effect Unit
onSelectChange (_ /\ setCodeType) onChange e = do
onSelectChange (_ /\ setCodeType) onChange e = do
let codeType = case value of
let codeType = case value of
"Haskell" -> Haskell
"JSON" -> JSON
"JSON" -> JSON
"Markdown" -> Markdown
"Markdown" -> Markdown
_ -> Markdown
_ -> Markdown
...
...
src/Gargantext/Components/Nodes/Corpus.purs
View file @
151471a3
...
@@ -64,9 +64,6 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
...
@@ -64,9 +64,6 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
let fieldsWithIndex = A.mapWithIndex (\idx -> \t -> Tuple idx t) fields
let fieldsWithIndex = A.mapWithIndex (\idx -> \t -> Tuple idx t) fields
fieldsS <- R.useState' fieldsWithIndex
fieldsS <- R.useState' fieldsWithIndex
R.useEffect' $ do
log2 "[corpusLayoutViewCpt] reload" $ fst reload
pure $ H.div {} [
pure $ H.div {} [
H.div { className: "row" } [
H.div { className: "row" } [
H.div { className: "btn btn-default " <> (saveEnabled fieldsWithIndex fieldsS)
H.div { className: "btn btn-default " <> (saveEnabled fieldsWithIndex fieldsS)
...
@@ -125,7 +122,6 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt
...
@@ -125,7 +122,6 @@ fieldsCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldsCodeEditorCpt" cpt
onChange :: R.State (Array FTFieldWithIndex) -> Index -> FieldType -> Effect Unit
onChange :: R.State (Array FTFieldWithIndex) -> Index -> FieldType -> Effect Unit
onChange (_ /\ setFields) idx typ = do
onChange (_ /\ setFields) idx typ = do
log2 "[fieldsCodeEditorCpt] onChange" typ
setFields $ \fields ->
setFields $ \fields ->
case A.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields of
case A.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields of
Nothing -> fields
Nothing -> fields
...
@@ -157,13 +153,12 @@ fieldCodeEditor props = R.createElement fieldCodeEditorCpt props []
...
@@ -157,13 +153,12 @@ fieldCodeEditor props = R.createElement fieldCodeEditorCpt props []
fieldCodeEditorCpt :: R.Component FieldCodeEditorProps
fieldCodeEditorCpt :: R.Component FieldCodeEditorProps
fieldCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorCpt" cpt
fieldCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorCpt" cpt
where
where
cpt {field: Field {typ:
Markdown md@{text
}}, onChange} _ = do
cpt {field: Field {typ:
Haskell hs@{code
}}, onChange} _ = do
pure $ CE.codeEditor {code
: text, defaultCodeType: CE.Markdown
, onChange: onChange'}
pure $ CE.codeEditor {code
, defaultCodeType: CE.Haskell
, onChange: onChange'}
where
where
onChange' :: CE.Code -> Effect Unit
onChange' :: CE.Code -> Effect Unit
onChange' c = do
onChange' c = do
log2 "[fieldCodeEditor'] Markdown c" c
onChange $ Haskell $ hs { code = c }
onChange $ Markdown $ md { text = c }
cpt {field: Field {typ: JSON j}, onChange} _ = do
cpt {field: Field {typ: JSON j}, onChange} _ = do
pure $ CE.codeEditor {code, defaultCodeType: CE.JSON, onChange: onChange'}
pure $ CE.codeEditor {code, defaultCodeType: CE.JSON, onChange: onChange'}
where
where
...
@@ -171,12 +166,17 @@ fieldCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorCpt" cpt
...
@@ -171,12 +166,17 @@ fieldCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorCpt" cpt
onChange' :: CE.Code -> Effect Unit
onChange' :: CE.Code -> Effect Unit
onChange' c = do
onChange' c = do
log2 "[fieldCodeEditor'] JSON c" c
case jsonParser c of
case jsonParser c of
Left err -> log2 "[fieldCodeEditor'] cannot parse json" c
Left err -> log2 "[fieldCodeEditor'] cannot parse json" c
Right j' -> case decodeJson j' of
Right j' -> case decodeJson j' of
Left err -> log2 "[fieldCodeEditor'] cannot decode json" j'
Left err -> log2 "[fieldCodeEditor'] cannot decode json" j'
Right j'' -> onChange $ JSON j''
Right j'' -> onChange $ JSON j''
cpt {field: Field {typ: Markdown md@{text}}, onChange} _ = do
pure $ CE.codeEditor {code: text, defaultCodeType: CE.Markdown, onChange: onChange'}
where
onChange' :: CE.Code -> Effect Unit
onChange' c = do
onChange $ Markdown $ md { text = c }
type LoadProps = (
type LoadProps = (
nodeId :: Int
nodeId :: Int
...
...
src/Gargantext/Components/Nodes/Corpus/Types.purs
View file @
151471a3
...
@@ -15,6 +15,7 @@ type Description = String
...
@@ -15,6 +15,7 @@ type Description = String
type Query = String
type Query = String
type Tag = String
type Tag = String
type Title = String
type Title = String
type HaskellCode = String
type MarkdownText = String
type MarkdownText = String
newtype Hyperdata =
newtype Hyperdata =
...
@@ -41,7 +42,12 @@ derive instance genericFTField :: Generic (Field FieldType) _
...
@@ -41,7 +42,12 @@ derive instance genericFTField :: Generic (Field FieldType) _
instance eqFTField :: Eq (Field FieldType) where
instance eqFTField :: Eq (Field FieldType) where
eq = genericEq
eq = genericEq
data FieldType = JSON {
data FieldType =
Haskell {
code :: HaskellCode
, tag :: Tag
}
| JSON {
authors :: Author
authors :: Author
, desc :: Description
, desc :: Description
, query :: Query
, query :: Query
...
@@ -62,6 +68,10 @@ instance decodeFTField :: DecodeJson (Field FieldType) where
...
@@ -62,6 +68,10 @@ instance decodeFTField :: DecodeJson (Field FieldType) where
type_ <- obj .: "type"
type_ <- obj .: "type"
data_ <- obj .: "data"
data_ <- obj .: "data"
typ <- case type_ of
typ <- case type_ of
"Haskell" -> do
code <- data_ .: "code"
tag <- data_ .: "tag"
pure $ Haskell {code, tag}
"JSON" -> do
"JSON" -> do
authors <- data_ .: "authors"
authors <- data_ .: "authors"
desc <- data_ .: "desc"
desc <- data_ .: "desc"
...
@@ -82,9 +92,14 @@ instance encodeFTField :: EncodeJson (Field FieldType) where
...
@@ -82,9 +92,14 @@ instance encodeFTField :: EncodeJson (Field FieldType) where
~> "type" := typ' typ
~> "type" := typ' typ
~> jsonEmptyObject
~> jsonEmptyObject
where
where
typ' (Haskell _) = "Haskell"
typ' (JSON _) = "JSON"
typ' (JSON _) = "JSON"
typ' (Markdown _) = "Markdown"
typ' (Markdown _) = "Markdown"
instance encodeFieldType :: EncodeJson FieldType where
instance encodeFieldType :: EncodeJson FieldType where
encodeJson (Haskell {code}) =
"code" := code
~> "tag" := "HaskellField"
~> jsonEmptyObject
encodeJson (JSON {authors, desc, query, tag, title}) =
encodeJson (JSON {authors, desc, query, tag, title}) =
"authors" := authors
"authors" := authors
~> "desc" := desc
~> "desc" := desc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment