FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: reset more global configurations in stories by tbouffard · Pull Request #646 · maxGraph/maxGraph · GitHub

forked from jgraph/mxgraph
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -37,8 +37,9 @@ export class StylesheetCodec extends ObjectCodec {
}

/**
* Static global switch that specifies if the use of eval is allowed for evaluating text content. Default is true.
* Static global switch that specifies if the use of eval is allowed for evaluating text content.
* Set this to `false` if stylesheets may contain user input.
* @default true
*/
static allowEval = true;

Expand Down
21 changes: 21 additions & 0 deletions packages/html/.storybook/preview.ts
This file contains hidden or 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,8 +1,10 @@
import type { Preview } from '@storybook/html';
import {
Client,
CodecRegistry,
GlobalConfig,
NoOpLogger,
ObjectCodec,
resetEdgeHandlerConfig,
resetEntityRelationConnectorConfig,
resetHandleConfig,
Expand All @@ -11,6 +13,8 @@ import {
resetStyleDefaultsConfig,
resetTranslationsConfig,
resetVertexHandlerConfig,
StencilShapeRegistry,
StylesheetCodec,
Translations,
} from '@maxgraph/core';

Expand All @@ -26,6 +30,11 @@ Translations.add(`${Client.basePath}/i18n/graph`, null, (): void => {
defaultLogger.info('[sb-config] i18n resources loaded for Graph');
});

const originalAllowEvalConfig = {
objectCodec: ObjectCodec.allowEval,
stylesheetCodec: StylesheetCodec.allowEval,
};

const resetMaxGraphConfigs = (): void => {
GlobalConfig.logger = defaultLogger;

Expand All @@ -37,6 +46,18 @@ const resetMaxGraphConfigs = (): void => {
resetStyleDefaultsConfig();
resetTranslationsConfig();
resetVertexHandlerConfig();

// Reset registries to remove additional elements registered in a story
// The objects storing the registered elements are currently public, but they should not be part of the public API.
// They will be marked as private in the future and clear functions will probably provide instead.
// Codec resets
CodecRegistry.aliases = {};
CodecRegistry.codecs = {};
ObjectCodec.allowEval = originalAllowEvalConfig.objectCodec;
StylesheetCodec.allowEval = originalAllowEvalConfig.stylesheetCodec;

// The following registries are filled by stories only
StencilShapeRegistry.stencils = {};
};

// This function is a workaround to destroy mxGraph elements that are not released by the previous story.
Expand Down

Back | FazBrowse Home | New Git URL