@gramlot/gramlot 0.3.32 → 0.3.34

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 (129) hide show
  1. package/dist/components/audio/__init__.py +1 -1
  2. package/dist/components/audio/assets/collection.js +2 -2
  3. package/dist/components/audio/assets/index.js +1 -1
  4. package/dist/components/charts/__init__.py +2 -2
  5. package/dist/components/charts/assets/collection.js +24 -43
  6. package/dist/components/charts/assets/index.js +1 -1
  7. package/dist/components/charts/assets/modules/chunk-USZCUBTC.js +1 -0
  8. package/dist/components/charts/assets/modules/echarts-gl.min-N6L67H2M.js +4282 -0
  9. package/dist/components/charts/assets/modules/echarts.esm.min-VHLRZDVQ.js +61 -0
  10. package/dist/components/charts/assets/modules/{plotly.min-4LB7HE7P.js → plotly.min-SSDU2DOH.js} +1 -1
  11. package/dist/components/charts/assets/modules/{uPlot.esm-5JJNHHRF.js → uPlot.esm-Q2UYUQHJ.js} +1 -1
  12. package/dist/components/charts/assets/modules/{uPlot.min-N3E3FA74.js → uPlot.min-XXHNQFXH.js} +1 -1
  13. package/dist/components/charts/assets/modules/{vega.module-2QCOVQ3A.js → vega.module-Y5CWNSZO.js} +1 -1
  14. package/dist/components/charts/grammar.json +15482 -232
  15. package/dist/components/chat/__init__.py +1 -1
  16. package/dist/components/chat/assets/collection.js +3 -3
  17. package/dist/components/chat/assets/index.js +1 -1
  18. package/dist/components/drawing/__init__.py +1 -1
  19. package/dist/components/drawing/assets/collection.js +3 -24
  20. package/dist/components/drawing/assets/index.js +1 -1
  21. package/dist/components/editors/__init__.py +2 -2
  22. package/dist/components/editors/assets/collection.js +2 -47
  23. package/dist/components/editors/assets/index.js +1 -1
  24. package/dist/components/editors/assets/modules/{jodit-engine-MTSA4GZ3.js → jodit-engine-CXRSFV47.js} +6 -6
  25. package/dist/components/grid/__init__.py +2 -2
  26. package/dist/components/grid/assets/collection.js +6 -28
  27. package/dist/components/grid/assets/index.js +1 -1
  28. package/dist/components/grid/assets/modules/{browser-LVJHKBBV.js → browser-Y2BRNI3P.js} +1 -1
  29. package/dist/components/grid/assets/modules/chunk-BLMUM44K.js +1 -0
  30. package/dist/components/grouplets/__init__.py +1 -1
  31. package/dist/components/grouplets/assets/collection.js +3 -3
  32. package/dist/components/grouplets/assets/index.js +1 -1
  33. package/dist/components/inputs/__init__.py +1 -1
  34. package/dist/components/inputs/assets/collection.js +8 -65
  35. package/dist/components/inputs/assets/index.js +1 -1
  36. package/dist/components/layout/__init__.py +1 -1
  37. package/dist/components/layout/assets/collection.js +9 -30
  38. package/dist/components/layout/assets/index.js +1 -1
  39. package/dist/components/selection_trial/__init__.py +1 -1
  40. package/dist/components/selection_trial/assets/collection.js +3 -3
  41. package/dist/components/selection_trial/assets/index.js +1 -1
  42. package/dist/components/tree/__init__.py +1 -1
  43. package/dist/components/tree/assets/collection.js +6 -27
  44. package/dist/components/tree/assets/index.js +1 -1
  45. package/dist/components/typst/__init__.py +1 -1
  46. package/dist/components/typst/assets/collection.js +3 -3
  47. package/dist/components/typst/assets/index.js +1 -1
  48. package/dist/components/uploads/__init__.py +1 -1
  49. package/dist/components/uploads/assets/collection.js +3 -30
  50. package/dist/components/uploads/assets/index.js +1 -1
  51. package/dist/components/vizabi/__init__.py +1 -1
  52. package/dist/components/vizabi/assets/collection.js +3 -21
  53. package/dist/components/vizabi/assets/index.js +1 -1
  54. package/dist/gramlot.js +1599 -59
  55. package/dist/gramlot.min.js +49 -48
  56. package/dist/libraries.json +126 -0
  57. package/dist/runtime-notices.json +4 -0
  58. package/dist/standard-collections.js +1 -1
  59. package/package.json +2 -2
  60. package/src/components/chart-boxplot-options.js +22 -0
  61. package/src/components/chart-candlestick-options.js +27 -0
  62. package/src/components/chart-controls.js +28 -6
  63. package/src/components/chart-domains.js +1 -1
  64. package/src/components/chart-engines/echarts.js +28 -4
  65. package/src/components/chart-engines/plotly.js +3 -2
  66. package/src/components/chart-engines/uplot.js +5 -3
  67. package/src/components/chart-engines/vega.js +2 -1
  68. package/src/components/chart-fields.js +11 -1
  69. package/src/components/chart-funnel-options.js +19 -0
  70. package/src/components/chart-gauge-options.js +98 -0
  71. package/src/components/chart-gauge.js +109 -0
  72. package/src/components/chart-heatmap-options.js +29 -0
  73. package/src/components/chart-notice.js +126 -0
  74. package/src/components/chart-pane.js +7 -1
  75. package/src/components/chart-parallel-options.js +24 -0
  76. package/src/components/chart-radar-options.js +29 -0
  77. package/src/components/chart-renderer.js +3 -9
  78. package/src/components/chart-sankey-options.js +43 -0
  79. package/src/components/chart-sunburst-options.js +12 -0
  80. package/src/components/chart-syntax.js +82 -0
  81. package/src/components/chart-time.js +2 -1
  82. package/src/components/chart-treemap-options.js +16 -0
  83. package/src/components/chart-type-data.js +62 -0
  84. package/src/components/chart-types/area.js +6 -1
  85. package/src/components/chart-types/bar.js +6 -1
  86. package/src/components/chart-types/bar3D.js +7 -1
  87. package/src/components/chart-types/boxplot.js +11 -0
  88. package/src/components/chart-types/candlestick.js +10 -0
  89. package/src/components/chart-types/donut.js +6 -1
  90. package/src/components/chart-types/funnel.js +7 -0
  91. package/src/components/chart-types/heatmap.js +8 -0
  92. package/src/components/chart-types/horizontalBar.js +6 -1
  93. package/src/components/chart-types/index.js +21 -1
  94. package/src/components/chart-types/line.js +6 -1
  95. package/src/components/chart-types/line3D.js +7 -1
  96. package/src/components/chart-types/lines3D.js +7 -1
  97. package/src/components/chart-types/map.js +7 -1
  98. package/src/components/chart-types/map3D.js +6 -1
  99. package/src/components/chart-types/mapBar3D.js +6 -1
  100. package/src/components/chart-types/parallel.js +7 -0
  101. package/src/components/chart-types/pie.js +6 -1
  102. package/src/components/chart-types/polygons3D.js +7 -1
  103. package/src/components/chart-types/radar.js +7 -0
  104. package/src/components/chart-types/sankey.js +8 -0
  105. package/src/components/chart-types/scatter.js +6 -1
  106. package/src/components/chart-types/scatter3D.js +7 -1
  107. package/src/components/chart-types/stackedArea.js +6 -1
  108. package/src/components/chart-types/stackedBar.js +6 -1
  109. package/src/components/chart-types/sunburst.js +7 -0
  110. package/src/components/chart-types/surface.js +7 -1
  111. package/src/components/chart-types/treemap.js +7 -0
  112. package/src/components/charts.js +60 -13
  113. package/src/components/code-mirror.js +2 -1
  114. package/src/components/grid-tools.js +2 -1
  115. package/src/components/html-editor.js +2 -1
  116. package/src/components/markdown-editor.js +2 -1
  117. package/src/components/registry.js +9 -5
  118. package/src/components/typst-preview.js +2 -1
  119. package/src/index.d.ts +16 -0
  120. package/src/index.js +5 -0
  121. package/src/libraries.js +83 -0
  122. package/src/page-store-connection.js +15 -5
  123. package/src/server/gramlot-server.d.ts +8 -0
  124. package/src/server/gramlot-server.js +40 -4
  125. package/src/shared-modules.js +79 -0
  126. package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +0 -76
  127. package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +0 -1
  128. package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +0 -4409
  129. package/dist/components/grid/assets/modules/chunk-RMRBEYTI.js +0 -1
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent 3d lines configuration. */
2
- export default {id:'line3D',label:'3D lines',controls:['category','secondDimension','measures'],threeD:true,measureLimit:null};
2
+ export default {id:'line3D',label:'3D lines',controls:[],threeD:true,
3
+ doc:'Shows values along two dimensions as lines in 3D space.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'First dimension',doc:'The first axis.'},
6
+ {name:'secondCaptionField',parameter:'secondCaptionField',count:1,required:true,dtype:null,caption:'Second dimension',doc:'The second axis; it must differ from the first.'},
7
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one series of heights on the grid of the two dimensions.'}
8
+ ]};
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent 3d paths configuration. */
2
- export default {id:'lines3D',label:'3D paths',controls:["category", "geoJSON", "geometry", "measures"],threeD:true,measureLimit:null};
2
+ export default {id:'lines3D',label:'3D paths',controls:['geoJSON'],threeD:true,
3
+ doc:'Draws paths of coordinates on a 3D map.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Path',doc:'The name of each path.'},
6
+ {name:'geometryField',parameter:'geometryField',count:1,required:true,dtype:null,caption:'Coordinates',doc:'A list of at least two longitude/latitude/altitude coordinates per row.'},
7
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one set of paths; values must not be negative.'}
8
+ ]};
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent 2d map configuration. */
2
- export default {id:'map',label:'2D map',controls:['category','geoJSON','mapMeasure'],threeD:false,measureLimit:null};
2
+ export default {id:'map',label:'2D map',controls:['geoJSON'],threeD:false,
3
+ doc:'Colours each territory of a GeoJSON map by one measure.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Territory',doc:'Matched to GeoJSON properties.name; one row per territory.'},
6
+ {name:'mapValueField',parameter:'mapValueField',count:1,required:true,dtype:'numeric',caption:'Map measure',doc:'The value that colours each territory.'},
7
+ {name:'mapLabelField',parameter:'mapLabelField',count:1,required:false,dtype:null,caption:'Map label',doc:'Text or number shown on each territory.'}
8
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Engine-independent 3d map configuration. */
2
- export default {id:'map3D',label:'3D map',controls:["category", "geoJSON", "measures"],threeD:true,measureLimit:null};
2
+ export default {id:'map3D',label:'3D map',controls:['geoJSON'],threeD:true,
3
+ doc:'Draws the territories of a GeoJSON map in 3D, one map per measure.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Territory',doc:'Matched to GeoJSON properties.name.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one map; values must not be negative.'}
7
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Columns at territory display anchors; each selected measure has its own color. */
2
- export default {id:'mapBar3D',label:'3D bars on map',controls:['category','geoJSON','mapBarScale','measures'],threeD:true,measureLimit:null};
2
+ export default {id:'mapBar3D',label:'3D bars on map',controls:['geoJSON','mapBarScale'],threeD:true,
3
+ doc:'Raises 3D columns on the territories of a GeoJSON map.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Territory',doc:'Matched to GeoJSON properties.name; one row per territory.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one column per territory; values must not be negative.'}
7
+ ]};
@@ -0,0 +1,7 @@
1
+ /** Engine-independent parallel coordinates configuration: each measure is an axis, each row a polyline. */
2
+ export default {id:'parallel',label:'Parallel coordinates',controls:[],threeD:false,domains:false,
3
+ doc:'Compares rows on several measures; each measure is a vertical axis, each row a line across them.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Item',doc:'One line per row.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one axis.'}
7
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Engine-independent pie configuration. */
2
- export default {id:'pie',label:'Pie',controls:['category','measures'],threeD:false,measureLimit:1};
2
+ export default {id:'pie',label:'Pie',controls:[],threeD:false,
3
+ doc:'Shows the share of each category in a total.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Slice',doc:'One slice per row, named by this column.'},
6
+ {name:'measure',parameter:'valueFields',count:1,required:true,dtype:'numeric',caption:'Measure',doc:'The size of each slice; values must not be negative.'}
7
+ ]};
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent 3d polygons configuration. */
2
- export default {id:'polygons3D',label:'3D polygons',controls:["category", "geometry", "measures"],threeD:true,measureLimit:null};
2
+ export default {id:'polygons3D',label:'3D polygons',controls:[],threeD:true,
3
+ doc:'Draws polygons of coordinates as 3D shapes.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Polygon',doc:'The unique name of each polygon.'},
6
+ {name:'geometryField',parameter:'geometryField',count:1,required:true,dtype:null,caption:'Coordinates',doc:'Closed coordinate rings per row, including any holes.'},
7
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one set of polygons; values must not be negative.'}
8
+ ]};
@@ -0,0 +1,7 @@
1
+ /** Engine-independent radar configuration: each measure is an axis, each row a polygon. */
2
+ export default {id:'radar',label:'Radar',controls:[],threeD:false,domains:false,
3
+ doc:'Compares items on several measures; each measure is an axis, each row a polygon.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Item',doc:'One polygon per row; a row with any empty measure is left out.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one axis of the radar.'}
7
+ ]};
@@ -0,0 +1,8 @@
1
+ /** Engine-independent sankey configuration: source, target and one measure as link value. */
2
+ export default {id:'sankey',label:'Sankey',controls:[],threeD:false,domains:false,
3
+ doc:'Shows flows between nodes; the width of each link is its value.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Source',doc:'The node a link starts from.'},
6
+ {name:'secondCaptionField',parameter:'secondCaptionField',count:1,required:true,dtype:null,caption:'Target',doc:'The node a link ends at; it must differ from the source column, and links must not form a cycle.'},
7
+ {name:'measure',parameter:'valueFields',count:1,required:true,dtype:'numeric',caption:'Measure',doc:'The width of each link; values must not be negative.'}
8
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Engine-independent scatter configuration. */
2
- export default {id:'scatter',label:'Scatter',controls:['category','measures'],threeD:false,measureLimit:null};
2
+ export default {id:'scatter',label:'Scatter',controls:[],threeD:false,
3
+ doc:'Shows each row as a point, to reveal relations and clusters.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Category',doc:'The horizontal position of each point.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one series of points, at its height.'}
7
+ ]};
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent 3d scatter configuration. */
2
- export default {id:'scatter3D',label:'3D scatter',controls:['category','secondDimension','measures'],threeD:true,measureLimit:null};
2
+ export default {id:'scatter3D',label:'3D scatter',controls:[],threeD:true,
3
+ doc:'Shows each row as a point in 3D space.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'First dimension',doc:'The first axis; numeric or date values.'},
6
+ {name:'secondCaptionField',parameter:'secondCaptionField',count:1,required:true,dtype:null,caption:'Second dimension',doc:'The second axis; numeric or date values.'},
7
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one series of points, at its height.'}
8
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Engine-independent stacked area configuration. */
2
- export default {id:'stackedArea',label:'Stacked area',controls:['category','measures'],threeD:false,measureLimit:null};
2
+ export default {id:'stackedArea',label:'Stacked area',controls:[],threeD:false,
3
+ doc:'Shows the parts of a total along an ordered category, with the areas stacked.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Category',doc:'The horizontal axis, in row order or time order.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one stacked layer.'}
7
+ ]};
@@ -1,2 +1,7 @@
1
1
  /** Engine-independent stacked bars configuration. */
