locizify 10.0.1 → 10.0.3

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,3 +1,11 @@
1
+ ### 10.0.3
2
+
3
+ - update locize dep
4
+
5
+ ### 10.0.2
6
+
7
+ - update locize deps
8
+
1
9
  ### 10.0.1
2
10
 
3
11
  - update locize dep
package/locizify.js CHANGED
@@ -5929,21 +5929,26 @@ var locizify = (function() {
5929
5929
  while (stack.length > 1) {
5930
5930
  if (!object) return {};
5931
5931
  const key = cleanKey(stack.shift());
5932
+ if (UNSAFE_KEYS.indexOf(key) > -1) return {};
5932
5933
  if (!object[key] && Empty) object[key] = new Empty();
5933
5934
  object = object[key];
5934
5935
  }
5935
5936
  if (!object) return {};
5937
+ const k = cleanKey(stack.shift());
5938
+ if (UNSAFE_KEYS.indexOf(k) > -1) return {};
5936
5939
  return {
5937
5940
  obj: object,
5938
- k: cleanKey(stack.shift())
5941
+ k
5939
5942
  };
5940
5943
  }
5941
5944
  function setPath(object, path, newValue) {
5942
5945
  const { obj, k } = getLastOfPath(object, path, Object);
5946
+ if (obj === void 0) return;
5943
5947
  obj[k] = newValue;
5944
5948
  }
5945
5949
  function pushPath(object, path, newValue, concat) {
5946
5950
  const { obj, k } = getLastOfPath(object, path, Object);
5951
+ if (obj === void 0) return;
5947
5952
  obj[k] = obj[k] || [];
5948
5953
  if (concat) obj[k] = obj[k].concat(newValue);
5949
5954
  if (!concat) obj[k].push(newValue);
@@ -6887,14 +6892,25 @@ var locizify = (function() {
6887
6892
  warning: "#e67a00",
6888
6893
  gray: "#ccc"
6889
6894
  };
6890
- var getIframeUrl = function getIframeUrl() {
6895
+ var resolveEnv = function resolveEnv() {
6891
6896
  var _prc$env;
6892
6897
  var p;
6893
6898
  if (typeof process !== "undefined") p = process;
6894
6899
  if (!p && typeof window !== "undefined") p = window.process;
6895
- var env = ((_prc$env = (p || {}).env) === null || _prc$env === void 0 ? void 0 : _prc$env.locizeIncontext) || "production";
6900
+ return ((_prc$env = (p || {}).env) === null || _prc$env === void 0 ? void 0 : _prc$env.locizeIncontext) || "production";
6901
+ };
6902
+ var getIframeUrl = function getIframeUrl() {
6903
+ var env = resolveEnv();
6896
6904
  return env === "development" ? "http://localhost:3003/" : env === "staging" ? "https://incontext-dev.locize.app" : "https://incontext.locize.app";
6897
6905
  };
6906
+ var getEditorOrigins = function getEditorOrigins() {
6907
+ var env = resolveEnv();
6908
+ return env === "development" ? ["http://localhost:3003", "http://localhost:3000"] : env === "staging" ? ["https://incontext-dev.locize.app", "https://dev.locize.app"] : [
6909
+ "https://incontext.locize.app",
6910
+ "https://www.locize.app",
6911
+ "https://locize.app"
6912
+ ];
6913
+ };
6898
6914
  //#endregion
6899
6915
  //#region node_modules/locize/dist/esm/ui/stylesheet.js
6900
6916
  var sheet = function() {
@@ -7120,6 +7136,19 @@ var locizify = (function() {
7120
7136
  if (!results[2]) return "";
7121
7137
  return decodeURIComponent(results[2].replace(/\+/g, " "));
7122
7138
  }
7139
+ var isDebug = function() {
7140
+ if (typeof window === "undefined") return false;
7141
+ try {
7142
+ return window.localStorage.getItem("locize-debug") === "true" || getQsParameterByName$1("locizedebug") === "true";
7143
+ } catch (e) {
7144
+ return false;
7145
+ }
7146
+ }();
7147
+ function debugLog() {
7148
+ var _console;
7149
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
7150
+ if (isDebug) (_console = console).warn.apply(_console, ["[locize]"].concat(args));
7151
+ }
7123
7152
  var _isInIframe = false;
7124
7153
  if (typeof window !== "undefined") try {
7125
7154
  _isInIframe = self !== top;
@@ -7169,12 +7198,14 @@ var locizify = (function() {
7169
7198
  }
7170
7199
  if (!api.origin) api.origin = getIframeUrl();
7171
7200
  if (!api.source || !api.source.postMessage || !api.initialized && allowedActionsBeforeInit.indexOf(action) < 0) {
7172
- pendingMsgs.push({
7201
+ debugLog("queueing (editor not connected yet)", action, payload);
7202
+ if (pendingMsgs.length < 100) pendingMsgs.push({
7173
7203
  action,
7174
7204
  payload
7175
7205
  });
7176
7206
  return;
7177
7207
  }
7208
+ debugLog("out", action, payload);
7178
7209
  if (api.legacy) api.source.postMessage(_objectSpread$5({ message: action }, payload), api.origin);
7179
7210
  else api.source.postMessage({
7180
7211
  sender: "i18next-editor",
@@ -7223,6 +7254,7 @@ var locizify = (function() {
7223
7254
  if (repeat < 0 && api.initInterval) {
7224
7255
  clearInterval(api.initInterval);
7225
7256
  delete api.initInterval;
7257
+ if (!api.initialized) debugLog("handshake gave up: editor never answered requestInitialize");
7226
7258
  }
7227
7259
  }, 2e3);
7228
7260
  },
@@ -7255,17 +7287,24 @@ var locizify = (function() {
7255
7287
  });
7256
7288
  }
7257
7289
  };
7258
- var getExpectedIframeOrigin = function getExpectedIframeOrigin() {
7290
+ var getExpectedEditorOrigins = function getExpectedEditorOrigins() {
7259
7291
  try {
7260
- return new URL(getIframeUrl()).origin;
7292
+ return getEditorOrigins().map(function(url) {
7293
+ return new URL(url).origin;
7294
+ });
7261
7295
  } catch (err) {
7262
- return null;
7296
+ return [];
7263
7297
  }
7264
7298
  };
7265
7299
  if (typeof window !== "undefined") window.addEventListener("message", function(e) {
7266
- var expectedOrigin = getExpectedIframeOrigin();
7267
- if (!expectedOrigin || e.origin !== expectedOrigin) return;
7268
- var _e$data = e.data, sender = _e$data.sender, action = _e$data.action, message = _e$data.message, payload = _e$data.payload;
7300
+ var expectedOrigins = getExpectedEditorOrigins();
7301
+ if (!expectedOrigins.length || expectedOrigins.indexOf(e.origin) < 0) {
7302
+ var _e$data;
7303
+ if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.sender) === "i18next-editor-frame") debugLog("dropped editor message from unexpected origin", e.origin, "expected one of", expectedOrigins);
7304
+ return;
7305
+ }
7306
+ var _e$data2 = e.data, sender = _e$data2.sender, action = _e$data2.action, message = _e$data2.message, payload = _e$data2.payload;
7307
+ debugLog("in", action || message, payload);
7269
7308
  if (message) {
7270
7309
  var usedEventName = getMappedLegacyEvent(message);
7271
7310
  if (handlers[usedEventName]) handlers[usedEventName].forEach(function(fc) {
@@ -7429,9 +7468,11 @@ var locizify = (function() {
7429
7468
  //#endregion
7430
7469
  //#region node_modules/locize/dist/esm/api/handleConfirmInitialized.js
7431
7470
  function handler$5(payload) {
7471
+ var _document$querySelect;
7432
7472
  api.initialized = true;
7433
7473
  clearInterval(api.initInterval);
7434
7474
  delete api.initInterval;
7475
+ (_document$querySelect = document.querySelector(".locize-incontext-error")) === null || _document$querySelect === void 0 || _document$querySelect.remove();
7435
7476
  api.sendCurrentParsedContent();
7436
7477
  api.sendCurrentTargetLanguage();
7437
7478
  }
@@ -7542,12 +7583,15 @@ var locizify = (function() {
7542
7583
  sheet.insertRule(".i18next-editor-popup * { \n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */\n }");
7543
7584
  sheet.insertRule(".i18next-editor-popup .resizer-right {\n width: 15px;\n height: 100%;\n background: transparent;\n position: absolute;\n right: -15px;\n bottom: 0;\n cursor: e-resize;\n }");
7544
7585
  sheet.insertRule(".i18next-editor-popup .resizer-both {\n width: 15px;\n height: 15px;\n background: transparent;\n z-index: 10;\n position: absolute;\n right: -15px;\n bottom: -15px;\n cursor: se-resize;\n }");
7586
+ sheet.insertRule(".locize-incontext-ribbon {\n cursor: pointer;\n position: fixed;\n bottom: 25px;\n right: 25px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 50px;\n height: 50px;\n background-color: rgba(249, 249, 249, 0.8);\n -webkit-backdrop-filter: blur(3px);\n backdrop-filter: blur(3px);\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n border-radius: 50%;\n }");
7587
+ sheet.insertRule(".locize-incontext-ribbon.locize-incontext-ribbon-left {\n right: auto;\n left: 25px;\n }");
7545
7588
  sheet.insertRule(".i18next-editor-popup .resizer-bottom {\n width: 100%;\n height: 15px;\n background: transparent;\n position: absolute;\n right: 0;\n bottom: -15px;\n cursor: s-resize;\n }");
7546
7589
  }
7547
- function Ribbon(popupEle, onMaximize) {
7590
+ function Ribbon(popupEle, onMaximize, ribbonPosition) {
7548
7591
  var ribbon = document.createElement("div");
7549
7592
  ribbon.setAttribute("data-i18next-editor-element", "true");
7550
- ribbon.style = "\n cursor: pointer;\n position: fixed;\n bottom: 25px;\n right: 25px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 50px;\n height: 50px;\n background-color: rgba(249, 249, 249, 0.2);\n backdrop-filter: blur(3px);\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n border-radius: 50%;\n ";
7593
+ ribbon.classList.add("locize-incontext-ribbon");
7594
+ if (ribbonPosition === "bottom-left") ribbon.classList.add("locize-incontext-ribbon-left");
7551
7595
  ribbon.onclick = function() {
7552
7596
  onMaximize();
7553
7597
  };
@@ -7572,7 +7616,18 @@ var locizify = (function() {
7572
7616
  return image;
7573
7617
  }
7574
7618
  var popupId = "i18next-editor-popup";
7619
+ function showPopupError(msg) {
7620
+ var popup = document.getElementById(popupId);
7621
+ if (!popup || popup.querySelector(".locize-incontext-error")) return;
7622
+ var err = document.createElement("div");
7623
+ err.className = "locize-incontext-error";
7624
+ err.setAttribute("data-i18next-editor-element", "true");
7625
+ err.textContent = msg;
7626
+ err.style = "\n position: absolute;\n top: 32px;\n left: 0;\n right: 0;\n z-index: 102;\n padding: 8px 10px;\n background-color: ".concat(colors.warning, ";\n color: #fff;\n font: 13px sans-serif;\n ");
7627
+ popup.appendChild(err);
7628
+ }
7575
7629
  function Popup(url, cb) {
7630
+ var opt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
7576
7631
  var popup = document.createElement("div");
7577
7632
  popup.setAttribute("id", popupId);
7578
7633
  popup.classList.add("i18next-editor-popup");
@@ -7589,7 +7644,7 @@ var locizify = (function() {
7589
7644
  setTimeout(function() {
7590
7645
  document.body.removeChild(ribbon);
7591
7646
  }, 1e3);
7592
- });
7647
+ }, opt.ribbonPosition);
7593
7648
  document.body.appendChild(ribbon);
7594
7649
  stopMouseTracking();
7595
7650
  }));
@@ -9153,6 +9208,10 @@ var locizify = (function() {
9153
9208
  var meta = unwrap(trimmedTxt);
9154
9209
  uninstrumentedStore.remove(node.uniqueID, node);
9155
9210
  store.save(node.uniqueID, meta.invisibleMeta, "text", extractHiddenMeta(node.uniqueID, "text", meta), node);
9211
+ } else if (hasHiddenMeta && !merge.length) {
9212
+ var _meta = unwrap(trimmedTxt);
9213
+ uninstrumentedStore.remove(node.uniqueID, node);
9214
+ store.save(node.uniqueID, _meta.invisibleMeta, "text", extractHiddenMeta(node.uniqueID, "text", _meta), node);
9156
9215
  } else if (hasHiddenStartMarker) merge.push({
9157
9216
  childIndex: i,
9158
9217
  child,
@@ -9169,11 +9228,11 @@ var locizify = (function() {
9169
9228
  child,
9170
9229
  text: txt
9171
9230
  });
9172
- var _meta = unwrap(merge.reduce(function(mem, item) {
9231
+ var _meta2 = unwrap(merge.reduce(function(mem, item) {
9173
9232
  return mem + item.text;
9174
9233
  }, ""));
9175
9234
  uninstrumentedStore.removeKey(node.uniqueID, "html", node, txt);
9176
- store.save(node.uniqueID, _meta.invisibleMeta, "html", extractHiddenMeta(node.uniqueID, "html", _meta, merge), node, merge);
9235
+ store.save(node.uniqueID, _meta2.invisibleMeta, "html", extractHiddenMeta(node.uniqueID, "html", _meta2, merge), node, merge);
9177
9236
  merge = [];
9178
9237
  }
9179
9238
  });
@@ -9332,13 +9391,9 @@ var locizify = (function() {
9332
9391
  var popups = document.getElementsByClassName("i18next-editor-popup");
9333
9392
  var elmnt = null;
9334
9393
  var overlay = null;
9335
- var currentZIndex = 1e5;
9336
9394
  for (var i = 0; i < popups.length; i++) {
9337
9395
  var popup = popups[i];
9338
9396
  var header = getHeader(popup);
9339
- popup.onmousedown = function() {
9340
- this.style.zIndex = "" + ++currentZIndex;
9341
- };
9342
9397
  if (header) {
9343
9398
  header.parentPopup = popup;
9344
9399
  header.onmousedown = dragMouseDown;
@@ -9349,7 +9404,6 @@ var locizify = (function() {
9349
9404
  if (overlay) overlay.style.display = "block";
9350
9405
  stopMouseTracking();
9351
9406
  elmnt = this.parentPopup;
9352
- elmnt.style.zIndex = "" + ++currentZIndex;
9353
9407
  e = e || window.event;
9354
9408
  pos3 = e.clientX;
9355
9409
  pos4 = e.clientY;
@@ -9490,7 +9544,11 @@ var locizify = (function() {
9490
9544
  var showInContext = opt.show || getQsParameterByName$1(opt.qsProp || "incontext") === "true";
9491
9545
  var scriptEle = document.getElementById("locize");
9492
9546
  var config = {};
9493
- ["projectId", "version"].forEach(function(attr) {
9547
+ [
9548
+ "projectId",
9549
+ "version",
9550
+ "ribbonPosition"
9551
+ ].forEach(function(attr) {
9494
9552
  if (!scriptEle) return;
9495
9553
  var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute("data-" + attr.toLowerCase());
9496
9554
  if (value === "true") value = true;
@@ -9515,6 +9573,13 @@ var locizify = (function() {
9515
9573
  observer.start();
9516
9574
  startMouseTracking(observer);
9517
9575
  if (!isInIframe && !document.getElementById("i18next-editor-popup")) {
9576
+ debugLog("starting InContext popup with config", config, "iframe:", getIframeUrl());
9577
+ if (!config.projectId) console.error("[locize] InContext editor: no projectId configured (script tag attribute, i18next editor/backend options or startStandalone options) - the editor will not find your project.");
9578
+ setTimeout(function() {
9579
+ if (api.initialized) return;
9580
+ console.error("[locize] InContext editor did not connect within 15s. Likely causes: you are not logged in at locize (open https://www.locize.app in another tab and log in), the page CSP blocks frame-src " + getIframeUrl() + ", or an adblocker blocked the iframe. Enable diagnostics via localStorage.setItem('locize-debug', 'true').");
9581
+ showPopupError("Could not connect to the locize editor. Are you logged in at locize.app? See the browser console for details.");
9582
+ }, 15e3);
9518
9583
  var popupEl = Popup(getIframeUrl(), function() {
9519
9584
  var _document$getElementB;
9520
9585
  api.source = (_document$getElementB = document.getElementById("i18next-editor-iframe")) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.contentWindow;
@@ -9524,7 +9589,7 @@ var locizify = (function() {
9524
9589
  delete api.initInterval;
9525
9590
  }
9526
9591
  api.requestInitialize(config);
9527
- });
9592
+ }, config);
9528
9593
  document.documentElement.append(popupEl);
9529
9594
  initDragElement();
9530
9595
  initResizeElement();
@@ -9648,7 +9713,7 @@ var locizify = (function() {
9648
9713
  })
9649
9714
  };
9650
9715
  if (!i18n.options.backend && !i18n.options.editor) return opts;
9651
- var pickFrom = i18n.options.editor || i18n.options.backend;
9716
+ var pickFrom = _objectSpread(_objectSpread({}, i18n.options.backend), i18n.options.editor);
9652
9717
  return _objectSpread(_objectSpread({}, opts), {}, {
9653
9718
  projectId: pickFrom.projectId,
9654
9719
  version: pickFrom.version