@lvce-editor/virtual-dom 0.5.1 → 0.7.0
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/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ export const renderInto: (
|
|
|
8
8
|
|
|
9
9
|
export const setIpc: (ipc: any) => void
|
|
10
10
|
|
|
11
|
-
export const setComponentUid: ($Element: HTMLElement) => void
|
|
11
|
+
export const setComponentUid: ($Element: HTMLElement, uid: number) => void
|
|
12
|
+
|
|
13
|
+
export const getComponentUid: ($Element: HTMLElement) => void
|
|
14
|
+
|
|
15
|
+
export const getComponentUidFromEvent: (event: Event) => void
|
|
12
16
|
|
|
13
17
|
export const rememberFocus: (
|
|
14
18
|
$Viewlet: HTMLElement,
|
package/dist/index.js
CHANGED
|
@@ -12,13 +12,13 @@ var getUidTarget = ($Element) => {
|
|
|
12
12
|
}
|
|
13
13
|
return void 0;
|
|
14
14
|
};
|
|
15
|
-
var
|
|
15
|
+
var getComponentUid = ($Element) => {
|
|
16
16
|
const $Target = getUidTarget($Element);
|
|
17
17
|
return $Target[uidSymbol];
|
|
18
18
|
};
|
|
19
|
-
var
|
|
19
|
+
var getComponentUidFromEvent = (event) => {
|
|
20
20
|
const { target, currentTarget } = event;
|
|
21
|
-
return
|
|
21
|
+
return getComponentUid(currentTarget || target);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
// src/parts/IpcState/IpcState.ts
|
|
@@ -281,7 +281,7 @@ var getWrappedListener = (listener, returnValue) => {
|
|
|
281
281
|
}
|
|
282
282
|
if (!cache.has(listener)) {
|
|
283
283
|
const wrapped = (event) => {
|
|
284
|
-
const uid =
|
|
284
|
+
const uid = getComponentUidFromEvent(event);
|
|
285
285
|
const result = listener(event);
|
|
286
286
|
if (result.length === 0) {
|
|
287
287
|
return;
|
|
@@ -438,7 +438,50 @@ var render2 = (elements, eventMap = {}) => {
|
|
|
438
438
|
renderInternal2($Root, elements, eventMap);
|
|
439
439
|
return $Root;
|
|
440
440
|
};
|
|
441
|
+
|
|
442
|
+
// src/parts/RememberFocus/RememberFocus.ts
|
|
443
|
+
var queryInputs = ($Viewlet) => {
|
|
444
|
+
return [...$Viewlet.querySelectorAll("input, textarea")];
|
|
445
|
+
};
|
|
446
|
+
var rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
|
|
447
|
+
const oldLeft = $Viewlet.style.left;
|
|
448
|
+
const oldTop = $Viewlet.style.top;
|
|
449
|
+
const oldWidth = $Viewlet.style.width;
|
|
450
|
+
const oldHeight = $Viewlet.style.height;
|
|
451
|
+
const focused = document.activeElement.getAttribute("name");
|
|
452
|
+
const $$Inputs = queryInputs($Viewlet);
|
|
453
|
+
const inputMap = /* @__PURE__ */ Object.create(null);
|
|
454
|
+
for (const $Input of $$Inputs) {
|
|
455
|
+
inputMap[$Input.name] = $Input.value;
|
|
456
|
+
}
|
|
457
|
+
if (uid) {
|
|
458
|
+
const $New = render2(dom, eventMap).firstChild;
|
|
459
|
+
setComponentUid($New, uid);
|
|
460
|
+
$Viewlet.replaceWith($New);
|
|
461
|
+
$Viewlet = $New;
|
|
462
|
+
} else {
|
|
463
|
+
renderInto($Viewlet, dom, eventMap);
|
|
464
|
+
}
|
|
465
|
+
const $$NewInputs = queryInputs($Viewlet);
|
|
466
|
+
for (const $Input of $$NewInputs) {
|
|
467
|
+
$Input.value = inputMap[$Input.name] || $Input.value || "";
|
|
468
|
+
}
|
|
469
|
+
if (focused) {
|
|
470
|
+
const $Focused = $Viewlet.querySelector(`[name="${focused}"]`);
|
|
471
|
+
if ($Focused) {
|
|
472
|
+
$Focused.focus();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
$Viewlet.style.top = oldTop;
|
|
476
|
+
$Viewlet.style.left = oldLeft;
|
|
477
|
+
$Viewlet.style.height = oldHeight;
|
|
478
|
+
$Viewlet.style.width = oldWidth;
|
|
479
|
+
return $Viewlet;
|
|
480
|
+
};
|
|
441
481
|
export {
|
|
482
|
+
getComponentUid,
|
|
483
|
+
getComponentUidFromEvent,
|
|
484
|
+
rememberFocus,
|
|
442
485
|
render2 as render,
|
|
443
486
|
renderInto,
|
|
444
487
|
setComponentUid,
|
package/package.json
CHANGED
|
@@ -14,12 +14,12 @@ const getUidTarget = ($Element) => {
|
|
|
14
14
|
return undefined
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const getComponentUid = ($Element) => {
|
|
18
18
|
const $Target = getUidTarget($Element)
|
|
19
19
|
return $Target[uidSymbol]
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const
|
|
22
|
+
export const getComponentUidFromEvent = (event) => {
|
|
23
23
|
const { target, currentTarget } = event
|
|
24
|
-
return
|
|
24
|
+
return getComponentUid(currentTarget || target)
|
|
25
25
|
}
|
|
@@ -10,7 +10,7 @@ export const getWrappedListener = (listener, returnValue) => {
|
|
|
10
10
|
}
|
|
11
11
|
if (!cache.has(listener)) {
|
|
12
12
|
const wrapped = (event) => {
|
|
13
|
-
const uid = ComponentUid.
|
|
13
|
+
const uid = ComponentUid.getComponentUidFromEvent(event)
|
|
14
14
|
const result = listener(event)
|
|
15
15
|
// TODO check for empty array by value
|
|
16
16
|
if (result.length === 0) {
|
package/src/parts/Main/Main.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
getComponentUid,
|
|
3
|
+
getComponentUidFromEvent,
|
|
4
|
+
setComponentUid,
|
|
5
|
+
} from '../ComponentUid/ComponentUid.ts'
|
|
2
6
|
export { setIpc } from '../IpcState/IpcState.ts'
|
|
7
|
+
export { rememberFocus } from '../RememberFocus/RememberFocus.ts'
|
|
3
8
|
export { render, renderInto } from '../VirtualDom/VirtualDom.ts'
|