All checks were successful
Build-und-Deploy / build (push) Successful in 11s
minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test minor change for pipeline test Add Gitea Actions build workflow Add CI/CD pipeline Test Build & Deploy add pipeline add pipeline2 add pipeline3 add pipeline4 add pipeline 5 add pipeline 6 add pipeline 7 add pipeline 8 add pipeline 9 add pipeline 10 add pipeline 11 add pipeline 12 add pipeline 13 add pipeline 14 add pipeline 15 add pipeline 16 add pipeline 17 add pipeline 18 add pipeline 19 add pipeline 20 add pipeline 21 add pipeline 22 add pipeline 23 add pipeline 24 1 2 3
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
import { noChange } from 'lit';
|
|
import { directive, PartType } from 'lit/directive.js';
|
|
import { AsyncDirective } from 'lit/async-directive.js';
|
|
|
|
class FlowComponentDirective extends AsyncDirective {
|
|
constructor(partInfo) {
|
|
super(partInfo);
|
|
if (partInfo.type !== PartType.CHILD) {
|
|
throw new Error(`${this.constructor.directiveName}() can only be used in child bindings`);
|
|
}
|
|
}
|
|
|
|
update(part, [appid, nodeid]) {
|
|
this.updateContent(part, appid, nodeid);
|
|
return noChange;
|
|
}
|
|
|
|
updateContent(part, appid, nodeid) {
|
|
const { parentNode, startNode } = part;
|
|
this.__parentNode = parentNode;
|
|
|
|
const hasNewNodeId = nodeid !== undefined && nodeid !== null;
|
|
const newNode = hasNewNodeId ? this.getNewNode(appid, nodeid) : null;
|
|
const oldNode = this.getOldNode(part);
|
|
|
|
clearTimeout(this.__parentNode.__nodeRetryTimeout);
|
|
|
|
if (hasNewNodeId && !newNode) {
|
|
// If the node is not found, try again later.
|
|
this.__parentNode.__nodeRetryTimeout = setTimeout(() => this.updateContent(part, appid, nodeid));
|
|
} else if (oldNode === newNode) {
|
|
return;
|
|
} else if (oldNode && newNode) {
|
|
parentNode.replaceChild(newNode, oldNode);
|
|
} else if (oldNode) {
|
|
parentNode.removeChild(oldNode);
|
|
} else if (newNode) {
|
|
startNode.after(newNode);
|
|
}
|
|
}
|
|
|
|
getNewNode(appid, nodeid) {
|
|
return window.Vaadin.Flow.clients[appid].getByNodeId(nodeid);
|
|
}
|
|
|
|
getOldNode(part) {
|
|
const { startNode, endNode } = part;
|
|
if (startNode.nextSibling === endNode) {
|
|
return;
|
|
}
|
|
return startNode.nextSibling;
|
|
}
|
|
|
|
disconnected() {
|
|
clearTimeout(this.__parentNode.__nodeRetryTimeout);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Renders the given flow component node.
|
|
*
|
|
* WARNING: This directive is not intended for public use.
|
|
*
|
|
* @param {string} appid
|
|
* @param {number} nodeid
|
|
* @private
|
|
*/
|
|
export const flowComponentDirective = directive(FlowComponentDirective);
|