@smartnet360/svelte-components 0.0.37 → 0.0.39

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 (32) hide show
  1. package/dist/apps/site-check/SiteCheck.svelte +7 -6
  2. package/dist/apps/site-check/SiteCheck.svelte.d.ts +2 -1
  3. package/dist/apps/site-check/default-cell-styling.d.ts +6 -0
  4. package/dist/apps/site-check/default-cell-styling.js +24 -0
  5. package/dist/apps/site-check/default-cell-styling.json +20 -0
  6. package/dist/apps/site-check/helper.d.ts +3 -2
  7. package/dist/apps/site-check/helper.js +16 -15
  8. package/dist/apps/site-check/index.d.ts +2 -1
  9. package/dist/apps/site-check/index.js +4 -2
  10. package/dist/apps/site-check/transforms.d.ts +32 -0
  11. package/dist/apps/site-check/transforms.js +101 -3
  12. package/dist/core/Charts/ChartCard.svelte +7 -5
  13. package/dist/core/Charts/ChartCard.svelte.d.ts +3 -1
  14. package/dist/core/Charts/ChartComponent.svelte +3 -1
  15. package/dist/core/Charts/adapt.js +19 -27
  16. package/dist/core/Charts/charts.model.d.ts +9 -0
  17. package/dist/core/Charts/data-utils.d.ts +4 -4
  18. package/dist/core/Charts/data-utils.js +69 -10
  19. package/dist/core/Charts/index.d.ts +1 -1
  20. package/dist/core/Settings/FieldRenderer.svelte +234 -0
  21. package/dist/core/Settings/FieldRenderer.svelte.d.ts +30 -0
  22. package/dist/core/Settings/Settings.svelte +199 -0
  23. package/dist/core/Settings/Settings.svelte.d.ts +24 -0
  24. package/dist/core/Settings/index.d.ts +9 -0
  25. package/dist/core/Settings/index.js +8 -0
  26. package/dist/core/Settings/store.d.ts +56 -0
  27. package/dist/core/Settings/store.js +184 -0
  28. package/dist/core/Settings/types.d.ts +162 -0
  29. package/dist/core/Settings/types.js +7 -0
  30. package/dist/core/index.d.ts +1 -0
  31. package/dist/core/index.js +2 -0
  32. package/package.json +1 -1
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Settings Store Factory
3
+ *
4
+ * Creates reactive stores for settings management with automatic persistence.
5
+ * Each consuming app creates its own store instance with its schema and namespace.
6
+ *
7
+ * Supports hierarchical access with TypeScript autocomplete:
8
+ * $settings.appearance.theme
9
+ * $settings.editor.fontSize
10
+ */
11
+ import type { SettingsSchema } from './types';
12
+ /**
13
+ * Type helper to infer settings structure from schema
14
+ * Converts schema into nested type: { segment: { field: value } }
15
+ */
16
+ export type InferSettingsType<T extends SettingsSchema> = {
17
+ [K in T['segments'][number]['id']]: {
18
+ [F in Extract<T['segments'][number], {
19
+ id: K;
20
+ }>['fields'][number] as F['id']]: F['defaultValue'];
21
+ };
22
+ };
23
+ /**
24
+ * Create a settings store instance with hierarchical access
25
+ *
26
+ * @param schema - The settings schema defining all fields
27
+ * @param namespace - Unique namespace for localStorage isolation (e.g., 'myApp')
28
+ * @returns A reactive store with hierarchical access: $settings.segment.field
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const settings = createSettingsStore(mySchema, 'myApp');
33
+ *
34
+ * // In Svelte components with full autocomplete:
35
+ * $settings.appearance.theme // ✅ TypeScript autocomplete works!
36
+ * $settings.editor.fontSize // ✅ Nested access
37
+ *
38
+ * // Update values:
39
+ * settings.update('appearance', 'theme', 'dark')
40
+ * settings.updateSegment('appearance', { theme: 'dark', ... })
41
+ * ```
42
+ */
43
+ export declare function createSettingsStore<T extends SettingsSchema>(schema: T, namespace: string): {
44
+ subscribe: (this: void, run: import("svelte/store").Subscriber<InferSettingsType<T>>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
45
+ update: (segmentId: string, fieldId: string, value: any) => void;
46
+ updateSegment: (segmentId: string, values: Record<string, any>) => void;
47
+ reset: (segmentId: string, fieldId: string) => void;
48
+ resetSegment: (segmentId: string) => void;
49
+ resetAll: () => void;
50
+ getValues: () => InferSettingsType<T>;
51
+ };
52
+ /**
53
+ * Helper to create a flat map of field ID -> field definition
54
+ * Useful for quick lookups when rendering or validating
55
+ */
56
+ export declare function createFieldMap(schema: SettingsSchema): Map<any, any>;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Settings Store Factory
3
+ *
4
+ * Creates reactive stores for settings management with automatic persistence.
5
+ * Each consuming app creates its own store instance with its schema and namespace.
6
+ *
7
+ * Supports hierarchical access with TypeScript autocomplete:
8
+ * $settings.appearance.theme
9
+ * $settings.editor.fontSize
10
+ */
11
+ import { writable, get } from 'svelte/store';
12
+ /**
13
+ * Extract default values from schema in hierarchical structure
14
+ * Returns: { segment: { field: value } }
15
+ */
16
+ function extractDefaults(schema) {
17
+ const defaults = {};
18
+ for (const segment of schema.segments) {
19
+ defaults[segment.id] = {};
20
+ for (const field of segment.fields) {
21
+ defaults[segment.id][field.id] = field.defaultValue;
22
+ }
23
+ }
24
+ return defaults;
25
+ }
26
+ /**
27
+ * Load saved settings from localStorage (SSR-safe)
28
+ * Supports hierarchical structure
29
+ */
30
+ function loadFromStorage(namespace, defaults) {
31
+ if (typeof window === 'undefined')
32
+ return defaults;
33
+ try {
34
+ const storageKey = `${namespace}:settings`;
35
+ const saved = localStorage.getItem(storageKey);
36
+ if (saved) {
37
+ const parsed = JSON.parse(saved);
38
+ // Deep merge with defaults to ensure new fields appear
39
+ const merged = {};
40
+ for (const segmentId in defaults) {
41
+ merged[segmentId] = {
42
+ ...defaults[segmentId],
43
+ ...(parsed[segmentId] || {})
44
+ };
45
+ }
46
+ return merged;
47
+ }
48
+ }
49
+ catch (error) {
50
+ console.error('Failed to load settings from localStorage:', error);
51
+ }
52
+ return defaults;
53
+ }
54
+ /**
55
+ * Save settings to localStorage (SSR-safe)
56
+ */
57
+ function saveToStorage(namespace, values) {
58
+ if (typeof window === 'undefined')
59
+ return;
60
+ try {
61
+ const storageKey = `${namespace}:settings`;
62
+ localStorage.setItem(storageKey, JSON.stringify(values));
63
+ }
64
+ catch (error) {
65
+ console.error('Failed to save settings to localStorage:', error);
66
+ }
67
+ }
68
+ /**
69
+ * Create a settings store instance with hierarchical access
70
+ *
71
+ * @param schema - The settings schema defining all fields
72
+ * @param namespace - Unique namespace for localStorage isolation (e.g., 'myApp')
73
+ * @returns A reactive store with hierarchical access: $settings.segment.field
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const settings = createSettingsStore(mySchema, 'myApp');
78
+ *
79
+ * // In Svelte components with full autocomplete:
80
+ * $settings.appearance.theme // ✅ TypeScript autocomplete works!
81
+ * $settings.editor.fontSize // ✅ Nested access
82
+ *
83
+ * // Update values:
84
+ * settings.update('appearance', 'theme', 'dark')
85
+ * settings.updateSegment('appearance', { theme: 'dark', ... })
86
+ * ```
87
+ */
88
+ export function createSettingsStore(schema, namespace) {
89
+ // Extract defaults from schema (hierarchical structure)
90
+ const defaults = extractDefaults(schema);
91
+ // Load initial values (defaults + any saved values)
92
+ const initialValues = loadFromStorage(namespace, defaults);
93
+ const { subscribe, set: setStore, update: updateStore } = writable(initialValues);
94
+ // Subscribe to changes and persist to localStorage
95
+ subscribe((values) => {
96
+ saveToStorage(namespace, values);
97
+ });
98
+ /**
99
+ * Update a single field value
100
+ * @param segmentId - The segment ID (e.g., 'appearance')
101
+ * @param fieldId - The field ID (e.g., 'theme')
102
+ * @param value - The new value
103
+ */
104
+ function update(segmentId, fieldId, value) {
105
+ updateStore((current) => ({
106
+ ...current,
107
+ [segmentId]: {
108
+ ...current[segmentId],
109
+ [fieldId]: value
110
+ }
111
+ }));
112
+ }
113
+ /**
114
+ * Update multiple fields in a segment at once
115
+ * @param segmentId - The segment ID
116
+ * @param values - Partial segment values
117
+ */
118
+ function updateSegment(segmentId, values) {
119
+ updateStore((current) => ({
120
+ ...current,
121
+ [segmentId]: {
122
+ ...current[segmentId],
123
+ ...values
124
+ }
125
+ }));
126
+ }
127
+ /**
128
+ * Reset a single field to its default value
129
+ * @param segmentId - The segment ID
130
+ * @param fieldId - The field ID
131
+ */
132
+ function reset(segmentId, fieldId) {
133
+ const defaultValue = defaults[segmentId]?.[fieldId];
134
+ if (defaultValue !== undefined) {
135
+ update(segmentId, fieldId, defaultValue);
136
+ }
137
+ }
138
+ /**
139
+ * Reset an entire segment to defaults
140
+ * @param segmentId - The segment ID
141
+ */
142
+ function resetSegment(segmentId) {
143
+ if (defaults[segmentId]) {
144
+ updateStore((current) => ({
145
+ ...current,
146
+ [segmentId]: { ...defaults[segmentId] }
147
+ }));
148
+ }
149
+ }
150
+ /**
151
+ * Reset all settings to their default values
152
+ */
153
+ function resetAll() {
154
+ setStore({ ...defaults });
155
+ }
156
+ /**
157
+ * Get a snapshot of current values (non-reactive)
158
+ */
159
+ function getValues() {
160
+ return get({ subscribe });
161
+ }
162
+ return {
163
+ subscribe,
164
+ update,
165
+ updateSegment,
166
+ reset,
167
+ resetSegment,
168
+ resetAll,
169
+ getValues
170
+ };
171
+ }
172
+ /**
173
+ * Helper to create a flat map of field ID -> field definition
174
+ * Useful for quick lookups when rendering or validating
175
+ */
176
+ export function createFieldMap(schema) {
177
+ const map = new Map();
178
+ for (const segment of schema.segments) {
179
+ for (const field of segment.fields) {
180
+ map.set(field.id, field);
181
+ }
182
+ }
183
+ return map;
184
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Settings System Type Definitions
3
+ *
4
+ * Defines the schema structure for the data-driven settings component.
5
+ * Schemas are passed in from consuming applications.
6
+ */
7
+ /**
8
+ * Base field definition shared by all field types
9
+ */
10
+ export interface BaseFieldDefinition {
11
+ /** Unique identifier for the field */
12
+ id: string;
13
+ /** Display label for the field */
14
+ label: string;
15
+ /** Optional description/help text */
16
+ description?: string;
17
+ /** Optional tooltip shown on hover */
18
+ tooltip?: string;
19
+ /** Whether the field is disabled */
20
+ disabled?: boolean;
21
+ /** Condition for field visibility (function that receives all settings) */
22
+ visibleIf?: (settings: Record<string, any>) => boolean;
23
+ }
24
+ /**
25
+ * Boolean toggle field (checkbox/switch)
26
+ */
27
+ export interface BooleanFieldDefinition extends BaseFieldDefinition {
28
+ type: 'boolean';
29
+ defaultValue: boolean;
30
+ }
31
+ /**
32
+ * Text input field
33
+ */
34
+ export interface TextFieldDefinition extends BaseFieldDefinition {
35
+ type: 'text';
36
+ defaultValue: string;
37
+ /** Input placeholder text */
38
+ placeholder?: string;
39
+ /** Maximum character length */
40
+ maxLength?: number;
41
+ /** Validation pattern (regex) */
42
+ pattern?: string;
43
+ }
44
+ /**
45
+ * Number input field
46
+ */
47
+ export interface NumberFieldDefinition extends BaseFieldDefinition {
48
+ type: 'number';
49
+ defaultValue: number;
50
+ min?: number;
51
+ max?: number;
52
+ step?: number;
53
+ /** Unit label (e.g., "px", "ms", "%") */
54
+ unit?: string;
55
+ }
56
+ /**
57
+ * Range slider field
58
+ */
59
+ export interface RangeFieldDefinition extends BaseFieldDefinition {
60
+ type: 'range';
61
+ defaultValue: number;
62
+ min: number;
63
+ max: number;
64
+ step?: number;
65
+ /** Whether to show the current value */
66
+ showValue?: boolean;
67
+ /** Unit label (e.g., "px", "ms", "%") */
68
+ unit?: string;
69
+ }
70
+ /**
71
+ * Color picker field
72
+ */
73
+ export interface ColorFieldDefinition extends BaseFieldDefinition {
74
+ type: 'color';
75
+ defaultValue: string;
76
+ }
77
+ /**
78
+ * Select dropdown field
79
+ */
80
+ export interface SelectFieldDefinition extends BaseFieldDefinition {
81
+ type: 'select';
82
+ defaultValue: string | number;
83
+ options: Array<{
84
+ value: string | number;
85
+ label: string;
86
+ description?: string;
87
+ }>;
88
+ }
89
+ /**
90
+ * Radio button group field
91
+ */
92
+ export interface RadioFieldDefinition extends BaseFieldDefinition {
93
+ type: 'radio';
94
+ defaultValue: string | number;
95
+ options: Array<{
96
+ value: string | number;
97
+ label: string;
98
+ description?: string;
99
+ }>;
100
+ }
101
+ /**
102
+ * Custom field that renders a provided Svelte component
103
+ */
104
+ export interface CustomFieldDefinition extends BaseFieldDefinition {
105
+ type: 'custom';
106
+ defaultValue: any;
107
+ /** The Svelte component to render */
108
+ component: any;
109
+ /** Additional props to pass to the custom component */
110
+ componentProps?: Record<string, any>;
111
+ }
112
+ /**
113
+ * Union type of all field definitions
114
+ */
115
+ export type FieldDefinition = BooleanFieldDefinition | TextFieldDefinition | NumberFieldDefinition | RangeFieldDefinition | ColorFieldDefinition | SelectFieldDefinition | RadioFieldDefinition | CustomFieldDefinition;
116
+ /**
117
+ * A segment groups related settings fields under a card/section
118
+ */
119
+ export interface SegmentDefinition {
120
+ /** Unique identifier for the segment */
121
+ id: string;
122
+ /** Display title for the card/section */
123
+ title: string;
124
+ /** Optional description for the segment */
125
+ description?: string;
126
+ /** Optional icon (emoji or icon class) */
127
+ icon?: string;
128
+ /** Whether the segment starts collapsed */
129
+ collapsed?: boolean;
130
+ /** Array of field definitions in this segment */
131
+ fields: FieldDefinition[];
132
+ }
133
+ /**
134
+ * Complete settings schema passed to the Settings component
135
+ */
136
+ export interface SettingsSchema {
137
+ /** Array of setting segments (cards) */
138
+ segments: SegmentDefinition[];
139
+ /** Optional schema version for migration support */
140
+ version?: string;
141
+ }
142
+ /**
143
+ * The live settings values (flat key-value pairs)
144
+ */
145
+ export type SettingsValues = Record<string, any>;
146
+ /**
147
+ * Store interface for settings
148
+ */
149
+ export interface SettingsStore {
150
+ /** Subscribe to settings changes */
151
+ subscribe: (callback: (value: SettingsValues) => void) => () => void;
152
+ /** Update a single setting value */
153
+ set: (key: string, value: any) => void;
154
+ /** Update multiple settings at once */
155
+ update: (values: Partial<SettingsValues>) => void;
156
+ /** Reset a single setting to default */
157
+ reset: (key: string) => void;
158
+ /** Reset all settings to defaults */
159
+ resetAll: () => void;
160
+ /** Get current values snapshot */
161
+ getValues: () => SettingsValues;
162
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Settings System Type Definitions
3
+ *
4
+ * Defines the schema structure for the data-driven settings component.
5
+ * Schemas are passed in from consuming applications.
6
+ */
7
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from './Desktop/index.js';
2
2
  export * from './Charts/index.js';
3
3
  export * from './TreeView/index.js';
4
+ export * from './Settings/index.js';
4
5
  export * from './logger/index.js';
@@ -6,5 +6,7 @@ export * from './Desktop/index.js';
6
6
  export * from './Charts/index.js';
7
7
  // TreeView generic hierarchical component
8
8
  export * from './TreeView/index.js';
9
+ // Settings system - data-driven settings component
10
+ export * from './Settings/index.js';
9
11
  // Logger utility for debugging and monitoring
10
12
  export * from './logger/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartnet360/svelte-components",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",