@fiduswriter/image-manager 0.1.13 → 0.1.14
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/dist/copyright_dialog/index.d.ts.map +1 -1
- package/dist/copyright_dialog/index.js +19 -20
- package/dist/copyright_dialog/index.js.map +1 -1
- package/dist/copyright_dialog/templates.d.ts +2 -2
- package/dist/copyright_dialog/templates.d.ts.map +1 -1
- package/dist/copyright_dialog/templates.js +3 -3
- package/dist/copyright_dialog/templates.js.map +1 -1
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +7 -8
- package/dist/database.js.map +1 -1
- package/dist/edit_dialog/index.d.ts.map +1 -1
- package/dist/edit_dialog/index.js +25 -23
- package/dist/edit_dialog/index.js.map +1 -1
- package/dist/edit_dialog/model.d.ts.map +1 -1
- package/dist/edit_dialog/model.js +14 -18
- package/dist/edit_dialog/model.js.map +1 -1
- package/dist/edit_dialog/templates.d.ts.map +1 -1
- package/dist/edit_dialog/templates.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/overview/categories.d.ts.map +1 -1
- package/dist/overview/categories.js +17 -20
- package/dist/overview/categories.js.map +1 -1
- package/dist/overview/index.d.ts.map +1 -1
- package/dist/overview/index.js +3 -2
- package/dist/overview/index.js.map +1 -1
- package/dist/overview/menu.d.ts.map +1 -1
- package/dist/overview/menu.js +13 -15
- package/dist/overview/menu.js.map +1 -1
- package/dist/selection_dialog/index.d.ts.map +1 -1
- package/dist/selection_dialog/index.js +22 -26
- package/dist/selection_dialog/index.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/copyright_dialog/index.ts +177 -186
- package/src/copyright_dialog/templates.ts +26 -19
- package/src/database.ts +61 -68
- package/src/edit_dialog/index.ts +261 -251
- package/src/edit_dialog/model.ts +220 -220
- package/src/edit_dialog/templates.ts +22 -22
- package/src/index.ts +5 -4
- package/src/overview/categories.ts +106 -116
- package/src/overview/index.ts +2 -2
- package/src/overview/menu.ts +77 -77
- package/src/selection_dialog/index.ts +197 -207
- package/src/types.ts +79 -65
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,0DAA0D;AAC1D,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACxB;AAED,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,kEAAkE;AAClE,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,S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AC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC1B;AAED,YAAY,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/image-manager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Fidus Writer image/media manager",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -69,13 +69,15 @@
|
|
|
69
69
|
"lint:fix": "eslint src --fix",
|
|
70
70
|
"format": "prettier --write .",
|
|
71
71
|
"format:check": "prettier --check .",
|
|
72
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js"
|
|
72
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
|
|
73
|
+
"install-hooks": "husky"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
76
|
"bibliojson": "^4.0.3",
|
|
76
77
|
"cropperjs": "^1.6.2",
|
|
77
78
|
"fast-deep-equal": "^3.1.3",
|
|
78
|
-
"fwtoolkit": "
|
|
79
|
+
"fwtoolkit": "file:../fwtoolkit",
|
|
80
|
+
"simple-datatables": "^10.2.0"
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
81
83
|
"@eslint/js": "^10.0.1",
|
|
@@ -88,7 +90,9 @@
|
|
|
88
90
|
"ts-jest": "^29.4.11",
|
|
89
91
|
"ts-jest-resolver": "^2.0.1",
|
|
90
92
|
"typescript": "^6.0.3",
|
|
91
|
-
"typescript-eslint": "^8.62.0"
|
|
93
|
+
"typescript-eslint": "^8.62.0",
|
|
94
|
+
"husky": "^9.1.7",
|
|
95
|
+
"lint-staged": "^17.0.8"
|
|
92
96
|
},
|
|
93
97
|
"lint-staged": {
|
|
94
98
|
"*.{ts,js,mjs,css,md,json,html}": [
|
|
@@ -1,211 +1,202 @@
|
|
|
1
|
-
import {edtfParse} from "bibliojson"
|
|
2
|
-
import deepEqual from "fast-deep-equal"
|
|
3
|
-
import {Dialog, InputList, TypeSwitch, escapeText} from "fwtoolkit"
|
|
4
|
-
import type {InputListItemRenderResult} from "fwtoolkit"
|
|
1
|
+
import { edtfParse } from "bibliojson";
|
|
2
|
+
import deepEqual from "fast-deep-equal";
|
|
3
|
+
import { Dialog, InputList, TypeSwitch, escapeText } from "fwtoolkit";
|
|
4
|
+
import type { InputListItemRenderResult } from "fwtoolkit";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./templates.js"
|
|
11
|
-
import type {Copyright, License} from "../types.js"
|
|
7
|
+
copyrightTemplate,
|
|
8
|
+
licenseInputTemplate,
|
|
9
|
+
licenseSelectTemplate,
|
|
10
|
+
} from "./templates.js";
|
|
11
|
+
import type { Copyright, License } from "../types.js";
|
|
12
12
|
|
|
13
13
|
export const LICENSE_URLS = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
] as [string, string][]
|
|
14
|
+
["CC BY 4.0", "https://creativecommons.org/licenses/by/4.0/"],
|
|
15
|
+
["CC BY-SA 4.0", "https://creativecommons.org/licenses/by-sa/4.0/"],
|
|
16
|
+
["CC BY-ND 4.0", "https://creativecommons.org/licenses/by-nd/4.0/"],
|
|
17
|
+
["CC BY-NC 4.0", "https://creativecommons.org/licenses/by-nc/4.0/"],
|
|
18
|
+
["CC BY-NC-SA 4.0", "https://creativecommons.org/licenses/by-nc-sa/4.0/"],
|
|
19
|
+
["CC BY-NC-ND 4.0", "https://creativecommons.org/licenses/by-nc-nd/4.0/"],
|
|
20
|
+
["CC0", "https://creativecommons.org/publicdomain/zero/1.0/"],
|
|
21
|
+
] as [string, string][];
|
|
22
22
|
|
|
23
23
|
function getLicenseTitle(url: string): string {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const license = LICENSE_URLS.find((license) => license[1] === url);
|
|
25
|
+
return license ? license[0] : "";
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export class CopyrightDialog {
|
|
29
|
-
|
|
29
|
+
copyright: Copyright;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
origCopyright: Copyright;
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
dialog: Dialog | false = false;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
licensesList!: InputList<License>;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
constructor(copyright: Copyright) {
|
|
38
|
+
this.copyright = copyright;
|
|
39
|
+
this.origCopyright = copyright;
|
|
40
|
+
this.dialog = false;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const dialogEl = this.dialog.dialogEl
|
|
48
|
-
this.copyright = {} as Copyright
|
|
49
|
-
const holder = (
|
|
50
|
-
dialogEl.querySelector(".holder") as HTMLInputElement
|
|
51
|
-
).value
|
|
52
|
-
this.copyright.holder = holder.length ? holder : false
|
|
53
|
-
const year = (
|
|
54
|
-
dialogEl.querySelector(".year") as HTMLInputElement
|
|
55
|
-
).value
|
|
56
|
-
this.copyright.year = year.length
|
|
57
|
-
? Math.max(0, Math.min(Number.parseInt(year) || 0, 2100))
|
|
58
|
-
: false
|
|
59
|
-
this.copyright.freeToRead = dialogEl.querySelector(
|
|
60
|
-
".free-to-read:checked"
|
|
61
|
-
)
|
|
62
|
-
? true
|
|
63
|
-
: false
|
|
64
|
-
const licenseStartDates = Array.from(
|
|
65
|
-
dialogEl.querySelectorAll(".license-start")
|
|
66
|
-
).map(el => (el as HTMLInputElement).value)
|
|
67
|
-
this.copyright.licenses = this.licensesList.values
|
|
68
|
-
.map((license, index) => {
|
|
69
|
-
if (!license.url.length) {
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
const returnValue: License = {
|
|
73
|
-
url: license.url,
|
|
74
|
-
title: license.title
|
|
75
|
-
}
|
|
76
|
-
const startDate = edtfParse(licenseStartDates[index])
|
|
77
|
-
if (
|
|
78
|
-
startDate.valid &&
|
|
79
|
-
(startDate.type === "Date" ||
|
|
80
|
-
startDate.type === "YearMonth" ||
|
|
81
|
-
startDate.type === "Year") &&
|
|
82
|
-
!startDate.uncertain &&
|
|
83
|
-
!startDate.approximate
|
|
84
|
-
) {
|
|
85
|
-
returnValue.start = startDate.cleanedString
|
|
86
|
-
}
|
|
87
|
-
return returnValue
|
|
88
|
-
})
|
|
89
|
-
.filter((license): license is License => license !== false)
|
|
43
|
+
getCurrentValue(): void {
|
|
44
|
+
if (!this.dialog) {
|
|
45
|
+
return;
|
|
90
46
|
}
|
|
47
|
+
const dialogEl = this.dialog.dialogEl;
|
|
48
|
+
this.copyright = {} as Copyright;
|
|
49
|
+
const holder = (dialogEl.querySelector(".holder") as HTMLInputElement)
|
|
50
|
+
.value;
|
|
51
|
+
this.copyright.holder = holder.length ? holder : false;
|
|
52
|
+
const year = (dialogEl.querySelector(".year") as HTMLInputElement).value;
|
|
53
|
+
this.copyright.year = year.length
|
|
54
|
+
? Math.max(0, Math.min(Number.parseInt(year) || 0, 2100))
|
|
55
|
+
: false;
|
|
56
|
+
this.copyright.freeToRead = dialogEl.querySelector(".free-to-read:checked")
|
|
57
|
+
? true
|
|
58
|
+
: false;
|
|
59
|
+
const licenseStartDates = Array.from(
|
|
60
|
+
dialogEl.querySelectorAll(".license-start"),
|
|
61
|
+
).map((el) => (el as HTMLInputElement).value);
|
|
62
|
+
this.copyright.licenses = this.licensesList.values
|
|
63
|
+
.map((license, index) => {
|
|
64
|
+
if (!license.url.length) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const returnValue: License = {
|
|
68
|
+
url: license.url,
|
|
69
|
+
title: license.title,
|
|
70
|
+
};
|
|
71
|
+
const startDate = edtfParse(licenseStartDates[index]);
|
|
72
|
+
if (
|
|
73
|
+
startDate.valid &&
|
|
74
|
+
(startDate.type === "Date" ||
|
|
75
|
+
startDate.type === "YearMonth" ||
|
|
76
|
+
startDate.type === "Year") &&
|
|
77
|
+
!startDate.uncertain &&
|
|
78
|
+
!startDate.approximate
|
|
79
|
+
) {
|
|
80
|
+
returnValue.start = startDate.cleanedString;
|
|
81
|
+
}
|
|
82
|
+
return returnValue;
|
|
83
|
+
})
|
|
84
|
+
.filter((license): license is License => license !== false);
|
|
85
|
+
}
|
|
91
86
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
87
|
+
init(): Promise<Copyright | false> {
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
const buttons = [];
|
|
90
|
+
buttons.push({
|
|
91
|
+
text: gettext("Change"),
|
|
92
|
+
classes: "fw-dark",
|
|
93
|
+
click: () => {
|
|
94
|
+
dialog.close();
|
|
95
|
+
this.getCurrentValue();
|
|
96
|
+
if (deepEqual(this.copyright, this.origCopyright)) {
|
|
97
|
+
// No change.
|
|
98
|
+
resolve(false);
|
|
99
|
+
}
|
|
100
|
+
resolve(this.copyright);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
108
103
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
buttons.push({
|
|
105
|
+
type: "cancel" as const,
|
|
106
|
+
});
|
|
112
107
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
const dialog = new Dialog({
|
|
109
|
+
width: 940,
|
|
110
|
+
height: 300,
|
|
111
|
+
id: "configure-copyright",
|
|
112
|
+
title: gettext("Set copyright information"),
|
|
113
|
+
body: copyrightTemplate(this.copyright),
|
|
114
|
+
buttons,
|
|
115
|
+
});
|
|
116
|
+
this.dialog = dialog;
|
|
122
117
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
dialog.open();
|
|
119
|
+
this.bind();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
renderItem: (license): InputListItemRenderResult<License> => ({
|
|
140
|
-
html: `<div class="copyright-license-switch"></div>
|
|
123
|
+
bind(): void {
|
|
124
|
+
if (!this.dialog) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const dialogEl = this.dialog.dialogEl;
|
|
128
|
+
this.licensesList = new InputList<License>({
|
|
129
|
+
dom: dialogEl.querySelector(".copyright-licenses-list") as HTMLElement,
|
|
130
|
+
initialValues: this.copyright.licenses || [],
|
|
131
|
+
emptyValue: { url: "", title: "", start: false },
|
|
132
|
+
renderItem: (license): InputListItemRenderResult<License> => ({
|
|
133
|
+
html: `<div class="copyright-license-switch"></div>
|
|
141
134
|
<div class="field-part field-part-small">
|
|
142
135
|
<input type="text" class="license-start" value="${license.start ? escapeText(license.start) : ""}" placeholder="${gettext("Start date")}">
|
|
143
136
|
</div>`,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
137
|
+
bind: (el) => {
|
|
138
|
+
const licenseContainer = el.closest("tr") as HTMLElement;
|
|
139
|
+
const startInput = licenseContainer.querySelector(".license-start");
|
|
140
|
+
if (license.start && startInput) {
|
|
141
|
+
(startInput as HTMLInputElement).value = license.start;
|
|
142
|
+
}
|
|
151
143
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
144
|
+
const mode =
|
|
145
|
+
license.url === "" ||
|
|
146
|
+
LICENSE_URLS.find((licenseUrl) => licenseUrl[1] === license.url)
|
|
147
|
+
? 1
|
|
148
|
+
: 2;
|
|
149
|
+
new TypeSwitch({
|
|
150
|
+
dom: el.querySelector(".copyright-license-switch") as HTMLElement,
|
|
151
|
+
label1: gettext("From list"),
|
|
152
|
+
label2: gettext("Custom"),
|
|
153
|
+
initialMode: mode as 1 | 2,
|
|
154
|
+
render1: () => licenseSelectTemplate({ url: license.url }),
|
|
155
|
+
render2: () =>
|
|
156
|
+
licenseInputTemplate({
|
|
157
|
+
url: license.url,
|
|
158
|
+
title: license.title,
|
|
159
|
+
}),
|
|
160
|
+
onChange: () => {
|
|
161
|
+
// Restore focus to the license input after switching.
|
|
162
|
+
const focusable = el.querySelector(
|
|
163
|
+
".fw-type-switch-input-inner input, .fw-type-switch-input-inner select",
|
|
164
|
+
);
|
|
165
|
+
if (focusable) {
|
|
166
|
+
(focusable as HTMLElement).focus();
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
getValue: (el) => {
|
|
173
|
+
const licenseInput = el.querySelector(
|
|
174
|
+
".fw-type-switch-input-inner",
|
|
175
|
+
) as HTMLElement;
|
|
176
|
+
const selectEl = licenseInput.querySelector("select.license");
|
|
177
|
+
let url: string, title: string;
|
|
178
|
+
if (selectEl) {
|
|
179
|
+
url = (selectEl as HTMLSelectElement).value;
|
|
180
|
+
title = getLicenseTitle(url);
|
|
181
|
+
} else {
|
|
182
|
+
url = (
|
|
183
|
+
licenseInput.querySelector("input.license") as HTMLInputElement
|
|
184
|
+
).value;
|
|
185
|
+
title = (
|
|
186
|
+
licenseInput.querySelector(
|
|
187
|
+
"input.license-title",
|
|
188
|
+
) as HTMLInputElement
|
|
189
|
+
).value;
|
|
190
|
+
}
|
|
191
|
+
const start = (el.closest("tr") as HTMLElement).querySelector(
|
|
192
|
+
".license-start",
|
|
193
|
+
);
|
|
194
|
+
return {
|
|
195
|
+
url,
|
|
196
|
+
title,
|
|
197
|
+
start: start ? (start as HTMLInputElement).value || false : false,
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
211
202
|
}
|
|
@@ -1,42 +1,49 @@
|
|
|
1
|
-
import {escapeText} from "fwtoolkit"
|
|
1
|
+
import { escapeText } from "fwtoolkit";
|
|
2
2
|
|
|
3
|
-
import {LICENSE_URLS} from "./index.js"
|
|
3
|
+
import { LICENSE_URLS } from "./index.js";
|
|
4
4
|
|
|
5
5
|
interface LicenseSelectTemplateData {
|
|
6
|
-
|
|
6
|
+
url: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
interface LicenseInputTemplateData {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
url: string;
|
|
11
|
+
title: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface CopyrightTemplateData {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
holder?: string | false;
|
|
16
|
+
year?: number | false;
|
|
17
|
+
freeToRead: boolean;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const licenseSelectTemplate = ({url}: LicenseSelectTemplateData) =>
|
|
21
|
-
|
|
20
|
+
export const licenseSelectTemplate = ({ url }: LicenseSelectTemplateData) =>
|
|
21
|
+
`<select class="license">
|
|
22
22
|
<option value=""></option>
|
|
23
23
|
${LICENSE_URLS.map(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
(licenseUrl) =>
|
|
25
|
+
`<option value="${licenseUrl[1]}"${url === licenseUrl[1] ? " selected" : ""}>${licenseUrl[0]}</option>`,
|
|
26
26
|
).join("")}
|
|
27
27
|
</select>
|
|
28
|
-
<div class="fw-select-arrow fa fa-caret-down"></div
|
|
28
|
+
<div class="fw-select-arrow fa fa-caret-down"></div>`;
|
|
29
29
|
|
|
30
|
-
export const licenseInputTemplate = ({
|
|
31
|
-
|
|
30
|
+
export const licenseInputTemplate = ({
|
|
31
|
+
url,
|
|
32
|
+
title,
|
|
33
|
+
}: LicenseInputTemplateData) =>
|
|
34
|
+
`<div class="field-part field-part-huge">
|
|
32
35
|
<input type='text' class='license' value="${escapeText(url)}" placeholder="${gettext("License URL")}">
|
|
33
36
|
</div>
|
|
34
37
|
<div class="field-part field-part-huge">
|
|
35
38
|
<input type='text' class='license-title' value="${escapeText(title)}" placeholder="${gettext("License Title")}">
|
|
36
|
-
</div
|
|
39
|
+
</div>`;
|
|
37
40
|
|
|
38
|
-
export const copyrightTemplate = ({
|
|
39
|
-
|
|
41
|
+
export const copyrightTemplate = ({
|
|
42
|
+
holder,
|
|
43
|
+
year,
|
|
44
|
+
freeToRead,
|
|
45
|
+
}: CopyrightTemplateData) =>
|
|
46
|
+
`<table class="fw-dialog-table">
|
|
40
47
|
<tbody>
|
|
41
48
|
<tr>
|
|
42
49
|
<th><h4 class="fw-tablerow-title fw-wtooltip">
|
|
@@ -69,4 +76,4 @@ export const copyrightTemplate = ({holder, year, freeToRead}: CopyrightTemplateD
|
|
|
69
76
|
</td>
|
|
70
77
|
</tr>
|
|
71
78
|
</tbody>
|
|
72
|
-
</table
|
|
79
|
+
</table>`;
|