mirror of
https://github.com/woutdp/live_svelte
synced 2026-05-24 09:28:21 +00:00
Refactor hooks.js
This commit is contained in:
parent
97777800fa
commit
06632a40ab
9 changed files with 139 additions and 485 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import * as Components from "../svelte/**/*"
|
||||
import * as Components from "../svelte/**/*.svelte"
|
||||
import {getRender} from "live_svelte"
|
||||
|
||||
export const render = getRender(Components)
|
||||
|
|
|
|||
|
|
@ -1,62 +1,63 @@
|
|||
import {detach, insert, noop} from "svelte/internal"
|
||||
import {normalizeComponents} from "./utils"
|
||||
|
||||
function base64ToElement(base64) {
|
||||
const template = document.createElement("div")
|
||||
template.innerHTML = atob(base64).trim()
|
||||
return template
|
||||
}
|
||||
|
||||
function dataAttributeToJson(attributeName, el) {
|
||||
const data = el.getAttribute(attributeName)
|
||||
function getAttributeJson(ref, attributeName) {
|
||||
const data = ref.el.getAttribute(attributeName)
|
||||
return data ? JSON.parse(data) : {}
|
||||
}
|
||||
|
||||
function createSlots(slots, ref) {
|
||||
const createSlot = (slotName, ref) => {
|
||||
let savedTarget, savedAnchor, savedElement
|
||||
return () => {
|
||||
function detach(node) {
|
||||
node.parentNode?.removeChild(node)
|
||||
}
|
||||
|
||||
function insert(target, node, anchor) {
|
||||
target.insertBefore(node, anchor || null)
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function getSlots(ref) {
|
||||
const slots = {}
|
||||
|
||||
for (const slotName in getAttributeJson(ref, "data-slots")) {
|
||||
const slot = () => {
|
||||
return {
|
||||
getElement() {
|
||||
return base64ToElement(dataAttributeToJson("data-slots", ref.el)[slotName])
|
||||
const base64 = getAttributeJson(ref, "data-slots")[slotName]
|
||||
const element = document.createElement("div")
|
||||
element.innerHTML = atob(base64).trim()
|
||||
return element
|
||||
},
|
||||
update() {
|
||||
const element = this.getElement()
|
||||
detach(savedElement)
|
||||
insert(savedTarget, element, savedAnchor)
|
||||
savedElement = element
|
||||
detach(this.savedElement)
|
||||
this.savedElement = this.getElement()
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor)
|
||||
},
|
||||
c: noop,
|
||||
m(target, anchor) {
|
||||
const element = this.getElement()
|
||||
savedTarget = target
|
||||
savedAnchor = anchor
|
||||
savedElement = element
|
||||
insert(target, element, anchor)
|
||||
this.savedTarget = target
|
||||
this.savedAnchor = anchor
|
||||
this.savedElement = this.getElement()
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor)
|
||||
},
|
||||
d(detaching) {
|
||||
if (detaching) detach(savedElement)
|
||||
if (detaching) detach(this.savedElement)
|
||||
},
|
||||
l: noop,
|
||||
}
|
||||
}
|
||||
|
||||
slots[slotName] = [slot]
|
||||
}
|
||||
|
||||
const svelteSlots = {}
|
||||
|
||||
for (const slotName in slots) {
|
||||
svelteSlots[slotName] = [createSlot(slotName, ref)]
|
||||
}
|
||||
|
||||
return svelteSlots
|
||||
return slots
|
||||
}
|
||||
|
||||
function getLiveJsonProps(ref) {
|
||||
const json = dataAttributeToJson("data-live-json", ref.el)
|
||||
const json = getAttributeJson(ref, "data-live-json")
|
||||
|
||||
// On SSR, data-live-json is the full object we want
|
||||
// After SSR, data-live-json is an array of keys, and we'll get the data from the window
|
||||
if (typeof json === "object" && json !== null && !Array.isArray(json)) return json
|
||||
if (!Array.isArray(json)) return json
|
||||
|
||||
const liveJsonData = {}
|
||||
for (const liveJsonVariable of json) {
|
||||
|
|
@ -68,10 +69,10 @@ function getLiveJsonProps(ref) {
|
|||
|
||||
function getProps(ref) {
|
||||
return {
|
||||
...dataAttributeToJson("data-props", ref.el),
|
||||
...getAttributeJson(ref, "data-props"),
|
||||
...getLiveJsonProps(ref),
|
||||
live: ref,
|
||||
$$slots: createSlots(dataAttributeToJson("data-slots", ref.el), ref),
|
||||
$$slots: getSlots(ref),
|
||||
$$scope: {},
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +98,7 @@ export function getHooks(components) {
|
|||
throw new Error(`Unable to find ${componentName} component.`)
|
||||
}
|
||||
|
||||
for (const liveJsonElement of Object.keys(dataAttributeToJson("data-live-json", this.el))) {
|
||||
for (const liveJsonElement of Object.keys(getAttributeJson(this, "data-live-json"))) {
|
||||
window.addEventListener(`${liveJsonElement}_initialized`, event => this._instance.$set(getProps(this)), false)
|
||||
window.addEventListener(`${liveJsonElement}_patched`, event => this._instance.$set(getProps(this)), false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import * as Components from "../svelte/**/*"
|
||||
import * as Components from "../svelte/**/*.svelte"
|
||||
import {getRender} from "live_svelte"
|
||||
|
||||
export const render = getRender(Components)
|
||||
|
|
|
|||
|
|
@ -47,172 +47,56 @@ function getRender(components) {
|
|||
};
|
||||
}
|
||||
|
||||
// ../node_modules/svelte/internal/index.mjs
|
||||
function noop() {
|
||||
// js/live_svelte/hooks.js
|
||||
function getAttributeJson(ref, attributeName) {
|
||||
const data = ref.el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function run(fn) {
|
||||
return fn();
|
||||
}
|
||||
function run_all(fns) {
|
||||
fns.forEach(run);
|
||||
}
|
||||
function is_function(thing) {
|
||||
return typeof thing === "function";
|
||||
}
|
||||
function is_empty(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
function detach(node) {
|
||||
node.parentNode?.removeChild(node);
|
||||
}
|
||||
function insert(target, node, anchor) {
|
||||
target.insertBefore(node, anchor || null);
|
||||
}
|
||||
function detach(node) {
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
function noop() {
|
||||
}
|
||||
var render_callbacks = [];
|
||||
function flush_render_callbacks(fns) {
|
||||
const filtered = [];
|
||||
const targets = [];
|
||||
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
|
||||
targets.forEach((c) => c());
|
||||
render_callbacks = filtered;
|
||||
}
|
||||
var globals = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : global;
|
||||
var _boolean_attributes = [
|
||||
"allowfullscreen",
|
||||
"allowpaymentrequest",
|
||||
"async",
|
||||
"autofocus",
|
||||
"autoplay",
|
||||
"checked",
|
||||
"controls",
|
||||
"default",
|
||||
"defer",
|
||||
"disabled",
|
||||
"formnovalidate",
|
||||
"hidden",
|
||||
"inert",
|
||||
"ismap",
|
||||
"itemscope",
|
||||
"loop",
|
||||
"multiple",
|
||||
"muted",
|
||||
"nomodule",
|
||||
"novalidate",
|
||||
"open",
|
||||
"playsinline",
|
||||
"readonly",
|
||||
"required",
|
||||
"reversed",
|
||||
"selected"
|
||||
];
|
||||
var boolean_attributes = /* @__PURE__ */ new Set([..._boolean_attributes]);
|
||||
function destroy_component(component, detaching) {
|
||||
const $$ = component.$$;
|
||||
if ($$.fragment !== null) {
|
||||
flush_render_callbacks($$.after_update);
|
||||
run_all($$.on_destroy);
|
||||
$$.fragment && $$.fragment.d(detaching);
|
||||
$$.on_destroy = $$.fragment = null;
|
||||
$$.ctx = [];
|
||||
}
|
||||
}
|
||||
var SvelteElement;
|
||||
if (typeof HTMLElement === "function") {
|
||||
SvelteElement = class extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({ mode: "open" });
|
||||
}
|
||||
connectedCallback() {
|
||||
const { on_mount } = this.$$;
|
||||
this.$$.on_disconnect = on_mount.map(run).filter(is_function);
|
||||
for (const key in this.$$.slotted) {
|
||||
this.appendChild(this.$$.slotted[key]);
|
||||
}
|
||||
}
|
||||
attributeChangedCallback(attr, _oldValue, newValue) {
|
||||
this[attr] = newValue;
|
||||
}
|
||||
disconnectedCallback() {
|
||||
run_all(this.$$.on_disconnect);
|
||||
}
|
||||
$destroy() {
|
||||
destroy_component(this, 1);
|
||||
this.$destroy = noop;
|
||||
}
|
||||
$on(type, callback) {
|
||||
if (!is_function(callback)) {
|
||||
return noop;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// js/live_svelte/hooks.js
|
||||
function base64ToElement(base64) {
|
||||
const template = document.createElement("div");
|
||||
template.innerHTML = atob(base64).trim();
|
||||
return template;
|
||||
}
|
||||
function dataAttributeToJson(attributeName, el) {
|
||||
const data = el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function createSlots(slots, ref) {
|
||||
const createSlot = (slotName, ref2) => {
|
||||
let savedTarget, savedAnchor, savedElement;
|
||||
return () => {
|
||||
function getSlots(ref) {
|
||||
const slots = {};
|
||||
for (const slotName in getAttributeJson(ref, "data-slots")) {
|
||||
const slot = () => {
|
||||
return {
|
||||
getElement() {
|
||||
return base64ToElement(dataAttributeToJson("data-slots", ref2.el)[slotName]);
|
||||
const base64 = getAttributeJson(ref, "data-slots")[slotName];
|
||||
const element = document.createElement("div");
|
||||
element.innerHTML = atob(base64).trim();
|
||||
return element;
|
||||
},
|
||||
update() {
|
||||
const element = this.getElement();
|
||||
detach(savedElement);
|
||||
insert(savedTarget, element, savedAnchor);
|
||||
savedElement = element;
|
||||
detach(this.savedElement);
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
c: noop,
|
||||
m(target, anchor) {
|
||||
const element = this.getElement();
|
||||
savedTarget = target;
|
||||
savedAnchor = anchor;
|
||||
savedElement = element;
|
||||
insert(target, element, anchor);
|
||||
this.savedTarget = target;
|
||||
this.savedAnchor = anchor;
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
d(detaching) {
|
||||
if (detaching)
|
||||
detach(savedElement);
|
||||
detach(this.savedElement);
|
||||
},
|
||||
l: noop
|
||||
};
|
||||
};
|
||||
};
|
||||
const svelteSlots = {};
|
||||
for (const slotName in slots) {
|
||||
svelteSlots[slotName] = [createSlot(slotName, ref)];
|
||||
slots[slotName] = [slot];
|
||||
}
|
||||
return svelteSlots;
|
||||
return slots;
|
||||
}
|
||||
function getLiveJsonProps(ref) {
|
||||
const json = dataAttributeToJson("data-live-json", ref.el);
|
||||
if (typeof json === "object" && json !== null && !Array.isArray(json))
|
||||
const json = getAttributeJson(ref, "data-live-json");
|
||||
if (!Array.isArray(json))
|
||||
return json;
|
||||
const liveJsonData = {};
|
||||
for (const liveJsonVariable of json) {
|
||||
|
|
@ -224,10 +108,10 @@ function getLiveJsonProps(ref) {
|
|||
}
|
||||
function getProps(ref) {
|
||||
return {
|
||||
...dataAttributeToJson("data-props", ref.el),
|
||||
...getAttributeJson(ref, "data-props"),
|
||||
...getLiveJsonProps(ref),
|
||||
live: ref,
|
||||
$$slots: createSlots(dataAttributeToJson("data-slots", ref.el), ref),
|
||||
$$slots: getSlots(ref),
|
||||
$$scope: {}
|
||||
};
|
||||
}
|
||||
|
|
@ -246,7 +130,7 @@ function getHooks(components) {
|
|||
if (!Component) {
|
||||
throw new Error(`Unable to find ${componentName} component.`);
|
||||
}
|
||||
for (const liveJsonElement of Object.keys(dataAttributeToJson("data-live-json", this.el))) {
|
||||
for (const liveJsonElement of Object.keys(getAttributeJson(this, "data-live-json"))) {
|
||||
window.addEventListener(`${liveJsonElement}_initialized`, (event) => this._instance.$set(getProps(this)), false);
|
||||
window.addEventListener(`${liveJsonElement}_patched`, (event) => this._instance.$set(getProps(this)), false);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -21,172 +21,56 @@ function getRender(components) {
|
|||
};
|
||||
}
|
||||
|
||||
// ../node_modules/svelte/internal/index.mjs
|
||||
function noop() {
|
||||
// js/live_svelte/hooks.js
|
||||
function getAttributeJson(ref, attributeName) {
|
||||
const data = ref.el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function run(fn) {
|
||||
return fn();
|
||||
}
|
||||
function run_all(fns) {
|
||||
fns.forEach(run);
|
||||
}
|
||||
function is_function(thing) {
|
||||
return typeof thing === "function";
|
||||
}
|
||||
function is_empty(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
function detach(node) {
|
||||
node.parentNode?.removeChild(node);
|
||||
}
|
||||
function insert(target, node, anchor) {
|
||||
target.insertBefore(node, anchor || null);
|
||||
}
|
||||
function detach(node) {
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
function noop() {
|
||||
}
|
||||
var render_callbacks = [];
|
||||
function flush_render_callbacks(fns) {
|
||||
const filtered = [];
|
||||
const targets = [];
|
||||
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
|
||||
targets.forEach((c) => c());
|
||||
render_callbacks = filtered;
|
||||
}
|
||||
var globals = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : global;
|
||||
var _boolean_attributes = [
|
||||
"allowfullscreen",
|
||||
"allowpaymentrequest",
|
||||
"async",
|
||||
"autofocus",
|
||||
"autoplay",
|
||||
"checked",
|
||||
"controls",
|
||||
"default",
|
||||
"defer",
|
||||
"disabled",
|
||||
"formnovalidate",
|
||||
"hidden",
|
||||
"inert",
|
||||
"ismap",
|
||||
"itemscope",
|
||||
"loop",
|
||||
"multiple",
|
||||
"muted",
|
||||
"nomodule",
|
||||
"novalidate",
|
||||
"open",
|
||||
"playsinline",
|
||||
"readonly",
|
||||
"required",
|
||||
"reversed",
|
||||
"selected"
|
||||
];
|
||||
var boolean_attributes = /* @__PURE__ */ new Set([..._boolean_attributes]);
|
||||
function destroy_component(component, detaching) {
|
||||
const $$ = component.$$;
|
||||
if ($$.fragment !== null) {
|
||||
flush_render_callbacks($$.after_update);
|
||||
run_all($$.on_destroy);
|
||||
$$.fragment && $$.fragment.d(detaching);
|
||||
$$.on_destroy = $$.fragment = null;
|
||||
$$.ctx = [];
|
||||
}
|
||||
}
|
||||
var SvelteElement;
|
||||
if (typeof HTMLElement === "function") {
|
||||
SvelteElement = class extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({ mode: "open" });
|
||||
}
|
||||
connectedCallback() {
|
||||
const { on_mount } = this.$$;
|
||||
this.$$.on_disconnect = on_mount.map(run).filter(is_function);
|
||||
for (const key in this.$$.slotted) {
|
||||
this.appendChild(this.$$.slotted[key]);
|
||||
}
|
||||
}
|
||||
attributeChangedCallback(attr, _oldValue, newValue) {
|
||||
this[attr] = newValue;
|
||||
}
|
||||
disconnectedCallback() {
|
||||
run_all(this.$$.on_disconnect);
|
||||
}
|
||||
$destroy() {
|
||||
destroy_component(this, 1);
|
||||
this.$destroy = noop;
|
||||
}
|
||||
$on(type, callback) {
|
||||
if (!is_function(callback)) {
|
||||
return noop;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// js/live_svelte/hooks.js
|
||||
function base64ToElement(base64) {
|
||||
const template = document.createElement("div");
|
||||
template.innerHTML = atob(base64).trim();
|
||||
return template;
|
||||
}
|
||||
function dataAttributeToJson(attributeName, el) {
|
||||
const data = el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function createSlots(slots, ref) {
|
||||
const createSlot = (slotName, ref2) => {
|
||||
let savedTarget, savedAnchor, savedElement;
|
||||
return () => {
|
||||
function getSlots(ref) {
|
||||
const slots = {};
|
||||
for (const slotName in getAttributeJson(ref, "data-slots")) {
|
||||
const slot = () => {
|
||||
return {
|
||||
getElement() {
|
||||
return base64ToElement(dataAttributeToJson("data-slots", ref2.el)[slotName]);
|
||||
const base64 = getAttributeJson(ref, "data-slots")[slotName];
|
||||
const element = document.createElement("div");
|
||||
element.innerHTML = atob(base64).trim();
|
||||
return element;
|
||||
},
|
||||
update() {
|
||||
const element = this.getElement();
|
||||
detach(savedElement);
|
||||
insert(savedTarget, element, savedAnchor);
|
||||
savedElement = element;
|
||||
detach(this.savedElement);
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
c: noop,
|
||||
m(target, anchor) {
|
||||
const element = this.getElement();
|
||||
savedTarget = target;
|
||||
savedAnchor = anchor;
|
||||
savedElement = element;
|
||||
insert(target, element, anchor);
|
||||
this.savedTarget = target;
|
||||
this.savedAnchor = anchor;
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
d(detaching) {
|
||||
if (detaching)
|
||||
detach(savedElement);
|
||||
detach(this.savedElement);
|
||||
},
|
||||
l: noop
|
||||
};
|
||||
};
|
||||
};
|
||||
const svelteSlots = {};
|
||||
for (const slotName in slots) {
|
||||
svelteSlots[slotName] = [createSlot(slotName, ref)];
|
||||
slots[slotName] = [slot];
|
||||
}
|
||||
return svelteSlots;
|
||||
return slots;
|
||||
}
|
||||
function getLiveJsonProps(ref) {
|
||||
const json = dataAttributeToJson("data-live-json", ref.el);
|
||||
if (typeof json === "object" && json !== null && !Array.isArray(json))
|
||||
const json = getAttributeJson(ref, "data-live-json");
|
||||
if (!Array.isArray(json))
|
||||
return json;
|
||||
const liveJsonData = {};
|
||||
for (const liveJsonVariable of json) {
|
||||
|
|
@ -198,10 +82,10 @@ function getLiveJsonProps(ref) {
|
|||
}
|
||||
function getProps(ref) {
|
||||
return {
|
||||
...dataAttributeToJson("data-props", ref.el),
|
||||
...getAttributeJson(ref, "data-props"),
|
||||
...getLiveJsonProps(ref),
|
||||
live: ref,
|
||||
$$slots: createSlots(dataAttributeToJson("data-slots", ref.el), ref),
|
||||
$$slots: getSlots(ref),
|
||||
$$scope: {}
|
||||
};
|
||||
}
|
||||
|
|
@ -220,7 +104,7 @@ function getHooks(components) {
|
|||
if (!Component) {
|
||||
throw new Error(`Unable to find ${componentName} component.`);
|
||||
}
|
||||
for (const liveJsonElement of Object.keys(dataAttributeToJson("data-live-json", this.el))) {
|
||||
for (const liveJsonElement of Object.keys(getAttributeJson(this, "data-live-json"))) {
|
||||
window.addEventListener(`${liveJsonElement}_initialized`, (event) => this._instance.$set(getProps(this)), false);
|
||||
window.addEventListener(`${liveJsonElement}_patched`, (event) => this._instance.$set(getProps(this)), false);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -64,172 +64,57 @@ var LiveSvelte = (() => {
|
|||
};
|
||||
}
|
||||
|
||||
// ../node_modules/svelte/internal/index.mjs
|
||||
function noop() {
|
||||
// js/live_svelte/hooks.js
|
||||
function getAttributeJson(ref, attributeName) {
|
||||
const data = ref.el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function run(fn) {
|
||||
return fn();
|
||||
}
|
||||
function run_all(fns) {
|
||||
fns.forEach(run);
|
||||
}
|
||||
function is_function(thing) {
|
||||
return typeof thing === "function";
|
||||
}
|
||||
function is_empty(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
function detach(node) {
|
||||
var _a;
|
||||
(_a = node.parentNode) == null ? void 0 : _a.removeChild(node);
|
||||
}
|
||||
function insert(target, node, anchor) {
|
||||
target.insertBefore(node, anchor || null);
|
||||
}
|
||||
function detach(node) {
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
function noop() {
|
||||
}
|
||||
var render_callbacks = [];
|
||||
function flush_render_callbacks(fns) {
|
||||
const filtered = [];
|
||||
const targets = [];
|
||||
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
|
||||
targets.forEach((c) => c());
|
||||
render_callbacks = filtered;
|
||||
}
|
||||
var globals = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : global;
|
||||
var _boolean_attributes = [
|
||||
"allowfullscreen",
|
||||
"allowpaymentrequest",
|
||||
"async",
|
||||
"autofocus",
|
||||
"autoplay",
|
||||
"checked",
|
||||
"controls",
|
||||
"default",
|
||||
"defer",
|
||||
"disabled",
|
||||
"formnovalidate",
|
||||
"hidden",
|
||||
"inert",
|
||||
"ismap",
|
||||
"itemscope",
|
||||
"loop",
|
||||
"multiple",
|
||||
"muted",
|
||||
"nomodule",
|
||||
"novalidate",
|
||||
"open",
|
||||
"playsinline",
|
||||
"readonly",
|
||||
"required",
|
||||
"reversed",
|
||||
"selected"
|
||||
];
|
||||
var boolean_attributes = /* @__PURE__ */ new Set([..._boolean_attributes]);
|
||||
function destroy_component(component, detaching) {
|
||||
const $$ = component.$$;
|
||||
if ($$.fragment !== null) {
|
||||
flush_render_callbacks($$.after_update);
|
||||
run_all($$.on_destroy);
|
||||
$$.fragment && $$.fragment.d(detaching);
|
||||
$$.on_destroy = $$.fragment = null;
|
||||
$$.ctx = [];
|
||||
}
|
||||
}
|
||||
var SvelteElement;
|
||||
if (typeof HTMLElement === "function") {
|
||||
SvelteElement = class extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({ mode: "open" });
|
||||
}
|
||||
connectedCallback() {
|
||||
const { on_mount } = this.$$;
|
||||
this.$$.on_disconnect = on_mount.map(run).filter(is_function);
|
||||
for (const key in this.$$.slotted) {
|
||||
this.appendChild(this.$$.slotted[key]);
|
||||
}
|
||||
}
|
||||
attributeChangedCallback(attr, _oldValue, newValue) {
|
||||
this[attr] = newValue;
|
||||
}
|
||||
disconnectedCallback() {
|
||||
run_all(this.$$.on_disconnect);
|
||||
}
|
||||
$destroy() {
|
||||
destroy_component(this, 1);
|
||||
this.$destroy = noop;
|
||||
}
|
||||
$on(type, callback) {
|
||||
if (!is_function(callback)) {
|
||||
return noop;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// js/live_svelte/hooks.js
|
||||
function base64ToElement(base64) {
|
||||
const template = document.createElement("div");
|
||||
template.innerHTML = atob(base64).trim();
|
||||
return template;
|
||||
}
|
||||
function dataAttributeToJson(attributeName, el) {
|
||||
const data = el.getAttribute(attributeName);
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
function createSlots(slots, ref) {
|
||||
const createSlot = (slotName, ref2) => {
|
||||
let savedTarget, savedAnchor, savedElement;
|
||||
return () => {
|
||||
function getSlots(ref) {
|
||||
const slots = {};
|
||||
for (const slotName in getAttributeJson(ref, "data-slots")) {
|
||||
const slot = () => {
|
||||
return {
|
||||
getElement() {
|
||||
return base64ToElement(dataAttributeToJson("data-slots", ref2.el)[slotName]);
|
||||
const base64 = getAttributeJson(ref, "data-slots")[slotName];
|
||||
const element = document.createElement("div");
|
||||
element.innerHTML = atob(base64).trim();
|
||||
return element;
|
||||
},
|
||||
update() {
|
||||
const element = this.getElement();
|
||||
detach(savedElement);
|
||||
insert(savedTarget, element, savedAnchor);
|
||||
savedElement = element;
|
||||
detach(this.savedElement);
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
c: noop,
|
||||
m(target, anchor) {
|
||||
const element = this.getElement();
|
||||
savedTarget = target;
|
||||
savedAnchor = anchor;
|
||||
savedElement = element;
|
||||
insert(target, element, anchor);
|
||||
this.savedTarget = target;
|
||||
this.savedAnchor = anchor;
|
||||
this.savedElement = this.getElement();
|
||||
insert(this.savedTarget, this.savedElement, this.savedAnchor);
|
||||
},
|
||||
d(detaching) {
|
||||
if (detaching)
|
||||
detach(savedElement);
|
||||
detach(this.savedElement);
|
||||
},
|
||||
l: noop
|
||||
};
|
||||
};
|
||||
};
|
||||
const svelteSlots = {};
|
||||
for (const slotName in slots) {
|
||||
svelteSlots[slotName] = [createSlot(slotName, ref)];
|
||||
slots[slotName] = [slot];
|
||||
}
|
||||
return svelteSlots;
|
||||
return slots;
|
||||
}
|
||||
function getLiveJsonProps(ref) {
|
||||
const json = dataAttributeToJson("data-live-json", ref.el);
|
||||
if (typeof json === "object" && json !== null && !Array.isArray(json))
|
||||
const json = getAttributeJson(ref, "data-live-json");
|
||||
if (!Array.isArray(json))
|
||||
return json;
|
||||
const liveJsonData = {};
|
||||
for (const liveJsonVariable of json) {
|
||||
|
|
@ -240,9 +125,9 @@ var LiveSvelte = (() => {
|
|||
return liveJsonData;
|
||||
}
|
||||
function getProps(ref) {
|
||||
return __spreadProps(__spreadValues(__spreadValues({}, dataAttributeToJson("data-props", ref.el)), getLiveJsonProps(ref)), {
|
||||
return __spreadProps(__spreadValues(__spreadValues({}, getAttributeJson(ref, "data-props")), getLiveJsonProps(ref)), {
|
||||
live: ref,
|
||||
$$slots: createSlots(dataAttributeToJson("data-slots", ref.el), ref),
|
||||
$$slots: getSlots(ref),
|
||||
$$scope: {}
|
||||
});
|
||||
}
|
||||
|
|
@ -261,7 +146,7 @@ var LiveSvelte = (() => {
|
|||
if (!Component) {
|
||||
throw new Error(`Unable to find ${componentName} component.`);
|
||||
}
|
||||
for (const liveJsonElement of Object.keys(dataAttributeToJson("data-live-json", this.el))) {
|
||||
for (const liveJsonElement of Object.keys(getAttributeJson(this, "data-live-json"))) {
|
||||
window.addEventListener(`${liveJsonElement}_initialized`, (event) => this._instance.$set(getProps(this)), false);
|
||||
window.addEventListener(`${liveJsonElement}_patched`, (event) => this._instance.$set(getProps(this)), false);
|
||||
}
|
||||
|
|
|
|||
2
priv/static/live_svelte.min.js
vendored
2
priv/static/live_svelte.min.js
vendored
|
|
@ -1 +1 @@
|
|||
var LiveSvelte=(()=>{var d=Object.defineProperty,C=Object.defineProperties,D=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var w=(t,e,n)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n in e||(e={}))F.call(e,n)&&w(t,n,e[n]);if($)for(var n of $(e))j.call(e,n)&&w(t,n,e[n]);return t},v=(t,e)=>C(t,M(e));var N=(t,e)=>{for(var n in e)d(t,n,{get:e[n],enumerable:!0})},L=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!F.call(t,o)&&o!==n&&d(t,o,{get:()=>e[o],enumerable:!(i=D(e,o))||i.enumerable});return t};var P=t=>L(d({},"__esModule",{value:!0}),t);var U={};N(U,{getHooks:()=>O,getRender:()=>x});function _(t){if(!Array.isArray(t.default)||!Array.isArray(t.filenames))return t;let e={};for(let[n,i]of t.default.entries()){let o=i.default,s=t.filenames[n].replace("../svelte/","").replace(".svelte","");e[s]=o}return e}function x(t){return t=_(t),function(n,i,o){let s=t[n],a=Object.fromEntries(Object.entries(o).map(([f,c])=>[f,()=>c]));return s.render(i,{$$slots:a})}}function l(){}function S(t){return t()}function A(t){t.forEach(S)}function E(t){return typeof t=="function"}function R(t){return Object.keys(t).length===0}function m(t,e,n){t.insertBefore(e,n||null)}function y(t){t.parentNode&&t.parentNode.removeChild(t)}var k=[];function q(t){let e=[],n=[];k.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),k=e}var Q=typeof window!="undefined"?window:typeof globalThis!="undefined"?globalThis:global;var z=["allowfullscreen","allowpaymentrequest","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],Z=new Set([...z]);function I(t,e){let n=t.$$;n.fragment!==null&&(q(n.after_update),A(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}var B;typeof HTMLElement=="function"&&(B=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){let{on_mount:t}=this.$$;this.$$.on_disconnect=t.map(S).filter(E);for(let e in this.$$.slotted)this.appendChild(this.$$.slotted[e])}attributeChangedCallback(t,e,n){this[t]=n}disconnectedCallback(){A(this.$$.on_disconnect)}$destroy(){I(this,1),this.$destroy=l}$on(t,e){if(!E(e))return l;let n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{let i=n.indexOf(e);i!==-1&&n.splice(i,1)}}$set(t){this.$$set&&!R(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}});function H(t){let e=document.createElement("div");return e.innerHTML=atob(t).trim(),e}function u(t,e){let n=e.getAttribute(t);return n?JSON.parse(n):{}}function J(t,e){let n=(o,s)=>{let a,f,c;return()=>({getElement(){return H(u("data-slots",s.el)[o])},update(){let r=this.getElement();y(c),m(a,r,f),c=r},c:l,m(r,g){let b=this.getElement();a=r,f=g,c=b,m(r,b,g)},d(r){r&&y(c)},l})},i={};for(let o in t)i[o]=[n(o,e)];return i}function G(t){let e=u("data-live-json",t.el);if(typeof e=="object"&&e!==null&&!Array.isArray(e))return e;let n={};for(let i of e){let o=window[i];o&&(n[i]=o)}return n}function h(t){return v(p(p({},u("data-props",t.el)),G(t)),{live:t,$$slots:J(u("data-slots",t.el),t),$$scope:{}})}function W(t){return t.$$.ctx.find(e=>e==null?void 0:e.default)}function O(t){return t=_(t),{SvelteHook:{mounted(){let n=this.el.getAttribute("data-name");if(!n)throw new Error("Component name must be provided");let i=t[n];if(!i)throw new Error(`Unable to find ${n} component.`);for(let o of Object.keys(u("data-live-json",this.el)))window.addEventListener(`${o}_initialized`,s=>this._instance.$set(h(this)),!1),window.addEventListener(`${o}_patched`,s=>this._instance.$set(h(this)),!1);this._instance=new i({target:this.el,props:h(this),hydrate:this.el.hasAttribute("data-ssr")})},updated(){this._instance.$set(h(this));let n=W(this._instance);for(let i in n)n[i][0]().update()},destroyed(){}}}}return P(U);})();
|
||||
var LiveSvelte=(()=>{var a=Object.defineProperty,y=Object.defineProperties,C=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,u=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var f=(t,e,n)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,c=(t,e)=>{for(var n in e||(e={}))h.call(e,n)&&f(t,n,e[n]);if(u)for(var n of u(e))k.call(e,n)&&f(t,n,e[n]);return t},m=(t,e)=>y(t,_(e));var J=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},x=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of j(e))!h.call(t,s)&&s!==n&&a(t,s,{get:()=>e[s],enumerable:!(o=C(e,s))||o.enumerable});return t};var z=t=>x(a({},"__esModule",{value:!0}),t);var N={};J(N,{getHooks:()=>A,getRender:()=>v});function d(t){if(!Array.isArray(t.default)||!Array.isArray(t.filenames))return t;let e={};for(let[n,o]of t.default.entries()){let s=o.default,r=t.filenames[n].replace("../svelte/","").replace(".svelte","");e[r]=s}return e}function v(t){return t=d(t),function(n,o,s){let r=t[n],b=Object.fromEntries(Object.entries(s).map(([E,w])=>[E,()=>w]));return r.render(o,{$$slots:b})}}function i(t,e){let n=t.el.getAttribute(e);return n?JSON.parse(n):{}}function p(t){var e;(e=t.parentNode)==null||e.removeChild(t)}function g(t,e,n){t.insertBefore(e,n||null)}function $(){}function H(t){let e={};for(let n in i(t,"data-slots")){let o=()=>({getElement(){let s=i(t,"data-slots")[n],r=document.createElement("div");return r.innerHTML=atob(s).trim(),r},update(){p(this.savedElement),this.savedElement=this.getElement(),g(this.savedTarget,this.savedElement,this.savedAnchor)},c:$,m(s,r){this.savedTarget=s,this.savedAnchor=r,this.savedElement=this.getElement(),g(this.savedTarget,this.savedElement,this.savedAnchor)},d(s){s&&p(this.savedElement)},l:$});e[n]=[o]}return e}function S(t){let e=i(t,"data-live-json");if(!Array.isArray(e))return e;let n={};for(let o of e){let s=window[o];s&&(n[o]=s)}return n}function l(t){return m(c(c({},i(t,"data-props")),S(t)),{live:t,$$slots:H(t),$$scope:{}})}function L(t){return t.$$.ctx.find(e=>e==null?void 0:e.default)}function A(t){return t=d(t),{SvelteHook:{mounted(){let n=this.el.getAttribute("data-name");if(!n)throw new Error("Component name must be provided");let o=t[n];if(!o)throw new Error(`Unable to find ${n} component.`);for(let s of Object.keys(i(this,"data-live-json")))window.addEventListener(`${s}_initialized`,r=>this._instance.$set(l(this)),!1),window.addEventListener(`${s}_patched`,r=>this._instance.$set(l(this)),!1);this._instance=new o({target:this.el,props:l(this),hydrate:this.el.hasAttribute("data-ssr")})},updated(){this._instance.$set(l(this));let n=L(this._instance);for(let o in n)n[o][0]().update()},destroyed(){}}}}return z(N);})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue