ノーマライズ処理を共通化
This commit is contained in:
parent
be15242bf6
commit
57906fd563
|
@ -124,12 +124,12 @@ function ok() {
|
||||||
|
|
||||||
// 本URL生成用params
|
// 本URL生成用params
|
||||||
const paramsForUrl = computed<EmbedParams>(() => ({
|
const paramsForUrl = computed<EmbedParams>(() => ({
|
||||||
header: header.value === true ? undefined : header.value,
|
header: header.value,
|
||||||
autoload: autoload.value === false ? undefined : autoload.value,
|
autoload: autoload.value,
|
||||||
maxHeight: typeof maxHeight.value === 'number' ? Math.max(0, maxHeight.value) : undefined,
|
maxHeight: typeof maxHeight.value === 'number' ? Math.max(0, maxHeight.value) : undefined,
|
||||||
colorMode: colorMode.value === 'auto' ? undefined : colorMode.value,
|
colorMode: colorMode.value === 'auto' ? undefined : colorMode.value,
|
||||||
rounded: rounded.value === true ? undefined : rounded.value,
|
rounded: rounded.value,
|
||||||
border: border.value === true ? undefined : border.value,
|
border: border.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// プレビュー用params(手動で更新を掛けるのでref)
|
// プレビュー用params(手動で更新を掛けるのでref)
|
||||||
|
@ -142,7 +142,7 @@ const embedPreviewUrl = computed(() => {
|
||||||
const maxHeight = parseInt(paramClass.get('maxHeight')!);
|
const maxHeight = parseInt(paramClass.get('maxHeight')!);
|
||||||
paramClass.set('maxHeight', maxHeight === 0 ? '500' : Math.min(maxHeight, 700).toString()); // プレビューであまりにも縮小されると見づらいため、700pxまでに制限
|
paramClass.set('maxHeight', maxHeight === 0 ? '500' : Math.min(maxHeight, 700).toString()); // プレビューであまりにも縮小されると見づらいため、700pxまでに制限
|
||||||
}
|
}
|
||||||
return `${url}/embed/${props.entity}/${_idOrUsername}?${paramClass.toString()}`;
|
return `${url}/embed/${props.entity}/${_idOrUsername}${paramClass.toString() ? '?' + paramClass.toString() : ''}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const isEmbedWithScrollbar = computed(() => embedRouteWithScrollbar.includes(props.entity));
|
const isEmbedWithScrollbar = computed(() => embedRouteWithScrollbar.includes(props.entity));
|
||||||
|
|
|
@ -35,11 +35,22 @@ export type EmbedParams = {
|
||||||
header?: boolean;
|
header?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// パラメータのデフォルトの値
|
||||||
|
export const defaultEmbedParams: EmbedParams = {
|
||||||
|
maxHeight: undefined,
|
||||||
|
colorMode: undefined,
|
||||||
|
rounded: true,
|
||||||
|
border: true,
|
||||||
|
autoload: false,
|
||||||
|
header: true,
|
||||||
|
};
|
||||||
|
|
||||||
export function normalizeEmbedParams(params: EmbedParams): Record<string, string> {
|
export function normalizeEmbedParams(params: EmbedParams): Record<string, string> {
|
||||||
// paramsのvalueをすべてstringに変換。undefinedやnullはプロパティごと消す
|
// paramsのvalueをすべてstringに変換。undefinedやnullはプロパティごと消す
|
||||||
const normalizedParams: Record<string, string> = {};
|
const normalizedParams: Record<string, string> = {};
|
||||||
for (const key in params) {
|
for (const key in params) {
|
||||||
if (params[key] == null) {
|
// デフォルトの値と同じならparamsに含めない
|
||||||
|
if (params[key] == null || params[key] === defaultEmbedParams[key]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (typeof params[key]) {
|
switch (typeof params[key]) {
|
||||||
|
|
Loading…
Reference in New Issue