@atlaskit/forge-react-types 0.42.6 → 0.42.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/forge-react-types
2
2
 
3
+ ## 0.42.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#183155](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183155)
8
+ [`0da1030d5f383`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0da1030d5f383) -
9
+ Remove @atlaskit/code dependency from @atlaskit/forge-react-types
10
+
3
11
  ## 0.42.6
4
12
 
5
13
  ### Patch Changes
@@ -1,5 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ "use strict";
@@ -3,13 +3,60 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeBlockProps
5
5
  *
6
- * @codegen <<SignedSource::8ab4ed1e38d2bd1f9ceafe4cbc20f97d>>
6
+ * @codegen <<SignedSource::8fded8a55e24b0312739eb3ab66f63ca>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/codeblock.partial.tsx <<SignedSource::88ed38fdfc47db0938e7801195a00403>>
9
9
  */
10
- import React from 'react';
11
- import { CodeBlock as PlatformCodeBlock } from '@atlaskit/code';
12
- type PlatformCodeBlockProps = React.ComponentProps<typeof PlatformCodeBlock>;
10
+ type PlatformCodeBlockProps = {
11
+ /**
12
+ * The code to be formatted.
13
+ */
14
+ text: string;
15
+ /**
16
+ * A unique string that appears as a data attribute `data-testid` in the
17
+ * rendered code. Serves as a hook for automated tests.
18
+ */
19
+ testId: string;
20
+ /**
21
+ * Sets whether to display code line numbers or not.
22
+ * @default true
23
+ */
24
+ showLineNumbers: boolean;
25
+ /**
26
+ * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
27
+ * `design-system/code`. Run against language grammars from PrismJS (full list
28
+ * available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
29
+ *
30
+ * When set to "text" will not perform highlighting. If unsupported language
31
+ * provided - code will be treated as "text" with no highlighting.
32
+ *
33
+ * @default 'text'
34
+ */
35
+ language: "text" | "PHP" | "php" | "php3" | "php4" | "php5" | "Java" | "java" | "CSharp" | "csharp" | "c#" | "Python" | "python" | "py" | "JavaScript" | "javascript" | "js" | "Html" | "html" | "xml" | "C++" | "c++" | "cpp" | "clike" | "Ruby" | "ruby" | "rb" | "duby" | "Objective-C" | "objective-c" | "objectivec" | "obj-c" | "objc" | "C" | "c" | "Swift" | "swift" | "TeX" | "tex" | "latex" | "Shell" | "shell" | "bash" | "sh" | "ksh" | "zsh" | "Scala" | "scala" | "Go" | "go" | "ActionScript" | "actionscript" | "actionscript3" | "as" | "ColdFusion" | "coldfusion" | "JavaFX" | "javafx" | "jfx" | "VbNet" | "vbnet" | "vb.net" | "vfp" | "clipper" | "xbase" | "JSON" | "json" | "MATLAB" | "matlab" | "Groovy" | "groovy" | "SQL" | "sql" | "postgresql" | "postgres" | "plpgsql" | "psql" | "postgresql-console" | "postgres-console" | "tsql" | "t-sql" | "mysql" | "sqlite" | "R" | "r" | "Perl" | "perl" | "pl" | "Lua" | "lua" | "Pascal" | "pas" | "pascal" | "objectpascal" | "delphi" | "XML" | "TypeScript" | "typescript" | "ts" | "CoffeeScript" | "coffeescript" | "coffee-script" | "coffee" | "Haskell" | "haskell" | "hs" | "Puppet" | "puppet" | "Arduino" | "arduino" | "Fortran" | "fortran" | "Erlang" | "erlang" | "erl" | "PowerShell" | "powershell" | "posh" | "ps1" | "psm1" | "Haxe" | "haxe" | "hx" | "hxsl" | "Elixir" | "elixir" | "ex" | "exs" | "Verilog" | "verilog" | "v" | "Rust" | "rust" | "VHDL" | "vhdl" | "Sass" | "sass" | "OCaml" | "ocaml" | "Dart" | "dart" | "CSS" | "css" | "reStructuredText" | "restructuredtext" | "rst" | "rest" | "Kotlin" | "kotlin" | "D" | "d" | "Octave" | "octave" | "QML" | "qbs" | "qml" | "Prolog" | "prolog" | "FoxPro" | "foxpro" | "purebasic" | "Scheme" | "scheme" | "scm" | "CUDA" | "cuda" | "cu" | "Julia" | "julia" | "jl" | "Racket" | "racket" | "rkt" | "Ada" | "ada" | "ada95" | "ada2005" | "Tcl" | "tcl" | "Mathematica" | "mathematica" | "mma" | "nb" | "Autoit" | "autoit" | "StandardML" | "standardmL" | "sml" | "standardml" | "Objective-J" | "objective-j" | "objectivej" | "obj-j" | "objj" | "Smalltalk" | "smalltalk" | "squeak" | "st" | "Vala" | "vala" | "vapi" | "LiveScript" | "livescript" | "live-script" | "XQuery" | "xquery" | "xqy" | "xq" | "xql" | "xqm" | "PlainText" | "plaintext" | "Yaml" | "yaml" | "yml" | "GraphQL" | "graphql" | "AppleScript" | "applescript" | "Clojure" | "clojure" | "Diff" | "diff" | "VisualBasic" | "visualbasic" | "JSX" | "jsx" | "TSX" | "tsx" | "SplunkSPL" | "splunk-spl" | "Dockerfile" | "docker" | "dockerfile" | "HCL" | "hcl" | "terraform" | "NGINX" | "nginx" | "Protocol Buffers" | "protobuf" | "proto" | "Handlebars" | "handlebars" | "mustache" | "Gherkin" | "gherkin" | "cucumber" | "ABAP" | "abap";
36
+ /**
37
+ * Comma delimited lines to highlight.
38
+ *
39
+ * Example uses:
40
+ * - To highlight one line `highlight="3"`
41
+ * - To highlight a group of lines `highlight="1-5"`
42
+ * - To highlight multiple groups `highlight="1-5,7,10,15-20"`
43
+ */
44
+ highlight: string;
45
+ /**
46
+ * Screen reader text for the start of a highlighted line.
47
+ */
48
+ highlightedStartText: string;
49
+ /**
50
+ * Screen reader text for the end of a highlighted line.
51
+ */
52
+ highlightedEndText: string;
53
+ /**
54
+ * Sets whether long lines will create a horizontally scrolling container.
55
+ * When set to `true`, these lines will visually wrap instead.
56
+ * @default false
57
+ */
58
+ shouldWrapLongLines: boolean;
59
+ };
13
60
  export type CodeBlockProps = Pick<PlatformCodeBlockProps, 'text' | 'testId' | 'showLineNumbers' | 'language' | 'highlight' | 'highlightedStartText' | 'highlightedEndText' | 'shouldWrapLongLines'>;
