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.
Files changed (95) hide show
  1. package/README.md +74 -36
  2. package/dist/cjs/{processLegacy.js → _processLegacy.js} +1 -2
  3. package/dist/cjs/{startStandalone.js → _startStandalone.js} +2 -2
  4. package/dist/cjs/api/handleCommitKeys.js +7 -0
  5. package/dist/cjs/api/handleEditKey.js +1 -1
  6. package/dist/cjs/api/handleIsLocizeEnabled.js +2 -2
  7. package/dist/cjs/api/handleRequestPopupChanges.js +11 -0
  8. package/dist/cjs/api/handleSendMatchedUninstrumented.js +26 -0
  9. package/dist/cjs/api/postMessage.js +32 -45
  10. package/dist/cjs/implementations/dummyImplementation.js +35 -0
  11. package/dist/cjs/implementations/i18nextImplementation.js +94 -0
  12. package/dist/cjs/index.d.ts +9 -16
  13. package/dist/cjs/index.js +4 -9
  14. package/dist/cjs/locizePlugin.js +6 -90
  15. package/dist/cjs/observer.js +1 -0
  16. package/dist/cjs/parser.js +100 -14
  17. package/dist/cjs/process.js +37 -5
  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 +54 -0
  28. package/dist/cjs/vars.js +5 -2
  29. package/dist/esm/{processLegacy.js → _processLegacy.js} +1 -2
  30. package/dist/esm/{startStandalone.js → _startStandalone.js} +1 -1
  31. package/dist/esm/api/handleCommitKeys.js +7 -0
  32. package/dist/esm/api/handleEditKey.js +1 -1
  33. package/dist/esm/api/handleIsLocizeEnabled.js +2 -2
  34. package/dist/esm/api/handleRequestPopupChanges.js +11 -0
  35. package/dist/esm/api/handleSendMatchedUninstrumented.js +20 -0
  36. package/dist/esm/api/postMessage.js +33 -44
  37. package/dist/esm/implementations/dummyImplementation.js +31 -0
  38. package/dist/esm/implementations/i18nextImplementation.js +85 -0
  39. package/dist/esm/index.d.ts +9 -16
  40. package/dist/esm/index.js +5 -8
  41. package/dist/esm/locizePlugin.js +5 -85
  42. package/dist/esm/observer.js +1 -0
  43. package/dist/esm/parser.js +101 -16
  44. package/dist/esm/process.js +38 -6
  45. package/dist/esm/store.js +1 -0
  46. package/dist/esm/ui/elements/highlightBox.js +9 -0
  47. package/dist/esm/ui/elements/icons.js +2 -16
  48. package/dist/esm/ui/elements/popup.js +3 -3
  49. package/dist/esm/ui/elements/ribbonBox.js +4 -7
  50. package/dist/esm/ui/highlightNode.js +28 -78
  51. package/dist/esm/ui/popup.js +10 -0
  52. package/dist/esm/ui/utils.js +18 -1
  53. package/dist/esm/uninstrumentedStore.js +18 -2
  54. package/dist/esm/utils.js +53 -1
  55. package/dist/esm/vars.js +5 -3
  56. package/dist/umd/locize.js +726 -496
  57. package/dist/umd/locize.min.js +1 -1
  58. package/index.d.ts +9 -16
  59. package/locize.js +726 -496
  60. package/locize.min.js +1 -1
  61. package/package.json +1 -1
  62. package/src/_startStandalone.js +22 -0
  63. package/src/api/handleCommitKeys.js +9 -0
  64. package/src/api/handleEditKey.js +5 -11
  65. package/src/api/handleIsLocizeEnabled.js +7 -2
  66. package/src/api/handleRequestPopupChanges.js +27 -0
  67. package/src/api/handleSendMatchedUninstrumented.js +38 -0
  68. package/src/api/index.js +1 -4
  69. package/src/api/postMessage.js +37 -53
  70. package/src/implementations/dummyImplementation.js +29 -0
  71. package/src/implementations/i18nextImplementation.js +114 -0
  72. package/src/implementations/index.js +2 -0
  73. package/src/index.js +8 -7
  74. package/src/locizePlugin.js +51 -28
  75. package/src/observer.js +1 -0
  76. package/src/parser.js +207 -19
  77. package/src/process.js +52 -5
  78. package/src/startStandalone.js +4 -17
  79. package/src/store.js +2 -0
  80. package/src/ui/elements/highlightBox.js +17 -0
  81. package/src/ui/elements/popup.js +4 -4
  82. package/src/ui/elements/ribbonBox.js +12 -8
  83. package/src/ui/highlightNode.js +102 -71
  84. package/src/ui/popup.js +33 -5
  85. package/src/ui/utils.js +28 -1
  86. package/src/uninstrumentedStore.js +18 -2
  87. package/src/utils.js +72 -5
  88. package/src/vars.js +6 -4
  89. package/dist/cjs/api/handleTurnOff.js +0 -8
  90. package/dist/cjs/api/handleTurnOn.js +0 -8
  91. package/dist/esm/api/handleTurnOff.js +0 -6
  92. package/dist/esm/api/handleTurnOn.js +0 -6
  93. /package/src/{processLegacy.js → _processLegacy.js} +0 -0
  94. /package/src/api/{handleTurnOff.js → _handleTurnOff.js} +0 -0
  95. /package/src/api/{handleTurnOn.js → _handleTurnOn.js} +0 -0
