@limetech/lime-web-components 6.4.1 → 6.5.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/action/action.d.ts +305 -13
  3. package/dist/action/action.d.ts.map +1 -1
  4. package/dist/application/decorators/application.d.ts +57 -3
  5. package/dist/application/decorators/application.d.ts.map +1 -1
  6. package/dist/application/decorators/session.d.ts +44 -3
  7. package/dist/application/decorators/session.d.ts.map +1 -1
  8. package/dist/application/decorators/user.d.ts +47 -3
  9. package/dist/application/decorators/user.d.ts.map +1 -1
  10. package/dist/application/repository.d.ts +102 -5
  11. package/dist/application/repository.d.ts.map +1 -1
  12. package/dist/application/session.d.ts +105 -15
  13. package/dist/application/session.d.ts.map +1 -1
  14. package/dist/application/user.d.ts +122 -13
  15. package/dist/application/user.d.ts.map +1 -1
  16. package/dist/commandbus/commandbus.d.ts +364 -23
  17. package/dist/commandbus/commandbus.d.ts.map +1 -1
  18. package/dist/conditionregistry/conditionregistry.d.ts +310 -27
  19. package/dist/conditionregistry/conditionregistry.d.ts.map +1 -1
  20. package/dist/config/decorator.d.ts +50 -3
  21. package/dist/config/decorator.d.ts.map +1 -1
  22. package/dist/config/repository.d.ts +131 -10
  23. package/dist/config/repository.d.ts.map +1 -1
  24. package/dist/core/context.d.ts +94 -4
  25. package/dist/core/context.d.ts.map +1 -1
  26. package/dist/core/lime-web-component.d.ts +59 -3
  27. package/dist/core/lime-web-component.d.ts.map +1 -1
  28. package/dist/core/metadata.d.ts +113 -13
  29. package/dist/core/metadata.d.ts.map +1 -1
  30. package/dist/core/platform.d.ts +175 -14
  31. package/dist/core/platform.d.ts.map +1 -1
  32. package/dist/core/state.d.ts +138 -14
  33. package/dist/core/state.d.ts.map +1 -1
  34. package/dist/datetimeformatter/datetimeformatter.d.ts +97 -34
  35. package/dist/datetimeformatter/datetimeformatter.d.ts.map +1 -1
  36. package/dist/device/decorator.d.ts +56 -4
  37. package/dist/device/decorator.d.ts.map +1 -1
  38. package/dist/device/device.d.ts +51 -6
  39. package/dist/device/device.d.ts.map +1 -1
  40. package/dist/dialog/dialog.d.ts +155 -19
  41. package/dist/dialog/dialog.d.ts.map +1 -1
  42. package/dist/index.cjs.js.map +1 -1
  43. package/dist/index.esm.js.map +1 -1
  44. package/dist/limeobject/file.d.ts +6 -0
  45. package/dist/limeobject/file.d.ts.map +1 -1
  46. package/package.json +7 -7
@@ -1,47 +1,171 @@
1
1
  import { Subscribable } from 'rxjs';
2
2
  import { LimeWebComponentContext } from './context';
3
3
  /**
4
- * Base service for letting a Lime web component subscribe to state changes
4
+ * Base interface for repositories that provide reactive state subscriptions.
5
+ *
6
+ * StateRepository is the foundation for all reactive data sources in the platform.
7
+ * Repositories like {@link ConfigRepository}, {@link LimeObjectRepository},
8
+ * {@link FilterRepository}, etc. extend this interface to provide
9
+ * subscription-based access to their data.
10
+ *
11
+ * The subscription pattern allows components to react to data changes automatically,
12
+ * ensuring UI stays synchronized with the underlying application state.
13
+ *
14
+ * @example RECOMMENDED: Use state decorators for automatic reactive properties
15
+ * ```typescript
16
+ * class MyComponent {
17
+ * @State()
18
+ * @SelectCurrentUser({
19
+ * map: [(user) => user?.fullname],
20
+ * filter: [(name) => name !== undefined]
21
+ * })
22
+ * private userName: string;
23
+ *
24
+ * @State()
25
+ * @SelectCurrentLimeobject({
26
+ * map: [(obj) => obj?.properties?.name]
27
+ * })
28
+ * private objectName: string;
29
+ * }
30
+ * ```
31
+ *
32
+ * @example ALTERNATIVE: Manual subscription for custom logic
33
+ * ```typescript
34
+ * const unsubscribe = repository.subscribe(
35
+ * (state) => {
36
+ * console.log('State updated:', state);
37
+ * },
38
+ * {
39
+ * map: [(state) => ({ user: state.user, language: state.language })],
40
+ * filter: [(state) => state.user !== null]
41
+ * }
42
+ * );
43
+ *
44
+ * // Remember to unsubscribe when component is destroyed
45
+ * unsubscribe();
46
+ * ```
47
+ *
5
48
  * @public
6
49
  * @group Core
7
50
  */
