@cdc/markup-include 4.23.10-alpha → 4.23.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdcmarkupinclude.js +6425 -5787
- package/package.json +4 -4
- package/src/{CdcMarkupInclude.jsx → CdcMarkupInclude.tsx} +45 -36
- package/src/_stories/MarkupInclude.stories.tsx +19 -0
- package/src/scss/main.scss +0 -4
- package/src/store/mi.actions.ts +21 -0
- package/src/store/mi.reducer.ts +36 -0
- package/src/types/Config.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/markup-include",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.11",
|
|
4
4
|
"description": "React component for displaying HTML content from an outside link",
|
|
5
5
|
"moduleName": "CdcMarkupInclude",
|
|
6
6
|
"main": "dist/cdcmarkupinclude",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cdc/core": "^4.23.
|
|
30
|
-
"axios": "^
|
|
29
|
+
"@cdc/core": "^4.23.11",
|
|
30
|
+
"axios": "^1.6.0",
|
|
31
31
|
"chroma": "0.0.1",
|
|
32
32
|
"chroma-js": "^2.1.0",
|
|
33
33
|
"html-react-parser": "^3.0.8",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"react": "^18.2.0",
|
|
39
39
|
"react-dom": "^18.2.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ecad213667a3cb96c921eaddba43a31c84caaa08"
|
|
42
42
|
}
|
|
@@ -1,32 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import axios from 'axios'
|
|
3
|
-
import parse from 'html-react-parser'
|
|
4
|
-
import { Markup } from 'interweave'
|
|
1
|
+
import { useEffect, useCallback, useRef, useReducer } from 'react'
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
import
|
|
3
|
+
// external
|
|
4
|
+
import { Markup } from 'interweave'
|
|
5
|
+
import axios from 'axios'
|
|
8
6
|
|
|
7
|
+
// cdc
|
|
8
|
+
import { Config } from './types/Config'
|
|
9
|
+
import { publish } from '@cdc/core/helpers/events'
|
|
9
10
|
import ConfigContext from './ConfigContext'
|
|
10
|
-
import
|
|
11
|
+
import coveUpdateWorker from '@cdc/core/helpers/coveUpdateWorker'
|
|
11
12
|
import defaults from './data/initial-state'
|
|
13
|
+
import EditorPanel from './components/EditorPanel'
|
|
12
14
|
|
|
15
|
+
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
16
|
+
import Loading from '@cdc/core/components/Loading'
|
|
17
|
+
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
18
|
+
import markupIncludeReducer from './store/mi.reducer'
|
|
19
|
+
|
|
20
|
+
// styles
|
|
13
21
|
import './scss/main.scss'
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
type CdcMarkupIncludeProps = {
|
|
24
|
+
config: Config
|
|
25
|
+
configUrl: string
|
|
26
|
+
isDashboard: boolean
|
|
27
|
+
isEditor: boolean
|
|
28
|
+
setConfig: any
|
|
29
|
+
}
|
|
16
30
|
|
|
17
|
-
import
|
|
18
|
-
|
|
31
|
+
import Title from '@cdc/core/components/ui/Title'
|
|
32
|
+
|
|
33
|
+
const CdcMarkupInclude = (props: CdcMarkupIncludeProps) => {
|
|
34
|
+
const { configUrl, config: configObj, isDashboard = false, isEditor = false, setConfig: setParentConfig } = props
|
|
35
|
+
const initialState = { config: configObj ?? defaults, loading: true, urlMarkup: '', markupError: null, errorMessage: null, coveLoadedHasRan: false }
|
|
19
36
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const [loading, setLoading] = useState(true)
|
|
37
|
+
const [state, dispatch] = useReducer(markupIncludeReducer, initialState)
|
|
38
|
+
|
|
39
|
+
const { config, loading, urlMarkup, markupError, errorMessage, coveLoadedHasRan } = state
|
|
24
40
|
|
|
25
41
|
// Custom States
|
|
26
|
-
const [urlMarkup, setUrlMarkup] = useState('')
|
|
27
|
-
const [markupError, setMarkupError] = useState(null)
|
|
28
|
-
const [errorMessage, setErrorMessage] = useState(null)
|
|
29
|
-
const [coveLoadedHasRan, setCoveLoadedHasRan] = useState(false)
|
|
30
42
|
const container = useRef()
|
|
31
43
|
|
|
32
44
|
const { innerContainerClasses, contentClasses } = useDataVizClasses(config)
|
|
@@ -45,7 +57,7 @@ const CdcMarkupInclude = ({ configUrl, config: configObj, isDashboard = false, i
|
|
|
45
57
|
newConfig.runtime.uniqueId = Date.now()
|
|
46
58
|
|
|
47
59
|
newConfig.runtime.editorErrorMessage = ''
|
|
48
|
-
|
|
60
|
+
dispatch({ type: 'SET_CONFIG', payload: newConfig })
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
const loadConfig = useCallback(async () => {
|
|
@@ -61,7 +73,7 @@ const CdcMarkupInclude = ({ configUrl, config: configObj, isDashboard = false, i
|
|
|
61
73
|
const processedConfig = { ...(await coveUpdateWorker(response)) }
|
|
62
74
|
|
|
63
75
|
updateConfig({ ...defaults, ...processedConfig })
|
|
64
|
-
|
|
76
|
+
dispatch({ type: 'SET_LOADING', payload: false })
|
|
65
77
|
}, [])
|
|
66
78
|
|
|
67
79
|
// Custom Functions
|
|
@@ -82,41 +94,42 @@ const CdcMarkupInclude = ({ configUrl, config: configObj, isDashboard = false, i
|
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
message += errorList[errorCode]
|
|
85
|
-
|
|
97
|
+
dispatch({ type: 'SET_ERROR_MESSAGE', payload: message })
|
|
86
98
|
} else {
|
|
87
|
-
|
|
99
|
+
dispatch({ type: 'SET_ERROR_MESSAGE', payload: null })
|
|
88
100
|
}
|
|
89
101
|
}, [markupError])
|
|
90
102
|
|
|
91
103
|
const loadConfigMarkupData = useCallback(async () => {
|
|
92
|
-
|
|
104
|
+
dispatch({ type: 'SET_MARKUP_ERROR', payload: null })
|
|
93
105
|
|
|
94
106
|
if (config.srcUrl) {
|
|
95
107
|
if (config.srcUrl === '#example') {
|
|
96
|
-
|
|
108
|
+
let payload =
|
|
97
109
|
'<!doctype html><html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h1>Header</h1> <p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p> <br> <p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. </p><br><p>She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek.</p></body></html>'
|
|
98
|
-
|
|
110
|
+
|
|
111
|
+
dispatch({ type: 'SET_URL_MARKUP', payload })
|
|
99
112
|
} else {
|
|
100
113
|
try {
|
|
101
114
|
await axios.get(config.srcUrl).then(res => {
|
|
102
115
|
if (res.data) {
|
|
103
|
-
|
|
116
|
+
dispatch({ type: 'SET_URL_MARKUP', payload: res.data })
|
|
104
117
|
}
|
|
105
118
|
})
|
|
106
119
|
} catch (err) {
|
|
107
120
|
if (err.response) {
|
|
108
121
|
// Response with error
|
|
109
|
-
|
|
122
|
+
dispatch({ type: 'SET_MARKUP_ERROR', payload: err.response.status })
|
|
110
123
|
} else if (err.request) {
|
|
111
124
|
// No response received
|
|
112
|
-
|
|
125
|
+
dispatch({ type: 'SET_MARKUP_ERROR', payload: 200 })
|
|
113
126
|
}
|
|
114
127
|
|
|
115
|
-
|
|
128
|
+
dispatch({ type: 'SET_URL_MARKUP', payload: '' })
|
|
116
129
|
}
|
|
117
130
|
}
|
|
118
131
|
} else {
|
|
119
|
-
|
|
132
|
+
dispatch({ type: 'SET_URL_MARKUP', payload: '' })
|
|
120
133
|
}
|
|
121
134
|
}, [config.srcUrl])
|
|
122
135
|
|
|
@@ -144,7 +157,7 @@ const CdcMarkupInclude = ({ configUrl, config: configObj, isDashboard = false, i
|
|
|
144
157
|
useEffect(() => {
|
|
145
158
|
if (config && !coveLoadedHasRan && container) {
|
|
146
159
|
publish('cove_loaded', { config: config })
|
|
147
|
-
|
|
160
|
+
dispatch({ type: 'SET_COVE_LOADED_HAS_RAN', payload: true })
|
|
148
161
|
}
|
|
149
162
|
}, [config, container])
|
|
150
163
|
|
|
@@ -165,11 +178,7 @@ const CdcMarkupInclude = ({ configUrl, config: configObj, isDashboard = false, i
|
|
|
165
178
|
if (loading === false) {
|
|
166
179
|
let body = (
|
|
167
180
|
<div className={bodyClasses.join(' ')} ref={container}>
|
|
168
|
-
{title
|
|
169
|
-
<header className={`cove-component__header ${config.theme}`} aria-hidden='true'>
|
|
170
|
-
{parse(title)} {isDashboard}
|
|
171
|
-
</header>
|
|
172
|
-
)}
|
|
181
|
+
<Title title={title} isDashboard={isDashboard} classes={[`${config.theme}`, 'mb-0']} />
|
|
173
182
|
<div className={`cove-component__content ${contentClasses.join(' ')}`}>
|
|
174
183
|
<div className={`${innerContainerClasses.join(' ')}`}>
|
|
175
184
|
<div className='cove-component__content-wrap'>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
|
+
import ExampleConfig_1 from './../data/initial-state'
|
|
3
|
+
import CdcMarkupInclude from '../CdcMarkupInclude'
|
|
4
|
+
import { Config } from '../types/Config'
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof CdcMarkupInclude> = {
|
|
7
|
+
title: 'Components/Templates/Markup Include',
|
|
8
|
+
component: CdcMarkupInclude
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type Story = StoryObj<typeof CdcMarkupInclude>
|
|
12
|
+
|
|
13
|
+
export const Initial_State: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
config: ExampleConfig_1 as unknown as Config
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default meta
|
package/src/scss/main.scss
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from '../types/Config'
|
|
2
|
+
|
|
3
|
+
type Action<T, P> = { type: T; payload: P }
|
|
4
|
+
|
|
5
|
+
type SET_CONFIG = Action<'SET_CONFIG', Config>
|
|
6
|
+
type SET_LOADING = Action<'SET_LOADING', boolean>
|
|
7
|
+
type SET_URL_MARKUP = Action<'SET_URL_MARKUP', string>
|
|
8
|
+
type SET_MARKUP_ERROR = Action<'SET_MARKUP_ERROR', any>
|
|
9
|
+
type SET_ERROR_MESSAGE = Action<'SET_ERROR_MESSAGE', any>
|
|
10
|
+
type SET_COVE_LOADED_HAS_RAN = Action<'SET_COVE_LOADED_HAS_RAN', boolean>
|
|
11
|
+
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
type MarkupIncludeActions =
|
|
14
|
+
| SET_CONFIG
|
|
15
|
+
| SET_LOADING
|
|
16
|
+
| SET_URL_MARKUP
|
|
17
|
+
| SET_MARKUP_ERROR
|
|
18
|
+
| SET_ERROR_MESSAGE
|
|
19
|
+
| SET_COVE_LOADED_HAS_RAN
|
|
20
|
+
|
|
21
|
+
export default MarkupIncludeActions
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Config } from '../types/Config'
|
|
2
|
+
import MarkupIncludeActions from './mi.actions'
|
|
3
|
+
|
|
4
|
+
export type MarkupIncludeState = {
|
|
5
|
+
config?: Config
|
|
6
|
+
loading: boolean
|
|
7
|
+
urlMarkup: string
|
|
8
|
+
markupError: any
|
|
9
|
+
errorMessage: any
|
|
10
|
+
coveLoadedHasRan: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const reducer = (state: MarkupIncludeState, action: MarkupIncludeActions): MarkupIncludeState => {
|
|
14
|
+
switch (action.type) {
|
|
15
|
+
case 'SET_CONFIG': {
|
|
16
|
+
return { ...state, config: action.payload }
|
|
17
|
+
}
|
|
18
|
+
case 'SET_LOADING': {
|
|
19
|
+
return { ...state, loading: action.payload }
|
|
20
|
+
}
|
|
21
|
+
case 'SET_URL_MARKUP': {
|
|
22
|
+
return { ...state, urlMarkup: action.payload }
|
|
23
|
+
}
|
|
24
|
+
case 'SET_MARKUP_ERROR': {
|
|
25
|
+
return { ...state, markupError: action.payload }
|
|
26
|
+
}
|
|
27
|
+
case 'SET_ERROR_MESSAGE': {
|
|
28
|
+
return { ...state, errorMessage: action.payload }
|
|
29
|
+
}
|
|
30
|
+
case 'SET_COVE_LOADED_HAS_RAN': {
|
|
31
|
+
return { ...state, coveLoadedHasRan: action.payload }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default reducer
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// todo: improve base config to extend from
|
|
2
|
+
// todo: theme type is different from waffle chart so its been assigned to any for now.
|
|
3
|
+
export type Config = {
|
|
4
|
+
title: string
|
|
5
|
+
showHeader: boolean
|
|
6
|
+
type: string
|
|
7
|
+
srcUrl: string
|
|
8
|
+
theme: any
|
|
9
|
+
visual: {
|
|
10
|
+
border: boolean
|
|
11
|
+
accent: boolean
|
|
12
|
+
background: boolean
|
|
13
|
+
hideBackgroundColor: boolean
|
|
14
|
+
borderColorTheme: boolean
|
|
15
|
+
}
|
|
16
|
+
}
|