@likec4/generators 0.32.0 → 0.33.1

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.
@@ -7,6 +7,9 @@ const componentName = (value) => {
7
7
  value = value.replaceAll('_', '');
8
8
  return value.charAt(0).toLocaleUpperCase() + value.slice(1);
9
9
  };
10
+ const generateViewId = (views) => joinToNode(views, view => expandToNode `'${view.id}'`, {
11
+ separator: ' | '
12
+ });
10
13
  export function generateReact(views) {
11
14
  const components = views.map(({ id }) => {
12
15
  return {
@@ -22,15 +25,18 @@ export function generateReact(views) {
22
25
  ******************************************************************************/
23
26
  /* eslint-disable */
24
27
 
25
- import type { DiagramView, EmbeddedDiagramProps } from '@likec4/diagrams'
26
- import { EmbeddedDiagram } from '@likec4/diagrams'
28
+ import type { DiagramView } from '@likec4/core'
29
+ import { LikeC4 } from '@likec4/diagrams'
27
30
  `.append(NL, NL);
28
31
  if (components.length == 0) {
29
32
  out.append('export {}', NL);
30
33
  return toString(out);
31
34
  }
32
- out
33
- .append('export const LikeC4ViewsData = {', NL)
35
+ out.appendTemplate `
36
+
37
+ export type LikeC4ViewId = ${generateViewId(views)};
38
+ export const LikeC4Views = {
39
+ `
34
40
  .indent({
35
41
  indentation: 2,
36
42
  indentedChildren: indent => {
@@ -40,39 +46,42 @@ export function generateReact(views) {
40
46
  }));
41
47
  }
42
48
  })
43
- .append('} as const', NL, NL).appendTemplate `
44
- export type LikeC4ViewsData = typeof LikeC4ViewsData
45
- export type LikeC4ViewId = keyof LikeC4ViewsData
46
- export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
47
- return typeof value === 'string' && value in LikeC4ViewsData
48
- }
49
+ .append('} as const satisfies Record<LikeC4ViewId, DiagramView>', NL, NL).appendTemplate `
50
+ export type LikeC4Views = typeof LikeC4Views
49
51
 
50
- export type LikeC4ViewProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, LikeC4ViewId>, 'views'>;
51
- export function LikeC4View(props: LikeC4ViewProps) {
52
- return <EmbeddedDiagram views={LikeC4ViewsData} {...props}/>
53
- }
52
+ export const {
53
+ isViewId,
54
+ Diagram,
55
+ Responsive,
56
+ Embedded,
57
+ Browser
58
+ } = LikeC4.create(LikeC4Views)
54
59
 
55
- type LikeC4ViewsProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, LikeC4ViewId>, 'views' | 'viewId'>
56
- export const LikeC4Views = {
57
- `
58
- .append(NL)
59
- .indent({
60
- indentation: 2,
61
- indentedChildren: components.map(({ id, name }) => expandToNode `
62
- ['${name}']: (props: LikeC4ViewsProps) => <LikeC4View viewId={'${id}'} {...props}/>,
63
- `.append(NL))
64
- // indentedChildren: [joinToNode(
65
- // components,
66
- // ({ id, name }) =>
67
- // expandToNode`
68
- // ['${name}']: (props: NamedViewProps) => <EmbeddedDiagram views={LikeC4ViewsData} viewId={'${id}'} {...props}/>
69
- // `,
70
- // {
71
- // separator: ',',
72
- // appendNewLineIfNotEmpty: true
73
- // }
74
- // )],
75
- })
76
- .append('} as const', NL, NL);
60
+ export type DiagramProps = LikeC4.Props<LikeC4ViewId>
61
+ export type ResponsiveProps = LikeC4.ResponsiveProps<LikeC4ViewId>
62
+ export type EmbeddedProps = LikeC4.EmbeddedProps<LikeC4ViewId>
63
+ export type BrowserProps = LikeC4.BrowserProps<LikeC4ViewId>
64
+
65
+ `.append(NL, NL).appendTemplate `
66
+ export type {
67
+ DiagramApi
68
+ } from '@likec4/diagrams'
69
+
70
+ export type {
71
+ Fqn,
72
+ Element,
73
+ RelationID,
74
+ Relation,
75
+ NodeId,
76
+ EdgeId,
77
+ ComputedNode,
78
+ ComputedEdge,
79
+ ComputedView,
80
+ DiagramView,
81
+ DiagramNode,
82
+ DiagramEdge,
83
+ DiagramLabel
84
+ } from '@likec4/core'
85
+ `.append(NL, NL);
77
86
  return toString(out);
78
87
  }
@@ -9,10 +9,10 @@ export function generateViewsDataTs(views) {
9
9
  ******************************************************************************/
10
10
  /* eslint-disable */
11
11
 
12
- import type { DiagramView } from '@likec4/diagrams'
12
+ import type { DiagramView } from '@likec4/core'
13
13
  `.append(NL, NL);
14
14
  out
15
- .append('export const LikeC4ViewsData = {', NL)
15
+ .append('export const LikeC4Views = {', NL)
16
16
  .indent({
17
17
  indentation: 2,
18
18
  indentedChildren: indent => {
@@ -23,11 +23,32 @@ export function generateViewsDataTs(views) {
23
23
  }
24
24
  })
25
25
  .append('} as const', NL, NL).appendTemplate `
26
- export type LikeC4ViewsData = typeof LikeC4ViewsData
27
- export type LikeC4ViewId = keyof LikeC4ViewsData
26
+ export type LikeC4Views = typeof LikeC4Views
27
+ export type LikeC4ViewId = keyof LikeC4Views
28
+
28
29
  export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
29
- return typeof value === 'string' && value in LikeC4ViewsData
30
+ return (
31
+ value != null &&
32
+ typeof value === 'string' &&
33
+ Object.prototype.hasOwnProperty.call(LikeC4Views, value)
34
+ )
30
35
  }
31
- `.append(NL);
36
+ `.append(NL, NL).appendTemplate `
37
+ export type {
38
+ Fqn,
39
+ Element,
40
+ RelationID,
41
+ Relation,
42
+ NodeId,
43
+ EdgeId,
44
+ ComputedNode,
45
+ ComputedEdge,
46
+ ComputedView,
47
+ DiagramView,
48
+ DiagramNode,
49
+ DiagramEdge,
50
+ DiagramLabel
51
+ } from '@likec4/core'
52
+ `.append(NL, NL);
32
53
  return toString(out);
33
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/generators",
3
- "version": "0.32.0",
3
+ "version": "0.33.1",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -38,7 +38,7 @@
38
38
  "test:watch": "run -T vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@likec4/core": "0.32.0",
41
+ "@likec4/core": "0.33.1",
42
42
  "json5": "^2.2.3",
43
43
  "langium": "^1.2.1",
44
44
  "rambdax": "^9.1.1"