@fuf-stack/megapixels 0.0.1 → 0.1.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.
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkXMMMIB2Ccjs = require('../chunk-XMMMIB2C.cjs');
6
+
7
+
8
+
9
+
10
+ exports.createFilter = _chunkXMMMIB2Ccjs.createFilter_default; exports.default = _chunkXMMMIB2Ccjs.Filter_default; exports.filters = _chunkXMMMIB2Ccjs.filters;
11
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/pixels/pixels/packages/megapixels/dist/Filter/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACF,+JAAC","file":"/home/runner/work/pixels/pixels/packages/megapixels/dist/Filter/index.cjs"}
@@ -0,0 +1,219 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * FilterDefinition
6
+ *
7
+ * Declarative description of a filter. A FilterDefinition is not used
8
+ * directly by the UI. Instead, it is passed to `createFilter` to produce a
9
+ * concrete, runtime `FilterInstance` for a specific usage (with name/icon and
10
+ * optional config overrides).
11
+ *
12
+ * @typeParam Config - The configuration object shape for this filter
13
+ * @typeParam Value - The runtime value type produced/consumed by this filter
14
+ */
15
+ interface FilterDefinition<Config, Value> {
16
+ components: {
17
+ /**
18
+ * Display component rendered inside the filter chip. Receives the current
19
+ * filter `value` and the merged `config`.
20
+ */
21
+ Display: (props: {
22
+ value: Value;
23
+ config: Config;
24
+ }) => ReactNode;
25
+ /**
26
+ * Form component rendered inside the modal. Receives the fully-qualified
27
+ * field name and the merged, validated `config`.
28
+ */
29
+ Form: (props: {
30
+ fieldName: string;
31
+ config: Config;
32
+ }) => ReactNode;
33
+ };
34
+ defaults: {
35
+ /** Baseline configuration for the filter; can be overridden per usage */
36
+ config: Config;
37
+ /** Initial form value seeded when a filter is added */
38
+ value: Value;
39
+ };
40
+ /**
41
+ * Validation factory returning an ex-validator schema for the value shape.
42
+ * Receives the (merged) `config` so the schema can depend on configuration.
43
+ */
44
+ validation: (config?: Config) => unknown;
45
+ }
46
+ /**
47
+ * FilterFactory
48
+ *
49
+ * A filter exports a factory that, given name/icon and optional config
50
+ * overrides, returns a concrete FilterInstance with merged config and a
51
+ * computed defaultValue.
52
+ *
53
+ * @typeParam Config - Configuration object shape for the filter
54
+ * @typeParam Value - Runtime value type for the filter
55
+ */
56
+ type FilterFactory<Config, Value> = (args: {
57
+ /** Per-usage configuration overrides merged with `defaults.config` */
58
+ config?: Partial<Config>;
59
+ /** Optional icon element shown in menus/labels */
60
+ icon?: ReactNode;
61
+ /** Logical field name under `filter.{name}` */
62
+ name: string;
63
+ }) => FilterInstance<Config, Value>;
64
+ /**
65
+ * FilterInstance
66
+ *
67
+ * Runtime instance created by merging a filter's defaults with usage
68
+ * overrides and attaching name/icon for UI.
69
+ *
70
+ * This is the only shape used by the rendering layer and context.
71
+ *
72
+ * @typeParam Config - Effective configuration object shape
73
+ * @typeParam Value - Effective value type for the filter
74
+ */
75
+ interface FilterInstance<Config, Value> {
76
+ /** UI components (Form/Display) provided by the filter */
77
+ components: FilterDefinition<Config, Value>['components'];
78
+ /** Merged configuration (`defaults.config` overlaid with per-usage overrides) */
79
+ config: Config;
80
+ /** Initial form value to seed when adding this filter */
81
+ defaultValue: Value;
82
+ /** Optional icon element used in menus/labels */
83
+ icon?: ReactNode;
84
+ /** Logical field name under `filter.{name}` */
85
+ name: string;
86
+ /** ex-validator schema factory for the value; typically closure over config */
87
+ validation: (config?: Config) => unknown;
88
+ }
89
+ /**
90
+ * FiltersConfiguration
91
+ *
92
+ * Top-level collection of instantiated filters used by the Filter component
93
+ * and FiltersContext. Each entry is a concrete FilterInstance (already created
94
+ * via a filter factory), carrying its merged config, default value, UI
95
+ * components, and validate function.
96
+ */
97
+ type FiltersConfiguration = FilterInstance<any, any>[];
98
+ /**
99
+ * FilterDisplayProps
100
+ *
101
+ * Props provided to a filter's Display component. Derived from an active
102
+ * FilterInstance at runtime.
103
+ *
104
+ * @typeParam Config - Effective configuration type for the instance
105
+ * @typeParam Value - Effective value type for the instance
106
+ */
107
+ interface FilterDisplayProps<Config, Value> {
108
+ /** Merged configuration for the filter instance */
109
+ config: Config;
110
+ /** Current (possibly partial) value for the filter instance */
111
+ value: Value;
112
+ }
113
+ /**
114
+ * FilterFormProps
115
+ *
116
+ * Props provided to a filter's Form component. The `fieldName` is the
117
+ * fully-qualified path in the host form, and the `config` is the instance's
118
+ * merged configuration.
119
+ *
120
+ * @typeParam Config - Effective configuration type for the instance
121
+ */
122
+ interface FilterFormProps<Config> {
123
+ /** Merged configuration for the filter instance */
124
+ config: Config;
125
+ /** Fully-qualified form field path (e.g., `filter.status`) */
126
+ fieldName: string;
127
+ }
128
+
129
+ type SearchConfiguration = boolean | {
130
+ /** Placeholder shown in the search input */
131
+ placeholder?: string;
132
+ };
133
+
134
+ interface FilterValues {
135
+ search?: string;
136
+ filter?: string | Record<string, unknown>;
137
+ }
138
+ type FilterChildRenderFn = (values: FilterValues) => ReactNode;
139
+ /**
140
+ * Filter
141
+ *
142
+ * Controlled, form-driven filter UI.
143
+ *
144
+ * Responsibilities
145
+ * - Derives initial form values from the controlled `values` prop
146
+ * - Builds a composite validation schema from the filter registry (and optional search)
147
+ * - Exposes ergonomic UI: active filters list, add/remove actions, and per-filter modal
148
+ * - Commits changes by invoking the controlled `onChange` callback on submit
149
+ *
150
+ * Structure
151
+ * - Owns an ex-forms `Form` that wraps the entire filter experience
152
+ * - Optionally renders a search input bound to the `search` field
153
+ * - Renders ActiveFilters, AddFilterMenu, and FilterModal inside a shared context
154
+ * - Optionally renders children as a render-prop with the resolved `values`
155
+ */
156
+ interface FilterProps {
157
+ /** Optional render-prop that receives the resolved, controlled values */
158
+ children?: FilterChildRenderFn;
159
+ /** CSS class name */
160
+ className?: string;
161
+ /** Configuration of the filter */
162
+ config: {
163
+ /**
164
+ * Declarative filter configuration. Each entry ties a logical name to a
165
+ * registry filter type and (optionally) per-usage config overrides.
166
+ */
167
+ filters: FiltersConfiguration;
168
+ /** Optional configuration for search field */
169
+ search?: SearchConfiguration;
170
+ };
171
+ /** ex-forms form instance name. Defaults to "filterComponentForm". */
172
+ formName?: string;
173
+ /** Controlled setter invoked on submit with the next canonical values */
174
+ onChange: (nextValues: FilterValues) => void;
175
+ /** Controlled committed state: the canonical `search` and `filter` values */
176
+ values: FilterValues;
177
+ }
178
+ /**
179
+ * Renders the filter UI bound to a single ex-forms `Form`.
180
+ * The form is the source of truth during user interaction; the committed
181
+ * state is controlled by the parent via `values`/`onChange`.
182
+ */
183
+ declare const Filter: ({ children, className, config, formName, onChange, values, }: FilterProps) => react_jsx_runtime.JSX.Element;
184
+
185
+ /**
186
+ * createFilter
187
+ *
188
+ * Builds a filter factory from a static FilterDefinition. The returned factory
189
+ * accepts a usage descriptor (name/icon and optional partial config) and
190
+ * produces a concrete FilterInstance with:
191
+ * - merged config (shallow: definition.defaults.config overlaid by overrides)
192
+ * - Form/Display components
193
+ * - validate function (forwarded from the definition)
194
+ * - defaultValue (forwarded from the definition)
195
+ * - name and icon for UI integration
196
+ *
197
+ * @typeParam Config - Configuration object shape for the filter
198
+ * @typeParam Value - Runtime value type for the filter
199
+ * @param definition - Static description of the filter (components, defaults, validate)
200
+ * @returns FilterFactory that creates FilterInstance<Config, Value>
201
+ */
202
+ declare const createFilter: <Config, Value>(definition: FilterDefinition<Config, Value>) => FilterFactory<Config, Value>;
203
+
204
+ declare const filters: {
205
+ boolean: FilterFactory<{
206
+ text: string;
207
+ textPrefix?: string | undefined;
208
+ textNoWord?: string | undefined;
209
+ }, boolean | undefined>;
210
+ checkboxgroup: FilterFactory<{
211
+ text: string;
212
+ options: {
213
+ value: string;
214
+ label: string;
215
+ }[];
216
+ }, string[]>;
217
+ };
218
+
219
+ export { type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, type FiltersConfiguration, createFilter, Filter as default, filters };
@@ -0,0 +1,219 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * FilterDefinition
6
+ *
7
+ * Declarative description of a filter. A FilterDefinition is not used
8
+ * directly by the UI. Instead, it is passed to `createFilter` to produce a
9
+ * concrete, runtime `FilterInstance` for a specific usage (with name/icon and
10
+ * optional config overrides).
11
+ *
12
+ * @typeParam Config - The configuration object shape for this filter
13
+ * @typeParam Value - The runtime value type produced/consumed by this filter
14
+ */
15
+ interface FilterDefinition<Config, Value> {
16
+ components: {
17
+ /**
18
+ * Display component rendered inside the filter chip. Receives the current
19
+ * filter `value` and the merged `config`.
20
+ */
21
+ Display: (props: {
22
+ value: Value;
23
+ config: Config;
24
+ }) => ReactNode;
25
+ /**
26
+ * Form component rendered inside the modal. Receives the fully-qualified
27
+ * field name and the merged, validated `config`.
28
+ */
29
+ Form: (props: {
30
+ fieldName: string;
31
+ config: Config;
32
+ }) => ReactNode;
33
+ };
34
+ defaults: {
35
+ /** Baseline configuration for the filter; can be overridden per usage */
36
+ config: Config;
37
+ /** Initial form value seeded when a filter is added */
38
+ value: Value;
39
+ };
40
+ /**
41
+ * Validation factory returning an ex-validator schema for the value shape.
42
+ * Receives the (merged) `config` so the schema can depend on configuration.
43
+ */
44
+ validation: (config?: Config) => unknown;
45
+ }
46
+ /**
47
+ * FilterFactory
48
+ *
49
+ * A filter exports a factory that, given name/icon and optional config
50
+ * overrides, returns a concrete FilterInstance with merged config and a
51
+ * computed defaultValue.
52
+ *
53
+ * @typeParam Config - Configuration object shape for the filter
54
+ * @typeParam Value - Runtime value type for the filter
55
+ */
56
+ type FilterFactory<Config, Value> = (args: {
57
+ /** Per-usage configuration overrides merged with `defaults.config` */
58
+ config?: Partial<Config>;
59
+ /** Optional icon element shown in menus/labels */
60
+ icon?: ReactNode;
61
+ /** Logical field name under `filter.{name}` */
62
+ name: string;
63
+ }) => FilterInstance<Config, Value>;
64
+ /**
65
+ * FilterInstance
66
+ *
67
+ * Runtime instance created by merging a filter's defaults with usage
68
+ * overrides and attaching name/icon for UI.
69
+ *
70
+ * This is the only shape used by the rendering layer and context.
71
+ *
72
+ * @typeParam Config - Effective configuration object shape
73
+ * @typeParam Value - Effective value type for the filter
74
+ */
75
+ interface FilterInstance<Config, Value> {
76
+ /** UI components (Form/Display) provided by the filter */
77
+ components: FilterDefinition<Config, Value>['components'];
78
+ /** Merged configuration (`defaults.config` overlaid with per-usage overrides) */
79
+ config: Config;
80
+ /** Initial form value to seed when adding this filter */
81
+ defaultValue: Value;
82
+ /** Optional icon element used in menus/labels */
83
+ icon?: ReactNode;
84
+ /** Logical field name under `filter.{name}` */
85
+ name: string;
86
+ /** ex-validator schema factory for the value; typically closure over config */
87
+ validation: (config?: Config) => unknown;
88
+ }
89
+ /**
90
+ * FiltersConfiguration
91
+ *
92
+ * Top-level collection of instantiated filters used by the Filter component
93
+ * and FiltersContext. Each entry is a concrete FilterInstance (already created
94
+ * via a filter factory), carrying its merged config, default value, UI
95
+ * components, and validate function.
96
+ */
97
+ type FiltersConfiguration = FilterInstance<any, any>[];
98
+ /**
99
+ * FilterDisplayProps
100
+ *
101
+ * Props provided to a filter's Display component. Derived from an active
102
+ * FilterInstance at runtime.
103
+ *
104
+ * @typeParam Config - Effective configuration type for the instance
105
+ * @typeParam Value - Effective value type for the instance
106
+ */
107
+ interface FilterDisplayProps<Config, Value> {
108
+ /** Merged configuration for the filter instance */
109
+ config: Config;
110
+ /** Current (possibly partial) value for the filter instance */
111
+ value: Value;
112
+ }
113
+ /**
114
+ * FilterFormProps
115
+ *
116
+ * Props provided to a filter's Form component. The `fieldName` is the
117
+ * fully-qualified path in the host form, and the `config` is the instance's
118
+ * merged configuration.
119
+ *
120
+ * @typeParam Config - Effective configuration type for the instance
121
+ */
122
+ interface FilterFormProps<Config> {
123
+ /** Merged configuration for the filter instance */
124
+ config: Config;
125
+ /** Fully-qualified form field path (e.g., `filter.status`) */
126
+ fieldName: string;
127
+ }
128
+
129
+ type SearchConfiguration = boolean | {
130
+ /** Placeholder shown in the search input */
131
+ placeholder?: string;
132
+ };
133
+
134
+ interface FilterValues {
135
+ search?: string;
136
+ filter?: string | Record<string, unknown>;
137
+ }
138
+ type FilterChildRenderFn = (values: FilterValues) => ReactNode;
139
+ /**
140
+ * Filter
141
+ *
142
+ * Controlled, form-driven filter UI.
143
+ *
144
+ * Responsibilities
145
+ * - Derives initial form values from the controlled `values` prop
146
+ * - Builds a composite validation schema from the filter registry (and optional search)
147
+ * - Exposes ergonomic UI: active filters list, add/remove actions, and per-filter modal
148
+ * - Commits changes by invoking the controlled `onChange` callback on submit
149
+ *
150
+ * Structure
151
+ * - Owns an ex-forms `Form` that wraps the entire filter experience
152
+ * - Optionally renders a search input bound to the `search` field
153
+ * - Renders ActiveFilters, AddFilterMenu, and FilterModal inside a shared context
154
+ * - Optionally renders children as a render-prop with the resolved `values`
155
+ */
156
+ interface FilterProps {
157
+ /** Optional render-prop that receives the resolved, controlled values */
158
+ children?: FilterChildRenderFn;
159
+ /** CSS class name */
160
+ className?: string;
161
+ /** Configuration of the filter */
162
+ config: {
163
+ /**
164
+ * Declarative filter configuration. Each entry ties a logical name to a
165
+ * registry filter type and (optionally) per-usage config overrides.
166
+ */
167
+ filters: FiltersConfiguration;
168
+ /** Optional configuration for search field */
169
+ search?: SearchConfiguration;
170
+ };
171
+ /** ex-forms form instance name. Defaults to "filterComponentForm". */
172
+ formName?: string;
173
+ /** Controlled setter invoked on submit with the next canonical values */
174
+ onChange: (nextValues: FilterValues) => void;
175
+ /** Controlled committed state: the canonical `search` and `filter` values */
176
+ values: FilterValues;
177
+ }
178
+ /**
179
+ * Renders the filter UI bound to a single ex-forms `Form`.
180
+ * The form is the source of truth during user interaction; the committed
181
+ * state is controlled by the parent via `values`/`onChange`.
182
+ */
183
+ declare const Filter: ({ children, className, config, formName, onChange, values, }: FilterProps) => react_jsx_runtime.JSX.Element;
184
+
185
+ /**
186
+ * createFilter
187
+ *
188
+ * Builds a filter factory from a static FilterDefinition. The returned factory
189
+ * accepts a usage descriptor (name/icon and optional partial config) and
190
+ * produces a concrete FilterInstance with:
191
+ * - merged config (shallow: definition.defaults.config overlaid by overrides)
192
+ * - Form/Display components
193
+ * - validate function (forwarded from the definition)
194
+ * - defaultValue (forwarded from the definition)
195
+ * - name and icon for UI integration
196
+ *
197
+ * @typeParam Config - Configuration object shape for the filter
198
+ * @typeParam Value - Runtime value type for the filter
199
+ * @param definition - Static description of the filter (components, defaults, validate)
200
+ * @returns FilterFactory that creates FilterInstance<Config, Value>
201
+ */
202
+ declare const createFilter: <Config, Value>(definition: FilterDefinition<Config, Value>) => FilterFactory<Config, Value>;
203
+
204
+ declare const filters: {
205
+ boolean: FilterFactory<{
206
+ text: string;
207
+ textPrefix?: string | undefined;
208
+ textNoWord?: string | undefined;
209
+ }, boolean | undefined>;
210
+ checkboxgroup: FilterFactory<{
211
+ text: string;
212
+ options: {
213
+ value: string;
214
+ label: string;
215
+ }[];
216
+ }, string[]>;
217
+ };
218
+
219
+ export { type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, type FiltersConfiguration, createFilter, Filter as default, filters };
@@ -0,0 +1,11 @@
1
+ import {
2
+ Filter_default,
3
+ createFilter_default,
4
+ filters
5
+ } from "../chunk-X574WZ6N.js";
6
+ export {
7
+ createFilter_default as createFilter,
8
+ Filter_default as default,
9
+ filters
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}