@gramlot/gramlot 0.3.27 → 0.3.31

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 (208) hide show
  1. package/assets/icons/chart.svg +1 -0
  2. package/dist/components/audio/__init__.py +13 -0
  3. package/dist/components/audio/assets/collection.js +3 -0
  4. package/dist/components/audio/assets/index.js +3 -0
  5. package/dist/components/audio/commands.json +7 -0
  6. package/dist/components/audio/grammar.json +335 -0
  7. package/dist/components/charts/__init__.py +13 -0
  8. package/dist/components/charts/assets/collection.js +47 -0
  9. package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
  10. package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
  11. package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
  12. package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
  13. package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
  14. package/dist/components/charts/assets/index.js +3 -0
  15. package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
  16. package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
  17. package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
  18. package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
  19. package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
  20. package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
  21. package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
  22. package/dist/components/charts/commands.json +7 -0
  23. package/dist/components/charts/grammar.json +1113 -0
  24. package/dist/components/chat/__init__.py +1 -1
  25. package/dist/components/chat/assets/collection.js +3 -3
  26. package/dist/components/chat/assets/index.js +1 -1
  27. package/dist/components/drawing/__init__.py +15 -0
  28. package/dist/components/drawing/assets/collection.js +28 -0
  29. package/dist/components/drawing/assets/index.js +3 -0
  30. package/dist/components/drawing/commands.json +7 -0
  31. package/dist/components/drawing/grammar.json +110 -0
  32. package/dist/components/editors/__init__.py +2 -2
  33. package/dist/components/editors/assets/collection.js +18 -18
  34. package/dist/components/editors/assets/index.js +1 -1
  35. package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
  36. package/dist/components/editors/grammar.json +150 -0
  37. package/dist/components/grid/__init__.py +2 -2
  38. package/dist/components/grid/assets/collection.js +71 -34
  39. package/dist/components/grid/assets/files/0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551-fflate.txt +21 -0
  40. package/dist/components/grid/assets/files/8cf9b31947daf7adb4a7a00a037459e58241af050cd0a603bfcf1756e533f75e-write-excel-file.txt +21 -0
  41. package/dist/components/grid/assets/index.js +1 -1
  42. package/dist/components/grid/assets/modules/browser-LVJHKBBV.js +19 -0
  43. package/dist/components/grid/assets/modules/chunk-RMRBEYTI.js +1 -0
  44. package/dist/components/grid/commands.json +42 -1
  45. package/dist/components/grid/grammar.json +650 -10
  46. package/dist/components/grouplets/__init__.py +1 -1
  47. package/dist/components/grouplets/assets/collection.js +3 -3
  48. package/dist/components/grouplets/assets/index.js +1 -1
  49. package/dist/components/inputs/__init__.py +3 -2
  50. package/dist/components/inputs/assets/collection.js +38 -23
  51. package/dist/components/inputs/assets/index.js +1 -1
  52. package/dist/components/inputs/grammar.json +1533 -321
  53. package/dist/components/layout/__init__.py +1 -1
  54. package/dist/components/layout/assets/collection.js +27 -23
  55. package/dist/components/layout/assets/index.js +1 -1
  56. package/dist/components/layout/grammar.json +85 -0
  57. package/dist/components/selection_trial/__init__.py +1 -1
  58. package/dist/components/selection_trial/assets/collection.js +3 -3
  59. package/dist/components/selection_trial/assets/index.js +1 -1
  60. package/dist/components/tree/__init__.py +1 -1
  61. package/dist/components/tree/assets/collection.js +11 -11
  62. package/dist/components/tree/assets/index.js +1 -1
  63. package/dist/components/tree/grammar.json +126 -0
  64. package/dist/components/typst/__init__.py +1 -1
  65. package/dist/components/typst/assets/collection.js +2 -2
  66. package/dist/components/typst/assets/index.js +1 -1
  67. package/dist/components/uploads/__init__.py +1 -1
  68. package/dist/components/uploads/assets/collection.js +8 -8
  69. package/dist/components/uploads/assets/index.js +1 -1
  70. package/dist/components/vizabi/__init__.py +13 -0
  71. package/dist/components/vizabi/assets/collection.js +22 -0
  72. package/dist/components/vizabi/assets/index.js +3 -0
  73. package/dist/components/vizabi/commands.json +7 -0
  74. package/dist/components/vizabi/grammar.json +128 -0
  75. package/dist/gramlot.js +944 -193
  76. package/dist/gramlot.min.js +85 -53
  77. package/dist/standard-collections.js +2 -0
  78. package/package.json +13 -4
  79. package/src/binding/grid-struct.js +5 -2
  80. package/src/binding/runtime.js +12 -1
  81. package/src/bootstrap.js +1 -1
  82. package/src/builder/gramlot-builder.d.ts +15 -2
  83. package/src/builder/gramlot-builder.js +116 -8
  84. package/src/builder/source.js +42 -1
  85. package/src/components/audio-analysis-session.js +65 -0
  86. package/src/components/audio.js +44 -0
  87. package/src/components/bases.js +6 -4
  88. package/src/components/border-container.js +6 -3
  89. package/src/components/buttons.js +47 -3
  90. package/src/components/chart-bar3d-options.js +30 -0
  91. package/src/components/chart-controls.js +83 -0
  92. package/src/components/chart-data-view.js +52 -0
  93. package/src/components/chart-data.js +42 -0
  94. package/src/components/chart-domains.js +46 -0
  95. package/src/components/chart-engines/echarts-options.js +50 -0
  96. package/src/components/chart-engines/echarts.js +82 -0
  97. package/src/components/chart-engines/index.js +22 -0
  98. package/src/components/chart-engines/plotly-map.js +34 -0
  99. package/src/components/chart-engines/plotly-spatial.js +35 -0
  100. package/src/components/chart-engines/plotly.js +138 -0
  101. package/src/components/chart-engines/uplot.js +57 -0
  102. package/src/components/chart-engines/vega.js +101 -0
  103. package/src/components/chart-fields.js +110 -0
  104. package/src/components/chart-geographic-options.js +47 -0
  105. package/src/components/chart-geojson.js +60 -0
  106. package/src/components/chart-geometry.js +11 -0
  107. package/src/components/chart-map-anchors.js +24 -0
  108. package/src/components/chart-map-bar3d-options.js +41 -0
  109. package/src/components/chart-map-data.js +25 -0
  110. package/src/components/chart-map-labels.js +8 -0
  111. package/src/components/chart-map-options.js +20 -0
  112. package/src/components/chart-pane.js +91 -0
  113. package/src/components/chart-renderer.js +58 -0
  114. package/src/components/chart-sample-view.js +32 -0
  115. package/src/components/chart-spatial-options.js +40 -0
  116. package/src/components/chart-time.js +84 -0
  117. package/src/components/chart-timeline.js +70 -0
  118. package/src/components/chart-types/area.js +2 -0
  119. package/src/components/chart-types/bar.js +2 -0
  120. package/src/components/chart-types/bar3D.js +2 -0
  121. package/src/components/chart-types/donut.js +2 -0
  122. package/src/components/chart-types/horizontalBar.js +2 -0
  123. package/src/components/chart-types/index.js +26 -0
  124. package/src/components/chart-types/line.js +2 -0
  125. package/src/components/chart-types/line3D.js +2 -0
  126. package/src/components/chart-types/lines3D.js +2 -0
  127. package/src/components/chart-types/map.js +2 -0
  128. package/src/components/chart-types/map3D.js +2 -0
  129. package/src/components/chart-types/mapBar3D.js +2 -0
  130. package/src/components/chart-types/pie.js +2 -0
  131. package/src/components/chart-types/polygons3D.js +2 -0
  132. package/src/components/chart-types/scatter.js +2 -0
  133. package/src/components/chart-types/scatter3D.js +2 -0
  134. package/src/components/chart-types/stackedArea.js +2 -0
  135. package/src/components/chart-types/stackedBar.js +2 -0
  136. package/src/components/chart-types/surface.js +2 -0
  137. package/src/components/charts.js +152 -0
  138. package/src/components/check-box-text-editor.js +88 -0
  139. package/src/components/check-box-text.js +193 -0
  140. package/src/components/check-box-tree.js +62 -0
  141. package/src/components/choice-editor.js +7 -5
  142. package/src/components/choice-field-styles.js +14 -0
  143. package/src/components/choices.js +5 -0
  144. package/src/components/drawing.js +199 -0
  145. package/src/components/grid-check-sets.js +98 -0
  146. package/src/components/grid-column-filters.js +198 -0
  147. package/src/components/grid-footer.js +120 -0
  148. package/src/components/grid-formulas.js +403 -0
  149. package/src/components/grid-grammar.json +131 -2
  150. package/src/components/grid-header-interaction.js +3 -1
  151. package/src/components/grid-rows.js +2 -2
  152. package/src/components/grid-search-box.js +38 -22
  153. package/src/components/grid-search-styles.js +13 -14
  154. package/src/components/grid-search.js +8 -1
  155. package/src/components/grid-selection.js +118 -0
  156. package/src/components/grid-structure.js +36 -5
  157. package/src/components/grid-styles.js +37 -1
  158. package/src/components/grid-tools.js +229 -0
  159. package/src/components/grid.js +223 -15
  160. package/src/components/image-uploader.js +2 -2
  161. package/src/components/inputs.js +19 -10
  162. package/src/components/labelbox.js +5 -1
  163. package/src/components/licenses/claygl.txt +23 -0
  164. package/src/components/licenses/echarts-gl.txt +29 -0
  165. package/src/components/licenses/fflate.txt +21 -0
  166. package/src/components/licenses/plotly.txt +21 -0
  167. package/src/components/licenses/uplot.txt +21 -0
  168. package/src/components/licenses/vega.txt +27 -0
  169. package/src/components/licenses/write-excel-file.txt +21 -0
  170. package/src/components/menus.js +19 -11
  171. package/src/components/toolbar-overflow.js +12 -8
  172. package/src/components/tree.js +30 -8
  173. package/src/components/typed-editor.js +14 -3
  174. package/src/components/vizabi-session.js +66 -0
  175. package/src/components/vizabi.js +66 -0
  176. package/src/components/window-surface.js +20 -9
  177. package/src/components/windows.js +1 -1
  178. package/src/editing-session.d.ts +2 -0
  179. package/src/editing-session.js +35 -3
  180. package/src/gramlot.d.ts +1 -0
  181. package/src/gramlot.js +2 -0
  182. package/src/handlers/device-handler.js +32 -32
  183. package/src/handlers/source-handler.d.ts +2 -2
  184. package/src/ide-documents.js +19 -3
  185. package/src/ide-runtime.d.ts +1 -0
  186. package/src/ide-runtime.js +45 -31
  187. package/src/index.d.ts +1 -0
  188. package/src/renderer/drag-drop.js +1 -0
  189. package/src/renderer/gramlot-renderer.d.ts +2 -0
  190. package/src/renderer/gramlot-renderer.js +5 -4
  191. package/src/server/assets.d.ts +3 -0
  192. package/src/server/assets.js +9 -0
  193. package/src/server/gramlot-server.d.ts +1 -1
  194. package/src/server/gramlot-server.js +2 -1
  195. package/src/server/index.d.ts +1 -1
  196. package/src/server/index.js +1 -1
  197. package/src/server/visual-editor.js +17 -17
  198. package/src/stores/bag-collection-store.js +14 -5
  199. package/src/stores/bag-collection-view.js +80 -18
  200. package/src/stores/collection-filter.js +2 -1
  201. package/src/stores/column-filter.js +49 -0
  202. package/src/stores/id-set.js +10 -0
  203. package/src/view/controls.js +8 -0
  204. package/src/view/html.js +10 -1
  205. package/src/view/label-menu.js +61 -0
  206. package/src/view/labelbox.js +15 -2
  207. package/themes/gramlot-base/theme.css +6 -0
  208. package/tools/gramlot-tools-inspector.js +169 -505
package/dist/gramlot.js CHANGED
@@ -22927,9 +22927,95 @@ var NameSyntax = class _NameSyntax {
22927
22927
  };
22928
22928
  var NAME_SYNTAX = new NameSyntax(String.raw`[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*`);
22929
22929
 
22930
+ // src/components/choices.js
22931
+ function parseChoices(values, separator = ",") {
22932
+ if (typeof separator !== "string" || !separator) throw new TypeError("separator must be a nonempty string");
22933
+ if (values === "") return [];
22934
+ const ids = /* @__PURE__ */ new Set();
22935
+ return values.split(separator).map((item) => {
22936
+ const colon = item.indexOf(":");
22937
+ const id = colon < 0 ? item : item.slice(0, colon);
22938
+ const caption = colon < 0 ? item : item.slice(colon + 1);
22939
+ if (!id || ids.has(id)) throw new Error("Invalid or duplicate choice code");
22940
+ ids.add(id);
22941
+ return { id, caption };
22942
+ });
22943
+ }
22944
+ function choiceCaption(choices, value, placeholder = "") {
22945
+ return choices.find((choice) => choice.id === value)?.caption ?? placeholder ?? "";
22946
+ }
22947
+
22948
+ // src/view/label-menu.js
22949
+ var LabelMenu = class {
22950
+ constructor(layout, choose) {
22951
+ this.layout = layout;
22952
+ const doc = layout.box.ownerDocument;
22953
+ this.button = doc.createElement("button");
22954
+ this.button.type = "button";
22955
+ this.button.className = "label-menu-trigger";
22956
+ this.button.setAttribute("aria-haspopup", "menu");
22957
+ this.button.setAttribute("aria-expanded", "false");
22958
+ this.menu = doc.createElement("gramlot-menu");
22959
+ this.menu.projectAttributes({});
22960
+ layout.labelBox.append(this.button, this.menu);
22961
+ this.button.addEventListener("click", (event) => {
22962
+ event.preventDefault();
22963
+ event.stopPropagation();
22964
+ if (this.menu.opened) this.menu.close();
22965
+ else this.menu.open(this.button);
22966
+ });
22967
+ this.button.addEventListener("keydown", (event) => {
22968
+ if (!["ArrowDown", "ArrowUp"].includes(event.key)) return;
22969
+ event.preventDefault();
22970
+ event.stopPropagation();
22971
+ this.menu.open(this.button, event.key === "ArrowUp");
22972
+ });
22973
+ this.choose = choose;
22974
+ }
22975
+ project({ lbl, lbl_value, lbl_values, disabled, readonly }, adapt) {
22976
+ const choices = parseChoices(lbl_values);
22977
+ if (this.values !== lbl_values) {
22978
+ this.menu.close(false);
22979
+ for (const item of this.menu.items) item.releaseCommand();
22980
+ this.menu.replaceChildren(...choices.map(({ id, caption: caption2 }) => {
22981
+ const item = this.menu.ownerDocument.createElement("gramlot-menu-line");
22982
+ item.projectAttributes({ code: id, caption: caption2 }, adapt);
22983
+ item.activateCommand = (event) => {
22984
+ if (item.prepareCommand(event)) this.choose(id);
22985
+ };
22986
+ item.control.addEventListener("click", (event) => item.activateCommand(event));
22987
+ return item;
22988
+ }));
22989
+ this.values = lbl_values;
22990
+ }
22991
+ const caption = choiceCaption(choices, lbl_value, lbl);
22992
+ this.button.textContent = caption;
22993
+ this.button.disabled = Boolean(disabled || readonly || !choices.length);
22994
+ if (this.button.disabled) this.menu.close(false);
22995
+ for (const item of this.menu.items) {
22996
+ item.projectAttributes({ ...item.parameters, checked: item.parameters.code === lbl_value }, adapt);
22997
+ }
22998
+ this.layout.fieldLabel.textContent = caption;
22999
+ this.layout.fieldLabel.hidden = true;
23000
+ this.layout.labelBox.hidden = false;
23001
+ }
23002
+ dispose() {
23003
+ this.menu.close(false);
23004
+ for (const item of this.menu.items) item.releaseCommand();
23005
+ this.menu.remove();
23006
+ this.button.remove();
23007
+ this.layout.fieldLabel.hidden = false;
23008
+ }
23009
+ };
23010
+
22930
23011
  // src/view/labelbox.js
22931
23012
  var labelboxPositions = ["TL", "TC", "TR", "L", "R", "BL", "BC", "BR"];
