@neovici/cosmoz-utils 6.23.0 → 6.25.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.
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { noChange } from 'lit-html';
|
|
2
|
+
import { AsyncDirective, directive } from 'lit-html/async-directive.js';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the slot's flattened assigned elements into the ref object,
|
|
5
|
+
* like ref() writes the element.
|
|
6
|
+
*
|
|
7
|
+
* Consumers read refObject.current at event time; a ref does not
|
|
8
|
+
* trigger renders.
|
|
9
|
+
*/
|
|
10
|
+
class AssignedRefDirective extends AsyncDirective {
|
|
11
|
+
_slot;
|
|
12
|
+
_ref;
|
|
13
|
+
#project = () => {
|
|
14
|
+
if (!this._slot || !this._ref) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this._ref.current = this._slot.assignedElements({ flatten: true });
|
|
18
|
+
};
|
|
19
|
+
#onSlotChange = () => this.#project();
|
|
20
|
+
update(part, [ref]) {
|
|
21
|
+
this._ref = ref;
|
|
22
|
+
const slot = part.element;
|
|
23
|
+
if (this._slot !== slot) {
|
|
24
|
+
this._slot?.removeEventListener('slotchange', this.#onSlotChange);
|
|
25
|
+
this._slot = slot;
|
|
26
|
+
slot.addEventListener('slotchange', this.#onSlotChange);
|
|
27
|
+
}
|
|
28
|
+
this.#project();
|
|
29
|
+
}
|
|
30
|
+
disconnected() {
|
|
31
|
+
// the slot outlives renders; the listener is owned for its lifetime
|
|
32
|
+
// and removed when the part is cleared (template swap, disconnect)
|
|
33
|
+
this._slot?.removeEventListener('slotchange', this.#onSlotChange);
|
|
34
|
+
this._slot = undefined;
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
|
+
render(ref) {
|
|
38
|
+
return noChange;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const assignedRef = directive(AssignedRefDirective);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { noChange } from 'lit-html';
|
|
2
|
+
import { AsyncDirective, directive } from 'lit-html/async-directive.js';
|
|
3
|
+
import { invoke } from '../function';
|
|
4
|
+
const write = (item, name, value) => {
|
|
5
|
+
if (value == null) {
|
|
6
|
+
item.removeAttribute(name);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
item.setAttribute(name, value);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const forward = (attrs, item) => {
|
|
13
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
14
|
+
write(item, name, invoke(value, item));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Forwards attributes onto every flattened assigned element of the slot
|
|
19
|
+
* the directive is placed on — on each render (state changes re-render
|
|
20
|
+
* the slot) and on slot changes (different elements are assigned).
|
|
21
|
+
*
|
|
22
|
+
* Values are strings, nulls (removals), or functions of the assigned
|
|
23
|
+
* element. Placement is the configuration: the placed slot states which
|
|
24
|
+
* members receive the attributes. Slot semantics decide membership:
|
|
25
|
+
* slotting forwards through nested slots, wrappers do not — a
|
|
26
|
+
* non-forwarding wrapper receives the attributes itself without
|
|
27
|
+
* exposing state.
|
|
28
|
+
*/
|
|
29
|
+
class ForwardAttributesDirective extends AsyncDirective {
|
|
30
|
+
_slot;
|
|
31
|
+
_attrs;
|
|
32
|
+
#forward = () => {
|
|
33
|
+
if (!this._slot || !this._attrs) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const items = this._slot.assignedElements({ flatten: true });
|
|
37
|
+
for (const item of items) {
|
|
38
|
+
forward(this._attrs, item);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
#onSlotChange = () => this.#forward();
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
render(attrs) {
|
|
44
|
+
return noChange;
|
|
45
|
+
}
|
|
46
|
+
update(part, [attrs]) {
|
|
47
|
+
this._attrs = attrs;
|
|
48
|
+
const slot = part.element;
|
|
49
|
+
if (this._slot !== slot) {
|
|
50
|
+
this._slot?.removeEventListener('slotchange', this.#onSlotChange);
|
|
51
|
+
this._slot = slot;
|
|
52
|
+
slot.addEventListener('slotchange', this.#onSlotChange);
|
|
53
|
+
}
|
|
54
|
+
this.#forward();
|
|
55
|
+
return noChange;
|
|
56
|
+
}
|
|
57
|
+
disconnected() {
|
|
58
|
+
// the slot outlives renders; the listener is owned for its lifetime
|
|
59
|
+
// and removed when the part is cleared (template swap, disconnect)
|
|
60
|
+
this._slot?.removeEventListener('slotchange', this.#onSlotChange);
|
|
61
|
+
this._slot = undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export const forwardAttributes = directive(ForwardAttributesDirective);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.25.0",
|
|
4
4
|
"description": "Date, money and template management functions commonly needed in Cosmoz views.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polymer",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"./keybindings/*": "./dist/keybindings/*.js"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@pionjs/pion": "^2.
|
|
63
|
+
"@pionjs/pion": "^2.16.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@changesets/cli": "^3.0.2",
|