@cdc/markup-include 4.25.7 → 4.25.10
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 +17202 -10890
- package/package.json +11 -3
- package/src/CdcMarkupInclude.tsx +62 -66
- package/src/_stories/MarkupInclude.Editor.stories.tsx +465 -0
- package/src/_stories/MarkupInclude.stories.tsx +58 -58
- package/src/components/EditorPanel.tsx +27 -121
- package/src/data/initial-state.js +6 -3
- package/src/index.jsx +5 -2
- package/src/test/CdcMarkupInclude.test.jsx +8 -3
- package/src/types/Condition.ts +1 -1
- package/src/types/Config.ts +4 -1
- package/vite.config.js +1 -1
- package/src/coreStyles_markupinclude.scss +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import React, { useState, useEffect,
|
|
1
|
+
import React, { useState, useEffect, useContext, useRef } from 'react'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import _ from 'lodash'
|
|
3
|
+
import { cloneConfig } from '@cdc/core/helpers/cloneConfig'
|
|
5
4
|
|
|
6
5
|
// Context
|
|
7
|
-
import { Variable } from '../types/Variable'
|
|
8
6
|
import ConfigContext from '../ConfigContext'
|
|
9
7
|
|
|
10
8
|
// Helpers
|
|
@@ -13,19 +11,16 @@ import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
|
|
|
13
11
|
// Components
|
|
14
12
|
import InputCheckbox from '@cdc/core/components/inputs/InputCheckbox'
|
|
15
13
|
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
16
|
-
import Icon from '@cdc/core/components/ui/Icon'
|
|
17
14
|
import InputText from '@cdc/core/components/inputs/InputText'
|
|
18
15
|
import Layout from '@cdc/core/components/Layout'
|
|
19
|
-
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
20
16
|
import Accordion from '@cdc/core/components/ui/Accordion'
|
|
17
|
+
import MarkupVariablesEditor from '@cdc/core/components/EditorPanel/components/MarkupVariablesEditor'
|
|
18
|
+
import FootnotesEditor from '@cdc/core/components/EditorPanel/FootnotesEditor'
|
|
19
|
+
import { Datasets } from '@cdc/core/types/DataSet'
|
|
21
20
|
|
|
22
21
|
// styles
|
|
23
22
|
import '@cdc/core/styles/v2/components/editor.scss'
|
|
24
23
|
import './editorPanel.style.css'
|
|
25
|
-
import VariableSection from './Variables'
|
|
26
|
-
import { CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
|
|
27
|
-
import FootnotesEditor from '@cdc/core/components/EditorPanel/FootnotesEditor'
|
|
28
|
-
import { Datasets } from '@cdc/core/types/DataSet'
|
|
29
24
|
|
|
30
25
|
const headerColors = [
|
|
31
26
|
'theme-blue',
|
|
@@ -48,12 +43,11 @@ type MarkupIncludeEditorPanelProps = {
|
|
|
48
43
|
const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
|
|
49
44
|
const { config, data, isDashboard, loading, setParentConfig, updateConfig } = useContext(ConfigContext)
|
|
50
45
|
const { contentEditor, theme, visual } = config
|
|
51
|
-
const { inlineHTML,
|
|
46
|
+
const { inlineHTML, srcUrl, title, useInlineHTML } = contentEditor
|
|
52
47
|
const [displayPanel, setDisplayPanel] = useState(true)
|
|
53
48
|
const updateField = updateFieldFactory(config, updateConfig, true)
|
|
54
|
-
const hasData = data?.[0] !== undefined ?? false
|
|
55
49
|
|
|
56
|
-
const
|
|
50
|
+
const textAreaInEditorContainer = useRef(null)
|
|
57
51
|
|
|
58
52
|
useEffect(() => {
|
|
59
53
|
// Pass up to Editor if needed
|
|
@@ -79,52 +73,25 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
|
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
const convertStateToConfig = () => {
|
|
82
|
-
const strippedState =
|
|
76
|
+
const strippedState = cloneConfig(config)
|
|
83
77
|
delete strippedState.newViz
|
|
84
78
|
delete strippedState.runtime
|
|
85
79
|
|
|
86
80
|
return strippedState
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const handleCreateNewVariableButtonClick = () => {
|
|
96
|
-
const newVariableArray = [..._.cloneDeep(variableArray)]
|
|
97
|
-
const newVariable = {
|
|
98
|
-
columnName: '',
|
|
99
|
-
conditions: [],
|
|
100
|
-
name: '',
|
|
101
|
-
tag: ''
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setControls({ ...controls, [variableArray.length + 1]: true })
|
|
105
|
-
|
|
106
|
-
newVariableArray.push(newVariable)
|
|
107
|
-
setVariableArray(newVariableArray)
|
|
108
|
-
setIsCreatingVariable(!isCreatingVariable)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const updateVariableArray = (newVariable: Variable, variableIndex: number) => {
|
|
112
|
-
const newVariableArray = _.cloneDeep(variableArray)
|
|
113
|
-
newVariableArray[variableIndex] = newVariable
|
|
114
|
-
setVariableArray(newVariableArray)
|
|
115
|
-
updateField('contentEditor', null, 'markupVariables', newVariableArray)
|
|
116
|
-
return
|
|
83
|
+
const handleMarkupVariablesChange = (variables: any[]) => {
|
|
84
|
+
updateConfig({
|
|
85
|
+
...config,
|
|
86
|
+
markupVariables: variables
|
|
87
|
+
})
|
|
117
88
|
}
|
|
118
89
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const newControls = _.cloneDeep(controls)
|
|
126
|
-
delete newControls[variableIndex]
|
|
127
|
-
setControls(newControls)
|
|
90
|
+
const handleToggleEnable = (enabled: boolean) => {
|
|
91
|
+
updateConfig({
|
|
92
|
+
...config,
|
|
93
|
+
enableMarkupVariables: enabled
|
|
94
|
+
})
|
|
128
95
|
}
|
|
129
96
|
|
|
130
97
|
const editorContent = (
|
|
@@ -164,77 +131,7 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
|
|
|
164
131
|
rows={10}
|
|
165
132
|
updateField={updateField}
|
|
166
133
|
/>
|
|
167
|
-
|
|
168
|
-
<hr className='accordion__divider' />
|
|
169
134
|
</div>
|
|
170
|
-
{/* Create New Variable*/}
|
|
171
|
-
|
|
172
|
-
{/* Variable Options List */}
|
|
173
|
-
<fieldset>
|
|
174
|
-
<label>
|
|
175
|
-
<span className='edit-label'>
|
|
176
|
-
Variables
|
|
177
|
-
<Tooltip style={{ textTransform: 'none' }}>
|
|
178
|
-
<Tooltip.Target>
|
|
179
|
-
<Icon display='question' style={{ marginLeft: '0.5rem' }} />
|
|
180
|
-
</Tooltip.Target>
|
|
181
|
-
<Tooltip.Content>{`To use created variables wrap the variable name in curly brackets, e.g. {{some_variable}}, and place the variable directly in your Inline HTML`}</Tooltip.Content>
|
|
182
|
-
</Tooltip>
|
|
183
|
-
</span>
|
|
184
|
-
</label>
|
|
185
|
-
{hasData === false && (
|
|
186
|
-
<span className='need-data-source-prompt'>To use variables, add data source.</span>
|
|
187
|
-
)}
|
|
188
|
-
{variableArray && variableArray.length > 0 && (
|
|
189
|
-
<div className='section-border'>
|
|
190
|
-
{variableArray?.map((variableObject, index) => {
|
|
191
|
-
return (
|
|
192
|
-
<VariableSection
|
|
193
|
-
key={`${variableObject.name}-${index}`}
|
|
194
|
-
controls={openVariableControls}
|
|
195
|
-
data={data}
|
|
196
|
-
deleteVariable={deleteVariable}
|
|
197
|
-
updateVariableArray={updateVariableArray}
|
|
198
|
-
variableConfig={variableObject}
|
|
199
|
-
variableIndex={index}
|
|
200
|
-
/>
|
|
201
|
-
)
|
|
202
|
-
})}
|
|
203
|
-
</div>
|
|
204
|
-
)}
|
|
205
|
-
<div className='pt-2'>
|
|
206
|
-
<CheckBox
|
|
207
|
-
value={allowHideSection}
|
|
208
|
-
section='contentEditor'
|
|
209
|
-
fieldName='allowHideSection'
|
|
210
|
-
label='Hide Section on Null'
|
|
211
|
-
updateField={updateField}
|
|
212
|
-
tooltip={
|
|
213
|
-
<Tooltip style={{ textTransform: 'none' }}>
|
|
214
|
-
<Tooltip.Target>
|
|
215
|
-
<Icon
|
|
216
|
-
display='question'
|
|
217
|
-
style={{ marginLeft: '0.5rem', display: 'inline-block', whiteSpace: 'nowrap' }}
|
|
218
|
-
/>
|
|
219
|
-
</Tooltip.Target>
|
|
220
|
-
<Tooltip.Content>
|
|
221
|
-
<p>{`Hide this entire Markup Include section if any variable is null or blank.`}</p>
|
|
222
|
-
</Tooltip.Content>
|
|
223
|
-
</Tooltip>
|
|
224
|
-
}
|
|
225
|
-
/>
|
|
226
|
-
</div>
|
|
227
|
-
|
|
228
|
-
<div className='mb-1 d-flex'>
|
|
229
|
-
<button
|
|
230
|
-
className={'btn btn-primary'}
|
|
231
|
-
onClick={handleCreateNewVariableButtonClick}
|
|
232
|
-
disabled={!hasData}
|
|
233
|
-
>
|
|
234
|
-
Create New Variable
|
|
235
|
-
</button>
|
|
236
|
-
</div>
|
|
237
|
-
</fieldset>
|
|
238
135
|
</>
|
|
239
136
|
) : (
|
|
240
137
|
<InputText
|
|
@@ -307,6 +204,15 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
|
|
|
307
204
|
<FootnotesEditor config={config} updateField={updateField} datasets={datasets} />
|
|
308
205
|
</Accordion.Section>
|
|
309
206
|
)}
|
|
207
|
+
<Accordion.Section title='Markup Variables'>
|
|
208
|
+
<MarkupVariablesEditor
|
|
209
|
+
markupVariables={config.markupVariables || []}
|
|
210
|
+
data={data || []}
|
|
211
|
+
onChange={handleMarkupVariablesChange}
|
|
212
|
+
enableMarkupVariables={config.enableMarkupVariables || false}
|
|
213
|
+
onToggleEnable={handleToggleEnable}
|
|
214
|
+
/>
|
|
215
|
+
</Accordion.Section>
|
|
310
216
|
</Accordion>
|
|
311
217
|
)
|
|
312
218
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
contentEditor: {
|
|
3
3
|
inlineHTML: '<h2>Inline HTML</h2>',
|
|
4
|
-
markupVariables: [],
|
|
5
4
|
showHeader: true,
|
|
6
5
|
srcUrl: '#example',
|
|
7
6
|
title: 'Markup Include',
|
|
8
|
-
useInlineHTML: false
|
|
7
|
+
useInlineHTML: false,
|
|
8
|
+
showNoDataMessage: false,
|
|
9
|
+
noDataMessageText: 'No Data Available'
|
|
9
10
|
},
|
|
10
11
|
data: [],
|
|
11
12
|
legend: {},
|
|
@@ -19,5 +20,7 @@ export default {
|
|
|
19
20
|
background: false,
|
|
20
21
|
hideBackgroundColor: false,
|
|
21
22
|
borderColorTheme: false
|
|
22
|
-
}
|
|
23
|
+
},
|
|
24
|
+
markupVariables: [],
|
|
25
|
+
enableMarkupVariables: false
|
|
23
26
|
}
|
package/src/index.jsx
CHANGED
|
@@ -4,7 +4,6 @@ import ReactDOM from 'react-dom/client'
|
|
|
4
4
|
import { GlobalContextProvider } from '@cdc/core/components/GlobalContext'
|
|
5
5
|
|
|
6
6
|
import '@cdc/core/styles/cove-main.scss'
|
|
7
|
-
import './coreStyles_markupinclude.scss'
|
|
8
7
|
|
|
9
8
|
import CdcMarkupInclude from './CdcMarkupInclude'
|
|
10
9
|
|
|
@@ -15,7 +14,11 @@ let domContainer = document.getElementsByClassName('react-container')[0]
|
|
|
15
14
|
ReactDOM.createRoot(domContainer).render(
|
|
16
15
|
<React.StrictMode>
|
|
17
16
|
<GlobalContextProvider>
|
|
18
|
-
<CdcMarkupInclude
|
|
17
|
+
<CdcMarkupInclude
|
|
18
|
+
configUrl={domContainer.attributes['data-config'].value}
|
|
19
|
+
interactionLabel={domContainer.attributes['data-config'].value}
|
|
20
|
+
isEditor={isEditor}
|
|
21
|
+
/>
|
|
19
22
|
</GlobalContextProvider>
|
|
20
23
|
</React.StrictMode>
|
|
21
24
|
)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
|
|
3
|
+
import { describe, it, expect } from 'vitest'
|
|
4
|
+
|
|
2
5
|
describe('Markup Include', () => {
|
|
3
|
-
it('
|
|
4
|
-
|
|
6
|
+
it('Can be built in isolation', async () => {
|
|
7
|
+
const pkgDir = path.join(__dirname, '..')
|
|
8
|
+
const result = testStandaloneBuild(pkgDir)
|
|
9
|
+
expect(result).toBe(true)
|
|
5
10
|
})
|
|
6
11
|
})
|
package/src/types/Condition.ts
CHANGED
package/src/types/Config.ts
CHANGED
|
@@ -6,11 +6,12 @@ export type Config = {
|
|
|
6
6
|
contentEditor: {
|
|
7
7
|
// Changing the base config object creates an infinite loop, nesting it is a workaround
|
|
8
8
|
inlineHTML: string
|
|
9
|
-
markupVariables: Variable[]
|
|
10
9
|
showHeader: boolean
|
|
11
10
|
srcUrl: string
|
|
12
11
|
title: string
|
|
13
12
|
useInlineHTML: boolean
|
|
13
|
+
showNoDataMessage: boolean
|
|
14
|
+
noDataMessageText: string
|
|
14
15
|
}
|
|
15
16
|
data?: Object[]
|
|
16
17
|
legend: {}
|
|
@@ -27,4 +28,6 @@ export type Config = {
|
|
|
27
28
|
borderColorTheme: boolean
|
|
28
29
|
}
|
|
29
30
|
version: Version
|
|
31
|
+
markupVariables: Variable[]
|
|
32
|
+
enableMarkupVariables: boolean
|
|
30
33
|
}
|
package/vite.config.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import '@cdc/core/styles/base';
|