8
51
  export interface StateRepository {
9
52
  /**
10
- * Subscribe to state changes
53
+ * Subscribe to state changes with optional transformation and filtering.
11
54
  *
12
- * @param callback - function to call when subscription updates
13
- * @param options - options for the state selector
14
- * @returns unsubscribe callback
55
+ * The subscription will immediately invoke the callback with the current state
56
+ * (if any), then continue to call it whenever the state changes. The map and
57
+ * filter options allow you to transform and selectively receive updates.
58
+ *
59
+ * @param callback - Function called with state updates (after map/filter applied)
60
+ * @param options - Optional transformations and filters for the subscription
61
+ * @returns Unsubscribe function - call this to stop receiving updates
62
+ *
63
+ * @remarks
64
+ * - Map functions are applied sequentially to transform the state
65
+ * - Filter functions must all return true for the callback to be invoked
66
+ * - Functions in map/filter arrays are bound to the component instance
67
+ * - Always store and call the unsubscribe function when component is destroyed
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Basic subscription
72
+ * const unsubscribe = repository.subscribe((state) => {
73
+ * console.log('State updated:', state);
74
+ * });
75
+ *
76
+ * // With transformations
77
+ * const unsubscribe = repository.subscribe(
78
+ * (userName) => console.log('User:', userName),
79
+ * { map: [(state) => state.user?.name] }
80
+ * );
81
+ * ```
15
82
  */
16
83
  subscribe(callback: (...args: unknown[]) => void, options?: StateOptions): () => void;
17
84
  }
18
85
  /**
19
- * Options for the state selector
86
+ * Configuration options for state subscriptions.
87
+ *
88
+ * These options allow you to transform and filter state updates before they
89
+ * reach your callback. Map functions transform the data, while filter functions
90
+ * determine whether the callback should be invoked at all.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const options: StateOptions = {
95
+ * // Extract and transform specific parts of state
96
+ * map: [
97
+ * (state) => state.users,
98
+ * (users) => users.map(u => ({ id: u.id, name: u.name }))
99
+ * ],
100
+ * // Only notify when conditions are met
101
+ * filter: [
102
+ * (users) => users.length > 0,
103
+ * (users) => users.some(u => u.name === 'Admin')
104
+ * ]
105
+ * };
106
+ * ```
107
+ *
20
108
  * @public
21
109
  * @group Core
22
110
  */
23
111
  export interface StateOptions {
24
112
  /**
25
- * List of functions that will be used to map the state.
26
- * The functions will be bound to the web component instance
113
+ * List of transformation functions applied sequentially to the state.
114
+ *
115
+ * Each function receives the output of the previous function (or the raw state
116
+ * for the first function). Use this to extract, transform, or compute derived
117
+ * values from the state. Functions are bound to the web component instance.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * map: [
122
+ * (state) => state.orders, // Extract orders
123
+ * (orders) => orders.filter(o => o.pending), // Filter to pending only
124
+ * (pending) => pending.length // Get count
125
+ * ]
126
+ * // Callback receives: number (count of pending orders)
127
+ * ```
27
128
  */
28
129
  map?: Array<(state: any) => any>;
29
130
  /**
30
- * List of functions that will be used to filter any changes to the state.
31
- * The functions will be bound to the web component instance
131
+ * List of predicate functions that must all return true for updates to be emitted.
132
+ *
133
+ * Filters are evaluated after map transformations. If any filter returns false,
134
+ * the callback is not invoked for that state change. Useful for preventing
135
+ * unnecessary updates. Functions are bound to the web component instance.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * filter: [
140
+ * (state) => state !== null, // Ignore null states
141
+ * (state) => state.isReady, // Only when ready
142
+ * (state) => state.items.length > 0 // Only when has items
143
+ * ]
144
+ * ```
32
145
  */
33
146
  filter?: Array<(state: any) => boolean>;
34
147
  }
