locize 3.1.0 → 3.2.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/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
+ ### 3.2.0
2
+
3
+ - using the locizePlugin export should only show the incontext editor if passing `?incontext=true`
4
+
5
+ ### 3.1.1
6
+
7
+ - prevent to append popup multiple times
8
+
1
9
  ### 3.1.0
2
10
 
3
- - additional plugin interface that shows incontext only if passing `?incontext=true``
11
+ - additional plugin interface that shows incontext only if passing `?incontext=true`
4
12
 
5
13
  ### 3.0.5
6
14
 
package/README.md CHANGED
@@ -49,18 +49,18 @@ This plugin is already included in [locizify](https://github.com/locize/locizify
49
49
 
50
50
  ## with i18next
51
51
 
52
- ### this will show the locize incontext editor as a popup in your website
52
+ ### this will show the locize incontext editor as a popup in your website only if the url contains the incontext=true query paramenter, i.e. http://localhost:8080?incontext=true
53
53
  ```js
54
- import { locizePlugin } from 'locize';
54
+ import { locizePlugin } from 'locize'
55
55
 
56
- i18next.use(locizePlugin);
56
+ i18next.use(locizePlugin)
57
57
  ```
58
58
 
59
- ### this will show the locize incontext editor as a popup in your website only if the url contains the incontext=true query paramenter, i.e. http://localhost:8080?incontext=true
59
+ ### this will show the locize incontext editor as a popup in your website
60
60
  ```js
61
- import { locizeEditorPlugin } from 'locize';
61
+ import { locizeEditorPlugin } from 'locize'
62
62
 
