@pure-ds/core 0.5.40 → 0.5.42

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.
Files changed (38) hide show
  1. package/.cursorrules +3 -1
  2. package/.github/copilot-instructions.md +3 -1
  3. package/dist/types/pds.d.ts +4 -0
  4. package/dist/types/public/assets/js/lit-lazy-props.d.ts +6 -0
  5. package/dist/types/public/assets/js/lit-lazy-props.d.ts.map +1 -0
  6. package/dist/types/public/assets/js/lit-msg.d.ts +3 -0
  7. package/dist/types/public/assets/js/lit-msg.d.ts.map +1 -0
  8. package/dist/types/public/assets/js/pds-manager.d.ts +426 -141
  9. package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -1
  10. package/dist/types/public/assets/js/pds.d.ts +4 -3
  11. package/dist/types/public/assets/js/pds.d.ts.map +1 -1
  12. package/dist/types/src/js/common/common.d.ts +6 -0
  13. package/dist/types/src/js/common/common.d.ts.map +1 -1
  14. package/dist/types/src/js/lit-lazy-props.d.ts +21 -0
  15. package/dist/types/src/js/lit-lazy-props.d.ts.map +1 -0
  16. package/dist/types/src/js/lit-msg.d.ts +2 -0
  17. package/dist/types/src/js/lit-msg.d.ts.map +1 -0
  18. package/dist/types/src/js/lit.d.ts +2 -20
  19. package/dist/types/src/js/lit.d.ts.map +1 -1
  20. package/dist/types/src/js/pds.d.ts +33 -0
  21. package/dist/types/src/js/pds.d.ts.map +1 -1
  22. package/package.json +2 -1
  23. package/packages/pds-cli/bin/pds-static.js +17 -0
  24. package/packages/pds-cli/bin/templates/bootstrap/esbuild-dev.cjs +9 -0
  25. package/packages/pds-cli/bin/templates/bootstrap/esbuild-dev.mjs +11 -0
  26. package/packages/pds-cli/bin/templates/bootstrap/public/index.html +1 -1
  27. package/public/assets/js/app.js +12 -12
  28. package/public/assets/js/lit-lazy-props.js +47 -0
  29. package/public/assets/js/lit-msg.js +1 -0
  30. package/public/assets/js/lit.js +3 -3
  31. package/public/assets/js/pds-manager.js +4 -4
  32. package/public/assets/js/pds.js +6 -6
  33. package/public/assets/pds/external/lit-lazy-props.js +47 -0
  34. package/public/assets/pds/external/lit-msg.js +1 -0
  35. package/public/assets/pds/external/lit.js +131 -0
  36. package/readme.md +104 -4
  37. package/src/js/pds.d.ts +4 -0
  38. package/src/js/pds.js +22 -0
package/readme.md CHANGED
@@ -1405,7 +1405,7 @@ await PDS.start({ design: myPreset });
1405
1405
  <script type="importmap">
1406
1406
  {
1407
1407
  "imports": {
1408
- "#pds/lit": "https://cdn.jsdelivr.net/npm/lit@3/index.js"
1408
+ "#pds/lit": "https://cdn.jsdelivr.net/npm/@pure-ds/core@latest/public/assets/pds/external/lit.js"
1409
1409
  }
1410
1410
  }
1411
1411
  </script>
