Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/titles performance tree nav #31

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/flightkit-v0.0.12/flightkit.min.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,9 @@
filter = { value: '', caseSensitive: false };
selectedElements = [];

/** making a dictionary for the tree values so that it is not rendered in the dom for large trees */
_treeValues = {}

static get observedAttributes() {
return ['contents', 'icon-set', 'max-depth', 'filter', 'search-style', 'comment'];
};
Expand Down Expand Up @@ -1528,7 +1531,6 @@

/** for when we have 2 spans */
if (parent.childNodes.length && parent.childNodes[0].childNodes.length && parent.childNodes[0].childNodes[0].tagName === 'DIV') {
console.log(parent.childNodes[0].childNodes);
flkElement.selectedElements = parent.childNodes[0].childNodes[0].childNodes;
}
}
Expand All @@ -1555,9 +1557,9 @@

if (typeof jsonKey !== 'string') jsonKey = jsonKey.toString();

const result = jsonKey.replace(/([A-Z_])/g, ($1) => {
const result = jsonKey.replace(/([-_])/g, ($1) => {
if ($1 === "_") return " ";
else return ` ${$1}`;
else return $1;
}).trim();
const convertedKey = result.charAt(0).toUpperCase() + result.slice(1);
return convertedKey;
Expand Down Expand Up @@ -1594,18 +1596,26 @@
const detailsEl = element.tagName.toLowerCase() === 'details';

/** doing a little bit more magic. Only open if a child is found that matches */
let childElements = element.dataset.branchValues.split(',');
let childElements = structuredClone(this._treeValues[element.dataset.branchValueId]);

const isBranch = Array.isArray(childElements);

/** When it is a leaf. */
let allValues = isBranch ? childElements.join() : childElements;

/** remove the branch */
childElements.shift();
if (isBranch) {
childElements.shift();
}

let childValues = childElements.join();
let childValues = isBranch ? childElements.join() : '';

if (this.filter.caseSensitive) {
match = element.dataset.branchValues.includes(this.filter.value);
match = allValues.includes(this.filter.value);
childMatch = childValues.includes(this.filter.value);
}
else {
match = element.dataset.branchValues.toLowerCase().includes(this.filter.value.toLowerCase());
match = allValues.toLowerCase().includes(this.filter.value.toLowerCase());
childMatch = childValues.toLowerCase().includes(this.filter.value.toLowerCase());
}

Expand All @@ -1632,7 +1642,7 @@
}

resetTree(all = true) {
let foundElements = this.querySelectorAll('[data-branch-values]');
let foundElements = this.querySelectorAll('[data-branch-value-id]');

for (const element of foundElements) {
element.parentElement.style.opacity = '';
Expand Down Expand Up @@ -1660,7 +1670,7 @@

filterTree() {
let searchTimer = setTimeout(() => {
let foundElements = this.querySelectorAll('[data-branch-values]');
let foundElements = this.querySelectorAll('[data-branch-value-id]');

for (const element of foundElements) {

Expand Down Expand Up @@ -1759,8 +1769,18 @@
leaf.style.left = '2px';
let leafText = document.createElement('span');

let branchValueId = uuidv4();

/** making sure it is unique. */
while (this._treeValues[branchValueId]) {
branchValueId = uuidv4();
}

leafText.dataset.branchValueId = branchValueId;

let allBranchValues = [text].concat(branchValues);
leafText.dataset.branchValues = [...new Set(allBranchValues)].join();
this._treeValues[branchValueId] = [...new Set(allBranchValues)].join();

/** to get the leaf */
leafText.dataset.leafKey = allBranchValues[0];

Expand Down Expand Up @@ -1789,6 +1809,7 @@
let leafNodes = Array.isArray(node) ? node : Object.keys(node);

for (const leaf of leafNodes) {

let branchValues;
if (node[leaf]) {
branchValues = this._jsonToValueArray(node[leaf]);
Expand Down Expand Up @@ -1817,7 +1838,15 @@
let branch = document.createElement('details');
branch.classList.add('flk-branch');
/** set values as we go down, for easy filtering */
branch.dataset.branchValues = [nodeKey].concat(this._jsonToValueArray(node[nodeKey])); /** also want to key above. */
let branchValueId = uuidv4();

/** making sure it is unique. */
while (this._treeValues[branchValueId]) {
branchValueId = uuidv4();
}

branch.dataset.branchValueId = branchValueId;
this._treeValues[branchValueId] = [nodeKey].concat(this._jsonToValueArray(node[nodeKey])); /** also want to key above. */

/** fix offset for custom icon */
branch.style.position = 'relative';
Expand Down
1 change: 1 addition & 0 deletions dist/flightkit-v0.0.13/flightkit.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.13/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.13/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.

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions documentation/public/cdn/ibiss-v0.0.13/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.13/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.

Loading