@teambit/code.ui.queries.get-file-content 0.0.0-aa88b68bd3186f455aefd3fe93c1a8f27e335f92
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 +5 -0
- package/dist/get-file-content.js +59 -0
- package/dist/get-file-content.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1778684266089.js +7 -0
- package/get-file-content.ts +80 -0
- package/index.ts +1 -0
- package/package.json +51 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFileContent = useFileContent;
|
|
4
|
+
const client_1 = require("@apollo/client");
|
|
5
|
+
const ui_foundation_ui_hooks_use_data_query_1 = require("@teambit/ui-foundation.ui.hooks.use-data-query");
|
|
6
|
+
const getFile = (0, client_1.gql) `
|
|
7
|
+
query getFile($id: String!, $extensionId: String, $path: String) {
|
|
8
|
+
getHost(id: $extensionId) {
|
|
9
|
+
id # used for GQL caching
|
|
10
|
+
get(id: $id) {
|
|
11
|
+
id {
|
|
12
|
+
# used for GQL caching
|
|
13
|
+
name
|
|
14
|
+
version
|
|
15
|
+
scope
|
|
16
|
+
}
|
|
17
|
+
getFile(path: $path)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
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
|
+
`;
|
|
34
|
+
function useFileContent(componentId, filePath, skip, host) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const id = componentId === null || componentId === void 0 ? void 0 : componentId.toString();
|
|
37
|
+
const querySkip = skip || !componentId || filePath === undefined;
|
|
38
|
+
const { data, loading, refetch } = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(getFile, {
|
|
39
|
+
variables: { id, path: filePath, extensionId: host },
|
|
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
|
+
},
|
|
55
|
+
});
|
|
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;
|
|
57
|
+
return { fileContent, loading };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=get-file-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,S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/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFileContent = void 0;
|
|
4
|
+
var get_file_content_1 = require("./get-file-content");
|
|
5
|
+
Object.defineProperty(exports, "useFileContent", { enumerable: true, get: function () { return get_file_content_1.useFileContent; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAA3C,kHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { gql, useSubscription } from '@apollo/client';
|
|
2
|
+
import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
|
|
3
|
+
import type { ComponentID } from '@teambit/component-id';
|
|
4
|
+
|
|
5
|
+
const getFile = gql`
|
|
6
|
+
query getFile($id: String!, $extensionId: String, $path: String) {
|
|
7
|
+
getHost(id: $extensionId) {
|
|
8
|
+
id # used for GQL caching
|
|
9
|
+
get(id: $id) {
|
|
10
|
+
id {
|
|
11
|
+
# used for GQL caching
|
|
12
|
+
name
|
|
13
|
+
version
|
|
14
|
+
scope
|
|
15
|
+
}
|
|
16
|
+
getFile(path: $path)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
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
|
+
|
|
35
|
+
type FileResult = {
|
|
36
|
+
getHost: {
|
|
37
|
+
id: string;
|
|
38
|
+
get: {
|
|
39
|
+
id: {
|
|
40
|
+
name: string;
|
|
41
|
+
version: string;
|
|
42
|
+
scope: string;
|
|
43
|
+
};
|
|
44
|
+
getFile?: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
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
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const fileContent = data?.getHost?.get?.getFile;
|
|
78
|
+
|
|
79
|
+
return { fileContent, loading };
|
|
80
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFileContent } from './get-file-content';
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/code.ui.queries.get-file-content",
|
|
3
|
+
"version": "0.0.0-aa88b68bd3186f455aefd3fe93c1a8f27e335f92",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/code/ui/queries/get-file-content",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "teambit.code",
|
|
8
|
+
"name": "ui/queries/get-file-content",
|
|
9
|
+
"version": "aa88b68bd3186f455aefd3fe93c1a8f27e335f92"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"core-js": "^3.0.0",
|
|
13
|
+
"@teambit/component-id": "1.2.4",
|
|
14
|
+
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.506"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/mocha": "9.1.0",
|
|
18
|
+
"@types/node": "12.20.4",
|
|
19
|
+
"@types/react": "^17.0.8",
|
|
20
|
+
"@types/react-dom": "^17.0.5",
|
|
21
|
+
"@types/jest": "^26.0.0",
|
|
22
|
+
"@babel/runtime": "7.20.0",
|
|
23
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@apollo/client": "^3.6.0",
|
|
27
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
28
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"optionalDependencies": {},
|
|
32
|
+
"peerDependenciesMeta": {},
|
|
33
|
+
"private": false,
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=12.22.0"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/teambit/bit"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"bit",
|
|
43
|
+
"components",
|
|
44
|
+
"collaboration",
|
|
45
|
+
"web",
|
|
46
|
+
"react",
|
|
47
|
+
"react-components",
|
|
48
|
+
"angular",
|
|
49
|
+
"angular-components"
|
|
50
|
+
]
|
|
51
|
+
}
|
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
|
+
}
|