-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: observer works inside shadowDom (#3163)
- Loading branch information
Showing
14 changed files
with
227 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { buildPackage } from './rollup.common'; | ||
|
||
export default [ | ||
buildPackage({ | ||
input: 'src/entry-development.ts', | ||
name: 'web.development', | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import type { ObserverMiddleware } from '@tolgee/core'; | ||
import type { ObserverMiddleware, ObserverRunProps } from '@tolgee/core'; | ||
import { GeneralObserver } from './observers/general/GeneralObserver'; | ||
import { InvisibleWrapper } from './observers/invisible/InvisibleWrapper'; | ||
|
||
export const InvisibleObserver = | ||
(): ObserverMiddleware => | ||
({ onClick, options }) => { | ||
const wrapper = InvisibleWrapper(); | ||
const observer = GeneralObserver(wrapper, options, onClick); | ||
return { ...observer, retranslate: () => {}, outputNotFormattable: false }; | ||
}; | ||
export const InvisibleObserver = (): ObserverMiddleware => () => { | ||
const observer = GeneralObserver(); | ||
|
||
const self = Object.freeze({ | ||
...observer, | ||
run(props: ObserverRunProps) { | ||
const wrapper = InvisibleWrapper(); | ||
observer.run({ ...props, wrapper }); | ||
}, | ||
retranslate() {}, | ||
outputNotFormattable: false, | ||
}); | ||
return self; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,35 @@ | ||
import type { ObserverMiddleware } from '@tolgee/core'; | ||
import type { ObserverMiddleware, ObserverRunProps } from '@tolgee/core'; | ||
import { GeneralObserver } from './observers/general/GeneralObserver'; | ||
import { setNodeText } from './observers/general/helpers'; | ||
import { TextWrapper } from './observers/text/TextWrapper'; | ||
|
||
export const TextObserver = | ||
(): ObserverMiddleware => | ||
({ translate, onClick, options }) => { | ||
const wrapper = TextWrapper({ | ||
inputPrefix: options.inputPrefix, | ||
inputSuffix: options.inputSuffix, | ||
translate, | ||
}); | ||
const { wrap, unwrap, stop, forEachElement, highlight, run } = | ||
GeneralObserver(wrapper, options, onClick); | ||
export const TextObserver = (): ObserverMiddleware => () => { | ||
const observer = GeneralObserver(); | ||
|
||
const retranslate = () => { | ||
forEachElement((_, elMeta) => { | ||
const self = Object.freeze({ | ||
...observer, | ||
run(props: ObserverRunProps) { | ||
const wrapper = TextWrapper({ | ||
inputPrefix: props.options.inputPrefix, | ||
inputSuffix: props.options.inputSuffix, | ||
translate: props.translate, | ||
}); | ||
observer.run({ ...props, wrapper }); | ||
}, | ||
retranslate() { | ||
observer.forEachElement((_, elMeta) => { | ||
for (const [node, nodeMeta] of elMeta.nodes.entries()) { | ||
if (nodeMeta.keyAttributeOnly) { | ||
return; | ||
} | ||
const result = wrapper.unwrap(nodeMeta.oldTextContent); | ||
const result = observer.unwrap(nodeMeta.oldTextContent); | ||
if (result) { | ||
setNodeText(node, result.text); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
return { | ||
wrap, | ||
unwrap, | ||
stop, | ||
run, | ||
retranslate, | ||
highlight, | ||
outputNotFormattable: true, | ||
}; | ||
}; | ||
}, | ||
outputNotFormattable: true, | ||
}); | ||
return self; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.