mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Sandbox: Fix prismjs syntax for plugins defining its own language (#73393)
* Sandbox: Fix prismjs syntax for plugins defining its own language * Add clarifying comment
This commit is contained in:
parent
040b7d2571
commit
050b9d9a85
@ -1,4 +1,5 @@
|
|||||||
import { isNearMembraneProxy, ProxyTarget } from '@locker/near-membrane-shared';
|
import { isNearMembraneProxy, ProxyTarget } from '@locker/near-membrane-shared';
|
||||||
|
import Prism from 'prismjs';
|
||||||
|
|
||||||
import { DataSourceApi } from '@grafana/data';
|
import { DataSourceApi } from '@grafana/data';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
@ -94,10 +95,16 @@ export function markDomElementStyleAsALiveTarget(el: Element) {
|
|||||||
* but not all objects, only the ones that are allowed to be modified
|
* but not all objects, only the ones that are allowed to be modified
|
||||||
*/
|
*/
|
||||||
export function patchObjectAsLiveTarget(obj: unknown) {
|
export function patchObjectAsLiveTarget(obj: unknown) {
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do not patch it twice
|
||||||
|
if (Object.hasOwn(obj, SANDBOX_LIVE_VALUE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
obj &&
|
|
||||||
// do not define it twice
|
|
||||||
!Object.hasOwn(obj, SANDBOX_LIVE_VALUE) &&
|
|
||||||
// only for proxies
|
// only for proxies
|
||||||
isNearMembraneProxy(obj) &&
|
isNearMembraneProxy(obj) &&
|
||||||
// do not patch functions
|
// do not patch functions
|
||||||
@ -107,6 +114,15 @@ export function patchObjectAsLiveTarget(obj: unknown) {
|
|||||||
(isReactClassComponent(obj) || obj instanceof DataSourceApi)
|
(isReactClassComponent(obj) || obj instanceof DataSourceApi)
|
||||||
) {
|
) {
|
||||||
Reflect.defineProperty(obj, SANDBOX_LIVE_VALUE, {});
|
Reflect.defineProperty(obj, SANDBOX_LIVE_VALUE, {});
|
||||||
|
} else {
|
||||||
|
// prismjs languages are defined by directly modifying the prism.languages objects.
|
||||||
|
// Plugins inside the sandbox can't modify objects from the blue realm and prismjs.languages
|
||||||
|
// is one of them.
|
||||||
|
// Marking it as a live target allows plugins inside the sandbox to modify the object directly
|
||||||
|
// and make syntax work again.
|
||||||
|
if (obj === Prism.languages) {
|
||||||
|
Object.defineProperty(obj, SANDBOX_LIVE_VALUE, {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user