@overlastic/svelte 0.8.0 → 0.8.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/dist/index.js CHANGED
@@ -1,63 +1,332 @@
1
- // src/define/constructor.ts
2
- import { createConstructor } from "@overlastic/core";
3
-
4
- // src/internal/index.ts
5
- var injectOverlayKey = Symbol("overlays:svelte");
6
- var injectOptionsKey = Symbol("overlays:options");
7
-
8
- // src/define/constructor.ts
9
- var constructor = createConstructor((Inst, props, options) => {
10
- const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
11
- function vanish() {
12
- app.$destroy();
13
- container.remove();
1
+ // src/components/index.ts
2
+ import { delay } from "@overlastic/core";
3
+ import { getContext, onMount } from "svelte";
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? `${key}` : key, value);
7
+ function noop() {
8
+ }
9
+ function assign(tar, src) {
10
+ for (const k in src) tar[k] = src[k];
11
+ return (
12
+ /** @type {T & S} */
13
+ tar
14
+ );
15
+ }
16
+ function run(fn) {
17
+ return fn();
18
+ }
19
+ function blank_object() {
20
+ return /* @__PURE__ */ Object.create(null);
21
+ }
22
+ function run_all(fns) {
23
+ fns.forEach(run);
24
+ }
25
+ function is_function(thing) {
26
+ return typeof thing === "function";
27
+ }
28
+ function safe_not_equal(a, b) {
29
+ return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
30
+ }
31
+ function is_empty(obj) {
32
+ return Object.keys(obj).length === 0;
33
+ }
34
+ function create_slot(definition, ctx, $$scope, fn) {
35
+ if (definition) {
36
+ const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
37
+ return definition[0](slot_ctx);
14
38
  }
15
- const context = new Map([..._context.entries()]);
16
- context.set(injectOverlayKey, {
17
- resolve: deferred.resolve,
18
- reject: deferred.reject,
19
- deferred,
20
- visible: false,
21
- vanish
39
+ }
40
+ function get_slot_context(definition, ctx, $$scope, fn) {
41
+ return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;
42
+ }
43
+ function get_slot_changes(definition, $$scope, dirty, fn) {
44
+ if (definition[2] && fn)
45
+ ;
46
+ return $$scope.dirty;
47
+ }
48
+ function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
49
+ if (slot_changes) {
50
+ const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
51
+ slot.p(slot_context, slot_changes);
52
+ }
53
+ }
54
+ function get_all_dirty_from_scope($$scope) {
55
+ if ($$scope.ctx.length > 32) {
56
+ const dirty = [];
57
+ const length = $$scope.ctx.length / 32;
58
+ for (let i = 0; i < length; i++) {
59
+ dirty[i] = -1;
60
+ }
61
+ return dirty;
62
+ }
63
+ return -1;
64
+ }
65
+ function insert(target, node, anchor) {
66
+ target.insertBefore(node, anchor || null);
67
+ }
68
+ function detach(node) {
69
+ if (node.parentNode) {
70
+ node.parentNode.removeChild(node);
71
+ }
72
+ }
73
+ function text(data) {
74
+ return document.createTextNode(data);
75
+ }
76
+ function empty() {
77
+ return text("");
78
+ }
79
+ function children(element) {
80
+ return Array.from(element.childNodes);
81
+ }
82
+ var current_component;
83
+ function set_current_component(component) {
84
+ current_component = component;
85
+ }
86
+ var dirty_components = [];
87
+ var binding_callbacks = [];
88
+ var render_callbacks = [];
89
+ var flush_callbacks = [];
90
+ var resolved_promise = /* @__PURE__ */ Promise.resolve();
91
+ var update_scheduled = false;
92
+ function schedule_update() {
93
+ if (!update_scheduled) {
94
+ update_scheduled = true;
95
+ resolved_promise.then(flush);
96
+ }
97
+ }
98
+ function add_render_callback(fn) {
99
+ render_callbacks.push(fn);
100
+ }
101
+ var seen_callbacks = /* @__PURE__ */ new Set();
102
+ var flushidx = 0;
103
+ function flush() {
104
+ if (flushidx !== 0) {
105
+ return;
106
+ }
107
+ const saved_component = current_component;
108
+ do {
109
+ try {
110
+ while (flushidx < dirty_components.length) {
111
+ const component = dirty_components[flushidx];
112
+ flushidx++;
113
+ set_current_component(component);
114
+ update(component.$$);
115
+ }
116
+ } catch (e) {
117
+ dirty_components.length = 0;
118
+ flushidx = 0;
119
+ throw e;
120
+ }
121
+ set_current_component(null);
122
+ dirty_components.length = 0;
123
+ flushidx = 0;
124
+ while (binding_callbacks.length) binding_callbacks.pop()();
125
+ for (let i = 0; i < render_callbacks.length; i += 1) {
126
+ const callback = render_callbacks[i];
127
+ if (!seen_callbacks.has(callback)) {
128
+ seen_callbacks.add(callback);
129
+ callback();
130
+ }
131
+ }
132
+ render_callbacks.length = 0;
133
+ } while (dirty_components.length);
134
+ while (flush_callbacks.length) {
135
+ flush_callbacks.pop()();
136
+ }
137
+ update_scheduled = false;
138
+ seen_callbacks.clear();
139
+ set_current_component(saved_component);
140
+ }
141
+ function update($$) {
142
+ if ($$.fragment !== null) {
143
+ $$.update();
144
+ run_all($$.before_update);
145
+ const dirty = $$.dirty;
146
+ $$.dirty = [-1];
147
+ $$.fragment && $$.fragment.p($$.ctx, dirty);
148
+ $$.after_update.forEach(add_render_callback);
149
+ }
150
+ }
151
+ function flush_render_callbacks(fns) {
152
+ const filtered = [];
153
+ const targets = [];
154
+ render_callbacks.forEach((c) => !fns.includes(c) ? filtered.push(c) : targets.push(c));
155
+ targets.forEach((c) => c());
156
+ render_callbacks = filtered;
157
+ }
158
+ var outroing = /* @__PURE__ */ new Set();
159
+ var outros;
160
+ function group_outros() {
161
+ outros = {
162
+ r: 0,
163
+ c: [],
164
+ p: outros
165
+ // parent group
166
+ };
167
+ }
168
+ function check_outros() {
169
+ if (!outros.r) {
170
+ run_all(outros.c);
171
+ }
172
+ outros = outros.p;
173
+ }
174
+ function transition_in(block, local) {
175
+ if (block && block.i) {
176
+ outroing.delete(block);
177
+ block.i(local);
178
+ }
179
+ }
180
+ function transition_out(block, local, detach2, callback) {
181
+ if (block && block.o) {
182
+ if (outroing.has(block))
183
+ return;
184
+ outroing.add(block);
185
+ outros.c.push(() => {
186
+ outroing.delete(block);
187
+ if (callback) {
188
+ if (detach2)
189
+ block.d(1);
190
+ callback();
191
+ }
192
+ });
193
+ block.o(local);
194
+ } else if (callback) {
195
+ callback();
196
+ }
197
+ }
198
+ function mount_component(component, target, anchor) {
199
+ const { fragment, after_update } = component.$$;
200
+ fragment && fragment.m(target, anchor);
201
+ add_render_callback(() => {
202
+ const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
203
+ if (component.$$.on_destroy) {
204
+ component.$$.on_destroy.push(...new_on_destroy);
205
+ } else {
206
+ run_all(new_on_destroy);
207
+ }
208
+ component.$$.on_mount = [];
22
209
  });
23
- const app = new Inst({
24
- target: container,
210
+ after_update.forEach(add_render_callback);
211
+ }
212
+ function destroy_component(component, detaching) {
213
+ const $$ = component.$$;
214
+ if ($$.fragment !== null) {
215
+ flush_render_callbacks($$.after_update);
216
+ run_all($$.on_destroy);
217
+ $$.fragment && $$.fragment.d(detaching);
218
+ $$.on_destroy = $$.fragment = null;
219
+ $$.ctx = [];
220
+ }
221
+ }
222
+ function make_dirty(component, i) {
223
+ if (component.$$.dirty[0] === -1) {
224
+ dirty_components.push(component);
225
+ schedule_update();
226
+ component.$$.dirty.fill(0);
227
+ }
228
+ component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
229
+ }
230
+ function init(component, options, instance2, create_fragment2, not_equal, props, append_styles = null, dirty = [-1]) {
231
+ const parent_component = current_component;
232
+ set_current_component(component);
233
+ const $$ = component.$$ = {
234
+ fragment: null,
235
+ ctx: [],
236
+ // state
25
237
  props,
26
- context
27
- });
28
- });
29
-
30
- // src/define/index.ts
31
- var defineOverlay = constructor.define;
32
- var renderOverlay = constructor.render;
33
-
34
- // src/composable/define.ts
35
- import { getContext, setContext } from "svelte";
36
- function useExtendOverlay(options = {}) {
37
- setContext(injectOptionsKey, options);
38
- return getContext(injectOverlayKey);
238
+ update: noop,
239
+ not_equal,
240
+ bound: blank_object(),
241
+ // lifecycle
242
+ on_mount: [],
243
+ on_destroy: [],
244
+ on_disconnect: [],
245
+ before_update: [],
246
+ after_update: [],
247
+ context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
248
+ // everything else
249
+ callbacks: blank_object(),
250
+ dirty,
251
+ skip_bound: false,
252
+ root: options.target || parent_component.$$.root
253
+ };
254
+ append_styles && append_styles($$.root);
255
+ let ready = false;
256
+ $$.ctx = instance2 ? instance2(component, options.props || {}, (i, ret, ...rest) => {
257
+ const value = rest.length ? rest[0] : ret;
258
+ if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
259
+ if (!$$.skip_bound && $$.bound[i])
260
+ $$.bound[i](value);
261
+ if (ready)
262
+ make_dirty(component, i);
263
+ }
264
+ return ret;
265
+ }) : [];
266
+ $$.update();
267
+ ready = true;
268
+ run_all($$.before_update);
269
+ $$.fragment = create_fragment2 ? create_fragment2($$.ctx) : false;
270
+ if (options.target) {
271
+ if (options.hydrate) {
272
+ const nodes = children(options.target);
273
+ $$.fragment && $$.fragment.l(nodes);
274
+ nodes.forEach(detach);
275
+ } else {
276
+ $$.fragment && $$.fragment.c();
277
+ }
278
+ if (options.intro)
279
+ transition_in(component.$$.fragment);
280
+ mount_component(component, options.target, options.anchor);
281
+ flush();
282
+ }
283
+ set_current_component(parent_component);
39
284
  }
40
-
41
- // src/components/index.ts
42
- import { getContext as getContext2, onMount } from "svelte";
43
- import { delay } from "@overlastic/core";
44
- import {
45
- SvelteComponentTyped,
46
- check_outros,
47
- create_slot,
48
- detach,
49
- empty,
50
- get_all_dirty_from_scope,
51
- get_slot_changes,
52
- group_outros,
53
- init,
54
- insert,
55
- noop,
56
- safe_not_equal,
57
- transition_in,
58
- transition_out,
59
- update_slot_base
60
- } from "svelte/internal";
285
+ var SvelteComponent = class {
286
+ constructor() {
287
+ __publicField(this, "$$");
288
+ __publicField(this, "$$set");
289
+ }
290
+ /** @returns {void} */
291
+ $destroy() {
292
+ destroy_component(this, 1);
293
+ this.$destroy = noop;
294
+ }
295
+ /**
296
+ * @template {Extract<keyof Events, string>} K
297
+ * @param {K} type
298
+ * @param {((e: Events[K]) => void) | null | undefined} callback
299
+ * @returns {() => void}
300
+ */
301
+ $on(type, callback) {
302
+ if (!is_function(callback)) {
303
+ return noop;
304
+ }
305
+ const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
306
+ callbacks.push(callback);
307
+ return () => {
308
+ const index = callbacks.indexOf(callback);
309
+ if (index !== -1)
310
+ callbacks.splice(index, 1);
311
+ };
312
+ }
313
+ /**
314
+ * @param {Partial<Props>} props
315
+ * @returns {void}
316
+ */
317
+ $set(props) {
318
+ if (this.$$set && !is_empty(props)) {
319
+ this.$$.skip_bound = true;
320
+ this.$$set(props);
321
+ this.$$.skip_bound = false;
322
+ }
323
+ }
324
+ };
325
+ var PUBLIC_VERSION = "4";
326
+ if (typeof window !== "undefined")
327
+ (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(PUBLIC_VERSION);
328
+ var injectOverlayKey = Symbol("overlays:svelte");
329
+ var injectOptionsKey = Symbol("overlays:options");
61
330
  function create_if_block(ctx) {
62
331
  let current;
63
332
  const default_slot_template = (
@@ -77,8 +346,9 @@ function create_if_block(ctx) {
77
346
  default_slot.c();
78
347
  },
79
348
  m(target, anchor) {
80
- if (default_slot)
349
+ if (default_slot) {
81
350
  default_slot.m(target, anchor);
351
+ }
82
352
  current = true;
83
353
  },
84
354
  p(ctx2, dirty) {
@@ -147,8 +417,9 @@ function create_fragment(ctx) {
147
417
  ) {
148
418
  if (if_block) {
149
419
  if_block.p(ctx2, dirty);
150
- if (dirty & 1)
420
+ if (dirty & 1) {
151
421
  transition_in(if_block, 1);
422
+ }
152
423
  } else {
153
424
  if_block = create_if_block(ctx2);
154
425
  if_block.c();
@@ -163,37 +434,36 @@ function create_fragment(ctx) {
163
434
  check_outros();
164
435
  }
165
436
  },
166
- i() {
437
+ i(local) {
167
438
  if (current)
168
439
  return;
169
440
  transition_in(if_block);
170
441
  current = true;
171
442
  },
172
- o() {
443
+ o(local) {
173
444
  transition_out(if_block);
174
445
  current = false;
175
446
  },
176
447
  d(detaching) {
448
+ if (detaching) {
449
+ detach(if_block_anchor);
450
+ }
177
451
  if (if_block)
178
452
  if_block.d(detaching);
179
- if (detaching)
180
- detach(if_block_anchor);
181
453
  }
182
454
  };
183
455
  }
184
456
  function instance($$self, $$props, $$invalidate) {
185
457
  let { $$slots: slots = {}, $$scope } = $$props;
186
458
  let { visible = false } = $$props;
187
- const { duration = 0, immediate = true } = getContext2(injectOptionsKey) || {};
188
- const { deferred, vanish } = getContext2(injectOverlayKey);
189
- async function destroy() {
459
+ const { duration = 0 } = getContext(injectOptionsKey) || {};
460
+ const { deferred, vanish } = getContext(injectOverlayKey);
461
+ deferred == null ? void 0 : deferred.finally(async () => {
190
462
  $$invalidate(0, visible = false);
191
463
  await delay(duration);
192
- vanish == null ? void 0 : vanish();
193
- return Promise.resolve();
194
- }
195
- onMount(() => immediate && $$invalidate(0, visible = true));
196
- deferred == null ? void 0 : deferred.then(destroy).catch(destroy);
464
+ vanish();
465
+ });
466
+ onMount(() => $$invalidate(0, visible = true));
197
467
  $$self.$$set = ($$props2) => {
198
468
  if ("visible" in $$props2)
199
469
  $$invalidate(0, visible = $$props2.visible);
@@ -202,15 +472,56 @@ function instance($$self, $$props, $$invalidate) {
202
472
  };
203
473
  return [visible, $$scope, slots];
204
474
  }
205
- var Overlay = class extends SvelteComponentTyped {
475
+ var _Overlay = class extends SvelteComponent {
206
476
  constructor(options) {
207
- super(options);
208
- init(this, options, instance, create_fragment, safe_not_equal, { visible: 0 }, noop);
477
+ super();
478
+ init(this, options, instance, create_fragment, safe_not_equal, { visible: 0 });
209
479
  }
210
480
  };
481
+ var Overlay = _Overlay;
482
+
483
+ // src/composable/define.ts
484
+ import { getContext as getContext2, setContext } from "svelte";
485
+
486
+ // src/internal/index.ts
487
+ var injectOverlayKey2 = Symbol("overlays:svelte");
488
+ var injectOptionsKey2 = Symbol("overlays:options");
489
+
490
+ // src/composable/define.ts
491
+ function useDisclosure(options = {}) {
492
+ setContext(injectOptionsKey2, options);
493
+ return getContext2(injectOverlayKey2);
494
+ }
495
+
496
+ // src/define/constructor.ts
497
+ import { createConstructor } from "@overlastic/core";
498
+ var constructor = createConstructor((Inst, props, options) => {
499
+ const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
500
+ function vanish() {
501
+ app.$destroy();
502
+ container.remove();
503
+ }
504
+ const context = new Map([..._context.entries()]);
505
+ context.set(injectOverlayKey2, {
506
+ confirm: deferred.confirm,
507
+ cannel: deferred.cancel,
508
+ deferred,
509
+ visible: false,
510
+ vanish
511
+ });
512
+ const app = new Inst({
513
+ target: container,
514
+ props,
515
+ context
516
+ });
517
+ });
518
+
519
+ // src/define/index.ts
520
+ var defineOverlay = constructor.define;
521
+ var renderOverlay = constructor.render;
211
522
  export {
212
523
  Overlay,
213
524
  defineOverlay,
214
525
  renderOverlay,
215
- useExtendOverlay
526
+ useDisclosure
216
527
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@overlastic/svelte",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/hairyf/overlastic#readme",
7
7
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "svelte": "^3.57.0",
29
- "@overlastic/core": "^0.8.0"
28
+ "svelte": "^4.0.0",
29
+ "@overlastic/core": "^0.8.3"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts",