lightview 1.8.1-b → 2.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 (224) hide show
  1. package/.agent/workflows/daisyui-component-migration.md +155 -0
  2. package/.codacy/cli.sh +149 -0
  3. package/.codacy/codacy.yaml +15 -0
  4. package/.github/instructions/codacy.instructions.md +72 -0
  5. package/.wranglerignore +21 -0
  6. package/README.md +1331 -21
  7. package/_headers +4 -0
  8. package/build.js +70 -0
  9. package/components/actions/button.js +151 -0
  10. package/components/actions/dropdown.js +120 -0
  11. package/components/actions/modal.js +146 -0
  12. package/components/actions/swap.js +118 -0
  13. package/components/daisyui.js +288 -0
  14. package/components/data-display/accordion.js +128 -0
  15. package/components/data-display/alert.js +112 -0
  16. package/components/data-display/avatar.js +170 -0
  17. package/components/data-display/badge.js +82 -0
  18. package/components/data-display/card.js +151 -0
  19. package/components/data-display/carousel.js +94 -0
  20. package/components/data-display/chart.js +220 -0
  21. package/components/data-display/chat.js +128 -0
  22. package/components/data-display/collapse.js +103 -0
  23. package/components/data-display/countdown.js +69 -0
  24. package/components/data-display/diff.js +111 -0
  25. package/components/data-display/kbd.js +65 -0
  26. package/components/data-display/loading.js +75 -0
  27. package/components/data-display/progress.js +79 -0
  28. package/components/data-display/radial-progress.js +88 -0
  29. package/components/data-display/skeleton.js +66 -0
  30. package/components/data-display/stats.js +159 -0
  31. package/components/data-display/table.js +146 -0
  32. package/components/data-display/timeline.js +146 -0
  33. package/components/data-display/toast.js +72 -0
  34. package/components/data-display/tooltip.js +74 -0
  35. package/components/data-input/checkbox.js +253 -0
  36. package/components/data-input/file-input.js +224 -0
  37. package/components/data-input/input.js +264 -0
  38. package/components/data-input/radio.js +338 -0
  39. package/components/data-input/range.js +204 -0
  40. package/components/data-input/rating.js +219 -0
  41. package/components/data-input/select.js +287 -0
  42. package/components/data-input/textarea.js +287 -0
  43. package/components/data-input/toggle.js +201 -0
  44. package/components/index.js +137 -0
  45. package/components/layout/divider.js +72 -0
  46. package/components/layout/drawer.js +142 -0
  47. package/components/layout/footer.js +100 -0
  48. package/components/layout/hero.js +109 -0
  49. package/components/layout/indicator.js +90 -0
  50. package/components/layout/join.js +78 -0
  51. package/components/layout/navbar.js +110 -0
  52. package/components/navigation/breadcrumbs.js +91 -0
  53. package/components/navigation/dock.js +103 -0
  54. package/components/navigation/menu.js +126 -0
  55. package/components/navigation/pagination.js +105 -0
  56. package/components/navigation/steps.js +89 -0
  57. package/components/navigation/tabs.css +177 -0
  58. package/components/navigation/tabs.js +123 -0
  59. package/components/theme/theme-switch.css +65 -0
  60. package/components/theme/theme-switch.js +177 -0
  61. package/docs/about.html +164 -0
  62. package/docs/api/computed.html +184 -0
  63. package/docs/api/effects.html +173 -0
  64. package/docs/api/elements.html +180 -0
  65. package/docs/api/enhance.html +225 -0
  66. package/docs/api/hypermedia.html +165 -0
  67. package/docs/api/index.html +178 -0
  68. package/docs/api/nav.html +18 -0
  69. package/docs/api/signals.html +136 -0
  70. package/docs/api/state.html +217 -0
  71. package/docs/assets/images/logo-favicon.svg +42 -0
  72. package/docs/assets/images/logo-static.svg +40 -0
  73. package/docs/assets/images/logo.svg +66 -0
  74. package/docs/assets/js/examplify.js +395 -0
  75. package/docs/assets/styles/site.css +1102 -0
  76. package/docs/assets/styles/themes.css +236 -0
  77. package/docs/components/accordion.html +439 -0
  78. package/docs/components/alert.html +528 -0
  79. package/docs/components/avatar.html +586 -0
  80. package/docs/components/badge.html +531 -0
  81. package/docs/components/breadcrumbs.html +278 -0
  82. package/docs/components/button.html +579 -0
  83. package/docs/components/card.html +561 -0
  84. package/docs/components/carousel.html +286 -0
  85. package/docs/components/chart-area.html +702 -0
  86. package/docs/components/chart-bar.html +782 -0
  87. package/docs/components/chart-column.html +735 -0
  88. package/docs/components/chart-line.html +794 -0
  89. package/docs/components/chart-pie.html +823 -0
  90. package/docs/components/chart.html +612 -0
  91. package/docs/components/chat.html +547 -0
  92. package/docs/components/checkbox.html +641 -0
  93. package/docs/components/collapse.html +536 -0
  94. package/docs/components/component-nav.html +53 -0
  95. package/docs/components/countdown.html +470 -0
  96. package/docs/components/diff.html +245 -0
  97. package/docs/components/divider.html +240 -0
  98. package/docs/components/dock.html +277 -0
  99. package/docs/components/drawer.html +515 -0
  100. package/docs/components/dropdown.html +479 -0
  101. package/docs/components/file-input.html +591 -0
  102. package/docs/components/footer.html +301 -0
  103. package/docs/components/gallery.html +504 -0
  104. package/docs/components/hero.html +264 -0
  105. package/docs/components/index.css +840 -0
  106. package/docs/components/index.html +735 -0
  107. package/docs/components/indicator.html +342 -0
  108. package/docs/components/input.html +644 -0
  109. package/docs/components/join.html +285 -0
  110. package/docs/components/kbd.html +322 -0
  111. package/docs/components/loading.html +521 -0
  112. package/docs/components/menu.html +461 -0
  113. package/docs/components/modal.html +639 -0
  114. package/docs/components/navbar.html +321 -0
  115. package/docs/components/pagination.html +279 -0
  116. package/docs/components/progress.html +514 -0
  117. package/docs/components/radial-progress.html +434 -0
  118. package/docs/components/radio.html +655 -0
  119. package/docs/components/range.html +611 -0
  120. package/docs/components/rating.html +642 -0
  121. package/docs/components/select.html +696 -0
  122. package/docs/components/sidebar-setup.js +93 -0
  123. package/docs/components/skeleton.html +447 -0
  124. package/docs/components/spinner.html +68 -0
  125. package/docs/components/stats.html +486 -0
  126. package/docs/components/steps.html +356 -0
  127. package/docs/components/swap.html +517 -0
  128. package/docs/components/switch.html +68 -0
  129. package/docs/components/table.html +668 -0
  130. package/docs/components/tabs.html +506 -0
  131. package/docs/components/text-input.html +68 -0
  132. package/docs/components/textarea.html +603 -0
  133. package/docs/components/timeline.html +487 -0
  134. package/docs/components/toast.html +474 -0
  135. package/docs/components/toggle.html +564 -0
  136. package/docs/components/tooltip.html +423 -0
  137. package/docs/examples/getting-started-example.html +40 -0
  138. package/docs/examples/index.html +93 -0
  139. package/docs/getting-started/index.html +739 -0
  140. package/docs/getting-started/reviews.html +23 -0
  141. package/docs/getting-started/reviews.odom +108 -0
  142. package/docs/getting-started/reviews.vdom +84 -0
  143. package/docs/index.html +134 -0
  144. package/docs/playground.html +416 -0
  145. package/docs/router.html +285 -0
  146. package/docs/styles/index.html +190 -0
  147. package/functions/_middleware.js +32 -0
  148. package/index.html +309 -0
  149. package/lightview-router.js +364 -0
  150. package/lightview-x.js +1577 -0
  151. package/lightview.js +658 -1109
  152. package/lightview.js.backup +793 -0
  153. package/middleware/locale.js +25 -0
  154. package/middleware/markdown.js +44 -0
  155. package/middleware/notFound.js +37 -0
  156. package/package.json +27 -41
  157. package/watch.js +92 -0
  158. package/wrangler.toml +12 -0
  159. package/.idea/lightview.iml +0 -12
  160. package/.idea/modules.xml +0 -8
  161. package/.idea/vcs.xml +0 -6
  162. package/LICENSE +0 -21
  163. package/codepen-no-tabs-embed.css +0 -2
  164. package/components/chart/chart.html +0 -17
  165. package/components/chart/example.html +0 -32
  166. package/components/chart.html +0 -83
  167. package/components/components.js +0 -113
  168. package/components/gantt/example.html +0 -22
  169. package/components/gantt/gantt.html +0 -42
  170. package/components/gauge/example.html +0 -28
  171. package/components/gauge/gauge.html +0 -20
  172. package/components/gauge.html +0 -60
  173. package/components/orgchart/example.html +0 -25
  174. package/components/orgchart/orgchart.html +0 -41
  175. package/components/repl/code-editor.html +0 -64
  176. package/components/repl/editor.html +0 -37
  177. package/components/repl/editorjs-inline-tool/index.js +0 -3
  178. package/components/repl/editorjs-inline-tool/inline-tools.js +0 -28
  179. package/components/repl/editorjs-inline-tool/tool.js +0 -175
  180. package/components/repl/repl-with-wysiwyg.html +0 -355
  181. package/components/repl/repl.html +0 -345
  182. package/components/repl/sup.js +0 -44
  183. package/components/repl/wysiwyg-repl.html +0 -258
  184. package/components/timeline/example.html +0 -33
  185. package/components/timeline/timeline.html +0 -44
  186. package/components/timeline.html +0 -81
  187. package/examples/anchor.html +0 -11
  188. package/examples/chart.html +0 -34
  189. package/examples/counter.html +0 -26
  190. package/examples/counter.test.mjs +0 -47
  191. package/examples/counter2.html +0 -26
  192. package/examples/directives.html +0 -79
  193. package/examples/foreign.html +0 -50
  194. package/examples/forgeinform.html +0 -98
  195. package/examples/form.html +0 -61
  196. package/examples/gauge.html +0 -18
  197. package/examples/invalid-template-literals.html +0 -44
  198. package/examples/medium/remote.html +0 -60
  199. package/examples/message.html +0 -18
  200. package/examples/nested.html +0 -11
  201. package/examples/object-bound-form.html +0 -34
  202. package/examples/remote-server.js +0 -51
  203. package/examples/remote.html +0 -34
  204. package/examples/remote.json +0 -1
  205. package/examples/scratch.html +0 -69
  206. package/examples/sensors/index.html +0 -30
  207. package/examples/sensors/sensor-server.js +0 -30
  208. package/examples/shared.html +0 -41
  209. package/examples/template.html +0 -33
  210. package/examples/timeline.html +0 -21
  211. package/examples/todo.html +0 -38
  212. package/examples/top.html +0 -10
  213. package/examples/types.html +0 -94
  214. package/examples/xor.html +0 -62
  215. package/jest-puppeteer.config.js +0 -5
  216. package/jest.config.json +0 -12
  217. package/sites/client.html +0 -48
  218. package/sites/index.html +0 -247
  219. package/test/basic.html +0 -93
  220. package/test/basic.test.mjs +0 -315
  221. package/test/extended.html +0 -29
  222. package/test/extended.test.mjs +0 -448
  223. package/types.js +0 -534
  224. package/unsplash.key +0 -1
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Locale Prefix Handler
3
+ * Extracts locale from path (e.g. /en/about -> /about with locale='en')
4
+ */
5
+ export const localeHandler = (ctx) => {
6
+ const path = typeof ctx === 'string' ? ctx : ctx.path;
7
+
8
+ // Match /en/ or /en at start of path
9
+ const match = path.match(/^\/([a-z]{2})($|\/)/);
10
+
11
+ if (match) {
12
+ const locale = match[1];
13
+ // Remove locale prefix
14
+ let newPath = path.substring(3);
15
+ if (!newPath.startsWith('/')) newPath = '/' + newPath;
16
+
17
+ return {
18
+ ...ctx,
19
+ path: newPath,
20
+ locale: locale
21
+ };
22
+ }
23
+
24
+ return ctx;
25
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Markdown Handler
3
+ * Intercepts .md requests, loads marked.js on demand, and renders HTML
4
+ */
5
+ let marked = null;
6
+
7
+ export const markdownHandler = async (ctx) => {
8
+ const path = typeof ctx === 'string' ? ctx : ctx.path;
9
+
10
+ // Only process .md files
11
+ if (!path.endsWith('.md')) return ctx;
12
+
13
+ try {
14
+ // 1. Load marked if needed
15
+ if (!marked) {
16
+ console.log('[Markdown] Loading processor...');
17
+ const module = await import('https://cdn.jsdelivr.net/npm/marked/+esm');
18
+ marked = module.marked;
19
+ }
20
+
21
+ // 2. Fetch the raw markdown content
22
+ const response = await fetch(path);
23
+ if (!response.ok) return null; // Let other handlers try or 404
24
+
25
+ const text = await response.text();
26
+
27
+ // 3. Convert to HTML
28
+ // marked.parse can be synchronous or async depending on extensions,
29
+ // but usually synchronous for standard usage.
30
+ const html = marked.parse(text);
31
+
32
+ // 4. Wrap the HTML in a container if needed, or just return it.
33
+ // For Lightview docs, we might want a wrapper, but raw HTML is fine for now.
34
+ // We'll return a Response object which the router understands as a final result.
35
+ return new Response(html, {
36
+ status: 200,
37
+ headers: { 'Content-Type': 'text/html' }
38
+ });
39
+
40
+ } catch (err) {
41
+ console.error('[Markdown] Error processing file:', err);
42
+ return null; // Fallthrough
43
+ }
44
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 404 Not Found Middleware
3
+ *
4
+ * Returns a configured Not Found handler that renders a 404 page
5
+ * into a target element or returns a 404 response.
6
+ *
7
+ * Usage:
8
+ * appRouter.use(notFound({
9
+ * contentEl: document.getElementById('content'),
10
+ * html: '<h1>404 Not Found</h1>' // Optional custom HTML
11
+ * }));
12
+ */
13
+ export const notFound = (options = {}) => {
14
+ const {
15
+ contentEl = null,
16
+ html = `
17
+ <div class="error-page" style="text-align: center; padding: 4rem 1rem;">
18
+ <h1 style="font-size: 3rem; margin-bottom: 1rem;">404</h1>
19
+ <p style="font-size: 1.25rem; margin-bottom: 2rem;">Page not found</p>
20
+ <a href="/" class="btn btn-primary">Go Home</a>
21
+ </div>
22
+ `
23
+ } = options;
24
+
25
+ return async (ctx) => {
26
+ const targetEl = contentEl || ctx.contentEl;
27
+
28
+ // If contentEl is provided (either via options or context), render directly
29
+ if (targetEl) {
30
+ targetEl.innerHTML = html;
31
+ return new Response(html, { status: 404, statusText: 'Not Found' });
32
+ }
33
+
34
+ // Otherwise return a response and let the caller handle it
35
+ return new Response(html, { status: 404, statusText: 'Not Found' });
36
+ };
37
+ };
package/package.json CHANGED
@@ -1,41 +1,27 @@
1
- {
2
- "name": "lightview",
3
- "version": "1.8.1b",
4
- "description": "Small, simple, powerful web UI and micro front end creation ... Great ideas from Svelte, React, Vue and Riot combined.",
5
- "main": "lightview.js",
6
- "scripts": {
7
- "test": "set NODE_OPTIONS=--experimental-vm-modules && jest ./test"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anywhichway/lightview.git"
12
- },
13
- "keywords": [
14
- "svelte",
15
- "react",
16
- "angular",
17
- "riot",
18
- "vue",
19
- "moon",
20
- "hyperapp",
21
- "hyperhtml",
22
- "micro front end",
23
- "custom elements",
24
- "web components"
25
- ],
26
- "author": "Simon Y. Blackwell",
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/anywhichway/lightview/issues"
30
- },
31
- "homepage": "https://lightview.dev",
32
- "devDependencies": {
33
- "@editorjs/editorjs": "^2.16.0",
34
- "editorjs-inline-tool": "^0.4.0",
35
- "jest": "^27.5.1",
36
- "jest-puppeteer": "^6.1.0"
37
- },
38
- "dependencies": {
39
- "froala-editor": "^4.0.11"
40
- }
41
- }
1
+ {
2
+ "name": "lightview",
3
+ "version": "2.0.0",
4
+ "description": "A lightweight reactive UI library with features of Bau, Juris, and HTMX",
5
+ "main": "lightview.js",
6
+ "directories": {
7
+ "doc": "docs"
8
+ },
9
+ "scripts": {
10
+ "dev": "wrangler pages dev . --port 3000",
11
+ "preview": "npm run build && wrangler pages dev ./dist --port 8788",
12
+ "build": "node build.js",
13
+ "watch": "node watch.js",
14
+ "deploy": "npm run build && wrangler pages deploy dist",
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [],
18
+ "author": "",
19
+ "license": "MIT",
20
+ "type": "commonjs",
21
+ "devDependencies": {
22
+ "wrangler": "^4.54.0"
23
+ },
24
+ "dependencies": {
25
+ "marked": "^17.0.1"
26
+ }
27
+ }
package/watch.js ADDED
@@ -0,0 +1,92 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execSync } = require('child_process');
4
+
5
+ const rootDir = __dirname;
6
+ const distDir = path.join(rootDir, 'dist');
7
+
8
+ // Configuration (must match build.js)
9
+ const allowedExtensions = ['.html', '.js', '.css', '.txt', '.xml', '.ico', '.png', '.svg', '.jpg', '.jpeg', '.md'];
10
+ const includeFiles = ['_headers'];
11
+ const excludeFiles = ['build.js', 'watch.js', 'package.json', 'package-lock.json', 'wrangler.toml'];
12
+ const allowedDirs = ['docs', 'components', 'middleware'];
13
+
14
+ function build() {
15
+ try {
16
+ console.log('Running full build...');
17
+ execSync('node build.js', { stdio: 'inherit' });
18
+ } catch (e) {
19
+ console.error('Build failed:', e);
20
+ }
21
+ }
22
+
23
+ function copyFile(srcPath, relativePath) {
24
+ try {
25
+ const destPath = path.join(distDir, relativePath);
26
+ const destDir = path.dirname(destPath);
27
+
28
+ if (!fs.existsSync(destDir)) {
29
+ fs.mkdirSync(destDir, { recursive: true });
30
+ }
31
+
32
+ fs.copyFileSync(srcPath, destPath);
33
+ console.log(`Updated: ${relativePath}`);
34
+ } catch (err) {
35
+ // Ignore errors for deleted files or temporary locks
36
+ if (err.code !== 'ENOENT' && err.code !== 'EBUSY') {
37
+ console.error(`Error copying ${relativePath}:`, err.message);
38
+ }
39
+ }
40
+ }
41
+
42
+ // Initial build
43
+ build();
44
+
45
+ console.log('Watching for changes...');
46
+
47
+ fs.watch(rootDir, { recursive: true }, (eventType, filename) => {
48
+ if (!filename) return;
49
+
50
+ // Ignore .git, node_modules, dist, etc.
51
+ if (filename.startsWith('.git') ||
52
+ filename.startsWith('node_modules') ||
53
+ filename.startsWith('dist') ||
54
+ filename.startsWith('.gemini')) {
55
+ return;
56
+ }
57
+
58
+ const srcPath = path.join(rootDir, filename);
59
+ const parts = filename.split(path.sep);
60
+ const topLevel = parts[0];
61
+
62
+ // Check if it's in one of the allowed directories
63
+ if (allowedDirs.includes(topLevel)) {
64
+ // Check if file exists to handle deletions gracefully
65
+ if (fs.existsSync(srcPath)) {
66
+ // Check if it's a directory
67
+ try {
68
+ const stat = fs.statSync(srcPath);
69
+ if (stat.isDirectory()) return;
70
+ } catch (e) {
71
+ return; // Ignore if stat fails
72
+ }
73
+
74
+ copyFile(srcPath, filename);
75
+ }
76
+ return;
77
+ }
78
+
79
+ // Check if it's a file in the root directory
80
+ if (parts.length === 1) {
81
+ const ext = path.extname(filename).toLowerCase();
82
+ const isAllowedExt = allowedExtensions.includes(ext);
83
+ const isExplicitInclude = includeFiles.includes(filename);
84
+ const isExcluded = excludeFiles.includes(filename) || filename.startsWith('.');
85
+
86
+ if ((isAllowedExt || isExplicitInclude) && !isExcluded) {
87
+ if (fs.existsSync(srcPath)) {
88
+ copyFile(srcPath, filename);
89
+ }
90
+ }
91
+ }
92
+ });
package/wrangler.toml ADDED
@@ -0,0 +1,12 @@
1
+ name = "lightview"
2
+ compatibility_date = "2024-01-01"
3
+
4
+ # [build]
5
+ # command = "npm run build"
6
+
7
+ # Cloudflare Pages configuration
8
+ # Note: Static asset headers are now defined in _headers file
9
+ # and the build directory is specified in the deploy command or dashboard.
10
+
11
+ [assets]
12
+ directory = "./dist"
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/lightview.iml" filepath="$PROJECT_DIR$/.idea/lightview.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Simon Y. Blackwell
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,2 +0,0 @@
1
- body.split-output #output > .active { width: 75%; }
2
- body.split-output #output > #result-box.active { width: 25% }
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Lightview:Component:Chart</title>
6
- </head>
7
- <body>
8
- <div id="target"></div>
9
- <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
10
- <script id="lightview">
11
- (document.currentComponent||(document.currentComponent=document.body)).mount = async function() {
12
- const {chart} = await import(new URL("../components.js", this.componentBaseURI).href);
13
- chart(self);
14
- }
15
- </script>
16
- </body>
17
- </html>
@@ -1,32 +0,0 @@
1
- <!DOCTYPE html>
2
- <head>
3
- <title>Lightview:Chart:Example</title>
4
- <link href="./chart.html" rel="module">
5
- <script src="../../lightview.js"></script>
6
- </head>
7
- <body>
8
- <l-chart id="myPieChart" type="PieChart" style="height:500px;" title="How Much Pizza I Ate Last Night">
9
- {
10
- options: { },
11
- columns: [
12
- {label: "Topping", type: "string"},
13
- {label: "Slices", type: "number"}
14
- ],
15
- rows: [
16
- ["Mushrooms", 3],
17
- ["Onions", 1],
18
- ["Olives", 1],
19
- ["Zucchini", 1],
20
- ["Pepperoni", 2]
21
- ]
22
- }
23
- </l-chart>
24
- <script>
25
- const el = document.getElementById("myPieChart");
26
- el.addEventListener("mounted",() => {
27
- chart = el.chart;
28
- chart.addRow(["Anchovies",1]);
29
- });
30
- </script>
31
- </body>
32
- </html>
@@ -1,83 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="UTF-8">
4
- <title>Lightview:Chart</title>
5
- </head>
6
- <body hidden>
7
- <div id="target"></div>
8
- <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
9
- <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
10
- <script id="lightview">
11
- (document.currentComponent||(document.currentComponent=document.body)).mount = async function() {
12
- let table = JSON5.parse(self.firstChild.textContent.trim()),
13
- chart,
14
- datatable,
15
- options = {};
16
- const target = self.getElementById("target"),
17
- resizeObserver = new ResizeObserver(entries => {
18
- for (let entry of entries) {
19
- if (entry.contentBoxSize) {
20
- // Firefox implements `contentBoxSize` as a single content rect, rather than an array
21
- const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
22
- options.width = contentBoxSize.inlineSize;
23
- } else {
24
- options.width = entry.contentRect.width;
25
- }
26
- }
27
- chart.draw(datatable, options);
28
- }),
29
- callback = (textNode, oldValue, newValue) => {
30
- datatable = new google.visualization.DataTable();
31
- try {
32
- table = table || JSON5.parse(newValue.trim());
33
- datatable = google.visualization.arrayToDataTable(table);
34
- chart.draw(datatable, options);
35
- table = null;
36
- } catch (e) {
37
- target.innerText = e + newValue;
38
- }
39
- };
40
- self.firstChild.innerText = "Loading ...";
41
- self.variables({type: "string", title: "string", style: "string"}, {observed});
42
- if (style) target.setAttribute("style", style);
43
- self.addRow = (row) => {
44
- datatable.addRows([row]);
45
- chart.draw(datatable, options);
46
- };
47
- self.setValue = (row, col, value) => {
48
- if (datatable) {
49
- datatable.setValue(row, col, value);
50
- chart.draw(datatable, options);
51
- }
52
- };
53
- self.setOptions = (newOptions) => {
54
- Object.assign(options, newOptions);
55
- };
56
- self.init = () => {
57
- if (!options.title && title) options.title = title;
58
- chart = new google.visualization[type](target);
59
- addEventListener("change", ({target, value}) => {
60
- if (target === "type") {
61
- chart = new google.visualization[type](target);
62
- } else if (target === "title") {
63
- options.title = value;
64
- } else if (target === "style") {
65
- target.setAttribute("style", value);
66
- }
67
- chart.draw(datatable, options);
68
- });
69
- const node = self.firstChild;
70
- callback(node, node.textContent, node.textContent);
71
- // Will be used by the Lightview global observer
72
- node.characterDataMutationCallback = callback;
73
- // resized charts if window resizes
74
- resizeObserver.observe(target);
75
- };
76
- self.addEventListener("connected", ({target}) => {
77
- google.charts.load("current", {"packages": ["corechart", "gauge"]});
78
- google.charts.setOnLoadCallback(self.init);
79
- });
80
- }
81
- </script>
82
- </body>
83
- </html>
@@ -1,113 +0,0 @@
1
- const chart = (self,{packages = ["corechart"],options={},columns=[],rows=[],type,optionsTransform, rowTransform}={}) => {
2
- options = {...options};
3
- columns = [...columns];
4
- let chart,
5
- datatable;
6
- const chartProxy = (chart) => {
7
- const extras = {
8
- setOption(name,value) {
9
- options[name] = value;
10
- chart.draw(datatable, options);
11
- },
12
- setOptions(newOptions) {
13
- options = {...newOptions};
14
- chart.draw(datatable, options);
15
- }
16
- };
17
- return new Proxy(chart,{
18
- get(target,property) {
19
- let value = extras[property];
20
- if(value!==undefined) return value;
21
- value = target[property];
22
- if(value!==undefined) return Reflect.get(target,property);
23
- value = datatable[property];
24
- if(typeof(value)==="function") {
25
- if(["add","insert","remove","set"].some((prefix) => property.startsWith(prefix))) {
26
- return (...args) => { value.call(datatable,...args); chart.draw(datatable,options); };
27
- };
28
- return value.bind(datatable);
29
- };
30
- }
31
- });
32
- };
33
- const target = self.getElementById("target"),
34
- resizeObserver = new ResizeObserver(entries => {
35
- for (let entry of entries) {
36
- if(entry.contentBoxSize) {
37
- // Firefox implements `contentBoxSize` as a single content rect, rather than an array
38
- const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
39
- if(options.width !== contentBoxSize.inlineSize) {
40
- options.width = contentBoxSize.inlineSize;
41
- chart.draw(datatable, options);
42
- }
43
- } else {
44
- if(options.width !== entry.contentRect.width) {
45
- options.width = entry.contentRect.width;
46
- chart.draw(datatable, options);
47
- }
48
- }
49
- }
50
- }),
51
- callback = (textNode, oldValue, newValue) => {
52
- datatable = new google.visualization.DataTable();
53
- try {
54
- const config = JSON5.parse(newValue.trim());
55
- if(config.options) Object.assign(options,config.options);
56
- if(config.columns) columns=config.columns;
57
- if(config.rows) rows=config.rows;
58
- columns.forEach((column) => {
59
- datatable.addColumn(column);
60
- });
61
- if(optionsTransform) options = optionsTransform(options);
62
- if(rowTransform) rows = rows.map((row,index) => rowTransform(row,index,options));
63
- datatable.addRows(rows);
64
- const {selectedStyle,style} = options;
65
- rows.forEach((row,index) => {
66
- if(selectedStyle) datatable.setRowProperty(index,"selectedStyle",selectedStyle);
67
- if(style) datatable.setRowProperty(index,"style",style);
68
- });
69
- chart.draw(datatable, options);
70
- } catch (e) {
71
- console.error(e + newValue);
72
- target.innerText = e + newValue;
73
- }
74
- };
75
- self.firstChild.innerText = "Loading ...";
76
- self.variables({type: "string", title: "string", style: "string"}, {observed:true});
77
- if(self.hasAttribute("style")) target.setAttribute("style",self.getAttribute("style"));
78
- self.init = () => {
79
- if(!options.title && self.hasAttribute("title")) options.title = self.getAttribute("title");
80
- self.chart = chart = chartProxy(new google.visualization[type||self.getAttribute("type")](target));
81
- addEventListener("change",({target,value}) => {
82
- if (target === "type") {
83
- chart = new google.visualization[type](target);
84
- } else if (target === "title") {
85
- options.title = value;
86
- } else if(target === "style") {
87
- target.setAttribute("style",value);
88
- }
89
- chart.draw(datatable, options);
90
- });
91
- const node = self.firstChild;
92
- callback(node, node.textContent, node.textContent);
93
- // Will be used by the Lightview global observer
94
- node.characterDataMutationCallback = callback;
95
- // resized charts if window resizes
96
- resizeObserver.observe(document.body);
97
- self.dispatchEvent(new Event("mounted"));
98
- };
99
- self.addEventListener("connected", ({target}) => {
100
- const gscript = document.createElement("script");
101
- gscript.setAttribute("src","https://www.gstatic.com/charts/loader.js");
102
- gscript.onload = () => {
103
- google.charts.load("current", {"packages":packages});
104
- google.charts.setOnLoadCallback(self.init);
105
- };
106
- self.appendChild(gscript);
107
- });
108
- const jscript = document.createElement("script");
109
- jscript.setAttribute("src","https://unpkg.com/json5@^2.0.0/dist/index.min.js");
110
- document.head.appendChild(jscript);
111
- }
112
-
113
- export {chart};
@@ -1,22 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Lightview:Component:Gantt:Example</title>
5
- <link href="./gantt.html" rel="module">
6
- <script src="../../lightview.js"></script>
7
- </head>
8
- <body>
9
- <l-gantt id="myChart" style="height:500px;" title="Research Project">
10
- {
11
- options: { },
12
- rows: [
13
- ['Research', 'Find sources',"2015-01-01", "2015-01-05", null, 100, null],
14
- ['Write', 'Write paper',null,"2015-01-09", "3d", 25, 'Research,Outline'],
15
- ['Cite', 'Create bibliography',null, "2015-01-07","1d" , 20, 'Research'],
16
- ['Complete', 'Hand in paper', null, "2015-01-10", "1d" , 0, 'Cite,Write'],
17
- ['Outline', 'Outline paper', null, "2015-01-06", "1d" , 100, 'Research']
18
- ]
19
- }
20
- </l-gantt>
21
- </body>
22
- </html>
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Lightview:Component:Gantt</title>
5
- </head>
6
- <body>
7
- <div id="target"></div>
8
- <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
9
- <script id="lightview">
10
- (document.currentComponent||(document.currentComponent=document.body)).mount = async function() {
11
- const {chart} = await import("../components.js"),
12
- {duration} = await import("/types.js");
13
- chart(self, {
14
- packages: ["gantt"],
15
- columns: [
16
- {label: "Task ID", type: "string"},
17
- {label: "Task Name", type: "string"},
18
- {label: "Start Date", type: "date"},
19
- {label: "End Date", type: "date"},
20
- {label: "Duration", type: "number"},
21
- {label: "% Complete", type: "number"},
22
- {label: "Dependencies", type: "string"}
23
- ],
24
- type: "Gantt",
25
- rowTransform(row, i) {
26
- return row.map((item, index) => {
27
- if (item && (index === 2 || index === 3)) {
28
- const date = new Date(item);
29
- if (!date || typeof (date) !== "object" || !(date instanceof Date)) {
30
- throw new TypeError(`row:${i} col:${index} is not a date`);
31
- }
32
- return date;
33
- }
34
- if (item && index === 4) return duration.parse(item);
35
- return item;
36
- })
37
- }
38
- });
39
- }
40
- </script>
41
- </body>
42
- </html>