Skip to content

Commit

Permalink
Run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
naschmitz committed Nov 6, 2024
1 parent 04da42b commit 1e183d1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 49 deletions.
9 changes: 5 additions & 4 deletions js/ipywidgets_styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export const legacyStyles = css`
.legacy-button:hover:enabled,
.legacy-button:focus:enabled {
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, var(--md-shadow-key-penumbra-opacity)),
0 3px 1px -2px rgba(0, 0, 0, var(--md-shadow-key-umbra-opacity)),
0 1px 5px 0 rgba(0, 0, 0, var(--md-shadow-ambient-shadow-opacity));
box-shadow: 0 2px 2px 0
rgba(0, 0, 0, var(--md-shadow-key-penumbra-opacity)),
0 3px 1px -2px rgba(0, 0, 0, var(--md-shadow-key-umbra-opacity)),
0 1px 5px 0 rgba(0, 0, 0, var(--md-shadow-ambient-shadow-opacity));
}
.legacy-slider {
Expand Down Expand Up @@ -55,4 +56,4 @@ export const legacyStyles = css`
height: var(--jp-widgets-inline-height);
line-height: var(--jp-widgets-inline-height);
}
`;
`;
16 changes: 12 additions & 4 deletions js/layer_manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { AnyModel, RenderProps } from "@anywidget/types";
import { html, css, LitElement } from "lit";
import { property } from "lit/decorators.js";
import { legacyStyles } from './ipywidgets_styles';

import { legacyStyles } from "./ipywidgets_styles";
import { loadFonts, updateChildren } from "./utils";

