@kdex-tech/sample-app-2 0.0.1

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.
Files changed (4) hide show
  1. package/README.md +21 -0
  2. package/app.js +53 -0
  3. package/kdexapp.yaml +11 -0
  4. package/package.json +16 -0
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Sample App 2
2
+
3
+ To deploy this app to a cluster
4
+
5
+ 1. Publish it to an NPM registry
6
+
7
+ ```bash
8
+ npm publish --access public
9
+ ```
10
+
11
+ 2. Apply the [kdexapp.yaml](kdexapp.yaml) file to your cluster:
12
+
13
+ ```bash
14
+ kubectl apply -f kdexapp.yaml
15
+ ```
16
+
17
+ To undeploy this app, delete the [kdexapp.yaml](kdexapp.yaml) file from your cluster:
18
+
19
+ ```bash
20
+ kubectl delete -f kdexapp.yaml
21
+ ```
package/app.js ADDED
@@ -0,0 +1,53 @@
1
+ import { AppBridge } from '@kdex-tech/ui';
2
+
3
+ export class SampleApp2 extends AppBridge(HTMLElement) {
4
+ constructor() {
5
+ super();
6
+ this.attachShadow({ mode: 'open' });
7
+
8
+ this.shadowRoot.addEventListener('click', this._handleInternalClick.bind(this));
9
+ }
10
+
11
+ onRouteActivated(path) {
12
+ const content = this._getContentForPath(path);
13
+
14
+ this.shadowRoot.innerHTML = `
15
+ <style>
16
+ :host {
17
+ display: block;
18
+ padding: 1rem;
19
+ border-radius: 4px;
20
+ }
21
+ </style>
22
+ <div>
23
+ <h3>A simple KDex app</h3>
24
+ <pre>
25
+ appId: ${this.getAttribute('data-content-id')}
26
+ appPath: ${this.appPath}
27
+ </pre>
28
+ ${content}
29
+ <button data-navigate="/foo">Navigate to /foo</button>
30
+ <button data-navigate="/bar">Navigate to /bar</button>
31
+ </div>
32
+ `;
33
+ }
34
+
35
+ _getContentForPath(path) {
36
+ switch (path) {
37
+ case '/foo': return `<h1>I've been routed to as /foo</h1>`;
38
+ case '/bar': return `<h1>I've been routed to as /bar</h1>`;
39
+ default: return `<p>This is a test component to verify the module loading works.</p>`;
40
+ }
41
+ }
42
+
43
+ // Use a data-attribute to identify navigation targets
44
+ _handleInternalClick(event) {
45
+ const trigger = event.composedPath().find(el => el.dataset?.navigate);
46
+ if (trigger) {
47
+ this.navigate(trigger.dataset.navigate);
48
+ }
49
+ }
50
+ }
51
+
52
+ // Register the component
53
+ customElements.define('sample-app-2', SampleApp2);
package/kdexapp.yaml ADDED
@@ -0,0 +1,11 @@
1
+ apiVersion: kdex.dev/v1alpha1
2
+ kind: KDexApp
3
+ metadata:
4
+ name: sample-app-2
5
+ spec:
6
+ customElements:
7
+ - description: A simple KDex app
8
+ name: sample-app-2
9
+ packageReference:
10
+ name: "@kdex-tech/sample-app-2"
11
+ version: 0.0.1
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "author": "KDex Tech Inc.",
3
+ "description": "This is an example of a simple KDex App",
4
+ "keywords": [
5
+ "kdex",
6
+ "app"
7
+ ],
8
+ "license": "Apache-2.0",
9
+ "module": "./app.js",
10
+ "name": "@kdex-tech/sample-app-2",
11
+ "type": "module",
12
+ "version": "0.0.1",
13
+ "dependencies": {
14
+ "@kdex-tech/ui": "^1.2.13"
15
+ }
16
+ }