@nomideusz/svelte-calendar 1.8.2 → 1.9.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/README.md CHANGED
@@ -1112,7 +1112,7 @@ The widget renders inside shadow DOM: host-page CSS cannot affect the calendar a
1112
1112
  | `api` | — | Events endpoint, fetched as `GET {api}?start=…&end=…` (ISO instants; appended with `&` if `api` already has a query). It must answer JSON: an array of events, or `{ "events": [...] }`. |
1113
1113
  | `events` | — | Inline JSON array of events, used when there is no `api` |
1114
1114
  | `headers` | — | JSON object of extra request headers for `api`. Without it the GET is a simple CORS request (no preflight). |
1115
- | `readonly` | read-only | The widget is read-only unless `readonly="false"`. There is no write endpoint: with `api`, drags are only visual; with `events`, they are kept in memory. |
1115
+ | `readonly` | read-only | The widget is read-only unless `readonly="false"`. There is no write endpoint: with `api`, drags are only visual; with `events`, they are kept in memory. Either way each committed drag fires `eventmove`. |
1116
1116
  | `view` | `week-planner` | Initial view ID (`week-planner`, `day-agenda`, `month-grid`, …) |
1117
1117
  | `theme` | `auto` | `auto`, `neutral` or `midnight` (unknown names fall back to `neutral`) |
1118
1118
  | `height` | `600` | Height in px (`"600"` or `"600px"`), or `auto` |
@@ -1131,6 +1131,21 @@ The widget renders inside shadow DOM: host-page CSS cannot affect the calendar a
1131
1131
 
1132
1132
  Each event in `api` responses and `events` needs `start` and `end` as date strings (ISO 8601) and may carry `id`, `title`, `color`, `allDay`, `subtitle` and `location`; other fields are ignored, as are events with an invalid or empty range. Changing an attribute updates the calendar in place.
1133
1133
 
1134
+ The element fires two DOM events (they bubble), with the event as the calendar holds it (`start` and `end` as `Date`s):
1135
+
1136
+ | Event | `detail` | When |
1137
+ |-------|----------|------|
1138
+ | `eventclick` | `{ event, anchor }` | An event is clicked or activated with Enter; `anchor` is its block's viewport rect |
1139
+ | `eventmove` | `{ event, start, end }` | A drag or resize committed (only with `readonly="false"`); `event` is the one before the move |
1140
+
1141
+ ```js
1142
+ const cal = document.querySelector('day-calendar');
1143
+ cal.addEventListener('eventclick', (e) => open(e.detail.event.id));
1144
+ cal.addEventListener('eventmove', (e) => save(e.detail.event.id, e.detail.start, e.detail.end));
1145
+ ```
1146
+
1147
+ Keep your own copy in step with `eventmove` if you later set `events` again: a new `events` value replaces what the calendar holds.
1148
+
1134
1149
  ## All Props
1135
1150
 
1136
1151
  Every `<Calendar>` prop (`CalendarProps`), grouped by what it controls.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomideusz/svelte-calendar",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "A themeable Svelte 5 calendar: day, week, scrolling-week and month views, agenda lists, touch-first mobile layouts, drag-and-drop, timezones, a headless API and an embeddable web component.",
5
5
  "type": "module",
6
6
  "sideEffects": [
package/widget/widget.js CHANGED
@@ -20756,6 +20756,7 @@ createHTML: (html) => {
20756
20756
  /** Minimum day-column width in px for the week grid (default: 110) — a narrower container scrolls sideways */
20757
20757
  /** Visible hours of the time grids, "start-end" in whole hours (e.g. "6-22") */
20758
20758
  /** UI words as a JSON object over the English defaults, e.g. '{"today":"Dziś"}' */
20759
+ /** Set by the <day-calendar> element: fires its `eventclick` / `eventmove` DOM events */
20759
20760
  let theme = prop($$props, "theme", 3, "auto"), view = prop($$props, "view", 3, "week-planner"), height = prop($$props, "height", 3, "600"), mondaystart = prop($$props, "mondaystart", 3, "true");
20760
20761
  const heightValue = /* @__PURE__ */ user_derived(() => {
20761
20762
  const trimmed = height().trim();
@@ -20914,7 +20915,16 @@ createHTML: (html) => {
20914
20915
  },
20915
20916
  get labels() {
20916
20917
  return get(labelsValue);
20917
- }
20918
+ },
20919
+ oneventclick: (event, anchor) => $$props.emit?.("eventclick", {
20920
+ event,
20921
+ anchor
20922
+ }),
20923
+ oneventmove: (event, start, end) => $$props.emit?.("eventmove", {
20924
+ event,
20925
+ start,
20926
+ end
20927
+ })
20918
20928
  });
20919
20929
  }
20920
20930
  pop();
@@ -21030,9 +21040,13 @@ createHTML: (html) => {
21030
21040
  this.stylesInjected = true;
21031
21041
  }
21032
21042
  const attrs = createReactiveProps(this.readProps());
21043
+ const emit = (type, detail) => this.dispatchEvent(new CustomEvent(type, {
21044
+ detail,
21045
+ bubbles: true
21046
+ }));
21033
21047
  const component = mount(CalendarWidget, {
21034
21048
  target: root,
21035
- props: attrs.props
21049
+ props: Object.assign(attrs.props, { emit })
21036
21050
  });
21037
21051
  this.instance = {
21038
21052
  component,