@open-feishu-card/adapter 0.2.1 → 0.3.0
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/dist/index.cjs +933 -162
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +932 -163
- package/dist/raw-to-dsl.d.ts +60 -6
- package/dist/raw-to-dsl.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/raw-to-dsl.d.ts
CHANGED
|
@@ -1,8 +1,62 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* RAW → 公开 DSL(JSON Schema 2.0)。
|
|
3
|
+
*
|
|
4
|
+
* 本文件完整移植自 `feishu-raw-card-to-dsl`(保持算法与行为一致)。
|
|
5
|
+
* monorepo 额外导出 `rawToDsl`(兼容本地 RAW / envelope)与可选的 `degradeUnknown`。
|
|
6
|
+
*
|
|
7
|
+
* Convert the editor-internal "raw_card_content" payload returned by
|
|
8
|
+
* `im.message.get?card_msg_content_type=raw_card_content` into the public
|
|
9
|
+
* JSON Schema 2.0 DSL we author and send.
|
|
10
|
+
*
|
|
11
|
+
* The raw payload differs from the public DSL in several ways:
|
|
12
|
+
* 1. Every node is wrapped as { id, tag, property: { ...real fields... } }.
|
|
13
|
+
* 2. Field names are camelCase (textAlign, backgroundStyle, imageID, ...).
|
|
14
|
+
* 3. Box fields (padding/margin) are objects { bottom:{type,value}, ... }
|
|
15
|
+
* instead of "Tpx Rpx Bpx Lpx" strings; scalar pixels (corner_radius,
|
|
16
|
+
* icon size) are similarly objectified.
|
|
17
|
+
* 4. Images carry imageID (numeric) which indexes into a separate
|
|
18
|
+
* json_attachment.images table to recover the real img_key.
|
|
19
|
+
* 5. Markdown is split into per-segment children (plain_text / link / br /
|
|
20
|
+
* at_all / person_v1 / text_tag / code_span / ...) under a wrapper
|
|
21
|
+
* element with originTag:'markdown'; we re-stitch them back into a
|
|
22
|
+
* single content string with inline markers.
|
|
23
|
+
* 6. Header is wrapped as `tag: 'card_header'` and its icon shows up as a
|
|
24
|
+
* sibling `udIcon` wrapper around an inner `ud_icon` element.
|
|
25
|
+
* 7. Editor mirrors the same value twice — a coarse enum (width:'auto')
|
|
26
|
+
* alongside a precise echo (widthValue:{type:'pixels',value:72}). We
|
|
27
|
+
* project the precise echo back onto the enum when it disagrees.
|
|
28
|
+
* 8. Most nodes carry editor defaults (disabled:false, vertical_align:
|
|
29
|
+
* 'top', flex_mode:'none', background_style:'default') that the public
|
|
30
|
+
* DSL omits. We strip them.
|
|
31
|
+
* 9. The whole thing is double-stringified into body.content as
|
|
32
|
+
* { json_card: "<stringified card>", json_attachment: { images, at_users? } }.
|
|
33
|
+
*
|
|
34
|
+
* Why we do this: the documented user_card_content path drops fields whose
|
|
35
|
+
* values match a server-side default (notably `column.padding` on a column
|
|
36
|
+
* with `background_style`), which silently breaks layouts on round-trip.
|
|
37
|
+
* The raw payload preserves them. We project raw -> public DSL on the read
|
|
38
|
+
* path so downstream code (patch_lark_card, archives, the model's mental
|
|
39
|
+
* model) keeps working against the only format that has a public spec.
|
|
40
|
+
*
|
|
41
|
+
* No public spec exists for the raw payload. The mapping below is sample-
|
|
42
|
+
* driven, derived from diffing rawCardToDsl(raw) against archived public DSL
|
|
43
|
+
* for ~250 cards we previously sent. When the converter encounters something
|
|
44
|
+
* it does not recognize, it keeps the original key/value (snake-cased) so
|
|
45
|
+
* downstream sees an unknown field rather than silently losing data.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isRawCardEnvelope(value: unknown): boolean;
|
|
48
|
+
export declare function rawCardToDsl(envelope: unknown): unknown;
|
|
49
|
+
/**
|
|
50
|
+
* Flexible entry used by this monorepo:
|
|
51
|
+
* - raw envelope (`json_card` + `card_schema`) → same as `rawCardToDsl`
|
|
52
|
+
* - already-parsed `{ json_card: object, json_attachment? }`
|
|
53
|
+
* - `{ card: ... }` / bare card (e.g. output of `dslToRaw`) → `convertRoot`
|
|
54
|
+
*/
|
|
55
|
+
export declare function rawToDsl(raw: unknown): unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Optional helper: wrap a private/unknown element as
|
|
58
|
+
* `{ tag: 'unknown', raw_tag, fallback }`.
|
|
59
|
+
* Not applied automatically by `rawToDsl` / `rawCardToDsl` (parity with upstream).
|
|
60
|
+
*/
|
|
2
61
|
export declare function degradeUnknown(el: Record<string, unknown>): Record<string, unknown>;
|
|
3
|
-
/** RAW envelope(可能是 {json_card:{card}} / {card} / 直接 card)→ DSL 卡片对象 */
|
|
4
|
-
export declare function rawToDsl(raw: unknown): Record<string, unknown>;
|
|
5
|
-
/** DSL → RAW(重导出,统一入口) */
|
|
6
|
-
export { dslToRaw } from './dsl-to-raw.js';
|
|
7
|
-
export type { CardElement, ElementProperty, JsonCard } from './types.js';
|
|
8
62
|
//# sourceMappingURL=raw-to-dsl.d.ts.map
|
package/dist/raw-to-dsl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAWH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AAo9CD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGnF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-feishu-card/adapter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "公开 DSL 与飞书内部 RAW JSON
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.20.1",
|
|
20
21
|
"tsup": "^8.3.5",
|
|
21
22
|
"tsx": "^4.19.3",
|
|
22
23
|
"typescript": "^7.0.2",
|
|
23
|
-
"
|
|
24
|
+
"vitest": "^2.1.9"
|
|
24
25
|
},
|
|
25
26
|
"license": "MIT",
|
|
26
27
|
"publishConfig": {
|
|
@@ -34,6 +35,6 @@
|
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "tsup && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
36
37
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
37
|
-
"test": "tsx --test test
|
|
38
|
+
"test": "tsx --test test/adapter.test.ts && vitest run"
|
|
38
39
|
}
|
|
39
40
|
}
|