Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tolgee/core

Package Overview
Dependencies
Maintainers
1
Versions
354
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tolgee/core - npm Package Compare versions

Comparing version 1.0.0-alpha.45 to 1.0.0-alpha.46

6

lib/Constants/Global.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TOLGEE_TARGET_ATTRIBUTE = exports.TOLGEE_ATTRIBUTE_NAME = exports.RESTRICTED_ASCENDANT_ATTRIBUTE = void 0;
exports.RESTRICTED_ASCENDANT_ATTRIBUTE = "data-tolgee-restricted";
exports.TOLGEE_ATTRIBUTE_NAME = "_tolgee";
exports.TOLGEE_TARGET_ATTRIBUTE = "_tolgee-target";
exports.RESTRICTED_ASCENDANT_ATTRIBUTE = 'data-tolgee-restricted';
exports.TOLGEE_ATTRIBUTE_NAME = '_tolgee';
exports.TOLGEE_TARGET_ATTRIBUTE = '_tolgee-target';
//# sourceMappingURL=Global.js.map

@@ -20,3 +20,3 @@ "use strict";

function ApiHttpError(response, code) {
var _this = _super.call(this, "Api http error") || this;
var _this = _super.call(this, 'Api http error') || this;
_this.response = response;

@@ -23,0 +23,0 @@ _this.code = code;

@@ -1,6 +0,6 @@

import { Properties } from "../Properties";
import { KeyAndParams, NodeWithMeta } from "../types";
import { TextService } from "../services/TextService";
import { ElementRegistrar } from "../services/ElementRegistrar";
import { TranslationHighlighter } from "../highlighter/TranslationHighlighter";
import { Properties } from '../Properties';
import { KeyAndParams, NodeWithMeta } from '../types';
import { TextService } from '../services/TextService';
import { ElementRegistrar } from '../services/ElementRegistrar';
import { TranslationHighlighter } from '../highlighter/TranslationHighlighter';
export declare abstract class AbstractHandler {

@@ -12,9 +12,9 @@ protected properties: Properties;

protected constructor(properties: Properties, textService: TextService, elementRegistrar: ElementRegistrar, translationHighlighter: TranslationHighlighter);
private static initParentElement;
abstract handle(node: Node): any;
protected filterRestricted<T extends Element | Text>(nodes: T[]): T[];
protected handleNodes(nodes: Array<Text | Attr>): Promise<void>;
protected translateChildNode(node: (Text | Attr), newValue: any, keys: KeyAndParams[]): NodeWithMeta;
private static initParentElement;
protected translateChildNode(node: Text | Attr, newValue: any, keys: KeyAndParams[]): NodeWithMeta;
private getParentElement;
private getSuitableParent;
}

@@ -60,2 +60,11 @@ "use strict";

}
AbstractHandler.initParentElement = function (element) {
if (element[Global_1.TOLGEE_ATTRIBUTE_NAME] === undefined) {
element[Global_1.TOLGEE_ATTRIBUTE_NAME] = {
nodes: new Set(),
};
element.setAttribute(Global_1.TOLGEE_ATTRIBUTE_NAME, '');
}
return element;
};
AbstractHandler.prototype.filterRestricted = function (nodes) {

@@ -65,4 +74,4 @@ var restrictedElements = this.properties.config.restrictedElements;

var e = NodeHelper_1.NodeHelper.closestElement(n);
return restrictedElements.indexOf(e.tagName.toLowerCase()) === -1
&& e.closest("[" + Global_1.RESTRICTED_ASCENDANT_ATTRIBUTE + "=\"true\"]") === null;
return (restrictedElements.indexOf(e.tagName.toLowerCase()) === -1 &&
e.closest("[" + Global_1.RESTRICTED_ASCENDANT_ATTRIBUTE + "=\"true\"]") === null);
});

@@ -116,3 +125,3 @@ };

oldTextContent: node.textContent,
keys: keys
keys: keys,
};

