@emuanalytics/flow-rdf-core 4.0.3 → 4.0.5

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 (89) hide show
  1. package/README.md +1 -64
  2. package/dist/index.d.mts +36 -31
  3. package/dist/index.d.ts +36 -31
  4. package/dist/index.mjs +20 -3249
  5. package/dist/lib/context/context-registry.mjs +63 -0
  6. package/dist/lib/context/debugger.mjs +240 -0
  7. package/dist/lib/context/flow-context.mjs +61 -0
  8. package/dist/lib/context/global-state.mjs +70 -0
  9. package/dist/lib/context/map-registry.mjs +59 -0
  10. package/dist/lib/context/query-registry.mjs +53 -0
  11. package/dist/lib/errors/flow-error.mjs +10 -0
  12. package/dist/lib/errors/flow-expression-error.mjs +14 -0
  13. package/dist/lib/errors/flow-map-error.mjs +9 -0
  14. package/dist/lib/expressions/expression-parser.mjs +198 -0
  15. package/dist/lib/expressions/functions/from-palette.mjs +75 -0
  16. package/dist/lib/expressions/functions/regex.mjs +25 -0
  17. package/dist/lib/expressions/functions/state.mjs +25 -0
  18. package/dist/lib/expressions/parser-helpers.mjs +37 -0
  19. package/dist/lib/expressions/reactive-expression.mjs +253 -0
  20. package/dist/lib/map/flow-core-map.mjs +749 -0
  21. package/dist/lib/map/plugins/annotations/annotation-layers.mjs +163 -0
  22. package/dist/lib/map/plugins/annotations/annotation.events.mjs +27 -0
  23. package/dist/lib/map/plugins/annotations/annotation.plugin.mjs +498 -0
  24. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DirectModeOverride.mjs +67 -0
  25. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DragCircleMode.mjs +65 -0
  26. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/create_supplementary_points_circle.mjs +15 -0
  27. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/drag_pan.mjs +20 -0
  28. package/dist/lib/map/plugins/data-join.plugin.mjs +173 -0
  29. package/dist/lib/map/plugins/export/export.plugin.mjs +21 -0
  30. package/dist/lib/map/plugins/export/map-exporter.mjs +177 -0
  31. package/dist/lib/map/plugins/hover-effect.plugin.mjs +58 -0
  32. package/dist/lib/map/plugins/index.d.mts +37 -72
  33. package/dist/lib/map/plugins/index.d.ts +37 -72
  34. package/dist/lib/map/plugins/index.mjs +11 -1811
  35. package/dist/lib/map/plugins/keyboard-shortcut-manager.mjs +120 -0
  36. package/dist/lib/map/plugins/map-plugin-base.mjs +25 -0
  37. package/dist/lib/map/plugins/plugin-manager.mjs +135 -0
  38. package/dist/lib/map/plugins/popup.plugin.mjs +55 -0
  39. package/dist/lib/map/plugins/selection/selection.events.mjs +21 -0
  40. package/dist/lib/map/plugins/selection/selection.plugin.mjs +136 -0
  41. package/dist/lib/map/plugins/selection/source-selection.mjs +156 -0
  42. package/dist/lib/map/plugins/url-sync.plugin.mjs +55 -0
  43. package/dist/lib/map/support/image-registry.mjs +82 -0
  44. package/dist/lib/map/support/map-events.mjs +71 -0
  45. package/dist/lib/map/support/map-feature-stream.mjs +158 -0
  46. package/dist/lib/map/support/map-popup.mjs +159 -0
  47. package/dist/lib/map/types.mjs +7 -0
  48. package/dist/lib/map-style/map-data-source.mjs +192 -0
  49. package/dist/lib/map-style/map-layer-style-builder-generated.mjs +1307 -0
  50. package/dist/lib/map-style/map-layer-style-builder.mjs +86 -0
  51. package/dist/lib/map-style/map-layer.mjs +223 -0
  52. package/dist/lib/map-style/map-style.mjs +178 -0
  53. package/dist/lib/queries/async-committer.mjs +30 -0
  54. package/dist/lib/queries/query.mjs +172 -0
  55. package/dist/lib/state-store/decorators.mjs +83 -0
  56. package/dist/lib/state-store/state-store.mjs +534 -0
  57. package/dist/lib/state-store/utils.mjs +7 -0
  58. package/dist/lib/utils/announce.mjs +12 -0
  59. package/dist/lib/utils/assert.mjs +12 -0
  60. package/dist/{shared/flow-rdf-core.187cb345.mjs → lib/utils/debounce.mjs} +3 -39
  61. package/dist/lib/utils/decorators.mjs +59 -0
  62. package/dist/lib/utils/deferred.mjs +11 -0
  63. package/dist/lib/utils/ensure-array.mjs +16 -0
  64. package/dist/{shared/flow-rdf-core.1f0901c5.mjs → lib/utils/feature-type-checks.mjs} +2 -2
  65. package/dist/lib/utils/functional.mjs +22 -0
  66. package/dist/lib/utils/global.mjs +18 -0
  67. package/dist/lib/utils/index.mjs +8 -5
  68. package/dist/lib/utils/random-id.mjs +9 -0
  69. package/dist/lib/utils/string-utils.mjs +3 -0
  70. package/dist/lib/utils/throttle.mjs +20 -0
  71. package/dist/{shared/flow-rdf-core.25e5f6d7.mjs → lib/utils/type-checks.mjs} +1 -26
  72. package/dist/lib/utils/watchable-promise.mjs +55 -0
  73. package/dist/package.json.mjs +3 -0
  74. package/dist/shared/{flow-rdf-core.4dde996e.d.cts → flow-rdf-core.8b5acf14.d.mts} +1315 -172
  75. package/dist/shared/{flow-rdf-core.4dde996e.d.ts → flow-rdf-core.8b5acf14.d.ts} +1315 -172
  76. package/package.json +4 -8
  77. package/dist/index.cjs +0 -3316
  78. package/dist/index.d.cts +0 -90
  79. package/dist/lib/map/plugins/index.cjs +0 -1851
  80. package/dist/lib/map/plugins/index.d.cts +0 -345
  81. package/dist/lib/utils/index.cjs +0 -48
  82. package/dist/lib/utils/index.d.cts +0 -160
  83. package/dist/shared/flow-rdf-core.06e85a6c.cjs +0 -1394
  84. package/dist/shared/flow-rdf-core.4dde996e.d.mts +0 -1916
  85. package/dist/shared/flow-rdf-core.55c169ca.cjs +0 -150
  86. package/dist/shared/flow-rdf-core.63162669.d.cts +0 -10
  87. package/dist/shared/flow-rdf-core.65045caf.mjs +0 -1360
  88. package/dist/shared/flow-rdf-core.a82b9be4.cjs +0 -34
  89. package/dist/shared/flow-rdf-core.f50908f0.cjs +0 -102
