2023-07-27 00:31:52 -05:00
|
|
|
<!--
|
2024-02-13 09:59:27 -06:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
<script lang="ts">
|
2023-01-13 03:25:40 -06:00
|
|
|
import { defineComponent, h, PropType, TransitionGroup, useCssModule } from 'vue';
|
2022-08-30 10:24:33 -05:00
|
|
|
import MkAd from '@/components/global/MkAd.vue';
|
2023-12-24 01:16:58 -06:00
|
|
|
import { isDebuggerEnabled, stackTraceInstances } from '@/debug.js';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2023-12-24 01:16:58 -06:00
|
|
|
import { MisskeyEntity } from '@/types/date-separated-list.js';
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
export default defineComponent({
|
2020-01-29 13:37:25 -06:00
|
|
|
props: {
|
|
|
|
items: {
|
2023-01-13 03:25:40 -06:00
|
|
|
type: Array as PropType<MisskeyEntity[]>,
|
2020-01-29 13:37:25 -06:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
direction: {
|
|
|
|
type: String,
|
2020-02-20 18:11:35 -06:00
|
|
|
required: false,
|
2022-08-30 10:24:33 -05:00
|
|
|
default: 'down',
|
2020-02-05 23:23:01 -06:00
|
|
|
},
|
|
|
|
reversed: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 10:24:33 -05:00
|
|
|
default: false,
|
2021-04-16 10:12:50 -05:00
|
|
|
},
|
|
|
|
noGap: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 10:24:33 -05:00
|
|
|
default: false,
|
2021-04-16 10:12:50 -05:00
|
|
|
},
|
2021-05-04 07:15:57 -05:00
|
|
|
ad: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 10:24:33 -05:00
|
|
|
default: false,
|
2021-05-04 07:15:57 -05:00
|
|
|
},
|
2020-01-29 13:37:25 -06:00
|
|
|
},
|
|
|
|
|
2022-01-10 09:05:18 -06:00
|
|
|
setup(props, { slots, expose }) {
|
2023-06-01 03:19:46 -05:00
|
|
|
const $style = useCssModule(); // カスタムレンダラなので使っても大丈夫
|
2023-10-29 02:09:20 -05:00
|
|
|
|
2024-09-14 22:20:29 -05:00
|
|
|
function getDateText(dateInstance: Date) {
|
|
|
|
const date = dateInstance.getDate();
|
|
|
|
const month = dateInstance.getMonth() + 1;
|
2024-01-19 17:11:59 -06:00
|
|
|
return i18n.tsx.monthAndDay({
|
2020-01-29 13:37:25 -06:00
|
|
|
month: month.toString(),
|
2022-08-30 10:24:33 -05:00
|
|
|
day: date.toString(),
|
2020-01-29 13:37:25 -06:00
|
|
|
});
|
2020-12-11 22:06:26 -06:00
|
|
|
}
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2022-01-10 09:05:18 -06:00
|
|
|
if (props.items.length === 0) return;
|
|
|
|
|
2023-03-08 23:35:38 -06:00
|
|
|
const renderChildrenImpl = () => props.items.map((item, i) => {
|
2022-01-10 09:05:18 -06:00
|
|
|
if (!slots || !slots.default) return;
|
2021-04-15 06:26:02 -05:00
|
|
|
|
2022-01-10 09:05:18 -06:00
|
|
|
const el = slots.default({
|
2022-08-30 10:24:33 -05:00
|
|
|
item: item,
|
2020-12-11 22:06:26 -06:00
|
|
|
})[0];
|
2020-12-30 02:31:59 -06:00
|
|
|
if (el.key == null && item.id) el.key = item.id;
|
2020-12-11 22:06:26 -06:00
|
|
|
|
2024-09-14 22:20:29 -05:00
|
|
|
const date = new Date(item.createdAt);
|
|
|
|
const nextDate = props.items[i + 1] ? new Date(props.items[i + 1].createdAt) : null;
|
|
|
|
|
2020-12-11 22:06:26 -06:00
|
|
|
if (
|
2022-03-01 06:36:20 -06:00
|
|
|
i !== props.items.length - 1 &&
|
2024-09-14 22:20:29 -05:00
|
|
|
nextDate != null && (
|
|
|
|
date.getFullYear() !== nextDate.getFullYear() ||
|
|
|
|
date.getMonth() !== nextDate.getMonth() ||
|
|
|
|
date.getDate() !== nextDate.getDate()
|
|
|
|
)
|
2020-12-11 22:06:26 -06:00
|
|
|
) {
|
|
|
|
const separator = h('div', {
|
2023-01-13 03:25:40 -06:00
|
|
|
class: $style['separator'],
|
2020-12-11 22:06:26 -06:00
|
|
|
key: item.id + ':separator',
|
|
|
|
}, h('p', {
|
2023-01-13 03:25:40 -06:00
|
|
|
class: $style['date'],
|
2020-12-11 22:06:26 -06:00
|
|
|
}, [
|
2023-01-13 03:25:40 -06:00
|
|
|
h('span', {
|
|
|
|
class: $style['date-1'],
|
|
|
|
}, [
|
2021-04-20 09:22:59 -05:00
|
|
|
h('i', {
|
2023-01-13 03:25:40 -06:00
|
|
|
class: `ti ti-chevron-up ${$style['date-1-icon']}`,
|
2020-12-11 22:06:26 -06:00
|
|
|
}),
|
2024-09-14 22:20:29 -05:00
|
|
|
getDateText(date),
|
2020-12-11 22:06:26 -06:00
|
|
|
]),
|
2023-01-13 03:25:40 -06:00
|
|
|
h('span', {
|
|
|
|
class: $style['date-2'],
|
|
|
|
}, [
|
2024-09-14 22:20:29 -05:00
|
|
|
getDateText(nextDate),
|
2021-04-20 09:22:59 -05:00
|
|
|
h('i', {
|
2023-01-13 03:25:40 -06:00
|
|
|
class: `ti ti-chevron-down ${$style['date-2-icon']}`,
|
2022-08-30 10:24:33 -05:00
|
|
|
}),
|
|
|
|
]),
|
2020-12-11 22:06:26 -06:00
|
|
|
]));
|
|
|
|
|
|
|
|
return [el, separator];
|
|
|
|
} else {
|
2022-01-10 09:05:18 -06:00
|
|
|
if (props.ad && item._shouldInsertAd_) {
|
2021-05-04 07:15:57 -05:00
|
|
|
return [h(MkAd, {
|
|
|
|
key: item.id + ':ad',
|
2021-05-05 05:05:19 -05:00
|
|
|
prefer: ['horizontal', 'horizontal-big'],
|
2021-05-04 07:15:57 -05:00
|
|
|
}), el];
|
|
|
|
} else {
|
|
|
|
return el;
|
|
|
|
}
|
2020-12-11 22:06:26 -06:00
|
|
|
}
|
2021-08-10 04:19:59 -05:00
|
|
|
});
|
|
|
|
|
2023-03-08 23:35:38 -06:00
|
|
|
const renderChildren = () => {
|
|
|
|
const children = renderChildrenImpl();
|
|
|
|
if (isDebuggerEnabled(6864)) {
|
|
|
|
const nodes = children.flatMap((node) => node ?? []);
|
|
|
|
const keys = new Set(nodes.map((node) => node.key));
|
|
|
|
if (keys.size !== nodes.length) {
|
|
|
|
const id = crypto.randomUUID();
|
|
|
|
const instances = stackTraceInstances();
|
|
|
|
os.toast(instances.reduce((a, c) => `${a} at ${c.type.name}`, `[DEBUG_6864 (${id})]: ${nodes.length - keys.size} duplicated keys found`));
|
|
|
|
console.warn({ id, debugId: 6864, stack: instances });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return children;
|
|
|
|
};
|
|
|
|
|
2024-01-30 04:53:53 -06:00
|
|
|
function onBeforeLeave(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
2023-01-13 03:25:40 -06:00
|
|
|
el.style.top = `${el.offsetTop}px`;
|
|
|
|
el.style.left = `${el.offsetLeft}px`;
|
|
|
|
}
|
2023-10-29 02:09:20 -05:00
|
|
|
|
2024-01-30 04:53:53 -06:00
|
|
|
function onLeaveCancelled(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
2023-01-13 03:25:40 -06:00
|
|
|
el.style.top = '';
|
|
|
|
el.style.left = '';
|
|
|
|
}
|
|
|
|
|
2024-06-21 22:40:00 -05:00
|
|
|
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
|
2024-01-30 04:53:53 -06:00
|
|
|
const classes = {
|
|
|
|
[$style['date-separated-list']]: true,
|
|
|
|
[$style['date-separated-list-nogap']]: props.noGap,
|
|
|
|
[$style['reversed']]: props.reversed,
|
|
|
|
[$style['direction-down']]: props.direction === 'down',
|
|
|
|
[$style['direction-up']]: props.direction === 'up',
|
|
|
|
};
|
|
|
|
|
|
|
|
return () => defaultStore.state.animation ? h(TransitionGroup, {
|
|
|
|
class: classes,
|
|
|
|
name: 'list',
|
|
|
|
tag: 'div',
|
|
|
|
onBeforeLeave,
|
|
|
|
onLeaveCancelled,
|
|
|
|
}, { default: renderChildren }) : h('div', {
|
|
|
|
class: classes,
|
|
|
|
}, { default: renderChildren });
|
2022-08-30 10:24:33 -05:00
|
|
|
},
|
2020-01-29 13:37:25 -06:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
<style lang="scss" module>
|
|
|
|
.date-separated-list {
|
2022-12-25 17:40:13 -06:00
|
|
|
container-type: inline-size;
|
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
&:global {
|
|
|
|
> .list-move {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.deny-move-transition > .list-move {
|
|
|
|
transition: none !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .list-enter-active {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
2021-05-04 09:12:36 -05:00
|
|
|
> *:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2023-07-31 00:54:30 -05:00
|
|
|
}
|
2021-05-04 09:12:36 -05:00
|
|
|
|
2023-07-31 00:54:30 -05:00
|
|
|
&:not(.date-separated-list-nogap) > *:not(:last-child) {
|
2024-10-10 02:12:16 -05:00
|
|
|
margin-bottom: var(--MI-margin);
|
2020-07-04 07:07:45 -05:00
|
|
|
}
|
2023-01-13 03:25:40 -06:00
|
|
|
}
|
2020-02-20 18:11:35 -06:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.date-separated-list-nogap {
|
|
|
|
> * {
|
|
|
|
margin: 0 !important;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
2020-03-20 04:55:15 -05:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
&:not(:last-child) {
|
2024-10-09 04:08:14 -05:00
|
|
|
border-bottom: solid 0.5px var(--MI_THEME-divider);
|
2020-02-20 18:11:35 -06:00
|
|
|
}
|
|
|
|
}
|
2023-01-13 03:25:40 -06:00
|
|
|
}
|
2020-02-20 18:11:35 -06:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.direction-up {
|
|
|
|
&:global {
|
|
|
|
> .list-enter-from,
|
|
|
|
> .list-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.direction-down {
|
|
|
|
&:global {
|
|
|
|
> .list-enter-from,
|
|
|
|
> .list-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-64px);
|
|
|
|
}
|
2020-02-20 18:11:35 -06:00
|
|
|
}
|
2023-01-13 03:25:40 -06:00
|
|
|
}
|
2020-02-20 18:11:35 -06:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.reversed {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column-reverse;
|
|
|
|
}
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.separator {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.date {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
line-height: 32px;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
2024-10-09 04:08:14 -05:00
|
|
|
color: var(--MI_THEME-dateLabelFg);
|
2023-01-13 03:25:40 -06:00
|
|
|
}
|
2021-04-09 22:40:50 -05:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.date-1 {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
2021-04-09 22:40:50 -05:00
|
|
|
|
2023-01-13 03:25:40 -06:00
|
|
|
.date-1-icon {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.date-2 {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.date-2-icon {
|
|
|
|
margin-left: 8px;
|
2021-04-09 22:40:50 -05:00
|
|
|
}
|
2020-01-29 13:37:25 -06:00
|
|
|
</style>
|
2023-01-13 03:25:40 -06:00
|
|
|
|