@arcgis/coding-components
Version:
Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.
99 lines (98 loc) • 6.09 kB
JavaScript
import { c as m } from "../../chunks/runtime.js";
import { ref as c } from "lit-html/directives/ref.js";
import { html as s } from "lit";
import { setFocusOnElement as d, addLTRMark as o, focusElement as h } from "@arcgis/components-utils";
import { LitElement as u, createEvent as a } from "@arcgis/lumina";
import { g as r, o as p, c as n, a as f } from "../../chunks/markdown.js";
import { f as g } from "../../chunks/monaco-importer.js";
import { u as _ } from "../../chunks/useT9n.js";
import { css as b } 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 */
const v = b`: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 y extends u {
constructor() {
super(...arguments), this.messages = _(), this._unselectItem = async () => {
this._selectedApiItem = void 0;
}, this._colorizeStyle = "", this._filterValue = "", this.hideDocumentationActions = !1, this.loading = !1, this.arcgisClose = a({ bubbles: !1 }), this.arcgisItemSelected = a({ bubbles: !1 });
}
static {
this.properties = { _colorizeStyle: 16, _filterValue: 16, _selectedApiItem: 16, apiLibrary: 0, hideDocumentationActions: 5, loading: 5 };
}
static {
this.styles = v;
}
//#endregion
//#region Lifecycle
load() {
this._colorizeStyle = r(), this._themeChangedListener = p(() => this._colorizeStyle = r());
}
willUpdate(e) {
if (e.has("apiLibrary")) {
if (!this._selectedApiItem)
return;
for (const i of this.apiLibrary ?? [])
for (const t of i.items)
if (t.name === this._selectedApiItem.name) {
this._selectedApiItem = t;
return;
}
this._selectedApiItem = void 0;
}
}
disconnectedCallback() {
super.disconnectedCallback(), this._flowObserver?.disconnect(), this._themeChangedListener?.dispose();
}
//#endregion
//#region Private Methods
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 }));
}
_emitItemSelected(e, i) {
if (!i)
return;
const t = e;
(!t.key || t.key === "Enter") && (e.preventDefault(), this.arcgisItemSelected.emit(i.completion.insertText ?? ""));
}
_emitClose() {
this.arcgisClose.emit();
}
_emitItemSelectedAndClose(e, i) {
const t = e;
(!t.key || t.key === "Enter") && (e.preventDefault(), this.arcgisItemSelected.emit(i.completion.insertText ?? ""));
}
_selectItem(e, i) {
e.stopPropagation(), this._selectedApiItem = i;
}
_updateFilterValue(e) {
this._filterValue = e.currentTarget.value ?? "";
}
_elementToMarkdown(e) {
e !== void 0 && (e.innerHTML = n(this._selectedApiItem.examples), f(e).catch(console.error));
}
//#endregion
//#region Rendering
renderApiCategory(e) {
const i = g(e.items, "name", this._filterValue);
return i.length ? s`<calcite-list-item-group .heading=${e.title}>${i.map((t) => s`<calcite-list-item .label=${o(t.completion.detail)} =${(l) => this._emitItemSelected(l, t)} =${(l) => this._emitItemSelected(l, t)}><calcite-action slot=actions-end .text=${this.messages.expand ?? ""} icon=chevron-right icon-flip-rtl scale=s =${(l) => this._selectItem(l, t)}></calcite-action></calcite-list-item>`)}</calcite-list-item-group>` : null;
}
renderApiItemFlowItem() {
const e = this._selectedApiItem;
return e ? s`<calcite-flow-item .heading=${this.messages.constantsandfunctions} .beforeBack=${this._unselectItem} closable =${this._emitClose} selected>${this.hideDocumentationActions ? null : s`<calcite-button width=half slot=footer appearance=outline kind=brand scale=s .href=${e.link} target=Help icon-start=information>${this.messages.moreinformation}</calcite-button>`}<calcite-button .width=${this.hideDocumentationActions ? "full" : "half"} slot=footer appearance=outline kind=brand icon-start=code scale=s =${(i) => this._emitItemSelectedAndClose(i, e)} ${c(h)}>${this.messages.insert}</calcite-button><calcite-block open .heading=${o(e.completion.detail)}><div .innerHTML=${n(e.completion.documentation) ?? ""}></div>${e.examples ? s`<div ${c(this._elementToMarkdown)}></div>` : null}</calcite-block></calcite-flow-item>` : null;
}
render() {
const e = (this.apiLibrary ?? []).map((t) => this.renderApiCategory(t)), i = e.every((t) => !t);
return s`<style>${this._colorizeStyle}</style><calcite-flow ${c(this.flowFocusHandler)}><calcite-flow-item .heading=${this.messages.constantsandfunctions} closable =${this._emitClose} .selected=${!this._selectedApiItem}><calcite-input .value=${this._filterValue} icon=magnifying-glass clearable =${this._updateFilterValue} class="sticky" scale=m></calcite-input>${this.loading ? s`<calcite-loader scale=s type=indeterminate .label=${this.messages.loading ?? "Loading"}></calcite-loader>` : s`<calcite-list label="arcade api">${i ? s`<div class="notice-container">${this.messages.noitems}</div>` : e}</calcite-list>`}</calcite-flow-item>${this.renderApiItemFlowItem()}</calcite-flow>`;
}
}
m("arcgis-language-api-panel", y);
export {
y as ArcgisLanguageApiPanel
};