@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,30 @@
|
|
|
1
|
+
<% banner %>
|
|
2
|
+
/*
|
|
3
|
+
Code in this file were generated using following JSON:
|
|
4
|
+
<% descriptor-json %>
|
|
5
|
+
*/
|
|
6
|
+
import PropTypes from 'prop-types'
|
|
7
|
+
import wrapper from '@vonage/vivid-react-wrapper'
|
|
8
|
+
<% imports %>
|
|
9
|
+
<% react-import %>
|
|
10
|
+
|
|
11
|
+
<% jsdoc.class %>
|
|
12
|
+
const <% component-class-name %> = wrapper('<% tag %>', {
|
|
13
|
+
events: [<% events %>],
|
|
14
|
+
attributes: [<% attributes %>],
|
|
15
|
+
properties: [<% properties %>]
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
<% component-class-name %>.propTypes = {
|
|
19
|
+
<% prop-types %>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
<% component-class-name %>.defaultProps = {
|
|
23
|
+
<% default-props %>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
<% component-class-name %>.displayName = '<% component-class-name %>'
|
|
27
|
+
|
|
28
|
+
<% compound-components %>
|
|
29
|
+
|
|
30
|
+
export default <% component-class-name %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import <% component-class-name %> from '../../../dist/<% component-class-name %>'
|
|
3
|
+
|
|
4
|
+
export const Default = () => <<% component-class-name %> />
|
|
5
|
+
export default {
|
|
6
|
+
title: 'V2/<% component-class-name %>',
|
|
7
|
+
argTypes: {
|
|
8
|
+
//
|
|
9
|
+
// Example values
|
|
10
|
+
// numberValue: { control: 'number', defaultValue: 123 },
|
|
11
|
+
// booleanValue: { control: 'boolean', defaultValue: true },
|
|
12
|
+
// objectValue: { control: 'object', defaultValue: {} },
|
|
13
|
+
// stringValue: { control: 'string', defaultValue: 'string' },
|
|
14
|
+
// colorValue: { control: 'color' },
|
|
15
|
+
// dateValue: { control: 'date' }
|
|
16
|
+
//
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Purpose: Support code-generation activities with templates
|
|
3
|
+
*/
|
|
4
|
+
const { readFileSync } = require('fs')
|
|
5
|
+
|
|
6
|
+
const TemplateToken = {
|
|
7
|
+
BANNER: '<% banner %>',
|
|
8
|
+
IMPORTS: '<% imports %>',
|
|
9
|
+
EXPORTS: '<% exports %>',
|
|
10
|
+
TAG: '<% tag %>',
|
|
11
|
+
ELEMENT_TYPES: '<% element-types %>',
|
|
12
|
+
COMPONENT_CLASS_NAME: '<% component-class-name %>',
|
|
13
|
+
COMPONENT_NAME: '<% component-name %>',
|
|
14
|
+
TAG_PREFIX: '<% tag-prefix %>',
|
|
15
|
+
PROP_TYPES: '<% prop-types %>',
|
|
16
|
+
PROPS: '<% props %>',
|
|
17
|
+
DEFAULT_PROPS: '<% default-props %>',
|
|
18
|
+
PROPERTIES: '<% properties %>',
|
|
19
|
+
ATTRIBUTES: '<% attributes %>',
|
|
20
|
+
EVENTS: '<% events %>',
|
|
21
|
+
CLASS_JSDOC: '<% jsdoc.class %>',
|
|
22
|
+
TAG_DESCRIPTOR_JSON: '<% descriptor-json %>',
|
|
23
|
+
COMPOUND_COMPONENTS: '<% compound-components %>',
|
|
24
|
+
REACT_IMPORT: '<% react-import %>'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const GENERATED_CODE_BANNER = `/*
|
|
28
|
+
* DO NOT EDIT THIS FILE. IT IS GENERATED
|
|
29
|
+
*/`
|
|
30
|
+
const templatesFolder = `${__dirname}`
|
|
31
|
+
const getTemplate = (template, language) =>
|
|
32
|
+
readFileSync(`${templatesFolder}/${language}/${template}.tmpl`, { encoding: 'utf8' })
|
|
33
|
+
.replace(TemplateToken.BANNER, GENERATED_CODE_BANNER)
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
getTemplate,
|
|
37
|
+
TemplateToken,
|
|
38
|
+
GENERATED_CODE_BANNER
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<% banner %>
|
|
2
|
+
/*
|
|
3
|
+
Code in this file were generated using following JSON:
|
|
4
|
+
<% descriptor-json %>
|
|
5
|
+
*/
|
|
6
|
+
import React, { ReactNode, SyntheticEvent, ForwardRefExoticComponent } from 'react'
|
|
7
|
+
import wrapper from '@vonage/vivid-react-wrapper'
|
|
8
|
+
import { register<% component-name %> } from '@vonage/vivid'
|
|
9
|
+
|
|
10
|
+
register<% component-name %>('<% tag-prefix %>')
|
|
11
|
+
|
|
12
|
+
const WrappedComponent = wrapper(`<% tag %>`, {
|
|
13
|
+
events: [<% events %>],
|
|
14
|
+
attributes: [<% attributes %>],
|
|
15
|
+
properties: [<% properties %>]
|
|
16
|
+
}) as ForwardRefExoticComponent<any>;
|
|
17
|
+
|
|
18
|
+
<% jsdoc.class %>
|
|
19
|
+
const <% component-class-name %> = (props:
|
|
20
|
+
{
|
|
21
|
+
children?: ReactNode,
|
|
22
|
+
slot?: string,
|
|
23
|
+
id?: string,
|
|
24
|
+
style?: React.CSSProperties,
|
|
25
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined,
|
|
26
|
+
<% props %>
|
|
27
|
+
}
|
|
28
|
+
): JSX.Element => <WrappedComponent {...props}>{props.children}</WrappedComponent>
|
|
29
|
+
|
|
30
|
+
<% component-class-name %>.displayName = '<% component-class-name %>'
|
|
31
|
+
|
|
32
|
+
export default <% component-class-name %>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<% banner %>
|
|
2
|
+
/*
|
|
3
|
+
Code in this file were generated using following JSON:
|
|
4
|
+
<% descriptor-json %>
|
|
5
|
+
*/
|
|
6
|
+
import React, { ReactNode, SyntheticEvent, ForwardRefExoticComponent } from 'react'
|
|
7
|
+
import wrapper from '@vonage/vivid-react-wrapper'
|
|
8
|
+
<% imports %>
|
|
9
|
+
|
|
10
|
+
const WrappedComponent = wrapper('<% tag %>', {
|
|
11
|
+
events: [<% events %>],
|
|
12
|
+
attributes: [<% attributes %>],
|
|
13
|
+
properties: [<% properties %>]
|
|
14
|
+
}) as ForwardRefExoticComponent<any>;
|
|
15
|
+
|
|
16
|
+
<% jsdoc.class %>
|
|
17
|
+
const <% component-class-name %> = (props:
|
|
18
|
+
{
|
|
19
|
+
children?: ReactNode,
|
|
20
|
+
slot?: string,
|
|
21
|
+
id?: string,
|
|
22
|
+
style?: React.CSSProperties,
|
|
23
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined,
|
|
24
|
+
<% props %>
|
|
25
|
+
}
|
|
26
|
+
): JSX.Element => <WrappedComponent {...props}>{props.children}</WrappedComponent>
|
|
27
|
+
|
|
28
|
+
export default <% component-class-name %>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
const { join, parse } = require('path')
|
|
2
|
+
const { flowRight, map, replace, reverse, startCase, uniqBy } = require('lodash/fp')
|
|
3
|
+
const { access, F_OK, readFileSync, existsSync, rmSync } = require('fs')
|
|
4
|
+
const mkdirp = require('mkdirp')
|
|
5
|
+
const { spawnSync } = require('child_process')
|
|
6
|
+
const { WCAConfig, VividRepo, FileName, OutputLanguage, ComponentsBindablePropertiesMap, ComponentsReadOnlyPropertiesMap, ComponentsExtraPropertiesMap } = require('./consts')
|
|
7
|
+
const { copySync } = require('fs-extra')
|
|
8
|
+
|
|
9
|
+
const renderPropertyJsDoc = tag => property => `* @param ${property.type ? `{${property.type}}` : ''} ${property.name} ${property.description ? `- ${property.description}` : ''} ${property.attribute ? `attribute: <${getComponentName(tag)} ${property.attribute} />` : ''}`
|
|
10
|
+
const renderTagPropertiesJsDoc = tag => getProperties(tag).map(renderPropertyJsDoc(tag)).join('\n')
|
|
11
|
+
const renderJsDoc = tag => `/** ${tag.description || ''} \n${renderTagPropertiesJsDoc(tag)}\n*/`
|
|
12
|
+
const stripQuotes = input => input.replace(/'/g, '')
|
|
13
|
+
const unique = stringArray => Array.from(new Set(stringArray))
|
|
14
|
+
const toJsonObjectsList = collection => (collection || []).map(JSON.stringify).join(',')
|
|
15
|
+
const toCommaSeparatedList = collection => (collection || []).map(x => `'${stripQuotes(x.name)}'`).join(',')
|
|
16
|
+
const capitalize = input => input.replace(/(^|\s)[a-z]/g, s => s.toUpperCase())
|
|
17
|
+
const deCapitalize = input => input.replace(/(^|\s)[A-Z]/g, s => s.toLowerCase())
|
|
18
|
+
const getComponentName = tag => capitalize(kebab2Camel(tag.name))
|
|
19
|
+
const camel2kebab = input => deCapitalize(input).replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, '-').toLowerCase()
|
|
20
|
+
const kebab2Camel = input => deCapitalize(input.split('-').map(x => capitalize(x)).join(''))
|
|
21
|
+
const snake2Camel = input => deCapitalize(input.split('_').map(x => capitalize(x)).join(''))
|
|
22
|
+
const event2PropName = eventName => `on${capitalize(kebab2Camel(snake2Camel(eventName)))}`
|
|
23
|
+
const event2EventDescriptor = event => typeof event === 'string'
|
|
24
|
+
? ({ name: event, propName: event2PropName(event) })
|
|
25
|
+
: event
|
|
26
|
+
const getUniqueEvents = flowRight(
|
|
27
|
+
uniqBy('name'),
|
|
28
|
+
// need to reverse to have custom events first, to allow overwriting of the ones grabbed from JSDocs
|
|
29
|
+
reverse,
|
|
30
|
+
map(event2EventDescriptor)
|
|
31
|
+
)
|
|
32
|
+
const isVividPackageName = (packageName) => /@vonage\/vwc-*/.test(packageName)
|
|
33
|
+
const getIndexFileName = language => `index.${language === OutputLanguage.TypeScript ? 'tsx' : language}`
|
|
34
|
+
const getVividPackageName = componentPath => {
|
|
35
|
+
const { dir } = parse(componentPath)
|
|
36
|
+
if (dir.indexOf('node_modules') >= 0) {
|
|
37
|
+
return /(@vonage\/vwc-.*?)\//.exec(componentPath.replace(/\\/g, '/'))[1]
|
|
38
|
+
}
|
|
39
|
+
const pathParts = dir.split('\\').join('/').split('/')
|
|
40
|
+
if (pathParts.length > 0 && pathParts[pathParts.length - 1] === 'src') {
|
|
41
|
+
pathParts.pop()
|
|
42
|
+
}
|
|
43
|
+
const packageJson = filePath(join(FileName.tempFolder, ...pathParts, FileName.packageJson))
|
|
44
|
+
const pkg = getParsedJson(packageJson)
|
|
45
|
+
return pkg.name
|
|
46
|
+
}
|
|
47
|
+
const prepareDir = (p, clean = true, verbose = true) => {
|
|
48
|
+
if (clean && existsSync(p)) {
|
|
49
|
+
if (verbose) {
|
|
50
|
+
console.info(`Clearing folder: ${p}`)
|
|
51
|
+
}
|
|
52
|
+
rmSync(p, { recursive: true })
|
|
53
|
+
}
|
|
54
|
+
mkdirp.sync(p)
|
|
55
|
+
}
|
|
56
|
+
const getProperties = tag => (tag.properties || [])
|
|
57
|
+
.filter(prop => !(ComponentsReadOnlyPropertiesMap[getComponentName(tag)] || []).includes(prop.name)) // skip readonly properties
|
|
58
|
+
.filter(prop => /'.*?'/.test(prop.name) ||
|
|
59
|
+
/^([a-zA-Z_$][a-zA-Z\\d_$]*)$/.test(prop.name)) // only props having valid names
|
|
60
|
+
.map(prop => {
|
|
61
|
+
const isBindable = (ComponentsBindablePropertiesMap[getComponentName(tag)] || []).includes(prop.name) ||
|
|
62
|
+
prop.type?.indexOf('=>') > 0 || // property type is function
|
|
63
|
+
prop.type?.indexOf('[]') > 0 // property type is array
|
|
64
|
+
prop.bindable = isBindable
|
|
65
|
+
return prop
|
|
66
|
+
}).concat(ComponentsExtraPropertiesMap[getComponentName(tag)] || [])
|
|
67
|
+
|
|
68
|
+
const isFileExists = (fileName) => new Promise(
|
|
69
|
+
(resolve, reject) => access(
|
|
70
|
+
filePath(fileName),
|
|
71
|
+
F_OK,
|
|
72
|
+
error => error
|
|
73
|
+
? reject(error)
|
|
74
|
+
: resolve(fileName)
|
|
75
|
+
))
|
|
76
|
+
const filePath = (fileName) => join(process.cwd(), fileName)
|
|
77
|
+
|
|
78
|
+
const readMetaData = () => new Promise(
|
|
79
|
+
(resolve) => {
|
|
80
|
+
const vividPackageFolder = join(process.cwd(), 'node_modules/@vonage/vivid')
|
|
81
|
+
const elementsMetaData = `${vividPackageFolder}/${FileName.customElements}`
|
|
82
|
+
const apiMetaData = `${vividPackageFolder}/${FileName.vividApi}`
|
|
83
|
+
const meta = {
|
|
84
|
+
api: getParsedJson(apiMetaData),
|
|
85
|
+
elements: getParsedJson(elementsMetaData)
|
|
86
|
+
}
|
|
87
|
+
resolve(meta)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const getParsedJson = (jsonFilePath) => JSON.parse(readFileSync(jsonFilePath, { encoding: 'utf8' }))
|
|
91
|
+
|
|
92
|
+
const getVividPackageNames = ({ dependencies, devDependencies }) => {
|
|
93
|
+
const packages = [
|
|
94
|
+
...Object.keys(dependencies),
|
|
95
|
+
...Object.keys(devDependencies)
|
|
96
|
+
]
|
|
97
|
+
const result = unique(packages).filter(isVividPackageName)
|
|
98
|
+
console.log(`Vivid packages detected from ${FileName.packageJson}: \n${result.map(x => ` - ${x}`).join('\n')}`)
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const getCustomElementTagsDefinitionsList = (config = WCAConfig) => (vividPackageNames) => new Promise((resolve) => {
|
|
103
|
+
const analyzerOutput = filePath(join(config.tempFolder, config.tempFileName))
|
|
104
|
+
const child = spawnSync(
|
|
105
|
+
'node',
|
|
106
|
+
config.nodeArgumentsFactory(vividPackageNames, analyzerOutput),
|
|
107
|
+
{ cwd: process.cwd() }
|
|
108
|
+
)
|
|
109
|
+
if (child.status === 0) {
|
|
110
|
+
const output = getParsedJson(analyzerOutput)
|
|
111
|
+
const uniqueTags = unique(output.tags.map(x => x.name)).map(x => output.tags.find(y => y.name === x))
|
|
112
|
+
return resolve(uniqueTags)
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const compileTypescript = (rootDir) => async (outDir) =>
|
|
117
|
+
spawnSync(
|
|
118
|
+
'node',
|
|
119
|
+
[
|
|
120
|
+
'./node_modules/typescript/lib/tsc.js',
|
|
121
|
+
'--project',
|
|
122
|
+
filePath('tsconfig.json'),
|
|
123
|
+
'--rootDir',
|
|
124
|
+
rootDir,
|
|
125
|
+
'--outDir',
|
|
126
|
+
outDir
|
|
127
|
+
]
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
const copyStaticAssets = (outputDir, assets) => () => {
|
|
131
|
+
const cp = file => {
|
|
132
|
+
const source = filePath(file)
|
|
133
|
+
const dest = filePath(join(outputDir, file))
|
|
134
|
+
copySync(source, dest)
|
|
135
|
+
console.info(`Copy static asset ${source} => ${dest}`)
|
|
136
|
+
}
|
|
137
|
+
assets.split(',').map(assetFileName => cp(assetFileName))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const getInputArgument = (argumentName, defaultValue = null) => {
|
|
141
|
+
const argumentObjects = process.argv
|
|
142
|
+
.filter(argument => argument.indexOf('=') >= 0)
|
|
143
|
+
.map(argument => ({
|
|
144
|
+
name: argument.split('=')[0].replace(/--/g, ''),
|
|
145
|
+
value: argument.split('=')[1]
|
|
146
|
+
}))
|
|
147
|
+
const targetArgument = argumentObjects.find(argumentObject => argumentObject.name === argumentName)
|
|
148
|
+
return targetArgument ? targetArgument.value : defaultValue
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const getComponentNameFromPackage = flowRight(
|
|
152
|
+
replace(/\s/g, ''),
|
|
153
|
+
startCase,
|
|
154
|
+
replace('@vonage/', '')
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
const compoundComponentTemplate = (baseName, compositeName, defaultProps) =>
|
|
158
|
+
`const ${compositeName} = (props) => createElement(${baseName}, props)
|
|
159
|
+
|
|
160
|
+
${compositeName}.defaultProps = ${JSON.stringify(defaultProps)}
|
|
161
|
+
|
|
162
|
+
${baseName}.${compositeName} = ${compositeName}`
|
|
163
|
+
|
|
164
|
+
const prepareCompoundComponents = (baseName, template, compoundComponentsConfig = {}) => () => Object
|
|
165
|
+
.entries(compoundComponentsConfig)
|
|
166
|
+
.map(([compositeName, defaultProps]) => template(baseName, compositeName, defaultProps))
|
|
167
|
+
.join('\n\n')
|
|
168
|
+
|
|
169
|
+
module.exports = {
|
|
170
|
+
toCommaSeparatedList,
|
|
171
|
+
toJsonObjectsList,
|
|
172
|
+
compileTypescript,
|
|
173
|
+
filePath,
|
|
174
|
+
prepareDir,
|
|
175
|
+
renderJsDoc,
|
|
176
|
+
capitalize,
|
|
177
|
+
kebab2Camel,
|
|
178
|
+
event2PropName,
|
|
179
|
+
event2EventDescriptor,
|
|
180
|
+
getComponentNameFromPackage,
|
|
181
|
+
getInputArgument,
|
|
182
|
+
getUniqueEvents,
|
|
183
|
+
readMetaData,
|
|
184
|
+
camel2kebab,
|
|
185
|
+
isFileExists,
|
|
186
|
+
isVividPackageName,
|
|
187
|
+
copyStaticAssets,
|
|
188
|
+
getIndexFileName,
|
|
189
|
+
getProperties,
|
|
190
|
+
getComponentName,
|
|
191
|
+
getParsedJson,
|
|
192
|
+
getVividPackageName,
|
|
193
|
+
getVividPackageNames,
|
|
194
|
+
getCustomElementTagsDefinitionsList,
|
|
195
|
+
prepareCompoundComponents,
|
|
196
|
+
compoundComponentTemplate
|
|
197
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
import { getUniqueEvents } from './utils'
|
|
3
|
+
|
|
4
|
+
const { getVividPackageNames, event2PropName, prepareCompoundComponents } = require('./utils')
|
|
5
|
+
|
|
6
|
+
it('getVividPackageNames', () => {
|
|
7
|
+
const packageJson = {
|
|
8
|
+
dependencies: {
|
|
9
|
+
'@vonage/vwc-button': '0.1',
|
|
10
|
+
'@vonage/vwc-icon': '0.2',
|
|
11
|
+
'@nvm/vwc-badge': '0.2'
|
|
12
|
+
},
|
|
13
|
+
devDependencies: {
|
|
14
|
+
'@vonage/vwc-dropdown': '0.1',
|
|
15
|
+
'@vonage/component': '0.2'
|
|
16
|
+
},
|
|
17
|
+
otherDependencies: {
|
|
18
|
+
'@vonage/vwc-nav': '0.3'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const expectedList = [
|
|
22
|
+
'@vonage/vwc-button',
|
|
23
|
+
'@vonage/vwc-icon',
|
|
24
|
+
'@vonage/vwc-dropdown'
|
|
25
|
+
]
|
|
26
|
+
expect(getVividPackageNames(packageJson)).toStrictEqual(expectedList)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it.each([
|
|
30
|
+
['digit-added', 'onDigitAdded'],
|
|
31
|
+
['userScrubRequest', 'onUserScrubRequest'],
|
|
32
|
+
['vvd_scheme_select', 'onVvdSchemeSelect']
|
|
33
|
+
])(`event2PropName should convert "%s" to "%s"`, (input, expected) => {
|
|
34
|
+
expect(event2PropName(input)).toStrictEqual(expected)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('compound components', () => {
|
|
38
|
+
const template = jest.fn()
|
|
39
|
+
const config = {
|
|
40
|
+
CTA: {
|
|
41
|
+
connotation: 'cta',
|
|
42
|
+
layout: 'filled'
|
|
43
|
+
},
|
|
44
|
+
Alert: {
|
|
45
|
+
connotation: 'alert',
|
|
46
|
+
layout: 'filled'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
prepareCompoundComponents('VwcButton', template, config)()
|
|
51
|
+
|
|
52
|
+
expect(template.mock.calls[0]).toEqual([
|
|
53
|
+
'VwcButton',
|
|
54
|
+
'CTA',
|
|
55
|
+
config.CTA
|
|
56
|
+
])
|
|
57
|
+
expect(template.mock.calls[1]).toEqual([
|
|
58
|
+
'VwcButton',
|
|
59
|
+
'Alert',
|
|
60
|
+
config.Alert
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('getUniqueEvents', () => {
|
|
65
|
+
const firstEvent = { name: 'non-unique', propName: 'replaced' }
|
|
66
|
+
const secondEvent = { name: 'non-unique', propName: 'targetPropName' }
|
|
67
|
+
const uniqueEvent = { name: 'unique', propName: 'onUnique' }
|
|
68
|
+
const events = [firstEvent, secondEvent, uniqueEvent]
|
|
69
|
+
|
|
70
|
+
expect(getUniqueEvents(events)).toEqual([uniqueEvent, secondEvent])
|
|
71
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const os = require('os')
|
|
2
|
+
const { getComponentNameFromPackage } = require('./generateWrappers/utils')
|
|
3
|
+
const { outputFile, readFile } = require('fs-extra')
|
|
4
|
+
|
|
5
|
+
const { isVividPackageName } = require('./generateWrappers/utils')
|
|
6
|
+
const { dependencies, devDependencies } = require('../package.json')
|
|
7
|
+
|
|
8
|
+
const generateSupportedComponents = () => {
|
|
9
|
+
const allDeps = Object.entries({
|
|
10
|
+
...devDependencies,
|
|
11
|
+
...dependencies
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const reducePackagesToVividComponentsList = (acc, [name, version]) => {
|
|
15
|
+
if (!isVividPackageName(name)) {
|
|
16
|
+
return acc
|
|
17
|
+
}
|
|
18
|
+
const componentName = getComponentNameFromPackage(name)
|
|
19
|
+
return [...acc, `| ${componentName} | ${name} | ${version} |`]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return allDeps.reduce(
|
|
23
|
+
reducePackagesToVividComponentsList,
|
|
24
|
+
[
|
|
25
|
+
'| Component Name | Package Name | Package Version |',
|
|
26
|
+
'|----------------|--------------|-----------------|'
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const updateSupportedComponents = async (readmePath) => {
|
|
32
|
+
const packageList = generateSupportedComponents()
|
|
33
|
+
const readme = await readFile(readmePath, { encoding: 'utf8' })
|
|
34
|
+
await outputFile(
|
|
35
|
+
readmePath,
|
|
36
|
+
// this finds a table, might be a problem if we have more than one ;)
|
|
37
|
+
// need the extra empty string to have a new line before the next section
|
|
38
|
+
readme.replace(/((\|[ -][^|\r\n]*)+\|(\r?\n|\r)?)+/gm, [...packageList, ''].join(os.EOL))
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updateSupportedComponents('README.md')
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const ora = require('ora')
|
|
2
|
+
const { EOL } = require('os')
|
|
3
|
+
const { spawn } = require('child_process')
|
|
4
|
+
const { dependencies } = require('../package.json')
|
|
5
|
+
|
|
6
|
+
const spinner = ora()
|
|
7
|
+
|
|
8
|
+
const spawnPromise = (...args) => new Promise((resolve, reject) => {
|
|
9
|
+
const cmd = spawn(...args)
|
|
10
|
+
const stdout = []
|
|
11
|
+
const stderr = []
|
|
12
|
+
cmd.stdout.on('data', (data) => stdout.push(data))
|
|
13
|
+
cmd.stderr.on('data', (data) => stderr.push(data))
|
|
14
|
+
cmd.on('close', (status) => status ? reject(stderr.join('')) : resolve(stdout.join('')))
|
|
15
|
+
cmd.on('error', () => reject(stderr.join('')))
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
// TODO: find a better way to load complete search results when searching NPM
|
|
19
|
+
// naive way to force paging when doing NPM search
|
|
20
|
+
// NPM limits the number of packages it returns and drops some versions and packages all together
|
|
21
|
+
const forcePaging = (pattern = '') =>
|
|
22
|
+
'abcdefghijklmnopqrstuvwxyz'.split('').map((letter) => `${pattern}-${letter}`)
|
|
23
|
+
|
|
24
|
+
const ignoredPackages = [
|
|
25
|
+
'@vonage/vwc-angular-forms',
|
|
26
|
+
'@vonage/vwc-angular-dialog',
|
|
27
|
+
'@vonage/vwc-toggle-buttons-group',
|
|
28
|
+
'@vonage/vwc-relative-time'
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const defaultPatterns = [
|
|
32
|
+
'vonage/vvd-context',
|
|
33
|
+
'vonage/vvd-core',
|
|
34
|
+
'vonage/vvd-fonts',
|
|
35
|
+
...forcePaging('vonage/vwc')
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const removeIgnoredPackages = ({ name }) => !ignoredPackages.includes(name)
|
|
39
|
+
|
|
40
|
+
const keepOnlyChangedPackages = ({ name, version }) => dependencies[name] !== `^${version}`
|
|
41
|
+
|
|
42
|
+
const getPackages = async (patterns = defaultPatterns) => {
|
|
43
|
+
const packages = []
|
|
44
|
+
spinner.start('')
|
|
45
|
+
for (const pattern of patterns) {
|
|
46
|
+
spinner.text = `Searching for Vivid packages to update. [found: ${packages.length}]`
|
|
47
|
+
try {
|
|
48
|
+
const stdout = await spawnPromise('npm', ['search', '--json', '--no-description', pattern], { encoding: 'utf8' })
|
|
49
|
+
packages.push(...JSON.parse(stdout).filter(removeIgnoredPackages).filter(keepOnlyChangedPackages))
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
spinner.clear()
|
|
54
|
+
return packages
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const updatePackageJson = async () => {
|
|
58
|
+
const packages = await getPackages()
|
|
59
|
+
if (!packages.length) {
|
|
60
|
+
spinner.info('Nothing to update. All packages already in latest versions.')
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
let updated = 0
|
|
64
|
+
spinner.succeed(`Found ${packages.length} packages needing update.`)
|
|
65
|
+
spinner.start()
|
|
66
|
+
for (const { name, version } of packages) {
|
|
67
|
+
const versionedPackage = `${name}@^${version}`
|
|
68
|
+
spinner.text = `Updating '${name}@${dependencies[name]}' to '^${version}'. [updated: ${updated}/${packages.length}]`
|
|
69
|
+
try {
|
|
70
|
+
await spawnPromise('yarn', ['add', versionedPackage], { encoding: 'utf8' })
|
|
71
|
+
updated++
|
|
72
|
+
} catch (errorMessage) {
|
|
73
|
+
spinner.fail()
|
|
74
|
+
spinner.fail(errorMessage.trim(EOL))
|
|
75
|
+
spinner.start()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
spinner.info(`Updated ${updated} of ${packages.length}`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
updatePackageJson()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* global HTMLElement */
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Renders the cell contents using React 18.x api
|
|
6
|
+
*
|
|
7
|
+
* @param {ReactNode} children - renderer contents
|
|
8
|
+
* @param {Container & { rootRenderer?: Root }} container - HTMLElement root container
|
|
9
|
+
*/
|
|
10
|
+
export const cellRendererFactory = (children, container) => {
|
|
11
|
+
const root = container?.rootRenderer ?? createRoot(container)
|
|
12
|
+
|
|
13
|
+
root.render(children)
|
|
14
|
+
container.rootRenderer = root
|
|
15
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* global HTMLElement */
|
|
2
|
+
import context from '@vonage/vvd-context'
|
|
3
|
+
import { init } from '@vonage/vvd-fonts'
|
|
4
|
+
|
|
5
|
+
import coreStyles from './../generated/style.core.all'
|
|
6
|
+
import darkThemeStyles from './../generated/style.theme.dark'
|
|
7
|
+
import lightThemeStyles from './../generated/style.theme.light'
|
|
8
|
+
import fontSpeziaStyles from './../generated/style.font.spezia'
|
|
9
|
+
import vividVersion from './../generated/vivid.version'
|
|
10
|
+
|
|
11
|
+
const vividDataAttributePrefix = 'data-vivid'
|
|
12
|
+
|
|
13
|
+
const appendStyleElement = (document = window.document) => (styleDescriptor) => {
|
|
14
|
+
const attributeName = `${vividDataAttributePrefix}-id`
|
|
15
|
+
if (document.querySelectorAll(`[${attributeName}="${styleDescriptor.id}"]`).length > 0) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
const styleElement = document.createElement('style')
|
|
19
|
+
styleElement.setAttribute('type', 'text/css')
|
|
20
|
+
styleElement.setAttribute(attributeName, styleDescriptor.id)
|
|
21
|
+
styleElement.innerHTML = styleDescriptor.css
|
|
22
|
+
document.head.append(styleElement)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* mounts Vivid context (styles) & Fonts into the target scope / document
|
|
27
|
+
* - target scope may by any `HTMLElement` or `Document` or `DocumentFragment` (including `ShadowRoot`)
|
|
28
|
+
* - default target (when not specified) is the document visible in the current scope
|
|
29
|
+
* - the API is idempotent, the style/s will be mounted only once, even if API called multiple times
|
|
30
|
+
*
|
|
31
|
+
* @param {Document | DocumentFragment | HTMLElement} target - target document/shadow root/element to mount the CSS into
|
|
32
|
+
* @param {Function} callback - callback function to be invoked once init is done
|
|
33
|
+
* @param {Object} options - options config how to init vivid. `theme` - dark | light, `font` - proprietary | oss
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} error - if the provided target argument is `null` or not a Node of type `Document` / `DocumentFragment` / `HTMLElement`
|
|
36
|
+
*/
|
|
37
|
+
export const initVivid = (target, callback, options) => {
|
|
38
|
+
if (target instanceof HTMLElement) {
|
|
39
|
+
target.classList.add('vivid-scope') // vivid 2.x
|
|
40
|
+
target.setAttribute(`${vividDataAttributePrefix}-v2`, vividVersion.v2)
|
|
41
|
+
|
|
42
|
+
target.classList.add('vvd-root') // vivid 3.x
|
|
43
|
+
target.setAttribute(`${vividDataAttributePrefix}-v3`, vividVersion.v3)
|
|
44
|
+
target = undefined
|
|
45
|
+
}
|
|
46
|
+
const appendStyle = appendStyleElement()
|
|
47
|
+
appendStyle(coreStyles)
|
|
48
|
+
appendStyle(options.theme === 'light' ? lightThemeStyles : darkThemeStyles)
|
|
49
|
+
if (options.font === 'proprietary') {
|
|
50
|
+
appendStyle(fontSpeziaStyles)
|
|
51
|
+
}
|
|
52
|
+
return Promise.all([
|
|
53
|
+
init(),
|
|
54
|
+
context.mount(target)
|
|
55
|
+
]).then(callback)
|
|
56
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { vwcTooltipEllipsisDecorator } from "../vwcTooltip"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Patches provided `VwcCard` (styles) to crop long heading text and
|
|
5
|
+
* shows browser tooltip when actually cropped
|
|
6
|
+
*
|
|
7
|
+
* @param {HTMLElement} element - target `VwcCard` element to apply the `heading` cropping logic to
|
|
8
|
+
* @example <VwcCard ref={vwcCardHeadingCropDecorator(text)} heading={text} />
|
|
9
|
+
*/
|
|
10
|
+
export const vwcCardHeadingCropDecorator = text => element =>
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
const cardContentElement = element?.shadowRoot.querySelector(
|
|
13
|
+
'.vwc-card-content'
|
|
14
|
+
)
|
|
15
|
+
const titleElement = element?.shadowRoot.querySelector(
|
|
16
|
+
'.vwc-card-title'
|
|
17
|
+
)
|
|
18
|
+
vwcTooltipEllipsisDecorator(text)(titleElement)
|
|
19
|
+
if (cardContentElement?.clientWidth < titleElement?.clientWidth) {
|
|
20
|
+
const computedCardContentStyle = window.getComputedStyle(cardContentElement, null)
|
|
21
|
+
titleElement.setAttribute('title', text)
|
|
22
|
+
titleElement.style.width = computedCardContentStyle.getPropertyValue('width')
|
|
23
|
+
titleElement.style.overflow = 'hidden'
|
|
24
|
+
titleElement.style.display = 'block'
|
|
25
|
+
titleElement.style['white-space'] = 'nowrap'
|
|
26
|
+
titleElement.style['text-overflow'] = 'ellipsis'
|
|
27
|
+
}
|
|
28
|
+
}, 0)
|