@@ -122,11 +131,2 @@ node.textContent = newValue;

};
AbstractHandler.initParentElement = function (element) {
if (element[Global_1.TOLGEE_ATTRIBUTE_NAME] === undefined) {
element[Global_1.TOLGEE_ATTRIBUTE_NAME] = {
nodes: new Set()
};
element.setAttribute(Global_1.TOLGEE_ATTRIBUTE_NAME, "");
}
return element;
};
AbstractHandler.prototype.getParentElement = function (node) {

@@ -139,4 +139,5 @@ var parent = this.getSuitableParent(node);

if (domParent === undefined) {
// eslint-disable-next-line no-console
console.error(node);
throw new Error("No suitable parent found for node above.");
throw new Error('No suitable parent found for node above.');
}

@@ -147,3 +148,5 @@ if (!this.properties.config.passToParent) {

if (Array.isArray(this.properties.config.passToParent)) {
var tagNameEquals = function (elementTagName) { return domParent.tagName.toLowerCase() === elementTagName.toLowerCase(); };
var tagNameEquals = function (elementTagName) {
return domParent.tagName.toLowerCase() === elementTagName.toLowerCase();
};
if (this.properties.config.passToParent.findIndex(tagNameEquals) === -1) {

@@ -153,3 +156,3 @@ return domParent;

}
if (typeof this.properties.config.passToParent === "function") {
if (typeof this.properties.config.passToParent === 'function') {
if (!this.properties.config.passToParent(domParent)) {

@@ -156,0 +159,0 @@ return domParent;

@@ -1,6 +0,6 @@

import { AbstractHandler } from "./AbstractHandler";
import { Properties } from "../Properties";
import { TextService } from "../services/TextService";
import { ElementRegistrar } from "../services/ElementRegistrar";
import { TranslationHighlighter } from "../highlighter/TranslationHighlighter";
import { AbstractHandler } from './AbstractHandler';
import { Properties } from '../Properties';
import { TextService } from '../services/TextService';
import { ElementRegistrar } from '../services/ElementRegistrar';
import { TranslationHighlighter } from '../highlighter/TranslationHighlighter';
export declare class AttributeHandler extends AbstractHandler {

@@ -7,0 +7,0 @@ protected properties: Properties;

@@ -5,4 +5,4 @@ import { CoreService } from '../services/CoreService';

import { Properties } from '../Properties';
import { AttributeHandler } from "./AttributeHandler";
import { TextService } from "../services/TextService";
import { AttributeHandler } from './AttributeHandler';
import { TextService } from '../services/TextService';
export declare class CoreHandler {

@@ -9,0 +9,0 @@ private service;

import { Properties } from '../Properties';
import { TranslationHighlighter } from '../highlighter/TranslationHighlighter';
import { TextService } from "../services/TextService";
import { AbstractHandler } from "./AbstractHandler";
import { ElementRegistrar } from "../services/ElementRegistrar";
import { TextService } from '../services/TextService';
import { AbstractHandler } from './AbstractHandler';
import { ElementRegistrar } from '../services/ElementRegistrar';
export declare class TextHandler extends AbstractHandler {

@@ -7,0 +7,0 @@ protected properties: Properties;

@@ -1,2 +0,2 @@

import { ArgumentTypes } from "./commonTypes";
import { ArgumentTypes } from './commonTypes';
export declare class NodeHelper {

@@ -3,0 +3,0 @@ private static evaluateGenerator;

@@ -89,5 +89,5 @@ "use strict";

if (arr.length < 1) {
throw new Error("No element found");
throw new Error('No element found');
}
throw new Error("Multiple elements found");
throw new Error('Multiple elements found');
};

@@ -112,3 +112,3 @@ NodeHelper.closestElement = function (node) {

NodeHelper.markElementAsTargetElement = function (element) {
element.setAttribute(Global_1.TOLGEE_TARGET_ATTRIBUTE, "");
element.setAttribute(Global_1.TOLGEE_TARGET_ATTRIBUTE, '');
};

@@ -115,0 +115,0 @@ NodeHelper.unmarkElementAsTargetElement = function (element) {

@@ -9,3 +9,3 @@ "use strict";

var result = [];
var actual = "";
var actual = '';
for (var i = 0; i < string.length; i++) {

@@ -15,3 +15,3 @@ var char = string[i];

result.push(this.removeEscapes(actual));
actual = "";
actual = '';
continue;

@@ -26,3 +26,3 @@ }

var escapeCharsCount = 0;
while (position > -1 && fullString[position - 1] === "\\") {
while (position > -1 && fullString[position - 1] === '\\') {
escapeCharsCount++;

@@ -35,6 +35,6 @@ position--;

return text.replace(/\\?\\?/g, function (match) {
if (match == "\\\\") {
return "\\";
if (match == '\\\\') {
return '\\';
}
return "";
return '';
});

@@ -41,0 +41,0 @@ };

@@ -1,3 +0,3 @@

import { ElementWithMeta } from "../types";
import { Properties } from "../Properties";
import { ElementWithMeta } from '../types';
import { Properties } from '../Properties';
export declare class MouseEventHandler {

@@ -4,0 +4,0 @@ private properties;

@@ -40,3 +40,4 @@ "use strict";

if (element._tolgee.listeningForHighlighting) {
console.error("Element is already listening mouse events! This is probably bug in tolgee");
// eslint-disable-next-line no-console
console.error('Element is already listening mouse events! This is probably bug in tolgee');
return;

@@ -66,4 +67,4 @@ }

};
element.addEventListener("mouseover", onMouseOver);
element.addEventListener("click", onClick);
element.addEventListener('mouseover', onMouseOver);
element.addEventListener('click', onClick);
var onMouseDownOrUp = function (e) {

@@ -75,11 +76,11 @@ if (_this.areKeysDown()) {

};
element.addEventListener("mousedown", onMouseDownOrUp);
element.addEventListener("mouseup", onMouseDownOrUp);
element.addEventListener("mouseout", onMouseOut);
element.addEventListener('mousedown', onMouseDownOrUp);
element.addEventListener('mouseup', onMouseDownOrUp);
element.addEventListener('mouseout', onMouseOut);
element._tolgee.removeAllEventListeners = function () {
element.removeEventListener("mousedown", onMouseDownOrUp);
element.removeEventListener("mouseup", onMouseDownOrUp);
element.removeEventListener("mouseover", onMouseOver);
element.removeEventListener("click", onClick);
element.removeEventListener("mouseout", onMouseOut);
element.removeEventListener('mousedown', onMouseDownOrUp);
element.removeEventListener('mouseup', onMouseDownOrUp);
element.removeEventListener('mouseover', onMouseOver);
element.removeEventListener('click', onClick);
element.removeEventListener('mouseout', onMouseOut);
};

@@ -94,4 +95,6 @@ };

MouseEventHandler.prototype.highlight = function () {
this.highlightedInitialBackgroundColor = this.getMouseOn().style.backgroundColor;
this.getMouseOn().style.backgroundColor = this.properties.config.highlightColor;
this.highlightedInitialBackgroundColor =
this.getMouseOn().style.backgroundColor;
this.getMouseOn().style.backgroundColor =
this.properties.config.highlightColor;
this.highlighted = this.getMouseOn();

@@ -101,3 +104,4 @@ };

if (this.highlighted) {
this.highlighted.style.backgroundColor = this.highlightedInitialBackgroundColor;
this.highlighted.style.backgroundColor =
this.highlightedInitialBackgroundColor;
this.highlighted = null;

@@ -104,0 +108,0 @@ }

import { CoreService } from '../services/CoreService';
import { ElementWithMeta } from '../types';
import { Properties } from '../Properties';
import { EventService } from "../services/EventService";
import { TranslationService } from "../services/TranslationService";
import { MouseEventHandler } from "./MouseEventHandler";
import { EventService } from '../services/EventService';
import { TranslationService } from '../services/TranslationService';
import { MouseEventHandler } from './MouseEventHandler';
export declare class TranslationHighlighter {

@@ -8,0 +8,0 @@ private service;

@@ -88,3 +88,3 @@ "use strict";

case 0:
if (!(typeof this.renderer === "object")) return [3 /*break*/, 2];
if (!(typeof this.renderer === 'object')) return [3 /*break*/, 2];
return [4 /*yield*/, this.getKey(e, element)];

@@ -99,4 +99,5 @@ case 1:

case 2:
console.warn("Tolgee UI is not provided. To translate interactively provide tolgee ui constructor to \"ui\" configuration property. " +
"To disable highlighting use production mode.");
// eslint-disable-next-line no-console
console.warn('Tolgee UI is not provided. To translate interactively provide tolgee ui constructor to "ui" configuration property. ' +
'To disable highlighting use production mode.');
return [2 /*return*/];

@@ -131,3 +132,4 @@ }

}
console.error("No key to translate. This seems like a bug in tolgee.");
// eslint-disable-next-line no-console
console.error('No key to translate. This seems like a bug in tolgee.');
return [2 /*return*/];

@@ -140,5 +142,3 @@ }

var nodes = Array.from(node._tolgee.nodes);
var keys = nodes.reduce(function (acc, curr) {
return __spread(acc, curr._tolgee.keys.map(function (k) { return k.key; }));
}, []);
var keys = nodes.reduce(function (acc, curr) { return __spread(acc, curr._tolgee.keys.map(function (k) { return k.key; })); }, []);
return new Set(keys);

@@ -149,3 +149,3 @@ };

if (this._renderer === undefined) {
if (typeof this.properties.config.ui === "function") {
if (typeof this.properties.config.ui === 'function') {
this._renderer = new this.properties.config.ui({

@@ -155,3 +155,3 @@ coreService: this.service,

eventService: this.eventService,
translationService: this.translationService
translationService: this.translationService,
});

@@ -158,0 +158,0 @@ }

import 'reflect-metadata';
import 'regenerator-runtime/runtime';
import { Tolgee } from './Tolgee';
import { TolgeeConfig } from "./TolgeeConfig";
import { TolgeeConfig } from './TolgeeConfig';
import { ModifierKey } from './Constants/ModifierKey';
export { Tolgee, TolgeeConfig, ModifierKey };

@@ -1,6 +0,6 @@

import { CoreHandler } from "./handlers/CoreHandler";
import { Properties } from "./Properties";
import { TextHandler } from "./handlers/TextHandler";
import { AttributeHandler } from "./handlers/AttributeHandler";
import { ElementRegistrar } from "./services/ElementRegistrar";
import { CoreHandler } from './handlers/CoreHandler';
import { Properties } from './Properties';
import { TextHandler } from './handlers/TextHandler';
import { AttributeHandler } from './handlers/AttributeHandler';
import { ElementRegistrar } from './services/ElementRegistrar';
export declare class Observer {

@@ -7,0 +7,0 @@ private properties;

@@ -125,3 +125,8 @@ "use strict";

Observer.prototype.observe = function () {
this.observer.observe(this.properties.config.targetElement, { attributes: true, childList: true, subtree: true, characterData: true });
this.observer.observe(this.properties.config.targetElement, {
attributes: true,
childList: true,
subtree: true,
characterData: true,
});
};

@@ -128,0 +133,0 @@ Observer.prototype.stopObserving = function () {

import { TolgeeConfig } from './TolgeeConfig';
import { Scope } from "./types";
import { Scope } from './types';
export declare class Properties {

@@ -4,0 +4,0 @@ config: TolgeeConfig;

@@ -11,4 +11,4 @@ "use strict";

var tsyringe_1 = require("tsyringe");
var PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY = "__tolgee_preferredLanguages";
var CURRENT_LANGUAGE_LOCAL_STORAGE_KEY = "__tolgee_currentLanguage";
var PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY = '__tolgee_preferredLanguages';
var CURRENT_LANGUAGE_LOCAL_STORAGE_KEY = '__tolgee_currentLanguage';
var Properties = /** @class */ (function () {

@@ -55,3 +55,3 @@ function Properties() {

}
var getTwoLetters_1 = function (fullTag) { return fullTag.replace(/^(.+?)(-.*)?$/, "$1"); };
var getTwoLetters_1 = function (fullTag) { return fullTag.replace(/^(.+?)(-.*)?$/, '$1'); };
var preferredTwoLetter_1 = getTwoLetters_1(window.navigator.language);

@@ -58,0 +58,0 @@ var twoLetterMatch = this.config.availableLanguages.find(function (l) { return getTwoLetters_1(l) === preferredTwoLetter_1; });

@@ -1,5 +0,5 @@

import { Properties } from "../Properties";
import { ArgumentTypes } from "../helpers/commonTypes";
import { Properties } from '../Properties';
import { ArgumentTypes } from '../helpers/commonTypes';
declare type FetchArgumentTypes = ArgumentTypes<typeof fetch>;
declare type Tail<T extends any[]> = ((...args: T) => any) extends ((_: infer First, ...rest: infer Rest) => any) ? T extends any[] ? Rest : ReadonlyArray<Rest[number]> : [];
declare type Tail<T extends any[]> = ((...args: T) => any) extends (_: infer First, ...rest: infer Rest) => any ? T extends any[] ? Rest : ReadonlyArray<Rest[number]> : [];
export declare class ApiHttpService {

@@ -6,0 +6,0 @@ private properties;

@@ -98,3 +98,3 @@ "use strict";

case 0:
if (!(typeof args[0] === "object")) return [3 /*break*/, 2];
if (!(typeof args[0] === 'object')) return [3 /*break*/, 2];
return [4 /*yield*/, fetch(__assign(__assign({}, args[0]), { url: this.getUrl(args[0].url) })).then(function (r) { return ApiHttpService_1.handleErrors(r); })];

@@ -104,3 +104,5 @@ case 1: return [2 /*return*/, _b.sent()];

_a = __read(args), url = _a[0], rest = _a.slice(1);
return [4 /*yield*/, fetch.apply(void 0, __spread([this.getUrl(url)], rest)).then(function (r) { return ApiHttpService_1.handleErrors(r); })];
return [4 /*yield*/, fetch.apply(void 0, __spread([this.getUrl(url)], rest)).then(function (r) {
return ApiHttpService_1.handleErrors(r);
})];
case 3: return [2 /*return*/, _b.sent()];

@@ -137,3 +139,3 @@ }

case 0: return [4 /*yield*/, this.fetch.apply(this, __spread([url, __assign({ body: JSON.stringify(body), method: 'POST', headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
} }, init)], rest))];

@@ -178,3 +180,4 @@ case 1: return [2 /*return*/, _a.sent()];

e_1 = _a.sent();
console.warn("Tolgee server responded with invalid status code.");
// eslint-disable-next-line no-console
console.warn('Tolgee server responded with invalid status code.');
return [3 /*break*/, 4];

@@ -181,0 +184,0 @@ case 4: throw error;

import { Properties } from '../Properties';
import { ApiHttpService } from "./ApiHttpService";
import { Scope } from "../types";
import { ApiHttpService } from './ApiHttpService';
import { Scope } from '../types';
export declare class CoreService {

@@ -5,0 +5,0 @@ private properties;

@@ -70,3 +70,5 @@ "use strict";

languages = new (_a.apply(Set, [void 0, _b.sent()]))();
this.properties.preferredLanguages = new Set(Array.from(this.properties.preferredLanguages).filter(function (l) { return languages.has(l); }));
this.properties.preferredLanguages = new Set(Array.from(this.properties.preferredLanguages).filter(function (l) {
return languages.has(l);
}));
return [2 /*return*/, languages];

@@ -88,5 +90,7 @@ }

e_1 = _a.sent();
// eslint-disable-next-line no-console
console.error(e_1);
console.error("Error getting scopes. Trying to switch to production mode!");
this.properties.config.mode = "production";
// eslint-disable-next-line no-console
console.error('Error getting scopes. Trying to switch to production mode!');
this.properties.config.mode = 'production';
return [3 /*break*/, 3];

@@ -108,3 +112,4 @@ case 3: return [2 /*return*/];

tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped),
__metadata("design:paramtypes", [Properties_1.Properties, ApiHttpService_1.ApiHttpService])
__metadata("design:paramtypes", [Properties_1.Properties,
ApiHttpService_1.ApiHttpService])
], CoreService);

@@ -111,0 +116,0 @@ return CoreService;

@@ -1,4 +0,4 @@

import { ElementWithMeta } from "../types";
import { Properties } from "../Properties";
import { TranslationHighlighter } from "../highlighter/TranslationHighlighter";
import { ElementWithMeta } from '../types';
import { Properties } from '../Properties';
import { TranslationHighlighter } from '../highlighter/TranslationHighlighter';
export declare class ElementRegistrar {

@@ -5,0 +5,0 @@ private properties;

@@ -67,3 +67,4 @@ "use strict";

}
if (this.properties.config.mode === "development" && !this.registeredElements.has(element)) {
if (this.properties.config.mode === 'development' &&
!this.registeredElements.has(element)) {
this.translationHighlighter.listen(element);

@@ -115,3 +116,3 @@ }

ElementRegistrar.prototype.cleanElement = function (element) {
if (typeof element._tolgee.removeAllEventListeners === "function") {
if (typeof element._tolgee.removeAllEventListeners === 'function') {
element._tolgee.removeAllEventListeners();

@@ -163,3 +164,4 @@ }

tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped),
__metadata("design:paramtypes", [Properties_1.Properties, TranslationHighlighter_1.TranslationHighlighter])
__metadata("design:paramtypes", [Properties_1.Properties,
TranslationHighlighter_1.TranslationHighlighter])
], ElementRegistrar);

@@ -166,0 +168,0 @@ return ElementRegistrar;

@@ -1,3 +0,3 @@

import { Subscription } from "./Subscription";
export declare type CallbackType<T> = (data: T) => (Promise<void> | void);
import { Subscription } from './Subscription';
export declare type CallbackType<T> = (data: T) => Promise<void> | void;
export interface EventEmitter<T> {

@@ -4,0 +4,0 @@ subscribe(callback: CallbackType<T>): Subscription;

@@ -35,3 +35,3 @@ "use strict";

var returned = callback(data);
if (typeof (returned === null || returned === void 0 ? void 0 : returned["then"]) === "function") {
if (typeof (returned === null || returned === void 0 ? void 0 : returned['then']) === 'function') {
promiseReturns.push(returned);

@@ -51,3 +51,5 @@ }

}
return new Promise(function (resolve) { return Promise.all(promiseReturns).then(function () { return resolve(); }); });
return new Promise(function (resolve) {
return Promise.all(promiseReturns).then(function () { return resolve(); });
});
};

@@ -64,3 +66,4 @@ EventEmitterImpl.prototype.subscribe = function (callback) {

if (!wasPresent) {
console.warn("Event to unsubscribe was not found");
// eslint-disable-next-line no-console
console.warn('Event to unsubscribe was not found');
}

@@ -67,0 +70,0 @@ };

@@ -1,3 +0,3 @@

import { EventEmitter } from "./EventEmitter";
import { TranslationData } from "../DTOs/TranslationData";
import { EventEmitter } from './EventEmitter';
import { TranslationData } from '../DTOs/TranslationData';
export declare class EventService {

@@ -4,0 +4,0 @@ readonly TRANSLATION_CHANGED: EventEmitter<TranslationData>;

@@ -1,4 +0,4 @@

import { KeyAndParams, TranslationParams } from "../types";
import { TranslationService } from "./TranslationService";
import { Properties } from "../Properties";
import { KeyAndParams, TranslationParams } from '../types';
import { TranslationService } from './TranslationService';
import { Properties } from '../Properties';
export declare type ReplacedType = {

@@ -5,0 +5,0 @@ text: string;

@@ -80,3 +80,4 @@ "use strict";

catch (e) {
if (e.code === "MISSING_VALUE") {
if (e.code === 'MISSING_VALUE') {
// eslint-disable-next-line no-console
console.warn(e.message);

@@ -91,10 +92,12 @@ return translation;

this.escapeParam = function (param) {
if (typeof param === "string") {
return param.replace(/[,:\\]/gs, "\\$&");
if (typeof param === 'string') {
return param.replace(/[,:\\]/gs, '\\$&');
}
if (typeof param === "number" || typeof param === "bigint") {
if (typeof param === 'number' || typeof param === 'bigint') {
return param.toString();
}
// eslint-disable-next-line no-console
console.warn(param);
console.warn("Unsupported value type of above param. Consider converting to string.");
// eslint-disable-next-line no-console
console.warn('Unsupported value type of above param. Consider converting to string.');
return param;

@@ -128,7 +131,7 @@ };

case 0:
matchRegexp = new RegExp(this.rawUnWrapRegex, "gs");
matchRegexp = new RegExp(this.rawUnWrapRegex, 'gs');
keysAndParams = [];
matched = false;
start = 0;
result = "";
result = '';
_b.label = 1;

@@ -141,3 +144,3 @@ case 1:

start = index + fullMatch.length;
if (pre === "\\" && !TextHelper_1.TextHelper.isCharEscaped(index, text)) {
if (pre === '\\' && !TextHelper_1.TextHelper.isCharEscaped(index, text)) {
result += wrapped;

@@ -167,7 +170,9 @@ return [3 /*break*/, 1];

if (params === void 0) { params = {}; }
var paramString = Object.entries(params).map(function (_a) {
var paramString = Object.entries(params)
.map(function (_a) {
var _b = __read(_a, 2), name = _b[0], value = _b[1];
return _this.escapeParam(name) + ":" + _this.escapeParam(value);
}).join(",");
paramString = paramString.length ? ":" + paramString : "";
})
.join(',');
paramString = paramString.length ? ":" + paramString : '';
return "" + this.properties.config.inputPrefix + this.escapeParam(key) + paramString + this.properties.config.inputSuffix;

@@ -192,3 +197,6 @@ };

var strings = unWrappedString.match(/(?:[^\\,:\n]|\\.)+/g);
var result = { key: TextHelper_1.TextHelper.removeEscapes(strings.shift()), params: {} };
var result = {
key: TextHelper_1.TextHelper.removeEscapes(strings.shift()),
params: {},
};
while (strings.length) {

@@ -212,3 +220,4 @@ var _a = __read(strings.splice(0, 2), 2), name_1 = _a[0], value = _a[1];

tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped),
__metadata("design:paramtypes", [Properties_1.Properties, TranslationService_1.TranslationService])
__metadata("design:paramtypes", [Properties_1.Properties,
TranslationService_1.TranslationService])
], TextService);

@@ -215,0 +224,0 @@ return TextService;

@@ -1,6 +0,6 @@

import { TranslationData } from "../DTOs/TranslationData";
import { Properties } from "../Properties";
import { CoreService } from "./CoreService";
import { ApiHttpService } from "./ApiHttpService";
import { EventService } from "./EventService";
import { TranslationData } from '../DTOs/TranslationData';
import { Properties } from '../Properties';
import { CoreService } from './CoreService';
import { ApiHttpService } from './ApiHttpService';
import { EventService } from './EventService';
export declare class TranslationService {

@@ -7,0 +7,0 @@ private properties;

@@ -84,7 +84,7 @@ "use strict";

case 0:
this.coreService.checkScope("translations.view");
this.coreService.checkScope('translations.view');
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 6]);
return [4 /*yield*/, this.apiHttpService.postJson("keyTranslations/" + Array.from(languages).join(","), { key: key })];
return [4 /*yield*/, this.apiHttpService.postJson("keyTranslations/" + Array.from(languages).join(','), { key: key })];
case 2:

@@ -97,8 +97,10 @@ data = _b.sent();

if (!(e_1.response.status === 404)) return [3 /*break*/, 5];
if (!(e_1.code === "language_not_found")) return [3 /*break*/, 5];
if (!(e_1.code === 'language_not_found')) return [3 /*break*/, 5];
_a = this.properties;
return [4 /*yield*/, this.coreService.getLanguages()];
case 4:
_a.preferredLanguages = _b.sent();
console.error("Requested language not found, refreshing the page!");
_a.preferredLanguages =
_b.sent();
// eslint-disable-next-line no-console
console.error('Requested language not found, refreshing the page!');
location.reload();

@@ -169,3 +171,3 @@ return [2 /*return*/];

case 0:
this.coreService.checkScope("translations.edit");
this.coreService.checkScope('translations.edit');
return [4 /*yield*/, this.apiHttpService.post('', translationData)];

@@ -175,4 +177,5 @@ case 1:

Object.keys(translationData.translations).forEach(function (lang) {
if (_this.translationsCache.get(lang)) { // if the language is not loaded, then ignore the change
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(translationData.key, ".");
if (_this.translationsCache.get(lang)) {
// if the language is not loaded, then ignore the change
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(translationData.key, '.');
var root = _this.translationsCache.get(lang);

@@ -184,3 +187,3 @@ for (var i = 0; i < path.length; i++) {

}
if (i === (path.length - 1)) {
if (i === path.length - 1) {
root[item] = translationData.translations[lang];

@@ -201,3 +204,4 @@ return;

if (orEmpty === void 0) { orEmpty = false; }
var message = this.getFromCache(key, lang) || this.getFromCache(key, this.properties.config.fallbackLanguage);
var message = this.getFromCache(key, lang) ||
this.getFromCache(key, this.properties.config.fallbackLanguage);
return TranslationService_1.translationByValue(message, key, orEmpty);

@@ -210,3 +214,3 @@ };

case 0:
if (!(this.properties.config.mode === "development")) return [3 /*break*/, 2];
if (!(this.properties.config.mode === 'development')) return [3 /*break*/, 2];
return [4 /*yield*/, this.fetchTranslationsDevelopment(lang)];

@@ -226,3 +230,3 @@ case 1: return [2 /*return*/, _a.sent()];

case 0:
url = "" + (this.properties.config.filesUrlPrefix || "/") + language + ".json";
url = "" + (this.properties.config.filesUrlPrefix || '/') + language + ".json";
_a.label = 1;

@@ -236,3 +240,4 @@ case 1:

//on error set language data as empty object to not break the flow
console.error("Server responend with error status while loading localization data.");
// eslint-disable-next-line no-console
console.error('Server responend with error status while loading localization data.');
this.translationsCache.set(language, {});

@@ -246,3 +251,3 @@ return [2 /*return*/];

case 4:
data = (_a.sent());
data = _a.sent();
this.translationsCache.set(language, data);

@@ -252,2 +257,3 @@ return [3 /*break*/, 6];

e_2 = _a.sent();
// eslint-disable-next-line no-console
console.error("Error parsing json retrieved from " + url + ".");

@@ -259,2 +265,3 @@ this.setEmptyLanguageData(language);

e_3 = _a.sent();
// eslint-disable-next-line no-console
console.error("Error fetching localization data from " + url + ".");

@@ -274,3 +281,3 @@ this.setEmptyLanguageData(language);

case 0:
this.coreService.checkScope("translations.view");
this.coreService.checkScope('translations.view');
_a.label = 1;

@@ -286,3 +293,4 @@ case 1:

e_4 = _a.sent();
console.error("Error while fetching localization data from API.", e_4);
// eslint-disable-next-line no-console
console.error('Error while fetching localization data from API.', e_4);
this.setEmptyLanguageData(language);

@@ -301,3 +309,3 @@ return [2 /*return*/];

if (lang === void 0) { lang = this.properties.currentLanguage; }
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, ".");
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, '.');
var root = this.translationsCache.get(lang);

@@ -331,5 +339,5 @@ //if lang is not downloaded or does not exist at all

if (orEmpty) {
return "";
return '';
}
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, ".");
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, '.');
return path[path.length - 1];

@@ -336,0 +344,0 @@ };

import { CoreService } from './services/CoreService';
import { TolgeeConfig } from './TolgeeConfig';
import { Properties } from './Properties';
import { TranslationParams } from "./types";
import { TranslationParams } from './types';
export declare class Tolgee {

@@ -6,0 +6,0 @@ private readonly container;

@@ -122,3 +122,3 @@ "use strict";

case 0:
if (!(this.properties.config.mode === "development")) return [3 /*break*/, 2];
if (!(this.properties.config.mode === 'development')) return [3 /*break*/, 2];
return [4 /*yield*/, this.loadScopes()];

@@ -125,0 +125,0 @@ case 1:

@@ -1,3 +0,3 @@

import { Mode } from "./types";
import { ModifierKey } from "./index";
import { Mode } from './types';
import { ModifierKey } from './index';
export declare class TolgeeConfig {

@@ -4,0 +4,0 @@ mode?: Mode;

@@ -9,16 +9,16 @@ "use strict";

function TolgeeConfig(config) {
this.apiUrl = "https://app.tolgee.io";
this.apiUrl = 'https://app.tolgee.io';
this.inputPrefix = '%-%tolgee:';
this.inputSuffix = '%-%';
this.defaultLanguage = 'en';
this.filesUrlPrefix = "i18n/";
this.filesUrlPrefix = 'i18n/';
this.tagAttributes = {
'textarea': ['placeholder'],
'input': ['value', 'placeholder'],
'select': ["aria-label"]
textarea: ['placeholder'],
input: ['value', 'placeholder'],
select: ['aria-label'],
};
this.highlightKeys = [index_1.ModifierKey.Alt];
this.passToParent = ["option", "optgroup"];
this.passToParent = ['option', 'optgroup'];
this.restrictedElements = ['script', 'style'];
this.highlightColor = "rgb(224 240 255)";
this.highlightColor = 'rgb(224 240 255)';
//workaround for: https://stackoverflow.com/questions/48725916/typescript-optional-property-with-a-getter

@@ -28,3 +28,3 @@ Object.defineProperty(this, 'targetElement', {

if (this.targetElement !== undefined) {
throw new Error("Target element is already defined!");
throw new Error('Target element is already defined!');
}

@@ -35,4 +35,5 @@ if (targetElement === undefined) {

if (NodeHelper_1.NodeHelper.isElementTargetElement(targetElement)) {
console.error("Target element: ", this._targetElement);
throw new Error("An tolgee instance is inited with provided target element");
// eslint-disable-next-line no-console
console.error('Target element: ', this._targetElement);
throw new Error('An tolgee instance is inited with provided target element');
}

@@ -44,3 +45,3 @@ this._targetElement = targetElement;

return this._targetElement;
}
},
});

@@ -51,6 +52,6 @@ Object.assign(this, config || {});

}
this.mode = this.mode || (this.apiKey ? "development" : "production");
this.mode = this.mode || (this.apiKey ? 'development' : 'production');
this.fallbackLanguage = this.fallbackLanguage || this.defaultLanguage;
if (this.watch === undefined) {
this.watch = this.mode === "development";
this.watch = this.mode === 'development';
}

@@ -57,0 +58,0 @@ }

@@ -27,6 +27,6 @@ "use strict";

};
window.addEventListener("message", receiveMessage, false);
typeof _this._stopListening === "function" && _this._stopListening();
window.addEventListener('message', receiveMessage, false);
typeof _this._stopListening === 'function' && _this._stopListening();
_this._stopListening = function () {
window.removeEventListener("message", receiveMessage, false);
window.removeEventListener('message', receiveMessage, false);
};

@@ -36,3 +36,3 @@ _this.startPopupListening();

this.startPopupListening = function () {
_this.listen("POPUP_TO_LIB", function (data) {
_this.listen('POPUP_TO_LIB', function (data) {
_this.listenersPopup.forEach(function (listener) {

@@ -56,3 +56,4 @@ if (data.type == listener.type) {

catch (e) {
console.warn("Can not send message.", e);
// eslint-disable-next-line no-console
console.warn('Can not send message.', e);
}

@@ -59,0 +60,0 @@ };

@@ -51,3 +51,3 @@ export interface TolgeeTextInputElement extends HTMLElement {

};
export declare type Scope = "translations.edit" | "translations.view" | "keys.edit";
export declare type Scope = 'translations.edit' | 'translations.view' | 'keys.edit';
export declare type Mode = 'development' | 'production';
{
"name": "@tolgee/core",
"version": "1.0.0-alpha.45",
"version": "1.0.0-alpha.46",
"description": "Library providing ability to translate messages directly in context of developed application.",

@@ -65,3 +65,3 @@ "main": "dist/tolgee.umd.js",

},
"gitHead": "3914b7c55c53c1ee75547672fd5afca5d5c5bb5a",
"gitHead": "2663bb665a81bdf53123412848f1fa821eea5f61",
"publishConfig": {

@@ -68,0 +68,0 @@ "access": "public"

@@ -31,2 +31,2 @@ # Tolgee core library

To learn more, check [Hello World example](https://toolkit.tolgee.io/docs/web/get_started/hello_world).
To learn more, check [Hello World example](https://toolkit.tolgee.io/docs/web/get_started/hello_world).

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

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

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

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

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc