soiz1 commited on
Commit
23e51a6
·
verified ·
1 Parent(s): 6fa3b2e

Update dev-tools.js

Browse files
Files changed (1) hide show
  1. dev-tools.js +108 -3
dev-tools.js CHANGED
@@ -717,7 +717,8 @@
717
  }
718
 
719
  // Elementsパネルの作成
720
- function createElementsPanel() {
 
721
  const panel = document.createElement('div');
722
  panel.className = 'devtools-panel';
723
  panel.id = 'elements-panel';
@@ -737,7 +738,7 @@
737
  container.appendChild(cssPanel);
738
  panel.appendChild(container);
739
 
740
- // CSSパネルを更新
741
  function updateCSSPanel(element) {
742
  const cssPanel = document.getElementById('css-panel');
743
  cssPanel.innerHTML = '';
@@ -827,6 +828,110 @@
827
  cssPanel.appendChild(computedRule);
828
  }
829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
830
  // CSSプロパティを編集
831
  function editCSSProperty(element, propName, styleType) {
832
  let currentValue = '';
@@ -853,7 +958,7 @@
853
  }, 0);
854
 
855
  return panel;
856
- }
857
 
858
  function refreshElementsPanel() {
859
  let tree = document.getElementById('dom-tree');
 
717
  }
718
 
719
  // Elementsパネルの作成
720
+ // Elementsパネルの作成
721
+ function createElementsPanel() {
722
  const panel = document.createElement('div');
723
  panel.className = 'devtools-panel';
724
  panel.id = 'elements-panel';
 
738
  container.appendChild(cssPanel);
739
  panel.appendChild(container);
740
 
741
+ // CSSパネルを更新する関数を外部からもアクセス可能にする
742
  function updateCSSPanel(element) {
743
  const cssPanel = document.getElementById('css-panel');
744
  cssPanel.innerHTML = '';
 
828
  cssPanel.appendChild(computedRule);
829
  }
830
 
831
+ // DOMツリーを構築する関数
832
+ function buildDOMTree(node, parentElement, depth = 0) {
833
+ if (node.nodeType === Node.ELEMENT_NODE) {
834
+ const element = document.createElement('div');
835
+ element.className = 'dom-node';
836
+ element.style.marginLeft = `${depth * 15}px`;
837
+ element.dataset.elementId = node.id || Math.random().toString(36).substr(2, 9);
838
+
839
+ // 右クリックイベント
840
+ element.oncontextmenu = (e) => {
841
+ e.preventDefault();
842
+ selectedElement = node;
843
+ selectedDOMNode = element;
844
+
845
+ document.querySelectorAll('.dom-node').forEach(el => el.classList.remove('selected'));
846
+ element.classList.add('selected');
847
+
848
+ contextMenu.style.display = 'block';
849
+ contextMenu.style.left = `${e.pageX}px`;
850
+ contextMenu.style.top = `${e.pageY}px`;
851
+
852
+ updateCSSPanel(node); // ここでupdateCSSPanelを呼び出し
853
+ };
854
+
855
+ // クリックで選択
856
+ element.onclick = (e) => {
857
+ e.stopPropagation();
858
+ selectedElement = node;
859
+ selectedDOMNode = element;
860
+
861
+ document.querySelectorAll('.dom-node').forEach(el => el.classList.remove('selected'));
862
+ element.classList.add('selected');
863
+
864
+ updateCSSPanel(node); // ここでupdateCSSPanelを呼び出し
865
+ };
866
+
867
+ // タグ名
868
+ const tag = document.createElement('span');
869
+ tag.className = 'dom-tag editable';
870
+ tag.textContent = `<${node.tagName.toLowerCase()}`;
871
+ tag.onclick = (e) => {
872
+ e.stopPropagation();
873
+ startInlineEdit(tag, node.tagName.toLowerCase(), (newValue) => {
874
+ const newElement = document.createElement(newValue);
875
+ Array.from(node.attributes).forEach(attr => {
876
+ newElement.setAttribute(attr.name, attr.value);
877
+ });
878
+ newElement.innerHTML = node.innerHTML;
879
+ node.parentNode.replaceChild(newElement, node);
880
+ selectedElement = newElement;
881
+ refreshElementsPanel();
882
+ });
883
+ };
884
+ element.appendChild(tag);
885
+
886
+ // 属性
887
+ Array.from(node.attributes).forEach(attr => {
888
+ const attrSpan = document.createElement('span');
889
+ attrSpan.className = 'dom-attr editable';
890
+ attrSpan.textContent = ` ${attr.name}="${attr.value}"`;
891
+ attrSpan.onclick = (e) => {
892
+ e.stopPropagation();
893
+ startInlineEdit(attrSpan, attr.value, (newValue) => {
894
+ node.setAttribute(attr.name, newValue);
895
+ refreshElementsPanel();
896
+ });
897
+ };
898
+ element.appendChild(attrSpan);
899
+ });
900
+
901
+ element.appendChild(document.createTextNode('>'));
902
+
903
+ // 子要素
904
+ if (node.childNodes.length > 0) {
905
+ node.childNodes.forEach(child => {
906
+ buildDOMTree(child, element, depth + 1);
907
+ });
908
+ }
909
+
910
+ // 閉じタグ
911
+ if (node.childNodes.length > 0 || node.tagName.toLowerCase() !== 'br') {
912
+ const closeTag = document.createElement('div');
913
+ closeTag.style.marginLeft = `${depth * 15}px`;
914
+ closeTag.innerHTML = `<span class="dom-tag">&lt;/${node.tagName.toLowerCase()}&gt;</span>`;
915
+ element.appendChild(closeTag);
916
+ }
917
+
918
+ parentElement.appendChild(element);
919
+ } else if (node.nodeType === Node.TEXT_NODE && node.textContent.trim()) {
920
+ const text = document.createElement('div');
921
+ text.style.marginLeft = `${depth * 15}px`;
922
+ text.className = 'dom-text editable';
923
+ text.textContent = `"${node.textContent.trim()}"`;
924
+ text.onclick = (e) => {
925
+ e.stopPropagation();
926
+ startInlineEdit(text, node.textContent.trim(), (newValue) => {
927
+ node.textContent = newValue;
928
+ refreshElementsPanel();
929
+ });
930
+ };
931
+ parentElement.appendChild(text);
932
+ }
933
+ }
934
+
935
  // CSSプロパティを編集
936
  function editCSSProperty(element, propName, styleType) {
937
  let currentValue = '';
 
958
  }, 0);
959
 
960
  return panel;
961
+ }
962
 
963
  function refreshElementsPanel() {
964
  let tree = document.getElementById('dom-tree');