@vonage/vivid-react 2.10.56 → 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.
Files changed (81) hide show
  1. package/.vscode/settings.json +4 -0
  2. package/README.md +17 -7
  3. package/package.json +9 -10
  4. package/scripts/cli.js +13 -14
  5. package/scripts/generateWrappers/consts.js +9 -15
  6. package/scripts/generateWrappers/generator.js +138 -4
  7. package/scripts/generateWrappers/prop.types.js +20 -19
  8. package/scripts/generateWrappers/templates/js/react-component-v3.tmpl +19 -0
  9. package/scripts/generateWrappers/templates/js/stories.tmpl +2 -2
  10. package/scripts/generateWrappers/templates/templates.js +3 -0
  11. package/scripts/generateWrappers/templates/ts/element-type.tmpl +3 -0
  12. package/scripts/generateWrappers/templates/ts/react-component-v3.tmpl +32 -0
  13. package/scripts/generateWrappers/templates/ts/types.tmpl +8 -0
  14. package/scripts/generateWrappers/utils.js +19 -48
  15. package/src/initialization/initVivid.js +34 -2
  16. package/stories/{VwcAccordion → v2/VwcAccordion}/VwcAccordion.stories.jsx +2 -2
  17. package/stories/{VwcActionGroup → v2/VwcActionGroup}/VwcActionGroup.stories.jsx +2 -2
  18. package/stories/{VwcBadge → v2/VwcBadge}/VwcBadge.stories.jsx +2 -2
  19. package/stories/{VwcBanner → v2/VwcBanner}/VwcBanner.stories.jsx +2 -2
  20. package/stories/{VwcButton → v2/VwcButton}/VwcButton.stories.jsx +2 -2
  21. package/stories/{VwcButtonToggleGroup → v2/VwcButtonToggleGroup}/VwcButtonToggleGroup.stories.jsx +3 -3
  22. package/stories/{VwcCalendar → v2/VwcCalendar}/VwcCalendar.stories.jsx +2 -2
  23. package/stories/{VwcCalendarEvent → v2/VwcCalendarEvent}/VwcCalendarEvent.stories.jsx +2 -2
  24. package/stories/{VwcCard → v2/VwcCard}/VwcCard.stories.jsx +4 -4
  25. package/stories/{VwcCarousel → v2/VwcCarousel}/VwcCarousel.stories.jsx +2 -2
  26. package/stories/{VwcCarouselItem → v2/VwcCarouselItem}/VwcCarouselItem.stories.jsx +2 -2
  27. package/stories/{VwcCheckListItem → v2/VwcCheckListItem}/VwcCheckListItem.stories.jsx +2 -2
  28. package/stories/{VwcCheckbox → v2/VwcCheckbox}/VwcCheckbox.stories.jsx +2 -2
  29. package/stories/{VwcChip → v2/VwcChip}/VwcChip.stories.jsx +2 -2
  30. package/stories/{VwcChipSet → v2/VwcChipSet}/VwcChipSet.stories.jsx +3 -3
  31. package/stories/{VwcCircularProgress → v2/VwcCircularProgress}/VwcCircularProgress.stories.jsx +2 -2
  32. package/stories/{VwcDataGrid → v2/VwcDataGrid}/VwcDataGrid.stories.jsx +6 -6
  33. package/stories/{VwcDataGridColumn → v2/VwcDataGridColumn}/VwcDataGridColumn.stories.jsx +2 -2
  34. package/stories/{VwcDatepicker → v2/VwcDatepicker}/VwcDatepicker.stories.jsx +2 -2
  35. package/stories/{VwcDialog → v2/VwcDialog}/VwcDialog.stories.jsx +2 -2
  36. package/stories/{VwcDrawer → v2/VwcDrawer}/VwcDrawer.stories.jsx +2 -2
  37. package/stories/{VwcDropdown → v2/VwcDropdown}/VwcDropdown.stories.jsx +2 -2
  38. package/stories/{VwcElevation → v2/VwcElevation}/VwcElevation.stories.jsx +2 -2
  39. package/stories/{VwcEmptyState → v2/VwcEmptyState}/VwcEmptyState.stories.jsx +2 -2
  40. package/stories/{VwcExpansionPanel → v2/VwcExpansionPanel}/VwcExpansionPanel.stories.jsx +2 -2
  41. package/stories/{VwcFab → v2/VwcFab}/VwcFab.stories.jsx +2 -2
  42. package/stories/{VwcFilePicker → v2/VwcFilePicker}/VwcFilePicker.stories.jsx +2 -2
  43. package/stories/{VwcFormfield → v2/VwcFormfield}/VwcFormfield.stories.jsx +2 -2
  44. package/stories/{VwcHelperMessage → v2/VwcHelperMessage}/VwcHelperMessage.stories.jsx +2 -2
  45. package/stories/{VwcIcon → v2/VwcIcon}/VwcIcon.stories.jsx +2 -2
  46. package/stories/{VwcIconButton → v2/VwcIconButton}/VwcIconButton.stories.jsx +2 -2
  47. package/stories/{VwcIconButtonToggle → v2/VwcIconButtonToggle}/VwcIconButtonToggle.stories.jsx +2 -2
  48. package/stories/{VwcKeypad → v2/VwcKeypad}/VwcKeypad.stories.jsx +2 -2
  49. package/stories/{VwcLayout → v2/VwcLayout}/VwcLayout.stories.jsx +3 -3
  50. package/stories/{VwcLinearProgress → v2/VwcLinearProgress}/VwcLinearProgress.stories.jsx +2 -2
  51. package/stories/{VwcList → v2/VwcList}/VwcList.stories.jsx +3 -3
  52. package/stories/{VwcListExpansionPanel → v2/VwcListExpansionPanel}/VwcListExpansionPanel.stories.jsx +2 -2
  53. package/stories/{VwcListItem → v2/VwcListItem}/VwcListItem.stories.jsx +2 -2
  54. package/stories/{VwcMenu → v2/VwcMenu}/VwcMenu.stories.jsx +4 -4
  55. package/stories/{VwcNotchedOutline → v2/VwcNotchedOutline}/VwcNotchedOutline.stories.jsx +2 -2
  56. package/stories/{VwcNote → v2/VwcNote}/VwcNote.stories.jsx +2 -2
  57. package/stories/{VwcPagination → v2/VwcPagination}/VwcPagination.stories.jsx +2 -2
  58. package/stories/{VwcPopup → v2/VwcPopup}/VwcPopup.stories.jsx +2 -2
  59. package/stories/{VwcRadio → v2/VwcRadio}/VwcRadio.stories.jsx +2 -2
  60. package/stories/{VwcRadioListItem → v2/VwcRadioListItem}/VwcRadioListItem.stories.jsx +2 -2
  61. package/stories/{VwcSchemeSelect → v2/VwcSchemeSelect}/VwcSchemeSelect.stories.jsx +2 -2
  62. package/stories/{VwcSelect → v2/VwcSelect}/VwcSelect.stories.jsx +2 -2
  63. package/stories/{VwcSideDrawer → v2/VwcSideDrawer}/VwcSideDrawer.stories.jsx +2 -2
  64. package/stories/{VwcSlider → v2/VwcSlider}/VwcSlider.stories.jsx +2 -2
  65. package/stories/{VwcSnackbar → v2/VwcSnackbar}/VwcSnackbar.stories.jsx +2 -2
  66. package/stories/{VwcSurface → v2/VwcSurface}/VwcSurface.stories.jsx +2 -2
  67. package/stories/{VwcSwitch → v2/VwcSwitch}/VwcSwitch.stories.jsx +2 -2
  68. package/stories/{VwcTab → v2/VwcTab}/VwcTab.stories.jsx +2 -2
  69. package/stories/{VwcTabBar → v2/VwcTabBar}/VwcTabBar.stories.jsx +3 -3
  70. package/stories/{VwcTag → v2/VwcTag}/VwcTag.stories.jsx +2 -2
  71. package/stories/{VwcText → v2/VwcText}/VwcText.stories.jsx +2 -2
  72. package/stories/{VwcTextarea → v2/VwcTextarea}/VwcTextarea.stories.jsx +2 -2
  73. package/stories/{VwcTextfield → v2/VwcTextfield}/VwcTextfield.stories.jsx +2 -2
  74. package/stories/{VwcThemeSwitch → v2/VwcThemeSwitch}/VwcThemeSwitch.stories.jsx +2 -2
  75. package/stories/{VwcTooltip → v2/VwcTooltip}/VwcTooltip.stories.jsx +4 -4
  76. package/stories/{VwcTopAppBar → v2/VwcTopAppBar}/VwcTopAppBar.stories.jsx +2 -2
  77. package/stories/{VwcTopAppBarFixed → v2/VwcTopAppBarFixed}/VwcTopAppBarFixed.stories.jsx +2 -2
  78. package/stories/{patches → v2/patches}/patches.stories.jsx +15 -15
  79. package/stories/v3/v3.stories.jsx +28 -0
  80. package/scripts/generateWrappers/index.js +0 -0
  81. package/types/index.d.ts +0 -2
