@streamscloud/kit 1.0.1 → 1.0.3

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 CHANGED
@@ -24,8 +24,7 @@ npm run lint:fix # eslint --fix + prettier --write
24
24
 
25
25
  ## Release
26
26
 
27
- Always via the npm scripts — `npm run publish:prod` / `npm run publish:dev`, never raw
28
- `npm publish`. The full workflow is in `.claude/CLAUDE.md`.
27
+ Through the `/sc:deliver` skill.
29
28
 
30
29
  ## Context
31
30
 
@@ -1,11 +1,16 @@
1
1
  <script lang="ts" generics="T">import { DragAndDrop } from './drag-and-drop.svelte';
2
- const { acceptedEvents, disabled, highlightOffset = 0, silent = false, showRejection = false, children, on } = $props();
3
- const dragEvent = $derived.by(() => DragAndDrop.event &&
4
- !disabled &&
5
- (acceptedEvents.includes(DragAndDrop.event.type) || !acceptedEvents.length)
6
- ? DragAndDrop.event
7
- : null);
8
- // A drag is in progress AND this zone refuses it (type not in acceptedEvents). Drives the
2
+ const { acceptedEvents, accepts, disabled, silent = false, showRejection = false, children, on } = $props();
3
+ const dragEvent = $derived.by(() => {
4
+ const event = DragAndDrop.event;
5
+ if (!event || disabled) {
6
+ return null;
7
+ }
8
+ if (acceptedEvents.length && !acceptedEvents.includes(event.type)) {
9
+ return null;
10
+ }
11
+ return !accepts || accepts(event) ? event : null;
12
+ });
13
+ // A drag is in progress AND this zone refuses it (type or `accepts`). Drives the
9
14
  // optional red-shield visual; `on.drop` / `on.enter` still don't fire for rejected drags.
10
15
  const dragRejected = $derived(!!DragAndDrop.event && !disabled && !dragEvent && showRejection);
11
16
  let dragOver = $state(false);
