Skip to content

Commit

Permalink
Add origin option
Browse files Browse the repository at this point in the history
  • Loading branch information
lookasc committed Nov 27, 2023
1 parent 257d774 commit 01b7dd7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@
},
"typesVersions": {
"*": {
"functions": ["dist/functions.d.ts"],
"injectIntl": ["dist/injectIntl.d.ts"],
"useIntl": ["dist/useIntl.d.ts"],
"useSSRIntl": ["dist/useSSRIntl.d.ts"]
"functions": [
"dist/functions.d.ts"
],
"injectIntl": [
"dist/injectIntl.d.ts"
],
"useIntl": [
"dist/useIntl.d.ts"
],
"useSSRIntl": [
"dist/useSSRIntl.d.ts"
]
}
},
"sideEffects": false,
Expand Down
14 changes: 11 additions & 3 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let phraseAppEditor = false;

function sanitizeConfig(config: any) : any {
function sanitizeConfig(config: any): any {
if (typeof config !== 'object') config = {};
config.prefix = config.prefix ? config.prefix : '{{__';
config.suffix = config.suffix ? config.suffix : '__}}';

Expand All @@ -25,7 +26,11 @@ export function createPhraseAppEditorScript(userConfig: Partial<Config>) {
prefix: '[[__',
suffix: '__]]'
}
const config = {...defaultConfig, ...userConfig}
const config = {
...defaultConfig,
...userConfig,
origin: 'react-intl-phraseapp'
}
globalThis.PHRASEAPP_ENABLED = config.phraseEnabled
globalThis.PHRASEAPP_CONFIG = config
return "window.PHRASEAPP_CONFIG = " + JSON.stringify(config) + ";" + "function init() {const phraseapp = document.createElement('script');phraseapp.type = 'module';phraseapp.async = true;phraseapp.src = 'https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js';let s = document.getElementsByTagName('script')[0]; s?.parentNode?.insertBefore(phraseapp, s);};init();"
Expand All @@ -36,7 +41,10 @@ export function initializePhraseAppEditor (config: any) {

phraseAppEditor = true;
globalThis.PHRASEAPP_ENABLED = config.phraseEnabled
globalThis.PHRASEAPP_CONFIG = sanitizeConfig(config);
globalThis.PHRASEAPP_CONFIG = {
...sanitizeConfig(config),
origin: 'react-intl-phraseapp'
}

if (config.phraseEnabled) {
const phraseapp = document.createElement('script');
Expand Down

0 comments on commit 01b7dd7

Please sign in to comment.