@sierra-95/svelte-scaffold 1.1.3 → 1.1.5

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.
@@ -13,7 +13,7 @@
13
13
  </script>
14
14
 
15
15
  <label class="sierra-input" style="width: {width}; max-width: {maxWidth}; color: {textColor}" for={id}>{label}
16
- <select bind:value={value} id={id} required style="background-color: {background}; height: {height}">
16
+ <select bind:value={value} id={id} name={id} required style="background-color: {background}; height: {height}">
17
17
  {#each options as option}
18
18
  <option
19
19
  value={option.value}
@@ -81,18 +81,37 @@
81
81
  return false;
82
82
  }
83
83
  }
84
+
85
+ $: showDropdown = $editorStore.insertImageMode?.length > 1;
86
+ //$: console.log("showDropdown", showDropdown);
87
+
88
+ function handleSingleMode() {
89
+ if ($editorStore.insertImageMode?.includes('filepicker')) {
90
+ handleInsertImage();
91
+ } else if ($editorStore.insertImageMode?.includes('url')) {
92
+ enterURL();
93
+ }
94
+ }
84
95
  </script>
96
+
85
97
  {#snippet formContent()}
86
98
  <div style="margin: 1rem 0rem;">
87
99
  <Input label="Enter Image URL" id="image-url" underline bind:value={value}/>
88
100
  </div>
89
101
  {/snippet}
90
- <DropdownContainer bind:open={openDropdown} width="150px">
91
- {#snippet dropdownTrigger()}
92
- <button type="button" aria-label="Insert Image" title="Insert File" on:click={() => openDropdown = !openDropdown}>
93
- <i class="fa fa-file"></i>
94
- </button>
95
- {/snippet}
96
- <MenuItem onclick={() => { handleInsertImage(); openDropdown = false; }}>File Picker</MenuItem>
97
- <MenuItem onclick={() => { enterURL(); openDropdown = false; }}>Enter URL</MenuItem>
98
- </DropdownContainer>
102
+
103
+ {#if showDropdown}
104
+ <DropdownContainer bind:open={openDropdown} width="150px">
105
+ {#snippet dropdownTrigger()}
106
+ <button type="button" aria-label="Insert Image" title="Insert File" on:click={() => openDropdown = !openDropdown}>
107
+ <i class="fa fa-file"></i>
108
+ </button>
109
+ {/snippet}
110
+ <MenuItem onclick={() => { handleInsertImage(); openDropdown = false; }}>File Picker</MenuItem>
111
+ <MenuItem onclick={() => { enterURL(); openDropdown = false; }}>Enter URL</MenuItem>
112
+ </DropdownContainer>
113
+ {:else}
114
+ <button type="button" aria-label="Insert Image" title="Insert File" on:click={() => handleSingleMode()}>
115
+ <i class="fa fa-file"></i>
116
+ </button>
117
+ {/if}
@@ -3,26 +3,39 @@
3
3
  TextFormatting, Headings, TextColor, TextAlign, Images, History, Youtube,
4
4
  Export, Lists, Links
5
5
  } from './tools.js';
6
- import type { Editor } from "@tiptap/core";
6
+
7
7
  import './styles/controls.css';
8
- import {Tabs} from '../../index.js';
9
-
10
- export let editor: Editor;
11
-
12
- const HomeItems = [
13
- TextFormatting,
14
- History,
15
- Headings,
16
- TextColor,
17
- TextAlign,
18
- Lists,
8
+ import {Tabs, editorStore} from '../../index.js';
9
+
10
+ const {editor} = $props();
11
+
12
+ let HomeItems: any[] = $state([]);
13
+ let InsertItems: any[] = $state([]);
14
+
15
+ const HOME_TOOLS = [
16
+ { feature: 'text-formatting', component: TextFormatting },
17
+ { feature: 'history', component: History },
18
+ { feature: 'headings', component: Headings },
19
+ { feature: 'text-color', component: TextColor },
20
+ { feature: 'text-align', component: TextAlign },
21
+ { feature: 'lists', component: Lists },
19
22
  ] as const;
20
23
 
21
- const InsertItems = [
22
- Images,
23
- Links,
24
- Youtube,
24
+ const INSERT_TOOLS = [
25
+ { feature: 'images', component: Images },
26
+ { feature: 'links', component: Links },
27
+ { feature: 'youtube', component: Youtube }
25
28
  ] as const;
29
+
30
+ $effect(() => {
31
+ HomeItems = HOME_TOOLS
32
+ .filter(tool => $editorStore.enabledFeatures.includes(tool.feature))
33
+ .map(tool => tool.component);
34
+
35
+ InsertItems = INSERT_TOOLS
36
+ .filter(tool => $editorStore.enabledFeatures.includes(tool.feature))
37
+ .map(tool => tool.component);
38
+ });
26
39
  </script>
27
40
 
28
41
  {#snippet Home()}
@@ -1,22 +1,6 @@
1
- import type { Editor } from "@tiptap/core";
2
1
  import './styles/controls.css';
3
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
- $$bindings?: Bindings;
6
- } & Exports;
7
- (internal: unknown, props: Props & {
8
- $$events?: Events;
9
- $$slots?: Slots;
10
- }): Exports & {
11
- $set?: any;
12
- $on?: any;
13
- };
14
- z_$$bindings?: Bindings;
15
- }
16
- declare const Controls: $$__sveltets_2_IsomorphicComponent<{
17
- editor: Editor;
18
- }, {
19
- [evt: string]: CustomEvent<any>;
20
- }, {}, {}, string>;
21
- type Controls = InstanceType<typeof Controls>;
2
+ declare const Controls: import("svelte").Component<{
3
+ editor: any;
4
+ }, {}, "">;
5
+ type Controls = ReturnType<typeof Controls>;
22
6
  export default Controls;
@@ -1,3 +1,5 @@
1
+ export type EditorFeature = 'text-formatting' | 'headings' | 'text-color' | 'text-align' | 'lists' | 'images' | 'links' | 'youtube' | 'history' | 'export';
2
+ export type ImageInsertMode = 'filepicker' | 'url';
1
3
  export type EditorState = {
2
4
  content: any;
3
5
  export: boolean;
@@ -8,7 +10,8 @@ export type EditorState = {
8
10
  serverDeleteUrl: string;
9
11
  serverStorageUrl: string;
10
12
  serverDownloadUrl: string;
11
- useFilePicker: boolean;
13
+ enabledFeatures: EditorFeature[];
14
+ insertImageMode: ImageInsertMode[];
12
15
  };
13
16
  export declare const editorStore: import("svelte/store").Writable<EditorState>;
14
17
  export declare function resetEditorStore(): void;
@@ -9,7 +9,8 @@ const defaultEditorState = {
9
9
  serverDeleteUrl: '',
10
10
  serverStorageUrl: '',
11
11
  serverDownloadUrl: '',
12
- useFilePicker: true,
12
+ enabledFeatures: [],
13
+ insertImageMode: ['filepicker', 'url']
13
14
  };
14
15
  export const editorStore = writable({
15
16
  ...defaultEditorState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sierra-95/svelte-scaffold",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",