Skip to content

Commit

Permalink
chore: added hashmaps for uuid and improved rendering; fix: fixed bug…
Browse files Browse the repository at this point in the history
… where sometimes a leaf was not show selected
  • Loading branch information
Veen committed Aug 6, 2024
1 parent 75fe7e6 commit 2d4815f
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 78 deletions.
1 change: 0 additions & 1 deletion dist/flightkit-v0.0.13/flightkit.min.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,37 @@
const guid = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
/** This will be unique enough */
const newGuid = guid.split('-')[0];

if (!window.$flightkitUUIDStore) {
window.$flightkitUUIDStore = [];
window.$flightkitUUIDStore = {};
}

/** verify to be absolutely sure ;) */
if (window.$flightkitUUIDStore.some(guid => guid === newGuid)) {
if (window.$flightkitUUIDStore[guid] !== undefined) {
return uuidv4();
}
else {
window.$flightkitUUIDStore.push(newGuid);
return newGuid;
window.$flightkitUUIDStore[guid] = true;
return guid;
}
}
function variableUID(length = 3) {
let guid = 'x'.repeat(length).replace(/[x]/g, () =>
(crypto.getRandomValues(new Uint8Array(1))[0] & 0xf).toString(16)
);

if (!window.$flightkitUUIDStore) {
window.$flightkitUUIDStore = {};
}

/** verify to be absolutely sure ;) */
if (window.$flightkitUUIDStore[guid] !== undefined) {
/** if we did hit it, make sure we limit the amount of hits by just adding to the length */
return variableUID(length + 1);
}
else {
window.$flightkitUUIDStore[guid] = true;
return guid;
}
}

Expand Down Expand Up @@ -1423,17 +1440,12 @@
};

_jsonToValueArray(json) {

let jsonString = JSON.stringify(json);
/** replace any array and object brackets */
jsonString = jsonString.replace(/[\[\]{}\"]/g, "");
let jsonKeyValueArray = jsonString.split(',');
let values = [];

for (const kvPair of jsonKeyValueArray) {
values = values.concat(kvPair.split(":"));
if (Array.isArray(json)) {
return [...new Set(json.flatMap(Object.values))];
}
else {
return Object.values(json)
}
return [...new Set(values)];
}

_emit(event, ftElement, detail) {
Expand Down Expand Up @@ -1493,7 +1505,7 @@
else if (data[crumb] === null) {
data = null;
}
else {
else if (Array.isArray(data)) {
/** Dealing with an array of objects */
let extractedData = [];
for (const obj of data) {
Expand All @@ -1520,12 +1532,9 @@

if (flkElement.selectedElements.length) {
flkElement.deselectTree();
flkElement.selectedElements = [];
}

// flkElement.previousElements = flkElement.selectedElements;
flkElement.selectedElements = [];


if (parent.tagName === 'DETAILS') {
flkElement.selectedElements.push(parent.childNodes[0]);

Expand All @@ -1536,6 +1545,9 @@
}
else {
flkElement.selectedElements.push(parent);
if (parent.childNodes.length && parent.childNodes[0].tagName === 'DIV') {
flkElement.selectedElements = parent.childNodes[0].childNodes;
}
}

for (const selectedElement of flkElement.selectedElements) {
Expand Down Expand Up @@ -1769,15 +1781,9 @@
leaf.style.left = '2px';
let leafText = document.createElement('span');

let branchValueId = uuidv4();

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

let branchValueId = variableUID();
leafText.dataset.branchValueId = branchValueId;

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

Expand Down Expand Up @@ -1838,13 +1844,8 @@
let branch = document.createElement('details');
branch.classList.add('flk-branch');
/** set values as we go down, for easy filtering */
let branchValueId = uuidv4();
let branchValueId = variableUID();

/** 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. */

Expand Down
1 change: 1 addition & 0 deletions dist/flightkit-v0.0.14/flightkit.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/cdn/ibiss-v0.0.14/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.14/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.14/avian.min.css

Large diffs are not rendered by default.

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

45 changes: 14 additions & 31 deletions flightkit/components/tree-navigation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { folderListIcon, fileListIcon, databaseListIcon, tableListIcon, columnListIcon } from '../flightkit-functions/icons';
import { returnDataSetValue, returnEventWithTopLevelElement } from '../flightkit-functions/domTraversal';
import { BaseComponent } from './extensions/base_component';
import { uuidv4 } from '../flightkit-functions/uuid_v4';
import { variableUID } from '../flightkit-functions/uuid_v4';

export class FlightkitTreeNavigation extends HTMLElement {
base;
Expand All @@ -23,17 +23,12 @@ export class FlightkitTreeNavigation extends HTMLElement {
};

_jsonToValueArray(json) {

let jsonString = JSON.stringify(json);
/** replace any array and object brackets */
jsonString = jsonString.replace(/[\[\]{}\"]/g, "");
let jsonKeyValueArray = jsonString.split(',');
let values = [];

for (const kvPair of jsonKeyValueArray) {
values = values.concat(kvPair.split(":"));
if (Array.isArray(json)) {
return [...new Set(json.flatMap(Object.values))];
}
else {
return Object.values(json)
}
return [...new Set(values)];
}

_emit(event, ftElement, detail) {
Expand Down Expand Up @@ -93,7 +88,7 @@ export class FlightkitTreeNavigation extends HTMLElement {
else if (data[crumb] === null) {
data = null
}
else {
else if (Array.isArray(data)) {
/** Dealing with an array of objects */
let extractedData = [];
for (const obj of data) {
Expand All @@ -120,12 +115,9 @@ export class FlightkitTreeNavigation extends HTMLElement {

if (flkElement.selectedElements.length) {
flkElement.deselectTree();
flkElement.selectedElements = [];
}

// flkElement.previousElements = flkElement.selectedElements;
flkElement.selectedElements = [];


if (parent.tagName === 'DETAILS') {
flkElement.selectedElements.push(parent.childNodes[0]);

Expand All @@ -136,6 +128,9 @@ export class FlightkitTreeNavigation extends HTMLElement {
}
else {
flkElement.selectedElements.push(parent)
if (parent.childNodes.length && parent.childNodes[0].tagName === 'DIV') {
flkElement.selectedElements = parent.childNodes[0].childNodes
}
}

for (const selectedElement of flkElement.selectedElements) {
Expand Down Expand Up @@ -315,7 +310,6 @@ export class FlightkitTreeNavigation extends HTMLElement {
this.filterTree();
}


createLeafText(text) {
let hasComment = typeof text === 'string' && this.commentType.length ? text.includes(this.commentType[0]) : false;

Expand Down Expand Up @@ -369,15 +363,9 @@ export class FlightkitTreeNavigation extends HTMLElement {
leaf.style.left = '2px';
let leafText = document.createElement('span');

let branchValueId = uuidv4();

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

let branchValueId = variableUID();
leafText.dataset.branchValueId = branchValueId;

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

Expand Down Expand Up @@ -438,13 +426,8 @@ export class FlightkitTreeNavigation extends HTMLElement {
let branch = document.createElement('details');
branch.classList.add('flk-branch');
/** set values as we go down, for easy filtering */
let branchValueId = uuidv4();
let branchValueId = variableUID();

/** 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. */

Expand Down
Loading

0 comments on commit 2d4815f

Please sign in to comment.