@arcgis/lumina 5.1.0-next.87 → 5.1.0-next.89

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.
@@ -12,6 +12,7 @@ export { useWatchAttributes } from './useWatchAttributes.ts';
12
12
  export { load } from './load.ts';
13
13
  export { proxyExports } from './proxyExports.ts';
14
14
  export { toFunction } from './toFunction.ts';
15
+ export { useSlottableRequest } from './useSlottableRequest.ts';
15
16
  export * from './types.ts';
16
17
  export { useMedia } from './useMedia.ts';
17
18
  export { useDirection } from './useDirection.ts';
@@ -1,4 +1,4 @@
1
- import { C as Controller, t as trackKey, a as createEventFactory, p as propertyTrackResolve } from "../Controller-Cer_6Z29.js";
1
+ import { C as Controller, c as createEvent, t as trackKey, a as createEventFactory, p as propertyTrackResolve } from "../Controller-Cer_6Z29.js";
2
2
  import { G, b, d } from "../Controller-Cer_6Z29.js";
3
3
  import { a as setAmbientComponent, i as isPromise, b as setParentController, d as retrieveParentControllers, r as retrieveComponent } from "../ControllerInternals-CeDntN3G.js";
4
4
  import { e, c, g, f } from "../ControllerInternals-CeDntN3G.js";
@@ -101,6 +101,53 @@ const toFunction = (Class) => (...args) => {
101
101
  setParentController(ambientControllers.at(-1));
102
102
  return instance;
103
103
  };
104
+ const useSlottableRequest = (component, watch, getDetailsBySlotName) => makeController((_component, controller) => {
105
+ const watchedProps = watch;
106
+ const slottableRequestController = createEvent({ bubbles: false, composed: false });
107
+ controller.onUpdated((changes) => {
108
+ if (!watchedProps.some((prop) => changes.has(prop))) {
109
+ return;
110
+ }
111
+ const previousDetails = getDetailsBySlotName(getWatchedProps(component, watchedProps, changes));
112
+ const currentDetails = getDetailsBySlotName(getWatchedProps(component, watchedProps));
113
+ previousDetails.forEach((previousDetail, slotName) => {
114
+ if (!currentDetails.has(slotName)) {
115
+ slottableRequestController.emit({ ...previousDetail, data: void 0 });
116
+ }
117
+ });
118
+ currentDetails.forEach((currentDetail, slotName) => {
119
+ const previousDetail = previousDetails.get(slotName);
120
+ if (!previousDetail || !isEqualValue(previousDetail, currentDetail)) {
121
+ slottableRequestController.emit(currentDetail);
122
+ }
123
+ });
124
+ });
125
+ return slottableRequestController;
126
+ });
127
+ function getWatchedProps(component, watchedProps, changes) {
128
+ const values = {};
129
+ watchedProps.forEach((prop) => {
130
+ values[prop] = changes?.has(prop) ? changes.get(prop) : component[prop];
131
+ });
132
+ return values;
133
+ }
134
+ function isEqualValue(previous, current) {
135
+ if (previous === current) {
136
+ return true;
137
+ }
138
+ if (!previous || !current || typeof previous !== "object" || typeof current !== "object") {
139
+ return false;
140
+ }
141
+ if (Array.isArray(previous) || Array.isArray(current)) {
142
+ return false;
143
+ }
144
+ const previousEntries = Object.entries(previous);
145
+ const currentEntries = Object.entries(current);
146
+ if (previousEntries.length !== currentEntries.length) {
147
+ return false;
148
+ }
149
+ return previousEntries.every(([key, value]) => isEqualValue(value, current[key]));
150
+ }
104
151
  const useMedia = (query) => makeController((_component, controller) => {
105
152
  const media = globalThis.matchMedia(query);
106
153
  const changed = () => {
@@ -278,5 +325,6 @@ export {
278
325
  useDirection,
279
326
  useMedia,
280
327
  usePropertyChange,
328
+ useSlottableRequest,
281
329
  useWatchAttributes
282
330
  };
@@ -0,0 +1,22 @@
1
+ import { EventEmitter } from '../createEvent.ts';
2
+ import { LitElement } from '../LitElement.ts';
3
+ type SlottableRequestDetail = {
4
+ name: string;
5
+ slotName: string;
6
+ data: unknown;
7
+ };
8
+ type WatchedProps<Component extends LitElement, ToWatch extends readonly (keyof Component)[]> = Pick<Component, ToWatch[number]>;
9
+ /**
10
+ * Watches host properties and emits slottable request details when the
11
+ * requested slot details are added, removed, or changed.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const slottableRequest = useSlottableRequest(this, ["item"], ({ item }) => {
16
+ * const details = new Map<string, Detail>();
17
+ * details.set("item-slot", { name: "item", slotName: "item-slot", data: item });
18
+ * return details;
19
+ * });
20
+ */
21
+ export declare const useSlottableRequest: <Component extends LitElement, const ToWatch extends readonly (keyof Component)[], Detail extends SlottableRequestDetail>(component: Component, watch: ToWatch, getDetailsBySlotName: (component: WatchedProps<Component, ToWatch>) => ReadonlyMap<string, Detail>) => EventEmitter<Detail>;
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/lumina",
3
- "version": "5.1.0-next.87",
3
+ "version": "5.1.0-next.89",
4
4
  "description": "Runtime for WebGIS SDK web components",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "csstype": "^3.1.3",
34
34
  "tslib": "^2.8.1",
35
- "@arcgis/toolkit": "~5.1.0-next.87"
35
+ "@arcgis/toolkit": "~5.1.0-next.89"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lit/context": "^1.1.6",