@teambit/compositions 0.0.728 → 0.0.731

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.
@@ -1,10 +1,10 @@
1
- import { Component, ComponentMap, AspectData } from '@teambit/component';
1
+ import { AspectData, Component, ComponentMap } from '@teambit/component';
2
+ import { DevFilesMain } from '@teambit/dev-files';
2
3
  import { GraphqlMain } from '@teambit/graphql';
4
+ import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
3
5
  import { PreviewMain } from '@teambit/preview';
4
6
  import { SchemaMain } from '@teambit/schema';
5
7
  import { Workspace } from '@teambit/workspace';
6
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
7
- import { DevFilesMain } from '@teambit/dev-files';
8
8
  import { Composition } from './composition';
9
9
  export declare type CompositionsConfig = {
10
10
  /**
@@ -68,6 +68,10 @@ export declare class CompositionsMain {
68
68
  * returns an array of doc file paths for a set of components.
69
69
  */
70
70
  getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]>;
71
+ /**
72
+ * checks if a file matches the composition file pattern.
73
+ */
74
+ isCompositionFile(filePath: string): boolean;
71
75
  /**
72
76
  * get component compositions.
73
77
  */
@@ -23,30 +23,30 @@ function _defineProperty2() {
23
23
  return data;
24
24
  }
25
25
 
26
- function _path() {
27
- const data = require("path");
26
+ function _cli() {
27
+ const data = require("@teambit/cli");
28
28
 
29
- _path = function () {
29
+ _cli = function () {
30
30
  return data;
31
31
  };
32
32
 
33
33
  return data;
34
34
  }
35
35
 
36
- function _cli() {
37
- const data = require("@teambit/cli");
36
+ function _component() {
37
+ const data = require("@teambit/component");
38
38
 
39
- _cli = function () {
39
+ _component = function () {
40
40
  return data;
41
41
  };
42
42
 
43
43
  return data;
44
44
  }
45
45
 
46
- function _component() {
47
- const data = require("@teambit/component");
46
+ function _devFiles() {
47
+ const data = require("@teambit/dev-files");
48
48
 
49
- _component = function () {
49
+ _devFiles = function () {
50
50
  return data;
51
51
  };
52
52
 
@@ -63,6 +63,16 @@ function _graphql() {
63
63
  return data;
64
64
  }
65
65
 
66
+ function _utils() {
67
+ const data = require("@teambit/legacy/dist/utils");
68
+
69
+ _utils = function () {
70
+ return data;
71
+ };
72
+
73
+ return data;
74
+ }
75
+
66
76
  function _preview() {
67
77
  const data = require("@teambit/preview");
68
78
 
@@ -83,30 +93,30 @@ function _schema() {
83
93
  return data;
84
94
  }
85
95
 
86
- function _workspace() {
87
- const data = require("@teambit/workspace");
96
+ function _toolboxPath() {
97
+ const data = require("@teambit/toolbox.path.match-patterns");
88
98
 
89
- _workspace = function () {
99
+ _toolboxPath = function () {
90
100
  return data;
91
101
  };
92
102
 
93
103
  return data;
94
104
  }
95
105
 
96
- function _utils() {
97
- const data = require("@teambit/legacy/dist/utils");
106
+ function _workspace() {
107
+ const data = require("@teambit/workspace");
98
108
 
99
- _utils = function () {
109
+ _workspace = function () {
100
110
  return data;
101
111
  };
102
112
 
103
113
  return data;
104
114
  }
105
115
 
106
- function _devFiles() {
107
- const data = require("@teambit/dev-files");
116
+ function _path() {
117
+ const data = require("path");
108
118
 
109
- _devFiles = function () {
119
+ _path = function () {
110
120
  return data;
111
121
  };
112
122
 
@@ -200,6 +210,18 @@ class CompositionsMain {
200
210
  return files;
201
211
  });
202
212
  }
213
+ /**
214
+ * checks if a file matches the composition file pattern.
215
+ */
216
+
217
+
218
+ isCompositionFile(filePath) {
219
+ const {
220
+ includePatterns,
221
+ excludePatterns
222
+ } = (0, _toolboxPath().splitPatterns)(this.compositionFilePattern);
223
+ return (0, _toolboxPath().matchPatterns)(filePath, includePatterns, excludePatterns);
224
+ }
203
225
  /**
204
226
  * get component compositions.
205
227
  */
@@ -238,7 +260,8 @@ class CompositionsMain {
238
260
  const pathArray = file.path.split('.');
239
261
  pathArray[pathArray.length - 1] = 'js';
240
262
  const module = this.schema.parseModule((0, _path().join)(this.workspace.componentDir(component.id), file.relative));
241
- return module.exports.map(exportModel => {
263
+ const exports = module.getExportSchemas();
264
+ return exports.map(exportModel => {
242
265
  var _exportModel$staticPr;
243
266
 
244
267
  const displayName = (_exportModel$staticPr = exportModel.staticProperties) === null || _exportModel$staticPr === void 0 ? void 0 : _exportModel$staticPr.get('compositionName');
@@ -1 +1 @@
1
- {"version":3,"sources":["compositions.main.runtime.ts"],"names":["CompositionsMain","constructor","compositionFilePattern","previewFilePattern","preview","workspace","schema","devFiles","getPreviewFiles","components","ComponentMap","as","component","compositionFiles","state","filesystem","byGlob","previewFiles","Set","map","file","relative","files","filter","has","getCompositions","entry","aspects","get","CompositionsAspect","id","compositions","data","Composition","fromArray","readCompositions","maybeFiles","byComponent","computeCompositions","onComponentLoad","composition","toObject","pathArray","path","split","length","module","parseModule","componentDir","exports","exportModel","displayName","staticProperties","identifier","undefined","provider","graphql","config","compositionPreviewFilePattern","registerDevPattern","register","registerDefinition","CompositionPreviewDefinition","bind","MainRuntime","PreviewAspect","GraphqlAspect","WorkspaceAspect","SchemaAspect","DevFilesAspect","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AA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xGNhE,gB,kBAyGW,CAACiE,wBAAD,EAAgBC,wBAAhB,EAA+BC,4BAA/B,EAAgDC,sBAAhD,EAA8DC,0BAA9D,EAA8EC,4BAA9E,C;;AA6BxBzC,mCAAmB0C,UAAnB,CAA8BvE,gBAA9B","sourcesContent":["import { join } from 'path';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect, ComponentMap, AspectData } from '@teambit/component';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { PreviewAspect, PreviewMain } from '@teambit/preview';\nimport { SchemaAspect, SchemaMain } from '@teambit/schema';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from '@teambit/legacy/dist/utils';\nimport { DevFilesAspect, DevFilesMain } from '@teambit/dev-files';\nimport { Composition } from './composition';\nimport { CompositionsAspect } from './compositions.aspect';\nimport { compositionsSchema } from './compositions.graphql';\nimport { CompositionPreviewDefinition } from './compositions.preview-definition';\n\nexport type CompositionsConfig = {\n /**\n * glob pattern to detect composition files. This includes all related files, like styles and jsons.\n * @example ['/*.composition?(s).*']\n */\n compositionFilePattern: string[];\n /**\n * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.\n * @example ['*.{t,j}s', '*.{t,j}sx']\n */\n compositionPreviewFilePattern: string[];\n};\n\n/**\n * the component documentation extension.\n */\nexport class CompositionsMain {\n constructor(\n /**\n * Glob pattern to select all composition files\n */\n private compositionFilePattern: string[],\n\n /**\n * Glob pattern to select composition preview files\n */\n private previewFilePattern: string[],\n\n /**\n * envs extension.\n */\n private preview: PreviewMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * schema extension.\n */\n private schema: SchemaMain,\n\n private devFiles: DevFilesMain\n ) {}\n\n /**\n * returns an array of doc file paths for a set of components.\n */\n getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]> {\n return ComponentMap.as<AbstractVinyl[]>(components, (component) => {\n // this includes non executables, like `button.compositions.module.scss` or `presets.compositions.json`\n const compositionFiles = component.state.filesystem.byGlob(this.compositionFilePattern);\n\n // select only relevant preview files (.tsx, etc)\n const previewFiles = new Set(\n component.state.filesystem.byGlob(this.previewFilePattern).map((file) => file.relative)\n );\n const files = compositionFiles.filter((file) => previewFiles.has(file.relative));\n\n return files;\n });\n }\n\n /**\n * get component compositions.\n */\n getCompositions(component: Component): Composition[] {\n const entry = component.state.aspects.get(CompositionsAspect.id);\n if (!entry) return [];\n const compositions = entry.data.compositions;\n if (!compositions) return [];\n\n return Composition.fromArray(compositions);\n }\n\n /**\n * read composition from the component source code.\n */\n readCompositions(component: Component): Composition[] {\n const maybeFiles = this.getPreviewFiles([component]).byComponent(component);\n\n if (!maybeFiles) return [];\n const [, files] = maybeFiles;\n return flatten(\n files.map((file) => {\n return this.computeCompositions(component, file);\n })\n );\n }\n\n async onComponentLoad(component: Component): Promise<AspectData> {\n const compositions = this.readCompositions(component);\n return {\n compositions: compositions.map((composition) => composition.toObject()),\n };\n }\n\n private computeCompositions(component: Component, file: AbstractVinyl): Composition[] {\n // :TODO hacked for a specific file extension now until david will take care in the compiler.\n const pathArray = file.path.split('.');\n pathArray[pathArray.length - 1] = 'js';\n\n const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));\n return module.exports.map((exportModel) => {\n const displayName = exportModel.staticProperties?.get('compositionName');\n\n return new Composition(\n exportModel.identifier,\n file.relative,\n typeof displayName === 'string' ? displayName : undefined\n );\n });\n }\n\n static defaultConfig: CompositionsConfig = {\n compositionFilePattern: ['**/*.composition?(s).*'],\n compositionPreviewFilePattern: ['**/*.{t,j}s?(x)'],\n };\n\n static runtime = MainRuntime;\n static dependencies = [PreviewAspect, GraphqlAspect, WorkspaceAspect, SchemaAspect, DevFilesAspect, ComponentAspect];\n\n static async provider(\n [preview, graphql, workspace, schema, devFiles]: [PreviewMain, GraphqlMain, Workspace, SchemaMain, DevFilesMain],\n config: CompositionsConfig\n ) {\n const compositions = new CompositionsMain(\n config.compositionFilePattern,\n config.compositionPreviewFilePattern,\n preview,\n workspace,\n schema,\n devFiles\n );\n\n // TODO: use the docs implementation to allow component specific pattern\n devFiles.registerDevPattern(config.compositionFilePattern);\n\n graphql.register(compositionsSchema(compositions));\n preview.registerDefinition(new CompositionPreviewDefinition(compositions));\n\n if (workspace) {\n workspace.onComponentLoad(compositions.onComponentLoad.bind(compositions));\n }\n\n return compositions;\n }\n}\n\nCompositionsAspect.addRuntime(CompositionsMain);\n"]}
1
+ {"version":3,"sources":["compositions.main.runtime.ts"],"names":["CompositionsMain","constructor","compositionFilePattern","previewFilePattern","preview","workspace","schema","devFiles","getPreviewFiles","components","ComponentMap","as","component","compositionFiles","state","filesystem","byGlob","previewFiles","Set","map","file","relative","files","filter","has","isCompositionFile","filePath","includePatterns","excludePatterns","getCompositions","entry","aspects","get","CompositionsAspect","id","compositions","data","Composition","fromArray","readCompositions","maybeFiles","byComponent","computeCompositions","onComponentLoad","composition","toObject","pathArray","path","split","length","module","parseModule","componentDir","exports","getExportSchemas","exportModel","displayName","staticProperties","identifier","undefined","provider","graphql","config","compositionPreviewFilePattern","registerDevPattern","register","registerDefinition","CompositionPreviewDefinition","bind","MainRuntime","PreviewAspect","GraphqlAspect","WorkspaceAspect","SchemaAspect","DevFilesAspect","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAC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ACyD,kBAAT,CAA4BF,MAAM,CAAC5D,sBAAnC;AAEA2D,IAAAA,OAAO,CAACI,QAAR,CAAiB,yCAAmB9B,YAAnB,CAAjB;AACA/B,IAAAA,OAAO,CAAC8D,kBAAR,CAA2B,KAAIC,6CAAJ,EAAiChC,YAAjC,CAA3B;;AAEA,QAAI9B,SAAJ,EAAe;AACbA,MAAAA,SAAS,CAACsC,eAAV,CAA0BR,YAAY,CAACQ,eAAb,CAA6ByB,IAA7B,CAAkCjC,YAAlC,CAA1B;AACD;;AAED,WAAOA,YAAP;AACD;;AA5I2B;;;gCAAjBnC,gB,mBA4GgC;AACzCE,EAAAA,sBAAsB,EAAE,CAAC,wBAAD,CADiB;AAEzC6D,EAAAA,6BAA6B,EAAE,CAAC,iBAAD;AAFU,C;gCA5GhC/D,gB,aAiHMqE,kB;gCAjHNrE,gB,kBAkHW,CAACsE,wBAAD,EAAgBC,wBAAhB,EAA+BC,4BAA/B,EAAgDC,sBAAhD,EAA8DC,0BAA9D,EAA8EC,4BAA9E,C;;AA6BxB1C,mCAAmB2C,UAAnB,CAA8B5E,gBAA9B","sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { AspectData, Component, ComponentAspect, ComponentMap } from '@teambit/component';\nimport { DevFilesAspect, DevFilesMain } from '@teambit/dev-files';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from '@teambit/legacy/dist/utils';\nimport { PreviewAspect, PreviewMain } from '@teambit/preview';\nimport { SchemaAspect, SchemaMain } from '@teambit/schema';\nimport { matchPatterns, splitPatterns } from '@teambit/toolbox.path.match-patterns';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { join } from 'path';\nimport { Composition } from './composition';\nimport { CompositionsAspect } from './compositions.aspect';\nimport { compositionsSchema } from './compositions.graphql';\nimport { CompositionPreviewDefinition } from './compositions.preview-definition';\n\nexport type CompositionsConfig = {\n /**\n * glob pattern to detect composition files. This includes all related files, like styles and jsons.\n * @example ['/*.composition?(s).*']\n */\n compositionFilePattern: string[];\n /**\n * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.\n * @example ['*.{t,j}s', '*.{t,j}sx']\n */\n compositionPreviewFilePattern: string[];\n};\n\n/**\n * the component documentation extension.\n */\nexport class CompositionsMain {\n constructor(\n /**\n * Glob pattern to select all composition files\n */\n private compositionFilePattern: string[],\n\n /**\n * Glob pattern to select composition preview files\n */\n private previewFilePattern: string[],\n\n /**\n * envs extension.\n */\n private preview: PreviewMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * schema extension.\n */\n private schema: SchemaMain,\n\n private devFiles: DevFilesMain\n ) {}\n\n /**\n * returns an array of doc file paths for a set of components.\n */\n getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]> {\n return ComponentMap.as<AbstractVinyl[]>(components, (component) => {\n // this includes non executables, like `button.compositions.module.scss` or `presets.compositions.json`\n const compositionFiles = component.state.filesystem.byGlob(this.compositionFilePattern);\n\n // select only relevant preview files (.tsx, etc)\n const previewFiles = new Set(\n component.state.filesystem.byGlob(this.previewFilePattern).map((file) => file.relative)\n );\n const files = compositionFiles.filter((file) => previewFiles.has(file.relative));\n\n return files;\n });\n }\n\n /**\n * checks if a file matches the composition file pattern.\n */\n isCompositionFile(filePath: string): boolean {\n const { includePatterns, excludePatterns } = splitPatterns(this.compositionFilePattern);\n return matchPatterns(filePath, includePatterns, excludePatterns);\n }\n\n /**\n * get component compositions.\n */\n getCompositions(component: Component): Composition[] {\n const entry = component.state.aspects.get(CompositionsAspect.id);\n if (!entry) return [];\n const compositions = entry.data.compositions;\n if (!compositions) return [];\n\n return Composition.fromArray(compositions);\n }\n\n /**\n * read composition from the component source code.\n */\n readCompositions(component: Component): Composition[] {\n const maybeFiles = this.getPreviewFiles([component]).byComponent(component);\n\n if (!maybeFiles) return [];\n const [, files] = maybeFiles;\n return flatten(\n files.map((file) => {\n return this.computeCompositions(component, file);\n })\n );\n }\n\n async onComponentLoad(component: Component): Promise<AspectData> {\n const compositions = this.readCompositions(component);\n return {\n compositions: compositions.map((composition) => composition.toObject()),\n };\n }\n\n private computeCompositions(component: Component, file: AbstractVinyl): Composition[] {\n // :TODO hacked for a specific file extension now until david will take care in the compiler.\n const pathArray = file.path.split('.');\n pathArray[pathArray.length - 1] = 'js';\n\n const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));\n const exports = module.getExportSchemas();\n return exports.map((exportModel) => {\n const displayName = exportModel.staticProperties?.get('compositionName');\n\n return new Composition(\n exportModel.identifier,\n file.relative,\n typeof displayName === 'string' ? displayName : undefined\n );\n });\n }\n\n static defaultConfig: CompositionsConfig = {\n compositionFilePattern: ['**/*.composition?(s).*'],\n compositionPreviewFilePattern: ['**/*.{t,j}s?(x)'],\n };\n\n static runtime = MainRuntime;\n static dependencies = [PreviewAspect, GraphqlAspect, WorkspaceAspect, SchemaAspect, DevFilesAspect, ComponentAspect];\n\n static async provider(\n [preview, graphql, workspace, schema, devFiles]: [PreviewMain, GraphqlMain, Workspace, SchemaMain, DevFilesMain],\n config: CompositionsConfig\n ) {\n const compositions = new CompositionsMain(\n config.compositionFilePattern,\n config.compositionPreviewFilePattern,\n preview,\n workspace,\n schema,\n devFiles\n );\n\n // TODO: use the docs implementation to allow component specific pattern\n devFiles.registerDevPattern(config.compositionFilePattern);\n\n graphql.register(compositionsSchema(compositions));\n preview.registerDefinition(new CompositionPreviewDefinition(compositions));\n\n if (workspace) {\n workspace.onComponentLoad(compositions.onComponentLoad.bind(compositions));\n }\n\n return compositions;\n }\n}\n\nCompositionsAspect.addRuntime(CompositionsMain);\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compositions",
3
- "version": "0.0.728",
3
+ "version": "0.0.731",
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.728"
9
+ "version": "0.0.731"
10
10
  },
11
11
  "dependencies": {
12
12
  "graphql-tag": "2.12.1",
@@ -24,16 +24,17 @@
24
24
  "@teambit/documenter.ui.heading": "4.1.1",
25
25
  "@teambit/documenter.ui.property-table": "4.1.3",
26
26
  "@teambit/evangelist.elements.icon": "1.0.2",
27
- "@teambit/component": "0.0.728",
27
+ "@teambit/component": "0.0.731",
28
28
  "@teambit/compositions.model.composition-id": "0.0.487",
29
- "@teambit/graphql": "0.0.728",
30
- "@teambit/cli": "0.0.486",
31
- "@teambit/dev-files": "0.0.728",
32
- "@teambit/preview": "0.0.728",
33
- "@teambit/schema": "0.0.728",
34
- "@teambit/workspace": "0.0.728",
29
+ "@teambit/graphql": "0.0.731",
30
+ "@teambit/cli": "0.0.488",
31
+ "@teambit/dev-files": "0.0.731",
32
+ "@teambit/preview": "0.0.731",
33
+ "@teambit/schema": "0.0.731",
34
+ "@teambit/toolbox.path.match-patterns": "0.0.1",
35
+ "@teambit/workspace": "0.0.731",
35
36
  "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.487",
36
- "@teambit/envs": "0.0.728",
37
+ "@teambit/envs": "0.0.731",
37
38
  "@teambit/component-id": "0.0.402",
38
39
  "@teambit/compositions.ui.compositions-menu-bar": "0.0.163",
39
40
  "@teambit/compositions.ui.hooks.use-composition": "0.0.163",
@@ -43,11 +44,11 @@
43
44
  "@teambit/design.ui.surfaces.status-message-card": "0.0.7",
44
45
  "@teambit/docs.ui.queries.get-docs": "0.0.487",
45
46
  "@teambit/mdx.ui.mdx-layout": "0.0.499",
46
- "@teambit/panels": "0.0.487",
47
+ "@teambit/panels": "0.0.489",
47
48
  "@teambit/preview.ui.component-preview": "0.0.493",
48
49
  "@teambit/ui-foundation.ui.buttons.collapser": "0.0.194",
49
50
  "@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.179",
50
- "@teambit/ui": "0.0.728",
51
+ "@teambit/ui": "0.0.731",
51
52
  "@teambit/compositions.model.composition-type": "0.0.488",
52
53
  "@teambit/compositions.ui.composition-card": "0.0.495"
53
54
  },
@@ -63,7 +64,7 @@
63
64
  "@teambit/compositions.aspect-docs.compositions": "0.0.137"
64
65
  },
65
66
  "peerDependencies": {
66
- "@teambit/legacy": "1.0.265",
67
+ "@teambit/legacy": "1.0.268",
67
68
  "react-dom": "^16.8.0 || ^17.0.0",
68
69
  "react": "^16.8.0 || ^17.0.0"
69
70
  },
@@ -91,7 +92,7 @@
91
92
  "react": "-"
92
93
  },
93
94
  "peerDependencies": {
94
- "@teambit/legacy": "1.0.265",
95
+ "@teambit/legacy": "1.0.268",
95
96
  "react-dom": "^16.8.0 || ^17.0.0",
96
97
  "react": "^16.8.0 || ^17.0.0"
97
98
  }
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compositions_compositions@0.0.728/dist/compositions.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compositions_compositions@0.0.728/dist/compositions.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compositions_compositions@0.0.731/dist/compositions.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compositions_compositions@0.0.731/dist/compositions.docs.mdx')]