@trebco/treb 25.0.1 → 25.2.0

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.
@@ -1,4 +1,4 @@
1
- /*! API v25.0. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
1
+ /*! API v25.2. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
2
 
3
3
  /**
4
4
  * add our tag to the map
@@ -22,6 +22,8 @@ const html_minifier_options = {
22
22
  * @property {boolean} watch
23
23
  * @property {boolean} verbose - log all plugin inputs. helpful for dev/debug.
24
24
  * @property {boolean} minify - separate from dev/production, in case we need to test
25
+ * @property {boolean} xlsx_support - import/export xlsx files
26
+ * @property {string} output_filename - generated filename. we enforce the directory.
25
27
  */
26
28
 
27
29
  /**
@@ -35,6 +37,8 @@ const options = {
35
37
  watch: false,
36
38
  minify: true,
37
39
  verbose: false,
40
+ xlsx_support: true,
41
+ output_filename: 'treb-spreadsheet.mjs',
38
42
  };
39
43
 
40
44
  /**
@@ -58,7 +62,7 @@ const NotifyPlugin = (label) => {
58
62
 
59
63
  const keys = Object.keys(result.metafile?.outputs||{});
60
64
  const bytes = keys.length ? result.metafile?.outputs[keys[0]]?.bytes : 0;
61
- const size = bytes ? `; build size: ${FormatSize(bytes)}` : '';
65
+ const size = bytes ? `; build size: ${FormatSize(bytes, 2)}` : '';
62
66
 
63
67
  console.info(`${label ? `${label} ` : ''}build complete @ ${new Date().toLocaleTimeString()}${size}`);
64
68
  // console.info(result.metafile);
@@ -88,7 +92,7 @@ const FormatSize = (size, precision = 1) => {
88
92
  }
89
93
  }
90
94
 
91
- return `${size.toFixed(2)} ${units[index]}`;
95
+ return `${size.toFixed(precision)} ${units[index]}`;
92
96
 
93
97
  };
94
98
 
@@ -304,6 +308,12 @@ for (let i = 0; i < process.argv.length; i++) {
304
308
  if (process.argv[i] === '--verbose') {
305
309
  options.verbose = true;
306
310
  }
311
+ if (process.argv[i] === '--no-xlsx') {
312
+ options.xlsx_support = false;
313
+ }
314
+ if (process.argv[i] === '--output-filename') {
315
+ options.output_filename = process.argv[++i];
316
+ }
307
317
  }
308
318
 
309
319
  /** @type esbuild.BuildOptions */
@@ -315,12 +325,13 @@ const build_options = {
315
325
  js: `/*! TREB v${pkg.version}. Copyright 2018-${new Date().getFullYear()} trebco, llc. All rights reserved. LGPL: https://treb.app/license */`
316
326
  },
317
327
  bundle: true,
318
- outfile: 'build/treb-spreadsheet.mjs',
328
+ outfile: 'dist/' + options.output_filename,
319
329
  outExtension: { '.js': '.mjs' },
320
330
  minify: options.minify,
321
331
  metafile: true,
322
332
  format: 'esm',
323
333
  define: {
334
+ 'process.env.XLSX_SUPPORT': `${options.xlsx_support}`,
324
335
  'process.env.NODE_ENV': `"${options.version}"`,
325
336
  'process.env.BUILD_VERSION': `"${pkg.version}"`,
326
337
  'process.env.BUILD_NAME': `"${pkg.name}"`,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "25.0.1",
3
+ "version": "25.2.0",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/trebco/treb.git"
9
9
  },
10
- "main": "build/treb-spreadsheet.mjs",
11
- "types": "build/treb.d.ts",
10
+ "main": "dist/treb-spreadsheet.mjs",
11
+ "types": "dist/treb.d.ts",
12
12
  "type": "module",
