locize 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -36
- package/dist/cjs/{processLegacy.js → _processLegacy.js} +1 -2
- package/dist/cjs/{startStandalone.js → _startStandalone.js} +2 -2
- package/dist/cjs/api/handleCommitKeys.js +7 -0
- package/dist/cjs/api/handleEditKey.js +1 -1
- package/dist/cjs/api/handleIsLocizeEnabled.js +2 -2
- package/dist/cjs/api/handleRequestPopupChanges.js +11 -0
- package/dist/cjs/api/handleSendMatchedUninstrumented.js +26 -0
- package/dist/cjs/api/postMessage.js +32 -45
- package/dist/cjs/implementations/dummyImplementation.js +35 -0
- package/dist/cjs/implementations/i18nextImplementation.js +94 -0
- package/dist/cjs/index.d.ts +9 -16
- package/dist/cjs/index.js +4 -9
- package/dist/cjs/locizePlugin.js +6 -90
- package/dist/cjs/observer.js +1 -0
- package/dist/cjs/parser.js +100 -14
- package/dist/cjs/process.js +37 -5
- package/dist/cjs/store.js +1 -0
- package/dist/cjs/ui/elements/highlightBox.js +13 -0
- package/dist/cjs/ui/elements/icons.js +1 -17
- package/dist/cjs/ui/elements/popup.js +3 -3
- package/dist/cjs/ui/elements/ribbonBox.js +3 -6
- package/dist/cjs/ui/highlightNode.js +28 -77
- package/dist/cjs/ui/popup.js +10 -0
- package/dist/cjs/ui/utils.js +18 -0
- package/dist/cjs/uninstrumentedStore.js +18 -2
- package/dist/cjs/utils.js +54 -0
- package/dist/cjs/vars.js +5 -2
- package/dist/esm/{processLegacy.js → _processLegacy.js} +1 -2
- package/dist/esm/{startStandalone.js → _startStandalone.js} +1 -1
- package/dist/esm/api/handleCommitKeys.js +7 -0
- package/dist/esm/api/handleEditKey.js +1 -1
- package/dist/esm/api/handleIsLocizeEnabled.js +2 -2
- package/dist/esm/api/handleRequestPopupChanges.js +11 -0
- package/dist/esm/api/handleSendMatchedUninstrumented.js +20 -0
- package/dist/esm/api/postMessage.js +33 -44
- package/dist/esm/implementations/dummyImplementation.js +31 -0
- package/dist/esm/implementations/i18nextImplementation.js +85 -0
- package/dist/esm/index.d.ts +9 -16
- package/dist/esm/index.js +5 -8
- package/dist/esm/locizePlugin.js +5 -85
- package/dist/esm/observer.js +1 -0
- package/dist/esm/parser.js +101 -16
- package/dist/esm/process.js +38 -6
- package/dist/esm/store.js +1 -0
- package/dist/esm/ui/elements/highlightBox.js +9 -0
- package/dist/esm/ui/elements/icons.js +2 -16
- package/dist/esm/ui/elements/popup.js +3 -3
- package/dist/esm/ui/elements/ribbonBox.js +4 -7
- package/dist/esm/ui/highlightNode.js +28 -78
- package/dist/esm/ui/popup.js +10 -0
- package/dist/esm/ui/utils.js +18 -1
- package/dist/esm/uninstrumentedStore.js +18 -2
- package/dist/esm/utils.js +53 -1
- package/dist/esm/vars.js +5 -3
- package/dist/umd/locize.js +726 -496
- package/dist/umd/locize.min.js +1 -1
- package/index.d.ts +9 -16
- package/locize.js +726 -496
- package/locize.min.js +1 -1
- package/package.json +1 -1
- package/src/_startStandalone.js +22 -0
- package/src/api/handleCommitKeys.js +9 -0
- package/src/api/handleEditKey.js +5 -11
- package/src/api/handleIsLocizeEnabled.js +7 -2
- package/src/api/handleRequestPopupChanges.js +27 -0
- package/src/api/handleSendMatchedUninstrumented.js +38 -0
- package/src/api/index.js +1 -4
- package/src/api/postMessage.js +37 -53
- package/src/implementations/dummyImplementation.js +29 -0
- package/src/implementations/i18nextImplementation.js +114 -0
- package/src/implementations/index.js +2 -0
- package/src/index.js +8 -7
- package/src/locizePlugin.js +51 -28
- package/src/observer.js +1 -0
- package/src/parser.js +207 -19
- package/src/process.js +52 -5
- package/src/startStandalone.js +4 -17
- package/src/store.js +2 -0
- package/src/ui/elements/highlightBox.js +17 -0
- package/src/ui/elements/popup.js +4 -4
- package/src/ui/elements/ribbonBox.js +12 -8
- package/src/ui/highlightNode.js +102 -71
- package/src/ui/popup.js +33 -5
- package/src/ui/utils.js +28 -1
- package/src/uninstrumentedStore.js +18 -2
- package/src/utils.js +72 -5
- package/src/vars.js +6 -4
- package/dist/cjs/api/handleTurnOff.js +0 -8
- package/dist/cjs/api/handleTurnOn.js +0 -8
- package/dist/esm/api/handleTurnOff.js +0 -6
- package/dist/esm/api/handleTurnOn.js +0 -6
- /package/src/{processLegacy.js → _processLegacy.js} +0 -0
- /package/src/api/{handleTurnOff.js → _handleTurnOff.js} +0 -0
- /package/src/api/{handleTurnOn.js → _handleTurnOn.js} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
|
|
3
|
+
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function getImplementation(i18n) {
|
|
7
|
+
var impl = {
|
|
8
|
+
getResource: function getResource(lng, ns, key) {
|
|
9
|
+
return i18n.getResource && i18n.getResource(lng, ns, key);
|
|
10
|
+
},
|
|
11
|
+
setResource: function setResource(lng, ns, key, value) {
|
|
12
|
+
return i18n.addResource(lng, ns, key, value, {
|
|
13
|
+
silent: true
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
17
|
+
i18n.loadNamespaces(ns, function () {
|
|
18
|
+
cb(i18n.getResourceBundle(lng, ns));
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
getDefaultNS: function getDefaultNS() {
|
|
22
|
+
return i18n.options.defaultNS;
|
|
23
|
+
},
|
|
24
|
+
getLng: function getLng() {
|
|
25
|
+
return i18n.resolvedLanguage || i18n.languages && i18n.languages[0] || i18n.options.lng;
|
|
26
|
+
},
|
|
27
|
+
getSourceLng: function getSourceLng() {
|
|
28
|
+
var fallback = i18n.options.fallbackLng;
|
|
29
|
+
if (typeof fallback === 'string') return fallback;
|
|
30
|
+
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
31
|
+
if (fallback && fallback["default"]) {
|
|
32
|
+
if (typeof fallback["default"] === 'string') return fallback;
|
|
33
|
+
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
34
|
+
}
|
|
35
|
+
if (typeof fallback === 'function') {
|
|
36
|
+
var res = fallback(i18n.resolvedLanguage);
|
|
37
|
+
if (typeof res === 'string') return res;
|
|
38
|
+
if (Array.isArray(res)) return res[res.length - 1];
|
|
39
|
+
}
|
|
40
|
+
return 'dev';
|
|
41
|
+
},
|
|
42
|
+
getLocizeDetails: function getLocizeDetails() {
|
|
43
|
+
var backendName;
|
|
44
|
+
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
45
|
+
backendName = 'I18nextLocizeBackend';
|
|
46
|
+
} else {
|
|
47
|
+
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
48
|
+
}
|
|
49
|
+
var opts = {
|
|
50
|
+
backendName: backendName,
|
|
51
|
+
sourceLng: impl.getSourceLng(),
|
|
52
|
+
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
53
|
+
i18nFramework: 'i18next',
|
|
54
|
+
isLocizify: i18n.options.isLocizify,
|
|
55
|
+
defaultNS: i18n.options.defaultNS,
|
|
56
|
+
targetLngs: _toConsumableArray(new Set([].concat(i18n.options.preload, i18n.options.supportedLngs, [impl.getLng()]))).filter(function (l) {
|
|
57
|
+
return l !== 'cimode' && l !== false && l !== 'false' && l !== undefined && l !== impl.getSourceLng();
|
|
58
|
+
}),
|
|
59
|
+
ns: _toConsumableArray(new Set([].concat(i18n.options.ns, i18n.options.fallbackNS, i18n.options.defaultNS))).filter(function (n) {
|
|
60
|
+
return n !== false && n !== 'false';
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
64
|
+
var pickFrom = i18n.options.editor || i18n.options.backend;
|
|
65
|
+
return _objectSpread(_objectSpread({}, opts), {}, {
|
|
66
|
+
projectId: pickFrom.projectId,
|
|
67
|
+
version: pickFrom.version
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
bindLanguageChange: function bindLanguageChange(cb) {
|
|
71
|
+
i18n.on('languageChanged', cb);
|
|
72
|
+
},
|
|
73
|
+
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
74
|
+
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
75
|
+
if (!isUpdate) cb(lng, ns, k, val);
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
triggerRerender: function triggerRerender() {
|
|
79
|
+
i18n.emit('editorSaved');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return impl;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { getImplementation };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export * from 'i18next-subliminal'
|
|
|
4
4
|
* The i18next plugin for the locize incontext editor.
|
|
5
5
|
*/
|
|
6
6
|
export interface LocizePlugin {
|
|
7
|
-
type: '3rdParty'
|
|
8
|
-
init(i18next: any): () => void
|
|
7
|
+
type: '3rdParty'
|
|
8
|
+
init(i18next: any): () => void
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -17,29 +17,22 @@ export const locizePlugin: LocizePlugin
|
|
|
17
17
|
* Returns an i18next plugin that will only show the incontext editor if the qsProp in your url is set to true or if you pass { show: true }.
|
|
18
18
|
* @param opt defaults to: { qsProp: 'incontext', show: false }
|
|
19
19
|
*/
|
|
20
|
-
export function locizeEditorPlugin(opt?: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
export function turnOn(): void;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Turn off programmatically.
|
|
29
|
-
*/
|
|
30
|
-
export function turnOff(): void;
|
|
20
|
+
export function locizeEditorPlugin(opt?: {
|
|
21
|
+
qsProp?: string
|
|
22
|
+
show?: boolean
|
|
23
|
+
}): LocizePlugin
|
|
31
24
|
|
|
32
25
|
/**
|
|
33
26
|
* Set the language for the editor.
|
|
34
27
|
*/
|
|
35
|
-
export function setEditorLng(lng: string): void
|
|
28
|
+
export function setEditorLng(lng: string): void
|
|
36
29
|
|
|
37
30
|
/**
|
|
38
31
|
* To load the translations somewhere.
|
|
39
32
|
*/
|
|
40
|
-
export function addLocizeSavedHandler(fn: (data: any) => void): void
|
|
33
|
+
export function addLocizeSavedHandler(fn: (data: any) => void): void
|
|
41
34
|
|
|
42
35
|
/**
|
|
43
36
|
* If used without i18next.
|
|
44
37
|
*/
|
|
45
|
-
export function startStandalone(): void
|
|
38
|
+
export function startStandalone(): void
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { locizePlugin, locizeEditorPlugin } from './locizePlugin.js';
|
|
2
2
|
export { locizeEditorPlugin, locizePlugin } from './locizePlugin.js';
|
|
3
|
-
import { startStandalone } from './
|
|
4
|
-
export { startStandalone } from './
|
|
3
|
+
import { startStandalone } from './_startStandalone.js';
|
|
4
|
+
export { startStandalone } from './_startStandalone.js';
|
|
5
5
|
import './api/handleEditKey.js';
|
|
6
6
|
import './api/handleCommitKey.js';
|
|
7
7
|
import './api/handleCommitKeys.js';
|
|
@@ -10,10 +10,9 @@ import './api/handleRequestPopupChanges.js';
|
|
|
10
10
|
import './api/handleRequestResourceBundle.js';
|
|
11
11
|
import './api/handleSelectedKeys.js';
|
|
12
12
|
import './api/handleIsLocizeEnabled.js';
|
|
13
|
-
import './api/
|
|
14
|
-
import './api/
|
|
15
|
-
|
|
16
|
-
export { addLocizeSavedHandler, setEditorLng, turnOff, turnOn } from './api/postMessage.js';
|
|
13
|
+
import './api/handleSendMatchedUninstrumented.js';
|
|
14
|
+
import { addLocizeSavedHandler, setEditorLng } from './api/postMessage.js';
|
|
15
|
+
export { addLocizeSavedHandler, setEditorLng } from './api/postMessage.js';
|
|
17
16
|
import { wrap, unwrap, containsHiddenMeta, PostProcessor } from 'i18next-subliminal';
|
|
18
17
|
export { PostProcessor, containsHiddenMeta, unwrap, wrap } from 'i18next-subliminal';
|
|
19
18
|
|
|
@@ -25,8 +24,6 @@ var index = {
|
|
|
25
24
|
addLocizeSavedHandler: addLocizeSavedHandler,
|
|
26
25
|
locizePlugin: locizePlugin,
|
|
27
26
|
locizeEditorPlugin: locizeEditorPlugin,
|
|
28
|
-
turnOn: turnOn,
|
|
29
|
-
turnOff: turnOff,
|
|
30
27
|
setEditorLng: setEditorLng,
|
|
31
28
|
startStandalone: startStandalone
|
|
32
29
|
};
|
package/dist/esm/locizePlugin.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import '@babel/runtime/helpers/esm/toConsumableArray';
|
|
2
3
|
import { PostProcessor } from 'i18next-subliminal';
|
|
3
4
|
export { unwrap } from 'i18next-subliminal';
|
|
4
5
|
import { start } from './process.js';
|
|
5
|
-
import {
|
|
6
|
-
import { getQsParameterByName } from './utils.js';
|
|
6
|
+
import { getImplementation } from './implementations/i18nextImplementation.js';
|
|
7
7
|
|
|
8
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
var isInIframe = typeof window !== 'undefined';
|
|
11
|
-
try {
|
|
12
|
-
isInIframe = self !== top;
|
|
13
|
-
} catch (e) {}
|
|
14
8
|
function configurePostProcessor(i18next, options) {
|
|
15
9
|
i18next.use(PostProcessor);
|
|
16
10
|
if (typeof options.postProcess === 'string') {
|
|
@@ -22,75 +16,6 @@ function configurePostProcessor(i18next, options) {
|
|
|
22
16
|
}
|
|
23
17
|
options.postProcessPassResolved = true;
|
|
24
18
|
}
|
|
25
|
-
function getImplementation(i18n) {
|
|
26
|
-
var impl = {
|
|
27
|
-
getResource: function getResource(lng, ns, key) {
|
|
28
|
-
return i18n.getResource(lng, ns, key);
|
|
29
|
-
},
|
|
30
|
-
setResource: function setResource(lng, ns, key, value) {
|
|
31
|
-
return i18n.addResource(lng, ns, key, value, {
|
|
32
|
-
silent: true
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
36
|
-
i18n.loadNamespaces(ns, function () {
|
|
37
|
-
cb(i18n.getResourceBundle(lng, ns));
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
getLng: function getLng() {
|
|
41
|
-
return i18n.resolvedLanguage || i18n.languages[0];
|
|
42
|
-
},
|
|
43
|
-
getSourceLng: function getSourceLng() {
|
|
44
|
-
var fallback = i18n.options.fallbackLng;
|
|
45
|
-
if (typeof fallback === 'string') return fallback;
|
|
46
|
-
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
47
|
-
if (fallback && fallback["default"]) {
|
|
48
|
-
if (typeof fallback["default"] === 'string') return fallback;
|
|
49
|
-
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
50
|
-
}
|
|
51
|
-
if (typeof fallback === 'function') {
|
|
52
|
-
var res = fallback(i18n.resolvedLanguage);
|
|
53
|
-
if (typeof res === 'string') return res;
|
|
54
|
-
if (Array.isArray(res)) return res[res.length - 1];
|
|
55
|
-
}
|
|
56
|
-
return 'dev';
|
|
57
|
-
},
|
|
58
|
-
getLocizeDetails: function getLocizeDetails() {
|
|
59
|
-
var backendName;
|
|
60
|
-
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
61
|
-
backendName = 'I18NextLocizeBackend';
|
|
62
|
-
} else {
|
|
63
|
-
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
64
|
-
}
|
|
65
|
-
var opts = {
|
|
66
|
-
backendName: backendName,
|
|
67
|
-
sourceLng: impl.getSourceLng(),
|
|
68
|
-
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
69
|
-
i18nFramework: 'i18next',
|
|
70
|
-
isLocizify: i18n.options.isLocizify,
|
|
71
|
-
defaultNS: i18n.options.defaultNS
|
|
72
|
-
};
|
|
73
|
-
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
74
|
-
var pickFrom = i18n.options.backend || i18n.options.editor;
|
|
75
|
-
return _objectSpread(_objectSpread({}, opts), {}, {
|
|
76
|
-
projectId: pickFrom.projectId,
|
|
77
|
-
version: pickFrom.version
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
bindLanguageChange: function bindLanguageChange(cb) {
|
|
81
|
-
i18n.on('languageChanged', cb);
|
|
82
|
-
},
|
|
83
|
-
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
84
|
-
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
85
|
-
if (!isUpdate) cb(lng, ns, k, val);
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
triggerRerender: function triggerRerender() {
|
|
89
|
-
i18n.emit('editorSaved');
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return impl;
|
|
93
|
-
}
|
|
94
19
|
var i18next;
|
|
95
20
|
var locizeEditorPlugin = function locizeEditorPlugin() {
|
|
96
21
|
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -100,14 +25,9 @@ var locizeEditorPlugin = function locizeEditorPlugin() {
|
|
|
100
25
|
init: function init(i18n) {
|
|
101
26
|
var options = i18n.options;
|
|
102
27
|
i18next = i18n;
|
|
103
|
-
var showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true';
|
|
104
|
-
if (!isInIframe && showInContext) configurePostProcessor(i18next, options);
|
|
105
28
|
var impl = getImplementation(i18n);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} else if (isInIframe) {
|
|
109
|
-
startLegacy(impl);
|
|
110
|
-
}
|
|
29
|
+
configurePostProcessor(i18next, options);
|
|
30
|
+
start(impl, opt);
|
|
111
31
|
}
|
|
112
32
|
};
|
|
113
33
|
};
|
package/dist/esm/observer.js
CHANGED
package/dist/esm/parser.js
CHANGED
|
@@ -2,7 +2,8 @@ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
|
2
2
|
import { containsHiddenMeta, containsHiddenStartMarker, unwrap } from 'i18next-subliminal';
|
|
3
3
|
import { store } from './store.js';
|
|
4
4
|
import { uninstrumentedStore } from './uninstrumentedStore.js';
|
|
5
|
-
import { validAttributes } from './vars.js';
|
|
5
|
+
import { ignoreElements, validAttributes } from './vars.js';
|
|
6
|
+
import { getI18nMetaFromNode } from './utils.js';
|
|
6
7
|
import './shims/uniqueID.js';
|
|
7
8
|
|
|
8
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -16,35 +17,84 @@ function setImplementation(impl) {
|
|
|
16
17
|
function walk(node, func) {
|
|
17
18
|
if (node.dataset && node.dataset.i18nextEditorElement === 'true') return;
|
|
18
19
|
func(node);
|
|
20
|
+
var instr = store.get(node.uniqueID);
|
|
21
|
+
var uninstr = uninstrumentedStore.get(node.uniqueID);
|
|
22
|
+
if (instr || uninstr) {
|
|
23
|
+
var _node$parentElement;
|
|
24
|
+
var id = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.uniqueID;
|
|
25
|
+
uninstrumentedStore.remove(id, node.parentElement);
|
|
26
|
+
}
|
|
19
27
|
var children = node.childNodes;
|
|
20
|
-
for (var
|
|
21
|
-
walk(children[
|
|
28
|
+
for (var _i = 0; _i < children.length; _i++) {
|
|
29
|
+
walk(children[_i], func);
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
|
-
function
|
|
25
|
-
var _i18n, _i18n2;
|
|
32
|
+
function extractHiddenMeta(id, type, meta, children) {
|
|
33
|
+
var _i18n, _i18n2, _i18n3;
|
|
26
34
|
var invisibleMeta = meta.invisibleMeta,
|
|
27
35
|
text = meta.text;
|
|
28
36
|
if (!invisibleMeta || !invisibleMeta.key || !invisibleMeta.ns) return;
|
|
29
|
-
if (!currentSourceLng) currentSourceLng =
|
|
37
|
+
if (!currentSourceLng) currentSourceLng = i18n.getSourceLng();
|
|
30
38
|
return _objectSpread(_objectSpread({
|
|
31
39
|
eleUniqueID: id,
|
|
32
40
|
textType: type,
|
|
33
|
-
children: children ? children.map(function (c) {
|
|
41
|
+
children: children && children.map ? children.map(function (c) {
|
|
34
42
|
return c.childIndex;
|
|
35
43
|
}).join(',') : null,
|
|
36
44
|
qualifiedKey: "".concat(invisibleMeta.ns, ":").concat(invisibleMeta.key)
|
|
37
45
|
}, invisibleMeta), {}, {
|
|
38
46
|
extractedText: text,
|
|
39
|
-
i18nTargetLng: (
|
|
47
|
+
i18nTargetLng: (_i18n = i18n) === null || _i18n === void 0 ? void 0 : _i18n.getLng(),
|
|
40
48
|
i18nSourceLng: currentSourceLng,
|
|
41
|
-
i18nRawText: _defineProperty(_defineProperty({}, "".concat(invisibleMeta.lng), invisibleMeta.source === 'translation' && i18n ? i18n.getResource(invisibleMeta.lng, invisibleMeta.ns, invisibleMeta.key) : null), "".concat(currentSourceLng), invisibleMeta.source === 'translation' && i18n ? i18n.getResource(currentSourceLng, invisibleMeta.ns, invisibleMeta.key) : null)
|
|
49
|
+
i18nRawText: _defineProperty(_defineProperty({}, "".concat(invisibleMeta.lng), invisibleMeta.source === 'translation' && i18n ? (_i18n2 = i18n) === null || _i18n2 === void 0 ? void 0 : _i18n2.getResource(invisibleMeta.lng, invisibleMeta.ns, invisibleMeta.key) : null), "".concat(currentSourceLng), invisibleMeta.source === 'translation' && i18n ? (_i18n3 = i18n) === null || _i18n3 === void 0 ? void 0 : _i18n3.getResource(currentSourceLng, invisibleMeta.ns, invisibleMeta.key) : null)
|
|
42
50
|
});
|
|
43
51
|
}
|
|
52
|
+
function extractNodeMeta(id, type) {
|
|
53
|
+
var _i18n4, _i18n5, _i18n6, _i18n7, _i18n8;
|
|
54
|
+
var nodeMeta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
55
|
+
var text = arguments.length > 3 ? arguments[3] : undefined;
|
|
56
|
+
var children = arguments.length > 4 ? arguments[4] : undefined;
|
|
57
|
+
var meta = nodeMeta[type];
|
|
58
|
+
if (!meta) return;
|
|
59
|
+
if (!currentSourceLng) currentSourceLng = i18n.getSourceLng();
|
|
60
|
+
var i18nTargetLng = i18n.getLng();
|
|
61
|
+
return {
|
|
62
|
+
eleUniqueID: id,
|
|
63
|
+
textType: type,
|
|
64
|
+
children: children && children.map ? children.map(function (c) {
|
|
65
|
+
return c.childIndex;
|
|
66
|
+
}).join(',') : null,
|
|
67
|
+
qualifiedKey: meta.key && (meta.ns || (_i18n4 = i18n) !== null && _i18n4 !== void 0 && _i18n4.getDefaultNS()) ? "".concat(meta.ns || ((_i18n5 = i18n) === null || _i18n5 === void 0 ? void 0 : _i18n5.getDefaultNS()), ":").concat(meta.key) : null,
|
|
68
|
+
key: meta.key,
|
|
69
|
+
ns: meta.ns || ((_i18n6 = i18n) === null || _i18n6 === void 0 ? void 0 : _i18n6.getDefaultNS()),
|
|
70
|
+
extractedText: text,
|
|
71
|
+
i18nTargetLng: i18nTargetLng,
|
|
72
|
+
i18nSourceLng: currentSourceLng,
|
|
73
|
+
i18nRawText: _defineProperty(_defineProperty({}, "".concat(i18nTargetLng), i18n && meta.ns && meta.key ? ((_i18n7 = i18n) === null || _i18n7 === void 0 ? void 0 : _i18n7.getResource(i18nTargetLng, meta.ns, meta.key)) || text : text), "".concat(currentSourceLng), i18n && meta.ns && meta.key ? (_i18n8 = i18n) === null || _i18n8 === void 0 ? void 0 : _i18n8.getResource(currentSourceLng, meta.ns, meta.key) : null)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
44
76
|
function containsOnlySpaces(str) {
|
|
45
77
|
return /^\s*$/.test(str);
|
|
46
78
|
}
|
|
79
|
+
function storeIfQualifiedKey(id, subliminal, type, nodeI18nMeta, node, children, txt) {
|
|
80
|
+
var stored = store.get(id);
|
|
81
|
+
var storedMeta = stored && stored.keys["".concat(type)] || {};
|
|
82
|
+
var typeMeta = nodeI18nMeta["".concat(type)] || {};
|
|
83
|
+
if (!typeMeta.key && storedMeta.key) typeMeta.key = storedMeta.key;
|
|
84
|
+
if (!typeMeta.ns && storedMeta.ns) typeMeta.ns = storedMeta.ns;
|
|
85
|
+
nodeI18nMeta["".concat(type)] = typeMeta;
|
|
86
|
+
var meta = extractNodeMeta(id, type, nodeI18nMeta, txt, children);
|
|
87
|
+
if (meta.qualifiedKey) {
|
|
88
|
+
store.save(id, null, type, meta, node, children);
|
|
89
|
+
uninstrumentedStore.removeKey(i, type, node);
|
|
90
|
+
} else {
|
|
91
|
+
uninstrumentedStore.save(id, type, node, txt);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
47
94
|
function handleNode(node) {
|
|
95
|
+
if (ignoreElements.indexOf(node.nodeName) > -1) return;
|
|
96
|
+
var nodeI18nMeta = getI18nMetaFromNode(node);
|
|
97
|
+
var usedSubliminalForText = false;
|
|
48
98
|
if (node.childNodes && !ignoreMergedEleUniqueIds.includes(node.uniqueID)) {
|
|
49
99
|
var merge = [];
|
|
50
100
|
node.childNodes.forEach(function (child, i) {
|
|
@@ -60,9 +110,11 @@ function handleNode(node) {
|
|
|
60
110
|
if (containsOnlySpaces(txt)) return;
|
|
61
111
|
var hasHiddenMeta = containsHiddenMeta(txt);
|
|
62
112
|
var hasHiddenStartMarker = containsHiddenStartMarker(txt);
|
|
113
|
+
if (hasHiddenMeta) usedSubliminalForText = true;
|
|
63
114
|
if (hasHiddenStartMarker && hasHiddenMeta) {
|
|
64
115
|
var meta = unwrap(txt);
|
|
65
|
-
|
|
116
|
+
uninstrumentedStore.remove(node.uniqueID, node);
|
|
117
|
+
store.save(node.uniqueID, meta.invisibleMeta, 'text', extractHiddenMeta(node.uniqueID, 'text', meta), node);
|
|
66
118
|
} else if (hasHiddenStartMarker) {
|
|
67
119
|
merge.push({
|
|
68
120
|
childIndex: i,
|
|
@@ -84,21 +136,54 @@ function handleNode(node) {
|
|
|
84
136
|
var _meta = unwrap(merge.reduce(function (mem, item) {
|
|
85
137
|
return mem + item.text;
|
|
86
138
|
}, ''));
|
|
87
|
-
|
|
139
|
+
uninstrumentedStore.removeKey(node.uniqueID, 'html', node, txt);
|
|
140
|
+
store.save(node.uniqueID, _meta.invisibleMeta, 'html', extractHiddenMeta(node.uniqueID, 'html', _meta, merge), node, merge);
|
|
88
141
|
merge = [];
|
|
89
|
-
} else if (txt) {
|
|
90
|
-
uninstrumentedStore.save(node.uniqueID, 'text', node);
|
|
91
142
|
}
|
|
92
143
|
});
|
|
144
|
+
if (!usedSubliminalForText) {
|
|
145
|
+
node.childNodes.forEach(function (child, i) {
|
|
146
|
+
if (merge.length && child.nodeName !== '#text') {
|
|
147
|
+
ignoreMergedEleUniqueIds.push(child.uniqueID);
|
|
148
|
+
}
|
|
149
|
+
var txt = child.textContent;
|
|
150
|
+
if (nodeI18nMeta && nodeI18nMeta['html'] && i < node.childNodes.length - 1) {
|
|
151
|
+
merge.push({
|
|
152
|
+
childIndex: i,
|
|
153
|
+
child: child,
|
|
154
|
+
text: txt
|
|
155
|
+
});
|
|
156
|
+
} else if (nodeI18nMeta && nodeI18nMeta['html'] && i === node.childNodes.length - 1) {
|
|
157
|
+
merge.push({
|
|
158
|
+
childIndex: i,
|
|
159
|
+
child: child,
|
|
160
|
+
text: txt
|
|
161
|
+
});
|
|
162
|
+
storeIfQualifiedKey(node.uniqueID, null, 'html', nodeI18nMeta, node, merge, node.innerHTML);
|
|
163
|
+
merge = [];
|
|
164
|
+
} else if (txt) {
|
|
165
|
+
if (nodeI18nMeta && nodeI18nMeta['text']) {
|
|
166
|
+
storeIfQualifiedKey(node.uniqueID, null, 'text', nodeI18nMeta, node, undefined, txt);
|
|
167
|
+
} else if (child.nodeName === '#text' && !containsOnlySpaces(txt)) {
|
|
168
|
+
uninstrumentedStore.save(node.uniqueID, 'text', node, txt);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
93
173
|
}
|
|
94
174
|
if (!node.getAttribute) return;
|
|
95
175
|
validAttributes.forEach(function (attr) {
|
|
96
176
|
var txt = node.getAttribute(attr);
|
|
97
177
|
if (containsHiddenMeta(txt)) {
|
|
98
178
|
var meta = unwrap(txt);
|
|
99
|
-
|
|
179
|
+
uninstrumentedStore.removeKey(node.uniqueID, attr, node);
|
|
180
|
+
store.save(node.uniqueID, meta.invisibleMeta, attr, extractHiddenMeta(node.uniqueID, "".concat(attr), meta), node);
|
|
100
181
|
} else if (txt) {
|
|
101
|
-
|
|
182
|
+
if (nodeI18nMeta && nodeI18nMeta[attr]) {
|
|
183
|
+
storeIfQualifiedKey(node.uniqueID, null, attr, nodeI18nMeta, node, undefined, txt);
|
|
184
|
+
} else {
|
|
185
|
+
uninstrumentedStore.save(node.uniqueID, attr, node, txt);
|
|
186
|
+
}
|
|
102
187
|
}
|
|
103
188
|
});
|
|
104
189
|
}
|
|
@@ -110,4 +195,4 @@ function parseTree(node) {
|
|
|
110
195
|
return store.data;
|
|
111
196
|
}
|
|
112
197
|
|
|
113
|
-
export { parseTree, setImplementation };
|
|
198
|
+
export { extractNodeMeta, parseTree, setImplementation };
|
package/dist/esm/process.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
-
import {
|
|
2
|
+
import { setImplementation, parseTree } from './parser.js';
|
|
3
3
|
import { createObserver } from './observer.js';
|
|
4
4
|
import { startMouseTracking } from './ui/mouseDistance.js';
|
|
5
5
|
import { initDragElement, initResizeElement } from './ui/popup.js';
|
|
@@ -13,15 +13,27 @@ import './api/handleRequestPopupChanges.js';
|
|
|
13
13
|
import './api/handleRequestResourceBundle.js';
|
|
14
14
|
import './api/handleSelectedKeys.js';
|
|
15
15
|
import './api/handleIsLocizeEnabled.js';
|
|
16
|
-
import './api/
|
|
17
|
-
import './api/handleTurnOff.js';
|
|
16
|
+
import './api/handleSendMatchedUninstrumented.js';
|
|
18
17
|
import { api } from './api/postMessage.js';
|
|
18
|
+
import { getQsParameterByName } from './utils.js';
|
|
19
|
+
import '@babel/runtime/helpers/esm/toConsumableArray';
|
|
20
|
+
import { getImplementation } from './implementations/dummyImplementation.js';
|
|
19
21
|
|
|
20
22
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
23
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
var dummyImplementation = getImplementation();
|
|
25
|
+
var isInIframe = typeof window !== 'undefined';
|
|
26
|
+
try {
|
|
27
|
+
isInIframe = self !== top;
|
|
28
|
+
} catch (e) {}
|
|
22
29
|
function start() {
|
|
23
|
-
var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
30
|
+
var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dummyImplementation;
|
|
31
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
32
|
+
show: false,
|
|
33
|
+
qsProp: 'incontext'
|
|
34
|
+
};
|
|
24
35
|
if (typeof document === 'undefined') return;
|
|
36
|
+
var showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true';
|
|
25
37
|
var scriptEle = document.getElementById('locize');
|
|
26
38
|
var config = {};
|
|
27
39
|
['projectId', 'version'].forEach(function (attr) {
|
|
@@ -31,13 +43,15 @@ function start() {
|
|
|
31
43
|
if (value === 'false') value = false;
|
|
32
44
|
if (value !== undefined && value !== null) config[attr] = value;
|
|
33
45
|
});
|
|
34
|
-
config = _objectSpread(_objectSpread({}, implementation.getLocizeDetails()), config);
|
|
46
|
+
config = _objectSpread(_objectSpread(_objectSpread({}, implementation.getLocizeDetails()), config), opt);
|
|
47
|
+
api.config = config;
|
|
35
48
|
api.init(implementation);
|
|
36
49
|
setImplementation(implementation);
|
|
37
50
|
implementation === null || implementation === void 0 || implementation.bindLanguageChange(function (lng) {
|
|
38
51
|
api.sendCurrentTargetLanguage(implementation.getLng());
|
|
39
52
|
});
|
|
40
53
|
function continueToStart() {
|
|
54
|
+
if (!isInIframe && !showInContext) return;
|
|
41
55
|
var observer = createObserver(document.body, function (eles) {
|
|
42
56
|
eles.forEach(function (ele) {
|
|
43
57
|
parseTree(ele);
|
|
@@ -46,13 +60,31 @@ function start() {
|
|
|
46
60
|
});
|
|
47
61
|
observer.start();
|
|
48
62
|
startMouseTracking(observer);
|
|
49
|
-
if (!document.getElementById(popupId)) {
|
|
63
|
+
if (!isInIframe && !document.getElementById(popupId)) {
|
|
50
64
|
document.body.append(Popup(getIframeUrl(), function () {
|
|
51
65
|
api.requestInitialize(config);
|
|
52
66
|
}));
|
|
53
67
|
initDragElement();
|
|
54
68
|
initResizeElement();
|
|
55
69
|
}
|
|
70
|
+
if (typeof window !== 'undefined') {
|
|
71
|
+
var oldHref = window.document.location.href;
|
|
72
|
+
api.sendHrefchanged(oldHref);
|
|
73
|
+
var bodyList = window.document.querySelector('body');
|
|
74
|
+
var _observer = new window.MutationObserver(function (mutations) {
|
|
75
|
+
mutations.forEach(function (mutation) {
|
|
76
|
+
if (oldHref !== window.document.location.href) {
|
|
77
|
+
oldHref = window.document.location.href;
|
|
78
|
+
api.sendHrefchanged(oldHref);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
var _config = {
|
|
83
|
+
childList: true,
|
|
84
|
+
subtree: true
|
|
85
|
+
};
|
|
86
|
+
_observer.observe(bodyList, _config);
|
|
87
|
+
}
|
|
56
88
|
}
|
|
57
89
|
if (document.body) return continueToStart();
|
|
58
90
|
window.addEventListener('load', function () {
|
package/dist/esm/store.js
CHANGED
|
@@ -21,6 +21,7 @@ function save(id, subliminal, type, meta, node, children) {
|
|
|
21
21
|
subliminal: subliminal
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
if (subliminal) data[id].subliminal = subliminal;
|
|
24
25
|
data[id].keys = _objectSpread(_objectSpread({}, data[id].keys), {}, _defineProperty({}, "".concat(type), meta));
|
|
25
26
|
if (children) {
|
|
26
27
|
data[id].children = _objectSpread(_objectSpread({}, data[id].children), {}, _defineProperty({}, "".concat(type, "-").concat(children.map(function (c) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function HighlightBox(ele, borderColor, shadowColor) {
|
|
2
|
+
var rect = ele.getBoundingClientRect();
|
|
3
|
+
var box = document.createElement('div');
|
|
4
|
+
box.style = "position: absolute; top: ".concat(rect.top - 2 + window.scrollY, "px; left: ").concat(rect.left - 2 + window.scrollX, "px; height: ").concat(rect.height + 4, "px; width: ").concat(rect.width + 4, "px; border: 1px solid ").concat(borderColor, "; border-radius: 2px; ").concat(shadowColor ? "box-shadow: 0 0 20px 0 ".concat(shadowColor, ";") : '');
|
|
5
|
+
box.setAttribute('data-i18next-editor-element', 'true');
|
|
6
|
+
return box;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { HighlightBox };
|