2
- export default {id:'stackedBar',label:'Stacked bars',controls:['category','measures'],threeD:false,measureLimit:null};
2
+ export default {id:'stackedBar',label:'Stacked bars',controls:[],threeD:false,
3
+ doc:'Shows the parts of a total for each category, with the measures stacked in one bar.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Category',doc:'One bar per value of this column.'},
6
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one segment of the bar.'}
7
+ ]};
@@ -0,0 +1,7 @@
1
+ /** Engine-independent sunburst configuration: nested Bag, one measure carried by the leaves. */
2
+ export default {id:'sunburst',label:'Sunburst',controls:[],threeD:false,domains:false,
3
+ doc:'Shows a hierarchy as rings; the angle of each sector is the value.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Label',doc:'The attribute that names each node of the nested Bag.'},
6
+ {name:'measure',parameter:'valueFields',count:1,required:true,dtype:'numeric',caption:'Measure',doc:'Carried by the leaves; a parent is the sum of its children. Values must not be negative.'}
7
+ ]};
@@ -1,2 +1,8 @@
1
1
  /** Engine-independent surface configuration. */
2
- export default {id:'surface',label:'Surface',controls:['category','secondDimension','measures'],threeD:true,measureLimit:null};
2
+ export default {id:'surface',label:'Surface',controls:[],threeD:true,
3
+ doc:'Shows a measured surface over a grid of two numeric dimensions.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'First dimension',doc:'The first axis; numeric or date values, at least two distinct.'},
6
+ {name:'secondCaptionField',parameter:'secondCaptionField',count:1,required:true,dtype:null,caption:'Second dimension',doc:'The second axis; numeric or date values, at least two distinct.'},
7
+ {name:'measures',parameter:'valueFields',count:'many',required:true,dtype:'numeric',caption:'Measures',doc:'Each measure is one surface; each coordinate pair appears once.'}
8
+ ]};
@@ -0,0 +1,7 @@
1
+ /** Engine-independent treemap configuration: nested Bag, one measure carried by the leaves. */
2
+ export default {id:'treemap',label:'Treemap',controls:[],threeD:false,domains:false,
3
+ doc:'Shows a hierarchy as nested rectangles whose area is the value.',
4
+ syntax:[
5
+ {name:'captionField',parameter:'captionField',count:1,required:true,dtype:null,caption:'Label',doc:'The attribute that names each node of the nested Bag.'},
6
+ {name:'measure',parameter:'valueFields',count:1,required:true,dtype:'numeric',caption:'Measure',doc:'Carried by the leaves; a parent is the sum of its children. Values must not be negative.'}
7
+ ]};
@@ -10,26 +10,27 @@ import {ChartDataView} from './chart-data-view.js';
10
10
  import {ChartGeoJSON} from './chart-geojson.js';
