Skip to content

Commit

Permalink
feat: Allow to hide some component inside the b64-playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanoa committed Sep 9, 2022
1 parent 260aa4a commit d39d793
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
11 changes: 10 additions & 1 deletion demo/playground-b64.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ <h1>demo biscuit</h1>
}
</style>

<bc-datalog-playground-b64 showBlocks="true" fromHash="eyJhdXRob3JpemVyIjoiY2hlY2sgaWYgdXNlcigxMik7XG5hbGxvdyBpZiB0cnVlOyIsImJsb2NrcyI6W3siY29kZSI6InVzZXIoMTIpOyIsImV4dGVybmFsS2V5IjpudWxsfV19">
<bc-datalog-playground-b64 displayFacts="false" showBlocks="true" fromHash="eyJhdXRob3JpemVyIjoiY2hlY2sgaWYgdXNlcigxMik7XG5hbGxvdyBpZiB0cnVlOyIsImJsb2NrcyI6W3siY29kZSI6InVzZXIoMTIpOyIsImV4dGVybmFsS2V5IjpudWxsfV19">

</bc-datalog-playground-b64>


<bc-datalog-playground-b64 displayFacts="true" showBlocks="true" fromHash="eyJhdXRob3JpemVyIjoiY2hlY2sgaWYgdXNlcigxMik7XG5hbGxvdyBpZiB0cnVlOyIsImJsb2NrcyI6W3siY29kZSI6InVzZXIoMTIpOyIsImV4dGVybmFsS2V5IjpudWxsfV19">

</bc-datalog-playground-b64>

<bc-datalog-playground-b64 displayFacts="true" displayExternalKeys="true" showBlocks="true" fromHash="eyJhdXRob3JpemVyIjoiY2hlY2sgaWYgdXNlcigxMik7XG5hbGxvdyBpZiB0cnVlOyIsImJsb2NrcyI6W3siY29kZSI6InVzZXIoMTIpOyIsImV4dGVybmFsS2V5IjpudWxsfV19">

</bc-datalog-playground-b64>

Expand Down
29 changes: 22 additions & 7 deletions src/bc-datalog-playground-base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
export class BCDatalogPlayground extends LitElement {
@property() fromHash = null;
@property() showBlocks = false;
@property() displayFacts = false;
@property() displayExternalKeys = false;
@state() code = "";
@state() blocks: Array<{ code: string; externalKey: string | null }> = [];
@state() private started = false;
Expand Down Expand Up @@ -67,6 +69,14 @@ export class BCDatalogPlayground extends LitElement {
console.log(newval)
this.showBlocks = newval === "true";
}

if (name === "displayfacts") {
this.displayFacts = newval === "true";
}

if (name === "displayexternalkeys") {
this.displayExternalKeys = newval === "true";
}
}

addBlock() {
Expand Down Expand Up @@ -141,28 +151,33 @@ export class BCDatalogPlayground extends LitElement {
) ?? [];
}


const factContent = html`<p>Facts</p>
<bc-authorizer-content
.content=${authorizer_world}
></bc-authorizer-content>`;

const facts = this.displayFacts ? factContent : html``;

return html`
${this.renderBlocks(markers.blocks, parseErrors.blocks)}
${this.renderAuthorizer(markers.authorizer, parseErrors.authorizer)}
<p>Result</p>
<bc-authorizer-result .content=${authorizer_result}>
</bc-authorizer-result>
<p>Facts</p>
<bc-authorizer-content
.content=${authorizer_world}
></bc-authorizer-content>
${facts}
`;
}

renderExternalKeyInput(blockId: number) {
if (blockId <= 0) return;

return html`
return this.displayExternalKeys ? html`:
<input
@input=${(e: InputEvent) => this.onUpdatedExternalKey(blockId, e)}
value=${this.blocks[blockId].externalKey}
/>
`;
` : html``;
}

renderBlock(
Expand All @@ -174,7 +189,7 @@ export class BCDatalogPlayground extends LitElement {
return html`
<p>${
blockId == 0 ? "Authority block" : "Block " + blockId
}: ${this.renderExternalKeyInput(blockId)}</p>
} ${this.renderExternalKeyInput(blockId)}</p>
<bc-datalog-editor
datalog=${code}
.markers=${markers ?? []}
Expand Down

0 comments on commit d39d793

Please sign in to comment.