@wix/ditto-codegen-public 1.0.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.
Files changed (170) hide show
  1. package/dist/examples-apps/ai-chatbot/.nvmrc +1 -0
  2. package/dist/examples-apps/ai-chatbot/README.md +21 -0
  3. package/dist/examples-apps/ai-chatbot/package-lock.json +7266 -0
  4. package/dist/examples-apps/ai-chatbot/package.json +35 -0
  5. package/dist/examples-apps/ai-chatbot/src/backend/api/chat/api.ts +62 -0
  6. package/dist/examples-apps/ai-chatbot/src/backend/api/settings/api.ts +39 -0
  7. package/dist/examples-apps/ai-chatbot/src/backend/database.ts +86 -0
  8. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/product/ProductChat.module.css +3 -0
  9. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/product/ProductChat.tsx +99 -0
  10. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/product/page.json +6 -0
  11. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/product/page.tsx +99 -0
  12. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/settings/page.json +6 -0
  13. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/settings/page.tsx +105 -0
  14. package/dist/examples-apps/ai-chatbot/src/dashboard/pages/wix_logo.svg +18 -0
  15. package/dist/examples-apps/ai-chatbot/src/dashboard/utils.ts +27 -0
  16. package/dist/examples-apps/ai-chatbot/src/dashboard/withProviders.tsx +15 -0
  17. package/dist/examples-apps/ai-chatbot/src/env.d.ts +4 -0
  18. package/dist/examples-apps/ai-chatbot/src/types.ts +4 -0
  19. package/dist/examples-apps/ai-chatbot/tsconfig.json +8 -0
  20. package/dist/examples-apps/ai-chatbot/wix.config.json +5 -0
  21. package/dist/examples-apps/chart-widget/.nvmrc +1 -0
  22. package/dist/examples-apps/chart-widget/README.md +21 -0
  23. package/dist/examples-apps/chart-widget/assets/chart-widget/thumbnail.png +0 -0
  24. package/dist/examples-apps/chart-widget/package-lock.json +6329 -0
  25. package/dist/examples-apps/chart-widget/package.json +30 -0
  26. package/dist/examples-apps/chart-widget/src/env.d.ts +4 -0
  27. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/common.ts +20 -0
  28. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/element/bar-chart.tsx +53 -0
  29. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/element/pie-chart.tsx +40 -0
  30. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/element.json +20 -0
  31. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/element.tsx +53 -0
  32. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/panel/chart-type.tsx +47 -0
  33. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/panel/slice.tsx +72 -0
  34. package/dist/examples-apps/chart-widget/src/site/widgets/custom-elements/chart-widget/panel.tsx +90 -0
  35. package/dist/examples-apps/chart-widget/tsconfig.json +8 -0
  36. package/dist/examples-apps/chart-widget/wix.config.json +5 -0
  37. package/dist/examples-apps/custom-products-catalog/.nvmrc +1 -0
  38. package/dist/examples-apps/custom-products-catalog/README.md +21 -0
  39. package/dist/examples-apps/custom-products-catalog/package-lock.json +8694 -0
  40. package/dist/examples-apps/custom-products-catalog/package.json +33 -0
  41. package/dist/examples-apps/custom-products-catalog/src/dashboard/components/create-product.tsx +54 -0
  42. package/dist/examples-apps/custom-products-catalog/src/dashboard/hooks/stores.ts +60 -0
  43. package/dist/examples-apps/custom-products-catalog/src/dashboard/pages/page.json +5 -0
  44. package/dist/examples-apps/custom-products-catalog/src/dashboard/pages/page.tsx +297 -0
  45. package/dist/examples-apps/custom-products-catalog/src/dashboard/pages/wix_logo.svg +18 -0
  46. package/dist/examples-apps/custom-products-catalog/src/dashboard/withProviders.tsx +16 -0
  47. package/dist/examples-apps/custom-products-catalog/src/env.d.ts +4 -0
  48. package/dist/examples-apps/custom-products-catalog/tsconfig.json +8 -0
  49. package/dist/examples-apps/custom-products-catalog/wix.config.json +5 -0
  50. package/dist/examples-apps/inventory-countdown/.nvmrc +1 -0
  51. package/dist/examples-apps/inventory-countdown/README.md +21 -0
  52. package/dist/examples-apps/inventory-countdown/package-lock.json +7457 -0
  53. package/dist/examples-apps/inventory-countdown/package.json +33 -0
  54. package/dist/examples-apps/inventory-countdown/src/assets/stock-counter/site-plugin-logo.svg +27 -0
  55. package/dist/examples-apps/inventory-countdown/src/env.d.ts +4 -0
  56. package/dist/examples-apps/inventory-countdown/src/site/plugins/custom-elements/stock-counter/consts.ts +1 -0
  57. package/dist/examples-apps/inventory-countdown/src/site/plugins/custom-elements/stock-counter/panel.tsx +81 -0
  58. package/dist/examples-apps/inventory-countdown/src/site/plugins/custom-elements/stock-counter/plugin.json +24 -0
  59. package/dist/examples-apps/inventory-countdown/src/site/plugins/custom-elements/stock-counter/plugin.module.css +4 -0
  60. package/dist/examples-apps/inventory-countdown/src/site/plugins/custom-elements/stock-counter/plugin.tsx +132 -0
  61. package/dist/examples-apps/inventory-countdown/tsconfig.json +8 -0
  62. package/dist/examples-apps/inventory-countdown/wix.config.json +5 -0
  63. package/dist/examples-apps/mixpanel-analytics/.nvmrc +1 -0
  64. package/dist/examples-apps/mixpanel-analytics/README.md +21 -0
  65. package/dist/examples-apps/mixpanel-analytics/package-lock.json +6357 -0
  66. package/dist/examples-apps/mixpanel-analytics/package.json +31 -0
  67. package/dist/examples-apps/mixpanel-analytics/src/dashboard/components/ProjectToken.tsx +60 -0
  68. package/dist/examples-apps/mixpanel-analytics/src/dashboard/hooks/wix-embeds.ts +33 -0
  69. package/dist/examples-apps/mixpanel-analytics/src/dashboard/pages/page.json +5 -0
  70. package/dist/examples-apps/mixpanel-analytics/src/dashboard/pages/page.tsx +39 -0
  71. package/dist/examples-apps/mixpanel-analytics/src/dashboard/withProviders.tsx +19 -0
  72. package/dist/examples-apps/mixpanel-analytics/src/env.d.ts +4 -0
  73. package/dist/examples-apps/mixpanel-analytics/src/site/embedded-scripts/mixpanel-analytics/embedded.html +13 -0
  74. package/dist/examples-apps/mixpanel-analytics/src/site/embedded-scripts/mixpanel-analytics/embedded.json +7 -0
  75. package/dist/examples-apps/mixpanel-analytics/tsconfig.json +8 -0
  76. package/dist/examples-apps/mixpanel-analytics/wix.config.json +5 -0
  77. package/dist/examples-apps/my-locations-app/.nvmrc +1 -0
  78. package/dist/examples-apps/my-locations-app/README.md +21 -0
  79. package/dist/examples-apps/my-locations-app/package-lock.json +6351 -0
  80. package/dist/examples-apps/my-locations-app/package.json +31 -0
  81. package/dist/examples-apps/my-locations-app/src/dashboard/pages/page.json +5 -0
  82. package/dist/examples-apps/my-locations-app/src/dashboard/pages/page.tsx +89 -0
  83. package/dist/examples-apps/my-locations-app/src/dashboard/pages/wix_logo.svg +18 -0
  84. package/dist/examples-apps/my-locations-app/src/env.d.ts +4 -0
  85. package/dist/examples-apps/my-locations-app/tsconfig.json +8 -0
  86. package/dist/examples-apps/my-locations-app/wix.config.json +5 -0
  87. package/dist/examples-apps/site-popup/.nvmrc +1 -0
  88. package/dist/examples-apps/site-popup/README.md +21 -0
  89. package/dist/examples-apps/site-popup/package-lock.json +8033 -0
  90. package/dist/examples-apps/site-popup/package.json +34 -0
  91. package/dist/examples-apps/site-popup/postcss.config.js +7 -0
  92. package/dist/examples-apps/site-popup/src/components/activation-configuration.tsx +49 -0
  93. package/dist/examples-apps/site-popup/src/components/close-button.tsx +30 -0
  94. package/dist/examples-apps/site-popup/src/components/date-range-picker.tsx +49 -0
  95. package/dist/examples-apps/site-popup/src/components/image-picker.tsx +33 -0
  96. package/dist/examples-apps/site-popup/src/components/popup/index.css +3 -0
  97. package/dist/examples-apps/site-popup/src/components/popup/index.tsx +71 -0
  98. package/dist/examples-apps/site-popup/src/components/site-popup-settings.tsx +120 -0
  99. package/dist/examples-apps/site-popup/src/dashboard/hooks/wix-embeds.ts +33 -0
  100. package/dist/examples-apps/site-popup/src/dashboard/pages/page.tsx +78 -0
  101. package/dist/examples-apps/site-popup/src/dashboard/withProviders.tsx +19 -0
  102. package/dist/examples-apps/site-popup/src/env.d.ts +4 -0
  103. package/dist/examples-apps/site-popup/src/site/embedded-scripts/site-popup/embedded.html +12 -0
  104. package/dist/examples-apps/site-popup/src/site/embedded-scripts/site-popup/embedded.json +7 -0
  105. package/dist/examples-apps/site-popup/src/site/embedded-scripts/site-popup/params.dev.json +7 -0
  106. package/dist/examples-apps/site-popup/src/site/embedded-scripts/site-popup/popup-overlay/index.css +3 -0
  107. package/dist/examples-apps/site-popup/src/site/embedded-scripts/site-popup/popup-overlay/index.tsx +58 -0
  108. package/dist/examples-apps/site-popup/src/types.ts +14 -0
  109. package/dist/examples-apps/site-popup/tailwind.config.js +8 -0
  110. package/dist/examples-apps/site-popup/tsconfig.json +9 -0
  111. package/dist/examples-apps/site-popup/wix.config.json +5 -0
  112. package/dist/examples-apps/spis-examples/.nvmrc +1 -0
  113. package/dist/examples-apps/spis-examples/README.md +21 -0
  114. package/dist/examples-apps/spis-examples/package-lock.json +6903 -0
  115. package/dist/examples-apps/spis-examples/package.json +31 -0
  116. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-additional-fees/additional-fees/plugin.json +5 -0
  117. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-additional-fees/additional-fees/plugin.ts +24 -0
  118. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-discounts-trigger/discount-triggers/plugin.json +5 -0
  119. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-discounts-trigger/discount-triggers/plugin.ts +42 -0
  120. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-shipping-rates/shipping-rates/plugin.json +7 -0
  121. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-shipping-rates/shipping-rates/plugin.ts +34 -0
  122. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-validations/validations/plugin.json +6 -0
  123. package/dist/examples-apps/spis-examples/src/backend/service-plugins/ecom-validations/validations/plugin.ts +24 -0
  124. package/dist/examples-apps/spis-examples/src/backend/service-plugins/gift-cards-provider/gift-cards/plugin.json +5 -0
  125. package/dist/examples-apps/spis-examples/src/backend/service-plugins/gift-cards-provider/gift-cards/plugin.ts +38 -0
  126. package/dist/examples-apps/spis-examples/src/dashboard/pages/page.tsx +59 -0
  127. package/dist/examples-apps/spis-examples/src/dashboard/pages/wix_logo.svg +18 -0
  128. package/dist/examples-apps/spis-examples/src/env.d.ts +4 -0
  129. package/dist/examples-apps/spis-examples/tsconfig.json +8 -0
  130. package/dist/examples-apps/spis-examples/wix.config.json +5 -0
  131. package/dist/examples-apps/top-blog-posts/.nvmrc +1 -0
  132. package/dist/examples-apps/top-blog-posts/README.md +21 -0
  133. package/dist/examples-apps/top-blog-posts/package-lock.json +6406 -0
  134. package/dist/examples-apps/top-blog-posts/package.json +31 -0
  135. package/dist/examples-apps/top-blog-posts/src/dashboard/pages/blog-utils.ts +44 -0
  136. package/dist/examples-apps/top-blog-posts/src/dashboard/pages/page.tsx +129 -0
  137. package/dist/examples-apps/top-blog-posts/src/dashboard/pages/wix_logo.svg +18 -0
  138. package/dist/examples-apps/top-blog-posts/src/env.d.ts +4 -0
  139. package/dist/examples-apps/top-blog-posts/tsconfig.json +8 -0
  140. package/dist/examples-apps/top-blog-posts/wix.config.json +5 -0
  141. package/dist/out.js +1365 -0
  142. package/dist/wix-cli-templates/.nvmrc +1 -0
  143. package/dist/wix-cli-templates/README.md +21 -0
  144. package/dist/wix-cli-templates/package-lock.json +7118 -0
  145. package/dist/wix-cli-templates/package.json +35 -0
  146. package/dist/wix-cli-templates/src/assets/my-widget/thumbnail.png +0 -0
  147. package/dist/wix-cli-templates/src/backend/api/my-api/api.ts +29 -0
  148. package/dist/wix-cli-templates/src/backend/events/my-event/event.ts +16 -0
  149. package/dist/wix-cli-templates/src/backend/my-web-method.web.ts +21 -0
  150. package/dist/wix-cli-templates/src/backend/service-plugins/ecom-additional-fees/my-service-plugin/plugin.ts +9 -0
  151. package/dist/wix-cli-templates/src/backend/service-plugins/ecom-discounts-trigger/my-service-plugin/plugin.ts +14 -0
  152. package/dist/wix-cli-templates/src/backend/service-plugins/ecom-payment-settings/my-service-plugin/plugin.ts +12 -0
  153. package/dist/wix-cli-templates/src/backend/service-plugins/ecom-shipping-rates/my-service-plugin/plugin.ts +9 -0
  154. package/dist/wix-cli-templates/src/backend/service-plugins/ecom-validations/my-service-plugin/plugin.ts +9 -0
  155. package/dist/wix-cli-templates/src/backend/service-plugins/gift-cards-provider/my-service-plugin/plugin.ts +23 -0
  156. package/dist/wix-cli-templates/src/dashboard/modals/my-modal/modal.tsx +40 -0
  157. package/dist/wix-cli-templates/src/dashboard/pages/page.tsx +59 -0
  158. package/dist/wix-cli-templates/src/dashboard/pages/wix_logo.svg +18 -0
  159. package/dist/wix-cli-templates/src/env.d.ts +4 -0
  160. package/dist/wix-cli-templates/src/site/embedded-scripts/my-script/embedded.html +2 -0
  161. package/dist/wix-cli-templates/src/site/embedded-scripts/my-script/embedded.json +7 -0
  162. package/dist/wix-cli-templates/src/site/embedded-scripts/my-script/logger.ts +1 -0
  163. package/dist/wix-cli-templates/src/site/embedded-scripts/my-script/params.dev.json +3 -0
  164. package/dist/wix-cli-templates/src/site/widgets/custom-elements/my-widget/element.json +27 -0
  165. package/dist/wix-cli-templates/src/site/widgets/custom-elements/my-widget/element.module.css +32 -0
  166. package/dist/wix-cli-templates/src/site/widgets/custom-elements/my-widget/element.tsx +36 -0
  167. package/dist/wix-cli-templates/src/site/widgets/custom-elements/my-widget/panel.tsx +54 -0
  168. package/dist/wix-cli-templates/tsconfig.json +8 -0
  169. package/dist/wix-cli-templates/wix.config.json +5 -0
  170. package/package.json +28 -0
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "site-popup",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "@tanstack/react-query": "^4.36.1",
6
+ "@wix/app-management": "^1.0.0",
7
+ "@wix/dashboard": "^1.3.21",
8
+ "@wix/design-system": "^1.111.0",
9
+ "@wix/essentials": "^0.1.4",
10
+ "@wix/site-site": "^1.2.0",
11
+ "tailwindcss": "^3.4.1"
12
+ },
13
+ "devDependencies": {
14
+ "@types/react": "^16.0.0",
15
+ "@types/react-dom": "^16.0.0",
16
+ "@wix/cli": "^1.0.0",
17
+ "@wix/cli-app": "^1.0.0",
18
+ "@wix/sdk-types": "^1.0.0",
19
+ "autoprefixer": "^10.4.17",
20
+ "postcss": "^8.4.35",
21
+ "react": "16.14.0",
22
+ "react-dom": "16.14.0",
23
+ "typescript": "^5.3.3"
24
+ },
25
+ "scripts": {
26
+ "build": "wix app build",
27
+ "release": "wix app release",
28
+ "dev": "wix app dev",
29
+ "preview": "wix app preview",
30
+ "logs": "wix app logs",
31
+ "generate": "wix app generate",
32
+ "typecheck": "tsc --noEmit"
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
7
+
@@ -0,0 +1,49 @@
1
+ import React, { type FC } from 'react';
2
+ import { Box, RadioGroup } from '@wix/design-system';
3
+ import { ActivationMode, ActivationOptions } from '../types.js';
4
+ import { DataRangePicker } from './date-range-picker.js';
5
+
6
+ interface Props {
7
+ activationOptions: ActivationOptions;
8
+ onChange: (activationOptions: ActivationOptions) => void;
9
+ }
10
+
11
+ export const ActivationConfiguration: FC<Props> = ({
12
+ onChange,
13
+ activationOptions,
14
+ }) => {
15
+ return (
16
+ <Box gap={3} direction="vertical" marginTop={1}>
17
+ <RadioGroup
18
+ name="Popup Activation"
19
+ display="horizontal"
20
+ value={activationOptions.activationMode}
21
+ onChange={(val) =>
22
+ onChange({
23
+ ...activationOptions,
24
+ activationMode: val as ActivationMode,
25
+ })
26
+ }
27
+ >
28
+ <RadioGroup.Radio value="active">Active</RadioGroup.Radio>
29
+ <RadioGroup.Radio value="timed">Timed</RadioGroup.Radio>
30
+ <RadioGroup.Radio value="disabled">Disabled</RadioGroup.Radio>
31
+ </RadioGroup>
32
+ {activationOptions.activationMode == 'timed' && (
33
+ <DataRangePicker
34
+ startDate={Number(
35
+ activationOptions.startDate || new Date().getTime()
36
+ )}
37
+ endDate={Number(activationOptions.endDate || new Date().getTime())}
38
+ onChange={(startDate, endDate) =>
39
+ onChange({
40
+ activationMode: 'timed',
41
+ startDate: startDate.toString(),
42
+ endDate: endDate.toString(),
43
+ })
44
+ }
45
+ />
46
+ )}
47
+ </Box>
48
+ );
49
+ };
@@ -0,0 +1,30 @@
1
+ import React, { type FC } from 'react';
2
+
3
+ interface Props {
4
+ onClick?: () => void;
5
+ }
6
+
7
+ export const CloseButton: FC<Props> = ({ onClick }) => {
8
+ return (
9
+ <div className="flex justify-end p-2">
10
+ <button
11
+ onClick={onClick}
12
+ type="button"
13
+ className="bg-transparent bg-gray-200 text-slate-200 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center"
14
+ >
15
+ <svg
16
+ className="w-5 h-5"
17
+ fill="currentColor"
18
+ viewBox="0 0 20 20"
19
+ xmlns="http://www.w3.org/2000/svg"
20
+ >
21
+ <path
22
+ fillRule="evenodd"
23
+ d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
24
+ clipRule="evenodd"
25
+ ></path>
26
+ </svg>
27
+ </button>
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,49 @@
1
+ import React, { type FC } from 'react';
2
+ import { Box, Cell, DatePicker, FormField, Layout } from '@wix/design-system';
3
+
4
+ interface Props {
5
+ startDate: number;
6
+ endDate: number;
7
+ onChange?: (startDate: number, endDate: number) => void;
8
+ }
9
+
10
+ export const DataRangePicker: FC<Props> = ({
11
+ onChange,
12
+ startDate,
13
+ endDate,
14
+ }) => {
15
+ return (
16
+ <Layout>
17
+ <Cell span={6}>
18
+ <Box gap={2}>
19
+ <FormField label="Start date">
20
+ <Box marginTop={1}>
21
+ <DatePicker
22
+ width="100%"
23
+ placeholderText="Select"
24
+ value={new Date(startDate)}
25
+ onChange={(value: Date) => onChange?.(value.getTime(), endDate)}
26
+ />
27
+ </Box>
28
+ </FormField>
29
+ </Box>
30
+ </Cell>
31
+ <Cell span={6}>
32
+ <Box gap={2}>
33
+ <FormField label="End date">
34
+ <Box marginTop={1}>
35
+ <DatePicker
36
+ width="100%"
37
+ placeholderText="Select"
38
+ value={new Date(endDate)}
39
+ onChange={(value: Date) =>
40
+ onChange?.(startDate, value.getTime())
41
+ }
42
+ />
43
+ </Box>
44
+ </FormField>
45
+ </Box>
46
+ </Cell>
47
+ </Layout>
48
+ );
49
+ };
@@ -0,0 +1,33 @@
1
+ import React, { type FC } from 'react';
2
+ import { Box, Input, TextButton } from '@wix/design-system';
3
+ import { dashboard } from '@wix/dashboard';
4
+ import * as Icons from '@wix/wix-ui-icons-common';
5
+
6
+ interface Props {
7
+ imageUrl: string;
8
+ imageTitle: string;
9
+ onChange: (imageUrl: string, imageTitle: string) => void;
10
+ }
11
+
12
+ export const ImagePicker: FC<Props> = ({ onChange, imageTitle }) => {
13
+ return (
14
+ <Box gap={3} verticalAlign="middle" marginTop={1}>
15
+ <Input value={imageTitle} disabled />
16
+ <TextButton
17
+ prefixIcon={<Icons.Edit />}
18
+ onClick={() =>
19
+ dashboard.openMediaManager().then((response) => {
20
+ if (response?.items[0]) {
21
+ onChange(
22
+ response?.items[0].url || '',
23
+ response?.items[0].displayName || ''
24
+ );
25
+ }
26
+ })
27
+ }
28
+ >
29
+ Change image
30
+ </TextButton>
31
+ </Box>
32
+ );
33
+ };
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,71 @@
1
+ import React, { type FC } from 'react';
2
+ import { CloseButton } from '../close-button.js';
3
+ import { SitePopupOptions } from '../../types.js';
4
+ import './index.css';
5
+
6
+ function formatDateWithLocale(dateInMillis: string, locale: string) {
7
+ const date = new Date(Number(dateInMillis));
8
+ const formatter = new Intl.DateTimeFormat(locale, {
9
+ year: 'numeric',
10
+ month: 'long',
11
+ day: 'numeric',
12
+ });
13
+ return formatter.format(date);
14
+ }
15
+
16
+ export const Popup: FC<
17
+ SitePopupOptions & {
18
+ locale: string;
19
+ onClose?: (hideForever?: boolean) => void;
20
+ }
21
+ > = ({
22
+ headline,
23
+ text,
24
+ imageUrl,
25
+ imageTitle,
26
+ onClose,
27
+ startDate,
28
+ endDate,
29
+ locale,
30
+ }) => {
31
+ let formattedText = text;
32
+ if (startDate) {
33
+ formattedText = formattedText.replace(/{startDate}/g, formatDateWithLocale(startDate, locale));
34
+ }
35
+ if (endDate) {
36
+ formattedText = formattedText.replace(/{endDate}/g, formatDateWithLocale(endDate, locale));
37
+ }
38
+ return (
39
+ <div className="rounded-lg shadow-2xl grid md:grid md:grid-cols-2">
40
+ <div id="close-btn" className="absolute z-[1000]">
41
+ <CloseButton onClick={() => onClose?.()} />
42
+ </div>
43
+ <div className="p-4 text-center sm:p-6 md:col-span-1 lg:p-8 bg-gray-800 flex flex-col justify-between rounded-l-lg">
44
+ <div className="relative bottom-0 isolate overflow-hidden px-4 py-24 sm:px-12 xl:py-32">
45
+ <h4 className="mx-auto max-w-2xl text-center text-3xl font-bold tracking-tight sm:text-4xl text-white">
46
+ <span style={{font: 'var(--wst-font-style-h4)'}}>{headline}</span>
47
+ </h4>
48
+ <p className="mx-auto mt-2 max-w-xl text-center text-lg leading-8 text-gray-300">
49
+ <span style={{font: 'var(--wst-font-style-body-medium)'}}>{formattedText}</span>
50
+ </p>
51
+ </div>
52
+ <div className="flex justify-center items-center p-4">
53
+ <button
54
+ type="button"
55
+ className="flex-bottom text-sm text-white hover:underline"
56
+ onClick={() => onClose?.(true)}
57
+ >
58
+ <span style={{font: 'var(--wst-font-style-body-small)'}}>Don't show this again</span>
59
+ </button>
60
+ </div>
61
+ </div>
62
+ <img
63
+ width="50vw"
64
+ height="50vh"
65
+ src={imageUrl}
66
+ alt={imageTitle}
67
+ className="h-64 object-cover w-full md:h-full rounded-r-lg"
68
+ />
69
+ </div>
70
+ );
71
+ };
@@ -0,0 +1,120 @@
1
+ import React, { type FC } from 'react';
2
+ import {
3
+ Input,
4
+ Text,
5
+ Box,
6
+ InputArea,
7
+ Card,
8
+ FormField,
9
+ FormFieldProps,
10
+ } from '@wix/design-system';
11
+ import { SitePopupOptions } from '../types.js';
12
+ import { ActivationConfiguration } from './activation-configuration.js';
13
+ import { ImagePicker } from './image-picker.js';
14
+
15
+ interface Props {
16
+ options: SitePopupOptions;
17
+ onChange: (options: SitePopupOptions) => void;
18
+ }
19
+
20
+ export const SitePopupSettings: FC<Props> = ({ options, onChange }) => {
21
+ const getFieldStatus = (
22
+ field: keyof SitePopupOptions
23
+ ): Partial<FormFieldProps> => {
24
+ return !options[field]
25
+ ? {
26
+ status: 'error',
27
+ statusMessage: 'Required.',
28
+ }
29
+ : {};
30
+ };
31
+
32
+ return (
33
+ <Box direction="vertical">
34
+ <Box gap={10} direction="vertical">
35
+ <Card>
36
+ <Card.Header
37
+ title="Settings"
38
+ subtitle={
39
+ <Box direction="horizontal">
40
+ <Text secondary>Customize your site popup appearance.</Text>
41
+ </Box>
42
+ }
43
+ />
44
+ <Card.Divider />
45
+ <Card.Content>
46
+ <Box gap={3} direction="vertical">
47
+ <Box gap={3} direction="vertical" width={'50%'}>
48
+ <FormField
49
+ labelSize="small"
50
+ label="Headline"
51
+ {...getFieldStatus('headline')}
52
+ >
53
+ <Input
54
+ placeholder="Sale 20% Off"
55
+ value={options?.headline}
56
+ onChange={(e) =>
57
+ onChange({
58
+ ...options,
59
+ headline: e.currentTarget.value,
60
+ })
61
+ }
62
+ />
63
+ </FormField>
64
+ <FormField
65
+ labelSize="small"
66
+ label="Text"
67
+ infoContent={
68
+ options.activationMode == 'timed'
69
+ ? 'Include the placeholders {startDate} and {endDate} to show the start and end dates, formatted according to the site\'s regional settings.'
70
+ : undefined
71
+ }
72
+ {...getFieldStatus('text')}
73
+ >
74
+ <InputArea
75
+ placeholder="Sign up and get 20% off on our Winter Sale"
76
+ value={options?.text}
77
+ onChange={(e) =>
78
+ onChange({
79
+ ...options,
80
+ text: e.currentTarget.value,
81
+ })
82
+ }
83
+ />
84
+ </FormField>
85
+ <FormField labelSize="small" label="Popup Activation">
86
+ <ActivationConfiguration
87
+ activationOptions={{
88
+ activationMode: options.activationMode,
89
+ startDate: options.startDate,
90
+ endDate: options.endDate,
91
+ }}
92
+ onChange={(activationOptions) =>
93
+ onChange({
94
+ ...options,
95
+ ...activationOptions,
96
+ })
97
+ }
98
+ />
99
+ </FormField>
100
+ <FormField labelSize="small" label="Popup Image">
101
+ <ImagePicker
102
+ imageTitle={options.imageTitle}
103
+ imageUrl={options.imageUrl}
104
+ onChange={(imageUrl, imageTitle) =>
105
+ onChange({
106
+ ...options,
107
+ imageUrl,
108
+ imageTitle,
109
+ })
110
+ }
111
+ />
112
+ </FormField>
113
+ </Box>
114
+ </Box>
115
+ </Card.Content>
116
+ </Card>
117
+ </Box>
118
+ </Box>
119
+ );
120
+ };
@@ -0,0 +1,33 @@
1
+ import { embeddedScripts } from '@wix/app-management';
2
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
3
+
4
+ export const QUERY_EMBEDS = 'queryEmbeds';
5
+ export const MUTATE_EMBEDS = 'mutateEmbeds';
6
+
7
+ export const useEmbeds = <T extends Record<string, string>>() => {
8
+ const queryClient = useQueryClient();
9
+
10
+ const getEmbeddedScript = useQuery<unknown, unknown, T>({
11
+ queryKey: [QUERY_EMBEDS],
12
+ refetchOnWindowFocus: false,
13
+ queryFn: async () => {
14
+ // https://dev.wix.com/docs/sdk/backend-modules/app-management/embedded-scripts/get-embedded-script
15
+ const embeddedScript = await embeddedScripts.getEmbeddedScript();
16
+ return embeddedScript.parameters || {};
17
+ },
18
+ });
19
+
20
+ const embedScript = useMutation<unknown, unknown, T>({
21
+ mutationKey: [MUTATE_EMBEDS],
22
+ mutationFn: async (parameters) => {
23
+ // https://dev.wix.com/docs/sdk/backend-modules/app-management/embedded-scripts/embed-script
24
+ await embeddedScripts.embedScript({ parameters });
25
+ return parameters;
26
+ },
27
+ onSuccess: (data) => {
28
+ queryClient.setQueryData([QUERY_EMBEDS], data);
29
+ },
30
+ });
31
+
32
+ return { embedScript, getEmbeddedScript };
33
+ };
@@ -0,0 +1,78 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { i18n } from '@wix/essentials';
3
+ import { Box, Button, Cell, Layout, Loader, Page } from '@wix/design-system';
4
+ import '@wix/design-system/styles.global.css';
5
+ import { withProviders } from '../withProviders';
6
+ import { SitePopupSettings } from '../../components/site-popup-settings.js';
7
+ import { SitePopupOptions } from '../../types.js';
8
+ import { useEmbeds } from '../hooks/wix-embeds.js';
9
+ import { Popup } from '../../components/popup/index.js';
10
+
11
+ const sitePopupDefaultOptions: SitePopupOptions = {
12
+ headline: 'Sale 20% Off',
13
+ text: 'Sign up and get 20% off on our Winter Sale',
14
+ imageUrl:
15
+ 'https://static.wixstatic.com/media/11062b_db81bbf678b641ff9e00b768cb155a49~mv2.jpg',
16
+ imageTitle: 'Clothes For Sale',
17
+ activationMode: 'active',
18
+ };
19
+
20
+ function SitePopup() {
21
+ const locale = i18n.getLocale();
22
+
23
+ const { embedScript, getEmbeddedScript } =
24
+ useEmbeds<Partial<SitePopupOptions>>();
25
+
26
+ const [sitePopupOptions, setSitePopupOptions] = useState<SitePopupOptions>(
27
+ sitePopupDefaultOptions
28
+ );
29
+
30
+ useEffect(() => {
31
+ setSitePopupOptions((prevOptions) => ({
32
+ ...prevOptions,
33
+ ...getEmbeddedScript.data,
34
+ imageUrl: (
35
+ getEmbeddedScript.data?.imageUrl || prevOptions.imageUrl
36
+ ).replace(/\\/g, ''),
37
+ }));
38
+ }, [getEmbeddedScript.data]);
39
+
40
+ return (
41
+ <Page height="100vh">
42
+ <Page.Header
43
+ title="Site Popup"
44
+ subtitle="Configure site popup setting & preview as it will appear on your site."
45
+ actionsBar={
46
+ <Button
47
+ skin="inverted"
48
+ disabled={!sitePopupOptions.headline || !sitePopupOptions.text}
49
+ onClick={() => embedScript.mutate({ ...sitePopupOptions })}
50
+ >
51
+ {embedScript.isLoading ? <Loader size="tiny" /> : 'Save'}
52
+ </Button>
53
+ }
54
+ />
55
+ <Page.Content>
56
+ {getEmbeddedScript.isLoading ? (
57
+ <Box align="center" verticalAlign="middle" height="50vh">
58
+ <Loader text="Loading..." />
59
+ </Box>
60
+ ) : (
61
+ <Layout>
62
+ <Cell>
63
+ <SitePopupSettings
64
+ options={sitePopupOptions}
65
+ onChange={(options) => setSitePopupOptions(options)}
66
+ />
67
+ </Cell>
68
+ <Cell>
69
+ <Popup {...sitePopupOptions} locale={locale} />
70
+ </Cell>
71
+ </Layout>
72
+ )}
73
+ </Page.Content>
74
+ </Page>
75
+ );
76
+ }
77
+
78
+ export default withProviders(SitePopup);
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
3
+ import { WixDesignSystemProvider } from '@wix/design-system';
4
+ import { i18n } from '@wix/essentials';
5
+
6
+ const queryClient = new QueryClient();
7
+
8
+ export function withProviders<P extends {} = {}>(Component: React.FC<P>) {
9
+ return function DashboardProviders(props: P) {
10
+ const locale = i18n.getLocale();
11
+ return (
12
+ <WixDesignSystemProvider locale={locale} features={{ newColorsBranding: true }}>
13
+ <QueryClientProvider client={queryClient}>
14
+ <Component {...props} />
15
+ </QueryClientProvider>
16
+ </WixDesignSystemProvider>
17
+ );
18
+ };
19
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="@wix/cli-app/client" />
2
+ /// <reference types="@wix/sdk-types/client" />
3
+
4
+ // NOTE: This file should not be edited. This is an auto-generated file.
@@ -0,0 +1,12 @@
1
+ <div
2
+ id="popup-data"
3
+ data-headline="{{headline}}"
4
+ data-text="{{text}}"
5
+ data-activation-mode="{{activationMode}}"
6
+ data-start-date="{{startDate}}"
7
+ data-end-date="{{endDate}}"
8
+ data-image-url="{{imageUrl}}"
9
+ data-image-title="{{imageTitle}}"
10
+ ></div>
11
+ <div id="site-popup"></div>
12
+ <script type="module" src="./popup-overlay/index.tsx"></script>
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://dev.wix.com/wix-cli/schemas/embedded-script.json",
3
+ "id": "2c43c310-939b-451d-b488-805f7ebba6ab",
4
+ "name": "Site Popup",
5
+ "scriptType": "FUNCTIONAL",
6
+ "placement": "BODY_START"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "headline": "Sale 20% Off",
3
+ "text": "Sign up and get 20% off on our Winter Sale",
4
+ "imageUrl": "https://static.wixstatic.com/media/11062b_db81bbf678b641ff9e00b768cb155a49~mv2.jpg",
5
+ "imageTitle": "Clothes For Sale",
6
+ "activationMode": "active"
7
+ }
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,58 @@
1
+ import ReactDOM from 'react-dom';
2
+ import React, { useEffect, useState } from 'react';
3
+ import { Popup } from '../../../../components/popup/index.js';
4
+ import { SitePopupOptions } from '../../../../types.js';
5
+ import './index.css';
6
+ import { site } from '@wix/site-site';
7
+
8
+ const PopupOverlay = () => {
9
+ const [shown, setShown] = useState<boolean>(false);
10
+ const el = document.querySelector('#popup-data') as HTMLElement;
11
+ const popupParams = el?.dataset as SitePopupOptions;
12
+
13
+ const [regionalSettings, setRegionalSettings] = useState<string>('en-us');
14
+
15
+ useEffect(() => {
16
+ site.regionalSettings().then(setRegionalSettings);
17
+ }, []);
18
+
19
+ useEffect(() => {
20
+ const isPopupShownStorage = localStorage.getItem('isPopupShown');
21
+ setShown(isPopupShownStorage !== 'false');
22
+ }, []);
23
+
24
+ const closePopup = (hideForever?: boolean) => {
25
+ setShown(false);
26
+ if (hideForever) {
27
+ localStorage.setItem('isPopupShown', 'false');
28
+ }
29
+ };
30
+
31
+ const shouldShowPopup = () => {
32
+ if (popupParams.activationMode === 'timed') {
33
+ return (
34
+ Date.now() > new Date(Number(popupParams.startDate)).getTime() &&
35
+ Date.now() < new Date(Number(popupParams.endDate)).getTime()
36
+ );
37
+ } else if (popupParams.activationMode === 'active') {
38
+ return true;
39
+ }
40
+ return false;
41
+ };
42
+
43
+ return (
44
+ <div
45
+ className={
46
+ shown && shouldShowPopup()
47
+ ? 'fixed flex justify-center items-center inset-0 z-[1000] bg-gray-300 bg-opacity-75'
48
+ : 'hidden'
49
+ }
50
+ >
51
+ <div className="w-9/12">
52
+ <Popup {...popupParams} locale={regionalSettings} onClose={closePopup} />
53
+ </div>
54
+ </div>
55
+ );
56
+ };
57
+
58
+ ReactDOM.render(<PopupOverlay />, document.getElementById('site-popup'));
@@ -0,0 +1,14 @@
1
+ export type ActivationMode = 'active' | 'timed' | 'disabled';
2
+
3
+ export type ActivationOptions = {
4
+ activationMode: ActivationMode;
5
+ startDate?: string;
6
+ endDate?: string;
7
+ };
8
+
9
+ export type SitePopupOptions = {
10
+ headline: string;
11
+ text: string;
12
+ imageUrl: string;
13
+ imageTitle: string;
14
+ } & ActivationOptions;
@@ -0,0 +1,8 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: ["./src/**/*.{js,jsx,ts,tsx}"],
4
+ theme: {
5
+ extend: {},
6
+ },
7
+ plugins: [],
8
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@wix/cli-app/tsconfig.app.json",
3
+ "compilerOptions": {
4
+ "jsx": "react",
5
+ "rootDir": "src",
6
+ "types": ["react"]
7
+ },
8
+ "include": ["src"]
9
+ }