locize 3.3.0 → 4.0.1

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +76 -38
  3. package/dist/cjs/api/handleCommitKeys.js +7 -0
  4. package/dist/cjs/api/handleEditKey.js +1 -1
  5. package/dist/cjs/api/handleIsLocizeEnabled.js +2 -2
  6. package/dist/cjs/api/handleRequestPopupChanges.js +11 -0
  7. package/dist/cjs/api/handleSendMatchedUninstrumented.js +26 -0
  8. package/dist/cjs/api/postMessage.js +32 -45
  9. package/dist/cjs/implementations/dummyImplementation.js +35 -0
  10. package/dist/cjs/implementations/i18nextImplementation.js +94 -0
  11. package/dist/cjs/index.d.ts +9 -16
  12. package/dist/cjs/index.js +1 -6
  13. package/dist/cjs/locizePlugin.js +6 -90
  14. package/dist/cjs/observer.js +1 -0
  15. package/dist/cjs/parser.js +100 -14
  16. package/dist/cjs/process.js +37 -5
  17. package/dist/cjs/startStandalone.js +11 -17
  18. package/dist/cjs/store.js +1 -0
  19. package/dist/cjs/ui/elements/highlightBox.js +13 -0
  20. package/dist/cjs/ui/elements/icons.js +1 -17
  21. package/dist/cjs/ui/elements/popup.js +3 -3
  22. package/dist/cjs/ui/elements/ribbonBox.js +3 -6
  23. package/dist/cjs/ui/highlightNode.js +28 -77
  24. package/dist/cjs/ui/popup.js +10 -0
  25. package/dist/cjs/ui/utils.js +18 -0
  26. package/dist/cjs/uninstrumentedStore.js +18 -2
  27. package/dist/cjs/utils.js +55 -77
  28. package/dist/cjs/vars.js +5 -2
  29. package/dist/esm/api/handleCommitKeys.js +7 -0
  30. package/dist/esm/api/handleEditKey.js +1 -1
  31. package/dist/esm/api/handleIsLocizeEnabled.js +2 -2
  32. package/dist/esm/api/handleRequestPopupChanges.js +11 -0
  33. package/dist/esm/api/handleSendMatchedUninstrumented.js +20 -0
  34. package/dist/esm/api/postMessage.js +33 -44
  35. package/dist/esm/implementations/dummyImplementation.js +31 -0
  36. package/dist/esm/implementations/i18nextImplementation.js +85 -0
  37. package/dist/esm/index.d.ts +9 -16
  38. package/dist/esm/index.js +3 -6
  39. package/dist/esm/locizePlugin.js +5 -85
  40. package/dist/esm/observer.js +1 -0
  41. package/dist/esm/parser.js +101 -16
  42. package/dist/esm/process.js +38 -6
  43. package/dist/esm/startStandalone.js +7 -17
  44. package/dist/esm/store.js +1 -0
  45. package/dist/esm/ui/elements/highlightBox.js +9 -0
  46. package/dist/esm/ui/elements/icons.js +2 -16
  47. package/dist/esm/ui/elements/popup.js +3 -3
  48. package/dist/esm/ui/elements/ribbonBox.js +4 -7
  49. package/dist/esm/ui/highlightNode.js +28 -78
  50. package/dist/esm/ui/popup.js +10 -0
  51. package/dist/esm/ui/utils.js +18 -1
  52. package/dist/esm/uninstrumentedStore.js +18 -2
  53. package/dist/esm/utils.js +54 -72
  54. package/dist/esm/vars.js +5 -3
  55. package/dist/umd/locize.js +637 -592
  56. package/dist/umd/locize.min.js +1 -1
  57. package/index.d.ts +9 -16
  58. package/locize.js +637 -592
  59. package/locize.min.js +1 -1
  60. package/package.json +1 -1
  61. package/src/_startStandalone.js +22 -0
  62. package/src/api/handleCommitKeys.js +9 -0
  63. package/src/api/handleEditKey.js +5 -11
  64. package/src/api/handleIsLocizeEnabled.js +7 -2
  65. package/src/api/handleRequestPopupChanges.js +27 -0
  66. package/src/api/handleSendMatchedUninstrumented.js +38 -0
  67. package/src/api/index.js +1 -4
  68. package/src/api/postMessage.js +37 -53
  69. package/src/implementations/dummyImplementation.js +29 -0
  70. package/src/implementations/i18nextImplementation.js +114 -0
  71. package/src/implementations/index.js +2 -0
  72. package/src/index.js +7 -6
  73. package/src/locizePlugin.js +51 -28
  74. package/src/observer.js +1 -0
  75. package/src/parser.js +207 -19
  76. package/src/process.js +52 -5
  77. package/src/startStandalone.js +4 -17
  78. package/src/store.js +2 -0
  79. package/src/ui/elements/highlightBox.js +17 -0
  80. package/src/ui/elements/popup.js +4 -4
  81. package/src/ui/elements/ribbonBox.js +12 -8
  82. package/src/ui/highlightNode.js +102 -71
  83. package/src/ui/popup.js +33 -5
  84. package/src/ui/utils.js +28 -1
  85. package/src/uninstrumentedStore.js +18 -2
  86. package/src/utils.js +72 -5
  87. package/src/vars.js +6 -4
  88. package/dist/cjs/api/handleTurnOff.js +0 -8
  89. package/dist/cjs/api/handleTurnOn.js +0 -8
  90. package/dist/cjs/clickHandler.js +0 -55
  91. package/dist/cjs/processLegacy.js +0 -80
  92. package/dist/esm/api/handleTurnOff.js +0 -6
  93. package/dist/esm/api/handleTurnOn.js +0 -6
  94. package/dist/esm/clickHandler.js +0 -51
  95. package/dist/esm/processLegacy.js +0 -72
  96. /package/src/{processLegacy.js → _processLegacy.js} +0 -0
  97. /package/src/api/{handleTurnOff.js → _handleTurnOff.js} +0 -0
  98. /package/src/api/{handleTurnOn.js → _handleTurnOn.js} +0 -0
