@redvars/peacock 3.12.0 → 3.13.0
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/custom-elements.json +17 -7
- package/dist/field.js +4 -5
- package/dist/field.js.map +1 -1
- package/dist/loader.js +34 -9
- package/dist/loader.js.map +1 -1
- package/dist/src/LoaderUtils.d.ts +10 -2
- package/dist/test/loader.test.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +2 -2
- package/src/LoaderUtils.ts +41 -13
- package/src/field/field.scss +8 -6
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -44,9 +44,9 @@ Visit [https://peacock.redvars.com](https://peacock.redvars.com) to view the doc
|
|
|
44
44
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
45
45
|
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
|
|
46
46
|
|
|
47
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.
|
|
47
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.13.0/dist/assets/styles.css"></link>
|
|
48
48
|
<script type='module'
|
|
49
|
-
src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.
|
|
49
|
+
src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.13.0/dist/loader.js'></script>
|
|
50
50
|
</head>
|
|
51
51
|
|
|
52
52
|
<wc-button>Button</wc-button>
|
package/src/LoaderUtils.ts
CHANGED
|
@@ -10,10 +10,22 @@ interface LoaderConfig {
|
|
|
10
10
|
|
|
11
11
|
export { LoaderConfig };
|
|
12
12
|
|
|
13
|
+
type LoadRoot = Element | Document | DocumentFragment;
|
|
14
|
+
|
|
13
15
|
export class LoaderUtils {
|
|
14
16
|
private _loaderConfig: LoaderConfig;
|
|
15
17
|
|
|
16
|
-
private _observer
|
|
18
|
+
private _observer = new MutationObserver(mutations => {
|
|
19
|
+
for (const { addedNodes } of mutations) {
|
|
20
|
+
for (const node of addedNodes) {
|
|
21
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
22
|
+
this.load(node as Element);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
private _observed = new WeakSet<Node>();
|
|
17
29
|
|
|
18
30
|
constructor(loaderConfig: LoaderConfig) {
|
|
19
31
|
this._loaderConfig = loaderConfig;
|
|
@@ -26,10 +38,27 @@ export class LoaderUtils {
|
|
|
26
38
|
}
|
|
27
39
|
|
|
28
40
|
start() {
|
|
41
|
+
// Before the eager components are defined, so their shadow roots are watched too.
|
|
42
|
+
this.watchShadowRoots();
|
|
29
43
|
this.eagerLoadComponents();
|
|
30
44
|
this.lazyLoadComponents(document);
|
|
31
45
|
}
|
|
32
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Watches every shadow root attached from now on, as it is attached, so lazy components that a
|
|
49
|
+
* component renders in its shadow root load as they do in the document.
|
|
50
|
+
*/
|
|
51
|
+
watchShadowRoots() {
|
|
52
|
+
const watch = (shadowRoot: ShadowRoot) =>
|
|
53
|
+
this.lazyLoadComponents(shadowRoot);
|
|
54
|
+
const { attachShadow } = Element.prototype;
|
|
55
|
+
Element.prototype.attachShadow = function attachShadowAndWatch(init) {
|
|
56
|
+
const shadowRoot = attachShadow.call(this, init);
|
|
57
|
+
watch(shadowRoot);
|
|
58
|
+
return shadowRoot;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
33
62
|
eagerLoadComponents() {
|
|
34
63
|
if (!this._loaderConfig.components) return;
|
|
35
64
|
for (const [name, value] of Object.entries(this._loaderConfig.components)) {
|
|
@@ -72,7 +101,7 @@ export class LoaderUtils {
|
|
|
72
101
|
}
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
async load(root:
|
|
104
|
+
async load(root: LoadRoot): Promise<void> {
|
|
76
105
|
const rootTagName =
|
|
77
106
|
root instanceof Element ? root.tagName.toLowerCase() : '';
|
|
78
107
|
|
|
@@ -90,23 +119,22 @@ export class LoaderUtils {
|
|
|
90
119
|
);
|
|
91
120
|
}
|
|
92
121
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (const { addedNodes } of mutations) {
|
|
96
|
-
for (const node of addedNodes) {
|
|
97
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
98
|
-
this.load(node as Element);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
122
|
+
/** Loads the lazy components in `root` (a document or a shadow root) and those added later. */
|
|
123
|
+
lazyLoadComponents(root: Document | Element | ShadowRoot) {
|
|
104
124
|
const target = root instanceof Document ? root.documentElement : root;
|
|
125
|
+
if (this._observed.has(target)) return;
|
|
126
|
+
this._observed.add(target);
|
|
127
|
+
|
|
105
128
|
this.load(target);
|
|
106
129
|
|
|
107
130
|
this._observer.observe(target, {
|
|
108
131
|
subtree: true,
|
|
109
132
|
childList: true,
|
|
110
133
|
});
|
|
134
|
+
|
|
135
|
+
// Shadow roots attached before watchShadowRoots() ran; later ones are watched as attached.
|
|
136
|
+
for (const element of target.querySelectorAll('*')) {
|
|
137
|
+
if (element.shadowRoot) this.lazyLoadComponents(element.shadowRoot);
|
|
138
|
+
}
|
|
111
139
|
}
|
|
112
140
|
}
|
package/src/field/field.scss
CHANGED
|
@@ -235,13 +235,15 @@
|
|
|
235
235
|
cursor: not-allowed;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
// A value to read, not a control switched off: the text, label and helper stay at full
|
|
239
|
+
// contrast, in a faint box with a lighter outline (full again on focus).
|
|
240
|
+
&.readonly:not(.disabled) {
|
|
239
241
|
cursor: initial;
|
|
240
|
-
--
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
--_container-color: color-mix(in srgb, var(--color-on-surface) 4%, transparent);
|
|
243
|
+
|
|
244
|
+
&:not(.focused) {
|
|
245
|
+
--_outline-opacity: 0.38;
|
|
246
|
+
}
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
&.show-skeleton {
|