@teambit/code.ui.queries.get-file-content 0.0.505 → 0.0.507

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,5 +1,5 @@
1
- import { ComponentID } from '@teambit/component';
1
+ import type { ComponentID } from '@teambit/component-id';
2
2
  export declare function useFileContent(componentId?: ComponentID, filePath?: string, skip?: boolean, host?: string): {
3
- fileContent: string;
3
+ fileContent: any;
4
4
  loading: boolean;
5
5
  };
@@ -19,12 +19,39 @@ const getFile = (0, client_1.gql) `
19
19
  }
20
20
  }
21
21
  `;
22
+ const COMPONENT_CHANGED_SUBSCRIPTION = (0, client_1.gql) `
23
+ subscription OnComponentChangedForFile {
24
+ componentChanged {
25
+ component {
26
+ id {
27
+ name
28
+ scope
29
+ }
30
+ }
31
+ }
32
+ }
33
+ `;
22
34
  function useFileContent(componentId, filePath, skip, host) {
23
35
  var _a, _b;
24
36
  const id = componentId === null || componentId === void 0 ? void 0 : componentId.toString();
25
- const { data, loading } = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(getFile, {
37
+ const querySkip = skip || !componentId || filePath === undefined;
38
+ const { data, loading, refetch } = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(getFile, {
26
39
  variables: { id, path: filePath, extensionId: host },
27
- skip: skip || !componentId || filePath === undefined,
40
+ skip: querySkip,
41
+ });
42
+ (0, client_1.useSubscription)(COMPONENT_CHANGED_SUBSCRIPTION, {
43
+ skip: querySkip,
44
+ onSubscriptionData: ({ subscriptionData }) => {
45
+ var _a, _b, _c;
46
+ const changedId = (_c = (_b = (_a = subscriptionData.data) === null || _a === void 0 ? void 0 : _a.componentChanged) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.id;
47
+ if (!changedId || !componentId)
48
+ return;
49
+ if (changedId.name !== componentId.fullName)
50
+ return;
51
+ if (changedId.scope && componentId.scope && changedId.scope !== componentId.scope)
52
+ return;
53
+ refetch();
54
+ },
28
55
  });
29
56
  const fileContent = (_b = (_a = data === null || data === void 0 ? void 0 : data.getHost) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.getFile;
30
57
  return { fileContent, loading };
@@ -1 +1 @@
1
- {"version":3,"file":"get-file-content.js","sourceRoot":"","sources":["../get-file-content.ts"],"names":[],"mappings":";;AAmCA,wCAgBC;AAnDD,2CAAqC;AACrC,0GAA8E;AAG9E,MAAM,OAAO,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;;;;;CAelB,CAAC;AAgBF,SAAgB,cAAc,CAC5B,WAAyB,EACzB,QAAiB,EACjB,IAAc,EACd,IAAa;;IAEb,MAAM,EAAE,GAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,EAAE,CAAC;IAEpC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAA,oDAAY,EAAa,OAAO,EAAE;QAC1D,SAAS,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAG;QACrD,IAAI,EAAE,IAAI,IAAI,CAAC,WAAW,IAAI,QAAQ,KAAK,SAAS;KACrD,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,0CAAE,GAAG,0CAAE,OAAO,CAAC;IAEhD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"get-file-content.js","sourceRoot":"","sources":["../get-file-content.ts"],"names":[],"mappings":";;AAwDA,wCAuBC;AA/ED,2CAAsD;AACtD,0GAA8E;AAG9E,MAAM,OAAO,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;;;;;CAelB,CAAC;AAEF,MAAM,8BAA8B,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;CAWzC,CAAC;AAwBF,SAAgB,cAAc,CAAC,WAAyB,EAAE,QAAiB,EAAE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1
- import { gql } from '@apollo/client';
1
+ import { gql, useSubscription } from '@apollo/client';
2
2
  import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
3
- import { ComponentID } from '@teambit/component';
3
+ import type { ComponentID } from '@teambit/component-id';
4
4
 
5
5
  const getFile = gql`
6
6
  query getFile($id: String!, $extensionId: String, $path: String) {
@@ -19,6 +19,19 @@ const getFile = gql`
19
19
  }
20
20
  `;
21
21
 
22
+ const COMPONENT_CHANGED_SUBSCRIPTION = gql`
23
+ subscription OnComponentChangedForFile {
24
+ componentChanged {
25
+ component {
26
+ id {
27
+ name
28
+ scope
29
+ }
30
+ }
31
+ }
32
+ }
33
+ `;
34
+
22
35
  type FileResult = {
23
36
  getHost: {
24
37
  id: string;
@@ -33,17 +46,32 @@ type FileResult = {
33
46
  };
34
47
  };
35
48
 
36
- export function useFileContent(
37
- componentId?: ComponentID,
38
- filePath?: string,
39
- skip?: boolean,
40
- host?: string,
41
- ) {
42
- const id = componentId?.toString();
43
-
44
- const { data, loading } = useDataQuery<FileResult>(getFile, {
45
- variables: { id, path: filePath, extensionId: host },
46
- skip: skip || !componentId || filePath === undefined,
49
+ type ComponentChangedSubData = {
50
+ componentChanged?: {
51
+ component?: {
52
+ id: { name: string; scope: string };
53
+ };
54
+ };
55
+ };
56
+
57
+ export function useFileContent(componentId?: ComponentID, filePath?: string, skip?: boolean, host?: string) {
58
+ const id = componentId?.toString();
59
+ const querySkip = skip || !componentId || filePath === undefined;
60
+
61
+ const { data, loading, refetch } = useDataQuery<FileResult>(getFile, {
62
+ variables: { id, path: filePath, extensionId: host },
63
+ skip: querySkip,
64
+ });
65
+
66
+ useSubscription<ComponentChangedSubData>(COMPONENT_CHANGED_SUBSCRIPTION, {
67
+ skip: querySkip,
68
+ onSubscriptionData: ({ subscriptionData }) => {
69
+ const changedId = subscriptionData.data?.componentChanged?.component?.id;
70
+ if (!changedId || !componentId) return;
71
+ if (changedId.name !== componentId.fullName) return;
72
+ if (changedId.scope && componentId.scope && changedId.scope !== componentId.scope) return;
73
+ refetch();
74
+ },
47
75
  });
48
76
 
49
77
  const fileContent = data?.getHost?.get?.getFile;
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
1
  {
2
2
  "name": "@teambit/code.ui.queries.get-file-content",
3
- "version": "0.0.505",
3
+ "version": "0.0.507",
4
4
  "homepage": "https://bit.cloud/teambit/code/ui/queries/get-file-content",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.code",
8
8
  "name": "ui/queries/get-file-content",
9
- "version": "0.0.505"
9
+ "version": "0.0.507"
10
10
  },
11
11
  "dependencies": {
12
12
  "core-js": "^3.0.0",
13
- "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.500"
13
+ "@teambit/component-id": "1.2.4",
14
+ "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.506"
14
15
  },
15
16
  "devDependencies": {
16
17
  "@types/mocha": "9.1.0",
17
18
  "@types/node": "12.20.4",
18
- "@types/react": "^17.0.8",
19
- "@types/react-dom": "^17.0.5",
19
+ "@types/react": "^19.0.0",
20
+ "@types/react-dom": "^19.0.0",
20
21
  "@types/jest": "^26.0.0",
21
22
  "@babel/runtime": "7.20.0",
22
23
  "@types/testing-library__jest-dom": "5.9.5"
23
24
  },
24
25
  "peerDependencies": {
25
- "@apollo/client": "^3.6.0",
26
- "react": "^16.8.0 || ^17.0.0",
27
- "react-dom": "^16.8.0 || ^17.0.0"
26
+ "@apollo/client": "^3.12.0",
27
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
28
+ "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
28
29
  },
29
30
  "license": "Apache-2.0",
30
31
  "optionalDependencies": {},
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }