@api-client/ui 0.1.5 → 0.1.7
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/.github/workflows/deployment.yml +1 -1
- package/build/src/events/StoreEvents.d.ts +1 -1
- package/build/src/events/StoreEvents.d.ts.map +1 -1
- package/build/src/events/StoreEvents.js.map +1 -1
- package/build/src/reactive/reactive.d.ts.map +1 -1
- package/build/src/reactive/reactive.js +43 -1
- package/build/src/reactive/reactive.js.map +1 -1
- package/demo/elements/md/notification/snack.html +1 -1
- package/demo/elements/user/user-avatar.ts +4 -0
- package/package.json +1 -1
- package/src/events/StoreEvents.ts +1 -1
- package/src/reactive/reactive.ts +43 -1
- package/test/core/live_data.spec.ts +33 -3
- package/test/elements/data-table/DataTable.browser.test.ts +0 -3
|
@@ -36,7 +36,7 @@ jobs:
|
|
|
36
36
|
- name: Install dependencies
|
|
37
37
|
run: npm ci
|
|
38
38
|
- name: Install playwright browsers
|
|
39
|
-
run: npx playwright install --with-deps
|
|
39
|
+
run: npx playwright install chromium --with-deps
|
|
40
40
|
- name: Building API models
|
|
41
41
|
run: npm run gen:apis
|
|
42
42
|
- name: Run tests
|
|
@@ -2,7 +2,7 @@ import type { Operation } from '@api-client/json/types.js';
|
|
|
2
2
|
import type { FileBreadcrumb, IFile } from '@api-client/core/models/store/File.js';
|
|
3
3
|
import type { IApplication } from '@api-client/core/models/Application.js';
|
|
4
4
|
import type { ContextListOptions, ContextListResult, IPatchRevision } from '@api-client/core/events/BaseEvents.js';
|
|
5
|
-
import { type IFileCreateOptions, ListFileKind } from '@api-client/core/
|
|
5
|
+
import { type IFileCreateOptions, ListFileKind } from '@api-client/core/sdk/FilesSdk.js';
|
|
6
6
|
import type { IUser } from '@api-client/core/models/store/User.js';
|
|
7
7
|
import type { AccessOperation } from '@api-client/core/models/store/Permission.js';
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreEvents.d.ts","sourceRoot":"","sources":["../../../src/events/StoreEvents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAClH,OAAO,EAAE,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"StoreEvents.d.ts","sourceRoot":"","sources":["../../../src/events/StoreEvents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAClH,OAAO,EAAE,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uCAAuC,CAAA;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AAElF;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;AAClF;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAsBnF;;;;;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aACF,CAAC,CAAA;YACF,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,MAAmC,CAAA;QACrD,CAAC;QACD,IAAI,EAAE,KAAK,EACT,cAAsB,EACtB,OAA4B,EAC5B,SAAsB,QAAQ,CAAC,IAAI,EACA,EAAE;YACrC,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;gBACpD,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE;oBACN,cAAc;oBACd,OAAO;oBACP,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAA;YACF,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,MAAsD,CAAA;QACxE,CAAC;KACF,CAAC;CACH,CAAC,CAAA","sourcesContent":["/* eslint-disable no-redeclare */\nimport type { Operation } from '@api-client/json/types.js'\nimport { EventTypes } from './EventTypes.js'\nimport type { FileBreadcrumb, IFile } from '@api-client/core/models/store/File.js'\nimport type { IApplication } from '@api-client/core/models/Application.js'\nimport type { ContextListOptions, ContextListResult, IPatchRevision } from '@api-client/core/events/BaseEvents.js'\nimport { type IFileCreateOptions, ListFileKind } from '@api-client/core/runtime/store/FilesSdk.js'\nimport type { IUser } from '@api-client/core/models/store/User.js'\nimport type { AccessOperation } from '@api-client/core/models/store/Permission.js'\n\n/**\n * Reads file metadata from the store.\n *\n * @param key The file key\n * @returns THe file metadata\n */\nfunction fileRead(key: string, media: false, target?: EventTarget): Promise<IFile>\n/**\n * Reads file contents from the store.\n *\n * @param key The file key\n * @returns THe file contents\n */\nfunction fileRead(key: string, media: true, target?: EventTarget): Promise<unknown>\n\n/**\n * Reads a user file definition from the store.\n * @param key The file key\n * @param media When true it reads file contents rather than metadata.\n */\nfunction fileRead(key: string, media: boolean, target: EventTarget = document.body): Promise<IFile | unknown> {\n const e = new CustomEvent(EventTypes.Store.File.read, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n media,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IFile | unknown>\n}\n\n/**\n * Patches file's meta in the store.\n *\n * @param key The file key\n * @param value The patch to apply.\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n media: false,\n target?: EventTarget\n): Promise<IPatchRevision>\n\n/**\n * Patches file's content in the store.\n *\n * @param key The file key\n * @param value The patch to apply.\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n media: true,\n target?: EventTarget\n): Promise<IPatchRevision>\n\n/**\n * Patches a file in the store.\n * @param key The key of the file to patch\n * @param value The JSON patch to be processed.\n * @returns The JSON patch to revert the change using the `@api-client/json` library\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n media?: boolean,\n target: EventTarget = document.body\n): Promise<IPatchRevision> {\n const e = new CustomEvent(EventTypes.Store.File.patch, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n value,\n media,\n id,\n app,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IPatchRevision>\n}\n\nexport default Object.freeze({\n File: Object.freeze({\n /**\n * Lists files (spaces, projects, etc) in the store.\n *\n * @param kinds the list of kinds to list. Spaces are always included.\n * @param options Optional query options.\n */\n list: async (\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IFile>> => {\n const e = new CustomEvent(EventTypes.Store.File.list, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n kinds,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IFile>>\n },\n /**\n * Lists files that are shared with the user.\n *\n * @param kinds the list of kinds to list. Spaces are always included.\n * @param options Optional query options.\n */\n listShared: async (\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IFile>> => {\n const e = new CustomEvent(EventTypes.Store.File.listShared, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n kinds,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IFile>>\n },\n /**\n * Creates a file in the store.\n *\n * @param meta The definition of a file that extends the IFile interface.\n * @param media The file content to create with the file meta, if available.\n * @param opts Optional options when creating a file\n * @returns The key of the creates file.\n */\n create: async (\n meta: IFile,\n media?: unknown,\n opts?: IFileCreateOptions,\n target: EventTarget = document.body\n ): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.create, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n meta,\n media,\n opts,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n /**\n * A special case of a create file flow.\n * It allow to create a file only from a name and its kind.\n * The store has logic to recognize the file from its `kind` and create a file.\n *\n * This is helpful when creating a new file from the \"create\" dialog.\n *\n * @param name The name provided by the user.\n * @param kind File kind.\n * @param opts Optional options when creating a file\n * @returns The key of the creates file.\n */\n createDefault: async (\n name: string,\n kind: string,\n opts?: IFileCreateOptions,\n target: EventTarget = document.body\n ): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.createDefault, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n name,\n kind,\n opts,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n read: fileRead,\n patch: patchFile,\n /**\n * Deletes the file in the store.\n *\n * @param key The key of the file to delete.\n */\n delete: async (key: string, target: EventTarget = document.body): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.delete, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n /**\n * Updates the sharing options of the file.\n *\n * @param key The file key\n * @param id The generated by the client random id. This id is reported back by the server.\n * @param value The patch operation on the file's ACL\n */\n patchUsers: async (\n key: string,\n id: string,\n value: AccessOperation[],\n app: IApplication,\n target: EventTarget = document.body\n ): Promise<void> => {\n const e = new CustomEvent(EventTypes.Store.File.patchUsers, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n value,\n id,\n app,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n await (e.detail.result as unknown as Promise<void>)\n },\n /**\n * Lists the users that have direct permission to the file.\n *\n * @param key The file key\n */\n listUsers: async (key: string, target: EventTarget = document.body): Promise<ContextListResult<IUser>> => {\n const e = new CustomEvent(EventTypes.Store.File.listUsers, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IUser>>\n },\n\n /**\n * Lists breadcrumbs to the file.\n *\n * @param fileOrFolder The if of the file or folder to query for.\n * @param options Optional query options.\n */\n breadcrumbs: async (\n fileOrFolder: string,\n target: EventTarget = document.body\n ): Promise<ContextListResult<FileBreadcrumb>> => {\n const e = new CustomEvent(EventTypes.Store.File.breadcrumbs, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key: fileOrFolder,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<FileBreadcrumb>>\n },\n }),\n /**\n * Reads the current user.\n */\n User: Object.freeze({\n me: async (target: EventTarget = document.body): Promise<IUser> => {\n const e = new CustomEvent(EventTypes.Store.User.me, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IUser>\n },\n read: async (\n organizationId: string,\n key: string,\n target: EventTarget = document.body\n ): Promise<IUser | undefined> => {\n const e = new CustomEvent(EventTypes.Store.User.read, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n organizationId,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IUser>\n },\n list: async (\n organizationId: string,\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IUser>> => {\n const e = new CustomEvent(EventTypes.Store.User.list, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n organizationId,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IUser>>\n },\n }),\n})\n"]}
|
|
1
|
+
{"version":3,"file":"StoreEvents.js","sourceRoot":"","sources":["../../../src/events/StoreEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAuB5C;;;;GAIG;AACH,SAAS,QAAQ,CAAC,GAAW,EAAE,KAAc,EAAE,SAAsB,QAAQ,CAAC,IAAI;IAChF,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;QACpD,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,GAAG;YACH,KAAK;YACL,MAAM,EAAE,SAAS;SAClB;KACF,CAAC,CAAA;IACF,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACvB,OAAO,CAAC,CAAC,MAAM,CAAC,MAA6C,CAAA;AAC/D,CAAC;AAiCD;;;;;GAKG;AACH,SAAS,SAAS,CAChB,GAAW,EACX,EAAU,EACV,KAAkB,EAClB,GAAiB,EACjB,KAAe,EACf,SAAsB,QAAQ,CAAC,IAAI;IAEnC,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE;QACrD,OAAO,EAAE,IAAI;QACb,UAAU,EAAE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B,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE;oBACN,GAAG;oBACH,cAAc;oBACd,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAA;YACF,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,MAAmC,CAAA;QACrD,CAAC;QACD,IAAI,EAAE,KAAK,EACT,cAAsB,EACtB,OAA4B,EAC5B,SAAsB,QAAQ,CAAC,IAAI,EACA,EAAE;YACrC,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;gBACpD,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE;oBACN,cAAc;oBACd,OAAO;oBACP,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAA;YACF,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,CAAC,CAAC,MAAM,CAAC,MAAsD,CAAA;QACxE,CAAC;KACF,CAAC;CACH,CAAC,CAAA","sourcesContent":["/* eslint-disable no-redeclare */\nimport type { Operation } from '@api-client/json/types.js'\nimport { EventTypes } from './EventTypes.js'\nimport type { FileBreadcrumb, IFile } from '@api-client/core/models/store/File.js'\nimport type { IApplication } from '@api-client/core/models/Application.js'\nimport type { ContextListOptions, ContextListResult, IPatchRevision } from '@api-client/core/events/BaseEvents.js'\nimport { type IFileCreateOptions, ListFileKind } from '@api-client/core/sdk/FilesSdk.js'\nimport type { IUser } from '@api-client/core/models/store/User.js'\nimport type { AccessOperation } from '@api-client/core/models/store/Permission.js'\n\n/**\n * Reads file metadata from the store.\n *\n * @param key The file key\n * @returns THe file metadata\n */\nfunction fileRead(key: string, media: false, target?: EventTarget): Promise<IFile>\n/**\n * Reads file contents from the store.\n *\n * @param key The file key\n * @returns THe file contents\n */\nfunction fileRead(key: string, media: true, target?: EventTarget): Promise<unknown>\n\n/**\n * Reads a user file definition from the store.\n * @param key The file key\n * @param media When true it reads file contents rather than metadata.\n */\nfunction fileRead(key: string, media: boolean, target: EventTarget = document.body): Promise<IFile | unknown> {\n const e = new CustomEvent(EventTypes.Store.File.read, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n media,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IFile | unknown>\n}\n\n/**\n * Patches file's meta in the store.\n *\n * @param key The file key\n * @param value The patch to apply.\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n media: false,\n target?: EventTarget\n): Promise<IPatchRevision>\n\n/**\n * Patches file's content in the store.\n *\n * @param key The file key\n * @param value The patch to apply.\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n media: true,\n target?: EventTarget\n): Promise<IPatchRevision>\n\n/**\n * Patches a file in the store.\n * @param key The key of the file to patch\n * @param value The JSON patch to be processed.\n * @returns The JSON patch to revert the change using the `@api-client/json` library\n */\nfunction patchFile(\n key: string,\n id: string,\n value: Operation[],\n app: IApplication,\n media?: boolean,\n target: EventTarget = document.body\n): Promise<IPatchRevision> {\n const e = new CustomEvent(EventTypes.Store.File.patch, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n value,\n media,\n id,\n app,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IPatchRevision>\n}\n\nexport default Object.freeze({\n File: Object.freeze({\n /**\n * Lists files (spaces, projects, etc) in the store.\n *\n * @param kinds the list of kinds to list. Spaces are always included.\n * @param options Optional query options.\n */\n list: async (\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IFile>> => {\n const e = new CustomEvent(EventTypes.Store.File.list, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n kinds,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IFile>>\n },\n /**\n * Lists files that are shared with the user.\n *\n * @param kinds the list of kinds to list. Spaces are always included.\n * @param options Optional query options.\n */\n listShared: async (\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IFile>> => {\n const e = new CustomEvent(EventTypes.Store.File.listShared, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n kinds,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IFile>>\n },\n /**\n * Creates a file in the store.\n *\n * @param meta The definition of a file that extends the IFile interface.\n * @param media The file content to create with the file meta, if available.\n * @param opts Optional options when creating a file\n * @returns The key of the creates file.\n */\n create: async (\n meta: IFile,\n media?: unknown,\n opts?: IFileCreateOptions,\n target: EventTarget = document.body\n ): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.create, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n meta,\n media,\n opts,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n /**\n * A special case of a create file flow.\n * It allow to create a file only from a name and its kind.\n * The store has logic to recognize the file from its `kind` and create a file.\n *\n * This is helpful when creating a new file from the \"create\" dialog.\n *\n * @param name The name provided by the user.\n * @param kind File kind.\n * @param opts Optional options when creating a file\n * @returns The key of the creates file.\n */\n createDefault: async (\n name: string,\n kind: string,\n opts?: IFileCreateOptions,\n target: EventTarget = document.body\n ): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.createDefault, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n name,\n kind,\n opts,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n read: fileRead,\n patch: patchFile,\n /**\n * Deletes the file in the store.\n *\n * @param key The key of the file to delete.\n */\n delete: async (key: string, target: EventTarget = document.body): Promise<string> => {\n const e = new CustomEvent(EventTypes.Store.File.delete, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<string>\n },\n /**\n * Updates the sharing options of the file.\n *\n * @param key The file key\n * @param id The generated by the client random id. This id is reported back by the server.\n * @param value The patch operation on the file's ACL\n */\n patchUsers: async (\n key: string,\n id: string,\n value: AccessOperation[],\n app: IApplication,\n target: EventTarget = document.body\n ): Promise<void> => {\n const e = new CustomEvent(EventTypes.Store.File.patchUsers, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n value,\n id,\n app,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n await (e.detail.result as unknown as Promise<void>)\n },\n /**\n * Lists the users that have direct permission to the file.\n *\n * @param key The file key\n */\n listUsers: async (key: string, target: EventTarget = document.body): Promise<ContextListResult<IUser>> => {\n const e = new CustomEvent(EventTypes.Store.File.listUsers, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IUser>>\n },\n\n /**\n * Lists breadcrumbs to the file.\n *\n * @param fileOrFolder The if of the file or folder to query for.\n * @param options Optional query options.\n */\n breadcrumbs: async (\n fileOrFolder: string,\n target: EventTarget = document.body\n ): Promise<ContextListResult<FileBreadcrumb>> => {\n const e = new CustomEvent(EventTypes.Store.File.breadcrumbs, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key: fileOrFolder,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<FileBreadcrumb>>\n },\n }),\n /**\n * Reads the current user.\n */\n User: Object.freeze({\n me: async (target: EventTarget = document.body): Promise<IUser> => {\n const e = new CustomEvent(EventTypes.Store.User.me, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IUser>\n },\n read: async (\n organizationId: string,\n key: string,\n target: EventTarget = document.body\n ): Promise<IUser | undefined> => {\n const e = new CustomEvent(EventTypes.Store.User.read, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n key,\n organizationId,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<IUser>\n },\n list: async (\n organizationId: string,\n options?: ContextListOptions,\n target: EventTarget = document.body\n ): Promise<ContextListResult<IUser>> => {\n const e = new CustomEvent(EventTypes.Store.User.list, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n organizationId,\n options,\n result: undefined,\n },\n })\n target.dispatchEvent(e)\n return e.detail.result as unknown as Promise<ContextListResult<IUser>>\n },\n }),\n})\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../../../src/reactive/reactive.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;CAClB;AAOD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,EAC7C,IAAI,SAAK,GACR,CAAC,
|
|
1
|
+
{"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../../../src/reactive/reactive.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;CAClB;AAOD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,EAC7C,IAAI,SAAK,GACR,CAAC,CA2GH;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAQ9D"}
|
|
@@ -12,17 +12,59 @@ export function createReactive(target, onChange, path = '') {
|
|
|
12
12
|
}
|
|
13
13
|
const handler = {
|
|
14
14
|
get(target, prop, receiver) {
|
|
15
|
+
// Retrieve the original value. If 'prop' is a getter, 'receiver' (the proxy) is used as 'this'.
|
|
15
16
|
const value = Reflect.get(target, prop, receiver);
|
|
17
|
+
// If the retrieved value is a function, bind it to the original 'target' object.
|
|
18
|
+
// This ensures that methods (e.g., Set.prototype.add, Map.prototype.set) are called
|
|
19
|
+
// with the correct 'this' context, which is the original unwrapped object.
|
|
20
|
+
// Special handling for Set and Map mutating methods
|
|
21
|
+
if (target instanceof Set) {
|
|
22
|
+
if (['add', 'delete', 'clear'].includes(String(prop))) {
|
|
23
|
+
return (...args) => {
|
|
24
|
+
const oldValue = new Set(target); // shallow copy before mutation
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
26
|
+
const result = value.apply(target, args);
|
|
27
|
+
onChange({
|
|
28
|
+
path,
|
|
29
|
+
value: target,
|
|
30
|
+
oldValue,
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (target instanceof Map) {
|
|
37
|
+
if (['set', 'delete', 'clear'].includes(String(prop))) {
|
|
38
|
+
return (...args) => {
|
|
39
|
+
const oldValue = new Map(target); // shallow copy before mutation
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
41
|
+
const result = value.apply(target, args);
|
|
42
|
+
onChange({
|
|
43
|
+
path,
|
|
44
|
+
value: target,
|
|
45
|
+
oldValue,
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === 'function' && !Array.isArray(target)) {
|
|
52
|
+
// If the value is a function, bind it to the original target object.
|
|
53
|
+
return value.bind(target);
|
|
54
|
+
}
|
|
55
|
+
// If the value is an object (and not null, and not a function due to the check above),
|
|
56
|
+
// then recursively create a reactive proxy for it.
|
|
16
57
|
if (typeof value === 'object' && value !== null) {
|
|
17
58
|
const finalPath = path ? `${path}.${String(prop)}` : String(prop);
|
|
18
59
|
return createReactive(value, onChange, finalPath);
|
|
19
60
|
}
|
|
61
|
+
// For primitive values or null, return the value directly.
|
|
20
62
|
return value;
|
|
21
63
|
},
|
|
22
64
|
set(target, prop, value, receiver) {
|
|
23
65
|
const oldValue = Reflect.get(target, prop, receiver);
|
|
24
66
|
const success = Reflect.set(target, prop, value); // do not set the receiver here
|
|
25
|
-
//
|
|
67
|
+
// The receiver is the proxy itself and if we set the value on the proxy, it will
|
|
26
68
|
// create an infinite loop.
|
|
27
69
|
if (success && oldValue !== value) {
|
|
28
70
|
// Check if the old value was proxied and remove it from the cache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../../src/reactive/reactive.ts"],"names":[],"mappings":"AAMA,kBAAkB;AAClB,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkB,CAAA;AAC/C,kBAAkB;AAClB,MAAM,aAAa,GAAG,IAAI,OAAO,EAAkB,CAAA;AAEnD,MAAM,UAAU,cAAc,CAC5B,MAAS,EACT,QAA6C,EAC7C,IAAI,GAAG,EAAE;IAET,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,gBAAgB;QAChB,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAM,CAAA,CAAC,wBAAwB;IAC5D,CAAC;IACD,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAA;IACf,CAAC;IAED,MAAM,OAAO,GAAoB;QAC/B,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,KAA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5B,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAChC,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,cAAsB;IACnD,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC7C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAA,CAAC,wBAAwB;IACvC,CAAC;IACD,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACrB,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IACpC,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["export interface ChangeEventDetail {\n path: string\n value: unknown\n oldValue: unknown\n}\n\n// target -> Proxy\nconst cachedRaw = new WeakMap<object, object>()\n// Proxy -> target\nconst cachedProxies = new WeakMap<object, object>()\n\nexport function createReactive<T extends object>(\n target: T,\n onChange: (detail: ChangeEventDetail) => void,\n path = ''\n): T {\n if (cachedRaw.has(target)) {\n // return target\n return cachedRaw.get(target) as T // Return existing proxy\n }\n if (cachedProxies.has(target)) {\n return target\n }\n\n const handler: ProxyHandler<T> = {\n get(target, prop, receiver) {\n // Retrieve the original value. If 'prop' is a getter, 'receiver' (the proxy) is used as 'this'.\n const value = Reflect.get(target, prop, receiver)\n // If the retrieved value is a function, bind it to the original 'target' object.\n // This ensures that methods (e.g., Set.prototype.add, Map.prototype.set) are called\n // with the correct 'this' context, which is the original unwrapped object.\n // Special handling for Set and Map mutating methods\n if (target instanceof Set) {\n if (['add', 'delete', 'clear'].includes(String(prop))) {\n return (...args: unknown[]) => {\n const oldValue = new Set(target) // shallow copy before mutation\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n const result = (value as Function).apply(target, args)\n onChange({\n path,\n value: target,\n oldValue,\n })\n return result\n }\n }\n }\n if (target instanceof Map) {\n if (['set', 'delete', 'clear'].includes(String(prop))) {\n return (...args: unknown[]) => {\n const oldValue = new Map(target) // shallow copy before mutation\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n const result = (value as Function).apply(target, args)\n onChange({\n path,\n value: target,\n oldValue,\n })\n return result\n }\n }\n }\n if (typeof value === 'function' && !Array.isArray(target)) {\n // If the value is a function, bind it to the original target object.\n return value.bind(target)\n }\n // If the value is an object (and not null, and not a function due to the check above),\n // then recursively create a reactive proxy for it.\n if (typeof value === 'object' && value !== null) {\n const finalPath = path ? `${path}.${String(prop)}` : String(prop)\n return createReactive(value, onChange, finalPath)\n }\n // For primitive values or null, return the value directly.\n return value\n },\n set(target, prop, value, receiver) {\n const oldValue = Reflect.get(target, prop, receiver)\n const success = Reflect.set(target, prop, value) // do not set the receiver here\n // The receiver is the proxy itself and if we set the value on the proxy, it will\n // create an infinite loop.\n if (success && oldValue !== value) {\n // Check if the old value was proxied and remove it from the cache\n if (typeof oldValue === 'object' && oldValue !== null) {\n const oldProxy = cachedRaw.get(oldValue)\n if (oldProxy) {\n cachedRaw.delete(oldValue)\n cachedProxies.delete(oldProxy)\n }\n }\n onChange({\n path: path ? `${path}.${String(prop)}` : String(prop),\n value,\n oldValue,\n })\n }\n return success\n },\n deleteProperty(target, prop) {\n const oldValue = Reflect.get(target, prop)\n const success = Reflect.deleteProperty(target, prop)\n if (success) {\n // Check if the old value was proxied and remove it from the cache\n if (typeof oldValue === 'object' && oldValue !== null) {\n const oldProxy = cachedRaw.get(oldValue)\n if (oldProxy) {\n cachedRaw.delete(oldValue)\n cachedProxies.delete(oldProxy)\n }\n }\n onChange({\n path: path ? `${path}.${String(prop)}` : String(prop),\n value: undefined,\n oldValue,\n })\n }\n return success\n },\n }\n const proxy = new Proxy(target, handler)\n cachedRaw.set(target, proxy)\n cachedProxies.set(proxy, target)\n return proxy\n}\n\n/**\n * Removes the proxy and cleans up the cached data.\n *\n * @param reactiveObject The reactive object to unhook.\n * @returns true if the object was reactive and was unhooked, false otherwise.\n */\nexport function unhookReactive(reactiveObject: object): boolean {\n const raw = cachedProxies.get(reactiveObject)\n if (!raw) {\n return false // Not a reactive object\n }\n cachedRaw.delete(raw)\n cachedProxies.delete(reactiveObject)\n return true\n}\n"]}
|
|
@@ -22,6 +22,8 @@ class ComponentDemoPage extends DemoPage {
|
|
|
22
22
|
kind: UserKind,
|
|
23
23
|
status: 'active',
|
|
24
24
|
grantType: 'editor',
|
|
25
|
+
created: new Date('2023-01-01T00:00:00Z').getTime(),
|
|
26
|
+
updated: new Date('2023-01-02T00:00:00Z').getTime(),
|
|
25
27
|
}
|
|
26
28
|
this.user2 = {
|
|
27
29
|
key: '2',
|
|
@@ -30,6 +32,8 @@ class ComponentDemoPage extends DemoPage {
|
|
|
30
32
|
kind: UserKind,
|
|
31
33
|
status: 'active',
|
|
32
34
|
grantType: 'editor',
|
|
35
|
+
created: new Date('2023-01-01T00:00:00Z').getTime(),
|
|
36
|
+
updated: new Date('2023-01-02T00:00:00Z').getTime(),
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { EventTypes } from './EventTypes.js'
|
|
|
4
4
|
import type { FileBreadcrumb, IFile } from '@api-client/core/models/store/File.js'
|
|
5
5
|
import type { IApplication } from '@api-client/core/models/Application.js'
|
|
6
6
|
import type { ContextListOptions, ContextListResult, IPatchRevision } from '@api-client/core/events/BaseEvents.js'
|
|
7
|
-
import { type IFileCreateOptions, ListFileKind } from '@api-client/core/
|
|
7
|
+
import { type IFileCreateOptions, ListFileKind } from '@api-client/core/sdk/FilesSdk.js'
|
|
8
8
|
import type { IUser } from '@api-client/core/models/store/User.js'
|
|
9
9
|
import type { AccessOperation } from '@api-client/core/models/store/Permission.js'
|
|
10
10
|
|
package/src/reactive/reactive.ts
CHANGED
|
@@ -24,17 +24,59 @@ export function createReactive<T extends object>(
|
|
|
24
24
|
|
|
25
25
|
const handler: ProxyHandler<T> = {
|
|
26
26
|
get(target, prop, receiver) {
|
|
27
|
+
// Retrieve the original value. If 'prop' is a getter, 'receiver' (the proxy) is used as 'this'.
|
|
27
28
|
const value = Reflect.get(target, prop, receiver)
|
|
29
|
+
// If the retrieved value is a function, bind it to the original 'target' object.
|
|
30
|
+
// This ensures that methods (e.g., Set.prototype.add, Map.prototype.set) are called
|
|
31
|
+
// with the correct 'this' context, which is the original unwrapped object.
|
|
32
|
+
// Special handling for Set and Map mutating methods
|
|
33
|
+
if (target instanceof Set) {
|
|
34
|
+
if (['add', 'delete', 'clear'].includes(String(prop))) {
|
|
35
|
+
return (...args: unknown[]) => {
|
|
36
|
+
const oldValue = new Set(target) // shallow copy before mutation
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
38
|
+
const result = (value as Function).apply(target, args)
|
|
39
|
+
onChange({
|
|
40
|
+
path,
|
|
41
|
+
value: target,
|
|
42
|
+
oldValue,
|
|
43
|
+
})
|
|
44
|
+
return result
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (target instanceof Map) {
|
|
49
|
+
if (['set', 'delete', 'clear'].includes(String(prop))) {
|
|
50
|
+
return (...args: unknown[]) => {
|
|
51
|
+
const oldValue = new Map(target) // shallow copy before mutation
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
53
|
+
const result = (value as Function).apply(target, args)
|
|
54
|
+
onChange({
|
|
55
|
+
path,
|
|
56
|
+
value: target,
|
|
57
|
+
oldValue,
|
|
58
|
+
})
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (typeof value === 'function' && !Array.isArray(target)) {
|
|
64
|
+
// If the value is a function, bind it to the original target object.
|
|
65
|
+
return value.bind(target)
|
|
66
|
+
}
|
|
67
|
+
// If the value is an object (and not null, and not a function due to the check above),
|
|
68
|
+
// then recursively create a reactive proxy for it.
|
|
28
69
|
if (typeof value === 'object' && value !== null) {
|
|
29
70
|
const finalPath = path ? `${path}.${String(prop)}` : String(prop)
|
|
30
71
|
return createReactive(value, onChange, finalPath)
|
|
31
72
|
}
|
|
73
|
+
// For primitive values or null, return the value directly.
|
|
32
74
|
return value
|
|
33
75
|
},
|
|
34
76
|
set(target, prop, value, receiver) {
|
|
35
77
|
const oldValue = Reflect.get(target, prop, receiver)
|
|
36
78
|
const success = Reflect.set(target, prop, value) // do not set the receiver here
|
|
37
|
-
//
|
|
79
|
+
// The receiver is the proxy itself and if we set the value on the proxy, it will
|
|
38
80
|
// create an infinite loop.
|
|
39
81
|
if (success && oldValue !== value) {
|
|
40
82
|
// Check if the old value was proxied and remove it from the cache
|
|
@@ -61,10 +61,40 @@ describe('LiveData Basic', () => {
|
|
|
61
61
|
|
|
62
62
|
liveData.value.items.push('orange')
|
|
63
63
|
|
|
64
|
-
assert.equal(spy.callCount, 1)
|
|
64
|
+
assert.equal(spy.callCount, 1, 'called once for the push')
|
|
65
65
|
const args = spy.args[0][0].detail
|
|
66
|
-
assert.equal(args.path, 'items.2')
|
|
67
|
-
assert.equal(args.value, 'orange')
|
|
66
|
+
assert.equal(args.path, 'items.2', 'path is correct')
|
|
67
|
+
assert.equal(args.value, 'orange', 'value is correct')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should handle sets', () => {
|
|
71
|
+
const data = { set: new Set(['apple', 'banana']) }
|
|
72
|
+
const liveData = new LiveData(data)
|
|
73
|
+
|
|
74
|
+
const spy = sinon.spy()
|
|
75
|
+
liveData.addEventListener('update', spy)
|
|
76
|
+
|
|
77
|
+
liveData.value.set.add('orange')
|
|
78
|
+
|
|
79
|
+
assert.equal(spy.callCount, 1, 'called once for the add')
|
|
80
|
+
const args = spy.args[0][0].detail
|
|
81
|
+
assert.equal(args.path, 'set', 'path is correct')
|
|
82
|
+
assert.deepEqual(args.value, data.set, 'value is correct')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should handle maps', () => {
|
|
86
|
+
const data = { map: new Map([['a', 'b']]) }
|
|
87
|
+
const liveData = new LiveData(data)
|
|
88
|
+
|
|
89
|
+
const spy = sinon.spy()
|
|
90
|
+
liveData.addEventListener('update', spy)
|
|
91
|
+
|
|
92
|
+
liveData.value.map.set('c', 'd')
|
|
93
|
+
|
|
94
|
+
assert.equal(spy.callCount, 1, 'called once for the add')
|
|
95
|
+
const args = spy.args[0][0].detail
|
|
96
|
+
assert.equal(args.path, 'map', 'path is correct')
|
|
97
|
+
assert.deepEqual(args.value, data.map, 'value is correct')
|
|
68
98
|
})
|
|
69
99
|
|
|
70
100
|
it('should handle arrays with array index', () => {
|
|
@@ -73,11 +73,8 @@ describe('DataTable', () => {
|
|
|
73
73
|
describe('Basic tests', () => {
|
|
74
74
|
it('renders the table with correct number of rows and columns', async () => {
|
|
75
75
|
const items = generateItems(3)
|
|
76
|
-
// console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
77
76
|
const element = await basicFixture<TestItem>(items)
|
|
78
|
-
// console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
|
|
79
77
|
await nextFrame()
|
|
80
|
-
// console.log('ccccccccccccccccccccccccccccccccccc')
|
|
81
78
|
const rows = element.shadowRoot!.querySelectorAll('tr')
|
|
82
79
|
assert.equal(rows.length, items.value.length + 1, 'has all rows') // +1 for header row
|
|
83
80
|
|