UNPKG

node-red-contrib-conta-azul-api

Version:
1,649 lines (1,568 loc) 433 kB
<script type='text/javascript'> "use strict" { const sir_render = function (node, options) { try { if (typeof node !== 'object') { return } let minWidth = '400px' if (options) { if (options.minWidth) minWidth = options.minWidth } if (!node.__clone) { node.__clone = window.$.extend(true, {}, node) } new Conta_azul({ target: document.getElementById('conta-azul-svelte-container'), props: { node: node.__clone } }) document.getElementById('conta-azul-svelte-container').style.width = minWidth const nodeIsSidebarTab = !!node.onchange if (!nodeIsSidebarTab) { const orgResize = node._def.oneditresize node._def.oneditresize = function (size) { document.getElementById('conta-azul-svelte-container').style.width = 'auto' if (orgResize) orgResize(size) node._def.oneditresize = orgResize } } } catch (e) { console.log(e) } } const sir_update = function (node) { if (node.__clone) { const clone = node.__clone delete node.__clone clone._version = "3.0.9" const defaultKeys = Object.keys(node._def.defaults) for (const key of Object.keys(clone)) { if (defaultKeys.indexOf(key) === -1) { delete clone[key] } } // update config node sidebar let updateConfigSidebar = false for (const key of defaultKeys) { if (node._def.defaults[key].type && node[key] !== clone[key]) { updateConfigSidebar = true // config has changed, add to or remove from config node and refresh sidebar // The official RED.nodes.updateConfigNodeUsers(configNode) seems to have no effect. const oldConfig = RED.nodes.node(node[key]) const newConfig = RED.nodes.node(clone[key]) // Remove from old config node if (oldConfig) { oldConfig.users = oldConfig.users.filter(userNode => userNode.id !== node.id) } // add to new config node if (newConfig && !newConfig.users?.find(userNode => userNode.id === node.id)) { newConfig.users.push(RED.nodes.node(node.id)) } } } if (updateConfigSidebar) { RED.sidebar.config.refresh() } Object.assign(node, clone) } } const sir_revert = function (node) { delete node.__clone } const sir_addCurrentNodeVersion = function (node) { node._version = '3.0.9' } function noop() { } const identity = x => x; function assign(tar, src) { // @ts-ignore for (const k in src) tar[k] = src[k]; return tar; } function run(fn) { return fn(); } function blank_object() { return Object.create(null); } function run_all(fns) { fns.forEach(run); } function is_function(thing) { return typeof thing === 'function'; } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } let src_url_equal_anchor; function src_url_equal(element_src, url) { if (!src_url_equal_anchor) { src_url_equal_anchor = document.createElement('a'); } src_url_equal_anchor.href = url; return element_src === src_url_equal_anchor.href; } function is_empty(obj) { return Object.keys(obj).length === 0; } function subscribe(store, ...callbacks) { if (store == null) { return noop; } const unsub = store.subscribe(...callbacks); return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub; } function component_subscribe(component, store, callback) { component.$$.on_destroy.push(subscribe(store, callback)); } function create_slot(definition, ctx, $$scope, fn) { if (definition) { const slot_ctx = get_slot_context(definition, ctx, $$scope, fn); return definition[0](slot_ctx); } } function get_slot_context(definition, ctx, $$scope, fn) { return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx; } function get_slot_changes(definition, $$scope, dirty, fn) { if (definition[2] && fn) { const lets = definition[2](fn(dirty)); if ($$scope.dirty === undefined) { return lets; } if (typeof lets === 'object') { const merged = []; const len = Math.max($$scope.dirty.length, lets.length); for (let i = 0; i < len; i += 1) { merged[i] = $$scope.dirty[i] | lets[i]; } return merged; } return $$scope.dirty | lets; } return $$scope.dirty; } function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) { if (slot_changes) { const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); slot.p(slot_context, slot_changes); } } function get_all_dirty_from_scope($$scope) { if ($$scope.ctx.length > 32) { const dirty = []; const length = $$scope.ctx.length / 32; for (let i = 0; i < length; i++) { dirty[i] = -1; } return dirty; } return -1; } function compute_slots(slots) { const result = {}; for (const key in slots) { result[key] = true; } return result; } function null_to_empty(value) { return value == null ? '' : value; } const is_client = typeof window !== 'undefined'; let now = is_client ? () => window.performance.now() : () => Date.now(); let raf = is_client ? cb => requestAnimationFrame(cb) : noop; const tasks = new Set(); function run_tasks(now) { tasks.forEach(task => { if (!task.c(now)) { tasks.delete(task); task.f(); } }); if (tasks.size !== 0) raf(run_tasks); } /** * Creates a new task that runs on each raf frame * until it returns a falsy value or is aborted */ function loop(callback) { let task; if (tasks.size === 0) raf(run_tasks); return { promise: new Promise(fulfill => { tasks.add(task = { c: callback, f: fulfill }); }), abort() { tasks.delete(task); } }; } function append(target, node) { target.appendChild(node); } function append_styles(target, style_sheet_id, styles) { const append_styles_to = get_root_for_style(target); if (!append_styles_to.getElementById(style_sheet_id)) { const style = element('style'); style.id = style_sheet_id; style.textContent = styles; append_stylesheet(append_styles_to, style); } } function get_root_for_style(node) { if (!node) return document; const root = node.getRootNode ? node.getRootNode() : node.ownerDocument; if (root && root.host) { return root; } return node.ownerDocument; } function append_empty_stylesheet(node) { const style_element = element('style'); append_stylesheet(get_root_for_style(node), style_element); return style_element.sheet; } function append_stylesheet(node, style) { append(node.head || node, style); return style.sheet; } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { if (node.parentNode) { node.parentNode.removeChild(node); } } function destroy_each(iterations, detaching) { for (let i = 0; i < iterations.length; i += 1) { if (iterations[i]) iterations[i].d(detaching); } } function element(name) { return document.createElement(name); } function svg_element(name) { return document.createElementNS('http://www.w3.org/2000/svg', name); } function text(data) { return document.createTextNode(data); } function space() { return text(' '); } function empty() { return text(''); } function listen(node, event, handler, options) { node.addEventListener(event, handler, options); return () => node.removeEventListener(event, handler, options); } function prevent_default(fn) { return function (event) { event.preventDefault(); // @ts-ignore return fn.call(this, event); }; } function stop_propagation(fn) { return function (event) { event.stopPropagation(); // @ts-ignore return fn.call(this, event); }; } function attr(node, attribute, value) { if (value == null) node.removeAttribute(attribute); else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); } function to_number(value) { return value === '' ? null : +value; } function children(element) { return Array.from(element.childNodes); } function set_data(text, data) { data = '' + data; if (text.data === data) return; text.data = data; } function set_input_value(input, value) { input.value = value == null ? '' : value; } function set_style(node, key, value, important) { if (value === null) { node.style.removeProperty(key); } else { node.style.setProperty(key, value, important ? 'important' : ''); } } function select_option(select, value, mounting) { for (let i = 0; i < select.options.length; i += 1) { const option = select.options[i]; if (option.__value === value) { option.selected = true; return; } } if (!mounting || value !== undefined) { select.selectedIndex = -1; // no option should be selected } } function select_value(select) { const selected_option = select.querySelector(':checked'); return selected_option && selected_option.__value; } function toggle_class(element, name, toggle) { element.classList[toggle ? 'add' : 'remove'](name); } function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) { const e = document.createEvent('CustomEvent'); e.initCustomEvent(type, bubbles, cancelable, detail); return e; } class HtmlTag { constructor(is_svg = false) { this.is_svg = false; this.is_svg = is_svg; this.e = this.n = null; } c(html) { this.h(html); } m(html, target, anchor = null) { if (!this.e) { if (this.is_svg) this.e = svg_element(target.nodeName); /** #7364 target for <template> may be provided as #document-fragment(11) */ else this.e = element((target.nodeType === 11 ? 'TEMPLATE' : target.nodeName)); this.t = target.tagName !== 'TEMPLATE' ? target : target.content; this.c(html); } this.i(anchor); } h(html) { this.e.innerHTML = html; this.n = Array.from(this.e.nodeName === 'TEMPLATE' ? this.e.content.childNodes : this.e.childNodes); } i(anchor) { for (let i = 0; i < this.n.length; i += 1) { insert(this.t, this.n[i], anchor); } } p(html) { this.d(); this.h(html); this.i(this.a); } d() { this.n.forEach(detach); } } // we need to store the information for multiple documents because a Svelte application could also contain iframes // https://github.com/sveltejs/svelte/issues/3624 const managed_styles = new Map(); let active = 0; // https://github.com/darkskyapp/string-hash/blob/master/index.js function hash(str) { let hash = 5381; let i = str.length; while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); return hash >>> 0; } function create_style_information(doc, node) { const info = { stylesheet: append_empty_stylesheet(node), rules: {} }; managed_styles.set(doc, info); return info; } function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) { const step = 16.666 / duration; let keyframes = '{\n'; for (let p = 0; p <= 1; p += step) { const t = a + (b - a) * ease(p); keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`; } const rule = keyframes + `100% {${fn(b, 1 - b)}}\n}`; const name = `__svelte_${hash(rule)}_${uid}`; const doc = get_root_for_style(node); const { stylesheet, rules } = managed_styles.get(doc) || create_style_information(doc, node); if (!rules[name]) { rules[name] = true; stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length); } const animation = node.style.animation || ''; node.style.animation = `${animation ? `${animation}, ` : ''}${name} ${duration}ms linear ${delay}ms 1 both`; active += 1; return name; } function delete_rule(node, name) { const previous = (node.style.animation || '').split(', '); const next = previous.filter(name ? anim => anim.indexOf(name) < 0 // remove specific animation : anim => anim.indexOf('__svelte') === -1 // remove all Svelte animations ); const deleted = previous.length - next.length; if (deleted) { node.style.animation = next.join(', '); active -= deleted; if (!active) clear_rules(); } } function clear_rules() { raf(() => { if (active) return; managed_styles.forEach(info => { const { ownerNode } = info.stylesheet; // there is no ownerNode if it runs on jsdom. if (ownerNode) detach(ownerNode); }); managed_styles.clear(); }); } function create_animation(node, from, fn, params) { if (!from) return noop; const to = node.getBoundingClientRect(); if (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) return noop; const { delay = 0, duration = 300, easing = identity, // @ts-ignore todo: should this be separated from destructuring? Or start/end added to public api and documentation? start: start_time = now() + delay, // @ts-ignore todo: end = start_time + duration, tick = noop, css } = fn(node, { from, to }, params); let running = true; let started = false; let name; function start() { if (css) { name = create_rule(node, 0, 1, duration, delay, easing, css); } if (!delay) { started = true; } } function stop() { if (css) delete_rule(node, name); running = false; } loop(now => { if (!started && now >= start_time) { started = true; } if (started && now >= end) { tick(1, 0); stop(); } if (!running) { return false; } if (started) { const p = now - start_time; const t = 0 + 1 * easing(p / duration); tick(t, 1 - t); } return true; }); start(); tick(0, 1); return stop; } function fix_position(node) { const style = getComputedStyle(node); if (style.position !== 'absolute' && style.position !== 'fixed') { const { width, height } = style; const a = node.getBoundingClientRect(); node.style.position = 'absolute'; node.style.width = width; node.style.height = height; add_transform(node, a); } } function add_transform(node, a) { const b = node.getBoundingClientRect(); if (a.left !== b.left || a.top !== b.top) { const style = getComputedStyle(node); const transform = style.transform === 'none' ? '' : style.transform; node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`; } } let current_component; function set_current_component(component) { current_component = component; } function get_current_component() { if (!current_component) throw new Error('Function called outside component initialization'); return current_component; } /** * The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM. * It must be called during the component's initialisation (but doesn't need to live *inside* the component; * it can be called from an external module). * * `onMount` does not run inside a [server-side component](/docs#run-time-server-side-component-api). * * https://svelte.dev/docs#run-time-svelte-onmount */ function onMount(fn) { get_current_component().$$.on_mount.push(fn); } /** * Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname). * Event dispatchers are functions that can take two arguments: `name` and `detail`. * * Component events created with `createEventDispatcher` create a * [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent). * These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture). * The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) * property and can contain any type of data. * * https://svelte.dev/docs#run-time-svelte-createeventdispatcher */ function createEventDispatcher() { const component = get_current_component(); return (type, detail, { cancelable = false } = {}) => { const callbacks = component.$$.callbacks[type]; if (callbacks) { // TODO are there situations where events could be dispatched // in a server (non-DOM) environment? const event = custom_event(type, detail, { cancelable }); callbacks.slice().forEach(fn => { fn.call(component, event); }); return !event.defaultPrevented; } return true; }; } // TODO figure out if we still want to support // shorthand events, or if we want to implement // a real bubbling mechanism function bubble(component, event) { const callbacks = component.$$.callbacks[event.type]; if (callbacks) { // @ts-ignore callbacks.slice().forEach(fn => fn.call(this, event)); } } const dirty_components = []; const binding_callbacks = []; let render_callbacks = []; const flush_callbacks = []; const resolved_promise = /* @__PURE__ */ Promise.resolve(); let update_scheduled = false; function schedule_update() { if (!update_scheduled) { update_scheduled = true; resolved_promise.then(flush); } } function tick() { schedule_update(); return resolved_promise; } function add_render_callback(fn) { render_callbacks.push(fn); } function add_flush_callback(fn) { flush_callbacks.push(fn); } // flush() calls callbacks in this order: // 1. All beforeUpdate callbacks, in order: parents before children // 2. All bind:this callbacks, in reverse order: children before parents. // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT // for afterUpdates called during the initial onMount, which are called in // reverse order: children before parents. // Since callbacks might update component values, which could trigger another // call to flush(), the following steps guard against this: // 1. During beforeUpdate, any updated components will be added to the // dirty_components array and will cause a reentrant call to flush(). Because // the flush index is kept outside the function, the reentrant call will pick // up where the earlier call left off and go through all dirty components. The // current_component value is saved and restored so that the reentrant call will // not interfere with the "parent" flush() call. // 2. bind:this callbacks cannot trigger new flush() calls. // 3. During afterUpdate, any updated components will NOT have their afterUpdate // callback called a second time; the seen_callbacks set, outside the flush() // function, guarantees this behavior. const seen_callbacks = new Set(); let flushidx = 0; // Do *not* move this inside the flush() function function flush() { // Do not reenter flush while dirty components are updated, as this can // result in an infinite loop. Instead, let the inner flush handle it. // Reentrancy is ok afterwards for bindings etc. if (flushidx !== 0) { return; } const saved_component = current_component; do { // first, call beforeUpdate functions // and update components try { while (flushidx < dirty_components.length) { const component = dirty_components[flushidx]; flushidx++; set_current_component(component); update$1(component.$$); } } catch (e) { // reset dirty state to not end up in a deadlocked state and then rethrow dirty_components.length = 0; flushidx = 0; throw e; } set_current_component(null); dirty_components.length = 0; flushidx = 0; while (binding_callbacks.length) binding_callbacks.pop()(); // then, once components are updated, call // afterUpdate functions. This may cause // subsequent updates... for (let i = 0; i < render_callbacks.length; i += 1) { const callback = render_callbacks[i]; if (!seen_callbacks.has(callback)) { // ...so guard against infinite loops seen_callbacks.add(callback); callback(); } } render_callbacks.length = 0; } while (dirty_components.length); while (flush_callbacks.length) { flush_callbacks.pop()(); } update_scheduled = false; seen_callbacks.clear(); set_current_component(saved_component); } function update$1($$) { if ($$.fragment !== null) { $$.update(); run_all($$.before_update); const dirty = $$.dirty; $$.dirty = [-1]; $$.fragment && $$.fragment.p($$.ctx, dirty); $$.after_update.forEach(add_render_callback); } } /** * Useful for example to execute remaining `afterUpdate` callbacks before executing `destroy`. */ function flush_render_callbacks(fns) { const filtered = []; const targets = []; render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c)); targets.forEach((c) => c()); render_callbacks = filtered; } let promise; function wait() { if (!promise) { promise = Promise.resolve(); promise.then(() => { promise = null; }); } return promise; } function dispatch(node, direction, kind) { node.dispatchEvent(custom_event(`${direction ? 'intro' : 'outro'}${kind}`)); } const outroing = new Set(); let outros; function group_outros() { outros = { r: 0, c: [], p: outros // parent group }; } function check_outros() { if (!outros.r) { run_all(outros.c); } outros = outros.p; } function transition_in(block, local) { if (block && block.i) { outroing.delete(block); block.i(local); } } function transition_out(block, local, detach, callback) { if (block && block.o) { if (outroing.has(block)) return; outroing.add(block); outros.c.push(() => { outroing.delete(block); if (callback) { if (detach) block.d(1); callback(); } }); block.o(local); } else if (callback) { callback(); } } const null_transition = { duration: 0 }; function create_in_transition(node, fn, params) { const options = { direction: 'in' }; let config = fn(node, params, options); let running = false; let animation_name; let task; let uid = 0; function cleanup() { if (animation_name) delete_rule(node, animation_name); } function go() { const { delay = 0, duration = 300, easing = identity, tick = noop, css } = config || null_transition; if (css) animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++); tick(0, 1); const start_time = now() + delay; const end_time = start_time + duration; if (task) task.abort(); running = true; add_render_callback(() => dispatch(node, true, 'start')); task = loop(now => { if (running) { if (now >= end_time) { tick(1, 0); dispatch(node, true, 'end'); cleanup(); return running = false; } if (now >= start_time) { const t = easing((now - start_time) / duration); tick(t, 1 - t); } } return running; }); } let started = false; return { start() { if (started) return; started = true; delete_rule(node); if (is_function(config)) { config = config(options); wait().then(go); } else { go(); } }, invalidate() { started = false; }, end() { if (running) { cleanup(); running = false; } } }; } function destroy_block(block, lookup) { block.d(1); lookup.delete(block.key); } function outro_and_destroy_block(block, lookup) { transition_out(block, 1, 1, () => { lookup.delete(block.key); }); } function fix_and_outro_and_destroy_block(block, lookup) { block.f(); outro_and_destroy_block(block, lookup); } function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) { let o = old_blocks.length; let n = list.length; let i = o; const old_indexes = {}; while (i--) old_indexes[old_blocks[i].key] = i; const new_blocks = []; const new_lookup = new Map(); const deltas = new Map(); const updates = []; i = n; while (i--) { const child_ctx = get_context(ctx, list, i); const key = get_key(child_ctx); let block = lookup.get(key); if (!block) { block = create_each_block(key, child_ctx); block.c(); } else if (dynamic) { // defer updates until all the DOM shuffling is done updates.push(() => block.p(child_ctx, dirty)); } new_lookup.set(key, new_blocks[i] = block); if (key in old_indexes) deltas.set(key, Math.abs(i - old_indexes[key])); } const will_move = new Set(); const did_move = new Set(); function insert(block) { transition_in(block, 1); block.m(node, next); lookup.set(block.key, block); next = block.first; n--; } while (o && n) { const new_block = new_blocks[n - 1]; const old_block = old_blocks[o - 1]; const new_key = new_block.key; const old_key = old_block.key; if (new_block === old_block) { // do nothing next = new_block.first; o--; n--; } else if (!new_lookup.has(old_key)) { // remove old block destroy(old_block, lookup); o--; } else if (!lookup.has(new_key) || will_move.has(new_key)) { insert(new_block); } else if (did_move.has(old_key)) { o--; } else if (deltas.get(new_key) > deltas.get(old_key)) { did_move.add(new_key); insert(new_block); } else { will_move.add(old_key); o--; } } while (o--) { const old_block = old_blocks[o]; if (!new_lookup.has(old_block.key)) destroy(old_block, lookup); } while (n) insert(new_blocks[n - 1]); run_all(updates); return new_blocks; } function bind(component, name, callback) { const index = component.$$.props[name]; if (index !== undefined) { component.$$.bound[index] = callback; callback(component.$$.ctx[index]); } } function create_component(block) { block && block.c(); } function mount_component(component, target, anchor, customElement) { const { fragment, after_update } = component.$$; fragment && fragment.m(target, anchor); if (!customElement) { // onMount happens before the initial afterUpdate add_render_callback(() => { const new_on_destroy = component.$$.on_mount.map(run).filter(is_function); // if the component was destroyed immediately // it will update the `$$.on_destroy` reference to `null`. // the destructured on_destroy may still reference to the old array if (component.$$.on_destroy) { component.$$.on_destroy.push(...new_on_destroy); } else { // Edge case - component was destroyed immediately, // most likely as a result of a binding initialising run_all(new_on_destroy); } component.$$.on_mount = []; }); } after_update.forEach(add_render_callback); } function destroy_component(component, detaching) { const $$ = component.$$; if ($$.fragment !== null) { flush_render_callbacks($$.after_update); run_all($$.on_destroy); $$.fragment && $$.fragment.d(detaching); // TODO null out other refs, including component.$$ (but need to // preserve final state?) $$.on_destroy = $$.fragment = null; $$.ctx = []; } } function make_dirty(component, i) { if (component.$$.dirty[0] === -1) { dirty_components.push(component); schedule_update(); component.$$.dirty.fill(0); } component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); } function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) { const parent_component = current_component; set_current_component(component); const $$ = component.$$ = { fragment: null, ctx: [], // state props, update: noop, not_equal, bound: blank_object(), // lifecycle on_mount: [], on_destroy: [], on_disconnect: [], before_update: [], after_update: [], context: new Map(options.context || (parent_component ? parent_component.$$.context : [])), // everything else callbacks: blank_object(), dirty, skip_bound: false, root: options.target || parent_component.$$.root }; append_styles && append_styles($$.root); let ready = false; $$.ctx = instance ? instance(component, options.props || {}, (i, ret, ...rest) => { const value = rest.length ? rest[0] : ret; if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value); if (ready) make_dirty(component, i); } return ret; }) : []; $$.update(); ready = true; run_all($$.before_update); // `false` as a special case of no DOM component $$.fragment = create_fragment ? create_fragment($$.ctx) : false; if (options.target) { if (options.hydrate) { const nodes = children(options.target); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.l(nodes); nodes.forEach(detach); } else { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.c(); } if (options.intro) transition_in(component.$$.fragment); mount_component(component, options.target, options.anchor, options.customElement); flush(); } set_current_component(parent_component); } /** * Base class for Svelte components. Used when dev=false. */ class SvelteComponent { $destroy() { destroy_component(this, 1); this.$destroy = noop; } $on(type, callback) { if (!is_function(callback)) { return noop; } const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); callbacks.push(callback); return () => { const index = callbacks.indexOf(callback); if (index !== -1) callbacks.splice(index, 1); }; } $set($$props) { if (this.$$set && !is_empty($$props)) { this.$$.skip_bound = true; this.$$set($$props); this.$$.skip_bound = false; } } } /* global RED */ const getBooleanFrom = (property) => { return typeof property === 'boolean' ? property : property.toString().toLowerCase() === 'true' }; const getId = (prop = null) => { let id = prop; if (!id) { id = Date.now() + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); } return id }; const getFadeDuration = (fading) => { let fadeDuration = 800; // do not use isNaN with boolean! if (typeof fading === 'number' || (typeof fading === 'string' && fading !== 'true' && fading !== 'false')) { fadeDuration = Number(fading); } else { fading = getBooleanFrom(fading); if (!fading) fadeDuration = 0; } return fadeDuration }; const setInternalValue = (internal, nodeProp, value) => { // value must not be undefined, as that can result in strange behaviour but can have other falsy value types (checkbox = false, number = 0) if (internal.updateNode && typeof nodeProp !== 'undefined') { return nodeProp } else if (typeof value !== 'undefined') { return value } else { return '' } }; const initInternal = (nodeProp, value) => { const internal = { init: true, isError: false, updateNode: typeof nodeProp !== 'undefined', valueHasChanged: false }; // on init set the nodeProp.value else we have the whole node property (with label etc.) internal.value = setInternalValue(internal, nodeProp?.value, value); internal.oldValue = internal.value; return internal }; const getNewInternal = (nodeProp, value, internal, validateFunction, error, node) => { internal.valueHasChanged = internal.updateNode ? nodeProp !== internal.value : internal.value !== value; if (internal.valueHasChanged) { if (internal.value === internal.oldValue) { internal.value = setInternalValue(internal, nodeProp, value); } internal.oldValue = internal.value; } if (validateFunction) { // add node to validate function to have access to node properties while validating when input field changes internal.isError = !validateFunction(internal.value, node); } else { internal.isError = error; } return internal }; // escape "unallowed" jQuery chars const idSanitizer = (id) => id.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1'); const setTooltip = (tooltip, tooltipExists, target) => { target = idSanitizer(target); // delete via popover.tooltip as RED.popover Object has no delete function and removing content will show empty tooltip RED.popover.tooltip(window.$(target)).delete(); tooltipExists = false; if (tooltip) { // Use RED.popover.create to set the tooltip instead of RED.popover.tooltip as a tooltip can't be interactive (closes on mouseover) // don't use a dynamic tooltip via content: () => {tooltip} as this won't work so well on some elements (e.g. label) and Node-RED won't // use the string rendered as html but as plain string. RED.popover.create({ tooltip: true, target: window.$(target), trigger: 'hover', size: 'small', direction: 'bottom', content: RED.utils.renderMarkdown(RED.utils.sanitize(tooltip)), delay: { show: 750, hide: 100 }, interactive: true, class: 'sir-NR-popover' }); tooltipExists = true; } return tooltipExists }; function cubicOut(t) { const f = t - 1.0; return f * f * f + 1.0; } function fade(node, { delay = 0, duration = 400, easing = identity } = {}) { const o = +getComputedStyle(node).opacity; return { delay, duration, easing, css: t => `opacity: ${t * o}` }; } /* ../../../svelte-integration-red/components/Row.svelte generated by Svelte v3.58.0 */ function add_css$h(target) { append_styles(target, "svelte-njf2hk", ".sir-Row.svelte-njf2hk{clear:both;margin-bottom:12px;display:flex;align-items:center;justify-content:flex-start}.sir-Row > *:not(:last-child){margin-right:7px}.sir-Row.inline button:not(:last-child){margin-right:3px}.sir-Row label{display:inline-block;min-width:105px;width:105px;margin-right:7px;align-items:center;margin-bottom:0px;overflow-wrap:break-word}i, .sir-Row, .sir-Row label{user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}"); } // (53:0) {:else} function create_else_block$7(ctx) { let div; let t; let div_class_value; let current; let mounted; let dispose; let if_block = /*indented*/ ctx[2] && create_if_block_2$b(ctx); const default_slot_template = /*#slots*/ ctx[9].default; const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[8], null); return { c() { div = element("div"); if (if_block) if_block.c(); t = space(); if (default_slot) default_slot.c(); attr(div, "id", /*id*/ ctx[0]); attr(div, "class", div_class_value = "" + (null_to_empty(/*clazz*/ ctx[3]) + " svelte-njf2hk")); attr(div, "style", /*style*/ ctx[4]); toggle_class(div, "sir-Row", !/*inline*/ ctx[1]); }, m(target, anchor) { insert(target, div, anchor); if (if_block) if_block.m(div, null); append(div, t); if (default_slot) { default_slot.m(div, null); } current = true; if (!mounted) { dispose = [ listen(div, "click", /*click_handler_1*/ ctx[16]), listen(div, "keypress", /*keypress_handler_1*/ ctx[17]), listen(div, "keydown", /*keydown_handler_1*/ ctx[18]), listen(div, "dblclick", /*dblclick_handler_1*/ ctx[19]), listen(div, "mouseenter", /*mouseenter_handler_1*/ ctx[20]), listen(div, "mouseleave", /*mouseleave_handler_1*/ ctx[21]) ]; mounted = true; } }, p(ctx, dirty) { if (/*indented*/ ctx[2]) { if (if_block) { if_block.p(ctx, dirty); } else { if_block = create_if_block_2$b(ctx); if_block.c(); if_block.m(div, t); } } else if (if_block) { if_block.d(1); if_block = null; } if (default_slot) { if (default_slot.p && (!current || dirty & /*$$scope*/ 256)) { update_slot_base( default_slot, default_slot_template, ctx, /*$$scope*/ ctx[8], !current ? get_all_dirty_from_scope(/*$$scope*/ ctx[8]) : get_slot_changes(default_slot_template, /*$$scope*/ ctx[8], dirty, null), null ); } } if (!current || dirty & /*id*/ 1) { attr(div, "id", /*id*/ ctx[0]); } if (!current || dirty & /*clazz*/ 8 && div_class_value !== (div_class_value = "" + (null_to_empty(/*clazz*/ ctx[3]) + " svelte-njf2hk"))) { attr(div, "class", div_class_value); } if (!current || dirty & /*style*/ 16) { attr(div, "style", /*style*/ ctx[4]); } if (!current || dirty & /*clazz, inline*/ 10) { toggle_class(div, "sir-Row", !/*inline*/ ctx[1]); } }, i(local) { if (current) return; transition_in(default_slot, local); current = true; }, o(local) { transition_out(default_slot, local); current = false; }, d(detaching) { if (detaching) detach(div); if (if_block) if_block.d(); if (default_slot) default_slot.d(detaching); mounted = false; run_all(dispose); } }; } // (46:0) {#if fadeDuration} function create_if_block$h(ctx) { let div; let t; let div_class_value; let div_intro; let current; let mounted; let dispose; let if_block = /*indented*/ ctx[2] && create_if_block_1$e(ctx); const default_slot_template = /*#slots*/ ctx[9].default; const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[8], null); return { c() { div = element("div"); if (if_block) if_block.c(); t = space(); if (default_slot) default_slot.c(); attr(div, "id", /*id*/ ctx[0]); attr(div, "class", div_class_value = "" + (null_to_empty(/*clazz*/ ctx[3]) + " svelte-njf2hk")); attr(div, "style", /*style*/ ctx[4]); toggle_class(div, "sir-Row", !/*inline*/ ctx[1]); }, m(target, anchor) { insert(target, div, anchor); if (if_block) if_block.m(div, null); append(div, t); if (default_slot) { default_slot.m(div, null); } current = true; if (!mounted) { dispose = [ listen(div, "click", /*click_handler*/ ctx[10]), listen(div, "keypress", /*keypress_handler*/ ctx[11]), listen(div, "keydown", /*keydown_handler*/ ctx[12]), listen(div, "dblclick", /*dblclick_handler*/ ctx[13]), listen(div, "mouseenter", /*mouseenter_handler*/ ctx[14]), listen(div, "mouseleave", /*mouseleave_handler*/ ctx[15]) ]; mounted = true; } }, p(new_ctx, dirty) { ctx = new_ctx; if (/*indented*/ ctx[2]) { if (if_block) { if_block.p(ctx, dirty); } else { if_block = create_if_block_1$e(ctx); if_block.c(); if_block.m(div, t); } } else if (if_block) { if_block.d(1); if_block = null; } if (default_slot) { if (default_slot.p && (!current || dirty & /*$$scope*/ 256)) { update_slot_base( default_slot, default_slot_template, ctx, /*$$scope*/ ctx[8], !current ? get_all_dirty_from_scope(/*$$scope*/ ctx[8]) : get_slot_changes(default_slot_template, /*$$scope*/ ctx[8], dirty, null), null ); } } if (!current || dirty & /*id*/ 1) { attr(div, "id", /*id*/ ctx[0]); } if (!current || dirty & /*clazz*/ 8 && div_class_value !== (div_class_value = "" + (null_to_empty(/*clazz*/ ctx[3]) + " svelte-njf2hk"))) { attr(div, "class", div_class_value); } if (!current || dirty & /*style*/ 16) { attr(div, "style", /*style*/ ctx[4]); } if (!current || dirty & /*clazz, inline*/ 10) { toggle_class(div, "sir-Row", !/*inline*/ ctx[1]); } }, i(local) { if (current) return; transition_in(default_slot, local); if (!div_intro) { add_render_callback(() => { div_intro = create_in_transition(div, fade, { duration: /*fadeDuration*/ ctx[5] }); div_intro.start(); }); } current = true; }, o(local) { transition_out(default_slot, local); current = false; }, d(detaching) { if (detaching) detach(div); if (if_block) if_block.d(); if (default_slot) default_slot.d(detaching); mounted = false; run_all(dispose); } }; } // (55:4) {#if indented} function create_if_block_2$b(ctx) { let label; return { c() { label = element("label"); attr(label, "for", /*id*/ ctx[0]); }, m(target, anchor) { insert(target, label, anchor); }, p(ctx, dirty) { if (dirty & /*id*/ 1) { attr(label, "for", /*id*/ ctx[0]); } }, d(detaching) { if (detaching) detach(label); } }; } // (48:4) {#if indented} function create_if_block_1$e(ctx) { let label; return { c() { label = element("label"); attr(label, "for", /*id*/ ctx[0]); }, m(target, anchor) { insert(target, label, anchor); }, p(ctx, dirty) { if (dirty & /*id*/ 1) { attr(label, "for", /*id*/ ctx[0]); } }, d(detaching) { if (detaching) detach(label); } }; } function create_fragment$j(ctx) { let current_block_type_index; let if_block; let if_block_anchor; let current; const if_block_creators = [create_if_block$h, create_else_block$7]; const if_blocks = []; function select_block_type(ctx, dirty) { if (/*fadeDuration*/ ctx[5]) return 0; return 1; } current_block_type_index = select_block_type(ctx); if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); return { c() { if_block.c(); if_block_anchor = empty(); }, m(target, anchor) { if_blocks[current_block_type_index].m(target, anchor); insert(target, if_block_anchor, anchor); current = true; }, p(ctx, [dirty]) { if_block.p(ctx, dirty); }, i(local) { if (current) return; transition_in(if_block); current = true; }, o(local) { transition_out(if_block); current = false; }, d(detaching) { if_blocks[current_block_type_index].d(detaching); if (detaching) detach(if_block_anchor); } }; } function instance$j($$self, $$props, $$invalidate) { let { $$slots: slots = {}, $$scope } = $$props; let { id, clazz = '', style = "", inline = false, maximize = false, indented = false, fading = true } = $$props; id = id || getId(); if (!id.toString().startsWith("sir-")) id = "sir-Row-" + id; inline = getBooleanFrom(inline); maximize = getBooleanFrom(maximize); indented = getBooleanFrom(indented); const fadeDuration = getFadeDuration(fading); function click_handler(event) { bubble.call(this, $$self, event); } function keypress_handler(event) { bubble.call(this, $$self, event); } function keydown_handler(event) { bubble.call(this, $$self, event); } function dblclick_handler(event) { bubble.call(this, $$self, event); } function mouseenter_handler(event) { bubble.call(this, $$self, event); } function mouseleave_handler(event) { bubble.call(this, $$self, event); } function click_handler_1(event) { bubble.call(this, $$self, event); } function keypress_handler_1(event) { bubble.call(this, $$self, event); } function keydown_handler_1(event) { bubble.call(this, $$self, event); } function dblclick_handler_1(event) { bubble.call(this, $$self, event); } function mouseenter_handler_1(event) { bubble.call(this, $$self, event); } function mouseleave_handler_1(event) { bubble.call(this, $$self, event); } $$self.$$set = $$props => { if ('id' in $$props) $$invalidate(0, id = $$props.id); if ('clazz' in $$props) $$invalidate(3, clazz = $$props.clazz); if ('style' in $$props) $$invalidate(4, style = $$props.style); if ('inline' in $$props) $$invalidate(1, inline = $$props.inline); if ('maximize' in $$props) $$invalidate(6, maximize = $$props.maximize); if ('indented' in $$props) $$invalidate(2, indented = $$props.indented); if ('fading' in $$props) $$invalidate(7, fading = $$props.fading); if ('$$scope' in $$props) $$invalidate(8, $$scope = $$props.$$scope); }; return [ id, inline, indented, clazz, style, fadeDuration, maximize, fading, $$scope, slots, click_handler, keypress_handler, keydown_handler, dblclick_handler, mouseenter_handler, mouseleave_handler, click_handler_1, keypress_handler_1, keydown_handler_1, dblclick_handler_1, mouseenter_handler_1, mouseleave_handler_1 ]; } class Row extends SvelteComponent { constructor(options) { super(); init( this, options, instance$j, create_fragment$j, safe_not_equal, { id: 0, clazz: 3, style: 4, inline: 1, maximize: 6, indented: 2, fading: 7 }, add_css$h ); } } /* global localStorage, */ // Translation: // current way with Node-RED tools: // - an i18nOptions object for the node where we can set a prefix if the Node-Red node is not in the main folder. // - to translate in a SIR component object just set the node property and set the path within the json file, e.g.: label:{ label.name }. // - instead of giving the node property you can set an i18n property with the path to the local folder, e.g.: 'test-node/second-node:' or if in the main folder: 'second-node:' // // a different approach to the code below is to use the offical way like: // - direct i18n in html <span data-i18n="test-node/second-node:second-node.label.name"></span> // - setting to placeholder prop <input type="text" data-i18n="[placeholder]myNode.placeholder.foo"> // // Sidenote: This translation is only working for custom nodes. Translations for the sir components are within their files. // This must be done that way, as we must ensure translation, whether SIR is installed or not. Also it seems that Node-Red only initialize translation files // for nodes registered in the package.json. // Addition: Since Node-Red 2.0.3 we can't import i18next as this will break all other translations. localStorage.getItem('editor-language') || navigator.language || 'en-US'; const i18nTranslate = (RED, node = {}, i18nDOM = true, translateThis) => { let result = translateThis; // i18n can be a string for the local folder path (which we can't have without node) or boolean false if we don't want to translate this one if (i18nDOM === false || i18nDOM.toString().trim() === 'false') { return result } let path = ''; if (typeof i18nDOM === 'string') { path = i18nDOM; } else if (node) { path = node.type; let folder = node?._def?.i18nOptions?.folder; if (folder) { if (!folder.endsWith('/')) { folder += '/'; } path = folder + path; } } if (path) { if (!path.endsWith(':')) path += ':'; result = RED._(path + translateThis); // RED._() will replace colon with dot, so we have to check if result is like that pattern const translateColonReplacedWithDot = translateThis.replaceAll(':', '.'); if (result === path + translateThis || result === path + translateColonReplacedWithDot || result === translateColonRep