Skip to content

Commit

Permalink
feat(STRINGS-221): Extend PhraseConfig type with hidingClasses fi…
Browse files Browse the repository at this point in the history
…eld (#65)
  • Loading branch information
lookasc authored Dec 12, 2024
1 parent 8dcea75 commit 43967ff
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type RequiredConfigOptions = "projectId" | "accountId";

export type PhraseConfig = Partial<{
phraseEnabled: boolean;
baseUrl: string;
Expand All @@ -20,7 +22,7 @@ export type PhraseConfig = Partial<{
useOldICE: boolean;
forceLocale: boolean;
loginDialogMessage: string;
datacenter: 'eu' | 'us';
datacenter: "eu" | "us";
autoLogin: {
perform: boolean;
email: string;
Expand All @@ -35,25 +37,28 @@ export type PhraseConfig = Partial<{
fullReparse: boolean;
sanitize?: (content: string) => string;
origin?: string;
hidingClasses: string[];
}>;

declare global {
interface Window {
PHRASEAPP_ENABLED: PhraseConfig['phraseEnabled'];
PHRASEAPP_ENABLED: PhraseConfig["phraseEnabled"];
PHRASEAPP_CONFIG: PhraseConfig;
}
}

let phraseAppEditor = false;

export function initializePhraseAppEditor(config: PhraseConfig) {
export function initializePhraseAppEditor(
config: PhraseConfig & Required<Pick<PhraseConfig, RequiredConfigOptions>>
): void {
if (phraseAppEditor) return;
phraseAppEditor = true;

const defaultConfig: PhraseConfig = {
phraseEnabled: false,
prefix: '{{__',
suffix: '__}}',
prefix: "{{__",
suffix: "__}}",
useOldICE: false,
fullReparse: true,
};
Expand All @@ -62,21 +67,21 @@ export function initializePhraseAppEditor(config: PhraseConfig) {
window.PHRASEAPP_CONFIG = {
...defaultConfig,
...config,
origin: 'ngx-translate-phraseapp',
origin: "ngx-translate-phraseapp",
};

if (config.phraseEnabled) {
const phraseapp = document.createElement('script');
const phraseapp = document.createElement("script");
phraseapp.async = true;

if (!config.useOldICE) {
phraseapp.type = 'module';
phraseapp.type = "module";
phraseapp.src = `https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js`;
} else {
phraseapp.type = 'text/javascript';
phraseapp.type = "text/javascript";
phraseapp.src = `https://phrase.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
}
var scriptEl = document.getElementsByTagName('script')[0];
var scriptEl = document.getElementsByTagName("script")[0];
if (scriptEl?.parentNode) {
scriptEl.parentNode.insertBefore(phraseapp, scriptEl);
} else {
Expand All @@ -91,5 +96,5 @@ export function isPhraseEnabled(): boolean {

export function escapeId(id: string): string {
let config = window.PHRASEAPP_CONFIG;
return config.prefix + 'phrase_' + id + config.suffix;
return config.prefix + "phrase_" + id + config.suffix;
}

0 comments on commit 43967ff

Please sign in to comment.