diff options
author | Zachary Zhang <zacharyzhang7@gmail.com> | 2024-04-02 16:37:22 -0400 |
---|---|---|
committer | Zachary Zhang <zacharyzhang7@gmail.com> | 2024-04-02 16:37:22 -0400 |
commit | 427406dc60f0f037d69e0992fbb3205476daf89e (patch) | |
tree | b19538c66ade34ab4d2684589dbb8604a613e7ff /src/fields/util.ts | |
parent | dc0ee4595e37042db3adf60b002d7baf77cb24ae (diff) | |
parent | 3d158bb9b941a3fcb1b486f354ca5c9195dd21c2 (diff) |
Merge branch 'master' into zach-starter
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index b73520999..ad592391e 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -1,4 +1,4 @@ -import { $mobx, action, observable, runInAction, trace } from 'mobx'; +import { $mobx, action, observable, runInAction, trace, values } from 'mobx'; import { computedFn } from 'mobx-utils'; import { returnZero } from '../Utils'; import { DocServer } from '../client/DocServer'; @@ -16,6 +16,7 @@ import { RichTextField } from './RichTextField'; import { SchemaHeaderField } from './SchemaHeaderField'; import { ComputedField } from './ScriptField'; import { DocCast, ScriptCast, StrCast } from './Types'; +import { BaseException } from 'pdfjs-dist/types/src/shared/util'; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -56,6 +57,8 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number delete curValue[FieldChanged]; } + if (typeof prop === 'string' && _propSetterCB.has(prop)) _propSetterCB.get(prop)!(target[SelfProxy], value); + const effectiveAcl = GetEffectiveAcl(target); const writeMode = DocServer.getFieldWriteMode(prop as string); @@ -282,10 +285,25 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc dataDocChanged && updateCachedAcls(dataDoc); } +export var _propSetterCB = new Map<string, ((target: any, value: any) => void) | undefined>(); +/** + * sets a callback function to be called whenever a value is assigned to the specified field key. + * For example, this is used to "publish" documents with titles that start with '@' + * @param prop + * @param setter + */ +export function SetPropSetterCb(prop: string, setter: ((target: any, value: any) => void) | undefined) { + _propSetterCB.set(prop, setter); +} + // // target should be either a Doc or ListImpl. receiver should be a Proxy<Doc> Or List. // export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean { + if (!in_prop) { + console.log('WARNING: trying to set an empty property. This should be fixed. '); + return false; + } let prop = in_prop; const effectiveAcl = in_prop === 'constructor' || typeof in_prop === 'symbol' ? AclAdmin : GetPropAcl(target, prop); if (effectiveAcl !== AclEdit && effectiveAcl !== AclAugment && effectiveAcl !== AclAdmin) return true; |