From 52891593ce1c0ca3ceec0134635610143dfe7d9a Mon Sep 17 00:00:00 2001 From: heapwolf Date: Sat, 20 Apr 2024 17:11:22 +0200 Subject: [PATCH] start removing esbuild --- importmap.json | 12 ++ socket.ini | 38 +++++- src/components/confirm.js | 2 +- src/components/editor.js | 4 +- src/components/git-status.js | 2 +- src/components/patch-requests.js | 2 +- src/components/project.js | 2 +- src/components/properties.js | 2 +- src/components/publish.js | 4 +- src/components/relative-date.js | 2 +- src/components/sprite.js | 2 +- src/components/subscribe.js | 4 +- src/components/terminal.js | 8 +- src/css/page-account.css | 9 +- src/db/index.js | 224 ------------------------------- src/git-data.js | 16 +-- src/index.html | 8 +- src/index.js | 6 +- src/pages/account.js | 49 +++---- 19 files changed, 105 insertions(+), 291 deletions(-) create mode 100644 importmap.json delete mode 100644 src/db/index.js diff --git a/importmap.json b/importmap.json new file mode 100644 index 0000000..2019ac7 --- /dev/null +++ b/importmap.json @@ -0,0 +1,12 @@ +{ + "imports": { + "@socketsupply/tonic": "npm:@socketsupply/tonic", + "@socketsupply/components": "npm:@socketsupply/components", + "@socketsupply/components/*": "npm:@socketsupply/components/*", + "@socketsupply/indexed": "npm:@socketsupply/indexed", + "monaco-editor": "npm:monaco-editor", + "xterm": "npm:xterm", + "xterm-addon-fit": "npm:xterm-addon-fit", + "xterm-addon-search": "npm:xterm-addon-search" + } +} diff --git a/socket.ini b/socket.ini index 6a1868a..6dd15b7 100644 --- a/socket.ini +++ b/socket.ini @@ -46,13 +46,43 @@ name = "union" output = "build" ; The build script. It runs before the `[build] copy` phase. -script = "node build.js" +; script = "node build.js" ; Key value pairs added to the envrionment. [env] DEV = true +[build.copy-map] +; +; What node modules to allow +; +importmap.json = importmap.json + +; +; Application Files +; +src/index.html = index.html +src/index.js = index.js +src/vm.js = vm.js +src/preview.js = preview.js +src/worker.js = worker.js +src/git-data.js = git-data.js +src/settings.json = settings.json + +src/components = components +src/views = views +src/fonts = fonts +src/lib = lib +src/pages = pages +src/css = css + +; +; Node modules +; +node_modules = node_modules + + [build.script] ; If true, it will pass build arguments to the build script. WARNING: this could be deprecated in the future. ; default value: false @@ -64,8 +94,9 @@ forward_arguments = false ; Could be a string or an array of strings sources[] = "src" - [webview] +importmap = "/importmap.json" + ; Make root open index.html ; default value: "/" root = "/" @@ -79,7 +110,6 @@ root = "/" watch = true ; Custom headers injected on all webview routes -[webview] ; default value: "" ; headers[] = "X-Custom-Header: Some-Value" @@ -99,6 +129,8 @@ $HOST_HOME = /user/home allowed[] = "https://*.stripe.com/*" allowed[] = "https://stripe.com/*" allowed[] = "https://*.stripe.network/*" +allowed[] = "https://*.stripecdn.com/*" +allowed[] = "https://newassets.hcaptcha.com/*" [permissions] ; Allow/Disallow fullscreen in application diff --git a/src/components/confirm.js b/src/components/confirm.js index 0f29a77..36c4f15 100644 --- a/src/components/confirm.js +++ b/src/components/confirm.js @@ -1,4 +1,4 @@ -import { TonicDialog } from '@socketsupply/components/dialog' +import { TonicDialog } from 'npm:@socketsupply/components/dialog.js' class DialogConfirm extends TonicDialog { async prompt (opts) { diff --git a/src/components/editor.js b/src/components/editor.js index ba81cea..d293c65 100644 --- a/src/components/editor.js +++ b/src/components/editor.js @@ -2,8 +2,8 @@ import fs from 'socket:fs' import path from 'socket:path' import { sha256 } from 'socket:network' -import * as monaco from 'monaco-editor' -import Tonic from '@socketsupply/tonic' +import * as monaco from 'npm:monaco-editor' +import Tonic from 'npm:@socketsupply/tonic' function rgbaToHex (rgbaString) { const rgbaValues = rgbaString.match(/\d+/g) diff --git a/src/components/git-status.js b/src/components/git-status.js index 8e5147f..204a024 100644 --- a/src/components/git-status.js +++ b/src/components/git-status.js @@ -1,4 +1,4 @@ -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' import { exec } from 'socket:child_process' class GitStatus extends Tonic { diff --git a/src/components/patch-requests.js b/src/components/patch-requests.js index 01ae287..ce54d97 100644 --- a/src/components/patch-requests.js +++ b/src/components/patch-requests.js @@ -1,4 +1,4 @@ -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' import path from 'socket:path' import fs from 'socket:fs' import { exec } from 'socket:child_process' diff --git a/src/components/project.js b/src/components/project.js index 98c0e58..2d84187 100644 --- a/src/components/project.js +++ b/src/components/project.js @@ -4,7 +4,7 @@ import path from 'socket:path' import { lookup } from 'socket:mime' import { cp, rm } from '../lib/fs.js' -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' const EXPANDED_STATE = 1 const CLOSED_STATE = 0 diff --git a/src/components/properties.js b/src/components/properties.js index 3f8e7e7..79dd41a 100644 --- a/src/components/properties.js +++ b/src/components/properties.js @@ -1,4 +1,4 @@ -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' import process from 'socket:process' import Config from '../lib/config.js' diff --git a/src/components/publish.js b/src/components/publish.js index a47e3d9..07c8838 100644 --- a/src/components/publish.js +++ b/src/components/publish.js @@ -2,8 +2,8 @@ import fs from 'socket:fs' import path from 'socket:path' import { exec, execSync } from 'socket:child_process' -import Tonic from '@socketsupply/tonic' -import { TonicDialog } from '@socketsupply/components/dialog' +import Tonic from 'npm:@socketsupply/tonic' +import { TonicDialog } from 'npm:@socketsupply/components/dialog' export class DialogPublish extends TonicDialog { click (e) { diff --git a/src/components/relative-date.js b/src/components/relative-date.js index 9837df1..e3aa289 100644 --- a/src/components/relative-date.js +++ b/src/components/relative-date.js @@ -1,4 +1,4 @@ -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' const T_YEARS = 1000 * 60 * 60 * 24 * 365 const T_MONTHS = 1000 * 60 * 60 * 24 * 30 diff --git a/src/components/sprite.js b/src/components/sprite.js index cb0554f..982daa8 100644 --- a/src/components/sprite.js +++ b/src/components/sprite.js @@ -1,4 +1,4 @@ -import Tonic from '@socketsupply/tonic' +import Tonic from 'npm:@socketsupply/tonic' class AppSprite extends Tonic { render () { diff --git a/src/components/subscribe.js b/src/components/subscribe.js index a5c4b56..b3130e9 100644 --- a/src/components/subscribe.js +++ b/src/components/subscribe.js @@ -2,8 +2,8 @@ import fs from 'socket:fs' import path from 'socket:path' import { Encryption, sha256 } from 'socket:network' -import Tonic from '@socketsupply/tonic' -import { TonicDialog } from '@socketsupply/components/dialog' +import Tonic from 'npm:@socketsupply/tonic' +import { TonicDialog } from 'npm:@socketsupply/components/dialog' export class DialogSubscribe extends TonicDialog { async show () { diff --git a/src/components/terminal.js b/src/components/terminal.js index 9a64030..67d7070 100644 --- a/src/components/terminal.js +++ b/src/components/terminal.js @@ -1,7 +1,7 @@ -import Tonic from '@socketsupply/tonic' -import { Terminal } from 'xterm' -import { FitAddon as Resizer } from 'xterm-addon-fit' -import { SearchAddon as Search } from 'xterm-addon-search' +import Tonic from 'npm:@socketsupply/tonic' +import { Terminal } from 'npm:xterm' +import { FitAddon as Resizer } from 'npm:xterm-addon-fit' +import { SearchAddon as Search } from 'npm:xterm-addon-search' // const SECOND = 1000 // const MAX_ROWS = 30 * SECOND diff --git a/src/css/page-account.css b/src/css/page-account.css index bd9b06a..3a4eaa4 100644 --- a/src/css/page-account.css +++ b/src/css/page-account.css @@ -10,8 +10,7 @@ body { display: flex; justify-content: center; align-content: center; - height: 100vh; - width: 100vw; + overflow: hidden; } form { @@ -30,8 +29,10 @@ form { #card-element { padding: 10px; - border: 1px solid #ccc; - border-radius: 5px; + border: 1px solid var(--tonic-border); + border-radius: 4px; + width: 100%; + height: 42px; } .StripeElement { diff --git a/src/db/index.js b/src/db/index.js deleted file mode 100644 index 6a3cb24..0000000 --- a/src/db/index.js +++ /dev/null @@ -1,224 +0,0 @@ -const getStore = (db, loc, type = 'readwrite') => { - const tx = db.transaction(loc, type) - return { tx, store: tx.objectStore(loc) } -} - -const getRange = o => { - const exLower = typeof o.lt !== 'undefined' - const exUpper = typeof o.gt !== 'undefined' - - const range = window.IDBKeyRange - - if ((o.lte || o.lt) && (o.gte || o.gt)) { - const args = [ - o.gte || o.gt, - o.lte || o.lt, - exLower, - exUpper - ] - - return range.bound(...args) - } - - if (o.lte || o.lt) { - return range.upperBound(o.lte || o.lt, exLower) - } - - if (o.gte || o.gt) { - return range.lowerBound(o.gte || o.gt, exUpper) - } -} - -export class Indexed { - constructor (loc) { - this._loc = loc - this._db = null - } - - static async open (...args) { - const indexed = new Indexed(...args) - return await indexed.init() - } - - static async drop (loc) { - return new Promise(resolve => { - const r = window.indexedDB.deleteDatabase(loc) - r.onsuccess = () => resolve({ data: true }) - r.onerror = event => resolve({ err: event.target }) - r.onblocked = event => resolve({ err: event.target }) - }) - } - - init () { - return new Promise(resolve => { - const r = window.indexedDB.open(this._loc) - const loc = this._loc - - r.onerror = event => { - throw event.target - } - - r.onupgradeneeded = (event) => { - this._db = event.target.result - const opts = { keyPath: 'key' } - const store = this._db.createObjectStore(loc, opts) - - store.transaction.oncomplete = event => { - resolve(this) - } - } - - r.onsuccess = (event) => { - this._db = event.target.result - resolve(this) - } - }) - } - - count () { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc) - const r = store.count() - r.onsuccess = () => resolve({ data: r.result || 0 }) - r.onerror = event => resolve({ err: event.target }) - r.onblocked = event => resolve({ err: event.target }) - }) - } - - has (key) { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc) - const r = store.get(key) - r.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - resolve({ err: event.target }) - } - r.onsuccess = function (event) { - resolve({ data: typeof this.result !== 'undefined' }) - } - }) - } - - get (key) { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc, 'readonly') - const r = store.get(key) - r.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - resolve({ err: event.target }) - } - r.onsuccess = function (event) { - if (typeof this.result === 'undefined') { - return resolve({ err: new Error('Not Found') }) - } - resolve({ data: this.result.value }) - } - }) - } - - put (key, value) { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc) - const r = store.put({ key, value }) - r.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - resolve({ err: event.target }) - } - r.onsuccess = event => resolve({}) - }) - } - - del (key) { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc) - const r = store.delete(key) - r.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - resolve({ err: event.target }) - } - r.onsuccess = event => resolve({}) - }) - } - - batch (ops) { - return new Promise(resolve => { - const { tx, store } = getStore(this._db, this._loc) - tx.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - resolve({ err: event.target }) - } - tx.oncomplete = event => resolve({}) - - const eachOp = op => { - if (op.type === 'put') { - store.put({ key: op.key, value: op.value }) - } - - if (op.type === 'del') { - store.delete(op.key) - } - } - - ops.forEach(eachOp) - }) - } - - readAll (opts) { - return new Promise(resolve => { - this.read(opts).then(({ events }) => { - const rows = new Map() - events.onerror = err => { - if (Indexed.onerror) Indexed.onerror(err) - resolve({ err }) - } - events.ondata = (key, value) => rows.set(key, value) - events.onend = () => resolve({ data: rows }) - }) - }) - } - - read (opts = {}) { - return new Promise(resolve => { - const { store } = getStore(this._db, this._loc, 'readonly') - const r = store.openCursor(getRange(opts), opts.reverse ? 'prevunique' : undefined) - const events = {} - let count = 0 - resolve({ events }) - - function onError (event) { - if (Indexed.onerror) Indexed.onerror(event.target) - if (events.onerror) events.onerror(event.target) - } - - async function onSuccess (event) { - const cursor = event.target.result - - if (cursor) { - const r = store.get(this.result.key) - - r.onerror = event => { - if (Indexed.onerror) Indexed.onerror(event.target) - if (events.onerror) events.onerror(event.target) - } - - r.onsuccess = function (event) { - if (events.ondata) events.ondata(this.result.key, this.result.value) - - if (opts.limit && (count++ === (opts.limit - 1))) { - if (events.onend) return events.onend() - return - } - cursor.continue() - } - } else { - if (events.onend) events.onend() - } - } - - r.onerror = onError - r.onsuccess = onSuccess - }) - } -} - -export default Indexed diff --git a/src/git-data.js b/src/git-data.js index 188bfa9..c8ec2fa 100644 --- a/src/git-data.js +++ b/src/git-data.js @@ -82,33 +82,26 @@ export class Patch { let capturingFile = false let currentHunk = null - // Adjusted regex for file section detection const fileSectionRegex = new RegExp(`^diff --git a/${filePath.replace(/\./g, '\\.')} b/${filePath.replace(/\./g, '\\.')}`) - - // Adjusted regex for hunk header detection const hunkHeaderRegex = /^@@ -\d+(,\d+)? \+\d+(,\d+)? @@/ lines.forEach(line => { if (fileSectionRegex.test(line)) { capturingFile = true - return // Skip the diff --git line itself + return } else if (capturingFile && line.startsWith('diff --git')) { - capturingFile = false // Stop capturing when a new file section starts + capturingFile = false } if (capturingFile) { const match = hunkHeaderRegex.exec(line) if (match) { - // Start of a new hunk currentHunk = { headers: [match[0]], changes: [] } hunks.push(currentHunk) - // Check if there's additional content on the same line following the hunk header if (match[0].length < line.length) { - // Add the remaining part of the line to the changes currentHunk.changes.push(' ' + line.substring(match[0].length).trim()) } } else if (currentHunk) { - // Add non-header lines to the current hunk's changes currentHunk.changes.push(line) } } @@ -117,8 +110,3 @@ export class Patch { return hunks } } - -// const p = new Patch(fs.readFileSync('0001-wip-ui.patch', 'utf8')) -// const di = p.extractHunks('src/components/git-status.js') - -// console.log(di) diff --git a/src/index.html b/src/index.html index d1cbffd..6f9731f 100644 --- a/src/index.html +++ b/src/index.html @@ -1,13 +1,12 @@ - + + + diff --git a/src/index.js b/src/index.js index fd13c70..96a8a9d 100644 --- a/src/index.js +++ b/src/index.js @@ -7,9 +7,9 @@ import vm from 'socket:vm' import { inspect, format } from 'socket:util' import { spawn, exec } from 'socket:child_process' -import Tonic from '@socketsupply/tonic' -import components from '@socketsupply/components' -import Indexed from '@socketsupply/indexed' +import Tonic from 'npm:@socketsupply/tonic' +import components from 'npm:@socketsupply/components' +import Indexed from 'npm:@socketsupply/indexed' import { Patch } from './git-data.js' import { cp, rm } from './lib/fs.js' diff --git a/src/pages/account.js b/src/pages/account.js index eaae086..744541f 100644 --- a/src/pages/account.js +++ b/src/pages/account.js @@ -1,36 +1,39 @@ +import Tonic from '@socketsupply/tonic' +import components from '@socketsupply/components' + +components(Tonic) + +console.log(Tonic) + const sharedKeys = { test: 'pk_test_51JpgUIFV3Il51eBDUO1s6JVOy9P3rFCkvX1Mbjvq4Qtkrj0ARg0CmXtYnpecsTyliVwvSJnEOOQXqUo0w48EKOP000oEdk14R2', live: 'pk_live_51JpgUIFV3Il51eBDWQworOndEE0S5T2HUqjowum8lPhSfpaboVz5iJlS1PfsWicfNtdUhTZhPSYtpJpZgI9Jc40800MkE0liSP' } window.addEventListener('DOMContentLoaded', e => { - setTimeout(() => { - const url = new URL(globalThis.location.href) - const key = url.searchParams.get('dev') === 'true' ? sharedKeys.test : sharedKeys.live - const stripe = Stripe(key) + const url = new URL(globalThis.location.href) + const key = url.searchParams.get('dev') === 'true' ? sharedKeys.test : sharedKeys.live + const stripe = Stripe(key) + const elements = stripe.elements() + const card = elements.create('card') - const elements = stripe.elements() + card.mount('#card-element') - const card = elements.create('card') + const submitButton = document.getElementById('submit') - card.mount('#card-element') + submitButton.addEventListener('click', async event => { + event.preventDefault() - const submitButton = document.getElementById('submit') - - submitButton.addEventListener('click', async event => { - event.preventDefault() - - const result = await stripe.createPaymentMethod({ - type: 'card', - card: card - }) + const result = await stripe.createPaymentMethod({ + type: 'card', + card: card + }) - if (result.error) { - console.log(result.error.message) - return - } + if (result.error) { + console.log(result.error.message) + return + } - console.log('TOKEN!', result.paymentMethod.id) - }) - }, 2048) + console.log('TOKEN!', result.paymentMethod.id) + }) })