Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions bin/build-phar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ set -e

CLI_DIR="src/cli"

restore_cli_package() {
composer config repositories --unset --working-dir="$CLI_DIR"
rm -rf "$CLI_DIR/vendor"
}

trap restore_cli_package EXIT

composer config repositories.local-etl '{"type": "path", "url": "../core/etl", "options": {"symlink": false}}' --working-dir="$CLI_DIR"
composer config repositories.local-adapter-csv '{"type": "path", "url": "../adapter/etl-adapter-csv", "options": {"symlink": false}}' --working-dir="$CLI_DIR"
composer config repositories.local-adapter-parquet '{"type": "path", "url": "../adapter/etl-adapter-parquet", "options": {"symlink": false}}' --working-dir="$CLI_DIR"
Expand All @@ -29,8 +36,5 @@ rm -rf "$CLI_DIR/vendor"

composer update --no-dev --working-dir="$CLI_DIR"

tools/box/vendor/bin/box compile --config "$CLI_DIR/box.json"

composer config repositories --unset --working-dir="$CLI_DIR"

rm -rf "$CLI_DIR/vendor"
# Box runs composer in a temporary directory, where a composer wrapper that reads secrets finds no configuration
COMPOSER_AUTH="${COMPOSER_AUTH:-"{}"}" tools/box/vendor/bin/box compile --config "$CLI_DIR/box.json"
1 change: 1 addition & 0 deletions phpdoc/.phpdoc/template/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.23.0/plugins/line-highlight/prism-line-highlight.css">
{% endblock %}
{% block javascripts %}
<script src="/posthog.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@3.4.6"></script>
<script src="https://cdn.jsdelivr.net/npm/css-vars-ponyfill@2"></script>
<script src="js/template.js"></script>
Expand Down
6 changes: 5 additions & 1 deletion web/landing/assets/controllers/clipboard_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ClipboardJS from 'clipboard';