14
61
  /**
15
62
  * Code highlights short strings of code snippets inline with body text.
@@ -3,13 +3,22 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeProps
5
5
  *
6
- * @codegen <<SignedSource::baf6b565e34d8df53db53b8855ec120d>>
6
+ * @codegen <<SignedSource::7ea0b6ee7be9f3e5454b38e528c0753f>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/code.partial.tsx <<SignedSource::6f210b052488fe7ece12d865706a551e>>
9
9
  */
10
- import React from 'react';
11
- import { Code as PlatformCode } from '@atlaskit/code';
12
- type PlatformCodeProps = React.ComponentProps<typeof PlatformCode>;
10
+ import { type ReactNode } from 'react';
11
+ type PlatformCodeProps = {
12
+ /**
13
+ * A unique string that appears as a data attribute `data-testid`
14
+ * in the rendered code. Serves as a hook for automated tests.
15
+ */
16
+ testId: string;
17
+ /**
18
+ * Content to be rendered in the inline code block.
19
+ */
20
+ children: ReactNode;
21
+ };
13
22
  export type CodeProps = Pick<PlatformCodeProps, 'children' | 'testId'>;
14
23
  /**
15
24
  * Code highlights short strings of code snippets inline with body text.
@@ -3,13 +3,60 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeBlockProps
5
5
  *
6
- * @codegen <<SignedSource::8ab4ed1e38d2bd1f9ceafe4cbc20f97d>>
6
+ * @codegen <<SignedSource::8fded8a55e24b0312739eb3ab66f63ca>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/codeblock.partial.tsx <<SignedSource::88ed38fdfc47db0938e7801195a00403>>
9
9
  */
