@spscommerce/ds-web-components 4.30.1 → 4.31.0-ie

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 (92) hide show
  1. package/dist/components/file-upload/file-upload.d.ts +116 -0
  2. package/dist/components/file-upload/file-upload.examples.d.ts +2 -0
  3. package/dist/components/file-upload/file-upload.examples.js +77 -0
  4. package/dist/components/file-upload/file-upload.examples.js.map +1 -0
  5. package/dist/components/file-upload/file-upload.js +403 -0
  6. package/dist/components/file-upload/file-upload.js.map +1 -0
  7. package/dist/components/file-upload/mime-type.enum.d.ts +75 -0
  8. package/dist/components/file-upload/mime-type.enum.js +77 -0
  9. package/dist/components/file-upload/mime-type.enum.js.map +1 -0
  10. package/dist/components/index.d.ts +11 -0
  11. package/dist/components/index.js +12 -0
  12. package/dist/components/index.js.map +1 -0
  13. package/dist/components/insight-card/insight-card.d.ts +40 -0
  14. package/dist/components/insight-card/insight-card.examples.d.ts +51 -0
  15. package/dist/components/insight-card/insight-card.examples.js +58 -0
  16. package/dist/components/insight-card/insight-card.examples.js.map +1 -0
  17. package/dist/components/insight-card/insight-card.js +147 -0
  18. package/dist/components/insight-card/insight-card.js.map +1 -0
  19. package/dist/components/insight-card/insights.d.ts +18 -0
  20. package/dist/components/insight-card/insights.js +90 -0
  21. package/dist/components/insight-card/insights.js.map +1 -0
  22. package/dist/components/nav-tabs/nav-tab-set.d.ts +7 -0
  23. package/dist/components/nav-tabs/nav-tab-set.js +53 -0
  24. package/dist/components/nav-tabs/nav-tab-set.js.map +1 -0
  25. package/dist/components/nav-tabs/nav-tab.d.ts +24 -0
  26. package/dist/components/nav-tabs/nav-tab.js +94 -0
  27. package/dist/components/nav-tabs/nav-tab.js.map +1 -0
  28. package/dist/components/nav-tabs/nav-tabs.examples.d.ts +11 -0
  29. package/dist/components/nav-tabs/nav-tabs.examples.js +18 -0
  30. package/dist/components/nav-tabs/nav-tabs.examples.js.map +1 -0
  31. package/dist/components/photo/photo.d.ts +42 -0
  32. package/dist/components/photo/photo.examples.d.ts +2 -0
  33. package/dist/components/photo/photo.examples.js +58 -0
  34. package/dist/components/photo/photo.examples.js.map +1 -0
  35. package/dist/components/photo/photo.js +172 -0
  36. package/dist/components/photo/photo.js.map +1 -0
  37. package/dist/decorators/component.d.ts +33 -0
  38. package/dist/decorators/component.js +313 -0
  39. package/dist/decorators/component.js.map +1 -0
  40. package/dist/decorators/content.d.ts +7 -0
  41. package/dist/decorators/content.js +13 -0
  42. package/dist/decorators/content.js.map +1 -0
  43. package/dist/decorators/event-dispatcher.d.ts +9 -0
  44. package/dist/decorators/event-dispatcher.js +22 -0
  45. package/dist/decorators/event-dispatcher.js.map +1 -0
  46. package/dist/decorators/event-listener.d.ts +5 -0
  47. package/dist/decorators/event-listener.js +14 -0
  48. package/dist/decorators/event-listener.js.map +1 -0
  49. package/dist/decorators/index.d.ts +7 -0
  50. package/dist/decorators/index.js +8 -0
  51. package/dist/decorators/index.js.map +1 -0
  52. package/dist/decorators/prop.d.ts +6 -0
  53. package/dist/decorators/prop.js +47 -0
  54. package/dist/decorators/prop.js.map +1 -0
  55. package/dist/decorators/query-selector.d.ts +19 -0
  56. package/dist/decorators/query-selector.js +32 -0
  57. package/dist/decorators/query-selector.js.map +1 -0
  58. package/dist/decorators/watch.d.ts +2 -0
  59. package/dist/decorators/watch.js +27 -0
  60. package/dist/decorators/watch.js.map +1 -0
  61. package/dist/index.d.ts +6 -0
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/lib/index.cjs.js +3178 -642
  65. package/dist/lib/index.es.js +2902 -2368
  66. package/dist/manifest.d.ts +2 -0
  67. package/dist/manifest.js +33 -0
  68. package/dist/manifest.js.map +1 -0
  69. package/dist/package.json +4 -3
  70. package/dist/utils/comment.d.ts +2 -0
  71. package/dist/utils/comment.js +15 -0
  72. package/dist/utils/comment.js.map +1 -0
  73. package/dist/utils/i18n.d.ts +3 -0
  74. package/dist/utils/i18n.js +9 -0
  75. package/dist/utils/i18n.js.map +1 -0
  76. package/dist/utils/index.d.ts +5 -0
  77. package/dist/utils/index.js +6 -0
  78. package/dist/utils/index.js.map +1 -0
  79. package/dist/utils/metadata.d.ts +22 -0
  80. package/dist/utils/metadata.js +23 -0
  81. package/dist/utils/metadata.js.map +1 -0
  82. package/dist/utils/pragma.d.ts +6 -0
  83. package/dist/utils/pragma.js +143 -0
  84. package/dist/utils/pragma.js.map +1 -0
  85. package/dist/utils/register.d.ts +13 -0
  86. package/dist/utils/register.js +73 -0
  87. package/dist/utils/register.js.map +1 -0
  88. package/lib/index.cjs.js +3178 -642
  89. package/lib/index.es.js +2902 -2368
  90. package/package.json +8 -7
  91. package/rollup.config.js +22 -0
  92. package/vite.config.js +1 -1
