@php-script/editor-svelte 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PhpScriptEditor.svelte +107 -0
- package/dist/PhpScriptEditor.svelte.d.ts +40 -0
- package/dist/PhpScriptEditor.svelte.d.ts.map +1 -0
- package/dist/elements.d.ts +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/load.d.ts +3 -0
- package/dist/load.d.ts.map +1 -0
- package/dist/load.js +3 -0
- package/package.json +51 -3
- package/README.md +0 -3
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
LintDiagnostic,
|
|
4
|
+
PhpScriptConfig,
|
|
5
|
+
PhpScriptEditor as PhpScriptEditorElement,
|
|
6
|
+
PhpScriptTheme,
|
|
7
|
+
SaveMethod,
|
|
8
|
+
SaveResult,
|
|
9
|
+
ThemeMode,
|
|
10
|
+
} from '@php-script/editor';
|
|
11
|
+
import { applyChangedProps } from '@php-script/editor/core';
|
|
12
|
+
import { onMount } from 'svelte';
|
|
13
|
+
import { loadPhpScriptEditor } from './load.js';
|
|
14
|
+
|
|
15
|
+
type MonacoEditor = NonNullable<PhpScriptEditorElement['editor']>;
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
value?: string;
|
|
19
|
+
config?: PhpScriptConfig | string | null;
|
|
20
|
+
configUrl?: string;
|
|
21
|
+
saveUrl?: string;
|
|
22
|
+
saveMethod?: SaveMethod;
|
|
23
|
+
saveField?: string;
|
|
24
|
+
saveHeaders?: Record<string, string>;
|
|
25
|
+
savePayload?: Record<string, unknown>;
|
|
26
|
+
persisted?: boolean;
|
|
27
|
+
csrfToken?: string;
|
|
28
|
+
lintUrl?: string;
|
|
29
|
+
lintDelay?: number;
|
|
30
|
+
theme?: ThemeMode | PhpScriptTheme;
|
|
31
|
+
readonly?: boolean;
|
|
32
|
+
name?: string;
|
|
33
|
+
options?: Record<string, unknown>;
|
|
34
|
+
labels?: Record<string, string>;
|
|
35
|
+
noToolbar?: boolean;
|
|
36
|
+
noSaveShortcut?: boolean;
|
|
37
|
+
/** CSS height, e.g. `24rem`. */
|
|
38
|
+
height?: string;
|
|
39
|
+
class?: string;
|
|
40
|
+
/** The custom element (bindable). */
|
|
41
|
+
element?: PhpScriptEditorElement | null;
|
|
42
|
+
onchange?: (value: string) => void;
|
|
43
|
+
onready?: (editor: MonacoEditor, element: PhpScriptEditorElement) => void;
|
|
44
|
+
onsavestart?: (event: CustomEvent) => void;
|
|
45
|
+
onsaved?: (result: SaveResult & { value: string }) => void;
|
|
46
|
+
onsaveerror?: (error: Error) => void;
|
|
47
|
+
ondiagnostics?: (diagnostics: LintDiagnostic[]) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
value = $bindable(''),
|
|
52
|
+
element = $bindable(null),
|
|
53
|
+
height,
|
|
54
|
+
class: className,
|
|
55
|
+
onchange,
|
|
56
|
+
onready,
|
|
57
|
+
onsavestart,
|
|
58
|
+
onsaved,
|
|
59
|
+
onsaveerror,
|
|
60
|
+
ondiagnostics,
|
|
61
|
+
...rest
|
|
62
|
+
}: Props = $props();
|
|
63
|
+
|
|
64
|
+
// Push props to element properties (objects pass without JSON).
|
|
65
|
+
// Only changed props, so the element's own updates (persisted, saveUrl after POST) survive.
|
|
66
|
+
const synced = new Map<string, unknown>();
|
|
67
|
+
$effect(() => {
|
|
68
|
+
if (element) applyChangedProps(element, { ...rest }, synced);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
$effect(() => {
|
|
72
|
+
if (element && value !== undefined && element.value !== value) element.value = value;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
onMount(() => {
|
|
76
|
+
const el = element!;
|
|
77
|
+
const listeners: Array<[string, (event: Event) => void]> = [
|
|
78
|
+
[
|
|
79
|
+
'ps-change',
|
|
80
|
+
(e) => {
|
|
81
|
+
value = (e as CustomEvent<{ value: string }>).detail.value;
|
|
82
|
+
onchange?.(value);
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
'ps-ready',
|
|
87
|
+
(e) => onready?.((e as CustomEvent<{ editor: MonacoEditor }>).detail.editor, el),
|
|
88
|
+
],
|
|
89
|
+
['ps-save-start', (e) => onsavestart?.(e as CustomEvent)],
|
|
90
|
+
['ps-saved', (e) => onsaved?.((e as CustomEvent<SaveResult & { value: string }>).detail)],
|
|
91
|
+
['ps-save-error', (e) => onsaveerror?.((e as CustomEvent<{ error: Error }>).detail.error)],
|
|
92
|
+
[
|
|
93
|
+
'ps-diagnostics',
|
|
94
|
+
(e) =>
|
|
95
|
+
ondiagnostics?.((e as CustomEvent<{ diagnostics: LintDiagnostic[] }>).detail.diagnostics),
|
|
96
|
+
],
|
|
97
|
+
];
|
|
98
|
+
for (const [type, fn] of listeners) el.addEventListener(type, fn);
|
|
99
|
+
void loadPhpScriptEditor();
|
|
100
|
+
return () => {
|
|
101
|
+
for (const [type, fn] of listeners) el.removeEventListener(type, fn);
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<php-script-editor bind:this={element} class={className} style:--php-script-editor-height={height}
|
|
107
|
+
></php-script-editor>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LintDiagnostic, PhpScriptConfig, PhpScriptEditor as PhpScriptEditorElement, PhpScriptTheme, SaveMethod, SaveResult, ThemeMode } from '@php-script/editor';
|
|
2
|
+
type MonacoEditor = NonNullable<PhpScriptEditorElement['editor']>;
|
|
3
|
+
interface Props {
|
|
4
|
+
value?: string;
|
|
5
|
+
config?: PhpScriptConfig | string | null;
|
|
6
|
+
configUrl?: string;
|
|
7
|
+
saveUrl?: string;
|
|
8
|
+
saveMethod?: SaveMethod;
|
|
9
|
+
saveField?: string;
|
|
10
|
+
saveHeaders?: Record<string, string>;
|
|
11
|
+
savePayload?: Record<string, unknown>;
|
|
12
|
+
persisted?: boolean;
|
|
13
|
+
csrfToken?: string;
|
|
14
|
+
lintUrl?: string;
|
|
15
|
+
lintDelay?: number;
|
|
16
|
+
theme?: ThemeMode | PhpScriptTheme;
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
name?: string;
|
|
19
|
+
options?: Record<string, unknown>;
|
|
20
|
+
labels?: Record<string, string>;
|
|
21
|
+
noToolbar?: boolean;
|
|
22
|
+
noSaveShortcut?: boolean;
|
|
23
|
+
/** CSS height, e.g. `24rem`. */
|
|
24
|
+
height?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
/** The custom element (bindable). */
|
|
27
|
+
element?: PhpScriptEditorElement | null;
|
|
28
|
+
onchange?: (value: string) => void;
|
|
29
|
+
onready?: (editor: MonacoEditor, element: PhpScriptEditorElement) => void;
|
|
30
|
+
onsavestart?: (event: CustomEvent) => void;
|
|
31
|
+
onsaved?: (result: SaveResult & {
|
|
32
|
+
value: string;
|
|
33
|
+
}) => void;
|
|
34
|
+
onsaveerror?: (error: Error) => void;
|
|
35
|
+
ondiagnostics?: (diagnostics: LintDiagnostic[]) => void;
|
|
36
|
+
}
|
|
37
|
+
declare const PhpScriptEditor: import("svelte").Component<Props, {}, "value" | "element">;
|
|
38
|
+
type PhpScriptEditor = ReturnType<typeof PhpScriptEditor>;
|
|
39
|
+
export default PhpScriptEditor;
|
|
40
|
+
//# sourceMappingURL=PhpScriptEditor.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhpScriptEditor.svelte.d.ts","sourceRoot":"","sources":["../src/PhpScriptEditor.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,cAAc,EACd,eAAe,EACf,eAAe,IAAI,sBAAsB,EACzC,cAAc,EACd,UAAU,EACV,UAAU,EACV,SAAS,EACV,MAAM,oBAAoB,CAAC;AAM5B,KAAK,YAAY,GAAG,WAAW,CA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AAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC3C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;CACzD;AAqEH,QAAA,MAAM,eAAe,4DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PhpScriptEditor } from '@php-script/editor';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
|
|
4
|
+
declare module 'svelte/elements' {
|
|
5
|
+
interface SvelteHTMLElements {
|
|
6
|
+
'php-script-editor': HTMLAttributes<PhpScriptEditor>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as PhpScriptEditor, default } from './PhpScriptEditor.svelte';
|
|
2
|
+
export { loadPhpScriptEditor } from './load.js';
|
|
3
|
+
export type { LintDiagnostic, PhpScriptConfig, PhpScriptEditor as PhpScriptEditorElement, PhpScriptTheme, SaveResult, } from '@php-script/editor';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EACV,cAAc,EACd,eAAe,EACf,eAAe,IAAI,sBAAsB,EACzC,cAAc,EACd,UAAU,GACX,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
package/dist/load.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,wBAAkD,CAAC"}
|
package/dist/load.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-script/editor-svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Svelte 5 wrapper for the <php-script-editor> web component (bind:value support).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"svelte": "./dist/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@php-script/editor": "^0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"monaco-editor": ">=0.55.0 <1.0.0",
|
|
26
|
+
"svelte": "^5.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@sveltejs/package": "^3.0.2",
|
|
30
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
31
|
+
"@testing-library/svelte": "^5.4.2",
|
|
32
|
+
"@vitest/browser-playwright": "^5.0.5",
|
|
33
|
+
"monaco-editor": "^0.57.0",
|
|
34
|
+
"svelte": "^5.57.3",
|
|
35
|
+
"svelte-check": "^4.4.0",
|
|
36
|
+
"typescript": "~6.0.3",
|
|
37
|
+
"vite": "^8.3.5",
|
|
38
|
+
"vitest": "^5.0.5"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/php-script/php-script-editor.git",
|
|
43
|
+
"directory": "packages/svelte"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": true
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "svelte-package -i src -o dist",
|
|
51
|
+
"typecheck": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings",
|
|
52
|
+
"test": "vitest run"
|
|
53
|
+
}
|
|
6
54
|
}
|
package/README.md
DELETED