@@ -1,6 +1,8 @@
1
1
  import { colors } from '../vars.js'
2
2
  import { RibbonBox } from './elements/ribbonBox.js'
3
+ import { HighlightBox } from './elements/highlightBox.js'
3
4
  import { computePosition, flip, shift, offset, arrow } from '@floating-ui/dom'
5
+ import { getOptimizedBoundingRectEle } from './utils.js'
4
6
 
5
7
  const eleToOutline = [
6
8
  'DIV',
@@ -18,15 +20,22 @@ const eleToOutline = [
18
20
  'DL',
19
21
  'PRE'
20
22
  ]
21
- const overriddenStyles = ['outline', 'border-radius', 'outline-offset', 'filter']
23
+ const overriddenStyles = [
24
+ 'outline',
25
+ 'border-radius',
26
+ 'outline-offset',
27
+ 'filter'
28
+ ]
22
29
  const originalStyles = {}
23
30
  const selected = {}
24
31
 
25
32
  export function highlight (item, node, keys) {
26
33
  const { id } = item
27
34
 
28
- if (selected[id]) return
35
+ // uncomment below if we do not won't the ribbon box to show on selected
36
+ // if (selected[id]) return
29
37
 
38
+ /*
30
39
  if (!originalStyles[id]) {
31
40
  originalStyles[id] = overriddenStyles.reduce((mem, s) => {
32
41
  mem[s] = node.style[s]
@@ -46,33 +55,22 @@ export function highlight (item, node, keys) {
46
55
  node.style.filter = 'brightness(110%)'
47
56
  // node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
48
57
  }
58
+ */
59
+
60
+ // get a bounding rect on main element or optimized inner text
61
+ const rectEle = getOptimizedBoundingRectEle(node)
62
+
63
+ if (!item.highlightBox) {
64
+ const box = HighlightBox(rectEle, colors.highlight)
65
+ document.body.appendChild(box)
66
+ item.highlightBox = box
67
+ }
49
68
 
50
69
  if (!item.ribbonBox) {
51
70
  const { box: actions, arrow: arrowEle } = RibbonBox(keys)
52
71
  document.body.appendChild(actions)
53
72
 
54
- let refEle = node
55
- // const arrowLen = arrowEle.offsetWidth
56
-
57
- // better placement for element only containing text
58
- // note: for html we would have to calculate based on children...
59
- if (node.childNodes.length === 1) {
60
- const childNode = node.childNodes[0]
61
-
62
- if (childNode && childNode.nodeName === '#text') {
63
- const range = document.createRange()
64
- range.selectNode(childNode)
65
- const rect = range.getBoundingClientRect()
66
-
67
- refEle = {
68
- getBoundingClientRect () {
69
- return rect
70
- }
71
- }
72
- }
73
- }
74
-
75
- computePosition(refEle, actions, {
73
+ computePosition(rectEle, actions, {
76
74
  placement: 'right',
77
75
  middleware: [
78
76
  flip({ fallbackPlacements: ['left', 'bottom'] }),
@@ -111,7 +109,12 @@ export function highlight (item, node, keys) {
111
109
  right: '',
112
110
  bottom: '',
113
111
  [staticSide]: `${side === 'bottom' ? -18 : -25}px`,
114
- transform: side === 'bottom' ? 'rotate(90deg)' : side === 'left' ? 'rotate(180deg)' : ''
112
+ transform:
113
+ side === 'bottom'
114
+ ? 'rotate(90deg)'
115
+ : side === 'left'
116
+ ? 'rotate(180deg)'
117
+ : ''
115
118
  })
116
119
  }
117
120
  })
@@ -126,71 +129,99 @@ export function highlightUninstrumented (item, node, keys) {
126
129
 
127
130
  if (selected[id]) return
128
131
 
129
- if (!originalStyles[id]) {
130
- originalStyles[id] = overriddenStyles.reduce((mem, s) => {
131
- mem[s] = node.style[s]
132
- return mem
133
- }, {})
134
- }
135
-
136
- if (eleToOutline.includes(node.nodeName)) {
137
- node.style.outline = `${colors.warning} solid 1px`
138
- node.style.setProperty('border-radius', '1px')
139
- node.style.setProperty('outline-offset', '2px')
140
- node.style.filter = 'brightness(110%)'
141
- } else {
142
- node.style.outline = `${colors.warning} solid 1px`
143
- node.style.setProperty('border-radius', '1px')
144
- node.style.setProperty('outline-offset', '1px')
145
- node.style.filter = 'brightness(110%)'
146
- // node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
132
+ // if (!originalStyles[id]) {
133
+ // originalStyles[id] = overriddenStyles.reduce((mem, s) => {
134
+ // mem[s] = node.style[s]
135
+ // return mem
136
+ // }, {})
137
+ // }
138
+
139
+ // if (eleToOutline.includes(node.nodeName)) {
140
+ // node.style.outline = `${colors.warning} solid 1px`
141
+ // node.style.setProperty('border-radius', '1px')
142
+ // node.style.setProperty('outline-offset', '2px')
143
+ // node.style.filter = 'brightness(110%)'
144
+ // } else {
145
+ // node.style.outline = `${colors.warning} solid 1px`
146
+ // node.style.setProperty('border-radius', '1px')
147
+ // node.style.setProperty('outline-offset', '1px')
148
+ // node.style.filter = 'brightness(110%)'
149
+ // // node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
150
+ // }
151
+
152
+ const rectEle = getOptimizedBoundingRectEle(node)
153
+
154
+ if (!item.highlightBox) {
155
+ const box = HighlightBox(rectEle, colors.warning)
156
+ document.body.appendChild(box)
157
+ item.highlightBox = box
147
158
  }
148
159
  }
149
160
 
150
161
  export function selectedHighlight (item, node, keys) {
151
162
  const { id } = item
152
163
 
153
- if (!originalStyles[id]) {
154
- originalStyles[id] = overriddenStyles.reduce((mem, s) => {
155
- mem[s] = node.style[s]
156
- return mem
157
- }, {})
158
- }
159
-
160
- if (eleToOutline.includes(node.nodeName)) {
161
- node.style.outline = `${colors.highlight} solid 1px`
162
- node.style.setProperty('border-radius', '1px')
163
- node.style.setProperty('outline-offset', '2px')
164
- // node.style.filter = 'brightness(110%)';
165
- node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
166
- } else {
167
- node.style.outline = `${colors.highlight} solid 1px`
168
- node.style.setProperty('border-radius', '1px')
169
- node.style.setProperty('outline-offset', '1px')
170
- // node.style.filter = 'brightness(110%)';
171
- node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
164
+ // if (!originalStyles[id]) {
165
+ // originalStyles[id] = overriddenStyles.reduce((mem, s) => {
166
+ // mem[s] = node.style[s]
167
+ // return mem
168
+ // }, {})
169
+ // }
170
+
171
+ // if (eleToOutline.includes(node.nodeName)) {
172
+ // // node.style.outline = `${colors.highlight} solid 1px`
173
+ // // node.style.setProperty('border-radius', '1px')
174
+ // // node.style.setProperty('outline-offset', '2px')
175
+ // // node.style.filter = 'brightness(110%)';
176
+ // node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
177
+ // } else {
178
+ // // node.style.outline = `${colors.highlight} solid 1px`
179
+ // // node.style.setProperty('border-radius', '1px')
180
+ // // node.style.setProperty('outline-offset', '1px')
181
+ // // node.style.filter = 'brightness(110%)';
182
+ // node.style.filter = `brightness(110%) drop-shadow(0px 0px 2px ${colors.highlight} )`
183
+ // }
184
+
185
+ const rectEle = getOptimizedBoundingRectEle(node)
186
+
187
+ if (!item.highlightBox) {
188
+ const box = HighlightBox(rectEle, colors.highlight, colors.gray)
189
+ document.body.appendChild(box)
190
+ item.highlightBox = box
172
191
  }
173
192
 
174
193
  // hide ribbons
175
- if (item.ribbonBox) {
176
- document.body.removeChild(item.ribbonBox)
194
+ // if (item.ribbonBox) {
195
+ // document.body.removeChild(item.ribbonBox)
177
196
 
178
- delete item.ribbonBox
179
- }
197
+ // delete item.ribbonBox
198
+ // }
180
199
 
181
200
  selected[id] = true
182
201
  }
183
202
 
203
+ export function recalcSelectedHighlight (item, node, keys) {
204
+ if (!selected[item.id]) return
205
+ resetHighlight(item, node, keys, false)
206
+ selectedHighlight(item, node, keys)
207
+ }
208
+
184
209
  export function resetHighlight (item, node, keys, ignoreSelected = true) {
185
210
  const { id } = item
186
211
 
187
212
  if (ignoreSelected && selected[id]) return
188
213
 
189
- if (originalStyles[id]) {
190
- overriddenStyles.forEach(s => {
191
- node.style.setProperty(s, originalStyles[id][s])
192
- })
193
- delete originalStyles[id]
214
+ // if (originalStyles[id]) {
215
+ // overriddenStyles.forEach(s => {
216
+ // node.style.setProperty(s, originalStyles[id][s])
217
+ // })
218
+ // delete originalStyles[id]
219
+ // }
220
+
221
+ if (item.highlightBox) {
222
+ document.body.removeChild(item.highlightBox)
223
+
224
+ delete item.highlightBox
194
225
  }
195
226
 
196
227
  if (item.ribbonBox) {
package/src/ui/popup.js CHANGED
@@ -25,7 +25,8 @@ export function initDragElement () {
25
25
  }
26
26
 
27
27
  function dragMouseDown (e) {
28
- if (!overlay) overlay = document.getElementById('i18next-editor-popup-overlay')
28
+ if (!overlay)
29
+ overlay = document.getElementById('i18next-editor-popup-overlay')
29
30
  if (overlay) overlay.style.display = 'block'
30
31
  stopMouseTracking()
31
32
 
@@ -61,13 +62,24 @@ export function initDragElement () {
61
62
  startMouseTracking()
62
63
  if (overlay) overlay.style.display = 'none'
63
64
 
65
+ const ele = document.getElementById('i18next-editor-popup')
66
+ localStorage.setItem(
67
+ 'locize_popup_pos',
68
+ JSON.stringify({
69
+ top: parseInt(document.defaultView.getComputedStyle(ele).top, 10),
70
+ left: parseInt(document.defaultView.getComputedStyle(ele).left, 10)
71
+ })
72
+ )
73
+
64
74
  /* stop moving when mouse button is released: */
65
75
  document.onmouseup = null
66
76
  document.onmousemove = null
67
77
  }
68
78
 
69
79
  function getHeader (element) {
70
- const headerItems = element.getElementsByClassName('i18next-editor-popup-header')
80
+ const headerItems = element.getElementsByClassName(
81
+ 'i18next-editor-popup-header'
82
+ )
71
83
 
72
84
  if (headerItems.length === 1) {
73
85
  return headerItems[0]
@@ -107,15 +119,22 @@ export function initResizeElement () {
107
119
 
108
120
  function initDrag (e) {
109
121
  stopMouseTracking()
110
- if (!overlay) overlay = document.getElementById('i18next-editor-popup-overlay')
122
+ if (!overlay)
123
+ overlay = document.getElementById('i18next-editor-popup-overlay')
111
124
  if (overlay) overlay.style.display = 'block'
112
125
 
113
126
  element = this.parentPopup
114
127
 
115
128
  startX = e.clientX
116
129
  startY = e.clientY
117
- startWidth = parseInt(document.defaultView.getComputedStyle(element).width, 10)
118
- startHeight = parseInt(document.defaultView.getComputedStyle(element).height, 10)
130
+ startWidth = parseInt(
131
+ document.defaultView.getComputedStyle(element).width,
132
+ 10
133
+ )
134
+ startHeight = parseInt(
135
+ document.defaultView.getComputedStyle(element).height,
136
+ 10
137
+ )
119
138
  document.documentElement.addEventListener('mousemove', doDrag, false)
120
139
  document.documentElement.addEventListener('mouseup', stopDrag, false)
121
140
  }
@@ -129,6 +148,15 @@ export function initResizeElement () {
129
148
  startMouseTracking()
130
149
  if (overlay) overlay.style.display = 'none'
131
150
 
151
+ const ele = document.getElementById('i18next-editor-popup')
152
+ localStorage.setItem(
153
+ 'locize_popup_size',
154
+ JSON.stringify({
155
+ width: parseInt(document.defaultView.getComputedStyle(ele).width, 10),
156
+ height: parseInt(document.defaultView.getComputedStyle(ele).height, 10)
157
+ })
158
+ )
159
+
132
160
  document.documentElement.removeEventListener('mousemove', doDrag, false)
133
161
  document.documentElement.removeEventListener('mouseup', stopDrag, false)
134
162
  }
package/src/ui/utils.js CHANGED
@@ -6,7 +6,8 @@ export function isInViewport (el) {
6
6
 
7
7
  const rect = el.getBoundingClientRect()
8
8
  // DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
9
- const windowHeight = window.innerHeight || document.documentElement.clientHeight
9
+ const windowHeight =
10
+ window.innerHeight || document.documentElement.clientHeight
10
11
  const windowWidth = window.innerWidth || document.documentElement.clientWidth
11
12
 
12
13
  // http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
@@ -41,3 +42,29 @@ export function mouseDistanceFromElement (mouseEvent, element) {
41
42
  hypot = (distX ** 2 + distY ** 2) ** (1 / 2)
42
43
  return Math.floor(hypot) // this will output 0 when next to your element.
43
44
  }
45
+
46
+ export function getOptimizedBoundingRectEle (node) {
47
+ // get a bounding rect on main element or optimized inner text
48
+ let refEle = node
49
+ // const arrowLen = arrowEle.offsetWidth
50
+
51
+ // better placement for element only containing text
52
+ // note: for html we would have to calculate based on children...
53
+ if (node.childNodes.length === 1) {
54
+ const childNode = node.childNodes[0]
55
+
56
+ if (childNode && childNode.nodeName === '#text') {
57
+ const range = document.createRange()
58
+ range.selectNode(childNode)
59
+ const rect = range.getBoundingClientRect()
60
+
61
+ refEle = {
62
+ getBoundingClientRect () {
63
+ return rect
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ return refEle
70
+ }
@@ -11,7 +11,7 @@ function clean () {
11
11
  })
12
12
  }
13
13
 
14
- function save (id, type, node) {
14
+ function save (id, type, node, txt) {
15
15
  if (!id || !type || !node) return
16
16
 
17
17
  if (!data[id]) {
@@ -23,16 +23,32 @@ function save (id, type, node) {
23
23
 
24
24
  data[id].keys = {
25
25
  ...data[id].keys,
26
- [`${type}`]: 'uninstrumented'
26
+ [`${type}`]: { value: txt, eleUniqueID: id, textType: type }
27
27
  }
28
28
  }
29
29
 
30
+ function remove (id, node) {
31
+ resetHighlight(id, node)
32
+ delete data[id]
33
+ }
34
+
35
+ function removeKey (id, key, node) {
36
+ const item = get(id)
37
+ if (!item) return
38
+
39
+ delete item.keys[`${key}`]
40
+
41
+ if (!Object.keys(item.keys).length) remove(id, node)
42
+ }
43
+
30
44
  function get (id) {
31
45
  return data[id]
32
46
  }
33
47
 
34
48
  export const uninstrumentedStore = {
35
49
  save,
50
+ remove,
51
+ removeKey,
36
52
  clean,
37
53
  get,
38
54
  data
package/src/utils.js CHANGED
@@ -56,7 +56,12 @@ export function getClickedElement (e) {
56
56
  e.srcElement.nodeType === 1 &&
57
57
  (e.srcElement.nodeName === 'BUTTON' || e.srcElement.nodeName === 'INPUT')
58
58
  ) {
59
- if (e.srcElement.getAttribute && e.srcElement.getAttribute('ignorelocizeeditor') === '') { return null }
59
+ if (
60
+ e.srcElement.getAttribute &&
61
+ e.srcElement.getAttribute('ignorelocizeeditor') === ''
62
+ ) {
63
+ return null
64
+ }
60
65
  return e.srcElement
61
66
  }
62
67
 
@@ -67,7 +72,8 @@ export function getClickedElement (e) {
67
72
  el = e.originalEvent.explicitOriginalTarget
68
73
  } else {
69
74
  const parent = e.srcElement
70
- if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '') return null
75
+ if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '')
76
+ return null
71
77
 
72
78
  const left = e.pageX
73
79
  const top = e.pageY
@@ -87,11 +93,13 @@ export function getClickedElement (e) {
87
93
  if (n.nodeType === 1 && nOffset.bottom < top) topStartsAt = i + 1
88
94
 
89
95
  // if node is below top click set end index to this node
90
- if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top) topBreaksAt = i
96
+ if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top)
97
+ topBreaksAt = i
91
98
  }
92
99
 
93
100
  // check we are inside children lenght
94
- if (topStartsAt + 1 > parent.childNodes.length) topStartsAt = parent.childNodes.length - 1
101
+ if (topStartsAt + 1 > parent.childNodes.length)
102
+ topStartsAt = parent.childNodes.length - 1
95
103
  if (!topBreaksAt) topBreaksAt = parent.childNodes.length
96
104
  // console.warn('bound', topStartsAt, topBreaksAt)
97
105
 
@@ -125,10 +133,69 @@ function getAttribute (el, name) {
125
133
  export function getElementI18nKey (el) {
126
134
  const key = getAttribute(el, 'data-i18n')
127
135
  if (key) return key
128
- if (el.nodeType === window.Node.TEXT_NODE && el.parentElement) { return getElementI18nKey(el.parentElement) }
136
+ if (el.nodeType === window.Node.TEXT_NODE && el.parentElement) {
137
+ return getElementI18nKey(el.parentElement)
138
+ }
129
139
  return undefined
130
140
  }
131
141
 
142
+ function parseAttrFromKey (key) {
143
+ let attr = 'text'
144
+
145
+ if (key.indexOf('[') == 0) {
146
+ var parts = key.split(']')
147
+ key = parts[1]
148
+ attr = parts[0].substr(1, parts[0].length - 1)
149
+ }
150
+
151
+ const newKey =
152
+ key.indexOf(';') == key.length - 1 ? key.substr(0, key.length - 2) : key
153
+
154
+ return [newKey, attr]
155
+ }
156
+
157
+ export function getI18nMetaFromNode (el, hasNamespacePrependToKey = true) {
158
+ const key = getElementI18nKey(el)
159
+ const ns = getElementNamespace(el)
160
+
161
+ const allKeys = {}
162
+
163
+ if (key && key.indexOf(';') >= 0) {
164
+ let keys = key.split(';')
165
+ for (let ix = 0, l_ix = keys.length; ix < l_ix; ix++) {
166
+ if (keys[ix] != '') {
167
+ const [usedKey, attr] = parseAttrFromKey(keys[ix])
168
+
169
+ allKeys[attr] = usedKey
170
+ }
171
+ }
172
+ } else if (key) {
173
+ const [usedKey, attr] = parseAttrFromKey(key)
174
+
175
+ allKeys[attr] = usedKey
176
+ }
177
+
178
+ if (Object.keys(allKeys).length < 1) return null
179
+
180
+ const res = Object.keys(allKeys).reduce((mem, attr) => {
181
+ let key = allKeys[attr]
182
+ let usedNS = ns
183
+ let usedKey = key
184
+
185
+ if (hasNamespacePrependToKey && key.indexOf(':') > -1) {
186
+ const parts = key.split(':')
187
+ usedKey = parts[1]
188
+ usedNS = parts[0]
189
+ }
190
+
191
+ mem[attr] = { key: usedKey, ns: usedNS }
192
+
193
+ return mem
194
+ }, {})
195
+
196
+ return res
197
+ }
198
+
132
199
  export function getElementNamespace (el) {
133
200
  let found
134
201
 
package/src/vars.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export const validAttributes = ['placeholder', 'title', 'alt']
2
+ export const ignoreElements = ['SCRIPT']
2
3
  export const colors = {
3
- highlight: '#26a69a',
4
- warning: '#e67a00'
4
+ highlight: '#1976d2',
5
+ warning: '#e67a00',
6
+ gray: '#ccc'
5
7
  }
6
8
 
7
9
  export const getIframeUrl = () => {
@@ -13,6 +15,6 @@ export const getIframeUrl = () => {
13
15
  return env === 'development'
14
16
  ? 'http://localhost:3003/'
15
17
  : env === 'staging'
16
- ? 'https://incontext-dev.locize.app'
17
- : 'https://incontext.locize.app'
18
+ ? 'https://incontext-dev.locize.app'
19
+ : 'https://incontext.locize.app'
18
20
  }
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var postMessage = require('./postMessage.js');
4
-
5
- function handler(payload, e) {
6
- postMessage.api.turnOff();
7
- }
8
- postMessage.api.addHandler('turnOff', handler);
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var postMessage = require('./postMessage.js');
4
-
5
- function handler(payload, e) {
6
- postMessage.api.turnOn();
7
- }
8
- postMessage.api.addHandler('turnOn', handler);
@@ -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);
File without changes
File without changes
File without changes