@aevantec/litevue 0.5.5 → 0.5.7
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/README.md +10 -7
- package/dist/litevue-devtools.iife.js +1 -1
- package/dist/litevue-devtools.mjs +1 -1
- package/dist/litevue-devtools.umd.js +1 -1
- package/dist/litevue-plugins.dev.iife.js +898 -0
- package/dist/litevue-plugins.dev.mjs +880 -0
- package/dist/litevue-plugins.iife.js +1 -1
- package/dist/litevue-plugins.mjs +1 -1
- package/dist/litevue-plugins.umd.js +1 -1
- package/dist/litevue.dev.iife.js +2103 -0
- package/dist/litevue.dev.mjs +2092 -0
- package/dist/litevue.iife.js +1 -1
- package/dist/litevue.mjs +1 -1
- package/dist/litevue.umd.js +1 -1
- package/dist/plugins/collapse.iife.js +1 -1
- package/dist/plugins/collapse.mjs +1 -1
- package/dist/plugins/collapse.umd.js +1 -1
- package/dist/plugins/media.dev.iife.js +249 -0
- package/dist/plugins/media.dev.mjs +243 -0
- package/dist/plugins/morph.dev.iife.js +217 -0
- package/dist/plugins/morph.dev.mjs +212 -0
- package/dist/plugins/morph.iife.js +1 -1
- package/dist/plugins/morph.mjs +1 -1
- package/dist/plugins/morph.umd.js +1 -1
- package/dist/plugins/persist.dev.iife.js +126 -0
- package/dist/plugins/persist.dev.mjs +120 -0
- package/dist/types/app.d.mts +15 -18
- package/dist/types/app.d.ts +15 -18
- package/dist/types/block.d.mts +1 -2
- package/dist/types/block.d.ts +1 -2
- package/dist/types/context.d.mts +5 -8
- package/dist/types/context.d.ts +5 -8
- package/dist/types/devtools.d.mts +7 -0
- package/dist/types/devtools.d.ts +7 -0
- package/dist/types/effect.d.mts +6 -10
- package/dist/types/effect.d.ts +6 -10
- package/dist/types/errors.d.mts +36 -0
- package/dist/types/errors.d.ts +36 -0
- package/dist/types/eval.d.mts +8 -2
- package/dist/types/eval.d.ts +8 -2
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/magics.d.mts +5 -6
- package/dist/types/magics.d.ts +5 -6
- package/dist/types/ownership.d.mts +9 -16
- package/dist/types/ownership.d.ts +9 -16
- package/dist/types/plugins/focus/index.d.mts +6 -8
- package/dist/types/plugins/focus/index.d.ts +6 -8
- package/dist/types/plugins/media/index.d.mts +6 -7
- package/dist/types/plugins/media/index.d.ts +6 -7
- package/dist/types/plugins/morph/index.d.mts +23 -11
- package/dist/types/plugins/morph/index.d.ts +23 -11
- package/dist/types/plugins/persist/index.d.mts +12 -19
- package/dist/types/plugins/persist/index.d.ts +12 -19
- package/dist/types/plugins/resize/index.d.mts +5 -7
- package/dist/types/plugins/resize/index.d.ts +5 -7
- package/dist/types/plugins/transition/index.d.mts +7 -12
- package/dist/types/plugins/transition/index.d.ts +7 -12
- package/dist/types/store.d.mts +3 -6
- package/dist/types/store.d.ts +3 -6
- package/dist/types/utils.d.mts +3 -3
- package/dist/types/utils.d.ts +3 -3
- package/dist/types/warn.d.mts +6 -8
- package/dist/types/warn.d.ts +6 -8
- package/package.json +11 -2
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
//#region src/plugins/morph/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* A `data-` attribute rather than `v-preserve`: an unrecognised `v-` attribute
|
|
4
|
+
* logs an unknown-directive error, and registering one would have the walker
|
|
5
|
+
* strip it, leaving nothing for the next morph. Matches `data-morph-skip`.
|
|
6
|
+
*/
|
|
7
|
+
var preserved = (node, opts) => node.nodeType === 1 && (node.hasAttribute("data-morph-preserve") || !!opts.preserve?.(node));
|
|
8
|
+
var dirRE = /^(?:v-|:|@)/;
|
|
9
|
+
var bindRE = /^(?::|v-bind:)/;
|
|
10
|
+
/**
|
|
11
|
+
* Attributes tried in order when no `key` option is given. All three express
|
|
12
|
+
* identity, so none repeat among siblings the way `name` does on a radio group
|
|
13
|
+
* — hence its absence. The attribute name is part of the key, so `id="5"` and
|
|
14
|
+
* `data-id="5"` stay distinct.
|
|
15
|
+
*/
|
|
16
|
+
var KEY_ATTRS = [
|
|
17
|
+
"id",
|
|
18
|
+
"data-key",
|
|
19
|
+
"data-id"
|
|
20
|
+
];
|
|
21
|
+
var defaultKey = (el) => {
|
|
22
|
+
for (const attr of KEY_ATTRS) {
|
|
23
|
+
const value = el.getAttribute(attr);
|
|
24
|
+
if (value != null) return attr + "=" + value;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The nearest stashed context, walking up from a live node. `v-scope` elements
|
|
30
|
+
* record theirs during walk, so inserted markup binds with the scope it landed
|
|
31
|
+
* in rather than the root.
|
|
32
|
+
*/
|
|
33
|
+
var nearestCtx = (node) => {
|
|
34
|
+
for (let el = node; el; el = el.parentElement) if (el.__ctx) return el.__ctx;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Attributes the client owns, read from the *incoming* markup — it still
|
|
38
|
+
* carries the directives the live DOM had stripped. `:class` there means the
|
|
39
|
+
* live `class` is bound and must survive the server's static value.
|
|
40
|
+
*/
|
|
41
|
+
var boundAttrs = (to) => {
|
|
42
|
+
const owned = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const { name } of to.attributes) if (bindRE.test(name)) owned.add(name.replace(bindRE, "").split(".")[0]);
|
|
44
|
+
else if (name === "v-model") {
|
|
45
|
+
owned.add("value");
|
|
46
|
+
owned.add("checked");
|
|
47
|
+
}
|
|
48
|
+
return owned;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* `v-for` and `v-if` render into Blocks: the live DOM holds anchors plus the
|
|
52
|
+
* clones the data produced, while the server still sends one template. Matched
|
|
53
|
+
* positionally, the rest would be deleted as "no longer sent".
|
|
54
|
+
*/
|
|
55
|
+
var isBlockRoot = (el) => el.hasAttribute("v-for") || el.hasAttribute("v-if") || el.hasAttribute("v-else") || el.hasAttribute("v-else-if");
|
|
56
|
+
/** True when the client, not the server, decides this element's contents. */
|
|
57
|
+
var ownsChildren = (to) => {
|
|
58
|
+
if (to.hasAttribute("v-text") || to.hasAttribute("v-html") || to.hasAttribute("v-pre") || to.hasAttribute("v-once") || isBlockRoot(to)) return true;
|
|
59
|
+
for (let c = to.firstElementChild; c; c = c.nextElementSibling) if (isBlockRoot(c)) return true;
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
var patchAttrs = (from, to) => {
|
|
63
|
+
const owned = boundAttrs(to);
|
|
64
|
+
for (const { name, value } of [...to.attributes]) {
|
|
65
|
+
if (dirRE.test(name) || owned.has(name)) continue;
|
|
66
|
+
if (from.getAttribute(name) !== value) from.setAttribute(name, value);
|
|
67
|
+
}
|
|
68
|
+
for (const { name } of [...from.attributes]) {
|
|
69
|
+
if (owned.has(name) || to.hasAttribute(name)) continue;
|
|
70
|
+
from.removeAttribute(name);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Incoming text still holding `{{ }}` is rendered by a text directive on the
|
|
75
|
+
* live side, so the live value wins.
|
|
76
|
+
*/
|
|
77
|
+
var isInterpolation = (data, ctx) => data.includes(ctx ? ctx.delimiters[0] : "{{");
|
|
78
|
+
var patchNode = (from, to, ctx, opts) => {
|
|
79
|
+
if (from.nodeType !== to.nodeType) return replaceNode(from, to, ctx, opts);
|
|
80
|
+
if (from.nodeType === 3 || from.nodeType === 8) {
|
|
81
|
+
const data = to.data;
|
|
82
|
+
if (isInterpolation(data, ctx)) return;
|
|
83
|
+
if (from.data !== data) from.data = data;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (from.nodeType !== 1) return;
|
|
87
|
+
const a = from;
|
|
88
|
+
const b = to;
|
|
89
|
+
if (a.tagName !== b.tagName) return replaceNode(from, to, ctx, opts);
|
|
90
|
+
if (opts.skip?.(a, b) || a.hasAttribute("data-morph-skip")) return;
|
|
91
|
+
patchAttrs(a, b);
|
|
92
|
+
if (!ownsChildren(b)) patchChildren(a, b, a.__ctx || ctx, opts);
|
|
93
|
+
};
|
|
94
|
+
var replaceNode = (from, to, ctx, opts) => {
|
|
95
|
+
if (preserved(from, opts)) return;
|
|
96
|
+
const fresh = to.cloneNode(true);
|
|
97
|
+
if (opts.beforeNodeAdded?.(fresh) === false) return;
|
|
98
|
+
ctx?.dispose?.(from);
|
|
99
|
+
from.parentNode.replaceChild(fresh, from);
|
|
100
|
+
opts.afterNodeRemoved?.(from);
|
|
101
|
+
mountNew(fresh, ctx);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Bind never-walked markup with the scope it was inserted into. The walker
|
|
105
|
+
* comes off the context, not an import, so this plugin doesn't pull a second
|
|
106
|
+
* copy of the core into the plugins bundle.
|
|
107
|
+
*/
|
|
108
|
+
var mountNew = (node, ctx) => {
|
|
109
|
+
const target = ctx || nearestCtx(node.parentNode);
|
|
110
|
+
target?.walk?.(node, target);
|
|
111
|
+
};
|
|
112
|
+
var patchChildren = (from, to, ctx, opts) => {
|
|
113
|
+
const key = opts.key || defaultKey;
|
|
114
|
+
const keyed = /* @__PURE__ */ new Map();
|
|
115
|
+
for (let n = from.firstChild; n; n = n.nextSibling) if (n.nodeType === 1) {
|
|
116
|
+
const k = key(n);
|
|
117
|
+
if (k == null) continue;
|
|
118
|
+
if (keyed.has(k)) console.warn(`[morph] duplicate key ${JSON.stringify(k)} among siblings; only the last is reusable. Keys must be unique within a parent.`);
|
|
119
|
+
keyed.set(k, n);
|
|
120
|
+
}
|
|
121
|
+
const keyOf = (n) => n && n.nodeType === 1 ? key(n) : null;
|
|
122
|
+
let oldChild = from.firstChild;
|
|
123
|
+
let newChild = to.firstChild;
|
|
124
|
+
const insert = (node) => {
|
|
125
|
+
const fresh = node.cloneNode(true);
|
|
126
|
+
if (opts.beforeNodeAdded?.(fresh) === false) return;
|
|
127
|
+
from.insertBefore(fresh, oldChild);
|
|
128
|
+
mountNew(fresh, ctx);
|
|
129
|
+
};
|
|
130
|
+
while (newChild) {
|
|
131
|
+
const nextNew = newChild.nextSibling;
|
|
132
|
+
const wantKey = keyOf(newChild);
|
|
133
|
+
if (wantKey != null) {
|
|
134
|
+
const match = keyed.get(wantKey);
|
|
135
|
+
if (match) {
|
|
136
|
+
if (match === oldChild) oldChild = oldChild.nextSibling;
|
|
137
|
+
else from.insertBefore(match, oldChild);
|
|
138
|
+
keyed.delete(wantKey);
|
|
139
|
+
patchNode(match, newChild, ctx, opts);
|
|
140
|
+
} else insert(newChild);
|
|
141
|
+
} else if (oldChild && keyOf(oldChild) == null) {
|
|
142
|
+
const nextOld = oldChild.nextSibling;
|
|
143
|
+
patchNode(oldChild, newChild, ctx, opts);
|
|
144
|
+
oldChild = nextOld;
|
|
145
|
+
} else insert(newChild);
|
|
146
|
+
newChild = nextNew;
|
|
147
|
+
}
|
|
148
|
+
while (oldChild) {
|
|
149
|
+
const next = oldChild.nextSibling;
|
|
150
|
+
if (!preserved(oldChild, opts)) {
|
|
151
|
+
ctx?.dispose?.(oldChild);
|
|
152
|
+
from.removeChild(oldChild);
|
|
153
|
+
opts.afterNodeRemoved?.(oldChild);
|
|
154
|
+
}
|
|
155
|
+
oldChild = next;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* morph(from, to) — patch `from` in place so it matches `to`, which may be an
|
|
160
|
+
* element or an HTML string for the *outer* element.
|
|
161
|
+
*/
|
|
162
|
+
var morph = (from, to, opts = {}) => {
|
|
163
|
+
let target;
|
|
164
|
+
if (typeof to === "string") {
|
|
165
|
+
const holder = document.createElement("template");
|
|
166
|
+
holder.innerHTML = to.trim();
|
|
167
|
+
const content = holder.content;
|
|
168
|
+
target = content.childElementCount === 1 ? content.firstElementChild : (() => {
|
|
169
|
+
const wrapper = from.cloneNode(false);
|
|
170
|
+
wrapper.appendChild(content);
|
|
171
|
+
return wrapper;
|
|
172
|
+
})();
|
|
173
|
+
} else target = to;
|
|
174
|
+
if (target) {
|
|
175
|
+
const restore = captureFocus();
|
|
176
|
+
patchNode(from, target, nearestCtx(from), opts);
|
|
177
|
+
restore();
|
|
178
|
+
}
|
|
179
|
+
return from;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* `insertBefore` blurs the node it moves, so a reorder drops focus even though
|
|
183
|
+
* the element survived. Re-focus afterwards and restore the caret. Only
|
|
184
|
+
* observable in a real browser — jsdom does not blur on move.
|
|
185
|
+
*/
|
|
186
|
+
var captureFocus = () => {
|
|
187
|
+
const active = document.activeElement;
|
|
188
|
+
if (!active || active === document.body) return () => {};
|
|
189
|
+
const field = active;
|
|
190
|
+
let start = null;
|
|
191
|
+
let end = null;
|
|
192
|
+
try {
|
|
193
|
+
start = field.selectionStart;
|
|
194
|
+
end = field.selectionEnd;
|
|
195
|
+
} catch {}
|
|
196
|
+
return () => {
|
|
197
|
+
if (active === document.activeElement || !active.isConnected) return;
|
|
198
|
+
active.focus();
|
|
199
|
+
if (start !== null) try {
|
|
200
|
+
field.setSelectionRange(start, end);
|
|
201
|
+
} catch {}
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Registers `$morph`, so a template can update a region from a fetch response
|
|
206
|
+
* without dropping into JavaScript.
|
|
207
|
+
*/
|
|
208
|
+
var morphPlugin = (app) => {
|
|
209
|
+
app.scope.$morph = morph;
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
export { morph, morphPlugin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var LiteVueMorph=function(
|
|
1
|
+
var LiteVueMorph=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=(e,t)=>1===e.nodeType&&(e.hasAttribute("data-morph-preserve")||!!t.preserve?.(e)),n=/^(?:v-|:|@)/,r=/^(?::|v-bind:)/,o=["id","data-key","data-id"],i=e=>{for(const t of o){const n=e.getAttribute(t);if(null!=n)return t+"="+n}return null},s=e=>{for(let t=e;t;t=t.parentElement)if(t.__ctx)return t.__ctx},l=e=>e.hasAttribute("v-for")||e.hasAttribute("v-if")||e.hasAttribute("v-else")||e.hasAttribute("v-else-if"),d=(e,t)=>{const o=(e=>{const t=new Set;for(const{name:n}of e.attributes)r.test(n)?t.add(n.replace(r,"").split(".")[0]):"v-model"===n&&(t.add("value"),t.add("checked"));return t})(t);for(const{name:r,value:i}of[...t.attributes])n.test(r)||o.has(r)||e.getAttribute(r)!==i&&e.setAttribute(r,i);for(const{name:n}of[...e.attributes])o.has(n)||t.hasAttribute(n)||e.removeAttribute(n)},a=(e,t,n,r)=>{if(e.nodeType!==t.nodeType)return c(e,t,n,r);if(3===e.nodeType||8===e.nodeType){const r=t.data;if(((e,t)=>e.includes(t?t.delimiters[0]:"{{"))(r,n))return;return void(e.data!==r&&(e.data=r))}if(1!==e.nodeType)return;const o=e,i=t;if(o.tagName!==i.tagName)return c(e,t,n,r);r.skip?.(o,i)||o.hasAttribute("data-morph-skip")||(d(o,i),(e=>{if(e.hasAttribute("v-text")||e.hasAttribute("v-html")||e.hasAttribute("v-pre")||e.hasAttribute("v-once")||l(e))return!0;for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(l(t))return!0;return!1})(i)||f(o,i,o.__ctx||n,r))},c=(e,n,r,o)=>{if(t(e,o))return;const i=n.cloneNode(!0);!1!==o.beforeNodeAdded?.(i)&&(r?.dispose?.(e),e.parentNode.replaceChild(i,e),o.afterNodeRemoved?.(e),u(i,r))},u=(e,t)=>{const n=t||s(e.parentNode);n?.walk?.(e,n)},f=(e,n,r,o)=>{const s=o.key||i,l=new Map;for(let t=e.firstChild;t;t=t.nextSibling)if(1===t.nodeType){const e=s(t);if(null==e)continue;l.set(e,t)}const d=e=>e&&1===e.nodeType?s(e):null;let c=e.firstChild,f=n.firstChild;const p=t=>{const n=t.cloneNode(!0);!1!==o.beforeNodeAdded?.(n)&&(e.insertBefore(n,c),u(n,r))};for(;f;){const t=f.nextSibling,n=d(f);if(null!=n){const t=l.get(n);t?(t===c?c=c.nextSibling:e.insertBefore(t,c),l.delete(n),a(t,f,r,o)):p(f)}else if(c&&null==d(c)){const e=c.nextSibling;a(c,f,r,o),c=e}else p(f);f=t}for(;c;){const n=c.nextSibling;t(c,o)||(r?.dispose?.(c),e.removeChild(c),o.afterNodeRemoved?.(c)),c=n}},p=(e,t,n={})=>{let r;if("string"==typeof t){const n=document.createElement("template");n.innerHTML=t.trim();const o=n.content;r=1===o.childElementCount?o.firstElementChild:(()=>{const t=e.cloneNode(!1);return t.appendChild(o),t})()}else r=t;if(r){const t=h();a(e,r,s(e),n),t()}return e},h=()=>{const e=document.activeElement;if(!e||e===document.body)return()=>{};const t=e;let n=null,r=null;try{n=t.selectionStart,r=t.selectionEnd}catch{}return()=>{if(e!==document.activeElement&&e.isConnected&&(e.focus(),null!==n))try{t.setSelectionRange(n,r)}catch{}}};return e.morph=p,e.morphPlugin=e=>{e.scope.$morph=p},e}({});
|
package/dist/plugins/morph.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=/^(?:v-|:|@)/,
|
|
1
|
+
var e=(e,t)=>1===e.nodeType&&(e.hasAttribute("data-morph-preserve")||!!t.preserve?.(e)),t=/^(?:v-|:|@)/,n=/^(?::|v-bind:)/,r=["id","data-key","data-id"],o=e=>{for(const t of r){const n=e.getAttribute(t);if(null!=n)return t+"="+n}return null},i=e=>{for(let t=e;t;t=t.parentElement)if(t.__ctx)return t.__ctx},s=e=>e.hasAttribute("v-for")||e.hasAttribute("v-if")||e.hasAttribute("v-else")||e.hasAttribute("v-else-if"),l=(e,r)=>{const o=(e=>{const t=/* @__PURE__ */new Set;for(const{name:r}of e.attributes)n.test(r)?t.add(r.replace(n,"").split(".")[0]):"v-model"===r&&(t.add("value"),t.add("checked"));return t})(r);for(const{name:n,value:i}of[...r.attributes])t.test(n)||o.has(n)||e.getAttribute(n)!==i&&e.setAttribute(n,i);for(const{name:t}of[...e.attributes])o.has(t)||r.hasAttribute(t)||e.removeAttribute(t)},d=(e,t,n,r)=>{if(e.nodeType!==t.nodeType)return a(e,t,n,r);if(3===e.nodeType||8===e.nodeType){const r=t.data;if(((e,t)=>e.includes(t?t.delimiters[0]:"{{"))(r,n))return;return void(e.data!==r&&(e.data=r))}if(1!==e.nodeType)return;const o=e,i=t;if(o.tagName!==i.tagName)return a(e,t,n,r);r.skip?.(o,i)||o.hasAttribute("data-morph-skip")||(l(o,i),(e=>{if(e.hasAttribute("v-text")||e.hasAttribute("v-html")||e.hasAttribute("v-pre")||e.hasAttribute("v-once")||s(e))return!0;for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(s(t))return!0;return!1})(i)||u(o,i,o.__ctx||n,r))},a=(t,n,r,o)=>{if(e(t,o))return;const i=n.cloneNode(!0);!1!==o.beforeNodeAdded?.(i)&&(r?.dispose?.(t),t.parentNode.replaceChild(i,t),o.afterNodeRemoved?.(t),c(i,r))},c=(e,t)=>{const n=t||i(e.parentNode);n?.walk?.(e,n)},u=(t,n,r,i)=>{const s=i.key||o,l=/* @__PURE__ */new Map;for(let e=t.firstChild;e;e=e.nextSibling)if(1===e.nodeType){const t=s(e);if(null==t)continue;l.set(t,e)}const a=e=>e&&1===e.nodeType?s(e):null;let u=t.firstChild,f=n.firstChild;const p=e=>{const n=e.cloneNode(!0);!1!==i.beforeNodeAdded?.(n)&&(t.insertBefore(n,u),c(n,r))};for(;f;){const e=f.nextSibling,n=a(f);if(null!=n){const e=l.get(n);e?(e===u?u=u.nextSibling:t.insertBefore(e,u),l.delete(n),d(e,f,r,i)):p(f)}else if(u&&null==a(u)){const e=u.nextSibling;d(u,f,r,i),u=e}else p(f);f=e}for(;u;){const n=u.nextSibling;e(u,i)||(r?.dispose?.(u),t.removeChild(u),i.afterNodeRemoved?.(u)),u=n}},f=(e,t,n={})=>{let r;if("string"==typeof t){const n=document.createElement("template");n.innerHTML=t.trim();const o=n.content;r=1===o.childElementCount?o.firstElementChild:(()=>{const t=e.cloneNode(!1);return t.appendChild(o),t})()}else r=t;if(r){const t=p();d(e,r,i(e),n),t()}return e},p=()=>{const e=document.activeElement;if(!e||e===document.body)return()=>{};const t=e;let n=null,r=null;try{n=t.selectionStart,r=t.selectionEnd}catch{}return()=>{if(e!==document.activeElement&&e.isConnected&&(e.focus(),null!==n))try{t.setSelectionRange(n,r)}catch{}}},h=e=>{e.scope.$morph=f};export{f as morph,h as morphPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiteVueMorph={})}(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=/^(?:v-|:|@)/,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiteVueMorph={})}(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=(e,t)=>1===e.nodeType&&(e.hasAttribute("data-morph-preserve")||!!t.preserve?.(e)),n=/^(?:v-|:|@)/,o=/^(?::|v-bind:)/,r=["id","data-key","data-id"],i=e=>{for(const t of r){const n=e.getAttribute(t);if(null!=n)return t+"="+n}return null},s=e=>{for(let t=e;t;t=t.parentElement)if(t.__ctx)return t.__ctx},l=e=>e.hasAttribute("v-for")||e.hasAttribute("v-if")||e.hasAttribute("v-else")||e.hasAttribute("v-else-if"),d=(e,t)=>{const r=(e=>{const t=new Set;for(const{name:n}of e.attributes)o.test(n)?t.add(n.replace(o,"").split(".")[0]):"v-model"===n&&(t.add("value"),t.add("checked"));return t})(t);for(const{name:o,value:i}of[...t.attributes])n.test(o)||r.has(o)||e.getAttribute(o)!==i&&e.setAttribute(o,i);for(const{name:n}of[...e.attributes])r.has(n)||t.hasAttribute(n)||e.removeAttribute(n)},a=(e,t,n,o)=>{if(e.nodeType!==t.nodeType)return u(e,t,n,o);if(3===e.nodeType||8===e.nodeType){const o=t.data;if(((e,t)=>e.includes(t?t.delimiters[0]:"{{"))(o,n))return;return void(e.data!==o&&(e.data=o))}if(1!==e.nodeType)return;const r=e,i=t;if(r.tagName!==i.tagName)return u(e,t,n,o);o.skip?.(r,i)||r.hasAttribute("data-morph-skip")||(d(r,i),(e=>{if(e.hasAttribute("v-text")||e.hasAttribute("v-html")||e.hasAttribute("v-pre")||e.hasAttribute("v-once")||l(e))return!0;for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(l(t))return!0;return!1})(i)||f(r,i,r.__ctx||n,o))},u=(e,n,o,r)=>{if(t(e,r))return;const i=n.cloneNode(!0);!1!==r.beforeNodeAdded?.(i)&&(o?.dispose?.(e),e.parentNode.replaceChild(i,e),r.afterNodeRemoved?.(e),c(i,o))},c=(e,t)=>{const n=t||s(e.parentNode);n?.walk?.(e,n)},f=(e,n,o,r)=>{const s=r.key||i,l=new Map;for(let t=e.firstChild;t;t=t.nextSibling)if(1===t.nodeType){const e=s(t);if(null==e)continue;l.set(e,t)}const d=e=>e&&1===e.nodeType?s(e):null;let u=e.firstChild,f=n.firstChild;const p=t=>{const n=t.cloneNode(!0);!1!==r.beforeNodeAdded?.(n)&&(e.insertBefore(n,u),c(n,o))};for(;f;){const t=f.nextSibling,n=d(f);if(null!=n){const t=l.get(n);t?(t===u?u=u.nextSibling:e.insertBefore(t,u),l.delete(n),a(t,f,o,r)):p(f)}else if(u&&null==d(u)){const e=u.nextSibling;a(u,f,o,r),u=e}else p(f);f=t}for(;u;){const n=u.nextSibling;t(u,r)||(o?.dispose?.(u),e.removeChild(u),r.afterNodeRemoved?.(u)),u=n}},p=(e,t,n={})=>{let o;if("string"==typeof t){const n=document.createElement("template");n.innerHTML=t.trim();const r=n.content;o=1===r.childElementCount?r.firstElementChild:(()=>{const t=e.cloneNode(!1);return t.appendChild(r),t})()}else o=t;if(o){const t=h();a(e,o,s(e),n),t()}return e},h=()=>{const e=document.activeElement;if(!e||e===document.body)return()=>{};const t=e;let n=null,o=null;try{n=t.selectionStart,o=t.selectionEnd}catch{}return()=>{if(e!==document.activeElement&&e.isConnected&&(e.focus(),null!==n))try{t.setSelectionRange(n,o)}catch{}}};e.morph=p,e.morphPlugin=e=>{e.scope.$morph=p}});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var LiteVuePersist = (function(exports, _aevantec_litevue) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/plugins/persist/index.ts
|
|
4
|
+
var PREFIX = "litevue:";
|
|
5
|
+
/** Custom storages registered by name, usable as a directive modifier. */
|
|
6
|
+
var registry = Object.create(null);
|
|
7
|
+
var defaultStorage = "local";
|
|
8
|
+
var builtin = (name) => {
|
|
9
|
+
try {
|
|
10
|
+
if (name === "local" || name === "localStorage") return localStorage;
|
|
11
|
+
if (name === "session" || name === "sessionStorage") return sessionStorage;
|
|
12
|
+
} catch {}
|
|
13
|
+
};
|
|
14
|
+
var resolve = (storage) => {
|
|
15
|
+
const target = storage ?? defaultStorage;
|
|
16
|
+
if (typeof target !== "string") return target;
|
|
17
|
+
return registry[target] ?? builtin(target);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Register a custom storage under a name, selectable anywhere — including as a
|
|
21
|
+
* directive modifier. Any object with getItem/setItem works.
|
|
22
|
+
*
|
|
23
|
+
* registerStorage('memory', myMemoryStorage);
|
|
24
|
+
* persistStore('scratch', { storage: 'memory' });
|
|
25
|
+
* <div v-persist.memory="scratch">…</div>
|
|
26
|
+
*/
|
|
27
|
+
var registerStorage = (name, storage) => {
|
|
28
|
+
registry[name] = storage;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Switch the storage used when none is specified. Accepts a registered name
|
|
32
|
+
* ('local', 'session', or your own) or a storage object.
|
|
33
|
+
*
|
|
34
|
+
* setDefaultStorage('session'); // everything defaults to sessionStorage
|
|
35
|
+
*/
|
|
36
|
+
var setDefaultStorage = (storage) => {
|
|
37
|
+
defaultStorage = storage;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Which own properties of `target` can round-trip through storage. Methods are
|
|
41
|
+
* behavior, not state; getter-only properties are derived and would throw on
|
|
42
|
+
* restore. An explicit list is filtered too, so naming a getter is a no-op.
|
|
43
|
+
*/
|
|
44
|
+
var persistable = (target, keys) => (keys ?? Object.keys(target)).filter((k) => {
|
|
45
|
+
if (k[0] === "$") return false;
|
|
46
|
+
const desc = Object.getOwnPropertyDescriptor(target, k);
|
|
47
|
+
if (desc && desc.get && !desc.set) return false;
|
|
48
|
+
const raw = desc && desc.value;
|
|
49
|
+
if (raw && raw.__v_isRef === true && raw.__v_isReadonly === true) return false;
|
|
50
|
+
return typeof target[k] !== "function";
|
|
51
|
+
});
|
|
52
|
+
/** Restore saved values, then keep storage in sync with every change. */
|
|
53
|
+
var sync = (target, key, keys, storage, run) => {
|
|
54
|
+
if (!storage) return run(() => {});
|
|
55
|
+
const fields = persistable(target, keys);
|
|
56
|
+
try {
|
|
57
|
+
const saved = JSON.parse(storage.getItem(key) || "null");
|
|
58
|
+
if (saved) {
|
|
59
|
+
for (const k of fields) if (k in saved) target[k] = saved[k];
|
|
60
|
+
}
|
|
61
|
+
} catch {}
|
|
62
|
+
return run(() => {
|
|
63
|
+
const snapshot = {};
|
|
64
|
+
for (const k of fields) snapshot[k] = target[k];
|
|
65
|
+
try {
|
|
66
|
+
storage.setItem(key, JSON.stringify(snapshot));
|
|
67
|
+
} catch {}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* v-persist="storage-key" — syncs the element's scope to storage: restored on
|
|
72
|
+
* mount, written back on every change, nested values included.
|
|
73
|
+
*
|
|
74
|
+
* The attribute value is the storage key verbatim, not an expression, and
|
|
75
|
+
* falls back to the element id. An argument narrows which properties are
|
|
76
|
+
* stored; a modifier picks the storage (`local` default, `session`, or any
|
|
77
|
+
* name given to registerStorage()).
|
|
78
|
+
*
|
|
79
|
+
* v-persist:draft="composer" — only `draft`
|
|
80
|
+
* v-persist:draft,recipient="composer" — only those two
|
|
81
|
+
* v-persist:draft.session="composer" — and into sessionStorage
|
|
82
|
+
*/
|
|
83
|
+
var persist = (app) => {
|
|
84
|
+
app.directive("persist", ({ ctx, el, exp, arg, modifiers, effect }) => {
|
|
85
|
+
const key = PREFIX + (exp || el.id);
|
|
86
|
+
if (key === PREFIX) console.error(`v-persist needs a key: v-persist="my-key".`);
|
|
87
|
+
let storage;
|
|
88
|
+
for (const name in modifiers || {}) {
|
|
89
|
+
if (resolve(name)) {
|
|
90
|
+
storage = name;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
console.error(`v-persist: unknown storage ".${name}" — use .local, .session, or a name passed to registerStorage().`);
|
|
94
|
+
}
|
|
95
|
+
const keys = arg ? arg.split(",").map((k) => k.trim()).filter(Boolean) : void 0;
|
|
96
|
+
sync(ctx.scope, key, keys, resolve(storage), effect);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* persistStore('cart') — the JS-side counterpart for global stores, which have
|
|
101
|
+
* no element to hang a directive on. Restores immediately, saves on change,
|
|
102
|
+
* and returns a stop function.
|
|
103
|
+
*
|
|
104
|
+
* persistStore('cart') // the whole store
|
|
105
|
+
* persistStore('cart', { keys: ['items'] }) // only these properties
|
|
106
|
+
* persistStore('cart', { key: 'v2:cart' }) // custom storage key
|
|
107
|
+
* persistStore('draft', { storage: 'session' }) // a different storage
|
|
108
|
+
* persistStore('scratch', { storage: myStorage }) // any getItem/setItem
|
|
109
|
+
*/
|
|
110
|
+
var persistStore = (name, options = {}) => {
|
|
111
|
+
const target = (0, _aevantec_litevue.store)(name);
|
|
112
|
+
if (!target) {
|
|
113
|
+
console.error(`persistStore("${name}") — no such store. Register it with store("${name}", { … }) first.`);
|
|
114
|
+
return () => {};
|
|
115
|
+
}
|
|
116
|
+
const storage = resolve(options.storage);
|
|
117
|
+
if (!storage) console.error(`persistStore("${name}") — storage "${String(options.storage)}" is not available.`);
|
|
118
|
+
return sync(target, PREFIX + (options.key ?? name), options.keys, storage, _aevantec_litevue.watchEffect);
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.persist = persist;
|
|
122
|
+
exports.persistStore = persistStore;
|
|
123
|
+
exports.registerStorage = registerStorage;
|
|
124
|
+
exports.setDefaultStorage = setDefaultStorage;
|
|
125
|
+
return exports;
|
|
126
|
+
})({}, LiteVue);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { store, watchEffect } from "@aevantec/litevue";
|
|
2
|
+
//#region src/plugins/persist/index.ts
|
|
3
|
+
var PREFIX = "litevue:";
|
|
4
|
+
/** Custom storages registered by name, usable as a directive modifier. */
|
|
5
|
+
var registry = Object.create(null);
|
|
6
|
+
var defaultStorage = "local";
|
|
7
|
+
var builtin = (name) => {
|
|
8
|
+
try {
|
|
9
|
+
if (name === "local" || name === "localStorage") return localStorage;
|
|
10
|
+
if (name === "session" || name === "sessionStorage") return sessionStorage;
|
|
11
|
+
} catch {}
|
|
12
|
+
};
|
|
13
|
+
var resolve = (storage) => {
|
|
14
|
+
const target = storage ?? defaultStorage;
|
|
15
|
+
if (typeof target !== "string") return target;
|
|
16
|
+
return registry[target] ?? builtin(target);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Register a custom storage under a name, selectable anywhere — including as a
|
|
20
|
+
* directive modifier. Any object with getItem/setItem works.
|
|
21
|
+
*
|
|
22
|
+
* registerStorage('memory', myMemoryStorage);
|
|
23
|
+
* persistStore('scratch', { storage: 'memory' });
|
|
24
|
+
* <div v-persist.memory="scratch">…</div>
|
|
25
|
+
*/
|
|
26
|
+
var registerStorage = (name, storage) => {
|
|
27
|
+
registry[name] = storage;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Switch the storage used when none is specified. Accepts a registered name
|
|
31
|
+
* ('local', 'session', or your own) or a storage object.
|
|
32
|
+
*
|
|
33
|
+
* setDefaultStorage('session'); // everything defaults to sessionStorage
|
|
34
|
+
*/
|
|
35
|
+
var setDefaultStorage = (storage) => {
|
|
36
|
+
defaultStorage = storage;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Which own properties of `target` can round-trip through storage. Methods are
|
|
40
|
+
* behavior, not state; getter-only properties are derived and would throw on
|
|
41
|
+
* restore. An explicit list is filtered too, so naming a getter is a no-op.
|
|
42
|
+
*/
|
|
43
|
+
var persistable = (target, keys) => (keys ?? Object.keys(target)).filter((k) => {
|
|
44
|
+
if (k[0] === "$") return false;
|
|
45
|
+
const desc = Object.getOwnPropertyDescriptor(target, k);
|
|
46
|
+
if (desc && desc.get && !desc.set) return false;
|
|
47
|
+
const raw = desc && desc.value;
|
|
48
|
+
if (raw && raw.__v_isRef === true && raw.__v_isReadonly === true) return false;
|
|
49
|
+
return typeof target[k] !== "function";
|
|
50
|
+
});
|
|
51
|
+
/** Restore saved values, then keep storage in sync with every change. */
|
|
52
|
+
var sync = (target, key, keys, storage, run) => {
|
|
53
|
+
if (!storage) return run(() => {});
|
|
54
|
+
const fields = persistable(target, keys);
|
|
55
|
+
try {
|
|
56
|
+
const saved = JSON.parse(storage.getItem(key) || "null");
|
|
57
|
+
if (saved) {
|
|
58
|
+
for (const k of fields) if (k in saved) target[k] = saved[k];
|
|
59
|
+
}
|
|
60
|
+
} catch {}
|
|
61
|
+
return run(() => {
|
|
62
|
+
const snapshot = {};
|
|
63
|
+
for (const k of fields) snapshot[k] = target[k];
|
|
64
|
+
try {
|
|
65
|
+
storage.setItem(key, JSON.stringify(snapshot));
|
|
66
|
+
} catch {}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* v-persist="storage-key" — syncs the element's scope to storage: restored on
|
|
71
|
+
* mount, written back on every change, nested values included.
|
|
72
|
+
*
|
|
73
|
+
* The attribute value is the storage key verbatim, not an expression, and
|
|
74
|
+
* falls back to the element id. An argument narrows which properties are
|
|
75
|
+
* stored; a modifier picks the storage (`local` default, `session`, or any
|
|
76
|
+
* name given to registerStorage()).
|
|
77
|
+
*
|
|
78
|
+
* v-persist:draft="composer" — only `draft`
|
|
79
|
+
* v-persist:draft,recipient="composer" — only those two
|
|
80
|
+
* v-persist:draft.session="composer" — and into sessionStorage
|
|
81
|
+
*/
|
|
82
|
+
var persist = (app) => {
|
|
83
|
+
app.directive("persist", ({ ctx, el, exp, arg, modifiers, effect }) => {
|
|
84
|
+
const key = PREFIX + (exp || el.id);
|
|
85
|
+
if (key === PREFIX) console.error(`v-persist needs a key: v-persist="my-key".`);
|
|
86
|
+
let storage;
|
|
87
|
+
for (const name in modifiers || {}) {
|
|
88
|
+
if (resolve(name)) {
|
|
89
|
+
storage = name;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
console.error(`v-persist: unknown storage ".${name}" — use .local, .session, or a name passed to registerStorage().`);
|
|
93
|
+
}
|
|
94
|
+
const keys = arg ? arg.split(",").map((k) => k.trim()).filter(Boolean) : void 0;
|
|
95
|
+
sync(ctx.scope, key, keys, resolve(storage), effect);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* persistStore('cart') — the JS-side counterpart for global stores, which have
|
|
100
|
+
* no element to hang a directive on. Restores immediately, saves on change,
|
|
101
|
+
* and returns a stop function.
|
|
102
|
+
*
|
|
103
|
+
* persistStore('cart') // the whole store
|
|
104
|
+
* persistStore('cart', { keys: ['items'] }) // only these properties
|
|
105
|
+
* persistStore('cart', { key: 'v2:cart' }) // custom storage key
|
|
106
|
+
* persistStore('draft', { storage: 'session' }) // a different storage
|
|
107
|
+
* persistStore('scratch', { storage: myStorage }) // any getItem/setItem
|
|
108
|
+
*/
|
|
109
|
+
var persistStore = (name, options = {}) => {
|
|
110
|
+
const target = store(name);
|
|
111
|
+
if (!target) {
|
|
112
|
+
console.error(`persistStore("${name}") — no such store. Register it with store("${name}", { … }) first.`);
|
|
113
|
+
return () => {};
|
|
114
|
+
}
|
|
115
|
+
const storage = resolve(options.storage);
|
|
116
|
+
if (!storage) console.error(`persistStore("${name}") — storage "${String(options.storage)}" is not available.`);
|
|
117
|
+
return sync(target, PREFIX + (options.key ?? name), options.keys, storage, watchEffect);
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { persist, persistStore, registerStorage, setDefaultStorage };
|
package/dist/types/app.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Directive } from './directives/index.mjs';
|
|
2
|
+
import { type ErrorHandler } from './errors.mjs';
|
|
2
3
|
export interface App {
|
|
3
4
|
/**
|
|
4
5
|
* The reactive root scope. Plugins may attach helpers here (conventionally
|
|
@@ -8,12 +9,8 @@ export interface App {
|
|
|
8
9
|
directive(name: string, def?: Directive): any;
|
|
9
10
|
/**
|
|
10
11
|
* Register a component — a function returning a scope object, used from
|
|
11
|
-
* `v-scope="Name()"` — or retrieve one by name.
|
|
12
|
-
*
|
|
13
|
-
* Components have always been plain functions reachable from an expression;
|
|
14
|
-
* this gives them a named home, so a plugin can contribute one without
|
|
15
|
-
* reaching into `app.scope`, and so a name can be looked up rather than
|
|
16
|
-
* guessed at.
|
|
12
|
+
* `v-scope="Name()"` — or retrieve one by name. Gives components a named
|
|
13
|
+
* home, so a plugin can contribute one without reaching into `app.scope`.
|
|
17
14
|
*/
|
|
18
15
|
component(name: string, factory?: ComponentFactory): any;
|
|
19
16
|
/**
|
|
@@ -22,6 +19,12 @@ export interface App {
|
|
|
22
19
|
* plugin twice is a no-op.
|
|
23
20
|
*/
|
|
24
21
|
use<Options>(plugin: Plugin<Options>, options?: Options): App;
|
|
22
|
+
/**
|
|
23
|
+
* Register a handler for every runtime error LiteVue catches. Runs in
|
|
24
|
+
* production too — this is where an app forwards errors to monitoring.
|
|
25
|
+
* Returns an unregister function; a full `unmount()` also releases it.
|
|
26
|
+
*/
|
|
27
|
+
onError(handler: ErrorHandler): () => void;
|
|
25
28
|
mount(el?: string | Element | null): App | void;
|
|
26
29
|
/**
|
|
27
30
|
* Tear down every mounted root, or — given an element or selector — only the
|
|
@@ -30,21 +33,15 @@ export interface App {
|
|
|
30
33
|
unmount(el?: string | Element | null): void;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
|
-
* A plugin may return a teardown function,
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* The shape matches directives, which already return their cleanup. Without
|
|
38
|
-
* it a plugin could acquire page-wide resources — observers, listeners,
|
|
39
|
-
* matchMedia subscriptions — and had no way to give them back: the media
|
|
40
|
-
* plugin held five MediaQueryList subscriptions for the life of the page
|
|
41
|
-
* whether or not any app was still running.
|
|
36
|
+
* A plugin may return a teardown function, run on full unmount; returning
|
|
37
|
+
* nothing stays valid. Mirrors directives, which already return their cleanup.
|
|
38
|
+
* Without it, page-wide resources — observers, listeners, matchMedia — could
|
|
39
|
+
* never be given back.
|
|
42
40
|
*/
|
|
43
41
|
export type PluginTeardown = () => void;
|
|
44
42
|
/**
|
|
45
|
-
* A component factory. Called from an expression —
|
|
46
|
-
*
|
|
47
|
-
* expression passes.
|
|
43
|
+
* A component factory. Called from an expression —
|
|
44
|
+
* `v-scope="Counter({ n: 1 })"` — returning that region's scope object.
|
|
48
45
|
*/
|
|
49
46
|
export type ComponentFactory = (...props: any[]) => Record<string, any>;
|
|
50
47
|
export type Plugin<Options = any> = ((app: App, options?: Options) => PluginTeardown | void) | {
|
package/dist/types/app.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Directive } from './directives';
|
|
2
|
+
import { type ErrorHandler } from './errors';
|
|
2
3
|
export interface App {
|
|
3
4
|
/**
|
|
4
5
|
* The reactive root scope. Plugins may attach helpers here (conventionally
|
|
@@ -8,12 +9,8 @@ export interface App {
|
|
|
8
9
|
directive(name: string, def?: Directive): any;
|
|
9
10
|
/**
|
|
10
11
|
* Register a component — a function returning a scope object, used from
|
|
11
|
-
* `v-scope="Name()"` — or retrieve one by name.
|
|
12
|
-
*
|
|
13
|
-
* Components have always been plain functions reachable from an expression;
|
|
14
|
-
* this gives them a named home, so a plugin can contribute one without
|
|
15
|
-
* reaching into `app.scope`, and so a name can be looked up rather than
|
|
16
|
-
* guessed at.
|
|
12
|
+
* `v-scope="Name()"` — or retrieve one by name. Gives components a named
|
|
13
|
+
* home, so a plugin can contribute one without reaching into `app.scope`.
|
|
17
14
|
*/
|
|
18
15
|
component(name: string, factory?: ComponentFactory): any;
|
|
19
16
|
/**
|
|
@@ -22,6 +19,12 @@ export interface App {
|
|
|
22
19
|
* plugin twice is a no-op.
|
|
23
20
|
*/
|
|
24
21
|
use<Options>(plugin: Plugin<Options>, options?: Options): App;
|
|
22
|
+
/**
|
|
23
|
+
* Register a handler for every runtime error LiteVue catches. Runs in
|
|
24
|
+
* production too — this is where an app forwards errors to monitoring.
|
|
25
|
+
* Returns an unregister function; a full `unmount()` also releases it.
|
|
26
|
+
*/
|
|
27
|
+
onError(handler: ErrorHandler): () => void;
|
|
25
28
|
mount(el?: string | Element | null): App | void;
|
|
26
29
|
/**
|
|
27
30
|
* Tear down every mounted root, or — given an element or selector — only the
|
|
@@ -30,21 +33,15 @@ export interface App {
|
|
|
30
33
|
unmount(el?: string | Element | null): void;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
|
-
* A plugin may return a teardown function,
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* The shape matches directives, which already return their cleanup. Without
|
|
38
|
-
* it a plugin could acquire page-wide resources — observers, listeners,
|
|
39
|
-
* matchMedia subscriptions — and had no way to give them back: the media
|
|
40
|
-
* plugin held five MediaQueryList subscriptions for the life of the page
|
|
41
|
-
* whether or not any app was still running.
|
|
36
|
+
* A plugin may return a teardown function, run on full unmount; returning
|
|
37
|
+
* nothing stays valid. Mirrors directives, which already return their cleanup.
|
|
38
|
+
* Without it, page-wide resources — observers, listeners, matchMedia — could
|
|
39
|
+
* never be given back.
|
|
42
40
|
*/
|
|
43
41
|
export type PluginTeardown = () => void;
|
|
44
42
|
/**
|
|
45
|
-
* A component factory. Called from an expression —
|
|
46
|
-
*
|
|
47
|
-
* expression passes.
|
|
43
|
+
* A component factory. Called from an expression —
|
|
44
|
+
* `v-scope="Counter({ n: 1 })"` — returning that region's scope object.
|
|
48
45
|
*/
|
|
49
46
|
export type ComponentFactory = (...props: any[]) => Record<string, any>;
|
|
50
47
|
export type Plugin<Options = any> = ((app: App, options?: Options) => PluginTeardown | void) | {
|