From 0bbde336b3636f4135de54c0ed75c7aa208534fe Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 8 Jan 2022 20:30:01 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20Widget=E3=81=AEcomposition=20?= =?UTF-8?q?api=E7=A7=BB=E8=A1=8C=20(#8125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * wip * wip * wip * wip * wip * wip * fix --- packages/client/src/components/widgets.vue | 79 ++++--- packages/client/src/scripts/form.ts | 30 ++- packages/client/src/widgets/activity.vue | 131 +++++------ packages/client/src/widgets/aichan.vue | 94 ++++---- packages/client/src/widgets/aiscript.vue | 176 ++++++++------- packages/client/src/widgets/button.vue | 151 +++++++------ packages/client/src/widgets/calendar.vue | 148 ++++++------ packages/client/src/widgets/clock.vue | 73 +++--- packages/client/src/widgets/define.ts | 75 ------- packages/client/src/widgets/digital-clock.vue | 123 +++++----- packages/client/src/widgets/federation.vue | 108 +++++---- packages/client/src/widgets/job-queue.vue | 188 ++++++++-------- packages/client/src/widgets/memo.vue | 98 ++++---- packages/client/src/widgets/notifications.vue | 95 ++++---- packages/client/src/widgets/online-users.vue | 80 ++++--- packages/client/src/widgets/photos.vue | 125 ++++++----- packages/client/src/widgets/post-form.vue | 38 ++-- packages/client/src/widgets/rss.vue | 107 +++++---- .../src/widgets/server-metric/index.vue | 123 +++++----- packages/client/src/widgets/slideshow.vue | 210 +++++++++--------- packages/client/src/widgets/timeline.vue | 201 +++++++++-------- packages/client/src/widgets/trends.vue | 86 +++---- packages/client/src/widgets/widget.ts | 71 ++++++ 23 files changed, 1389 insertions(+), 1221 deletions(-) delete mode 100644 packages/client/src/widgets/define.ts create mode 100644 packages/client/src/widgets/widget.ts diff --git a/packages/client/src/components/widgets.vue b/packages/client/src/components/widgets.vue index 12f712925..ccde5fbe5 100644 --- a/packages/client/src/components/widgets.vue +++ b/packages/client/src/components/widgets.vue @@ -10,7 +10,7 @@ {{ $ts.close }} @@ -18,7 +18,7 @@
- +
@@ -28,7 +28,7 @@ diff --git a/packages/client/src/scripts/form.ts b/packages/client/src/scripts/form.ts index 7bf6cec45..7f321cc0a 100644 --- a/packages/client/src/scripts/form.ts +++ b/packages/client/src/scripts/form.ts @@ -21,11 +21,39 @@ export type FormItem = { default: string | null; hidden?: boolean; enum: string[]; +} | { + label?: string; + type: 'radio'; + default: unknown | null; + hidden?: boolean; + options: { + label: string; + value: unknown; + }[]; +} | { + label?: string; + type: 'object'; + default: Record | null; + hidden: true; } | { label?: string; type: 'array'; default: unknown[] | null; - hidden?: boolean; + hidden: true; }; export type Form = Record; + +type GetItemType = + Item['type'] extends 'string' ? string : + Item['type'] extends 'number' ? number : + Item['type'] extends 'boolean' ? boolean : + Item['type'] extends 'radio' ? unknown : + Item['type'] extends 'enum' ? string : + Item['type'] extends 'array' ? unknown[] : + Item['type'] extends 'object' ? Record + : never; + +export type GetFormResultType = { + [P in keyof F]: GetItemType; +}; diff --git a/packages/client/src/widgets/activity.vue b/packages/client/src/widgets/activity.vue index d322f4758..acbbb7a97 100644 --- a/packages/client/src/widgets/activity.vue +++ b/packages/client/src/widgets/activity.vue @@ -1,82 +1,89 @@ - diff --git a/packages/client/src/widgets/aichan.vue b/packages/client/src/widgets/aichan.vue index 891b7454d..03e394b97 100644 --- a/packages/client/src/widgets/aichan.vue +++ b/packages/client/src/widgets/aichan.vue @@ -1,51 +1,65 @@ - diff --git a/packages/client/src/widgets/aiscript.vue b/packages/client/src/widgets/aiscript.vue index 46c5094ee..0a5c0d614 100644 --- a/packages/client/src/widgets/aiscript.vue +++ b/packages/client/src/widgets/aiscript.vue @@ -1,9 +1,9 @@ - diff --git a/packages/client/src/widgets/button.vue b/packages/client/src/widgets/button.vue index e98570862..a33afd6e7 100644 --- a/packages/client/src/widgets/button.vue +++ b/packages/client/src/widgets/button.vue @@ -1,90 +1,99 @@ - diff --git a/packages/client/src/widgets/calendar.vue b/packages/client/src/widgets/calendar.vue index c8b52d7af..d16d3424b 100644 --- a/packages/client/src/widgets/calendar.vue +++ b/packages/client/src/widgets/calendar.vue @@ -1,5 +1,5 @@ - diff --git a/packages/client/src/widgets/clock.vue b/packages/client/src/widgets/clock.vue index 6ca7ecd43..6acb10d74 100644 --- a/packages/client/src/widgets/clock.vue +++ b/packages/client/src/widgets/clock.vue @@ -1,45 +1,56 @@ - diff --git a/packages/client/src/widgets/define.ts b/packages/client/src/widgets/define.ts deleted file mode 100644 index 08a346d97..000000000 --- a/packages/client/src/widgets/define.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { defineComponent } from 'vue'; -import { throttle } from 'throttle-debounce'; -import { Form } from '@/scripts/form'; -import * as os from '@/os'; - -export default function (data: { - name: string; - props?: () => T; -}) { - return defineComponent({ - props: { - widget: { - type: Object, - required: false - }, - settingCallback: { - required: false - } - }, - - emits: ['updateProps'], - - data() { - return { - props: this.widget ? JSON.parse(JSON.stringify(this.widget.data)) : {}, - save: throttle(3000, () => { - this.$emit('updateProps', this.props); - }), - }; - }, - - computed: { - id(): string { - return this.widget ? this.widget.id : null; - }, - }, - - created() { - this.mergeProps(); - - this.$watch('props', () => { - this.mergeProps(); - }, { deep: true }); - - if (this.settingCallback) this.settingCallback(this.setting); - }, - - methods: { - mergeProps() { - if (data.props) { - const defaultProps = data.props(); - for (const prop of Object.keys(defaultProps)) { - if (this.props.hasOwnProperty(prop)) continue; - this.props[prop] = defaultProps[prop].default; - } - } - }, - - async setting() { - const form = data.props(); - for (const item of Object.keys(form)) { - form[item].default = this.props[item]; - } - const { canceled, result } = await os.form(data.name, form); - if (canceled) return; - - for (const key of Object.keys(result)) { - this.props[key] = result[key]; - } - - this.save(); - }, - } - }); -} diff --git a/packages/client/src/widgets/digital-clock.vue b/packages/client/src/widgets/digital-clock.vue index fbf632d2d..637b0368b 100644 --- a/packages/client/src/widgets/digital-clock.vue +++ b/packages/client/src/widgets/digital-clock.vue @@ -1,73 +1,84 @@ - diff --git a/packages/client/src/widgets/federation.vue b/packages/client/src/widgets/federation.vue index 736a91c52..5d53b683b 100644 --- a/packages/client/src/widgets/federation.vue +++ b/packages/client/src/widgets/federation.vue @@ -1,5 +1,5 @@ - diff --git a/packages/client/src/widgets/job-queue.vue b/packages/client/src/widgets/job-queue.vue index 1b7c71de6..4a2a3cf23 100644 --- a/packages/client/src/widgets/job-queue.vue +++ b/packages/client/src/widgets/job-queue.vue @@ -1,134 +1,146 @@ - diff --git a/packages/client/src/widgets/memo.vue b/packages/client/src/widgets/memo.vue index 9b51ada22..3dfc6eb5f 100644 --- a/packages/client/src/widgets/memo.vue +++ b/packages/client/src/widgets/memo.vue @@ -1,5 +1,5 @@ - diff --git a/packages/client/src/widgets/notifications.vue b/packages/client/src/widgets/notifications.vue index 568705b66..8cf29c927 100644 --- a/packages/client/src/widgets/notifications.vue +++ b/packages/client/src/widgets/notifications.vue @@ -1,65 +1,68 @@ - diff --git a/packages/client/src/widgets/online-users.vue b/packages/client/src/widgets/online-users.vue index 5b889f481..2d4768869 100644 --- a/packages/client/src/widgets/online-users.vue +++ b/packages/client/src/widgets/online-users.vue @@ -1,48 +1,60 @@ - diff --git a/packages/client/src/widgets/photos.vue b/packages/client/src/widgets/photos.vue index 7a0b54027..8f948dc64 100644 --- a/packages/client/src/widgets/photos.vue +++ b/packages/client/src/widgets/photos.vue @@ -1,5 +1,5 @@ - diff --git a/packages/client/src/widgets/post-form.vue b/packages/client/src/widgets/post-form.vue index 6de0574cc..51aa8fcf6 100644 --- a/packages/client/src/widgets/post-form.vue +++ b/packages/client/src/widgets/post-form.vue @@ -2,22 +2,34 @@ - diff --git a/packages/client/src/widgets/rss.vue b/packages/client/src/widgets/rss.vue index b2dc77854..aa8205458 100644 --- a/packages/client/src/widgets/rss.vue +++ b/packages/client/src/widgets/rss.vue @@ -1,7 +1,7 @@ - diff --git a/packages/client/src/widgets/server-metric/index.vue b/packages/client/src/widgets/server-metric/index.vue index 107b75090..2caa73fa7 100644 --- a/packages/client/src/widgets/server-metric/index.vue +++ b/packages/client/src/widgets/server-metric/index.vue @@ -1,21 +1,22 @@ - diff --git a/packages/client/src/widgets/slideshow.vue b/packages/client/src/widgets/slideshow.vue index 0909bda67..ac0c6c9e0 100644 --- a/packages/client/src/widgets/slideshow.vue +++ b/packages/client/src/widgets/slideshow.vue @@ -1,126 +1,116 @@ - diff --git a/packages/client/src/widgets/timeline.vue b/packages/client/src/widgets/timeline.vue index aee6a35b1..fa700cc8e 100644 --- a/packages/client/src/widgets/timeline.vue +++ b/packages/client/src/widgets/timeline.vue @@ -1,116 +1,129 @@ - diff --git a/packages/client/src/widgets/trends.vue b/packages/client/src/widgets/trends.vue index ffad93c02..3905daa67 100644 --- a/packages/client/src/widgets/trends.vue +++ b/packages/client/src/widgets/trends.vue @@ -1,5 +1,5 @@ - diff --git a/packages/client/src/widgets/widget.ts b/packages/client/src/widgets/widget.ts new file mode 100644 index 000000000..81239bfb3 --- /dev/null +++ b/packages/client/src/widgets/widget.ts @@ -0,0 +1,71 @@ +import { reactive, watch } from 'vue'; +import { throttle } from 'throttle-debounce'; +import { Form, GetFormResultType } from '@/scripts/form'; +import * as os from '@/os'; + +export type Widget

> = { + id: string; + data: Partial

; +}; + +export type WidgetComponentProps

> = { + widget?: Widget

; +}; + +export type WidgetComponentEmits

> = { + (e: 'updateProps', props: P); +}; + +export type WidgetComponentExpose = { + name: string; + id: string | null; + configure: () => void; +}; + +export const useWidgetPropsManager = >( + name: string, + propsDef: F, + props: Readonly>>, + emit: WidgetComponentEmits>, +): { + widgetProps: GetFormResultType; + save: () => void; + configure: () => void; +} => { + const widgetProps = reactive(props.widget ? JSON.parse(JSON.stringify(props.widget.data)) : {}); + + const mergeProps = () => { + for (const prop of Object.keys(propsDef)) { + if (widgetProps.hasOwnProperty(prop)) continue; + widgetProps[prop] = propsDef[prop].default; + } + }; + watch(widgetProps, () => { + mergeProps(); + }, { deep: true, immediate: true, }); + + const save = throttle(3000, () => { + emit('updateProps', widgetProps) + }); + + const configure = async () => { + const form = JSON.parse(JSON.stringify(propsDef)); + for (const item of Object.keys(form)) { + form[item].default = widgetProps[item]; + } + const { canceled, result } = await os.form(name, form); + if (canceled) return; + + for (const key of Object.keys(result)) { + widgetProps[key] = result[key]; + } + + save(); + }; + + return { + widgetProps, + save, + configure, + }; +}; From d8f3622e166b988840d88dd0be561cdf712c7876 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 9 Jan 2022 00:00:27 +0900 Subject: [PATCH 02/10] fix --- packages/client/src/widgets/rss.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/widgets/rss.vue b/packages/client/src/widgets/rss.vue index aa8205458..7a2272d74 100644 --- a/packages/client/src/widgets/rss.vue +++ b/packages/client/src/widgets/rss.vue @@ -50,7 +50,7 @@ const items = ref([]); const fetching = ref(true); const tick = () => { - fetch(`https://api.rss2json.com/v1/api.json?rss_url=${this.props.url}`, {}).then(res => { + fetch(`https://api.rss2json.com/v1/api.json?rss_url=${widgetProps.url}`, {}).then(res => { res.json().then(feed => { items.value = feed.items; fetching.value = false; From a10be38d0ee0e01e278422d58e2f2df7e20d3c40 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 9 Jan 2022 18:50:03 +0900 Subject: [PATCH 03/10] bye chat ui --- CHANGELOG.md | 1 + packages/client/src/init.ts | 1 - packages/client/src/menu.ts | 7 - .../src/ui/chat/date-separated-list.vue | 157 --- packages/client/src/ui/chat/header-clock.vue | 62 - packages/client/src/ui/chat/index.vue | 463 ------- packages/client/src/ui/chat/note-header.vue | 99 -- packages/client/src/ui/chat/note-preview.vue | 112 -- packages/client/src/ui/chat/note.sub.vue | 137 -- packages/client/src/ui/chat/note.vue | 1143 ----------------- packages/client/src/ui/chat/notes.vue | 94 -- packages/client/src/ui/chat/pages/channel.vue | 259 ---- .../client/src/ui/chat/pages/timeline.vue | 222 ---- packages/client/src/ui/chat/post-form.vue | 770 ----------- packages/client/src/ui/chat/side.vue | 157 --- packages/client/src/ui/chat/store.ts | 17 - .../client/src/ui/chat/sub-note-content.vue | 62 - packages/client/src/ui/chat/widgets.vue | 62 - 18 files changed, 1 insertion(+), 3824 deletions(-) delete mode 100644 packages/client/src/ui/chat/date-separated-list.vue delete mode 100644 packages/client/src/ui/chat/header-clock.vue delete mode 100644 packages/client/src/ui/chat/index.vue delete mode 100644 packages/client/src/ui/chat/note-header.vue delete mode 100644 packages/client/src/ui/chat/note-preview.vue delete mode 100644 packages/client/src/ui/chat/note.sub.vue delete mode 100644 packages/client/src/ui/chat/note.vue delete mode 100644 packages/client/src/ui/chat/notes.vue delete mode 100644 packages/client/src/ui/chat/pages/channel.vue delete mode 100644 packages/client/src/ui/chat/pages/timeline.vue delete mode 100644 packages/client/src/ui/chat/post-form.vue delete mode 100644 packages/client/src/ui/chat/side.vue delete mode 100644 packages/client/src/ui/chat/store.ts delete mode 100644 packages/client/src/ui/chat/sub-note-content.vue delete mode 100644 packages/client/src/ui/chat/widgets.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ab40f76..501e5cad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Changes - Room機能が削除されました - 後日別リポジトリとして復活予定です +- Chat UIが削除されました ### Improvements diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index 2263b4ca3..af70aec70 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -172,7 +172,6 @@ const app = createApp(await ( !$i ? import('@/ui/visitor.vue') : ui === 'deck' ? import('@/ui/deck.vue') : ui === 'desktop' ? import('@/ui/desktop.vue') : - ui === 'chat' ? import('@/ui/chat/index.vue') : ui === 'classic' ? import('@/ui/classic.vue') : import('@/ui/universal.vue') ).then(x => x.default)); diff --git a/packages/client/src/menu.ts b/packages/client/src/menu.ts index ea6f801fe..98a892d56 100644 --- a/packages/client/src/menu.ts +++ b/packages/client/src/menu.ts @@ -198,13 +198,6 @@ export const menuDef = reactive({ localStorage.setItem('ui', 'classic'); unisonReload(); } - }, { - text: 'Chat (β)', - active: ui === 'chat', - action: () => { - localStorage.setItem('ui', 'chat'); - unisonReload(); - } }, /*{ text: i18n.locale.desktop + ' (β)', active: ui === 'desktop', diff --git a/packages/client/src/ui/chat/date-separated-list.vue b/packages/client/src/ui/chat/date-separated-list.vue deleted file mode 100644 index 1a36aca6d..000000000 --- a/packages/client/src/ui/chat/date-separated-list.vue +++ /dev/null @@ -1,157 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/header-clock.vue b/packages/client/src/ui/chat/header-clock.vue deleted file mode 100644 index 3488289c2..000000000 --- a/packages/client/src/ui/chat/header-clock.vue +++ /dev/null @@ -1,62 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/index.vue b/packages/client/src/ui/chat/index.vue deleted file mode 100644 index f66ab4dce..000000000 --- a/packages/client/src/ui/chat/index.vue +++ /dev/null @@ -1,463 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/note-header.vue b/packages/client/src/ui/chat/note-header.vue deleted file mode 100644 index 5f87fdd14..000000000 --- a/packages/client/src/ui/chat/note-header.vue +++ /dev/null @@ -1,99 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/note-preview.vue b/packages/client/src/ui/chat/note-preview.vue deleted file mode 100644 index c28591815..000000000 --- a/packages/client/src/ui/chat/note-preview.vue +++ /dev/null @@ -1,112 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/note.sub.vue b/packages/client/src/ui/chat/note.sub.vue deleted file mode 100644 index b61b7521a..000000000 --- a/packages/client/src/ui/chat/note.sub.vue +++ /dev/null @@ -1,137 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/note.vue b/packages/client/src/ui/chat/note.vue deleted file mode 100644 index fa5faa4ec..000000000 --- a/packages/client/src/ui/chat/note.vue +++ /dev/null @@ -1,1143 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/notes.vue b/packages/client/src/ui/chat/notes.vue deleted file mode 100644 index 51d4afcf5..000000000 --- a/packages/client/src/ui/chat/notes.vue +++ /dev/null @@ -1,94 +0,0 @@ - - - diff --git a/packages/client/src/ui/chat/pages/channel.vue b/packages/client/src/ui/chat/pages/channel.vue deleted file mode 100644 index 2755cc92b..000000000 --- a/packages/client/src/ui/chat/pages/channel.vue +++ /dev/null @@ -1,259 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/pages/timeline.vue b/packages/client/src/ui/chat/pages/timeline.vue deleted file mode 100644 index f67d33339..000000000 --- a/packages/client/src/ui/chat/pages/timeline.vue +++ /dev/null @@ -1,222 +0,0 @@ - - - - - diff --git a/packages/client/src/ui/chat/post-form.vue b/packages/client/src/ui/chat/post-form.vue deleted file mode 100644 index 0f0409665..000000000 --- a/packages/client/src/ui/chat/post-form.vue +++ /dev/null @@ -1,770 +0,0 @@ -