@fiduswriter/editor 0.1.67 → 0.1.68
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/README.md +141 -5
- package/dist/clipboard/copy/serializers.js +1 -1
- package/dist/clipboard/copy/serializers.js.map +1 -1
- package/dist/comments/store.d.ts.map +1 -1
- package/dist/comments/store.js +1 -2
- package/dist/comments/store.js.map +1 -1
- package/dist/dialogs/contributor.d.ts.map +1 -1
- package/dist/dialogs/contributor.js +2 -2
- package/dist/dialogs/contributor.js.map +1 -1
- package/dist/document_template/exporter.js +2 -2
- package/dist/document_template/exporter.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/editor/index.d.ts +1 -1
- package/dist/plugins/editor/index.d.ts.map +1 -1
- package/dist/plugins/editor/index.js.map +1 -1
- package/dist/static_app.d.ts +72 -0
- package/dist/static_app.d.ts.map +1 -0
- package/dist/static_app.js +234 -0
- package/dist/static_app.js.map +1 -0
- package/dist/static_editor.d.ts +45 -0
- package/dist/static_editor.d.ts.map +1 -0
- package/dist/static_editor.js +118 -0
- package/dist/static_editor.js.map +1 -0
- package/package.json +3 -3
- package/src/clipboard/copy/serializers.ts +1 -1
- package/src/comments/store.ts +1 -2
- package/src/dialogs/contributor.ts +2 -3
- package/src/document_template/exporter.ts +2 -2
- package/src/index.ts +9 -0
- package/src/plugins/editor/index.ts +1 -1
- package/src/static_app.ts +360 -0
- package/src/static_editor.ts +186 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/editor/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/editor/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAM,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/editor/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/editor/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAA6C,EAAE,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { CSL } from "./types.js";
|
|
2
|
+
import type { Image } from "@fiduswriter/image-manager/types";
|
|
3
|
+
import type { EditorApp } from "./types.js";
|
|
4
|
+
export interface StaticDocumentStyle {
|
|
5
|
+
title: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
contents: string;
|
|
8
|
+
documentstylefile_set: Array<[string, string]>;
|
|
9
|
+
}
|
|
10
|
+
export interface StaticExportTemplate {
|
|
11
|
+
title: string;
|
|
12
|
+
file_type: string;
|
|
13
|
+
template_file: string;
|
|
14
|
+
}
|
|
15
|
+
export interface StaticDocumentTemplate {
|
|
16
|
+
title: string;
|
|
17
|
+
}
|
|
18
|
+
export interface StaticAppConfig {
|
|
19
|
+
/** Locale code used by the editor, e.g. "en". */
|
|
20
|
+
locale: string;
|
|
21
|
+
/** gettext function for UI strings. */
|
|
22
|
+
gettext: (msgid: string) => string;
|
|
23
|
+
/** CSL engine instance. */
|
|
24
|
+
csl: CSL;
|
|
25
|
+
/**
|
|
26
|
+
* Function returning the document payload the editor should load.
|
|
27
|
+
* Called whenever the editor refreshes document data from the server.
|
|
28
|
+
*/
|
|
29
|
+
documentData: () => Promise<{
|
|
30
|
+
doc: Record<string, unknown>;
|
|
31
|
+
doc_info: Record<string, unknown>;
|
|
32
|
+
time: number;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Optional callback returning the current document content node.
|
|
36
|
+
* Used by File > Download to extract a template definition from the document.
|
|
37
|
+
*/
|
|
38
|
+
getDocContent?: () => Record<string, unknown> | undefined;
|
|
39
|
+
/** Initial image entries keyed by image id. */
|
|
40
|
+
initialImages?: Record<number, Image>;
|
|
41
|
+
/** Document styles available for the document template. */
|
|
42
|
+
documentStyles?: StaticDocumentStyle[];
|
|
43
|
+
/** Export templates available for the document template. */
|
|
44
|
+
exportTemplates?: StaticExportTemplate[];
|
|
45
|
+
/** Document templates keyed by import id. */
|
|
46
|
+
documentTemplates?: Record<string, StaticDocumentTemplate>;
|
|
47
|
+
/** Optional override for the template API response. */
|
|
48
|
+
getTemplateForDoc?: (docId: string | number, token: string | false) => Promise<Record<string, unknown>>;
|
|
49
|
+
/** Application name. */
|
|
50
|
+
appName?: string;
|
|
51
|
+
/** Routes table used by the app router. */
|
|
52
|
+
routes?: Record<string, {
|
|
53
|
+
app: string;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Optional handler called when the editor tries to save the document.
|
|
57
|
+
* Defaults to a no-op that returns version 0.
|
|
58
|
+
*/
|
|
59
|
+
onSaveDocument?: (data: Record<string, unknown>) => Promise<{
|
|
60
|
+
json: Record<string, unknown>;
|
|
61
|
+
status: number;
|
|
62
|
+
}>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create an {@link EditorApp} for a statically served Fidus Writer editor.
|
|
66
|
+
*
|
|
67
|
+
* This wires up in-memory API connectors so that the editor can run without a
|
|
68
|
+
* backend server. It is used by the standalone demo and can be used by any
|
|
69
|
+
* static deployment of `@fiduswriter/editor`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createStaticApp(config: StaticAppConfig): Promise<EditorApp>;
|
|
72
|
+
//# sourceMappingURL=static_app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static_app.d.ts","sourceRoot":"","sources":["../src/static_app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,E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A6C;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;IAC1D,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,CAChB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,MAAM,GAAG,KAAK,KACpB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACrC,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAC,CAAA;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;QACxD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7B,MAAM,EAAE,MAAM,CAAA;KACjB,CAAC,CAAA;CACL;AAoCD;;;;;;GAMG;AACH,wBAAsB,eAAe,CACjC,MAAM,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,CAAC,CA2OpB"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { BibliographyDB } from "@fiduswriter/bibliography-manager/database";
|
|
2
|
+
import { ImageDB } from "@fiduswriter/image-manager/database";
|
|
3
|
+
import { FW_DOCUMENT_VERSION } from "@fiduswriter/document/schema";
|
|
4
|
+
import { extractTemplate } from "@fiduswriter/document/importer/native/extract_template";
|
|
5
|
+
function fileToDataUrl(file) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const reader = new FileReader();
|
|
8
|
+
reader.onload = () => resolve(String(reader.result));
|
|
9
|
+
reader.onerror = reject;
|
|
10
|
+
reader.readAsDataURL(file);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function getImageDimensions(dataUrl) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const img = new Image();
|
|
16
|
+
img.onload = () => resolve({ width: img.width, height: img.height });
|
|
17
|
+
img.onerror = reject;
|
|
18
|
+
img.src = dataUrl;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create an {@link EditorApp} for a statically served Fidus Writer editor.
|
|
23
|
+
*
|
|
24
|
+
* This wires up in-memory API connectors so that the editor can run without a
|
|
25
|
+
* backend server. It is used by the standalone demo and can be used by any
|
|
26
|
+
* static deployment of `@fiduswriter/editor`.
|
|
27
|
+
*/
|
|
28
|
+
export async function createStaticApp(config) {
|
|
29
|
+
const documentStyles = config.documentStyles || [];
|
|
30
|
+
const exportTemplates = config.exportTemplates || [];
|
|
31
|
+
const documentTemplates = config.documentTemplates || {};
|
|
32
|
+
// In-memory store for images uploaded during this session.
|
|
33
|
+
const sessionImages = {};
|
|
34
|
+
let nextImageId = 1;
|
|
35
|
+
if (config.initialImages) {
|
|
36
|
+
Object.entries(config.initialImages).forEach(([id, image]) => {
|
|
37
|
+
sessionImages[Number(id)] = image;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function storeImage(data, files) {
|
|
41
|
+
const id = data.id ? Number(data.id) : nextImageId++;
|
|
42
|
+
const existing = sessionImages[id];
|
|
43
|
+
const file = files?.image?.file ??
|
|
44
|
+
files?.image ??
|
|
45
|
+
data.image;
|
|
46
|
+
let imageUrl = existing?.image ?? "";
|
|
47
|
+
let fileType = existing?.file_type ?? "png";
|
|
48
|
+
let width = existing?.width ?? 0;
|
|
49
|
+
let height = existing?.height ?? 0;
|
|
50
|
+
if (file) {
|
|
51
|
+
imageUrl = await fileToDataUrl(file);
|
|
52
|
+
fileType =
|
|
53
|
+
data.original_file_type ||
|
|
54
|
+
file.type ||
|
|
55
|
+
"image/png";
|
|
56
|
+
const dimensions = await getImageDimensions(imageUrl);
|
|
57
|
+
width = dimensions.width;
|
|
58
|
+
height = dimensions.height;
|
|
59
|
+
}
|
|
60
|
+
const image = {
|
|
61
|
+
id,
|
|
62
|
+
title: data.title || existing?.title || "",
|
|
63
|
+
file_type: fileType,
|
|
64
|
+
image: imageUrl,
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
added: existing?.added || Date.now(),
|
|
68
|
+
cats: data.cats || existing?.cats || [],
|
|
69
|
+
copyright: data.copyright ||
|
|
70
|
+
existing?.copyright || { freeToRead: true, licenses: [] }
|
|
71
|
+
};
|
|
72
|
+
sessionImages[id] = image;
|
|
73
|
+
return image;
|
|
74
|
+
}
|
|
75
|
+
const defaultGetTemplateForDoc = async () => {
|
|
76
|
+
const docContent = config.getDocContent?.();
|
|
77
|
+
const template = docContent
|
|
78
|
+
? extractTemplate(docContent)
|
|
79
|
+
: null;
|
|
80
|
+
const title = docContent?.attrs?.template ||
|
|
81
|
+
template?.content?.attrs?.template ||
|
|
82
|
+
"";
|
|
83
|
+
return {
|
|
84
|
+
json: {
|
|
85
|
+
id: 1,
|
|
86
|
+
title,
|
|
87
|
+
content: template?.content ?? {},
|
|
88
|
+
doc_version: FW_DOCUMENT_VERSION,
|
|
89
|
+
export_templates: exportTemplates.map(template => ({
|
|
90
|
+
fields: {
|
|
91
|
+
template_file: template.template_file,
|
|
92
|
+
file_type: template.file_type,
|
|
93
|
+
title: template.title
|
|
94
|
+
}
|
|
95
|
+
})),
|
|
96
|
+
document_styles: documentStyles.map(style => ({
|
|
97
|
+
fields: {
|
|
98
|
+
contents: style.contents,
|
|
99
|
+
slug: style.slug,
|
|
100
|
+
title: style.title,
|
|
101
|
+
documentstylefile_set: style.documentstylefile_set
|
|
102
|
+
}
|
|
103
|
+
}))
|
|
104
|
+
},
|
|
105
|
+
status: 200
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const documentApi = {
|
|
109
|
+
createDocument: async () => ({ json: { id: 1 }, status: 200 }),
|
|
110
|
+
getWebSocketBase: async () => ({ json: { ws_base: "" }, status: 200 }),
|
|
111
|
+
getDocumentStyles: async () => ({
|
|
112
|
+
json: {
|
|
113
|
+
export_templates: exportTemplates,
|
|
114
|
+
document_styles: documentStyles,
|
|
115
|
+
document_templates: documentTemplates
|
|
116
|
+
},
|
|
117
|
+
status: 200
|
|
118
|
+
}),
|
|
119
|
+
getDocumentData: async () => {
|
|
120
|
+
const data = await config.documentData();
|
|
121
|
+
return { json: data, status: 200 };
|
|
122
|
+
},
|
|
123
|
+
saveDocument: async (data) => {
|
|
124
|
+
if (config.onSaveDocument) {
|
|
125
|
+
return config.onSaveDocument(data);
|
|
126
|
+
}
|
|
127
|
+
return { json: { version: 0 }, status: 200 };
|
|
128
|
+
},
|
|
129
|
+
commentNotify: async () => Promise.resolve(),
|
|
130
|
+
requestAccess: async () => ({ json: {}, status: 200 }),
|
|
131
|
+
validateShareToken: async () => ({ json: {}, status: 404 }),
|
|
132
|
+
listShareTokens: async () => ({ json: [], status: 200 }),
|
|
133
|
+
createShareToken: async () => ({ json: {}, status: 200 }),
|
|
134
|
+
revokeShareToken: async () => ({ json: {}, status: 200 }),
|
|
135
|
+
getAccessRights: async () => ({ json: {}, status: 200 }),
|
|
136
|
+
saveAccessRights: async () => Promise.resolve(),
|
|
137
|
+
saveE2EEImage: async () => ({ json: {}, status: 200 }),
|
|
138
|
+
deleteE2EEImage: async () => Promise.resolve(),
|
|
139
|
+
uploadRevision: async () => Promise.resolve(),
|
|
140
|
+
getTemplateForDoc: async (id, token) => {
|
|
141
|
+
if (config.getTemplateForDoc) {
|
|
142
|
+
return {
|
|
143
|
+
json: await config.getTemplateForDoc(id, token),
|
|
144
|
+
status: 200
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return defaultGetTemplateForDoc();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const documentImportApi = {
|
|
151
|
+
createDoc: async () => ({ json: { id: 1 }, status: 200 }),
|
|
152
|
+
saveImage: async (data, files) => {
|
|
153
|
+
const image = await storeImage(data, files || {});
|
|
154
|
+
return { json: { id: image.id }, status: 200 };
|
|
155
|
+
},
|
|
156
|
+
saveE2EEImage: async () => ({ json: {}, status: 200 }),
|
|
157
|
+
saveDocument: async (data) => {
|
|
158
|
+
if (config.onSaveDocument) {
|
|
159
|
+
return config.onSaveDocument(data);
|
|
160
|
+
}
|
|
161
|
+
return { json: { version: 0 }, status: 200 };
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const imageApi = {
|
|
165
|
+
getImages: async () => ({
|
|
166
|
+
imageCategories: [],
|
|
167
|
+
images: Object.values(sessionImages)
|
|
168
|
+
}),
|
|
169
|
+
saveImage: async (data, files = {}) => {
|
|
170
|
+
const image = await storeImage(data, files);
|
|
171
|
+
return {
|
|
172
|
+
errormsg: {},
|
|
173
|
+
values: image
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
saveCategories: async () => ({ entries: [] }),
|
|
177
|
+
deleteImages: async (ids) => {
|
|
178
|
+
ids.forEach(id => delete sessionImages[id]);
|
|
179
|
+
return Promise.resolve();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const bibliographyApi = {
|
|
183
|
+
getDB: async () => ({
|
|
184
|
+
bib_categories: [],
|
|
185
|
+
bib_list: [],
|
|
186
|
+
last_modified: -1,
|
|
187
|
+
number_of_entries: 0,
|
|
188
|
+
user_id: 1
|
|
189
|
+
}),
|
|
190
|
+
saveBibEntries: async (tmpDB) => ({
|
|
191
|
+
id_translations: Object.keys(tmpDB).map(tmpId => [
|
|
192
|
+
Number.parseInt(tmpId),
|
|
193
|
+
Number.parseInt(tmpId)
|
|
194
|
+
])
|
|
195
|
+
}),
|
|
196
|
+
saveCategories: async () => ({ entries: [] }),
|
|
197
|
+
deleteCategory: async () => new Response(JSON.stringify({}), { status: 200 }),
|
|
198
|
+
deleteBibEntries: async () => new Response(JSON.stringify({}), { status: 200 })
|
|
199
|
+
};
|
|
200
|
+
const contactsApi = {
|
|
201
|
+
add: async () => ({ json: {}, status: 200 })
|
|
202
|
+
};
|
|
203
|
+
const app = {
|
|
204
|
+
name: config.appName || "fiduswriter-static-editor",
|
|
205
|
+
routes: config.routes || {
|
|
206
|
+
"": { app: "document" },
|
|
207
|
+
document: { app: "document" }
|
|
208
|
+
},
|
|
209
|
+
goTo: () => { },
|
|
210
|
+
isOffline: () => false,
|
|
211
|
+
settings: {
|
|
212
|
+
APPS: [config.appName || "static"],
|
|
213
|
+
EDITOR_SAVE_MODE: "external",
|
|
214
|
+
EDITOR_ONLY_MODE: true,
|
|
215
|
+
E2EE_MODE: "disabled",
|
|
216
|
+
LANGUAGE: config.locale
|
|
217
|
+
},
|
|
218
|
+
csl: config.csl,
|
|
219
|
+
apiConnectors: {
|
|
220
|
+
document: documentApi,
|
|
221
|
+
documentImport: documentImportApi,
|
|
222
|
+
image: imageApi,
|
|
223
|
+
bibliography: bibliographyApi,
|
|
224
|
+
contacts: contactsApi
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const bibDB = new BibliographyDB(app);
|
|
228
|
+
const imageDB = new ImageDB(app);
|
|
229
|
+
imageDB.setImage = (_id, _data) => { };
|
|
230
|
+
app.bibDB = bibDB;
|
|
231
|
+
app.imageDB = imageDB;
|
|
232
|
+
return app;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=static_app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static_app.js","sourceRoot":"","sources":["../src/static_app.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,4CAA4C,CAAA;AAEzE,OAAO,EAAC,OAAO,EAAC,MAAM,qCAAqC,CAAA;AAG3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAC,eAAe,EAAC,MAAM,wDAAwD,CAAA;AAwFtF,SAAS,aAAa,CAAC,IAAU;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAA;QA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QACnD,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI;YACrB,EAAE,EAAE,EAAC,GAAG,EAAE,UAAU,EAAC;YACrB,QAAQ,EAAE,EAAC,GAAG,EAAE,UAAU,EAAC;SAC9B;QACD,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;QACtB,QAAQ,EAAE;YACN,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,QAAQ,CAAC;YAClC,gBAAgB,EAAE,UAAU;YAC5B,gBAAgB,EAAE,IAAI;YACtB,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE,MAAM,CAAC,MAAM;SAC1B;QACD,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,aAAa,EAAE;YACX,QAAQ,EAAE,WAAW;YACrB,cAAc,EAAE,iBAAiB;YACjC,KAAK,EAAE,QAAQ;YACf,YAAY,EAAE,eAAe;YAC7B,QAAQ,EAAE,WAAW;SACxB;KACoB,CAAA;IAEzB,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,GAAU,CAAC,CAAA;IAC5C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAU,CAA6B,CAAA;IACnE,OAAO,CAAC,QAAQ,GAAG,CAAC,GAAW,EAAE,KAA8B,EAAE,EAAE,GAAE,CAAC,CAErE;IAAC,GAAW,CAAC,KAAK,GAAG,KAAK,CAC1B;IAAC,GAAW,CAAC,OAAO,GAAG,OAAO,CAAA;IAE/B,OAAO,GAAG,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CSL, EditorUser } from "./types.js";
|
|
2
|
+
import type { StaticAppConfig } from "./static_app.js";
|
|
3
|
+
import type { Editor } from "./index.js";
|
|
4
|
+
export type { StaticAppConfig } from "./static_app.js";
|
|
5
|
+
export interface StaticEditorConfig extends Omit<StaticAppConfig, "gettext" | "csl"> {
|
|
6
|
+
/** gettext function for UI strings. When omitted, a function backed by `localeCatalog` is used. */
|
|
7
|
+
gettext?: (msgid: string) => string;
|
|
8
|
+
/** CSL engine instance. When omitted, a default engine is created. */
|
|
9
|
+
csl?: CSL;
|
|
10
|
+
/** Display name for the user. Used to build the user object when `user` is not given. */
|
|
11
|
+
username?: string;
|
|
12
|
+
/** Pre-built user object. Takes precedence over `username`. */
|
|
13
|
+
user?: EditorUser;
|
|
14
|
+
/**
|
|
15
|
+
* Base path for resolving static assets.
|
|
16
|
+
* Defaults to the directory containing the current page.
|
|
17
|
+
*/
|
|
18
|
+
staticBasePath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional locale catalog. When omitted, the catalog is fetched from
|
|
21
|
+
* `../locale/{locale}/messages.json` relative to the current page.
|
|
22
|
+
*/
|
|
23
|
+
localeCatalog?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Optional callback for save attempts. Receives the document payload.
|
|
26
|
+
*/
|
|
27
|
+
onSaveDocument?: (data: Record<string, unknown>) => Promise<{
|
|
28
|
+
json: Record<string, unknown>;
|
|
29
|
+
status: number;
|
|
30
|
+
}>;
|
|
31
|
+
/** Optional extra editor plugins. */
|
|
32
|
+
plugins?: Array<[string, Record<string, unknown>]>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create and initialize a statically served Fidus Writer editor.
|
|
36
|
+
*
|
|
37
|
+
* This is the high-level entry point for running `@fiduswriter/editor` without
|
|
38
|
+
* a backend server. It sets up the runtime globals, loads locale strings,
|
|
39
|
+
* creates the static app shell, and initializes the editor.
|
|
40
|
+
*
|
|
41
|
+
* The lower-level {@link Editor} constructor and {@link createStaticApp} are
|
|
42
|
+
* still available for server-backed deployments or advanced customization.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createStaticEditor(config: StaticEditorConfig): Promise<Editor>;
|
|
45
|
+
//# sourceMappingURL=static_editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static_editor.d.ts","sourceRoot":"","sources":["../src/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
|
|
2
|
+
async function loadLocaleCatalog(locale) {
|
|
3
|
+
try {
|
|
4
|
+
const response = await fetch(`../locale/${locale}/messages.json`);
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
return (await response.json());
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function createGettext(catalog) {
|
|
15
|
+
return function gettextImpl(msgid) {
|
|
16
|
+
return catalog[msgid] || msgid;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function defaultStaticUrl(basePath) {
|
|
20
|
+
return (path) => {
|
|
21
|
+
if (path.startsWith("css/editor/")) {
|
|
22
|
+
return `${basePath}css/${path.slice("css/editor/".length)}`;
|
|
23
|
+
}
|
|
24
|
+
if (path === "css/bibliography/bibliography.css") {
|
|
25
|
+
return `${basePath}css/bibliography.css`;
|
|
26
|
+
}
|
|
27
|
+
if (path.startsWith("css/")) {
|
|
28
|
+
return `${basePath}${path}`;
|
|
29
|
+
}
|
|
30
|
+
return `${basePath}static/${path}`;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create and initialize a statically served Fidus Writer editor.
|
|
35
|
+
*
|
|
36
|
+
* This is the high-level entry point for running `@fiduswriter/editor` without
|
|
37
|
+
* a backend server. It sets up the runtime globals, loads locale strings,
|
|
38
|
+
* creates the static app shell, and initializes the editor.
|
|
39
|
+
*
|
|
40
|
+
* The lower-level {@link Editor} constructor and {@link createStaticApp} are
|
|
41
|
+
* still available for server-backed deployments or advanced customization.
|
|
42
|
+
*/
|
|
43
|
+
export async function createStaticEditor(config) {
|
|
44
|
+
// The editor source expects these Fidus Writer runtime helpers as globals.
|
|
45
|
+
// They must be present before any editor module is evaluated, because some
|
|
46
|
+
// editor modules call them at the top level.
|
|
47
|
+
;
|
|
48
|
+
window.gettext = gettext;
|
|
49
|
+
window.interpolate = interpolate;
|
|
50
|
+
window.staticUrl = staticUrl;
|
|
51
|
+
const locale = config.locale || "en";
|
|
52
|
+
const catalog = config.localeCatalog ?? (await loadLocaleCatalog(locale));
|
|
53
|
+
const localeGettext = config.gettext ?? createGettext(catalog);
|
|
54
|
+
const basePath = config.staticBasePath ??
|
|
55
|
+
window.location.pathname.replace(/\/(?:editor\/(?:index\.html)?|index\.html)$/, "/");
|
|
56
|
+
initSettings({
|
|
57
|
+
apiUrl: url => url,
|
|
58
|
+
apiUrlMap: {},
|
|
59
|
+
getCsrfToken: () => "",
|
|
60
|
+
gettext: localeGettext,
|
|
61
|
+
interpolate: (fmt, args, named) => {
|
|
62
|
+
if (named) {
|
|
63
|
+
return fmt.replace(/%\(([^)]+)\)s?/g, (_match, key) => {
|
|
64
|
+
const value = args[key];
|
|
65
|
+
return value !== undefined ? String(value) : "";
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
let index = 0;
|
|
69
|
+
return fmt.replace(/%s/g, () => {
|
|
70
|
+
const value = args[index++];
|
|
71
|
+
return value !== undefined ? String(value) : "";
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
staticUrl: defaultStaticUrl(basePath)
|
|
75
|
+
});
|
|
76
|
+
const username = config.username || "User";
|
|
77
|
+
const user = config.user ??
|
|
78
|
+
{
|
|
79
|
+
id: 1,
|
|
80
|
+
username: username.toLowerCase().replace(/\s+/g, "_") || "user",
|
|
81
|
+
emails: [{ address: "user@example.com", primary: true }],
|
|
82
|
+
name: username,
|
|
83
|
+
is_authenticated: true
|
|
84
|
+
};
|
|
85
|
+
let csl = config.csl;
|
|
86
|
+
if (!csl) {
|
|
87
|
+
const { createCSL } = await import("@fiduswriter/document/citations/create_csl");
|
|
88
|
+
csl = await createCSL();
|
|
89
|
+
// createCSL replaces getStyle/getLocale with versions that only look at
|
|
90
|
+
// pre-registered styles. Restore the prototype methods so the bundled
|
|
91
|
+
// style/locale chunks are loaded dynamically.
|
|
92
|
+
const cslProto = Object.getPrototypeOf(csl);
|
|
93
|
+
csl.getStyle = cslProto.getStyle;
|
|
94
|
+
csl.getLocale = cslProto.getLocale;
|
|
95
|
+
}
|
|
96
|
+
const { createStaticApp } = await import("./static_app.js");
|
|
97
|
+
const app = await createStaticApp({
|
|
98
|
+
...config,
|
|
99
|
+
locale,
|
|
100
|
+
gettext: localeGettext,
|
|
101
|
+
csl,
|
|
102
|
+
onSaveDocument: config.onSaveDocument
|
|
103
|
+
});
|
|
104
|
+
// Prime the user bibliography and image databases so dialogs that read
|
|
105
|
+
// from them see empty but valid stores.
|
|
106
|
+
await Promise.all([
|
|
107
|
+
app.bibDB.getDB(),
|
|
108
|
+
app.imageDB.getDB()
|
|
109
|
+
]);
|
|
110
|
+
const docInfo = (await config.documentData()).doc_info;
|
|
111
|
+
const docId = docInfo?.id ?? 1;
|
|
112
|
+
const docPath = docInfo?.path ?? "";
|
|
113
|
+
const { Editor } = await import("./index.js");
|
|
114
|
+
const editor = new Editor({ app, user }, docPath, String(docId), config.plugins ?? []);
|
|
115
|
+
await editor.init();
|
|
116
|
+
return editor;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=static_editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static_editor.js","sourceRoot":"","sources":["../src/static_editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,WAAW,CAAA;AAwCvE,KAAK,UAAU,iBAAiB,CAC5B,MAAc;IAEd,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,aAAa,MAAM,gBAAgB,CAAC,CAAA;QACjE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACb,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA2B,CAAA;IAC5D,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAA;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MAAM,CAAC,YAAY,CAAC,CAAA;IAE3C,MAAM,MAAM,GAAG,IAAI,MAAM,CACrB,EAAC,GAAG,EAAE,IAAI,EAAC,EACX,OAAO,EACP,MAAM,CAAC,KAAK,CAAC,EACb,MAAM,CAAC,OAAO,IAAK,EAA+C,CACrE,CAAA;IAED,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACnB,OAAO,MAAM,CAAA;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"description": "Fidus Writer browser editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fiduswriter",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"lint:fix": "eslint src --fix",
|
|
84
84
|
"format": "prettier --write .",
|
|
85
85
|
"format:check": "prettier --check .",
|
|
86
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
|
|
86
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js && node test/copy-serializer.js && node test/comment-store.js && node test/import-comments.js && node test/contributor-dialog.js",
|
|
87
87
|
"deploy-pages": "./scripts/deploy-pages.sh",
|
|
88
88
|
"install-hooks": "husky",
|
|
89
89
|
"demo": "echo 'Open demo/editor/index.html or run: npx http-server .pages-build -p 8080 -c-1'",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@fiduswriter/bibliography-manager": "^0.1.28",
|
|
94
|
-
"@fiduswriter/document": "^0.2.
|
|
94
|
+
"@fiduswriter/document": "^0.2.37",
|
|
95
95
|
"@fiduswriter/image-manager": "^0.1.22",
|
|
96
96
|
"@fortawesome/fontawesome-free": "^7.2.0",
|
|
97
97
|
"cropperjs": "^1.6.2",
|
|
@@ -46,8 +46,8 @@ class ClipboardDOMSerializer {
|
|
|
46
46
|
this.editor.app.csl,
|
|
47
47
|
true // synchronous. Should work as the editor has used the same style previously.
|
|
48
48
|
)
|
|
49
|
-
const fm = citRenderer.fm as any
|
|
50
49
|
if (citRenderer.init()) {
|
|
50
|
+
const fm = citRenderer.fm as any
|
|
51
51
|
if (fm.bibHTML.length) {
|
|
52
52
|
const bibDiv = document.createElement("div")
|
|
53
53
|
bibDiv.classList.add("fiduswriter-clipboard-bibliography")
|
package/src/comments/store.ts
CHANGED
|
@@ -100,8 +100,7 @@ export class ModCommentStore {
|
|
|
100
100
|
id: "-1",
|
|
101
101
|
user: (this.mod.editor.user as any).id,
|
|
102
102
|
username,
|
|
103
|
-
date: Date.now() - this.mod.editor.clientTimeAdjustment
|
|
104
|
-
isGlobal: true
|
|
103
|
+
date: Date.now() - this.mod.editor.clientTimeAdjustment
|
|
105
104
|
}),
|
|
106
105
|
inDOM: false,
|
|
107
106
|
view
|
|
@@ -24,7 +24,6 @@ export class ContributorDialog {
|
|
|
24
24
|
this.node = node
|
|
25
25
|
this.view = view
|
|
26
26
|
this.contributor = contributor
|
|
27
|
-
console.log("ContirbutorDialog", {node, view, contributor, idTypes})
|
|
28
27
|
this.idTypes = idTypes
|
|
29
28
|
this.dialog = false
|
|
30
29
|
}
|
|
@@ -32,12 +31,12 @@ export class ContributorDialog {
|
|
|
32
31
|
init(): void {
|
|
33
32
|
const buttons = []
|
|
34
33
|
// Add Update/Add button
|
|
35
|
-
const dialogEl = (this.dialog as InstanceType<typeof Dialog>).dialogEl
|
|
36
|
-
|
|
37
34
|
buttons.push({
|
|
38
35
|
text: this.contributor ? gettext("Update") : gettext("Add"),
|
|
39
36
|
classes: "fw-dark",
|
|
40
37
|
click: () => {
|
|
38
|
+
const dialogEl = (this.dialog as InstanceType<typeof Dialog>)
|
|
39
|
+
.dialogEl
|
|
41
40
|
// Get form values
|
|
42
41
|
let firstname: string | false = (
|
|
43
42
|
dialogEl.querySelector("input[name=firstname]") as
|
|
@@ -77,7 +77,7 @@ export class DocumentTemplateExporter {
|
|
|
77
77
|
file_type: string
|
|
78
78
|
title: string
|
|
79
79
|
}> = []
|
|
80
|
-
data.export_templates.forEach(
|
|
80
|
+
;(data.export_templates || []).forEach(
|
|
81
81
|
(template: {
|
|
82
82
|
fields: {template_file: string; file_type: string; title: string}
|
|
83
83
|
}) => {
|
|
@@ -103,7 +103,7 @@ export class DocumentTemplateExporter {
|
|
|
103
103
|
title: string
|
|
104
104
|
files: string[]
|
|
105
105
|
}> = []
|
|
106
|
-
data.document_styles.forEach(
|
|
106
|
+
;(data.document_styles || []).forEach(
|
|
107
107
|
(docStyle: {
|
|
108
108
|
fields: {
|
|
109
109
|
contents: string
|
package/src/index.ts
CHANGED
|
@@ -1322,3 +1322,12 @@ export type {
|
|
|
1322
1322
|
EditorDocumentImportApi,
|
|
1323
1323
|
EditorContactsApi
|
|
1324
1324
|
} from "./types.js"
|
|
1325
|
+
export {createStaticEditor} from "./static_editor.js"
|
|
1326
|
+
export type {StaticEditorConfig} from "./static_editor.js"
|
|
1327
|
+
export {createStaticApp} from "./static_app.js"
|
|
1328
|
+
export type {
|
|
1329
|
+
StaticAppConfig,
|
|
1330
|
+
StaticDocumentStyle,
|
|
1331
|
+
StaticExportTemplate,
|
|
1332
|
+
StaticDocumentTemplate
|
|
1333
|
+
} from "./static_app.js"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const plugins = []
|
|
1
|
+
export const plugins: Array<[string, Record<string, unknown>]> = []
|