@tolgee/core
Advanced tools
Comparing version 1.0.0-alpha.60 to 1.1.0
@@ -1,7 +0,4 @@ | ||
"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'; | ||
export var RESTRICTED_ASCENDANT_ATTRIBUTE = 'data-tolgee-restricted'; | ||
export var TOLGEE_ATTRIBUTE_NAME = '_tolgee'; | ||
export var TOLGEE_TARGET_ATTRIBUTE = '_tolgee-target'; | ||
//# sourceMappingURL=Global.js.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ModifierKey = void 0; | ||
var ModifierKey; | ||
export var ModifierKey; | ||
(function (ModifierKey) { | ||
@@ -10,3 +7,3 @@ ModifierKey[ModifierKey["Alt"] = 0] = "Alt"; | ||
ModifierKey[ModifierKey["Meta"] = 3] = "Meta"; | ||
})(ModifierKey = exports.ModifierKey || (exports.ModifierKey = {})); | ||
})(ModifierKey || (ModifierKey = {})); | ||
//# sourceMappingURL=ModifierKey.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TranslationData = void 0; | ||
var TranslationData = /** @class */ (function () { | ||
@@ -11,3 +8,3 @@ function TranslationData(key, translations) { | ||
}()); | ||
exports.TranslationData = TranslationData; | ||
export { TranslationData }; | ||
//# sourceMappingURL=TranslationData.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -10,2 +9,4 @@ var extendStatics = function (d, b) { | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
@@ -16,4 +17,2 @@ function __() { this.constructor = d; } | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ApiHttpError = void 0; | ||
var ApiHttpError = /** @class */ (function (_super) { | ||
@@ -31,3 +30,3 @@ __extends(ApiHttpError, _super); | ||
}(Error)); | ||
exports.ApiHttpError = ApiHttpError; | ||
export { ApiHttpError }; | ||
//# sourceMappingURL=ApiHttpError.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -49,6 +48,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractHandler = void 0; | ||
var NodeHelper_1 = require("../helpers/NodeHelper"); | ||
var Global_1 = require("../Constants/Global"); | ||
import { NodeHelper } from '../helpers/NodeHelper'; | ||
import { RESTRICTED_ASCENDANT_ATTRIBUTE, TOLGEE_ATTRIBUTE_NAME, } from '../Constants/Global'; | ||
var AbstractHandler = /** @class */ (function () { | ||
@@ -62,7 +59,7 @@ function AbstractHandler(properties, textService, elementRegistrar, translationHighlighter) { | ||
AbstractHandler.initParentElement = function (element) { | ||
if (element[Global_1.TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
element[Global_1.TOLGEE_ATTRIBUTE_NAME] = { | ||
if (element[TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
element[TOLGEE_ATTRIBUTE_NAME] = { | ||
nodes: new Set(), | ||
}; | ||
element.setAttribute(Global_1.TOLGEE_ATTRIBUTE_NAME, ''); | ||
element.setAttribute(TOLGEE_ATTRIBUTE_NAME, ''); | ||
} | ||
@@ -74,5 +71,5 @@ return element; | ||
return nodes.filter(function (n) { | ||
var e = NodeHelper_1.NodeHelper.closestElement(n); | ||
var e = NodeHelper.closestElement(n); | ||
return (restrictedElements.indexOf(e.tagName.toLowerCase()) === -1 && | ||
e.closest("[" + Global_1.RESTRICTED_ASCENDANT_ATTRIBUTE + "=\"true\"]") === null); | ||
e.closest("[" + RESTRICTED_ASCENDANT_ATTRIBUTE + "=\"true\"]") === null); | ||
}); | ||
@@ -93,6 +90,6 @@ }; | ||
textNode = nodes_1_1.value; | ||
if (textNode[Global_1.TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
textNode[Global_1.TOLGEE_ATTRIBUTE_NAME] = {}; | ||
if (textNode[TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
textNode[TOLGEE_ATTRIBUTE_NAME] = {}; | ||
} | ||
tolgeeData = textNode[Global_1.TOLGEE_ATTRIBUTE_NAME]; | ||
tolgeeData = textNode[TOLGEE_ATTRIBUTE_NAME]; | ||
if (!((tolgeeData === null || tolgeeData === void 0 ? void 0 : tolgeeData.locked) !== true)) return [3 /*break*/, 3]; | ||
@@ -132,3 +129,3 @@ this.lockNode(textNode); | ||
AbstractHandler.prototype.translateChildNode = function (node, newValue, keys) { | ||
node[Global_1.TOLGEE_ATTRIBUTE_NAME] = { | ||
node[TOLGEE_ATTRIBUTE_NAME] = { | ||
oldTextContent: node.textContent, | ||
@@ -141,6 +138,6 @@ keys: keys, | ||
AbstractHandler.prototype.lockNode = function (node) { | ||
if (node[Global_1.TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
node[Global_1.TOLGEE_ATTRIBUTE_NAME] = {}; | ||
if (node[TOLGEE_ATTRIBUTE_NAME] === undefined) { | ||
node[TOLGEE_ATTRIBUTE_NAME] = {}; | ||
} | ||
var tolgeeData = node[Global_1.TOLGEE_ATTRIBUTE_NAME]; | ||
var tolgeeData = node[TOLGEE_ATTRIBUTE_NAME]; | ||
if ((tolgeeData === null || tolgeeData === void 0 ? void 0 : tolgeeData.locked) !== true) { | ||
@@ -152,4 +149,4 @@ tolgeeData.locked = true; | ||
AbstractHandler.prototype.unlockNode = function (node) { | ||
if (node[Global_1.TOLGEE_ATTRIBUTE_NAME]) { | ||
node[Global_1.TOLGEE_ATTRIBUTE_NAME].locked = false; | ||
if (node[TOLGEE_ATTRIBUTE_NAME]) { | ||
node[TOLGEE_ATTRIBUTE_NAME].locked = false; | ||
} | ||
@@ -162,3 +159,3 @@ }; | ||
AbstractHandler.prototype.getSuitableParent = function (node) { | ||
var domParent = NodeHelper_1.NodeHelper.getParentElement(node); | ||
var domParent = NodeHelper.getParentElement(node); | ||
if (domParent === undefined) { | ||
@@ -189,3 +186,3 @@ // eslint-disable-next-line no-console | ||
}()); | ||
exports.AbstractHandler = AbstractHandler; | ||
export { AbstractHandler }; | ||
//# sourceMappingURL=AbstractHandler.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -10,2 +9,4 @@ var extendStatics = function (d, b) { | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
@@ -16,11 +17,2 @@ function __() { this.constructor = d; } | ||
})(); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -89,11 +81,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AttributeHandler = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var AbstractHandler_1 = require("./AbstractHandler"); | ||
var Properties_1 = require("../Properties"); | ||
var NodeHelper_1 = require("../helpers/NodeHelper"); | ||
var TextService_1 = require("../services/TextService"); | ||
var ElementRegistrar_1 = require("../services/ElementRegistrar"); | ||
var TranslationHighlighter_1 = require("../highlighter/TranslationHighlighter"); | ||
import { AbstractHandler } from './AbstractHandler'; | ||
import { NodeHelper } from '../helpers/NodeHelper'; | ||
var AttributeHandler = /** @class */ (function (_super) { | ||
@@ -135,3 +120,3 @@ __extends(AttributeHandler, _super); | ||
expression = "descendant-or-self::" + tag + "/@" + attribute + "[contains(., '" + inputPrefix + "') and contains(., '" + inputSuffix + "')]"; | ||
nodes = NodeHelper_1.NodeHelper.evaluate(expression, node); | ||
nodes = NodeHelper.evaluate(expression, node); | ||
return [4 /*yield*/, this.handleNodes(nodes)]; | ||
@@ -174,12 +159,5 @@ case 5: | ||
}; | ||
AttributeHandler = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
TextService_1.TextService, | ||
ElementRegistrar_1.ElementRegistrar, | ||
TranslationHighlighter_1.TranslationHighlighter]) | ||
], AttributeHandler); | ||
return AttributeHandler; | ||
}(AbstractHandler_1.AbstractHandler)); | ||
exports.AttributeHandler = AttributeHandler; | ||
}(AbstractHandler)); | ||
export { AttributeHandler }; | ||
//# sourceMappingURL=AttributeHandler.js.map |
@@ -9,3 +9,3 @@ import { CoreService } from '../services/CoreService'; | ||
private service; | ||
private basicTextHandler; | ||
private textHandler; | ||
private eventService; | ||
@@ -15,5 +15,5 @@ private properties; | ||
private textService; | ||
constructor(service: CoreService, basicTextHandler: TextHandler, eventService: EventService, properties: Properties, attributeHandler: AttributeHandler, textService: TextService); | ||
constructor(service: CoreService, textHandler: TextHandler, eventService: EventService, properties: Properties, attributeHandler: AttributeHandler, textService: TextService); | ||
handleSubtree(target: Element): Promise<void>; | ||
private refresh; | ||
} |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -58,16 +48,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreHandler = void 0; | ||
var NodeHelper_1 = require("../helpers/NodeHelper"); | ||
var CoreService_1 = require("../services/CoreService"); | ||
var TextHandler_1 = require("./TextHandler"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var EventService_1 = require("../services/EventService"); | ||
var Properties_1 = require("../Properties"); | ||
var AttributeHandler_1 = require("./AttributeHandler"); | ||
var TextService_1 = require("../services/TextService"); | ||
import { NodeHelper } from '../helpers/NodeHelper'; | ||
var CoreHandler = /** @class */ (function () { | ||
function CoreHandler(service, basicTextHandler, eventService, properties, attributeHandler, textService) { | ||
function CoreHandler(service, textHandler, eventService, properties, attributeHandler, textService) { | ||
this.service = service; | ||
this.basicTextHandler = basicTextHandler; | ||
this.textHandler = textHandler; | ||
this.eventService = eventService; | ||
@@ -87,3 +68,3 @@ this.properties = properties; | ||
_a.sent(); | ||
return [4 /*yield*/, this.basicTextHandler.handle(target)]; | ||
return [4 /*yield*/, this.textHandler.handle(target)]; | ||
case 2: | ||
@@ -103,3 +84,3 @@ _a.sent(); | ||
case 0: | ||
nodes = NodeHelper_1.NodeHelper.evaluate("//*[@_tolgee]", this.properties.config.targetElement); | ||
nodes = NodeHelper.evaluate("//*[@_tolgee]", this.properties.config.targetElement); | ||
_e.label = 1; | ||
@@ -161,14 +142,5 @@ case 1: | ||
}; | ||
CoreHandler = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [CoreService_1.CoreService, | ||
TextHandler_1.TextHandler, | ||
EventService_1.EventService, | ||
Properties_1.Properties, | ||
AttributeHandler_1.AttributeHandler, | ||
TextService_1.TextService]) | ||
], CoreHandler); | ||
return CoreHandler; | ||
}()); | ||
exports.CoreHandler = CoreHandler; | ||
export { CoreHandler }; | ||
//# sourceMappingURL=CoreHandler.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -10,2 +9,4 @@ var extendStatics = function (d, b) { | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
@@ -16,11 +17,2 @@ function __() { this.constructor = d; } | ||
})(); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -62,11 +54,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextHandler = void 0; | ||
var NodeHelper_1 = require("../helpers/NodeHelper"); | ||
var Properties_1 = require("../Properties"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var TranslationHighlighter_1 = require("../highlighter/TranslationHighlighter"); | ||
var TextService_1 = require("../services/TextService"); | ||
var AbstractHandler_1 = require("./AbstractHandler"); | ||
var ElementRegistrar_1 = require("../services/ElementRegistrar"); | ||
import { NodeHelper } from '../helpers/NodeHelper'; | ||
import { AbstractHandler } from './AbstractHandler'; | ||
var TextHandler = /** @class */ (function (_super) { | ||
@@ -91,3 +76,3 @@ __extends(TextHandler, _super); | ||
xPath = "./descendant-or-self::text()[contains(., '" + inputPrefix + "') and contains(., '" + inputSuffix + "')]"; | ||
nodes = NodeHelper_1.NodeHelper.evaluate(xPath, node); | ||
nodes = NodeHelper.evaluate(xPath, node); | ||
filtered = this.filterRestricted(nodes); | ||
@@ -102,12 +87,5 @@ return [4 /*yield*/, this.handleNodes(filtered)]; | ||
}; | ||
TextHandler = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
TranslationHighlighter_1.TranslationHighlighter, | ||
TextService_1.TextService, | ||
ElementRegistrar_1.ElementRegistrar]) | ||
], TextHandler); | ||
return TextHandler; | ||
}(AbstractHandler_1.AbstractHandler)); | ||
exports.TextHandler = TextHandler; | ||
}(AbstractHandler)); | ||
export { TextHandler }; | ||
//# sourceMappingURL=TextHandler.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=commonTypes.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
@@ -45,9 +44,8 @@ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NodeHelper = void 0; | ||
var Global_1 = require("../Constants/Global"); | ||
import { TOLGEE_TARGET_ATTRIBUTE } from '../Constants/Global'; | ||
var NodeHelper = /** @class */ (function () { | ||
@@ -78,3 +76,3 @@ function NodeHelper() { | ||
} | ||
return Array.from(this.evaluateGenerator.apply(this, __spread(args))); | ||
return Array.from(this.evaluateGenerator.apply(this, __spreadArray([], __read(args)))); | ||
}; | ||
@@ -86,3 +84,3 @@ NodeHelper.evaluateToSingle = function () { | ||
} | ||
var arr = this.evaluate.apply(this, __spread(args)); | ||
var arr = this.evaluate.apply(this, __spreadArray([], __read(args))); | ||
if (arr.length === 1) { | ||
@@ -111,9 +109,9 @@ return arr[0]; | ||
NodeHelper.isElementTargetElement = function (element) { | ||
return element.hasAttribute(Global_1.TOLGEE_TARGET_ATTRIBUTE); | ||
return element.hasAttribute(TOLGEE_TARGET_ATTRIBUTE); | ||
}; | ||
NodeHelper.markElementAsTargetElement = function (element) { | ||
element.setAttribute(Global_1.TOLGEE_TARGET_ATTRIBUTE, ''); | ||
element.setAttribute(TOLGEE_TARGET_ATTRIBUTE, ''); | ||
}; | ||
NodeHelper.unmarkElementAsTargetElement = function (element) { | ||
element.removeAttribute(Global_1.TOLGEE_TARGET_ATTRIBUTE); | ||
element.removeAttribute(TOLGEE_TARGET_ATTRIBUTE); | ||
}; | ||
@@ -134,3 +132,3 @@ NodeHelper.nodeContains = function (descendant, node) { | ||
}()); | ||
exports.NodeHelper = NodeHelper; | ||
export { NodeHelper }; | ||
//# sourceMappingURL=NodeHelper.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextHelper = void 0; | ||
var TextHelper = /** @class */ (function () { | ||
@@ -40,3 +37,3 @@ function TextHelper() { | ||
}()); | ||
exports.TextHelper = TextHelper; | ||
export { TextHelper }; | ||
//# sourceMappingURL=TextHelper.js.map |
@@ -5,3 +5,2 @@ import { ElementWithMeta } from '../types'; | ||
private properties; | ||
constructor(properties: Properties); | ||
private keysDown; | ||
@@ -13,2 +12,3 @@ private mouseOn; | ||
private keysChanged; | ||
constructor(properties: Properties); | ||
handle(element: ElementWithMeta & ElementCSSInlineStyle, onclick: (clickEvent: MouseEvent) => void): void; | ||
@@ -15,0 +15,0 @@ private initEventListeners; |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -22,8 +12,4 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MouseEventHandler = void 0; | ||
var ModifierKey_1 = require("../Constants/ModifierKey"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var Properties_1 = require("../Properties"); | ||
var EventEmitter_1 = require("../services/EventEmitter"); | ||
import { ModifierKey } from '../Constants/ModifierKey'; | ||
import { EventEmitterImpl } from '../services/EventEmitter'; | ||
var MouseEventHandler = /** @class */ (function () { | ||
@@ -34,5 +20,8 @@ function MouseEventHandler(properties) { | ||
this.mouseOn = new Set(); | ||
this.mouseOnChanged = new EventEmitter_1.EventEmitterImpl(); | ||
this.keysChanged = new EventEmitter_1.EventEmitterImpl(); | ||
this.initKeyListener(); | ||
this.mouseOnChanged = new EventEmitterImpl(); | ||
this.keysChanged = new EventEmitterImpl(); | ||
if (typeof window !== 'undefined') { | ||
this.initKeyListener(); | ||
return; | ||
} | ||
} | ||
@@ -128,3 +117,3 @@ MouseEventHandler.prototype.handle = function (element, onclick) { | ||
window.addEventListener('keydown', function (e) { | ||
var modifierKey = ModifierKey_1.ModifierKey[e.key]; | ||
var modifierKey = ModifierKey[e.key]; | ||
if (modifierKey !== undefined) { | ||
@@ -136,3 +125,3 @@ _this.keysDown.add(modifierKey); | ||
window.addEventListener('keyup', function (e) { | ||
_this.keysDown.delete(ModifierKey_1.ModifierKey[e.key]); | ||
_this.keysDown.delete(ModifierKey[e.key]); | ||
_this.keysChanged.emit(_this.areKeysDown()); | ||
@@ -168,9 +157,5 @@ }); | ||
}; | ||
MouseEventHandler = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties]) | ||
], MouseEventHandler); | ||
return MouseEventHandler; | ||
}()); | ||
exports.MouseEventHandler = MouseEventHandler; | ||
export { MouseEventHandler }; | ||
//# sourceMappingURL=MouseEventHandler.js.map |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -63,14 +53,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TranslationHighlighter = void 0; | ||
var CoreService_1 = require("../services/CoreService"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var Properties_1 = require("../Properties"); | ||
var EventService_1 = require("../services/EventService"); | ||
var TranslationService_1 = require("../services/TranslationService"); | ||
var MouseEventHandler_1 = require("./MouseEventHandler"); | ||
var TranslationHighlighter = /** @class */ (function () { | ||
@@ -107,3 +90,2 @@ function TranslationHighlighter(service, properties, eventService, translationService, mouseEventHandler) { | ||
} | ||
TranslationHighlighter_1 = TranslationHighlighter; | ||
TranslationHighlighter.prototype.listen = function (element) { | ||
@@ -124,3 +106,3 @@ var _this = this; | ||
case 0: | ||
keys = TranslationHighlighter_1.getKeyOptions(element); | ||
keys = TranslationHighlighter.getKeyOptions(element); | ||
if (!(keys.size > 1)) return [3 /*break*/, 2]; | ||
@@ -142,3 +124,3 @@ return [4 /*yield*/, this.renderer.getKey({ keys: keys, openEvent: mouseEvent })]; | ||
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 __spreadArray(__spreadArray([], __read(acc)), __read(curr._tolgee.keys.map(function (k) { return k.key; }))); }, []); | ||
return new Set(keys); | ||
@@ -163,14 +145,5 @@ }; | ||
}); | ||
var TranslationHighlighter_1; | ||
TranslationHighlighter = TranslationHighlighter_1 = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [CoreService_1.CoreService, | ||
Properties_1.Properties, | ||
EventService_1.EventService, | ||
TranslationService_1.TranslationService, | ||
MouseEventHandler_1.MouseEventHandler]) | ||
], TranslationHighlighter); | ||
return TranslationHighlighter; | ||
}()); | ||
exports.TranslationHighlighter = TranslationHighlighter; | ||
export { TranslationHighlighter }; | ||
//# sourceMappingURL=TranslationHighlighter.js.map |
@@ -1,3 +0,1 @@ | ||
import 'reflect-metadata'; | ||
import 'regenerator-runtime/runtime'; | ||
import { Tolgee } from './Tolgee'; | ||
@@ -4,0 +2,0 @@ import { TolgeeConfig } from './TolgeeConfig'; |
@@ -1,12 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ModifierKey = exports.TolgeeConfig = exports.Tolgee = void 0; | ||
require("reflect-metadata"); | ||
require("regenerator-runtime/runtime"); | ||
var Tolgee_1 = require("./Tolgee"); | ||
Object.defineProperty(exports, "Tolgee", { enumerable: true, get: function () { return Tolgee_1.Tolgee; } }); | ||
var TolgeeConfig_1 = require("./TolgeeConfig"); | ||
Object.defineProperty(exports, "TolgeeConfig", { enumerable: true, get: function () { return TolgeeConfig_1.TolgeeConfig; } }); | ||
var ModifierKey_1 = require("./Constants/ModifierKey"); | ||
Object.defineProperty(exports, "ModifierKey", { enumerable: true, get: function () { return ModifierKey_1.ModifierKey; } }); | ||
import { Tolgee } from './Tolgee'; | ||
import { TolgeeConfig } from './TolgeeConfig'; | ||
import { ModifierKey } from './Constants/ModifierKey'; | ||
export { Tolgee, TolgeeConfig, ModifierKey }; | ||
//# sourceMappingURL=index.js.map |
@@ -13,5 +13,6 @@ import { CoreHandler } from './handlers/CoreHandler'; | ||
constructor(properties: Properties, coreHandler: CoreHandler, basicTextHandler: TextHandler, attributeHandler: AttributeHandler, nodeRegistrar: ElementRegistrar); | ||
private observer; | ||
private _observer; | ||
private get observer(); | ||
observe(): void; | ||
stopObserving(): void; | ||
} |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -58,13 +48,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Observer = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var CoreHandler_1 = require("./handlers/CoreHandler"); | ||
var Properties_1 = require("./Properties"); | ||
var TextHandler_1 = require("./handlers/TextHandler"); | ||
var AttributeHandler_1 = require("./handlers/AttributeHandler"); | ||
var ElementRegistrar_1 = require("./services/ElementRegistrar"); | ||
var Observer = /** @class */ (function () { | ||
function Observer(properties, coreHandler, basicTextHandler, attributeHandler, nodeRegistrar) { | ||
var _this = this; | ||
this.properties = properties; | ||
@@ -75,53 +56,67 @@ this.coreHandler = coreHandler; | ||
this.nodeRegistrar = nodeRegistrar; | ||
this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () { | ||
var mutationsList_1, mutationsList_1_1, mutation, e_1_1; | ||
var e_1, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 9, 10, 11]); | ||
mutationsList_1 = __values(mutationsList), mutationsList_1_1 = mutationsList_1.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!!mutationsList_1_1.done) return [3 /*break*/, 8]; | ||
mutation = mutationsList_1_1.value; | ||
if (!(mutation.type === 'characterData')) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.basicTextHandler.handle(mutation.target)]; | ||
case 2: | ||
_b.sent(); | ||
return [3 /*break*/, 7]; | ||
case 3: | ||
if (!(mutation.type === 'childList')) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.coreHandler.handleSubtree(mutation.target)]; | ||
case 4: | ||
_b.sent(); | ||
return [3 /*break*/, 7]; | ||
case 5: | ||
if (!(mutation.type === 'attributes')) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, this.attributeHandler.handle(mutation.target)]; | ||
case 6: | ||
_b.sent(); | ||
_b.label = 7; | ||
case 7: | ||
mutationsList_1_1 = mutationsList_1.next(); | ||
return [3 /*break*/, 1]; | ||
case 8: return [3 /*break*/, 11]; | ||
case 9: | ||
e_1_1 = _b.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3 /*break*/, 11]; | ||
case 10: | ||
try { | ||
if (mutationsList_1_1 && !mutationsList_1_1.done && (_a = mutationsList_1.return)) _a.call(mutationsList_1); | ||
this._observer = undefined; | ||
} | ||
Object.defineProperty(Observer.prototype, "observer", { | ||
get: function () { | ||
var _this = this; | ||
if (!this._observer && typeof window !== 'undefined') { | ||
this._observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () { | ||
var mutationsList_1, mutationsList_1_1, mutation, e_1_1; | ||
var e_1, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 9, 10, 11]); | ||
mutationsList_1 = __values(mutationsList), mutationsList_1_1 = mutationsList_1.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!!mutationsList_1_1.done) return [3 /*break*/, 8]; | ||
mutation = mutationsList_1_1.value; | ||
if (!(mutation.type === 'characterData')) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.basicTextHandler.handle(mutation.target)]; | ||
case 2: | ||
_b.sent(); | ||
return [3 /*break*/, 7]; | ||
case 3: | ||
if (!(mutation.type === 'childList')) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.coreHandler.handleSubtree(mutation.target)]; | ||
case 4: | ||
_b.sent(); | ||
return [3 /*break*/, 7]; | ||
case 5: | ||
if (!(mutation.type === 'attributes')) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, this.attributeHandler.handle(mutation.target)]; | ||
case 6: | ||
_b.sent(); | ||
_b.label = 7; | ||
case 7: | ||
mutationsList_1_1 = mutationsList_1.next(); | ||
return [3 /*break*/, 1]; | ||
case 8: return [3 /*break*/, 11]; | ||
case 9: | ||
e_1_1 = _b.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3 /*break*/, 11]; | ||
case 10: | ||
try { | ||
if (mutationsList_1_1 && !mutationsList_1_1.done && (_a = mutationsList_1.return)) _a.call(mutationsList_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
return [7 /*endfinally*/]; | ||
case 11: | ||
this.nodeRegistrar.refreshAll(); | ||
return [2 /*return*/]; | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
return [7 /*endfinally*/]; | ||
case 11: | ||
this.nodeRegistrar.refreshAll(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
} | ||
}); | ||
}); }); | ||
} | ||
return this._observer; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Observer.prototype.observe = function () { | ||
if (!this.observer) { | ||
return; | ||
} | ||
this.observer.observe(this.properties.config.targetElement, { | ||
@@ -135,15 +130,10 @@ attributes: true, | ||
Observer.prototype.stopObserving = function () { | ||
if (!this.observer) { | ||
return; | ||
} | ||
this.observer.disconnect(); | ||
}; | ||
Observer = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
CoreHandler_1.CoreHandler, | ||
TextHandler_1.TextHandler, | ||
AttributeHandler_1.AttributeHandler, | ||
ElementRegistrar_1.ElementRegistrar]) | ||
], Observer); | ||
return Observer; | ||
}()); | ||
exports.Observer = Observer; | ||
export { Observer }; | ||
//# sourceMappingURL=Observer.js.map |
@@ -6,7 +6,8 @@ import { TolgeeConfig } from './TolgeeConfig'; | ||
scopes?: Scope[]; | ||
_currentLanguage?: string; | ||
get currentLanguage(): string; | ||
set currentLanguage(language: string); | ||
get preferredLanguages(): Set<string>; | ||
set preferredLanguages(languages: Set<string>); | ||
get preferredLanguages(): Set<string>; | ||
set currentLanguage(language: string); | ||
get currentLanguage(): string; | ||
private getLanguageByNavigator; | ||
} |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Properties = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY = '__tolgee_preferredLanguages'; | ||
@@ -16,21 +6,20 @@ var CURRENT_LANGUAGE_LOCAL_STORAGE_KEY = '__tolgee_currentLanguage'; | ||
} | ||
Object.defineProperty(Properties.prototype, "preferredLanguages", { | ||
get: function () { | ||
return new Set(JSON.parse(localStorage.getItem(PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY))); | ||
}, | ||
set: function (languages) { | ||
localStorage.setItem(PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY, JSON.stringify(Array.from(languages))); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Properties.prototype, "currentLanguage", { | ||
get: function () { | ||
var result = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY); | ||
if (this.config.availableLanguages) { | ||
var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(result) > -1; | ||
if (!isSavedLanguageAvailable) { | ||
result = undefined; | ||
var result; | ||
if (this.config.forceLanguage) { | ||
return this.config.forceLanguage; | ||
} | ||
if (typeof localStorage !== 'undefined') { | ||
result = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY); | ||
if (this.config.availableLanguages) { | ||
var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(result) > -1; | ||
if (!isSavedLanguageAvailable) { | ||
result = undefined; | ||
} | ||
} | ||
} | ||
else { | ||
result = this._currentLanguage; | ||
} | ||
if (!result) { | ||
@@ -43,2 +32,6 @@ result = this.getLanguageByNavigator(); | ||
set: function (language) { | ||
if (typeof localStorage == 'undefined') { | ||
this._currentLanguage = language; | ||
return; | ||
} | ||
localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language); | ||
@@ -49,4 +42,14 @@ }, | ||
}); | ||
Object.defineProperty(Properties.prototype, "preferredLanguages", { | ||
get: function () { | ||
return new Set(JSON.parse(localStorage.getItem(PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY))); | ||
}, | ||
set: function (languages) { | ||
localStorage.setItem(PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY, JSON.stringify(Array.from(languages))); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Properties.prototype.getLanguageByNavigator = function () { | ||
if (window && this.config.availableLanguages) { | ||
if (typeof window !== 'undefined' && this.config.availableLanguages) { | ||
var preferred_1 = window.navigator.language; | ||
@@ -66,8 +69,5 @@ var exactMatch = this.config.availableLanguages.find(function (l) { return l === preferred_1; }); | ||
}; | ||
Properties = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped) | ||
], Properties); | ||
return Properties; | ||
}()); | ||
exports.Properties = Properties; | ||
export { Properties }; | ||
//# sourceMappingURL=Properties.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -13,11 +12,2 @@ __assign = Object.assign || function(t) { | ||
}; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -75,11 +65,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ApiHttpService = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var Properties_1 = require("../Properties"); | ||
var ApiHttpError_1 = require("../Errors/ApiHttpError"); | ||
import { ApiHttpError } from '../Errors/ApiHttpError'; | ||
var ApiHttpService = /** @class */ (function () { | ||
@@ -89,3 +76,2 @@ function ApiHttpService(properties) { | ||
} | ||
ApiHttpService_1 = ApiHttpService; | ||
ApiHttpService.prototype.fetch = function () { | ||
@@ -102,8 +88,8 @@ var args = []; | ||
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); })]; | ||
return [4 /*yield*/, fetch(__assign(__assign({}, args[0]), { url: this.getUrl(args[0].url) })).then(function (r) { return ApiHttpService.handleErrors(r); })]; | ||
case 1: return [2 /*return*/, _b.sent()]; | ||
case 2: | ||
_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, __spreadArray([this.getUrl(url)], __read(rest))).then(function (r) { | ||
return ApiHttpService.handleErrors(r); | ||
})]; | ||
@@ -123,3 +109,3 @@ case 3: return [2 /*return*/, _b.sent()]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spread(args)).then(function (res) { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spreadArray([], __read(args))).then(function (res) { | ||
return res.json(); | ||
@@ -141,5 +127,5 @@ })]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spread([url, __assign({ body: JSON.stringify(body), method: 'POST', headers: { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spreadArray([url, __assign({ body: JSON.stringify(body), method: 'POST', headers: { | ||
'Content-Type': 'application/json', | ||
} }, init)], rest))]; | ||
} }, init)], __read(rest)))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -159,3 +145,3 @@ } | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.post.apply(this, __spread([url, body, init], rest)).then(function (res) { return res.json(); })]; | ||
case 0: return [4 /*yield*/, this.post.apply(this, __spreadArray([url, body, init], __read(rest))).then(function (res) { return res.json(); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -173,3 +159,3 @@ } | ||
if (!(response.status >= 400)) return [3 /*break*/, 5]; | ||
error = new ApiHttpError_1.ApiHttpError(response); | ||
error = new ApiHttpError(response); | ||
_a.label = 1; | ||
@@ -197,10 +183,5 @@ case 1: | ||
}; | ||
var ApiHttpService_1; | ||
ApiHttpService = ApiHttpService_1 = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties]) | ||
], ApiHttpService); | ||
return ApiHttpService; | ||
}()); | ||
exports.ApiHttpService = ApiHttpService; | ||
export { ApiHttpService }; | ||
//# sourceMappingURL=ApiHttpService.js.map |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -47,7 +37,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreService = void 0; | ||
var Properties_1 = require("../Properties"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var ApiHttpService_1 = require("./ApiHttpService"); | ||
var CoreService = /** @class */ (function () { | ||
@@ -109,10 +94,5 @@ function CoreService(properties, apiHttpService) { | ||
}; | ||
CoreService = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
ApiHttpService_1.ApiHttpService]) | ||
], CoreService); | ||
return CoreService; | ||
}()); | ||
exports.CoreService = CoreService; | ||
export { CoreService }; | ||
//# sourceMappingURL=CoreService.js.map |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
@@ -49,9 +39,4 @@ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ElementRegistrar = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var Properties_1 = require("../Properties"); | ||
var Global_1 = require("../Constants/Global"); | ||
var TranslationHighlighter_1 = require("../highlighter/TranslationHighlighter"); | ||
var NodeHelper_1 = require("../helpers/NodeHelper"); | ||
import { TOLGEE_ATTRIBUTE_NAME } from '../Constants/Global'; | ||
import { NodeHelper } from '../helpers/NodeHelper'; | ||
var ElementRegistrar = /** @class */ (function () { | ||
@@ -119,3 +104,3 @@ function ElementRegistrar(properties, translationHighlighter) { | ||
} | ||
element.removeAttribute(Global_1.TOLGEE_ATTRIBUTE_NAME); | ||
element.removeAttribute(TOLGEE_ATTRIBUTE_NAME); | ||
delete element._tolgee; | ||
@@ -136,3 +121,3 @@ this.registeredElements.delete(element); | ||
node = _b.value; | ||
if (!NodeHelper_1.NodeHelper.nodeContains(this.properties.config.targetElement, node)) return [3 /*break*/, 3]; | ||
if (!NodeHelper.nodeContains(this.properties.config.targetElement, node)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, node]; | ||
@@ -163,10 +148,5 @@ case 2: | ||
}; | ||
ElementRegistrar = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
TranslationHighlighter_1.TranslationHighlighter]) | ||
], ElementRegistrar); | ||
return ElementRegistrar; | ||
}()); | ||
exports.ElementRegistrar = ElementRegistrar; | ||
export { ElementRegistrar }; | ||
//# sourceMappingURL=ElementRegistrar.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -13,5 +12,3 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EventEmitterImpl = void 0; | ||
var Subscription_1 = require("./Subscription"); | ||
import { Subscription } from './Subscription'; | ||
var EventEmitterImpl = /** @class */ (function () { | ||
@@ -58,3 +55,3 @@ function EventEmitterImpl() { | ||
var newId = this.idCounter++; | ||
var subscription = new Subscription_1.Subscription(function () { return _this.unsubscribe(newId); }); | ||
var subscription = new Subscription(function () { return _this.unsubscribe(newId); }); | ||
this.subscriptions.set(newId, callback); | ||
@@ -72,3 +69,3 @@ return subscription; | ||
}()); | ||
exports.EventEmitterImpl = EventEmitterImpl; | ||
export { EventEmitterImpl }; | ||
//# sourceMappingURL=EventEmitter.js.map |
@@ -1,24 +0,11 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EventService = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var EventEmitter_1 = require("./EventEmitter"); | ||
import { EventEmitterImpl } from './EventEmitter'; | ||
var EventService = /** @class */ (function () { | ||
function EventService() { | ||
this.TRANSLATION_CHANGED = new EventEmitter_1.EventEmitterImpl(); | ||
this.LANGUAGE_CHANGED = new EventEmitter_1.EventEmitterImpl(); | ||
this.LANGUAGE_LOADED = new EventEmitter_1.EventEmitterImpl(); | ||
this.TRANSLATION_CHANGED = new EventEmitterImpl(); | ||
this.LANGUAGE_CHANGED = new EventEmitterImpl(); | ||
this.LANGUAGE_LOADED = new EventEmitterImpl(); | ||
} | ||
EventService = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped) | ||
], EventService); | ||
return EventService; | ||
}()); | ||
exports.EventService = EventService; | ||
export { EventService }; | ||
//# sourceMappingURL=EventService.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Subscription = void 0; | ||
var Subscription = /** @class */ (function () { | ||
@@ -13,3 +10,3 @@ function Subscription(onUnsubscribe) { | ||
}()); | ||
exports.Subscription = Subscription; | ||
export { Subscription }; | ||
//# sourceMappingURL=Subscription.js.map |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -63,9 +53,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextService = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var TranslationService_1 = require("./TranslationService"); | ||
var Properties_1 = require("../Properties"); | ||
var TextHelper_1 = require("../helpers/TextHelper"); | ||
var intl_messageformat_1 = require("intl-messageformat"); | ||
import { TextHelper } from '../helpers/TextHelper'; | ||
import IntlMessageFormat from 'intl-messageformat'; | ||
var TextService = /** @class */ (function () { | ||
@@ -78,3 +63,3 @@ function TextService(properties, translationService) { | ||
try { | ||
return new intl_messageformat_1.default(translation, _this.properties.currentLanguage).format(params); | ||
return new IntlMessageFormat(translation, _this.properties.currentLanguage).format(params); | ||
} | ||
@@ -106,3 +91,2 @@ catch (e) { | ||
} | ||
TextService_1 = TextService; | ||
TextService.prototype.translate = function (key, params, lang, orEmpty) { | ||
@@ -144,3 +128,3 @@ if (lang === void 0) { lang = this.properties.currentLanguage; } | ||
start = index + fullMatch.length; | ||
if (pre === '\\' && !TextHelper_1.TextHelper.isCharEscaped(index, text)) { | ||
if (pre === '\\' && !TextHelper.isCharEscaped(index, text)) { | ||
result += wrapped; | ||
@@ -158,3 +142,3 @@ return [3 /*break*/, 1]; | ||
result += text.substring(start); | ||
withoutEscapes = TextHelper_1.TextHelper.removeEscapes(result); | ||
withoutEscapes = TextHelper.removeEscapes(result); | ||
if (matched) { | ||
@@ -186,3 +170,3 @@ return [2 /*return*/, { text: withoutEscapes, keys: keysAndParams }]; | ||
case 0: | ||
_a = TextService_1.parseUnwrapped(text), key = _a.key, params = _a.params; | ||
_a = TextService.parseUnwrapped(text), key = _a.key, params = _a.params; | ||
return [4 /*yield*/, this.translate(key, params, undefined, false)]; | ||
@@ -199,3 +183,3 @@ case 1: | ||
var result = { | ||
key: TextHelper_1.TextHelper.removeEscapes(strings.shift()), | ||
key: TextHelper.removeEscapes(strings.shift()), | ||
params: {}, | ||
@@ -218,11 +202,5 @@ }; | ||
}); | ||
var TextService_1; | ||
TextService = TextService_1 = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
TranslationService_1.TranslationService]) | ||
], TextService); | ||
return TextService; | ||
}()); | ||
exports.TextService = TextService; | ||
export { TextService }; | ||
//# sourceMappingURL=TextService.js.map |
@@ -14,2 +14,4 @@ import { TranslationData } from '../DTOs/TranslationData'; | ||
constructor(properties: Properties, coreService: CoreService, apiHttpService: ApiHttpService, eventService: EventService); | ||
private static translationByValue; | ||
initStatic(): void; | ||
loadTranslations(lang?: string): Promise<void>; | ||
@@ -25,3 +27,2 @@ getTranslation(key: string, lang?: string, orEmpty?: boolean): Promise<string>; | ||
private getFromCache; | ||
private static translationByValue; | ||
} |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -47,2 +37,18 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -59,12 +65,5 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TranslationService = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var TranslationData_1 = require("../DTOs/TranslationData"); | ||
var Properties_1 = require("../Properties"); | ||
var CoreService_1 = require("./CoreService"); | ||
var ApiHttpService_1 = require("./ApiHttpService"); | ||
var TextHelper_1 = require("../helpers/TextHelper"); | ||
var ApiHttpError_1 = require("../Errors/ApiHttpError"); | ||
var EventService_1 = require("./EventService"); | ||
import { TranslationData } from '../DTOs/TranslationData'; | ||
import { TextHelper } from '../helpers/TextHelper'; | ||
import { ApiHttpError } from '../Errors/ApiHttpError'; | ||
var TranslationService = /** @class */ (function () { | ||
@@ -93,6 +92,6 @@ function TranslationService(properties, coreService, apiHttpService, eventService) { | ||
data = _b.sent(); | ||
return [2 /*return*/, new TranslationData_1.TranslationData(key, data)]; | ||
return [2 /*return*/, new TranslationData(key, data)]; | ||
case 3: | ||
e_1 = _b.sent(); | ||
if (!(e_1 instanceof ApiHttpError_1.ApiHttpError)) return [3 /*break*/, 5]; | ||
if (!(e_1 instanceof ApiHttpError)) return [3 /*break*/, 5]; | ||
if (!(e_1.response.status === 404)) return [3 /*break*/, 5]; | ||
@@ -116,3 +115,26 @@ if (!(e_1.code === 'language_not_found')) return [3 /*break*/, 5]; | ||
} | ||
TranslationService_1 = TranslationService; | ||
TranslationService.translationByValue = function (message, key, orEmpty) { | ||
if (message) { | ||
return message; | ||
} | ||
if (orEmpty) { | ||
return ''; | ||
} | ||
var path = TextHelper.splitOnNonEscapedDelimiter(key, '.'); | ||
return path[path.length - 1]; | ||
}; | ||
TranslationService.prototype.initStatic = function () { | ||
var _this = this; | ||
var _a; | ||
if (this.properties.config.mode === 'production' && | ||
typeof ((_a = this.properties.config) === null || _a === void 0 ? void 0 : _a.staticData) === 'object') { | ||
Object.entries(this.properties.config.staticData).forEach(function (_a) { | ||
var _b = __read(_a, 2), language = _b[0], data = _b[1]; | ||
//if not provider or promise then it is raw data | ||
if (typeof data !== 'function') { | ||
_this.translationsCache.set(language, data); | ||
} | ||
}); | ||
} | ||
}; | ||
TranslationService.prototype.loadTranslations = function (lang) { | ||
@@ -162,3 +184,3 @@ if (lang === void 0) { lang = this.properties.currentLanguage; } | ||
_a.label = 3; | ||
case 3: return [2 /*return*/, TranslationService_1.translationByValue(message, key, orEmpty)]; | ||
case 3: return [2 /*return*/, TranslationService.translationByValue(message, key, orEmpty)]; | ||
} | ||
@@ -181,3 +203,3 @@ }); | ||
// if the language is not loaded, then ignore the change | ||
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(translationData.key, '.'); | ||
var path = TextHelper.splitOnNonEscapedDelimiter(translationData.key, '.'); | ||
var root = _this.translationsCache.get(lang); | ||
@@ -207,3 +229,3 @@ for (var i = 0; i < path.length; i++) { | ||
this.getFromCache(key, this.properties.config.fallbackLanguage); | ||
return TranslationService_1.translationByValue(message, key, orEmpty); | ||
return TranslationService.translationByValue(message, key, orEmpty); | ||
}; | ||
@@ -225,43 +247,58 @@ TranslationService.prototype.fetchTranslations = function (lang) { | ||
TranslationService.prototype.fetchTranslationsProduction = function (language) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, result, data, e_2, e_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var langStaticData, data, url, result, data, e_2, e_3; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
langStaticData = (_b = (_a = this.properties.config) === null || _a === void 0 ? void 0 : _a.staticData) === null || _b === void 0 ? void 0 : _b[language]; | ||
if (!(typeof langStaticData === 'function')) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, langStaticData()]; | ||
case 1: | ||
data = _c.sent(); | ||
this.translationsCache.set(language, data); | ||
return [2 /*return*/]; | ||
case 2: | ||
if (langStaticData !== undefined) { | ||
this.translationsCache.set(language, langStaticData); | ||
return [2 /*return*/]; | ||
} | ||
_c.label = 3; | ||
case 3: | ||
url = "" + (this.properties.config.filesUrlPrefix || '/') + language + ".json"; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 7, , 8]); | ||
_c.label = 4; | ||
case 4: | ||
_c.trys.push([4, 10, , 11]); | ||
return [4 /*yield*/, fetch(url)]; | ||
case 2: | ||
result = _a.sent(); | ||
case 5: | ||
result = _c.sent(); | ||
if (result.status >= 400) { | ||
//on error set language data as empty object to not break the flow | ||
// eslint-disable-next-line no-console | ||
console.error('Server responend with error status while loading localization data.'); | ||
console.error('Server responded with error status while loading localization data.'); | ||
this.translationsCache.set(language, {}); | ||
return [2 /*return*/]; | ||
} | ||
_a.label = 3; | ||
case 3: | ||
_a.trys.push([3, 5, , 6]); | ||
_c.label = 6; | ||
case 6: | ||
_c.trys.push([6, 8, , 9]); | ||
return [4 /*yield*/, result.json()]; | ||
case 4: | ||
data = _a.sent(); | ||
case 7: | ||
data = _c.sent(); | ||
this.translationsCache.set(language, data); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
e_2 = _a.sent(); | ||
return [3 /*break*/, 9]; | ||
case 8: | ||
e_2 = _c.sent(); | ||
// eslint-disable-next-line no-console | ||
console.error("Error parsing json retrieved from " + url + "."); | ||
this.setEmptyLanguageData(language); | ||
return [3 /*break*/, 6]; | ||
case 6: return [3 /*break*/, 8]; | ||
case 7: | ||
e_3 = _a.sent(); | ||
return [3 /*break*/, 9]; | ||
case 9: return [3 /*break*/, 11]; | ||
case 10: | ||
e_3 = _c.sent(); | ||
// eslint-disable-next-line no-console | ||
console.error("Error fetching localization data from " + url + "."); | ||
this.setEmptyLanguageData(language); | ||
return [3 /*break*/, 8]; | ||
case 8: return [2 /*return*/]; | ||
return [3 /*break*/, 11]; | ||
case 11: return [2 /*return*/]; | ||
} | ||
@@ -303,3 +340,3 @@ }); | ||
if (lang === void 0) { lang = this.properties.currentLanguage; } | ||
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, '.'); | ||
var path = TextHelper.splitOnNonEscapedDelimiter(key, '.'); | ||
var root = this.translationsCache.get(lang); | ||
@@ -328,23 +365,5 @@ //if lang is not downloaded or does not exist at all | ||
}; | ||
TranslationService.translationByValue = function (message, key, orEmpty) { | ||
if (message) { | ||
return message; | ||
} | ||
if (orEmpty) { | ||
return ''; | ||
} | ||
var path = TextHelper_1.TextHelper.splitOnNonEscapedDelimiter(key, '.'); | ||
return path[path.length - 1]; | ||
}; | ||
var TranslationService_1; | ||
TranslationService = TranslationService_1 = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped), | ||
__metadata("design:paramtypes", [Properties_1.Properties, | ||
CoreService_1.CoreService, | ||
ApiHttpService_1.ApiHttpService, | ||
EventService_1.EventService]) | ||
], TranslationService); | ||
return TranslationService; | ||
}()); | ||
exports.TranslationService = TranslationService; | ||
export { TranslationService }; | ||
//# sourceMappingURL=TranslationService.js.map |
@@ -1,17 +0,12 @@ | ||
import { CoreService } from './services/CoreService'; | ||
import { TolgeeConfig } from './TolgeeConfig'; | ||
import { Properties } from './Properties'; | ||
import { TranslationParams } from './types'; | ||
export declare class Tolgee { | ||
private readonly container; | ||
properties: Properties; | ||
private eventService; | ||
private observer; | ||
private translationService; | ||
private textService; | ||
private coreHandler; | ||
private elementRegistrar; | ||
export: any; | ||
default: any; | ||
Tolgee: any; | ||
private dependencyStore; | ||
constructor(config: TolgeeConfig); | ||
private _coreService; | ||
get coreService(): CoreService; | ||
get properties(): import("./Properties").Properties; | ||
get translationService(): import("./services/TranslationService").TranslationService; | ||
get coreService(): import("./services/CoreService").CoreService; | ||
get lang(): string; | ||
@@ -22,2 +17,9 @@ set lang(value: string); | ||
get onLangLoaded(): import("./services/EventEmitter").EventEmitter<string>; | ||
/** | ||
* True if loading is needed to wait for Tolgee init. | ||
* When translation data are provided statically (using import | ||
* as staticData config property) then there is no need for translation | ||
* fetching so initial loading is not needed at all. | ||
*/ | ||
get initialLoading(): boolean; | ||
run(): Promise<void>; | ||
@@ -24,0 +26,0 @@ refresh(): Promise<void>; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,27 +37,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Tolgee = void 0; | ||
var CoreService_1 = require("./services/CoreService"); | ||
var TolgeeConfig_1 = require("./TolgeeConfig"); | ||
var Properties_1 = require("./Properties"); | ||
var tsyringe_1 = require("tsyringe"); | ||
var EventService_1 = require("./services/EventService"); | ||
var Observer_1 = require("./Observer"); | ||
var TranslationService_1 = require("./services/TranslationService"); | ||
var TextService_1 = require("./services/TextService"); | ||
var CoreHandler_1 = require("./handlers/CoreHandler"); | ||
var ElementRegistrar_1 = require("./services/ElementRegistrar"); | ||
var NodeHelper_1 = require("./helpers/NodeHelper"); | ||
import { TolgeeConfig } from './TolgeeConfig'; | ||
import { NodeHelper } from './helpers/NodeHelper'; | ||
import { DependencyStore } from './services/DependencyStore'; | ||
var Tolgee = /** @class */ (function () { | ||
function Tolgee(config) { | ||
var _this = this; | ||
this.container = tsyringe_1.container.createChildContainer(); | ||
this.properties = this.container.resolve(Properties_1.Properties); | ||
this.eventService = this.container.resolve(EventService_1.EventService); | ||
this.observer = this.container.resolve(Observer_1.Observer); | ||
this.translationService = this.container.resolve(TranslationService_1.TranslationService); | ||
this.textService = this.container.resolve(TextService_1.TextService); | ||
this.coreHandler = this.container.resolve(CoreHandler_1.CoreHandler); | ||
this.elementRegistrar = this.container.resolve(ElementRegistrar_1.ElementRegistrar); | ||
this._coreService = this.container.resolve(CoreService_1.CoreService); | ||
this.translate = function (key, params, noWrap) { | ||
@@ -78,4 +58,4 @@ if (params === void 0) { params = {}; } | ||
_a.sent(); | ||
return [2 /*return*/, this.textService.wrap(key, params)]; | ||
case 3: return [2 /*return*/, this.textService.translate(key, params)]; | ||
return [2 /*return*/, this.dependencyStore.textService.wrap(key, params)]; | ||
case 3: return [2 /*return*/, this.dependencyStore.textService.translate(key, params)]; | ||
} | ||
@@ -89,17 +69,30 @@ }); | ||
if (_this.properties.config.mode === 'development' && !noWrap) { | ||
return _this.textService.wrap(key, params); | ||
return _this.dependencyStore.textService.wrap(key, params); | ||
} | ||
return _this.textService.instant(key, params, undefined, orEmpty); | ||
return _this.dependencyStore.textService.instant(key, params, undefined, orEmpty); | ||
}; | ||
this.stop = function () { | ||
_this.observer.stopObserving(); | ||
_this.elementRegistrar.cleanAll(); | ||
NodeHelper_1.NodeHelper.unmarkElementAsTargetElement(_this.properties.config.targetElement); | ||
_this.dependencyStore.observer.stopObserving(); | ||
_this.dependencyStore.elementRegistrar.cleanAll(); | ||
NodeHelper.unmarkElementAsTargetElement(_this.properties.config.targetElement); | ||
}; | ||
this.container = tsyringe_1.container.createChildContainer(); | ||
this.properties.config = new TolgeeConfig_1.TolgeeConfig(config); | ||
this.dependencyStore = new DependencyStore(new TolgeeConfig(config)); | ||
} | ||
Object.defineProperty(Tolgee.prototype, "properties", { | ||
get: function () { | ||
return this.dependencyStore.properties; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Tolgee.prototype, "translationService", { | ||
get: function () { | ||
return this.dependencyStore.translationService; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Tolgee.prototype, "coreService", { | ||
get: function () { | ||
return this._coreService; | ||
return this.dependencyStore.coreService; | ||
}, | ||
@@ -115,3 +108,4 @@ enumerable: false, | ||
this.properties.currentLanguage = value; | ||
this.eventService.LANGUAGE_CHANGED.emit(value); | ||
this.dependencyStore.eventService | ||
.LANGUAGE_CHANGED.emit(value); | ||
}, | ||
@@ -130,3 +124,3 @@ enumerable: false, | ||
get: function () { | ||
return this.eventService.LANGUAGE_CHANGED; | ||
return this.dependencyStore.eventService.LANGUAGE_CHANGED; | ||
}, | ||
@@ -138,3 +132,3 @@ enumerable: false, | ||
get: function () { | ||
return this.eventService.LANGUAGE_LOADED; | ||
return this.dependencyStore.eventService.LANGUAGE_LOADED; | ||
}, | ||
@@ -144,2 +138,24 @@ enumerable: false, | ||
}); | ||
Object.defineProperty(Tolgee.prototype, "initialLoading", { | ||
/** | ||
* True if loading is needed to wait for Tolgee init. | ||
* When translation data are provided statically (using import | ||
* as staticData config property) then there is no need for translation | ||
* fetching so initial loading is not needed at all. | ||
*/ | ||
get: function () { | ||
var _a, _b; | ||
var currentLang = this.properties.currentLanguage; | ||
var fallbackLang = this.properties.config.fallbackLanguage; | ||
var fallbackPreloading = this.properties.config.preloadFallback; | ||
var isStaticDataProvided = function (data) { | ||
return data !== undefined && typeof data !== 'function'; | ||
}; | ||
return (!isStaticDataProvided((_a = this.properties.config.staticData) === null || _a === void 0 ? void 0 : _a[currentLang]) || | ||
(!!fallbackPreloading && | ||
!isStaticDataProvided((_b = this.properties.config.staticData) === null || _b === void 0 ? void 0 : _b[fallbackLang]))); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Tolgee.prototype.run = function () { | ||
@@ -167,3 +183,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
if (this.properties.config.watch) { | ||
this.observer.observe(); | ||
this.dependencyStore.observer.observe(); | ||
} | ||
@@ -178,3 +194,3 @@ return [2 /*return*/]; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.coreHandler.handleSubtree(this.properties.config.targetElement)]; | ||
return [2 /*return*/, this.dependencyStore.coreHandler.handleSubtree(this.properties.config.targetElement)]; | ||
}); | ||
@@ -191,5 +207,6 @@ }); | ||
_a = this.properties; | ||
return [4 /*yield*/, this.coreService.getScopes()]; | ||
return [4 /*yield*/, this.dependencyStore.coreService.getScopes()]; | ||
case 1: | ||
_a.scopes = _b.sent(); | ||
_a.scopes = | ||
_b.sent(); | ||
_b.label = 2; | ||
@@ -203,4 +220,4 @@ case 2: return [2 /*return*/]; | ||
}()); | ||
exports.Tolgee = Tolgee; | ||
exports.default = Tolgee; | ||
export { Tolgee }; | ||
export default Tolgee; | ||
//# sourceMappingURL=Tolgee.js.map |
@@ -1,3 +0,3 @@ | ||
import { Mode } from './types'; | ||
import { ModifierKey } from './index'; | ||
import { Mode, Translations } from './types'; | ||
import { ModifierKey } from './Constants/ModifierKey'; | ||
export declare class TolgeeConfig { | ||
@@ -9,2 +9,3 @@ mode?: Mode; | ||
inputSuffix?: string; | ||
forceLanguage?: string; | ||
defaultLanguage?: string; | ||
@@ -24,2 +25,6 @@ availableLanguages?: string[]; | ||
highlightColor?: string; | ||
/** localization data to use in production mode */ | ||
staticData?: { | ||
[key: string]: Translations | (() => Promise<Translations>); | ||
}; | ||
/** | ||
@@ -26,0 +31,0 @@ * When true, fallback language will be preloaded on Tolgee.run |
@@ -1,7 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TolgeeConfig = void 0; | ||
var index_1 = require("./index"); | ||
var NodeHelper_1 = require("./helpers/NodeHelper"); | ||
var DEFAULT_TARGET_ELEMENT_SUPPLIER = function () { return document.body; }; | ||
import { NodeHelper } from './helpers/NodeHelper'; | ||
import { ModifierKey } from './Constants/ModifierKey'; | ||
var DEFAULT_TARGET_ELEMENT_SUPPLIER = function () { | ||
if (typeof document !== 'undefined') { | ||
return document.body; | ||
} | ||
}; | ||
var TolgeeConfig = /** @class */ (function () { | ||
@@ -19,3 +20,3 @@ function TolgeeConfig(config) { | ||
}; | ||
this.highlightKeys = [index_1.ModifierKey.Alt]; | ||
this.highlightKeys = [ModifierKey.Alt]; | ||
this.passToParent = ['option', 'optgroup']; | ||
@@ -37,3 +38,3 @@ this.restrictedElements = ['script', 'style']; | ||
} | ||
if (NodeHelper_1.NodeHelper.isElementTargetElement(targetElement)) { | ||
if (NodeHelper.isElementTargetElement(targetElement)) { | ||
// eslint-disable-next-line no-console | ||
@@ -44,3 +45,3 @@ console.error('Target element: ', this._targetElement); | ||
this._targetElement = targetElement; | ||
NodeHelper_1.NodeHelper.markElementAsTargetElement(this._targetElement); | ||
NodeHelper.markElementAsTargetElement(this._targetElement); | ||
}, | ||
@@ -63,3 +64,3 @@ get: function () { | ||
}()); | ||
exports.TolgeeConfig = TolgeeConfig; | ||
export { TolgeeConfig }; | ||
//# sourceMappingURL=TolgeeConfig.js.map |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Messages = void 0; | ||
var tsyringe_1 = require("tsyringe"); | ||
var Messages = /** @class */ (function () { | ||
@@ -62,8 +52,5 @@ function Messages() { | ||
}; | ||
Messages = __decorate([ | ||
tsyringe_1.scoped(tsyringe_1.Lifecycle.ContainerScoped) | ||
], Messages); | ||
return Messages; | ||
}()); | ||
exports.Messages = Messages; | ||
export { Messages }; | ||
//# sourceMappingURL=Messages.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@tolgee/core", | ||
"version": "1.0.0-alpha.60", | ||
"version": "1.1.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
"main": "dist/tolgee.umd.js", | ||
"main": "index.js", | ||
"types": "./lib/index.d.ts", | ||
@@ -25,5 +25,5 @@ "repository": { | ||
"scripts": { | ||
"build": "webpack --env mode=production && tsc", | ||
"build": "rollup -c rollup.config.js && tsc", | ||
"test": "jest --config ./jest.config.js", | ||
"develop": "webpack --env mode=development --watch" | ||
"develop": "concurrently \"rollup -c rollup.config.js -w\" \"tsc --watch\" " | ||
}, | ||
@@ -33,8 +33,9 @@ "author": "JanCizmar", | ||
"files": [ | ||
"index.js", | ||
"lib/**/*", | ||
"dist/**/*", | ||
"core/**/*", | ||
"ui/**/*" | ||
"dist/**/*" | ||
], | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "13.0.4", | ||
"@rollup/plugin-typescript": "8.2.5", | ||
"@testing-library/dom": "^7.24.5", | ||
@@ -45,25 +46,13 @@ "@testing-library/jest-dom": "^5.11.4", | ||
"@types/node": "^14.14.22", | ||
"clsx": "^1.1.1", | ||
"copy-webpack-plugin": "^7.0.0", | ||
"css-loader": "^5.0.1", | ||
"cypress": "^7.1.0", | ||
"cypress-dotenv": "^1.2.2", | ||
"cypress-xpath": "^1.6.1", | ||
"dotenv-webpack": "^7.0.2", | ||
"html-webpack-plugin": "^4.5.0", | ||
"intl-messageformat": "^9.5.3", | ||
"concurrently": "6.2.1", | ||
"intl-messageformat": "^9.9.1", | ||
"jest": "^26.5.2", | ||
"jest-fetch-mock": "^3.0.3", | ||
"reflect-metadata": "^0.1.13", | ||
"regenerator-runtime": "^0.13.7", | ||
"rollup": "^2.56.3", | ||
"rollup-plugin-terser": "7.0.2", | ||
"ts-jest": "^26.4.1", | ||
"ts-loader": "^8.0.14", | ||
"tslint": "~6.1.3", | ||
"tsyringe": "^4.3.0", | ||
"typescript": "^4.0.5", | ||
"webpack": "^5.21.2", | ||
"webpack-bundle-analyzer": "^4.3.0", | ||
"webpack-cli": "^4.5.0" | ||
"tslib": "^2.3.1", | ||
"typescript": "4.3.5" | ||
}, | ||
"gitHead": "60d32e2d4982ec299e0fc633c228c2c1a813deea", | ||
"gitHead": "99cbf40f4c07c936173963c8ead2f9c536fee5b5", | ||
"publishConfig": { | ||
@@ -70,0 +59,0 @@ "access": "public" |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
16
35913
97
1
100
12176
1
5
3
79
1313680
1
13