pds-dev-kit-web-test 2.3.5 → 2.3.6

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.
@@ -0,0 +1,14 @@
1
+ import type { FontResponse, PublHeaders, SearchParams } from './types';
2
+ export declare const DEFAULT_PAGINATION: {
3
+ page: number;
4
+ limit: number;
5
+ };
6
+ export declare const DEFAULT_FILTER: {
7
+ sort: string;
8
+ order: string;
9
+ };
10
+ export declare const DEFAULT_SEARCHQUERY: {
11
+ usecase: string;
12
+ searchTerm: string;
13
+ };
14
+ export declare function fetchSandollFonts(baseURL: string, searchParams: SearchParams, publHeaders: PublHeaders): Promise<FontResponse>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.fetchSandollFonts = exports.DEFAULT_SEARCHQUERY = exports.DEFAULT_FILTER = exports.DEFAULT_PAGINATION = void 0;
40
+ exports.DEFAULT_PAGINATION = { page: 1, limit: 100 };
41
+ exports.DEFAULT_FILTER = { sort: 'trending', order: 'ASC' };
42
+ exports.DEFAULT_SEARCHQUERY = { usecase: 'EDITOR', searchTerm: '' };
43
+ function fetchSandollFonts(baseURL, searchParams, publHeaders) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var url, searchQuery, pagination, filter, response;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ url = new URL('/seller/api/v2/channel-management/font-manager/sandoll/available-fonts', baseURL);
50
+ searchQuery = searchParams.searchQuery, pagination = searchParams.pagination, filter = searchParams.filter;
51
+ // Set query parameters
52
+ url.searchParams.append('usecase', searchQuery.usecase || 'EDITOR');
53
+ if (searchQuery.searchTerm) {
54
+ url.searchParams.append('searchTerm', searchQuery.searchTerm);
55
+ }
56
+ url.searchParams.append('page', pagination.page.toString());
57
+ url.searchParams.append('limit', pagination.limit.toString());
58
+ url.searchParams.append('sort', filter.sort);
59
+ url.searchParams.append('order', filter.order);
60
+ return [4 /*yield*/, fetch(url.toString(), {
61
+ method: 'GET',
62
+ headers: {
63
+ Authorization: "Bearer ".concat(publHeaders.channelToken),
64
+ 'x-publ-channel-id': "".concat(publHeaders.channelId)
65
+ }
66
+ })];
67
+ case 1:
68
+ response = _a.sent();
69
+ if (!response.ok) {
70
+ throw new Error('Network response was not ok');
71
+ }
72
+ return [2 /*return*/, response.json()];
73
+ }
74
+ });
75
+ });
76
+ }
77
+ exports.fetchSandollFonts = fetchSandollFonts;
@@ -0,0 +1,47 @@
1
+ export type Pagination = {
2
+ page: number;
3
+ limit: number;
4
+ };
5
+ export type Filter = {
6
+ sort: 'trending' | 'popularity' | 'date' | 'alpha';
7
+ order: 'ASC' | 'DESC';
8
+ };
9
+ export type SearchQuery = {
10
+ usecase?: 'EDITOR';
11
+ searchTerm?: string;
12
+ };
13
+ export type SandollFont = {
14
+ id: string;
15
+ distinctId: string;
16
+ fontEnumValue: string;
17
+ provider: string;
18
+ fontName: string;
19
+ fontFamilyName: string;
20
+ supportedWeights: number[];
21
+ providerFontId: string;
22
+ providerFontName: string;
23
+ providerFontFamilyId: string;
24
+ providerFontFamilyName: string;
25
+ providerCssInfoDict: CSSInfoDict;
26
+ };
27
+ export type CSSInfoDict = {
28
+ fontFamily: string;
29
+ fontWeight: number;
30
+ };
31
+ export type SupportedOptionMap = {};
32
+ export type FontResponse = {
33
+ data: {
34
+ availableFonts: SandollFont[];
35
+ supportedOptions: SupportedOptionMap;
36
+ pagination: Pagination;
37
+ };
38
+ };
39
+ export type SearchParams = {
40
+ pagination: Pagination;
41
+ searchQuery: SearchQuery;
42
+ filter: Filter;
43
+ };
44
+ export type PublHeaders = {
45
+ channelToken: string;
46
+ channelId: string;
47
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +1,18 @@
1
1
  /// <reference types="react" />
2
- import type { SANDOLL_Font, SANDOLL_SortOptionType, SANDOLL_FilterOptionType, SANDOLL_ChangeFilterOptionHandler } from '../types';
2
+ import type { PublHeaders, SearchParams } from '../api/types';
3
+ import type { SANDOLL_Font, SANDOLL_FilterOptionType, SANDOLL_ChangeFilterOptionHandler } from '../types';
3
4
  type HeadlessProps = {
4
5
  isLoading: boolean;
5
6
  fonts: SANDOLL_Font[];
6
- filteredFonts: SANDOLL_Font[];
7
7
  filterOptions: SANDOLL_FilterOptionType;
8
- changeSort: (option: SANDOLL_SortOptionType) => void;
8
+ changeSort: (option: SearchParams) => void;
9
9
  changeFilterOption: SANDOLL_ChangeFilterOptionHandler;
10
10
  };
11
11
  type Props = {
12
- apiKey: string;
13
- sort: SANDOLL_SortOptionType;
12
+ baseURL: string;
13
+ searchParams: SearchParams;
14
+ publHeaders: PublHeaders;
14
15
  children: (args: HeadlessProps) => JSX.Element;
15
16
  };
16
- declare function GoogleFontsList({ apiKey, sort, children }: Props): JSX.Element;
17
- export default GoogleFontsList;
17
+ declare function SandollFontsList({ baseURL, searchParams, publHeaders, children }: Props): JSX.Element;
18
+ export default SandollFontsList;
@@ -46,17 +46,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
49
  Object.defineProperty(exports, "__esModule", { value: true });
53
50
  var react_1 = require("react");
54
- // import getGoogleWebFonts from '../api/getGoogleWebFonts';
55
- // import getFontId from '../utils/getFontId';
56
- var delay_1 = __importDefault(require("../utils/delay"));
51
+ var getSandollFonts_1 = require("../api/getSandollFonts");
57
52
  var DEFAULT_CATEGORIES = ['serif'];
58
- function GoogleFontsList(_a) {
59
- var apiKey = _a.apiKey, sort = _a.sort, children = _a.children;
53
+ function SandollFontsList(_a) {
54
+ var baseURL = _a.baseURL, searchParams = _a.searchParams, publHeaders = _a.publHeaders, children = _a.children;
60
55
  var _b = (0, react_1.useState)(false), isLoading = _b[0], setIsLoading = _b[1];
61
56
  var _c = (0, react_1.useState)([]), fonts = _c[0], setFonts = _c[1];
62
57
  var _d = (0, react_1.useState)({
@@ -66,24 +61,15 @@ function GoogleFontsList(_a) {
66
61
  (0, react_1.useEffect)(function () {
67
62
  function call() {
68
63
  return __awaiter(this, void 0, void 0, function () {
69
- var items;
64
+ var res;
70
65
  return __generator(this, function (_a) {
71
66
  switch (_a.label) {
72
67
  case 0:
73
68
  setIsLoading(true);
74
- return [4 /*yield*/, (0, delay_1.default)(2000)];
69
+ return [4 /*yield*/, (0, getSandollFonts_1.fetchSandollFonts)(baseURL, searchParams, publHeaders)];
75
70
  case 1:
76
- _a.sent();
77
- items = [
78
- { id: '1', family: 'sandoll-test-1', category: 'san-serif' },
79
- { id: '2', family: 'sandoll-test-2', category: 'deco' },
80
- { id: '3', family: 'sandoll-test-3', category: 'round' }
81
- ];
82
- // const { items } = await getGoogleWebFonts({
83
- // key: apiKey,
84
- // sort
85
- // });
86
- setFonts(items);
71
+ res = _a.sent();
72
+ setFonts(res.data.availableFonts);
87
73
  setIsLoading(false);
88
74
  return [2 /*return*/];
89
75
  }
@@ -91,23 +77,19 @@ function GoogleFontsList(_a) {
91
77
  });
92
78
  }
93
79
  call();
94
- }, [apiKey, sort]);
95
- function changeSort(sortOption) {
80
+ }, [baseURL, searchParams, publHeaders]);
81
+ function changeSort(searchParams) {
96
82
  return __awaiter(this, void 0, void 0, function () {
97
- var items;
83
+ var res;
98
84
  return __generator(this, function (_a) {
99
85
  switch (_a.label) {
100
86
  case 0:
101
87
  setIsLoading(true);
102
- return [4 /*yield*/, (0, delay_1.default)(2000)];
88
+ return [4 /*yield*/, (0, getSandollFonts_1.fetchSandollFonts)(baseURL, searchParams, publHeaders)];
103
89
  case 1:
104
- _a.sent();
105
- items = [
106
- { id: '4', family: 'sandoll-test-4', category: 'san-serif' },
107
- { id: '5', family: 'sandoll-test-5', category: 'deco' },
108
- { id: '6', family: 'sandoll-test-6', category: 'round' }
109
- ];
110
- setFonts(items);
90
+ res = _a.sent();
91
+ setFonts(res.data.availableFonts);
92
+ setIsLoading(false);
111
93
  return [2 /*return*/];
112
94
  }
113
95
  });
@@ -120,26 +102,25 @@ function GoogleFontsList(_a) {
120
102
  return (__assign(__assign({}, prev), (_a = {}, _a[name] = value, _a)));
121
103
  });
122
104
  }
123
- var filteredFonts = fonts.filter(function (font) {
124
- var categories = filterOptions.categories, searchQuery = filterOptions.searchQuery;
125
- var isSelectedCategory = categories.includes(font.category);
126
- var query = searchQuery.toLocaleLowerCase().trim();
127
- var matchSearchQuery = font.family.toLocaleLowerCase().includes(query);
128
- if (!matchSearchQuery) {
129
- return false;
130
- }
131
- if (isSelectedCategory) {
132
- return true;
133
- }
134
- return false;
135
- });
105
+ // const filteredFonts = fonts.filter((font) => {
106
+ // const { categories, searchQuery } = filterOptions;
107
+ // const isSelectedCategory = categories.includes(font.category);
108
+ // const query = searchQuery.toLocaleLowerCase().trim();
109
+ // const matchSearchQuery = font.family.toLocaleLowerCase().includes(query);
110
+ // if (!matchSearchQuery) {
111
+ // return false;
112
+ // }
113
+ // if (isSelectedCategory) {
114
+ // return true;
115
+ // }
116
+ // return false;
117
+ // });
136
118
  return children({
137
119
  isLoading: isLoading,
138
120
  fonts: fonts,
139
- filteredFonts: filteredFonts,
140
121
  filterOptions: filterOptions,
141
122
  changeSort: changeSort,
142
123
  changeFilterOption: changeFilterOption
143
124
  });
144
125
  }
145
- exports.default = GoogleFontsList;
126
+ exports.default = SandollFontsList;
@@ -1,4 +1,5 @@
1
1
  export { default as SandollFontItem } from './headless/SandollFontItem';
2
2
  export { default as SandollFontsList } from './headless/SandollFontsList';
3
+ export { default as createSandollFontLink } from './utils/createSandollFontLink';
3
4
  export * from './types';
4
5
  export * from './constants';
@@ -17,10 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.SandollFontsList = exports.SandollFontItem = void 0;
20
+ exports.createSandollFontLink = exports.SandollFontsList = exports.SandollFontItem = void 0;
21
21
  var SandollFontItem_1 = require("./headless/SandollFontItem");
22
22
  Object.defineProperty(exports, "SandollFontItem", { enumerable: true, get: function () { return __importDefault(SandollFontItem_1).default; } });
23
23
  var SandollFontsList_1 = require("./headless/SandollFontsList");
24
24
  Object.defineProperty(exports, "SandollFontsList", { enumerable: true, get: function () { return __importDefault(SandollFontsList_1).default; } });
25
+ var createSandollFontLink_1 = require("./utils/createSandollFontLink");
26
+ Object.defineProperty(exports, "createSandollFontLink", { enumerable: true, get: function () { return __importDefault(createSandollFontLink_1).default; } });
25
27
  __exportStar(require("./types"), exports);
26
28
  __exportStar(require("./constants"), exports);
@@ -1,9 +1,6 @@
1
+ import type { SandollFont } from './api/types';
1
2
  import type { PDSIconType } from '../../common/types';
2
- export type SANDOLL_Font = {
3
- family: string;
4
- id: string;
5
- category: SANDOLL_CategoryType;
6
- };
3
+ export type SANDOLL_Font = SandollFont;
7
4
  export type SANDOLL_CategoryType = 'serif' | 'san-serif' | 'slab' | 'round' | 'script' | 'deco' | 'symbol' | 'blackLetter';
8
5
  export type SANDOLL_SortOptionType = 'date' | 'alpha';
9
6
  export type SANDOLL_CategoryIconType = Record<SANDOLL_Category, PDSIconType>;
@@ -0,0 +1,2 @@
1
+ declare function createSandollFontLink(href: string): void;
2
+ export default createSandollFontLink;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // href: CSS_URI_FOR_PUBL_OR_INDIVIDUAL_URI
4
+ function createSandollFontLink(href) {
5
+ try {
6
+ var linkTag = document.createElement('link');
7
+ linkTag.setAttribute('rel', 'stylesheet');
8
+ linkTag.setAttribute('charset', 'utf-8');
9
+ linkTag.setAttribute('href', href);
10
+ document.head.appendChild(linkTag);
11
+ }
12
+ catch (error) {
13
+ console.error(error);
14
+ }
15
+ }
16
+ exports.default = createSandollFontLink;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pds-dev-kit-web-test",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "dist/index.js",