@corbe30/fortune-excel 1.0.3 → 1.0.4

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 (102) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +24 -24
  3. package/dist/HandleZip.js +90 -34
  4. package/dist/ImportHelper.d.ts +2 -0
  5. package/dist/ImportHelper.js +51 -0
  6. package/dist/ToExcel/ExcelBorder.js +141 -141
  7. package/dist/ToExcel/ExcelConvert.js +19 -8
  8. package/dist/ToExcel/ExcelFile.js +66 -22
  9. package/dist/ToExcel/ExcelImage.js +27 -17
  10. package/dist/ToExcel/ExcelStyle.js +7 -7
  11. package/dist/ToFortuneSheet/FortuneBase.js +84 -28
  12. package/dist/ToFortuneSheet/FortuneCell.js +205 -185
  13. package/dist/ToFortuneSheet/FortuneFile.js +117 -111
  14. package/dist/ToFortuneSheet/FortuneImage.js +35 -15
  15. package/dist/ToFortuneSheet/FortuneSheet.js +217 -191
  16. package/dist/ToFortuneSheet/ReadXml.js +114 -87
  17. package/dist/ToolbarItem.d.ts +12 -0
  18. package/dist/ToolbarItem.js +67 -0
  19. package/dist/Transform.d.ts +2 -0
  20. package/dist/Transform.js +78 -0
  21. package/dist/common/constant.js +24 -24
  22. package/dist/common/emf.js +5 -5
  23. package/dist/common/method.js +169 -162
  24. package/dist/icons/ExportIcon.d.ts +3 -0
  25. package/dist/icons/ExportIcon.js +7 -0
  26. package/dist/icons/ImportIcon.d.ts +3 -0
  27. package/dist/icons/ImportIcon.js +7 -0
  28. package/dist/main.d.ts +2 -2
  29. package/dist/main.js +2 -24
  30. package/package.json +2 -2
  31. package/storybook-static/assets/Color-6VNJS4EI-0c01ecf9.js +1 -0
  32. package/storybook-static/assets/DocsRenderer-NNNQARDV-8c85b0e9.js +364 -0
  33. package/storybook-static/assets/Page.stories-2589ebf6.css +1 -0
  34. package/storybook-static/assets/Page.stories-a573643a.js +1948 -0
  35. package/storybook-static/assets/WithTooltip-V3YHNWJZ-a3f0d923.js +1 -0
  36. package/storybook-static/assets/_commonjs-dynamic-modules-302442b1.js +1 -0
  37. package/storybook-static/assets/_commonjsHelpers-de833af9.js +1 -0
  38. package/storybook-static/assets/_getPrototype-1e53b583.js +3 -0
  39. package/storybook-static/assets/entry-preview-b21759a2.js +1 -0
  40. package/storybook-static/assets/entry-preview-docs-d14f77b2.js +54 -0
  41. package/storybook-static/assets/formatter-SWP5E3XI-02b41ceb.js +156 -0
  42. package/storybook-static/assets/iframe-b3040d49.js +1 -0
  43. package/storybook-static/assets/index-1b441bc2.js +1 -0
  44. package/storybook-static/assets/index-356e4a49.js +6 -0
  45. package/storybook-static/assets/index-8b3efc3f.js +9 -0
  46. package/storybook-static/assets/index-9322cee5.js +1 -0
  47. package/storybook-static/assets/preview-0ef86afd.js +7 -0
  48. package/storybook-static/assets/preview-1970e752.js +1 -0
  49. package/storybook-static/assets/preview-2d30111f.js +27 -0
  50. package/storybook-static/assets/preview-2ff2accb.js +1 -0
  51. package/storybook-static/assets/preview-30b54f76.js +20 -0
  52. package/storybook-static/assets/preview-ba2273f4.js +1 -0
  53. package/storybook-static/assets/preview-c56bf6ac.js +1 -0
  54. package/storybook-static/assets/preview-d01b88e8.js +17 -0
  55. package/storybook-static/assets/preview-da31036b.js +396 -0
  56. package/storybook-static/assets/react-18-0a210e0b.js +24 -0
  57. package/storybook-static/assets/syntaxhighlighter-MJWPISIS-6799d638.js +1 -0
  58. package/storybook-static/favicon.svg +7 -0
  59. package/storybook-static/iframe.html +460 -0
  60. package/storybook-static/index.html +127 -0
  61. package/storybook-static/index.json +1 -0
  62. package/storybook-static/project.json +1 -0
  63. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +3 -0
  64. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js.LEGAL.txt +0 -0
  65. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +12 -0
  66. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js.LEGAL.txt +0 -0
  67. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +63 -0
  68. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js.LEGAL.txt +18 -0
  69. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +3 -0
  70. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js.LEGAL.txt +0 -0
  71. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +3 -0
  72. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js.LEGAL.txt +0 -0
  73. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +3 -0
  74. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js.LEGAL.txt +0 -0
  75. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +3 -0
  76. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js.LEGAL.txt +0 -0
  77. package/storybook-static/sb-addons/interactions-8/manager-bundle.js +12 -0
  78. package/storybook-static/sb-addons/interactions-8/manager-bundle.js.LEGAL.txt +0 -0
  79. package/storybook-static/sb-addons/links-0/manager-bundle.js +3 -0
  80. package/storybook-static/sb-addons/links-0/manager-bundle.js.LEGAL.txt +0 -0
  81. package/storybook-static/sb-common-assets/fonts.css +31 -0
  82. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  83. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  84. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  85. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  86. package/storybook-static/sb-manager/WithTooltip-V3YHNWJZ-MXTFSDU5.js +1 -0
  87. package/storybook-static/sb-manager/chunk-5QAFKPS7.js +7 -0
  88. package/storybook-static/sb-manager/chunk-7PRFHFSS.js +9 -0
  89. package/storybook-static/sb-manager/chunk-XE6LDGTE.js +406 -0
  90. package/storybook-static/sb-manager/chunk-YDUB7CS6.js +348 -0
  91. package/storybook-static/sb-manager/chunk-ZEU7PDD3.js +1 -0
  92. package/storybook-static/sb-manager/formatter-SWP5E3XI-7BGIK6BL.js +156 -0
  93. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  94. package/storybook-static/sb-manager/globals.js +1 -0
  95. package/storybook-static/sb-manager/index.js +1 -0
  96. package/storybook-static/sb-manager/runtime.js +1 -0
  97. package/storybook-static/sb-manager/syntaxhighlighter-MJWPISIS-JOSCT6CQ.js +1 -0
  98. package/storybook-static/sb-preview/globals.js +1 -0
  99. package/storybook-static/sb-preview/runtime.js +112 -0
  100. package/storybook-static/stories.json +1 -0
  101. package/tsconfig.json +4 -3
  102. package/.github/workflows/main.yml +0 -30
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib"
3
+ }
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  FortuneExcel is an import/export library for [FortuneSheet](https://github.com/ruilisi/fortune-sheet/).
4
4
  It only supports .xlsx format files (not .xls).
5
5
 
6
- It is a fork of (now archived) FortuneSheetExcel.
6
+ It is a fork of (now archived) [FortuneSheetExcel](https://github.com/zenmrp/FortuneSheetExcel).
7
7
 
8
8
  ## Features
9
9
 
@@ -16,34 +16,34 @@ Supports the following spreadsheet features in import/export:
16
16
 
17
17
  ## Usage
18
18
 
19
- > NOTE: to be modified as a plugin for FortuneSheet
20
-
21
19
  For best results, import and export a single sheet at a time. Although you can force FortuneExcel to handle multiple sheets, certain configurations may break.
22
20
 
21
+ ### React frontend
22
+ `ImportHelper` is a hidden component and only required when using `importToolBarItem`.
23
23
  ```js
24
- import { transformExcelToFortune } from "FortuneSheetExcel";
25
-
26
- // e.g. got a file input change event
27
- const xls = await e.target.files[0].arrayBuffer();
28
- const fsh = await transformExcelToFortune(xls);
29
- setData(fsh.sheets); // use this as the Workbook data
24
+ import { importToolBarItem, ImportHelper, exportToolBarItem } from "fortune-excel";
25
+
26
+ function App() {
27
+ const workbookRef = useRef();
28
+ const [key, setKey] = useState(0);
29
+ const [sheets, setSheets] = useState(data);
30
+
31
+ return (
32
+ <>
33
+ <ImportHelper setKey={setKey} setSheets={setSheets} sheetRef={workbookRef1} />
34
+ <Workbook
35
+ key={key}
36
+ data={sheets}
37
+ ref={workbookRef}
38
+ customToolbarItems={[exportToolBarItem(workbookRef), importToolBarItem()]}
39
+ />
40
+ </>
41
+ );
42
+ }
30
43
  ```
31
44
 
32
- Interactively in a node repl:
33
-
34
- ```js
35
- f = await (
36
- await import("node:fs/promises")
37
- ).readFile("/home/val/Downloads/Silkscreen.xlsx");
38
- console.log(
39
- (
40
- await (
41
- await import("FortuneSheetExcel")
42
- ).FortuneExcel.transformExcelToFortune(f)
43
- ).toJsonString()
44
- );
45
- // in dev: console.log((await (await import("./dist/main.js")).FortuneExcel.transformExcelToFortune(f)).toJsonString())
46
- ```
45
+ ### Node backend
46
+ to be updated
47
47
 
48
48
  ## Authors and acknowledgment
49
49
 
package/dist/HandleZip.js CHANGED
@@ -1,37 +1,93 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  import JSZip from "jszip";
2
- export class HandleZip {
3
- constructor(file) {
38
+ var HandleZip = /** @class */ (function () {
39
+ function HandleZip(file) {
4
40
  this.uploadFile = file;
5
41
  }
6
- async unzipFile() {
7
- const zip = await JSZip.loadAsync(this.uploadFile);
8
- const fileList = {};
9
- for (const [_path, zipEntry] of Object.entries(zip.files)) {
10
- const fileName = zipEntry.name;
11
- const fileNameArr = fileName.split(".");
12
- const suffix = fileNameArr[fileNameArr.length - 1].toLowerCase();
13
- let fileType = "string";
14
- if (suffix in
15
- {
16
- png: 1,
17
- jpeg: 1,
18
- jpg: 1,
19
- gif: 1,
20
- bmp: 1,
21
- tif: 1,
22
- webp: 1,
23
- }) {
24
- fileType = "base64";
25
- }
26
- else if (suffix == "emf") {
27
- fileType = "arraybuffer";
28
- }
29
- let data = await zipEntry.async(fileType);
30
- if (fileType == "base64") {
31
- data = "data:image/" + suffix + ";base64," + data;
32
- }
33
- fileList[zipEntry.name] = data; // XXX: ignore EMF ArrayBuffer :/
34
- }
35
- return fileList;
36
- }
37
- }
42
+ HandleZip.prototype.unzipFile = function () {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var zip, fileList, _i, _a, _b, _path, zipEntry, fileName, fileNameArr, suffix, fileType, data;
45
+ return __generator(this, function (_c) {
46
+ switch (_c.label) {
47
+ case 0: return [4 /*yield*/, JSZip.loadAsync(this.uploadFile)];
48
+ case 1:
49
+ zip = _c.sent();
50
+ fileList = {};
51
+ _i = 0, _a = Object.entries(zip.files);
52
+ _c.label = 2;
53
+ case 2:
54
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
55
+ _b = _a[_i], _path = _b[0], zipEntry = _b[1];
56
+ fileName = zipEntry.name;
57
+ fileNameArr = fileName.split(".");
58
+ suffix = fileNameArr[fileNameArr.length - 1].toLowerCase();
59
+ fileType = "string";
60
+ if (suffix in
61
+ {
62
+ png: 1,
63
+ jpeg: 1,
64
+ jpg: 1,
65
+ gif: 1,
66
+ bmp: 1,
67
+ tif: 1,
68
+ webp: 1,
69
+ }) {
70
+ fileType = "base64";
71
+ }
72
+ else if (suffix == "emf") {
73
+ fileType = "arraybuffer";
74
+ }
75
+ return [4 /*yield*/, zipEntry.async(fileType)];
76
+ case 3:
77
+ data = _c.sent();
78
+ if (fileType == "base64") {
79
+ data = "data:image/" + suffix + ";base64," + data;
80
+ }
81
+ fileList[zipEntry.name] = data; // XXX: ignore EMF ArrayBuffer :/
82
+ _c.label = 4;
83
+ case 4:
84
+ _i++;
85
+ return [3 /*break*/, 2];
86
+ case 5: return [2 /*return*/, fileList];
87
+ }
88
+ });
89
+ });
90
+ };
91
+ return HandleZip;
92
+ }());
93
+ export { HandleZip };
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const ImportHelper: (props: any) => React.JSX.Element;
@@ -0,0 +1,51 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import React from "react";
38
+ import { transformExcelToFortune } from "./Transform.js";
39
+ export var ImportHelper = function (props) {
40
+ var setSheets = props.setSheets, setKey = props.setKey, sheetRef = props.sheetRef;
41
+ return (React.createElement("input", { type: "file", id: "ImportHelper", onChange: function (e) { return __awaiter(void 0, void 0, void 0, function () {
42
+ return __generator(this, function (_a) {
43
+ switch (_a.label) {
44
+ case 0: return [4 /*yield*/, transformExcelToFortune(e, setSheets, setKey, sheetRef)];
45
+ case 1:
46
+ _a.sent();
47
+ return [2 /*return*/];
48
+ }
49
+ });
50
+ }); }, hidden: true }));
51
+ };