UNPKG

svelte-advanced-tables

Version:

This project brings DataTable into your Svelte project.

944 lines (941 loc) 122 kB
function noop() { } function run(fn) { return fn(); } function blank_object() { return Object.create(null); } function run_all(fns) { fns.forEach(run); } function is_function(thing) { return typeof thing === 'function'; } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function is_empty(obj) { return Object.keys(obj).length === 0; } function append(target, node) { target.appendChild(node); } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { node.parentNode.removeChild(node); } function destroy_each(iterations, detaching) { for (let i = 0; i < iterations.length; i += 1) { if (iterations[i]) iterations[i].d(detaching); } } function element(name) { return document.createElement(name); } function text(data) { return document.createTextNode(data); } function space() { return text(' '); } function attr(node, attribute, value) { if (value == null) node.removeAttribute(attribute); else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); } function children(element) { return Array.from(element.childNodes); } function set_data(text, data) { data = '' + data; if (text.wholeText !== data) text.data = data; } let current_component; function set_current_component(component) { current_component = component; } function get_current_component() { if (!current_component) throw new Error('Function called outside component initialization'); return current_component; } function onMount(fn) { get_current_component().$$.on_mount.push(fn); } const dirty_components = []; const binding_callbacks = []; const render_callbacks = []; const flush_callbacks = []; const resolved_promise = Promise.resolve(); let update_scheduled = false; function schedule_update() { if (!update_scheduled) { update_scheduled = true; resolved_promise.then(flush); } } function add_render_callback(fn) { render_callbacks.push(fn); } let flushing = false; const seen_callbacks = new Set(); function flush() { if (flushing) return; flushing = true; do { // first, call beforeUpdate functions // and update components for (let i = 0; i < dirty_components.length; i += 1) { const component = dirty_components[i]; set_current_component(component); update(component.$$); } set_current_component(null); dirty_components.length = 0; while (binding_callbacks.length) binding_callbacks.pop()(); // then, once components are updated, call // afterUpdate functions. This may cause // subsequent updates... for (let i = 0; i < render_callbacks.length; i += 1) { const callback = render_callbacks[i]; if (!seen_callbacks.has(callback)) { // ...so guard against infinite loops seen_callbacks.add(callback); callback(); } } render_callbacks.length = 0; } while (dirty_components.length); while (flush_callbacks.length) { flush_callbacks.pop()(); } update_scheduled = false; flushing = false; seen_callbacks.clear(); } function update($$) { if ($$.fragment !== null) { $$.update(); run_all($$.before_update); const dirty = $$.dirty; $$.dirty = [-1]; $$.fragment && $$.fragment.p($$.ctx, dirty); $$.after_update.forEach(add_render_callback); } } const outroing = new Set(); function transition_in(block, local) { if (block && block.i) { outroing.delete(block); block.i(local); } } function mount_component(component, target, anchor, customElement) { const { fragment, on_mount, on_destroy, after_update } = component.$$; fragment && fragment.m(target, anchor); if (!customElement) { // onMount happens before the initial afterUpdate add_render_callback(() => { const new_on_destroy = on_mount.map(run).filter(is_function); if (on_destroy) { on_destroy.push(...new_on_destroy); } else { // Edge case - component was destroyed immediately, // most likely as a result of a binding initialising run_all(new_on_destroy); } component.$$.on_mount = []; }); } after_update.forEach(add_render_callback); } function destroy_component(component, detaching) { const $$ = component.$$; if ($$.fragment !== null) { run_all($$.on_destroy); $$.fragment && $$.fragment.d(detaching); // TODO null out other refs, including component.$$ (but need to // preserve final state?) $$.on_destroy = $$.fragment = null; $$.ctx = []; } } function make_dirty(component, i) { if (component.$$.dirty[0] === -1) { dirty_components.push(component); schedule_update(); component.$$.dirty.fill(0); } component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); } function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) { const parent_component = current_component; set_current_component(component); const $$ = component.$$ = { fragment: null, ctx: null, // state props, update: noop, not_equal, bound: blank_object(), // lifecycle on_mount: [], on_destroy: [], on_disconnect: [], before_update: [], after_update: [], context: new Map(parent_component ? parent_component.$$.context : options.context || []), // everything else callbacks: blank_object(), dirty, skip_bound: false, root: options.target || parent_component.$$.root }; append_styles && append_styles($$.root); let ready = false; $$.ctx = instance ? instance(component, options.props || {}, (i, ret, ...rest) => { const value = rest.length ? rest[0] : ret; if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value); if (ready) make_dirty(component, i); } return ret; }) : []; $$.update(); ready = true; run_all($$.before_update); // `false` as a special case of no DOM component $$.fragment = create_fragment ? create_fragment($$.ctx) : false; if (options.target) { if (options.hydrate) { const nodes = children(options.target); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.l(nodes); nodes.forEach(detach); } else { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.c(); } if (options.intro) transition_in(component.$$.fragment); mount_component(component, options.target, options.anchor, options.customElement); flush(); } set_current_component(parent_component); } /** * Base class for Svelte components. Used when dev=false. */ class SvelteComponent { $destroy() { destroy_component(this, 1); this.$destroy = noop; } $on(type, callback) { const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); callbacks.push(callback); return () => { const index = callbacks.indexOf(callback); if (index !== -1) callbacks.splice(index, 1); }; } $set($$props) { if (this.$$set && !is_empty($$props)) { this.$$.skip_bound = true; this.$$set($$props); this.$$.skip_bound = false; } } } (function (f) { if (typeof exports === 'object' && typeof module !== 'undefined') { module.exports = f(); } else if (typeof define === 'function' && define.amd) { define([], f); } else { var g; if (typeof window !== 'undefined') { g = window; } else if (typeof global !== 'undefined') { g = global; } else if (typeof self !== 'undefined') { g = self; } else { g = this; } g.simpleDatatables = f(); } }) (function () { return (function () { function r(e, n, t) { function o(i, f) { if (!n[i]) { if (!e[i]) { var c = 'function' == typeof require && require; if (!f && c) return c(i, !0); if (u) return u(i, !0); var a = new Error('Cannot find module \'' + i + '\''); throw a.code = 'MODULE_NOT_FOUND', a } var p = n[i] = { exports: { } }; e[i][0].call(p.exports, function (r) { var n = e[i][1][r]; return o(n || r) }, p, p.exports, r, e, n, t); } return n[i].exports } for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++) o(t[i]); return o } return r }) () ({ 1: [ function (require, module, exports) { (function (global) { (function () { function t(t, e) { return t(e = { exports: { } }, e.exports), e.exports } var e = t((function (t, e) { t.exports = function () { var t = 'millisecond', e = 'second', n = 'minute', r = 'hour', i = 'day', s = 'week', a = 'month', o = 'quarter', u = 'year', f = 'date', h = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, c = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, d = { name: 'en', weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_') }, l = function (t, e, n) { var r = String(t); return !r || r.length >= e ? t : '' + Array(e + 1 - r.length).join(n) + t }, M = { s: l, z: function (t) { var e = - t.utcOffset(), n = Math.abs(e), r = Math.floor(n / 60), i = n % 60; return (e <= 0 ? '+' : '-') + l(r, 2, '0') + ':' + l(i, 2, '0') }, m: function t(e, n) { if (e.date() < n.date()) return - t(n, e); var r = 12 * (n.year() - e.year()) + (n.month() - e.month()), i = e.clone().add(r, a), s = n - i < 0, o = e.clone().add(r + (s ? - 1 : 1), a); return + ( - (r + (n - i) / (s ? i - o : o - i)) || 0) }, a: function (t) { return t < 0 ? Math.ceil(t) || 0 : Math.floor(t) }, p: function (h) { return { M: a, y: u, w: s, d: i, D: f, h: r, m: n, s: e, ms: t, Q: o } [ h ] || String(h || '').toLowerCase().replace(/s$/, '') }, u: function (t) { return void 0 === t } }, $ = 'en', m = { }; m[$] = d; var D = function (t) { return t instanceof y }, Y = function (t, e, n) { var r; if (!t) return $; if ('string' == typeof t) m[t] && (r = t), e && (m[t] = e, r = t); else { var i = t.name; m[i] = t, r = i; } return !n && r && ($ = r), r || !n && $ }, v = function (t, e) { if (D(t)) return t.clone(); var n = 'object' == typeof e ? e : { }; return n.date = t, n.args = arguments, new y(n) }, p = M; p.l = Y, p.i = D, p.w = function (t, e) { return v(t, { locale: e.$L, utc: e.$u, x: e.$x, $offset: e.$offset }) }; var y = function () { function d(t) { this.$L = Y(t.locale, null, !0), this.parse(t); } var l = d.prototype; return l.parse = function (t) { this.$d = function (t) { var e = t.date, n = t.utc; if (null === e) return new Date(NaN); if (p.u(e)) return new Date; if (e instanceof Date) return new Date(e); if ('string' == typeof e && !/Z$/i.test(e)) { var r = e.match(h); if (r) { var i = r[2] - 1 || 0, s = (r[7] || '0').substring(0, 3); return n ? new Date(Date.UTC(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s)) : new Date(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s) } } return new Date(e) }(t), this.$x = t.x || { }, this.init(); }, l.init = function () { var t = this.$d; this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds(); }, l.$utils = function () { return p }, l.isValid = function () { return !('Invalid Date' === this.$d.toString()) }, l.isSame = function (t, e) { var n = v(t); return this.startOf(e) <= n && n <= this.endOf(e) }, l.isAfter = function (t, e) { return v(t) < this.startOf(e) }, l.isBefore = function (t, e) { return this.endOf(e) < v(t) }, l.$g = function (t, e, n) { return p.u(t) ? this[e] : this.set(n, t) }, l.unix = function () { return Math.floor(this.valueOf() / 1000) }, l.valueOf = function () { return this.$d.getTime() }, l.startOf = function (t, o) { var h = this, c = !!p.u(o) || o, d = p.p(t), l = function (t, e) { var n = p.w(h.$u ? Date.UTC(h.$y, e, t) : new Date(h.$y, e, t), h); return c ? n : n.endOf(i) }, M = function (t, e) { return p.w(h.toDate() [t].apply(h.toDate('s'), (c ? [ 0, 0, 0, 0 ] : [ 23, 59, 59, 999 ]).slice(e)), h) }, $ = this.$W, m = this.$M, D = this.$D, Y = 'set' + (this.$u ? 'UTC' : ''); switch (d) { case u: return c ? l(1, 0) : l(31, 11); case a: return c ? l(1, m) : l(0, m + 1); case s: var v = this.$locale().weekStart || 0, y = ($ < v ? $ + 7 : $) - v; return l(c ? D - y : D + (6 - y), m); case i: case f: return M(Y + 'Hours', 0); case r: return M(Y + 'Minutes', 1); case n: return M(Y + 'Seconds', 2); case e: return M(Y + 'Milliseconds', 3); default: return this.clone() } }, l.endOf = function (t) { return this.startOf(t, !1) }, l.$set = function (s, o) { var h, c = p.p(s), d = 'set' + (this.$u ? 'UTC' : ''), l = (h = { }, h[i] = d + 'Date', h[f] = d + 'Date', h[a] = d + 'Month', h[u] = d + 'FullYear', h[r] = d + 'Hours', h[n] = d + 'Minutes', h[e] = d + 'Seconds', h[t] = d + 'Milliseconds', h) [c], M = c === i ? this.$D + (o - this.$W) : o; if (c === a || c === u) { var $ = this.clone().set(f, 1); $.$d[l](M), $.init(), this.$d = $.set(f, Math.min(this.$D, $.daysInMonth())).$d; } else l && this.$d[l](M); return this.init(), this }, l.set = function (t, e) { return this.clone().$set(t, e) }, l.get = function (t) { return this[p.p(t)]() }, l.add = function (t, o) { var f, h = this; t = Number(t); var c = p.p(o), d = function (e) { var n = v(h); return p.w(n.date(n.date() + Math.round(e * t)), h) }; if (c === a) return this.set(a, this.$M + t); if (c === u) return this.set(u, this.$y + t); if (c === i) return d(1); if (c === s) return d(7); var l = (f = { }, f[n] = 60000, f[r] = 3600000, f[e] = 1000, f) [c] || 1, M = this.$d.getTime() + t * l; return p.w(M, this) }, l.subtract = function (t, e) { return this.add( - 1 * t, e) }, l.format = function (t) { var e = this; if (!this.isValid()) return 'Invalid Date'; var n = t || 'YYYY-MM-DDTHH:mm:ssZ', r = p.z(this), i = this.$locale(), s = this.$H, a = this.$m, o = this.$M, u = i.weekdays, f = i.months, h = function (t, r, i, s) { return t && (t[r] || t(e, n)) || i[r].substr(0, s) }, d = function (t) { return p.s(s % 12 || 12, t, '0') }, l = i.meridiem || function (t, e, n) { var r = t < 12 ? 'AM' : 'PM'; return n ? r.toLowerCase() : r }, M = { YY: String(this.$y).slice( - 2), YYYY: this.$y, M: o + 1, MM: p.s(o + 1, 2, '0'), MMM: h(i.monthsShort, o, f, 3), MMMM: h(f, o), D: this.$D, DD: p.s(this.$D, 2, '0'), d: String(this.$W), dd: h(i.weekdaysMin, this.$W, u, 2), ddd: h(i.weekdaysShort, this.$W, u, 3), dddd: u[this.$W], H: String(s), HH: p.s(s, 2, '0'), h: d(1), hh: d(2), a: l(s, a, !0), A: l(s, a, !1), m: String(a), mm: p.s(a, 2, '0'), s: String(this.$s), ss: p.s(this.$s, 2, '0'), SSS: p.s(this.$ms, 3, '0'), Z: r }; return n.replace(c, (function (t, e) { return e || M[t] || r.replace(':', '') })) }, l.utcOffset = function () { return 15 * - Math.round(this.$d.getTimezoneOffset() / 15) }, l.diff = function (t, f, h) { var c, d = p.p(f), l = v(t), M = 60000 * (l.utcOffset() - this.utcOffset()), $ = this - l, m = p.m(this, l); return m = (c = { }, c[u] = m / 12, c[a] = m, c[o] = m / 3, c[s] = ($ - M) / 604800000, c[i] = ($ - M) / 86400000, c[r] = $ / 3600000, c[n] = $ / 60000, c[e] = $ / 1000, c) [d] || $, h ? m : p.a(m) }, l.daysInMonth = function () { return this.endOf(a).$D }, l.$locale = function () { return m[this.$L] }, l.locale = function (t, e) { if (!t) return this.$L; var n = this.clone(), r = Y(t, e, !0); return r && (n.$L = r), n }, l.clone = function () { return p.w(this.$d, this) }, l.toDate = function () { return new Date(this.valueOf()) }, l.toJSON = function () { return this.isValid() ? this.toISOString() : null }, l.toISOString = function () { return this.$d.toISOString() }, l.toString = function () { return this.$d.toUTCString() }, d }(), g = y.prototype; return v.prototype = g, [ ['$ms', t], [ '$s', e ], [ '$m', n ], [ '$H', r ], [ '$W', i ], [ '$M', a ], [ '$y', u ], [ '$D', f ] ].forEach((function (t) { g[t[1]] = function (e) { return this.$g(e, t[0], t[1]) }; })), v.extend = function (t, e) { return t.$i || (t(e, y, v), t.$i = !0), v }, v.locale = Y, v.isDayjs = D, v.unix = function (t) { return v(1000 * t) }, v.en = m[$], v.Ls = m, v.p = { }, v }(); })), n = t((function (t, e) { var n, r, i, s, a, o, u, f, h, c, d, l, M; t.exports = (n = { LTS: 'h:mm:ss A', LT: 'h:mm A', L: 'MM/DD/YYYY', LL: 'MMMM D, YYYY', LLL: 'MMMM D, YYYY h:mm A', LLLL: 'dddd, MMMM D, YYYY h:mm A' }, r = function (t, e) { return t.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (function (t, r, i) { var s = i && i.toUpperCase(); return r || e[i] || n[i] || e[s].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (function (t, e, n) { return e || n.slice(1) })) })) }, i = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g, u = { }, h = [ /[+-]\d\d:?(\d\d)?/, function (t) { (this.zone || (this.zone = { })).offset = function (t) { if (!t) return 0; var e = t.match(/([+-]|\d\d)/g), n = 60 * e[1] + ( + e[2] || 0); return 0 === n ? 0 : '+' === e[0] ? - n : n }(t); } ], c = function (t) { var e = u[t]; return e && (e.indexOf ? e : e.s.concat(e.f)) }, d = function (t, e) { var n, r = u.meridiem; if (r) { for (var i = 1; i <= 24; i += 1) if (t.indexOf(r(i, 0, e)) > - 1) { n = i > 12; break } } else n = t === (e ? 'pm' : 'PM'); return n }, l = { A: [ o = /\d*[^\s\d-:/()]+/, function (t) { this.afternoon = d(t, !1); } ], a: [ o, function (t) { this.afternoon = d(t, !0); } ], S: [ /\d/, function (t) { this.milliseconds = 100 * + t; } ], SS: [ s = /\d\d/, function (t) { this.milliseconds = 10 * + t; } ], SSS: [ /\d{3}/, function (t) { this.milliseconds = + t; } ], s: [ a = /\d\d?/, (f = function (t) { return function (e) { this[t] = + e; } }) ('seconds') ], ss: [ a, f('seconds') ], m: [ a, f('minutes') ], mm: [ a, f('minutes') ], H: [ a, f('hours') ], h: [ a, f('hours') ], HH: [ a, f('hours') ], hh: [ a, f('hours') ], D: [ a, f('day') ], DD: [ s, f('day') ], Do: [ o, function (t) { var e = u.ordinal, n = t.match(/\d+/); if (this.day = n[0], e) for (var r = 1; r <= 31; r += 1) e(r).replace(/\[|\]/g, '') === t && (this.day = r); } ], M: [ a, f('month') ], MM: [ s, f('month') ], MMM: [ o, function (t) { var e = c('months'), n = (c('monthsShort') || e.map((function (t) { return t.substr(0, 3) }))).indexOf(t) + 1; if (n < 1) throw new Error; this.month = n % 12 || n; } ], MMMM: [ o, function (t) { var e = c('months').indexOf(t) + 1; if (e < 1) throw new Error; this.month = e % 12 || e; } ], Y: [ /[+-]?\d+/, f('year') ], YY: [ s, function (t) { t = + t, this.year = t + (t > 68 ? 1900 : 2000); } ], YYYY: [ /\d{4}/, f('year') ], Z: h, ZZ: h }, M = function (t, e, n) { try { var s = function (t) { for (var e = (t = r(t, u && u.formats)).match(i), n = e.length, s = 0; s < n; s += 1) { var a = e[s], o = l[a], f = o && o[0], h = o && o[1]; e[s] = h ? { regex: f, parser: h } : a.replace(/^\[|\]$/g, ''); } return function (t) { for (var r = { }, i = 0, s = 0; i < n; i += 1) { var a = e[i]; if ('string' == typeof a) s += a.length; else { var o = a.regex, u = a.parser, f = t.substr(s), h = o.exec(f) [0]; u.call(r, h), t = t.replace(h, ''); } } return function (t) { var e = t.afternoon; if (void 0