Skip to content

Commit 091acae

Browse files
authored
Merge pull request #178 from takker99:jsr
build: Ready for publishing JSR
2 parents 8cf7b83 + 1eebf82 commit 091acae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2390
-196
lines changed

.github/workflows/ci.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,5 @@ jobs:
1010
- uses: denoland/setup-deno@v1
1111
with:
1212
deno-version: "v1.x"
13-
- name: Check fmt
14-
run: deno fmt --check
15-
- name: Run lint
16-
run: deno lint
17-
- name: Run type check
18-
run: deno check --remote ./**/*.ts
19-
- name: Run test
20-
run: deno test --allow-read --allow-write
13+
- name: Check fmt & lint & type check & test
14+
run: deno task check:dry

.github/workflows/publish.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# cf. https://jsr.io/@core/unknownutil/3.18.1/.github/workflows/jsr.yml
2+
name: publish
3+
4+
env:
5+
DENO_VERSION: 1.x
6+
7+
on:
8+
push:
9+
tags:
10+
- '*'
11+
12+
permissions:
13+
contents: read
14+
id-token: write # The OIDC ID token is used for authentication with JSR.
15+
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Install Deno
23+
uses: denoland/setup-deno@v1
24+
with:
25+
deno-version: ${{ env.DENO_VERSION }}
26+
- name: Publish on tag
27+
run: deno task publish

.github/workflows/udd.yml

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
# from https://zenn.dev/kawarimidoll/articles/c68204d248c107#設定ファイル
2-
name: update-deno-dependencies
1+
# ported from https://github.com/jsr-core/unknownutil/blob/v3.18.1/.github/workflows/udd.yml and modified a bit
2+
name: Update
33

44
on:
55
schedule:
66
- cron: "0 0 * * *"
7+
workflow_dispatch:
78