export interface LayerManagerModel {
Expand Down Expand Up @@ -35,7 +36,10 @@ export class LayerManager extends LitElement {
];

private _model: AnyModel<LayerManagerModel> | undefined = undefined;
private static modelNameToViewName = new Map<keyof LayerManagerModel, keyof LayerManager | null>([
private static modelNameToViewName = new Map<
keyof LayerManagerModel,
keyof LayerManager | null
>([
["children", null],
["visible", "visible"],
]);
Expand Down Expand Up @@ -67,7 +71,9 @@ export class LayerManager extends LitElement {
.checked="${this.visible}"
@change="${this.onLayerVisibilityChanged}"
/>
<span class="legacy-text all-layers-text">All layers on/off</span>
<span class="legacy-text all-layers-text"
>All layers on/off</span
>
</div>
<slot></slot>
</div>
Expand Down Expand Up @@ -95,7 +101,9 @@ if (!customElements.get(LayerManager.componentName)) {

async function render({ model, el }: RenderProps<LayerManagerModel>) {
loadFonts();
const manager = <LayerManager>document.createElement(LayerManager.componentName);
const manager = <LayerManager>(
document.createElement(LayerManager.componentName)
);
manager.model = model;
el.appendChild(manager);

Expand Down
74 changes: 46 additions & 28 deletions js/layer_manager_row.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { AnyModel, RenderProps } from "@anywidget/types";
import { html, css, LitElement, TemplateResult, nothing } from "lit";
import { property } from "lit/decorators.js";
import { classMap } from 'lit/directives/class-map.js';
import { classMap } from "lit/directives/class-map.js";

import { legacyStyles } from './ipywidgets_styles';
import { legacyStyles } from "./ipywidgets_styles";
import { materialStyles } from "./material_styles";
import { loadFonts } from "./utils";

Expand Down Expand Up @@ -62,13 +62,21 @@ export class LayerManagerRow extends LitElement {
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
button.loading .spinner,
Expand All @@ -95,7 +103,10 @@ export class LayerManagerRow extends LitElement {
];

private _model: AnyModel<LayerManagerRowModel> | undefined = undefined;
private static modelNameToViewName = new Map<keyof LayerManagerRowModel, keyof LayerManagerRow | null>([
private static modelNameToViewName = new Map<
keyof LayerManagerRowModel,
keyof LayerManagerRow | null
>([
["name", "name"],
["visible", "visible"],
["opacity", "opacity"],
Expand All @@ -104,7 +115,10 @@ export class LayerManagerRow extends LitElement {

set model(model: AnyModel<LayerManagerRowModel>) {
this._model = model;
for (const [modelKey, widgetKey] of LayerManagerRow.modelNameToViewName) {
for (const [
modelKey,
widgetKey,
] of LayerManagerRow.modelNameToViewName) {
if (widgetKey) {
// Get initial values from the Python model.
(this as any)[widgetKey] = model.get(modelKey);
Expand Down Expand Up @@ -158,15 +172,17 @@ export class LayerManagerRow extends LitElement {
</button>
<button
class=${classMap({
'legacy-button': true,
'settings-delete-button': true,
'loading': this.isLoading,
'done-loading': !this.isLoading
"legacy-button": true,
"settings-delete-button": true,
loading: this.isLoading,
"done-loading": !this.isLoading,
})}
@click="${this.onDeleteClicked}"
>
<div class="spinner"></div>
<span class="close-icon material-symbols-outlined">&#xe5cd;</span>
<span class="close-icon material-symbols-outlined"
>&#xe5cd;</span
>
</button>
</div>
${this.renderConfirmDialog()}
Expand All @@ -180,18 +196,18 @@ export class LayerManagerRow extends LitElement {
return html`
<div class="row">
<span class="legacy-text remove-layer-text">Remove layer?</span>
<button
class="legacy-button primary confirm-deny-button"
@click="${this.confirmDeletion}"
>
Yes
</button>
<button
class="legacy-button primary confirm-deny-button"
@click="${this.cancelDeletion}"
>
No
</button>
<button
class="legacy-button primary confirm-deny-button"
@click="${this.confirmDeletion}"
>
Yes
</button>
<button
class="legacy-button primary confirm-deny-button"
@click="${this.cancelDeletion}"
>
No
</button>
</div>
`;
}
Expand All @@ -215,15 +231,15 @@ export class LayerManagerRow extends LitElement {
}

private onSettingsClicked(_: Event) {
this._model?.send({ "type": "click", "id": "settings" });
this._model?.send({ type: "click", id: "settings" });
}

private onDeleteClicked(_: Event) {
this.isConfirmDialogVisible = true;
}

private confirmDeletion(_: Event) {
this._model?.send({ "type": "click", "id": "delete" });
this._model?.send({ type: "click", id: "delete" });
}

private cancelDeletion(_: Event) {
Expand All @@ -238,7 +254,9 @@ if (!customElements.get(LayerManagerRow.componentName)) {

function render({ model, el }: RenderProps<LayerManagerRowModel>) {
loadFonts();
const row = <LayerManagerRow>document.createElement(LayerManagerRow.componentName);
const row = <LayerManagerRow>(
document.createElement(LayerManagerRow.componentName)
);
row.model = model;
el.appendChild(row);
}
Expand Down
11 changes: 6 additions & 5 deletions js/material_styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { css } from "lit";

export const materialStyles = css`
@font-face {
font-family: 'Material Symbols Outlined';
font-family: "Material Symbols Outlined";
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v205/kJF1BvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oDMzByHX9rA6RzaxHMPdY43zj-jCxv3fzvRNU22ZXGJpEpjC_1v-p_4MrImHCIJIZrDCvHOejbd5zrDAt.woff2) format('woff2');
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v205/kJF1BvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oDMzByHX9rA6RzaxHMPdY43zj-jCxv3fzvRNU22ZXGJpEpjC_1v-p_4MrImHCIJIZrDCvHOejbd5zrDAt.woff2)
format("woff2");
}
.material-symbols-outlined {
-webkit-font-feature-settings: 'liga';
-webkit-font-feature-settings: "liga";
-webkit-font-smoothing: antialiased;
direction: ltr;
display: inline-block;
font-family: 'Material Symbols Outlined';
font-family: "Material Symbols Outlined";
font-style: normal;
font-weight: normal;
letter-spacing: normal;
Expand All @@ -22,4 +23,4 @@ export const materialStyles = css`
white-space: nowrap;
word-wrap: normal;
}
`;
`;
23 changes: 15 additions & 8 deletions js/utils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import type { AnyModel } from "@anywidget/types";
import { IWidgetManager, WidgetModel } from "@jupyter-widgets/base";

async function unpackModels(modelIds: Array<string>, manager: IWidgetManager): Promise<Array<WidgetModel>> {
async function unpackModels(
modelIds: Array<string>,
manager: IWidgetManager
): Promise<Array<WidgetModel>> {
return Promise.all(
modelIds.map(id => manager.get_model(id.slice("IPY_MODEL_".length)))
modelIds.map((id) => manager.get_model(id.slice("IPY_MODEL_".length)))
);
}

export function loadFonts() {
if (!document.querySelector('.custom-fonts')) {
const styleElement = document.createElement('style');
styleElement.classList.add('custom-fonts');
styleElement.textContent = '@import "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined";'
if (!document.querySelector(".custom-fonts")) {
const styleElement = document.createElement("style");
styleElement.classList.add("custom-fonts");
styleElement.textContent =
'@import "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined";';
document.body.appendChild(styleElement);
}
}

export async function updateChildren(container: HTMLElement, model: AnyModel<any>) {
export async function updateChildren(
container: HTMLElement,
model: AnyModel<any>
) {
const children = model.get("children");
const child_models = await unpackModels(children, model.widget_manager);
const child_views = await Promise.all(
child_models.map(model => model.widget_manager.create_view(model))
child_models.map((model) => model.widget_manager.create_view(model))
);
container.innerHTML = ``;
for (const child_view of child_views) {
Expand Down

0 comments on commit 1e183d1

Please sign in to comment.