10
- import React from 'react';
11
- import { CodeBlock as PlatformCodeBlock } from '@atlaskit/code';
12
- type PlatformCodeBlockProps = React.ComponentProps<typeof PlatformCodeBlock>;
10
+ type PlatformCodeBlockProps = {
11
+ /**
12
+ * The code to be formatted.
13
+ */
14
+ text: string;
15
+ /**
16
+ * A unique string that appears as a data attribute `data-testid` in the
17
+ * rendered code. Serves as a hook for automated tests.
18
+ */
19
+ testId: string;
20
+ /**
21
+ * Sets whether to display code line numbers or not.
22
+ * @default true
23
+ */
24
+ showLineNumbers: boolean;
25
+ /**
26
+ * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
27
+ * `design-system/code`. Run against language grammars from PrismJS (full list
28
+ * available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
29
+ *
30
+ * When set to "text" will not perform highlighting. If unsupported language
31
+ * provided - code will be treated as "text" with no highlighting.
32
+ *
33
+ * @default 'text'
34
+ */
35
+ language: "text" | "PHP" | "php" | "php3" | "php4" | "php5" | "Java" | "java" | "CSharp" | "csharp" | "c#" | "Python" | "python" | "py" | "JavaScript" | "javascript" | "js" | "Html" | "html" | "xml" | "C++" | "c++" | "cpp" | "clike" | "Ruby" | "ruby" | "rb" | "duby" | "Objective-C" | "objective-c" | "objectivec" | "obj-c" | "objc" | "C" | "c" | "Swift" | "swift" | "TeX" | "tex" | "latex" | "Shell" | "shell" | "bash" | "sh" | "ksh" | "zsh" | "Scala" | "scala" | "Go" | "go" | "ActionScript" | "actionscript" | "actionscript3" | "as" | "ColdFusion" | "coldfusion" | "JavaFX" | "javafx" | "jfx" | "VbNet" | "vbnet" | "vb.net" | "vfp" | "clipper" | "xbase" | "JSON" | "json" | "MATLAB" | "matlab" | "Groovy" | "groovy" | "SQL" | "sql" | "postgresql" | "postgres" | "plpgsql" | "psql" | "postgresql-console" | "postgres-console" | "tsql" | "t-sql" | "mysql" | "sqlite" | "R" | "r" | "Perl" | "perl" | "pl" | "Lua" | "lua" | "Pascal" | "pas" | "pascal" | "objectpascal" | "delphi" | "XML" | "TypeScript" | "typescript" | "ts" | "CoffeeScript" | "coffeescript" | "coffee-script" | "coffee" | "Haskell" | "haskell" | "hs" | "Puppet" | "puppet" | "Arduino" | "arduino" | "Fortran" | "fortran" | "Erlang" | "erlang" | "erl" | "PowerShell" | "powershell" | "posh" | "ps1" | "psm1" | "Haxe" | "haxe" | "hx" | "hxsl" | "Elixir" | "elixir" | "ex" | "exs" | "Verilog" | "verilog" | "v" | "Rust" | "rust" | "VHDL" | "vhdl" | "Sass" | "sass" | "OCaml" | "ocaml" | "Dart" | "dart" | "CSS" | "css" | "reStructuredText" | "restructuredtext" | "rst" | "rest" | "Kotlin" | "kotlin" | "D" | "d" | "Octave" | "octave" | "QML" | "qbs" | "qml" | "Prolog" | "prolog" | "FoxPro" | "foxpro" | "purebasic" | "Scheme" | "scheme" | "scm" | "CUDA" | "cuda" | "cu" | "Julia" | "julia" | "jl" | "Racket" | "racket" | "rkt" | "Ada" | "ada" | "ada95" | "ada2005" | "Tcl" | "tcl" | "Mathematica" | "mathematica" | "mma" | "nb" | "Autoit" | "autoit" | "StandardML" | "standardmL" | "sml" | "standardml" | "Objective-J" | "objective-j" | "objectivej" | "obj-j" | "objj" | "Smalltalk" | "smalltalk" | "squeak" | "st" | "Vala" | "vala" | "vapi" | "LiveScript" | "livescript" | "live-script" | "XQuery" | "xquery" | "xqy" | "xq" | "xql" | "xqm" | "PlainText" | "plaintext" | "Yaml" | "yaml" | "yml" | "GraphQL" | "graphql" | "AppleScript" | "applescript" | "Clojure" | "clojure" | "Diff" | "diff" | "VisualBasic" | "visualbasic" | "JSX" | "jsx" | "TSX" | "tsx" | "SplunkSPL" | "splunk-spl" | "Dockerfile" | "docker" | "dockerfile" | "HCL" | "hcl" | "terraform" | "NGINX" | "nginx" | "Protocol Buffers" | "protobuf" | "proto" | "Handlebars" | "handlebars" | "mustache" | "Gherkin" | "gherkin" | "cucumber" | "ABAP" | "abap";
36
+ /**
37
+ * Comma delimited lines to highlight.
38
+ *
39
+ * Example uses:
40
+ * - To highlight one line `highlight="3"`
41
+ * - To highlight a group of lines `highlight="1-5"`
42
+ * - To highlight multiple groups `highlight="1-5,7,10,15-20"`
43
+ */
44
+ highlight: string;
45
+ /**
46
+ * Screen reader text for the start of a highlighted line.
47
+ */
48
+ highlightedStartText: string;
49
+ /**
50
+ * Screen reader text for the end of a highlighted line.
51
+ */
52
+ highlightedEndText: string;
53
+ /**
54
+ * Sets whether long lines will create a horizontally scrolling container.
55
+ * When set to `true`, these lines will visually wrap instead.
56
+ * @default false
57
+ */
58
+ shouldWrapLongLines: boolean;
59
+ };
13
60
  export type CodeBlockProps = Pick<PlatformCodeBlockProps, 'text' | 'testId' | 'showLineNumbers' | 'language' | 'highlight' | 'highlightedStartText' | 'highlightedEndText' | 'shouldWrapLongLines'>;
14
61
  /**
15
62
  * Code highlights short strings of code snippets inline with body text.
@@ -3,13 +3,22 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeProps
5
5
  *
6
- * @codegen <<SignedSource::baf6b565e34d8df53db53b8855ec120d>>
6
+ * @codegen <<SignedSource::7ea0b6ee7be9f3e5454b38e528c0753f>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/code.partial.tsx <<SignedSource::6f210b052488fe7ece12d865706a551e>>
9
9
  */
10
- import React from 'react';
11
- import { Code as PlatformCode } from '@atlaskit/code';
12
- type PlatformCodeProps = React.ComponentProps<typeof PlatformCode>;
10
+ import { type ReactNode } from 'react';
11
+ type PlatformCodeProps = {
12
+ /**
13
+ * A unique string that appears as a data attribute `data-testid`
14
+ * in the rendered code. Serves as a hook for automated tests.
15
+ */
16
+ testId: string;
17
+ /**
18
+ * Content to be rendered in the inline code block.
19
+ */
20
+ children: ReactNode;
21
+ };
13
22
  export type CodeProps = Pick<PlatformCodeProps, 'children' | 'testId'>;
