@bino-bi/bn-template-engine 1.0.0-alpha.7 → 1.0.0-alpha.9
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-3141c4a2.entry.js +1 -0
- package/dist/bn-template-engine/p-67538176.entry.js +1 -0
- package/dist/bn-template-engine/p-916296a5.entry.js +1 -0
- package/dist/bn-template-engine/{p-1164c0b0.entry.js → p-96006b06.entry.js} +1 -1
- package/dist/bn-template-engine/p-B4JfKvVT.js +1 -0
- package/dist/bn-template-engine/{p-JNHhIe7t.js → p-B_d-jp99.js} +1 -1
- package/dist/bn-template-engine/p-Ck-NYtot.js +1 -0
- package/dist/bn-template-engine/p-CnDq0oVa.js +1 -0
- package/dist/bn-template-engine/p-DSXNgKLa.js +1 -0
- package/dist/bn-template-engine/p-bc711fb0.entry.js +1 -0
- package/dist/bn-template-engine/p-c86395b8.entry.js +1 -0
- package/dist/bn-template-engine/p-e6f646b1.entry.js +1 -0
- package/dist/bn-template-engine/p-f41d9242.entry.js +1 -0
- package/dist/bn-template-engine/{p-B0lsgVuN.js → p-gFbbuhtl.js} +1 -1
- package/dist/cjs/{SVGVariancesStyleGroup-BqAdPYtL.js → bn-asset_20.cjs.entry.js} +21955 -6939
- package/dist/cjs/bn-grid.cjs.entry.js +6 -9
- package/dist/cjs/bn-image.cjs.entry.js +6 -9
- package/dist/cjs/bn-internationalization.cjs.entry.js +5 -6
- package/dist/cjs/bn-template-engine.cjs.js +2 -2
- package/dist/cjs/bn-template.cjs.entry.js +3 -4
- package/dist/cjs/bn-text.cjs.entry.js +7 -10
- package/dist/cjs/bn-tree.cjs.entry.js +11 -10
- package/dist/cjs/{context-protocol-DRQWrwsA.js → context-protocol-ohYzcb5F.js} +1 -1
- package/dist/cjs/editor-companion.cjs.entry.js +2 -2
- package/dist/cjs/{index-Cjw0q6gP.js → index-CDKG4xmO.js} +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/{scaling-BidPsO53.js → scaling-CIAClQR5.js} +3 -3
- package/dist/cjs/{withBodyObserver-C6gLgq_e.js → withBodyObserver-D7BKWN2N.js} +2 -2
- package/dist/cjs/{withHasError-B8gHkfV2.js → withHasError-Cl2gTQzA.js} +106 -2
- package/dist/cjs/{Order-BGx39pS5.js → withStyled-qd94SSb4.js} +648 -6
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +24 -5
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +24 -5
- package/dist/collection/components/bn-layout-card/bn-layout-card.js +12 -6
- package/dist/collection/components/bn-layout-page/bn-layout-page.js +12 -7
- package/dist/collection/components/bn-table/bn-table.js +25 -7
- package/dist/collection/components/bn-table/ibcs-table.js +68 -3
- package/dist/collection/components/bn-tree/bn-tree.js +5 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-layout-card.js +1 -1
- package/dist/components/bn-layout-page.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-tree.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/esm/{SVGVariancesStyleGroup-DOIT-zvI.js → bn-asset_20.entry.js} +22055 -7043
- package/dist/esm/bn-grid.entry.js +4 -7
- package/dist/esm/bn-image.entry.js +4 -7
- package/dist/esm/bn-internationalization.entry.js +4 -5
- package/dist/esm/bn-template-engine.js +3 -3
- package/dist/esm/bn-template.entry.js +2 -3
- package/dist/esm/bn-text.entry.js +5 -8
- package/dist/esm/bn-tree.entry.js +9 -8
- package/dist/esm/{context-protocol-2peaD4y8.js → context-protocol-DdbSplvE.js} +2 -2
- package/dist/esm/editor-companion.entry.js +2 -2
- package/dist/esm/{index-JNHhIe7t.js → index-B_d-jp99.js} +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/esm/{scaling-BOcjT8M0.js → scaling-DGKKkuL9.js} +4 -4
- package/dist/esm/{withBodyObserver-DczL5ia8.js → withBodyObserver-AFk2wwHT.js} +2 -2
- package/dist/esm/{withHasError-B3QX2emi.js → withHasError-DW_vMDUp.js} +106 -2
- package/dist/esm/{Order-sRO-lj7X.js → withStyled-BIkqU2w4.js} +616 -1
- package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +1 -0
- package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +1 -0
- package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +8 -2
- package/dist/types/components/bn-layout-page/bn-layout-page.d.ts +8 -3
- package/dist/types/components/bn-table/ibcs-table.d.ts +19 -0
- package/dist/types/components.d.ts +8 -8
- package/package.json +1 -1
- package/dist/bn-template-engine/p-0fabe296.entry.js +0 -1
- package/dist/bn-template-engine/p-355abdf0.entry.js +0 -1
- package/dist/bn-template-engine/p-79KuA4Ox.js +0 -1
- package/dist/bn-template-engine/p-859cc06d.entry.js +0 -1
- package/dist/bn-template-engine/p-8acec99e.entry.js +0 -1
- package/dist/bn-template-engine/p-8f490c45.entry.js +0 -1
- package/dist/bn-template-engine/p-9721a5bb.entry.js +0 -1
- package/dist/bn-template-engine/p-9a564f8f.entry.js +0 -1
- package/dist/bn-template-engine/p-9cee22fa.entry.js +0 -1
- package/dist/bn-template-engine/p-B7p8beYH.js +0 -1
- package/dist/bn-template-engine/p-BDh7GfC5.js +0 -1
- package/dist/bn-template-engine/p-BoMtoHJB.js +0 -1
- package/dist/bn-template-engine/p-Bs8BqBsb.js +0 -1
- package/dist/bn-template-engine/p-CYjZRKdI.js +0 -1
- package/dist/bn-template-engine/p-DG-1MR_T.js +0 -1
- package/dist/bn-template-engine/p-Dnkv5rt8.js +0 -1
- package/dist/bn-template-engine/p-bdd2b243.entry.js +0 -1
- package/dist/bn-template-engine/p-f27995c9.entry.js +0 -1
- package/dist/bn-template-engine/p-f6ecb265.entry.js +0 -1
- package/dist/bn-template-engine/p-sRO-lj7X.js +0 -1
- package/dist/bn-template-engine/p-tzFCK9qn.js +0 -1
- package/dist/cjs/bn-asset_16.cjs.entry.js +0 -9099
- package/dist/cjs/bn-card.cjs.entry.js +0 -36
- package/dist/cjs/bn-chart-time.cjs.entry.js +0 -1031
- package/dist/cjs/bn-layout-card.cjs.entry.js +0 -279
- package/dist/cjs/formatter-4XCS0d2B.js +0 -221
- package/dist/cjs/ibcs-chart-time.cjs.entry.js +0 -4137
- package/dist/cjs/withComponentStatus-_x4LQZ0N.js +0 -109
- package/dist/cjs/withComponentStyle-ClSJfCku.js +0 -128
- package/dist/cjs/withInheritedProps-BH2KNER3.js +0 -157
- package/dist/cjs/withStyled-9tG024gQ.js +0 -522
- package/dist/esm/bn-asset_16.entry.js +0 -9082
- package/dist/esm/bn-card.entry.js +0 -34
- package/dist/esm/bn-chart-time.entry.js +0 -1029
- package/dist/esm/bn-layout-card.entry.js +0 -277
- package/dist/esm/formatter-BDh7GfC5.js +0 -215
- package/dist/esm/ibcs-chart-time.entry.js +0 -4135
- package/dist/esm/withComponentStatus-DodoSXe-.js +0 -107
- package/dist/esm/withComponentStyle-D3VWOsto.js +0 -126
- package/dist/esm/withInheritedProps-BlXDxhHK.js +0 -154
- package/dist/esm/withStyled-CE3_3taP.js +0 -495
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { g as generateUUID, r as runIfExisits } from './withHasError-B3QX2emi.js';
|
|
2
|
-
|
|
3
|
-
/** Lifecycle state of a tracked component instance. */
|
|
4
|
-
var ComponentStatus;
|
|
5
|
-
(function (ComponentStatus) {
|
|
6
|
-
ComponentStatus[ComponentStatus["RUNNING"] = 0] = "RUNNING";
|
|
7
|
-
ComponentStatus[ComponentStatus["SUCCESSFUL"] = 1] = "SUCCESSFUL";
|
|
8
|
-
ComponentStatus[ComponentStatus["ERROR"] = 2] = "ERROR";
|
|
9
|
-
})(ComponentStatus || (ComponentStatus = {}));
|
|
10
|
-
/**
|
|
11
|
-
* Singleton registry that tracks the render status of all bn-* component instances.
|
|
12
|
-
*
|
|
13
|
-
* Each component registers itself via {@link withComponentStatus} and reports
|
|
14
|
-
* `RUNNING` / `SUCCESSFUL` / `ERROR` transitions. After 500 ms of inactivity
|
|
15
|
-
* (no status updates), the aggregate result is written to
|
|
16
|
-
* `window.componentRegisterIsRenderedResult` as a boolean. External tools
|
|
17
|
-
* (e.g. headless screenshot renderers) poll this value to detect when
|
|
18
|
-
* the entire page has finished rendering.
|
|
19
|
-
*
|
|
20
|
-
* The 500 ms debounce prevents premature "rendered" signals during rapid
|
|
21
|
-
* successive re-renders.
|
|
22
|
-
*
|
|
23
|
-
* Status counts are maintained incrementally — `updateStatus` adjusts running
|
|
24
|
-
* counters instead of iterating all entries, making it O(1) per update.
|
|
25
|
-
*/
|
|
26
|
-
var ComponentRegister;
|
|
27
|
-
(function (ComponentRegister) {
|
|
28
|
-
let currentTimeOutId = undefined;
|
|
29
|
-
const componentRegister = new Map();
|
|
30
|
-
const statusCounts = { running: 0, successful: 0, error: 0 };
|
|
31
|
-
const countKey = (status) => {
|
|
32
|
-
switch (status) {
|
|
33
|
-
case ComponentStatus.RUNNING:
|
|
34
|
-
return "running";
|
|
35
|
-
case ComponentStatus.SUCCESSFUL:
|
|
36
|
-
return "successful";
|
|
37
|
-
default:
|
|
38
|
-
return "error";
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Records a status change for the component identified by `uuid` and
|
|
43
|
-
* resets the 500 ms debounce timer. When the timer fires, the aggregate
|
|
44
|
-
* "all rendered" boolean is published to `window.componentRegisterIsRenderedResult`.
|
|
45
|
-
*/
|
|
46
|
-
ComponentRegister.updateStatus = (uuid, status) => {
|
|
47
|
-
if (currentTimeOutId) {
|
|
48
|
-
clearTimeout(currentTimeOutId);
|
|
49
|
-
}
|
|
50
|
-
const prev = componentRegister.get(uuid);
|
|
51
|
-
if (prev !== undefined) {
|
|
52
|
-
statusCounts[countKey(prev)]--;
|
|
53
|
-
}
|
|
54
|
-
statusCounts[countKey(status)]++;
|
|
55
|
-
componentRegister.set(uuid, status);
|
|
56
|
-
currentTimeOutId = setTimeout(() => {
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
window.componentRegisterIsRenderedResult = ComponentRegister.componentRegisterIsRendered();
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
// eslint-disable-next-line no-console
|
|
61
|
-
console.log("componentRegisterIsRendered:", window.componentRegisterIsRenderedResult);
|
|
62
|
-
}, 500);
|
|
63
|
-
};
|
|
64
|
-
/** Returns `true` when no components are currently in `RUNNING` state. */
|
|
65
|
-
ComponentRegister.componentRegisterIsRendered = () => {
|
|
66
|
-
return statusCounts.running === 0;
|
|
67
|
-
};
|
|
68
|
-
/** Returns a summary count of components in each status category. */
|
|
69
|
-
ComponentRegister.componentRegisterStatus = () => {
|
|
70
|
-
return Object.assign({}, statusCounts);
|
|
71
|
-
};
|
|
72
|
-
})(ComponentRegister || (ComponentRegister = {}));
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Mixin that tracks a component's render lifecycle in the global {@link ComponentRegister}.
|
|
76
|
-
*
|
|
77
|
-
* Assigns a stable UUID to the component instance and reports status transitions:
|
|
78
|
-
* - `RUNNING` on `connectedCallback` and `componentWillRender`
|
|
79
|
-
* - `SUCCESSFUL` on `componentDidRender`
|
|
80
|
-
*
|
|
81
|
-
* External tools (e.g. screenshot/PDF renderers) poll
|
|
82
|
-
* `window.componentRegisterIsRenderedResult` to determine when all components
|
|
83
|
-
* have finished rendering.
|
|
84
|
-
*
|
|
85
|
-
* @param component - The Stencil component instance
|
|
86
|
-
*/
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
-
const withComponentStatus = (component) => {
|
|
89
|
-
const uuid = generateUUID();
|
|
90
|
-
const connectedCallback = component["connectedCallback"];
|
|
91
|
-
component["connectedCallback"] = () => {
|
|
92
|
-
ComponentRegister.updateStatus(uuid, ComponentStatus.RUNNING);
|
|
93
|
-
runIfExisits(connectedCallback, component);
|
|
94
|
-
};
|
|
95
|
-
const componentWillRender = component["componentWillRender"];
|
|
96
|
-
component["componentWillRender"] = () => {
|
|
97
|
-
ComponentRegister.updateStatus(uuid, ComponentStatus.RUNNING);
|
|
98
|
-
runIfExisits(componentWillRender, component);
|
|
99
|
-
};
|
|
100
|
-
const componentDidRender = component["componentDidRender"];
|
|
101
|
-
component["componentDidRender"] = () => {
|
|
102
|
-
ComponentRegister.updateStatus(uuid, ComponentStatus.SUCCESSFUL);
|
|
103
|
-
runIfExisits(componentDidRender, component);
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { withComponentStatus as w };
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { g as getElement, f as forceUpdate } from './index-JNHhIe7t.js';
|
|
2
|
-
import { a as getStores, c as clearStoresCache } from './context-protocol-2peaD4y8.js';
|
|
3
|
-
import { r as runIfExisits } from './withHasError-B3QX2emi.js';
|
|
4
|
-
|
|
5
|
-
const isObject = (obj) => {
|
|
6
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
7
|
-
if (typeof Object.getPrototypeOf === 'function') {
|
|
8
|
-
const prototype = Object.getPrototypeOf(obj);
|
|
9
|
-
return prototype === Object.prototype || prototype === null;
|
|
10
|
-
}
|
|
11
|
-
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
};
|
|
15
|
-
const overwriteMerge = (_, currArr) => currArr;
|
|
16
|
-
const combineMerge = (prevArr, currArr) => {
|
|
17
|
-
return [...new Set([...prevArr, ...currArr])];
|
|
18
|
-
};
|
|
19
|
-
const getMergeFn = (type) => {
|
|
20
|
-
switch (type) {
|
|
21
|
-
case 'overwrite':
|
|
22
|
-
return overwriteMerge;
|
|
23
|
-
case 'combine':
|
|
24
|
-
default:
|
|
25
|
-
return combineMerge;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const withDefaultOptions = (options) => {
|
|
30
|
-
return {
|
|
31
|
-
arrayMergeType: 'combine',
|
|
32
|
-
arrayMerge: getMergeFn(options ? options.arrayMergeType : 'combine'),
|
|
33
|
-
...options,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const merge = (objects, options) => {
|
|
37
|
-
const opts = withDefaultOptions(options);
|
|
38
|
-
return objects.reduce((prev, curr) => {
|
|
39
|
-
Object.keys(curr).forEach((key) => {
|
|
40
|
-
if (Array.isArray(prev[key]) && Array.isArray(curr[key])) {
|
|
41
|
-
if (opts && opts.arrayMerge) {
|
|
42
|
-
prev[key] = opts.arrayMerge(prev[key], curr[key]);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else if (isObject(prev[key]) && isObject(curr[key])) {
|
|
46
|
-
prev[key] = merge([prev[key], curr[key]], opts);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
prev[key] = curr[key];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return prev;
|
|
53
|
-
}, {});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Mixin that provides themed styling to a Stencil component using a
|
|
58
|
-
* three-layer merge strategy.
|
|
59
|
-
*
|
|
60
|
-
* The effective style is computed by deep-merging three layers in order:
|
|
61
|
-
* 1. `_system` -- built-in defaults (lowest priority)
|
|
62
|
-
* 2. `_default` -- user-defined global overrides
|
|
63
|
-
* 3. The value of the host element's `selected-style` attribute (highest priority)
|
|
64
|
-
*
|
|
65
|
-
* A MutationObserver watches `selected-style` and the store subscription
|
|
66
|
-
* reacts to updates in the componentStyles store, triggering a re-merge
|
|
67
|
-
* and forced re-render on changes.
|
|
68
|
-
*
|
|
69
|
-
* @param component - The Stencil component instance
|
|
70
|
-
* @returns A query function `componentStyle(<selector>)` that provides type-safe
|
|
71
|
-
* access to the merged style object, e.g. `componentStyle(s => s.table.headerBg)`
|
|
72
|
-
*/
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
const withComponentStyle = (component) => {
|
|
75
|
-
let subscription;
|
|
76
|
-
let stores;
|
|
77
|
-
let selectedStyle;
|
|
78
|
-
let style;
|
|
79
|
-
const updateStyle = () => {
|
|
80
|
-
const state = stores.componentStyles.state;
|
|
81
|
-
style = merge([
|
|
82
|
-
state["_system"] || {},
|
|
83
|
-
state["_default"] || {},
|
|
84
|
-
state[selectedStyle] || {},
|
|
85
|
-
]);
|
|
86
|
-
};
|
|
87
|
-
const observer = new MutationObserver((mutations) => {
|
|
88
|
-
mutations.forEach((mutation) => {
|
|
89
|
-
if (mutation.attributeName === "selected-style") {
|
|
90
|
-
selectedStyle = getElement(component).getAttribute("selected-style");
|
|
91
|
-
updateStyle();
|
|
92
|
-
forceUpdate(component);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
const connectedCallback = component["connectedCallback"];
|
|
97
|
-
component["connectedCallback"] = () => {
|
|
98
|
-
const element = getElement(component);
|
|
99
|
-
stores = getStores(element);
|
|
100
|
-
style = stores.componentStyles.state["_system"];
|
|
101
|
-
observer.observe(element, { attributes: true, attributeFilter: ["selected-style"] });
|
|
102
|
-
selectedStyle = getElement(component).getAttribute("selected-style");
|
|
103
|
-
updateStyle();
|
|
104
|
-
subscription = stores.componentStyles.on("set", (key) => {
|
|
105
|
-
if (key === selectedStyle) {
|
|
106
|
-
selectedStyle = getElement(component).getAttribute("selected-style");
|
|
107
|
-
updateStyle();
|
|
108
|
-
forceUpdate(getElement(component));
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
runIfExisits(connectedCallback, component);
|
|
112
|
-
};
|
|
113
|
-
const disconnectedCallback = component["disconnectedCallback"];
|
|
114
|
-
component["disconnectedCallback"] = () => {
|
|
115
|
-
observer.disconnect();
|
|
116
|
-
runIfExisits(subscription);
|
|
117
|
-
clearStoresCache(getElement(component));
|
|
118
|
-
runIfExisits(disconnectedCallback, component);
|
|
119
|
-
};
|
|
120
|
-
const componentStyle = (q) => {
|
|
121
|
-
return q(style);
|
|
122
|
-
};
|
|
123
|
-
return componentStyle;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export { withComponentStyle as w };
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { g as getElement, f as forceUpdate } from './index-JNHhIe7t.js';
|
|
2
|
-
import { r as runIfExisits } from './withHasError-B3QX2emi.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Reserved prop values that activate inheritance from ancestor layout
|
|
6
|
-
* components (`bn-layout-card` or `bn-layout-page`).
|
|
7
|
-
*/
|
|
8
|
-
const INHERITED_CLOSEST = "inherited-closest";
|
|
9
|
-
const INHERITED_PAGE = "inherited-page";
|
|
10
|
-
/** Tags that qualify as inheritance ancestors. */
|
|
11
|
-
const ANCESTOR_CARD = "bn-layout-card";
|
|
12
|
-
const ANCESTOR_PAGE = "bn-layout-page";
|
|
13
|
-
/**
|
|
14
|
-
* Returns `true` when `value` is one of the recognised inheritance keywords.
|
|
15
|
-
*/
|
|
16
|
-
function isInheritedValue(value) {
|
|
17
|
-
return value === INHERITED_CLOSEST || value === INHERITED_PAGE;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Walks up the DOM tree (crossing shadow boundaries) to find the nearest
|
|
21
|
-
* ancestor layout component.
|
|
22
|
-
*
|
|
23
|
-
* - `"inherited-closest"` matches the first `bn-layout-card` or `bn-layout-page`.
|
|
24
|
-
* - `"inherited-page"` skips cards and matches only `bn-layout-page`.
|
|
25
|
-
*
|
|
26
|
-
* Uses the same traversal pattern as `findContextElement` in
|
|
27
|
-
* `context-protocol.ts`.
|
|
28
|
-
*/
|
|
29
|
-
function findAncestor(element, mode) {
|
|
30
|
-
let current = element.parentNode;
|
|
31
|
-
while (current) {
|
|
32
|
-
if (current instanceof HTMLElement) {
|
|
33
|
-
const tag = current.nodeName.toLowerCase();
|
|
34
|
-
if (mode === INHERITED_PAGE) {
|
|
35
|
-
if (tag === ANCESTOR_PAGE)
|
|
36
|
-
return current;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (tag === ANCESTOR_CARD || tag === ANCESTOR_PAGE)
|
|
40
|
-
return current;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (current.parentNode) {
|
|
44
|
-
current = current.parentNode;
|
|
45
|
-
}
|
|
46
|
-
else if (current instanceof ShadowRoot) {
|
|
47
|
-
current = current.host;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Mixin that enables property inheritance from ancestor layout components.
|
|
57
|
-
*
|
|
58
|
-
* When a component sets a prop to `"inherited-closest"` or `"inherited-page"`,
|
|
59
|
-
* this mixin resolves the actual value by walking up the DOM to find the
|
|
60
|
-
* nearest `bn-layout-card` / `bn-layout-page` and reading the corresponding
|
|
61
|
-
* HTML attribute. A `MutationObserver` watches the ancestor for attribute
|
|
62
|
-
* changes, triggering a re-render when inherited values update.
|
|
63
|
-
*
|
|
64
|
-
* Follows the same decorator-style pattern as `withComponentStyle`.
|
|
65
|
-
*
|
|
66
|
-
* @param component The Stencil component instance
|
|
67
|
-
* @param mappings Array of prop-to-attribute mappings
|
|
68
|
-
* @returns A resolver function used inside `prepare*()` methods
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
const withInheritedProps = (component, mappings) => {
|
|
72
|
-
/** Resolved values keyed by propName. */
|
|
73
|
-
const resolved = new Map();
|
|
74
|
-
/** Observer watching the ancestor element's attributes. */
|
|
75
|
-
let observer = null;
|
|
76
|
-
/** The ancestor element currently being observed. */
|
|
77
|
-
let ancestorEl;
|
|
78
|
-
/**
|
|
79
|
-
* For each mapping whose prop is an inheritance keyword, walk the DOM once
|
|
80
|
-
* and read the corresponding attribute from the ancestor.
|
|
81
|
-
*/
|
|
82
|
-
const resolveAll = () => {
|
|
83
|
-
const element = getElement(component);
|
|
84
|
-
resolved.clear();
|
|
85
|
-
// Determine which attrs to watch on which ancestor
|
|
86
|
-
const attrsToWatch = [];
|
|
87
|
-
for (const mapping of mappings) {
|
|
88
|
-
const value = component[mapping.propName];
|
|
89
|
-
if (typeof value !== "string" || !isInheritedValue(value))
|
|
90
|
-
continue;
|
|
91
|
-
// Find ancestor (re-use the first one found for the same mode)
|
|
92
|
-
if (!ancestorEl) {
|
|
93
|
-
ancestorEl = findAncestor(element, value);
|
|
94
|
-
}
|
|
95
|
-
if (!ancestorEl)
|
|
96
|
-
continue;
|
|
97
|
-
const attrValue = ancestorEl.getAttribute(mapping.ancestorAttr);
|
|
98
|
-
if (attrValue != null) {
|
|
99
|
-
resolved.set(mapping.propName, attrValue);
|
|
100
|
-
}
|
|
101
|
-
attrsToWatch.push(mapping.ancestorAttr);
|
|
102
|
-
}
|
|
103
|
-
// Set up MutationObserver on the ancestor
|
|
104
|
-
if (ancestorEl && attrsToWatch.length > 0) {
|
|
105
|
-
observer = new MutationObserver(() => {
|
|
106
|
-
// Re-read all inherited attributes from the ancestor
|
|
107
|
-
for (const mapping of mappings) {
|
|
108
|
-
if (!isInheritedValue(component[mapping.propName]))
|
|
109
|
-
continue;
|
|
110
|
-
const attrValue = ancestorEl.getAttribute(mapping.ancestorAttr);
|
|
111
|
-
if (attrValue != null) {
|
|
112
|
-
resolved.set(mapping.propName, attrValue);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
resolved.delete(mapping.propName);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
forceUpdate(component);
|
|
119
|
-
});
|
|
120
|
-
observer.observe(ancestorEl, {
|
|
121
|
-
attributes: true,
|
|
122
|
-
attributeFilter: attrsToWatch,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
const connectedCallback = component["connectedCallback"];
|
|
127
|
-
component["connectedCallback"] = () => {
|
|
128
|
-
resolveAll();
|
|
129
|
-
runIfExisits(connectedCallback, component);
|
|
130
|
-
};
|
|
131
|
-
const disconnectedCallback = component["disconnectedCallback"];
|
|
132
|
-
component["disconnectedCallback"] = () => {
|
|
133
|
-
if (observer) {
|
|
134
|
-
observer.disconnect();
|
|
135
|
-
observer = null;
|
|
136
|
-
}
|
|
137
|
-
ancestorEl = undefined;
|
|
138
|
-
resolved.clear();
|
|
139
|
-
runIfExisits(disconnectedCallback, component);
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Resolver: returns the inherited value for the given prop, or `undefined`
|
|
143
|
-
* when the prop is not using inheritance (so the caller falls through to
|
|
144
|
-
* its normal logic).
|
|
145
|
-
*/
|
|
146
|
-
const resolve = (propName, currentValue) => {
|
|
147
|
-
if (!isInheritedValue(currentValue))
|
|
148
|
-
return undefined;
|
|
149
|
-
return resolved.get(propName);
|
|
150
|
-
};
|
|
151
|
-
return resolve;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
export { isInheritedValue as i, withInheritedProps as w };
|