@trebco/treb 25.4.2 → 25.5.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/dist/treb-spreadsheet.mjs +5 -5
- package/dist/treb.d.ts +2 -2
- package/package.json +1 -1
- package/treb-base-types/src/theme.ts +0 -11
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +47 -0
- package/treb-embed/src/embedded-spreadsheet.ts +28 -3
- package/treb-embed/src/options.ts +11 -0
- package/treb-embed/src/types.ts +1 -0
- package/treb-embed/style/theme-defaults.scss +5 -0
package/dist/treb.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! API v25.
|
|
1
|
+
/*! API v25.5. 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
|
|
@@ -1210,7 +1210,7 @@ export interface TableSortOptions {
|
|
|
1210
1210
|
asc: boolean;
|
|
1211
1211
|
}
|
|
1212
1212
|
export type TableSortType = 'text' | 'numeric' | 'auto';
|
|
1213
|
-
export declare type LoadSource = "drag-and-drop" | "local-file" | "network-file" | "local-storage" | "undo";
|
|
1213
|
+
export declare type LoadSource = "drag-and-drop" | "local-file" | "network-file" | "local-storage" | "inline-document" | "undo";
|
|
1214
1214
|
|
|
1215
1215
|
/**
|
|
1216
1216
|
* EmbeddedSheetEvent is a discriminated union. Switch on the `type` field
|
package/package.json
CHANGED
|
@@ -528,17 +528,6 @@ export const LoadThemeProperties = (container: HTMLElement): Theme => {
|
|
|
528
528
|
theme.offset_light = css.color;
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
/*
|
|
532
|
-
css = CSS('grid-background');
|
|
533
|
-
if (css.backgroundImage) {
|
|
534
|
-
const match = css.backgroundImage.match(/url\("*(.*?)"*\)/);
|
|
535
|
-
if (match) {
|
|
536
|
-
theme.background_image = new Image();
|
|
537
|
-
theme.background_image.src = match[1];
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
*/
|
|
541
|
-
|
|
542
531
|
// this _is_ painted, but it doesn't necessarily need to be -- we
|
|
543
532
|
// could use a node. that would require moving it around, though.
|
|
544
533
|
// let's leave it for now.
|
|
@@ -208,6 +208,10 @@ export class SpreadsheetConstructor {
|
|
|
208
208
|
case 'data-treb':
|
|
209
209
|
continue;
|
|
210
210
|
|
|
211
|
+
// has special handling as an attribute
|
|
212
|
+
case 'inline-document':
|
|
213
|
+
continue;
|
|
214
|
+
|
|
211
215
|
// special case
|
|
212
216
|
case 'src':
|
|
213
217
|
attribute_options.document = this.root.getAttribute('src') || undefined;
|
|
@@ -255,6 +259,49 @@ export class SpreadsheetConstructor {
|
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
|
|
262
|
+
// inline-document means look in the tag contents for a script
|
|
263
|
+
// element, and use that. the script must have type "application/json",
|
|
264
|
+
// and if it has a name, the name must match the value of the
|
|
265
|
+
// inline-document attribute.
|
|
266
|
+
//
|
|
267
|
+
// so either
|
|
268
|
+
//
|
|
269
|
+
// <treb-spreadsheet inline-document>
|
|
270
|
+
// <script type="application/json">{ ... }</script>
|
|
271
|
+
// </treb-spreadsheet>
|
|
272
|
+
//
|
|
273
|
+
// or
|
|
274
|
+
//
|
|
275
|
+
// <treb-spreadsheet inline-document="xyz">
|
|
276
|
+
// <script type="application/json" name="xyz">{ ... }</script>
|
|
277
|
+
// </treb-spreadsheet>
|
|
278
|
+
|
|
279
|
+
if (this.root.hasAttribute('inline-document')) {
|
|
280
|
+
const inline_name = this.root.getAttribute('inline-document') || '';
|
|
281
|
+
for (const element of Array.from(this.root.children)) {
|
|
282
|
+
if (element instanceof HTMLScriptElement) {
|
|
283
|
+
if (element.type === 'application/json') {
|
|
284
|
+
const name = element.getAttribute('name') || '';
|
|
285
|
+
if (name === inline_name) {
|
|
286
|
+
const content = element.textContent;
|
|
287
|
+
if (content) {
|
|
288
|
+
try {
|
|
289
|
+
options.inline_document = JSON.parse(content);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
console.error(err);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (!options.inline_document) {
|
|
301
|
+
console.warn('inline document failed');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
258
305
|
this.root.innerHTML = html;
|
|
259
306
|
options.container = this.root.querySelector('.treb-layout-spreadsheet') as HTMLElement;
|
|
260
307
|
|
|
@@ -506,11 +506,15 @@ export class EmbeddedSpreadsheet {
|
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
+
if (this.options.document && this.options.inline_document) {
|
|
510
|
+
console.warn('both document and inline-document are provided');
|
|
511
|
+
}
|
|
512
|
+
|
|
509
513
|
const network_document = this.options.document;
|
|
510
514
|
|
|
511
515
|
// optionally data from storage, with fallback
|
|
512
516
|
|
|
513
|
-
let data: string | undefined;
|
|
517
|
+
let data: string | undefined | TREBDocument;
|
|
514
518
|
let source: LoadSource | undefined;
|
|
515
519
|
|
|
516
520
|
// don't load if we're a split view. we can also skip the
|
|
@@ -523,6 +527,14 @@ export class EmbeddedSpreadsheet {
|
|
|
523
527
|
}
|
|
524
528
|
}
|
|
525
529
|
|
|
530
|
+
// if we have an inline document, and there was nothing in local storage,
|
|
531
|
+
// load the inline document now. not for splits.
|
|
532
|
+
|
|
533
|
+
if (!data && !this.options.toll_initial_load && !options.model && options.inline_document) {
|
|
534
|
+
data = options.inline_document;
|
|
535
|
+
source = LoadSource.INLINE_DOCUMENT;
|
|
536
|
+
}
|
|
537
|
+
|
|
526
538
|
// this one should not be done for a split view, but we should still
|
|
527
539
|
// do it if the toll flag is set, and storage key is set.
|
|
528
540
|
|
|
@@ -858,8 +870,12 @@ export class EmbeddedSpreadsheet {
|
|
|
858
870
|
// FIXME: this should yield so we can subscribe to events before the initial load
|
|
859
871
|
|
|
860
872
|
if (data) {
|
|
861
|
-
|
|
862
|
-
|
|
873
|
+
if (typeof data === 'string') {
|
|
874
|
+
data = JSON.parse(data);
|
|
875
|
+
}
|
|
876
|
+
if (data) {
|
|
877
|
+
this.LoadDocument(data as TREBDocument, { recalculate: !!this.options.recalculate, source});
|
|
878
|
+
}
|
|
863
879
|
}
|
|
864
880
|
else if (!network_document) {
|
|
865
881
|
|
|
@@ -2307,6 +2323,15 @@ export class EmbeddedSpreadsheet {
|
|
|
2307
2323
|
*/
|
|
2308
2324
|
public Revert(): void {
|
|
2309
2325
|
|
|
2326
|
+
if (this.options.inline_document) {
|
|
2327
|
+
this.LoadDocument(this.options.inline_document);
|
|
2328
|
+
if (this.options.storage_key) {
|
|
2329
|
+
this.SaveLocalStorage('reverted_backup');
|
|
2330
|
+
localStorage.removeItem(this.options.storage_key);
|
|
2331
|
+
}
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2310
2335
|
const canonical = this.options.document;
|
|
2311
2336
|
|
|
2312
2337
|
if (canonical) {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { ICellAddress } from 'treb-base-types';
|
|
23
|
+
import type { TREBDocument } from './types';
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* options for exporting CSV/TSV
|
|
@@ -97,6 +98,16 @@ export interface EmbeddedSpreadsheetOptions {
|
|
|
97
98
|
*/
|
|
98
99
|
document?: string;
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @internal - testing
|
|
103
|
+
*
|
|
104
|
+
* load document directly from data. obeys the same rules as `document`
|
|
105
|
+
* regarding local storage and revert. if you provide both document and
|
|
106
|
+
* inline_document we will show a warning, but inline_document will take
|
|
107
|
+
* precedence.
|
|
108
|
+
*/
|
|
109
|
+
inline_document?: TREBDocument;
|
|
110
|
+
|
|
100
111
|
/**
|
|
101
112
|
* fetch network document (URI)
|
|
102
113
|
* @deprecated - use `document`
|
package/treb-embed/src/types.ts
CHANGED
|
@@ -182,9 +182,14 @@ $text-reference-color-5: rgb(254, 47, 1);
|
|
|
182
182
|
background: var(--treb-grid-background, #fff);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/*
|
|
186
|
+
* we stopped using this in favor of sheet backgrounds. although
|
|
187
|
+
* there's a case to be made for the static background as well.
|
|
188
|
+
*
|
|
185
189
|
.grid-background {
|
|
186
190
|
background-image: var(--treb-grid-background-image, none);
|
|
187
191
|
}
|
|
192
|
+
*/
|
|
188
193
|
|
|
189
194
|
/**
|
|
190
195
|
* this is used for freeze-area highlights
|