@@ -46,7 +51,6 @@ const onDragLeave = () => {
46
51
  class:drop-zone--drag-over={dragOver && dragEvent && !silent}
47
52
  class:drop-zone--drag-reject={dragOver && dragRejected && !silent}
48
53
  class:drop-zone--disabled={disabled}
49
- style:--_dz--offset="{highlightOffset}px"
50
54
  ondrop={onDrop}
51
55
  ondragover={onDragOver}
52
56
  ondragleave={onDragLeave}
@@ -58,39 +62,33 @@ const onDragLeave = () => {
58
62
 
59
63
  <!--
60
64
  @component
61
- Reactive drop target paired with `DragSource` via the `DragAndDrop` singleton store. When a
62
- source starts dragging a `DragEventModel<T>` whose `type` is listed in `acceptedEvents` (or
63
- when `acceptedEvents` is empty — accept any), the zone activates a dashed-border outline; on
64
- hover (`dragover`) the outline becomes solid and the body fills with the accent tint. The
65
- consumer handles the actual drop via `on.drop`.
66
-
67
- Set `silent` when the host paints its own active / hover visuals; the zone keeps the event
68
- plumbing but skips the built-in chrome. Use `highlightOffset` to outset the dashed border
69
- (e.g. when the host has a rounded background that should remain visible inside the border).
70
- Pass `showRejection` to paint a red shield when the zone is hovered with a drag whose type
71
- isn't in `acceptedEvents` — useful for visible zones where silent inertia could be confusing.
65
+ Drop target for in-app drags, paired with `DragSource` through the `DragAndDrop` singleton store.
66
+ A drag it takes (by `acceptedEvents` and `accepts`) draws a dashed outline that turns solid over an
67
+ info tint on hover, and its payload reaches `on.drop`.
72
68
 
73
69
  ### CSS Custom Properties
74
70
  | Property | Description | Default |
75
71
  |---|---|---|
76
- | `--sc-kit--drop-zone--border-color` | Dashed outline color (active, idle) | `var(--sc-kit--color--accent)` |
77
- | `--sc-kit--drop-zone--border-color--hover` | Solid outline color on dragover | `var(--sc-kit--color--accent)` |
78
- | `--sc-kit--drop-zone--background--hover` | Translucent fill on dragover (overlays content) | `var(--sc-kit--color--accent)` at 12% over transparent |
79
- | `--sc-kit--drop-zone--border-color--reject` | Solid outline color when hovered with a rejected type (requires `showRejection`) | `var(--sc-kit--color--danger)` |
80
- | `--sc-kit--drop-zone--background--reject` | Translucent fill when hovered with a rejected type | `var(--sc-kit--color--danger)` at 12% over transparent |
72
+ | `--sc-kit--drop-zone--border-color` | Dashed outline color (active, idle) | `var(--sc-kit--color--info)` |
73
+ | `--sc-kit--drop-zone--border-color--hover` | Solid outline color on dragover | `var(--sc-kit--color--info)` |
74
+ | `--sc-kit--drop-zone--background--hover` | Translucent fill on dragover (overlays content) | `var(--sc-kit--color--info)` at 12% over transparent |
75
+ | `--sc-kit--drop-zone--border-color--reject` | Solid outline color when hovered with a rejected drag (requires `showRejection`) | `var(--sc-kit--color--danger)` |
76
+ | `--sc-kit--drop-zone--background--reject` | Translucent fill when hovered with a rejected drag | `var(--sc-kit--color--danger)` at 12% over transparent |
77
+ | `--sc-kit--drop-zone--border-width` | Outline width in every state | `2px` |
81
78
  | `--sc-kit--drop-zone--border-radius` | Outline radius | `var(--sc-kit--radius--sm)` |
79
+ | `--sc-kit--drop-zone--inset` | Outline inset from the zone edges; negative values outset it | `0px` |
82
80
  -->
83
81
 
84
82
  <style>.drop-zone {
85
- --_dz--offset: 0px;
86
- --_dz--border-color: var(--sc-kit--drop-zone--border-color, var(--sc-kit--color--accent));
83
+ --_dz--inset: var(--sc-kit--drop-zone--inset, 0px);
84
+ --_dz--border-color: var(--sc-kit--drop-zone--border-color, var(--sc-kit--color--info));
87
85
  --_dz--border-color-hover: var(
88
86
  --sc-kit--drop-zone--border-color--hover,
89
- var(--sc-kit--color--accent)
87
+ var(--sc-kit--color--info)
90
88
  );
91
89
  --_dz--background-hover: var(
92
90
  --sc-kit--drop-zone--background--hover,
93
- color-mix(in srgb, var(--sc-kit--color--accent) 12%, transparent)
91
+ color-mix(in srgb, var(--sc-kit--color--info) 12%, transparent)
94
92
  );
95
93
  --_dz--border-color-reject: var(
96
94
  --sc-kit--drop-zone--border-color--reject,
@@ -100,6 +98,7 @@ isn't in `acceptedEvents` — useful for visible zones where silent inertia coul
100
98
  --sc-kit--drop-zone--background--reject,
101
99
  color-mix(in srgb, var(--sc-kit--color--danger) 12%, transparent)
102
100
  );
101
+ --_dz--border-width: var(--sc-kit--drop-zone--border-width, 2px);
103
102
  --_dz--border-radius: var(--sc-kit--drop-zone--border-radius, var(--sc-kit--radius--sm));
104
103
  width: 100%;
105
104
  height: 100%;
@@ -111,10 +110,10 @@ isn't in `acceptedEvents` — useful for visible zones where silent inertia coul
111
110
  .drop-zone--active::before {
112
111
  content: "";
113
112
  position: absolute;
114
- inset: calc(-1 * var(--_dz--offset));
113
+ inset: var(--_dz--inset);
115
114
  pointer-events: none;
116
115
  box-sizing: border-box;
117
- border: 1px dashed var(--_dz--border-color);
116
+ border: var(--_dz--border-width) dashed var(--_dz--border-color);
118
117
  border-radius: var(--_dz--border-radius);
119
118
  z-index: 2;
120
119
  }
@@ -126,10 +125,10 @@ isn't in `acceptedEvents` — useful for visible zones where silent inertia coul
126
125
  .drop-zone--drag-reject::before {
127
126
  content: "";
128
127
  position: absolute;
129
- inset: calc(-1 * var(--_dz--offset));
128
+ inset: var(--_dz--inset);
130
129
  pointer-events: none;
131
130
  box-sizing: border-box;
132
- border: 1px solid var(--_dz--border-color-reject);
131
+ border: var(--_dz--border-width) solid var(--_dz--border-color-reject);
133
132
  background: var(--_dz--background-reject);
134
133
  border-radius: var(--_dz--border-radius);
135
134
  z-index: 2;
@@ -7,15 +7,16 @@ declare function $$render<T>(): {
7
7
  * `type` field of whatever `DragSource` set on the shared store.
8
8
  */
9
9
  acceptedEvents: string[];
10
+ /** Payload check on top of `acceptedEvents`; `false` refuses the drag exactly like a type mismatch. */
11
+ accepts?: (event: DragEventModel<T>) => boolean;
10
12
  disabled?: boolean;
11
- /** Offset (px) for the dashed-border overlay. Positive values outset, negative inset. @default 0 */
12
- highlightOffset?: number;
13
13
  /** Suppress the built-in dashed-border + fill visual; the host paints its own. */
14
14
  silent?: boolean;
15
15
  /**
16
- * When `true`, the zone paints a red shield on hover if there's a drag in progress whose
17
- * type is NOT in `acceptedEvents`. Useful when the zone is visible and the user might
18
- * think it accepts the dragged item — explicit refusal beats silent inertia. @default false
16
+ * When `true`, the zone paints a red shield on hover if there's a drag in progress it
17
+ * refuses (type not in `acceptedEvents`, or `accepts` returned `false`). Useful when the
18
+ * zone is visible and the user might think it accepts the dragged item — explicit refusal
19
+ * beats silent inertia. @default false
19
20
  */
20
21
  showRejection?: boolean;
21
22
  children?: Snippet;
@@ -45,27 +46,21 @@ interface $$IsomorphicComponent {
45
46
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
46
47
  }
47
48
  /**
48
- * Reactive drop target paired with `DragSource` via the `DragAndDrop` singleton store. When a
49
- * source starts dragging a `DragEventModel<T>` whose `type` is listed in `acceptedEvents` (or
50
- * when `acceptedEvents` is empty — accept any), the zone activates a dashed-border outline; on
51
- * hover (`dragover`) the outline becomes solid and the body fills with the accent tint. The
52
- * consumer handles the actual drop via `on.drop`.
53
- *
54
- * Set `silent` when the host paints its own active / hover visuals; the zone keeps the event
55
- * plumbing but skips the built-in chrome. Use `highlightOffset` to outset the dashed border
56
- * (e.g. when the host has a rounded background that should remain visible inside the border).
57
- * Pass `showRejection` to paint a red shield when the zone is hovered with a drag whose type
58
- * isn't in `acceptedEvents` — useful for visible zones where silent inertia could be confusing.
49
+ * Drop target for in-app drags, paired with `DragSource` through the `DragAndDrop` singleton store.
50
+ * A drag it takes (by `acceptedEvents` and `accepts`) draws a dashed outline that turns solid over an
51
+ * info tint on hover, and its payload reaches `on.drop`.
59
52
  *
60
53
  * ### CSS Custom Properties
61
54
  * | Property | Description | Default |
62
55
  * |---|---|---|
63
- * | `--sc-kit--drop-zone--border-color` | Dashed outline color (active, idle) | `var(--sc-kit--color--accent)` |
64
- * | `--sc-kit--drop-zone--border-color--hover` | Solid outline color on dragover | `var(--sc-kit--color--accent)` |
65
- * | `--sc-kit--drop-zone--background--hover` | Translucent fill on dragover (overlays content) | `var(--sc-kit--color--accent)` at 12% over transparent |
66
- * | `--sc-kit--drop-zone--border-color--reject` | Solid outline color when hovered with a rejected type (requires `showRejection`) | `var(--sc-kit--color--danger)` |
67
- * | `--sc-kit--drop-zone--background--reject` | Translucent fill when hovered with a rejected type | `var(--sc-kit--color--danger)` at 12% over transparent |
56
+ * | `--sc-kit--drop-zone--border-color` | Dashed outline color (active, idle) | `var(--sc-kit--color--info)` |
57
+ * | `--sc-kit--drop-zone--border-color--hover` | Solid outline color on dragover | `var(--sc-kit--color--info)` |
58
+ * | `--sc-kit--drop-zone--background--hover` | Translucent fill on dragover (overlays content) | `var(--sc-kit--color--info)` at 12% over transparent |
59
+ * | `--sc-kit--drop-zone--border-color--reject` | Solid outline color when hovered with a rejected drag (requires `showRejection`) | `var(--sc-kit--color--danger)` |
60
+ * | `--sc-kit--drop-zone--background--reject` | Translucent fill when hovered with a rejected drag | `var(--sc-kit--color--danger)` at 12% over transparent |
61
+ * | `--sc-kit--drop-zone--border-width` | Outline width in every state | `2px` |
68
62
  * | `--sc-kit--drop-zone--border-radius` | Outline radius | `var(--sc-kit--radius--sm)` |
63
+ * | `--sc-kit--drop-zone--inset` | Outline inset from the zone edges; negative values outset it | `0px` |
69
64
  */
70
65
  declare const Cmp: $$IsomorphicComponent;
71
66
  type Cmp<T> = InstanceType<typeof Cmp<T>>;
@@ -0,0 +1,149 @@
1
+ <script lang="ts">import { matchesAcceptedFileTypes } from '../../core/files';
2
+ const { accept = '', refused = false, disabled = false, hint, children, on } = $props();
3
+ let rootRef = $state();
4
+ let verdict = $state(null);
5
+ const isFileDrag = (e) => !!e.dataTransfer?.types.includes('Files');
6
+ const isOverNestedZone = (e) => {
7
+ const element = e.target instanceof Text ? e.target.parentElement : e.target;
8
+ return !(element instanceof Element) || element.closest('[data-file-drop-zone]') !== rootRef;
9
+ };
10
+ // An extension token can't be checked before the drop: the browser hides file names until then.
11
+ const acceptsType = (type) => !type ||
12
+ accept.split(',').some((token) => token.trim().startsWith('.')) ||
13
+ matchesAcceptedFileTypes(new File([], '', { type }), accept);
14
+ const evaluate = (dataTransfer) => {
15
+ if (refused) {
16
+ return 'reject';
17
+ }
18
+ const types = [...dataTransfer.items]
19
+ .filter((item) => item.kind === 'file')
20
+ .map((item) => item.type);
21
+ if (!types.length) {
22
+ return null;
23
+ }
24
+ return types.some(acceptsType) ? 'accept' : 'reject';
25
+ };
26
+ const onDragOver = (e) => {
27
+ if (!isFileDrag(e) || !e.dataTransfer) {
28
+ return;
29
+ }
30
+ if (isOverNestedZone(e)) {
31
+ verdict = null;
32
+ return;
33
+ }
34
+ e.preventDefault();
35
+ e.stopPropagation();
36
+ verdict = disabled ? null : (evaluate(e.dataTransfer) ?? verdict ?? 'accept');
37
+ e.dataTransfer.dropEffect = verdict === 'accept' ? 'copy' : 'none';
38
+ };
39
+ const onDragLeave = (e) => {
40
+ if (!(e.relatedTarget instanceof Node) || !rootRef?.contains(e.relatedTarget)) {
41
+ verdict = null;
42
+ }
43
+ };
44
+ const onDrop = (e) => {
45
+ if (!isFileDrag(e)) {
46
+ return;
47
+ }
48
+ verdict = null;
49
+ if (isOverNestedZone(e)) {
50
+ return;
51
+ }
52
+ e.preventDefault();
53
+ e.stopPropagation();
54
+ if (disabled || refused) {
55
+ return;
56
+ }
57
+ const files = [...(e.dataTransfer?.files ?? [])];
58
+ const accepted = files.filter((file) => matchesAcceptedFileTypes(file, accept));
59
+ const rejected = files.filter((file) => !accepted.includes(file));
60
+ if (accepted.length) {
61
+ on.drop(accepted);
62
+ }
63
+ if (rejected.length) {
64
+ on.reject?.(rejected);
65
+ }
66
+ };
67
+ </script>
68
+
69
+ <div
70
+ class="file-drop-zone"
71
+ class:file-drop-zone--active={verdict !== null}
72
+ data-file-drop-zone
73
+ bind:this={rootRef}
74
+ ondragovercapture={onDragOver}
75
+ ondragleave={onDragLeave}
76
+ ondropcapture={onDrop}
77
+ role="none">
78
+ {@render children()}
79
+ {#if verdict}
80
+ <div
81
+ class="file-drop-zone__shield"
82
+ class:file-drop-zone__shield--rejected={verdict === 'reject'}>
83
+ {#if hint}
84
+ <div class="file-drop-zone__hint">{@render hint({ rejected: verdict === 'reject' })}</div>
85
+ {/if}
86
+ </div>
87
+ {/if}
88
+ </div>
89
+
90
+ <!--
91
+ @component
92
+ Drop target for files dragged in from the OS: hovering files paint an info shield when they match
93
+ `accept` and a danger one otherwise, and `on.drop` receives only the matching files (the rest go to `on.reject`). A file drop never
94
+ reaches the browser, in-app drags pass through untouched, and of nested zones the innermost takes the
95
+ files.
96
+
97
+ ### CSS Custom Properties
98
+ | Property | Description | Default |
99
+ |---|---|---|
100
+ | `--sc-kit--file-drop-zone--color` | Outline and shield color for accepted files | `var(--sc-kit--color--info)` |
101
+ | `--sc-kit--file-drop-zone--color--reject` | Outline and shield color for rejected files | `var(--sc-kit--color--danger)` |
102
+ | `--sc-kit--file-drop-zone--border-width` | Shield outline width | `2px` |
103
+ | `--sc-kit--file-drop-zone--border-radius` | Shield radius | `var(--sc-kit--radius--sm)` |
104
+ | `--sc-kit--file-drop-zone--inset` | Shield inset from the zone edges | `0px` |
105
+ -->
106
+
107
+ <style>.file-drop-zone {
108
+ --_fdz--color: var(--sc-kit--file-drop-zone--color, var(--sc-kit--color--info));
109
+ --_fdz--color-reject: var(
110
+ --sc-kit--file-drop-zone--color--reject,
111
+ var(--sc-kit--color--danger)
112
+ );
113
+ --_fdz--border-width: var(--sc-kit--file-drop-zone--border-width, 2px);
114
+ --_fdz--border-radius: var(--sc-kit--file-drop-zone--border-radius, var(--sc-kit--radius--sm));
115
+ --_fdz--inset: var(--sc-kit--file-drop-zone--inset, 0px);
116
+ position: relative;
117
+ width: 100%;
118
+ height: 100%;
119
+ }
120
+ .file-drop-zone--active {
121
+ isolation: isolate;
122
+ }
123
+ .file-drop-zone__shield {
124
+ --_fdz--shield-color: var(--_fdz--color);
125
+ position: absolute;
126
+ inset: var(--_fdz--inset);
127
+ z-index: 2;
128
+ display: flex;
129
+ flex-direction: column;
130
+ justify-content: center;
131
+ pointer-events: none;
132
+ border: var(--_fdz--border-width) solid var(--_fdz--shield-color);
133
+ border-radius: var(--_fdz--border-radius);
134
+ background: color-mix(in srgb, var(--_fdz--shield-color) 12%, transparent);
135
+ }
136
+ .file-drop-zone__shield--rejected {
137
+ --_fdz--shield-color: var(--_fdz--color-reject);
138
+ }
139
+ .file-drop-zone__hint {
140
+ position: sticky;
141
+ inset-block: var(--sc-kit--space--4);
142
+ inline-size: fit-content;
143
+ max-inline-size: calc(100% - 2 * var(--sc-kit--space--2));
144
+ margin-inline: auto;
145
+ padding: var(--sc-kit--space--2) var(--sc-kit--space--4);
146
+ background: var(--sc-kit--color--bg--element);
147
+ border-radius: var(--sc-kit--radius--md);
148
+ box-shadow: var(--sc-kit--shadow--md);
149
+ }</style>
@@ -0,0 +1,36 @@
1
+ import type { Snippet } from 'svelte';
2
+ type Props = {
3
+ /** Like `<input accept>`; `''` takes any file. @default '' */
4
+ accept?: string;
5
+ /** Files hovering the zone are shown as rejected and can't be dropped (e.g. while busy). */
6
+ refused?: boolean;
7
+ disabled?: boolean;
8
+ /** Content centered in the shield while files hover the zone. */
9
+ hint?: Snippet<[{
10
+ rejected: boolean;
11
+ }]>;
12
+ children: Snippet;
13
+ on: {
14
+ drop: (files: File[]) => void;
15
+ /** Dropped files that don't match `accept`; they never reach `drop`. */
16
+ reject?: (files: File[]) => void;
17
+ };
18
+ };
19
+ /**
20
+ * Drop target for files dragged in from the OS: hovering files paint an info shield when they match
21
+ * `accept` and a danger one otherwise, and `on.drop` receives only the matching files (the rest go to `on.reject`). A file drop never
22
+ * reaches the browser, in-app drags pass through untouched, and of nested zones the innermost takes the
23
+ * files.
24
+ *
25
+ * ### CSS Custom Properties
26
+ * | Property | Description | Default |
27
+ * |---|---|---|
28
+ * | `--sc-kit--file-drop-zone--color` | Outline and shield color for accepted files | `var(--sc-kit--color--info)` |
29
+ * | `--sc-kit--file-drop-zone--color--reject` | Outline and shield color for rejected files | `var(--sc-kit--color--danger)` |
30
+ * | `--sc-kit--file-drop-zone--border-width` | Shield outline width | `2px` |
31
+ * | `--sc-kit--file-drop-zone--border-radius` | Shield radius | `var(--sc-kit--radius--sm)` |
32
+ * | `--sc-kit--file-drop-zone--inset` | Shield inset from the zone edges | `0px` |
33
+ */
34
+ declare const Cmp: import("svelte").Component<Props, {}, "">;
35
+ type Cmp = ReturnType<typeof Cmp>;
36
+ export default Cmp;
@@ -2,3 +2,4 @@ export type { DragEventModel } from './types';
2
2
  export { DragAndDrop } from './drag-and-drop.svelte';
3
3
  export { default as DragSource } from './cmp.drag-source.svelte';
4
4
  export { default as DropZone } from './cmp.drop-zone.svelte';
5
+ export { default as FileDropZone } from './cmp.file-drop-zone.svelte';
@@ -1,3 +1,4 @@
1
1
  export { DragAndDrop } from './drag-and-drop.svelte';
2
2
  export { default as DragSource } from './cmp.drag-source.svelte';
3
3
  export { default as DropZone } from './cmp.drop-zone.svelte';
4
+ export { default as FileDropZone } from './cmp.file-drop-zone.svelte';
@@ -132,10 +132,10 @@ via `DataTransfer.items` — extension-only accept tokens defer to drop).
132
132
  | Property | Description | Default |
133
133
  |---|---|---|
134
134
  | `--sc-kit--file-uploader--background` | Drop-zone background | `var(--sc-kit--color--bg--subtle)` |
135
- | `--sc-kit--file-uploader--background--drag` | Background during valid drag-over / hover | `var(--sc-kit--color--accent--softer)` |
135
+ | `--sc-kit--file-uploader--background--drag` | Background during valid drag-over / hover | `var(--sc-kit--color--info--soft)` |
136
136
  | `--sc-kit--file-uploader--background--drag-invalid` | Background when a dragged file's MIME does not match the Mime rule | `var(--sc-kit--color--danger--soft)` |
137
137
  | `--sc-kit--file-uploader--border-color` | Dashed border color (idle) | `var(--sc-kit--color--border--strong)` |
138
- | `--sc-kit--file-uploader--border-color--drag` | Dashed border color during valid drag-over / hover | `var(--sc-kit--color--accent)` |
138
+ | `--sc-kit--file-uploader--border-color--drag` | Dashed border color during valid drag-over / hover | `var(--sc-kit--color--info)` |
139
139
  | `--sc-kit--file-uploader--border-color--drag-invalid` | Dashed border color when dragged file's MIME does not match the Mime rule | `var(--sc-kit--color--danger)` |
140
140
  | `--sc-kit--file-uploader--border-radius` | Drop-zone radius | `var(--sc-kit--radius--lg)` |
141
141
  | `--sc-kit--file-uploader--padding` | Inner padding | `var(--sc-kit--space--6)` |
@@ -152,7 +152,7 @@ via `DataTransfer.items` — extension-only accept tokens defer to drop).
152
152
  --_fu--background: var(--sc-kit--file-uploader--background, var(--sc-kit--color--bg--subtle));
153
153
  --_fu--background-drag: var(
154
154
  --sc-kit--file-uploader--background--drag,
155
- var(--sc-kit--color--accent--softer)
155
+ var(--sc-kit--color--info--soft)
156
156
  );
157
157
  --_fu--background-drag-invalid: var(
158
158
  --sc-kit--file-uploader--background--drag-invalid,
@@ -164,7 +164,7 @@ via `DataTransfer.items` — extension-only accept tokens defer to drop).
164
164
  );
165
165
  --_fu--border-color-drag: var(
166
166
  --sc-kit--file-uploader--border-color--drag,
167
- var(--sc-kit--color--accent)
167
+ var(--sc-kit--color--info)
168
168
  );
169
169
  --_fu--border-color-drag-invalid: var(
170
170
  --sc-kit--file-uploader--border-color--drag-invalid,
@@ -43,10 +43,10 @@ type Props = {
43
43
  * | Property | Description | Default |
44
44
  * |---|---|---|
45
45
  * | `--sc-kit--file-uploader--background` | Drop-zone background | `var(--sc-kit--color--bg--subtle)` |
46
- * | `--sc-kit--file-uploader--background--drag` | Background during valid drag-over / hover | `var(--sc-kit--color--accent--softer)` |
46
+ * | `--sc-kit--file-uploader--background--drag` | Background during valid drag-over / hover | `var(--sc-kit--color--info--soft)` |
47
47
  * | `--sc-kit--file-uploader--background--drag-invalid` | Background when a dragged file's MIME does not match the Mime rule | `var(--sc-kit--color--danger--soft)` |
48
48
  * | `--sc-kit--file-uploader--border-color` | Dashed border color (idle) | `var(--sc-kit--color--border--strong)` |
49
- * | `--sc-kit--file-uploader--border-color--drag` | Dashed border color during valid drag-over / hover | `var(--sc-kit--color--accent)` |
49
+ * | `--sc-kit--file-uploader--border-color--drag` | Dashed border color during valid drag-over / hover | `var(--sc-kit--color--info)` |
50
50
  * | `--sc-kit--file-uploader--border-color--drag-invalid` | Dashed border color when dragged file's MIME does not match the Mime rule | `var(--sc-kit--color--danger)` |
51
51
  * | `--sc-kit--file-uploader--border-radius` | Drop-zone radius | `var(--sc-kit--radius--lg)` |
52
52
  * | `--sc-kit--file-uploader--padding` | Inner padding | `var(--sc-kit--space--6)` |
@@ -19,12 +19,17 @@ not scrolled horizontally.
19
19
  | `--sc-kit--html-block--font-size` | Base font size | `0.875em` |
20
20
  | `--sc-kit--html-block--text-color` | Body text color | `--sc-kit--color--text--primary` |
21
21
  | `--sc-kit--html-block--link-color` | Anchor color | `--sc-kit--color--accent` |
22
+ | `--sc-kit--html-block--link-color--disabled` | Color of an anchor with `aria-disabled="true"` | `--sc-kit--html-block--link-color` |
22
23
  | `--sc-kit--html-block--code-font` | Monospace font for `pre` and `code` | `--sc-kit--font--mono` |
23
24
  -->
24
25
 
25
26
  <style>.html-block {
26
27
  --_html-block--text: var(--sc-kit--html-block--text-color, var(--sc-kit--color--text--primary));
27
28
  --_html-block--link: var(--sc-kit--html-block--link-color, var(--sc-kit--color--accent));
29
+ --_html-block--link-disabled: var(
30
+ --sc-kit--html-block--link-color--disabled,
31
+ var(--_html-block--link)
32
+ );
28
33
  --_html-block--code-font: var(--sc-kit--html-block--code-font, var(--sc-kit--font--mono));
29
34
  --_html-block--font-size: var(--sc-kit--html-block--font-size, 0.875em);
30
35
  display: block;
@@ -101,6 +106,10 @@ not scrolled horizontally.
101
106
  .html-block :global(a) {
102
107
  color: var(--_html-block--link);
103
108
  }
109
+ .html-block :global(a[aria-disabled='true']) {
110
+ color: var(--_html-block--link-disabled);
111
+ cursor: default;
112
+ }
104
113
  .html-block :global(ul),
105
114
  .html-block :global(ol) {
106
115
  padding-left: 1.5em;
@@ -14,6 +14,7 @@ type Props = {
14
14
  * | `--sc-kit--html-block--font-size` | Base font size | `0.875em` |
15
15
  * | `--sc-kit--html-block--text-color` | Body text color | `--sc-kit--color--text--primary` |
16
16
  * | `--sc-kit--html-block--link-color` | Anchor color | `--sc-kit--color--accent` |
17
+ * | `--sc-kit--html-block--link-color--disabled` | Color of an anchor with `aria-disabled="true"` | `--sc-kit--html-block--link-color` |
17
18
  * | `--sc-kit--html-block--code-font` | Monospace font for `pre` and `code` | `--sc-kit--font--mono` |
18
19
  */
19
20
  declare const Cmp: import("svelte").Component<Props, {}, "">;
@@ -4,7 +4,7 @@ import { getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-fiel
4
4
  import { InputEmojiPicker } from '../_internal/input-emoji-picker';
5
5
  import { HtmlBlock } from '../html-block';
6
6
  import { RichTextInputLocalization } from './rich-text-input-localization';
7
- import { addValidatedLinkButton } from './validated-link-button';
7
+ import { LINK_TARGET, registerValidatedLink } from './validated-link-button';
8
8
  import { onDestroy, onMount } from 'svelte';
9
9
  const { value, size = 'md', disabled = false, readonly = false, inert = false, error = false, borderless = false, emoji = false, autofocus = false, rows = 0, placeholder = '', options, conf, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'aria-required': ariaRequired, on } = $props();
10
10
  const id = $props.id();
@@ -82,7 +82,8 @@ onMount(async () => {
82
82
  auto_focus: autofocus ? id : undefined,
83
83
  placeholder,
84
84
  readonly: disabled || readonly || inert,
85
- toolbar: 'undo redo | blocks | fontfamily fontsize | bold italic underline | forecolor backcolor | alignleft aligncenter alignright | bullist numlist outdent indent | lineheight | table | validatedlink',
85
+ toolbar: 'undo redo | blocks | fontfamily fontsize | bold italic underline | forecolor backcolor | alignleft aligncenter alignright | bullist numlist outdent indent | lineheight | table | ' +
86
+ ['validatedlink', ...(options?.extraToolbarButtons ?? [])].join(' '),
86
87
  toolbar_persist: options?.persistToolbar,
87
88
  plugins: ['advlist', 'link', 'lists', 'table'],
88
89
  advlist_bullet_styles: 'default,circle,square,disc',
@@ -91,7 +92,9 @@ onMount(async () => {
91
92
  font_family_formats: 'Arial=arial,helvetica,sans-serif; Comic Sans MS=comic sans ms,cursive; Courier New=courier new,courier,monospace; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,charcoal,sans-serif; Lucida Console=lucida console,monaco,monospace; Palatino Linotype=palatino linotype,book antiqua,palatino,serif; Tahoma=tahoma,geneva,sans-serif; Times New Roman=times new roman,times,serif; Trebuchet MS=trebuchet ms,sans-serif; Verdana=verdana,geneva,sans-serif',
92
93
  font_size_formats: '8px 10px 12px 14px 16px 18px 24px 36px 48px',
93
94
  block_formats: 'Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6',
94
- contextmenu: 'link',
95
+ contextmenu: ['validatedlink', ...(options?.extraContextMenu ?? [])].join(' '),
96
+ link_default_target: LINK_TARGET,
97
+ link_target_list: false,
95
98
  paste_data_images: false,
96
99
  paste_preprocess: (_, args) => {
97
100
  if (args.internal) {
@@ -126,7 +129,7 @@ onMount(async () => {
126
129
  everFocused = true;
127
130
  on?.focus?.();
128
131
  });
129
- addValidatedLinkButton(editor, loc);
132
+ registerValidatedLink(editor, loc);
130
133
  on?.mounted?.({ editor, insertEmoji });
131
134
  if (typeof conf?.setup === 'function') {
132
135
  conf.setup(editor);
@@ -1,5 +1,5 @@
1
- import type { RichTextInputOptions } from './types';
2
- import type { Editor, RawEditorOptions } from 'hugerte';
1
+ import type { RichTextEditor, RichTextInputOptions } from './types';
2
+ import type { RawEditorOptions } from 'hugerte';
3
3
  type Props = {
4
4
  /** HTML content. */
5
5
  value: string | null | undefined;
@@ -30,7 +30,7 @@ type Props = {
30
30
  focus?: () => void;
31
31
  blur?: () => void;
32
32
  mounted?: (data: {
33
- editor: Editor;
33
+ editor: RichTextEditor;
34
34
  insertEmoji: (emoji: string) => void;
35
35
  }) => void;
36
36
  };
@@ -1,2 +1,2 @@
1
1
  export { default as RichTextInput } from './cmp.rich-text-input.svelte';
2
- export type { RichTextInputOptions } from './types';
2
+ export type { RichTextEditor, RichTextInputOptions } from './types';
@@ -3,9 +3,6 @@ export declare class RichTextInputLocalization {
3
3
  get linkDialogTitle(): string;
4
4
  get linkUrlLabel(): string;
5
5
  get linkTextLabel(): string;
6
- get linkTargetLabel(): string;
7
- get linkTargetSelf(): string;
8
- get linkTargetBlank(): string;
9
6
  get linkCancelButton(): string;
10
7
  get linkSaveButton(): string;
11
8
  get linkUrlInvalid(): string;
@@ -4,9 +4,6 @@ const loc = {
4
4
  linkDialogTitle: { en: 'Insert/Edit Link', no: 'Sett inn/rediger lenke' },
5
5
  linkUrlLabel: { en: 'URL', no: 'URL' },
6
6
  linkTextLabel: { en: 'Text to display', no: 'Tekst a vise' },
7
- linkTargetLabel: { en: 'Open link in...', no: 'Apne lenke i...' },
8
- linkTargetSelf: { en: 'Current window', no: 'Gjeldende vindu' },
9
- linkTargetBlank: { en: 'New window', no: 'Nytt vindu' },
10
7
  linkCancelButton: { en: 'Cancel', no: 'Avbryt' },
11
8
  linkSaveButton: { en: 'Save', no: 'Lagre' },
12
9
  linkUrlInvalid: {
@@ -27,15 +24,6 @@ export class RichTextInputLocalization {
27
24
  get linkTextLabel() {
28
25
  return loc.linkTextLabel[AppLocale.current];
29
26
  }
30
- get linkTargetLabel() {
31
- return loc.linkTargetLabel[AppLocale.current];
32
- }
33
- get linkTargetSelf() {
34
- return loc.linkTargetSelf[AppLocale.current];
35
- }
36
- get linkTargetBlank() {
37
- return loc.linkTargetBlank[AppLocale.current];
38
- }
39
27
  get linkCancelButton() {
40
28
  return loc.linkCancelButton[AppLocale.current];
41
29
  }
@@ -1,4 +1,10 @@
1
+ import type { Editor } from 'hugerte';
2
+ export type RichTextEditor = Editor;
1
3
  export type RichTextInputOptions = {
2
4
  persistToolbar?: boolean;
3
5
  fixedToolbarId?: string;
6
+ /** HugeRTE button names appended after the link button. The host registers them in `conf.setup`. */
7
+ extraToolbarButtons?: string[];
8
+ /** HugeRTE context menu names appended after the link menu. The host registers them in `conf.setup`. */
9
+ extraContextMenu?: string[];
4
10
  };
@@ -1,3 +1,4 @@
1
1
  import type { RichTextInputLocalization } from './rich-text-input-localization';
2
2
  import type { Editor } from 'hugerte';
3
- export declare const addValidatedLinkButton: (editor: Editor, loc: RichTextInputLocalization) => void;
3
+ export declare const LINK_TARGET = "_blank";
4
+ export declare const registerValidatedLink: (editor: Editor, loc: RichTextInputLocalization) => void;
@@ -1,78 +1,101 @@
1
1
  import { validateHref } from '../../core/utils';
2
- const DEFAULT_TARGET = '_blank';
3
- export const addValidatedLinkButton = (editor, loc) => {
2
+ export const LINK_TARGET = '_blank';
3
+ export const registerValidatedLink = (editor, loc) => {
4
+ const isInHostAnchor = (node) => {
5
+ const anchor = editor.dom.getParent(node, 'a');
6
+ return anchor !== null && !anchor.hasAttribute('href');
7
+ };
8
+ const selectionTouchesHostAnchor = () => {
9
+ const range = editor.selection.getRng();
10
+ return (isInHostAnchor(editor.selection.getNode()) ||
11
+ (!range.collapsed && range.cloneContents().querySelector('a:not([href])') !== null));
12
+ };
13
+ const disableInHostAnchor = (api) => {
14
+ const update = () => api.setEnabled(!editor.mode.isReadOnly() && !selectionTouchesHostAnchor());
15
+ update();
16
+ // SelectionChange: touch handle drags fire no NodeChange; SwitchMode: the theme re-enables every button when leaving readonly.
17
+ editor.on('NodeChange SelectionChange SwitchMode', update);
18
+ return () => editor.off('NodeChange SelectionChange SwitchMode', update);
19
+ };
20
+ const openLinkDialog = () => {
21
+ const linkNode = editor.dom.getParent(editor.selection.getNode(), 'a[href]');
22
+ let initialUrl = '';
23
+ let initialText = '';
24
+ if (linkNode) {
25
+ initialUrl = linkNode.getAttribute('href') ?? '';
26
+ initialText = linkNode.textContent ?? '';
27
+ }
28
+ else {
29
+ initialText = editor.selection.getContent({ format: 'text' }) ?? '';
30
+ }
31
+ let userChangedText = false;
32
+ editor.windowManager.open({
33
+ title: loc.linkDialogTitle,
34
+ body: {
35
+ type: 'panel',
36
+ items: [
37
+ { type: 'input', name: 'url', label: loc.linkUrlLabel },
38
+ { type: 'input', name: 'text', label: loc.linkTextLabel }
39
+ ]
40
+ },
41
+ initialData: {
42
+ url: initialUrl,
43
+ text: initialText
44
+ },
45
+ buttons: [
46
+ { type: 'cancel', text: loc.linkCancelButton },
47
+ { type: 'submit', text: loc.linkSaveButton, primary: true }
48
+ ],
49
+ onChange: (api, details) => {
50
+ if (details.name === 'text' && !userChangedText) {
51
+ userChangedText = true;
52
+ }
53
+ if (details.name === 'url') {
54
+ const data = api.getData();
55
+ if (!userChangedText && !initialText) {
56
+ api.setData({ text: data.url });
57
+ }
58
+ }
59
+ },
60
+ onSubmit: (api) => {
61
+ const data = api.getData();
62
+ if (!validateHref(data.url, { allowRelative: 'prefixed' }).valid) {
63
+ editor.windowManager.alert(loc.linkUrlInvalid);
64
+ return;
65
+ }
66
+ if (linkNode) {
67
+ editor.dom.setAttrib(linkNode, 'href', data.url);
68
+ editor.dom.setAttrib(linkNode, 'target', LINK_TARGET);
69
+ linkNode.textContent = data.text ?? data.url;
70
+ }
71
+ else {
72
+ editor.insertContent(`<a href="${data.url}" target="${LINK_TARGET}">${data.text ?? data.url}</a>`);
73
+ }
74
+ api.close();
75
+ }
76
+ });
77
+ };
4
78
  editor.ui.registry.addButton('validatedlink', {
5
79
  icon: 'link',
6
80
  tooltip: loc.linkButton,
7
- onAction: () => {
8
- const linkNode = editor.dom.getParent(editor.selection.getNode(), 'a');
9
- let initialUrl = '';
10
- let initialText = '';
11
- let initialTarget = DEFAULT_TARGET;
12
- if (linkNode) {
13
- initialUrl = linkNode.getAttribute('href') ?? '';
14
- initialText = linkNode.textContent ?? '';
15
- initialTarget = linkNode.getAttribute('target') ?? DEFAULT_TARGET;
16
- }
17
- else {
18
- initialText = editor.selection.getContent({ format: 'text' }) ?? '';
81
+ onAction: openLinkDialog,
82
+ onSetup: disableInHostAnchor
83
+ });
84
+ editor.ui.registry.addMenuItem('validatedlink', {
85
+ icon: 'link',
86
+ text: loc.linkButton,
87
+ onAction: openLinkDialog
88
+ });
89
+ editor.ui.registry.addContextMenu('validatedlink', {
90
+ update: (element) => {
91
+ if (!editor.dom.isEditable(element) ||
92
+ isInHostAnchor(element) ||
93
+ selectionTouchesHostAnchor()) {
94
+ return '';
19
95
  }
20
- let userChangedText = false;
21
- editor.windowManager.open({
22
- title: loc.linkDialogTitle,
23
- body: {
24
- type: 'panel',
25
- items: [
26
- { type: 'input', name: 'url', label: loc.linkUrlLabel },
27
- { type: 'input', name: 'text', label: loc.linkTextLabel },
28
- {
29
- type: 'listbox',
30
- name: 'openIn',
31
- label: loc.linkTargetLabel,
32
- items: [
33
- { text: loc.linkTargetSelf, value: '_self' },
34
- { text: loc.linkTargetBlank, value: '_blank' }
35
- ]
36
- }
37
- ]
38
- },
39
- initialData: {
40
- url: initialUrl,
41
- text: initialText,
42
- openIn: initialTarget
43
- },
44
- buttons: [
45
- { type: 'cancel', text: loc.linkCancelButton },
46
- { type: 'submit', text: loc.linkSaveButton, primary: true }
47
- ],
48
- onChange: (api, details) => {
49
- if (details.name === 'text' && !userChangedText) {
50
- userChangedText = true;
51
- }
52
- if (details.name === 'url') {
53
- const data = api.getData();
54
- if (!userChangedText && !initialText) {
55
- api.setData({ text: data.url });
56
- }
57
- }
58
- },
59
- onSubmit: (api) => {
60
- const data = api.getData();
61
- if (!validateHref(data.url, { allowRelative: 'prefixed' }).valid) {
62
- editor.windowManager.alert(loc.linkUrlInvalid);
63
- return;
64
- }
65
- if (linkNode) {
66
- editor.dom.setAttrib(linkNode, 'href', data.url);
67
- editor.dom.setAttrib(linkNode, 'target', data.openIn);
68
- linkNode.textContent = data.text ?? data.url;
69
- }
70
- else {
71
- editor.insertContent(`<a href="${data.url}" target="${data.openIn}">${data.text ?? data.url}</a>`);
72
- }
73
- api.close();
74
- }
75
- });
96
+ return editor.dom.getParent(element, 'a[href]')
97
+ ? 'validatedlink unlink openlink'
98
+ : 'validatedlink';
76
99
  }
77
100
  });
78
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",