@mapples/inlang 1.0.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.
- package/README.md +454 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/dims.d.ts +5 -0
- package/dist/dims.d.ts.map +1 -0
- package/dist/dims.js +17 -0
- package/dist/dims.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/state/conditions.d.ts +5 -0
- package/dist/state/conditions.d.ts.map +1 -0
- package/dist/state/conditions.js +8 -0
- package/dist/state/conditions.js.map +1 -0
- package/dist/state/index.d.ts +5 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +5 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/regexp.d.ts +2 -0
- package/dist/state/regexp.d.ts.map +1 -0
- package/dist/state/regexp.js +2 -0
- package/dist/state/regexp.js.map +1 -0
- package/dist/state/types.d.ts +74 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +17 -0
- package/dist/state/types.js.map +1 -0
- package/dist/state/utils.d.ts +93 -0
- package/dist/state/utils.d.ts.map +1 -0
- package/dist/state/utils.js +158 -0
- package/dist/state/utils.js.map +1 -0
- package/dist/this.d.ts +6 -0
- package/dist/this.d.ts.map +1 -0
- package/dist/this.js +15 -0
- package/dist/this.js.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# @mapples/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the Mapples Open Kit. This package provides all the core type definitions used across the Mapples ecosystem, including component registration, form configurations, and asset management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mapples/types
|
|
9
|
+
# or
|
|
10
|
+
yarn add @mapples/types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The `@mapples/types` package contains essential TypeScript interfaces and types that define the structure and behavior of components, forms, and assets in the Mapples system. These types ensure type safety and provide clear contracts for developers working with the Mapples Open Kit.
|
|
16
|
+
|
|
17
|
+
## Core Types
|
|
18
|
+
|
|
19
|
+
### Action Types
|
|
20
|
+
|
|
21
|
+
#### `Action`
|
|
22
|
+
|
|
23
|
+
Represents a user action that occurred in the application. Actions are used for tracking user interactions, analytics, and state management.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
interface Action {
|
|
27
|
+
time: number; // Timestamp when the action occurred (in milliseconds since epoch)
|
|
28
|
+
type?: string; // Optional string identifier for the type of action
|
|
29
|
+
payload?: ActionPayload; // Optional payload containing additional data about the action
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### `ActionPayload`
|
|
34
|
+
|
|
35
|
+
Represents the payload data that can be attached to an action.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
interface ActionPayload {
|
|
39
|
+
originalEventData?: any[]; // Original event data from the source event
|
|
40
|
+
data?: any; // Custom data payload specific to the action
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Example:**
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { Action, ActionPayload } from '@mapples/types';
|
|
48
|
+
|
|
49
|
+
const userAction: Action = {
|
|
50
|
+
time: Date.now(),
|
|
51
|
+
type: 'BUTTON_PRESSED',
|
|
52
|
+
payload: {
|
|
53
|
+
data: { buttonId: 'submit', userId: '123' },
|
|
54
|
+
originalEventData: ['button', 'press', { x: 100, y: 200 }],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Mapplet Types
|
|
60
|
+
|
|
61
|
+
#### `MappletType<State>`
|
|
62
|
+
|
|
63
|
+
Represents the configuration interface for a Mapplet application. A Mapplet is a self-contained application that can be embedded or run standalone.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
interface MappletType<State extends object = object> {
|
|
67
|
+
state?: State; // Optional initial state object for the Mapplet
|
|
68
|
+
onAction?: (action: Action) => void; // Optional callback function to handle actions
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Example:**
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { MappletType, Action } from '@mapples/types';
|
|
76
|
+
|
|
77
|
+
interface MyAppState {
|
|
78
|
+
user: { name: string; email: string };
|
|
79
|
+
settings: { theme: string };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const myMapplet: MappletType<MyAppState> = {
|
|
83
|
+
state: {
|
|
84
|
+
user: { name: 'John', email: 'john@example.com' },
|
|
85
|
+
settings: { theme: 'dark' },
|
|
86
|
+
},
|
|
87
|
+
onAction: (action: Action) => {
|
|
88
|
+
console.log('Mapplet action:', action);
|
|
89
|
+
// Handle analytics, logging, etc.
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Asset Types
|
|
95
|
+
|
|
96
|
+
#### `AssetType`
|
|
97
|
+
|
|
98
|
+
Represents the different types of assets that can be used in the Mapples system.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
type AssetType = 'image' | 'video' | 'icon' | 'font' | 'json';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Example:**
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { AssetType } from '@mapples/types';
|
|
108
|
+
|
|
109
|
+
const imageAsset: AssetType = 'image';
|
|
110
|
+
const videoAsset: AssetType = 'video';
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Component Types
|
|
114
|
+
|
|
115
|
+
#### `RegisteredComponent<T>`
|
|
116
|
+
|
|
117
|
+
Defines the structure for registering components in the Mapples component system. This interface contains all the metadata needed to make a component available in the visual editor.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
interface RegisteredComponent<T extends object = object> {
|
|
121
|
+
type: string; // Unique component identifier
|
|
122
|
+
groupId: string; // Group this component belongs to
|
|
123
|
+
label: string; // Display name
|
|
124
|
+
Component: ComponentType<PropsWithChildren<T>>; // React component
|
|
125
|
+
Icon: ComponentType<SvgProps>; // Icon for component palette
|
|
126
|
+
initialProps: T; // Default props
|
|
127
|
+
styleKeys: StyleKey[]; // Available style properties
|
|
128
|
+
props: PropsFormField[]; // Property form fields
|
|
129
|
+
actionProps: string[]; // Action-triggering properties
|
|
130
|
+
hidden?: boolean; // Hide from palette
|
|
131
|
+
hasChildren?: boolean; // Can contain children
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Example:**
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { RegisteredComponent } from '@mapples/types';
|
|
139
|
+
|
|
140
|
+
interface ButtonProps {
|
|
141
|
+
text: string;
|
|
142
|
+
disabled?: boolean;
|
|
143
|
+
onPress?: () => void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const buttonComponent: RegisteredComponent<ButtonProps> = {
|
|
147
|
+
type: 'Button',
|
|
148
|
+
groupId: 'inputs',
|
|
149
|
+
label: 'Button',
|
|
150
|
+
Component: Button,
|
|
151
|
+
Icon: ButtonIcon,
|
|
152
|
+
initialProps: { text: 'Click me' },
|
|
153
|
+
styleKeys: [backgroundColorStyle, textColorStyle],
|
|
154
|
+
props: [textField, disabledField],
|
|
155
|
+
actionProps: ['onPress'],
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### `RegisteredComponentsGroup`
|
|
160
|
+
|
|
161
|
+
Represents a group of components in the component palette.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
interface RegisteredComponentsGroup {
|
|
165
|
+
id: string; // Unique group identifier
|
|
166
|
+
label: string; // Display name
|
|
167
|
+
Icon: ComponentType<SvgProps>; // Group icon
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### `RegisteredComponents`
|
|
172
|
+
|
|
173
|
+
A registry mapping component types to their definitions.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
type RegisteredComponents = Record<string, RegisteredComponent>;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### `StyleKey`
|
|
180
|
+
|
|
181
|
+
Defines a style property configuration.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
interface StyleKey {
|
|
185
|
+
label: string; // Human-readable label
|
|
186
|
+
value: string; // CSS property name
|
|
187
|
+
forms: StyleFormType[]; // Applicable form types
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Form Types
|
|
192
|
+
|
|
193
|
+
#### `StyleFormType`
|
|
194
|
+
|
|
195
|
+
Enum representing different categories of style forms.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
enum StyleFormType {
|
|
199
|
+
Dimension = 'Dimension', // Width, height, min/max dimensions
|
|
200
|
+
Image = 'Image', // Background images, object fit
|
|
201
|
+
Text = 'Text', // Text color, alignment
|
|
202
|
+
Typography = 'Typography', // Font family, size, weight
|
|
203
|
+
Position = 'Position', // Top, left, right, bottom
|
|
204
|
+
Surface = 'Surface', // Background color, opacity
|
|
205
|
+
ScrollSurface = 'ScrollSurface', // Scrollable surface properties
|
|
206
|
+
Borders = 'Borders', // Border width, color, radius
|
|
207
|
+
Shadow = 'Shadow', // Box shadow, elevation
|
|
208
|
+
Spacing = 'Spacing', // Margin, padding
|
|
209
|
+
Svg = 'Svg', // SVG-related properties
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### `PropsFormType`
|
|
214
|
+
|
|
215
|
+
Enum for property form field types.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
enum PropsFormType {
|
|
219
|
+
Text = 'Text', // Text input field
|
|
220
|
+
Select = 'Select', // Single selection dropdown
|
|
221
|
+
Switch = 'Switch', // Boolean toggle
|
|
222
|
+
MultiSelect = 'MultiSelect', // Multiple selection dropdown
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### `PropsFormField`
|
|
227
|
+
|
|
228
|
+
Configuration for component property form fields.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
interface PropsFormField {
|
|
232
|
+
propsKey: string; // Property key in component props
|
|
233
|
+
label: string; // Form field label
|
|
234
|
+
options?: PropsFormFieldOptions; // Options for select fields
|
|
235
|
+
type: PropsFormType; // Form field type
|
|
236
|
+
dataProp?: boolean; // Can be bound to data sources
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Example:**
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import { PropsFormField, PropsFormType } from '@mapples/types';
|
|
244
|
+
|
|
245
|
+
const textField: PropsFormField = {
|
|
246
|
+
propsKey: 'text',
|
|
247
|
+
label: 'Button Text',
|
|
248
|
+
type: PropsFormType.Text,
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const sizeField: PropsFormField = {
|
|
252
|
+
propsKey: 'size',
|
|
253
|
+
label: 'Size',
|
|
254
|
+
type: PropsFormType.Select,
|
|
255
|
+
options: [
|
|
256
|
+
{ label: 'Small', value: 'sm' },
|
|
257
|
+
{ label: 'Medium', value: 'md' },
|
|
258
|
+
{ label: 'Large', value: 'lg' },
|
|
259
|
+
],
|
|
260
|
+
};
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### `PropsFormFieldOption`
|
|
264
|
+
|
|
265
|
+
Represents an option in select/multi-select fields.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
interface PropsFormFieldOption {
|
|
269
|
+
label: string; // Display text
|
|
270
|
+
value: string; // Stored value
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### `PropsFormFieldOptions`
|
|
275
|
+
|
|
276
|
+
Union type for form field options.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
type PropsFormFieldOptions =
|
|
280
|
+
| PropsFormFieldOption[] // Array of options
|
|
281
|
+
| 'typography' // Special typography type
|
|
282
|
+
| AssetType; // Asset type for asset selection
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### `ActionFormProps`
|
|
286
|
+
|
|
287
|
+
Configuration for action properties.
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
interface ActionFormProps {
|
|
291
|
+
propsKey: string; // Action property key
|
|
292
|
+
label: string; // Form field label
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### `PropsFieldConfig`
|
|
297
|
+
|
|
298
|
+
Mapping of form types to their React components.
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
type PropsFieldConfig = Record<PropsFormType, ComponentType<PropsFormField>>;
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Usage Examples
|
|
305
|
+
|
|
306
|
+
### Registering a Component
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import {
|
|
310
|
+
RegisteredComponent,
|
|
311
|
+
PropsFormField,
|
|
312
|
+
PropsFormType,
|
|
313
|
+
StyleFormType,
|
|
314
|
+
StyleKey,
|
|
315
|
+
} from '@mapples/types';
|
|
316
|
+
|
|
317
|
+
// Define component props
|
|
318
|
+
interface MyButtonProps {
|
|
319
|
+
text: string;
|
|
320
|
+
variant: 'primary' | 'secondary';
|
|
321
|
+
disabled?: boolean;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Create style keys
|
|
325
|
+
const backgroundColorStyle: StyleKey = {
|
|
326
|
+
label: 'Background Color',
|
|
327
|
+
value: 'backgroundColor',
|
|
328
|
+
forms: [StyleFormType.Surface],
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// Create form fields
|
|
332
|
+
const textField: PropsFormField = {
|
|
333
|
+
propsKey: 'text',
|
|
334
|
+
label: 'Button Text',
|
|
335
|
+
type: PropsFormType.Text,
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const variantField: PropsFormField = {
|
|
339
|
+
propsKey: 'variant',
|
|
340
|
+
label: 'Variant',
|
|
341
|
+
type: PropsFormType.Select,
|
|
342
|
+
options: [
|
|
343
|
+
{ label: 'Primary', value: 'primary' },
|
|
344
|
+
{ label: 'Secondary', value: 'secondary' },
|
|
345
|
+
],
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// Register the component
|
|
349
|
+
const myButtonComponent: RegisteredComponent<MyButtonProps> = {
|
|
350
|
+
type: 'MyButton',
|
|
351
|
+
groupId: 'custom',
|
|
352
|
+
label: 'My Button',
|
|
353
|
+
Component: MyButton,
|
|
354
|
+
Icon: MyButtonIcon,
|
|
355
|
+
initialProps: {
|
|
356
|
+
text: 'Click me',
|
|
357
|
+
variant: 'primary',
|
|
358
|
+
},
|
|
359
|
+
styleKeys: [backgroundColorStyle],
|
|
360
|
+
props: [textField, variantField],
|
|
361
|
+
actionProps: ['onPress'],
|
|
362
|
+
};
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Creating a Component Group
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { RegisteredComponentsGroup } from '@mapples/types';
|
|
369
|
+
|
|
370
|
+
const customGroup: RegisteredComponentsGroup = {
|
|
371
|
+
id: 'custom',
|
|
372
|
+
label: 'Custom Components',
|
|
373
|
+
Icon: CustomIcon,
|
|
374
|
+
};
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Working with Form Fields
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import {
|
|
381
|
+
PropsFormField,
|
|
382
|
+
PropsFormType,
|
|
383
|
+
PropsFormFieldOptions,
|
|
384
|
+
} from '@mapples/types';
|
|
385
|
+
|
|
386
|
+
// Text field
|
|
387
|
+
const nameField: PropsFormField = {
|
|
388
|
+
propsKey: 'name',
|
|
389
|
+
label: 'Name',
|
|
390
|
+
type: PropsFormType.Text,
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// Select field with options
|
|
394
|
+
const statusField: PropsFormField = {
|
|
395
|
+
propsKey: 'status',
|
|
396
|
+
label: 'Status',
|
|
397
|
+
type: PropsFormType.Select,
|
|
398
|
+
options: [
|
|
399
|
+
{ label: 'Active', value: 'active' },
|
|
400
|
+
{ label: 'Inactive', value: 'inactive' },
|
|
401
|
+
{ label: 'Pending', value: 'pending' },
|
|
402
|
+
],
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// Asset selection field
|
|
406
|
+
const imageField: PropsFormField = {
|
|
407
|
+
propsKey: 'image',
|
|
408
|
+
label: 'Image',
|
|
409
|
+
type: PropsFormType.Select,
|
|
410
|
+
options: 'image', // AssetType
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// Typography field
|
|
414
|
+
const fontField: PropsFormField = {
|
|
415
|
+
propsKey: 'font',
|
|
416
|
+
label: 'Font',
|
|
417
|
+
type: PropsFormType.Select,
|
|
418
|
+
options: 'typography',
|
|
419
|
+
};
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Integration with Other Packages
|
|
423
|
+
|
|
424
|
+
This types package is used throughout the Mapples ecosystem:
|
|
425
|
+
|
|
426
|
+
- **@mapples/action**: Uses `Action` and `ActionPayload` types for action management
|
|
427
|
+
- **@mapples/state**: Uses state-related types for state management
|
|
428
|
+
- **@mapples/ui**: Uses `RegisteredComponent` and related types for component registration
|
|
429
|
+
- **@mapples/form**: Uses `PropsFormField` and form-related types for property editing
|
|
430
|
+
- **@mapples/style**: Uses `StyleKey` and `StyleFormType` for styling configuration
|
|
431
|
+
- **@mapples/render**: Uses component types for rendering components
|
|
432
|
+
|
|
433
|
+
## Type Safety
|
|
434
|
+
|
|
435
|
+
All types in this package are designed to provide maximum type safety and IntelliSense support. When working with Mapples components, you'll get:
|
|
436
|
+
|
|
437
|
+
- Autocomplete for all properties
|
|
438
|
+
- Type checking for component props
|
|
439
|
+
- Validation for form field configurations
|
|
440
|
+
- IntelliSense for style properties
|
|
441
|
+
|
|
442
|
+
## Contributing
|
|
443
|
+
|
|
444
|
+
When adding new types to this package:
|
|
445
|
+
|
|
446
|
+
1. Follow the existing naming conventions
|
|
447
|
+
2. Add comprehensive TSDoc comments
|
|
448
|
+
3. Include usage examples
|
|
449
|
+
4. Update this README with new types
|
|
450
|
+
5. Ensure all types are exported from the main index file
|
|
451
|
+
|
|
452
|
+
## License
|
|
453
|
+
|
|
454
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,aAAa,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AACjC,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC"}
|
package/dist/dims.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dims.d.ts","sourceRoot":"","sources":["../src/dims.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AACzC,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrC,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,CAAC;AASxD,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,IAAI,GAAG,IAS9C,CAAC"}
|
package/dist/dims.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FN_SEPARATOR } from './constants';
|
|
2
|
+
const dimRegExp = new RegExp(`^"(w|h|width|height)(${FN_SEPARATOR}\\d+)?"$`);
|
|
3
|
+
const mapDimsType = {
|
|
4
|
+
w: 'width',
|
|
5
|
+
h: 'height',
|
|
6
|
+
width: 'width',
|
|
7
|
+
height: 'height',
|
|
8
|
+
};
|
|
9
|
+
export const parseDims = (dim) => {
|
|
10
|
+
if (dimRegExp.test(dim)) {
|
|
11
|
+
const [type, percent] = dim.slice(1, -1).split(FN_SEPARATOR);
|
|
12
|
+
const value = parseInt(percent || '', 10);
|
|
13
|
+
return [mapDimsType[type], !isNaN(value) ? value / 100 : 1];
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=dims.js.map
|
package/dist/dims.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dims.js","sourceRoot":"","sources":["../src/dims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,wBAAwB,YAAY,UAAU,CAAC,CAAC;AAM7E,MAAM,WAAW,GAAG;IAClB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,QAAQ;IACX,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC;AAEX,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAe,EAAE;IACpD,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC7D,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAE1C,OAAO,CAAC,WAAW,CAAC,IAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../../src/state/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,EAAE,EAAE,aAAiC,CAAC;AACnD,eAAO,MAAM,KAAK,EAAE,aAAiC,CAAC;AAEtD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAG1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../../src/state/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,CAAC,MAAM,EAAE,GAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,KAAK,GAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,YAAY,GAAsC;IAC7D,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE;IACvB,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,KAAK;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/state/regexp.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,QAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../src/state/regexp.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of condition operators for evaluating data properties.
|
|
3
|
+
*
|
|
4
|
+
* Used in condition strings to specify how to compare a data property value
|
|
5
|
+
* against another value.
|
|
6
|
+
*
|
|
7
|
+
* @enum Conditions
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare enum Conditions {
|
|
11
|
+
/** Equality condition - checks if values are equal */
|
|
12
|
+
equals = "eq",
|
|
13
|
+
/** Not equals condition - checks if values are not equal */
|
|
14
|
+
notEquals = "neq"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type representing a simple condition string.
|
|
18
|
+
*
|
|
19
|
+
* Format: `${dataProp}::${condition}::${value}`
|
|
20
|
+
* where dataProp is a path, condition is a Conditions operator, and value is a string.
|
|
21
|
+
*
|
|
22
|
+
* @type SimpleCondition
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type SimpleCondition = `${string}::${Conditions}::${string}`;
|
|
26
|
+
/**
|
|
27
|
+
* Type representing a boolean condition string.
|
|
28
|
+
*
|
|
29
|
+
* Format: `${dataProp}::${condition}::${'true' | 'false'}`
|
|
30
|
+
* Used for conditions that compare against boolean values.
|
|
31
|
+
*
|
|
32
|
+
* @type BoolCondition
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export type BoolCondition = `${string}::${Conditions}::${'true' | 'false'}`;
|
|
36
|
+
/**
|
|
37
|
+
* Function type for condition evaluation.
|
|
38
|
+
*
|
|
39
|
+
* Takes two values and returns a boolean indicating whether the condition is met.
|
|
40
|
+
*
|
|
41
|
+
* @type ConditionFunc
|
|
42
|
+
* @param a - First value to compare
|
|
43
|
+
* @param b - Second value to compare
|
|
44
|
+
* @returns True if the condition is satisfied, false otherwise
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export type ConditionFunc = (a: unknown, b: unknown) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Type representing the type of a value in a condition.
|
|
50
|
+
*
|
|
51
|
+
* @type ValueType
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export type ValueType = 'string' | 'number' | 'boolean' | 'dataProp';
|
|
55
|
+
/**
|
|
56
|
+
* Result of parsing a condition string.
|
|
57
|
+
*
|
|
58
|
+
* Contains the parsed components of a condition string including the data property path,
|
|
59
|
+
* the condition operator, the value to compare against, and the type of that value.
|
|
60
|
+
*
|
|
61
|
+
* @interface ParseConditionResult
|
|
62
|
+
* @property {string} dataProp - The data property path to evaluate
|
|
63
|
+
* @property {Conditions} condition - The condition operator to use
|
|
64
|
+
* @property {string | boolean} valueProp - The value to compare against
|
|
65
|
+
* @property {ValueType} valueType - The type of the value (string, number, boolean, or dataProp)
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export interface ParseConditionResult {
|
|
69
|
+
dataProp: string;
|
|
70
|
+
condition: Conditions;
|
|
71
|
+
valueProp: string | boolean;
|
|
72
|
+
valueType: ValueType;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,oBAAY,UAAU;IACpB,sDAAsD;IACtD,MAAM,OAAO;IACb,4DAA4D;IAC5D,SAAS,QAAQ;CAClB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,MAAM,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,GAAG,MAAM,KAAK,UAAU,KAAK,MAAM,GAAG,OAAO,EAAE,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,SAAS,EAAE,SAAS,CAAC;CACtB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of condition operators for evaluating data properties.
|
|
3
|
+
*
|
|
4
|
+
* Used in condition strings to specify how to compare a data property value
|
|
5
|
+
* against another value.
|
|
6
|
+
*
|
|
7
|
+
* @enum Conditions
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export var Conditions;
|
|
11
|
+
(function (Conditions) {
|
|
12
|
+
/** Equality condition - checks if values are equal */
|
|
13
|
+
Conditions["equals"] = "eq";
|
|
14
|
+
/** Not equals condition - checks if values are not equal */
|
|
15
|
+
Conditions["notEquals"] = "neq";
|
|
16
|
+
})(Conditions || (Conditions = {}));
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,sDAAsD;IACtD,2BAAa,CAAA;IACb,4DAA4D;IAC5D,+BAAiB,CAAA;AACnB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BoolCondition, ParseConditionResult, SimpleCondition } from './types';
|
|
2
|
+
export declare const toConditionString: (...values: string[]) => string;
|
|
3
|
+
export declare const parseConditionString: (value: string) => ParseConditionResult;
|
|
4
|
+
/**
|
|
5
|
+
* Parses a condition string into its component parts.
|
|
6
|
+
*
|
|
7
|
+
* Condition strings follow the format: `dataProp::condition::value`
|
|
8
|
+
* - `dataProp`: The data property path to evaluate
|
|
9
|
+
* - `condition`: The condition operator (eq, neq)
|
|
10
|
+
* - `value`: The value to compare against (can be a string, boolean, or dataProp reference)
|
|
11
|
+
*
|
|
12
|
+
* @param value - The condition string to parse (e.g., "user.age::eq::18" or "user.active::eq::true")
|
|
13
|
+
* @returns A parsed condition result with dataProp, condition, valueProp, and valueType
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const result = parseCondition("user.age::eq::18");
|
|
18
|
+
* // Returns: { dataProp: "user.age", condition: Conditions.equals, valueProp: "18", valueType: "dataProp" }
|
|
19
|
+
*
|
|
20
|
+
* const boolResult = parseCondition("user.active::eq::true");
|
|
21
|
+
* // Returns: { dataProp: "user.active", condition: Conditions.equals, valueProp: true, valueType: "boolean" }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const parseCondition: (value: SimpleCondition | BoolCondition) => ParseConditionResult;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard that checks if a value is a valid condition string.
|
|
29
|
+
*
|
|
30
|
+
* Valid condition strings follow the pattern: `dataProp::condition::value`
|
|
31
|
+
* where:
|
|
32
|
+
* - `dataProp` is alphanumeric with dots and underscores
|
|
33
|
+
* - `condition` is alphanumeric with underscores
|
|
34
|
+
* - `value` can be a quoted string, alphanumeric, or empty
|
|
35
|
+
*
|
|
36
|
+
* @param value - The value to check
|
|
37
|
+
* @returns True if the value is a valid condition string, false otherwise
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* isCondition("user.age::eq::18"); // true
|
|
42
|
+
* isCondition("user.active::eq::true"); // true
|
|
43
|
+
* isCondition("invalid"); // false
|
|
44
|
+
* isCondition(123); // false
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare const isCondition: (value: unknown) => value is SimpleCondition;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a string or boolean value to a boolean.
|
|
52
|
+
*
|
|
53
|
+
* String values are converted by checking if they equal the string "true".
|
|
54
|
+
* Boolean values are returned as-is.
|
|
55
|
+
*
|
|
56
|
+
* @param value - The value to convert (string or boolean)
|
|
57
|
+
* @returns The boolean representation of the value
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* toBool("true"); // true
|
|
62
|
+
* toBool("false"); // false
|
|
63
|
+
* toBool(true); // true
|
|
64
|
+
* toBool(false); // false
|
|
65
|
+
* toBool("yes"); // false
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare const toBool: (value: string | boolean) => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Converts a string or boolean value to a number.
|
|
73
|
+
*
|
|
74
|
+
* - Boolean values: true becomes 1, false becomes 0
|
|
75
|
+
* - String values: parsed using Number(), returns 0 if NaN
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to convert (string or boolean)
|
|
78
|
+
* @returns The numeric representation of the value (0 if conversion fails)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* toNumber("123"); // 123
|
|
83
|
+
* toNumber("45.67"); // 45.67
|
|
84
|
+
* toNumber(true); // 1
|
|
85
|
+
* toNumber(false); // 0
|
|
86
|
+
* toNumber("invalid"); // 0
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare const toNumber: (value: string | boolean) => number;
|
|
92
|
+
export declare const parseJoin: (key: string) => string[];
|
|
93
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EAEb,oBAAoB,EACpB,eAAe,EAEhB,MAAM,SAAS,CAAC;AAWjB,eAAO,MAAM,iBAAiB,GAAI,GAAG,QAAQ,MAAM,EAAE,WAEpD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,oBAWpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,eAAe,GAAG,aAAa,KACrC,oBAgCF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,eAKrD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,GAAG,OAAO,YAI7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,GAAG,OAAO,WAU/C,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,aAEpC,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { FN_SEPARATOR } from '@mapples/inlang';
|
|
2
|
+
import { ConditionStringRegExp } from './regexp';
|
|
3
|
+
const mapTypes = {
|
|
4
|
+
str: 'string',
|
|
5
|
+
num: 'number',
|
|
6
|
+
bool: 'boolean',
|
|
7
|
+
string: 'string',
|
|
8
|
+
number: 'number',
|
|
9
|
+
boolean: 'boolean',
|
|
10
|
+
};
|
|
11
|
+
export const toConditionString = (...values) => {
|
|
12
|
+
return values.join(FN_SEPARATOR);
|
|
13
|
+
};
|
|
14
|
+
export const parseConditionString = (value) => {
|
|
15
|
+
const [dataProp, condition, valueProp] = value
|
|
16
|
+
.trim()
|
|
17
|
+
.split(ConditionStringRegExp);
|
|
18
|
+
return {
|
|
19
|
+
dataProp,
|
|
20
|
+
condition: condition,
|
|
21
|
+
valueProp: valueProp,
|
|
22
|
+
valueType: 'string',
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Parses a condition string into its component parts.
|
|
27
|
+
*
|
|
28
|
+
* Condition strings follow the format: `dataProp::condition::value`
|
|
29
|
+
* - `dataProp`: The data property path to evaluate
|
|
30
|
+
* - `condition`: The condition operator (eq, neq)
|
|
31
|
+
* - `value`: The value to compare against (can be a string, boolean, or dataProp reference)
|
|
32
|
+
*
|
|
33
|
+
* @param value - The condition string to parse (e.g., "user.age::eq::18" or "user.active::eq::true")
|
|
34
|
+
* @returns A parsed condition result with dataProp, condition, valueProp, and valueType
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const result = parseCondition("user.age::eq::18");
|
|
39
|
+
* // Returns: { dataProp: "user.age", condition: Conditions.equals, valueProp: "18", valueType: "dataProp" }
|
|
40
|
+
*
|
|
41
|
+
* const boolResult = parseCondition("user.active::eq::true");
|
|
42
|
+
* // Returns: { dataProp: "user.active", condition: Conditions.equals, valueProp: true, valueType: "boolean" }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export const parseCondition = (value) => {
|
|
48
|
+
const [dataProp, condition, valueProp] = value
|
|
49
|
+
.trim()
|
|
50
|
+
.split(ConditionStringRegExp);
|
|
51
|
+
if (valueProp === 'true' || valueProp === 'false')
|
|
52
|
+
return {
|
|
53
|
+
dataProp,
|
|
54
|
+
condition: condition,
|
|
55
|
+
valueProp: valueProp === 'true',
|
|
56
|
+
valueType: 'boolean',
|
|
57
|
+
};
|
|
58
|
+
if (/^"[^"]*"$/.test(valueProp)) {
|
|
59
|
+
const parsedValue = valueProp.slice(1, -1);
|
|
60
|
+
const [value, type] = parsedValue.split(FN_SEPARATOR);
|
|
61
|
+
return {
|
|
62
|
+
dataProp,
|
|
63
|
+
condition: condition,
|
|
64
|
+
valueProp: value,
|
|
65
|
+
valueType: mapTypes[type] || 'string',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
dataProp,
|
|
70
|
+
condition: condition,
|
|
71
|
+
valueProp,
|
|
72
|
+
valueType: 'dataProp',
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Type guard that checks if a value is a valid condition string.
|
|
77
|
+
*
|
|
78
|
+
* Valid condition strings follow the pattern: `dataProp::condition::value`
|
|
79
|
+
* where:
|
|
80
|
+
* - `dataProp` is alphanumeric with dots and underscores
|
|
81
|
+
* - `condition` is alphanumeric with underscores
|
|
82
|
+
* - `value` can be a quoted string, alphanumeric, or empty
|
|
83
|
+
*
|
|
84
|
+
* @param value - The value to check
|
|
85
|
+
* @returns True if the value is a valid condition string, false otherwise
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* isCondition("user.age::eq::18"); // true
|
|
90
|
+
* isCondition("user.active::eq::true"); // true
|
|
91
|
+
* isCondition("invalid"); // false
|
|
92
|
+
* isCondition(123); // false
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export const isCondition = (value) => {
|
|
98
|
+
return (typeof value === 'string' &&
|
|
99
|
+
/^[a-zA-Z0-9_.]+::[a-zA-Z0-9_]+::("[^"]*"|[a-zA-Z0-9_]*|)$/.test(value));
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Converts a string or boolean value to a boolean.
|
|
103
|
+
*
|
|
104
|
+
* String values are converted by checking if they equal the string "true".
|
|
105
|
+
* Boolean values are returned as-is.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The value to convert (string or boolean)
|
|
108
|
+
* @returns The boolean representation of the value
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* toBool("true"); // true
|
|
113
|
+
* toBool("false"); // false
|
|
114
|
+
* toBool(true); // true
|
|
115
|
+
* toBool(false); // false
|
|
116
|
+
* toBool("yes"); // false
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export const toBool = (value) => {
|
|
122
|
+
if (typeof value === 'boolean')
|
|
123
|
+
return value;
|
|
124
|
+
return value === 'true';
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Converts a string or boolean value to a number.
|
|
128
|
+
*
|
|
129
|
+
* - Boolean values: true becomes 1, false becomes 0
|
|
130
|
+
* - String values: parsed using Number(), returns 0 if NaN
|
|
131
|
+
*
|
|
132
|
+
* @param value - The value to convert (string or boolean)
|
|
133
|
+
* @returns The numeric representation of the value (0 if conversion fails)
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* toNumber("123"); // 123
|
|
138
|
+
* toNumber("45.67"); // 45.67
|
|
139
|
+
* toNumber(true); // 1
|
|
140
|
+
* toNumber(false); // 0
|
|
141
|
+
* toNumber("invalid"); // 0
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export const toNumber = (value) => {
|
|
147
|
+
if (typeof value === 'boolean') {
|
|
148
|
+
return value ? 1 : 0;
|
|
149
|
+
}
|
|
150
|
+
const numValue = Number(value);
|
|
151
|
+
if (isNaN(numValue))
|
|
152
|
+
return 0;
|
|
153
|
+
return numValue;
|
|
154
|
+
};
|
|
155
|
+
export const parseJoin = (key) => {
|
|
156
|
+
return key.replace(/\n/g, '').split(';');
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"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"}
|
package/dist/this.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type This = ['this', string?];
|
|
2
|
+
export declare const isThis: (value?: string) => boolean;
|
|
3
|
+
export declare const isDataThis: (value?: string) => boolean | undefined;
|
|
4
|
+
export declare const parseDataThis: (value: string) => string[];
|
|
5
|
+
export declare const parseThis: (value?: string) => This;
|
|
6
|
+
//# sourceMappingURL=this.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"this.d.ts","sourceRoot":"","sources":["../src/this.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAErC,eAAO,MAAM,MAAM,GAAI,QAAQ,MAAM,YAEpC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,wBAExC,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,aAE1C,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,KAAG,IAE1C,CAAC"}
|
package/dist/this.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DATA_THIS, DOT_SEPARATOR, FN_SEPARATOR } from './constants';
|
|
2
|
+
const actionThisRegExp = new RegExp(`^"this(${FN_SEPARATOR}\\d+)?"$`);
|
|
3
|
+
export const isThis = (value) => {
|
|
4
|
+
return actionThisRegExp.test(value || '');
|
|
5
|
+
};
|
|
6
|
+
export const isDataThis = (value) => {
|
|
7
|
+
return value?.startsWith(DATA_THIS);
|
|
8
|
+
};
|
|
9
|
+
export const parseDataThis = (value) => {
|
|
10
|
+
return value.replace(DATA_THIS, '').split(DOT_SEPARATOR);
|
|
11
|
+
};
|
|
12
|
+
export const parseThis = (value) => {
|
|
13
|
+
return value ? value.slice(1, -1).split(FN_SEPARATOR) : ['this'];
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=this.js.map
|
package/dist/this.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"this.js","sourceRoot":"","sources":["../src/this.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,UAAU,YAAY,UAAU,CAAC,CAAC;AAItE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE;IACvC,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,EAAE;IAC3C,OAAO,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,EAAE;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAQ,EAAE;IAChD,OAAO,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mapples/inlang",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -b tsconfig.build.json",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"type-check": "tsc --noEmit",
|
|
10
|
+
"clean": "rm -rf dist"
|
|
11
|
+
},
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Oleksandr Soloviov",
|
|
14
|
+
"url": "https://mapples.org/people/olek_soloviov"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/mapplesorg/mapples-open-kit.git",
|
|
20
|
+
"directory": "packages/@mapples/inlang"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"package.json"
|
|
26
|
+
]
|
|
27
|
+
}
|