Add supporting themes required for Lotusdocs
This commit is contained in:
67
themes/hugo-mod-jslibs-dist/alpinejs/packages/persist/dist/cdn.js
vendored
Normal file
67
themes/hugo-mod-jslibs-dist/alpinejs/packages/persist/dist/cdn.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
(() => {
|
||||
// packages/persist/src/index.js
|
||||
function src_default(Alpine) {
|
||||
let persist = () => {
|
||||
let alias;
|
||||
let storage;
|
||||
try {
|
||||
storage = localStorage;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.warn("Alpine: $persist is using temporary storage since localStorage is unavailable.");
|
||||
let dummy = /* @__PURE__ */ new Map();
|
||||
storage = {
|
||||
getItem: dummy.get.bind(dummy),
|
||||
setItem: dummy.set.bind(dummy)
|
||||
};
|
||||
}
|
||||
return Alpine.interceptor((initialValue, getter, setter, path, key) => {
|
||||
let lookup = alias || `_x_${path}`;
|
||||
let initial = storageHas(lookup, storage) ? storageGet(lookup, storage) : initialValue;
|
||||
setter(initial);
|
||||
Alpine.effect(() => {
|
||||
let value = getter();
|
||||
storageSet(lookup, value, storage);
|
||||
setter(value);
|
||||
});
|
||||
return initial;
|
||||
}, (func) => {
|
||||
func.as = (key) => {
|
||||
alias = key;
|
||||
return func;
|
||||
}, func.using = (target) => {
|
||||
storage = target;
|
||||
return func;
|
||||
};
|
||||
});
|
||||
};
|
||||
Object.defineProperty(Alpine, "$persist", { get: () => persist() });
|
||||
Alpine.magic("persist", persist);
|
||||
Alpine.persist = (key, { get, set }, storage = localStorage) => {
|
||||
let initial = storageHas(key, storage) ? storageGet(key, storage) : get();
|
||||
set(initial);
|
||||
Alpine.effect(() => {
|
||||
let value = get();
|
||||
storageSet(key, value, storage);
|
||||
set(value);
|
||||
});
|
||||
};
|
||||
}
|
||||
function storageHas(key, storage) {
|
||||
return storage.getItem(key) !== null;
|
||||
}
|
||||
function storageGet(key, storage) {
|
||||
let value = storage.getItem(key, storage);
|
||||
if (value === void 0)
|
||||
return;
|
||||
return JSON.parse(value);
|
||||
}
|
||||
function storageSet(key, value, storage) {
|
||||
storage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
// packages/persist/builds/cdn.js
|
||||
document.addEventListener("alpine:init", () => {
|
||||
window.Alpine.plugin(src_default);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user