@driftime/sanity-plugin-icon 0.4.2 → 0.5.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.
Files changed (49) hide show
  1. package/README.md +40 -1
  2. package/dist/{adapters-Bx_MyEX_.js → adapters-Dw6yeA3A.js} +2 -3
  3. package/dist/{adapters-Bx_MyEX_.js.map → adapters-Dw6yeA3A.js.map} +1 -1
  4. package/dist/{sets-kepuObH8.js → defaults-BEzCWZtH.js} +2 -39
  5. package/dist/defaults-BEzCWZtH.js.map +1 -0
  6. package/dist/index.d.ts +1 -40
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +4 -144
  9. package/dist/index.js.map +1 -1
  10. package/dist/loader-2g6inuO6.js +96 -0
  11. package/dist/loader-2g6inuO6.js.map +1 -0
  12. package/dist/next-loader.d.ts.map +1 -1
  13. package/dist/next-loader.js +4 -73
  14. package/dist/next-loader.js.map +1 -1
  15. package/dist/next.d.ts +3 -2
  16. package/dist/next.d.ts.map +1 -1
  17. package/dist/next.js +9 -8
  18. package/dist/next.js.map +1 -1
  19. package/dist/{nodes-DAzj56Xn.js → nodes-Bn7fLVZO.js} +47 -3
  20. package/dist/nodes-Bn7fLVZO.js.map +1 -0
  21. package/dist/read-worker.js +2 -2
  22. package/dist/render.d.ts +24 -2
  23. package/dist/render.d.ts.map +1 -1
  24. package/dist/render.js +21 -3
  25. package/dist/render.js.map +1 -1
  26. package/dist/{sets-D5_YGFll.js → sets-B5arQvrZ.js} +59 -6
  27. package/dist/sets-B5arQvrZ.js.map +1 -0
  28. package/dist/sets-DH5UbUV_.js +49 -0
  29. package/dist/sets-DH5UbUV_.js.map +1 -0
  30. package/dist/types-CmTEhJK6.js +189 -0
  31. package/dist/types-CmTEhJK6.js.map +1 -0
  32. package/dist/types-D9GjPlhU.d.ts +59 -0
  33. package/dist/types-D9GjPlhU.d.ts.map +1 -0
  34. package/dist/vite.js +3 -4
  35. package/dist/vite.js.map +1 -1
  36. package/package.json +1 -1
  37. package/dist/drawing-ByrcBbWB.js +0 -50
  38. package/dist/drawing-ByrcBbWB.js.map +0 -1
  39. package/dist/nodes-DAzj56Xn.js.map +0 -1
  40. package/dist/registry-B0Dxiwhh.js +0 -68
  41. package/dist/registry-B0Dxiwhh.js.map +0 -1
  42. package/dist/registry-BEEpqK3z.js +0 -13
  43. package/dist/registry-BEEpqK3z.js.map +0 -1
  44. package/dist/sets-D5_YGFll.js.map +0 -1
  45. package/dist/sets-kepuObH8.js.map +0 -1
  46. package/dist/types-qlHEYDoN.d.ts +0 -20
  47. package/dist/types-qlHEYDoN.d.ts.map +0 -1
  48. package/dist/utils-COPacfAq.js +0 -48
  49. package/dist/utils-COPacfAq.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- import { n as logger, r as pluginName, t as parseIconSet } from "./sets-kepuObH8.js";
2
- import { n as isDefined, t as convertCase } from "./utils-COPacfAq.js";
3
- import { a as resolveIconDrawing, o as serializeIconDrawing } from "./nodes-DAzj56Xn.js";
4
- import { t as Drawing } from "./drawing-ByrcBbWB.js";
5
- import { t as getIconSetKey } from "./registry-BEEpqK3z.js";
1
+ import { n as pluginName, t as logger } from "./defaults-BEzCWZtH.js";
2
+ import { a as resolveIconDrawing, c as isDefined, o as serializeIconDrawing, s as convertCase } from "./nodes-Bn7fLVZO.js";
3
+ import { a as splitMatches, i as selectIcons, n as normalizeTerms, o as Drawing, r as requestLibrary, t as iconTypeName } from "./types-CmTEhJK6.js";
4
+ import { n as getIconSetKey } from "./sets-DH5UbUV_.js";
6
5
  import { ChangeIndicator, FieldActionsProvider, FieldActionsResolver, FormField, defineField, definePlugin, defineType, getPublishedId, set, setIfMissing, unset, useFormValue } from "sanity";
