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.

96 lines (95 loc) 6.24 kB
import { c as m } from "../../chunks/runtime.js"; import { ref as o } from "lit-html/directives/ref.js"; import { html as s } from "lit"; import { setFocusOnElement as h, addLTRMark as c, focusElement as u } from "@arcgis/components-utils"; import { LitElement as f, createEvent as a } from "@arcgis/lumina"; import { g as r, o as p, c as n, a as g } from "../../chunks/markdown.js"; import { f as _ } from "../../chunks/monaco-importer.js"; import { u as b } from "../../chunks/useT9n.js"; import { css as v } from "@lit/reactive-element/css-tag.js"; import { s as d } from "../../chunks/sql-expr-contribution.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. v4.33.0 */ const y = v`: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 I extends f { constructor() { super(...arguments), this.messages = b(), this._unselectItem = async () => { this._selectedApiItem = void 0; }, this._colorizeStyle = "", this._filterValue = "", this.languageId = "arcade", this.hideDocumentationActions = !1, this.loading = !1, this.closed = !1, this.arcgisClose = a({ bubbles: !1 }), this.arcgisItemSelected = a({ bubbles: !1 }); } static { this.properties = { _colorizeStyle: 16, _filterValue: 16, _selectedApiItem: 16, languageId: 1, apiLibrary: 0, hideDocumentationActions: 5, loading: 5, closed: 5 }; } static { this.styles = y; } async load() { await d(this.languageId), this._colorizeStyle = r(), this._themeChangedListener = p(() => this._colorizeStyle = r()); } willUpdate(e) { if (e.has("languageId") && d(this.languageId), 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(); } flowFocusHandler(e) { if (!e) { this._flowObserver?.disconnect(), this._flowObserver = void 0; return; } this._flowObserver || (this._flowObserver = new MutationObserver(() => { h(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), g(e, this.languageId).catch(console.error)); } renderApiCategory(e) { const i = _(e.items, "name", this._filterValue); return i.length ? s`<calcite-list-item-group .heading=${e.title}>${i.map((t) => s`<calcite-list-item .label=${c(t.completion.detail)} @calciteListItemSelect=${(l) => this._emitItemSelected(l, t)} @keydown=${(l) => this._emitItemSelected(l, t)}><calcite-action slot=actions-end .text=${this.messages.expand ?? ""} icon=chevron-right icon-flip-rtl scale=s @click=${(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 @calciteFlowItemClose=${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 @click=${(i) => this._emitItemSelectedAndClose(i, e)} ${o(u)}>${this.messages.insert}</calcite-button><calcite-block open .heading=${c(e.completion.detail)}><div .innerHTML=${n(e.completion.documentation) ?? ""}></div>${e.examples ? s`<div ${o(this._elementToMarkdown)}></div>` : null}</calcite-block></calcite-flow-item>` : null; } render() { if (this.closed) return null; const e = (this.apiLibrary ?? []).map((t) => this.renderApiCategory(t)), i = e.every((t) => !t); return s`<style>${this._colorizeStyle}</style><calcite-flow ${o(this.flowFocusHandler)}><calcite-flow-item .heading=${this.messages.constantsandfunctions} closable @calciteFlowItemClose=${this._emitClose} .selected=${!this._selectedApiItem}><calcite-input .value=${this._filterValue} icon=magnifying-glass clearable @calciteInputInput=${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", I); export { I as ArcgisLanguageApiPanel };