|
340 | 340 |
|
341 | 341 | </template>
|
342 | 342 |
|
| 343 | +<!-- <script setup> |
| 344 | +import { useExportComponent } from "./composables/useExportComponent.js"; |
| 345 | +import { mapState, mapActions } from "vuex"; |
| 346 | +import VueDraggableResizable from "vue-draggable-resizable/src/components/vue-draggable-resizable.vue"; |
| 347 | +import VueMultiselect from "vue-multiselect"; |
| 348 | +import "vue-draggable-resizable/src/components/vue-draggable-resizable.css"; |
| 349 | +import 'vue3-draggable-resizable/dist/Vue3DraggableResizable.css' |
| 350 | +import { ColorPicker } from 'vue-accessible-color-picker' |
| 351 | +import { useStore } from "vuex"; |
| 352 | +import { ref, computed, onMounted, watch } from "vue"; |
| 353 | +
|
| 354 | +const { fs, ipcRenderer } = window; |
| 355 | +
|
| 356 | +const cloneDeep = require("lodash.clonedeep"); |
| 357 | +
|
| 358 | +const store = useStore(); |
| 359 | +const modalOpen = ref(false); |
| 360 | +const noteText = ref(''); |
| 361 | +const wasDragged = ref(false); |
| 362 | +const testModel = ref([]); |
| 363 | +const noteModal = ref(false); |
| 364 | +const colorModal = ref(false); |
| 365 | +const mockImg = ref(false); |
| 366 | +const htmlElements = ref([]); |
| 367 | +const childrenSelected = ref([]); |
| 368 | +const boxes = ref<HTMLElement>(null) |
| 369 | +
|
| 370 | +
|
| 371 | +
|
| 372 | +onMounted(() => { |
| 373 | + console.log(boxes.value, "onmounted boxes.value") |
| 374 | + // listener for the copy |
| 375 | + window.addEventListener("copy", () => { |
| 376 | + // if there is an activeComponent, copy info to state using dispatch |
| 377 | + if (activeComponent !== '' && noteModalOpen === false) { |
| 378 | + store.dispatch("copyActiveComponent"); |
| 379 | + } |
| 380 | + }); |
| 381 | + window.addEventListener("paste", () => { |
| 382 | + if (noteModalOpen === false) { |
| 383 | + store.dispatch("pasteActiveComponent"); |
| 384 | + } |
| 385 | + }); |
| 386 | + }) |
| 387 | +
|
| 388 | + //computed |
| 389 | + const routes = computed(() => store.state.routes); |
| 390 | + const activeRoute = computed(() => store.state.activeRoute); |
| 391 | + const activeComponent = computed(() => store.state.activeComponent); |
| 392 | + const componentMap = computed(() => store.state.componentMap); |
| 393 | + const componentChildrenMultiselectValue = computed(() => store.state.componentChildrenMultiselectValue); |
| 394 | + const imagePath = computed(() => store.state.imagePath); |
| 395 | + const activeComponentObj = computed(() => store.state.activeComponentObj); |
| 396 | + const exportAsTypescript = computed(() => store.state.exportAsTypescript); |
| 397 | + const noteModalOpen = computed(() => store.state.noteModalOpen); |
| 398 | + const activeRouteDisplay = computed(() => store.state.activeRouteDisplay); |
| 399 | + const selectedElementList = computed(() => store.state.selectedElementList); |
| 400 | + const activeLayer = computed(() => store.state.activeLayer); |
| 401 | + const colorModalOpen = computed(() => store.state.colorModalOpen); |
| 402 | + const gridLayout = computed(() => store.state.gridLayout); |
| 403 | + const containerH = computed(() => store.state.containerH); |
| 404 | + const containerW = computed(() => store.state.containerW); |
| 405 | + |
| 406 | + // used in VueDraggableResizeable component |
| 407 | + const activeRouteArray = computed(() => { |
| 408 | + return routes[activeRoute]; |
| 409 | + }) |
| 410 | +
|
| 411 | + // used to delete active component |
| 412 | + const activeComponentData = computed(() => { |
| 413 | + // Must deep clone this so we are not directly mutating state |
| 414 | + // return this.activeComponentObj; |
| 415 | + return cloneDeep(activeComponentObj); |
| 416 | + }) |
| 417 | + |
| 418 | + const options = computed(() => { |
| 419 | + if (activeComponent !== '') { |
| 420 | + childrenSelected = []; |
| 421 | + childrenSelected = componentMap[activeComponent].children; |
| 422 | + } else { |
| 423 | + childrenSelected = []; |
| 424 | + } |
| 425 | + const compMap = componentMap; |
| 426 | + const activeComp = activeComponent; |
| 427 | + const val = routes[activeRoute].map( |
| 428 | + (component) => component.componentName |
| 429 | + ); |
| 430 | + const relatives = [...val] |
| 431 | + //also need to filter out any parents |
| 432 | + let parentalLineage = []; |
| 433 | + findLineage(relatives) |
| 434 | + function findLineage(children) { |
| 435 | + children.forEach((el) => { |
| 436 | + parentalLineage.push(el); |
| 437 | + if (compMap[el].children.length > 0) { |
| 438 | + findLineage(compMap[el].children); |
| 439 | + } |
| 440 | + if (el !== activeComp) { |
| 441 | + parentalLineage.pop(); |
| 442 | + } else { |
| 443 | + return; |
| 444 | + } |
| 445 | + }) |
| 446 | + } |
| 447 | + const optionOutput = val.filter(el => !parentalLineage.includes(el)).filter(el => el !== this.activeComponent); |
| 448 | + return optionOutput; |
| 449 | + }); |
| 450 | +
|
| 451 | + const userImage = computed(() => { |
| 452 | + const imgSrc = `file://` + imagePath[activeRoute]; |
| 453 | + return imgSrc; |
| 454 | + }) |
| 455 | +
|
| 456 | + // updates display with mockup image |
| 457 | + const mockBg = computed(() => { |
| 458 | + return imagePath[activeRoute] |
| 459 | + ? { |
| 460 | + background: `url("${userImage}") no-repeat rgba(223, 218, 218, 0.886) top left`, |
| 461 | + "background-size": "contain" |
| 462 | + } |
| 463 | + : {}; |
| 464 | + }) |
| 465 | +
|
| 466 | + // find the amount of grid lines for width |
| 467 | + const gridWidth = computed(() => { |
| 468 | + return containerW / gridLayout[0]; |
| 469 | + }) |
| 470 | +
|
| 471 | + // find the amount of grid lines for height |
| 472 | + const gridHeight = computed(() => { |
| 473 | + return containerH / gridLayout[1]; |
| 474 | + }) |
| 475 | + |
| 476 | +
|
| 477 | +const updated = computed(() => { |
| 478 | + // if there are no active components, all boxes are unhighlighted |
| 479 | + if (activeComponent === "") { |
| 480 | + if (boxes) { |
| 481 | + boxes.forEach((element) => { |
| 482 | + element.enabled = false; |
| 483 | + element.$emit("deactivated"); |
| 484 | + element.$emit("update:active", false); |
| 485 | + }); |
| 486 | + } |
| 487 | + } else { |
| 488 | + // if a component is set to active, highlight it |
| 489 | + boxes.forEach((element) => { |
| 490 | + if ( |
| 491 | + activeComponent === element.$attrs.id && |
| 492 | + element.enabled === false |
| 493 | + ) { |
| 494 | + element.enabled = true; |
| 495 | + element.$emit("activated"); |
| 496 | + element.$emit("update:active", true); |
| 497 | + } |
| 498 | + }); |
| 499 | + } |
| 500 | + }) |
| 501 | +
|
| 502 | +//methods |
| 503 | +const setActiveComponent = (payload) => store.dispatch("setActiveComponent", payload); |
| 504 | +const updateComponentChildrenMultiselectValue = (payload) => store.dispatch("updateComponentChildrenMultiselectValue", payload); |
| 505 | +const updateActiveComponentChildrenValue = (payload) => store.dispatch("updateActiveComponentChildrenValue", payload); |
| 506 | +const updateComponentPosition = (payload) => store.dispatch("updateComponentPosition", payload); |
| 507 | +const updateStartingPosition = (payload) => store.dispatch("updateStartingPosition", payload); |
| 508 | +const updateComponentLayer = (payload) => store.dispatch("updateComponentLayer", payload); |
| 509 | +const updateStartingSize = (payload) => store.dispatch("updateStartingSize", payload); |
| 510 | +const updateComponentSize = (payload) => store.dispatch("updateComponentSize", payload); |
| 511 | +const addActiveComponentNote = (payload) => store.dispatch("addActiveComponentNote", payload); |
| 512 | +const deleteActiveComponentNote = (payload) => store.dispatch("deleteActiveComponentNote", payload); |
| 513 | +const openNoteModal = (payload) => store.dispatch("openNoteModal", payload); |
| 514 | +const openColorModal = (payload) => store.dispatch("openColorModal", payload); |
| 515 | +const updateColor = (payload) => store.dispatch("updateColor", payload); |
| 516 | +const updateComponentGridPosition = (payload) => store.dispatch("updateComponentGridPosition", payload); |
| 517 | +
|
| 518 | +
|
| 519 | +const useExportComponentBound = () => { |
| 520 | + useExportComponent.bind(this)(); |
| 521 | + } |
| 522 | +
|
| 523 | +const isElementPlus = (htmlList) => { |
| 524 | + return htmlList.find(({ text }) => text[0] === 'e'); |
| 525 | + } |
| 526 | +
|
| 527 | + //color change function |
| 528 | +const updateColors = (data) => { |
| 529 | + let payload = { |
| 530 | + color: data.cssColor, |
| 531 | + activeComponent: activeComponent, |
| 532 | + routeArray: routes[activeRoute], |
| 533 | + activeComponentData: activeComponentData, |
| 534 | + } |
| 535 | + updateColor(payload) |
| 536 | + refresh(); |
| 537 | + } |
343 | 538 |
|
| 539 | + // sets component's ending size/position |
| 540 | +const finishedResize = (x, y, w, h) => { |
| 541 | + let payload = { |
| 542 | + x: x, |
| 543 | + y: y, |
| 544 | + w: w, |
| 545 | + h: h, |
| 546 | + activeComponent: activeComponent, |
| 547 | + routeArray: routes[activeRoute], |
| 548 | + activeComponentData: activeComponentData, |
| 549 | + }; |
| 550 | + updateComponentSize(payload); |
| 551 | + updateComponentGridPosition(payload); |
| 552 | + refresh(); |
| 553 | + } |
| 554 | +
|
| 555 | + // refresh function |
| 556 | +const refresh = () => { |
| 557 | + const payload = { |
| 558 | + activeComponent: activeComponent, |
| 559 | + routeArray: routes[activeRoute], |
| 560 | + activeComponentData: activeComponentData, |
| 561 | + z: activeComponentData.z, |
| 562 | + }; |
| 563 | + payload.z++; |
| 564 | + updateComponentLayer(payload); |
| 565 | + payload.z--; |
| 566 | + updateComponentLayer(payload); |
| 567 | + } |
| 568 | +
|
| 569 | + // drag and drop function |
| 570 | +const finishedDrag = (x, y) => { |
| 571 | + let payload = { |
| 572 | + x: x, |
| 573 | + y: y, |
| 574 | + activeComponent: activeComponent, |
| 575 | + routeArray: routes[activeRoute], |
| 576 | + activeComponentData: activeComponentData, |
| 577 | + }; |
| 578 | + updateComponentPosition(payload); |
| 579 | + updateComponentGridPosition(payload); |
| 580 | + wasDragged = true; |
| 581 | + setTimeout(() => wasDragged = false, 100) |
| 582 | + refresh(); |
| 583 | + } |
| 584 | +
|
| 585 | +const onActivated = (componentData) => { |
| 586 | + console.log(componentData, "this is compdata") |
| 587 | + if (!componentData) { |
| 588 | + return; |
| 589 | + } |
| 590 | + if (boxes) { |
| 591 | + boxes.forEach((element) => { |
| 592 | + if (element.$attrs.id !== componentData.componentName) { |
| 593 | + element.enabled = false; |
| 594 | + element.$emit("deactivated"); |
| 595 | + element.$emit("update:active", false); |
| 596 | + } |
| 597 | + if ( |
| 598 | + activeComponent === element.$attrs.id && |
| 599 | + element.enabled === false |
| 600 | + ) { |
| 601 | + element.enabled = true; |
| 602 | + element.$emit("activated"); |
| 603 | + element.$emit("update:active", true); |
| 604 | + } |
| 605 | + }); |
| 606 | + } |
| 607 | + if (!(componentData.componentName === activeComponent)) { |
| 608 | + setActiveComponent(componentData.componentName); |
| 609 | + } |
| 610 | + if (componentData && componentData.hasOwnProperty('componentName')) { |
| 611 | + activeComponentData.isActive = true; |
| 612 | + } |
| 613 | + } |
| 614 | +
|
| 615 | + // deactivated is emitted before activated |
| 616 | +const onDeactivated = () => { |
| 617 | + if (activeComponent !== "") { |
| 618 | + activeComponentData.isActive = false; |
| 619 | + } |
| 620 | + } |
| 621 | +
|
| 622 | + // renders modal with Update Children and Layer in it |
| 623 | +const handleAddNotes = () => { |
| 624 | + if (wasDragged === false && activeComponent !== '') { |
| 625 | + openNoteModal(); |
| 626 | + } |
| 627 | + } |
| 628 | +
|
| 629 | + //color editor - opens the pop up |
| 630 | +const handleEditColor = () => { |
| 631 | + if (wasDragged === false && activeComponent !== '') { |
| 632 | + openColorModal(); |
| 633 | + } |
| 634 | + } |
| 635 | +
|
| 636 | +const handleAddChild = () => { |
| 637 | + modalOpen = true; |
| 638 | + } |
| 639 | +
|
| 640 | +const submitNote = (e) => { |
| 641 | + e.preventDefault() |
| 642 | + if (noteText === '') { |
| 643 | + return; |
| 644 | + } |
| 645 | + addActiveComponentNote(noteText); |
| 646 | + noteText = ''; |
| 647 | + } |
| 648 | +
|
| 649 | +const deleteNote = (e) => { |
| 650 | + deleteActiveComponentNote(e.target.previousElementSibling.innerText); |
| 651 | + } |
| 652 | +
|
| 653 | + // used when user selects to add child from dropdown |
| 654 | +const handleSelect = (value) => { //actually handles adding or deleting |
| 655 | + updateActiveComponentChildrenValue(value); |
| 656 | + } |
| 657 | +
|
| 658 | + // user can change component's layer order |
| 659 | +const handleLayer = (e) => { |
| 660 | + e.preventDefault(); |
| 661 | + const payload = { |
| 662 | + activeComponent: activeComponent, |
| 663 | + routeArray: routes[activeRoute], |
| 664 | + activeComponentData: activeComponentData, |
| 665 | + z: activeComponentData.z, |
| 666 | + }; |
| 667 | +
|
| 668 | + if (e.target.innerText === "+") payload.z++; |
| 669 | + if (e.target.innerText === "–" && payload.z > 0) payload.z--; |
| 670 | + updateComponentLayer(payload); |
| 671 | + } |
| 672 | +
|
| 673 | + // if user clicks on display grid, resets active component to '' |
| 674 | +const handleClick = (event) => { |
| 675 | + if (event.target.className === "component-display grid-bg") { |
| 676 | + setActiveComponent(""); |
| 677 | + } |
| 678 | + } |
| 679 | +
|
| 680 | +const handleRight = (event) => { |
| 681 | + if (event.target.className === "component-display grid-bg") { |
| 682 | + //right click modal to make a component? |
| 683 | + } |
| 684 | + } |
| 685 | +
|
| 686 | + watch(noteModalOpen, () => { |
| 687 | + noteModal = noteModalOpen; |
| 688 | + }); |
| 689 | +
|
| 690 | + watch(colorModalOpen, () => { |
| 691 | + colorModal = colorModalOpen; |
| 692 | + }); |
| 693 | +
|
| 694 | + |
| 695 | + watch(activeComponent, () => { |
| 696 | + if (activeComponent !== '' && |
| 697 | + store.state.showTutorial === true && |
| 698 | + store.state.tutorialFirstOpen === true) { |
| 699 | + store.commit("TOGGLE_TUTORIAL"); |
| 700 | + } |
| 701 | + onActivated(activeComponentObj); |
| 702 | + } |
| 703 | +) |
| 704 | +</script> --> |
344 | 705 |
|
| 706 | +<!-- old options API script --> |
345 | 707 | <script>
|
346 | 708 | import { useExportComponent } from "./composables/useExportComponent.js";
|
347 | 709 | import { mapState, mapActions } from "vuex";
|
@@ -376,6 +738,7 @@ export default {
|
376 | 738 | };
|
377 | 739 | },
|
378 | 740 | mounted() {
|
| 741 | + // console.log(this.$refs.boxes, "this is this.refs.boxes mounted") |
379 | 742 | // listener for the copy
|
380 | 743 | window.addEventListener("copy", () => {
|
381 | 744 | // if there is an activeComponent, copy info to state using dispatch
|
|
0 commit comments