@trintel/zooy 1.6.0 → 1.6.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/chunks/{register-Cdc1Dawc.js → register-CP6_mXMf.js} +1 -1
- package/dist/chunks/{register-BW7XFFn2.js → register-DkjYj3ib.js} +1 -1
- package/dist/chunks/zoo-CaW98OQn.js +393 -0
- package/dist/chunks/zoo-Cpc0eKfk.js +52 -0
- package/dist/zooy.cjs.js +2 -2
- package/dist/zooy.es.js +29 -33
- package/package.json +1 -1
- package/dist/chunks/zoo-B8_zFikt.js +0 -52
- package/dist/chunks/zoo-Cztpe9qH.js +0 -391
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
import { n as A } from "./component-library-registry-DB5UeqC2.js";
|
|
2
|
-
import { isDefAndNotNull as f } from "badu";
|
|
3
|
-
import { assocPath as w, both as k, has as p, path as v } from "ramda";
|
|
4
|
-
import { LitElement as b, css as y, html as c } from "lit";
|
|
5
|
-
var _ = {
|
|
6
|
-
json: (e) => JSON.stringify(e, null, 2),
|
|
7
|
-
tpl: (e, t, i) => {
|
|
8
|
-
const r = i?.getAttribute("zoo-bind-attr-tpl") || i?.getAttribute("zoo-bind-tpl");
|
|
9
|
-
if (!r) return e;
|
|
10
|
-
try {
|
|
11
|
-
return new Function("value", "data", `return \`${r}\`;`)(e, t);
|
|
12
|
-
} catch (n) {
|
|
13
|
-
return console.warn("[Binder] Invalid template:", r, n), e;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}, B = class {
|
|
17
|
-
#s;
|
|
18
|
-
#t;
|
|
19
|
-
#i;
|
|
20
|
-
#e = null;
|
|
21
|
-
#r;
|
|
22
|
-
constructor(e, t, i, r = {}) {
|
|
23
|
-
if (!t) throw new Error("Binder requires a URL");
|
|
24
|
-
if (!i || !(i instanceof Element)) throw new Error("Binder requires a valid rootEl Element");
|
|
25
|
-
this.#s = e, this.#t = new URL(t, window.location.origin), this.#i = i, this.#r = {
|
|
26
|
-
..._,
|
|
27
|
-
...r.formatters
|
|
28
|
-
}, r.urlParams ? this.#a(r.urlParams) : this.#n();
|
|
29
|
-
}
|
|
30
|
-
get url() {
|
|
31
|
-
return this.#t;
|
|
32
|
-
}
|
|
33
|
-
get data() {
|
|
34
|
-
return this.#e;
|
|
35
|
-
}
|
|
36
|
-
get limit() {
|
|
37
|
-
return parseInt(this.#t.searchParams.get("limit") || "0", 10);
|
|
38
|
-
}
|
|
39
|
-
get offset() {
|
|
40
|
-
return parseInt(this.#t.searchParams.get("offset") || "0", 10);
|
|
41
|
-
}
|
|
42
|
-
get isPaginated() {
|
|
43
|
-
return k(p("count"), p("results"))(this.#e);
|
|
44
|
-
}
|
|
45
|
-
#a(e) {
|
|
46
|
-
return Object.entries(e).forEach(([t, i]) => {
|
|
47
|
-
if (!f(i) || i === "" || Array.isArray(i) && i.length < 1) {
|
|
48
|
-
this.#t.searchParams.delete(t);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (Array.isArray(i)) {
|
|
52
|
-
this.#t.searchParams.set(t, i.join(","));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
this.#t.searchParams.set(t, i);
|
|
56
|
-
}), this.#n(), this.#t;
|
|
57
|
-
}
|
|
58
|
-
#n() {
|
|
59
|
-
const e = this.#t.href.split(this.url.origin)[1].slice(1);
|
|
60
|
-
this.#i.querySelectorAll("[zoo-bind-binderurl]").forEach((t) => {
|
|
61
|
-
t.setAttribute("zoo-bind-binderurl", e);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async fetchData(e = {}) {
|
|
65
|
-
const t = await this.#s.user.fetchJson(this.#a(e).toString(), this.#s.abortController.signal);
|
|
66
|
-
return this.setData(t);
|
|
67
|
-
}
|
|
68
|
-
setData(e) {
|
|
69
|
-
return this.#e = e, this.render();
|
|
70
|
-
}
|
|
71
|
-
async render() {
|
|
72
|
-
if (!f(this.#e)) {
|
|
73
|
-
console.warn("[Binder] No data to render");
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.#n(), this.#o(this.#i, this.#e, 0), await this.#c();
|
|
77
|
-
}
|
|
78
|
-
#o(e, t, i = 0, r = {}) {
|
|
79
|
-
const n = r.removeAttributes ?? !1;
|
|
80
|
-
e.querySelectorAll("[zoo-bind-attr]").forEach((s) => {
|
|
81
|
-
s.closest("[zoo-template]") || (s.getAttribute("zoo-bind-attr").split(",").forEach((a) => {
|
|
82
|
-
const [o, l] = a.split(":").map((d) => d.trim()), [m, h] = l.split("|").map((d) => d.trim());
|
|
83
|
-
let u = this.#l(t, m, i);
|
|
84
|
-
h && this.#r[h] && (u = this.#r[h](u, t, s)), f(u) && s.setAttribute(o, u);
|
|
85
|
-
}), n && (s.removeAttribute("zoo-bind-attr"), s.removeAttribute("zoo-bind-attr-tpl")));
|
|
86
|
-
}), e.querySelectorAll("[zoo-bind]").forEach((s) => {
|
|
87
|
-
if (s.closest("[zoo-template]")) return;
|
|
88
|
-
const [a, o] = s.getAttribute("zoo-bind").split("|").map((m) => m.trim());
|
|
89
|
-
let l = this.#l(t, a, i);
|
|
90
|
-
o && this.#r[o] && (l = this.#r[o](l, t, s)), s.textContent = l ?? "", n && (s.removeAttribute("zoo-bind"), s.removeAttribute("zoo-bind-tpl"));
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
async #c() {
|
|
94
|
-
const e = this.#i.querySelectorAll("[zoo-template]");
|
|
95
|
-
for (const t of e) {
|
|
96
|
-
const i = t.getAttribute("zoo-template"), r = t.getAttribute("zoo-template-bind");
|
|
97
|
-
if (!i) {
|
|
98
|
-
console.warn("[Binder] Consumer missing template ID", t);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const n = this.#i.querySelector(`#${i}`);
|
|
102
|
-
if (!n || n.tagName !== "TEMPLATE") {
|
|
103
|
-
console.error(`[DataBinder] Template not found or invalid: ${i}`);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const s = r ? v(r.split("."), this.#e) : this.#e;
|
|
107
|
-
if (!s) {
|
|
108
|
-
console.warn(`[DataBinder] Data slice is undefined. Path: ${r}. Skipping render for this consumer.`);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (!Array.isArray(s)) {
|
|
112
|
-
console.error(`[DataBinder] Data slice is not an array. Path: ${r}`, s);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
t.replaceChildren(), s.forEach((a, o) => {
|
|
116
|
-
const l = this.#u(n, a, o);
|
|
117
|
-
t.appendChild(l);
|
|
118
|
-
}), await this.#s.parseContent(t);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
#u(e, t, i) {
|
|
122
|
-
const r = e.content.cloneNode(!0);
|
|
123
|
-
return this.#o(r, t, i, { removeAttributes: !0 }), r;
|
|
124
|
-
}
|
|
125
|
-
#l(e, t, i) {
|
|
126
|
-
const r = {
|
|
127
|
-
$index: () => i,
|
|
128
|
-
$index__paged: () => this.offset + i,
|
|
129
|
-
$index1: () => i + 1,
|
|
130
|
-
$index1__paged: () => this.offset + i + 1
|
|
131
|
-
};
|
|
132
|
-
return r[t] ? r[t]() : v(t.split("."), e);
|
|
133
|
-
}
|
|
134
|
-
}, g = new Map(Object.entries({
|
|
135
|
-
event: "event",
|
|
136
|
-
endpoint: "endpoint",
|
|
137
|
-
href: "href",
|
|
138
|
-
url: "url",
|
|
139
|
-
target: "target",
|
|
140
|
-
"record-id": "recordId",
|
|
141
|
-
"zoo-sort-field": "sortField",
|
|
142
|
-
"zoo-view": "view",
|
|
143
|
-
"zoo-event": "event",
|
|
144
|
-
"zoo-href": "href"
|
|
145
|
-
})), $ = (e) => {
|
|
146
|
-
let t = {};
|
|
147
|
-
return Array.from(e.attributes).forEach((i) => {
|
|
148
|
-
const r = i.name, n = i.value;
|
|
149
|
-
g.has(r) ? t[g.get(r)] = n : (r.startsWith("data-") || r.startsWith("zoo-")) && (t = w(r.split("-"), n, t));
|
|
150
|
-
}), t;
|
|
151
|
-
}, E = (e, t, i = "event") => e.getAttribute(t) || e.getAttribute(i), z = class extends b {
|
|
152
|
-
static properties = {
|
|
153
|
-
token: { type: String },
|
|
154
|
-
prefix: { type: String },
|
|
155
|
-
postfix: { type: String }
|
|
156
|
-
};
|
|
157
|
-
static styles = y`
|
|
158
|
-
:host {
|
|
159
|
-
display: inline-block;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.tag {
|
|
163
|
-
text-align: center;
|
|
164
|
-
display: inline-flex;
|
|
165
|
-
align-items: center;
|
|
166
|
-
justify-content: center;
|
|
167
|
-
line-height: initial;
|
|
168
|
-
width: max-content;
|
|
169
|
-
padding: 0.2em 1em;
|
|
170
|
-
border-radius: 1em;
|
|
171
|
-
font-size: var(--zoo-theme-chips-font-size, 0.75rem);
|
|
172
|
-
white-space: nowrap;
|
|
173
|
-
word-break: break-word;
|
|
174
|
-
box-sizing: border-box;
|
|
175
|
-
}
|
|
176
|
-
`;
|
|
177
|
-
render() {
|
|
178
|
-
const e = `${this.prefix ?? ""}${this.token ?? "default"}${this.postfix ?? ""}`;
|
|
179
|
-
return c`
|
|
180
|
-
<span
|
|
181
|
-
class="tag"
|
|
182
|
-
style="
|
|
183
|
-
background-color: var(--zoo-tag-${e}-bg, var(--zoo-tag-default-bg, #9e9e9e));
|
|
184
|
-
color: var(--zoo-tag-${e}-fg, var(--zoo-tag-default-fg, #ffffff));
|
|
185
|
-
"
|
|
186
|
-
>
|
|
187
|
-
<slot></slot>
|
|
188
|
-
</span>
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
customElements.get("zoo-tag") || customElements.define("zoo-tag", z);
|
|
193
|
-
var x = (e) => {
|
|
194
|
-
const t = Math.floor((/* @__PURE__ */ new Date() - e) / 1e3), i = [
|
|
195
|
-
{
|
|
196
|
-
name: "year",
|
|
197
|
-
seconds: 31536e3
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: "month",
|
|
201
|
-
seconds: 2592e3
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
name: "week",
|
|
205
|
-
seconds: 604800
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: "day",
|
|
209
|
-
seconds: 86400
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: "hour",
|
|
213
|
-
seconds: 3600
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
name: "minute",
|
|
217
|
-
seconds: 60
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: "second",
|
|
221
|
-
seconds: 1
|
|
222
|
-
}
|
|
223
|
-
];
|
|
224
|
-
if (t < 0) {
|
|
225
|
-
const r = Math.abs(t);
|
|
226
|
-
for (const n of i) {
|
|
227
|
-
const s = Math.floor(r / n.seconds);
|
|
228
|
-
if (s >= 1) return new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(s, n.name);
|
|
229
|
-
}
|
|
230
|
-
return "just now";
|
|
231
|
-
}
|
|
232
|
-
for (const r of i) {
|
|
233
|
-
const n = Math.floor(t / r.seconds);
|
|
234
|
-
if (n >= 1) return new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(-n, r.name);
|
|
235
|
-
}
|
|
236
|
-
return "just now";
|
|
237
|
-
}, L = (e) => {
|
|
238
|
-
const [{ value: t }, , { value: i }, , { value: r }, , { value: n }, , { value: s }, , { value: a }] = new Intl.DateTimeFormat("en", {
|
|
239
|
-
day: "2-digit",
|
|
240
|
-
month: "short",
|
|
241
|
-
year: "2-digit",
|
|
242
|
-
hour: "2-digit",
|
|
243
|
-
minute: "2-digit",
|
|
244
|
-
second: "2-digit",
|
|
245
|
-
hourCycle: "h23"
|
|
246
|
-
}).formatToParts(e);
|
|
247
|
-
return `${i} ${t} ${r} ${n}:${s}:${a}`;
|
|
248
|
-
}, S = (e) => {
|
|
249
|
-
const [{ value: t }, , { value: i }, , { value: r }] = new Intl.DateTimeFormat("en", {
|
|
250
|
-
day: "2-digit",
|
|
251
|
-
month: "short",
|
|
252
|
-
year: "2-digit"
|
|
253
|
-
}).formatToParts(e);
|
|
254
|
-
return `${i} ${t} ${r}`;
|
|
255
|
-
}, T = class extends b {
|
|
256
|
-
static properties = {
|
|
257
|
-
timestamp: { type: Number },
|
|
258
|
-
kind: { type: String },
|
|
259
|
-
concat: { type: String }
|
|
260
|
-
};
|
|
261
|
-
static styles = y`
|
|
262
|
-
:host {
|
|
263
|
-
display: inline;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
.relative {
|
|
267
|
-
color: var(--zoo-timestamp-relative-color, inherit);
|
|
268
|
-
font-weight: var(--zoo-timestamp-relative-weight, inherit);
|
|
269
|
-
font-size: var(--zoo-timestamp-relative-size, inherit);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
.static {
|
|
273
|
-
color: var(--zoo-timestamp-static-color, inherit);
|
|
274
|
-
font-weight: var(--zoo-timestamp-static-weight, inherit);
|
|
275
|
-
font-size: var(--zoo-timestamp-static-size, inherit);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
.separator {
|
|
279
|
-
color: var(--zoo-timestamp-separator-color, inherit);
|
|
280
|
-
}
|
|
281
|
-
`;
|
|
282
|
-
constructor() {
|
|
283
|
-
super(), this.timestamp = Date.now(), this.kind = "both", this.concat = "r (s)", this._boundTickHandler = this._onTimeTick.bind(this), this._isListening = !1;
|
|
284
|
-
}
|
|
285
|
-
_shouldListenToTicks() {
|
|
286
|
-
return this.kind === "relative" || this.kind === "both";
|
|
287
|
-
}
|
|
288
|
-
connectedCallback() {
|
|
289
|
-
super.connectedCallback(), this._updateTickListener();
|
|
290
|
-
}
|
|
291
|
-
disconnectedCallback() {
|
|
292
|
-
this._removeTickListener(), super.disconnectedCallback();
|
|
293
|
-
}
|
|
294
|
-
updated(e) {
|
|
295
|
-
super.updated(e), e.has("kind") && this._updateTickListener();
|
|
296
|
-
}
|
|
297
|
-
_updateTickListener() {
|
|
298
|
-
const e = this._shouldListenToTicks();
|
|
299
|
-
e && !this._isListening ? (document.addEventListener("zoo-tick-60", this._boundTickHandler), this._isListening = !0) : !e && this._isListening && this._removeTickListener();
|
|
300
|
-
}
|
|
301
|
-
_removeTickListener() {
|
|
302
|
-
this._isListening && (document.removeEventListener("zoo-tick-60", this._boundTickHandler), this._isListening = !1);
|
|
303
|
-
}
|
|
304
|
-
_onTimeTick() {
|
|
305
|
-
this.requestUpdate();
|
|
306
|
-
}
|
|
307
|
-
_parseTemplate(e) {
|
|
308
|
-
const t = [];
|
|
309
|
-
let i = e;
|
|
310
|
-
for (; i.length > 0; ) {
|
|
311
|
-
const r = i.indexOf("r"), n = [r, i.indexOf("s")].filter((s) => s !== -1).sort((s, a) => s - a)[0];
|
|
312
|
-
if (n === void 0) {
|
|
313
|
-
i.length > 0 && t.push({
|
|
314
|
-
type: "text",
|
|
315
|
-
value: i
|
|
316
|
-
});
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
n > 0 && t.push({
|
|
320
|
-
type: "text",
|
|
321
|
-
value: i.substring(0, n)
|
|
322
|
-
}), n === r ? t.push({
|
|
323
|
-
type: "relative",
|
|
324
|
-
value: ""
|
|
325
|
-
}) : t.push({
|
|
326
|
-
type: "static",
|
|
327
|
-
value: ""
|
|
328
|
-
}), i = i.substring(n + 1);
|
|
329
|
-
}
|
|
330
|
-
return t;
|
|
331
|
-
}
|
|
332
|
-
_getFormattedParts() {
|
|
333
|
-
let e = this.timestamp;
|
|
334
|
-
e < 9466848e5 && (e = e * 1e3);
|
|
335
|
-
const t = new Date(e), i = x(t), r = L(t), n = S(t);
|
|
336
|
-
switch (this.kind) {
|
|
337
|
-
case "relative":
|
|
338
|
-
return [{
|
|
339
|
-
type: "relative",
|
|
340
|
-
value: i
|
|
341
|
-
}];
|
|
342
|
-
case "datetime":
|
|
343
|
-
return [{
|
|
344
|
-
type: "static",
|
|
345
|
-
value: r
|
|
346
|
-
}];
|
|
347
|
-
case "date":
|
|
348
|
-
return [{
|
|
349
|
-
type: "static",
|
|
350
|
-
value: n
|
|
351
|
-
}];
|
|
352
|
-
case "both":
|
|
353
|
-
return this._parseTemplate(this.concat).map((s) => s.type === "relative" ? {
|
|
354
|
-
type: "relative",
|
|
355
|
-
value: i
|
|
356
|
-
} : s.type === "static" ? {
|
|
357
|
-
type: "static",
|
|
358
|
-
value: r
|
|
359
|
-
} : s);
|
|
360
|
-
default:
|
|
361
|
-
return this._parseTemplate(this.concat).map((s) => s.type === "relative" ? {
|
|
362
|
-
type: "relative",
|
|
363
|
-
value: i
|
|
364
|
-
} : s.type === "static" ? {
|
|
365
|
-
type: "static",
|
|
366
|
-
value: r
|
|
367
|
-
} : s);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
render() {
|
|
371
|
-
let e = this.timestamp;
|
|
372
|
-
e < 9466848e5 && (e = e * 1e3);
|
|
373
|
-
const t = new Date(e), i = this._getFormattedParts();
|
|
374
|
-
return c`<time datetime="${t.toISOString()}">
|
|
375
|
-
${i.map((r) => r.type === "relative" ? c`<span class="relative">${r.value}</span>` : r.type === "static" ? c`<span class="static">${r.value}</span>` : c`<span class="separator">${r.value}</span>`)}
|
|
376
|
-
</time>`;
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
customElements.get("zoo-timestamp") || customElements.define("zoo-timestamp", T);
|
|
380
|
-
var F = /* @__PURE__ */ A({
|
|
381
|
-
ZooTag: () => z,
|
|
382
|
-
ZooTimestamp: () => T,
|
|
383
|
-
getEventAttribute: () => E,
|
|
384
|
-
getSemanticAttributes: () => $
|
|
385
|
-
});
|
|
386
|
-
export {
|
|
387
|
-
B as i,
|
|
388
|
-
E as n,
|
|
389
|
-
$ as r,
|
|
390
|
-
F as t
|
|
391
|
-
};
|