mirror of
https://github.com/tenrok/vue-tribute.git
synced 2026-06-10 00:22:27 +03:00
Commits build files
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-demo
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
import { defineComponent, ref, onMounted, onBeforeUnmount, watch, nextTick, h, unref } from "vue";
|
||||
import Tribute from "tributejs";
|
||||
const VueTribute = defineComponent({
|
||||
name: "vue-tribute",
|
||||
props: {
|
||||
options: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
setup(props, context) {
|
||||
if (typeof Tribute === "undefined") {
|
||||
throw new Error("[vue-tribute] cannot locate tributejs.");
|
||||
}
|
||||
const root = ref();
|
||||
const el = ref();
|
||||
const attachTribute = (el2, options = props.options) => {
|
||||
if (!el2.value)
|
||||
return;
|
||||
let tribute = new Tribute(unref(options));
|
||||
tribute.attach(el2.value);
|
||||
el2.value.tributeInstance = tribute;
|
||||
};
|
||||
onMounted(() => {
|
||||
var _a;
|
||||
el.value = (_a = root.value) == null ? void 0 : _a.childNodes[0];
|
||||
if (!el) {
|
||||
throw new Error("[vue-tribute] cannot find a suitable element to attach to.");
|
||||
}
|
||||
attachTribute(el);
|
||||
el.value.addEventListener("tribute-replaced", (e) => {
|
||||
var _a2;
|
||||
(_a2 = e.target) == null ? void 0 : _a2.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
});
|
||||
});
|
||||
const detachTribute = (el2) => {
|
||||
var _a;
|
||||
if (!((_a = el2.value) == null ? void 0 : _a.tributeInstance))
|
||||
return;
|
||||
el2.value.tributeInstance.detach(el2.value);
|
||||
el2.value.tributeInstance = void 0;
|
||||
delete el2.value.dataset.tribute;
|
||||
};
|
||||
onBeforeUnmount(() => {
|
||||
detachTribute(el);
|
||||
});
|
||||
watch(() => props.options, async (newOptions) => {
|
||||
var _a;
|
||||
if ((_a = el.value) == null ? void 0 : _a.tributeInstance) {
|
||||
await nextTick();
|
||||
detachTribute(el);
|
||||
await nextTick();
|
||||
attachTribute(el, __spreadValues({}, newOptions));
|
||||
}
|
||||
}, { deep: true });
|
||||
return () => h("div", { class: "v-tribute", ref: root }, [context.slots.default ? context.slots.default()[0] : null].filter(Boolean));
|
||||
}
|
||||
});
|
||||
const install = (app) => {
|
||||
app.component(VueTribute.name, VueTribute);
|
||||
};
|
||||
VueTribute.install = install;
|
||||
export { VueTribute, VueTribute as default };
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
var w=Object.defineProperty;var p=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var v=(t,e,u)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[e]=u,h=(t,e)=>{for(var u in e||(e={}))y.call(e,u)&&v(t,u,e[u]);if(p)for(var u of p(e))j.call(e,u)&&v(t,u,e[u]);return t};(function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue"),require("tributejs")):typeof define=="function"&&define.amd?define(["exports","vue","tributejs"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["vue-tribute"]={},t.Vue,t.Tribute))})(this,function(t,e,u){"use strict";function T(i){return i&&typeof i=="object"&&"default"in i?i:{default:i}}var d=T(u);const o=e.defineComponent({name:"vue-tribute",props:{options:{type:Object,required:!0}},setup(i,f){if(typeof d.default=="undefined")throw new Error("[vue-tribute] cannot locate tributejs.");const l=e.ref(),a=e.ref(),c=(n,r=i.options)=>{if(!n.value)return;let s=new d.default(e.unref(r));s.attach(n.value),n.value.tributeInstance=s};e.onMounted(()=>{var n;if(a.value=(n=l.value)==null?void 0:n.childNodes[0],!a)throw new Error("[vue-tribute] cannot find a suitable element to attach to.");c(a),a.value.addEventListener("tribute-replaced",r=>{var s;(s=r.target)==null||s.dispatchEvent(new Event("input",{bubbles:!0}))})});const b=n=>{var r;!((r=n.value)==null?void 0:r.tributeInstance)||(n.value.tributeInstance.detach(n.value),n.value.tributeInstance=void 0,delete n.value.dataset.tribute)};return e.onBeforeUnmount(()=>{b(a)}),e.watch(()=>i.options,async n=>{var r;((r=a.value)==null?void 0:r.tributeInstance)&&(await e.nextTick(),b(a),await e.nextTick(),c(a,h({},n)))},{deep:!0}),()=>e.h("div",{class:"v-tribute",ref:l},[f.slots.default?f.slots.default()[0]:null].filter(Boolean))}}),m=i=>{i.component(o.name,o)};o.install=m,t.VueTribute=o,t.default=o,Object.defineProperty(t,"__esModule",{value:!0}),t[Symbol.toStringTag]="Module"});
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"start": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"build": "vue-tsc --noEmit --skipLibCheck && vite build",
|
||||
"build:demo": "vite build --mode demo",
|
||||
"preview": "vite preview",
|
||||
"serve": "vite preview",
|
||||
|
||||
+2
-1
@@ -13,5 +13,6 @@
|
||||
"lib": ["esnext", "dom"],
|
||||
"types": ["node", "vitest/globals"]
|
||||
},
|
||||
"include": ["vite.config.ts", "env.d.ts", "lib/**/*.ts", "demo/**/*.ts", "demo/**/*.vue"]
|
||||
"include": ["vite.config.ts", "env.d.ts", "lib/**/*.ts", "demo/**/*.ts", "demo/**/*.vue"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user