@teambit/code.ui.queries.get-file-content 0.0.505 → 0.0.506
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/dist/get-file-content.d.ts +2 -2
- package/dist/get-file-content.js +29 -2
- package/dist/get-file-content.js.map +1 -1
- package/dist/preview-1778686821215.js +7 -0
- package/get-file-content.ts +41 -13
- package/package.json +4 -3
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -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:
|
|
3
|
+
fileContent: any;
|
|
4
4
|
loading: boolean;
|
|
5
5
|
};
|
package/dist/get-file-content.js
CHANGED
|
@@ -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
|
|
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:
|
|
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":";;
|
|
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,IAAc,EAAE,IAAa;;IACxG,MAAM,EAAE,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,WAAW,IAAI,QAAQ,KAAK,SAAS,CAAC;IAEjE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,oDAAY,EAAa,OAAO,EAAE;QACnE,SAAS,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE;QACpD,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;IAEH,IAAA,wBAAe,EAA0B,8BAA8B,EAAE;QACvE,IAAI,EAAE,SAAS;QACf,kBAAkB,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE;;YAC3C,MAAM,SAAS,GAAG,MAAA,MAAA,MAAA,gBAAgB,CAAC,IAAI,0CAAE,gBAAgB,0CAAE,SAAS,0CAAE,EAAE,CAAC;YACzE,IAAI,CAAC,SAAS,IAAI,CAAC,WAAW;gBAAE,OAAO;YACvC,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,QAAQ;gBAAE,OAAO;YACpD,IAAI,SAAS,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,IAAI,SAAS,CAAC,KAAK,KAAK,WAAW,CAAC,KAAK;gBAAE,OAAO;YAC1F,OAAO,EAAE,CAAC;QACZ,CAAC;KACF,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"}
|
package/get-file-content.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/code.ui.queries.get-file-content",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.506",
|
|
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.
|
|
9
|
+
"version": "0.0.506"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"core-js": "^3.0.0",
|
|
13
|
-
"@teambit/
|
|
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",
|
package/types/asset.d.ts
ADDED
|
@@ -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
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -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
|
+
}
|