reactivated 0.25.0 → 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 (98) hide show
  1. package/{babel.config.d.ts → dist/babel.config.d.ts} +0 -0
  2. package/{babel.config.js → dist/babel.config.js} +0 -0
  3. package/dist/babel.config.js.map +1 -0
  4. package/dist/build.client.d.ts +2 -0
  5. package/{build.client.js → dist/build.client.js} +14 -13
  6. package/dist/build.client.js.map +1 -0
  7. package/dist/build.renderer.d.ts +2 -0
  8. package/{build.renderer.js → dist/build.renderer.js} +21 -14
  9. package/dist/build.renderer.js.map +1 -0
  10. package/{client.d.ts → dist/client.d.ts} +0 -0
  11. package/dist/client.js +19 -0
  12. package/dist/client.js.map +1 -0
  13. package/{components → dist/components}/Form.d.ts +1 -0
  14. package/{components → dist/components}/Form.js +4 -5
  15. package/dist/components/Form.js.map +1 -0
  16. package/{components → dist/components}/Widget.d.ts +0 -0
  17. package/{components → dist/components}/Widget.js +5 -7
  18. package/dist/components/Widget.js.map +1 -0
  19. package/{context.d.ts → dist/context.d.ts} +0 -0
  20. package/dist/context.js +20 -0
  21. package/dist/context.js.map +1 -0
  22. package/{eslintrc.d.ts → dist/eslintrc.d.ts} +0 -0
  23. package/{eslintrc.js → dist/eslintrc.js} +0 -0
  24. package/dist/eslintrc.js.map +1 -0
  25. package/{forms → dist/forms}/index.d.ts +0 -0
  26. package/dist/forms/index.js +377 -0
  27. package/dist/forms/index.js.map +1 -0
  28. package/{forms → dist/forms}/widgets.d.ts +1 -0
  29. package/{forms → dist/forms}/widgets.js +11 -11
  30. package/dist/forms/widgets.js.map +1 -0
  31. package/{generated.d.ts → dist/generated.d.ts} +0 -0
  32. package/{generated.js → dist/generated.js} +0 -0
  33. package/dist/generated.js.map +1 -0
  34. package/dist/generator/constants.d.ts +2 -0
  35. package/{generator → dist/generator}/constants.js +11 -11
  36. package/dist/generator/constants.js.map +1 -0
  37. package/dist/generator.d.ts +2 -0
  38. package/dist/generator.js +155 -0
  39. package/dist/generator.js.map +1 -0
  40. package/{index.d.ts → dist/index.d.ts} +0 -0
  41. package/{index.js → dist/index.js} +0 -0
  42. package/dist/index.js.map +1 -0
  43. package/{models.d.ts → dist/models.d.ts} +0 -0
  44. package/{models.js → dist/models.js} +0 -0
  45. package/dist/models.js.map +1 -0
  46. package/{renderer.d.ts → dist/renderer.d.ts} +0 -0
  47. package/dist/renderer.js +117 -0
  48. package/dist/renderer.js.map +1 -0
  49. package/{types.d.ts → dist/types.d.ts} +0 -0
  50. package/{types.js → dist/types.js} +0 -0
  51. package/dist/types.js.map +1 -0
  52. package/package.json +23 -19
  53. package/scripts/setup_environment.sh +39 -0
  54. package/{README.md → src/README.md} +0 -0
  55. package/src/babel.config.tsx +14 -0
  56. package/src/build.client.tsx +59 -0
  57. package/src/build.renderer.tsx +69 -0
  58. package/src/client.tsx +15 -0
  59. package/src/components/Form.tsx +73 -0
  60. package/src/components/Widget.tsx +202 -0
  61. package/src/context.tsx +28 -0
  62. package/src/eslintrc.tsx +117 -0
  63. package/src/forms/index.tsx +769 -0
  64. package/src/forms/widgets.tsx +85 -0
  65. package/src/generated.tsx +267 -0
  66. package/src/generator/constants.tsx +40 -0
  67. package/src/generator.tsx +181 -0
  68. package/src/index.tsx +4 -0
  69. package/src/models.tsx +12 -0
  70. package/src/renderer.tsx +165 -0
  71. package/src/types.tsx +6 -0
  72. package/tsconfig.json +10 -20
  73. package/babel.config.js.map +0 -1
  74. package/build.client.d.ts +0 -1
  75. package/build.client.js.map +0 -1
  76. package/build.renderer.d.ts +0 -1
  77. package/build.renderer.js.map +0 -1
  78. package/client.js +0 -30
  79. package/client.js.map +0 -1
  80. package/components/Form.js.map +0 -1
  81. package/components/Widget.js.map +0 -1
  82. package/context.js +0 -31
  83. package/context.js.map +0 -1
  84. package/eslintrc.js.map +0 -1
  85. package/forms/index.js +0 -401
  86. package/forms/index.js.map +0 -1
  87. package/forms/widgets.js.map +0 -1
  88. package/generated.js.map +0 -1
  89. package/generator/constants.d.ts +0 -1
  90. package/generator/constants.js.map +0 -1
  91. package/generator.d.ts +0 -1
  92. package/generator.js +0 -109
  93. package/generator.js.map +0 -1
  94. package/index.js.map +0 -1
  95. package/models.js.map +0 -1
  96. package/renderer.js +0 -108
  97. package/renderer.js.map +0 -1
  98. package/types.js.map +0 -1
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ // Must be above the compile import as get-stdin used by
9
+ // json-schema-to-typescript messes up the descriptor even if unused.
10
+ const stdinBuffer = fs_1.default.readFileSync(0);
11
+ const json_schema_to_typescript_1 = require("json-schema-to-typescript");
12
+ const ts_morph_1 = require("ts-morph");
13
+ const schema = JSON.parse(stdinBuffer.toString("utf8"));
14
+ const { urls: possibleEmptyUrls, templates, interfaces, types, values } = schema;
15
+ const urls = Object.assign(Object.assign({}, possibleEmptyUrls), { __reactivated_do_not_use: {
16
+ route: "__reactivated_do_not_use",
17
+ args: {},
18
+ }, __reactivated_do_not_use_args: {
19
+ route: "__reactivated_do_not_use_args",
20
+ args: {
21
+ _: "string",
22
+ },
23
+ } });
24
+ const project = new ts_morph_1.Project();
25
+ const sourceFile = project.createSourceFile("");
26
+ if (Object.keys(urls).length !== 0) {
27
+ sourceFile.addVariableStatement({
28
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
29
+ declarations: [
30
+ {
31
+ name: "urls",
32
+ initializer: JSON.stringify(urls),
33
+ },
34
+ ],
35
+ });
36
+ const urlMap = sourceFile.addInterface({
37
+ name: "URLMap",
38
+ });
39
+ urlMap.setIsExported(true);
40
+ const withArguments = [""];
41
+ const withoutArguments = [""];
42
+ for (const name of Object.keys(urls)) {
43
+ const properties = urls[name].args;
44
+ const normalizedName = name.replace(/[^\w]/g, "_");
45
+ const urlInterface = sourceFile.addInterface({
46
+ name: normalizedName,
47
+ properties: [{ name: "name", type: `'${name}'` }],
48
+ });
49
+ const argsInterface = sourceFile.addInterface({
50
+ name: `${normalizedName}_args`,
51
+ });
52
+ for (const propertyName of Object.keys(properties)) {
53
+ argsInterface.addProperty({
54
+ name: propertyName,
55
+ type: properties[propertyName],
56
+ });
57
+ }
58
+ urlInterface.addProperty({
59
+ name: "args",
60
+ type: `${normalizedName}_args`,
61
+ });
62
+ urlMap.addProperty({
63
+ name: normalizedName,
64
+ type: normalizedName,
65
+ });
66
+ if (Object.keys(properties).length === 0) {
67
+ withoutArguments.push(normalizedName);
68
+ }
69
+ else {
70
+ withArguments.push(normalizedName);
71
+ }
72
+ }
73
+ sourceFile.addTypeAlias({ name: "WithArguments", type: withArguments.join("|") });
74
+ sourceFile.addTypeAlias({
75
+ name: "WithoutArguments",
76
+ type: withoutArguments.join("|"),
77
+ });
78
+ sourceFile.addStatements(`
79
+
80
+ type All = WithArguments|WithoutArguments;
81
+ export function reverse<T extends WithoutArguments['name']>(name: T): string;
82
+ export function reverse<T extends WithArguments['name']>(name: T, args: Extract<WithArguments, {name: T}>['args']): string;
83
+ export function reverse<T extends All['name']>(name: T, args?: Extract<WithArguments, {name: T}>['args']): string {
84
+ let route = urls[name].route;
85
+
86
+ if (args != null) {
87
+ for (const token of Object.keys(args)) {
88
+ route = route.replace(new RegExp('<(.+?:)' + token + '>'), (args as any)[token]);
89
+ }
90
+ }
91
+ return route;
92
+ }`);
93
+ }
94
+ sourceFile.addStatements(`
95
+ import React from "react"
96
+ import createContext from "reactivated/dist/context";
97
+ import * as forms from "reactivated/dist/forms";
98
+ import * as generated from "reactivated/dist/generated";
99
+
100
+ // Note: this needs strict function types to behave correctly with excess properties etc.
101
+ export type Checker<P, U extends (React.FunctionComponent<P> | React.ComponentClass<P>)> = {};
102
+
103
+ export const {Context, Provider, getServerData} = createContext<_Types["Context"]>();
104
+
105
+ export const getTemplate = ({template_name}: {template_name: string}) => {
106
+ // This require needs to be *inside* the function to avoid circular dependencies with esbuild.
107
+ const { default: templates, filenames } = require('../../client/templates/**/*');
108
+ const templatePath = "../../client/templates/" + template_name + ".tsx";
109
+ const possibleTemplate: {default: React.ComponentType<any>} | null = templates.find((t: any, index: number) => filenames[index] === templatePath);
110
+
111
+ if (possibleTemplate == null) {
112
+ throw new Error("Template " + template_name + ".tsx not found");
113
+ }
114
+ return possibleTemplate.default;
115
+ }
116
+
117
+ export const CSRFToken = forms.createCSRFToken(Context);
118
+
119
+ export const {createRenderer, Iterator} = forms.bindWidgetType<_Types["globals"]["Widget"]>();
120
+ export type FieldHandler = forms.FieldHandler<_Types["globals"]["Widget"]>;
121
+
122
+ export const {Form, FormSet, Widget, useForm, useFormSet, ManagementForm} = forms;
123
+ `);
124
+ // tslint:disable-next-line
125
+ (0, json_schema_to_typescript_1.compile)(types, "_Types").then((ts) => {
126
+ process.stdout.write("/* eslint-disable */\n");
127
+ process.stdout.write(ts);
128
+ for (const name of Object.keys(templates)) {
129
+ const propsName = templates[name];
130
+ sourceFile.addStatements(`
131
+
132
+ import ${name}Implementation from "@client/templates/${name}"
133
+ export type ${name}Check = Checker<_Types["${propsName}"], typeof ${name}Implementation>;
134
+
135
+ export namespace templates {
136
+ export type ${name} = _Types["${propsName}"];
137
+ }
138
+
139
+
140
+ `);
141
+ }
142
+ for (const name of Object.keys(interfaces)) {
143
+ const propsName = interfaces[name];
144
+ sourceFile.addStatements(`
145
+
146
+ export namespace interfaces {
147
+ export type ${name} = _Types["${propsName}"];
148
+ }
149
+
150
+
151
+ `);
152
+ }
153
+ process.stdout.write(sourceFile.getText());
154
+ });
155
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.tsx"],"names":[],"mappings":";;;;;;AAEA,4CAAoB;AAGpB,wDAAwD;AACxD,qEAAqE;AACrE,MAAM,WAAW,GAAG,YAAE,CAA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CAAC,GAAG,CAAC;KACnC,CAAC,CAAC;IACH,UAAU,CAAC,aAAa,CAAC;;;;;;;;;;;;;;MAcvB,CAAC,CAAC;CACP;AAED,UAAU,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BxB,CAAC,CAAC;AAEH,2BAA2B;AAC3B,IAAA,mCAAO,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;IACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEzB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QACvC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAClC,UAAU,CAAC,aAAa,CAAC;;SAExB,IAAI,0CAA0C,IAAI;cAC7C,IAAI,2BAA2B,SAAS,cAAc,IAAI;;;kBAGtD,IAAI,cAAc,SAAS;;;;SAIpC,CAAC,CAAC;KACN;IAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QACxC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,UAAU,CAAC,aAAa,CAAC;;;kBAGf,IAAI,cAAc,SAAS;;;;SAIpC,CAAC,CAAC;KACN;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC"}
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,oDAAkC;AAClC,sDAAoC"}
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.tsx"],"names":[],"mappings":""}
File without changes
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a, _b;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.server = exports.SOCKET_PATH = exports.serverRender = exports.simpleRender = exports.render = exports.renderPage = exports.BODY_SIZE_LIMIT = void 0;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const http_1 = __importDefault(require("http"));
10
+ const react_1 = __importDefault(require("react"));
11
+ const server_1 = __importDefault(require("react-dom/server"));
12
+ const react_helmet_async_1 = require("react-helmet-async");
13
+ // Useful when running e2e tests or the like, where the output is not
14
+ // co-located with the running process.
15
+ const REACTIVATED_CLIENT_ROOT = (_a = process.env.REACTIVATED_CLIENT_ROOT) !== null && _a !== void 0 ? _a : `../client`;
16
+ // TODO: WHAT DOES THIS NEED TO BE? Even 100k was super fragile and a 10 choice field broke it.
17
+ exports.BODY_SIZE_LIMIT = "100000000k";
18
+ const renderPage = ({ html, helmet, context, props, }) => `
19
+ <!DOCTYPE html>
20
+ <html ${helmet.htmlAttributes.toString()}>
21
+ <head>
22
+ <script>
23
+ // These go first because scripts below need them.
24
+ // WARNING: See the following for security issues around embedding JSON in HTML:
25
+ // http://redux.js.org/recipes/ServerRendering.html#security-considerations
26
+ window.__PRELOADED_PROPS__ = ${JSON.stringify(props).replace(/</g, "\\u003c")}
27
+ window.__PRELOADED_CONTEXT__ = ${JSON.stringify(context).replace(/</g, "\\u003c")}
28
+ </script>
29
+
30
+ ${helmet.base.toString()}
31
+ ${helmet.link.toString()}
32
+ ${helmet.meta.toString()}
33
+ ${helmet.noscript.toString()}
34
+ ${helmet.script.toString()}
35
+ ${helmet.style.toString()}
36
+ ${helmet.title.toString()}
37
+ </head>
38
+ <body ${helmet.bodyAttributes.toString()}>
39
+ <div id="root">${html}</div>
40
+ </body>
41
+ </html>
42
+ `;
43
+ exports.renderPage = renderPage;
44
+ const PATHS = ["/", "/form/"];
45
+ const render = ({ context, props }) => {
46
+ const { Provider, getTemplate } = require("_reactivated/index.tsx");
47
+ try {
48
+ const Template = getTemplate(context);
49
+ const helmetContext = {};
50
+ const rendered = server_1.default.renderToString(react_1.default.createElement(react_helmet_async_1.HelmetProvider, { context: helmetContext },
51
+ react_1.default.createElement(Provider, { value: context },
52
+ react_1.default.createElement(Template, Object.assign({}, props)))));
53
+ const { helmet } = helmetContext;
54
+ return {
55
+ status: "success",
56
+ rendered: (0, exports.renderPage)({
57
+ html: rendered,
58
+ helmet,
59
+ props,
60
+ context,
61
+ }),
62
+ };
63
+ }
64
+ catch (error) {
65
+ return { status: "error", error };
66
+ }
67
+ };
68
+ exports.render = render;
69
+ const simpleRender = () => {
70
+ const input = fs_1.default.readFileSync(0);
71
+ const { context, props } = JSON.parse(input.toString("utf8"));
72
+ process.stdout.write(JSON.stringify((0, exports.render)({ context, props })));
73
+ };
74
+ exports.simpleRender = simpleRender;
75
+ const serverRender = (body) => {
76
+ const { context, props } = JSON.parse(body.toString("utf8"));
77
+ return (0, exports.render)({ context, props });
78
+ };
79
+ exports.serverRender = serverRender;
80
+ const OK_RESPONSE = 200;
81
+ const ERROR_REPONSE = 500;
82
+ // Relative path to keep it under 100 characters.
83
+ // See: https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars
84
+ exports.SOCKET_PATH = (_b = process.env.REACTIVATED_SOCKET) !== null && _b !== void 0 ? _b : `node_modules/_reactivated/reactivated.sock`;
85
+ exports.server = http_1.default.createServer((req, res) => {
86
+ let body = Buffer.from("");
87
+ req.on("data", (chunk) => {
88
+ body = Buffer.concat([body, chunk]);
89
+ });
90
+ req.on("end", () => {
91
+ const result = (0, exports.serverRender)(body);
92
+ if (result.status === "success") {
93
+ res.writeHead(OK_RESPONSE, { "Content-Type": "text/html; charset=utf-8" });
94
+ res.end(result.rendered);
95
+ }
96
+ else {
97
+ res.writeHead(ERROR_REPONSE, { "Content-Type": "application/json" });
98
+ res.end(JSON.stringify(result.error, Object.getOwnPropertyNames(result.error)));
99
+ }
100
+ });
101
+ });
102
+ if (fs_1.default.existsSync(exports.SOCKET_PATH)) {
103
+ fs_1.default.unlinkSync(exports.SOCKET_PATH);
104
+ }
105
+ exports.server.listen(exports.SOCKET_PATH, () => {
106
+ const address = exports.server.address();
107
+ if (address == null) {
108
+ throw new Error();
109
+ }
110
+ else if (typeof address === "string") {
111
+ process.stdout.write(`RENDERER:${address}:LISTENING`);
112
+ }
113
+ else {
114
+ process.stdout.write(`RENDERER:${address.port.toString()}:LISTENING`);
115
+ }
116
+ });
117
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.tsx"],"names":[],"mappings":";;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAGxB,kDAA0B;AAC1B,8DAA8C;AAC9C,2DAK4B;AAE5B,qEAAqE;AACrE,uCAAuC;AACvC,MAAM,uBAAuB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,uBAAuB,mCAAI,WAAW,CAAC;AAInF,+FAA+F;AAClF,QAAA,eAAe,GAAG,YAAY,CAAC;AAErC,MAAM,UAAU,GAAG,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,KAAK,GAMR,EAAE,EAAE,CACD;;QAEI,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE;;;;;;2CAMG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CACxD,IAAI,EACJ,SAAS,CACZ;6CACgC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAC5D,IAAI,EACJ,SAAS,CACZ;;;UAGH,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;UACtB,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;UACtB,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;UACtB,MAAM,CAAC,Q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AM,CAAC,MAAM,KAAK,SAAS,EAAE;YAC7B,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,EAAC,cAAc,EAAE,0BAA0B,EAAC,CAAC,CAAC;YACzE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SAC5B;aAAM;YACH,GAAG,CAAC,SAAS,CAAC,aAAa,EAAE,EAAC,cAAc,EAAE,kBAAkB,EAAC,CAAC,CAAC;YACnE,GAAG,CAAC,GAAG,CACH,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CACzE,CAAC;SACL;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,IAAI,YAAE,CAAC,UAAU,CAAC,mBAAW,CAAC,EAAE;IAC5B,YAAE,CAAC,UAAU,CAAC,mBAAW,CAAC,CAAC;CAC9B;AAED,cAAM,CAAC,MAAM,CAAC,mBAAW,EAAE,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,cAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,IAAI,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,EAAE,CAAC;KACrB;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,YAAY,CAAC,CAAC;KACzD;SAAM;QACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;KACzE;AACL,CAAC,CAAC,CAAC"}
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.tsx"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,9 +1,22 @@
1
1
  {
2
2
  "name": "reactivated",
3
- "version": "0.25.0",
4
- "repository": "github:silviogutierrez/reactivated",
5
- "license": "MIT",
3
+ "version": "1.0.0",
6
4
  "description": "",
5
+ "main": "dist/index2.js",
6
+ "typings": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "tsc"
10
+ },
11
+ "author": "",
12
+ "bin": {
13
+ "setup_environment.sh": "./scripts/setup_environment.sh",
14
+ "generate_client_assets": "./dist/generator.js",
15
+ "generate_client_constants": "./dist/generator/constants.js",
16
+ "build.client.js": "./dist/build.client.js",
17
+ "build.renderer.js": "./dist/build.renderer.js"
18
+ },
19
+ "license": "ISC",
7
20
  "dependencies": {
8
21
  "@babel/core": "^7.16.7",
9
22
  "@babel/preset-react": "^7.17.12",
@@ -13,8 +26,6 @@
13
26
  "@linaria/esbuild": "3.0.0-beta.21",
14
27
  "@linaria/react": "3.0.0-beta.21",
15
28
  "@linaria/shaker": "3.0.0-beta.21",
16
- "@types/react": "^18.0.12",
17
- "@types/react-dom": "^18.0.5",
18
29
  "@typescript-eslint/eslint-plugin": "^5.30.6",
19
30
  "@typescript-eslint/parser": "^5.30.6",
20
31
  "@vanilla-extract/css": "^1.6.8",
@@ -29,22 +40,15 @@
29
40
  "eslint-plugin-react-hooks": "^4.6.0",
30
41
  "immer": "^9.0.7",
31
42
  "json-schema-to-typescript": "^10.1.5",
32
- "react": "^18.1.0",
33
- "react-dom": "^18.1.0",
34
- "react-helmet-async": "^1.3.0",
35
43
  "terser": "^5.10.0",
36
44
  "ts-morph": "^13.0.2",
37
45
  "typescript": "^4.7.4"
38
46
  },