14
23
  /**
15
24
  * Code highlights short strings of code snippets inline with body text.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/forge-react-types",
3
- "version": "0.42.6",
3
+ "version": "0.42.7",
4
4
  "description": "Component types for Forge UI Kit React components",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,14 +28,13 @@
28
28
  "@atlaskit/button": "^23.2.0",
29
29
  "@atlaskit/calendar": "^17.1.0",
30
30
  "@atlaskit/checkbox": "^17.1.0",
31
- "@atlaskit/code": "^17.2.0",
32
31
  "@atlaskit/comment": "^13.0.0",
33
32
  "@atlaskit/datetime-picker": "^17.0.0",
34
33
  "@atlaskit/dynamic-table": "^18.2.0",
35
34
  "@atlaskit/empty-state": "^10.1.0",
36
35
  "@atlaskit/form": "^12.0.0",
37
36
  "@atlaskit/heading": "^5.2.0",
38
- "@atlaskit/inline-edit": "^15.2.0",
37
+ "@atlaskit/inline-edit": "^15.3.0",
39
38
  "@atlaskit/lozenge": "^13.0.0",
40
39
  "@atlaskit/modal-dialog": "^14.2.0",
41
40
  "@atlaskit/popup": "^4.3.0",
@@ -45,7 +44,7 @@
45
44
  "@atlaskit/radio": "^8.1.0",
46
45
  "@atlaskit/range": "^9.1.0",
47
46
  "@atlaskit/section-message": "^8.2.0",
48
- "@atlaskit/select": "^21.0.0",
47
+ "@atlaskit/select": "^21.1.0",
49
48
  "@atlaskit/spinner": "^18.0.0",
50
49
  "@atlaskit/tabs": "^18.1.0",
51
50
  "@atlaskit/tag": "^14.0.0",
@@ -8,6 +8,7 @@ import {
8
8
  } from 'ts-morph';
9
9
  // eslint-disable-next-line import/no-extraneous-dependencies
10
10
  import kebabCase from 'lodash/kebabCase';
11
+ import { serializeSymbolType } from './typeSerializer';
11
12
 
12
13
  const getNames = (symbol: Symbol) => {
13
14
  const name = symbol.getName();
@@ -125,20 +126,39 @@ const isTokenUsed = (token: string, codes: string[]) => {
125
126
  return codes.some((code) => check.test(code));
126
127
  };
127
128
 
129
+ interface IImportDeclaration {
130
+ addNamedImport: (namedImport: string) => void;
131
+ removeNamedImport: (namedImport: string) => void;
132
+ getText: () => string;
133
+ }
134
+
128
135
  /**
129
136
  * implement a custom ImportDeclaration object that allows remove named import
130
137
  * and re-generate the modified import statement.
131
138
  * This is for solving the edge case raised from DynamicTableProps.
132
139
  */
