ftvuzw-configuration-builder 0.1.0 → 0.1.2

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 (4) hide show
  1. package/LICENSE +0 -30
  2. package/dist/index.js +48 -592
  3. package/package.json +2 -2
  4. package/README.md +0 -211
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ftvuzw-configuration-builder",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "dev": "python -m http.server 8770",
18
- "build": "esbuild src/index.js --bundle --outfile=dist/index.js --format=esm --minify",
18
+ "build": "node build.mjs",
19
19
  "prepublishOnly": "npm run build",
20
20
  "test": "echo \"No tests yet\" && exit 0"
21
21
  },
package/README.md DELETED
@@ -1,211 +0,0 @@
1
- # dialog-builder-element
2
-
3
- A configurable `<dialog-builder>` **web component** for visually authoring
4
- form/dialog configurations. Each field can carry visibility (`hidden`),
5
- read-only, dropdown options, a computed value (`calculation`) and validation —
6
- all authored through a no-code **rule builder** that compiles to plain
7
- `x => …` JavaScript function strings plus a plain-language summary.
8
-
9
- The headline design goal is **configurability by field type**: every element
10
- type declares *which features it supports*, so a `file` upload (no options, no
11
- calculation) and a rich `dropdown` share the same engine without special-casing.
12
-
13
- ```
14
- <dialog-builder>
15
- ├─ top bar: config name + roles
16
- ├─ rows of field "cards" (Label, Type, Width, Default)
17
- │ └─ per-card feature tabs — rendered ONLY for features the type supports
18
- │ Readonly · Hide · Dropdown · Calculation · Validation
19
- └─ live JSON output (active field / complete dialog)
20
- ```
21
-
22
- ## Install
23
-
24
- ```bash
25
- npm install dialog-builder-element
26
- ```
27
-
28
- The package ships as native ES modules (no build step required).
29
-
30
- ## Usage
31
-
32
- ```html
33
- <dialog-builder id="builder"></dialog-builder>
34
-
35
- <script type="module">
36
- import 'dialog-builder-element'; // registers <dialog-builder>
37
-
38
- const builder = document.getElementById('builder');
39
-
40
- // Load an existing config (also settable before the element upgrades).
41
- builder.config = {
42
- name: 'Risk Dialog',
43
- roles: ['Admin', 'Manager'],
44
- rows: [
45
- [
46
- { key: 'origin', label: 'Origin Project', type: 'text', width: 2 },
47
- { key: 'risk', label: 'Project Risk', type: 'dropdown', width: 2,
48
- options: ['This Project', 'Outside Project'] },
49
- { key: 'attachment', label: 'Attachment', type: 'file', width: 2 },
50
- ],
51
- ],
52
- };
53
-
54
- // React to every edit.
55
- builder.addEventListener('change', (e) => {
56
- console.log(e.detail); // -> { name, roles, rows: [[field, ...]] }
57
- });
58
-
59
- // Read the current config any time.
60
- const cfg = builder.getConfig();
61
- </script>
62
- ```
63
-
64
- ### Properties
65
-
66
- | Property | Type | Description |
67
- |---------------|-------------------------------|-------------|
68
- | `config` | `{ name, roles, rows }` | Get/set the whole dialog config. `rows` is an array of rows; each row is an array of field objects. |
69
- | `roles` | `string[]` | Get/set the global role list used by role-based readonly/hidden rules. |
70
- | `fieldTypes` | `FieldType[]` (set only) | Replace the field-type registry. See below. |
71
-
72
- ### Methods & events
73
-
74
- - `getConfig()` → deep copy of the current config.
75
- - `"change"` event → `CustomEvent` whose `detail` is the current config; fires on any edit.
76
-
77
- ### Theming
78
-
79
- All colors are CSS custom properties set on `:host`. Override them on the element:
80
-
81
- ```css
82
- dialog-builder { --db-primary: #0b7285; --db-radius: 6px; }
83
- ```
84
-
85
- ## Configurable field types — the important part
86
-
87
- A field type is just data. Every type declares a `features` array; the UI reads
88
- it to decide which controls to render. **Adding a new type requires no code
89
- changes outside the registry.**
90
-
91
- ```js
92
- import { DEFAULT_FIELD_TYPES, FEATURES } from 'dialog-builder-element/field-types';
93
-
94
- builder.fieldTypes = [
95
- ...DEFAULT_FIELD_TYPES,
96
- {
97
- value: 'rating', // stored on field.type
98
- label: 'Star Rating', // shown in the type dropdown
99
- icon: 'star', // Material Symbols icon name
100
- defaultWidth: 2, // grid columns a new field spans
101
- valueBucket: 'number', // how the rule engine compares it: text|number|bool|array
102
- features: [
103
- FEATURES.READONLY,
104
- FEATURES.HIDDEN,
105
- FEATURES.VALIDATION,
106
- FEATURES.CALCULATION,
107
- FEATURES.DEFAULT,
108
- ],
109
- },
110
- ];
111
- ```
112
-
113
- ### Available features
114
-
115
- | Feature | Effect on the card |
116
- |------------------------|--------------------|
117
- | `FEATURES.READONLY` | "Readonly" rule tab (`x => boolean`, `true` = read-only). |
118
- | `FEATURES.HIDDEN` | "Hide" rule tab (`x => boolean`, `true` = hidden). |
119
- | `FEATURES.OPTIONS` | "Dropdown" editor: value list, table (`{value,label,…}`), or async API fetcher. |
120
- | `FEATURES.MULTIPLE` | Adds the multi-select toggle inside the options editor (needs `OPTIONS`). |
121
- | `FEATURES.CALCULATION` | "Calculation" rule tab (computed value: number/text/bool/date/formula/field/JSON). |
122
- | `FEATURES.VALIDATION` | "Validation" rule tab (returns an error message or `""`). |
123
- | `FEATURES.DEFAULT` | Shows the inline "Default value" input. |
124
-
125
- ### Built-in types
126
-
127
- | Type | Features |
128
- |------------|----------|
129
- | `text` | readonly, hidden, validation, calculation, default |
130
- | `number` | readonly, hidden, validation, calculation, default |
131
- | `dropdown` | readonly, hidden, **options**, **multiple**, validation, calculation, default |
132
- | `textarea` | readonly, hidden, validation, default |
133
- | `checkbox` | readonly, hidden, validation, calculation, default |
134
- | `date` | readonly, hidden, validation, calculation, default |
135
- | `file` | readonly, hidden, validation — *example of a structurally lighter type* |
136
-
137
- > The `file` type ships as a worked example: it has no Dropdown or Calculation
138
- > buttons because those features simply aren't listed. Remove the type, or add
139
- > your own, by passing a custom registry.
140
-
141
- ## Output shape
142
-
143
- `getConfig()` / the `change` event produce a compact JSON/JS-style config —
144
- each rule is a plain JS function (as a source string), and anything unset is
145
- omitted:
146
-
147
- ```jsonc
148
- {
149
- "name": "Risk Dialog",
150
- "roles": ["Admin", "Manager"],
151
- "rows": [
152
- [
153
- {
154
- "key": "origin",
155
- "label": "Origin Project",
156
- "type": "text",
157
- "width": 2,
158
- "options": ["A", "B"], // or [{value,label}], for dropdowns
159
- "default": "",
160
- "readonly": "x => x.currentUserRole === \"User\"", // true → read-only
161
- "hidden": "x => !x.origin", // true → hidden
162
- "validate": "x => !x.origin ? \"Required\" : \"\"", // "" → valid
163
- "color": "x => x.risk > 5 ? \"#f44336\" : \"\"", // hex → tint
164
- "onInit": "x => \"default value\"", // computed default
165
- // or "onUpdate": recomputed on every change (field becomes read-only)
166
- "email": "(prevX, x) => [...recipients]",
167
- "_rules": { /* visual-editor rule models — see below */ }
168
- }
169
- ]
170
- ]
171
- }
172
- ```
173
-
174
- The rule keys are executable function strings your runtime can `new Function`
175
- to drive a live form; `x` is the current form values plus `currentUserRole` /
176
- `currentUser`. `_rules` holds the editable models behind the visual rule
177
- builder — the builder regenerates the functions from them on load, so a saved
178
- config re-opens with its rules intact. Strip `_rules` if a consumer only needs
179
- the runtime behavior.
180
-
181
- Importing also accepts the old verbose shape (`readonlyCode`, `hiddenCode`,
182
- `validationCode`, `colorCode`, `calculation` + `calculationTrigger`, top-level
183
- `*Rules`) and production-style booleans (`disabled: true` / `hidden: true`
184
- become constant functions).
185
-
186
- ## Reusing the engine directly
187
-
188
- The pure codegen functions are exported if you want to compile rule models
189
- yourself (no DOM):
190
-
191
- ```js
192
- import { codegen } from 'dialog-builder-element';
193
- // or: import * as codegen from 'dialog-builder-element/codegen';
194
-
195
- const fields = [{ key: 'amount', label: 'Amount', type: 'number' }];
196
- const js = codegen.genValidationJs(fields, {
197
- rules: [{ when: { combinator: 'AND', conditions: [
198
- { field: 'amount', operator: 'isEmpty' },
199
- ] }, message: 'Required' }],
200
- });
201
- // -> x => (x.amount === null || x.amount === undefined || x.amount === "") ? "Required" : ""
202
- ```
203
-
204
- ## Scope (v0.1)
205
-
206
- Included: cards, rows, the field-type registry, the rule builder (readonly /
207
- hidden / calculation / validation), options (value/table/API), roles, live JSON
208
- output, `change` events.
209
-
210
- Deferred to a later version: drag-and-drop reordering of cards/rows, and the
211
- JSON import/validation panel from the original prototype.