dsh-open-desktop 0.6.0 → 0.6.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.
package/README.md CHANGED
@@ -56,7 +56,7 @@ $DSH_HOME/open-desktop/
56
56
  ```bash
57
57
  npm install
58
58
  npm run build # src/client/ → client.js(esbuild,react 由宿主注入)
59
- npm test # 217 条测试
59
+ npm test # 218 条测试
60
60
  npm run harness # 可选:普通浏览器里的拖拽验证台
61
61
  ```
62
62
 
package/client.js CHANGED
@@ -5325,7 +5325,7 @@ window.__ModuleLoader__.load({
5325
5325
  const csp = "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'";
5326
5326
  const runtime = `(function(){
5327
5327
  function applyTokens(tokens){if(!tokens)return;var root=document.documentElement;for(var key in tokens){root.style.setProperty("--od-"+key,tokens[key])}}
5328
- window.dshWidget={data:null,tokens:{},size:{w:0,h:0},save:function(value){parent.postMessage({__od:true,type:"save",value:value},"*")},fetch:function(url,init){var id="f"+Math.random().toString(36).slice(2);return new Promise(function(resolve,reject){function onMessage(event){var message=event.data||{};if(message.__od!==true||message.type!=="fetch-result"||message.id!==id)return;window.removeEventListener("message",onMessage);if(message.ok)resolve(message.value);else reject(new Error(message.error||"fetch failed"))}window.addEventListener("message",onMessage);parent.postMessage({__od:true,type:"fetch",id:id,url:String(url),init:init||null},"*")})}};
5328
+ window.dshWidget={data:null,tokens:{},size:{w:0,h:0},save:function(value,options){parent.postMessage({__od:true,type:"save",value:value,options:options||null},"*")},fetch:function(url,init){var id="f"+Math.random().toString(36).slice(2);return new Promise(function(resolve,reject){function onMessage(event){var message=event.data||{};if(message.__od!==true||message.type!=="fetch-result"||message.id!==id)return;window.removeEventListener("message",onMessage);if(message.ok)resolve(message.value);else reject(new Error(message.error||"fetch failed"))}window.addEventListener("message",onMessage);parent.postMessage({__od:true,type:"fetch",id:id,url:String(url),init:init||null},"*")})}};
5329
5329
  function report(){try{var d=document.documentElement;var b=document.body;var sh=Math.max(d?d.scrollHeight:0,b?b.scrollHeight:0);var ch=window.innerHeight||(d?d.clientHeight:0);parent.postMessage({__od:true,type:"overflow",scrollHeight:sh,clientHeight:ch},"*")}catch(error){}}
5330
5330
  window.addEventListener("message",function(event){var message=event.data||{};if(message.__od!==true)return;if(message.type==="hello"){parent.postMessage({__od:true,type:"ready"},"*");return}if(message.type==="tokens"){window.dshWidget.tokens=message.tokens||{};applyTokens(message.tokens);return}if(message.type==="data"){if(message.tokens)applyTokens(message.tokens);if(message.size)window.dshWidget.size=message.size;window.dshWidget.data=message.value;if(typeof window.dshWidget.onData==="function")window.dshWidget.onData(message.value);report()}});
5331
5331
  document.addEventListener("click",function(event){var target=event.target;var link=target&&target.closest?target.closest("a[href]"):null;if(!link)return;var href=link.getAttribute("href")||"";if(!/^https?:\\/\\//i.test(href))return;event.preventDefault();parent.postMessage({__od:true,type:"open",url:href},"*")},true);
@@ -5419,7 +5419,7 @@ window.__ModuleLoader__.load({
5419
5419
  return;
5420
5420
  }
5421
5421
  if (message.type === "save") {
5422
- if (typeof props.onSave === "function") props.onSave(message.value);
5422
+ if (typeof props.onSave === "function") props.onSave(message.value, message.options || null);
5423
5423
  return;
5424
5424
  }
5425
5425
  if (message.type === "fetch") {
@@ -5655,8 +5655,8 @@ window.__ModuleLoader__.load({
5655
5655
  onGrow: function(item) {
5656
5656
  props.onGrow?.(item);
5657
5657
  },
5658
- onSave: function(value) {
5659
- props.onSave?.(widget.id, value);
5658
+ onSave: function(value, options) {
5659
+ props.onSave?.(widget.id, value, options);
5660
5660
  }
5661
5661
  });
5662
5662
  }
@@ -7713,8 +7713,12 @@ window.__ModuleLoader__.load({
7713
7713
  });
7714
7714
  },
7715
7715
  onMove: moveWidget,
7716
- onSave: function(id, value) {
7717
- run("card-data", { id, value }).catch(function() {
7716
+ onSave: function(id, value, options) {
7717
+ run("card-data", {
7718
+ id,
7719
+ value,
7720
+ refetch: !!(options && options.refresh === true)
7721
+ }).catch(function() {
7718
7722
  });
7719
7723
  }
7720
7724
  })
package/host/board.js CHANGED
@@ -146,7 +146,7 @@ export function createBoard({ ctx, paths, cards, refresh, sessions }) {
146
146
  // 交互状态:卡片 view 通过 dshWidget.save(value) 写回自己的 data/state.json。
147
147
  // 语义是「浅合并」而不是覆盖:同一张卡可能同时存时间窗、选中项、勾选状态,
148
148
  // 各自 save 自己那几个键,不能互相抹掉。只允许落在这张卡片的 data/ 下。
149
- const writeData = async ({ id, value } = {}) => {
149
+ const writeData = async ({ id, value, refetch } = {}) => {
150
150
  const card = requireCard(id)
151
151
  const dir = join(paths.cardDir(card.id), 'data')
152
152
  const file = join(dir, 'state.json')
@@ -171,9 +171,13 @@ export function createBoard({ ctx, paths, cards, refresh, sessions }) {
171
171
  const temp = file + '.tmp'
172
172
  await writeFile(temp, text, 'utf8')
173
173
  await rename(temp, file)
174
- // 不在这里重新取数:卡片自己刚改完状态,本地已经是新的;
175
- // 再触发一次网络刷新只会让点击变慢,还可能用旧快照覆盖视图。
174
+ // 默认不重新取数:卡片自己刚改完状态,本地已经是新的;
175
+ // 再跑一遍采集只会让点击变慢,还可能用旧快照覆盖视图。
176
+ // 但「改了自选股/订阅列表」这类改动,数据本身要重取,view 传 refetch 才跑。
176
177
  publish()
178
+ if (refetch === true) {
179
+ refreshNow({ id: card.id }).catch(() => { /* 失败会走卡片自己的陈旧态 */ })
180
+ }
177
181
  return { written: true, bytes }
178
182
  }
179
183
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-open-desktop",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "把 DSH 的中栏变成可拖拽的数据卡片墙:每张卡片是一条真实会话,用 view/ 里的前端代码渲染,自带刷新节奏。",
6
6
  "keywords": [