Skip to content

Commit f81b7f1

Browse files
authored
Merge pull request #165 from takker99:extend-metadata
feat(patch): `update()`の第2引数から、`Page`の全データを取り出せるようにした
2 parents 7243e71 + 9fb16d4 commit f81b7f1

File tree

16 files changed

+66
-80
lines changed

16 files changed

+66
-80
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: denoland/setup-deno@v1
1111
with:
12-
deno-version: "1.36.1"
12+
deno-version: "v1.x"
1313
- name: Check fmt
1414
run: deno fmt --check
1515
- name: Run lint

.github/workflows/udd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: denoland/setup-deno@v1
1414
with:
15-
deno-version: "1.36.1"
15+
deno-version: "v1.x"
1616
- name: Update dependencies
1717
run: >
1818
deno run --allow-net --allow-read --allow-write=deps/

browser/dom/click.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export const holdDown = async (
5353
target: element,
5454
clientX: options.X,
5555
clientY: options.Y,
56-
pageX: options.X + window.scrollX,
57-
pageY: options.Y + window.scrollY,
56+
pageX: options.X + globalThis.scrollX,
57+
pageY: options.Y + globalThis.scrollY,
5858
});
5959
const mouseOptions = {
6060
button: options.button ?? 0,

browser/dom/extractCodeFiles.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { extractCodeFiles } from "./extractCodeFiles.ts";
22
import { Line } from "../../deps/scrapbox.ts";
33
import { assertSnapshot } from "../../deps/testing.ts";
4-
import sample from "./sample-lines1.json" assert { type: "json" };
4+
import sample from "./sample-lines1.json" with { type: "json" };
55

66
Deno.test("extractCodeFiles", async (t) => {
77
await assertSnapshot(

browser/dom/isHeightViewable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
export const isHeightViewable = (element: HTMLElement): boolean => {
66
const { top, bottom } = element.getBoundingClientRect();
7-
return top >= 0 && bottom <= window.innerHeight;
7+
return top >= 0 && bottom <= globalThis.innerHeight;
88
};

browser/dom/motion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const getVisibleLineCount = (): number => {
161161
if (clientHeight === undefined) {
162162
throw Error("Could not find .line:last-of-type");
163163
}
164-
return Math.round(window.innerHeight / clientHeight);
164+
return Math.round(globalThis.innerHeight / clientHeight);
165165
};
166166

167167
/** 半ページ上にスクロールする

browser/dom/open.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export const open = (
5858
options?.newTab !== false &&
5959
(options?.newTab === true || project !== scrapbox.Project.name)
6060
) {
61-
window.open(url);
61+
globalThis.open(url);
6262
return;
6363
}
6464
if (
6565
options?.reload !== false &&
6666
(options?.reload === true || project !== scrapbox.Project.name)
6767
) {
68-
window.open(url, "_self");
68+
globalThis.open(url, "_self");
6969
return;
7070
}
7171

browser/websocket/_codeBlock.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Change, Socket, wrap } from "../../deps/socket.ts";
2+
import { Page } from "../../deps/scrapbox-rest.ts";
23
import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
3-
import { HeadData } from "./pull.ts";
44
import { getProjectId, getUserId } from "./id.ts";
55
import { pushWithRetry } from "./_fetch.ts";
66

@@ -14,7 +14,7 @@ export interface CodeTitle {
1414
/** コミットを送信する一連の処理 */
1515
export const applyCommit = async (
1616
commits: Change[],
17-
head: HeadData,
17+
page: Page,
1818
projectName: string,
1919
pageTitle: string,
2020
socket: Socket,
@@ -26,9 +26,9 @@ export const applyCommit = async (
2626
]);
2727
const { request } = wrap(socket);
2828
return await pushWithRetry(request, commits, {
29-
parentId: head.commitId,
29+
parentId: page.commitId,
3030
projectId: projectId,
31-
pageId: head.pageId,
31+
pageId: page.id,
3232
userId: userId_,
3333
project: projectName,
3434
title: pageTitle,

browser/websocket/deletePage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const deletePage = async (
2020
options?: DeletePageOptions,
2121
): Promise<void> => {
2222
const [
23-
{ pageId, commitId: parentId, persistent },
23+
{ id: pageId, commitId: parentId, persistent },
2424
projectId,
2525
userId,
2626
] = await Promise.all([

browser/websocket/makeChanges.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { diffToChanges } from "./diffToChanges.ts";
2-
import type { Line } from "../../deps/scrapbox.ts";
3-
import { Block, Node, parse } from "../../deps/scrapbox.ts";
2+
import { Block, Line, Node, parse } from "../../deps/scrapbox.ts";
3+
import { Page } from "../../deps/scrapbox-rest.ts";
44
import type { Change } from "../../deps/socket.ts";
5-
import type { HeadData } from "./pull.ts";
65
import { toTitleLc } from "../../title.ts";
76
import { parseYoutube } from "../../parser/youtube.ts";
87

98
export interface Init {
109
userId: string;
11-
head: HeadData;
10+
page: Page;
1211
}
1312
export function* makeChanges(
1413
left: Pick<Line, "text" | "id">[],
1514
right: string[],
16-
{ userId, head }: Init,
15+
{ userId, page }: Init,
1716
): Generator<Change, void, unknown> {
1817
// 改行文字が入るのを防ぐ
1918
const right_ = right.flatMap((text) => text.split("\n"));
@@ -24,7 +23,7 @@ export function* makeChanges(
2423

2524
// titleの差分を入れる
2625
// 空ページの場合もタイトル変更commitを入れる
27-
if (left[0].text !== right_[0] || !head.persistent) {
26+
if (left[0].text !== right_[0] || !page.persistent) {
2827
yield { title: right_[0] };
2928
}
3029

@@ -38,18 +37,18 @@ export function* makeChanges(
3837
// リンクと画像の差分を入れる
3938
const [links, projectLinks, image] = findLinksAndImage(right_.join("\n"));
4039
if (
41-
head.links.length !== links.length ||
42-
!head.links.every((link) => links.includes(link))
40+
page.links.length !== links.length ||
41+
!page.links.every((link) => links.includes(link))
4342
) {
4443
yield { links };
4544
}
4645
if (
47-
head.projectLinks.length !== projectLinks.length ||
48-
!head.projectLinks.every((link) => projectLinks.includes(link))
46+
page.projectLinks.length !== projectLinks.length ||
47+
!page.projectLinks.every((link) => projectLinks.includes(link))
4948
) {
5049
yield { projectLinks };
5150
}
52-
if (head.image !== image) {
51+
if (page.image !== image) {
5352
yield { image };
5453
}
5554
}

0 commit comments

Comments
 (0)