11
11
  import {ChartFields} from './chart-fields.js';
12
12
  import {ChartRenderer} from './chart-renderer.js';
13
+ import {Gauge} from './chart-gauge.js';
14
+ import {ChartNotice,CHART_NOTICE_STYLE,chartErrorSections,chartTypeSections} from './chart-notice.js';
15
+ import {ChartSyntaxError} from './chart-syntax.js';
16
+ import {chartTypes} from './chart-types/index.js';
13
17
 
14
18
  const ChartView = defineComponent({
15
19
  name:'chartView', tag:'gramlot-chart-view', base:Container, sourceContext:true, bagStore:true,
16
20
  parameters:{sampleMin:{dtype:'R',nullable:true,binding:'read'},sampleMax:{dtype:'R',nullable:true,binding:'read'},sampleStep:{dtype:'R',default:1,binding:'read'},sampleStart:{dtype:'R',default:0,binding:'read'},mapLabelMode:{dtype:'T',default:'value',binding:'read'},mapBarScale:{dtype:'T',default:'zero',binding:'read'},selectedTerritory:{dtype:'T',default:'',binding:'twoWay'},configpath:{dtype:'T'},timeEmpty:{dtype:'T',default:'previous',binding:'read'},timeField:{dtype:'T',default:'',binding:'read'},timeValue:{dtype:'X',nullable:true,binding:'read'},timeStep:{dtype:'T',default:'month',binding:'read'},engine:{dtype:'T',default:'echarts',binding:'read'},mapValueField:{dtype:'T',binding:'read'},mapLabelField:{dtype:'T',binding:'read'},geoJSON:{dtype:'X',nullable:true,binding:'read'},geometryField:{dtype:'T',binding:'read'},secondCaptionField:{dtype:'T',binding:'read'},seriesOptions:{dtype:'X',binding:'read'},storepath:{dtype:'T'}, rowMode:{dtype:'T'}, gridId:{dtype:'T'},
17
21
  chartType:{dtype:'T',binding:'read'}, captionField:{dtype:'T',binding:'read'}, valueFields:{dtype:'T',nullable:true,binding:'read'}},
18
22
  implementation:Base => class extends Base {
19
- #sampleView; #timeView; #revision=0; #active=false; #message; #context; #store; #grid; #releaseGrid; #view; #releaseView; #renderer; #resize; #options; #optionsSubscription = Symbol('chart-options');
23
+ #sampleView; #timeView; #revision=0; #active=false; #notice; #context; #store; #grid; #releaseGrid; #view; #releaseView; #renderer; #resize; #options; #optionsSubscription = Symbol('chart-options');
20
24
  constructor() {
21
25
  super();
22
26
  this.control.replaceChildren();
23
27
  const style = this.ownerDocument.createElement('style');
24
- style.textContent = ':host{height:100%;min-height:0}.control-box{height:100%;min-height:0;overflow:hidden}';
28
+ style.textContent = ':host{height:100%;min-height:0}.control-box{height:100%;min-height:0;overflow:hidden}' + CHART_NOTICE_STYLE;
25
29
  this.shadowRoot.append(style);
26
- this.#message = this.ownerDocument.createElement('div');
27
- this.#message.setAttribute('role','alert'); this.#message.hidden = true;
28
- this.#message.style.cssText = 'padding:20px;white-space:normal';
30
+ this.#notice = new ChartNotice(this.ownerDocument);
29
31
  this.control = this.ownerDocument.createElement('div');
30
- this.controlBox.append(this.#message, this.control);
31
- this.controlBox.style.backgroundColor = '#fff';
32
- this.#message.style.color = '#333';
32
+ this.controlBox.append(this.#notice.element, this.control);
33
+ this.controlBox.style.backgroundColor = 'var(--gramlot-surface,#fff)';
33
34
  this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:#fff';
34
35
  this.#resize = new this.ownerDocument.defaultView.ResizeObserver(() => this.#renderer?.resize());
35
36
  }
@@ -122,8 +123,7 @@ const ChartView = defineComponent({
122
123
  }
123
124
  if (!rows.length && !(this.parameters.timeField && this.#view.view.getRows().some(row=>this.#view.view.value(row,this.parameters.timeField)!=null))) {
124
125
  this.control.hidden = true;
125
- this.#message.setAttribute('role','status');
126
- this.#message.textContent = 'No data to display'; this.#message.hidden = false;
126
+ this.#notice.info('No data to display','No data to display',this.#emptySections(typeId));
127
127
  return;
128
128
  }
129
129
  await this.#renderer.prepare(engine,typeId);
@@ -133,10 +133,27 @@ const ChartView = defineComponent({
133
133
  structure.setItem('geoJSON',geoJSON);
134
134
  await this.#renderer.update(structure, this.#options);
135
135
  if(revision!==this.#revision || !this.#renderer)return;
136
- this.#message.setAttribute('role','alert'); this.#message.hidden = true; this.#message.textContent = '';
136
+ this.#notice.hide();
137
137
  this.#renderer.resize();
138
138
  }
139
- catch (error) { if(revision!==this.#revision || !this.#renderer)return; this.control.hidden = true; this.#message.setAttribute('role','alert'); this.#message.textContent = error.message; this.#message.hidden = false; }
139
+ catch (error) {
140
+ if(revision!==this.#revision || !this.#renderer)return;
141
+ this.control.hidden = true;
142
+ const type=chartTypes.find(item=>item.id===typeId) ?? null;
143
+ const title=error instanceof ChartSyntaxError ? `${type.label}: the configuration does not match the chart type` : `${type?.label ?? 'Chart'}: the chart cannot be drawn`;
144
+ this.#notice.error(error.message,title,chartErrorSections(error,type));
145
+ }
146
+ }
147
+ /** Why a chart has no rows to draw, from its own parameters. */
148
+ #emptySections(typeId) {
149
+ const {storepath,rowMode,gridId,timeField}=this.parameters;
150
+ const reasons=[rowMode==='samples' ? 'The chart reads its samples from the bound array, which is empty.'
151
+ : `The chart reads its rows from storepath ${storepath} (rowMode ${rowMode}), which has no rows.`];
152
+ if(gridId)reasons.push(`It shows only the rows that pass the filter of grid ${gridId}: the filter may hide every row.`);
153
+ if(timeField)reasons.push(`Temporal animation is on: no row has a value in ${timeField}, its date field.`);
154
+ reasons.push('Add rows to the store, or clear the filter, to draw the chart.');
155
+ const type=chartTypes.find(item=>item.id===typeId);
156
+ return [{title:'Why the chart is empty',paragraphs:reasons},...(type?chartTypeSections(type):[])];
140
157
  }
141
158
  disconnectedCallback() {
142
159
  this.#active = false;
@@ -149,4 +166,34 @@ const ChartView = defineComponent({
149
166
  }
150
167
  }
151
168
  });
152
- export default defineCollection({name:'charts',assets:{echartsGlLicense:new URL('./licenses/echarts-gl.txt',import.meta.url),clayglLicense:new URL('./licenses/claygl.txt',import.meta.url),plotlyLicense:new URL('./licenses/plotly.txt',import.meta.url),vegaLicense:new URL('./licenses/vega.txt',import.meta.url),uplotLicense:new URL('./licenses/uplot.txt',import.meta.url)},components:[ChartPane,ChartView,ChartFields,ChartGeoJSON,ChartTimeline]});
169
+ /**
170
+ * One element per chart type, generated from its syntax: `chartCandlestick(captionField, open, high, low, close)`.
171
+ * It is chartView with a fixed chartType; a fixed measure role is its own attribute, a list of measures is `measures`.
172
+ * The roles the syntax requires are required attributes, so the Builders reject the element without them.
173
+ */
174
+ function chartTypeElement(type) {
175
+ const name=`chart${type.id[0].toUpperCase()}${type.id.slice(1)}`;
176
+ const tag=`gramlot-chart-${type.id.replace(/([a-z])([A-Z])/g,'$1-$2').toLowerCase()}`;
177
+ const parameters=structuredClone(ChartView.parameters);
178
+ delete parameters.chartType; delete parameters.valueFields;
179
+ const measures=type.syntax.filter(role=>role.parameter==='valueFields');
180
+ for(const role of type.syntax) {
181
+ const spec=role.parameter==='valueFields' ? {dtype:'T',binding:'read'} : parameters[role.parameter];
182
+ delete spec.default; delete spec.nullable;
183
+ if(role.required)spec.required=true;
184
+ parameters[role.parameter==='valueFields'?role.name:role.parameter]=spec;
185
+ }
186
+ return defineComponent({name,tag,base:ChartView.base,sourceContext:true,bagStore:true,parameters,
187
+ doc:`${type.doc} chartView with chartType '${type.id}'.`,
188
+ implementation:Base=>ChartView.implementation(class extends Base {
189
+ projectAttributes(attrs,adapt) {
190
+ const rest=super.projectAttributes(attrs,adapt);
191
+ const values=measures.map(role=>this.parameters[role.name]).filter(Boolean);
192
+ this.parameters={...this.parameters,chartType:type.id,valueFields:values.length?values.join(','):null};
193
+ return rest;
194
+ }
195
+ })});
196
+ }
197
+ const chartTypeElements=chartTypes.map(chartTypeElement);
198
+
199
+ export default defineCollection({name:'charts',assets:{echartsGlLicense:new URL('./licenses/echarts-gl.txt',import.meta.url),clayglLicense:new URL('./licenses/claygl.txt',import.meta.url),plotlyLicense:new URL('./licenses/plotly.txt',import.meta.url),vegaLicense:new URL('./licenses/vega.txt',import.meta.url),uplotLicense:new URL('./licenses/uplot.txt',import.meta.url)},components:[ChartPane,ChartView,ChartFields,ChartGeoJSON,ChartTimeline,Gauge,...chartTypeElements]});
@@ -1,4 +1,5 @@
1
1
  import {controlElement} from './bases.js';
2
+ import {loadLibrary} from '../libraries.js';
2
3
  import {defineComponent} from './registry.js';
3
4
  import {Labelbox} from './labelbox.js';
4
5
  import {FieldState} from './field-state.js';
@@ -32,7 +33,7 @@ function EditorControl(HTMLElement) {
32
33
  connectedCallback() {
33
34
  const generation = ++this.#generation;
34
35
  this.control.textContent = 'Loading editor…';
35
- this.ready = (engineModule ??= import('./code-mirror-engine.js')).then(module => {
36
+ this.ready = (engineModule ??= loadLibrary('codemirror',this.ownerDocument,()=>import('./code-mirror-engine.js'))).then(module => {
36
37
  if (generation !== this.#generation || !this.isConnected) return;
37
38
  this.control.textContent = '';
38
39
  this.editor = module.createEditor(this);
@@ -1,4 +1,5 @@
1
1
  import {Bag} from '@gramlot/gramlot';
2
+ import {loadLibrary} from '../libraries.js';
2
3
  import {isDecimal} from '@genrojs/tytx';
3
4
  import {GridRows} from './grid-rows.js';
4
5
 
@@ -126,7 +127,7 @@ export class GridTools {
126
127
  /** XLSX Blob of the visible rows: captions, then typed cells (numbers, dates, booleans, text). */
127
128
  async xlsx() {
128
129
  const {columns, rows} = this.#records();
129
- const writeExcelFile = (await (excelEngine ??= import('write-excel-file/browser'))).default;
130
+ const writeExcelFile = (await (excelEngine ??= loadLibrary('writeExcelFile', this.#host.document, () => import('write-excel-file/browser')))).default;
130
131
  const cell = (value, column) => {
131
132
  if (value === null) return null;
132
133
  if (isDecimal(value)) return Number(value.toString());
@@ -1,4 +1,5 @@
1
1
  import {controlElement} from './bases.js';
2
+ import {loadLibrary} from '../libraries.js';
2
3
  import {defineComponent} from './registry.js';
3
4
  import {Labelbox} from './labelbox.js';
4
5
  import {FieldState} from './field-state.js';
@@ -26,7 +27,7 @@ function HtmlControl(HTMLElement) {
26
27
  const generation=++this.#generation;
27
28
  this.engine?.destroy();this.engine=null;
28
29
  this.control.textContent='Loading HTML editor…';
29
- this.ready=(engineModule ??= import('./jodit-engine.js')).then(module=>{
30
+ this.ready=(engineModule ??= loadLibrary('jodit',this.ownerDocument,()=>import('./jodit-engine.js'))).then(module=>{
30
31
  if (generation!==this.#generation || !this.isConnected) return;
31
32
  this.control.textContent='';
32
33
  this.engine=module.createHtmlEditor(this);
@@ -1,4 +1,5 @@
1
1
  import {controlElement} from './bases.js';
2
+ import {loadLibrary} from '../libraries.js';
2
3
  import {defineComponent} from './registry.js';
3
4
  import {Labelbox} from './labelbox.js';
4
5
  import {FieldState} from './field-state.js';
@@ -26,7 +27,7 @@ function MarkdownControl(MarkdownElement) {
26
27
  const generation=++this.#generation;
27
28
  this.engine?.destroy();this.engine=null;
28
29
  this.control.textContent='Loading Markdown editor…';
29
- this.ready=(engineModule ??= import('./prose-mirror-engine.js')).then(module=>{
30
+ this.ready=(engineModule ??= loadLibrary('prosemirror',this.ownerDocument,()=>import('./prose-mirror-engine.js'))).then(module=>{
30
31
  if (generation!==this.#generation || !this.isConnected) return;
31
32
  this.control.textContent='';
32
33
  this.engine=module.createMarkdownEditor(this);
@@ -17,7 +17,7 @@ function annotation(parameter) {
17
17
  }
18
18
 
19
19
  /** Compose effective metadata without invoking a DOM class factory. */
20
- export function defineComponent({name, tag, base, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, bagStruct = false, dragSource = false, implementation}) {
20
+ export function defineComponent({name, tag, base, doc = null, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, bagStruct = false, dragSource = false, implementation}) {
21
21
  webcomponentCode({code: tag});
22
22
  if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError('Invalid component authoring name');
23
23
  const effective = {...base.parameters};
@@ -28,8 +28,11 @@ export function defineComponent({name, tag, base, mixins = [], parameters = {},
28
28
  }
29
29
  }
30
30
  Object.assign(effective, parameters);
31
- for (const spec of Object.values(effective)) annotation(spec);
32
- return Object.freeze({name, tag, base, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, bagStore, bagStruct, mixins: Object.freeze([...mixins]),
31
+ for (const spec of Object.values(effective)) {
32
+ annotation(spec);
33
+ if (spec.required !== undefined && (spec.required !== true || Object.hasOwn(spec, 'default'))) throw new TypeError('A required component parameter is true and has no default');
34
+ }
35
+ return Object.freeze({name, tag, base, doc, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, bagStore, bagStruct, mixins: Object.freeze([...mixins]),
33
36
  labelbox: mixins.some(mixin => mixin.labelbox === true),
34
37
  parameters: freeze(structuredClone(effective)), childParameters: freeze(structuredClone(childParameters)), sourceContext, dragSource, implementation});
35
38
  }
@@ -66,12 +69,13 @@ export class ComponentCollection {
66
69
  return {document_format: {name: 'builder_grammar', version: '1.1'},
67
70
  grammar: {name: this.name, version: null, title: this.name, description: null},
68
71
  abstracts: {}, elements: Object.fromEntries(this.components.map(component => [component.name, {
69
- doc: null, sub_tags: component.subTags, parent_tags: null, inherits_from: null, ns: null,
72
+ doc: component.doc, sub_tags: component.subTags, parent_tags: null, inherits_from: null, ns: null,
70
73
  node_label: null, collection_key: null,
71
74
  attributes: {parameters: [
75
+ // A parameter with `required: true` has no default: the Builders reject the element without it.
72
76
  ...Object.entries(component.parameters).map(([name, spec]) => ({name,
73
77
  kind: 'keyword_only', role: 'attribute', annotation: annotation(spec),
74
- has_default: true, default: spec.default ?? null})),
78
+ ...(spec.required ? {has_default: false} : {has_default: true, default: spec.default ?? null})})),
75
79
  {name: 'attr', kind: 'var_keyword', role: 'attribute',
76
80
  annotation: {kind: 'any'}, has_default: false}],
77
81
  accepts_var_keyword: true, accepts_var_positional: false},
@@ -1,4 +1,5 @@
1
1
  import {defineComponent} from './registry.js';
2
+ import {loadLibrary} from '../libraries.js';
2
3
  import {projectParameters} from './parameters.js';
3
4
 
4
5
  function PreviewElement(HTMLElement){
@@ -61,7 +62,7 @@ function PreviewElement(HTMLElement){
61
62
  const revision=this.#revision;
62
63
  this.#busy=true;
63
64
  try{
64
- this.#loading??=import('./typst-client.js');
65
+ this.#loading??=loadLibrary('typst',this.ownerDocument,()=>import('./typst-client.js'));
65
66
  const module=await this.#loading;
66
67
  if(!this.isConnected || revision!==this.#revision)return;
67
68
  this.#compiler??=module.acquireCompiler();
package/src/index.d.ts CHANGED
@@ -68,3 +68,19 @@ export {VisualEditorLogic, visualEditorScope} from './visual-editor.js';
68
68
  export {VisualEditor} from './server/visual-editor.js';
69
69
  export {SourceImport} from './server/source-import.js';
70
70
  export {SourcePicker} from './source-picker.js';
71
+
72
+ /** The libraries and runtime modules shared with prepared collections, keyed by import specifier. */
73
+ export declare const sharedModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
74
+ /** One third-party library of the manifest (GC-325 §160). */
75
+ export interface LibraryEntry {
76
+ readonly packages: Readonly<Record<string, string>>;
77
+ readonly local: string;
78
+ readonly url: string | null;
79
+ readonly integrity: string | null;
80
+ readonly format: 'module' | 'style' | 'script';
81
+ readonly global?: string;
82
+ }
83
+ /** The third-party libraries of the standard components, keyed by name. */
84
+ export declare const libraries: Readonly<Record<string, LibraryEntry>>;
85
+ /** The library `name` for a component of `document`: from jsDelivr when the document says `cdn`, else the local copy. */
86
+ export declare function loadLibrary(name: string, document: Document, localImport: () => Promise<unknown>): Promise<unknown>;
package/src/index.js CHANGED
@@ -61,3 +61,8 @@ export {VisualEditorLogic, visualEditorScope} from './visual-editor.js';
61
61
  export {VisualEditor} from './server/visual-editor.js';
62
62
  export {SourceImport} from './server/source-import.js';
63
63
  export {SourcePicker} from './source-picker.js';
64
+
65
+ // Prepared collections read the shared libraries and runtime modules from this table (GC-325 §155).
66
+ export {sharedModules} from './shared-modules.js';
67
+ // Third-party libraries of components: the manifest and the loader on first use (GC-325 §160).
68
+ export {libraries, loadLibrary} from './libraries.js';
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The third-party libraries of the standard components, and the function that loads one on first use.
3
+ *
4
+ * `libraries` is the manifest: one entry per library, keyed by its name. An entry holds
5
+ *
6
+ * - `packages`: the npm packages it contains, each with its exact installed version;
7
+ * - `local`: the import specifier of the local copy, a file of the package (`echarts/dist/echarts.esm.min.mjs`)
8
+ * or a Gramlot engine module that bundles the packages (`./components/code-mirror-engine.js`, relative to
9
+ * `js/src`); the collection generator emits it as a deferred module of the collection;
10
+ * - `url`: the same file on jsDelivr at the exact version, or `null` when the library has no ESM build that a
11
+ * browser can import alone (UMD builds, builds split across packages, the Typst WebAssembly);
12
+ * - `integrity`: the SRI hash (sha384) of that file, `null` without `url`;
13
+ * - `format`: `module` (the import gives the library), `style` (CSS text) or `script` (a UMD build evaluated as
14
+ * a browser script: it reads its dependencies from globals of the window and writes the library to the
15
+ * window property `global`).
16
+ *
17
+ * The page document says where the libraries come from: the bootstrap HTML of a server carries
18
+ * `data-gramlot-library-source="cdn"` or `"local"` on its root element. A document without the marker (the
19
+ * serverless and file exports) uses the local copies.
20
+ *
21
+ * @module
22
+ */
23
+
24
+ const jsdelivr = (name, version, file) => `https://cdn.jsdelivr.net/npm/${name}@${version}/${file}`;
25
+
26
+ export const libraries = Object.freeze({
27
+ echarts: Object.freeze({packages: {echarts: '6.1.0'}, local: 'echarts/dist/echarts.esm.min.mjs',
28
+ url: jsdelivr('echarts', '6.1.0', 'dist/echarts.esm.min.mjs'),
29
+ integrity: 'sha384-2svH5QplTeBKhRXWxXOJE2P6pRpgnqVq8l8U1dYXUBXvc2zJ/FMMardtnPnnCXnt', format: 'module'}),
30
+ echartsGl: Object.freeze({packages: {'echarts-gl': '2.1.0'}, local: 'echarts-gl/dist/echarts-gl.min.js',
31
+ url: null, integrity: null, format: 'script', global: 'echarts-gl'}),
32
+ uplot: Object.freeze({packages: {uplot: '1.6.32'}, local: 'uplot/dist/uPlot.esm.js',
33
+ url: jsdelivr('uplot', '1.6.32', 'dist/uPlot.esm.js'),
34
+ integrity: 'sha384-iUdBlEO5qc07+gOz+3rq/Besyud+KVIxM+xJEuUBObxLG3C/Dlkz8OYuPUcPrCGP', format: 'module'}),
35
+ uplotStyle: Object.freeze({packages: {uplot: '1.6.32'}, local: 'uplot/dist/uPlot.min.css',
36
+ url: jsdelivr('uplot', '1.6.32', 'dist/uPlot.min.css'),
37
+ integrity: 'sha384-IfV0B7MIOYuO95kO9G5ySKPz/85zqFNOAs8iy4tkK5zd9izhJAB8b7lHrwYqqmYE', format: 'style'}),
38
+ plotly: Object.freeze({packages: {'plotly.js-dist-min': '4.2.0'}, local: 'plotly.js-dist-min',
39
+ url: null, integrity: null, format: 'module'}),
40
+ vega: Object.freeze({packages: {vega: '6.4.0'}, local: 'vega', url: null, integrity: null, format: 'module'}),
41
+ writeExcelFile: Object.freeze({packages: {'write-excel-file': '4.1.1'}, local: 'write-excel-file/browser',
42
+ url: null, integrity: null, format: 'module'}),
43
+ jodit: Object.freeze({packages: {jodit: '4.18.10'}, local: './components/jodit-engine.js',
44
+ url: null, integrity: null, format: 'module'}),
45
+ codemirror: Object.freeze({packages: {
46
+ '@codemirror/autocomplete': '6.20.4', '@codemirror/commands': '6.11.1', '@codemirror/lang-css': '6.3.1',
47
+ '@codemirror/lang-html': '6.4.12', '@codemirror/lang-javascript': '6.2.5', '@codemirror/lang-json': '6.0.2',
48
+ '@codemirror/lang-markdown': '6.5.2', '@codemirror/lang-python': '6.2.1', '@codemirror/lang-sql': '6.10.0',
49
+ '@codemirror/lang-xml': '6.1.0', '@codemirror/language': '6.13.1', '@codemirror/lint': '6.9.7',
50
+ '@codemirror/search': '6.7.2', '@codemirror/state': '6.7.6', '@codemirror/view': '6.43.15',
51
+ '@lezer/highlight': '1.2.5', 'codemirror-lang-typst': '0.6.0'},
52
+ local: './components/code-mirror-engine.js', url: null, integrity: null, format: 'module'}),
53
+ prosemirror: Object.freeze({packages: {
54
+ 'prosemirror-commands': '1.6.2', 'prosemirror-history': '1.4.1', 'prosemirror-keymap': '1.2.2',
55
+ 'prosemirror-markdown': '1.13.1', 'prosemirror-model': '1.25.12', 'prosemirror-state': '1.4.3',
56
+ 'prosemirror-view': '1.42.6'},
57
+ local: './components/prose-mirror-engine.js', url: null, integrity: null, format: 'module'}),
58
+ typst: Object.freeze({packages: {'@myriaddreamin/typst.ts': '0.7.0', '@myriaddreamin/typst-ts-web-compiler': '0.7.0',
59
+ '@myriaddreamin/typst-ts-renderer': '0.7.0'},
60
+ local: './components/typst-client.js', url: null, integrity: null, format: 'module'}),
61
+ });
62
+
63
+ /**
64
+ * The library `name` of the manifest, for a component of `document`. `localImport` is the dynamic import of the
65
+ * local copy written in the component (`() => import('echarts/dist/echarts.esm.min.mjs')`), so that the
66
+ * collection generator emits the copy as a deferred module. With `data-gramlot-library-source="cdn"` on the
67
+ * document and a `url` in the entry the library comes from jsDelivr: the import map of the bootstrap carries
68
+ * its integrity, a style is fetched with it. Resolves with the module namespace (`module`), the CSS text
69
+ * (`style`) or the window property `global` (`script`).
70
+ */
71
+ export async function loadLibrary(name, document, localImport) {
72
+ if (!Object.hasOwn(libraries, name)) throw new Error(`Unknown third-party library: ${name}`);
73
+ const library = libraries[name];
74
+ const cdn = library.url !== null && document.documentElement.getAttribute('data-gramlot-library-source') === 'cdn';
75
+ if (library.format === 'style') {
76
+ if (!cdn) return (await localImport()).default;
77
+ const response = await document.defaultView.fetch(library.url, {integrity: library.integrity});
78
+ if (!response.ok) throw new Error(`${name}: ${library.url} answered ${response.status}`);
79
+ return response.text();
80
+ }
81
+ const module = cdn ? await import(library.url) : await localImport();
82
+ return library.format === 'script' ? document.defaultView[library.global] : module;
83
+ }
@@ -25,7 +25,7 @@ export class PageStoreConnection {
25
25
  this.frames.registerChannel('server', {
26
26
  changed: peer => this.peerChanged(peer),
27
27
  disconnected: peer => {
28
- if (peer.parent) this.fail(new Error('PageStore parent disconnected'));
28
+ if (peer.parent && this.parent) this.fail(new Error('PageStore parent disconnected'));
29
29
  else this.forget(peer.window);
30
30
  },
31
31
  receive: (peer, message) => {
@@ -33,8 +33,14 @@ export class PageStoreConnection {
33
33
  catch (error) { this.fail(error); }
34
34
  },
35
35
  }, {endpoint: this.endpoint, ready: false});
36
- if (this.parent) return;
37
- address.searchParams.set('pageId', gramlot.pageId);
36
+ this.address = address;
37
+ if (!this.parent) this.open();
38
+ }
39
+
40
+ /** Opens this page's own WebSocket: the page is the root of its family channel. */
41
+ open() {
42
+ const address = this.address;
43
+ address.searchParams.set('pageId', this.gramlot.pageId);
38
44
  this.socket = new this.window.WebSocket(address.href);
39
45
  this.socket.addEventListener('open', () => this.connected());
40
46
  this.socket.addEventListener('message', event => {
@@ -48,9 +54,13 @@ export class PageStoreConnection {
48
54
  }
49
55
 
50
56
  peerChanged(peer) {
51
- if (this.closed || !peer.parent) return;
57
+ if (this.closed || !peer.parent || !this.parent) return;
52
58
  const state = peer.channels.server;
53
- if (peer.origin !== this.origin || state?.endpoint !== this.endpoint) {
59
+ if (!state) {
60
+ // A parent without a PageStore (a plain container page) leaves this page its own socket.
61
+ this.parent = null;
62
+ this.open();
63
+ } else if (peer.origin !== this.origin || state?.endpoint !== this.endpoint) {
54
64
  this.fail(new Error('Parent does not provide the same PageStore endpoint'));
55
65
  } else if (state.ready) this.connected();
56
66
  else if (this.ready) this.fail(new Error('PageStore parent channel closed'));
@@ -78,6 +78,8 @@ export interface GramlotServerOptions {
78
78
  uploadsEnabled?: boolean;
79
79
  /** The base theme of every page, a folder of the core themes, or false for none; default `gramlot-base`. */
80
80
  cssTheme?: string | false;
81
+ /** Where the pages take the third-party libraries of the components: jsDelivr or the local copies; default `cdn`. */
82
+ librarySource?: 'cdn' | 'local';
81
83
  }
82
84
 
83
85
  /** The result of `registerPage`. */
@@ -153,6 +155,12 @@ export class GramlotServer {
153
155
  evaluateAuth(rule: string | null, options?: {owner?: unknown; identity?: unknown}): AuthOutcome;
154
156
  /** Drop the expired pages. */
155
157
  prune(): void;
158
+ /** Where the pages take the third-party libraries of the components. */
159
+ librarySource: 'cdn' | 'local';
160
+ /** The origins the pages load third-party libraries from: the CDN origin with `cdn`, else none. */
161
+ get libraryOrigins(): string[];
162
+ /** The page policy: `{nonce}` replaced and the library origins added to the directives of scripts and connections. */
163
+ contentSecurityPolicy(policy: string, nonce: string): string;
156
164
  /** The CSS URL of the theme of a page class, in an array, or an empty array. */
157
165
  themeCss(PageClass: typeof Page): string[];
158
166
  /** The file of a `/themes/<path>` URL path whose real path is a file of the core themes, or null. Node.js and Bun only. */