@arcgis/coding-components 4.30.0 → 4.31.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +3 -3
- package/dist/arcgis-coding-components/assets/code-editor/arcade.worker.js +13 -13
- package/dist/arcgis-coding-components/assets/code-editor/css.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/html.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/json.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/sql-expr.worker.js +11 -0
- package/dist/arcgis-coding-components/assets/code-editor/ts.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/sql-expression-editor/api/sql-expression-api.t9n.en.json +735 -0
- package/dist/arcgis-coding-components/index.esm.js +3 -3
- package/dist/arcgis-coding-components/p-025fda85.js +6 -0
- package/dist/arcgis-coding-components/{p-b7981062.js → p-02cae55d.js} +4 -4
- package/dist/arcgis-coding-components/p-193ac44f.js +6 -0
- package/dist/arcgis-coding-components/{p-ed5c78ce.js → p-22253750.js} +2 -2
- package/dist/arcgis-coding-components/p-4fc79a07.entry.js +6 -0
- package/dist/arcgis-coding-components/p-50484a4f.js +6 -0
- package/dist/arcgis-coding-components/p-6e28fd70.js +6 -0
- package/dist/arcgis-coding-components/p-7164c348.js +6 -0
- package/dist/arcgis-coding-components/p-767b17ee.entry.js +6 -0
- package/dist/arcgis-coding-components/{p-69ef969a.js → p-790067b1.js} +11 -11
- package/dist/arcgis-coding-components/{p-e9510c84.js → p-8196fa73.js} +3 -3
- package/dist/arcgis-coding-components/{p-f40fe9c5.js → p-8cf09bcc.js} +2 -2
- package/dist/arcgis-coding-components/{p-ca3f5530.js → p-923858b5.js} +3 -3
- package/dist/arcgis-coding-components/{p-ae0db715.js → p-960aa9dc.js} +3 -3
- package/dist/arcgis-coding-components/p-9956a574.js +6 -0
- package/dist/arcgis-coding-components/{p-9770fb37.js → p-ab78d6c4.js} +4 -4
- package/dist/arcgis-coding-components/{p-e37595ba.js → p-ad75160d.js} +4 -4
- package/dist/arcgis-coding-components/{p-24fb1d11.js → p-da9431ba.js} +3 -3
- package/dist/arcgis-coding-components/p-f452d4b8.entry.js +6 -0
- package/dist/cjs/{app-globals-18ba6880.js → app-globals-bade840e.js} +2 -2
- package/dist/cjs/arcade-defaults-8b8d6c07.js +116 -0
- package/dist/cjs/arcade-language-features-747fb1da.js +274 -0
- package/dist/cjs/arcade-mode-dce44622.js +336 -0
- package/dist/cjs/{arcgis-arcade-api_6.cjs.entry.js → arcgis-arcade-editor_6.cjs.entry.js} +3806 -5154
- package/dist/cjs/arcgis-coding-components.cjs.js +5 -5
- package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +81 -0
- package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +80 -0
- package/dist/cjs/{css-d8a65bb9.js → css-077ba0c5.js} +2 -2
- package/dist/cjs/{cssMode-07dbb853.js → cssMode-7f2030db.js} +5 -5
- package/dist/cjs/{html-bb10cced.js → html-e3a243e9.js} +5 -5
- package/dist/cjs/{htmlMode-7df0a09d.js → htmlMode-c273d6dc.js} +5 -5
- package/dist/cjs/{index-15bcce7e.js → index-37a86ff4.js} +12 -4
- package/dist/cjs/index.cjs.js +5 -4
- package/dist/cjs/{javascript-f0dbed11.js → javascript-7a33cca7.js} +5 -5
- package/dist/cjs/{jsonMode-9e54e9b7.js → jsonMode-6b4e0850.js} +5 -5
- package/dist/cjs/{arcade-defaults-d0931224.js → language-defaults-base-b32cb091.js} +88 -144
- package/dist/cjs/loader.cjs.js +5 -5
- package/dist/cjs/sql-expr-defaults-8a5834f3.js +1280 -0
- package/dist/cjs/sql-expr-mode-a72a1f92.js +21838 -0
- package/dist/cjs/{tsMode-ca28bc5f.js → tsMode-c2edcd57.js} +6 -6
- package/dist/cjs/{typescript-39540ed7.js → typescript-c50c5516.js} +5 -5
- package/dist/components/arcade-defaults.js +47 -1537
- package/dist/components/arcade-language-features.js +271 -0
- package/dist/components/arcade-mode.js +7 -267
- package/dist/components/arcade-results.js +7 -7
- package/dist/components/arcade-suggestions.js +8 -8
- package/dist/components/arcade-variables.js +7 -7
- package/dist/components/arcgis-arcade-editor.js +49 -50
- package/dist/components/arcgis-arcade-results.js +2 -2
- package/dist/components/arcgis-arcade-suggestions.js +2 -2
- package/dist/components/arcgis-arcade-variables.js +2 -2
- package/dist/components/arcgis-assets.d.ts +2 -2
- package/dist/components/arcgis-assets.js +3 -3
- package/dist/components/arcgis-code-editor.js +2 -2
- package/dist/components/arcgis-language-api-panel.d.ts +11 -0
- package/dist/components/arcgis-language-api-panel.js +11 -0
- package/dist/components/arcgis-sql-expression-editor.d.ts +11 -0
- package/dist/components/arcgis-sql-expression-editor.js +120 -0
- package/dist/components/arcgis-sql-expression-fields.d.ts +11 -0
- package/dist/components/arcgis-sql-expression-fields.js +11 -0
- package/dist/components/chunk-3IUJHIAA.js +1154 -0
- package/dist/components/code-editor.js +186 -17
- package/dist/components/fields.js +3 -3
- package/dist/components/index.js +2 -2
- package/dist/components/index2.js +31 -23
- package/dist/components/{arcade-api.js → language-api-panel.js} +29 -60
- package/dist/components/language-defaults-base.js +1535 -0
- package/dist/components/markdown.js +3 -3
- package/dist/components/sql-expr-defaults.js +131 -0
- package/dist/components/sql-expr-mode.js +21836 -0
- package/dist/components/sql-expression-fields.js +102 -0
- package/dist/components/useT9n.js +46 -9
- package/dist/components/utilities.js +2 -2
- package/dist/esm/{app-globals-2a0e9afb.js → app-globals-ed47e16d.js} +2 -2
- package/dist/esm/arcade-defaults-562fe19b.js +111 -0
- package/dist/esm/arcade-language-features-8edb3527.js +269 -0
- package/dist/esm/{arcade-mode-e9728a63.js → arcade-mode-ad036f46.js} +7 -266
- package/dist/esm/{arcgis-arcade-api_6.entry.js → arcgis-arcade-editor_6.entry.js} +3793 -5141
- package/dist/esm/arcgis-coding-components.js +6 -6
- package/dist/esm/arcgis-sql-expression-editor.entry.js +77 -0
- package/dist/esm/arcgis-sql-expression-fields.entry.js +76 -0
- package/dist/esm/{css-61c794c2.js → css-810518f1.js} +2 -2
- package/dist/esm/{cssMode-6e0ccd51.js → cssMode-a7208024.js} +4 -4
- package/dist/esm/{html-44ad432e.js → html-e187d7d8.js} +4 -4
- package/dist/esm/{htmlMode-fd336434.js → htmlMode-06b7bae2.js} +4 -4
- package/dist/esm/{index-0d124a57.js → index-3743d31f.js} +12 -4
- package/dist/esm/index.js +5 -4
- package/dist/esm/{javascript-ac057954.js → javascript-04a3f866.js} +5 -5
- package/dist/esm/{jsonMode-ea8fa529.js → jsonMode-ee8bb2ea.js} +4 -4
- package/dist/esm/{arcade-defaults-811bdd4d.js → language-defaults-base-52a397f5.js} +82 -142
- package/dist/esm/loader.js +6 -6
- package/dist/esm/sql-expr-defaults-f7c2d5ef.js +1274 -0
- package/dist/esm/sql-expr-mode-433b4a39.js +21835 -0
- package/dist/esm/{tsMode-af9c3001.js → tsMode-c80c462e.js} +4 -4
- package/dist/esm/{typescript-baec45d6.js → typescript-a9b8caa7.js} +4 -4
- package/dist/loader/cdn.js +2 -2
- package/dist/loader/index.cjs.js +2 -2
- package/dist/loader/index.es2017.js +2 -2
- package/dist/loader/index.js +2 -2
- package/dist/types/components/arcade-editor/arcade-editor.d.ts +45 -10
- package/dist/types/components/arcade-results/arcade-results.d.ts +43 -1
- package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +22 -1
- package/dist/types/components/arcade-variables/arcade-variables.d.ts +28 -1
- package/dist/types/components/code-editor/code-editor.d.ts +16 -5
- package/dist/types/components/language-api-panel/language-api-panel.d.ts +73 -0
- package/dist/types/components/sql-expression-editor/sql-expression-editor.d.ts +24 -0
- package/dist/types/components/sql-expression-fields/sql-expression-fields.d.ts +32 -0
- package/dist/types/components.d.ts +148 -70
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +13 -0
- package/dist/types/dependencies.d.ts +21 -0
- package/dist/types/utils/arcade-monaco/arcade-contribution.d.ts +1 -24
- package/dist/types/utils/arcade-monaco/arcade-defaults.d.ts +12 -49
- package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +6 -4
- package/dist/types/utils/arcade-monaco/arcade-mode.d.ts +3 -2
- package/dist/types/utils/arcade-monaco/arcade-service-accessors.d.ts +31 -0
- package/dist/types/utils/arcade-monaco/arcade-worker-manager.d.ts +3 -2
- package/dist/types/utils/arcade-monaco/arcade.worker.d.ts +5 -5
- package/dist/types/utils/arcade-monaco/types.d.ts +6 -35
- package/dist/types/utils/language-defaults-base.d.ts +69 -0
- package/dist/types/utils/profile/predefined-profile.d.ts +3 -1
- package/dist/types/utils/profile/types.d.ts +29 -69
- package/dist/types/utils/profile/utils.d.ts +4 -7
- package/dist/types/utils/sql-expr-monaco/DependentFiles/DateOnly.d.ts +41 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlInterval.d.ts +16 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlTimestampOffset.d.ts +26 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/TimeOnly.d.ts +37 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/UnknownTimeZone.d.ts +11 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/WhereGrammar.d.ts +122 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlCompareUtils.d.ts +5 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlDateParsingUtils.d.ts +18 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlUtils.d.ts +6 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/standardizedFunctions.d.ts +156 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/support.d.ts +150 -0
- package/dist/types/utils/sql-expr-monaco/PeggyGrammar/sql92grammar.d.ts +1397 -0
- package/dist/types/utils/sql-expr-monaco/libraries/date/properties/index.d.ts +59 -0
- package/dist/types/utils/sql-expr-monaco/libraries/numeric/properties/index.d.ts +295 -0
- package/dist/types/utils/sql-expr-monaco/libraries/string/properties/index.d.ts +135 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-completion.d.ts +6 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-contribution.d.ts +11 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-defaults.d.ts +22 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-language-features.d.ts +61 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-language-syntax.d.ts +8 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-mode.d.ts +10 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation-adapter.d.ts +3 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation-diagnostic-adapter.d.ts +41 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation-utils.d.ts +99 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation.d.ts +41 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-worker-manager.d.ts +15 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr.worker.d.ts +21 -0
- package/dist/types/utils/sql-expr-monaco/types.d.ts +91 -0
- package/dist/types/utils/sql-expr-profile/predefined-profile.d.ts +2 -0
- package/package.json +23 -17
- package/dist/arcgis-coding-components/p-98cf909d.js +0 -6
- package/dist/arcgis-coding-components/p-bf047552.entry.js +0 -6
- package/dist/arcgis-coding-components/p-f602fc86.js +0 -6
- package/dist/cjs/arcade-mode-8424eafa.js +0 -595
- package/dist/components/arcade-contribution.js +0 -181
- package/dist/components/arcgis-arcade-api.d.ts +0 -11
- package/dist/components/arcgis-arcade-api.js +0 -11
- package/dist/components/chunk-2CDDVOQU.js +0 -1364
- package/dist/types/components/arcade-api/arcade-api.d.ts +0 -45
- package/dist/types/components/arcade-api/t9n-types.d.ts +0 -8
- package/dist/types/components/arcade-editor/t9n-types.d.ts +0 -8
- package/dist/types/components/arcade-results/t9n-types.d.ts +0 -13
- package/dist/types/components/arcade-suggestions/t9n-types.d.ts +0 -6
- package/dist/types/components/arcade-variables/t9n-types.d.ts +0 -8
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ar.json → language-api-panel/t9n/language-api-panel.t9n.ar.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.bg.json → language-api-panel/t9n/language-api-panel.t9n.bg.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.bs.json → language-api-panel/t9n/language-api-panel.t9n.bs.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ca.json → language-api-panel/t9n/language-api-panel.t9n.ca.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.cs.json → language-api-panel/t9n/language-api-panel.t9n.cs.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.da.json → language-api-panel/t9n/language-api-panel.t9n.da.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.de.json → language-api-panel/t9n/language-api-panel.t9n.de.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.el.json → language-api-panel/t9n/language-api-panel.t9n.el.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.en.json → language-api-panel/t9n/language-api-panel.t9n.en.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.es.json → language-api-panel/t9n/language-api-panel.t9n.es.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.et.json → language-api-panel/t9n/language-api-panel.t9n.et.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.fi.json → language-api-panel/t9n/language-api-panel.t9n.fi.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.fr.json → language-api-panel/t9n/language-api-panel.t9n.fr.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.he.json → language-api-panel/t9n/language-api-panel.t9n.he.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.hr.json → language-api-panel/t9n/language-api-panel.t9n.hr.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.hu.json → language-api-panel/t9n/language-api-panel.t9n.hu.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.id.json → language-api-panel/t9n/language-api-panel.t9n.id.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.it.json → language-api-panel/t9n/language-api-panel.t9n.it.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ja.json → language-api-panel/t9n/language-api-panel.t9n.ja.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ko.json → language-api-panel/t9n/language-api-panel.t9n.ko.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.lt.json → language-api-panel/t9n/language-api-panel.t9n.lt.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.lv.json → language-api-panel/t9n/language-api-panel.t9n.lv.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.nb.json → language-api-panel/t9n/language-api-panel.t9n.nb.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.nl.json → language-api-panel/t9n/language-api-panel.t9n.nl.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.pl.json → language-api-panel/t9n/language-api-panel.t9n.pl.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.pt-BR.json → language-api-panel/t9n/language-api-panel.t9n.pt-BR.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.pt-PT.json → language-api-panel/t9n/language-api-panel.t9n.pt-PT.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ro.json → language-api-panel/t9n/language-api-panel.t9n.ro.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.ru.json → language-api-panel/t9n/language-api-panel.t9n.ru.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.sk.json → language-api-panel/t9n/language-api-panel.t9n.sk.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.sl.json → language-api-panel/t9n/language-api-panel.t9n.sl.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.sr.json → language-api-panel/t9n/language-api-panel.t9n.sr.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.sv.json → language-api-panel/t9n/language-api-panel.t9n.sv.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.th.json → language-api-panel/t9n/language-api-panel.t9n.th.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.tr.json → language-api-panel/t9n/language-api-panel.t9n.tr.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.uk.json → language-api-panel/t9n/language-api-panel.t9n.uk.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.vi.json → language-api-panel/t9n/language-api-panel.t9n.vi.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.zh-CN.json → language-api-panel/t9n/language-api-panel.t9n.zh-CN.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.zh-HK.json → language-api-panel/t9n/language-api-panel.t9n.zh-HK.json} +0 -0
- /package/dist/arcgis-coding-components/assets/{arcade-api/t9n/arcade-api.t9n.zh-TW.json → language-api-panel/t9n/language-api-panel.t9n.zh-TW.json} +0 -0
|
@@ -0,0 +1,1535 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
* See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
|
+
* v4.31.0-next.10
|
|
5
|
+
*/
|
|
6
|
+
import { CompletionItemKind, InsertTextMode, InsertTextFormat } from 'vscode-languageserver-types';
|
|
7
|
+
import { p as portalItemPageUrl } from './utilities.js';
|
|
8
|
+
import { n as newLayersFeatureLayer, i as importRequest, s as supportedFields, a as newPortalPortalItem, b as newWebScene, c as newWebMap, f as fieldAlias, d as fieldTypeToIconName, e as fieldTypeToArcadeType } from './fields.js';
|
|
9
|
+
import { i as isNotNull, a as isNotUndefined, b as addLTRMark, s as setValuesInString, c as supportedLocales } from './index2.js';
|
|
10
|
+
import { Emitter, Uri } from 'monaco-editor';
|
|
11
|
+
import { getArcgisAssetPath as getAssetPath } from "./arcgis-assets.js";
|
|
12
|
+
|
|
13
|
+
//#region Type Guards
|
|
14
|
+
function isFeatureLayerLikeInstance(item) {
|
|
15
|
+
return (!!item &&
|
|
16
|
+
typeof item === "object" &&
|
|
17
|
+
"declaredClass" in item &&
|
|
18
|
+
typeof item.declaredClass === "string" &&
|
|
19
|
+
item.declaredClass.startsWith("esri.layers.") &&
|
|
20
|
+
isFieldsDefinition(item) &&
|
|
21
|
+
"queryFeatures" in item &&
|
|
22
|
+
typeof item.queryFeatures === "function");
|
|
23
|
+
}
|
|
24
|
+
function isGroupLayerCapable(item) {
|
|
25
|
+
return (!!item &&
|
|
26
|
+
typeof item === "object" &&
|
|
27
|
+
"allLayers" in item &&
|
|
28
|
+
"allTables" in item &&
|
|
29
|
+
typeof item.allLayers === "object" &&
|
|
30
|
+
typeof item.allTables === "object");
|
|
31
|
+
}
|
|
32
|
+
function isMapInstance(item) {
|
|
33
|
+
return (!!item &&
|
|
34
|
+
typeof item === "object" &&
|
|
35
|
+
"declaredClass" in item &&
|
|
36
|
+
typeof item.declaredClass === "string" &&
|
|
37
|
+
(item.declaredClass === "esri.Map" ||
|
|
38
|
+
item.declaredClass === "esri.WebMap" ||
|
|
39
|
+
item.declaredClass === "esri.WebScene"));
|
|
40
|
+
}
|
|
41
|
+
function isLoadAllCapable(item) {
|
|
42
|
+
return !!item && typeof item === "object" && "loadAll" in item && typeof item.loadAll === "function";
|
|
43
|
+
}
|
|
44
|
+
function isPortalItemDefinition(item) {
|
|
45
|
+
return !!item && typeof item === "object" && "portalItem" in item && item.portalItem != null;
|
|
46
|
+
}
|
|
47
|
+
function isFeatureLayerItemDefinition(item) {
|
|
48
|
+
return !!item && typeof item === "object" && "portalItem" in item && item.portalItem != null;
|
|
49
|
+
}
|
|
50
|
+
function isFieldsDefinition(item) {
|
|
51
|
+
return !!item && typeof item === "object" && "fields" in item && Array.isArray(item.fields);
|
|
52
|
+
}
|
|
53
|
+
function isUrlDefinition(item) {
|
|
54
|
+
return !!item && typeof item === "object" && "url" in item && typeof item.url === "string";
|
|
55
|
+
}
|
|
56
|
+
function isSupportedServiceUrlDefinition(item) {
|
|
57
|
+
return isUrlDefinition(item) && /\/(?:featureserver|mapserver)(?:\/|$)/iu.test(item.url);
|
|
58
|
+
}
|
|
59
|
+
function isSubtypeInstance(item) {
|
|
60
|
+
return (!!item &&
|
|
61
|
+
typeof item === "object" &&
|
|
62
|
+
"declaredClass" in item &&
|
|
63
|
+
item.declaredClass === "esri.layers.support.Subtype");
|
|
64
|
+
}
|
|
65
|
+
function isCodedValueDomainInstance(item) {
|
|
66
|
+
return (!!item &&
|
|
67
|
+
typeof item === "object" &&
|
|
68
|
+
"declaredClass" in item &&
|
|
69
|
+
item.declaredClass === "esri.layers.support.CodedValueDomain");
|
|
70
|
+
}
|
|
71
|
+
function isInheritedDomainInstance(item) {
|
|
72
|
+
return (!!item &&
|
|
73
|
+
typeof item === "object" &&
|
|
74
|
+
"declaredClass" in item &&
|
|
75
|
+
item.declaredClass === "esri.layers.support.InheritedDomain");
|
|
76
|
+
}
|
|
77
|
+
function isPredefinedProfile(item) {
|
|
78
|
+
return (!!item &&
|
|
79
|
+
typeof item === "object" &&
|
|
80
|
+
"id" in item &&
|
|
81
|
+
typeof item.id === "string" &&
|
|
82
|
+
"definitions" in item &&
|
|
83
|
+
typeof item.definitions === "object" &&
|
|
84
|
+
!Array.isArray(item.definitions));
|
|
85
|
+
}
|
|
86
|
+
function isTitleCapableSource(item) {
|
|
87
|
+
return !!item && typeof item === "object" && "title" in item && typeof item.title === "string";
|
|
88
|
+
}
|
|
89
|
+
function isUrlCapableSource(item) {
|
|
90
|
+
return !!item && typeof item === "object" && "url" in item && typeof item.url === "string";
|
|
91
|
+
}
|
|
92
|
+
function isLayerIdCapableSource(item) {
|
|
93
|
+
return !!item && typeof item === "object" && "layerId" in item && typeof item.layerId === "number";
|
|
94
|
+
}
|
|
95
|
+
function isFeatureTypesCapableLayer(item) {
|
|
96
|
+
return !!item && typeof item === "object" && "typeIdField" in item && "types" in item;
|
|
97
|
+
}
|
|
98
|
+
function isDomainsCapableLayer(item) {
|
|
99
|
+
return !!item && typeof item === "object" && "getFieldDomain" in item && typeof item.getFieldDomain === "function";
|
|
100
|
+
}
|
|
101
|
+
function isSubtypeFieldCapableLayer(item) {
|
|
102
|
+
return !!item && typeof item === "object" && "subtypeField" in item;
|
|
103
|
+
}
|
|
104
|
+
function isSubtypesCapableLayer(item) {
|
|
105
|
+
return isSubtypeFieldCapableLayer(item) && "subtypes" in item;
|
|
106
|
+
}
|
|
107
|
+
function isPortalItemCapable(item) {
|
|
108
|
+
return !!item && typeof item === "object" && "portalItem" in item;
|
|
109
|
+
}
|
|
110
|
+
function isRelationshipsCapableLayer(item) {
|
|
111
|
+
return (isLayerIdCapableSource(item) &&
|
|
112
|
+
"relationships" in item &&
|
|
113
|
+
"url" in item &&
|
|
114
|
+
Array.isArray(item.relationships) &&
|
|
115
|
+
typeof item.url === "string");
|
|
116
|
+
}
|
|
117
|
+
function isTableCapableLayer(item) {
|
|
118
|
+
return !!item && typeof item === "object" && "isTable" in item && typeof item.isTable === "boolean";
|
|
119
|
+
}
|
|
120
|
+
function isLoadableSource(item) {
|
|
121
|
+
return !!item && typeof item === "object" && "load" in item && typeof item.load === "function";
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region Service Metadata
|
|
125
|
+
async function supportedSourceFromDefinition(definition) {
|
|
126
|
+
if (!definition) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
let source = null;
|
|
130
|
+
if (isFieldsDefinition(definition)) {
|
|
131
|
+
source = definition;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
source = await newLayersFeatureLayer(definition);
|
|
135
|
+
}
|
|
136
|
+
if (isLoadableSource(source)) {
|
|
137
|
+
await source.load();
|
|
138
|
+
}
|
|
139
|
+
return source;
|
|
140
|
+
}
|
|
141
|
+
async function serviceMetaData(url) {
|
|
142
|
+
url += "/layers";
|
|
143
|
+
const request = await importRequest();
|
|
144
|
+
const response = await request(url, { responseType: "json", query: { f: "json" } });
|
|
145
|
+
const queryCapability = url.endsWith("MapServer/layers") ? "data" : "query";
|
|
146
|
+
const layers = getSupportedLayerInfos(response.data?.layers, queryCapability);
|
|
147
|
+
const tables = getSupportedLayerInfos(response.data?.tables, queryCapability);
|
|
148
|
+
return { layers, tables };
|
|
149
|
+
}
|
|
150
|
+
function getSupportedLayerInfos(layers, queryCapability) {
|
|
151
|
+
if (!layers) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
return layers.filter((layer) => {
|
|
155
|
+
switch (layer.type) {
|
|
156
|
+
case "Feature Layer":
|
|
157
|
+
case "Oriented Imagery Layer":
|
|
158
|
+
case "Catalog Layer":
|
|
159
|
+
case "Table": {
|
|
160
|
+
const capabilities = layer.capabilities
|
|
161
|
+
? layer.capabilities
|
|
162
|
+
.toLowerCase()
|
|
163
|
+
.split(",")
|
|
164
|
+
.map((value) => value.trim())
|
|
165
|
+
: [];
|
|
166
|
+
return capabilities.includes(queryCapability);
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region Support functions
|
|
177
|
+
async function getRelatedFeatureLayer(layer, relationship) {
|
|
178
|
+
const relatedFeatureLayer = await newLayersFeatureLayer({ url: `${layer.url}/${relationship.relatedTableId}` });
|
|
179
|
+
await relatedFeatureLayer.load();
|
|
180
|
+
return relatedFeatureLayer;
|
|
181
|
+
}
|
|
182
|
+
function sortFields(layer) {
|
|
183
|
+
return (firstField, secondField) => {
|
|
184
|
+
if (firstField.type === "oid") {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
if (secondField.type === "oid") {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
if (isSubtypeFieldCapableLayer(layer)) {
|
|
191
|
+
if (firstField.name === layer.subtypeField) {
|
|
192
|
+
return -1;
|
|
193
|
+
}
|
|
194
|
+
if (secondField.name === layer.subtypeField) {
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (isFeatureTypesCapableLayer(layer)) {
|
|
199
|
+
if (firstField.name === layer.typeIdField) {
|
|
200
|
+
return -1;
|
|
201
|
+
}
|
|
202
|
+
if (secondField.name === layer.typeIdField) {
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return firstField.name.localeCompare(secondField.name, "en", { sensitivity: "base" });
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function areAllDomainsInherited(types, field) {
|
|
210
|
+
return types?.every((type) => type.domains?.[field.name]?.type === "inherited") ?? false;
|
|
211
|
+
}
|
|
212
|
+
// const validIdentifierExpr = new RegExp(/^[a-z_$][\w$]*$/gi);
|
|
213
|
+
const validIdentifierExpr = /^[a-z_$][a-z0-9_$]*$/giu;
|
|
214
|
+
function getMemberExpressionProperty(prop, includeDot = true) {
|
|
215
|
+
if (prop.match(validIdentifierExpr)) {
|
|
216
|
+
return `${includeDot ? "." : ""}${prop}`;
|
|
217
|
+
}
|
|
218
|
+
return `["${prop}"]`;
|
|
219
|
+
}
|
|
220
|
+
function assembleMemberExpression(obj, prop) {
|
|
221
|
+
if (!obj) {
|
|
222
|
+
return prop;
|
|
223
|
+
}
|
|
224
|
+
return `${obj}${getMemberExpressionProperty(prop)}`;
|
|
225
|
+
}
|
|
226
|
+
function getMapPortalItem(map) {
|
|
227
|
+
if (isPortalItemCapable(map)) {
|
|
228
|
+
return map.portalItem;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region Editor Profile to Language Service Profile functions
|
|
234
|
+
async function variablesToLSVariable(editorVariables, kind = CompletionItemKind.Variable) {
|
|
235
|
+
return await Promise.all(editorVariables.map(async (editorVariable) => {
|
|
236
|
+
switch (editorVariable.type) {
|
|
237
|
+
case "dictionary":
|
|
238
|
+
return await dictionaryToLSDictionary(editorVariable, kind);
|
|
239
|
+
case "feature":
|
|
240
|
+
return await featureToLSFeature(editorVariable, kind);
|
|
241
|
+
default:
|
|
242
|
+
return variableToLSVariable(editorVariable, kind);
|
|
243
|
+
}
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
function variableToLSVariable(editorVariable, kind) {
|
|
247
|
+
const { name, type } = editorVariable;
|
|
248
|
+
const description = editorVariable.getDescription();
|
|
249
|
+
return {
|
|
250
|
+
name,
|
|
251
|
+
description,
|
|
252
|
+
type,
|
|
253
|
+
completion: {
|
|
254
|
+
label: name,
|
|
255
|
+
detail: name,
|
|
256
|
+
insertText: name,
|
|
257
|
+
insertTextMode: InsertTextMode.asIs,
|
|
258
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
259
|
+
kind,
|
|
260
|
+
documentation: { kind: "markdown", value: description },
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async function featureToLSFeature(editorFeature, kind) {
|
|
265
|
+
// Get the source for the definition
|
|
266
|
+
const source = await editorFeature.loadSource();
|
|
267
|
+
const { name } = editorFeature;
|
|
268
|
+
const description = editorFeature.getDescription();
|
|
269
|
+
const resultCompletion = {
|
|
270
|
+
label: name,
|
|
271
|
+
detail: name,
|
|
272
|
+
insertText: name,
|
|
273
|
+
insertTextMode: InsertTextMode.asIs,
|
|
274
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
275
|
+
kind,
|
|
276
|
+
};
|
|
277
|
+
const result = {
|
|
278
|
+
name,
|
|
279
|
+
description,
|
|
280
|
+
type: "dictionary",
|
|
281
|
+
properties: [],
|
|
282
|
+
completion: resultCompletion,
|
|
283
|
+
};
|
|
284
|
+
// No source definition, then it will be a feature without any known fields
|
|
285
|
+
if (!source) {
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
// Create properties for the fields and the aliases
|
|
289
|
+
// Also improve the feature completion documentation
|
|
290
|
+
let featureCompletionDescription = description;
|
|
291
|
+
const fieldProfileValues = [];
|
|
292
|
+
const aliasProfileValues = [];
|
|
293
|
+
supportedFields(source.fields).forEach((field) => {
|
|
294
|
+
let fieldCompletionDescription = `**${field.name}** \n${field.type}`;
|
|
295
|
+
if (field.description) {
|
|
296
|
+
fieldCompletionDescription += ` \n'${field.description}`;
|
|
297
|
+
}
|
|
298
|
+
if (featureCompletionDescription) {
|
|
299
|
+
featureCompletionDescription += " \n \n";
|
|
300
|
+
}
|
|
301
|
+
featureCompletionDescription += `**${field.name}** (${fieldAlias(field)}) \n${field.type}`;
|
|
302
|
+
if (field.description) {
|
|
303
|
+
featureCompletionDescription += ` \n'${field.description}`;
|
|
304
|
+
}
|
|
305
|
+
// The property for the field
|
|
306
|
+
const type = fieldTypeToArcadeType(field);
|
|
307
|
+
const insertText = getMemberExpressionProperty(field.name, false);
|
|
308
|
+
const description = fieldAlias(field);
|
|
309
|
+
fieldProfileValues.push({
|
|
310
|
+
name: field.name,
|
|
311
|
+
description,
|
|
312
|
+
type,
|
|
313
|
+
completion: {
|
|
314
|
+
label: field.name,
|
|
315
|
+
detail: description,
|
|
316
|
+
insertText,
|
|
317
|
+
insertTextMode: InsertTextMode.asIs,
|
|
318
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
319
|
+
kind: CompletionItemKind.Field,
|
|
320
|
+
documentation: { kind: "markdown", value: fieldCompletionDescription },
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
if (!field.alias || field.alias.toLowerCase() === field.name.toLowerCase()) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// The property for the alias if different than the field name
|
|
327
|
+
let aliasCompletionDescription = `**${field.alias}** \n${field.type}`;
|
|
328
|
+
if (field.description) {
|
|
329
|
+
aliasCompletionDescription += ` \n'${field.description}`;
|
|
330
|
+
}
|
|
331
|
+
aliasProfileValues.push({
|
|
332
|
+
name: field.alias,
|
|
333
|
+
description: field.name,
|
|
334
|
+
type,
|
|
335
|
+
completion: {
|
|
336
|
+
label: field.alias,
|
|
337
|
+
detail: field.name,
|
|
338
|
+
insertText,
|
|
339
|
+
insertTextMode: InsertTextMode.asIs,
|
|
340
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
341
|
+
kind: CompletionItemKind.Field,
|
|
342
|
+
documentation: { kind: "markdown", value: aliasCompletionDescription },
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
result.properties = [...fieldProfileValues, ...aliasProfileValues];
|
|
347
|
+
resultCompletion.documentation = { kind: "markdown", value: featureCompletionDescription };
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
async function dictionaryToLSDictionary(editorDictionary, kind) {
|
|
351
|
+
const { name, dictionaryVariables: variables } = editorDictionary;
|
|
352
|
+
const description = editorDictionary.getDescription();
|
|
353
|
+
const completionDescription = variables.reduce((previous, p) => {
|
|
354
|
+
if (previous !== "") {
|
|
355
|
+
previous += " \n \n";
|
|
356
|
+
}
|
|
357
|
+
previous += `**${p.name}** \n${p.type}`;
|
|
358
|
+
const description = p.getDescription();
|
|
359
|
+
if (description) {
|
|
360
|
+
previous += ` \n${description}`;
|
|
361
|
+
}
|
|
362
|
+
return previous;
|
|
363
|
+
}, description);
|
|
364
|
+
return {
|
|
365
|
+
name,
|
|
366
|
+
description,
|
|
367
|
+
type: "dictionary",
|
|
368
|
+
properties: await variablesToLSVariable(variables, CompletionItemKind.Field),
|
|
369
|
+
completion: {
|
|
370
|
+
label: name,
|
|
371
|
+
detail: name,
|
|
372
|
+
insertText: name,
|
|
373
|
+
insertTextMode: InsertTextMode.asIs,
|
|
374
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
375
|
+
kind,
|
|
376
|
+
documentation: { kind: "markdown", value: completionDescription },
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Represents a item in the EditorProfile. The profile is converted into an optimized way for
|
|
382
|
+
* rendering in the editor. In addition to the representation of profile variables, other
|
|
383
|
+
* structures are created such as groups.
|
|
384
|
+
*/
|
|
385
|
+
class ProfileItemBase {
|
|
386
|
+
constructor(_profile, _label, description) {
|
|
387
|
+
this._profile = _profile;
|
|
388
|
+
this._label = _label;
|
|
389
|
+
this.description = description;
|
|
390
|
+
this.filterDescription = false;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Returns the label string.
|
|
394
|
+
*/
|
|
395
|
+
getLabel() {
|
|
396
|
+
if (this._label == null) {
|
|
397
|
+
return "";
|
|
398
|
+
}
|
|
399
|
+
if (typeof this._label === "string") {
|
|
400
|
+
// Some of our variables can start with a $ sign.
|
|
401
|
+
// If the component is under RTL, the string is messed up.
|
|
402
|
+
// It is converted from $feature to feature$, This is not acceptable since the label
|
|
403
|
+
// represents a variable name. We are adding in front of the $ sign a right to left mark.
|
|
404
|
+
return addLTRMark(this._label);
|
|
405
|
+
}
|
|
406
|
+
return setValuesInString(this._profile?.intlStrings[this._label.code], this._label.formatValues);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Returns the description string.
|
|
410
|
+
*/
|
|
411
|
+
getDescription() {
|
|
412
|
+
if (this.description == null) {
|
|
413
|
+
return "";
|
|
414
|
+
}
|
|
415
|
+
if (typeof this.description === "string") {
|
|
416
|
+
return this.description;
|
|
417
|
+
}
|
|
418
|
+
return setValuesInString(this._profile?.intlStrings[this.description.code], this.description.formatValues);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Returns true if the item pass the filter test
|
|
422
|
+
*/
|
|
423
|
+
passFilter(filterExpression) {
|
|
424
|
+
if (!filterExpression) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
if (filterExpression.test(this.getLabel())) {
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
return this.filterDescription && filterExpression.test(this.getDescription());
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* The base class for profile variables representation in the EditorProfile.
|
|
435
|
+
*/
|
|
436
|
+
class VariableBase extends ProfileItemBase {
|
|
437
|
+
constructor(props) {
|
|
438
|
+
super(props.profile, props.label, props.description ?? props.declaration?.description);
|
|
439
|
+
this.declaration = props.declaration ?? {};
|
|
440
|
+
this.name = props.declaration?.name ?? "";
|
|
441
|
+
this.snippet = props.snippet ?? "";
|
|
442
|
+
this.nonInteractive = props.nonInteractive ?? false;
|
|
443
|
+
this.filterDescription = props.filterDescription ?? false;
|
|
444
|
+
this.icon = props.icon;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Represents the IProfileValue.
|
|
449
|
+
*/
|
|
450
|
+
class ValueVariable extends VariableBase {
|
|
451
|
+
constructor(props) {
|
|
452
|
+
super(props);
|
|
453
|
+
this.type = "text";
|
|
454
|
+
this.isCollection = false;
|
|
455
|
+
this.type = props.declaration?.type ?? "text";
|
|
456
|
+
}
|
|
457
|
+
getDescription() {
|
|
458
|
+
if (this.description == null) {
|
|
459
|
+
return this._profile?.intlStrings[this.type.toLowerCase()] ?? "";
|
|
460
|
+
}
|
|
461
|
+
return super.getDescription();
|
|
462
|
+
}
|
|
463
|
+
toProfileVariableDefinition() {
|
|
464
|
+
return { type: this.type, name: "", ...this.declaration };
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Represents the IProfileArray. The main difference is that the IProfileValue type
|
|
469
|
+
* is used as valueType.
|
|
470
|
+
*/
|
|
471
|
+
class ArrayVariable extends VariableBase {
|
|
472
|
+
constructor(props) {
|
|
473
|
+
super(props);
|
|
474
|
+
this.type = "array";
|
|
475
|
+
this.isCollection = false;
|
|
476
|
+
this.elementType = props.declaration?.elementType ?? { type: "number", name: "number" };
|
|
477
|
+
}
|
|
478
|
+
getDescription() {
|
|
479
|
+
if (this.description == null) {
|
|
480
|
+
return this._profile?.intlStrings[this.type.toLowerCase()] ?? "";
|
|
481
|
+
}
|
|
482
|
+
return super.getDescription();
|
|
483
|
+
}
|
|
484
|
+
toProfileVariableDefinition() {
|
|
485
|
+
return { type: this.type, elementType: this.elementType, name: "", ...this.declaration };
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Represents a collection of items. The collection of items can be synchronous or
|
|
490
|
+
* asynchronous. If the collection is asynchronous then the collection should be
|
|
491
|
+
* loaded by using the function 'load'. The property 'loaded' indicates if the
|
|
492
|
+
* collection is ready or not.
|
|
493
|
+
*/
|
|
494
|
+
class CollectionBasedVariable extends VariableBase {
|
|
495
|
+
constructor(owner, props) {
|
|
496
|
+
super(props);
|
|
497
|
+
this.owner = owner;
|
|
498
|
+
this.isCollection = true;
|
|
499
|
+
this._loaded = true;
|
|
500
|
+
/**
|
|
501
|
+
* The collection of items used to display the profile.
|
|
502
|
+
* If the collection is asynchronous, the 'load' function should
|
|
503
|
+
* be called first before using the items.
|
|
504
|
+
*/
|
|
505
|
+
this.variables = [];
|
|
506
|
+
}
|
|
507
|
+
get breadcrumb() {
|
|
508
|
+
// If there's an owner, prepend its breadcrumb and append the current name
|
|
509
|
+
if (this.owner) {
|
|
510
|
+
const ownerBreadcrumb = this.owner.breadcrumb;
|
|
511
|
+
return ownerBreadcrumb ? `${ownerBreadcrumb} / ${this.name}` : this.name;
|
|
512
|
+
}
|
|
513
|
+
// If there's no owner, this is the root element, so just return its name
|
|
514
|
+
return this.name;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Returns true if the collection has been loaded
|
|
518
|
+
*/
|
|
519
|
+
get loaded() {
|
|
520
|
+
return this._loaded;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Returns an url to the associated information
|
|
524
|
+
*/
|
|
525
|
+
get informationUrl() {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
get informationType() {
|
|
529
|
+
return "";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
class GroupOfVariables extends ProfileItemBase {
|
|
533
|
+
constructor(profile, label, variables = []) {
|
|
534
|
+
super(profile, label);
|
|
535
|
+
this.variables = variables;
|
|
536
|
+
this.type = "group";
|
|
537
|
+
this.isCollection = true;
|
|
538
|
+
}
|
|
539
|
+
passFilter() {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
class DictionaryVariable extends CollectionBasedVariable {
|
|
544
|
+
constructor(owner, props) {
|
|
545
|
+
super(owner, props);
|
|
546
|
+
this.type = "dictionary";
|
|
547
|
+
/**
|
|
548
|
+
* The variables that the dictionary holds. It is different than the variables.
|
|
549
|
+
* The variables may contain grouping.
|
|
550
|
+
*/
|
|
551
|
+
this.dictionaryVariables = [];
|
|
552
|
+
this.loadPropertyDeclarations(props.declaration?.properties);
|
|
553
|
+
// If we have a snippet then wrap the properties in a group and use the snippet as the heading
|
|
554
|
+
// This is not applicable for root Dictionary such as Profile
|
|
555
|
+
if (this.snippet && this.dictionaryVariables.length) {
|
|
556
|
+
this.variables = [new GroupOfVariables(this._profile, this.snippet, this.dictionaryVariables)];
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
async loadSource() {
|
|
560
|
+
// No-op
|
|
561
|
+
}
|
|
562
|
+
loadPropertyDeclarations(declarations) {
|
|
563
|
+
this.dictionaryVariables = this.createVariableInstances(declarations);
|
|
564
|
+
this.variables = this.dictionaryVariables;
|
|
565
|
+
}
|
|
566
|
+
createVariableInstances(declarations) {
|
|
567
|
+
if (!Array.isArray(declarations)) {
|
|
568
|
+
return [];
|
|
569
|
+
}
|
|
570
|
+
const properties = [];
|
|
571
|
+
declarations.forEach((declaration) => {
|
|
572
|
+
const variable = this.createVariableInstance(declaration);
|
|
573
|
+
if (variable) {
|
|
574
|
+
properties.push(variable);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
return properties;
|
|
578
|
+
}
|
|
579
|
+
createVariableInstance(declaration) {
|
|
580
|
+
const snippet = assembleMemberExpression(this.snippet, declaration.name);
|
|
581
|
+
switch (declaration.type) {
|
|
582
|
+
case "number":
|
|
583
|
+
case "text":
|
|
584
|
+
case "boolean":
|
|
585
|
+
case "date":
|
|
586
|
+
case "dateOnly":
|
|
587
|
+
case "time":
|
|
588
|
+
case "geometry":
|
|
589
|
+
case "knowledgeGraph":
|
|
590
|
+
return new ValueVariable({ profile: this._profile, declaration, label: snippet, snippet });
|
|
591
|
+
case "feature":
|
|
592
|
+
return new FeatureVariable(this, { profile: this._profile, declaration, label: snippet, snippet });
|
|
593
|
+
case "featureSet":
|
|
594
|
+
return new FeatureSetVariable(this, { profile: this._profile, declaration, label: snippet, snippet }, [
|
|
595
|
+
new ValueVariable({ profile: this._profile, label: snippet, description: "", snippet }),
|
|
596
|
+
]);
|
|
597
|
+
case "featureSetCollection":
|
|
598
|
+
return new FeatureSetCollectionVariable(this, {
|
|
599
|
+
profile: this._profile,
|
|
600
|
+
declaration,
|
|
601
|
+
label: snippet,
|
|
602
|
+
snippet,
|
|
603
|
+
});
|
|
604
|
+
case "dictionary":
|
|
605
|
+
return new DictionaryVariable(this, {
|
|
606
|
+
profile: this._profile,
|
|
607
|
+
declaration,
|
|
608
|
+
label: snippet,
|
|
609
|
+
snippet,
|
|
610
|
+
});
|
|
611
|
+
case "array":
|
|
612
|
+
return new ArrayVariable({
|
|
613
|
+
profile: this._profile,
|
|
614
|
+
declaration,
|
|
615
|
+
label: snippet,
|
|
616
|
+
snippet,
|
|
617
|
+
});
|
|
618
|
+
default:
|
|
619
|
+
console.error("Editor profile: Invalid profile variable", declaration);
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
toProfileVariableDefinition() {
|
|
624
|
+
return {
|
|
625
|
+
type: this.type,
|
|
626
|
+
name: "",
|
|
627
|
+
...this.declaration,
|
|
628
|
+
properties: this.dictionaryVariables.map((variable) => variable.toProfileVariableDefinition()),
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
class SourceBasedVariable extends CollectionBasedVariable {
|
|
633
|
+
constructor(owner, props, relationshipsProperties) {
|
|
634
|
+
super(owner, props);
|
|
635
|
+
this.relationshipsProperties = relationshipsProperties;
|
|
636
|
+
this._source = null;
|
|
637
|
+
this._loaded = false;
|
|
638
|
+
this._definition = props.declaration?.definition;
|
|
639
|
+
}
|
|
640
|
+
get title() {
|
|
641
|
+
return isTitleCapableSource(this._source) ? this._source.title : "";
|
|
642
|
+
}
|
|
643
|
+
get url() {
|
|
644
|
+
return isUrlCapableSource(this._source) ? this._source.url : "";
|
|
645
|
+
}
|
|
646
|
+
get informationUrl() {
|
|
647
|
+
if (!this.loaded) {
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
if (!this.url) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
return isLayerIdCapableSource(this._source) ? `${this.url}/${this._source.layerId}` : this.url;
|
|
654
|
+
}
|
|
655
|
+
get informationType() {
|
|
656
|
+
return this._profile?.intlStrings.layer ?? "layer";
|
|
657
|
+
}
|
|
658
|
+
async loadSource() {
|
|
659
|
+
if (isNotNull(this._loadPromise) && isNotUndefined(this._loadPromise)) {
|
|
660
|
+
return await this._loadPromise;
|
|
661
|
+
}
|
|
662
|
+
this._loadPromise = this._loadSource();
|
|
663
|
+
return await this._loadPromise;
|
|
664
|
+
}
|
|
665
|
+
_getValueSnippet(field) {
|
|
666
|
+
// If the source is a feature, then we want to assemble the snippet ($feature) with the field name as a member expression
|
|
667
|
+
return this.type === "feature" ? assembleMemberExpression(this.snippet, field.name) : field.name;
|
|
668
|
+
}
|
|
669
|
+
_getSubtypeOrDomainNameSnippet(field) {
|
|
670
|
+
if (this.type !== "feature") {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
if (isSubtypeFieldCapableLayer(this._source) && field.name === this._source.subtypeField) {
|
|
674
|
+
return `SubtypeName(${this.snippet})`;
|
|
675
|
+
}
|
|
676
|
+
return `DomainName(${this.snippet}, "${field.name}")`;
|
|
677
|
+
}
|
|
678
|
+
_getFieldProperty(field) {
|
|
679
|
+
// Check if the field is the type id field or of the field has a coded domain.
|
|
680
|
+
// If it has then the property will be an exanpdable property (dictionary).
|
|
681
|
+
// Otherwise just return a simple value property.
|
|
682
|
+
const subtypesOrDomainValuesDictionary = this._getDomainDictionary(field);
|
|
683
|
+
if (subtypesOrDomainValuesDictionary) {
|
|
684
|
+
return subtypesOrDomainValuesDictionary;
|
|
685
|
+
}
|
|
686
|
+
// Create the value property
|
|
687
|
+
const valueSnippet = this._getValueSnippet(field);
|
|
688
|
+
return new ValueVariable({
|
|
689
|
+
profile: this._profile,
|
|
690
|
+
label: valueSnippet,
|
|
691
|
+
description: fieldAlias(field),
|
|
692
|
+
snippet: valueSnippet,
|
|
693
|
+
icon: fieldTypeToIconName(field),
|
|
694
|
+
filterDescription: true,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
_getDomainDictionary(field) {
|
|
698
|
+
if (!isDomainsCapableLayer(this._source)) {
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
// Note we have multiple scenarios:
|
|
702
|
+
// - Layers without subtypes or feature types: We will check if the field has a domain
|
|
703
|
+
// - Layers with only subtypes: We will parse the subtypes metadata and create a dictionary
|
|
704
|
+
// - Layers with only feature types: We will parse the feature types metadata
|
|
705
|
+
// - Layers with both subtypes and feature types: we will actually use the subtypes metadata
|
|
706
|
+
// Summary, we will always use the subtypes metadata if available.
|
|
707
|
+
if (isSubtypeFieldCapableLayer(this._source) && !!this._source.subtypeField) {
|
|
708
|
+
return this._getSubtypeDomainDictionary(field);
|
|
709
|
+
}
|
|
710
|
+
if (isFeatureTypesCapableLayer(this._source) && !!this._source.typeIdField) {
|
|
711
|
+
return this._getFeatureTypeDomainDictionary(field);
|
|
712
|
+
}
|
|
713
|
+
return this._getFieldDomainDictionary(field);
|
|
714
|
+
}
|
|
715
|
+
_getSubtypeDomainDictionary(field) {
|
|
716
|
+
// Should be tested before calling this function
|
|
717
|
+
if (!isSubtypeFieldCapableLayer(this._source)) {
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
// If the source has a subtype field but doesn't have subtypes, it is certainly a subtype sublayer
|
|
721
|
+
if (!isSubtypesCapableLayer(this._source)) {
|
|
722
|
+
// For the subtype field there is no domain
|
|
723
|
+
if (field.name === this._source.subtypeField) {
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
// For the other fields, we will use the getFieldDomain function
|
|
727
|
+
return this._getFieldDomainDictionary(field);
|
|
728
|
+
}
|
|
729
|
+
// The code here shoud be executed for layers that have subtypes
|
|
730
|
+
// Sepcial case for the subtype field
|
|
731
|
+
if (field.name === this._source.subtypeField) {
|
|
732
|
+
const domainDictionary = this._createDomainDictionary(field);
|
|
733
|
+
domainDictionary.icon = "subtype";
|
|
734
|
+
domainDictionary.variables.push(this._getTypeOrSubtypeDomainGroup(this._source.subtypes, field));
|
|
735
|
+
return domainDictionary;
|
|
736
|
+
}
|
|
737
|
+
// Check if all the domains for the field in the types are inherited.
|
|
738
|
+
// If it is we can simplify the structure by avoiding splitting in subtypes
|
|
739
|
+
if (areAllDomainsInherited(this._source.subtypes, field)) {
|
|
740
|
+
return this._getFieldDomainDictionary(field);
|
|
741
|
+
}
|
|
742
|
+
// We have domains per subtype
|
|
743
|
+
// We need to go thru each types and create a dictionary.
|
|
744
|
+
const domainValuesBySubtypeGroup = this._getDomainValuesGroup(this._source.subtypes, field);
|
|
745
|
+
if (!domainValuesBySubtypeGroup) {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
const domainDictionary = this._createDomainDictionary(field);
|
|
749
|
+
domainDictionary.variables.push(domainValuesBySubtypeGroup);
|
|
750
|
+
return domainDictionary;
|
|
751
|
+
}
|
|
752
|
+
_getFeatureTypeDomainDictionary(field) {
|
|
753
|
+
// SHould be tested before calling this function
|
|
754
|
+
if (!isFeatureTypesCapableLayer(this._source)) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
// Special case for the type id field
|
|
758
|
+
if (field.name === this._source.typeIdField) {
|
|
759
|
+
const domainDictionary = this._createDomainDictionary(field);
|
|
760
|
+
domainDictionary.variables.push(this._getTypeOrSubtypeDomainGroup(this._source.types, field));
|
|
761
|
+
return domainDictionary;
|
|
762
|
+
}
|
|
763
|
+
// Check if all the domains for the field in the types are inherited.
|
|
764
|
+
// If it is we can simplify the structure by avoiding splitting in subtypes
|
|
765
|
+
if (areAllDomainsInherited(this._source.types, field)) {
|
|
766
|
+
return this._getFieldDomainDictionary(field);
|
|
767
|
+
}
|
|
768
|
+
// We have domains per feature type
|
|
769
|
+
// We need to go thru each types and create a dictionary.
|
|
770
|
+
const domainValuesByFeatureTypeGroup = this._getDomainValuesGroup(this._source.types, field);
|
|
771
|
+
if (!domainValuesByFeatureTypeGroup) {
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
const domainDictionary = this._createDomainDictionary(field);
|
|
775
|
+
domainDictionary.variables.push(domainValuesByFeatureTypeGroup);
|
|
776
|
+
return domainDictionary;
|
|
777
|
+
}
|
|
778
|
+
_getFieldDomainDictionary(field) {
|
|
779
|
+
// SHould be tested before calling this function
|
|
780
|
+
if (!isDomainsCapableLayer(this._source)) {
|
|
781
|
+
return null;
|
|
782
|
+
}
|
|
783
|
+
const fieldDomain = this._source.getFieldDomain(field.name);
|
|
784
|
+
if (!isCodedValueDomainInstance(fieldDomain)) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
const domainValuesGroup = this._getCodedValueDomainGroup(fieldDomain, {
|
|
788
|
+
code: "domainvalues",
|
|
789
|
+
});
|
|
790
|
+
const domainDictionary = this._createDomainDictionary(field);
|
|
791
|
+
domainDictionary.variables.push(domainValuesGroup);
|
|
792
|
+
return domainDictionary;
|
|
793
|
+
}
|
|
794
|
+
_getTypeOrSubtypeDomainGroup(types, field) {
|
|
795
|
+
// Try the coded domain first
|
|
796
|
+
if (isCodedValueDomainInstance(field.domain)) {
|
|
797
|
+
return this._getCodedValueDomainGroup(field.domain, { code: "subtypes" });
|
|
798
|
+
}
|
|
799
|
+
// No coded domain, we will manufacture it
|
|
800
|
+
const values = types?.map((t) => {
|
|
801
|
+
const label = isSubtypeInstance(t) ? t.code : t.id;
|
|
802
|
+
return new ValueVariable({
|
|
803
|
+
profile: this._profile,
|
|
804
|
+
label: `${label}`,
|
|
805
|
+
description: t.name,
|
|
806
|
+
snippet: `"${label}"`,
|
|
807
|
+
});
|
|
808
|
+
}) ?? [];
|
|
809
|
+
return new GroupOfVariables(this._profile, { code: "subtypes" }, values);
|
|
810
|
+
}
|
|
811
|
+
_getCodedValueDomainGroup(domain, label) {
|
|
812
|
+
const values = domain.codedValues.map((v) => new ValueVariable({
|
|
813
|
+
profile: this._profile,
|
|
814
|
+
label: `${v.code}`,
|
|
815
|
+
description: v.name,
|
|
816
|
+
snippet: `"${v.code}"`,
|
|
817
|
+
filterDescription: true,
|
|
818
|
+
}));
|
|
819
|
+
return new GroupOfVariables(this._profile, label, values);
|
|
820
|
+
}
|
|
821
|
+
_getDomainValuesGroup(types, field) {
|
|
822
|
+
const variables = [];
|
|
823
|
+
if (!types || types.length === 0) {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
types.forEach((type) => {
|
|
827
|
+
let domain = type.domains?.[field.name];
|
|
828
|
+
if (!domain) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (isInheritedDomainInstance(domain)) {
|
|
832
|
+
domain = field.domain;
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (!isCodedValueDomainInstance(domain)) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
const alias = fieldAlias(field);
|
|
839
|
+
const domainValuesGroup = this._getCodedValueDomainGroup(domain, {
|
|
840
|
+
code: "domainvaluesfortypeformat",
|
|
841
|
+
formatValues: {
|
|
842
|
+
fieldName: alias,
|
|
843
|
+
typeName: type.name,
|
|
844
|
+
},
|
|
845
|
+
});
|
|
846
|
+
const id = isSubtypeInstance(type) ? type.code : type.id;
|
|
847
|
+
const label = `${id}`;
|
|
848
|
+
const snippet = `"${id}""`;
|
|
849
|
+
const subtypeDictionary = new DictionaryVariable(this, {
|
|
850
|
+
profile: this._profile,
|
|
851
|
+
label,
|
|
852
|
+
snippet,
|
|
853
|
+
description: type.name,
|
|
854
|
+
declaration: { name: alias },
|
|
855
|
+
});
|
|
856
|
+
subtypeDictionary.variables = [domainValuesGroup];
|
|
857
|
+
variables.push(subtypeDictionary);
|
|
858
|
+
});
|
|
859
|
+
if (!variables.length) {
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
return new GroupOfVariables(this._profile, { code: "domainvaluesbysubtypes" }, variables);
|
|
863
|
+
}
|
|
864
|
+
_createDomainDictionary(field) {
|
|
865
|
+
// Create the domain dictionary.
|
|
866
|
+
// The dictionary will have a header group and a value group.
|
|
867
|
+
// At this point we are only creating the header group in the dictionary.
|
|
868
|
+
const valueSnippet = this._getValueSnippet(field);
|
|
869
|
+
const alias = fieldAlias(field);
|
|
870
|
+
const domainDictionary = new DictionaryVariable(this, {
|
|
871
|
+
profile: this._profile,
|
|
872
|
+
label: valueSnippet,
|
|
873
|
+
description: alias,
|
|
874
|
+
snippet: valueSnippet,
|
|
875
|
+
icon: "form-dropdown",
|
|
876
|
+
declaration: { name: field.name },
|
|
877
|
+
});
|
|
878
|
+
// Add the header group
|
|
879
|
+
const headerGroup = new GroupOfVariables(this._profile, alias, [
|
|
880
|
+
new ValueVariable({
|
|
881
|
+
profile: this._profile,
|
|
882
|
+
label: valueSnippet,
|
|
883
|
+
description: "",
|
|
884
|
+
snippet: valueSnippet,
|
|
885
|
+
}),
|
|
886
|
+
]);
|
|
887
|
+
domainDictionary.variables = [headerGroup];
|
|
888
|
+
// Add the SubtypeName or DomainName snippet if available
|
|
889
|
+
const subtypeOrDomainNameSnippet = this._getSubtypeOrDomainNameSnippet(field);
|
|
890
|
+
if (subtypeOrDomainNameSnippet) {
|
|
891
|
+
headerGroup.variables.push(new ValueVariable({
|
|
892
|
+
profile: this._profile,
|
|
893
|
+
label: subtypeOrDomainNameSnippet,
|
|
894
|
+
description: "",
|
|
895
|
+
snippet: subtypeOrDomainNameSnippet,
|
|
896
|
+
}));
|
|
897
|
+
}
|
|
898
|
+
return domainDictionary;
|
|
899
|
+
}
|
|
900
|
+
async _getRelationshipsProperty() {
|
|
901
|
+
// We need the data store to find the relationship feature layers
|
|
902
|
+
if (!this.relationshipsProperties?.exposeRelationships || !this._profile?.supportFeatureSetFunctions) {
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
const source = this._source;
|
|
906
|
+
if (!isRelationshipsCapableLayer(source)) {
|
|
907
|
+
return null;
|
|
908
|
+
}
|
|
909
|
+
const relationshipsGroup = new GroupOfVariables(this._profile, { code: "relationships" });
|
|
910
|
+
const relationshipItems = await Promise.all(source.relationships.map(async (relationship) => {
|
|
911
|
+
const relatedLayer = await getRelatedFeatureLayer(source, relationship);
|
|
912
|
+
if (!isFeatureLayerLikeInstance(relatedLayer)) {
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
if (relationship.relatedTableId === this.relationshipsProperties?.sourceTableId) {
|
|
916
|
+
// We don't want to show the reverse relationship
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
const snippet = `FeatureSetByRelationshipName(${this.snippet}, "${relationship.name}")`;
|
|
920
|
+
return new FeatureSetVariable(this, {
|
|
921
|
+
profile: this._profile,
|
|
922
|
+
declaration: { definition: relatedLayer },
|
|
923
|
+
label: relatedLayer.title,
|
|
924
|
+
description: "",
|
|
925
|
+
nonInteractive: true,
|
|
926
|
+
}, [new ValueVariable({ profile: this._profile, label: snippet, description: "", snippet })], { exposeRelationships: true, sourceTableId: source.layerId });
|
|
927
|
+
}));
|
|
928
|
+
relationshipsGroup.variables = relationshipItems.filter(isNotNull);
|
|
929
|
+
if (!relationshipsGroup.variables.length) {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
return relationshipsGroup;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
class FeatureVariable extends SourceBasedVariable {
|
|
936
|
+
constructor(owner, props) {
|
|
937
|
+
super(owner, props, { exposeRelationships: true });
|
|
938
|
+
this.type = "feature";
|
|
939
|
+
}
|
|
940
|
+
get title() {
|
|
941
|
+
if (isTitleCapableSource(this._source)) {
|
|
942
|
+
return this._source.title ?? "";
|
|
943
|
+
}
|
|
944
|
+
return { code: "feature" };
|
|
945
|
+
}
|
|
946
|
+
async _loadSource() {
|
|
947
|
+
if (this.loaded) {
|
|
948
|
+
return this._source;
|
|
949
|
+
}
|
|
950
|
+
try {
|
|
951
|
+
this._source = await supportedSourceFromDefinition(this._definition);
|
|
952
|
+
if (!this._source) {
|
|
953
|
+
throw new Error("Invalid definition");
|
|
954
|
+
}
|
|
955
|
+
// The title group and snippet
|
|
956
|
+
const title = isTitleCapableSource(this._source) ? this._source.title ?? "" : "";
|
|
957
|
+
this.variables.push(new GroupOfVariables(this._profile, title, [
|
|
958
|
+
new ValueVariable({
|
|
959
|
+
profile: this._profile,
|
|
960
|
+
label: this.snippet,
|
|
961
|
+
description: "",
|
|
962
|
+
snippet: this.snippet,
|
|
963
|
+
}),
|
|
964
|
+
]));
|
|
965
|
+
// The collection of feature attribute values
|
|
966
|
+
const valuesGroup = new GroupOfVariables(this._profile, { code: "values" });
|
|
967
|
+
this.variables.push(valuesGroup);
|
|
968
|
+
// Add the geometry if it's a feature layer and not a table
|
|
969
|
+
if (isTableCapableLayer(this._source) && !this._source.isTable) {
|
|
970
|
+
const snippet = `Geometry(${this.snippet})`;
|
|
971
|
+
const geometryProperty = new ValueVariable({
|
|
972
|
+
profile: this._profile,
|
|
973
|
+
declaration: { name: snippet },
|
|
974
|
+
label: snippet,
|
|
975
|
+
description: "Geometry",
|
|
976
|
+
snippet,
|
|
977
|
+
icon: "shapes",
|
|
978
|
+
filterDescription: true,
|
|
979
|
+
});
|
|
980
|
+
valuesGroup.variables.push(geometryProperty);
|
|
981
|
+
}
|
|
982
|
+
this._source.fields.sort(sortFields(this._source)).forEach((field) => {
|
|
983
|
+
valuesGroup.variables.push(this._getFieldProperty(field));
|
|
984
|
+
});
|
|
985
|
+
// The relatonships
|
|
986
|
+
const relationshipsGroup = await this._getRelationshipsProperty();
|
|
987
|
+
if (relationshipsGroup) {
|
|
988
|
+
this.variables.push(relationshipsGroup);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
catch (error) {
|
|
992
|
+
console.error("Error with definition", error, this._definition);
|
|
993
|
+
this._source = null;
|
|
994
|
+
}
|
|
995
|
+
finally {
|
|
996
|
+
this._loaded = true;
|
|
997
|
+
}
|
|
998
|
+
return this._source;
|
|
999
|
+
}
|
|
1000
|
+
toProfileVariableDefinition() {
|
|
1001
|
+
return { type: this.type, name: "", ...this.declaration, definition: this._definition };
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
class FeatureSetVariable extends SourceBasedVariable {
|
|
1005
|
+
constructor(owner, props, featureSetSnippets = [],
|
|
1006
|
+
// Relationships for feature set if only supported if the feature set is actually
|
|
1007
|
+
// representing a relationsip feature layer for a feature source.
|
|
1008
|
+
relationshipProps) {
|
|
1009
|
+
super(owner, props, relationshipProps);
|
|
1010
|
+
this.featureSetSnippets = featureSetSnippets;
|
|
1011
|
+
this.type = "featureSet";
|
|
1012
|
+
}
|
|
1013
|
+
get title() {
|
|
1014
|
+
if (isTitleCapableSource(this._source)) {
|
|
1015
|
+
return this._source.title ?? "";
|
|
1016
|
+
}
|
|
1017
|
+
return { code: "featureset" };
|
|
1018
|
+
}
|
|
1019
|
+
async _loadSource() {
|
|
1020
|
+
if (this.loaded) {
|
|
1021
|
+
return this._source;
|
|
1022
|
+
}
|
|
1023
|
+
try {
|
|
1024
|
+
this._source = await supportedSourceFromDefinition(this._definition);
|
|
1025
|
+
if (!this._source) {
|
|
1026
|
+
throw new Error("Invalid definition");
|
|
1027
|
+
}
|
|
1028
|
+
// The title group and snippet
|
|
1029
|
+
this.variables.push(new GroupOfVariables(this._profile, this.title, this.featureSetSnippets));
|
|
1030
|
+
// Add the fields
|
|
1031
|
+
const fieldsGroup = new GroupOfVariables(this._profile, { code: "fields" });
|
|
1032
|
+
this.variables.push(fieldsGroup);
|
|
1033
|
+
fieldsGroup.variables = this._source.fields
|
|
1034
|
+
.sort(sortFields(this._source))
|
|
1035
|
+
.map((field) => this._getFieldProperty(field));
|
|
1036
|
+
// Add the relationships if enabled
|
|
1037
|
+
const relationshipsGroup = await this._getRelationshipsProperty();
|
|
1038
|
+
if (relationshipsGroup) {
|
|
1039
|
+
this.variables.push(relationshipsGroup);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
catch (error) {
|
|
1043
|
+
console.error("Error with definition", error, this._definition);
|
|
1044
|
+
this._source = null;
|
|
1045
|
+
}
|
|
1046
|
+
finally {
|
|
1047
|
+
this._loaded = true;
|
|
1048
|
+
}
|
|
1049
|
+
return this._source;
|
|
1050
|
+
}
|
|
1051
|
+
toProfileVariableDefinition() {
|
|
1052
|
+
return { type: this.type, name: "", ...this.declaration, definition: this._definition };
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
class FeatureSetCollectionVariable extends CollectionBasedVariable {
|
|
1056
|
+
constructor(owner, props) {
|
|
1057
|
+
super(owner, props);
|
|
1058
|
+
this.type = "featureSetCollection";
|
|
1059
|
+
this._featureSetCollections = null;
|
|
1060
|
+
this._loaded = false;
|
|
1061
|
+
this._definition = props.declaration?.definition;
|
|
1062
|
+
}
|
|
1063
|
+
get informationUrl() {
|
|
1064
|
+
if (!this.loaded || !this._featureSetCollections) {
|
|
1065
|
+
return null;
|
|
1066
|
+
}
|
|
1067
|
+
if (typeof this._featureSetCollections.source !== "string") {
|
|
1068
|
+
return portalItemPageUrl(getMapPortalItem(this._featureSetCollections.source));
|
|
1069
|
+
}
|
|
1070
|
+
// const firstLayer = this._featureSetCollection.layers[0] ?? this._featureSetCollection.tables[0];
|
|
1071
|
+
// if (!firstLayer) {
|
|
1072
|
+
return null;
|
|
1073
|
+
// }
|
|
1074
|
+
// return `${firstLayer.url}`;
|
|
1075
|
+
}
|
|
1076
|
+
get informationType() {
|
|
1077
|
+
if (!this.loaded || !this._featureSetCollections) {
|
|
1078
|
+
return "";
|
|
1079
|
+
}
|
|
1080
|
+
if (typeof this._featureSetCollections.source === "string") {
|
|
1081
|
+
return this._profile?.intlStrings.featureservice ?? "featureservice";
|
|
1082
|
+
}
|
|
1083
|
+
switch (this._featureSetCollections.source.declaredClass) {
|
|
1084
|
+
case "esri.WebMap":
|
|
1085
|
+
return this._profile?.intlStrings.webmap ?? "webmap";
|
|
1086
|
+
case "esri.WebScene":
|
|
1087
|
+
return this._profile?.intlStrings.webscene ?? "webscene";
|
|
1088
|
+
default:
|
|
1089
|
+
return this._profile?.intlStrings.map ?? "map";
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
async loadSource() {
|
|
1093
|
+
if (isNotNull(this._loadPromise) && isNotUndefined(this._loadPromise)) {
|
|
1094
|
+
return await this._loadPromise;
|
|
1095
|
+
}
|
|
1096
|
+
this._loadPromise = this._loadSource();
|
|
1097
|
+
return await this._loadPromise;
|
|
1098
|
+
}
|
|
1099
|
+
async _loadSource() {
|
|
1100
|
+
if (this.loaded) {
|
|
1101
|
+
return this._featureSetCollections;
|
|
1102
|
+
}
|
|
1103
|
+
try {
|
|
1104
|
+
this._featureSetCollections = await this._featureSetCollectionsFromDefinition();
|
|
1105
|
+
if (!this._featureSetCollections) {
|
|
1106
|
+
throw new Error("Invalid definition");
|
|
1107
|
+
}
|
|
1108
|
+
// Create the group for the header
|
|
1109
|
+
const groupLabel = typeof this._featureSetCollections.source === "string"
|
|
1110
|
+
? { code: this._featureSetCollections.source.endsWith("FeatureServer") ? "featureservice" : "mapservice" }
|
|
1111
|
+
: {
|
|
1112
|
+
code: "webmapformat",
|
|
1113
|
+
formatValues: {
|
|
1114
|
+
webMapTitle: getMapPortalItem(this._featureSetCollections.source)?.title || "Untitled map",
|
|
1115
|
+
},
|
|
1116
|
+
};
|
|
1117
|
+
const headerGroup = new GroupOfVariables(this._profile, groupLabel, [
|
|
1118
|
+
new ValueVariable({
|
|
1119
|
+
profile: this._profile,
|
|
1120
|
+
label: this.snippet,
|
|
1121
|
+
description: "",
|
|
1122
|
+
snippet: this.snippet,
|
|
1123
|
+
}),
|
|
1124
|
+
]);
|
|
1125
|
+
// Creates the groups for the layer and tables
|
|
1126
|
+
const layersGroup = new GroupOfVariables(this._profile, { code: "layers" }, this._featureSetCollections.layers);
|
|
1127
|
+
const tablesGroup = new GroupOfVariables(this._profile, { code: "tables" }, this._featureSetCollections.tables);
|
|
1128
|
+
this.variables.push(headerGroup, layersGroup, tablesGroup);
|
|
1129
|
+
}
|
|
1130
|
+
catch (error) {
|
|
1131
|
+
console.error("Error with definition", error, this._definition);
|
|
1132
|
+
this._featureSetCollections = null;
|
|
1133
|
+
}
|
|
1134
|
+
finally {
|
|
1135
|
+
this._loaded = true;
|
|
1136
|
+
}
|
|
1137
|
+
return this._featureSetCollections;
|
|
1138
|
+
}
|
|
1139
|
+
async _featureSetCollectionsFromDefinition() {
|
|
1140
|
+
if (!this._definition) {
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
if (isMapInstance(this._definition)) {
|
|
1144
|
+
return await this._featureSetCollectionFromMap(this._definition);
|
|
1145
|
+
}
|
|
1146
|
+
if (isUrlDefinition(this._definition)) {
|
|
1147
|
+
return await this._featureSetCollectionFromUrl(this._definition.url);
|
|
1148
|
+
}
|
|
1149
|
+
if (isPortalItemDefinition(this._definition)) {
|
|
1150
|
+
// Preload the portal item so we can discover if are dealing with a Web Map
|
|
1151
|
+
// or Feature Service
|
|
1152
|
+
return await this._featureSetCollectionFromPortalItem(this._definition.portalItem);
|
|
1153
|
+
}
|
|
1154
|
+
return null;
|
|
1155
|
+
}
|
|
1156
|
+
async _featureSetCollectionFromMap(map) {
|
|
1157
|
+
if (isLoadAllCapable(map)) {
|
|
1158
|
+
// Make sure the map is loaded
|
|
1159
|
+
await map.loadAll();
|
|
1160
|
+
}
|
|
1161
|
+
// Until jsapi fix a bug we have to load the table separately
|
|
1162
|
+
await Promise.all(map.tables.map(async (t) => (await t.load())));
|
|
1163
|
+
return {
|
|
1164
|
+
layers: this._convertWebMapLayersToVariables(map.layers),
|
|
1165
|
+
tables: this._convertWebMapLayersToVariables(map.tables, true),
|
|
1166
|
+
source: map,
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
async _featureSetCollectionFromPortalItem(definition) {
|
|
1170
|
+
const portalItem = await newPortalPortalItem(definition);
|
|
1171
|
+
await portalItem.load();
|
|
1172
|
+
switch (portalItem.type) {
|
|
1173
|
+
case "Web Map": {
|
|
1174
|
+
const webMap = await newWebMap({ portalItem });
|
|
1175
|
+
return await this._featureSetCollectionFromMap(webMap);
|
|
1176
|
+
}
|
|
1177
|
+
case "Web Scene": {
|
|
1178
|
+
const webScene = await newWebScene({ portalItem });
|
|
1179
|
+
return await this._featureSetCollectionFromMap(webScene);
|
|
1180
|
+
}
|
|
1181
|
+
case "Feature Service":
|
|
1182
|
+
return await this._featureSetCollectionFromUrl(portalItem.url);
|
|
1183
|
+
default:
|
|
1184
|
+
console.error("Unsupported portal item", definition);
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
async _featureSetCollectionFromUrl(url) {
|
|
1189
|
+
let processedUrl = url.replace(/\/featureserver\/[0-9]*/iu, "/FeatureServer");
|
|
1190
|
+
processedUrl = processedUrl.replace(/\/mapserver\/[0-9]*/iu, "/MapServer");
|
|
1191
|
+
processedUrl = processedUrl.split("?")[0];
|
|
1192
|
+
if (!processedUrl) {
|
|
1193
|
+
return null;
|
|
1194
|
+
}
|
|
1195
|
+
const metadata = await serviceMetaData(processedUrl);
|
|
1196
|
+
const layersPromise = Promise.all(metadata.layers.map(async (layerInfo) => {
|
|
1197
|
+
const featureLayer = await newLayersFeatureLayer({ url: `${processedUrl}/${layerInfo.id}` });
|
|
1198
|
+
await featureLayer.load();
|
|
1199
|
+
return this._createFeatureSetVariable(featureLayer);
|
|
1200
|
+
}));
|
|
1201
|
+
const tablesPromise = Promise.all(metadata.tables.map(async (layerInfo) => {
|
|
1202
|
+
const table = await newLayersFeatureLayer({ url: `${processedUrl}/${layerInfo.id}` });
|
|
1203
|
+
await table.load();
|
|
1204
|
+
return this._createFeatureSetVariable(table);
|
|
1205
|
+
}));
|
|
1206
|
+
const [layers, tables] = await Promise.all([layersPromise, tablesPromise]);
|
|
1207
|
+
return { layers, tables, source: processedUrl };
|
|
1208
|
+
}
|
|
1209
|
+
_convertWebMapLayersToVariables(layers, filteringTables = false) {
|
|
1210
|
+
const layerVariables = [];
|
|
1211
|
+
layers
|
|
1212
|
+
.toArray()
|
|
1213
|
+
.reverse()
|
|
1214
|
+
.forEach((layer) => {
|
|
1215
|
+
if (isFeatureLayerLikeInstance(layer)) {
|
|
1216
|
+
layerVariables.push(this._createFeatureSetVariable(layer, true));
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
if (isGroupLayerCapable(layer)) {
|
|
1220
|
+
const groupLayerVariables = filteringTables
|
|
1221
|
+
? this._convertWebMapLayersToVariables(layer.allTables, true)
|
|
1222
|
+
: this._convertWebMapLayersToVariables(layer.allLayers);
|
|
1223
|
+
layerVariables.push(...groupLayerVariables);
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
return layerVariables;
|
|
1227
|
+
}
|
|
1228
|
+
_createFeatureSetVariable(featureLayerLike, isFromWebMap = false) {
|
|
1229
|
+
return new FeatureSetVariable(this, {
|
|
1230
|
+
profile: this._profile,
|
|
1231
|
+
declaration: { name: featureLayerLike.title, definition: featureLayerLike },
|
|
1232
|
+
label: isFromWebMap
|
|
1233
|
+
? featureLayerLike.title
|
|
1234
|
+
: featureLayerLike.sourceJSON.name ?? featureLayerLike.title,
|
|
1235
|
+
description: "",
|
|
1236
|
+
nonInteractive: true,
|
|
1237
|
+
}, this._makeFeatureSetSnippets(featureLayerLike, isFromWebMap));
|
|
1238
|
+
}
|
|
1239
|
+
_makeFeatureSetSnippets(featureLayerLike, isFromWebMap = false) {
|
|
1240
|
+
if (!this._profile?.supportFeatureSetFunctions) {
|
|
1241
|
+
return [];
|
|
1242
|
+
}
|
|
1243
|
+
if (isFromWebMap) {
|
|
1244
|
+
const snippetById = `FeatureSetById(${this.snippet}, "${featureLayerLike.id}")`;
|
|
1245
|
+
const snippetByName = `FeatureSetByName(${this.snippet}, "${featureLayerLike.title}")`;
|
|
1246
|
+
return [
|
|
1247
|
+
new ValueVariable({ profile: this._profile, label: snippetById, description: "", snippet: snippetById }),
|
|
1248
|
+
new ValueVariable({ profile: this._profile, label: snippetByName, description: "", snippet: snippetByName }),
|
|
1249
|
+
];
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
const snippetById = `FeatureSetById(${this.snippet}, "${featureLayerLike.layerId}")`;
|
|
1253
|
+
return [new ValueVariable({ profile: this._profile, label: snippetById, description: "", snippet: snippetById })];
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
toProfileVariableDefinition() {
|
|
1257
|
+
return { type: this.type, name: "", ...this.declaration, definition: this._definition };
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* The EditorProfile is an object that represents an Arcade Profile.
|
|
1262
|
+
* It is used to display the profile in the editor.
|
|
1263
|
+
* It takes an IEditorProfile as a definition and a locale.
|
|
1264
|
+
* A EditorPofile instance
|
|
1265
|
+
* Some of the variables in the profile are based on layers, web maps, or feature services.
|
|
1266
|
+
* They need to be loaded asynchronously to get the metadata necessary for validation and completion.
|
|
1267
|
+
*/
|
|
1268
|
+
class EditorProfile extends DictionaryVariable {
|
|
1269
|
+
constructor(definition, intlStrings, locale = "en") {
|
|
1270
|
+
// Delay the load of the variable declarations so we have a `this`
|
|
1271
|
+
super(undefined, {
|
|
1272
|
+
profile: null,
|
|
1273
|
+
declaration: { properties: [] },
|
|
1274
|
+
});
|
|
1275
|
+
this.definition = definition;
|
|
1276
|
+
this.intlStrings = intlStrings;
|
|
1277
|
+
this.locale = locale;
|
|
1278
|
+
this.variables = [];
|
|
1279
|
+
// We are the root
|
|
1280
|
+
this._profile = this;
|
|
1281
|
+
// Now that `this` is defined, we can load the variables
|
|
1282
|
+
this.loadPropertyDeclarations(definition?.variables);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Returns true if the profile supports feature set functions for snippets.
|
|
1286
|
+
*/
|
|
1287
|
+
get supportFeatureSetFunctions() {
|
|
1288
|
+
return this.definition?.bundles?.includes("data-access") ?? false;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Returns the language service profile. It is different than the editor profile as it is optimized for Monaco.
|
|
1292
|
+
*/
|
|
1293
|
+
async toLSProfile() {
|
|
1294
|
+
const { apiVersion, bundles, hiddenApiItems } = this.definition ?? {};
|
|
1295
|
+
const variables = await variablesToLSVariable(this.dictionaryVariables);
|
|
1296
|
+
return { apiVersion, bundles, variables, hiddenApiItems: hiddenApiItems?.map((s) => s.toLowerCase()) };
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Returns the EditorProfile as a json. The EditorProfile may have been updated. This function allows to
|
|
1300
|
+
* get the new json representing mutations.
|
|
1301
|
+
*/
|
|
1302
|
+
toEditorProfileDefinition() {
|
|
1303
|
+
return {
|
|
1304
|
+
...this.definition,
|
|
1305
|
+
variables: this.dictionaryVariables.map((variable) => variable.toProfileVariableDefinition()),
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
//#endregion
|
|
1310
|
+
|
|
1311
|
+
function isFeatureDefinition(item) {
|
|
1312
|
+
return isUrlDefinition(item) || isFieldsDefinition(item) || isFeatureLayerItemDefinition(item);
|
|
1313
|
+
}
|
|
1314
|
+
function isFeatureSetDefinition(item) {
|
|
1315
|
+
return isUrlDefinition(item) || isFieldsDefinition(item) || isFeatureLayerItemDefinition(item);
|
|
1316
|
+
}
|
|
1317
|
+
function isFeatureSetCollectionDefinition(item) {
|
|
1318
|
+
return isPortalItemDefinition(item) || isMapInstance(item) || isSupportedServiceUrlDefinition(item);
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Get a PredefinedProfile for a locale. If not already loaded then fetch it.
|
|
1322
|
+
* If the locale doesn't exist or the locale profile file doesn't exist then returns
|
|
1323
|
+
* the english version of the profile.
|
|
1324
|
+
*/
|
|
1325
|
+
async function getSdkPredefinedProfiles(locale = "en") {
|
|
1326
|
+
const profiles = sdkPredefinedProfilesMap.get(locale);
|
|
1327
|
+
if (profiles) {
|
|
1328
|
+
return profiles;
|
|
1329
|
+
}
|
|
1330
|
+
if (!supportedLocales.has(locale)) {
|
|
1331
|
+
return await getSdkPredefinedProfiles("en");
|
|
1332
|
+
}
|
|
1333
|
+
try {
|
|
1334
|
+
const response = await fetch(getAssetPath(`./assets/arcade-language/profiles/arcade-profiles.t9n.${locale}.json`));
|
|
1335
|
+
if (response.ok) {
|
|
1336
|
+
return cacheSdkPredefinedProfiles(locale, (await response.json()));
|
|
1337
|
+
}
|
|
1338
|
+
if (locale === "en") {
|
|
1339
|
+
return null;
|
|
1340
|
+
}
|
|
1341
|
+
return await getSdkPredefinedProfiles("en");
|
|
1342
|
+
}
|
|
1343
|
+
catch {
|
|
1344
|
+
return null;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
const sdkPredefinedProfilesMap = new Map();
|
|
1348
|
+
/**
|
|
1349
|
+
* Convert a stored profile into a PredefinedProfile and add it to the in-memory
|
|
1350
|
+
* Map of profiles per locale.
|
|
1351
|
+
*/
|
|
1352
|
+
function cacheSdkPredefinedProfiles(locale, profiles) {
|
|
1353
|
+
const map = new Map();
|
|
1354
|
+
profiles.forEach((profile) => {
|
|
1355
|
+
map.set(profile.id, profile);
|
|
1356
|
+
});
|
|
1357
|
+
sdkPredefinedProfilesMap.set(locale, map);
|
|
1358
|
+
return map;
|
|
1359
|
+
}
|
|
1360
|
+
async function getSdkPredefinedProfile(id, locale = "en") {
|
|
1361
|
+
const profiles = await getSdkPredefinedProfiles(locale);
|
|
1362
|
+
return profiles?.get(id) ?? null;
|
|
1363
|
+
}
|
|
1364
|
+
function isExtendedPredefinedProfileDefinition(item) {
|
|
1365
|
+
return !!item && typeof item === "object" && "additionalVariables" in item && Array.isArray(item.additionalVariables);
|
|
1366
|
+
}
|
|
1367
|
+
function convertApiVariables(variables) {
|
|
1368
|
+
return variables?.map(convertApiVariable);
|
|
1369
|
+
}
|
|
1370
|
+
function convertApiVariable(variable) {
|
|
1371
|
+
switch (variable.type) {
|
|
1372
|
+
case "dictionary":
|
|
1373
|
+
return {
|
|
1374
|
+
...variable,
|
|
1375
|
+
type: variable.type,
|
|
1376
|
+
properties: convertApiVariables(variable.properties),
|
|
1377
|
+
};
|
|
1378
|
+
case "array": {
|
|
1379
|
+
return {
|
|
1380
|
+
...variable,
|
|
1381
|
+
type: variable.type,
|
|
1382
|
+
elementType: { type: "number", name: "number" },
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
default:
|
|
1386
|
+
return { ...variable, type: variable.type };
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
async function convertToEditorProfileDefinition(predefinedProfile, locale = "en") {
|
|
1390
|
+
if (!isPredefinedProfile(predefinedProfile)) {
|
|
1391
|
+
return undefined;
|
|
1392
|
+
}
|
|
1393
|
+
const sdkPredefinedProfile = await getSdkPredefinedProfile(predefinedProfile.id, locale);
|
|
1394
|
+
if (!sdkPredefinedProfile) {
|
|
1395
|
+
return undefined;
|
|
1396
|
+
}
|
|
1397
|
+
const editorProfile = {
|
|
1398
|
+
bundles: [...sdkPredefinedProfile.bundles],
|
|
1399
|
+
variables: [],
|
|
1400
|
+
hiddenApiItems: predefinedProfile.hiddenApiItems?.map((s) => s.toLowerCase()),
|
|
1401
|
+
};
|
|
1402
|
+
// Merge the SDK variables' definitions/properties with the predefined profile definitions.
|
|
1403
|
+
sdkPredefinedProfile.variables.forEach((predefinedVariable) => {
|
|
1404
|
+
// Don't include disabled variables
|
|
1405
|
+
if (predefinedProfile.disabledVariables?.includes(predefinedVariable.name)) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
// Try to get a definition from the predefined profile, for the variable that needs one.
|
|
1409
|
+
const definition = predefinedProfile.definitions[predefinedVariable.name];
|
|
1410
|
+
// Note: Something is weird with TS. The sdkVariables are being casted to the wrong type
|
|
1411
|
+
// despite the type checking from the switch statement.
|
|
1412
|
+
switch (predefinedVariable.type) {
|
|
1413
|
+
case "dictionary": {
|
|
1414
|
+
// For dictionary, we support properties overrride
|
|
1415
|
+
return editorProfile.variables.push(convertApiVariable({
|
|
1416
|
+
...predefinedVariable,
|
|
1417
|
+
type: predefinedVariable.type,
|
|
1418
|
+
properties: Array.isArray(definition) ? [...definition] : predefinedVariable.properties,
|
|
1419
|
+
}));
|
|
1420
|
+
}
|
|
1421
|
+
case "feature":
|
|
1422
|
+
// If the definition is not valid, then we don't include it.
|
|
1423
|
+
if (!isFeatureDefinition(definition)) {
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
return editorProfile.variables.push({ ...predefinedVariable, type: predefinedVariable.type, definition });
|
|
1427
|
+
case "featureSet":
|
|
1428
|
+
// If the definition is not valid, then we don't include it.
|
|
1429
|
+
if (!isFeatureSetDefinition(definition)) {
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
return editorProfile.variables.push({ ...predefinedVariable, type: predefinedVariable.type, definition });
|
|
1433
|
+
case "featureSetCollection":
|
|
1434
|
+
// If the definition is not valid, then we don't include it.
|
|
1435
|
+
if (!isFeatureSetCollectionDefinition(definition)) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
return editorProfile.variables.push({ ...predefinedVariable, type: predefinedVariable.type, definition });
|
|
1439
|
+
default:
|
|
1440
|
+
return editorProfile.variables.push(convertApiVariable(predefinedVariable));
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
if (isExtendedPredefinedProfileDefinition(predefinedProfile)) {
|
|
1444
|
+
editorProfile.variables.push(...(predefinedProfile.additionalVariables ?? []));
|
|
1445
|
+
}
|
|
1446
|
+
return editorProfile;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// this file contains the building blocks for a language default provider
|
|
1450
|
+
const defaultContext = {
|
|
1451
|
+
locale: "en",
|
|
1452
|
+
};
|
|
1453
|
+
class LanguageDefaultsBase {
|
|
1454
|
+
constructor() {
|
|
1455
|
+
// #endregion
|
|
1456
|
+
// #region Protected properties
|
|
1457
|
+
this._onDidChange = new Emitter();
|
|
1458
|
+
this._profileMap = new Map();
|
|
1459
|
+
this._apiContextMap = new Map();
|
|
1460
|
+
this._onModelContextDidChange = new Emitter();
|
|
1461
|
+
this._onDidModelContextChangeTimeout = -1;
|
|
1462
|
+
// #endregion
|
|
1463
|
+
}
|
|
1464
|
+
// #endregion
|
|
1465
|
+
// #region Protected methods
|
|
1466
|
+
_fireModelContextDidChange(key) {
|
|
1467
|
+
if (this._onDidModelContextChangeTimeout !== -1) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
this._onDidModelContextChangeTimeout = window.setTimeout(() => {
|
|
1471
|
+
this._onDidModelContextChangeTimeout = -1;
|
|
1472
|
+
this._onModelContextDidChange.fire(key);
|
|
1473
|
+
}, 0);
|
|
1474
|
+
}
|
|
1475
|
+
_getApiKey(modelId) {
|
|
1476
|
+
if (!Uri.isUri(modelId)) {
|
|
1477
|
+
modelId = Uri.parse(modelId);
|
|
1478
|
+
}
|
|
1479
|
+
return modelId.toString();
|
|
1480
|
+
}
|
|
1481
|
+
// #endregion
|
|
1482
|
+
// #region Public methods
|
|
1483
|
+
get onDidChange() {
|
|
1484
|
+
return this._onDidChange.event;
|
|
1485
|
+
}
|
|
1486
|
+
get languageOptions() {
|
|
1487
|
+
return this._languageOptions;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Dispose any cached resources for the model
|
|
1491
|
+
*/
|
|
1492
|
+
disposeForModel(modelId) {
|
|
1493
|
+
const key = this._getApiKey(modelId);
|
|
1494
|
+
this._profileMap.delete(key);
|
|
1495
|
+
if (this._apiContextMap.delete(key)) {
|
|
1496
|
+
this._fireModelContextDidChange(key);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Returns the editor profile for the given model id.
|
|
1501
|
+
* @param modelId The model id for which to get the editor profile.
|
|
1502
|
+
* @returns The editor profile for the model.
|
|
1503
|
+
*/
|
|
1504
|
+
getEditorProfileForModel(modelId) {
|
|
1505
|
+
return this._profileMap.get(this._getApiKey(modelId));
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Returns the API context for the given model id.
|
|
1509
|
+
* Returns the default context if the model has no context.
|
|
1510
|
+
* @param modelId The model id for which to get the API context.
|
|
1511
|
+
* @returns The API context for the model.
|
|
1512
|
+
*/
|
|
1513
|
+
getApiContextForModel(contextId) {
|
|
1514
|
+
return this._apiContextMap.get(this._getApiKey(contextId)) ?? defaultContext;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Set or update api context for the given model id.
|
|
1518
|
+
* @param modelId The model id for which to set the context.
|
|
1519
|
+
* @param apiContext The api context to set.
|
|
1520
|
+
*/
|
|
1521
|
+
updateApiContextForModel(modelId, apiContext) {
|
|
1522
|
+
const key = this._getApiKey(modelId);
|
|
1523
|
+
const currentApiContext = this._apiContextMap.get(key) ?? {};
|
|
1524
|
+
this._apiContextMap.set(key, { ...currentApiContext, ...apiContext });
|
|
1525
|
+
this._fireModelContextDidChange(key);
|
|
1526
|
+
}
|
|
1527
|
+
get onModelContextDidChange() {
|
|
1528
|
+
return this._onModelContextDidChange.event;
|
|
1529
|
+
}
|
|
1530
|
+
get languageId() {
|
|
1531
|
+
return this._languageId;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
export { EditorProfile as E, LanguageDefaultsBase as L, isFeatureSetDefinition as a, convertToEditorProfileDefinition as c, isPredefinedProfile as i };
|