@openremote/core 1.0.3 → 1.2.0-snapshot.20240512160221

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.
Files changed (43) hide show
  1. package/dist/umd/index.bundle.js +2 -273
  2. package/dist/umd/index.bundle.js.LICENSE.txt +26 -0
  3. package/dist/umd/index.js +2 -7
  4. package/dist/umd/index.js.LICENSE.txt +22 -0
  5. package/dist/umd/index.orbundle.js +50 -280
  6. package/dist/umd/index.orbundle.js.LICENSE.txt +38 -0
  7. package/{dist → lib}/asset-mixin.d.ts +2 -0
  8. package/lib/asset-mixin.js +1 -0
  9. package/lib/asset-mixin.js.map +1 -0
  10. package/{dist → lib}/console.d.ts +14 -5
  11. package/lib/console.js +1 -0
  12. package/lib/console.js.map +1 -0
  13. package/lib/defaults.js +1 -0
  14. package/lib/defaults.js.map +1 -0
  15. package/{dist → lib}/event.d.ts +20 -19
  16. package/lib/event.js +1 -0
  17. package/lib/event.js.map +1 -0
  18. package/lib/index.d.ts +150 -0
  19. package/lib/index.js +1 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/util.d.ts +92 -0
  22. package/lib/util.js +1 -0
  23. package/lib/util.js.map +1 -0
  24. package/package.json +24 -25
  25. package/.project +0 -17
  26. package/.settings/org.eclipse.buildship.core.prefs +0 -2
  27. package/@types/i18next-sprintf-postprocessor.d.ts +0 -1
  28. package/dist/asset-mixin.js +0 -156
  29. package/dist/console.js +0 -452
  30. package/dist/defaults.js +0 -16
  31. package/dist/event.js +0 -567
  32. package/dist/index.d.ts +0 -224
  33. package/dist/index.js +0 -996
  34. package/dist/mdi-icons.json +0 -1
  35. package/dist/or-icon-set.d.ts +0 -3
  36. package/dist/or-icon-set.js +0 -10
  37. package/dist/util.d.ts +0 -41
  38. package/dist/util.js +0 -362
  39. package/mdi-iconset-generator.js +0 -34
  40. package/tsconfig.json +0 -16
  41. package/typedoc.js +0 -3
  42. package/webpack.config.js +0 -16
  43. /package/{dist → lib}/defaults.d.ts +0 -0
