pict-section-form 1.3.15 → 1.3.16

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 (47) hide show
  1. package/docs/Providers.md +12 -7
  2. package/docs/_sidebar.md +2 -0
  3. package/docs/input_providers/016-facet-filter.md +106 -0
  4. package/docs/input_providers/README.md +1 -0
  5. package/example_applications/README.md +6 -0
  6. package/example_applications/facet_filter/.quackage.json +9 -0
  7. package/example_applications/facet_filter/Facet-Filter-Application.js +210 -0
  8. package/example_applications/facet_filter/Facet-Filter-Server.js +233 -0
  9. package/example_applications/facet_filter/Facet-Filter-Smoke-Runner.js +101 -0
  10. package/example_applications/facet_filter/FacetFilterData.json +44 -0
  11. package/example_applications/facet_filter/README-FacetFilter.md +70 -0
  12. package/example_applications/facet_filter/html/Facet-Filter-Smoke.js +128 -0
  13. package/example_applications/facet_filter/html/index.html +74 -0
  14. package/example_applications/facet_filter/package.json +27 -0
  15. package/example_applications/nested_distill_sandbox/Sandbox-Driver-Headlight.js +17 -0
  16. package/example_applications/nested_distill_sandbox/Sandbox-Driver.js +369 -0
  17. package/example_applications/nested_distill_sandbox/Sandbox-Runner.js +372 -0
  18. package/example_applications/nested_distill_sandbox/approaches/A1-tabular-trigger-group.js +67 -0
  19. package/example_applications/nested_distill_sandbox/approaches/A3-crossmap-selectoptionsrefresh.js +61 -0
  20. package/example_applications/nested_distill_sandbox/approaches/A4-graph-solvers-flat-list.js +53 -0
  21. package/example_applications/nested_distill_sandbox/approaches/A5-facet-filter.js +75 -0
  22. package/example_applications/nested_distill_sandbox/approaches/A5b-facet-filter-symmetric.js +15 -0
  23. package/example_applications/nested_distill_sandbox/approaches/A5h-facet-filter-headlight-picker.js +15 -0
  24. package/example_applications/nested_distill_sandbox/approaches/R0-original-jmf-manifest-headlight.js +27 -0
  25. package/example_applications/nested_distill_sandbox/approaches/R1-real-jmf-manifest-headlight.js +136 -0
  26. package/example_applications/nested_distill_sandbox/approaches/_Common.js +344 -0
  27. package/example_applications/nested_distill_sandbox/approaches/_Scenarios.js +262 -0
  28. package/package.json +1 -1
  29. package/source/providers/Pict-Provider-DynamicSolver.js +2 -0
  30. package/source/providers/Pict-Provider-ListDistilling.js +266 -1
  31. package/source/providers/Pict-Provider-MetaLists.js +16 -2
  32. package/source/providers/inputs/Pict-Provider-Input-FacetFilter.js +232 -0
  33. package/source/providers/inputs/Pict-Provider-Input-Select.js +41 -1
  34. package/source/views/Pict-View-Form-Metacontroller.js +5 -3
  35. package/test/Pict-Provider-ListDistilling-Facet_tests.js +375 -0
  36. package/test/PictSectionForm-Injection-Conformance_tests.js +11 -0
  37. package/test/fixtures/injection/Injection-Fixture-Cases.js +1 -0
  38. package/test/fixtures/injection/Injection-Fixture-Manifest.json +15 -0
  39. package/types/source/providers/Pict-Provider-DynamicSolver.d.ts.map +1 -1
  40. package/types/source/providers/Pict-Provider-ListDistilling.d.ts +90 -1
  41. package/types/source/providers/Pict-Provider-ListDistilling.d.ts.map +1 -1
  42. package/types/source/providers/Pict-Provider-MetaLists.d.ts.map +1 -1
  43. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts +103 -0
  44. package/types/source/providers/inputs/Pict-Provider-Input-FacetFilter.d.ts.map +1 -0
  45. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts +12 -0
  46. package/types/source/providers/inputs/Pict-Provider-Input-Select.d.ts.map +1 -1
  47. package/types/source/views/Pict-View-Form-Metacontroller.d.ts.map +1 -1
