@riebeckite/plugin-query 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@ JavaScript is required.
10
10
 
11
11
  ## Overview
12
12
 
13
- `queryPlugin()` recognises fenced blocks
13
+ `query()` recognises fenced blocks
14
14
 
15
15
  ````md
16
16
  ```query
@@ -31,11 +31,11 @@ permalink).
31
31
 
32
32
  ```ts
33
33
  import { defineConfig } from "@riebeckite/core";
34
- import { queryPlugin } from "@riebeckite/plugin-query";
34
+ import { query } from "@riebeckite/plugin-query";
35
35
 
36
36
  export default defineConfig({
37
37
  // ...
38
- plugins: [queryPlugin()],
38
+ plugins: [query()],
39
39
  });
40
40
  ```
41
41
 
@@ -85,6 +85,26 @@ limit: 10
85
85
  format: list
86
86
  ```
87
87
 
88
+ ## Live example
89
+
90
+ A list with a limit:
91
+
92
+ ~~~query
93
+ format: list
94
+ sort:
95
+ field: title
96
+ order: asc
97
+ limit: 5
98
+ ~~~
99
+
100
+ A table with selected columns:
101
+
102
+ ~~~query
103
+ format: table
104
+ columns: [title, date, tags]
105
+ limit: 5
106
+ ~~~
107
+
88
108
  ## Options
89
109
 
90
110
  | Option | Type | Default | Description |
@@ -113,7 +133,7 @@ emits a `content-query-invalid` error diagnostic. Unknown fields emit a
113
133
 
114
134
  ## Exports
115
135
 
116
- - `queryPlugin(options?)` — plugin factory
136
+ - `query(options?)` — plugin factory
117
137
  - `remarkQuery(options?)` — remark transform usable on its own (`options.language` selects the fence language)
118
138
  - `queryContentEntries(entries, spec)` — the Core matching engine (also
119
139
  available from `@riebeckite/core`)
package/README_ja.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## できること
10
10
 
11
- `queryPlugin()` は Markdown 中のフェンスコードブロック
11
+ `query()` は Markdown 中のフェンスコードブロック
12
12
 
13
13
  ````md
14
14
  ```query
@@ -28,11 +28,11 @@ limit: 5
28
28
 
29
29
  ```ts
30
30
  import { defineConfig } from "@riebeckite/core";
31
- import { queryPlugin } from "@riebeckite/plugin-query";
31
+ import { query } from "@riebeckite/plugin-query";
32
32
 
33
33
  export default defineConfig({
34
34
  // ...
35
- plugins: [queryPlugin()],
35
+ plugins: [query()],
36
36
  });
37
37
  ```
38
38
 
@@ -82,6 +82,26 @@ limit: 10
82
82
  format: list
83
83
  ```
84
84
 
85
+ ## 実行例
86
+
87
+ 件数を絞ったリスト:
88
+
89
+ ~~~query
90
+ format: list
91
+ sort:
92
+ field: title
93
+ order: asc
94
+ limit: 5
95
+ ~~~
96
+
97
+ 列を選んだテーブル:
98
+
99
+ ~~~query
100
+ format: table
101
+ columns: [title, date, tags]
102
+ limit: 5
103
+ ~~~
104
+
85
105
  ## オプション
86
106
 
87
107
  | オプション | 型 | 既定値 | 内容 |
@@ -97,7 +117,7 @@ format: list
97
117
 
98
118
  ## 診断
99
119
 
100
- 不正な YAML やマッピングでないブロックは、その場にエラー表示を出しつつ、`content-query-invalid` のエラー診断を生成します。未知のフィールドは `content-query-unknown-field` の警告になります。
120
+ 不正な YAML やマッピングでないブロックは、その場にエラーを表示し、`content-query-invalid` のエラー診断を生成します。未知のフィールドは `content-query-unknown-field` の警告になります。
101
121
 
102
122
  ## 制限事項
103
123
 
@@ -106,7 +126,7 @@ format: list
106
126
 
107
127
  ## エクスポート
108
128
 
109
- - `queryPlugin(options?)`:プラグインファクトリ
129
+ - `query(options?)`:プラグインファクトリ
110
130
  - `remarkQuery(options?)`:Remark 変換だけを利用する場合の API(`options.language` でフェンス言語を指定)
111
131
  - `queryContentEntries(entries, spec)`:Core の照合エンジン(`@riebeckite/core` からも利用可能)
112
132
  - 型: `QueryOptions`、`QuerySpec`、`QueryOutputFormat`
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ import type { QueryOptions } from "./src/types.js";
2
2
  export { queryContentEntries } from "@riebeckite/core";
3
3
  export { remarkQuery } from "./src/remark.js";
4
4
  export type { QueryOptions, QueryOutputFormat, QuerySpec, } from "./src/types.js";
5
- export declare function queryPlugin(options?: QueryOptions): import("@riebeckite/core").RiebeckitePlugin<QueryOptions>;
5
+ export declare function query(options?: QueryOptions): import("@riebeckite/core").RiebeckitePlugin<QueryOptions>;
package/dist/index.js CHANGED
@@ -69,18 +69,18 @@ function resolveQuery(spec, options) {
69
69
  className: options.className ?? "rr-query"
70
70
  };
71
71
  }
