@24i/bigscreen-sdk 1.0.25 → 1.0.26-alpha.2447
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/package.json +1 -1
- package/packages/create-package/dist/createPackage.js +66 -0
- package/packages/create-package/dist/createPackage.js.map +1 -0
- package/packages/create-package/dist/index.js +5 -0
- package/packages/create-package/dist/index.js.map +1 -0
- package/packages/create-package/dist/questionnaire/questions.js +35 -0
- package/packages/create-package/dist/questionnaire/questions.js.map +1 -0
- package/packages/create-package/dist/settings/Settings.js +10 -0
- package/packages/create-package/dist/settings/Settings.js.map +1 -0
- package/packages/create-package/dist/types.js +3 -0
- package/packages/create-package/dist/types.js.map +1 -0
- package/packages/focus/README.md +17 -0
- package/packages/focus/src/IFocusable.ts +1 -0
- package/packages/focus/src/hasFocus.ts +36 -0
- package/packages/focus/src/index.ts +1 -0
- package/packages/sdk-installer/dist/index.js +5 -0
- package/packages/sdk-installer/dist/sdkInstaller.js +38 -0
- package/packages/sdk-installer/dist/services/clean.js +11 -0
- package/packages/sdk-installer/dist/services/download.js +55 -0
- package/packages/sdk-installer/dist/services/index.js +11 -0
- package/packages/sdk-installer/dist/services/install.js +24 -0
- package/packages/sdk-installer/dist/services/unzip.js +12 -0
- package/packages/sdk-installer/dist/types/index.d.ts +1 -0
- package/packages/sdk-installer/dist/types/sdkInstaller.d.ts +7 -0
- package/packages/sdk-installer/dist/types/services/clean.d.ts +2 -0
- package/packages/sdk-installer/dist/types/services/download.d.ts +2 -0
- package/packages/sdk-installer/dist/types/services/index.d.ts +4 -0
- package/packages/sdk-installer/dist/types/services/install.d.ts +2 -0
- package/packages/sdk-installer/dist/types/services/unzip.d.ts +2 -0
- package/packages/utils/README.md +4 -0
- package/packages/utils/src/elementUtils.ts +25 -0
- package/packages/utils/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.main = void 0;
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const fse = require("fs-extra");
|
|
8
|
+
const chalk = require("chalk");
|
|
9
|
+
const minimist = require("minimist");
|
|
10
|
+
const questions_1 = require("./questionnaire/questions");
|
|
11
|
+
const Settings_1 = require("./settings/Settings");
|
|
12
|
+
async function isDirectoryEmpty(dirPath) {
|
|
13
|
+
const files = await fs.promises.readdir(dirPath);
|
|
14
|
+
return !files.length;
|
|
15
|
+
}
|
|
16
|
+
async function copyTemplateFiles(templateDir, targetDir) {
|
|
17
|
+
return fse.copy(templateDir, targetDir);
|
|
18
|
+
}
|
|
19
|
+
function updatePackageJsonFile(filePath, options) {
|
|
20
|
+
let data = fs.readFileSync(filePath, 'utf8');
|
|
21
|
+
const keywords = options.keywords.map((word) => `"${word}"`).join(', ');
|
|
22
|
+
data = data.replace(/("name": ")(.*)(")/, `$1${options.name}$3`);
|
|
23
|
+
data = data.replace(/("version": ")(.*)(")/, `$1${options.version}$3`);
|
|
24
|
+
data = data.replace(/("description": ")(.*)(")/, `$1${options.description}$3`);
|
|
25
|
+
data = data.replace(/("keywords": \[)(.*)(\])/, `$1${keywords}$3`);
|
|
26
|
+
data = data.replace(/("author": ")(.*)(")/, `$1${options.author}$3`);
|
|
27
|
+
fs.writeFileSync(filePath, data);
|
|
28
|
+
}
|
|
29
|
+
function parseArguments(rawArgv) {
|
|
30
|
+
const argv = minimist(rawArgv.slice(2));
|
|
31
|
+
const dirName = argv._[0];
|
|
32
|
+
if (!dirName) {
|
|
33
|
+
console.error('Error: Missing package name');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
dirName,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function main() {
|
|
41
|
+
const { dirName: destDirName } = parseArguments(process.argv);
|
|
42
|
+
const destDir = path.join(process.cwd(), 'packages/', destDirName);
|
|
43
|
+
if (fs.existsSync(destDir)) {
|
|
44
|
+
console.error(`Error: Target directory "${destDir}" already exists`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
48
|
+
const isDirEmpty = await isDirectoryEmpty(destDir);
|
|
49
|
+
if (!isDirEmpty) {
|
|
50
|
+
console.error(`Error: Target directory "${destDir}" is not empty.`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const settings = Object.assign({}, Settings_1.Settings);
|
|
54
|
+
settings.name = `${Settings_1.Settings.name}${destDirName}`.toLowerCase();
|
|
55
|
+
const details = await (0, questions_1.promptPackageDetails)(settings);
|
|
56
|
+
const templateDir = path.join(__dirname, '..', 'templates/typescript');
|
|
57
|
+
await copyTemplateFiles(templateDir, destDir);
|
|
58
|
+
const packageJsonFile = path.join(destDir, 'package.json');
|
|
59
|
+
updatePackageJsonFile(packageJsonFile, details);
|
|
60
|
+
const docsSymlinkTarget = path.join('../../../packages/', destDirName, '/README.md');
|
|
61
|
+
const docsSymlinkPath = path.join(process.cwd(), 'docs/packages/', destDirName, '/README.md');
|
|
62
|
+
await fse.ensureSymlink(docsSymlinkTarget, docsSymlinkPath);
|
|
63
|
+
console.log(`${chalk.green('Success')}, package has been initialized!`);
|
|
64
|
+
}
|
|
65
|
+
exports.main = main;
|
|
66
|
+
//# sourceMappingURL=createPackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPackage.js","sourceRoot":"","sources":["../src/createPackage.ts"],"names":[],"mappings":";;;;AAEA,6BAA6B;AAC7B,yBAAyB;AACzB,gCAAgC;AAChC,+BAA+B;AAC/B,qCAAqC;AACrC,yDAAiE;AACjE,kDAA+C;AAG/C,KAAK,UAAU,gBAAgB,CAAC,OAAe;IAC3C,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAA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,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAC3D,qBAAqB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAGhD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IACrF,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAC9F,MAAM,GAAG,CAAC,aAAa,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAAC;AAC5E,CAAC;AA/BD,oBA+BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,mDAAuC;AAEvC,IAAA,oBAAI,GAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptPackageDetails = void 0;
|
|
4
|
+
const inquirer = require("inquirer");
|
|
5
|
+
async function promptPackageDetails(defaultValues) {
|
|
6
|
+
return inquirer.prompt([
|
|
7
|
+
{
|
|
8
|
+
type: 'input',
|
|
9
|
+
name: 'name',
|
|
10
|
+
message: 'Package name:',
|
|
11
|
+
default: defaultValues.name,
|
|
12
|
+
}, {
|
|
13
|
+
type: 'input',
|
|
14
|
+
name: 'version',
|
|
15
|
+
message: 'Version:',
|
|
16
|
+
default: defaultValues.version,
|
|
17
|
+
}, {
|
|
18
|
+
type: 'input',
|
|
19
|
+
name: 'description',
|
|
20
|
+
message: 'Description:',
|
|
21
|
+
}, {
|
|
22
|
+
type: 'input',
|
|
23
|
+
name: 'keywords',
|
|
24
|
+
message: 'Keywords:',
|
|
25
|
+
filter: (ans) => ans.split(/[\s,]+/),
|
|
26
|
+
}, {
|
|
27
|
+
type: 'input',
|
|
28
|
+
name: 'author',
|
|
29
|
+
message: 'Author:',
|
|
30
|
+
default: defaultValues.author,
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
exports.promptPackageDetails = promptPackageDetails;
|
|
35
|
+
//# sourceMappingURL=questions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"questions.js","sourceRoot":"","sources":["../../src/questionnaire/questions.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAWrC,KAAK,UAAU,oBAAoB,CAAC,aAA4C;IAC5E,OAAO,QAAQ,CAAC,MAAM,CAAC;QACnB;YACI,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,eAAe;YACxB,OAAO,EAAE,aAAa,CAAC,IAAI;SAC9B,EAAE;YACC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,aAAa,CAAC,OAAO;SACjC,EAAE;YACC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,cAAc;SAC1B,EAAE;YACC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,WAAW;YACpB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;SACvC,EAAE;YACC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,SAAS;YAClB,OAAO,EAAE,aAAa,CAAC,MAAM;SAChC;KACJ,CAAC,CAAC;AACP,CAAC;AAEQ,oDAAoB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Settings = void 0;
|
|
4
|
+
const Settings = {
|
|
5
|
+
name: '@24i/smartapps-bigscreen-',
|
|
6
|
+
version: '0.0.1',
|
|
7
|
+
author: '24i',
|
|
8
|
+
};
|
|
9
|
+
exports.Settings = Settings;
|
|
10
|
+
//# sourceMappingURL=Settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../src/settings/Settings.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG;IACb,IAAI,EAAE,2BAA2B;IACjC,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,KAAK;CAChB,CAAC;AAEO,4BAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/packages/focus/README.md
CHANGED
|
@@ -14,11 +14,13 @@ IFocusable is an interface that should be implemented by anything that can be fo
|
|
|
14
14
|
interface IFocusable {
|
|
15
15
|
focus(options?: FocusOptions): void,
|
|
16
16
|
hasDom?(element: HTMLElement): boolean,
|
|
17
|
+
hasFocus?(): boolean,
|
|
17
18
|
}
|
|
18
19
|
```
|
|
19
20
|
- focus is the main function that is called when focusing component/element.
|
|
20
21
|
- hasDom is optional optimization for components to help Layout components locate the currently
|
|
21
22
|
focused child.
|
|
23
|
+
- hasFocus is optional check if the component has focus inside or is itself focused.
|
|
22
24
|
|
|
23
25
|
## Layout components
|
|
24
26
|
- Vertical: Use it to create focus between elements vertically (up/down)
|
|
@@ -329,3 +331,18 @@ outside of the component and not focused.
|
|
|
329
331
|
```ts
|
|
330
332
|
const refocusAfterHashChange = (focusWrapperOrReference: HTMLElement | Reference<HTMLElement>) => void;
|
|
331
333
|
```
|
|
334
|
+
|
|
335
|
+
## hasFocus
|
|
336
|
+
Test if the element (or element in the reference) has the `activeElement` inside or optionally,
|
|
337
|
+
if the element itself is the `activeElement`.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
const hasFocus = (elementOrReference: HTMLElement | Reference<HTMLElement>, includeElementItself = false) => boolean;
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## isFocused
|
|
344
|
+
Test if the element (or element in the reference) is the `activeElement`.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
const isFocused = (elementOrReference: HTMLElement | Reference<HTMLElement>) => boolean;
|
|
348
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Reference, unwrapReference } from '@24i/bigscreen-sdk/jsx';
|
|
2
|
+
import { isElementWrappedBy } from '@24i/bigscreen-sdk/utils/elementUtils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Test if the element (or element in the reference) has the `activeElement` inside or optionally,
|
|
6
|
+
* if the element itself is the `activeElement`.
|
|
7
|
+
* @param elementOrReference DOM element or reference to element on which we test focus
|
|
8
|
+
* @param includeElementItself if true, active element is also tested with the provided element.
|
|
9
|
+
* Default is false
|
|
10
|
+
* @returns true if the element has focused element inside or is itself focused
|
|
11
|
+
*/
|
|
12
|
+
export const hasFocus = (
|
|
13
|
+
elementOrReference: HTMLElement | Reference<HTMLElement>,
|
|
14
|
+
includeElementItself = false,
|
|
15
|
+
) => {
|
|
16
|
+
const element = unwrapReference(elementOrReference);
|
|
17
|
+
if (!element) return false;
|
|
18
|
+
return isElementWrappedBy(
|
|
19
|
+
document.activeElement as HTMLElement,
|
|
20
|
+
element,
|
|
21
|
+
includeElementItself,
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Test if the element (or element in the reference) is the `activeElement`.
|
|
27
|
+
* @param elementOrReference DOM element or reference to element on which we test focus
|
|
28
|
+
* @returns true if the element is focused
|
|
29
|
+
*/
|
|
30
|
+
export const isFocused = (
|
|
31
|
+
elementOrReference: HTMLElement | Reference<HTMLElement>,
|
|
32
|
+
) => {
|
|
33
|
+
const element = unwrapReference(elementOrReference);
|
|
34
|
+
if (!element) return false;
|
|
35
|
+
return document.activeElement === element;
|
|
36
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkInstaller = void 0;
|
|
4
|
+
var sdkInstaller_1 = require("./sdkInstaller");
|
|
5
|
+
Object.defineProperty(exports, "sdkInstaller", { enumerable: true, get: function () { return sdkInstaller_1.sdkInstaller; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkInstaller = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
const services_1 = require("./services");
|
|
7
|
+
const log = (message) => process.stdout.write(message);
|
|
8
|
+
const sdkInstaller = async ({ zipPath, installPath, enableLogs }) => {
|
|
9
|
+
const logger = enableLogs ? log : () => false;
|
|
10
|
+
const pathsToDelete = [];
|
|
11
|
+
let usedInstallPath;
|
|
12
|
+
try {
|
|
13
|
+
const parsedZipPath = (0, path_1.parse)(zipPath);
|
|
14
|
+
const parsedZipUrl = (0, url_1.parse)(zipPath);
|
|
15
|
+
if (!parsedZipUrl.protocol) {
|
|
16
|
+
throw new Error('Installation from local packages is not supported yet.');
|
|
17
|
+
}
|
|
18
|
+
logger('Downloading...');
|
|
19
|
+
const downloadedFilePath = `${process.cwd()}/${parsedZipPath.base}`;
|
|
20
|
+
pathsToDelete.push(downloadedFilePath);
|
|
21
|
+
await (0, services_1.download)(zipPath, downloadedFilePath);
|
|
22
|
+
logger('\rUnpacking...');
|
|
23
|
+
const unzippedDirPath = `${process.cwd()}/${parsedZipPath.name}`;
|
|
24
|
+
pathsToDelete.push(unzippedDirPath);
|
|
25
|
+
(0, services_1.unzip)(downloadedFilePath);
|
|
26
|
+
logger('\rInstalling...');
|
|
27
|
+
usedInstallPath = (0, services_1.install)(unzippedDirPath, installPath);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
(0, services_1.clean)(pathsToDelete);
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
logger('\rCleaning...');
|
|
34
|
+
(0, services_1.clean)(pathsToDelete);
|
|
35
|
+
logger(`\rInstalled to ${usedInstallPath}\n`);
|
|
36
|
+
return usedInstallPath;
|
|
37
|
+
};
|
|
38
|
+
exports.sdkInstaller = sdkInstaller;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clean = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const deleteFileOrDirectory = (path) => {
|
|
6
|
+
(0, child_process_1.spawnSync)('rm', ['-r', path]);
|
|
7
|
+
};
|
|
8
|
+
const clean = (pathsToBeDeleted) => {
|
|
9
|
+
pathsToBeDeleted.forEach(deleteFileOrDirectory);
|
|
10
|
+
};
|
|
11
|
+
exports.clean = clean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.download = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const url = require("url");
|
|
7
|
+
const http = require("http");
|
|
8
|
+
const https = require("https");
|
|
9
|
+
const createDirPathIfDoesntExist = async (dirPath) => {
|
|
10
|
+
if (!fs.existsSync(dirPath)) {
|
|
11
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const getNetworkProtocolAdapter = (requestedUrl) => {
|
|
15
|
+
const { protocol } = url.parse(requestedUrl);
|
|
16
|
+
switch (protocol) {
|
|
17
|
+
case 'http:': return http;
|
|
18
|
+
case 'https:': return https;
|
|
19
|
+
default: throw new Error(`${protocol} protocol is not supported`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const getResponseError = (response) => {
|
|
23
|
+
const HTTP_RESPONSE_STATUS_CODE_OK = 200;
|
|
24
|
+
const { statusCode, headers } = response;
|
|
25
|
+
const contentType = headers['content-type'];
|
|
26
|
+
if (statusCode !== HTTP_RESPONSE_STATUS_CODE_OK) {
|
|
27
|
+
return new Error(`Request Failed. Status Code: ${statusCode}`);
|
|
28
|
+
}
|
|
29
|
+
if (!contentType) {
|
|
30
|
+
return new Error('Missing Content-Type: expected application/zip');
|
|
31
|
+
}
|
|
32
|
+
if (!/^application\/zip/.test(contentType)) {
|
|
33
|
+
return new Error(`Wrong Content-Type: expected application/zip, received ${contentType}`);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
const download = async (fromUrl, toFilePath) => {
|
|
38
|
+
const toDirPath = path.parse(toFilePath).dir;
|
|
39
|
+
await createDirPathIfDoesntExist(toDirPath);
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const request = getNetworkProtocolAdapter(fromUrl).get(fromUrl, (response) => {
|
|
42
|
+
const error = getResponseError(response);
|
|
43
|
+
if (error) {
|
|
44
|
+
reject(error);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const file = fs.createWriteStream(toFilePath);
|
|
48
|
+
file.on('error', reject);
|
|
49
|
+
file.on('finish', resolve);
|
|
50
|
+
response.pipe(file);
|
|
51
|
+
});
|
|
52
|
+
request.on('error', reject);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.download = download;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clean = exports.install = exports.unzip = exports.download = void 0;
|
|
4
|
+
var download_1 = require("./download");
|
|
5
|
+
Object.defineProperty(exports, "download", { enumerable: true, get: function () { return download_1.download; } });
|
|
6
|
+
var unzip_1 = require("./unzip");
|
|
7
|
+
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return unzip_1.unzip; } });
|
|
8
|
+
var install_1 = require("./install");
|
|
9
|
+
Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_1.install; } });
|
|
10
|
+
var clean_1 = require("./clean");
|
|
11
|
+
Object.defineProperty(exports, "clean", { enumerable: true, get: function () { return clean_1.clean; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.install = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const getInstalledPathFromOutput = (output) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const prefix = 'INSTALL_PATH=';
|
|
8
|
+
const installedPathRow = output
|
|
9
|
+
.split('\n')
|
|
10
|
+
.map((outputRow) => outputRow.trim())
|
|
11
|
+
.filter((trimmedOutputRow) => trimmedOutputRow.startsWith(prefix));
|
|
12
|
+
return ((_a = installedPathRow[0]) === null || _a === void 0 ? void 0 : _a.replace(prefix, '')) || '';
|
|
13
|
+
};
|
|
14
|
+
const install = (installerDirPath, installToPath) => {
|
|
15
|
+
const installationScriptPath = `${installerDirPath}/install.js`;
|
|
16
|
+
const installationCommandWithoutCustomPath = `node ${installationScriptPath}`;
|
|
17
|
+
const installationCmdToBeUsed = installToPath
|
|
18
|
+
? `${installationCommandWithoutCustomPath} ${installToPath}`
|
|
19
|
+
: installationCommandWithoutCustomPath;
|
|
20
|
+
const execOptions = { maxBuffer: 5242880 };
|
|
21
|
+
const installationScriptOutput = (0, child_process_1.execSync)(installationCmdToBeUsed, execOptions).toString();
|
|
22
|
+
return getInstalledPathFromOutput(installationScriptOutput);
|
|
23
|
+
};
|
|
24
|
+
exports.install = install;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unzip = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const unzip = (filePath) => {
|
|
6
|
+
const spawnOptions = { maxBuffer: 5242880 };
|
|
7
|
+
const unzipProcess = (0, child_process_1.spawnSync)('unzip', ['-n', filePath], spawnOptions);
|
|
8
|
+
if (unzipProcess.stderr.length) {
|
|
9
|
+
throw new Error(unzipProcess.stderr.toString());
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.unzip = unzip;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sdkInstaller } from './sdkInstaller';
|
package/packages/utils/README.md
CHANGED
|
@@ -21,6 +21,7 @@ import { generateUuid } from '@24i/bigscreen-sdk/utils/generateUuid';
|
|
|
21
21
|
- **[addClass](#addClass)** - safely adds class to reference.
|
|
22
22
|
- **[debounce](#debounce)** - debounced function is only executed again after a period of not being called, supports leading, trailing (default) and both executions.
|
|
23
23
|
- **[displayToggler](#displayToggler)** - exports `getDisplayToggler` that allows you to easily show/hide an element with guard preventing unnecessary DOM calls.
|
|
24
|
+
- **[elementUtils](#elementUtils)** - various utils above HTMLElement.
|
|
24
25
|
- **[forceReflow](#forceReflow)** - To force a DOM reflow on given DOM element.
|
|
25
26
|
- **[generateUuid](#generateUuid)** - function to get UUIDv4 according to RFC 4122.
|
|
26
27
|
- **[isMouseUsed](#isMouseUsed)** - **DEPRECATED** moved to `device` package.
|
|
@@ -95,6 +96,9 @@ And returns `IDisplayToggler` interface with 4 functions:
|
|
|
95
96
|
- `isVisible: () => boolean;` - returns true if the element is visible, false otherwise
|
|
96
97
|
- `isHidden: () => boolean;` - returns true if the element is hidden, false otherwise
|
|
97
98
|
|
|
99
|
+
### elementUtils
|
|
100
|
+
Various utils for HTMLElement such as visibility tests or element wrapping tests.
|
|
101
|
+
|
|
98
102
|
### forceReflow
|
|
99
103
|
To force a DOM reflow on given DOM element. It can be needed for transitions
|
|
100
104
|
or other purposes.
|
|
@@ -4,6 +4,12 @@ import { SCREEN_WIDTH } from './sizes';
|
|
|
4
4
|
|
|
5
5
|
const SAFE_TIMEOUT = 100;
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Test if the element (or element in the reference) is wrapped visible. This means that the
|
|
9
|
+
* element does not have `display: none` or `visibility: hidden`.
|
|
10
|
+
* @param elementOrReference DOM element or reference to element on which we test wrapping
|
|
11
|
+
* @returns true if element is visible
|
|
12
|
+
*/
|
|
7
13
|
export const isElementVisible = (
|
|
8
14
|
elementOrReference: HTMLElement | Reference<HTMLElement>,
|
|
9
15
|
) => {
|
|
@@ -13,10 +19,18 @@ export const isElementVisible = (
|
|
|
13
19
|
return style.display !== 'none' && style.visibility !== 'hidden';
|
|
14
20
|
};
|
|
15
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Test if the element (or element in the reference) is wrapped fully visible. This means that the
|
|
24
|
+
* element does not have `display: none` or `visibility: hidden` and exists
|
|
25
|
+
* inside visible DOM tree, which exists in the document.body.
|
|
26
|
+
* @param elementOrReference DOM element or reference to element on which we test wrapping
|
|
27
|
+
* @returns true if element is visible
|
|
28
|
+
*/
|
|
16
29
|
export const isElementFullyVisible = (
|
|
17
30
|
elementOrReference: HTMLElement | Reference<HTMLElement>,
|
|
18
31
|
) => {
|
|
19
32
|
const element = unwrapReference(elementOrReference);
|
|
33
|
+
if (!element) return false;
|
|
20
34
|
if (isElementVisible(element)) {
|
|
21
35
|
let parent = element.parentElement;
|
|
22
36
|
while (parent) {
|
|
@@ -33,6 +47,16 @@ export const isElementFullyVisible = (
|
|
|
33
47
|
return false;
|
|
34
48
|
};
|
|
35
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Test if the element (or element in the reference) is wrapped by another element.
|
|
52
|
+
* @param elementOrReference DOM element or reference to element on which we test wrapping
|
|
53
|
+
* @param wrapperElementOrReferenceOrCondition wrapper element or certain condition (utils is
|
|
54
|
+
* running upwards in the DOM tree from first element till some element has some specific condition)
|
|
55
|
+
* @param includesElementItself if true, test will check also provided element itself.
|
|
56
|
+
* This is useful in some cases when we need to include also provided element as wrapper
|
|
57
|
+
* in one run of the util.
|
|
58
|
+
* @returns true if the element is wrapped by provided wrapper
|
|
59
|
+
*/
|
|
36
60
|
export const isElementWrappedBy = (
|
|
37
61
|
elementOrReference: HTMLElement | Reference<HTMLElement>,
|
|
38
62
|
wrapperElementOrReferenceOrCondition:
|
|
@@ -40,6 +64,7 @@ export const isElementWrappedBy = (
|
|
|
40
64
|
includesElementItself = false,
|
|
41
65
|
) => {
|
|
42
66
|
const element = unwrapReference(elementOrReference);
|
|
67
|
+
if (!element) return false;
|
|
43
68
|
let currentParent = includesElementItself ? element : element.parentElement;
|
|
44
69
|
let wrapperElement: HTMLElement | null = null;
|
|
45
70
|
let condition: ((currentWrapper: HTMLElement) => boolean) | null = null;
|