@@ -0,0 +1,232 @@
1
+ const libPictSectionInputExtension = require('../Pict-Provider-InputExtension.js');
2
+
3
+ /**
4
+ * FacetFilter input provider.
5
+ *
6
+ * Keeps a set of inputs that choose from one shared join list (their `Facet` ListFilterRules name the same
7
+ * `JoinListAddress`) mutually consistent when one of them changes. In a tabular group the set is the
8
+ * facet inputs in the changed row only; outside a table it is the facet inputs in the same view.
9
+ *
10
+ * On a change it runs, before the form solves:
11
+ * 1. ClearInvalid (default true): walking the siblings in column order, a sibling whose value no longer
12
+ * appears in any join record agreeing with the changed value (and the siblings already kept) is cleared.
13
+ * 2. AutoFillSingle (default true): an empty sibling left with exactly one allowed value takes it, repeated
14
+ * until nothing changes. The changed input itself is never filled, so clearing it sticks.
15
+ * 3. CarryFields ({ "<row address>": "<join record address>" }): on a sibling that holds a value, the join
16
+ * record its facet set now identifies (exactly one agreeing record) is copied into the row; with no value,
17
+ * or no single record, those row fields are cleared.
18
+ *
19
+ * It only acts on a user change, never on load or marshal, so a saved value -- carried fields included -- is
20
+ * never rewritten by opening a document or by the join list changing later. Narrowing the offered options
21
+ * is the `Facet` rule's job in ListDistilling.filterList.
22
+ *
23
+ * ListFilterRules: [ { FilterType: "Facet", JoinListAddress: "AppData.Graph", JoinListAddressGlobal: true, JoinListValueAddress: "Colour" } ],
24
+ * Providers: [ "Pict-Input-FacetFilter" ]
25
+ *
26
+ * @class
27
+ * @extends libPictSectionInputExtension
28
+ * @memberof providers.inputs
29
+ */
30
+ class FacetFilterInputHandler extends libPictSectionInputExtension
31
+ {
32
+ /**
33
+ * @param {import('fable')} pFable - The Fable instance.
34
+ * @param {Record<string, any>} [pOptions] - The options for the provider.
35
+ * @param {string} [pServiceHash] - The service hash for the provider.
36
+ */
37
+ constructor(pFable, pOptions, pServiceHash)
38
+ {
39
+ super(pFable, pOptions, pServiceHash);
40
+
41
+ /** @type {import('pict')} */
42
+ this.pict;
43
+ /** @type {any} */
44
+ this.log;
45
+
46
+ // Writing a sibling runs that sibling's change providers (this one included); only the user's change reconciles.
47
+ this.reconciling = false;
48
+ }
49
+
50
+ /**
51
+ * @param {Object} pView
52
+ * @param {Record<string, any>} pInput
53
+ * @param {number|undefined} pRowIndex - undefined outside a table
54
+ * @param {any} pValue
55
+ */
56
+ setFacetValue(pView, pInput, pRowIndex, pValue)
57
+ {
58
+ if ((typeof(pRowIndex) === 'number') || ((typeof(pRowIndex) === 'string') && (pRowIndex !== '')))
59
+ {
60
+ pView.setDataTabularByHash(pInput.PictForm.GroupIndex, pInput.Hash, pRowIndex, pValue);
61
+ return;
62
+ }
63
+ pView.setDataByInput(pInput, pValue);
64
+ }
65
+
66
+ /**
67
+ * Reconciles the changed input's facet siblings; see the class description.
68
+ *
69
+ * @param {Object} pView
70
+ * @param {Record<string, any>} pInput - the input the user changed
71
+ * @param {number} [pRowIndex]
72
+ * @return {Array<string>} hashes of the siblings whose value was changed
73
+ */
74
+ reconcileFacets(pView, pInput, pRowIndex)
75
+ {
76
+ if (this.reconciling)
77
+ {
78
+ return [];
79
+ }
80
+ this.reconciling = true;
81
+ try
82
+ {
83
+ return this.reconcileFacetSiblings(pView, pInput, pRowIndex);
84
+ }
85
+ finally
86
+ {
87
+ this.reconciling = false;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * @param {Object} pView
93
+ * @param {Record<string, any>} pInput - the input the user changed
94
+ * @param {number} [pRowIndex]
95
+ * @return {Array<string>} hashes of the siblings whose value was changed
96
+ */
97
+ reconcileFacetSiblings(pView, pInput, pRowIndex)
98
+ {
99
+ const tmpDistilling = this.pict.providers.ListDistilling;
100
+ const tmpSiblings = tmpDistilling.getFacetSiblings(pView, pInput, pRowIndex);
101
+ const tmpChanged = [];
102
+ if (tmpSiblings.length < 2)
103
+ {
104
+ return tmpChanged;
105
+ }
106
+
107
+ const tmpKept = tmpSiblings.map((pSibling) => (pSibling.Input === pInput));
108
+ for (let i = 0; i < tmpSiblings.length; i++)
109
+ {
110
+ const tmpSibling = tmpSiblings[i];
111
+ if (tmpKept[i] || tmpDistilling.isEmptyFacetValue(tmpSibling.Value))
112
+ {
113
+ tmpKept[i] = true;
114
+ continue;
115
+ }
116
+ const tmpConstraining = tmpSiblings.map((pOther, pIndex) => ({ Input: pOther.Input, Rule: pOther.Rule, Value: tmpKept[pIndex] ? pOther.Value : '' }));
117
+ const tmpAllowed = tmpDistilling.getFacetAllowedValues(pView, tmpSibling.Input, tmpSibling.Rule, pRowIndex, tmpConstraining);
118
+ if (tmpAllowed.has(String(tmpSibling.Value)) || (tmpSibling.Rule.ClearInvalid === false))
119
+ {
120
+ tmpKept[i] = true;
121
+ continue;
122
+ }
123
+ tmpSibling.Value = '';
124
+ this.setFacetValue(pView, tmpSibling.Input, pRowIndex, '');
125
+ tmpChanged.push(tmpSibling.Input.Hash);
126
+ tmpKept[i] = true;
127
+ }
128
+
129
+ for (let tmpPass = 0; tmpPass < tmpSiblings.length; tmpPass++)
130
+ {
131
+ let tmpFilled = false;
132
+ for (const tmpSibling of tmpSiblings)
133
+ {
134
+ if ((tmpSibling.Input === pInput) || !tmpDistilling.isEmptyFacetValue(tmpSibling.Value) || (tmpSibling.Rule.AutoFillSingle === false))
135
+ {
136
+ continue;
137
+ }
138
+ const tmpAllowed = tmpDistilling.getFacetAllowedValues(pView, tmpSibling.Input, tmpSibling.Rule, pRowIndex, tmpSiblings);
139
+ if (tmpAllowed.size === 1)
140
+ {
141
+ tmpSibling.Value = tmpAllowed.values().next().value;
142
+ this.setFacetValue(pView, tmpSibling.Input, pRowIndex, tmpSibling.Value);
143
+ tmpChanged.push(tmpSibling.Input.Hash);
144
+ tmpFilled = true;
145
+ }
146
+ }
147
+ if (!tmpFilled)
148
+ {
149
+ break;
150
+ }
151
+ }
152
+
153
+ for (const tmpSibling of tmpSiblings)
154
+ {
155
+ if (tmpSibling.Rule.CarryFields && (typeof(tmpSibling.Rule.CarryFields) === 'object'))
156
+ {
157
+ this.carryFields(pView, tmpSibling, pRowIndex, tmpSiblings);
158
+ }
159
+ }
160
+ return tmpChanged;
161
+ }
162
+
163
+ /**
164
+ * Copies a sibling's CarryFields from the one join record its facet set identifies, or clears them.
165
+ *
166
+ * @param {Object} pView
167
+ * @param {{ Input: Record<string, any>, Rule: Record<string, any>, Value: any }} pSibling
168
+ * @param {number|undefined} pRowIndex
169
+ * @param {Array<{ Input: Record<string, any>, Rule: Record<string, any>, Value: any }>} pSiblings
170
+ */
171
+ carryFields(pView, pSibling, pRowIndex, pSiblings)
172
+ {
173
+ const tmpDistilling = this.pict.providers.ListDistilling;
174
+ let tmpRecord = null;
175
+ if (!tmpDistilling.isEmptyFacetValue(pSibling.Value))
176
+ {
177
+ const tmpMatches = tmpDistilling.getFacetMatchingRecords(pView, pSibling.Input, pSibling.Rule, pRowIndex, pSiblings)
178
+ .filter((pJoinRecord) => String(this.pict.manifest.getValueAtAddress(pJoinRecord, pSibling.Rule.JoinListValueAddress)) === String(pSibling.Value));
179
+ tmpRecord = (tmpMatches.length === 1) ? tmpMatches[0] : null;
180
+ }
181
+ const tmpIsTabular = (typeof(pRowIndex) === 'number') || ((typeof(pRowIndex) === 'string') && (pRowIndex !== ''));
182
+ const tmpTarget = tmpIsTabular ? pView.getTabularRecordData(pSibling.Input.PictForm.GroupIndex, pRowIndex) : pView.getMarshalDestinationObject();
183
+ if (!tmpTarget)
184
+ {
185
+ return;
186
+ }
187
+ for (const tmpRowAddress of Object.keys(pSibling.Rule.CarryFields))
188
+ {
189
+ const tmpValue = tmpRecord ? this.pict.manifest.getValueAtAddress(tmpRecord, pSibling.Rule.CarryFields[tmpRowAddress]) : '';
190
+ this.pict.manifest.setValueAtAddress(tmpTarget, tmpRowAddress, (tmpValue === undefined) ? '' : tmpValue);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * @param {Object} pView - The view object.
196
+ * @param {Object} pInput - The input object.
197
+ * @param {any} pValue - The new value.
198
+ * @param {string} pHTMLSelector - The HTML selector.
199
+ * @param {string} pTransactionGUID - The transaction GUID, if any.
200
+ * @returns {any}
201
+ */
202
+ onDataChange(pView, pInput, pValue, pHTMLSelector, pTransactionGUID)
203
+ {
204
+ this.reconcileFacets(pView, pInput);
205
+ return super.onDataChange(pView, pInput, pValue, pHTMLSelector, pTransactionGUID);
206
+ }
207
+
208
+ /**
209
+ * @param {Object} pView - The view object.
210
+ * @param {Object} pInput - The input object.
211
+ * @param {any} pValue - The new value.
212
+ * @param {string} pHTMLSelector - The HTML selector.
213
+ * @param {number} pRowIndex - The index of the row.
214
+ * @param {string} pTransactionGUID - The transaction GUID, if any.
215
+ * @returns {any}
216
+ */
217
+ onDataChangeTabular(pView, pInput, pValue, pHTMLSelector, pRowIndex, pTransactionGUID)
218
+ {
219
+ this.reconcileFacets(pView, pInput, pRowIndex);
220
+ return super.onDataChangeTabular(pView, pInput, pValue, pHTMLSelector, pRowIndex, pTransactionGUID);
221
+ }
222
+ }
223
+
224
+ module.exports = FacetFilterInputHandler;
225
+
226
+ module.exports.default_configuration = (
227
+ {
228
+ "ProviderIdentifier": "Pict-Input-FacetFilter",
229
+ "AutoInitialize": true,
230
+ "AutoInitializeOrdinal": 0,
231
+ "AutoSolveWithApp": false
232
+ });
@@ -61,6 +61,29 @@ class CustomInputHandler extends libPictSectionInputExtension
61
61
  return `#SELECT-TABULAR-DROPDOWN-${pInputHTMLID}-${pRowIndex}`;
62
62
  }
63
63
 
64
+ /**
65
+ * Records the option ids on the element and reports whether they differ from what it last rendered,
66
+ * so a refresh on every marshal does not rebuild (and blur) a dropdown whose options are unchanged.
67
+ *
68
+ * @param {HTMLElement} pSelectElement
69
+ * @param {Array<{ id: string, text: string }>} pListData
70
+ * @return {boolean}
71
+ */
72
+ optionsChanged(pSelectElement, pListData)
73
+ {
74
+ if (!pSelectElement || !pSelectElement.setAttribute)
75
+ {
76
+ return true;
77
+ }
78
+ const tmpSignature = Array.isArray(pListData) ? pListData.map((pEntry) => `${pEntry.id}\u0001${pEntry.text}`).join('\u0002') : '';
79
+ if (pSelectElement.getAttribute('data-pict-options') === tmpSignature)
80
+ {
81
+ return false;
82
+ }
83
+ pSelectElement.setAttribute('data-pict-options', tmpSignature);
84
+ return true;
85
+ }
86
+
64
87
  /**
65
88
  * Refreshes the select list for a dynamic input.
66
89
  * @param {Object} pView - The view object.
@@ -91,6 +114,10 @@ class CustomInputHandler extends libPictSectionInputExtension
91
114
  tmpListData = this.pict.providers.ListDistilling.filterList(pView, pInput, tmpListData);
92
115
 
93
116
  tmpInputSelectElement = tmpInputSelectElement[0];
117
+ if (!this.optionsChanged(tmpInputSelectElement, tmpListData))
118
+ {
119
+ return;
120
+ }
94
121
  // HAX
95
122
  tmpInputSelectElement.innerHTML = '';
96
123
 
@@ -128,7 +155,7 @@ class CustomInputHandler extends libPictSectionInputExtension
128
155
  tmpListData = this.pict.providers.DynamicMetaLists.getList(pInput.PictForm.SelectOptionsPickList);
129
156
  }
130
157
 
131
- tmpListData = this.pict.providers.ListDistilling.filterList(pView, pInput, tmpListData);
158
+ tmpListData = this.pict.providers.ListDistilling.filterList(pView, pInput, tmpListData, pRowIndex);
132
159
 
133
160
  // TODO: Determine later if this should ever be an array.
134
161
  if (!Array.isArray(tmpInputSelectElement) || tmpInputSelectElement.length < 1)
@@ -138,6 +165,11 @@ class CustomInputHandler extends libPictSectionInputExtension
138
165
 
139
166
  tmpInputSelectElement = tmpInputSelectElement[0];
140
167
 
168
+ if (!this.optionsChanged(tmpInputSelectElement, tmpListData))
169
+ {
170
+ return;
171
+ }
172
+
141
173
  // HAX
142
174
  tmpInputSelectElement.innerHTML = '';
143
175
 
@@ -234,6 +266,10 @@ class CustomInputHandler extends libPictSectionInputExtension
234
266
  */
235
267
  onDataMarshalToForm(pView, pGroup, pRow, pInput, pValue, pHTMLSelector, pTransactionGUID)
236
268
  {
269
+ if (this.pict.providers.ListDistilling.getFacetRule(pInput))
270
+ {
271
+ this.refreshSelectList(pView, pGroup, pRow, pInput, pValue, pHTMLSelector);
272
+ }
237
273
  /** @type {Array<HTMLElement>|HTMLElement} */
238
274
  const tmpInputSelectElements = this.pict.ContentAssignment.getElement(this.getSelectInputHTMLID(pInput.Macro.RawHTMLID));
239
275
  if (!tmpInputSelectElements || tmpInputSelectElements.length < 1)
@@ -281,6 +317,10 @@ class CustomInputHandler extends libPictSectionInputExtension
281
317
  */
282
318
  onDataMarshalToFormTabular(pView, pGroup, pInput, pValue, pHTMLSelector, pRowIndex, pTransactionGUID)
283
319
  {
320
+ if (this.pict.providers.ListDistilling.getFacetRule(pInput))
321
+ {
322
+ this.refreshSelectListTabular(pView, pGroup, null, pInput, pValue, pHTMLSelector, pRowIndex);
323
+ }
284
324
  /** @type {Array<HTMLElement>|HTMLElement} */
285
325
  const tmpInputSelectElements = this.pict.ContentAssignment.getElement(this.getTabularSelectDropdownID(pInput.Macro.RawHTMLID, pRowIndex));
286
326
  if (!tmpInputSelectElements || tmpInputSelectElements.length < 1)
@@ -138,10 +138,12 @@ class PictFormMetacontroller extends libPictViewClass
138
138
 
139
139
  gatherInitialBundle(fCallback)
140
140
  {
141
- if (this.manifestDescription && this.manifestDescription.InitialBundle)
141
+ // Runs before bootstrap has set manifestDescription, so fall back to the manifest bootstrap will use.
142
+ const tmpManifestDescription = this.manifestDescription || this.fable.settings.DefaultFormManifest;
143
+ if (tmpManifestDescription && Array.isArray(tmpManifestDescription.InitialBundle))
142
144
  {
143
- this.log.info(`Gathering initial bundle for ${this.manifestDescription.InitialBundle.length} entities.`);
144
- return this.pict.EntityProvider.gatherDataFromServer(this.manifestDescription.InitialBundle, (pError) =>
145
+ this.log.info(`Gathering initial bundle for ${tmpManifestDescription.InitialBundle.length} entities.`);
146
+ return this.pict.EntityProvider.gatherDataFromServer(tmpManifestDescription.InitialBundle, (pError) =>
145
147
  {
146
148
  // in case of an empty array, or all tasks being synchronous, wait for the next tick so we don't get event ordering problems
147
149
  setTimeout(() => fCallback(pError), 0);