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.

194 lines (193 loc) • 15.7 kB
import { c as P } from "../../chunks/runtime.js"; import { html as t } from "lit-html"; import { nothing as y, LitElement as C, createEvent as f, safeClassMap as v } from "@arcgis/lumina"; import { setValuesInString as o, quoteString as g } from "@arcgis/components-utils"; import { B as b, v as h, M as m, f as M, a as R, b as A } from "../../chunks/arcade-executor.js"; import { u as I } from "../../chunks/useT9n.js"; import { css as L } from "@lit/reactive-element/css-tag.js"; import { s as O } from "../../chunks/fields.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.14 */ const D = L`:host{display:flex;flex-direction:column;width:100%;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-2);.flex-adjustable{flex:1 1 auto;overflow:hidden}.flex-row{display:flex;flex-direction:row;overflow:hidden}.flex-column{display:flex;flex-direction:column;overflow:hidden}.y-scrollable-container{overflow-y:auto;block-size:100%;background-color:var(--calcite-color-foreground-1)}header{border-bottom:1px solid var(--calcite-color-border-3);flex:0 0 auto}.ltr-container{direction:ltr}calcite-action-bar{calcite-action-group{padding-inline-end:var(--calcite-spacing-sm);calcite-action{padding-inline-end:var(--calcite-spacing-sm)}calcite-action:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}}calcite-action-group:last-child{border-inline-end-width:0px}calcite-action-group:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}}.notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}.color-info{color:var(--calcite-color-status-info)}.color-error{color:var(--calcite-color-status-danger)}.color-success{color:var(--calcite-color-status-success)}[class*=result-value-]{font-size:var(--calcite-font-size--2);line-height:1.25rem;background-color:var(--calcite-color-foreground-1);margin:var(--calcite-spacing-md)}.console-logs-container{background-color:var(--calcite-color-foreground-1);padding:0 var(--calcite-spacing-md);font-family:var(--calcite-code-family);font-size:var(--calcite-font-size--2);font-weight:var(--calcite-font-weight-normal)}.result-value-table{table{display:block;max-width:fit-content;overflow-x:auto;border-spacing:0;border-collapse:collapse;text-align:start;white-space:nowrap;thead{background-color:var(--calcite-color-foreground-2)}tr{border-top:1px solid var(--calcite-color-border-3);border-bottom:1px solid var(--calcite-color-border-3)}th,td{border-inline-start:1px solid var(--calcite-color-border-3);border-inline-end:1px solid var(--calcite-color-border-3);text-align:start;padding:var(--calcite-spacing-xxs);.string-value{white-space:pre}}th{font-weight:var(--calcite-font-weight-medium)}}}.tree-item-label,.number-value,.string-value,.boolean-value{font-family:var(--calcite-code-family)}.tree-item-label,.value-type{color:var(--calcite-color-text-2);font-weight:var(--calcite-font-weight-normal)}.dictionary-property{color:var(--arcgis-editor-identifier)}.number-value{color:var(--arcgis-editor-number)}.string-value{color:var(--arcgis-editor-string);white-space:pre-wrap}.constant-value{color:var(--arcgis-editor-constant)}.date-value{color:var(--arcgis-editor-date)}}`, l = { lines: !0, selectionMode: "none", scale: "s", oncalciteTreeSelect: (e) => e.currentTarget.selectedItems.forEach((a) => a.selected = !1) }, u = { onClick: (e) => { const a = e.currentTarget; a.expanded = !a.expanded; } }, r = ({ name: e }) => t`<span class="dictionary-property">${e}</span><span>:&nbsp;</span>`, x = ({ value: e, subtree: a = !1 }) => t`<calcite-tree slot=${(a ? "children" : void 0) ?? y} .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item class="string-value">${JSON.stringify(e.castAsJson(), void 0, 2)}</calcite-tree-item></calcite-tree>`, w = ({ value: e, subtree: a = !1 }) => t`<calcite-tree slot=${(a ? "children" : void 0) ?? y} .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item><div class="tree-item-label">${r({ name: "type" })}${e.type}</div></calcite-tree-item><calcite-tree-item><div class="tree-item-label">${r({ name: "value" })}<span class="string-value">${JSON.stringify(e, void 0, 2)}</span></div></calcite-tree-item></calcite-tree>`, p = ({ arcadeResult: e }) => { switch (e.type) { case "unknown": case "null": return t`<span class="constant-value">${e.type}</span>`; case "text": return t`<span class="string-value">${g(e.value)}</span>`; case "number": return t`<span class="number-value">${e.value.toString()}</span>`; case "boolean": return t`<span class="constant-value">${e.value.toString()}</span>`; case "date": return t`<span class="date-value">${A(e)}</span>`; case "dateOnly": return t`<span class="string-value">${g(R(e))}</span>`; case "time": return t`<span class="string-value">${g(M(e))}</span>`; default: return null; } }, S = ({ arcadeResult: e, t9nStrings: a }) => { const s = e.value ?? [], c = Math.max(s.length - m, 0); return t`<span>${`${e.type}(${s.length ?? 0})`}</span>${c > 0 ? t`<span>&nbsp;${o(a.showingfirstitemsformat, { count: m.toString() })}</span>` : null}`; }, k = ({ value: e, subtree: a, t9nStrings: s }) => { const c = e.geometry?.(); return t`<calcite-tree slot=${"children"} .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}>${e.keys().map((i) => { const n = h(e.field(i)); return e.arcadeDeclaredClass === "esri.arcade.Feature" && n.type === "geometry" ? null : $({ arcadeResult: n, name: i, t9nStrings: s }); })}${c ? $({ arcadeResult: { type: "geometry", value: c }, name: "geometry", t9nStrings: s }) : null}</calcite-tree>`; }, F = ({ arcadeResult: e, t9nStrings: a }) => t`<div class="value-type"><span>${e.type}:</span>${e.features.length >= b ? t`<span>&nbsp;${o(a.showingfirstitemsformat, { count: b.toString() })}</span>` : null}</div>`, T = ({ items: e, subtree: a, t9nStrings: s }) => t`<calcite-tree slot=${"children"} .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}>${e.map((c, i) => { const n = h(c); return $({ arcadeResult: n, name: i, expanded: !1, t9nStrings: s }); })}</calcite-tree>`, $ = ({ arcadeResult: e, name: a, expanded: s, t9nStrings: c }) => { switch (e.type) { case "null": case "unknown": case "text": case "number": case "date": case "dateOnly": case "time": case "boolean": return t`<calcite-tree-item><div class="tree-item-label">${r({ name: a })}${p({ arcadeResult: e })}</div></calcite-tree-item>`; case "array": { const n = (e.value ?? []).slice(0, m); return t`<calcite-tree-item .expanded=${s} @click=${u.onClick}><div class="tree-item-label">${r({ name: a })}${S({ arcadeResult: e, t9nStrings: c })}</div>${T({ items: n, subtree: !0, t9nStrings: c })}</calcite-tree-item>`; } case "geometry": return t`<calcite-tree-item .expanded=${s} @click=${u.onClick}><div class="tree-item-label">${r({ name: a })}<span>${e.type}</span></div>${w({ value: e.value, subtree: !0 })}</calcite-tree-item>`; case "attachment": return t`<calcite-tree-item .expanded=${s} @click=${u.onClick}><div class="tree-item-label">${r({ name: a })}<span>${e.type}</span></div>${x({ value: e.value, subtree: !0 })}</calcite-tree-item>`; case "feature": case "dictionary": case "portal": return t`<calcite-tree-item .expanded=${s} @click=${u.onClick}><div class="tree-item-label">${r({ name: a })}<span>${e.type}</span></div>${k({ value: e.value, subtree: !0, t9nStrings: c })}</calcite-tree-item>`; default: return null; } }, _ = ({ arcadeResult: e }) => { const a = O(e.value.fields); return t`<table><thead><tr>${a.map((s) => t`<th>${s.name}</th>`)}</tr></thead><tbody>${e.features.map((s) => t`<tr>${a.map((c) => { try { const i = h(s.field(c.name)); return t`<td>${p({ arcadeResult: i })}</td>`; } catch { return t`<td></td>`; } })}</tr>`)}</tbody></table>`; }, d = { onClick: (e) => { const a = e.currentTarget; a.expanded = !a.expanded; } }; class z extends C { constructor() { super(...arguments), this.messages = I(), this.openedResultPanel = "output", this.arcgisClose = f({ bubbles: !1 }), this.arcgisOpenedResultPanelChange = f({ bubbles: !1 }); } static { this.properties = { consoleLogs: 0, loading: 5, openedResultPanel: 3, result: 0 }; } static { this.styles = D; } updateResultPanel(a) { this.openedResultPanel = a, this.arcgisOpenedResultPanelChange.emit(a); } _switchResultPanel(a) { const s = a.currentTarget.dataset.panelName; s && this.updateResultPanel(s); } _emitClose() { this.arcgisClose.emit(); } renderConsolePanel() { return this.openedResultPanel !== "console" ? null : this.loading && !this.consoleLogs?.length ? t`<calcite-loader scale=s type=indeterminate label></calcite-loader>` : t`<div class="console-logs-container ltr-container">${this.consoleLogs?.length ? this.consoleLogs.map((a) => t`<p>${a}</p>`) : t`<p>${this.messages.consolemessage}</p>`}</div>`; } renderLogPanel() { if (this.openedResultPanel !== "log") return null; if (this.loading) return t`<calcite-loader scale=s type=indeterminate label></calcite-loader>`; const a = this.result?.type === "error" ? "color-error" : "color-success"; return t`<calcite-list label=results>${this.result ? t`<calcite-list-item .label=${o(this.messages.lastexecutionformat, { timeStamp: new Intl.DateTimeFormat(this.messages._t9nLocale, { dateStyle: "medium", timeStyle: "medium" }).format(this.result.timeStamp) })}><calcite-icon slot=content-start icon=information scale=s class=${v(a)}></calcite-icon></calcite-list-item><calcite-list-item .label=${o(this.messages.compilationtimeformat, { time: new Intl.NumberFormat(this.messages._t9nLocale, { style: "unit", unit: "millisecond", maximumFractionDigits: 2 }).format(this.result.compilationTime ?? 0) })}><calcite-icon slot=content-start icon=information scale=s class=${v(a)}></calcite-icon></calcite-list-item><calcite-list-item .label=${o(this.messages.executiontimeformat, { time: new Intl.NumberFormat(this.messages._t9nLocale, { style: "unit", unit: "millisecond", maximumFractionDigits: 2 }).format(this.result.executionTime ?? 0) })}><calcite-icon slot=content-start icon=information scale=s class=${v(a)}></calcite-icon></calcite-list-item>` : t`<calcite-list-item .label=${this.messages.runscriptmessage}><calcite-icon slot=content-start icon=information scale=s class="color-info"></calcite-icon></calcite-list-item>`}</calcite-list>`; } renderOutputPanel() { if (this.openedResultPanel !== "output") return null; if (this.loading) return t`<calcite-loader scale=s type=indeterminate label></calcite-loader>`; switch (this.result?.type) { case "error": return t`<div class="result-value-simple flex-adjustable">${o(this.messages.executionerrorformat, { message: this.result.value })}</div>`; case "null": case "unknown": return t`<div class="result-value-simple ltr-container">${p({ arcadeResult: this.result })}</div>`; case "text": case "number": case "date": case "dateOnly": case "time": case "boolean": return t`<div class="result-value-simple ltr-container"><span class="value-type">${this.result.type}:&nbsp;</span>${p({ arcadeResult: this.result })}</div>`; case "array": { const s = (this.result.value ?? []).slice(0, m); return t`<div class="result-value-simple ltr-container"><calcite-tree .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item expanded @click=${d.onClick}><div class="tree-item-label">${S({ arcadeResult: this.result, t9nStrings: this.messages })}</div>${T({ items: s, subtree: !0, t9nStrings: this.messages })}</calcite-tree-item></calcite-tree></div>`; } case "geometry": return t`<div class="result-value-simple ltr-container"><calcite-tree .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item expanded @click=${d.onClick}><div class="tree-item-label">${this.result.type}</div>${w({ value: this.result.value, subtree: !0 })}</calcite-tree-item></calcite-tree></div>`; case "attachment": return t`<div class="result-value-simple ltr-container"><calcite-tree .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item expanded @click=${d.onClick}><div class="tree-item-label">${this.result.type}</div>${x({ value: this.result.value, subtree: !0 })}</calcite-tree-item></calcite-tree></div>`; case "feature": case "dictionary": case "portal": return t`<div class="result-value-simple ltr-container"><calcite-tree .lines=${l.lines} .selectionMode=${l.selectionMode} .scale=${l.scale} @calciteTreeSelect=${l.oncalciteTreeSelect}><calcite-tree-item expanded @click=${d.onClick}><div class="tree-item-label">${this.result.type}</div>${k({ value: this.result.value, subtree: !0, t9nStrings: this.messages })}</calcite-tree-item></calcite-tree></div>`; case "featureSet": return t`<div class="result-value-table ltr-container">${F({ arcadeResult: this.result, t9nStrings: this.messages })}${_({ arcadeResult: this.result })}</div>`; case "knowledgeGraph": return t`<div class="result-value-simple ltr-container"><span class="value-type">${this.result.type}:&nbsp;</span><span class="string-value">${this.result.value.url}</span></div>`; default: return t`<div class="result-value-simple flex-adjustable ltr-container">${this.messages.runscriptmessage}</div>`; } } render() { return t`<header class="flex-row"><calcite-action-bar class="flex-adjustable" layout=horizontal scale=s expanded expand-disabled><calcite-action-group scale=s><calcite-action .active=${this.openedResultPanel === "output"} .text=${this.messages.output ?? ""} text-enabled scale=s icon=list-show-all icon-flip-rtl @click=${this._switchResultPanel} data-panel-name=output></calcite-action><calcite-action .active=${this.openedResultPanel === "console"} .text=${this.messages.console ?? ""} text-enabled scale=s icon=console icon-flip-rtl @click=${this._switchResultPanel} data-panel-name=console></calcite-action><calcite-action .active=${this.openedResultPanel === "log"} .text=${this.messages.log ?? ""} text-enabled scale=s icon=list icon-flip-rtl @click=${this._switchResultPanel} data-panel-name=log></calcite-action></calcite-action-group></calcite-action-bar><calcite-action scale=s icon=x .text=${this.messages.close ?? ""} @click=${this._emitClose}></calcite-action></header><article class="flex-adjustable">${this.loading ? t`<calcite-loader scale=s type=indeterminate label></calcite-loader>` : t`<div class="flex-column y-scrollable-container">${this.renderOutputPanel()}${this.renderConsolePanel()}${this.renderLogPanel()}</div>`}</article>`; } } P("arcgis-arcade-results", z); export { z as ArcgisArcadeResults };