UNPKG

@arcgis/coding-components

Version:

Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.

90 lines (89 loc) 5.43 kB
import { c as n } from "../../chunks/runtime.js"; import { ref as l } from "lit-html/directives/ref.js"; import { html as s, nothing as c } from "lit"; import { setFocusOnElement as d, focusElement as g } from "@arcgis/components-utils"; import { LitElement as u, createEvent as r } from "@arcgis/lumina"; import { g as a, o as h, b as m, c as f } from "../../chunks/markdown.js"; import { f as p } from "../../chunks/monaco-importer.js"; import { u as b } from "../../chunks/useT9n.js"; import { css as _ } from "@lit/reactive-element/css-tag.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. v4.32.14 */ function v(o) { return !Array.isArray(o) || !o.length ? !1 : Array.isArray(o[0].suggestions); } const S = _`:host{background-color:var(--calcite-color-foreground-1);.notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}.sticky{position:sticky;top:0;z-index:10}calcite-flow{height:100%}calcite-block{p:first-of-type{margin-top:0}code{font-family:var(--calcite-code-family)}pre{direction:ltr;overflow-x:auto;background-color:var(--calcite-color-foreground-2);padding:var(--calcite-spacing-sm);code{font-size:var(--calcite-font-size--2)}}}calcite-list-item-group{background-color:var(--calcite-color-foreground-2)}}`; class $ extends u { constructor() { super(...arguments), this._beforeBack = async () => { this._selectedSuggestion = void 0; }, this.messages = b(), this._colorizeStyle = "", this._filterValue = "", this.arcgisClose = r({ bubbles: !1 }), this.arcgisItemSelected = r({ bubbles: !1 }); } static { this.properties = { _colorizeStyle: 16, _filterValue: 16, _selectedSuggestion: 16, suggestions: 0 }; } static { this.styles = S; } //#endregion //#region Lifecycle load() { this._colorizeStyle = a(), this._themeChangedListener = h(() => this._colorizeStyle = a()); } willUpdate(e) { e.has("suggestions") && this.suggestionsPropChanged(); } disconnectedCallback() { super.disconnectedCallback(), this._flowObserver?.disconnect(), this._themeChangedListener?.dispose(); } //#endregion //#region Private Methods suggestionsPropChanged() { this._selectedSuggestion = void 0; } flowFocusHandler(e) { if (!e) { this._flowObserver?.disconnect(), this._flowObserver = void 0; return; } this._flowObserver || (this._flowObserver = new MutationObserver(() => { d(e.querySelector("calcite-flow-item:last-child"), "calcite-input"); }), this._flowObserver.observe(e, { attributes: !0, attributeFilter: ["id"], childList: !0 })); } _updateFilterValue(e) { this._filterValue = e.currentTarget?.value ?? ""; } _emitItemSelected(e, t) { const i = e; (!i.key || i.key === "Enter") && (e.preventDefault(), this.arcgisItemSelected.emit(t.code)); } _showSuggestionDetail(e, t) { e.stopPropagation(), this._selectedSuggestion = t; } _emitClose() { this.arcgisClose.emit(); } _colorizeCode(e) { e !== void 0 && m(e, this._selectedSuggestion.code); } //#endregion //#region Rendering renderSuggestionGroups() { return this.suggestions === void 0 ? null : v(this.suggestions) ? this.suggestions.map((e) => s`<calcite-list-item-group .heading=${e.label}>${this.renderSuggestionListItems(e.suggestions)}</calcite-list-item-group>`) : this.renderSuggestionListItems(this.suggestions); } renderSuggestionListItems(e) { return e = p(e, "label", this._filterValue), e.length ? e.map((t) => s`<calcite-list-item .label=${t.label} .description=${t.description} @calciteListItemSelect=${(i) => this._emitItemSelected(i, t)} @keydown=${(i) => this._emitItemSelected(i, t)} data-item=${t ?? c}><calcite-action slot=actions-end .text=${this.messages.expand ?? ""} scale=s icon=chevron-right icon-flip-rtl @click=${(i) => this._showSuggestionDetail(i, t)} data-item=${t ?? c}></calcite-action></calcite-list-item>`) : s`<div class="notice-container">${this.messages.noitems}</div>`; } renderSuggestionFlowItem() { const e = this._selectedSuggestion; return e ? s`<calcite-flow-item .heading=${this.messages.suggestions} closable @calciteFlowItemClose=${this._emitClose} .beforeBack=${this._beforeBack} selected><calcite-button width=half slot=footer appearance=outline kind=brand icon-start=code scale=s @click=${(t) => this._emitItemSelected(t, e)} data-item=${e ?? c} ${l(g)}>${this.messages.insert}</calcite-button><calcite-block open .heading=${e.label} .description=${e.description}><div .innerHTML=${f(e.documentation) ?? ""}></div><pre><code ${l(this._colorizeCode)}></code></pre></calcite-block></calcite-flow-item>` : null; } render() { return s`<style>${this._colorizeStyle}</style><calcite-flow ${l(this.flowFocusHandler)}><calcite-flow-item .heading=${this.messages.suggestions} closable @calciteFlowItemClose=${this._emitClose} .selected=${!this._selectedSuggestion}><calcite-input .value=${this._filterValue} icon=magnifying-glass clearable @calciteInputInput=${this._updateFilterValue} class="sticky" scale=m></calcite-input><calcite-list label=suggestions>${this.renderSuggestionGroups()}</calcite-list></calcite-flow-item>${this.renderSuggestionFlowItem()}</calcite-flow>`; } } n("arcgis-arcade-suggestions", $); export { $ as ArcgisArcadeSuggestions };