22932
- var labelboxStyle = `.gramlot-labelbox[hidden]{display:none!important}
23013
+ var labelboxStyle = `.gramlot-labelbox>.label-box>.label-menu-trigger{font:inherit;color:inherit;background:transparent;border:0;padding:0;min-width:0;min-height:var(--gramlot-touch-target,0px);height:auto;display:inline-flex;align-items:center;gap:.4em;cursor:pointer;text-align:inherit;line-height:inherit}
23014
+ .gramlot-labelbox>.label-box>.label-menu-trigger::after{content:'';width:.35em;height:.35em;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:translateY(-.1em) rotate(45deg);flex:none}
23015
+ .gramlot-labelbox>.label-box>.label-menu-trigger:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:3px;border-radius:2px}
23016
+ .gramlot-labelbox>.label-box>.label-menu-trigger:disabled{opacity:.5;cursor:default}
23017
+ .gramlot-labelbox>.label-box>label[hidden]{display:none}
23018
+ .gramlot-labelbox[hidden]{display:none!important}
22933
23019
  .gramlot-labelbox{box-sizing:border-box;min-width:0;min-height:0;--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control';grid-template-columns:minmax(0,1fr);grid-template-rows:max-content minmax(0,1fr)}
22934
23020
  .gramlot-labelbox>.label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .gramlot-labelbox>.control-box{box-sizing:border-box;grid-area:control;min-width:0;min-height:0;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
22935
23021
  .gramlot-labelbox>.control-box>*{max-width:100%;box-sizing:border-box}
@@ -22987,7 +23073,7 @@ function createLabelbox(document, controlBox) {
22987
23073
  return layout;
22988
23074
  }
22989
23075
  function projectLabelbox(layout, attrs, adapt) {
22990
- const { lbl, lbl_variant, lbl_position = lbl_variant === "card" ? "TC" : "TL", ...rest } = attrs;
23076
+ const { lbl, lbl_value, lbl_values, lbl_variant, lbl_position = lbl_variant === "card" ? "TC" : "TL", ...rest } = attrs;
22991
23077
  if (!labelboxPositions.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
22992
23078
  const groups = { box: {}, label: {}, labelBox: {}, controlBox: {} };
22993
23079
  const prefixes = [["box_l_", "labelBox"], ["box_c_", "controlBox"], ["lbl_", "label"], ["box_", "box"]];
@@ -23017,6 +23103,13 @@ function projectLabelbox(layout, attrs, adapt) {
23017
23103
  else layout.box.dataset.variant = lbl_variant;
23018
23104
  layout.fieldLabel.textContent = lbl ?? "";
23019
23105
  layout.labelBox.hidden = lbl == null || lbl === "";
23106
+ if (lbl_values != null) {
23107
+ layout.menu ??= new LabelMenu(layout, (value) => layout.choose(value));
23108
+ layout.menu.project(attrs, adapt);
23109
+ } else if (layout.menu) {
23110
+ layout.menu.dispose();
23111
+ layout.menu = null;
23112
+ }
23020
23113
  layout.box.dispatchEvent(new layout.box.ownerDocument.defaultView.Event("gramlot-label-layout", { bubbles: true }));
23021
23114
  return rest;
23022
23115
  }
@@ -23028,6 +23121,21 @@ function labelboxPresentation(content) {
23028
23121
  return box?.labelbox && labelboxContent(box) === content ? box : content;
23029
23122
  }
23030
23123
 
23124
+ // src/components/choice-field-styles.js
23125
+ var choiceFieldStyles = `
23126
+ .choice-field{position:relative;min-width:0}
23127
+ .choice-field>input{box-sizing:border-box;width:100%;padding-inline-end:calc(var(--gramlot-choice-toggle-width,1.6em) + .4em)}
23128
+ .choice-field>.choice-toggle{position:absolute;inset-inline-end:1px;inset-block:1px;
23129
+ width:var(--gramlot-choice-toggle-width,1.6em);min-width:0;min-height:0;
23130
+ display:grid;place-items:center;padding:0;border:0;border-radius:0;
23131
+ background:transparent;box-shadow:none;color:inherit;font:inherit;cursor:pointer}
23132
+ .choice-toggle::after{content:'';width:.4em;height:.4em;border-inline-end:1.5px solid currentColor;
23133
+ border-block-end:1.5px solid currentColor;transform:translateY(-.1em) rotate(45deg);pointer-events:none}
23134
+ .choice-toggle:disabled{opacity:.5;cursor:default}
23135
+ .choice-toggle:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
23136
+ .choice-field>input::-webkit-calendar-picker-indicator{opacity:0}
23137
+ `;
23138
+
23031
23139
  // src/webcomponent.js
23032
23140
  var NAME2 = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
23033
23141
  var RESERVED = /* @__PURE__ */ new Set([
@@ -23201,21 +23309,6 @@ function parameterValues(component, attrs) {
23201
23309
  return Object.fromEntries(Object.entries(component.parameters).map(([name, spec]) => [name, Object.hasOwn(attrs, name) ? attrs[name] : spec.default]));
23202
23310
  }
23203
23311
 
23204
- // src/components/choices.js
23205
- function parseChoices(values, separator = ",") {
23206
- if (typeof separator !== "string" || !separator) throw new TypeError("separator must be a nonempty string");
23207
- if (values === "") return [];
23208
- const ids = /* @__PURE__ */ new Set();
23209
- return values.split(separator).map((item) => {
23210
- const colon = item.indexOf(":");
23211
- const id = colon < 0 ? item : item.slice(0, colon);
23212
- const caption = colon < 0 ? item : item.slice(colon + 1);
23213
- if (!id || ids.has(id)) throw new Error("Invalid or duplicate choice code");
23214
- ids.add(id);
23215
- return { id, caption };
23216
- });
23217
- }
23218
-
23219
23312
  // src/components/bases.js
23220
23313
  function controlElement(HTMLElement) {
23221
23314
  return class extends HTMLElement {
@@ -23370,11 +23463,15 @@ function ChoiceGroup(HTMLElement) {
23370
23463
  items[next].focus();
23371
23464
  });
23372
23465
  }
23466
+ choiceOptions() {
23467
+ return parseChoices(this.parameters.values ?? "");
23468
+ }
23373
23469
  projectAttributes(attrs, adapt) {
23374
23470
  const rest = super.projectAttributes(attrs, adapt);
23375
- const values = this.parameters.values ?? "";
23376
- if (values !== this.#values) {
23377
- const options = parseChoices(values);
23471
+ const values = this.choiceOptions();
23472
+ const signature = JSON.stringify(values);
23473
+ if (signature !== this.#values) {
23474
+ const options = values;
23378
23475
  const retained = /* @__PURE__ */ new Set();
23379
23476
  let previous = null;
23380
23477
  for (const { id: code, caption } of options) {
@@ -23401,7 +23498,7 @@ function ChoiceGroup(HTMLElement) {
23401
23498
  item.label.remove();
23402
23499
  this.#options.delete(code);
23403
23500
  }
23404
- this.#values = values;
23501
+ this.#values = signature;
23405
23502
  }
23406
23503
  const cols = this.parameters.cols;
23407
23504
  if (!Number.isInteger(cols) || cols < 1) throw new TypeError("cols must be a positive integer");
@@ -23835,6 +23932,7 @@ var ToolbarOverflow = class {
23835
23932
  :host([role=toolbar]) .toolbar-viewport{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex:1 1 0%;min-width:0;min-height:0;overflow-x:auto;overflow-y:hidden}
23836
23933
  :host([role=toolbar][aria-orientation=vertical]) .toolbar-viewport{flex-direction:column;align-items:stretch;overflow-x:hidden;overflow-y:auto;width:100%}
23837
23934
  :host([role=toolbar]) ::slotted(*){flex-shrink:0}
23935
+ :host([role=toolbar]) .toolbar-viewport[data-measuring]{flex:none;width:max-content;height:max-content;overflow:visible}
23838
23936
  .toolbar-more{flex:0 0 auto;width:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));height:max(var(--gramlot-field-height,32px),var(--gramlot-touch-target,0px));padding:0;border:0;border-radius:4px;background:transparent;color:inherit;font:inherit;display:grid;place-items:center}
23839
23937
  .toolbar-more svg{display:block;width:18px;height:18px;pointer-events:none}
23840
23938
  .toolbar-more:hover,.toolbar-more:focus-visible{background:var(--gramlot-selected,Highlight)}
@@ -23922,27 +24020,28 @@ var ToolbarOverflow = class {
23922
24020
  this.#overflow.clear();
23923
24021
  menu.refreshItems();
23924
24022
  for (const item of menu.items) item.refreshAvailability();
24023
+ this.#viewport.setAttribute("data-measuring", "");
23925
24024
  const gap = parseFloat(win.getComputedStyle(this.#viewport).gap) || 0;
23926
24025
  const lengths = new Map(units.map((unit) => {
23927
24026
  const css = win.getComputedStyle(unit);
23928
24027
  const length = labelboxContent(unit).localName === "gramlot-spacer" ? labelboxContent(unit).parameters.size ?? 0 : unit.getBoundingClientRect()[axis];
23929
24028
  return [unit, length + (parseFloat(css[vertical ? "marginTop" : "marginLeft"]) || 0) + (parseFloat(css[vertical ? "marginBottom" : "marginRight"]) || 0)];
23930
24029
  }));
24030
+ this.#viewport.removeAttribute("data-measuring");
23931
24031
  const separator = (unit) => labelboxContent(unit).getAttribute("role") === "separator";
23932
24032
  const tidy = (list) => list.filter((unit, index) => !separator(unit) || list.slice(0, index).some((item) => labelboxContent(item).localName !== "gramlot-spacer" && !separator(item)) && list.slice(index + 1).find((item) => labelboxContent(item).localName !== "gramlot-spacer") && !separator(list.slice(index + 1).find((item) => labelboxContent(item).localName !== "gramlot-spacer")));
23933
24033
  const required = (remaining2) => remaining2.reduce((sum2, unit) => sum2 + lengths.get(unit), 0) + Math.max(0, remaining2.length - 1) * gap;
23934
24034
  let remaining = tidy(units);
23935
24035
  if (required(remaining) > available) {
23936
- const candidates = units.map((unit, index) => ({ unit, index })).filter(({ unit }) => labelboxContent(unit).localName === "gramlot-menu-line" && !separator(unit) && labelboxContent(unit).parameters.overflowable).sort((a, b) => labelboxContent(a.unit).parameters.priority - labelboxContent(b.unit).parameters.priority || b.index - a.index);
23937
- for (const { unit } of candidates) {
23938
- if (required(remaining) <= available - 32) break;
23939
- this.#overflow.add(unit);
23940
- remaining = tidy(remaining.filter((item) => item !== unit));
24036
+ let cut = units.length;
24037
+ while (cut > 0 && required(remaining) > available - 32) {
24038
+ cut--;
24039
+ remaining = tidy(units.slice(0, cut));
23941
24040
  }
24041
+ const suffix = tidy(units.slice(cut).filter((unit) => labelboxContent(unit).localName !== "gramlot-spacer"));
24042
+ for (const unit of suffix) this.#overflow.add(unit);
23942
24043
  }
23943
- const overflowRows = tidy(units.filter((unit) => this.#overflow.has(unit) || separator(unit) && !remaining.includes(unit)));
23944
- for (const unit of overflowRows) this.#overflow.add(unit);
23945
- for (const unit of units) if (separator(unit) && !remaining.includes(unit) && !this.#overflow.has(unit)) unit.slot = "suppressed";
24044
+ for (const unit of units) if (!remaining.includes(unit) && !this.#overflow.has(unit)) unit.slot = "suppressed";
23946
24045
  for (const unit of this.#overflow) {
23947
24046
  unit.slot = "overflow";
23948
24047
  unit.setAttribute("data-menu-overflow", "");
@@ -24028,9 +24127,9 @@ function MenuContainer(HTMLElement) {
24028
24127
  const doc = this.ownerDocument, shadow = this.attachShadow({ mode: "open" });
24029
24128
  const style = doc.createElement("style");
24030
24129
  style.textContent = `:host{box-sizing:border-box;color:var(--gramlot-ink,CanvasText)}
24031
- :host([role=menu]){position:fixed;inset:auto;margin:0;padding:5px;min-width:min(16rem,var(--gramlot-popup-available-width));width:max-content;font:inherit;
24130
+ :host([role=menu]){position:fixed;inset:auto;margin:0;padding:3px;min-width:0;width:max-content;font:inherit;
24032
24131
  max-width:min(28rem,var(--gramlot-popup-available-width));max-height:var(--gramlot-popup-available-height);overflow:auto;
24033
- background:var(--gramlot-field-background,Canvas);border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-lg,9px);box-shadow:0 8px 28px #0004}
24132
+ background:var(--gramlot-field-background,Canvas);border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,5px);box-shadow:0 4px 14px #0003}
24034
24133
  :host([role=toolbar][aria-orientation=vertical]){flex-direction:column;align-items:stretch}
24035
24134
  :host([role=toolbar]){display:flex;gap:var(--gramlot-toolbar-gap,4px);align-items:center}
24036
24135
  :host([role=menu]) ::slotted([role=separator]){margin:5px 7px 5px 2.5rem;border-top:1px solid var(--gramlot-border-control,#888)}
@@ -24074,8 +24173,11 @@ function MenuContainer(HTMLElement) {
24074
24173
  isOverflowed(item) {
24075
24174
  return this.#overflow.contains(item);
24076
24175
  }
24176
+ get visibleItems() {
24177
+ return this.items.filter((item) => labelboxPresentation(item).slot !== "suppressed" && !item.hidden && !item.closest("[hidden]") && item.getAttribute("role") !== "separator");
24178
+ }
24077
24179
  get usableItems() {
24078
- return this.items.filter((item) => labelboxPresentation(item).slot !== "suppressed" && !item.disabled && !item.hidden && !item.closest("[hidden]") && item.getAttribute("role") !== "separator");
24180
+ return this.visibleItems.filter((item) => !item.disabled);
24079
24181
  }
24080
24182
  get parentMenu() {
24081
24183
  return this.parentElement?.closest("gramlot-menu") ?? null;
@@ -24170,6 +24272,11 @@ function MenuContainer(HTMLElement) {
24170
24272
  for (const group of this.querySelectorAll("gramlot-menu-line")) if (group.menuOwner === this && group.parameters.group) group.refreshAvailability();
24171
24273
  for (const item of this.items) item.refreshAvailability();
24172
24274
  const usable = this.usableItems;
24275
+ for (const [part, present, width] of [
24276
+ ["check", this.visibleItems.some((item) => item.parameters.checked != null), "1.4em"],
24277
+ ["icon", this.visibleItems.some((item) => item.entryIcon || item.entryIconSrc), "1.5em"],
24278
+ ["arrow", this.visibleItems.some((item) => item.submenu), ".9em"]
24279
+ ]) this.style.setProperty(`--gramlot-menu-${part}-track`, present ? width : "0px");
24173
24280
  if (this.#active && !usable.includes(this.#active)) {
24174
24281
  const index = this.#previous.indexOf(this.#active);
24175
24282
  const next = this.#previous.slice(index + 1).find((item) => usable.includes(item)) ?? this.#previous.slice(0, index).reverse().find((item) => usable.includes(item));
@@ -24293,10 +24400,10 @@ function menuLine(Base) {
24293
24400
  const style = doc.createElement("style");
24294
24401
  style.textContent = `:host{color:var(--gramlot-ink,CanvasText)} .control-box{color:inherit;height:100%} :host button{color:inherit}
24295
24402
  .menu-check:empty,.menu-arrow:empty{display:none}
24296
- button.menu-row{display:grid;grid-template-columns:1em 1.15em minmax(0,1fr) .7em;column-gap:.5em;
24297
- align-items:center;width:100%;min-height:max(min(var(--gramlot-field-height,28px),28px),var(--gramlot-touch-target,0px));padding:var(--gramlot-button-padding,3px 8px);
24403
+ button.menu-row{display:grid;grid-template-columns:var(--gramlot-menu-check-track,0px) var(--gramlot-menu-icon-track,0px) minmax(0,1fr) var(--gramlot-menu-arrow-track,0px);column-gap:0;
24404
+ align-items:center;width:100%;min-height:max(24px,var(--gramlot-touch-target,0px));padding:2px 7px;
24298
24405
  line-height:1.3;text-align:left;border:0;border-radius:var(--gramlot-radius-sm,5px);background:transparent;cursor:default}
24299
- .menu-row .menu-check,.menu-row .icon,.menu-row .menu-arrow{display:flex;align-items:center;justify-content:center;min-width:0}
24406
+ .menu-row .menu-check,.menu-row .icon,.menu-row .menu-arrow{display:flex;align-items:center;justify-content:start;min-width:0}
24300
24407
  .menu-row .menu-check{grid-column:1}.menu-row .icon{grid-column:2}
24301
24408
  .menu-row .menu-caption{grid-column:3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
24302
24409
  .menu-row .menu-arrow{grid-column:4;font-size:1.2em;line-height:1}
@@ -24308,6 +24415,7 @@ function menuLine(Base) {
24308
24415
  background:transparent;cursor:pointer;line-height:1.2;white-space:nowrap}
24309
24416
  :host button.toolbar-button .icon{display:inline-flex;align-items:center;justify-content:center;
24310
24417
  width:var(--gramlot-toolbar-icon-size);height:var(--gramlot-toolbar-icon-size);font-size:var(--gramlot-toolbar-icon-size);line-height:1}
24418
+ #control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size)}
24311
24419
  :host button.toolbar-button .icon:empty{display:none}
24312
24420
  :host button.toolbar-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 10%,transparent)}
24313
24421
  :host button.toolbar-button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
@@ -24317,7 +24425,7 @@ function menuLine(Base) {
24317
24425
  :host button.toolbar-below .menu-caption{font-size:11px;line-height:1.2}
24318
24426
  :host button.toolbar-tooltip .menu-caption{display:none}
24319
24427
  :host button.toolbar-button .menu-check{display:none}
24320
- :host button.toolbar-tooltip .menu-arrow{position:absolute;right:3px;top:50%;transform:translateY(-50%);font-size:12px}
24428
+ :host button.toolbar-tooltip .menu-arrow{position:static;flex:0 0 8px;margin-inline-start:2px;font-size:12px;line-height:1}
24321
24429
  :host button.toolbar-below .menu-arrow{position:absolute;inset:4px 3px auto auto;font-size:12px}`;
24322
24430
  style.textContent += `
24323
24431
  :host([role=group]){display:block;min-width:0}
@@ -24355,7 +24463,7 @@ function menuLine(Base) {
24355
24463
  return this.parentElement?.closest("gramlot-menu") ?? null;
24356
24464
  }
24357
24465
  get submenu() {
24358
- return [...this.children].map(labelboxContent).find((child) => child.localName === "gramlot-menu") ?? null;
24466
+ return [...this.children].map(labelboxContent).find((child) => child?.localName === "gramlot-menu") ?? null;
24359
24467
  }
24360
24468
  get entryCaption() {
24361
24469
  return this.parameters.caption ?? this.#registry?.label ?? "";
@@ -24378,9 +24486,9 @@ function menuLine(Base) {
24378
24486
  const rest = super.projectAttributes(attrs, adapt);
24379
24487
  this.#accessibleLabel = attrs["aria-label"];
24380
24488
  if (this.parameters.iconSize != null && (!Number.isFinite(this.parameters.iconSize) || this.parameters.iconSize <= 0)) throw new TypeError("menuline iconSize must be positive");
24381
- if (!Number.isFinite(this.parameters.priority)) throw new TypeError("menuline priority must be finite");
24382
24489
  this.#authoredDisabled = Boolean(this.parameters.disabled);
24383
24490
  this.#render();
24491
+ this.menuOwner?.refreshItems();
24384
24492
  this.menuOwner?.overflow.schedule();
24385
24493
  return rest;
24386
24494
  }
@@ -24425,9 +24533,10 @@ function menuLine(Base) {
24425
24533
  else this.control.style.removeProperty("--gramlot-toolbar-icon-size");
24426
24534
  this.toggleAttribute("data-menu-group-rows", Boolean(popup || owner?.parameters.orientation === "vertical"));
24427
24535
  this.control.classList.toggle("menu-row", popup);
24428
- this.#arrow.textContent = this.submenu ? popup || owner?.parameters.orientation === "vertical" ? "\u203A" : "\u25BE" : "";
24536
+ this.#arrow.textContent = this.submenu ? toolbar && labelPosition === "tooltip" ? "\u2304" : popup || owner?.parameters.orientation === "vertical" ? "\u203A" : "\u25BE" : "";
24429
24537
  const disabled = this.#authoredDisabled || this.getAttribute("role") === "separator" || Boolean(this.parameters.command && !this.#registry) || ["loading", "error"].includes(owner?.status) || Boolean(this.closest("gramlot-drop-down-button")?.parameters.disabled);
24430
24538
  if (this.control.disabled !== disabled) this.control.disabled = disabled;
24539
+ this.refreshIconOnly();
24431
24540
  }
24432
24541
  get disabled() {
24433
24542
  for (let p = this.parentElement; p && p !== this.menuOwner; p = p.parentElement) if (p.localName === "gramlot-menu-line" && p.parameters.disabled) return true;
@@ -24468,6 +24577,7 @@ function menuLine(Base) {
24468
24577
  function Command(HTMLElement) {
24469
24578
  return class extends controlElement(HTMLElement) {
24470
24579
  #actionPresentation = null;
24580
+ #captionObserver;
24471
24581
  constructor() {
24472
24582
  super();
24473
24583
  const doc = this.ownerDocument;
@@ -24509,7 +24619,42 @@ function Command(HTMLElement) {
24509
24619
  :host([role=separator]) button{display:none}
24510
24620
  @media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border-color:ButtonText;filter:none}}
24511
24621
  `;
24622
+ style.textContent += `
24623
+ #control.icon-only{gap:0;padding:var(--gramlot-button-icon-padding,5px);
24624
+ min-width:max(calc(var(--gramlot-button-icon-size,24px) + 12px),var(--gramlot-touch-target,0px));
24625
+ min-height:max(calc(var(--gramlot-button-icon-size,24px) + 12px),var(--gramlot-touch-target,0px));
24626
+ background:transparent;border-color:transparent;line-height:1}
24627
+ #control.icon-only .icon{display:inline-flex;align-items:center;justify-content:center;flex:none;
24628
+ width:var(--gramlot-button-icon-size,24px);height:var(--gramlot-button-icon-size,24px);
24629
+ font-size:var(--gramlot-button-icon-size,24px);line-height:1}
24630
+ #control.icon-only:hover:not(:disabled){background:var(--gramlot-selected,Highlight)}
24631
+ #control.icon-only:is([aria-pressed=true],[aria-checked=true],[aria-expanded=true]){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action,CanvasText)}
24632
+ #control.icon-only .led{display:none}
24633
+ @media(forced-colors:active){#control.icon-only{background:ButtonFace;color:ButtonText;border-color:ButtonText}
24634
+ #control.icon-only:is([aria-pressed=true],[aria-checked=true],[aria-expanded=true]){background:Highlight;color:HighlightText}}
24635
+ `;
24512
24636
  this.shadowRoot.append(style);
24637
+ this.#captionObserver = new this.ownerDocument.defaultView.MutationObserver(() => this.refreshIconOnly());
24638
+ }
24639
+ connectedCallback() {
24640
+ super.connectedCallback();
24641
+ const options = { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["hidden", "slot"] };
24642
+ this.#captionObserver.observe(this, options);
24643
+ this.#captionObserver.observe(this.control, options);
24644
+ this.refreshIconOnly();
24645
+ }
24646
+ disconnectedCallback() {
24647
+ this.#captionObserver.disconnect();
24648
+ }
24649
+ releaseControl() {
24650
+ this.#captionObserver.disconnect();
24651
+ super.releaseControl();
24652
+ }
24653
+ refreshIconOnly() {
24654
+ const hasContent = (node) => node.nodeType === 3 ? Boolean(node.textContent.trim()) : node.nodeType === 1 && !node.hidden && node.getAttribute("slot") !== "menu";
24655
+ const slottedCaption = !this.caption.hidden && this.caption.assignedNodes().some(hasContent);
24656
+ const extraCaption = [...this.control.children].some((node) => node !== this.icon && node !== this.caption && !node.hidden && !node.matches(".led,.menu-check,.menu-arrow") && !(node.matches(".menu-caption") && this.control.classList.contains("toolbar-tooltip")) && Boolean(node.textContent.trim()));
24657
+ this.control.classList.toggle("icon-only", !this.control.classList.contains("menu-row") && Boolean(this.icon.textContent || this.icon.firstElementChild) && !slottedCaption && !extraCaption);
24513
24658
  }
24514
24659
  get disabled() {
24515
24660
  return this.control.disabled;
@@ -24530,6 +24675,7 @@ function Command(HTMLElement) {
24530
24675
  renderIcon(icon, iconSrc) {
24531
24676
  if (!iconSrc) {
24532
24677
  this.icon.textContent = icon ?? "";
24678
+ this.refreshIconOnly();
24533
24679
  return;
24534
24680
  }
24535
24681
  let image = this.icon.firstElementChild;
@@ -24540,6 +24686,7 @@ function Command(HTMLElement) {
24540
24686
  this.icon.replaceChildren(image);
24541
24687
  }
24542
24688
  if (image.getAttribute("src") !== iconSrc) image.setAttribute("src", iconSrc);
24689
+ this.refreshIconOnly();
24543
24690
  }
24544
24691
  get entryIcon() {
24545
24692
  return this.parameters.icon;
@@ -24553,6 +24700,7 @@ function Command(HTMLElement) {
24553
24700
  this.icon.textContent = presentation.icon;
24554
24701
  this.title = presentation.title;
24555
24702
  this.control.setAttribute("aria-label", presentation.title);
24703
+ this.refreshIconOnly();
24556
24704
  }
24557
24705
  attachCommand() {
24558
24706
  }
@@ -24652,8 +24800,6 @@ var MenuLine = defineComponent({
24652
24800
  labelPosition: { dtype: "T", binding: "read", nullable: true, enum: ["beside", "below", "tooltip"] },
24653
24801
  iconSize: { dtype: "R", binding: "read", nullable: true },
24654
24802
  group: { dtype: "B", default: false },
24655
- priority: { dtype: "R", default: 0 },
24656
- overflowable: { dtype: "B", default: true },
24657
24803
  parameters: { annotation: { kind: "type", module: "builtins", name: "dict" }, nullable: true },
24658
24804
  favorite: { dtype: "B", default: false }
24659
24805
  },
@@ -24687,13 +24833,16 @@ var DropDownButton = defineComponent({
24687
24833
  super();
24688
24834
  const doc = this.ownerDocument;
24689
24835
  this.control.classList.add("split");
24836
+ this.controlBox.classList.add("choice-field");
24837
+ const affordance = doc.createElement("style");
24838
+ affordance.textContent = choiceFieldStyles + ".split{border-radius:var(--gramlot-radius-sm,4px);padding-inline-end:calc(var(--gramlot-choice-toggle-width,1.6em) + .5em)}";
24839
+ this.shadowRoot.append(affordance);
24690
24840
  this.#chosenCaption = doc.createElement("span");
24691
24841
  this.#chosenCaption.hidden = true;
24692
24842
  this.control.append(this.#chosenCaption);
24693
24843
  this.#arrow = doc.createElement("button");
24694
24844
  this.#arrow.type = "button";
24695
- this.#arrow.className = "arrow";
24696
- this.#arrow.textContent = "\u25BE";
24845
+ this.#arrow.className = "arrow choice-toggle";
24697
24846
  this.#arrow.setAttribute("aria-label", "Open menu");
24698
24847
  this.#arrow.setAttribute("aria-haspopup", "menu");
24699
24848
  this.#arrow.setAttribute("aria-expanded", "false");
@@ -24930,6 +25079,7 @@ var EditingSession = class {
24930
25079
  this.validationRevision = 0;
24931
25080
  this.validatedRevision = -1;
24932
25081
  this.fullValidation = null;
25082
+ this.derived = /* @__PURE__ */ new Set();
24933
25083
  if (!(this.data instanceof Bag)) throw new TypeError("A form requires a Bag at its datapath.");
24934
25084
  this.registers.setItem("baseline", copy(this.data));
24935
25085
  for (const name of ["changes", "errors", "pending", "drafts"]) this.registers.setItem(name, new Bag());
@@ -24954,6 +25104,33 @@ var EditingSession = class {
24954
25104
  get data() {
24955
25105
  return this.runtime.gramlot.data.getItem(this.path);
24956
25106
  }
25107
+ /**
25108
+ * Declare derived values (grid formula results, published totals): `match(path)` receives a path
25109
+ * relative to the session, `<path>?<attribute>` for an attribute. Derived values are never changes.
25110
+ * Returns the release.
25111
+ */
25112
+ registerDerived(match) {
25113
+ this.derived.add(match);
25114
+ this.updateChanges();
25115
+ return () => {
25116
+ this.derived.delete(match);
25117
+ };
25118
+ }
25119
+ isDerived(path) {
25120
+ for (const match of this.derived) if (match(path)) return true;
25121
+ return false;
25122
+ }
25123
+ /** The attributes of the node at `path` that are not derived. */
25124
+ ownAttributes(node, path) {
25125
+ return Object.fromEntries(Object.entries(node.attr).filter(([name]) => !this.isDerived(`${path}?${name}`)));
25126
+ }
25127
+ /** A node, possibly absent, that holds only derived values. */
25128
+ onlyDerived(node, path) {
25129
+ if (!node) return true;
25130
+ if (Object.keys(this.ownAttributes(node, path)).length) return false;
25131
+ if (node.value instanceof Bag) return node.value.getNodes().every((child) => this.onlyDerived(child, path ? `${path}.${child.label}` : child.label));
25132
+ return this.isDerived(path);
25133
+ }
24957
25134
  subscribe(listener) {
24958
25135
  this.listeners.add(listener);
24959
25136
  return () => this.listeners.delete(listener);
@@ -25371,18 +25548,20 @@ var EditingSession = class {
25371
25548
  const changes = this.registers.getItem("changes");
25372
25549
  const relative = changedPath === this.path ? "" : changedPath?.startsWith(this.path + ".") ? changedPath.slice(this.path.length + 1).split("?")[0] : "";
25373
25550
  const visit = (a, b, path2) => {
25374
- if (a && b && a.value instanceof Bag && b.value instanceof Bag && same(a.attr, b.attr)) {
25551
+ if (path2 && this.isDerived(path2)) return;
25552
+ const attrsA = a && this.ownAttributes(a, path2), attrsB = b && this.ownAttributes(b, path2);
25553
+ if (a && b && a.value instanceof Bag && b.value instanceof Bag && same(attrsA, attrsB)) {
25375
25554
  const labels = new Set([...a.value.getNodes(), ...b.value.getNodes()].map((n) => n.label));
25376
25555
  for (const label of labels) visit(a.value.getNode(label), b.value.getNode(label), path2 ? path2 + "." + label : label);
25377
- } else if (!a || !b || !same([a.value, a.attr], [b.value, b.attr])) {
25556
+ } else if (a && b ? !same([a.value, attrsA], [b.value, attrsB]) : !(this.onlyDerived(a, path2) && this.onlyDerived(b, path2))) {
25378
25557
  changes.setItem(encoded(path2), new Bag({
25379
25558
  path: path2,
25380
25559
  existed: Boolean(a),
25381
25560
  exists: Boolean(b),
25382
25561
  previous: a ? copy(a.value) : null,
25383
25562
  current: b ? copy(b.value) : null,
25384
- previousAttributes: a ? copy(a.attr) : null,
25385
- currentAttributes: b ? copy(b.attr) : null
25563
+ previousAttributes: a ? copy(attrsA) : null,
25564
+ currentAttributes: b ? copy(attrsB) : null
25386
25565
  }));
25387
25566
  }
25388
25567
  };
@@ -25658,8 +25837,37 @@ var NodeRequests = class {
25658
25837
  function isExpression2(value) {
25659
25838
  return typeof value === "string" && value.startsWith("==");
25660
25839
  }
25840
+ function structFormulaCode(grid) {
25841
+ const items = [];
25842
+ const visit = (bag) => {
25843
+ for (const child of bag.getNodes()) {
25844
+ if (child.nodeTag === "column" && typeof child.getAttr("formula") === "string") {
25845
+ items.push([`struct.${child.getAttr("field")}.formula`, child.getAttr("formula")]);
25846
+ } else if ((child._getMeta("gridStruct") || child.nodeTag === "colgroup") && child.staticValue instanceof SourceBag) visit(child.staticValue);
25847
+ }
25848
+ };
25849
+ if (grid.staticValue instanceof SourceBag) visit(grid.staticValue);
25850
+ return items;
25851
+ }
25661
25852
  var GramlotBuilderBagNode = class extends SourceBagNode {
25662
25853
  #formState = null;
25854
+ #treeStore = null;
25855
+ /** An externally owned Bag attached to this tree's Source node. */
25856
+ get treeStore() {
25857
+ return this.#treeStore;
25858
+ }
25859
+ setTreeStore(bag) {
25860
+ if (this.nodeTag !== "tree") throw new TypeError("setTreeStore requires a tree Source node");
25861
+ if (bag !== null && !(bag instanceof Bag)) throw new TypeError("setTreeStore requires a Bag or null");
25862
+ if (bag === this.#treeStore) return;
25863
+ this.#treeStore = bag;
25864
+ const runtime = this.rootBuilder.binding;
25865
+ const binding = runtime?.bindingFor(this);
25866
+ if (binding && !binding.closed) {
25867
+ binding.rebind();
25868
+ if (runtime.renderer.attached(this)) runtime.renderer.project(this);
25869
+ }
25870
+ }
25663
25871
  /** The local form lifecycle owned by the nearest marked Source ancestor. */
25664
25872
  get formState() {
25665
25873
  for (let owner = this; owner; owner = owner.parentNode) {
@@ -25703,6 +25911,12 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
25703
25911
  }
25704
25912
  return (attrs = {}) => this.builder.wrapSource(this.builder.commandOnNode(this, "grid", null, attrs));
25705
25913
  }
25914
+ get toolbar() {
25915
+ if (this.nodeTag !== "framePane") throw new TypeError("toolbar accessor requires framePane");
25916
+ const bar = this.staticValue instanceof SourceBag ? this.staticValue.getNode("top.bar") : null;
25917
+ if (!bar || bar.nodeTag !== "menu") throw new TypeError("This frame has no toolbar");
25918
+ return this.builder.wrapSource(bar);
25919
+ }
25706
25920
  get top() {
25707
25921
  return this.frameRegion("top");
25708
25922
  }
@@ -25770,6 +25984,7 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
25770
25984
  }
25771
25985
  }
25772
25986
  if (isExpression2(this.staticValue) || this.nodeTag === "script" && typeof this.staticValue === "string") items.push(["", this.staticValue]);
25987
+ if (this._getMeta("gramlot_component")?.bagStruct) items.push(...structFormulaCode(this));
25773
25988
  return items;
25774
25989
  }
25775
25990
  /**
@@ -26838,6 +27053,25 @@ var DATA_PATH_ATTRIBUTES = {
26838
27053
  dataRemote: "destination_path"
26839
27054
  };
26840
27055
  var DATA_INLINE_ATTRIBUTES = { dataFormula: "formula", dataController: "script" };
27056
+ var FRAMEWORK_ATTRIBUTES = /* @__PURE__ */ new Set(["node_label", "node_position", "nodeId", "target_id", "datapath", "iterate", "store", "_tag", "_meta", "ns"]);
27057
+ var EXPORT_FORMATS = { csv: "CSV", json: "JSON", tytx: "TYTX", xml: "XML", xlsx: "Excel" };
27058
+ var FRAME_GRID_COMPOSED = /* @__PURE__ */ new Set(["node_label", "frameTarget", "nodeId"]);
27059
+ var FRAME_GRID_PARAMETERS = /* @__PURE__ */ new Set(["storepath", "rowMode", "structpath"]);
27060
+ function keywordPatternError(spec, attrs) {
27061
+ const pattern = spec?._meta?.keywordPattern;
27062
+ if (!pattern) return null;
27063
+ const declared = new Set(spec.attributes.parameters.filter((parameter) => !parameter.kind.startsWith("var_")).map((parameter) => parameter.name));
27064
+ const unknown = Object.keys(attrs).find((name) => !declared.has(name) && !FRAMEWORK_ATTRIBUTES.has(name) && !new RegExp(pattern).test(name));
27065
+ return unknown === void 0 ? null : `unknown attribute '${unknown}'`;
27066
+ }
27067
+ function frameGridExportFormats(exportRows) {
27068
+ if (typeof exportRows === "boolean") return exportRows ? Object.keys(EXPORT_FORMATS) : [];
27069
+ if (typeof exportRows !== "string" || !exportRows.trim()) throw new TypeError("frameGrid export requires a boolean or a list of formats");
27070
+ const formats = exportRows.split(",").map((item) => item.trim());
27071
+ const unknown = formats.find((item) => !Object.hasOwn(EXPORT_FORMATS, item));
27072
+ if (unknown !== void 0) throw new TypeError(`frameGrid export format '${unknown}' is not one of ${Object.keys(EXPORT_FORMATS).join(", ")}`);
27073
+ return formats;
27074
+ }
26841
27075
  function dataElementError(tag2, attrs) {
26842
27076
  if (["input", "textarea", "select", "webcomponent"].includes(tag2) && pointerTransform(attrs.value)) {
26843
27077
  return "'value' does not accept pointer suffixes; use an ordinary value pointer";
@@ -26880,10 +27114,52 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
26880
27114
  this.defineGrammar(buttons_default.toDocument());
26881
27115
  }
26882
27116
  /** Compose real Source nodes; frame/grid/menu retain their existing runtime owners. */
26883
- frameGrid(parent, { storepath, rowMode, structpath, searchOn = false, ...attrs } = {}) {
27117
+ frameGrid(parent, {
27118
+ storepath,
27119
+ rowMode,
27120
+ structpath,
27121
+ searchOn = false,
27122
+ searchHelp = false,
27123
+ chart = false,
27124
+ export: exportRows = false,
27125
+ printRows = false,
27126
+ advancedTools = false,
27127
+ addrow = false,
27128
+ addrow_defaults = null,
27129
+ duprow = false,
27130
+ delrow = false,
27131
+ gridsemaphore = false,
27132
+ ...attrs
27133
+ } = {}) {
26884
27134
  for (const tag2 of ["framePane", "grid"]) {
26885
27135
  if (!this.schemaTag(tag2)) throw new TypeError(`frameGrid requires the ${tag2} collection`);
26886
27136
  }
27137
+ const chartOptions = {};
27138
+ for (const key2 of Object.keys(attrs)) if (key2.startsWith("chart_")) {
27139
+ chartOptions[key2.slice(6)] = attrs[key2];
27140
+ delete attrs[key2];
27141
+ }
27142
+ const [frameAttrs, routed] = this.frameGridRoute(attrs);
27143
+ const twice = Object.keys(routed).find((name) => ["storepath", "rowMode"].includes(name) || name === "structpath" && structpath != null);
27144
+ if (twice !== void 0) throw new TypeError(`frameGrid: '${twice}' is given twice`);
27145
+ if (chart !== false) {
27146
+ if (chart !== true && (typeof chart !== "string" || !chart)) throw new TypeError("chart requires a boolean or chart type");
27147
+ if (!frameAttrs.datapath) throw new TypeError("A chart frameGrid requires its own datapath");
27148
+ if (!this.schemaTag("chartPane")) throw new TypeError("frameGrid requires the chartPane collection");
27149
+ if (typeof chart === "string") chartOptions.chartType = chart;
27150
+ } else if (Object.keys(chartOptions).length) throw new TypeError("chart_* options require chart");
27151
+ const exportFormats = frameGridExportFormats(exportRows);
27152
+ for (const [name, value] of Object.entries({ printRows, advancedTools, addrow, duprow, delrow, gridsemaphore })) {
27153
+ if (typeof value !== "boolean") throw new TypeError(`frameGrid ${name} requires a boolean`);
27154
+ }
27155
+ if (addrow_defaults !== null && (!addrow || typeof addrow_defaults !== "object" || Array.isArray(addrow_defaults))) {
27156
+ throw new TypeError("addrow_defaults requires addrow and a mapping");
27157
+ }
27158
+ if (gridsemaphore) {
27159
+ if (!frameAttrs.datapath) throw new TypeError("A gridsemaphore frameGrid requires its own datapath");
27160
+ if (!this.schemaTag("editingStatus")) throw new TypeError("frameGrid requires the editingStatus collection");
27161
+ frameAttrs.form = true;
27162
+ }
26887
27163
  const gridAttrs = {
26888
27164
  storepath,
26889
27165
  rowMode,
@@ -26891,15 +27167,83 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
26891
27167
  node_label: "grid",
26892
27168
  frameTarget: true,
26893
27169
  height: "100%",
26894
- width: "100%"
27170
+ width: "100%",
27171
+ // Legacy frameGrid default: the current row identity at .selectedId of the frame's own datapath.
27172
+ ...frameAttrs.datapath ? { selectedId: "^.selectedId" } : {},
27173
+ ...routed
26895
27174
  };
27175
+ if (chart !== false) gridAttrs.nodeId = randomId();
26896
27176
  this.validateNodeValues("grid", null, gridAttrs);
26897
- if (searchOn !== false) this.validateNodeValues("searchBox", null, { searchOn });
26898
- const frame = parent.framePane(attrs);
27177
+ if (searchOn !== false) this.validateNodeValues("searchBox", null, { searchOn, searchHelp });
27178
+ const frame = parent.framePane(frameAttrs);
26899
27179
  frame.center.grid(gridAttrs);
26900
- if (searchOn !== false) frame.top.menu({ presentation: "bar", node_label: "search", aria_label: "Grid search", padding: "4px 8px", background: "var(--gramlot-surface-subtle)" }).menuline({ group: true }).searchBox({ searchOn });
27180
+ const bar = frame.top.menu({ presentation: "bar", node_label: "bar", aria_label: "Grid toolbar", class: "gramlot-grid-toolbar" });
27181
+ if (searchOn !== false) bar.menuline({ group: true, node_label: "search", class: "gramlot-grid-search" }).searchBox({ searchOn, searchHelp });
27182
+ if (addrow) bar.menuline({ command: "grid:addrow", node_label: "addrow", ...addrow_defaults === null ? {} : { parameters: { defaults: addrow_defaults } } });
27183
+ if (duprow) bar.menuline({ command: "grid:duprow", node_label: "duprow" });
27184
+ if (delrow) bar.menuline({ command: "grid:delrow", node_label: "delrow" });
27185
+ const exportMenu = (parent2) => {
27186
+ const menu = parent2.menuline({ caption: "Export", icon: "\u21E9", labelPosition: "tooltip", node_label: "export" }).menu();
27187
+ for (const name of exportFormats) menu.menuline({ command: "grid:export", caption: EXPORT_FORMATS[name], parameters: { format: name }, node_label: name });
27188
+ };
27189
+ if (exportFormats.length) exportMenu(bar);
27190
+ if (printRows) bar.menuline({ command: "grid:printRows", node_label: "printRows" });
27191
+ if (advancedTools) {
27192
+ const tools = bar.menuline({ caption: "Advanced tools", icon: "\u2026", labelPosition: "tooltip", node_label: "advancedTools" }).menu();
27193
+ tools.menuline({ command: "grid:lineNumbers", node_label: "lineNumbers" });
27194
+ if (exportFormats.length) exportMenu(tools);
27195
+ if (printRows) tools.menuline({ command: "grid:printRows", node_label: "printRows" });
27196
+ }
27197
+ if (gridsemaphore) bar.menuline({ group: true, node_label: "semaphore" }).editingStatus();
27198
+ if (chart !== false) {
27199
+ bar.menuline({ caption: "Chart", icon: "\u25A5", labelPosition: "tooltip", node_label: "chart", action: "this.SET('._chart.open',true)" });
27200
+ const window2 = frame.center.floatingPane({
27201
+ title: "Chart",
27202
+ open: "^._chart.open",
27203
+ width: "820px",
27204
+ height: "560px",
27205
+ movable: true,
27206
+ resizable: true,
27207
+ maximizable: true,
27208
+ node_label: "chartWindow"
27209
+ });
27210
+ window2.frame.center.chartPane({
27211
+ storepath,
27212
+ rowMode,
27213
+ gridId: gridAttrs.nodeId,
27214
+ configpath: "._chart",
27215
+ configDefaults: new Bag(chartOptions),
27216
+ height: "100%"
27217
+ });
27218
+ }
26901
27219
  return frame;
26902
27220
  }
27221
+ /** Split frameGrid keywords: unprefixed grid parameters go to the grid, `grid_`/`frame_` force any attribute. */
27222
+ frameGridRoute(attrs) {
27223
+ const declared = (tag2) => new Set(this.schema[tag2].attributes.parameters.filter((parameter) => !parameter.kind.startsWith("var_")).map((parameter) => parameter.name));
27224
+ const source = /* @__PURE__ */ new Set([...FRAMEWORK_ATTRIBUTES, ...META_ATTRS]);
27225
+ const gridNames = declared("grid"), frameNames = declared("framePane");
27226
+ const pattern = new RegExp(this.schema.grid._meta.parameterPattern);
27227
+ const routed = (name) => (gridNames.has(name) || pattern.test(name)) && !frameNames.has(name) && !source.has(name) && !FRAME_GRID_COMPOSED.has(name) && !FRAME_GRID_PARAMETERS.has(name);
27228
+ const frame = {}, grid = {};
27229
+ for (const [key2, value] of Object.entries(attrs)) {
27230
+ let name, target;
27231
+ if (key2.startsWith("grid_")) {
27232
+ name = key2.slice("grid_".length);
27233
+ target = grid;
27234
+ if (FRAME_GRID_COMPOSED.has(name)) throw new TypeError(`frameGrid: '${key2}' is composed by frameGrid`);
27235
+ } else if (key2.startsWith("frame_")) {
27236
+ name = key2.slice("frame_".length);
27237
+ target = frame;
27238
+ } else {
27239
+ name = key2;
27240
+ target = routed(key2) ? grid : frame;
27241
+ }
27242
+ if (Object.hasOwn(target, name)) throw new TypeError(`frameGrid: '${name}' is given twice`);
27243
+ target[name] = value;
27244
+ }
27245
+ return [frame, grid];
27246
+ }
26903
27247
  /** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
26904
27248
  static get dialectPrefixes() {
26905
27249
  const prefixes = [];
@@ -27000,7 +27344,7 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
27000
27344
  if (tag2 === "webcomponent") webcomponentCode(attrs);
27001
27345
  const excluded = excludedAttribute(attrs);
27002
27346
  if (excluded) throw new Error(`${tag2}: attribute '${excluded}' is excluded from Gramlot`);
27003
- const error = dataElementError(tag2, attrs);
27347
+ const error = dataElementError(tag2, attrs) ?? keywordPatternError(this.schema[tag2], attrs);
27004
27348
  if (error) throw new Error(`${tag2}: ${error}`);
27005
27349
  return super.validateNodeValues(tag2, value, attrs);
27006
27350
  }
@@ -27012,7 +27356,7 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
27012
27356
  if (node.nodeTag === "webcomponent") webcomponentCode(options.attrs ?? node.getAttr());
27013
27357
  const excluded = excludedAttribute(options.attrs ?? node.getAttr());
27014
27358
  if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot`);
27015
- const error = dataElementError(node.nodeTag, options.attrs ?? node.getAttr());
27359
+ const error = dataElementError(node.nodeTag, options.attrs ?? node.getAttr()) ?? keywordPatternError(this.schema[node.nodeTag], options.attrs ?? node.getAttr());
27016
27360
  if (error) throw new Error(`${node.nodeTag} '${node.label}': ${error}`);
27017
27361
  return super.validateNode(node, options);
27018
27362
  }
@@ -27715,6 +28059,14 @@ function componentContext(adapter) {
27715
28059
  callLogic: (name, keywords) => callLogic(binding.runtime, node, name, keywords),
27716
28060
  format: (value, options) => app.format(value, options),
27717
28061
  ...validationContext(binding),
28062
+ selectionDisplay: (caption, value) => {
28063
+ if (binding.closed) return;
28064
+ const pointer = node.getAttr("value");
28065
+ if (node.pointerType(pointer) !== "^" || pointer.includes("?") || !Object.is(node.getRelativeData(pointer), value)) return;
28066
+ const path = pointer.slice(1) + "?_displayedValue";
28067
+ if (node.getRelativeData(path) !== caption) node.setRelativeData(path, caption);
28068
+ },
28069
+ periodOutput: (path, value) => node.setRelativeData(path, value),
27718
28070
  selectionOutputs: ({ selectedCaption, selectedRecord, fields }, row) => {
27719
28071
  if (binding.closed) return;
27720
28072
  if (selectedCaption) node.setRelativeData(selectedCaption, row?.caption ?? null);
@@ -27886,6 +28238,10 @@ var HtmlElement = class {
27886
28238
  const controlBox = document.createElement("div");
27887
28239
  controlBox.append(element);
27888
28240
  record2.labelbox = createLabelbox(document, controlBox);
28241
+ record2.labelbox.choose = (value) => {
28242
+ if (node.pointerType(node.getAttr("lbl_value"))) this.writeParameter(node, "lbl_value", value);
28243
+ else node.setAttr({ lbl_value: value });
28244
+ };
27889
28245
  record2.presentation = record2.labelbox.box;
27890
28246
  record2.labelId = `gramlot-label-${randomId()}`;
27891
28247
  record2.controlId = `gramlot-control-${randomId()}`;
@@ -27959,7 +28315,10 @@ var HtmlElement = class {
27959
28315
  }
27960
28316
  if (record2.labelbox) {
27961
28317
  record2.labelbox.box.style.visibility = "";
27962
- projectLabelbox(record2.labelbox, attrs, adapt);
28318
+ const parameters2 = this.definition(node).meta.gramlot_component?.parameters ?? {};
28319
+ const defaults = Object.fromEntries(Object.entries(parameters2).filter(([name, spec]) => name.startsWith("lbl_") && Object.hasOwn(spec, "default")).map(([name, spec]) => [name, spec.default]));
28320
+ if (attrs.lbl_variant === "card" && attrs.lbl_position == null) delete defaults.lbl_position;
28321
+ projectLabelbox(record2.labelbox, { ...defaults, ...attrs }, adapt);
27963
28322
  }
27964
28323
  if (this.definition(node).meta.gramlot_component) {
27965
28324
  if (this.definition(node).meta.gramlot_component.bagStore) {
@@ -28604,6 +28963,53 @@ var NativeEventBinding = class {
28604
28963
  }
28605
28964
  };
28606
28965
 
28966
+ // src/stores/column-filter.js
28967
+ function columnValue(value) {
28968
+ if (value == null || value === "") return null;
28969
+ if (typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || value instanceof Date && Number.isFinite(value.getTime()) || isDecimal2(value) && value.isFinite()) return value;
28970
+ throw new TypeError("Column filters require loaded scalar values");
28971
+ }
28972
+ function columnValueKey(value) {
28973
+ return toTytx(columnValue(value));
28974
+ }
28975
+ function columnSelection(values) {
28976
+ if (!Array.isArray(values)) throw new TypeError("Column selection requires an array or null");
28977
+ return Object.freeze([...new Map(values.map((value) => {
28978
+ const key2 = columnValueKey(value);
28979
+ return [key2, fromTytx(key2)];
28980
+ })).values()]);
28981
+ }
28982
+ function columnDateRange(range) {
28983
+ if (range === null) return null;
28984
+ const { from, to, dtype, timeZone } = range;
28985
+ if (!["D", "DH", "DHZ"].includes(dtype)) throw new TypeError("Date range requires a date column");
28986
+ for (const value of [from, to]) {
28987
+ if (value !== null && (!(value instanceof Date) || !Number.isFinite(value.getTime()) || value.getUTCHours() || value.getUTCMinutes() || value.getUTCSeconds() || value.getUTCMilliseconds())) {
28988
+ throw new TypeError("Date bounds require civil dates");
28989
+ }
28990
+ }
28991
+ if (from && to && from > to) throw new RangeError("From must not be after To.");
28992
+ if (dtype === "DHZ" && !timeZone) throw new TypeError("DHZ requires a timeZone");
28993
+ return from || to ? Object.freeze({
28994
+ from: from?.toISOString().slice(0, 10) ?? null,
28995
+ to: to?.toISOString().slice(0, 10) ?? null,
28996
+ dtype,
28997
+ timeZone
28998
+ }) : null;
28999
+ }
29000
+ function columnDateMatches(value, range) {
29001
+ if (!range) return true;
29002
+ if (value == null || value === "") return false;
29003
+ if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw new TypeError("Date range requires date values");
29004
+ let day;
29005
+ if (range.dtype === "DHZ") {
29006
+ const parts2 = new Intl.DateTimeFormat("en", { timeZone: range.timeZone, year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(value);
29007
+ const part = (type) => parts2.find((item) => item.type === type).value;
29008
+ day = `${part("year")}-${part("month")}-${part("day")}`;
29009
+ } else day = value.toISOString().slice(0, 10);
29010
+ return (!range.from || day >= range.from) && (!range.to || day <= range.to);
29011
+ }
29012
+
28607
29013
  // node_modules/@genrojs/toolbox/js/src/dates/civil.js
28608
29014
  function daysInMonth(year, month) {
28609
29015
  if (month === 2) return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
@@ -29112,7 +29518,8 @@ function compileFilter(filter) {
29112
29518
  if (typeof value !== "string" || !Array.isArray(columns) || !columns.length || columns.some((field) => typeof field !== "string" || !field || field === "rowidx") || !["T", "L", "R", "N", "D"].includes(dtype)) throw new TypeError("Invalid collection filter");
29113
29519
  if (!value.trim()) return null;
29114
29520
  if (dtype === "T") {
29115
- const expression = new RegExp(value, "i");
29521
+ const pattern = filter.literal === true ? value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") : value;
29522
+ const expression = new RegExp(pattern, "i");
29116
29523
  return (read) => expression.test(columns.map((field) => searchText(read(field), locale, filter.timeZone)).join(" "));
29117
29524
  }
29118
29525
  if (columns.length !== 1) throw new TypeError("Typed filters require one column");
@@ -29181,6 +29588,19 @@ function parseNumber(text3, locale) {
29181
29588
  return result;
29182
29589
  }
29183
29590
 
29591
+ // src/stores/id-set.js
29592
+ function containsId(value, id) {
29593
+ return ("," + value + ",").includes("," + id + ",");
29594
+ }
29595
+ function requireIdSet(value) {
29596
+ if (typeof value !== "string") throw new TypeError("grid checked must refer to a string (empty string for an empty set)");
29597
+ return value;
29598
+ }
29599
+ function requireId(id) {
29600
+ if (typeof id !== "string" || !id || id.includes(",")) throw new TypeError("grid checkedField requires nonempty text IDs without commas");
29601
+ return id;
29602
+ }
29603
+
29184
29604
  // src/stores/bag-collection-store.js
29185
29605
  var BagCollectionStore = class {
29186
29606
  #listeners = /* @__PURE__ */ new Set();
@@ -29195,9 +29615,14 @@ var BagCollectionStore = class {
29195
29615
  this.#listeners.add(listener);
29196
29616
  return () => this.#listeners.delete(listener);
29197
29617
  }
29198
- /** Called by the page's single Data subscription. Each view reconciles independently. */
29199
- receiveData(event, row = null) {
29200
- publishCollection(this.#listeners, { full: row === null, rows: row ? [row] : [] });
29618
+ /**
29619
+ * Called by the page's single Data subscription. Each view reconciles independently.
29620
+ * `row` is the row node the event is inside, null for a change of the row list itself;
29621
+ * `field` is the label directly under the row on the event path, null when the event
29622
+ * targets the row node or inserts/deletes its direct children.
29623
+ */
29624
+ receiveData(event, row = null, field = null) {
29625
+ publishCollection(this.#listeners, { full: row === null, rows: row ? [row] : [], event, field });
29201
29626
  }
29202
29627
  getRows() {
29203
29628
  const nodes = this.bag.getNodes();
@@ -29221,7 +29646,12 @@ var BagCollectionStore = class {
29221
29646
  };
29222
29647
  function publishCollection(listeners, change) {
29223
29648
  const errors = [];
29224
- const notice = Object.freeze({ full: change.full, rows: Object.freeze([...change.rows]) });
29649
+ const notice = Object.freeze({
29650
+ full: change.full,
29651
+ rows: Object.freeze([...change.rows]),
29652
+ event: change.event ?? null,
29653
+ field: change.field ?? null
29654
+ });
29225
29655
  for (const listener of [...listeners]) {
29226
29656
  if (!listeners.has(listener)) continue;
29227
29657
  try {
@@ -29240,8 +29670,7 @@ var BagCollectionView = class {
29240
29670
  #listeners = /* @__PURE__ */ new Set();
29241
29671
  #indices = /* @__PURE__ */ new Map();
29242
29672
  #sortedBy = "";
29243
- #filter = null;
29244
- #predicate = null;
29673
+ #filters = /* @__PURE__ */ new Map();
29245
29674
  #filtered = null;
29246
29675
  constructor(store) {
29247
29676
  this.bindStore(store);
@@ -29259,7 +29688,19 @@ var BagCollectionView = class {
29259
29688
  return parseSort(this.#sortedBy);
29260
29689
  }
29261
29690
  get filter() {
29262
- return this.#filter;
29691
+ return this.#filters.get("search")?.definition ?? null;
29692
+ }
29693
+ get filterSignature() {
29694
+ return JSON.stringify([...this.#filters].map(([name, { definition }]) => [name, definition]));
29695
+ }
29696
+ /** Immutable accepted entries cross runtime/collection bundle boundaries. */
29697
+ get filterContributions() {
29698
+ return Object.freeze([...this.#filters].map(([name, entry]) => Object.freeze([name, Object.freeze({ ...entry })])));
29699
+ }
29700
+ /** Copy immutable accepted criteria into another Source-owned view, never rows. */
29701
+ copyFiltersFrom(view) {
29702
+ if (this.filterSignature === view.filterSignature) return;
29703
+ this.#commit(this.#orderedNodes(), this.#sortedBy, new Map(view.filterContributions));
29263
29704
  }
29264
29705
  get filtered() {
29265
29706
  return this.#filtered === null ? null : [...this.#filtered];
@@ -29300,39 +29741,88 @@ var BagCollectionView = class {
29300
29741
  return this.#store.getRows().toSorted((a, b) => (this.#indices.get(a) ?? Infinity) - (this.#indices.get(b) ?? Infinity));
29301
29742
  }
29302
29743
  synchronize(change = { full: true, rows: [] }) {
29303
- if (!change.full && !this.#sortedBy && !this.#predicate) {
29304
- publishCollection(this.#listeners, change);
29744
+ if (!change.full && !this.#sortedBy && !this.#filters.size) {
29745
+ publishCollection(this.#listeners, { full: change.full, rows: change.rows });
29305
29746
  return;
29306
29747
  }
29307
- this.#commit(this.#sorted(this.#orderedNodes(), this.criteria), this.#sortedBy, this.#filter, this.#predicate, change);
29748
+ this.#commit(this.#sorted(this.#orderedNodes(), this.criteria), this.#sortedBy, this.#filters, change);
29308
29749
  }
29309
29750
  sort(sortedBy) {
29310
29751
  const nodes = this.#sorted(this.#orderedNodes(), parseSort(sortedBy));
29311
- this.#commit(nodes, sortedBy, this.#filter, this.#predicate);
29752
+ this.#commit(nodes, sortedBy, this.#filters);
29312
29753
  }
29313
29754
  moveRow(node, target, after = false) {
29314
29755
  if (node === target || node.parentBag !== this.bag || target.parentBag !== this.bag) return;
29315
29756
  const nodes = this.getRows(false);
29316
29757
  nodes.splice(nodes.indexOf(node), 1);
29317
29758
  nodes.splice(nodes.indexOf(target) + Number(after), 0, node);
29318
- this.#commit(nodes, "", this.#filter, this.#predicate);
29759
+ this.#commit(nodes, "", this.#filters);
29319
29760
  }
29320
- applyFilter(filter) {
29761
+ applyFilter(filter, contribution2 = "search") {
29762
+ if (!["base", "search"].includes(contribution2)) throw new TypeError("Unknown collection filter contribution");
29321
29763
  const definition = filter === null ? null : Object.freeze({ ...filter, columns: Object.freeze([...filter.columns]) });
29322
- const predicate = compileFilter(definition);
29323
- this.#commit(this.#orderedNodes(), this.#sortedBy, definition, predicate);
29764
+ this.#applyContribution(contribution2, definition, compileFilter(definition));
29324
29765
  }
29325
- #commit(nodes, sortedBy, filter, predicate, change = { full: false, rows: [] }) {
29326
- const filtered = predicate ? nodes.flatMap((node, index) => predicate((field) => this.value(node, field)) ? [index] : []) : null;
29327
- const full = change.full || sortedBy !== this.#sortedBy || JSON.stringify(filter) !== JSON.stringify(this.#filter) || nodes.length !== this.#indices.size || nodes.some((node, index) => this.#indices.get(node) !== index) || JSON.stringify(filtered) !== JSON.stringify(this.#filtered);
29766
+ applySetFilter(sets) {
29767
+ const definition = sets === null ? null : Object.freeze(sets.map(({ field, value }) => {
29768
+ if (typeof field !== "string" || !field) throw new TypeError("Set filter requires an identity field");
29769
+ requireIdSet(value);
29770
+ return Object.freeze({ field, value });
29771
+ }));
29772
+ const predicate = definition === null ? null : (read) => definition.every(({ field, value }) => containsId(value, requireId(read(field))));
29773
+ this.#applyContribution("sets", definition, predicate);
29774
+ }
29775
+ columnFilter(field) {
29776
+ return this.#filters.get(`column:${field}`)?.definition.values ?? null;
29777
+ }
29778
+ columnRange(field) {
29779
+ const range = this.#filters.get(`column:${field}`)?.definition.range;
29780
+ return range ? { ...range, from: range.from && /* @__PURE__ */ new Date(range.from + "T00:00:00Z"), to: range.to && /* @__PURE__ */ new Date(range.to + "T00:00:00Z") } : null;
29781
+ }
29782
+ applyColumnFilter(field, values, range = this.columnRange(field)) {
29783
+ range = columnDateRange(range);
29784
+ if (typeof field !== "string" || !field) throw new TypeError("Column filter requires a field");
29785
+ const selected = values === null ? null : columnSelection(values);
29786
+ const keys = selected?.map(columnValueKey);
29787
+ const definition = selected === null && range === null ? null : Object.freeze({ field, values: selected, keys: keys && Object.freeze(keys), range });
29788
+ const predicate = definition === null ? null : (read) => columnDateMatches(read(field), range) && (keys === void 0 || keys.includes(columnValueKey(read(field))));
29789
+ this.#applyContribution(`column:${field}`, definition, predicate);
29790
+ }
29791
+ columnFacets(field) {
29792
+ const facets = /* @__PURE__ */ new Map();
29793
+ const range = this.#filters.get(`column:${field}`)?.definition.range ?? null;
29794
+ const selected = this.columnFilter(field);
29795
+ const keys = selected?.map(columnValueKey);
29796
+ const predicates = [...this.#filters].filter(([name]) => name !== `column:${field}`).map(([, entry]) => entry.predicate).filter((predicate) => predicate !== null);
29797
+ for (const node of this.#orderedNodes()) {
29798
+ const value = columnValue(this.value(node, field)), key2 = columnValueKey(value);
29799
+ if (!facets.has(key2)) facets.set(key2, { key: key2, value, count: 0, selected: columnDateMatches(value, range) && (keys === void 0 || keys.includes(key2)) });
29800
+ if (predicates.every((predicate) => predicate((field2) => this.value(node, field2)))) facets.get(key2).count++;
29801
+ }
29802
+ for (const value of selected ?? []) {
29803
+ const key2 = columnValueKey(value);
29804
+ if (!facets.has(key2)) facets.set(key2, { key: key2, value, count: 0, selected: true });
29805
+ }
29806
+ return [...facets.values()].filter((entry) => columnDateMatches(entry.value, range));
29807
+ }
29808
+ #applyContribution(name, definition, predicate) {
29809
+ if (JSON.stringify(this.#filters.get(name)?.definition ?? null) === JSON.stringify(definition)) return;
29810
+ const filters = new Map(this.#filters);
29811
+ if (definition === null) filters.delete(name);
29812
+ else filters.set(name, { definition, predicate });
29813
+ this.#commit(this.#orderedNodes(), this.#sortedBy, filters);
29814
+ }
29815
+ #commit(nodes, sortedBy, filters, change = { full: false, rows: [] }) {
29816
+ const predicates = [...filters.values()].map((entry) => entry.predicate).filter((predicate) => predicate !== null);
29817
+ const filtered = predicates.length ? nodes.flatMap((node, index) => predicates.every((predicate) => predicate((field) => this.value(node, field))) ? [index] : []) : null;
29818
+ const full = change.full || sortedBy !== this.#sortedBy || filters !== this.#filters || nodes.length !== this.#indices.size || nodes.some((node, index) => this.#indices.get(node) !== index) || JSON.stringify(filtered) !== JSON.stringify(this.#filtered);
29328
29819
  this.#indices = new Map(nodes.map((node, index) => [node, index]));
29329
29820
  this.#sortedBy = sortedBy;
29330
- this.#filter = filter;
29331
- this.#predicate = predicate;
29821
+ this.#filters = filters;
29332
29822
  this.#filtered = filtered;
29333
29823
  const visible = filtered === null ? null : new Set(filtered);
29334
29824
  const rows = full ? [] : change.rows.filter((node) => this.#indices.has(node) && (visible === null || visible.has(this.#indices.get(node))));
29335
- if (full || rows.length) publishCollection(this.#listeners, { full, rows });
29825
+ if (full || rows.length || change.rows.length) publishCollection(this.#listeners, { full, rows });
29336
29826
  }
29337
29827
  #sorted(nodes, criteria) {
29338
29828
  if (!criteria.length) return nodes;
@@ -29570,9 +30060,171 @@ var DataRouter = class {
29570
30060
  }
29571
30061
  };
29572
30062
 
30063
+ // src/components/grid-formulas.js
30064
+ var SPECIAL_INDEX = "#";
30065
+ var IDENTIFIER2 = /[A-Za-z_$][\w$]*/g;
30066
+ function formulaDefinitions(columns) {
30067
+ const entries3 = /* @__PURE__ */ new Map();
30068
+ for (const column of columns) {
30069
+ if (column.formula == null) continue;
30070
+ const formula = column.formula.trim();
30071
+ const special = formula === SPECIAL_INDEX ? { kind: "index", field: null } : formula.startsWith("+=") ? { kind: "running", field: formula.slice(2).trim() } : formula.startsWith("%=") ? { kind: "percent", field: formula.slice(2).trim() } : null;
30072
+ if (special && special.kind !== "index" && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(special.field)) {
30073
+ throw new TypeError(`grid formula '${formula}' requires a field`);
30074
+ }
30075
+ const parameters2 = /* @__PURE__ */ new Map();
30076
+ for (const [name, raw] of Object.entries(column)) {
30077
+ if (name.startsWith("formula_")) parameters2.set(name.slice("formula_".length), raw);
30078
+ }
30079
+ let arithmetic = null;
30080
+ if (!special) {
30081
+ try {
30082
+ arithmetic = parseArithmetic(formula);
30083
+ } catch {
30084
+ }
30085
+ }
30086
+ const references = special ? new Set(special.field ? [special.field] : []) : new Set(formula.match(IDENTIFIER2) ?? []);
30087
+ entries3.set(column.field, {
30088
+ field: column.field,
30089
+ formula: column.formula,
30090
+ special,
30091
+ arithmetic,
30092
+ parameters: parameters2,
30093
+ references,
30094
+ calculated: column.calculated === true,
30095
+ column
30096
+ });
30097
+ }
30098
+ const triggered = /* @__PURE__ */ new Map();
30099
+ for (const entry of entries3.values()) {
30100
+ for (const dependency of entry.references) {
30101
+ if (!triggered.has(dependency)) triggered.set(dependency, /* @__PURE__ */ new Set());
30102
+ triggered.get(dependency).add(entry.field);
30103
+ }
30104
+ }
30105
+ const visiting = /* @__PURE__ */ new Set(), visited = /* @__PURE__ */ new Set(), order = [];
30106
+ const visit = (field) => {
30107
+ if (visited.has(field)) return;
30108
+ if (visiting.has(field)) throw new TypeError(`grid formula dependency cycle at '${field}'`);
30109
+ visiting.add(field);
30110
+ for (const dependency of entries3.get(field).references) if (entries3.has(dependency)) visit(dependency);
30111
+ visiting.delete(field);
30112
+ visited.add(field);
30113
+ order.push(field);
30114
+ };
30115
+ for (const field of entries3.keys()) visit(field);
30116
+ const viewFields = /* @__PURE__ */ new Set();
30117
+ for (const field of order) {
30118
+ const entry = entries3.get(field);
30119
+ if (["index", "running"].includes(entry.special?.kind) || [...entry.references].some((name) => viewFields.has(name))) viewFields.add(field);
30120
+ }
30121
+ const definitions = new Map([...entries3].map(([field, entry]) => [field, Object.freeze({ ...entry, view: viewFields.has(field) })]));
30122
+ return Object.freeze({ definitions, triggered, order: Object.freeze(order), viewFields });
30123
+ }
30124
+ function parseArithmetic(code) {
30125
+ const tokens = tokenize(code);
30126
+ let position = 0;
30127
+ const peek = () => tokens[position];
30128
+ const take = (value) => {
30129
+ if (peek().value !== value) throw new SyntaxError(`expected '${value}' in arithmetic formula`);
30130
+ return tokens[position++];
30131
+ };
30132
+ const precedence = { "+": 1, "-": 1, "*": 2, "/": 2, "%": 2, "**": 3 };
30133
+ const primary = () => {
30134
+ const token = peek();
30135
+ if (token.type === "number") {
30136
+ position++;
30137
+ return { kind: "number", value: token.value };
30138
+ }
30139
+ if (token.type === "name") {
30140
+ position++;
30141
+ return { kind: "name", value: token.value };
30142
+ }
30143
+ if (token.value === "(") {
30144
+ position++;
30145
+ const node = expression(0);
30146
+ take(")");
30147
+ return node;
30148
+ }
30149
+ if (token.value === "+" || token.value === "-") {
30150
+ position++;
30151
+ return { kind: "unary", operator: token.value, child: primary() };
30152
+ }
30153
+ throw new SyntaxError(`unexpected '${token.value || "end"}' in arithmetic formula`);
30154
+ };
30155
+ const expression = (minimum) => {
30156
+ let left = primary();
30157
+ while (precedence[peek().value] >= minimum) {
30158
+ const operator = tokens[position++].value;
30159
+ const right = expression(precedence[operator] + (operator === "**" ? 0 : 1));
30160
+ left = { kind: "binary", operator, left, right };
30161
+ }
30162
+ return left;
30163
+ };
30164
+ const tree = expression(0);
30165
+ if (peek().type !== "eof") throw new SyntaxError(`unexpected '${peek().value}' in arithmetic formula`);
30166
+ return tree;
30167
+ }
30168
+ function tokenize(code) {
30169
+ const result = [];
30170
+ let offset = 0;
30171
+ while (offset < code.length) {
30172
+ const rest = code.slice(offset);
30173
+ const whitespace = /^\s+/.exec(rest);
30174
+ if (whitespace) {
30175
+ offset += whitespace[0].length;
30176
+ continue;
30177
+ }
30178
+ const number = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(rest);
30179
+ if (number) {
30180
+ result.push({ type: "number", value: number[0] });
30181
+ offset += number[0].length;
30182
+ continue;
30183
+ }
30184
+ const name = /^[A-Za-z_$][\w$]*/.exec(rest);
30185
+ if (name) {
30186
+ result.push({ type: "name", value: name[0] });
30187
+ offset += name[0].length;
30188
+ continue;
30189
+ }
30190
+ const operator = /^(?:\*\*|[()+\-*/%])/.exec(rest);
30191
+ if (operator) {
30192
+ result.push({ type: "operator", value: operator[0] });
30193
+ offset += operator[0].length;
30194
+ continue;
30195
+ }
30196
+ throw new SyntaxError(`unsupported arithmetic formula token at ${offset}`);
30197
+ }
30198
+ result.push({ type: "eof", value: "" });
30199
+ return result;
30200
+ }
30201
+
29573
30202
  // src/components/grid-structure.js
29574
30203
  var TYPES = /* @__PURE__ */ new Set(["T", "B", "L", "R", "N", "D", "H", "DHZ"]);
29575
- var COLUMN_KEYS = /* @__PURE__ */ new Set(["tag", "field", "name", "dtype", "width", "align", "format", "columnset", "white_space", "max_height", "edit"]);
30204
+ var COLUMN_KEYS = /* @__PURE__ */ new Set([
30205
+ "tag",
30206
+ "field",
30207
+ "name",
30208
+ "title",
30209
+ "dtype",
30210
+ "width",
30211
+ "align",
30212
+ "format",
30213
+ "columnset",
30214
+ "white_space",
30215
+ "max_height",
30216
+ "edit",
30217
+ "check",
30218
+ "checked",
30219
+ "checkedField",
30220
+ "formula",
30221
+ "calculated",
30222
+ "hidden",
30223
+ "totalize",
30224
+ "footer_value",
30225
+ "footer_format"
30226
+ ]);
30227
+ var FORMULA_PARAMETER = /^formula_[A-Za-z_$][\w$]*$/;
29576
30228
  var GROUP_KEYS = /* @__PURE__ */ new Set(["tag", "code", "name", "background", "color"]);
29577
30229
  var GridStructure = class {
29578
30230
  #nodes = /* @__PURE__ */ new Map();
@@ -29595,9 +30247,10 @@ var GridStructure = class {
29595
30247
  }
29596
30248
  this.columns = [];
29597
30249
  this.groups = [];
30250
+ const declared = [];
29598
30251
  for (const node of cells.getNodes()) {
29599
30252
  const attrs = node.getAttr();
29600
- requireKeys(attrs, COLUMN_KEYS);
30253
+ requireKeys(attrs, COLUMN_KEYS, FORMULA_PARAMETER);
29601
30254
  if (attrs.tag !== "cell" || node.staticValue != null || node.resolver) throw new TypeError("grid cell must be a scalar declaration");
29602
30255
  requireIdentity(attrs.field, "field");
29603
30256
  if (fields.has(attrs.field)) throw new TypeError(`Duplicate grid field: ${attrs.field}`);
@@ -29613,13 +30266,23 @@ var GridStructure = class {
29613
30266
  throw new TypeError("grid max_height requires a nonnegative CSS length (px, em or rem)");
29614
30267
  }
29615
30268
  if (attrs.white_space != null && !["normal", "nowrap", "pre-wrap"].includes(attrs.white_space)) throw new TypeError("grid white_space requires normal, nowrap or pre-wrap");
29616
- for (const key2 of ["name", "format"]) if (attrs[key2] != null && typeof attrs[key2] !== "string") throw new TypeError(`grid ${key2} must be text`);
30269
+ for (const key2 of ["name", "title", "format"]) if (attrs[key2] != null && typeof attrs[key2] !== "string") throw new TypeError(`grid ${key2} must be text`);
29617
30270
  if (attrs.edit != null && typeof attrs.edit !== "boolean" && (typeof attrs.edit !== "object" || Array.isArray(attrs.edit))) throw new TypeError("grid edit requires a boolean or editor options");
30271
+ if (attrs.check != null || attrs.checked != null || attrs.checkedField != null) {
30272
+ if (!["multiple", "single"].includes(attrs.check) || typeof attrs.checked !== "string" || !attrs.checked.startsWith("^") || attrs.checked.length < 2 || attrs.checked.includes("?")) {
30273
+ throw new TypeError("grid check requires single or multiple and checked=^DataPath");
30274
+ }
30275
+ requireIdentity(attrs.checkedField, "checkedField");
30276
+ if (attrs.edit) throw new TypeError("external check sets cannot edit row fields");
30277
+ }
30278
+ requireFormulaAttributes(attrs);
29618
30279
  const column = Object.freeze({
29619
30280
  ...attrs,
29620
30281
  name: attrs.name ?? attrs.field,
29621
30282
  align: attrs.align ?? (["L", "R", "N"].includes(attrs.dtype) ? "end" : "start")
29622
30283
  });
30284
+ declared.push(column);
30285
+ if (attrs.hidden) continue;
29623
30286
  this.columns.push(column);
29624
30287
  const code = attrs.columnset ?? null;
29625
30288
  let run = this.groups.at(-1);
@@ -29630,6 +30293,8 @@ var GridStructure = class {
29630
30293
  run.columns.push(column);
29631
30294
  }
29632
30295
  if (!this.columns.length) throw new TypeError("grid struct requires at least one column");
30296
+ this.fields = Object.freeze([...fields]);
30297
+ this.formulas = formulaDefinitions(declared);
29633
30298
  for (const group of this.groups) {
29634
30299
  Object.freeze(group.columns);
29635
30300
  Object.freeze(group);
@@ -29659,8 +30324,21 @@ function branch(bag, label) {
29659
30324
  if (!node || node.resolver || !(node.staticValue instanceof Bag)) throw new TypeError(`grid struct requires Bag ${label}`);
29660
30325
  return node.staticValue;
29661
30326
  }
29662
- function requireKeys(attrs, allowed) {
29663
- for (const key2 of Object.keys(attrs)) if (!allowed.has(key2)) throw new TypeError(`Unsupported grid struct attribute: ${key2}`);
30327
+ function requireKeys(attrs, allowed, pattern = null) {
30328
+ for (const key2 of Object.keys(attrs)) {
30329
+ if (!allowed.has(key2) && !pattern?.test(key2)) throw new TypeError(`Unsupported grid struct attribute: ${key2}`);
30330
+ }
30331
+ }
30332
+ function requireFormulaAttributes(attrs) {
30333
+ if (attrs.formula != null && (typeof attrs.formula !== "string" || !attrs.formula.trim())) throw new TypeError("grid formula must be nonempty text");
30334
+ if (attrs.formula == null && (attrs.calculated != null || Object.keys(attrs).some((key2) => key2.startsWith("formula_")))) {
30335
+ throw new TypeError(`grid ${attrs.field}: calculated and formula_<name> require a formula`);
30336
+ }
30337
+ for (const key2 of ["calculated", "hidden"]) if (attrs[key2] != null && typeof attrs[key2] !== "boolean") throw new TypeError(`grid ${key2} must be a boolean`);
30338
+ if (attrs.totalize != null && typeof attrs.totalize !== "boolean" && (typeof attrs.totalize !== "string" || !attrs.totalize)) {
30339
+ throw new TypeError("grid totalize requires a boolean or a Data path");
30340
+ }
30341
+ for (const key2 of ["footer_value", "footer_format"]) if (attrs[key2] != null && typeof attrs[key2] !== "string") throw new TypeError(`grid ${key2} must be text`);
29664
30342
  }
29665
30343
  function requireIdentity(value, label) {
29666
30344
  if (typeof value !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) throw new TypeError(`grid ${label} requires a simple field identifier`);
@@ -29677,7 +30355,29 @@ function structureData(source) {
29677
30355
  node.builder.validateNode(node);
29678
30356
  if (node.nodeTag !== "column" || node.staticValue != null) throw new TypeError("grid column must be a scalar declaration");
29679
30357
  const attrs = { tag: "cell" };
29680
- for (const key2 of ["field", "name", "dtype", "width", "align", "format", "white_space", "max_height", "edit"]) {
30358
+ const keys = [
30359
+ "field",
30360
+ "name",
30361
+ "title",
30362
+ "dtype",
30363
+ "width",
30364
+ "align",
30365
+ "format",
30366
+ "white_space",
30367
+ "max_height",
30368
+ "edit",
30369
+ "check",
30370
+ "checked",
30371
+ "checkedField",
30372
+ "formula",
30373
+ "calculated",
30374
+ "hidden",
30375
+ "totalize",
30376
+ "footer_value",
30377
+ "footer_format",
30378
+ ...Object.keys(node.getAttr()).filter((key2) => key2.startsWith("formula_"))
30379
+ ];
30380
+ for (const key2 of keys) {
29681
30381
  if (node.getAttr(key2) != null) attrs[key2] = node.getAttr(key2);
29682
30382
  }
29683
30383
  const label = `cell_${attrs.field}`;
@@ -29716,7 +30416,7 @@ function validateGridDeclaration(node) {
29716
30416
  function installGridStruct(node, data) {
29717
30417
  const value = structureData(node.staticValue);
29718
30418
  new GridStructure(value);
29719
- const path = `gramlot.grid.${crypto.randomUUID().replaceAll("-", "")}.struct`;
30419
+ const path = `_gramlot.grid.${crypto.randomUUID().replaceAll("-", "")}.struct`;
29720
30420
  data.setItem(path, value, null, ">", false, true, node);
29721
30421
  node.parentNode.setAttr({ structpath: path }, false);
29722
30422
  node.setValue(null, false);
@@ -30975,6 +31675,7 @@ var BindingRuntime = class {
30975
31675
  }
30976
31676
  /** Resolve a tree store against the selected live root. */
30977
31677
  treeStore(node) {
31678
+ if (node.treeStore !== null) return node.treeStore;
30978
31679
  const path = node.getAttr("storepath");
30979
31680
  if (path === "*S" || path.startsWith("*S.")) {
30980
31681
  const root = this.renderer.source.getItem("main");
@@ -31053,7 +31754,11 @@ var BindingRuntime = class {
31053
31754
  const value = bag.node(segment)?.staticValue;
31054
31755
  if (!(value instanceof Bag)) break;
31055
31756
  const store = this.#collectionStores.get(value);
31056
- store?.receiveData(event, index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null);
31757
+ store?.receiveData(
31758
+ event,
31759
+ index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null,
31760
+ event.pathlist[index + 2] ?? null
31761
+ );
31057
31762
  bag = value;
31058
31763
  }
31059
31764
  this.router.deliver(event);
@@ -31408,6 +32113,15 @@ var NodeBinding = class {
31408
32113
  const component = node._getMeta("gramlot_component");
31409
32114
  for (const [capability, attribute] of [["bagStore", "storepath"], ["bagStruct", "structpath"]]) {
31410
32115
  if (!component?.[capability]) continue;
32116
+ if (capability === "bagStore" && node.nodeTag === "tree" && node.treeStore !== null) {
32117
+ const store = node.treeStore;
32118
+ const subscription = `gramlot-tree-${randomId()}`;
32119
+ store.subscribe(subscription, { any: () => {
32120
+ if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
32121
+ } });
32122
+ this.#registrations.push({ close: () => store.unsubscribe(subscription, { any: true }) });
32123
+ continue;
32124
+ }
31411
32125
  const value = node.getAttr(attribute);
31412
32126
  if (typeof value !== "string" || !value || /^[\^=]/.test(value) || value.includes("?")) {
31413
32127
  throw new TypeError(`${attribute} requires a plain Bag data path`);
@@ -31765,6 +32479,7 @@ var DragDrop = class {
31765
32479
  dropEffect: policy.dropEffect,
31766
32480
  dataAvailable: true
31767
32481
  };
32482
+ if (row.placement !== void 0) context.placement = row.placement;
31768
32483
  const accepted = policy.accepted && this.#renderer.checkDropTarget(record2.node, context) && this.#renderer.records.get(record2.node) === record2 && row.element.isConnected;
31769
32484
  return { record: record2, element: row.element, accepted, context };
31770
32485
  }
@@ -31940,26 +32655,26 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
31940
32655
  return this.dragPreparation.prepare(node, event);
31941
32656
  }
31942
32657
  /** Dynamic eligibility only; cannot replace the independent type/tag/effect policy. */
31943
- checkDropTarget(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
32658
+ checkDropTarget(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, placement }) {
31944
32659
  const record2 = this.records.get(node);
31945
32660
  if (!record2) return false;
31946
32661
  if (!record2.resolved.dropTargetCb) return true;
31947
32662
  const allowed = this.html.callLogic(
31948
32663
  node,
31949
32664
  record2.resolved.dropTargetCb,
31950
- { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
32665
+ { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, ...placement === void 0 ? {} : { placement } }
31951
32666
  );
31952
32667
  if (typeof allowed !== "boolean") throw new TypeError("dropTargetCb must return a boolean synchronously");
31953
32668
  return allowed;
31954
32669
  }
31955
32670
  /** Invoke only the general action, after acceptance and removal of data handled by typed actions. */
31956
- async invokeDrop(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
32671
+ async invokeDrop(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, placement }) {
31957
32672
  const record2 = this.records.get(node);
31958
32673
  if (!record2 || !record2.resolved.onDrop || Object.keys(dropValues).length === 0) return;
31959
32674
  await this.html.callLogic(
31960
32675
  node,
31961
32676
  record2.resolved.onDrop,
31962
- { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
32677
+ { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable, ...placement === void 0 ? {} : { placement } }
31963
32678
  );
31964
32679
  }
31965
32680
  /** Notify origin completion independently of application-operation success. */
@@ -32084,6 +32799,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
32084
32799
  ...this.html.create(node, document, tag2, attrs, resolved2.visible ?? null)
32085
32800
  };
32086
32801
  this.html.compose(record2, text3, children);
32802
+ if (record2.labelbox) record2.cleanup.push(() => record2.labelbox.menu?.dispose());
32087
32803
  record2.shape = ControlAdapter.shape(record2.element, resolved2);
32088
32804
  this.records.set(node, record2);
32089
32805
  this.elements.set(record2.element, record2);
@@ -33243,23 +33959,23 @@ var DeviceHandler = class extends Handler {
33243
33959
  }
33244
33960
  installData() {
33245
33961
  const { gramlot } = this;
33246
- gramlot.data.setItem("gramlot.device.database", null, { status: "idle", error: null });
33247
- gramlot.data.setItem("gramlot.device.orientation", null, { status: "idle", error: null, listening: false });
33962
+ gramlot.data.setItem("_gramlot.device.database", null, { status: "idle", error: null });
33963
+ gramlot.data.setItem("_gramlot.device.orientation", null, { status: "idle", error: null, listening: false });
33248
33964
  for (const name of ["gyroscope", "accelerometer"]) {
33249
33965
  gramlot.data.setItem(
33250
- `gramlot.device.${name}`,
33966
+ `_gramlot.device.${name}`,
33251
33967
  null,
33252
33968
  { enabled: false, watching: false, status: "idle", error: null }
33253
33969
  );
33254
- gramlot.data.getNode(`gramlot.device.${name}`).setAttr({ error: null }, false, true, false);
33970
+ gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({ error: null }, false, true, false);
33255
33971
  this.#sensors.set(name, {
33256
- node: gramlot.data.getNode(`gramlot.device.${name}`),
33972
+ node: gramlot.data.getNode(`_gramlot.device.${name}`),
33257
33973
  stream: null,
33258
33974
  cleanup: Promise.resolve()
33259
33975
  });
33260
33976
  }
33261
33977
  for (const name of NAMES) {
33262
- const path = `gramlot.device.${name}`;
33978
+ const path = `_gramlot.device.${name}`;
33263
33979
  const attrs = { status: "idle", error: null, cacheTime: name === "appinfo" ? -1 : 5 };
33264
33980
  if (name === "location") Object.assign(attrs, { enabled: false, watching: false });
33265
33981
  gramlot.data.setItem(path, null);
@@ -33270,54 +33986,54 @@ var DeviceHandler = class extends Handler {
33270
33986
  this.resolvers.set(name, resolver);
33271
33987
  }
33272
33988
  gramlot.data.setItem(
33273
- "gramlot.device.clipboard",
33989
+ "_gramlot.device.clipboard",
33274
33990
  null,
33275
33991
  { status: "idle", error: null, text: "", copy: null, paste: null, operation: null }
33276
33992
  );
33277
- const clipboard = gramlot.data.getNode("gramlot.device.clipboard");
33278
- gramlot.data.setItem("gramlot.device.camera", null, { status: "idle", error: null, capture: null, choose: null });
33279
- const camera = gramlot.data.getNode("gramlot.device.camera");
33280
- gramlot.data.setItem("gramlot.device.barcode", null, { status: "idle", error: null, scan: null });
33281
- const barcode = gramlot.data.getNode("gramlot.device.barcode");
33282
- gramlot.data.setItem("gramlot.device.biometrics", null, { status: "idle", error: null, verify: null });
33283
- const biometrics = gramlot.data.getNode("gramlot.device.biometrics");
33993
+ const clipboard = gramlot.data.getNode("_gramlot.device.clipboard");
33994
+ gramlot.data.setItem("_gramlot.device.camera", null, { status: "idle", error: null, capture: null, choose: null });
33995
+ const camera = gramlot.data.getNode("_gramlot.device.camera");
33996
+ gramlot.data.setItem("_gramlot.device.barcode", null, { status: "idle", error: null, scan: null });
33997
+ const barcode = gramlot.data.getNode("_gramlot.device.barcode");
33998
+ gramlot.data.setItem("_gramlot.device.biometrics", null, { status: "idle", error: null, verify: null });
33999
+ const biometrics = gramlot.data.getNode("_gramlot.device.biometrics");
33284
34000
  const notifications = new Bag();
33285
34001
  notifications.setItem("request", new Bag());
33286
34002
  for (const name of ["scheduled", "received", "action"]) notifications.setItem(name, null);
33287
34003
  gramlot.data.setItem(
33288
- "gramlot.device.notifications",
34004
+ "_gramlot.device.notifications",
33289
34005
  notifications,
33290
34006
  { status: "idle", error: null, schedule: null, listening: false, listenerError: null }
33291
34007
  );
33292
- const notificationNode = gramlot.data.getNode("gramlot.device.notifications");
34008
+ const notificationNode = gramlot.data.getNode("_gramlot.device.notifications");
33293
34009
  const push = new Bag();
33294
34010
  for (const name of ["registration", "received", "action"]) push.setItem(name, null);
33295
34011
  gramlot.data.setItem(
33296
- "gramlot.device.push",
34012
+ "_gramlot.device.push",
33297
34013
  push,
33298
34014
  { status: "idle", error: null, register: null, listening: false, listenerError: null }
33299
34015
  );
33300
- const pushNode = gramlot.data.getNode("gramlot.device.push");
34016
+ const pushNode = gramlot.data.getNode("_gramlot.device.push");
33301
34017
  const links = new Bag();
33302
34018
  links.setItem("request", null);
33303
- gramlot.data.setItem("gramlot.device.links", links, { listening: false, listenerError: null });
34019
+ gramlot.data.setItem("_gramlot.device.links", links, { listening: false, listenerError: null });
33304
34020
  const shortcuts = new Bag();
33305
34021
  shortcuts.setItem("request", null);
33306
- gramlot.data.setItem("gramlot.device.shortcuts", shortcuts, { listening: false, listenerError: null });
33307
- gramlot.data.setItem("gramlot.device.network", null, { status: "idle", error: null, listening: false });
34022
+ gramlot.data.setItem("_gramlot.device.shortcuts", shortcuts, { listening: false, listenerError: null });
34023
+ gramlot.data.setItem("_gramlot.device.network", null, { status: "idle", error: null, listening: false });
33308
34024
  const lifecycle = new Bag();
33309
34025
  lifecycle.setItem("active", null);
33310
34026
  lifecycle.setItem("event", null);
33311
34027
  lifecycle.setItem("sequence", 0);
33312
- gramlot.data.setItem("gramlot.device.lifecycle", lifecycle, { status: "idle", error: null, listening: false });
34028
+ gramlot.data.setItem("_gramlot.device.lifecycle", lifecycle, { status: "idle", error: null, listening: false });
33313
34029
  gramlot.data.setItem(
33314
- "gramlot.device.haptics",
34030
+ "_gramlot.device.haptics",
33315
34031
  null,
33316
34032
  { status: "idle", error: null, impact: null, style: "medium", vibrate: null, duration: 600 }
33317
34033
  );
33318
- const haptics = gramlot.data.getNode("gramlot.device.haptics");
34034
+ const haptics = gramlot.data.getNode("_gramlot.device.haptics");
33319
34035
  gramlot.data.setItem(
33320
- "gramlot.device.audio",
34036
+ "_gramlot.device.audio",
33321
34037
  null,
33322
34038
  {
33323
34039
  status: "idle",
@@ -33332,7 +34048,7 @@ var DeviceHandler = class extends Handler {
33332
34048
  shareActivity: null
33333
34049
  }
33334
34050
  );
33335
- const audio = gramlot.data.getNode("gramlot.device.audio");
34051
+ const audio = gramlot.data.getNode("_gramlot.device.audio");
33336
34052
  gramlot.data.subscribe("gramlot.device", { update: (event) => {
33337
34053
  if (this.disposed) return;
33338
34054
  for (const [name, sensor] of this.#sensors) {
@@ -33428,16 +34144,16 @@ var DeviceHandler = class extends Handler {
33428
34144
  node.setAttr({ status: "success", error: null }, true, true, false);
33429
34145
  });
33430
34146
  if (provider.capabilities.includes("links")) {
33431
- this.#startLinkEvents(this.gramlot.data.getNode("gramlot.device.links"));
34147
+ this.#startLinkEvents(this.gramlot.data.getNode("_gramlot.device.links"));
33432
34148
  }
33433
34149
  if (provider.capabilities.includes("shortcuts")) {
33434
- this.#startShortcutEvents(this.gramlot.data.getNode("gramlot.device.shortcuts"));
34150
+ this.#startShortcutEvents(this.gramlot.data.getNode("_gramlot.device.shortcuts"));
33435
34151
  }
33436
34152
  if (provider.capabilities.includes("push")) {
33437
- this.#startPushEvents(this.gramlot.data.getNode("gramlot.device.push"));
34153
+ this.#startPushEvents(this.gramlot.data.getNode("_gramlot.device.push"));
33438
34154
  }
33439
34155
  if (provider.capabilities.includes("notifications")) {
33440
- this.#startNotificationEvents(this.gramlot.data.getNode("gramlot.device.notifications"));
34156
+ this.#startNotificationEvents(this.gramlot.data.getNode("_gramlot.device.notifications"));
33441
34157
  }
33442
34158
  }
33443
34159
  assertLive() {
@@ -33476,7 +34192,7 @@ var DeviceHandler = class extends Handler {
33476
34192
  }
33477
34193
  // Page-owned state streams share lifetime/error handling, never public dispatch.
33478
34194
  #startStateEvents(name, start, accept) {
33479
- const node = this.gramlot.data.getNode(`gramlot.device.${name}`);
34195
+ const node = this.gramlot.data.getNode(`_gramlot.device.${name}`);
33480
34196
  if (!this.provider.capabilities.includes(name)) {
33481
34197
  node.setAttr(failureAttributes({ code: "UNAVAILABLE", message: `${name} is unavailable` }), true, true, false);
33482
34198
  return;
@@ -34141,7 +34857,7 @@ var DeviceHandler = class extends Handler {
34141
34857
  this.assertLive();
34142
34858
  if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== "string") throw new TypeError("Invalid database name");
34143
34859
  if (this.#database) throw new Error("This page already owns a database connection");
34144
- const node = this.gramlot.data.getNode("gramlot.device.database");
34860
+ const node = this.gramlot.data.getNode("_gramlot.device.database");
34145
34861
  const state = (status, error = null) => {
34146
34862
  if (!this.disposed) node.setAttr({ status, error }, true, true, false);
34147
34863
  };
@@ -34498,6 +35214,10 @@ var Gramlot = class {
34498
35214
  registerDocument(document) {
34499
35215
  for (const collection of this.#collections) collection.register(document.defaultView);
34500
35216
  }
35217
+ /** The prepared collection already activated by this page. */
35218
+ getCollection(name) {
35219
+ return this.#collections.find((collection) => collection.name === name);
35220
+ }
34501
35221
  subscribe(topic, callback) {
34502
35222
  return this._subscriptions.subscribe(topic, callback);
34503
35223
  }
@@ -34658,7 +35378,7 @@ var PageBootstrap = class {
34658
35378
  ...config2,
34659
35379
  document,
34660
35380
  serverAdapter: this.serverAdapter,
34661
- collections: [...config2.collections ?? [], ...collections.map((c) => c.toDocument())]
35381
+ collections: [...config2.collections ?? [], ...collections]
34662
35382
  });
34663
35383
  window2.removeEventListener("pagehide", pagehide);
34664
35384
  for (const collection of collections) collection.registerCommands(app);
@@ -35250,6 +35970,7 @@ var IdeDocuments = class {
35250
35970
  return this.state.getItem("documents");
35251
35971
  }
35252
35972
  async open(root, path) {
35973
+ if (!/\.(?:py|js|mjs|ts|json|html|css|xml|md|markdown|sql|typ|txt|png|jpg|jpeg|webp)$/i.test(path)) return null;
35253
35974
  const key2 = documentKey(root, path);
35254
35975
  const existing = this.documents.getNodes().find((node) => !node.value.getItem("isNew") && node.value.getItem("root") === root && node.value.getItem("path") === path);
35255
35976
  if (existing) return existing.label;
@@ -35258,7 +35979,13 @@ var IdeDocuments = class {
35258
35979
  const promise = this.gramlot.rpc.call("data", "document_read", { root, path }, { signal: request.signal }).then((result) => {
35259
35980
  if (this.disposed || request.signal.aborted) return null;
35260
35981
  const document = new Bag();
35261
- for (const [name, value] of Object.entries({ ...result, root, saved: result.content, busy: false })) document.setItem(name, value);
35982
+ const content = result.language === "image" ? result.content.toTytx() : result.content;
35983
+ for (const [name, value] of Object.entries({ ...result, content, root, saved: content, busy: false })) document.setItem(name, value);
35984
+ if (result.language === "image") {
35985
+ const annotations = result.content;
35986
+ document.setItem("annotations", annotations);
35987
+ annotations.subscribe("ide-annotations", { any: () => document.setItem("content", annotations.toTytx()) });
35988
+ }
35262
35989
  this.documents.setItem(key2, document);
35263
35990
  return key2;
35264
35991
  }).finally(() => this.pending.delete(key2));
@@ -35364,11 +36091,14 @@ var IdeDocuments = class {
35364
36091
  if (!doc || doc.getItem("isNew") || !this.dirty(key2) || !doc.getItem("writable") || this.pending.has(key2)) return false;
35365
36092
  const content = doc.getItem("content"), request = new AbortController();
35366
36093
  doc.setItem("busy", true);
35367
- const promise = this.gramlot.rpc.call("data", "document_save", {
36094
+ const image = doc.getItem("language") === "image";
36095
+ const path = image ? doc.getItem("annotationPath") : doc.getItem("path");
36096
+ const creating = image && doc.getItem("revision") === null;
36097
+ const promise = this.gramlot.rpc.call("data", creating ? "document_create" : "document_save", {
35368
36098
  root: doc.getItem("root"),
35369
- path: doc.getItem("path"),
35370
- content,
35371
- revision: doc.getItem("revision")
36099
+ path,
36100
+ content: image ? Bag.fromTytx(content) : content,
36101
+ ...creating ? {} : { revision: doc.getItem("revision") }
35372
36102
  }, { signal: request.signal }).then((result) => {
35373
36103
  if (this.disposed || request.signal.aborted) return false;
35374
36104
  doc.setItem("revision", result.revision);
@@ -35385,6 +36115,10 @@ var IdeDocuments = class {
35385
36115
  const doc = this.documents.getItem(key2);
35386
36116
  if (!doc || !this.dirty(key2) || this.pending.has(key2)) return false;
35387
36117
  doc.setItem("content", doc.getItem("saved"));
36118
+ if (doc.getItem("language") === "image") {
36119
+ doc.getItem("annotations").replace(Bag.fromTytx(doc.getItem("saved")));
36120
+ doc.setItem("content", doc.getItem("saved"));
36121
+ }
35388
36122
  return true;
35389
36123
  }
35390
36124
  canClose(key2, discard = false) {
@@ -35492,6 +36226,16 @@ var IdeLogic = class {
35492
36226
  const root = state.getItem("workspace");
35493
36227
  if (root && root !== state.getItem("browser.root")) state.setItem("browser.requestedRoot", root);
35494
36228
  }
36229
+ async ideUploadCompleted(node, { result }) {
36230
+ const context = ideContext(node), state = context.scope.getRelativeData(".");
36231
+ if (state.getItem("browser.root") !== result.root) return;
36232
+ state.setItem("upload.open", false);
36233
+ const controller = context.scope.value.getNode("frame.left.browser").fileSystemController;
36234
+ if (controller.request) return;
36235
+ const opened = await controller.open(result.root);
36236
+ if (opened === result.root && !context.documents.disposed && state.getItem("browser.root") === result.root)
36237
+ await this.ideOpenDocument(context.scope, result.root, result.path);
36238
+ }
35495
36239
  ideDocumentState(node, key2) {
35496
36240
  const context = ideContext(node), { documents } = context;
35497
36241
  const doc = documents.documents.getItem(key2);
@@ -35631,59 +36375,63 @@ var IdeLogic = class {
35631
36375
  form.button("Create file", { disabled: "^.busy" }).dataController({ func: "ideCreate", documentKey: key2 });
35632
36376
  form.button("Cancel", { disabled: "^.busy", class: "button--quiet" }).dataController({ func: "ideCancelCreate", documentKey: key2 });
35633
36377
  const editorArea = target.div({ flex: "1", min_height: 0 });
35634
- const html2 = doc.getItem("language") === "html";
35635
- const markdown = doc.getItem("language") === "markdown";
35636
- const rich = html2 || markdown;
35637
- const typst = doc.getItem("language") === "typst";
35638
- const preview = rich || typst || recipe;
35639
- const views = preview ? editorArea.tabContainer({ height: "100%", selectedPage: `^.documents.${key2}.view` }) : null;
35640
- const code = preview ? views.contentPane({ title: "Code", pageName: "code", height: "100%" }) : editorArea;
35641
- codeMirrorWithOptions(code, {
35642
- datapath: `.documents.${key2}`,
35643
- value: "^.content",
35644
- language: doc.getItem("language"),
35645
- height: "100%",
35646
- readonly: "^.readonly",
35647
- nodeId: `${context.editorPrefix}_editor_${key2}`,
35648
- editorView: "code",
35649
- selfsubscribe_historyChanged: "ideHistoryChanged"
35650
- });
35651
- target.dataController({ func: "ideSave", documentKey: key2, [`subscribe_${context.editorPrefix}_editor_${key2}_save`]: true });
35652
- if (typst) views.contentPane({ title: "Preview", pageName: "preview", height: "100%" }).typstPreview({ value: `^.documents.${key2}.content`, filename: `^.documents.${key2}.pdfFilename`, height: "100%" });
35653
- if (recipe) {
35654
- const output = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
35655
- output.div(`^.documents.${key2}.renderStatus`, { role: "status", padding: "8px 12px", white_space: "pre-wrap", overflow: "auto", max_height: "30%" });
35656
- output.typstPreview({
35657
- value: `^.documents.${key2}.typstSource`,
35658
- filename: `^.documents.${key2}.pdfFilename`,
35659
- hidden: `^.documents.${key2}.previewHidden`,
35660
- flex: "1",
35661
- min_height: 0
35662
- });
35663
- views.contentPane({ title: "Generated Typst", pageName: "generated", height: "100%" }).codeMirror({ value: `^.documents.${key2}.typstSource`, language: "typst", readonly: true, height: "100%" });
35664
- }
35665
- if (rich) {
35666
- const previewPane = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
35667
- if (markdown) {
35668
- doc.setItem("allowHtml", false);
35669
- previewPane.checkbox({ value: `^.documents.${key2}.allowHtml`, label: "Allow embedded HTML", class: "gramlot-ide-allow-html", padding: "8px 12px", flex_shrink: 0 });
35670
- }
35671
- previewPane[html2 ? "htmlPreview" : "markdownPreview"]({
35672
- value: `^.documents.${key2}.content`,
35673
- flex: "1",
35674
- min_height: 0,
35675
- ...markdown ? { allowHtml: `^.documents.${key2}.allowHtml` } : {}
35676
- });
35677
- views.contentPane({ title: "Rich text", pageName: "rich", height: "100%" })[html2 ? "htmlEditor" : "markdownEditor"]({
36378
+ if (doc.getItem("language") === "image") {
36379
+ editorArea.drawingPane({ image: `^.documents.${key2}.image`, annotations: `^.documents.${key2}.annotations`, height: "100%" });
36380
+ } else {
36381
+ const html2 = doc.getItem("language") === "html";
36382
+ const markdown = doc.getItem("language") === "markdown";
36383
+ const rich = html2 || markdown;
36384
+ const typst = doc.getItem("language") === "typst";
36385
+ const preview = rich || typst || recipe;
36386
+ const views = preview ? editorArea.tabContainer({ height: "100%", selectedPage: `^.documents.${key2}.view` }) : null;
36387
+ const code = preview ? views.contentPane({ title: "Code", pageName: "code", height: "100%" }) : editorArea;
36388
+ codeMirrorWithOptions(code, {
35678
36389
  datapath: `.documents.${key2}`,
35679
36390
  value: "^.content",
35680
- readonly: "^.readonly",
36391
+ language: doc.getItem("language"),
35681
36392
  height: "100%",
35682
- nodeId: `${context.editorPrefix}_rich_editor_${key2}`,
35683
- editorView: "rich",
36393
+ readonly: "^.readonly",
36394
+ nodeId: `${context.editorPrefix}_editor_${key2}`,
36395
+ editorView: "code",
35684
36396
  selfsubscribe_historyChanged: "ideHistoryChanged"
35685
36397
  });
35686
- target.dataController({ func: "ideSave", documentKey: key2, [`subscribe_${context.editorPrefix}_rich_editor_${key2}_save`]: true });
36398
+ target.dataController({ func: "ideSave", documentKey: key2, [`subscribe_${context.editorPrefix}_editor_${key2}_save`]: true });
36399
+ if (typst) views.contentPane({ title: "Preview", pageName: "preview", height: "100%" }).typstPreview({ value: `^.documents.${key2}.content`, filename: `^.documents.${key2}.pdfFilename`, height: "100%" });
36400
+ if (recipe) {
36401
+ const output = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
36402
+ output.div(`^.documents.${key2}.renderStatus`, { role: "status", padding: "8px 12px", white_space: "pre-wrap", overflow: "auto", max_height: "30%" });
36403
+ output.typstPreview({
36404
+ value: `^.documents.${key2}.typstSource`,
36405
+ filename: `^.documents.${key2}.pdfFilename`,
36406
+ hidden: `^.documents.${key2}.previewHidden`,
36407
+ flex: "1",
36408
+ min_height: 0
36409
+ });
36410
+ views.contentPane({ title: "Generated Typst", pageName: "generated", height: "100%" }).codeMirror({ value: `^.documents.${key2}.typstSource`, language: "typst", readonly: true, height: "100%" });
36411
+ }
36412
+ if (rich) {
36413
+ const previewPane = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
36414
+ if (markdown) {
36415
+ doc.setItem("allowHtml", false);
36416
+ previewPane.checkbox({ value: `^.documents.${key2}.allowHtml`, label: "Allow embedded HTML", class: "gramlot-ide-allow-html", padding: "8px 12px", flex_shrink: 0 });
36417
+ }
36418
+ previewPane[html2 ? "htmlPreview" : "markdownPreview"]({
36419
+ value: `^.documents.${key2}.content`,
36420
+ flex: "1",
36421
+ min_height: 0,
36422
+ ...markdown ? { allowHtml: `^.documents.${key2}.allowHtml` } : {}
36423
+ });
36424
+ views.contentPane({ title: "Rich text", pageName: "rich", height: "100%" })[html2 ? "htmlEditor" : "markdownEditor"]({
36425
+ datapath: `.documents.${key2}`,
36426
+ value: "^.content",
36427
+ readonly: "^.readonly",
36428
+ height: "100%",
36429
+ nodeId: `${context.editorPrefix}_rich_editor_${key2}`,
36430
+ editorView: "rich",
36431
+ selfsubscribe_historyChanged: "ideHistoryChanged"
36432
+ });
36433
+ target.dataController({ func: "ideSave", documentKey: key2, [`subscribe_${context.editorPrefix}_rich_editor_${key2}_save`]: true });
36434
+ }
35687
36435
  }
35688
36436
  }
35689
36437
  }
@@ -36059,11 +36807,11 @@ var VisualEditor = class {
36059
36807
  pane.dataController({ func: "initializeEditorAppearance", _onBuilt: true });
36060
36808
  pane.dataController({ func: "applyEditorAppearance", profile: "^.appearanceProfile", palette: "^.appearancePalette", mode: "^.appearanceMode" });
36061
36809
  const rail = this.rail = pane.menu({ presentation: "bar", orientation: "vertical", aria_label: "Editor panels", class: "visual-editor-rail" });
36062
- this.toolButton(rail.menuline({ group: true, overflowable: false }), "Source / Data", "toggleNavigation", toolIcons.navigation);
36063
- this.toolButton(rail.menuline({ group: true, overflowable: false }), "Catalogue", "openCatalogue", toolIcons.catalogue);
36064
- this.toolButton(rail.menuline({ group: true, overflowable: false }), "Properties", "openProperties", toolIcons.properties);
36810
+ this.toolButton(rail.menuline({ group: true }), "Source / Data", "toggleNavigation", toolIcons.navigation);
36811
+ this.toolButton(rail.menuline({ group: true }), "Catalogue", "openCatalogue", toolIcons.catalogue);
36812
+ this.toolButton(rail.menuline({ group: true }), "Properties", "openProperties", toolIcons.properties);
36065
36813
  this.toolButton(
36066
- rail.menuline({ group: true, overflowable: false }),
36814
+ rail.menuline({ group: true }),
36067
36815
  "Clipboard",
36068
36816
  "this.SET('.clipboardVisible', !this.GET('.clipboardVisible'))",
36069
36817
  toolIcons.paste,
@@ -36078,23 +36826,23 @@ var VisualEditor = class {
36078
36826
  }
36079
36827
  );
36080
36828
  rail.spacer({ flex: 1 });
36081
- this.toolButton(rail.menuline({ group: true, overflowable: false }), "Appearance", "this.SET('.appearanceOpen', !this.GET('.appearanceOpen'))", toolIcons.appearance);
36829
+ this.toolButton(rail.menuline({ group: true }), "Appearance", "this.SET('.appearanceOpen', !this.GET('.appearanceOpen'))", toolIcons.appearance);
36082
36830
  const layoutRoot = pane.framePane({ node_label: "layout", height: "100%", id: `${editorId}-editor-frame`, class: "visual-editor-layout" });
36083
36831
  layoutRoot.top.setAttr({ height: "30px" });
36084
36832
  const toolbar = layoutRoot.top.menu({ presentation: "bar", aria_label: "Editor tools", class: "visual-editor-toolbar" });
36085
- toolbar.menuline({ group: true, overflowable: false }).span("Source editor", { class: "visual-editor-brand" });
36086
- const files = toolbar.menuline({ group: true, overflowable: false, gap: "4px", hidden: !fileCommands });
36833
+ toolbar.menuline({ group: true }).span("Source editor", { class: "visual-editor-brand" });
36834
+ const files = toolbar.menuline({ group: true, gap: "4px", hidden: !fileCommands });
36087
36835
  for (const [caption, action, icon] of [["New", "newPage", "new"], ["Open", "openUpload", "open"], ["Download", "downloadPage", "download"], ["Copy Source", "copySource", "copy"]])
36088
36836
  this.toolButton(files, caption, action, toolIcons[icon], { id: `${editorId}-${icon}` });
36089
- toolbar.menuline({ group: true, overflowable: false }).span({ class: "visual-toolbar-divider", aria_hidden: "true" });
36090
- const edit = toolbar.menuline({ group: true, overflowable: false, gap: "2px" });
36837
+ toolbar.menuline({ group: true }).span({ class: "visual-toolbar-divider", aria_hidden: "true" });
36838
+ const edit = toolbar.menuline({ group: true, gap: "2px" });
36091
36839
  this.toolButton(edit, "Cut branch", "cutBranch", toolIcons.cut, { title: "Cut branch (F8)" });
36092
36840
  this.toolButton(edit, "Copy branch", "copyBranch", toolIcons.copy);
36093
36841
  this.toolButton(edit, "Paste branch", "pasteBranch", toolIcons.paste, { title: "Paste branch (F9)" });
36094
36842
  toolbar.spacer({ flex: 1 });
36095
- toolbar.menuline({ group: true, overflowable: false, hidden: "^.modified:=!{}" }).span("Unsaved changes", { role: "status", class: "visual-editor-hint" });
36096
- toolbar.menuline({ group: true, overflowable: false }).span("^.fileStatus", { role: "status", class: "visual-editor-file-status" });
36097
- toolbar.menuline({ group: true, overflowable: false }).span("^.filename", { class: "visual-editor-filename" });
36843
+ toolbar.menuline({ group: true, hidden: "^.modified:=!{}" }).span("Unsaved changes", { role: "status", class: "visual-editor-hint" });
36844
+ toolbar.menuline({ group: true }).span("^.fileStatus", { role: "status", class: "visual-editor-file-status" });
36845
+ toolbar.menuline({ group: true }).span("^.filename", { class: "visual-editor-filename" });
36098
36846
  const left = layoutRoot.left;
36099
36847
  left.setAttr({
36100
36848
  width: "min(240px, 34vw)",
@@ -36231,7 +36979,7 @@ var VisualEditor = class {
36231
36979
  naming.frame.center.p("^.error", { role: "alert", margin: "12px" });
36232
36980
  const namingBar = naming.frame.bottom.menu({ presentation: "bar", aria_label: "Clipboard commands", padding: "3px 6px" });
36233
36981
  namingBar.spacer({ flex: 1 });
36234
- const namingButtons = namingBar.menuline({ group: true, overflowable: false, gap: "8px" });
36982
+ const namingButtons = namingBar.menuline({ group: true, gap: "8px" });
36235
36983
  namingButtons.button("Cancel", { action: "this.SET('.clipboardOpen', false)" });
36236
36984
  namingButtons.button("Save branch", { action: "saveClipboard" });
36237
36985
  const dialog = pane.dialog({ class: "visual-editor-popup", title: "Required parameters", open: "^.insertionOpen", width: "400px", height: "280px", movable: true, resizable: true });
@@ -36239,7 +36987,7 @@ var VisualEditor = class {
36239
36987
  dialog.frame.center.p("^.error", { role: "alert" });
36240
36988
  const bar = dialog.frame.bottom.menu({ presentation: "bar", aria_label: "Insertion commands", padding: "3px 6px", border_top: "1px solid var(--gramlot-border)" });
36241
36989
  bar.spacer({ flex: 1 });
36242
- const buttons = bar.menuline({ group: true, overflowable: false, gap: "8px" });
36990
+ const buttons = bar.menuline({ group: true, gap: "8px" });
36243
36991
  buttons.button("Cancel", { action: "this.SET('.insertionOpen', false)" });
36244
36992
  buttons.button("Insert", { action: "insertWidget" });
36245
36993
  const settings = pane.floatingPane({ class: "visual-editor-popup", title: "Appearance", open: "^.appearanceOpen", default_open: false, width: "280px", height: "260px", movable: true, resizable: true });
@@ -36265,7 +37013,7 @@ var VisualEditor = class {
36265
37013
  pane.dataSetter({ destination_path: ".codeDocument", value: new Bag({ ...document, saved: document.content, busy: false, status: "" }) });
36266
37014
  const anchor = `#${pane.getAttr("visualEditorId")}Editor`;
36267
37015
  const opener = frame === this.frame ? this.toolbar : frame.top.menu({ presentation: "bar", aria_label: "Code drawer" });
36268
- opener.menuline({ group: true, overflowable: false }).button("Code", { action: "openCode", class: "button--quiet" });
37016
+ opener.menuline({ group: true }).button("Code", { action: "openCode", class: "button--quiet" });
36269
37017
  const drawer = frame.right;
36270
37018
  drawer.setAttr({
36271
37019
  class: "visual-editor-code",
@@ -36292,7 +37040,7 @@ var VisualEditor = class {
36292
37040
  code.bottom.div("^.codeDocument.status", { role: "status", font_size: "12px", padding: "4px 10px" });
36293
37041
  const bar = code.bottom.menu({ presentation: "bar", aria_label: "Page code commands", padding: "3px 6px" });
36294
37042
  bar.spacer({ flex: 1 });
36295
- const commands = bar.menuline({ group: true, overflowable: false, gap: "6px" });
37043
+ const commands = bar.menuline({ group: true, gap: "6px" });
36296
37044
  commands.button("Close", { action: "this.SET('.codeOpen', 'close')" });
36297
37045
  commands.button("Preview saved", { action: "codePreview", disabled: "^.codeDocument.busy" });
36298
37046
  commands.button("Save", { action: "codeSave", disabled: "^.codeSaveDisabled" });
@@ -36308,7 +37056,7 @@ var VisualEditor = class {
36308
37056
  }
36309
37057
  search(pane, path, label) {
36310
37058
  const bar = pane.menu({ presentation: "bar", aria_label: label, class: "visual-search-toolbar" });
36311
- const field = bar.menuline({ group: true, overflowable: false, flex: 1, min_width: 0 }).div({ class: "visual-search-field" });
37059
+ const field = bar.menuline({ group: true, flex: 1, min_width: 0 }).div({ class: "visual-search-field" });
36312
37060
  field.span({ class: "visual-search-icon", aria_hidden: "true" });
36313
37061
  field.input({ type: "search", value: `^.${path}`, default: "", live: true, placeholder: label, aria_label: label });
36314
37062
  field.html_button({
@@ -38499,7 +39247,8 @@ function Labelbox(Base) {
38499
39247
  }
38500
39248
  projectAttributes(attrs, adapt) {
38501
39249
  const rest = super.projectAttributes(attrs, adapt);
38502
- const label = this.parameters.lbl ?? "";
39250
+ const { lbl, lbl_value, lbl_values } = this.parameters;
39251
+ const label = lbl_values == null ? lbl ?? "" : choiceCaption(parseChoices(lbl_values), lbl_value, lbl);
38503
39252
  if (label) this.control.setAttribute("aria-label", label);
38504
39253
  else this.control.removeAttribute("aria-label");
38505
39254
  return rest;
@@ -38509,6 +39258,8 @@ function Labelbox(Base) {
38509
39258
  Labelbox.labelbox = true;
38510
39259
  Labelbox.parameters = {
38511
39260
  lbl: { dtype: "T", qualification: "intl_str", nullable: true, binding: "read" },
39261
+ lbl_value: { dtype: "T", nullable: true, binding: "twoWay" },
39262
+ lbl_values: { dtype: "T", nullable: true, binding: "read" },
38512
39263
  lbl_position: { dtype: "T", default: "TL", binding: "read", enum: labelboxPositions }
38513
39264
  };
38514
39265