@enonic/nextjs-adapter 2.0.0-B3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.eslint-childrc.js +17 -0
  2. package/.eslintrc.js +15 -0
  3. package/.github/dependabot.yml +20 -0
  4. package/.github/pull-merger.yml +1 -0
  5. package/.github/workflows/release.yml +39 -0
  6. package/LICENSE +201 -0
  7. package/RELEASE.md +75 -0
  8. package/package.json +8 -7
  9. package/server/.eslintrc.js +11 -0
  10. package/server/ClearableFileCache.ts +410 -0
  11. package/server/cache.ts +50 -0
  12. package/server/index.ts +74 -0
  13. package/server/tsconfig.json +23 -0
  14. package/setversion.js +8 -0
  15. package/src/.eslintrc.js +11 -0
  16. package/src/ComponentRegistry.ts +189 -0
  17. package/{UrlProcessor.js → src/UrlProcessor.ts} +54 -36
  18. package/{baseMappings.js → src/baseMappings.ts} +13 -3
  19. package/{guillotine/fetchContent.js → src/guillotine/fetchContent.ts} +496 -243
  20. package/src/guillotine/getMetaData.ts +246 -0
  21. package/{index.d.ts → src/index.ts} +1 -1
  22. package/src/tsconfig.json +20 -0
  23. package/{utils.js → src/utils.ts} +160 -70
  24. package/{views/BaseComponent.jsx → src/views/BaseComponent.tsx} +73 -39
  25. package/{views/BaseContent.jsx → src/views/BaseContent.tsx} +24 -17
  26. package/src/views/BaseLayout.tsx +45 -0
  27. package/{views/BaseMacro.jsx → src/views/BaseMacro.tsx} +45 -29
  28. package/src/views/BasePage.tsx +56 -0
  29. package/src/views/BasePart.tsx +50 -0
  30. package/{views/Empty.jsx → src/views/Empty.tsx} +2 -0
  31. package/src/views/Fragment.tsx +45 -0
  32. package/src/views/MainView.tsx +21 -0
  33. package/src/views/Region.tsx +89 -0
  34. package/{views/RichTextView.jsx → src/views/RichTextView.tsx} +31 -10
  35. package/{views/SingleComponent.jsx → src/views/SingleComponent.tsx} +8 -2
  36. package/src/views/StaticContent.tsx +40 -0
  37. package/src/views/Text.tsx +15 -0
  38. package/src/views/macros/DefaultMacro.tsx +9 -0
  39. package/src/views/macros/DisableMacro.tsx +8 -0
  40. package/ComponentRegistry.d.ts +0 -64
  41. package/ComponentRegistry.js +0 -121
  42. package/UrlProcessor.d.ts +0 -25
  43. package/baseMappings.d.ts +0 -1
  44. package/guillotine/fetchContent.d.ts +0 -48
  45. package/guillotine/getMetaData.d.ts +0 -94
  46. package/guillotine/getMetaData.js +0 -128
  47. package/index.js +0 -5
  48. package/query/Shortcut.d.ts +0 -1
  49. package/server/ClearableFileCache.d.ts +0 -31
  50. package/server/ClearableFileCache.js +0 -472
  51. package/server/cache.d.ts +0 -2
  52. package/server/cache.js +0 -129
  53. package/server/index.d.ts +0 -5
  54. package/server/index.js +0 -132
  55. package/utils.d.ts +0 -114
  56. package/views/BaseComponent.d.ts +0 -25
  57. package/views/BaseContent.d.ts +0 -4
  58. package/views/BaseLayout.d.ts +0 -17
  59. package/views/BaseLayout.jsx +0 -24
  60. package/views/BaseMacro.d.ts +0 -16
  61. package/views/BasePage.d.ts +0 -19
  62. package/views/BasePage.jsx +0 -34
  63. package/views/BasePart.d.ts +0 -19
  64. package/views/BasePart.jsx +0 -24
  65. package/views/Empty.d.ts +0 -3
  66. package/views/Fragment.d.ts +0 -10
  67. package/views/Fragment.jsx +0 -30
  68. package/views/MainView.d.ts +0 -4
  69. package/views/MainView.jsx +0 -14
  70. package/views/Region.d.ts +0 -20
  71. package/views/Region.jsx +0 -52
  72. package/views/RichTextView.d.ts +0 -16
  73. package/views/SingleComponent.d.ts +0 -5
  74. package/views/StaticContent.d.ts +0 -15
  75. package/views/StaticContent.jsx +0 -36
  76. package/views/Text.d.ts +0 -9
  77. package/views/Text.jsx +0 -4
  78. package/views/macros/DefaultMacro.d.ts +0 -4
  79. package/views/macros/DefaultMacro.jsx +0 -3
  80. package/views/macros/DisableMacro.d.ts +0 -3
  81. package/views/macros/DisableMacro.jsx +0 -2
  82. /package/{query/Shortcut.js → src/query/Shortcut.ts} +0 -0