@@ -0,0 +1,4 @@
1
+ {
2
+ "npm.exclude": "**/dist",
3
+ "npm.scriptExplorerExclude": ["install"]
4
+ }
package/README.md CHANGED
@@ -88,13 +88,8 @@ Adding the `resolutions` field when using `yarn` might help get the correct vers
88
88
 
89
89
  If the one you're looking for is missing, just [add a new one](#adding-a-component), so everyone can access them.
90
90
 
91
- # Usage
92
-
93
- ## Artifactory
94
- To use this package, you need to have Artifactory setup for your project. See how to do it [here](https://confluence.vonage.com/pages/viewpage.action?pageId=123601806) and [here](https://github.com/newvoicemedia/vonage-cli/blob/master/pipeline-guide/how-to/NODEJS-NPM-DEVELOPMENT.md).
95
-
96
91
  ## Installation
97
- Once you have Artifactory configured, just run:
92
+ Just run:
98
93
  ```shell
99
94
  $ yarn add @vonage/vivid-react
100
95
  ```
@@ -103,7 +98,6 @@ No need for importing `vivid` directly. The dependencies will be installed for y
103
98
  ## Initialization
104
99
 
105
100
  ```javascript
106
- // Function
107
101
  import ReactDOM from 'react-dom'
108
102
  import { initVivid } from '@vonage/vivid-react'
109
103
  const rootElement = document.getElementById('react-root')
@@ -115,16 +109,32 @@ const renderApp = () => {
115
109
  )
116
110
  }
117
111
 
112
+ // for Vivid 2.x
118
113
  initVivid(rootElement).then(renderApp)
114
+
115
+ // OR
116
+
117
+ // for Vivid 2.x + Vivid 3.x
118
+ initVivid(rootElement, () => {}, {
119
+ font: 'oss',
120
+ theme: 'light'
121
+ }).then(renderApp)
119
122
  ```
120
123
 
121
124
  ## Importing
125
+ For vivid **2.x**
122
126
  Instead of importing each `vivid` component from `@vonage/vwc-*`, import them from `@vonage/vivid-react` instead.
123
127
  ```javascript
124
128
  import VwcCheckbox from '@vonage/vivid-react/VwcCheckbox'
125
129
  import VwcSlider from '@vonage/vivid-react/VwcSlider'
126
130
  ```
127
131
 
132
+ For vivid **3.x**
133
+ ```javascript
134
+ import VwcCheckbox from '@vonage/vivid-react/v3/VwcCheckbox'
135
+ import VwcSlider from '@vonage/vivid-react/v3/VwcSlider'
136
+ ```
137
+
128
138
  ## Bundling
129
139
  This package is an ES module, so you might need to add some configuration to your bundling process.
130
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonage/vivid-react",
3
- "version": "2.10.56",
3
+ "version": "2.10.58",
4
4
  "description": "Vivid wrapped for easy React usage & IDE autocomplete support & typescript typings",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -27,6 +27,7 @@
27
27
  "CLI"
28
28
  ],
