Skip to content

Commit

Permalink
Remove ondemand methods for CodeMirror and SortableJS (#18336)
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep authored Oct 23, 2023
1 parent b24e99c commit 77e05de
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 72 deletions.
5 changes: 2 additions & 3 deletions src/components/ha-code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../common/dom/fire_event";
import { stopPropagation } from "../common/dom/stop_propagation";
import { CodeMirror, loadCodeMirror } from "../resources/codemirror.ondemand";
import { HomeAssistant } from "../types";
import "./ha-icon";

Expand Down Expand Up @@ -58,7 +57,7 @@ export class HaCodeEditor extends ReactiveElement {

@state() private _value = "";

private _loadedCodeMirror?: CodeMirror;
private _loadedCodeMirror?: typeof import("../resources/codemirror");

private _iconList?: Completion[];

Expand Down Expand Up @@ -110,7 +109,7 @@ export class HaCodeEditor extends ReactiveElement {

// Ensure CodeMirror module is loaded before any update
protected override async scheduleUpdate() {
this._loadedCodeMirror ??= await loadCodeMirror();
this._loadedCodeMirror ??= await import("../resources/codemirror");
super.scheduleUpdate();
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { subscribeRepairsIssueRegistry } from "../data/repairs";
import { UpdateEntity, updateCanInstall } from "../data/update";
import { SubscribeMixin } from "../mixins/subscribe-mixin";
import { actionHandler } from "../panels/lovelace/common/directives/action-handler-directive";
import { SortableInstance, loadSortable } from "../resources/sortable.ondemand";
import type { SortableInstance } from "../resources/sortable";
import { haStyleScrollbar } from "../resources/styles";
import type { HomeAssistant, PanelInfo, Route } from "../types";
import "./ha-icon";
Expand Down Expand Up @@ -689,7 +689,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.getElementById("sortable")!,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import {
computeDefaultFavoriteColors,
} from "../../../../data/light";
import { actionHandler } from "../../../../panels/lovelace/common/directives/action-handler-directive";
import {
SortableInstance,
loadSortable,
} from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";
import { HomeAssistant } from "../../../../types";
import { showConfirmationDialog } from "../../../generic/show-dialog-box";
import "./ha-favorite-color-button";
Expand Down Expand Up @@ -73,7 +70,7 @@ export class HaMoreInfoLightFavoriteColors extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".container")!,
{
Expand Down
7 changes: 2 additions & 5 deletions src/panels/config/automation/action/ha-automation-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ import { ACTION_TYPES } from "../../../../data/action";
import { AutomationClipboard } from "../../../../data/automation";
import { Action } from "../../../../data/script";
import { sortableStyles } from "../../../../resources/ha-sortable-style";
import {
SortableInstance,
loadSortable,
} from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";
import { Entries, HomeAssistant } from "../../../../types";
import type HaAutomationActionRow from "./ha-automation-action-row";
import { getType } from "./ha-automation-action-row";
Expand Down Expand Up @@ -227,7 +224,7 @@ export default class HaAutomationAction extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(this.shadowRoot!.querySelector(".actions")!, {
animation: 150,
fallbackClass: "sortable-fallback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { CSSResultGroup, LitElement, PropertyValues, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import type { ActionDetail } from "@material/mwc-list";
import {
loadSortable,
SortableInstance,
} from "../../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../../resources/sortable";
import { ensureArray } from "../../../../../common/array/ensure-array";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { capitalizeFirstLetter } from "../../../../../common/string/capitalize-first-letter";
Expand Down Expand Up @@ -481,7 +478,8 @@ export class HaChooseAction extends LitElement implements ActionElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../../resources/sortable"))
.default;
this._sortable = new Sortable(this.shadowRoot!.querySelector(".options")!, {
animation: 150,
fallbackClass: "sortable-fallback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ import type { LocalizeFunc } from "../../../../common/translations/localize";
import type { HaSelect } from "../../../../components/ha-select";
import { CONDITION_TYPES } from "../../../../data/condition";
import { sortableStyles } from "../../../../resources/ha-sortable-style";
import {
loadSortable,
SortableInstance,
} from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";
import "./types/ha-automation-condition-and";
import "./types/ha-automation-condition-device";
import "./types/ha-automation-condition-numeric_state";
Expand Down Expand Up @@ -248,7 +245,7 @@ export default class HaAutomationCondition extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".conditions")!,
{
Expand Down
5 changes: 2 additions & 3 deletions src/panels/config/automation/trigger/ha-automation-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import "../../../../components/ha-svg-icon";
import { AutomationClipboard, Trigger } from "../../../../data/automation";
import { TRIGGER_TYPES } from "../../../../data/trigger";
import { sortableStyles } from "../../../../resources/ha-sortable-style";
import { SortableInstance } from "../../../../resources/sortable";
import { loadSortable } from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";
import { Entries, HomeAssistant } from "../../../../types";
import "./ha-automation-trigger-row";
import type HaAutomationTriggerRow from "./ha-automation-trigger-row";
Expand Down Expand Up @@ -225,7 +224,7 @@ export default class HaAutomationTrigger extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".triggers")!,
{
Expand Down
7 changes: 2 additions & 5 deletions src/panels/config/helpers/forms/ha-input_select-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import type { InputSelect } from "../../../../data/input_select";
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
import { haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import {
loadSortable,
SortableInstance,
} from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";

@customElement("ha-input_select-form")
class HaInputSelectForm extends LitElement {
Expand Down Expand Up @@ -50,7 +47,7 @@ class HaInputSelectForm extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(this.shadowRoot!.querySelector(".options")!, {
animation: 150,
fallbackClass: "sortable-fallback",
Expand Down
7 changes: 2 additions & 5 deletions src/panels/lovelace/cards/hui-shopping-list-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import {
updateItem,
} from "../../../data/shopping-list";
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
import {
loadSortable,
SortableInstance,
} from "../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../resources/sortable";
import { HomeAssistant } from "../../../types";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { SensorCardConfig, ShoppingListCardConfig } from "./types";
Expand Down Expand Up @@ -318,7 +315,7 @@ class HuiShoppingListCard
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../resources/sortable")).default;
const sortableEl = this._sortableEl;
this._sortable = new Sortable(sortableEl!, {
animation: 150,
Expand Down
7 changes: 2 additions & 5 deletions src/panels/lovelace/components/hui-entity-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import type {
} from "../../../components/entity/ha-entity-picker";
import "../../../components/ha-icon-button";
import { sortableStyles } from "../../../resources/ha-sortable-style";
import {
loadSortable,
SortableInstance,
} from "../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../resources/sortable";
import { HomeAssistant } from "../../../types";
import { EntityConfig } from "../entity-rows/types";

Expand Down Expand Up @@ -93,7 +90,7 @@ export class HuiEntityEditor extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".entities")!,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import {
stripCustomPrefix,
} from "../../../../data/lovelace_custom_cards";
import { sortableStyles } from "../../../../resources/ha-sortable-style";
import {
SortableInstance,
loadSortable,
} from "../../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../../resources/sortable";
import { HomeAssistant } from "../../../../types";
import { getTileFeatureElementClass } from "../../create-element/create-tile-feature-element";
import { supportsAlarmModesTileFeature } from "../../tile-features/hui-alarm-modes-tile-feature";
Expand Down Expand Up @@ -321,7 +318,7 @@ export class HuiTileCardFeaturesEditor extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".features")!,
{
Expand Down
7 changes: 2 additions & 5 deletions src/panels/lovelace/editor/hui-entities-card-row-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker
import "../../../components/ha-icon-button";
import "../../../components/ha-svg-icon";
import { sortableStyles } from "../../../resources/ha-sortable-style";
import {
loadSortable,
SortableInstance,
} from "../../../resources/sortable.ondemand";
import type { SortableInstance } from "../../../resources/sortable";
import { HomeAssistant } from "../../../types";
import { EntityConfig, LovelaceRowConfig } from "../entity-rows/types";

Expand Down Expand Up @@ -134,7 +131,7 @@ export class HuiEntitiesCardRowEditor extends LitElement {
}

private async _createSortable() {
const Sortable = await loadSortable();
const Sortable = (await import("../../../resources/sortable")).default;
this._sortable = new Sortable(
this.shadowRoot!.querySelector(".entities")!,
{
Expand Down
8 changes: 0 additions & 8 deletions src/resources/codemirror.ondemand.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/resources/sortable.ondemand.ts

This file was deleted.

0 comments on commit 77e05de

Please sign in to comment.