@brftech/filex-core 0.1.56 → 0.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +108 -108
- package/dist/{ArchiveViewer-CJdaw5x3.js → ArchiveViewer-CbUUEREI.js} +20 -20
- package/dist/ArchiveViewer-CbUUEREI.js.map +1 -0
- package/dist/{CsvViewer-QYx_tePQ.js → CsvViewer-72rDsQJX.js} +3 -3
- package/dist/CsvViewer-72rDsQJX.js.map +1 -0
- package/dist/{DrawioViewer-GWt0TyB7.js → DrawioViewer-DSyMwGvg.js} +7 -7
- package/dist/DrawioViewer-DSyMwGvg.js.map +1 -0
- package/dist/{EpubViewer-Je0ywklQ.js → EpubViewer-DvDa17d7.js} +3 -3
- package/dist/EpubViewer-DvDa17d7.js.map +1 -0
- package/dist/{IpynbViewer-TsB4gqP-.js → IpynbViewer-DibIkdsz.js} +3 -3
- package/dist/IpynbViewer-DibIkdsz.js.map +1 -0
- package/dist/{MermaidViewer-CXfeDS-7.js → MermaidViewer-BoFLtGvl.js} +3 -3
- package/dist/MermaidViewer-BoFLtGvl.js.map +1 -0
- package/dist/{PsdViewer-VtPpxKVe.js → PsdViewer-K2iZkwax.js} +3 -3
- package/dist/PsdViewer-K2iZkwax.js.map +1 -0
- package/dist/{TiffViewer-OINn9bbb.js → TiffViewer-JzDzbqpO.js} +3 -3
- package/dist/TiffViewer-JzDzbqpO.js.map +1 -0
- package/dist/{Viewer3D-xvvyiWHd.js → Viewer3D-WEMYCP8l.js} +7 -7
- package/dist/Viewer3D-WEMYCP8l.js.map +1 -0
- package/dist/filex-core.js +1 -1
- package/dist/filex-core.umd.cjs +4 -4
- package/dist/filex-core.umd.cjs.map +1 -1
- package/dist/{index-CmSYzt6L.js → index-B5YT-m5Q.js} +209 -209
- package/dist/index-B5YT-m5Q.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/useViewerFetch-czqbd2Lj.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Breadcrumb.vue +282 -282
- package/src/components/ContextMenu.vue +152 -152
- package/src/components/GridView.vue +166 -166
- package/src/components/ListView.vue +212 -212
- package/src/components/PendingOpsTray.vue +91 -91
- package/src/components/RecentlyOpened.vue +155 -155
- package/src/components/StarButton.vue +101 -101
- package/src/components/TagPicker.vue +184 -184
- package/src/components/Toolbar.vue +220 -220
- package/src/components/UploadProgress.vue +78 -78
- package/src/composables/useFileApi.ts +692 -692
- package/src/composables/useKeyboardShortcuts.ts +144 -144
- package/src/composables/useLocale.ts +60 -60
- package/src/composables/useMonacoLoader.ts +98 -98
- package/src/composables/usePendingOps.ts +200 -200
- package/src/composables/useSelection.ts +81 -81
- package/src/composables/useUploadChunked.ts +250 -250
- package/src/composables/useViewerFetch.ts +58 -58
- package/src/index.ts +80 -80
- package/src/locales/en.ts +122 -122
- package/src/locales/index.ts +12 -12
- package/src/locales/tr.ts +122 -122
- package/src/modals/DeleteConfirmModal.vue +32 -32
- package/src/modals/Modal.vue +104 -104
- package/src/modals/NewFolderModal.vue +64 -64
- package/src/modals/PermissionsModal.vue +815 -815
- package/src/modals/PreviewModal.vue +1070 -1070
- package/src/modals/RenameModal.vue +58 -58
- package/src/modals/ShareModal.vue +135 -135
- package/src/styles/base.css +1224 -1224
- package/src/styles/variables.css +90 -90
- package/src/types/FileNode.ts +136 -136
- package/src/types/index.ts +27 -27
- package/src/types/peers.d.ts +45 -45
- package/src/viewers/ArchiveViewer.vue +186 -186
- package/src/viewers/CsvViewer.vue +319 -319
- package/src/viewers/DrawioViewer.vue +243 -243
- package/src/viewers/EpubViewer.vue +307 -307
- package/src/viewers/IpynbViewer.vue +365 -365
- package/src/viewers/MermaidViewer.vue +259 -259
- package/src/viewers/PdfViewer.vue +562 -562
- package/src/viewers/PsdViewer.vue +264 -264
- package/src/viewers/TiffViewer.vue +273 -273
- package/src/viewers/Viewer3D.vue +120 -120
- package/dist/ArchiveViewer-CJdaw5x3.js.map +0 -1
- package/dist/CsvViewer-QYx_tePQ.js.map +0 -1
- package/dist/DrawioViewer-GWt0TyB7.js.map +0 -1
- package/dist/EpubViewer-Je0ywklQ.js.map +0 -1
- package/dist/IpynbViewer-TsB4gqP-.js.map +0 -1
- package/dist/MermaidViewer-CXfeDS-7.js.map +0 -1
- package/dist/PsdViewer-VtPpxKVe.js.map +0 -1
- package/dist/TiffViewer-OINn9bbb.js.map +0 -1
- package/dist/Viewer3D-xvvyiWHd.js.map +0 -1
- package/dist/index-CmSYzt6L.js.map +0 -1
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* DrawioViewer — embed diagrams.net via iframe + postMessage handshake.
|
|
4
|
-
*
|
|
5
|
-
* The diagrams.net embed mode (`?embed=1&proto=json`) handshakes via
|
|
6
|
-
* window.postMessage:
|
|
7
|
-
*
|
|
8
|
-
* 1. iframe sends {event:'init'} ← bootstrap
|
|
9
|
-
* 2. parent sends {action:'load', xml} ← our payload
|
|
10
|
-
* 3. iframe sends {event:'save', xml} on save ← we POST back
|
|
11
|
-
*
|
|
12
|
-
* No external library required — diagrams.net hosts the entire editor
|
|
13
|
-
* inside the iframe. We just fetch the source XML on mount and route
|
|
14
|
-
* `save` events back to the configured `pdfSaveUrl`-style endpoint
|
|
15
|
-
* (drawio uses the same shape: POST `{path, content}` body).
|
|
16
|
-
*/
|
|
17
|
-
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
18
|
-
import { fetchViewerText } from '../composables/useViewerFetch';
|
|
19
|
-
|
|
20
|
-
const props = defineProps<{
|
|
21
|
-
url: string;
|
|
22
|
-
filePath: string;
|
|
23
|
-
ext: string;
|
|
24
|
-
drawioUrl?: string;
|
|
25
|
-
/** Optional save endpoint. When unset the iframe stays read-only. */
|
|
26
|
-
saveUrl?: string;
|
|
27
|
-
readOnly?: boolean;
|
|
28
|
-
t?: (key: string) => string;
|
|
29
|
-
authHeaders?: () => Record<string, string>;
|
|
30
|
-
authCredentials?: RequestCredentials;
|
|
31
|
-
}>();
|
|
32
|
-
|
|
33
|
-
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
34
|
-
const error = ref<string | null>(null);
|
|
35
|
-
const status = ref<'loading' | 'ready' | 'saving' | 'saved' | 'error'>('loading');
|
|
36
|
-
const readOnly = ref(!!props.readOnly || !props.saveUrl);
|
|
37
|
-
|
|
38
|
-
// drawioUrl=null is the operator's "off" signal — FileExplorer wipes it
|
|
39
|
-
// when the capabilities probe reports drawio offline. Don't silently fall
|
|
40
|
-
// back to the public embed.diagrams.net iframe, that defeats the point of
|
|
41
|
-
// gating: render a "not configured" pane instead so the user understands
|
|
42
|
-
// why the editor isn't loading.
|
|
43
|
-
//
|
|
44
|
-
// `drawioBase` MUST be a computed (not a const), otherwise a stale null
|
|
45
|
-
// at mount time (capabilities probe still inflight) gets cached for the
|
|
46
|
-
// component's lifetime — leading to the spurious
|
|
47
|
-
// "viewer.drawio.disabled" fallback after the capability flips to "ok".
|
|
48
|
-
const drawioBase = computed<string | null>(() =>
|
|
49
|
-
props.drawioUrl ? props.drawioUrl.replace(/\/$/, '') : null,
|
|
50
|
-
);
|
|
51
|
-
const iframeSrc = computed<string>(() => {
|
|
52
|
-
if (!drawioBase.value) return '';
|
|
53
|
-
const params = new URLSearchParams({
|
|
54
|
-
embed: '1',
|
|
55
|
-
proto: 'json',
|
|
56
|
-
spin: '1',
|
|
57
|
-
saveAndExit: '0',
|
|
58
|
-
noSaveBtn: readOnly.value ? '1' : '0',
|
|
59
|
-
noExitBtn: '1',
|
|
60
|
-
ui: 'kennedy',
|
|
61
|
-
modified: 'unsavedChanges',
|
|
62
|
-
});
|
|
63
|
-
return `${drawioBase.value}/?${params.toString()}`;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
let pendingXml: string = '';
|
|
67
|
-
|
|
68
|
-
async function loadXml(): Promise<void> {
|
|
69
|
-
status.value = 'loading';
|
|
70
|
-
error.value = null;
|
|
71
|
-
try {
|
|
72
|
-
pendingXml = await fetchViewerText({
|
|
73
|
-
url: props.url,
|
|
74
|
-
headers: props.authHeaders?.() ?? {},
|
|
75
|
-
credentials: props.authCredentials,
|
|
76
|
-
});
|
|
77
|
-
} catch (err) {
|
|
78
|
-
error.value = err instanceof Error ? err.message : 'fetch failed';
|
|
79
|
-
status.value = 'error';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function send(msg: unknown): void {
|
|
84
|
-
iframeRef.value?.contentWindow?.postMessage(JSON.stringify(msg), '*');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function persist(xml: string): Promise<void> {
|
|
88
|
-
if (!props.saveUrl) return;
|
|
89
|
-
status.value = 'saving';
|
|
90
|
-
try {
|
|
91
|
-
const headers: Record<string, string> = {
|
|
92
|
-
'Content-Type': 'application/json',
|
|
93
|
-
...(props.authHeaders?.() ?? {}),
|
|
94
|
-
};
|
|
95
|
-
const res = await fetch(props.saveUrl, {
|
|
96
|
-
method: 'POST',
|
|
97
|
-
headers,
|
|
98
|
-
credentials: props.authCredentials || 'same-origin',
|
|
99
|
-
body: JSON.stringify({ path: props.filePath, content: xml }),
|
|
100
|
-
});
|
|
101
|
-
if (!res.ok) {
|
|
102
|
-
throw new Error(`${res.status} ${res.statusText}`);
|
|
103
|
-
}
|
|
104
|
-
status.value = 'saved';
|
|
105
|
-
setTimeout(() => {
|
|
106
|
-
if (status.value === 'saved') status.value = 'ready';
|
|
107
|
-
}, 2500);
|
|
108
|
-
} catch (err) {
|
|
109
|
-
error.value = err instanceof Error ? err.message : 'save failed';
|
|
110
|
-
status.value = 'error';
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function onMessage(ev: MessageEvent): void {
|
|
115
|
-
if (typeof ev.data !== 'string' || ev.data.length === 0) return;
|
|
116
|
-
// Drawio messages always start with '{' or '<'. Ignore anything else
|
|
117
|
-
// (devtools / unrelated postMessage senders inside the same window).
|
|
118
|
-
const first = ev.data[0];
|
|
119
|
-
if (first !== '{' && first !== '<') return;
|
|
120
|
-
let payload: any;
|
|
121
|
-
try {
|
|
122
|
-
payload = JSON.parse(ev.data);
|
|
123
|
-
} catch {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (!payload || typeof payload !== 'object') return;
|
|
127
|
-
switch (payload.event) {
|
|
128
|
-
case 'init':
|
|
129
|
-
send({
|
|
130
|
-
action: 'load',
|
|
131
|
-
xml: pendingXml,
|
|
132
|
-
autosave: 0,
|
|
133
|
-
});
|
|
134
|
-
status.value = 'ready';
|
|
135
|
-
break;
|
|
136
|
-
case 'save':
|
|
137
|
-
if (typeof payload.xml === 'string') {
|
|
138
|
-
persist(payload.xml);
|
|
139
|
-
}
|
|
140
|
-
break;
|
|
141
|
-
case 'export':
|
|
142
|
-
// Could persist a PNG/SVG render; out of V1 scope.
|
|
143
|
-
break;
|
|
144
|
-
case 'autosave':
|
|
145
|
-
if (typeof payload.xml === 'string' && !readOnly.value) {
|
|
146
|
-
persist(payload.xml);
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
default:
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function bootIfReady(): void {
|
|
155
|
-
if (!drawioBase.value) {
|
|
156
|
-
error.value = tt('viewer.drawio.disabled', 'Drawio (diagrams.net) yapılandırılmamış.');
|
|
157
|
-
status.value = 'error';
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
// Clear a previous "disabled" error in case the prop just became
|
|
161
|
-
// available (capability probe finished after mount).
|
|
162
|
-
if (error.value === tt('viewer.drawio.disabled', 'Drawio (diagrams.net) yapılandırılmamış.')) {
|
|
163
|
-
error.value = null;
|
|
164
|
-
status.value = 'loading';
|
|
165
|
-
}
|
|
166
|
-
loadXml();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
onMounted(() => {
|
|
170
|
-
window.addEventListener('message', onMessage);
|
|
171
|
-
bootIfReady();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
watch(() => props.drawioUrl, bootIfReady);
|
|
175
|
-
|
|
176
|
-
onBeforeUnmount(() => {
|
|
177
|
-
window.removeEventListener('message', onMessage);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
function tt(key: string, fallback: string): string {
|
|
181
|
-
return props.t ? props.t(key) : fallback;
|
|
182
|
-
}
|
|
183
|
-
</script>
|
|
184
|
-
|
|
185
|
-
<template>
|
|
186
|
-
<div class="filex-viewer-drawio">
|
|
187
|
-
<div v-if="error" class="filex-viewer-fallback">
|
|
188
|
-
<span class="filex-viewer-fallback__icon">📐</span>
|
|
189
|
-
<p>{{ error }}</p>
|
|
190
|
-
</div>
|
|
191
|
-
<iframe
|
|
192
|
-
v-else
|
|
193
|
-
ref="iframeRef"
|
|
194
|
-
:src="iframeSrc"
|
|
195
|
-
class="filex-viewer-drawio__frame"
|
|
196
|
-
title="diagrams.net editor"
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
</template>
|
|
200
|
-
|
|
201
|
-
<style scoped>
|
|
202
|
-
.filex-viewer-drawio {
|
|
203
|
-
display: flex;
|
|
204
|
-
flex-direction: column;
|
|
205
|
-
width: 100%;
|
|
206
|
-
height: 100%;
|
|
207
|
-
min-height: 70vh;
|
|
208
|
-
background: var(--fe-bg, #fff);
|
|
209
|
-
}
|
|
210
|
-
.filex-viewer-drawio__bar {
|
|
211
|
-
display: flex;
|
|
212
|
-
align-items: center;
|
|
213
|
-
gap: 12px;
|
|
214
|
-
padding: 6px 12px;
|
|
215
|
-
background: var(--fe-bg-elev, #f7f8fa);
|
|
216
|
-
border-bottom: 1px solid var(--fe-border, #e2e6ed);
|
|
217
|
-
font-size: 12px;
|
|
218
|
-
color: var(--fe-text-muted, #5a6475);
|
|
219
|
-
}
|
|
220
|
-
.filex-viewer-drawio__status[data-state="error"] { color: var(--fe-danger, #dc2626); }
|
|
221
|
-
.filex-viewer-drawio__status[data-state="saved"] { color: #059669; }
|
|
222
|
-
.filex-viewer-drawio__readonly {
|
|
223
|
-
font-style: italic;
|
|
224
|
-
margin-left: auto;
|
|
225
|
-
}
|
|
226
|
-
.filex-viewer-drawio__frame {
|
|
227
|
-
flex: 1;
|
|
228
|
-
width: 100%;
|
|
229
|
-
border: 0;
|
|
230
|
-
background: #fafafa;
|
|
231
|
-
min-height: 0;
|
|
232
|
-
}
|
|
233
|
-
.filex-viewer-fallback {
|
|
234
|
-
text-align: center;
|
|
235
|
-
padding: 32px;
|
|
236
|
-
color: var(--fe-text-muted, #5a6475);
|
|
237
|
-
}
|
|
238
|
-
.filex-viewer-fallback__icon {
|
|
239
|
-
font-size: 48px;
|
|
240
|
-
display: block;
|
|
241
|
-
margin-bottom: 12px;
|
|
242
|
-
}
|
|
243
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* DrawioViewer — embed diagrams.net via iframe + postMessage handshake.
|
|
4
|
+
*
|
|
5
|
+
* The diagrams.net embed mode (`?embed=1&proto=json`) handshakes via
|
|
6
|
+
* window.postMessage:
|
|
7
|
+
*
|
|
8
|
+
* 1. iframe sends {event:'init'} ← bootstrap
|
|
9
|
+
* 2. parent sends {action:'load', xml} ← our payload
|
|
10
|
+
* 3. iframe sends {event:'save', xml} on save ← we POST back
|
|
11
|
+
*
|
|
12
|
+
* No external library required — diagrams.net hosts the entire editor
|
|
13
|
+
* inside the iframe. We just fetch the source XML on mount and route
|
|
14
|
+
* `save` events back to the configured `pdfSaveUrl`-style endpoint
|
|
15
|
+
* (drawio uses the same shape: POST `{path, content}` body).
|
|
16
|
+
*/
|
|
17
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
18
|
+
import { fetchViewerText } from '../composables/useViewerFetch';
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{
|
|
21
|
+
url: string;
|
|
22
|
+
filePath: string;
|
|
23
|
+
ext: string;
|
|
24
|
+
drawioUrl?: string;
|
|
25
|
+
/** Optional save endpoint. When unset the iframe stays read-only. */
|
|
26
|
+
saveUrl?: string;
|
|
27
|
+
readOnly?: boolean;
|
|
28
|
+
t?: (key: string) => string;
|
|
29
|
+
authHeaders?: () => Record<string, string>;
|
|
30
|
+
authCredentials?: RequestCredentials;
|
|
31
|
+
}>();
|
|
32
|
+
|
|
33
|
+
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
34
|
+
const error = ref<string | null>(null);
|
|
35
|
+
const status = ref<'loading' | 'ready' | 'saving' | 'saved' | 'error'>('loading');
|
|
36
|
+
const readOnly = ref(!!props.readOnly || !props.saveUrl);
|
|
37
|
+
|
|
38
|
+
// drawioUrl=null is the operator's "off" signal — FileExplorer wipes it
|
|
39
|
+
// when the capabilities probe reports drawio offline. Don't silently fall
|
|
40
|
+
// back to the public embed.diagrams.net iframe, that defeats the point of
|
|
41
|
+
// gating: render a "not configured" pane instead so the user understands
|
|
42
|
+
// why the editor isn't loading.
|
|
43
|
+
//
|
|
44
|
+
// `drawioBase` MUST be a computed (not a const), otherwise a stale null
|
|
45
|
+
// at mount time (capabilities probe still inflight) gets cached for the
|
|
46
|
+
// component's lifetime — leading to the spurious
|
|
47
|
+
// "viewer.drawio.disabled" fallback after the capability flips to "ok".
|
|
48
|
+
const drawioBase = computed<string | null>(() =>
|
|
49
|
+
props.drawioUrl ? props.drawioUrl.replace(/\/$/, '') : null,
|
|
50
|
+
);
|
|
51
|
+
const iframeSrc = computed<string>(() => {
|
|
52
|
+
if (!drawioBase.value) return '';
|
|
53
|
+
const params = new URLSearchParams({
|
|
54
|
+
embed: '1',
|
|
55
|
+
proto: 'json',
|
|
56
|
+
spin: '1',
|
|
57
|
+
saveAndExit: '0',
|
|
58
|
+
noSaveBtn: readOnly.value ? '1' : '0',
|
|
59
|
+
noExitBtn: '1',
|
|
60
|
+
ui: 'kennedy',
|
|
61
|
+
modified: 'unsavedChanges',
|
|
62
|
+
});
|
|
63
|
+
return `${drawioBase.value}/?${params.toString()}`;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
let pendingXml: string = '';
|
|
67
|
+
|
|
68
|
+
async function loadXml(): Promise<void> {
|
|
69
|
+
status.value = 'loading';
|
|
70
|
+
error.value = null;
|
|
71
|
+
try {
|
|
72
|
+
pendingXml = await fetchViewerText({
|
|
73
|
+
url: props.url,
|
|
74
|
+
headers: props.authHeaders?.() ?? {},
|
|
75
|
+
credentials: props.authCredentials,
|
|
76
|
+
});
|
|
77
|
+
} catch (err) {
|
|
78
|
+
error.value = err instanceof Error ? err.message : 'fetch failed';
|
|
79
|
+
status.value = 'error';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function send(msg: unknown): void {
|
|
84
|
+
iframeRef.value?.contentWindow?.postMessage(JSON.stringify(msg), '*');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function persist(xml: string): Promise<void> {
|
|
88
|
+
if (!props.saveUrl) return;
|
|
89
|
+
status.value = 'saving';
|
|
90
|
+
try {
|
|
91
|
+
const headers: Record<string, string> = {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
...(props.authHeaders?.() ?? {}),
|
|
94
|
+
};
|
|
95
|
+
const res = await fetch(props.saveUrl, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers,
|
|
98
|
+
credentials: props.authCredentials || 'same-origin',
|
|
99
|
+
body: JSON.stringify({ path: props.filePath, content: xml }),
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
103
|
+
}
|
|
104
|
+
status.value = 'saved';
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
if (status.value === 'saved') status.value = 'ready';
|
|
107
|
+
}, 2500);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
error.value = err instanceof Error ? err.message : 'save failed';
|
|
110
|
+
status.value = 'error';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function onMessage(ev: MessageEvent): void {
|
|
115
|
+
if (typeof ev.data !== 'string' || ev.data.length === 0) return;
|
|
116
|
+
// Drawio messages always start with '{' or '<'. Ignore anything else
|
|
117
|
+
// (devtools / unrelated postMessage senders inside the same window).
|
|
118
|
+
const first = ev.data[0];
|
|
119
|
+
if (first !== '{' && first !== '<') return;
|
|
120
|
+
let payload: any;
|
|
121
|
+
try {
|
|
122
|
+
payload = JSON.parse(ev.data);
|
|
123
|
+
} catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!payload || typeof payload !== 'object') return;
|
|
127
|
+
switch (payload.event) {
|
|
128
|
+
case 'init':
|
|
129
|
+
send({
|
|
130
|
+
action: 'load',
|
|
131
|
+
xml: pendingXml,
|
|
132
|
+
autosave: 0,
|
|
133
|
+
});
|
|
134
|
+
status.value = 'ready';
|
|
135
|
+
break;
|
|
136
|
+
case 'save':
|
|
137
|
+
if (typeof payload.xml === 'string') {
|
|
138
|
+
persist(payload.xml);
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case 'export':
|
|
142
|
+
// Could persist a PNG/SVG render; out of V1 scope.
|
|
143
|
+
break;
|
|
144
|
+
case 'autosave':
|
|
145
|
+
if (typeof payload.xml === 'string' && !readOnly.value) {
|
|
146
|
+
persist(payload.xml);
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function bootIfReady(): void {
|
|
155
|
+
if (!drawioBase.value) {
|
|
156
|
+
error.value = tt('viewer.drawio.disabled', 'Drawio (diagrams.net) yapılandırılmamış.');
|
|
157
|
+
status.value = 'error';
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Clear a previous "disabled" error in case the prop just became
|
|
161
|
+
// available (capability probe finished after mount).
|
|
162
|
+
if (error.value === tt('viewer.drawio.disabled', 'Drawio (diagrams.net) yapılandırılmamış.')) {
|
|
163
|
+
error.value = null;
|
|
164
|
+
status.value = 'loading';
|
|
165
|
+
}
|
|
166
|
+
loadXml();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
window.addEventListener('message', onMessage);
|
|
171
|
+
bootIfReady();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
watch(() => props.drawioUrl, bootIfReady);
|
|
175
|
+
|
|
176
|
+
onBeforeUnmount(() => {
|
|
177
|
+
window.removeEventListener('message', onMessage);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
function tt(key: string, fallback: string): string {
|
|
181
|
+
return props.t ? props.t(key) : fallback;
|
|
182
|
+
}
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<div class="filex-viewer-drawio">
|
|
187
|
+
<div v-if="error" class="filex-viewer-fallback">
|
|
188
|
+
<span class="filex-viewer-fallback__icon">📐</span>
|
|
189
|
+
<p>{{ error }}</p>
|
|
190
|
+
</div>
|
|
191
|
+
<iframe
|
|
192
|
+
v-else
|
|
193
|
+
ref="iframeRef"
|
|
194
|
+
:src="iframeSrc"
|
|
195
|
+
class="filex-viewer-drawio__frame"
|
|
196
|
+
title="diagrams.net editor"
|
|
197
|
+
/>
|
|
198
|
+
</div>
|
|
199
|
+
</template>
|
|
200
|
+
|
|
201
|
+
<style scoped>
|
|
202
|
+
.filex-viewer-drawio {
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-direction: column;
|
|
205
|
+
width: 100%;
|
|
206
|
+
height: 100%;
|
|
207
|
+
min-height: 70vh;
|
|
208
|
+
background: var(--fe-bg, #fff);
|
|
209
|
+
}
|
|
210
|
+
.filex-viewer-drawio__bar {
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 12px;
|
|
214
|
+
padding: 6px 12px;
|
|
215
|
+
background: var(--fe-bg-elev, #f7f8fa);
|
|
216
|
+
border-bottom: 1px solid var(--fe-border, #e2e6ed);
|
|
217
|
+
font-size: 12px;
|
|
218
|
+
color: var(--fe-text-muted, #5a6475);
|
|
219
|
+
}
|
|
220
|
+
.filex-viewer-drawio__status[data-state="error"] { color: var(--fe-danger, #dc2626); }
|
|
221
|
+
.filex-viewer-drawio__status[data-state="saved"] { color: #059669; }
|
|
222
|
+
.filex-viewer-drawio__readonly {
|
|
223
|
+
font-style: italic;
|
|
224
|
+
margin-left: auto;
|
|
225
|
+
}
|
|
226
|
+
.filex-viewer-drawio__frame {
|
|
227
|
+
flex: 1;
|
|
228
|
+
width: 100%;
|
|
229
|
+
border: 0;
|
|
230
|
+
background: #fafafa;
|
|
231
|
+
min-height: 0;
|
|
232
|
+
}
|
|
233
|
+
.filex-viewer-fallback {
|
|
234
|
+
text-align: center;
|
|
235
|
+
padding: 32px;
|
|
236
|
+
color: var(--fe-text-muted, #5a6475);
|
|
237
|
+
}
|
|
238
|
+
.filex-viewer-fallback__icon {
|
|
239
|
+
font-size: 48px;
|
|
240
|
+
display: block;
|
|
241
|
+
margin-bottom: 12px;
|
|
242
|
+
}
|
|
243
|
+
</style>
|