mosaic 1.0.2 → 1.0.5
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/LICENSE +21 -0
- package/README.md +63 -8
- package/cjs/attribute.js +90 -0
- package/cjs/constants.js +15 -0
- package/cjs/context.js +66 -0
- package/cjs/define.js +117 -0
- package/cjs/formControl.js +42 -0
- package/cjs/helpers.js +140 -0
- package/cjs/index.js +9 -0
- package/cjs/list.js +109 -0
- package/cjs/mergeSlots.js +37 -0
- package/cjs/proxy.js +42 -0
- package/cjs/render.js +388 -0
- package/cjs/token.js +63 -0
- package/cjs/update.js +128 -0
- package/dist/mosaic.js +1100 -0
- package/dist/mosaic.min.js +1 -0
- package/package.json +42 -25
- package/src/attribute.js +84 -0
- package/src/constants.js +5 -0
- package/src/context.js +60 -0
- package/src/define.js +116 -0
- package/src/formControl.js +36 -0
- package/src/helpers.js +123 -0
- package/src/index.js +1 -0
- package/src/list.js +100 -0
- package/src/mergeSlots.js +31 -0
- package/src/proxy.js +36 -0
- package/src/render.js +390 -0
- package/src/token.js +55 -0
- package/src/update.js +122 -0
- package/SCRATCH.md +0 -31
- package/cli.js +0 -17
- package/conf.json +0 -0
- package/docs/assets/css/main.css +0 -2638
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/index.html +0 -111
- package/docs/modules.html +0 -131
- package/example/components/x-drawer.html +0 -41
- package/example/mosaic/templates/mocha/index.html +0 -39
- package/example/mosaic/tests.d.ts +0 -13
- package/example/mosaic/tests.js +0 -28
- package/example/mosaic/website.d.ts +0 -31
- package/example/mosaic/website.js +0 -64
- package/example/mosaic.config.d.ts +0 -7
- package/example/mosaic.config.js +0 -8
- package/example/package-lock.json +0 -899
- package/example/package.json +0 -20
- package/example/pages/index.html +0 -12
- package/example/test/x-drawer.d.ts +0 -0
- package/example/test/x-drawer.js +0 -94
- package/index.d.ts +0 -85
- package/index.js +0 -123
- package/index.wdocs.js +0 -37
- package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Light-webfont.eot +0 -0
- package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Light-webfont.woff +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/out/global.html +0 -912
- package/out/index.html +0 -65
- package/out/index.js.html +0 -239
- package/out/scripts/linenumber.js +0 -25
- package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/out/scripts/prettify/lang-css.js +0 -2
- package/out/scripts/prettify/prettify.js +0 -28
- package/out/styles/jsdoc-default.css +0 -358
- package/out/styles/prettify-jsdoc.css +0 -111
- package/out/styles/prettify-tomorrow.css +0 -132
- package/tsconfig.json +0 -11
package/dist/mosaic.js
ADDED
|
@@ -0,0 +1,1100 @@
|
|
|
1
|
+
function systemReducer(state, action) {
|
|
2
|
+
switch (action.type) {
|
|
3
|
+
case "SET": {
|
|
4
|
+
const { name, value } = action.payload;
|
|
5
|
+
return {
|
|
6
|
+
...state,
|
|
7
|
+
[name]: value,
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
case "MERGE": {
|
|
11
|
+
return {
|
|
12
|
+
...state,
|
|
13
|
+
...action.payload,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
|
|
21
|
+
Notes
|
|
22
|
+
|
|
23
|
+
- any call to dispatch will immediately invoke the reducer
|
|
24
|
+
- any call to dispatch within middleware is also immediately processed
|
|
25
|
+
- SET and MERGE are not interceptable by middleware
|
|
26
|
+
- middleware functions are assumed to call next synchronously
|
|
27
|
+
- the render function (subscriber) is invoked once for every call to dispatch
|
|
28
|
+
- the render function is debounced
|
|
29
|
+
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
function configure(
|
|
33
|
+
{ update = {}, middleware = [], derivations = {}, initialState = {} },
|
|
34
|
+
node
|
|
35
|
+
) {
|
|
36
|
+
let subscribers = [];
|
|
37
|
+
let state;
|
|
38
|
+
let updatedCallback = () => {};
|
|
39
|
+
|
|
40
|
+
function updateState(o) {
|
|
41
|
+
state = { ...o };
|
|
42
|
+
for (let k in derivations) {
|
|
43
|
+
state[k] = derivations[k](o);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
updateState(initialState);
|
|
48
|
+
|
|
49
|
+
function getState() {
|
|
50
|
+
return { ...state }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function subscribe(fn) {
|
|
54
|
+
subscribers.push(fn);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function flush() {
|
|
58
|
+
subscribers.forEach((fn) => fn());
|
|
59
|
+
subscribers = [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onUpdate(fn) {
|
|
63
|
+
updatedCallback = fn;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function dispatch(action) {
|
|
67
|
+
const { type } = action;
|
|
68
|
+
if (type === "SET" || type === "MERGE") {
|
|
69
|
+
updateState(systemReducer(getState(), action));
|
|
70
|
+
} else {
|
|
71
|
+
if (middleware.length) {
|
|
72
|
+
let mw = middleware.slice();
|
|
73
|
+
|
|
74
|
+
let next = (action) => {
|
|
75
|
+
if (mw.length) {
|
|
76
|
+
let x = mw.shift();
|
|
77
|
+
|
|
78
|
+
if (action.type in x) {
|
|
79
|
+
x[action.type](action, next, {
|
|
80
|
+
getState,
|
|
81
|
+
dispatch,
|
|
82
|
+
afterNextRender: subscribe,
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
next(action);
|
|
86
|
+
}
|
|
87
|
+
} else if (action.type in update) {
|
|
88
|
+
updateState(update[action.type](getState(), action));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
let x = mw.shift();
|
|
93
|
+
|
|
94
|
+
if (type in x) {
|
|
95
|
+
x[type](action, next, {
|
|
96
|
+
getState,
|
|
97
|
+
dispatch,
|
|
98
|
+
afterNextRender: subscribe,
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
next(action);
|
|
102
|
+
}
|
|
103
|
+
} else if (type in update) {
|
|
104
|
+
updateState(update[type](getState(), action));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
updatedCallback();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (let actionName in update) {
|
|
111
|
+
if (actionName.startsWith("$")) {
|
|
112
|
+
node.addEventListener(actionName, ({ detail }) => dispatch(detail));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
dispatch,
|
|
118
|
+
getState,
|
|
119
|
+
onUpdate,
|
|
120
|
+
flush,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const TEXT = 1;
|
|
125
|
+
const ATTRIBUTE = 2;
|
|
126
|
+
const INPUT = 3;
|
|
127
|
+
const EVENT = 4;
|
|
128
|
+
const REPEAT = 5;
|
|
129
|
+
|
|
130
|
+
const updateFormControl = (node, value) => {
|
|
131
|
+
if (node.nodeName === "SELECT") {
|
|
132
|
+
Array.from(node.querySelectorAll("option")).forEach((option) => {
|
|
133
|
+
option.selected = value.includes(option.value);
|
|
134
|
+
});
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let checked;
|
|
139
|
+
|
|
140
|
+
switch (node.getAttribute("type")) {
|
|
141
|
+
case "checkbox":
|
|
142
|
+
checked = value;
|
|
143
|
+
if (node.checked === checked) break
|
|
144
|
+
if (checked) {
|
|
145
|
+
node.setAttribute("checked", "");
|
|
146
|
+
} else {
|
|
147
|
+
node.removeAttribute("checked");
|
|
148
|
+
}
|
|
149
|
+
break
|
|
150
|
+
case "radio":
|
|
151
|
+
checked = value === node.getAttribute("value");
|
|
152
|
+
if (node.checked === checked) break
|
|
153
|
+
node.checked = checked;
|
|
154
|
+
if (checked) {
|
|
155
|
+
node.setAttribute("checked", "");
|
|
156
|
+
} else {
|
|
157
|
+
node.removeAttribute("checked");
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
default:
|
|
161
|
+
if (node.value === value) break
|
|
162
|
+
node.setAttribute("value", (node.value = value || ""));
|
|
163
|
+
break
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const last = (v = []) => v[v.length - 1];
|
|
168
|
+
|
|
169
|
+
const isWhitespace = (node) => {
|
|
170
|
+
return node.nodeType === node.TEXT_NODE && node.nodeValue.trim() === ""
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const walk = (node, callback, deep = true) => {
|
|
174
|
+
if (!node) return
|
|
175
|
+
if (!isWhitespace(node)) {
|
|
176
|
+
let v = callback(node);
|
|
177
|
+
if (v === false) return
|
|
178
|
+
if (v?.nodeName) return walk(v, callback, deep)
|
|
179
|
+
}
|
|
180
|
+
if (deep) walk(node.firstChild, callback, deep);
|
|
181
|
+
walk(node.nextSibling, callback, deep);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const transformBrackets = (str = "") => {
|
|
185
|
+
let parts = str.split(/(\[[^\]]+\])/).filter((v) => v);
|
|
186
|
+
return parts.reduce((a, part) => {
|
|
187
|
+
let v = part.charAt(0) === "[" ? "." + part.replace(/\./g, ":") : part;
|
|
188
|
+
return a + v
|
|
189
|
+
}, "")
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const getTarget = (path, target) => {
|
|
193
|
+
let parts = transformBrackets(path)
|
|
194
|
+
.split(".")
|
|
195
|
+
.map((k) => {
|
|
196
|
+
if (k.charAt(0) === "[") {
|
|
197
|
+
let p = k.slice(1, -1).replace(/:/g, ".");
|
|
198
|
+
return getValueAtPath(p, target)
|
|
199
|
+
} else {
|
|
200
|
+
return k
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
let t =
|
|
205
|
+
parts.slice(0, -1).reduce((o, k) => {
|
|
206
|
+
return o && o[k]
|
|
207
|
+
}, target) || target;
|
|
208
|
+
return [t, last(parts)]
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const getValueAtPath = (path, target) => {
|
|
212
|
+
let [a, b] = getTarget(path, target);
|
|
213
|
+
let v = a?.[b];
|
|
214
|
+
if (typeof v === "function") return v.bind(a)
|
|
215
|
+
return v
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const fragmentFromTemplate = (v) => {
|
|
219
|
+
if (typeof v === "string") {
|
|
220
|
+
let tpl = document.createElement("template");
|
|
221
|
+
tpl.innerHTML = v.trim();
|
|
222
|
+
return tpl.content
|
|
223
|
+
}
|
|
224
|
+
if (v.nodeName === "TEMPLATE") return v.cloneNode(true).content
|
|
225
|
+
if (v.nodeName === "defs") return v.firstElementChild.cloneNode(true)
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const debounce = (fn) => {
|
|
229
|
+
let wait = false;
|
|
230
|
+
let invoke = false;
|
|
231
|
+
return () => {
|
|
232
|
+
if (wait) {
|
|
233
|
+
invoke = true;
|
|
234
|
+
} else {
|
|
235
|
+
wait = true;
|
|
236
|
+
fn();
|
|
237
|
+
requestAnimationFrame(() => {
|
|
238
|
+
if (invoke) fn();
|
|
239
|
+
wait = false;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const isPrimitive = (v) => v === null || typeof v !== "object";
|
|
246
|
+
|
|
247
|
+
const typeOf = (v) =>
|
|
248
|
+
Object.prototype.toString.call(v).match(/\s(.+[^\]])/)[1];
|
|
249
|
+
|
|
250
|
+
const pascalToKebab = (string) =>
|
|
251
|
+
string.replace(/[\w]([A-Z])/g, function (m) {
|
|
252
|
+
return m[0] + "-" + m[1].toLowerCase()
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const kebabToPascal = (string) =>
|
|
256
|
+
string.replace(/[\w]-([\w])/g, function (m) {
|
|
257
|
+
return m[0] + m[2].toUpperCase()
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const applyAttribute = (node, name, value) => {
|
|
261
|
+
name = pascalToKebab(name);
|
|
262
|
+
|
|
263
|
+
if (typeof value === "boolean") {
|
|
264
|
+
if (name.startsWith("aria-")) {
|
|
265
|
+
value = "" + value;
|
|
266
|
+
} else if (value) {
|
|
267
|
+
value = "";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
272
|
+
node.setAttribute(name, value);
|
|
273
|
+
} else {
|
|
274
|
+
node.removeAttribute(name);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const attributeToProp = (k, v) => {
|
|
279
|
+
let name = kebabToPascal(k);
|
|
280
|
+
if (v === "") v = true;
|
|
281
|
+
if (k.startsWith("aria-")) {
|
|
282
|
+
if (v === "true") v = true;
|
|
283
|
+
if (v === "false") v = false;
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
name,
|
|
287
|
+
value: v,
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
function parseEach(node) {
|
|
292
|
+
let each = node.getAttribute("each");
|
|
293
|
+
let m = each?.match(/(.+)\s+in\s+(.+)/);
|
|
294
|
+
if (!m) {
|
|
295
|
+
if (!each) return m
|
|
296
|
+
return {
|
|
297
|
+
path: each.trim(),
|
|
298
|
+
key: node.getAttribute("key"),
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
let [_, left, right] = m;
|
|
302
|
+
let parts = left.match(/\(([^\)]+)\)/);
|
|
303
|
+
let [a, b] = (parts ? parts[1].split(",") : [left]).map((v) => v.trim());
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
path: right.trim(),
|
|
307
|
+
identifier: b ? b : a,
|
|
308
|
+
index: b ? a : b,
|
|
309
|
+
key: node.getAttribute("key"),
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const getBlockSize = (template) => {
|
|
314
|
+
let i = 0;
|
|
315
|
+
walk(template.content?.firstChild || template.firstChild, () => i++, false);
|
|
316
|
+
return i
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const nextNonWhitespaceSibling = (node) => {
|
|
320
|
+
return isWhitespace(node.nextSibling)
|
|
321
|
+
? nextNonWhitespaceSibling(node.nextSibling)
|
|
322
|
+
: node.nextSibling
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const getBlockFragments = (template, numBlocks) => {
|
|
326
|
+
let blockSize = getBlockSize(template);
|
|
327
|
+
|
|
328
|
+
let r = [];
|
|
329
|
+
if (numBlocks) {
|
|
330
|
+
while (numBlocks--) {
|
|
331
|
+
let f = document.createDocumentFragment();
|
|
332
|
+
let n = blockSize;
|
|
333
|
+
while (n--) {
|
|
334
|
+
f.appendChild(nextNonWhitespaceSibling(template));
|
|
335
|
+
}
|
|
336
|
+
r.push(f);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return r
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const getBlocks = (template) => {
|
|
343
|
+
let numBlocks = template.getAttribute("length");
|
|
344
|
+
let blockSize = getBlockSize(template);
|
|
345
|
+
let r = [];
|
|
346
|
+
let node = template;
|
|
347
|
+
if (numBlocks) {
|
|
348
|
+
while (numBlocks--) {
|
|
349
|
+
let f = [];
|
|
350
|
+
let n = blockSize;
|
|
351
|
+
while (n--) {
|
|
352
|
+
node = nextNonWhitespaceSibling(node);
|
|
353
|
+
f.push(node);
|
|
354
|
+
}
|
|
355
|
+
r.push(f);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return r
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const compareKeyedLists = (key, a = [], b = []) => {
|
|
362
|
+
let delta = b.map(([k, item]) =>
|
|
363
|
+
!key ? (k in a ? k : -1) : a.findIndex(([_, v]) => v[key] === item[key])
|
|
364
|
+
);
|
|
365
|
+
if (a.length !== b.length || !delta.every((a, b) => a === b)) return delta
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
function lastChild(v) {
|
|
369
|
+
return (v.nodeType === v.DOCUMENT_FRAGMENT_NODE && v.lastChild) || v
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const updateList = (template, delta, entries, createListItem) => {
|
|
373
|
+
let n = template.getAttribute("length") || 0;
|
|
374
|
+
let blocks = getBlockFragments(template, n);
|
|
375
|
+
let t = template;
|
|
376
|
+
|
|
377
|
+
delta.forEach((i, newIndex) => {
|
|
378
|
+
let frag =
|
|
379
|
+
i === -1
|
|
380
|
+
? createListItem(entries[newIndex][1], entries[newIndex][0])
|
|
381
|
+
: blocks[i];
|
|
382
|
+
let x = lastChild(frag);
|
|
383
|
+
t.after(frag);
|
|
384
|
+
t = x;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
template.setAttribute("length", delta.length);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const VALUE = 1;
|
|
391
|
+
const KEY = 2;
|
|
392
|
+
const FUNCTION = 3;
|
|
393
|
+
|
|
394
|
+
const hasMustache = (v) => v.match(/({{[^{}]+}})/);
|
|
395
|
+
|
|
396
|
+
const getParts = (value) =>
|
|
397
|
+
value
|
|
398
|
+
.trim()
|
|
399
|
+
.split(/({{[^{}]+}})/)
|
|
400
|
+
.filter((v) => v)
|
|
401
|
+
.map((value) => {
|
|
402
|
+
let match = value.match(/{{([^{}]+)}}/);
|
|
403
|
+
|
|
404
|
+
if (!match)
|
|
405
|
+
return {
|
|
406
|
+
type: VALUE,
|
|
407
|
+
value,
|
|
408
|
+
negated: false,
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
value = match[1].trim();
|
|
412
|
+
let negated = value.charAt(0) === "!";
|
|
413
|
+
if (negated) value = value.slice(1);
|
|
414
|
+
|
|
415
|
+
return {
|
|
416
|
+
type: KEY,
|
|
417
|
+
value,
|
|
418
|
+
negated,
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const getValueFromParts = (target, parts) => {
|
|
423
|
+
return parts.reduce((a, part) => {
|
|
424
|
+
let { type, value, negated } = part;
|
|
425
|
+
|
|
426
|
+
let v;
|
|
427
|
+
|
|
428
|
+
if (type === VALUE) v = value;
|
|
429
|
+
if (type === KEY) {
|
|
430
|
+
v = getValueAtPath(value, target);
|
|
431
|
+
}
|
|
432
|
+
if (type === FUNCTION) {
|
|
433
|
+
let args = part.args.map((value) => getValueAtPath(value, target));
|
|
434
|
+
|
|
435
|
+
v = getValueAtPath(part.method, target)?.(...args);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (negated) v = !v;
|
|
439
|
+
|
|
440
|
+
return a || a === 0 ? a + v : v
|
|
441
|
+
}, "")
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const pascalToKebab$1 = (string) =>
|
|
445
|
+
string.replace(/[\w]([A-Z])/g, function (m) {
|
|
446
|
+
return m[0] + "-" + m[1].toLowerCase()
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const kebabToPascal$1 = (string) =>
|
|
450
|
+
string.replace(/[\w]-([\w])/g, function (m) {
|
|
451
|
+
return m[0] + m[2].toUpperCase()
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const parseStyles = (value) => {
|
|
455
|
+
let type = typeof value;
|
|
456
|
+
|
|
457
|
+
if (type === "string")
|
|
458
|
+
return value.split(";").reduce((o, value) => {
|
|
459
|
+
const [k, v] = value.split(":").map((v) => v.trim());
|
|
460
|
+
if (k) o[k] = v;
|
|
461
|
+
return o
|
|
462
|
+
}, {})
|
|
463
|
+
|
|
464
|
+
if (type === "object") return value
|
|
465
|
+
|
|
466
|
+
return {}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const joinStyles = (value) =>
|
|
470
|
+
Object.entries(value)
|
|
471
|
+
.map(([k, v]) => `${k}: ${v};`)
|
|
472
|
+
.join(" ");
|
|
473
|
+
|
|
474
|
+
const convertStyles = (o) =>
|
|
475
|
+
Object.keys(o).reduce((a, k) => {
|
|
476
|
+
a[pascalToKebab$1(k)] = o[k];
|
|
477
|
+
return a
|
|
478
|
+
}, {});
|
|
479
|
+
|
|
480
|
+
const applyAttribute$1 = (node, name, value) => {
|
|
481
|
+
if (name === "style") {
|
|
482
|
+
value = joinStyles(
|
|
483
|
+
convertStyles({
|
|
484
|
+
...parseStyles(node.getAttribute("style")),
|
|
485
|
+
...parseStyles(value),
|
|
486
|
+
})
|
|
487
|
+
);
|
|
488
|
+
} else if (name === "class") {
|
|
489
|
+
switch (typeOf(value)) {
|
|
490
|
+
case "Array":
|
|
491
|
+
value = value.join(" ");
|
|
492
|
+
break
|
|
493
|
+
case "Object":
|
|
494
|
+
value = Object.keys(value)
|
|
495
|
+
.reduce((a, k) => {
|
|
496
|
+
if (value[k]) a.push(k);
|
|
497
|
+
return a
|
|
498
|
+
}, [])
|
|
499
|
+
.join(" ");
|
|
500
|
+
break
|
|
501
|
+
}
|
|
502
|
+
} else if (!isPrimitive(value)) {
|
|
503
|
+
return (node[kebabToPascal$1(name)] = value)
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
name = pascalToKebab$1(name);
|
|
507
|
+
|
|
508
|
+
if (typeof value === "boolean") {
|
|
509
|
+
if (name.startsWith("aria-")) {
|
|
510
|
+
value = "" + value;
|
|
511
|
+
} else if (value) {
|
|
512
|
+
value = "";
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
let current = node.getAttribute(name);
|
|
517
|
+
|
|
518
|
+
if (value === current) return
|
|
519
|
+
|
|
520
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
521
|
+
node.setAttribute(name, value);
|
|
522
|
+
} else {
|
|
523
|
+
node.removeAttribute(name);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const handler = ({ path, identifier, key, index, i, k }) => ({
|
|
528
|
+
get(target, property) {
|
|
529
|
+
let x = getValueAtPath(path, target);
|
|
530
|
+
|
|
531
|
+
// x === the collection
|
|
532
|
+
|
|
533
|
+
if (property === identifier) {
|
|
534
|
+
for (let n in x) {
|
|
535
|
+
let v = x[n];
|
|
536
|
+
if (key) {
|
|
537
|
+
if (v[key] === k) return v
|
|
538
|
+
} else {
|
|
539
|
+
if (n == i) return v
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (property === index) {
|
|
545
|
+
for (let n in x) {
|
|
546
|
+
let v = x[n];
|
|
547
|
+
if (key) {
|
|
548
|
+
if (v[key] === k) return n
|
|
549
|
+
} else {
|
|
550
|
+
if (n == i) return n
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
let t = key ? x.find((v) => v[key] === k) : x[i];
|
|
556
|
+
if (t?.hasOwnProperty?.(property)) return t[property]
|
|
557
|
+
|
|
558
|
+
return Reflect.get(...arguments)
|
|
559
|
+
},
|
|
560
|
+
set(target, property, value) {
|
|
561
|
+
let x = getValueAtPath(path, target);
|
|
562
|
+
let t = key ? x.find((v) => v[key] === k) : x[i];
|
|
563
|
+
if (t && !isPrimitive(t)) {
|
|
564
|
+
t[property] = value;
|
|
565
|
+
return true
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return Reflect.set(...arguments)
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
const createContext = (v = []) => {
|
|
573
|
+
let context = v;
|
|
574
|
+
return {
|
|
575
|
+
get: () => context,
|
|
576
|
+
push: (v) => context.push(v),
|
|
577
|
+
wrap: (state) => {
|
|
578
|
+
return context.reduce(
|
|
579
|
+
(target, ctx) => new Proxy(target, handler(ctx)),
|
|
580
|
+
state
|
|
581
|
+
)
|
|
582
|
+
},
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
const render = (
|
|
587
|
+
target,
|
|
588
|
+
{ getState, dispatch },
|
|
589
|
+
template,
|
|
590
|
+
updatedCallback,
|
|
591
|
+
beforeMountCallback
|
|
592
|
+
) => {
|
|
593
|
+
let observer = () => {
|
|
594
|
+
let subscribers = new Set();
|
|
595
|
+
return {
|
|
596
|
+
publish: (cb) => {
|
|
597
|
+
for (let fn of subscribers) {
|
|
598
|
+
fn();
|
|
599
|
+
}
|
|
600
|
+
cb?.();
|
|
601
|
+
},
|
|
602
|
+
subscribe(fn) {
|
|
603
|
+
subscribers.add(fn);
|
|
604
|
+
},
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const createSubscription = {
|
|
609
|
+
[TEXT]: ({ value, node, context }, { getState }) => {
|
|
610
|
+
return {
|
|
611
|
+
handler: () => {
|
|
612
|
+
let state = context ? context.wrap(getState()) : getState();
|
|
613
|
+
let a = node.textContent;
|
|
614
|
+
let b = getValueFromParts(state, getParts(value));
|
|
615
|
+
if (a !== b) node.textContent = b;
|
|
616
|
+
},
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
[ATTRIBUTE]: ({ value, node, name, context }, { getState }) => {
|
|
620
|
+
return {
|
|
621
|
+
handler: () => {
|
|
622
|
+
let state = context ? context.wrap(getState()) : getState();
|
|
623
|
+
let b = getValueFromParts(state, getParts(value));
|
|
624
|
+
|
|
625
|
+
applyAttribute$1(node, name, b);
|
|
626
|
+
|
|
627
|
+
if (node.nodeName === "OPTION") {
|
|
628
|
+
let path = node.parentNode.getAttribute("name");
|
|
629
|
+
let selected = getValueAtPath(path, state);
|
|
630
|
+
node.selected = selected === b;
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
[INPUT]: ({ node, path, context }, { getState, dispatch }) => {
|
|
636
|
+
node.addEventListener("input", () => {
|
|
637
|
+
let value =
|
|
638
|
+
node.getAttribute("type") === "checkbox" ? node.checked : node.value;
|
|
639
|
+
|
|
640
|
+
if (value.trim?.().length && !isNaN(value)) value = +value;
|
|
641
|
+
|
|
642
|
+
if (context) {
|
|
643
|
+
let state = context.wrap(getState());
|
|
644
|
+
state[path] = value;
|
|
645
|
+
dispatch({
|
|
646
|
+
type: "MERGE",
|
|
647
|
+
payload: state,
|
|
648
|
+
});
|
|
649
|
+
} else {
|
|
650
|
+
dispatch({
|
|
651
|
+
type: "SET",
|
|
652
|
+
payload: {
|
|
653
|
+
name: path,
|
|
654
|
+
value,
|
|
655
|
+
context,
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
return {
|
|
662
|
+
handler: () => {
|
|
663
|
+
let state = context ? context.wrap(getState()) : getState();
|
|
664
|
+
updateFormControl(node, getValueAtPath(path, state));
|
|
665
|
+
},
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
[EVENT]: (
|
|
669
|
+
{ node, eventType, actionType, context },
|
|
670
|
+
{ dispatch, getState }
|
|
671
|
+
) => {
|
|
672
|
+
/*
|
|
673
|
+
|
|
674
|
+
NB that context is only passed for local actions not prefixed with "$"
|
|
675
|
+
|
|
676
|
+
*/
|
|
677
|
+
|
|
678
|
+
node.addEventListener(eventType, (event) => {
|
|
679
|
+
let isGlobal = actionType.startsWith("$");
|
|
680
|
+
|
|
681
|
+
let action = {
|
|
682
|
+
type: actionType,
|
|
683
|
+
event,
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
if (!isGlobal)
|
|
687
|
+
action.context = context ? context.wrap(getState()) : getState();
|
|
688
|
+
|
|
689
|
+
dispatch(action);
|
|
690
|
+
|
|
691
|
+
if (isGlobal) {
|
|
692
|
+
node.dispatchEvent(
|
|
693
|
+
new CustomEvent(actionType, {
|
|
694
|
+
detail: action,
|
|
695
|
+
bubbles: true,
|
|
696
|
+
})
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return {
|
|
701
|
+
handler: () => {},
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
[REPEAT]: (
|
|
705
|
+
{
|
|
706
|
+
node,
|
|
707
|
+
context,
|
|
708
|
+
map,
|
|
709
|
+
path,
|
|
710
|
+
identifier,
|
|
711
|
+
index,
|
|
712
|
+
key,
|
|
713
|
+
blockIndex,
|
|
714
|
+
hydrate,
|
|
715
|
+
pickupNode,
|
|
716
|
+
},
|
|
717
|
+
{ getState }
|
|
718
|
+
) => {
|
|
719
|
+
let oldValue;
|
|
720
|
+
node.$t = blockIndex - 1;
|
|
721
|
+
|
|
722
|
+
const initialiseBlock = (rootNode, i, k, exitNode) => {
|
|
723
|
+
walk(
|
|
724
|
+
rootNode,
|
|
725
|
+
multi(
|
|
726
|
+
(node) => {
|
|
727
|
+
if (node === exitNode) return false
|
|
728
|
+
},
|
|
729
|
+
bindAll(
|
|
730
|
+
map,
|
|
731
|
+
hydrate,
|
|
732
|
+
createContext(
|
|
733
|
+
(context?.get() || []).concat({
|
|
734
|
+
path,
|
|
735
|
+
identifier,
|
|
736
|
+
key,
|
|
737
|
+
index,
|
|
738
|
+
i,
|
|
739
|
+
k,
|
|
740
|
+
})
|
|
741
|
+
)
|
|
742
|
+
),
|
|
743
|
+
(child) => (child.$t = blockIndex)
|
|
744
|
+
)
|
|
745
|
+
);
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
function firstChild(v) {
|
|
749
|
+
return (v.nodeType === v.DOCUMENT_FRAGMENT_NODE && v.firstChild) || v
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const createListItem = (datum, i) => {
|
|
753
|
+
let k = datum[key];
|
|
754
|
+
let frag = fragmentFromTemplate(node);
|
|
755
|
+
initialiseBlock(firstChild(frag), i, k);
|
|
756
|
+
return frag
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
if (hydrate) {
|
|
760
|
+
let x = getValueAtPath(path, getState());
|
|
761
|
+
let blocks = getBlocks(node);
|
|
762
|
+
|
|
763
|
+
blocks.forEach((block, i) => {
|
|
764
|
+
let datum = x[i];
|
|
765
|
+
let k = datum?.[key];
|
|
766
|
+
initialiseBlock(block[0], i, k, last(block).nextSibling);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
pickupNode = last(last(blocks)).nextSibling;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return {
|
|
773
|
+
handler: () => {
|
|
774
|
+
let state = context ? context.wrap(getState()) : getState();
|
|
775
|
+
|
|
776
|
+
const newValue = Object.entries(getValueAtPath(path, state) || []);
|
|
777
|
+
const delta = compareKeyedLists(key, oldValue, newValue);
|
|
778
|
+
|
|
779
|
+
if (delta) {
|
|
780
|
+
updateList(node, delta, newValue, createListItem);
|
|
781
|
+
}
|
|
782
|
+
oldValue = newValue.slice(0);
|
|
783
|
+
},
|
|
784
|
+
pickupNode,
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
const mediator = () => {
|
|
790
|
+
const o = observer();
|
|
791
|
+
return {
|
|
792
|
+
bind(v) {
|
|
793
|
+
let s = createSubscription[v.type](v, { getState, dispatch });
|
|
794
|
+
o.subscribe(s.handler);
|
|
795
|
+
return s
|
|
796
|
+
},
|
|
797
|
+
// scheduleUpdate: debounce((state, cb) => {
|
|
798
|
+
// return o.publish(state, cb)
|
|
799
|
+
// }),
|
|
800
|
+
update(cb) {
|
|
801
|
+
return o.publish(cb)
|
|
802
|
+
},
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
const { bind, update } = mediator();
|
|
807
|
+
|
|
808
|
+
let blockCount = 0;
|
|
809
|
+
|
|
810
|
+
const parse = (frag) => {
|
|
811
|
+
let index = 0;
|
|
812
|
+
let map = {};
|
|
813
|
+
|
|
814
|
+
walk(frag, (node) => {
|
|
815
|
+
let x = [];
|
|
816
|
+
let pickupNode;
|
|
817
|
+
switch (node.nodeType) {
|
|
818
|
+
case node.TEXT_NODE: {
|
|
819
|
+
let value = node.textContent;
|
|
820
|
+
if (hasMustache(value)) {
|
|
821
|
+
x.push({
|
|
822
|
+
type: TEXT,
|
|
823
|
+
value,
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
break
|
|
827
|
+
}
|
|
828
|
+
case node.ELEMENT_NODE: {
|
|
829
|
+
let each = parseEach(node);
|
|
830
|
+
|
|
831
|
+
if (each) {
|
|
832
|
+
let ns = node.namespaceURI;
|
|
833
|
+
let m;
|
|
834
|
+
|
|
835
|
+
if (ns.endsWith("/svg")) {
|
|
836
|
+
node.removeAttribute("each");
|
|
837
|
+
let tpl = document.createElementNS(ns, "defs");
|
|
838
|
+
tpl.innerHTML = node.outerHTML;
|
|
839
|
+
node.parentNode.replaceChild(tpl, node);
|
|
840
|
+
node = tpl;
|
|
841
|
+
m = parse(node.firstChild);
|
|
842
|
+
} else {
|
|
843
|
+
if (node.nodeName !== "TEMPLATE") {
|
|
844
|
+
node.removeAttribute("each");
|
|
845
|
+
let tpl = document.createElement("template");
|
|
846
|
+
|
|
847
|
+
tpl.innerHTML = node.outerHTML;
|
|
848
|
+
node.parentNode.replaceChild(tpl, node);
|
|
849
|
+
node = tpl;
|
|
850
|
+
}
|
|
851
|
+
m = parse(node.content.firstChild);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
pickupNode = node.nextSibling;
|
|
855
|
+
|
|
856
|
+
x.push({
|
|
857
|
+
type: REPEAT,
|
|
858
|
+
map: m,
|
|
859
|
+
blockIndex: blockCount++,
|
|
860
|
+
...each,
|
|
861
|
+
pickupNode,
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
break
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
let attrs = node.attributes;
|
|
868
|
+
let i = attrs.length;
|
|
869
|
+
while (i--) {
|
|
870
|
+
let { name, value } = attrs[i];
|
|
871
|
+
|
|
872
|
+
if (
|
|
873
|
+
name === ":name" &&
|
|
874
|
+
value &&
|
|
875
|
+
(node.nodeName === "INPUT" ||
|
|
876
|
+
node.nodeName === "SELECT" ||
|
|
877
|
+
node.nodeName === "TEXTAREA")
|
|
878
|
+
) {
|
|
879
|
+
x.push({
|
|
880
|
+
type: INPUT,
|
|
881
|
+
path: value,
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
node.removeAttribute(name);
|
|
885
|
+
node.setAttribute("name", value);
|
|
886
|
+
} else if (name.startsWith(":on")) {
|
|
887
|
+
node.removeAttribute(name);
|
|
888
|
+
let eventType = name.split(":on")[1];
|
|
889
|
+
x.push({
|
|
890
|
+
type: EVENT,
|
|
891
|
+
eventType,
|
|
892
|
+
actionType: value,
|
|
893
|
+
});
|
|
894
|
+
} else if (name.startsWith(":")) {
|
|
895
|
+
let prop = name.slice(1);
|
|
896
|
+
|
|
897
|
+
let v = value || prop;
|
|
898
|
+
|
|
899
|
+
if (!v.includes("{{")) v = `{{${v}}}`;
|
|
900
|
+
|
|
901
|
+
x.push({
|
|
902
|
+
type: ATTRIBUTE,
|
|
903
|
+
name: prop,
|
|
904
|
+
value: v,
|
|
905
|
+
});
|
|
906
|
+
node.removeAttribute(name);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
if (x.length) map[index] = x;
|
|
912
|
+
index++;
|
|
913
|
+
return pickupNode
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
return map
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
const multi =
|
|
920
|
+
(...fns) =>
|
|
921
|
+
(...args) => {
|
|
922
|
+
for (let fn of fns) {
|
|
923
|
+
let v = fn(...args);
|
|
924
|
+
if (v === false) return false
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
const bindAll = (bMap, hydrate = 0, context) => {
|
|
929
|
+
let index = 0;
|
|
930
|
+
return (node) => {
|
|
931
|
+
let k = index;
|
|
932
|
+
let p;
|
|
933
|
+
if (k in bMap) {
|
|
934
|
+
bMap[k].forEach((v) => {
|
|
935
|
+
let x = bind({
|
|
936
|
+
...v,
|
|
937
|
+
node,
|
|
938
|
+
context,
|
|
939
|
+
hydrate,
|
|
940
|
+
});
|
|
941
|
+
p = x.pickupNode;
|
|
942
|
+
});
|
|
943
|
+
node.$i = index;
|
|
944
|
+
}
|
|
945
|
+
index++;
|
|
946
|
+
return p
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
let frag = fragmentFromTemplate(template);
|
|
951
|
+
let map = parse(frag);
|
|
952
|
+
|
|
953
|
+
walk(frag, bindAll(map));
|
|
954
|
+
beforeMountCallback?.(frag);
|
|
955
|
+
target.prepend(frag);
|
|
956
|
+
update();
|
|
957
|
+
|
|
958
|
+
return debounce(() => update(updatedCallback))
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
const childNodes = (node) => {
|
|
962
|
+
let frag = document.createDocumentFragment();
|
|
963
|
+
while (node.firstChild) {
|
|
964
|
+
frag.appendChild(node.firstChild);
|
|
965
|
+
}
|
|
966
|
+
return frag
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
const mergeSlots = (targetNode, sourceNode) => {
|
|
970
|
+
let namedSlots = sourceNode.querySelectorAll("slot[name]");
|
|
971
|
+
|
|
972
|
+
namedSlots.forEach((slot) => {
|
|
973
|
+
let name = slot.attributes.name.value;
|
|
974
|
+
let node = targetNode.querySelector(`[slot="${name}"]`);
|
|
975
|
+
if (!node) {
|
|
976
|
+
slot.parentNode.replaceChild(childNodes(slot), slot);
|
|
977
|
+
return
|
|
978
|
+
}
|
|
979
|
+
node.removeAttribute("slot");
|
|
980
|
+
slot.parentNode.replaceChild(node, slot);
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
let defaultSlot = sourceNode.querySelector("slot:not([name])");
|
|
984
|
+
|
|
985
|
+
if (defaultSlot) {
|
|
986
|
+
defaultSlot.parentNode.replaceChild(
|
|
987
|
+
childNodes(targetNode.innerHTML.trim() ? targetNode : defaultSlot),
|
|
988
|
+
defaultSlot
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
const define = (name, factory, template) =>
|
|
994
|
+
customElements.define(
|
|
995
|
+
name,
|
|
996
|
+
class extends HTMLElement {
|
|
997
|
+
async connectedCallback() {
|
|
998
|
+
if (!this.initialised) {
|
|
999
|
+
let config = factory(this);
|
|
1000
|
+
|
|
1001
|
+
if (config instanceof Promise) config = await config;
|
|
1002
|
+
|
|
1003
|
+
let { subscribe, shadow, initialState = {} } = config;
|
|
1004
|
+
|
|
1005
|
+
this.connectedCallback = config.connectedCallback;
|
|
1006
|
+
this.disconnectedCallback = config.disconnectedCallback;
|
|
1007
|
+
|
|
1008
|
+
const { dispatch, getState, onUpdate, flush } = configure(
|
|
1009
|
+
config,
|
|
1010
|
+
this
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
initialState = getState();
|
|
1014
|
+
|
|
1015
|
+
let observedProps = Object.keys(initialState).filter(
|
|
1016
|
+
(v) => v.charAt(0) === "$"
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
let observedAttributes = observedProps
|
|
1020
|
+
.map((v) => v.slice(1))
|
|
1021
|
+
.map(pascalToKebab);
|
|
1022
|
+
|
|
1023
|
+
let sa = this.setAttribute;
|
|
1024
|
+
this.setAttribute = (k, v) => {
|
|
1025
|
+
if (observedAttributes.includes(k)) {
|
|
1026
|
+
let { name, value } = attributeToProp(k, v);
|
|
1027
|
+
dispatch({
|
|
1028
|
+
type: "SET",
|
|
1029
|
+
payload: { name: "$" + name, value },
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
sa.apply(this, [k, v]);
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
observedAttributes.forEach((name) => {
|
|
1036
|
+
let property = attributeToProp(name).name;
|
|
1037
|
+
|
|
1038
|
+
let value;
|
|
1039
|
+
|
|
1040
|
+
if (this.hasAttribute(name)) {
|
|
1041
|
+
value = this.getAttribute(name);
|
|
1042
|
+
} else {
|
|
1043
|
+
value = this[property] || initialState["$" + property];
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
Object.defineProperty(this, property, {
|
|
1047
|
+
get() {
|
|
1048
|
+
return getState()["$" + property]
|
|
1049
|
+
},
|
|
1050
|
+
set(v) {
|
|
1051
|
+
dispatch({
|
|
1052
|
+
type: "SET",
|
|
1053
|
+
payload: { name: "$" + property, value: v },
|
|
1054
|
+
});
|
|
1055
|
+
if (isPrimitive(v)) {
|
|
1056
|
+
applyAttribute(this, property, v);
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
this[property] = value;
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
let beforeMountCallback;
|
|
1065
|
+
|
|
1066
|
+
if (shadow) {
|
|
1067
|
+
this.attachShadow({
|
|
1068
|
+
mode: shadow,
|
|
1069
|
+
});
|
|
1070
|
+
} else {
|
|
1071
|
+
beforeMountCallback = (frag) => mergeSlots(this, frag);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
onUpdate(
|
|
1075
|
+
render(
|
|
1076
|
+
this.shadowRoot || this,
|
|
1077
|
+
{ getState, dispatch },
|
|
1078
|
+
template,
|
|
1079
|
+
() => {
|
|
1080
|
+
observedProps.forEach((k) => {
|
|
1081
|
+
let v = getState()[k];
|
|
1082
|
+
if (isPrimitive(v)) applyAttribute(this, k.slice(1), v);
|
|
1083
|
+
});
|
|
1084
|
+
subscribe?.(getState());
|
|
1085
|
+
flush();
|
|
1086
|
+
},
|
|
1087
|
+
beforeMountCallback
|
|
1088
|
+
)
|
|
1089
|
+
);
|
|
1090
|
+
this.initialised = true;
|
|
1091
|
+
}
|
|
1092
|
+
this.connectedCallback?.();
|
|
1093
|
+
}
|
|
1094
|
+
disconnectedCallback() {
|
|
1095
|
+
this.disconnectedCallback?.();
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
export { define };
|