@@ -0,0 +1,116 @@
1
+ import { ClassBindings, Dispatcher } from "../../decorators/index";
2
+ export declare class SpsFileUploadComponent extends HTMLElement {
3
+ static readonly displayName = "sps-file-upload";
4
+ static readonly props: {
5
+ description: string;
6
+ multiple: string;
7
+ dismissable: string;
8
+ processing: string;
9
+ mini: string;
10
+ downloadLabel: string;
11
+ acceptExtensions: string;
12
+ maxSize: string;
13
+ selection: {
14
+ event: boolean;
15
+ type: string;
16
+ };
17
+ dismissal: {
18
+ event: boolean;
19
+ type: string;
20
+ };
21
+ download: {
22
+ event: boolean;
23
+ type: string;
24
+ };
25
+ };
26
+ /**
27
+ * The "term" for what the user should upload. Defaults to "File" or "Files",
28
+ * but if you set the `acceptExtensions` prop you might set this to something
29
+ * more specific, such as "Spreadsheet" or "Images".
30
+ */
31
+ description: any;
32
+ /**
33
+ * If true, the component will accept multiple files at once. By default, you can
34
+ * only select one file at a time.
35
+ */
36
+ multiple: boolean;
37
+ /** Controls whether the component is visible. */
38
+ shown: boolean;
39
+ /** Controls whether the user can hide the component from view. */
40
+ dismissable: boolean;
41
+ /**
42
+ * Puts the component in "processing" state, where it displays a spinner and
43
+ * does not allow any files to be selected.
44
+ */
45
+ processing: boolean;
46
+ /** Specifies that the component should be displayed in the "mini" style. */
47
+ mini: boolean;
48
+ /** If provided, the content area width will be set to 50% of the overall width. */
49
+ constrainContentWidth: boolean;
50
+ /** If provided, a button will be rendered with this text as its label. */
51
+ downloadLabel: string;
52
+ /**
53
+ * A list of extensions, provided either as an array of strings or a
54
+ * string containing comma-separates extensions. Only files with the MIME types
55
+ * associated with those extensions will be able to be selected. The case of
56
+ * the extensions does not matter; neither does whether you prefix them with a
57
+ * dot. That is, ".doc", "DOCX", and "jpg" are all valid extensions for this prop.
58
+ */
59
+ acceptExtensions: string[] | string;
60
+ /** The maximum allowable size in bytes for files selected by the component. */
61
+ maxSize: string;
62
+ /**
63
+ * Event which emits when a file or files have been selected by the user. The
64
+ * event detail will be an array of Files.
65
+ */
66
+ selection: Dispatcher<File[]>;
67
+ /**
68
+ * If the `dismissable` prop has been set, this event will fire when the user
69
+ * opts to hide the component.
70
+ */
71
+ dismissal: Dispatcher<void>;
72
+ /**
73
+ * If the `downloadLabel` prop has been provided, this event will fire when the
74
+ * user clicks the download button that is rendered.
75
+ */
76
+ download: Dispatcher<void>;
77
+ /** The HTML file input element within the component. */
78
+ fileInput: HTMLInputElement;
79
+ /**
80
+ * The list of selected files. If the `multiple` prop has not been provided,
81
+ * it is still an array; it will simply be an array of one when the user selects
82
+ * a file.
83
+ */
84
+ files: File[];
85
+ private accept;
86
+ private acceptMIMETypes;
87
+ private acceptExtensionsDescription;
88
+ private maxSizeBytes;
89
+ private active;
90
+ private error;
91
+ private namesOfUnsupportedFiles;
92
+ get [ClassBindings](): string[];
93
+ constructor();
94
+ connectedCallback(): void;
95
+ attributeChangedCallback(attrName: string, oldValue: any, newValue: any): void;
96
+ /**
97
+ * If the `dismissable` prop has been set, this will programmatically
98
+ * dismiss the component and fire the "dismissal" event.
99
+ */
100
+ dismiss(): void;
101
+ /** If the `dismissable` prop has been set, this will programmatically show the component. */
102
+ show(): void;
103
+ render({ t }: {
104
+ t: any;
105
+ }): JSX.Element;
106
+ private parseAndValidateMaxSize;
107
+ private processAcceptExtensions;
108
+ private selectFiles;
109
+ private handleDragOver;
110
+ private handleDragEnter;
111
+ private handleDragLeave;
112
+ private handleDrop;
113
+ private handleBrowseLinkClick;
114
+ private handleDownloadButtonClick;
115
+ private handleFileInputChange;
116
+ }
@@ -0,0 +1,2 @@
1
+ import type { DSReactExamples } from "@spscommerce/ds-shared";
2
+ export declare const SpsFileUploadExamples: DSReactExamples;
@@ -0,0 +1,77 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import { code } from "@spscommerce/utils";
6
+ export var SpsFileUploadExamples = {
7
+ basic: {
8
+ label: "Basic File Upload",
9
+ description: code(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <p>Simply allow the user to drag-and-drop or select either a single file or multiple files at once.</p>\n "], ["\n <p>Simply allow the user to drag-and-drop or select either a single file or multiple files at once.</p>\n "]))),
10
+ examples: {
11
+ single: {
12
+ description: "<p>Single file upload</p>",
13
+ react: code(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref}/>\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref}/>\n </div>\n </div>\n )\n }\n "]))),
14
+ },
15
+ multiple: {
16
+ description: "<p>Multiple file upload</p>",
17
+ react: code(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref} multiple/>\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref} multiple/>\n </div>\n </div>\n )\n }\n "]))),
18
+ },
19
+ },
20
+ },
21
+ restrictions: {
22
+ label: "Restrictions",
23
+ description: code(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n <p>You can place restrictions on what files will be accepted with an extension whitelist and/or a maximum size.</p>\n "], ["\n <p>You can place restrictions on what files will be accepted with an extension whitelist and/or a maximum size.</p>\n "]))),
24
+ examples: {
25
+ size: {
26
+ description: "<p>Maximum size</p>",
27
+ react: code(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref} maxSize=\"100KB\"/>\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload ref={ref} maxSize=\"100KB\"/>\n </div>\n </div>\n )\n }\n "]))),
28
+ },
29
+ type: {
30
+ description: "<p>File type whitelist</p>",
31
+ react: code(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheets\"\n multiple\n acceptExtensions=\"XLS, xlsx, .csv\"\n />\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheets\"\n multiple\n acceptExtensions=\"XLS, xlsx, .csv\"\n />\n </div>\n </div>\n )\n }\n "]))),
32
+ },
33
+ both: {
34
+ description: "<p>Both restrictions</p>",
35
+ react: code(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheets\"\n multiple\n acceptExtensions=\"XLS, xlsx, .csv\"\n maxSize=\"25MB\"\n />\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheets\"\n multiple\n acceptExtensions=\"XLS, xlsx, .csv\"\n maxSize=\"25MB\"\n />\n </div>\n </div>\n )\n }\n "]))),
36
+ },
37
+ },
38
+ },
39
+ dismissable: {
40
+ label: "Dismissable",
41
+ description: code(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n <p>With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can\n show it again programmatically if you need to.</p>\n "], ["\n <p>With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can\n show it again programmatically if you need to.</p>\n "]))),
42
+ examples: {
43
+ dismissable: {
44
+ react: code(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n function Component() {\n const [showFileUpload, setShowFileUpload] = React.useState(true)\n const ref = React.useRef()\n\n function handleDismissal() {\n setShowFileUpload(false)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"dismissal\", handleDismissal)\n return () => {\n ref.current.removeEventListener(\"dismissal\", handleDismissal)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n dismissable\n shown={showFileUpload}\n />\n {!showFileUpload && (\n <SpsButton onClick={() => setShowFileUpload(true)}>\n Reset\n </SpsButton>\n )}\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const [showFileUpload, setShowFileUpload] = React.useState(true)\n const ref = React.useRef()\n\n function handleDismissal() {\n setShowFileUpload(false)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"dismissal\", handleDismissal)\n return () => {\n ref.current.removeEventListener(\"dismissal\", handleDismissal)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n dismissable\n shown={showFileUpload}\n />\n {!showFileUpload && (\n <SpsButton onClick={() => setShowFileUpload(true)}>\n Reset\n </SpsButton>\n )}\n </div>\n </div>\n )\n }\n "]))),
45
+ },
46
+ },
47
+ },
48
+ downloadButton: {
49
+ label: "Download Button",
50
+ description: code(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n <p>You can optionally provide a button to download a file. Typically this will be a template for\n whatever the user is expected to upload. They can then fill out the template, save it, and upload it.</p>\n "], ["\n <p>You can optionally provide a button to download a file. Typically this will be a template for\n whatever the user is expected to upload. They can then fill out the template, save it, and upload it.</p>\n "]))),
51
+ examples: {
52
+ downloadButton: {
53
+ react: code(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleDownload() {\n console.log(\"Download triggered.\")\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"download\", handleDownload)\n return () => {\n ref.current.removeEventListener(\"download\", handleDownload)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheet\"\n acceptExtensions=\"xlsx\"\n downloadLabel=\"Download Excel Template\"\n />\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleDownload() {\n console.log(\"Download triggered.\")\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"download\", handleDownload)\n return () => {\n ref.current.removeEventListener(\"download\", handleDownload)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-12\">\n <sps-file-upload\n ref={ref}\n description=\"Spreadsheet\"\n acceptExtensions=\"xlsx\"\n downloadLabel=\"Download Excel Template\"\n />\n </div>\n </div>\n )\n }\n "]))),
54
+ },
55
+ },
56
+ },
57
+ mini: {
58
+ label: "Mini File Upload",
59
+ description: code(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n <p>When the file upload component is to be placed in a small container,\n it should be marked as a mini file upload so that everything fits.</p>\n "], ["\n <p>When the file upload component is to be placed in a small container,\n it should be marked as a mini file upload so that everything fits.</p>\n "]))),
60
+ examples: {
61
+ single: {
62
+ react: code(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-4\">\n <sps-file-upload ref={ref} mini/>\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-4\">\n <sps-file-upload ref={ref} mini/>\n </div>\n </div>\n )\n }\n "]))),
63
+ },
64
+ },
65
+ },
66
+ constrainContentWidth: {
67
+ label: "Constrain Content Width",
68
+ description: code(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n <p>If this prop is provided, the content will be restricted to 50% of\n the overall width of the component. Consult your product designer if\n you're not sure whether to use this variant.</p>\n "], ["\n <p>If this prop is provided, the content will be restricted to 50% of\n the overall width of the component. Consult your product designer if\n you're not sure whether to use this variant.</p>\n "]))),
69
+ examples: {
70
+ constrainContentWidth: {
71
+ react: code(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event: CustomEvent<Array<File>>) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-4\">\n <sps-file-upload ref={ref} constrainContentWidth/>\n </div>\n </div>\n )\n }\n "], ["\n function Component() {\n const ref = React.useRef()\n\n function handleChange(event: CustomEvent<Array<File>>) {\n console.log(event.detail)\n }\n\n React.useEffect(() => {\n ref.current.addEventListener(\"selection\", handleChange)\n return () => {\n ref.current.removeEventListener(\"selection\", handleChange)\n }\n })\n\n return (\n <div className=\"sps-row\">\n <div className=\"col-4\">\n <sps-file-upload ref={ref} constrainContentWidth/>\n </div>\n </div>\n )\n }\n "]))),
72
+ },
73
+ },
74
+ },
75
+ };
76
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
77
+ //# sourceMappingURL=file-upload.examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-upload.examples.js","sourceRoot":"","sources":["../../../src/components/file-upload/file-upload.examples.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,MAAM,CAAC,IAAM,qBAAqB,GAAoB;IACpD,KAAK,EAAE;QACL,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,IAAI,oMAAA,iIAEZ,IAAA;QACL,QAAQ,EAAE;YACR,MAAM,EAAE;gBACN,WAAW,EAAE,2BAA2B;gBACxC,KAAK,EAAE,IAAI,2+BAAA,w6BAuBF,IAAA;aACV;YACD,QAAQ,EAAE;gBACR,WAAW,EAAE,6BAA6B;gBAC1C,KAAK,EAAE,IAAI,o/BAAA,i7BAuBF,IAAA;aACV;SACF;KACF;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,IAAI,gNAAA,6IAEZ,IAAA;QACL,QAAQ,EAAE;YACR,IAAI,EAAE;gBACJ,WAAW,EAAE,qBAAqB;gBAClC,KAAK,EAAE,IAAI,6/BAAA,07BAuBF,IAAA;aACV;YACD,IAAI,EAAE;gBACJ,WAAW,EAAE,4BAA4B;gBACzC,KAAK,EAAE,IAAI,gwCAAA,6rCA4BF,IAAA;aACV;YACD,IAAI,EAAE;gBACJ,WAAW,EAAE,0BAA0B;gBACvC,KAAK,EAAE,IAAI,0zCAAA,uvCA6BF,IAAA;aACV;SACF;KACF;IACD,WAAW,EAAE;QACX,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,IAAI,8QAAA,2MAGZ,IAAA;QACL,QAAQ,EAAE;YACR,WAAW,EAAE;gBACX,KAAK,EAAE,IAAI,yiDAAA,s+CAiCF,IAAA;aACV;SACF;KACF;IACD,cAAc,EAAE;QACd,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,IAAI,sTAAA,iPAGZ,IAAA;QACL,QAAQ,EAAE;YACR,cAAc,EAAE;gBACd,KAAK,EAAE,IAAI,iyCAAA,4tCA4BF,IAAA;aACV;SACF;KACF;IACD,IAAI,EAAE;QACJ,KAAK,EAAE,kBAAkB;QACzB,WAAW,EAAE,IAAI,0PAAA,qLAGZ,IAAA;QACL,QAAQ,EAAE;YACR,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI,i/BAAA,46BAuBF,IAAA;aACV;SACF;KACF;IACD,qBAAqB,EAAE;QACrB,KAAK,EAAE,yBAAyB;QAChC,WAAW,EAAE,IAAI,oTAAA,+OAIZ,IAAA;QACL,QAAQ,EAAE;YACR,qBAAqB,EAAE;gBACrB,KAAK,EAAE,IAAI,4hCAAA,u9BAuBF,IAAA;aACV;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,403 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ var __values = (this && this.__values) || function(o) {
26
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
27
+ if (m) return m.call(o);
28
+ if (o && typeof o.length === "number") return {
29
+ next: function () {
30
+ if (o && i >= o.length) o = void 0;
31
+ return { value: o && o[i++], done: !o };
32
+ }
33
+ };
34
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
35
+ };
36
+ /** @jsx h */
37
+ /* eslint-disable new-cap */
38
+ import { SpsIcon } from "@spscommerce/ds-shared";
39
+ import { parseFileSize } from "@spscommerce/utils";
40
+ import { ClassBindings, Component, EventDispatcher,
41
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
42
+ EventListener, Prop, QuerySelector, } from "../../decorators/index";
43
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
+ import { h } from "../../utils/pragma";
45
+ import { MIMEType } from "./mime-type.enum";
46
+ var CPT_NAME = "sps-file-upload";
47
+ var SpsFileUploadComponent = /** @class */ (function (_super) {
48
+ __extends(SpsFileUploadComponent, _super);
49
+ function SpsFileUploadComponent() {
50
+ var _this = _super.call(this) || this;
51
+ /** Controls whether the component is visible. */
52
+ _this.shown = true;
53
+ /**
54
+ * The list of selected files. If the `multiple` prop has not been provided,
55
+ * it is still an array; it will simply be an array of one when the user selects
56
+ * a file.
57
+ */
58
+ _this.files = [];
59
+ _this.acceptMIMETypes = new Set();
60
+ _this.active = false;
61
+ _this.error = false;
62
+ _this.namesOfUnsupportedFiles = [];
63
+ _this.handleBrowseLinkClick = _this.handleBrowseLinkClick.bind(_this);
64
+ _this.handleDownloadButtonClick = _this.handleDownloadButtonClick.bind(_this);
65
+ _this.handleFileInputChange = _this.handleFileInputChange.bind(_this);
66
+ _this.dismiss = _this.dismiss.bind(_this);
67
+ return _this;
68
+ }
69
+ Object.defineProperty(SpsFileUploadComponent.prototype, ClassBindings, {
70
+ get: function () {
71
+ return [
72
+ CPT_NAME,
73
+ this.active && CPT_NAME + "--active",
74
+ this.error && CPT_NAME + "--error",
75
+ !this.shown && CPT_NAME + "--hidden",
76
+ this.mini && CPT_NAME + "--mini",
77
+ this.constrainContentWidth && CPT_NAME + "--constrained-content-width",
78
+ ];
79
+ },
80
+ enumerable: false,
81
+ configurable: true
82
+ });
83
+ SpsFileUploadComponent.prototype.connectedCallback = function () {
84
+ this.description = this.description || (this.multiple ? "Files" : "File");
85
+ if (this.acceptExtensions) {
86
+ this.processAcceptExtensions(this.acceptExtensions);
87
+ }
88
+ if (this.maxSize) {
89
+ this.parseAndValidateMaxSize(this.maxSize);
90
+ }
91
+ };
92
+ SpsFileUploadComponent.prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
93
+ if (attrName === "acceptExtensions") {
94
+ this.processAcceptExtensions(newValue);
95
+ }
96
+ if (attrName === "maxSize") {
97
+ this.parseAndValidateMaxSize(newValue);
98
+ }
99
+ };
100
+ /**
101
+ * If the `dismissable` prop has been set, this will programmatically
102
+ * dismiss the component and fire the "dismissal" event.
103
+ */
104
+ SpsFileUploadComponent.prototype.dismiss = function () {
105
+ if (this.dismissable) {
106
+ this.shown = false;
107
+ this.update();
108
+ this.dismissal.dispatch();
109
+ }
110
+ };
111
+ /** If the `dismissable` prop has been set, this will programmatically show the component. */
112
+ SpsFileUploadComponent.prototype.show = function () {
113
+ if (this.dismissable) {
114
+ this.shown = true;
115
+ this.update();
116
+ }
117
+ };
118
+ SpsFileUploadComponent.prototype.render = function (_a) {
119
+ var _this = this;
120
+ var t = _a.t;
121
+ var icon = this.error ? SpsIcon.EXCLAMATION_CIRCLE : SpsIcon.UPLOAD_CLOUD;
122
+ var instructions = (this.multiple
123
+ ? t("design-system:fileUpload.instructions_plural")
124
+ : t("design-system:fileUpload.instructions")).split("|");
125
+ return (h("div", { "data-fragment": true },
126
+ h("div", { className: CPT_NAME + "__content" }, this.processing
127
+ ? (h("div", { "data-fragment": true },
128
+ h("i", { className: "sps-spinner sps-spinner--medium", "aria-hidden": "true" }),
129
+ h("div", { className: CPT_NAME + "__instructions" }, t("design-system:fileUpload.processing"))))
130
+ : (h("div", { "data-fragment": true },
131
+ h("i", { className: "sps-icon sps-icon-" + icon + " " + CPT_NAME + "__icon-primary", "aria-hidden": "true" }),
132
+ h("div", { className: CPT_NAME + "__title" }, this.error
133
+ ? (h("div", { "data-fragment": true }, t(this.namesOfUnsupportedFiles.length > 1
134
+ ? "design-system:fileUpload.cancelled_plural"
135
+ : "design-system:fileUpload.cancelled")))
136
+ : h("div", { "data-fragment": true }, t("design-system:fileUpload.title", { description: this.description }))),
137
+ this.error
138
+ ? (h("div", { className: CPT_NAME + "__errored-files" }, new Set(this.namesOfUnsupportedFiles.map(function (name, i) {
139
+ var breakpoint = Math.floor(name.length / 2);
140
+ return (h("div", { className: CPT_NAME + "__errored-filename", key: name },
141
+ h("span", { className: CPT_NAME + "__errored-filename-segment" }, name.substr(0, breakpoint)),
142
+ h("div", { className: CPT_NAME + "__errored-filename-segment" },
143
+ h("span", null, name.substr(breakpoint))),
144
+ i < _this.namesOfUnsupportedFiles.length - 1 ? "," : ""));
145
+ }))))
146
+ : h("span", null),
147
+ h("div", { className: CPT_NAME + "__instructions" },
148
+ h("div", { "data-fragment": true },
149
+ h("span", null, instructions[0]),
150
+ h("a", { href: "", onClick: this.handleBrowseLinkClick }, instructions[1]),
151
+ h("span", null, instructions[2]))),
152
+ h("div", { className: CPT_NAME + "__requirements" },
153
+ this.acceptExtensions
154
+ ? (h("div", { "data-fragment": true },
155
+ "(",
156
+ " ",
157
+ t("design-system:fileUpload.acceptedTypes", { fileTypes: this.acceptExtensionsDescription }),
158
+ " ",
159
+ ")"))
160
+ : "",
161
+ this.maxSize
162
+ ? (h("div", { "data-fragment": true },
163
+ "(",
164
+ t("design-system:fileUpload.maximumSize", { size: this.maxSize }),
165
+ " ",
166
+ ")"))
167
+ : ""),
168
+ this.downloadLabel
169
+ && (h("div", { className: "sps-button sps-button--link " + CPT_NAME + "__download-button", onClick: this.handleDownloadButtonClick },
170
+ h("button", { type: "button" },
171
+ h("i", { className: "sps-icon sps-icon-download-cloud", "aria-hidden": "true" }),
172
+ " ",
173
+ this.downloadLabel)))))),
174
+ this.dismissable && !this.processing
175
+ && (h("div", { className: "sps-button sps-button--icon " + CPT_NAME + "__close-button", onClick: this.dismiss },
176
+ h("button", { type: "button", title: t("design-system:fileUpload.close") },
177
+ h("i", { className: "sps-icon sps-icon-x", "aria-hidden": "true" })))),
178
+ h("form", null,
179
+ h("input", { type: "file", accept: this.accept || "*/*", multiple: this.multiple || null, onChange: this.handleFileInputChange }))));
180
+ };
181
+ SpsFileUploadComponent.prototype.parseAndValidateMaxSize = function (maxSize) {
182
+ try {
183
+ this.maxSizeBytes = parseFileSize(maxSize);
184
+ }
185
+ catch (error) {
186
+ throw new Error("Could not parse \"" + maxSize + "\" as a file size.");
187
+ }
188
+ };
189
+ SpsFileUploadComponent.prototype.processAcceptExtensions = function (acceptExtensions) {
190
+ var e_1, _a, e_2, _b;
191
+ var splitExtensions = Array.isArray(acceptExtensions)
192
+ ? acceptExtensions
193
+ : acceptExtensions.trim().split(/\s?,\s?/);
194
+ var trimmedExtensions = splitExtensions.map(function (ext) { return ext.replace(/^\./, ""); });
195
+ var extList = trimmedExtensions.map(function (ext) { return ("." + ext).toLowerCase(); });
196
+ this.acceptExtensionsDescription = extList
197
+ .map(function (ext, i) { return (i > 0 && i === extList.length - 1 ? "or " + ext : ext); })
198
+ .join(extList.length > 2 ? ", " : " ");
199
+ this.acceptMIMETypes.clear();
200
+ try {
201
+ for (var trimmedExtensions_1 = __values(trimmedExtensions), trimmedExtensions_1_1 = trimmedExtensions_1.next(); !trimmedExtensions_1_1.done; trimmedExtensions_1_1 = trimmedExtensions_1.next()) {
202
+ var ext = trimmedExtensions_1_1.value;
203
+ try {
204
+ for (var _c = (e_2 = void 0, __values(MIMEType[ext.toUpperCase()].split(","))), _d = _c.next(); !_d.done; _d = _c.next()) {
205
+ var type = _d.value;
206
+ this.acceptMIMETypes.add(type);
207
+ }
208
+ }
209
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
210
+ finally {
211
+ try {
212
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
213
+ }
214
+ finally { if (e_2) throw e_2.error; }
215
+ }
216
+ }
217
+ }
218
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
219
+ finally {
220
+ try {
221
+ if (trimmedExtensions_1_1 && !trimmedExtensions_1_1.done && (_a = trimmedExtensions_1.return)) _a.call(trimmedExtensions_1);
222
+ }
223
+ finally { if (e_1) throw e_1.error; }
224
+ }
225
+ this.accept = extList.concat(Array.from(this.acceptMIMETypes)).join(",");
226
+ };
227
+ SpsFileUploadComponent.prototype.selectFiles = function (files) {
228
+ var e_3, _a;
229
+ this.namesOfUnsupportedFiles = [];
230
+ var fileArray = Array.from(files);
231
+ try {
232
+ for (var fileArray_1 = __values(fileArray), fileArray_1_1 = fileArray_1.next(); !fileArray_1_1.done; fileArray_1_1 = fileArray_1.next()) {
233
+ var file = fileArray_1_1.value;
234
+ if (this.acceptExtensions && !this.acceptMIMETypes.has(file.type)) {
235
+ this.namesOfUnsupportedFiles.push(file.name);
236
+ }
237
+ if (this.maxSize && file.size > this.maxSizeBytes) {
238
+ this.namesOfUnsupportedFiles.push(file.name);
239
+ }
240
+ }
241
+ }
242
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
243
+ finally {
244
+ try {
245
+ if (fileArray_1_1 && !fileArray_1_1.done && (_a = fileArray_1.return)) _a.call(fileArray_1);
246
+ }
247
+ finally { if (e_3) throw e_3.error; }
248
+ }
249
+ if (this.namesOfUnsupportedFiles.length) {
250
+ this.error = true;
251
+ this.fileInput.value = null;
252
+ this.update();
253
+ }
254
+ else {
255
+ this.files = fileArray;
256
+ this.selection.dispatch(fileArray);
257
+ }
258
+ };
259
+ /* eslint-disable class-methods-use-this, @typescript-eslint/member-ordering */
260
+ SpsFileUploadComponent.prototype.handleDragOver = function (event) {
261
+ event.preventDefault();
262
+ event.stopPropagation();
263
+ };
264
+ /* eslint-enable class-methods-use-this */
265
+ SpsFileUploadComponent.prototype.handleDragEnter = function (event) {
266
+ event.preventDefault();
267
+ this.active = true;
268
+ this.error = false;
269
+ this.update();
270
+ };
271
+ SpsFileUploadComponent.prototype.handleDragLeave = function (event) {
272
+ event.preventDefault();
273
+ this.active = false;
274
+ this.update();
275
+ };
276
+ SpsFileUploadComponent.prototype.handleDrop = function (event) {
277
+ event.preventDefault();
278
+ event.stopPropagation();
279
+ this.active = false;
280
+ if (event.dataTransfer.items) {
281
+ this.selectFiles(Array.from(event.dataTransfer.items).map(function (item) { return item.getAsFile(); }));
282
+ }
283
+ else {
284
+ this.selectFiles(event.dataTransfer.files);
285
+ }
286
+ this.update();
287
+ };
288
+ /* eslint-enable @typescript-eslint/member-ordering */
289
+ SpsFileUploadComponent.prototype.handleBrowseLinkClick = function (event) {
290
+ event.preventDefault();
291
+ this.error = false;
292
+ this.update();
293
+ this.fileInput.click();
294
+ };
295
+ SpsFileUploadComponent.prototype.handleDownloadButtonClick = function () {
296
+ this.download.dispatch();
297
+ };
298
+ SpsFileUploadComponent.prototype.handleFileInputChange = function (event) {
299
+ event.stopPropagation();
300
+ this.selectFiles(event.target.files);
301
+ };
302
+ SpsFileUploadComponent.displayName = CPT_NAME;
303
+ SpsFileUploadComponent.props = {
304
+ description: "string",
305
+ multiple: "boolean",
306
+ dismissable: "boolean",
307
+ processing: "boolean",
308
+ mini: "boolean",
309
+ downloadLabel: "string",
310
+ acceptExtensions: "Array<string> | string",
311
+ maxSize: "string",
312
+ selection: { event: true, type: "CustomEvent<Array<File>>" },
313
+ dismissal: { event: true, type: "CustomEvent<void>" },
314
+ download: { event: true, type: "CustomEvent<void>" },
315
+ };
316
+ __decorate([
317
+ Prop(),
318
+ __metadata("design:type", Object)
319
+ ], SpsFileUploadComponent.prototype, "description", void 0);
320
+ __decorate([
321
+ Prop(Boolean),
322
+ __metadata("design:type", Boolean)
323
+ ], SpsFileUploadComponent.prototype, "multiple", void 0);
324
+ __decorate([
325
+ Prop(Boolean),
326
+ __metadata("design:type", Object)
327
+ ], SpsFileUploadComponent.prototype, "shown", void 0);
328
+ __decorate([
329
+ Prop(Boolean),
330
+ __metadata("design:type", Boolean)
331
+ ], SpsFileUploadComponent.prototype, "dismissable", void 0);
332
+ __decorate([
333
+ Prop(Boolean),
334
+ __metadata("design:type", Boolean)
335
+ ], SpsFileUploadComponent.prototype, "processing", void 0);
336
+ __decorate([
337
+ Prop(Boolean),
338
+ __metadata("design:type", Boolean)
339
+ ], SpsFileUploadComponent.prototype, "mini", void 0);
340
+ __decorate([
341
+ Prop(Boolean),
342
+ __metadata("design:type", Boolean)
343
+ ], SpsFileUploadComponent.prototype, "constrainContentWidth", void 0);
344
+ __decorate([
345
+ Prop(),
346
+ __metadata("design:type", String)
347
+ ], SpsFileUploadComponent.prototype, "downloadLabel", void 0);
348
+ __decorate([
349
+ Prop(),
350
+ __metadata("design:type", Object)
351
+ ], SpsFileUploadComponent.prototype, "acceptExtensions", void 0);
352
+ __decorate([
353
+ Prop(),
354
+ __metadata("design:type", String)
355
+ ], SpsFileUploadComponent.prototype, "maxSize", void 0);
356
+ __decorate([
357
+ EventDispatcher(),
358
+ __metadata("design:type", Object)
359
+ ], SpsFileUploadComponent.prototype, "selection", void 0);
360
+ __decorate([
361
+ EventDispatcher(),
362
+ __metadata("design:type", Object)
363
+ ], SpsFileUploadComponent.prototype, "dismissal", void 0);
364
+ __decorate([
365
+ EventDispatcher(),
366
+ __metadata("design:type", Object)
367
+ ], SpsFileUploadComponent.prototype, "download", void 0);
368
+ __decorate([
369
+ QuerySelector("input[type='file']"),
370
+ __metadata("design:type", HTMLInputElement)
371
+ ], SpsFileUploadComponent.prototype, "fileInput", void 0);
372
+ __decorate([
373
+ EventListener("dragover"),
374
+ __metadata("design:type", Function),
375
+ __metadata("design:paramtypes", [Event]),
376
+ __metadata("design:returntype", void 0)
377
+ ], SpsFileUploadComponent.prototype, "handleDragOver", null);
378
+ __decorate([
379
+ EventListener("dragenter"),
380
+ __metadata("design:type", Function),
381
+ __metadata("design:paramtypes", [Event]),
382
+ __metadata("design:returntype", void 0)
383
+ ], SpsFileUploadComponent.prototype, "handleDragEnter", null);
384
+ __decorate([
385
+ EventListener("dragleave"),
386
+ __metadata("design:type", Function),
387
+ __metadata("design:paramtypes", [Event]),
388
+ __metadata("design:returntype", void 0)
389
+ ], SpsFileUploadComponent.prototype, "handleDragLeave", null);
390
+ __decorate([
391
+ EventListener("drop"),
392
+ __metadata("design:type", Function),
393
+ __metadata("design:paramtypes", [Object]),
394
+ __metadata("design:returntype", void 0)
395
+ ], SpsFileUploadComponent.prototype, "handleDrop", null);
396
+ SpsFileUploadComponent = __decorate([
397
+ Component({ tag: CPT_NAME }),
398
+ __metadata("design:paramtypes", [])
399
+ ], SpsFileUploadComponent);
400
+ return SpsFileUploadComponent;
401
+ }(HTMLElement));
402
+ export { SpsFileUploadComponent };
403
+ //# sourceMappingURL=file-upload.js.map