@mantou/gem 2.2.0 → 2.2.1
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/gem.es.js +2007 -2020
- package/dist/gem.umd.js +15 -32
- package/elements/base/dialog.d.ts +1 -1
- package/elements/base/dialog.d.ts.map +1 -1
- package/elements/base/dialog.js +2 -2
- package/elements/base/dialog.js.map +1 -1
- package/elements/base/gesture.d.ts +1 -1
- package/elements/base/gesture.d.ts.map +1 -1
- package/elements/base/gesture.js +4 -4
- package/elements/base/gesture.js.map +1 -1
- package/elements/base/link.d.ts.map +1 -1
- package/elements/base/link.js +7 -12
- package/elements/base/link.js.map +1 -1
- package/elements/base/modal-factory.d.ts +23 -12
- package/elements/base/modal-factory.d.ts.map +1 -1
- package/elements/base/modal-factory.js +14 -14
- package/elements/base/modal-factory.js.map +1 -1
- package/elements/base/reflect.d.ts +1 -2
- package/elements/base/reflect.d.ts.map +1 -1
- package/elements/base/reflect.js +8 -10
- package/elements/base/reflect.js.map +1 -1
- package/elements/base/route.d.ts +17 -7
- package/elements/base/route.d.ts.map +1 -1
- package/elements/base/route.js +6 -6
- package/elements/base/route.js.map +1 -1
- package/elements/base/title.d.ts +1 -1
- package/elements/base/title.d.ts.map +1 -1
- package/elements/base/title.js +3 -3
- package/elements/base/title.js.map +1 -1
- package/elements/base/unsafe.d.ts +1 -1
- package/elements/base/unsafe.d.ts.map +1 -1
- package/elements/base/unsafe.js +1 -1
- package/elements/base/unsafe.js.map +1 -1
- package/elements/base/use.d.ts +1 -1
- package/elements/base/use.d.ts.map +1 -1
- package/elements/base/use.js +1 -1
- package/elements/base/use.js.map +1 -1
- package/elements/link.js +1 -1
- package/elements/link.js.map +1 -1
- package/elements/route.js +1 -1
- package/elements/route.js.map +1 -1
- package/helper/hmr.d.ts +11 -0
- package/helper/hmr.d.ts.map +1 -0
- package/helper/hmr.js +255 -0
- package/helper/hmr.js.map +1 -0
- package/helper/i18n.d.ts +2 -2
- package/helper/i18n.d.ts.map +1 -1
- package/helper/i18n.js +5 -4
- package/helper/i18n.js.map +1 -1
- package/helper/logger.d.ts +1 -1
- package/helper/logger.d.ts.map +1 -1
- package/helper/logger.js +8 -5
- package/helper/logger.js.map +1 -1
- package/helper/mediaquery.js +1 -1
- package/helper/mediaquery.js.map +1 -1
- package/helper/ssr-shim.d.ts.map +1 -1
- package/helper/ssr-shim.js +2 -0
- package/helper/ssr-shim.js.map +1 -1
- package/helper/theme.d.ts +3 -4
- package/helper/theme.d.ts.map +1 -1
- package/helper/theme.js +1 -1
- package/helper/theme.js.map +1 -1
- package/index.d.ts +1 -2
- package/index.d.ts.map +1 -1
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/lib/decorators.d.ts +5 -13
- package/lib/decorators.d.ts.map +1 -1
- package/lib/decorators.js +40 -42
- package/lib/decorators.js.map +1 -1
- package/lib/directive.d.ts +0 -18
- package/lib/directive.d.ts.map +1 -1
- package/lib/directive.js +1 -2
- package/lib/directive.js.map +1 -1
- package/lib/element.d.ts +8 -137
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +16 -481
- package/lib/element.js.map +1 -1
- package/lib/history.d.ts +67 -9
- package/lib/history.d.ts.map +1 -1
- package/lib/history.js +12 -12
- package/lib/history.js.map +1 -1
- package/lib/lit-html.d.ts +5 -104
- package/lib/lit-html.d.ts.map +1 -1
- package/lib/lit-html.js +73 -27
- package/lib/lit-html.js.map +1 -1
- package/lib/reactive.d.ts +123 -0
- package/lib/reactive.d.ts.map +1 -0
- package/lib/reactive.js +478 -0
- package/lib/reactive.js.map +1 -0
- package/lib/repeat.d.ts +3 -3
- package/lib/repeat.d.ts.map +1 -1
- package/lib/repeat.js +3 -3
- package/lib/repeat.js.map +1 -1
- package/lib/store.d.ts +13 -2
- package/lib/store.d.ts.map +1 -1
- package/lib/store.js +1 -0
- package/lib/store.js.map +1 -1
- package/lib/utils.d.ts +23 -11
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +20 -15
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.d.ts.map +1 -1
- package/lib/version.js +1 -2
- package/lib/version.js.map +1 -1
- package/package.json +3 -3
- package/src/dist.ts +6 -8
- package/src/elements/base/dialog.ts +2 -2
- package/src/elements/base/gesture.ts +5 -5
- package/src/elements/base/link.ts +16 -22
- package/src/elements/base/modal-factory.ts +14 -14
- package/src/elements/base/reflect.ts +2 -3
- package/src/elements/base/route.ts +13 -14
- package/src/elements/base/title.ts +4 -4
- package/src/elements/base/unsafe.ts +1 -1
- package/src/elements/base/use.ts +1 -1
- package/src/elements/link.ts +1 -1
- package/src/elements/route.ts +1 -1
- package/src/helper/hmr.ts +305 -0
- package/src/helper/i18n.ts +7 -7
- package/src/helper/logger.ts +9 -5
- package/src/helper/mediaquery.ts +1 -1
- package/src/helper/ssr-shim.ts +3 -0
- package/src/helper/theme.ts +4 -4
- package/src/index.ts +1 -4
- package/src/lib/decorators.ts +56 -68
- package/src/lib/directive.ts +3 -5
- package/src/lib/element.ts +22 -600
- package/src/lib/history.ts +14 -15
- package/src/lib/lit-html.ts +86 -34
- package/src/lib/reactive.ts +596 -0
- package/src/lib/repeat.ts +5 -5
- package/src/lib/store.ts +1 -0
- package/src/lib/utils.ts +35 -30
- package/src/lib/version.ts +1 -2
- package/src/test/elements/link.test.ts +2 -2
- package/src/test/elements/reflect.test.ts +3 -3
- package/src/test/elements/title.test.ts +2 -2
- package/src/test/gem-element/advance.test.ts +10 -9
- package/src/test/gem-element/basic.test.ts +3 -3
- package/src/test/gem-element/decorators.test.ts +10 -10
- package/src/test/gem-element/multi.test.ts +2 -2
- package/src/test/history.test.ts +1 -2
- package/src/test/store.test.ts +2 -3
- package/src/test/utils.test.ts +4 -5
- package/src/test/utils.ts +2 -2
- package/helper/react-shim.d.ts +0 -15
- package/helper/react-shim.d.ts.map +0 -1
- package/helper/react-shim.js +0 -56
- package/helper/react-shim.js.map +0 -1
- package/lib/directives.d.ts +0 -4
- package/lib/directives.d.ts.map +0 -1
- package/lib/directives.js +0 -5
- package/lib/directives.js.map +0 -1
- package/lib/ref.d.ts +0 -1
- package/lib/ref.d.ts.map +0 -1
- package/lib/ref.js +0 -2
- package/lib/ref.js.map +0 -1
package/src/lib/history.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// https://github.com/WICG/navigation-api#stakeholder-feedback
|
|
2
2
|
|
|
3
3
|
import { connect, createStore } from './store';
|
|
4
|
-
import {
|
|
4
|
+
import { absoluteLocation, cleanObject, GemError, QueryString } from './utils';
|
|
5
5
|
|
|
6
|
-
const nativeHistory =
|
|
6
|
+
const nativeHistory = globalThis.history;
|
|
7
7
|
const nativePushState: typeof nativeHistory.pushState = nativeHistory.pushState.bind(nativeHistory);
|
|
8
8
|
const nativeReplaceState: typeof nativeHistory.replaceState = nativeHistory.replaceState.bind(nativeHistory);
|
|
9
9
|
|
|
@@ -107,7 +107,7 @@ function updateHistory(p: UpdateHistoryParams, native: typeof nativeHistory.push
|
|
|
107
107
|
const url = getUrlBarPath(path) + new QueryString(query) + hash;
|
|
108
108
|
const prevHash = decodeURIComponent(location.hash);
|
|
109
109
|
native(state, title, url);
|
|
110
|
-
if (prevHash !== hash)
|
|
110
|
+
if (prevHash !== hash) dispatchEvent(new CustomEvent('hashchange'));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// 跨框架时,调用者对 basePath 无感知
|
|
@@ -128,7 +128,7 @@ function updateHistoryByNative(data: any, title: string, originUrl: string, nati
|
|
|
128
128
|
const prevHash = location.hash;
|
|
129
129
|
native(state, title, url);
|
|
130
130
|
// `location.hash` 和 `hash` 都已经进行了 url 编码,可以直接进行相等判断
|
|
131
|
-
if (prevHash !== hash)
|
|
131
|
+
if (prevHash !== hash) dispatchEvent(new CustomEvent('hashchange'));
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
const gemBasePathStore = createStore({
|
|
@@ -185,27 +185,26 @@ const gemHistory = new GemHistory();
|
|
|
185
185
|
|
|
186
186
|
const gemTitleStore = createStore({ defaultTitle: document.title, url: '', title: '' });
|
|
187
187
|
|
|
188
|
-
const
|
|
188
|
+
const HISTORY = { history: gemHistory, titleStore: gemTitleStore, basePathStore: gemBasePathStore };
|
|
189
189
|
|
|
190
190
|
declare global {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
191
|
+
// eslint-disable-next-line no-var
|
|
192
|
+
var _GEMHISTORY: typeof HISTORY | undefined;
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
if (!
|
|
197
|
-
|
|
195
|
+
if (!globalThis._GEMHISTORY) {
|
|
196
|
+
globalThis._GEMHISTORY = HISTORY;
|
|
198
197
|
|
|
199
|
-
nativeHistory.pushState =
|
|
198
|
+
nativeHistory.pushState = (state: any, title: string, path: string) => {
|
|
200
199
|
updateHistoryByNative(state, title, path, nativePushState);
|
|
201
200
|
};
|
|
202
201
|
|
|
203
|
-
nativeHistory.replaceState =
|
|
202
|
+
nativeHistory.replaceState = (state: any, title: string, path: string) => {
|
|
204
203
|
updateHistoryByNative(state, title, path, nativeReplaceState);
|
|
205
204
|
};
|
|
206
205
|
|
|
207
206
|
// 点击 `<a>`
|
|
208
|
-
|
|
207
|
+
addEventListener('hashchange', ({ isTrusted }) => {
|
|
209
208
|
if (isTrusted) {
|
|
210
209
|
gemHistory.replace({ hash: location.hash });
|
|
211
210
|
}
|
|
@@ -250,7 +249,7 @@ if (!window._GEMHISTORY) {
|
|
|
250
249
|
* 表示 popstate handler 中正在进行导航
|
|
251
250
|
*/
|
|
252
251
|
let navigating = false;
|
|
253
|
-
|
|
252
|
+
addEventListener('popstate', (event) => {
|
|
254
253
|
const newState = event.state as HistoryState | null;
|
|
255
254
|
if (!newState?.$key) {
|
|
256
255
|
// 比如作为其他框架 app 的宿主 app
|
|
@@ -316,5 +315,5 @@ if (!window._GEMHISTORY) {
|
|
|
316
315
|
});
|
|
317
316
|
}
|
|
318
317
|
|
|
319
|
-
const { history, titleStore, basePathStore } =
|
|
318
|
+
const { history, titleStore, basePathStore } = globalThis._GEMHISTORY;
|
|
320
319
|
export { history, titleStore, basePathStore };
|
package/src/lib/lit-html.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* Gem Note:
|
|
9
|
+
*
|
|
8
10
|
* TemplateResult change to classes
|
|
9
11
|
* Use `null`/`undefined` instead `nothing`, no export `noChange`
|
|
10
12
|
* Built-in ref & rest props`
|
|
@@ -12,6 +14,7 @@
|
|
|
12
14
|
* Remove sanitizer
|
|
13
15
|
* Remove debug log event
|
|
14
16
|
* Remove warning log
|
|
17
|
+
* Support v-if/v-else-if/v-else
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
20
|
import type { TrustedTypesWindow } from 'trusted-types/lib';
|
|
@@ -22,9 +25,7 @@ const global = globalThis;
|
|
|
22
25
|
|
|
23
26
|
const trustedTypes = (global as unknown as TrustedTypesWindow).trustedTypes;
|
|
24
27
|
|
|
25
|
-
const policy = trustedTypes?.createPolicy('lit-html', {
|
|
26
|
-
createHTML: (s: string) => s,
|
|
27
|
-
});
|
|
28
|
+
const policy = trustedTypes?.createPolicy('lit-html', { createHTML: (s: string) => s });
|
|
28
29
|
|
|
29
30
|
// Added to an attribute name to mark the attribute as bound so we can find
|
|
30
31
|
// it easily.
|
|
@@ -51,7 +52,7 @@ const createMarker = () => d.createComment('');
|
|
|
51
52
|
// https://tc39.github.io/ecma262/#sec-typeof-operator
|
|
52
53
|
type Primitive = null | undefined | boolean | number | string | symbol | bigint;
|
|
53
54
|
const isPrimitive = (value: unknown): value is Primitive =>
|
|
54
|
-
value === null || (typeof value
|
|
55
|
+
value === null || (typeof value !== 'object' && typeof value !== 'function');
|
|
55
56
|
const isNullish = (value: unknown) => value === null || value === undefined;
|
|
56
57
|
const isIterable = (value: any): value is Iterable<unknown> => Symbol.iterator in value;
|
|
57
58
|
|
|
@@ -125,6 +126,13 @@ const doubleQuoteAttrEndRegex = /"/g;
|
|
|
125
126
|
*/
|
|
126
127
|
const rawTextElement = /^(?:script|style|textarea|title)$/i;
|
|
127
128
|
|
|
129
|
+
/** TemplateResult types */
|
|
130
|
+
const HTML_RESULT = 1;
|
|
131
|
+
const SVG_RESULT = 2;
|
|
132
|
+
const MATHML_RESULT = 3;
|
|
133
|
+
|
|
134
|
+
type ResultType = typeof HTML_RESULT | typeof SVG_RESULT | typeof MATHML_RESULT;
|
|
135
|
+
|
|
128
136
|
// TemplatePart types
|
|
129
137
|
// IMPORTANT: these must match the values in PartType
|
|
130
138
|
const ATTRIBUTE_PART = 1;
|
|
@@ -135,11 +143,9 @@ const EVENT_PART = 5;
|
|
|
135
143
|
const ELEMENT_PART = 6;
|
|
136
144
|
const COMMENT_PART = 7;
|
|
137
145
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
MATHML,
|
|
142
|
-
}
|
|
146
|
+
const V_IF = 'v-if';
|
|
147
|
+
const V_ELSE_IF = 'v-else-if';
|
|
148
|
+
const V_ELSE = 'v-else';
|
|
143
149
|
|
|
144
150
|
export class TemplateResult {
|
|
145
151
|
type: ResultType;
|
|
@@ -158,9 +164,9 @@ const tag =
|
|
|
158
164
|
return new TemplateResult(type, strings, values);
|
|
159
165
|
};
|
|
160
166
|
|
|
161
|
-
export const html = tag(
|
|
162
|
-
export const svg = tag(
|
|
163
|
-
export const mathml = tag(
|
|
167
|
+
export const html = tag(HTML_RESULT);
|
|
168
|
+
export const svg = tag(SVG_RESULT);
|
|
169
|
+
export const mathml = tag(MATHML_RESULT);
|
|
164
170
|
|
|
165
171
|
// for directive
|
|
166
172
|
export const noChange = Symbol.for('lit-noChange');
|
|
@@ -249,7 +255,7 @@ const getTemplateHtml = (strings: TemplateStringsArray, type: ResultType): [Trus
|
|
|
249
255
|
// parts. ElementParts are also reflected in this array as undefined
|
|
250
256
|
// rather than a string, to disambiguate from attribute bindings.
|
|
251
257
|
const attrNames: Array<string> = [];
|
|
252
|
-
let htmlStr = type ===
|
|
258
|
+
let htmlStr = type === SVG_RESULT ? '<svg>' : type === MATHML_RESULT ? '<math>' : '';
|
|
253
259
|
|
|
254
260
|
// When we're inside a raw text tag (not it's text content), the regex
|
|
255
261
|
// will still be tagRegex so we can find attributes, but will switch to
|
|
@@ -357,9 +363,7 @@ const getTemplateHtml = (strings: TemplateStringsArray, type: ResultType): [Trus
|
|
|
357
363
|
}
|
|
358
364
|
|
|
359
365
|
const htmlResult: string | TrustedHTML =
|
|
360
|
-
htmlStr +
|
|
361
|
-
(strings[l] || '<?>') +
|
|
362
|
-
(type === ResultType.SVG ? '</svg>' : type === ResultType.MATHML ? '</math>' : '');
|
|
366
|
+
htmlStr + (strings[l] || '<?>') + (type === SVG_RESULT ? '</svg>' : type === MATHML_RESULT ? '</math>' : '');
|
|
363
367
|
|
|
364
368
|
// Returned as an array for terseness
|
|
365
369
|
return [trustFromTemplateString(strings, htmlResult), attrNames];
|
|
@@ -385,7 +389,7 @@ class Template {
|
|
|
385
389
|
walker.currentNode = this.el.content;
|
|
386
390
|
|
|
387
391
|
// Re-parent SVG or MathML nodes into template root
|
|
388
|
-
if (type ===
|
|
392
|
+
if (type === SVG_RESULT || type === MATHML_RESULT) {
|
|
389
393
|
const wrapper = this.el.content.firstChild!;
|
|
390
394
|
wrapper.replaceWith(...wrapper.childNodes);
|
|
391
395
|
}
|
|
@@ -513,10 +517,10 @@ function resolveDirective(
|
|
|
513
517
|
const nextDirectiveConstructor = isPrimitive(value)
|
|
514
518
|
? undefined
|
|
515
519
|
: // This property needs to remain unminified.
|
|
516
|
-
(value as DirectiveResult)
|
|
520
|
+
(value as DirectiveResult)._$litDirective$;
|
|
517
521
|
if (currentDirective?.constructor !== nextDirectiveConstructor) {
|
|
518
522
|
// This property needs to remain unminified.
|
|
519
|
-
currentDirective?.
|
|
523
|
+
currentDirective?._$notifyDirectiveConnectionChanged?.(false);
|
|
520
524
|
if (nextDirectiveConstructor === undefined) {
|
|
521
525
|
currentDirective = undefined;
|
|
522
526
|
} else {
|
|
@@ -548,6 +552,8 @@ export type { TemplateInstance };
|
|
|
548
552
|
class TemplateInstance implements Disconnectable {
|
|
549
553
|
_$template: Template;
|
|
550
554
|
_$parts: Array<Part | undefined> = [];
|
|
555
|
+
/** @internal */
|
|
556
|
+
_$conditions: ConditionChain[] = [];
|
|
551
557
|
|
|
552
558
|
/** @internal */
|
|
553
559
|
_$parent: ChildPart;
|
|
@@ -574,8 +580,10 @@ class TemplateInstance implements Disconnectable {
|
|
|
574
580
|
_clone(options: RenderOptions | undefined) {
|
|
575
581
|
const {
|
|
576
582
|
el: { content },
|
|
577
|
-
parts
|
|
583
|
+
parts,
|
|
578
584
|
} = this._$template;
|
|
585
|
+
const ifMap = new Map<Element, number>();
|
|
586
|
+
const elseIfMap = new Map<Element, number>();
|
|
579
587
|
const fragment = (options?.creationScope ?? d).importNode(content, true);
|
|
580
588
|
walker.currentNode = fragment;
|
|
581
589
|
|
|
@@ -590,6 +598,8 @@ class TemplateInstance implements Disconnectable {
|
|
|
590
598
|
if (templatePart.type === CHILD_PART) {
|
|
591
599
|
part = new ChildPart(node as HTMLElement, node.nextSibling, this, options);
|
|
592
600
|
} else if (templatePart.type === ATTRIBUTE_PART) {
|
|
601
|
+
templatePart.name === V_IF && ifMap.set(node as HTMLElement, partIndex);
|
|
602
|
+
templatePart.name === V_ELSE_IF && elseIfMap.set(node as HTMLElement, partIndex);
|
|
593
603
|
part = new templatePart.ctor(node as HTMLElement, templatePart.name, templatePart.strings, this, options);
|
|
594
604
|
} else if (templatePart.type === ELEMENT_PART) {
|
|
595
605
|
part = new ElementPart(node as HTMLElement, this, options);
|
|
@@ -602,6 +612,18 @@ class TemplateInstance implements Disconnectable {
|
|
|
602
612
|
nodeIndex++;
|
|
603
613
|
}
|
|
604
614
|
}
|
|
615
|
+
|
|
616
|
+
ifMap.forEach((idx, element) => {
|
|
617
|
+
const chain = new ConditionChain(element, idx);
|
|
618
|
+
this._$conditions.push(chain);
|
|
619
|
+
let ele: Element | null = element;
|
|
620
|
+
while ((ele = ele.nextElementSibling)) {
|
|
621
|
+
const pos = elseIfMap.get(ele);
|
|
622
|
+
if (pos === undefined) break;
|
|
623
|
+
chain.push(ele, pos);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
|
|
605
627
|
// We need to set the currentNode away from the cloned tree so that we
|
|
606
628
|
// don't hold onto the tree even if the tree is detached and should be
|
|
607
629
|
// freed.
|
|
@@ -619,12 +641,52 @@ class TemplateInstance implements Disconnectable {
|
|
|
619
641
|
// since values are in between template spans. We increment i by 1
|
|
620
642
|
// later in the loop, so increment it by part.strings.length - 2 here
|
|
621
643
|
i += (part as AttributePart).strings!.length - 2;
|
|
644
|
+
} else if ((part as AttributePart).name === V_IF || (part as AttributePart).name === V_ELSE_IF) {
|
|
622
645
|
} else {
|
|
623
646
|
part._$setValue(values[i]);
|
|
624
647
|
}
|
|
625
648
|
}
|
|
626
649
|
i++;
|
|
627
650
|
}
|
|
651
|
+
|
|
652
|
+
this._$conditions.forEach((e) => e.update(values));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
class ConditionChain {
|
|
657
|
+
readonly mark: Comment;
|
|
658
|
+
readonly list: { ele: Element; idx?: number }[];
|
|
659
|
+
|
|
660
|
+
constructor(ele: Element, idx: number) {
|
|
661
|
+
const mark = createMarker();
|
|
662
|
+
ele.before(mark);
|
|
663
|
+
this.mark = mark;
|
|
664
|
+
this.list = [{ ele, idx }];
|
|
665
|
+
this.check();
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
get next() {
|
|
669
|
+
return this.list.at(-1)!.ele.nextElementSibling;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
push(ele: Element, idx?: number) {
|
|
673
|
+
this.list.push({ ele, idx });
|
|
674
|
+
this.check();
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
check() {
|
|
678
|
+
const next = this.next;
|
|
679
|
+
if (next?.attributes.getNamedItem(V_ELSE)) {
|
|
680
|
+
this.list.push({ ele: next });
|
|
681
|
+
next.removeAttribute(V_ELSE);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
update(values: Array<unknown>) {
|
|
686
|
+
const { mark, list } = this;
|
|
687
|
+
const show = list.find(({ idx }) => idx === undefined || !!values[idx]);
|
|
688
|
+
if (show && !show.ele.parentNode) mark.after(show.ele);
|
|
689
|
+
list.forEach(({ ele }) => (!show || ele !== show.ele) && ele.remove());
|
|
628
690
|
}
|
|
629
691
|
}
|
|
630
692
|
|
|
@@ -1042,7 +1104,7 @@ class AttributePart implements Disconnectable {
|
|
|
1042
1104
|
const values = value as Array<unknown>;
|
|
1043
1105
|
value = strings[0];
|
|
1044
1106
|
|
|
1045
|
-
let i, v;
|
|
1107
|
+
let i: number, v: any;
|
|
1046
1108
|
for (i = 0; i < strings.length - 1; i++) {
|
|
1047
1109
|
v = resolveDirective(this, values[valueIndex! + i], directiveParent, i);
|
|
1048
1110
|
change ||= !isPrimitive(v) || v !== (this._$committedValue as Array<unknown>)[i];
|
|
@@ -1095,16 +1157,6 @@ export type { EventPart };
|
|
|
1095
1157
|
class EventPart extends AttributePart {
|
|
1096
1158
|
override readonly type = EVENT_PART;
|
|
1097
1159
|
|
|
1098
|
-
constructor(
|
|
1099
|
-
element: HTMLElement,
|
|
1100
|
-
name: string,
|
|
1101
|
-
strings: ReadonlyArray<string>,
|
|
1102
|
-
parent: Disconnectable,
|
|
1103
|
-
options: RenderOptions | undefined,
|
|
1104
|
-
) {
|
|
1105
|
-
super(element, name, strings, parent, options);
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
1160
|
/** @internal */
|
|
1109
1161
|
override _$setValue(newListener: unknown, directiveParent: DirectiveParent = this) {
|
|
1110
1162
|
newListener = resolveDirective(this, newListener, directiveParent, 0);
|
|
@@ -1175,7 +1227,7 @@ class ElementPart implements Disconnectable {
|
|
|
1175
1227
|
if (!value) return;
|
|
1176
1228
|
if (value instanceof Ref) {
|
|
1177
1229
|
value.value = this.element;
|
|
1178
|
-
} else if ((value as DirectiveResult)
|
|
1230
|
+
} else if ((value as DirectiveResult)._$litDirective$) {
|
|
1179
1231
|
resolveDirective(this, value);
|
|
1180
1232
|
} else {
|
|
1181
1233
|
if (this._$props) {
|
|
@@ -1202,10 +1254,10 @@ export const render = (
|
|
|
1202
1254
|
options?: RenderOptions,
|
|
1203
1255
|
): RootPart => {
|
|
1204
1256
|
const partOwnerNode = (options?.renderBefore ?? container) as any;
|
|
1205
|
-
let part: ChildPart = partOwnerNode
|
|
1257
|
+
let part: ChildPart = partOwnerNode._$litPart$;
|
|
1206
1258
|
if (part === undefined) {
|
|
1207
1259
|
const endNode = options?.renderBefore ?? null;
|
|
1208
|
-
partOwnerNode
|
|
1260
|
+
partOwnerNode._$litPart$ = part = new ChildPart(
|
|
1209
1261
|
container.insertBefore(createMarker(), endNode),
|
|
1210
1262
|
endNode,
|
|
1211
1263
|
undefined,
|