@pure-ds/core 0.7.30 → 0.7.33
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/.github/copilot-instructions.md +20 -11
- package/LOCALIZATION.md +197 -0
- package/dist/types/pds.config.d.ts +1 -1
- package/dist/types/pds.config.d.ts.map +1 -1
- package/dist/types/pds.d.ts +150 -0
- package/dist/types/public/assets/pds/components/pds-form.d.ts +2 -2
- package/dist/types/public/assets/pds/components/pds-form.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts +2 -2
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-rating.d.ts +1 -119
- package/dist/types/public/assets/pds/components/pds-rating.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-treeview.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-upload.d.ts.map +1 -1
- package/dist/types/src/js/common/ask.d.ts.map +1 -1
- package/dist/types/src/js/common/font-loader.d.ts.map +1 -1
- package/dist/types/src/js/common/localization-resource-provider.d.ts +49 -0
- package/dist/types/src/js/common/localization-resource-provider.d.ts.map +1 -0
- package/dist/types/src/js/common/localization.d.ts +25 -0
- package/dist/types/src/js/common/localization.d.ts.map +1 -0
- package/dist/types/src/js/common/msg.d.ts +1 -2
- package/dist/types/src/js/common/msg.d.ts.map +1 -1
- package/dist/types/src/js/common/pds-log.d.ts +3 -0
- package/dist/types/src/js/common/pds-log.d.ts.map +1 -0
- package/dist/types/src/js/lit.d.ts +0 -7
- package/dist/types/src/js/lit.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-config.d.ts +51 -0
- package/dist/types/src/js/pds-core/pds-config.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-registry.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-runtime.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-start-helpers.d.ts.map +1 -1
- package/dist/types/src/js/pds-localization.d.ts +3 -0
- package/dist/types/src/js/pds-localization.d.ts.map +1 -0
- package/dist/types/src/js/pds-singleton.d.ts +13 -0
- package/dist/types/src/js/pds-singleton.d.ts.map +1 -0
- package/dist/types/src/js/pds.d.ts +9 -1
- package/dist/types/src/js/pds.d.ts.map +1 -1
- package/package.json +10 -4
- package/packages/pds-cli/README.md +2 -0
- package/packages/pds-cli/lib/pds-mcp-core.js +2 -2
- package/public/assets/js/app.js +9 -11
- package/public/assets/js/lit.js +3 -94
- package/public/assets/js/pds-ask.js +4 -4
- package/public/assets/js/pds-enhancers.js +1 -1
- package/public/assets/js/pds-localization.js +1 -0
- package/public/assets/js/pds-manager.js +118 -118
- package/public/assets/js/pds.js +2 -2
- package/public/assets/pds/components/pds-calendar.js +4 -4
- package/public/assets/pds/components/pds-daterange.js +11 -8
- package/public/assets/pds/components/pds-form.js +22 -22
- package/public/assets/pds/components/pds-live-edit.js +503 -42
- package/public/assets/pds/components/pds-live-importer.js +66 -66
- package/public/assets/pds/components/pds-live-template-canvas.js +3 -3
- package/public/assets/pds/components/pds-omnibox.js +4 -4
- package/public/assets/pds/components/pds-rating.js +5 -3
- package/public/assets/pds/components/pds-tags.js +5 -5
- package/public/assets/pds/components/pds-theme.js +4 -4
- package/public/assets/pds/components/pds-toaster.js +6 -6
- package/public/assets/pds/components/pds-treeview.js +8 -4
- package/public/assets/pds/components/pds-upload.js +7 -6
- package/public/assets/pds/core/pds-ask.js +4 -4
- package/public/assets/pds/core/pds-enhancers.js +1 -1
- package/public/assets/pds/core/pds-localization.js +1 -0
- package/public/assets/pds/core/pds-manager.js +118 -118
- package/public/assets/pds/core.js +2 -2
- package/public/assets/pds/external/lit.js +3 -94
- package/readme.md +34 -6
- package/src/js/common/ask.js +530 -0
- package/src/js/common/common.js +122 -0
- package/src/js/common/font-loader.js +202 -0
- package/src/js/common/localization-resource-provider.js +274 -0
- package/src/js/common/localization.js +839 -0
- package/src/js/common/msg.js +9 -0
- package/src/js/common/pds-core/pds.d.ts +128 -0
- package/src/js/common/pds-log.js +144 -0
- package/src/js/common/toast.js +122 -0
- package/src/js/pds-core/pds-config.js +51 -10
- package/src/js/pds-core/pds-enhancers.js +5 -3
- package/src/js/pds-core/pds-live.js +7 -5
- package/src/js/pds-core/pds-registry.js +6 -4
- package/src/js/pds-core/pds-runtime.js +12 -8
- package/src/js/pds-core/pds-start-helpers.js +9 -4
- package/src/js/pds-singleton.js +49 -0
- package/src/js/pds.d.ts +150 -0
- package/src/js/pds.js +420 -40
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { AutoDefiner as CoreAutoDefiner } from "pure-web/auto-definer";
|
|
7
|
+
import { PDS } from "../pds-singleton.js";
|
|
7
8
|
|
|
8
9
|
const __ABSOLUTE_URL_PATTERN__ = /^[a-z][a-z0-9+\-.]*:\/\//i;
|
|
9
10
|
const __MODULE_URL__ = (() => {
|
|
@@ -238,6 +239,7 @@ export function normalizeInitConfig(
|
|
|
238
239
|
mode, autoDefine, applyGlobalStyles, manageTheme,
|
|
239
240
|
themeStorageKey, preloadStyles, criticalLayers,
|
|
240
241
|
managerURL, manager,
|
|
242
|
+
localization,
|
|
241
243
|
preset: _preset, design: _design, enhancers: _enhancers,
|
|
242
244
|
log: userLog,
|
|
243
245
|
...otherProps
|
|
@@ -429,17 +431,19 @@ export async function setupAutoDefinerAndEnhancers(options, { baseEnhancers = []
|
|
|
429
431
|
err?.message?.includes("Failed to resolve module specifier");
|
|
430
432
|
|
|
431
433
|
if (isLitComponent && isMissingLitError) {
|
|
432
|
-
|
|
434
|
+
PDS.log(
|
|
435
|
+
"error",
|
|
433
436
|
`❌ PDS component <${tag}> requires Lit but #pds/lit is not in import map.
|
|
434
437
|
See: https://github.com/Pure-Web-Foundation/pure-ds/blob/main/readme.md#lit-components-not-working`
|
|
435
438
|
);
|
|
436
439
|
} else {
|
|
437
|
-
|
|
440
|
+
PDS.log(
|
|
441
|
+
"warn",
|
|
438
442
|
`⚠️ PDS component <${tag}> not found. Assets may not be installed.`
|
|
439
443
|
);
|
|
440
444
|
}
|
|
441
445
|
} else {
|
|
442
|
-
|
|
446
|
+
PDS.log("error", `❌ Auto-define error for <${tag}>:`, err);
|
|
443
447
|
}
|
|
444
448
|
},
|
|
445
449
|
// Apply all user overrides except mapper so we can still wrap it
|
|
@@ -457,7 +461,8 @@ export async function setupAutoDefinerAndEnhancers(options, { baseEnhancers = []
|
|
|
457
461
|
}
|
|
458
462
|
return mapped;
|
|
459
463
|
} catch (e) {
|
|
460
|
-
|
|
464
|
+
PDS.log(
|
|
465
|
+
"warn",
|
|
461
466
|
"Custom autoDefine.mapper error; falling back to default:",
|
|
462
467
|
e?.message || e
|
|
463
468
|
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class PDSBase extends EventTarget {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
/** @type {'live' | 'static' | null} */
|
|
5
|
+
this.mode = null;
|
|
6
|
+
/** @type {Record<string, any> | null} */
|
|
7
|
+
this.compiled = null;
|
|
8
|
+
/** @type {(level: 'log' | 'warn' | 'error' | 'debug' | 'info', message?: any, ...data: any[]) => void} */
|
|
9
|
+
this.log = () => {};
|
|
10
|
+
/** @type {((level: 'log' | 'warn' | 'error' | 'debug' | 'info', message?: any, ...data: any[]) => void) | null} */
|
|
11
|
+
this.logHandler = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PDS_SINGLETON_KEY = "__PURE_DS_PDS_SINGLETON__";
|
|
16
|
+
|
|
17
|
+
const globalScope = typeof globalThis !== "undefined" ? globalThis : window;
|
|
18
|
+
const existingPDS = globalScope?.[PDS_SINGLETON_KEY];
|
|
19
|
+
|
|
20
|
+
export const PDS =
|
|
21
|
+
existingPDS && typeof existingPDS.addEventListener === "function"
|
|
22
|
+
? existingPDS
|
|
23
|
+
: new PDSBase();
|
|
24
|
+
|
|
25
|
+
if (globalScope) {
|
|
26
|
+
globalScope[PDS_SINGLETON_KEY] = PDS;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof PDS.log !== "function") {
|
|
30
|
+
PDS.log = (level = "log", message, ...data) => {
|
|
31
|
+
if (typeof console === "undefined") return;
|
|
32
|
+
const method =
|
|
33
|
+
typeof console[level] === "function"
|
|
34
|
+
? console[level].bind(console)
|
|
35
|
+
: typeof console.log === "function"
|
|
36
|
+
? console.log.bind(console)
|
|
37
|
+
: null;
|
|
38
|
+
if (!method) return;
|
|
39
|
+
if (data.length > 0) {
|
|
40
|
+
method(message, ...data);
|
|
41
|
+
} else {
|
|
42
|
+
method(message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof PDS.logHandler !== "function") {
|
|
48
|
+
PDS.logHandler = null;
|
|
49
|
+
}
|
package/src/js/pds.d.ts
CHANGED
|
@@ -107,6 +107,73 @@ export interface CompiledState {
|
|
|
107
107
|
/** Public config types for editor IntelliSense */
|
|
108
108
|
export type PDSInitConfig = import("./pds-core/pds-config.js").PDSInitConfig;
|
|
109
109
|
|
|
110
|
+
export interface PDSLocalizationMessages {
|
|
111
|
+
[key: string]: string | { content?: string };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface PDSLocalizationTranslateContext {
|
|
115
|
+
key: string;
|
|
116
|
+
values: any[];
|
|
117
|
+
options?: Record<string, any>;
|
|
118
|
+
locale: string;
|
|
119
|
+
defaultLocale: string;
|
|
120
|
+
messages: Record<string, string>;
|
|
121
|
+
messagesByLocale?: Record<string, Record<string, string>>;
|
|
122
|
+
template?: { strings: string[]; values: any[] } | null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface PDSLocalizationProvider {
|
|
126
|
+
translate?: (context: PDSLocalizationTranslateContext) => string | undefined | null;
|
|
127
|
+
loadLocale?: (context: {
|
|
128
|
+
locale: string;
|
|
129
|
+
defaultLocale: string;
|
|
130
|
+
reason?: string;
|
|
131
|
+
loadedLocales?: string[];
|
|
132
|
+
messages?: Record<string, string>;
|
|
133
|
+
load?: boolean;
|
|
134
|
+
}) =>
|
|
135
|
+
| Promise<PDSLocalizationMessages>
|
|
136
|
+
| PDSLocalizationMessages
|
|
137
|
+
| void;
|
|
138
|
+
setLocale?: (context: {
|
|
139
|
+
locale: string;
|
|
140
|
+
defaultLocale: string;
|
|
141
|
+
reason?: string;
|
|
142
|
+
loadedLocales?: string[];
|
|
143
|
+
messages?: Record<string, string>;
|
|
144
|
+
load?: boolean;
|
|
145
|
+
}) =>
|
|
146
|
+
| Promise<PDSLocalizationMessages>
|
|
147
|
+
| PDSLocalizationMessages
|
|
148
|
+
| void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface PDSLocalizationConfig {
|
|
152
|
+
locale?: string;
|
|
153
|
+
locales?: string[];
|
|
154
|
+
messages?: PDSLocalizationMessages;
|
|
155
|
+
provider?: PDSLocalizationProvider;
|
|
156
|
+
translate?: PDSLocalizationProvider["translate"];
|
|
157
|
+
loadLocale?: PDSLocalizationProvider["loadLocale"];
|
|
158
|
+
setLocale?: PDSLocalizationProvider["setLocale"];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface PDSJSONLocalizationOptions {
|
|
162
|
+
locale?: string;
|
|
163
|
+
locales?: string[];
|
|
164
|
+
basePath?: string;
|
|
165
|
+
aliases?: Record<string, string[]>;
|
|
166
|
+
requestInit?: RequestInit;
|
|
167
|
+
cache?: Map<string, PDSLocalizationMessages>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface PDSStrResult {
|
|
171
|
+
strTag: true;
|
|
172
|
+
strings: string[];
|
|
173
|
+
values: any[];
|
|
174
|
+
raw?: string[];
|
|
175
|
+
}
|
|
176
|
+
|
|
110
177
|
/**
|
|
111
178
|
* Generator - programmatic API to produce tokens, layered CSS and helper modules from a config.
|
|
112
179
|
* Typical usage:
|
|
@@ -264,6 +331,53 @@ export class PDS extends EventTarget {
|
|
|
264
331
|
static enums?: Record<string, any>;
|
|
265
332
|
static common?: Record<string, any>;
|
|
266
333
|
static parse?: (html: string) => Element[];
|
|
334
|
+
static msg: (template: string | PDSStrResult, options?: Record<string, any>) => string;
|
|
335
|
+
static str: (strings: TemplateStringsArray, ...values: any[]) => PDSStrResult;
|
|
336
|
+
static configureLocalization: (config?: PDSLocalizationConfig | null) => {
|
|
337
|
+
locale: string;
|
|
338
|
+
messages: Record<string, string>;
|
|
339
|
+
hasProvider: boolean;
|
|
340
|
+
};
|
|
341
|
+
static loadLocale: (locale: string) => Promise<Record<string, string>>;
|
|
342
|
+
static setLocale: (locale: string, options?: { load?: boolean }) => Promise<string>;
|
|
343
|
+
static getLocalizationState: () => {
|
|
344
|
+
locale: string;
|
|
345
|
+
messages: Record<string, string>;
|
|
346
|
+
hasProvider: boolean;
|
|
347
|
+
};
|
|
348
|
+
static createJSONLocalization: (
|
|
349
|
+
options?: PDSJSONLocalizationOptions
|
|
350
|
+
) => PDSLocalizationConfig;
|
|
351
|
+
static i18n: {
|
|
352
|
+
msg: (template: string | PDSStrResult, options?: Record<string, any>) => string;
|
|
353
|
+
str: (strings: TemplateStringsArray, ...values: any[]) => PDSStrResult;
|
|
354
|
+
configure: (config?: PDSLocalizationConfig | null) => {
|
|
355
|
+
locale: string;
|
|
356
|
+
messages: Record<string, string>;
|
|
357
|
+
hasProvider: boolean;
|
|
358
|
+
};
|
|
359
|
+
loadLocale: (locale: string) => Promise<Record<string, string>>;
|
|
360
|
+
setLocale: (locale: string, options?: { load?: boolean }) => Promise<string>;
|
|
361
|
+
getState: () => {
|
|
362
|
+
locale: string;
|
|
363
|
+
messages: Record<string, string>;
|
|
364
|
+
hasProvider: boolean;
|
|
365
|
+
};
|
|
366
|
+
createJSONLocalization: (
|
|
367
|
+
options?: PDSJSONLocalizationOptions
|
|
368
|
+
) => PDSLocalizationConfig;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Canonical logging entry point for PDS runtime and consuming apps.
|
|
372
|
+
*
|
|
373
|
+
* When `config.log(...)` is provided to `PDS.start(...)`, that handler
|
|
374
|
+
* is invoked through this method.
|
|
375
|
+
*/
|
|
376
|
+
static log(
|
|
377
|
+
level: 'log' | 'warn' | 'error' | 'debug' | 'info',
|
|
378
|
+
message?: any,
|
|
379
|
+
...data: any[]
|
|
380
|
+
): void;
|
|
267
381
|
static AutoComplete?: any;
|
|
268
382
|
static loadAutoComplete?: () => Promise<any>;
|
|
269
383
|
|
|
@@ -374,6 +488,7 @@ export class PDS extends EventTarget {
|
|
|
374
488
|
preloadStyles?: boolean;
|
|
375
489
|
criticalLayers?: string[];
|
|
376
490
|
managerURL?: string;
|
|
491
|
+
localization?: PDSLocalizationConfig;
|
|
377
492
|
// static-only
|
|
378
493
|
staticPaths?: Record<string, string>;
|
|
379
494
|
enhancers?: Array<any>;
|
|
@@ -394,6 +509,41 @@ export class PDS extends EventTarget {
|
|
|
394
509
|
preloadCritical?(config: any, options?: { theme?: string; layers?: string[] }): void;
|
|
395
510
|
}
|
|
396
511
|
|
|
512
|
+
export declare function msg(
|
|
513
|
+
template: string | PDSStrResult,
|
|
514
|
+
options?: Record<string, any>
|
|
515
|
+
): string;
|
|
516
|
+
|
|
517
|
+
export declare function str(
|
|
518
|
+
strings: TemplateStringsArray,
|
|
519
|
+
...values: any[]
|
|
520
|
+
): PDSStrResult;
|
|
521
|
+
|
|
522
|
+
export declare function configureLocalization(
|
|
523
|
+
config?: PDSLocalizationConfig | null
|
|
524
|
+
): {
|
|
525
|
+
locale: string;
|
|
526
|
+
messages: Record<string, string>;
|
|
527
|
+
hasProvider: boolean;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
export declare function loadLocale(locale: string): Promise<Record<string, string>>;
|
|
531
|
+
|
|
532
|
+
export declare function setLocale(
|
|
533
|
+
locale: string,
|
|
534
|
+
options?: { load?: boolean }
|
|
535
|
+
): Promise<string>;
|
|
536
|
+
|
|
537
|
+
export declare function getLocalizationState(): {
|
|
538
|
+
locale: string;
|
|
539
|
+
messages: Record<string, string>;
|
|
540
|
+
hasProvider: boolean;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
export declare function createJSONLocalization(
|
|
544
|
+
options?: PDSJSONLocalizationOptions
|
|
545
|
+
): PDSLocalizationConfig;
|
|
546
|
+
|
|
397
547
|
export { PDS as default };
|
|
398
548
|
|
|
399
549
|
// ===== pds-form Types =====
|