@@ -1,6 +0,0 @@
1
- import { api } from './postMessage.js';
2
-
3
- function handler(payload, e) {
4
- api.turnOff();
5
- }
6
- api.addHandler('turnOff', handler);
@@ -1,6 +0,0 @@
1
- import { api } from './postMessage.js';
2
-
3
- function handler(payload, e) {
4
- api.turnOn();
5
- }
6
- api.addHandler('turnOn', handler);
@@ -1,51 +0,0 @@
1
- import { containsHiddenMeta, unwrap } from 'i18next-subliminal';
2
- import { getClickedElement, getElementText, getElementI18nKey, getElementNamespace } from './utils.js';
3
-
4
- function createClickHandler(cb) {
5
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
- var handler = function handler(e) {
7
- var el = getClickedElement(e);
8
- if (!el) return {};
9
- e.preventDefault();
10
- e.stopPropagation();
11
- function getFallbackNS() {
12
- if (options.isLocizify) return options.defaultNS;
13
- }
14
- var text = getElementText(el);
15
- var key = getElementI18nKey(el);
16
- var ns = getElementNamespace(el) || getFallbackNS();
17
- if (containsHiddenMeta(text)) {
18
- var meta = unwrap(text);
19
- if (meta && meta.invisibleMeta && meta.invisibleMeta.key) key = meta.invisibleMeta.key;
20
- if (meta && meta.invisibleMeta && meta.invisibleMeta.ns) ns = meta.invisibleMeta.ns;
21
- }
22
- var rectEl = el.getBoundingClientRect ? el : el.parentElement;
23
- var _rectEl$getBoundingCl = rectEl.getBoundingClientRect(),
24
- top = _rectEl$getBoundingCl.top,
25
- left = _rectEl$getBoundingCl.left,
26
- width = _rectEl$getBoundingCl.width,
27
- height = _rectEl$getBoundingCl.height;
28
- var style = window.getComputedStyle(rectEl, null);
29
- var pT = parseFloat(style.getPropertyValue('padding-top'));
30
- var pB = parseFloat(style.getPropertyValue('padding-bottom'));
31
- var pR = parseFloat(style.getPropertyValue('padding-right'));
32
- var pL = parseFloat(style.getPropertyValue('padding-left'));
33
- var sizing = style.getPropertyValue('box-sizing');
34
- cb({
35
- tagName: rectEl.tagName,
36
- text: text,
37
- key: key,
38
- ns: ns,
39
- box: {
40
- top: top,
41
- left: left,
42
- width: sizing === 'border-box' ? width : width - pR - pL,
43
- height: sizing === 'border-box' ? height : height - pT - pB
44
- },
45
- style: style.cssText
46
- });
47
- };
48
- return handler;
49
- }
50
-
51
- export { createClickHandler };
@@ -1,72 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import './api/handleEditKey.js';
3
- import './api/handleCommitKey.js';
4
- import './api/handleCommitKeys.js';
5
- import './api/handleConfirmInitialized.js';
6
- import './api/handleRequestPopupChanges.js';
7
- import './api/handleRequestResourceBundle.js';
8
- import './api/handleSelectedKeys.js';
9
- import './api/handleIsLocizeEnabled.js';
10
- import './api/handleTurnOn.js';
11
- import './api/handleTurnOff.js';
12
- import { api, sendMessage } from './api/postMessage.js';
13
- import { createClickHandler } from './clickHandler.js';
14
-
15
- 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
- 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; }
17
- function startLegacy() {
18
- var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
- if (typeof document === 'undefined') return;
20
- var scriptEle = document.getElementById('locize');
21
- var config = {};
22
- ['projectId', 'version'].forEach(function (attr) {
23
- if (!scriptEle) return;
24
- var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
25
- if (value === 'true') value = true;
26
- if (value === 'false') value = false;
27
- if (value !== undefined && value !== null) config[attr] = value;
28
- });
29
- config = _objectSpread(_objectSpread({}, implementation.getLocizeDetails()), config);
30
- api.init(implementation, createClickHandler(function (payload) {
31
- sendMessage('clickedElement', {
32
- payload: payload
33
- });
34
- }, implementation.getLocizeDetails()));
35
- api.sendCurrentTargetLanguage = function (lng) {
36
- sendMessage('setLng', {
37
- lng: lng || implementation.getLng()
38
- });
39
- };
40
- if (typeof window !== 'undefined') {
41
- var oldHref = window.document.location.href;
42
- window.addEventListener('load', function () {
43
- sendMessage('hrefChanged', {
44
- href: window.document.location.href
45
- });
46
- var bodyList = window.document.querySelector('body');
47
- var observer = new window.MutationObserver(function (mutations) {
48
- mutations.forEach(function (mutation) {
49
- if (oldHref !== window.document.location.href) {
50
- oldHref = window.document.location.href;
51
- sendMessage('hrefChanged', {
52
- href: oldHref
53
- });
54
- }
55
- });
56
- });
57
- var config = {
58
- childList: true,
59
- subtree: true
60
- };
61
- observer.observe(bodyList, config);
62
- });
63
- }
64
- implementation === null || implementation === void 0 || implementation.bindLanguageChange(function (lng) {
65
- api.sendCurrentTargetLanguage(implementation.getLng());
66
- });
67
- implementation === null || implementation === void 0 || implementation.bindMissingKeyHandler(function (lng, ns, k, val) {
68
- api.onAddedKey(lng, ns, k, val);
69
- });
70
- }
71
-
72
- export { startLegacy };
File without changes
File without changes
File without changes