7
6
  import { c } from "react/compiler-runtime";
8
7
  import { createElement, useEffect, useRef, useState } from "react";
@@ -12,7 +11,6 @@ import { Box, Button, Card, Dialog, Flex, Grid, Spinner, Stack, Text, TextInput
12
11
  import { SearchIcon } from "@sanity/icons/Search";
13
12
  import { WarningOutlineIcon } from "@sanity/icons/WarningOutline";
14
13
  import { Popover } from "@sanity/ui/popover";
15
- import { iconRegistry } from "@driftime/sanity-plugin-icon/sets";
16
14
  /**
17
15
  * Checks whether a form node has members, as objects and arrays of objects do.
18
16
  *
@@ -326,142 +324,6 @@ function Recent(t0) {
326
324
  }), $[22] = props, $[23] = t2, $[24] = t4, $[25] = t5) : t5 = $[25], t5;
327
325
  }
328
326
  /**
329
- * Normalises text for search, so hyphenated names and multi-word keywords match the same way.
330
- *
331
- * @param value - The text.
332
- * @returns The normalised text.
333
- */
334
- function normalizeTerms(value) {
335
- return value.toLowerCase().replaceAll(/[\s-]+/gu, " ").trim();
336
- }
337
- /**
338
- * Splits text into the parts a search matches and the parts it doesn't, matching the way search does: ignoring case,
339
- * and treating spaces and hyphens alike.
340
- *
341
- * @param text - The text to split.
342
- * @param query - The normalised search.
343
- * @returns The parts in order, each with where it starts in the text and whether it matches.
344
- */
345
- function splitMatches(text, query) {
346
- if (!isDefined(query)) return [{
347
- text,
348
- start: 0,
349
- match: !1
350
- }];
351
- let pattern = query.split(" ").map((word) => word.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`)).join(String.raw`[\s-]+`), parts = text.split(RegExp(`(${pattern})`, "giu"));
352
- return parts.map((part, index) => ({
353
- text: part,
354
- start: parts.slice(0, index).join("").length,
355
- match: index % 2 == 1
356
- }));
357
- }
358
- /**
359
- * Narrows the library to the named icons, in the order given. Unknown names are skipped, so a list keeps working
360
- * across library releases.
361
- *
362
- * @param library - Every icon in the library.
363
- * @param names - The icons to offer, or undefined for all of them.
364
- * @returns The icons to offer.
365
- */
366
- function selectIcons(library, names) {
367
- if (!isDefined(names)) return library;
368
- let byName = new Map(library.map((icon) => [icon.name, icon]));
369
- return [...new Set(names)].flatMap((name) => {
370
- let icon = byName.get(name);
371
- return isDefined(icon) ? [icon] : [];
372
- });
373
- }
374
- /**
375
- * Lists identifiers as inline code, separated by commas.
376
- *
377
- * @param identifiers - The identifiers.
378
- * @returns The list.
379
- */
380
- function formatList(identifiers) {
381
- return identifiers.map((identifier) => `\`${identifier}\``).join(", ");
382
- }
383
- /**
384
- * Describes why a library the project hasn't installed can't be shown, and what to add.
385
- *
386
- * @param label - Readable name of the library.
387
- * @param packageName - Package the library is read from, or an example of one for a family of packages.
388
- * @param family - Whether the library is a family of packages, one per style.
389
- * @param listed - Whether the project's `package.json` lists the package.
390
- * @param sitePackage - Another package of the library the project lists, or undefined when there's none.
391
- * @returns The problem.
392
- */
393
- function describeMissingLibrary(label, packageName, family, listed, sitePackage) {
394
- return listed ? {
395
- title: `${label} isn't installed yet`,
396
- description: `\`${packageName}\` is in \`package.json\` but not in \`node_modules\`. Reinstall the project's dependencies.`
397
- } : isDefined(sitePackage) ? {
398
- title: `${label} needs \`${packageName}\``,
399
- description: `The Studio reads ${label} from \`${packageName}\`, not \`${sitePackage}\`. Add it as a dev dependency.`
400
- } : {
401
- title: `${label} isn't installed`,
402
- description: family ? `Install a ${label} style package, such as \`${packageName}\`.` : `Install \`${packageName}\` in the project.`
403
- };
404
- }
405
- /**
406
- * Loads one library style from the sets the build step converted.
407
- *
408
- * @param library - Identifier of the library, or undefined when none is set.
409
- * @param style - Identifier of the style, or undefined for the library's default.
410
- * @returns The icons, or why they can't be shown.
411
- */
412
- async function readLibrary(library, style) {
413
- if (!isDefined(library)) return { problem: {
414
- title: "No icon library set",
415
- description: "Set `library` in the icon plugin's configuration or in the field's options."
416
- } };
417
- if (!iconRegistry.ready) return { problem: {
418
- title: "Icons aren't set up",
419
- description: "Add `withIcons()` to the Studio's build configuration, then restart the Studio."
420
- } };
421
- let info = iconRegistry.libraries[library];
422
- if (!isDefined(info)) return { problem: {
423
- title: "Unknown icon library",
424
- description: `There's no icon library called \`${library}\`. Use one of: ${formatList(Object.keys(iconRegistry.libraries))}.`
425
- } };
426
- let { label, packageName, packagePrefix, styles, listed, installed, sitePackage } = info;
427
- if (!installed) return { problem: describeMissingLibrary(label, packageName, isDefined(packagePrefix), listed, sitePackage) };
428
- let resolvedStyle = style ?? styles[0] ?? "", loader = iconRegistry.sets[getIconSetKey(library, resolvedStyle)];
429
- if (!isDefined(loader)) return { problem: isDefined(packagePrefix) ? {
430
- title: `${label} style \`${resolvedStyle}\` isn't installed`,
431
- description: `Install \`${packagePrefix}${resolvedStyle}\` in the project.`
432
- } : {
433
- title: `Unknown ${label} style`,
434
- description: `${label} has no \`${resolvedStyle}\` style. Use one of: ${formatList(styles)}.`
435
- } };
436
- let module = await loader(), set = parseIconSet(module.default);
437
- return isDefined(set) ? { icons: set.icons.map(({ name, keywords, node, root }) => ({
438
- name,
439
- label: convertCase(name, "title"),
440
- tags: keywords.join(", "),
441
- drawing: {
442
- root: root ?? set.root,
443
- node
444
- },
445
- terms: normalizeTerms([name, ...keywords].join(" "))
446
- })) } : { problem: {
447
- title: `Couldn't load ${label}`,
448
- description: "Restart the Studio and try again."
449
- } };
450
- }
451
- /** Library requests shared by every field in the session, keyed by library and style, since the data never changes. */
452
- const libraryRequests = /* @__PURE__ */ new Map();
453
- /**
454
- * Loads a library style, reusing a request already in progress.
455
- *
456
- * @param library - Identifier of the library, or undefined when none is set.
457
- * @param style - Identifier of the style, or undefined for the library's default.
458
- * @returns The icons, or why they can't be shown.
459
- */
460
- async function requestLibrary(library, style) {
461
- let key = getIconSetKey(library ?? "", style ?? ""), request = libraryRequests.get(key);
462
- return isDefined(request) || (request = readLibrary(library, style), libraryRequests.set(key, request)), await request;
463
- }
464
- /**
465
327
  * Gap between the tooltip and its cell, set through margins because `@sanity/ui` offers no other way.
466
328
  * Only the top is set, since the tooltip always appears above the cell.
467
329
  */
@@ -938,8 +800,6 @@ function resolveIconOptions(options, config) {
938
800
  icons
939
801
  };
940
802
  }
941
- /** Schema type name of the icon object. */
942
- const iconTypeName = "icon";
943
803
  /**
944
804
  * Creates the patches that store an icon, with the library and style it was chosen from.
945
805
  *