@bino-bi/bn-template-engine 1.0.0-alpha.11 → 1.0.0-alpha.13
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.
- package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
- package/dist/bn-template-engine/p-3c827826.entry.js +1 -0
- package/dist/bn-template-engine/p-46699464.entry.js +1 -0
- package/dist/bn-template-engine/{p-e783733e.entry.js → p-52097456.entry.js} +1 -1
- package/dist/bn-template-engine/p-637e3b8f.entry.js +1 -0
- package/dist/bn-template-engine/{p-c2cbb8ea.entry.js → p-67eae33e.entry.js} +1 -1
- package/dist/bn-template-engine/{p-fdb3e99a.entry.js → p-82023539.entry.js} +1 -1
- package/dist/bn-template-engine/p-BVFHvEXF.js +1 -0
- package/dist/bn-template-engine/p-BjBz5cSL.js +1 -0
- package/dist/bn-template-engine/p-CQnZV3JG.js +1 -0
- package/dist/bn-template-engine/p-DHheVOfP.js +1 -0
- package/dist/bn-template-engine/{p-e94b4e31.entry.js → p-ab3ea8cf.entry.js} +1 -1
- package/dist/cjs/bn-asset_21.cjs.entry.js +576 -730
- package/dist/cjs/bn-grid.cjs.entry.js +2 -2
- package/dist/cjs/bn-image.cjs.entry.js +2 -2
- package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/bn-text.cjs.entry.js +3 -3
- package/dist/cjs/bn-tree.cjs.entry.js +2 -2
- package/dist/cjs/context-protocol-Op7uUwN3.js +9214 -0
- package/dist/cjs/editor-companion.cjs.entry.js +13 -6
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{scaling-eyzCrFB8.js → scaling-57N4Cxb_.js} +44 -40
- package/dist/cjs/{withBodyObserver-D7BKWN2N.js → withBodyObserver-BKUE_ypL.js} +12 -7
- package/dist/cjs/withStyled-C2kmGAK3.js +1405 -0
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +11 -6
- package/dist/collection/components/bn-chart-structure/ibcs-chart-structure.js +50 -22
- package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +51 -48
- package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +5 -4
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +11 -6
- package/dist/collection/components/bn-chart-time/ibcs-chart-time.js +47 -22
- package/dist/collection/components/bn-chart-time/utils/TimeChart.js +76 -60
- package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +5 -4
- package/dist/collection/components/bn-chart-time/utils/model/TimeChartDataRow.js +2 -0
- package/dist/collection/components/bn-dataset/bn-dataset.js +214 -23
- package/dist/collection/components/bn-datasource/bn-datasource.js +27 -9
- package/dist/collection/components/bn-table/bn-table.js +13 -5
- package/dist/collection/components/bn-table/ibcs-table.js +52 -25
- package/dist/collection/components/bn-table/utils/Table.js +27 -21
- package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +2 -2
- package/dist/collection/components/bn-table/utils/helper/DataQuery.js +52 -43
- package/dist/collection/components/bn-table/utils/helper/QueryGroup.js +4 -9
- package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +5 -4
- package/dist/collection/components/editor-companion/editor-companion.js +12 -5
- package/dist/collection/context/scopedDb.js +113 -0
- package/dist/collection/stores/createScopedStores.js +3 -4
- package/dist/collection/utils/dataAnalyzer.js +14 -8
- package/dist/collection/utils/withBodyObserver.js +12 -7
- package/dist/collection/utils/withDataset.js +43 -39
- package/dist/collection/utils/withDatasource.js +28 -18
- package/dist/components/DataFormatDigits.js +1 -1
- package/dist/components/DateStringFactory.js +1 -1
- package/dist/components/Order.js +1 -1
- package/dist/components/SVGVariancesStyleGroup.js +1 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-dataset.js +1 -1
- package/dist/components/bn-datasource.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-title2.js +1 -1
- package/dist/components/context-protocol.js +1 -1
- package/dist/components/editor-companion.js +1 -1
- package/dist/components/ibcs-chart-structure2.js +1 -1
- package/dist/components/ibcs-chart-time2.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/components/ibcs-title2.js +1 -1
- package/dist/components/ibcsRuleSet.js +1 -1
- package/dist/components/luxon.js +1 -0
- package/dist/components/scaling.js +1 -1
- package/dist/components/withBodyObserver.js +1 -1
- package/dist/esm/bn-asset_21.entry.js +571 -725
- package/dist/esm/bn-grid.entry.js +2 -2
- package/dist/esm/bn-image.entry.js +2 -2
- package/dist/esm/bn-internationalization.entry.js +2 -2
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/bn-text.entry.js +3 -3
- package/dist/esm/bn-tree.entry.js +2 -2
- package/dist/esm/context-protocol-BDhzNbeD.js +9204 -0
- package/dist/esm/editor-companion.entry.js +13 -6
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{scaling-BzbiBnuN.js → scaling-La1Ow72h.js} +44 -40
- package/dist/esm/{withBodyObserver-AFk2wwHT.js → withBodyObserver-IokS6fHD.js} +12 -7
- package/dist/esm/withStyled-Bl9cSoRW.js +1372 -0
- package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +4 -2
- package/dist/types/components/bn-chart-structure/ibcs-chart-structure.d.ts +7 -3
- package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +11 -12
- package/dist/types/components/bn-chart-structure/utils/model/StructureChartComponentConfig.d.ts +5 -3
- package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +4 -2
- package/dist/types/components/bn-chart-time/ibcs-chart-time.d.ts +7 -3
- package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +11 -12
- package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +5 -3
- package/dist/types/components/bn-dataset/bn-dataset.d.ts +39 -5
- package/dist/types/components/bn-datasource/bn-datasource.d.ts +5 -0
- package/dist/types/components/bn-table/bn-table.d.ts +4 -2
- package/dist/types/components/bn-table/ibcs-table.d.ts +11 -3
- package/dist/types/components/bn-table/utils/Table.d.ts +8 -6
- package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +2 -2
- package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +7 -3
- package/dist/types/components/bn-table/utils/helper/QueryGroup.d.ts +4 -5
- package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +5 -3
- package/dist/types/components/editor-companion/editor-companion.d.ts +2 -0
- package/dist/types/components.d.ts +105 -46
- package/dist/types/context/context-protocol.d.ts +4 -3
- package/dist/types/context/scopedDb.d.ts +37 -0
- package/dist/types/stores/createScopedStores.d.ts +1 -2
- package/dist/types/utils/DateStringFactory.d.ts +1 -1
- package/dist/types/utils/dataAnalyzer.d.ts +2 -1
- package/dist/types/utils/withDataset.d.ts +6 -2
- package/dist/types/utils/withDatasource.d.ts +3 -3
- package/package.json +2 -1
- package/dist/bn-template-engine/p-095f74d7.entry.js +0 -1
- package/dist/bn-template-engine/p-14318b0d.entry.js +0 -1
- package/dist/bn-template-engine/p-2133e02b.entry.js +0 -1
- package/dist/bn-template-engine/p-7HSTE79g.js +0 -1
- package/dist/bn-template-engine/p-Bi2wx-el.js +0 -1
- package/dist/bn-template-engine/p-CWiZks2h.js +0 -1
- package/dist/bn-template-engine/p-DSXNgKLa.js +0 -1
- package/dist/cjs/context-protocol-B_jipZpJ.js +0 -665
- package/dist/cjs/withStyled-V7xz_x1c.js +0 -9535
- package/dist/collection/stores/datasets.js +0 -14
- package/dist/collection/stores/datasources.js +0 -14
- package/dist/components/_commonjsHelpers.js +0 -1
- package/dist/components/alasql.min.js +0 -1
- package/dist/esm/context-protocol-D-o_UZ33.js +0 -658
- package/dist/esm/withStyled-5RqF8WBL.js +0 -9501
- package/dist/types/stores/datasets.d.ts +0 -14
- package/dist/types/stores/datasources.d.ts +0 -14
|
@@ -23,8 +23,7 @@ export class EditorCompanion {
|
|
|
23
23
|
if (this.distinctCache.has(cacheKey)) {
|
|
24
24
|
return Promise.resolve(this.distinctCache.get(cacheKey));
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
const result = this.distinct(this.stores.datasources.get(dataSourceName) || [], key);
|
|
26
|
+
const result = this.distinct(this.queryRows(dataSourceName), key);
|
|
28
27
|
this.distinctCache.set(cacheKey, result);
|
|
29
28
|
return Promise.resolve(result);
|
|
30
29
|
}
|
|
@@ -33,13 +32,21 @@ export class EditorCompanion {
|
|
|
33
32
|
if (this.distinctCache.has(cacheKey)) {
|
|
34
33
|
return Promise.resolve(this.distinctCache.get(cacheKey));
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
const result = this.distinct(this.stores.datasets.get(datasetName) || [], key);
|
|
35
|
+
const result = this.distinct(this.queryRows(datasetName), key);
|
|
38
36
|
this.distinctCache.set(cacheKey, result);
|
|
39
37
|
return Promise.resolve(result);
|
|
40
38
|
}
|
|
41
39
|
render() {
|
|
42
|
-
return h(Fragment, { key: '
|
|
40
|
+
return h(Fragment, { key: 'd6eb8ea68a4d507142547f4014f1dd3db58dcfd4' });
|
|
41
|
+
}
|
|
42
|
+
/** Materialize a table or view from the shared db, returning [] when it doesn't exist yet. */
|
|
43
|
+
queryRows(name) {
|
|
44
|
+
try {
|
|
45
|
+
return this.stores.db.db.exec(`SELECT * FROM \`${name}\``);
|
|
46
|
+
}
|
|
47
|
+
catch (_e) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
distinct(data, key) {
|
|
45
52
|
return [...new Set(data.map((d) => d[key]))].filter((v) => v !== null && v !== undefined);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-context isolated AlaSQL database with a tiny pub/sub for table/view
|
|
3
|
+
* data changes.
|
|
4
|
+
*
|
|
5
|
+
* Each `<bn-context>` owns one `ScopedDb`. `<bn-datasource>` and the static/
|
|
6
|
+
* URL branches of `<bn-dataset>` register tables; the SQL branch of
|
|
7
|
+
* `<bn-dataset>` registers views. Consumer components subscribe by name and
|
|
8
|
+
* re-render when the producer calls `notify(name)`.
|
|
9
|
+
*
|
|
10
|
+
* @module context/scopedDb
|
|
11
|
+
*/
|
|
12
|
+
import alasql from "alasql";
|
|
13
|
+
import { DateTime } from "luxon";
|
|
14
|
+
/**
|
|
15
|
+
* Builds a SQL FROM-clause expression for a dataset, optionally filtered.
|
|
16
|
+
*
|
|
17
|
+
* Helpers (DataQuery, Table, StructureChart, TimeChart, dataAnalyzer) embed
|
|
18
|
+
* this in their queries instead of accepting `[data]` array parameters, so
|
|
19
|
+
* alasql doesn't have to ingest a fresh table on every call.
|
|
20
|
+
*/
|
|
21
|
+
export function buildFromExpr(tableName, filter) {
|
|
22
|
+
if (filter != null && filter.length > 0) {
|
|
23
|
+
return `(SELECT * FROM \`${tableName}\` WHERE ${filter}) AS __src`;
|
|
24
|
+
}
|
|
25
|
+
return `\`${tableName}\``;
|
|
26
|
+
}
|
|
27
|
+
/** Coerces an unknown value into a Luxon `DateTime`, or `undefined` if it can't be parsed. */
|
|
28
|
+
function toDateTime(value) {
|
|
29
|
+
if (value == null)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (typeof value === "string") {
|
|
32
|
+
const dt = DateTime.fromISO(value);
|
|
33
|
+
return dt.isValid ? dt : undefined;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "number") {
|
|
36
|
+
const dt = DateTime.fromMillis(value);
|
|
37
|
+
return dt.isValid ? dt : undefined;
|
|
38
|
+
}
|
|
39
|
+
// Already a DateTime-shaped object.
|
|
40
|
+
if (typeof value.isValid === "boolean") {
|
|
41
|
+
const dt = value;
|
|
42
|
+
return dt.isValid ? dt : undefined;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* AlaSQL custom functions (UDFs) live on the `alasql.fn` global, not per-DB.
|
|
48
|
+
* Register them once at module load — multiple contexts share the registrations.
|
|
49
|
+
*
|
|
50
|
+
* Signatures are widened to `(...x: unknown[]) => unknown` to satisfy alasql's
|
|
51
|
+
* `userDefinedFunction` type; argument validation happens inside each UDF.
|
|
52
|
+
*/
|
|
53
|
+
let udfsRegistered = false;
|
|
54
|
+
function registerUdfs() {
|
|
55
|
+
if (udfsRegistered)
|
|
56
|
+
return;
|
|
57
|
+
udfsRegistered = true;
|
|
58
|
+
alasql.fn.transformOperator = ((a) => (a === "-" ? -1 : 1));
|
|
59
|
+
alasql.fn.normalizeDate = ((date, normalizationLevel, _locale) => {
|
|
60
|
+
const dt = toDateTime(date);
|
|
61
|
+
if (!dt)
|
|
62
|
+
return undefined;
|
|
63
|
+
return dt.startOf(normalizationLevel);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Creates a fresh isolated database with its own subscriber map. */
|
|
67
|
+
export function createScopedDb() {
|
|
68
|
+
registerUdfs();
|
|
69
|
+
const db = new alasql.Database();
|
|
70
|
+
const subscribers = new Map();
|
|
71
|
+
return {
|
|
72
|
+
db,
|
|
73
|
+
subscribe(name, cb) {
|
|
74
|
+
let set = subscribers.get(name);
|
|
75
|
+
if (!set) {
|
|
76
|
+
set = new Set();
|
|
77
|
+
subscribers.set(name, set);
|
|
78
|
+
}
|
|
79
|
+
set.add(cb);
|
|
80
|
+
return () => {
|
|
81
|
+
const s = subscribers.get(name);
|
|
82
|
+
if (!s)
|
|
83
|
+
return;
|
|
84
|
+
s.delete(cb);
|
|
85
|
+
if (s.size === 0)
|
|
86
|
+
subscribers.delete(name);
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
notify(name) {
|
|
90
|
+
const set = subscribers.get(name);
|
|
91
|
+
if (!set)
|
|
92
|
+
return;
|
|
93
|
+
for (const cb of set) {
|
|
94
|
+
try {
|
|
95
|
+
cb();
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
console.error(`[bn] subscriber for "${name}" threw`, e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
hasTable(name) {
|
|
103
|
+
var _a;
|
|
104
|
+
return ((_a = db.tables) === null || _a === void 0 ? void 0 : _a[name]) != null;
|
|
105
|
+
},
|
|
106
|
+
hasView(name) {
|
|
107
|
+
var _a;
|
|
108
|
+
// alasql stores views in db.views (separate from db.tables)
|
|
109
|
+
// @ts-ignore - views is not in the public typings
|
|
110
|
+
return ((_a = db.views) === null || _a === void 0 ? void 0 : _a[name]) != null;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
import { createStore } from "@stencil/store";
|
|
10
10
|
import { SYSTEM_STYLE_DEFAULTS } from "./componentStyles";
|
|
11
11
|
import { SYSTEM_I18N_DEFAULTS } from "./internationalization";
|
|
12
|
+
import { createScopedDb } from "../context/scopedDb";
|
|
12
13
|
export function createScopedStores() {
|
|
13
|
-
const
|
|
14
|
-
const datasets = createStore({});
|
|
14
|
+
const db = createScopedDb();
|
|
15
15
|
const datasetsMeta = createStore({});
|
|
16
16
|
const componentStyles = createStore({
|
|
17
17
|
_system: SYSTEM_STYLE_DEFAULTS,
|
|
@@ -21,8 +21,7 @@ export function createScopedStores() {
|
|
|
21
21
|
const context = createStore({ locale: "en" });
|
|
22
22
|
const scalingGroups = createStore({});
|
|
23
23
|
return {
|
|
24
|
-
|
|
25
|
-
datasets,
|
|
24
|
+
db,
|
|
26
25
|
datasetsMeta,
|
|
27
26
|
componentStyles,
|
|
28
27
|
internationalization,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import alasql from "alasql";
|
|
2
1
|
import { SiPrefix } from "./model/SiPrefix";
|
|
3
2
|
/**
|
|
4
3
|
* SI prefix lookup table mapping prefix symbols to their numeric multipliers.
|
|
@@ -46,8 +45,8 @@ export class DataAnalyzer {
|
|
|
46
45
|
* are considered; variance columns are excluded.
|
|
47
46
|
* - `null` with data: defaults to GREATEST auto-detection
|
|
48
47
|
*/
|
|
49
|
-
static calculateMeasureScale(
|
|
50
|
-
var _a;
|
|
48
|
+
static calculateMeasureScale(db, fromExpr, scenarios, mode) {
|
|
49
|
+
var _a, _b;
|
|
51
50
|
if (mode === "_") {
|
|
52
51
|
return new SiPrefix();
|
|
53
52
|
}
|
|
@@ -56,7 +55,7 @@ export class DataAnalyzer {
|
|
|
56
55
|
return this.lookupPrefix(mode);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
if (scenarios.length === 0) {
|
|
58
|
+
if (scenarios.length === 0 || !fromExpr) {
|
|
60
59
|
return new SiPrefix();
|
|
61
60
|
}
|
|
62
61
|
// filtering wordlenght == 3, so variances are not considered
|
|
@@ -64,18 +63,25 @@ export class DataAnalyzer {
|
|
|
64
63
|
.filter((word) => word.length === 3)
|
|
65
64
|
.map((x) => "ABS(" + x + ")")
|
|
66
65
|
.toString()})) as prefixvalue
|
|
67
|
-
FROM
|
|
66
|
+
FROM ${fromExpr}`;
|
|
68
67
|
const queryMin = `SELECT MIN(LEAST(${scenarios
|
|
69
68
|
.filter((word) => word.length === 3)
|
|
70
69
|
.map((x) => "ABS(" + x + ")")
|
|
71
70
|
.toString()})) as prefixvalue
|
|
72
|
-
FROM
|
|
71
|
+
FROM ${fromExpr}`;
|
|
73
72
|
let query = queryMax;
|
|
74
73
|
if ((mode === null || mode === void 0 ? void 0 : mode.toUpperCase()) === "LEAST") {
|
|
75
74
|
query = queryMin;
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
let num;
|
|
77
|
+
try {
|
|
78
|
+
const result = db.exec(query);
|
|
79
|
+
num = (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.prefixvalue) !== null && _b !== void 0 ? _b : 0;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.error("DataAnalyzer: measure-scale query failed", query, e);
|
|
83
|
+
return new SiPrefix();
|
|
84
|
+
}
|
|
79
85
|
return this.determinePrefix(Math.abs(num));
|
|
80
86
|
}
|
|
81
87
|
/** Maps an absolute numeric value to the best-fitting SI prefix based on digit count. */
|
|
@@ -14,16 +14,21 @@ import { runIfExisits } from "./utils";
|
|
|
14
14
|
*/
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
16
|
const withBodyObserver = (component, onUpdate) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
let hostElement;
|
|
18
|
+
// Coalesce bursts of mutations (e.g. devtools "Edit as HTML" fires childList +
|
|
19
|
+
// characterData in quick succession) and always read the *host* textContent so
|
|
20
|
+
// we deliver the complete body, not the individual text node that mutated.
|
|
21
|
+
const observer = new MutationObserver(() => {
|
|
22
|
+
var _a;
|
|
23
|
+
if (hostElement)
|
|
24
|
+
onUpdate((_a = hostElement.textContent) !== null && _a !== void 0 ? _a : "");
|
|
21
25
|
});
|
|
22
26
|
const connectedCallback = component["connectedCallback"];
|
|
23
27
|
component["connectedCallback"] = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
hostElement = getElement(component);
|
|
30
|
+
observer.observe(hostElement, { childList: true, subtree: true, characterData: true });
|
|
31
|
+
onUpdate((_a = hostElement.textContent) !== null && _a !== void 0 ? _a : "");
|
|
27
32
|
runIfExisits(connectedCallback, component);
|
|
28
33
|
};
|
|
29
34
|
const disconnectedCallback = component["disconnectedCallback"];
|
|
@@ -41,8 +41,12 @@ const warnIfDatasource = (component, datasources) => {
|
|
|
41
41
|
* Mixin that subscribes a Stencil component to one or more datasets/datasources.
|
|
42
42
|
*
|
|
43
43
|
* **Naming convention:** The `datasets` HTML attribute accepts a comma-separated list of names.
|
|
44
|
-
* Names prefixed with `$` (e.g. `$revenue`) read directly from the raw
|
|
45
|
-
* unprefixed names read from
|
|
44
|
+
* Names prefixed with `$` (e.g. `$revenue`) read directly from the raw datasource tables;
|
|
45
|
+
* unprefixed names read from datasets (registered as tables/views by `<bn-dataset>`).
|
|
46
|
+
*
|
|
47
|
+
* Data is sourced from the shared per-context alasql database; each subscribed
|
|
48
|
+
* name is registered with `stores.db.subscribe(...)` and the rows are materialized
|
|
49
|
+
* via `db.exec("SELECT * FROM <name>")` whenever the producer fires `notify(name)`.
|
|
46
50
|
*
|
|
47
51
|
* The mixin installs a MutationObserver on the host element's `datasets` attribute so
|
|
48
52
|
* bindings update automatically when the attribute is changed at runtime.
|
|
@@ -55,12 +59,24 @@ const warnIfDatasource = (component, datasources) => {
|
|
|
55
59
|
const withDataset = (
|
|
56
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
61
|
component, onUpdate, onMetaUpdate) => {
|
|
58
|
-
let
|
|
59
|
-
let subscriptionSource;
|
|
62
|
+
let dbUnsubs = [];
|
|
60
63
|
let subscriptionMeta;
|
|
61
64
|
let datasets = [];
|
|
62
65
|
let datasources = [];
|
|
63
66
|
let stores;
|
|
67
|
+
/** Materialize the current rows for a subscribed name via the shared db, then deliver. */
|
|
68
|
+
const deliver = (name, isDatasource) => {
|
|
69
|
+
const tableName = isDatasource ? name.substring(1) : name;
|
|
70
|
+
let rows;
|
|
71
|
+
try {
|
|
72
|
+
rows = stores.db.db.exec(`SELECT * FROM \`${tableName}\``);
|
|
73
|
+
}
|
|
74
|
+
catch (_e) {
|
|
75
|
+
// Table/view not registered yet (producer hasn't fired). Treat as empty.
|
|
76
|
+
rows = [];
|
|
77
|
+
}
|
|
78
|
+
onUpdate(name, rows);
|
|
79
|
+
};
|
|
64
80
|
const deliverMeta = (name) => {
|
|
65
81
|
if (onMetaUpdate) {
|
|
66
82
|
// @ts-ignore
|
|
@@ -69,20 +85,30 @@ component, onUpdate, onMetaUpdate) => {
|
|
|
69
85
|
onMetaUpdate(name, meta);
|
|
70
86
|
}
|
|
71
87
|
};
|
|
88
|
+
/** Tear down current db subscriptions and re-subscribe based on `datasets` / `datasources`. */
|
|
89
|
+
const rebind = () => {
|
|
90
|
+
dbUnsubs.forEach((fn) => fn());
|
|
91
|
+
dbUnsubs = [];
|
|
92
|
+
datasets.forEach((name) => {
|
|
93
|
+
if (!name)
|
|
94
|
+
return;
|
|
95
|
+
dbUnsubs.push(stores.db.subscribe(name, () => deliver(name, false)));
|
|
96
|
+
deliver(name, false);
|
|
97
|
+
deliverMeta(name);
|
|
98
|
+
});
|
|
99
|
+
datasources.forEach((ref) => {
|
|
100
|
+
if (!ref)
|
|
101
|
+
return;
|
|
102
|
+
dbUnsubs.push(stores.db.subscribe(ref.substring(1), () => deliver(ref, true)));
|
|
103
|
+
deliver(ref, true);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
72
106
|
const observer = new MutationObserver((mutations) => {
|
|
73
107
|
mutations.forEach((mutation) => {
|
|
74
108
|
if (mutation.attributeName === "datasets") {
|
|
75
109
|
[datasources, datasets] = partition((s) => s.startsWith("$"), getElement(component).getAttribute("datasets").split(","));
|
|
76
110
|
warnIfDatasource(component, datasources);
|
|
77
|
-
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
onUpdate(name, stores.datasets.get(name));
|
|
80
|
-
deliverMeta(name);
|
|
81
|
-
});
|
|
82
|
-
datasources.forEach((name) => {
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
onUpdate(name, stores.datasources.get(name.substring(1)));
|
|
85
|
-
});
|
|
111
|
+
rebind();
|
|
86
112
|
}
|
|
87
113
|
});
|
|
88
114
|
});
|
|
@@ -92,26 +118,8 @@ component, onUpdate, onMetaUpdate) => {
|
|
|
92
118
|
stores = getStores(element);
|
|
93
119
|
[datasources, datasets] = partition((s) => s.startsWith("$"), (element.getAttribute("datasets") || "").split(","));
|
|
94
120
|
warnIfDatasource(component, datasources);
|
|
95
|
-
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
onUpdate(name, stores.datasets.get(name));
|
|
98
|
-
deliverMeta(name);
|
|
99
|
-
});
|
|
100
|
-
datasources.forEach((name) => {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
onUpdate(name, stores.datasources.get(name.substring(1)));
|
|
103
|
-
});
|
|
121
|
+
rebind();
|
|
104
122
|
observer.observe(element, { attributes: true, attributeFilter: ["datasets"] });
|
|
105
|
-
subscriptionSet = stores.datasets.on("set", (key, newVlaue) => {
|
|
106
|
-
if (datasets.includes(key)) {
|
|
107
|
-
onUpdate(key, newVlaue);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
subscriptionSource = stores.datasources.on("set", (key, newVlaue) => {
|
|
111
|
-
if (datasources.includes("$" + key)) {
|
|
112
|
-
onUpdate("$" + key, newVlaue);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
123
|
if (onMetaUpdate) {
|
|
116
124
|
subscriptionMeta = stores.datasetsMeta.on("set", (key, newValue) => {
|
|
117
125
|
if (datasets.includes(key)) {
|
|
@@ -124,19 +132,15 @@ component, onUpdate, onMetaUpdate) => {
|
|
|
124
132
|
const disconnectedCallback = component["disconnectedCallback"];
|
|
125
133
|
component["disconnectedCallback"] = () => {
|
|
126
134
|
observer.disconnect();
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
dbUnsubs.forEach((fn) => fn());
|
|
136
|
+
dbUnsubs = [];
|
|
129
137
|
runIfExisits(subscriptionMeta);
|
|
130
138
|
clearStoresCache(getElement(component));
|
|
131
139
|
runIfExisits(disconnectedCallback, component);
|
|
132
140
|
};
|
|
133
141
|
return (names) => {
|
|
134
142
|
datasets = names;
|
|
135
|
-
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
onUpdate(name, stores.datasets.get(name));
|
|
138
|
-
deliverMeta(name);
|
|
139
|
-
});
|
|
143
|
+
rebind();
|
|
140
144
|
};
|
|
141
145
|
};
|
|
142
146
|
export default withDataset;
|
|
@@ -5,9 +5,9 @@ import { getElement } from "@stencil/core";
|
|
|
5
5
|
* Mixin that subscribes a Stencil component to raw datasources.
|
|
6
6
|
*
|
|
7
7
|
* This is the simpler counterpart of {@link withDataset} -- it reads directly from
|
|
8
|
-
* the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* the shared alasql database via `stores.db.subscribe(name, ...)`. Primarily used
|
|
9
|
+
* by `bn-dataset` itself to react to upstream datasource updates so it can re-fire
|
|
10
|
+
* its own dataset notification.
|
|
11
11
|
*
|
|
12
12
|
* Watches the host element's `datasources` attribute via MutationObserver for
|
|
13
13
|
* dynamic rebinding at runtime.
|
|
@@ -17,17 +17,34 @@ import { getElement } from "@stencil/core";
|
|
|
17
17
|
*/
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
19
|
const withDatasource = (component, onUpdate) => {
|
|
20
|
-
let
|
|
20
|
+
let dbUnsubs = [];
|
|
21
21
|
let datasources = [];
|
|
22
22
|
let stores;
|
|
23
|
+
const deliver = (name) => {
|
|
24
|
+
let rows;
|
|
25
|
+
try {
|
|
26
|
+
rows = stores.db.db.exec(`SELECT * FROM \`${name}\``);
|
|
27
|
+
}
|
|
28
|
+
catch (_e) {
|
|
29
|
+
rows = [];
|
|
30
|
+
}
|
|
31
|
+
onUpdate(name, rows);
|
|
32
|
+
};
|
|
33
|
+
const rebind = () => {
|
|
34
|
+
dbUnsubs.forEach((fn) => fn());
|
|
35
|
+
dbUnsubs = [];
|
|
36
|
+
datasources.forEach((name) => {
|
|
37
|
+
if (!name)
|
|
38
|
+
return;
|
|
39
|
+
dbUnsubs.push(stores.db.subscribe(name, () => deliver(name)));
|
|
40
|
+
deliver(name);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
23
43
|
const observer = new MutationObserver((mutations) => {
|
|
24
44
|
mutations.forEach((mutation) => {
|
|
25
45
|
if (mutation.attributeName === "datasources") {
|
|
26
46
|
datasources = (getElement(component).getAttribute("datasources") || "").split(",");
|
|
27
|
-
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
onUpdate(name, stores.datasources.get(name));
|
|
30
|
-
});
|
|
47
|
+
rebind();
|
|
31
48
|
}
|
|
32
49
|
});
|
|
33
50
|
});
|
|
@@ -36,22 +53,15 @@ const withDatasource = (component, onUpdate) => {
|
|
|
36
53
|
const element = getElement(component);
|
|
37
54
|
stores = getStores(element);
|
|
38
55
|
datasources = (element.getAttribute("datasources") || "").split(",");
|
|
39
|
-
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
onUpdate(name, stores.datasources.get(name));
|
|
42
|
-
});
|
|
56
|
+
rebind();
|
|
43
57
|
observer.observe(element, { attributes: true, attributeFilter: ["datasources"] });
|
|
44
|
-
subscription = stores.datasources.on("set", (key, newVlaue) => {
|
|
45
|
-
if (datasources.includes(key)) {
|
|
46
|
-
onUpdate(key, newVlaue);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
58
|
runIfExisits(connectedCallback, component);
|
|
50
59
|
};
|
|
51
60
|
const disconnectedCallback = component["disconnectedCallback"];
|
|
52
61
|
component["disconnectedCallback"] = () => {
|
|
53
62
|
observer.disconnect();
|
|
54
|
-
|
|
63
|
+
dbUnsubs.forEach((fn) => fn());
|
|
64
|
+
dbUnsubs = [];
|
|
55
65
|
clearStoresCache(getElement(component));
|
|
56
66
|
runIfExisits(disconnectedCallback, component);
|
|
57
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e}from"./Order.js";class t{constructor(e="",t=1){this.prefix=e,this.value=t}}var a;!function(e){e[e.Y=1e24]="Y",e[e.Z=1e21]="Z",e[e.E=1e18]="E",e[e.P=1e15]="P",e[e.T=1e12]="T",e[e.G=1e9]="G",e[e.M=1e6]="M",e[e.k=1e3]="k",e[e.h=100]="h",e[e.da=10]="da",e[e.d=.1]="d",e[e.c=.01]="c",e[e.m=.001]="m",e[e.my=1e-6]="my",e[e.n=1e-9]="n",e[e.p=1e-12]="p",e[e.f=1e-15]="f",e[e.a=1e-18]="a",e[e.z=1e-21]="z",e[e.y=1e-24]="y"}(a||(a={}));class r{static calculateMeasureScale(e,a,r,n){var s,i;if("_"===n)return new t;if(null!=n&&[...this.unitsLeast,...this.unitsGreat].includes(n))return this.lookupPrefix(n);if(0===r.length||!a)return new t;const u=`SELECT MAX(GREATEST(${r.filter((e=>3===e.length)).map((e=>"ABS("+e+")")).toString()})) as prefixvalue\n FROM ${a}`,c=`SELECT MIN(LEAST(${r.filter((e=>3===e.length)).map((e=>"ABS("+e+")")).toString()})) as prefixvalue\n FROM ${a}`;let l,h=u;"LEAST"===(null==n?void 0:n.toUpperCase())&&(h=c);try{l=null!==(i=null===(s=e.exec(h)[0])||void 0===s?void 0:s.prefixvalue)&&void 0!==i?i:0}catch(e){return console.error("DataAnalyzer: measure-scale query failed",h,e),new t}return this.determinePrefix(Math.abs(l))}static determinePrefix(e){if(e>=1e3){const a=Math.floor(Math.floor(Math.abs(e)).toString().length/3),r=+Math.pow(1e3,a);return new t(this.unitsGreat[a-1],r)}if(e<=.001){const a=Math.floor(Math.abs(e).toString().length/3),r=1/Math.pow(1e3,a);return new t(this.unitsLeast[a-1],r)}return new t}static lookupPrefix(e){return new t(e,a[e])}}r.unitsGreat=["k","M","G","T","P","E","Z","Y"],r.unitsLeast=["m","my","n","p","P","f","a","z","y"];class n{constructor(e=2,t=1){this.percent=e,this.decimal=t}}class s{adapt(t){const a=new n;return e.isNumber(t.percent)&&(a.percent=t.percent),e.isNumber(t.decimal)&&(a.decimal=t.decimal),a}default(){return new n}}export{r as D,t as S,n as a,s as b}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{D as t}from"./luxon.js";var e,s;!function(t){t.YEAR="year",t.QUARTER="quarter",t.MONTH="month",t.WEEK="week",t.DAY="day",t.HOUR="hour",t.MINUTE="minute",t.SECOND="second",t.MILLISECOND="millisecond",t.NONE="fallback",t.AUTO="auto"}(e||(e={})),function(t){t.AVG="avg",t.INTERVAL="interval",t.START="start",t.END="end",t.YTD="ytd",t.YTG="ytg",t.CUM="cum",t.MAT="mat",t.NONE="none",t.AUTO="auto"}(s||(s={}));class r{constructor(){this._dateFormat={year:"yyyy",quarter:"q'Q' yyyy",month:"LLL yyyy",week:"'KW'WW yyyy",day:"dd.MM.yyyy",hour:"TT",minute:"TT",second:"TT",millisecond:"TT:SSS",fallback:"dd.MM.yyyy"},this._dateFormatShort={year:"yy",quarter:"q'Q'",month:"LLL",week:"'KW'WW",day:"dd",hour:"hh'h'",minute:"mm'm'",second:"ss's'",millisecond:"SSS'ms'",fallback:"dd.MM.yyyy"},this._dateLinkFormat={avg:"Ø[LINK]",interval:"[DATE]..[DATE2]",start:".[DATE]",end:"[DATE].",ytd:"_[DATE]",ytg:"[DATE]_",cum:"[DATE]_[DATE2]",mat:"~[DATE]",none:"[DATE]"},this.locale="de",this.dateFormat=this._dateFormat,this.dateLinkFormat=this._dateLinkFormat,this.dateFormatShort=this._dateFormatShort}setDateLinkFormat(t){this.dateLinkFormat=t}setDateFormat(t){this.dateFormat=t}setDateFormatShort(t){this.dateFormatShort=t}setLocale(t){this.locale=t}getDateString(t,e){return t.setLocale(this.locale).toFormat(this.dateFormat[e]||this.dateFormat.fallback)}getSmartDateString(t,s){switch(s){case e.DAY:return this.getFormatedDayDate(t);case e.MONTH:return this.getFormatedMonthDate(t);case e.QUARTER:return this.getFormatedQuarterDate(t);case e.WEEK:return this.getFormatedWeekDate(t);case e.HOUR:return this.getFormatedHourDate(t);case e.MINUTE:return this.getFormatedMinuteDate(t);case e.SECOND:return this.getFormatedSecondDate(t);case e.MILLISECOND:return this.getFormatedMilliSecondDate(t);default:return this.getDateString(t,s)}}calculateDistanceType(s,r,i=32){if(null==r)return e.DAY;const a="number"==typeof s?t.fromMillis(s):s,n="number"==typeof r?t.fromMillis(r):r;return 0===n.diff(a).as("milliseconds")?e.DAY:n.diff(a).as("milliseconds")<i?e.MILLISECOND:n.diff(a).as("seconds")<i?e.SECOND:n.diff(a).as("minutes")<i?e.MINUTE:n.diff(a).as("hours")<i?e.HOUR:n.diff(a).as("days")<i?e.DAY:n.diff(a).as("weeks")<i?e.WEEK:n.diff(a).as("months")<i?e.MONTH:n.diff(a).as("quarters")<i?e.QUARTER:e.YEAR}datesBetween(t,e,s,r){const i=this.convertDateDistanceToMomentunitOfTime(s),a=t.startOf(i),n=e.endOf(i);let h=n.diff(a).as(i);const u=[];h>=r&&(h=r);let o=a;do{u.push(o),o=o.plus(this.createDiratonLike(i,1))}while(o<=n&&u.length<h);return u}getDateLinkString(r,i,a,n,h){if(null==r&&null==i)return"";if(null==r&&a!==s.END&&a!==s.YTD)return"";if(null==i&&(s.INTERVAL===a||s.CUM===a||s.END===a||s.YTD===a))return"";const u=r||t.now(),o=i;n===e.AUTO&&(n=this.calculateDistanceType(u,o,h));let c=this.getDateString(u,n),l="",d=s.NONE;return null!=o&&(l=this.getDateString(o,n),d=s.INTERVAL,c===l&&a===s.INTERVAL&&(a=s.NONE),c===l&&a===s.AVG&&(d=s.NONE),s.END!==a&&s.YTD!==a||(c=l),(a===s.INTERVAL||a===s.CUM||s.AVG)&&(n===e.QUARTER?u.quarter===o.quarter&&u.year===o.year?l=l.replace(" "+o.year,""):u.year===o.year&&(c=c.replace(" "+u.year,"")):n===e.MONTH?u.month===o.month&&u.year===o.year?l=l.replace(" "+o.year,""):u.year===o.year&&(c=c.replace(" "+u.year,"")):n===e.WEEK&&(u.weekNumber===o.weekNumber&&u.year===o.year?l=l.replace(" "+o.year,""):u.year===o.year&&(c=c.replace(" "+u.year,""))))),this.dateLinkFormat[a].replace("[LINK]",this.dateLinkFormat[d]).replace("[DATE]",c).replace("[DATE2]",l)}getShortDateString(t,e){return t.setLocale(this.locale).toFormat(this.dateFormatShort[e]||this.dateFormatShort.fallback)}getFormatedDayDate(t){let e=this.dateFormatShort.day;return this.isFirstInMonth(t)&&(e+=" "+this.dateFormatShort.month),this.isJanuary(t)&&(e+=" "+this.dateFormatShort.year),t.setLocale(this.locale).toFormat(e)}getFormatedMonthDate(t){let e=this.dateFormatShort.month;return this.isJanuary(t)&&(e+=" "+this.dateFormatShort.year),t.setLocale(this.locale).toFormat(e)}getFormatedQuarterDate(t){let e=this.dateFormatShort.quarter;return this.isFirstQuarter(t)&&(e+=" "+this.dateFormatShort.year),t.setLocale(this.locale).toFormat(e)}getFormatedWeekDate(t){let e=this.dateFormatShort.week;return this.isFirstWeek(t)&&(e+=" "+this.dateFormatShort.year),t.setLocale(this.locale).toFormat(e)}getFormatedHourDate(t){let e=this.dateFormatShort.hour;return this.isFirstHour(t)&&(e+=" "+this.dateFormatShort.day),t.setLocale(this.locale).toFormat(e)}getFormatedMinuteDate(t){let e=this.dateFormatShort.minute;return this.isFirstMinute(t)&&(e=this.dateFormatShort.hour+":"+e),t.setLocale(this.locale).toFormat(e)}getFormatedSecondDate(t){let e=this.dateFormatShort.second;return this.isFirstSecond(t)&&(e=this.dateFormatShort.minute+":"+e),t.setLocale(this.locale).toFormat(e)}getFormatedMilliSecondDate(t){let e=this.dateFormatShort.millisecond;return this.isFirstMilliSecond(t)&&(e=this.dateFormatShort.second+":"+e),t.setLocale(this.locale).toFormat(e)}isFirstInMonth(t){return 1===t.day}isJanuary(t){return 1===t.month}isFirstQuarter(t){return 1===t.quarter}isFirstWeek(t){return 1===t.weekNumber}isFirstHour(t){return 0===t.hour}isFirstMinute(t){return 0===t.minute}isFirstSecond(t){return 0===t.second}isFirstMilliSecond(t){return 0===t.millisecond}convertDateDistanceToMomentunitOfTime(t){let s;switch(t){case e.YEAR:s="year";break;case e.MONTH:s="month";break;case e.QUARTER:s="quarter";break;case e.WEEK:s="week";break;case e.DAY:s="day";break;case e.HOUR:s="hour";break;case e.MINUTE:s="minute";break;case e.SECOND:s="second";break;case e.MILLISECOND:s="millisecond";break;default:s="day"}return s}createDiratonLike(t,e){switch(t){case"year":return{years:e};case"month":return{months:e};case"quarter":return{quarters:e};case"week":return{weeks:e};case"day":default:return{days:e};case"hour":return{hours:e};case"minute":return{minutes:e};case"second":return{seconds:e};case"millisecond":return{milliseconds:e}}}}export{e as D,s as a,r as b}
|