2023-01-27 03:22:44 -08:00
import type { IDisplayOptions , INodeProperties } from 'n8n-workflow' ;
2021-05-20 14:31:23 -07:00
const colors = [
{
name : 'Default' ,
value : 'default' ,
} ,
{
name : 'Gray' ,
value : 'gray' ,
} ,
{
name : 'Brown' ,
value : 'brown' ,
} ,
{
name : 'Orange' ,
value : 'orange' ,
} ,
{
name : 'Yellow' ,
value : 'yellow' ,
} ,
{
name : 'Green' ,
value : 'green' ,
} ,
{
name : 'Blue' ,
value : 'blue' ,
} ,
{
name : 'Purple' ,
value : 'purple' ,
} ,
{
name : 'Pink' ,
value : 'pink' ,
} ,
{
name : 'Red' ,
value : 'red' ,
} ,
{
name : 'Gray Background' ,
value : 'gray_background' ,
} ,
{
name : 'Brown Background' ,
value : 'brown_background' ,
} ,
{
name : 'Orange Background' ,
value : 'orange_background' ,
} ,
{
name : 'Yellow Background' ,
value : 'yellow_background' ,
} ,
{
name : 'Green Background' ,
value : 'green_background' ,
} ,
{
name : 'Blue Background' ,
value : 'blue_background' ,
} ,
{
name : 'Purple Background' ,
value : 'purple_background' ,
} ,
{
name : 'Pink Background' ,
value : 'pink_background' ,
} ,
{
name : 'Red Background' ,
value : 'red_background' ,
} ,
] ;
2021-12-03 00:44:16 -08:00
const annotation : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
{
displayName : 'Annotations' ,
name : 'annotationUi' ,
type : 'collection' ,
placeholder : 'Add Annotation' ,
default : { } ,
options : [
{
displayName : 'Bold' ,
name : 'bold' ,
type : 'boolean' ,
default : false ,
2021-12-29 14:23:22 -08:00
description : 'Whether the text is bolded' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Italic' ,
name : 'italic' ,
type : 'boolean' ,
default : false ,
2021-12-29 14:23:22 -08:00
description : 'Whether the text is italicized' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Strikethrough' ,
name : 'strikethrough' ,
type : 'boolean' ,
default : false ,
2021-12-29 14:23:22 -08:00
description : 'Whether the text is struck through' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Underline' ,
name : 'underline' ,
type : 'boolean' ,
default : false ,
2021-12-29 14:23:22 -08:00
description : 'Whether the text is underlined' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Code' ,
name : 'code' ,
type : 'boolean' ,
default : false ,
2021-12-29 14:23:22 -08:00
description : 'Whether the text is code style' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Color' ,
name : 'color' ,
type : 'options' ,
options : colors ,
default : '' ,
2021-12-29 14:23:22 -08:00
description : 'Color of the text' ,
2021-05-20 14:31:23 -07:00
} ,
] ,
2021-12-29 14:23:22 -08:00
description : 'All annotations that apply to this rich text' ,
2021-05-20 14:31:23 -07:00
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2021-12-03 00:44:16 -08:00
const typeMention : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
{
displayName : 'Type' ,
name : 'mentionType' ,
type : 'options' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
textType : [ 'mention' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
options : [
{
name : 'Database' ,
value : 'database' ,
} ,
{
name : 'Date' ,
value : 'date' ,
} ,
{
name : 'Page' ,
value : 'page' ,
} ,
{
name : 'User' ,
value : 'user' ,
} ,
] ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'An inline mention of a user, page, database, or date. In the app these are created by typing @ followed by the name of a user, page, database, or a date.' ,
2021-05-20 14:31:23 -07:00
} ,
{
2022-06-03 10:23:49 -07:00
displayName : 'User Name or ID' ,
2021-05-20 14:31:23 -07:00
name : 'user' ,
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getUsers' ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'user' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'The ID of the user being mentioned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Page ID' ,
name : 'page' ,
type : 'string' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'page' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
default : '' ,
2021-12-29 14:23:22 -08:00
description : 'The ID of the page being mentioned' ,
2021-05-20 14:31:23 -07:00
} ,
{
2022-11-11 04:37:52 -08:00
displayName : 'Database' ,
2021-05-20 14:31:23 -07:00
name : 'database' ,
2022-11-11 04:37:52 -08:00
type : 'resourceLocator' ,
default : { mode : 'list' , value : '' } ,
modes : [
{
displayName : 'Database' ,
name : 'list' ,
type : 'list' ,
placeholder : 'Select a Database...' ,
typeOptions : {
searchListMethod : 'getDatabases' ,
searchable : true ,
} ,
} ,
{
displayName : 'Link' ,
name : 'url' ,
type : 'string' ,
placeholder :
'https://www.notion.so/0fe2f7de558b471eab07e9d871cdf4a9?v=f2d424ba0c404733a3f500c78c881610' ,
validation : [
{
type : 'regex' ,
properties : {
regex :
2022-11-22 04:43:28 -08:00
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}).*' ,
2022-11-11 04:37:52 -08:00
errorMessage : 'Not a valid Notion Database URL' ,
} ,
} ,
] ,
extractValue : {
type : 'regex' ,
2022-11-22 04:43:28 -08:00
regex :
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})' ,
2022-11-11 04:37:52 -08:00
} ,
} ,
{
displayName : 'ID' ,
name : 'id' ,
type : 'string' ,
placeholder : 'ab1545b247fb49fa92d6f4b49f4d8116' ,
validation : [
{
type : 'regex' ,
properties : {
2022-11-22 04:43:28 -08:00
regex :
'^(([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}))[ \t]*' ,
2022-11-11 04:37:52 -08:00
errorMessage : 'Not a valid Notion Database ID' ,
} ,
} ,
] ,
extractValue : {
type : 'regex' ,
regex : '^([0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})' ,
} ,
url : '=https://www.notion.so/{{$value.replace(/-/g, "")}}' ,
} ,
] ,
2021-05-20 14:31:23 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'database' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
2022-11-22 04:43:28 -08:00
description : 'The Notion Database being mentioned' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Range' ,
name : 'range' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'date' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
description : 'Whether or not you want to define a date range' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Date' ,
name : 'date' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'date' ] ,
range : [ false ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'dateTime' ,
default : '' ,
2021-12-29 14:23:22 -08:00
description : 'An ISO 8601 format date, with optional time' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Date Start' ,
name : 'dateStart' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
mentionType : [ 'date' ] ,
range : [ true ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'dateTime' ,
default : '' ,
2021-12-29 14:23:22 -08:00
description : 'An ISO 8601 format date, with optional time' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Date End' ,
name : 'dateEnd' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
range : [ true ] ,
mentionType : [ 'date' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'dateTime' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
'An ISO 8601 formatted date, with optional time. Represents the end of a date range.' ,
2021-05-20 14:31:23 -07:00
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2021-12-03 00:44:16 -08:00
const typeEquation : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
{
displayName : 'Expression' ,
name : 'expression' ,
type : 'string' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
textType : [ 'equation' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
default : '' ,
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2021-12-03 00:44:16 -08:00
const typeText : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
{
displayName : 'Text' ,
name : 'text' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
textType : [ 'text' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'string' ,
default : '' ,
2022-08-17 08:50:24 -07:00
description :
"Text content. This field contains the actual content of your text and is probably the field you'll use most often." ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Is Link' ,
name : 'isLink' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
textType : [ 'text' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'boolean' ,
default : false ,
} ,
{
displayName : 'Text Link' ,
name : 'textLink' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
textType : [ 'text' ] ,
isLink : [ true ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
type : 'string' ,
default : '' ,
2021-12-29 14:23:22 -08:00
description : 'The URL that this link points to' ,
2021-05-20 14:31:23 -07:00
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2022-08-17 08:50:24 -07:00
export const text = ( displayOptions : IDisplayOptions ) : INodeProperties [ ] = >
[
{
displayName : 'Text' ,
name : 'text' ,
placeholder : 'Add Text' ,
type : 'fixedCollection' ,
default : { } ,
typeOptions : {
multipleValues : true ,
2021-05-20 14:31:23 -07:00
} ,
2022-08-17 08:50:24 -07:00
displayOptions ,
options : [
{
name : 'text' ,
displayName : 'Text' ,
values : [
{
displayName : 'Type' ,
name : 'textType' ,
type : 'options' ,
options : [
{
name : 'Equation' ,
value : 'equation' ,
} ,
{
name : 'Mention' ,
value : 'mention' ,
} ,
{
name : 'Text' ,
value : 'text' ,
} ,
] ,
default : 'text' ,
} ,
. . . typeText ,
. . . typeMention ,
. . . typeEquation ,
2021-05-20 14:31:23 -07:00
2022-08-17 08:50:24 -07:00
. . . annotation ,
] ,
} ,
2021-05-20 14:31:23 -07:00
] ,
2022-08-17 08:50:24 -07:00
description : 'Rich text in the block' ,
2021-05-20 14:31:23 -07:00
} ,
2022-08-17 08:50:24 -07:00
] as INodeProperties [ ] ;
2021-05-20 14:31:23 -07:00
2022-08-17 08:50:24 -07:00
const todo = ( type : string ) : INodeProperties [ ] = >
[
{
displayName : 'Checked' ,
name : 'checked' ,
type : 'boolean' ,
default : false ,
displayOptions : {
show : {
type : [ type ] ,
} ,
} ,
description : 'Whether the to_do is checked or not' ,
2021-05-20 14:31:23 -07:00
} ,
2022-08-17 08:50:24 -07:00
] as INodeProperties [ ] ;
const title = ( type : string ) : INodeProperties [ ] = >
[
{
displayName : 'Title' ,
name : 'title' ,
type : 'string' ,
default : '' ,
displayOptions : {
show : {
type : [ type ] ,
} ,
} ,
description : 'Plain text of page title' ,
} ,
] as INodeProperties [ ] ;
2021-05-20 14:31:23 -07:00
2021-12-03 00:44:16 -08:00
const richText = ( displayOptions : IDisplayOptions ) : INodeProperties [ ] = > [
2021-05-20 14:31:23 -07:00
{
displayName : 'Rich Text' ,
name : 'richText' ,
type : 'boolean' ,
displayOptions ,
default : false ,
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2021-12-03 00:44:16 -08:00
const textContent = ( displayOptions : IDisplayOptions ) : INodeProperties [ ] = > [
2021-05-20 14:31:23 -07:00
{
displayName : 'Text' ,
name : 'textContent' ,
type : 'string' ,
displayOptions ,
default : '' ,
} ,
2021-12-03 00:44:16 -08:00
] ;
2021-05-20 14:31:23 -07:00
2021-12-29 14:23:22 -08:00
const block = ( blockType : string ) : INodeProperties [ ] = > {
2021-05-20 14:31:23 -07:00
const data : INodeProperties [ ] = [ ] ;
switch ( blockType ) {
case 'to_do' :
data . push ( . . . todo ( blockType ) ) ;
2022-08-17 08:50:24 -07:00
data . push (
. . . richText ( {
show : {
type : [ blockType ] ,
} ,
} ) ,
) ;
data . push (
. . . textContent ( {
show : {
type : [ blockType ] ,
richText : [ false ] ,
} ,
} ) ,
) ;
data . push (
. . . text ( {
show : {
type : [ blockType ] ,
richText : [ true ] ,
} ,
} ) ,
) ;
2021-05-20 14:31:23 -07:00
break ;
case 'child_page' :
data . push ( . . . title ( blockType ) ) ;
break ;
default :
2022-08-17 08:50:24 -07:00
data . push (
. . . richText ( {
show : {
type : [ blockType ] ,
} ,
} ) ,
) ;
data . push (
. . . textContent ( {
show : {
type : [ blockType ] ,
richText : [ false ] ,
} ,
} ) ,
) ;
data . push (
. . . text ( {
show : {
type : [ blockType ] ,
richText : [ true ] ,
} ,
} ) ,
) ;
2021-05-20 14:31:23 -07:00
break ;
}
return data ;
} ;
2022-08-17 08:50:24 -07:00
export const blocks = ( resource : string , operation : string ) : INodeProperties [ ] = > [
{
displayName : 'Blocks' ,
name : 'blockUi' ,
type : 'fixedCollection' ,
typeOptions : {
multipleValues : true ,
2021-05-20 14:31:23 -07:00
} ,
2022-08-17 08:50:24 -07:00
default : { } ,
displayOptions : {
show : {
resource : [ resource ] ,
operation : [ operation ] ,
} ,
2021-05-20 14:31:23 -07:00
} ,
2022-08-17 08:50:24 -07:00
placeholder : 'Add Block' ,
options : [
{
name : 'blockValues' ,
displayName : 'Block' ,
values : [
{
displayName : 'Type Name or ID' ,
name : 'type' ,
type : 'options' ,
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
typeOptions : {
loadOptionsMethod : 'getBlockTypes' ,
} ,
default : 'paragraph' ,
} ,
. . . block ( 'paragraph' ) ,
. . . block ( 'heading_1' ) ,
. . . block ( 'heading_2' ) ,
. . . block ( 'heading_3' ) ,
. . . block ( 'toggle' ) ,
. . . block ( 'to_do' ) ,
. . . block ( 'child_page' ) ,
. . . block ( 'bulleted_list_item' ) ,
. . . block ( 'numbered_list_item' ) ,
] ,
} ,
] ,
} ,
2021-12-03 00:44:16 -08:00
] ;