@xlinklight/browser-extension-tools 1.0.0-rc.0 → 1.0.0
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 +33 -33
- package/assets/shared/css/side-panel.css +94 -94
- package/assets/shared/js/chrome-runtime.js +87 -87
- package/assets/shared/js/extension-account-menu.js +239 -239
- package/assets/shared/js/extension-i18n.js +42 -42
- package/assets/shared/js/extension-session-store.js +42 -42
- package/assets/shared/js/extension-tabs.js +23 -23
- package/assets/shared/js/link-light-api-client.js +31 -31
- package/assets/shared/js/side-panel-account.js +14 -14
- package/assets/shared/js/side-panel-api.js +13 -13
- package/assets/shared/js/side-panel-bootstrap.js +127 -127
- package/assets/shared/js/side-panel-dom.js +15 -15
- package/assets/shared/js/side-panel-i18n.js +37 -37
- package/assets/shared/js/side-panel-import-preview.js +7 -7
- package/assets/shared/js/side-panel-status.js +13 -13
- package/assets/shared/js/side-panel-tabs.js +35 -35
- package/assets/shared/js/side-panel-translations.js +41 -41
- package/package.json +1 -1
- package/src/chrome-discovery.mjs +231 -231
- package/src/chrome-for-testing.mjs +203 -203
- package/src/chrome-install-worker.mjs +8 -8
- package/src/cli.mjs +171 -171
- package/src/dev-cli.mjs +9 -9
- package/src/dev-extension.mjs +350 -350
- package/src/package-cli.mjs +7 -7
- package/src/package.mjs +223 -223
- package/src/profile.mjs +144 -144
- package/src/reload-server.mjs +108 -108
- package/src/run.mjs +7 -7
- package/src/watcher.mjs +45 -45
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
(function initializeLinkLightExtensionTabs(global) {
|
|
2
|
-
function initializeSidePanelTabs({ documentRef = global.document, getTab, onActivate }) {
|
|
3
|
-
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
4
|
-
if (button.dataset.disabled === "true") continue;
|
|
5
|
-
const tab = getTab(button.dataset.tab);
|
|
6
|
-
if (!tab) continue;
|
|
7
|
-
button.addEventListener("click", () => onActivate(tab.id));
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function activateTab(tabId, { documentRef = global.document } = {}) {
|
|
12
|
-
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
13
|
-
if (button.dataset.disabled === "true") continue;
|
|
14
|
-
if (button.dataset.tab === tabId) button.setAttribute("aria-current", "page");
|
|
15
|
-
else button.removeAttribute("aria-current");
|
|
16
|
-
}
|
|
17
|
-
for (const panel of documentRef.querySelectorAll("[data-tab-panel]")) {
|
|
18
|
-
panel.hidden = panel.dataset.tabPanel !== tabId;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
global.LinkLightExtensionTabs = { activateTab, initializeSidePanelTabs };
|
|
23
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightExtensionTabs(global) {
|
|
2
|
+
function initializeSidePanelTabs({ documentRef = global.document, getTab, onActivate }) {
|
|
3
|
+
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
4
|
+
if (button.dataset.disabled === "true") continue;
|
|
5
|
+
const tab = getTab(button.dataset.tab);
|
|
6
|
+
if (!tab) continue;
|
|
7
|
+
button.addEventListener("click", () => onActivate(tab.id));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function activateTab(tabId, { documentRef = global.document } = {}) {
|
|
12
|
+
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
13
|
+
if (button.dataset.disabled === "true") continue;
|
|
14
|
+
if (button.dataset.tab === tabId) button.setAttribute("aria-current", "page");
|
|
15
|
+
else button.removeAttribute("aria-current");
|
|
16
|
+
}
|
|
17
|
+
for (const panel of documentRef.querySelectorAll("[data-tab-panel]")) {
|
|
18
|
+
panel.hidden = panel.dataset.tabPanel !== tabId;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
global.LinkLightExtensionTabs = { activateTab, initializeSidePanelTabs };
|
|
23
|
+
})(globalThis);
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
(function initializeLinkLightApiClient(global) {
|
|
2
|
-
function createLinkLightApiClient(runtime, sessionStore, getAccountState) {
|
|
3
|
-
function resolveUrl(path) {
|
|
4
|
-
if (/^https?:\/\//.test(path)) return path;
|
|
5
|
-
return `${runtime.origin}${path.startsWith("/") ? path : `/${path}`}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function headers(extraHeaders = {}) {
|
|
9
|
-
const state = typeof getAccountState === "function" ? getAccountState() : null;
|
|
10
|
-
return {
|
|
11
|
-
...(state && sessionStore ? sessionStore.headers(state) : { "Content-Type": "application/json" }),
|
|
12
|
-
...(runtime.pluginToken ? { "x-link-light-plugin-token": runtime.pluginToken } : {}),
|
|
13
|
-
...extraHeaders,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function request(path, init = {}, options = {}) {
|
|
18
|
-
const response = await global.fetch(resolveUrl(path), {
|
|
19
|
-
...init,
|
|
20
|
-
headers: options.auth === false ? { "Content-Type": "application/json", ...(init.headers || {}) } : headers(init.headers),
|
|
21
|
-
});
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
if (!response.ok) throw new Error(data?.error?.code || options.fallbackError || "link_light_request_failed");
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return { headers, request, resolveUrl };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
global.LinkLightApiClient = { createLinkLightApiClient };
|
|
31
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightApiClient(global) {
|
|
2
|
+
function createLinkLightApiClient(runtime, sessionStore, getAccountState) {
|
|
3
|
+
function resolveUrl(path) {
|
|
4
|
+
if (/^https?:\/\//.test(path)) return path;
|
|
5
|
+
return `${runtime.origin}${path.startsWith("/") ? path : `/${path}`}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function headers(extraHeaders = {}) {
|
|
9
|
+
const state = typeof getAccountState === "function" ? getAccountState() : null;
|
|
10
|
+
return {
|
|
11
|
+
...(state && sessionStore ? sessionStore.headers(state) : { "Content-Type": "application/json" }),
|
|
12
|
+
...(runtime.pluginToken ? { "x-link-light-plugin-token": runtime.pluginToken } : {}),
|
|
13
|
+
...extraHeaders,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function request(path, init = {}, options = {}) {
|
|
18
|
+
const response = await global.fetch(resolveUrl(path), {
|
|
19
|
+
...init,
|
|
20
|
+
headers: options.auth === false ? { "Content-Type": "application/json", ...(init.headers || {}) } : headers(init.headers),
|
|
21
|
+
});
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
if (!response.ok) throw new Error(data?.error?.code || options.fallbackError || "link_light_request_failed");
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { headers, request, resolveUrl };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
global.LinkLightApiClient = { createLinkLightApiClient };
|
|
31
|
+
})(globalThis);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelAccount(global) {
|
|
2
|
-
function isStoredSessionSignedIn(accountState, now = Date.now()) {
|
|
3
|
-
return Boolean(accountState.token && accountState.expiresAt && new Date(accountState.expiresAt).getTime() > now);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function getStoredSessionHeaders(accountState) {
|
|
7
|
-
const headers = { "Content-Type": "application/json" };
|
|
8
|
-
if (!isStoredSessionSignedIn(accountState)) throw new Error("authentication_required");
|
|
9
|
-
headers.Authorization = `Bearer ${accountState.token}`;
|
|
10
|
-
return headers;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
global.LinkLightSidePanelAccount = { getStoredSessionHeaders, isStoredSessionSignedIn };
|
|
14
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelAccount(global) {
|
|
2
|
+
function isStoredSessionSignedIn(accountState, now = Date.now()) {
|
|
3
|
+
return Boolean(accountState.token && accountState.expiresAt && new Date(accountState.expiresAt).getTime() > now);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function getStoredSessionHeaders(accountState) {
|
|
7
|
+
const headers = { "Content-Type": "application/json" };
|
|
8
|
+
if (!isStoredSessionSignedIn(accountState)) throw new Error("authentication_required");
|
|
9
|
+
headers.Authorization = `Bearer ${accountState.token}`;
|
|
10
|
+
return headers;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
global.LinkLightSidePanelAccount = { getStoredSessionHeaders, isStoredSessionSignedIn };
|
|
14
|
+
})(globalThis);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelApi(global) {
|
|
2
|
-
async function requestJson({ origin, path, headers, body }) {
|
|
3
|
-
const response = await global.fetch(`${origin}${path}`, {
|
|
4
|
-
method: "POST",
|
|
5
|
-
headers,
|
|
6
|
-
body: JSON.stringify(body),
|
|
7
|
-
});
|
|
8
|
-
const data = await response.json();
|
|
9
|
-
return { data, response };
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
global.LinkLightSidePanelApi = { requestJson };
|
|
13
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelApi(global) {
|
|
2
|
+
async function requestJson({ origin, path, headers, body }) {
|
|
3
|
+
const response = await global.fetch(`${origin}${path}`, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
headers,
|
|
6
|
+
body: JSON.stringify(body),
|
|
7
|
+
});
|
|
8
|
+
const data = await response.json();
|
|
9
|
+
return { data, response };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
global.LinkLightSidePanelApi = { requestJson };
|
|
13
|
+
})(globalThis);
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelBootstrap(global) {
|
|
2
|
-
function createSidePanelBootstrap({
|
|
3
|
-
extensionRuntime,
|
|
4
|
-
languagePreferenceStorageKey,
|
|
5
|
-
localeDirectories,
|
|
6
|
-
fallbackLocale = "zh-CN",
|
|
7
|
-
sidePanelTabs,
|
|
8
|
-
elements,
|
|
9
|
-
initialStatusKey = "statusWaiting",
|
|
10
|
-
onAfterStaticTranslations,
|
|
11
|
-
onDisabledTab,
|
|
12
|
-
onTabActivated,
|
|
13
|
-
onLanguageChanged,
|
|
14
|
-
}) {
|
|
15
|
-
const { interpolate, loadLocaleMessageMap, normalizeLanguagePreference, resolveLocale } = global.LinkLightSidePanelI18n;
|
|
16
|
-
const { updateCount, updateStatus } = global.LinkLightSidePanelStatus;
|
|
17
|
-
const { applySidePanelTranslations } = global.LinkLightSidePanelTranslations;
|
|
18
|
-
const {
|
|
19
|
-
activateSidePanelTab,
|
|
20
|
-
initializeSidePanelTabs: initializeSharedSidePanelTabs,
|
|
21
|
-
} = global.LinkLightSidePanelTabs;
|
|
22
|
-
|
|
23
|
-
let messages = {};
|
|
24
|
-
let languagePreference = "auto";
|
|
25
|
-
let activeLocale = fallbackLocale;
|
|
26
|
-
const activeStatus = { key: initialStatusKey, values: {} };
|
|
27
|
-
|
|
28
|
-
function t(key, values = {}) {
|
|
29
|
-
return interpolate(messages[key] ?? key, values);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function readLanguagePreference() {
|
|
33
|
-
const result = await extensionRuntime.storage.get([languagePreferenceStorageKey]);
|
|
34
|
-
return normalizeLanguagePreference(result?.[languagePreferenceStorageKey]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function saveLanguagePreference(preference) {
|
|
38
|
-
await extensionRuntime.storage.set({ [languagePreferenceStorageKey]: normalizeLanguagePreference(preference) });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function loadMessages(locale) {
|
|
42
|
-
messages = await loadLocaleMessageMap({ runtime: extensionRuntime, locale, localeDirectories, fallbackLocale });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function applyTranslations() {
|
|
46
|
-
applySidePanelTranslations({
|
|
47
|
-
t,
|
|
48
|
-
locale: activeLocale,
|
|
49
|
-
languageInput: elements.languageInput,
|
|
50
|
-
languagePreference,
|
|
51
|
-
safetyNote: elements.safetyNote,
|
|
52
|
-
onAfterStaticTranslations,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function setStatus(key, values = {}) {
|
|
57
|
-
updateStatus({ state: activeStatus, key, values, statusText: elements.statusText, t });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function setCount(value) {
|
|
61
|
-
updateCount({ count: elements.count, value, t });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getErrorStatusKey(error, fallbackKey) {
|
|
65
|
-
const key = error instanceof Error ? error.message : "";
|
|
66
|
-
return messages[key] ? key : fallbackKey;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function activateTab(tabId) {
|
|
70
|
-
activateSidePanelTab(tabId);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function initializeSidePanelTabs() {
|
|
74
|
-
initializeSharedSidePanelTabs({
|
|
75
|
-
tabs: sidePanelTabs,
|
|
76
|
-
onActivate: (tab) => {
|
|
77
|
-
activateTab(tab.id);
|
|
78
|
-
onTabActivated?.(tab, api);
|
|
79
|
-
},
|
|
80
|
-
onDisabled: (tab) => {
|
|
81
|
-
if (typeof onDisabledTab === "function") {
|
|
82
|
-
onDisabledTab(tab, api);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
setStatus("statusFeatureComingSoon", { feature: t(tab.labelKey) });
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function initializeI18n() {
|
|
91
|
-
languagePreference = await readLanguagePreference();
|
|
92
|
-
activeLocale = resolveLocale({ preference: languagePreference, runtime: extensionRuntime, fallbackLocale });
|
|
93
|
-
await loadMessages(activeLocale);
|
|
94
|
-
applyTranslations();
|
|
95
|
-
setStatus(initialStatusKey);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function handleLanguagePreferenceChange() {
|
|
99
|
-
languagePreference = normalizeLanguagePreference(elements.languageInput.value);
|
|
100
|
-
await saveLanguagePreference(languagePreference);
|
|
101
|
-
activeLocale = resolveLocale({ preference: languagePreference, runtime: extensionRuntime, fallbackLocale });
|
|
102
|
-
await loadMessages(activeLocale);
|
|
103
|
-
applyTranslations();
|
|
104
|
-
onLanguageChanged?.(api);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const api = {
|
|
108
|
-
activateTab,
|
|
109
|
-
applyTranslations,
|
|
110
|
-
getActiveLocale: () => activeLocale,
|
|
111
|
-
getCurrentStatus: () => activeStatus,
|
|
112
|
-
getErrorStatusKey,
|
|
113
|
-
getLanguagePreference: () => languagePreference,
|
|
114
|
-
getMessages: () => messages,
|
|
115
|
-
handleLanguagePreferenceChange,
|
|
116
|
-
initializeI18n,
|
|
117
|
-
initializeSidePanelTabs,
|
|
118
|
-
setCount,
|
|
119
|
-
setStatus,
|
|
120
|
-
t,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return api;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
global.LinkLightSidePanelBootstrap = { createSidePanelBootstrap };
|
|
127
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelBootstrap(global) {
|
|
2
|
+
function createSidePanelBootstrap({
|
|
3
|
+
extensionRuntime,
|
|
4
|
+
languagePreferenceStorageKey,
|
|
5
|
+
localeDirectories,
|
|
6
|
+
fallbackLocale = "zh-CN",
|
|
7
|
+
sidePanelTabs,
|
|
8
|
+
elements,
|
|
9
|
+
initialStatusKey = "statusWaiting",
|
|
10
|
+
onAfterStaticTranslations,
|
|
11
|
+
onDisabledTab,
|
|
12
|
+
onTabActivated,
|
|
13
|
+
onLanguageChanged,
|
|
14
|
+
}) {
|
|
15
|
+
const { interpolate, loadLocaleMessageMap, normalizeLanguagePreference, resolveLocale } = global.LinkLightSidePanelI18n;
|
|
16
|
+
const { updateCount, updateStatus } = global.LinkLightSidePanelStatus;
|
|
17
|
+
const { applySidePanelTranslations } = global.LinkLightSidePanelTranslations;
|
|
18
|
+
const {
|
|
19
|
+
activateSidePanelTab,
|
|
20
|
+
initializeSidePanelTabs: initializeSharedSidePanelTabs,
|
|
21
|
+
} = global.LinkLightSidePanelTabs;
|
|
22
|
+
|
|
23
|
+
let messages = {};
|
|
24
|
+
let languagePreference = "auto";
|
|
25
|
+
let activeLocale = fallbackLocale;
|
|
26
|
+
const activeStatus = { key: initialStatusKey, values: {} };
|
|
27
|
+
|
|
28
|
+
function t(key, values = {}) {
|
|
29
|
+
return interpolate(messages[key] ?? key, values);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function readLanguagePreference() {
|
|
33
|
+
const result = await extensionRuntime.storage.get([languagePreferenceStorageKey]);
|
|
34
|
+
return normalizeLanguagePreference(result?.[languagePreferenceStorageKey]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function saveLanguagePreference(preference) {
|
|
38
|
+
await extensionRuntime.storage.set({ [languagePreferenceStorageKey]: normalizeLanguagePreference(preference) });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function loadMessages(locale) {
|
|
42
|
+
messages = await loadLocaleMessageMap({ runtime: extensionRuntime, locale, localeDirectories, fallbackLocale });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function applyTranslations() {
|
|
46
|
+
applySidePanelTranslations({
|
|
47
|
+
t,
|
|
48
|
+
locale: activeLocale,
|
|
49
|
+
languageInput: elements.languageInput,
|
|
50
|
+
languagePreference,
|
|
51
|
+
safetyNote: elements.safetyNote,
|
|
52
|
+
onAfterStaticTranslations,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function setStatus(key, values = {}) {
|
|
57
|
+
updateStatus({ state: activeStatus, key, values, statusText: elements.statusText, t });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function setCount(value) {
|
|
61
|
+
updateCount({ count: elements.count, value, t });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getErrorStatusKey(error, fallbackKey) {
|
|
65
|
+
const key = error instanceof Error ? error.message : "";
|
|
66
|
+
return messages[key] ? key : fallbackKey;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function activateTab(tabId) {
|
|
70
|
+
activateSidePanelTab(tabId);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function initializeSidePanelTabs() {
|
|
74
|
+
initializeSharedSidePanelTabs({
|
|
75
|
+
tabs: sidePanelTabs,
|
|
76
|
+
onActivate: (tab) => {
|
|
77
|
+
activateTab(tab.id);
|
|
78
|
+
onTabActivated?.(tab, api);
|
|
79
|
+
},
|
|
80
|
+
onDisabled: (tab) => {
|
|
81
|
+
if (typeof onDisabledTab === "function") {
|
|
82
|
+
onDisabledTab(tab, api);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setStatus("statusFeatureComingSoon", { feature: t(tab.labelKey) });
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function initializeI18n() {
|
|
91
|
+
languagePreference = await readLanguagePreference();
|
|
92
|
+
activeLocale = resolveLocale({ preference: languagePreference, runtime: extensionRuntime, fallbackLocale });
|
|
93
|
+
await loadMessages(activeLocale);
|
|
94
|
+
applyTranslations();
|
|
95
|
+
setStatus(initialStatusKey);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function handleLanguagePreferenceChange() {
|
|
99
|
+
languagePreference = normalizeLanguagePreference(elements.languageInput.value);
|
|
100
|
+
await saveLanguagePreference(languagePreference);
|
|
101
|
+
activeLocale = resolveLocale({ preference: languagePreference, runtime: extensionRuntime, fallbackLocale });
|
|
102
|
+
await loadMessages(activeLocale);
|
|
103
|
+
applyTranslations();
|
|
104
|
+
onLanguageChanged?.(api);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const api = {
|
|
108
|
+
activateTab,
|
|
109
|
+
applyTranslations,
|
|
110
|
+
getActiveLocale: () => activeLocale,
|
|
111
|
+
getCurrentStatus: () => activeStatus,
|
|
112
|
+
getErrorStatusKey,
|
|
113
|
+
getLanguagePreference: () => languagePreference,
|
|
114
|
+
getMessages: () => messages,
|
|
115
|
+
handleLanguagePreferenceChange,
|
|
116
|
+
initializeI18n,
|
|
117
|
+
initializeSidePanelTabs,
|
|
118
|
+
setCount,
|
|
119
|
+
setStatus,
|
|
120
|
+
t,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return api;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
global.LinkLightSidePanelBootstrap = { createSidePanelBootstrap };
|
|
127
|
+
})(globalThis);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelDom(global) {
|
|
2
|
-
function appendText(parent, className, text) {
|
|
3
|
-
const element = global.document.createElement("div");
|
|
4
|
-
element.className = className;
|
|
5
|
-
element.textContent = text;
|
|
6
|
-
parent.append(element);
|
|
7
|
-
return element;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function setBusy(button, busy) {
|
|
11
|
-
button.disabled = busy;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
global.LinkLightSidePanelDom = { appendText, setBusy };
|
|
15
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelDom(global) {
|
|
2
|
+
function appendText(parent, className, text) {
|
|
3
|
+
const element = global.document.createElement("div");
|
|
4
|
+
element.className = className;
|
|
5
|
+
element.textContent = text;
|
|
6
|
+
parent.append(element);
|
|
7
|
+
return element;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function setBusy(button, busy) {
|
|
11
|
+
button.disabled = busy;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
global.LinkLightSidePanelDom = { appendText, setBusy };
|
|
15
|
+
})(globalThis);
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelI18n(global) {
|
|
2
|
-
function normalizeChromeLocale(locale, fallbackLocale = "zh-CN") {
|
|
3
|
-
const normalized = String(locale || "").toLowerCase();
|
|
4
|
-
if (normalized.startsWith("en")) return "en-US";
|
|
5
|
-
return fallbackLocale;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function normalizeLanguagePreference(value) {
|
|
9
|
-
if (value === "zh-CN" || value === "en-US") return value;
|
|
10
|
-
return "auto";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function resolveLocale({ preference, runtime, fallbackLocale = "zh-CN" }) {
|
|
14
|
-
if (preference === "zh-CN" || preference === "en-US") return preference;
|
|
15
|
-
return normalizeChromeLocale(runtime.getUILocale(), fallbackLocale);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function interpolate(template, values = {}) {
|
|
19
|
-
return String(template || "").replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function loadLocaleMessageMap({ runtime, locale, localeDirectories, fallbackLocale = "zh-CN" }) {
|
|
23
|
-
const directory = localeDirectories[locale] ?? localeDirectories[fallbackLocale];
|
|
24
|
-
const catalog = await runtime.loadLocaleMessages(directory);
|
|
25
|
-
return Object.fromEntries(
|
|
26
|
-
Object.entries(catalog).map(([key, value]) => [key, typeof value?.message === "string" ? value.message : ""]),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
global.LinkLightSidePanelI18n = {
|
|
31
|
-
interpolate,
|
|
32
|
-
loadLocaleMessageMap,
|
|
33
|
-
normalizeChromeLocale,
|
|
34
|
-
normalizeLanguagePreference,
|
|
35
|
-
resolveLocale,
|
|
36
|
-
};
|
|
37
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelI18n(global) {
|
|
2
|
+
function normalizeChromeLocale(locale, fallbackLocale = "zh-CN") {
|
|
3
|
+
const normalized = String(locale || "").toLowerCase();
|
|
4
|
+
if (normalized.startsWith("en")) return "en-US";
|
|
5
|
+
return fallbackLocale;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function normalizeLanguagePreference(value) {
|
|
9
|
+
if (value === "zh-CN" || value === "en-US") return value;
|
|
10
|
+
return "auto";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function resolveLocale({ preference, runtime, fallbackLocale = "zh-CN" }) {
|
|
14
|
+
if (preference === "zh-CN" || preference === "en-US") return preference;
|
|
15
|
+
return normalizeChromeLocale(runtime.getUILocale(), fallbackLocale);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function interpolate(template, values = {}) {
|
|
19
|
+
return String(template || "").replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function loadLocaleMessageMap({ runtime, locale, localeDirectories, fallbackLocale = "zh-CN" }) {
|
|
23
|
+
const directory = localeDirectories[locale] ?? localeDirectories[fallbackLocale];
|
|
24
|
+
const catalog = await runtime.loadLocaleMessages(directory);
|
|
25
|
+
return Object.fromEntries(
|
|
26
|
+
Object.entries(catalog).map(([key, value]) => [key, typeof value?.message === "string" ? value.message : ""]),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
global.LinkLightSidePanelI18n = {
|
|
31
|
+
interpolate,
|
|
32
|
+
loadLocaleMessageMap,
|
|
33
|
+
normalizeChromeLocale,
|
|
34
|
+
normalizeLanguagePreference,
|
|
35
|
+
resolveLocale,
|
|
36
|
+
};
|
|
37
|
+
})(globalThis);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelImportPreview(global) {
|
|
2
|
-
function filterImportableDrafts(drafts, predicate) {
|
|
3
|
-
return (drafts || []).filter(predicate);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
global.LinkLightSidePanelImportPreview = { filterImportableDrafts };
|
|
7
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelImportPreview(global) {
|
|
2
|
+
function filterImportableDrafts(drafts, predicate) {
|
|
3
|
+
return (drafts || []).filter(predicate);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
global.LinkLightSidePanelImportPreview = { filterImportableDrafts };
|
|
7
|
+
})(globalThis);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelStatus(global) {
|
|
2
|
-
function updateStatus({ state, key, values = {}, statusText, t }) {
|
|
3
|
-
state.key = key;
|
|
4
|
-
state.values = values;
|
|
5
|
-
statusText.textContent = t(key, values);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function updateCount({ count, value, t }) {
|
|
9
|
-
count.textContent = t("countLabel", { count: value });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
global.LinkLightSidePanelStatus = { updateCount, updateStatus };
|
|
13
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelStatus(global) {
|
|
2
|
+
function updateStatus({ state, key, values = {}, statusText, t }) {
|
|
3
|
+
state.key = key;
|
|
4
|
+
state.values = values;
|
|
5
|
+
statusText.textContent = t(key, values);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function updateCount({ count, value, t }) {
|
|
9
|
+
count.textContent = t("countLabel", { count: value });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
global.LinkLightSidePanelStatus = { updateCount, updateStatus };
|
|
13
|
+
})(globalThis);
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
(function initializeLinkLightSidePanelTabs(global) {
|
|
2
|
-
function activateSidePanelTab(tabId, { documentRef = global.document } = {}) {
|
|
3
|
-
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
4
|
-
if (button.dataset.tab === tabId) button.setAttribute("aria-current", "page");
|
|
5
|
-
else button.removeAttribute("aria-current");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
for (const panel of documentRef.querySelectorAll("[data-tab-panel]")) {
|
|
9
|
-
panel.hidden = panel.dataset.tabPanel !== tabId;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function initializeSidePanelTabs({
|
|
14
|
-
tabs,
|
|
15
|
-
documentRef = global.document,
|
|
16
|
-
onActivate,
|
|
17
|
-
onDisabled,
|
|
18
|
-
}) {
|
|
19
|
-
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
20
|
-
const tab = tabs.find((item) => item.id === button.dataset.tab);
|
|
21
|
-
if (!tab) continue;
|
|
22
|
-
|
|
23
|
-
button.addEventListener("click", () => {
|
|
24
|
-
if (tab.disabled) {
|
|
25
|
-
onDisabled?.(tab);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onActivate?.(tab);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
global.LinkLightSidePanelTabs = { activateSidePanelTab, initializeSidePanelTabs };
|
|
35
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSidePanelTabs(global) {
|
|
2
|
+
function activateSidePanelTab(tabId, { documentRef = global.document } = {}) {
|
|
3
|
+
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
4
|
+
if (button.dataset.tab === tabId) button.setAttribute("aria-current", "page");
|
|
5
|
+
else button.removeAttribute("aria-current");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
for (const panel of documentRef.querySelectorAll("[data-tab-panel]")) {
|
|
9
|
+
panel.hidden = panel.dataset.tabPanel !== tabId;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function initializeSidePanelTabs({
|
|
14
|
+
tabs,
|
|
15
|
+
documentRef = global.document,
|
|
16
|
+
onActivate,
|
|
17
|
+
onDisabled,
|
|
18
|
+
}) {
|
|
19
|
+
for (const button of documentRef.querySelectorAll("[data-tab]")) {
|
|
20
|
+
const tab = tabs.find((item) => item.id === button.dataset.tab);
|
|
21
|
+
if (!tab) continue;
|
|
22
|
+
|
|
23
|
+
button.addEventListener("click", () => {
|
|
24
|
+
if (tab.disabled) {
|
|
25
|
+
onDisabled?.(tab);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onActivate?.(tab);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
global.LinkLightSidePanelTabs = { activateSidePanelTab, initializeSidePanelTabs };
|
|
35
|
+
})(globalThis);
|