atriusmaps-node-sdk 1.0.0 → 3.2.28

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 (105) hide show
  1. package/README.md +76 -0
  2. package/config/rollup.config.cjs.js +31 -0
  3. package/dist/cjs/_virtual/_empty_module_placeholder.js +5 -0
  4. package/dist/cjs/deploy/nodeEntry.js +15 -0
  5. package/dist/cjs/deploy/prepareSDKConfig.js +9 -0
  6. package/dist/cjs/package.json +1 -0
  7. package/dist/cjs/package.json.js +11 -0
  8. package/dist/cjs/plugins/clientAPI/src/clientAPI.js +9 -0
  9. package/dist/cjs/plugins/dynamicPois/src/dynamicPois.js +33 -0
  10. package/dist/cjs/plugins/poiDataManager/src/poiDataManager.js +36 -0
  11. package/dist/cjs/plugins/sdkServer/src/sdkHeadless.js +31 -0
  12. package/dist/cjs/plugins/sdkServer/src/sdkServer.js +13 -0
  13. package/dist/cjs/plugins/sdkServer/src/util.js +10 -0
  14. package/dist/cjs/plugins/searchService/src/poiSearch.js +28 -0
  15. package/dist/cjs/plugins/searchService/src/searchService.js +37 -0
  16. package/dist/cjs/plugins/searchService/src/searchTypeahead.js +8 -0
  17. package/dist/cjs/plugins/searchService/src/utils.js +13 -0
  18. package/dist/cjs/plugins/venueDataLoader/src/venueDataLoader.js +36 -0
  19. package/dist/cjs/plugins/venueDataLoader/src/venueLoadingUtils.js +34 -0
  20. package/dist/cjs/plugins/wayfinder/src/findRoute.js +30 -0
  21. package/dist/cjs/plugins/wayfinder/src/minPriorityQueue.js +5 -0
  22. package/dist/cjs/plugins/wayfinder/src/navGraph.js +13 -0
  23. package/dist/cjs/plugins/wayfinder/src/navGraphDebug.js +30 -0
  24. package/dist/cjs/plugins/wayfinder/src/segmentBadges.js +5 -0
  25. package/dist/cjs/plugins/wayfinder/src/segmentBuilder.js +32 -0
  26. package/dist/cjs/plugins/wayfinder/src/segmentCategories.js +5 -0
  27. package/dist/cjs/plugins/wayfinder/src/stepBuilder.js +10 -0
  28. package/dist/cjs/plugins/wayfinder/src/wayfinder.js +40 -0
  29. package/dist/cjs/src/app.js +44 -0
  30. package/dist/cjs/src/auth/Auth.js +23 -0
  31. package/dist/cjs/src/configs/postproc-mol-url-parms.js +9 -0
  32. package/dist/cjs/src/configs/postproc-stateTracking.js +31 -0
  33. package/dist/cjs/src/configs/sdkHeadless.json.js +47 -0
  34. package/dist/cjs/src/controller.js +14 -0
  35. package/dist/cjs/src/debugTools.js +30 -0
  36. package/dist/cjs/src/env.js +7 -0
  37. package/dist/cjs/src/extModules/bustle.js +13 -0
  38. package/dist/cjs/src/extModules/flexapi/src/help.js +9 -0
  39. package/dist/cjs/src/extModules/flexapi/src/index.js +13 -0
  40. package/dist/cjs/src/extModules/flexapi/src/validate.js +10 -0
  41. package/dist/cjs/src/extModules/geohasher.js +8 -0
  42. package/dist/cjs/src/extModules/log.js +7 -0
  43. package/dist/cjs/src/historyManager.js +7 -0
  44. package/dist/cjs/src/utils/bounds.js +10 -0
  45. package/dist/cjs/src/utils/buildStructureLookup.js +29 -0
  46. package/dist/cjs/src/utils/configUtils.js +8 -0
  47. package/dist/cjs/src/utils/dom.js +10 -0
  48. package/dist/cjs/src/utils/funcs.js +15 -0
  49. package/dist/cjs/src/utils/geodesy.js +8 -0
  50. package/dist/cjs/src/utils/geom.js +35 -0
  51. package/dist/cjs/src/utils/i18n.js +14 -0
  52. package/dist/cjs/src/utils/observable.js +5 -0
  53. package/dist/cjs/src/utils/rand.js +8 -0
  54. package/lib/_virtual/_empty_module_placeholder.js +1 -0
  55. package/lib/deploy/nodeEntry.js +1 -58
  56. package/lib/deploy/prepareSDKConfig.js +1 -112
  57. package/lib/package.json.js +1 -143
  58. package/lib/plugins/clientAPI/src/clientAPI.js +1 -14
  59. package/lib/plugins/dynamicPois/src/dynamicPois.js +1 -131
  60. package/lib/plugins/poiDataManager/src/poiDataManager.js +1 -207
  61. package/lib/plugins/sdkServer/src/sdkHeadless.js +1 -53
  62. package/lib/plugins/sdkServer/src/sdkServer.js +1 -211
  63. package/lib/plugins/sdkServer/src/util.js +1 -18
  64. package/lib/plugins/searchService/src/poiSearch.js +1 -39
  65. package/lib/plugins/searchService/src/searchService.js +1 -234
  66. package/lib/plugins/searchService/src/searchTypeahead.js +1 -63
  67. package/lib/plugins/searchService/src/utils.js +1 -30
  68. package/lib/plugins/venueDataLoader/src/venueDataLoader.js +1 -465
  69. package/lib/plugins/venueDataLoader/src/venueLoadingUtils.js +1 -84
  70. package/lib/plugins/wayfinder/src/findRoute.js +1 -134
  71. package/lib/plugins/wayfinder/src/minPriorityQueue.js +1 -89
  72. package/lib/plugins/wayfinder/src/navGraph.js +1 -370
  73. package/lib/plugins/wayfinder/src/navGraphDebug.js +1 -95
  74. package/lib/plugins/wayfinder/src/segmentBadges.js +1 -29
  75. package/lib/plugins/wayfinder/src/segmentBuilder.js +1 -241
  76. package/lib/plugins/wayfinder/src/segmentCategories.js +1 -30
  77. package/lib/plugins/wayfinder/src/stepBuilder.js +1 -236
  78. package/lib/plugins/wayfinder/src/wayfinder.js +1 -452
  79. package/lib/src/app.js +1 -150
  80. package/lib/src/auth/Auth.js +1 -35
  81. package/lib/src/configs/postproc-mol-url-parms.js +1 -58
  82. package/lib/src/configs/postproc-stateTracking.js +1 -40
  83. package/lib/src/configs/sdkHeadless.json.js +1 -42
  84. package/lib/src/controller.js +1 -45
  85. package/lib/src/debugTools.js +1 -108
  86. package/lib/src/env.js +1 -17
  87. package/lib/src/extModules/bustle.js +1 -126
  88. package/lib/src/extModules/flexapi/src/help.js +1 -21
  89. package/lib/src/extModules/flexapi/src/index.js +1 -66
  90. package/lib/src/extModules/flexapi/src/validate.js +1 -131
  91. package/lib/src/extModules/geohasher.js +1 -90
  92. package/lib/src/extModules/log.js +1 -70
  93. package/lib/src/historyManager.js +1 -30
  94. package/lib/src/utils/bounds.js +1 -23
  95. package/lib/src/utils/buildStructureLookup.js +1 -17
  96. package/lib/src/utils/configUtils.js +1 -61
  97. package/lib/src/utils/dom.js +1 -46
  98. package/lib/src/utils/funcs.js +1 -50
  99. package/lib/src/utils/geodesy.js +1 -35
  100. package/lib/src/utils/geom.js +1 -141
  101. package/lib/src/utils/i18n.js +1 -70
  102. package/lib/src/utils/observable.js +1 -76
  103. package/lib/src/utils/rand.js +1 -82
  104. package/package.json +23 -6
  105. package/lib/_virtual/_empty_module_placeholder +0 -3
