ngx-dynamic-entity-builder 1.14.0 → 2.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 CHANGED
@@ -46,10 +46,12 @@ export const appConfig: ApplicationConfig = {
46
46
  ```html
47
47
  <ngx-entity-builder
48
48
  [config]="initialConfig"
49
+ [rules]="initialRules"
49
50
  [languages]="['en', 'de']"
50
51
  [uiLanguage]="'en'"
51
52
  [availableRoles]="['admin', 'editor']"
52
53
  (configChange)="onConfigUpdated($event)"
54
+ (rulesChange)="onRulesUpdated($event)"
53
55
  (save)="onSave($event)"
54
56
  />
55
57
  ```
@@ -59,6 +61,7 @@ export const appConfig: ApplicationConfig = {
59
61
  | Input | Type | Notes |
60
62
  |---|---|---|
61
63
  | `config` | `EntityFormConfig \| undefined` | Omit to start from an empty schema. |
64
+ | `rules` | `FormRule[] \| undefined` | The rules that belong with `config`. They arrive together as one snapshot, so opening a builder is not itself an undoable step. Omit and it opens with none. |
62
65
  | `languages` | `string[]` | Locales offered for localized labels. Defaults to `['en']`. |
63
66
  | `uiLanguage` | `string` | Locale for the builder's **own** chrome, not the labels being authored. Defaults to `'en'`. |
64
67
  | `availableRoles` | `string[]` | Roles offered in the permissions editor. |
@@ -69,8 +72,43 @@ export const appConfig: ApplicationConfig = {
69
72
  | Output | Payload |
70
73
  |---|---|
71
74
  | `configChange` | `EntityFormConfig` — emitted on every edit. |
75
+ | `rulesChange` | `FormRule[]` — emitted on every edit, the mirror of `configChange`. |
72
76
  | `save` | `EntityFormConfig` — emitted when the user saves. |
73
77
 
78
+ ### Rules are stored beside the config, not inside it
79
+
80
+ `EntityFormConfig` has no `rules` property: the renderer takes them as a separate `[rules]`
81
+ input, and so does this component. A host therefore has to save both.
82
+
83
+ `save` carries the config alone, for compatibility. Keep the latest `rulesChange` and write
84
+ it alongside:
85
+
86
+ ```typescript
87
+ import type { EntityFormConfig, FormRule } from '@dynamic-entity/core';
88
+
89
+ declare const api: {
90
+ saveConfig(config: EntityFormConfig): void;
91
+ saveRules(entity: string, rules: FormRule[]): void;
92
+ };
93
+
94
+ let authored: FormRule[] = [];
95
+
96
+ export function onRulesUpdated(rules: FormRule[]): void {
97
+ authored = rules;
98
+ }
99
+
100
+ export function onSave(config: EntityFormConfig): void {
101
+ api.saveConfig(config);
102
+ // Saving the config alone drops every rule the user just authored.
103
+ api.saveRules(config.entity, authored);
104
+ }
105
+ ```
106
+
107
+ Keeping the pair together matters beyond persistence: renaming a field repoints the rules
108
+ that named it, so a host that saved the config from a later edit and the rules from an
109
+ earlier one would write a rule pointing at a field that no longer exists. The undo history
110
+ stores the two together for the same reason.
111
+
74
112
  ---
75
113
 
76
114
  ## ↩️ Undo & redo