@teambit/compositions 0.0.554 → 0.0.558

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 (35) hide show
  1. package/dist/composition.d.ts +22 -1
  2. package/dist/composition.section.d.ts +8 -1
  3. package/dist/compositions.main.runtime.d.ts +56 -1
  4. package/dist/compositions.preview.runtime.d.ts +9 -1
  5. package/dist/compositions.ui.runtime.d.ts +3 -0
  6. package/dist/ui/composition-preview.d.ts +15 -0
  7. package/package.json +34 -26
  8. package/tsconfig.json +1 -2
  9. package/composition.section.tsx +0 -29
  10. package/composition.ts +0 -44
  11. package/compositions.aspect.ts +0 -9
  12. package/compositions.docs.mdx +0 -8
  13. package/compositions.graphql.ts +0 -32
  14. package/compositions.main.runtime.ts +0 -164
  15. package/compositions.module.scss +0 -100
  16. package/compositions.preview-definition.ts +0 -21
  17. package/compositions.preview.runtime.ts +0 -67
  18. package/compositions.tsx +0 -185
  19. package/compositions.ui.runtime.tsx +0 -53
  20. package/index.ts +0 -10
  21. package/package-tar/teambit-compositions-0.0.554.tgz +0 -0
  22. package/types/asset.d.ts +0 -29
  23. package/types/style.d.ts +0 -42
  24. package/ui/composition-preview.tsx +0 -60
  25. package/ui/compositions-overview/compositions-overview.module.scss +0 -16
  26. package/ui/compositions-overview/compositions-overview.tsx +0 -21
  27. package/ui/compositions-overview/index.ts +0 -1
  28. package/ui/compositions-panel/compositions-panel.module.scss +0 -119
  29. package/ui/compositions-panel/compositions-panel.tsx +0 -58
  30. package/ui/compositions-panel/index.ts +0 -0
  31. package/ui/compositions-panel-node/compositions-panel-node.module.scss +0 -15
  32. package/ui/compositions-panel-node/compositions-panel-node.tsx +0 -22
  33. package/ui/compositions-panel-node/index.ts +0 -1
  34. package/ui/index.ts +0 -1
  35. package/ui/use-compositions.tsx +0 -14
@@ -4,10 +4,31 @@ export declare type CompositionProps = {
4
4
  displayName?: string;
5
5
  };
