frappe-ui 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frappe-ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"
@@ -300,7 +300,6 @@
300
300
  }
301
301
  },
302
302
  "devDependencies": {
303
- "@changesets/changelog-github": "^0.7.0",
304
303
  "@changesets/cli": "^2.31.1",
305
304
  "@codemirror/lang-css": "^6.3.0",
306
305
  "@codemirror/lang-html": "^6.4.9",
@@ -17,6 +17,7 @@ import { useReactiveSlots } from '../../composables/useReactiveSlots'
17
17
  import { usePortalTarget } from '../../composables/usePortalTarget'
18
18
  import { useEmptyValueMapping } from '../shared/selection/useEmptyValueMapping'
19
19
  import { useFilteredGroups } from '../shared/selection/useFilteredGroups'
20
+ import { rankMatch } from '../../utils/rankMatch'
20
21
  import { useIsModelBound } from '../shared/selection/useIsModelBound'
21
22
  import {
22
23
  InputDescription,
@@ -234,6 +235,8 @@ const filteredGroups = useFilteredGroups<NormalizedItem, NormalizedGroup>({
234
235
  item.type === 'custom'
235
236
  ? matchesCustomOption(item, q)
236
237
  : matchesSelectableOption(item, q),
238
+ // custom action rows keep their place; options rank by how well they match
239
+ rank: (item, q) => (item.type === 'custom' ? null : rankMatch(item.label, q)),
237
240
  // `alwaysMatch` carries consumer-declared visibility: a custom row's
238
241
  // `condition` is authoritative and runs even before the user types, so it
239
242
  // is deliberately unaffected by `filterable`.
@@ -40,7 +40,7 @@
40
40
  "
41
41
  @interact-outside="
42
42
  (e: Event) => {
43
- if (!isDismissible) e.preventDefault()
43
+ if (!isDismissible || isEditorFloating(e)) e.preventDefault()
44
44
  }
45
45
  "
46
46
  >
@@ -208,6 +208,13 @@ const slots = useReactiveSlots<DialogSlots>()
208
208
 
209
209
  const isDismissible = computed(() => props.dismissible !== false)
210
210
 
211
+ // the editor's suggestion menus (@mention, /, #, :) live on <body>; picking from one isn't leaving the dialog
212
+ function isEditorFloating(e: Event) {
213
+ return (
214
+ e.target instanceof Element && !!e.target.closest('[data-editor-floating]')
215
+ )
216
+ }
217
+
211
218
  const sizeClass = computed(() => {
212
219
  const map: Record<string, string> = {
213
220
  xs: 'max-w-xs',
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <nav
3
3
  data-slot="mobile-nav"
4
- class="grid shrink-0 auto-cols-fr grid-flow-col border-t border-outline-gray-2 bg-surface-elevation-2 [@media(display-mode:standalone)]:pb-4"
4
+ class="grid shrink-0 auto-cols-fr grid-flow-col border-t border-outline-gray-2 bg-surface-elevation-2 [@media(display-mode:standalone)]:pb-[max(1rem,env(safe-area-inset-bottom))]"
5
5
  >
6
6
  <slot />
7
7
  </nav>
@@ -10,8 +10,9 @@
10
10
  <script setup lang="ts">
11
11
  // A bare grid frame: each MobileNavItem becomes one equal-width column
12
12
  // (auto-cols-fr + grid-flow-col), so the bar adapts to any item count without
13
- // hardcoding a column class. Bottom padding clears the home indicator in an
14
- // installed PWA (display-mode: standalone).
13
+ // hardcoding a column class. In an installed PWA (display-mode: standalone)
14
+ // the bar runs to the bottom edge and its padding clears the home indicator:
15
+ // the safe-area inset, or 1rem where the inset is smaller.
15
16
 
16
17
  defineSlots<{
17
18
  /** One or more `MobileNavItem`s, each becoming an equal-width tab. */
@@ -48,7 +48,10 @@ shell.
48
48
 
49
49
  The content area uses the browser's native scrolling, with momentum and
50
50
  overscroll. The header and the tab bar stay fixed to the edges. In an installed
51
- PWA, the header gets extra top padding to clear the status bar.
51
+ PWA, the header gets extra top padding to clear the status bar, and the tab bar
52
+ gets bottom padding to clear the home indicator. On iOS 26 the tab bar reaches
53
+ the bottom edge only when the app loads `frappe-ui/style.css`, which gives the
54
+ installed app its full-screen viewport.
52
55
 
53
56
  ### Desktop is a separate component
54
57
 
@@ -16,6 +16,7 @@ import { useReactiveSlots } from '../../composables/useReactiveSlots'
16
16
  import { usePortalTarget } from '../../composables/usePortalTarget'
17
17
  import { useEmptyValueMapping } from '../shared/selection/useEmptyValueMapping'
18
18
  import { useFilteredGroups } from '../shared/selection/useFilteredGroups'
19
+ import { rankMatch } from '../../utils/rankMatch'
19
20
  import { useIsModelBound } from '../shared/selection/useIsModelBound'
20
21
  import OptionIcon from '../shared/selection/OptionIcon.vue'
21
22
  import {
@@ -195,6 +196,7 @@ const filteredGroups = useFilteredGroups({
195
196
  hasTypedSinceOpen,
196
197
  query,
197
198
  matches: matchesOption,
199
+ rank: (item, q) => rankMatch(item.label, q),
198
200
  filterable: () => props.filterable ?? true,
199
201
  })
200
202
 
@@ -17,6 +17,10 @@ import {
17
17
  * `condition` callback must be authoritative even before the user
18
18
  * types). Default: include every item.
19
19
  * - On the typing path, items must pass BOTH `alwaysMatch` AND `matches`.
20
+ * - On the typing path, `rank` then orders the matches within each group,
21
+ * lower first; ties keep their source order. Items ranked `null` (e.g.
22
+ * custom action rows) keep their slot. Ranking is skipped when
23
+ * `filterable` is false.
20
24
  * - `filterable: false` switches the `matches` filter off entirely, for
21
25
  * pickers whose options come from a server search — the backend already
22
26
  * decided what matches, and a second literal substring pass on the
@@ -37,6 +41,8 @@ export function useFilteredGroups<
37
41
  hasTypedSinceOpen: Ref<boolean>
38
42
  query: Ref<string>
39
43
  matches: (item: TItem, query: string) => boolean
44
+ /** Orders matches while typing, lower first; `null` keeps an item where it is. */
45
+ rank: (item: TItem, query: string) => number | null
40
46
  alwaysMatch?: (item: TItem) => boolean
41
47
  /** Client-side query filtering. Defaults to `true`. */
42
48
  filterable?: MaybeRefOrGetter<boolean>
@@ -48,14 +54,42 @@ export function useFilteredGroups<
48
54
  filterable && source.open.value && source.hasTypedSinceOpen.value
49
55
 
50
56
  return source.groups.value
51
- .map((group) => ({
52
- ...group,
53
- options: group.options.filter((item) => {
57
+ .map((group) => {
58
+ const options = group.options.filter((item) => {
54
59
  if (!alwaysMatch(item)) return false
55
60
  if (!filterByTypedQuery) return true
56
61
  return source.matches(item, source.query.value)
57
- }),
58
- }))
62
+ })
63
+ return {
64
+ ...group,
65
+ options: filterByTypedQuery
66
+ ? rankOptions(options, source.rank, source.query.value)
67
+ : options,
68
+ }
69
+ })
59
70
  .filter((group) => group.options.length > 0) as TGroup[]
60
71
  })
61
72
  }
73
+
74
+ // sort the rankable items among themselves; unranked items (rank `null`) keep their slot
75
+ function rankOptions<TItem>(
76
+ options: TItem[],
77
+ rank: (item: TItem, query: string) => number | null,
78
+ query: string,
79
+ ): TItem[] {
80
+ const entries = options.map((item, index) => ({
81
+ item,
82
+ index,
83
+ rank: rank(item, query),
84
+ }))
85
+ const ranked = entries
86
+ .filter(
87
+ (entry): entry is { item: TItem; index: number; rank: number } =>
88
+ entry.rank !== null,
89
+ )
90
+ .sort((a, b) => a.rank - b.rank || a.index - b.index)
91
+ let next = 0
92
+ return entries.map((entry) =>
93
+ entry.rank === null ? entry.item : ranked[next++].item,
94
+ )
95
+ }
@@ -17,7 +17,7 @@ import SuggestionList from '../suggestion/SuggestionList.vue'
17
17
  import { warnRemoved } from '#utils/warnDeprecated'
18
18
  import {
19
19
  insertSuggestionNode,
20
- filterByQuery,
20
+ rankByQuery,
21
21
  getSuggestionOptions,
22
22
  } from '#molecules/editor/extensions/shared/suggestion-helpers'
23
23
  import './style.css'
@@ -168,7 +168,7 @@ const MentionSuggestionExtension =
168
168
 
169
169
  // The matched items are passed through as they came in, so the item
170
170
  // slot receives the caller's own object, extra fields and all.
171
- return filterByQuery(mentions, query, 'label').slice(0, 10)
171
+ return rankByQuery(mentions, query, 'label').slice(0, 10)
172
172
  },
173
173
 
174
174
  command: ({ editor, range, props }) => {
@@ -1,6 +1,7 @@
1
1
  import type { Editor, Range } from '@tiptap/core'
2
2
  import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
3
3
  import type { EditorState } from '@tiptap/pm/state'
4
+ import { rankMatch } from '#utils/rankMatch'
4
5
 
5
6
  /**
6
7
  * Shared helpers for slash/emoji/mention/tag suggesters: DRY node-insertion,
@@ -49,6 +50,14 @@ export function filterByQuery<T>(items: T[], query: string, key: keyof T): T[] {
49
50
  })
50
51
  }
51
52
 
53
+ /** `filterByQuery` in `rankMatch` order: best match first, ties keep input order. */
54
+ export function rankByQuery<T>(items: T[], query: string, key: keyof T): T[] {
55
+ return filterByQuery(items, query, key).sort(
56
+ (a, b) =>
57
+ rankMatch(String(a[key]), query) - rankMatch(String(b[key]), query),
58
+ )
59
+ }
60
+
52
61
  /**
53
62
  * True when `pos` sits inside a code context — either a code-block node or text
54
63
  * carrying the inline `code` mark. Suggesters (`@`/`#`/`:`) use this to stay
@@ -96,6 +96,12 @@ export function createSuggestionRenderer(
96
96
 
97
97
  floatingEl = wrapper
98
98
  floatingEl.style.position = 'absolute'
99
+ // A modal Dialog lets this <body> popup take clicks when the editor is
100
+ // inside it. A popup left open in an editor behind the Dialog stays
101
+ // unclickable, so it can't insert into that editor.
102
+ if (props.editor.view.dom.closest('[role=dialog]'))
103
+ floatingEl.style.pointerEvents = 'auto'
104
+ floatingEl.dataset.editorFloating = ''
99
105
  document.body.appendChild(floatingEl)
100
106
  getReferenceClientRect = props.clientRect as () => DOMRect | null
101
107
 
package/src/style.css CHANGED
@@ -14,3 +14,15 @@
14
14
  .no-transition *::after {
15
15
  transition: none !important;
16
16
  }
17
+
18
+ /* MobileShell: iOS 26 sizes an installed web app's viewport short by the status
19
+ bar height while the page is shorter than the screen, so the fixed shell and
20
+ its tab bar stop above a strip of page background (WebKit 301108). A page at
21
+ least as tall as the screen gets the full viewport. The cap keeps the page
22
+ from scrolling in apps with an opaque status bar, where 100lvh overstates the
23
+ viewport and the top inset is 0 (WebKit 316008). */
24
+ @media (display-mode: standalone) {
25
+ html {
26
+ min-height: min(100lvh, calc(100% + env(safe-area-inset-top)));
27
+ }
28
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * How well `text` matches `query`, lower is better. Case-insensitive.
3
+ *
4
+ * 0: exact match, or an empty query
5
+ * 1: `text` starts with the query
6
+ * 2: a word in `text` starts with the query (words split on anything that is
7
+ * not a letter or digit)
8
+ * 3: any other match
9
+ */
10
+ export function rankMatch(text: string, query: string): number {
11
+ const normalizedText = text.toLowerCase()
12
+ const normalizedQuery = query.toLowerCase()
13
+ if (!normalizedQuery || normalizedText === normalizedQuery) return 0
14
+ if (normalizedText.startsWith(normalizedQuery)) return 1
15
+ const words = normalizedText.split(/[^\p{L}\p{N}]+/u)
16
+ if (words.some((word) => word.startsWith(normalizedQuery))) return 2
17
+ return 3
18
+ }
@@ -0,0 +1,36 @@
1
+ import path from 'path'
2
+ import { findBenchPath } from './utils.js'
3
+
4
+ const SITES_IMPORT = /^(?:\.\.\/)+sites\/(.+)$/
5
+
6
+ // Apps read bench files with a relative import such as
7
+ // '../../../../sites/common_site_config.json', which only resolves while the app
8
+ // sits in the bench's apps/ folder. When it does not, as for an app linked into
9
+ // apps/ from elsewhere, resolve the file in the bench instead.
10
+ export function benchFiles() {
11
+ return {
12
+ name: 'frappeui-bench-files',
13
+ enforce: 'pre',
14
+ async resolveId(source, importer, options) {
15
+ const match = source.match(SITES_IMPORT)
16
+ if (!match) {
17
+ return null
18
+ }
19
+ const resolved = await this.resolve(source, importer, {
20
+ ...options,
21
+ skipSelf: true,
22
+ })
23
+ if (resolved) {
24
+ return resolved
25
+ }
26
+ const benchPath = findBenchPath()
27
+ if (!benchPath) {
28
+ return null
29
+ }
30
+ return this.resolve(path.join(benchPath, 'sites', match[1]), importer, {
31
+ ...options,
32
+ skipSelf: true,
33
+ })
34
+ },
35
+ }
36
+ }
package/vite/index.js CHANGED
@@ -6,6 +6,7 @@ import { buildConfig } from './buildConfig.js'
6
6
  import { siteBanner } from './siteBanner.js'
7
7
  import { barrelImports } from './barrelImports.js'
8
8
  import { codeLanguages } from './codeLanguages.js'
9
+ import { benchFiles } from './benchFiles.js'
9
10
 
10
11
  function frappeuiPlugin(options = {}) {
11
12
  let plugins = []
@@ -19,6 +20,9 @@ function frappeuiPlugin(options = {}) {
19
20
  const barrelImportsOpt = options.barrelImports ?? true
20
21
  const codeLanguagesOpt = options.codeLanguages ?? true
21
22
 
23
+ // Resolve `../…/sites/<file>` imports in the bench when they do not resolve
24
+ // in place, as for an app linked into apps/ from another folder.
25
+ plugins.push(benchFiles())
22
26
  if (codeLanguagesOpt) {
23
27
  // Stub the `@codemirror/lang-*` packages this app did not install, so
24
28
  // `frappe-ui/code-editor` builds with the languages it renders and no more.
package/vite/utils.js CHANGED
@@ -22,16 +22,28 @@ export function getCommonSiteConfig() {
22
22
  return null
23
23
  }
24
24
 
25
+ const warnedBenchPaths = new Set()
26
+
25
27
  export function findBenchPath() {
26
28
  let currentDir = path.resolve('.')
27
- while (currentDir !== '/') {
28
- if (
29
- fs.existsSync(path.join(currentDir, 'sites')) &&
30
- fs.existsSync(path.join(currentDir, 'apps'))
31
- ) {
29
+ while (currentDir !== path.dirname(currentDir)) {
30
+ if (isBench(currentDir)) {
32
31
  return currentDir
33
32
  }
34
- currentDir = path.resolve(currentDir, '..')
33
+ currentDir = path.dirname(currentDir)
34
+ }
35
+
36
+ // An app linked into apps/ from elsewhere has no bench above it. Tools that
37
+ // link it, such as `pilot dev`, set FRAPPE_BENCH_PATH to the bench.
38
+ if (process.env.FRAPPE_BENCH_PATH) {
39
+ const benchPath = path.resolve(process.env.FRAPPE_BENCH_PATH)
40
+ if (!isBench(benchPath) && !warnedBenchPaths.has(benchPath)) {
41
+ warnedBenchPaths.add(benchPath)
42
+ console.warn(
43
+ `FRAPPE_BENCH_PATH is ${benchPath}, which has no apps/ and sites/ folders`,
44
+ )
45
+ }
46
+ return benchPath
35
47
  }
36
48
  return null
37
49
  }
@@ -53,7 +65,7 @@ export function findAppName() {
53
65
 
54
66
  // Walk up from cwd until we find a directory whose parent is the apps folder
55
67
  let currentDir = path.resolve('.')
56
- while (currentDir !== '/') {
68
+ while (currentDir !== path.dirname(currentDir)) {
57
69
  const parent = path.dirname(currentDir)
58
70
  if (path.resolve(parent) === path.resolve(appsFolder)) {
59
71
  return path.basename(currentDir)
@@ -61,9 +73,47 @@ export function findAppName() {
61
73
  currentDir = parent
62
74
  }
63
75
 
76
+ return findLinkedAppName(appsFolder)
77
+ }
78
+
79
+ // Finds an app symlinked into apps/ from another folder by comparing real paths.
80
+ function findLinkedAppName(appsFolder) {
81
+ let names
82
+ try {
83
+ names = fs.readdirSync(appsFolder)
84
+ } catch {
85
+ return null
86
+ }
87
+
88
+ const apps = new Map(
89
+ names.map((name) => [realPath(path.join(appsFolder, name)), name]),
90
+ )
91
+ let currentDir = realPath(path.resolve('.'))
92
+ while (currentDir !== path.dirname(currentDir)) {
93
+ if (apps.has(currentDir)) {
94
+ return apps.get(currentDir)
95
+ }
96
+ currentDir = path.dirname(currentDir)
97
+ }
98
+
64
99
  return null
65
100
  }
66
101
 
102
+ function isBench(dir) {
103
+ return (
104
+ fs.existsSync(path.join(dir, 'sites')) &&
105
+ fs.existsSync(path.join(dir, 'apps'))
106
+ )
107
+ }
108
+
109
+ function realPath(filePath) {
110
+ try {
111
+ return fs.realpathSync(filePath)
112
+ } catch {
113
+ return filePath
114
+ }
115
+ }
116
+
67
117
  export async function getInstalledAppSites(appName) {
68
118
  const { execFile } = await import('node:child_process')
69
119
  const { promisify } = await import('node:util')