@peerboard/core
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -21,5 +21,2 @@ "use strict"; | ||
})(ExcludeOptions = exports.ExcludeOptions || (exports.ExcludeOptions = {})); | ||
var trimLeftSlash = function (str) { | ||
return str.startsWith('/') ? str.substr(1) : str; | ||
}; | ||
var forumSDK = null; | ||
@@ -51,12 +48,3 @@ var loadingSDK = null; | ||
}; | ||
var defaultOptions = function () { return ({ | ||
resize: true, | ||
hideMenu: true, | ||
baseURL: "https://peerboard." + window.document.location.hostname, | ||
sdkURL: PEERBOARD_EMBED_SDK_URL, | ||
onTitleChanged: function (title) { return window.document.title = title; }, | ||
onPathChanged: function (newPath) { return window.history.replaceState({}, window.document.title, newPath); } | ||
}); }; | ||
exports.createForum = function (forumID, container, options) { | ||
var _a; | ||
exports.createForum = function (forumID, container, opts) { | ||
if (typeof window === 'undefined') { | ||
@@ -66,37 +54,3 @@ console.warn('peerboard: window is not defined, cannot create forum, potentially used in ssr'); | ||
} | ||
var opts = __assign(__assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true }), options); | ||
var usesHashRouting = (_a = opts === null || opts === void 0 ? void 0 : opts.prefix) === null || _a === void 0 ? void 0 : _a.includes("#"); | ||
if (!opts.usePathFromQs) { | ||
// Auto resolve final location using part after the prefix | ||
if (opts.prefix && opts.prefix !== "/") { | ||
var pathname = document.location.pathname; | ||
if (usesHashRouting) { | ||
pathname += document.location.hash; | ||
} | ||
// Cut everything before the prefix to support /{lang}/{prefix}/{peer-board-path} cases | ||
var matches = new RegExp("(.*/" + trimLeftSlash(opts.prefix) + ")(.*)").exec(pathname); | ||
// Let's use current path and the root as best guess | ||
var prefix = document.location.pathname; | ||
var pbProductPath = "/"; | ||
if (matches) { | ||
if (matches[1]) { | ||
prefix = matches[1]; | ||
} | ||
if (matches[2]) { | ||
pbProductPath = matches[2]; | ||
} | ||
} | ||
opts.prefix = prefix; // override prefix to calculate proper path updates in remote embed script | ||
opts.path = "/" + trimLeftSlash(pbProductPath); | ||
} | ||
else { | ||
// TODO: For the root we cannot reliably detect language, country codes guess? | ||
opts.path = document.location.pathname; | ||
} | ||
// No need to add extra stuff since it's already counted at path in hash routing case | ||
if (!usesHashRouting) { | ||
opts.path += document.location.search + document.location.hash; | ||
} | ||
} | ||
return exports.loadSdk(options.sdkURL).then(function () { | ||
return exports.loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -120,4 +74,4 @@ throw new Error("Forum should be loaded at the moment."); | ||
console.error("Error creating forum: ", err); | ||
if (options.onFail) { | ||
options.onFail(); | ||
if (opts.onFail) { | ||
opts.onFail(); | ||
} | ||
@@ -127,3 +81,3 @@ throw err; | ||
}; | ||
exports.createCommentWidget = function (communityID, container, exclude, spaceID, options) { | ||
exports.createCommentWidget = function (communityID, container, exclude, spaceID, opts) { | ||
if (spaceID === void 0) { spaceID = 0; } | ||
@@ -134,7 +88,3 @@ if (typeof window === 'undefined') { | ||
} | ||
var opts = __assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true, | ||
// tslint:disable-next-line:no-empty | ||
onPathChanged: function () { } }); | ||
Object.assign(opts, options); | ||
return exports.loadSdk(options.sdkURL).then(function () { | ||
return exports.loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -141,0 +91,0 @@ throw new Error("Forum should be loaded at the moment."); |
@@ -36,5 +36,2 @@ 'use strict'; | ||
})(exports.ExcludeOptions || (exports.ExcludeOptions = {})); | ||
var trimLeftSlash = function (str) { | ||
return str.startsWith('/') ? str.substr(1) : str; | ||
}; | ||
var forumSDK = null; | ||
@@ -66,12 +63,3 @@ var loadingSDK = null; | ||
}; | ||
var defaultOptions = function () { return ({ | ||
resize: true, | ||
hideMenu: true, | ||
baseURL: "https://peerboard." + window.document.location.hostname, | ||
sdkURL: PEERBOARD_EMBED_SDK_URL, | ||
onTitleChanged: function (title) { return window.document.title = title; }, | ||
onPathChanged: function (newPath) { return window.history.replaceState({}, window.document.title, newPath); } | ||
}); }; | ||
var createForum = function (forumID, container, options) { | ||
var _a; | ||
var createForum = function (forumID, container, opts) { | ||
if (typeof window === 'undefined') { | ||
@@ -81,37 +69,3 @@ console.warn('peerboard: window is not defined, cannot create forum, potentially used in ssr'); | ||
} | ||
var opts = __assign(__assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true }), options); | ||
var usesHashRouting = (_a = opts === null || opts === void 0 ? void 0 : opts.prefix) === null || _a === void 0 ? void 0 : _a.includes("#"); | ||
if (!opts.usePathFromQs) { | ||
// Auto resolve final location using part after the prefix | ||
if (opts.prefix && opts.prefix !== "/") { | ||
var pathname = document.location.pathname; | ||
if (usesHashRouting) { | ||
pathname += document.location.hash; | ||
} | ||
// Cut everything before the prefix to support /{lang}/{prefix}/{peer-board-path} cases | ||
var matches = new RegExp("(.*/" + trimLeftSlash(opts.prefix) + ")(.*)").exec(pathname); | ||
// Let's use current path and the root as best guess | ||
var prefix = document.location.pathname; | ||
var pbProductPath = "/"; | ||
if (matches) { | ||
if (matches[1]) { | ||
prefix = matches[1]; | ||
} | ||
if (matches[2]) { | ||
pbProductPath = matches[2]; | ||
} | ||
} | ||
opts.prefix = prefix; // override prefix to calculate proper path updates in remote embed script | ||
opts.path = "/" + trimLeftSlash(pbProductPath); | ||
} | ||
else { | ||
// TODO: For the root we cannot reliably detect language, country codes guess? | ||
opts.path = document.location.pathname; | ||
} | ||
// No need to add extra stuff since it's already counted at path in hash routing case | ||
if (!usesHashRouting) { | ||
opts.path += document.location.search + document.location.hash; | ||
} | ||
} | ||
return loadSdk(options.sdkURL).then(function () { | ||
return loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -135,4 +89,4 @@ throw new Error("Forum should be loaded at the moment."); | ||
console.error("Error creating forum: ", err); | ||
if (options.onFail) { | ||
options.onFail(); | ||
if (opts.onFail) { | ||
opts.onFail(); | ||
} | ||
@@ -142,3 +96,3 @@ throw err; | ||
}; | ||
var createCommentWidget = function (communityID, container, exclude, spaceID, options) { | ||
var createCommentWidget = function (communityID, container, exclude, spaceID, opts) { | ||
if (spaceID === void 0) { spaceID = 0; } | ||
@@ -149,7 +103,3 @@ if (typeof window === 'undefined') { | ||
} | ||
var opts = __assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true, | ||
// tslint:disable-next-line:no-empty | ||
onPathChanged: function () { } }); | ||
Object.assign(opts, options); | ||
return loadSdk(options.sdkURL).then(function () { | ||
return loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -156,0 +106,0 @@ throw new Error("Forum should be loaded at the moment."); |
@@ -38,5 +38,2 @@ (function (global, factory) { | ||
})(exports.ExcludeOptions || (exports.ExcludeOptions = {})); | ||
var trimLeftSlash = function (str) { | ||
return str.startsWith('/') ? str.substr(1) : str; | ||
}; | ||
var forumSDK = null; | ||
@@ -68,12 +65,3 @@ var loadingSDK = null; | ||
}; | ||
var defaultOptions = function () { return ({ | ||
resize: true, | ||
hideMenu: true, | ||
baseURL: "https://peerboard." + window.document.location.hostname, | ||
sdkURL: PEERBOARD_EMBED_SDK_URL, | ||
onTitleChanged: function (title) { return window.document.title = title; }, | ||
onPathChanged: function (newPath) { return window.history.replaceState({}, window.document.title, newPath); } | ||
}); }; | ||
var createForum = function (forumID, container, options) { | ||
var _a; | ||
var createForum = function (forumID, container, opts) { | ||
if (typeof window === 'undefined') { | ||
@@ -83,37 +71,3 @@ console.warn('peerboard: window is not defined, cannot create forum, potentially used in ssr'); | ||
} | ||
var opts = __assign(__assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true }), options); | ||
var usesHashRouting = (_a = opts === null || opts === void 0 ? void 0 : opts.prefix) === null || _a === void 0 ? void 0 : _a.includes("#"); | ||
if (!opts.usePathFromQs) { | ||
// Auto resolve final location using part after the prefix | ||
if (opts.prefix && opts.prefix !== "/") { | ||
var pathname = document.location.pathname; | ||
if (usesHashRouting) { | ||
pathname += document.location.hash; | ||
} | ||
// Cut everything before the prefix to support /{lang}/{prefix}/{peer-board-path} cases | ||
var matches = new RegExp("(.*/" + trimLeftSlash(opts.prefix) + ")(.*)").exec(pathname); | ||
// Let's use current path and the root as best guess | ||
var prefix = document.location.pathname; | ||
var pbProductPath = "/"; | ||
if (matches) { | ||
if (matches[1]) { | ||
prefix = matches[1]; | ||
} | ||
if (matches[2]) { | ||
pbProductPath = matches[2]; | ||
} | ||
} | ||
opts.prefix = prefix; // override prefix to calculate proper path updates in remote embed script | ||
opts.path = "/" + trimLeftSlash(pbProductPath); | ||
} | ||
else { | ||
// TODO: For the root we cannot reliably detect language, country codes guess? | ||
opts.path = document.location.pathname; | ||
} | ||
// No need to add extra stuff since it's already counted at path in hash routing case | ||
if (!usesHashRouting) { | ||
opts.path += document.location.search + document.location.hash; | ||
} | ||
} | ||
return loadSdk(options.sdkURL).then(function () { | ||
return loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -137,4 +91,4 @@ throw new Error("Forum should be loaded at the moment."); | ||
console.error("Error creating forum: ", err); | ||
if (options.onFail) { | ||
options.onFail(); | ||
if (opts.onFail) { | ||
opts.onFail(); | ||
} | ||
@@ -144,3 +98,3 @@ throw err; | ||
}; | ||
var createCommentWidget = function (communityID, container, exclude, spaceID, options) { | ||
var createCommentWidget = function (communityID, container, exclude, spaceID, opts) { | ||
if (spaceID === void 0) { spaceID = 0; } | ||
@@ -151,7 +105,3 @@ if (typeof window === 'undefined') { | ||
} | ||
var opts = __assign(__assign({}, defaultOptions()), { scrollToTopOnNavigationChanged: true, | ||
// tslint:disable-next-line:no-empty | ||
onPathChanged: function () { } }); | ||
Object.assign(opts, options); | ||
return loadSdk(options.sdkURL).then(function () { | ||
return loadSdk(opts.sdkURL).then(function () { | ||
if (!forumSDK) { | ||
@@ -158,0 +108,0 @@ throw new Error("Forum should be loaded at the moment."); |
@@ -54,3 +54,3 @@ export declare enum ExcludeOptions { | ||
} | ||
interface Options extends FunctionOptions, LoginOptions, SdkUrlOptions, TitleOptions, UrlOptions { | ||
export interface Options extends FunctionOptions, LoginOptions, SdkUrlOptions, TitleOptions, UrlOptions { | ||
prefix?: string; | ||
@@ -92,4 +92,4 @@ anon?: boolean; | ||
export declare const loadSdk: (embedSDKURL?: string | undefined) => Promise<void>; | ||
export declare const createForum: (forumID: number, container: HTMLElement, options: Readonly<Options>) => Promise<ForumAPI | null>; | ||
export declare const createCommentWidget: (communityID: number, container: HTMLElement, exclude: ExcludeOptions[], spaceID: number | undefined, options: Readonly<WidgetOptions>) => Promise<ForumAPI | null>; | ||
export declare const createForum: (forumID: number, container: HTMLElement, opts: Readonly<Options>) => Promise<ForumAPI | null>; | ||
export declare const createCommentWidget: (communityID: number, container: HTMLElement, exclude: ExcludeOptions[], spaceID: number | undefined, opts: Readonly<WidgetOptions>) => Promise<ForumAPI | null>; | ||
export {}; |
{ | ||
"name": "@peerboard/core", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"description": "peerboard.com frontend components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44568
445