@webround/editor 0.0.0-stage → 0.3.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 (227) hide show
  1. package/dist/blocks.d.ts +90 -0
  2. package/dist/blocks.js +119 -0
  3. package/dist/bridge.d.ts +96 -0
  4. package/dist/bridge.js +970 -0
  5. package/dist/check/aria.d.ts +19 -0
  6. package/dist/check/aria.js +106 -0
  7. package/dist/check/cli.d.ts +3 -0
  8. package/dist/check/cli.js +30 -0
  9. package/dist/check/css.d.ts +13 -0
  10. package/dist/check/css.js +63 -0
  11. package/dist/check/html.d.ts +8 -0
  12. package/dist/check/html.js +29 -0
  13. package/dist/check/index.d.ts +4 -0
  14. package/dist/check/index.js +5 -0
  15. package/dist/check/links.d.ts +7 -0
  16. package/dist/check/links.js +23 -0
  17. package/dist/check/orphans.d.ts +20 -0
  18. package/dist/check/orphans.js +57 -0
  19. package/dist/check/producer-code.d.ts +53 -0
  20. package/dist/check/producer-code.js +379 -0
  21. package/dist/check/producer-dom.d.ts +21 -0
  22. package/dist/check/producer-dom.js +52 -0
  23. package/dist/check/project.d.ts +20 -0
  24. package/dist/check/project.js +51 -0
  25. package/dist/check/rules.d.ts +7 -0
  26. package/dist/check/rules.js +517 -0
  27. package/dist/check/types.d.ts +160 -0
  28. package/dist/check/types.js +22 -0
  29. package/dist/components/WrAltcha.d.ts +5 -0
  30. package/dist/components/WrAltcha.js +8 -0
  31. package/dist/components/WrButton.d.ts +8 -0
  32. package/dist/components/WrButton.js +34 -0
  33. package/dist/components/WrForm.d.ts +6 -0
  34. package/dist/components/WrForm.js +29 -0
  35. package/dist/components/WrFormPrivacy.d.ts +4 -0
  36. package/dist/components/WrFormPrivacy.js +7 -0
  37. package/dist/components/WrFormSuccess.d.ts +4 -0
  38. package/dist/components/WrFormSuccess.js +12 -0
  39. package/dist/components/WrIframe.d.ts +12 -0
  40. package/dist/components/WrIframe.js +30 -0
  41. package/dist/components/WrImage.d.ts +9 -0
  42. package/dist/components/WrImage.js +28 -0
  43. package/dist/components/WrInput.d.ts +8 -0
  44. package/dist/components/WrInput.js +29 -0
  45. package/dist/components/WrLink.d.ts +10 -0
  46. package/dist/components/WrLink.js +38 -0
  47. package/dist/components/WrNav.d.ts +26 -0
  48. package/dist/components/WrNav.js +30 -0
  49. package/dist/components/WrSection.d.ts +11 -0
  50. package/dist/components/WrSection.js +5 -0
  51. package/dist/components/WrShared.d.ts +12 -0
  52. package/dist/components/WrShared.js +20 -0
  53. package/dist/components/WrText.d.ts +11 -0
  54. package/dist/components/WrText.js +41 -0
  55. package/dist/components/WrVideo.d.ts +9 -0
  56. package/dist/components/WrVideo.js +73 -0
  57. package/dist/components/text-editor/CodeThemeContext.d.ts +8 -0
  58. package/dist/components/text-editor/CodeThemeContext.js +10 -0
  59. package/dist/components/text-editor/ExampleTheme.d.ts +77 -0
  60. package/dist/components/text-editor/ExampleTheme.js +76 -0
  61. package/dist/components/text-editor/ToolbarContext.d.ts +17 -0
  62. package/dist/components/text-editor/ToolbarContext.js +32 -0
  63. package/dist/components/text-editor/WrTextEditor.d.ts +13 -0
  64. package/dist/components/text-editor/WrTextEditor.js +48 -0
  65. package/dist/components/text-editor/common/constants.d.ts +109 -0
  66. package/dist/components/text-editor/common/constants.js +58 -0
  67. package/dist/components/text-editor/common/surface.d.ts +3 -0
  68. package/dist/components/text-editor/common/surface.js +8 -0
  69. package/dist/components/text-editor/common/utils.d.ts +7 -0
  70. package/dist/components/text-editor/common/utils.js +78 -0
  71. package/dist/components/text-editor/hooks/useLexicalCommitOnBlur.d.ts +5 -0
  72. package/dist/components/text-editor/hooks/useLexicalCommitOnBlur.js +41 -0
  73. package/dist/components/text-editor/hooks/useLexicalMarkdown.d.ts +33 -0
  74. package/dist/components/text-editor/hooks/useLexicalMarkdown.js +284 -0
  75. package/dist/components/text-editor/nodes/CodeBlockNode.d.ts +23 -0
  76. package/dist/components/text-editor/nodes/CodeBlockNode.js +138 -0
  77. package/dist/components/text-editor/nodes/HorizontalRuleNode.d.ts +13 -0
  78. package/dist/components/text-editor/nodes/HorizontalRuleNode.js +22 -0
  79. package/dist/components/text-editor/plugins/CodeBlockPlugin.d.ts +2 -0
  80. package/dist/components/text-editor/plugins/CodeBlockPlugin.js +38 -0
  81. package/dist/components/text-editor/plugins/FontPlugin.d.ts +12 -0
  82. package/dist/components/text-editor/plugins/FontPlugin.js +114 -0
  83. package/dist/components/text-editor/plugins/FontSizePlugin.d.ts +7 -0
  84. package/dist/components/text-editor/plugins/FontSizePlugin.js +105 -0
  85. package/dist/components/text-editor/plugins/FontWeightPlugin.d.ts +6 -0
  86. package/dist/components/text-editor/plugins/FontWeightPlugin.js +103 -0
  87. package/dist/components/text-editor/plugins/HTMLTagPlugin.d.ts +7 -0
  88. package/dist/components/text-editor/plugins/HTMLTagPlugin.js +82 -0
  89. package/dist/components/text-editor/plugins/HorizontalRulePlugin.d.ts +2 -0
  90. package/dist/components/text-editor/plugins/HorizontalRulePlugin.js +35 -0
  91. package/dist/components/text-editor/plugins/LineSpacingPlugin.d.ts +7 -0
  92. package/dist/components/text-editor/plugins/LineSpacingPlugin.js +83 -0
  93. package/dist/components/text-editor/plugins/LinkPlugin.d.ts +8 -0
  94. package/dist/components/text-editor/plugins/LinkPlugin.js +183 -0
  95. package/dist/components/text-editor/plugins/ListToolbarPlugin.d.ts +7 -0
  96. package/dist/components/text-editor/plugins/ListToolbarPlugin.js +40 -0
  97. package/dist/components/text-editor/plugins/LoadContentPlugin.d.ts +4 -0
  98. package/dist/components/text-editor/plugins/LoadContentPlugin.js +63 -0
  99. package/dist/components/text-editor/plugins/MarkdownExportPlugin.d.ts +4 -0
  100. package/dist/components/text-editor/plugins/MarkdownExportPlugin.js +17 -0
  101. package/dist/components/text-editor/plugins/MarkdownPastePlugin.d.ts +2 -0
  102. package/dist/components/text-editor/plugins/MarkdownPastePlugin.js +45 -0
  103. package/dist/components/text-editor/plugins/SanitizePastePlugin.d.ts +3 -0
  104. package/dist/components/text-editor/plugins/SanitizePastePlugin.js +40 -0
  105. package/dist/components/text-editor/plugins/TextAlignPlugin.d.ts +7 -0
  106. package/dist/components/text-editor/plugins/TextAlignPlugin.js +65 -0
  107. package/dist/components/text-editor/plugins/TextColorPlugin.d.ts +7 -0
  108. package/dist/components/text-editor/plugins/TextColorPlugin.js +117 -0
  109. package/dist/components/text-editor/plugins/ToolbarPlugin.d.ts +10 -0
  110. package/dist/components/text-editor/plugins/ToolbarPlugin.js +73 -0
  111. package/dist/components/text-editor/theme-colors.d.ts +11 -0
  112. package/dist/components/text-editor/theme-colors.js +28 -0
  113. package/dist/context/WrAppContext.d.ts +35 -0
  114. package/dist/context/WrAppContext.js +113 -0
  115. package/dist/context/WrLayout.d.ts +15 -0
  116. package/dist/context/WrLayout.js +22 -0
  117. package/dist/context/WrPageContext.d.ts +28 -0
  118. package/dist/context/WrPageContext.js +282 -0
  119. package/dist/context/restoreValues.d.ts +2 -0
  120. package/dist/context/restoreValues.js +6 -0
  121. package/dist/contrast.d.ts +45 -0
  122. package/dist/contrast.js +122 -0
  123. package/dist/drop.d.ts +7 -0
  124. package/dist/drop.js +51 -0
  125. package/dist/gaps.d.ts +14 -0
  126. package/dist/gaps.js +50 -0
  127. package/dist/hooks/useWrMessage.d.ts +5 -0
  128. package/dist/hooks/useWrMessage.js +24 -0
  129. package/dist/hooks/useWrSave.d.ts +2 -0
  130. package/dist/hooks/useWrSave.js +11 -0
  131. package/dist/index.css +467 -0
  132. package/dist/index.d.ts +20 -0
  133. package/dist/index.js +20 -0
  134. package/dist/interactive.d.ts +8 -0
  135. package/dist/interactive.js +13 -0
  136. package/dist/measure-rules.d.ts +34 -0
  137. package/dist/measure-rules.js +54 -0
  138. package/dist/measure.d.ts +11 -0
  139. package/dist/measure.js +139 -0
  140. package/dist/messages.d.ts +860 -0
  141. package/dist/messages.js +2 -0
  142. package/dist/nav.d.ts +5 -0
  143. package/dist/nav.js +10 -0
  144. package/dist/operations/animations-store.d.ts +6 -0
  145. package/dist/operations/animations-store.js +63 -0
  146. package/dist/operations/cli.d.ts +3 -0
  147. package/dist/operations/cli.js +52 -0
  148. package/dist/operations/comments-store.d.ts +17 -0
  149. package/dist/operations/comments-store.js +62 -0
  150. package/dist/operations/context.d.ts +12 -0
  151. package/dist/operations/context.js +35 -0
  152. package/dist/operations/define.d.ts +81 -0
  153. package/dist/operations/define.js +86 -0
  154. package/dist/operations/index.d.ts +6 -0
  155. package/dist/operations/index.js +6 -0
  156. package/dist/operations/ops/check.d.ts +5 -0
  157. package/dist/operations/ops/check.js +53 -0
  158. package/dist/operations/ops/comments.d.ts +6 -0
  159. package/dist/operations/ops/comments.js +133 -0
  160. package/dist/operations/ops/content.d.ts +16 -0
  161. package/dist/operations/ops/content.js +73 -0
  162. package/dist/operations/ops/json.d.ts +4 -0
  163. package/dist/operations/ops/json.js +27 -0
  164. package/dist/operations/ops/langs.d.ts +4 -0
  165. package/dist/operations/ops/langs.js +32 -0
  166. package/dist/operations/ops/nodes.d.ts +8 -0
  167. package/dist/operations/ops/nodes.js +270 -0
  168. package/dist/operations/ops/pages.d.ts +8 -0
  169. package/dist/operations/ops/pages.js +154 -0
  170. package/dist/operations/ops/project.d.ts +36 -0
  171. package/dist/operations/ops/project.js +97 -0
  172. package/dist/operations/ops/seo.d.ts +17 -0
  173. package/dist/operations/ops/seo.js +358 -0
  174. package/dist/operations/ops/style.d.ts +76 -0
  175. package/dist/operations/ops/style.js +268 -0
  176. package/dist/operations/ops/stylesets.d.ts +9 -0
  177. package/dist/operations/ops/stylesets.js +145 -0
  178. package/dist/operations/ops/theme.d.ts +6 -0
  179. package/dist/operations/ops/theme.js +304 -0
  180. package/dist/operations/registry.d.ts +8 -0
  181. package/dist/operations/registry.js +19 -0
  182. package/dist/operations/stylesets-store.d.ts +50 -0
  183. package/dist/operations/stylesets-store.js +216 -0
  184. package/dist/registry.d.ts +5 -0
  185. package/dist/registry.js +24 -0
  186. package/dist/save.d.ts +65 -0
  187. package/dist/save.js +86 -0
  188. package/dist/schema.d.ts +69 -0
  189. package/dist/schema.js +110 -0
  190. package/dist/scope.d.ts +41 -0
  191. package/dist/scope.js +44 -0
  192. package/dist/vite-plugins/ast.d.ts +3 -0
  193. package/dist/vite-plugins/ast.js +238 -0
  194. package/dist/vite-plugins/core-swap.d.ts +3 -0
  195. package/dist/vite-plugins/core-swap.js +57 -0
  196. package/dist/vite-plugins/create-page.d.ts +4 -0
  197. package/dist/vite-plugins/create-page.js +59 -0
  198. package/dist/vite-plugins/guard.d.ts +15 -0
  199. package/dist/vite-plugins/guard.js +35 -0
  200. package/dist/vite-plugins/head.d.ts +13 -0
  201. package/dist/vite-plugins/head.js +53 -0
  202. package/dist/vite-plugins/index.d.ts +7 -0
  203. package/dist/vite-plugins/index.js +7 -0
  204. package/dist/vite-plugins/jsx-tree.d.ts +118 -0
  205. package/dist/vite-plugins/jsx-tree.js +686 -0
  206. package/dist/vite-plugins/langs.d.ts +3 -0
  207. package/dist/vite-plugins/langs.js +44 -0
  208. package/dist/vite-plugins/operations.d.ts +10 -0
  209. package/dist/vite-plugins/operations.js +66 -0
  210. package/dist/vite-plugins/pages-api.d.ts +3 -0
  211. package/dist/vite-plugins/pages-api.js +112 -0
  212. package/dist/vite-plugins/pages.d.ts +3 -0
  213. package/dist/vite-plugins/pages.js +64 -0
  214. package/dist/vite-plugins/read.d.ts +3 -0
  215. package/dist/vite-plugins/read.js +45 -0
  216. package/dist/vite-plugins/seo-files.d.ts +8 -0
  217. package/dist/vite-plugins/seo-files.js +42 -0
  218. package/dist/vite-plugins/theme.d.ts +3 -0
  219. package/dist/vite-plugins/theme.js +207 -0
  220. package/dist/vite-plugins/update.d.ts +3 -0
  221. package/dist/vite-plugins/update.js +46 -0
  222. package/dist/vite-plugins/wr-plugins.d.ts +15 -0
  223. package/dist/vite-plugins/wr-plugins.js +34 -0
  224. package/dist/vite-plugins.d.ts +11 -0
  225. package/dist/vite-plugins.js +518 -0
  226. package/package.json +96 -5
  227. package/README.md +0 -3
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function wrCoreSwapPlugin(): Plugin;
3
+ //# sourceMappingURL=core-swap.d.ts.map
@@ -0,0 +1,57 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { createRequire } from 'module';
4
+ const require = createRequire(import.meta.url);
5
+ export function wrCoreSwapPlugin() {
6
+ let editorPkgDir = null;
7
+ let editorEntry = null;
8
+ try {
9
+ editorEntry = require.resolve('@webround/editor');
10
+ // risali da editorEntry finche' non trovi la root del pacchetto (dove sta il suo package.json)
11
+ let dir = path.dirname(editorEntry);
12
+ while (dir !== path.dirname(dir)) {
13
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
14
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
15
+ if (pkg.name === '@webround/editor') {
16
+ editorPkgDir = dir;
17
+ break;
18
+ }
19
+ }
20
+ dir = path.dirname(dir);
21
+ }
22
+ }
23
+ catch (err) {
24
+ editorPkgDir = null;
25
+ editorEntry = null;
26
+ }
27
+ return {
28
+ name: 'wr-core-swap',
29
+ enforce: 'pre',
30
+ // Pacchetto installato in node_modules (non linkato come nel monorepo): va dichiarato subito
31
+ // all'optimizer, altrimenti Vite lo scopre a runtime, riottimizza e ricarica la pagina al primo avvio.
32
+ // Se è linkato (sviluppo dell'SDK) NON va pre-bundlato: le modifiche all'editor devono restare visibili.
33
+ config() {
34
+ const installed = editorPkgDir !== null && editorPkgDir.split(path.sep).includes('node_modules');
35
+ return installed ? { optimizeDeps: { include: ['@webround/editor'] } } : {};
36
+ },
37
+ async resolveId(source, importer) {
38
+ if (!editorEntry || !editorPkgDir)
39
+ return null;
40
+ if (source !== '@webround/core')
41
+ return null;
42
+ if (importer) {
43
+ const normalizedImporter = path.resolve(importer);
44
+ const normalizedEditorDir = path.resolve(editorPkgDir);
45
+ if (normalizedImporter.startsWith(normalizedEditorDir + path.sep)) {
46
+ return null;
47
+ }
48
+ }
49
+ // Si risolve il pacchetto come import "bare" invece di restituire il path assoluto:
50
+ // così, quando @webround/editor è installato in node_modules (non linkato come nel monorepo),
51
+ // Vite lo riconosce come dipendenza e lo pre-bundla insieme alle sue dipendenze (react-router, cookie, …).
52
+ // Con un path assoluto il pacchetto veniva servito "crudo" e le dipendenze CJS si rompevano nel browser.
53
+ return this.resolve('@webround/editor', importer, { skipSelf: true });
54
+ },
55
+ };
56
+ }
57
+ //# sourceMappingURL=core-swap.js.map
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function wrPageScaffold(component: string): string;
3
+ export declare function wrCreatePagePlugin(): Plugin;
4
+ //# sourceMappingURL=create-page.d.ts.map
@@ -0,0 +1,59 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { SRC_ROOT, isSafePageName, isSafeComponentName, wrRoute } from './guard.js';
4
+ export function wrPageScaffold(component) {
5
+ return `import { WrSection } from '@webround/core';
6
+
7
+ export default function ${component}() {
8
+ return <WrSection id="root" />;
9
+ }
10
+ `;
11
+ }
12
+ export function wrCreatePagePlugin() {
13
+ return {
14
+ name: 'wr-create-page',
15
+ configureServer(server) {
16
+ wrRoute(server, '/wr/create-page', (req, res) => {
17
+ if (req.method !== 'POST') {
18
+ res.statusCode = 405;
19
+ res.end();
20
+ return;
21
+ }
22
+ let body = '';
23
+ req.on('data', chunk => body += chunk);
24
+ req.on('end', () => {
25
+ try {
26
+ const { pageName, component, lazy } = JSON.parse(body);
27
+ if (!isSafePageName(pageName) || !isSafeComponentName(component)) {
28
+ res.statusCode = 400;
29
+ res.end(JSON.stringify({ error: 'invalid pageName or component' }));
30
+ return;
31
+ }
32
+ const pagePath = path.join(SRC_ROOT, 'config', 'pages', `${pageName}.json`);
33
+ const componentPath = path.join(SRC_ROOT, 'pages', `${component}.tsx`);
34
+ const routesPath = path.join(SRC_ROOT, 'config', 'routes.json');
35
+ if (fs.existsSync(pagePath) || fs.existsSync(componentPath)) {
36
+ res.statusCode = 409;
37
+ res.end(JSON.stringify({ error: 'page or component already exists' }));
38
+ return;
39
+ }
40
+ fs.mkdirSync(path.dirname(pagePath), { recursive: true });
41
+ fs.writeFileSync(pagePath, JSON.stringify({}, null, 2));
42
+ fs.mkdirSync(path.dirname(componentPath), { recursive: true });
43
+ fs.writeFileSync(componentPath, wrPageScaffold(component));
44
+ const routes = JSON.parse(fs.readFileSync(routesPath, 'utf-8'));
45
+ routes[pageName] = { component, ...(lazy ? { lazy: true } : {}) };
46
+ fs.writeFileSync(routesPath, JSON.stringify(routes, null, 2));
47
+ res.end(JSON.stringify({ ok: true }));
48
+ }
49
+ catch (err) {
50
+ console.error('[wr-create-page] failed:', err);
51
+ res.statusCode = 500;
52
+ res.end(JSON.stringify({ error: err instanceof Error ? err.message : String(err) }));
53
+ }
54
+ });
55
+ });
56
+ }
57
+ };
58
+ }
59
+ //# sourceMappingURL=create-page.js.map
@@ -0,0 +1,15 @@
1
+ import type { Connect, ViteDevServer } from 'vite';
2
+ import type { IncomingMessage, ServerResponse } from 'http';
3
+ /**
4
+ * Accetta SOLO richieste same-origin, cioè fatte dall'app che gira nell'iframe verso sé stessa.
5
+ * Il browser imposta `Sec-Fetch-Site` e non è falsificabile da JS: le chiamate cross-origin
6
+ * (il parent wr-editor, un altro sito, un fetch da fuori) risultano `cross-site`/`same-site` e vengono rifiutate.
7
+ * L'assenza dell'header (client non-browser) è un rifiuto. NB: un client non-browser che forgia gli header
8
+ * non è fermato da qui — quello è compito dell'autenticazione davanti al container.
9
+ */
10
+ export declare function isSameOriginRequest(req: IncomingMessage): boolean;
11
+ type Handler = (req: IncomingMessage, res: ServerResponse, next: Connect.NextFunction) => void;
12
+ /** Registra un middleware /wr/* protetto dal guard same-origin. Da usare al posto di `server.middlewares.use`. */
13
+ export declare function wrRoute(server: ViteDevServer, route: string, handler: Handler): void;
14
+ export {};
15
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Accetta SOLO richieste same-origin, cioè fatte dall'app che gira nell'iframe verso sé stessa.
3
+ * Il browser imposta `Sec-Fetch-Site` e non è falsificabile da JS: le chiamate cross-origin
4
+ * (il parent wr-editor, un altro sito, un fetch da fuori) risultano `cross-site`/`same-site` e vengono rifiutate.
5
+ * L'assenza dell'header (client non-browser) è un rifiuto. NB: un client non-browser che forgia gli header
6
+ * non è fermato da qui — quello è compito dell'autenticazione davanti al container.
7
+ */
8
+ export function isSameOriginRequest(req) {
9
+ if (req.headers['sec-fetch-site'] !== 'same-origin')
10
+ return false;
11
+ const origin = req.headers.origin;
12
+ if (origin) {
13
+ try {
14
+ if (new URL(origin).host !== req.headers.host)
15
+ return false;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
23
+ /** Registra un middleware /wr/* protetto dal guard same-origin. Da usare al posto di `server.middlewares.use`. */
24
+ export function wrRoute(server, route, handler) {
25
+ server.middlewares.use(route, (req, res, next) => {
26
+ if (!isSameOriginRequest(req)) {
27
+ res.statusCode = 403;
28
+ res.setHeader('Content-Type', 'application/json');
29
+ res.end(JSON.stringify({ error: 'forbidden' }));
30
+ return;
31
+ }
32
+ handler(req, res, next);
33
+ });
34
+ }
35
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1,13 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * What belongs in the HTML a visitor (and a crawler) gets BEFORE any script runs, because a crawler looks for it there: today the Google Search Console
4
+ * verification tag. It is put in `index.html` as the page is served in dev and as it is built, from `config/seo.json` (the one place it is written:
5
+ * the SEO panel, `seo-site-set`), so it is in the file that goes to the CDN and in every copy of it. Everything else a page says to search engines is
6
+ * written at runtime by `WrSeoHead`. A tag the project's own `index.html` already has is left alone: it is never written twice.
7
+ *
8
+ * The other thing that must be there before the first paint is the theme of a site that has two (a `.dark` block in `src/theme.css`): the script that sets the `dark` class
9
+ * on <html> from the visitor's choice (or their system's, if the theme says so) is put in the head from `theme.css`, so a dark page never flashes light and nobody has to
10
+ * write the script. A site with one theme gets nothing. A page that already handles the theme itself (it names the storage key) is left alone.
11
+ */
12
+ export declare function wrHeadPlugin(root?: string): Plugin;
13
+ //# sourceMappingURL=head.d.ts.map
@@ -0,0 +1,53 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { wrSearchConsoleCode } from '@webround/core/seo';
4
+ import { WR_BASE_CSS } from '@webround/core/base-css';
5
+ import { WR_THEME_STORAGE_KEY, wrThemeHasDark, wrThemeStartScript, wrThemeStartsFromSystem } from '@webround/core/theme';
6
+ import { SEO_FILE } from '../operations/ops/project.js';
7
+ /**
8
+ * What belongs in the HTML a visitor (and a crawler) gets BEFORE any script runs, because a crawler looks for it there: today the Google Search Console
9
+ * verification tag. It is put in `index.html` as the page is served in dev and as it is built, from `config/seo.json` (the one place it is written:
10
+ * the SEO panel, `seo-site-set`), so it is in the file that goes to the CDN and in every copy of it. Everything else a page says to search engines is
11
+ * written at runtime by `WrSeoHead`. A tag the project's own `index.html` already has is left alone: it is never written twice.
12
+ *
13
+ * The other thing that must be there before the first paint is the theme of a site that has two (a `.dark` block in `src/theme.css`): the script that sets the `dark` class
14
+ * on <html> from the visitor's choice (or their system's, if the theme says so) is put in the head from `theme.css`, so a dark page never flashes light and nobody has to
15
+ * write the script. A site with one theme gets nothing. A page that already handles the theme itself (it names the storage key) is left alone.
16
+ */
17
+ export function wrHeadPlugin(root = process.cwd()) {
18
+ const seoFile = path.join(root, 'src', SEO_FILE);
19
+ const themeFile = path.join(root, 'src', 'theme.css');
20
+ const readTheme = () => { try {
21
+ return fs.readFileSync(themeFile, 'utf-8');
22
+ }
23
+ catch {
24
+ return '';
25
+ } };
26
+ const read = () => {
27
+ try {
28
+ return JSON.parse(fs.readFileSync(seoFile, 'utf-8'));
29
+ }
30
+ catch {
31
+ return {};
32
+ }
33
+ };
34
+ return {
35
+ name: 'wr-head',
36
+ transformIndexHtml: {
37
+ order: 'pre',
38
+ handler(html) {
39
+ const tags = [];
40
+ if (!html.includes('data-wr-base'))
41
+ tags.push({ tag: 'style', attrs: { 'data-wr-base': '' }, children: WR_BASE_CSS, injectTo: 'head-prepend' });
42
+ const code = wrSearchConsoleCode(read().searchConsole);
43
+ if (code && !/name\s*=\s*["']google-site-verification["']/i.test(html))
44
+ tags.push({ tag: 'meta', attrs: { name: 'google-site-verification', content: code }, injectTo: 'head-prepend' });
45
+ const theme = readTheme();
46
+ if (wrThemeHasDark(theme) && !html.includes(WR_THEME_STORAGE_KEY))
47
+ tags.push({ tag: 'script', children: wrThemeStartScript(wrThemeStartsFromSystem(theme)), injectTo: 'head-prepend' });
48
+ return tags;
49
+ },
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=head.js.map
@@ -0,0 +1,7 @@
1
+ export { wrOperationsPlugin } from './operations.js';
2
+ export { wrPageScaffold } from '../operations/ops/pages.js';
3
+ export { wrCoreSwapPlugin } from './core-swap.js';
4
+ export { wrPagesPlugin } from './pages.js';
5
+ export { wrLangsPlugin } from './langs.js';
6
+ export { wrPlugins, type WrPluginsOptions } from './wr-plugins.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export { wrOperationsPlugin } from './operations.js';
2
+ export { wrPageScaffold } from '../operations/ops/pages.js';
3
+ export { wrCoreSwapPlugin } from './core-swap.js';
4
+ export { wrPagesPlugin } from './pages.js';
5
+ export { wrLangsPlugin } from './langs.js';
6
+ export { wrPlugins } from './wr-plugins.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,118 @@
1
+ import { Project, ts, type JsxSelfClosingElement, type JsxOpeningElement, type JsxElement, type JsxFragment, type SourceFile, type Node } from 'ts-morph';
2
+ import { type WrElementKind } from '@webround/core/kinds';
3
+ import type { WrAnchorMode, WrAnchor } from '../messages';
4
+ export type JsxNode = JsxSelfClosingElement | JsxOpeningElement;
5
+ export type FullJsxNode = JsxElement | JsxSelfClosingElement;
6
+ export declare function toFullNode(node: JsxNode): FullJsxNode;
7
+ export declare function loadSourceFile(project: Project, filePath: string): SourceFile | undefined;
8
+ export declare function findNode(project: Project, filePath: string, id: string): {
9
+ node: JsxNode;
10
+ full: FullJsxNode;
11
+ kind: WrElementKind;
12
+ } | null;
13
+ /** Gli id letterali di tutti i componenti Wr* di un file. */
14
+ export declare function collectFileIds(sourceFile: SourceFile): Set<string>;
15
+ export declare function getIndent(node: Node): string;
16
+ /**
17
+ * Importa da `@webround/core` i componenti che servono, se il file non li importa già: da dove non importa. Un file che prende
18
+ * `WrImage` da `@webround/editor` lo tiene così, e non ne ottiene un secondo (un identificatore duplicato non compila).
19
+ */
20
+ export declare function ensureImports(sourceFile: SourceFile, names: string[]): void;
21
+ type PageRoot = JsxElement | JsxFragment | JsxSelfClosingElement;
22
+ /**
23
+ * La radice JSX del componente del file: quello esportato di default (`export default function Home() { return (<>…</>); }`) o, se
24
+ * il file non ha un default, il primo componente esportato per nome che restituisce JSX (`export function Header() { … }`, i file di
25
+ * `src/layout/`).
26
+ */
27
+ export declare function findPageRoot(sourceFile: SourceFile): PageRoot | null;
28
+ export type InsertErrorCode = 'invalid-jsx' | 'id-exists' | 'anchor-not-found' | 'generated-by-code' | 'component-root' | 'invalid-move' | 'not-a-container' | 'invalid-mode' | 'no-page-root' | 'invalid-result';
29
+ export interface InsertError {
30
+ ok: false;
31
+ status: number;
32
+ code: InsertErrorCode;
33
+ error: string;
34
+ }
35
+ export interface InsertRequest {
36
+ /** Markup JSX: uno o più elementi, qualunque tag: l'editor non impone una struttura. I componenti Wr* possono non avere `id`: se manca (o è già preso) lo sceglie il plugin. */
37
+ jsx: string;
38
+ anchor: WrAnchor;
39
+ mode: WrAnchorMode;
40
+ /** Un id già preso viene cambiato (`hero` → `hero-2`) invece di rifiutare l'inserimento. Predefinito: true. */
41
+ uniqueIds?: boolean;
42
+ }
43
+ export interface InsertSuccess {
44
+ ok: true;
45
+ /** Gli id di tutti i componenti Wr* inseriti, nell'ordine del documento, come sono finiti nel file. */
46
+ ids: string[];
47
+ /** Gli id degli elementi di primo livello che sono componenti Wr*: sono quelli che un annulla rimuove. */
48
+ rootIds: string[];
49
+ /** Vero se ogni elemento di primo livello è un componente Wr* (ha un id): solo allora l'inserimento si può annullare per id. */
50
+ undoable: boolean;
51
+ /** `idRichiesto → idFinale`, solo per quelli cambiati. */
52
+ idMap: Record<string, string>;
53
+ /** Il markup così com'è stato inserito (id finali, senza indentazione di contesto): per rifare l'inserimento. */
54
+ jsx: string;
55
+ }
56
+ /** What the parser could not read: the message and the line of each problem (an unclosed tag, a stray token…). */
57
+ export declare function syntaxErrors(sf: ts.SourceFile): {
58
+ message: string;
59
+ line: number;
60
+ }[];
61
+ /** L'unità di indentazione del file: tab, o il rientro più piccolo che vi compare (2 o 4 spazi di solito). */
62
+ export declare function detectIndentUnit(text: string): string;
63
+ /**
64
+ * Rifà i rientri interni del markup con l'unità del file: un blocco scritto a 2 spazi in un file a 4 (o a tab) non deve
65
+ * lasciare un solo livello "storto". Il rientro comune è già tolto (`dedent`); qui si convertono i livelli.
66
+ */
67
+ export declare function reindent(text: string, unit: string): string;
68
+ /**
69
+ * Inserisce markup JSX in un file: valida, sceglie gli id, indenta, aggiunge gli import e scrive. Atomico: o il file è cambiato come
70
+ * richiesto, o non è cambiato.
71
+ */
72
+ export declare function insertJsx(project: Project, filePath: string, request: InsertRequest): InsertSuccess | InsertError;
73
+ export interface DeleteResult {
74
+ removedIds: string[];
75
+ removedJsx: string;
76
+ anchor: WrAnchor | null;
77
+ anchorMode: WrAnchorMode;
78
+ }
79
+ /** Toglie il nodo con questo id (e i suoi discendenti) dal file, ripulendo gli import che non servono più. null se non c'è. */
80
+ /** Non si cancella: nessun cambiamento, e il perché. */
81
+ export interface DeleteRefused {
82
+ refused: true;
83
+ code: 'component-root';
84
+ error: string;
85
+ }
86
+ export declare function deleteJsx(project: Project, filePath: string, id: string, options?: {
87
+ pruneImports?: boolean;
88
+ }): DeleteResult | DeleteRefused | null;
89
+ export interface MoveRequest {
90
+ /** L'elemento da spostare, con tutto ciò che contiene. */
91
+ id: string;
92
+ /** Dove va, rispetto a un altro elemento (o alla radice della pagina), come per un inserimento. */
93
+ anchor: WrAnchor;
94
+ mode: WrAnchorMode;
95
+ }
96
+ export interface MoveSuccess {
97
+ ok: true;
98
+ id: string;
99
+ /** Dov'era: per annullare basta spostarlo di nuovo lì. */
100
+ from: {
101
+ anchor: WrAnchor;
102
+ mode: WrAnchorMode;
103
+ };
104
+ }
105
+ /**
106
+ * Sposta un elemento (e i suoi figli) in un altro punto dello stesso file. Gli id restano quelli: il JSON non si tocca. È una
107
+ * cancellazione e un inserimento dello stesso testo; se l'inserimento non riesce il file torna com'era, e la scrittura finale è una.
108
+ */
109
+ export declare function moveJsx(project: Project, filePath: string, request: MoveRequest): MoveSuccess | InsertError;
110
+ /** The literal value of a JSX attribute: a string, a boolean, a number. `present: false` for anything the code decides (an expression). */
111
+ export declare function readJsxLiteral(node: JsxNode, key: string): {
112
+ present: boolean;
113
+ value?: string | boolean | number;
114
+ };
115
+ /** Writes (or, with null, removes) a literal attribute. */
116
+ export declare function writeJsxLiteral(node: JsxNode, key: string, value: string | boolean | number | null): void;
117
+ export {};
118
+ //# sourceMappingURL=jsx-tree.d.ts.map