72
- function renderQueryResult(entries, query) {
72
+ function renderQueryResult(entries, query2) {
73
73
  if (entries.length === 0) {
74
- return `<p class="${escapeHtmlAttribute(query.className)} ${escapeHtmlAttribute(query.className)}--empty">${escapeHtml(query.empty)}</p>`;
74
+ return `<p class="${escapeHtmlAttribute(query2.className)} ${escapeHtmlAttribute(query2.className)}--empty">${escapeHtml(query2.empty)}</p>`;
75
75
  }
76
- return query.format === "list" ? renderList(entries, query) : renderTable(entries, query);
76
+ return query2.format === "list" ? renderList(entries, query2) : renderTable(entries, query2);
77
77
  }
78
78
  function renderQueryError(message, options) {
79
79
  const className = options.className ?? "rr-query";
80
80
  return `<div class="${escapeHtmlAttribute(className)} ${escapeHtmlAttribute(className)}--error" role="status">${escapeHtml(message)}</div>`;
81
81
  }
82
- function renderTable(entries, query) {
83
- const { className, columns } = query;
82
+ function renderTable(entries, query2) {
83
+ const { className, columns } = query2;
84
84
  const head = columns.map(
85
85
  (field) => `<th class="${escapeHtmlAttribute(className)}__heading" scope="col">${escapeHtml(columnLabel(field))}</th>`
86
86
  ).join("");
@@ -102,8 +102,8 @@ function renderTable(entries, query) {
102
102
  "</div>"
103
103
  ].join("");
104
104
  }
105
- function renderList(entries, query) {
106
- const { className, columns } = query;
105
+ function renderList(entries, query2) {
106
+ const { className, columns } = query2;
107
107
  const metaColumns = columns.filter((field) => field !== "title");
108
108
  const items = entries.map((entry) => {
109
109
  const meta = metaColumns.map((field) => {
@@ -201,11 +201,11 @@ function replacePlaceholders(entry, entries, options, diagnostics) {
201
201
  return entry.html.replace(pattern, (_match, encoded) => {
202
202
  const parsed = parseBlock(entry, encoded, options, diagnostics);
203
203
  if (typeof parsed === "string") return parsed;
204
- const query = resolveQuery(parsed, options);
204
+ const query2 = resolveQuery(parsed, options);
205
205
  const excludeSelf = parsed.excludeSelf ?? options.excludeSelf ?? false;
206
206
  const pool = excludeSelf ? entries.filter((candidate) => candidate.slug !== entry.slug) : entries;
207
207
  const selected = queryContentEntries(pool, parsed);
208
- return renderQueryResult(selected, query);
208
+ return renderQueryResult(selected, query2);
209
209
  });
210
210
  }
211
211
  function parseBlock(entry, encoded, options, diagnostics) {
@@ -278,7 +278,7 @@ function formatError(error) {
278
278
 
279
279
  // index.ts
280
280
  import { queryContentEntries as queryContentEntries2 } from "@riebeckite/core";
281
- function queryPlugin(options = {}) {
281
+ function query(options = {}) {
282
282
  const language = options.language ?? "query";
283
283
  const runtime = createQueryRuntime(options);
284
284
  return definePlugin({
@@ -342,7 +342,7 @@ function isColumnList(value) {
342
342
  return value === void 0 || Array.isArray(value) && value.every((item) => typeof item === "string");
343
343
  }
344
344
  export {
345
+ query,
345
346
  queryContentEntries2 as queryContentEntries,
346
- queryPlugin,
347
347
  remarkQuery
348
348
  };
@@ -1,5 +1,4 @@
1
1
  export declare const QUERY_ATTRIBUTE = "data-rr-query";
2
- export declare function encodeQuerySpec(source: string): string;
3
2
  export declare function decodeQuerySpec(encoded: string): string;
4
3
  export declare function createQueryPlaceholder(source: string): string;
5
4
  export declare function createQueryPlaceholderPattern(): RegExp;
@@ -1,5 +1,6 @@
1
1
  import type { Root } from "mdast";
2
- export type RemarkQueryOptions = {
2
+ type RemarkQueryOptions = {
3
3
  language?: string;
4
4
  };
5
5
  export declare function remarkQuery(options?: RemarkQueryOptions): (tree: Root) => void;
6
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { type ContentManifestEntry } from "@riebeckite/core";
2
2
  import type { QueryOptions, QuerySpec } from "./types.js";
3
- export type ResolvedQuery = {
3
+ type ResolvedQuery = {
4
4
  format: "table" | "list";
5
5
  columns: readonly string[];
6
6
  empty: string;
@@ -9,3 +9,4 @@ export type ResolvedQuery = {
9
9
  export declare function resolveQuery(spec: QuerySpec, options: QueryOptions): ResolvedQuery;
10
10
  export declare function renderQueryResult(entries: readonly ContentManifestEntry[], query: ResolvedQuery): string;
11
11
  export declare function renderQueryError(message: string, options: QueryOptions): string;
12
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { ContentManifest, Diagnostic } from "@riebeckite/core";
2
2
  import type { QueryOptions } from "./types.js";
3
- export type QueryRuntime = {
3
+ type QueryRuntime = {
4
4
  resolve(manifest: ContentManifest, diagnostics: Diagnostic[]): void;
5
5
  };
6
6
  export declare function createQueryRuntime(options: QueryOptions): QueryRuntime;
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-query",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,14 +15,14 @@
15
15
  "./style.css": "./style.css"
16
16
  },
17
17
  "dependencies": {
18
+ "@riebeckite/core": "0.0.33",
18
19
  "@types/mdast": "^4.0.4",
19
20
  "unist-util-visit": "^5.1.0",
20
- "vfile-matter": "^5.0.1",
21
- "@riebeckite/core": "0.0.31"
21
+ "vfile-matter": "^5.0.1"
22
22
  },
23
23
  "devDependencies": {
24
- "tsx": "^4.22.4",
25
- "@riebeckite/test": "0.0.31"
24
+ "@riebeckite/test": "0.0.33",
25
+ "tsx": "^4.22.4"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"