29
29
  "dependencies": {
30
+ "@vonage/vivid": "3.18.0",
30
31
  "@vonage/vivid-react-wrapper": "1.2.9",
31
32
  "@vonage/vvd-context": "2.42.0",
32
33
  "@vonage/vvd-core": "2.42.0",
@@ -92,21 +93,19 @@
92
93
  "@babel/preset-react": "^7.14.5",
93
94
  "@babel/runtime": "^7.13.17",
94
95
  "@material-ui/core": "^4.11.1",
95
- "@octokit/core": "^3.1.2",
96
96
  "@rollup/plugin-babel": "^5.2.2",
97
97
  "@rollup/plugin-commonjs": "^17.0.0",
98
98
  "@rollup/plugin-node-resolve": "^11.0.0",
99
- "@storybook/addon-actions": "6.5.13",
100
- "@storybook/addon-controls": "6.5.13",
101
- "@storybook/addon-essentials": "6.5.13",
102
- "@storybook/addon-links": "6.5.13",
103
- "@storybook/addons": "6.5.13",
104
- "@storybook/react": "6.5.13",
99
+ "@storybook/addon-actions": "6.5.14",
100
+ "@storybook/addon-controls": "6.5.14",
101
+ "@storybook/addon-essentials": "6.5.14",
102
+ "@storybook/addon-links": "6.5.14",
103
+ "@storybook/addons": "6.5.14",
104
+ "@storybook/react": "6.5.14",
105
105
  "@types/react": "16.9.49",
106
106
  "@webcomponents/webcomponentsjs": "^2.5.0",
107
107
  "babel-jest": "^26.6.1",
108
108
  "babel-loader": "^8.2.2",
109
- "extract-zip": "2.0.1",
110
109
  "fs-extra": "^9.0.1",
111
110
  "jest": "^26.6.1",
112
111
  "lodash": "^4.17.20",
@@ -132,7 +131,7 @@
132
131
  "react-dom": ">=16.8"
133
132
  },
134
133
  "engines": {
135
- "node": ">=14.0.0"
134
+ "node": ">=14.0.0 <=18.16.0"
136
135
  },
137
136
  "optionalDependencies": {
138
137
  "prop-types": "^15.7.2"
package/scripts/cli.js CHANGED
@@ -1,11 +1,11 @@
1
- const { OutputLanguage, CLIArgument, WCAConfigAll, FileName, Assets } = require('./generateWrappers/consts')
2
- const { generateWrappers } = require('./generateWrappers/generator')
1
+ const { OutputLanguage, CLIArgument, FileName, Assets } = require('./generateWrappers/consts')
2
+ const { generateWrappers, generateWrappersV3 } = require('./generateWrappers/generator')
3
3
  const {
4
4
  isFileExists,
5
+ readMetaData,
5
6
  getParsedJson,
6
7
  getVividPackageNames,
7
8
  getInputArgument,
8
- getVividLatestRelease,
9
9
  getCustomElementTagsDefinitionsList,
10
10
  copyStaticAssets
11
11
  } = require('./generateWrappers/utils')
@@ -15,14 +15,13 @@ const language = getInputArgument(CLIArgument.Language, OutputLanguage.JavaScrip
15
15
  const staticAssets = getInputArgument(CLIArgument.Assets, Assets)
16
16
  const cleanTemp = getInputArgument(CLIArgument.CleanTemp, true) !== 'false'
17
17
 
18
- getInputArgument(CLIArgument.All)
19
- ? getVividLatestRelease()
20
- .then(getCustomElementTagsDefinitionsList(WCAConfigAll))
21
- .then(generateWrappers(outputDir, language, cleanTemp))
22
- .then(copyStaticAssets(outputDir, staticAssets))
23
- : isFileExists(FileName.packageJson)
24
- .then(getParsedJson)
25
- .then(getVividPackageNames)
26
- .then(getCustomElementTagsDefinitionsList())
27
- .then(generateWrappers(outputDir, language, cleanTemp))
28
- .then(copyStaticAssets(outputDir, staticAssets))
18
+ // generate wrappers for Vivid 2.x
19
+ isFileExists(FileName.packageJson)
20
+ .then(getParsedJson)
21
+ .then(getVividPackageNames)
22
+ .then(getCustomElementTagsDefinitionsList())
23
+ .then(generateWrappers(outputDir, language, cleanTemp))
24
+ .then(() => readMetaData() // generate wrappers for Vivid 3.x
25
+ .then(generateWrappersV3(outputDir, language, cleanTemp)))
26
+ .then(copyStaticAssets(outputDir, staticAssets))
27
+
@@ -1,8 +1,11 @@
1
1
  const FileName = {
2
2
  packageJson: 'package.json',
3
3
  tempFolder: 'temp',
4
+ customElements: 'custom-elements.json',
5
+ vividApi: 'vivid.api.json',
4
6
  tempFileName: 'analyzerOutput.json',
5
7
  tempTsFolder: 'ts',
8
+ generatedFolder: 'src/generated',
6
9
  tempVividZipball: 'vivid.zip',
7
10
  defaultOutputDirectory: 'dist',
8
11
  storyOutputDir: 'stories',
@@ -33,24 +36,11 @@ const WCAConfig = {
33
36
  ]
34
37
  }
35
38
 
36
- const WCAConfigAll = {
37
- tempFolder: FileName.tempFolder,
38
- tempFileName: FileName.tempFileName,
39
- nodeArgumentsFactory: (targetFolder, analyzerOutputFile) => [
40
- './node_modules/web-component-analyzer/cli.js',
41
- 'analyze',
42
- `${targetFolder}/{src/,}*.?s`,
43
- '--format', 'json',
44
- '--outFile', analyzerOutputFile
45
- ]
46
- }
47
-
48
39
  const CLIArgument = {
49
40
  Assets: 'assets', // static assets to be copied to output folder
50
41
  Output: 'output', // output folder
51
42
  Language: 'language', // language js,ts
52
- CleanTemp: 'clean', // clean up temp folder after CLI run
53
- All: 'all' // ignore local package.json and produce wrappers for *all* Vivid components
43
+ CleanTemp: 'clean' // clean up temp folder after CLI run
54
44
  }
55
45
 
56
46
  const OutputLanguage = {
@@ -83,6 +73,10 @@ const ComponentsEventsMap = {
83
73
  VwcTextarea: ['input', 'blur', 'focus']
84
74
  }
85
75
 
76
+ const ComponentsEventsMapV3 = {
77
+ VwcButton: ['click']
78
+ }
79
+
86
80
  const ComponentsReadOnlyPropertiesMap = {
87
81
  VwcAccordion: ['styles'],
88
82
  VwcActionGroup: ['styles'],
@@ -212,6 +206,7 @@ const CompoundComponentsMap = {
212
206
 
213
207
  module.exports = {
214
208
  ComponentsEventsMap,
209
+ ComponentsEventsMapV3,
215
210
  ComponentsReadOnlyPropertiesMap,
216
211
  ComponentsBindablePropertiesMap,
217
212
  ComponentsExtraPropertiesMap,
@@ -220,7 +215,6 @@ module.exports = {
220
215
  Assets,
221
216
  OutputLanguage,
222
217
  WCAConfig,
223
- WCAConfigAll,
224
218
  CLIArgument,
225
219
  VividRepo
226
220
  }
@@ -2,6 +2,7 @@ const packageJson = require('../../package.json')
2
2
  const { getImportsFromTag } = require('./helpers/generator')
3
3
  const {
4
4
  ComponentsEventsMap,
5
+ ComponentsEventsMapV3,
5
6
  CompoundComponentsMap,
6
7
  OutputLanguage,
7
8
  FileName
@@ -15,6 +16,8 @@ const {
15
16
  getComponentName,
16
17
  toJsonObjectsList,
17
18
  filePath,
19
+ camel2kebab,
20
+ event2PropName,
18
21
  renderJsDoc,
19
22
  getIndexFileName,
20
23
  getProperties,
@@ -25,7 +28,8 @@ const {
25
28
  } = require('./utils')
26
29
  const { getTemplate, TemplateToken } = require('./templates/templates')
27
30
  const { join } = require('path')
28
- const { getPropTypes, getDefaultProps, getProps } = require('./prop.types')
31
+ const { getPropTypes, getDefaultProps, getProps, mapType } = require('./prop.types')
32
+ const { writeFileSync, readFileSync } = require('fs')
29
33
 
30
34
  const generateTypings = outputDir => async tags => {
31
35
  const distTs = join(FileName.tempFolder, FileName.tempTsFolder)
@@ -33,6 +37,12 @@ const generateTypings = outputDir => async tags => {
33
37
  await compileTypescript(distTs)(outputDir)
34
38
  }
35
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
+
36
46
  const renderComponent = tag => language => componentName => {
37
47
  const compoundsConfig = CompoundComponentsMap[componentName] || {}
38
48
  const getCompoundComponents = prepareCompoundComponents(componentName, compoundComponentTemplate, compoundsConfig)
@@ -58,6 +68,9 @@ const renderComponent = tag => language => componentName => {
58
68
  .replace(new RegExp(TemplateToken.TAG, 'g'), tag.name)
59
69
  }
60
70
 
71
+ /**
72
+ * Generates Vivid 2.x wrappers
73
+ */
61
74
  const generateWrappers = (outputDir, language = OutputLanguage.JavaScript, cleanTemp = true, verbose = true) => async (tags) => {
62
75
  const indexFileName = getIndexFileName(language)
63
76
  const saveIndex = (outputDir, content) => {
@@ -78,7 +91,7 @@ const generateWrappers = (outputDir, language = OutputLanguage.JavaScript, clean
78
91
  }
79
92
 
80
93
  const getStoriesContent = (componentName, tag) =>
81
- getTemplate('stories', 'js')
94
+ getTemplate('stories', OutputLanguage.JavaScript)
82
95
  .split(TemplateToken.COMPONENT_CLASS_NAME).join(componentName)
83
96
 
84
97
  prepareDir(outputDir, true, verbose)
@@ -93,7 +106,7 @@ const generateWrappers = (outputDir, language = OutputLanguage.JavaScript, clean
93
106
  tag.events = [...(tag.events || []), ...(ComponentsEventsMap[componentName] || [])]
94
107
 
95
108
  const componentOutputDir = join(process.cwd(), outputDir, componentName)
96
- const storyOutputDir = join(process.cwd(), FileName.storyOutputDir, componentName)
109
+ const storyOutputDir = join(process.cwd(), FileName.storyOutputDir, 'v2', componentName)
97
110
  const componentContent = renderComponent(tag)(language)(componentName)
98
111
 
99
112
  await saveIndex(componentOutputDir, componentContent)
@@ -125,6 +138,127 @@ const generateWrappers = (outputDir, language = OutputLanguage.JavaScript, clean
125
138
  }
126
139
  }
127
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
+
128
261
  module.exports = {
129
- generateWrappers
262
+ generateWrappers,
263
+ generateWrappersV3
130
264
  }
@@ -10,29 +10,29 @@ const isArray = type => /(.*)\[\]$/gm.test(type) || type === 'array'
10
10
  const isNumber = type => /(integer)/.test(type) || type === 'number | null'
11
11
 
12
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} */`
13
31
 
14
32
  const getProps = tag => {
15
33
  const eventsProps = getEvents(tag).map(x => ` ${x}?: (event: SyntheticEvent) => void`)
16
34
 
17
35
  const properties = getProperties(tag)
18
- const mapType = type => ([
19
- 'boolean',
20
- 'Boolean',
21
- 'string',
22
- 'string | null',
23
- 'string | undefined',
24
- 'string | number',
25
- 'number',
26
- 'unknown'].indexOf(type) >= 0 ||
27
- isTypeSet(type))
28
- ? type
29
- : isBoolean(type)
30
- ? 'boolean'
31
- : isNumber(type)
32
- ? 'number'
33
- : isArray(type)
34
- ? 'any[]'
35
- : `any /* ${type} */`
36
36
  const props = properties.map(x => ` ${x.name}?: ${mapType(x.type)}`)
37
37
 
38
38
  return [
@@ -82,5 +82,6 @@ module.exports = {
82
82
  getPropTypes,
83
83
 
84
84
  // TypeScript
85
- getProps
85
+ getProps,
86
+ mapType
86
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 %>
@@ -1,9 +1,9 @@
1
1
  import React from 'react'
2
- import <% component-class-name %> from '../../dist/<% component-class-name %>'
2
+ import <% component-class-name %> from '../../../dist/<% component-class-name %>'
3
3
 
4
4
  export const Default = () => <<% component-class-name %> />
5
5
  export default {
6
- title: '<% component-class-name %>',
6
+ title: 'V2/<% component-class-name %>',
7
7
  argTypes: {
8
8
  //
9
9
  // Example values
@@ -8,7 +8,10 @@ const TemplateToken = {
8
8
  IMPORTS: '<% imports %>',
9
9
  EXPORTS: '<% exports %>',
10
10
  TAG: '<% tag %>',
11
+ ELEMENT_TYPES: '<% element-types %>',
11
12
  COMPONENT_CLASS_NAME: '<% component-class-name %>',
13
+ COMPONENT_NAME: '<% component-name %>',
14
+ TAG_PREFIX: '<% tag-prefix %>',
12
15
  PROP_TYPES: '<% prop-types %>',
13
16
  PROPS: '<% props %>',
14
17
  DEFAULT_PROPS: '<% default-props %>',
@@ -0,0 +1,3 @@
1
+ "<% tag %>": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & Partial<{
2
+ <% attributes %>
3
+ }>;
@@ -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,8 @@
1
+ <% banner %>
2
+ declare module '@vonage/vivid-react-wrapper';
3
+ declare module '@vonage/vivid-react';
4
+ declare namespace JSX {
5
+ interface IntrinsicElements {
6
+ <% element-types %>
7
+ }
8
+ }