export default class extends Controller
{
static values = { kind: String }

connect()
{
if (!ClipboardJS.isSupported()) {
Expand All @@ -18,6 +20,8 @@ export default class extends Controller

this.element.classList.add('copied');
setTimeout(() => this.element.classList.remove('copied'), 2000);

window.posthog?.capture('site:code_copy', { code_kind: this.kindValue });
});
}
}
}
11 changes: 10 additions & 1 deletion web/landing/assets/controllers/code_editor_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller } from "@hotwired/stimulus"
import { EditorView, basicSetup } from "codemirror"
import { EditorState, StateField, StateEffect, Compartment, Prec } from "@codemirror/state"
import { EditorState, StateField, StateEffect, Compartment, Prec, Transaction } from "@codemirror/state"
import { Decoration } from "@codemirror/view"
import { keymap } from "@codemirror/view"
import { php } from "@codemirror/lang-php"
Expand All @@ -17,6 +17,7 @@ export default class extends Controller {
#textarea
#errorEffect
#editorReady = false
#codeModified = false
#themeCompartment = new Compartment()
#onThemeChanged = null

Expand Down Expand Up @@ -74,6 +75,10 @@ export default class extends Controller {
flowTooltips,
EditorView.updateListener.of((update) => {
if (update.docChanged) {
if (update.transactions.some(transaction => transaction.annotation(Transaction.userEvent) !== undefined)) {
this.#codeModified = true
}

this.#textarea.value = update.state.doc.toString()
this.dispatch('code-changed', { bubbles: true })
}
Expand Down Expand Up @@ -143,6 +148,10 @@ export default class extends Controller {
}
}

isCodeModified() {
return this.#codeModified
}

getCode() {
return this.#editor ? this.#editor.state.doc.toString() : ''
}
Expand Down
12 changes: 12 additions & 0 deletions web/landing/assets/controllers/playground_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Controller } from "@hotwired/stimulus"

const POSTHOG_EVENTS = {
'wasm:runtime-load': 'playground:runtime_load',
'playground-run:code-run': 'playground:code_run',
'playground-share:snippet-share': 'playground:snippet_share',
'playground-share:snippet-open': 'playground:snippet_open',
'playground-upload:file-upload': 'playground:file_upload',
}

export default class extends Controller {
static outlets = ["wasm", "code-editor", "turnstile", "playground-output", "playground-tabs"]
static targets = ["loadingMessage", "loadingBar", "loadingPercent", "navigation", "editor", "outputContainer", "storageIndicator", "actionSpinner"]
Expand All @@ -13,6 +21,10 @@ export default class extends Controller {
this.#log('Connecting playground controller')
}

capture({ type, detail }) {
window.posthog?.capture(POSTHOG_EVENTS[type], detail)
}

onNotification(event) {
const { message, type } = event.detail
if (this.hasPlaygroundOutputOutlet) {
Expand Down
11 changes: 9 additions & 2 deletions web/landing/assets/controllers/playground_run_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static outlets = ["code-editor", "wasm", "playground-output"]
static values = { isExample: { type: Boolean, default: false } }

async run() {
this.dispatch('action-started', { bubbles: true })
Expand Down Expand Up @@ -37,8 +38,14 @@ export default class extends Controller {
}
}

this.dispatch('executed', {
detail: { success: result.success, executionTime: result.executionTime },
this.dispatch('code-run', {
detail: {
is_success: result.success,
duration_ms: result.executionTime,
failure_reason: result.failureReason,
is_example: this.isExampleValue,
is_code_modified: this.codeEditorOutlet.isCodeModified()
},
bubbles: true
})
} finally {
Expand Down
51 changes: 28 additions & 23 deletions web/landing/assets/controllers/playground_share_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default class extends Controller {
#wasmResourcesLoaded = false
#pendingSnippetLoad = false
#defaultFingerprint = null
#exampleCodeModified = false
#boundHandleExampleLoaded = null

connect() {
this.#debug = this.application.debug
Expand All @@ -24,25 +22,12 @@ export default class extends Controller {

this.#boundHandleCodeChanged = this.#handleCodeChanged.bind(this)
this.element.addEventListener('code-editor:code-changed', this.#boundHandleCodeChanged)

this.#boundHandleExampleLoaded = this.#handleExampleLoaded.bind(this)
this.element.addEventListener('playground-storage:loaded-from-example', this.#boundHandleExampleLoaded)
}

disconnect() {
if (this.#boundHandleCodeChanged) {
this.element.removeEventListener('code-editor:code-changed', this.#boundHandleCodeChanged)
}
if (this.#boundHandleExampleLoaded) {
this.element.removeEventListener('playground-storage:loaded-from-example', this.#boundHandleExampleLoaded)
}
}

#handleExampleLoaded() {
// Reset the modified flag when example is initially loaded
// This prevents the initial setCode() call from marking example as modified
this.#exampleCodeModified = false
this.#log('Example loaded, reset exampleCodeModified flag')
}

async onWasmResourcesLoaded() {
Expand Down Expand Up @@ -130,6 +115,8 @@ export default class extends Controller {
}

async #loadSnippetFromR2(snippetId) {
let failureReason = 'other'

try {
const snippetsBaseUrl = this.snippetsUrlValue
const baseUrl = `${snippetsBaseUrl}/snippets/${snippetId}`
Expand All @@ -139,19 +126,22 @@ export default class extends Controller {

const metadataResponse = await fetch(metadataUrl)
if (!metadataResponse.ok) {
failureReason = 'not_found'
throw new Error(`Snippet not found (HTTP ${metadataResponse.status})`)
}

const metadata = await metadataResponse.json()

const expiresAt = new Date(metadata.expires_at)
if (Date.now() > expiresAt.getTime()) {
failureReason = 'expired'
throw new Error('Snippet has expired')
}

const codeUrl = `${baseUrl}/code.php`
const codeResponse = await fetch(codeUrl)
if (!codeResponse.ok) {
failureReason = 'code_missing'
throw new Error('Code file not found')
}
const code = await codeResponse.text()
Expand All @@ -177,6 +167,7 @@ export default class extends Controller {

if (!this.wasmOutlet.areResourcesLoaded()) {
this.#showNotification('WASM resources failed to load, datasets not loaded', 'error')
this.#reportOpen(null)
return
}
this.#log('WASM resources loaded, proceeding with dataset upload')
Expand Down Expand Up @@ -233,8 +224,9 @@ export default class extends Controller {
this.#showNotification('Snippet loaded successfully!', 'success')

this.#snippetLoaded = true

this.#reportOpen(null)
} catch (error) {
this.#reportOpen(failureReason)
console.error('[ShareCode] Failed to load snippet:', error)
this.#showNotification(`Failed to load snippet: ${error.message}`, 'error')
}
Expand All @@ -243,20 +235,23 @@ export default class extends Controller {
async share() {
this.dispatch('action-started', { bubbles: true })

let files = []

try {
// First, wait only for code-editor and wasm (NOT turnstile yet)
await Promise.all([
this.codeEditorOutlet.onLoad(),
this.wasmOutlet.onLoad()
])

const files = await this.#collectUploadedFiles()
files = await this.#collectUploadedFiles()

// Check for unmodified example BEFORE requiring Turnstile
if (this.isExampleValue && !this.#exampleCodeModified && files.length === 0) {
if (this.isExampleValue && !this.codeEditorOutlet.isCodeModified() && files.length === 0) {
const exampleUrl = `${window.location.origin}${window.location.pathname}`
await this.#copyToClipboard(exampleUrl)
this.#showNotification('Example link copied to clipboard!', 'success', exampleUrl)
this.#reportShare('example_link', files.length)
return
}

Expand All @@ -275,6 +270,7 @@ export default class extends Controller {
if (this.#defaultFingerprint && fingerprint === this.#defaultFingerprint) {
this.#log('Code matches default, not uploading')
this.#showNotification('You are trying to share default code. Please modify the code first.', 'info')
this.#reportShare('refused', files.length)
return
}

Expand All @@ -293,11 +289,14 @@ export default class extends Controller {

await this.#copyToClipboard(shareUrl)
this.#showNotification('Snippet already exists! Link copied to clipboard.', 'success', shareUrl)
this.#reportShare('exists', files.length)
return
}

await this.#uploadSnippetToAPI(code, fingerprint, files)
this.#reportShare('created', files.length)
} catch (error) {
this.#reportShare('failed', files.length)
console.error('[ShareCode] Share failed:', error)
console.error('[ShareCode] Error stack:', error.stack)
this.#logError('[ShareCode] Share failed:', error)
Expand Down Expand Up @@ -378,12 +377,18 @@ export default class extends Controller {
}
}

#handleCodeChanged() {
// Mark example as modified when code changes
if (this.isExampleValue) {
this.#exampleCodeModified = true
}
#reportShare(outcome, fileCount) {
this.dispatch('snippet-share', { detail: { outcome, file_count: fileCount }, bubbles: true })
}

#reportOpen(failureReason) {
this.dispatch('snippet-open', {
detail: { is_success: failureReason === null, failure_reason: failureReason },
bubbles: true
})
}

#handleCodeChanged() {
if (this.#snippetLoaded) {
this.#log('Code changed, clearing snippet URL from browser')
const cleanUrl = `${window.location.origin}${window.location.pathname}`
Expand Down
23 changes: 20 additions & 3 deletions web/landing/assets/controllers/playground_upload_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class extends Controller {
const validation = this.#validate(file)
if (!validation.valid) {
this.playgroundOutputOutlet.show({ content: validation.error, type: 'error' })
this.#reportUpload(file, validation.failureReason)
return
}

Expand All @@ -42,6 +43,22 @@ export default class extends Controller {
this.playgroundOutputOutlet.show({ content: `File uploaded: ${file.name}`, type: 'success' })
this.dispatch('file-uploaded', { detail: { filename: file.name, size: file.size }, bubbles: true })
}

this.#reportUpload(file, result.success ? null : 'write')
}

#reportUpload(file, failureReason) {
const extension = file.name.split('.').pop().toLowerCase()

this.dispatch('file-upload', {
detail: {
is_success: failureReason === null,
file_extension: this.allowedExtensionsValue.includes(extension) ? extension : 'other',
file_size: file.size,
failure_reason: failureReason
},
bubbles: true
})
}

async handleFileUpload(event) {
Expand Down Expand Up @@ -96,16 +113,16 @@ export default class extends Controller {
#validate(file) {
const filenameCheck = this.#validateFilename(file.name)
if (!filenameCheck.valid) {
return filenameCheck
return { ...filenameCheck, failureReason: 'filename' }
}

if (file.size > this.maxFileSizeValue) {
return { valid: false, error: `File too large: ${file.name} (max 2MB)` }
return { valid: false, error: `File too large: ${file.name} (max 2MB)`, failureReason: 'size' }
}

const ext = file.name.split('.').pop().toLowerCase()
if (!this.allowedExtensionsValue.includes(ext)) {
return { valid: false, error: `Invalid extension: ${ext}` }
return { valid: false, error: `Invalid extension: ${ext}`, failureReason: 'extension' }
}

return { valid: true }
Expand Down
Loading
Loading