35
148
  /**
149
+ * Extended state options for repositories that are context-aware.
150
+ *
151
+ * Some repositories (like CurrentLimetype and CurrentLimeobject) can automatically
152
+ * react to context changes. When the context observable emits a new value, these
153
+ * repositories will re-evaluate and emit their state for the new context.
154
+ *
36
155
  * @public
37
156
  * @group Core
38
157
  */
39
158
  export interface ContextAwareStateOptions extends StateOptions {
40
159
  /**
41
- * An observable that emits a new value when the context of the component
42
- * is changed. If set, the corresponding state service will emit a new value
43
- * when the context has changed as well. Only applies to states that are
44
- * aware of the context, e.g. `CurrentLimetype` and `CurrentLimeobject`
160
+ * Observable that emits new context values to trigger state re-evaluation.
161
+ *
162
+ * When provided, the repository will subscribe to this observable and re-fetch
163
+ * or re-evaluate its state whenever a new context is emitted. This is particularly
164
+ * useful for components that need to react to navigation or context switches.
165
+ *
166
+ * Only applies to context-aware state services like:
167
+ * - `CurrentLimetype` - Updates when limetype in context changes
168
+ * - `CurrentLimeobject` - Re-fetches object when context ID changes
45
169
  */
46
170
  context?: Subscribable<LimeWebComponentContext> | null;
47
171
  }
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B;;;;;;OAMG;IACH,SAAS,CACL,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACtC,OAAO,CAAC,EAAE,YAAY,GACvB,MAAM,IAAI,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IAEH,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;IAEjC;;;OAGG;IAEH,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC1D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;CAC1D"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAQpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,WAAW,eAAe;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,SAAS,CACL,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACtC,OAAO,CAAC,EAAE,YAAY,GACvB,MAAM,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,YAAY;IACzB;;;;;;;;;;;;;;;;OAgBG;IAEH,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;IAEjC;;;;;;;;;;;;;;;OAeG;IAEH,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;CAC3C;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC1D;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;CAC1D"}
@@ -45,60 +45,123 @@ export interface DateTimeFormatterOptions {
45
45
  hourCycle?: HourCycle;
46
46
  }
47
47
  /**
48
- * Service for formatting date and time values.
48
+ * Service for formatting and parsing date and time values according to user locale
49
+ *
50
+ * The DateTimeFormatter provides locale-aware formatting for dates and times,
51
+ * ensuring that dates are displayed in a format familiar to the user. It handles
52
+ * various date types including full timestamps, date-only values, times, and
53
+ * relative dates (like "2 hours ago").
54
+ *
55
+ * The service also handles the complexities of parsing date strings and converting
56
+ * between UTC and local time, which is particularly important for date-only values
57
+ * that need timezone compensation.
58
+ *
59
+ * @example Basic date formatting
60
+ * ```ts
61
+ * const formatter = platform.get(PlatformServiceName.DateTimeFormatter);
62
+ * const timestamp = '2024-03-15T14:30:00.000Z';
63
+ * const formatted = formatter.format(timestamp, 'datetime');
64
+ * // Result: "2024-03-15 14:30" (format varies by locale)
65
+ * ```
66
+ *
67
+ * @example Formatting different date types
68
+ * ```ts
69
+ * const formatter = platform.get(PlatformServiceName.DateTimeFormatter);
70
+ * const now = new Date();
71
+ *
72
+ * formatter.format(now, 'datetime'); // "2024-03-15 14:30"
73
+ * formatter.format(now, 'date'); // "2024-03-15"
74
+ * formatter.format(now, 'time'); // "14:30" or "2:30 PM"
75
+ * formatter.format(now, 'relative'); // "2 hours ago"
76
+ * ```
49
77
  *
50
78
  * @public
51
79
  * @group Localization
52
80
  */
