formlab-mcp 0.7.15 → 0.7.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.
- package/package.json +1 -1
- package/server.json +2 -2
- package/tools/lab.js +2 -0
- package/vendor/cost.js +65 -17
- package/vendor/fragrance.js +36 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.16",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.16",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.16",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/tools/lab.js
CHANGED
|
@@ -441,6 +441,8 @@ const get_batch = {
|
|
|
441
441
|
stockLedger: (Array.isArray(b.stockLedger) ? b.stockLedger : []).map(e => ({
|
|
442
442
|
date: e.ts || null, delta: e.delta ?? null, unit: e.unit || b.unit || '', kind: e.kind || '', note: e.note || '',
|
|
443
443
|
...(e.customer ? { customer: e.customer } : {}),
|
|
444
|
+
// 29i: a sample piece put back into stock (kind 'return', positive delta), and which sample.
|
|
445
|
+
...(e.kind === 'return' && e.sampleId ? { returnedFromSample: ((samples || []).find(x => x && x.id === e.sampleId) || {}).uid || e.sampleId, ...(e.sampleQty != null ? { sampleQty: e.sampleQty, sampleUnit: e.sampleUnit || '' } : {}) } : {}),
|
|
444
446
|
...(Array.isArray(e.qcOpen) && e.qcOpen.length ? { shippedWithQcOpen: e.qcOpen, qcReason: e.qcReason || null } : {}),
|
|
445
447
|
// 2 Dec: the CoA it went with (null = none issued), and no ingredient lots recorded. Older shipments carry neither.
|
|
446
448
|
// 0.7.12: the saved certificate it went with (its number in certificates).
|
package/vendor/cost.js
CHANGED
|
@@ -194,6 +194,33 @@ function _usedCountUnits() {
|
|
|
194
194
|
.filter(u => { const k = u.toLowerCase(); if (seen.has(k)) return false; seen.add(k); return true; }).slice(0, 30);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
// Unit groups, one place (5 Dec, Jun: "for stock unit, can we put picker choices in groups?"): the unit combobox
|
|
198
|
+
// below and every plain unit <select> (stock, lot, cost "per") file a unit under the same heading.
|
|
199
|
+
const FL_UNIT_GROUPS = [['frac', 'Fraction'], ['mass', 'Mass'], ['vol', 'Volume'], ['len', 'Length'], ['amt', 'Amount / count'], ['other', 'Other']];
|
|
200
|
+
function flUnitGroupOf(u, extraCount) {
|
|
201
|
+
u = String(u || '');
|
|
202
|
+
if (['wt%', 'vol%', '%', 'ppm', 'ppb'].indexOf(u) !== -1) return 'frac';
|
|
203
|
+
if (typeof isMassUnit === 'function' && isMassUnit(u)) return 'mass';
|
|
204
|
+
if (typeof isVolUnit === 'function' && isVolUnit(u)) return 'vol';
|
|
205
|
+
if (typeof isLengthUnit === 'function' && isLengthUnit(u)) return 'len';
|
|
206
|
+
if (['mol', 'eq', 'each', 'pcs', 'unit', 'units'].indexOf(u) !== -1 || (extraCount || []).indexOf(u) !== -1) return 'amt';
|
|
207
|
+
if (typeof FL_COUNT_UNITS_COMMON !== 'undefined' && FL_COUNT_UNITS_COMMON.indexOf(u) !== -1) return 'amt';
|
|
208
|
+
const cu = (typeof db !== 'undefined' && db && db.customUnits && db.customUnits[u]) || null;
|
|
209
|
+
if (cu && cu.dimension === 'count') return 'amt';
|
|
210
|
+
return 'other';
|
|
211
|
+
}
|
|
212
|
+
// <option>s for a unit <select>, in <optgroup>s (Mass, Volume, …). `cur` is selected, and added when the list lacks it
|
|
213
|
+
// (a stock unit of "candle" no longer shows as the list's first unit).
|
|
214
|
+
function flUnitOptionsHtml(units, cur) {
|
|
215
|
+
const e = v => String(v).replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
216
|
+
const list = [...new Set((units || []).map(String))];
|
|
217
|
+
if (cur && !list.includes(cur)) list.push(cur);
|
|
218
|
+
const by = {};
|
|
219
|
+
list.forEach(u => { const k = flUnitGroupOf(u); (by[k] = by[k] || []).push(u); });
|
|
220
|
+
return FL_UNIT_GROUPS.filter(g => by[g[0]]).map(g => `<optgroup label="${e(g[1])}">${by[g[0]].map(u =>
|
|
221
|
+
`<option value="${e(u)}"${u === cur ? ' selected' : ''}>${e(u)}</option>`).join('')}</optgroup>`).join('');
|
|
222
|
+
}
|
|
223
|
+
|
|
197
224
|
// ============================================================
|
|
198
225
|
// Unit combobox — replaces the native <datalist> popup.
|
|
199
226
|
// ------------------------------------------------------------
|
|
@@ -241,15 +268,8 @@ function _usedCountUnits() {
|
|
|
241
268
|
// (Mass / Volume / Length …) and uses the same isMassUnit/isVolUnit helpers
|
|
242
269
|
// so custom units land in the right bucket too.
|
|
243
270
|
var countUnits = []; // the amount-made list's count units, refreshed each time that list opens
|
|
244
|
-
function classify(u) {
|
|
245
|
-
|
|
246
|
-
if (typeof isMassUnit === 'function' && isMassUnit(u)) return 'mass';
|
|
247
|
-
if (typeof isVolUnit === 'function' && isVolUnit(u)) return 'vol';
|
|
248
|
-
if (typeof isLengthUnit === 'function' && isLengthUnit(u)) return 'len';
|
|
249
|
-
if (['mol', 'eq', 'each', 'pcs', 'unit', 'units'].indexOf(u) !== -1 || countUnits.indexOf(u) !== -1) return 'amt';
|
|
250
|
-
return 'other';
|
|
251
|
-
}
|
|
252
|
-
var GROUP_ORDER = [['frac', 'Fraction'], ['mass', 'Mass'], ['vol', 'Volume'], ['len', 'Length'], ['amt', 'Amount / count'], ['other', 'Other']];
|
|
271
|
+
function classify(u) { return flUnitGroupOf(u, countUnits); } // shared with the unit <select>s (5 Dec)
|
|
272
|
+
var GROUP_ORDER = FL_UNIT_GROUPS;
|
|
253
273
|
function groupUnits(units) {
|
|
254
274
|
var by = {};
|
|
255
275
|
units.forEach(function (u) { var k = classify(u); (by[k] = by[k] || []).push(u); });
|
|
@@ -842,6 +862,14 @@ function flIsPieceUnit(u) {
|
|
|
842
862
|
const hit = t => Object.keys(t).some(k => k === raw || k.toLowerCase() === lower);
|
|
843
863
|
return !hit(MASS_TO_KG) && !hit(VOL_TO_L) && !(typeof LENGTH_TO_M !== 'undefined' && hit(LENGTH_TO_M));
|
|
844
864
|
}
|
|
865
|
+
// The word for one piece in "Weight per …" (5 Dec, Jun: "is per piece better or per unit better because piece itself is
|
|
866
|
+
// a unit"): the stock unit when it is one item (jar, wick, candle), else "piece". A pack (box, bag) holds many pieces and
|
|
867
|
+
// "each" / "unit" say nothing, so those read "piece"; so do mass and volume units.
|
|
868
|
+
function flPieceNoun(stockUnit) {
|
|
869
|
+
const u = String(stockUnit || '').trim();
|
|
870
|
+
if (!u || u.length > 24 || ['each', 'piece', 'pieces', 'pc', 'pcs', 'unit', 'units', 'ea'].includes(u.toLowerCase())) return 'piece';
|
|
871
|
+
return flIsPieceUnit(u) ? u : 'piece';
|
|
872
|
+
}
|
|
845
873
|
// A row counted in pieces whose ingredient is marked "Not mixed in" (a wick, a jar: a part per unit, not a share of the
|
|
846
874
|
// mix) sits outside the mix (Jun, 3 Dec): not a share of the whole, not part of the total, the mixed-basis check or the
|
|
847
875
|
// per-kg cost; it goes into the batch as counted, and its price per piece of product. In a wt% or vol% recipe and, since
|
|
@@ -2599,13 +2627,16 @@ function computeBatchCost(batch, displayCcy = getDisplayCurrency()) {
|
|
|
2599
2627
|
const sizeKg = quantityToKg(batch.targetQuantity, batch.unit, f, _umk);
|
|
2600
2628
|
// Parts counted per piece (1 wick per candle) × the pieces the batch makes (3 Dec).
|
|
2601
2629
|
const _isCount = _umk != null && !(batch.unit in MASS_TO_KG) && !(batch.unit in VOL_TO_L);
|
|
2602
|
-
const
|
|
2630
|
+
const _pieces = perKg.countedPerPiece ? flProductUnits(f, sizeKg, _isCount ? batch.targetQuantity : null) : 0;
|
|
2631
|
+
const countedCost = perKg.countedPerPiece ? perKg.countedPerPiece * _pieces : 0;
|
|
2632
|
+
const _money = v => (typeof formatMoney === 'function') ? formatMoney(v, displayCcy) : String(v);
|
|
2603
2633
|
return {
|
|
2604
2634
|
formulation: f,
|
|
2605
2635
|
perKg: perKg.perKg,
|
|
2606
2636
|
sizeKg,
|
|
2607
2637
|
total: sizeKg != null ? perKg.perKg * sizeKg + countedCost : null,
|
|
2608
2638
|
counted: countedCost || null,
|
|
2639
|
+
countedText: countedCost ? flCountedPartsText(perKg, _pieces, countedCost, _money) : null, // "12 × $3,200.00 MacPro Book 2026"
|
|
2609
2640
|
currency: displayCcy,
|
|
2610
2641
|
missing: perKg.missing.concat((perKg.countedUnpriced || []).map(ing => ({ reason: 'no cost on file (counted per piece)', ingredient: ing }))),
|
|
2611
2642
|
};
|
|
@@ -2839,21 +2870,37 @@ function quantityToKg(qty, unit, formula, unitMassKg) {
|
|
|
2839
2870
|
}
|
|
2840
2871
|
|
|
2841
2872
|
// Returns { perKg, kg, computed, ccy, convertible } in the display currency.
|
|
2873
|
+
// The counted parts spelled out (Jun, 5 Dec: "$38,400.00 counted parts" hid 12 × $3,200): "12 × $3,200.00 MacPro
|
|
2874
|
+
// Book 2026". Null when the rows don't add up to the counted cost (a sub-formula's own parts), so callers keep the sum.
|
|
2875
|
+
function flCountedPartsText(cost, pieces, counted, money) {
|
|
2876
|
+
const rows = cost && cost.countedRows;
|
|
2877
|
+
if (!rows || !rows.length || !(pieces > 0) || !(counted > 0)) return null;
|
|
2878
|
+
const items = rows.map(r => {
|
|
2879
|
+
const n = parseFloat(r.row && r.row.amount) || 1;
|
|
2880
|
+
const name = (r.ingredient && r.ingredient.name) || 'part';
|
|
2881
|
+
return { cost: r.perPiece * pieces, text: `${+(n * pieces).toFixed(3)} × ${money(r.perPiece / n)} ${name}` };
|
|
2882
|
+
});
|
|
2883
|
+
const sum = items.reduce((a, x) => a + x.cost, 0);
|
|
2884
|
+
if (!isFinite(sum) || Math.abs(sum - counted) > Math.max(0.01, counted * 1e-6)) return null;
|
|
2885
|
+
return items.length <= 2 ? items.map(x => x.text).join(' + ')
|
|
2886
|
+
: `${items[0].text} + ${items.length - 1} more parts (${money(sum - items[0].cost)})`;
|
|
2887
|
+
}
|
|
2842
2888
|
function quantityCost(qty, unit, formula, displayCcy) {
|
|
2843
2889
|
const ccy = displayCcy ||
|
|
2844
2890
|
(typeof getDisplayCurrency === 'function' ? getDisplayCurrency() : null) ||
|
|
2845
2891
|
(formula && formula.costCurrency) || 'USD';
|
|
2846
|
-
let perKg = null, perPiece = null;
|
|
2892
|
+
let perKg = null, perPiece = null, c = null;
|
|
2847
2893
|
try {
|
|
2848
|
-
|
|
2894
|
+
c = formula && typeof computeFormulationCost === 'function' ? computeFormulationCost(formula, ccy) : null;
|
|
2849
2895
|
if (c && isFinite(c.perKg)) perKg = c.perKg;
|
|
2850
2896
|
if (c && c.countedPerPiece > 0) perPiece = c.countedPerPiece;
|
|
2851
2897
|
} catch (_) { perKg = null; }
|
|
2852
2898
|
const kg = quantityToKg(qty, unit, formula);
|
|
2853
2899
|
// A wick, priced per piece of product (27f: a candle sample read $1.72 without its $0.12 wick).
|
|
2854
|
-
const
|
|
2900
|
+
const pieces = (perPiece != null && kg > 0 && typeof flProductUnits === 'function') ? flProductUnits(formula, kg, null) : 0;
|
|
2901
|
+
const counted = pieces ? perPiece * pieces : 0;
|
|
2855
2902
|
const computed = (perKg != null && kg != null) ? perKg * kg + counted : null;
|
|
2856
|
-
return { perKg, kg, computed, ccy, convertible: kg != null, counted };
|
|
2903
|
+
return { perKg, kg, computed, ccy, convertible: kg != null, counted, pieces, cost: c };
|
|
2857
2904
|
}
|
|
2858
2905
|
|
|
2859
2906
|
// Open the global Display-currency setting — Settings modal → Preferences tab
|
|
@@ -2940,7 +2987,7 @@ function entityCostCellHtml(summary, label) {
|
|
|
2940
2987
|
// o = { kind:'sample'|'batch', id, qty, unit, formula, override }.
|
|
2941
2988
|
function entityCostValueHtml(o) {
|
|
2942
2989
|
if (typeof flCostHidden === 'function' && flCostHidden()) return '<span style="color:var(--dk-faint, #94a3b8)">—</span>'; // 0267: cost hidden from Viewers
|
|
2943
|
-
const { perKg, computed, ccy, convertible, counted } = quantityCost(o.qty, o.unit, o.formula);
|
|
2990
|
+
const { perKg, computed, ccy, convertible, counted, pieces, cost } = quantityCost(o.qty, o.unit, o.formula);
|
|
2944
2991
|
const money = v => (typeof formatMoney === 'function') ? formatMoney(v, ccy) : (ccy + ' ' + (+v).toFixed(2));
|
|
2945
2992
|
const ovRaw = (o.override != null && o.override !== '' && isFinite(parseFloat(o.override))) ? parseFloat(o.override) : null;
|
|
2946
2993
|
// The override was entered in o.overrideCcy (legacy values w/o a stamp are
|
|
@@ -3004,8 +3051,9 @@ function entityCostValueHtml(o) {
|
|
|
3004
3051
|
const col = (why === 'needs-density') ? 'var(--dk-amber-fg, #b45309)' : 'var(--text-muted)';
|
|
3005
3052
|
return `<span style="color:var(--text-muted)">—</span> <span style="font-size:11px;color:${col}">${msg}</span>${editBtn}`;
|
|
3006
3053
|
}
|
|
3007
|
-
|
|
3008
|
-
|
|
3054
|
+
// Its own line under the total (Jun, 5 Dec: the breakdown wrapped beside it, splitting a part's name around Override).
|
|
3055
|
+
const breakdown = `<div class="fl-cost-breakdown" style="font-size:11px;color:var(--text-muted);margin-top:2px">${esc(String(o.qty))} ${esc(o.unit || '')} × ${money(perKg)}/kg${counted > 0 ? ` + ${esc(flCountedPartsText(cost, pieces, counted, money) || money(counted) + ' counted parts')}` : ''}</div>`;
|
|
3056
|
+
return `<strong>${money(computed)}</strong>${editBtn}${breakdown}${ccyLine}`;
|
|
3009
3057
|
}
|
|
3010
3058
|
|
|
3011
3059
|
function openCostOverrideModal(kind, id) {
|
package/vendor/fragrance.js
CHANGED
|
@@ -930,6 +930,38 @@ function _frgDocSelectHtml(id, ing, picked, none) {
|
|
|
930
930
|
: frag.concat(rest).map(opt).join('');
|
|
931
931
|
return `<select id="${id}"${docs.length ? '' : ' disabled'}><option value="">${docs.length ? none : 'No documents yet'}</option>${body}</select>`;
|
|
932
932
|
}
|
|
933
|
+
// Upload right where the certificate is picked (Jun, 5 Dec: "in class details card, when edit, it is unclear how to
|
|
934
|
+
// upload these docs"). The PDF is filed under Documents › Fragrance Compliance and picked here. A new ingredient has
|
|
935
|
+
// nowhere to file it yet: it says to save first.
|
|
936
|
+
// Quiet links beside the picker, as in the other form dialogs (Jun, 5 Dec: "maybe use subtle upload and Read in Class &
|
|
937
|
+
// Details?"): Upload · Read from PDF. The Documents tab keeps its buttons.
|
|
938
|
+
function _frgDocLinksHtml(ing, selId, which) {
|
|
939
|
+
const saved = !!(ing && ing.id && (db.ingredients || []).some(i => i && i.id === ing.id));
|
|
940
|
+
const link = (text, onclick, title, extra) => `<span class="fl-dq-link" role="button" tabindex="0"${extra || ''} onclick="${onclick}" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();this.click();}"${title ? ` title="${title}"` : ''}>${text}</span>`;
|
|
941
|
+
const up = saved ? link('Upload', `_frgUploadDoc('${escJsAttr(ing.id)}', '${selId}')`, 'Upload a PDF to Documents › Fragrance Compliance') : '';
|
|
942
|
+
const read = _frgCanRead() ? link('Read from PDF', `flFrReadDoc('${which}')`, '', ` id="f-fr-read-${which}"`)
|
|
943
|
+
: link('Read from PDF <span class="asm-designer-pro-badge usda-pro">Pro</span>', 'docProUpsell()', '');
|
|
944
|
+
return `<span class="fl-dq fr-doc-links">${up}${up ? '<span class="fl-dq-sep" aria-hidden="true">·</span>' : ''}${read}</span>${saved ? '' : '<span class="fr-dim fr-up-hint">Save the ingredient to upload its PDF here.</span>'}`;
|
|
945
|
+
}
|
|
946
|
+
function _frgUploadDoc(ingId, selId) {
|
|
947
|
+
const input = document.createElement('input');
|
|
948
|
+
input.type = 'file'; input.accept = 'application/pdf';
|
|
949
|
+
input.onchange = async e => {
|
|
950
|
+
const file = e.target.files && e.target.files[0];
|
|
951
|
+
if (!file || typeof docAttach !== 'function') return;
|
|
952
|
+
const res = await docAttach(ingId, 'FRAG', file);
|
|
953
|
+
if (!res || res.error) { if (typeof toast === 'function') toast((res && res.error) || 'Upload failed.', 'error'); return; }
|
|
954
|
+
const ing = (db.ingredients || []).find(i => i && i.id === ingId);
|
|
955
|
+
// Both pickers list the new file; this one takes it. What the other had picked stays.
|
|
956
|
+
['f-fr-cert', 'f-fr-decl'].forEach(id => {
|
|
957
|
+
const sel = document.getElementById(id); if (!sel) return;
|
|
958
|
+
const keep = id === selId ? res.docId : sel.value;
|
|
959
|
+
sel.outerHTML = _frgDocSelectHtml(id, ing, keep, 'Choose\u2026');
|
|
960
|
+
});
|
|
961
|
+
if (typeof toast === 'function') toast(`${file.name} filed under Documents \u203a Fragrance Compliance`);
|
|
962
|
+
};
|
|
963
|
+
input.click();
|
|
964
|
+
}
|
|
933
965
|
// The two blocks inside the ingredient form's Fragrance Details panel.
|
|
934
966
|
function flFrIngFormHtml(ing) {
|
|
935
967
|
const fd = (ing && ing.fragranceDetails) || {};
|
|
@@ -942,8 +974,7 @@ function flFrIngFormHtml(ing) {
|
|
|
942
974
|
<div class="fr-dim fr-from">From the supplier\u2019s IFRA certificate.</div>
|
|
943
975
|
<div class="fr-form-top">
|
|
944
976
|
<label class="fr-f-short">Amendment<input id="f-fr-amend" maxlength="20" placeholder="51st" value="${_frgEsc(fd.ifraAmendment || '')}" /></label>
|
|
945
|
-
<label class="fr-f-doc">Certificate${_frgDocSelectHtml('f-fr-cert', ing, fd.ifraCertDocId, 'Choose\u2026')}</label
|
|
946
|
-
${_frgReadBtnHtml('limits')}
|
|
977
|
+
<label class="fr-f-doc">Certificate${_frgDocSelectHtml('f-fr-cert', ing, fd.ifraCertDocId, 'Choose\u2026')}</label>${_frgDocLinksHtml(ing, 'f-fr-cert', 'limits')}
|
|
947
978
|
</div>
|
|
948
979
|
<div class="fr-row fr-cols"${limits.length ? '' : ' hidden'}><span>Category</span><span>Limit</span><span class="num">Max</span><span></span></div>
|
|
949
980
|
<div id="f-fr-limits">${limits.map(_frgLimitRowHtml).join('')}</div>
|
|
@@ -953,9 +984,8 @@ function flFrIngFormHtml(ing) {
|
|
|
953
984
|
const allergensBody = `<div class="fr-block">
|
|
954
985
|
<div class="fr-dim fr-from">% in this material, from the allergen declaration.</div>
|
|
955
986
|
<div class="fr-form-top">
|
|
956
|
-
<label class="fr-f-doc">Declaration${_frgDocSelectHtml('f-fr-decl', ing, ing && ing.allergenDeclDocId, 'Choose\u2026')}</label
|
|
987
|
+
<label class="fr-f-doc">Declaration${_frgDocSelectHtml('f-fr-decl', ing, ing && ing.allergenDeclDocId, 'Choose\u2026')}</label>${_frgDocLinksHtml(ing, 'f-fr-decl', 'allergens')}
|
|
957
988
|
<label class="fr-check"><input type="checkbox" id="f-fr-none"${declared && !al.length ? ' checked' : ''} onchange="_frgNoneTicked(this)" /> Declares none</label>
|
|
958
|
-
${_frgReadBtnHtml('allergens')}
|
|
959
989
|
</div>
|
|
960
990
|
${auto ? '<div class="fr-dim" data-fr-auto>On the EU list by its CAS: counted as 100% of itself. Add rows only to say otherwise.</div>' : ''}
|
|
961
991
|
<div class="fr-row fr-cols"${al.length ? '' : ' hidden'}><span>Allergen</span><span>CAS</span><span class="num">In material</span><span></span></div>
|
|
@@ -992,10 +1022,6 @@ function _frgAllergensHint(n, total, none, decl, auto) {
|
|
|
992
1022
|
// left unsaved: the form is the review step, and Save is the person's own. Nothing is read without a document picked,
|
|
993
1023
|
// so every row that arrives already has its source. A row already in the form is never replaced.
|
|
994
1024
|
const _frgCanRead = () => typeof hasFeature !== 'function' || hasFeature('docs.extract');
|
|
995
|
-
function _frgReadBtnHtml(which) {
|
|
996
|
-
if (!_frgCanRead()) return `<button type="button" class="btn btn-secondary btn-sm fr-read" onclick="docProUpsell()">Read from PDF <span class="asm-designer-pro-badge usda-pro">Pro</span></button>`;
|
|
997
|
-
return `<button type="button" class="btn btn-secondary btn-sm fr-read" id="f-fr-read-${which}" onclick="flFrReadDoc('${which}')">Read from PDF</button>`;
|
|
998
|
-
}
|
|
999
1025
|
function _frgReadPrompt(which, ing) {
|
|
1000
1026
|
const name = _frgName(ing);
|
|
1001
1027
|
if (which === 'limits') return [
|
|
@@ -1065,11 +1091,11 @@ async function flFrReadDoc(which) {
|
|
|
1065
1091
|
if (!ap) return;
|
|
1066
1092
|
const btn = document.getElementById('f-fr-read-' + which);
|
|
1067
1093
|
_frgReading = true;
|
|
1068
|
-
if (btn) { btn.disabled = true; btn.textContent = 'Reading…'; }
|
|
1094
|
+
if (btn) { btn.disabled = true; btn.setAttribute('aria-disabled', 'true'); btn.textContent = 'Reading…'; }
|
|
1069
1095
|
let raw;
|
|
1070
1096
|
try { raw = ap.provider === 'mock' ? _frgReadMock(which) : await _runPdfExtract(ap.provider, ap.key, _frgReadPrompt(which, ing), doc); }
|
|
1071
1097
|
catch (e) { say('Could not read the document: ' + ((e && e.message) || e)); return; }
|
|
1072
|
-
finally { _frgReading = false; const b = document.getElementById('f-fr-read-' + which); if (b) { b.disabled = false; b.textContent = 'Read from PDF'; } }
|
|
1098
|
+
finally { _frgReading = false; const b = document.getElementById('f-fr-read-' + which); if (b) { b.disabled = false; b.removeAttribute('aria-disabled'); b.textContent = 'Read from PDF'; } }
|
|
1073
1099
|
// The form may have closed, or another document been picked, while the call was out.
|
|
1074
1100
|
const list = document.getElementById(which === 'limits' ? 'f-fr-limits' : 'f-fr-allergens'), sel2 = document.getElementById(which === 'limits' ? 'f-fr-cert' : 'f-fr-decl');
|
|
1075
1101
|
if (!list || !sel2 || sel2.value !== doc.id) return;
|