mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
fix: Message wrap
This commit is contained in:
@@ -145,7 +145,7 @@ export const addMessage = function (
|
|||||||
from: idFrom,
|
from: idFrom,
|
||||||
to: idTo,
|
to: idTo,
|
||||||
message: message.text,
|
message: message.text,
|
||||||
wrap: (message.wrap === undefined && autoWrap()) ?? !!message.wrap,
|
wrap: message.wrap ?? autoWrap(),
|
||||||
answer: answer,
|
answer: answer,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -178,7 +178,7 @@ export const addSignal = function (
|
|||||||
from: idFrom,
|
from: idFrom,
|
||||||
to: idTo,
|
to: idTo,
|
||||||
message: message?.text ?? '',
|
message: message?.text ?? '',
|
||||||
wrap: (message?.wrap === undefined && autoWrap()) ?? !!message?.wrap,
|
wrap: message?.wrap ?? autoWrap(),
|
||||||
type: messageType,
|
type: messageType,
|
||||||
activate,
|
activate,
|
||||||
});
|
});
|
||||||
@@ -228,13 +228,23 @@ export const setWrap = function (wrapSetting?: boolean) {
|
|||||||
state.records.wrapEnabled = wrapSetting;
|
state.records.wrapEnabled = wrapSetting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractWrap = (text?: string): { cleanedText?: string; wrap?: boolean } => {
|
||||||
|
if (!text) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const wrap =
|
||||||
|
/^:?wrap:/.exec(text) !== null ? true : /^:?nowrap:/.exec(text) !== null ? false : undefined;
|
||||||
|
const cleanedText = (wrap === undefined ? text : text.replace(/^:?(?:no)?wrap:/, '')).trim();
|
||||||
|
return { cleanedText, wrap };
|
||||||
|
};
|
||||||
|
|
||||||
export const autoWrap = () => {
|
export const autoWrap = () => {
|
||||||
// if setWrap has been called, use that value, otherwise use the value from the config
|
// if setWrap has been called, use that value, otherwise use the value from the config
|
||||||
// TODO: refactor, always use the config value let setWrap update the config value
|
// TODO: refactor, always use the config value let setWrap update the config value
|
||||||
if (state.records.wrapEnabled !== undefined) {
|
if (state.records.wrapEnabled !== undefined) {
|
||||||
return state.records.wrapEnabled;
|
return state.records.wrapEnabled;
|
||||||
}
|
}
|
||||||
return getConfig()?.sequence?.wrap;
|
return getConfig().sequence?.wrap ?? false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clear = function () {
|
export const clear = function () {
|
||||||
@@ -244,14 +254,10 @@ export const clear = function () {
|
|||||||
|
|
||||||
export const parseMessage = function (str: string) {
|
export const parseMessage = function (str: string) {
|
||||||
const trimmedStr = str.trim();
|
const trimmedStr = str.trim();
|
||||||
|
const { wrap, cleanedText } = extractWrap(trimmedStr);
|
||||||
const message = {
|
const message = {
|
||||||
text: trimmedStr.replace(/^:?(?:no)?wrap:/, '').trim(),
|
text: cleanedText,
|
||||||
wrap:
|
wrap,
|
||||||
/^:?wrap:/.exec(trimmedStr) !== null
|
|
||||||
? true
|
|
||||||
: /^:?nowrap:/.exec(trimmedStr) !== null
|
|
||||||
? false
|
|
||||||
: undefined,
|
|
||||||
};
|
};
|
||||||
log.debug(`parseMessage: ${JSON.stringify(message)}`);
|
log.debug(`parseMessage: ${JSON.stringify(message)}`);
|
||||||
return message;
|
return message;
|
||||||
@@ -279,21 +285,11 @@ export const parseBoxData = function (str: string) {
|
|||||||
title = str.trim();
|
title = str.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const { wrap, cleanedText } = extractWrap(title);
|
||||||
return {
|
return {
|
||||||
color: color,
|
text: cleanedText ? sanitizeText(cleanedText, getConfig()) : undefined,
|
||||||
text:
|
color,
|
||||||
title !== undefined
|
wrap,
|
||||||
? sanitizeText(title.replace(/^:?(?:no)?wrap:/, ''), getConfig())
|
|
||||||
: undefined,
|
|
||||||
wrap:
|
|
||||||
title !== undefined
|
|
||||||
? /^:?wrap:/.exec(title) !== null
|
|
||||||
? true
|
|
||||||
: /^:?nowrap:/.exec(title) !== null
|
|
||||||
? false
|
|
||||||
: undefined
|
|
||||||
: undefined,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -352,7 +348,7 @@ export const addNote = function (
|
|||||||
actor: actor,
|
actor: actor,
|
||||||
placement: placement,
|
placement: placement,
|
||||||
message: message.text,
|
message: message.text,
|
||||||
wrap: (message.wrap === undefined && autoWrap()) ?? !!message.wrap,
|
wrap: message.wrap ?? autoWrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
//@ts-ignore: Coerce actor into a [to, from, ...] array
|
//@ts-ignore: Coerce actor into a [to, from, ...] array
|
||||||
@@ -363,7 +359,7 @@ export const addNote = function (
|
|||||||
from: actors[0],
|
from: actors[0],
|
||||||
to: actors[1],
|
to: actors[1],
|
||||||
message: message.text,
|
message: message.text,
|
||||||
wrap: (message.wrap === undefined && autoWrap()) ?? !!message.wrap,
|
wrap: message.wrap ?? autoWrap(),
|
||||||
type: LINETYPE.NOTE,
|
type: LINETYPE.NOTE,
|
||||||
placement: placement,
|
placement: placement,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user