@rxdi/lit-html 0.7.157 → 0.7.158
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/async.d.ts +3 -3
- package/dist/async.js +4 -4
- package/dist/decorators/component.decorator.d.ts +1 -2
- package/dist/decorators/component.decorator.js +3 -3
- package/dist/index.d.ts +28 -17
- package/dist/index.js +28 -17
- package/package.json +4 -2
- package/dist/lit-element/decorators.d.ts +0 -14
- package/dist/lit-element/decorators.js +0 -32
- package/dist/lit-element/experimental-hydrate-support.d.ts +0 -6
- package/dist/lit-element/experimental-hydrate-support.js +0 -65
- package/dist/lit-element/index.d.ts +0 -7
- package/dist/lit-element/index.js +0 -25
- package/dist/lit-element/lit-element.d.ts +0 -157
- package/dist/lit-element/lit-element.js +0 -258
- package/dist/lit-element/polyfill-support.d.ts +0 -24
- package/dist/lit-element/polyfill-support.js +0 -58
- package/dist/lit-element/private-ssr-support.d.ts +0 -21
- package/dist/lit-element/private-ssr-support.js +0 -25
- package/dist/lit-html/async-directive.d.ts +0 -170
- package/dist/lit-html/async-directive.js +0 -250
- package/dist/lit-html/directive-helpers.d.ts +0 -105
- package/dist/lit-html/directive-helpers.js +0 -192
- package/dist/lit-html/directive.d.ts +0 -65
- package/dist/lit-html/directive.js +0 -52
- package/dist/lit-html/directives/async-append.d.ts +0 -38
- package/dist/lit-html/directives/async-append.js +0 -55
- package/dist/lit-html/directives/async-replace.d.ts +0 -39
- package/dist/lit-html/directives/async-replace.js +0 -112
- package/dist/lit-html/directives/cache.d.ts +0 -34
- package/dist/lit-html/directives/cache.js +0 -80
- package/dist/lit-html/directives/class-map.d.ts +0 -44
- package/dist/lit-html/directives/class-map.js +0 -92
- package/dist/lit-html/directives/guard.d.ts +0 -59
- package/dist/lit-html/directives/guard.js +0 -82
- package/dist/lit-html/directives/if-defined.d.ts +0 -13
- package/dist/lit-html/directives/if-defined.js +0 -17
- package/dist/lit-html/directives/live.d.ts +0 -42
- package/dist/lit-html/directives/live.js +0 -79
- package/dist/lit-html/directives/private-async-helpers.d.ts +0 -57
- package/dist/lit-html/directives/private-async-helpers.js +0 -117
- package/dist/lit-html/directives/ref.d.ts +0 -65
- package/dist/lit-html/directives/ref.js +0 -113
- package/dist/lit-html/directives/repeat.d.ts +0 -63
- package/dist/lit-html/directives/repeat.js +0 -416
- package/dist/lit-html/directives/style-map.d.ts +0 -46
- package/dist/lit-html/directives/style-map.js +0 -102
- package/dist/lit-html/directives/template-content.d.ts +0 -25
- package/dist/lit-html/directives/template-content.js +0 -33
- package/dist/lit-html/directives/unsafe-html.d.ts +0 -26
- package/dist/lit-html/directives/unsafe-html.js +0 -64
- package/dist/lit-html/directives/unsafe-svg.d.ts +0 -26
- package/dist/lit-html/directives/unsafe-svg.js +0 -26
- package/dist/lit-html/directives/until.d.ts +0 -43
- package/dist/lit-html/directives/until.js +0 -137
- package/dist/lit-html/experimental-hydrate.d.ts +0 -50
- package/dist/lit-html/experimental-hydrate.js +0 -322
- package/dist/lit-html/lit-html.d.ts +0 -335
- package/dist/lit-html/lit-html.js +0 -1259
- package/dist/lit-html/polyfill-support.d.ts +0 -67
- package/dist/lit-html/polyfill-support.js +0 -185
- package/dist/lit-html/private-ssr-support.d.ts +0 -52
- package/dist/lit-html/private-ssr-support.js +0 -54
- package/dist/lit-html/static.d.ts +0 -58
- package/dist/lit-html/static.js +0 -114
- package/dist/reactive-element/css-tag.d.ts +0 -64
- package/dist/reactive-element/css-tag.js +0 -125
- package/dist/reactive-element/decorators/base.d.ts +0 -47
- package/dist/reactive-element/decorators/base.js +0 -70
- package/dist/reactive-element/decorators/custom-element.d.ts +0 -26
- package/dist/reactive-element/decorators/custom-element.js +0 -47
- package/dist/reactive-element/decorators/event-options.d.ts +0 -37
- package/dist/reactive-element/decorators/event-options.js +0 -47
- package/dist/reactive-element/decorators/index.d.ts +0 -14
- package/dist/reactive-element/decorators/index.js +0 -32
- package/dist/reactive-element/decorators/property.d.ts +0 -40
- package/dist/reactive-element/decorators/property.js +0 -92
- package/dist/reactive-element/decorators/query-all.d.ts +0 -31
- package/dist/reactive-element/decorators/query-all.js +0 -46
- package/dist/reactive-element/decorators/query-assigned-nodes.d.ts +0 -33
- package/dist/reactive-element/decorators/query-assigned-nodes.js +0 -55
- package/dist/reactive-element/decorators/query-async.d.ts +0 -39
- package/dist/reactive-element/decorators/query-async.js +0 -71
- package/dist/reactive-element/decorators/query.d.ts +0 -32
- package/dist/reactive-element/decorators/query.js +0 -60
- package/dist/reactive-element/decorators/state.d.ts +0 -24
- package/dist/reactive-element/decorators/state.js +0 -29
- package/dist/reactive-element/index.d.ts +0 -5
- package/dist/reactive-element/index.js +0 -17
- package/dist/reactive-element/polyfill-support.d.ts +0 -40
- package/dist/reactive-element/polyfill-support.js +0 -89
- package/dist/reactive-element/reactive-controller.d.ts +0 -76
- package/dist/reactive-element/reactive-controller.js +0 -7
- package/dist/reactive-element/reactive-element.d.ts +0 -653
- package/dist/reactive-element/reactive-element.js +0 -979
|
@@ -1,979 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @license
|
|
4
|
-
* Copyright 2017 Google LLC
|
|
5
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var _a, _b, _c, _d;
|
|
27
|
-
var _e;
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ReactiveElement = exports.notEqual = exports.defaultConverter = void 0;
|
|
30
|
-
/**
|
|
31
|
-
* Use this module if you want to create your own base class extending
|
|
32
|
-
* [[ReactiveElement]].
|
|
33
|
-
* @packageDocumentation
|
|
34
|
-
*/
|
|
35
|
-
const css_tag_1 = require("./css-tag");
|
|
36
|
-
__exportStar(require("./css-tag"), exports);
|
|
37
|
-
const DEV_MODE = true;
|
|
38
|
-
let requestUpdateThenable;
|
|
39
|
-
let issueWarning;
|
|
40
|
-
if (DEV_MODE) {
|
|
41
|
-
// Ensure warnings are issued only 1x, even if multiple versions of Lit
|
|
42
|
-
// are loaded.
|
|
43
|
-
const issuedWarnings = ((_a = globalThis.litIssuedWarnings) !== null && _a !== void 0 ? _a : (globalThis.litIssuedWarnings = new Set()));
|
|
44
|
-
// Issue a warning, if we haven't already.
|
|
45
|
-
issueWarning = (code, warning) => {
|
|
46
|
-
warning += ` See https://lit.dev/msg/${code} for more information.`;
|
|
47
|
-
if (!issuedWarnings.has(warning)) {
|
|
48
|
-
console.warn(warning);
|
|
49
|
-
issuedWarnings.add(warning);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
issueWarning('dev-mode', `Lit is in dev mode. Not recommended for production!`);
|
|
53
|
-
// Issue polyfill support warning.
|
|
54
|
-
if (((_b = window.ShadyDOM) === null || _b === void 0 ? void 0 : _b.inUse) &&
|
|
55
|
-
globalThis[`reactiveElementPolyfillSupport${DEV_MODE ? `DevMode` : ``}`] ===
|
|
56
|
-
undefined) {
|
|
57
|
-
issueWarning('polyfill-support-missing', `Shadow DOM is being polyfilled via \`ShadyDOM\` but ` +
|
|
58
|
-
`the \`polyfill-support\` module has not been loaded.`);
|
|
59
|
-
}
|
|
60
|
-
requestUpdateThenable = (name) => ({
|
|
61
|
-
then: (onfulfilled, _onrejected) => {
|
|
62
|
-
issueWarning('request-update-promise', `The \`requestUpdate\` method should no longer return a Promise but ` +
|
|
63
|
-
`does so on \`${name}\`. Use \`updateComplete\` instead.`);
|
|
64
|
-
if (onfulfilled !== undefined) {
|
|
65
|
-
onfulfilled(false);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/*
|
|
71
|
-
* When using Closure Compiler, JSCompiler_renameProperty(property, object) is
|
|
72
|
-
* replaced at compile time by the munged name for object[property]. We cannot
|
|
73
|
-
* alias this function, so we have to use a small shim that has the same
|
|
74
|
-
* behavior when not compiling.
|
|
75
|
-
*/
|
|
76
|
-
/*@__INLINE__*/
|
|
77
|
-
const JSCompiler_renameProperty = (prop, _obj) => prop;
|
|
78
|
-
exports.defaultConverter = {
|
|
79
|
-
toAttribute(value, type) {
|
|
80
|
-
switch (type) {
|
|
81
|
-
case Boolean:
|
|
82
|
-
value = value ? '' : null;
|
|
83
|
-
break;
|
|
84
|
-
case Object:
|
|
85
|
-
case Array:
|
|
86
|
-
// if the value is `null` or `undefined` pass this through
|
|
87
|
-
// to allow removing/no change behavior.
|
|
88
|
-
value = value == null ? value : JSON.stringify(value);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
return value;
|
|
92
|
-
},
|
|
93
|
-
fromAttribute(value, type) {
|
|
94
|
-
let fromValue = value;
|
|
95
|
-
switch (type) {
|
|
96
|
-
case Boolean:
|
|
97
|
-
fromValue = value !== null;
|
|
98
|
-
break;
|
|
99
|
-
case Number:
|
|
100
|
-
fromValue = value === null ? null : Number(value);
|
|
101
|
-
break;
|
|
102
|
-
case Object:
|
|
103
|
-
case Array:
|
|
104
|
-
// Do *not* generate exception when invalid JSON is set as elements
|
|
105
|
-
// don't normally complain on being mis-configured.
|
|
106
|
-
// TODO(sorvell): Do generate exception in *dev mode*.
|
|
107
|
-
try {
|
|
108
|
-
// Assert to adhere to Bazel's "must type assert JSON parse" rule.
|
|
109
|
-
fromValue = JSON.parse(value);
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
fromValue = null;
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
return fromValue;
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Change function that returns true if `value` is different from `oldValue`.
|
|
121
|
-
* This method is used as the default for a property's `hasChanged` function.
|
|
122
|
-
*/
|
|
123
|
-
const notEqual = (value, old) => {
|
|
124
|
-
// This ensures (old==NaN, value==NaN) always returns false
|
|
125
|
-
return old !== value && (old === old || value === value);
|
|
126
|
-
};
|
|
127
|
-
exports.notEqual = notEqual;
|
|
128
|
-
const defaultPropertyDeclaration = {
|
|
129
|
-
attribute: true,
|
|
130
|
-
type: String,
|
|
131
|
-
converter: exports.defaultConverter,
|
|
132
|
-
reflect: false,
|
|
133
|
-
hasChanged: exports.notEqual,
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* The Closure JS Compiler doesn't currently have good support for static
|
|
137
|
-
* property semantics where "this" is dynamic (e.g.
|
|
138
|
-
* https://github.com/google/closure-compiler/issues/3177 and others) so we use
|
|
139
|
-
* this hack to bypass any rewriting by the compiler.
|
|
140
|
-
*/
|
|
141
|
-
const finalized = 'finalized';
|
|
142
|
-
/**
|
|
143
|
-
* Base element class which manages element properties and attributes. When
|
|
144
|
-
* properties change, the `update` method is asynchronously called. This method
|
|
145
|
-
* should be supplied by subclassers to render updates as desired.
|
|
146
|
-
* @noInheritDoc
|
|
147
|
-
*/
|
|
148
|
-
class ReactiveElement extends HTMLElement {
|
|
149
|
-
constructor() {
|
|
150
|
-
super();
|
|
151
|
-
this.__instanceProperties = new Map();
|
|
152
|
-
/**
|
|
153
|
-
* True if there is a pending update as a result of calling `requestUpdate()`.
|
|
154
|
-
* Should only be read.
|
|
155
|
-
* @category updates
|
|
156
|
-
*/
|
|
157
|
-
this.isUpdatePending = false;
|
|
158
|
-
/**
|
|
159
|
-
* Is set to `true` after the first update. The element code cannot assume
|
|
160
|
-
* that `renderRoot` exists before the element `hasUpdated`.
|
|
161
|
-
* @category updates
|
|
162
|
-
*/
|
|
163
|
-
this.hasUpdated = false;
|
|
164
|
-
/**
|
|
165
|
-
* Name of currently reflecting property
|
|
166
|
-
*/
|
|
167
|
-
this.__reflectingProperty = null;
|
|
168
|
-
this._initialize();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Adds an initializer function to the class that is called during instance
|
|
172
|
-
* construction.
|
|
173
|
-
*
|
|
174
|
-
* This is useful for code that runs against a `ReactiveElement`
|
|
175
|
-
* subclass, such as a decorator, that needs to do work for each
|
|
176
|
-
* instance, such as setting up a `ReactiveController`.
|
|
177
|
-
*
|
|
178
|
-
* ```ts
|
|
179
|
-
* const myDecorator = (target: typeof ReactiveElement, key: string) => {
|
|
180
|
-
* target.addInitializer((instance: ReactiveElement) => {
|
|
181
|
-
* // This is run during construction of the element
|
|
182
|
-
* new MyController(instance);
|
|
183
|
-
* });
|
|
184
|
-
* }
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* Decorating a field will then cause each instance to run an initializer
|
|
188
|
-
* that adds a controller:
|
|
189
|
-
*
|
|
190
|
-
* ```ts
|
|
191
|
-
* class MyElement extends LitElement {
|
|
192
|
-
* @myDecorator foo;
|
|
193
|
-
* }
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* Initializers are stored per-constructor. Adding an initializer to a
|
|
197
|
-
* subclass does not add it to a superclass. Since initializers are run in
|
|
198
|
-
* constructors, initializers will run in order of the class hierarchy,
|
|
199
|
-
* starting with superclasses and progressing to the instance's class.
|
|
200
|
-
*
|
|
201
|
-
* @nocollapse
|
|
202
|
-
*/
|
|
203
|
-
static addInitializer(initializer) {
|
|
204
|
-
var _a;
|
|
205
|
-
(_a = this._initializers) !== null && _a !== void 0 ? _a : (this._initializers = []);
|
|
206
|
-
this._initializers.push(initializer);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Returns a list of attributes corresponding to the registered properties.
|
|
210
|
-
* @nocollapse
|
|
211
|
-
* @category attributes
|
|
212
|
-
*/
|
|
213
|
-
static get observedAttributes() {
|
|
214
|
-
// note: piggy backing on this to ensure we're finalized.
|
|
215
|
-
this.finalize();
|
|
216
|
-
const attributes = [];
|
|
217
|
-
// Use forEach so this works even if for/of loops are compiled to for loops
|
|
218
|
-
// expecting arrays
|
|
219
|
-
this.elementProperties.forEach((v, p) => {
|
|
220
|
-
const attr = this.__attributeNameForProperty(p, v);
|
|
221
|
-
if (attr !== undefined) {
|
|
222
|
-
this.__attributeToPropertyMap.set(attr, p);
|
|
223
|
-
attributes.push(attr);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
return attributes;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Creates a property accessor on the element prototype if one does not exist
|
|
230
|
-
* and stores a `PropertyDeclaration` for the property with the given options.
|
|
231
|
-
* The property setter calls the property's `hasChanged` property option
|
|
232
|
-
* or uses a strict identity check to determine whether or not to request
|
|
233
|
-
* an update.
|
|
234
|
-
*
|
|
235
|
-
* This method may be overridden to customize properties; however,
|
|
236
|
-
* when doing so, it's important to call `super.createProperty` to ensure
|
|
237
|
-
* the property is setup correctly. This method calls
|
|
238
|
-
* `getPropertyDescriptor` internally to get a descriptor to install.
|
|
239
|
-
* To customize what properties do when they are get or set, override
|
|
240
|
-
* `getPropertyDescriptor`. To customize the options for a property,
|
|
241
|
-
* implement `createProperty` like this:
|
|
242
|
-
*
|
|
243
|
-
* ```ts
|
|
244
|
-
* static createProperty(name, options) {
|
|
245
|
-
* options = Object.assign(options, {myOption: true});
|
|
246
|
-
* super.createProperty(name, options);
|
|
247
|
-
* }
|
|
248
|
-
* ```
|
|
249
|
-
*
|
|
250
|
-
* @nocollapse
|
|
251
|
-
* @category properties
|
|
252
|
-
*/
|
|
253
|
-
static createProperty(name, options = defaultPropertyDeclaration) {
|
|
254
|
-
// if this is a state property, force the attribute to false.
|
|
255
|
-
if (options.state) {
|
|
256
|
-
// Cast as any since this is readonly.
|
|
257
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
-
options.attribute = false;
|
|
259
|
-
}
|
|
260
|
-
// Note, since this can be called by the `@property` decorator which
|
|
261
|
-
// is called before `finalize`, we ensure finalization has been kicked off.
|
|
262
|
-
this.finalize();
|
|
263
|
-
this.elementProperties.set(name, options);
|
|
264
|
-
// Do not generate an accessor if the prototype already has one, since
|
|
265
|
-
// it would be lost otherwise and that would never be the user's intention;
|
|
266
|
-
// Instead, we expect users to call `requestUpdate` themselves from
|
|
267
|
-
// user-defined accessors. Note that if the super has an accessor we will
|
|
268
|
-
// still overwrite it
|
|
269
|
-
if (!options.noAccessor && !this.prototype.hasOwnProperty(name)) {
|
|
270
|
-
const key = typeof name === 'symbol' ? Symbol() : `__${name}`;
|
|
271
|
-
const descriptor = this.getPropertyDescriptor(name, key, options);
|
|
272
|
-
if (descriptor !== undefined) {
|
|
273
|
-
Object.defineProperty(this.prototype, name, descriptor);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Returns a property descriptor to be defined on the given named property.
|
|
279
|
-
* If no descriptor is returned, the property will not become an accessor.
|
|
280
|
-
* For example,
|
|
281
|
-
*
|
|
282
|
-
* ```ts
|
|
283
|
-
* class MyElement extends LitElement {
|
|
284
|
-
* static getPropertyDescriptor(name, key, options) {
|
|
285
|
-
* const defaultDescriptor =
|
|
286
|
-
* super.getPropertyDescriptor(name, key, options);
|
|
287
|
-
* const setter = defaultDescriptor.set;
|
|
288
|
-
* return {
|
|
289
|
-
* get: defaultDescriptor.get,
|
|
290
|
-
* set(value) {
|
|
291
|
-
* setter.call(this, value);
|
|
292
|
-
* // custom action.
|
|
293
|
-
* },
|
|
294
|
-
* configurable: true,
|
|
295
|
-
* enumerable: true
|
|
296
|
-
* }
|
|
297
|
-
* }
|
|
298
|
-
* }
|
|
299
|
-
* ```
|
|
300
|
-
*
|
|
301
|
-
* @nocollapse
|
|
302
|
-
* @category properties
|
|
303
|
-
*/
|
|
304
|
-
static getPropertyDescriptor(name, key, options) {
|
|
305
|
-
return {
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
|
-
get() {
|
|
308
|
-
return this[key];
|
|
309
|
-
},
|
|
310
|
-
set(value) {
|
|
311
|
-
const oldValue = this[name];
|
|
312
|
-
this[key] = value;
|
|
313
|
-
this.requestUpdate(name, oldValue, options);
|
|
314
|
-
},
|
|
315
|
-
configurable: true,
|
|
316
|
-
enumerable: true,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Returns the property options associated with the given property.
|
|
321
|
-
* These options are defined with a `PropertyDeclaration` via the `properties`
|
|
322
|
-
* object or the `@property` decorator and are registered in
|
|
323
|
-
* `createProperty(...)`.
|
|
324
|
-
*
|
|
325
|
-
* Note, this method should be considered "final" and not overridden. To
|
|
326
|
-
* customize the options for a given property, override [[`createProperty`]].
|
|
327
|
-
*
|
|
328
|
-
* @nocollapse
|
|
329
|
-
* @final
|
|
330
|
-
* @category properties
|
|
331
|
-
*/
|
|
332
|
-
static getPropertyOptions(name) {
|
|
333
|
-
return this.elementProperties.get(name) || defaultPropertyDeclaration;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Creates property accessors for registered properties, sets up element
|
|
337
|
-
* styling, and ensures any superclasses are also finalized. Returns true if
|
|
338
|
-
* the element was finalized.
|
|
339
|
-
* @nocollapse
|
|
340
|
-
*/
|
|
341
|
-
static finalize() {
|
|
342
|
-
if (this.hasOwnProperty(finalized)) {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
this[finalized] = true;
|
|
346
|
-
// finalize any superclasses
|
|
347
|
-
const superCtor = Object.getPrototypeOf(this);
|
|
348
|
-
superCtor.finalize();
|
|
349
|
-
this.elementProperties = new Map(superCtor.elementProperties);
|
|
350
|
-
// initialize Map populated in observedAttributes
|
|
351
|
-
this.__attributeToPropertyMap = new Map();
|
|
352
|
-
// make any properties
|
|
353
|
-
// Note, only process "own" properties since this element will inherit
|
|
354
|
-
// any properties defined on the superClass, and finalization ensures
|
|
355
|
-
// the entire prototype chain is finalized.
|
|
356
|
-
if (this.hasOwnProperty(JSCompiler_renameProperty('properties', this))) {
|
|
357
|
-
const props = this.properties;
|
|
358
|
-
// support symbols in properties (IE11 does not support this)
|
|
359
|
-
const propKeys = [
|
|
360
|
-
...Object.getOwnPropertyNames(props),
|
|
361
|
-
...Object.getOwnPropertySymbols(props),
|
|
362
|
-
];
|
|
363
|
-
// This for/of is ok because propKeys is an array
|
|
364
|
-
for (const p of propKeys) {
|
|
365
|
-
// note, use of `any` is due to TypeScript lack of support for symbol in
|
|
366
|
-
// index types
|
|
367
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
|
-
this.createProperty(p, props[p]);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
this.elementStyles = this.finalizeStyles(this.styles);
|
|
372
|
-
// DEV mode warnings
|
|
373
|
-
if (DEV_MODE) {
|
|
374
|
-
const warnRemovedOrRenamed = (name, renamed = false) => {
|
|
375
|
-
if (this.prototype.hasOwnProperty(name)) {
|
|
376
|
-
issueWarning(renamed ? 'renamed-api' : 'removed-api', `\`${name}\` is implemented on class ${this.name}. It ` +
|
|
377
|
-
`has been ${renamed ? 'renamed' : 'removed'} ` +
|
|
378
|
-
`in this version of LitElement.`);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
warnRemovedOrRenamed('initialize');
|
|
382
|
-
warnRemovedOrRenamed('requestUpdateInternal');
|
|
383
|
-
warnRemovedOrRenamed('_getUpdateComplete', true);
|
|
384
|
-
}
|
|
385
|
-
return true;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Takes the styles the user supplied via the `static styles` property and
|
|
389
|
-
* returns the array of styles to apply to the element.
|
|
390
|
-
* Override this method to integrate into a style management system.
|
|
391
|
-
*
|
|
392
|
-
* Styles are deduplicated preserving the _last_ instance in the list. This
|
|
393
|
-
* is a performance optimization to avoid duplicated styles that can occur
|
|
394
|
-
* especially when composing via subclassing. The last item is kept to try
|
|
395
|
-
* to preserve the cascade order with the assumption that it's most important
|
|
396
|
-
* that last added styles override previous styles.
|
|
397
|
-
*
|
|
398
|
-
* @nocollapse
|
|
399
|
-
* @category styles
|
|
400
|
-
*/
|
|
401
|
-
static finalizeStyles(styles) {
|
|
402
|
-
const elementStyles = [];
|
|
403
|
-
if (Array.isArray(styles)) {
|
|
404
|
-
// Dedupe the flattened array in reverse order to preserve the last items.
|
|
405
|
-
// Casting to Array<unknown> works around TS error that
|
|
406
|
-
// appears to come from trying to flatten a type CSSResultArray.
|
|
407
|
-
const set = new Set(styles.flat(Infinity).reverse());
|
|
408
|
-
// Then preserve original order by adding the set items in reverse order.
|
|
409
|
-
for (const s of set) {
|
|
410
|
-
elementStyles.unshift((0, css_tag_1.getCompatibleStyle)(s));
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
else if (styles !== undefined) {
|
|
414
|
-
elementStyles.push((0, css_tag_1.getCompatibleStyle)(styles));
|
|
415
|
-
}
|
|
416
|
-
return elementStyles;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Returns the property name for the given attribute `name`.
|
|
420
|
-
* @nocollapse
|
|
421
|
-
*/
|
|
422
|
-
static __attributeNameForProperty(name, options) {
|
|
423
|
-
const attribute = options.attribute;
|
|
424
|
-
return attribute === false
|
|
425
|
-
? undefined
|
|
426
|
-
: typeof attribute === 'string'
|
|
427
|
-
? attribute
|
|
428
|
-
: typeof name === 'string'
|
|
429
|
-
? name.toLowerCase()
|
|
430
|
-
: undefined;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Internal only override point for customizing work done when elements
|
|
434
|
-
* are constructed.
|
|
435
|
-
*
|
|
436
|
-
* @internal
|
|
437
|
-
*/
|
|
438
|
-
_initialize() {
|
|
439
|
-
var _a;
|
|
440
|
-
this.__updatePromise = new Promise((res) => (this.enableUpdating = res));
|
|
441
|
-
this._$changedProperties = new Map();
|
|
442
|
-
this.__saveInstanceProperties();
|
|
443
|
-
// ensures first update will be caught by an early access of
|
|
444
|
-
// `updateComplete`
|
|
445
|
-
this.requestUpdate();
|
|
446
|
-
(_a = this.constructor._initializers) === null || _a === void 0 ? void 0 : _a.forEach((i) => i(this));
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Registers a `ReactiveController` to participate in the element's reactive
|
|
450
|
-
* update cycle. The element automatically calls into any registered
|
|
451
|
-
* controllers during its lifecycle callbacks.
|
|
452
|
-
*
|
|
453
|
-
* If the element is connected when `addController()` is called, the
|
|
454
|
-
* controller's `hostConnected()` callback will be immediately called.
|
|
455
|
-
* @category controllers
|
|
456
|
-
*/
|
|
457
|
-
addController(controller) {
|
|
458
|
-
var _a, _b;
|
|
459
|
-
((_a = this.__controllers) !== null && _a !== void 0 ? _a : (this.__controllers = [])).push(controller);
|
|
460
|
-
// If a controller is added after the element has been connected,
|
|
461
|
-
// call hostConnected. Note, re-using existence of `renderRoot` here
|
|
462
|
-
// (which is set in connectedCallback) to avoid the need to track a
|
|
463
|
-
// first connected state.
|
|
464
|
-
if (this.renderRoot !== undefined && this.isConnected) {
|
|
465
|
-
(_b = controller.hostConnected) === null || _b === void 0 ? void 0 : _b.call(controller);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Removes a `ReactiveController` from the element.
|
|
470
|
-
* @category controllers
|
|
471
|
-
*/
|
|
472
|
-
removeController(controller) {
|
|
473
|
-
var _a;
|
|
474
|
-
// Note, if the indexOf is -1, the >>> will flip the sign which makes the
|
|
475
|
-
// splice do nothing.
|
|
476
|
-
(_a = this.__controllers) === null || _a === void 0 ? void 0 : _a.splice(this.__controllers.indexOf(controller) >>> 0, 1);
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Fixes any properties set on the instance before upgrade time.
|
|
480
|
-
* Otherwise these would shadow the accessor and break these properties.
|
|
481
|
-
* The properties are stored in a Map which is played back after the
|
|
482
|
-
* constructor runs. Note, on very old versions of Safari (<=9) or Chrome
|
|
483
|
-
* (<=41), properties created for native platform properties like (`id` or
|
|
484
|
-
* `name`) may not have default values set in the element constructor. On
|
|
485
|
-
* these browsers native properties appear on instances and therefore their
|
|
486
|
-
* default value will overwrite any element default (e.g. if the element sets
|
|
487
|
-
* this.id = 'id' in the constructor, the 'id' will become '' since this is
|
|
488
|
-
* the native platform default).
|
|
489
|
-
*/
|
|
490
|
-
__saveInstanceProperties() {
|
|
491
|
-
// Use forEach so this works even if for/of loops are compiled to for loops
|
|
492
|
-
// expecting arrays
|
|
493
|
-
this.constructor.elementProperties.forEach((_v, p) => {
|
|
494
|
-
if (this.hasOwnProperty(p)) {
|
|
495
|
-
this.__instanceProperties.set(p, this[p]);
|
|
496
|
-
delete this[p];
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Returns the node into which the element should render and by default
|
|
502
|
-
* creates and returns an open shadowRoot. Implement to customize where the
|
|
503
|
-
* element's DOM is rendered. For example, to render into the element's
|
|
504
|
-
* childNodes, return `this`.
|
|
505
|
-
*
|
|
506
|
-
* @return Returns a node into which to render.
|
|
507
|
-
* @category rendering
|
|
508
|
-
*/
|
|
509
|
-
createRenderRoot() {
|
|
510
|
-
var _a;
|
|
511
|
-
const renderRoot = (_a = this.shadowRoot) !== null && _a !== void 0 ? _a : this.attachShadow(this.constructor.shadowRootOptions);
|
|
512
|
-
(0, css_tag_1.adoptStyles)(renderRoot, this.constructor.elementStyles);
|
|
513
|
-
return renderRoot;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* On first connection, creates the element's renderRoot, sets up
|
|
517
|
-
* element styling, and enables updating.
|
|
518
|
-
* @category lifecycle
|
|
519
|
-
*/
|
|
520
|
-
connectedCallback() {
|
|
521
|
-
var _a;
|
|
522
|
-
// create renderRoot before first update.
|
|
523
|
-
if (this.renderRoot === undefined) {
|
|
524
|
-
this.renderRoot = this.createRenderRoot();
|
|
525
|
-
}
|
|
526
|
-
this.enableUpdating(true);
|
|
527
|
-
(_a = this.__controllers) === null || _a === void 0 ? void 0 : _a.forEach((c) => { var _a; return (_a = c.hostConnected) === null || _a === void 0 ? void 0 : _a.call(c); });
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Note, this method should be considered final and not overridden. It is
|
|
531
|
-
* overridden on the element instance with a function that triggers the first
|
|
532
|
-
* update.
|
|
533
|
-
* @category updates
|
|
534
|
-
*/
|
|
535
|
-
enableUpdating(_requestedUpdate) { }
|
|
536
|
-
/**
|
|
537
|
-
* Allows for `super.disconnectedCallback()` in extensions while
|
|
538
|
-
* reserving the possibility of making non-breaking feature additions
|
|
539
|
-
* when disconnecting at some point in the future.
|
|
540
|
-
* @category lifecycle
|
|
541
|
-
*/
|
|
542
|
-
disconnectedCallback() {
|
|
543
|
-
var _a;
|
|
544
|
-
(_a = this.__controllers) === null || _a === void 0 ? void 0 : _a.forEach((c) => { var _a; return (_a = c.hostDisconnected) === null || _a === void 0 ? void 0 : _a.call(c); });
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Synchronizes property values when attributes change.
|
|
548
|
-
* @category attributes
|
|
549
|
-
*/
|
|
550
|
-
attributeChangedCallback(name, _old, value) {
|
|
551
|
-
this._$attributeToProperty(name, value);
|
|
552
|
-
}
|
|
553
|
-
__propertyToAttribute(name, value, options = defaultPropertyDeclaration) {
|
|
554
|
-
var _a, _b;
|
|
555
|
-
const attr = this.constructor.__attributeNameForProperty(name, options);
|
|
556
|
-
if (attr !== undefined && options.reflect === true) {
|
|
557
|
-
const toAttribute = (_b = (_a = options.converter) === null || _a === void 0 ? void 0 : _a.toAttribute) !== null && _b !== void 0 ? _b : exports.defaultConverter.toAttribute;
|
|
558
|
-
const attrValue = toAttribute(value, options.type);
|
|
559
|
-
if (DEV_MODE &&
|
|
560
|
-
this.constructor.enabledWarnings.indexOf('migration') >= 0 &&
|
|
561
|
-
attrValue === undefined) {
|
|
562
|
-
issueWarning('undefined-attribute-value', `The attribute value for the ${name} property is ` +
|
|
563
|
-
`undefined on element ${this.localName}. The attribute will be ` +
|
|
564
|
-
`removed, but in the previous version of \`ReactiveElement\`, ` +
|
|
565
|
-
`the attribute would not have changed.`);
|
|
566
|
-
}
|
|
567
|
-
// Track if the property is being reflected to avoid
|
|
568
|
-
// setting the property again via `attributeChangedCallback`. Note:
|
|
569
|
-
// 1. this takes advantage of the fact that the callback is synchronous.
|
|
570
|
-
// 2. will behave incorrectly if multiple attributes are in the reaction
|
|
571
|
-
// stack at time of calling. However, since we process attributes
|
|
572
|
-
// in `update` this should not be possible (or an extreme corner case
|
|
573
|
-
// that we'd like to discover).
|
|
574
|
-
// mark state reflecting
|
|
575
|
-
this.__reflectingProperty = name;
|
|
576
|
-
if (attrValue == null) {
|
|
577
|
-
this.removeAttribute(attr);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
this.setAttribute(attr, attrValue);
|
|
581
|
-
}
|
|
582
|
-
// mark state not reflecting
|
|
583
|
-
this.__reflectingProperty = null;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
/** @internal */
|
|
587
|
-
_$attributeToProperty(name, value) {
|
|
588
|
-
var _a, _b, _c;
|
|
589
|
-
const ctor = this.constructor;
|
|
590
|
-
// Note, hint this as an `AttributeMap` so closure clearly understands
|
|
591
|
-
// the type; it has issues with tracking types through statics
|
|
592
|
-
const propName = ctor.__attributeToPropertyMap.get(name);
|
|
593
|
-
// Use tracking info to avoid reflecting a property value to an attribute
|
|
594
|
-
// if it was just set because the attribute changed.
|
|
595
|
-
if (propName !== undefined && this.__reflectingProperty !== propName) {
|
|
596
|
-
const options = ctor.getPropertyOptions(propName);
|
|
597
|
-
const converter = options.converter;
|
|
598
|
-
const fromAttribute = (_c = (_b = (_a = converter) === null || _a === void 0 ? void 0 : _a.fromAttribute) !== null && _b !== void 0 ? _b : (typeof converter === 'function'
|
|
599
|
-
? converter
|
|
600
|
-
: null)) !== null && _c !== void 0 ? _c : exports.defaultConverter.fromAttribute;
|
|
601
|
-
// mark state reflecting
|
|
602
|
-
this.__reflectingProperty = propName;
|
|
603
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
604
|
-
this[propName] = fromAttribute(value, options.type);
|
|
605
|
-
// mark state not reflecting
|
|
606
|
-
this.__reflectingProperty = null;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Requests an update which is processed asynchronously. This should be called
|
|
611
|
-
* when an element should update based on some state not triggered by setting
|
|
612
|
-
* a reactive property. In this case, pass no arguments. It should also be
|
|
613
|
-
* called when manually implementing a property setter. In this case, pass the
|
|
614
|
-
* property `name` and `oldValue` to ensure that any configured property
|
|
615
|
-
* options are honored.
|
|
616
|
-
*
|
|
617
|
-
* @param name name of requesting property
|
|
618
|
-
* @param oldValue old value of requesting property
|
|
619
|
-
* @param options property options to use instead of the previously
|
|
620
|
-
* configured options
|
|
621
|
-
* @category updates
|
|
622
|
-
*/
|
|
623
|
-
requestUpdate(name, oldValue, options) {
|
|
624
|
-
let shouldRequestUpdate = true;
|
|
625
|
-
// If we have a property key, perform property update steps.
|
|
626
|
-
if (name !== undefined) {
|
|
627
|
-
options =
|
|
628
|
-
options ||
|
|
629
|
-
this.constructor.getPropertyOptions(name);
|
|
630
|
-
const hasChanged = options.hasChanged || exports.notEqual;
|
|
631
|
-
if (hasChanged(this[name], oldValue)) {
|
|
632
|
-
if (!this._$changedProperties.has(name)) {
|
|
633
|
-
this._$changedProperties.set(name, oldValue);
|
|
634
|
-
}
|
|
635
|
-
// Add to reflecting properties set.
|
|
636
|
-
// Note, it's important that every change has a chance to add the
|
|
637
|
-
// property to `_reflectingProperties`. This ensures setting
|
|
638
|
-
// attribute + property reflects correctly.
|
|
639
|
-
if (options.reflect === true && this.__reflectingProperty !== name) {
|
|
640
|
-
if (this.__reflectingProperties === undefined) {
|
|
641
|
-
this.__reflectingProperties = new Map();
|
|
642
|
-
}
|
|
643
|
-
this.__reflectingProperties.set(name, options);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
// Abort the request if the property should not be considered changed.
|
|
648
|
-
shouldRequestUpdate = false;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
if (!this.isUpdatePending && shouldRequestUpdate) {
|
|
652
|
-
this.__updatePromise = this.__enqueueUpdate();
|
|
653
|
-
}
|
|
654
|
-
// Note, since this no longer returns a promise, in dev mode we return a
|
|
655
|
-
// thenable which warns if it's called.
|
|
656
|
-
return DEV_MODE
|
|
657
|
-
? requestUpdateThenable(this.localName)
|
|
658
|
-
: undefined;
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* Sets up the element to asynchronously update.
|
|
662
|
-
*/
|
|
663
|
-
__enqueueUpdate() {
|
|
664
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
665
|
-
this.isUpdatePending = true;
|
|
666
|
-
try {
|
|
667
|
-
// Ensure any previous update has resolved before updating.
|
|
668
|
-
// This `await` also ensures that property changes are batched.
|
|
669
|
-
yield this.__updatePromise;
|
|
670
|
-
}
|
|
671
|
-
catch (e) {
|
|
672
|
-
// Refire any previous errors async so they do not disrupt the update
|
|
673
|
-
// cycle. Errors are refired so developers have a chance to observe
|
|
674
|
-
// them, and this can be done by implementing
|
|
675
|
-
// `window.onunhandledrejection`.
|
|
676
|
-
Promise.reject(e);
|
|
677
|
-
}
|
|
678
|
-
const result = this.scheduleUpdate();
|
|
679
|
-
// If `scheduleUpdate` returns a Promise, we await it. This is done to
|
|
680
|
-
// enable coordinating updates with a scheduler. Note, the result is
|
|
681
|
-
// checked to avoid delaying an additional microtask unless we need to.
|
|
682
|
-
if (result != null) {
|
|
683
|
-
yield result;
|
|
684
|
-
}
|
|
685
|
-
return !this.isUpdatePending;
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Schedules an element update. You can override this method to change the
|
|
690
|
-
* timing of updates by returning a Promise. The update will await the
|
|
691
|
-
* returned Promise, and you should resolve the Promise to allow the update
|
|
692
|
-
* to proceed. If this method is overridden, `super.scheduleUpdate()`
|
|
693
|
-
* must be called.
|
|
694
|
-
*
|
|
695
|
-
* For instance, to schedule updates to occur just before the next frame:
|
|
696
|
-
*
|
|
697
|
-
* ```ts
|
|
698
|
-
* override protected async scheduleUpdate(): Promise<unknown> {
|
|
699
|
-
* await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
700
|
-
* super.scheduleUpdate();
|
|
701
|
-
* }
|
|
702
|
-
* ```
|
|
703
|
-
* @category updates
|
|
704
|
-
*/
|
|
705
|
-
scheduleUpdate() {
|
|
706
|
-
return this.performUpdate();
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Performs an element update. Note, if an exception is thrown during the
|
|
710
|
-
* update, `firstUpdated` and `updated` will not be called.
|
|
711
|
-
*
|
|
712
|
-
* Call `performUpdate()` to immediately process a pending update. This should
|
|
713
|
-
* generally not be needed, but it can be done in rare cases when you need to
|
|
714
|
-
* update synchronously.
|
|
715
|
-
*
|
|
716
|
-
* Note: To ensure `performUpdate()` synchronously completes a pending update,
|
|
717
|
-
* it should not be overridden. In LitElement 2.x it was suggested to override
|
|
718
|
-
* `performUpdate()` to also customizing update scheduling. Instead, you should now
|
|
719
|
-
* override `scheduleUpdate()`. For backwards compatibility with LitElement 2.x,
|
|
720
|
-
* scheduling updates via `performUpdate()` continues to work, but will make
|
|
721
|
-
* also calling `performUpdate()` to synchronously process updates difficult.
|
|
722
|
-
*
|
|
723
|
-
* @category updates
|
|
724
|
-
*/
|
|
725
|
-
performUpdate() {
|
|
726
|
-
var _a;
|
|
727
|
-
// Abort any update if one is not pending when this is called.
|
|
728
|
-
// This can happen if `performUpdate` is called early to "flush"
|
|
729
|
-
// the update.
|
|
730
|
-
if (!this.isUpdatePending) {
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
// create renderRoot before first update.
|
|
734
|
-
if (!this.hasUpdated) {
|
|
735
|
-
// Produce warning if any class properties are shadowed by class fields
|
|
736
|
-
if (DEV_MODE) {
|
|
737
|
-
const shadowedProperties = [];
|
|
738
|
-
this.constructor.elementProperties.forEach((_v, p) => {
|
|
739
|
-
var _a;
|
|
740
|
-
if (this.hasOwnProperty(p) && !((_a = this.__instanceProperties) === null || _a === void 0 ? void 0 : _a.has(p))) {
|
|
741
|
-
shadowedProperties.push(p);
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
if (shadowedProperties.length) {
|
|
745
|
-
throw new Error(`The following properties on element ${this.localName} will not ` +
|
|
746
|
-
`trigger updates as expected because they are set using class ` +
|
|
747
|
-
`fields: ${shadowedProperties.join(', ')}. ` +
|
|
748
|
-
`Native class fields and some compiled output will overwrite ` +
|
|
749
|
-
`accessors used for detecting changes. See ` +
|
|
750
|
-
`https://lit.dev/msg/class-field-shadowing ` +
|
|
751
|
-
`for more information.`);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
// Mixin instance properties once, if they exist.
|
|
756
|
-
if (this.__instanceProperties) {
|
|
757
|
-
// Use forEach so this works even if for/of loops are compiled to for loops
|
|
758
|
-
// expecting arrays
|
|
759
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
760
|
-
this.__instanceProperties.forEach((v, p) => (this[p] = v));
|
|
761
|
-
this.__instanceProperties = undefined;
|
|
762
|
-
}
|
|
763
|
-
let shouldUpdate = false;
|
|
764
|
-
const changedProperties = this._$changedProperties;
|
|
765
|
-
try {
|
|
766
|
-
shouldUpdate = this.shouldUpdate(changedProperties);
|
|
767
|
-
if (shouldUpdate) {
|
|
768
|
-
this.willUpdate(changedProperties);
|
|
769
|
-
(_a = this.__controllers) === null || _a === void 0 ? void 0 : _a.forEach((c) => { var _a; return (_a = c.hostUpdate) === null || _a === void 0 ? void 0 : _a.call(c); });
|
|
770
|
-
this.update(changedProperties);
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
this.__markUpdated();
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
catch (e) {
|
|
777
|
-
// Prevent `firstUpdated` and `updated` from running when there's an
|
|
778
|
-
// update exception.
|
|
779
|
-
shouldUpdate = false;
|
|
780
|
-
// Ensure element can accept additional updates after an exception.
|
|
781
|
-
this.__markUpdated();
|
|
782
|
-
throw e;
|
|
783
|
-
}
|
|
784
|
-
// The update is no longer considered pending and further updates are now allowed.
|
|
785
|
-
if (shouldUpdate) {
|
|
786
|
-
this._$didUpdate(changedProperties);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* @category updates
|
|
791
|
-
*/
|
|
792
|
-
willUpdate(_changedProperties) { }
|
|
793
|
-
// Note, this is an override point for polyfill-support.
|
|
794
|
-
// @internal
|
|
795
|
-
_$didUpdate(changedProperties) {
|
|
796
|
-
var _a;
|
|
797
|
-
(_a = this.__controllers) === null || _a === void 0 ? void 0 : _a.forEach((c) => { var _a; return (_a = c.hostUpdated) === null || _a === void 0 ? void 0 : _a.call(c); });
|
|
798
|
-
if (!this.hasUpdated) {
|
|
799
|
-
this.hasUpdated = true;
|
|
800
|
-
this.firstUpdated(changedProperties);
|
|
801
|
-
}
|
|
802
|
-
this.updated(changedProperties);
|
|
803
|
-
if (DEV_MODE &&
|
|
804
|
-
this.isUpdatePending &&
|
|
805
|
-
this.constructor.enabledWarnings.indexOf('change-in-update') >= 0) {
|
|
806
|
-
issueWarning('change-in-update', `Element ${this.localName} scheduled an update ` +
|
|
807
|
-
`(generally because a property was set) ` +
|
|
808
|
-
`after an update completed, causing a new update to be scheduled. ` +
|
|
809
|
-
`This is inefficient and should be avoided unless the next update ` +
|
|
810
|
-
`can only be scheduled as a side effect of the previous update.`);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
__markUpdated() {
|
|
814
|
-
this._$changedProperties = new Map();
|
|
815
|
-
this.isUpdatePending = false;
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* Returns a Promise that resolves when the element has completed updating.
|
|
819
|
-
* The Promise value is a boolean that is `true` if the element completed the
|
|
820
|
-
* update without triggering another update. The Promise result is `false` if
|
|
821
|
-
* a property was set inside `updated()`. If the Promise is rejected, an
|
|
822
|
-
* exception was thrown during the update.
|
|
823
|
-
*
|
|
824
|
-
* To await additional asynchronous work, override the `getUpdateComplete`
|
|
825
|
-
* method. For example, it is sometimes useful to await a rendered element
|
|
826
|
-
* before fulfilling this Promise. To do this, first await
|
|
827
|
-
* `super.getUpdateComplete()`, then any subsequent state.
|
|
828
|
-
*
|
|
829
|
-
* @return A promise of a boolean that resolves to true if the update completed
|
|
830
|
-
* without triggering another update.
|
|
831
|
-
* @category updates
|
|
832
|
-
*/
|
|
833
|
-
get updateComplete() {
|
|
834
|
-
return this.getUpdateComplete();
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Override point for the `updateComplete` promise.
|
|
838
|
-
*
|
|
839
|
-
* It is not safe to override the `updateComplete` getter directly due to a
|
|
840
|
-
* limitation in TypeScript which means it is not possible to call a
|
|
841
|
-
* superclass getter (e.g. `super.updateComplete.then(...)`) when the target
|
|
842
|
-
* language is ES5 (https://github.com/microsoft/TypeScript/issues/338).
|
|
843
|
-
* This method should be overridden instead. For example:
|
|
844
|
-
*
|
|
845
|
-
* ```ts
|
|
846
|
-
* class MyElement extends LitElement {
|
|
847
|
-
* override async getUpdateComplete() {
|
|
848
|
-
* const result = await super.getUpdateComplete();
|
|
849
|
-
* await this._myChild.updateComplete;
|
|
850
|
-
* return result;
|
|
851
|
-
* }
|
|
852
|
-
* }
|
|
853
|
-
* ```
|
|
854
|
-
*
|
|
855
|
-
* @return A promise of a boolean that resolves to true if the update completed
|
|
856
|
-
* without triggering another update.
|
|
857
|
-
* @category updates
|
|
858
|
-
*/
|
|
859
|
-
getUpdateComplete() {
|
|
860
|
-
return this.__updatePromise;
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* Controls whether or not `update()` should be called when the element requests
|
|
864
|
-
* an update. By default, this method always returns `true`, but this can be
|
|
865
|
-
* customized to control when to update.
|
|
866
|
-
*
|
|
867
|
-
* @param _changedProperties Map of changed properties with old values
|
|
868
|
-
* @category updates
|
|
869
|
-
*/
|
|
870
|
-
shouldUpdate(_changedProperties) {
|
|
871
|
-
return true;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Updates the element. This method reflects property values to attributes.
|
|
875
|
-
* It can be overridden to render and keep updated element DOM.
|
|
876
|
-
* Setting properties inside this method will *not* trigger
|
|
877
|
-
* another update.
|
|
878
|
-
*
|
|
879
|
-
* @param _changedProperties Map of changed properties with old values
|
|
880
|
-
* @category updates
|
|
881
|
-
*/
|
|
882
|
-
update(_changedProperties) {
|
|
883
|
-
if (this.__reflectingProperties !== undefined) {
|
|
884
|
-
// Use forEach so this works even if for/of loops are compiled to for
|
|
885
|
-
// loops expecting arrays
|
|
886
|
-
this.__reflectingProperties.forEach((v, k) => this.__propertyToAttribute(k, this[k], v));
|
|
887
|
-
this.__reflectingProperties = undefined;
|
|
888
|
-
}
|
|
889
|
-
this.__markUpdated();
|
|
890
|
-
}
|
|
891
|
-
/**
|
|
892
|
-
* Invoked whenever the element is updated. Implement to perform
|
|
893
|
-
* post-updating tasks via DOM APIs, for example, focusing an element.
|
|
894
|
-
*
|
|
895
|
-
* Setting properties inside this method will trigger the element to update
|
|
896
|
-
* again after this update cycle completes.
|
|
897
|
-
*
|
|
898
|
-
* @param _changedProperties Map of changed properties with old values
|
|
899
|
-
* @category updates
|
|
900
|
-
*/
|
|
901
|
-
updated(_changedProperties) { }
|
|
902
|
-
/**
|
|
903
|
-
* Invoked when the element is first updated. Implement to perform one time
|
|
904
|
-
* work on the element after update.
|
|
905
|
-
*
|
|
906
|
-
* Setting properties inside this method will trigger the element to update
|
|
907
|
-
* again after this update cycle completes.
|
|
908
|
-
*
|
|
909
|
-
* @param _changedProperties Map of changed properties with old values
|
|
910
|
-
* @category updates
|
|
911
|
-
*/
|
|
912
|
-
firstUpdated(_changedProperties) { }
|
|
913
|
-
}
|
|
914
|
-
exports.ReactiveElement = ReactiveElement;
|
|
915
|
-
_e = finalized;
|
|
916
|
-
/**
|
|
917
|
-
* Marks class as having finished creating properties.
|
|
918
|
-
*/
|
|
919
|
-
ReactiveElement[_e] = true;
|
|
920
|
-
/**
|
|
921
|
-
* Memoized list of all element properties, including any superclass properties.
|
|
922
|
-
* Created lazily on user subclasses when finalizing the class.
|
|
923
|
-
* @nocollapse
|
|
924
|
-
* @category properties
|
|
925
|
-
*/
|
|
926
|
-
ReactiveElement.elementProperties = new Map();
|
|
927
|
-
/**
|
|
928
|
-
* Memoized list of all element styles.
|
|
929
|
-
* Created lazily on user subclasses when finalizing the class.
|
|
930
|
-
* @nocollapse
|
|
931
|
-
* @category styles
|
|
932
|
-
*/
|
|
933
|
-
ReactiveElement.elementStyles = [];
|
|
934
|
-
/**
|
|
935
|
-
* Options used when calling `attachShadow`. Set this property to customize
|
|
936
|
-
* the options for the shadowRoot; for example, to create a closed
|
|
937
|
-
* shadowRoot: `{mode: 'closed'}`.
|
|
938
|
-
*
|
|
939
|
-
* Note, these options are used in `createRenderRoot`. If this method
|
|
940
|
-
* is customized, options should be respected if possible.
|
|
941
|
-
* @nocollapse
|
|
942
|
-
* @category rendering
|
|
943
|
-
*/
|
|
944
|
-
ReactiveElement.shadowRootOptions = { mode: 'open' };
|
|
945
|
-
// Apply polyfills if available
|
|
946
|
-
(_c = globalThis[`reactiveElementPolyfillSupport${DEV_MODE ? `DevMode` : ``}`]) === null || _c === void 0 ? void 0 : _c.call(globalThis, {
|
|
947
|
-
ReactiveElement,
|
|
948
|
-
});
|
|
949
|
-
// Dev mode warnings...
|
|
950
|
-
if (DEV_MODE) {
|
|
951
|
-
// Default warning set.
|
|
952
|
-
ReactiveElement.enabledWarnings = ['change-in-update'];
|
|
953
|
-
const ensureOwnWarnings = function (ctor) {
|
|
954
|
-
if (!ctor.hasOwnProperty(JSCompiler_renameProperty('enabledWarnings', ctor))) {
|
|
955
|
-
ctor.enabledWarnings = ctor.enabledWarnings.slice();
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
ReactiveElement.enableWarning = function (warning) {
|
|
959
|
-
ensureOwnWarnings(this);
|
|
960
|
-
if (this.enabledWarnings.indexOf(warning) < 0) {
|
|
961
|
-
this.enabledWarnings.push(warning);
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
ReactiveElement.disableWarning = function (warning) {
|
|
965
|
-
ensureOwnWarnings(this);
|
|
966
|
-
const i = this.enabledWarnings.indexOf(warning);
|
|
967
|
-
if (i >= 0) {
|
|
968
|
-
this.enabledWarnings.splice(i, 1);
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
// IMPORTANT: do not change the property name or the assignment expression.
|
|
973
|
-
// This line will be used in regexes to search for ReactiveElement usage.
|
|
974
|
-
// TODO(justinfagnani): inject version number at build time
|
|
975
|
-
((_d = globalThis.reactiveElementVersions) !== null && _d !== void 0 ? _d : (globalThis.reactiveElementVersions = [])).push('1.0.0');
|
|
976
|
-
if (DEV_MODE && globalThis.reactiveElementVersions.length > 1) {
|
|
977
|
-
issueWarning('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
|
|
978
|
-
`is not recommended.`);
|
|
979
|
-
}
|