|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { logger } from '../helpers/logger.js' |
7 | | -import { provide, inject, ref, computed } from 'vue' |
8 | | -import type { InjectionKey, Ref, ShallowReactive } from 'vue' |
9 | | -import { isPublicShare } from '@nextcloud/sharing/public' |
10 | | -import { loadState } from '@nextcloud/initial-state' |
11 | | - |
12 | | -export interface EditorFlags { |
13 | | - isPublic: Ref<boolean> |
14 | | - isRichEditor: Ref<boolean> |
15 | | - isRichWorkspace: Ref<boolean> |
16 | | -} |
17 | | -interface Props { |
18 | | - isDirectEditing: boolean |
19 | | - richWorkspace: boolean |
20 | | - mime: string |
21 | | -} |
22 | | -export const editorFlagsKey = Symbol('editor:flags') as InjectionKey<EditorFlags> |
23 | | -export const provideEditorFlags = (props: ShallowReactive<Props>) => { |
24 | | - const isPublic = computed(() => props.isDirectEditing || isPublicShare()) |
25 | | - const isRichWorkspace = computed(() => props.richWorkspace) |
26 | | - const isRichEditor = computed( |
27 | | - () => |
28 | | - loadState('text', 'rich_editing_enabled', true) |
29 | | - && props.mime === 'text/markdown', |
30 | | - ) |
31 | | - provide(editorFlagsKey, { isPublic, isRichEditor, isRichWorkspace }) |
32 | | - return { isPublic, isRichEditor, isRichWorkspace } |
33 | | -} |
34 | | -export const useEditorFlags = () => { |
35 | | - const { isPublic, isRichEditor, isRichWorkspace } = inject(editorFlagsKey, { |
36 | | - isPublic: ref(false), |
37 | | - isRichEditor: ref(false), |
38 | | - isRichWorkspace: ref(false), |
39 | | - }) |
40 | | - return { isPublic, isRichEditor, isRichWorkspace } |
41 | | -} |
42 | 7 |
|
43 | 8 | export const FILE = Symbol('editor:file') |
44 | 9 | export const ATTACHMENT_RESOLVER = Symbol('attachment:resolver') |
|
0 commit comments