cncjs-conversational 0.2.0 → 0.2.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/web/index.html +12 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cncjs-conversational",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Conversational programming CNCjs custom widget: face, side face, square up, pockets and bolt circles laid out as a dimensioned sketch.",
5
5
  "keywords": [
6
6
  "cncjs",
package/web/index.html CHANGED
@@ -1080,7 +1080,15 @@ const embedding = window.parent === window || !token ? 'standalone' : sameOrigin
1080
1080
  const cnc = { token, port: null, load: { state: 'idle', message: '', program: '' } };
1081
1081
  const programName = () => `${st.op}${st.op === 'square' ? `-setup${st.sq.setup}` : st.op === 'side' ? `-${st.side.side}` : ''}.nc`;
1082
1082
  const programText = () => current.length ? current.join('\n') + '\n' : '';
1083
- const setLoad = (state, message = '', program = '') => { cnc.load = { state, message, program }; updateLoad(); };
1083
+ const setLoad = (state, message = '', program = '') => {
1084
+ // An outcome that arrives after the operator edited the program is still shown once,
1085
+ // marked as describing the earlier version; the next edit clears it.
1086
+ const edited = state !== 'loading' && program !== programText();
1087
+ cnc.load = edited
1088
+ ? { state, message: `${message} (This was the program before your last edit.)`, program: programText() }
1089
+ : { state, message, program };
1090
+ updateLoad();
1091
+ };
1084
1092
 
1085
1093
  function updateLoad() {
1086
1094
  const load = document.getElementById('load'), note = document.getElementById('cnc-note');
@@ -1114,7 +1122,9 @@ async function loadIntoCncjs() {
1114
1122
  try {
1115
1123
  // gcode:load stops CNCjs's workflow, so only load when nothing is running or paused,
1116
1124
  // the same rule CNCjs's own Upload button follows.
1117
- const workflow = (await cncjsApi('/api/controllers')).find(c => c.port === port)?.workflow?.state;
1125
+ const controllers = await cncjsApi('/api/controllers');
1126
+ if (!Array.isArray(controllers)) return setLoad('failed', 'Not loaded: CNCjs did not report its controllers.', program);
1127
+ const workflow = controllers.find(c => c.port === port)?.workflow?.state;
1118
1128
  if (!workflow) return setLoad('failed', `Not loaded: ${port} is not open in CNCjs.`, program);
1119
1129
  if (workflow !== 'idle') return setLoad('refused', `Not loaded: a program is ${workflow} on ${port}. Stop it in CNCjs first.`, program);
1120
1130
  await cncjsApi('/api/gcode', { method: 'POST', body: JSON.stringify({ port, name, gcode: program }) });