@arcgis/coding-components 4.30.0-next.5 → 4.30.0-next.50
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.css +1 -1
- package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ar.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.bg.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.bs.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ca.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.cs.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.da.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.de.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.el.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.en.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.es.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.et.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.fi.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.fr.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.he.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.hr.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.hu.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.id.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.it.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ja.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ko.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.lt.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.lv.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.nb.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.nl.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pl.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pt-BR.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pt-PT.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ro.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ru.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sk.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sl.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sr.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sv.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.th.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.tr.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.uk.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.vi.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-CN.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-HK.json +25 -0
- package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-TW.json +25 -0
- package/dist/arcgis-coding-components/assets/code-editor/arcade.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/css.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/editor.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/ts.worker.js +1 -1
- package/dist/arcgis-coding-components/index.esm.js +2 -2
- package/dist/arcgis-coding-components/{p-cebf794f.js → p-2c805689.js} +2 -2
- package/dist/arcgis-coding-components/{p-7d7f1240.js → p-50055c43.js} +2 -2
- package/dist/arcgis-coding-components/{p-06d44cef.js → p-60888738.js} +3 -3
- package/dist/arcgis-coding-components/{p-2e3aede1.js → p-7c5bb70b.js} +2 -2
- package/dist/arcgis-coding-components/{p-551af1f6.js → p-8c564c76.js} +2 -2
- package/dist/arcgis-coding-components/p-ab00671b.js +68 -0
- package/dist/arcgis-coding-components/p-b62b3ecc.js +7 -0
- package/dist/arcgis-coding-components/{p-fd3fa4a0.js → p-bda60780.js} +2 -2
- package/dist/arcgis-coding-components/{p-32911b21.js → p-bf81a3f3.js} +2 -2
- package/dist/arcgis-coding-components/{p-0f11c91b.js → p-c3aa0ba1.js} +2 -2
- package/dist/arcgis-coding-components/{p-a4e27a58.js → p-d220236c.js} +1 -1
- package/dist/arcgis-coding-components/p-f11a8755.entry.js +6 -0
- package/dist/cjs/{arcade-defaults-204e7ccd.js → arcade-defaults-57e26a09.js} +483 -173
- package/dist/cjs/{arcade-mode-4100f9e4.js → arcade-mode-3b27569b.js} +45 -51
- package/dist/cjs/arcgis-arcade-api_6.cjs.entry.js +1702 -283
- package/dist/cjs/arcgis-coding-components.cjs.js +3 -3
- package/dist/cjs/{css-bfbeba2f.js → css-c4174c97.js} +1 -1
- package/dist/cjs/{cssMode-76b5efe0.js → cssMode-11d4382b.js} +3 -3
- package/dist/cjs/{html-5cb5408f.js → html-f41bd48d.js} +3 -3
- package/dist/cjs/{htmlMode-22c5689f.js → htmlMode-59c5586b.js} +3 -3
- package/dist/cjs/{index-a37bcea1.js → index-999a3012.js} +40 -4
- package/dist/cjs/index.cjs.js +3 -3
- package/dist/cjs/{javascript-ec61b6c4.js → javascript-00a4972f.js} +4 -4
- package/dist/cjs/{jsonMode-ceded417.js → jsonMode-3550388e.js} +3 -3
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/{tsMode-d4f8e205.js → tsMode-b6cf29ec.js} +3 -3
- package/dist/cjs/{typescript-0d60800f.js → typescript-2704ab9d.js} +3 -3
- package/dist/components/arcade-api.js +21 -32
- package/dist/components/arcade-contribution.js +71 -12
- package/dist/components/arcade-defaults.js +78 -73
- package/dist/components/arcade-mode.js +44 -50
- package/dist/components/arcade-results.js +47 -60
- package/dist/components/arcade-suggestions.js +23 -33
- package/dist/components/arcade-variables.js +22 -36
- package/dist/components/arcgis-arcade-api.js +1 -1
- package/dist/components/arcgis-arcade-editor.js +59 -147
- package/dist/components/arcgis-arcade-results.js +1 -1
- package/dist/components/arcgis-arcade-suggestions.js +1 -1
- package/dist/components/arcgis-arcade-variables.js +1 -1
- package/dist/components/arcgis-assets.d.ts +1 -1
- package/dist/components/arcgis-assets.js +1 -1
- package/dist/components/arcgis-code-editor.js +1 -1
- package/dist/components/chunk-27DTPISK.js +1438 -0
- package/dist/components/code-editor.js +71 -75
- package/dist/components/fields.js +40 -44
- package/dist/components/index.js +1 -1
- package/dist/components/index2.js +314 -3
- package/dist/components/markdown.js +9 -11
- package/dist/components/useT9n.js +11 -0
- package/dist/components/utilities.js +3 -3
- package/dist/esm/{arcade-defaults-a8eba8cf.js → arcade-defaults-c102be00.js} +472 -160
- package/dist/esm/{arcade-mode-b8fed895.js → arcade-mode-c4dd84f5.js} +45 -51
- package/dist/esm/arcgis-arcade-api_6.entry.js +1702 -283
- package/dist/esm/arcgis-coding-components.js +4 -4
- package/dist/esm/{css-d802bf2b.js → css-be9f2148.js} +1 -1
- package/dist/esm/{cssMode-e68d14c9.js → cssMode-5bfb9fcd.js} +3 -3
- package/dist/esm/{html-b1eb86e6.js → html-e4052e46.js} +3 -3
- package/dist/esm/{htmlMode-1211bc87.js → htmlMode-39da10b5.js} +3 -3
- package/dist/esm/{index-916b1135.js → index-507ff821.js} +40 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/{javascript-f1cc1f09.js → javascript-2698ff38.js} +4 -4
- package/dist/esm/{jsonMode-85d9cded.js → jsonMode-01c45b94.js} +3 -3
- package/dist/esm/loader.js +4 -4
- package/dist/esm/{tsMode-61fedc4b.js → tsMode-4ee78489.js} +3 -3
- package/dist/esm/{typescript-49d6ec3c.js → typescript-5e150a72.js} +3 -3
- package/dist/loader/cdn.js +1 -1
- package/dist/loader/index.cjs.js +1 -1
- package/dist/loader/index.es2017.js +1 -1
- package/dist/loader/index.js +1 -1
- package/dist/types/components/arcade-api/arcade-api.d.ts +6 -7
- package/dist/types/components/arcade-editor/arcade-editor.d.ts +18 -11
- package/dist/types/components/arcade-results/arcade-results.d.ts +6 -9
- package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +7 -8
- package/dist/types/components/arcade-variables/arcade-variables.d.ts +6 -8
- package/dist/types/components/code-editor/code-editor.d.ts +23 -13
- package/dist/types/components.d.ts +57 -35
- package/dist/types/controllers/useT9n.d.ts +1 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stencil.config.d.ts +3 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/arcade-editor.stories.d.ts +34 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/code-editor/code-editor.stories.d.ts +6 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/reference/stories/arcade-editor.stories.d.ts +9 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-inline-url-importer.d.ts +9 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-json-importer.d.ts +19 -0
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/stencil-monaco-plugins.d.ts +6 -0
- package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +1 -1
- package/dist/types/utils/profile/types.d.ts +1 -1
- package/package.json +20 -19
- package/dist/arcgis-coding-components/p-a331eda4.entry.js +0 -6
- package/dist/arcgis-coding-components/p-d0f4a5d4.js +0 -68
- package/dist/arcgis-coding-components/p-e311f720.js +0 -7
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
* See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
|
-
* v4.30.0-next.
|
|
4
|
+
* v4.30.0-next.50
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { g as generateTokensCSSForColorMap, e as editor, S as StandaloneServices, I as IStandaloneThemeService, c as createCommonjsModule, b as commonjsGlobal, i as
|
|
6
|
+
import { g as getAssetPath, r as registerInstance, c as createEvent, h, H as Host, a as getElement, F as Fragment } from './index-507ff821.js';
|
|
7
|
+
import { g as generateTokensCSSForColorMap, e as editor, S as StandaloneServices, I as IStandaloneThemeService, c as createCommonjsModule, b as commonjsGlobal, i as isURL, h as hasSameOrigin, d as importRequest, l as languages, f as arcadeDefaults, U as Uri, s as setFocusOnElement, j as filterCollection, k as addLTRMark, m as importArcade, D as Deferred$1, n as generateGuid, o as getElementTheme, K as KeyCode, p as setValuesInString, q as quoteString, r as supportedFields, t as createFilterExpression, R as Range, u as observeAncestorsMutation$1, v as KeyMod } from './arcade-defaults-c102be00.js';
|
|
8
8
|
|
|
9
9
|
async function colorizeCode(code) {
|
|
10
10
|
return await editor.colorize(code, "arcade", { tabSize: 2 });
|
|
@@ -2917,26 +2917,1456 @@ var marked_umd = createCommonjsModule(function (module, exports) {
|
|
|
2917
2917
|
// Set up the marked library to use GitHub Flavored Markdown and to use the custom renderer for links.
|
|
2918
2918
|
marked_umd.marked.use({
|
|
2919
2919
|
gfm: true,
|
|
2920
|
+
breaks: true,
|
|
2921
|
+
async: false,
|
|
2920
2922
|
renderer: {
|
|
2921
2923
|
link(href, title, text) {
|
|
2922
2924
|
return `<calcite-link href="${href}" title="${title ?? text}" target="Arcade Help">${text}</calcite-link>`;
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
+
},
|
|
2926
|
+
},
|
|
2925
2927
|
});
|
|
2926
2928
|
/**
|
|
2927
2929
|
* Converts a markdown string to HTML using the marked library.
|
|
2928
2930
|
*/
|
|
2929
2931
|
function convertMarkdownString(value) {
|
|
2930
|
-
value
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2932
|
+
if (value === null || value === undefined) {
|
|
2933
|
+
return "";
|
|
2934
|
+
}
|
|
2935
|
+
return marked_umd.marked.parse(typeof value === "string" ? value : value.value);
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
// src/framework.ts
|
|
2939
|
+
function retrieveComponentMembers(component, isLit) {
|
|
2940
|
+
if (isLit) {
|
|
2941
|
+
const elementProperties = getLitProperties(component);
|
|
2942
|
+
component.manager.internals.members = Object.fromEntries(
|
|
2943
|
+
Array.from(elementProperties, ([name, { state, type }]) => [
|
|
2944
|
+
name,
|
|
2945
|
+
[
|
|
2946
|
+
state ? 32 /* State */ : type === Number ? 2 /* Number */ : type === Boolean ? 4 /* Boolean */ : 1 /* String */
|
|
2947
|
+
]
|
|
2948
|
+
])
|
|
2949
|
+
);
|
|
2950
|
+
} else {
|
|
2951
|
+
const constructor = component.constructor;
|
|
2952
|
+
const members = constructor.__registerControllers?.(component) ?? void 0;
|
|
2953
|
+
constructor.__registerControllers = void 0;
|
|
2954
|
+
if (typeof members !== "object")
|
|
2955
|
+
throw new Error(
|
|
2956
|
+
"Failed to retrieve internal component meta. Make sure you have the useComponentsControllers() Rollup Plugin for Stencil Controllers configured in your Stencil config."
|
|
2957
|
+
);
|
|
2958
|
+
component.manager.internals.members = members;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
var getLitProperties = (component) => component.constructor.elementProperties;
|
|
2962
|
+
function parsePropertyValue(value, type = 8 /* Any */) {
|
|
2963
|
+
const isComplex = value == null || typeof value === "object" || typeof value === "function";
|
|
2964
|
+
if (isComplex)
|
|
2965
|
+
return value;
|
|
2966
|
+
if ((type & 4 /* Boolean */) !== 0)
|
|
2967
|
+
return value === "false" ? false : value === "" || !!value;
|
|
2968
|
+
else if ((type & 2 /* Number */) !== 0)
|
|
2969
|
+
return Number.parseFloat(value);
|
|
2970
|
+
else if ((type & 1 /* String */) !== 0)
|
|
2971
|
+
return String(value);
|
|
2972
|
+
else
|
|
2973
|
+
return value;
|
|
2974
|
+
}
|
|
2975
|
+
var makeMemberFilter = (filter) => (component) => {
|
|
2976
|
+
const members = component.manager.internals.members;
|
|
2977
|
+
return Object.entries(members ?? {}).filter(([_name, [propType]]) => (propType & filter) !== 0).map(([name]) => name);
|
|
2978
|
+
};
|
|
2979
|
+
var getPropLikeMembers = makeMemberFilter(63 /* PropLike */);
|
|
2980
|
+
var getMemberType = (component, name) => component.manager.internals.members?.[name]?.[0];
|
|
2981
|
+
function getPropType(component, name) {
|
|
2982
|
+
const type = getMemberType(component, name);
|
|
2983
|
+
if (type === void 0)
|
|
2984
|
+
return void 0;
|
|
2985
|
+
else if (type & 32 /* State */)
|
|
2986
|
+
return "state";
|
|
2987
|
+
else
|
|
2988
|
+
return "prop";
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
// src/types.ts
|
|
2992
|
+
var controllerSymbol = Symbol("controller");
|
|
2993
|
+
|
|
2994
|
+
// src/utils.ts
|
|
2995
|
+
function extendObject(base, extend) {
|
|
2996
|
+
Object.entries(extend).forEach(([key, value]) => {
|
|
2997
|
+
if (key in base)
|
|
2998
|
+
throw new Error(`Unable to extend object because property "${key}" is already defined`);
|
|
2999
|
+
const thisBase = base;
|
|
3000
|
+
thisBase[key] = value;
|
|
3001
|
+
});
|
|
3002
|
+
return base;
|
|
3003
|
+
}
|
|
3004
|
+
var isController = (value) => typeof value === "object" && value !== null && (controllerSymbol in value || "hostConnected" in value || "hostDisconnected" in value || "hostUpdate" in value || "hostUpdated" in value);
|
|
3005
|
+
|
|
3006
|
+
// ../components-utils/dist/index.js
|
|
3007
|
+
var Deferred = class {
|
|
3008
|
+
/**
|
|
3009
|
+
* Creates a new deferred promise.
|
|
3010
|
+
*/
|
|
3011
|
+
constructor() {
|
|
3012
|
+
this.resolve = () => void 0;
|
|
3013
|
+
this.reject = () => void 0;
|
|
3014
|
+
this.promise = new Promise((resolve, reject) => {
|
|
3015
|
+
this.resolve = resolve;
|
|
3016
|
+
this.reject = reject;
|
|
2936
3017
|
});
|
|
2937
|
-
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
function inTargetElement(element, targetElement) {
|
|
3021
|
+
let currentElement = element;
|
|
3022
|
+
while (currentElement) {
|
|
3023
|
+
if (currentElement === targetElement) {
|
|
3024
|
+
return true;
|
|
3025
|
+
}
|
|
3026
|
+
if (!currentElement.parentNode) {
|
|
3027
|
+
return false;
|
|
3028
|
+
}
|
|
3029
|
+
if (currentElement.parentNode instanceof ShadowRoot) {
|
|
3030
|
+
currentElement = currentElement.parentNode.host;
|
|
3031
|
+
} else {
|
|
3032
|
+
currentElement = currentElement.parentNode;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
return false;
|
|
3036
|
+
}
|
|
3037
|
+
function observeAncestorsMutation(element, attributeFilter, callback) {
|
|
3038
|
+
const { subscribe } = observe(attributeFilter);
|
|
3039
|
+
return subscribe((mutations) => {
|
|
3040
|
+
const matched = mutations.some((mutation) => inTargetElement(element, mutation.target));
|
|
3041
|
+
if (matched)
|
|
3042
|
+
callback();
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3045
|
+
var observers = {};
|
|
3046
|
+
function observe(attributeFilter) {
|
|
3047
|
+
const attributes = attributeFilter.join(",");
|
|
3048
|
+
const previousObserver = observers[attributes];
|
|
3049
|
+
if (previousObserver !== void 0)
|
|
3050
|
+
return previousObserver;
|
|
3051
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
3052
|
+
const mutationObserver = new MutationObserver((mutations) => subscribers.forEach((callback) => callback(mutations)));
|
|
3053
|
+
mutationObserver.observe(document.documentElement, {
|
|
3054
|
+
attributes: true,
|
|
3055
|
+
attributeFilter,
|
|
3056
|
+
subtree: true
|
|
3057
|
+
});
|
|
3058
|
+
const observer = {
|
|
3059
|
+
subscribe(callback) {
|
|
3060
|
+
subscribers.add(callback);
|
|
3061
|
+
return {
|
|
3062
|
+
remove: () => {
|
|
3063
|
+
subscribers.delete(callback);
|
|
3064
|
+
if (subscribers.size === 0) {
|
|
3065
|
+
mutationObserver.disconnect();
|
|
3066
|
+
observers[attributes] = void 0;
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
};
|
|
3072
|
+
observers[attributes] = observer;
|
|
3073
|
+
return observer;
|
|
3074
|
+
}
|
|
3075
|
+
function closestElement(base, selector) {
|
|
3076
|
+
let currentElement = base;
|
|
3077
|
+
while (currentElement) {
|
|
3078
|
+
const element = currentElement.closest(selector);
|
|
3079
|
+
if (element) {
|
|
3080
|
+
return element;
|
|
3081
|
+
}
|
|
3082
|
+
const rootElement = currentElement.getRootNode();
|
|
3083
|
+
if (rootElement === document) {
|
|
3084
|
+
return null;
|
|
3085
|
+
}
|
|
3086
|
+
currentElement = rootElement.host;
|
|
3087
|
+
}
|
|
3088
|
+
return null;
|
|
3089
|
+
}
|
|
3090
|
+
function getElementAttribute(el, prop, fallbackValue) {
|
|
3091
|
+
const closest = closestElement(el, `[${prop}]`);
|
|
3092
|
+
return closest?.getAttribute(prop) ?? fallbackValue;
|
|
3093
|
+
}
|
|
3094
|
+
function safeCall(callback) {
|
|
3095
|
+
try {
|
|
3096
|
+
return callback?.();
|
|
3097
|
+
} catch (error) {
|
|
3098
|
+
console.error(error, callback);
|
|
3099
|
+
}
|
|
3100
|
+
return void 0;
|
|
3101
|
+
}
|
|
3102
|
+
async function safeAsyncCall(callback) {
|
|
3103
|
+
try {
|
|
3104
|
+
return await callback();
|
|
3105
|
+
} catch (error) {
|
|
3106
|
+
console.error(error, callback);
|
|
3107
|
+
}
|
|
3108
|
+
return void 0;
|
|
3109
|
+
}
|
|
3110
|
+
var camelToKebab = (string) => string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : "-"}${upper.toLowerCase()}`);
|
|
3111
|
+
var upperBeforeLower = /[A-Z]+(?![a-z])|[A-Z]/gu;
|
|
3112
|
+
var capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
3113
|
+
var camelToHuman = (string) => capitalize(string.replace(upperBeforeLower, (upper, remainder) => `${remainder === 0 ? "" : " "}${upper}`));
|
|
3114
|
+
var supportedLocales = /* @__PURE__ */ new Set([
|
|
3115
|
+
"ar",
|
|
3116
|
+
"bg",
|
|
3117
|
+
"bs",
|
|
3118
|
+
"ca",
|
|
3119
|
+
"cs",
|
|
3120
|
+
"da",
|
|
3121
|
+
"de",
|
|
3122
|
+
"el",
|
|
3123
|
+
"en",
|
|
3124
|
+
"es",
|
|
3125
|
+
"et",
|
|
3126
|
+
"fi",
|
|
3127
|
+
"fr",
|
|
3128
|
+
"he",
|
|
3129
|
+
"hr",
|
|
3130
|
+
"hu",
|
|
3131
|
+
"id",
|
|
3132
|
+
"it",
|
|
3133
|
+
"ja",
|
|
3134
|
+
"ko",
|
|
3135
|
+
"lt",
|
|
3136
|
+
"lv",
|
|
3137
|
+
"nl",
|
|
3138
|
+
"nb",
|
|
3139
|
+
"pl",
|
|
3140
|
+
"pt-BR",
|
|
3141
|
+
"pt-PT",
|
|
3142
|
+
"ro",
|
|
3143
|
+
"ru",
|
|
3144
|
+
"sk",
|
|
3145
|
+
"sl",
|
|
3146
|
+
"sr",
|
|
3147
|
+
"sv",
|
|
3148
|
+
"th",
|
|
3149
|
+
"tr",
|
|
3150
|
+
"uk",
|
|
3151
|
+
"vi",
|
|
3152
|
+
"zh-CN",
|
|
3153
|
+
"zh-HK",
|
|
3154
|
+
"zh-TW"
|
|
3155
|
+
]);
|
|
3156
|
+
var defaultLocale = "en";
|
|
3157
|
+
async function fetchT9NStringsBundle(locale, assetsPath, prefix = "") {
|
|
3158
|
+
const path = `${assetsPath}/${prefix}`;
|
|
3159
|
+
const filePath = `${path}${locale}.json`;
|
|
3160
|
+
t9nStringsCache[filePath] ?? (t9nStringsCache[filePath] = fetchBundle(locale, path));
|
|
3161
|
+
return await t9nStringsCache[filePath];
|
|
3162
|
+
}
|
|
3163
|
+
var t9nStringsCache = {};
|
|
3164
|
+
async function fetchBundle(locale, path) {
|
|
3165
|
+
const filePath = `${path}${locale}.json`;
|
|
3166
|
+
try {
|
|
3167
|
+
const response = await fetch(filePath);
|
|
3168
|
+
if (response.ok)
|
|
3169
|
+
return await response.json();
|
|
3170
|
+
} catch (error) {
|
|
3171
|
+
console.error(error);
|
|
3172
|
+
return fallbackBundle;
|
|
3173
|
+
}
|
|
3174
|
+
if (locale === defaultLocale)
|
|
3175
|
+
return fallbackBundle;
|
|
3176
|
+
return await fetchBundle(defaultLocale, path);
|
|
3177
|
+
}
|
|
3178
|
+
var fallbackBundle = new Proxy(
|
|
3179
|
+
{},
|
|
3180
|
+
{
|
|
3181
|
+
get: (_target, property) => camelToHuman(property.toString())
|
|
3182
|
+
}
|
|
3183
|
+
);
|
|
3184
|
+
function getElementLocales(element) {
|
|
3185
|
+
const lang = getElementAttribute(element, "lang", navigator.language || defaultLocale);
|
|
3186
|
+
if (supportedLocales.has(lang)) {
|
|
3187
|
+
return { lang, t9nLocale: lang };
|
|
3188
|
+
}
|
|
3189
|
+
const rootCode = lang.slice(0, 2);
|
|
3190
|
+
return { lang, t9nLocale: supportedLocales.has(rootCode) ? rootCode : defaultLocale };
|
|
3191
|
+
}
|
|
3192
|
+
function startLocaleObserver(element, assetsPath, onUpdated, assetName) {
|
|
3193
|
+
let result = void 0;
|
|
3194
|
+
const callback = () => void updateComponentLocateState(element, assetsPath, assetName).then((newResult) => {
|
|
3195
|
+
if (result?.lang !== newResult.lang || result.t9nLocale !== newResult.t9nLocale || result.t9nStrings !== newResult.t9nStrings)
|
|
3196
|
+
onUpdated(newResult);
|
|
3197
|
+
result = newResult;
|
|
3198
|
+
}).catch(console.error);
|
|
3199
|
+
callback();
|
|
3200
|
+
return observeAncestorsMutation(element, ["lang"], callback);
|
|
3201
|
+
}
|
|
3202
|
+
async function updateComponentLocateState(element, assetsPath, assetName = element.tagName.toLowerCase().replace("arcgis-", "")) {
|
|
3203
|
+
const { lang, t9nLocale } = getElementLocales(element);
|
|
3204
|
+
const t9nAssetsPath = `${assetsPath}/${assetName}/t9n`;
|
|
3205
|
+
const prefix = `${assetName}.t9n.`;
|
|
3206
|
+
const t9nStrings = await fetchT9NStringsBundle(t9nLocale, t9nAssetsPath, prefix);
|
|
3207
|
+
return { lang, t9nLocale, t9nStrings };
|
|
2938
3208
|
}
|
|
2939
3209
|
|
|
3210
|
+
// src/ControllerInternals.ts
|
|
3211
|
+
var ControllerInternals = class {
|
|
3212
|
+
constructor() {
|
|
3213
|
+
this._ambientControllers = [];
|
|
3214
|
+
/**
|
|
3215
|
+
* The type definition has to be duplicated due to the
|
|
3216
|
+
* "'use' is referenced directly or indirectly in its own type annotation."
|
|
3217
|
+
* error
|
|
3218
|
+
*/
|
|
3219
|
+
this.use = async (value, watchExports) => {
|
|
3220
|
+
const controller = this.useRefSync(value);
|
|
3221
|
+
if (controller === void 0) {
|
|
3222
|
+
if (typeof watchExports === "function") {
|
|
3223
|
+
const error = new Error(
|
|
3224
|
+
`Unable to resolve a controller from the provided value, so can't watch it's exports. ${unresolvableExports}`
|
|
3225
|
+
);
|
|
3226
|
+
console.error(error);
|
|
3227
|
+
}
|
|
3228
|
+
return value;
|
|
3229
|
+
}
|
|
3230
|
+
await controller.ready;
|
|
3231
|
+
if (typeof watchExports === "function") {
|
|
3232
|
+
if (controller.watchExports === void 0)
|
|
3233
|
+
throw new Error(`The controller must implement watchExports method to support watching exports`);
|
|
3234
|
+
const unsubscribe = controller.watchExports(
|
|
3235
|
+
(exports) => watchExports(exports, unsubscribe)
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
return controller.exports;
|
|
3239
|
+
};
|
|
3240
|
+
this.useRef = async (value) => {
|
|
3241
|
+
const controller = this.useRefSync(value);
|
|
3242
|
+
if (controller === void 0)
|
|
3243
|
+
throw new Error(`Unable to resolve a controller from the provided value. ${unresolvableExports}`);
|
|
3244
|
+
await controller.ready;
|
|
3245
|
+
return controller;
|
|
3246
|
+
};
|
|
3247
|
+
this.shouldBypassSetter = false;
|
|
3248
|
+
this.shouldBypassGetter = false;
|
|
3249
|
+
this.shouldBypassReadonly = false;
|
|
3250
|
+
/**
|
|
3251
|
+
* A map from component instance or component element to component instance.
|
|
3252
|
+
* To get from component instance or component element to component element,
|
|
3253
|
+
* you can just use the .el property
|
|
3254
|
+
*/
|
|
3255
|
+
this.elementToInstance = /* @__PURE__ */ new WeakMap();
|
|
3256
|
+
}
|
|
3257
|
+
/*
|
|
3258
|
+
* Allow controllers to implicitly retrieve which component they are in, to
|
|
3259
|
+
* improve DX (avoids the need to pass "this" explicitly for each controller)
|
|
3260
|
+
*/
|
|
3261
|
+
setAmbientComponent(component) {
|
|
3262
|
+
if (this._ambientComponent === component)
|
|
3263
|
+
return;
|
|
3264
|
+
this._ambientComponent = component;
|
|
3265
|
+
queueMicrotask(() => {
|
|
3266
|
+
if (this._ambientComponent === component)
|
|
3267
|
+
this._ambientComponent = void 0;
|
|
3268
|
+
});
|
|
3269
|
+
}
|
|
3270
|
+
retrieveComponent(name) {
|
|
3271
|
+
if (this._ambientComponent === void 0)
|
|
3272
|
+
throw new Error(
|
|
3273
|
+
[
|
|
3274
|
+
`Unable to find out which component ${name || "this"} controller `,
|
|
3275
|
+
"belongs to. This might happen if you tried to create a controller ",
|
|
3276
|
+
"outside the component. If so, please wrap your controller ",
|
|
3277
|
+
"definition in an arrow function, ",
|
|
3278
|
+
"`const myController = ()=>makeController(...);` and call that",
|
|
3279
|
+
"function inside the component `my = myController();`, or ",
|
|
3280
|
+
"define your controller using makeGenericController/GenericController ",
|
|
3281
|
+
"instead.\n",
|
|
3282
|
+
"If you wish to use a controller inside an async controller, ",
|
|
3283
|
+
"make sure you are using controller.use.\n",
|
|
3284
|
+
"You might also have multiple instances of Controllers loaded"
|
|
3285
|
+
].join("\n")
|
|
3286
|
+
);
|
|
3287
|
+
return this._ambientComponent;
|
|
3288
|
+
}
|
|
3289
|
+
/*
|
|
3290
|
+
* Aids proxyExports() in knowing who is it's host
|
|
3291
|
+
*/
|
|
3292
|
+
setParentController(controller) {
|
|
3293
|
+
if (controller === void 0) {
|
|
3294
|
+
this._ambientControllers = [];
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
const index = this._ambientControllers.indexOf(controller);
|
|
3298
|
+
this._ambientControllers = index === -1 ? [...this._ambientControllers, controller] : this._ambientControllers.slice(0, index + 1);
|
|
3299
|
+
queueMicrotask(() => {
|
|
3300
|
+
this._ambientControllers = [];
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3303
|
+
retrieveParentControllers() {
|
|
3304
|
+
return this._ambientControllers;
|
|
3305
|
+
}
|
|
3306
|
+
/*
|
|
3307
|
+
* Aids controller.use in retrieving controller value when it receives
|
|
3308
|
+
* controller exports, rather than the controller itself
|
|
3309
|
+
*/
|
|
3310
|
+
setAmbientChildController(controller) {
|
|
3311
|
+
if (this._ambientChildController === controller)
|
|
3312
|
+
return;
|
|
3313
|
+
this._ambientChildController = controller;
|
|
3314
|
+
queueMicrotask(() => {
|
|
3315
|
+
if (this._ambientChildController === controller)
|
|
3316
|
+
this._ambientChildController = void 0;
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
retrieveAmbientChildController() {
|
|
3320
|
+
const controller = this._ambientChildController;
|
|
3321
|
+
this._ambientChildController = void 0;
|
|
3322
|
+
return controller;
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Try to resolve a controller, without awaiting it's load
|
|
3326
|
+
*/
|
|
3327
|
+
useRefSync(value) {
|
|
3328
|
+
const ambientChildController = this.retrieveAmbientChildController();
|
|
3329
|
+
if (ambientChildController !== void 0)
|
|
3330
|
+
return ambientChildController;
|
|
3331
|
+
const component = Controller.internals.retrieveComponent();
|
|
3332
|
+
const controller = component.manager.internals.resolveExports(value);
|
|
3333
|
+
if (controller !== void 0)
|
|
3334
|
+
return controller;
|
|
3335
|
+
if (isController(value))
|
|
3336
|
+
return value;
|
|
3337
|
+
return void 0;
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
var unresolvableExports = [
|
|
3341
|
+
"The value you passed is not a controller and not a controller exports. If ",
|
|
3342
|
+
"your controller exports a literal value, try making your controller export ",
|
|
3343
|
+
"an object instead"
|
|
3344
|
+
].join("");
|
|
3345
|
+
|
|
3346
|
+
// src/Controller.ts
|
|
3347
|
+
var _a;
|
|
3348
|
+
var _Controller = class _Controller {
|
|
3349
|
+
constructor(component) {
|
|
3350
|
+
this._ready = new Deferred();
|
|
3351
|
+
this._lifecycleDisconnected = [];
|
|
3352
|
+
this.connectedCalled = false;
|
|
3353
|
+
this.willLoadCalled = false;
|
|
3354
|
+
this.didLoadCalled = false;
|
|
3355
|
+
this[_a] = true;
|
|
3356
|
+
this.ready = this._ready.promise;
|
|
3357
|
+
/*
|
|
3358
|
+
* Setting default exports to "this" so that controllers that don't use
|
|
3359
|
+
* exports/proxyExports(), could still be used as if they did
|
|
3360
|
+
* (i.e with controller.use)
|
|
3361
|
+
*/
|
|
3362
|
+
this._exports = makeProvisionalValue(this);
|
|
3363
|
+
this._exportWatchers = /* @__PURE__ */ new Set();
|
|
3364
|
+
const resolvedComponent = toControllerHost(
|
|
3365
|
+
component ?? _Controller.internals.retrieveComponent(new.target.name)
|
|
3366
|
+
);
|
|
3367
|
+
Object.defineProperty(this, "component", {
|
|
3368
|
+
writable: false,
|
|
3369
|
+
enumerable: false,
|
|
3370
|
+
configurable: true,
|
|
3371
|
+
value: resolvedComponent
|
|
3372
|
+
});
|
|
3373
|
+
this.component.addController(this);
|
|
3374
|
+
_Controller.internals.setParentController(this);
|
|
3375
|
+
if ("hostDestroy" in this)
|
|
3376
|
+
this.component.manager.ensureHasDestroy();
|
|
3377
|
+
const manager = this.component.manager;
|
|
3378
|
+
const isInControllerManager = manager === void 0;
|
|
3379
|
+
if (!isInControllerManager)
|
|
3380
|
+
queueMicrotask(() => this.catchUpLifecycle());
|
|
3381
|
+
const controller = isInControllerManager ? {} : this;
|
|
3382
|
+
this._callbacks = {
|
|
3383
|
+
hostConnected: "hostConnected" in controller ? [() => controller.hostConnected?.()] : [],
|
|
3384
|
+
hostDisconnected: "hostDisconnected" in controller ? [() => controller.hostDisconnected?.()] : [],
|
|
3385
|
+
hostLoad: "hostLoad" in controller ? [() => controller.hostLoad?.()] : [],
|
|
3386
|
+
hostLoaded: "hostLoaded" in controller ? [() => controller.hostLoaded?.()] : [],
|
|
3387
|
+
hostUpdate: "hostUpdate" in controller ? [() => controller.hostUpdate?.()] : [],
|
|
3388
|
+
hostUpdated: "hostUpdated" in controller ? [() => controller.hostUpdated?.()] : [],
|
|
3389
|
+
hostDestroy: "hostDestroy" in controller ? [() => controller.hostDestroy?.()] : [],
|
|
3390
|
+
hostLifecycle: "hostLifecycle" in controller ? [() => controller.hostLifecycle?.()] : []
|
|
3391
|
+
};
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* If controller is being added dynamically, after the component
|
|
3395
|
+
* construction, then trigger connected and load right away
|
|
3396
|
+
*/
|
|
3397
|
+
catchUpLifecycle() {
|
|
3398
|
+
if (this.connectedCalled)
|
|
3399
|
+
return;
|
|
3400
|
+
this.triggerConnected();
|
|
3401
|
+
const loadWillStillHappen = !this.component.manager.willLoadCalled;
|
|
3402
|
+
if (loadWillStillHappen)
|
|
3403
|
+
return;
|
|
3404
|
+
this.triggerLoad().then(() => {
|
|
3405
|
+
const loadedWillStillHappen = !this.component.manager.didLoadCalled;
|
|
3406
|
+
if (loadedWillStillHappen)
|
|
3407
|
+
return;
|
|
3408
|
+
this.triggerLoaded();
|
|
3409
|
+
}).catch(console.error);
|
|
3410
|
+
}
|
|
3411
|
+
get exports() {
|
|
3412
|
+
return this._exports;
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* Set controller's exports property (for usage with proxyExports()) and mark
|
|
3416
|
+
* controller as ready (for usage in other controllers). Also, triggers
|
|
3417
|
+
* re-render of the component
|
|
3418
|
+
*/
|
|
3419
|
+
set exports(exports) {
|
|
3420
|
+
if (this._exports !== exports) {
|
|
3421
|
+
this._exports = exports;
|
|
3422
|
+
if (this.connectedCalled)
|
|
3423
|
+
this.component.requestUpdate();
|
|
3424
|
+
this._exportWatchers.forEach((callback) => callback(exports));
|
|
3425
|
+
}
|
|
3426
|
+
this._ready.resolve(exports);
|
|
3427
|
+
}
|
|
3428
|
+
setProvisionalExports(exports) {
|
|
3429
|
+
this._exports = makeProvisionalValue(exports);
|
|
3430
|
+
this._exportWatchers.forEach((callback) => callback(this._exports));
|
|
3431
|
+
}
|
|
3432
|
+
watchExports(callback) {
|
|
3433
|
+
const safeCallback = (exports) => safeCall(() => callback(exports));
|
|
3434
|
+
this._exportWatchers.add(safeCallback);
|
|
3435
|
+
return () => void this._exportWatchers.delete(safeCallback);
|
|
3436
|
+
}
|
|
3437
|
+
/**
|
|
3438
|
+
* A flexible utility for making sure a controller is loaded before it's used,
|
|
3439
|
+
* regardless of how or where a controller was defined:
|
|
3440
|
+
*
|
|
3441
|
+
* @example
|
|
3442
|
+
* makeGenericController(async (component, controller) => {
|
|
3443
|
+
* // Await some controller from the component:
|
|
3444
|
+
* await controller.use(component.someController);
|
|
3445
|
+
* // Initialize new controllers
|
|
3446
|
+
* await controller.use(load(importCoreReactiveUtils));
|
|
3447
|
+
* await controller.use(new ViewModelController(component,newWidgetsHomeHomeViewModel));
|
|
3448
|
+
* await controller.use(someController(component));
|
|
3449
|
+
* });
|
|
3450
|
+
*
|
|
3451
|
+
* @remarks
|
|
3452
|
+
* If your controller is not async, and you are not creating it async, then
|
|
3453
|
+
* you are not required to use controller.use - you can use it directly.
|
|
3454
|
+
* Similarly, accessing controllers after componentWillLoad callback does not
|
|
3455
|
+
* require awaiting them as they are guaranteed to be loaded by then.
|
|
3456
|
+
*/
|
|
3457
|
+
get use() {
|
|
3458
|
+
_Controller.internals.setAmbientComponent(this.component);
|
|
3459
|
+
return _Controller.internals.use;
|
|
3460
|
+
}
|
|
3461
|
+
/**
|
|
3462
|
+
* Just like controller.use, but returns the controller itself, rather than it's
|
|
3463
|
+
* exports
|
|
3464
|
+
*
|
|
3465
|
+
* Use cases:
|
|
3466
|
+
* - You have a controller and you want to make sure it's loaded before you
|
|
3467
|
+
* try to use it
|
|
3468
|
+
* - Your controller is not using exports, so you wish to access some props on
|
|
3469
|
+
* it directly
|
|
3470
|
+
* - You have a controller exports only, and you want to retrieve the
|
|
3471
|
+
* controller itself. This is useful if you wish to call .watchExports() or
|
|
3472
|
+
* some other method on the controller
|
|
3473
|
+
*/
|
|
3474
|
+
get useRef() {
|
|
3475
|
+
_Controller.internals.setAmbientComponent(this.component);
|
|
3476
|
+
return _Controller.internals.useRef;
|
|
3477
|
+
}
|
|
3478
|
+
/**
|
|
3479
|
+
* If you need to set a prop/state without triggering the custom setter you
|
|
3480
|
+
* defined with getSet()/dynamicGetSet()/readonly(), set the value inside
|
|
3481
|
+
* of this function
|
|
3482
|
+
*
|
|
3483
|
+
* @example
|
|
3484
|
+
* @Prop() readOnly = this.manager.readOnly(true);
|
|
3485
|
+
*
|
|
3486
|
+
* someAction(): void {
|
|
3487
|
+
* this.manager.bypassSetter(()=>{
|
|
3488
|
+
* this.readOnly = false;
|
|
3489
|
+
* });
|
|
3490
|
+
* }
|
|
3491
|
+
*
|
|
3492
|
+
*/
|
|
3493
|
+
bypassSetter(callback) {
|
|
3494
|
+
_Controller.internals.shouldBypassSetter = true;
|
|
3495
|
+
try {
|
|
3496
|
+
return callback();
|
|
3497
|
+
} finally {
|
|
3498
|
+
_Controller.internals.shouldBypassSetter = false;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* Like bypassSetter, but only bypasses this.manager.readonly(), rather that
|
|
3503
|
+
* all setters set using this.manager.getSet()
|
|
3504
|
+
*/
|
|
3505
|
+
bypassReadonly(callback) {
|
|
3506
|
+
_Controller.internals.shouldBypassReadonly = true;
|
|
3507
|
+
try {
|
|
3508
|
+
return callback();
|
|
3509
|
+
} finally {
|
|
3510
|
+
_Controller.internals.shouldBypassReadonly = false;
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
/**
|
|
3514
|
+
* Property reads inside of this function will bypass any custom getter you
|
|
3515
|
+
* may have, and read the value directly from what's stored in Stencil/Lit.
|
|
3516
|
+
*
|
|
3517
|
+
* This also bypasses reactiveUtils integration - reading a property inside of
|
|
3518
|
+
* bypassGetter won't make that property tracked.
|
|
3519
|
+
*
|
|
3520
|
+
* @example
|
|
3521
|
+
* reactiveUtils.watch(
|
|
3522
|
+
* ()=>{
|
|
3523
|
+
* this.manager.bypassGetter(()=>{
|
|
3524
|
+
* console.log(this.someProp);
|
|
3525
|
+
* });
|
|
3526
|
+
* return this.prop;
|
|
3527
|
+
* },
|
|
3528
|
+
* console.log
|
|
3529
|
+
* )
|
|
3530
|
+
*/
|
|
3531
|
+
bypassGetter(callback) {
|
|
3532
|
+
_Controller.internals.shouldBypassGetter = true;
|
|
3533
|
+
try {
|
|
3534
|
+
return callback();
|
|
3535
|
+
} finally {
|
|
3536
|
+
_Controller.internals.shouldBypassGetter = false;
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
/**
|
|
3540
|
+
* Like this.manager.getSet(), but can be called on any component's
|
|
3541
|
+
* state/prop from anywhere, rather than just from the default value
|
|
3542
|
+
*/
|
|
3543
|
+
dynamicGetSet(name, getSet) {
|
|
3544
|
+
this.genericGetSet(name, getSet);
|
|
3545
|
+
}
|
|
3546
|
+
/**
|
|
3547
|
+
* Like dynamicGetSet, but less type-safe. Useful in cases when trying to set
|
|
3548
|
+
* getters/setters in place where property names & types are not known
|
|
3549
|
+
* statically
|
|
3550
|
+
*/
|
|
3551
|
+
genericGetSet(property, getSet) {
|
|
3552
|
+
var _a2, _b;
|
|
3553
|
+
const genericGetSet = getSet;
|
|
3554
|
+
const internals = this.component.manager.internals;
|
|
3555
|
+
if (genericGetSet.get !== void 0) {
|
|
3556
|
+
(_a2 = internals.getters)[property] ?? (_a2[property] = []);
|
|
3557
|
+
internals.getters[property].unshift(genericGetSet.get);
|
|
3558
|
+
}
|
|
3559
|
+
if (genericGetSet.set !== void 0) {
|
|
3560
|
+
(_b = internals.setters)[property] ?? (_b[property] = []);
|
|
3561
|
+
internals.setters[property].unshift(genericGetSet.set);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
// FEATURE: improve typings
|
|
3565
|
+
/**
|
|
3566
|
+
* Dynamically set a watcher for any reactive property
|
|
3567
|
+
*/
|
|
3568
|
+
watch(property, callback) {
|
|
3569
|
+
var _a2;
|
|
3570
|
+
const type = getMemberType(this.component, property);
|
|
3571
|
+
if (type === void 0)
|
|
3572
|
+
throw new Error(
|
|
3573
|
+
`Trying to watch a non-@property, non-@state property "${property}". Either convert it into a @state() or use get/set syntax`
|
|
3574
|
+
);
|
|
3575
|
+
const internals = this.component.manager.internals;
|
|
3576
|
+
(_a2 = internals.allWatchers)[property] ?? (_a2[property] = []);
|
|
3577
|
+
const watchers = internals.allWatchers[property];
|
|
3578
|
+
const genericCallback = callback;
|
|
3579
|
+
const safeCallback = (newValue, oldValue, propertyName) => safeCall(() => genericCallback(newValue, oldValue, propertyName));
|
|
3580
|
+
watchers.push(safeCallback);
|
|
3581
|
+
return () => {
|
|
3582
|
+
const index = watchers.indexOf(safeCallback);
|
|
3583
|
+
if (index !== -1)
|
|
3584
|
+
watchers.splice(index, 1);
|
|
3585
|
+
};
|
|
3586
|
+
}
|
|
3587
|
+
// Register a lifecycle callback
|
|
3588
|
+
onConnected(callback) {
|
|
3589
|
+
this._callbacks.hostConnected.push(callback);
|
|
3590
|
+
}
|
|
3591
|
+
onDisconnected(callback) {
|
|
3592
|
+
this._callbacks.hostDisconnected.push(callback);
|
|
3593
|
+
}
|
|
3594
|
+
onLoad(callback) {
|
|
3595
|
+
this._callbacks.hostLoad.push(callback);
|
|
3596
|
+
}
|
|
3597
|
+
onLoaded(callback) {
|
|
3598
|
+
this._callbacks.hostLoaded.push(callback);
|
|
3599
|
+
}
|
|
3600
|
+
onUpdate(callback) {
|
|
3601
|
+
this._callbacks.hostUpdate.push(callback);
|
|
3602
|
+
}
|
|
3603
|
+
onUpdated(callback) {
|
|
3604
|
+
this._callbacks.hostUpdated.push(callback);
|
|
3605
|
+
}
|
|
3606
|
+
onDestroy(callback) {
|
|
3607
|
+
this.component.manager.ensureHasDestroy();
|
|
3608
|
+
this._callbacks.hostDestroy.push(callback);
|
|
3609
|
+
}
|
|
3610
|
+
onLifecycle(callback) {
|
|
3611
|
+
this._callbacks.hostLifecycle.push(callback);
|
|
3612
|
+
if (this.connectedCalled && this.component.el.isConnected)
|
|
3613
|
+
this._callLifecycle(callback);
|
|
3614
|
+
}
|
|
3615
|
+
// Call each lifecycle hook
|
|
3616
|
+
triggerConnected() {
|
|
3617
|
+
this._callbacks.hostConnected.forEach(safeCall);
|
|
3618
|
+
this.triggerLifecycle();
|
|
3619
|
+
this.connectedCalled = true;
|
|
3620
|
+
}
|
|
3621
|
+
triggerDisconnected() {
|
|
3622
|
+
this._callbacks.hostDisconnected.forEach(safeCall);
|
|
3623
|
+
this._lifecycleDisconnected.forEach(safeCall);
|
|
3624
|
+
this._lifecycleDisconnected = [];
|
|
3625
|
+
}
|
|
3626
|
+
async triggerLoad() {
|
|
3627
|
+
if (this.willLoadCalled)
|
|
3628
|
+
return;
|
|
3629
|
+
this.willLoadCalled = true;
|
|
3630
|
+
if (this._callbacks.hostLoad.length > 0)
|
|
3631
|
+
await Promise.allSettled(this._callbacks.hostLoad.map(safeAsyncCall));
|
|
3632
|
+
this._ready.resolve(this._exports);
|
|
3633
|
+
}
|
|
3634
|
+
triggerLoaded() {
|
|
3635
|
+
if (this.didLoadCalled)
|
|
3636
|
+
return;
|
|
3637
|
+
this._callbacks.hostLoaded.forEach(safeCall);
|
|
3638
|
+
this.didLoadCalled = true;
|
|
3639
|
+
}
|
|
3640
|
+
triggerUpdate() {
|
|
3641
|
+
this._callbacks.hostUpdate.forEach(safeCall);
|
|
3642
|
+
}
|
|
3643
|
+
triggerUpdated() {
|
|
3644
|
+
this._callbacks.hostUpdated.forEach(safeCall);
|
|
3645
|
+
}
|
|
3646
|
+
triggerDestroy() {
|
|
3647
|
+
this._callbacks.hostDestroy.forEach(safeCall);
|
|
3648
|
+
}
|
|
3649
|
+
triggerLifecycle() {
|
|
3650
|
+
this._callbacks.hostLifecycle.forEach((callback) => this._callLifecycle(callback));
|
|
3651
|
+
}
|
|
3652
|
+
_callLifecycle(callback) {
|
|
3653
|
+
_Controller.internals.setAmbientComponent(this.component);
|
|
3654
|
+
const cleanupRaw = safeCall(callback);
|
|
3655
|
+
const cleanup = Array.isArray(cleanupRaw) ? cleanupRaw : [cleanupRaw];
|
|
3656
|
+
cleanup.forEach((cleanup2) => {
|
|
3657
|
+
if (typeof cleanup2 === "function")
|
|
3658
|
+
this._lifecycleDisconnected.push(cleanup2);
|
|
3659
|
+
else if (typeof cleanup2 === "object" && typeof cleanup2.remove === "function")
|
|
3660
|
+
this._lifecycleDisconnected.push(cleanup2.remove);
|
|
3661
|
+
});
|
|
3662
|
+
}
|
|
3663
|
+
};
|
|
3664
|
+
_a = controllerSymbol;
|
|
3665
|
+
_Controller.internals = new ControllerInternals();
|
|
3666
|
+
var Controller = _Controller;
|
|
3667
|
+
var GenericController = class extends Controller {
|
|
3668
|
+
// Redundant constructor needed to improve typing
|
|
3669
|
+
constructor(component) {
|
|
3670
|
+
super(component);
|
|
3671
|
+
}
|
|
3672
|
+
// Overriding super's watch only to improve typing
|
|
3673
|
+
watch(property, callback) {
|
|
3674
|
+
return super.watch(
|
|
3675
|
+
property,
|
|
3676
|
+
callback
|
|
3677
|
+
);
|
|
3678
|
+
}
|
|
3679
|
+
dynamicGetSet(property, getSet) {
|
|
3680
|
+
super.genericGetSet(property, getSet);
|
|
3681
|
+
}
|
|
3682
|
+
};
|
|
3683
|
+
function makeProvisionalValue(base) {
|
|
3684
|
+
if (typeof base !== "object" && typeof base !== "function" || base === null)
|
|
3685
|
+
return base;
|
|
3686
|
+
const proxy2 = new Proxy(base, {
|
|
3687
|
+
get(target, prop, receiver) {
|
|
3688
|
+
if (cyclical.has(prop) && prop in target && target[prop] === proxy2)
|
|
3689
|
+
return void 0;
|
|
3690
|
+
if (prop in target || prop in Promise.prototype || typeof prop === "symbol")
|
|
3691
|
+
return typeof target === "function" ? target[prop] : Reflect.get(target, prop, receiver);
|
|
3692
|
+
console.error(`Trying to access "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
|
|
3693
|
+
return void 0;
|
|
3694
|
+
},
|
|
3695
|
+
set(target, prop, newValue, receiver) {
|
|
3696
|
+
console.error(`Trying to set "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
|
|
3697
|
+
return Reflect.set(target, prop, newValue, receiver);
|
|
3698
|
+
}
|
|
3699
|
+
});
|
|
3700
|
+
return proxy2;
|
|
3701
|
+
}
|
|
3702
|
+
var cyclical = /* @__PURE__ */ new Set(["exports", "_exports"]);
|
|
3703
|
+
var accessBeforeLoad = "" ;
|
|
3704
|
+
function toControllerHost(component) {
|
|
3705
|
+
if ("addController" in component)
|
|
3706
|
+
return component;
|
|
3707
|
+
else
|
|
3708
|
+
throw new Error(
|
|
3709
|
+
"Component does not implement ControllerHost. This might be because you forgot to add 'manager: Controller<this> = useControllerManager(this);' in your component, or you tried to use some controller before that line"
|
|
3710
|
+
);
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
// src/proxyExports.ts
|
|
3714
|
+
var proxyExports = (Class) => (...args) => {
|
|
3715
|
+
const ambientControllers = Controller.internals.retrieveParentControllers();
|
|
3716
|
+
const instance = new Class(...args);
|
|
3717
|
+
const initialExports = instance.exports;
|
|
3718
|
+
Controller.internals.setParentController(ambientControllers.at(-1));
|
|
3719
|
+
const internals = instance.component.manager.internals;
|
|
3720
|
+
internals.markExports(instance, initialExports);
|
|
3721
|
+
instance.watchExports((exports) => internals.markExports(instance, exports));
|
|
3722
|
+
Controller.internals.setAmbientChildController(instance);
|
|
3723
|
+
const hostCandidates = [instance.component, ...ambientControllers].reverse();
|
|
3724
|
+
return internals.trackKey(
|
|
3725
|
+
hostCandidates,
|
|
3726
|
+
(resolution) => resolution === void 0 ? void 0 : setProxy(instance, resolution.host, resolution.key, initialExports),
|
|
3727
|
+
initialExports
|
|
3728
|
+
);
|
|
3729
|
+
};
|
|
3730
|
+
function setProxy(controller, host, key, initialExports) {
|
|
3731
|
+
const genericHost = host;
|
|
3732
|
+
const controllerValueChanged = genericHost[key] !== controller.exports;
|
|
3733
|
+
const hostValueChanged = genericHost[key] !== initialExports;
|
|
3734
|
+
const controllerUpdatedExports = initialExports !== controller.exports;
|
|
3735
|
+
if (controllerValueChanged && !hostValueChanged && controllerUpdatedExports)
|
|
3736
|
+
genericHost[key] = controller.exports;
|
|
3737
|
+
controller.watchExports(() => {
|
|
3738
|
+
if (genericHost[key] === controller.exports)
|
|
3739
|
+
return;
|
|
3740
|
+
const manager = controller.component.manager;
|
|
3741
|
+
const isReadOnly = manager.internals.readonlyProps?.has(key) === true;
|
|
3742
|
+
if (isReadOnly)
|
|
3743
|
+
manager.bypassReadonly(() => {
|
|
3744
|
+
genericHost[key] = controller.exports;
|
|
3745
|
+
});
|
|
3746
|
+
else
|
|
3747
|
+
genericHost[key] = controller.exports;
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
// src/functional.ts
|
|
3752
|
+
var makeController = (constructor) => proxy(void 0, constructor);
|
|
3753
|
+
var FunctionalController = class extends Controller {
|
|
3754
|
+
constructor(component, constructor) {
|
|
3755
|
+
super(component);
|
|
3756
|
+
const originalExports = this.exports;
|
|
3757
|
+
try {
|
|
3758
|
+
Controller.internals.setAmbientComponent(this.component);
|
|
3759
|
+
const value = constructor(this.component, this);
|
|
3760
|
+
const constructorChangedExports = this.exports !== originalExports;
|
|
3761
|
+
if (value instanceof Promise) {
|
|
3762
|
+
if (!constructorChangedExports)
|
|
3763
|
+
this.setProvisionalExports(value);
|
|
3764
|
+
const resolved = value.then((result) => {
|
|
3765
|
+
this.exports = result;
|
|
3766
|
+
super.catchUpLifecycle();
|
|
3767
|
+
}).catch((error) => {
|
|
3768
|
+
this._ready.reject(error);
|
|
3769
|
+
console.error(error);
|
|
3770
|
+
});
|
|
3771
|
+
this.onLoad(async () => await resolved);
|
|
3772
|
+
} else {
|
|
3773
|
+
if (!constructorChangedExports || value !== void 0)
|
|
3774
|
+
this.exports = value;
|
|
3775
|
+
queueMicrotask(() => super.catchUpLifecycle());
|
|
3776
|
+
}
|
|
3777
|
+
} catch (error) {
|
|
3778
|
+
this._ready.reject(error);
|
|
3779
|
+
console.error(error);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
/** Noop - will be called in the constructor instead */
|
|
3783
|
+
catchUpLifecycle() {
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
3787
|
+
var proxy = proxyExports(FunctionalController);
|
|
3788
|
+
|
|
3789
|
+
// src/trackPropertyKey.ts
|
|
3790
|
+
function trackPropertyKey(object, onResolved, defaultValue) {
|
|
3791
|
+
const keys = Object.keys(object);
|
|
3792
|
+
const keyCount = keys.length;
|
|
3793
|
+
if (keyTrackMap === void 0)
|
|
3794
|
+
queueMicrotask(keyTrackResolve);
|
|
3795
|
+
keyTrackMap ?? (keyTrackMap = /* @__PURE__ */ new Map());
|
|
3796
|
+
let pendingTrackers = keyTrackMap.get(object);
|
|
3797
|
+
if (pendingTrackers === void 0) {
|
|
3798
|
+
pendingTrackers = { callbacks: [], keyCount };
|
|
3799
|
+
keyTrackMap.set(object, pendingTrackers);
|
|
3800
|
+
}
|
|
3801
|
+
if (pendingTrackers.keyCount !== keyCount) {
|
|
3802
|
+
pendingTrackers.callbacks.forEach((resolve) => resolve(keys));
|
|
3803
|
+
pendingTrackers.callbacks = [];
|
|
3804
|
+
pendingTrackers.keyCount = keyCount;
|
|
3805
|
+
}
|
|
3806
|
+
pendingTrackers.callbacks.push((keys2) => {
|
|
3807
|
+
const callback = (key2) => safeCall(() => onResolved(key2));
|
|
3808
|
+
const key = keys2[keyCount];
|
|
3809
|
+
if (key === void 0)
|
|
3810
|
+
callback(void 0);
|
|
3811
|
+
else if (object[key] === defaultValue)
|
|
3812
|
+
callback(key);
|
|
3813
|
+
else
|
|
3814
|
+
callback(void 0);
|
|
3815
|
+
});
|
|
3816
|
+
return defaultValue;
|
|
3817
|
+
}
|
|
3818
|
+
var keyTrackMap = void 0;
|
|
3819
|
+
function keyTrackResolve() {
|
|
3820
|
+
Array.from(keyTrackMap?.entries() ?? []).forEach(([object, { callbacks }]) => {
|
|
3821
|
+
const keys = Object.keys(object);
|
|
3822
|
+
callbacks.forEach((commit) => commit(keys));
|
|
3823
|
+
});
|
|
3824
|
+
keyTrackMap = void 0;
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
// src/ComponentInternals.ts
|
|
3828
|
+
var ComponentInternals = class {
|
|
3829
|
+
constructor(component) {
|
|
3830
|
+
/**
|
|
3831
|
+
* When watchers are set, set then into `allWatchers`. When watchers are read
|
|
3832
|
+
* in the setter, read from `enabledWatchers`.
|
|
3833
|
+
* On connectedCallback(), controller manager does `enabledWatchers=allWatchers`.
|
|
3834
|
+
* Reasoning:
|
|
3835
|
+
* - This disables watchers until connected callback (matches behavior of
|
|
3836
|
+
* Stencil's watchers)
|
|
3837
|
+
* - This removes in the setter to check if watchers were enabled already or
|
|
3838
|
+
* not (as getters/setters are hot path, and should be streamlined)
|
|
3839
|
+
*/
|
|
3840
|
+
this.enabledWatchers = {};
|
|
3841
|
+
this.allWatchers = {};
|
|
3842
|
+
this.trackKey = (hostsCandidates, onResolved, defaultValue) => {
|
|
3843
|
+
const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
|
|
3844
|
+
let leftToResolve = candidateHosts.length + 1;
|
|
3845
|
+
const resolved = (resolution) => {
|
|
3846
|
+
leftToResolve -= 1;
|
|
3847
|
+
if (resolution !== void 0)
|
|
3848
|
+
leftToResolve = 0;
|
|
3849
|
+
if (leftToResolve === 0)
|
|
3850
|
+
onResolved(resolution);
|
|
3851
|
+
};
|
|
3852
|
+
candidateHosts.forEach(
|
|
3853
|
+
(host) => this.component.manager.trackPropertyKey(
|
|
3854
|
+
host,
|
|
3855
|
+
(key) => resolved(
|
|
3856
|
+
key === void 0 ? void 0 : {
|
|
3857
|
+
key,
|
|
3858
|
+
host,
|
|
3859
|
+
type: "property",
|
|
3860
|
+
domValue: void 0
|
|
3861
|
+
}
|
|
3862
|
+
),
|
|
3863
|
+
defaultValue
|
|
3864
|
+
)
|
|
3865
|
+
);
|
|
3866
|
+
this.component.manager.trackPropKey((key, domValue) => {
|
|
3867
|
+
const propType = key === void 0 ? void 0 : getPropType(this.component, key);
|
|
3868
|
+
resolved(
|
|
3869
|
+
key === void 0 ? void 0 : {
|
|
3870
|
+
key,
|
|
3871
|
+
host: this.component,
|
|
3872
|
+
type: propType ?? "prop",
|
|
3873
|
+
domValue: propType === "prop" ? domValue : void 0
|
|
3874
|
+
}
|
|
3875
|
+
);
|
|
3876
|
+
}, defaultValue);
|
|
3877
|
+
return defaultValue;
|
|
3878
|
+
};
|
|
3879
|
+
this.trackPropKey = (onResolved, defaultValue) => {
|
|
3880
|
+
if (this._trackedValue !== nothing && this._trackedValue !== defaultValue)
|
|
3881
|
+
this._firePropertyTrackers(void 0, void 0, void 0);
|
|
3882
|
+
if (this._keyTrackers.length === 0)
|
|
3883
|
+
queueMicrotask(() => this._firePropertyTrackers(void 0, void 0, void 0));
|
|
3884
|
+
this._trackedValue = defaultValue;
|
|
3885
|
+
this._keyTrackers.push(
|
|
3886
|
+
(key, value, previousValue) => safeCall(() => onResolved(defaultValue === value ? key : void 0, previousValue))
|
|
3887
|
+
);
|
|
3888
|
+
return defaultValue;
|
|
3889
|
+
};
|
|
3890
|
+
this._trackedValue = nothing;
|
|
3891
|
+
this._keyTrackers = [];
|
|
3892
|
+
this.getters = {};
|
|
3893
|
+
this.setters = {};
|
|
3894
|
+
this.accessorGetter = {};
|
|
3895
|
+
this.accessorSetter = {};
|
|
3896
|
+
this._exports = /* @__PURE__ */ new WeakMap();
|
|
3897
|
+
Object.defineProperty(this, "component", {
|
|
3898
|
+
writable: false,
|
|
3899
|
+
enumerable: false,
|
|
3900
|
+
configurable: true,
|
|
3901
|
+
value: component
|
|
3902
|
+
});
|
|
3903
|
+
}
|
|
3904
|
+
_firePropertyTrackers(key, value, oldValue) {
|
|
3905
|
+
const trackers = this._keyTrackers;
|
|
3906
|
+
this._trackedValue = nothing;
|
|
3907
|
+
this._keyTrackers = [];
|
|
3908
|
+
trackers.forEach((tracker) => tracker(key, value, oldValue));
|
|
3909
|
+
}
|
|
3910
|
+
/**
|
|
3911
|
+
* Configure a getter or setter for a given \@Prop/\@State
|
|
3912
|
+
*
|
|
3913
|
+
* Note, since props are defined on the prototype, they are shared between all
|
|
3914
|
+
* instances of a component. Thus, instead of passing a reference to the
|
|
3915
|
+
* getter/setter function, you should update the
|
|
3916
|
+
* ComponentInternals.getters/setters properties, and then call getSetProxy
|
|
3917
|
+
* to apply the changes to the prototype
|
|
3918
|
+
*/
|
|
3919
|
+
getSetProxy(property, hasGetter, hasSetter) {
|
|
3920
|
+
const component = this.component;
|
|
3921
|
+
const classPrototype = component.constructor.prototype;
|
|
3922
|
+
this._getSetProxy(classPrototype, property, hasGetter, hasSetter, "class");
|
|
3923
|
+
if (component.manager.isLit)
|
|
3924
|
+
return;
|
|
3925
|
+
const htmlPrototype = component.el.constructor.prototype;
|
|
3926
|
+
if (classPrototype !== htmlPrototype)
|
|
3927
|
+
this._getSetProxy(htmlPrototype, property, hasGetter, hasSetter, "html");
|
|
3928
|
+
}
|
|
3929
|
+
_getSetProxy(prototype, name, hasGetter, hasSetter, type) {
|
|
3930
|
+
const component = this.component;
|
|
3931
|
+
const propType = getMemberType(component, name);
|
|
3932
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
3933
|
+
const tolerateNotFound = type === "html";
|
|
3934
|
+
if (descriptor?.set === void 0 || descriptor.get === void 0)
|
|
3935
|
+
if (descriptor !== void 0 && "value" in descriptor)
|
|
3936
|
+
throw new Error(
|
|
3937
|
+
`getSet() should only be used on @Prop/@property/@State/@state properties. For internal component properties, use regular get/set syntax. Tried to use it on "${name}" in ${component.el.tagName}`
|
|
3938
|
+
);
|
|
3939
|
+
else if (tolerateNotFound)
|
|
3940
|
+
return;
|
|
3941
|
+
else
|
|
3942
|
+
throw new Error(`Unable to find "${name}" property on the ${component.el.tagName} component`);
|
|
3943
|
+
const { get: originalGet, set: originalSet } = descriptor;
|
|
3944
|
+
const isGetterAlreadyOverwritten = customAccessor in originalGet;
|
|
3945
|
+
const isSetterAlreadyOverwritten = customAccessor in originalSet;
|
|
3946
|
+
const shouldOverwriteGet = !isGetterAlreadyOverwritten && hasGetter;
|
|
3947
|
+
const shouldOverwriteSet = !isSetterAlreadyOverwritten && hasSetter;
|
|
3948
|
+
if (!shouldOverwriteGet && !shouldOverwriteSet)
|
|
3949
|
+
return;
|
|
3950
|
+
const finalGetter = shouldOverwriteGet ? function getter() {
|
|
3951
|
+
let value = originalGet.call(this);
|
|
3952
|
+
const component2 = Controller.internals.elementToInstance.get(this);
|
|
3953
|
+
if (Controller.internals.shouldBypassGetter || component2 === void 0)
|
|
3954
|
+
return value;
|
|
3955
|
+
const internals = component2.manager.internals;
|
|
3956
|
+
value = internals.accessorGetter[name](value, name);
|
|
3957
|
+
const getters = internals.getters[name] ?? emptyArray;
|
|
3958
|
+
for (let i = 0; i < getters.length; i++)
|
|
3959
|
+
value = getters[i](value, name);
|
|
3960
|
+
return value;
|
|
3961
|
+
} : originalGet;
|
|
3962
|
+
const finalSetter = shouldOverwriteSet ? function setter(rawNewValue) {
|
|
3963
|
+
const oldValue = originalGet.call(this);
|
|
3964
|
+
const component2 = Controller.internals.elementToInstance.get(this);
|
|
3965
|
+
if (component2 === void 0) {
|
|
3966
|
+
originalSet.call(this, rawNewValue);
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
let newValue = component2.manager.isLit ? rawNewValue : parsePropertyValue(rawNewValue, propType);
|
|
3970
|
+
const internals = component2.manager.internals;
|
|
3971
|
+
if (newValue === oldValue)
|
|
3972
|
+
originalSet.call(this, rawNewValue);
|
|
3973
|
+
else {
|
|
3974
|
+
const setters = Controller.internals.shouldBypassSetter ? emptyArray : internals.setters[name] ?? emptyArray;
|
|
3975
|
+
for (let i = 0; i < setters.length; i++)
|
|
3976
|
+
newValue = setters[i](newValue, oldValue, name);
|
|
3977
|
+
newValue = internals.accessorSetter[name](newValue, oldValue, name);
|
|
3978
|
+
originalSet.call(this, newValue);
|
|
3979
|
+
if (newValue !== oldValue)
|
|
3980
|
+
internals.enabledWatchers[name]?.forEach((watcher) => watcher(newValue, oldValue, name));
|
|
3981
|
+
}
|
|
3982
|
+
if (internals._keyTrackers.length > 0)
|
|
3983
|
+
internals?._firePropertyTrackers(name, rawNewValue, oldValue);
|
|
3984
|
+
} : originalSet;
|
|
3985
|
+
if (shouldOverwriteGet)
|
|
3986
|
+
Object.defineProperty(finalGetter, customAccessor, { value: true });
|
|
3987
|
+
if (shouldOverwriteSet)
|
|
3988
|
+
Object.defineProperty(finalSetter, customAccessor, { value: true });
|
|
3989
|
+
Object.defineProperty(prototype, name, {
|
|
3990
|
+
...descriptor,
|
|
3991
|
+
get: finalGetter,
|
|
3992
|
+
set: finalSetter
|
|
3993
|
+
});
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Associate an exports object with a controller for reverse lookup in
|
|
3997
|
+
* controller.use
|
|
3998
|
+
*/
|
|
3999
|
+
markExports(controller, exports) {
|
|
4000
|
+
if (typeof exports === "object" && exports !== null || typeof exports === "function")
|
|
4001
|
+
this._exports.set(exports, controller);
|
|
4002
|
+
}
|
|
4003
|
+
resolveExports(exports) {
|
|
4004
|
+
if (typeof exports === "object" && exports !== null || typeof exports === "function")
|
|
4005
|
+
return this._exports.get(exports);
|
|
4006
|
+
else
|
|
4007
|
+
return void 0;
|
|
4008
|
+
}
|
|
4009
|
+
};
|
|
4010
|
+
var emptyArray = [];
|
|
4011
|
+
var customAccessor = Symbol("controllersCustomAccessor");
|
|
4012
|
+
var nothing = Symbol("nothing");
|
|
4013
|
+
|
|
4014
|
+
// src/ControllerManager.ts
|
|
4015
|
+
var useControllerManager = (component, forceUpdate) => new ControllerManager(component, forceUpdate);
|
|
4016
|
+
var ControllerManager = class extends GenericController {
|
|
4017
|
+
constructor(component, forceUpdate) {
|
|
4018
|
+
const isLit = "addController" in component;
|
|
4019
|
+
const controllers = /* @__PURE__ */ new Set();
|
|
4020
|
+
function addController(controller) {
|
|
4021
|
+
controllers.add(controller);
|
|
4022
|
+
if (isLit && !(controllerSymbol in controller) && component.el.isConnected)
|
|
4023
|
+
controller.hostConnected?.();
|
|
4024
|
+
}
|
|
4025
|
+
const removeController = (controller) => void controllers.delete(controller);
|
|
4026
|
+
if (!isLit) {
|
|
4027
|
+
const update = forceUpdate ?? component.constructor.__forceUpdate;
|
|
4028
|
+
const controllerHost = {
|
|
4029
|
+
addController,
|
|
4030
|
+
removeController,
|
|
4031
|
+
requestUpdate: () => update(component)
|
|
4032
|
+
};
|
|
4033
|
+
extendObject(component, controllerHost);
|
|
4034
|
+
}
|
|
4035
|
+
super(component);
|
|
4036
|
+
this.internals = new ComponentInternals(this.component);
|
|
4037
|
+
this.destroyed = false;
|
|
4038
|
+
this._updatePromise = new Deferred();
|
|
4039
|
+
this._originalLifecycles = {};
|
|
4040
|
+
/**
|
|
4041
|
+
* A magical solution to finding out what property name a given controller
|
|
4042
|
+
* on a given object was assigned to. Note, this does not work for properties
|
|
4043
|
+
* that have \@Prop() or \@State() decorator - for those, use
|
|
4044
|
+
* manager.trackPropKey() instead.
|
|
4045
|
+
*
|
|
4046
|
+
* @example
|
|
4047
|
+
* function trackMe<T>(defaultValue:T, component:BaseComponent):T {
|
|
4048
|
+
* component.manager.trackPropertyKey(component, (key)=>console.log(key), defaultValue);
|
|
4049
|
+
* return defaultValue;
|
|
4050
|
+
* }
|
|
4051
|
+
*
|
|
4052
|
+
* class MyComponent extends BaseComponent {
|
|
4053
|
+
* // Will console log "myProp"
|
|
4054
|
+
* myProp = trackMe('a', this);
|
|
4055
|
+
* }
|
|
4056
|
+
*
|
|
4057
|
+
*/
|
|
4058
|
+
this.trackPropertyKey = trackPropertyKey;
|
|
4059
|
+
/**
|
|
4060
|
+
* Like manager.trackPropertyKey(), but for props that have \@State() or \@Prop()
|
|
4061
|
+
* decorator
|
|
4062
|
+
*
|
|
4063
|
+
* @example
|
|
4064
|
+
* function trackMe(component:BaseComponent) {
|
|
4065
|
+
* component.manager.trackPropKey((key)=>console.log(key));
|
|
4066
|
+
* }
|
|
4067
|
+
*
|
|
4068
|
+
* class MyComponent extends BaseComponent {
|
|
4069
|
+
* // Will console log "myProp"
|
|
4070
|
+
* @Prop() myProp = trackMe(this);
|
|
4071
|
+
*
|
|
4072
|
+
* // Will console log "myState"
|
|
4073
|
+
* @State() myState = trackMe(this);
|
|
4074
|
+
* }
|
|
4075
|
+
*/
|
|
4076
|
+
this.trackPropKey = this.internals.trackPropKey;
|
|
4077
|
+
/**
|
|
4078
|
+
* A combination of trackPropertyKey() and trackPropKey(). For usage when
|
|
4079
|
+
* you want to track a property, but don't know if it will be defined with the
|
|
4080
|
+
* \@Prop() decorator or not
|
|
4081
|
+
*/
|
|
4082
|
+
this.trackKey = this.internals.trackKey;
|
|
4083
|
+
this._readonlySetter = (newValue, oldValue, property) => {
|
|
4084
|
+
if (Controller.internals.shouldBypassReadonly)
|
|
4085
|
+
return newValue;
|
|
4086
|
+
const component = this.component;
|
|
4087
|
+
const isProp = getPropType(component, property) === "prop";
|
|
4088
|
+
if (isProp) {
|
|
4089
|
+
if (this.isLit) {
|
|
4090
|
+
const details = getLitProperties(component).get(property);
|
|
4091
|
+
if (details && details?.attribute !== false)
|
|
4092
|
+
component.el.setAttribute(
|
|
4093
|
+
typeof details.attribute === "string" ? details.attribute : camelToKebab(property),
|
|
4094
|
+
// Not using converter.toAttribute to keep this unlikely case simpler
|
|
4095
|
+
String(oldValue)
|
|
4096
|
+
);
|
|
4097
|
+
} else
|
|
4098
|
+
component.requestUpdate();
|
|
4099
|
+
}
|
|
4100
|
+
throw new Error(
|
|
4101
|
+
`Cannot assign to read-only property "${property}" of ${component.el.tagName.toLowerCase()}. Trying to assign "${String(
|
|
4102
|
+
newValue
|
|
4103
|
+
)}"`
|
|
4104
|
+
);
|
|
4105
|
+
};
|
|
4106
|
+
/**
|
|
4107
|
+
* In development, on hot module reload, controller would be re-initialized
|
|
4108
|
+
* with all Props and State values persistent, but properties lost. This unsafe
|
|
4109
|
+
* development-only API lets you set or get data for a controller that would
|
|
4110
|
+
* persist across hot reloads.
|
|
4111
|
+
*/
|
|
4112
|
+
this.devOnlySetPersistentControllerData = void 0 ;
|
|
4113
|
+
this.devOnlyGetPersistentControllerData = void 0 ;
|
|
4114
|
+
if (isLit) {
|
|
4115
|
+
component.addController = addController;
|
|
4116
|
+
component.removeController = removeController;
|
|
4117
|
+
}
|
|
4118
|
+
this.isLit = isLit;
|
|
4119
|
+
this.component.manager = this;
|
|
4120
|
+
retrieveComponentMembers(component, isLit);
|
|
4121
|
+
this._controllers = controllers;
|
|
4122
|
+
this.exports = void 0;
|
|
4123
|
+
this.hasDestroy = "autoDestroyDisabled" in this.component && typeof this.component.destroy === "function";
|
|
4124
|
+
if (this.hasDestroy)
|
|
4125
|
+
this.watch("autoDestroyDisabled", () => this._autoDestroyDisabledWatcher());
|
|
4126
|
+
this._bindLifecycleMethods();
|
|
4127
|
+
if (!isLit)
|
|
4128
|
+
Object.defineProperty(component, "updateComplete", {
|
|
4129
|
+
get: async () => await this._updatePromise.promise
|
|
4130
|
+
});
|
|
4131
|
+
const members = getPropLikeMembers(component);
|
|
4132
|
+
const internals = component.manager.internals;
|
|
4133
|
+
members.forEach((name) => {
|
|
4134
|
+
internals.accessorGetter[name] = defaultGetterSetter;
|
|
4135
|
+
internals.accessorSetter[name] = defaultGetterSetter;
|
|
4136
|
+
internals.getSetProxy(name, true, true);
|
|
4137
|
+
});
|
|
4138
|
+
Controller.internals.setParentController(void 0);
|
|
4139
|
+
Controller.internals.setAmbientComponent(component);
|
|
4140
|
+
Controller.internals.elementToInstance.set(component.el, component);
|
|
4141
|
+
Controller.internals.elementToInstance.set(component, component);
|
|
4142
|
+
}
|
|
4143
|
+
_bindLifecycleMethods() {
|
|
4144
|
+
const component = this.component;
|
|
4145
|
+
const isLit = this.isLit;
|
|
4146
|
+
this._originalLifecycles = {
|
|
4147
|
+
// These callbacks will be called by Lit, so we don't have to
|
|
4148
|
+
connectedCallback: isLit ? void 0 : component.connectedCallback,
|
|
4149
|
+
disconnectedCallback: isLit ? void 0 : component.disconnectedCallback,
|
|
4150
|
+
componentWillLoad: isLit ? void 0 : component.componentWillLoad,
|
|
4151
|
+
componentDidLoad: isLit ? void 0 : component.componentDidLoad,
|
|
4152
|
+
componentWillUpdate: isLit ? void 0 : component.componentWillUpdate,
|
|
4153
|
+
componentDidUpdate: isLit ? void 0 : component.componentDidUpdate,
|
|
4154
|
+
destroy: component.destroy
|
|
4155
|
+
};
|
|
4156
|
+
if (!isLit) {
|
|
4157
|
+
component.connectedCallback = this.hostConnected.bind(this);
|
|
4158
|
+
component.disconnectedCallback = this.hostDisconnected.bind(this);
|
|
4159
|
+
component.componentWillLoad = this.hostLoad.bind(this);
|
|
4160
|
+
component.componentDidLoad = this.hostLoaded.bind(this);
|
|
4161
|
+
component.componentWillUpdate = this.hostUpdate.bind(this);
|
|
4162
|
+
component.componentDidUpdate = this.hostUpdated.bind(this);
|
|
4163
|
+
}
|
|
4164
|
+
if (this.hasDestroy)
|
|
4165
|
+
component.destroy = this.destroy.bind(this);
|
|
4166
|
+
}
|
|
4167
|
+
/**
|
|
4168
|
+
* Throws an error if component does not implement destroy() lifecycle, but
|
|
4169
|
+
* tries to use it.
|
|
4170
|
+
*/
|
|
4171
|
+
ensureHasDestroy() {
|
|
4172
|
+
if (!this.hasDestroy)
|
|
4173
|
+
throw new Error(destroyErrorMessage);
|
|
4174
|
+
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Private because this is not supposed to be called by Component directly.
|
|
4177
|
+
* Instead, _bindLifecycleMethods will take care of that. Otherwise, you risk
|
|
4178
|
+
* calling lifecycle methods twice.
|
|
4179
|
+
*/
|
|
4180
|
+
hostConnected() {
|
|
4181
|
+
if (this.destroyed) {
|
|
4182
|
+
const tagName = this.component.el.tagName.toLowerCase();
|
|
4183
|
+
this.component.el.remove();
|
|
4184
|
+
throw new Error(
|
|
4185
|
+
`The ${tagName} component has already been destroyed. It can not be used again. If you meant to disconnect and reconnect a component without automatic destroy, set the autoDestroyDisabled prop.`
|
|
4186
|
+
);
|
|
4187
|
+
}
|
|
4188
|
+
if (this._autoDestroyTimeout !== void 0)
|
|
4189
|
+
clearTimeout(this._autoDestroyTimeout);
|
|
4190
|
+
this.internals.enabledWatchers = this.internals.allWatchers;
|
|
4191
|
+
keyTrackResolve();
|
|
4192
|
+
this._controllers.forEach(
|
|
4193
|
+
(controller) => "triggerConnected" in controller ? controller.triggerConnected() : safeCall(() => controller.hostConnected?.())
|
|
4194
|
+
);
|
|
4195
|
+
this._originalLifecycles.connectedCallback?.call(this.component);
|
|
4196
|
+
}
|
|
4197
|
+
hostDisconnected() {
|
|
4198
|
+
if (this.destroyed)
|
|
4199
|
+
return;
|
|
4200
|
+
this._controllers.forEach(
|
|
4201
|
+
(controller) => "triggerDisconnected" in controller ? controller.triggerDisconnected() : safeCall(() => controller.hostDisconnected?.())
|
|
4202
|
+
);
|
|
4203
|
+
this._originalLifecycles.disconnectedCallback?.call(this.component);
|
|
4204
|
+
if (this.hasDestroy)
|
|
4205
|
+
this._autoDestroyDisabledWatcher();
|
|
4206
|
+
}
|
|
4207
|
+
// REFACTOR: don't force async if there are no async load controllers?
|
|
4208
|
+
async hostLoad() {
|
|
4209
|
+
if (typeof this.internals.reactiveUtilsIntegration === "function")
|
|
4210
|
+
await this.internals.reactiveUtilsIntegration();
|
|
4211
|
+
await Promise.allSettled(
|
|
4212
|
+
Array.from(
|
|
4213
|
+
this._controllers,
|
|
4214
|
+
async (controller) => "triggerLoad" in controller ? await controller.triggerLoad() : await safeAsyncCall(async () => await controller.hostLoad?.())
|
|
4215
|
+
)
|
|
4216
|
+
);
|
|
4217
|
+
await this._originalLifecycles.componentWillLoad?.call(this.component);
|
|
4218
|
+
}
|
|
4219
|
+
hostLoaded() {
|
|
4220
|
+
this._controllers.forEach(
|
|
4221
|
+
(controller) => "triggerLoaded" in controller ? controller.triggerLoaded() : safeCall(() => controller.hostLoaded?.())
|
|
4222
|
+
);
|
|
4223
|
+
this._originalLifecycles.componentDidLoad?.call(this.component);
|
|
4224
|
+
}
|
|
4225
|
+
hostUpdate() {
|
|
4226
|
+
this._controllers.forEach(
|
|
4227
|
+
(controller) => "triggerUpdate" in controller ? controller.triggerUpdate() : safeCall(() => controller.hostUpdate?.())
|
|
4228
|
+
);
|
|
4229
|
+
void this._originalLifecycles.componentWillUpdate?.call(this.component);
|
|
4230
|
+
}
|
|
4231
|
+
hostUpdated() {
|
|
4232
|
+
this._controllers.forEach(
|
|
4233
|
+
(controller) => "triggerUpdated" in controller ? controller.triggerUpdated() : safeCall(() => controller.hostUpdated?.())
|
|
4234
|
+
);
|
|
4235
|
+
this._originalLifecycles.componentDidUpdate?.call(this.component);
|
|
4236
|
+
if (!this.isLit) {
|
|
4237
|
+
const updatePromise = this._updatePromise;
|
|
4238
|
+
this._updatePromise = new Deferred();
|
|
4239
|
+
updatePromise.resolve(true);
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
async destroy() {
|
|
4243
|
+
this.ensureHasDestroy();
|
|
4244
|
+
if (this.destroyed)
|
|
4245
|
+
return;
|
|
4246
|
+
if (this.component.el.isConnected) {
|
|
4247
|
+
this.hasDestroy = false;
|
|
4248
|
+
try {
|
|
4249
|
+
this.component.el.remove();
|
|
4250
|
+
} finally {
|
|
4251
|
+
this.hasDestroy = true;
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
this._autoDestroyTimeout = void 0;
|
|
4255
|
+
this.destroyed = true;
|
|
4256
|
+
this._controllers.forEach(
|
|
4257
|
+
(controller) => "triggerDestroy" in controller ? controller.triggerDestroy() : safeCall(() => controller.hostDestroy?.())
|
|
4258
|
+
);
|
|
4259
|
+
this._controllers.clear();
|
|
4260
|
+
await this._originalLifecycles.destroy?.call(this.component);
|
|
4261
|
+
}
|
|
4262
|
+
_autoDestroyDisabledWatcher() {
|
|
4263
|
+
if (!this.component.el.isConnected && !this.component.autoDestroyDisabled) {
|
|
4264
|
+
if (this._autoDestroyTimeout !== void 0)
|
|
4265
|
+
clearTimeout(this._autoDestroyTimeout);
|
|
4266
|
+
const destroy = () => void this.destroy().catch(console.error);
|
|
4267
|
+
this._autoDestroyTimeout = setTimeout(destroy, autoDestroyOnDisconnectTimeout);
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
// REFACTOR: replace this with a readonly:true option in @property()
|
|
4271
|
+
/**
|
|
4272
|
+
* Make a @Prop() or @State() readonly (prevent overwriting default value).
|
|
4273
|
+
*
|
|
4274
|
+
* For internal properties, prefer TypeScript's "readonly" modifier instead.
|
|
4275
|
+
*
|
|
4276
|
+
* @example
|
|
4277
|
+
* // Defining readonly prop
|
|
4278
|
+
* @Prop({ reflect: true }) prop = this.manager.readonly('a');
|
|
4279
|
+
*
|
|
4280
|
+
* @example
|
|
4281
|
+
* // Overwriting readonly prop internally
|
|
4282
|
+
* this.manager.bypassReadonly(()=>{
|
|
4283
|
+
* this.prop = 'b';
|
|
4284
|
+
* });
|
|
4285
|
+
*
|
|
4286
|
+
*/
|
|
4287
|
+
readonly(value) {
|
|
4288
|
+
return this.getSet(value, { set: this._readonlySetter });
|
|
4289
|
+
}
|
|
4290
|
+
// REFACTOR: remove this in Lit in favor of native get/set
|
|
4291
|
+
/**
|
|
4292
|
+
* Listen for any component's @State()/@Prop() change, and mutate it's
|
|
4293
|
+
* value before it is set.
|
|
4294
|
+
* This is necessary because Stencil's Compiler does not support get/set for
|
|
4295
|
+
* @State()/@Prop().
|
|
4296
|
+
* For private component properties, you should use regular get/set syntax.
|
|
4297
|
+
*
|
|
4298
|
+
* @example
|
|
4299
|
+
* @Prop() exampleProp = this.manager.getSet(defaultValue,{get,set})
|
|
4300
|
+
* @Prop() someProp = this.manager.getSet(
|
|
4301
|
+
* undefined as string | undefined,
|
|
4302
|
+
* {
|
|
4303
|
+
* get: (value)=>value.trim(),
|
|
4304
|
+
* set: (newValue,oldValue) => newValue.trim() ?? oldValue
|
|
4305
|
+
* }
|
|
4306
|
+
* )
|
|
4307
|
+
*
|
|
4308
|
+
* @remarks
|
|
4309
|
+
* Unlike a native get/set, the get function receives the current attribute
|
|
4310
|
+
* value, and can modify it before returning it (or can disregard the current
|
|
4311
|
+
* value and get it from elsewhere instead).
|
|
4312
|
+
* Similarly, setter is called with the new and old value, and is expected to
|
|
4313
|
+
* return the final new value (or return the old value to undo the change)
|
|
4314
|
+
*/
|
|
4315
|
+
getSet(defaultValue, getSet) {
|
|
4316
|
+
return this.component.manager.trackPropKey((name) => {
|
|
4317
|
+
var _a;
|
|
4318
|
+
if (name === void 0)
|
|
4319
|
+
throw new Error(
|
|
4320
|
+
"Unable to resolve get/set's prop name. Make sure you are using it like @Prop() someProp = this.manager.getSet(defaultValue,{get,set})"
|
|
4321
|
+
);
|
|
4322
|
+
if (getSet.set === this._readonlySetter) {
|
|
4323
|
+
(_a = this.internals).readonlyProps ?? (_a.readonlyProps = /* @__PURE__ */ new Set());
|
|
4324
|
+
this.internals.readonlyProps.add(name);
|
|
4325
|
+
}
|
|
4326
|
+
const genericComponent = this.component;
|
|
4327
|
+
const value = genericComponent[name];
|
|
4328
|
+
if (value != null && value !== defaultValue && typeof getSet.set === "function" && getSet.initialSet !== false) {
|
|
4329
|
+
const newValue = getSet.set(value, defaultValue, name);
|
|
4330
|
+
if (newValue !== value)
|
|
4331
|
+
genericComponent[name] = newValue;
|
|
4332
|
+
}
|
|
4333
|
+
this.genericGetSet(name, getSet);
|
|
4334
|
+
}, defaultValue);
|
|
4335
|
+
}
|
|
4336
|
+
};
|
|
4337
|
+
var destroyErrorMessage = `
|
|
4338
|
+
If the component uses a controller that uses destroy() method, then the
|
|
4339
|
+
component must have the following properties:
|
|
4340
|
+
${// Don't expose internal code in production, and keep bundle smaller:
|
|
4341
|
+
`autoDestroyDisabled and destroy` }
|
|
4342
|
+
`.trim();
|
|
4343
|
+
var autoDestroyOnDisconnectTimeout = 1e3;
|
|
4344
|
+
var defaultGetterSetter = (value) => value;
|
|
4345
|
+
|
|
4346
|
+
// src/useT9n.ts
|
|
4347
|
+
var makeT9nController = (getAssetPath) => ({ blocking = false, name } = {}) => (
|
|
4348
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
4349
|
+
makeController((component, controller) => {
|
|
4350
|
+
controller.onLifecycle(
|
|
4351
|
+
() => startLocaleObserver(
|
|
4352
|
+
component.el,
|
|
4353
|
+
getAssetPath("./assets"),
|
|
4354
|
+
({ t9nLocale, t9nStrings, lang }) => {
|
|
4355
|
+
controller.exports = { ...t9nStrings, _lang: lang, _t9nLocale: t9nLocale };
|
|
4356
|
+
const label = t9nStrings.componentLabel ?? t9nStrings.widgetLabel;
|
|
4357
|
+
if (typeof label === "string" && "label" in component && component.label == null)
|
|
4358
|
+
component.label ?? (component.label = label);
|
|
4359
|
+
},
|
|
4360
|
+
name
|
|
4361
|
+
)
|
|
4362
|
+
);
|
|
4363
|
+
if (blocking)
|
|
4364
|
+
return controller.ready;
|
|
4365
|
+
const locale = getElementLocales(component.el);
|
|
4366
|
+
return { _lang: locale.lang, _t9nLocale: locale.t9nLocale };
|
|
4367
|
+
})
|
|
4368
|
+
);
|
|
4369
|
+
|
|
2940
4370
|
function isMonacoEnvironmentSetup() {
|
|
2941
4371
|
return !!window.MonacoEnvironment?.getWorkerUrl;
|
|
2942
4372
|
}
|
|
@@ -2977,21 +4407,81 @@ function setupMonacoEnvironment(assetsPath) {
|
|
|
2977
4407
|
break;
|
|
2978
4408
|
}
|
|
2979
4409
|
// If we have a relative path or we are on same orgin, we can use the default js implementation
|
|
2980
|
-
if (!
|
|
4410
|
+
if (!isURL(url) || hasSameOrigin(url, globalThis.location.href, true)) {
|
|
2981
4411
|
return new Worker(url, { name: languageId });
|
|
2982
4412
|
}
|
|
2983
4413
|
// For cross orgin, we will load the worker code as a string and manufacture a blob
|
|
2984
4414
|
const esriRequest = await importRequest();
|
|
2985
4415
|
const response = await esriRequest(url, {
|
|
2986
|
-
responseType: "text"
|
|
4416
|
+
responseType: "text",
|
|
2987
4417
|
});
|
|
2988
4418
|
return new Worker(URL.createObjectURL(new Blob([response.data], {
|
|
2989
|
-
type: "text/javascript"
|
|
4419
|
+
type: "text/javascript",
|
|
2990
4420
|
})));
|
|
2991
|
-
}
|
|
4421
|
+
},
|
|
2992
4422
|
};
|
|
2993
4423
|
}
|
|
2994
4424
|
|
|
4425
|
+
const themeConfig = {
|
|
4426
|
+
"arcade-light-theme": {
|
|
4427
|
+
comment: "#606060",
|
|
4428
|
+
constant: "#9809C8",
|
|
4429
|
+
date: "#296389",
|
|
4430
|
+
identifier: "#0000B3",
|
|
4431
|
+
keyword: "#BF4900",
|
|
4432
|
+
number: "#136D3D",
|
|
4433
|
+
string: "#A31515"
|
|
4434
|
+
},
|
|
4435
|
+
"arcade-dark-theme": {
|
|
4436
|
+
comment: "#BFBFBF",
|
|
4437
|
+
constant: "#CDBAEA",
|
|
4438
|
+
date: "#97A6CE",
|
|
4439
|
+
identifier: "#9FD4F3",
|
|
4440
|
+
keyword: "#EEAA5A",
|
|
4441
|
+
number: "#AAD04B",
|
|
4442
|
+
string: "#F2877B"
|
|
4443
|
+
}
|
|
4444
|
+
};
|
|
4445
|
+
|
|
4446
|
+
function setupArcadeTheme() {
|
|
4447
|
+
["light", "dark"].forEach((theme) => {
|
|
4448
|
+
const base = theme === "light" ? "vs" : "vs-dark";
|
|
4449
|
+
const colors = themeConfig[`arcade-${theme}-theme`];
|
|
4450
|
+
// Defines the light and dark theme based on the calcite theme name
|
|
4451
|
+
editor.defineTheme(base, {
|
|
4452
|
+
base,
|
|
4453
|
+
inherit: true,
|
|
4454
|
+
rules: [
|
|
4455
|
+
{ token: "comment.arc", foreground: colors.comment },
|
|
4456
|
+
{ token: "constant.arc", foreground: colors.constant },
|
|
4457
|
+
{ token: "keyword.arc", foreground: colors.keyword },
|
|
4458
|
+
{ token: "identifier.arc", foreground: colors.identifier },
|
|
4459
|
+
{ token: "number.arc", foreground: colors.number },
|
|
4460
|
+
{ token: "string.arc", foreground: colors.string },
|
|
4461
|
+
],
|
|
4462
|
+
colors: {},
|
|
4463
|
+
});
|
|
4464
|
+
});
|
|
4465
|
+
}
|
|
4466
|
+
const monacoThemeKeys = ["comment", "keyword", "identifier", "string", "number", "constant"];
|
|
4467
|
+
const colorRulesKeys = [...monacoThemeKeys, "date"];
|
|
4468
|
+
function updateThemeColors(theme, colorRules) {
|
|
4469
|
+
if (colorRules === undefined) {
|
|
4470
|
+
setupArcadeTheme();
|
|
4471
|
+
return;
|
|
4472
|
+
}
|
|
4473
|
+
const base = theme === "light" ? "vs" : "vs-dark";
|
|
4474
|
+
const rules = [];
|
|
4475
|
+
monacoThemeKeys.forEach((key) => {
|
|
4476
|
+
const foreground = colorRules[key];
|
|
4477
|
+
if (!foreground) {
|
|
4478
|
+
return;
|
|
4479
|
+
}
|
|
4480
|
+
rules.push({ token: `${key}.arc`, foreground });
|
|
4481
|
+
});
|
|
4482
|
+
editor.defineTheme(base, { base, inherit: true, rules, colors: {} });
|
|
4483
|
+
}
|
|
4484
|
+
|
|
2995
4485
|
/**
|
|
2996
4486
|
* Returns the arcade diagnostic service.
|
|
2997
4487
|
* Example:
|
|
@@ -3021,23 +4511,22 @@ async function getArcadeWorker(uri) {
|
|
|
3021
4511
|
}
|
|
3022
4512
|
/**
|
|
3023
4513
|
* Request the arcade mode
|
|
3024
|
-
* @returns mode
|
|
4514
|
+
* @returns arcade mode module
|
|
3025
4515
|
*/
|
|
3026
4516
|
async function getMode() {
|
|
3027
|
-
return await import('./arcade-mode-
|
|
4517
|
+
return await import('./arcade-mode-c4dd84f5.js');
|
|
3028
4518
|
}
|
|
3029
4519
|
// Register the language in Monaco
|
|
3030
4520
|
languages.register({
|
|
3031
4521
|
id: arcadeDefaults.languageId,
|
|
3032
4522
|
aliases: ["Arcade", "arcade"],
|
|
3033
4523
|
extensions: [".arc"],
|
|
3034
|
-
mimetypes: ["application/arcade"]
|
|
4524
|
+
mimetypes: ["application/arcade"],
|
|
3035
4525
|
});
|
|
3036
4526
|
// An event emitted when a language is first time needed
|
|
3037
4527
|
languages.onLanguage(arcadeDefaults.languageId, () => {
|
|
3038
|
-
|
|
4528
|
+
setupArcadeTheme();
|
|
3039
4529
|
arcadeDefaults.setLanguageOptions({ assetsPath: `${getAssetsPath() ?? "."}/arcade-language` });
|
|
3040
|
-
// Async import the language mode
|
|
3041
4530
|
getMode()
|
|
3042
4531
|
.then((mode) => {
|
|
3043
4532
|
// Setup the language mode
|
|
@@ -3048,13 +4537,17 @@ languages.onLanguage(arcadeDefaults.languageId, () => {
|
|
|
3048
4537
|
});
|
|
3049
4538
|
});
|
|
3050
4539
|
|
|
3051
|
-
const
|
|
4540
|
+
const useT9n = makeT9nController(getAssetPath);
|
|
4541
|
+
|
|
4542
|
+
const arcadeApiCss = ":host{background-color:var(--calcite-color-foreground-1)}:host .notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}:host .sticky{position:sticky;top:0px;z-index:10}:host calcite-flow{height:100%}:host calcite-block p:first-of-type{margin-top:0}:host calcite-block code{font-family:var(--calcite-code-family)}:host calcite-block pre{direction:ltr;overflow-x:auto;background-color:var(--calcite-color-foreground-2);padding:var(--calcite-spacing-sm)}:host calcite-block pre code{font-size:var(--calcite-font-size--2)}";
|
|
3052
4543
|
|
|
3053
4544
|
const ArcgisArcadeApi = class {
|
|
3054
4545
|
constructor(hostRef) {
|
|
3055
4546
|
registerInstance(this, hostRef);
|
|
3056
|
-
this.
|
|
3057
|
-
this.
|
|
4547
|
+
this.arcgisClose = createEvent(this, "arcgisClose", 3);
|
|
4548
|
+
this.arcgisItemSelected = createEvent(this, "arcgisItemSelected", 3);
|
|
4549
|
+
this.manager = useControllerManager(this);
|
|
4550
|
+
this.messages = useT9n();
|
|
3058
4551
|
this._emitItemSelected = (e) => {
|
|
3059
4552
|
const item = e.target?.["data-item"];
|
|
3060
4553
|
if (!item) {
|
|
@@ -3063,10 +4556,10 @@ const ArcgisArcadeApi = class {
|
|
|
3063
4556
|
const keyEvent = e;
|
|
3064
4557
|
if (!keyEvent.key || keyEvent.key === "Enter") {
|
|
3065
4558
|
e.preventDefault();
|
|
3066
|
-
this.
|
|
4559
|
+
this.arcgisItemSelected.emit(item.completion.insertText);
|
|
3067
4560
|
}
|
|
3068
4561
|
};
|
|
3069
|
-
this._emitClose = () => this.
|
|
4562
|
+
this._emitClose = () => this.arcgisClose.emit();
|
|
3070
4563
|
this._emitItemSelectedAndClose = (e) => {
|
|
3071
4564
|
if (!e.target) {
|
|
3072
4565
|
return;
|
|
@@ -3078,7 +4571,7 @@ const ArcgisArcadeApi = class {
|
|
|
3078
4571
|
if (!item) {
|
|
3079
4572
|
return;
|
|
3080
4573
|
}
|
|
3081
|
-
this.
|
|
4574
|
+
this.arcgisItemSelected.emit(item.completion.insertText);
|
|
3082
4575
|
}
|
|
3083
4576
|
};
|
|
3084
4577
|
this._selectItem = (e) => {
|
|
@@ -3094,9 +4587,6 @@ const ArcgisArcadeApi = class {
|
|
|
3094
4587
|
this._updateFilterValue = (e) => {
|
|
3095
4588
|
this._filterValue = e.target?.value ?? "";
|
|
3096
4589
|
};
|
|
3097
|
-
this._lang = "";
|
|
3098
|
-
this._t9nLocale = "";
|
|
3099
|
-
this._t9nStrings = undefined;
|
|
3100
4590
|
this._selectedApiItem = undefined;
|
|
3101
4591
|
this._filterValue = "";
|
|
3102
4592
|
this._colorizeStyle = "";
|
|
@@ -3110,7 +4600,6 @@ const ArcgisArcadeApi = class {
|
|
|
3110
4600
|
async componentWillLoad() {
|
|
3111
4601
|
this._colorizeStyle = generateColorizeStyles();
|
|
3112
4602
|
this._themeChangedListner = onColorizeThemeChanged(() => (this._colorizeStyle = generateColorizeStyles()));
|
|
3113
|
-
await B(this, getAssetPath("./assets"));
|
|
3114
4603
|
arcadeDefaults.onModelContextDidChange((key) => {
|
|
3115
4604
|
if (!this.modelId || key !== Uri.parse(this.modelId).toString()) {
|
|
3116
4605
|
return;
|
|
@@ -3120,7 +4609,6 @@ const ArcgisArcadeApi = class {
|
|
|
3120
4609
|
await this._updateApiLibrary();
|
|
3121
4610
|
}
|
|
3122
4611
|
disconnectedCallback() {
|
|
3123
|
-
q(this);
|
|
3124
4612
|
this._flowObserver?.disconnect();
|
|
3125
4613
|
this._themeChangedListner?.dispose();
|
|
3126
4614
|
}
|
|
@@ -3165,7 +4653,7 @@ const ArcgisArcadeApi = class {
|
|
|
3165
4653
|
// When switching between flow the same reference is reused
|
|
3166
4654
|
this._flowObserver = new MutationObserver(() => {
|
|
3167
4655
|
// Get the last panel and try to set focus on the input element
|
|
3168
|
-
|
|
4656
|
+
setFocusOnElement(ref.querySelector("calcite-flow-item:last-child"), "calcite-input");
|
|
3169
4657
|
});
|
|
3170
4658
|
this._flowObserver.observe(ref, { attributes: true, attributeFilter: ["id"], childList: true });
|
|
3171
4659
|
}
|
|
@@ -3176,14 +4664,14 @@ const ArcgisArcadeApi = class {
|
|
|
3176
4664
|
if (!filteredApiItems.length) {
|
|
3177
4665
|
return null;
|
|
3178
4666
|
}
|
|
3179
|
-
return (h("calcite-list-item-group", { heading: category.title }, filteredApiItems.map((apiItem) => (h("calcite-list-item", { label:
|
|
4667
|
+
return (h("calcite-list-item-group", { heading: category.title }, filteredApiItems.map((apiItem) => (h("calcite-list-item", { label: addLTRMark(apiItem.completion.detail), onCalciteListItemSelect: this._emitItemSelected, onKeyPress: this._emitItemSelected, "data-item": apiItem }, h("calcite-action", { slot: "actions-end", text: this.messages.expand ?? "Expand", icon: "chevron-right", iconFlipRtl: true, scale: "s", onClick: this._selectItem, "data-item": apiItem }))))));
|
|
3180
4668
|
}
|
|
3181
4669
|
renderApiItemFlowItem() {
|
|
3182
4670
|
const apiItem = this._selectedApiItem;
|
|
3183
4671
|
if (!apiItem) {
|
|
3184
4672
|
return null;
|
|
3185
4673
|
}
|
|
3186
|
-
return (h("calcite-flow-item", { heading: this.
|
|
4674
|
+
return (h("calcite-flow-item", { heading: this.messages.constantsandfunctions, beforeBack: this._unselectItem, closable: true, onCalciteFlowItemClose: this._emitClose }, this.hideDocumentationActions ? null : (h("calcite-button", { width: "half", slot: "footer", appearance: "outline", kind: "brand", scale: "s", href: apiItem.link, target: "Arcade Help", "icon-start": "information" }, this.messages.moreinformation)), h("calcite-button", { width: "half", slot: "footer", appearance: "outline", kind: "brand", "icon-start": "code", scale: "s", onClick: this._emitItemSelectedAndClose, "data-item": apiItem, ref: (e) => void e?.setFocus() }, this.messages.insert ?? "Insert"), h("calcite-block", { open: true, heading: addLTRMark(apiItem.completion.detail) }, h("div", { innerHTML: convertMarkdownString(apiItem.completion.documentation) }), apiItem.examples ? (h("div", { ref: (e) => {
|
|
3187
4675
|
if (!e) {
|
|
3188
4676
|
return;
|
|
3189
4677
|
}
|
|
@@ -3194,10 +4682,10 @@ const ArcgisArcadeApi = class {
|
|
|
3194
4682
|
render() {
|
|
3195
4683
|
const categories = (this._apiLibrary ?? []).map((apiCategory) => this.renderApiCategory(apiCategory));
|
|
3196
4684
|
const empty = categories.every((g) => !g);
|
|
3197
|
-
return (h(Host, null, h("style", null, this._colorizeStyle), h("calcite-flow", { ref: (ref) => this.flowFocusHandler(ref) }, h("calcite-flow-item", { heading: this.
|
|
4685
|
+
return (h(Host, null, h("style", null, this._colorizeStyle), h("calcite-flow", { ref: (ref) => this.flowFocusHandler(ref) }, h("calcite-flow-item", { heading: this.messages.constantsandfunctions, closable: true, onCalciteFlowItemClose: this._emitClose }, h("calcite-input", { value: this._filterValue, icon: "magnifying-glass", clearable: true, onCalciteInputInput: this._updateFilterValue, class: "sticky", scale: "m" }), this._preparingApi ? (h("calcite-loader", { scale: "s", type: "indeterminate", label: this.messages.loading ?? "Loading" })) : (h("calcite-list", null, empty ? h("div", { class: "notice-container" }, this.messages.noitems ?? "No items") : categories))), this.renderApiItemFlowItem())));
|
|
3198
4686
|
}
|
|
3199
4687
|
static get assetsDirs() { return ["assets"]; }
|
|
3200
|
-
get
|
|
4688
|
+
get el() { return getElement(this); }
|
|
3201
4689
|
};
|
|
3202
4690
|
ArcgisArcadeApi.style = arcadeApiCss;
|
|
3203
4691
|
|
|
@@ -3384,7 +4872,7 @@ async function executeScript(editorProfile, script, testContext, console) {
|
|
|
3384
4872
|
// Setup an executor with the script
|
|
3385
4873
|
const arcade = await importArcade();
|
|
3386
4874
|
const executor = await arcade.createArcadeExecutor(script ?? "", {
|
|
3387
|
-
variables: editorProfile?.variables ?? []
|
|
4875
|
+
variables: editorProfile?.variables ?? [],
|
|
3388
4876
|
});
|
|
3389
4877
|
// We want to measure the execution time
|
|
3390
4878
|
const t1 = performance.now();
|
|
@@ -3394,7 +4882,7 @@ async function executeScript(editorProfile, script, testContext, console) {
|
|
|
3394
4882
|
spatialReference,
|
|
3395
4883
|
timeZone,
|
|
3396
4884
|
rawOutput: true,
|
|
3397
|
-
console
|
|
4885
|
+
console,
|
|
3398
4886
|
};
|
|
3399
4887
|
// Execute the script
|
|
3400
4888
|
const scriptOutput = await executor.executeAsync(profileVariableInstances, executeContext);
|
|
@@ -3418,81 +4906,21 @@ async function executeScript(editorProfile, script, testContext, console) {
|
|
|
3418
4906
|
error,
|
|
3419
4907
|
timeStamp,
|
|
3420
4908
|
compilationTime: 0,
|
|
3421
|
-
executionTime: 0
|
|
4909
|
+
executionTime: 0,
|
|
3422
4910
|
};
|
|
3423
4911
|
}
|
|
3424
4912
|
}
|
|
3425
4913
|
|
|
3426
|
-
const
|
|
3427
|
-
"arcade-light-theme": {
|
|
3428
|
-
comment: "#606060",
|
|
3429
|
-
constant: "#9809C8",
|
|
3430
|
-
date: "#296389",
|
|
3431
|
-
identifier: "#0000B3",
|
|
3432
|
-
keyword: "#BF4900",
|
|
3433
|
-
number: "#136D3D",
|
|
3434
|
-
string: "#A31515"
|
|
3435
|
-
},
|
|
3436
|
-
"arcade-dark-theme": {
|
|
3437
|
-
comment: "#BFBFBF",
|
|
3438
|
-
constant: "#CDBAEA",
|
|
3439
|
-
date: "#97A6CE",
|
|
3440
|
-
identifier: "#9FD4F3",
|
|
3441
|
-
keyword: "#EEAA5A",
|
|
3442
|
-
number: "#AAD04B",
|
|
3443
|
-
string: "#F2877B"
|
|
3444
|
-
}
|
|
3445
|
-
};
|
|
4914
|
+
const arcadeEditorCss = "arcgis-arcade-editor{display:flex;flex-direction:column;position:relative;overflow:hidden;border:1px solid var(--calcite-color-border-3);box-sizing:border-box;background-color:var(--calcite-color-foreground-1);height:100%}arcgis-arcade-editor .flex-adjustable{flex:1 1 auto;overflow:hidden}arcgis-arcade-editor .flex-panel{flex:1 0 auto}arcgis-arcade-editor .position-relative{position:relative}arcgis-arcade-editor .flex-row{display:flex;flex-direction:row;overflow:hidden}arcgis-arcade-editor .flex-column{display:flex;flex-direction:column;overflow:hidden}arcgis-arcade-editor .border-inline-start{border-inline-start:1px solid var(--calcite-color-border-3);box-sizing:border-box}arcgis-arcade-editor .border-inline-end{border-inline-end:1px solid var(--calcite-color-border-3);box-sizing:border-box}arcgis-arcade-editor .sticky{position:sticky;top:0px;z-index:10}arcgis-arcade-editor .notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1);text-align:center}arcgis-arcade-editor .side-action-bar{max-width:25%}arcgis-arcade-editor .side-panel{max-width:45%;width:600px}arcgis-arcade-editor .side-panel calcite-flow{height:100%}arcgis-arcade-editor .main-action-bar{border-bottom:1px solid var(--calcite-color-border-3);flex:0 0 auto}arcgis-arcade-editor .main-action-bar calcite-action-group{padding-inline-end:var(--calcite-spacing-sm)}arcgis-arcade-editor .main-action-bar calcite-action-group calcite-action{padding-inline-end:var(--calcite-spacing-sm)}arcgis-arcade-editor .main-action-bar calcite-action-group calcite-action:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}arcgis-arcade-editor .main-action-bar calcite-action-group:last-child{border-inline-end-width:0px}arcgis-arcade-editor .main-action-bar calcite-action-group:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}arcgis-arcade-editor arcgis-arcade-results{border-top:1px solid var(--calcite-color-border-3);box-sizing:border-box;max-height:50%;min-height:50%;margin-bottom:-1px}arcgis-arcade-editor calcite-flow [slot=footer]{word-break:break-word}arcgis-arcade-editor calcite-list-item-group calcite-list-item{margin-bottom:1px;box-shadow:0 1px 0 var(--calcite-color-border-3)}arcgis-arcade-editor calcite-list-item-group calcite-list-item:last-child{box-shadow:none}arcgis-arcade-editor calcite-list-item-group:last-child{margin-bottom:var(--calcite-spacing-xl)}";
|
|
3446
4915
|
|
|
3447
|
-
function setupArcadeTheme() {
|
|
3448
|
-
["light", "dark"].forEach((theme) => {
|
|
3449
|
-
const base = theme === "light" ? "vs" : "vs-dark";
|
|
3450
|
-
const colors = themeConfig[`arcade-${theme}-theme`];
|
|
3451
|
-
// Defines the light and dark theme based on the calcite theme name
|
|
3452
|
-
editor.defineTheme(base, {
|
|
3453
|
-
base,
|
|
3454
|
-
inherit: true,
|
|
3455
|
-
rules: [
|
|
3456
|
-
{ token: "comment.arc", foreground: colors.comment },
|
|
3457
|
-
{ token: "constant.arc", foreground: colors.constant },
|
|
3458
|
-
{ token: "keyword.arc", foreground: colors.keyword },
|
|
3459
|
-
{ token: "identifier.arc", foreground: colors.identifier },
|
|
3460
|
-
{ token: "number.arc", foreground: colors.number },
|
|
3461
|
-
{ token: "string.arc", foreground: colors.string }
|
|
3462
|
-
],
|
|
3463
|
-
colors: {}
|
|
3464
|
-
});
|
|
3465
|
-
});
|
|
3466
|
-
}
|
|
3467
|
-
const monacoThemeKeys = ["comment", "keyword", "identifier", "string", "number", "constant"];
|
|
3468
|
-
const colorRulesKeys = [...monacoThemeKeys, "date"];
|
|
3469
|
-
function updateThemeColors(theme, colorRules) {
|
|
3470
|
-
if (colorRules === undefined) {
|
|
3471
|
-
setupArcadeTheme();
|
|
3472
|
-
return;
|
|
3473
|
-
}
|
|
3474
|
-
const base = theme === "light" ? "vs" : "vs-dark";
|
|
3475
|
-
const rules = [];
|
|
3476
|
-
monacoThemeKeys.forEach((key) => {
|
|
3477
|
-
const foreground = colorRules[key];
|
|
3478
|
-
if (!foreground) {
|
|
3479
|
-
return;
|
|
3480
|
-
}
|
|
3481
|
-
rules.push({ token: `${key}.arc`, foreground });
|
|
3482
|
-
});
|
|
3483
|
-
editor.defineTheme(base, { base, inherit: true, rules, colors: {} });
|
|
3484
|
-
}
|
|
3485
|
-
|
|
3486
|
-
const arcadeEditorCss = "arcgis-arcade-editor{display:flex;flex-direction:column;height:100%;width:100%;position:relative;overflow:hidden;border:1px solid var(--calcite-color-border-3);box-sizing:border-box;background-color:var(--calcite-color-foreground-1)}arcgis-arcade-editor .flex-adjustable{flex:1 1 auto;overflow:hidden}arcgis-arcade-editor .flex-panel{flex:1 0 auto}arcgis-arcade-editor .position-relative{position:relative}arcgis-arcade-editor .flex-row{display:flex;flex-direction:row;overflow:hidden}arcgis-arcade-editor .flex-column{display:flex;flex-direction:column;overflow:hidden}arcgis-arcade-editor .border-inline-start{border-inline-start:1px solid var(--calcite-color-border-3);box-sizing:border-box}arcgis-arcade-editor .border-inline-end{border-inline-end:1px solid var(--calcite-color-border-3);box-sizing:border-box}arcgis-arcade-editor .sticky{position:sticky;top:0px;z-index:10}arcgis-arcade-editor .notice-container{margin:var(--calcite-spacing-quarter);padding:var(--calcite-spacing-half);background-color:var(--calcite-color-foreground-1);text-align:center}arcgis-arcade-editor .side-action-bar{max-width:25%}arcgis-arcade-editor .side-panel{max-width:45%;width:600px}arcgis-arcade-editor .side-panel calcite-flow{height:100%}arcgis-arcade-editor .main-action-bar{border-bottom:1px solid var(--calcite-color-border-3);flex:0 0 auto}arcgis-arcade-editor .main-action-bar calcite-action-group{padding-inline-end:var(--calcite-spacing-half)}arcgis-arcade-editor .main-action-bar calcite-action-group calcite-action{padding-inline-end:var(--calcite-spacing-half)}arcgis-arcade-editor .main-action-bar calcite-action-group calcite-action:not(:first-child){padding-inline-start:var(--calcite-spacing-half)}arcgis-arcade-editor .main-action-bar calcite-action-group:last-child{border-inline-end-width:0px}arcgis-arcade-editor .main-action-bar calcite-action-group:not(:first-child){padding-inline-start:var(--calcite-spacing-half)}arcgis-arcade-editor arcgis-arcade-results{border-top:1px solid var(--calcite-color-border-3);box-sizing:border-box;max-height:50%;min-height:50%;margin-bottom:-1px}arcgis-arcade-editor calcite-flow [slot=footer]{word-break:break-word}arcgis-arcade-editor calcite-list-item-group calcite-list-item{margin-bottom:1px;box-shadow:0 1px 0 var(--calcite-color-border-3)}arcgis-arcade-editor calcite-list-item-group calcite-list-item:last-child{box-shadow:none}arcgis-arcade-editor calcite-list-item-group:last-child{margin-bottom:var(--calcite-spacing-1)}";
|
|
3487
|
-
|
|
3488
|
-
setupArcadeTheme();
|
|
3489
4916
|
const ArcgisArcadeEditor = class {
|
|
3490
4917
|
constructor(hostRef) {
|
|
3491
4918
|
registerInstance(this, hostRef);
|
|
3492
|
-
this.
|
|
3493
|
-
this.
|
|
3494
|
-
this.
|
|
3495
|
-
this.
|
|
4919
|
+
this.arcgisScriptChange = createEvent(this, "arcgisScriptChange", 3);
|
|
4920
|
+
this.arcgisDiagnosticsChange = createEvent(this, "arcgisDiagnosticsChange", 3);
|
|
4921
|
+
this.manager = useControllerManager(this);
|
|
4922
|
+
this._componentReadyDefer = new Deferred$1();
|
|
4923
|
+
this._modelId = generateGuid();
|
|
3496
4924
|
this._editorProfilePromise = Promise.resolve(undefined);
|
|
3497
4925
|
this._disposables = [];
|
|
3498
4926
|
this._executeScript = async () => {
|
|
@@ -3533,17 +4961,16 @@ const ArcgisArcadeEditor = class {
|
|
|
3533
4961
|
}
|
|
3534
4962
|
};
|
|
3535
4963
|
this._openArcadeHelp = () => void window.open(DevelopersWebSitePath, "Arcade Help");
|
|
3536
|
-
this.
|
|
4964
|
+
this._onCodeEditorValueChange = (e) => {
|
|
3537
4965
|
e.stopPropagation();
|
|
3538
|
-
this.
|
|
4966
|
+
this.script = e.detail;
|
|
4967
|
+
this.arcgisScriptChange.emit(e.detail);
|
|
3539
4968
|
};
|
|
3540
4969
|
this._insertAsSnippet = (e) => void this._codeEditorElt?.insertSnippet(e.detail).catch(console.error);
|
|
3541
4970
|
this._insertAsText = (e) => void this._codeEditorElt?.insertText(e.detail).catch(console.error);
|
|
3542
4971
|
this._onResultPanelChange = (e) => void (this._resultPanel = e.detail);
|
|
3543
4972
|
this._onExecutionPanelClose = () => void (this._showExecutionPanel = false);
|
|
3544
|
-
this.
|
|
3545
|
-
this._t9nLocale = "";
|
|
3546
|
-
this._t9nStrings = undefined;
|
|
4973
|
+
this.messages = useT9n();
|
|
3547
4974
|
this._standaloneCodeEditor = undefined;
|
|
3548
4975
|
this._preparingProfile = false;
|
|
3549
4976
|
this._editorProfile = undefined;
|
|
@@ -3562,6 +4989,10 @@ const ArcgisArcadeEditor = class {
|
|
|
3562
4989
|
this.sideActionBarExpanded = false;
|
|
3563
4990
|
this.openedSidePanel = "none";
|
|
3564
4991
|
this.editorOptions = undefined;
|
|
4992
|
+
this.editorInstance = this.manager.getSet(undefined, {
|
|
4993
|
+
get: () => this._codeEditorElt?.editorInstance,
|
|
4994
|
+
set: (_value, prevValue) => prevValue,
|
|
4995
|
+
});
|
|
3565
4996
|
}
|
|
3566
4997
|
_profileChanged() {
|
|
3567
4998
|
this._updateEditorProfile().catch(console.error);
|
|
@@ -3574,18 +5005,17 @@ const ArcgisArcadeEditor = class {
|
|
|
3574
5005
|
}
|
|
3575
5006
|
_snippetChanged() {
|
|
3576
5007
|
arcadeDefaults.updateApiContextForModel(this._modelId, {
|
|
3577
|
-
snippets: this.snippets
|
|
5008
|
+
snippets: this.snippets,
|
|
3578
5009
|
});
|
|
3579
5010
|
}
|
|
3580
5011
|
// #endregion
|
|
3581
5012
|
// #region Public methods API
|
|
3582
5013
|
/**
|
|
3583
|
-
*
|
|
3584
|
-
* @returns {Promise<string>}
|
|
5014
|
+
* @deprecated Use `script` property instead.
|
|
3585
5015
|
*/
|
|
3586
5016
|
async getScript() {
|
|
3587
5017
|
await this._componentReadyDefer.promise;
|
|
3588
|
-
return
|
|
5018
|
+
return this._codeEditorElt?.value;
|
|
3589
5019
|
}
|
|
3590
5020
|
/**
|
|
3591
5021
|
* Set the focus on the element.
|
|
@@ -3596,12 +5026,11 @@ const ArcgisArcadeEditor = class {
|
|
|
3596
5026
|
}
|
|
3597
5027
|
/**
|
|
3598
5028
|
* @internal
|
|
3599
|
-
*
|
|
3600
|
-
* @returns {Promise<IStandaloneCodeEditor>} - The monaco editor instance
|
|
5029
|
+
* @deprecated Use `editorInstance` property instead.
|
|
3601
5030
|
*/
|
|
3602
5031
|
async getEditorInstance() {
|
|
3603
5032
|
await this._componentReadyDefer.promise;
|
|
3604
|
-
return
|
|
5033
|
+
return this._codeEditorElt?.editorInstance;
|
|
3605
5034
|
}
|
|
3606
5035
|
/**
|
|
3607
5036
|
* Returns the Arcade result for the script for the provided test data.
|
|
@@ -3623,11 +5052,11 @@ const ArcgisArcadeEditor = class {
|
|
|
3623
5052
|
* @internal
|
|
3624
5053
|
*/
|
|
3625
5054
|
async updateThemeColors(colorRules) {
|
|
3626
|
-
const theme =
|
|
5055
|
+
const theme = getElementTheme(this.el);
|
|
3627
5056
|
updateThemeColors(theme, colorRules);
|
|
3628
5057
|
if (colorRules === undefined) {
|
|
3629
5058
|
colorRulesKeys.forEach((key) => {
|
|
3630
|
-
this.
|
|
5059
|
+
this.el.style.removeProperty(`--arcgis-arcade-editor-${key}`);
|
|
3631
5060
|
});
|
|
3632
5061
|
return;
|
|
3633
5062
|
}
|
|
@@ -3636,7 +5065,7 @@ const ArcgisArcadeEditor = class {
|
|
|
3636
5065
|
if (!foreground) {
|
|
3637
5066
|
return;
|
|
3638
5067
|
}
|
|
3639
|
-
this.
|
|
5068
|
+
this.el.style.setProperty(`--arcgis-arcade-editor-${key}`, foreground);
|
|
3640
5069
|
});
|
|
3641
5070
|
}
|
|
3642
5071
|
// #endregion
|
|
@@ -3644,14 +5073,13 @@ const ArcgisArcadeEditor = class {
|
|
|
3644
5073
|
async componentWillLoad() {
|
|
3645
5074
|
const assetsPath = getAssetPath("./assets");
|
|
3646
5075
|
// We are a bit in a chicken and egg situation here.
|
|
3647
|
-
// Normally, it is the code editor that is responsible for setting up the Monaco
|
|
5076
|
+
// Normally, it is the code editor that is responsible for setting up the Monaco environment.
|
|
3648
5077
|
// However, we need to setup the environment before the code editor is instantiated because
|
|
3649
5078
|
// we need to access the arcade language service to get the api library.
|
|
3650
5079
|
setupMonacoEnvironment(assetsPath);
|
|
3651
|
-
|
|
3652
|
-
//
|
|
3653
|
-
|
|
3654
|
-
await B(this, assetsPath, async () => await this._updateEditorProfile());
|
|
5080
|
+
await this._updateEditorProfile();
|
|
5081
|
+
// The profile has to be refreshed on locale change
|
|
5082
|
+
this.manager.watch("messages", () => void this._updateEditorProfile().catch(console.error));
|
|
3655
5083
|
}
|
|
3656
5084
|
async componentDidLoad() {
|
|
3657
5085
|
// Mark on component as ready.
|
|
@@ -3660,7 +5088,7 @@ const ArcgisArcadeEditor = class {
|
|
|
3660
5088
|
// Start listening to the validation diagnostics.
|
|
3661
5089
|
// We are doing this as late as possible
|
|
3662
5090
|
const diagnosticsService = await getArcadeDiagnosticService();
|
|
3663
|
-
this._disposables.push(diagnosticsService.onDiagnosticsChange((event) => !this._preparingProfile && this.
|
|
5091
|
+
this._disposables.push(diagnosticsService.onDiagnosticsChange((event) => !this._preparingProfile && this.arcgisDiagnosticsChange.emit(event.diagnostics)));
|
|
3664
5092
|
// Get editor instance and add action
|
|
3665
5093
|
this._standaloneCodeEditor = await this.getEditorInstance();
|
|
3666
5094
|
this._standaloneCodeEditor?.addAction({
|
|
@@ -3674,12 +5102,11 @@ const ArcgisArcadeEditor = class {
|
|
|
3674
5102
|
if (this.testData) {
|
|
3675
5103
|
this._executeScript().catch(console.error);
|
|
3676
5104
|
}
|
|
3677
|
-
}
|
|
5105
|
+
},
|
|
3678
5106
|
});
|
|
3679
5107
|
await this._codeEditorElt?.setFocus();
|
|
3680
5108
|
}
|
|
3681
5109
|
disconnectedCallback() {
|
|
3682
|
-
q(this);
|
|
3683
5110
|
arcadeDefaults.disposeApiContextForModel(this._modelId);
|
|
3684
5111
|
arcadeDefaults.disposeEditorProfileForModel(this._modelId);
|
|
3685
5112
|
while (this._disposables.length) {
|
|
@@ -3696,8 +5123,8 @@ const ArcgisArcadeEditor = class {
|
|
|
3696
5123
|
try {
|
|
3697
5124
|
// Set a new profile for the model using the profile definition and the locale.
|
|
3698
5125
|
await arcadeDefaults.setProfileForModel(this._modelId, this.profile, {
|
|
3699
|
-
locale: this._t9nLocale,
|
|
3700
|
-
snippets: this.snippets
|
|
5126
|
+
locale: this.messages._t9nLocale,
|
|
5127
|
+
snippets: this.snippets,
|
|
3701
5128
|
});
|
|
3702
5129
|
// Get the corresponding editor profile for the model.
|
|
3703
5130
|
// The editor profile contains the specialized profile for the UI.
|
|
@@ -3717,16 +5144,16 @@ const ArcgisArcadeEditor = class {
|
|
|
3717
5144
|
if (!this.testData) {
|
|
3718
5145
|
return null;
|
|
3719
5146
|
}
|
|
3720
|
-
return (h("calcite-action-bar", { class: "main-action-bar", layout: "horizontal", scale: "s", expanded: true, "expand-disabled": true }, h("calcite-action-group", { scale: "s" }, h("calcite-action", { text: this.
|
|
5147
|
+
return (h("calcite-action-bar", { class: "main-action-bar", layout: "horizontal", scale: "s", expanded: true, "expand-disabled": true }, h("calcite-action-group", { scale: "s" }, h("calcite-action", { text: this.messages.run ?? "Run", "text-enabled": true, icon: "play", scale: "s", loading: this._preparingProfile, onClick: this._executeScript }), this._executionResult ? (h("calcite-action", { text: this.messages.lastresults ?? "Last results", active: this._showExecutionPanel, "text-enabled": true, icon: "access-string-results", iconFlipRtl: true, scale: "s", onClick: this._toggleShowExecutionPanel })) : null)));
|
|
3721
5148
|
}
|
|
3722
5149
|
//#endregion
|
|
3723
5150
|
//#region Render Main Panel
|
|
3724
5151
|
renderMainPanel() {
|
|
3725
|
-
return (h("arcgis-code-editor", { class: "flex-adjustable", language: arcadeDefaults.languageId, value: this.script ?? "", modelId: this._modelId, options: this.editorOptions,
|
|
5152
|
+
return (h("arcgis-code-editor", { class: "flex-adjustable", language: arcadeDefaults.languageId, value: this.script ?? "", modelId: this._modelId, options: this.editorOptions, onArcgisValueChange: this._onCodeEditorValueChange, ref: (e) => (this._codeEditorElt = e) }));
|
|
3726
5153
|
}
|
|
3727
5154
|
//#endregion
|
|
3728
5155
|
//#region Rendering the Action Bar
|
|
3729
|
-
renderAction({ id, label, icon, active, panelName, onClick = this._toggleSidePanel }) {
|
|
5156
|
+
renderAction({ id, label, icon, active, panelName, onClick = this._toggleSidePanel, }) {
|
|
3730
5157
|
return (h(Fragment, null, h("calcite-action", { id: id, text: label, icon: icon, active: active, onClick: onClick, "data-panel-name": panelName }), !this.sideActionBarExpanded && (h("calcite-tooltip", { label: label, "reference-element": id }, h("span", null, label)))));
|
|
3731
5158
|
}
|
|
3732
5159
|
renderSideActionBar() {
|
|
@@ -3735,33 +5162,33 @@ const ArcgisArcadeEditor = class {
|
|
|
3735
5162
|
}
|
|
3736
5163
|
return (h("calcite-action-bar", { class: "side-action-bar border-inline-start", expanded: !!this.sideActionBarExpanded, position: "end", onCalciteActionBarToggle: this._toggleSideActionBarExpanded }, h("calcite-action-group", null, this.renderAction({
|
|
3737
5164
|
id: "profile-variables-action",
|
|
3738
|
-
label: this.
|
|
5165
|
+
label: this.messages.profilevariables ?? "Profile variables",
|
|
3739
5166
|
icon: "profile-variables",
|
|
3740
5167
|
active: this.openedSidePanel === "variables",
|
|
3741
|
-
panelName: "variables"
|
|
5168
|
+
panelName: "variables",
|
|
3742
5169
|
}), this.renderAction({
|
|
3743
5170
|
id: "function-action",
|
|
3744
|
-
label: this.
|
|
5171
|
+
label: this.messages.constantsandfunctions ?? "Constants and functions",
|
|
3745
5172
|
icon: "function",
|
|
3746
5173
|
active: this.openedSidePanel === "api",
|
|
3747
|
-
panelName: "api"
|
|
5174
|
+
panelName: "api",
|
|
3748
5175
|
}), this.suggestions?.length
|
|
3749
5176
|
? this.renderAction({
|
|
3750
5177
|
id: "suggestions-action",
|
|
3751
|
-
label: this.
|
|
5178
|
+
label: this.messages.suggestions ?? "Suggestions",
|
|
3752
5179
|
icon: "lightbulb",
|
|
3753
5180
|
active: this.openedSidePanel === "suggestions",
|
|
3754
|
-
panelName: "suggestions"
|
|
5181
|
+
panelName: "suggestions",
|
|
3755
5182
|
})
|
|
3756
5183
|
: null, this.hideDocumentationActions
|
|
3757
5184
|
? null
|
|
3758
5185
|
: this.renderAction({
|
|
3759
5186
|
id: "developer-website-action",
|
|
3760
|
-
label: this.
|
|
5187
|
+
label: this.messages.help ?? "Help",
|
|
3761
5188
|
icon: "question",
|
|
3762
5189
|
active: false,
|
|
3763
5190
|
panelName: "none",
|
|
3764
|
-
onClick: this._openArcadeHelp
|
|
5191
|
+
onClick: this._openArcadeHelp,
|
|
3765
5192
|
}))));
|
|
3766
5193
|
}
|
|
3767
5194
|
//#endregion
|
|
@@ -3772,11 +5199,11 @@ const ArcgisArcadeEditor = class {
|
|
|
3772
5199
|
}
|
|
3773
5200
|
switch (this.openedSidePanel) {
|
|
3774
5201
|
case "api":
|
|
3775
|
-
return (h("arcgis-arcade-api", { class: "side-panel flex-panel border-inline-start", modelId: this._modelId, hideDocumentationActions: this.hideDocumentationActions,
|
|
5202
|
+
return (h("arcgis-arcade-api", { class: "side-panel flex-panel border-inline-start", modelId: this._modelId, hideDocumentationActions: this.hideDocumentationActions, onArcgisItemSelected: this._insertAsSnippet, onArcgisClose: this._toggleSidePanel, "data-panel-name": "none" }));
|
|
3776
5203
|
case "variables":
|
|
3777
|
-
return (h("arcgis-arcade-variables", { class: "side-panel flex-panel border-inline-start", loading: this._preparingProfile, modelId: this._modelId,
|
|
5204
|
+
return (h("arcgis-arcade-variables", { class: "side-panel flex-panel border-inline-start", loading: this._preparingProfile, modelId: this._modelId, onArcgisItemSelected: this._insertAsText, onArcgisClose: this._toggleSidePanel, "data-panel-name": "none" }));
|
|
3778
5205
|
case "suggestions":
|
|
3779
|
-
return (h("arcgis-arcade-suggestions", { class: "side-panel flex-panel border-inline-start", suggestions: this.suggestions,
|
|
5206
|
+
return (h("arcgis-arcade-suggestions", { class: "side-panel flex-panel border-inline-start", suggestions: this.suggestions, onArcgisItemSelected: this._insertAsText, onArcgisClose: this._toggleSidePanel, "data-panel-name": "none" }));
|
|
3780
5207
|
default:
|
|
3781
5208
|
return null;
|
|
3782
5209
|
}
|
|
@@ -3787,7 +5214,7 @@ const ArcgisArcadeEditor = class {
|
|
|
3787
5214
|
if (!this._showExecutionPanel) {
|
|
3788
5215
|
return null;
|
|
3789
5216
|
}
|
|
3790
|
-
return (h("arcgis-arcade-results", { class: "flex-adjustable", openedResultPanel: this._resultPanel, loading: this._executingScript, result: this._executionResult, consoleLogs: this._consoleLogs,
|
|
5217
|
+
return (h("arcgis-arcade-results", { class: "flex-adjustable", openedResultPanel: this._resultPanel, loading: this._executingScript, result: this._executionResult, consoleLogs: this._consoleLogs, onArcgisOpenedResultPanelChange: this._onResultPanelChange, onArcgisClose: this._onExecutionPanelClose }));
|
|
3791
5218
|
}
|
|
3792
5219
|
//#endregion
|
|
3793
5220
|
//#region Render
|
|
@@ -3795,7 +5222,7 @@ const ArcgisArcadeEditor = class {
|
|
|
3795
5222
|
return (h(Host, null, this.renderMainActionBar(), h("div", { class: "flex-row flex-adjustable" }, h("div", { class: "flex-column flex-adjustable" }, this.renderMainPanel(), this.renderResultsPanel()), this.renderSidePanel(), this.renderSideActionBar())));
|
|
3796
5223
|
}
|
|
3797
5224
|
static get assetsDirs() { return ["assets"]; }
|
|
3798
|
-
get
|
|
5225
|
+
get el() { return getElement(this); }
|
|
3799
5226
|
static get watchers() { return {
|
|
3800
5227
|
"profile": ["_profileChanged"],
|
|
3801
5228
|
"testData": ["_testDataChanged"],
|
|
@@ -3804,20 +5231,20 @@ const ArcgisArcadeEditor = class {
|
|
|
3804
5231
|
};
|
|
3805
5232
|
ArcgisArcadeEditor.style = arcadeEditorCss;
|
|
3806
5233
|
|
|
3807
|
-
const arcadeResultsCss = ":host{display:flex;flex-direction:column;width:100%;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-2)}:host .flex-adjustable{flex:1 1 auto;overflow:hidden}:host .flex-row{display:flex;flex-direction:row;overflow:hidden}:host .flex-column{display:flex;flex-direction:column;overflow:hidden}:host .y-scrollable-container{overflow-y:auto;block-size:100%;background-color:var(--calcite-color-foreground-1)}:host header{border-bottom:1px solid var(--calcite-color-border-3);flex:0 0 auto}:host .ltr-container{direction:ltr}:host calcite-action-bar calcite-action-group{padding-inline-end:var(--calcite-spacing-
|
|
5234
|
+
const arcadeResultsCss = ":host{display:flex;flex-direction:column;width:100%;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-2)}:host .flex-adjustable{flex:1 1 auto;overflow:hidden}:host .flex-row{display:flex;flex-direction:row;overflow:hidden}:host .flex-column{display:flex;flex-direction:column;overflow:hidden}:host .y-scrollable-container{overflow-y:auto;block-size:100%;background-color:var(--calcite-color-foreground-1)}:host header{border-bottom:1px solid var(--calcite-color-border-3);flex:0 0 auto}:host .ltr-container{direction:ltr}:host calcite-action-bar calcite-action-group{padding-inline-end:var(--calcite-spacing-sm)}:host calcite-action-bar calcite-action-group calcite-action{padding-inline-end:var(--calcite-spacing-sm)}:host calcite-action-bar calcite-action-group calcite-action:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}:host calcite-action-bar calcite-action-group:last-child{border-inline-end-width:0px}:host calcite-action-bar calcite-action-group:not(:first-child){padding-inline-start:var(--calcite-spacing-sm)}:host .notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}:host .color-info{color:var(--calcite-color-status-info)}:host .color-error{color:var(--calcite-color-status-danger)}:host .color-success{color:var(--calcite-color-status-success)}:host [class*=result-value-]{font-size:var(--calcite-font-size--2);line-height:1.25rem;background-color:var(--calcite-color-foreground-1);margin:var(--calcite-spacing-md)}:host .console-logs-container{background-color:var(--calcite-color-foreground-1);padding:0 var(--calcite-spacing-md);font-family:var(--calcite-code-family);font-size:var(--calcite-font-size--2);font-weight:var(--calcite-font-weight-normal)}:host .result-value-table table{display:block;max-width:fit-content;overflow-x:auto;border-spacing:0;border-collapse:collapse;text-align:start;white-space:nowrap}:host .result-value-table table thead{background-color:var(--calcite-color-foreground-2)}:host .result-value-table table tr{border-top:1px solid var(--calcite-color-border-3);border-bottom:1px solid var(--calcite-color-border-3)}:host .result-value-table table th,:host .result-value-table table td{border-inline-start:1px solid var(--calcite-color-border-3);border-inline-end:1px solid var(--calcite-color-border-3);text-align:start;padding:var(--calcite-spacing-xxs)}:host .result-value-table table th .string-value,:host .result-value-table table td .string-value{white-space:pre}:host .result-value-table table th{font-weight:var(--calcite-font-weight-medium)}:host .tree-item-label,:host .number-value,:host .string-value,:host .boolean-value{font-family:var(--calcite-code-family)}:host .tree-item-label,:host .value-type{color:var(--calcite-color-text-2);font-weight:var(--calcite-font-weight-normal)}:host .dictionary-property{color:var(--arcgis-arcade-editor-identifier)}:host .number-value{color:var(--arcgis-arcade-editor-number)}:host .string-value{color:var(--arcgis-arcade-editor-string);white-space:pre-wrap}:host .constant-value{color:var(--arcgis-arcade-editor-constant)}:host .date-value{color:var(--arcgis-arcade-editor-date)}";
|
|
3808
5235
|
|
|
3809
5236
|
//#region Specialized Constants
|
|
3810
5237
|
const treeProps = {
|
|
3811
5238
|
lines: true,
|
|
3812
5239
|
selectionMode: "none",
|
|
3813
5240
|
scale: "s",
|
|
3814
|
-
onCalciteTreeSelect: (e) => e.target.selectedItems.forEach((itemElt) => (itemElt.selected = false))
|
|
5241
|
+
onCalciteTreeSelect: (e) => e.target.selectedItems.forEach((itemElt) => (itemElt.selected = false)),
|
|
3815
5242
|
};
|
|
3816
5243
|
const expandableTreeItemProps = {
|
|
3817
5244
|
onClick: (e) => {
|
|
3818
5245
|
const item = e.currentTarget;
|
|
3819
5246
|
item.expanded = !item.expanded;
|
|
3820
|
-
}
|
|
5247
|
+
},
|
|
3821
5248
|
};
|
|
3822
5249
|
//#endregion
|
|
3823
5250
|
//#region Helper Functions
|
|
@@ -3836,7 +5263,7 @@ function renderSimpleValue(arcadeResult) {
|
|
|
3836
5263
|
case "null":
|
|
3837
5264
|
return h("span", { class: "constant-value" }, arcadeResult.type);
|
|
3838
5265
|
case "text":
|
|
3839
|
-
return h("span", { class: "string-value" },
|
|
5266
|
+
return h("span", { class: "string-value" }, quoteString(arcadeResult.value));
|
|
3840
5267
|
case "number":
|
|
3841
5268
|
return h("span", { class: "number-value" }, arcadeResult.value.toString());
|
|
3842
5269
|
case "boolean":
|
|
@@ -3844,9 +5271,9 @@ function renderSimpleValue(arcadeResult) {
|
|
|
3844
5271
|
case "date":
|
|
3845
5272
|
return h("span", { class: "date-value" }, formatArcadeResultDate(arcadeResult));
|
|
3846
5273
|
case "dateOnly":
|
|
3847
|
-
return h("span", { class: "string-value" },
|
|
5274
|
+
return h("span", { class: "string-value" }, quoteString(formatArcadeResultDateOnly(arcadeResult)));
|
|
3848
5275
|
case "time":
|
|
3849
|
-
return h("span", { class: "string-value" },
|
|
5276
|
+
return h("span", { class: "string-value" }, quoteString(formatArcadeResultTimeOnly(arcadeResult)));
|
|
3850
5277
|
default:
|
|
3851
5278
|
return null;
|
|
3852
5279
|
}
|
|
@@ -3866,8 +5293,11 @@ function renderFeatureSetTable(arcadeResult) {
|
|
|
3866
5293
|
const ArcgisArcadeResults = class {
|
|
3867
5294
|
constructor(hostRef) {
|
|
3868
5295
|
registerInstance(this, hostRef);
|
|
3869
|
-
this.
|
|
3870
|
-
this.
|
|
5296
|
+
this.arcgisOpenedResultPanelChange = createEvent(this, "arcgisOpenedResultPanelChange", 3);
|
|
5297
|
+
this.arcgisClose = createEvent(this, "arcgisClose", 3);
|
|
5298
|
+
this.manager = useControllerManager(this);
|
|
5299
|
+
//#region Private Properties
|
|
5300
|
+
this.messages = useT9n();
|
|
3871
5301
|
this._switchResultPanel = (e) => {
|
|
3872
5302
|
if (!e.target) {
|
|
3873
5303
|
return;
|
|
@@ -3878,28 +5308,17 @@ const ArcgisArcadeResults = class {
|
|
|
3878
5308
|
}
|
|
3879
5309
|
this.updateResultPanel(panelName);
|
|
3880
5310
|
};
|
|
3881
|
-
this._emitClose = () => this.
|
|
3882
|
-
this._lang = "";
|
|
3883
|
-
this._t9nLocale = "";
|
|
3884
|
-
this._t9nStrings = undefined;
|
|
5311
|
+
this._emitClose = () => this.arcgisClose.emit();
|
|
3885
5312
|
this.loading = true;
|
|
3886
5313
|
this.openedResultPanel = "output";
|
|
3887
5314
|
this.result = undefined;
|
|
3888
5315
|
this.consoleLogs = undefined;
|
|
3889
5316
|
}
|
|
3890
5317
|
//#endregion
|
|
3891
|
-
// #region Component lifecycle events
|
|
3892
|
-
async componentWillLoad() {
|
|
3893
|
-
await B(this, getAssetPath("./assets"));
|
|
3894
|
-
}
|
|
3895
|
-
disconnectedCallback() {
|
|
3896
|
-
q(this);
|
|
3897
|
-
}
|
|
3898
|
-
// #endregion
|
|
3899
5318
|
//#region Private Methods
|
|
3900
5319
|
updateResultPanel(resultPanelType) {
|
|
3901
5320
|
this.openedResultPanel = resultPanelType;
|
|
3902
|
-
this.
|
|
5321
|
+
this.arcgisOpenedResultPanelChange.emit(resultPanelType);
|
|
3903
5322
|
}
|
|
3904
5323
|
//#endregion
|
|
3905
5324
|
//#region Rendering
|
|
@@ -3910,7 +5329,7 @@ const ArcgisArcadeResults = class {
|
|
|
3910
5329
|
if (this.loading && !this.consoleLogs?.length) {
|
|
3911
5330
|
return h("calcite-loader", { scale: "s", type: "indeterminate", label: "" });
|
|
3912
5331
|
}
|
|
3913
|
-
return (h("div", { class: "console-logs-container ltr-container" }, this.consoleLogs?.length ?
|
|
5332
|
+
return (h("div", { class: "console-logs-container ltr-container" }, this.consoleLogs?.length ? this.consoleLogs.map((log) => h("p", null, log)) : h("p", null, this.messages.consolemessage)));
|
|
3914
5333
|
}
|
|
3915
5334
|
renderLogPanel() {
|
|
3916
5335
|
if (this.openedResultPanel !== "log") {
|
|
@@ -3920,24 +5339,24 @@ const ArcgisArcadeResults = class {
|
|
|
3920
5339
|
return h("calcite-loader", { scale: "s", type: "indeterminate", label: "" });
|
|
3921
5340
|
}
|
|
3922
5341
|
const iconClass = this.result?.type === "error" ? "color-error" : "color-success";
|
|
3923
|
-
return (h("calcite-list", null, this.result ? (h(Fragment, null, h("calcite-list-item", { label:
|
|
3924
|
-
timeStamp: new Intl.DateTimeFormat(this._t9nLocale, {
|
|
5342
|
+
return (h("calcite-list", null, this.result ? (h(Fragment, null, h("calcite-list-item", { label: setValuesInString(this.messages.lastexecutionformat, {
|
|
5343
|
+
timeStamp: new Intl.DateTimeFormat(this.messages._t9nLocale, {
|
|
3925
5344
|
dateStyle: "medium",
|
|
3926
|
-
timeStyle: "medium"
|
|
3927
|
-
}).format(this.result.timeStamp)
|
|
3928
|
-
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })), h("calcite-list-item", { label:
|
|
3929
|
-
time: new Intl.NumberFormat(this._t9nLocale, {
|
|
5345
|
+
timeStyle: "medium",
|
|
5346
|
+
}).format(this.result.timeStamp),
|
|
5347
|
+
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })), h("calcite-list-item", { label: setValuesInString(this.messages.compilationtimeformat, {
|
|
5348
|
+
time: new Intl.NumberFormat(this.messages._t9nLocale, {
|
|
3930
5349
|
style: "unit",
|
|
3931
5350
|
unit: "millisecond",
|
|
3932
|
-
maximumFractionDigits: 2
|
|
3933
|
-
}).format(this.result.compilationTime ?? 0)
|
|
3934
|
-
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })), h("calcite-list-item", { label:
|
|
3935
|
-
time: new Intl.NumberFormat(this._t9nLocale, {
|
|
5351
|
+
maximumFractionDigits: 2,
|
|
5352
|
+
}).format(this.result.compilationTime ?? 0),
|
|
5353
|
+
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })), h("calcite-list-item", { label: setValuesInString(this.messages.executiontimeformat, {
|
|
5354
|
+
time: new Intl.NumberFormat(this.messages._t9nLocale, {
|
|
3936
5355
|
style: "unit",
|
|
3937
5356
|
unit: "millisecond",
|
|
3938
|
-
maximumFractionDigits: 2
|
|
3939
|
-
}).format(this.result.executionTime ?? 0)
|
|
3940
|
-
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })))) : (h("calcite-list-item", { label: this.
|
|
5357
|
+
maximumFractionDigits: 2,
|
|
5358
|
+
}).format(this.result.executionTime ?? 0),
|
|
5359
|
+
}) }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: iconClass })))) : (h("calcite-list-item", { label: this.messages.runscriptmessage ?? "No output, run the script once." }, h("calcite-icon", { slot: "content-start", icon: "information", scale: "s", class: "color-info" })))));
|
|
3941
5360
|
}
|
|
3942
5361
|
renderOutputPanel() {
|
|
3943
5362
|
if (this.openedResultPanel !== "output") {
|
|
@@ -3948,8 +5367,8 @@ const ArcgisArcadeResults = class {
|
|
|
3948
5367
|
}
|
|
3949
5368
|
switch (this.result?.type) {
|
|
3950
5369
|
case "error":
|
|
3951
|
-
return (h("div", { class: "result-value-simple flex-adjustable" },
|
|
3952
|
-
message: this.result.value
|
|
5370
|
+
return (h("div", { class: "result-value-simple flex-adjustable" }, setValuesInString(this.messages.executionerrorformat, {
|
|
5371
|
+
message: this.result.value,
|
|
3953
5372
|
})));
|
|
3954
5373
|
case "null":
|
|
3955
5374
|
case "unknown":
|
|
@@ -3979,14 +5398,14 @@ const ArcgisArcadeResults = class {
|
|
|
3979
5398
|
case "knowledgeGraph":
|
|
3980
5399
|
return (h("div", { class: "result-value-simple ltr-container" }, h("span", { class: "value-type" }, this.result.type, ":\u00A0"), h("span", { class: "string-value" }, this.result.value.url)));
|
|
3981
5400
|
default:
|
|
3982
|
-
return
|
|
5401
|
+
return h("div", { class: "result-value-simple flex-adjustable ltr-container" }, this.messages.runscriptmessage);
|
|
3983
5402
|
}
|
|
3984
5403
|
}
|
|
3985
5404
|
renderArrayHeader(arcadeResult) {
|
|
3986
5405
|
const items = arcadeResult.value ?? [];
|
|
3987
5406
|
const leftoverCount = Math.max(items.length - MaxArrayItems, 0);
|
|
3988
|
-
return (h(Fragment, null, h("span", null, `${arcadeResult.type}(${items.length ?? 0})`), leftoverCount > 0 ? (h("span", null, "\u00A0",
|
|
3989
|
-
count: MaxArrayItems.toString()
|
|
5407
|
+
return (h(Fragment, null, h("span", null, `${arcadeResult.type}(${items.length ?? 0})`), leftoverCount > 0 ? (h("span", null, "\u00A0", setValuesInString(this.messages.showingfirstitemsformat, {
|
|
5408
|
+
count: MaxArrayItems.toString(),
|
|
3990
5409
|
}))) : null));
|
|
3991
5410
|
}
|
|
3992
5411
|
renderArrayTree(items, subtree = false) {
|
|
@@ -4031,15 +5450,15 @@ const ArcgisArcadeResults = class {
|
|
|
4031
5450
|
}
|
|
4032
5451
|
}
|
|
4033
5452
|
renderFeatureSetLabel(arcadeResult) {
|
|
4034
|
-
return (h("div", { class: "value-type" }, h("span", null, arcadeResult.type, ":"), arcadeResult.features.length >= BatchSize ? (h("span", null, "\u00A0",
|
|
4035
|
-
count: BatchSize.toString()
|
|
5453
|
+
return (h("div", { class: "value-type" }, h("span", null, arcadeResult.type, ":"), arcadeResult.features.length >= BatchSize ? (h("span", null, "\u00A0", setValuesInString(this.messages.showingfirstitemsformat, {
|
|
5454
|
+
count: BatchSize.toString(),
|
|
4036
5455
|
}))) : null));
|
|
4037
5456
|
}
|
|
4038
5457
|
render() {
|
|
4039
|
-
return (h(Host, null, h("header", { class: "flex-row" }, h("calcite-action-bar", { class: "flex-adjustable", layout: "horizontal", scale: "s", expanded: true, "expand-disabled": true }, h("calcite-action-group", { scale: "s" }, h("calcite-action", { active: this.openedResultPanel === "output", text: this.
|
|
5458
|
+
return (h(Host, null, h("header", { class: "flex-row" }, h("calcite-action-bar", { class: "flex-adjustable", layout: "horizontal", scale: "s", expanded: true, "expand-disabled": true }, h("calcite-action-group", { scale: "s" }, h("calcite-action", { active: this.openedResultPanel === "output", text: this.messages.output ?? "Output", "text-enabled": true, scale: "s", icon: "list-show-all", iconFlipRtl: true, onClick: this._switchResultPanel, "data-panel-name": "output" }), h("calcite-action", { active: this.openedResultPanel === "console", text: this.messages.console ?? "Console", "text-enabled": true, scale: "s", icon: "console", iconFlipRtl: true, onClick: this._switchResultPanel, "data-panel-name": "console" }), h("calcite-action", { active: this.openedResultPanel === "log", text: this.messages.log ?? "Log", "text-enabled": true, scale: "s", icon: "list", iconFlipRtl: true, onClick: this._switchResultPanel, "data-panel-name": "log" }))), h("calcite-action", { scale: "s", icon: "x", text: this.messages.close ?? "", onClick: this._emitClose })), h("article", { class: "flex-adjustable" }, this.loading ? (h("calcite-loader", { scale: "s", type: "indeterminate", label: "" })) : (h("div", { class: "flex-column y-scrollable-container" }, this.renderOutputPanel(), this.renderConsolePanel(), this.renderLogPanel())))));
|
|
4040
5459
|
}
|
|
4041
5460
|
static get assetsDirs() { return ["assets"]; }
|
|
4042
|
-
get
|
|
5461
|
+
get el() { return getElement(this); }
|
|
4043
5462
|
};
|
|
4044
5463
|
ArcgisArcadeResults.style = arcadeResultsCss;
|
|
4045
5464
|
|
|
@@ -4053,13 +5472,15 @@ function isSuggestionGroups(item) {
|
|
|
4053
5472
|
return Array.isArray(item[0].suggestions);
|
|
4054
5473
|
}
|
|
4055
5474
|
|
|
4056
|
-
const arcadeSuggestionsCss = ":host{background-color:var(--calcite-color-foreground-1)}:host .notice-container{margin:var(--calcite-spacing-
|
|
5475
|
+
const arcadeSuggestionsCss = ":host{background-color:var(--calcite-color-foreground-1)}:host .notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}:host .sticky{position:sticky;top:0px;z-index:10}:host calcite-flow{height:100%}:host calcite-block p:first-of-type{margin-top:0}:host calcite-block code{font-family:var(--calcite-code-family)}:host calcite-block pre{direction:ltr;overflow-x:auto;background-color:var(--calcite-color-foreground-2);padding:var(--calcite-spacing-sm)}:host calcite-block pre code{font-size:var(--calcite-font-size--2)}";
|
|
4057
5476
|
|
|
4058
5477
|
const ArcgisArcadeSuggestions = class {
|
|
4059
5478
|
constructor(hostRef) {
|
|
4060
5479
|
registerInstance(this, hostRef);
|
|
4061
|
-
this.
|
|
4062
|
-
this.
|
|
5480
|
+
this.arcgisClose = createEvent(this, "arcgisClose", 3);
|
|
5481
|
+
this.arcgisItemSelected = createEvent(this, "arcgisItemSelected", 3);
|
|
5482
|
+
this.manager = useControllerManager(this);
|
|
5483
|
+
this.messages = useT9n();
|
|
4063
5484
|
this._updateFilterValue = (e) => {
|
|
4064
5485
|
this._filterValue = e.target?.value ?? "";
|
|
4065
5486
|
};
|
|
@@ -4071,7 +5492,7 @@ const ArcgisArcadeSuggestions = class {
|
|
|
4071
5492
|
const keyEvent = e;
|
|
4072
5493
|
if (!keyEvent.key || keyEvent.key === "Enter") {
|
|
4073
5494
|
e.preventDefault();
|
|
4074
|
-
this.
|
|
5495
|
+
this.arcgisItemSelected.emit(item.code);
|
|
4075
5496
|
}
|
|
4076
5497
|
};
|
|
4077
5498
|
this._showSuggestionDetail = (e) => {
|
|
@@ -4083,14 +5504,11 @@ const ArcgisArcadeSuggestions = class {
|
|
|
4083
5504
|
this._selectedSuggestion = item;
|
|
4084
5505
|
};
|
|
4085
5506
|
this._emitClose = () => {
|
|
4086
|
-
this.
|
|
5507
|
+
this.arcgisClose.emit();
|
|
4087
5508
|
};
|
|
4088
5509
|
this._beforeBack = async () => {
|
|
4089
5510
|
this._selectedSuggestion = undefined;
|
|
4090
5511
|
};
|
|
4091
|
-
this._lang = "";
|
|
4092
|
-
this._t9nLocale = "";
|
|
4093
|
-
this._t9nStrings = undefined;
|
|
4094
5512
|
this._selectedSuggestion = undefined;
|
|
4095
5513
|
this._filterValue = "";
|
|
4096
5514
|
this._colorizeStyle = "";
|
|
@@ -4103,13 +5521,11 @@ const ArcgisArcadeSuggestions = class {
|
|
|
4103
5521
|
// #region Component lifecycle events
|
|
4104
5522
|
async componentWillLoad() {
|
|
4105
5523
|
this._colorizeStyle = generateColorizeStyles();
|
|
4106
|
-
this.
|
|
4107
|
-
await B(this, getAssetPath("./assets"));
|
|
5524
|
+
this._themeChangedListener = onColorizeThemeChanged(() => (this._colorizeStyle = generateColorizeStyles()));
|
|
4108
5525
|
}
|
|
4109
5526
|
disconnectedCallback() {
|
|
4110
5527
|
this._flowObserver?.disconnect();
|
|
4111
|
-
this.
|
|
4112
|
-
q(this);
|
|
5528
|
+
this._themeChangedListener?.dispose();
|
|
4113
5529
|
}
|
|
4114
5530
|
// #endregion
|
|
4115
5531
|
//#region Private Methods
|
|
@@ -4127,7 +5543,7 @@ const ArcgisArcadeSuggestions = class {
|
|
|
4127
5543
|
// When switching between flow the same reference is reused
|
|
4128
5544
|
this._flowObserver = new MutationObserver(() => {
|
|
4129
5545
|
// Get the last panel and try to set focus on the input element
|
|
4130
|
-
|
|
5546
|
+
setFocusOnElement(ref.querySelector("calcite-flow-item:last-child"), "calcite-input");
|
|
4131
5547
|
});
|
|
4132
5548
|
this._flowObserver.observe(ref, { attributes: true, attributeFilter: ["id"], childList: true });
|
|
4133
5549
|
}
|
|
@@ -4145,29 +5561,29 @@ const ArcgisArcadeSuggestions = class {
|
|
|
4145
5561
|
renderSuggestionListItems(suggestions) {
|
|
4146
5562
|
suggestions = filterCollection(suggestions, "label", this._filterValue);
|
|
4147
5563
|
if (!suggestions.length) {
|
|
4148
|
-
return h("div", { class: "notice-container" }, this.
|
|
5564
|
+
return h("div", { class: "notice-container" }, this.messages.noitems ?? "No item");
|
|
4149
5565
|
}
|
|
4150
|
-
return suggestions.map((suggestion) => (h("calcite-list-item", { label: suggestion.label, description: suggestion.description, onCalciteListItemSelect: this._emitItemSelected, onKeyPress: this._emitItemSelected, "data-item": suggestion }, h("calcite-action", { slot: "actions-end", text: this.
|
|
5566
|
+
return suggestions.map((suggestion) => (h("calcite-list-item", { label: suggestion.label, description: suggestion.description, onCalciteListItemSelect: this._emitItemSelected, onKeyPress: this._emitItemSelected, "data-item": suggestion }, h("calcite-action", { slot: "actions-end", text: this.messages.expand ?? "", scale: "s", icon: "chevron-right", iconFlipRtl: true, onClick: this._showSuggestionDetail, "data-item": suggestion }))));
|
|
4151
5567
|
}
|
|
4152
5568
|
renderSuggestionFlowItem() {
|
|
4153
5569
|
const suggestion = this._selectedSuggestion;
|
|
4154
5570
|
if (!suggestion) {
|
|
4155
5571
|
return null;
|
|
4156
5572
|
}
|
|
4157
|
-
return (h("calcite-flow-item", { heading: this.
|
|
5573
|
+
return (h("calcite-flow-item", { heading: this.messages.suggestions, closable: true, onCalciteFlowItemClose: this._emitClose, beforeBack: this._beforeBack }, h("calcite-button", { width: "half", slot: "footer", appearance: "outline", kind: "brand", "icon-start": "code", scale: "s", onClick: this._emitItemSelected, ref: (e) => void e?.setFocus(), "data-item": suggestion }, this.messages.insert), h("calcite-block", { open: true, heading: suggestion.label, description: suggestion.description }, h("div", { innerHTML: convertMarkdownString(suggestion.documentation) }), h("pre", null, h("code", { ref: (e) => e === undefined ? undefined : void colorizeCodeElement(e, suggestion.code).catch(console.error) })))));
|
|
4158
5574
|
}
|
|
4159
5575
|
render() {
|
|
4160
|
-
return (h(Host, null, h("style", null, this._colorizeStyle), h("calcite-flow", { ref: (ref) => this.flowFocusHandler(ref) }, h("calcite-flow-item", { heading: this.
|
|
5576
|
+
return (h(Host, null, h("style", null, this._colorizeStyle), h("calcite-flow", { ref: (ref) => this.flowFocusHandler(ref) }, h("calcite-flow-item", { heading: this.messages.suggestions, closable: true, onCalciteFlowItemClose: this._emitClose }, h("calcite-input", { value: this._filterValue, icon: "magnifying-glass", clearable: true, onCalciteInputInput: this._updateFilterValue, class: "sticky", scale: "m" }), h("calcite-list", null, this.renderSuggestionGroups())), this.renderSuggestionFlowItem())));
|
|
4161
5577
|
}
|
|
4162
5578
|
static get assetsDirs() { return ["assets"]; }
|
|
4163
|
-
get
|
|
5579
|
+
get el() { return getElement(this); }
|
|
4164
5580
|
static get watchers() { return {
|
|
4165
5581
|
"suggestions": ["suggestionsPropChanged"]
|
|
4166
5582
|
}; }
|
|
4167
5583
|
};
|
|
4168
5584
|
ArcgisArcadeSuggestions.style = arcadeSuggestionsCss;
|
|
4169
5585
|
|
|
4170
|
-
const arcadeVariablesCss = ":host{background-color:var(--calcite-color-foreground-1)}:host .notice-container{margin:var(--calcite-spacing-
|
|
5586
|
+
const arcadeVariablesCss = ":host{background-color:var(--calcite-color-foreground-1)}:host .notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}:host .sticky{position:sticky;top:0px;z-index:10}:host calcite-flow{height:100%}";
|
|
4171
5587
|
|
|
4172
5588
|
function stopEnterPropagation(e) {
|
|
4173
5589
|
if (e.key === "Enter") {
|
|
@@ -4177,8 +5593,10 @@ function stopEnterPropagation(e) {
|
|
|
4177
5593
|
const ArcgisArcadeVariables = class {
|
|
4178
5594
|
constructor(hostRef) {
|
|
4179
5595
|
registerInstance(this, hostRef);
|
|
4180
|
-
this.
|
|
4181
|
-
this.
|
|
5596
|
+
this.arcgisClose = createEvent(this, "arcgisClose", 3);
|
|
5597
|
+
this.arcgisItemSelected = createEvent(this, "arcgisItemSelected", 3);
|
|
5598
|
+
this.manager = useControllerManager(this);
|
|
5599
|
+
this.messages = useT9n();
|
|
4182
5600
|
this._updateFilterValue = (e) => {
|
|
4183
5601
|
this._filterValue = e.target.value;
|
|
4184
5602
|
};
|
|
@@ -4187,7 +5605,7 @@ const ArcgisArcadeVariables = class {
|
|
|
4187
5605
|
this._filterValue = "";
|
|
4188
5606
|
};
|
|
4189
5607
|
this._emitClose = () => {
|
|
4190
|
-
this.
|
|
5608
|
+
this.arcgisClose.emit();
|
|
4191
5609
|
};
|
|
4192
5610
|
this._backToTop = () => {
|
|
4193
5611
|
this._flowItemRenderers = [];
|
|
@@ -4200,7 +5618,7 @@ const ArcgisArcadeVariables = class {
|
|
|
4200
5618
|
const keyEvent = e;
|
|
4201
5619
|
if (!keyEvent.key || keyEvent.key === "Enter") {
|
|
4202
5620
|
e.preventDefault();
|
|
4203
|
-
this.
|
|
5621
|
+
this.arcgisItemSelected.emit(variable.snippet);
|
|
4204
5622
|
}
|
|
4205
5623
|
};
|
|
4206
5624
|
this._showCollectionPanel = (e) => {
|
|
@@ -4211,9 +5629,6 @@ const ArcgisArcadeVariables = class {
|
|
|
4211
5629
|
e.stopPropagation();
|
|
4212
5630
|
this.addPanelRenderer(this.collectionBasedVariableRenderer(collectionVariable));
|
|
4213
5631
|
};
|
|
4214
|
-
this._lang = "";
|
|
4215
|
-
this._t9nLocale = "";
|
|
4216
|
-
this._t9nStrings = undefined;
|
|
4217
5632
|
this._mutationCounter = 1;
|
|
4218
5633
|
this._flowItemRenderers = [];
|
|
4219
5634
|
this._filterValue = "";
|
|
@@ -4224,12 +5639,7 @@ const ArcgisArcadeVariables = class {
|
|
|
4224
5639
|
this._flowItemRenderers = [];
|
|
4225
5640
|
}
|
|
4226
5641
|
//#endregion
|
|
4227
|
-
// #region Component lifecycle events
|
|
4228
|
-
async componentWillLoad() {
|
|
4229
|
-
await B(this, getAssetPath("./assets"));
|
|
4230
|
-
}
|
|
4231
5642
|
disconnectedCallback() {
|
|
4232
|
-
q(this);
|
|
4233
5643
|
this._flowObserver?.disconnect();
|
|
4234
5644
|
}
|
|
4235
5645
|
// #endregion
|
|
@@ -4254,7 +5664,7 @@ const ArcgisArcadeVariables = class {
|
|
|
4254
5664
|
// When switching between flow the same reference is reused
|
|
4255
5665
|
this._flowObserver = new MutationObserver(() => {
|
|
4256
5666
|
// Get the last panel and try to set focus on the input element
|
|
4257
|
-
|
|
5667
|
+
setFocusOnElement(ref.querySelector("calcite-flow-item:last-child"), "calcite-input");
|
|
4258
5668
|
});
|
|
4259
5669
|
this._flowObserver.observe(ref, { attributes: true, attributeFilter: ["id"], childList: true });
|
|
4260
5670
|
}
|
|
@@ -4283,15 +5693,15 @@ const ArcgisArcadeVariables = class {
|
|
|
4283
5693
|
});
|
|
4284
5694
|
loading = true;
|
|
4285
5695
|
}
|
|
4286
|
-
return (h("calcite-flow-item", { heading: this.
|
|
5696
|
+
return (h("calcite-flow-item", { heading: this.messages.profilevariables, description: collection.breadcrumb, beforeBack: this._beforeBack, closable: true, onCalciteFlowItemClose: this._emitClose }, h("calcite-action", { slot: "header-actions-end", text: this.messages.backtotop ?? "Back to top", scale: "m", hidden: topPanel, icon: "chevrons-left", iconFlipRtl: true, onClick: this._backToTop }), h("calcite-input", { value: this._filterValue, icon: "magnifying-glass", clearable: true, onCalciteInputInput: this._updateFilterValue, class: "sticky", scale: "m" }), loading ? (h("calcite-loader", { scale: "s", type: "indeterminate", label: this.messages.loading ?? "Loading" })) : (h("calcite-list", null, this.renderEditorVariables(collection)))));
|
|
4287
5697
|
};
|
|
4288
5698
|
}
|
|
4289
5699
|
renderEditorVariables(collection) {
|
|
4290
5700
|
// Filter the variables. Skip group, we will filter the children later on.
|
|
4291
|
-
const filterExpression =
|
|
5701
|
+
const filterExpression = createFilterExpression(this._filterValue);
|
|
4292
5702
|
const filteredVariables = collection.variables.filter((variable) => variable.passFilter(filterExpression));
|
|
4293
5703
|
if (!filteredVariables.length) {
|
|
4294
|
-
return h("div", { class: "notice-container" }, this.
|
|
5704
|
+
return h("div", { class: "notice-container" }, this.messages.noitems ?? "No item");
|
|
4295
5705
|
}
|
|
4296
5706
|
return filteredVariables.map((variable) => this.renderEditorVariable(variable));
|
|
4297
5707
|
}
|
|
@@ -4301,18 +5711,18 @@ const ArcgisArcadeVariables = class {
|
|
|
4301
5711
|
// Group is a collection but we represent it differently
|
|
4302
5712
|
return (h("calcite-list-item-group", { heading: variable.getLabel() }, this.renderEditorVariables(variable)));
|
|
4303
5713
|
default:
|
|
4304
|
-
return (h("calcite-list-item", { label: variable.getLabel(), description: variable.getDescription(), onCalciteListItemSelect: this._emitItemSelected, onKeyPress: this._emitItemSelected, "data-item": variable }, variable.isCollection ? (h("calcite-action", { slot: "actions-end", text: this.
|
|
5714
|
+
return (h("calcite-list-item", { label: variable.getLabel(), description: variable.getDescription(), onCalciteListItemSelect: this._emitItemSelected, onKeyPress: this._emitItemSelected, "data-item": variable }, variable.isCollection ? (h("calcite-action", { slot: "actions-end", text: this.messages.expand ?? "", scale: "s", icon: "chevron-right", iconFlipRtl: true, onClick: this._showCollectionPanel, onKeyPress: stopEnterPropagation, "data-item": variable })) : null, variable.icon ? h("calcite-icon", { icon: variable.icon, scale: "s", slot: "content-start" }) : null));
|
|
4305
5715
|
}
|
|
4306
5716
|
}
|
|
4307
5717
|
render() {
|
|
4308
5718
|
const profile = arcadeDefaults.getEditorProfileForModel(this.modelId ?? "");
|
|
4309
5719
|
if (!this.loading && !profile?.variables.length) {
|
|
4310
|
-
return (h("calcite-flow", null, h("calcite-flow-item", { heading: this.
|
|
5720
|
+
return (h("calcite-flow", null, h("calcite-flow-item", { heading: this.messages.profilevariables, closable: true, onCalciteFlowItemClose: this._emitClose }, h("div", { class: "notice-container" }, this.messages.noprofilevariablesmessage ?? ""))));
|
|
4311
5721
|
}
|
|
4312
5722
|
return (h("calcite-flow", { ref: (ref) => this.flowFocusHandler(ref) }, this.collectionBasedVariableRenderer(profile, true)(), this._flowItemRenderers.map((renderer) => renderer())));
|
|
4313
5723
|
}
|
|
4314
5724
|
static get assetsDirs() { return ["assets"]; }
|
|
4315
|
-
get
|
|
5725
|
+
get el() { return getElement(this); }
|
|
4316
5726
|
static get watchers() { return {
|
|
4317
5727
|
"modelId": ["modelIdPropChanged"]
|
|
4318
5728
|
}; }
|
|
@@ -4330,74 +5740,76 @@ const EditorOptionsDefaults = {
|
|
|
4330
5740
|
renderLineHighlight: "none",
|
|
4331
5741
|
suggest: {
|
|
4332
5742
|
snippetsPreventQuickSuggestions: false,
|
|
4333
|
-
showWords: false
|
|
5743
|
+
showWords: false,
|
|
4334
5744
|
},
|
|
4335
5745
|
tabSize: 2,
|
|
4336
|
-
useShadowDOM: true
|
|
5746
|
+
useShadowDOM: true,
|
|
4337
5747
|
};
|
|
4338
5748
|
const ArcgisCodeEditor = class {
|
|
4339
5749
|
constructor(hostRef) {
|
|
4340
5750
|
registerInstance(this, hostRef);
|
|
4341
|
-
this.
|
|
4342
|
-
this.
|
|
5751
|
+
this.arcgisValueChange = createEvent(this, "arcgisValueChange", 3);
|
|
5752
|
+
this.arcgisSelectionChange = createEvent(this, "arcgisSelectionChange", 3);
|
|
5753
|
+
this.manager = useControllerManager(this);
|
|
5754
|
+
this._componentReadyDefer = new Deferred$1();
|
|
4343
5755
|
this._disposables = [];
|
|
4344
|
-
this.value =
|
|
5756
|
+
this.value = this.manager.getSet("", {
|
|
5757
|
+
get: () => this._editorInstance?.getValue() ?? "",
|
|
5758
|
+
set: (newValue, oldValue) => {
|
|
5759
|
+
if (!this._editorInstance) {
|
|
5760
|
+
return "";
|
|
5761
|
+
}
|
|
5762
|
+
const model = this._editorInstance.getModel();
|
|
5763
|
+
if (!model) {
|
|
5764
|
+
return "";
|
|
5765
|
+
}
|
|
5766
|
+
if (model.getValue() === newValue) {
|
|
5767
|
+
return newValue;
|
|
5768
|
+
}
|
|
5769
|
+
// Set the value and preserve the undo stack
|
|
5770
|
+
const range = model.getFullModelRange();
|
|
5771
|
+
this._editorInstance.executeEdits("", [{ range, text: newValue ?? "", forceMoveMarkers: true }]);
|
|
5772
|
+
this._editorInstance.pushUndoStop();
|
|
5773
|
+
// By returning oldValue we are preventing a re-render.
|
|
5774
|
+
// The getter will return the new value anyway.
|
|
5775
|
+
return oldValue;
|
|
5776
|
+
},
|
|
5777
|
+
});
|
|
4345
5778
|
this.language = undefined;
|
|
4346
|
-
this.modelId =
|
|
5779
|
+
this.modelId = generateGuid();
|
|
4347
5780
|
this.options = undefined;
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
}
|
|
4353
|
-
this._editorInstance.setValue(newValue ?? "");
|
|
5781
|
+
this.editorInstance = this.manager.getSet(undefined, {
|
|
5782
|
+
get: () => this._editorInstance,
|
|
5783
|
+
set: (_value, prevValue) => prevValue,
|
|
5784
|
+
});
|
|
4354
5785
|
}
|
|
4355
5786
|
languagePropChange() {
|
|
4356
|
-
if (!this._editorInstance) {
|
|
4357
|
-
return;
|
|
4358
|
-
}
|
|
4359
5787
|
this.updateModel();
|
|
4360
5788
|
}
|
|
4361
5789
|
modelIdPropChange() {
|
|
4362
|
-
if (!this._editorInstance) {
|
|
4363
|
-
return;
|
|
4364
|
-
}
|
|
4365
5790
|
this.updateModel();
|
|
4366
5791
|
}
|
|
4367
5792
|
optionsPropChange(newValue) {
|
|
4368
|
-
if (!
|
|
5793
|
+
if (!newValue) {
|
|
4369
5794
|
return;
|
|
4370
5795
|
}
|
|
4371
|
-
this._editorInstance
|
|
5796
|
+
this._editorInstance?.updateOptions(newValue);
|
|
4372
5797
|
}
|
|
4373
5798
|
//#endregion
|
|
4374
5799
|
// #region Public methods API
|
|
4375
5800
|
/**
|
|
4376
|
-
*
|
|
4377
|
-
* @returns {Promise<string>}
|
|
5801
|
+
* @deprecated Use `value` property instead.
|
|
4378
5802
|
*/
|
|
4379
5803
|
async getValue() {
|
|
4380
5804
|
await this._componentReadyDefer.promise;
|
|
4381
|
-
return this.
|
|
5805
|
+
return this.value;
|
|
4382
5806
|
}
|
|
4383
5807
|
/**
|
|
4384
|
-
*
|
|
4385
|
-
* on the model to preserve undo/redo stack.
|
|
4386
|
-
* @param text
|
|
4387
|
-
* @returns {Promise<void>}
|
|
5808
|
+
* @deprecated Use `value` property instead.
|
|
4388
5809
|
*/
|
|
4389
5810
|
async setValue(text) {
|
|
4390
5811
|
await this._componentReadyDefer.promise;
|
|
4391
|
-
|
|
4392
|
-
return;
|
|
4393
|
-
}
|
|
4394
|
-
const model = this._editorInstance.getModel();
|
|
4395
|
-
if (!model) {
|
|
4396
|
-
return;
|
|
4397
|
-
}
|
|
4398
|
-
const range = model.getFullModelRange();
|
|
4399
|
-
this._editorInstance.executeEdits("", [{ range, text: text ?? "", forceMoveMarkers: true }]);
|
|
4400
|
-
this._editorInstance.pushUndoStop();
|
|
5812
|
+
this.value = text ?? "";
|
|
4401
5813
|
}
|
|
4402
5814
|
/**
|
|
4403
5815
|
* Inserts a text at the current position in the editor.
|
|
@@ -4432,8 +5844,7 @@ const ArcgisCodeEditor = class {
|
|
|
4432
5844
|
}
|
|
4433
5845
|
/**
|
|
4434
5846
|
* @internal
|
|
4435
|
-
*
|
|
4436
|
-
* @returns {Promise<IStandaloneCodeEditor>} - The monaco editor instance
|
|
5847
|
+
* @deprecated Use `editorInstance` property instead.
|
|
4437
5848
|
*/
|
|
4438
5849
|
async getEditorInstance() {
|
|
4439
5850
|
await this._componentReadyDefer.promise;
|
|
@@ -4467,30 +5878,32 @@ const ArcgisCodeEditor = class {
|
|
|
4467
5878
|
const model = editor.createModel("", this.language, this.getUri());
|
|
4468
5879
|
// Create the editor for the host element.
|
|
4469
5880
|
// This will not trigger a diagnostic.
|
|
4470
|
-
this._editorInstance = editor.create(this.
|
|
5881
|
+
this._editorInstance = editor.create(this.el, {
|
|
4471
5882
|
...(this.options ?? {}),
|
|
4472
5883
|
model,
|
|
4473
5884
|
fixedOverflowWidgets: true,
|
|
4474
|
-
scrollBeyondLastLine: false
|
|
5885
|
+
scrollBeyondLastLine: false,
|
|
4475
5886
|
});
|
|
4476
5887
|
this._disposables.push(this._editorInstance);
|
|
4477
5888
|
// Set the value now to trigger a diagnostic again
|
|
4478
5889
|
model.setValue(this.value ?? "");
|
|
4479
|
-
// Now we
|
|
5890
|
+
// Now we indicate that the component is ready
|
|
4480
5891
|
this._componentReadyDefer.resolve();
|
|
4481
5892
|
this._editorInstance.updateOptions(EditorOptionsDefaults);
|
|
4482
|
-
// Listen to the Monaco Editor content change event and propagate
|
|
4483
5893
|
this._editorInstance.onDidChangeModelContent(() => {
|
|
4484
|
-
|
|
4485
|
-
this.
|
|
5894
|
+
this.value = this._editorInstance?.getValue() ?? "";
|
|
5895
|
+
this.arcgisValueChange.emit(this.value);
|
|
5896
|
+
});
|
|
5897
|
+
this._editorInstance.onDidChangeCursorSelection((e) => {
|
|
5898
|
+
this.arcgisSelectionChange.emit({ selection: e.selection, model: this._editorInstance?.getModel() });
|
|
4486
5899
|
});
|
|
4487
5900
|
// Detect if the host element or its ancestors got a theme attribute mutation
|
|
4488
|
-
this._themeObserver =
|
|
5901
|
+
this._themeObserver = observeAncestorsMutation$1(this.el, ["class"], () => this.updateTheme());
|
|
4489
5902
|
// Update the theme of the Monaco Editor
|
|
4490
5903
|
this.updateTheme();
|
|
4491
5904
|
// Creates a resize observer to re-layout the editor on size changing
|
|
4492
5905
|
const resizeObserver = new ResizeObserver(() => this._editorInstance?.layout());
|
|
4493
|
-
resizeObserver.observe(this.
|
|
5906
|
+
resizeObserver.observe(this.el);
|
|
4494
5907
|
// Add common actions to the Monaco Editor's context menu and command palette
|
|
4495
5908
|
this.addCommonEditorActions();
|
|
4496
5909
|
}
|
|
@@ -4498,7 +5911,14 @@ const ArcgisCodeEditor = class {
|
|
|
4498
5911
|
while (this._disposables.length) {
|
|
4499
5912
|
this._disposables.pop()?.dispose();
|
|
4500
5913
|
}
|
|
4501
|
-
this._themeObserver?.
|
|
5914
|
+
this._themeObserver?.remove();
|
|
5915
|
+
}
|
|
5916
|
+
componentShouldUpdate(_newVal, _oldVal, propName) {
|
|
5917
|
+
if (propName === "value" || propName === "language" || propName === "modelId" || propName === "options") {
|
|
5918
|
+
// These are properties that we directly pass to the editor
|
|
5919
|
+
return false;
|
|
5920
|
+
}
|
|
5921
|
+
return true;
|
|
4502
5922
|
}
|
|
4503
5923
|
//#endregion
|
|
4504
5924
|
// #region Private methods API
|
|
@@ -4507,7 +5927,7 @@ const ArcgisCodeEditor = class {
|
|
|
4507
5927
|
return;
|
|
4508
5928
|
}
|
|
4509
5929
|
this._editorInstance.getModel()?.dispose();
|
|
4510
|
-
this._editorInstance.setModel(editor.createModel(this.value
|
|
5930
|
+
this._editorInstance.setModel(editor.createModel(this.value, this.language, this.getUri()));
|
|
4511
5931
|
}
|
|
4512
5932
|
getUri() {
|
|
4513
5933
|
return this.modelId ? Uri.parse(this.modelId) : Uri.parse("");
|
|
@@ -4516,7 +5936,7 @@ const ArcgisCodeEditor = class {
|
|
|
4516
5936
|
// This is called the first time and subsequently by the Mutation Observer
|
|
4517
5937
|
// Figure out the theme by walking the ancestor path.
|
|
4518
5938
|
// If no theme is found then default to light.
|
|
4519
|
-
const theme =
|
|
5939
|
+
const theme = getElementTheme(this.el) === "light" ? "vs" : "vs-dark";
|
|
4520
5940
|
if (theme === this._currentTheme) {
|
|
4521
5941
|
return;
|
|
4522
5942
|
}
|
|
@@ -4541,7 +5961,7 @@ const ArcgisCodeEditor = class {
|
|
|
4541
5961
|
contextMenuOrder: 1,
|
|
4542
5962
|
// Method that will be executed when the action is triggered.
|
|
4543
5963
|
// @param editor The editor instance is passed in as a convenience
|
|
4544
|
-
run: async () => await zoomInFn?.run()
|
|
5964
|
+
run: async () => await zoomInFn?.run(),
|
|
4545
5965
|
});
|
|
4546
5966
|
this._editorInstance?.addAction({
|
|
4547
5967
|
id: "editor.action.fontZoomOut",
|
|
@@ -4549,7 +5969,7 @@ const ArcgisCodeEditor = class {
|
|
|
4549
5969
|
keybindings: [KeyMod.CtrlCmd | KeyCode.Minus],
|
|
4550
5970
|
contextMenuGroupId: "zooming",
|
|
4551
5971
|
contextMenuOrder: 2,
|
|
4552
|
-
run: async () => await zoomOutFn?.run()
|
|
5972
|
+
run: async () => await zoomOutFn?.run(),
|
|
4553
5973
|
});
|
|
4554
5974
|
}
|
|
4555
5975
|
//#endregion
|
|
@@ -4558,9 +5978,8 @@ const ArcgisCodeEditor = class {
|
|
|
4558
5978
|
return h(Host, null);
|
|
4559
5979
|
}
|
|
4560
5980
|
static get assetsDirs() { return ["assets"]; }
|
|
4561
|
-
get
|
|
5981
|
+
get el() { return getElement(this); }
|
|
4562
5982
|
static get watchers() { return {
|
|
4563
|
-
"value": ["valuePropChange"],
|
|
4564
5983
|
"language": ["languagePropChange"],
|
|
4565
5984
|
"modelId": ["modelIdPropChange"],
|
|
4566
5985
|
"options": ["optionsPropChange"]
|