6
6
  export declare class Composition {
7
+ /**
8
+ * identifier of the composition
9
+ */
7
10
  readonly identifier: string;
11
+ /**
12
+ * file path in which the composition is contained.
13
+ */
8
14
  readonly filepath?: string | undefined;
15
+ /**
16
+ * set explicit display name
17
+ */
9
18
  private _displayName?;
10
- constructor(identifier: string, filepath?: string | undefined, _displayName?: string | undefined);
19
+ constructor(
20
+ /**
21
+ * identifier of the composition
22
+ */
23
+ identifier: string,
24
+ /**
25
+ * file path in which the composition is contained.
26
+ */
27
+ filepath?: string | undefined,
28
+ /**
29
+ * set explicit display name
30
+ */
31
+ _displayName?: string | undefined);
11
32
  get displayName(): string;
12
33
  toObject(): {
13
34
  identifier: string;
@@ -4,10 +4,17 @@ declare type Options = {
4
4
  menuBarWidgetSlot: CompositionsMenuSlot;
5
5
  };
6
6
  export declare class CompositionsSection implements Section {
7
+ /**
8
+ * simulations ui extension.
9
+ */
7
10
  private compositions;
8
11
  private options;
9
12
  private emptyStateSlot;
10
- constructor(compositions: CompositionsUI, options: Options, emptyStateSlot: EmptyStateSlot);
13
+ constructor(
14
+ /**
15
+ * simulations ui extension.
16
+ */
17
+ compositions: CompositionsUI, options: Options, emptyStateSlot: EmptyStateSlot);
11
18
  navigationLink: {
12
19
  href: string;
13
20
  children: string;
@@ -7,19 +7,74 @@ import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
7
7
  import { DevFilesMain } from '@teambit/dev-files';
8
8
  import { Composition } from './composition';
9
9
  export declare type CompositionsConfig = {
10
+ /**
11
+ * glob pattern to detect composition files. This includes all related files, like styles and jsons.
12
+ * @example ['/*.composition?(s).*']
13
+ */
10
14
  compositionFilePattern: string[];
15
+ /**
16
+ * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.
17
+ * @example ['*.{t,j}s', '*.{t,j}sx']
18
+ */
11
19
  compositionPreviewFilePattern: string[];
12
20
  };
21
+ /**
22
+ * the component documentation extension.
23
+ */
13
24
  export declare class CompositionsMain {
25
+ /**
26
+ * Glob pattern to select all composition files
27
+ */
14
28
  private compositionFilePattern;
29
+ /**
30
+ * Glob pattern to select composition preview files
31
+ */
15
32
  private previewFilePattern;
33
+ /**
34
+ * envs extension.
35
+ */
16
36
  private preview;
37
+ /**
38
+ * workspace extension.
39
+ */
17
40
  private workspace;
41
+ /**
42
+ * schema extension.
43
+ */
18
44
  private schema;
19
45
  private devFiles;
20
- constructor(compositionFilePattern: string[], previewFilePattern: string[], preview: PreviewMain, workspace: Workspace, schema: SchemaMain, devFiles: DevFilesMain);
46
+ constructor(
47
+ /**
48
+ * Glob pattern to select all composition files
49
+ */
50
+ compositionFilePattern: string[],
51
+ /**
52
+ * Glob pattern to select composition preview files
53
+ */
54
+ previewFilePattern: string[],
55
+ /**
56
+ * envs extension.
57
+ */
58
+ preview: PreviewMain,
59
+ /**
60
+ * workspace extension.
61
+ */
62
+ workspace: Workspace,
63
+ /**
64
+ * schema extension.
65
+ */
66
+ schema: SchemaMain, devFiles: DevFilesMain);
67
+ /**
68
+ * returns an array of doc file paths for a set of components.
69
+ */
21
70
  getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]>;
71
+ /**
72
+ * get component compositions.
73
+ */
22
74
  getCompositions(component: Component): Composition[];
75
+ /**
76
+ * read composition from the component source code.
77
+ */
23
78
  readCompositions(component: Component): Composition[];
24
79
  onComponentLoad(component: Component): Promise<AspectData>;
25
80
  private computeCompositions;
@@ -1,8 +1,16 @@
1
1
  import { PreviewPreview, RenderingContext, PreviewModule } from '@teambit/preview';
2
2
  export declare class CompositionsPreview {
3
+ /**
4
+ * preview extension.
5
+ */
3
6
  private preview;
4
- constructor(preview: PreviewPreview);
7
+ constructor(
8
+ /**
9
+ * preview extension.
10
+ */
11
+ preview: PreviewPreview);
5
12
  render(componentId: string, modules: PreviewModule, otherPreviewDefs: any, context: RenderingContext): void;
13
+ /** gets relevant information for this preview to render */
6
14
  selectPreviewModel(componentId: string, previewModule: PreviewModule): any;
7
15
  private getActiveComposition;
8
16
  static runtime: import("@teambit/harmony").RuntimeDefinition;
@@ -9,6 +9,9 @@ export declare class CompositionsUI {
9
9
  private menuBarWidgetSlot;
10
10
  private emptyStateSlot;
11
11
  constructor(menuBarWidgetSlot: CompositionsMenuSlot, emptyStateSlot: EmptyStateSlot);
12
+ /**
13
+ * register a new tester empty state. this allows to register a different empty state from each environment for example.
14
+ */
12
15
  registerEmptyState(emptyStateComponent: ComponentType): this;
13
16
  registerMenuWidget(...widget: MenuBarWidget[]): void;
14
17
  static dependencies: import("@teambit/harmony").Aspect[];
@@ -1,10 +1,25 @@
1
1
  import { ComponentModel } from '@teambit/component';
2
2
  import { Composition } from '../composition';
3
3
  export declare type ComponentCompositionProps = {
4
+ /**
5
+ * HTML class
6
+ */
4
7
  className?: string;
8
+ /**
9
+ * component to render.
10
+ */
5
11
  component: ComponentModel;
12
+ /**
13
+ * composition to use for component rendering.
14
+ */
6
15
  composition?: Composition;
16
+ /**
17
+ * Additional query params to append at the end of the *hash*. Changing this property will not reload the composition.
18
+ */
7
19
  queryParams?: string | string[];
20
+ /**
21
+ * skip hot reload
22
+ */
8
23
  hotReload?: boolean;
9
24
  };
10
25
  export declare function ComponentComposition({ component, composition, hotReload, className, queryParams, }: ComponentCompositionProps): JSX.Element;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compositions",
3
- "version": "0.0.554",
3
+ "version": "0.0.558",
4
4
  "homepage": "https://bit.dev/teambit/compositions/compositions",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compositions",
8
8
  "name": "compositions",
9
- "version": "0.0.554"
9
+ "version": "0.0.558"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -23,32 +23,32 @@
23
23
  "@teambit/documenter.ui.heading": "4.1.1",
24
24
  "@teambit/documenter.ui.property-table": "4.1.3",
25
25
  "@teambit/evangelist.elements.icon": "1.0.2",
26
- "@teambit/component": "0.0.554",
27
- "@teambit/compositions.model.composition-id": "0.0.462",
28
- "@teambit/graphql": "0.0.554",
29
- "@teambit/cli": "0.0.385",
30
- "@teambit/dev-files": "0.0.554",
31
- "@teambit/preview": "0.0.554",
32
- "@teambit/schema": "0.0.554",
33
- "@teambit/workspace": "0.0.554",
34
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.462",
35
- "@teambit/envs": "0.0.554",
36
- "@teambit/compositions.ui.compositions-menu-bar": "0.0.139",
37
- "@teambit/compositions.ui.hooks.use-composition": "0.0.139",
26
+ "@teambit/component": "0.0.558",
27
+ "@teambit/compositions.model.composition-id": "0.0.465",
28
+ "@teambit/graphql": "0.0.558",
29
+ "@teambit/cli": "0.0.388",
30
+ "@teambit/dev-files": "0.0.558",
31
+ "@teambit/preview": "0.0.558",
32
+ "@teambit/schema": "0.0.558",
33
+ "@teambit/workspace": "0.0.558",
34
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.465",
35
+ "@teambit/envs": "0.0.558",
36
+ "@teambit/compositions.ui.compositions-menu-bar": "0.0.142",
37
+ "@teambit/compositions.ui.hooks.use-composition": "0.0.142",
38
38
  "@teambit/design.ui.alert-card": "0.0.13",
39
39
  "@teambit/design.ui.empty-box": "0.0.352",
40
40
  "@teambit/design.ui.input.option-button": "0.0.26",
41
41
  "@teambit/design.ui.separator": "0.0.351",
42
42
  "@teambit/design.ui.surfaces.status-message-card": "0.0.6",
43
- "@teambit/docs.ui.queries.get-docs": "0.0.462",
44
- "@teambit/mdx.ui.mdx-layout": "0.0.466",
45
- "@teambit/panels": "0.0.385",
46
- "@teambit/preview.ui.component-preview": "0.0.462",
47
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.167",
48
- "@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.155",
49
- "@teambit/ui": "0.0.554",
50
- "@teambit/compositions.model.composition-type": "0.0.463",
51
- "@teambit/compositions.ui.composition-card": "0.0.468"
43
+ "@teambit/docs.ui.queries.get-docs": "0.0.465",
44
+ "@teambit/mdx.ui.mdx-layout": "0.0.469",
45
+ "@teambit/panels": "0.0.388",
46
+ "@teambit/preview.ui.component-preview": "0.0.465",
47
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.170",
48
+ "@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.158",
49
+ "@teambit/ui": "0.0.558",
50
+ "@teambit/compositions.model.composition-type": "0.0.466",
51
+ "@teambit/compositions.ui.composition-card": "0.0.471"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/react": "^17.0.8",
@@ -59,10 +59,10 @@
59
59
  "@types/jest": "^26.0.0",
60
60
  "@types/react-dom": "^17.0.5",
61
61
  "@types/node": "12.20.4",
62
- "@teambit/compositions.aspect-docs.compositions": "0.0.104"
62
+ "@teambit/compositions.aspect-docs.compositions": "0.0.107"
63
63
  },
64
64
  "peerDependencies": {
65
- "@teambit/legacy": "1.0.171",
65
+ "@teambit/legacy": "1.0.174",
66
66
  "react-dom": "^16.8.0 || ^17.0.0",
67
67
  "react": "^16.8.0 || ^17.0.0"
68
68
  },
@@ -90,12 +90,20 @@
90
90
  "react": "-"
91
91
  },
92
92
  "peerDependencies": {
93
- "@teambit/legacy": "1.0.171",
93
+ "@teambit/legacy": "1.0.174",
94
94
  "react-dom": "^16.8.0 || ^17.0.0",
95
95
  "react": "^16.8.0 || ^17.0.0"
96
96
  }
97
97
  }
98
98
  },
99
+ "files": [
100
+ "dist",
101
+ "!dist/tsconfig.tsbuildinfo",
102
+ "README.md",
103
+ "README.mdx",
104
+ "*.js",
105
+ "*.json"
106
+ ],
99
107
  "private": false,
100
108
  "engines": {
101
109
  "node": ">=12.22.0"
package/tsconfig.json CHANGED
@@ -15,9 +15,9 @@
15
15
  "skipLibCheck": true,
16
16
  "moduleResolution": "node",
17
17
  "esModuleInterop": true,
18
- "outDir": "dist",
19
18
  "composite": true,
20
19
  "emitDeclarationOnly": true,
20
+ "outDir": "dist",
21
21
  "experimentalDecorators": true,
22
22
  "emitDecoratorMetadata": true,
23
23
  "allowSyntheticDefaultImports": true,
@@ -25,7 +25,6 @@
25
25
  "strict": true,
26
26
  "noImplicitAny": false,
27
27
  "rootDir": ".",
28
- "removeComments": true,
29
28
  "preserveConstEnums": true,
30
29
  "resolveJsonModule": true
31
30
  },
@@ -1,29 +0,0 @@
1
- import { Section } from '@teambit/component';
2
- import React from 'react';
3
- import { Compositions } from './compositions';
4
- import type { CompositionsUI, CompositionsMenuSlot, EmptyStateSlot } from './compositions.ui.runtime';
5
-
6
- type Options = { menuBarWidgetSlot: CompositionsMenuSlot };
7
-
8
- export class CompositionsSection implements Section {
9
- constructor(
10
- /**
11
- * simulations ui extension.
12
- */
13
- private compositions: CompositionsUI,
14
- private options: Options,
15
- private emptyStateSlot: EmptyStateSlot
16
- ) {}
17
-
18
- navigationLink = {
19
- href: '~compositions',
20
- children: 'Compositions',
21
- };
22
-
23
- route = {
24
- path: '~compositions',
25
- children: <Compositions menuBarWidgets={this.options.menuBarWidgetSlot} emptyState={this.emptyStateSlot} />,
26
- };
27
-
28
- order = 20;
29
- }
package/composition.ts DELETED
@@ -1,44 +0,0 @@
1
- import { humanizeCompositionId } from '@teambit/compositions.model.composition-id';
2
-
3
- export type CompositionProps = {
4
- identifier: string;
5
- filepath?: string;
6
- displayName?: string;
7
- };
8
-
9
- export class Composition {
10
- constructor(
11
- /**
12
- * identifier of the composition
13
- */
14
- readonly identifier: string,
15
-
16
- /**
17
- * file path in which the composition is contained.
18
- */
19
- readonly filepath?: string,
20
-
21
- /**
22
- * set explicit display name
23
- */
24
- private _displayName?: string
25
- ) {}
26
-
27
- get displayName() {
28
- return this._displayName || humanizeCompositionId(this.identifier);
29
- }
30
-
31
- toObject() {
32
- return {
33
- identifier: this.identifier,
34
- filepath: this.filepath,
35
- displayName: this._displayName,
36
- };
37
- }
38
-
39
- static fromArray(compositions: CompositionProps[]): Composition[] {
40
- return compositions.map((composition) => {
41
- return new Composition(composition.identifier, composition.filepath, composition.displayName);
42
- });
43
- }
44
- }
@@ -1,9 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const CompositionsAspect = Aspect.create({
4
- id: 'teambit.compositions/compositions',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
8
-
9
- export default CompositionsAspect;
@@ -1,8 +0,0 @@
1
- ---
2
- description: Renders component instances as part of different compositions.
3
- labels: ['ui', 'tests']
4
- ---
5
-
6
- import { Compositions } from '@teambit/compositions.aspect-docs.compositions';
7
-
8
- <Compositions />
@@ -1,32 +0,0 @@
1
- import { Component } from '@teambit/component';
2
- import { Schema } from '@teambit/graphql';
3
- import gql from 'graphql-tag';
4
-
5
- import { CompositionsMain } from './compositions.main.runtime';
6
-
7
- export function compositionsSchema(compositions: CompositionsMain): Schema {
8
- return {
9
- typeDefs: gql`
10
- extend type Component {
11
- compositions: [Composition]
12
- }
13
-
14
- type Subscription {
15
- compositionAdded: Composition
16
- }
17
-
18
- type Composition {
19
- filepath: String
20
- identifier: String
21
- displayName: String
22
- }
23
- `,
24
- resolvers: {
25
- Component: {
26
- compositions: (component: Component) => {
27
- return compositions.getCompositions(component);
28
- },
29
- },
30
- },
31
- };
32
- }
@@ -1,164 +0,0 @@
1
- import { join } from 'path';
2
- import { MainRuntime } from '@teambit/cli';
3
- import { Component, ComponentAspect, ComponentMap, AspectData } from '@teambit/component';
4
- import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
5
- import { PreviewAspect, PreviewMain } from '@teambit/preview';
6
- import { SchemaAspect, SchemaMain } from '@teambit/schema';
7
- import { Workspace, WorkspaceAspect } from '@teambit/workspace';
8
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
9
- import { flatten } from '@teambit/legacy/dist/utils';
10
- import { DevFilesAspect, DevFilesMain } from '@teambit/dev-files';
11
- import { Composition } from './composition';
12
- import { CompositionsAspect } from './compositions.aspect';
13
- import { compositionsSchema } from './compositions.graphql';
14
- import { CompositionPreviewDefinition } from './compositions.preview-definition';
15
-
16
- export type CompositionsConfig = {
17
- /**
18
- * glob pattern to detect composition files. This includes all related files, like styles and jsons.
19
- * @example ['/*.composition?(s).*']
20
- */
21
- compositionFilePattern: string[];
22
- /**
23
- * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.
24
- * @example ['*.{t,j}s', '*.{t,j}sx']
25
- */
26
- compositionPreviewFilePattern: string[];
27
- };
28
-
29
- /**
30
- * the component documentation extension.
31
- */
32
- export class CompositionsMain {
33
- constructor(
34
- /**
35
- * Glob pattern to select all composition files
36
- */
37
- private compositionFilePattern: string[],
38
-
39
- /**
40
- * Glob pattern to select composition preview files
41
- */
42
- private previewFilePattern: string[],
43
-
44
- /**
45
- * envs extension.
46
- */
47
- private preview: PreviewMain,
48
-
49
- /**
50
- * workspace extension.
51
- */
52
- private workspace: Workspace,
53
-
54
- /**
55
- * schema extension.
56
- */
57
- private schema: SchemaMain,
58
-
59
- private devFiles: DevFilesMain
60
- ) {}
61
-
62
- /**
63
- * returns an array of doc file paths for a set of components.
64
- */
65
- getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]> {
66
- return ComponentMap.as<AbstractVinyl[]>(components, (component) => {
67
- // this includes non executables, like `button.compositions.module.scss` or `presets.compositions.json`
68
- const compositionFiles = component.state.filesystem.byGlob(this.compositionFilePattern);
69
-
70
- // select only relevant preview files (.tsx, etc)
71
- const previewFiles = new Set(
72
- component.state.filesystem.byGlob(this.previewFilePattern).map((file) => file.relative)
73
- );
74
- const files = compositionFiles.filter((file) => previewFiles.has(file.relative));
75
-
76
- return files;
77
- });
78
- }
79
-
80
- /**
81
- * get component compositions.
82
- */
83
- getCompositions(component: Component): Composition[] {
84
- const entry = component.state.aspects.get(CompositionsAspect.id);
85
- if (!entry) return [];
86
- const compositions = entry.data.compositions;
87
- if (!compositions) return [];
88
-
89
- return Composition.fromArray(compositions);
90
- }
91
-
92
- /**
93
- * read composition from the component source code.
94
- */
95
- readCompositions(component: Component): Composition[] {
96
- const maybeFiles = this.getPreviewFiles([component]).byComponent(component);
97
-
98
- if (!maybeFiles) return [];
99
- const [, files] = maybeFiles;
100
- return flatten(
101
- files.map((file) => {
102
- return this.computeCompositions(component, file);
103
- })
104
- );
105
- }
106
-
107
- async onComponentLoad(component: Component): Promise<AspectData> {
108
- const compositions = this.readCompositions(component);
109
- return {
110
- compositions: compositions.map((composition) => composition.toObject()),
111
- };
112
- }
113
-
114
- private computeCompositions(component: Component, file: AbstractVinyl): Composition[] {
115
- // :TODO hacked for a specific file extension now until david will take care in the compiler.
116
- const pathArray = file.path.split('.');
117
- pathArray[pathArray.length - 1] = 'js';
118
-
119
- const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));
120
- return module.exports.map((exportModel) => {
121
- const displayName = exportModel.staticProperties?.get('compositionName');
122
-
123
- return new Composition(
124
- exportModel.identifier,
125
- file.relative,
126
- typeof displayName === 'string' ? displayName : undefined
127
- );
128
- });
129
- }
130
-
131
- static defaultConfig: CompositionsConfig = {
132
- compositionFilePattern: ['**/*.composition?(s).*'],
133
- compositionPreviewFilePattern: ['**/*.{t,j}s?(x)'],
134
- };
135
-
136
- static runtime = MainRuntime;
137
- static dependencies = [PreviewAspect, GraphqlAspect, WorkspaceAspect, SchemaAspect, DevFilesAspect, ComponentAspect];
138
-
139
- static async provider(
140
- [preview, graphql, workspace, schema, devFiles]: [PreviewMain, GraphqlMain, Workspace, SchemaMain, DevFilesMain],
141
- config: CompositionsConfig
142
- ) {
143
- const compositions = new CompositionsMain(
144
- config.compositionFilePattern,
145
- config.compositionPreviewFilePattern,
146
- preview,
147
- workspace,
148
- schema,
149
- devFiles
150
- );
151
- devFiles.registerDevPattern(config.compositionFilePattern);
152
-
153
- graphql.register(compositionsSchema(compositions));
154
- preview.registerDefinition(new CompositionPreviewDefinition(compositions));
155
-
156
- if (workspace) {
157
- workspace.onComponentLoad(compositions.onComponentLoad.bind(compositions));
158
- }
159
-
160
- return compositions;
161
- }
162
- }
163
-
164
- CompositionsAspect.addRuntime(CompositionsMain);