package/server/cache.js DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.purgeCache = void 0;
63
- var fs = __importStar(require("fs"));
64
- var getCacheHandler = function (cache) {
65
- return cache.cacheHandler;
66
- };
67
- var purgeCache = function (cache, pathname) { return __awaiter(void 0, void 0, void 0, function () {
68
- return __generator(this, function (_a) {
69
- if (pathname) {
70
- return [2 /*return*/, purgePath(cache, pathname)];
71
- }
72
- else {
73
- return [2 /*return*/, purgeAll(cache)];
74
- }
75
- return [2 /*return*/];
76
- });
77
- }); };
78
- exports.purgeCache = purgeCache;
79
- var purgePath = function (cache, pathname) { return __awaiter(void 0, void 0, void 0, function () {
80
- var handler, fsPathObj;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- handler = getCacheHandler(cache);
85
- return [4 /*yield*/, handler.getFsPath({ pathname: pathname })];
86
- case 1:
87
- fsPathObj = _a.sent();
88
- try {
89
- /* Delete entry in cache */
90
- handler.delete(pathname);
91
- /* Delete files from disc */
92
- fs.unlinkSync("".concat(fsPathObj.filePath, ".html"));
93
- fs.unlinkSync("".concat(fsPathObj.filePath, ".json"));
94
- console.info("\nCache deleted for '".concat(fsPathObj.filePath, "'\n"));
95
- }
96
- catch (err) {
97
- console.error("Could not delete cache of '".concat(fsPathObj.filePath, "':"), err);
98
- }
99
- return [2 /*return*/];
100
- }
101
- });
102
- }); };
103
- var purgeAll = function (cache) { return __awaiter(void 0, void 0, void 0, function () {
104
- var handler, pagesRoot, err_1;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- handler = getCacheHandler(cache);
109
- _a.label = 1;
110
- case 1:
111
- _a.trys.push([1, 3, , 4]);
112
- /* Purge cache */
113
- handler.clear();
114
- return [4 /*yield*/, handler.getFsPath({ pathname: '' })];
115
- case 2:
116
- pagesRoot = (_a.sent()).filePath;
117
- if (fs.existsSync(pagesRoot)) {
118
- fs.rmSync(pagesRoot, { recursive: true });
119
- }
120
- console.info('\nCache was successfully purged\n');
121
- return [3 /*break*/, 4];
122
- case 3:
123
- err_1 = _a.sent();
124
- console.error('Could not purge cache:', err_1);
125
- return [3 /*break*/, 4];
126
- case 4: return [2 /*return*/];
127
- }
128
- });
129
- }); };
package/server/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { NextServer } from 'next/dist/server/next';
2
- export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
3
- export declare const withEnonicCache: (config: any) => any;
4
- declare const _default: (next: (options: any) => any) => Promise<NextServer>;
5
- export default _default;
package/server/index.js DELETED
@@ -1,132 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.withEnonicCache = exports.PURGE_CACHE_URL = void 0;
43
- var http_1 = require("http");
44
- var cache_1 = require("./cache");
45
- var path_1 = __importDefault(require("path"));
46
- var hostname = process.env.HOST || '127.0.0.1';
47
- var dev = process.env.NODE_ENV !== 'production';
48
- var port = process.env.PORT && parseInt(process.env.PORT, 10) || (dev ? 3000 : 4242);
49
- exports.PURGE_CACHE_URL = '/_/enonic/cache/purge';
50
- var withEnonicCache = function (config) {
51
- var exp = config.experimental || {};
52
- exp.isrMemoryCacheSize = exp.isrMemoryCacheSize || 1000000;
53
- exp.incrementalCacheHandlerPath = path_1.default.resolve(__dirname, 'ClearableFileCache.js');
54
- config.experimental = exp;
55
- return config;
56
- };
57
- exports.withEnonicCache = withEnonicCache;
58
- // Not typed to prevent collision of local types with end-user ones
59
- exports.default = (function (next) { return __awaiter(void 0, void 0, void 0, function () {
60
- var nextServer, nextHandler;
61
- return __generator(this, function (_a) {
62
- switch (_a.label) {
63
- case 0:
64
- nextServer = next({ dev: dev, hostname: hostname, port: port });
65
- nextHandler = nextServer.getRequestHandler();
66
- return [4 /*yield*/, nextServer.prepare().then(function () { return __awaiter(void 0, void 0, void 0, function () {
67
- var nextNodeServer, opts, purgeUrl, server;
68
- var _a;
69
- return __generator(this, function (_b) {
70
- switch (_b.label) {
71
- case 0: return [4 /*yield*/, ((_a = nextServer['getServer']) === null || _a === void 0 ? void 0 : _a.call(nextServer))];
72
- case 1:
73
- nextNodeServer = _b.sent();
74
- if (!nextNodeServer) {
75
- console.error('Unable to access incremental cache, cache purge endpoint will be disabled');
76
- return [2 /*return*/, nextServer];
77
- }
78
- opts = nextNodeServer['serverOptions'].conf;
79
- purgeUrl = ((opts === null || opts === void 0 ? void 0 : opts.basePath) || '') + exports.PURGE_CACHE_URL;
80
- console.info("Staring cache purge endpoint at ".concat(purgeUrl, "..."));
81
- server = (0, http_1.createServer)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
82
- var parsedUrl, tokenParam, cache, pathParam;
83
- return __generator(this, function (_a) {
84
- switch (_a.label) {
85
- case 0:
86
- parsedUrl = new URL("http://".concat(hostname, ":").concat(port).concat(req.url || ''));
87
- if (!(parsedUrl.pathname !== purgeUrl)) return [3 /*break*/, 2];
88
- return [4 /*yield*/, nextHandler(req, res)];
89
- case 1:
90
- _a.sent();
91
- return [3 /*break*/, 5];
92
- case 2:
93
- if (!dev) return [3 /*break*/, 3];
94
- console.warn('\nCache clearing is not available in DEV mode.\n');
95
- res.setHeader('Content-Type', 'application/json');
96
- res.end(JSON.stringify({ purged: false }));
97
- return [3 /*break*/, 5];
98
- case 3:
99
- tokenParam = parsedUrl.searchParams.get('token');
100
- if (tokenParam !== process.env.ENONIC_API_TOKEN) {
101
- // XP hijacks 401 to show login page, so send 407 instead
102
- res.statusCode = 407;
103
- res.end(JSON.stringify({ message: 'Invalid token' }));
104
- return [2 /*return*/];
105
- }
106
- cache = nextNodeServer.getIncrementalCache({
107
- requestHeaders: Object.assign({}, req.headers),
108
- });
109
- pathParam = parsedUrl.searchParams.get('path') || undefined;
110
- return [4 /*yield*/, (0, cache_1.purgeCache)(cache, pathParam)];
111
- case 4:
112
- _a.sent();
113
- res.setHeader('Content-Type', 'application/json');
114
- res.end(JSON.stringify({ purged: true }));
115
- _a.label = 5;
116
- case 5: return [2 /*return*/];
117
- }
118
- });
119
- }); }).listen(port, hostname, function () {
120
- console.info("Server ready on ".concat(hostname, ":").concat(port));
121
- }).on('error', function (e) {
122
- console.error('Server error:', e);
123
- server.close();
124
- });
125
- return [2 /*return*/, nextServer];
126
- }
127
- });
128
- }); })];
129
- case 1: return [2 /*return*/, _a.sent()];
130
- }
131
- });
132
- }); });
package/utils.d.ts DELETED
@@ -1,114 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /** Import config values from .env, .env.development and .env.production */
4
- import { GetServerSidePropsContext } from 'next';
5
- import { ParsedUrlQuery } from 'node:querystring';
6
- import { IncomingHttpHeaders } from 'http';
7
- export declare const IS_DEV_MODE: boolean;
8
- export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
9
- export declare enum ENV_VARS {
10
- PROJECTS = "ENONIC_PROJECTS",
11
- API = "ENONIC_API",
12
- API_TOKEN = "ENONIC_API_TOKEN"
13
- }
14
- /** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
15
- export declare const APP_NAME: string;
16
- /** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
17
- export declare const APP_NAME_UNDERSCORED: string;
18
- /** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
19
- export declare const APP_NAME_DASHED: string;
20
- export declare const XP_BASE_URL_HEADER = "xpbaseurl";
21
- export declare const RENDER_MODE_HEADER = "content-studio-mode";
22
- export declare const PROJECT_ID_HEADER = "content-studio-project";
23
- export declare const JSESSIONID_HEADER = "jsessionid";
24
- export declare const PORTAL_COMPONENT_ATTRIBUTE = "data-portal-component-type";
25
- export declare const PORTAL_REGION_ATTRIBUTE = "data-portal-region";
26
- export declare const FRAGMENT_CONTENTTYPE_NAME = "portal:fragment";
27
- export declare const FRAGMENT_DEFAULT_REGION_NAME = "fragment";
28
- export declare const PAGE_TEMPLATE_CONTENTTYPE_NAME = "portal:page-template";
29
- export declare const PAGE_TEMPLATE_FOLDER = "portal:template-folder";
30
- export declare const SITE_CONTENTTYPE_NAME = "portal:site";
31
- export declare const LOCALE_HEADER = "locale";
32
- export declare const LOCALES_HEADER = "locales";
33
- export declare const DEFAULT_LOCALE_HEADER = "default-locale";
34
- /** excluded contents:
35
- * - folder
36
- * - shortcuts (redirect can't be used in prerender)
37
- * - media
38
- * - paths with '/_' in them
39
- */
40
- export declare const GET_STATIC_PATHS_QUERY = "query ($count: Int) {\n guillotine {\n queryDsl(\n first: $count,\n sort: {\n field: \"modifiedTime\",\n direction: DESC \n }\n query: {boolean: {mustNot: [\n {in: {field: \"type\", stringValues: [\"base:folder\", \"base:shortcut\"]}}\n {like: {field: \"type\", value: {string: \"media:*\"}}}\n {like: {field: \"_path\", value: {string: \"*/_*\"}}}\n ]}}\n ) {\n _name\n _path\n site {_name}\n }\n }\n}";
41
- export declare enum XP_REQUEST_TYPE {
42
- COMPONENT = "component",
43
- TYPE = "type",
44
- PAGE = "page"
45
- }
46
- export declare enum RENDER_MODE {
47
- INLINE = "inline",
48
- EDIT = "edit",
49
- PREVIEW = "preview",
50
- LIVE = "live",
51
- ADMIN = "admin",
52
- NEXT = "next"
53
- }
54
- export declare enum XP_COMPONENT_TYPE {
55
- PART = "part",
56
- LAYOUT = "layout",
57
- TEXT = "text",
58
- FRAGMENT = "fragment",
59
- PAGE = "page"
60
- }
61
- export interface ServerSideParams extends ParsedUrlQuery {
62
- contentPath?: string[];
63
- mode?: string;
64
- }
65
- export interface PreviewParams {
66
- contentPath: string[];
67
- headers: Record<string, string>;
68
- params: Record<string, string>;
69
- }
70
- export type Context = GetServerSidePropsContext<ServerSideParams, PreviewParams>;
71
- export type LocaleProjectConfig = {
72
- project: string;
73
- site: string;
74
- locale: string;
75
- };
76
- export type LocaleProjectConfigs = {
77
- default: LocaleProjectConfig;
78
- [locale: string]: LocaleProjectConfig;
79
- };
80
- export interface MinimalContext {
81
- req?: {
82
- headers: IncomingHttpHeaders;
83
- };
84
- locale?: string;
85
- defaultLocale?: string;
86
- locales?: string[];
87
- }
88
- export interface ContentPathItem {
89
- params: {
90
- contentPath: string[];
91
- };
92
- locale?: string;
93
- }
94
- export declare const getRenderMode: (context?: MinimalContext) => RENDER_MODE;
95
- export declare function normalizeLocale(locale: string): string | undefined;
96
- export declare function getLocaleProjectConfig(context?: MinimalContext): LocaleProjectConfig;
97
- export declare function getLocaleProjectConfigById(projectId?: string, useDefault?: boolean): LocaleProjectConfig;
98
- export declare function getLocaleProjectConfigs(): LocaleProjectConfigs;
99
- export declare function fixDoubleSlashes(str: string): string;
100
- export declare function getContentApiUrl(context?: MinimalContext): string;
101
- export declare function addJsessionHeaders(headers?: Object, context?: MinimalContext): void;
102
- export declare function addLocaleHeaders(headers?: Object, context?: Context): void;
103
- export declare const getXpBaseUrl: (context?: MinimalContext) => string;
104
- export declare const commonChars: (s1?: string, s2?: string) => string;
105
- export declare const sanitizeGraphqlName: (text: string) => string;
106
- declare const adapterConstants: {
107
- IS_DEV_MODE: boolean;
108
- APP_NAME: string;
109
- APP_NAME_UNDERSCORED: string;
110
- APP_NAME_DASHED: string;
111
- PORTAL_COMPONENT_ATTRIBUTE: string;
112
- PORTAL_REGION_ATTRIBUTE: string;
113
- };
114
- export default adapterConstants;
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import { MetaData, PageComponent } from '../guillotine/getMetaData';
3
- export type BaseComponentProps = {
4
- component: PageComponent;
5
- meta: MetaData;
6
- common?: any;
7
- };
8
- declare const BaseComponent: ({ component, meta, common }: BaseComponentProps) => JSX.Element;
9
- export default BaseComponent;
10
- export declare const MissingComponent: ({ descriptor, type }: {
11
- descriptor?: string;
12
- type: string;
13
- }) => React.JSX.Element;
14
- export declare function shouldShowMissingView(meta: MetaData): boolean;
15
- export declare const ErrorComponent: ({ type, descriptor, reason }: {
16
- type?: string;
17
- descriptor?: string;
18
- reason: string;
19
- }) => React.JSX.Element;
20
- export declare function shouldShowErrorView(meta: MetaData): boolean;
21
- export declare const PlaceholderComponent: ({ type, descriptor }: {
22
- type?: string;
23
- descriptor?: string;
24
- }) => React.JSX.Element;
25
- export declare function shouldShowPlaceholderView(meta: MetaData): boolean;
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { FetchContentResult } from '../guillotine/fetchContent';
3
- declare const BaseContent: (props: FetchContentResult) => React.JSX.Element;
4
- export default BaseContent;
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
- import { LayoutData, MetaData, RegionTree } from '../guillotine/getMetaData';
3
- export interface LayoutProps {
4
- layout: LayoutData;
5
- path: string;
6
- common: any;
7
- meta: MetaData;
8
- }
9
- interface BaseLayoutProps {
10
- component?: LayoutData;
11
- path: string;
12
- regions?: RegionTree;
13
- common?: any;
14
- meta: MetaData;
15
- }
16
- declare const BaseLayout: (props: BaseLayoutProps) => React.JSX.Element;
17
- export default BaseLayout;
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { ComponentRegistry } from '../ComponentRegistry';
3
- import { XP_COMPONENT_TYPE } from '../utils';
4
- import { MissingComponent, shouldShowMissingView } from './BaseComponent';
5
- const BaseLayout = (props) => {
6
- const { component, common, regions, meta, path } = props;
7
- let layoutSelection;
8
- if (component) {
9
- layoutSelection = ComponentRegistry.getLayout(component.descriptor);
10
- }
11
- const SelectedLayoutView = layoutSelection === null || layoutSelection === void 0 ? void 0 : layoutSelection.view;
12
- if (SelectedLayoutView) {
13
- return <SelectedLayoutView layout={{ descriptor: component === null || component === void 0 ? void 0 : component.descriptor, regions: regions || {}, config: component === null || component === void 0 ? void 0 : component.config }} path={path} common={common} meta={meta}/>;
14
- }
15
- else if (component === null || component === void 0 ? void 0 : component.descriptor) {
16
- // empty descriptor usually means uninitialized layout
17
- console.warn(`BaseLayout: can not render layout '${component === null || component === void 0 ? void 0 : component.descriptor}': no next view or catch-all defined`);
18
- if (shouldShowMissingView(meta)) {
19
- return <MissingComponent type={XP_COMPONENT_TYPE.LAYOUT} descriptor={component.descriptor}/>;
20
- }
21
- }
22
- return null;
23
- };
24
- export default BaseLayout;
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { MacroConfig, MacroData, MetaData } from '../guillotine/getMetaData';
3
- export declare const MACRO_DISABLE = "system:disable";
4
- export declare const MACRO_EMBED = "system:embed";
5
- interface BaseMacroProps {
6
- data: MacroData;
7
- meta: MetaData;
8
- renderInEditMode?: boolean;
9
- }
10
- export interface MacroProps {
11
- name: string;
12
- config: MacroConfig;
13
- meta: MetaData;
14
- }
15
- declare const BaseMacro: (props: BaseMacroProps) => React.JSX.Element;
16
- export default BaseMacro;
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { MetaData, PageData } from '../guillotine/getMetaData';
3
- export interface PageProps {
4
- page: PageData;
5
- path: string;
6
- data?: any;
7
- common?: any;
8
- meta: MetaData;
9
- }
10
- export interface BasePageProps {
11
- component?: PageData;
12
- path?: string;
13
- common?: any;
14
- data?: any;
15
- error?: string;
16
- meta: MetaData;
17
- }
18
- declare const BasePage: (props: BasePageProps) => React.JSX.Element;
19
- export default BasePage;
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import { ComponentRegistry } from '../ComponentRegistry';
3
- import { XP_COMPONENT_TYPE } from '../utils';
4
- import { ErrorComponent, MissingComponent, shouldShowErrorView, shouldShowMissingView } from './BaseComponent';
5
- const BasePage = (props) => {
6
- const { component, data, common, error, meta, path } = props;
7
- const desc = component === null || component === void 0 ? void 0 : component.descriptor;
8
- if (error) {
9
- console.warn(`BasePage: '${desc}' error: ${error}`);
10
- if (shouldShowErrorView(meta)) {
11
- return <ErrorComponent reason={error} descriptor={desc} type={XP_COMPONENT_TYPE.PAGE}/>;
12
- }
13
- else {
14
- return null;
15
- }
16
- }
17
- let pageDef;
18
- if (desc) {
19
- pageDef = ComponentRegistry.getPage(desc);
20
- }
21
- const PageView = pageDef === null || pageDef === void 0 ? void 0 : pageDef.view;
22
- if (PageView) {
23
- return <PageView page={component} path={path} data={data} common={common} meta={meta}/>;
24
- }
25
- else if (component === null || component === void 0 ? void 0 : component.descriptor) {
26
- // empty descriptor usually means uninitialized page
27
- console.warn(`BasePage: can not render page '${desc}': no next view or catch-all defined`);
28
- if (shouldShowMissingView(meta)) {
29
- return <MissingComponent type={XP_COMPONENT_TYPE.PAGE} descriptor={component.descriptor}/>;
30
- }
31
- }
32
- return null;
33
- };
34
- export default BasePage;
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { MetaData, PartData } from '../guillotine/getMetaData';
3
- export interface PartProps {
4
- part: PartData;
5
- path: string;
6
- data?: any;
7
- common?: any;
8
- meta: MetaData;
9
- }
10
- interface BasePartProps {
11
- component?: PartData;
12
- path: string;
13
- common?: any;
14
- data?: any;
15
- error?: string;
16
- meta: MetaData;
17
- }
18
- declare const BasePart: (props: BasePartProps) => React.JSX.Element;
19
- export default BasePart;
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { ComponentRegistry } from '../ComponentRegistry';
3
- import { XP_COMPONENT_TYPE } from '../utils';
4
- import { MissingComponent, shouldShowMissingView } from './BaseComponent';
5
- const BasePart = (props) => {
6
- const { component, data, common, meta, path } = props;
7
- let partSelection;
8
- if (component) {
9
- partSelection = ComponentRegistry.getPart(component.descriptor);
10
- }
11
- const SelectedPartView = partSelection === null || partSelection === void 0 ? void 0 : partSelection.view;
12
- if (SelectedPartView) {
13
- return <SelectedPartView part={component} path={path} data={data} common={common} meta={meta}/>;
14
- }
15
- else if (component === null || component === void 0 ? void 0 : component.descriptor) {
16
- // empty descriptor usually means uninitialized part
17
- console.warn(`BasePart: can not render part '${component.descriptor}': no next view or catch-all defined`);
18
- if (shouldShowMissingView(meta)) {
19
- return <MissingComponent type={XP_COMPONENT_TYPE.PART} descriptor={component.descriptor}/>;
20
- }
21
- }
22
- return null;
23
- };
24
- export default BasePart;
package/views/Empty.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const Empty: () => React.JSX.Element;
3
- export default Empty;
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { FragmentData, MetaData, PageData } from '../guillotine/getMetaData';
3
- interface FragmentProps {
4
- page?: PageData;
5
- component?: FragmentData;
6
- common?: any;
7
- meta: MetaData;
8
- }
9
- declare const FragmentView: (props: FragmentProps) => React.JSX.Element;
10
- export default FragmentView;
@@ -1,30 +0,0 @@
1
- import React from 'react';
2
- import BaseComponent, { MissingComponent, shouldShowMissingView } from './BaseComponent';
3
- import { FRAGMENT_DEFAULT_REGION_NAME, XP_COMPONENT_TYPE } from '../utils';
4
- const FragmentView = (props) => {
5
- var _a;
6
- const { component, page } = props;
7
- const comps = [];
8
- if (page) {
9
- // rendering whole page
10
- const regions = page.regions || {};
11
- const regionComps = (_a = regions[FRAGMENT_DEFAULT_REGION_NAME]) === null || _a === void 0 ? void 0 : _a.components;
12
- if (regionComps) {
13
- comps.push(...regionComps);
14
- }
15
- }
16
- else if (component === null || component === void 0 ? void 0 : component.fragment) {
17
- // rendering a part of a page
18
- comps.push(...component.fragment.components);
19
- }
20
- if (!comps.length && shouldShowMissingView(props.meta)) {
21
- return <MissingComponent type={XP_COMPONENT_TYPE.FRAGMENT} descriptor={(page === null || page === void 0 ? void 0 : page.descriptor) || (component === null || component === void 0 ? void 0 : component.id)}/>;
22
- }
23
- else {
24
- const { common, meta } = props;
25
- return (<>
26
- {comps.map((comp, i) => (<BaseComponent key={i} component={comp} common={common} meta={meta}/>))}
27
- </>);
28
- }
29
- };
30
- export default FragmentView;
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { FetchContentResult } from '../guillotine/fetchContent';
3
- declare const _MainView: (props: FetchContentResult) => React.JSX.Element;
4
- export default _MainView;
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import SingleComponent from './SingleComponent';
3
- import BaseContent from './BaseContent';
4
- import { XP_REQUEST_TYPE } from '../utils';
5
- const _MainView = (props) => {
6
- const { meta } = props;
7
- // Single-component render:
8
- if ((meta === null || meta === void 0 ? void 0 : meta.requestType) === XP_REQUEST_TYPE.COMPONENT) {
9
- return <SingleComponent {...props}/>;
10
- }
11
- // meta.requestType="type", and hence content-type based, is standard view for now.
12
- return <BaseContent {...props}/>;
13
- };
14
- export default _MainView;