@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
205 lines (199 loc) • 9.12 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-C4h1muVj.js';
import { i as isArray } from './isArray-C_HhfJYh.js';
import { i as isObject } from './isObject-C7eoH3L1.js';
import { i as isNumber } from './isNumber-hN3DcWii.js';
import { d as baseClone } from './_baseClone-DRQcJxio.js';
import { D as DoorState } from './sliding-door-interface-B-CH3G6g.js';
import './isObjectLike-CIR68wtF.js';
import './global-C56buD75.js';
import './_getAllKeys-C08dM1uK.js';
import './_isIndex-DgTx77bC.js';
import './isLength-BBM_tGdM.js';
import './_getTag-CFse-dEC.js';
import './_baseAssignValue-DAaC80vH.js';
import './_defineProperty-CWEcucM9.js';
/** Used to compose bitmasks for cloning. */
var CLONE_SYMBOLS_FLAG = 4;
/**
* Creates a shallow clone of `value`.
*
* **Note:** This method is loosely based on the
* [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
* and supports cloning arrays, array buffers, booleans, date objects, maps,
* numbers, `Object` objects, regexes, sets, strings, symbols, and typed
* arrays. The own enumerable properties of `arguments` objects are cloned
* as plain objects. An empty object is returned for uncloneable values such
* as error objects, functions, DOM nodes, and WeakMaps.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to clone.
* @returns {*} Returns the cloned value.
* @see _.cloneDeep
* @example
*
* var objects = [{ 'a': 1 }, { 'b': 2 }];
*
* var shallow = _.clone(objects);
* console.log(shallow[0] === objects[0]);
* // => true
*/
function clone(value) {
return baseClone(value, CLONE_SYMBOLS_FLAG);
}
const slidingDoorCss = "slot-fb[hidden],slot[hidden]{display:initial !important}lar-button-group{display:-ms-flexbox;display:flex;gap:0.5rem;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:100%;max-width:400px;margin:2rem auto;padding:0.4rem;background:rgba(0, 0, 0, 0.03);border-radius:0.8rem;-webkit-box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.5);box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.5)}lar-button-group lar-button{-ms-flex:1;flex:1;min-height:3.5rem;font-weight:600;font-size:0.95rem;text-transform:uppercase;letter-spacing:0.05em;border-radius:0.5rem;-webkit-transition:all 0.3s cubic-bezier(0.4, 0, 0.2, 1);transition:all 0.3s cubic-bezier(0.4, 0, 0.2, 1);-webkit-box-shadow:0 2px 8px -2px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.1);box-shadow:0 2px 8px -2px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.1)}lar-button-group lar-button:active{-webkit-transform:scale(0.97);transform:scale(0.97)}";
const SlidingDoorNode = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.output = createEvent(this, "output");
this.request = createEvent(this, "request");
/////// LarvaNode base properties
/**
* Component main icon
*/
this.icon = 'off';
/**
* The color to use from your application's color palette.
* Detrouble options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
*/
this.color = 'primary';
/**
* Disable quck actions
*/
this.disableQuickActions = false;
/**
* Allow node indication color automatic change based on feedback/node value. Defaults to false
*/
this.allowIndicationAutoColoring = false;
/**
* Is logging for this component enabled (lar-log subcomponent loaded)
*/
this.log = true;
/**
* Node size
*/
this.nodeSize = 'default';
/////// LarvaNode base properties and events - end
this.loading = true;
this.fullState = {
doorState: undefined,
doorStateString: DoorState.UNKNOWN,
slidingTimerRunning: false,
slidingTimerElapsed: 0,
slidingTimerTimeout: 0,
slidingTimerStartedAt: 0,
stopEnabled: false
};
}
componentDidLoad() {
const el = this.el.shadowRoot || this.el;
this.node = el.querySelector('lar-node');
this.output.emit({ command: 'get' });
}
/**
* Larva error input
*/
async error(data) {
if (this.node) {
this.node.error(data);
}
this.loading = false;
}
/**
* Input Larva event message (see above)
*/
async input(data) {
if (isArray(data)) ;
else if (isObject(data)) {
const lastState = clone(this.fullState);
this.fullState = data;
if (this.fullState.slidingTimerRunning && isNumber(this.fullState.slidingTimerElapsed) && isNumber(this.fullState.slidingTimerTimeout)) {
if (!this.timer || lastState.slidingTimerStartedAt !== this.fullState.slidingTimerStartedAt) {
// restart the timer if slidingTimerStartedAt has changed
this.startTimer();
}
}
if (!this.fullState.slidingTimerRunning && this.timer) {
this.resetTimer();
}
}
this.loading = false;
}
resetTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
startTimer() {
this.timerValue = this.fullState.slidingTimerElapsed;
const intervalTime = 1000;
this.resetTimer();
this.timer = setInterval(() => {
try {
if (!this.fullState.slidingTimerRunning || this.timerValue > this.fullState.slidingTimerTimeout) {
this.resetTimer();
// timer should have been stopped by now
// make read request to get the state
this.output.emit({ command: 'get' });
this.loading = true;
}
this.timerValue += intervalTime;
}
catch (err) {
console.error(err);
}
}, intervalTime);
}
sendCommand(cmd) {
this.output.emit({ command: cmd });
this.loading = true;
}
render() {
let value = this.loading ? '' : 'slidingDoor.stateUnknown';
let iconSmall = '';
let colorIconSmall = this.colorIconSmall;
switch (this.fullState.doorStateString) {
case DoorState.CLOSED: {
value = 'slidingDoor.stateClosed';
iconSmall = 'lock';
colorIconSmall = this.allowIndicationAutoColoring ? 'success' : this.colorIconSmall;
break;
}
case DoorState.OPEN: {
value = 'slidingDoor.stateOpen';
iconSmall = 'unlock';
colorIconSmall = this.allowIndicationAutoColoring ? 'danger' : this.colorIconSmall;
break;
}
case DoorState.OPENING: {
iconSmall = 'moving-cogs';
value = 'slidingDoor.stateOpening';
break;
}
case DoorState.CLOSING: {
iconSmall = 'moving-cogs';
value = 'slidingDoor.stateClosing';
break;
}
}
const componentProps = {
doorState: this.fullState.doorStateString,
stopEnabled: Boolean(this.fullState.stopEnabled),
color: this.colorInputs || this.color,
loading: this.loading,
onSendcommand: (ev) => this.sendCommand(ev.detail),
};
return (h("lar-node", { key: '390a6cfd0d7a6325c6b58d536c3837361ead69d6', value: value, hideTitles: this.hideTitles, icon: this.icon, iconSmall: iconSmall, color: this.color, supTitle: this.supTitle, mainTitle: this.mainTitle, subTitle: this.subTitle, colorModal: this.colorModal, colorInputs: this.colorInputs, colorIconSmall: colorIconSmall, loading: this.loading, log: this.log, nodeSize: this.nodeSize, component: "sliding-door-content", componentProps: componentProps }, this.disableQuickActions === false &&
h("lar-button-push", { key: '9c30b34b67b21e064356b40937db5cb293cf7151', size: "small", slot: "titles", color: this.colorInputs || this.color, disabled: this.loading || this.fullState.slidingTimerRunning || !this.fullState.doorStateString || this.fullState.doorStateString === DoorState.UNKNOWN || this.fullState.doorStateString === DoorState.OPENING || this.fullState.doorStateString === DoorState.CLOSING, onClick: ev => this.fullState.doorStateString === DoorState.CLOSED ? this.sendCommand('open') : this.sendCommand('close') }), h("slot", { key: '7d45b188ba352f169058e0c0af03204badb1b11a' })));
}
get el() { return getElement(this); }
};
SlidingDoorNode.style = slidingDoorCss;
export { SlidingDoorNode as lar_sliding_door };
//# sourceMappingURL=lar-sliding-door.entry.js.map