@fiduswriter/frontend 0.1.66 → 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 +7 -0
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +2 -1
- package/dist/app/index.js.map +1 -1
- package/dist/css/document-template-editor/document_template_designer.css +68 -68
- package/dist/css/image-manager/dialog_usermedia.css +41 -41
- package/dist/user/auth/login.d.ts.map +1 -1
- package/dist/user/auth/login.js +2 -1
- package/dist/user/auth/login.js.map +1 -1
- package/dist/user/auth/signup.d.ts +3 -1
- package/dist/user/auth/signup.d.ts.map +1 -1
- package/dist/user/auth/signup.js +30 -1
- package/dist/user/auth/signup.js.map +1 -1
- package/dist/user/auth/social_icons.d.ts +2 -0
- package/dist/user/auth/social_icons.d.ts.map +1 -0
- package/dist/user/auth/social_icons.js +11 -0
- package/dist/user/auth/social_icons.js.map +1 -0
- package/dist/workers/adjust_doc_to_template.d.ts.map +1 -1
- package/dist/workers/adjust_doc_to_template.js +13 -6
- package/dist/workers/adjust_doc_to_template.js.map +1 -1
- package/locale/ar/messages.json +371 -357
- package/locale/bg/messages.json +371 -357
- package/locale/cs/messages.json +371 -357
- package/locale/da/messages.json +371 -357
- package/locale/de/messages.json +371 -357
- package/locale/en/messages.json +371 -357
- package/locale/en_US/messages.json +371 -357
- package/locale/es/messages.json +371 -357
- package/locale/fr/messages.json +371 -357
- package/locale/it/messages.json +371 -357
- package/locale/ja/messages.json +371 -357
- package/locale/ko/messages.json +371 -357
- package/locale/nb/messages.json +371 -357
- package/locale/nl/messages.json +371 -357
- package/locale/pl/messages.json +371 -357
- package/locale/pt_BR/messages.json +371 -357
- package/locale/pt_PT/messages.json +371 -357
- package/locale/ru/messages.json +371 -357
- package/locale/sv/messages.json +371 -357
- package/locale/tr/messages.json +371 -357
- package/locale/zh_Hans/messages.json +371 -357
- package/package.json +4 -4
- package/scripts/extract-i18n-generic.js +182 -139
- package/src/app/index.ts +3 -1
- package/src/user/auth/login.ts +2 -1
- package/src/user/auth/signup.ts +50 -1
- package/src/user/auth/social_icons.ts +10 -0
- package/src/workers/adjust_doc_to_template.ts +18 -12
- package/scripts/extract-fwtoolkit-i18n.js +0 -230
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/frontend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"description": "Fidus Writer-specific shared utilities and UI chrome",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fiduswriter",
|
|
@@ -237,9 +237,9 @@
|
|
|
237
237
|
"@types/qrcode": "^1.5.6",
|
|
238
238
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
239
239
|
"eslint": "^10.6.0",
|
|
240
|
-
"gettext-parser": "^
|
|
241
|
-
"globals": "^
|
|
242
|
-
"happy-dom": "^
|
|
240
|
+
"gettext-parser": "^10.0.0",
|
|
241
|
+
"globals": "^17.0.0",
|
|
242
|
+
"happy-dom": "^21.0.0",
|
|
243
243
|
"husky": "^9.1.7",
|
|
244
244
|
"jest": "^30.5.2",
|
|
245
245
|
"lint-staged": "^17.0.8",
|
|
@@ -7,13 +7,25 @@
|
|
|
7
7
|
* translations from a Django djangojs.po file (including obsolete #~ entries),
|
|
8
8
|
* and writes per-language messages.po into locale/.
|
|
9
9
|
*
|
|
10
|
+
* Translations already present in the target messages.po files are preserved,
|
|
11
|
+
* so re-running extraction never loses work done by translate_all.py or by
|
|
12
|
+
* human translators. All .po parsing handles msgids and msgstrs wrapped over
|
|
13
|
+
* multiple lines (polib and msgcat wrap long lines when saving) — a naive
|
|
14
|
+
* line-based parser silently drops every translation long enough to wrap.
|
|
15
|
+
*
|
|
10
16
|
* Usage:
|
|
11
17
|
* node scripts/extract-i18n.js <path-to-django-locale>
|
|
12
18
|
*/
|
|
13
19
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
import {
|
|
21
|
+
readFileSync,
|
|
22
|
+
writeFileSync,
|
|
23
|
+
mkdirSync,
|
|
24
|
+
readdirSync,
|
|
25
|
+
existsSync
|
|
26
|
+
} from "node:fs"
|
|
27
|
+
import {join, dirname} from "node:path"
|
|
28
|
+
import {fileURLToPath} from "node:url"
|
|
17
29
|
|
|
18
30
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
19
31
|
const root = join(__dirname, "..")
|
|
@@ -30,11 +42,20 @@ const msgids = new Set()
|
|
|
30
42
|
|
|
31
43
|
function scanDir(dir) {
|
|
32
44
|
if (!existsSync(dir)) return
|
|
33
|
-
for (const entry of readdirSync(dir, {
|
|
45
|
+
for (const entry of readdirSync(dir, {withFileTypes: true})) {
|
|
34
46
|
const full = join(dir, entry.name)
|
|
35
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
entry.isDirectory() &&
|
|
49
|
+
entry.name !== "node_modules" &&
|
|
50
|
+
!entry.name.startsWith(".")
|
|
51
|
+
) {
|
|
36
52
|
scanDir(full)
|
|
37
|
-
} else if (
|
|
53
|
+
} else if (
|
|
54
|
+
entry.isFile() &&
|
|
55
|
+
(entry.name.endsWith(".ts") ||
|
|
56
|
+
entry.name.endsWith(".js") ||
|
|
57
|
+
entry.name.endsWith(".mjs"))
|
|
58
|
+
) {
|
|
38
59
|
const content = readFileSync(full, "utf8")
|
|
39
60
|
let match
|
|
40
61
|
while ((match = GETTEXT_RE.exec(content)) !== null) {
|
|
@@ -53,183 +74,185 @@ if (msgids.size === 0) {
|
|
|
53
74
|
process.exit(0)
|
|
54
75
|
}
|
|
55
76
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Parse the active (non-obsolete) entries of a .po file into a Map of
|
|
79
|
+
* msgid → {msgstr, comment}. Handles msgids and msgstrs wrapped over
|
|
80
|
+
* multiple lines. Entries with an empty msgstr and plural entries are
|
|
81
|
+
* skipped.
|
|
82
|
+
*/
|
|
83
|
+
function parsePoEntries(content) {
|
|
84
|
+
const entries = new Map()
|
|
85
|
+
let msgid = null
|
|
86
|
+
let msgstr = ""
|
|
87
|
+
let comment = ""
|
|
88
|
+
let pendingComment = ""
|
|
89
|
+
let mode = null // null | "msgid" | "msgstr"
|
|
68
90
|
|
|
69
|
-
const
|
|
70
|
-
|
|
91
|
+
const flush = () => {
|
|
92
|
+
if (msgid && msgstr) {
|
|
93
|
+
entries.set(msgid, {msgstr, comment: comment.trim()})
|
|
94
|
+
}
|
|
95
|
+
msgid = null
|
|
96
|
+
msgstr = ""
|
|
97
|
+
comment = ""
|
|
98
|
+
mode = null
|
|
99
|
+
}
|
|
71
100
|
|
|
72
|
-
|
|
73
|
-
let currentMsgid = null
|
|
74
|
-
let currentComment = ""
|
|
75
|
-
for (const line of poContent.split("\n")) {
|
|
101
|
+
for (const line of content.split("\n")) {
|
|
76
102
|
const trimmed = line.trim()
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (trimmed.startsWith("#:")) {
|
|
81
|
-
if (currentMsgid === null) currentComment += line + "\n"
|
|
103
|
+
if (trimmed === "") {
|
|
104
|
+
flush()
|
|
105
|
+
pendingComment = ""
|
|
82
106
|
continue
|
|
83
107
|
}
|
|
84
|
-
if (trimmed.startsWith("
|
|
85
|
-
|
|
108
|
+
if (trimmed.startsWith("#~")) {
|
|
109
|
+
// Obsolete entries are handled by parseObsoleteEntries().
|
|
86
110
|
continue
|
|
87
111
|
}
|
|
88
|
-
if (trimmed.startsWith("#")
|
|
89
|
-
|
|
90
|
-
currentMsgid = unescapePo(trimmed.slice(7, -1))
|
|
112
|
+
if (trimmed.startsWith("#")) {
|
|
113
|
+
if (msgid === null) pendingComment += line + "\n"
|
|
91
114
|
continue
|
|
92
115
|
}
|
|
93
116
|
if (trimmed.startsWith("msgid ")) {
|
|
94
|
-
|
|
117
|
+
flush()
|
|
118
|
+
comment = pendingComment
|
|
119
|
+
pendingComment = ""
|
|
120
|
+
mode = "msgid"
|
|
121
|
+
msgid = unescapePo(stripQuotes(trimmed.slice(6)))
|
|
95
122
|
continue
|
|
96
123
|
}
|
|
97
|
-
if (trimmed.startsWith(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
currentMsgid = null
|
|
101
|
-
currentComment = ""
|
|
102
|
-
continue
|
|
103
|
-
}
|
|
104
|
-
if (trimmed.startsWith("msgstr ") && currentMsgid !== null) {
|
|
105
|
-
const msgstr = unescapePo(trimmed.slice(7))
|
|
106
|
-
if (msgstr) translationMap.set(currentMsgid, { msgstr, comment: currentComment.trim() })
|
|
107
|
-
currentMsgid = null
|
|
108
|
-
currentComment = ""
|
|
124
|
+
if (trimmed.startsWith("msgid_plural") || trimmed.startsWith("msgstr[")) {
|
|
125
|
+
msgid = null
|
|
126
|
+
mode = null
|
|
109
127
|
continue
|
|
110
128
|
}
|
|
111
|
-
if (trimmed.startsWith("
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
if (trimmed.startsWith("msgstr ")) {
|
|
130
|
+
if (msgid === null) continue
|
|
131
|
+
mode = "msgstr"
|
|
132
|
+
msgstr = unescapePo(stripQuotes(trimmed.slice(7)))
|
|
114
133
|
continue
|
|
115
134
|
}
|
|
116
|
-
if (trimmed.startsWith('"')
|
|
117
|
-
|
|
135
|
+
if (trimmed.startsWith('"')) {
|
|
136
|
+
const fragment = unescapePo(stripQuotes(trimmed))
|
|
137
|
+
if (mode === "msgid") {
|
|
138
|
+
msgid += fragment
|
|
139
|
+
} else if (mode === "msgstr") {
|
|
140
|
+
msgstr += fragment
|
|
141
|
+
}
|
|
118
142
|
}
|
|
119
143
|
}
|
|
144
|
+
flush()
|
|
145
|
+
return entries
|
|
146
|
+
}
|
|
120
147
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Parse the obsolete (#~) entries of a .po file into a Map of
|
|
150
|
+
* msgid → {msgstr, comment}. These often still hold the translation of a
|
|
151
|
+
* string that was reworded slightly, so they seed new msgids as well.
|
|
152
|
+
*/
|
|
153
|
+
function parseObsoleteEntries(content) {
|
|
154
|
+
const entries = new Map()
|
|
155
|
+
let state = null // null | "msgid" | "msgstr"
|
|
156
|
+
let msgid = ""
|
|
157
|
+
let msgstr = ""
|
|
158
|
+
let prevMsgid = null
|
|
127
159
|
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
|
|
160
|
+
const flush = () => {
|
|
161
|
+
if (msgid && msgstr && !entries.has(msgid)) {
|
|
162
|
+
entries.set(msgid, {msgstr, comment: ""})
|
|
131
163
|
}
|
|
132
|
-
if (
|
|
133
|
-
|
|
164
|
+
if (prevMsgid && msgstr && !entries.has(prevMsgid)) {
|
|
165
|
+
entries.set(prevMsgid, {msgstr, comment: ""})
|
|
134
166
|
}
|
|
167
|
+
state = null
|
|
168
|
+
msgid = ""
|
|
169
|
+
msgstr = ""
|
|
170
|
+
prevMsgid = null
|
|
135
171
|
}
|
|
136
172
|
|
|
137
|
-
for (const line of
|
|
173
|
+
for (const line of content.split("\n")) {
|
|
138
174
|
const trimmed = line.trim()
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
obsState = "msgid"
|
|
144
|
-
obsMsgid = unescapePo(trimmed.slice(10, -1))
|
|
145
|
-
obsMsgstr = ""
|
|
146
|
-
obsPrevMsgid = null
|
|
175
|
+
if (trimmed.startsWith('#~ msgid "') || trimmed.startsWith("#~ msgid ")) {
|
|
176
|
+
flush()
|
|
177
|
+
state = "msgid"
|
|
178
|
+
msgid = unescapePo(stripQuotes(trimmed.slice(9)))
|
|
147
179
|
continue
|
|
148
180
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
saveObsolete()
|
|
152
|
-
obsState = "msgid"
|
|
153
|
-
obsMsgid = unescapePo(trimmed.slice(9))
|
|
154
|
-
obsMsgstr = ""
|
|
155
|
-
obsPrevMsgid = null
|
|
181
|
+
if (trimmed.startsWith('#~| msgid "') || trimmed.startsWith("#~| msgid ")) {
|
|
182
|
+
prevMsgid = unescapePo(stripQuotes(trimmed.slice(11)))
|
|
156
183
|
continue
|
|
157
184
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
if (
|
|
186
|
+
state === "msgid" &&
|
|
187
|
+
(trimmed.startsWith('#~ msgstr "') || trimmed.startsWith("#~ msgstr "))
|
|
188
|
+
) {
|
|
189
|
+
state = "msgstr"
|
|
190
|
+
msgstr = unescapePo(stripQuotes(trimmed.slice(11)))
|
|
161
191
|
continue
|
|
162
192
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
if (trimmed.startsWith("#~ msgstr ") && obsState === "msgid" && !trimmed.startsWith('#~ msgstr "')) {
|
|
171
|
-
obsState = "msgstr"
|
|
172
|
-
obsMsgstr = unescapePo(trimmed.slice(10))
|
|
173
|
-
continue
|
|
174
|
-
}
|
|
175
|
-
// ----------- multi-line continuation -----------
|
|
176
|
-
if (trimmed.startsWith('#~ "') && obsState !== null) {
|
|
177
|
-
const fragment = unescapePo(trimmed.slice(4, -1))
|
|
178
|
-
if (obsState === "msgid") {
|
|
179
|
-
obsMsgid += fragment
|
|
180
|
-
} else if (obsState === "msgstr") {
|
|
181
|
-
obsMsgstr += fragment
|
|
193
|
+
if (trimmed.startsWith('#~ "') && state !== null) {
|
|
194
|
+
const fragment = unescapePo(stripQuotes(trimmed.slice(4)))
|
|
195
|
+
if (state === "msgid") {
|
|
196
|
+
msgid += fragment
|
|
197
|
+
} else {
|
|
198
|
+
msgstr += fragment
|
|
182
199
|
}
|
|
183
200
|
continue
|
|
184
201
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
saveObsolete()
|
|
188
|
-
obsState = null
|
|
189
|
-
obsMsgid = ""
|
|
190
|
-
obsMsgstr = ""
|
|
202
|
+
if (state === "msgstr" && !trimmed.startsWith("#~")) {
|
|
203
|
+
flush()
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
206
|
+
flush()
|
|
207
|
+
return entries
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Build translation maps from djangojs.po — including obsolete #~ entries
|
|
211
|
+
const languages = readdirSync(djangoLocalePath, {withFileTypes: true})
|
|
212
|
+
.filter(e => e.isDirectory())
|
|
213
|
+
.map(e => e.name)
|
|
214
|
+
|
|
215
|
+
console.log(
|
|
216
|
+
`Looking up translations in ${languages.length} languages (including obsolete entries)...`
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
let totalTranslated = 0
|
|
220
|
+
|
|
221
|
+
for (const lang of languages) {
|
|
222
|
+
const poFile = join(djangoLocalePath, lang, "LC_MESSAGES", "djangojs.po")
|
|
223
|
+
if (!existsSync(poFile)) continue
|
|
224
|
+
|
|
225
|
+
const poContent = readFileSync(poFile, "utf8")
|
|
226
|
+
const translationMap = parsePoEntries(poContent)
|
|
227
|
+
for (const [key, value] of parseObsoleteEntries(poContent)) {
|
|
228
|
+
if (!translationMap.has(key)) translationMap.set(key, value)
|
|
196
229
|
}
|
|
197
230
|
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
231
|
+
// Merge existing translations from the target .po file so translations
|
|
232
|
+
// added by translate_all.py or manual editing are preserved across
|
|
233
|
+
// re-extractions.
|
|
201
234
|
const existingPo = join(root, "locale", lang, "LC_MESSAGES", "messages.po")
|
|
202
235
|
const existingTranslations = new Map()
|
|
203
236
|
if (existsSync(existingPo)) {
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (trimmed.startsWith('msgid "')) {
|
|
209
|
-
curMsgid = unescapePo(trimmed.slice(7, -1))
|
|
210
|
-
continue
|
|
211
|
-
}
|
|
212
|
-
if (trimmed.startsWith('msgstr "') && curMsgid !== null) {
|
|
213
|
-
const ms = unescapePo(trimmed.slice(8, -1))
|
|
214
|
-
if (ms) existingTranslations.set(curMsgid, ms)
|
|
215
|
-
curMsgid = null
|
|
216
|
-
continue
|
|
217
|
-
}
|
|
218
|
-
if (trimmed.startsWith('"') && curMsgid !== null) {
|
|
219
|
-
curMsgid += unescapePo(trimmed.slice(1, -1))
|
|
220
|
-
}
|
|
237
|
+
for (const [key, value] of parsePoEntries(
|
|
238
|
+
readFileSync(existingPo, "utf8")
|
|
239
|
+
)) {
|
|
240
|
+
existingTranslations.set(key, value.msgstr)
|
|
221
241
|
}
|
|
222
242
|
}
|
|
223
243
|
|
|
244
|
+
// Build entries
|
|
224
245
|
const entries = []
|
|
225
246
|
for (const msgid of msgids) {
|
|
226
247
|
// Prefer existing translation over djangojs.po lookup (no synthetic comment)
|
|
227
248
|
const existing = existingTranslations.get(msgid)
|
|
228
|
-
const t = existing
|
|
249
|
+
const t = existing
|
|
250
|
+
? {msgstr: existing, comment: ""}
|
|
251
|
+
: translationMap.get(msgid)
|
|
229
252
|
entries.push({
|
|
230
253
|
msgid,
|
|
231
254
|
msgstr: t ? t.msgstr : "",
|
|
232
|
-
comment: t ? t.comment : ""
|
|
255
|
+
comment: t ? t.comment : ""
|
|
233
256
|
})
|
|
234
257
|
if (t?.msgstr) totalTranslated++
|
|
235
258
|
}
|
|
@@ -245,11 +268,11 @@ for (const lang of languages) {
|
|
|
245
268
|
'"Content-Type: text/plain; charset=UTF-8\\n"',
|
|
246
269
|
`"Language: ${lang}\\n"`,
|
|
247
270
|
'"Plural-Forms: nplurals=2; plural=(n != 1);\\n"',
|
|
248
|
-
""
|
|
271
|
+
""
|
|
249
272
|
].join("\n")
|
|
250
273
|
|
|
251
274
|
const body = entries
|
|
252
|
-
.map(
|
|
275
|
+
.map(e => {
|
|
253
276
|
let lines = ""
|
|
254
277
|
if (e.comment && !e.comment.startsWith("# obsolete")) {
|
|
255
278
|
lines += e.comment + "\n"
|
|
@@ -261,18 +284,38 @@ for (const lang of languages) {
|
|
|
261
284
|
.join("")
|
|
262
285
|
|
|
263
286
|
const langDir = join(root, "locale", lang, "LC_MESSAGES")
|
|
264
|
-
mkdirSync(langDir, {
|
|
287
|
+
mkdirSync(langDir, {recursive: true})
|
|
265
288
|
writeFileSync(join(langDir, "messages.po"), header + body, "utf8")
|
|
266
289
|
|
|
267
|
-
const translated = entries.filter(
|
|
268
|
-
console.log(
|
|
290
|
+
const translated = entries.filter(e => e.msgstr).length
|
|
291
|
+
console.log(
|
|
292
|
+
` ${lang}: ${entries.length} entries, ${translated} translated`
|
|
293
|
+
)
|
|
269
294
|
}
|
|
270
295
|
|
|
271
296
|
console.log(`\nTotal translated strings: ${totalTranslated}`)
|
|
272
297
|
|
|
273
298
|
function escapePo(s) {
|
|
274
|
-
return s
|
|
299
|
+
return s
|
|
300
|
+
.replace(/\\/g, "\\\\")
|
|
301
|
+
.replace(/"/g, '\\"')
|
|
302
|
+
.replace(/\n/g, "\\n")
|
|
303
|
+
.replace(/\r/g, "\\r")
|
|
304
|
+
.replace(/\t/g, "\\t")
|
|
275
305
|
}
|
|
306
|
+
|
|
276
307
|
function unescapePo(s) {
|
|
277
|
-
return s
|
|
308
|
+
return s
|
|
309
|
+
.replace(/\\"/g, '"')
|
|
310
|
+
.replace(/\\n/g, "\n")
|
|
311
|
+
.replace(/\\r/g, "\r")
|
|
312
|
+
.replace(/\t/g, "\t")
|
|
313
|
+
.replace(/\\\\/g, "\\")
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function stripQuotes(s) {
|
|
317
|
+
if (s.startsWith('"') && s.endsWith('"') && s.length >= 2) {
|
|
318
|
+
return s.slice(1, -1)
|
|
319
|
+
}
|
|
320
|
+
return s
|
|
278
321
|
}
|
package/src/app/index.ts
CHANGED
|
@@ -210,7 +210,9 @@ export class App {
|
|
|
210
210
|
case "sign-up":
|
|
211
211
|
returnValue = new Signup({
|
|
212
212
|
app: this.config.app as PreloginApp,
|
|
213
|
-
language: this.config.language || ""
|
|
213
|
+
language: this.config.language || "",
|
|
214
|
+
socialaccount_providers:
|
|
215
|
+
this.config.socialaccount_providers ?? []
|
|
214
216
|
})
|
|
215
217
|
break
|
|
216
218
|
default:
|
package/src/user/auth/login.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {escapeText} from "fwtoolkit"
|
|
2
2
|
import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
|
|
3
|
+
import {socialProviderIcon} from "./social_icons.js"
|
|
3
4
|
|
|
4
5
|
export class LoginPage extends PreloginPage {
|
|
5
6
|
socialaccount_providers: Array<Record<string, unknown>>
|
|
@@ -44,7 +45,7 @@ export class LoginPage extends PreloginPage {
|
|
|
44
45
|
(provider: any) => `<li>
|
|
45
46
|
<a title="${provider.name}" class="fw-button fw-socialaccount fw-${provider.id}"
|
|
46
47
|
href="${provider.login_url}">
|
|
47
|
-
<span class="fab fa-${provider.id}"></span>
|
|
48
|
+
<span class="fab fa-${socialProviderIcon(provider.id)}"></span>
|
|
48
49
|
${gettext("Login with")} ${provider.name}
|
|
49
50
|
</a>
|
|
50
51
|
</li>`
|
package/src/user/auth/signup.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import {escapeText} from "fwtoolkit"
|
|
2
2
|
import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
|
|
3
|
+
import {socialProviderIcon} from "./social_icons.js"
|
|
3
4
|
|
|
4
5
|
export class Signup extends PreloginPage {
|
|
5
|
-
|
|
6
|
+
socialaccount_providers: Array<Record<string, unknown>>
|
|
7
|
+
|
|
8
|
+
constructor({
|
|
9
|
+
app,
|
|
10
|
+
language,
|
|
11
|
+
socialaccount_providers
|
|
12
|
+
}: {
|
|
13
|
+
app: PreloginApp
|
|
14
|
+
language: string
|
|
15
|
+
socialaccount_providers: Array<Record<string, unknown>>
|
|
16
|
+
}) {
|
|
6
17
|
super({app, language})
|
|
18
|
+
this.socialaccount_providers = socialaccount_providers
|
|
7
19
|
this.title = gettext("Signup")
|
|
8
20
|
if (this.app.settings?.REGISTRATION_OPEN) {
|
|
9
21
|
this.contents = `<div class="fw-login-left">
|
|
@@ -13,6 +25,26 @@ export class Signup extends PreloginPage {
|
|
|
13
25
|
'Already have an account? Then please <a href="/" title="Login">login</a>.'
|
|
14
26
|
)}
|
|
15
27
|
</p>
|
|
28
|
+
${
|
|
29
|
+
this.app.settings?.SOCIALACCOUNT_OPEN &&
|
|
30
|
+
this.socialaccount_providers.length
|
|
31
|
+
? `<div class="socialaccount_ballot">
|
|
32
|
+
<ul class="socialaccount_providers">
|
|
33
|
+
${this.socialaccount_providers
|
|
34
|
+
.map(
|
|
35
|
+
(provider: any) => `<li>
|
|
36
|
+
<a title="${provider.name}" class="fw-button fw-socialaccount fw-${provider.id}"
|
|
37
|
+
href="${provider.login_url}">
|
|
38
|
+
<span class="fab fa-${socialProviderIcon(provider.id)}"></span>
|
|
39
|
+
${gettext("Sign up with")} ${provider.name}
|
|
40
|
+
</a>
|
|
41
|
+
</li>`
|
|
42
|
+
)
|
|
43
|
+
.join("")}
|
|
44
|
+
</ul>
|
|
45
|
+
</div>`
|
|
46
|
+
: ""
|
|
47
|
+
}
|
|
16
48
|
</div>
|
|
17
49
|
<div class="fw-login-right">
|
|
18
50
|
<form>
|
|
@@ -53,6 +85,23 @@ export class Signup extends PreloginPage {
|
|
|
53
85
|
bind(): void {
|
|
54
86
|
super.bind()
|
|
55
87
|
|
|
88
|
+
const socialButtons = document.body.querySelectorAll(
|
|
89
|
+
".fw-button.fw-socialaccount"
|
|
90
|
+
)
|
|
91
|
+
let btnWidth = 1
|
|
92
|
+
|
|
93
|
+
socialButtons.forEach((button: Element) => {
|
|
94
|
+
const theWidth = (button as HTMLElement).clientWidth
|
|
95
|
+
if (btnWidth < theWidth) {
|
|
96
|
+
btnWidth = theWidth
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
btnWidth += 15
|
|
100
|
+
socialButtons.forEach(
|
|
101
|
+
button =>
|
|
102
|
+
((button as HTMLElement).style.width = `${btnWidth}px`)
|
|
103
|
+
)
|
|
104
|
+
|
|
56
105
|
const signupSubmit = document.querySelector("#signup-submit")
|
|
57
106
|
|
|
58
107
|
if (!this.app.settings?.REGISTRATION_OPEN || !signupSubmit) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Map social account provider ids to Font Awesome brand icon names.
|
|
2
|
+
// The allauth openid_connect provider stands for an arbitrary OpenID
|
|
3
|
+
// Connect identity provider (for example an LDAP bridge via Dex,
|
|
4
|
+
// Keycloak or authentik), for which Font Awesome has a generic icon.
|
|
5
|
+
export const socialProviderIcon = (providerId: string): string => {
|
|
6
|
+
const iconMap: Record<string, string> = {
|
|
7
|
+
openid_connect: "openid"
|
|
8
|
+
}
|
|
9
|
+
return iconMap[providerId] || providerId
|
|
10
|
+
}
|
|
@@ -24,18 +24,24 @@ export class AdjustDocToTemplateWorker {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
init(): void {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
try {
|
|
28
|
+
const stateDoc = this.schema.nodeFromJSON(this.doc)
|
|
29
|
+
const newStateDoc = this.schema.nodeFromJSON(
|
|
30
|
+
adjustDocToTemplate(
|
|
31
|
+
this.doc as any,
|
|
32
|
+
this.template as any,
|
|
33
|
+
this.documentStyleSlugs,
|
|
34
|
+
this.schema
|
|
35
|
+
)
|
|
34
36
|
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const transform = recreateTransform(stateDoc, newStateDoc)
|
|
38
|
+
const steps: Array<Record<string, unknown>> = []
|
|
39
|
+
transform.steps.forEach((step: any) => steps.push(step.toJSON()))
|
|
40
|
+
this.sendMessage({type: "result", steps})
|
|
41
|
+
} catch (error) {
|
|
42
|
+
// Report the failure so the editor can clear its wait cover
|
|
43
|
+
// instead of waiting forever for a result message.
|
|
44
|
+
this.sendMessage({type: "error", error: String(error)})
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
}
|