UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 9.64 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import{ClonableMixin as e}from"./core/Clonable.js";import o from"./core/Collection.js";import{JSONSupport as s}from"./core/JSONSupport.js";import{clone as i}from"./core/lang.js";import r from"./core/Logger.js";import{isPromiseLike as n}from"./core/promiseUtils.js";import{property as p,cast as l,subclass as a}from"./core/accessorSupport/decorators.js";import{ensureOneOfType as d}from"./core/accessorSupport/ensureType.js";import{collectFields as c,collectArcadeFieldNames as f,extractSubstitutionTemplatesFromString as m}from"./layers/support/fieldUtils.js";import{UtilityNetworkAssociationsContent as u,RelationshipContent as h,ExpressionContent as y,FieldsContent as I,AttachmentsContent as F,TextContent as _,CustomContent as w,MediaContent as g,BaseContent as x,persistableWebSceneTypes as N,persistableTypes as A}from"./popup/content.js";import C from"./popup/ExpressionInfo.js";import S from"./popup/FieldInfo.js";import O from"./popup/LayerOptions.js";import R from"./popup/RelatedRecordsInfo.js";import{types as E}from"./popup/content/support/mediaInfoTypes.js";import j from"./support/actions/ActionBase.js";import T from"./support/actions/ActionButton.js";import v from"./support/actions/ActionToggle.js";import{reader as b}from"./core/accessorSupport/decorators/reader.js";import{writer as J}from"./core/accessorSupport/decorators/writer.js";const B="relationships/",L="expression/",M=o.ofType({key:"type",defaultKeyValue:"button",base:j,typeMap:{button:T,toggle:v}}),P={base:x,key:"type",typeMap:{media:g,custom:w,text:_,attachments:F,fields:I,expression:y,relationship:h,utilityNetworkAssociations:u}},W=new Set(["attachments","fields","media","text","expression","relationship"]),k=new Set([...W,"utility-network-associations"]);let U=class extends(e(s)){constructor(t){super(t),this.actions=null,this.expressionInfos=null,this.fieldInfos=null,this.layerOptions=null,this.lastEditInfoEnabled=!0,this.outFields=null,this.overwriteActions=!1,this.returnGeometry=!1,this.title=""}get content(){return this._get("content")??""}set content(t){this._set("content",t)}castContent(t){return Array.isArray(t)?t.map(t=>d(P,t)):"string"==typeof t||"function"==typeof t||t instanceof HTMLElement||n(t)?t:(r.getLogger(this).error("content error","unsupported content value",{value:t}),null)}readContent(t,e){const{popupElements:o}=e;return Array.isArray(o)&&o.length>0?this._readPopupInfoElements(e.description,e.mediaInfos,o):this._readPopupInfo(e)}writeWebSceneContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeWebMapContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeFieldInfos(t,e,o,s){const{content:i}=this,r=Array.isArray(i)?i:null,{writeFieldFormat:n,...p}=s||{};if(t){const o=r?r.filter(t=>"fields"===t.type):[],s=o.length&&o.every(t=>t.fieldInfos?.length);e.fieldInfos=t.filter(Boolean).map(t=>{const e=t.toJSON(p);return s&&(e.visible=!1),e})}if(r)for(const l of r)"fields"===l.type&&this._writeFieldsContent(l,e,p)}writeLayerOptions(t,e,o,s){e[o]=!t||null===t.showNoDataRecords&&null===t.returnTopmostRaster?null:t.toJSON(s)}writeTitle(t,e){e.title=t||""}async collectRequiredFields(t,e,o){const s=this.expressionInfos||[];await this._collectExpressionInfoFields(t,e,o,[...s,...this._getContentExpressionInfos(this.content,s)]),c(t,e,[...this.outFields||[],...this._getActionsFields(this.actions),...this._getTitleFields(this.title),...this._getContentFields(this.content)])}async getRequiredFields(t,e){const o=new Set;return await this.collectRequiredFields(o,t,e),[...o].sort()}_writePopupTemplateContent(t,e,o){"string"!=typeof t?Array.isArray(t)&&(e.popupElements=t.filter(t=>"web-scene"===o?.origin?W.has(t.type):k.has(t.type)).map(t=>t?.toJSON(o)),e.popupElements.forEach(t=>{"attachments"===t.type?this._writeAttachmentContent(e):"media"===t.type?this._writeMediaContent(t,e):"text"===t.type?this._writeTextContent(t,e):"relationship"===t.type&&this._writeRelationshipContent(t,e)})):e.description=t}_writeFieldsContent(t,e,o){const s=t.fieldInfos;if(!Array.isArray(s)||!s.length)return;const i=e.fieldInfos;if(Array.isArray(i))for(const r of s){const t=i.find(t=>t.fieldName?.toLowerCase()===r.fieldName?.toLowerCase());t?t.visible=!0:i.push(r.toJSON(o))}else e.fieldInfos=s.map(t=>t.toJSON(o))}_writeAttachmentContent(t){t.showAttachments||(t.showAttachments=!0)}_writeRelationshipContent(t,e){const o=t.orderByFields?.map(e=>this._toFieldOrderJSON(e,t.relationshipId))||[],s=[...e.relatedRecordsInfo?.orderByFields||[],...o];e.relatedRecordsInfo={showRelatedRecords:!0,...s?.length&&{orderByFields:s}}}_writeTextContent(t,e){!e.description&&t.text&&(e.description=t.text)}_writeMediaContent(t,e){if(!Array.isArray(t.mediaInfos)||!t.mediaInfos.length)return;const o=i(t.mediaInfos);Array.isArray(e.mediaInfos)?e.mediaInfos=[...e.mediaInfos,...o]:e.mediaInfos=o}_readPopupInfoElements(t,e,o){const s={description:!1,mediaInfos:!1};return o.map(o=>"media"===o.type?(o.mediaInfos||!e||s.mediaInfos||(o.mediaInfos=e,s.mediaInfos=!0),g.fromJSON(o)):"text"===o.type?(o.text||!t||s.description||(o.text=t,s.description=!0),_.fromJSON(o)):"attachments"===o.type?F.fromJSON(o):"fields"===o.type?I.fromJSON(o):"expression"===o.type?y.fromJSON(o):"relationship"===o.type?h.fromJSON(o):"utilityNetworkAssociations"===o.type?u.fromJSON(o):void 0).filter(Boolean)}_toRelationshipContent(t){const{field:e,order:o}=t;if(!e?.startsWith(B))return null;const s=e.replace(B,"").split("/");if(2!==s.length)return null;const i=parseInt(s[0],10),r=s[1];return!Number.isNaN(i)&&r?h.fromJSON({relationshipId:i,orderByFields:[{field:r,order:o}]}):null}_toFieldOrderJSON(t,e){const{order:o,field:s}=t;return{field:`${B}${e}/${s}`,order:o}}_readPopupInfo({description:t,mediaInfos:e,showAttachments:o,relatedRecordsInfo:s={showRelatedRecords:!1}}){const i=[];t?i.push(new _({text:t})):i.push(new I),Array.isArray(e)&&e.length&&i.push(g.fromJSON({mediaInfos:e})),o&&i.push(F.fromJSON({displayType:"auto"}));const{showRelatedRecords:r,orderByFields:n}=s;return r&&n?.length&&n.forEach(t=>{const e=this._toRelationshipContent(t);e&&i.push(e)}),i.length?i:t}_getContentElementFields(t){const e=t?.type;if("attachments"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)];if("custom"===e)return t.outFields||[];if("fields"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...this._getFieldInfoFields(t.fieldInfos??this.fieldInfos)];if("media"===e){const e=t.mediaInfos||[];return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...e.reduce((t,e)=>[...t,...this._getMediaInfoFields(e)],[])]}return"text"===e?this._extractFieldNames(t.text):"relationship"===e||"utility-network-associations"===e?[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)]:[]}_getMediaInfoFields(t){const{caption:e,title:o,value:s}=t,i=s||{},{fields:r,normalizeField:n,tooltipField:p,sourceURL:l,linkURL:a}=i,d=[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(l),...this._extractFieldNames(a),...r??[]];return n&&d.push(n),p&&d.push(p),d}_getContentExpressionInfos(t,e){return Array.isArray(t)?t.reduce((t,e)=>[...t,..."expression"===e.type&&e.expressionInfo?[e.expressionInfo]:[]],e):[]}_getContentFields(t){return"string"==typeof t?this._extractFieldNames(t):Array.isArray(t)?t.reduce((t,e)=>[...t,...this._getContentElementFields(e)],[]):[]}async _collectExpressionInfoFields(t,e,o,s){s&&await Promise.all(s.map(s=>f(t,e,o,s.expression)))}_getFieldInfoFields(t){return t?t.filter(({fieldName:t,visible:e})=>!(void 0!==e&&!e||!t||t.startsWith(B)||t.startsWith(L))).map(t=>t.fieldName):[]}_getActionsFields(t){return t?t.toArray().reduce((t,e)=>[...t,...this._getActionFields(e)],[]):[]}_getActionFields(t){const{className:e,title:o,type:s}=t,i="button"===s||"toggle"===s?t.image:"";return[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(i)]}_getTitleFields(t){return"string"==typeof t?this._extractFieldNames(t):[]}_extractFieldNames(t){return m(t).filter(t=>!(t.startsWith(B)||t.startsWith(L)))}};t([p({type:M})],U.prototype,"actions",void 0),t([p()],U.prototype,"content",null),t([l("content")],U.prototype,"castContent",null),t([b("content",["description","fieldInfos","popupElements","mediaInfos","showAttachments","relatedRecordsInfo"])],U.prototype,"readContent",null),t([J("web-scene","content",{popupElements:{type:o.ofType(N)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(E)},description:{type:String},relatedRecordsInfo:{type:R}})],U.prototype,"writeWebSceneContent",null),t([J("content",{popupElements:{type:o.ofType(A)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(E)},description:{type:String},relatedRecordsInfo:{type:R}})],U.prototype,"writeWebMapContent",null),t([p({type:[C],json:{write:!0}})],U.prototype,"expressionInfos",void 0),t([p({type:[S]})],U.prototype,"fieldInfos",void 0),t([J("fieldInfos")],U.prototype,"writeFieldInfos",null),t([p({type:O})],U.prototype,"layerOptions",void 0),t([J("layerOptions")],U.prototype,"writeLayerOptions",null),t([p({type:Boolean,json:{read:{source:"showLastEditInfo"},write:{target:"showLastEditInfo"},default:!0}})],U.prototype,"lastEditInfoEnabled",void 0),t([p()],U.prototype,"outFields",void 0),t([p()],U.prototype,"overwriteActions",void 0),t([p()],U.prototype,"returnGeometry",void 0),t([p({json:{type:String}})],U.prototype,"title",void 0),t([J("title")],U.prototype,"writeTitle",null),U=t([a("esri.PopupTemplate")],U);const q=U;export{q as default};