@servicetitan/anvil2-ext-common 0.4.0 → 0.5.1
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/CHANGELOG.md +22 -0
- package/dist/Suggestions-ChGGcGuO.js +47 -0
- package/dist/Suggestions-ChGGcGuO.js.map +1 -0
- package/dist/Suggestions.d.ts +1 -0
- package/dist/Suggestions.js +2 -0
- package/dist/Suggestions.js.map +1 -0
- package/dist/index.js +8 -35313
- package/dist/index.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.d.ts +59 -0
- package/dist/src/components/Suggestions/index.d.ts +2 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/form/components/FormMultiSelect/FormMultiSelect.d.ts +1 -1
- package/dist/src/form/components/FormSelect/FormSelect.d.ts +1 -1
- package/package.json +5 -4
- package/dist/index.css +0 -2911
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @servicetitan/anvil2-ext-common
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2424](https://github.com/servicetitan/hammer/pull/2424) [`7015549`](https://github.com/servicetitan/hammer/commit/7015549817ceaa7400eb32b7dff172e21d8ba673) Thanks [@pbuckingham-st](https://github.com/pbuckingham-st)! - No longer bundles a copy of `@servicetitan/anvil2`; it is now a peer dependency. This fixes anvil2 components (e.g. `ButtonToggle`/`FilterBar`) rendering with incorrect styling in apps that load both `@servicetitan/anvil2` and `@servicetitan/anvil2-ext-common`.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e975960`](https://github.com/servicetitan/hammer/commit/e975960082858a46e7a49d01c4bb9628cb39ddb7), [`daaa703`](https://github.com/servicetitan/hammer/commit/daaa703508f434218151b09ec3e09c99e7f7ba2d), [`9eb595b`](https://github.com/servicetitan/hammer/commit/9eb595be23bd648c339b58a331f3b60d4a0d7f15), [`e536233`](https://github.com/servicetitan/hammer/commit/e53623374fc9300964e1c758d48a7bf4d1d5f5fa), [`9eb595b`](https://github.com/servicetitan/hammer/commit/9eb595be23bd648c339b58a331f3b60d4a0d7f15)]:
|
|
10
|
+
- @servicetitan/anvil2@3.3.0
|
|
11
|
+
|
|
12
|
+
## 0.5.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#2386](https://github.com/servicetitan/hammer/pull/2386) [`efd6121`](https://github.com/servicetitan/hammer/commit/efd6121759713cefb12e51387183bc97c0c3aec6) Thanks [@hbartlett-st](https://github.com/hbartlett-st)! - [Suggestions] Add new render-prop component that coordinates highlighting fields populated by a suggestion until they are edited. Exposes `suggestable` and `suggestor` prop-getters plus imperative `markSuggested`, `clearHighlight`, and `isHighlighted` methods.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#2417](https://github.com/servicetitan/hammer/pull/2417) [`4c60241`](https://github.com/servicetitan/hammer/commit/4c602418f0fb7da06961e76781b44bac02d0a7d0) Thanks [@hbartlett-st](https://github.com/hbartlett-st)! - [Dependencies] Loosen `@servicetitan/anvil2` dependency to `workspace:^` so consumers resolve a caret range instead of a pinned version
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`efd6121`](https://github.com/servicetitan/hammer/commit/efd6121759713cefb12e51387183bc97c0c3aec6), [`58eb789`](https://github.com/servicetitan/hammer/commit/58eb78970e47ffeabbe57a97c345cdbe8edd4a01), [`1c606c5`](https://github.com/servicetitan/hammer/commit/1c606c5f0bd4d7416cb0f4b6fcb409c4b6377d6b), [`efd6121`](https://github.com/servicetitan/hammer/commit/efd6121759713cefb12e51387183bc97c0c3aec6), [`efd6121`](https://github.com/servicetitan/hammer/commit/efd6121759713cefb12e51387183bc97c0c3aec6)]:
|
|
23
|
+
- @servicetitan/anvil2@3.2.0
|
|
24
|
+
|
|
3
25
|
## 0.4.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
const wrap = (handlers, before) => {
|
|
5
|
+
if (!handlers) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const out = {};
|
|
9
|
+
for (const name of Object.keys(handlers)) {
|
|
10
|
+
const fn = handlers[name];
|
|
11
|
+
out[name] = (...args) => {
|
|
12
|
+
before();
|
|
13
|
+
fn?.(...args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
};
|
|
18
|
+
function Suggestions({ children }) {
|
|
19
|
+
const [suggested, setSuggested] = useState(
|
|
20
|
+
() => /* @__PURE__ */ new Set()
|
|
21
|
+
);
|
|
22
|
+
const registry = useRef(/* @__PURE__ */ new Set());
|
|
23
|
+
const markSuggested = (keys) => setSuggested(new Set(keys ?? [...registry.current]));
|
|
24
|
+
const clearHighlight = (key) => setSuggested((prev) => {
|
|
25
|
+
if (!prev.has(key)) return prev;
|
|
26
|
+
const next = new Set(prev);
|
|
27
|
+
next.delete(key);
|
|
28
|
+
return next;
|
|
29
|
+
});
|
|
30
|
+
const api = {
|
|
31
|
+
suggestable: (key, handlers) => {
|
|
32
|
+
registry.current.add(key);
|
|
33
|
+
return {
|
|
34
|
+
isHighlighted: suggested.has(key),
|
|
35
|
+
...wrap(handlers, () => clearHighlight(key))
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
suggestor: (handlers, keys) => wrap(handlers, () => markSuggested(keys)),
|
|
39
|
+
markSuggested,
|
|
40
|
+
clearHighlight,
|
|
41
|
+
isHighlighted: (key) => suggested.has(key)
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(api) });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { Suggestions as S };
|
|
47
|
+
//# sourceMappingURL=Suggestions-ChGGcGuO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suggestions-ChGGcGuO.js","sources":["../src/components/Suggestions/Suggestions.tsx"],"sourcesContent":["import { ReactNode, useRef, useState } from \"react\";\n\n/* eslint-disable @typescript-eslint/no-explicit-any -- prop getters are\n * intentionally field-agnostic: they wrap whatever change handlers a given\n * field exposes (onChange, onSelectedOptionChange, ...) without caring about\n * their argument shapes. */\ntype Handler = (...args: any[]) => void;\ntype Handlers = Record<string, Handler | undefined>;\n\nexport interface SuggestionsApi {\n /**\n * Props for a field that should be highlighted while it holds a suggested\n * value. Returns `isHighlighted` plus copies of any handlers you pass, each\n * wrapped to clear the highlight on the first user edit. Pass the handler\n * under the field's own prop name (`onChange`, `onSelectedOptionChange`, ...).\n *\n * @example <TextField {...suggestable(\"city\", { onChange: setCity })} />\n */\n suggestable: <O extends Handlers>(\n key: string,\n handlers?: O,\n ) => { isHighlighted: boolean } & O;\n /**\n * Props for the field whose selection populates the others. Returns copies of\n * the handlers you pass, each wrapped to first mark the suggestable fields as\n * highlighted. Your handler still does the value population.\n *\n * @param keys which fields to highlight; defaults to every registered key.\n * @example <TypeaheadTextField {...suggestor({ onSelectOption: apply })} />\n */\n suggestor: <O extends Handlers>(handlers?: O, keys?: string[]) => O;\n /** Imperatively highlight fields (defaults to every registered key). */\n markSuggested: (keys?: string[]) => void;\n /** Imperatively clear a field's highlight. */\n clearHighlight: (key: string) => void;\n /** Whether a field is currently holding a suggested value. */\n isHighlighted: (key: string) => boolean;\n}\n\nexport interface SuggestionsProps {\n children: (api: SuggestionsApi) => ReactNode;\n}\n\nconst wrap = <O extends Handlers>(\n handlers: O | undefined,\n before: () => void,\n): O => {\n if (!handlers) {\n return {} as O;\n }\n\n const out: Handlers = {};\n for (const name of Object.keys(handlers)) {\n const fn = handlers[name];\n out[name] = (...args) => {\n before();\n fn?.(...args);\n };\n }\n return out as O;\n};\n\n/**\n * Coordinates the \"highlight fields populated by a suggestion until edited\"\n * behavior for a group of fields, without per-field state wiring.\n *\n * Relies on the fact that a controlled field's change handler fires only on\n * user input, never when its `value` prop changes programmatically — so we\n * track provenance per field rather than comparing values. A field stays\n * un-highlighted after an edit even if the suggested value is re-entered,\n * because typing still fires the handler.\n *\n * @example\n * <Suggestions>\n * {({ suggestor, suggestable }) => (\n * <>\n * <TypeaheadTextField\n * {...suggestor({ onSelectOption: (opt) => applyAddress(opt.value) })}\n * loadOptions={lookupAddresses}\n * />\n * <TextField {...suggestable(\"city\", { onChange: handleCity })} />\n * </>\n * )}\n * </Suggestions>\n */\nexport function Suggestions({ children }: SuggestionsProps) {\n const [suggested, setSuggested] = useState<ReadonlySet<string>>(\n () => new Set(),\n );\n const registry = useRef<Set<string>>(new Set());\n\n const markSuggested = (keys?: string[]) =>\n setSuggested(new Set(keys ?? [...registry.current]));\n\n const clearHighlight = (key: string) =>\n setSuggested((prev) => {\n if (!prev.has(key)) return prev; // keep referential stability\n const next = new Set(prev);\n next.delete(key);\n return next;\n });\n\n const api: SuggestionsApi = {\n suggestable: (key, handlers) => {\n registry.current.add(key); // learn keys so markSuggested() can target all\n return {\n isHighlighted: suggested.has(key),\n ...wrap(handlers, () => clearHighlight(key)),\n };\n },\n suggestor: (handlers, keys) => wrap(handlers, () => markSuggested(keys)),\n markSuggested,\n clearHighlight,\n isHighlighted: (key) => suggested.has(key),\n };\n\n return <>{children(api)}</>;\n}\n"],"names":[],"mappings":";;;AA2CA,MAAM,IAAA,GAAO,CACX,QAAA,EACA,MAAA,KACM;AACN,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,MAAgB,EAAC;AACvB,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxC,IAAA,MAAM,EAAA,GAAK,SAAS,IAAI,CAAA;AACxB,IAAA,GAAA,CAAI,IAAI,CAAA,GAAI,CAAA,GAAI,IAAA,KAAS;AACvB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