create-appsemble 0.19.11
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/README.md +35 -0
- package/dist/commands/block.d.ts +11 -0
- package/dist/commands/block.js +61 -0
- package/dist/commands/block.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/readPackageJson.d.ts +9 -0
- package/dist/lib/readPackageJson.js +17 -0
- package/dist/lib/readPackageJson.js.map +1 -0
- package/package.json +47 -0
- package/templates/mini-jsx/.appsemblerc.yaml +1 -0
- package/templates/mini-jsx/block.ts +28 -0
- package/templates/mini-jsx/package.json +7 -0
- package/templates/mini-jsx/src/index.module.css +19 -0
- package/templates/mini-jsx/src/index.tsx +39 -0
- package/templates/mini-jsx/tsconfig.json +9 -0
- package/templates/preact/.appsemblerc.yaml +1 -0
- package/templates/preact/block.ts +17 -0
- package/templates/preact/package.json +8 -0
- package/templates/preact/src/index.tsx +58 -0
- package/templates/preact/tsconfig.json +9 -0
- package/templates/vanilla/.appsemblerc.yaml +1 -0
- package/templates/vanilla/block.ts +10 -0
- package/templates/vanilla/package.json +6 -0
- package/templates/vanilla/src/index.ts +25 -0
- package/templates/vanilla/tsconfig.json +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#  Appsemble Create
|
|
2
|
+
|
|
3
|
+
> Bootstrap an Appsemble block
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/create-appsemble)
|
|
6
|
+
[](https://gitlab.com/appsemble/appsemble/-/releases/0.18.23)
|
|
7
|
+
[](https://codecov.io/gl/appsemble/appsemble)
|
|
8
|
+
[](https://prettier.io)
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
In a future release, this package lets a developer bootstrap Appsemble related boilerplate using
|
|
13
|
+
`npm init` or `yarn create`.
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm init appsemble
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
yarn create appsemble
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Blocks
|
|
24
|
+
|
|
25
|
+
This package allows you to bootstrap an Appsemble block in a standard Appsemble project layout. The
|
|
26
|
+
initial command will be followed by a number questions interactively.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm init appsemble block
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.18.23/LICENSE.md) ©
|
|
35
|
+
[Appsemble](https://appsemble.com)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Argv } from 'yargs';
|
|
2
|
+
export declare const command = "block";
|
|
3
|
+
export declare const description = "Bootstrap a new Appsemble block.";
|
|
4
|
+
interface BlockArgs {
|
|
5
|
+
organization?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
template?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function builder(yargs: Argv): Promise<Argv>;
|
|
10
|
+
export declare function handler(args: BlockArgs): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.description = exports.command = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const node_utils_1 = require("@appsemble/node-utils");
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const inquirer_1 = require("inquirer");
|
|
9
|
+
const readPackageJson_1 = require("../lib/readPackageJson");
|
|
10
|
+
const templateDir = path_1.resolve(__dirname, '../../templates');
|
|
11
|
+
exports.command = 'block';
|
|
12
|
+
exports.description = 'Bootstrap a new Appsemble block.';
|
|
13
|
+
async function builder(yargs) {
|
|
14
|
+
const choices = await fs_1.promises.readdir(templateDir);
|
|
15
|
+
return yargs
|
|
16
|
+
.option('organization', {
|
|
17
|
+
describe: 'The ID the block should be created for.',
|
|
18
|
+
})
|
|
19
|
+
.option('name', {
|
|
20
|
+
describe: 'The name of the block',
|
|
21
|
+
})
|
|
22
|
+
.option('template', {
|
|
23
|
+
describe: 'The template to use.',
|
|
24
|
+
choices,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.builder = builder;
|
|
28
|
+
async function handler(args) {
|
|
29
|
+
const choices = await fs_1.promises.readdir(templateDir);
|
|
30
|
+
const answers = await inquirer_1.prompt([
|
|
31
|
+
!args.organization && {
|
|
32
|
+
name: 'organization',
|
|
33
|
+
message: 'For which organization is the block?',
|
|
34
|
+
},
|
|
35
|
+
!args.name && { name: 'name', message: 'What should be the name of the block?' },
|
|
36
|
+
!args.template && {
|
|
37
|
+
name: 'type',
|
|
38
|
+
type: 'list',
|
|
39
|
+
choices,
|
|
40
|
+
message: 'What kind of block project should be bootstrapped?',
|
|
41
|
+
},
|
|
42
|
+
].filter(Boolean));
|
|
43
|
+
const organization = answers.organization || args.organization;
|
|
44
|
+
const name = answers.name || args.name;
|
|
45
|
+
const template = answers.template || args.template;
|
|
46
|
+
const { version } = await readPackageJson_1.readPackageJson();
|
|
47
|
+
const outputPath = path_1.join(process.cwd(), 'blocks', name);
|
|
48
|
+
const inputPath = path_1.join(templateDir, template);
|
|
49
|
+
const pkgPath = path_1.join(inputPath, 'package.json');
|
|
50
|
+
const [inputPkg] = await node_utils_1.readData(pkgPath);
|
|
51
|
+
const outputPkg = {
|
|
52
|
+
name: `@${organization}/${name}`,
|
|
53
|
+
version,
|
|
54
|
+
...inputPkg,
|
|
55
|
+
};
|
|
56
|
+
await fs_extra_1.copy(inputPath, outputPath, { filter: (src) => src !== pkgPath });
|
|
57
|
+
await node_utils_1.writeData(path_1.join(outputPath, 'package.json'), outputPkg);
|
|
58
|
+
node_utils_1.logger.info(`Successfully created @${organization}/${name}/${version} at ${outputPath}`);
|
|
59
|
+
}
|
|
60
|
+
exports.handler = handler;
|
|
61
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/commands/block.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,+BAAqC;AAErC,sDAAoE;AACpE,uCAAgC;AAChC,uCAAkC;AAIlC,4DAAyD;AAEzD,MAAM,WAAW,GAAG,cAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAE7C,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,WAAW,GAAG,kCAAkC,CAAC;AAQvD,KAAK,UAAU,OAAO,CAAC,KAAW;IACvC,MAAM,OAAO,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,KAAK;SACT,MAAM,CAAC,cAAc,EAAE;QACtB,QAAQ,EAAE,yCAAyC;KACpD,CAAC;SACD,MAAM,CAAC,MAAM,EAAE;QACd,QAAQ,EAAE,uBAAuB;KAClC,CAAC;SACD,MAAM,CAAC,UAAU,EAAE;QAClB,QAAQ,EAAE,sBAAsB;QAChC,OAAO;KACR,CAAC,CAAC;AACP,CAAC;AAdD,0BAcC;AAEM,KAAK,UAAU,OAAO,CAAC,IAAe;IAC3C,MAAM,OAAO,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,iBAAM,CAC1B;QACE,CAAC,IAAI,CAAC,YAAY,IAAI;YACpB,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,sCAAsC;SAChD;QACD,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uCAAuC,EAAE;QAChF,CAAC,IAAI,CAAC,QAAQ,IAAI;YAChB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,OAAO;YACP,OAAO,EAAE,oDAAoD;SAC9D;KACF,CAAC,MAAM,CAAC,OAAO,CAAC,CAClB,CAAC;IAEF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC;IAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;IACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;IAEnD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,iCAAe,EAAE,CAAC;IAC5C,MAAM,UAAU,GAAG,WAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,WAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,WAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAChD,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,qBAAQ,CAAc,OAAO,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,IAAI,YAAY,IAAI,IAAI,EAAE;QAChC,OAAO;QACP,GAAG,QAAQ;KACZ,CAAC;IACF,MAAM,eAAI,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC,CAAC;IACxE,MAAM,sBAAS,CAAC,WAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,SAAS,CAAC,CAAC;IAC7D,mBAAM,CAAC,IAAI,CAAC,yBAAyB,YAAY,IAAI,IAAI,IAAI,OAAO,OAAO,UAAU,EAAE,CAAC,CAAC;AAC3F,CAAC;AAnCD,0BAmCC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const node_utils_1 = require("@appsemble/node-utils");
|
|
9
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
10
|
+
function main() {
|
|
11
|
+
return yargs_1.default
|
|
12
|
+
.option('verbose', {
|
|
13
|
+
alias: 'v',
|
|
14
|
+
describe: 'Increase verbosity',
|
|
15
|
+
type: 'count',
|
|
16
|
+
})
|
|
17
|
+
.option('quiet', {
|
|
18
|
+
alias: 'q',
|
|
19
|
+
describe: 'Decrease verbosity',
|
|
20
|
+
type: 'count',
|
|
21
|
+
})
|
|
22
|
+
.middleware([node_utils_1.configureLogger])
|
|
23
|
+
.commandDir(path_1.join(__dirname, 'commands'), {
|
|
24
|
+
extensions: [path_1.extname(__filename).slice(1)],
|
|
25
|
+
})
|
|
26
|
+
.demandCommand(1)
|
|
27
|
+
.fail(node_utils_1.handleError)
|
|
28
|
+
.help()
|
|
29
|
+
.completion().argv;
|
|
30
|
+
}
|
|
31
|
+
if (module === require.main) {
|
|
32
|
+
try {
|
|
33
|
+
main();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
node_utils_1.logger.error(error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,+BAAqC;AAErC,sDAA6E;AAC7E,kDAA0B;AAE1B,SAAS,IAAI;IACX,OAAO,eAAK;SACT,MAAM,CAAC,SAAS,EAAE;QACjB,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,oBAAoB;QAC9B,IAAI,EAAE,OAAO;KACd,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QACf,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,oBAAoB;QAC9B,IAAI,EAAE,OAAO;KACd,CAAC;SACD,UAAU,CAAC,CAAC,4BAAe,CAAC,CAAC;SAC7B,UAAU,CAAC,WAAI,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE;QACvC,UAAU,EAAE,CAAC,cAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC3C,CAAC;SACD,aAAa,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,wBAAW,CAAC;SACjB,IAAI,EAAE;SACN,UAAU,EAAE,CAAC,IAAI,CAAC;AACvB,CAAC;AAED,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,EAAE;IAC3B,IAAI;QACF,IAAI,EAAE,CAAC;KACR;IAAC,OAAO,KAAc,EAAE;QACvB,mBAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACrB;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPackageJson = void 0;
|
|
4
|
+
const node_utils_1 = require("@appsemble/node-utils");
|
|
5
|
+
/**
|
|
6
|
+
* Read package.json
|
|
7
|
+
*
|
|
8
|
+
* TypeScript doesn’t allow importing files from outside of rootDir.
|
|
9
|
+
*
|
|
10
|
+
* @returns The contents of package.json
|
|
11
|
+
*/
|
|
12
|
+
async function readPackageJson() {
|
|
13
|
+
const [pkg] = await node_utils_1.readData(require.resolve('../../package.json'));
|
|
14
|
+
return pkg;
|
|
15
|
+
}
|
|
16
|
+
exports.readPackageJson = readPackageJson;
|
|
17
|
+
//# sourceMappingURL=readPackageJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readPackageJson.js","sourceRoot":"","sources":["../../src/lib/readPackageJson.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AAGjD;;;;;;GAMG;AACI,KAAK,UAAU,eAAe;IACnC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,qBAAQ,CAAc,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACjF,OAAO,GAAG,CAAC;AACb,CAAC;AAHD,0CAGC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-appsemble",
|
|
3
|
+
"version": "0.19.11",
|
|
4
|
+
"description": "Bootstrap an Appsemble project",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"app",
|
|
7
|
+
"apps",
|
|
8
|
+
"appsemble",
|
|
9
|
+
"cli",
|
|
10
|
+
"framework",
|
|
11
|
+
"low-code",
|
|
12
|
+
"lowcode"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://appsemble.app",
|
|
15
|
+
"bugs": "https://gitlab.com/appsemble/appsemble/issues",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://gitlab.com/appsemble/appsemble.git",
|
|
19
|
+
"directory": "packages/create-appsemble"
|
|
20
|
+
},
|
|
21
|
+
"license": "LGPL-3.0-only",
|
|
22
|
+
"author": "Appsemble <info@appsemble.com> (https://appsemble.com)",
|
|
23
|
+
"main": "dist",
|
|
24
|
+
"bin": "dist/index.js",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"templates"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"prepack": "tsc -p tsconfig.build.json",
|
|
31
|
+
"test": "jest"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@appsemble/node-utils": "0.19.11",
|
|
35
|
+
"fs-extra": "^10.0.0",
|
|
36
|
+
"inquirer": "^8.0.0",
|
|
37
|
+
"type-fest": "^2.0.0",
|
|
38
|
+
"yargs": "^17.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/fs-extra": "^9.0.0",
|
|
42
|
+
"@types/inquirer": "^8.0.0"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=12.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
output: dist
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IconName, Remapper } from '@appsemble/sdk';
|
|
2
|
+
|
|
3
|
+
export interface Field {
|
|
4
|
+
/**
|
|
5
|
+
* The value of the property to render.
|
|
6
|
+
*/
|
|
7
|
+
value: Remapper;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The fontawesome icon to render.
|
|
11
|
+
*/
|
|
12
|
+
icon: IconName;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The label to render.
|
|
16
|
+
*/
|
|
17
|
+
label?: Remapper;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare module '@appsemble/sdk' {
|
|
21
|
+
interface EventListeners {
|
|
22
|
+
data: {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Parameters {
|
|
26
|
+
fields: Field[];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { bootstrap } from '@appsemble/sdk';
|
|
2
|
+
|
|
3
|
+
import styles from './index.module.css';
|
|
4
|
+
|
|
5
|
+
bootstrap(({ events, parameters: { fields }, utils: { fa, remap } }) => {
|
|
6
|
+
const wrapper = (
|
|
7
|
+
<div className={styles.wrapper}>
|
|
8
|
+
<div className={styles.loader} />
|
|
9
|
+
</div>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
events.on.data((data, error) => {
|
|
13
|
+
while (wrapper.lastElementChild) {
|
|
14
|
+
wrapper.lastElementChild.remove();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (error) {
|
|
18
|
+
wrapper.append('error');
|
|
19
|
+
} else {
|
|
20
|
+
wrapper.append(
|
|
21
|
+
...fields.map(({ icon, label, value }) => {
|
|
22
|
+
const remappedLabel = remap(label, data) as string;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className={styles.field}>
|
|
26
|
+
<i className={`${fa(icon)} ${styles.icon}`} />
|
|
27
|
+
<div className={`has-text-weight-bold ${styles.value}`}>
|
|
28
|
+
{remap(value, data) as string}
|
|
29
|
+
</div>
|
|
30
|
+
{remappedLabel && <div>{remappedLabel}</div>}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return <div>{wrapper}</div>;
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
output: dist
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module '@appsemble/sdk' {
|
|
2
|
+
interface EventListeners {
|
|
3
|
+
/**
|
|
4
|
+
* This event can be used to receive incoming data to display.
|
|
5
|
+
*/
|
|
6
|
+
data: never;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface Parameters {
|
|
10
|
+
/**
|
|
11
|
+
* A list of fields to render out in a table.
|
|
12
|
+
*/
|
|
13
|
+
fields: string[];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { bootstrap } from '@appsemble/preact';
|
|
2
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
3
|
+
|
|
4
|
+
bootstrap(({ events, parameters: { fields } }) => {
|
|
5
|
+
const [data, setData] = useState<any[]>(null);
|
|
6
|
+
const [error, setError] = useState(false);
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const onData = (newData: unknown[], newError: unknown): void => {
|
|
10
|
+
if (newError) {
|
|
11
|
+
setError(true);
|
|
12
|
+
setData(null);
|
|
13
|
+
} else {
|
|
14
|
+
setError(false);
|
|
15
|
+
setData(newData);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
events.on.data(onData);
|
|
20
|
+
|
|
21
|
+
return () => {
|
|
22
|
+
events.off.data(onData);
|
|
23
|
+
};
|
|
24
|
+
}, [events]);
|
|
25
|
+
|
|
26
|
+
if (error) {
|
|
27
|
+
return <p>Error loading data.</p>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!data) {
|
|
31
|
+
return <p>Loading…</p>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!data.length) {
|
|
35
|
+
return <p>No data to display.</p>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<table className="table">
|
|
40
|
+
<thead>
|
|
41
|
+
<tr>
|
|
42
|
+
{fields.map((field) => (
|
|
43
|
+
<th key={field}>{field}</th>
|
|
44
|
+
))}
|
|
45
|
+
</tr>
|
|
46
|
+
</thead>
|
|
47
|
+
<tbody>
|
|
48
|
+
{data.map((item, dataIndex) => (
|
|
49
|
+
<tr key={item.id || dataIndex}>
|
|
50
|
+
{fields.map((field) => (
|
|
51
|
+
<td key={field}>{item[field]}</td>
|
|
52
|
+
))}
|
|
53
|
+
</tr>
|
|
54
|
+
))}
|
|
55
|
+
</tbody>
|
|
56
|
+
</table>
|
|
57
|
+
);
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
output: dist
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { bootstrap } from '@appsemble/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} actions - Prepared actions the block can dispatch.
|
|
5
|
+
* @param {Object} data - The data that was somehow passed into the block. I.e. data passed in from
|
|
6
|
+
* another block.
|
|
7
|
+
* @param {Object} events - Event related functions and constants.
|
|
8
|
+
* @param {Object} pageParameters - Parameters that the app creator defined in the app definition.
|
|
9
|
+
* @param {Object} utils - Some utility functions provided by the Appsemble framework.
|
|
10
|
+
*/
|
|
11
|
+
bootstrap(({ actions, data, events, pageParameters, shadowRoot, utils }) => {
|
|
12
|
+
const button = document.createElement('button');
|
|
13
|
+
button.type = 'button';
|
|
14
|
+
button.textContent = 'Click me!';
|
|
15
|
+
button.classList.add('button');
|
|
16
|
+
button.addEventListener(
|
|
17
|
+
'click',
|
|
18
|
+
(event) => {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
actions.onClick();
|
|
21
|
+
},
|
|
22
|
+
true,
|
|
23
|
+
);
|
|
24
|
+
return button;
|
|
25
|
+
});
|