gridjs-spreadsheet 26.6.2 → 26.7.1

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 (60) hide show
  1. package/angular.d.ts +67 -0
  2. package/angular.js +174 -0
  3. package/example/README.md +242 -41
  4. package/example/angular-gridjs/.nvmrc +1 -0
  5. package/example/angular-gridjs/angular.json +66 -0
  6. package/example/angular-gridjs/package.json +31 -0
  7. package/example/angular-gridjs/proxy.conf.json +12 -0
  8. package/example/angular-gridjs/src/app/api.ts +7 -0
  9. package/example/angular-gridjs/src/app/app.component.html +57 -0
  10. package/example/angular-gridjs/src/app/app.component.ts +153 -0
  11. package/example/angular-gridjs/src/app/routing.ts +52 -0
  12. package/example/angular-gridjs/src/favicon.ico +0 -0
  13. package/example/angular-gridjs/src/index.html +12 -0
  14. package/example/angular-gridjs/src/main.ts +7 -0
  15. package/example/angular-gridjs/src/styles.css +37 -0
  16. package/example/angular-gridjs/tsconfig.app.json +9 -0
  17. package/example/angular-gridjs/tsconfig.json +29 -0
  18. package/example/pom.xml +3 -3
  19. package/example/react-gridjs/index.html +12 -0
  20. package/example/react-gridjs/package.json +20 -0
  21. package/example/react-gridjs/src/App.jsx +188 -0
  22. package/example/react-gridjs/src/api.js +7 -0
  23. package/example/react-gridjs/src/main.jsx +9 -0
  24. package/example/react-gridjs/src/routing.js +51 -0
  25. package/example/react-gridjs/src/styles.css +37 -0
  26. package/example/react-gridjs/vite.config.js +16 -0
  27. package/example/src/main/java/com/aspose/gridjs/demo/controller/DataController.java +80 -2
  28. package/example/src/main/java/com/aspose/gridjs/demo/controller/GridJs2Controller.java +12 -0
  29. package/example/vanilla-gridjs/npm/index.html +29 -0
  30. package/example/vanilla-gridjs/npm/main.js +8 -0
  31. package/example/vanilla-gridjs/npm/package.json +16 -0
  32. package/example/vanilla-gridjs/npm/vite.config.js +11 -0
  33. package/example/vanilla-gridjs/script/index.html +32 -0
  34. package/example/vanilla-gridjs/script/main.js +9 -0
  35. package/example/vanilla-gridjs/script/package.json +12 -0
  36. package/example/vanilla-gridjs/script/vite.config.js +11 -0
  37. package/example/vanilla-gridjs/shared/demo-app.js +205 -0
  38. package/example/vanilla-gridjs/shared/styles.css +36 -0
  39. package/example/vue-gridjs/index.html +12 -0
  40. package/example/vue-gridjs/package.json +19 -0
  41. package/example/vue-gridjs/src/App.vue +199 -0
  42. package/example/vue-gridjs/src/api.js +7 -0
  43. package/example/vue-gridjs/src/main.js +9 -0
  44. package/example/vue-gridjs/src/routing.js +51 -0
  45. package/example/vue-gridjs/src/styles.css +37 -0
  46. package/example/vue-gridjs/vite.config.js +21 -0
  47. package/index.d.ts +58 -1
  48. package/index.js +1 -1
  49. package/package.json +170 -50
  50. package/react.d.ts +27 -0
  51. package/react.js +111 -0
  52. package/readme.md +470 -318
  53. package/shared.d.ts +66 -0
  54. package/shared.js +204 -0
  55. package/vue.d.ts +20 -0
  56. package/vue.js +125 -0
  57. package/xspreadsheet.css +7 -0
  58. package/xspreadsheet.js +3 -3
  59. package/example/.mvn/wrapper/maven-wrapper.properties +0 -18
  60. package/example/src/test/java/com/aspose/gridjs/demo/GridjsdemoApplicationTests.java +0 -1441