@@ -1,58 +1 @@
1
- import 'query-string';
2
-
3
- const parmToPlugin = {
4
- navFrom: 'online/getDirectionsFromTo',
5
- navTo: 'online/getDirectionsFromTo',
6
- accessible: 'online/getDirectionsFromTo',
7
- showNav: 'online/getDirectionsFromTo',
8
- poiId: ['online/getDirectionsFromTo', 'online/poiView'],
9
- vid: 'venueDataLoader',
10
- stage: 'venueDataLoader',
11
- contentStage: 'venueDataLoader',
12
- search: 'online/headerOnline',
13
- ho: ['online/getDirectionsFromTo', 'analytics2'], // handoff indicator (used in analytics)
14
- home: 'online/homeView', // doing a handoff to home view
15
- zoom: 'mapRenderer',
16
- pitch: 'mapRenderer',
17
- bearing: 'mapRenderer',
18
- lat: 'mapRenderer',
19
- lng: 'mapRenderer',
20
- radius: 'mapRenderer',
21
- buildingId: 'mapRenderer',
22
- floorId: 'mapRenderer',
23
- refInstallId: 'analytics2'
24
- };
25
-
26
- // Note: see note about security for forceCreate on postproc-stateTracking - same thing
27
- // applies here!
28
- function setDeepLinksForParms (config, parms, forceCreate) {
29
- // allow for lldebug on the URL to set debug mode. I made it "lldebug" just so it wasn't SO easy to guess. ;-)
30
- if (parms.lldebug !== undefined) {
31
- try {
32
- config.debug = JSON.parse(parms.lldebug);
33
- if (config.debug === null) // allow for a URL parm of just `lldebug` (no value = null)
34
- config.debug = { };
35
- } catch (e) { config.debug = true; }
36
- }
37
- Object.keys(parmToPlugin)
38
- .forEach(key => {
39
- if (parms[key] !== undefined) {
40
- let plugins = parmToPlugin[key];
41
- if (!Array.isArray(plugins))
42
- plugins = [plugins];
43
- plugins.forEach(plugin => {
44
- let pc = config.plugins[plugin]; // config for this plugin
45
- if (!pc && forceCreate)
46
- pc = config.plugins[plugin] = { };
47
- pc.deepLinkProps = { ...pc.deepLinkProps, [key]: parms[key] };
48
- });
49
- }
50
- });
51
-
52
- if (parms.poiId && parms.showNav) // poiId doubles as a parm for both - if showNav is defined, it should target getDirectionsFromTo only
53
- delete config.plugins['online/poiView'].deepLinkProps.poiId;
54
-
55
- return config
56
- }
57
-
58
- export { setDeepLinksForParms };
1
+ import"query-string";const e={navFrom:"online/getDirectionsFromTo",navTo:"online/getDirectionsFromTo",accessible:"online/getDirectionsFromTo",showNav:"online/getDirectionsFromTo",poiId:["online/getDirectionsFromTo","online/poiView"],vid:"venueDataLoader",stage:"venueDataLoader",contentStage:"venueDataLoader",search:"online/headerOnline",ho:["online/getDirectionsFromTo","analytics2"],home:"online/homeView",zoom:"mapRenderer",pitch:"mapRenderer",bearing:"mapRenderer",lat:"mapRenderer",lng:"mapRenderer",radius:"mapRenderer",buildingId:"mapRenderer",floorId:"mapRenderer",refInstallId:"analytics2"};function n(n,o,r){if(void 0!==o.lldebug)try{n.debug=JSON.parse(o.lldebug),null===n.debug&&(n.debug={})}catch(e){n.debug=!0}return Object.keys(e).forEach((i=>{if(void 0!==o[i]){let a=e[i];Array.isArray(a)||(a=[a]),a.forEach((e=>{let a=n.plugins[e];!a&&r&&(a=n.plugins[e]={}),a.deepLinkProps={...a.deepLinkProps,[i]:o[i]}}))}})),o.poiId&&o.showNav&&delete n.plugins["online/poiView"].deepLinkProps.poiId,n}export{n as setDeepLinksForParms};
@@ -1,40 +1 @@
1
- import 'query-string';
2
- import * as R from 'ramda';
3
- import 'zousan';
4
-
5
- /**
6
- * Given a state string (JSON representation of latestState above) this will
7
- * update the app state (via calling all plugins with their state)
8
- *
9
- * Note: forceCreate is a potential security risk. It is used by the SDK BEFORE the extends
10
- * is processed, so needed here - but a user could prepare a stateString that included
11
- * some plugin they aren't supposed to have activated. Lets revisit this soon and
12
- * instead have a way to tell this postprocessor to look for state somewhere BESIDES
13
- * the location.search - then we can remove dangerous flag. (of course it would take someone
14
- * incredibly familiar with our source code to exploit this - and currently there is nothing
15
- * they could gain from it)
16
- * @param {Object} app App object created in App.js
17
- * @param {string} stateString stringified JSON object representing state
18
- * @param {boolean} forceCreate if true, create any plugin entries if not found
19
- */
20
- function setStateFromStateString (config, stateString, forceCreate) {
21
- const state = JSON.parse(stateString);
22
-
23
- // Iterate through each state object, which has a plugin id and key/value state props
24
- Object.values(state).forEach(so => {
25
- let pluginConf = config.plugins[so.id];
26
- if (!pluginConf && forceCreate)
27
- pluginConf = config.plugins[so.id] = { };
28
- if (pluginConf) {
29
- const curDLP = pluginConf.deepLinkProps;
30
- if (!curDLP)
31
- pluginConf.deepLinkProps = so;
32
- else
33
- pluginConf.deepLinkProps = R.mergeDeepRight(curDLP, so);
34
- }
35
- });
36
-
37
- return config
38
- }
39
-
40
- export { setStateFromStateString };
1
+ import"query-string";import*as e from"ramda";import"zousan";function r(r,i,o){const p=JSON.parse(i);return Object.values(p).forEach((i=>{let p=r.plugins[i.id];if(!p&&o&&(p=r.plugins[i.id]={}),p){const r=p.deepLinkProps;p.deepLinkProps=r?e.mergeDeepRight(r,i):i}})),r}export{r as setStateFromStateString};
@@ -1,42 +1 @@
1
- var name = "SDK headless";
2
- var plugins = {
3
- analytics: {
4
- platformSdk: "SDK",
5
- active: false
6
- },
7
- analytics2: {
8
- productName: "LocusMaps JS SDK",
9
- active: false,
10
- disableSending: false
11
- },
12
- clientAPI: {
13
- },
14
- dynamicPois: {
15
- },
16
- poiDataManager: {
17
- },
18
- sdkServer: {
19
- },
20
- searchService: {
21
- },
22
- venueDataLoader: {
23
- assetStage: "prod",
24
- formatVersion: "v5",
25
- availableLanguages: [
26
- {
27
- langCode: "en",
28
- assetSuffix: ""
29
- }
30
- ]
31
- },
32
- wayfinder: {
33
- compareFindPaths: false
34
- }
35
- };
36
- var sdkHeadless = {
37
- name: name,
38
- plugins: plugins
39
- };
40
-
41
- export default sdkHeadless;
42
- export { name, plugins };
1
+ var a="SDK headless",e={analytics:{platformSdk:"SDK",active:!1},analytics2:{productName:"LocusMaps JS SDK",active:!1,disableSending:!1},clientAPI:{},dynamicPois:{},poiDataManager:{},sdkServer:{},searchService:{},venueDataLoader:{assetStage:"prod",formatVersion:"v5",availableLanguages:[{langCode:"en",assetSuffix:""}]},wayfinder:{compareFindPaths:!1}},s={name:"SDK headless",plugins:e};export{s as default,a as name,e as plugins};
@@ -1,45 +1 @@
1
- import IObject from 'IObject';
2
- import { create as create$1 } from './app.js';
3
-
4
- /**
5
- * This manages the creation and organization of your App instances.
6
- * Each instance is created via the create function - passing in a configuration
7
- * object, which extends any existing configuration template.
8
- */
9
-
10
- // IObject.freeze = 'DEEP'
11
-
12
- // This is a list of "instances" of your full app stack. Often this will be only one.
13
- // If you wish to give it a name, use the appName property. Else one will be assigned.
14
- let apps = new IObject();
15
-
16
- // The configuration template is used as the base configurationx for all app
17
- // instances. It can be set with setConfigTemplate
18
- const configTemplate = new IObject();
19
-
20
- const sendAlert = msg => typeof window !== 'undefined' ? window.alert(msg) : console.error(msg);
21
-
22
- /**
23
- * Create a new instance of the engine. Pass in a configuration object which will
24
- * extend the config template.
25
- * @param {} config Configuration for this instance. Will be shallow copied.
26
- */
27
- async function create (config) {
28
- if (!config) { throw Error('Attempt to create App instance with no configuration') }
29
-
30
- // Create a new immutable configuration based on the configuration template
31
- let myConfig = new IObject(Object.assign({}, configTemplate, config));
32
-
33
- // If no name was defined for this instance, create one.
34
- const appName = myConfig.appName || 'Instance' + (Object.keys(apps).length + 1);
35
- myConfig = myConfig.set('appName', appName);
36
-
37
- try {
38
- const app = await create$1(myConfig);
39
- // console.log('Got appInstance: ', app)
40
- apps = apps.set(appName, app);
41
- return app
42
- } catch (e) { console.error(e); e.message ? sendAlert(e.message) : sendAlert('Error creating map. Please try again later.'); }
43
- }
44
-
45
- export { create };
1
+ import e from"IObject";import{create as t}from"./app.js";let r=new e;const n=new e,a=e=>"undefined"!=typeof window?window.alert(e):console.error(e);async function o(o){if(!o)throw Error("Attempt to create App instance with no configuration");let s=new e(Object.assign({},n,o));const c=s.appName||"Instance"+(Object.keys(r).length+1);s=s.set("appName",c);try{const e=await t(s);return r=r.set(c,e),e}catch(e){console.error(e),e.message?a(e.message):a("Error creating map. Please try again later.")}}export{o as create};
@@ -1,108 +1 @@
1
- import * as R from 'ramda';
2
- import { orphanTest } from '../plugins/wayfinder/src/navGraphDebug.js';
3
- import { $, $$, ad } from './utils/dom.js';
4
- import { singleFile } from './utils/funcs.js';
5
-
6
- if (typeof window !== 'undefined')
7
- window.R = R; // helps use Rambda in console... probably don't want to do this once we integrate with customer content
8
-
9
- // NOTE:
10
- // The exported functions from this module all get placed into the app.debug (accessable from console via _app.debug) and bound to
11
- // the app instance. So the `this` context will contain the app instance when these are run. This allows you to access objects like
12
- // the bus via `this.bus` or configuration via `this.config`
13
- // Update: these are now also available in MoL by searching for `debug:<funcname>` - such as `debug:showIcons`
14
-
15
- const showIcons = () => { $('#mapRenderDiv').innerHTML = '<style> div { display: inline-block; text-align: center; border: 1px solid lightblue; }</style>' + $$('svg symbol').map(e => `<div><svg><use xlink:href="#${e.id}"/></svg><br/>${e.id}</div>`).join(''); };
16
-
17
- function poisByCategory () {
18
- return this.bus.send('poi/getAll')
19
- .then(r => r[0])
20
- .then(p => Object.values(p))
21
- .then(R.groupBy(o => o.category))
22
- }
23
-
24
- const highlightNodes = () => ad({ tag: 'style', html: '* { background-color: rgba(255,0,0,.2); } * * { background-color: rgba(0,255,0,.2); } * * * { background-color: rgba(0,0,255,.2); } * * * * { background-color: rgba(255,0,255,.2); } * * * * * { background-color: rgba(0,255,255,.2); } * * * * * * { background-color: rgba(255,255,0,.2); } * * * * * * * { background-color: rgba(255,0,0,.2); } * * * * * * * * { background-color: rgba(0,255,0,.2); } * * * * * * * * * { background-color: rgba(0,0,255,.2); }' }, $('head'));
25
-
26
- function getPoiById (id) {
27
- return this.bus.send('poi/getById', { id })
28
- .then(r => r[0])
29
- }
30
-
31
- async function showOrphaned () {
32
- const navGraph = await this.bus.get('wayfinder/_getNavGraph');
33
- const oob = orphanTest(navGraph._nodes);
34
- this.bus.send('map/showOrphanedGraphNodes', { orphanedNodes: oob.orphaned });
35
- }
36
-
37
- async function showgraph () {
38
- const navGraph = await this.bus.get('wayfinder/getNavGraphFeatures');
39
- this.bus.send('map/showNavGraphFeatures', { navGraph });
40
- monitorDebugFeaturesReset('map/resetNavGraphFeatures', this.bus);
41
- }
42
-
43
- async function bounds () {
44
- const venueCenter = await this.bus.get('venueData/getVenueCenter');
45
- const { venueRadius, bounds } = await this.bus.get('venueData/getVenueData');
46
- this.bus.send('map/showVenueBounds', { venueCenter, venueRadius, bounds });
47
- monitorDebugFeaturesReset('map/resetVenueBounds', this.bus);
48
- }
49
-
50
- async function padding () {
51
- this.bus.send('map/togglePadding');
52
- monitorDebugFeaturesReset('map/togglePadding', this.bus);
53
- }
54
-
55
- const monitorDebugFeaturesReset = (resetEventName, bus) => {
56
- const unsubscribe = bus.monitor('homeview/performSearch', ({ term }) => {
57
- if (!term) {
58
- bus.send(resetEventName);
59
- unsubscribe();
60
- }
61
- });
62
- };
63
-
64
- function dndGo () {
65
- const bus = this.bus;
66
- const toggleActive = (e, indicateDragVisual) => {
67
- e.preventDefault();
68
- if (indicateDragVisual)
69
- e.target.classList.add('dragover');
70
- else
71
- e.target.classList.remove('dragover');
72
- };
73
-
74
- const handlers = {
75
-
76
- drop: async function (e) {
77
- toggleActive(e, false);
78
-
79
- // Load the file into the player
80
- for (const file of e.dataTransfer.files) {
81
- const filename = file.name;
82
- if (file.type === 'application/json' || (file.type.startsWith('text/'))) {
83
- const reader = new FileReader();
84
- reader.onload = singleFile(async e =>
85
- bus.send(`debugTools/fileDrop`, { file, filename, content: e.target.result }));
86
- reader.readAsText(file);
87
- }
88
- }
89
- },
90
-
91
- // Drag-over event
92
- dragover: function (e) { toggleActive(e, true); },
93
-
94
- // Drag-leave event
95
- dragleave: function (e) { toggleActive(e, false); }
96
-
97
- }; // end of handlers def
98
-
99
- Object.keys(handlers).forEach(function (event) {
100
- document.body.addEventListener(event, handlers[event]);
101
- });
102
-
103
- console.log('DnD Listeners installed');
104
- } // end of function installDragNDrop
105
-
106
- var debugTools = { showIcons, poisByCategory, highlightNodes, getPoiById, orphanTest, showOrphaned, showgraph, dndGo, bounds, padding };
107
-
108
- export default debugTools;
1
+ import*as e from"ramda";import{orphanTest as n}from"../plugins/wayfinder/src/navGraphDebug.js";import{$ as s,$$ as t,ad as o}from"./utils/dom.js";import{singleFile as a}from"./utils/funcs.js";"undefined"!=typeof window&&(window.R=e);const r=(e,n)=>{const s=n.monitor("homeview/performSearch",(({term:t})=>{t||(n.send(e),s())}))};var i={showIcons:()=>{s("#mapRenderDiv").innerHTML="<style> div { display: inline-block; text-align: center; border: 1px solid lightblue; }</style>"+t("svg symbol").map((e=>`<div><svg><use xlink:href="#${e.id}"/></svg><br/>${e.id}</div>`)).join("")},poisByCategory:function(){return this.bus.send("poi/getAll").then((e=>e[0])).then((e=>Object.values(e))).then(e.groupBy((e=>e.category)))},highlightNodes:()=>o({tag:"style",html:"* { background-color: rgba(255,0,0,.2); } * * { background-color: rgba(0,255,0,.2); } * * * { background-color: rgba(0,0,255,.2); } * * * * { background-color: rgba(255,0,255,.2); } * * * * * { background-color: rgba(0,255,255,.2); } * * * * * * { background-color: rgba(255,255,0,.2); } * * * * * * * { background-color: rgba(255,0,0,.2); } * * * * * * * * { background-color: rgba(0,255,0,.2); } * * * * * * * * * { background-color: rgba(0,0,255,.2); }"},s("head")),getPoiById:function(e){return this.bus.send("poi/getById",{id:e}).then((e=>e[0]))},orphanTest:n,showOrphaned:async function(){const e=await this.bus.get("wayfinder/_getNavGraph"),s=n(e._nodes);this.bus.send("map/showOrphanedGraphNodes",{orphanedNodes:s.orphaned})},showgraph:async function(){const e=await this.bus.get("wayfinder/getNavGraphFeatures");this.bus.send("map/showNavGraphFeatures",{navGraph:e}),r("map/resetNavGraphFeatures",this.bus)},dndGo:function(){const e=this.bus,n=(e,n)=>{e.preventDefault(),n?e.target.classList.add("dragover"):e.target.classList.remove("dragover")},s={drop:async function(s){n(s,!1);for(const n of s.dataTransfer.files){const s=n.name;if("application/json"===n.type||n.type.startsWith("text/")){const t=new FileReader;t.onload=a((async t=>e.send("debugTools/fileDrop",{file:n,filename:s,content:t.target.result}))),t.readAsText(n)}}},dragover:function(e){n(e,!0)},dragleave:function(e){n(e,!1)}};Object.keys(s).forEach((function(e){document.body.addEventListener(e,s[e])})),console.log("DnD Listeners installed")},bounds:async function(){const e=await this.bus.get("venueData/getVenueCenter"),{venueRadius:n,bounds:s}=await this.bus.get("venueData/getVenueData");this.bus.send("map/showVenueBounds",{venueCenter:e,venueRadius:n,bounds:s}),r("map/resetVenueBounds",this.bus)},buildingBounds:async function(e){this.bus.send("map/showBuildingBounds",{nameFilter:e}),r("map/resetVenueBounds",this.bus)},padding:async function(){this.bus.send("map/togglePadding"),r("map/togglePadding",this.bus)}};export{i as default};
package/lib/src/env.js CHANGED
@@ -1,17 +1 @@
1
- function buildEnv (app) {
2
- const desktopViewMinWidth = app.config.desktopViewMinWidth || 0; // default to desktop view for all sizes
3
- const isBrowser = typeof window !== 'undefined';
4
-
5
- const env = {
6
- isBrowser,
7
- isMobile: () => isBrowser && innerWidth < desktopViewMinWidth,
8
- isDesktop: () => isBrowser && !env.isMobile()
9
- };
10
-
11
- if (isBrowser)
12
- window.addEventListener('resize', () => app.bus.send('env/resize'));
13
-
14
- return env
15
- }
16
-
17
- export { buildEnv };
1
+ function e(e){const i=e.config.desktopViewMinWidth||0,n="undefined"!=typeof window,s={isBrowser:n,isMobile:()=>n&&innerWidth<i,isDesktop:()=>n&&!s.isMobile()};return n&&window.addEventListener("resize",(()=>e.bus.send("env/resize"))),s}export{e as buildEnv};
@@ -1,126 +1 @@
1
- import Zousan from 'zousan';
2
-
3
- /**
4
- * Bustle is a highly performant event bus that offers event order guarantees.
5
- */
6
-
7
- // Remove element from array at index specified and return the removed element.
8
- // Source array will then have item removed.
9
- const arRmAt = (ar, index) => ar.splice(index, 1)[0]; // oh yah, thats intuitive!
10
-
11
- // Removes the value from the array if it exists. The array is then returned
12
- const arRm = (ar, value) => {
13
- let i = 0;
14
- do {
15
- i = ar.indexOf(value, i);
16
- if (i >= 0)
17
- arRmAt(ar, i);
18
- } while (i >= 0)
19
- return ar
20
- };
21
-
22
- // This creates a bus instance. When used as a Singleton, you will only call this once
23
- // for the life of your app. To isolate events (perhaps for performance or security
24
- // reasons) you can create multple bus instances.
25
- function create (opts = { }) {
26
- // If a log option is defined, use it - and if it supports sublogs, instantiate that. If all else fails, use console
27
- const log = opts.log ? (opts.log.sublog ? opts.log.sublog('bustle', { color: 'pink' }) : opts.log) : console;
28
-
29
- const ons = { }; // holds your listeners
30
- const mons = { }; // holds your monitors
31
-
32
- // subscribes to an event. Your listener will always be called
33
- // with a single argument. I am considering adding another way
34
- // to subscribe to events by observing an event and then
35
- // subscribing to that observer.
36
- function on (ev, fn) {
37
- if (!ons[ev])
38
- ons[ev] = [];
39
-
40
- ons[ev].push(fn);
41
-
42
- return () => off(ev, fn)
43
- }
44
-
45
- // Similar to "on" but is always called after all normal "on" listeners,
46
- // and any values returned by a monitor call are ignored (not added to the
47
- // response). Also, any calls to monitor listeners contains both the message
48
- // object AND a promise containing the response from the normal listeners.
49
- function monitor (ev, fn) {
50
- if (!mons[ev])
51
- mons[ev] = [];
52
-
53
- mons[ev].push(fn);
54
-
55
- return () => moff(ev, fn)
56
- }
57
-
58
- function off (ev, fn) {
59
- if (!ons[ev])
60
- return
61
- arRm(ons[ev], fn);
62
- }
63
-
64
- function moff (ev, fn) {
65
- if (!mons[ev])
66
- return
67
- arRm(mons[ev], fn);
68
- }
69
-
70
- const serve = (ev, ob, done) => () => {
71
- // const myOns = (ons[ev] || []).concat(ons["*"] ? ons["*"] : [])
72
- const myOns = ons[ev];
73
- const myMons = mons[ev];
74
- const res = [];
75
- if (myOns) {
76
- for (const listener of myOns) {
77
- try {
78
- res.push(listener(ob));
79
- } catch (err) {
80
- if (opts.reportAllErrors) log.error(err);
81
- if (opts.rejectOnError) res.push(Zousan.reject(err));
82
- res.push(err);
83
- }
84
- }
85
- }
86
-
87
- const results = Zousan.all(res);
88
-
89
- if (myMons) {
90
- for (const listener of myMons) {
91
- try {
92
- listener(ob, results);
93
- } catch (err) {
94
- if (opts.reportAllErrors)
95
- log.error(err);
96
- }
97
- }
98
- }
99
-
100
- done(results);
101
- };
102
-
103
- // Used when there is a single listener that provides information or a service,
104
- // a get sends a message to that listener, ensures it gets exactly 1 result,
105
- // and returns that result.
106
- const get = (ev, ob) =>
107
- send(ev, ob).then(res => res.length !== 1
108
- ? Zousan.reject(`${ev} event did not return a single result, but ${res.length} results.`)
109
- : res[0]);
110
-
111
- function send (ev, ob) {
112
- if (opts.trace) { if (!ob) ob = { }; ob._stack = Error().stack; }
113
- if (opts.showEvents) {
114
- if (typeof opts.showEvents === 'function') {
115
- if (opts.showEvents(ev, ob))
116
- log.info('send with', ev, ' and ', ob);
117
- } else
118
- log.info('send with', ev, ' and ', ob);
119
- }
120
- return new Zousan(resolve => Zousan.soon(serve(ev, ob, resolve)))
121
- }
122
-
123
- return { get, moff, monitor, off, on, send }
124
- }
125
-
126
- export { create };
1
+ import o from"zousan";const n=(o,n)=>o.splice(n,1)[0],t=(o,t)=>{let r=0;do{r=o.indexOf(t,r),r>=0&&n(o,r)}while(r>=0);return o};function r(n={}){const r=n.log?n.log.sublog?n.log.sublog("bustle",{color:"pink"}):n.log:console,e={},s={};function c(o,n){e[o]&&t(e[o],n)}function u(o,n){s[o]&&t(s[o],n)}function l(t,c){return n.trace&&(c||(c={}),c._stack=Error().stack),n.showEvents&&("function"==typeof n.showEvents?n.showEvents(t,c)&&r.info("send with",t," and ",c):r.info("send with",t," and ",c)),new o((u=>o.soon(((t,c,u)=>()=>{const l=e[t],f=s[t],i=[];if(l)for(const t of l)try{i.push(t(c))}catch(t){n.reportAllErrors&&r.error(t),n.rejectOnError&&i.push(o.reject(t)),i.push(t)}const h=o.all(i);if(f)for(const o of f)try{o(c,h)}catch(o){n.reportAllErrors&&r.error(o)}u(h)})(t,c,u))))}return{get:(n,t)=>l(n,t).then((t=>1!==t.length?o.reject(`${n} event did not return a single result, but ${t.length} results.`):t[0])),moff:u,monitor:function(o,n){return s[o]||(s[o]=[]),s[o].push(n),()=>u(o,n)},off:c,on:function(o,n){return e[o]||(e[o]=[]),e[o].push(n),()=>c(o,n)},send:l}}export{r as create};
@@ -1,21 +1 @@
1
- function pad (total, str) {
2
- while (str.length < total) { str += ' '; }
3
- return str
4
- }
5
-
6
- const getHelpHeader = () => pad(18, 'Command') + 'Arguments\n' + pad(18, '----------------') + '----------------\n';
7
-
8
- /**
9
- * Returns help on the passed command signature
10
- */
11
- const getHelp = sig => pad(18, sig.command) +
12
- (sig.args ? sig.args.map(argob => `${argob.name} {${argob.type}} ${argob.optional ? ' (optional)' : ' (required)'}`).join(', ') : '');
13
-
14
- /**
15
- * Returns help on the passed command signatures
16
- */
17
- const getHelpList = sigList => {
18
- return sigList.reduce((ret, sig) => `${ret}${getHelp(sig)}\n`, getHelpHeader())
19
- };
20
-
21
- export { getHelp, getHelpHeader, getHelpList };
1
+ function n(n,o){for(;o.length<n;)o+=" ";return o}const o=()=>n(18,"Command")+"Arguments\n"+n(18,"----------------")+"----------------\n",e=o=>n(18,o.command)+(o.args?o.args.map((n=>`${n.name} {${n.type}} ${n.optional?" (optional)":" (required)"}`)).join(", "):""),r=n=>n.reduce(((n,o)=>`${n}${e(o)}\n`),o());export{e as getHelp,o as getHelpHeader,r as getHelpList};
@@ -1,66 +1 @@
1
- import Zousan from 'zousan';
2
- import { getHelpList, getHelpHeader, getHelp } from './help.js';
3
- import { getSigMatch, validate } from './validate.js';
4
-
5
- const COMMAND_VALIDATION_REGEX = /^[-_.0-9a-zA-Z]+$/;
6
- const JS = JSON.stringify;
7
-
8
- const commandDefsList = [];
9
- const commands = () => commandDefsList.map(cob => cob.sig);
10
- const customTypes = { };
11
- const library = { customTypes, commandDefsList };
12
- const getCommandJSON = () => ({ commands: commands(), customTypes });
13
-
14
- function registerCommand (sig, fn) {
15
- const command = sig.command;
16
- if (command === undefined) { throw Error(`Invalid command specification in registerCommand: ${JS(sig)}. No 'command' property specified.`) }
17
-
18
- if (!COMMAND_VALIDATION_REGEX.test(command)) {
19
- const er = Error(`Invalid command specification in registerCommand: ${JS(sig)}. Command name '${command}' not valid.`);
20
- throw er
21
- }
22
-
23
- commandDefsList.push({ sig, fn });
24
-
25
- return execute
26
- }
27
-
28
- function registerCustomType (name, spec) {
29
- customTypes[name] = spec;
30
- }
31
-
32
- function clearCommands () {
33
- commandDefsList.length = 0;
34
- registerCommand({ command: 'help', args: [] }, () => getHelpList(commands()));
35
- registerCommand({ command: 'getCommandJSON', args: [] }, getCommandJSON);
36
- }
37
-
38
- function execute (cob) {
39
- return new Zousan((resolve, reject) => {
40
- if (!cob) { return reject(new Error(`No command specified in command object ${JS(cob)}`)) }
41
-
42
- const commandMatches = library.commandDefsList
43
- .filter(com => com.sig.command === cob.command);
44
-
45
- if (commandMatches.length === 0) { return reject(new Error(`No API command '${cob.command}' found.\n${getHelpList(library.commandDefsList.map(o => o.sig))}`)) }
46
-
47
- const sigMatch = getSigMatch(library, cob);
48
-
49
- if (!sigMatch) {
50
- if (commandMatches.length === 1) { return reject(new Error(`Required fields not present in ${JS(cob)}\n${getHelpHeader()}${getHelp(commandMatches[0].sig)}`)) } else { return reject(new Error(`Command arguments did not match any required signatures: ${JS(cob)}\n${getHelpList(library.commandDefsList.map(o => o.sig))}`)) }
51
- }
52
-
53
- // console.log(`command ${JS(cob)} is ${JS(sigMatch.sig)}`)
54
-
55
- try {
56
- validate(library, sigMatch.sig, cob); // this will throw an error if invalid
57
- } catch (e) { return reject(e) }
58
-
59
- resolve(sigMatch.fn(cob));
60
- })
61
- }
62
-
63
- registerCommand({ command: 'help', args: [] }, () => getHelpList(commands()));
64
- registerCommand({ command: 'getCommandJSON', args: [] }, getCommandJSON);
65
-
66
- export { clearCommands, execute, registerCommand, registerCustomType };
1
+ import n from"zousan";import{getHelpList as o,getHelpHeader as r,getHelp as m}from"./help.js";import{getSigMatch as e,validate as t}from"./validate.js";const i=/^[-_.0-9a-zA-Z]+$/,s=JSON.stringify;function a(){const a=[],c=()=>a.map((n=>n.sig)),d={},f={customTypes:d,commandDefsList:a};function u(n,o){const r=n.command;if(void 0===r)throw Error(`Invalid command specification in registerCommand: ${s(n)}. No 'command' property specified.`);if(!i.test(r)){throw Error(`Invalid command specification in registerCommand: ${s(n)}. Command name '${r}' not valid.`)}return a.push({sig:n,fn:o}),p}function p(i){return new n(((n,a)=>{if(!i)return a(new Error(`No command specified in command object ${s(i)}`));const c=f.commandDefsList.filter((n=>n.sig.command===i.command));if(0===c.length)return a(new Error(`No API command '${i.command}' found.\n${o(f.commandDefsList.map((n=>n.sig)))}`));const d=e(f,i);if(!d)return 1===c.length?a(new Error(`Required fields not present in ${s(i)}\n${r()}${m(c[0].sig)}`)):a(new Error(`Command arguments did not match any required signatures: ${s(i)}\n${o(f.commandDefsList.map((n=>n.sig)))}`));try{t(f,d.sig,i)}catch(n){return a(n)}n(d.fn(i))}))}return u({command:"help",args:[]},(()=>o(c()))),u({command:"getCommandJSON",args:[]},(()=>({commands:c(),customTypes:d}))),{registerCommand:u,registerCustomType:function(n,o){d[n]=o},execute:p}}export{a as default};