@@ -1775,6 +1775,8 @@ export default {
1775
1775
 
1776
1776
  **Symptoms:** `<pds-form>` or other Lit-based components fail to load with module resolution errors.
1777
1777
 
1778
+ See the dedicated Lit guide: [pds-lit-guide.md](pds-lit-guide.md).
1779
+
1778
1780
  **Components requiring Lit:**
1779
1781
  - `<pds-form>` - JSON Schema forms
1780
1782
  - `<pds-drawer>` - Drawer/sidebar panels
@@ -1785,28 +1787,126 @@ export default {
1785
1787
  <script type="importmap">
1786
1788
  {
1787
1789
  "imports": {
1788
- "#pds/lit": "/assets/js/lit.js"
1790
+ "#pds/lit": "/assets/pds/external/lit.js"
1789
1791
  }
1790
1792
  }
1791
1793
  </script>
1792
1794
  ```
1793
1795
 
1796
+ **About the bundle:** `#pds/lit` is a convenience bundle that re-exports official Lit APIs and adds PDS helpers:
1797
+ - `lazyProps` (waits for custom element definition before applying object props)
1798
+ - `msg()` (PDS localization helper)
1799
+ - `loadLocale()` (loads translation strings)
1800
+
1801
+ **Prefer not to use the bundle?** Create your own module and alias `#pds/lit` to it:
1802
+
1803
+ ```javascript
1804
+ // pds-lit.js (example)
1805
+ export * from "lit";
1806
+ export * from "lit/directives/repeat.js";
1807
+ export * from "lit/directives/keyed.js";
1808
+ export * from "lit/directives/class-map.js";
1809
+ export { ref, createRef } from "lit/directives/ref.js";
1810
+ export { ifDefined } from "lit/directives/if-defined.js";
1811
+ export { until } from "lit/directives/until.js";
1812
+ export { unsafeHTML } from "lit/directives/unsafe-html.js";
1813
+ export { unsafeSVG } from "lit/directives/unsafe-svg.js";
1814
+
1815
+ // Optional: use PDS localization helper
1816
+ // export { msg } from "@pure-ds/core/src/js/common/msg.js";
1817
+
1818
+ // Minimal lazyProps implementation (see src/js/lit.js)
1819
+ import { Directive, directive } from "lit/directive.js";
1820
+ class LazyPropsDirective extends Directive {
1821
+ #pendingProps = null;
1822
+ #element = null;
1823
+ render(_props) { return null; }
1824
+ update(part, [props]) {
1825
+ const element = part.element;
1826
+ if (this.#element !== element) {
1827
+ this.#element = element;
1828
+ this.#pendingProps = props;
1829
+ this.#applyProps();
1830
+ } else if (JSON.stringify(this.#pendingProps) !== JSON.stringify(props)) {
1831
+ this.#pendingProps = props;
1832
+ this.#applyProps();
1833
+ }
1834
+ return null;
1835
+ }
1836
+ async #applyProps() {
1837
+ if (!this.#element || !this.#pendingProps) return;
1838
+ await customElements.whenDefined(this.#element.tagName.toLowerCase());
1839
+ for (const [key, value] of Object.entries(this.#pendingProps)) {
1840
+ this.#element[key] = value;
1841
+ }
1842
+ }
1843
+ }
1844
+ export const lazyProps = directive(LazyPropsDirective);
1845
+ ```
1846
+
1794
1847
  Or in bundlers (Vite, Webpack, etc.):
1795
1848
 
1796
1849
  ```javascript
1797
1850
  // vite.config.js
1851
+ import path from 'node:path';
1852
+
1853
+ const pdsLitPath = path.resolve(
1854
+ __dirname,
1855
+ 'node_modules/@pure-ds/core/public/assets/pds/external/lit.js'
1856
+ );
1857
+
1798
1858
  export default {
1799
1859
  resolve: {
1800
- alias: { '#pds/lit': 'lit' }
1860
+ alias: { '#pds/lit': pdsLitPath }
1801
1861
  }
1802
1862
  };
1803
1863
 
1804
1864
  // webpack.config.js
1865
+ const path = require('node:path');
1866
+
1867
+ const pdsLitPath = path.resolve(
1868
+ __dirname,
1869
+ 'node_modules/@pure-ds/core/public/assets/pds/external/lit.js'
1870
+ );
1871
+
1805
1872
  module.exports = {
1806
1873
  resolve: {
1807
- alias: { '#pds/lit': 'lit' }
1874
+ alias: { '#pds/lit': pdsLitPath }
1808
1875
  }
1809
1876
  };
1877
+
1878
+ // esbuild
1879
+ const path = require('node:path');
1880
+ require('esbuild').build({
1881
+ alias: {
1882
+ '#pds/lit': path.resolve(
1883
+ process.cwd(),
1884
+ 'node_modules/@pure-ds/core/public/assets/pds/external/lit.js'
1885
+ )
1886
+ }
1887
+ });
1888
+
1889
+ // rollup (using @rollup/plugin-alias)
1890
+ import path from 'node:path';
1891
+
1892
+ alias({
1893
+ entries: [
1894
+ {
1895
+ find: '#pds/lit',
1896
+ replacement: path.resolve(
1897
+ __dirname,
1898
+ 'node_modules/@pure-ds/core/public/assets/pds/external/lit.js'
1899
+ )
1900
+ }
1901
+ ]
1902
+ });
1903
+
1904
+ // parcel (package.json)
1905
+ {
1906
+ "alias": {
1907
+ "#pds/lit": "node_modules/@pure-ds/core/public/assets/pds/external/lit.js"
1908
+ }
1909
+ }
1810
1910
  ```
1811
1911
 
1812
1912
  **Note:** Wait for components to load before accessing their APIs:
package/src/js/pds.d.ts CHANGED
@@ -159,6 +159,9 @@ export interface PDSEventMap {
159
159
  export class PDS extends EventTarget {
160
160
  // Static surface
161
161
  static registry: PDSRegistry;
162
+ static initializing?: boolean;
163
+ static currentPreset?: string | null;
164
+ static debug?: boolean;
162
165
  static applyStyles?: (generator?: Generator) => void;
163
166
  static adoptLayers: (shadowRoot: ShadowRoot, layers?: string[], additionalSheets?: CSSStyleSheet[]) => Promise<void>;
164
167
  static adoptPrimitives: (shadowRoot: ShadowRoot, additionalSheets?: CSSStyleSheet[]) => Promise<void>;
@@ -173,6 +176,7 @@ export class PDS extends EventTarget {
173
176
  static ontology?: any;
174
177
  static enums?: Record<string, any>;
175
178
  static common?: Record<string, any>;
179
+ static parse?: (html: string) => Element[];
176
180
  static query?: (question: string) => Promise<any[]>;
177
181
  static AutoComplete?: any;
178
182
  static loadAutoComplete?: () => Promise<any>;
package/src/js/pds.js CHANGED
@@ -22,12 +22,33 @@
22
22
  *
23
23
  * @typedef {Object} PDSAPI
24
24
  * @property {import("./pds-core/pds-registry.js").PDSRegistry} registry - Singleton runtime registry for live/static mode
25
+ * @property {boolean} initializing - Internal init guard (set while PDS.start is running)
26
+ * @property {string|null} currentPreset - Current preset id/name (legacy; may be null)
27
+ * @property {boolean} debug - Enable verbose runtime logging
25
28
  * @property {(generator?: import("./pds-core/pds-generator.js").Generator) => void} applyStyles - Apply generated styles to the document (live-only)
26
29
  * @property {(shadowRoot: ShadowRoot, layers?: string[], additionalSheets?: CSSStyleSheet[]) => Promise<void>} adoptLayers - Adopt multiple layers into a ShadowRoot. May log errors and fallback to additionalSheets when static imports fail.
27
30
  * @property {(shadowRoot: ShadowRoot, additionalSheets?: CSSStyleSheet[]) => Promise<void>} adoptPrimitives - Adopt primitives layer into a ShadowRoot. Designed as a convenience for components.
28
31
  * @property {(css:string) => CSSStyleSheet} createStylesheet - Create a constructable stylesheet from CSS text. @throws {DOMException} on invalid CSS in some browsers.
29
32
  * @property {() => boolean} isLiveMode - Returns true when running in live/designer-backed mode
30
33
  * @property {() => Promise<typeof import("./pds-core/pds-generator.js").Generator>} getGenerator - Live-only accessor for the Generator class
34
+ * @property {(question: string) => Promise<any[]>} query - Live-only query interface
35
+ * @property {(message: string, options?: any) => Promise<any>} ask - Modal dialog helper (static + live)
36
+ * @property {(message: string, options?: any) => Promise<string>} toast - Toast helper (static + live)
37
+ * @property {Record<string, any>} common - Common utilities namespace (static + live)
38
+ * @property {(html: string) => Element[]} parse - HTML string parser (static + live)
39
+ * @property {any} AutoComplete - Lazy-loaded autocomplete class (null until loaded)
40
+ * @property {() => Promise<any>} loadAutoComplete - Lazy-load the autocomplete package
41
+ * @property {Record<string, any>} enums - Enum values (static + live)
42
+ * @property {any} ontology - Design system ontology (live-only)
43
+ * @property {Record<string, any>} presets - Preset metadata (live-only)
44
+ * @property {Array<{selector: string, description?: string, demoHtml?: string}>} enhancerMetadata - Enhancer metadata (live-only)
45
+ * @property {Array<any>} defaultEnhancers - Default enhancer definitions (static + live)
46
+ * @property {(el: Element) => ComponentDef | null} findComponentForElement - Ontology lookup helper (live-only)
47
+ * @property {() => void} preloadCritical - Emit critical CSS into <style> (live-only)
48
+ * @property {any} currentConfig - Frozen configuration snapshot after start (static + live)
49
+ * @property {any} compiled - Compiled design system state (live-only)
50
+ * @property {string|null} theme - Theme preference getter/setter (static + live, browser only)
51
+ * @property {(config?: object) => Promise<any>} start - Unified entry point for live/static init
31
52
  */
32
53
 
33
54
  /**
@@ -127,6 +148,7 @@ PDS.isLiveMode = () => registry.isLive;
127
148
  PDS.ask = ask;
128
149
  PDS.toast = toast;
129
150
  PDS.common = common;
151
+ PDS.parse = common.parseHTML;
130
152
  PDS.AutoComplete = null;
131
153
  PDS.loadAutoComplete = async () => {
132
154
  if (PDS.AutoComplete) return PDS.AutoComplete;