63
- i18next.use(locizeEditorPlugin());
63
+ i18next.use(locizeEditorPlugin({ show: true }))
64
64
  ```
65
65
 
66
66
  Using react-i18next you might want to bind the editorSaved event to trigger a rerender:
@@ -1,20 +1,21 @@
1
1
  'use strict';
2
2
 
3
3
  var postMessage = require('./postMessage.js');
4
+ var popup = require('../ui/elements/popup.js');
4
5
 
5
6
  function handler(payload) {
6
7
  var containerStyle = payload.containerStyle;
7
8
  if (containerStyle) {
8
- var popup = document.getElementById('i18next-editor-popup');
9
+ var popup$1 = document.getElementById(popup.popupId);
9
10
  if (containerStyle.height) {
10
- var diff = "calc(".concat(containerStyle.height, " - ").concat(popup.style.height, ")");
11
- popup.style.setProperty('top', "calc(".concat(popup.style.top, " - ").concat(diff, ")"));
12
- popup.style.setProperty('height', containerStyle.height);
11
+ var diff = "calc(".concat(containerStyle.height, " - ").concat(popup$1.style.height, ")");
12
+ popup$1.style.setProperty('top', "calc(".concat(popup$1.style.top, " - ").concat(diff, ")"));
13
+ popup$1.style.setProperty('height', containerStyle.height);
13
14
  }
14
15
  if (containerStyle.width) {
15
- var _diff = "calc(".concat(containerStyle.width, " - ").concat(popup.style.width, ")");
16
- popup.style.setProperty('left', "calc(".concat(popup.style.left, " - ").concat(_diff, ")"));
17
- popup.style.setProperty('width', containerStyle.width);
16
+ var _diff = "calc(".concat(containerStyle.width, " - ").concat(popup$1.style.width, ")");
17
+ popup$1.style.setProperty('left', "calc(".concat(popup$1.style.left, " - ").concat(_diff, ")"));
18
+ popup$1.style.setProperty('width', containerStyle.width);
18
19
  }
19
20
  }
20
21
  }
@@ -9,15 +9,15 @@ export interface LocizePlugin {
9
9
  }
10
10
 
11
11
  /**
12
- * Returns an i18next plugin that will show the incontext editor.
12
+ * Returns an i18next plugin that will show the incontext editor only if your url contains the query paramenter ?incontext=true.
13
13
  */
14
14
  export const locizePlugin: LocizePlugin
15
15
 
16
16
  /**
17
- * Returns an i18next plugin that will only show the incontext editor if the qsProp in your url is set to true.
18
- * @param opt defaults to: { qsProp: 'incontext' }
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
+ * @param opt defaults to: { qsProp: 'incontext', show: false }
19
19
  */
20
- export function locizeEditorPlugin(opt?: { qsProp?: string }): LocizePlugin
20
+ export function locizeEditorPlugin(opt?: { qsProp?: string, show?: boolean }): LocizePlugin
21
21
 
22
22
  /**
23
23
  * Turn on programmatically.
@@ -99,20 +99,6 @@ function getImplementation(i18n) {
99
99
  return impl;
100
100
  }
101
101
  var i18next;
102
- var locizePlugin = {
103
- type: '3rdParty',
104
- init: function init(i18n) {
105
- var options = i18n.options;
106
- i18next = i18n;
107
- if (!isInIframe) configurePostProcessor(i18next, options);
108
- var impl = getImplementation(i18n);
109
- if (!isInIframe) {
110
- process.start(impl);
111
- } else {
112
- processLegacy.startLegacy(impl);
113
- }
114
- }
115
- };
116
102
  var locizeEditorPlugin = function locizeEditorPlugin() {
117
103
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
118
104
  opt.qsProp = opt.qsProp || 'incontext';
@@ -121,7 +107,7 @@ var locizeEditorPlugin = function locizeEditorPlugin() {
121
107
  init: function init(i18n) {
122
108
  var options = i18n.options;
123
109
  i18next = i18n;
124
- var showInContext = utils.getQsParameterByName(opt.qsProp) === 'true';
110
+ var showInContext = opt.show || utils.getQsParameterByName(opt.qsProp) === 'true';
125
111
  if (!isInIframe && showInContext) configurePostProcessor(i18next, options);
126
112
  var impl = getImplementation(i18n);
127
113
  if (!isInIframe && showInContext) {
@@ -132,6 +118,7 @@ var locizeEditorPlugin = function locizeEditorPlugin() {
132
118
  }
133
119
  };
134
120
  };
121
+ var locizePlugin = locizeEditorPlugin();
135
122
 
136
123
  Object.defineProperty(exports, 'unwrap', {
137
124
  enumerable: true,
@@ -54,11 +54,13 @@ function start() {
54
54
  });
55
55
  observer$1.start();
56
56
  mouseDistance.startMouseTracking(observer$1);
57
- document.body.append(popup.Popup(vars.getIframeUrl(), function () {
58
- postMessage.api.requestInitialize(config);
59
- }));
60
- popup$1.initDragElement();
61
- popup$1.initResizeElement();
57
+ if (!document.getElementById(popup.popupId)) {
58
+ document.body.append(popup.Popup(vars.getIframeUrl(), function () {
59
+ postMessage.api.requestInitialize(config);
60
+ }));
61
+ popup$1.initDragElement();
62
+ popup$1.initResizeElement();
63
+ }
62
64
  }
63
65
  if (document.body) return continueToStart();
64
66
  window.addEventListener('load', function () {
@@ -41,9 +41,10 @@ function Minimize(popupEle, onMinimize) {
41
41
  };
42
42
  return image;
43
43
  }
44
+ var popupId = 'i18next-editor-popup';
44
45
  function Popup(url, cb) {
45
46
  var popup = document.createElement('div');
46
- popup.setAttribute('id', 'i18next-editor-popup');
47
+ popup.setAttribute('id', popupId);
47
48
  popup.classList.add('i18next-editor-popup');
48
49
  popup.style = "\n z-index: 9;\n background-color: transparent;\n border: 1px solid rgba(200, 200, 200, 0.9);\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n --i18next-editor-popup-height: 200px;\n height: var(--i18next-editor-popup-height);\n min-height: 150px;\n min-width: 300px;\n --i18next-editor-popup-width: 400px;\n width: var(--i18next-editor-popup-width);\n max-height: 600px;\n max-width: 800px;\n\n position: fixed;\n --i18next-editor-popup-position-top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n --i18next-editor-popup-position-left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n\n overflow: visible;\n ";
49
50
  popup.setAttribute('data-i18next-editor-element', 'true');
@@ -78,3 +79,4 @@ function Popup(url, cb) {
78
79
  }
79
80
 
80
81
  exports.Popup = Popup;
82
+ exports.popupId = popupId;
@@ -1,9 +1,10 @@
1
1
  import { api } from './postMessage.js';
2
+ import { popupId } from '../ui/elements/popup.js';
2
3
 
3
4
  function handler(payload) {
4
5
  var containerStyle = payload.containerStyle;
5
6
  if (containerStyle) {
6
- var popup = document.getElementById('i18next-editor-popup');
7
+ var popup = document.getElementById(popupId);
7
8
  if (containerStyle.height) {
8
9
  var diff = "calc(".concat(containerStyle.height, " - ").concat(popup.style.height, ")");
9
10
  popup.style.setProperty('top', "calc(".concat(popup.style.top, " - ").concat(diff, ")"));
@@ -9,15 +9,15 @@ export interface LocizePlugin {
9
9
  }
10
10
 
11
11
  /**
12
- * Returns an i18next plugin that will show the incontext editor.
12
+ * Returns an i18next plugin that will show the incontext editor only if your url contains the query paramenter ?incontext=true.
13
13
  */
14
14
  export const locizePlugin: LocizePlugin
15
15
 
16
16
  /**
17
- * Returns an i18next plugin that will only show the incontext editor if the qsProp in your url is set to true.
18
- * @param opt defaults to: { qsProp: 'incontext' }
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
+ * @param opt defaults to: { qsProp: 'incontext', show: false }
19
19
  */
20
- export function locizeEditorPlugin(opt?: { qsProp?: string }): LocizePlugin
20
+ export function locizeEditorPlugin(opt?: { qsProp?: string, show?: boolean }): LocizePlugin
21
21
 
22
22
  /**
23
23
  * Turn on programmatically.
@@ -92,20 +92,6 @@ function getImplementation(i18n) {
92
92
  return impl;
93
93
  }
94
94
  var i18next;
95
- var locizePlugin = {
96
- type: '3rdParty',
97
- init: function init(i18n) {
98
- var options = i18n.options;
99
- i18next = i18n;
100
- if (!isInIframe) configurePostProcessor(i18next, options);
101
- var impl = getImplementation(i18n);
102
- if (!isInIframe) {
103
- start(impl);
104
- } else {
105
- startLegacy(impl);
106
- }
107
- }
108
- };
109
95
  var locizeEditorPlugin = function locizeEditorPlugin() {
110
96
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
111
97
  opt.qsProp = opt.qsProp || 'incontext';
@@ -114,7 +100,7 @@ var locizeEditorPlugin = function locizeEditorPlugin() {
114
100
  init: function init(i18n) {
115
101
  var options = i18n.options;
116
102
  i18next = i18n;
117
- var showInContext = getQsParameterByName(opt.qsProp) === 'true';
103
+ var showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true';
118
104
  if (!isInIframe && showInContext) configurePostProcessor(i18next, options);
119
105
  var impl = getImplementation(i18n);
120
106
  if (!isInIframe && showInContext) {
@@ -125,5 +111,6 @@ var locizeEditorPlugin = function locizeEditorPlugin() {
125
111
  }
126
112
  };
127
113
  };
114
+ var locizePlugin = locizeEditorPlugin();
128
115
 
129
116
  export { locizeEditorPlugin, locizePlugin };
@@ -3,7 +3,7 @@ import { parseTree, setImplementation } 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';
6
- import { Popup } from './ui/elements/popup.js';
6
+ import { popupId, Popup } from './ui/elements/popup.js';
7
7
  import { getIframeUrl } from './vars.js';
8
8
  import './api/handleEditKey.js';
9
9
  import './api/handleCommitKey.js';
@@ -46,11 +46,13 @@ function start() {
46
46
  });
47
47
  observer.start();
48
48
  startMouseTracking(observer);
49
- document.body.append(Popup(getIframeUrl(), function () {
50
- api.requestInitialize(config);
51
- }));
52
- initDragElement();
53
- initResizeElement();
49
+ if (!document.getElementById(popupId)) {
50
+ document.body.append(Popup(getIframeUrl(), function () {
51
+ api.requestInitialize(config);
52
+ }));
53
+ initDragElement();
54
+ initResizeElement();
55
+ }
54
56
  }
55
57
  if (document.body) return continueToStart();
56
58
  window.addEventListener('load', function () {
@@ -37,9 +37,10 @@ function Minimize(popupEle, onMinimize) {
37
37
  };
38
38
  return image;
39
39
  }
40
+ var popupId = 'i18next-editor-popup';
40
41
  function Popup(url, cb) {
41
42
  var popup = document.createElement('div');
42
- popup.setAttribute('id', 'i18next-editor-popup');
43
+ popup.setAttribute('id', popupId);
43
44
  popup.classList.add('i18next-editor-popup');
44
45
  popup.style = "\n z-index: 9;\n background-color: transparent;\n border: 1px solid rgba(200, 200, 200, 0.9);\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n --i18next-editor-popup-height: 200px;\n height: var(--i18next-editor-popup-height);\n min-height: 150px;\n min-width: 300px;\n --i18next-editor-popup-width: 400px;\n width: var(--i18next-editor-popup-width);\n max-height: 600px;\n max-width: 800px;\n\n position: fixed;\n --i18next-editor-popup-position-top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n --i18next-editor-popup-position-left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n\n overflow: visible;\n ";
45
46
  popup.setAttribute('data-i18next-editor-element', 'true');
@@ -73,4 +74,4 @@ function Popup(url, cb) {
73
74
  return popup;
74
75
  }
75
76
 
76
- export { Popup };
77
+ export { Popup, popupId };