39
- "devDependencies": {},
40
- "main": "lib/index.js",
41
- "scripts": {
42
- "@ comment 1": "tsc && find . \\( -name '*.ts' -o -name '*.tsx' \\) -not -path './node_modules/*' -exec rm {} \\;",
43
- "@ comment 2": "See .npmignore for how we prevent .ts and .tsx files from being uploaded. Above is another way.",
44
- "prepublishOnly": "tsc",
45
- "postpublish": "git clean -fd",
46
- "build": "tsc --outDir dist",
47
- "start": "rm -rf ../../sample/node_modules/reactivated && tsc -w --outDir ../../sample/node_modules/reactivated"
48
- },
49
- "author": ""
47
+ "peerDependencies": {
48
+ "@types/react": "^18.0.12",
49
+ "@types/react-dom": "^18.0.5",
50
+ "react": "^18.1.0",
51
+ "react-dom": "^18.1.0",
52
+ "react-helmet-async": "^1.3.0"
53
+ }
50
54
  }
@@ -0,0 +1,39 @@
1
+ # This script is meant to be sourced, not run in a subshell.
2
+ SOURCE_DATE_EPOCH=$(date +%s)
3
+ export SOURCE_DATE_EPOCH
4
+ VIRTUAL_ENV=$PWD/.venv
5
+ PATH=$VIRTUAL_ENV/bin:$PATH
6
+ POSTGRESQL_DATA="$VIRTUAL_ENV/postgresql"
7
+ POSTGRESQL_LOGS="$VIRTUAL_ENV/postgresql/logs.txt"
8
+ TMP_ENV="$TMPDIR/reactivated/$(echo "$VIRTUAL_ENV" | md5sum | awk '{print $1}')"
9
+
10
+ export PGPORT=1
11
+ export PGDATABASE="database"
12
+ export PGHOST=$TMP_ENV
13
+ EXTERNAL_PID="$TMP_ENV/postmaster.pid"
14
+
15
+ if [ ! -d "$VIRTUAL_ENV" ]; then
16
+ if [ -f "$EXTERNAL_PID" ]; then
17
+ kill -9 "$(cat "$EXTERNAL_PID")"
18
+ rm "$EXTERNAL_PID"
19
+ fi
20
+
21
+ NEED_DATABASE=true
22
+ npm install
23
+ rm -rf "$TMP_ENV"
24
+ virtualenv "$VIRTUAL_ENV"
25
+ mkdir "$VIRTUAL_ENV/static"
26
+ initdb "$POSTGRESQL_DATA"
27
+ pip install -r requirements.txt
28
+
29
+ fi
30
+
31
+ mkdir -p "$TMP_ENV"
32
+
33
+ if [ ! -f "$EXTERNAL_PID" ]; then
34
+ pg_ctl -o "-p 1 -k \"$PGHOST\" -c listen_addresses=\"\" -c external_pid_file=\"$EXTERNAL_PID\"" -D "$POSTGRESQL_DATA" -l "$POSTGRESQL_LOGS" start &>/dev/null
35
+ fi
36
+
37
+ if [ "$NEED_DATABASE" == true ]; then
38
+ createdb $PGDATABASE &>/dev/null
39
+ fi
File without changes
@@ -0,0 +1,14 @@
1
+ export default {
2
+ presets: [["@babel/preset-typescript", {allowNamespaces: true}]],
3
+ plugins: [
4
+ [
5
+ "module-resolver",
6
+ {
7
+ root: ["./"],
8
+ alias: {
9
+ "@client": "./client",
10
+ },
11
+ },
12
+ ],
13
+ ],
14
+ };
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ import linaria from "@linaria/esbuild";
4
+ import {vanillaExtractPlugin} from "@vanilla-extract/esbuild-plugin";
5
+ import * as esbuild from "esbuild";
6
+ import ImportGlobPlugin from "esbuild-plugin-import-glob";
7
+
8
+ const entryNames = process.argv.slice(2);
9
+
10
+ const entryPoints = Object.fromEntries(
11
+ entryNames.map((entry) => [entry, `./client/${entry}.tsx`]),
12
+ );
13
+
14
+ const production = process.env.NODE_ENV === "production";
15
+ const identifiers = production ? "short" : "debug";
16
+
17
+ const env = {
18
+ NODE_ENV: production ? "production" : "development",
19
+ BUILD_VERSION: process.env.BUILD_VERSION,
20
+ TAG_VERSION: process.env.TAG_VERSION,
21
+ };
22
+
23
+ esbuild
24
+ .build({
25
+ entryPoints,
26
+ bundle: true,
27
+ // We use terser to minify because esbuild breaks safari sourcemaps.
28
+ // It's likely a Safari bug, but terser seems to work for some reason.
29
+ minify: false,
30
+ // Related to sourcemaps as well in Safari.
31
+ legalComments: "none",
32
+ platform: "browser",
33
+ outdir: "./static/dist",
34
+ sourcemap: true,
35
+ target: "es2018",
36
+ preserveSymlinks: true,
37
+ watch: production === false,
38
+ external: ["moment", "@client/generated/images"],
39
+ define: {
40
+ // You need both. The one from the stringified JSON is not picked
41
+ // up during the build process.
42
+ "process.env.NODE_ENV": production ? '"production"' : '"development"',
43
+ process: JSON.stringify({env}),
44
+
45
+ // Redux persist needs this.
46
+ global: "{}",
47
+ },
48
+ plugins: [
49
+ ImportGlobPlugin(),
50
+ // We manually pass in identifiers because the client is not
51
+ // minified by esbuild but the renderer is, so class names could
52
+ // differ.
53
+ // Instead of set it manually instead of relying on minification
54
+ // settings.
55
+ vanillaExtractPlugin({identifiers}),
56
+ linaria({sourceMap: true, esbuildOptions: {sourcemap: "inline"}}),
57
+ ],
58
+ })
59
+ .catch(() => process.exit(1));
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+
3
+ import linaria from "@linaria/esbuild";
4
+ import {vanillaExtractPlugin} from "@vanilla-extract/esbuild-plugin";
5
+ import * as esbuild from "esbuild";
6
+ import ImportGlobPlugin from "esbuild-plugin-import-glob";
7
+ import http from "http";
8
+ import fs = require("fs");
9
+
10
+ let server: http.Server | null = null;
11
+
12
+ const CACHE_KEY = `${process.cwd()}/node_modules/_reactivated/renderer.js`;
13
+ const production = process.env.NODE_ENV === "production";
14
+ const identifiers = production ? "short" : "debug";
15
+
16
+ esbuild
17
+ .build({
18
+ stdin: {
19
+ contents: `
20
+ export {server} from "reactivated/dist/renderer";
21
+ `,
22
+ resolveDir: process.cwd(),
23
+ loader: "ts",
24
+ },
25
+ minify: production,
26
+ bundle: true,
27
+ platform: "node",
28
+ outfile: "./node_modules/_reactivated/renderer.js",
29
+ sourcemap: true,
30
+ target: "es2018",
31
+ preserveSymlinks: true,
32
+ // Needed so _reactivated is included in renderer.tsx regardless
33
+ // of the location of reactivated being in the cwd node_modules or
34
+ // above as in monorepos.
35
+ nodePaths: [`${process.cwd()}/node_modules`],
36
+ watch:
37
+ production === true
38
+ ? false
39
+ : {
40
+ onRebuild: () => {
41
+ restartServer();
42
+ },
43
+ },
44
+ plugins: [
45
+ ImportGlobPlugin(),
46
+ // We manually pass in identifiers because the client is not
47
+ // minified by esbuild but the renderer is, so class names could
48
+ // differ.
49
+ // Instead of set it manually instead of relying on minification
50
+ // settings.
51
+ vanillaExtractPlugin({identifiers}),
52
+ linaria({sourceMap: true}),
53
+ ],
54
+ })
55
+ .then(() => {
56
+ if (production === false) {
57
+ restartServer();
58
+ }
59
+ })
60
+ .catch(() => process.exit(1));
61
+
62
+ const restartServer = () => {
63
+ if (server != null) {
64
+ server.close();
65
+ }
66
+
67
+ delete require.cache[CACHE_KEY];
68
+ server = require(CACHE_KEY).server;
69
+ };
package/src/client.tsx ADDED
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import {hydrate} from "react-dom";
3
+
4
+ const props = (window as any).__PRELOADED_STATE__;
5
+
6
+ if ((module as any).hot) {
7
+ (module as any).hot.accept();
8
+ }
9
+
10
+ // tslint:disable-next-line
11
+ const Template = require("client/templates/" + props.template_name + ".tsx").default;
12
+
13
+ export const bootstrap = () => {
14
+ hydrate(<Template {...props} />, document.getElementById("root"));
15
+ };
@@ -0,0 +1,73 @@
1
+ import React from "react";
2
+
3
+ import {getValueForSelect, WidgetType} from "./Widget";
4
+
5
+ interface FieldLike {
6
+ name: string;
7
+ widget: WidgetType;
8
+ label: string;
9
+ help_text: string;
10
+ }
11
+
12
+ /*
13
+ interface Form {
14
+ fields: {
15
+ [name: string]: FieldLike;
16
+ },
17
+ errors: {
18
+ [P in keyof this['fields']]: string[]|null;
19
+ }
20
+ iterator: Array<keyof this['fields']>;
21
+ }
22
+ */
23
+
24
+ export interface FieldMap {
25
+ [name: string]: FieldLike;
26
+ }
27
+
28
+ export interface FormLike<T extends FieldMap> {
29
+ name: string;
30
+ fields: T;
31
+ errors: {[P in keyof T]?: string[]} | null;
32
+ iterator: Array<keyof T>;
33
+ prefix: string;
34
+ }
35
+
36
+ export interface FormSetLike<T extends FieldMap> {
37
+ initial_form_count: number;
38
+ total_form_count: number;
39
+ max_num: number;
40
+ min_num: number;
41
+ can_delete: boolean;
42
+ can_order: boolean;
43
+ non_form_errors: string[];
44
+
45
+ // Technically we don't need management form.
46
+ // Since we have ManagementForm as a component that uses initial and total.
47
+ management_form: unknown;
48
+ prefix: string;
49
+
50
+ forms: Array<FormLike<T>>;
51
+ empty_form: FormLike<T>;
52
+ }
53
+
54
+ export const ManagementForm = <T extends FieldMap>({
55
+ formSet,
56
+ }: {
57
+ formSet: FormSetLike<T>;
58
+ }) => {
59
+ return (
60
+ <>
61
+ <input
62
+ type="hidden"
63
+ name={`${formSet.prefix}-INITIAL_FORMS`}
64
+ value={formSet.initial_form_count}
65
+ />
66
+ <input
67
+ type="hidden"
68
+ name={`${formSet.prefix}-TOTAL_FORMS`}
69
+ value={formSet.total_form_count}
70
+ />
71
+ </>
72
+ );
73
+ };