Skip to content

Commit

Permalink
Merge pull request #42 from pennions/fix/flightkit-treenav-table
Browse files Browse the repository at this point in the history
fix: events are correctly handled when clicking an item in the tree
  • Loading branch information
jelmerveen authored Nov 6, 2024
2 parents 9defbf4 + efa9864 commit 934b0fc
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 78 deletions.
2 changes: 1 addition & 1 deletion build-ibiss.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build() {
}
}

fs.rmdir('./dist', { recursive: true }, () => {
fs.rm('./dist', { recursive: true }, () => {
console.log('cleaning done');
const rollupCommands = [
"npx rollup --config rollup.config.js",
Expand Down
1 change: 0 additions & 1 deletion dist/flightkit-v0.0.21/flightkit.min.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1001,14 +1001,14 @@

if (templateItem) {
if (annotation[property] && annotation[property][templateItem]) {
replacement = annotation[property][templateItem];
replacement = annotation[property][templateItem].trim();
}
else {
replacement = templateItem;
replacement = templateItem.trim();
}
}

return Array.isArray(replacement) ? replacement.join(', ') : replacement.toString().trim();
return Array.isArray(replacement) ? replacement.join(', ') : replacement.toString();
});
}

Expand Down Expand Up @@ -1625,6 +1625,9 @@
selectedElements = [];
_setup = true;

/** Keep track of bubbling event, because we cannot stop propagation, it conflicts with things like dropdown */
_lastEventEmitted = 0;

/** To make it so, something will not collapse when clicking, remember that we filtered, so the next click action will not close if open. */
_justFiltered = false;

Expand All @@ -1639,13 +1642,14 @@
return [...new Set(getAllValuesAndKeysFromJson(json))];
}

_emit(event, ftElement, detail) {
_emit(event, flkElement, detail) {
detail.fkTreeEvent = true;
let selectEvent = new CustomEvent(event, {
detail,
bubbles: true,
cancelable: true
});
ftElement.dispatchEvent(selectEvent);
flkElement.dispatchEvent(selectEvent);
}

constructor() {
Expand Down Expand Up @@ -1686,15 +1690,23 @@
}

emitNodeToggle(event) {
event.stopPropagation();

/** Clicked in between items in a list, ignore. */
if (["LI", "UL"].includes(event.target.tagName)) {
return false;
}

const flkEvent = returnEventWithTopLevelElement(event, 'flk-tree-nav');
const flkElement = flkEvent.target;

/** Check if an event bubbled, so we do not do it twice. */
var lastEventEmitted = flkElement._lastEventEmitted;
flkElement._lastEventEmitted = event.timeStamp;

if (lastEventEmitted !== 0) {
var noSignificantChange = event.timeStamp - lastEventEmitted < 30;
if (noSignificantChange) {
return false;
}
}
const item = returnDataSetValue(event, 'branchKey');
const depth = parseInt(returnDataSetValue(event, 'depth'));
let data = flkElement.contents;
Expand Down
1 change: 1 addition & 0 deletions dist/flightkit-v0.0.22/flightkit.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.22/avian.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.22/flightkit.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.22/htmx-ibiss-ui.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.22/rocket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/js/flightkit.min.js

Large diffs are not rendered by default.

46 changes: 0 additions & 46 deletions docs/screen-properties.html

This file was deleted.

1 change: 1 addition & 0 deletions documentation/public/cdn/ibiss-v0.0.22/avian.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions documentation/public/cdn/ibiss-v0.0.22/flightkit.min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions documentation/public/cdn/ibiss-v0.0.22/rocket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion documentation/public/js/flightkit.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions flightkit/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,14 @@ export class FlightkitTable extends HTMLElement {

if (templateItem) {
if (annotation[property] && annotation[property][templateItem]) {
replacement = annotation[property][templateItem]
replacement = annotation[property][templateItem].trim();
}
else {
replacement = templateItem;
replacement = templateItem.trim();
}
}

return Array.isArray(replacement) ? replacement.join(', ') : replacement.toString().trim();
return Array.isArray(replacement) ? replacement.join(', ') : replacement.toString();
});
}

Expand Down
21 changes: 16 additions & 5 deletions flightkit/components/tree-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class FlightkitTreeNavigation extends HTMLElement {
selectedElements = [];
_setup = true;

/** Keep track of bubbling event, because we cannot stop propagation, it conflicts with things like dropdown */
_lastEventEmitted = 0;

/** To make it so, something will not collapse when clicking, remember that we filtered, so the next click action will not close if open. */
_justFiltered = false;

Expand All @@ -32,13 +35,13 @@ export class FlightkitTreeNavigation extends HTMLElement {
return [...new Set(getAllValuesAndKeysFromJson(json))];
}

_emit(event, ftElement, detail) {
_emit(event, flkElement, detail) {
let selectEvent = new CustomEvent(event, {
detail,
bubbles: true,
cancelable: true
});
ftElement.dispatchEvent(selectEvent);
flkElement.dispatchEvent(selectEvent);
}

constructor() {
Expand Down Expand Up @@ -79,15 +82,23 @@ export class FlightkitTreeNavigation extends HTMLElement {
}

emitNodeToggle(event) {
event.stopPropagation();

/** Clicked in between items in a list, ignore. */
if (["LI", "UL"].includes(event.target.tagName)) {
return false;
}

const flkEvent = returnEventWithTopLevelElement(event, 'flk-tree-nav');
const flkElement = flkEvent.target;

/** Check if an event bubbled, so we do not do it twice. */
var lastEventEmitted = flkElement._lastEventEmitted;
flkElement._lastEventEmitted = event.timeStamp;

if (lastEventEmitted !== 0) {
var noSignificantChange = event.timeStamp - lastEventEmitted < 30
if (noSignificantChange) {
return false;
}
}
const item = returnDataSetValue(event, 'branchKey');
const depth = parseInt(returnDataSetValue(event, 'depth'));
let data = flkElement.contents;
Expand Down
15 changes: 5 additions & 10 deletions flightkit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<body class="row gap-5 p-3">
<div>
<input class="mb-2" type="text" id="table-filter" placeholder="filter">
<flk-table class="bg-white striped" id="db-table" pagination="1|20" e-paginate="maxPages">
<flk-table class="bg-white striped" id="db-table" pagination="1|20">
<template name="column1">
<div title="{{ +notes }}">{{ $fooifier }} + {{ column6 }}</div>
</template>
<template name="column3">
<i>{{ column3 }}</i>
<i>{{ column3 }}</i>
</template>
</flk-table>
</div>
Expand All @@ -48,7 +48,7 @@
max-depth="1"></flk-tree-nav>
</div>

<flk-tree-nav id="databases" icon-set="database" max-depth="3" e-tree-click="clicky" e-loaded="log"> </flk-tree-nav>
<flk-tree-nav id="databases" icon-set="database" max-depth="3" e-tree-click="clicky"> </flk-tree-nav>

<code>
Click on a tree to get the Preview
Expand All @@ -67,14 +67,9 @@
}

var myDbNav;
function log(e) {
console.log('loaded!')
}
function maxPages(e) {
console.log(e)
}
function clicky(e) {

function clicky(e) {
console.log(e)
let previewEl = document.getElementById('clicky-preview')
previewEl.innerText = JSON.stringify(e.contents, null, 4);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@pennions/ibiss",
"version": "0.0.21",
"version": "0.0.22",
"avian_version": "0.0.2",
"flightkit_version": "0.0.21",
"flightkit_version": "0.0.22",
"htmx_plugin_version": "0.0.1",
"rocketjs_version": "0.0.1",
"description": "Frontend library of Pennions",
Expand Down

0 comments on commit 934b0fc

Please sign in to comment.