Skip to content

Commit 49f46be

Browse files
authored
[add] Document Block model & updating methods (#14)
1 parent 1f11e24 commit 49f46be

File tree

12 files changed

+322
-113
lines changed

12 files changed

+322
-113
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-lark",
3-
"version": "2.4.3",
3+
"version": "2.5.0",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.",
@@ -30,7 +30,7 @@
3030
"koajax": "^3.1.2",
3131
"lodash.memoize": "^4.1.2",
3232
"mobx": "^6.15.0",
33-
"mobx-restful": "^2.1.3",
33+
"mobx-restful": "^2.1.4",
3434
"regenerator-runtime": "^0.14.1",
3535
"web-utility": "^4.6.2"
3636
},
@@ -42,13 +42,13 @@
4242
"@parcel/transformer-typescript-tsc": "~2.16.0",
4343
"@types/fs-extra": "^11.0.4",
4444
"@types/lodash.memoize": "^4.1.9",
45-
"@types/node": "^22.18.10",
45+
"@types/node": "^22.18.12",
4646
"@types/react-dom": "^19.2.2",
4747
"@types/turndown": "^5.0.5",
4848
"dotenv": "^17.2.3",
4949
"fs-extra": "^11.3.2",
5050
"husky": "^9.1.7",
51-
"lint-staged": "^16.2.4",
51+
"lint-staged": "^16.2.5",
5252
"parcel": "~2.16.0",
5353
"prettier": "^3.6.2",
5454
"react": "^19.2.0",

pnpm-lock.yaml

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Lark.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Context, HTTPClient, makeFormData } from 'koajax';
22
import { buildURLData, cache, sleep } from 'web-utility';
33

4-
import { WikiNodeModel } from './module';
4+
import { DocumentModel, WikiNodeModel } from './module';
55
import {
66
isLarkError,
77
JSTicket,
@@ -209,22 +209,19 @@ export class LarkApp implements LarkAppOption {
209209
static documentPathPattern = /(wiki|docx)\/(\w+)/;
210210

211211
/**
212-
* @see {@link https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/docs-v1/content/get}
212+
* @see {@link DocumentModel#getOneContent}
213213
*/
214214
async downloadMarkdown(URI: string) {
215215
await this.getAccessToken();
216216

217217
const [, type, id] = URI.match(LarkApp.documentPathPattern) || [];
218218

219-
const doc_token = type === 'wiki' ? await this.wiki2docx(id) : id;
219+
const doc_token = type === 'wiki' ? await this.wiki2docx(id) : id,
220+
{ client } = this;
220221

221-
const { body } = await this.client.get<LarkData<{ content: string }>>(
222-
`docs/v1/content?${new URLSearchParams({
223-
doc_type: 'docx',
224-
doc_token,
225-
content_type: 'markdown'
226-
})}`
227-
);
228-
return body!.data!.content;
222+
class InternalDocumentModel extends DocumentModel {
223+
client = client;
224+
}
225+
return new InternalDocumentModel('').getOneContent(doc_token, 'markdown');
229226
}
230227
}

src/module/BITable/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,12 @@ export function BiTable() {
275275
/**
276276
* @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table/list}
277277
*/
278-
async *openStream() {
279-
for await (const item of createPageStream<BITable>(
278+
openStream() {
279+
return createPageStream<BITable>(
280280
this.client,
281281
this.baseURI,
282282
total => (this.totalCount = total)
283-
))
284-
yield item;
283+
);
285284
}
286285
}
287286
return BiTableModel;

src/module/Document/component/Block.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC } from 'react';
2-
import { uniqueID } from 'web-utility';
2+
import { clone, uniqueID } from 'web-utility';
33

44
import { Block, BlockType } from '../type';
55
import { ListBlockComponent, TextBlockComponent } from './Text';
@@ -55,7 +55,7 @@ export const blockComponentMap: Partial<Record<BlockType, FC<any>>> = {
5555
export const blockMap: Record<string, Block<any, any, any>> = {};
5656

5757
export function registerBlocks<T extends Block<any, any, any>>(blocks: T[]) {
58-
blocks = globalThis.structuredClone?.(blocks) || JSON.parse(JSON.stringify(blocks));
58+
blocks = clone(blocks);
5959

6060
let root: T | undefined;
6161

0 commit comments

Comments
 (0)