wrec 0.17.2 → 0.17.3
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/examples/table-wired.js +104 -0
- package/dist/examples/table-wired.js.map +1 -0
- package/dist/paths.js +21 -0
- package/dist/paths.js.map +1 -0
- package/dist/proxies.js +53 -0
- package/dist/proxies.js.map +1 -0
- package/dist/wrec-state.js +160 -0
- package/dist/wrec-state.js.map +1 -0
- package/dist/wrec.es.js +37 -36
- package/dist/wrec.js +1029 -0
- package/dist/wrec.js.map +1 -0
- package/dist/wrec.min.js +1 -0
- package/dist/wrec.umd.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { css, html, Wrec } from '../wrec';
|
|
2
|
+
class TableWired extends Wrec {
|
|
3
|
+
static properties = {
|
|
4
|
+
headings: { type: (Array) },
|
|
5
|
+
propNames: { type: (Array) },
|
|
6
|
+
data: { type: (Array) }
|
|
7
|
+
};
|
|
8
|
+
static css = css `
|
|
9
|
+
.sort-indicator {
|
|
10
|
+
color: white;
|
|
11
|
+
display: inline-block;
|
|
12
|
+
line-height: 1rem;
|
|
13
|
+
margin-left: 0.5rem;
|
|
14
|
+
width: 1rem;
|
|
15
|
+
}
|
|
16
|
+
table {
|
|
17
|
+
border-collapse: collapse;
|
|
18
|
+
}
|
|
19
|
+
td,
|
|
20
|
+
th {
|
|
21
|
+
border: 2px solid gray;
|
|
22
|
+
padding: 0.5rem;
|
|
23
|
+
}
|
|
24
|
+
th {
|
|
25
|
+
background-color: cornflowerblue;
|
|
26
|
+
color: white;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
> span {
|
|
29
|
+
pointer-events: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
// bind is needed here because makeTh uses "this".
|
|
34
|
+
static html = html `
|
|
35
|
+
<table>
|
|
36
|
+
<thead>
|
|
37
|
+
<tr>
|
|
38
|
+
this.headings.map(this.makeTh.bind(this))
|
|
39
|
+
</tr>
|
|
40
|
+
</thead>
|
|
41
|
+
<tbody>
|
|
42
|
+
this.data.map((_obj, index) => this.makeTr(index))
|
|
43
|
+
</tbody>
|
|
44
|
+
</table>
|
|
45
|
+
`;
|
|
46
|
+
sortAscending = true;
|
|
47
|
+
sortHeader = null;
|
|
48
|
+
makeTd(dataIndex, prop) {
|
|
49
|
+
const value = this.data[dataIndex][prop];
|
|
50
|
+
return html `<td>${value}</td>`;
|
|
51
|
+
}
|
|
52
|
+
makeTh(heading, index) {
|
|
53
|
+
return html `
|
|
54
|
+
<th
|
|
55
|
+
aria-label="sort by ${heading}"
|
|
56
|
+
data-property="${this.propNames[index]}"
|
|
57
|
+
onclick="sort"
|
|
58
|
+
role="button"
|
|
59
|
+
tabindex="0"
|
|
60
|
+
>
|
|
61
|
+
<span>${heading}</span>
|
|
62
|
+
<span class="sort-indicator"></span>
|
|
63
|
+
</th>
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
makeTr(dataIndex) {
|
|
67
|
+
return html `
|
|
68
|
+
<tr>
|
|
69
|
+
this.propNames.map(propName => this.makeTd(${dataIndex}, propName))
|
|
70
|
+
</tr>
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
sort(event) {
|
|
74
|
+
let th = event.target;
|
|
75
|
+
const property = th.getAttribute('data-property');
|
|
76
|
+
this.sortAscending = th === this.sortHeader ? !this.sortAscending : true;
|
|
77
|
+
this.data.sort((a, b) => {
|
|
78
|
+
const aValue = a[property];
|
|
79
|
+
const bValue = b[property];
|
|
80
|
+
let compare = typeof aValue === 'string'
|
|
81
|
+
? aValue.localeCompare(bValue)
|
|
82
|
+
: typeof aValue === 'number'
|
|
83
|
+
? aValue - bValue
|
|
84
|
+
: 0;
|
|
85
|
+
return this.sortAscending ? compare : -compare;
|
|
86
|
+
});
|
|
87
|
+
// Trigger the property set method by assigning a clone.
|
|
88
|
+
this.data = [...this.data];
|
|
89
|
+
// Clear sort indicator from previously selected header.
|
|
90
|
+
if (this.sortHeader) {
|
|
91
|
+
const sortIndicator = this.sortHeader.querySelector('.sort-indicator');
|
|
92
|
+
if (sortIndicator)
|
|
93
|
+
sortIndicator.textContent = '';
|
|
94
|
+
}
|
|
95
|
+
// Add sort indicator to currently selected header.
|
|
96
|
+
const sortIndicator = th.querySelector('.sort-indicator');
|
|
97
|
+
if (sortIndicator) {
|
|
98
|
+
sortIndicator.textContent = this.sortAscending ? '\u25B2' : '\u25BC';
|
|
99
|
+
}
|
|
100
|
+
this.sortHeader = th;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
TableWired.register();
|
|
104
|
+
//# sourceMappingURL=table-wired.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-wired.js","sourceRoot":"","sources":["../../src/examples/table-wired.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAIxC,MAAM,UAAW,SAAQ,IAAI;IAC3B,MAAM,CAAC,UAAU,GAAG;QAClB,QAAQ,EAAE,EAAC,IAAI,EAAE,CAAA,KAAa,CAAA,EAAC;QAC/B,SAAS,EAAE,EAAC,IAAI,EAAE,CAAA,KAAa,CAAA,EAAC;QAChC,IAAI,EAAE,EAAC,IAAI,EAAE,CAAA,KAAa,CAAA,EAAC;KAC5B,CAAC;IAEF,MAAM,CAAC,GAAG,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBf,CAAC;IAEF,kDAAkD;IAClD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAA;;;;;;;;;;;GAWjB,CAAC;IAEF,aAAa,GAAG,IAAI,CAAC;IACrB,UAAU,GAAgC,IAAI,CAAC;IAE/C,MAAM,CAAC,SAAiB,EAAE,IAAY;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO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U,EAAE,CAAC;YACpB,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;YACvE,IAAI,aAAa;gBAAE,aAAa,CAAC,WAAW,GAAG,EAAE,CAAC;QACpD,CAAC;QAED,mDAAmD;QACnD,MAAM,aAAa,GAAG,EAAE,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;QAC1D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvE,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;;AAGH,UAAU,CAAC,QAAQ,EAAE,CAAC"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getPathValue(obj, path) {
|
|
2
|
+
let value = obj;
|
|
3
|
+
for (const key of path.split('.')) {
|
|
4
|
+
value = value[key];
|
|
5
|
+
}
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
export function setPathValue(obj, path, value) {
|
|
9
|
+
const keys = path.split('.');
|
|
10
|
+
const lastIndex = keys.length - 1;
|
|
11
|
+
let target = obj;
|
|
12
|
+
keys.forEach((key, index) => {
|
|
13
|
+
if (index === lastIndex) {
|
|
14
|
+
target[key] = value;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
target = target[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,GAAgB,EAAE,IAAY;IACzD,IAAI,KAAK,GAAsB,GAAG,CAAC;IACnC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAgB,EAAE,IAAY,EAAE,KAAc;IACzE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,IAAI,MAAM,GAAQ,GAAG,CAAC;IACtB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/proxies.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a recursive Proxy to monitor deep property changes,
|
|
3
|
+
* passing the dot-separated path to the callback.
|
|
4
|
+
* @param {Object} target object to proxy
|
|
5
|
+
* @param {ProxyCallback} callback function to call when any property changes
|
|
6
|
+
* @param {string} [path=''] current path prefix, used internally for recursion
|
|
7
|
+
* @returns {Proxy} deep proxy
|
|
8
|
+
*/
|
|
9
|
+
export function createDeepProxy(target, callback, path = '') {
|
|
10
|
+
// Use a WeakMap to cache proxies and
|
|
11
|
+
// avoid infinite recursion or memory leaks.
|
|
12
|
+
const proxyCache = new WeakMap();
|
|
13
|
+
const deepHandler = {
|
|
14
|
+
// Intercept property reads.
|
|
15
|
+
// This creates nested proxies lazily.
|
|
16
|
+
get(target, key) {
|
|
17
|
+
const value = Reflect.get(target, key);
|
|
18
|
+
// If the value is a primitive, return it.
|
|
19
|
+
if (value === null || typeof value !== 'object')
|
|
20
|
+
return value;
|
|
21
|
+
// If a proxy for this object has already been created, return it.
|
|
22
|
+
const proxy = proxyCache.get(value);
|
|
23
|
+
if (proxy)
|
|
24
|
+
return proxy;
|
|
25
|
+
// Wrap the nested object in a new proxy and return it.
|
|
26
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
27
|
+
const nestedProxy = createDeepProxy(value, callback, newPath);
|
|
28
|
+
proxyCache.set(value, nestedProxy);
|
|
29
|
+
return nestedProxy;
|
|
30
|
+
},
|
|
31
|
+
// Intercept property writes.
|
|
32
|
+
set(target, key, newValue) {
|
|
33
|
+
const oldValue = Reflect.get(target, key);
|
|
34
|
+
if (oldValue !== newValue) {
|
|
35
|
+
Reflect.set(target, key, newValue);
|
|
36
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
37
|
+
callback(newPath, oldValue, newValue);
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return new Proxy(target, deepHandler);
|
|
43
|
+
}
|
|
44
|
+
// This converts a deep proxy to a plain object.
|
|
45
|
+
export function proxyToPlainObject(obj) {
|
|
46
|
+
const clone = {};
|
|
47
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
48
|
+
const isObject = typeof value === 'object' && value !== null;
|
|
49
|
+
clone[key] = isObject ? proxyToPlainObject(value) : value;
|
|
50
|
+
}
|
|
51
|
+
return clone;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=proxies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAmB,EACnB,QAAuB,EACvB,IAAI,GAAG,EAAE;IAET,qCAAqC;IACrC,4CAA4C;IAC5C,MAAM,UAAU,GAAG,IAAI,OAAO,EAAE,CAAC;IAEjC,MAAM,WAAW,GAAG;QAClB,4BAA4B;QAC5B,s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gD;AAChD,MAAM,UAAU,kBAAkB,CAAC,GAAgB;IACjD,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;QAC7D,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAoB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createDeepProxy, proxyToPlainObject } from './proxies.js';
|
|
2
|
+
const inBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
3
|
+
class WrecError extends Error {
|
|
4
|
+
}
|
|
5
|
+
// JavaScript does not allow creating a subclass of the Proxy class.
|
|
6
|
+
export class WrecState {
|
|
7
|
+
static #stateMap = new Map();
|
|
8
|
+
static {
|
|
9
|
+
if (inBrowser) {
|
|
10
|
+
window.addEventListener('beforeunload', () => {
|
|
11
|
+
// This persists the data in all WrecState objects
|
|
12
|
+
// created with the "persist" option set to true
|
|
13
|
+
// to sessionStorage as JSON strings so they can be
|
|
14
|
+
// restored after the user refreshes the page.
|
|
15
|
+
for (const [name, state] of this.#stateMap.entries()) {
|
|
16
|
+
if (state.#persist) {
|
|
17
|
+
const obj = proxyToPlainObject(state);
|
|
18
|
+
sessionStorage.setItem('wrec-state-' + name, JSON.stringify(obj));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// This static method is useful for accessing a specific WrecState object
|
|
25
|
+
// from the DevTools console. For example:
|
|
26
|
+
// state = WrecState.get('vault');
|
|
27
|
+
//
|
|
28
|
+
// WrecState object properties are accessed via nested Proxy objects
|
|
29
|
+
// so all changes can be monitored.
|
|
30
|
+
//
|
|
31
|
+
// Properties can be directly modified as follows:
|
|
32
|
+
// state.color = 'blue';
|
|
33
|
+
// state.team.leader.name = 'Mark';
|
|
34
|
+
static get(name) {
|
|
35
|
+
return this.#stateMap.get(name);
|
|
36
|
+
}
|
|
37
|
+
#id = Symbol('objectId');
|
|
38
|
+
// This cannot be replaced by a WeakMap<ChangeListener, Set<string>>
|
|
39
|
+
// because there is no way to iterate over the keys of a WeakMap.
|
|
40
|
+
#listenerHolders = [];
|
|
41
|
+
#name;
|
|
42
|
+
#persist;
|
|
43
|
+
#proxy;
|
|
44
|
+
constructor(name, persist, initial) {
|
|
45
|
+
if (!name)
|
|
46
|
+
throw new WrecError('name cannot be empty');
|
|
47
|
+
if (WrecState.#stateMap.has(name)) {
|
|
48
|
+
throw new WrecError(`WrecState with name "${name}" already exists`);
|
|
49
|
+
}
|
|
50
|
+
this.#name = name;
|
|
51
|
+
this.#persist = persist;
|
|
52
|
+
this.#proxy = createDeepProxy({}, this.#notifyListeners.bind(this));
|
|
53
|
+
// If there is existing state data in sessionStorage,
|
|
54
|
+
// use that instead of the supplied initial data.
|
|
55
|
+
if (persist && inBrowser) {
|
|
56
|
+
const json = sessionStorage.getItem('wrec-state-' + name);
|
|
57
|
+
const existingState = json ? JSON.parse(json) : undefined;
|
|
58
|
+
if (existingState)
|
|
59
|
+
initial = existingState;
|
|
60
|
+
}
|
|
61
|
+
if (initial) {
|
|
62
|
+
for (const [key, value] of Object.entries(initial)) {
|
|
63
|
+
this.addProperty(key, value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
WrecState.#stateMap.set(name, this);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param listener - object that has a "changed" method
|
|
70
|
+
* @param map - map from state property paths to component properties
|
|
71
|
+
*/
|
|
72
|
+
addListener(listener, map = {}) {
|
|
73
|
+
// Check if the listener was already added.
|
|
74
|
+
const listenerHolder = this.#listenerHolders.find(listenerHolder => listenerHolder.listenerRef.deref() === listener);
|
|
75
|
+
if (listenerHolder) {
|
|
76
|
+
// Add properties to existing propertyMap.
|
|
77
|
+
const { propertyMap } = listenerHolder;
|
|
78
|
+
for (const [key, value] of Object.entries(map)) {
|
|
79
|
+
propertyMap[key] = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Add a new listener.
|
|
84
|
+
this.#listenerHolders.push({
|
|
85
|
+
listenerRef: new WeakRef(listener),
|
|
86
|
+
propertyMap: map
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
addProperty(propName, initialValue) {
|
|
91
|
+
Object.defineProperty(this, propName, {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get() {
|
|
94
|
+
return this.#proxy[propName];
|
|
95
|
+
},
|
|
96
|
+
set(newValue) {
|
|
97
|
+
this.#proxy[propName] = newValue;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
this.#proxy[propName] = initialValue;
|
|
101
|
+
}
|
|
102
|
+
get id() {
|
|
103
|
+
return this.#id;
|
|
104
|
+
}
|
|
105
|
+
// This is useful for debugging from the DevTools console.
|
|
106
|
+
// For example: state.log()
|
|
107
|
+
log() {
|
|
108
|
+
console.log('WrecState:', this.#name);
|
|
109
|
+
for (const [key, value] of Object.entries(this.#proxy)) {
|
|
110
|
+
console.log(` ${key} = ${JSON.stringify(value)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
#notifyListeners(statePath, oldValue, newValue) {
|
|
114
|
+
/* For debugging ...
|
|
115
|
+
console.log(
|
|
116
|
+
`state.ts: path ${statePath} changed from`,
|
|
117
|
+
`${JSON.stringify(oldValue)} to ${JSON.stringify(newValue)}`
|
|
118
|
+
);
|
|
119
|
+
*/
|
|
120
|
+
const staleHolders = new Set();
|
|
121
|
+
for (const holder of this.#listenerHolders) {
|
|
122
|
+
const listener = holder.listenerRef.deref();
|
|
123
|
+
// If the WeakRef no longer refers to a valid object ...
|
|
124
|
+
if (!listener) {
|
|
125
|
+
staleHolders.add(holder);
|
|
126
|
+
// If the listener is an HTMLElement
|
|
127
|
+
// that is disconnected from the DOM ...
|
|
128
|
+
}
|
|
129
|
+
else if (inBrowser &&
|
|
130
|
+
listener instanceof HTMLElement &&
|
|
131
|
+
!listener.isConnected) {
|
|
132
|
+
staleHolders.add(holder);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const { propertyMap } = holder;
|
|
136
|
+
const keys = Object.keys(propertyMap);
|
|
137
|
+
if (keys.length === 0 || keys.includes(statePath)) {
|
|
138
|
+
listener.changed(statePath, propertyMap[statePath], newValue, oldValue, this);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// WARNING: If the element is connected again later,
|
|
143
|
+
// the WrecState useState method must be called again
|
|
144
|
+
// to re-add the element as a listener.
|
|
145
|
+
this.#listenerHolders = this.#listenerHolders.filter(holder => !staleHolders.has(holder));
|
|
146
|
+
}
|
|
147
|
+
removeListener(listener) {
|
|
148
|
+
this.#listenerHolders = this.#listenerHolders.filter(holder => {
|
|
149
|
+
return holder.listenerRef.deref() !== listener;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (inBrowser) {
|
|
154
|
+
const inDevelopment = process.env.NODE_ENV === 'development';
|
|
155
|
+
if (inDevelopment) {
|
|
156
|
+
// This makes the WrecState class available in the DevTools console.
|
|
157
|
+
window.WrecState = WrecState;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=wrec-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrec-state.js","sourceRoot":"","sources":["../src/wrec-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAEjE,MAAM,SAAS,GACb,OAAO,MAAM,KAAK,W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MAAM,CAAC,MAAM,CAAC,EAAE;YAC5D,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,QAAQ,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC;;AAGH,IAAI,SAAS,EAAE,CAAC;IACd,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;IAC7D,IAAI,aAAa,EAAE,CAAC;QAClB,oEAAoE;QACnE,MAAc,CAAC,SAAS,GAAG,SAAS,CAAC;IACxC,CAAC;AACH,CAAC"}
|
package/dist/wrec.es.js
CHANGED
|
@@ -15,7 +15,7 @@ class m extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
const k = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, P = "a-zA-Z_$", F = P + "0-9", b = `[${P}][${F}]*`, j = /<!--\s*(.*?)\s*-->/, _ = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, A = new RegExp(`^this\\.${b}$`), y = new RegExp(`this\\.${b}(\\.${b})*`, "g"), N = new RegExp(`this\\.${b}(\\.${b})*`), V = /* @__PURE__ */ new Set(["class", "style"]), $ = 5;
|
|
17
17
|
function I(r) {
|
|
18
|
-
return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof
|
|
18
|
+
return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof l;
|
|
19
19
|
}
|
|
20
20
|
function q(r, t, e) {
|
|
21
21
|
const s = document.createElement(r);
|
|
@@ -64,14 +64,14 @@ function H(r, t, e) {
|
|
|
64
64
|
if (S(e))
|
|
65
65
|
if (typeof e == "boolean") {
|
|
66
66
|
e ? r.setAttribute(s, s) : r.removeAttribute(s);
|
|
67
|
-
const i =
|
|
67
|
+
const i = l.getPropName(s);
|
|
68
68
|
r[i] = e;
|
|
69
69
|
} else {
|
|
70
70
|
const i = r.getAttribute(t), n = String(e);
|
|
71
71
|
i !== n && (r.setAttribute(s, n), s === "value" && v(r) && (r.value = n));
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
74
|
-
const i =
|
|
74
|
+
const i = l.getPropName(t);
|
|
75
75
|
r[i] = e;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -79,7 +79,7 @@ function T(r, t, e) {
|
|
|
79
79
|
const [s, o] = t.split(":");
|
|
80
80
|
r instanceof CSSRule ? r.style.setProperty(s, e) : (H(r, s, e), s === "value" && v(r) && (r.value = e));
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class l extends HTMLElement {
|
|
83
83
|
// This is used to lookup the camelCase property name
|
|
84
84
|
// that corresponds to a kebab-case attribute name.
|
|
85
85
|
static #p = /* @__PURE__ */ new Map();
|
|
@@ -100,18 +100,19 @@ class u extends HTMLElement {
|
|
|
100
100
|
// not one for only the Wrec class.
|
|
101
101
|
// This must be set in each Wrec subclass.
|
|
102
102
|
// It describes all the properties that a web component supports.
|
|
103
|
-
static properties
|
|
103
|
+
static properties;
|
|
104
104
|
// This is a map from properties to arrays of
|
|
105
105
|
// computed property expressions that use the property.
|
|
106
106
|
// It is used to update computed properties
|
|
107
107
|
// when the properties on which they depend are modified.
|
|
108
108
|
// See the method #updateComputedProperties.
|
|
109
109
|
// This map cannot be private.
|
|
110
|
-
static propToComputedMap
|
|
110
|
+
static propToComputedMap;
|
|
111
111
|
// This is a map from properties to expressions that refer to them.
|
|
112
112
|
// It is the sma for all instances of a component.
|
|
113
113
|
// This map cannot be private.
|
|
114
|
-
static propToExprsMap = null;
|
|
114
|
+
//static propToExprsMap: Map<string, string[]> | null = null;
|
|
115
|
+
static propToExprsMap;
|
|
115
116
|
static template = null;
|
|
116
117
|
#t = this.constructor;
|
|
117
118
|
// This is a map from expressions to references to them
|
|
@@ -134,7 +135,7 @@ class u extends HTMLElement {
|
|
|
134
135
|
// to the properties of different parent components.
|
|
135
136
|
// This is used to update a parent property
|
|
136
137
|
// when the corresponding child property value changes.
|
|
137
|
-
#
|
|
138
|
+
#u = /* @__PURE__ */ new Map();
|
|
138
139
|
constructor() {
|
|
139
140
|
super(), this.attachShadow({ mode: "open" });
|
|
140
141
|
const t = this.#t;
|
|
@@ -142,7 +143,7 @@ class u extends HTMLElement {
|
|
|
142
143
|
}
|
|
143
144
|
attributeChangedCallback(t, e, s) {
|
|
144
145
|
t === "disabled" && this.#m();
|
|
145
|
-
const o =
|
|
146
|
+
const o = l.getPropName(t);
|
|
146
147
|
if (this.#n(o)) {
|
|
147
148
|
const i = this.#y(o, String(s));
|
|
148
149
|
this[o] = i;
|
|
@@ -179,7 +180,7 @@ class u extends HTMLElement {
|
|
|
179
180
|
this.#M(o, i, e);
|
|
180
181
|
}
|
|
181
182
|
#M(t, e, s) {
|
|
182
|
-
const o =
|
|
183
|
+
const o = l.getAttrName(t), i = this.hasAttribute(o);
|
|
183
184
|
e.required && !i && this.#e(this, t, "is a required attribute");
|
|
184
185
|
let n = e.value;
|
|
185
186
|
this.hasOwnProperty(t) && (n = this[t], delete this[t]);
|
|
@@ -191,13 +192,13 @@ class u extends HTMLElement {
|
|
|
191
192
|
},
|
|
192
193
|
set(a) {
|
|
193
194
|
h === Number && typeof a == "string" && (a = C(a));
|
|
194
|
-
const
|
|
195
|
-
if (a ===
|
|
195
|
+
const u = this[f];
|
|
196
|
+
if (a === u) return;
|
|
196
197
|
this.#F(t, h, a), this[f] = a;
|
|
197
198
|
const { state: p, stateProp: g } = this.#t.properties[t];
|
|
198
199
|
g && O(p, g, a), this.#L(t), this.#x(t, h, a, o), this.#E(t), this.#H(t, a);
|
|
199
200
|
const M = this.#a[t];
|
|
200
|
-
M && this.setFormValue(M, String(a)), this.propertyChangedCallback(t,
|
|
201
|
+
M && this.setFormValue(M, String(a)), this.propertyChangedCallback(t, u, a), e.dispatch && this.dispatch("change", { [t]: a });
|
|
201
202
|
}
|
|
202
203
|
});
|
|
203
204
|
}
|
|
@@ -207,7 +208,7 @@ class u extends HTMLElement {
|
|
|
207
208
|
I(s) && (s.disabled = t);
|
|
208
209
|
}
|
|
209
210
|
disconnectedCallback() {
|
|
210
|
-
this.#s.clear(), this.#f.clear(), this.#
|
|
211
|
+
this.#s.clear(), this.#f.clear(), this.#u.clear();
|
|
211
212
|
}
|
|
212
213
|
dispatch(t, e) {
|
|
213
214
|
this.dispatchEvent(
|
|
@@ -229,15 +230,15 @@ class u extends HTMLElement {
|
|
|
229
230
|
return this.name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
230
231
|
}
|
|
231
232
|
#R(t) {
|
|
232
|
-
const e = t instanceof
|
|
233
|
+
const e = t instanceof l;
|
|
233
234
|
for (const s of t.getAttributeNames()) {
|
|
234
235
|
const o = t.getAttribute(s), i = this.#g(t, o);
|
|
235
236
|
if (i) {
|
|
236
237
|
const n = this[i];
|
|
237
238
|
n === void 0 && this.#c(t, s, i), t[i] = n;
|
|
238
239
|
let [h, c] = s.split(":");
|
|
239
|
-
h === "value" && (c ? (t["on" + c] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(h, this[i])) : c = "change"), e && t.#
|
|
240
|
-
|
|
240
|
+
h === "value" && (c ? (t["on" + c] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(h, this[i])) : c = "change"), e && t.#u.set(
|
|
241
|
+
l.getPropName(h),
|
|
241
242
|
i
|
|
242
243
|
);
|
|
243
244
|
}
|
|
@@ -313,12 +314,12 @@ class u extends HTMLElement {
|
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
static getAttrName(t) {
|
|
316
|
-
let e =
|
|
317
|
-
return e || (e = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(),
|
|
317
|
+
let e = l.#d.get(t);
|
|
318
|
+
return e || (e = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), l.#d.set(t, e)), e;
|
|
318
319
|
}
|
|
319
320
|
static getPropName(t) {
|
|
320
|
-
let e =
|
|
321
|
-
return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()),
|
|
321
|
+
let e = l.#p.get(t);
|
|
322
|
+
return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()), l.#p.set(t, e)), e;
|
|
322
323
|
}
|
|
323
324
|
#N(t, e, s) {
|
|
324
325
|
if (s.length !== 1) return;
|
|
@@ -330,9 +331,9 @@ class u extends HTMLElement {
|
|
|
330
331
|
h ? t["on" + h] === void 0 && this.#e(t, e, "refers to an unsupported event name") : h = "change";
|
|
331
332
|
const f = E(o);
|
|
332
333
|
t.addEventListener(h, (a) => {
|
|
333
|
-
const { target:
|
|
334
|
-
if (!
|
|
335
|
-
const p =
|
|
334
|
+
const { target: u } = a;
|
|
335
|
+
if (!u) return;
|
|
336
|
+
const p = u.value, { type: g } = this.#t.properties[f];
|
|
336
337
|
this[f] = g === Number ? C(p) : p, this.#E(f);
|
|
337
338
|
});
|
|
338
339
|
}
|
|
@@ -345,7 +346,7 @@ class u extends HTMLElement {
|
|
|
345
346
|
this.#R(s), s.firstElementChild || this.#P(s);
|
|
346
347
|
}
|
|
347
348
|
static get observedAttributes() {
|
|
348
|
-
const t = Object.keys(this.properties || {}).map(
|
|
349
|
+
const t = Object.keys(this.properties || {}).map(l.getAttrName);
|
|
349
350
|
return t.includes("disabled") || t.push("disabled"), t;
|
|
350
351
|
}
|
|
351
352
|
// Subclasses can override this to add functionality.
|
|
@@ -393,7 +394,7 @@ class u extends HTMLElement {
|
|
|
393
394
|
// in attribute values or the text content of elements!
|
|
394
395
|
#r(t, e, s = void 0) {
|
|
395
396
|
if (!t) return;
|
|
396
|
-
const o = this.#
|
|
397
|
+
const o = this.#l(e, s, t);
|
|
397
398
|
if (!o) {
|
|
398
399
|
const c = t.replaceAll("this..", "this.");
|
|
399
400
|
s ? T(e, s, c) : "textContent" in e && (e.textContent = c);
|
|
@@ -404,13 +405,13 @@ class u extends HTMLElement {
|
|
|
404
405
|
const f = E(c);
|
|
405
406
|
if (typeof this[f] == "function") return;
|
|
406
407
|
const a = i.propToExprsMap;
|
|
407
|
-
let
|
|
408
|
-
|
|
408
|
+
let u = a.get(f);
|
|
409
|
+
u || (u = [], a.set(f, u)), u.includes(t) || u.push(t);
|
|
409
410
|
});
|
|
410
411
|
for (const [c, f] of this.#s.entries())
|
|
411
412
|
for (const a of f) {
|
|
412
|
-
const
|
|
413
|
-
|
|
413
|
+
const u = a instanceof HTMLElement || a instanceof CSSStyleRule ? a : a.element;
|
|
414
|
+
u instanceof CSSStyleRule || u.isConnected || this.#s.set(
|
|
414
415
|
c,
|
|
415
416
|
f.filter((p) => p !== a)
|
|
416
417
|
);
|
|
@@ -479,7 +480,7 @@ class u extends HTMLElement {
|
|
|
479
480
|
// Update corresponding parent web component property if bound to one.
|
|
480
481
|
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
481
482
|
#H(t, e) {
|
|
482
|
-
const s = this.#
|
|
483
|
+
const s = this.#u.get(t);
|
|
483
484
|
if (!s) return;
|
|
484
485
|
const o = this.getRootNode();
|
|
485
486
|
if (!(o instanceof ShadowRoot)) return;
|
|
@@ -527,7 +528,7 @@ class u extends HTMLElement {
|
|
|
527
528
|
);
|
|
528
529
|
continue;
|
|
529
530
|
}
|
|
530
|
-
if (!e.has(
|
|
531
|
+
if (!e.has(l.getPropName(o))) {
|
|
531
532
|
if (o === "name") {
|
|
532
533
|
if (t.formAssociated) continue;
|
|
533
534
|
throw new m(
|
|
@@ -538,7 +539,7 @@ class u extends HTMLElement {
|
|
|
538
539
|
}
|
|
539
540
|
}
|
|
540
541
|
}
|
|
541
|
-
#
|
|
542
|
+
#l(t, e, s) {
|
|
542
543
|
const o = s.match(y);
|
|
543
544
|
if (o)
|
|
544
545
|
return o.forEach((i) => {
|
|
@@ -586,9 +587,9 @@ class u extends HTMLElement {
|
|
|
586
587
|
let h = n.slice(2);
|
|
587
588
|
h = h[0].toLowerCase() + h.slice(1).toLowerCase();
|
|
588
589
|
const c = i.value;
|
|
589
|
-
this.#
|
|
590
|
+
this.#l(s, n, c);
|
|
590
591
|
let f;
|
|
591
|
-
typeof this[c] == "function" ? f = (a) => this[c](a) : (this.#
|
|
592
|
+
typeof this[c] == "function" ? f = (a) => this[c](a) : (this.#l(s, n, c), f = () => this.#o(c)), s.addEventListener(h, f), o.push(n);
|
|
592
593
|
}
|
|
593
594
|
}
|
|
594
595
|
for (const i of o)
|
|
@@ -627,7 +628,7 @@ function Z(r, ...t) {
|
|
|
627
628
|
return e;
|
|
628
629
|
}
|
|
629
630
|
export {
|
|
630
|
-
|
|
631
|
+
l as Wrec,
|
|
631
632
|
q as createElement,
|
|
632
633
|
z as css,
|
|
633
634
|
Z as html
|