133
- class ImportDeclarationProxy {
140
+ class ImportDeclarationProxy implements IImportDeclaration {
134
141
  private readonly base: ImportDeclaration;
135
142
 
136
143
  private removedNamedImports = new Set<string>();
137
144
 
145
+ private addedNamedImports = new Set<string>();
146
+
138
147
  constructor(base: ImportDeclaration) {
139
148
  this.base = base;
140
149
  }
141
150
 
151
+ public getBasePackage() {
152
+ return this.base.getModuleSpecifierValue();
153
+ }
154
+
155
+ public addNamedImport(namedImport: string) {
156
+ if (this.removedNamedImports.has(namedImport)) {
157
+ this.removedNamedImports.delete(namedImport);
158
+ }
159
+ this.addedNamedImports.add(namedImport);
160
+ }
161
+
142
162
  public removeNamedImport(namedImport: string) {
143
163
  const target = this.base
144
164
  .getNamedImports()
@@ -155,22 +175,55 @@ class ImportDeclarationProxy {
155
175
  return this.base.getText();
156
176
  }
157
177
  let [_, importStatement, importedNames, packageName] = match;
158
- importedNames = importedNames.trim();
178
+ let importedNamesList = importedNames
179
+ .trim()
180
+ .split(',')
181
+ .map((text) => text.trim());
159
182
 
160
183
  if (isSharedUIKit2TypesImport(this.base)) {
161
184
  packageName = './types.codegen';
162
185
  }
186
+
163
187
  if (this.removedNamedImports.size > 0) {
164
- importedNames = importedNames!
165
- .split(',')
166
- .map((text) => text.trim())
167
- .filter((text) => !this.removedNamedImports.has(text))
168
- .join(', ');
188
+ importedNamesList = importedNamesList.filter((text) => !this.removedNamedImports.has(text));
169
189
  }
190
+ if (this.addedNamedImports) {
191
+ importedNamesList = Array.from(new Set([...importedNamesList, ...this.addedNamedImports]));
192
+ }
193
+ importedNames = importedNamesList.sort().join(', ');
170
194
  return `${importStatement}{ ${importedNames} } from '${packageName}';`;
171
195
  }
172
196
  }
173
197
 
198
+ class SimpleImportDeclaration implements IImportDeclaration {
199
+ private readonly packageName: string;
200
+
201
+ private namedImports = new Set<string>();
202
+
203
+ constructor(packageName: string) {
204
+ this.packageName = packageName;
205
+ }
206
+
207
+ public addNamedImport(namedImport: string) {
208
+ this.namedImports.add(namedImport);
209
+ }
210
+
211
+ public removeNamedImport(namedImport: string) {
212
+ this.namedImports.delete(namedImport);
213
+ }
214
+
215
+ public getText() {
216
+ if (this.namedImports.size === 0) {
217
+ return `import '${this.packageName}';`;
218
+ }
219
+ const importedNames = Array.from(this.namedImports)
220
+ .sort()
221
+ .map((name) => `type ${name}`)
222
+ .join(', ');
223
+ return `import { ${importedNames} } from '${this.packageName}';`;
224
+ }
225
+ }
226
+
174
227
  // handles type imports from platform/packages/forge/forge-ui/src/components/UIKit/types.ts
175
228
  const isSharedUIKit2TypesImport = (importDeclaration: ImportDeclaration) => {
176
229
  return (
@@ -502,6 +555,125 @@ const baseGenerateComponentPropTypeSourceCode = (
502
555
  });
503
556
  };
504
557
 
558
+ const registeredExternalTypes: Record<
559
+ string,
560
+ {
561
+ package: string;
562
+ alias?: string;
563
+ }
564
+ > = {
565
+ 'React.ReactNode': {
566
+ package: 'react',
567
+ alias: 'ReactNode',
568
+ },
569
+ };
570
+
571
+ // consolidate external types into import declarations
572
+ const consolidateImportDeclarations = (
573
+ importDeclarations: ImportDeclarationProxy[],
574
+ externalTypes: Set<string>,
575
+ ): IImportDeclaration[] => {
576
+ const declarations: IImportDeclaration[] = [...importDeclarations];
577
+ externalTypes.forEach((typeName) => {
578
+ const typePackage = registeredExternalTypes[typeName];
579
+ if (typePackage) {
580
+ const existingImport = importDeclarations.find(
581
+ (declaration) => declaration.getBasePackage() === typePackage.package,
582
+ );
583
+ if (existingImport) {
584
+ existingImport.addNamedImport(typeName);
585
+ } else {
586
+ const newImport = new SimpleImportDeclaration(typePackage.package);
587
+ newImport.addNamedImport(typePackage.alias ?? typeName);
588
+ declarations.push(newImport);
589
+ }
590
+ }
591
+ });
592
+ return declarations;
593
+ };
594
+
595
+ /**
596
+ * This function implements the new code generation logic for the component prop types.
597
+ * Instead of referencing to the ADS component prop types, it generates the prop types
598
+ * by serializing the ADS component prop types. Hence, it remove the dependency on the
599
+ * ADS components.
600
+ */
601
+ const generateComponentPropTypeSourceCodeWithSerializedType = (
602
+ componentPropSymbol: Symbol,
603
+ sourceFile: SourceFile,
604
+ customConsolidator?: CodeConsolidator,
605
+ ) => {
606
+ // 1) extract the prop types from the source file
607
+ const baseComponentPropSymbol = getBaseComponentSymbol(componentPropSymbol, sourceFile);
608
+
609
+ // 2) from the prop type code further extract other relevant types in the source file,
610
+ // and separate the platform props type declaration from the rest of the dependent types.
611
+ // as this will be used to generate the type code.
612
+ const [dependentTypeDeclarations, platformPropsTypeDeclaration] = getDependentTypeDeclarations(
613
+ baseComponentPropSymbol,
614
+ sourceFile,
615
+ ).reduce(
616
+ (agg, declarations) => {
617
+ if (declarations.getName().startsWith('Platform')) {
618
+ // this is the platform props type declaration, we will use it to generate the type code
619
+ agg[1] = declarations;
620
+ } else {
621
+ agg[0].push(declarations);
622
+ }
623
+ return agg;
624
+ },
625
+ [[] as TypeAliasDeclaration[], null as TypeAliasDeclaration | null],
626
+ );
627
+
628
+ // 3) extract the import statement
629
+ const importDeclarations = extractImportDeclarations(
630
+ sourceFile,
631
+ baseComponentPropSymbol,
632
+ dependentTypeDeclarations,
633
+ );
634
+
635
+ // 4) resolve other types definition (not part of the ADS components)
636
+ const externalTypesCode = resolveExternalTypesCode(
637
+ sourceFile,
638
+ baseComponentPropSymbol,
639
+ dependentTypeDeclarations,
640
+ );
641
+
642
+ // 5) serialize the prop type for the @atlaskit component (e.g. PlatformButtonProps)
643
+ const [typeDefCode, usedExternalTypes] = serializeSymbolType(
644
+ baseComponentPropSymbol,
645
+ sourceFile.getProject().getTypeChecker(),
646
+ );
647
+
648
+ // 6) generate the source file
649
+ const importCode = consolidateImportDeclarations(importDeclarations, usedExternalTypes)
650
+ .map((declaration) => declaration.getText())
651
+ .join('\n');
652
+
653
+ const platformPropsTypeDeclarationName = platformPropsTypeDeclaration?.getName();
654
+ const dependentTypeCode = [
655
+ ...dependentTypeDeclarations.map((typeAlias) => typeAlias.getText()),
656
+ platformPropsTypeDeclarationName &&
657
+ `\n// Serialized type\ntype ${platformPropsTypeDeclarationName} = ${typeDefCode}`,
658
+ ]
659
+ .filter(Boolean)
660
+ .join('\n');
661
+
662
+ const componentPropCode = getComponentPropsTypeCode(baseComponentPropSymbol);
663
+
664
+ // 7) get component type code
665
+ const componentTypeCode = getComponentTypeCode(baseComponentPropSymbol, sourceFile);
666
+
667
+ return (customConsolidator ?? consolidateCodeSections)({
668
+ sourceFile,
669
+ importCode,
670
+ externalTypesCode,
671
+ dependentTypeCode,
672
+ componentPropCode,
673
+ componentTypeCode,
674
+ });
675
+ };
676
+
505
677
  const handleXCSSProp: CodeConsolidator = ({
506
678
  sourceFile,
507
679
  importCode,
@@ -553,11 +725,19 @@ const codeConsolidators: Record<string, CodeConsolidator> = {
553
725
  PressableProps: handleXCSSProp,
554
726
  };
555
727
 
728
+ const typeSerializableComponentPropSymbols = ['CodeProps', 'CodeBlockProps'];
729
+
556
730
  const generateComponentPropTypeSourceCode = (
557
731
  componentPropSymbol: Symbol,
558
732
  sourceFile: SourceFile,
559
733
  ) => {
560
- return baseGenerateComponentPropTypeSourceCode(
734
+ const sourceCodeGenerator = typeSerializableComponentPropSymbols.includes(
735
+ componentPropSymbol.getName(),
736
+ )
737
+ ? generateComponentPropTypeSourceCodeWithSerializedType
738
+ : baseGenerateComponentPropTypeSourceCode;
739
+
740
+ return sourceCodeGenerator(
561
741
  componentPropSymbol,
562
742
  sourceFile,
563
743
  codeConsolidators[componentPropSymbol.getName()],
@@ -0,0 +1,201 @@
1
+ import {
2
+ type Symbol as TSSymbol,
3
+ type Node,
4
+ type TypeChecker,
5
+ type PropertySignature,
6
+ type Type as TSType,
7
+ SyntaxKind,
8
+ } from 'ts-morph';
9
+
10
+ export const serializeSymbolType = (
11
+ symbol: TSSymbol,
12
+ typeChecker: TypeChecker,
13
+ ): [string, Set<string>] => {
14
+ const declaration = symbol.getDeclarations()[0];
15
+
16
+ if (!declaration) {
17
+ throw new Error(`No declaration found for symbol: ${symbol.getName()}`);
18
+ }
19
+
20
+ const usedExternalTypes = new Set<string>();
21
+ if (declaration.getKind() === SyntaxKind.TypeAliasDeclaration) {
22
+ const typeAlias = declaration.asKindOrThrow(SyntaxKind.TypeAliasDeclaration);
23
+ const typeNode = typeAlias.getTypeNode();
24
+ if (typeNode && isCommonComponentPropType(typeNode)) {
25
+ const serializedType = flattenPickType(
26
+ typeNode.asKindOrThrow(SyntaxKind.TypeReference),
27
+ typeChecker,
28
+ usedExternalTypes,
29
+ );
30
+ return [serializedType, usedExternalTypes];
31
+ }
32
+ }
33
+
34
+ throw new Error(
35
+ `Unsupported declaration kind: ${declaration.getKindName()} for symbol: ${symbol.getName()}`,
36
+ );
37
+ };
38
+
39
+ /**
40
+ * Checks if a node is a common component prop type. e.g.
41
+ *
42
+ * export type BleedProps = Pick<
43
+ * PlatformBleedProps,
44
+ * 'children' | 'all' | 'inline' | 'block' | 'testId' | 'role'
45
+ * >;
46
+ */
47
+ const isCommonComponentPropType = (node: Node) => {
48
+ if (node.getKind() === SyntaxKind.TypeReference) {
49
+ const typeRef = node.asKindOrThrow(SyntaxKind.TypeReference);
50
+ const typeName = typeRef.getTypeName().getText();
51
+ return typeName === 'Pick';
52
+ }
53
+ return false;
54
+ };
55
+
56
+ // resolve single level type references (e.g. SupportedLanguages))
57
+ // type SupportedLanguages = 'text' | 'PHP' | 'Java' | 'CSharp' | ...;
58
+ const isSimpleTypeReferenceNode = (node: Node): boolean => {
59
+ const type = node.getType();
60
+ if (type.isUnion()) {
61
+ const unionTypes = type.getUnionTypes();
62
+ return unionTypes.every((t) => {
63
+ return t.isString() || t.isStringLiteral() || t.isNumber() || t.isBoolean();
64
+ });
65
+ }
66
+ return false;
67
+ };
68
+
69
+ const serializeSimpleTypeNode = (node: Node): string => {
70
+ switch (node.getKind()) {
71
+ case SyntaxKind.UnionType:
72
+ const unionType = node.asKindOrThrow(SyntaxKind.UnionType);
73
+ const unionTypes = unionType.getTypeNodes().map((t) => serializeSimpleTypeNode(t));
74
+ return unionTypes.join(' | ');
75
+
76
+ case SyntaxKind.StringLiteral:
77
+ return `'${node.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue()}'`;
78
+ case SyntaxKind.TypeReference:
79
+ // resolve single level type references (e.g. SupportedLanguages))
80
+ if (isSimpleTypeReferenceNode(node)) {
81
+ return node
82
+ .getType()
83
+ .getUnionTypes()
84
+ .map((t) => t.getText())
85
+ .join(' | ');
86
+ }
87
+ }
88
+ return node.getText();
89
+ };
90
+
91
+ const serializePropertySignatureCode = (propertySignature: PropertySignature) => {
92
+ return `${propertySignature.getName()}: ${serializeSimpleTypeNode(propertySignature.getTypeNode()!)};`;
93
+ };
94
+
95
+ const flattenPickType = (
96
+ typeRef: Node,
97
+ typeChecker: TypeChecker,
98
+ usedExternalTypesOutput: Set<string>,
99
+ ): string => {
100
+ const typeArgs = typeRef.asKindOrThrow(SyntaxKind.TypeReference).getTypeArguments();
101
+
102
+ if (typeArgs.length < 2) {
103
+ return typeRef.getText(); // Fallback if not a valid Pick
104
+ }
105
+
106
+ const keysNode = typeArgs[1];
107
+
108
+ // Get the selected keys
109
+ const selectedKeys = extractUnionKeys(keysNode);
110
+
111
+ // Get the base type symbol
112
+ const properties = typeRef
113
+ .getType()
114
+ .getProperties()
115
+ .filter((prop) => selectedKeys.includes(prop.getName()));
116
+
117
+ if (properties.length === 0) {
118
+ return '{}'; // If no properties match, return 'any'
119
+ }
120
+
121
+ const serializedProperties = properties
122
+ .map((prop) => {
123
+ const propertySignature = prop.getDeclarations()[0] as PropertySignature | undefined;
124
+ if (!propertySignature) {
125
+ return null; // Skip if no declaration
126
+ }
127
+ const jsDoc = propertySignature.getJsDocs()?.[0]?.getText();
128
+ const typeCode = `\t${serializePropertySignatureCode(propertySignature)}`;
129
+ getUnresolvableTypes(propertySignature.getType()).forEach((typeName) => {
130
+ usedExternalTypesOutput.add(typeName);
131
+ });
132
+ return [jsDoc, typeCode].filter(Boolean).join('\n');
133
+ })
134
+ .filter(Boolean);
135
+
136
+ if (serializedProperties.length === 0) {
137
+ return '{}'; // If no properties are serialized, return empty object
138
+ }
139
+ return `{\n ${serializedProperties.join('\n ')}\n}`;
140
+ };
141
+
142
+ const getUnresolvableTypes = (tsType: TSType) => {
143
+ const unresolvableTypes = new Set<string>();
144
+ getUnresolvableTypesBase(tsType, unresolvableTypes);
145
+ return unresolvableTypes;
146
+ };
147
+
148
+ const getUnresolvableTypesBase = (tsType: TSType, unresolvableTypes: Set<string>) => {
149
+ if (isExternalType(tsType)) {
150
+ unresolvableTypes.add(tsType.getText());
151
+ } else if (tsType.isUnion()) {
152
+ const unionTypes = tsType.getUnionTypes();
153
+ unionTypes.forEach((type) => {
154
+ getUnresolvableTypesBase(type, unresolvableTypes);
155
+ });
156
+ } else if (!isBasicType(tsType)) {
157
+ unresolvableTypes.add(tsType.getText());
158
+ }
159
+ };
160
+
161
+ const isBasicType = (tsType: TSType): boolean => {
162
+ return (
163
+ tsType.isString() ||
164
+ tsType.isNumber() ||
165
+ tsType.isBoolean() ||
166
+ tsType.isNull() ||
167
+ tsType.isUndefined() ||
168
+ tsType.isAny() ||
169
+ tsType.isUnknown() ||
170
+ tsType.isNever()
171
+ );
172
+ };
173
+
174
+ const isExternalType = (tsType: TSType): boolean => {
175
+ const symbol = tsType.getSymbol() ?? tsType.getAliasSymbol();
176
+ if (!symbol) {return false;}
177
+
178
+ const declaration = symbol.getDeclarations()?.[0];
179
+ if (!declaration) {return false;}
180
+
181
+ const sourceFile = declaration.getSourceFile();
182
+ const filePath = sourceFile.getFilePath();
183
+
184
+ return filePath.includes('node_modules');
185
+ };
186
+
187
+ const extractUnionKeys = (keysNode: Node): string[] => {
188
+ if (keysNode.getKind() === SyntaxKind.UnionType) {
189
+ const unionType = keysNode.asKindOrThrow(SyntaxKind.UnionType);
190
+ return unionType.getTypeNodes().map((node) => {
191
+ if (node.getKind() === SyntaxKind.StringLiteral) {
192
+ return node.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue();
193
+ }
194
+ return node.getText().replace(/['"]/g, '');
195
+ });
196
+ } else if (keysNode.getKind() === SyntaxKind.StringLiteral) {
197
+ return [keysNode.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue()];
198
+ }
199
+
200
+ return [keysNode.getText().replace(/['"]/g, '')];
201
+ };
@@ -3,16 +3,64 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeBlockProps
5
5
  *
6
- * @codegen <<SignedSource::8ab4ed1e38d2bd1f9ceafe4cbc20f97d>>
6
+ * @codegen <<SignedSource::8fded8a55e24b0312739eb3ab66f63ca>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/codeblock.partial.tsx <<SignedSource::88ed38fdfc47db0938e7801195a00403>>
9
9
  */
10
10
  /* eslint @repo/internal/codegen/signed-source-integrity: "warn" */
11
11
 
12
- import React from 'react';
13
- import { CodeBlock as PlatformCodeBlock } from '@atlaskit/code';
14
12
 
15
- type PlatformCodeBlockProps = React.ComponentProps<typeof PlatformCodeBlock>;
13
+ // Serialized type
14
+ type PlatformCodeBlockProps = {
15
+ /**
16
+ * The code to be formatted.
17
+ */
18
+ text: string;
19
+ /**
20
+ * A unique string that appears as a data attribute `data-testid` in the
21
+ * rendered code. Serves as a hook for automated tests.
22
+ */
23
+ testId: string;
24
+ /**
25
+ * Sets whether to display code line numbers or not.
26
+ * @default true
27
+ */
28
+ showLineNumbers: boolean;
29
+ /**
30
+ * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
31
+ * `design-system/code`. Run against language grammars from PrismJS (full list
32
+ * available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
33
+ *
34
+ * When set to "text" will not perform highlighting. If unsupported language
35
+ * provided - code will be treated as "text" with no highlighting.
36
+ *
37
+ * @default 'text'
38
+ */
39
+ language: "text" | "PHP" | "php" | "php3" | "php4" | "php5" | "Java" | "java" | "CSharp" | "csharp" | "c#" | "Python" | "python" | "py" | "JavaScript" | "javascript" | "js" | "Html" | "html" | "xml" | "C++" | "c++" | "cpp" | "clike" | "Ruby" | "ruby" | "rb" | "duby" | "Objective-C" | "objective-c" | "objectivec" | "obj-c" | "objc" | "C" | "c" | "Swift" | "swift" | "TeX" | "tex" | "latex" | "Shell" | "shell" | "bash" | "sh" | "ksh" | "zsh" | "Scala" | "scala" | "Go" | "go" | "ActionScript" | "actionscript" | "actionscript3" | "as" | "ColdFusion" | "coldfusion" | "JavaFX" | "javafx" | "jfx" | "VbNet" | "vbnet" | "vb.net" | "vfp" | "clipper" | "xbase" | "JSON" | "json" | "MATLAB" | "matlab" | "Groovy" | "groovy" | "SQL" | "sql" | "postgresql" | "postgres" | "plpgsql" | "psql" | "postgresql-console" | "postgres-console" | "tsql" | "t-sql" | "mysql" | "sqlite" | "R" | "r" | "Perl" | "perl" | "pl" | "Lua" | "lua" | "Pascal" | "pas" | "pascal" | "objectpascal" | "delphi" | "XML" | "TypeScript" | "typescript" | "ts" | "CoffeeScript" | "coffeescript" | "coffee-script" | "coffee" | "Haskell" | "haskell" | "hs" | "Puppet" | "puppet" | "Arduino" | "arduino" | "Fortran" | "fortran" | "Erlang" | "erlang" | "erl" | "PowerShell" | "powershell" | "posh" | "ps1" | "psm1" | "Haxe" | "haxe" | "hx" | "hxsl" | "Elixir" | "elixir" | "ex" | "exs" | "Verilog" | "verilog" | "v" | "Rust" | "rust" | "VHDL" | "vhdl" | "Sass" | "sass" | "OCaml" | "ocaml" | "Dart" | "dart" | "CSS" | "css" | "reStructuredText" | "restructuredtext" | "rst" | "rest" | "Kotlin" | "kotlin" | "D" | "d" | "Octave" | "octave" | "QML" | "qbs" | "qml" | "Prolog" | "prolog" | "FoxPro" | "foxpro" | "purebasic" | "Scheme" | "scheme" | "scm" | "CUDA" | "cuda" | "cu" | "Julia" | "julia" | "jl" | "Racket" | "racket" | "rkt" | "Ada" | "ada" | "ada95" | "ada2005" | "Tcl" | "tcl" | "Mathematica" | "mathematica" | "mma" | "nb" | "Autoit" | "autoit" | "StandardML" | "standardmL" | "sml" | "standardml" | "Objective-J" | "objective-j" | "objectivej" | "obj-j" | "objj" | "Smalltalk" | "smalltalk" | "squeak" | "st" | "Vala" | "vala" | "vapi" | "LiveScript" | "livescript" | "live-script" | "XQuery" | "xquery" | "xqy" | "xq" | "xql" | "xqm" | "PlainText" | "plaintext" | "Yaml" | "yaml" | "yml" | "GraphQL" | "graphql" | "AppleScript" | "applescript" | "Clojure" | "clojure" | "Diff" | "diff" | "VisualBasic" | "visualbasic" | "JSX" | "jsx" | "TSX" | "tsx" | "SplunkSPL" | "splunk-spl" | "Dockerfile" | "docker" | "dockerfile" | "HCL" | "hcl" | "terraform" | "NGINX" | "nginx" | "Protocol Buffers" | "protobuf" | "proto" | "Handlebars" | "handlebars" | "mustache" | "Gherkin" | "gherkin" | "cucumber" | "ABAP" | "abap";
40
+ /**
41
+ * Comma delimited lines to highlight.
42
+ *
43
+ * Example uses:
44
+ * - To highlight one line `highlight="3"`
45
+ * - To highlight a group of lines `highlight="1-5"`
46
+ * - To highlight multiple groups `highlight="1-5,7,10,15-20"`
47
+ */
48
+ highlight: string;
49
+ /**
50
+ * Screen reader text for the start of a highlighted line.
51
+ */
52
+ highlightedStartText: string;
53
+ /**
54
+ * Screen reader text for the end of a highlighted line.
55
+ */
56
+ highlightedEndText: string;
57
+ /**
58
+ * Sets whether long lines will create a horizontally scrolling container.
59
+ * When set to `true`, these lines will visually wrap instead.
60
+ * @default false
61
+ */
62
+ shouldWrapLongLines: boolean;
63
+ }
16
64
 
17
65
  export type CodeBlockProps = Pick<
18
66
  PlatformCodeBlockProps,
@@ -3,16 +3,27 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - CodeProps
5
5
  *
6
- * @codegen <<SignedSource::baf6b565e34d8df53db53b8855ec120d>>
6
+ * @codegen <<SignedSource::7ea0b6ee7be9f3e5454b38e528c0753f>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
8
  * @codegenDependency ../../../../forge-ui/src/components/UIKit/code/__generated__/code.partial.tsx <<SignedSource::6f210b052488fe7ece12d865706a551e>>
9
9
  */
10
10
  /* eslint @repo/internal/codegen/signed-source-integrity: "warn" */
11
11
 
12
- import React from 'react';
13
- import { Code as PlatformCode } from '@atlaskit/code';
12
+ import { type ReactNode } from 'react';
14
13
 
15
- type PlatformCodeProps = React.ComponentProps<typeof PlatformCode>;
14
+
15
+ // Serialized type
16
+ type PlatformCodeProps = {
17
+ /**
18
+ * A unique string that appears as a data attribute `data-testid`
19
+ * in the rendered code. Serves as a hook for automated tests.
20
+ */
21
+ testId: string;
22
+ /**
23
+ * Content to be rendered in the inline code block.
24
+ */
25
+ children: ReactNode;
26
+ }
16
27
 
17
28
  export type CodeProps = Pick<
18
29
  PlatformCodeProps,