53
81
  export interface DateTimeFormatter {
54
82
  /**
55
- * Format the given date as the given type.
83
+ * Format a date or timestamp as a localized string
56
84
  *
57
- * **Note**<br>
58
- * If a `string` is supplied to the `date` parameter, it will be converted
59
- * to a `Date` object before formatting. See {@link DateTimeFormatter#parse}
60
- * for details.
85
+ * Converts a date value to a human-readable string according to the user's
86
+ * locale and the specified format type. The formatting automatically respects
87
+ * the user's locale preferences for date ordering, separators, and time format.
88
+ *
89
+ * @param date - The date to format, either as a Date object or an ISO string
90
+ * @param options - Either a string specifying the format type (e.g., 'date', 'time', 'datetime'),
91
+ * or a {@link DateTimeFormatterOptions} object for more control
92
+ * @returns A localized string representation of the date
93
+ *
94
+ * @example Simple string format types
95
+ * ```ts
96
+ * const date = new Date('2024-03-15T14:30:00');
97
+ *
98
+ * formatter.format(date, 'date'); // "2024-03-15" or "15/03/2024" depending on locale
99
+ * formatter.format(date, 'time'); // "14:30" or "2:30 PM" depending on locale
100
+ * formatter.format(date, 'datetime'); // "2024-03-15 14:30"
101
+ * formatter.format(date, 'relative'); // "2 hours ago"
102
+ * ```
61
103
  *
62
- * @param date - The date to format.
63
- * @param options - Either a string specifying the type to format the date
64
- * as, or a `DateTimeFormatterOptions` object.
65
- * @returns A string representation of the date.
104
+ * @example Using format options
105
+ * ```ts
106
+ * const date = new Date();
107
+ *
108
+ * // With specific hour cycle
109
+ * const formatted = formatter.format(date, {
110
+ * type: 'datetime',
111
+ * hourCycle: 'h23' // Force 24-hour format
112
+ * });
113
+ * ```
114
+ *
115
+ * @example Formatting dates from API responses
116
+ * ```ts
117
+ * // Date string from API will be automatically parsed
118
+ * const apiDate = "2024-03-15T14:30:00.000Z";
119
+ * const display = formatter.format(apiDate, 'datetime');
120
+ * ```
121
+ *
122
+ * @note If a `string` is supplied to the `date` parameter, it will be converted
123
+ * to a `Date` object before formatting. See {@link DateTimeFormatter.parse}
124
+ * for details on how strings are parsed.
66
125
  */
67
126
  format(date: Date | string, options: DateTimeType | DateTimeFormatterOptions): string;
68
127
  /**
69
- * Parse a date value, converting it to local time.
128
+ * Parse a date string and convert it to a Date object with proper timezone handling
70
129
  *
71
- * A date value passed as a `string` may be converted as a date-only value
72
- * if `type` is 'date', 'year', 'quarter', 'month' or 'week'. This
73
- * basically means returning dates as they are stored in the database, by
74
- * compensating for any time difference.
130
+ * This method handles the complexity of converting date strings to Date objects,
131
+ * with special handling for date-only values that need timezone compensation.
132
+ * This is important when working with dates stored in a database, which are
133
+ * typically in UTC but should be displayed in the user's local timezone.
75
134
  *
76
- * If the date value includes time but not time zone offset, it is always
77
- * interpreted as local time.
135
+ * For date-only types ('date', 'year', 'quarter', 'month', 'week'), the method
136
+ * compensates for timezone differences to ensure the date is displayed as stored.
78
137
  *
79
- * A date value passed as a `Date` is returned unmodified.
138
+ * @param date - The date value to parse. Can be a Date object (returned unchanged)
139
+ * or a string in ISO format
140
+ * @param type - The date type, which determines how timezone conversion is handled
141
+ * @returns A Date object in local time
80
142
  *
81
- * @example
82
- * ```
83
- * // Converting a saved date value to 2023-10-24 in local time
84
- * // The time component of the returned date object should be ignored.
85
- * const parsedDate = dateTimeFormatter.parse('2023-10-24T00:00:00.000Z', 'date');
143
+ * @example Parsing a date-only value from the database
144
+ * ```ts
145
+ * // Database stores "2024-03-15" as "2024-03-15T00:00:00.000Z"
146
+ * const dbValue = '2024-03-15T00:00:00.000Z';
147
+ * const localDate = formatter.parse(dbValue, 'date');
148
+ * // localDate represents 2024-03-15 in local time, regardless of timezone
86
149
  * ```
87
150
  *
88
- * @example
89
- * ```
90
- * // Parsing a date value as local time
91
- * const parsedDate = dateTimeFormatter.parse('2023-10-24 23:59:59', 'date');
151
+ * @example Parsing a datetime value
152
+ * ```ts
153
+ * // Datetime values include time and respect timezones
154
+ * const timestamp = '2024-03-15T14:30:00.000Z';
155
+ * const localTime = formatter.parse(timestamp, 'datetime');
156
+ * // localTime is converted to user's timezone
92
157
  * ```
93
158
  *
94
- * @example
159
+ * @example Parsing a date string without timezone info
160
+ * ```ts
161
+ * // Date strings without timezone are interpreted as local time
162
+ * const localDateStr = '2024-03-15 23:59:59';
163
+ * const date = formatter.parse(localDateStr, 'datetime');
95
164
  * ```
96
- * // Parsing a date-time value including time zone offset
97
- * const parsedDate = dateTimeFormatter.parse('2023-10-24T13:00:00+02:00', 'time');
98
- * ```
99
- *
100
- * @param date - The date to parse.
101
- * @param type - A string specifying the type to parse the date as.
102
165
  */
103
166
  parse(date: Date | string, type: DateTimeType): Date;
104
167
  }
