@arcgis/coding-components 4.31.0-next.2 → 4.31.0-next.21
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/README.md +22 -3
- package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ar.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bg.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bs.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ca.json +6 -6
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.cs.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.da.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.de.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.el.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.es.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.et.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fi.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fr.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.he.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.hr.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.id.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.it.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ko.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nb.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nl.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pl.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-BR.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-PT.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ru.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sk.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sl.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sr.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sv.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.th.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.tr.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.uk.json +5 -5
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.vi.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-CN.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-HK.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-TW.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.ca.json +2 -2
- package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.de.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.he.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.ca.json +1 -1
- package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.it.json +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/css.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/html.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/json.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/code-editor/sql-expr.worker.js +33 -0
- package/dist/arcgis-coding-components/assets/code-editor/ts.worker.js +1 -1
- package/dist/arcgis-coding-components/assets/language-api-panel/t9n/language-api-panel.t9n.ca.json +1 -1
- package/dist/arcgis-coding-components/assets/sql-expression-editor/api/sql-expression-api.t9n.en.json +735 -0
- package/dist/arcgis-coding-components/index.esm.js +2 -2
- package/dist/arcgis-coding-components/{p-7984ea8e.js → p-1b799777.js} +2 -2
- package/dist/arcgis-coding-components/p-4d5cf512.entry.js +6 -0
- package/dist/arcgis-coding-components/{p-60c2a820.js → p-56266a64.js} +2 -2
- package/dist/arcgis-coding-components/{p-e8211ffe.js → p-57b8bcd7.js} +1 -1
- package/dist/arcgis-coding-components/{p-9eced6fc.js → p-5b67b62b.js} +2 -2
- package/dist/arcgis-coding-components/{p-93a97573.js → p-64137fec.js} +3 -3
- package/dist/arcgis-coding-components/{p-e7ee4d64.js → p-6621a80f.js} +3 -3
- package/dist/arcgis-coding-components/p-77dd5521.js +6 -0
- package/dist/arcgis-coding-components/p-8eb7e694.js +6 -0
- package/dist/arcgis-coding-components/p-a2341e0c.js +6 -0
- package/dist/arcgis-coding-components/{p-bb7e832e.js → p-b715834b.js} +3 -3
- package/dist/arcgis-coding-components/p-cbee273f.js +6 -0
- package/dist/arcgis-coding-components/{p-5ef7cce5.js → p-cdc52d2f.js} +1 -1
- package/dist/arcgis-coding-components/{p-36fedc23.js → p-d7d1f130.js} +12 -12
- package/dist/arcgis-coding-components/p-e1f9b463.entry.js +6 -0
- package/dist/arcgis-coding-components/{p-62ee6251.js → p-e5a924a1.js} +1 -1
- package/dist/arcgis-coding-components/p-f2d64a9d.js +6 -0
- package/dist/arcgis-coding-components/{p-03ea6cd7.js → p-ff62d134.js} +3 -3
- package/dist/arcgis-coding-components/p-ffce0588.entry.js +6 -0
- package/dist/cjs/{app-globals-aee5f4b5.js → app-globals-a9ef3ca8.js} +1 -1
- package/dist/cjs/arcade-defaults-f5241680.js +349 -0
- package/dist/cjs/arcade-language-features-0b9f3947.js +274 -0
- package/dist/cjs/arcade-mode-cc08d9cd.js +335 -0
- package/dist/cjs/arcgis-arcade-editor_6.cjs.entry.js +181 -1501
- package/dist/cjs/arcgis-coding-components.cjs.js +4 -4
- package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +81 -0
- package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +80 -0
- package/dist/cjs/{css-7cc05f76.js → css-bb6a49ec.js} +1 -1
- package/dist/cjs/{cssMode-2b0daeae.js → cssMode-e7fac7d7.js} +3 -4
- package/dist/cjs/{html-f56911e1.js → html-7ff4071d.js} +3 -4
- package/dist/cjs/{htmlMode-43eed674.js → htmlMode-c89193ec.js} +3 -4
- package/dist/cjs/{index-b34238a6.js → index-4b7880ab.js} +9 -1
- package/dist/cjs/index.cjs.js +4 -3
- package/dist/cjs/{javascript-5115cb76.js → javascript-864c0220.js} +3 -4
- package/dist/cjs/{jsonMode-550dda36.js → jsonMode-ac4a7be7.js} +3 -4
- package/dist/cjs/{arcade-defaults-a8d8f8e2.js → language-defaults-base-57b37f9f.js} +842 -1183
- package/dist/cjs/loader.cjs.js +4 -4
- package/dist/cjs/sql-expr-defaults-245b036d.js +1347 -0
- package/dist/cjs/sql-expr-mode-304f5ce2.js +20844 -0
- package/dist/cjs/{tsMode-336306a9.js → tsMode-d30d4ab1.js} +4 -5
- package/dist/cjs/{typescript-b395242f.js → typescript-6c87ddb3.js} +3 -4
- package/dist/components/arcade-defaults.js +54 -1369
- package/dist/components/arcade-language-features.js +271 -0
- package/dist/components/arcade-mode.js +4 -264
- package/dist/components/arcade-results.js +7 -5
- package/dist/components/arcade-suggestions.js +7 -5
- package/dist/components/arcade-variables.js +8 -6
- package/dist/components/arcgis-arcade-editor.js +37 -35
- 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/arcgis-language-api-panel.js +1 -1
- package/dist/components/arcgis-sql-expression-editor.d.ts +11 -0
- package/dist/components/arcgis-sql-expression-editor.js +120 -0
- package/dist/components/arcgis-sql-expression-fields.d.ts +11 -0
- package/dist/components/arcgis-sql-expression-fields.js +11 -0
- package/dist/components/chunk-2JTWBRMN.js +1154 -0
- package/dist/components/code-editor.js +40 -13
- package/dist/components/fields.js +5 -5
- package/dist/components/index.js +1 -1
- package/dist/components/index2.js +30 -22
- package/dist/components/language-api-panel.js +13 -40
- package/dist/components/language-defaults-base.js +1309 -0
- package/dist/components/markdown.js +1 -1
- package/dist/components/sql-expr-defaults.js +196 -0
- package/dist/components/sql-expr-mode.js +20842 -0
- package/dist/components/sql-expression-fields.js +102 -0
- package/dist/components/useT9n.js +45 -8
- package/dist/components/utilities.js +1 -1
- package/dist/esm/{app-globals-59faaf33.js → app-globals-6d0ca11d.js} +1 -1
- package/dist/esm/arcade-defaults-066445c4.js +344 -0
- package/dist/esm/arcade-language-features-0e00c199.js +269 -0
- package/dist/esm/{arcade-mode-5d46035e.js → arcade-mode-abf1e1cf.js} +3 -263
- package/dist/esm/arcgis-arcade-editor_6.entry.js +127 -1447
- package/dist/esm/arcgis-coding-components.js +5 -5
- package/dist/esm/arcgis-sql-expression-editor.entry.js +77 -0
- package/dist/esm/arcgis-sql-expression-fields.entry.js +76 -0
- package/dist/esm/{css-e257dc49.js → css-c6dae12d.js} +1 -1
- package/dist/esm/{cssMode-c11f7f40.js → cssMode-052bb603.js} +2 -3
- package/dist/esm/{html-a6c37a99.js → html-572696a1.js} +2 -3
- package/dist/esm/{htmlMode-1270bc7d.js → htmlMode-fc184f2d.js} +2 -3
- package/dist/esm/{index-a970952c.js → index-0edd9846.js} +9 -1
- package/dist/esm/index.js +4 -3
- package/dist/esm/{javascript-ee179624.js → javascript-8bfc0096.js} +3 -4
- package/dist/esm/{jsonMode-07502ccb.js → jsonMode-7adf94ff.js} +2 -3
- package/dist/esm/{arcade-defaults-9eb28407.js → language-defaults-base-85a7f476.js} +833 -1179
- package/dist/esm/loader.js +5 -5
- package/dist/esm/sql-expr-defaults-be84ec7f.js +1339 -0
- package/dist/esm/sql-expr-mode-a4413e5c.js +20840 -0
- package/dist/esm/{tsMode-96749a12.js → tsMode-d10773c8.js} +2 -3
- package/dist/esm/{typescript-a3cf9881.js → typescript-9491f23e.js} +2 -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-editor/arcade-editor.d.ts +45 -10
- package/dist/types/components/arcade-results/arcade-results.d.ts +43 -1
- package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +22 -1
- package/dist/types/components/arcade-variables/arcade-variables.d.ts +28 -1
- package/dist/types/components/code-editor/code-editor.d.ts +16 -5
- package/dist/types/components/language-api-panel/language-api-panel.d.ts +34 -8
- package/dist/types/components/sql-expression-editor/sql-expression-editor.d.ts +24 -0
- package/dist/types/components/sql-expression-fields/sql-expression-fields.d.ts +32 -0
- package/dist/types/components.d.ts +98 -24
- 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 +8 -1
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/editorContext.d.ts +5 -1
- package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +13 -0
- package/dist/types/dependencies.d.ts +6 -10
- package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +1 -0
- package/dist/types/utils/arcade-monaco/arcade-profile-strategy.d.ts +9 -0
- package/dist/types/utils/fields.d.ts +2 -2
- package/dist/types/utils/language-defaults-base.d.ts +2 -9
- package/dist/types/utils/profile/editor-profile.d.ts +7 -6
- package/dist/types/utils/profile/types.d.ts +53 -65
- package/dist/types/utils/profile/utils.d.ts +9 -8
- package/dist/types/utils/sql-expr-monaco/DependentFiles/DateOnly.d.ts +41 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlInterval.d.ts +16 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlTimestampOffset.d.ts +26 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/TimeOnly.d.ts +37 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/UnknownTimeZone.d.ts +11 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/WhereGrammar.d.ts +122 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlCompareUtils.d.ts +5 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlDateParsingUtils.d.ts +18 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlUtils.d.ts +6 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/standardizedFunctions.d.ts +156 -0
- package/dist/types/utils/sql-expr-monaco/DependentFiles/support.d.ts +150 -0
- package/dist/types/utils/sql-expr-monaco/PeggyGrammar/sql92grammar.d.ts +1397 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-completion.d.ts +6 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-constants.d.ts +45 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-contribution.d.ts +1 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-defaults.d.ts +21 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-language-features.d.ts +39 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-language-syntax.d.ts +8 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-mode.d.ts +43 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-service-accessors.d.ts +19 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation-diagnostic-adapter.d.ts +34 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation-utils.d.ts +100 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-validation.d.ts +41 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr-worker-manager.d.ts +17 -0
- package/dist/types/utils/sql-expr-monaco/sql-expr.worker.d.ts +24 -0
- package/dist/types/utils/sql-expr-monaco/sql-expression-profile-strategy.d.ts +13 -0
- package/dist/types/utils/sql-expr-monaco/types.d.ts +89 -0
- package/package.json +27 -21
- package/dist/arcgis-coding-components/p-0c6de9b3.js +0 -6
- package/dist/arcgis-coding-components/p-81c37dab.entry.js +0 -6
- package/dist/cjs/arcade-mode-b85ae7d4.js +0 -595
- package/dist/components/chunk-IHYYRFLQ.js +0 -1363
- package/dist/types/components/arcade-editor/t9n-types.d.ts +0 -8
- package/dist/types/components/arcade-results/t9n-types.d.ts +0 -13
- package/dist/types/components/arcade-suggestions/t9n-types.d.ts +0 -6
- package/dist/types/components/arcade-variables/t9n-types.d.ts +0 -8
- package/dist/types/components/language-api-panel/t9n-types.d.ts +0 -8
- package/dist/types/utils/profile/predefined-profile.d.ts +0 -2
|
@@ -1,1363 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
|
-
* See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
|
-
* v4.31.0-next.2
|
|
5
|
-
*/
|
|
6
|
-
import { D as Deferred, k as camelToKebab, l as safeCall, m as safeAsyncCall, n as devToolsAwareTimeout } from './index2.js';
|
|
7
|
-
|
|
8
|
-
// src/framework.ts
|
|
9
|
-
function retrieveComponentMembers(component, isLit) {
|
|
10
|
-
if (isLit) {
|
|
11
|
-
const elementProperties = getLitProperties(component);
|
|
12
|
-
component.manager.internals.members = Object.fromEntries(
|
|
13
|
-
Array.from(elementProperties, ([name, { state, type }]) => [
|
|
14
|
-
name,
|
|
15
|
-
[
|
|
16
|
-
state ? 32 /* State */ : type === Number ? 2 /* Number */ : type === Boolean ? 4 /* Boolean */ : 1 /* String */
|
|
17
|
-
]
|
|
18
|
-
])
|
|
19
|
-
);
|
|
20
|
-
} else {
|
|
21
|
-
const constructor = component.constructor;
|
|
22
|
-
const members = constructor.__registerControllers?.(component) ?? void 0;
|
|
23
|
-
constructor.__registerControllers = void 0;
|
|
24
|
-
if (typeof members !== "object") {
|
|
25
|
-
throw new Error(
|
|
26
|
-
"Failed to retrieve internal component meta. Make sure you have the useComponentsControllers() Rollup Plugin for Stencil Controllers configured in your Stencil config."
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
component.manager.internals.members = members;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
var getLitProperties = (component) => component.constructor.elementProperties;
|
|
33
|
-
function parsePropertyValue(value, type = 8 /* Any */) {
|
|
34
|
-
const isComplex = value == null || typeof value === "object" || typeof value === "function";
|
|
35
|
-
if (isComplex) {
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
if ((type & 4 /* Boolean */) !== 0) {
|
|
39
|
-
return value === "false" ? false : value === "" || !!value;
|
|
40
|
-
} else if ((type & 2 /* Number */) !== 0) {
|
|
41
|
-
return Number.parseFloat(value);
|
|
42
|
-
} else if ((type & 1 /* String */) !== 0) {
|
|
43
|
-
return String(value);
|
|
44
|
-
} else {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
var makeMemberFilter = (filter) => (component) => {
|
|
49
|
-
const members = component.manager.internals.members;
|
|
50
|
-
return Object.entries(members ?? {}).filter(([_name, [propType]]) => (propType & filter) !== 0).map(([name]) => name);
|
|
51
|
-
};
|
|
52
|
-
var getPropLikeMembers = makeMemberFilter(63 /* PropLike */);
|
|
53
|
-
var getMemberType = (component, name) => component.manager.internals.members?.[name]?.[0];
|
|
54
|
-
function getPropType(component, name) {
|
|
55
|
-
const type = getMemberType(component, name);
|
|
56
|
-
if (type === void 0) {
|
|
57
|
-
return void 0;
|
|
58
|
-
} else if (type & 32 /* State */) {
|
|
59
|
-
return "state";
|
|
60
|
-
} else {
|
|
61
|
-
return "prop";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/types.ts
|
|
66
|
-
var controllerSymbol = Symbol("controller");
|
|
67
|
-
|
|
68
|
-
// src/utils.ts
|
|
69
|
-
var isController = (value) => typeof value === "object" && value !== null && (controllerSymbol in value || "hostConnected" in value || "hostDisconnected" in value || "hostUpdate" in value || "hostUpdated" in value);
|
|
70
|
-
|
|
71
|
-
// src/ControllerInternals.ts
|
|
72
|
-
var ControllerInternals = class {
|
|
73
|
-
constructor() {
|
|
74
|
-
this._ambientControllers = [];
|
|
75
|
-
/**
|
|
76
|
-
* The type definition has to be duplicated due to the
|
|
77
|
-
* "'use' is referenced directly or indirectly in its own type annotation."
|
|
78
|
-
* error
|
|
79
|
-
*/
|
|
80
|
-
this.use = async (value, watchExports) => {
|
|
81
|
-
const controller = this.useRefSync(value);
|
|
82
|
-
if (controller === void 0) {
|
|
83
|
-
if (typeof watchExports === "function") {
|
|
84
|
-
const error = new Error(
|
|
85
|
-
`Unable to resolve a controller from the provided value, so can't watch it's exports. ${unresolvableExports}`
|
|
86
|
-
);
|
|
87
|
-
{
|
|
88
|
-
console.error(error);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
await controller.ready;
|
|
94
|
-
if (typeof watchExports === "function") {
|
|
95
|
-
if (controller.watchExports === void 0) {
|
|
96
|
-
throw new Error(`The controller must implement watchExports method to support watching exports`);
|
|
97
|
-
}
|
|
98
|
-
const unsubscribe = controller.watchExports(
|
|
99
|
-
(exports) => watchExports(exports, unsubscribe)
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
return controller.exports;
|
|
103
|
-
};
|
|
104
|
-
this.useRef = async (value) => {
|
|
105
|
-
const controller = this.useRefSync(value);
|
|
106
|
-
if (controller === void 0) {
|
|
107
|
-
throw new Error(`Unable to resolve a controller from the provided value. ${unresolvableExports}`);
|
|
108
|
-
}
|
|
109
|
-
await controller.ready;
|
|
110
|
-
return controller;
|
|
111
|
-
};
|
|
112
|
-
this.useRefSync = (value) => {
|
|
113
|
-
const ambientChildController = this.retrieveAmbientChildController();
|
|
114
|
-
if (ambientChildController !== void 0) {
|
|
115
|
-
return ambientChildController;
|
|
116
|
-
}
|
|
117
|
-
const component = Controller.internals.retrieveComponent();
|
|
118
|
-
const controller = component.manager.internals.resolveExports(value);
|
|
119
|
-
if (controller !== void 0) {
|
|
120
|
-
return controller;
|
|
121
|
-
}
|
|
122
|
-
if (isController(value)) {
|
|
123
|
-
return value;
|
|
124
|
-
}
|
|
125
|
-
return void 0;
|
|
126
|
-
};
|
|
127
|
-
this.shouldBypassSetter = false;
|
|
128
|
-
this.shouldBypassGetter = false;
|
|
129
|
-
this.shouldBypassReadonly = false;
|
|
130
|
-
/**
|
|
131
|
-
* A map from component instance or component element to component instance.
|
|
132
|
-
* To get from component instance or component element to component element,
|
|
133
|
-
* you can just use the .el property
|
|
134
|
-
*/
|
|
135
|
-
this.elementToInstance = /* @__PURE__ */ new WeakMap();
|
|
136
|
-
}
|
|
137
|
-
/*
|
|
138
|
-
* Allow controllers to implicitly retrieve which component they are in, to
|
|
139
|
-
* improve DX (avoids the need to pass "this" explicitly for each controller)
|
|
140
|
-
*/
|
|
141
|
-
setAmbientComponent(component) {
|
|
142
|
-
if (this._ambientComponent === component) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
this._ambientComponent = component;
|
|
146
|
-
queueMicrotask(() => {
|
|
147
|
-
if (this._ambientComponent === component) {
|
|
148
|
-
this._ambientComponent = void 0;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
retrieveComponent(name) {
|
|
153
|
-
if (this._ambientComponent === void 0) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
[
|
|
156
|
-
`Unable to find out which component ${name || "this"} controller `,
|
|
157
|
-
"belongs to. This might happen if you tried to create a controller ",
|
|
158
|
-
"outside the component. If so, please wrap your controller ",
|
|
159
|
-
"definition in an arrow function, ",
|
|
160
|
-
"`const myController = ()=>makeController(...);` and call that",
|
|
161
|
-
"function inside the component `my = myController();`, or ",
|
|
162
|
-
"define your controller using makeGenericController/GenericController ",
|
|
163
|
-
"instead.\n",
|
|
164
|
-
"If you wish to use a controller inside an async controller, ",
|
|
165
|
-
"make sure you are using controller.use.\n",
|
|
166
|
-
"You might also have multiple instances of Controllers loaded"
|
|
167
|
-
].join("\n")
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return this._ambientComponent;
|
|
171
|
-
}
|
|
172
|
-
/*
|
|
173
|
-
* Aids proxyExports() in knowing who is it's host
|
|
174
|
-
*/
|
|
175
|
-
setParentController(controller) {
|
|
176
|
-
if (controller === void 0) {
|
|
177
|
-
this._ambientControllers = [];
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const index = this._ambientControllers.indexOf(controller);
|
|
181
|
-
this._ambientControllers = index === -1 ? [...this._ambientControllers, controller] : this._ambientControllers.slice(0, index + 1);
|
|
182
|
-
queueMicrotask(() => {
|
|
183
|
-
this._ambientControllers = [];
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
retrieveParentControllers() {
|
|
187
|
-
return this._ambientControllers;
|
|
188
|
-
}
|
|
189
|
-
/*
|
|
190
|
-
* Aids controller.use in retrieving controller value when it receives
|
|
191
|
-
* controller exports, rather than the controller itself
|
|
192
|
-
*/
|
|
193
|
-
setAmbientChildController(controller) {
|
|
194
|
-
if (this._ambientChildController === controller) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
this._ambientChildController = controller;
|
|
198
|
-
queueMicrotask(() => {
|
|
199
|
-
if (this._ambientChildController === controller) {
|
|
200
|
-
this._ambientChildController = void 0;
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
retrieveAmbientChildController() {
|
|
205
|
-
const controller = this._ambientChildController;
|
|
206
|
-
this._ambientChildController = void 0;
|
|
207
|
-
return controller;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
var unresolvableExports = [
|
|
211
|
-
"The value you passed is not a controller and not a controller exports. If ",
|
|
212
|
-
"your controller exports a literal value, try making your controller export ",
|
|
213
|
-
"an object instead"
|
|
214
|
-
].join("");
|
|
215
|
-
|
|
216
|
-
// src/Controller.ts
|
|
217
|
-
var _a;
|
|
218
|
-
var _Controller = class _Controller {
|
|
219
|
-
constructor(component) {
|
|
220
|
-
this._callbacks = {
|
|
221
|
-
hostConnected: [],
|
|
222
|
-
hostDisconnected: [],
|
|
223
|
-
hostLoad: [],
|
|
224
|
-
hostLoaded: [],
|
|
225
|
-
hostUpdate: [],
|
|
226
|
-
hostUpdated: [],
|
|
227
|
-
hostDestroy: [],
|
|
228
|
-
hostLifecycle: []
|
|
229
|
-
};
|
|
230
|
-
this._ready = new Deferred();
|
|
231
|
-
this._lifecycleDisconnected = [];
|
|
232
|
-
this.connectedCalled = false;
|
|
233
|
-
this.willLoadCalled = false;
|
|
234
|
-
this.didLoadCalled = false;
|
|
235
|
-
this[_a] = true;
|
|
236
|
-
this.ready = this._ready.promise;
|
|
237
|
-
/*
|
|
238
|
-
* Setting default exports to "this" so that controllers that don't use
|
|
239
|
-
* exports/proxyExports(), could still be used as if they did
|
|
240
|
-
* (i.e with controller.use)
|
|
241
|
-
*/
|
|
242
|
-
this._exports = makeProvisionalValue(this);
|
|
243
|
-
this._exportWatchers = /* @__PURE__ */ new Set();
|
|
244
|
-
const resolvedComponent = toControllerHost(
|
|
245
|
-
component ?? _Controller.internals.retrieveComponent(new.target.name)
|
|
246
|
-
);
|
|
247
|
-
Object.defineProperty(this, "component", {
|
|
248
|
-
writable: false,
|
|
249
|
-
enumerable: false,
|
|
250
|
-
configurable: true,
|
|
251
|
-
value: resolvedComponent
|
|
252
|
-
});
|
|
253
|
-
this.component.addController(this);
|
|
254
|
-
_Controller.internals.setParentController(this);
|
|
255
|
-
if ("hostDestroy" in this) {
|
|
256
|
-
this.component.manager.ensureHasDestroy();
|
|
257
|
-
}
|
|
258
|
-
const manager = this.component.manager;
|
|
259
|
-
const isInControllerManager = manager === void 0;
|
|
260
|
-
if (!isInControllerManager) {
|
|
261
|
-
queueMicrotask(() => this.catchUpLifecycle());
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* If controller is being added dynamically, after the component
|
|
266
|
-
* construction, then trigger connected and load right away
|
|
267
|
-
*/
|
|
268
|
-
catchUpLifecycle() {
|
|
269
|
-
const { manager } = this.component;
|
|
270
|
-
const connectedWillStillHappen = !manager.connectedCalled;
|
|
271
|
-
if (!connectedWillStillHappen && !this.connectedCalled) {
|
|
272
|
-
this.triggerConnected();
|
|
273
|
-
}
|
|
274
|
-
const loadWillStillHappen = !manager.willLoadCalled;
|
|
275
|
-
if (loadWillStillHappen) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
this.triggerLoad().then(() => {
|
|
279
|
-
const loadedWillStillHappen = !manager.didLoadCalled;
|
|
280
|
-
if (loadedWillStillHappen) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
this.triggerLoaded();
|
|
284
|
-
}).catch(console.error);
|
|
285
|
-
}
|
|
286
|
-
get exports() {
|
|
287
|
-
return this._exports;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Set controller's exports property (for usage with proxyExports()) and mark
|
|
291
|
-
* controller as ready (for usage in other controllers). Also, triggers
|
|
292
|
-
* re-render of the component
|
|
293
|
-
*/
|
|
294
|
-
set exports(exports) {
|
|
295
|
-
if (this._exports !== exports) {
|
|
296
|
-
this._exports = exports;
|
|
297
|
-
if (this.connectedCalled) {
|
|
298
|
-
this.component.requestUpdate();
|
|
299
|
-
}
|
|
300
|
-
this._exportWatchers.forEach(safeCall);
|
|
301
|
-
}
|
|
302
|
-
this._ready.resolve(exports);
|
|
303
|
-
}
|
|
304
|
-
setProvisionalExports(exports) {
|
|
305
|
-
this._exports = makeProvisionalValue(exports);
|
|
306
|
-
this._exportWatchers.forEach(safeCall);
|
|
307
|
-
}
|
|
308
|
-
watchExports(callback) {
|
|
309
|
-
const safeCallback = () => callback(this._exports);
|
|
310
|
-
this._exportWatchers.add(safeCallback);
|
|
311
|
-
return () => void this._exportWatchers.delete(safeCallback);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* A flexible utility for making sure a controller is loaded before it's used,
|
|
315
|
-
* regardless of how or where a controller was defined:
|
|
316
|
-
*
|
|
317
|
-
* @example
|
|
318
|
-
* makeGenericController(async (component, controller) => {
|
|
319
|
-
* // Await some controller from the component:
|
|
320
|
-
* await controller.use(component.someController);
|
|
321
|
-
* // Initialize new controllers
|
|
322
|
-
* await controller.use(load(importCoreReactiveUtils));
|
|
323
|
-
* await controller.use(new ViewModelController(component,newWidgetsHomeHomeViewModel));
|
|
324
|
-
* await controller.use(someController(component));
|
|
325
|
-
* });
|
|
326
|
-
*
|
|
327
|
-
* @remarks
|
|
328
|
-
* If your controller is not async, and you are not creating it async, then
|
|
329
|
-
* you are not required to use controller.use - you can use it directly.
|
|
330
|
-
* Similarly, accessing controllers after componentWillLoad callback does not
|
|
331
|
-
* require awaiting them as they are guaranteed to be loaded by then.
|
|
332
|
-
*/
|
|
333
|
-
get use() {
|
|
334
|
-
_Controller.internals.setAmbientComponent(this.component);
|
|
335
|
-
return _Controller.internals.use;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Just like controller.use, but returns the controller itself, rather than it's
|
|
339
|
-
* exports
|
|
340
|
-
*
|
|
341
|
-
* Use cases:
|
|
342
|
-
* - You have a controller and you want to make sure it's loaded before you
|
|
343
|
-
* try to use it
|
|
344
|
-
* - Your controller is not using exports, so you wish to access some props on
|
|
345
|
-
* it directly
|
|
346
|
-
* - You have a controller exports only, and you want to retrieve the
|
|
347
|
-
* controller itself. This is useful if you wish to call .watchExports() or
|
|
348
|
-
* some other method on the controller
|
|
349
|
-
*/
|
|
350
|
-
get useRef() {
|
|
351
|
-
_Controller.internals.setAmbientComponent(this.component);
|
|
352
|
-
return _Controller.internals.useRef;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Like useRef, but doesn't wait for the controller to get ready
|
|
356
|
-
*/
|
|
357
|
-
get useRefSync() {
|
|
358
|
-
_Controller.internals.setAmbientComponent(this.component);
|
|
359
|
-
return _Controller.internals.useRefSync;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* If you need to set a prop/state without triggering the custom setter you
|
|
363
|
-
* defined with getSet()/dynamicGetSet()/readonly(), set the value inside
|
|
364
|
-
* of this function
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* @Prop() readOnly = this.manager.readOnly(true);
|
|
368
|
-
*
|
|
369
|
-
* someAction(): void {
|
|
370
|
-
* this.manager.bypassSetter(()=>{
|
|
371
|
-
* this.readOnly = false;
|
|
372
|
-
* });
|
|
373
|
-
* }
|
|
374
|
-
*
|
|
375
|
-
*/
|
|
376
|
-
bypassSetter(callback) {
|
|
377
|
-
_Controller.internals.shouldBypassSetter = true;
|
|
378
|
-
try {
|
|
379
|
-
return callback();
|
|
380
|
-
} finally {
|
|
381
|
-
_Controller.internals.shouldBypassSetter = false;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Like bypassSetter, but only bypasses this.manager.readonly(), rather that
|
|
386
|
-
* all setters set using this.manager.getSet()
|
|
387
|
-
*/
|
|
388
|
-
bypassReadonly(callback) {
|
|
389
|
-
_Controller.internals.shouldBypassReadonly = true;
|
|
390
|
-
try {
|
|
391
|
-
return callback();
|
|
392
|
-
} finally {
|
|
393
|
-
_Controller.internals.shouldBypassReadonly = false;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Property reads inside of this function will bypass any custom getter you
|
|
398
|
-
* may have, and read the value directly from what's stored in Stencil/Lit.
|
|
399
|
-
*
|
|
400
|
-
* This also bypasses reactiveUtils integration - reading a property inside of
|
|
401
|
-
* bypassGetter won't make that property tracked.
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* reactiveUtils.watch(
|
|
405
|
-
* ()=>{
|
|
406
|
-
* this.manager.bypassGetter(()=>{
|
|
407
|
-
* console.log(this.someProp);
|
|
408
|
-
* });
|
|
409
|
-
* return this.prop;
|
|
410
|
-
* },
|
|
411
|
-
* console.log
|
|
412
|
-
* )
|
|
413
|
-
*/
|
|
414
|
-
bypassGetter(callback) {
|
|
415
|
-
_Controller.internals.shouldBypassGetter = true;
|
|
416
|
-
try {
|
|
417
|
-
return callback();
|
|
418
|
-
} finally {
|
|
419
|
-
_Controller.internals.shouldBypassGetter = false;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Like this.manager.getSet(), but can be called on any component's
|
|
424
|
-
* state/prop from anywhere, rather than just from the default value
|
|
425
|
-
*/
|
|
426
|
-
dynamicGetSet(name, getSet) {
|
|
427
|
-
this.genericGetSet(name, getSet);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Like dynamicGetSet, but less type-safe. Useful in cases when trying to set
|
|
431
|
-
* getters/setters in place where property names & types are not known
|
|
432
|
-
* statically
|
|
433
|
-
*/
|
|
434
|
-
genericGetSet(property, getSet) {
|
|
435
|
-
var _a2, _b;
|
|
436
|
-
const genericGetSet = getSet;
|
|
437
|
-
const internals = this.component.manager.internals;
|
|
438
|
-
if (typeof genericGetSet.get === "function") {
|
|
439
|
-
(_a2 = internals.getters)[property] ?? (_a2[property] = []);
|
|
440
|
-
internals.getters[property].unshift(genericGetSet.get);
|
|
441
|
-
}
|
|
442
|
-
const set = genericGetSet.set === "ignore" ? ignoreSet : genericGetSet.set;
|
|
443
|
-
if (set) {
|
|
444
|
-
(_b = internals.setters)[property] ?? (_b[property] = []);
|
|
445
|
-
internals.setters[property].unshift(set);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
// FEATURE: improve typings
|
|
449
|
-
/**
|
|
450
|
-
* Dynamically set a watcher for any reactive property
|
|
451
|
-
*/
|
|
452
|
-
watch(property, callback) {
|
|
453
|
-
var _a2;
|
|
454
|
-
const type = getMemberType(this.component, property);
|
|
455
|
-
if (type === void 0) {
|
|
456
|
-
throw new Error(
|
|
457
|
-
`Trying to watch a non-@property, non-@state property "${property}". Either convert it into a @state() or use get/set syntax`
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
const internals = this.component.manager.internals;
|
|
461
|
-
(_a2 = internals.allWatchers)[property] ?? (_a2[property] = []);
|
|
462
|
-
const watchers = internals.allWatchers[property];
|
|
463
|
-
const genericCallback = callback;
|
|
464
|
-
const safeCallback = (newValue, oldValue, propertyName) => safeCall(genericCallback, null, newValue, oldValue, propertyName);
|
|
465
|
-
watchers.push(safeCallback);
|
|
466
|
-
return () => {
|
|
467
|
-
const index = watchers.indexOf(safeCallback);
|
|
468
|
-
if (index !== -1) {
|
|
469
|
-
watchers.splice(index, 1);
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
controllerRemoved() {
|
|
474
|
-
if (this.component.el.isConnected) {
|
|
475
|
-
this.triggerDisconnected();
|
|
476
|
-
}
|
|
477
|
-
this.triggerDestroy();
|
|
478
|
-
}
|
|
479
|
-
// Register a lifecycle callback
|
|
480
|
-
onConnected(callback) {
|
|
481
|
-
this._callbacks.hostConnected.push(callback);
|
|
482
|
-
}
|
|
483
|
-
onDisconnected(callback) {
|
|
484
|
-
this._callbacks.hostDisconnected.push(callback);
|
|
485
|
-
}
|
|
486
|
-
onLoad(callback) {
|
|
487
|
-
this._callbacks.hostLoad.push(callback);
|
|
488
|
-
}
|
|
489
|
-
onLoaded(callback) {
|
|
490
|
-
this._callbacks.hostLoaded.push(callback);
|
|
491
|
-
}
|
|
492
|
-
onUpdate(callback) {
|
|
493
|
-
this._callbacks.hostUpdate.push(callback);
|
|
494
|
-
}
|
|
495
|
-
onUpdated(callback) {
|
|
496
|
-
this._callbacks.hostUpdated.push(callback);
|
|
497
|
-
}
|
|
498
|
-
onDestroy(callback) {
|
|
499
|
-
this.component.manager.ensureHasDestroy();
|
|
500
|
-
this._callbacks.hostDestroy.push(callback);
|
|
501
|
-
}
|
|
502
|
-
onLifecycle(callback) {
|
|
503
|
-
this._callbacks.hostLifecycle.push(callback);
|
|
504
|
-
if (this.connectedCalled && this.component.el.isConnected) {
|
|
505
|
-
this._callLifecycle(callback);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
// Call each lifecycle hook
|
|
509
|
-
triggerConnected() {
|
|
510
|
-
const genericController = this;
|
|
511
|
-
if (genericController.hostConnected) {
|
|
512
|
-
safeCall(genericController.hostConnected, genericController);
|
|
513
|
-
}
|
|
514
|
-
this._callbacks.hostConnected.forEach(safeCall);
|
|
515
|
-
this.triggerLifecycle();
|
|
516
|
-
this.connectedCalled = true;
|
|
517
|
-
}
|
|
518
|
-
triggerDisconnected() {
|
|
519
|
-
const genericController = this;
|
|
520
|
-
if (genericController.hostDisconnected) {
|
|
521
|
-
safeCall(genericController.hostDisconnected, genericController);
|
|
522
|
-
}
|
|
523
|
-
this._callbacks.hostDisconnected.forEach(safeCall);
|
|
524
|
-
this._lifecycleDisconnected.forEach(safeCall);
|
|
525
|
-
this._lifecycleDisconnected = [];
|
|
526
|
-
}
|
|
527
|
-
async triggerLoad() {
|
|
528
|
-
if (this.willLoadCalled) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
this.willLoadCalled = true;
|
|
532
|
-
const genericController = this;
|
|
533
|
-
if (genericController.hostLoad) {
|
|
534
|
-
await safeAsyncCall(genericController.hostLoad, genericController);
|
|
535
|
-
}
|
|
536
|
-
if (this._callbacks.hostLoad.length > 0) {
|
|
537
|
-
await Promise.allSettled(this._callbacks.hostLoad.map(safeAsyncCall));
|
|
538
|
-
}
|
|
539
|
-
this._ready.resolve(this._exports);
|
|
540
|
-
}
|
|
541
|
-
triggerLoaded() {
|
|
542
|
-
if (this.didLoadCalled) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
const genericController = this;
|
|
546
|
-
if (genericController.hostLoaded) {
|
|
547
|
-
safeCall(genericController.hostLoaded, genericController);
|
|
548
|
-
}
|
|
549
|
-
this._callbacks.hostLoaded.forEach(safeCall);
|
|
550
|
-
this.didLoadCalled = true;
|
|
551
|
-
}
|
|
552
|
-
triggerUpdate() {
|
|
553
|
-
const genericController = this;
|
|
554
|
-
if (genericController.hostUpdate) {
|
|
555
|
-
safeCall(genericController.hostUpdate, genericController);
|
|
556
|
-
}
|
|
557
|
-
this._callbacks.hostUpdate.forEach(safeCall);
|
|
558
|
-
}
|
|
559
|
-
triggerUpdated() {
|
|
560
|
-
const genericController = this;
|
|
561
|
-
if (genericController.hostUpdated) {
|
|
562
|
-
safeCall(genericController.hostUpdated, genericController);
|
|
563
|
-
}
|
|
564
|
-
this._callbacks.hostUpdated.forEach(safeCall);
|
|
565
|
-
}
|
|
566
|
-
triggerDestroy() {
|
|
567
|
-
const genericController = this;
|
|
568
|
-
if (genericController.hostDestroy) {
|
|
569
|
-
safeCall(genericController.hostDestroy, genericController);
|
|
570
|
-
}
|
|
571
|
-
this._callbacks.hostDestroy.forEach(safeCall);
|
|
572
|
-
}
|
|
573
|
-
triggerLifecycle() {
|
|
574
|
-
const genericController = this;
|
|
575
|
-
if (genericController.hostLifecycle) {
|
|
576
|
-
this._callLifecycle(() => genericController.hostLifecycle());
|
|
577
|
-
}
|
|
578
|
-
this._callbacks.hostLifecycle.forEach((callback) => this._callLifecycle(callback));
|
|
579
|
-
}
|
|
580
|
-
_callLifecycle(callback) {
|
|
581
|
-
_Controller.internals.setAmbientComponent(this.component);
|
|
582
|
-
const cleanupRaw = safeCall(callback);
|
|
583
|
-
const cleanup = Array.isArray(cleanupRaw) ? cleanupRaw : [cleanupRaw];
|
|
584
|
-
cleanup.forEach((cleanup2) => {
|
|
585
|
-
if (typeof cleanup2 === "function") {
|
|
586
|
-
this._lifecycleDisconnected.push(cleanup2);
|
|
587
|
-
} else if (typeof cleanup2 === "object" && typeof cleanup2.remove === "function") {
|
|
588
|
-
this._lifecycleDisconnected.push(cleanup2.remove);
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
_a = controllerSymbol;
|
|
594
|
-
_Controller.internals = new ControllerInternals();
|
|
595
|
-
var Controller = _Controller;
|
|
596
|
-
var GenericController = class extends Controller {
|
|
597
|
-
// Redundant constructor needed to improve typing
|
|
598
|
-
constructor(component) {
|
|
599
|
-
super(component);
|
|
600
|
-
}
|
|
601
|
-
// Overriding super's watch only to improve typing
|
|
602
|
-
watch(property, callback) {
|
|
603
|
-
return super.watch(
|
|
604
|
-
property,
|
|
605
|
-
callback
|
|
606
|
-
);
|
|
607
|
-
}
|
|
608
|
-
dynamicGetSet(property, getSet) {
|
|
609
|
-
super.genericGetSet(property, getSet);
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
function makeProvisionalValue(base) {
|
|
613
|
-
if (typeof base !== "object" && typeof base !== "function" || base === null) {
|
|
614
|
-
return base;
|
|
615
|
-
}
|
|
616
|
-
const proxy2 = new Proxy(base, {
|
|
617
|
-
get(target, prop, receiver) {
|
|
618
|
-
if (cyclical.has(prop) && prop in target && target[prop] === proxy2) {
|
|
619
|
-
return void 0;
|
|
620
|
-
}
|
|
621
|
-
if (prop in target || prop in Promise.prototype || typeof prop === "symbol") {
|
|
622
|
-
return typeof target === "function" ? target[prop] : Reflect.get(target, prop, receiver);
|
|
623
|
-
}
|
|
624
|
-
console.error(`Trying to access "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
|
|
625
|
-
return void 0;
|
|
626
|
-
},
|
|
627
|
-
set(target, prop, newValue, receiver) {
|
|
628
|
-
console.error(`Trying to set "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
|
|
629
|
-
return Reflect.set(target, prop, newValue, receiver);
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
return proxy2;
|
|
633
|
-
}
|
|
634
|
-
var cyclical = /* @__PURE__ */ new Set(["exports", "_exports"]);
|
|
635
|
-
var accessBeforeLoad = "" ;
|
|
636
|
-
function toControllerHost(component) {
|
|
637
|
-
if ("addController" in component) {
|
|
638
|
-
return component;
|
|
639
|
-
} else {
|
|
640
|
-
throw new Error(
|
|
641
|
-
"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"
|
|
642
|
-
);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
var ignoreSet = (_, value) => value;
|
|
646
|
-
function trackPropertyKey(object, onResolved, defaultValue) {
|
|
647
|
-
const keys = Object.keys(object);
|
|
648
|
-
const keyCount = keys.length;
|
|
649
|
-
if (keyTrackMap === void 0) {
|
|
650
|
-
queueMicrotask(keyTrackResolve);
|
|
651
|
-
}
|
|
652
|
-
keyTrackMap ?? (keyTrackMap = /* @__PURE__ */ new Map());
|
|
653
|
-
let pendingTrackers = keyTrackMap.get(object);
|
|
654
|
-
if (pendingTrackers === void 0) {
|
|
655
|
-
pendingTrackers = { callbacks: [], keyCount };
|
|
656
|
-
keyTrackMap.set(object, pendingTrackers);
|
|
657
|
-
}
|
|
658
|
-
if (pendingTrackers.keyCount !== keyCount) {
|
|
659
|
-
pendingTrackers.callbacks.forEach((resolve) => resolve(keys));
|
|
660
|
-
pendingTrackers.callbacks = [];
|
|
661
|
-
pendingTrackers.keyCount = keyCount;
|
|
662
|
-
}
|
|
663
|
-
pendingTrackers.callbacks.push((keys2) => {
|
|
664
|
-
const callback = (key2) => safeCall(onResolved, null, key2);
|
|
665
|
-
const key = keys2[keyCount];
|
|
666
|
-
if (key === void 0) {
|
|
667
|
-
callback(void 0);
|
|
668
|
-
} else if (object[key] === defaultValue) {
|
|
669
|
-
callback(key);
|
|
670
|
-
} else {
|
|
671
|
-
callback(void 0);
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
return defaultValue;
|
|
675
|
-
}
|
|
676
|
-
var keyTrackMap = void 0;
|
|
677
|
-
function keyTrackResolve() {
|
|
678
|
-
Array.from(keyTrackMap?.entries() ?? []).forEach(([object, { callbacks }]) => {
|
|
679
|
-
const keys = Object.keys(object);
|
|
680
|
-
callbacks.forEach((commit) => commit(keys));
|
|
681
|
-
});
|
|
682
|
-
keyTrackMap = void 0;
|
|
683
|
-
}
|
|
684
|
-
var ComponentInternals = class {
|
|
685
|
-
constructor(component) {
|
|
686
|
-
/**
|
|
687
|
-
* When watchers are set, set then into `allWatchers`. When watchers are read
|
|
688
|
-
* in the setter, read from `enabledWatchers`.
|
|
689
|
-
* On connectedCallback(), controller manager does `enabledWatchers=allWatchers`.
|
|
690
|
-
* Reasoning:
|
|
691
|
-
* - This disables watchers until connected callback (matches behavior of
|
|
692
|
-
* Stencil's watchers)
|
|
693
|
-
* - This removes in the setter to check if watchers were enabled already or
|
|
694
|
-
* not (as getters/setters are hot path, and should be streamlined)
|
|
695
|
-
*/
|
|
696
|
-
this.enabledWatchers = {};
|
|
697
|
-
this.allWatchers = {};
|
|
698
|
-
this.trackKey = (hostsCandidates, onResolved, defaultValue) => {
|
|
699
|
-
const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
|
|
700
|
-
let leftToResolve = candidateHosts.length + 1;
|
|
701
|
-
const resolved = (resolution) => {
|
|
702
|
-
leftToResolve -= 1;
|
|
703
|
-
if (resolution !== void 0) {
|
|
704
|
-
leftToResolve = 0;
|
|
705
|
-
}
|
|
706
|
-
if (leftToResolve === 0) {
|
|
707
|
-
onResolved(resolution);
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
candidateHosts.forEach(
|
|
711
|
-
(host) => this.component.manager.trackPropertyKey(
|
|
712
|
-
host,
|
|
713
|
-
(key) => resolved(
|
|
714
|
-
key === void 0 ? void 0 : {
|
|
715
|
-
key,
|
|
716
|
-
host,
|
|
717
|
-
type: "property",
|
|
718
|
-
domValue: void 0
|
|
719
|
-
}
|
|
720
|
-
),
|
|
721
|
-
defaultValue
|
|
722
|
-
)
|
|
723
|
-
);
|
|
724
|
-
this.component.manager.trackPropKey((key, domValue) => {
|
|
725
|
-
const propType = key === void 0 ? void 0 : getPropType(this.component, key);
|
|
726
|
-
resolved(
|
|
727
|
-
key === void 0 ? void 0 : {
|
|
728
|
-
key,
|
|
729
|
-
host: this.component,
|
|
730
|
-
type: propType ?? "prop",
|
|
731
|
-
domValue: propType === "prop" ? domValue : void 0
|
|
732
|
-
}
|
|
733
|
-
);
|
|
734
|
-
}, defaultValue);
|
|
735
|
-
return defaultValue;
|
|
736
|
-
};
|
|
737
|
-
this.trackPropKey = (onResolved, defaultValue) => {
|
|
738
|
-
if (this._trackedValue !== nothing && this._trackedValue !== defaultValue) {
|
|
739
|
-
this._firePropertyTrackers(void 0, void 0, void 0);
|
|
740
|
-
}
|
|
741
|
-
if (this._keyTrackers.length === 0) {
|
|
742
|
-
queueMicrotask(() => this._firePropertyTrackers(void 0, void 0, void 0));
|
|
743
|
-
}
|
|
744
|
-
this._trackedValue = defaultValue;
|
|
745
|
-
this._keyTrackers.push(
|
|
746
|
-
(key, value, previousValue) => safeCall(onResolved, void 0, defaultValue === value ? key : void 0, previousValue)
|
|
747
|
-
);
|
|
748
|
-
return defaultValue;
|
|
749
|
-
};
|
|
750
|
-
this._trackedValue = nothing;
|
|
751
|
-
this._keyTrackers = [];
|
|
752
|
-
this.getters = {};
|
|
753
|
-
this.setters = {};
|
|
754
|
-
this.accessorGetter = {};
|
|
755
|
-
this.accessorSetter = {};
|
|
756
|
-
this.reactiveUtilsIntegrations = /* @__PURE__ */ new Set();
|
|
757
|
-
this._exports = /* @__PURE__ */ new WeakMap();
|
|
758
|
-
Object.defineProperty(this, "component", {
|
|
759
|
-
writable: false,
|
|
760
|
-
enumerable: false,
|
|
761
|
-
configurable: true,
|
|
762
|
-
value: component
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
_firePropertyTrackers(key, value, oldValue) {
|
|
766
|
-
const trackers = this._keyTrackers;
|
|
767
|
-
this._trackedValue = nothing;
|
|
768
|
-
this._keyTrackers = [];
|
|
769
|
-
trackers.forEach((tracker) => tracker(key, value, oldValue));
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Configure a getter or setter for a given \@Prop/\@State
|
|
773
|
-
*
|
|
774
|
-
* Note, since props are defined on the prototype, they are shared between all
|
|
775
|
-
* instances of a component. Thus, instead of passing a reference to the
|
|
776
|
-
* getter/setter function, you should update the
|
|
777
|
-
* ComponentInternals.getters/setters properties, and then call getSetProxy
|
|
778
|
-
* to apply the changes to the prototype
|
|
779
|
-
*/
|
|
780
|
-
getSetProxy(property, hasGetter, hasSetter) {
|
|
781
|
-
const component = this.component;
|
|
782
|
-
const classPrototype = component.constructor.prototype;
|
|
783
|
-
this._getSetProxy(classPrototype, property, hasGetter, hasSetter, "class");
|
|
784
|
-
if (component.manager.isLit) {
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
const htmlPrototype = component.el.constructor.prototype;
|
|
788
|
-
if (classPrototype !== htmlPrototype) {
|
|
789
|
-
this._getSetProxy(htmlPrototype, property, hasGetter, hasSetter, "html");
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
_getSetProxy(prototype, name, hasGetter, hasSetter, type) {
|
|
793
|
-
const component = this.component;
|
|
794
|
-
const propType = getMemberType(component, name);
|
|
795
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
796
|
-
const tolerateNotFound = type === "html";
|
|
797
|
-
if (descriptor?.set === void 0 || descriptor.get === void 0) {
|
|
798
|
-
if (descriptor !== void 0 && "value" in descriptor) {
|
|
799
|
-
throw new Error(
|
|
800
|
-
`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}`
|
|
801
|
-
);
|
|
802
|
-
} else if (tolerateNotFound) {
|
|
803
|
-
return;
|
|
804
|
-
} else {
|
|
805
|
-
throw new Error(`Unable to find "${name}" property on the ${component.el.tagName} component`);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
const { get: originalGet, set: originalSet } = descriptor;
|
|
809
|
-
const isGetterAlreadyOverwritten = customAccessor in originalGet;
|
|
810
|
-
const isSetterAlreadyOverwritten = customAccessor in originalSet;
|
|
811
|
-
const shouldOverwriteGet = !isGetterAlreadyOverwritten && hasGetter;
|
|
812
|
-
const shouldOverwriteSet = !isSetterAlreadyOverwritten && hasSetter;
|
|
813
|
-
if (!shouldOverwriteGet && !shouldOverwriteSet) {
|
|
814
|
-
return;
|
|
815
|
-
}
|
|
816
|
-
const finalGetter = shouldOverwriteGet ? function getter() {
|
|
817
|
-
let value = originalGet.call(this);
|
|
818
|
-
const component2 = Controller.internals.elementToInstance.get(this);
|
|
819
|
-
if (Controller.internals.shouldBypassGetter || component2 === void 0) {
|
|
820
|
-
return value;
|
|
821
|
-
}
|
|
822
|
-
const internals = component2.manager.internals;
|
|
823
|
-
value = internals.accessorGetter[name](value, name);
|
|
824
|
-
const getters = internals.getters[name] ?? emptyArray;
|
|
825
|
-
for (let i = 0; i < getters.length; i++) {
|
|
826
|
-
value = getters[i](value, name);
|
|
827
|
-
}
|
|
828
|
-
return value;
|
|
829
|
-
} : originalGet;
|
|
830
|
-
const finalSetter = shouldOverwriteSet ? function setter(rawNewValue) {
|
|
831
|
-
const oldValue = originalGet.call(this);
|
|
832
|
-
const component2 = Controller.internals.elementToInstance.get(this);
|
|
833
|
-
if (component2 === void 0) {
|
|
834
|
-
originalSet.call(this, rawNewValue);
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
|
-
let newValue = component2.manager.isLit ? rawNewValue : parsePropertyValue(rawNewValue, propType);
|
|
838
|
-
const internals = component2.manager.internals;
|
|
839
|
-
if (newValue === oldValue) {
|
|
840
|
-
originalSet.call(this, rawNewValue);
|
|
841
|
-
} else {
|
|
842
|
-
const setters = Controller.internals.shouldBypassSetter ? emptyArray : internals.setters[name] ?? emptyArray;
|
|
843
|
-
for (let i = 0; i < setters.length; i++) {
|
|
844
|
-
newValue = setters[i](newValue, oldValue, name);
|
|
845
|
-
if (newValue === oldValue) {
|
|
846
|
-
break;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
newValue = internals.accessorSetter[name](newValue, oldValue, name);
|
|
850
|
-
originalSet.call(this, newValue);
|
|
851
|
-
if (newValue !== oldValue) {
|
|
852
|
-
internals.enabledWatchers[name]?.forEach((watcher) => watcher(newValue, oldValue, name));
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
if (internals._keyTrackers.length > 0) {
|
|
856
|
-
internals?._firePropertyTrackers(name, rawNewValue, oldValue);
|
|
857
|
-
}
|
|
858
|
-
} : originalSet;
|
|
859
|
-
if (shouldOverwriteGet) {
|
|
860
|
-
Object.defineProperty(finalGetter, customAccessor, { value: true });
|
|
861
|
-
}
|
|
862
|
-
if (shouldOverwriteSet) {
|
|
863
|
-
Object.defineProperty(finalSetter, customAccessor, { value: true });
|
|
864
|
-
}
|
|
865
|
-
Object.defineProperty(prototype, name, {
|
|
866
|
-
...descriptor,
|
|
867
|
-
get: finalGetter,
|
|
868
|
-
set: finalSetter
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* Associate an exports object with a controller for reverse lookup in
|
|
873
|
-
* controller.use
|
|
874
|
-
*/
|
|
875
|
-
markExports(controller, exports) {
|
|
876
|
-
if (typeof exports === "object" && exports !== null || typeof exports === "function") {
|
|
877
|
-
this._exports.set(exports, controller);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
resolveExports(exports) {
|
|
881
|
-
if (typeof exports === "object" && exports !== null || typeof exports === "function") {
|
|
882
|
-
return this._exports.get(exports);
|
|
883
|
-
} else {
|
|
884
|
-
return void 0;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
var emptyArray = [];
|
|
889
|
-
var customAccessor = Symbol("controllersCustomAccessor");
|
|
890
|
-
var nothing = Symbol("nothing");
|
|
891
|
-
var useControllerManager = (component, forceUpdate) => new ControllerManager(component, forceUpdate);
|
|
892
|
-
var ControllerManager = class extends GenericController {
|
|
893
|
-
constructor(component, forceUpdate) {
|
|
894
|
-
const isLit = "addController" in component;
|
|
895
|
-
const controllers = /* @__PURE__ */ new Set();
|
|
896
|
-
function addController(controller) {
|
|
897
|
-
controllers.add(controller);
|
|
898
|
-
if (isLit && !(controllerSymbol in controller) && component.el.isConnected) {
|
|
899
|
-
controller.hostConnected?.();
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
function removeController(controller) {
|
|
903
|
-
void controllers.delete(controller);
|
|
904
|
-
controller.controllerRemoved?.();
|
|
905
|
-
}
|
|
906
|
-
const controllerHost = component;
|
|
907
|
-
controllerHost.addController = addController;
|
|
908
|
-
controllerHost.removeController = removeController;
|
|
909
|
-
if (!isLit) {
|
|
910
|
-
const update = forceUpdate ?? component.constructor.__forceUpdate;
|
|
911
|
-
controllerHost.requestUpdate = () => update(component);
|
|
912
|
-
}
|
|
913
|
-
super(component);
|
|
914
|
-
this.internals = new ComponentInternals(this.component);
|
|
915
|
-
this.destroyed = false;
|
|
916
|
-
this._updatePromise = new Deferred();
|
|
917
|
-
this._originalLifecycles = {};
|
|
918
|
-
/**
|
|
919
|
-
* A magical solution to finding out what property name a given controller
|
|
920
|
-
* on a given object was assigned to. Note, this does not work for properties
|
|
921
|
-
* that have \@Prop() or \@State() decorator - for those, use
|
|
922
|
-
* manager.trackPropKey() instead.
|
|
923
|
-
*
|
|
924
|
-
* @example
|
|
925
|
-
* function trackMe<T>(defaultValue:T, component:BaseComponent):T {
|
|
926
|
-
* component.manager.trackPropertyKey(component, (key)=>console.log(key), defaultValue);
|
|
927
|
-
* return defaultValue;
|
|
928
|
-
* }
|
|
929
|
-
*
|
|
930
|
-
* class MyComponent extends BaseComponent {
|
|
931
|
-
* // Will console log "myProp"
|
|
932
|
-
* myProp = trackMe('a', this);
|
|
933
|
-
* }
|
|
934
|
-
*
|
|
935
|
-
*/
|
|
936
|
-
this.trackPropertyKey = trackPropertyKey;
|
|
937
|
-
/**
|
|
938
|
-
* Like manager.trackPropertyKey(), but for props that have \@State() or \@Prop()
|
|
939
|
-
* decorator
|
|
940
|
-
*
|
|
941
|
-
* @example
|
|
942
|
-
* function trackMe(component:BaseComponent) {
|
|
943
|
-
* component.manager.trackPropKey((key)=>console.log(key));
|
|
944
|
-
* }
|
|
945
|
-
*
|
|
946
|
-
* class MyComponent extends BaseComponent {
|
|
947
|
-
* // Will console log "myProp"
|
|
948
|
-
* @Prop() myProp = trackMe(this);
|
|
949
|
-
*
|
|
950
|
-
* // Will console log "myState"
|
|
951
|
-
* @State() myState = trackMe(this);
|
|
952
|
-
* }
|
|
953
|
-
*/
|
|
954
|
-
this.trackPropKey = this.internals.trackPropKey;
|
|
955
|
-
/**
|
|
956
|
-
* A combination of trackPropertyKey() and trackPropKey(). For usage when
|
|
957
|
-
* you want to track a property, but don't know if it will be defined with the
|
|
958
|
-
* \@Prop() decorator or not
|
|
959
|
-
*/
|
|
960
|
-
this.trackKey = this.internals.trackKey;
|
|
961
|
-
this._readonlySetter = (newValue, oldValue, property) => {
|
|
962
|
-
if (Controller.internals.shouldBypassReadonly) {
|
|
963
|
-
return newValue;
|
|
964
|
-
}
|
|
965
|
-
const component = this.component;
|
|
966
|
-
const isProp = getPropType(component, property) === "prop";
|
|
967
|
-
if (isProp) {
|
|
968
|
-
if (this.isLit) {
|
|
969
|
-
const details = getLitProperties(component).get(property);
|
|
970
|
-
if (details && details?.attribute !== false) {
|
|
971
|
-
component.el.setAttribute(
|
|
972
|
-
typeof details.attribute === "string" ? details.attribute : camelToKebab(property),
|
|
973
|
-
// Not using converter.toAttribute to keep this unlikely case simpler
|
|
974
|
-
String(oldValue)
|
|
975
|
-
);
|
|
976
|
-
}
|
|
977
|
-
} else {
|
|
978
|
-
component.requestUpdate();
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
throw new Error(
|
|
982
|
-
`Cannot assign to read-only property "${property}" of ${component.el.tagName.toLowerCase()}. Trying to assign "${String(
|
|
983
|
-
newValue
|
|
984
|
-
)}"`
|
|
985
|
-
);
|
|
986
|
-
};
|
|
987
|
-
/**
|
|
988
|
-
* In development, on hot module reload, controller would be re-initialized
|
|
989
|
-
* with all Props and State values persistent, but properties lost. This unsafe
|
|
990
|
-
* development-only API lets you set or get data for a controller that would
|
|
991
|
-
* persist across hot reloads.
|
|
992
|
-
*/
|
|
993
|
-
this.devOnlySetPersistentControllerData = void 0 ;
|
|
994
|
-
this.devOnlyGetPersistentControllerData = void 0 ;
|
|
995
|
-
this.isLit = isLit;
|
|
996
|
-
this.component.manager = this;
|
|
997
|
-
retrieveComponentMembers(component, isLit);
|
|
998
|
-
this._controllers = controllers;
|
|
999
|
-
this.exports = void 0;
|
|
1000
|
-
this.hasDestroy = "autoDestroyDisabled" in this.component && typeof this.component.destroy === "function";
|
|
1001
|
-
if (this.hasDestroy) {
|
|
1002
|
-
this.watch("autoDestroyDisabled", () => this._autoDestroyDisabledWatcher());
|
|
1003
|
-
}
|
|
1004
|
-
this._bindLifecycleMethods();
|
|
1005
|
-
if (!isLit) {
|
|
1006
|
-
Object.defineProperty(component, "updateComplete", {
|
|
1007
|
-
get: async () => await this._updatePromise.promise
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
const members = getPropLikeMembers(component);
|
|
1011
|
-
const internals = component.manager.internals;
|
|
1012
|
-
members.forEach((name) => {
|
|
1013
|
-
internals.accessorGetter[name] = defaultGetterSetter;
|
|
1014
|
-
internals.accessorSetter[name] = defaultGetterSetter;
|
|
1015
|
-
internals.getSetProxy(name, true, true);
|
|
1016
|
-
});
|
|
1017
|
-
Controller.internals.setParentController(void 0);
|
|
1018
|
-
Controller.internals.setAmbientComponent(component);
|
|
1019
|
-
Controller.internals.elementToInstance.set(component.el, component);
|
|
1020
|
-
Controller.internals.elementToInstance.set(component, component);
|
|
1021
|
-
}
|
|
1022
|
-
_bindLifecycleMethods() {
|
|
1023
|
-
const component = this.component;
|
|
1024
|
-
const isLit = this.isLit;
|
|
1025
|
-
this._originalLifecycles = {
|
|
1026
|
-
// These component's callbacks will be called by Lit, so we don't have to
|
|
1027
|
-
connectedCallback: isLit ? void 0 : component.connectedCallback,
|
|
1028
|
-
disconnectedCallback: isLit ? void 0 : component.disconnectedCallback,
|
|
1029
|
-
componentWillLoad: isLit ? void 0 : component.componentWillLoad,
|
|
1030
|
-
componentDidLoad: isLit ? void 0 : component.componentDidLoad,
|
|
1031
|
-
componentWillUpdate: isLit ? void 0 : component.componentWillUpdate,
|
|
1032
|
-
componentDidUpdate: isLit ? void 0 : component.componentDidUpdate,
|
|
1033
|
-
destroy: component.destroy
|
|
1034
|
-
};
|
|
1035
|
-
const hostConnected = this._connectedCallback.bind(this);
|
|
1036
|
-
const hostDisconnected = this._disconnectedCallback.bind(this);
|
|
1037
|
-
const hostUpdate = this._update.bind(this);
|
|
1038
|
-
const hostUpdated = this._updated.bind(this);
|
|
1039
|
-
if (isLit) {
|
|
1040
|
-
component.constructor.prototype.addController.call(component, {
|
|
1041
|
-
// Lit will call these callbacks
|
|
1042
|
-
hostConnected,
|
|
1043
|
-
hostDisconnected,
|
|
1044
|
-
hostUpdate,
|
|
1045
|
-
hostUpdated
|
|
1046
|
-
});
|
|
1047
|
-
} else {
|
|
1048
|
-
component.connectedCallback = hostConnected;
|
|
1049
|
-
component.disconnectedCallback = hostDisconnected;
|
|
1050
|
-
component.componentWillLoad = this._load.bind(this);
|
|
1051
|
-
component.componentDidLoad = this._loaded.bind(this);
|
|
1052
|
-
component.componentWillUpdate = hostUpdate;
|
|
1053
|
-
component.componentDidUpdate = hostUpdated;
|
|
1054
|
-
}
|
|
1055
|
-
if (this.hasDestroy) {
|
|
1056
|
-
component.destroy = this.destroy.bind(this);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Throws an error if component does not implement destroy() lifecycle, but
|
|
1061
|
-
* tries to use it.
|
|
1062
|
-
*/
|
|
1063
|
-
ensureHasDestroy() {
|
|
1064
|
-
if (!this.hasDestroy) {
|
|
1065
|
-
throw new Error(destroyErrorMessage);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Private because this is not supposed to be called by Component directly.
|
|
1070
|
-
* Instead, _bindLifecycleMethods will take care of that. Otherwise, you risk
|
|
1071
|
-
* calling lifecycle methods twice.
|
|
1072
|
-
*/
|
|
1073
|
-
_connectedCallback() {
|
|
1074
|
-
if (this.destroyed) {
|
|
1075
|
-
const tagName = this.component.el.tagName.toLowerCase();
|
|
1076
|
-
this.component.el.remove();
|
|
1077
|
-
throw new Error(
|
|
1078
|
-
`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.`
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
if (this._autoDestroyTimeout !== void 0) {
|
|
1082
|
-
clearTimeout(this._autoDestroyTimeout);
|
|
1083
|
-
}
|
|
1084
|
-
this.internals.enabledWatchers = this.internals.allWatchers;
|
|
1085
|
-
keyTrackResolve();
|
|
1086
|
-
this._controllers.forEach(
|
|
1087
|
-
(controller) => "triggerConnected" in controller ? controller.triggerConnected() : safeCall(controller.hostConnected, controller)
|
|
1088
|
-
);
|
|
1089
|
-
this._originalLifecycles.connectedCallback?.call(this.component);
|
|
1090
|
-
}
|
|
1091
|
-
_disconnectedCallback() {
|
|
1092
|
-
if (this.destroyed) {
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
this._controllers.forEach(
|
|
1096
|
-
(controller) => "triggerDisconnected" in controller ? controller.triggerDisconnected() : safeCall(controller.hostDisconnected, controller)
|
|
1097
|
-
);
|
|
1098
|
-
this._originalLifecycles.disconnectedCallback?.call(this.component);
|
|
1099
|
-
if (this.hasDestroy) {
|
|
1100
|
-
this._autoDestroyDisabledWatcher();
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
async _load() {
|
|
1104
|
-
const integrations = this.internals.reactiveUtilsIntegrations;
|
|
1105
|
-
if (integrations.size > 0) {
|
|
1106
|
-
for (const controller of integrations) {
|
|
1107
|
-
if ("triggerLoad" in controller) {
|
|
1108
|
-
await controller.triggerLoad();
|
|
1109
|
-
} else {
|
|
1110
|
-
await safeAsyncCall(controller.hostLoad, controller);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
await Promise.allSettled(
|
|
1115
|
-
Array.from(
|
|
1116
|
-
this._controllers,
|
|
1117
|
-
async (controller) => integrations.has(controller) ? void 0 : "triggerLoad" in controller ? await controller.triggerLoad() : await safeAsyncCall(controller.hostLoad, controller)
|
|
1118
|
-
)
|
|
1119
|
-
);
|
|
1120
|
-
await this._originalLifecycles.componentWillLoad?.call(this.component);
|
|
1121
|
-
}
|
|
1122
|
-
_loaded() {
|
|
1123
|
-
this._controllers.forEach(
|
|
1124
|
-
(controller) => "triggerLoaded" in controller ? controller.triggerLoaded() : safeCall(controller.hostLoaded, controller)
|
|
1125
|
-
);
|
|
1126
|
-
this._originalLifecycles.componentDidLoad?.call(this.component);
|
|
1127
|
-
}
|
|
1128
|
-
_update() {
|
|
1129
|
-
this._controllers.forEach(
|
|
1130
|
-
(controller) => "triggerUpdate" in controller ? controller.triggerUpdate() : safeCall(controller.hostUpdate, controller)
|
|
1131
|
-
);
|
|
1132
|
-
void this._originalLifecycles.componentWillUpdate?.call(this.component);
|
|
1133
|
-
}
|
|
1134
|
-
_updated() {
|
|
1135
|
-
this._controllers.forEach(
|
|
1136
|
-
(controller) => "triggerUpdated" in controller ? controller.triggerUpdated() : safeCall(controller.hostUpdated, controller)
|
|
1137
|
-
);
|
|
1138
|
-
this._originalLifecycles.componentDidUpdate?.call(this.component);
|
|
1139
|
-
if (!this.isLit) {
|
|
1140
|
-
const updatePromise = this._updatePromise;
|
|
1141
|
-
this._updatePromise = new Deferred();
|
|
1142
|
-
updatePromise.resolve(true);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
async destroy() {
|
|
1146
|
-
this.ensureHasDestroy();
|
|
1147
|
-
if (this.destroyed) {
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
if (this.component.el.isConnected) {
|
|
1151
|
-
this.hasDestroy = false;
|
|
1152
|
-
try {
|
|
1153
|
-
this.component.el.remove();
|
|
1154
|
-
} finally {
|
|
1155
|
-
this.hasDestroy = true;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
this._autoDestroyTimeout = void 0;
|
|
1159
|
-
this.destroyed = true;
|
|
1160
|
-
this._controllers.forEach(
|
|
1161
|
-
(controller) => "triggerDestroy" in controller ? controller.triggerDestroy() : safeCall(controller.hostDestroy, controller)
|
|
1162
|
-
);
|
|
1163
|
-
this._controllers.clear();
|
|
1164
|
-
await this._originalLifecycles.destroy?.call(this.component);
|
|
1165
|
-
}
|
|
1166
|
-
_autoDestroyDisabledWatcher() {
|
|
1167
|
-
if (!this.component.el.isConnected && !this.component.autoDestroyDisabled) {
|
|
1168
|
-
if (this._autoDestroyTimeout !== void 0) {
|
|
1169
|
-
clearTimeout(this._autoDestroyTimeout);
|
|
1170
|
-
}
|
|
1171
|
-
const destroy = () => void this.destroy().catch(console.error);
|
|
1172
|
-
{
|
|
1173
|
-
this._autoDestroyTimeout = devToolsAwareTimeout(destroy, autoDestroyOnDisconnectTimeout);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
// REFACTOR: replace this with a readonly:true option in @property()
|
|
1178
|
-
/**
|
|
1179
|
-
* Make a @Prop() or @State() readonly (prevent overwriting default value).
|
|
1180
|
-
*
|
|
1181
|
-
* For internal properties, prefer TypeScript's "readonly" modifier instead.
|
|
1182
|
-
*
|
|
1183
|
-
* @example
|
|
1184
|
-
* // Defining readonly prop
|
|
1185
|
-
* @Prop({ reflect: true }) prop = this.manager.readonly('a');
|
|
1186
|
-
*
|
|
1187
|
-
* @example
|
|
1188
|
-
* // Overwriting readonly prop internally
|
|
1189
|
-
* this.manager.bypassReadonly(()=>{
|
|
1190
|
-
* this.prop = 'b';
|
|
1191
|
-
* });
|
|
1192
|
-
*
|
|
1193
|
-
*/
|
|
1194
|
-
readonly(value) {
|
|
1195
|
-
return this.getSet(value, { set: this._readonlySetter });
|
|
1196
|
-
}
|
|
1197
|
-
// REFACTOR: remove this in Lit in favor of native get/set
|
|
1198
|
-
/**
|
|
1199
|
-
* Listen for any component's @State()/@Prop() change, and mutate it's
|
|
1200
|
-
* value before it is set.
|
|
1201
|
-
* This is necessary because Stencil's Compiler does not support get/set for
|
|
1202
|
-
* @State()/@Prop().
|
|
1203
|
-
* For private component properties, you should use regular get/set syntax.
|
|
1204
|
-
*
|
|
1205
|
-
* @example
|
|
1206
|
-
* @Prop() exampleProp = this.manager.getSet(defaultValue,{get,set})
|
|
1207
|
-
* @Prop() someProp = this.manager.getSet(
|
|
1208
|
-
* undefined as string | undefined,
|
|
1209
|
-
* {
|
|
1210
|
-
* get: (value)=>value.trim(),
|
|
1211
|
-
* set: (newValue,oldValue) => newValue.trim() ?? oldValue
|
|
1212
|
-
* }
|
|
1213
|
-
* )
|
|
1214
|
-
*
|
|
1215
|
-
* @remarks
|
|
1216
|
-
* Unlike a native get/set, the get function receives the current attribute
|
|
1217
|
-
* value, and can modify it before returning it (or can disregard the current
|
|
1218
|
-
* value and get it from elsewhere instead).
|
|
1219
|
-
* Similarly, setter is called with the new and old value, and is expected to
|
|
1220
|
-
* return the final new value (or return the old value to undo the change)
|
|
1221
|
-
*/
|
|
1222
|
-
getSet(defaultValue, getSet) {
|
|
1223
|
-
return this.component.manager.trackPropKey((name) => {
|
|
1224
|
-
var _a2;
|
|
1225
|
-
if (name === void 0) {
|
|
1226
|
-
throw new Error(
|
|
1227
|
-
"Unable to resolve get/set's prop name. Make sure you are using it like @Prop() someProp = this.manager.getSet(defaultValue,{get,set})"
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
if (getSet.set === this._readonlySetter) {
|
|
1231
|
-
(_a2 = this.internals).readonlyProps ?? (_a2.readonlyProps = /* @__PURE__ */ new Set());
|
|
1232
|
-
this.internals.readonlyProps.add(name);
|
|
1233
|
-
}
|
|
1234
|
-
const genericComponent = this.component;
|
|
1235
|
-
const value = genericComponent[name];
|
|
1236
|
-
const isStencilHotReload = "production" !== "production" ;
|
|
1237
|
-
const initialSet = getSet.initialSet ?? true;
|
|
1238
|
-
if (value != null && value !== defaultValue && typeof getSet.set === "function" && initialSet && !isStencilHotReload) {
|
|
1239
|
-
const newValue = getSet.set(value, defaultValue, name);
|
|
1240
|
-
if (newValue !== value) {
|
|
1241
|
-
if (this.isLit) {
|
|
1242
|
-
genericComponent[name] = newValue;
|
|
1243
|
-
} else {
|
|
1244
|
-
let firstConnected = true;
|
|
1245
|
-
this.onConnected(() => {
|
|
1246
|
-
if (!firstConnected) {
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1249
|
-
firstConnected = true;
|
|
1250
|
-
this.bypassSetter(() => {
|
|
1251
|
-
genericComponent[name] = newValue;
|
|
1252
|
-
});
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
this.genericGetSet(name, getSet);
|
|
1258
|
-
}, defaultValue);
|
|
1259
|
-
}
|
|
1260
|
-
};
|
|
1261
|
-
var destroyErrorMessage = `
|
|
1262
|
-
If the component uses a controller that uses destroy() method, then the
|
|
1263
|
-
component must have the following properties:
|
|
1264
|
-
${// Don't expose internal code in production, and keep bundle smaller:
|
|
1265
|
-
`autoDestroyDisabled and destroy` }
|
|
1266
|
-
`.trim();
|
|
1267
|
-
var autoDestroyOnDisconnectTimeout = 1e3;
|
|
1268
|
-
var defaultGetterSetter = (value) => value;
|
|
1269
|
-
|
|
1270
|
-
// src/proxyExports.ts
|
|
1271
|
-
var proxyExports = (Class) => (...args) => {
|
|
1272
|
-
const ambientControllers = Controller.internals.retrieveParentControllers();
|
|
1273
|
-
const instance = new Class(...args);
|
|
1274
|
-
const initialExports = instance.exports;
|
|
1275
|
-
Controller.internals.setParentController(ambientControllers.at(-1));
|
|
1276
|
-
const internals = instance.component.manager.internals;
|
|
1277
|
-
internals.markExports(instance, initialExports);
|
|
1278
|
-
instance.watchExports((exports) => internals.markExports(instance, exports));
|
|
1279
|
-
Controller.internals.setAmbientChildController(instance);
|
|
1280
|
-
const hostCandidates = [instance.component, ...ambientControllers].reverse();
|
|
1281
|
-
return internals.trackKey(
|
|
1282
|
-
hostCandidates,
|
|
1283
|
-
(resolution) => resolution === void 0 ? void 0 : setProxy(instance, resolution, initialExports),
|
|
1284
|
-
initialExports
|
|
1285
|
-
);
|
|
1286
|
-
};
|
|
1287
|
-
function setProxy(controller, { host, key, type }, initialExports) {
|
|
1288
|
-
const genericHost = host;
|
|
1289
|
-
const controllerValueChanged = genericHost[key] !== controller.exports;
|
|
1290
|
-
const hostValueChanged = genericHost[key] !== initialExports;
|
|
1291
|
-
const controllerUpdatedExports = initialExports !== controller.exports;
|
|
1292
|
-
if (controllerValueChanged && !hostValueChanged && controllerUpdatedExports) {
|
|
1293
|
-
genericHost[key] = controller.exports;
|
|
1294
|
-
}
|
|
1295
|
-
const isProxyExportsOnComponent = host === controller.component;
|
|
1296
|
-
if (isProxyExportsOnComponent && type === "prop") {
|
|
1297
|
-
const internals = controller.component.manager.internals;
|
|
1298
|
-
if (hostValueChanged) {
|
|
1299
|
-
internals.markExports(controller, genericHost[key]);
|
|
1300
|
-
}
|
|
1301
|
-
controller.component.manager.watch(key, (value) => {
|
|
1302
|
-
if (value !== controller.exports) {
|
|
1303
|
-
internals.markExports(controller, value);
|
|
1304
|
-
}
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
controller.watchExports(() => {
|
|
1308
|
-
if (genericHost[key] === controller.exports) {
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
const manager = controller.component.manager;
|
|
1312
|
-
const isReadOnly = manager.internals.readonlyProps?.has(key) === true;
|
|
1313
|
-
if (isReadOnly) {
|
|
1314
|
-
manager.bypassReadonly(() => {
|
|
1315
|
-
genericHost[key] = controller.exports;
|
|
1316
|
-
});
|
|
1317
|
-
} else {
|
|
1318
|
-
genericHost[key] = controller.exports;
|
|
1319
|
-
}
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
// src/functional.ts
|
|
1324
|
-
var makeController = (constructor) => proxy(void 0, constructor);
|
|
1325
|
-
var FunctionalController = class extends Controller {
|
|
1326
|
-
constructor(component, constructor) {
|
|
1327
|
-
super(component);
|
|
1328
|
-
const originalExports = this.exports;
|
|
1329
|
-
try {
|
|
1330
|
-
Controller.internals.setAmbientComponent(this.component);
|
|
1331
|
-
const value = constructor(this.component, this);
|
|
1332
|
-
const constructorChangedExports = this.exports !== originalExports;
|
|
1333
|
-
if (value instanceof Promise) {
|
|
1334
|
-
if (!constructorChangedExports) {
|
|
1335
|
-
this.setProvisionalExports(value);
|
|
1336
|
-
}
|
|
1337
|
-
const resolved = value.then((result) => {
|
|
1338
|
-
this.exports = result;
|
|
1339
|
-
super.catchUpLifecycle();
|
|
1340
|
-
}).catch((error) => {
|
|
1341
|
-
this._ready.reject(error);
|
|
1342
|
-
console.error(error);
|
|
1343
|
-
});
|
|
1344
|
-
this.onLoad(async () => await resolved);
|
|
1345
|
-
} else {
|
|
1346
|
-
if (!constructorChangedExports || value !== void 0) {
|
|
1347
|
-
this.exports = value;
|
|
1348
|
-
}
|
|
1349
|
-
queueMicrotask(() => super.catchUpLifecycle());
|
|
1350
|
-
}
|
|
1351
|
-
} catch (error) {
|
|
1352
|
-
this._ready.reject(error);
|
|
1353
|
-
console.error(error);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
/** Noop - will be called in the constructor instead */
|
|
1357
|
-
catchUpLifecycle() {
|
|
1358
|
-
return;
|
|
1359
|
-
}
|
|
1360
|
-
};
|
|
1361
|
-
var proxy = proxyExports(FunctionalController);
|
|
1362
|
-
|
|
1363
|
-
export { makeController as m, useControllerManager as u };
|