Skip to content

Commit 6aa2346

Browse files
committed
同名ファイル選択後のchangeイベント発火など
同名ファイル選択後のchangeイベントを発火させる URLに?diagramを付ける style.cursor微調整 テキスト読み込みをawait file.text()に変更
1 parent a1572f5 commit 6aa2346

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
"kuma/no-boolean-member": "error",
1616
"kuma/no-boolean-in": "error",
1717
"kuma/no-eq-boolean": "error",
18+
"kuma/enforce-history-second-arg-empty": "error",
1819
"accessor-pairs": "error",
1920
"array-bracket-newline": "error",
2021
"array-bracket-spacing": "error",

index.htm

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
<script defer src="./src/index.js"></script>
2222
<!-- <script defer src="./src/tests/tests.js"></script> -->
2323
<link rel="stylesheet" href="./index.css">
24-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-143855243-2"></script>
24+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LGPQNL0DZH"></script>
2525
<script>
2626
window.dataLayer = window.dataLayer || [];
27-
function gtag() {
28-
dataLayer.push(arguments);
29-
}
30-
gtag("js", new Date());
31-
gtag("config", "UA-143855243-2");
27+
function gtag() { dataLayer.push(arguments); }
28+
gtag('js', new Date());
29+
gtag('config', 'G-LGPQNL0DZH');
3230
</script>
3331
</head>
3432

src/index.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
let l_previous_click_diagram_global;
55
let initialize_Maps_global;
66

7+
/**
8+
* 初期状態でURLからsearchとhashを除く。
9+
*/
10+
const s_initial_url_global = location.href.match(/\/([^/#?]*)(?:[#?][^/]*)?$/u)[1];
11+
712
const s_START_color_global = "#ffcaea";
813

914
const e_input_screen_global = document.getElementById("input_screen");
@@ -12,7 +17,7 @@
1217
const e_diagram_global = document.getElementById("diagram");
1318
const e_mermaid_code_global = document.getElementById("mermaid_code");
1419

15-
history.replaceState({ "number": 0 }, "");
20+
history.replaceState({ "number": 0 }, "", s_initial_url_global);
1621

1722
const escape_code = (s_mermaid_code) => s_mermaid_code.replaceAll(/\\/gu, "\\\\").replaceAll(/[_@*]/gu, "\\$&");
1823

@@ -96,7 +101,7 @@
96101
/**
97102
* Object.create(null) としたのは o_functions={} なら if 条件の判定 o_functions[o_function_flow.s_to] でエラーになる場合があるため。
98103
* o_function_flow.s_to がプロトタイプ名と被ったときプロパティ名が最初から存在すると判定されてしまう。
99-
* if 条件の判定ほうも Object.hasOwnProperty.call に変更した。
104+
* if 条件判定のほうも Object.hasOwnProperty.call に変更した。
100105
*/
101106
const o_functions = Object.create(null);
102107

@@ -383,9 +388,9 @@
383388
e_output_screen_global.style.display = "none";
384389

385390
e_input_screen_global.classList.remove("dragenter");
386-
document.body.style.cursor = "initial";
391+
document.body.style.cursor = "";
387392

388-
history.replaceState({ "number": 0 }, "");
393+
history.replaceState({ "number": 0 }, "", s_initial_url_global);
389394
};
390395

391396
if (s_code_global === void 0) {
@@ -469,10 +474,10 @@
469474

470475
e_input_screen_global.classList.remove("dragenter");
471476
// eslint-disable-next-line require-atomic-updates
472-
document.body.style.cursor = "initial";
477+
document.body.style.cursor = "";
473478

474479
if (history.state?.number !== 1) {
475-
history.pushState({ "number": 1 }, "");
480+
history.pushState({ "number": 1 }, "", `${s_initial_url_global}?diagram`);
476481
}
477482
};
478483

@@ -484,22 +489,20 @@
484489
const e_select_file = document.getElementById("select_file");
485490
const e_body = document.body;
486491

487-
const l_change_file = () => {
492+
const l_change_file = async () => {
488493
const { files } = e_select_file;
489494
const file = files[0];
490495
const s_filename = file.name;
491496
s_filename_global = s_filename;
492497

493-
const reader = new FileReader();
498+
const s_code = await file.text();
494499

495-
reader.onload = () => {
496-
const s_code = reader.result;
497-
s_code_global = s_code;
500+
s_code_global = s_code;
498501

499-
update_output_screen(s_code, s_filename);
500-
};
502+
// eslint-disable-next-line require-atomic-updates
503+
e_select_file.value = "";
501504

502-
reader.readAsText(file);
505+
update_output_screen(s_code, s_filename);
503506
};
504507

505508
const l_dragenter_body = (e) => {
@@ -518,7 +521,7 @@
518521
}
519522
};
520523

521-
const l_drop_handler = (e) => {
524+
const l_drop_handler = async (e) => {
522525
e.preventDefault();
523526

524527
const item = [...e.dataTransfer.items].find((a) => a.kind === "file");
@@ -529,16 +532,11 @@
529532
const s_filename = file.name;
530533
s_filename_global = s_filename;
531534

532-
const reader = new FileReader();
533-
534-
reader.onload = () => {
535-
const s_code = reader.result;
536-
s_code_global = s_code;
535+
const s_code = await file.text();
537536

538-
update_output_screen(s_code, s_filename);
539-
};
537+
s_code_global = s_code;
540538

541-
reader.readAsText(file);
539+
update_output_screen(s_code, s_filename);
542540
};
543541

544542
const l_dragover_body = (e) => {

src/tests/test_1.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-vars */
12
/* eslint-disable new-cap */
23
/* eslint-disable no-undef */
34
/* eslint-disable no-var */
@@ -73,3 +74,17 @@ var o10 = {
7374
}
7475
}
7576
};
77+
78+
t = {
79+
"t2": "t3"
80+
};
81+
o11 = {
82+
[(1, t.t2)]() {
83+
test6();
84+
}
85+
};
86+
var o12 = {
87+
[(1, t.t2)]() {
88+
test6();
89+
}
90+
};

src/tests/test_1_export.js

+24
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ var o10 = {
6565
m1() { test5(); }
6666
}
6767
}
68+
};
69+
70+
t = {
71+
"t2": "t3"
72+
};
73+
o11 = {
74+
[(1, t.t2)]() {
75+
test6();
76+
}
77+
};
78+
var o12 = {
79+
[(1, t.t2)]() {
80+
test6();
81+
}
6882
};`;
6983

7084
export const expected = `[
@@ -127,5 +141,15 @@ export const expected = `[
127141
"s_from": "o10.a2.b1.m1",
128142
"s_to": "test5",
129143
"n_count": 1
144+
},
145+
{
146+
"s_from": "o11.?",
147+
"s_to": "test6",
148+
"n_count": 1
149+
},
150+
{
151+
"s_from": "o12.?",
152+
"s_to": "test6",
153+
"n_count": 1
130154
}
131155
]`;

0 commit comments

Comments
 (0)