diff --git a/flake.nix b/flake.nix index 46658bbd5..eaf7f6be6 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ lib.wrapCustomTemplate = { system, pkgs, customTemplatePath }: let - scaffolding = inputs.holochain.packages.${system}.hc-scaffold; + scaffolding = inputs.holonix.packages.${system}.hc-scaffold; in pkgs.runCommand "hc-scaffold" { diff --git a/templates/custom-template/custom-template/flake.nix b/templates/custom-template/custom-template/flake.nix index 88e44d806..469e618cd 100644 --- a/templates/custom-template/custom-template/flake.nix +++ b/templates/custom-template/custom-template/flake.nix @@ -3,28 +3,30 @@ inputs = { holonix.url = "github:holochain/holonix?ref=main"; - + scaffolding.url = "github:holochain/scaffolding/holochain-weekly"; nixpkgs.follows = "holonix/nixpkgs"; flake-parts.follows = "holonix/flake-parts"; }; outputs = inputs@{ flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = builtins.attrNames inputs.holonix.devShells; - perSystem = { inputs', pkgs, ... }: { + perSystem = { inputs', pkgs, system, ... }: { formatter = pkgs.nixpkgs-fmt; devShells.default = pkgs.mkShell { inputsFrom = [ inputs'.holonix.devShells.default ]; - packages = (with pkgs; [ - nodejs_20 - binaryen - ]); + packages = (with pkgs; [ nodejs_20 binaryen ]); shellHook = '' export PS1='\[\033[1;34m\][holonix:\w]\$\[\033[0m\] ' ''; }; + + packages.app = inputs.scaffolding.lib.wrapCustomTemplate { + inherit pkgs system; + customTemplatePath = ./template; + }; }; }; } diff --git a/templates/custom-template/custom-template/template/collection.instructions.hbs b/templates/custom-template/custom-template/template/collection.instructions.hbs index a26ae14af..51ad54b6f 100644 --- a/templates/custom-template/custom-template/template/collection.instructions.hbs +++ b/templates/custom-template/custom-template/template/collection.instructions.hbs @@ -1,9 +1,2 @@ -{{#if (eq collection_type.type "Global")}} -At first, the UI for this application is empty. If you want the newly scaffolded collection to be the entry point for its UI, import the element in `ui/src/holochain-app.ts`: - - import './{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}'; - -And insert it in the `
` like this: - -
<{{kebab_case collection_name}}>
-{{/if}} +If you want the newly scaffolded collection's component to be the entry point for its UI, import the +generated <{{kebab_case collection_name}}> component. \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/collection/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.test.ts.hbs b/templates/custom-template/custom-template/template/collection/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.test.ts.hbs index 59cd68f89..7694dcbda 100644 --- a/templates/custom-template/custom-template/template/collection/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.test.ts.hbs +++ b/templates/custom-template/custom-template/template/collection/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.test.ts.hbs @@ -1,7 +1,16 @@ import { assert, test } from "vitest"; import { runScenario, dhtSync, CallableCell } from '@holochain/tryorama'; -import { NewEntryAction, ActionHash, Record, Link, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash } from '@holochain/client'; +import { + NewEntryAction, + ActionHash, + Record, + Link, + AppBundleSource, + fakeActionHash, + fakeAgentPubKey, + fakeEntryHash +} from '@holochain/client'; import { decode } from '@msgpack/msgpack'; import { create{{pascal_case referenceable.name}} } from './common.js'; @@ -66,4 +75,3 @@ test('create a {{pascal_case referenceable.name}} and get {{lower_case collectio {{/if}} }); }); - diff --git a/templates/custom-template/custom-template/template/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.ts.hbs b/templates/custom-template/custom-template/template/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.ts.hbs index a8dccc205..8a7a87967 100644 --- a/templates/custom-template/custom-template/template/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.ts.hbs +++ b/templates/custom-template/custom-template/template/collection/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case collection_name}}.ts.hbs @@ -4,6 +4,7 @@ import { AppClient, AgentPubKey, Link, EntryHash, ActionHash, Record, NewEntryAc import { consume } from '@lit-labs/context'; import { Task } from '@lit-labs/task'; +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; import { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; @@ -24,7 +25,7 @@ export class {{pascal_case collection_name}} extends LitElement { @state() signaledHashes: Array<{{referenceable.hash_type}}> = []; - _fetch{{pascal_case (plural referenceable.name)}} = new Task(this, ([{{#if (eq collection_type.type "ByAuthor")}}author{{/if}}]) => this.client.callZome({ + _fetch{{pascal_case (plural referenceable.name)}} = new Task(this, ([{{#if (eq collection_type.type "ByAuthor")}}author{{/if}}]: any) => this.client.callZome({ cap_secret: null, role_name: '{{dna_role_name}}', zome_name: '{{coordinator_zome_manifest.name}}', @@ -34,12 +35,12 @@ export class {{pascal_case collection_name}} extends LitElement { firstUpdated() { {{#if (eq collection_type.type "ByAuthor")}} - if (this.author === undefined) { + if (!this.author) { throw new Error(`The author property is required for the {{kebab_case collection_name}} element`); } {{/if}} - this.client.on('signal', signal => { + this.client?.on('signal', signal => { if (!(SignalType.App in signal)) return; if (signal.App.zome_name !== '{{coordinator_zome_manifest.name}}') return; const payload = signal.App.payload as {{pascal_case coordinator_zome_manifest.name}}Signal; @@ -53,25 +54,27 @@ export class {{pascal_case collection_name}} extends LitElement { } renderList(hashes: Array<{{referenceable.hash_type}}>) { - if (hashes.length === 0) return html`No {{lower_case (plural referenceable.name)}} found{{#if (eq collection_type.type "ByAuthor")}} for this author{{/if}}.`; + if (!hashes.length) return html`
No {{lower_case (plural referenceable.name)}} found{{#if (eq collection_type.type "ByAuthor")}} for this author{{/if}}.
`; return html` - -
- ${hashes.map(hash => - html`<{{kebab_case referenceable.name}}-detail .{{camel_case referenceable.name}}Hash=${hash} style="margin-bottom: 16px;" @{{kebab_case referenceable.name}}-deleted=${() => { this._fetch{{pascal_case (plural referenceable.name)}}.run(); this.signaledHashes = []; } }>` - )} +
+ ${hashes.map(hash => html` + <{{kebab_case referenceable.name}}-detail + .{{camel_case referenceable.name}}Hash=${hash} + @{{kebab_case referenceable.name}}-deleted=${() => { this._fetch{{pascal_case (plural referenceable.name)}}.run(); this.signaledHashes = []; } } + > + `)}
`; } render() { return this._fetch{{pascal_case (plural referenceable.name)}}.render({ - pending: () => html`
- -
`, + pending: () => html``, complete: (links) => this.renderList([...this.signaledHashes, ...links.map(l => l.target)]), - error: (e: any) => html`Error fetching the {{lower_case (plural referenceable.name)}}: ${e.message}.` + error: (e: any) => html`
Error fetching the {{lower_case (plural referenceable.name)}}: ${e.message}.
` }); } + + static styles = sharedStyles; } diff --git a/templates/custom-template/custom-template/template/coordinator-zome/tests/src/{{dna_role_name}}/{{zome_manifest.name}}/common.ts.hbs b/templates/custom-template/custom-template/template/coordinator-zome/tests/src/{{dna_role_name}}/{{zome_manifest.name}}/common.ts.hbs index e1b810614..04f613ed8 100644 --- a/templates/custom-template/custom-template/template/coordinator-zome/tests/src/{{dna_role_name}}/{{zome_manifest.name}}/common.ts.hbs +++ b/templates/custom-template/custom-template/template/coordinator-zome/tests/src/{{dna_role_name}}/{{zome_manifest.name}}/common.ts.hbs @@ -1,3 +1,2 @@ import { CallableCell } from '@holochain/tryorama'; import { NewEntryAction, ActionHash, Record, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash, fakeDnaHash } from '@holochain/client'; - diff --git a/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/common.ts.hbs b/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/common.ts.hbs index 6009ec1a2..404534844 100644 --- a/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/common.ts.hbs +++ b/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/common.ts.hbs @@ -50,4 +50,3 @@ export async function create{{pascal_case entry_type.name}}(cell: CallableCell, payload: {{camel_case entry_type.name}} || await sample{{pascal_case entry_type.name}}(cell), }); } - diff --git a/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}.test.ts.hbs b/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}.test.ts.hbs index d9e4500d0..28b4d67d9 100644 --- a/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}.test.ts.hbs +++ b/templates/custom-template/custom-template/template/entry-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}.test.ts.hbs @@ -1,7 +1,19 @@ import { assert, test } from "vitest"; import { runScenario, dhtSync, CallableCell } from '@holochain/tryorama'; -import { Link, NewEntryAction, ActionHash, Record, AppBundleSource, fakeDnaHash, fakeActionHash, fakeAgentPubKey, fakeEntryHash } from '@holochain/client'; +import { + NewEntryAction, + ActionHash, + Record, + Link, + CreateLink, + DeleteLink, + SignedActionHashed, + AppBundleSource, + fakeActionHash, + fakeAgentPubKey, + fakeEntryHash +} from '@holochain/client'; import { decode } from '@msgpack/msgpack'; import { create{{pascal_case entry_type.name}}, sample{{pascal_case entry_type.name}} } from './common.js'; @@ -12,7 +24,7 @@ test('create {{pascal_case entry_type.name}}', async () => { // This assumes app bundle created by the `hc app pack` command. const testAppPath = process.cwd() + '/../workdir/{{app_name}}.happ'; - // Set up the app to be installed + // Set up the app to be installed const appSource = { appBundleSource: { path: testAppPath } }; // Add 2 players with the test app to the Scenario. The returned players @@ -35,7 +47,7 @@ test('create and read {{pascal_case entry_type.name}}', async () => { // This assumes app bundle created by the `hc app pack` command. const testAppPath = process.cwd() + '/../workdir/{{app_name}}.happ'; - // Set up the app to be installed + // Set up the app to be installed const appSource = { appBundleSource: { path: testAppPath } }; // Add 2 players with the test app to the Scenario. The returned players @@ -87,7 +99,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => { // This assumes app bundle created by the `hc app pack` command. const testAppPath = process.cwd() + '/../workdir/{{app_name}}.happ'; - // Set up the app to be installed + // Set up the app to be installed const appSource = { appBundleSource: { path: testAppPath } }; // Add 2 players with the test app to the Scenario. The returned players @@ -101,9 +113,9 @@ test('create and update {{pascal_case entry_type.name}}', async () => { // Alice creates a {{pascal_case entry_type.name}} const record: Record = await create{{pascal_case entry_type.name}}(alice.cells[0]); assert.ok(record); - + const originalActionHash = record.signed_action.hashed.hash; - + // Alice updates the {{pascal_case entry_type.name}} let contentUpdate: any = await sample{{pascal_case entry_type.name}}(alice.cells[0]); let updateInput = { @@ -123,7 +135,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => { // Wait for the updated entry to be propagated to the other node. await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - + // Bob gets the updated {{pascal_case entry_type.name}} const readUpdatedOutput0: Record = await bob.cells[0].callZome({ zome_name: "{{coordinator_zome_manifest.name}}", @@ -134,7 +146,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => { // Alice updates the {{pascal_case entry_type.name}} again contentUpdate = await sample{{pascal_case entry_type.name}}(alice.cells[0]); - updateInput = { + updateInput = { {{#if link_from_original_to_each_update}} original_{{snake_case entry_type.name}}_hash: originalActionHash, {{/if}} @@ -151,7 +163,7 @@ test('create and update {{pascal_case entry_type.name}}', async () => { // Wait for the updated entry to be propagated to the other node. await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - + // Bob gets the updated {{pascal_case entry_type.name}} const readUpdatedOutput1: Record = await bob.cells[0].callZome({ zome_name: "{{coordinator_zome_manifest.name}}", @@ -179,7 +191,7 @@ test('create and delete {{pascal_case entry_type.name}}', async () => { // This assumes app bundle created by the `hc app pack` command. const testAppPath = process.cwd() + '/../workdir/{{app_name}}.happ'; - // Set up the app to be installed + // Set up the app to be installed const appSource = { appBundleSource: { path: testAppPath } }; // Add 2 players with the test app to the Scenario. The returned players @@ -223,17 +235,17 @@ test('create and delete {{pascal_case entry_type.name}}', async () => { // Wait for the entry deletion to be propagated to the other node. await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - + // Bob gets the oldest delete for the {{pascal_case entry_type.name}} - const oldestDeleteFor{{pascal_case entry_type.name}} = await bob.cells[0].callZome({ + const oldestDeleteFor{{pascal_case entry_type.name}}: SignedActionHashed = await bob.cells[0].callZome({ zome_name: "{{coordinator_zome_manifest.name}}", fn_name: "get_oldest_delete_for_{{snake_case entry_type.name}}", payload: record.signed_action.hashed.hash, }); assert.ok(oldestDeleteFor{{pascal_case entry_type.name}}); - - // Bob gets the deletions for {{pascal_case entry_type.name}} - const deletesFor{{pascal_case entry_type.name}} = await bob.cells[0].callZome({ + + // Bob gets the deletions for the {{pascal_case entry_type.name}} + const deletesFor{{pascal_case entry_type.name}}: SignedActionHashed[] = await bob.cells[0].callZome({ zome_name: "{{coordinator_zome_manifest.name}}", fn_name: "get_all_deletes_for_{{snake_case entry_type.name}}", payload: record.signed_action.hashed.hash, @@ -251,8 +263,8 @@ test('create and delete {{pascal_case entry_type.name}}', async () => { }); assert.equal(linksTo{{pascal_case (plural linked_from.name)}}.length, 0); - // Bob gets the deleted {{pascal_case (plural linked_from.name)}} for the {{pascal_case ../entry_type.name}} - const deletedLinksTo{{pascal_case (plural linked_from.name)}} = await bob.cells[0].callZome({ + // Bob gets the deleted {{pascal_case (plural linked_from.name)}} for the {{pascal_case ../entry_type.name}} + const deletedLinksTo{{pascal_case (plural linked_from.name)}}: Array<[SignedActionHashed, SignedActionHashed[]]> = await bob.cells[0].callZome({ zome_name: "{{../coordinator_zome_manifest.name}}", fn_name: "get_deleted_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}", payload: {{#if (eq cardinality "vector")}}sample.{{field_name}}[0]{{else}}sample.{{field_name}}{{/if}} diff --git a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/create-{{kebab_case entry_type.name}}.ts.hbs b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/create-{{kebab_case entry_type.name}}.ts.hbs index 03da7a895..36cfdf8fe 100644 --- a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/create-{{kebab_case entry_type.name}}.ts.hbs +++ b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/create-{{kebab_case entry_type.name}}.ts.hbs @@ -1,10 +1,7 @@ import { LitElement, html } from 'lit'; import { state, customElement, property } from 'lit/decorators.js'; -import { InstalledCell, ActionHash, Record, AgentPubKey, EntryHash, AppClient, DnaHash } from '@holochain/client'; +import { InstalledCell, ActionHash, Record, AgentPubKey, EntryHash, AppClient, DnaHash, HolochainError } from '@holochain/client'; import { consume } from '@lit-labs/context'; -import '@material/mwc-button'; -import '@material/mwc-snackbar'; -import { Snackbar } from '@material/mwc-snackbar'; {{#uniq_lines}} {{#each entry_type.fields}} {{#if widget}} @@ -14,6 +11,7 @@ import { Snackbar } from '@material/mwc-snackbar'; {{/each}} {{/uniq_lines}} +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; import { {{pascal_case entry_type.name}}{{#each entry_type.fields}}{{#if (eq field_type.type "Enum")}}, {{field_type.label}}{{/if}}{{/each}} } from './types'; @@ -53,7 +51,7 @@ export class Create{{pascal_case entry_type.name}} extends LitElement { {{/if}} {{/if}} {{/each}} - + firstUpdated() { {{#each entry_type.fields}} {{#if (not widget) }} @@ -71,7 +69,7 @@ export class Create{{pascal_case entry_type.name}} extends LitElement { } async create{{pascal_case entry_type.name}}() { - const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { + const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { {{#each entry_type.fields}} {{#if widget}} {{snake_case field_name}}: this._{{camel_case field_name}}, @@ -97,41 +95,37 @@ export class Create{{pascal_case entry_type.name}} extends LitElement { {{camel_case entry_type.name}}Hash: record.signed_action.hashed.hash } })); - } catch (e: any) { - const errorSnackbar = this.shadowRoot?.getElementById('create-error') as Snackbar; - errorSnackbar.labelText = `Error creating the {{lower_case entry_type.name}}: ${e.message}`; - errorSnackbar.show(); + } catch (e) { + alert((e as HolochainError).message); } } render() { return html` - - - -
- Create {{title_case entry_type.name}} - +
+

Create {{pascal_case entry_type.name}}

{{#each entry_type.fields}} {{#if widget}} -
+
{{#if (not (eq cardinality "vector") )}} - {{> (concat field_type.type "/" widget "/edit/render") label=(title_case field_name) variable_to_read=(concat "this._" (camel_case field_name) ) variable_to_change=(concat "this._" (camel_case field_name) ) required=(eq cardinality "single") }} + {{> (concat field_type.type "/" widget "/edit/render") label=(title_case field_name) variable_to_read=(concat "this._" (camel_case field_name) ) variable_to_change=(concat "this._" (camel_case field_name) ) required=(eq cardinality "single") }} {{else}} - {{> Vec/edit/render field_name=field_name field_type=field_type widget=widget }} + {{> Vec/edit/render field_name=field_name field_type=field_type widget=widget }} {{/if}} - -
- + +
{{/if}} {{/each}} - this.create{{pascal_case entry_type.name}}()} - > -
`; + > + Create {{title_case entry_type.name}} + +
+ `; } -} + + static styles = sharedStyles; +} \ No newline at end of file diff --git "a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" "b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" index 2b2ae89c2..fae604da5 100644 --- "a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" +++ "b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" @@ -1,10 +1,13 @@ import { LitElement, html } from 'lit'; import { state, customElement, property } from 'lit/decorators.js'; -import { InstalledCell, Record, Link, AppClient, EntryHash, ActionHash, AgentPubKey } from '@holochain/client'; +import { InstalledCell, Record, Link, AppClient, EntryHash, ActionHash, AgentPubKey, SignalType } from '@holochain/client'; import { consume } from '@lit-labs/context'; import { Task } from '@lit-labs/task'; +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; +import { {{pascal_case ../coordinator_zome_manifest.name}}Signal } from './types'; + import './{{kebab_case ../entry_type.name}}-detail'; @customElement('{{kebab_case (plural ../entry_type.name)}}-for-{{kebab_case linked_from.name}}') @@ -13,11 +16,14 @@ export class {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_ client!: AppClient; @property({ - hasChanged: (newVal: {{linked_from.hash_type}}, oldVal: {{linked_from.hash_type}}) => newVal.toString() !== oldVal.toString() + hasChanged: (newVal: {{linked_from.hash_type}}, oldVal: {{linked_from.hash_type}}) => newVal.toString() !== oldVal?.toString() }) {{camel_case linked_from.singular_arg}}!: {{linked_from.hash_type}}; - _fetch{{pascal_case (plural ../entry_type.name)}} = new Task(this, ([{{camel_case linked_from.singular_arg}}]) => this.client.callZome({ + @state() + hashes: Array = []; + + _fetch{{pascal_case (plural ../entry_type.name)}} = new Task(this, ([{{camel_case linked_from.singular_arg}}]: Array<{{linked_from.hash_type}}>) => this.client.callZome({ cap_secret: null, role_name: '{{../dna_role_name}}', zome_name: '{{../coordinator_zome_manifest.name}}', @@ -26,30 +32,41 @@ export class {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_ }) as Promise>, () => [this.{{camel_case linked_from.singular_arg}}]); firstUpdated() { - if (this.{{camel_case linked_from.singular_arg}} === undefined) { + if (!this.{{camel_case linked_from.singular_arg}}) { throw new Error(`The {{camel_case linked_from.singular_arg}} property is required for the {{kebab_case (plural ../entry_type.name)}}-for-{{kebab_case linked_from.name}} element`); } + + this.client?.on('signal', signal => { + if (!(SignalType.App in signal)) return; + if (signal.App.zome_name !== '{{../coordinator_zome_manifest.name}}') return; + const payload = signal.App.payload as {{pascal_case ../coordinator_zome_manifest.name}}Signal; + if (!(payload.type === 'EntryCreated' && payload.app_entry.type === '{{pascal_case ../entry_type.name}}')) return; + this._fetch{{pascal_case (plural ../entry_type.name)}}.run(); + }) } - renderList(links: Array) { - if (links.length === 0) return html`No {{lower_case (plural ../entry_type.name)}} found for this {{lower_case linked_from.name}}.`; + renderList(hashes: Array) { + if (!hashes.length) return html`
No {{lower_case (plural ../entry_type.name)}} found for this {{lower_case linked_from.name}}.
`; return html` -
- ${links.map(link => - html`<{{kebab_case ../entry_type.name}}-detail .{{camel_case ../entry_type.name}}Hash=${link.target}>` - )} +
+ ${hashes.map(hash => html` + <{{kebab_case ../entry_type.name}}-detail + .{{camel_case ../entry_type.name}}Hash=${hash} + @{{kebab_case ../entry_type.name}}-deleted=${() => { this._fetch{{pascal_case (plural ../entry_type.name)}}.run(); this.hashes = []; } } + > + `)}
`; } render() { return this._fetch{{pascal_case (plural ../entry_type.name)}}.render({ - pending: () => html`
- -
`, - complete: (links) => this.renderList(links), - error: (e: any) => html`Error fetching {{lower_case (plural ../entry_type.name)}}: ${e.message}.` + pending: () => html``, + complete: (links) => this.renderList([...this.hashes, ...links.map(l => l.target)]), + error: (e: any) => html`
Error fetching {{lower_case (plural ../entry_type.name)}}: ${e.message}.
` }); } -} + + static styles = sharedStyles; +} \ No newline at end of file diff --git "a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}edit-{{kebab_case entry_type.name}}.ts{{\302\241if}}.hbs" "b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}edit-{{kebab_case entry_type.name}}.ts{{\302\241if}}.hbs" index 3c1859aac..a4a1a7b01 100644 --- "a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}edit-{{kebab_case entry_type.name}}.ts{{\302\241if}}.hbs" +++ "b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}edit-{{kebab_case entry_type.name}}.ts{{\302\241if}}.hbs" @@ -1,11 +1,8 @@ import { LitElement, html } from 'lit'; import { state, customElement, property } from 'lit/decorators.js'; -import { ActionHash, EntryHash, AgentPubKey, Record, AppClient, DnaHash } from '@holochain/client'; +import { ActionHash, EntryHash, AgentPubKey, Record, AppClient, DnaHash, HolochainError } from '@holochain/client'; import { consume } from '@lit-labs/context'; import { decode } from '@msgpack/msgpack'; -import '@material/mwc-button'; -import '@material/mwc-snackbar'; -import { Snackbar } from '@material/mwc-snackbar'; {{#uniq_lines}} {{#each entry_type.fields}} {{#if widget}} @@ -15,6 +12,7 @@ import { Snackbar } from '@material/mwc-snackbar'; {{/each}} {{/uniq_lines}} +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; import { {{pascal_case entry_type.name}}{{#each entry_type.fields}}{{#if (eq field_type.type "Enum")}}, {{field_type.label}}{{/if}}{{/each}} } from './types'; @@ -23,7 +21,7 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { @consume({ context: clientContext }) client!: AppClient; - + {{#if link_from_original_to_each_update}} @property({ hasChanged: (newVal: ActionHash, oldVal: ActionHash) => newVal?.toString() !== oldVal?.toString() @@ -31,14 +29,14 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { original{{pascal_case entry_type.name}}Hash!: ActionHash; {{/if}} - + @property() currentRecord!: Record; - + get current{{pascal_case entry_type.name}}() { return decode((this.currentRecord.entry as any).Present.entry) as {{pascal_case entry_type.name}}; } - + {{#each entry_type.fields}} {{#if widget }} {{#if (not (eq cardinality "vector" ) )}} @@ -56,19 +54,19 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { is{{pascal_case entry_type.name}}Valid() { return true{{#each entry_type.fields}}{{#if widget}}{{#if (eq cardinality "single")}} && {{> (concat field_type.type "/" widget "/is-valid") variable_to_validate=(concat "this._" (camel_case field_name)) }}{{/if}}{{#if (eq cardinality "vector")}} && this._{{camel_case field_name}}.every(e => {{> (concat field_type.type "/" widget "/is-valid") variable_to_validate="e" }}){{/if}}{{/if}}{{/each}}; } - + connectedCallback() { super.connectedCallback(); - if (this.currentRecord === undefined) { + if (!this.currentRecord) { throw new Error(`The currentRecord property is required for the edit-{{kebab_case entry_type.name}} element`); } {{#if link_from_original_to_each_update}} - if (this.original{{pascal_case entry_type.name}}Hash === undefined) { + if (!this.original{{pascal_case entry_type.name}}Hash) { throw new Error(`The original{{pascal_case entry_type.name}}Hash property is required for the edit-{{kebab_case entry_type.name}} element`); } {{/if}} - + {{#each entry_type.fields}} {{#if widget}} this._{{camel_case field_name}} = this.current{{pascal_case ../entry_type.name}}.{{snake_case field_name}}; @@ -77,7 +75,7 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { } async update{{pascal_case entry_type.name}}() { - const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { + const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { {{#each entry_type.fields}} {{#if widget}} {{#if (eq cardinality "single") }} @@ -108,7 +106,7 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { updated_{{snake_case entry_type.name}}: {{camel_case entry_type.name}} }, }); - + this.dispatchEvent(new CustomEvent('{{kebab_case entry_type.name}}-updated', { composed: true, bubbles: true, @@ -120,53 +118,43 @@ export class Edit{{pascal_case entry_type.name}} extends LitElement { updated{{pascal_case entry_type.name}}Hash: updateRecord.signed_action.hashed.hash } })); - } catch (e: any) { - const errorSnackbar = this.shadowRoot?.getElementById('update-error') as Snackbar; - errorSnackbar.labelText = `Error updating the {{lower_case entry_type.name}}: ${e.message}`; - errorSnackbar.show(); + } catch (e) { + alert((e as HolochainError).message); } } render() { return html` - - - -
- Edit {{title_case entry_type.name}} +
{{#each entry_type.fields}} {{#if widget}} -
+
{{#if (not (eq cardinality "vector") )}} {{> (concat field_type.type "/" widget "/edit/render") label=(title_case field_name) variable_to_read=(concat "this._" (camel_case field_name) ) variable_to_change=(concat "this._" (camel_case field_name) ) required=(eq cardinality "single") }} {{else}} {{> Vec/edit/render field_name=field_name field_type=field_type widget=widget }} {{/if}} - -
+ +
{{/if}} {{/each}} - -
- this.dispatchEvent(new CustomEvent('edit-canceled', { +
+ +
-
`; +
+ `; } + + static styles = sharedStyles; } diff --git a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}-detail.ts.hbs b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}-detail.ts.hbs index 4889e0111..d7eedc360 100644 --- a/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}-detail.ts.hbs +++ b/templates/custom-template/custom-template/template/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{kebab_case entry_type.name}}-detail.ts.hbs @@ -1,12 +1,9 @@ import { LitElement, html } from 'lit'; import { state, customElement, property } from 'lit/decorators.js'; -import { EntryHash, Record, ActionHash, AppClient, DnaHash } from '@holochain/client'; +import { EntryHash, Record, ActionHash, AppClient, DnaHash, HolochainError } from '@holochain/client'; import { consume } from '@lit-labs/context'; import { Task } from '@lit-labs/task'; import { decode } from '@msgpack/msgpack'; -import '@material/mwc-icon-button'; -import '@material/mwc-snackbar'; -import { Snackbar } from '@material/mwc-snackbar'; {{#uniq_lines}} {{#each entry_type.fields}} {{#if widget}} @@ -20,6 +17,7 @@ import { Snackbar } from '@material/mwc-snackbar'; import './edit-{{kebab_case entry_type.name}}'; {{/if}} +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; import { {{pascal_case entry_type.name}}{{#each entry_type.fields}}{{#if (eq field_type.type "Enum")}}, {{field_type.label}}{{/if}}{{/each}} } from './types'; @@ -33,7 +31,7 @@ export class {{pascal_case entry_type.name}}Detail extends LitElement { }) {{camel_case entry_type.name}}Hash!: {{#if entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}; - _fetchRecord = new Task(this, ([{{camel_case entry_type.name}}Hash]) => this.client.callZome({ + _fetchRecord = new Task(this, ([{{camel_case entry_type.name}}Hash]: Array<{{#if entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}>) => this.client.callZome({ cap_secret: null, role_name: '{{dna_role_name}}', zome_name: '{{coordinator_zome_manifest.name}}', @@ -42,12 +40,11 @@ export class {{pascal_case entry_type.name}}Detail extends LitElement { }) as Promise, () => [this.{{camel_case entry_type.name}}Hash]); {{#if crud.update}} - @state() - _editing = false; + @state() _editing = false; {{/if}} firstUpdated() { - if (this.{{camel_case entry_type.name}}Hash === undefined) { + if (!this.{{camel_case entry_type.name}}Hash) { throw new Error(`The {{camel_case entry_type.name}}Hash property is required for the {{kebab_case entry_type.name}}-detail element`); } } @@ -70,10 +67,8 @@ export class {{pascal_case entry_type.name}}Detail extends LitElement { } })); this._fetchRecord.run(); - } catch (e: any) { - const errorSnackbar = this.shadowRoot?.getElementById('delete-error') as Snackbar; - errorSnackbar.labelText = `Error deleting the {{lower_case entry_type.name}}: ${e.message}`; - errorSnackbar.show(); + } catch (e) { + alert((e as HolochainError).message) } } {{/if}} @@ -81,70 +76,62 @@ export class {{pascal_case entry_type.name}}Detail extends LitElement { renderDetail(record: Record) { const {{camel_case entry_type.name}} = decode((record.entry as any).Present.entry) as {{pascal_case entry_type.name}}; - return html`{{#if crud.delete}} - - - {{/if}} - -
-
- - - {{#if crud.update}} - { this._editing = true; } }> - {{/if}} - {{#if crud.delete}} - this.delete{{pascal_case entry_type.name}}()}> - {{/if}} -
- + return html` +
{{#each entry_type.fields}} {{#if widget}} {{#if (not (eq cardinality "vector") )}} -
- {{title_case field_name}}: - {{> (concat field_type.type "/" widget "/detail/render") variable_to_read=(concat (camel_case ../entry_type.name) "." (snake_case field_name) ) }} +
+ {{title_case field_name}}: + {{> (concat field_type.type "/" widget "/detail/render") variable_to_read=(concat (camel_case ../entry_type.name) "." (snake_case field_name) ) }}
{{else}} {{> Vec/detail/render variable_to_read=(concat (camel_case ../entry_type.name) "." (snake_case field_name) ) field_name=field_name field_type=field_type widget=widget }} {{/if}} - {{/if}} {{/each}} -
+ +
+{{#if crud.update}} + +{{/if}} +{{#if crud.delete}} + +{{/if}} +
+
`; } render{{pascal_case entry_type.name}}(record: Record | undefined) { - if (!record) return html`The requested {{lower_case entry_type.name}} was not found.`; - + if (!record) return html`
The requested {{lower_case entry_type.name}} was not found.
`; {{#if crud.update}} if (this._editing) { - return html` { - this._editing = false; - await this._fetchRecord.run(); - } } - @edit-canceled=${() => { this._editing = false; } } - style="display: flex; flex: 1;" - >`; + return html` + { + this._editing = false; + await this._fetchRecord.run(); + } } + @edit-canceled=${() => { this._editing = false; } } + > + `; } - {{/if}} return this.renderDetail(record); } render() { return this._fetchRecord.render({ - pending: () => html`
- -
`, + pending: () => html``, complete: (record) => this.render{{pascal_case entry_type.name}}(record), - error: (e: any) => html`Error fetching the {{lower_case entry_type.name}}: ${e.message}` + error: (e: any) => html`
Error fetching the {{lower_case entry_type.name}}: ${e.message}
` }); } -} + + static styles = sharedStyles; +} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/example.instructions.hbs b/templates/custom-template/custom-template/template/example.instructions.hbs index 3ac12f06d..cfdf10efd 100644 --- a/templates/custom-template/custom-template/template/example.instructions.hbs +++ b/templates/custom-template/custom-template/template/example.instructions.hbs @@ -1,6 +1,10 @@ Run the example app with: cd {{example}} - nix develop - npm install - npm start + nix develop + {{(package_manager_command package_manager "install" null)}} + {{(package_manager_command package_manager "start" null)}} + +Generated ui code might also need to be reformatted: + + {{(package_manager_command package_manager "format" "ui")}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/example/ui/src/holochain-app.ts.hbs b/templates/custom-template/custom-template/template/example/ui/src/holochain-app.ts.hbs index fb9c9c9b4..58eee306c 100644 --- a/templates/custom-template/custom-template/template/example/ui/src/holochain-app.ts.hbs +++ b/templates/custom-template/custom-template/template/example/ui/src/holochain-app.ts.hbs @@ -1,75 +1,43 @@ -import { LitElement, css, html } from 'lit'; +import { LitElement, html, css, unsafeCSS } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { AppClient, AppWebsocket } from '@holochain/client'; import { provide } from '@lit-labs/context'; +import sharedStyles from './index.css'; import { clientContext } from './contexts'; import './forum/posts/all-posts'; -import { AllPosts } from './forum/posts/all-posts'; import './forum/posts/create-post'; @customElement('holochain-app') export class HolochainApp extends LitElement { - @state() loading = true; - - @state() result: string | undefined; + @state() loading = false; @provide({ context: clientContext }) @property({ type: Object }) client!: AppClient; async firstUpdated() { - this.client = await AppWebsocket.connect(); - - this.loading = false; + this.loading = true; + try { + this.client = await AppWebsocket.connect(); + } catch(e) { + console.error(e) + } finally { + this.loading = false; + } } render() { - if (this.loading) - return html` - - `; - + if (this.loading) return html``; return html` -
-

Forum

- -
-

All Posts

- - -
-
+
+

Welcome to the Forum hApp

+ + +
`; } - static styles = css` - :host { - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: flex-start; - font-size: calc(10px + 2vmin); - color: #1a2b42; - max-width: 960px; - margin: 0 auto; - text-align: center; - background-color: var(--lit-element-background-color); - } - - main { - flex-grow: 1; - } - - .app-footer { - font-size: calc(12px + 0.5vmin); - align-items: center; - } - - .app-footer a { - margin-left: 5px; - } - `; -} + static styles = css`${unsafeCSS(sharedStyles)}`; +} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/ActionHash/sample.hbs b/templates/custom-template/custom-template/template/field-types/ActionHash/sample.hbs index 62bb9db14..3d318bd7c 100644 --- a/templates/custom-template/custom-template/template/field-types/ActionHash/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/ActionHash/sample.hbs @@ -1 +1 @@ -(await fakeActionHash()) +(await fakeActionHash()) \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/ActionHash/type.hbs b/templates/custom-template/custom-template/template/field-types/ActionHash/type.hbs index a00d2d429..339425a42 100644 --- a/templates/custom-template/custom-template/template/field-types/ActionHash/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/ActionHash/type.hbs @@ -1 +1 @@ -ActionHash +ActionHash \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/AgentPubKey/sample.hbs b/templates/custom-template/custom-template/template/field-types/AgentPubKey/sample.hbs index 98a2ed787..2ad640d28 100644 --- a/templates/custom-template/custom-template/template/field-types/AgentPubKey/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/AgentPubKey/sample.hbs @@ -1 +1 @@ -(await fakeAgentPubKey()) +(await fakeAgentPubKey()) \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/AgentPubKey/type.hbs b/templates/custom-template/custom-template/template/field-types/AgentPubKey/type.hbs index f25075ccb..fe408746c 100644 --- a/templates/custom-template/custom-template/template/field-types/AgentPubKey/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/AgentPubKey/type.hbs @@ -1 +1 @@ -AgentPubKey +AgentPubKey \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/DnaHash/sample.hbs b/templates/custom-template/custom-template/template/field-types/DnaHash/sample.hbs index 9369d2e2b..19e7efd04 100644 --- a/templates/custom-template/custom-template/template/field-types/DnaHash/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/DnaHash/sample.hbs @@ -1 +1 @@ -(await fakeDnaHash()) +(await fakeDnaHash()) \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/DnaHash/type.hbs b/templates/custom-template/custom-template/template/field-types/DnaHash/type.hbs index c0e9d7168..3551c1f2c 100644 --- a/templates/custom-template/custom-template/template/field-types/DnaHash/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/DnaHash/type.hbs @@ -1 +1 @@ -DnaHash +DnaHash \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/EntryHash/sample.hbs b/templates/custom-template/custom-template/template/field-types/EntryHash/sample.hbs index 5f7895b86..f1f27ff28 100644 --- a/templates/custom-template/custom-template/template/field-types/EntryHash/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/EntryHash/sample.hbs @@ -1 +1 @@ -(await fakeEntryHash()) +(await fakeEntryHash()) \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/EntryHash/type.hbs b/templates/custom-template/custom-template/template/field-types/EntryHash/type.hbs index b97d6b80e..9a4e496c5 100644 --- a/templates/custom-template/custom-template/template/field-types/EntryHash/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/EntryHash/type.hbs @@ -1 +1 @@ -EntryHash +EntryHash \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/Select/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/Enum/Select/detail/render.hbs index bfaf687c2..2bdebc1aa 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/Select/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/Select/detail/render.hbs @@ -1 +1 @@ -${ {{#each field_type.variants}}{{#unless @last}} {{../variable_to_read}}.type === '{{pascal_case this}}' ?{{/unless}} `{{title_case this}}`{{#unless @last}} :{{/unless}} {{/each}} } +${ {{#each field_type.variants}}{{#unless @last}} {{../variable_to_read}}.type === '{{pascal_case this}}' ?{{/unless}} `{{title_case this}}`{{#unless @last}} :{{/unless}} {{/each}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/imports.hbs deleted file mode 100644 index 171161339..000000000 --- a/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-select'; diff --git a/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/render.hbs index c1f8d52f4..81534064b 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/Select/edit/render.hbs @@ -1,5 +1,8 @@ - + + \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/Select/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/Enum/Select/initial-value.hbs index 560b9ff7e..214893c2e 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/Select/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/Select/initial-value.hbs @@ -1 +1 @@ -{ type: '{{lookup field_type.variants 0}}' } +{ type: '{{lookup field_type.variants 0}}' } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/Select/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/Enum/Select/is-valid.hbs index 27ba77dda..f32a5804e 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/Select/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/Select/is-valid.hbs @@ -1 +1 @@ -true +true \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/default.hbs b/templates/custom-template/custom-template/template/field-types/Enum/default.hbs new file mode 100644 index 000000000..214893c2e --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/Enum/default.hbs @@ -0,0 +1 @@ +{ type: '{{lookup field_type.variants 0}}' } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/sample.hbs b/templates/custom-template/custom-template/template/field-types/Enum/sample.hbs index 560b9ff7e..214893c2e 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/sample.hbs @@ -1 +1 @@ -{ type: '{{lookup field_type.variants 0}}' } +{ type: '{{lookup field_type.variants 0}}' } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Enum/type.hbs b/templates/custom-template/custom-template/template/field-types/Enum/type.hbs index e9b80fff9..798c93ded 100644 --- a/templates/custom-template/custom-template/template/field-types/Enum/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/Enum/type.hbs @@ -1 +1 @@ -{{pascal_case field_type.label}} +{{pascal_case field_type.label}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextArea/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/String/TextArea/detail/render.hbs index 433f42b69..b82c4a0a1 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextArea/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextArea/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} } +${ {{variable_to_read}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/imports.hbs deleted file mode 100644 index 01d0786c1..000000000 --- a/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-textarea'; diff --git a/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/render.hbs index cd25d12f4..5823114e1 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextArea/edit/render.hbs @@ -1 +1,11 @@ - { {{variable_to_change}} = (e.target as any).value;} } {{#if required}}required{{/if}}> + + \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextArea/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/String/TextArea/initial-value.hbs index a614936fa..942309095 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextArea/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextArea/initial-value.hbs @@ -1 +1 @@ -'' +'' \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextArea/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/String/TextArea/is-valid.hbs index a9e6c9814..e3891233e 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextArea/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextArea/is-valid.hbs @@ -1 +1 @@ -{{variable_to_validate}} !== '' +{{variable_to_validate}} !== '' \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextField/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/String/TextField/detail/render.hbs index 433f42b69..b82c4a0a1 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextField/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextField/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} } +${ {{variable_to_read}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextField/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/String/TextField/edit/imports.hbs deleted file mode 100644 index 0572528d4..000000000 --- a/templates/custom-template/custom-template/template/field-types/String/TextField/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-textfield'; diff --git a/templates/custom-template/custom-template/template/field-types/String/TextField/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/String/TextField/edit/render.hbs index 38869aa15..5311bf73b 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextField/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextField/edit/render.hbs @@ -1 +1,11 @@ - { {{variable_to_change}} = (e.target as any).value; } } {{#if required}}required{{/if}}> + + { {{variable_to_change}} = (e.target as any).value; } } + {{#if required}} + required + {{/if}} +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextField/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/String/TextField/initial-value.hbs index a614936fa..942309095 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextField/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextField/initial-value.hbs @@ -1 +1 @@ -'' +'' \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/TextField/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/String/TextField/is-valid.hbs index a9e6c9814..e3891233e 100644 --- a/templates/custom-template/custom-template/template/field-types/String/TextField/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/TextField/is-valid.hbs @@ -1 +1 @@ -{{variable_to_validate}} !== '' +{{variable_to_validate}} !== '' \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/default.hbs b/templates/custom-template/custom-template/template/field-types/String/default.hbs new file mode 100644 index 000000000..5de6da439 --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/String/default.hbs @@ -0,0 +1 @@ +{{#if (eq cardinality "vector")}}[]{{else}}""{{/if}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/sample.hbs b/templates/custom-template/custom-template/template/field-types/String/sample.hbs index 56b4c51a6..f128f21fd 100644 --- a/templates/custom-template/custom-template/template/field-types/String/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/sample.hbs @@ -1 +1 @@ -"Lorem ipsum dolor sit amet, consectetur adipiscing elit." +"Lorem ipsum dolor sit amet, consectetur adipiscing elit." \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/String/type.hbs b/templates/custom-template/custom-template/template/field-types/String/type.hbs index ee8a39c38..ec186f1f3 100644 --- a/templates/custom-template/custom-template/template/field-types/String/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/String/type.hbs @@ -1 +1 @@ -string +string \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/detail/render.hbs index 537195405..322138be4 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/detail/render.hbs @@ -1 +1 @@ -${new Date({{variable_to_read}} / 1000).toLocaleString() } +${new Date({{variable_to_read}} / 1000).toLocaleString() } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/imports.hbs deleted file mode 100644 index f8705a0ed..000000000 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@vaadin/date-time-picker/theme/material/vaadin-date-time-picker.js'; diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/render.hbs index 6197e2383..97e59e87e 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/edit/render.hbs @@ -1 +1,12 @@ - { {{variable_to_change}} = new Date((e.target as any).value).valueOf() * 1000;} } {{#if required}}required{{/if}}> \ No newline at end of file + + { {{variable_to_change}} = Math.floor(new Date(e.target.value).getTime() / 1000); } } + {{#if required}} + required + {{/if}} +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/initial-value.hbs index 56bfef5d4..e32bcd5fd 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/initial-value.hbs @@ -1 +1 @@ -Date.now() +Date.now() \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/is-valid.hbs index 27ba77dda..f32a5804e 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/DateTimePicker/is-valid.hbs @@ -1 +1 @@ -true +true \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/default.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/default.hbs new file mode 100644 index 000000000..1b4b0c67a --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/default.hbs @@ -0,0 +1 @@ +Date.now() * 1000 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/sample.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/sample.hbs index ed20776b5..e82254249 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/sample.hbs @@ -1 +1 @@ -1674053334548000 +1674053334548000 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Timestamp/type.hbs b/templates/custom-template/custom-template/template/field-types/Timestamp/type.hbs index b67e17aeb..0dfad6f42 100644 --- a/templates/custom-template/custom-template/template/field-types/Timestamp/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/Timestamp/type.hbs @@ -1 +1 @@ -number +number \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Vec/default.hbs b/templates/custom-template/custom-template/template/field-types/Vec/default.hbs new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/Vec/default.hbs @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Vec/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/Vec/detail/render.hbs deleted file mode 100644 index 6b1b24b2b..000000000 --- a/templates/custom-template/custom-template/template/field-types/Vec/detail/render.hbs +++ /dev/null @@ -1,4 +0,0 @@ -
- {{title_case field_name}} - ${ {{variable_to_read}}.map(el => html`{{> (concat field_type.type "/" widget "/detail/render") variable_to_read="el"}}`)} -
diff --git a/templates/custom-template/custom-template/template/field-types/Vec/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/Vec/edit/render.hbs deleted file mode 100644 index 96ec1f455..000000000 --- a/templates/custom-template/custom-template/template/field-types/Vec/edit/render.hbs +++ /dev/null @@ -1,6 +0,0 @@ -
this.requestUpdate()} @change=${() => this.requestUpdate()}> - {{title_case field_name}} - - ${this._{{camel_case field_name}}.map((el, i) => html`{{> (concat field_type.type "/" widget "/edit/render") label="" variable_to_read="el" variable_to_change=(concat "this._" (camel_case field_name) "[i]" ) }} }`)} - { this._{{camel_case field_name}} = [...this._{{camel_case field_name}}, {{> (concat field_type.type "/" widget "/initial-value") field_type=field_type}}]; } }> -
\ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Vec/sample.hbs b/templates/custom-template/custom-template/template/field-types/Vec/sample.hbs new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/Vec/sample.hbs @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/Vec/type.hbs b/templates/custom-template/custom-template/template/field-types/Vec/type.hbs index 1f1899cec..44a00abfa 100644 --- a/templates/custom-template/custom-template/template/field-types/Vec/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/Vec/type.hbs @@ -1 +1 @@ -Array<{{field_type.type}}> +Array<{{field_type.type}}> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/detail/render.hbs index 725742854..dda2fe9b1 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} ? 'Yes' : 'No' } +${ {{variable_to_read}} ? 'Yes' : 'No' } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/imports.hbs deleted file mode 100644 index a8312f198..000000000 --- a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/imports.hbs +++ /dev/null @@ -1,2 +0,0 @@ -import '@material/mwc-checkbox'; -import '@material/mwc-formfield'; diff --git a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/render.hbs index c1a1625fe..3fb668d2b 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/edit/render.hbs @@ -1,3 +1,7 @@ - - { {{variable_to_change}} = (e.target as any).checked;} }> - \ No newline at end of file + + { {{variable_to_change}} = (e.target as any).checked;} } +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/initial-value.hbs index 27ba77dda..02e4a84d6 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/initial-value.hbs @@ -1 +1 @@ -true +false \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/is-valid.hbs index 27ba77dda..f32a5804e 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/Checkbox/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/Checkbox/is-valid.hbs @@ -1 +1 @@ -true +true \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/default.hbs b/templates/custom-template/custom-template/template/field-types/bool/default.hbs new file mode 100644 index 000000000..51b676e7a --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/bool/default.hbs @@ -0,0 +1 @@ +{{#if (eq cardinality "vector")}}[]{{else}}false{{/if}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/sample.hbs b/templates/custom-template/custom-template/template/field-types/bool/sample.hbs index 27ba77dda..02e4a84d6 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/sample.hbs @@ -1 +1 @@ -true +false \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/bool/type.hbs b/templates/custom-template/custom-template/template/field-types/bool/type.hbs index 7b19ee8df..535368032 100644 --- a/templates/custom-template/custom-template/template/field-types/bool/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/bool/type.hbs @@ -1 +1 @@ -boolean +boolean \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/Slider/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/f32/Slider/detail/render.hbs index 433f42b69..b82c4a0a1 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/Slider/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/Slider/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} } +${ {{variable_to_read}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/imports.hbs deleted file mode 100644 index 9c37e9323..000000000 --- a/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-slider'; diff --git a/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/render.hbs index 364300128..99547a15a 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/Slider/edit/render.hbs @@ -1,5 +1,8 @@ -
- {{label}} - - { {{variable_to_change}} = e.detail.value; } }> -
+ + { {{variable_to_change}} = e.detail.value; } } +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/Slider/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/f32/Slider/initial-value.hbs index ba66466c2..171538eb0 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/Slider/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/Slider/initial-value.hbs @@ -1 +1 @@ -0.0 +0.0 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/Slider/is-valid.hbs b/templates/custom-template/custom-template/template/field-types/f32/Slider/is-valid.hbs index 27ba77dda..f32a5804e 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/Slider/is-valid.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/Slider/is-valid.hbs @@ -1 +1 @@ -true +true \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/default.hbs b/templates/custom-template/custom-template/template/field-types/f32/default.hbs new file mode 100644 index 000000000..0039c80a1 --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/f32/default.hbs @@ -0,0 +1 @@ +{{#if (eq cardinality "vector")}}[]{{else}}0.0{{/if}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/sample.hbs b/templates/custom-template/custom-template/template/field-types/f32/sample.hbs index 2eb3c4fe4..ea2303bc0 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/sample.hbs @@ -1 +1 @@ -0.5 +0.5 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/f32/type.hbs b/templates/custom-template/custom-template/template/field-types/f32/type.hbs index b67e17aeb..0dfad6f42 100644 --- a/templates/custom-template/custom-template/template/field-types/f32/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/f32/type.hbs @@ -1 +1 @@ -number +number \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/i32/Slider/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/i32/Slider/detail/render.hbs index 433f42b69..b82c4a0a1 100644 --- a/templates/custom-template/custom-template/template/field-types/i32/Slider/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/i32/Slider/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} } +${ {{variable_to_read}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/imports.hbs deleted file mode 100644 index 9c37e9323..000000000 --- a/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-slider'; diff --git a/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/render.hbs index 136a70331..7ba55ca89 100644 --- a/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/i32/Slider/edit/render.hbs @@ -1,5 +1,7 @@ -
- {{label}} - - { {{variable_to_change}} = e.detail.value; } } discrete> -
+ + { {{variable_to_change}} = e.detail.value; } } +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/i32/default.hbs b/templates/custom-template/custom-template/template/field-types/i32/default.hbs new file mode 100644 index 000000000..16b2eb52b --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/i32/default.hbs @@ -0,0 +1 @@ +{{#if (eq cardinality "vector")}}[]{{else}}0{{/if}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/i32/sample.hbs b/templates/custom-template/custom-template/template/field-types/i32/sample.hbs index 291670352..46b71d470 100644 --- a/templates/custom-template/custom-template/template/field-types/i32/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/i32/sample.hbs @@ -1 +1 @@ --10 +-10 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/i32/type.hbs b/templates/custom-template/custom-template/template/field-types/i32/type.hbs index b67e17aeb..0dfad6f42 100644 --- a/templates/custom-template/custom-template/template/field-types/i32/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/i32/type.hbs @@ -1 +1 @@ -number +number \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/Slider/detail/render.hbs b/templates/custom-template/custom-template/template/field-types/u32/Slider/detail/render.hbs index 433f42b69..b82c4a0a1 100644 --- a/templates/custom-template/custom-template/template/field-types/u32/Slider/detail/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/u32/Slider/detail/render.hbs @@ -1 +1 @@ -${ {{variable_to_read}} } +${ {{variable_to_read}} } \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/imports.hbs b/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/imports.hbs deleted file mode 100644 index 9c37e9323..000000000 --- a/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/imports.hbs +++ /dev/null @@ -1 +0,0 @@ -import '@material/mwc-slider'; diff --git a/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/render.hbs b/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/render.hbs index 136a70331..99547a15a 100644 --- a/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/render.hbs +++ b/templates/custom-template/custom-template/template/field-types/u32/Slider/edit/render.hbs @@ -1,5 +1,8 @@ -
- {{label}} - - { {{variable_to_change}} = e.detail.value; } } discrete> -
+ + { {{variable_to_change}} = e.detail.value; } } +> \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/Slider/initial-value.hbs b/templates/custom-template/custom-template/template/field-types/u32/Slider/initial-value.hbs index 573541ac9..c22708346 100644 --- a/templates/custom-template/custom-template/template/field-types/u32/Slider/initial-value.hbs +++ b/templates/custom-template/custom-template/template/field-types/u32/Slider/initial-value.hbs @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/default.hbs b/templates/custom-template/custom-template/template/field-types/u32/default.hbs new file mode 100644 index 000000000..16b2eb52b --- /dev/null +++ b/templates/custom-template/custom-template/template/field-types/u32/default.hbs @@ -0,0 +1 @@ +{{#if (eq cardinality "vector")}}[]{{else}}0{{/if}} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/sample.hbs b/templates/custom-template/custom-template/template/field-types/u32/sample.hbs index f599e28b8..9a037142a 100644 --- a/templates/custom-template/custom-template/template/field-types/u32/sample.hbs +++ b/templates/custom-template/custom-template/template/field-types/u32/sample.hbs @@ -1 +1 @@ -10 +10 \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/field-types/u32/type.hbs b/templates/custom-template/custom-template/template/field-types/u32/type.hbs index b67e17aeb..0dfad6f42 100644 --- a/templates/custom-template/custom-template/template/field-types/u32/type.hbs +++ b/templates/custom-template/custom-template/template/field-types/u32/type.hbs @@ -1 +1 @@ -number +number \ No newline at end of file diff --git "a/templates/custom-template/custom-template/template/link-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if to_referenceable}}{{kebab_case from_referenceable.name}}-to-{{kebab_case (plural to_referenceable.name)}}.test.ts{{\302\241if}}.hbs" "b/templates/custom-template/custom-template/template/link-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if to_referenceable}}{{kebab_case from_referenceable.name}}-to-{{kebab_case (plural to_referenceable.name)}}.test.ts{{\302\241if}}.hbs" index 902aebe29..84e12c27f 100644 --- "a/templates/custom-template/custom-template/template/link-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if to_referenceable}}{{kebab_case from_referenceable.name}}-to-{{kebab_case (plural to_referenceable.name)}}.test.ts{{\302\241if}}.hbs" +++ "b/templates/custom-template/custom-template/template/link-type/tests/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if to_referenceable}}{{kebab_case from_referenceable.name}}-to-{{kebab_case (plural to_referenceable.name)}}.test.ts{{\302\241if}}.hbs" @@ -1,7 +1,19 @@ import { assert, test } from "vitest"; import { runScenario, dhtSync, CallableCell } from '@holochain/tryorama'; -import { NewEntryAction, ActionHash, Record, Link, SignedActionHashed, CreateLink, DeleteLink, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash } from '@holochain/client'; +import { + NewEntryAction, + ActionHash, + Record, + Link, + CreateLink, + DeleteLink, + SignedActionHashed, + AppBundleSource, + fakeActionHash, + fakeAgentPubKey, + fakeEntryHash +} from '@holochain/client'; import { decode } from '@msgpack/msgpack'; {{#if (ne from_referenceable.hash_type "AgentPubKey")}} diff --git "a/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{kebab_case (plural from_referenceable.name)}}-for-{{kebab_case to_referenceable.name}}.ts{{\302\241if}}.hbs" "b/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{kebab_case (plural from_referenceable.name)}}-for-{{kebab_case to_referenceable.name}}.ts{{\302\241if}}.hbs" index 6341cf723..1ddb2555a 100644 --- "a/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{kebab_case (plural from_referenceable.name)}}-for-{{kebab_case to_referenceable.name}}.ts{{\302\241if}}.hbs" +++ "b/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and bidireccional (and to_referenceable (ne from_referenceable.hash_type 'AgentPubKey')))}}{{kebab_case (plural from_referenceable.name)}}-for-{{kebab_case to_referenceable.name}}.ts{{\302\241if}}.hbs" @@ -3,6 +3,8 @@ import { state, property, customElement } from 'lit/decorators.js'; import { AgentPubKey, Link, EntryHash, ActionHash, Record, AppClient, NewEntryAction, SignalType } from '@holochain/client'; import { consume } from '@lit-labs/context'; import { Task } from '@lit-labs/task'; + +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; import { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; @@ -18,7 +20,7 @@ export class {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to }) {{camel_case to_referenceable.singular_arg}}!: {{to_referenceable.hash_type}}; - _fetch{{pascal_case (plural from_referenceable.name)}} = new Task(this, ([{{camel_case to_referenceable.singular_arg}}]) => this.client.callZome({ + _fetch{{pascal_case (plural from_referenceable.name)}} = new Task(this, ([{{camel_case to_referenceable.singular_arg}}]: Array<{{to_referenceable.hash_type}}>) => this.client.callZome({ cap_secret: null, role_name: '{{dna_role_name}}', zome_name: '{{coordinator_zome_manifest.name}}', @@ -30,12 +32,12 @@ export class {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to signaledHashes: Array<{{from_referenceable.hash_type}}> = []; firstUpdated() { - if (this.{{camel_case to_referenceable.singular_arg}} === undefined) { + if (!this.{{camel_case to_referenceable.singular_arg}}) { throw new Error(`The {{camel_case to_referenceable.singular_arg}} property is required for the {{kebab_case (plural from_referenceable.name)}}-for-{{kebab_case to_referenceable.name}} element`); } - this.client.on('signal', signal => { - if (!(SignalType.App in signal)) return + this.client?.on('signal', signal => { + if (!(SignalType.App in signal)) return; if (signal.App.zome_name !== '{{coordinator_zome_manifest.name}}') return; const payload = signal.App.payload as {{pascal_case coordinator_zome_manifest.name}}Signal; if (payload.type !== 'LinkCreated') return; @@ -46,10 +48,10 @@ export class {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to } renderList(hashes: Array<{{to_referenceable.hash_type}}>) { - if (hashes.length === 0) return html`No {{lower_case (plural from_referenceable.name)}} found for this {{lower_case to_referenceable.name}}`; + if (!hashes.length) return html`
No {{lower_case (plural from_referenceable.name)}} found for this {{lower_case to_referenceable.name}}
`; return html` -
+
${hashes.map(hash => html`<{{kebab_case from_referenceable.name}}-detail .{{camel_case from_referenceable.name}}Hash=${hash} style="margin-bottom: 16px;">` )} @@ -59,11 +61,11 @@ export class {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to render() { return this._fetch{{pascal_case (plural from_referenceable.name)}}.render({ - pending: () => html`
- -
`, + pending: () => html``, complete: (links) => this.renderList([...this.signaledHashes, ...links.map(l => l.target)]), - error: (e: any) => html`Error fetching the {{lower_case (plural from_referenceable.name)}}: ${e.message}.` + error: (e: any) => html`
Error fetching the {{lower_case (plural from_referenceable.name)}}: ${e.message}.
` }); } + + static styles = sharedStyles; } diff --git "a/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}}.ts{{\302\241if}}.hbs" "b/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}}.ts{{\302\241if}}.hbs" index c943123ce..b751dbd6a 100644 --- "a/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}}.ts{{\302\241if}}.hbs" +++ "b/templates/custom-template/custom-template/template/link-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if (and to_referenceable (ne to_referenceable.hash_type 'AgentPubKey'))}}{{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}}.ts{{\302\241if}}.hbs" @@ -4,10 +4,12 @@ import { AgentPubKey, Link, EntryHash, ActionHash, Record, AppClient, NewEntryAc import { consume } from '@lit-labs/context'; import { Task } from '@lit-labs/task'; +import { sharedStyles } from '../../shared-styles'; import { clientContext } from '../../contexts'; -import './{{kebab_case to_referenceable.name}}-detail'; import { {{pascal_case coordinator_zome_manifest.name}}Signal } from './types'; +import './{{kebab_case to_referenceable.name}}-detail'; + @customElement('{{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}}') export class {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}} extends LitElement { @consume({ context: clientContext }) @@ -21,7 +23,7 @@ export class {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from @state() signaledHashes: Array<{{to_referenceable.hash_type}}> = []; - _fetch{{pascal_case (plural to_referenceable.name)}} = new Task(this, ([{{camel_case from_referenceable.singular_arg}}]) => this.client.callZome({ + _fetch{{pascal_case (plural to_referenceable.name)}} = new Task(this, ([{{camel_case from_referenceable.singular_arg}}]: Array<{{from_referenceable.hash_type}}>) => this.client.callZome({ cap_secret: null, role_name: '{{dna_role_name}}', zome_name: '{{coordinator_zome_manifest.name}}', @@ -30,12 +32,12 @@ export class {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from }) as Promise>, () => [this.{{camel_case from_referenceable.singular_arg}}]); firstUpdated() { - if (this.{{camel_case from_referenceable.singular_arg}} === undefined) { + if (!this.{{camel_case from_referenceable.singular_arg}}) { throw new Error(`The {{camel_case from_referenceable.singular_arg}} property is required for the {{kebab_case (plural to_referenceable.name)}}-for-{{kebab_case from_referenceable.name}} element`); } - this.client.on('signal', signal => { - if (!(SignalType.App in signal)) return; + this.client?.on('signal', signal => { + if (!(SignalType.App in signal)) return if (signal.App.zome_name !== '{{coordinator_zome_manifest.name}}') return; const payload = signal.App.payload as {{pascal_case coordinator_zome_manifest.name}}Signal; if (payload.type !== 'LinkCreated') return; @@ -46,10 +48,10 @@ export class {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from } renderList(hashes: Array<{{to_referenceable.hash_type}}>) { - if (hashes.length === 0) return html`No {{lower_case (plural to_referenceable.name)}} found for this {{lower_case from_referenceable.name}}`; + if (!hashes.length) return html`
No {{lower_case (plural to_referenceable.name)}} found for this {{lower_case from_referenceable.name}}
`; return html` -
+
${hashes.map(hash => html`<{{kebab_case to_referenceable.name}}-detail .{{camel_case to_referenceable.name}}Hash=${hash} style="margin-bottom: 16px;">` )} @@ -59,11 +61,11 @@ export class {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from render() { return this._fetch{{pascal_case (plural to_referenceable.name)}}.render({ - pending: () => html`
- -
`, + pending: () => html``, complete: (links) => this.renderList([...this.signaledHashes, ...links.map(l => l.target)]), - error: (e: any) => html`Error fetching the {{lower_case (plural to_referenceable.name)}}: ${e.message}.` + error: (e: any) => html`
Error fetching the {{lower_case (plural to_referenceable.name)}}: ${e.message}.
` }); } -} + + static styles = sharedStyles; +} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/web-app/.github/workflows/test.yaml.hbs b/templates/custom-template/custom-template/template/web-app/.github/workflows/test.yaml.hbs index 5c88e3c50..08bccaa26 100644 --- a/templates/custom-template/custom-template/template/web-app/.github/workflows/test.yaml.hbs +++ b/templates/custom-template/custom-template/template/web-app/.github/workflows/test.yaml.hbs @@ -1,6 +1,6 @@ name: "test" on: - push: + push: branches: [ main ] pull_request: branches: [ main ] @@ -22,4 +22,4 @@ jobs: - name: Install and test run: | - nix develop --command bash -c "npm i && npm t" + nix develop --command bash -c "{{(package_manager_command package_manager "install" null)}} && {{(package_manager_command package_manager "test" null)}}" diff --git a/templates/custom-template/custom-template/template/web-app/README.md.hbs b/templates/custom-template/custom-template/template/web-app/README.md.hbs index 5274b8049..0164034bc 100644 --- a/templates/custom-template/custom-template/template/web-app/README.md.hbs +++ b/templates/custom-template/custom-template/template/web-app/README.md.hbs @@ -8,7 +8,7 @@ Enter the nix shell by running this in the root folder of the repository: ```bash nix develop -npm install +{{(package_manager_command package_manager "install" null)}} ``` **Run all the other instructions in this README from inside this nix shell, otherwise they won't work**. @@ -16,7 +16,7 @@ npm install ## Running 2 agents ```bash -npm start +{{(package_manager_command package_manager "start" null)}} ``` This will create a network of 2 nodes connected to each other and their respective UIs. @@ -25,7 +25,7 @@ It will also bring up the Holochain Playground for advanced introspection of the ## Running the backend tests ```bash -npm test +{{(package_manager_command package_manager "test" null)}} ``` ## Bootstrapping a network @@ -33,7 +33,7 @@ npm test Create a custom network of nodes connected to each other and their respective UIs with: ```bash -AGENTS=3 npm run network +AGENTS=3 {{(package_manager_command package_manager "network" null)}} ``` Substitute the "3" for the number of nodes that you want to bootstrap in your network. @@ -43,7 +43,7 @@ This will also bring up the Holochain Playground for advanced introspection of t To package the web happ: ``` bash -npm run package +{{(package_manager_command package_manager "package" null)}} ``` You'll have the `{{app_name}}.webhapp` in `workdir`. This is what you should distribute so that the Holochain Launcher can install it. diff --git a/templates/custom-template/custom-template/template/web-app/flake.nix.hbs b/templates/custom-template/custom-template/template/web-app/flake.nix.hbs deleted file mode 100644 index 155c7c0ff..000000000 --- a/templates/custom-template/custom-template/template/web-app/flake.nix.hbs +++ /dev/null @@ -1,17 +0,0 @@ -{{#merge previous_file_content}} - {{#match_scope "inputs = {"}} - {{previous_scope_content}} - - scaffolding.url = "github:"; - {{/match_scope}} - {{#match_scope "devShells.default = pkgs.mkShell {"}} - - inputsFrom = [ inputs'.holochain-flake.devShells.holonix ]; - - packages = with pkgs; [ - nodejs_20 - ] ++ [ - inputs'.scaffolding.packages.hc-scaffold-custom-template - ]; - {{/match_scope}} -{{/merge}} diff --git a/templates/custom-template/custom-template/template/web-app/package.json.hbs b/templates/custom-template/custom-template/template/web-app/package.json.hbs index 8503102b0..19ec6e52f 100644 --- a/templates/custom-template/custom-template/template/web-app/package.json.hbs +++ b/templates/custom-template/custom-template/template/web-app/package.json.hbs @@ -6,33 +6,35 @@ "tests" ], "scripts": { - "start": "AGENTS=2 BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) npm run network", - "network": "hc sandbox clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run launch:happ\" \"holochain-playground\"", - "test": "npm run build:zomes && hc app pack workdir --recursive && npm t -w tests", + "start": "AGENTS=${AGENTS:-2} BOOTSTRAP_PORT=$(get-port) SIGNAL_PORT=$(get-port) {{(package_manager_command package_manager "network" null)}}", + "network": "hc sandbox clean && {{(package_manager_command package_manager "build:happ" null)}} && UI_PORT=$(get-port) concurrently \"{{(package_manager_command package_manager "start" "ui")}}\" \"{{(package_manager_command package_manager "launch:happ" null)}}\" \"holochain-playground\"", + "test": "{{(package_manager_command package_manager "build:zomes" null)}} && hc app pack workdir --recursive && {{(package_manager_command package_manager "test" "tests")}}", "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT workdir/{{app_name}}.happ", - "start:tauri": "AGENTS=2 BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) npm run network:tauri", - "network:tauri": "hc sandbox clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run launch:tauri\" \"holochain-playground\"", + "start:tauri": "AGENTS=${AGENTS:-2} BOOTSTRAP_PORT=$(get-port) SIGNAL_PORT=$(get-port) {{(package_manager_command package_manager "network:tauri" null)}}", + "network:tauri": "hc sandbox clean && {{(package_manager_command package_manager "build:happ" null)}} && UI_PORT=$(get-port) concurrently \"{{(package_manager_command package_manager "start" "ui")}}\" \"{{(package_manager_command package_manager "launch:tauri" null)}}\" \"holochain-playground\"", "launch:tauri": "concurrently \"hc run-local-services --bootstrap-port $BOOTSTRAP_PORT --signal-port $SIGNAL_PORT\" \"echo pass | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/{{app_name}}.happ --ui-port $UI_PORT network --bootstrap http://127.0.0.1:\"$BOOTSTRAP_PORT\" webrtc ws://127.0.0.1:\"$SIGNAL_PORT\"\"", {{#if holo_enabled}} - "start:holo": "AGENTS=2 npm run network:holo", - "network:holo": "npm run build:happ && UI_PORT=8888 concurrently \"npm run launch:holo-dev-server\" \"holochain-playground ws://localhost:4444\" \"concurrently-repeat 'VITE_APP_CHAPERONE_URL=http://localhost:24274 VITE_APP_IS_HOLO=true npm start -w ui' $AGENTS\"", + "start:holo": "AGENTS=${AGENTS:-2} {{(package_manager_command package_manager "network:holo" null)}}", + "network:holo": "{{(package_manager_command package_manager "build:happ" null)}} && UI_PORT=$(get-port) concurrently \"{{(package_manager_command package_manager "launch:holo-dev-server" null)}}\" \"holochain-playground ws://localhost:4444\" \"concurrently-repeat 'VITE_APP_CHAPERONE_URL=http://localhost:24274 VITE_APP_IS_HOLO=true {{(package_manager_command package_manager "start" "ui")}}' $AGENTS\"", "launch:holo-dev-server": "holo-dev-server workdir/{{app_name}}.happ", {{/if}} - "package": "npm run build:happ && npm run package -w ui && hc web-app pack workdir --recursive", - "build:happ": "npm run build:zomes && hc app pack workdir --recursive", - "build:zomes": "RUSTFLAGS='' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown" + {{#if (eq package_manager "pnpm")}} + "postinstall": "node ./node_modules/.pnpm/node_modules/electron/install.js", + {{/if}} + "package": "{{(package_manager_command package_manager "build:happ" null)}} && {{(package_manager_command package_manager "package" "ui")}} && hc web-app pack workdir --recursive", + "build:happ": "{{(package_manager_command package_manager "build:zomes" null)}} && hc app pack workdir --recursive", + "build:zomes": "cargo build --release --target wasm32-unknown-unknown" }, "devDependencies": { "@holochain-playground/cli": "{{holochain_playground_cli_version}}", "@holochain/hc-spin": "{{hc_spin_version}}", "concurrently": "^6.2.1", - "rimraf": "^5.0.7", {{#if holo_enabled}} "concurrently-repeat": "^0.0.1", {{/if}} - "new-port-cli": "^1.0.0" + "get-port-cli": "^3.0.0" }, "engines": { - "npm": ">=7.0.0" + "node": ">=16.0.0" } } diff --git a/templates/custom-template/custom-template/template/web-app/tests/package.json.hbs b/templates/custom-template/custom-template/template/web-app/tests/package.json.hbs index 8821314bc..59bce775a 100644 --- a/templates/custom-template/custom-template/template/web-app/tests/package.json.hbs +++ b/templates/custom-template/custom-template/template/web-app/tests/package.json.hbs @@ -1,5 +1,6 @@ { "name": "tests", + "version": "0.1.0", "private": true, "scripts": { "test": "vitest run" diff --git a/templates/custom-template/custom-template/template/web-app/tests/vitest.config.ts.hbs b/templates/custom-template/custom-template/template/web-app/tests/vitest.config.ts.hbs index 7737dbd2a..ed926ca6b 100644 --- a/templates/custom-template/custom-template/template/web-app/tests/vitest.config.ts.hbs +++ b/templates/custom-template/custom-template/template/web-app/tests/vitest.config.ts.hbs @@ -6,4 +6,3 @@ export default defineConfig({ testTimeout: 60*1000*3 // 3 mins }, }) - diff --git a/templates/custom-template/custom-template/template/web-app/ui/index.html.hbs b/templates/custom-template/custom-template/template/web-app/ui/index.html.hbs index dc24b0de7..f38b7af12 100644 --- a/templates/custom-template/custom-template/template/web-app/ui/index.html.hbs +++ b/templates/custom-template/custom-template/template/web-app/ui/index.html.hbs @@ -8,30 +8,10 @@ /> - - - - {{title_case app_name}} - - diff --git a/templates/custom-template/custom-template/template/web-app/ui/package.json.hbs b/templates/custom-template/custom-template/template/web-app/ui/package.json.hbs index 4696d4658..61c0fcf8f 100644 --- a/templates/custom-template/custom-template/template/web-app/ui/package.json.hbs +++ b/templates/custom-template/custom-template/template/web-app/ui/package.json.hbs @@ -6,11 +6,11 @@ "build": "vite build", {{#if holo_enabled}} "build:holo": "VITE_APP_IS_HOLO=true vite build", - "package:holo": "npm run build:holo && rimraf dist.zip && cd dist && bestzip ../dist.zip *", + "package:holo": "{{(package_manager_command package_manager "build:holo" null)}} && rimraf dist.zip && cd dist && bestzip ../dist.zip *", {{/if}} "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore", "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore", - "package": "npm run build && rimraf dist.zip && cd dist && bestzip ../dist.zip *" + "package": "{{(package_manager_command package_manager "build" null)}} && rimraf dist.zip && cd dist && bestzip ../dist.zip *" }, "dependencies": { "@holochain/client": "{{holochain_client_version}}", @@ -19,18 +19,7 @@ {{/if}} "@lit-labs/context": "^0.2.0", "@lit-labs/task": "^2.0.0", - "@material/mwc-circular-progress": "^0.27.0", - "@material/mwc-button": "^0.27.0", - "@material/mwc-textfield": "^0.27.0", - "@material/mwc-textarea": "^0.27.0", - "@material/mwc-checkbox": "^0.27.0", - "@material/mwc-slider": "^0.27.0", - "@material/mwc-icon-button": "^0.27.0", - "@material/mwc-select": "^0.27.0", - "@material/mwc-snackbar": "^0.27.0", - "@material/mwc-formfield": "^0.27.0", "@msgpack/msgpack": "^2.8.0", - "@vaadin/date-time-picker": "^23.2.8", "lit": "^2.6.1" }, "devDependencies": { @@ -44,7 +33,8 @@ "rimraf": "^5.0.7", "vite": "^4.0.0", "vite-plugin-checker": "^0.5.3", - "typescript": "^4.5.5" + "typescript": "^4.5.5", + "tslib": "^2.6.3" }, "eslintConfig": { "parser": "@typescript-eslint/parser", @@ -60,7 +50,11 @@ "prefer-destructuring": "off", "no-useless-constructor": "off", "no-empty-function": "off", + "no-nested-ternary": "off", "no-empty-pattern": "off", + "no-console": "off", + "no-alert": "off", + "no-param-reassign": "off", "camelcase": "off", "import/no-duplicates": "off", "no-unused-vars": "off", diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/assets/holochainLogo.svg.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/assets/holochainLogo.svg.hbs new file mode 100644 index 000000000..d5b87c953 --- /dev/null +++ b/templates/custom-template/custom-template/template/web-app/ui/src/assets/holochainLogo.svg.hbs @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/contexts.ts.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/contexts.ts.hbs index 1722ea941..e947aaaf0 100644 --- a/templates/custom-template/custom-template/template/web-app/ui/src/contexts.ts.hbs +++ b/templates/custom-template/custom-template/template/web-app/ui/src/contexts.ts.hbs @@ -1,5 +1,4 @@ import { createContext } from '@lit-labs/context'; import { AppClient } from '@holochain/client'; -export const clientContext = createContext('AppClient'); - +export const clientContext = createContext('AppClient'); \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/declarations.d.ts.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/declarations.d.ts.hbs new file mode 100644 index 000000000..bf581f294 --- /dev/null +++ b/templates/custom-template/custom-template/template/web-app/ui/src/declarations.d.ts.hbs @@ -0,0 +1,9 @@ +declare module '*.svg' { + const content: string; + export default content; +} + +declare module '*.css' { + const content: string; + export default content; +} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/holochain-app.ts.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/holochain-app.ts.hbs index f49bf140e..59a6ffcba 100644 --- a/templates/custom-template/custom-template/template/web-app/ui/src/holochain-app.ts.hbs +++ b/templates/custom-template/custom-template/template/web-app/ui/src/holochain-app.ts.hbs @@ -1,19 +1,14 @@ -import { LitElement, css, html } from 'lit'; +import { LitElement, html, css } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -import { - AppWebsocket, - ActionHash, - AppClient, -} from '@holochain/client'; +import { AppWebsocket, ActionHash, AppClient, HolochainError } from '@holochain/client'; {{#if holo_enabled}} import WebSdk from '@holo-host/web-sdk' import type { AgentState } from '@holo-host/web-sdk'; {{/if}} import { provide } from '@lit-labs/context'; -{{#if holo_enabled}} -import '@material/mwc-button'; -{{/if}} +import { sharedStyles } from './shared-styles'; +import HolochainLogo from "./assets/holochainLogo.svg"; import { clientContext } from './contexts'; {{#if holo_enabled}} @@ -22,37 +17,50 @@ const IS_HOLO = ['true', '1', 't'].includes(import.meta.env.VITE_APP_IS_HOLO?.to @customElement('holochain-app') export class HolochainApp extends LitElement { - @state() loading = true; + @state() loading = false; + + @state() + error: HolochainError | undefined; @provide({ context: clientContext }) @property({ type: Object }) client!: AppClient; async firstUpdated() { - {{#if holo_enabled}} - if (IS_HOLO) { - const client = await WebSdk.connect({ - chaperoneUrl: import.meta.env.VITE_APP_CHAPERONE_URL, - authFormCustomization: { - appName: '{{app_name}}', - } - }); - - client.on('agent-state', (agent_state: AgentState) => { - this.loading = !agent_state.isAvailable || agent_state.isAnonymous; - }); - - client.signUp({ cancellable: false }); - this.client = client; - - } else { + this.loading = true; +{{#if holo_enabled}} + try { + if (IS_HOLO) { + const client = await WebSdk.connect({ + chaperoneUrl: import.meta.env.VITE_APP_CHAPERONE_URL, + authFormCustomization: { + appName: '{{app_name}}', + } + }); + + client.on('agent-state', (agent_state: AgentState) => { + this.loading = !agent_state.isAvailable || agent_state.isAnonymous; + }); + + client.signUp({ cancellable: false }); + this.client = client; + } else { + this.client = await AppWebsocket.connect(); + } + } catch(e) { + this.error = e as HolochainError; + } finally { + this.loading = false; + } +{{else}} + try { this.client = await AppWebsocket.connect(); + } catch(e) { + this.error = e as HolochainError; + } finally { this.loading = false; } - {{else}} - this.client = await AppWebsocket.connect(); - this.loading = false; - {{/if}} +{{/if}} } {{#if holo_enabled}} @@ -63,73 +71,55 @@ export class HolochainApp extends LitElement { {{/if}} render() { - if (this.loading) - return html` - - `; - + if (this.loading) return html``; return html` -
-

{{title_case app_name}}

- -
-

EDIT ME! Add the components of your app here.

- - Look in the ui/src/DNA/ZOME folders for UI elements that are generated with hc scaffold entry-type, hc scaffold collection and hc scaffold link-type and add them here as appropriate. - - For example, if you have scaffolded a "todos" dna, a "todos" zome, a "todo_item" entry type, and a collection called "all_todos", you might want to add an element here to create and list your todo items, with the generated ui/src/todos/todos/all-todos.ts and ui/src/todos/todos/create-todo.ts elements. - - So, to use those elements here: -
    -
  1. Import the elements with: -
    -import './todos/todos/all-todos';
    -import './todos/todos/create-todo';
    -              
    -
  2. -
  3. Replace this "EDIT ME!" section with <create-todo></create-todo><all-todos></all-todos>.
  4. -
+
+
+ + + +
+

Holochain Lit hApp

+
+
+ ${this.loading ? html`

connecting...

` : ''} + ${this.error ? html`

${this.error.message}

` : html`

Client is connected.

`} +
+

Import scaffolded components into src/holochain-app.ts to use your hApp

+

Click on the Holochain logo to learn more

- {{#if holo_enabled}} - ${IS_HOLO ? html` - this.logout()} - > - `: ''} - {{/if}} -
+{{#if holo_enabled}} + ${IS_HOLO ? html``: ''} +{{/if}} +
`; } static styles = css` - :host { - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: flex-start; - font-size: calc(10px + 2vmin); - color: #1a2b42; - max-width: 960px; - margin: 0 auto; - text-align: center; - background-color: var(--lit-element-background-color); + ${sharedStyles} + + .logo { + height: 15em; + padding: 1.5em; + will-change: filter; + transition: filter 300ms; + width: auto; + } + + .logo:hover { + filter: drop-shadow(0 0 2em #646cffaa); } - main { - flex-grow: 1; + .logo.holochain:hover { + filter: drop-shadow(0 0 2em #61dafbaa); } - .app-footer { - font-size: calc(12px + 0.5vmin); - align-items: center; + .card { + padding: 2em; } - .app-footer a { - margin-left: 5px; + .read-the-docs { + color: #888; } `; -} +} \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/index.css.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/index.css.hbs new file mode 100644 index 000000000..9cb3efd2c --- /dev/null +++ b/templates/custom-template/custom-template/template/web-app/ui/src/index.css.hbs @@ -0,0 +1,261 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + justify-content: center; + text-align: center; + align-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} + +label { + display: block; + margin-bottom: 0.5em; + font-weight: 500; +} + +input { + display: block; + width: 540px; + padding: 0.75em; + margin: 0.5em 0; + border: 1px solid #ccc; + border-radius: 4px; + font-family: inherit; + font-size: 1em; + color: inherit; + background-color: #2c2c2c; + transition: border-color 0.25s, box-shadow 0.25s; +} + +input[type="checkbox"] { + display: inline-block; + width: auto; + margin-bottom: 1em; + transform: scale(1.5); + margin-right: 0.5em; + vertical-align: middle; +} + +input:focus { + outline: none; + border-color: #646cff; + box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.2); +} + +textarea { + display: block; + width: 540px; + height: 150px; + padding: 0.75em; + margin: 0.5em 0; + border: 1px solid #ccc; + border-radius: 4px; + font-family: inherit; + font-size: 1em; + color: inherit; + background-color: #2c2c2c; + transition: border-color 0.25s, box-shadow 0.25s; + resize: none; +} + +textarea:focus { + outline: none; + border-color: #646cff; + box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.2); +} + +@media (prefers-color-scheme: light) { + input, + textarea { + background-color: #ffffff; + border-color: #ccc; + } + + input:focus, + textarea:focus { + border-color: #646cff; + box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.2); + } +} + +select { + display: block; + width: 566px; + padding: 0.75em; + margin: 1em 0; + border: 1px solid #ccc; + border-radius: 4px; + font-family: inherit; + font-size: 1em; + color: inherit; + background-color: #2c2c2c; + transition: border-color 0.25s, box-shadow 0.25s; +} + +select:focus { + outline: none; + border-color: #646cff; + box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.2); +} + +@media (prefers-color-scheme: light) { + select { + background-color: #ffffff; + border-color: #ccc; + } + + select:focus { + border-color: #646cff; + box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.2); + } +} + +.alert { + font-size: 1.2em; + font-weight: bold; + color: rgba(255, 255, 255, 0.87); + text-align: center; + padding: 2rem; + background-color: #333333; + border: 1px solid #555555; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + margin: 1rem auto; + max-width: 500px; +} + +section { + padding: 2rem; + margin: 1rem 0; + background-color: #333333; + border: 1px solid #555555; + border-radius: 8px; + box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); + transition: transform 0.3s, box-shadow 0.3s; + max-width: 500px; +} + +section:hover { + transform: translateY(-5px); + box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4); +} + +section div { + margin-bottom: 1.5rem; + padding: 1rem; + background-color: #444444; + border: 1px solid #666666; + border-radius: 4px; +} + +section input { + width: 440px; +} + +section select { + width: 464px; +} + +section textarea { + width: 440px; +} + +section div:last-child { + margin-bottom: 0; +} + +section p, +section span { + margin: 0; + font-size: 1em; + line-height: 1.6; + color: rgba(255, 255, 255, 0.87); +} + +section div:has(button) { + display: flex; + justify-content: space-between; + align-items: center; +} + +progress { + width: 100%; + height: 1.5em; +} + +progress::-webkit-progress-bar { + background-color: #444444; + border-radius: 8px; +} + +progress::-webkit-progress-value { + background-color: #646cff; + border-radius: 8px; +} + +progress::-moz-progress-bar { + background-color: #646cff; + border-radius: 8px; +} diff --git a/templates/custom-template/custom-template/template/web-app/ui/src/shared-styles.ts.hbs b/templates/custom-template/custom-template/template/web-app/ui/src/shared-styles.ts.hbs new file mode 100644 index 000000000..5080ba072 --- /dev/null +++ b/templates/custom-template/custom-template/template/web-app/ui/src/shared-styles.ts.hbs @@ -0,0 +1,4 @@ +import { css, unsafeCSS } from 'lit'; +import styles from './index.css'; + +export const sharedStyles = css`${unsafeCSS(styles)}`; \ No newline at end of file diff --git a/templates/custom-template/custom-template/template/web-app/ui/vite.config.ts.hbs b/templates/custom-template/custom-template/template/web-app/ui/vite.config.ts.hbs index 51c6f7ccc..b8181d30d 100644 --- a/templates/custom-template/custom-template/template/web-app/ui/vite.config.ts.hbs +++ b/templates/custom-template/custom-template/template/web-app/ui/vite.config.ts.hbs @@ -1,7 +1,6 @@ import { defineConfig } from 'vite'; import checker from 'vite-plugin-checker'; -// https://vitejs.dev/config/ export default defineConfig({ plugins: [ checker({