@@ -0,0 +1,192 @@
1
+ import * as mobx from 'mobx';
2
+ import { isIn, isString, isStringFull, isNil, isURL } from '../utils/type-checks.mjs';
3
+ import { FlowCoreError } from '../errors/flow-error.mjs';
4
+ import { ReactiveExpression } from '../expressions/reactive-expression.mjs';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => {
9
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ return value;
11
+ };
12
+ const _MapDataSource = class _MapDataSource {
13
+ constructor(options) {
14
+ __publicField(this, "_options");
15
+ __publicField(this, "_srcExpression", null);
16
+ __publicField(this, "_parameters", {});
17
+ __publicField(this, "_state", null);
18
+ this._options = {
19
+ ..._MapDataSource.defaultOptions,
20
+ ...options
21
+ };
22
+ if (!isIn(options.type, ["vector", "geojson", "raster"])) {
23
+ throw new FlowCoreError(`${this.formattedName()}: unrecognized type '${options.type}'`);
24
+ }
25
+ this.setSrcExpression(options.src);
26
+ mobx.makeObservable(
27
+ this,
28
+ {
29
+ //observable
30
+ _options: mobx.observable.shallow,
31
+ _srcExpression: mobx.observable,
32
+ _parameters: mobx.observable,
33
+ //computed
34
+ dataSourceSpecification: mobx.computed,
35
+ // actions
36
+ bindState: mobx.action,
37
+ setSrc: mobx.action,
38
+ setParameter: mobx.action
39
+ },
40
+ { name: this.formattedName(options.id) }
41
+ );
42
+ }
43
+ get id() {
44
+ return this._options.id;
45
+ }
46
+ get type() {
47
+ return this._options.type;
48
+ }
49
+ get featureId() {
50
+ return this._options.featureId;
51
+ }
52
+ get dataSourceSpecification() {
53
+ let src = this._srcExpression ? mobx.toJS(this._srcExpression.value) : this._options.src;
54
+ if (isString(src)) {
55
+ src = this.expandSrc(src, this._options.type);
56
+ }
57
+ let ds;
58
+ switch (this._options.type) {
59
+ case "vector":
60
+ ds = isStringFull(src) ? {
61
+ type: "vector",
62
+ url: src
63
+ } : (
64
+ // For null src use an empty geojson datasource as a placeholder
65
+ {
66
+ type: "geojson",
67
+ data: { type: "FeatureCollection", features: [] }
68
+ }
69
+ );
70
+ if (this._options.featureId) {
71
+ ds.promoteId = this._options.featureId;
72
+ }
73
+ return ds;
74
+ case "raster":
75
+ ds = isStringFull(src) ? {
76
+ type: "raster",
77
+ url: src
78
+ } : (
79
+ // For null src use an empty geojson datasource as a placeholder
80
+ {
81
+ type: "geojson",
82
+ data: { type: "FeatureCollection", features: [] }
83
+ }
84
+ );
85
+ return ds;
86
+ case "geojson":
87
+ ds = {
88
+ type: "geojson",
89
+ data: src || { type: "FeatureCollection", features: [] }
90
+ };
91
+ if (this._options.cluster) {
92
+ ds.cluster = true;
93
+ ds.clusterMaxZoom = this._options.clusterMaxZoom;
94
+ ds.clusterMinPoints = this._options.clusterMinPoints;
95
+ ds.clusterRadius = this._options.clusterRadius;
96
+ }
97
+ if (this._options.featureId) {
98
+ ds.promoteId = this._options.featureId;
99
+ }
100
+ return ds;
101
+ default:
102
+ throw new FlowCoreError(`${this.formattedName()}: unrecognized type '${this._options.type}'`);
103
+ }
104
+ }
105
+ bindState(state) {
106
+ this._state = state;
107
+ if (this._srcExpression) {
108
+ this._srcExpression?.bindState(state);
109
+ }
110
+ Object.values(this._parameters).forEach((expr) => expr.bindState(state));
111
+ return this;
112
+ }
113
+ setSrc(val) {
114
+ this._options.src = val;
115
+ this.setSrcExpression(val);
116
+ }
117
+ setParameter(name, expression) {
118
+ if (isNil(expression)) {
119
+ delete this._parameters[name];
120
+ } else {
121
+ const expr = new ReactiveExpression(expression);
122
+ this._parameters[name] = expr.bindState(this._state);
123
+ }
124
+ }
125
+ setFlowEndpoint(endpoint) {
126
+ this._options.flowHost = endpoint.host;
127
+ this._options.flowApiKey = endpoint.apiKey;
128
+ }
129
+ formattedName(id) {
130
+ return `MapDataSource<${id || this._options.id}>`;
131
+ }
132
+ setSrcExpression(src) {
133
+ if (isString(src)) {
134
+ if (isURL(src))
135
+ src = `'${src}'`;
136
+ this._srcExpression = new ReactiveExpression(src);
137
+ this._srcExpression.bindState(this._state);
138
+ } else {
139
+ this._srcExpression = null;
140
+ }
141
+ }
142
+ /**
143
+ * Convert a src parameter to final URL
144
+ *
145
+ * @param src Data source url/dataset/tilesource ID
146
+ * @param type Data source type
147
+ * @returns URL
148
+ */
149
+ expandSrc(src, type) {
150
+ const host = this._options.flowHost;
151
+ let isGeoJSON = false;
152
+ if (!isURL(src)) {
153
+ switch (type) {
154
+ case "vector":
155
+ case "raster":
156
+ src = `${host}/tiles/${src}/index.json`;
157
+ break;
158
+ case "geojson":
159
+ src = `${host}/api/v1/datasets/${src}/query`;
160
+ isGeoJSON = true;
161
+ break;
162
+ default:
163
+ throw new FlowCoreError(`${this.formattedName()}: unrecognized type '${this._options.type}'`);
164
+ }
165
+ }
166
+ const urlObj = new URL(src);
167
+ const combinedParams = new URLSearchParams(urlObj.searchParams);
168
+ Object.entries(this._parameters).filter(([_, expr]) => !isNil(expr.value)).forEach(([key, expr]) => combinedParams.append(key, expr.value));
169
+ if (this._options.flowHost && src.startsWith(this._options.flowHost) && !combinedParams.has("apikey") && this._options.flowApiKey) {
170
+ combinedParams.append("apikey", this._options.flowApiKey);
171
+ }
172
+ if (this._options.limit) {
173
+ combinedParams.append("limit", this._options.limit.toString(10));
174
+ }
175
+ if (isGeoJSON) {
176
+ combinedParams.append("format", "geojson");
177
+ }
178
+ urlObj.search = combinedParams.toString();
179
+ return urlObj.toString();
180
+ }
181
+ };
182
+ __publicField(_MapDataSource, "defaultOptions", {
183
+ type: "vector",
184
+ cluster: false,
185
+ clusterRadius: 50,
186
+ clusterMaxZoom: 20,
187
+ clusterMinPoints: 2,
188
+ flowHost: "https://flow.emu-analytics.net"
189
+ });
190
+ let MapDataSource = _MapDataSource;
191
+
192
+ export { MapDataSource };