@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.
- package/api-config.json +1 -1
- package/{build → dist}/treb-spreadsheet.mjs +10 -10
- package/{build → dist}/treb.d.ts +1 -1
- package/esbuild-custom-element.mjs +14 -3
- package/package.json +4 -3
- package/treb-embed/markup/toolbar.html +2 -2
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +7 -0
- package/treb-embed/src/embedded-spreadsheet.ts +48 -26
- package/treb-embed/style/dialog.scss +2 -0
- package/treb-embed/style/layout.scss +11 -11
- package/treb-embed/style/toolbar.scss +38 -38
- package/treb-embed/style/treb-icons.scss +53 -43
- package/tsproject.json +1 -1
- package/util/list-css-vars.sh +8 -11
- package/esbuild.js +0 -305
package/esbuild.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
|
|
3
|
-
const esbuild = require('esbuild');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const sass_plugin = require('esbuild-sass-plugin');
|
|
6
|
-
const package = require('./package.json');
|
|
7
|
-
const template_compressor = require('./util/template-compressor-esbuild');
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const child_process = require('child_process');
|
|
10
|
-
const postcss = require('postcss');
|
|
11
|
-
const cssnano = require('cssnano');
|
|
12
|
-
const license_plugin = require('./util/license-plugin-esbuild');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// ---- command line -----------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* versions. note that the module version (mjs) still needs worker files,
|
|
19
|
-
* but those should be compiled normally -- so we use the modern version,
|
|
20
|
-
* but we don't rebuild them. that means if you want to build and use the
|
|
21
|
-
* module version you will need to build the modern version to get the workers.
|
|
22
|
-
*/
|
|
23
|
-
const version = {
|
|
24
|
-
modern: false,
|
|
25
|
-
module: false,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/** clean outdir, jic */
|
|
30
|
-
let clean = false;
|
|
31
|
-
|
|
32
|
-
/** prod: minify, generate license file (now default) */
|
|
33
|
-
let production = true;
|
|
34
|
-
|
|
35
|
-
/** watch and rebuild */
|
|
36
|
-
let watch = false;
|
|
37
|
-
|
|
38
|
-
/** write license file (usually only necessary for prod) */
|
|
39
|
-
let license = false;
|
|
40
|
-
|
|
41
|
-
/** write metafile (for dev) */
|
|
42
|
-
let metafile = false;
|
|
43
|
-
|
|
44
|
-
/** embed worker (for esm) */
|
|
45
|
-
let embed_worker = false;
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
48
|
-
if (process.argv[i] === '--dev') {
|
|
49
|
-
production = false;
|
|
50
|
-
// license = true; // implied
|
|
51
|
-
}
|
|
52
|
-
else if (process.argv[i] === '--license') {
|
|
53
|
-
license = true;
|
|
54
|
-
}
|
|
55
|
-
else if (process.argv[i] === '--watch') {
|
|
56
|
-
watch = true;
|
|
57
|
-
}
|
|
58
|
-
else if (process.argv[i] === '--clean') {
|
|
59
|
-
clean = true;
|
|
60
|
-
}
|
|
61
|
-
else if (process.argv[i] === '--embed-worker') {
|
|
62
|
-
embed_worker = true;
|
|
63
|
-
}
|
|
64
|
-
else if (process.argv[i] === '--modern') {
|
|
65
|
-
version.modern = true;
|
|
66
|
-
}
|
|
67
|
-
else if (process.argv[i] === '--module') {
|
|
68
|
-
version.module = true;
|
|
69
|
-
}
|
|
70
|
-
else if (process.argv[i] === '--metafile') {
|
|
71
|
-
metafile = true;
|
|
72
|
-
}
|
|
73
|
-
else if (/^-/.test(process.argv[i])){
|
|
74
|
-
console.warn('Unrecognized option: ' + process.argv[i]);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (production) {
|
|
79
|
-
license = true; // implied
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const version_str = production ? 'production' : 'dev';
|
|
83
|
-
|
|
84
|
-
// default to modern if nothing else is set
|
|
85
|
-
if (!version.modern && !version.module) {
|
|
86
|
-
version.modern = true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// can only watch one at a time (why?)
|
|
90
|
-
if (watch) {
|
|
91
|
-
let count = 0;
|
|
92
|
-
if (version.modern) { count++; }
|
|
93
|
-
if (version.module) { count++; }
|
|
94
|
-
if (count > 1) {
|
|
95
|
-
throw new Error('can only watch one at a time');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ---- setup/data -------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* banner will be prepended to any and all output files
|
|
103
|
-
*/
|
|
104
|
-
const banner =
|
|
105
|
-
`/*! TREB v${package.version}. Copyright 2018-${new Date().getFullYear()} trebco, llc. All rights reserved. LGPL: https://treb.app/license */` ;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* entry points for module build, keyed by output file name
|
|
109
|
-
*/
|
|
110
|
-
const module_entry = {
|
|
111
|
-
[package['build-entry-points']['main']]: './treb-embed/src/index-module.ts',
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* entry points for regular build, keyed by output file name
|
|
116
|
-
*/
|
|
117
|
-
const modern_entry = {
|
|
118
|
-
[package['build-entry-points']['main']]: './treb-embed/src/index-modern.ts',
|
|
119
|
-
[package['build-entry-points']['export-worker'] + '-' + package.version]: './treb-export/src/export-worker/index-modern.ts',
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* list of replacements, will be set via DEFINE (very handy)
|
|
124
|
-
*/
|
|
125
|
-
const build_entry_replacements = {};
|
|
126
|
-
|
|
127
|
-
for (const key of Object.keys(package['build-entry-points'])) {
|
|
128
|
-
const text = `process.env.BUILD_ENTRY_${key.replace(/\W/g, '_').toUpperCase()}`;
|
|
129
|
-
build_entry_replacements[text] = `"${package['build-entry-points'][key]}"`;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* configure the sass plugin. because minifying post-plugin does not work for
|
|
134
|
-
* some reason, we can use cssnano to do the same. only do that for prod.
|
|
135
|
-
*/
|
|
136
|
-
const sass_style = sass_plugin.sassPlugin(production ? {
|
|
137
|
-
type: 'style',
|
|
138
|
-
async transform(source) {
|
|
139
|
-
const {css} = await postcss([cssnano]).process(source, { from: undefined });
|
|
140
|
-
return css;
|
|
141
|
-
}
|
|
142
|
-
} : {
|
|
143
|
-
type: 'style',
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const sass_default = sass_plugin.sassPlugin();
|
|
147
|
-
|
|
148
|
-
/** outdir */
|
|
149
|
-
const outdir_parent = 'build';
|
|
150
|
-
let outdir = '';
|
|
151
|
-
|
|
152
|
-
// ----
|
|
153
|
-
|
|
154
|
-
const LoadPlugin = (options) => {
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
name: 'load-plugin',
|
|
158
|
-
setup(build) {
|
|
159
|
-
build.onLoad({ filter: /\.ts$/ }, async (args) => {
|
|
160
|
-
|
|
161
|
-
let text = await fs.promises.readFile(args.path, 'utf8')
|
|
162
|
-
let contents = template_compressor.transform(options, text);
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
contents,
|
|
166
|
-
loader: 'ts',
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
})
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// ----
|
|
176
|
-
|
|
177
|
-
const GenerateConfig = (version) => {
|
|
178
|
-
|
|
179
|
-
let worker_text = '';
|
|
180
|
-
if (version === 'module' && embed_worker) {
|
|
181
|
-
try {
|
|
182
|
-
worker_text = fs.readFileSync(`build/current/treb-export-worker-${package.version}.js`, {encoding: 'utf-8'});
|
|
183
|
-
}
|
|
184
|
-
catch (err) {
|
|
185
|
-
console.error('\n** embedding worker failed. make sure the worker for this version exists before building module.\n');
|
|
186
|
-
throw err;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const config = {
|
|
191
|
-
|
|
192
|
-
metafile: metafile||license, // only if necessary
|
|
193
|
-
watch: watch ? {
|
|
194
|
-
onRebuild(error, result) {
|
|
195
|
-
if (error) console.error('watch build failed:', error)
|
|
196
|
-
else console.log('watch build succeeded:', result)
|
|
197
|
-
},
|
|
198
|
-
} : undefined,
|
|
199
|
-
minify: !!production,
|
|
200
|
-
banner: {
|
|
201
|
-
js: banner,
|
|
202
|
-
css: banner,
|
|
203
|
-
},
|
|
204
|
-
define: {
|
|
205
|
-
'process.env.WORKER_TEXT': worker_text ? JSON.stringify(worker_text) :`""`,
|
|
206
|
-
'process.env.NODE_ENV': `"${version_str}"`,
|
|
207
|
-
'process.env.BUILD_VERSION': `"${package.version}"`,
|
|
208
|
-
'process.env.BUILD_NAME': `"${package.name}"`,
|
|
209
|
-
...build_entry_replacements,
|
|
210
|
-
},
|
|
211
|
-
bundle: true,
|
|
212
|
-
tsconfig: './treb-embed/modern.tsconfig.json',
|
|
213
|
-
plugins: [
|
|
214
|
-
LoadPlugin({
|
|
215
|
-
tags: [
|
|
216
|
-
{ tag: 'tmpl',
|
|
217
|
-
trim_lines: true,
|
|
218
|
-
remove_html_comments: true,
|
|
219
|
-
icons: {
|
|
220
|
-
tag: 'icon',
|
|
221
|
-
dir: path.resolve(__dirname, 'treb-embed', 'icons', '4'),
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
{ tag: 'composite', trim_lines: true, remove_tag: true, },
|
|
225
|
-
{ tag: 'css', remove_whitespace: true, remove_tag: true, },
|
|
226
|
-
],
|
|
227
|
-
version,
|
|
228
|
-
}),
|
|
229
|
-
],
|
|
230
|
-
outdir : version === 'module' ? path.join(outdir, 'esm') : outdir,
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
switch (version) {
|
|
234
|
-
case 'modern':
|
|
235
|
-
config.entryPoints = modern_entry;
|
|
236
|
-
config.plugins.push(sass_style);
|
|
237
|
-
break;
|
|
238
|
-
|
|
239
|
-
case 'module':
|
|
240
|
-
config.entryPoints = module_entry;
|
|
241
|
-
config.format = 'esm';
|
|
242
|
-
config.outExtension = { '.js': '.mjs' };
|
|
243
|
-
config.plugins.push(sass_default);
|
|
244
|
-
break;
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return config;
|
|
250
|
-
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// ---- run builder ------------------------------------------------------------
|
|
254
|
-
|
|
255
|
-
const Run = async () => {
|
|
256
|
-
|
|
257
|
-
// writing to "current", and we will copy to versioned dir.
|
|
258
|
-
|
|
259
|
-
outdir = path.join(outdir_parent, 'current');
|
|
260
|
-
await fs.promises.mkdir(outdir, { recursive: true });
|
|
261
|
-
|
|
262
|
-
// FIXME: clean should -r ?
|
|
263
|
-
|
|
264
|
-
if (clean) {
|
|
265
|
-
await new Promise((resolve) => {
|
|
266
|
-
child_process.exec(`rm -r ${path.join(outdir, '*')}`, () => resolve());
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// modern version includes all support files
|
|
271
|
-
|
|
272
|
-
if (version.modern) {
|
|
273
|
-
console.info(`building modern (${version_str})...`);
|
|
274
|
-
const result = await esbuild.build(GenerateConfig('modern'));
|
|
275
|
-
if (result.metafile) {
|
|
276
|
-
if (metafile) {
|
|
277
|
-
await fs.promises.writeFile(
|
|
278
|
-
path.join(outdir, 'metafile.json'),
|
|
279
|
-
JSON.stringify(result.metafile, undefined, 2), { encoding: 'utf8' });
|
|
280
|
-
}
|
|
281
|
-
if (license) {
|
|
282
|
-
const licenses = await license_plugin.GenerateLicenseFile(result.metafile);
|
|
283
|
-
await fs.promises.writeFile(path.join(outdir, '3d_party.txt'), licenses, { encoding: 'utf8' });
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// module must be after modern, if we are embedding worker
|
|
289
|
-
|
|
290
|
-
if (version.module) {
|
|
291
|
-
console.info(`building module (${version_str})...`);
|
|
292
|
-
await esbuild.build(GenerateConfig('module'));
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const versioned_dir = path.join(outdir_parent, package.version);
|
|
296
|
-
await fs.promises.mkdir(versioned_dir, { recursive: true });
|
|
297
|
-
|
|
298
|
-
await new Promise((resolve) => {
|
|
299
|
-
child_process.exec(`cp -r ${path.join(outdir, '*')} ${versioned_dir}`, () => resolve());
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
Run();
|
|
305
|
-
|