@@ -1 +1 @@
1
- {"version":3,"file":"datetimeformatter.d.ts","sourceRoot":"","sources":["../../src/datetimeformatter/datetimeformatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;IAEnB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;;;;;;;;;;OAYG;IACH,MAAM,CACF,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,EAAE,YAAY,GAAG,wBAAwB,GACjD,MAAM,CAAC;IAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACxD"}
1
+ {"version":3,"file":"datetimeformatter.d.ts","sourceRoot":"","sources":["../../src/datetimeformatter/datetimeformatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;IAEnB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACH,MAAM,CACF,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,EAAE,YAAY,GAAG,wBAAwB,GACjD,MAAM,CAAC;IAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACxD"}
@@ -6,12 +6,64 @@ import { StateOptions } from '../core';
6
6
  */
7
7
  export type DeviceType = 'desktop' | 'tablet' | 'phone';
8
8
  /**
9
- * Get the current device type
9
+ * Decorator that subscribes to the current device type from the device service.
10
10
  *
11
- * The device will only indicate roughly how big the viewport is, not what actual device is being used
11
+ * This decorator automatically updates the decorated property whenever the device type
12
+ * changes (typically when the viewport is resized). The device type indicates roughly
13
+ * how big the viewport is, not what actual device is being used. It's the recommended
14
+ * approach over manual subscriptions as it handles subscription lifecycle automatically.
15
+ *
16
+ * @param options - Configuration for state transformation and filtering via {@link StateOptions}
17
+ * @returns A PropertyDecorator that sets up automatic subscription to device type
18
+ *
19
+ * @remarks
20
+ * Subscribes to: Device service
21
+ *
22
+ * Updates: The decorated property with {@link DeviceType} ('desktop', 'tablet', or 'phone')
23
+ *
24
+ * Viewport-aware: Automatically updates when viewport size changes
25
+ *
26
+ * Lifecycle: Automatically subscribes in `connectedCallback` and
27
+ * unsubscribes in `disconnectedCallback`
28
+ *
29
+ * @example
30
+ * Basic usage with Stencil component
31
+ * ```typescript
32
+ * @State()
33
+ * @SelectDevice()
34
+ * private deviceType: DeviceType;
35
+ *
36
+ * render() {
37
+ * return (
38
+ * <div class={`layout-${this.deviceType}`}>
39
+ * <p>Viewing on: {this.deviceType}</p>
40
+ * </div>
41
+ * );
42
+ * }
43
+ * ```
44
+ *
45
+ * @example
46
+ * Conditional rendering based on device
47
+ * ```typescript
48
+ * @State()
49
+ * @SelectDevice()
50
+ * private device: DeviceType;
51
+ *
52
+ * render() {
53
+ * if (this.device === 'phone') {
54
+ * return <button class="hamburger-menu">Menu</button>;
55
+ * }
56
+ *
57
+ * return (
58
+ * <nav class="full-menu">
59
+ * <a href="/home">Home</a>
60
+ * <a href="/about">About</a>
61
+ * <a href="/contact">Contact</a>
62
+ * </nav>
63
+ * );
64
+ * }
65
+ * ```
12
66
  *
13
- * @param options - state decorator options
14
- * @returns state decorator
15
67
  * @public
16
68
  * @group Device
17
69
  */
@@ -1 +1 @@
1
- {"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/device/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EAEf,MAAM,SAAS,CAAC;AAGjB;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAExD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,YAAiB,GAAG,iBAAiB,CAM1E"}
1
+ {"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/device/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EAEf,MAAM,SAAS,CAAC;AAGjB;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,YAAiB,GAAG,iBAAiB,CAM1E"}
@@ -1,25 +1,70 @@
1
1
  import { StateRepository } from '../core';
2
2
  /**
3
+ * Service for detecting the current device viewport size category
4
+ *
5
+ * The Device service provides reactive methods to determine whether the current
6
+ * viewport size falls into desktop, tablet, or phone categories. This is useful
7
+ * for creating responsive components that adapt their UI based on available screen
8
+ * real estate.
9
+ *
10
+ * Since Device extends {@link StateRepository}, components can use the `@State`
11
+ * decorator to automatically re-render when the device size category changes
12
+ * (e.g., when the user resizes their browser window or rotates their device).
13
+ *
14
+ * @example Checking device size
15
+ * ```ts
16
+ * const device = this.platform.get(PlatformServiceName.Device);
17
+ *
18
+ * if (device.isPhoneSize()) {
19
+ * return this.generateMobileExport();
20
+ * }
21
+ *
22
+ * return this.generateDesktopExport();
23
+ * ```
24
+ *
25
+ * @example Conditional logic based on viewport size
26
+ * ```ts
27
+ * const device = this.platform.get(PlatformServiceName.Device);
28
+ *
29
+ * if (device.isDesktopSize()) {
30
+ * columns = ['name', 'email', 'phone', 'address', 'status'];
31
+ * } else if (device.isTabletSize()) {
32
+ * columns = ['name', 'email', 'status'];
33
+ * } else {
34
+ * columns = ['name', 'status'];
35
+ * }
36
+ * ```
37
+ *
3
38
  * @public
4
39
  * @group Device
5
40
  */
6
41
  export interface Device extends StateRepository {
7
42
  /**
8
- * Check if the device type is 'desktop'
43
+ * Check if the current viewport size is in the desktop category
9
44
  *
10
- * @returns true/false
45
+ * Desktop size typically indicates a large screen with ample horizontal space
46
+ * for full-featured layouts, multiple columns, and detailed information display.
47
+ *
48
+ * @returns `true` if the viewport is desktop-sized, `false` otherwise
11
49
  */
12
50
  isDesktopSize(): boolean;
13
51
  /**
14
- * Check if the device type is 'tablet'
52
+ * Check if the current viewport size is in the tablet category
53
+ *
54
+ * Tablet size typically indicates a medium-sized screen where some layout
55
+ * adjustments may be needed compared to desktop, but more space is available
56
+ * than on phone screens.
15
57
  *
16
- * @returns true/false
58
+ * @returns `true` if the viewport is tablet-sized, `false` otherwise
17
59
  */
18
60
  isTabletSize(): boolean;
19
61
  /**
20
- * Check if the device type is 'phone'
62
+ * Check if the current viewport size is in the phone category
63
+ *
64
+ * Phone size typically indicates a small screen where compact layouts, single
65
+ * columns, and simplified navigation patterns are most appropriate.
21
66
  *
22
- * @returns true/false
67
+ * @returns `true` if the viewport is phone-sized, `false` otherwise
23
68
  */
24
69
  isPhoneSize(): boolean;
25
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/device/device.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC3C;;;;OAIG;IACH,aAAa,IAAI,OAAO,CAAC;IAEzB;;;;OAIG;IACH,YAAY,IAAI,OAAO,CAAC;IAExB;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC;CAC1B"}
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/device/device.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC3C;;;;;;;OAOG;IACH,aAAa,IAAI,OAAO,CAAC;IAEzB;;;;;;;;OAQG;IACH,YAAY,IAAI,OAAO,CAAC;IAExB;;;;;;;OAOG;IACH,WAAW,IAAI,OAAO,CAAC;CAC1B"}