create-basicjs 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/bin/create-basicjs.js +58 -5
- package/bin/verify-package.js +1 -1
- package/package.json +2 -2
- package/payload/projects/tauri/.github/workflows/build.yml +86 -0
- package/payload/projects/tauri/.github/workflows/tests.yml +87 -0
- package/payload/projects/tauri/AGENTS.md +128 -0
- package/payload/projects/tauri/CLAUDE.md +1 -0
- package/payload/projects/tauri/LICENSE +201 -0
- package/payload/projects/tauri/NOTICE +8 -0
- package/payload/projects/tauri/README.md +269 -0
- package/payload/projects/tauri/checks/window-check.js +189 -0
- package/payload/projects/tauri/gitignore +8 -0
- package/payload/projects/tauri/handbook/01-getting-started.md +188 -0
- package/payload/projects/tauri/handbook/02-the-project.md +264 -0
- package/payload/projects/tauri/handbook/03-the-page.md +260 -0
- package/payload/projects/tauri/handbook/04-commands.md +265 -0
- package/payload/projects/tauri/handbook/05-events-and-state.md +275 -0
- package/payload/projects/tauri/handbook/06-plugins.md +282 -0
- package/payload/projects/tauri/handbook/07-the-window-and-the-app.md +431 -0
- package/payload/projects/tauri/handbook/08-security.md +374 -0
- package/payload/projects/tauri/handbook/09-tests-and-checks.md +266 -0
- package/payload/projects/tauri/handbook/10-building-and-releasing.md +238 -0
- package/payload/projects/tauri/handbook/11-troubleshooting.md +259 -0
- package/payload/projects/tauri/handbook/README.md +125 -0
- package/payload/projects/tauri/handbook/turkce/01-getting-started.md +193 -0
- package/payload/projects/tauri/handbook/turkce/02-the-project.md +272 -0
- package/payload/projects/tauri/handbook/turkce/03-the-page.md +272 -0
- package/payload/projects/tauri/handbook/turkce/04-commands.md +271 -0
- package/payload/projects/tauri/handbook/turkce/05-events-and-state.md +284 -0
- package/payload/projects/tauri/handbook/turkce/06-plugins.md +286 -0
- package/payload/projects/tauri/handbook/turkce/07-the-window-and-the-app.md +433 -0
- package/payload/projects/tauri/handbook/turkce/08-security.md +384 -0
- package/payload/projects/tauri/handbook/turkce/09-tests-and-checks.md +275 -0
- package/payload/projects/tauri/handbook/turkce/10-building-and-releasing.md +241 -0
- package/payload/projects/tauri/handbook/turkce/11-troubleshooting.md +264 -0
- package/payload/projects/tauri/handbook/turkce/README.md +128 -0
- package/payload/projects/tauri/images/app.png +0 -0
- package/payload/projects/tauri/src-tauri/Cargo.lock +4389 -0
- package/payload/projects/tauri/src-tauri/Cargo.toml +31 -0
- package/payload/projects/tauri/src-tauri/app-icon.svg +16 -0
- package/payload/projects/tauri/src-tauri/build.rs +15 -0
- package/payload/projects/tauri/src-tauri/capabilities/default.json +7 -0
- package/payload/projects/tauri/src-tauri/gitignore +5 -0
- package/payload/projects/tauri/src-tauri/icons/128x128.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/128x128@2x.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/32x32.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/icon.icns +0 -0
- package/payload/projects/tauri/src-tauri/icons/icon.ico +0 -0
- package/payload/projects/tauri/src-tauri/src/check.rs +144 -0
- package/payload/projects/tauri/src-tauri/src/files.rs +255 -0
- package/payload/projects/tauri/src-tauri/src/main.rs +45 -0
- package/payload/projects/tauri/src-tauri/src/sizes.rs +214 -0
- package/payload/projects/tauri/src-tauri/tauri.conf.json +44 -0
- package/payload/projects/tauri/src-tauri/tests/project.rs +243 -0
- package/payload/projects/tauri/ui/app.js +459 -0
- package/payload/projects/tauri/ui/backend.js +196 -0
- package/payload/projects/tauri/ui/basic/LICENSE +14 -0
- package/payload/projects/tauri/ui/basic/basic.min.css +1 -0
- package/payload/projects/tauri/ui/basic/basic.min.js +78 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/LICENSE.txt +206 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- package/payload/projects/tauri/ui/basic/scroll-bar.min.js +3 -0
- package/payload/projects/tauri/ui/comp/_sources.txt +9 -0
- package/payload/projects/tauri/ui/comp/components.min.js +21 -0
- package/payload/projects/tauri/ui/index.html +28 -0
- package/payload/projects/tauri/ui/sizes.js +104 -0
- package/payload/starter/AGENTS.md +11 -6
- package/payload/starter/README.md +1 -1
- package/payload/starter/_basic/VERSION +1 -1
- package/payload/starter/_basic/assets/cards/almond-blossom.png +0 -0
- package/payload/starter/_basic/assets/cards/blackberry.png +0 -0
- package/payload/starter/_basic/assets/cards/borage.png +0 -0
- package/payload/starter/_basic/assets/cards/chamomile.png +0 -0
- package/payload/starter/_basic/assets/cards/dill.png +0 -0
- package/payload/starter/_basic/assets/cards/eucalyptus.png +0 -0
- package/payload/starter/_basic/assets/cards/fennel.png +0 -0
- package/payload/starter/_basic/assets/cards/fig.png +0 -0
- package/payload/starter/_basic/assets/cards/juniper.png +0 -0
- package/payload/starter/_basic/assets/cards/lavender.png +0 -0
- package/payload/starter/_basic/assets/cards/lemon.png +0 -0
- package/payload/starter/_basic/assets/cards/olives.png +0 -0
- package/payload/starter/_basic/assets/cards/oregano.png +0 -0
- package/payload/starter/_basic/assets/cards/pepper.png +0 -0
- package/payload/starter/_basic/assets/cards/physalis.png +0 -0
- package/payload/starter/_basic/assets/cards/pomegranate.png +0 -0
- package/payload/starter/_basic/assets/cards/poppy.png +0 -0
- package/payload/starter/_basic/assets/cards/rosehip.png +0 -0
- package/payload/starter/_basic/assets/cards/saffron.png +0 -0
- package/payload/starter/_basic/assets/categories/cappuccino.png +0 -0
- package/payload/starter/_basic/assets/categories/chocolate-milk.png +0 -0
- package/payload/starter/_basic/assets/categories/coffee.png +0 -0
- package/payload/starter/_basic/assets/categories/frappe.png +0 -0
- package/payload/starter/_basic/assets/categories/iced-caffee.png +0 -0
- package/payload/starter/_basic/assets/categories/milkshake.png +0 -0
- package/payload/starter/_basic/assets/categories/orange-juice.png +0 -0
- package/payload/starter/_basic/assets/categories/tea.png +0 -0
- package/payload/starter/_basic/assets/fruids/brokoli.png +0 -0
- package/payload/starter/_basic/assets/fruids/cilek.png +0 -0
- package/payload/starter/_basic/assets/fruids/domates.png +0 -0
- package/payload/starter/_basic/assets/fruids/elma.png +0 -0
- package/payload/starter/_basic/assets/fruids/havuc.png +0 -0
- package/payload/starter/_basic/assets/fruids/karpuz.png +0 -0
- package/payload/starter/_basic/assets/fruids/limon.png +0 -0
- package/payload/starter/_basic/assets/fruids/muz.png +0 -0
- package/payload/starter/_basic/assets/fruids/nar.png +0 -0
- package/payload/starter/_basic/assets/fruids/patlican.png +0 -0
- package/payload/starter/_basic/assets/fruids/yabanmersini.png +0 -0
- package/payload/starter/_basic/assets/fruids/yesilbiber.png +0 -0
- package/payload/starter/_basic/basic/LICENSE +1 -1
- package/payload/starter/_basic/basic/basic.css +3 -6
- package/payload/starter/_basic/basic/basic.js +154 -60
- package/payload/starter/_basic/basic/basic.min.js +19 -6
- package/payload/starter/_basic/basic/scroll-bar.js +4 -2
- package/payload/starter/_basic/basic/scroll-bar.min.js +1 -0
- package/payload/starter/_basic/comp/accordion.js +659 -0
- package/payload/starter/_basic/comp/action-button.js +22 -23
- package/payload/starter/_basic/comp/action-tab-bar.js +8 -8
- package/payload/starter/_basic/comp/app-bar.js +12 -11
- package/payload/starter/_basic/comp/{badge-v2.js → badge.js} +51 -5
- package/payload/starter/_basic/comp/bottom-bar.js +62 -26
- package/payload/starter/_basic/comp/breadcrumbs.js +4 -2
- package/payload/starter/_basic/comp/canvas.js +652 -0
- package/payload/starter/_basic/comp/chat-view.js +827 -0
- package/payload/starter/_basic/comp/check-box.js +137 -21
- package/payload/starter/_basic/comp/code-editor.js +1171 -0
- package/payload/starter/_basic/comp/{select-color.js → color-picker.js} +62 -29
- package/payload/starter/_basic/comp/context-menu.js +348 -31
- package/payload/starter/_basic/comp/{currency-input-b.js → currency-field.js} +48 -29
- package/payload/starter/_basic/comp/data-table.js +114 -42
- package/payload/starter/_basic/comp/{select-date.js → date-picker.js} +104 -52
- package/payload/starter/_basic/comp/dialog.js +214 -76
- package/payload/starter/_basic/comp/email-field.js +65 -0
- package/payload/starter/_basic/comp/{select-file.js → file-picker.js} +245 -57
- package/payload/starter/_basic/comp/filters.js +374 -60
- package/payload/starter/_basic/comp/form.js +38 -26
- package/payload/starter/_basic/comp/full-screen-select.js +36 -33
- package/payload/starter/_basic/comp/gauge.js +12 -8
- package/payload/starter/_basic/comp/graph-box.js +3911 -0
- package/payload/starter/_basic/comp/grid-group.js +185 -0
- package/payload/starter/_basic/comp/hold-to-confirm-button.js +16 -7
- package/payload/starter/_basic/comp/image-view.js +598 -0
- package/payload/starter/_basic/comp/item-list.js +507 -163
- package/payload/starter/_basic/comp/json-editor.js +3221 -0
- package/payload/starter/_basic/comp/json-view.js +597 -0
- package/payload/starter/_basic/comp/label-editor.js +22 -19
- package/payload/starter/_basic/comp/left-menu.js +89 -22
- package/payload/starter/_basic/comp/line-progress-bar.js +196 -45
- package/payload/starter/_basic/comp/loading-screen.js +49 -18
- package/payload/starter/_basic/comp/log-view.js +530 -0
- package/payload/starter/_basic/comp/{login-page-v2.js → login-page.js} +205 -106
- package/payload/starter/_basic/comp/markdown-view.js +1046 -0
- package/payload/starter/_basic/comp/menu-bar.js +624 -0
- package/payload/starter/_basic/comp/mini-graph-box.js +20 -11
- package/payload/starter/_basic/comp/minimal-accent.js +208 -0
- package/payload/starter/_basic/comp/notice.js +15 -13
- package/payload/starter/_basic/comp/{number-input-b.js → number-field.js} +26 -19
- package/payload/starter/_basic/comp/numeric-keyboard.js +15 -13
- package/payload/starter/_basic/comp/page-control.js +21 -4
- package/payload/starter/_basic/comp/page-header.js +7 -6
- package/payload/starter/_basic/comp/password-field.js +192 -0
- package/payload/starter/_basic/comp/period-bar.js +8 -7
- package/payload/starter/_basic/comp/{phone-input-b.js → phone-field.js} +80 -45
- package/payload/starter/_basic/comp/progress-bar.js +401 -85
- package/payload/starter/_basic/comp/property-panel.js +1022 -123
- package/payload/starter/_basic/comp/radio-button.js +79 -19
- package/payload/starter/_basic/comp/range-slider.js +569 -0
- package/payload/starter/_basic/comp/rich-text-editor.js +33 -30
- package/payload/starter/_basic/comp/scroll-area.js +308 -0
- package/payload/starter/_basic/comp/scrolling-text.js +10 -9
- package/payload/starter/_basic/comp/search-input.js +725 -0
- package/payload/starter/_basic/comp/search-results.js +60 -24
- package/payload/starter/_basic/comp/select-box.js +229 -107
- package/payload/starter/_basic/comp/settings-row.js +20 -19
- package/payload/starter/_basic/comp/side-panel.js +53 -10
- package/payload/starter/_basic/comp/slider-field.js +264 -88
- package/payload/starter/_basic/comp/slider.js +556 -86
- package/payload/starter/_basic/comp/smart-button.js +438 -353
- package/payload/starter/_basic/comp/smart-table.js +748 -186
- package/payload/starter/_basic/comp/sortable-list.js +47 -38
- package/payload/starter/_basic/comp/spark-line-box.js +25 -16
- package/payload/starter/_basic/comp/splitter.js +411 -0
- package/payload/starter/_basic/comp/status-bar.js +408 -0
- package/payload/starter/_basic/comp/step-bar.js +345 -0
- package/payload/starter/_basic/comp/stepper.js +103 -49
- package/payload/starter/_basic/comp/tabs.js +67 -18
- package/payload/starter/_basic/comp/tag-input.js +50 -10
- package/payload/starter/_basic/comp/tap-effect.js +6 -4
- package/payload/starter/_basic/comp/text-area-field.js +233 -0
- package/payload/starter/_basic/comp/text-field.js +1006 -0
- package/payload/starter/_basic/comp/time-line.js +102 -28
- package/payload/starter/_basic/comp/{select-time.js → time-picker.js} +104 -51
- package/payload/starter/_basic/comp/tiny-select.js +79 -39
- package/payload/starter/_basic/comp/tiny-table.js +12 -8
- package/payload/starter/_basic/comp/toast.js +87 -34
- package/payload/starter/_basic/comp/toggle.js +149 -28
- package/payload/starter/_basic/comp/tool-bar.js +760 -0
- package/payload/starter/_basic/comp/tooltip.js +80 -17
- package/payload/starter/_basic/comp/tree-view.js +124 -41
- package/payload/starter/_basic/comp/ui-effects.js +17 -11
- package/payload/starter/_basic/comp/ui-standards.js +5 -4
- package/payload/starter/_basic/comp/url-field.js +190 -0
- package/payload/starter/_basic/comp/web-view.js +70 -16
- package/payload/starter/_basic/docs/basic-js-animated-rules.md +15 -9
- package/payload/starter/_basic/docs/basic-js-code-rules.md +42 -5
- package/payload/starter/_basic/docs/basic-js-components.md +12 -17
- package/payload/starter/_basic/docs/basic-js-core.md +5 -4
- package/payload/starter/_basic/docs/component-index.md +248 -107
- package/payload/starter/_basic/docs/component-template.js +28 -24
- package/payload/starter/_basic/docs/handbook/00-introduction.md +6 -2
- package/payload/starter/_basic/docs/handbook/00-what-is-new.md +21 -0
- package/payload/starter/_basic/docs/handbook/01-label.md +4 -4
- package/payload/starter/_basic/docs/handbook/02-box.md +7 -7
- package/payload/starter/_basic/docs/handbook/03-image.md +4 -4
- package/payload/starter/_basic/docs/handbook/04-common-properties.md +6 -5
- package/payload/starter/_basic/docs/handbook/05-autolayout.md +8 -7
- package/payload/starter/_basic/docs/handbook/06-button.md +3 -3
- package/payload/starter/_basic/docs/handbook/07-input.md +3 -3
- package/payload/starter/_basic/docs/handbook/08-page.md +3 -3
- package/payload/starter/_basic/docs/handbook/09-useful-examples.md +39 -58
- package/payload/starter/_basic/docs/handbook/10-motion.md +6 -6
- package/payload/starter/_basic/docs/handbook/11-other-functions.md +1 -0
- package/payload/starter/_basic/docs/handbook/13-sound.md +3 -3
- package/payload/starter/_basic/docs/handbook/14-using-components.md +180 -0
- package/payload/starter/_basic/docs/handbook/15-making-a-component.md +338 -0
- package/payload/starter/_basic/docs/what-is-new.md +106 -0
- package/payload/starter/_basic/examples/accordion.htm +174 -0
- package/payload/starter/_basic/examples/action-button.htm +74 -32
- package/payload/starter/_basic/examples/action-tab-bar.htm +5 -6
- package/payload/starter/_basic/examples/app-bar.htm +63 -41
- package/payload/starter/_basic/examples/badge.htm +96 -0
- package/payload/starter/_basic/examples/bottom-bar-2.htm +61 -48
- package/payload/starter/_basic/examples/bottom-bar.htm +74 -16
- package/payload/starter/_basic/examples/breadcrumbs.htm +160 -150
- package/payload/starter/_basic/examples/canvas.htm +190 -0
- package/payload/starter/_basic/examples/chat-view.htm +143 -0
- package/payload/starter/_basic/examples/check-box-2.htm +71 -82
- package/payload/starter/_basic/examples/check-box-3.htm +72 -83
- package/payload/starter/_basic/examples/check-box.htm +207 -0
- package/payload/starter/_basic/examples/code-editor-2.htm +259 -0
- package/payload/starter/_basic/examples/code-editor.htm +272 -0
- package/payload/starter/_basic/examples/color-picker.htm +206 -0
- package/payload/starter/_basic/examples/context-menu.htm +180 -139
- package/payload/starter/_basic/examples/currency-field.htm +105 -0
- package/payload/starter/_basic/examples/data-table-2.htm +2 -1
- package/payload/starter/_basic/examples/data-table-3.htm +1 -1
- package/payload/starter/_basic/examples/data-table-4.htm +15 -12
- package/payload/starter/_basic/examples/data-table-5.htm +11 -3
- package/payload/starter/_basic/examples/data-table.htm +90 -40
- package/payload/starter/_basic/examples/date-picker.htm +239 -0
- package/payload/starter/_basic/examples/dialog-centered.htm +394 -40
- package/payload/starter/_basic/examples/dialog.htm +267 -46
- package/payload/starter/_basic/examples/email-field.htm +102 -0
- package/payload/starter/_basic/examples/file-picker.htm +296 -0
- package/payload/starter/_basic/examples/filters.htm +33 -22
- package/payload/starter/_basic/examples/{form-1.htm → form.htm} +18 -19
- package/payload/starter/_basic/examples/full-screen-select.htm +81 -58
- package/payload/starter/_basic/examples/gallery-styled.htm +896 -0
- package/payload/starter/_basic/examples/gauge.htm +95 -81
- package/payload/starter/_basic/examples/graph-box.htm +365 -0
- package/payload/starter/_basic/examples/grid-group.htm +179 -0
- package/payload/starter/_basic/examples/hold-to-confirm-button.htm +102 -113
- package/payload/starter/_basic/examples/image-view.htm +195 -0
- package/payload/starter/_basic/examples/item-list-2.htm +138 -94
- package/payload/starter/_basic/examples/item-list.htm +191 -86
- package/payload/starter/_basic/examples/json-editor.htm +206 -0
- package/payload/starter/_basic/examples/json-view.htm +153 -0
- package/payload/starter/_basic/examples/label-editor.htm +85 -89
- package/payload/starter/_basic/examples/left-menu-2.htm +93 -0
- package/payload/starter/_basic/examples/left-menu.htm +42 -37
- package/payload/starter/_basic/examples/line-progress-bar.htm +155 -114
- package/payload/starter/_basic/examples/loading-screen.htm +149 -125
- package/payload/starter/_basic/examples/log-view.htm +175 -0
- package/payload/starter/_basic/examples/{login-page-dark-v2.htm → login-page-dark.htm} +265 -267
- package/payload/starter/_basic/examples/{login-page-v2.htm → login-page.htm} +266 -267
- package/payload/starter/_basic/examples/markdown-view.htm +220 -0
- package/payload/starter/_basic/examples/menu-bar-2.htm +225 -0
- package/payload/starter/_basic/examples/menu-bar.htm +145 -0
- package/payload/starter/_basic/examples/mini-graph-box.htm +98 -109
- package/payload/starter/_basic/examples/minimal-accent.htm +196 -0
- package/payload/starter/_basic/examples/minimal-theme.htm +432 -0
- package/payload/starter/_basic/examples/notice.htm +13 -4
- package/payload/starter/_basic/examples/number-field.htm +103 -0
- package/payload/starter/_basic/examples/numeric-keyboard.htm +44 -42
- package/payload/starter/_basic/examples/page-control.htm +181 -130
- package/payload/starter/_basic/examples/page-header.htm +57 -30
- package/payload/starter/_basic/examples/password-field.htm +117 -0
- package/payload/starter/_basic/examples/period-bar.htm +43 -29
- package/payload/starter/_basic/examples/phone-field-select-country.htm +292 -0
- package/payload/starter/_basic/examples/phone-field.htm +104 -0
- package/payload/starter/_basic/examples/progress-bar-ozden.htm +229 -92
- package/payload/starter/_basic/examples/progress-bar.htm +222 -174
- package/payload/starter/_basic/examples/property-panel.htm +152 -52
- package/payload/starter/_basic/examples/radio-button-2.htm +101 -109
- package/payload/starter/_basic/examples/radio-button-3.htm +81 -71
- package/payload/starter/_basic/examples/radio-button.htm +289 -0
- package/payload/starter/_basic/examples/range-slider.htm +171 -0
- package/payload/starter/_basic/examples/rich-text-editor.htm +115 -110
- package/payload/starter/_basic/examples/scroll-area.htm +293 -0
- package/payload/starter/_basic/examples/scrolling-text.htm +27 -6
- package/payload/starter/_basic/examples/search-input-2-light.htm +112 -0
- package/payload/starter/_basic/examples/search-input-3-dark.htm +105 -0
- package/payload/starter/_basic/examples/{search-input-v2-place.htm → search-input-place.htm} +25 -26
- package/payload/starter/_basic/examples/search-input.htm +159 -0
- package/payload/starter/_basic/examples/search-results.htm +85 -88
- package/payload/starter/_basic/examples/select-box-2-item-view.htm +304 -0
- package/payload/starter/_basic/examples/select-box-ozden-dark-text.htm +70 -0
- package/payload/starter/_basic/examples/select-box-ozden-item.htm +6 -5
- package/payload/starter/_basic/examples/select-box-ozden-text.htm +5 -3
- package/payload/starter/_basic/examples/select-box.htm +190 -159
- package/payload/starter/_basic/examples/settings-row.htm +92 -43
- package/payload/starter/_basic/examples/side-panel-2.htm +63 -25
- package/payload/starter/_basic/examples/side-panel.htm +84 -70
- package/payload/starter/_basic/examples/slider-2-split.htm +186 -0
- package/payload/starter/_basic/examples/slider-field-ozden.htm +286 -0
- package/payload/starter/_basic/examples/slider-field.htm +174 -134
- package/payload/starter/_basic/examples/slider.htm +257 -180
- package/payload/starter/_basic/examples/smart-button-3-ozden.htm +170 -257
- package/payload/starter/_basic/examples/smart-button-4-dark.htm +86 -47
- package/payload/starter/_basic/examples/smart-button-5-features.htm +130 -125
- package/payload/starter/_basic/examples/smart-button-alternatif.htm +266 -0
- package/payload/starter/_basic/examples/smart-button.htm +207 -174
- package/payload/starter/_basic/examples/smart-table-2.htm +43 -56
- package/payload/starter/_basic/examples/smart-table-3.htm +148 -113
- package/payload/starter/_basic/examples/smart-table-4.htm +37 -50
- package/payload/starter/_basic/examples/{smart-table-1.htm → smart-table-5.htm} +37 -48
- package/payload/starter/_basic/examples/smart-table.htm +183 -0
- package/payload/starter/_basic/examples/sortable-list.htm +191 -142
- package/payload/starter/_basic/examples/spark-line-box.htm +149 -161
- package/payload/starter/_basic/examples/splitter.htm +164 -0
- package/payload/starter/_basic/examples/status-bar.htm +166 -0
- package/payload/starter/_basic/examples/step-bar.htm +129 -0
- package/payload/starter/_basic/examples/stepper-2.htm +86 -58
- package/payload/starter/_basic/examples/stepper.htm +146 -135
- package/payload/starter/_basic/examples/tabs-2.htm +58 -67
- package/payload/starter/_basic/examples/tabs.htm +197 -180
- package/payload/starter/_basic/examples/tag-input.htm +150 -153
- package/payload/starter/_basic/examples/tap-effect.htm +23 -19
- package/payload/starter/_basic/examples/text-area-field.htm +104 -0
- package/payload/starter/_basic/examples/text-field-2.htm +113 -0
- package/payload/starter/_basic/examples/text-field-3-style.htm +105 -0
- package/payload/starter/_basic/examples/text-field-4-custom-unit.htm +96 -0
- package/payload/starter/_basic/examples/{input-b-ex5-warning-icon.htm → text-field-5-warning-icon.htm} +19 -19
- package/payload/starter/_basic/examples/text-field-6-modern-dark.htm +114 -0
- package/payload/starter/_basic/examples/text-field-7-modern.htm +106 -0
- package/payload/starter/_basic/examples/text-field-8-light-dark.htm +159 -0
- package/payload/starter/_basic/examples/text-field.htm +163 -0
- package/payload/starter/_basic/examples/time-line.htm +180 -116
- package/payload/starter/_basic/examples/time-picker.htm +240 -0
- package/payload/starter/_basic/examples/tiny-select.htm +118 -86
- package/payload/starter/_basic/examples/tiny-table.htm +40 -34
- package/payload/starter/_basic/examples/toast.htm +145 -147
- package/payload/starter/_basic/examples/toggle-2.htm +99 -68
- package/payload/starter/_basic/examples/toggle-3.htm +104 -101
- package/payload/starter/_basic/examples/toggle.htm +161 -93
- package/payload/starter/_basic/examples/tool-bar.htm +172 -0
- package/payload/starter/_basic/examples/tooltip-2.htm +110 -60
- package/payload/starter/_basic/examples/tooltip-3.htm +124 -65
- package/payload/starter/_basic/examples/tooltip-4.htm +218 -0
- package/payload/starter/_basic/examples/tooltip.htm +206 -124
- package/payload/starter/_basic/examples/tree-view.htm +210 -182
- package/payload/starter/_basic/examples/ui-effects.htm +207 -185
- package/payload/starter/_basic/examples/ui-standards.htm +200 -139
- package/payload/starter/_basic/examples/url-field.htm +120 -0
- package/payload/starter/_basic/examples/web-view.htm +109 -110
- package/payload/starter/_basic/min/accordion.min.js +2 -0
- package/payload/starter/_basic/min/action-button.min.js +1 -1
- package/payload/starter/_basic/min/app-bar.min.js +1 -1
- package/payload/starter/_basic/min/badge.min.js +2 -0
- package/payload/starter/_basic/min/bottom-bar.min.js +1 -1
- package/payload/starter/_basic/min/canvas.min.js +2 -0
- package/payload/starter/_basic/min/chat-view.min.js +2 -0
- package/payload/starter/_basic/min/check-box.min.js +1 -1
- package/payload/starter/_basic/min/code-editor.min.js +2 -0
- package/payload/starter/_basic/min/color-picker.min.js +2 -0
- package/payload/starter/_basic/min/context-menu.min.js +1 -1
- package/payload/starter/_basic/min/currency-field.min.js +2 -0
- package/payload/starter/_basic/min/data-table.min.js +1 -1
- package/payload/starter/_basic/min/date-picker.min.js +2 -0
- package/payload/starter/_basic/min/dialog.min.js +1 -1
- package/payload/starter/_basic/min/email-field.min.js +2 -0
- package/payload/starter/_basic/min/file-picker.min.js +2 -0
- package/payload/starter/_basic/min/filters.min.js +1 -1
- package/payload/starter/_basic/min/form.min.js +1 -1
- package/payload/starter/_basic/min/full-screen-select.min.js +1 -1
- package/payload/starter/_basic/min/gauge.min.js +1 -1
- package/payload/starter/_basic/min/graph-box.min.js +2 -0
- package/payload/starter/_basic/min/grid-group.min.js +2 -0
- package/payload/starter/_basic/min/hold-to-confirm-button.min.js +1 -1
- package/payload/starter/_basic/min/image-view.min.js +2 -0
- package/payload/starter/_basic/min/item-list.min.js +1 -1
- package/payload/starter/_basic/min/json-editor.min.js +2 -0
- package/payload/starter/_basic/min/json-view.min.js +2 -0
- package/payload/starter/_basic/min/label-editor.min.js +1 -1
- package/payload/starter/_basic/min/left-menu.min.js +1 -1
- package/payload/starter/_basic/min/line-progress-bar.min.js +1 -1
- package/payload/starter/_basic/min/loading-screen.min.js +1 -1
- package/payload/starter/_basic/min/log-view.min.js +2 -0
- package/payload/starter/_basic/min/login-page.min.js +2 -0
- package/payload/starter/_basic/min/markdown-view.min.js +2 -0
- package/payload/starter/_basic/min/menu-bar.min.js +2 -0
- package/payload/starter/_basic/min/mini-graph-box.min.js +1 -1
- package/payload/starter/_basic/min/minimal-accent.min.js +2 -0
- package/payload/starter/_basic/min/notice.min.js +1 -1
- package/payload/starter/_basic/min/number-field.min.js +2 -0
- package/payload/starter/_basic/min/numeric-keyboard.min.js +1 -1
- package/payload/starter/_basic/min/page-control.min.js +1 -1
- package/payload/starter/_basic/min/password-field.min.js +2 -0
- package/payload/starter/_basic/min/phone-field.min.js +2 -0
- package/payload/starter/_basic/min/progress-bar.min.js +1 -1
- package/payload/starter/_basic/min/property-panel.min.js +1 -1
- package/payload/starter/_basic/min/radio-button.min.js +1 -1
- package/payload/starter/_basic/min/range-slider.min.js +2 -0
- package/payload/starter/_basic/min/rich-text-editor.min.js +1 -1
- package/payload/starter/_basic/min/scroll-area.min.js +2 -0
- package/payload/starter/_basic/min/scrolling-text.min.js +1 -1
- package/payload/starter/_basic/min/search-input.min.js +2 -0
- package/payload/starter/_basic/min/search-results.min.js +1 -1
- package/payload/starter/_basic/min/select-box.min.js +1 -1
- package/payload/starter/_basic/min/settings-row.min.js +1 -1
- package/payload/starter/_basic/min/side-panel.min.js +1 -1
- package/payload/starter/_basic/min/slider-field.min.js +1 -1
- package/payload/starter/_basic/min/slider.min.js +1 -1
- package/payload/starter/_basic/min/smart-button.min.js +1 -1
- package/payload/starter/_basic/min/smart-table.min.js +1 -1
- package/payload/starter/_basic/min/sortable-list.min.js +1 -1
- package/payload/starter/_basic/min/spark-line-box.min.js +1 -1
- package/payload/starter/_basic/min/splitter.min.js +2 -0
- package/payload/starter/_basic/min/status-bar.min.js +2 -0
- package/payload/starter/_basic/min/step-bar.min.js +2 -0
- package/payload/starter/_basic/min/stepper.min.js +1 -1
- package/payload/starter/_basic/min/tabs.min.js +1 -1
- package/payload/starter/_basic/min/tag-input.min.js +1 -1
- package/payload/starter/_basic/min/text-area-field.min.js +2 -0
- package/payload/starter/_basic/min/text-field.min.js +2 -0
- package/payload/starter/_basic/min/time-line.min.js +1 -1
- package/payload/starter/_basic/min/time-picker.min.js +2 -0
- package/payload/starter/_basic/min/tiny-select.min.js +1 -1
- package/payload/starter/_basic/min/toast.min.js +1 -1
- package/payload/starter/_basic/min/toggle.min.js +1 -1
- package/payload/starter/_basic/min/tool-bar.min.js +2 -0
- package/payload/starter/_basic/min/tooltip.min.js +1 -1
- package/payload/starter/_basic/min/tree-view.min.js +1 -1
- package/payload/starter/_basic/min/ui-effects.min.js +1 -1
- package/payload/starter/_basic/min/url-field.min.js +2 -0
- package/payload/starter/_basic/min/web-view.min.js +1 -1
- package/payload/templates/booking/app/app.js +11 -8
- package/payload/templates/booking/app/settings.js +4 -4
- package/payload/templates/booking/index.htm +3 -3
- package/payload/templates/booking/pages/account.js +6 -6
- package/payload/templates/booking/pages/book.js +1 -1
- package/payload/templates/booking/pages/services.js +5 -4
- package/payload/templates/classic/app/app.js +15 -11
- package/payload/templates/classic/app/settings.js +22 -20
- package/payload/templates/classic/assets/_attribute.txt +2 -0
- package/payload/templates/classic/assets/cards/dill.png +0 -0
- package/payload/templates/classic/assets/cards/fennel.png +0 -0
- package/payload/templates/classic/assets/cards/juniper.png +0 -0
- package/payload/templates/classic/assets/cards/olives.png +0 -0
- package/payload/templates/classic/assets/cards/oregano.png +0 -0
- package/payload/templates/classic/assets/cards/pepper.png +0 -0
- package/payload/templates/classic/assets/cards/rosehip.png +0 -0
- package/payload/templates/classic/assets/categories/cappuccino.png +0 -0
- package/payload/templates/classic/assets/categories/chocolate-milk.png +0 -0
- package/payload/templates/classic/assets/categories/coffee.png +0 -0
- package/payload/templates/classic/assets/categories/frappe.png +0 -0
- package/payload/templates/classic/assets/categories/iced-caffee.png +0 -0
- package/payload/templates/classic/assets/categories/milkshake.png +0 -0
- package/payload/templates/classic/assets/categories/orange-juice.png +0 -0
- package/payload/templates/classic/assets/categories/tea.png +0 -0
- package/payload/templates/classic/index.htm +2 -2
- package/payload/templates/classic/pages/example.js +10 -10
- package/payload/templates/classic/pages/examples.js +44 -43
- package/payload/templates/classic/pages/home.js +16 -15
- package/payload/templates/classic/pages/info-pages.js +5 -5
- package/payload/templates/classic/pages/search.js +8 -7
- package/payload/templates/classic/pages/settings.js +13 -13
- package/payload/templates/classic/pages/tasks.js +1 -0
- package/payload/templates/classic/pages/template-pages.js +12 -11
- package/payload/templates/coffee-shop/app/app.js +12 -8
- package/payload/templates/coffee-shop/app/settings.js +4 -4
- package/payload/templates/coffee-shop/index.htm +3 -3
- package/payload/templates/coffee-shop/pages/drink.js +1 -1
- package/payload/templates/coffee-shop/pages/menu.js +5 -4
- package/payload/templates/forms/TEMPLATE.md +1 -1
- package/payload/templates/forms/appointment-form.htm +55 -53
- package/payload/templates/forms/contact-form-to-mail.htm +38 -37
- package/payload/templates/forms/contact-form-to-supabase.htm +47 -46
- package/payload/templates/forms/dark-contact-form.htm +43 -40
- package/payload/templates/forms/event-registration-form.htm +80 -77
- package/payload/templates/forms/feedback-form.htm +54 -54
- package/payload/templates/forms/order-form.htm +88 -84
- package/payload/templates/forms/recruitment-form.htm +60 -60
- package/payload/templates/forms/service/readme.md +9 -8
- package/payload/templates/forms/service/send-form-mail.php +38 -21
- package/payload/templates/forms/support-ticket-form.htm +67 -65
- package/payload/templates/panel/common/module-page.js +2 -2
- package/payload/templates/panel/common/theme.js +37 -10
- package/payload/templates/panel/common/top-bar.js +45 -40
- package/payload/templates/panel/index.htm +59 -60
- package/payload/templates/panel/module10/greenhouse.htm +98 -113
- package/payload/templates/panel/module11/arduino-projects.htm +47 -58
- package/payload/templates/panel/module6/energy-hub.htm +71 -103
- package/payload/templates/panel/module7/3d-printers.htm +58 -81
- package/payload/templates/panel/module8/cold-rooms.htm +58 -79
- package/payload/templates/panel/module9/elevator-fleet.htm +72 -93
- package/payload/templates/panel/pages/activity.js +134 -152
- package/payload/templates/panel/pages/contents.js +291 -308
- package/payload/templates/panel/pages/customers.js +250 -267
- package/payload/templates/panel/pages/edit-user.js +31 -30
- package/payload/templates/panel/pages/home.js +39 -70
- package/payload/templates/panel/pages/media.js +166 -183
- package/payload/templates/panel/pages/notifications.js +7 -7
- package/payload/templates/panel/pages/orders.js +200 -217
- package/payload/templates/panel/pages/products.js +259 -278
- package/payload/templates/panel/pages/reports.js +74 -123
- package/payload/templates/panel/pages/roles.js +57 -60
- package/payload/templates/panel/pages/settings.js +127 -143
- package/payload/templates/panel/pages/user-actions.js +106 -110
- package/payload/templates/panel/pages/user-list.js +221 -238
- package/payload/templates/panel/pages/users.js +14 -29
- package/payload/templates/shop/TEMPLATE.md +1 -1
- package/payload/templates/shop/app/app.js +11 -8
- package/payload/templates/shop/app/settings.js +4 -4
- package/payload/templates/shop/index.htm +3 -3
- package/payload/templates/shop/pages/account.js +7 -7
- package/payload/templates/shop/pages/cart.js +1 -1
- package/payload/templates/shop/pages/checkout.js +2 -2
- package/payload/templates/shop/pages/product.js +2 -2
- package/payload/templates/shop/pages/shop.js +6 -5
- package/payload/templates/starter/TEMPLATE.md +1 -1
- package/payload/templates/starter/app/app.js +12 -8
- package/payload/templates/starter/app/settings.js +14 -11
- package/payload/templates/starter/index.htm +3 -3
- package/payload/templates/starter/pages/about.js +1 -1
- package/payload/templates/starter/pages/home.js +2 -2
- package/payload/templates/starter/pages/product.js +1 -1
- package/payload/templates/starter/pages/products.js +5 -5
- package/payload/templates/starter/pages/settings.js +1 -1
- package/payload/templates/starter/pages/tasks.js +8 -8
- package/payload/templates/starter/pages/website.js +1 -1
- package/payload/starter/_basic/comp/chart-box/chart-4.5.1.umd.min.js +0 -13
- package/payload/starter/_basic/comp/chart-box/chart-js-LICENSE.md +0 -9
- package/payload/starter/_basic/comp/chart-box.js +0 -868
- package/payload/starter/_basic/comp/email-input-b.js +0 -57
- package/payload/starter/_basic/comp/input-b.js +0 -759
- package/payload/starter/_basic/comp/password-input-b.js +0 -164
- package/payload/starter/_basic/comp/search-input-v2.js +0 -427
- package/payload/starter/_basic/comp/textarea-b.js +0 -184
- package/payload/starter/_basic/comp/url-input-b.js +0 -145
- package/payload/starter/_basic/examples/badgeV2.htm +0 -68
- package/payload/starter/_basic/examples/chart-box.htm +0 -287
- package/payload/starter/_basic/examples/check-box-1.htm +0 -220
- package/payload/starter/_basic/examples/currency-input-b.htm +0 -71
- package/payload/starter/_basic/examples/email-input-b.htm +0 -67
- package/payload/starter/_basic/examples/input-b-ex1.htm +0 -132
- package/payload/starter/_basic/examples/input-b-ex2.htm +0 -136
- package/payload/starter/_basic/examples/input-b-ex3-style.htm +0 -113
- package/payload/starter/_basic/examples/input-b-ex4-custom-unit.htm +0 -112
- package/payload/starter/_basic/examples/input-b-ex6-dark.htm +0 -108
- package/payload/starter/_basic/examples/input-b-ex7-ozden.htm +0 -153
- package/payload/starter/_basic/examples/number-input-b.htm +0 -68
- package/payload/starter/_basic/examples/password-input-b.htm +0 -70
- package/payload/starter/_basic/examples/phone-input-b-select-country.htm +0 -298
- package/payload/starter/_basic/examples/phone-input-b.htm +0 -72
- package/payload/starter/_basic/examples/radio-button-1.htm +0 -264
- package/payload/starter/_basic/examples/search-input-v2-ozden.htm +0 -128
- package/payload/starter/_basic/examples/search-input-v2.htm +0 -65
- package/payload/starter/_basic/examples/select-color.htm +0 -215
- package/payload/starter/_basic/examples/select-date.htm +0 -244
- package/payload/starter/_basic/examples/select-file.htm +0 -268
- package/payload/starter/_basic/examples/select-time.htm +0 -249
- package/payload/starter/_basic/examples/smart-button-2.htm +0 -220
- package/payload/starter/_basic/examples/textarea-b.htm +0 -76
- package/payload/starter/_basic/examples/unfinished-login-page-dark-supabase.htm +0 -221
- package/payload/starter/_basic/examples/unfinished-login-page-supabase.htm +0 -221
- package/payload/starter/_basic/examples/url-input-b.htm +0 -85
- package/payload/starter/_basic/min/badge-v2.min.js +0 -2
- package/payload/starter/_basic/min/chart-box.min.js +0 -2
- package/payload/starter/_basic/min/currency-input-b.min.js +0 -2
- package/payload/starter/_basic/min/email-input-b.min.js +0 -2
- package/payload/starter/_basic/min/input-b.min.js +0 -2
- package/payload/starter/_basic/min/login-page-v2.min.js +0 -2
- package/payload/starter/_basic/min/number-input-b.min.js +0 -2
- package/payload/starter/_basic/min/password-input-b.min.js +0 -2
- package/payload/starter/_basic/min/phone-input-b.min.js +0 -2
- package/payload/starter/_basic/min/search-input-v2.min.js +0 -2
- package/payload/starter/_basic/min/select-color.min.js +0 -2
- package/payload/starter/_basic/min/select-date.min.js +0 -2
- package/payload/starter/_basic/min/select-file.min.js +0 -2
- package/payload/starter/_basic/min/select-time.min.js +0 -2
- package/payload/starter/_basic/min/textarea-b.min.js +0 -2
- package/payload/starter/_basic/min/url-input-b.min.js +0 -2
- package/payload/templates/panel/common/bridge.min.js +0 -0
- package/payload/templates/panel/common/full-view.min.js +0 -1
- package/payload/templates/panel/common/main-view.min.js +0 -1
- package/payload/templates/panel/common/module-page.min.js +0 -1
- package/payload/templates/panel/common/right-view.min.js +0 -1
- package/payload/templates/panel/common/start-page.min.js +0 -1
- package/payload/templates/panel/common/top-bar-v25-07-29-1.js +0 -330
- package/payload/templates/panel/common/top-bar-v25-07-29-2.js +0 -265
- package/payload/templates/panel/common/top-bar.min.js +0 -1
- package/payload/templates/panel/common/ui-standards.min.js +0 -1
- package/payload/templates/panel/managers/database.min.js +0 -1
- package/payload/templates/panel/managers/login.min.js +0 -1
- package/payload/templates/panel/pages/_page-template.min.js +0 -1
- package/payload/templates/panel/pages/contents.min.js +0 -1
- package/payload/templates/panel/pages/edit-user.min.js +0 -1
- package/payload/templates/panel/pages/edit-users-table.min.js +0 -1
- package/payload/templates/panel/pages/home.min.js +0 -1
- package/payload/templates/panel/pages/notifications.min.js +0 -1
- package/payload/templates/panel/pages/reports.min.js +0 -1
- package/payload/templates/panel/pages/settings.min.js +0 -1
- package/payload/templates/panel/pages/user-actions.min.js +0 -2
- package/payload/templates/panel/pages/users.min.js +0 -1
- /package/payload/starter/_basic/comp/{password-input-b → password-field}/hide-btn.png +0 -0
- /package/payload/starter/_basic/comp/{password-input-b → password-field}/hide-btn2.png +0 -0
- /package/payload/starter/_basic/comp/{password-input-b → password-field}/show-btn.png +0 -0
- /package/payload/starter/_basic/comp/{password-input-b → password-field}/show-btn2.png +0 -0
- /package/payload/starter/_basic/comp/{search-input-v2 → search-input}/clear-round.svg +0 -0
- /package/payload/starter/_basic/comp/{search-input-v2 → search-input}/clear.svg +0 -0
- /package/payload/starter/_basic/comp/{search-input-v2 → search-input}/filter.png +0 -0
- /package/payload/starter/_basic/comp/{search-input-v2 → search-input}/filter.svg +0 -0
- /package/payload/starter/_basic/comp/{search-input-v2 → search-input}/search.svg +0 -0
|
@@ -0,0 +1,1171 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
CodeEditor - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT
|
|
8
|
+
- A text editor for code: line numbers, colors by language, the line of the cursor. A long line does not wrap: the
|
|
9
|
+
view scrolls sideways.
|
|
10
|
+
- Languages: "python", "javascript", "go", "ruby", "json", "html", "css", "sql", "bash", "text". CodeEditor.languages
|
|
11
|
+
takes your own.
|
|
12
|
+
- The typing is the <textarea> of the browser: selection, copy, paste, undo and the input of every language work as
|
|
13
|
+
they do everywhere. The colors are drawn behind it, only for the lines that are seen, so a file of 100000 lines stays
|
|
14
|
+
fast.
|
|
15
|
+
- Keys: Tab and Shift + Tab indent (also many lines), Enter keeps the indent of its line (one more after ":" in Python,
|
|
16
|
+
after "{", "[" or "(" in the others), Backspace in the indent goes back one level, Ctrl (or Cmd) + / comments the
|
|
17
|
+
lines out. Undo takes all of them back. Escape, then Tab leaves the editor (for a keyboard user).
|
|
18
|
+
- changeDelay (ms): onChange waits for the typing to rest (for a big text sent to another place).
|
|
19
|
+
- Style packages: "light" (default), "dark". Select with styleName (CodeEditor.styles), or later with setTheme().
|
|
20
|
+
|
|
21
|
+
USAGE:
|
|
22
|
+
const editor = CodeEditor({
|
|
23
|
+
width: 600, height: 400,
|
|
24
|
+
language: "python",
|
|
25
|
+
value: "def hello():\n print('Hello')\n",
|
|
26
|
+
onChange: function (self) { println(self.value.length); },
|
|
27
|
+
onCursorChange: function (self) { println(self.cursorLine + ":" + self.cursorColumn); },
|
|
28
|
+
});
|
|
29
|
+
editor.setValue("x = 1\n"); // onChange is called; setValue(text, 1): silent. Undo starts again.
|
|
30
|
+
editor.getValue(); // the text now (self.value too)
|
|
31
|
+
editor.insertText("print(x)"); // at the cursor; undo takes it back
|
|
32
|
+
editor.getSelectedText();
|
|
33
|
+
editor.setLanguage("javascript");
|
|
34
|
+
editor.setReadOnly(1);
|
|
35
|
+
editor.setShowLineNumbers(0);
|
|
36
|
+
editor.setTabSize(2);
|
|
37
|
+
editor.goToLine(120);
|
|
38
|
+
editor.focusEditor();
|
|
39
|
+
editor.setTheme("dark");
|
|
40
|
+
CodeEditor({ styleName: "dark", placeholder: "Write here", changeDelay: 150 });
|
|
41
|
+
|
|
42
|
+
A NEW LANGUAGE:
|
|
43
|
+
CodeEditor.languages.toml = { lineComment: "#", strings: ['"""', '"', "'"], multiLineStrings: ['"""'], keywords: ["true", "false"], propertyWords: 1 };
|
|
44
|
+
Its keys: lineComment, blockComment: [start, end], strings (the longest first), multiLineStrings, keywords, builtins,
|
|
45
|
+
ignoreCase: 1, callWords: 1 (a word before "(" is a function), propertyWords: 1 (a word before ":" is a property),
|
|
46
|
+
propertyStrings: 1 (a string before ":" is a property), decorators: "@", variables: "$", indentAfter: ":" (the letters
|
|
47
|
+
at the end of a line that open one more level). tokenize: function (text, state): your own, instead of all of them:
|
|
48
|
+
returns { parts: [[kind, text], ...], state }. kind: "keyword", "string", "number", "comment", "builtin", "function",
|
|
49
|
+
"property", "tag", "attribute", "variable", "" (plain). state goes to the next line.
|
|
50
|
+
|
|
51
|
+
Started Date: November 2026
|
|
52
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
53
|
+
|
|
54
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
55
|
+
Licensed under the Apache License, Version 2.0
|
|
56
|
+
SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
"use strict";
|
|
61
|
+
|
|
62
|
+
// Default values:
|
|
63
|
+
const CodeEditorDefaults = {
|
|
64
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
65
|
+
left: 0,
|
|
66
|
+
top: 0,
|
|
67
|
+
width: "100%",
|
|
68
|
+
height: 320,
|
|
69
|
+
value: "", // The text
|
|
70
|
+
language: "text", // A name of CodeEditor.languages
|
|
71
|
+
tabSize: 4, // The spaces of one level
|
|
72
|
+
readOnly: 0,
|
|
73
|
+
showLineNumbers: 1,
|
|
74
|
+
placeholder: "",
|
|
75
|
+
changeDelay: 0, // ms: onChange waits for the typing to rest
|
|
76
|
+
ariaLabel: "Code",
|
|
77
|
+
onChange: function (self) { }, // self.value changed. (Not at create time, not with silent: 1)
|
|
78
|
+
onCursorChange: function (self) { }, // self.cursorLine, self.cursorColumn (from 1)
|
|
79
|
+
styleName: "light", // "light", "dark" or a name added to CodeEditor.styles
|
|
80
|
+
style: { // Light style package (default)
|
|
81
|
+
box: { color: "white", border: 1, borderColor: Black(0.14), round: 8 },
|
|
82
|
+
text: {
|
|
83
|
+
fontSize: 13,
|
|
84
|
+
lineHeight: 20,
|
|
85
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
86
|
+
color: "#2B2B2A",
|
|
87
|
+
caretColor: "#111111",
|
|
88
|
+
paddingX: 10,
|
|
89
|
+
paddingY: 8,
|
|
90
|
+
},
|
|
91
|
+
gutter: { color: "#F6F6F4", lineColor: Black(0.08), textColor: Black(0.38), activeTextColor: Black(0.8), space: 1 }, // space: letters at each side
|
|
92
|
+
activeLine: { color: "rgba(91, 186, 193, 0.1)" },
|
|
93
|
+
selection: { color: "rgba(91, 186, 193, 0.35)" },
|
|
94
|
+
placeholder: { color: Black(0.4) },
|
|
95
|
+
scrollBar: { color: Black(0.22), hoverColor: Black(0.4), size: 10 },
|
|
96
|
+
// The colors of the code
|
|
97
|
+
kinds: {
|
|
98
|
+
keyword: "#8A2F8E",
|
|
99
|
+
string: "#1F7A3D",
|
|
100
|
+
number: "#A85A00",
|
|
101
|
+
comment: "#7A7F87",
|
|
102
|
+
builtin: "#00717A",
|
|
103
|
+
function: "#2467B8",
|
|
104
|
+
property: "#2467B8",
|
|
105
|
+
tag: "#A32A4B",
|
|
106
|
+
attribute: "#A85A00",
|
|
107
|
+
variable: "#00717A",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const CodeEditor = function (params = {}) {
|
|
113
|
+
|
|
114
|
+
// Merge style package: params.style > CodeEditor.styles[styleName] > CodeEditorDefaults.style (light)
|
|
115
|
+
const pageStyle = params.style; // WHY: setTheme() puts it over another package.
|
|
116
|
+
basic.applyStylePackage(params, CodeEditor.styles, CodeEditorDefaults);
|
|
117
|
+
|
|
118
|
+
// Merge params:
|
|
119
|
+
mergeIntoIfMissing(params, CodeEditorDefaults);
|
|
120
|
+
|
|
121
|
+
// BOX: Component container
|
|
122
|
+
const box = startObject(params);
|
|
123
|
+
|
|
124
|
+
// *** PRIVATE VARIABLES:
|
|
125
|
+
let _s = box.style;
|
|
126
|
+
const BUFFER_LINES = 25; // Lines drawn over and under the ones that are seen: a small scroll draws nothing
|
|
127
|
+
const MAX_COLORED_LETTERS = 2000; // A longer line is colored up to here (a minified file)
|
|
128
|
+
const MIN_GUTTER_DIGITS = 2;
|
|
129
|
+
const CARET_MARGIN_LINES = 2; // goToLine() keeps this many lines around the line
|
|
130
|
+
let lines = [""];
|
|
131
|
+
let lineStates = [null]; // lineStates[i]: the state of the tokenizer at the start of line i
|
|
132
|
+
let validStateCount = 1; // The states up to here are right
|
|
133
|
+
let drawnFirstLine = -1; // The lines of the code layer now
|
|
134
|
+
let drawnLastLine = -1;
|
|
135
|
+
let cancelChange = null; // The waiting onChange (changeDelay)
|
|
136
|
+
let canLeaveWithTab = 0; // 1: Escape was pressed: the next Tab leaves the editor
|
|
137
|
+
|
|
138
|
+
// *** PUBLIC VARIABLES:
|
|
139
|
+
box.cursorLine = 1; // Read only (from 1)
|
|
140
|
+
box.cursorColumn = 1;
|
|
141
|
+
// NOTE: Default values are also public variables. (box.value, box.language, box.readOnly...)
|
|
142
|
+
|
|
143
|
+
// *** PRIVATE FUNCTIONS:
|
|
144
|
+
|
|
145
|
+
// The style of a package, with the style of the page over it. (setTheme)
|
|
146
|
+
const styleOfPackage = function (styleName) {
|
|
147
|
+
const fresh = { styleName: styleName, style: pageStyle };
|
|
148
|
+
basic.applyStylePackage(fresh, CodeEditor.styles, CodeEditorDefaults);
|
|
149
|
+
mergeIntoIfMissing(fresh, CodeEditorDefaults);
|
|
150
|
+
return fresh.style;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const languageDefinition = function () {
|
|
154
|
+
return CodeEditor.languages[box.language] || CodeEditor.languages.text;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const textarea = function () {
|
|
158
|
+
return box.textareaElem;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// WHY up to the line: a change only moves the states after it, and only the lines that are seen ask for them.
|
|
162
|
+
const makeStatesUpTo = function (lineIndex) {
|
|
163
|
+
const definition = languageDefinition();
|
|
164
|
+
for (let i = validStateCount; i <= lineIndex && i < lines.length; i++) {
|
|
165
|
+
const previousText = lines[i - 1].slice(0, MAX_COLORED_LETTERS);
|
|
166
|
+
lineStates[i] = CodeEditor.tokenizeLine(previousText, lineStates[i - 1], definition).state;
|
|
167
|
+
validStateCount = i + 1;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const lineHtml = function (lineIndex) {
|
|
172
|
+
const text = lines[lineIndex];
|
|
173
|
+
const colored = text.slice(0, MAX_COLORED_LETTERS);
|
|
174
|
+
const result = CodeEditor.tokenizeLine(colored, lineStates[lineIndex], languageDefinition());
|
|
175
|
+
const html = result.parts.map(CodeEditor.partHtml).join("");
|
|
176
|
+
return html + basic.escapeHtml(text.slice(MAX_COLORED_LETTERS));
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const lineHeight = function () {
|
|
180
|
+
return _s.text.lineHeight;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// CONTENT: the lines that are seen and the ones around them. force: also when they are the same lines.
|
|
184
|
+
const drawVisibleLines = function (force) {
|
|
185
|
+
const elem = textarea();
|
|
186
|
+
const firstSeen = Math.floor(elem.scrollTop / lineHeight());
|
|
187
|
+
const seenCount = Math.ceil(elem.clientHeight / lineHeight()) + 1;
|
|
188
|
+
const lastSeen = Math.min(lines.length - 1, firstSeen + seenCount);
|
|
189
|
+
const isInDrawnLines = (firstSeen >= drawnFirstLine && lastSeen <= drawnLastLine);
|
|
190
|
+
|
|
191
|
+
if (force || !isInDrawnLines) {
|
|
192
|
+
drawnFirstLine = Math.max(0, firstSeen - BUFFER_LINES);
|
|
193
|
+
drawnLastLine = Math.min(lines.length - 1, lastSeen + BUFFER_LINES);
|
|
194
|
+
makeStatesUpTo(drawnLastLine);
|
|
195
|
+
drawCode();
|
|
196
|
+
drawGutter();
|
|
197
|
+
}
|
|
198
|
+
placeLayers();
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const drawCode = function () {
|
|
202
|
+
const parts = [];
|
|
203
|
+
for (let i = drawnFirstLine; i <= drawnLastLine; i++) parts.push(lineHtml(i));
|
|
204
|
+
box.codeLayer.text = parts.join("\n");
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const drawGutter = function () {
|
|
208
|
+
const numbers = [];
|
|
209
|
+
for (let i = drawnFirstLine; i <= drawnLastLine; i++) {
|
|
210
|
+
const isActive = (i + 1 === box.cursorLine);
|
|
211
|
+
numbers.push((isActive) ? '<span class="code-editor-active-number">' + (i + 1) + "</span>" : String(i + 1));
|
|
212
|
+
}
|
|
213
|
+
box.gutterLayer.text = numbers.join("\n");
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// LAYOUT: the layers follow the scroll of the textarea
|
|
217
|
+
const placeLayers = function () {
|
|
218
|
+
const elem = textarea();
|
|
219
|
+
const top = _s.text.paddingY + drawnFirstLine * lineHeight() - elem.scrollTop;
|
|
220
|
+
const left = _s.text.paddingX - elem.scrollLeft;
|
|
221
|
+
box.codeLayer.css.transform = "translate(" + left + "px, " + top + "px)";
|
|
222
|
+
box.gutterLayer.css.transform = "translateY(" + top + "px)";
|
|
223
|
+
box.activeLine.top = _s.text.paddingY + (box.cursorLine - 1) * lineHeight() - elem.scrollTop;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// LAYOUT: the gutter is as wide as the number of the last line
|
|
227
|
+
const refreshGutterWidth = function () {
|
|
228
|
+
const digits = Math.max(MIN_GUTTER_DIGITS, String(lines.length).length);
|
|
229
|
+
const letters = digits + 2 * _s.gutter.space;
|
|
230
|
+
const width = (box.showLineNumbers == 1) ? "calc(" + letters + "ch + 1px)" : "0px";
|
|
231
|
+
box.gutter.visible = (box.showLineNumbers == 1) ? 1 : 0;
|
|
232
|
+
box.gutter.css.width = width;
|
|
233
|
+
box.gutterLayer.css.right = _s.gutter.space + "ch";
|
|
234
|
+
box.codeArea.css.left = width;
|
|
235
|
+
box.codeArea.css.width = "calc(100% - " + width + ")";
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// The state of a changed text: the states before the first changed line stay.
|
|
239
|
+
const readValue = function () {
|
|
240
|
+
// WHY once: a big textarea makes its value again at every read (about 100 ms for 100000 lines in WebKit).
|
|
241
|
+
const value = textarea().value;
|
|
242
|
+
const newLines = value.split("\n");
|
|
243
|
+
let firstChanged = 0;
|
|
244
|
+
const shorter = Math.min(lines.length, newLines.length);
|
|
245
|
+
while (firstChanged < shorter && lines[firstChanged] === newLines[firstChanged]) firstChanged++;
|
|
246
|
+
lines = newLines;
|
|
247
|
+
lineStates.length = Math.min(lineStates.length, lines.length);
|
|
248
|
+
validStateCount = Math.min(validStateCount, firstChanged + 1, lines.length);
|
|
249
|
+
box.value = value;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// The line and the column of the cursor, and what shows them
|
|
253
|
+
const readCursor = function () {
|
|
254
|
+
const cursor = textarea().selectionStart;
|
|
255
|
+
let line = 1;
|
|
256
|
+
let lineStart = 0;
|
|
257
|
+
let lineBreak = box.value.indexOf("\n");
|
|
258
|
+
while (lineBreak >= 0 && lineBreak < cursor) {
|
|
259
|
+
line++;
|
|
260
|
+
lineStart = lineBreak + 1;
|
|
261
|
+
lineBreak = box.value.indexOf("\n", lineStart);
|
|
262
|
+
}
|
|
263
|
+
const column = cursor - lineStart + 1;
|
|
264
|
+
const isSame = (line === box.cursorLine && column === box.cursorColumn);
|
|
265
|
+
const isOtherLine = (line !== box.cursorLine);
|
|
266
|
+
box.cursorLine = line;
|
|
267
|
+
box.cursorColumn = column;
|
|
268
|
+
if (isOtherLine) drawGutter();
|
|
269
|
+
placeLayers();
|
|
270
|
+
if (!isSame) box.onCursorChange(box);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const tellChange = function () {
|
|
274
|
+
if (cancelChange) cancelChange();
|
|
275
|
+
cancelChange = null;
|
|
276
|
+
if (box.changeDelay <= 0) {
|
|
277
|
+
box.onChange(box);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
cancelChange = box.after(box.changeDelay, function () {
|
|
281
|
+
cancelChange = null;
|
|
282
|
+
box.onChange(box);
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const onInput = function () {
|
|
287
|
+
readValue();
|
|
288
|
+
refreshGutterWidth();
|
|
289
|
+
drawVisibleLines(1);
|
|
290
|
+
readCursor();
|
|
291
|
+
tellChange();
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// WHY execCommand: the only way that stays in the undo of the textarea (setRangeText and value do not).
|
|
295
|
+
const insertAtSelection = function (text) {
|
|
296
|
+
const elem = textarea();
|
|
297
|
+
elem.focus();
|
|
298
|
+
const isDone = (text === "") ? document.execCommand("delete") : document.execCommand("insertText", false, text);
|
|
299
|
+
if (!isDone) {
|
|
300
|
+
elem.setRangeText(text, elem.selectionStart, elem.selectionEnd, "end");
|
|
301
|
+
onInput();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// The start and the end of the whole lines of the selection, as places in the text
|
|
306
|
+
const selectedLineRange = function () {
|
|
307
|
+
const elem = textarea();
|
|
308
|
+
const value = elem.value;
|
|
309
|
+
const start = value.lastIndexOf("\n", elem.selectionStart - 1) + 1;
|
|
310
|
+
// WHY: A selection that ends at the start of a line does not take that line.
|
|
311
|
+
const lastPlace = (elem.selectionEnd > elem.selectionStart && value[elem.selectionEnd - 1] === "\n") ? elem.selectionEnd - 1 : elem.selectionEnd;
|
|
312
|
+
let end = value.indexOf("\n", lastPlace);
|
|
313
|
+
if (end < 0) end = value.length;
|
|
314
|
+
return { start: start, end: end };
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// Changes the whole lines of the selection with one step of undo, and selects them.
|
|
318
|
+
const changeSelectedLines = function (changeLine) {
|
|
319
|
+
const elem = textarea();
|
|
320
|
+
const range = selectedLineRange();
|
|
321
|
+
const oldLines = elem.value.slice(range.start, range.end).split("\n");
|
|
322
|
+
const newText = oldLines.map(changeLine).join("\n");
|
|
323
|
+
elem.setSelectionRange(range.start, range.end);
|
|
324
|
+
insertAtSelection(newText);
|
|
325
|
+
elem.setSelectionRange(range.start, range.start + newText.length);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const indentOne = function () {
|
|
329
|
+
return " ".repeat(box.tabSize);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const isManyLines = function () {
|
|
333
|
+
const elem = textarea();
|
|
334
|
+
return elem.value.slice(elem.selectionStart, elem.selectionEnd).includes("\n");
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const onTabKey = function () {
|
|
338
|
+
if (isManyLines()) {
|
|
339
|
+
changeSelectedLines(function (line) { return (line.length > 0) ? indentOne() + line : line; });
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const elem = textarea();
|
|
343
|
+
const lineStart = elem.value.lastIndexOf("\n", elem.selectionStart - 1) + 1;
|
|
344
|
+
const column = elem.selectionStart - lineStart;
|
|
345
|
+
insertAtSelection(" ".repeat(box.tabSize - (column % box.tabSize)));
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const onShiftTabKey = function () {
|
|
349
|
+
changeSelectedLines(function (line) {
|
|
350
|
+
const spaces = line.match(/^ */)[0].length;
|
|
351
|
+
return line.slice(Math.min(spaces, box.tabSize));
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const onEnterKey = function () {
|
|
356
|
+
const elem = textarea();
|
|
357
|
+
const lineStart = elem.value.lastIndexOf("\n", elem.selectionStart - 1) + 1;
|
|
358
|
+
const beforeCursor = elem.value.slice(lineStart, elem.selectionStart);
|
|
359
|
+
const indent = beforeCursor.match(/^[ \t]*/)[0];
|
|
360
|
+
const opensLevel = (languageDefinition().indentAfter || "").includes(beforeCursor.trimEnd().slice(-1) || " ");
|
|
361
|
+
insertAtSelection("\n" + indent + ((opensLevel) ? indentOne() : ""));
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// In the indent, Backspace goes back to the level before. Returns 1 when it did.
|
|
365
|
+
const onBackspaceKey = function () {
|
|
366
|
+
const elem = textarea();
|
|
367
|
+
if (elem.selectionStart !== elem.selectionEnd) return 0;
|
|
368
|
+
const lineStart = elem.value.lastIndexOf("\n", elem.selectionStart - 1) + 1;
|
|
369
|
+
const beforeCursor = elem.value.slice(lineStart, elem.selectionStart);
|
|
370
|
+
if (beforeCursor.length === 0 || beforeCursor.trim().length > 0) return 0;
|
|
371
|
+
const count = ((beforeCursor.length - 1) % box.tabSize) + 1;
|
|
372
|
+
elem.setSelectionRange(elem.selectionStart - count, elem.selectionStart);
|
|
373
|
+
insertAtSelection("");
|
|
374
|
+
return 1;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const toggleLineComment = function () {
|
|
378
|
+
const mark = languageDefinition().lineComment;
|
|
379
|
+
if (!mark) return;
|
|
380
|
+
const elem = textarea();
|
|
381
|
+
const range = selectedLineRange();
|
|
382
|
+
const oldLines = elem.value.slice(range.start, range.end).split("\n");
|
|
383
|
+
const isCommented = oldLines.every(function (line) { return line.trim() === "" || line.trimStart().startsWith(mark); });
|
|
384
|
+
changeSelectedLines(function (line) {
|
|
385
|
+
if (line.trim() === "") return line;
|
|
386
|
+
if (!isCommented) return line.replace(/^(\s*)/, "$1" + mark + " ");
|
|
387
|
+
return line.replace(new RegExp("^(\\s*)" + CodeEditor.escapeRegExp(mark) + " ?"), "$1");
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const onKeyDown = function (event) {
|
|
392
|
+
const isTab = (event.key === "Tab");
|
|
393
|
+
const isCommentKey = (event.key === "/" && (event.ctrlKey || event.metaKey));
|
|
394
|
+
if (event.key === "Escape") canLeaveWithTab = 1;
|
|
395
|
+
else if (!isTab) canLeaveWithTab = 0;
|
|
396
|
+
|
|
397
|
+
if (isTab && canLeaveWithTab) {
|
|
398
|
+
canLeaveWithTab = 0;
|
|
399
|
+
return; // WHY: The Tab of the browser: a keyboard user can leave the editor.
|
|
400
|
+
}
|
|
401
|
+
if (box.readOnly == 1) return;
|
|
402
|
+
|
|
403
|
+
if (isTab) {
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
if (event.shiftKey) onShiftTabKey();
|
|
406
|
+
else onTabKey();
|
|
407
|
+
} else if (event.key === "Enter" && !event.isComposing) {
|
|
408
|
+
event.preventDefault();
|
|
409
|
+
onEnterKey();
|
|
410
|
+
} else if (event.key === "Backspace" && !event.isComposing) {
|
|
411
|
+
if (onBackspaceKey()) event.preventDefault();
|
|
412
|
+
} else if (isCommentKey) {
|
|
413
|
+
event.preventDefault();
|
|
414
|
+
toggleLineComment();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// LOOK: everything that comes from the style (the first drawing and setTheme)
|
|
419
|
+
const applyLook = function () {
|
|
420
|
+
const text = _s.text;
|
|
421
|
+
const fontCss = { fontFamily: text.fontFamily, fontSize: text.fontSize + "px", lineHeight: text.lineHeight + "px" };
|
|
422
|
+
box.props(_s.box);
|
|
423
|
+
box.gutter.color = _s.gutter.color;
|
|
424
|
+
// WHY the font of the code on these two: their widths are written in ch, the width of a letter of their own font.
|
|
425
|
+
box.gutter.css = { ...fontCss, borderRight: "1px solid " + _s.gutter.lineColor };
|
|
426
|
+
box.codeArea.css = fontCss;
|
|
427
|
+
box.gutterLayer.css = { ...fontCss, color: _s.gutter.textColor };
|
|
428
|
+
box.codeLayer.css = { ...fontCss, color: text.color, tabSize: box.tabSize };
|
|
429
|
+
box.activeLine.color = _s.activeLine.color;
|
|
430
|
+
box.activeLine.height = text.lineHeight;
|
|
431
|
+
Object.assign(textarea().style, fontCss, {
|
|
432
|
+
padding: text.paddingY + "px " + text.paddingX + "px",
|
|
433
|
+
caretColor: text.caretColor,
|
|
434
|
+
tabSize: box.tabSize,
|
|
435
|
+
});
|
|
436
|
+
const variables = { "--code-editor-selection": _s.selection.color, "--code-editor-placeholder": _s.placeholder.color,
|
|
437
|
+
"--code-editor-active-number": _s.gutter.activeTextColor, "--code-editor-bar": _s.scrollBar.color,
|
|
438
|
+
"--code-editor-bar-hover": _s.scrollBar.hoverColor, "--code-editor-bar-size": _s.scrollBar.size + "px" };
|
|
439
|
+
Object.keys(_s.kinds).forEach(function (kind) { variables["--code-editor-" + kind] = _s.kinds[kind]; });
|
|
440
|
+
Object.keys(variables).forEach(function (name) { box.elem.style.setProperty(name, variables[name]); });
|
|
441
|
+
refreshGutterWidth();
|
|
442
|
+
drawVisibleLines(1);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// Everything of a new text
|
|
446
|
+
const showValue = function () {
|
|
447
|
+
lines = [""];
|
|
448
|
+
lineStates = [null];
|
|
449
|
+
validStateCount = 1;
|
|
450
|
+
readValue();
|
|
451
|
+
textarea().scrollTop = 0;
|
|
452
|
+
textarea().scrollLeft = 0;
|
|
453
|
+
box.cursorLine = 1;
|
|
454
|
+
box.cursorColumn = 1;
|
|
455
|
+
refreshGutterWidth();
|
|
456
|
+
drawVisibleLines(1);
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// *** PUBLIC FUNCTIONS:
|
|
460
|
+
|
|
461
|
+
// silent: 1 -> onChange is not called. NOTE: The undo of the browser starts again with a new text.
|
|
462
|
+
box.setValue = function (value, silent = 0) {
|
|
463
|
+
const text = (value === null || value === undefined) ? "" : String(value);
|
|
464
|
+
if (text === textarea().value) return; // the same text: nothing to draw, no onChange
|
|
465
|
+
textarea().value = text;
|
|
466
|
+
showValue();
|
|
467
|
+
if (!silent) tellChange();
|
|
468
|
+
};
|
|
469
|
+
// USAGE: get: editor.value (or editor.getValue()), set: editor.setValue("x = 1\n")
|
|
470
|
+
|
|
471
|
+
box.getValue = function () {
|
|
472
|
+
return textarea().value;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// At the cursor, over the selected text. Undo takes it back.
|
|
476
|
+
box.insertText = function (text) {
|
|
477
|
+
insertAtSelection(String(text));
|
|
478
|
+
};
|
|
479
|
+
// USAGE: editor.insertText("print(x)")
|
|
480
|
+
|
|
481
|
+
box.getSelectedText = function () {
|
|
482
|
+
const elem = textarea();
|
|
483
|
+
return elem.value.slice(elem.selectionStart, elem.selectionEnd);
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
box.setLanguage = function (language) {
|
|
487
|
+
box.language = language;
|
|
488
|
+
validStateCount = 1;
|
|
489
|
+
drawVisibleLines(1);
|
|
490
|
+
};
|
|
491
|
+
// USAGE: editor.setLanguage("python")
|
|
492
|
+
|
|
493
|
+
box.setReadOnly = function (value) {
|
|
494
|
+
box.readOnly = basic.isOn(value) ? 1 : 0;
|
|
495
|
+
textarea().readOnly = (box.readOnly == 1);
|
|
496
|
+
};
|
|
497
|
+
// USAGE: editor.setReadOnly(1)
|
|
498
|
+
|
|
499
|
+
box.setShowLineNumbers = function (value) {
|
|
500
|
+
box.showLineNumbers = basic.isOn(value) ? 1 : 0;
|
|
501
|
+
refreshGutterWidth();
|
|
502
|
+
};
|
|
503
|
+
// USAGE: editor.setShowLineNumbers(0)
|
|
504
|
+
|
|
505
|
+
box.setTabSize = function (size) {
|
|
506
|
+
box.tabSize = size;
|
|
507
|
+
textarea().style.tabSize = size;
|
|
508
|
+
box.codeLayer.css.tabSize = size;
|
|
509
|
+
};
|
|
510
|
+
// USAGE: editor.setTabSize(2)
|
|
511
|
+
|
|
512
|
+
// Puts the cursor at the start of a line (from 1) and shows it.
|
|
513
|
+
box.goToLine = function (lineNumber) {
|
|
514
|
+
const elem = textarea();
|
|
515
|
+
const line = basic.clamp(Math.round(lineNumber), 1, lines.length);
|
|
516
|
+
let place = 0;
|
|
517
|
+
for (let i = 0; i < line - 1; i++) place += lines[i].length + 1;
|
|
518
|
+
elem.focus({ preventScroll: true });
|
|
519
|
+
elem.setSelectionRange(place, place);
|
|
520
|
+
const top = (line - 1) * lineHeight();
|
|
521
|
+
const margin = CARET_MARGIN_LINES * lineHeight();
|
|
522
|
+
const isSeen = (top - margin >= elem.scrollTop && top + lineHeight() + margin <= elem.scrollTop + elem.clientHeight);
|
|
523
|
+
if (!isSeen) elem.scrollTop = Math.max(0, top - elem.clientHeight / 2);
|
|
524
|
+
drawVisibleLines(0);
|
|
525
|
+
readCursor();
|
|
526
|
+
};
|
|
527
|
+
// USAGE: editor.goToLine(120)
|
|
528
|
+
|
|
529
|
+
box.focusEditor = function () {
|
|
530
|
+
textarea().focus({ preventScroll: true });
|
|
531
|
+
};
|
|
532
|
+
// USAGE: editor.focusEditor()
|
|
533
|
+
|
|
534
|
+
// Another style package while it is on the page. A style given by the page stays over it.
|
|
535
|
+
box.setTheme = function (styleName) {
|
|
536
|
+
box.styleName = styleName;
|
|
537
|
+
_s = styleOfPackage(styleName);
|
|
538
|
+
box.style = _s;
|
|
539
|
+
applyLook();
|
|
540
|
+
};
|
|
541
|
+
// USAGE: editor.setTheme("dark")
|
|
542
|
+
|
|
543
|
+
// *** OBJECT VIEW:
|
|
544
|
+
|
|
545
|
+
basic.addCss("code-editor",
|
|
546
|
+
".code-editor-textarea { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 0; border: 0; outline: none;" +
|
|
547
|
+
" resize: none; box-sizing: border-box; background: transparent; color: transparent; -webkit-text-fill-color: transparent;" +
|
|
548
|
+
" white-space: pre; overflow: auto; pointer-events: auto; user-select: text; -webkit-user-select: text; font-variant-ligatures: none; }" +
|
|
549
|
+
".code-editor-textarea::selection { background: var(--code-editor-selection); }" +
|
|
550
|
+
".code-editor-textarea::placeholder { color: var(--code-editor-placeholder); -webkit-text-fill-color: var(--code-editor-placeholder); }" +
|
|
551
|
+
".code-editor-textarea::-webkit-scrollbar { width: var(--code-editor-bar-size); height: var(--code-editor-bar-size); }" +
|
|
552
|
+
".code-editor-textarea::-webkit-scrollbar-thumb { background: var(--code-editor-bar); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }" +
|
|
553
|
+
".code-editor-textarea::-webkit-scrollbar-thumb:hover { background: var(--code-editor-bar-hover); border: 2px solid transparent; background-clip: padding-box; }" +
|
|
554
|
+
".code-editor-textarea::-webkit-scrollbar-corner { background: transparent; }" +
|
|
555
|
+
".code-editor-layer { white-space: pre; font-variant-ligatures: none; overflow: visible; width: max-content; }" +
|
|
556
|
+
".code-editor-active-number { color: var(--code-editor-active-number); }" +
|
|
557
|
+
CodeEditor.KIND_NAMES.map(function (kind) { return ".code-editor-" + kind + " { color: var(--code-editor-" + kind + "); }"; }).join("")
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
// BOX: The line numbers
|
|
561
|
+
box.gutter = startBox({ left: 0, top: 0, height: "100%", css: { boxSizing: "border-box" } });
|
|
562
|
+
|
|
563
|
+
// LABEL: The numbers that are seen
|
|
564
|
+
box.gutterLayer = Label({ top: 0, textAlign: "right" });
|
|
565
|
+
box.gutterLayer.elem.classList.add("code-editor-layer");
|
|
566
|
+
box.gutterLayer.css.left = "auto";
|
|
567
|
+
box.gutterLayer.aria = { hidden: "true" };
|
|
568
|
+
|
|
569
|
+
endBox();
|
|
570
|
+
|
|
571
|
+
// BOX: The code
|
|
572
|
+
box.codeArea = startBox({ top: 0, height: "100%", color: "transparent" });
|
|
573
|
+
|
|
574
|
+
// BOX: The line of the cursor
|
|
575
|
+
box.activeLine = Box({ left: 0, width: "100%" });
|
|
576
|
+
|
|
577
|
+
// LABEL: The colored code that is seen (behind the textarea)
|
|
578
|
+
box.codeLayer = Label({ left: 0, top: 0 });
|
|
579
|
+
box.codeLayer.elem.classList.add("code-editor-layer");
|
|
580
|
+
box.codeLayer.aria = { hidden: "true" };
|
|
581
|
+
|
|
582
|
+
endBox();
|
|
583
|
+
|
|
584
|
+
// TEXTAREA: The typing. A raw element: basic.js has no object of more lines. Its text is transparent, over the colors.
|
|
585
|
+
box.textareaElem = document.createElement("textarea");
|
|
586
|
+
box.textareaElem.classList.add("code-editor-textarea");
|
|
587
|
+
box.textareaElem.wrap = "off";
|
|
588
|
+
box.textareaElem.spellcheck = false;
|
|
589
|
+
box.textareaElem.setAttribute("autocomplete", "off");
|
|
590
|
+
box.textareaElem.setAttribute("autocorrect", "off");
|
|
591
|
+
box.textareaElem.setAttribute("autocapitalize", "off");
|
|
592
|
+
box.textareaElem.setAttribute("aria-label", box.ariaLabel);
|
|
593
|
+
box.textareaElem.placeholder = box.placeholder;
|
|
594
|
+
box.textareaElem.readOnly = (box.readOnly == 1);
|
|
595
|
+
box.textareaElem.value = (box.value === null || box.value === undefined) ? "" : String(box.value);
|
|
596
|
+
box.codeArea.elem.appendChild(box.textareaElem);
|
|
597
|
+
|
|
598
|
+
// *** OBJECT INIT CODE:
|
|
599
|
+
|
|
600
|
+
box.listenTo(textarea(), "input", onInput);
|
|
601
|
+
box.listenTo(textarea(), "scroll", function () { drawVisibleLines(0); });
|
|
602
|
+
box.listenTo(textarea(), "keydown", function (self, event) { onKeyDown(event); });
|
|
603
|
+
box.listenTo(textarea(), "keyup", readCursor);
|
|
604
|
+
box.listenTo(textarea(), "mouseup", readCursor);
|
|
605
|
+
box.listenTo(textarea(), "focus", readCursor);
|
|
606
|
+
box.listenTo(document, "selectionchange", function () {
|
|
607
|
+
if (document.activeElement === textarea()) readCursor();
|
|
608
|
+
});
|
|
609
|
+
// WHY: The first drawing has no height when the box is not on the page yet; a new height shows more lines.
|
|
610
|
+
box.onResize(function () { drawVisibleLines(0); });
|
|
611
|
+
|
|
612
|
+
readValue();
|
|
613
|
+
applyLook();
|
|
614
|
+
|
|
615
|
+
return endObject(box);
|
|
616
|
+
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
620
|
+
|
|
621
|
+
CodeEditor.KIND_NAMES = ["keyword", "string", "number", "comment", "builtin", "function", "property", "tag", "attribute", "variable"];
|
|
622
|
+
|
|
623
|
+
CodeEditor.escapeRegExp = function (text) {
|
|
624
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// [kind, text] as HTML
|
|
628
|
+
CodeEditor.partHtml = function (part) {
|
|
629
|
+
const text = basic.escapeHtml(part[1]);
|
|
630
|
+
return (part[0]) ? '<span class="code-editor-' + part[0] + '">' + text + "</span>" : text;
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
CodeEditor.NUMBER = /^(0[xX][0-9a-fA-F_]+|0[bB][01_]+|\d[\d_]*(\.\d*)?([eE][+-]?\d+)?|\.\d+([eE][+-]?\d+)?)/;
|
|
634
|
+
// WHY the letters of every language: "şif" is one word, not "ş" and the keyword "if".
|
|
635
|
+
CodeEditor.WORD = /^[\p{L}_][\p{L}\p{N}_]*/u;
|
|
636
|
+
CodeEditor.WORD_LETTER = /[\p{L}\p{N}_]/u;
|
|
637
|
+
|
|
638
|
+
// The text from a place to the end of a string, with the letters after a backslash skipped. -1: it does not end here.
|
|
639
|
+
CodeEditor.findStringEnd = function (text, from, mark) {
|
|
640
|
+
let index = from;
|
|
641
|
+
while (index < text.length) {
|
|
642
|
+
if (text[index] === "\\") {
|
|
643
|
+
index += 2;
|
|
644
|
+
} else if (text.startsWith(mark, index)) {
|
|
645
|
+
return index + mark.length;
|
|
646
|
+
} else {
|
|
647
|
+
index++;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return -1;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// The kind of a word by its place
|
|
654
|
+
CodeEditor.kindOfWord = function (word, restOfLine, definition) {
|
|
655
|
+
const lookedUp = (definition.ignoreCase) ? word.toLowerCase() : word;
|
|
656
|
+
if (definition.keywordSet.has(lookedUp)) return "keyword";
|
|
657
|
+
if (definition.builtinSet.has(lookedUp)) return "builtin";
|
|
658
|
+
if (definition.callWords && /^\s*\(/.test(restOfLine)) return "function";
|
|
659
|
+
if (definition.propertyWords && /^\s*:/.test(restOfLine)) return "property";
|
|
660
|
+
return "";
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
// WHY sets, made once: the words are looked up for every word of every line that is drawn.
|
|
664
|
+
CodeEditor.prepareDefinition = function (definition) {
|
|
665
|
+
if (definition.keywordSet) return;
|
|
666
|
+
definition.keywordSet = new Set(definition.keywords || []);
|
|
667
|
+
definition.builtinSet = new Set(definition.builtins || []);
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
// One line: { parts: [[kind, text], ...], state }. state: the end mark of what is still open at the end of the line.
|
|
671
|
+
CodeEditor.tokenizeLine = function (text, state, definition) {
|
|
672
|
+
if (definition.tokenize) return definition.tokenize(text, state);
|
|
673
|
+
CodeEditor.prepareDefinition(definition);
|
|
674
|
+
|
|
675
|
+
const parts = [];
|
|
676
|
+
const add = function (kind, value) {
|
|
677
|
+
if (value.length === 0) return;
|
|
678
|
+
const last = parts[parts.length - 1];
|
|
679
|
+
if (last && last[0] === kind) last[1] += value;
|
|
680
|
+
else parts.push([kind, value]);
|
|
681
|
+
};
|
|
682
|
+
let index = 0;
|
|
683
|
+
let openState = state;
|
|
684
|
+
|
|
685
|
+
// WHAT IS STILL OPEN from the lines before (a comment, a string of many lines)
|
|
686
|
+
if (openState) {
|
|
687
|
+
const isString = (definition.multiLineStrings || []).includes(openState);
|
|
688
|
+
const end = (isString) ? CodeEditor.findStringEnd(text, 0, openState) : text.indexOf(openState);
|
|
689
|
+
const kind = (isString) ? "string" : "comment";
|
|
690
|
+
if (end < 0) {
|
|
691
|
+
add(kind, text);
|
|
692
|
+
return { parts: parts, state: openState };
|
|
693
|
+
}
|
|
694
|
+
const stop = (isString) ? end : end + openState.length;
|
|
695
|
+
add(kind, text.slice(0, stop));
|
|
696
|
+
index = stop;
|
|
697
|
+
openState = null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const lineComment = definition.lineComment;
|
|
701
|
+
const blockComment = definition.blockComment;
|
|
702
|
+
const strings = definition.strings || [];
|
|
703
|
+
const multiLine = definition.multiLineStrings || [];
|
|
704
|
+
|
|
705
|
+
while (index < text.length) {
|
|
706
|
+
const rest = text.slice(index);
|
|
707
|
+
const letter = text[index];
|
|
708
|
+
|
|
709
|
+
if (lineComment && rest.startsWith(lineComment)) {
|
|
710
|
+
add("comment", rest);
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (blockComment && rest.startsWith(blockComment[0])) {
|
|
715
|
+
const end = text.indexOf(blockComment[1], index + blockComment[0].length);
|
|
716
|
+
if (end < 0) {
|
|
717
|
+
add("comment", rest);
|
|
718
|
+
openState = blockComment[1];
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
add("comment", text.slice(index, end + blockComment[1].length));
|
|
722
|
+
index = end + blockComment[1].length;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const stringMark = strings.find(function (mark) { return rest.startsWith(mark); });
|
|
727
|
+
if (stringMark) {
|
|
728
|
+
const end = CodeEditor.findStringEnd(text, index + stringMark.length, stringMark);
|
|
729
|
+
if (end < 0) {
|
|
730
|
+
add("string", rest);
|
|
731
|
+
if (multiLine.includes(stringMark)) openState = stringMark;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
const isProperty = (definition.propertyStrings && /^\s*:/.test(text.slice(end)));
|
|
735
|
+
add((isProperty) ? "property" : "string", text.slice(index, end));
|
|
736
|
+
index = end;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const isAfterWord = (index > 0 && CodeEditor.WORD_LETTER.test(text[index - 1]));
|
|
741
|
+
const numberMatch = (isAfterWord) ? null : CodeEditor.NUMBER.exec(rest);
|
|
742
|
+
if (numberMatch) {
|
|
743
|
+
add("number", numberMatch[0]);
|
|
744
|
+
index += numberMatch[0].length;
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if (definition.decorators && letter === definition.decorators) {
|
|
749
|
+
const decorator = CodeEditor.WORD.exec(rest.slice(1));
|
|
750
|
+
if (decorator) {
|
|
751
|
+
add("function", letter + decorator[0]);
|
|
752
|
+
index += 1 + decorator[0].length;
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (definition.variables && letter === definition.variables) {
|
|
758
|
+
const variable = CodeEditor.WORD.exec(rest.slice(1));
|
|
759
|
+
if (variable) {
|
|
760
|
+
add("variable", letter + variable[0]);
|
|
761
|
+
index += 1 + variable[0].length;
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const wordMatch = CodeEditor.WORD.exec(rest);
|
|
767
|
+
if (wordMatch) {
|
|
768
|
+
const word = wordMatch[0];
|
|
769
|
+
add(CodeEditor.kindOfWord(word, rest.slice(word.length), definition), word);
|
|
770
|
+
index += word.length;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
add("", letter);
|
|
775
|
+
index++;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return { parts: parts, state: openState };
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
// HTML has tags instead of words. state: "-->" (a comment), "tag" (the attributes of a tag go on)
|
|
782
|
+
CodeEditor.tokenizeHtml = function (text, state) {
|
|
783
|
+
const parts = [];
|
|
784
|
+
let index = 0;
|
|
785
|
+
let openState = state;
|
|
786
|
+
|
|
787
|
+
const readTagInside = function () {
|
|
788
|
+
while (index < text.length) {
|
|
789
|
+
const rest = text.slice(index);
|
|
790
|
+
const closing = /^\/?>/.exec(rest);
|
|
791
|
+
if (closing) {
|
|
792
|
+
parts.push(["tag", closing[0]]);
|
|
793
|
+
index += closing[0].length;
|
|
794
|
+
openState = null;
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const attribute = /^[A-Za-z_:@][\w:.-]*/.exec(rest);
|
|
798
|
+
const quoted = /^("[^"]*"?|'[^']*'?)/.exec(rest);
|
|
799
|
+
if (attribute) {
|
|
800
|
+
parts.push(["attribute", attribute[0]]);
|
|
801
|
+
index += attribute[0].length;
|
|
802
|
+
} else if (quoted) {
|
|
803
|
+
parts.push(["string", quoted[0]]);
|
|
804
|
+
index += quoted[0].length;
|
|
805
|
+
} else {
|
|
806
|
+
parts.push(["", text[index]]);
|
|
807
|
+
index++;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
openState = "tag";
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
if (openState === "-->") {
|
|
814
|
+
const end = text.indexOf("-->");
|
|
815
|
+
if (end < 0) return { parts: [["comment", text]], state: "-->" };
|
|
816
|
+
parts.push(["comment", text.slice(0, end + 3)]);
|
|
817
|
+
index = end + 3;
|
|
818
|
+
openState = null;
|
|
819
|
+
} else if (openState === "tag") {
|
|
820
|
+
readTagInside();
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
while (index < text.length) {
|
|
824
|
+
const rest = text.slice(index);
|
|
825
|
+
if (rest.startsWith("<!--")) {
|
|
826
|
+
const end = text.indexOf("-->", index + 4);
|
|
827
|
+
if (end < 0) {
|
|
828
|
+
parts.push(["comment", rest]);
|
|
829
|
+
return { parts: parts, state: "-->" };
|
|
830
|
+
}
|
|
831
|
+
parts.push(["comment", text.slice(index, end + 3)]);
|
|
832
|
+
index = end + 3;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
const opening = /^<\/?[A-Za-z!][\w:-]*/.exec(rest);
|
|
836
|
+
if (opening) {
|
|
837
|
+
parts.push(["tag", opening[0]]);
|
|
838
|
+
index += opening[0].length;
|
|
839
|
+
readTagInside();
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
const nextTag = rest.indexOf("<", 1);
|
|
843
|
+
const stop = (nextTag < 0) ? text.length : index + nextTag;
|
|
844
|
+
parts.push(["", text.slice(index, stop)]);
|
|
845
|
+
index = stop;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
return { parts: parts, state: openState };
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// Ruby has its own parts: :symbols, font_size: values, @variables, #{} in a string, %w[] lists, heredocs and
|
|
852
|
+
// =begin comments. state: "=end" (a =begin comment), "<<~END" or "<<END" (a heredoc and the word that ends it;
|
|
853
|
+
// "~": that word may be indented), "%]" (a %w[ list and its closing letter).
|
|
854
|
+
CodeEditor.RUBY_CLOSERS = { "[": "]", "(": ")", "{": "}", "<": ">" };
|
|
855
|
+
CodeEditor.RUBY_HEREDOC = /^<<([~-]?)(["'`]?)([A-Za-z_]\w*)\2/;
|
|
856
|
+
CodeEditor.RUBY_PERCENT = /^%([wWiIqQ]?)([[({<|!\/])/;
|
|
857
|
+
CodeEditor.RUBY_SYMBOL = /^:[\p{L}_][\p{L}\p{N}_]*[?!]?/u;
|
|
858
|
+
CodeEditor.RUBY_VARIABLE = /^(@@?|\$)[\p{L}_][\p{L}\p{N}_]*/u;
|
|
859
|
+
|
|
860
|
+
CodeEditor.tokenizeRuby = function (text, state) {
|
|
861
|
+
const definition = CodeEditor.languages.ruby;
|
|
862
|
+
CodeEditor.prepareDefinition(definition);
|
|
863
|
+
const parts = [];
|
|
864
|
+
const add = function (kind, value) {
|
|
865
|
+
if (value.length === 0) return;
|
|
866
|
+
const last = parts[parts.length - 1];
|
|
867
|
+
if (last && last[0] === kind) last[1] += value;
|
|
868
|
+
else parts.push([kind, value]);
|
|
869
|
+
};
|
|
870
|
+
let index = 0;
|
|
871
|
+
let openState = state;
|
|
872
|
+
let heredocState = null; // WHY: the text of a heredoc starts on the next line, the rest of this line is code
|
|
873
|
+
let previousWord = "";
|
|
874
|
+
|
|
875
|
+
// A "..." or `...` string: the code in #{} is colored as code. Returns the index after it, -1: it goes on.
|
|
876
|
+
const readInterpolated = function (from, mark) {
|
|
877
|
+
let start = from;
|
|
878
|
+
let at = from + 1;
|
|
879
|
+
while (at < text.length) {
|
|
880
|
+
if (text[at] === "\\") {
|
|
881
|
+
at += 2;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (text[at] === mark) {
|
|
885
|
+
add("string", text.slice(start, at + 1));
|
|
886
|
+
return at + 1;
|
|
887
|
+
}
|
|
888
|
+
const close = (text.startsWith("#{", at)) ? CodeEditor.findRubyBraceEnd(text, at + 2) : -1;
|
|
889
|
+
if (close < 0) {
|
|
890
|
+
at++;
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
add("string", text.slice(start, at));
|
|
894
|
+
add("variable", "#{");
|
|
895
|
+
CodeEditor.tokenizeRuby(text.slice(at + 2, close), null).parts.forEach(function (part) { add(part[0], part[1]); });
|
|
896
|
+
add("variable", "}");
|
|
897
|
+
at = close + 1;
|
|
898
|
+
start = at;
|
|
899
|
+
}
|
|
900
|
+
add("string", text.slice(start));
|
|
901
|
+
return -1;
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// WHAT IS STILL OPEN from the lines before
|
|
905
|
+
if (openState === "=end") {
|
|
906
|
+
add("comment", text);
|
|
907
|
+
return { parts: parts, state: (/^=end\b/.test(text)) ? null : "=end" };
|
|
908
|
+
}
|
|
909
|
+
if (openState && openState.startsWith("<<")) {
|
|
910
|
+
const isIndented = (openState[2] === "~");
|
|
911
|
+
const endWord = openState.slice((isIndented) ? 3 : 2);
|
|
912
|
+
const isEnd = ((isIndented) ? text.trim() : text) === endWord;
|
|
913
|
+
add("string", text);
|
|
914
|
+
return { parts: parts, state: (isEnd) ? null : openState };
|
|
915
|
+
}
|
|
916
|
+
if (openState && openState.startsWith("%")) {
|
|
917
|
+
const end = CodeEditor.findStringEnd(text, 0, openState[1]);
|
|
918
|
+
if (end < 0) {
|
|
919
|
+
add("string", text);
|
|
920
|
+
return { parts: parts, state: openState };
|
|
921
|
+
}
|
|
922
|
+
add("string", text.slice(0, end));
|
|
923
|
+
index = end;
|
|
924
|
+
openState = null;
|
|
925
|
+
}
|
|
926
|
+
if (/^=begin\b/.test(text)) {
|
|
927
|
+
add("comment", text);
|
|
928
|
+
return { parts: parts, state: "=end" };
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
while (index < text.length) {
|
|
932
|
+
const rest = text.slice(index);
|
|
933
|
+
const letter = text[index];
|
|
934
|
+
const before = text.slice(0, index).trimEnd();
|
|
935
|
+
const isAfterValue = /[\p{L}\p{N}_)\]}]$/u.test(before); // WHY: "a %(b)" is a remainder after a value
|
|
936
|
+
|
|
937
|
+
if (letter === "#") {
|
|
938
|
+
add("comment", rest);
|
|
939
|
+
break;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (letter === '"' || letter === "`") {
|
|
943
|
+
const end = readInterpolated(index, letter);
|
|
944
|
+
if (end < 0) break;
|
|
945
|
+
index = end;
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
if (letter === "'") {
|
|
950
|
+
const end = CodeEditor.findStringEnd(text, index + 1, "'");
|
|
951
|
+
const stop = (end < 0) ? text.length : end;
|
|
952
|
+
add("string", text.slice(index, stop));
|
|
953
|
+
index = stop;
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
const percent = CodeEditor.RUBY_PERCENT.exec(rest);
|
|
958
|
+
if (percent && (percent[1] || !isAfterValue)) {
|
|
959
|
+
const closer = CodeEditor.RUBY_CLOSERS[percent[2]] || percent[2];
|
|
960
|
+
const end = CodeEditor.findStringEnd(text, index + percent[0].length, closer);
|
|
961
|
+
if (end < 0) {
|
|
962
|
+
add("string", rest);
|
|
963
|
+
openState = "%" + closer;
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
add("string", text.slice(index, end));
|
|
967
|
+
index = end;
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
const heredoc = CodeEditor.RUBY_HEREDOC.exec(rest);
|
|
972
|
+
const isHeredoc = heredoc && (heredoc[1] || /^[A-Z_]+$/.test(heredoc[3])); // WHY: "list <<item" appends
|
|
973
|
+
if (isHeredoc) {
|
|
974
|
+
add("string", heredoc[0]);
|
|
975
|
+
if (!heredocState) heredocState = "<<" + ((heredoc[1]) ? "~" : "") + heredoc[3];
|
|
976
|
+
index += heredoc[0].length;
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
if (rest.startsWith("::")) {
|
|
981
|
+
add("", "::");
|
|
982
|
+
index += 2;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
const isAfterWord = (index > 0 && CodeEditor.WORD_LETTER.test(text[index - 1]));
|
|
987
|
+
const symbol = (isAfterWord) ? null : CodeEditor.RUBY_SYMBOL.exec(rest); // WHY: "puts :name", not "a:b"
|
|
988
|
+
if (symbol) {
|
|
989
|
+
add("property", symbol[0]);
|
|
990
|
+
index += symbol[0].length;
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const variable = CodeEditor.RUBY_VARIABLE.exec(rest);
|
|
995
|
+
if (variable) {
|
|
996
|
+
add("variable", variable[0]);
|
|
997
|
+
index += variable[0].length;
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
const numberMatch = (isAfterWord) ? null : CodeEditor.NUMBER.exec(rest);
|
|
1002
|
+
if (numberMatch) {
|
|
1003
|
+
add("number", numberMatch[0]);
|
|
1004
|
+
index += numberMatch[0].length;
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
const wordMatch = CodeEditor.WORD.exec(rest);
|
|
1009
|
+
if (wordMatch) {
|
|
1010
|
+
const mark = /^[?!](?!=)/.exec(rest.slice(wordMatch[0].length)); // empty?, save!
|
|
1011
|
+
const word = wordMatch[0] + ((mark) ? mark[0] : "");
|
|
1012
|
+
const after = rest.slice(word.length);
|
|
1013
|
+
const kind = CodeEditor.kindOfRubyWord(word, after, previousWord, definition);
|
|
1014
|
+
const value = (kind === "property") ? word + ":" : word;
|
|
1015
|
+
add(kind, value);
|
|
1016
|
+
index += value.length;
|
|
1017
|
+
previousWord = word;
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
add("", letter);
|
|
1022
|
+
index++;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
return { parts: parts, state: openState || heredocState };
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
// The index of the "}" that closes a #{ (from: after it). -1: not on this line.
|
|
1029
|
+
CodeEditor.findRubyBraceEnd = function (text, from) {
|
|
1030
|
+
let depth = 1;
|
|
1031
|
+
for (let at = from; at < text.length; at++) {
|
|
1032
|
+
if (text[at] === "{") depth++;
|
|
1033
|
+
if (text[at] === "}") depth--;
|
|
1034
|
+
if (depth === 0) return at;
|
|
1035
|
+
}
|
|
1036
|
+
return -1;
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
// The kind of a Ruby word: font_size: is a named value, the word after def a function, a capital a constant.
|
|
1040
|
+
CodeEditor.kindOfRubyWord = function (word, restOfLine, previousWord, definition) {
|
|
1041
|
+
if (/^:(?!:)/.test(restOfLine)) return "property";
|
|
1042
|
+
if (definition.keywordSet.has(word)) return "keyword";
|
|
1043
|
+
if (definition.builtinSet.has(word)) return "builtin";
|
|
1044
|
+
if (previousWord === "def" || /^\(/.test(restOfLine)) return "function";
|
|
1045
|
+
if (/^\p{Lu}/u.test(word)) return "builtin";
|
|
1046
|
+
return "";
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
// *** LANGUAGES:
|
|
1050
|
+
CodeEditor.languages = {
|
|
1051
|
+
|
|
1052
|
+
text: {
|
|
1053
|
+
tokenize: function (line) { return { parts: [["", line]], state: null }; },
|
|
1054
|
+
},
|
|
1055
|
+
|
|
1056
|
+
python: {
|
|
1057
|
+
lineComment: "#",
|
|
1058
|
+
strings: ['"""', "'''", '"', "'"],
|
|
1059
|
+
multiLineStrings: ['"""', "'''"],
|
|
1060
|
+
keywords: ["False", "None", "True", "and", "as", "assert", "async", "await", "break", "class", "continue", "def", "del", "elif", "else", "except", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return", "try", "while", "with", "yield"],
|
|
1061
|
+
builtins: ["abs", "all", "any", "bool", "bytes", "dict", "dir", "enumerate", "filter", "float", "format", "getattr", "hasattr", "input", "int", "isinstance", "iter", "len", "list", "map", "max", "min", "next", "object", "open", "print", "range", "repr", "reversed", "round", "set", "setattr", "sorted", "str", "sum", "super", "tuple", "type", "zip", "self", "cls"],
|
|
1062
|
+
callWords: 1,
|
|
1063
|
+
decorators: "@",
|
|
1064
|
+
indentAfter: ":",
|
|
1065
|
+
},
|
|
1066
|
+
|
|
1067
|
+
javascript: {
|
|
1068
|
+
lineComment: "//",
|
|
1069
|
+
blockComment: ["/*", "*/"],
|
|
1070
|
+
strings: ['"', "'", "`"],
|
|
1071
|
+
multiLineStrings: ["`"],
|
|
1072
|
+
keywords: ["async", "await", "break", "case", "catch", "class", "const", "continue", "default", "delete", "do", "else", "export", "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "let", "new", "null", "of", "return", "static", "super", "switch", "this", "throw", "true", "try", "typeof", "undefined", "var", "void", "while", "yield"],
|
|
1073
|
+
builtins: ["Array", "Boolean", "Date", "Error", "JSON", "Map", "Math", "Number", "Object", "Promise", "RegExp", "Set", "String", "console", "document", "window"],
|
|
1074
|
+
callWords: 1,
|
|
1075
|
+
indentAfter: "{[(",
|
|
1076
|
+
},
|
|
1077
|
+
|
|
1078
|
+
go: {
|
|
1079
|
+
lineComment: "//",
|
|
1080
|
+
blockComment: ["/*", "*/"],
|
|
1081
|
+
strings: ['"', "'", "`"],
|
|
1082
|
+
multiLineStrings: ["`"],
|
|
1083
|
+
keywords: ["break", "case", "chan", "const", "continue", "default", "defer", "else", "fallthrough", "false", "for", "func", "go", "goto", "if", "import", "interface", "iota", "map", "nil", "package", "range", "return", "select", "struct", "switch", "true", "type", "var"],
|
|
1084
|
+
builtins: ["any", "append", "bool", "byte", "cap", "clear", "close", "complex", "copy", "delete", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "len", "make", "max", "min", "new", "panic", "print", "println", "recover", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr"],
|
|
1085
|
+
callWords: 1,
|
|
1086
|
+
indentAfter: "{[(",
|
|
1087
|
+
},
|
|
1088
|
+
|
|
1089
|
+
ruby: {
|
|
1090
|
+
tokenize: CodeEditor.tokenizeRuby,
|
|
1091
|
+
lineComment: "#", // WHY: Ctrl + / comments the lines out with it
|
|
1092
|
+
keywords: ["BEGIN", "END", "__FILE__", "__LINE__", "__method__", "alias", "and", "attr_accessor", "attr_reader", "attr_writer", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "extend", "false", "for", "if", "in", "include", "lambda", "loop", "module", "next", "nil", "not", "or", "prepend", "private", "proc", "protected", "public", "raise", "redo", "require", "require_relative", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while", "yield"],
|
|
1093
|
+
builtins: ["Array", "Float", "Hash", "Integer", "String", "format", "gets", "print", "printf", "puts", "rand", "sleep", "sprintf"],
|
|
1094
|
+
indentAfter: "{[(|",
|
|
1095
|
+
},
|
|
1096
|
+
|
|
1097
|
+
json: {
|
|
1098
|
+
strings: ['"'],
|
|
1099
|
+
keywords: ["true", "false", "null"],
|
|
1100
|
+
propertyStrings: 1,
|
|
1101
|
+
indentAfter: "{[",
|
|
1102
|
+
},
|
|
1103
|
+
|
|
1104
|
+
css: {
|
|
1105
|
+
blockComment: ["/*", "*/"],
|
|
1106
|
+
strings: ['"', "'"],
|
|
1107
|
+
propertyWords: 1,
|
|
1108
|
+
variables: "#", // #fff, #title
|
|
1109
|
+
indentAfter: "{",
|
|
1110
|
+
},
|
|
1111
|
+
|
|
1112
|
+
sql: {
|
|
1113
|
+
lineComment: "--",
|
|
1114
|
+
blockComment: ["/*", "*/"],
|
|
1115
|
+
strings: ["'", '"'],
|
|
1116
|
+
ignoreCase: 1,
|
|
1117
|
+
keywords: ["add", "all", "alter", "and", "as", "asc", "between", "by", "case", "create", "delete", "desc", "distinct", "drop", "else", "end", "exists", "from", "group", "having", "in", "index", "inner", "insert", "into", "is", "join", "key", "left", "like", "limit", "not", "null", "offset", "on", "or", "order", "outer", "primary", "right", "select", "set", "table", "then", "union", "unique", "update", "values", "view", "when", "where"],
|
|
1118
|
+
builtins: ["avg", "count", "max", "min", "sum", "coalesce", "lower", "upper", "integer", "text", "real", "varchar", "boolean", "date"],
|
|
1119
|
+
callWords: 1,
|
|
1120
|
+
indentAfter: "(",
|
|
1121
|
+
},
|
|
1122
|
+
|
|
1123
|
+
bash: {
|
|
1124
|
+
lineComment: "#",
|
|
1125
|
+
strings: ['"', "'"],
|
|
1126
|
+
keywords: ["case", "do", "done", "elif", "else", "esac", "exit", "export", "fi", "for", "function", "if", "in", "local", "return", "set", "then", "until", "while"],
|
|
1127
|
+
builtins: ["cat", "cd", "chmod", "cp", "echo", "find", "grep", "ls", "mkdir", "mv", "pwd", "read", "rm", "sed", "sudo", "touch"],
|
|
1128
|
+
variables: "$",
|
|
1129
|
+
indentAfter: "{(",
|
|
1130
|
+
},
|
|
1131
|
+
|
|
1132
|
+
html: {
|
|
1133
|
+
tokenize: CodeEditor.tokenizeHtml,
|
|
1134
|
+
},
|
|
1135
|
+
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// *** STYLE PACKAGES:
|
|
1139
|
+
// USAGE: CodeEditor({ styleName: "dark" })
|
|
1140
|
+
// USAGE: CodeEditor({ styleName: "dark", style: { kinds: { keyword: "tomato" } } }) // Change only some keys.
|
|
1141
|
+
// NOTE: A new package needs only the keys that differ from the default (light) style.
|
|
1142
|
+
// USAGE: CodeEditor.styles.myStyle = { box: { color: "#FFFDF5" } };
|
|
1143
|
+
CodeEditor.styles = {
|
|
1144
|
+
|
|
1145
|
+
// White, a soft gray for the numbers.
|
|
1146
|
+
light: CodeEditorDefaults.style,
|
|
1147
|
+
|
|
1148
|
+
// For a dark window.
|
|
1149
|
+
dark: {
|
|
1150
|
+
box: { color: "#1C1C1B", borderColor: White(0.1) },
|
|
1151
|
+
text: { color: "#E6E6E3", caretColor: "#FFFFFF" },
|
|
1152
|
+
gutter: { color: "#232322", lineColor: White(0.08), textColor: White(0.38), activeTextColor: White(0.85) },
|
|
1153
|
+
activeLine: { color: White(0.05) },
|
|
1154
|
+
selection: { color: "rgba(111, 198, 205, 0.35)" },
|
|
1155
|
+
placeholder: { color: White(0.42) },
|
|
1156
|
+
scrollBar: { color: White(0.22), hoverColor: White(0.4) },
|
|
1157
|
+
kinds: {
|
|
1158
|
+
keyword: "#D7A2E8",
|
|
1159
|
+
string: "#8FD694",
|
|
1160
|
+
number: "#F0B56A",
|
|
1161
|
+
comment: "#8D939B",
|
|
1162
|
+
builtin: "#6FC6CD",
|
|
1163
|
+
function: "#8CC4EE",
|
|
1164
|
+
property: "#8CC4EE",
|
|
1165
|
+
tag: "#F08FA8",
|
|
1166
|
+
attribute: "#F0B56A",
|
|
1167
|
+
variable: "#6FC6CD",
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
|
|
1171
|
+
};
|