89
jobs:
910
udd:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1314
- uses: denoland/setup-deno@v1
1415
with:
15-
deno-version: "v1.x"
16+
deno-version: "1.x"
1617
- name: Update dependencies
17-
run: >
18-
deno run --allow-net --allow-read --allow-write=deps/
19-
--allow-run=deno https://deno.land/x/[email protected]/main.ts deps/*.ts
20-
--test="deno test --allow-read"
21-
- name: Create Pull Request
22-
uses: peter-evans/create-pull-request@v3
18+
run: |
19+
deno task upgrade > ../output.txt
20+
env:
21+
NO_COLOR: 1
22+
- name: Read ../output.txt
23+
id: log
24+
uses: juliangruber/read-file-action@v1
2325
with:
24-
commit-message: ":arrow_up: update deno dependencies"
25-
title: Update Deno Dependencies
26-
body: >
27-
Automated updates by [deno-udd](https://github.com/hayd/deno-udd)
28-
and [create-pull-request](https://github.com/peter-evans/create-pull-request)
29-
GitHub action
26+
path: ../output.txt
27+
- uses: peter-evans/create-pull-request@v6
28+
with:
29+
commit-message: ":package: Update Deno dependencies"
30+
title: ":package: Update Deno dependencies"
31+
body: |
32+
The output of `deno task update` is
33+
34+
```
35+
${{ steps.log.outputs.content }}
36+
```
3037
branch: update-deno-dependencies
3138
author: GitHub <[email protected]>
32-
delete-branch: true
39+
delete-branch: true

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# scrapbox-userscript-std
22

3-
UNOFFICIAL standard module for Scrapbox UserScript
3+
[![JSR](https://jsr.io/badges/@cosense/std)](https://jsr.io/@cosense/std)
4+
[![test](https://github.com/takker99/scrapbox-userscript-std/workflows/ci/badge.svg)](https://github.com/takker99/scrapbox-userscript-std/actions?query=workflow%3Aci)
45

5-
[document](https://doc.deno.land/https://raw.githubusercontent.com/takker99/scrapbox-userscript-std/0.14.9/mod.ts)
6+
UNOFFICIAL standard module for Scrapbox UserScript

browser/dom/caret.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { textInput } from "./dom.ts";
62

73
/** editor上の位置情報 */

browser/dom/click.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
5-
import { sleep } from "../../sleep.ts";
1+
import { delay } from "@std/async/delay";
62

73
/** the options for `click()` */
84
export interface ClickOptions {
@@ -36,7 +32,7 @@ export const click = async (
3632

3733
// ScrapboxのReactの処理が終わるまで少し待つ
3834
// 待ち時間は感覚で決めた
39-
await sleep(10);
35+
await delay(10);
4036
};
4137

4238
export interface HoldDownOptions extends ClickOptions {
@@ -71,12 +67,12 @@ export const holdDown = async (
7167
};
7268
element.dispatchEvent(new TouchEvent("touchstart", mouseOptions));
7369
element.dispatchEvent(new MouseEvent("mousedown", mouseOptions));
74-
await sleep(options.holding ?? 1000);
70+
await delay(options.holding ?? 1000);
7571
element.dispatchEvent(new MouseEvent("mouseup", mouseOptions));
7672
element.dispatchEvent(new TouchEvent("touchend", mouseOptions));
7773
element.dispatchEvent(new MouseEvent("click", mouseOptions));
7874

7975
// ScrapboxのReactの処理が終わるまで少し待つ
8076
// 待ち時間は感覚で決めた
81-
await sleep(10);
77+
await delay(10);
8278
};

browser/dom/cursor.d.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
5-
import { BaseLine, BaseStore } from "../../deps/scrapbox.ts";
6-
import { Position } from "./position.ts";
7-
import { Page } from "./page.d.ts";
1+
import { type BaseLine, BaseStore } from "../../deps/scrapbox.ts";
2+
import type { Position } from "./position.ts";
3+
import type { Page } from "./page.d.ts";
84

95
export interface SetPositionOptions {
106
/** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか

browser/dom/cursor.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { takeStores } from "./stores.ts";
6-
import { Cursor } from "./cursor.d.ts";
2+
import type { Cursor } from "./cursor.d.ts";
73
export type { Cursor };
84

95
export const takeCursor = (): Cursor => takeStores().cursor;

browser/dom/dom.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
41
import {
52
ensureHTMLAnchorElement,
63
ensureHTMLDivElement,

browser/dom/edit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getLineCount } from "./node.ts";
44
import { range } from "../../range.ts";
55
import { textInput } from "./dom.ts";
66
import { isArray, isNumber, isString } from "../../is.ts";
7-
import { sleep } from "../../sleep.ts";
7+
import { delay } from "@std/async/delay";
88

99
export const undo = (count = 1): void => {
1010
for (const _ of range(0, count)) {
@@ -165,5 +165,5 @@ export const insertText = async (text: string): Promise<void> => {
165165

166166
const event = new InputEvent("input", { bubbles: true });
167167
cursor.dispatchEvent(event);
168-
await sleep(1); // 待ち時間は感覚で決めた
168+
await delay(1); // 待ち時間は感覚で決めた
169169
};

browser/dom/ensure.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference lib="dom" />
21
// These code are based on https://deno.land/x/unknownutil@v1.1.0/ensure.ts
32

43
export const ensureHTMLDivElement: (

browser/dom/extractCodeFiles.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { extractCodeFiles } from "./extractCodeFiles.ts";
2-
import { Line } from "../../deps/scrapbox.ts";
2+
import type { Line } from "../../deps/scrapbox.ts";
33
import { assertSnapshot } from "../../deps/testing.ts";
44
import sample from "./sample-lines1.json" with { type: "json" };
55

browser/dom/extractCodeFiles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Line } from "../../deps/scrapbox.ts";
1+
import type { Line } from "../../deps/scrapbox.ts";
22

33
/** 一つのソースコードを表す */
44
export interface CodeFile {

browser/dom/getCachedLines.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Line, Scrapbox } from "../../deps/scrapbox.ts";
1+
import type { Line, Scrapbox } from "../../deps/scrapbox.ts";
22
declare const scrapbox: Scrapbox;
33

44
let isLatestData = false;

browser/dom/isHeightViewable.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
export const isHeightViewable = (element: HTMLElement): boolean => {
62
const { top, bottom } = element.getBoundingClientRect();
73
return top >= 0 && bottom <= globalThis.innerHeight;

browser/dom/motion.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { press } from "./press.ts";
62
import { click, holdDown } from "./click.ts";
73
import {

browser/dom/node.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
41
import { isNone, isNumber, isString } from "../../is.ts";
52
import { ensureArray } from "../../ensure.ts";
63
import { getCachedLines } from "./getCachedLines.ts";
@@ -138,7 +135,7 @@ export const getInternalLink = (dom: HTMLElement): HTMLElement | undefined => {
138135
if (isNone(link)) return undefined;
139136
return link as HTMLElement;
140137
};
141-
export const getLink = (dom: HTMLElement) => {
138+
export const getLink = (dom: HTMLElement): HTMLElement | undefined => {
142139
const link = dom.closest(".link, .page-link");
143140
if (isNone(link)) return undefined;
144141
return link as HTMLElement;

browser/dom/open.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { encodeTitleURI } from "../../title.ts";
62
import {
7-
PageTransitionContext,
3+
type PageTransitionContext,
84
pushPageTransition,
95
} from "./pushPageTransition.ts";
106
import type { Scrapbox } from "../../deps/scrapbox.ts";
@@ -43,7 +39,7 @@ export const open = (
4339
project: string,
4440
title: string,
4541
options?: OpenOptions,
46-
) => {
42+
): void => {
4743
const url = new URL(`/${project}/${encodeTitleURI(title)}`, location.href);
4844
if (options?.body) url.search = `?body=${encodeURIComponent(options.body)}`;
4945
if (options?.id) url.hash = `#${options.id}`;
@@ -88,4 +84,4 @@ export const openInTheSameTab = (
8884
project: string,
8985
title: string,
9086
body?: string,
91-
) => open(project, title, { newTab: false, reload: false, body });
87+
): void => open(project, title, { newTab: false, reload: false, body });

browser/dom/page.d.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { BaseStore } from "../../deps/scrapbox.ts";
6-
import { Page as PageData } from "../../deps/scrapbox-rest.ts";
2+
import type { Page as PageData } from "../../deps/scrapbox-rest.ts";
73

84
export interface SetPositionOptions {
95
/** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか

browser/dom/press.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { textInput } from "./dom.ts";
62

73
/** the options for `press()` */

browser/dom/selection.d.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
5-
import { BaseLine, BaseStore } from "../../deps/scrapbox.ts";
6-
import { Position } from "./position.ts";
1+
import { type BaseLine, BaseStore } from "../../deps/scrapbox.ts";
2+
import type { Position } from "./position.ts";
73

84
export interface Range {
95
start: Position;

browser/dom/selection.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { takeStores } from "./stores.ts";
6-
import { Selection } from "./selection.d.ts";
2+
import type { Selection } from "./selection.d.ts";
73
export type { Selection };
84

95
export const takeSelection = (): Selection => takeStores().selection;

browser/dom/stores.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/// <reference no-default-lib="true"/>
2-
/// <reference lib="esnext"/>
3-
/// <reference lib="dom" />
4-
51
import { textInput } from "./dom.ts";
6-
import { Cursor } from "./cursor.d.ts";
7-
import { Selection } from "./selection.d.ts";
2+
import type { Cursor } from "./cursor.d.ts";
3+
import type { Selection } from "./selection.d.ts";
84
export type { Cursor, Selection };
95

106
export const takeStores = (): { cursor: Cursor; selection: Selection } => {

browser/dom/takeInternalLines.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { lines } from "./dom.ts";
2-
import { BaseLine } from "../../deps/scrapbox.ts";
2+
import type { BaseLine } from "../../deps/scrapbox.ts";
33

44
/** Scrapbox内部の本文データの参照を取得する
55
*

browser/dom/textInputEventListener.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Scrapbox } from "../../deps/scrapbox.ts";
1+
import type { Scrapbox } from "../../deps/scrapbox.ts";
22
import { textInput } from "./dom.ts";
33
import { decode, encode } from "./_internal.ts";
44
declare const scrapbox: Scrapbox;

browser/websocket/_codeBlock.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference lib="deno.ns" />
2-
31
import { assertEquals, assertSnapshot } from "../../deps/testing.ts";
42
import { extractFromCodeTitle } from "./_codeBlock.ts";
53

browser/websocket/_codeBlock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
1+
import type { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
22

33
/** コードブロックのタイトル行の情報を保持しておくためのinterface */
44
export interface CodeTitle {

browser/websocket/deletePage.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { push, PushOptions, RetryError } from "./push.ts";
2-
import { Result } from "../../rest/util.ts";
1+
import { push, type PushOptions, type RetryError } from "./push.ts";
2+
import type { Result } from "../../rest/util.ts";
33

44
export type DeletePageOptions = PushOptions;
55

browser/websocket/findMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseLine, Node, parse } from "../../deps/scrapbox.ts";
1+
import { type BaseLine, type Node, parse } from "../../deps/scrapbox.ts";
22
import { toTitleLc } from "../../title.ts";
33
import { parseYoutube } from "../../parser/youtube.ts";
44

browser/websocket/isSimpleCodeFile.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, assertFalse } from "../../deps/testing.ts";
22
import { isSimpleCodeFile } from "./isSimpleCodeFile.ts";
3-
import { SimpleCodeFile } from "./updateCodeFile.ts";
3+
import type { SimpleCodeFile } from "./updateCodeFile.ts";
44

55
const codeFile: SimpleCodeFile = {
66
filename: "filename",

browser/websocket/isSimpleCodeFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SimpleCodeFile } from "./updateCodeFile.ts";
1+
import type { SimpleCodeFile } from "./updateCodeFile.ts";
22

33
/** objectがSimpleCodeFile型かどうかを判別する */
44
export function isSimpleCodeFile(obj: unknown): obj is SimpleCodeFile {

0 commit comments

Comments
 (0)