@openremote/or-attribute-input 1.8.0-snapshot.20250725120001 → 1.8.0-snapshot.20250725123024

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.
@@ -1,88 +1,12 @@
1
- import { rankWith, and, mapStateToControlProps, mapDispatchToControlProps, uiTypeIs, formatIs } from "@jsonforms/core";
2
- import manager, { OREvent } from "@openremote/core";
3
- import { getTemplateWrapper } from "@openremote/or-json-forms";
4
- import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
5
- import { html } from "lit";
6
- import "@openremote/or-mwc-components/or-mwc-input";
7
- import { i18next } from "@openremote/or-translate";
8
- import { until } from "lit/directives/until.js";
9
- /**
10
- * This function creates a short lived cache for loading the list of agents; this is useful when multiple instances
11
- * of this control are used in a single UI
12
- */
13
- let agents;
14
- let loadingPromise;
15
- let subscribed = false;
16
- const timeout = 2000;
17
- export function loadAgents() {
18
- if (agents) {
19
- return Promise.resolve(agents);
20
- }
21
- if (loadingPromise) {
22
- return loadingPromise;
23
- }
24
- if (!subscribed) {
25
- manager.addListener((ev) => {
26
- switch (ev) {
27
- case OREvent.DISPLAY_REALM_CHANGED:
28
- agents = undefined;
29
- loadingPromise = undefined;
30
- break;
1
+ let agents,loadingPromise;import{rankWith as e,and as t,mapStateToControlProps as r,mapDispatchToControlProps as o,uiTypeIs as n,formatIs as s}from"@jsonforms/core";import i,{OREvent as a}from"@openremote/core";import{getTemplateWrapper as d}from"@openremote/or-json-forms";import{InputType as m}from"@openremote/or-mwc-components/or-mwc-input";import{html as p}from"lit";import"@openremote/or-mwc-components/or-mwc-input";import{i18next as c}from"@openremote/or-translate";import{until as l}from"lit/directives/until.js";let subscribed=!1,timeout=2e3;export function loadAgents(){return agents?Promise.resolve(agents):loadingPromise||(subscribed||(i.addListener(e=>{e===a.DISPLAY_REALM_CHANGED&&(agents=void 0,loadingPromise=void 0)}),i.events.subscribeAssetEvents(void 0,!1,e=>{e.asset&&e.asset.type.endsWith("Agent")&&(agents=void 0,loadingPromise=void 0)}),subscribed=!0),loadingPromise=i.rest.api.AssetResource.queryAssets({realm:{name:i.displayRealm},types:["Agent"],select:{attributes:[]}}).then(e=>e.data).then(e=>(agents=e,e)))}let agentIdTester=e(6,t(n("Control"),s("or-agent-id"))),agentIdRenderer=(e,t)=>{t=Object.assign(Object.assign(Object.assign({},t),r({jsonforms:Object.assign({},e)},t)),o(e.dispatch));let n=loadAgents().then(e=>{let r=e.map(e=>[e.id,e.name+" ("+e.id+")"]);return p`
2
+ <or-mwc-input .label="${c.t("agentId")}" required class="agent-id-picker" @or-mwc-input-changed="${r=>(e=>{t.handleChange(t.path,e?e.id:void 0)})(e.find(e=>e.id===r.detail.value))}" type="${m.SELECT}" .value="${t.data}" .placeholder="${c.t("selectAgent")}" .options="${r}"></or-mwc-input>
3
+ `});return d(p`
4
+ <style>
5
+ .agent-id-picker {
6
+ min-width: 300px;
7
+ max-width: 600px;
8
+ width: 100%;
31
9
  }
32
- });
33
- manager.events.subscribeAssetEvents(undefined, false, (assetEvent) => {
34
- if (assetEvent.asset && assetEvent.asset.type.endsWith("Agent")) {
35
- agents = undefined;
36
- loadingPromise = undefined;
37
- }
38
- });
39
- subscribed = true;
40
- }
41
- loadingPromise = manager.rest.api.AssetResource.queryAssets({
42
- realm: {
43
- name: manager.displayRealm
44
- },
45
- types: [
46
- "Agent"
47
- ],
48
- select: {
49
- attributes: []
50
- }
51
- })
52
- .then(response => response.data)
53
- .then(agnts => {
54
- agents = agnts;
55
- return agnts;
56
- });
57
- return loadingPromise;
58
- }
59
- const agentIdTester = rankWith(6, and(uiTypeIs("Control"), formatIs("or-agent-id")));
60
- const agentIdRenderer = (state, props) => {
61
- props = Object.assign(Object.assign(Object.assign({}, props), mapStateToControlProps({ jsonforms: Object.assign({}, state) }, props)), mapDispatchToControlProps(state.dispatch));
62
- const onAgentChanged = (agent) => {
63
- props.handleChange(props.path, agent ? agent.id : undefined);
64
- return;
65
- };
66
- const loadedTemplatePromise = loadAgents().then(agents => {
67
- const options = agents.map(agent => [agent.id, agent.name + " (" + agent.id + ")"]);
68
- return html `
69
- <or-mwc-input .label="${i18next.t("agentId")}" required class="agent-id-picker" @or-mwc-input-changed="${(ev) => onAgentChanged(agents.find((agent) => agent.id === ev.detail.value))}" type="${InputType.SELECT}" .value="${props.data}" .placeholder="${i18next.t("selectAgent")}" .options="${options}"></or-mwc-input>
70
- `;
71
- });
72
- const template = html `
73
- <style>
74
- .agent-id-picker {
75
- min-width: 300px;
76
- max-width: 600px;
77
- width: 100%;
78
- }
79
- </style>
80
- ${until(loadedTemplatePromise, html `<or-mwc-input class="agent-id-picker" .type="${InputType.SELECT}"></or-mwc-input>`)}
81
- `;
82
- return getTemplateWrapper(template, undefined);
83
- };
84
- export const agentIdRendererRegistryEntry = {
85
- tester: agentIdTester,
86
- renderer: agentIdRenderer
87
- };
88
- //# sourceMappingURL=agent-link-json-forms-renderer.js.map
10
+ </style>
11
+ ${l(n,p`<or-mwc-input class="agent-id-picker" .type="${m.SELECT}"></or-mwc-input>`)}
12
+ `,void 0)};export const agentIdRendererRegistryEntry={tester:agentIdTester,renderer:agentIdRenderer};