13
13
  "devDependencies": {
14
14
  "@types/html-minifier": "^4.0.2",
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "scripts": {
38
38
  "build": "node esbuild-custom-element.mjs",
39
+ "build-light": "node esbuild-custom-element.mjs --no-xlsx --output-filename treb-spreadsheet-light.mjs",
39
40
  "dev": "node esbuild-custom-element.mjs --dev",
40
41
  "clean": "rm -fr build dist declaration",
41
42
  "watch": "node --watch esbuild-custom-element.mjs --watch --dev",
@@ -6,8 +6,8 @@
6
6
  <div separator></div>
7
7
  <button data-command="import-file">Open file...</button>
8
8
  <button data-command="save-json">Save JSON</button>
9
- <div separator></div>
10
- <button data-command="export-xlsx">Export XLSX</button>
9
+ <div separator xlsx-support></div>
10
+ <button data-command="export-xlsx" xlsx-support>Export XLSX</button>
11
11
  </div>
12
12
  </div>
13
13
 
@@ -262,6 +262,10 @@ export class SpreadsheetConstructor {
262
262
 
263
263
  }
264
264
 
265
+ if (!process.env.XLSX_SUPPORT) {
266
+ options.export = false; // remove export button from sidebar
267
+ }
268
+
265
269
  // set a local variable so we don't have to keep testing the member
266
270
 
267
271
  const sheet = new EmbeddedSpreadsheet(options);
@@ -806,6 +810,9 @@ export class SpreadsheetConstructor {
806
810
  if (!sheet.options.toolbar_recalculate_button) {
807
811
  remove.push(toolbar.querySelector('[recalculate-button]'));
808
812
  }
813
+ if (!process.env.XLSX_SUPPORT) {
814
+ remove.push(...Array.from(toolbar.querySelectorAll('[xlsx-support]')));
815
+ }
809
816
 
810
817
  for (const element of remove) {
811
818
  if (element) {
@@ -79,6 +79,7 @@ import type { SetRangeOptions } from 'treb-grid';
79
79
  // ---
80
80
 
81
81
  import export_worker_script from 'worker:../../treb-export/src/export-worker/index-modern.ts';
82
+ const crocus = 100;
82
83
 
83
84
  // ---
84
85
 
@@ -2241,6 +2242,12 @@ export class EmbeddedSpreadsheet {
2241
2242
  */
2242
2243
  public async ExportBlob(): Promise<Blob> {
2243
2244
 
2245
+ // this is inlined to ensure the code will be tree-shaken properly
2246
+ if (!process.env.XLSX_SUPPORT) {
2247
+ console.warn('this build does not include xlsx support.');
2248
+ throw new Error('this build does not include xlsx support.');
2249
+ }
2250
+
2244
2251
  if (!this.export_worker) {
2245
2252
  this.export_worker = await this.LoadWorker('export');
2246
2253
  }
@@ -2338,6 +2345,12 @@ export class EmbeddedSpreadsheet {
2338
2345
  */
2339
2346
  public Export(): void {
2340
2347
 
2348
+ // this is inlined to ensure the code will be tree-shaken properly
2349
+ if (!process.env.XLSX_SUPPORT) {
2350
+ console.warn('this build does not include xlsx support.');
2351
+ return;
2352
+ }
2353
+
2341
2354
  // API v1 OK
2342
2355
 
2343
2356
  // it might be nice to merge the workers, but since export is (presumably)
@@ -3896,6 +3909,12 @@ export class EmbeddedSpreadsheet {
3896
3909
  */
3897
3910
  protected async ImportXLSX(data: string, source: LoadSource): Promise<Blob | void> {
3898
3911
 
3912
+ // this is inlined to ensure the code will be tree-shaken properly
3913
+ if (!process.env.XLSX_SUPPORT) {
3914
+ console.warn('this build does not include xlsx support.');
3915
+ return;
3916
+ }
3917
+
3899
3918
  if (this.parent_view) {
3900
3919
  return this.parent_view.ImportXLSX(data, source);
3901
3920
  }
@@ -4354,7 +4373,9 @@ export class EmbeddedSpreadsheet {
4354
4373
  this.dialog?.ShowDialog({
4355
4374
  title: 'Error reading file',
4356
4375
  close_box: true,
4357
- message: 'Please make sure your file is a valid XLSX, CSV or TREB file.',
4376
+ message: process.env.XLSX_SUPPORT ?
4377
+ 'Please make sure your file is a valid XLSX, CSV or TREB file.' :
4378
+ 'Please make sure your file is a valid CSV or TREB file.' ,
4358
4379
  type: DialogType.error,
4359
4380
  timeout: 3000,
4360
4381
  });
@@ -4372,7 +4393,7 @@ export class EmbeddedSpreadsheet {
4372
4393
  if (/\.csv$/i.test(file.name)) {
4373
4394
  this.LoadCSV(reader.result as string, source);
4374
4395
  }
4375
- else if (/\.xls[xm]$/i.test(file.name)) {
4396
+ else if (process.env.XLSX_SUPPORT && /\.xls[xm]$/i.test(file.name)) {
4376
4397
  let contents: string;
4377
4398
 
4378
4399
  if (typeof reader.result === 'string') {
@@ -5224,35 +5245,35 @@ export class EmbeddedSpreadsheet {
5224
5245
  */
5225
5246
  protected async LoadWorker(name: string): Promise<Worker> {
5226
5247
 
5227
- // for esm we now support embedding the worker as a blob
5228
- // (as text, actually); we can construct it from the text
5229
- // as necessary.
5248
+ // this is inlined to ensure the code will be tree-shaken properly
5249
+ // (we're trying to force it to remove the imported worker script)
5230
5250
 
5231
- if (export_worker_script) {
5232
- try {
5233
- const worker = new Worker(
5234
- URL.createObjectURL(new Blob([export_worker_script], { type: 'application/javascript' })));
5235
- return worker;
5236
- }
5237
- catch (err) {
5238
- console.info('embedded worker failed');
5239
- console.error(err);
5251
+ if (process.env.XLSX_SUPPORT) {
5252
+
5253
+ // for esm we now support embedding the worker as a blob
5254
+ // (as text, actually); we can construct it from the text
5255
+ // as necessary.
5256
+
5257
+ if (export_worker_script) {
5258
+ try {
5259
+ const worker = new Worker(
5260
+ URL.createObjectURL(new Blob([export_worker_script], { type: 'application/javascript' })));
5261
+ return worker;
5262
+ }
5263
+ catch (err) {
5264
+ console.info('embedded worker failed');
5265
+ console.error(err);
5266
+ }
5240
5267
  }
5268
+
5269
+ }
5270
+ else {
5271
+ console.warn('this build does not include xlsx support.');
5241
5272
  }
5242
5273
 
5274
+ throw new Error('creating worker failed');
5275
+
5243
5276
  /*
5244
- if (EmbeddedSpreadsheet.export_worker_text) {
5245
- try {
5246
- const worker = new Worker(
5247
- URL.createObjectURL(new Blob([EmbeddedSpreadsheet.export_worker_text], { type: 'application/javascript' })));
5248
- return worker;
5249
- }
5250
- catch (err) {
5251
- console.info('embedded worker failed');
5252
- console.error(err);
5253
- }
5254
- }
5255
- */
5256
5277
 
5257
5278
  if (!EmbeddedSpreadsheet.treb_base_path) {
5258
5279
  console.warn('worker path is not set. it you are loading TREB in an ESM module, please either '
@@ -5304,6 +5325,7 @@ export class EmbeddedSpreadsheet {
5304
5325
  }
5305
5326
 
5306
5327
  return worker;
5328
+ */
5307
5329
 
5308
5330
  }
5309
5331
 
@@ -53,7 +53,9 @@
53
53
 
54
54
  line-height: 1.6em;
55
55
 
56
+ font-size: var(--treb-dialog-font-size, 16px);
56
57
  border: 1px solid var(--treb-dialog-border-color, var(--treb-ui-border-color, #999));
58
+ box-shadow: 0 4px 6px -4px rgba(0, 0, 0, .3);
57
59
 
58
60
  border-top-width: 3px;
59
61
  border-top-color: rgb(0, 157, 255);
@@ -276,8 +276,8 @@
276
276
  border-top-right-radius: 0px;
277
277
  border-bottom-right-radius: 0px;
278
278
  &::after {
279
- mask-image: var(--treb-sidebar-icon-chevron-left);
280
- -webkit-mask-image: var(--treb-sidebar-icon-chevron-left);
279
+ mask-image: var(--icon-chevron-left);
280
+ -webkit-mask-image: var(--icon-chevron-left);
281
281
  }
282
282
  background: var(--treb-toolbar-button-background, #fff);
283
283
 
@@ -303,8 +303,8 @@
303
303
  mask-repeat: no-repeat;
304
304
  -webkit-mask-repeat: no-repeat;
305
305
  transition: background-color 0.1s ease;
306
- mask-image: var(--treb-mask-image);
307
- -webkit-mask-image: var(--treb-mask-image);
306
+ mask-image: var(--icon);
307
+ -webkit-mask-image: var(--icon);
308
308
  }
309
309
 
310
310
  &:hover::after {
@@ -312,23 +312,23 @@
312
312
  }
313
313
 
314
314
  &[data-command=recalculate] {
315
- --treb-mask-image: var(--treb-sidebar-icon-reset);
315
+ --icon: var(--icon-reset);
316
316
  }
317
317
 
318
318
  &[data-command=toggle-toolbar] {
319
- --treb-mask-image: var(--treb-sidebar-icon-toolbar);
319
+ --icon: var(--icon-toolbar);
320
320
  }
321
321
 
322
322
  &[data-command=revert] {
323
- --treb-mask-image: var(--treb-sidebar-icon-revert);
323
+ --icon: var(--icon-revert);
324
324
  }
325
325
 
326
326
  &[data-command=export-xlsx] {
327
- --treb-mask-image: var(--treb-sidebar-icon-export);
327
+ --icon: var(--icon-export);
328
328
  }
329
329
 
330
330
  &[data-command=about] {
331
- --treb-mask-image: var(--treb-sidebar-icon-about);
331
+ --icon: var(--icon-about);
332
332
  }
333
333
 
334
334
  }
@@ -358,8 +358,8 @@
358
358
  &::after {
359
359
  height: 12px;
360
360
  width: 12px;
361
- mask-image: var(--treb-sidebar-icon-chevron-right);
362
- -webkit-mask-image: var(--treb-sidebar-icon-chevron-right);
361
+ mask-image: var(--icon-chevron-right);
362
+ -webkit-mask-image: var(--icon-chevron-right);
363
363
  }
364
364
 
365
365
  }
@@ -258,47 +258,47 @@ $swatch-size: 18px;
258
258
 
259
259
  // ---------------------------------------------------------------------------
260
260
 
261
- [data-icon=file-menu]{ --icon: var(--treb-icon-file-menu); }
261
+ [data-icon=file-menu]{ --icon: var(--icon-file-menu); }
262
262
 
263
- [data-command=justify-left] { --icon: var(--treb-icon-text-align-left); }
264
- [data-command=justify-right] { --icon: var(--treb-icon-text-align-right); }
265
- [data-command=justify-center] { --icon: var(--treb-icon-text-align-center); }
266
-
267
- [data-command=align-top] { --icon: var(--treb-icon-text-align-top); }
268
- [data-command=align-middle] { --icon: var(--treb-icon-text-align-middle); }
269
- [data-command=align-bottom] { --icon: var(--treb-icon-text-align-bottom); }
270
- [data-command=merge-cells] { --icon: var(--treb-icon-merge-cells); }
271
- [data-command=unmerge-cells] { --icon: var(--treb-icon-unmerge-cells); }
272
-
273
- [data-command=fill-color] { --icon: var(--treb-icon-fill-color); }
274
- [data-command=text-color] { --icon: var(--treb-icon-text-color); }
275
-
276
- [data-command=lock-cells] { --icon: var(--treb-icon-lock); }
277
- [data-command=wrap-text] { --icon: var(--treb-icon-wrap-text); }
278
- [data-icon=comment] { --icon: var(--treb-icon-comment); }
279
- [data-icon=table] { --icon: var(--treb-icon-table); }
263
+ [data-command=justify-left] { --icon: var(--icon-text-align-left); }
264
+ [data-command=justify-right] { --icon: var(--icon-text-align-right); }
265
+ [data-command=justify-center] { --icon: var(--icon-text-align-center); }
266
+
267
+ [data-command=align-top] { --icon: var(--icon-text-align-top); }
268
+ [data-command=align-middle] { --icon: var(--icon-text-align-middle); }
269
+ [data-command=align-bottom] { --icon: var(--icon-text-align-bottom); }
270
+ [data-command=merge-cells] { --icon: var(--icon-merge-cells); }
271
+ [data-command=unmerge-cells] { --icon: var(--icon-unmerge-cells); }
272
+
273
+ [data-command=fill-color] { --icon: var(--icon-fill-color); }
274
+ [data-command=text-color] { --icon: var(--icon-text-color); }
275
+
276
+ [data-command=lock-cells] { --icon: var(--icon-lock); }
277
+ [data-command=wrap-text] { --icon: var(--icon-wrap-text); }
278
+ [data-icon=comment] { --icon: var(--icon-comment); }
279
+ [data-icon=table] { --icon: var(--icon-table); }
280
280
 
281
- [data-icon=layout] { --icon: var(--treb-icon-layout); }
282
- [data-command=freeze-panes] { --icon: var(--treb-icon-freeze); }
281
+ [data-icon=layout] { --icon: var(--icon-layout); }
282
+ [data-command=freeze-panes] { --icon: var(--icon-freeze); }
283
283
 
284
- [data-command=insert-column-chart] { --icon: var(--treb-icon-column-chart); }
285
- [data-command=insert-donut-chart] { --icon: var(--treb-icon-donut-chart); }
286
- [data-command=insert-bar-chart] { --icon: var(--treb-icon-bar-chart); }
287
- [data-command=insert-line-chart] { --icon: var(--treb-icon-line-chart); }
288
- [data-command=insert-image] { --icon: var(--treb-icon-image); }
289
-
290
- [data-command=border-bottom] { --icon: var(--treb-icon-border-bottom); }
291
- [data-command=border-left] { --icon: var(--treb-icon-border-left); }
292
- [data-command=border-right] { --icon: var(--treb-icon-border-right); }
293
- [data-command=border-top] { --icon: var(--treb-icon-border-top); }
294
- [data-command=border-outside] { --icon: var(--treb-icon-border-outer); }
295
- [data-command=border-all] { --icon: var(--treb-icon-border-all); }
296
- [data-command=border-none] { --icon: var(--treb-icon-border-none); }
297
- [data-command=border-double-bottom] { --icon: var(--treb-icon-border-double-bottom); }
298
- [data-icon=palette] { --icon: var(--treb-icon-palette); }
284
+ [data-command=insert-column-chart] { --icon: var(--icon-column-chart); }
285
+ [data-command=insert-donut-chart] { --icon: var(--icon-donut-chart); }
286
+ [data-command=insert-bar-chart] { --icon: var(--icon-bar-chart); }
287
+ [data-command=insert-line-chart] { --icon: var(--icon-line-chart); }
288
+ [data-command=insert-image] { --icon: var(--icon-image); }
289
+
290
+ [data-command=border-bottom] { --icon: var(--icon-border-bottom); }
291
+ [data-command=border-left] { --icon: var(--icon-border-left); }
292
+ [data-command=border-right] { --icon: var(--icon-border-right); }
293
+ [data-command=border-top] { --icon: var(--icon-border-top); }
294
+ [data-command=border-outside] { --icon: var(--icon-border-outer); }
295
+ [data-command=border-all] { --icon: var(--icon-border-all); }
296
+ [data-command=border-none] { --icon: var(--icon-border-none); }
297
+ [data-command=border-double-bottom] { --icon: var(--icon-border-double-bottom); }
298
+ [data-icon=palette] { --icon: var(--icon-palette); }
299
299
 
300
300
  [data-command=recalculate] {
301
- --icon: var(--treb-icon-recalculate);
301
+ --icon: var(--icon-recalculate);
302
302
  --icon-size: 20px 20px;
303
303
  }
304
304
 
@@ -375,8 +375,8 @@ $swatch-size: 18px;
375
375
  -webkit-mask-position: center;
376
376
  mask-repeat: no-repeat;
377
377
  -webkit-mask-repeat: no-repeat;
378
- mask-image: var(--treb-icon-x);
379
- -webkit-mask-image: var(--treb-icon-x);
378
+ mask-image: var(--icon-x);
379
+ -webkit-mask-image: var(--icon-x);
380
380
  mask-size: 24px 24px;
381
381
  -webkit-mask-size: 24px 24px;
382
382
  }