Comparing version 0.1.4 to 0.1.5
1050
dist/client.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,558 +9,557 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
class NotionEXClient { | ||
client; | ||
constructor(client) { | ||
this.client = client; | ||
} | ||
getDOMJSONFromBlockId(blockId, option) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// fetch blocks recursively | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
let hasMore = true; | ||
let blocks = []; | ||
const params = { | ||
block_id: blockId, | ||
page_size: 100, | ||
start_cursor: undefined | ||
}; | ||
while (hasMore) { | ||
const data = yield this.client.blocks.children.list(params); | ||
blocks = [...blocks, ...data.results]; | ||
hasMore = data.has_more; | ||
if (data.next_cursor != null) | ||
params.start_cursor = data.next_cursor; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// convert blocks | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
const results = []; | ||
let prev_is_ul = false; | ||
let prev_is_ol = false; | ||
for (const block of blocks) { | ||
if ('type' in block) { | ||
switch (block.type) { | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Audio | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'audio': { | ||
results.push({ | ||
type: 'audio', | ||
content: block.audio.type === 'external' | ||
? block.audio.external.url | ||
: block.audio.file.url, | ||
children: this.convertRichTextToDOMJSON(block.audio.caption) | ||
async getDOMJSONFromBlockId(blockId, option) { | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// fetch blocks recursively | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
let hasMore = true; | ||
let blocks = []; | ||
const params = { | ||
block_id: blockId, | ||
page_size: 100, | ||
start_cursor: undefined | ||
}; | ||
while (hasMore) { | ||
const data = await this.client.blocks.children.list(params); | ||
blocks = [...blocks, ...data.results]; | ||
hasMore = data.has_more; | ||
if (data.next_cursor != null) | ||
params.start_cursor = data.next_cursor; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// convert blocks | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
const results = []; | ||
let prev_is_ul = false; | ||
let prev_is_ol = false; | ||
for (const block of blocks) { | ||
if ('type' in block) { | ||
switch (block.type) { | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Audio | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'audio': { | ||
results.push({ | ||
type: 'audio', | ||
content: block.audio.type === 'external' | ||
? block.audio.external.url | ||
: block.audio.file.url, | ||
children: this.convertRichTextToDOMJSON(block.audio.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// bookmark | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'bookmark': { | ||
const { result } = await (0, open_graph_scraper_1.default)({ url: block.bookmark.url }); | ||
const title = result.ogTitle || result.dcTitle || result.twitterTitle; | ||
const description = result.ogDescription || result.twitterDescription; | ||
const images = result.ogImage || result.twitterImage; | ||
const [image] = images != null ? images : [undefined]; | ||
results.push({ | ||
type: 'bookmark', | ||
content: block.bookmark.url, | ||
extension: { title, description, image: image?.url }, | ||
children: this.convertRichTextToDOMJSON(block.bookmark.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// breadcrumb | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'breadcrumb': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// bulleted_list_item | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'bulleted_list_item': { | ||
const liChildren = block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.bulleted_list_item.rich_text) | ||
}, | ||
...(await this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: this.convertRichTextToDOMJSON(block.bulleted_list_item.rich_text); | ||
if (prev_is_ul) { | ||
results[results.length - 1].children.push({ | ||
type: 'li', | ||
children: liChildren | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// bookmark | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'bookmark': { | ||
const { result } = yield (0, open_graph_scraper_1.default)({ url: block.bookmark.url }); | ||
const title = result.ogTitle || result.dcTitle || result.twitterTitle; | ||
const description = result.ogDescription || result.twitterDescription; | ||
const images = result.ogImage || result.twitterImage; | ||
const [image] = images != null ? images : [undefined]; | ||
else { | ||
results.push({ | ||
type: 'bookmark', | ||
content: block.bookmark.url, | ||
extension: { title, description, image: image === null || image === void 0 ? void 0 : image.url }, | ||
children: this.convertRichTextToDOMJSON(block.bookmark.caption) | ||
type: 'ul', | ||
children: [ | ||
{ | ||
type: 'li', | ||
children: liChildren | ||
} | ||
] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// breadcrumb | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'breadcrumb': { | ||
break; | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// numbered_list_item | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'numbered_list_item': { | ||
const olChildren = block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.numbered_list_item.rich_text) | ||
}, | ||
...(await this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: this.convertRichTextToDOMJSON(block.numbered_list_item.rich_text); | ||
if (prev_is_ol) { | ||
results[results.length - 1].children.push({ | ||
type: 'li', | ||
children: olChildren | ||
}); | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// bulleted_list_item | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'bulleted_list_item': { | ||
const liChildren = block.has_children | ||
? [ | ||
else { | ||
results.push({ | ||
type: 'ol', | ||
children: [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.bulleted_list_item.rich_text) | ||
}, | ||
...(yield this.getDOMJSONFromBlockId(block.id)) | ||
type: 'li', | ||
children: olChildren | ||
} | ||
] | ||
: this.convertRichTextToDOMJSON(block.bulleted_list_item.rich_text); | ||
if (prev_is_ul) { | ||
results[results.length - 1].children.push({ | ||
type: 'li', | ||
children: liChildren | ||
}); | ||
} | ||
else { | ||
results.push({ | ||
type: 'ul', | ||
children: [ | ||
{ | ||
type: 'li', | ||
children: liChildren | ||
} | ||
] | ||
}); | ||
} | ||
break; | ||
}); | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// numbered_list_item | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'numbered_list_item': { | ||
const olChildren = block.has_children | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// callout | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'callout': { | ||
results.push({ | ||
type: 'callout', | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.numbered_list_item.rich_text) | ||
children: this.convertRichTextToDOMJSON(block.callout.rich_text) | ||
}, | ||
...(yield this.getDOMJSONFromBlockId(block.id)) | ||
...(await this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: this.convertRichTextToDOMJSON(block.numbered_list_item.rich_text); | ||
if (prev_is_ol) { | ||
results[results.length - 1].children.push({ | ||
type: 'li', | ||
children: olChildren | ||
}); | ||
} | ||
else { | ||
results.push({ | ||
type: 'ol', | ||
children: [ | ||
{ | ||
type: 'li', | ||
children: olChildren | ||
} | ||
] | ||
}); | ||
} | ||
: [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.callout.rich_text) | ||
} | ||
] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// child_database | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'child_database': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// child_page | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'child_page': { | ||
if (option != null && option.enableChildPage) { | ||
results.push(...(await this.getDOMJSONFromBlockId(block.id))); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// callout | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'callout': { | ||
results.push({ | ||
type: 'callout', | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.callout.rich_text) | ||
}, | ||
...(yield this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.callout.rich_text) | ||
} | ||
] | ||
}); | ||
else { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// child_database | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'child_database': { | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Code (Codeblock) | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'code': { | ||
results.push({ | ||
type: 'code', | ||
content: block.code.rich_text.map((r) => r.plain_text).join(''), | ||
extension: { language: block.code.language }, | ||
children: this.convertRichTextToDOMJSON(block.code.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// column | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'column': { | ||
results.push({ | ||
type: 'column', | ||
children: await this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// column_list | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'column_list': { | ||
results.push({ | ||
type: 'column_list', | ||
children: await this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// divider | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'divider': { | ||
results.push({ | ||
type: 'divider', | ||
children: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// embed | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'embed': { | ||
results.push({ | ||
type: 'embed', | ||
content: block.embed.url, | ||
children: this.convertRichTextToDOMJSON(block.embed.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// equation | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'equation': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// file | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'file': { | ||
results.push({ | ||
type: 'file', | ||
content: block.file.type === 'external' | ||
? block.file.external.url | ||
: block.file.file.url, | ||
children: this.convertRichTextToDOMJSON(block.file.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_1 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_1': { | ||
results.push({ | ||
type: 'heading_1', | ||
content: block.heading_1.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? await this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_2 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_2': { | ||
results.push({ | ||
type: 'heading_2', | ||
content: block.heading_2.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? await this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_3 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_3': { | ||
results.push({ | ||
type: 'heading_3', | ||
content: block.heading_3.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? await this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// image | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'image': { | ||
results.push({ | ||
type: 'image', | ||
content: block.image.type === 'external' | ||
? block.image.external.url | ||
: block.image.file.url, | ||
children: this.convertRichTextToDOMJSON(block.image.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// link_preview | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'link_preview': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// link_to_page | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'link_to_page': { | ||
if (option != null && | ||
option.enableLinkPageRef && | ||
block.link_to_page.type === 'page_id') { | ||
results.push(...(await this.getDOMJSONFromBlockId(block.link_to_page.page_id))); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// child_page | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'child_page': { | ||
if (option != null && option.enableChildPage) { | ||
results.push(...(yield this.getDOMJSONFromBlockId(block.id))); | ||
break; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Code (Codeblock) | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'code': { | ||
results.push({ | ||
type: 'code', | ||
content: block.code.rich_text.map((r) => r.plain_text).join(''), | ||
extension: { language: block.code.language }, | ||
children: this.convertRichTextToDOMJSON(block.code.caption) | ||
}); | ||
else { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// column | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'column': { | ||
results.push({ | ||
type: 'column', | ||
children: yield this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'pdf': { | ||
results.push({ | ||
type: 'pdf', | ||
content: block.pdf.type === 'external' | ||
? block.pdf.external.url | ||
: block.pdf.file.url, | ||
children: this.convertRichTextToDOMJSON(block.pdf.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// quote | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'quote': { | ||
results.push({ | ||
type: 'quote', | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.quote.rich_text) | ||
}, | ||
...(await this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.quote.rich_text) | ||
} | ||
] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// synced_block | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'synced_block': { | ||
if (option != null && option.enableSyncedBlock) { | ||
results.push(...(await this.getDOMJSONFromBlockId(block.id))); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// column_list | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'column_list': { | ||
results.push({ | ||
type: 'column_list', | ||
children: yield this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
else { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// divider | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'divider': { | ||
results.push({ | ||
type: 'divider', | ||
children: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// embed | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'embed': { | ||
results.push({ | ||
type: 'embed', | ||
content: block.embed.url, | ||
children: this.convertRichTextToDOMJSON(block.embed.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// equation | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'equation': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// file | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'file': { | ||
results.push({ | ||
type: 'file', | ||
content: block.file.type === 'external' | ||
? block.file.external.url | ||
: block.file.file.url, | ||
children: this.convertRichTextToDOMJSON(block.file.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_1 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_1': { | ||
results.push({ | ||
type: 'heading_1', | ||
content: block.heading_1.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? yield this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_2 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_2': { | ||
results.push({ | ||
type: 'heading_2', | ||
content: block.heading_2.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? yield this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// heading_3 | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'heading_3': { | ||
results.push({ | ||
type: 'heading_3', | ||
content: block.heading_3.rich_text | ||
.map((r) => r.plain_text) | ||
.join(''), | ||
// If this block is a toggle | ||
children: block.has_children | ||
? yield this.getDOMJSONFromBlockId(block.id) | ||
: [] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// image | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'image': { | ||
results.push({ | ||
type: 'image', | ||
content: block.image.type === 'external' | ||
? block.image.external.url | ||
: block.image.file.url, | ||
children: this.convertRichTextToDOMJSON(block.image.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// link_preview | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'link_preview': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// link_to_page | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'link_to_page': { | ||
if (option != null && | ||
option.enableLinkPageRef && | ||
block.link_to_page.type === 'page_id') { | ||
results.push(...(yield this.getDOMJSONFromBlockId(block.link_to_page.page_id))); | ||
break; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'pdf': { | ||
results.push({ | ||
type: 'pdf', | ||
content: block.pdf.type === 'external' | ||
? block.pdf.external.url | ||
: block.pdf.file.url, | ||
children: this.convertRichTextToDOMJSON(block.pdf.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// quote | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'quote': { | ||
results.push({ | ||
type: 'quote', | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.quote.rich_text) | ||
}, | ||
...(yield this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.quote.rich_text) | ||
} | ||
] | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// synced_block | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'synced_block': { | ||
if (option != null && option.enableSyncedBlock) { | ||
results.push(...(yield this.getDOMJSONFromBlockId(block.id))); | ||
break; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table': { | ||
results.push({ | ||
type: 'table', | ||
children: yield this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table_row | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table_row': { | ||
results.push({ | ||
type: 'table_row', | ||
children: block.table_row.cells.map((cell) => { | ||
return { | ||
type: 'table_cell', | ||
children: this.convertRichTextToDOMJSON(cell) | ||
}; | ||
}) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table_of_contents | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table_of_contents': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// template | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'template': { | ||
break; | ||
} | ||
case 'to_do': { | ||
results.push({ | ||
type: 'to_do', | ||
extension: { isChecked: block.to_do.checked }, | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.to_do.rich_text) | ||
}, | ||
...(yield this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: this.convertRichTextToDOMJSON(block.to_do.rich_text) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// toggle | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'toggle': { | ||
results.push({ | ||
type: 'toggle', | ||
content: block.toggle.rich_text.map((r) => r.plain_text).join(''), | ||
children: yield this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// unsupported | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'unsupported': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// video | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'video': { | ||
results.push({ | ||
type: 'video', | ||
content: block.video.type === 'external' | ||
? block.video.external.url | ||
: block.video.file.url, | ||
children: this.convertRichTextToDOMJSON(block.video.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Paragraph | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'paragraph': { | ||
const children = this.convertRichTextToDOMJSON(block.paragraph.rich_text); | ||
results.push({ type: 'paragraph', children }); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// default | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
default: | ||
break; | ||
} | ||
if (block.type === 'bulleted_list_item') { | ||
prev_is_ul = true; | ||
prev_is_ol = false; | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table': { | ||
results.push({ | ||
type: 'table', | ||
children: await this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
else if (block.type === 'numbered_list_item') { | ||
prev_is_ol = true; | ||
prev_is_ul = false; | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table_row | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table_row': { | ||
results.push({ | ||
type: 'table_row', | ||
children: block.table_row.cells.map((cell) => { | ||
return { | ||
type: 'table_cell', | ||
children: this.convertRichTextToDOMJSON(cell) | ||
}; | ||
}) | ||
}); | ||
break; | ||
} | ||
else { | ||
prev_is_ul = false; | ||
prev_is_ol = false; | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// table_of_contents | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'table_of_contents': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// template | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'template': { | ||
break; | ||
} | ||
case 'to_do': { | ||
results.push({ | ||
type: 'to_do', | ||
extension: { isChecked: block.to_do.checked }, | ||
children: block.has_children | ||
? [ | ||
{ | ||
type: 'paragraph', | ||
children: this.convertRichTextToDOMJSON(block.to_do.rich_text) | ||
}, | ||
...(await this.getDOMJSONFromBlockId(block.id)) | ||
] | ||
: this.convertRichTextToDOMJSON(block.to_do.rich_text) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// toggle | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'toggle': { | ||
results.push({ | ||
type: 'toggle', | ||
content: block.toggle.rich_text.map((r) => r.plain_text).join(''), | ||
children: await this.getDOMJSONFromBlockId(block.id) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// unsupported | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'unsupported': { | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// video | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'video': { | ||
results.push({ | ||
type: 'video', | ||
content: block.video.type === 'external' | ||
? block.video.external.url | ||
: block.video.file.url, | ||
children: this.convertRichTextToDOMJSON(block.video.caption) | ||
}); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// Paragraph | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
case 'paragraph': { | ||
const children = this.convertRichTextToDOMJSON(block.paragraph.rich_text); | ||
results.push({ type: 'paragraph', children }); | ||
break; | ||
} | ||
// # -------------------------------------------------------------------------------- | ||
// | ||
// default | ||
// | ||
// # -------------------------------------------------------------------------------- | ||
default: | ||
break; | ||
} | ||
if (block.type === 'bulleted_list_item') { | ||
prev_is_ul = true; | ||
prev_is_ol = false; | ||
} | ||
else if (block.type === 'numbered_list_item') { | ||
prev_is_ol = true; | ||
prev_is_ul = false; | ||
} | ||
else { | ||
prev_is_ul = false; | ||
prev_is_ol = false; | ||
} | ||
} | ||
return results; | ||
}); | ||
} | ||
return results; | ||
} | ||
@@ -576,0 +566,0 @@ convertRichTextToDOMJSON(richText) { |
{ | ||
"name": "notion-ex", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -14,3 +14,3 @@ { | ||
/* Language and Environment */ | ||
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
@@ -110,3 +110,3 @@ // "jsx": "preserve", /* Specify what JSX code is generated. */ | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "tests"] | ||
"exclude": ["tests"] | ||
} |
90921
2138