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

feat(id): produce UUID with generateId. move to /utils/Identifier.js #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions src/DiagramModel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import DiagramNode from "./DiagramNode";

var generateId = function() {
return Math.trunc(Math.random() * 1000);
};
import { generateId } from "./utils/Identifier";

/**
* @class DiagramModel
Expand Down
4 changes: 1 addition & 3 deletions src/DiagramNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var generateId = function() {
return Math.trunc(Math.random() * 1000);
};
import { generateId } from "./utils/Identifier";

/**
* @class DiagramNode
Expand Down
10 changes: 3 additions & 7 deletions src/components/Diagram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ import DiagramNode from "./DiagramNode";
import DiagramLink from "./DiagramLink";
import DiagramPort from "./DiagramPort";

var generateId = function() {
return Math.trunc(Math.random() * 1000);
};
import { generateId } from "./../utils/Identifier";

function getAbsoluteXY(element) {
var viewportElement = document.documentElement;
Expand Down Expand Up @@ -253,12 +251,10 @@ export default {

links[this.draggedItem.linkIndex].points[
this.draggedItem.pointIndex
].x =
coords.x;
].x = coords.x;
links[this.draggedItem.linkIndex].points[
this.draggedItem.pointIndex
].y =
coords.y;
].y = coords.y;
this.updateLinksPositions();
} else {
let coords = this.convertXYtoViewPort(this.mouseX, this.mouseY);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/Identifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Generate a UUID (v1)
* @param {Integer} c clock-seq-and-reserved clock-seq-low
* @return {String} The UUID
* http://www.rfcreader.com/#rfc4122_line385 allows random instead of MAC address
* https://www.famkruithof.net/uuid/uuidgen
* https://realityripple.com/Tools/UnUUID/
*/
export function generateId(c = 9999) {
const t = ((Date.now() + 12219292800000) * 1e4).toString(16);
const n = crypto.getRandomValues(new Uint8Array(6)).reduce((sum, x, i) => {
return sum + (i === 0 ? x | 1 : x).toString(16).padStart(2, "0");
}, "");
return `${t.slice(-8)}-${t.slice(-12, -8)}-1${t.slice(0, 3)}-${c}-${n}`;
}