fox-block-builder
Version:
Maintainable code for loop slack-block-kit-like modal builder
98 lines • 3.38 kB
JavaScript
/* eslint-disable max-classes-per-file */
/* eslint-disable max-len */
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrintPreviewUrl = exports.GetPreviewUrl = exports.GetBlockId = exports.GetBlocks = exports.GetAttachments = exports.End = exports.BuildToObject = exports.BuildToJSON = void 0;
const lib_1 = require("../lib");
class BuildToJSON extends lib_1.Builder {
/**
* @description Builds the view and returns it as a Slack API-compatible JSON string.
*/
buildToJSON() {
const result = this.build();
return JSON.stringify(result);
}
}
exports.BuildToJSON = BuildToJSON;
class BuildToObject extends lib_1.Builder {
/**
* @description Builds the view and returns it as a Slack API-compatible object.
*/
buildToObject() {
return this.build();
}
}
exports.BuildToObject = BuildToObject;
class End extends lib_1.Builder {
/**
* @description Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object.
*
* {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation}
* {@link https://www.blockbuilder.dev|Open Block Builder Documentation}
*/
end() {
return this;
}
}
exports.End = End;
class GetAttachments extends lib_1.Builder {
/**
* @description Builds the view and returns a Slack API-compatible array of attachments.
*
* {@link https://api.slack.com/reference/messaging/attachments|View in Slack API Documentation}
*/
getAttachments() {
return this.build().attachments;
}
}
exports.GetAttachments = GetAttachments;
class GetBlocks extends lib_1.Builder {
/**
* @description Builds the view and returns a Slack API-compatible array of blocks.
*
* {@link https://api.slack.com/block-kit|View in Slack API Documentation}
*/
getBlocks() {
this.build();
return this.build().blocks;
}
}
exports.GetBlocks = GetBlocks;
class GetBlockId extends lib_1.Builder {
/**
* @description Builds the block and returns its id
*/
getBlockId() {
this.build();
return this.build().block_id;
}
}
exports.GetBlockId = GetBlockId;
class GetPreviewUrl extends lib_1.Builder {
/**
* @description Builds the view and returns the preview URL in order to open and preview the view on Slack's Block Kit Builder web application.
*/
getPreviewUrl() {
const result = this.build();
const baseUri = 'https://app.slack.com/block-kit-builder/#';
const stringifiedBlocks = result.type
? JSON.stringify(result)
: JSON.stringify({
blocks: result.blocks,
attachments: result.attachments,
});
return encodeURI(`${baseUri}${stringifiedBlocks}`).replace(/[!'()*]/g, escape);
}
}
exports.GetPreviewUrl = GetPreviewUrl;
class PrintPreviewUrl extends GetPreviewUrl {
/**
* @description Calls getPreviewUrl to build the preview URL and log it to the console.
*/
printPreviewUrl() {
// eslint-disable-next-line no-console
console.log(this.getPreviewUrl());
}
}
exports.PrintPreviewUrl = PrintPreviewUrl;
//# sourceMappingURL=other-methods.js.map
;