@vonage/vivid-react 2.10.47 → 2.10.58
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/.storybook/main.js +11 -0
- package/.storybook/preview.js +3 -0
- package/.vscode/settings.json +4 -0
- package/README.md +75 -65
- package/babel.config.js +38 -0
- package/package.json +66 -67
- package/rollup.config.js +30 -0
- package/scripts/cli.js +27 -0
- package/scripts/generateWrappers/consts.js +220 -0
- package/scripts/generateWrappers/generator.js +264 -0
- package/scripts/generateWrappers/helpers/generator.js +18 -0
- package/scripts/generateWrappers/helpers/generator.test.js +56 -0
- package/scripts/generateWrappers/prop.types.js +87 -0
- package/scripts/generateWrappers/templates/js/index.tmpl +2 -0
- package/scripts/generateWrappers/templates/js/react-component-v3.tmpl +19 -0
- package/scripts/generateWrappers/templates/js/react-component.tmpl +30 -0
- package/scripts/generateWrappers/templates/js/stories.tmpl +18 -0
- package/scripts/generateWrappers/templates/templates.js +39 -0
- package/scripts/generateWrappers/templates/ts/element-type.tmpl +3 -0
- package/scripts/generateWrappers/templates/ts/index.tmpl +2 -0
- package/scripts/generateWrappers/templates/ts/react-component-v3.tmpl +32 -0
- package/scripts/generateWrappers/templates/ts/react-component.tmpl +28 -0
- package/scripts/generateWrappers/templates/ts/types.tmpl +8 -0
- package/scripts/generateWrappers/utils.js +197 -0
- package/scripts/generateWrappers/utils.test.js +71 -0
- package/scripts/updateDocs.js +42 -0
- package/scripts/updateVividPackages.js +81 -0
- package/src/dataGrid/index.js +15 -0
- package/src/index.js +3 -0
- package/src/initialization/initVivid.js +56 -0
- package/src/patches/VwcCard/index.js +2 -0
- package/src/patches/VwcCard/vwcCardHeadingCrop.js +28 -0
- package/src/patches/VwcCard/vwcCardWithMenu.js +14 -0
- package/src/patches/index.js +6 -0
- package/src/patches/vwcDataGrid.js +26 -0
- package/src/patches/vwcNoteContentOverflow.js +20 -0
- package/src/patches/vwcSetAttributeValue.js +12 -0
- package/src/patches/vwcSnackBarHtmlMessage.js +21 -0
- package/src/patches/vwcTooltip.js +46 -0
- package/stories/v2/VwcAccordion/VwcAccordion.stories.jsx +18 -0
- package/stories/v2/VwcActionGroup/VwcActionGroup.stories.jsx +18 -0
- package/stories/v2/VwcBadge/VwcBadge.stories.jsx +18 -0
- package/stories/v2/VwcBanner/VwcBanner.stories.jsx +18 -0
- package/stories/v2/VwcButton/VwcButton.stories.jsx +18 -0
- package/stories/v2/VwcButtonToggleGroup/VwcButtonToggleGroup.stories.jsx +47 -0
- package/stories/v2/VwcCalendar/VwcCalendar.stories.jsx +18 -0
- package/stories/v2/VwcCalendarEvent/VwcCalendarEvent.stories.jsx +18 -0
- package/stories/v2/VwcCard/VwcCard.stories.jsx +90 -0
- package/stories/v2/VwcCarousel/VwcCarousel.stories.jsx +18 -0
- package/stories/v2/VwcCarouselItem/VwcCarouselItem.stories.jsx +18 -0
- package/stories/v2/VwcCheckListItem/VwcCheckListItem.stories.jsx +18 -0
- package/stories/v2/VwcCheckbox/VwcCheckbox.stories.jsx +18 -0
- package/stories/v2/VwcChip/VwcChip.stories.jsx +18 -0
- package/stories/v2/VwcChipSet/VwcChipSet.stories.jsx +38 -0
- package/stories/v2/VwcCircularProgress/VwcCircularProgress.stories.jsx +18 -0
- package/stories/v2/VwcDataGrid/VwcDataGrid.stories.jsx +109 -0
- package/stories/v2/VwcDataGridColumn/VwcDataGridColumn.stories.jsx +18 -0
- package/stories/v2/VwcDatepicker/VwcDatepicker.stories.jsx +18 -0
- package/stories/v2/VwcDialog/VwcDialog.stories.jsx +18 -0
- package/stories/v2/VwcDrawer/VwcDrawer.stories.jsx +18 -0
- package/stories/v2/VwcDropdown/VwcDropdown.stories.jsx +18 -0
- package/stories/v2/VwcElevation/VwcElevation.stories.jsx +18 -0
- package/stories/v2/VwcEmptyState/VwcEmptyState.stories.jsx +18 -0
- package/stories/v2/VwcExpansionPanel/VwcExpansionPanel.stories.jsx +18 -0
- package/stories/v2/VwcFab/VwcFab.stories.jsx +18 -0
- package/stories/v2/VwcFilePicker/VwcFilePicker.stories.jsx +18 -0
- package/stories/v2/VwcFormfield/VwcFormfield.stories.jsx +18 -0
- package/stories/v2/VwcHelperMessage/VwcHelperMessage.stories.jsx +18 -0
- package/stories/v2/VwcIcon/VwcIcon.stories.jsx +18 -0
- package/stories/v2/VwcIconButton/VwcIconButton.stories.jsx +18 -0
- package/stories/v2/VwcIconButtonToggle/VwcIconButtonToggle.stories.jsx +18 -0
- package/stories/v2/VwcKeypad/VwcKeypad.stories.jsx +18 -0
- package/stories/v2/VwcLayout/VwcLayout.stories.jsx +63 -0
- package/stories/v2/VwcLinearProgress/VwcLinearProgress.stories.jsx +18 -0
- package/stories/v2/VwcList/VwcList.stories.jsx +25 -0
- package/stories/v2/VwcListExpansionPanel/VwcListExpansionPanel.stories.jsx +18 -0
- package/stories/v2/VwcListItem/VwcListItem.stories.jsx +18 -0
- package/stories/v2/VwcMenu/VwcMenu.stories.jsx +41 -0
- package/stories/v2/VwcNotchedOutline/VwcNotchedOutline.stories.jsx +18 -0
- package/stories/v2/VwcNote/VwcNote.stories.jsx +18 -0
- package/stories/v2/VwcPagination/VwcPagination.stories.jsx +18 -0
- package/stories/v2/VwcPopup/VwcPopup.stories.jsx +18 -0
- package/stories/v2/VwcRadio/VwcRadio.stories.jsx +18 -0
- package/stories/v2/VwcRadioListItem/VwcRadioListItem.stories.jsx +18 -0
- package/stories/v2/VwcSchemeSelect/VwcSchemeSelect.stories.jsx +18 -0
- package/stories/v2/VwcSelect/VwcSelect.stories.jsx +18 -0
- package/stories/v2/VwcSideDrawer/VwcSideDrawer.stories.jsx +18 -0
- package/stories/v2/VwcSlider/VwcSlider.stories.jsx +18 -0
- package/stories/v2/VwcSnackbar/VwcSnackbar.stories.jsx +18 -0
- package/stories/v2/VwcSurface/VwcSurface.stories.jsx +18 -0
- package/stories/v2/VwcSwitch/VwcSwitch.stories.jsx +18 -0
- package/stories/v2/VwcTab/VwcTab.stories.jsx +18 -0
- package/stories/v2/VwcTabBar/VwcTabBar.stories.jsx +63 -0
- package/stories/v2/VwcTag/VwcTag.stories.jsx +18 -0
- package/stories/v2/VwcText/VwcText.stories.jsx +18 -0
- package/stories/v2/VwcTextarea/VwcTextarea.stories.jsx +24 -0
- package/stories/v2/VwcTextfield/VwcTextfield.stories.jsx +47 -0
- package/stories/v2/VwcThemeSwitch/VwcThemeSwitch.stories.jsx +18 -0
- package/stories/v2/VwcTooltip/VwcTooltip.stories.jsx +41 -0
- package/stories/v2/VwcTopAppBar/VwcTopAppBar.stories.jsx +18 -0
- package/stories/v2/VwcTopAppBarFixed/VwcTopAppBarFixed.stories.jsx +18 -0
- package/stories/v2/patches/patches.stories.jsx +94 -0
- package/stories/v3/v3.stories.jsx +28 -0
- package/tsconfig.json +70 -0
- package/VwcAccordion/index.d.ts +0 -14
- package/VwcAccordion/index.js +0 -59
- package/VwcAccordion/package.json +0 -11
- package/VwcActionGroup/index.d.ts +0 -18
- package/VwcActionGroup/index.js +0 -90
- package/VwcActionGroup/package.json +0 -11
- package/VwcBadge/index.d.ts +0 -29
- package/VwcBadge/index.js +0 -154
- package/VwcBadge/package.json +0 -11
- package/VwcBanner/index.d.ts +0 -26
- package/VwcBanner/index.js +0 -91
- package/VwcBanner/package.json +0 -11
- package/VwcButton/index.d.ts +0 -55
- package/VwcButton/index.js +0 -240
- package/VwcButton/package.json +0 -11
- package/VwcButtonToggleGroup/index.d.ts +0 -25
- package/VwcButtonToggleGroup/index.js +0 -91
- package/VwcButtonToggleGroup/package.json +0 -11
- package/VwcCalendar/index.d.ts +0 -20
- package/VwcCalendar/index.js +0 -70
- package/VwcCalendar/package.json +0 -11
- package/VwcCalendarEvent/index.d.ts +0 -25
- package/VwcCalendarEvent/index.js +0 -81
- package/VwcCalendarEvent/package.json +0 -11
- package/VwcCard/index.d.ts +0 -23
- package/VwcCard/index.js +0 -76
- package/VwcCard/package.json +0 -11
- package/VwcCarousel/index.d.ts +0 -14
- package/VwcCarousel/index.js +0 -45
- package/VwcCarousel/package.json +0 -11
- package/VwcCarouselItem/index.d.ts +0 -14
- package/VwcCarouselItem/index.js +0 -49
- package/VwcCarouselItem/package.json +0 -11
- package/VwcCheckListItem/index.d.ts +0 -41
- package/VwcCheckListItem/index.js +0 -153
- package/VwcCheckListItem/package.json +0 -11
- package/VwcCheckbox/index.d.ts +0 -34
- package/VwcCheckbox/index.js +0 -126
- package/VwcCheckbox/package.json +0 -11
- package/VwcChip/index.d.ts +0 -31
- package/VwcChip/index.js +0 -106
- package/VwcChip/package.json +0 -11
- package/VwcChipSet/index.d.ts +0 -16
- package/VwcChipSet/index.js +0 -60
- package/VwcChipSet/package.json +0 -11
- package/VwcCircularProgress/index.d.ts +0 -24
- package/VwcCircularProgress/index.js +0 -84
- package/VwcCircularProgress/package.json +0 -11
- package/VwcDataGrid/index.d.ts +0 -33
- package/VwcDataGrid/index.js +0 -122
- package/VwcDataGrid/package.json +0 -11
- package/VwcDataGridColumn/index.d.ts +0 -43
- package/VwcDataGridColumn/index.js +0 -144
- package/VwcDataGridColumn/package.json +0 -11
- package/VwcDatepicker/index.d.ts +0 -120
- package/VwcDatepicker/index.js +0 -422
- package/VwcDatepicker/package.json +0 -11
- package/VwcDialog/index.d.ts +0 -40
- package/VwcDialog/index.js +0 -135
- package/VwcDialog/package.json +0 -11
- package/VwcDrawer/index.d.ts +0 -20
- package/VwcDrawer/index.js +0 -80
- package/VwcDrawer/package.json +0 -11
- package/VwcDropdown/index.d.ts +0 -61
- package/VwcDropdown/index.js +0 -221
- package/VwcDropdown/package.json +0 -11
- package/VwcElevation/index.d.ts +0 -14
- package/VwcElevation/index.js +0 -45
- package/VwcElevation/package.json +0 -11
- package/VwcEmptyState/index.d.ts +0 -18
- package/VwcEmptyState/index.js +0 -59
- package/VwcEmptyState/package.json +0 -11
- package/VwcExpansionPanel/index.d.ts +0 -34
- package/VwcExpansionPanel/index.js +0 -199
- package/VwcExpansionPanel/package.json +0 -11
- package/VwcFab/index.d.ts +0 -32
- package/VwcFab/index.js +0 -124
- package/VwcFab/package.json +0 -11
- package/VwcFilePicker/index.d.ts +0 -24
- package/VwcFilePicker/index.js +0 -88
- package/VwcFilePicker/package.json +0 -11
- package/VwcFormfield/index.d.ts +0 -20
- package/VwcFormfield/index.js +0 -70
- package/VwcFormfield/package.json +0 -11
- package/VwcHelperMessage/index.d.ts +0 -14
- package/VwcHelperMessage/index.js +0 -49
- package/VwcHelperMessage/package.json +0 -11
- package/VwcIcon/index.d.ts +0 -22
- package/VwcIcon/index.js +0 -102
- package/VwcIcon/package.json +0 -11
- package/VwcIconButton/index.d.ts +0 -31
- package/VwcIconButton/index.js +0 -111
- package/VwcIconButton/package.json +0 -11
- package/VwcIconButtonToggle/index.d.ts +0 -37
- package/VwcIconButtonToggle/index.js +0 -136
- package/VwcIconButtonToggle/package.json +0 -11
- package/VwcKeypad/index.d.ts +0 -31
- package/VwcKeypad/index.js +0 -176
- package/VwcKeypad/package.json +0 -11
- package/VwcLayout/index.d.ts +0 -20
- package/VwcLayout/index.js +0 -105
- package/VwcLayout/package.json +0 -11
- package/VwcLinearProgress/index.d.ts +0 -26
- package/VwcLinearProgress/index.js +0 -98
- package/VwcLinearProgress/package.json +0 -11
- package/VwcList/index.d.ts +0 -35
- package/VwcList/index.js +0 -146
- package/VwcList/package.json +0 -11
- package/VwcListExpansionPanel/index.d.ts +0 -19
- package/VwcListExpansionPanel/index.js +0 -68
- package/VwcListExpansionPanel/package.json +0 -11
- package/VwcListItem/index.d.ts +0 -42
- package/VwcListItem/index.js +0 -171
- package/VwcListItem/package.json +0 -11
- package/VwcMenu/index.d.ts +0 -53
- package/VwcMenu/index.js +0 -210
- package/VwcMenu/package.json +0 -11
- package/VwcNotchedOutline/index.d.ts +0 -17
- package/VwcNotchedOutline/index.js +0 -58
- package/VwcNotchedOutline/package.json +0 -11
- package/VwcNote/index.d.ts +0 -18
- package/VwcNote/index.js +0 -59
- package/VwcNote/package.json +0 -11
- package/VwcPagination/index.d.ts +0 -16
- package/VwcPagination/index.js +0 -52
- package/VwcPagination/package.json +0 -11
- package/VwcPopup/index.d.ts +0 -30
- package/VwcPopup/index.js +0 -147
- package/VwcPopup/package.json +0 -11
- package/VwcRadio/index.d.ts +0 -52
- package/VwcRadio/index.js +0 -149
- package/VwcRadio/package.json +0 -11
- package/VwcRadioListItem/index.d.ts +0 -41
- package/VwcRadioListItem/index.js +0 -148
- package/VwcRadioListItem/package.json +0 -11
- package/VwcSchemeSelect/index.d.ts +0 -14
- package/VwcSchemeSelect/index.js +0 -46
- package/VwcSchemeSelect/package.json +0 -11
- package/VwcSelect/index.d.ts +0 -60
- package/VwcSelect/index.js +0 -253
- package/VwcSelect/package.json +0 -11
- package/VwcSideDrawer/index.d.ts +0 -22
- package/VwcSideDrawer/index.js +0 -73
- package/VwcSideDrawer/package.json +0 -11
- package/VwcSlider/index.d.ts +0 -34
- package/VwcSlider/index.js +0 -129
- package/VwcSlider/package.json +0 -11
- package/VwcSnackbar/index.d.ts +0 -42
- package/VwcSnackbar/index.js +0 -138
- package/VwcSnackbar/package.json +0 -11
- package/VwcSurface/index.d.ts +0 -42
- package/VwcSurface/index.js +0 -145
- package/VwcSurface/package.json +0 -11
- package/VwcSwitch/index.d.ts +0 -27
- package/VwcSwitch/index.js +0 -114
- package/VwcSwitch/package.json +0 -11
- package/VwcTab/index.d.ts +0 -40
- package/VwcTab/index.js +0 -151
- package/VwcTab/package.json +0 -11
- package/VwcTabBar/index.d.ts +0 -15
- package/VwcTabBar/index.js +0 -55
- package/VwcTabBar/package.json +0 -11
- package/VwcTag/index.d.ts +0 -34
- package/VwcTag/index.js +0 -115
- package/VwcTag/package.json +0 -11
- package/VwcText/index.d.ts +0 -18
- package/VwcText/index.js +0 -83
- package/VwcText/package.json +0 -11
- package/VwcTextarea/index.d.ts +0 -93
- package/VwcTextarea/index.js +0 -331
- package/VwcTextarea/package.json +0 -11
- package/VwcTextfield/index.d.ts +0 -89
- package/VwcTextfield/index.js +0 -329
- package/VwcTextfield/package.json +0 -11
- package/VwcThemeSwitch/index.d.ts +0 -14
- package/VwcThemeSwitch/index.js +0 -57
- package/VwcThemeSwitch/package.json +0 -11
- package/VwcTooltip/index.d.ts +0 -22
- package/VwcTooltip/index.js +0 -105
- package/VwcTooltip/package.json +0 -11
- package/VwcTopAppBar/index.d.ts +0 -22
- package/VwcTopAppBar/index.js +0 -77
- package/VwcTopAppBar/package.json +0 -11
- package/VwcTopAppBarFixed/index.d.ts +0 -22
- package/VwcTopAppBarFixed/index.js +0 -88
- package/VwcTopAppBarFixed/package.json +0 -11
- package/index.js +0 -281
- package/types/index.d.ts +0 -2
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
const FileName = {
|
|
2
|
+
packageJson: 'package.json',
|
|
3
|
+
tempFolder: 'temp',
|
|
4
|
+
customElements: 'custom-elements.json',
|
|
5
|
+
vividApi: 'vivid.api.json',
|
|
6
|
+
tempFileName: 'analyzerOutput.json',
|
|
7
|
+
tempTsFolder: 'ts',
|
|
8
|
+
generatedFolder: 'src/generated',
|
|
9
|
+
tempVividZipball: 'vivid.zip',
|
|
10
|
+
defaultOutputDirectory: 'dist',
|
|
11
|
+
storyOutputDir: 'stories',
|
|
12
|
+
readme: 'README.md',
|
|
13
|
+
testing: 'testing',
|
|
14
|
+
types: 'types'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Assets = [
|
|
18
|
+
FileName.packageJson,
|
|
19
|
+
FileName.readme,
|
|
20
|
+
FileName.testing,
|
|
21
|
+
FileName.types
|
|
22
|
+
].join(',')
|
|
23
|
+
|
|
24
|
+
const VividRepo = 'Vonage/vivid'
|
|
25
|
+
|
|
26
|
+
const WCAConfig = {
|
|
27
|
+
tempFolder: FileName.tempFolder,
|
|
28
|
+
tempFileName: FileName.tempFileName,
|
|
29
|
+
nodeArgumentsFactory: (packageNames, analyzerOutputFile) => [
|
|
30
|
+
'./node_modules/web-component-analyzer/cli.js',
|
|
31
|
+
'analyze',
|
|
32
|
+
`node_modules/{${packageNames.join(',')}}/{src/,}*.?s`,
|
|
33
|
+
'--discoverNodeModules',
|
|
34
|
+
'--format', 'json',
|
|
35
|
+
'--outFile', analyzerOutputFile
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const CLIArgument = {
|
|
40
|
+
Assets: 'assets', // static assets to be copied to output folder
|
|
41
|
+
Output: 'output', // output folder
|
|
42
|
+
Language: 'language', // language js,ts
|
|
43
|
+
CleanTemp: 'clean' // clean up temp folder after CLI run
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const OutputLanguage = {
|
|
47
|
+
JavaScript: 'js',
|
|
48
|
+
TypeScript: 'ts'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO: this can be removed when JSDocs for each component will be updated in Vivid repository
|
|
52
|
+
const ComponentsEventsMap = {
|
|
53
|
+
VwcButtonToggleGroup: ['selected'],
|
|
54
|
+
VwcButton: ['click'],
|
|
55
|
+
VwcCard: ['click'],
|
|
56
|
+
VwcCheckbox: ['change'],
|
|
57
|
+
VwcChipSet: [{ name: 'MDCChip:selection', propName: 'onSelection' }],
|
|
58
|
+
VwcDataGrid: [{ name: 'selected-items-changed', propName: 'onSelectedItemsChange' }],
|
|
59
|
+
VwcDialog: ['opening', 'opened', 'closing', 'closed'],
|
|
60
|
+
VwcIconButton: ['click'],
|
|
61
|
+
VwcIconButtonToggle: [{ name: 'MDCIconButtonToggle:change', propName: 'onChange' }],
|
|
62
|
+
VwcListExpansionPanel: ['closed', 'opened'],
|
|
63
|
+
VwcListItem: ['click', { name: 'request-selected', propName: 'onRequestSelected' }],
|
|
64
|
+
VwcCheckListItem: [{ name: 'request-selected', propName: 'onRequestSelected' }],
|
|
65
|
+
VwcPagination: ['change'],
|
|
66
|
+
VwcRadio: ['change'],
|
|
67
|
+
VwcSlider: ['change'],
|
|
68
|
+
VwcSnackbar: ['opening', 'opened', 'closing', 'closed'],
|
|
69
|
+
VwcSwitch: ['change'],
|
|
70
|
+
VwcTab: [{ name: 'MDCTab:interacted', propName: 'onInteracted' }],
|
|
71
|
+
VwcTabBar: [{ name: 'MDCTabBar:activated', propName: 'onActivated' }],
|
|
72
|
+
VwcTextfield: ['input', 'blur', 'focus'],
|
|
73
|
+
VwcTextarea: ['input', 'blur', 'focus']
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const ComponentsEventsMapV3 = {
|
|
77
|
+
VwcButton: ['click']
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ComponentsReadOnlyPropertiesMap = {
|
|
81
|
+
VwcAccordion: ['styles'],
|
|
82
|
+
VwcActionGroup: ['styles'],
|
|
83
|
+
VwcAudio: ['styles', 'floatingLabelFoundation', 'lineRippleFoundation'],
|
|
84
|
+
VwcListExpansionPanel: ['styles', 'headerNodes'],
|
|
85
|
+
VwcExpansionPanel: ['styles'],
|
|
86
|
+
VwcBadge: ['styles'],
|
|
87
|
+
VwcBanner: ['styles'],
|
|
88
|
+
VwcDrawer: ['styles'],
|
|
89
|
+
VwcNotchedOutline: ['styles'],
|
|
90
|
+
VwcSurface: ['styles'],
|
|
91
|
+
VwcFilePicker: ['styles'],
|
|
92
|
+
VwcFormfield: ['styles'],
|
|
93
|
+
VwcHelperMessage: ['styles'],
|
|
94
|
+
VwcLinearProgress: ['styles'],
|
|
95
|
+
VwcThemeSwitch: ['styles'],
|
|
96
|
+
VwcTopAppBar: ['styles'],
|
|
97
|
+
VwcChip: ['styles'],
|
|
98
|
+
VwcCircularProgress: ['styles'],
|
|
99
|
+
VwcTopAppBarFixed: ['styles'],
|
|
100
|
+
VwcMediaController: ['floatingLabelFoundation', 'lineRippleFoundation'],
|
|
101
|
+
VwcRelativeTime: ['floatingLabelFoundation', 'lineRippleFoundation'],
|
|
102
|
+
VwcCarouselItem: ['floatingLabelFoundation', 'lineRippleFoundation'],
|
|
103
|
+
VwcList: ['styles', 'items', 'selected', 'index', 'layout', 'debouncedLayout'],
|
|
104
|
+
VwcListItem: ['styles', 'ripple', 'text'],
|
|
105
|
+
VwcLayout: ['styles'],
|
|
106
|
+
VwcSwitch: ['styles', 'ripple'],
|
|
107
|
+
VwcTab: ['styles', 'active', 'ripple', 'isRippleActive'],
|
|
108
|
+
VwcFab: ['styles', 'ripple'],
|
|
109
|
+
VwcTabBar: ['styles', 'active'],
|
|
110
|
+
VwcText: ['styles'],
|
|
111
|
+
VwcTextarea: ['styles', 'validity', 'ripple'],
|
|
112
|
+
VwcTextfield: ['styles', 'validity', 'willValidate', 'selectionStart', 'selectionEnd', 'ripple'],
|
|
113
|
+
VwcMenu: ['styles', 'slotElement', 'items', 'index', 'selected', 'mdcRoot'],
|
|
114
|
+
VwcRadio: ['styles', 'ripple', 'isRippleActive'],
|
|
115
|
+
VwcRadioListItem: ['styles', 'ripple'],
|
|
116
|
+
VwcSelect: ['styles', 'items', 'ripple'],
|
|
117
|
+
VwcCheckbox: ['styles', 'isRippleActive', 'ripple'],
|
|
118
|
+
VwcChipSet: ['styles', 'chips'],
|
|
119
|
+
VwcCheckListItem: ['styles', 'ripple'],
|
|
120
|
+
VwcDialog: ['styles'],
|
|
121
|
+
VwcDropdown: ['styles', 'items', 'selected'],
|
|
122
|
+
VwcButton: ['styles', 'buttonElement', 'ripple'],
|
|
123
|
+
VwcButtonToggleGroup: ['items', 'selected'],
|
|
124
|
+
VwcKeypad: ['styles', 'digitsDisplay'],
|
|
125
|
+
VwcIconButton: ['styles', 'buttonElement', 'ripple'],
|
|
126
|
+
VwcIconButtonToggle: ['styles', 'ripple'],
|
|
127
|
+
VwcDataGrid: ['styles', 'selectedItems'],
|
|
128
|
+
VwcSlider: ['styles', 'ripple']
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Properties reflected as attributes having different name
|
|
132
|
+
const RenamedReflectedAttributesPropertiesMap = {
|
|
133
|
+
VwcText: ['fontFace'], // font-face attribute
|
|
134
|
+
VwcLayout: ['columnBasis', 'columnSpacing', 'autoSizing']
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Bindable means property has complex type: (Function, Object, Array, etc.) OR properties reflected as attributes having different name
|
|
138
|
+
// Those properties needs to be binded directly to the underlying web element "as is"
|
|
139
|
+
// w/o toString => fromString transformations via HTML attributes
|
|
140
|
+
const ComponentsBindablePropertiesMap = {
|
|
141
|
+
VwcButton: ['form'],
|
|
142
|
+
VwcTextarea: ['form'],
|
|
143
|
+
VwcTextfield: ['form'],
|
|
144
|
+
VwcDataGrid: ['rowDetailsRenderer'],
|
|
145
|
+
VwcDataGridColumn: ['headerRenderer', 'footerRenderer', 'cellRenderer'],
|
|
146
|
+
VwcDialog: ['closeButton'],
|
|
147
|
+
VwcMenu: ['anchor'],
|
|
148
|
+
...RenamedReflectedAttributesPropertiesMap
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Extra properties to be exposed for element
|
|
152
|
+
const ComponentsExtraPropertiesMap = {
|
|
153
|
+
VwcIconButton: [
|
|
154
|
+
{
|
|
155
|
+
"name": "value",
|
|
156
|
+
"type": "string"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const CompoundComponentsMap = {
|
|
162
|
+
VwcButton: {
|
|
163
|
+
CallToAction: {
|
|
164
|
+
unelevated: true,
|
|
165
|
+
connotation: 'cta',
|
|
166
|
+
type: 'button',
|
|
167
|
+
layout: 'filled'
|
|
168
|
+
},
|
|
169
|
+
Alert: {
|
|
170
|
+
unelevated: true,
|
|
171
|
+
connotation: 'alert',
|
|
172
|
+
type: 'button',
|
|
173
|
+
layout: 'filled'
|
|
174
|
+
},
|
|
175
|
+
Outlined: {
|
|
176
|
+
unelevated: true,
|
|
177
|
+
layout: 'outlined',
|
|
178
|
+
type: 'button'
|
|
179
|
+
},
|
|
180
|
+
Success: {
|
|
181
|
+
unelevated: true,
|
|
182
|
+
connotation: 'success',
|
|
183
|
+
type: 'button',
|
|
184
|
+
layout: 'filled'
|
|
185
|
+
},
|
|
186
|
+
Info: {
|
|
187
|
+
unelevated: true,
|
|
188
|
+
connotation: 'info',
|
|
189
|
+
type: 'button',
|
|
190
|
+
layout: 'filled'
|
|
191
|
+
},
|
|
192
|
+
Primary: {
|
|
193
|
+
unelevated: true,
|
|
194
|
+
connotation: 'primary',
|
|
195
|
+
type: 'button',
|
|
196
|
+
layout: 'filled'
|
|
197
|
+
},
|
|
198
|
+
Announcement: {
|
|
199
|
+
unelevated: true,
|
|
200
|
+
connotation: 'announcement',
|
|
201
|
+
type: 'button',
|
|
202
|
+
layout: 'filled'
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = {
|
|
208
|
+
ComponentsEventsMap,
|
|
209
|
+
ComponentsEventsMapV3,
|
|
210
|
+
ComponentsReadOnlyPropertiesMap,
|
|
211
|
+
ComponentsBindablePropertiesMap,
|
|
212
|
+
ComponentsExtraPropertiesMap,
|
|
213
|
+
CompoundComponentsMap,
|
|
214
|
+
FileName,
|
|
215
|
+
Assets,
|
|
216
|
+
OutputLanguage,
|
|
217
|
+
WCAConfig,
|
|
218
|
+
CLIArgument,
|
|
219
|
+
VividRepo
|
|
220
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
const packageJson = require('../../package.json')
|
|
2
|
+
const { getImportsFromTag } = require('./helpers/generator')
|
|
3
|
+
const {
|
|
4
|
+
ComponentsEventsMap,
|
|
5
|
+
ComponentsEventsMapV3,
|
|
6
|
+
CompoundComponentsMap,
|
|
7
|
+
OutputLanguage,
|
|
8
|
+
FileName
|
|
9
|
+
} = require('./consts')
|
|
10
|
+
|
|
11
|
+
const { pathExists, outputFile, outputJson } = require('fs-extra')
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
compileTypescript,
|
|
15
|
+
prepareDir,
|
|
16
|
+
getComponentName,
|
|
17
|
+
toJsonObjectsList,
|
|
18
|
+
filePath,
|
|
19
|
+
camel2kebab,
|
|
20
|
+
event2PropName,
|
|
21
|
+
renderJsDoc,
|
|
22
|
+
getIndexFileName,
|
|
23
|
+
getProperties,
|
|
24
|
+
getUniqueEvents,
|
|
25
|
+
getVividPackageName,
|
|
26
|
+
prepareCompoundComponents,
|
|
27
|
+
compoundComponentTemplate
|
|
28
|
+
} = require('./utils')
|
|
29
|
+
const { getTemplate, TemplateToken } = require('./templates/templates')
|
|
30
|
+
const { join } = require('path')
|
|
31
|
+
const { getPropTypes, getDefaultProps, getProps, mapType } = require('./prop.types')
|
|
32
|
+
const { writeFileSync, readFileSync } = require('fs')
|
|
33
|
+
|
|
34
|
+
const generateTypings = outputDir => async tags => {
|
|
35
|
+
const distTs = join(FileName.tempFolder, FileName.tempTsFolder)
|
|
36
|
+
await generateWrappers(distTs, OutputLanguage.TypeScript, false, false)(tags)
|
|
37
|
+
await compileTypescript(distTs)(outputDir)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const generateTypingsV3 = outputDir => async meta => {
|
|
41
|
+
const distTs = join(FileName.tempFolder, FileName.tempTsFolder)
|
|
42
|
+
await generateWrappersV3(distTs, OutputLanguage.TypeScript, false, false)(meta)
|
|
43
|
+
await compileTypescript(distTs)(outputDir)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const renderComponent = tag => language => componentName => {
|
|
47
|
+
const compoundsConfig = CompoundComponentsMap[componentName] || {}
|
|
48
|
+
const getCompoundComponents = prepareCompoundComponents(componentName, compoundComponentTemplate, compoundsConfig)
|
|
49
|
+
return getTemplate('react-component', language)
|
|
50
|
+
.replace(TemplateToken.CLASS_JSDOC, renderJsDoc(tag))
|
|
51
|
+
.replace(TemplateToken.IMPORTS, getImportsFromTag(tag).join('\n'))
|
|
52
|
+
.replace(TemplateToken.EVENTS, toJsonObjectsList(getUniqueEvents(tag.events)))
|
|
53
|
+
.replace(TemplateToken.PROPERTIES,
|
|
54
|
+
toJsonObjectsList(
|
|
55
|
+
getProperties(tag)
|
|
56
|
+
.filter(property => property.bindable)
|
|
57
|
+
.map(({ name }) => name))
|
|
58
|
+
)
|
|
59
|
+
.replace(TemplateToken.ATTRIBUTES, '')
|
|
60
|
+
.replace(TemplateToken.PROP_TYPES, getPropTypes(tag).join(',\n'))
|
|
61
|
+
.replace(TemplateToken.PROPS, getProps(tag).join(',\n'))
|
|
62
|
+
.replace(TemplateToken.DEFAULT_PROPS, getDefaultProps(tag).join(',\n'))
|
|
63
|
+
.replace(TemplateToken.TAG_DESCRIPTOR_JSON, JSON.stringify(tag, null, ' '))
|
|
64
|
+
.replace(TemplateToken.COMPOUND_COMPONENTS, getCompoundComponents())
|
|
65
|
+
.replace(TemplateToken.REACT_IMPORT, getCompoundComponents() &&
|
|
66
|
+
'import { createElement } from \'react\'')
|
|
67
|
+
.replace(new RegExp(TemplateToken.COMPONENT_CLASS_NAME, 'g'), componentName)
|
|
68
|
+
.replace(new RegExp(TemplateToken.TAG, 'g'), tag.name)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Generates Vivid 2.x wrappers
|
|
73
|
+
*/
|
|
74
|
+
const generateWrappers = (outputDir, language = OutputLanguage.JavaScript, cleanTemp = true, verbose = true) => async (tags) => {
|
|
75
|
+
const indexFileName = getIndexFileName(language)
|
|
76
|
+
const saveIndex = (outputDir, content) => {
|
|
77
|
+
const indexOutputFileName = join(outputDir, indexFileName)
|
|
78
|
+
return outputFile(
|
|
79
|
+
indexOutputFileName,
|
|
80
|
+
content
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const saveStory = async (outputDir, componentName, content) => {
|
|
85
|
+
const indexOutputFileName = join(outputDir, `${componentName}.stories.jsx`)
|
|
86
|
+
const exists = await pathExists(indexOutputFileName)
|
|
87
|
+
return exists || outputFile(
|
|
88
|
+
indexOutputFileName,
|
|
89
|
+
content
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const getStoriesContent = (componentName, tag) =>
|
|
94
|
+
getTemplate('stories', OutputLanguage.JavaScript)
|
|
95
|
+
.split(TemplateToken.COMPONENT_CLASS_NAME).join(componentName)
|
|
96
|
+
|
|
97
|
+
prepareDir(outputDir, true, verbose)
|
|
98
|
+
const components = []
|
|
99
|
+
|
|
100
|
+
for (const tag of tags) {
|
|
101
|
+
const componentName = getComponentName(tag)
|
|
102
|
+
components.push(componentName)
|
|
103
|
+
if (verbose) {
|
|
104
|
+
console.info(`Processing ${componentName}...`)
|
|
105
|
+
}
|
|
106
|
+
tag.events = [...(tag.events || []), ...(ComponentsEventsMap[componentName] || [])]
|
|
107
|
+
|
|
108
|
+
const componentOutputDir = join(process.cwd(), outputDir, componentName)
|
|
109
|
+
const storyOutputDir = join(process.cwd(), FileName.storyOutputDir, 'v2', componentName)
|
|
110
|
+
const componentContent = renderComponent(tag)(language)(componentName)
|
|
111
|
+
|
|
112
|
+
await saveIndex(componentOutputDir, componentContent)
|
|
113
|
+
await saveStory(storyOutputDir, componentName, getStoriesContent(componentName, tag))
|
|
114
|
+
|
|
115
|
+
const packageName = getVividPackageName(tag.path)
|
|
116
|
+
const packageJsonContent = {
|
|
117
|
+
name: `@vonage/vivid-react-${tag.name}`,
|
|
118
|
+
version: packageJson.version,
|
|
119
|
+
main: indexFileName,
|
|
120
|
+
types: 'index.d.ts',
|
|
121
|
+
private: true,
|
|
122
|
+
license: 'MIT',
|
|
123
|
+
dependencies: {
|
|
124
|
+
[packageName]: packageJson.dependencies[packageName]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
await outputJson(join(componentOutputDir, FileName.packageJson), packageJsonContent, { spaces: 2 })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (language === OutputLanguage.JavaScript) {
|
|
131
|
+
await generateTypings(outputDir)(tags)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
prepareDir(filePath(FileName.tempFolder), cleanTemp, verbose)
|
|
135
|
+
|
|
136
|
+
if (verbose) {
|
|
137
|
+
console.info(`${components.length} wrappers generated at ${outputDir}`)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const renderComponentV3 = prefix => classDeclaration => language => componentClassName => {
|
|
142
|
+
const componentPrefix = prefix
|
|
143
|
+
const componentName = classDeclaration.name
|
|
144
|
+
const componentTagName = `${componentPrefix}-${camel2kebab(componentName)}`
|
|
145
|
+
const events = [...(classDeclaration.events?.map(({ name }) => name) || []), ...(ComponentsEventsMapV3[componentClassName] || [])]
|
|
146
|
+
const properties = classDeclaration.members?.filter(({ privacy = 'public', kind, readonly }) => kind === 'field' && privacy === 'public' && readonly !== true) || []
|
|
147
|
+
const attributes = classDeclaration.attributes?.filter(({ fieldName }) => properties.find(({ name }) => fieldName === name)) || []
|
|
148
|
+
const propertyNames = properties.map(({ name }) => `'${name}'`)
|
|
149
|
+
const props = [
|
|
150
|
+
...(events.map(x => x.propName || event2PropName(x.name || x)).map(x => ` ${x}?: (event: SyntheticEvent) => void`)),
|
|
151
|
+
...(properties.map(({ name, type }) => ` ${name}?: ${mapType(type?.text)}`))
|
|
152
|
+
]
|
|
153
|
+
const renderPropertyJsDoc = ({ type, name, attribute = null, description }) => `* @param ${type?.text ? `{${type?.text}}` : ''} ${name} ${description ? `- ${description}` : ''} ${attribute ? `**attribute** \`${attribute.name || attribute.fieldName}\`` : ''}`
|
|
154
|
+
const jsDoc = `/** ${classDeclaration.description || componentClassName} \n${properties.map((p) => ({ ...p, attribute: attributes.find(({ fieldName }) => fieldName === p.name) })).map(renderPropertyJsDoc).join('\n')}\n*/`
|
|
155
|
+
|
|
156
|
+
return getTemplate('react-component-v3', language)
|
|
157
|
+
.replace(TemplateToken.CLASS_JSDOC, jsDoc)
|
|
158
|
+
.replace(TemplateToken.ATTRIBUTES, '')
|
|
159
|
+
.replace(TemplateToken.PROP_TYPES, '')
|
|
160
|
+
.replace(TemplateToken.PROPS, props.join(',\n'))
|
|
161
|
+
.replace(TemplateToken.TAG_DESCRIPTOR_JSON, JSON.stringify(classDeclaration, null, ' '))
|
|
162
|
+
.replace(new RegExp(TemplateToken.COMPONENT_CLASS_NAME, 'g'), componentClassName)
|
|
163
|
+
.replace(new RegExp(TemplateToken.TAG_PREFIX, 'g'), componentPrefix)
|
|
164
|
+
.replace(new RegExp(TemplateToken.COMPONENT_NAME, 'g'), componentName)
|
|
165
|
+
.replace(new RegExp(TemplateToken.TAG, 'g'), componentTagName)
|
|
166
|
+
.replace(new RegExp(TemplateToken.EVENTS, 'g'), toJsonObjectsList(getUniqueEvents(events)))
|
|
167
|
+
.replace(new RegExp(TemplateToken.PROPERTIES, 'g'), propertyNames.join(', '))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Generates Vivid 3.x wrappers
|
|
172
|
+
*/
|
|
173
|
+
const generateWrappersV3 = (outputDir, language = OutputLanguage.JavaScript, cleanTemp = true, verbose = true) => async (meta) => {
|
|
174
|
+
const componentPrefix = 'vvd3'
|
|
175
|
+
const indexFileName = getIndexFileName(language)
|
|
176
|
+
const saveIndex = (outputDir, content) => {
|
|
177
|
+
const indexOutputFileName = join(outputDir, indexFileName)
|
|
178
|
+
return outputFile(
|
|
179
|
+
indexOutputFileName,
|
|
180
|
+
content
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const outDir = `${outputDir}/v3`
|
|
185
|
+
|
|
186
|
+
const classDeclarations = meta.elements.modules.reduce((acc, { declarations }) =>
|
|
187
|
+
[...acc, ...declarations.filter(({ kind }) => kind === 'class')]
|
|
188
|
+
, [])
|
|
189
|
+
|
|
190
|
+
for (const classDeclaration of classDeclarations) {
|
|
191
|
+
const componentName = `Vwc${classDeclaration.name}`
|
|
192
|
+
const componentNameKebab = camel2kebab(classDeclaration.name)
|
|
193
|
+
const componentOutputDir = join(process.cwd(), outDir, componentName)
|
|
194
|
+
const componentContent = renderComponentV3(componentPrefix)(classDeclaration)(language)(componentName)
|
|
195
|
+
await saveIndex(componentOutputDir, componentContent)
|
|
196
|
+
|
|
197
|
+
const packageName = '@vonage/vivid'
|
|
198
|
+
const packageJsonContent = {
|
|
199
|
+
name: `@vonage/vivid-react-${componentPrefix}-${componentNameKebab}`,
|
|
200
|
+
version: packageJson.dependencies[packageName],
|
|
201
|
+
main: indexFileName,
|
|
202
|
+
types: 'index.d.ts',
|
|
203
|
+
private: true,
|
|
204
|
+
license: 'MIT',
|
|
205
|
+
dependencies: {
|
|
206
|
+
[packageName]: packageJson.dependencies[packageName]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
await outputJson(join(componentOutputDir, FileName.packageJson), packageJsonContent, { spaces: 2 })
|
|
210
|
+
|
|
211
|
+
if (verbose) {
|
|
212
|
+
console.info(`${componentName}... v3`)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (language === OutputLanguage.TypeScript) {
|
|
217
|
+
const typesDir = filePath(FileName.types)
|
|
218
|
+
prepareDir(typesDir)
|
|
219
|
+
await outputFile(
|
|
220
|
+
join(typesDir, `index.d.ts`),
|
|
221
|
+
getTemplate('types', OutputLanguage.TypeScript)
|
|
222
|
+
.replace(TemplateToken.ELEMENT_TYPES,
|
|
223
|
+
classDeclarations.map(({ attributes, name }) => {
|
|
224
|
+
const componentTagName = `${componentPrefix}-${camel2kebab(name)}`
|
|
225
|
+
return getTemplate('element-type', OutputLanguage.TypeScript)
|
|
226
|
+
.replace(TemplateToken.TAG, componentTagName)
|
|
227
|
+
.replace(TemplateToken.ATTRIBUTES, (attributes || []).map(({ name, fieldName, type = { text: 'string' } }) => ` "${name || fieldName}": ${type.text};`).join('\n'))
|
|
228
|
+
}).join('\n')
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (language === OutputLanguage.JavaScript) {
|
|
234
|
+
const generatedDir = filePath(FileName.generatedFolder)
|
|
235
|
+
prepareDir(generatedDir)
|
|
236
|
+
|
|
237
|
+
writeFileSync(
|
|
238
|
+
`${generatedDir}/vivid.version.js`,
|
|
239
|
+
`export default { v2: '${packageJson.dependencies['@vonage/vvd-core']}', v3: \`${packageJson.dependencies['@vonage/vivid']}\`}`
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
for (const { name, file } of [
|
|
243
|
+
{ name: 'core.all', file: './node_modules/@vonage/vivid/styles/core/all.css' },
|
|
244
|
+
{ name: 'theme.light', file: './node_modules/@vonage/vivid/styles/tokens/theme-light.css' },
|
|
245
|
+
{ name: 'theme.dark', file: './node_modules/@vonage/vivid/styles/tokens/theme-dark.css' },
|
|
246
|
+
{ name: 'font.spezia', file: './node_modules/@vonage/vivid/styles/fonts/spezia-variable.css' }
|
|
247
|
+
]) {
|
|
248
|
+
const cssText = readFileSync(file, { encoding: 'utf8' }).replace(/\/\*# sourceMappingURL=.*\*\//g, '')
|
|
249
|
+
writeFileSync(
|
|
250
|
+
`${generatedDir}/style.${name}.js`,
|
|
251
|
+
`export default { id: '${name}', css: \`${cssText}\`}`
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
await generateTypingsV3(outputDir)(meta)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
prepareDir(filePath(FileName.tempFolder), cleanTemp, verbose)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
module.exports = {
|
|
262
|
+
generateWrappers,
|
|
263
|
+
generateWrappersV3
|
|
264
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { posix, win32 } = require('path')
|
|
2
|
+
|
|
3
|
+
const rootImportExclusions = ['vwc-tags']
|
|
4
|
+
|
|
5
|
+
module.exports.getImportsFromTag = ({ name, path }) => {
|
|
6
|
+
const normalizedPath = path.split(win32.sep).join(posix.sep)
|
|
7
|
+
const [, rootComponent] = /@vonage\/([\w-]+)\//g.exec(normalizedPath)
|
|
8
|
+
const result = []
|
|
9
|
+
if (rootComponent === name) {
|
|
10
|
+
result.push(`@vonage/${name}`)
|
|
11
|
+
} else {
|
|
12
|
+
if (rootImportExclusions.indexOf(rootComponent) < 0) {
|
|
13
|
+
result.push(`@vonage/${rootComponent}`)
|
|
14
|
+
}
|
|
15
|
+
result.push(`@vonage/${rootComponent}/${name}`)
|
|
16
|
+
}
|
|
17
|
+
return result.map(x => `import '${x}'`)
|
|
18
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const { posix, win32 } = require('path')
|
|
2
|
+
const { getImportsFromTag } = require('./generator')
|
|
3
|
+
|
|
4
|
+
describe('getImportsFromTag', () => {
|
|
5
|
+
const mainComponentTag = {
|
|
6
|
+
name: 'vwc-list',
|
|
7
|
+
path: './../node_modules/@vonage/vwc-list/src/vwc-list.ts'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const subComponentExclusionTag = {
|
|
11
|
+
name: 'vwc-tag',
|
|
12
|
+
path: './..\\node_modules\\@vonage\\vwc-tags\\vwc-tag.d.ts'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const subComponentTag = {
|
|
16
|
+
name: 'vwc-radio-list-item',
|
|
17
|
+
path: './../node_modules/@vonage/vwc-list/src/vwc-radio-list-item.ts'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
it('should create a default import for main component', () => {
|
|
21
|
+
const result = getImportsFromTag(mainComponentTag)
|
|
22
|
+
|
|
23
|
+
expect(result).toEqual([`import '@vonage/vwc-list'`])
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should create import from specific file for subcomponent and main component import', () => {
|
|
27
|
+
const result = getImportsFromTag(subComponentTag)
|
|
28
|
+
|
|
29
|
+
expect(result).toEqual([
|
|
30
|
+
`import '@vonage/vwc-list'`,
|
|
31
|
+
`import '@vonage/vwc-list/${subComponentTag.name}'`
|
|
32
|
+
])
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should create import from specific file for subcomponent with exclusion', () => {
|
|
36
|
+
const result = getImportsFromTag(subComponentExclusionTag)
|
|
37
|
+
|
|
38
|
+
expect(result).toEqual([
|
|
39
|
+
`import '@vonage/vwc-tags/${subComponentExclusionTag.name}'`
|
|
40
|
+
])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should work for win32 paths', () => {
|
|
44
|
+
const winTag = {
|
|
45
|
+
...subComponentTag,
|
|
46
|
+
path: subComponentTag.path.split(posix.sep).join(win32.sep)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const result = getImportsFromTag(winTag)
|
|
50
|
+
|
|
51
|
+
expect(result).toEqual([
|
|
52
|
+
`import '@vonage/vwc-list'`,
|
|
53
|
+
`import '@vonage/vwc-list/${subComponentTag.name}'`
|
|
54
|
+
])
|
|
55
|
+
})
|
|
56
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const { event2PropName, getProperties } = require('./utils')
|
|
2
|
+
|
|
3
|
+
// Common
|
|
4
|
+
|
|
5
|
+
const getEvents = tag => (tag.events || []).map(x => x.propName || event2PropName(x.name || x))
|
|
6
|
+
const isTypeSet = type => /(".*?" \|)/.test(type)
|
|
7
|
+
const isStringTypeSet = type => /".*"[ |]?/.test(type) && /".*"[ |]?/.exec(type)[0] === type
|
|
8
|
+
const isBoolean = type => /^(true|false)$/.test(type) || type === 'boolean'
|
|
9
|
+
const isArray = type => /(.*)\[\]$/gm.test(type) || type === 'array'
|
|
10
|
+
const isNumber = type => /(integer)/.test(type) || type === 'number | null'
|
|
11
|
+
|
|
12
|
+
// TypeScript
|
|
13
|
+
const mapType = type => ([
|
|
14
|
+
'boolean',
|
|
15
|
+
'Boolean',
|
|
16
|
+
'string',
|
|
17
|
+
'string | null',
|
|
18
|
+
'string | undefined',
|
|
19
|
+
'string | number',
|
|
20
|
+
'number',
|
|
21
|
+
'unknown'].indexOf(type) >= 0 ||
|
|
22
|
+
isTypeSet(type))
|
|
23
|
+
? type
|
|
24
|
+
: isBoolean(type)
|
|
25
|
+
? 'boolean'
|
|
26
|
+
: isNumber(type)
|
|
27
|
+
? 'number'
|
|
28
|
+
: isArray(type)
|
|
29
|
+
? 'any[]'
|
|
30
|
+
: `any /* ${type} */`
|
|
31
|
+
|
|
32
|
+
const getProps = tag => {
|
|
33
|
+
const eventsProps = getEvents(tag).map(x => ` ${x}?: (event: SyntheticEvent) => void`)
|
|
34
|
+
|
|
35
|
+
const properties = getProperties(tag)
|
|
36
|
+
const props = properties.map(x => ` ${x.name}?: ${mapType(x.type)}`)
|
|
37
|
+
|
|
38
|
+
return [
|
|
39
|
+
...eventsProps,
|
|
40
|
+
...props
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// JavaScript
|
|
45
|
+
|
|
46
|
+
const getDefaultProps = tag => {
|
|
47
|
+
const defaultProperties = getProperties(tag).filter(x => x.default)
|
|
48
|
+
return defaultProperties.map(x => ` ${x.name}: ${x.default}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getPropTypes = tag => {
|
|
52
|
+
const eventsPropTypes = getEvents(tag).map(x => ` ${x}: PropTypes.func`)
|
|
53
|
+
|
|
54
|
+
const properties = getProperties(tag)
|
|
55
|
+
const isString = type => type === 'string | undefined' || type === 'string | null'
|
|
56
|
+
const getSetTypeOptions = setType => setType.split('|').map(x => x.trim())
|
|
57
|
+
const mapTypeToPropType = type => ['boolean', 'string', 'number', 'array'].indexOf(type) >= 0
|
|
58
|
+
? (type === 'boolean' ? 'bool' : type)
|
|
59
|
+
: isStringTypeSet(type)
|
|
60
|
+
? `oneOf([${getSetTypeOptions(type).join(',')}])`
|
|
61
|
+
: isString(type)
|
|
62
|
+
? 'string'
|
|
63
|
+
: isNumber(type)
|
|
64
|
+
? 'number'
|
|
65
|
+
: isArray(type)
|
|
66
|
+
? 'array'
|
|
67
|
+
: isBoolean(type)
|
|
68
|
+
? 'bool'
|
|
69
|
+
: `any /* ${type || 'type not provided'} */`
|
|
70
|
+
const propertiesPropTypes = properties.map(x =>
|
|
71
|
+
` ${x.name}: PropTypes.${mapTypeToPropType(x.type)}${x.default ? `/* default: ${x.default} */` : ''}${x.attribute ? `/* attribute: ${x.attribute} */` : ''}`)
|
|
72
|
+
|
|
73
|
+
return [
|
|
74
|
+
...eventsPropTypes,
|
|
75
|
+
...propertiesPropTypes
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
// JavaScript
|
|
81
|
+
getDefaultProps,
|
|
82
|
+
getPropTypes,
|
|
83
|
+
|
|
84
|
+
// TypeScript
|
|
85
|
+
getProps,
|
|
86
|
+
mapType
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<% banner %>
|
|
2
|
+
/*
|
|
3
|
+
Code in this file were generated using following JSON:
|
|
4
|
+
<% descriptor-json %>
|
|
5
|
+
*/
|
|
6
|
+
import wrapper from '@vonage/vivid-react-wrapper'
|
|
7
|
+
import { register<% component-name %> } from '@vonage/vivid'
|
|
8
|
+
|
|
9
|
+
register<% component-name %>('<% tag-prefix %>')
|
|
10
|
+
|
|
11
|
+
const <% component-class-name %> = wrapper(`<% tag %>`, {
|
|
12
|
+
events: [<% events %>],
|
|
13
|
+
attributes: [<% attributes %>],
|
|
14
|
+
properties: [<% properties %>]
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
<% component-class-name %>.displayName = '<% component-class-name %>'
|
|
18
|
+
|
|
19
|
+
export default <% component-class-name %>
|