package/shared.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import type Spreadsheet from 'gridjs-spreadsheet';
2
+
3
+ export interface GridJsEndpoints {
4
+ updateCell: string;
5
+ imageUrl: string;
6
+ addImage: string;
7
+ addImageByUrl: string;
8
+ copyImage: string;
9
+ download: string;
10
+ ole: string;
11
+ lazyLoading: string;
12
+ }
13
+
14
+ export interface GridJsAdapterCallbacks {
15
+ ready?: (instance: Spreadsheet, adapter: GridJsAdapter) => void;
16
+ change?: (...args: any[]) => void;
17
+ error?: (payload: any) => void;
18
+ cellSelected?: (...args: any[]) => void;
19
+ cellEdited?: (...args: any[]) => void;
20
+ sheetSelected?: (...args: any[]) => void;
21
+ sheetLoaded?: (...args: any[]) => void;
22
+ }
23
+
24
+ export interface GridJsAdapterDependencies {
25
+ globalObject?: any;
26
+ jszip?: any;
27
+ importJSZip?: () => Promise<any>;
28
+ importGridJs?: () => Promise<any>;
29
+ }
30
+
31
+ export interface GridJsAdapterConfig {
32
+ container: HTMLElement;
33
+ apiBase?: string;
34
+ endpoints?: Partial<GridJsEndpoints>;
35
+ data?: any;
36
+ loader?: () => Promise<any> | any;
37
+ mode?: 'edit' | 'read';
38
+ locale?: string;
39
+ local?: string;
40
+ token?: string;
41
+ height?: string | number;
42
+ showToolbar?: boolean;
43
+ showContextmenu?: boolean;
44
+ updateMode?: string;
45
+ loadingGif?: string;
46
+ activeSheetName?: string;
47
+ uniqueid?: string;
48
+ fileName?: string;
49
+ basicZorder?: number;
50
+ view?: Record<string, any>;
51
+ callbacks?: GridJsAdapterCallbacks;
52
+ dependencies?: GridJsAdapterDependencies;
53
+ }
54
+
55
+ export interface GridJsAdapter {
56
+ instance: Spreadsheet;
57
+ payload: any;
58
+ endpoints: GridJsEndpoints;
59
+ refreshToken(token: string): void;
60
+ getData(): any;
61
+ getUpdateDatas(): any;
62
+ destroy(): void;
63
+ }
64
+
65
+ export function makeGridJsEndpoints(apiBase?: string): GridJsEndpoints;
66
+ export function createGridJsAdapter(config: GridJsAdapterConfig): Promise<GridJsAdapter>;
package/shared.js ADDED
@@ -0,0 +1,204 @@
1
+ const DEFAULT_Z_ORDER = 5678;
2
+
3
+ function trimTrailingSlash(value) {
4
+ return String(value || '').replace(/\/+$/, '');
5
+ }
6
+
7
+ function joinEndpoint(apiBase, path) {
8
+ const normalizedBase = trimTrailingSlash(apiBase);
9
+ return `${normalizedBase}${path}`;
10
+ }
11
+
12
+ export function makeGridJsEndpoints(apiBase = '') {
13
+ return {
14
+ updateCell: joinEndpoint(apiBase, '/GridJs2/UpdateCell'),
15
+ imageUrl: joinEndpoint(apiBase, '/GridJs2/ImageUrl'),
16
+ addImage: joinEndpoint(apiBase, '/GridJs2/AddImage'),
17
+ addImageByUrl: joinEndpoint(apiBase, '/GridJs2/AddImageByURL'),
18
+ copyImage: joinEndpoint(apiBase, '/GridJs2/CopyImage'),
19
+ download: joinEndpoint(apiBase, '/GridJs2/Download'),
20
+ ole: joinEndpoint(apiBase, '/GridJs2/Ole'),
21
+ lazyLoading: joinEndpoint(apiBase, '/GridJs2/LazyLoadingStreamJson'),
22
+ };
23
+ }
24
+
25
+ function getBrowserGlobal(explicitGlobal) {
26
+ if (explicitGlobal) return explicitGlobal;
27
+ if (typeof window !== 'undefined') return window;
28
+ return globalThis;
29
+ }
30
+
31
+ async function resolveImportedDependency(importer) {
32
+ const mod = await importer();
33
+ return mod.default || mod;
34
+ }
35
+
36
+ async function resolveDependency({
37
+ provided,
38
+ importer,
39
+ globalObject,
40
+ globalNames,
41
+ moduleName,
42
+ }) {
43
+ if (provided) return provided;
44
+ if (importer) return resolveImportedDependency(importer);
45
+
46
+ for (const globalName of globalNames) {
47
+ if (globalObject[globalName]) return globalObject[globalName];
48
+ }
49
+
50
+ throw new Error(`GridJS wrapper requires ${moduleName}. Pass it through dependencies or expose it on window.`);
51
+ }
52
+
53
+ async function ensureRuntimeDependencies(dependencies = {}) {
54
+ const globalObject = getBrowserGlobal(dependencies.globalObject);
55
+ const jszip = await resolveDependency({
56
+ provided: dependencies.jszip,
57
+ importer: dependencies.importJSZip,
58
+ globalObject,
59
+ globalNames: ['JSZip'],
60
+ moduleName: 'jszip',
61
+ });
62
+
63
+ globalObject.JSZip = jszip;
64
+
65
+ return { globalObject, jszip };
66
+ }
67
+
68
+ async function loadGridJs(dependencies = {}) {
69
+ if (dependencies.importGridJs) {
70
+ return dependencies.importGridJs();
71
+ }
72
+
73
+ const globalObject = getBrowserGlobal(dependencies.globalObject);
74
+ if (globalObject['gridjs-spreadsheet']) {
75
+ return globalObject['gridjs-spreadsheet'];
76
+ }
77
+ if (globalObject.x_spreadsheet) {
78
+ return { default: globalObject.x_spreadsheet };
79
+ }
80
+
81
+ throw new Error('GridJS wrapper requires gridjs-spreadsheet. Pass dependencies.importGridJs or load the UMD script first.');
82
+ }
83
+
84
+ async function resolveGridJsPayload({ data, loader }) {
85
+ if (data) return data;
86
+ if (typeof loader === 'function') return loader();
87
+ throw new Error('GridJS wrapper requires either data or loader.');
88
+ }
89
+
90
+ function getSheets(payload) {
91
+ if (!payload) return [];
92
+ if (Array.isArray(payload)) return payload;
93
+ return payload.data || [];
94
+ }
95
+
96
+ function callIfPresent(target, methodName, ...args) {
97
+ if (target && typeof target[methodName] === 'function') {
98
+ target[methodName](...args);
99
+ }
100
+ }
101
+
102
+ function bindEvent(instance, eventName, callback) {
103
+ if (typeof callback === 'function' && instance && typeof instance.on === 'function') {
104
+ instance.on(eventName, callback);
105
+ }
106
+ }
107
+
108
+ function buildSpreadsheetOptions(config, endpoints) {
109
+ const lang = config.locale || config.local || 'en';
110
+
111
+ return {
112
+ updateMode: config.updateMode || 'server',
113
+ updateUrl: endpoints.updateCell,
114
+ showToolbar: config.showToolbar !== false,
115
+ showContextmenu: config.showContextmenu !== false,
116
+ mode: config.mode || 'edit',
117
+ local: lang,
118
+ locale: lang,
119
+ ...(config.token ? { token: config.token } : {}),
120
+ ...(config.loadingGif ? { loadingGif: config.loadingGif } : {}),
121
+ ...(config.view ? { view: config.view } : {}),
122
+ };
123
+ }
124
+
125
+ export async function createGridJsAdapter(config) {
126
+ if (!config || !config.container) {
127
+ throw new Error('GridJS wrapper requires a container element.');
128
+ }
129
+
130
+ const callbacks = config.callbacks || {};
131
+ const endpoints = {
132
+ ...makeGridJsEndpoints(config.apiBase),
133
+ ...(config.endpoints || {}),
134
+ };
135
+ const payload = await resolveGridJsPayload(config);
136
+ await ensureRuntimeDependencies(config.dependencies);
137
+
138
+ const gridJsModule = await loadGridJs(config.dependencies);
139
+ const Spreadsheet = gridJsModule.default || gridJsModule.Spreadsheet || gridJsModule;
140
+ const options = buildSpreadsheetOptions(config, endpoints);
141
+ const instance = new Spreadsheet(config.container, options);
142
+ let destroyed = false;
143
+
144
+ instance.loadData(getSheets(payload), config.activeSheetName || payload?.actname);
145
+ callIfPresent(instance, 'setUniqueId', payload?.uniqueid || config.uniqueid || '');
146
+ callIfPresent(instance, 'setFileName', payload?.filename || config.fileName || '');
147
+ callIfPresent(
148
+ instance,
149
+ 'setImageInfo',
150
+ endpoints.imageUrl,
151
+ endpoints.addImage,
152
+ endpoints.addImageByUrl,
153
+ endpoints.copyImage,
154
+ config.basicZorder || DEFAULT_Z_ORDER,
155
+ config.loadingGif,
156
+ );
157
+ callIfPresent(instance, 'setFileDownloadInfo', endpoints.download);
158
+ callIfPresent(instance, 'setOleDownloadInfo', endpoints.ole);
159
+ callIfPresent(instance, 'setLazyLoadingUrl', endpoints.lazyLoading);
160
+
161
+ if (typeof callbacks.change === 'function' && typeof instance.change === 'function') {
162
+ instance.change(callbacks.change);
163
+ }
164
+ if (typeof callbacks.error === 'function') {
165
+ callIfPresent(instance, 'updateServerError', (xhr, textStatus, errorThrown) => {
166
+ callbacks.error({ type: 'updateServerError', xhr, textStatus, errorThrown });
167
+ });
168
+ callIfPresent(instance, 'updateCellError', (message) => {
169
+ callbacks.error({ type: 'updateCellError', message });
170
+ });
171
+ }
172
+
173
+ bindEvent(instance, 'cell-selected', callbacks.cellSelected);
174
+ bindEvent(instance, 'cell-edited', callbacks.cellEdited);
175
+ bindEvent(instance, 'sheet-selected', callbacks.sheetSelected);
176
+ bindEvent(instance, 'sheet-loaded', callbacks.sheetLoaded);
177
+
178
+ const adapter = {
179
+ instance,
180
+ payload,
181
+ endpoints,
182
+ refreshToken(token) {
183
+ callIfPresent(instance, 'refreshToken', token);
184
+ },
185
+ getData() {
186
+ return typeof instance.getData === 'function' ? instance.getData() : null;
187
+ },
188
+ getUpdateDatas() {
189
+ return typeof instance.getUpdateDatas === 'function' ? instance.getUpdateDatas() : null;
190
+ },
191
+ destroy() {
192
+ if (destroyed) return;
193
+ destroyed = true;
194
+ callIfPresent(instance, 'destroy');
195
+ config.container.innerHTML = '';
196
+ },
197
+ };
198
+
199
+ if (typeof callbacks.ready === 'function') {
200
+ callbacks.ready(instance, adapter);
201
+ }
202
+
203
+ return adapter;
204
+ }
package/vue.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { DefineComponent } from 'vue';
2
+ import type Spreadsheet from 'gridjs-spreadsheet';
3
+ import type { GridJsAdapter } from './shared';
4
+
5
+ export interface GridJsSpreadsheetProps {
6
+ apiBase?: string;
7
+ data?: any;
8
+ loader?: () => Promise<any> | any;
9
+ mode?: 'edit' | 'read';
10
+ locale?: string;
11
+ token?: string;
12
+ height?: string | number;
13
+ showToolbar?: boolean;
14
+ showContextmenu?: boolean;
15
+ }
16
+
17
+ export declare const GridJsSpreadsheet: DefineComponent<GridJsSpreadsheetProps, {}, any>;
18
+ export default GridJsSpreadsheet;
19
+
20
+ export type GridJsReadyHandler = (instance: Spreadsheet, adapter: GridJsAdapter) => void;
package/vue.js ADDED
@@ -0,0 +1,125 @@
1
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, toRaw, watch } from 'vue';
2
+ import { createGridJsAdapter } from './shared.js';
3
+
4
+ function clonePlain(value) {
5
+ const rawValue = toRaw(value);
6
+ if (typeof structuredClone === 'function') {
7
+ try {
8
+ return structuredClone(rawValue);
9
+ } catch {
10
+ // Vue props can contain reactive proxies. Fall back to JSON cloning after
11
+ // unwrapping the top-level proxy.
12
+ }
13
+ }
14
+ return JSON.parse(JSON.stringify(rawValue));
15
+ }
16
+
17
+ function importGridJs() {
18
+ return import('gridjs-spreadsheet');
19
+ }
20
+
21
+ export const GridJsSpreadsheet = defineComponent({
22
+ name: 'GridJsSpreadsheet',
23
+ props: {
24
+ apiBase: { type: String, default: '' },
25
+ data: { type: Object, default: null },
26
+ loader: { type: Function, default: null },
27
+ mode: { type: String, default: 'edit' },
28
+ locale: { type: String, default: 'en' },
29
+ token: { type: String, default: '' },
30
+ height: { type: [String, Number], default: 'calc(100vh - 96px)' },
31
+ showToolbar: { type: Boolean, default: true },
32
+ showContextmenu: { type: Boolean, default: true },
33
+ },
34
+ emits: [
35
+ 'ready',
36
+ 'change',
37
+ 'error',
38
+ 'cell-selected',
39
+ 'cell-edited',
40
+ 'sheet-selected',
41
+ 'sheet-loaded',
42
+ ],
43
+ setup(props, { emit }) {
44
+ const host = ref(null);
45
+ let adapter = null;
46
+
47
+ async function mountGridJs() {
48
+ if (!host.value || (!props.data && !props.loader)) return;
49
+ adapter?.destroy();
50
+ host.value.innerHTML = '';
51
+
52
+ adapter = await createGridJsAdapter({
53
+ container: host.value,
54
+ apiBase: props.apiBase,
55
+ data: props.data ? clonePlain(props.data) : undefined,
56
+ loader: props.loader,
57
+ mode: props.mode,
58
+ locale: props.locale,
59
+ token: props.token,
60
+ showToolbar: props.showToolbar,
61
+ showContextmenu: props.showContextmenu,
62
+ callbacks: {
63
+ ready: (instance, activeAdapter) => emit('ready', instance, activeAdapter),
64
+ change: (...args) => emit('change', ...args),
65
+ error: payload => emit('error', payload),
66
+ cellSelected: (...args) => emit('cell-selected', ...args),
67
+ cellEdited: (...args) => emit('cell-edited', ...args),
68
+ sheetSelected: (...args) => emit('sheet-selected', ...args),
69
+ sheetLoaded: (...args) => emit('sheet-loaded', ...args),
70
+ },
71
+ dependencies: {
72
+ importJSZip: () => import('jszip'),
73
+ importGridJs,
74
+ },
75
+ });
76
+ }
77
+
78
+ watch(
79
+ () => [
80
+ props.data?.uniqueid,
81
+ props.data?.filename,
82
+ props.apiBase,
83
+ props.mode,
84
+ props.locale,
85
+ props.showToolbar,
86
+ props.showContextmenu,
87
+ ],
88
+ () => {
89
+ mountGridJs().catch(error => emit('error', { type: 'mountError', error }));
90
+ },
91
+ { immediate: true },
92
+ );
93
+
94
+ watch(
95
+ () => props.token,
96
+ token => {
97
+ if (adapter && token) {
98
+ adapter.refreshToken(token);
99
+ }
100
+ },
101
+ );
102
+
103
+ onMounted(() => {
104
+ mountGridJs().catch(error => emit('error', { type: 'mountError', error }));
105
+ });
106
+
107
+ onBeforeUnmount(() => {
108
+ adapter?.destroy();
109
+ adapter = null;
110
+ if (host.value) host.value.innerHTML = '';
111
+ });
112
+
113
+ return () => h('div', {
114
+ ref: host,
115
+ class: 'gridjs-vue-host',
116
+ style: {
117
+ width: '100%',
118
+ height: props.height,
119
+ background: '#ffffff',
120
+ },
121
+ });
122
+ },
123
+ });
124
+
125
+ export default GridJsSpreadsheet;
package/xspreadsheet.css CHANGED
@@ -46,6 +46,7 @@ body {
46
46
  box-shadow: 1px 1px 3px -1px rgba(0, 0, 0, 0.3);
47
47
  }
48
48
  .x-spreadsheet-comment-tip {
49
+ box-sizing: border-box;
49
50
  font-family: inherit;
50
51
  position: absolute;
51
52
  padding: 5px 10px;
@@ -53,6 +54,12 @@ body {
53
54
  border-radius: 1px;
54
55
  background: #ffffe1;
55
56
  font-size: 12px;
57
+ max-width: min(720px, calc(100vw - 16px));
58
+ max-height: min(420px, 45vh, calc(100vh - 16px));
59
+ overflow: auto;
60
+ white-space: normal;
61
+ overflow-wrap: anywhere;
62
+ word-break: break-word;
56
63
  z-index: 201;
57
64
  }
58
65
  .x-spreadsheet-comment-tip:before {