package/dist/console.js DELETED
@@ -1,452 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import manager from "./index";
11
- // No ES6 module support in platform lib
12
- let platform = require('platform');
13
- export class Console {
14
- constructor(realm, autoEnable, enableComplete) {
15
- this._autoEnable = false;
16
- this._initialised = false;
17
- this._initialiseInProgress = false;
18
- this._pendingProviderPromises = {};
19
- this._pendingProviderEnables = [];
20
- this._registrationTimer = null;
21
- this._realm = realm;
22
- this._autoEnable = autoEnable;
23
- this._enableCompleteCallback = enableComplete;
24
- // Export this to the window to make it accessible from mobile webview code
25
- // @ts-ignore
26
- window.OpenRemoteConsole = this;
27
- // Check for query parameters to override values
28
- let queryParams = new URLSearchParams(window.location.search);
29
- let consoleName = queryParams.get("consoleName");
30
- let consoleVersion = queryParams.get("consoleVersion");
31
- let consolePlatform = queryParams.get("consolePlatform");
32
- let consoleProviders = queryParams.get("consoleProviders");
33
- let autoEnableStr = queryParams.get("consoleAutoEnable");
34
- let requestedProviders = consoleProviders && consoleProviders.length > 0 ? consoleProviders.split(" ") : ["push", "storage"];
35
- if (requestedProviders.indexOf("storage") < 0) {
36
- requestedProviders.push("storage"); // Storage provider is essential to operation and should always be available
37
- }
38
- this._pendingProviderEnables = consoleProviders && consoleProviders.length > 0 ? consoleProviders.split(" ") : [];
39
- // Look for existing console registration in local storage or just create a new one
40
- let consoleReg = Console._createConsoleRegistration();
41
- let consoleRegStr = window.localStorage.getItem("OpenRemoteConsole:" + realm);
42
- if (consoleRegStr) {
43
- try {
44
- let storedRegObj = JSON.parse(consoleRegStr);
45
- let storedReg = storedRegObj;
46
- if (storedReg.id) {
47
- consoleReg.id = storedReg.id;
48
- }
49
- if (storedReg.name) {
50
- consoleReg.name = storedReg.name;
51
- }
52
- if (storedReg.providers) {
53
- consoleReg.providers = storedReg.providers;
54
- }
55
- if (storedReg.apps) {
56
- consoleReg.apps = storedReg.apps;
57
- }
58
- }
59
- catch (e) {
60
- console.error("Failed to deserialise console registration");
61
- }
62
- }
63
- let oldProviders = consoleReg.providers;
64
- consoleReg.providers = {};
65
- for (let providerName of requestedProviders) {
66
- let provider = oldProviders && oldProviders.hasOwnProperty(providerName) ? oldProviders[providerName] : {
67
- enabled: false,
68
- disabled: false
69
- };
70
- consoleReg.providers[providerName] = provider;
71
- }
72
- let appName = manager.getAppName();
73
- if (appName.length > 0 && consoleReg.apps.indexOf(appName) < 0) {
74
- consoleReg.apps.push(appName);
75
- }
76
- this._registration = consoleReg;
77
- if (consoleName) {
78
- consoleReg.name = consoleName;
79
- }
80
- if (consoleVersion) {
81
- consoleReg.version = consoleVersion;
82
- }
83
- if (consolePlatform) {
84
- consoleReg.platform = consolePlatform;
85
- }
86
- if (autoEnableStr) {
87
- this._autoEnable = autoEnableStr === "TRUE" || autoEnableStr === "true";
88
- }
89
- }
90
- get registration() {
91
- return this._registration;
92
- }
93
- get autoEnable() {
94
- return this._autoEnable;
95
- }
96
- get pendingProviderEnables() {
97
- return this._pendingProviderEnables.slice(0);
98
- }
99
- get shellApple() {
100
- // @ts-ignore
101
- return navigator.platform.substr(0, 2) === 'iP' && window.webkit && window.webkit.messageHandlers;
102
- }
103
- get shellAndroid() {
104
- // @ts-ignore
105
- return !!window.MobileInterface;
106
- }
107
- get isMobile() {
108
- return this.shellApple || this.shellAndroid;
109
- }
110
- initialise() {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- if (this._initialised || this._initialiseInProgress) {
113
- return;
114
- }
115
- console.debug("Console: initialising");
116
- this._initialiseInProgress = true;
117
- try {
118
- if (this._registration.providers) {
119
- for (let providerName of Object.keys(this._registration.providers)) {
120
- yield this._initialiseProvider(providerName);
121
- }
122
- }
123
- // Get an ID for this console if it doesn't have one
124
- if (!this._registration.id) {
125
- yield this.sendRegistration(0);
126
- }
127
- this._initialised = true;
128
- this._initialiseInProgress = false;
129
- if (this._pendingProviderEnables.length === 0) {
130
- yield this.sendRegistration();
131
- this._callCompletedCallback();
132
- }
133
- else if (this._autoEnable) {
134
- yield this.enableProviders();
135
- }
136
- }
137
- catch (e) {
138
- console.error(e);
139
- }
140
- finally {
141
- this._initialiseInProgress = false;
142
- }
143
- });
144
- }
145
- // This mechanism doesn't support sending extra data to the providers being enabled and it doesn't allow data
146
- // to be retrieved from the replies; if that is required then providers should be manually enabled from the calling app
147
- enableProviders() {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- if (!this._initialised) {
150
- throw new Error("Console must be initialised before enabling providers");
151
- }
152
- for (let index = this._pendingProviderEnables.length - 1; index > -1; index--) {
153
- let providerName = this._pendingProviderEnables[index];
154
- yield this.enableProvider(providerName);
155
- }
156
- });
157
- }
158
- enableProvider(providerName, data) {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- if (!this._initialised) {
161
- console.debug("Console must be initialised before disabling providers");
162
- throw new Error("Console must be initialised before enabling providers");
163
- }
164
- if (!this._registration.providers.hasOwnProperty(providerName)) {
165
- console.debug("Invalid console provider '" + providerName + "'");
166
- throw new Error("Invalid console provider '" + providerName + "'");
167
- }
168
- console.debug("Console: enabling provider '" + providerName + "'");
169
- let msg = {
170
- provider: providerName,
171
- action: "PROVIDER_ENABLE",
172
- consoleId: this._registration.id,
173
- data
174
- };
175
- let response = yield this.sendProviderMessage(msg, true);
176
- this._registration.providers[providerName].hasPermission = response.hasPermission;
177
- this._registration.providers[providerName].success = response.success;
178
- this._registration.providers[providerName].enabled = response.success;
179
- this._registration.providers[providerName].data = response.data;
180
- let index = this._pendingProviderEnables.indexOf(providerName);
181
- if (index >= 0) {
182
- this._pendingProviderEnables.splice(index, 1);
183
- if (this._pendingProviderEnables.length === 0) {
184
- this.sendRegistration();
185
- this._callCompletedCallback();
186
- }
187
- }
188
- return response;
189
- });
190
- }
191
- disableProvider(provider) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- if (!this._initialised) {
194
- console.debug("Console must be initialised before disabling providers");
195
- throw new Error("Console must be initialised before disabling providers");
196
- }
197
- if (!this._registration.providers.hasOwnProperty(provider)) {
198
- console.debug("Invalid console provider '" + provider + "'");
199
- throw new Error("Invalid console provider '" + provider + "'");
200
- }
201
- console.debug("Console: disabling provider '" + provider + "'");
202
- let response = yield this.sendProviderMessage({
203
- provider: provider,
204
- action: "PROVIDER_DISABLE"
205
- }, true);
206
- this._registration.providers[provider].disabled = true;
207
- this._registration.providers[provider].enabled = false;
208
- return response;
209
- });
210
- }
211
- sendProviderMessage(message, waitForResponse) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- if (!this._registration.providers.hasOwnProperty(message.provider)) {
214
- console.debug("Invalid console provider '" + message.provider + "'");
215
- throw new Error("Invalid console provider '" + message.provider + "'");
216
- }
217
- if (!waitForResponse) {
218
- this._doSendProviderMessage(message);
219
- return;
220
- }
221
- let promiseName = message.provider + message.action;
222
- if (this._pendingProviderPromises[promiseName]) {
223
- throw new Error("Message already pending for provider '" + name + "' with action '" + message.action + "'");
224
- }
225
- return yield new Promise(resolve => {
226
- this._pendingProviderPromises[promiseName] = resolve;
227
- this._doSendProviderMessage(message);
228
- });
229
- });
230
- }
231
- // Uses a delayed mechanism to avoid excessive calls to the server during enabling providers
232
- sendRegistration(delay) {
233
- if (this._registrationTimer) {
234
- window.clearTimeout(this._registrationTimer);
235
- this._registrationTimer = null;
236
- }
237
- delay = delay !== undefined ? delay : 2000;
238
- console.debug("Sending registration in: " + delay + "ms");
239
- return new Promise((resolve, reject) => {
240
- this._registrationTimer = window.setTimeout(() => {
241
- this._registrationTimer = null;
242
- console.debug("Console: updating registration");
243
- try {
244
- manager.rest.api.ConsoleResource.register(this._registration).then((response) => {
245
- if (response.status !== 200) {
246
- throw new Error("Failed to register console");
247
- }
248
- this._registration = response.data;
249
- console.debug("Console: registration successful");
250
- console.debug("Console: updating locally stored registration");
251
- window.localStorage.setItem("OpenRemoteConsole:" + this._realm, JSON.stringify(this._registration));
252
- resolve();
253
- });
254
- }
255
- catch (e) {
256
- console.error("Failed to register console");
257
- reject("Failed to register console");
258
- }
259
- });
260
- });
261
- }
262
- storeData(key, value) {
263
- this.sendProviderMessage({
264
- provider: "storage",
265
- action: "STORE",
266
- key: key,
267
- value: value
268
- }, false);
269
- }
270
- retrieveData(key) {
271
- return __awaiter(this, void 0, void 0, function* () {
272
- let response = yield this.sendProviderMessage({
273
- provider: "storage",
274
- action: "RETRIEVE",
275
- key: key
276
- }, true);
277
- if (response && response.value) {
278
- return response.value;
279
- }
280
- });
281
- }
282
- _postNativeShellMessage(jsonMessage) {
283
- if (this.shellAndroid) {
284
- // @ts-ignore
285
- return window.MobileInterface.postMessage(JSON.stringify(jsonMessage));
286
- }
287
- if (this.shellApple) {
288
- // @ts-ignore
289
- return window.webkit.messageHandlers.int.postMessage(jsonMessage);
290
- }
291
- }
292
- _doSendProviderMessage(msg) {
293
- if (this.isMobile) {
294
- this._postNativeShellMessage({ type: "provider", data: msg });
295
- }
296
- else {
297
- if (!msg.provider || !msg.action) {
298
- return;
299
- }
300
- switch (msg.provider.trim().toUpperCase()) {
301
- // TODO: Implement web browser provider handling (web push etc.)
302
- case "PUSH":
303
- switch (msg.action.trim().toUpperCase()) {
304
- case "PROVIDER_INIT":
305
- let initResponse = {
306
- action: "PROVIDER_INIT",
307
- provider: "push",
308
- version: "web",
309
- enabled: true,
310
- disabled: false,
311
- hasPermission: true,
312
- requiresPermission: false,
313
- success: true
314
- };
315
- this._handleProviderResponse(JSON.stringify(initResponse));
316
- break;
317
- case "PROVIDER_ENABLE":
318
- let enableResponse = {
319
- action: "PROVIDER_ENABLE",
320
- provider: "push",
321
- hasPermission: true,
322
- success: true
323
- };
324
- this._handleProviderResponse(JSON.stringify(enableResponse));
325
- break;
326
- default:
327
- throw new Error("Unsupported provider '" + msg.provider + "' and action '" + msg.action + "'");
328
- }
329
- break;
330
- case "STORAGE":
331
- switch (msg.action) {
332
- case "PROVIDER_INIT":
333
- let initResponse = {
334
- action: "PROVIDER_INIT",
335
- provider: "storage",
336
- version: "1.0.0",
337
- disabled: false,
338
- enabled: true,
339
- hasPermission: true,
340
- requiresPermission: false,
341
- success: true
342
- };
343
- this._handleProviderResponse(JSON.stringify(initResponse));
344
- break;
345
- case "PROVIDER_ENABLE":
346
- let enableResponse = {
347
- action: "PROVIDER_ENABLE",
348
- provider: "storage",
349
- hasPermission: true,
350
- success: true
351
- };
352
- this._handleProviderResponse(JSON.stringify(enableResponse));
353
- break;
354
- case "STORE":
355
- {
356
- let keyValue = msg.key ? msg.key.trim() : null;
357
- if (!keyValue || keyValue.length === 0) {
358
- throw new Error("Storage provider 'store' action requires a `key`");
359
- }
360
- if (msg.value) {
361
- if (msg.value === null) {
362
- window.localStorage.removeItem(keyValue);
363
- }
364
- else {
365
- window.localStorage.setItem(keyValue, msg.value);
366
- }
367
- }
368
- }
369
- break;
370
- case "RETRIEVE":
371
- {
372
- let keyValue = msg.key ? msg.key.trim() : null;
373
- if (!keyValue || keyValue.length === 0) {
374
- throw new Error("Storage provider 'retrieve' action requires a `key`");
375
- }
376
- this._handleProviderResponse(JSON.stringify({
377
- action: "RETRIEVE",
378
- provider: "storage",
379
- key: keyValue,
380
- value: window.localStorage.getItem(keyValue)
381
- }));
382
- }
383
- break;
384
- default:
385
- throw new Error("Unsupported provider '" + msg.provider + "' and action '" + msg.action + "'");
386
- }
387
- break;
388
- }
389
- }
390
- }
391
- // This is called by native web view code
392
- _handleProviderResponse(msg) {
393
- if (!msg) {
394
- return;
395
- }
396
- let msgJson = JSON.parse(msg);
397
- let name = msgJson.provider;
398
- let action = msgJson.action;
399
- let resolve = this._pendingProviderPromises[name + action];
400
- if (resolve != null) {
401
- this._pendingProviderPromises[name + action] = null;
402
- resolve(msgJson);
403
- }
404
- }
405
- _callCompletedCallback() {
406
- let callback = this._enableCompleteCallback;
407
- this._enableCompleteCallback = null;
408
- if (callback) {
409
- window.setTimeout(() => {
410
- callback();
411
- }, 0);
412
- }
413
- }
414
- static _createConsoleRegistration() {
415
- let reg = {
416
- name: platform.name,
417
- version: platform.version,
418
- platform: platform.os.toString(),
419
- apps: [],
420
- model: ((platform.manufacturer ? platform.manufacturer + " " : "") + (platform.product ? platform.product : "")).trim()
421
- };
422
- return reg;
423
- }
424
- _initialiseProvider(providerName) {
425
- return __awaiter(this, void 0, void 0, function* () {
426
- console.debug("Console: initialising provider '" + providerName + "'");
427
- let initResponse = yield this.sendProviderMessage({
428
- provider: providerName,
429
- action: "PROVIDER_INIT"
430
- }, true);
431
- this._registration.providers[providerName].version = initResponse.version;
432
- this._registration.providers[providerName].requiresPermission = initResponse.requiresPermission;
433
- this._registration.providers[providerName].hasPermission = initResponse.hasPermission;
434
- this._registration.providers[providerName].success = initResponse.success;
435
- this._registration.providers[providerName].enabled = initResponse.enabled;
436
- this._registration.providers[providerName].disabled = initResponse.disabled;
437
- this._registration.providers[providerName].data = initResponse.data;
438
- if (!initResponse.success) {
439
- console.debug("Provider initialisation failed: '" + providerName + "'");
440
- initResponse.disabled = true;
441
- this._registration.providers[providerName].disabled = true;
442
- }
443
- if (initResponse.disabled || initResponse.enabled) {
444
- let index = this._pendingProviderEnables.indexOf(providerName);
445
- if (index >= 0) {
446
- this._pendingProviderEnables.splice(index, 1);
447
- }
448
- }
449
- });
450
- }
451
- }
452
- //# sourceMappingURL=console.js.map
package/dist/defaults.js DELETED
@@ -1,16 +0,0 @@
1
- export const DefaultColor4 = "#1b5630"; // Primary
2
- export const DefaultColor7 = "#FFF"; // Secondary
3
- export const DefaultColor1 = "#FFF"; // Surface
4
- export const DefaultColor2 = "#F9F9F9"; // Background
5
- export const DefaultColor5 = "#CCC"; // Borders and lines
6
- export const DefaultColor6 = "#be0000"; // Invalid/Error
7
- export const DefaultColor8 = "#FFF"; // On Primary
8
- export const DefaultColor3 = "#4c4c4c"; // Text / On Secondary
9
- export const DefaultColor9 = "#000"; // On Background
10
- export const DefaultColor10 = "#000"; // On Surface
11
- export const DefaultColor11 = "#FFF"; // On Error
12
- export const DefaultBoxShadowBottom = "0 5px 5px -5px rgba(0,0,0,0.3)";
13
- export const DefaultBoxShadow = "0 1px 3px 0 rgba(0,0,0,0.21)";
14
- export const DefaultHeaderHeight = "50px";
15
- export const DefaultDisabledOpacity = "0.3";
16
- //# sourceMappingURL=defaults.js.map