ds-one 0.2.0-alpha.2 → 0.2.0-alpha.3
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/DS1/1-root/one.css +1 -1
- package/DS1/utils/cdn-loader.ts +20 -44
- package/README.md +3 -3
- package/dist/ds-one.bundle.js +16 -36
- package/dist/ds-one.bundle.js.map +2 -2
- package/dist/ds-one.bundle.min.js +32 -32
- package/dist/ds-one.bundle.min.js.map +3 -3
- package/dist/utils/cdn-loader.d.ts.map +1 -1
- package/dist/utils/cdn-loader.js +20 -38
- package/package.json +1 -1
package/DS1/1-root/one.css
CHANGED
package/DS1/utils/cdn-loader.ts
CHANGED
|
@@ -17,20 +17,7 @@ declare global {
|
|
|
17
17
|
// Track if we've already attempted to load
|
|
18
18
|
let loadAttempted = false;
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
"./keys.json",
|
|
22
|
-
"./tekst.json",
|
|
23
|
-
"./tekster.json",
|
|
24
|
-
"./language.json",
|
|
25
|
-
"./languages.json",
|
|
26
|
-
"./translations.json",
|
|
27
|
-
"./translate.json",
|
|
28
|
-
"./i18n.json",
|
|
29
|
-
"./locales.json",
|
|
30
|
-
"./strings.json",
|
|
31
|
-
"./text.json",
|
|
32
|
-
"./texts.json",
|
|
33
|
-
];
|
|
20
|
+
const DEFAULT_TRANSLATION_FILE = "./translations.json";
|
|
34
21
|
|
|
35
22
|
function normalizeCandidate(path: string): string | null {
|
|
36
23
|
if (!path) {
|
|
@@ -86,26 +73,29 @@ function findAttributeCandidate(): string | null {
|
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
function resolveTranslationSources(): string[] {
|
|
89
|
-
const candidates =
|
|
76
|
+
const candidates: string[] = [];
|
|
90
77
|
|
|
91
78
|
const windowCandidate =
|
|
92
79
|
typeof window !== "undefined" ? window.DS_ONE_TRANSLATIONS_FILE : null;
|
|
93
80
|
const attributeCandidate = findAttributeCandidate();
|
|
94
81
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
82
|
+
// Only use explicitly configured paths, or the single default
|
|
83
|
+
const windowNormalized = normalizeCandidate(windowCandidate ?? "");
|
|
84
|
+
if (windowNormalized) {
|
|
85
|
+
candidates.push(windowNormalized);
|
|
86
|
+
}
|
|
101
87
|
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
const attrNormalized = normalizeCandidate(attributeCandidate ?? "");
|
|
89
|
+
if (attrNormalized && !candidates.includes(attrNormalized)) {
|
|
90
|
+
candidates.push(attrNormalized);
|
|
91
|
+
}
|
|
104
92
|
|
|
105
|
-
//
|
|
106
|
-
|
|
93
|
+
// Only try default if no explicit path was configured
|
|
94
|
+
if (candidates.length === 0) {
|
|
95
|
+
candidates.push(DEFAULT_TRANSLATION_FILE);
|
|
96
|
+
}
|
|
107
97
|
|
|
108
|
-
return
|
|
98
|
+
return candidates;
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
function validateTranslationMap(
|
|
@@ -124,16 +114,14 @@ async function fetchTranslationFile(
|
|
|
124
114
|
source: string
|
|
125
115
|
): Promise<TranslationMap | null> {
|
|
126
116
|
try {
|
|
127
|
-
console.log(`[DS one] Attempting to fetch translations from: ${source}`);
|
|
128
117
|
const response = await fetch(source);
|
|
129
118
|
|
|
130
119
|
if (!response.ok) {
|
|
131
|
-
|
|
120
|
+
// 404 is expected if no translations file exists - don't log as error
|
|
132
121
|
return null;
|
|
133
122
|
}
|
|
134
123
|
|
|
135
124
|
const translations = await response.json();
|
|
136
|
-
console.log(`[DS one] Successfully fetched JSON from ${source}`);
|
|
137
125
|
|
|
138
126
|
if (!validateTranslationMap(translations)) {
|
|
139
127
|
console.warn(
|
|
@@ -148,21 +136,9 @@ async function fetchTranslationFile(
|
|
|
148
136
|
return null;
|
|
149
137
|
}
|
|
150
138
|
|
|
151
|
-
console.log(`[DS one] Valid translations found: ${languages.join(", ")}`);
|
|
152
139
|
return translations;
|
|
153
|
-
} catch
|
|
154
|
-
|
|
155
|
-
error instanceof TypeError &&
|
|
156
|
-
error.message.includes("Failed to fetch")
|
|
157
|
-
) {
|
|
158
|
-
console.log(`[DS one] Network error fetching ${source}`);
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
console.error(
|
|
163
|
-
`[DS one] Error loading external translations from ${source}:`,
|
|
164
|
-
error
|
|
165
|
-
);
|
|
140
|
+
} catch {
|
|
141
|
+
// Silently fail - file likely doesn't exist or isn't valid JSON
|
|
166
142
|
return null;
|
|
167
143
|
}
|
|
168
144
|
}
|
|
@@ -212,7 +188,7 @@ export async function loadExternalTranslations(): Promise<boolean> {
|
|
|
212
188
|
}
|
|
213
189
|
|
|
214
190
|
console.info(
|
|
215
|
-
`[DS one] No external translations found
|
|
191
|
+
`[DS one] No external translations found at ${sources[0] ?? DEFAULT_TRANSLATION_FILE}. Using bundled translations.`
|
|
216
192
|
);
|
|
217
193
|
|
|
218
194
|
return false;
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npm install ds-one@alpha
|
|
|
26
26
|
yarn add ds-one@alpha
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
**Note**: Currently published as alpha version `0.2.0-alpha.
|
|
29
|
+
**Note**: Currently published as alpha version `0.2.0-alpha.3`. Use `@alpha` tag to install.
|
|
30
30
|
|
|
31
31
|
### Basic Usage (CDN)
|
|
32
32
|
|
|
@@ -86,7 +86,7 @@ Try DS one in your browser: **[dsone.dev](https://dsone.dev)** (documentation sl
|
|
|
86
86
|
- **[Internationalization](./docs/i18n.md)** - Language keys and Notion CMS setup
|
|
87
87
|
- **[Examples](./docs/examples.md)** - Usage examples and patterns
|
|
88
88
|
|
|
89
|
-
## Current Status: v0.2.0-alpha.
|
|
89
|
+
## Current Status: v0.2.0-alpha.3
|
|
90
90
|
|
|
91
91
|
**⚠️ Alpha Release**: This is an early alpha version. The API may change as we refine the components and architecture.
|
|
92
92
|
|
|
@@ -183,7 +183,7 @@ bun run build
|
|
|
183
183
|
|
|
184
184
|
```bash
|
|
185
185
|
# Create a new alpha release (recommended for now)
|
|
186
|
-
bun run release:pre:alpha # Bumps alpha version (e.g., 0.2.0-alpha.
|
|
186
|
+
bun run release:pre:alpha # Bumps alpha version (e.g., 0.2.0-alpha.3 → 0.2.0-alpha.3)
|
|
187
187
|
|
|
188
188
|
# Other release commands (for future use)
|
|
189
189
|
bun run release:patch # For patch releases
|
package/dist/ds-one.bundle.js
CHANGED
|
@@ -78,20 +78,7 @@ if (typeof window !== "undefined") {
|
|
|
78
78
|
|
|
79
79
|
// dist/utils/cdn-loader.js
|
|
80
80
|
var loadAttempted = false;
|
|
81
|
-
var
|
|
82
|
-
"./keys.json",
|
|
83
|
-
"./tekst.json",
|
|
84
|
-
"./tekster.json",
|
|
85
|
-
"./language.json",
|
|
86
|
-
"./languages.json",
|
|
87
|
-
"./translations.json",
|
|
88
|
-
"./translate.json",
|
|
89
|
-
"./i18n.json",
|
|
90
|
-
"./locales.json",
|
|
91
|
-
"./strings.json",
|
|
92
|
-
"./text.json",
|
|
93
|
-
"./texts.json"
|
|
94
|
-
];
|
|
81
|
+
var DEFAULT_TRANSLATION_FILE = "./translations.json";
|
|
95
82
|
function normalizeCandidate(path) {
|
|
96
83
|
if (!path) {
|
|
97
84
|
return null;
|
|
@@ -125,19 +112,21 @@ function findAttributeCandidate() {
|
|
|
125
112
|
return null;
|
|
126
113
|
}
|
|
127
114
|
function resolveTranslationSources() {
|
|
128
|
-
const candidates =
|
|
115
|
+
const candidates = [];
|
|
129
116
|
const windowCandidate = typeof window !== "undefined" ? window.DS_ONE_TRANSLATIONS_FILE : null;
|
|
130
117
|
const attributeCandidate = findAttributeCandidate();
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
118
|
+
const windowNormalized = normalizeCandidate(windowCandidate ?? "");
|
|
119
|
+
if (windowNormalized) {
|
|
120
|
+
candidates.push(windowNormalized);
|
|
121
|
+
}
|
|
122
|
+
const attrNormalized = normalizeCandidate(attributeCandidate ?? "");
|
|
123
|
+
if (attrNormalized && !candidates.includes(attrNormalized)) {
|
|
124
|
+
candidates.push(attrNormalized);
|
|
125
|
+
}
|
|
126
|
+
if (candidates.length === 0) {
|
|
127
|
+
candidates.push(DEFAULT_TRANSLATION_FILE);
|
|
128
|
+
}
|
|
129
|
+
return candidates;
|
|
141
130
|
}
|
|
142
131
|
function validateTranslationMap(candidate) {
|
|
143
132
|
if (!candidate || typeof candidate !== "object") {
|
|
@@ -147,14 +136,11 @@ function validateTranslationMap(candidate) {
|
|
|
147
136
|
}
|
|
148
137
|
async function fetchTranslationFile(source) {
|
|
149
138
|
try {
|
|
150
|
-
console.log(`[DS one] Attempting to fetch translations from: ${source}`);
|
|
151
139
|
const response = await fetch(source);
|
|
152
140
|
if (!response.ok) {
|
|
153
|
-
console.log(`[DS one] Failed to fetch ${source} (${response.status})`);
|
|
154
141
|
return null;
|
|
155
142
|
}
|
|
156
143
|
const translations = await response.json();
|
|
157
|
-
console.log(`[DS one] Successfully fetched JSON from ${source}`);
|
|
158
144
|
if (!validateTranslationMap(translations)) {
|
|
159
145
|
console.warn(`[DS one] Invalid translation format in ${source}. Expected object with language codes as keys.`);
|
|
160
146
|
return null;
|
|
@@ -164,14 +150,8 @@ async function fetchTranslationFile(source) {
|
|
|
164
150
|
console.warn(`[DS one] No languages found in ${source}`);
|
|
165
151
|
return null;
|
|
166
152
|
}
|
|
167
|
-
console.log(`[DS one] Valid translations found: ${languages.join(", ")}`);
|
|
168
153
|
return translations;
|
|
169
|
-
} catch
|
|
170
|
-
if (error instanceof TypeError && error.message.includes("Failed to fetch")) {
|
|
171
|
-
console.log(`[DS one] Network error fetching ${source}`);
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
console.error(`[DS one] Error loading external translations from ${source}:`, error);
|
|
154
|
+
} catch {
|
|
175
155
|
return null;
|
|
176
156
|
}
|
|
177
157
|
}
|
|
@@ -199,7 +179,7 @@ async function loadExternalTranslations() {
|
|
|
199
179
|
window.dispatchEvent(new CustomEvent("translations-ready"));
|
|
200
180
|
return true;
|
|
201
181
|
}
|
|
202
|
-
console.info(`[DS one] No external translations found
|
|
182
|
+
console.info(`[DS one] No external translations found at ${sources[0] ?? DEFAULT_TRANSLATION_FILE}. Using bundled translations.`);
|
|
203
183
|
return false;
|
|
204
184
|
}
|
|
205
185
|
if (typeof window !== "undefined") {
|